From 28d16176960e908983aaa3926faddc374209de78 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Mon, 28 Dec 2015 11:39:07 +0000 Subject: cairo-1.14.6 git-svn-id: svn://tug.org/texlive/trunk@39210 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/libs/README | 2 +- Build/source/libs/cairo/ChangeLog | 6 + Build/source/libs/cairo/README | 7 +- .../libs/cairo/cairo-1.14.2-PATCHES/ChangeLog | 29 - .../libs/cairo/cairo-1.14.2-PATCHES/TL-Changes | 34 - Build/source/libs/cairo/cairo-1.14.2/AUTHORS | 115 - Build/source/libs/cairo/cairo-1.14.2/BIBLIOGRAPHY | 109 - Build/source/libs/cairo/cairo-1.14.2/BUGS | 85 - Build/source/libs/cairo/cairo-1.14.2/CODING_STYLE | 291 - Build/source/libs/cairo/cairo-1.14.2/COPYING | 33 - .../libs/cairo/cairo-1.14.2/COPYING-LGPL-2.1 | 510 -- .../source/libs/cairo/cairo-1.14.2/COPYING-MPL-1.1 | 470 -- Build/source/libs/cairo/cairo-1.14.2/HACKING | 185 - Build/source/libs/cairo/cairo-1.14.2/INSTALL | 184 - Build/source/libs/cairo/cairo-1.14.2/KNOWN_ISSUES | 3 - Build/source/libs/cairo/cairo-1.14.2/Makefile.am | 83 - .../source/libs/cairo/cairo-1.14.2/Makefile.win32 | 24 - Build/source/libs/cairo/cairo-1.14.2/NEWS | 7366 ------------------ Build/source/libs/cairo/cairo-1.14.2/PORTING_GUIDE | 265 - Build/source/libs/cairo/cairo-1.14.2/README | 204 - Build/source/libs/cairo/cairo-1.14.2/README.win32 | 66 - Build/source/libs/cairo/cairo-1.14.2/RELEASING | 142 - Build/source/libs/cairo/cairo-1.14.2/acinclude.m4 | 55 - Build/source/libs/cairo/cairo-1.14.2/autogen.sh | 31 - .../cairo/cairo-1.14.2/build/Makefile.am.analysis | 37 - .../cairo/cairo-1.14.2/build/Makefile.am.changelog | 82 - .../cairo/cairo-1.14.2/build/Makefile.am.common | 14 - .../cairo/cairo-1.14.2/build/Makefile.am.gtk-doc | 190 - .../cairo/cairo-1.14.2/build/Makefile.am.releasing | 194 - .../cairo/cairo-1.14.2/build/Makefile.win32.common | 74 - .../cairo-1.14.2/build/Makefile.win32.features | 41 - .../cairo-1.14.2/build/Makefile.win32.features-h | 130 - .../cairo/cairo-1.14.2/build/Makefile.win32.inform | 13 - .../libs/cairo/cairo-1.14.2/build/aclocal.cairo.m4 | 216 - .../cairo/cairo-1.14.2/build/aclocal.compare.m4 | 162 - .../cairo/cairo-1.14.2/build/aclocal.enable.m4 | 409 - .../libs/cairo/cairo-1.14.2/build/aclocal.float.m4 | 65 - .../cairo/cairo-1.14.2/build/aclocal.makefile.m4 | 234 - .../libs/cairo/cairo-1.14.2/build/aclocal.pkg.m4 | 157 - .../cairo/cairo-1.14.2/build/configure.ac.analysis | 106 - .../cairo/cairo-1.14.2/build/configure.ac.features | 427 -- .../cairo-1.14.2/build/configure.ac.noversion | 23 - .../cairo/cairo-1.14.2/build/configure.ac.pthread | 253 - .../cairo/cairo-1.14.2/build/configure.ac.system | 160 - .../cairo/cairo-1.14.2/build/configure.ac.tools | 25 - .../cairo/cairo-1.14.2/build/configure.ac.version | 42 - .../cairo/cairo-1.14.2/build/configure.ac.warnings | 99 - .../libs/cairo/cairo-1.14.2/build/gtk-doc.m4 | 88 - .../source/libs/cairo/cairo-1.14.2/cairo-version.h | 8 - Build/source/libs/cairo/cairo-1.14.2/config.h.in | 413 - Build/source/libs/cairo/cairo-1.14.2/configure.ac | 878 --- .../source/libs/cairo/cairo-1.14.2/src/Makefile.am | 119 - .../cairo/cairo-1.14.2/src/Makefile.am.analysis | 35 - .../cairo/cairo-1.14.2/src/Makefile.am.features | 657 -- .../libs/cairo/cairo-1.14.2/src/Makefile.sources | 472 -- .../libs/cairo/cairo-1.14.2/src/Makefile.win32 | 29 - .../cairo/cairo-1.14.2/src/Makefile.win32.features | 661 -- Build/source/libs/cairo/cairo-1.14.2/src/README | 69 - .../src/cairo-analysis-surface-private.h | 74 - .../cairo-1.14.2/src/cairo-analysis-surface.c | 934 --- .../cairo/cairo-1.14.2/src/cairo-arc-private.h | 61 - .../source/libs/cairo/cairo-1.14.2/src/cairo-arc.c | 312 - .../cairo/cairo-1.14.2/src/cairo-array-private.h | 90 - .../libs/cairo/cairo-1.14.2/src/cairo-array.c | 526 -- .../cairo/cairo-1.14.2/src/cairo-atomic-private.h | 272 - .../libs/cairo/cairo-1.14.2/src/cairo-atomic.c | 106 - .../cairo/cairo-1.14.2/src/cairo-backend-private.h | 201 - .../cairo/cairo-1.14.2/src/cairo-base64-stream.c | 144 - .../cairo/cairo-1.14.2/src/cairo-base85-stream.c | 131 - .../src/cairo-bentley-ottmann-rectangular.c | 884 --- .../src/cairo-bentley-ottmann-rectilinear.c | 600 -- .../cairo/cairo-1.14.2/src/cairo-bentley-ottmann.c | 1909 ----- .../cairo/cairo-1.14.2/src/cairo-beos-surface.cpp | 984 --- .../libs/cairo/cairo-1.14.2/src/cairo-beos.h | 60 - .../cairo-1.14.2/src/cairo-botor-scan-converter.c | 2164 ------ .../libs/cairo/cairo-1.14.2/src/cairo-box-inline.h | 121 - .../cairo/cairo-1.14.2/src/cairo-boxes-intersect.c | 690 -- .../cairo/cairo-1.14.2/src/cairo-boxes-private.h | 123 - .../libs/cairo/cairo-1.14.2/src/cairo-boxes.c | 460 -- .../cairo/cairo-1.14.2/src/cairo-cache-private.h | 145 - .../libs/cairo/cairo-1.14.2/src/cairo-cache.c | 338 - .../libs/cairo/cairo-1.14.2/src/cairo-cff-subset.c | 3440 --------- .../libs/cairo/cairo-1.14.2/src/cairo-clip-boxes.c | 599 -- .../cairo/cairo-1.14.2/src/cairo-clip-inline.h | 83 - .../cairo/cairo-1.14.2/src/cairo-clip-polygon.c | 156 - .../cairo/cairo-1.14.2/src/cairo-clip-private.h | 198 - .../cairo/cairo-1.14.2/src/cairo-clip-region.c | 123 - .../cairo/cairo-1.14.2/src/cairo-clip-surface.c | 240 - .../src/cairo-clip-tor-scan-converter.c | 1845 ----- .../libs/cairo/cairo-1.14.2/src/cairo-clip.c | 838 --- .../cairo-1.14.2/src/cairo-cogl-context-private.h | 52 - .../cairo/cairo-1.14.2/src/cairo-cogl-context.c | 822 -- .../cairo-1.14.2/src/cairo-cogl-gradient-private.h | 89 - .../cairo/cairo-1.14.2/src/cairo-cogl-gradient.c | 642 -- .../cairo/cairo-1.14.2/src/cairo-cogl-private.h | 164 - .../cairo/cairo-1.14.2/src/cairo-cogl-surface.c | 2805 ------- .../cairo-1.14.2/src/cairo-cogl-utils-private.h | 54 - .../libs/cairo/cairo-1.14.2/src/cairo-cogl-utils.c | 126 - .../libs/cairo/cairo-1.14.2/src/cairo-cogl.h | 69 - .../libs/cairo/cairo-1.14.2/src/cairo-color.c | 193 - .../cairo/cairo-1.14.2/src/cairo-combsort-inline.h | 94 - .../cairo-1.14.2/src/cairo-compiler-private.h | 244 - .../src/cairo-composite-rectangles-private.h | 159 - .../cairo-1.14.2/src/cairo-composite-rectangles.c | 500 -- .../cairo-1.14.2/src/cairo-compositor-private.h | 365 - .../libs/cairo/cairo-1.14.2/src/cairo-compositor.c | 268 - .../cairo/cairo-1.14.2/src/cairo-contour-inline.h | 80 - .../cairo/cairo-1.14.2/src/cairo-contour-private.h | 124 - .../libs/cairo/cairo-1.14.2/src/cairo-contour.c | 453 -- .../cairo/cairo-1.14.2/src/cairo-damage-private.h | 85 - .../libs/cairo/cairo-1.14.2/src/cairo-damage.c | 241 - .../libs/cairo/cairo-1.14.2/src/cairo-debug.c | 304 - .../src/cairo-default-context-private.h | 68 - .../cairo/cairo-1.14.2/src/cairo-default-context.c | 1475 ---- .../cairo/cairo-1.14.2/src/cairo-deflate-stream.c | 156 - .../libs/cairo/cairo-1.14.2/src/cairo-deprecated.h | 123 - .../cairo/cairo-1.14.2/src/cairo-device-private.h | 86 - .../libs/cairo/cairo-1.14.2/src/cairo-device.c | 541 -- .../cairo-1.14.2/src/cairo-directfb-surface.c | 544 -- .../libs/cairo/cairo-1.14.2/src/cairo-directfb.h | 67 - .../source/libs/cairo/cairo-1.14.2/src/cairo-drm.h | 120 - .../cairo/cairo-1.14.2/src/cairo-egl-context.c | 317 - .../cairo/cairo-1.14.2/src/cairo-error-inline.h | 52 - .../cairo/cairo-1.14.2/src/cairo-error-private.h | 127 - .../libs/cairo/cairo-1.14.2/src/cairo-error.c | 73 - .../cairo-1.14.2/src/cairo-fallback-compositor.c | 185 - .../src/cairo-features-uninstalled.pc.in | 7 - .../cairo/cairo-1.14.2/src/cairo-features.pc.in | 12 - .../cairo/cairo-1.14.2/src/cairo-fixed-private.h | 395 - .../cairo-1.14.2/src/cairo-fixed-type-private.h | 75 - .../libs/cairo/cairo-1.14.2/src/cairo-fixed.c | 39 - .../cairo-1.14.2/src/cairo-font-face-twin-data.c | 1072 --- .../cairo/cairo-1.14.2/src/cairo-font-face-twin.c | 752 -- .../libs/cairo/cairo-1.14.2/src/cairo-font-face.c | 338 - .../cairo/cairo-1.14.2/src/cairo-font-options.c | 535 -- .../cairo-1.14.2/src/cairo-fontconfig-private.h | 78 - .../cairo-1.14.2/src/cairo-freed-pool-private.h | 139 - .../libs/cairo/cairo-1.14.2/src/cairo-freed-pool.c | 93 - .../cairo-1.14.2/src/cairo-freelist-private.h | 139 - .../cairo-1.14.2/src/cairo-freelist-type-private.h | 54 - .../libs/cairo/cairo-1.14.2/src/cairo-freelist.c | 191 - .../libs/cairo/cairo-1.14.2/src/cairo-ft-font.c | 3577 --------- .../libs/cairo/cairo-1.14.2/src/cairo-ft-private.h | 61 - .../source/libs/cairo/cairo-1.14.2/src/cairo-ft.h | 118 - .../cairo/cairo-1.14.2/src/cairo-gl-composite.c | 1265 ---- .../libs/cairo/cairo-1.14.2/src/cairo-gl-device.c | 804 -- .../cairo-1.14.2/src/cairo-gl-dispatch-private.h | 129 - .../cairo/cairo-1.14.2/src/cairo-gl-dispatch.c | 261 - .../cairo-1.14.2/src/cairo-gl-ext-def-private.h | 143 - .../libs/cairo/cairo-1.14.2/src/cairo-gl-glyphs.c | 503 -- .../cairo-1.14.2/src/cairo-gl-gradient-private.h | 93 - .../cairo/cairo-1.14.2/src/cairo-gl-gradient.c | 338 - .../libs/cairo/cairo-1.14.2/src/cairo-gl-info.c | 111 - .../cairo-1.14.2/src/cairo-gl-msaa-compositor.c | 944 --- .../libs/cairo/cairo-1.14.2/src/cairo-gl-operand.c | 788 -- .../libs/cairo/cairo-1.14.2/src/cairo-gl-private.h | 853 --- .../libs/cairo/cairo-1.14.2/src/cairo-gl-shaders.c | 1093 --- .../libs/cairo/cairo-1.14.2/src/cairo-gl-source.c | 111 - .../cairo-1.14.2/src/cairo-gl-spans-compositor.c | 553 -- .../libs/cairo/cairo-1.14.2/src/cairo-gl-surface.c | 1459 ---- .../cairo-1.14.2/src/cairo-gl-traps-compositor.c | 558 -- .../source/libs/cairo/cairo-1.14.2/src/cairo-gl.h | 155 - .../cairo/cairo-1.14.2/src/cairo-glx-context.c | 324 - .../cairo/cairo-1.14.2/src/cairo-gstate-private.h | 387 - .../libs/cairo/cairo-1.14.2/src/cairo-gstate.c | 2346 ------ .../cairo/cairo-1.14.2/src/cairo-hash-private.h | 87 - .../libs/cairo/cairo-1.14.2/src/cairo-hash.c | 578 -- .../libs/cairo/cairo-1.14.2/src/cairo-hull.c | 235 - .../cairo-1.14.2/src/cairo-image-compositor.c | 3137 -------- .../cairo-1.14.2/src/cairo-image-info-private.h | 68 - .../libs/cairo/cairo-1.14.2/src/cairo-image-info.c | 421 -- .../cairo/cairo-1.14.2/src/cairo-image-source.c | 1601 ---- .../cairo-1.14.2/src/cairo-image-surface-inline.h | 96 - .../cairo-1.14.2/src/cairo-image-surface-private.h | 238 - .../cairo/cairo-1.14.2/src/cairo-image-surface.c | 1321 ---- .../cairo/cairo-1.14.2/src/cairo-line-inline.h | 48 - .../cairo/cairo-1.14.2/src/cairo-line-private.h | 51 - .../libs/cairo/cairo-1.14.2/src/cairo-line.c | 306 - .../cairo/cairo-1.14.2/src/cairo-list-inline.h | 215 - .../cairo/cairo-1.14.2/src/cairo-list-private.h | 48 - .../source/libs/cairo/cairo-1.14.2/src/cairo-lzw.c | 404 - .../cairo/cairo-1.14.2/src/cairo-malloc-private.h | 149 - .../cairo/cairo-1.14.2/src/cairo-mask-compositor.c | 1481 ---- .../libs/cairo/cairo-1.14.2/src/cairo-matrix.c | 1212 --- .../cairo/cairo-1.14.2/src/cairo-mempool-private.h | 85 - .../libs/cairo/cairo-1.14.2/src/cairo-mempool.c | 369 - .../src/cairo-mesh-pattern-rasterizer.c | 941 --- .../libs/cairo/cairo-1.14.2/src/cairo-misc.c | 955 --- .../cairo-1.14.2/src/cairo-mono-scan-converter.c | 612 -- .../cairo-1.14.2/src/cairo-mutex-impl-private.h | 278 - .../cairo-1.14.2/src/cairo-mutex-list-private.h | 78 - .../cairo/cairo-1.14.2/src/cairo-mutex-private.h | 67 - .../cairo-1.14.2/src/cairo-mutex-type-private.h | 194 - .../libs/cairo/cairo-1.14.2/src/cairo-mutex.c | 82 - .../cairo/cairo-1.14.2/src/cairo-no-compositor.c | 107 - .../libs/cairo/cairo-1.14.2/src/cairo-observer.c | 52 - .../cairo/cairo-1.14.2/src/cairo-os2-private.h | 67 - .../cairo/cairo-1.14.2/src/cairo-os2-surface.c | 1415 ---- .../source/libs/cairo/cairo-1.14.2/src/cairo-os2.h | 110 - .../cairo-1.14.2/src/cairo-output-stream-private.h | 201 - .../cairo/cairo-1.14.2/src/cairo-output-stream.c | 802 -- .../cairo-1.14.2/src/cairo-paginated-private.h | 168 - .../src/cairo-paginated-surface-private.h | 62 - .../cairo-1.14.2/src/cairo-paginated-surface.c | 716 -- .../cairo/cairo-1.14.2/src/cairo-path-bounds.c | 207 - .../libs/cairo/cairo-1.14.2/src/cairo-path-fill.c | 341 - .../cairo-1.14.2/src/cairo-path-fixed-private.h | 206 - .../libs/cairo/cairo-1.14.2/src/cairo-path-fixed.c | 1589 ---- .../cairo/cairo-1.14.2/src/cairo-path-in-fill.c | 290 - .../cairo/cairo-1.14.2/src/cairo-path-private.h | 57 - .../cairo-1.14.2/src/cairo-path-stroke-boxes.c | 711 -- .../cairo-1.14.2/src/cairo-path-stroke-polygon.c | 1364 ---- .../cairo-1.14.2/src/cairo-path-stroke-traps.c | 1149 --- .../cairo-1.14.2/src/cairo-path-stroke-tristrip.c | 1088 --- .../cairo/cairo-1.14.2/src/cairo-path-stroke.c | 1485 ---- .../libs/cairo/cairo-1.14.2/src/cairo-path.c | 479 -- .../cairo/cairo-1.14.2/src/cairo-pattern-inline.h | 65 - .../cairo/cairo-1.14.2/src/cairo-pattern-private.h | 369 - .../libs/cairo/cairo-1.14.2/src/cairo-pattern.c | 4699 ------------ .../cairo-1.14.2/src/cairo-pdf-operators-private.h | 176 - .../cairo/cairo-1.14.2/src/cairo-pdf-operators.c | 1560 ---- .../cairo-1.14.2/src/cairo-pdf-shading-private.h | 100 - .../cairo/cairo-1.14.2/src/cairo-pdf-shading.c | 279 - .../cairo-1.14.2/src/cairo-pdf-surface-private.h | 218 - .../cairo/cairo-1.14.2/src/cairo-pdf-surface.c | 7880 -------------------- .../source/libs/cairo/cairo-1.14.2/src/cairo-pdf.h | 94 - .../source/libs/cairo/cairo-1.14.2/src/cairo-pen.c | 475 -- .../cairo/cairo-1.14.2/src/cairo-pixman-private.h | 51 - .../source/libs/cairo/cairo-1.14.2/src/cairo-png.c | 819 -- .../cairo-1.14.2/src/cairo-polygon-intersect.c | 1532 ---- .../cairo/cairo-1.14.2/src/cairo-polygon-reduce.c | 1438 ---- .../libs/cairo/cairo-1.14.2/src/cairo-polygon.c | 608 -- .../libs/cairo/cairo-1.14.2/src/cairo-private.h | 64 - .../cairo-1.14.2/src/cairo-ps-surface-private.h | 104 - .../libs/cairo/cairo-1.14.2/src/cairo-ps-surface.c | 4694 ------------ .../source/libs/cairo/cairo-1.14.2/src/cairo-ps.h | 116 - .../cairo/cairo-1.14.2/src/cairo-qt-surface.cpp | 1738 ----- .../source/libs/cairo/cairo-1.14.2/src/cairo-qt.h | 85 - .../cairo/cairo-1.14.2/src/cairo-quartz-font.c | 859 --- .../cairo-1.14.2/src/cairo-quartz-image-surface.c | 387 - .../cairo/cairo-1.14.2/src/cairo-quartz-image.h | 59 - .../cairo/cairo-1.14.2/src/cairo-quartz-private.h | 109 - .../cairo/cairo-1.14.2/src/cairo-quartz-surface.c | 2574 ------- .../libs/cairo/cairo-1.14.2/src/cairo-quartz.h | 82 - .../cairo-1.14.2/src/cairo-raster-source-pattern.c | 430 -- .../src/cairo-recording-surface-inline.h | 68 - .../src/cairo-recording-surface-private.h | 195 - .../cairo-1.14.2/src/cairo-recording-surface.c | 2188 ------ .../libs/cairo/cairo-1.14.2/src/cairo-rectangle.c | 299 - .../src/cairo-rectangular-scan-converter.c | 791 -- .../src/cairo-reference-count-private.h | 62 - .../cairo/cairo-1.14.2/src/cairo-region-private.h | 77 - .../libs/cairo/cairo-1.14.2/src/cairo-region.c | 939 --- .../cairo/cairo-1.14.2/src/cairo-rtree-private.h | 142 - .../libs/cairo/cairo-1.14.2/src/cairo-rtree.c | 388 - .../cairo-1.14.2/src/cairo-scaled-font-private.h | 183 - .../src/cairo-scaled-font-subsets-private.h | 735 -- .../cairo-1.14.2/src/cairo-scaled-font-subsets.c | 1299 ---- .../cairo/cairo-1.14.2/src/cairo-scaled-font.c | 3158 -------- .../cairo/cairo-1.14.2/src/cairo-script-private.h | 59 - .../cairo/cairo-1.14.2/src/cairo-script-surface.c | 3999 ---------- .../libs/cairo/cairo-1.14.2/src/cairo-script.h | 98 - .../cairo-1.14.2/src/cairo-shape-mask-compositor.c | 340 - .../libs/cairo/cairo-1.14.2/src/cairo-skia.h | 66 - .../cairo/cairo-1.14.2/src/cairo-slope-private.h | 72 - .../libs/cairo/cairo-1.14.2/src/cairo-slope.c | 99 - .../src/cairo-spans-compositor-private.h | 111 - .../cairo-1.14.2/src/cairo-spans-compositor.c | 1201 --- .../cairo/cairo-1.14.2/src/cairo-spans-private.h | 206 - .../libs/cairo/cairo-1.14.2/src/cairo-spans.c | 250 - .../libs/cairo/cairo-1.14.2/src/cairo-spline.c | 424 -- .../cairo-1.14.2/src/cairo-stroke-dash-private.h | 70 - .../cairo/cairo-1.14.2/src/cairo-stroke-dash.c | 96 - .../cairo/cairo-1.14.2/src/cairo-stroke-style.c | 354 - .../src/cairo-surface-backend-private.h | 221 - .../src/cairo-surface-clipper-private.h | 71 - .../cairo/cairo-1.14.2/src/cairo-surface-clipper.c | 196 - .../src/cairo-surface-fallback-private.h | 95 - .../cairo-1.14.2/src/cairo-surface-fallback.c | 115 - .../cairo/cairo-1.14.2/src/cairo-surface-inline.h | 60 - .../src/cairo-surface-observer-inline.h | 59 - .../src/cairo-surface-observer-private.h | 208 - .../cairo-1.14.2/src/cairo-surface-observer.c | 2106 ------ .../src/cairo-surface-offset-private.h | 95 - .../cairo/cairo-1.14.2/src/cairo-surface-offset.c | 308 - .../cairo/cairo-1.14.2/src/cairo-surface-private.h | 121 - .../src/cairo-surface-snapshot-inline.h | 67 - .../src/cairo-surface-snapshot-private.h | 51 - .../cairo-1.14.2/src/cairo-surface-snapshot.c | 289 - .../src/cairo-surface-subsurface-inline.h | 72 - .../src/cairo-surface-subsurface-private.h | 55 - .../cairo-1.14.2/src/cairo-surface-subsurface.c | 587 -- .../src/cairo-surface-wrapper-private.h | 193 - .../cairo/cairo-1.14.2/src/cairo-surface-wrapper.c | 685 -- .../libs/cairo/cairo-1.14.2/src/cairo-surface.c | 2749 ------- .../cairo-1.14.2/src/cairo-svg-surface-private.h | 74 - .../cairo/cairo-1.14.2/src/cairo-svg-surface.c | 2884 ------- .../source/libs/cairo/cairo-1.14.2/src/cairo-svg.h | 84 - .../cairo-1.14.2/src/cairo-tee-surface-private.h | 47 - .../cairo/cairo-1.14.2/src/cairo-tee-surface.c | 602 -- .../source/libs/cairo/cairo-1.14.2/src/cairo-tee.h | 66 - .../cairo/cairo-1.14.2/src/cairo-time-private.h | 94 - .../libs/cairo/cairo-1.14.2/src/cairo-time.c | 225 - .../cairo-1.14.2/src/cairo-tor-scan-converter.c | 1899 ----- .../cairo-1.14.2/src/cairo-tor22-scan-converter.c | 1709 ----- .../cairo/cairo-1.14.2/src/cairo-toy-font-face.c | 524 -- .../cairo-1.14.2/src/cairo-traps-compositor.c | 2351 ------ .../cairo/cairo-1.14.2/src/cairo-traps-private.h | 143 - .../libs/cairo/cairo-1.14.2/src/cairo-traps.c | 1123 --- .../cairo-1.14.2/src/cairo-tristrip-private.h | 94 - .../libs/cairo/cairo-1.14.2/src/cairo-tristrip.c | 185 - .../src/cairo-truetype-subset-private.h | 212 - .../cairo/cairo-1.14.2/src/cairo-truetype-subset.c | 1631 ---- .../cairo/cairo-1.14.2/src/cairo-type1-fallback.c | 903 --- .../cairo-1.14.2/src/cairo-type1-glyph-names.c | 410 - .../cairo/cairo-1.14.2/src/cairo-type1-private.h | 51 - .../cairo/cairo-1.14.2/src/cairo-type1-subset.c | 1821 ----- .../src/cairo-type3-glyph-surface-private.h | 89 - .../cairo-1.14.2/src/cairo-type3-glyph-surface.c | 568 -- .../cairo/cairo-1.14.2/src/cairo-types-private.h | 429 -- .../libs/cairo/cairo-1.14.2/src/cairo-unicode.c | 422 -- .../cairo/cairo-1.14.2/src/cairo-uninstalled.pc.in | 8 - .../cairo-1.14.2/src/cairo-user-font-private.h | 46 - .../libs/cairo/cairo-1.14.2/src/cairo-user-font.c | 831 --- .../libs/cairo/cairo-1.14.2/src/cairo-version.c | 261 - .../libs/cairo/cairo-1.14.2/src/cairo-version.h | 14 - .../libs/cairo/cairo-1.14.2/src/cairo-vg-surface.c | 1853 ----- .../source/libs/cairo/cairo-1.14.2/src/cairo-vg.h | 103 - .../cairo/cairo-1.14.2/src/cairo-wgl-context.c | 261 - .../cairo/cairo-1.14.2/src/cairo-wideint-private.h | 338 - .../cairo-1.14.2/src/cairo-wideint-type-private.h | 158 - .../libs/cairo/cairo-1.14.2/src/cairo-wideint.c | 852 --- .../libs/cairo/cairo-1.14.2/src/cairo-win32.h | 112 - .../cairo-1.14.2/src/cairo-xcb-connection-core.c | 300 - .../cairo-1.14.2/src/cairo-xcb-connection-render.c | 299 - .../cairo-1.14.2/src/cairo-xcb-connection-shm.c | 115 - .../cairo/cairo-1.14.2/src/cairo-xcb-connection.c | 1006 --- .../cairo/cairo-1.14.2/src/cairo-xcb-private.h | 801 -- .../cairo/cairo-1.14.2/src/cairo-xcb-resources.c | 281 - .../libs/cairo/cairo-1.14.2/src/cairo-xcb-screen.c | 494 -- .../libs/cairo/cairo-1.14.2/src/cairo-xcb-shm.c | 337 - .../cairo-1.14.2/src/cairo-xcb-surface-core.c | 639 -- .../cairo-1.14.2/src/cairo-xcb-surface-render.c | 4878 ------------ .../cairo/cairo-1.14.2/src/cairo-xcb-surface.c | 1530 ---- .../source/libs/cairo/cairo-1.14.2/src/cairo-xcb.h | 116 - .../cairo-1.14.2/src/cairo-xlib-core-compositor.c | 650 -- .../cairo/cairo-1.14.2/src/cairo-xlib-display.c | 655 -- .../src/cairo-xlib-fallback-compositor.c | 248 - .../cairo/cairo-1.14.2/src/cairo-xlib-private.h | 470 -- .../src/cairo-xlib-render-compositor.c | 2005 ----- .../cairo/cairo-1.14.2/src/cairo-xlib-screen.c | 467 -- .../cairo/cairo-1.14.2/src/cairo-xlib-source.c | 1168 --- .../cairo-1.14.2/src/cairo-xlib-surface-private.h | 44 - .../cairo-1.14.2/src/cairo-xlib-surface-shm.c | 1459 ---- .../cairo/cairo-1.14.2/src/cairo-xlib-surface.c | 2383 ------ .../cairo/cairo-1.14.2/src/cairo-xlib-visual.c | 194 - .../cairo-1.14.2/src/cairo-xlib-xcb-surface.c | 847 --- .../cairo-1.14.2/src/cairo-xlib-xrender-private.h | 1173 --- .../cairo/cairo-1.14.2/src/cairo-xlib-xrender.h | 66 - .../libs/cairo/cairo-1.14.2/src/cairo-xlib.h | 118 - .../cairo/cairo-1.14.2/src/cairo-xml-surface.c | 1209 --- .../source/libs/cairo/cairo-1.14.2/src/cairo-xml.h | 67 - Build/source/libs/cairo/cairo-1.14.2/src/cairo.c | 4031 ---------- Build/source/libs/cairo/cairo-1.14.2/src/cairo.h | 3153 -------- .../source/libs/cairo/cairo-1.14.2/src/cairo.pc.in | 13 - .../source/libs/cairo/cairo-1.14.2/src/cairoint.h | 2081 ------ .../libs/cairo/cairo-1.14.2/src/check-def.sh | 48 - .../cairo/cairo-1.14.2/src/check-doc-syntax.awk | 106 - .../cairo/cairo-1.14.2/src/check-doc-syntax.sh | 82 - .../cairo-1.14.2/src/check-has-hidden-symbols.c | 3 - .../libs/cairo/cairo-1.14.2/src/check-headers.sh | 27 - .../libs/cairo/cairo-1.14.2/src/check-link.c | 24 - .../libs/cairo/cairo-1.14.2/src/check-plt.sh | 28 - .../cairo-1.14.2/src/check-preprocessor-syntax.sh | 59 - .../src/test-base-compositor-surface.c | 824 -- .../src/test-compositor-surface-private.h | 56 - .../cairo-1.14.2/src/test-compositor-surface.c | 264 - .../cairo-1.14.2/src/test-compositor-surface.h | 71 - .../src/test-null-compositor-surface.c | 480 -- .../src/test-null-compositor-surface.h | 60 - .../cairo-1.14.2/src/test-paginated-surface.c | 286 - .../cairo-1.14.2/src/test-paginated-surface.h | 48 - .../source/libs/cairo/cairo-src-PATCHES/ChangeLog | 33 + .../source/libs/cairo/cairo-src-PATCHES/TL-Changes | 33 + Build/source/libs/cairo/cairo-src/AUTHORS | 115 + Build/source/libs/cairo/cairo-src/BIBLIOGRAPHY | 109 + Build/source/libs/cairo/cairo-src/BUGS | 85 + Build/source/libs/cairo/cairo-src/CODING_STYLE | 291 + Build/source/libs/cairo/cairo-src/COPYING | 33 + Build/source/libs/cairo/cairo-src/COPYING-LGPL-2.1 | 510 ++ Build/source/libs/cairo/cairo-src/COPYING-MPL-1.1 | 470 ++ Build/source/libs/cairo/cairo-src/HACKING | 185 + Build/source/libs/cairo/cairo-src/INSTALL | 184 + Build/source/libs/cairo/cairo-src/KNOWN_ISSUES | 3 + Build/source/libs/cairo/cairo-src/Makefile.am | 83 + Build/source/libs/cairo/cairo-src/Makefile.win32 | 24 + Build/source/libs/cairo/cairo-src/NEWS | 7485 +++++++++++++++++++ Build/source/libs/cairo/cairo-src/PORTING_GUIDE | 265 + Build/source/libs/cairo/cairo-src/README | 204 + Build/source/libs/cairo/cairo-src/README.win32 | 66 + Build/source/libs/cairo/cairo-src/RELEASING | 138 + Build/source/libs/cairo/cairo-src/acinclude.m4 | 55 + Build/source/libs/cairo/cairo-src/autogen.sh | 31 + .../cairo/cairo-src/build/Makefile.am.analysis | 37 + .../cairo/cairo-src/build/Makefile.am.changelog | 82 + .../libs/cairo/cairo-src/build/Makefile.am.common | 14 + .../libs/cairo/cairo-src/build/Makefile.am.gtk-doc | 190 + .../cairo/cairo-src/build/Makefile.am.releasing | 194 + .../cairo/cairo-src/build/Makefile.win32.common | 74 + .../cairo/cairo-src/build/Makefile.win32.features | 41 + .../cairo-src/build/Makefile.win32.features-h | 130 + .../cairo/cairo-src/build/Makefile.win32.inform | 13 + .../libs/cairo/cairo-src/build/aclocal.cairo.m4 | 228 + .../libs/cairo/cairo-src/build/aclocal.compare.m4 | 162 + .../libs/cairo/cairo-src/build/aclocal.enable.m4 | 409 + .../libs/cairo/cairo-src/build/aclocal.float.m4 | 65 + .../libs/cairo/cairo-src/build/aclocal.makefile.m4 | 234 + .../libs/cairo/cairo-src/build/aclocal.pkg.m4 | 157 + .../cairo/cairo-src/build/configure.ac.analysis | 106 + .../cairo/cairo-src/build/configure.ac.features | 427 ++ .../cairo/cairo-src/build/configure.ac.noversion | 23 + .../cairo/cairo-src/build/configure.ac.pthread | 253 + .../libs/cairo/cairo-src/build/configure.ac.system | 160 + .../libs/cairo/cairo-src/build/configure.ac.tools | 25 + .../cairo/cairo-src/build/configure.ac.version | 42 + .../cairo/cairo-src/build/configure.ac.warnings | 99 + Build/source/libs/cairo/cairo-src/build/gtk-doc.m4 | 88 + Build/source/libs/cairo/cairo-src/cairo-version.h | 8 + Build/source/libs/cairo/cairo-src/config.h.in | 416 ++ Build/source/libs/cairo/cairo-src/configure.ac | 878 +++ Build/source/libs/cairo/cairo-src/src/Makefile.am | 119 + .../libs/cairo/cairo-src/src/Makefile.am.analysis | 35 + .../libs/cairo/cairo-src/src/Makefile.am.features | 657 ++ .../libs/cairo/cairo-src/src/Makefile.sources | 472 ++ .../source/libs/cairo/cairo-src/src/Makefile.win32 | 29 + .../cairo/cairo-src/src/Makefile.win32.features | 661 ++ Build/source/libs/cairo/cairo-src/src/README | 69 + .../cairo-src/src/cairo-analysis-surface-private.h | 74 + .../cairo/cairo-src/src/cairo-analysis-surface.c | 934 +++ .../libs/cairo/cairo-src/src/cairo-arc-private.h | 61 + Build/source/libs/cairo/cairo-src/src/cairo-arc.c | 312 + .../libs/cairo/cairo-src/src/cairo-array-private.h | 90 + .../source/libs/cairo/cairo-src/src/cairo-array.c | 529 ++ .../cairo/cairo-src/src/cairo-atomic-private.h | 362 + .../source/libs/cairo/cairo-src/src/cairo-atomic.c | 106 + .../cairo/cairo-src/src/cairo-backend-private.h | 201 + .../libs/cairo/cairo-src/src/cairo-base64-stream.c | 144 + .../libs/cairo/cairo-src/src/cairo-base85-stream.c | 131 + .../src/cairo-bentley-ottmann-rectangular.c | 884 +++ .../src/cairo-bentley-ottmann-rectilinear.c | 600 ++ .../cairo/cairo-src/src/cairo-bentley-ottmann.c | 1909 +++++ .../cairo/cairo-src/src/cairo-beos-surface.cpp | 984 +++ Build/source/libs/cairo/cairo-src/src/cairo-beos.h | 60 + .../cairo-src/src/cairo-botor-scan-converter.c | 2164 ++++++ .../libs/cairo/cairo-src/src/cairo-box-inline.h | 121 + .../cairo/cairo-src/src/cairo-boxes-intersect.c | 690 ++ .../libs/cairo/cairo-src/src/cairo-boxes-private.h | 123 + .../source/libs/cairo/cairo-src/src/cairo-boxes.c | 460 ++ .../libs/cairo/cairo-src/src/cairo-cache-private.h | 145 + .../source/libs/cairo/cairo-src/src/cairo-cache.c | 338 + .../libs/cairo/cairo-src/src/cairo-cff-subset.c | 3440 +++++++++ .../libs/cairo/cairo-src/src/cairo-clip-boxes.c | 599 ++ .../libs/cairo/cairo-src/src/cairo-clip-inline.h | 83 + .../libs/cairo/cairo-src/src/cairo-clip-polygon.c | 156 + .../libs/cairo/cairo-src/src/cairo-clip-private.h | 198 + .../libs/cairo/cairo-src/src/cairo-clip-region.c | 123 + .../libs/cairo/cairo-src/src/cairo-clip-surface.c | 240 + .../cairo-src/src/cairo-clip-tor-scan-converter.c | 1845 +++++ Build/source/libs/cairo/cairo-src/src/cairo-clip.c | 838 +++ .../cairo-src/src/cairo-cogl-context-private.h | 52 + .../libs/cairo/cairo-src/src/cairo-cogl-context.c | 822 ++ .../cairo-src/src/cairo-cogl-gradient-private.h | 89 + .../libs/cairo/cairo-src/src/cairo-cogl-gradient.c | 642 ++ .../libs/cairo/cairo-src/src/cairo-cogl-private.h | 164 + .../libs/cairo/cairo-src/src/cairo-cogl-surface.c | 2805 +++++++ .../cairo/cairo-src/src/cairo-cogl-utils-private.h | 54 + .../libs/cairo/cairo-src/src/cairo-cogl-utils.c | 126 + Build/source/libs/cairo/cairo-src/src/cairo-cogl.h | 69 + .../source/libs/cairo/cairo-src/src/cairo-color.c | 193 + .../cairo/cairo-src/src/cairo-combsort-inline.h | 94 + .../cairo/cairo-src/src/cairo-compiler-private.h | 244 + .../src/cairo-composite-rectangles-private.h | 159 + .../cairo-src/src/cairo-composite-rectangles.c | 500 ++ .../cairo/cairo-src/src/cairo-compositor-private.h | 365 + .../libs/cairo/cairo-src/src/cairo-compositor.c | 268 + .../cairo/cairo-src/src/cairo-contour-inline.h | 80 + .../cairo/cairo-src/src/cairo-contour-private.h | 124 + .../libs/cairo/cairo-src/src/cairo-contour.c | 453 ++ .../cairo/cairo-src/src/cairo-damage-private.h | 85 + .../source/libs/cairo/cairo-src/src/cairo-damage.c | 241 + .../source/libs/cairo/cairo-src/src/cairo-debug.c | 304 + .../cairo-src/src/cairo-default-context-private.h | 68 + .../cairo/cairo-src/src/cairo-default-context.c | 1475 ++++ .../cairo/cairo-src/src/cairo-deflate-stream.c | 156 + .../libs/cairo/cairo-src/src/cairo-deprecated.h | 123 + .../cairo/cairo-src/src/cairo-device-private.h | 86 + .../source/libs/cairo/cairo-src/src/cairo-device.c | 541 ++ .../cairo/cairo-src/src/cairo-directfb-surface.c | 544 ++ .../libs/cairo/cairo-src/src/cairo-directfb.h | 67 + Build/source/libs/cairo/cairo-src/src/cairo-drm.h | 120 + .../libs/cairo/cairo-src/src/cairo-egl-context.c | 317 + .../libs/cairo/cairo-src/src/cairo-error-inline.h | 52 + .../libs/cairo/cairo-src/src/cairo-error-private.h | 127 + .../source/libs/cairo/cairo-src/src/cairo-error.c | 73 + .../cairo-src/src/cairo-fallback-compositor.c | 185 + .../cairo-src/src/cairo-features-uninstalled.pc.in | 7 + .../libs/cairo/cairo-src/src/cairo-features.pc.in | 12 + .../libs/cairo/cairo-src/src/cairo-fixed-private.h | 395 + .../cairo/cairo-src/src/cairo-fixed-type-private.h | 75 + .../source/libs/cairo/cairo-src/src/cairo-fixed.c | 39 + .../cairo-src/src/cairo-font-face-twin-data.c | 1072 +++ .../cairo/cairo-src/src/cairo-font-face-twin.c | 752 ++ .../libs/cairo/cairo-src/src/cairo-font-face.c | 345 + .../libs/cairo/cairo-src/src/cairo-font-options.c | 535 ++ .../cairo/cairo-src/src/cairo-fontconfig-private.h | 78 + .../cairo/cairo-src/src/cairo-freed-pool-private.h | 139 + .../libs/cairo/cairo-src/src/cairo-freed-pool.c | 93 + .../cairo/cairo-src/src/cairo-freelist-private.h | 139 + .../cairo-src/src/cairo-freelist-type-private.h | 54 + .../libs/cairo/cairo-src/src/cairo-freelist.c | 191 + .../libs/cairo/cairo-src/src/cairo-ft-font.c | 3596 +++++++++ .../libs/cairo/cairo-src/src/cairo-ft-private.h | 61 + Build/source/libs/cairo/cairo-src/src/cairo-ft.h | 118 + .../libs/cairo/cairo-src/src/cairo-gl-composite.c | 1265 ++++ .../libs/cairo/cairo-src/src/cairo-gl-device.c | 804 ++ .../cairo-src/src/cairo-gl-dispatch-private.h | 129 + .../libs/cairo/cairo-src/src/cairo-gl-dispatch.c | 261 + .../cairo/cairo-src/src/cairo-gl-ext-def-private.h | 143 + .../libs/cairo/cairo-src/src/cairo-gl-glyphs.c | 503 ++ .../cairo-src/src/cairo-gl-gradient-private.h | 93 + .../libs/cairo/cairo-src/src/cairo-gl-gradient.c | 338 + .../libs/cairo/cairo-src/src/cairo-gl-info.c | 111 + .../cairo/cairo-src/src/cairo-gl-msaa-compositor.c | 944 +++ .../libs/cairo/cairo-src/src/cairo-gl-operand.c | 792 ++ .../libs/cairo/cairo-src/src/cairo-gl-private.h | 853 +++ .../libs/cairo/cairo-src/src/cairo-gl-shaders.c | 1093 +++ .../libs/cairo/cairo-src/src/cairo-gl-source.c | 111 + .../cairo-src/src/cairo-gl-spans-compositor.c | 553 ++ .../libs/cairo/cairo-src/src/cairo-gl-surface.c | 1459 ++++ .../cairo-src/src/cairo-gl-traps-compositor.c | 558 ++ Build/source/libs/cairo/cairo-src/src/cairo-gl.h | 155 + .../libs/cairo/cairo-src/src/cairo-glx-context.c | 324 + .../cairo/cairo-src/src/cairo-gstate-private.h | 387 + .../source/libs/cairo/cairo-src/src/cairo-gstate.c | 2346 ++++++ .../libs/cairo/cairo-src/src/cairo-hash-private.h | 87 + Build/source/libs/cairo/cairo-src/src/cairo-hash.c | 578 ++ Build/source/libs/cairo/cairo-src/src/cairo-hull.c | 235 + .../cairo/cairo-src/src/cairo-image-compositor.c | 3137 ++++++++ .../cairo/cairo-src/src/cairo-image-info-private.h | 68 + .../libs/cairo/cairo-src/src/cairo-image-info.c | 421 ++ .../libs/cairo/cairo-src/src/cairo-image-source.c | 1601 ++++ .../cairo-src/src/cairo-image-surface-inline.h | 96 + .../cairo-src/src/cairo-image-surface-private.h | 238 + .../libs/cairo/cairo-src/src/cairo-image-surface.c | 1321 ++++ .../libs/cairo/cairo-src/src/cairo-line-inline.h | 48 + .../libs/cairo/cairo-src/src/cairo-line-private.h | 51 + Build/source/libs/cairo/cairo-src/src/cairo-line.c | 306 + .../libs/cairo/cairo-src/src/cairo-list-inline.h | 215 + .../libs/cairo/cairo-src/src/cairo-list-private.h | 48 + Build/source/libs/cairo/cairo-src/src/cairo-lzw.c | 404 + .../cairo/cairo-src/src/cairo-malloc-private.h | 149 + .../cairo/cairo-src/src/cairo-mask-compositor.c | 1481 ++++ .../source/libs/cairo/cairo-src/src/cairo-matrix.c | 1212 +++ .../cairo/cairo-src/src/cairo-mempool-private.h | 85 + .../libs/cairo/cairo-src/src/cairo-mempool.c | 369 + .../cairo-src/src/cairo-mesh-pattern-rasterizer.c | 941 +++ Build/source/libs/cairo/cairo-src/src/cairo-misc.c | 955 +++ .../cairo-src/src/cairo-mono-scan-converter.c | 612 ++ .../cairo/cairo-src/src/cairo-mutex-impl-private.h | 278 + .../cairo/cairo-src/src/cairo-mutex-list-private.h | 78 + .../libs/cairo/cairo-src/src/cairo-mutex-private.h | 67 + .../cairo/cairo-src/src/cairo-mutex-type-private.h | 194 + .../source/libs/cairo/cairo-src/src/cairo-mutex.c | 82 + .../libs/cairo/cairo-src/src/cairo-no-compositor.c | 107 + .../libs/cairo/cairo-src/src/cairo-observer.c | 52 + .../libs/cairo/cairo-src/src/cairo-os2-private.h | 67 + .../libs/cairo/cairo-src/src/cairo-os2-surface.c | 1415 ++++ Build/source/libs/cairo/cairo-src/src/cairo-os2.h | 110 + .../cairo-src/src/cairo-output-stream-private.h | 201 + .../libs/cairo/cairo-src/src/cairo-output-stream.c | 802 ++ .../cairo/cairo-src/src/cairo-paginated-private.h | 168 + .../src/cairo-paginated-surface-private.h | 62 + .../cairo/cairo-src/src/cairo-paginated-surface.c | 716 ++ .../libs/cairo/cairo-src/src/cairo-path-bounds.c | 207 + .../libs/cairo/cairo-src/src/cairo-path-fill.c | 341 + .../cairo/cairo-src/src/cairo-path-fixed-private.h | 206 + .../libs/cairo/cairo-src/src/cairo-path-fixed.c | 1589 ++++ .../libs/cairo/cairo-src/src/cairo-path-in-fill.c | 290 + .../libs/cairo/cairo-src/src/cairo-path-private.h | 57 + .../cairo/cairo-src/src/cairo-path-stroke-boxes.c | 711 ++ .../cairo-src/src/cairo-path-stroke-polygon.c | 1364 ++++ .../cairo/cairo-src/src/cairo-path-stroke-traps.c | 1149 +++ .../cairo-src/src/cairo-path-stroke-tristrip.c | 1088 +++ .../libs/cairo/cairo-src/src/cairo-path-stroke.c | 1485 ++++ Build/source/libs/cairo/cairo-src/src/cairo-path.c | 479 ++ .../cairo/cairo-src/src/cairo-pattern-inline.h | 65 + .../cairo/cairo-src/src/cairo-pattern-private.h | 369 + .../libs/cairo/cairo-src/src/cairo-pattern.c | 4699 ++++++++++++ .../cairo-src/src/cairo-pdf-operators-private.h | 176 + .../libs/cairo/cairo-src/src/cairo-pdf-operators.c | 1560 ++++ .../cairo-src/src/cairo-pdf-shading-private.h | 100 + .../libs/cairo/cairo-src/src/cairo-pdf-shading.c | 279 + .../cairo-src/src/cairo-pdf-surface-private.h | 218 + .../libs/cairo/cairo-src/src/cairo-pdf-surface.c | 7880 ++++++++++++++++++++ Build/source/libs/cairo/cairo-src/src/cairo-pdf.h | 94 + Build/source/libs/cairo/cairo-src/src/cairo-pen.c | 475 ++ .../cairo/cairo-src/src/cairo-pixman-private.h | 51 + Build/source/libs/cairo/cairo-src/src/cairo-png.c | 819 ++ .../cairo/cairo-src/src/cairo-polygon-intersect.c | 1471 ++++ .../cairo/cairo-src/src/cairo-polygon-reduce.c | 1438 ++++ .../libs/cairo/cairo-src/src/cairo-polygon.c | 608 ++ .../libs/cairo/cairo-src/src/cairo-private.h | 64 + .../cairo/cairo-src/src/cairo-ps-surface-private.h | 104 + .../libs/cairo/cairo-src/src/cairo-ps-surface.c | 4694 ++++++++++++ Build/source/libs/cairo/cairo-src/src/cairo-ps.h | 116 + .../libs/cairo/cairo-src/src/cairo-qt-surface.cpp | 1738 +++++ Build/source/libs/cairo/cairo-src/src/cairo-qt.h | 85 + .../libs/cairo/cairo-src/src/cairo-quartz-font.c | 859 +++ .../cairo-src/src/cairo-quartz-image-surface.c | 387 + .../libs/cairo/cairo-src/src/cairo-quartz-image.h | 59 + .../cairo/cairo-src/src/cairo-quartz-private.h | 109 + .../cairo/cairo-src/src/cairo-quartz-surface.c | 2574 +++++++ .../source/libs/cairo/cairo-src/src/cairo-quartz.h | 82 + .../cairo-src/src/cairo-raster-source-pattern.c | 430 ++ .../cairo-src/src/cairo-recording-surface-inline.h | 68 + .../src/cairo-recording-surface-private.h | 195 + .../cairo/cairo-src/src/cairo-recording-surface.c | 2188 ++++++ .../libs/cairo/cairo-src/src/cairo-rectangle.c | 299 + .../src/cairo-rectangular-scan-converter.c | 791 ++ .../cairo-src/src/cairo-reference-count-private.h | 62 + .../cairo/cairo-src/src/cairo-region-private.h | 77 + .../source/libs/cairo/cairo-src/src/cairo-region.c | 939 +++ .../libs/cairo/cairo-src/src/cairo-rtree-private.h | 142 + .../source/libs/cairo/cairo-src/src/cairo-rtree.c | 388 + .../cairo-src/src/cairo-scaled-font-private.h | 183 + .../src/cairo-scaled-font-subsets-private.h | 735 ++ .../cairo-src/src/cairo-scaled-font-subsets.c | 1301 ++++ .../libs/cairo/cairo-src/src/cairo-scaled-font.c | 3158 ++++++++ .../cairo/cairo-src/src/cairo-script-private.h | 59 + .../cairo/cairo-src/src/cairo-script-surface.c | 3999 ++++++++++ .../source/libs/cairo/cairo-src/src/cairo-script.h | 98 + .../cairo-src/src/cairo-shape-mask-compositor.c | 340 + Build/source/libs/cairo/cairo-src/src/cairo-skia.h | 66 + .../libs/cairo/cairo-src/src/cairo-slope-private.h | 72 + .../source/libs/cairo/cairo-src/src/cairo-slope.c | 99 + .../cairo-src/src/cairo-spans-compositor-private.h | 111 + .../cairo/cairo-src/src/cairo-spans-compositor.c | 1201 +++ .../libs/cairo/cairo-src/src/cairo-spans-private.h | 206 + .../source/libs/cairo/cairo-src/src/cairo-spans.c | 250 + .../source/libs/cairo/cairo-src/src/cairo-spline.c | 424 ++ .../cairo-src/src/cairo-stroke-dash-private.h | 70 + .../libs/cairo/cairo-src/src/cairo-stroke-dash.c | 96 + .../libs/cairo/cairo-src/src/cairo-stroke-style.c | 354 + .../cairo-src/src/cairo-surface-backend-private.h | 221 + .../cairo-src/src/cairo-surface-clipper-private.h | 71 + .../cairo/cairo-src/src/cairo-surface-clipper.c | 196 + .../cairo-src/src/cairo-surface-fallback-private.h | 95 + .../cairo/cairo-src/src/cairo-surface-fallback.c | 115 + .../cairo/cairo-src/src/cairo-surface-inline.h | 60 + .../cairo-src/src/cairo-surface-observer-inline.h | 59 + .../cairo-src/src/cairo-surface-observer-private.h | 208 + .../cairo/cairo-src/src/cairo-surface-observer.c | 2106 ++++++ .../cairo-src/src/cairo-surface-offset-private.h | 95 + .../cairo/cairo-src/src/cairo-surface-offset.c | 308 + .../cairo/cairo-src/src/cairo-surface-private.h | 121 + .../cairo-src/src/cairo-surface-snapshot-inline.h | 67 + .../cairo-src/src/cairo-surface-snapshot-private.h | 51 + .../cairo/cairo-src/src/cairo-surface-snapshot.c | 289 + .../src/cairo-surface-subsurface-inline.h | 72 + .../src/cairo-surface-subsurface-private.h | 55 + .../cairo/cairo-src/src/cairo-surface-subsurface.c | 587 ++ .../cairo-src/src/cairo-surface-wrapper-private.h | 193 + .../cairo/cairo-src/src/cairo-surface-wrapper.c | 685 ++ .../libs/cairo/cairo-src/src/cairo-surface.c | 2749 +++++++ .../cairo-src/src/cairo-svg-surface-private.h | 74 + .../libs/cairo/cairo-src/src/cairo-svg-surface.c | 2884 +++++++ Build/source/libs/cairo/cairo-src/src/cairo-svg.h | 84 + .../cairo-src/src/cairo-tee-surface-private.h | 47 + .../libs/cairo/cairo-src/src/cairo-tee-surface.c | 602 ++ Build/source/libs/cairo/cairo-src/src/cairo-tee.h | 66 + .../libs/cairo/cairo-src/src/cairo-time-private.h | 94 + Build/source/libs/cairo/cairo-src/src/cairo-time.c | 225 + .../cairo/cairo-src/src/cairo-tor-scan-converter.c | 1899 +++++ .../cairo-src/src/cairo-tor22-scan-converter.c | 1709 +++++ .../libs/cairo/cairo-src/src/cairo-toy-font-face.c | 524 ++ .../cairo/cairo-src/src/cairo-traps-compositor.c | 2351 ++++++ .../libs/cairo/cairo-src/src/cairo-traps-private.h | 143 + .../source/libs/cairo/cairo-src/src/cairo-traps.c | 1123 +++ .../cairo/cairo-src/src/cairo-tristrip-private.h | 94 + .../libs/cairo/cairo-src/src/cairo-tristrip.c | 185 + .../cairo-src/src/cairo-truetype-subset-private.h | 212 + .../cairo/cairo-src/src/cairo-truetype-subset.c | 1631 ++++ .../cairo/cairo-src/src/cairo-type1-fallback.c | 903 +++ .../cairo/cairo-src/src/cairo-type1-glyph-names.c | 410 + .../libs/cairo/cairo-src/src/cairo-type1-private.h | 51 + .../libs/cairo/cairo-src/src/cairo-type1-subset.c | 1821 +++++ .../src/cairo-type3-glyph-surface-private.h | 89 + .../cairo-src/src/cairo-type3-glyph-surface.c | 568 ++ .../libs/cairo/cairo-src/src/cairo-types-private.h | 429 ++ .../libs/cairo/cairo-src/src/cairo-unicode.c | 422 ++ .../cairo/cairo-src/src/cairo-uninstalled.pc.in | 8 + .../cairo/cairo-src/src/cairo-user-font-private.h | 46 + .../libs/cairo/cairo-src/src/cairo-user-font.c | 831 +++ .../libs/cairo/cairo-src/src/cairo-version.c | 261 + .../libs/cairo/cairo-src/src/cairo-version.h | 14 + .../libs/cairo/cairo-src/src/cairo-vg-surface.c | 1853 +++++ Build/source/libs/cairo/cairo-src/src/cairo-vg.h | 103 + .../libs/cairo/cairo-src/src/cairo-wgl-context.c | 261 + .../cairo/cairo-src/src/cairo-wideint-private.h | 338 + .../cairo-src/src/cairo-wideint-type-private.h | 158 + .../libs/cairo/cairo-src/src/cairo-wideint.c | 852 +++ .../source/libs/cairo/cairo-src/src/cairo-win32.h | 112 + .../cairo-src/src/cairo-xcb-connection-core.c | 300 + .../cairo-src/src/cairo-xcb-connection-render.c | 299 + .../cairo/cairo-src/src/cairo-xcb-connection-shm.c | 115 + .../cairo/cairo-src/src/cairo-xcb-connection.c | 1006 +++ .../libs/cairo/cairo-src/src/cairo-xcb-private.h | 801 ++ .../libs/cairo/cairo-src/src/cairo-xcb-resources.c | 281 + .../libs/cairo/cairo-src/src/cairo-xcb-screen.c | 494 ++ .../libs/cairo/cairo-src/src/cairo-xcb-shm.c | 337 + .../cairo/cairo-src/src/cairo-xcb-surface-core.c | 639 ++ .../cairo/cairo-src/src/cairo-xcb-surface-render.c | 4881 ++++++++++++ .../libs/cairo/cairo-src/src/cairo-xcb-surface.c | 1529 ++++ Build/source/libs/cairo/cairo-src/src/cairo-xcb.h | 116 + .../cairo-src/src/cairo-xlib-core-compositor.c | 650 ++ .../libs/cairo/cairo-src/src/cairo-xlib-display.c | 655 ++ .../cairo-src/src/cairo-xlib-fallback-compositor.c | 248 + .../libs/cairo/cairo-src/src/cairo-xlib-private.h | 470 ++ .../cairo-src/src/cairo-xlib-render-compositor.c | 2005 +++++ .../libs/cairo/cairo-src/src/cairo-xlib-screen.c | 467 ++ .../libs/cairo/cairo-src/src/cairo-xlib-source.c | 1168 +++ .../cairo-src/src/cairo-xlib-surface-private.h | 44 + .../cairo/cairo-src/src/cairo-xlib-surface-shm.c | 1459 ++++ .../libs/cairo/cairo-src/src/cairo-xlib-surface.c | 2383 ++++++ .../libs/cairo/cairo-src/src/cairo-xlib-visual.c | 194 + .../cairo/cairo-src/src/cairo-xlib-xcb-surface.c | 847 +++ .../cairo-src/src/cairo-xlib-xrender-private.h | 1173 +++ .../libs/cairo/cairo-src/src/cairo-xlib-xrender.h | 66 + Build/source/libs/cairo/cairo-src/src/cairo-xlib.h | 118 + .../libs/cairo/cairo-src/src/cairo-xml-surface.c | 1209 +++ Build/source/libs/cairo/cairo-src/src/cairo-xml.h | 67 + Build/source/libs/cairo/cairo-src/src/cairo.c | 4031 ++++++++++ Build/source/libs/cairo/cairo-src/src/cairo.h | 3153 ++++++++ Build/source/libs/cairo/cairo-src/src/cairo.pc.in | 13 + Build/source/libs/cairo/cairo-src/src/cairoint.h | 2082 ++++++ Build/source/libs/cairo/cairo-src/src/check-def.sh | 48 + .../libs/cairo/cairo-src/src/check-doc-syntax.awk | 106 + .../libs/cairo/cairo-src/src/check-doc-syntax.sh | 82 + .../cairo/cairo-src/src/check-has-hidden-symbols.c | 3 + .../libs/cairo/cairo-src/src/check-headers.sh | 27 + Build/source/libs/cairo/cairo-src/src/check-link.c | 24 + Build/source/libs/cairo/cairo-src/src/check-plt.sh | 28 + .../cairo-src/src/check-preprocessor-syntax.sh | 59 + .../cairo-src/src/test-base-compositor-surface.c | 824 ++ .../src/test-compositor-surface-private.h | 56 + .../cairo/cairo-src/src/test-compositor-surface.c | 264 + .../cairo/cairo-src/src/test-compositor-surface.h | 71 + .../cairo-src/src/test-null-compositor-surface.c | 480 ++ .../cairo-src/src/test-null-compositor-surface.h | 60 + .../cairo/cairo-src/src/test-paginated-surface.c | 286 + .../cairo/cairo-src/src/test-paginated-surface.h | 48 + Build/source/libs/cairo/configure | 24 +- Build/source/libs/cairo/configure.ac | 4 +- Build/source/libs/cairo/version.ac | 2 +- 764 files changed, 214002 insertions(+), 213795 deletions(-) delete mode 100644 Build/source/libs/cairo/cairo-1.14.2-PATCHES/ChangeLog delete mode 100644 Build/source/libs/cairo/cairo-1.14.2-PATCHES/TL-Changes delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/AUTHORS delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/BIBLIOGRAPHY delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/BUGS delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/CODING_STYLE delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/COPYING delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/COPYING-LGPL-2.1 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/COPYING-MPL-1.1 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/HACKING delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/INSTALL delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/KNOWN_ISSUES delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/Makefile.am delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/Makefile.win32 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/NEWS delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/PORTING_GUIDE delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/README delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/README.win32 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/RELEASING delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/acinclude.m4 delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/autogen.sh delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.analysis delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.changelog delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.common delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.gtk-doc delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.releasing delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.common delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features-h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.inform delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/aclocal.cairo.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/aclocal.compare.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/aclocal.enable.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/aclocal.float.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/aclocal.makefile.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/aclocal.pkg.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.analysis delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.features delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.noversion delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.pthread delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.system delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.tools delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.version delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.warnings delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/build/gtk-doc.m4 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/cairo-version.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/config.h.in delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/configure.ac delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.analysis delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.features delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/Makefile.sources delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32 delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32.features delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/README delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-array-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-array.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-backend-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-base64-stream.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-base85-stream.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectangular.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectilinear.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos-surface.cpp delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-botor-scan-converter.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-box-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-intersect.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cff-subset.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-boxes.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-polygon.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-region.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-tor-scan-converter.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-color.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-combsort-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-compiler-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-debug.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-deflate-stream.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-deprecated.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-device-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-device.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-drm.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-egl-context.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-error.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-fallback-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-features-uninstalled.pc.in delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-features.pc.in delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-type-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin-data.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-options.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-fontconfig-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-type-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-font.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-composite.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-device.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-ext-def-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-glyphs.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-info.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-msaa-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-operand.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-shaders.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-source.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-spans-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-traps-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-glx-context.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-hull.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-source.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-line.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-lzw.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-malloc-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mask-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-matrix.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mesh-pattern-rasterizer.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-misc.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mono-scan-converter.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-impl-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-list-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-type-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-no-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-observer.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-bounds.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fill.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-in-fill.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-boxes.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-polygon.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-traps.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-tristrip.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-path.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pen.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-pixman-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-png.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-intersect.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-reduce.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt-surface.cpp delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-font.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-raster-source-pattern.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangle.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangular-scan-converter.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-reference-count-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-region-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-region.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-script.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-shape-mask-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-skia.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-spline.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-style.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-backend-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-inline.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-time-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-time.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor-scan-converter.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor22-scan-converter.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-toy-font-face.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-fallback.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-glyph-names.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-subset.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-types-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-unicode.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-uninstalled.pc.in delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-wgl-context.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-type-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-win32.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-core.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-render.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-shm.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-resources.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-screen.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-shm.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-core.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-render.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-core-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-display.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-fallback-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-render-compositor.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-screen.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-source.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-shm.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-visual.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xcb-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairo.pc.in delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/cairoint.h delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/src/check-def.sh delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.awk delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.sh delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/check-has-hidden-symbols.c delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/src/check-headers.sh delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/check-link.c delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/src/check-plt.sh delete mode 100755 Build/source/libs/cairo/cairo-1.14.2/src/check-preprocessor-syntax.sh delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-base-compositor-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface-private.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.h delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.c delete mode 100644 Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.h create mode 100644 Build/source/libs/cairo/cairo-src-PATCHES/ChangeLog create mode 100644 Build/source/libs/cairo/cairo-src-PATCHES/TL-Changes create mode 100644 Build/source/libs/cairo/cairo-src/AUTHORS create mode 100644 Build/source/libs/cairo/cairo-src/BIBLIOGRAPHY create mode 100644 Build/source/libs/cairo/cairo-src/BUGS create mode 100644 Build/source/libs/cairo/cairo-src/CODING_STYLE create mode 100644 Build/source/libs/cairo/cairo-src/COPYING create mode 100644 Build/source/libs/cairo/cairo-src/COPYING-LGPL-2.1 create mode 100644 Build/source/libs/cairo/cairo-src/COPYING-MPL-1.1 create mode 100644 Build/source/libs/cairo/cairo-src/HACKING create mode 100644 Build/source/libs/cairo/cairo-src/INSTALL create mode 100644 Build/source/libs/cairo/cairo-src/KNOWN_ISSUES create mode 100644 Build/source/libs/cairo/cairo-src/Makefile.am create mode 100644 Build/source/libs/cairo/cairo-src/Makefile.win32 create mode 100644 Build/source/libs/cairo/cairo-src/NEWS create mode 100644 Build/source/libs/cairo/cairo-src/PORTING_GUIDE create mode 100644 Build/source/libs/cairo/cairo-src/README create mode 100644 Build/source/libs/cairo/cairo-src/README.win32 create mode 100644 Build/source/libs/cairo/cairo-src/RELEASING create mode 100644 Build/source/libs/cairo/cairo-src/acinclude.m4 create mode 100755 Build/source/libs/cairo/cairo-src/autogen.sh create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.am.analysis create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.am.changelog create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.am.common create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.am.gtk-doc create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.am.releasing create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.win32.common create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.win32.features create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.win32.features-h create mode 100644 Build/source/libs/cairo/cairo-src/build/Makefile.win32.inform create mode 100644 Build/source/libs/cairo/cairo-src/build/aclocal.cairo.m4 create mode 100644 Build/source/libs/cairo/cairo-src/build/aclocal.compare.m4 create mode 100644 Build/source/libs/cairo/cairo-src/build/aclocal.enable.m4 create mode 100644 Build/source/libs/cairo/cairo-src/build/aclocal.float.m4 create mode 100644 Build/source/libs/cairo/cairo-src/build/aclocal.makefile.m4 create mode 100644 Build/source/libs/cairo/cairo-src/build/aclocal.pkg.m4 create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.analysis create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.features create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.noversion create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.pthread create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.system create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.tools create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.version create mode 100644 Build/source/libs/cairo/cairo-src/build/configure.ac.warnings create mode 100644 Build/source/libs/cairo/cairo-src/build/gtk-doc.m4 create mode 100644 Build/source/libs/cairo/cairo-src/cairo-version.h create mode 100644 Build/source/libs/cairo/cairo-src/config.h.in create mode 100644 Build/source/libs/cairo/cairo-src/configure.ac create mode 100644 Build/source/libs/cairo/cairo-src/src/Makefile.am create mode 100644 Build/source/libs/cairo/cairo-src/src/Makefile.am.analysis create mode 100644 Build/source/libs/cairo/cairo-src/src/Makefile.am.features create mode 100644 Build/source/libs/cairo/cairo-src/src/Makefile.sources create mode 100644 Build/source/libs/cairo/cairo-src/src/Makefile.win32 create mode 100644 Build/source/libs/cairo/cairo-src/src/Makefile.win32.features create mode 100644 Build/source/libs/cairo/cairo-src/src/README create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-arc-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-arc.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-array-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-array.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-atomic-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-atomic.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-backend-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-base64-stream.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-base85-stream.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectangular.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectilinear.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-beos-surface.cpp create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-beos.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-botor-scan-converter.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-box-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-boxes-intersect.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-boxes-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-boxes.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cache-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cache.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cff-subset.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-boxes.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-polygon.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-region.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip-tor-scan-converter.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-clip.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-context-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-context.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-cogl.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-color.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-combsort-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-compiler-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-compositor-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-contour-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-contour-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-contour.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-damage-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-damage.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-debug.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-default-context-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-default-context.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-deflate-stream.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-deprecated.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-device-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-device.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-directfb-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-directfb.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-drm.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-egl-context.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-error-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-error-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-error.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-fallback-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-features-uninstalled.pc.in create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-features.pc.in create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-fixed-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-fixed-type-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-fixed.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin-data.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-font-face.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-font-options.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-fontconfig-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-freed-pool-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-freed-pool.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-freelist-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-freelist-type-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-freelist.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-ft-font.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-ft-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-ft.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-composite.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-device.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-ext-def-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-glyphs.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-info.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-msaa-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-operand.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-shaders.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-source.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-spans-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl-traps-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gl.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-glx-context.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gstate-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-gstate.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-hash-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-hash.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-hull.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-info-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-info.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-source.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-surface-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-image-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-line-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-line-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-line.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-list-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-list-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-lzw.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-malloc-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mask-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-matrix.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mempool-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mempool.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mesh-pattern-rasterizer.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-misc.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mono-scan-converter.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mutex-impl-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mutex-list-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mutex-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mutex-type-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-mutex.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-no-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-observer.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-os2-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-os2-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-os2.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-output-stream-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-output-stream.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-paginated-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-bounds.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-fill.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-fixed-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-fixed.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-in-fill.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-boxes.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-polygon.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-traps.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-tristrip.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path-stroke.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-path.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pattern-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pattern-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pattern.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pdf.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pen.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-pixman-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-png.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-polygon-intersect.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-polygon-reduce.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-polygon.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-ps-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-ps-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-ps.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-qt-surface.cpp create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-qt.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-quartz-font.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-quartz-image-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-quartz-image.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-quartz-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-quartz-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-quartz.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-raster-source-pattern.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-recording-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-rectangle.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-rectangular-scan-converter.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-reference-count-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-region-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-region.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-rtree-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-rtree.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-scaled-font.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-script-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-script-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-script.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-shape-mask-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-skia.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-slope-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-slope.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-spans-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-spans.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-spline.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-stroke-style.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-backend-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-observer.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-offset-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-offset.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-inline.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-svg-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-svg-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-svg.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tee-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tee-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tee.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-time-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-time.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tor-scan-converter.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tor22-scan-converter.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-toy-font-face.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-traps-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-traps-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-traps.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tristrip-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-tristrip.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-type1-fallback.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-type1-glyph-names.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-type1-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-type1-subset.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-types-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-unicode.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-uninstalled.pc.in create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-user-font-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-user-font.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-version.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-version.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-vg-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-vg.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-wgl-context.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-wideint-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-wideint-type-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-wideint.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-win32.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-core.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-render.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-shm.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-resources.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-screen.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-shm.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-core.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-render.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xcb.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-core-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-display.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-fallback-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-render-compositor.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-screen.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-source.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-shm.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-visual.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-xcb-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xlib.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xml-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo-xml.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo.c create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo.h create mode 100644 Build/source/libs/cairo/cairo-src/src/cairo.pc.in create mode 100644 Build/source/libs/cairo/cairo-src/src/cairoint.h create mode 100755 Build/source/libs/cairo/cairo-src/src/check-def.sh create mode 100755 Build/source/libs/cairo/cairo-src/src/check-doc-syntax.awk create mode 100755 Build/source/libs/cairo/cairo-src/src/check-doc-syntax.sh create mode 100644 Build/source/libs/cairo/cairo-src/src/check-has-hidden-symbols.c create mode 100755 Build/source/libs/cairo/cairo-src/src/check-headers.sh create mode 100644 Build/source/libs/cairo/cairo-src/src/check-link.c create mode 100755 Build/source/libs/cairo/cairo-src/src/check-plt.sh create mode 100755 Build/source/libs/cairo/cairo-src/src/check-preprocessor-syntax.sh create mode 100644 Build/source/libs/cairo/cairo-src/src/test-base-compositor-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/test-compositor-surface-private.h create mode 100644 Build/source/libs/cairo/cairo-src/src/test-compositor-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/test-compositor-surface.h create mode 100644 Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.h create mode 100644 Build/source/libs/cairo/cairo-src/src/test-paginated-surface.c create mode 100644 Build/source/libs/cairo/cairo-src/src/test-paginated-surface.h diff --git a/Build/source/libs/README b/Build/source/libs/README index 7a310ebd24f..79f932fbc4b 100644 --- a/Build/source/libs/README +++ b/Build/source/libs/README @@ -9,7 +9,7 @@ bypassing or using the original one. See also comments in ../texk/README. -cairo 1.14.2 - checked 11mar15 +cairo 1.14.6 - checked 28dec15 http://cairographics.org/releases/ freetype2 2.6.1 - checked 4sep15 diff --git a/Build/source/libs/cairo/ChangeLog b/Build/source/libs/cairo/ChangeLog index 32528dfeaa2..0ba6bad3174 100644 --- a/Build/source/libs/cairo/ChangeLog +++ b/Build/source/libs/cairo/ChangeLog @@ -1,3 +1,9 @@ +2015-12-28 Akira Kakuto + + Import cairo-1.14.6. + * configure.ac: new source-tree-naming convention per Karl. + * version.ac: Adapted. + 2015-07-06 Peter Breitenlohner * Makefile.am: Better dependencies for 'make check'. diff --git a/Build/source/libs/cairo/README b/Build/source/libs/cairo/README index 5afa338803a..853dc23241a 100644 --- a/Build/source/libs/cairo/README +++ b/Build/source/libs/cairo/README @@ -1,14 +1,15 @@ - Building cairo-1.10.2 as part of the TL tree + Building cairo-1.14.6 as part of the TL tree ============================================ This directory libs/cairo/ uses a proxy Makefile.am to build the cairo library 'libcairo' from the unmodified source tree in -libs/cairo/cairo-x.y.z/, bypassing the original build system. +libs/cairo/cairo-src/, bypassing the original build system. -As far as applicable, the tests in libs/cairo/cairo-x.y.z/configure have +As far as applicable, the tests in libs/cairo/cairo-src/configure have been translated into equivalent test in libs/cairo/configure.ac. ============================= 2012-11-10 Taco Hoekwater 2013-04-15 Peter Breitenlohner +2015-12-28 Akira Kakuto diff --git a/Build/source/libs/cairo/cairo-1.14.2-PATCHES/ChangeLog b/Build/source/libs/cairo/cairo-1.14.2-PATCHES/ChangeLog deleted file mode 100644 index ca926256712..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2-PATCHES/ChangeLog +++ /dev/null @@ -1,29 +0,0 @@ -2015-03-11 Peter Breitenlohner - - Import cairo-1.14.2. - -2014-10-15 Peter Breitenlohner - - Import cairo-1.14.0. - -2013-09-10 Peter Breitenlohner - - Import cairo-1.12.16. - -2013-05-25 Peter Breitenlohner - - Import cairo-1.12.14. - -2012-11-16 Peter Breitenlohner - - Import cairo-1.12.8. - * patch-01-mingw (removed): Obsolete. - -2012-11-15 Peter Breitenlohner - - Import cairo-1.10.2. - * patch-01-mingw (new): Build fix for MinGW. - -2012-11-10 Taco Hoekwater - - Import cairo-1.12.8. diff --git a/Build/source/libs/cairo/cairo-1.14.2-PATCHES/TL-Changes b/Build/source/libs/cairo/cairo-1.14.2-PATCHES/TL-Changes deleted file mode 100644 index 9d7307107cf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2-PATCHES/TL-Changes +++ /dev/null @@ -1,34 +0,0 @@ -Changes applied to the cairo-1.14.2/ tree as obtained from: - http://cairographics.org/releases/cairo-1.14.2.tar.xz - -Removed: - Makefile.in - ChangeLog* - aclocal.m4 - build/ar-lib - build/compile - build/config.guess - build/config.sub - build/depcomp - build/install-sh - build/libtool.m4 - build/ltmain.sh - build/ltoptions.m4 - build/ltsugar.m4 - build/ltversion.m4 - build/lt~obsolete.m4 - build/missing - build/test-driver - configure - src/Makefile.in - -Removed unused dirs: - boilerplate - doc - perf - src/drm - src/skia - src/win32 - test - util - diff --git a/Build/source/libs/cairo/cairo-1.14.2/AUTHORS b/Build/source/libs/cairo/cairo-1.14.2/AUTHORS deleted file mode 100644 index d85696fa81c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/AUTHORS +++ /dev/null @@ -1,115 +0,0 @@ -Josh Aas Memory leak fix for quartz backend -Daniel Amelang Many (magic) floating-point optimizations -Shawn T. Amundson Build fix -Olivier Andrieu PNG backend -Peter Dennis Bartok Bug fix for clipping -Dave Beckett Build fixes, Debian packaging -Kai-Uwe Behrmann SVG bug fixes -Christian Biesinger BeOS backend -Billy Biggs Pixman code merge. Optimization. Fixes for subtle rendering bugs. -Hans Breuer win32 bug fixes, build fixes, and improvements -Brian Cameron Flag bug in Sun's X server -Carlos Garcia Campos libspectre integration into the test-suite -Andrea Canciani Bugs, quartz backend improvements and type 6/7 patterns. -Damien Carbery Build fixes -Andrew Chant Adding const where needed -Steve Chaplin Bug fixes for PNG reading -Tomasz Cholewo Bug fixes -Manu Cornet SVG build fix -Frederic Crozat Fix test suite for OPD platforms (IA64 or PPC64) -Julien Danjou XCB fixes -Radek Doulík Bug report and test case -John Ehresman Build fixes for win32 -John Ellson First font/glyph extents functions -Michael Emmel DirectFB backend -Miklós Erdélyi Fix typo leading to a crash -Behdad Esfahbod Huge piles of bug fixes, improvements, and general maintenance -Gilles Espinasse Font related fixes -Larry Ewing Test case for group-clip -Brian Ewins ATSUI maintenance (first success at making it really work) -Bertram Felgenhauer Fixes for subtle arithmetic errors -Damian Frank Build system improvements for win32 -Bdale Garbee Provided essential support for cairo achitecture sessions -Jens Granseuer Fixes to generate proper compiler flags -Laxmi Harikumar Build fix -J. Ali Harlow win32 backend updates -Bryce Harrington Test cases, bug/typo fixes -Mathias Hasselmann Significant reduction of calls to malloc -Richard Henderson "slim" macros for better shared libraries -James Henstridge Build fixes related to freetype -Graydon Hoare Support for non-render X server, first real text support -Thomas Hunger Initial version of cairo_in_stroke/fill -Thomas Jaeger Extended repeat modes for X -Björn Lindqvist Performance test cases -Kristian Høgsberg PDF backend, PS backend with meta-surfaces -Amaury Jacquot Documentation review, appplication testing -Adrian Johnson PDF backend improvement -Michael Johnson Bug fix for pre-C99 compilers -Jonathon Jongsma Fix documentation typos -Øyvind Kolås OpenVG backend, Bug fixes. Better default values. -Martin Kretzschmar Arithmetic fix for 64-bit architectures -Mathieu Lacage several bug/typo fixes -Dominic Lachowicz PDF conformance fix, fix image surface to zero out contents -Alexander Larsson Profiling and performance fixes. -Sylvestre Ledru Static analysis fixes. -Tor Lillqvist win32 build fixes, build scripts -Jinghua Luo Add bitmap glyph transformation, many freetype and glitz fixes -Luke-Jr Build fix for cross-compiling -Kjartan Maraas Several fixes for sparse, lots of debug help for multi-thread bugs -Nis Martensen Bug fix for sub paths -Jordi Mas Bug fix for cairo_show_text -Nicholas Miell Fixes for linking bugs on AMD64 -Eugeniy Meshcheryakov PS/PDF font subsetting improvements -Zakharov Mikhail Build fix for HP-UX -Christopher (Monty) Montgomery Performnace fix (subimage_copy), multi-thread testing -Tim Mooney Fix test suite to compile with Solaris compiler -Jeff Muizelaar Patient, painful, pixman code merge. Many fixes for intricacies of dashing. -Yevgen Muntyan win32 build fix -Ravi Nanjundappa Static analysis fixes, test cases, skia backend update/fixes -Declan Naughton Fix documentation typos -Peter Nilsson Glitz backend -Henning Noren Fix memory leak -Geoff Norton Build fixes -Robert O'Callahan Const-correctness fixes, several new API functions for completeness (and to help mozilla) -Ian Osgood XCB backend maintenance -Benjamin Otte Refinements to cairo/perf timing, OpenGL backend fixups, random fixes -Mike Owens Bug fixes -Emmanuel Pacaud SVG backend -Keith Packard Original concept, polygon tessellation, dashing, font metrics rewrite -Stuart Parmenter Original GDI+ backend, win32 fixes -Alfred Peng Fixes for Sun compilers and for a memory leak -Christof Petig Build fixes related to freetype -Joonas Pihlaja Huge improvements to the tessellator performance -Mart Raudsepp Build fixes -David Reveman New pattern API, glitz backend -Calum Robinson Quartz backend -Pavel Roskin Several cleanups to eliminate warnings -Tim Rowley Quartz/ATSUI fixes, X server workarounds, win32 glyph path support, test case to expose gradient regression -Soeren Sandmann Lots of MMX love for pixman compositing -Uli Schlachter Some more XCB fixes -Torsten Schönfeld Build fixes -Jamey Sharp Surface/font backend virtualization, XCB backend -Jason Dorje Short Build fixes and bug fixes -Jeff Smith Fixes for intricacies of stroking code -Travis Spencer XCB backend fix -Bill Spitzak Build fix to find Xrender.h without xrender.pc, downscaling support -Zhe Su Add support for fontconfig's embeddedbitmap option -Owen Taylor Font rewrite, documentation, win32 backend -Pierre Tardy EGL support and testing, OpenVG backend -Karl Tomlinson Optimisation and obscure bug fixes (mozilla) -Alp Toker Fix several code/comment typos -Malcolm Tredinnick Documentation fixes -David Turner Optimize gradient calculations -Kalle Vahlman Allow perf reports to be compared across different platforms -Sasha Vasko Build fix to compile without xlib backend -Vladimir Vukicevic Quartz backend rewrite, win32/quartz maintenance -Jonathan Watt win32 fixes -Peter Weilbacher OS/2 backend -Dan Williams Implemnt MMX function to help OLPC -Chris Wilson Large-scale robustness improvements, (warn_unsed_result and malloc failure injection) -Carl Worth Original library, support for paths, images -Richard D. Worth Build fixes for cygwin -Kent Worsnop Fix PDF dashing bug -Dave Yeo Build fix for win32 - -(please let us know if we have missed anyone) diff --git a/Build/source/libs/cairo/cairo-1.14.2/BIBLIOGRAPHY b/Build/source/libs/cairo/cairo-1.14.2/BIBLIOGRAPHY deleted file mode 100644 index 90a6cef205b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/BIBLIOGRAPHY +++ /dev/null @@ -1,109 +0,0 @@ -Here's an effort to document some of the academic work that was -referenced during the implementation of cairo. It is presented in the -context of operations as they would be performed by either -cairo_stroke() or cairo_fill(): - -Given a Bézier path, approximate it with line segments: - - The deCasteljau algorithm - "Outillages methodes calcul", P de Casteljau, technical - report, - Andre Citroen Automobiles SA, Paris, 1959 - - That technical report might be "hard" to find, but fortunately - this algorithm will be described in any reasonable textbook on - computational geometry. Two that have been recommended by - cairo contributors are: - - "Computational Geometry, Algorithms and Applications", M. de - Berg, M. van Kreveld, M. Overmars, M. Schwarzkopf; - Springer-Verlag, ISBN: 3-540-65620-0. - - "Computational Geometry in C (Second Edition)", Joseph - O'Rourke, Cambridge University Press, ISBN 0521640105. - -Then, if stroking, construct a polygonal representation of the pen -approximating a circle (if filling skip three steps): - - "Good approximation of circles by curvature-continuous Bezier - curves", Tor Dokken and Morten Daehlen, Computer Aided - Geometric Design 8 (1990) 22-41. - -Add points to that pen based on the initial/final path faces and take -the convex hull: - - Convex hull algorithm - - [Again, see your favorite computational geometry - textbook. Should cite the name of the algorithm cairo uses - here, if it has a name.] - -Now, "convolve" the "tracing" of the pen with the tracing of the path: - - "A Kinetic Framework for Computational Geometry", Leonidas - J. Guibas, Lyle Ramshaw, and Jorge Stolfi, Proceedings of the - 24th IEEE Annual Symposium on Foundations of Computer Science - (FOCS), November 1983, 100-111. - -The result of the convolution is a polygon that must be filled. A fill -operations begins here. We use a very conventional Bentley-Ottmann -pass for computing the intersections, informed by some hints on robust -implementation courtesy of John Hobby: - - John D. Hobby, Practical Segment Intersection with Finite - Precision Output, Computation Geometry Theory and - Applications, 13(4), 1999. - - http://cm.bell-labs.com/who/hobby/93_2-27.pdf - -Hobby's primary contribution in that paper is his "tolerance square" -algorithm for robustness against edges being "bent" due to restricting -intersection coordinates to the grid available by finite-precision -arithmetic. This is one algorithm we have not implemented yet. - -We use a data-structure called Skiplists in the our implementation -of Bentley-Ottmann: - - W. Pugh, Skip Lists: a Probabilistic Alternative to Balanced Trees, - Communications of the ACM, vol. 33, no. 6, pp.668-676, 1990. - - http://citeseer.ist.psu.edu/pugh90skip.html - -The random number generator used in our skip list implementation is a -very small generator by Hars and Petruska. The generator is based on -an invertable function on Z_{2^32} with full period and is described -in - - Hars L. and Petruska G., - ``Pseudorandom Recursions: Small and Fast Pseurodandom - Number Generators for Embedded Applications'', - Hindawi Publishing Corporation - EURASIP Journal on Embedded Systems - Volume 2007, Article ID 98417, 13 pages - doi:10.1155/2007/98417 - - http://www.hindawi.com/getarticle.aspx?doi=10.1155/2007/98417&e=cta - -From the result of the intersection-finding pass, we are currently -computing a tessellation of trapezoids, (the exact manner is -undergoing some work right now with some important speedup), but we -may want to rasterize directly from those edges at some point. - -Given the set of tessellated trapezoids, we currently execute a -straightforward, (and slow), point-sampled rasterization, (and -currently with a near-pessimal regular 15x17 grid). - -We've now computed a mask which gets fed along with the source and -destination into cairo's fundamental rendering equation. The most -basic form of this equation is: - - destination = (source IN mask) OP destination - -with the restriction that no part of the destination outside the -current clip region is affected. In this equation, IN refers to the -Porter-Duff "in" operation, while OP refers to a any user-selected -Porter-Duff operator: - - T. Porter & T. Duff, Compositing Digital Images Computer - Graphics Volume 18, Number 3 July 1984 pp 253-259 - - http://keithp.com/~keithp/porterduff/p253-porter.pdf diff --git a/Build/source/libs/cairo/cairo-1.14.2/BUGS b/Build/source/libs/cairo/cairo-1.14.2/BUGS deleted file mode 100644 index ef044046d3e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/BUGS +++ /dev/null @@ -1,85 +0,0 @@ -If you find a bug in cairo we would love to hear about it. We're also -trying to make cairo better, and learning about the bugs that users -encounter is an essential part of that. So we really appreciate the -extra effort users put in to providing high-quality bug reports. - -There are two acceptable ways to report cairo bugs, and you can choose -which you prefer: - -1) Bugzilla bug tracking database: - - You can use the following web interface to report new bugs, follow - up on previous bug reports, and search for existing, known - bugs. Just use the "cairo" product: - - http://bugs.freedesktop.org - - It is necessary to go through a quick account creation process, - (with email address verification), in order to be able to report - new bugs in bugzilla. We apologize for any inconvenience that might - cause, and hope it won't prevent you from reporting bugs. - -2) Cairo mailing list: - - For people who cannot stand the bugzilla interface, you can just - send an email to cairo mailing list (cairo@cairographics.org). The - mailing list only allows posting from subscribers, so use the - following page for subscription instructions: - - http://cairographics.org/lists - - Again, we apologize for any inconvenience this subscription step - might cause, but we've found it necessary to require this in order - to enjoy spam-free discussions on the list. - - If you don't actually _want_ to be a subscriber to the mailing - list, but just want to be able to send a message, the easiest thing - to do is to go through the subscription process, and then use the - preferences page to disable message delivery to your address. - -Which of the above you use to report bugs depends on your own -preferences. Some people find just typing an email message much easier -than using the web-based forms on bugzilla. Others greatly prefer the -ability to check back on a specific bug entry in bugzilla without -having to ask on the mailing list if an issue has been resolved. - -Regardless of which method you use, here are some general tips that -will help you improve the quality of your bug report, (which will help -in getting the bug fixed sooner): - -1) Check to see if the bug has been reported already. It's pretty easy - to run a search or two against the cairo product in the - http://bugs.freedesktop.org bugzilla database. Another place to - look for known bugs is the cairo ROADMAP: - - http://cairographics.org/ROADMAP - - which shows a planned schedule of releases and which bug fixes are - being planned for each release. - -2) Provide an accurate description of the bug with detailed steps for - how we can reproduce the problem. - -3) If possible provide a minimal test case demonstrating the bug. A - great test case would be a minimal self-contained function in C or - python or whatever language you are using for cairo. The function - might accept nothing more than a cairo context, (cairo_t* in C). - -4) If you feel like being particularly helpful, you could craft this - minimal test case in the form necessary for cairo's test - suite. This isn't much more work than writing a minimal - function. Just look at the cairo/test/README file and imitate the - style of existing test cases. - - If you do submit a test case, be sure to include Copyright - information, (with the standard MIT licensing blurb if you want us - to include your test in the test case). Also, including a reference - image showing the expected result will be extremely useful. - -5) Finally, the best bug report also comes attached with a patch to - cairo to fix the bug. So send this too if you have it! Otherwise, - don't worry about it and we'll try to fix cairo when we can. - -Thanks, and have fun with cairo! - --Carl diff --git a/Build/source/libs/cairo/cairo-1.14.2/CODING_STYLE b/Build/source/libs/cairo/cairo-1.14.2/CODING_STYLE deleted file mode 100644 index 95ceac04d84..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/CODING_STYLE +++ /dev/null @@ -1,291 +0,0 @@ -Cairo coding style. - -This document is intended to be a short description of the preferred -coding style for the cairo source code. Good style requires good -taste, which means this can't all be reduced to automated rules, and -there are exceptions. - -We want the code to be easy to understand and maintain, and consistent -style plays an important part in that, even if some of the specific -details seem trivial. If nothing else, this document gives a place to -put consistent answers for issues that would otherwise be arbitrary. - -Most of the guidelines here are demonstrated by examples, (which means -this document is quicker to read than it might appear given its -length). Most of the examples are positive examples that you should -imitate. The few negative examples are clearly marked with a comment -of /* Yuck! */. Please don't submit code to cairo that looks like any -of these. - -Indentation ------------ -Each new level is indented 4 more spaces than the previous level: - - if (condition) - do_something (); - -This may be achieved with space characters or a combination of tab -characters and space characters. It may not be achieved with tab -characters exclusively (see below). - -Tab characters --------------- -The tab character must always be interpreted according to its -traditional meaning: - - Advance to the next column which is a multiple of 8. - -With this definition, even levels of indentation can be achieved with -a sequence of tab characters, while odd levels of indentation may -begin with a sequence of tab character but must end with 4 space -characters. - -Some programmers have been misled by certain text editors into -thinking that 4-space indentation can be achieved with tab characters -exclusively by changing the meaning of tab character to be "advance to -the next column which is a multiple of 4". Code formatted in this way, -making an assumption of a fictitious 4-character-tab will not be -accepted into cairo. - -The rationale here is that tabs are used in the code for lining things -up other than indentation, (see the Whitespace section below), and -changing the interpretation of tab from its traditional meaning will -break this alignment. - -Braces ------- -Most of the code in cairo uses bracing in the style of K&R: - - if (condition) { - do_this (); - do_that (); - } else { - do_the_other (); - } - -but some of the code uses an alternate style: - - if (condition) - { - do_this (); - do_that (); - } - else - { - do_the_other (); - } - -and that seems just fine. We won't lay down any strict rule on this -point, (though there should be some local consistency). If you came -here hoping to find some guidance, then use the first form above. - -If all of the substatements of an if statement are single statements, -the optional braces should not usually appear: - - if (condition) - do_this (); - else - do_that (); - -But the braces are mandatory when mixing single statement and compound -statements in the various clauses. For example, do not do this: - - if (condition) { - do_this (); - do_that (); - } else /* Yuck! */ - do_the_other (); - -And of course, there are exceptions for when the code just looks -better with the braces: - - if (condition) { - /* Note that we have to be careful here. */ - do_something_dangerous (with_care); - } - - if (condition && - other_condition && - yet_another) - { - do_something (); - } - -And note that this last example also shows a situation in which the -opening brace really needs to be on its own line. The following looks awful: - - if (condition && - other_condition && - yet_another) { /* Yuck! */ - do_something (); - } - -As we said above, legible code that is easy to understand and maintain -is the goal, not adherence to strict rules. - -Whitespace ----------- -Separate logically distinct chunks with a single newline. This -obviously applies between functions, but also applies within a -function or block and can even be used to good effect within a -structure definition: - - struct _cairo_gstate { - cairo_operator_t op; - - double tolerance; - - /* stroke style */ - double line_width; - cairo_line_cap_t line_cap; - cairo_line_join_t line_join; - double miter_limit; - - cairo_fill_rule_t fill_rule; - - double *dash; - int num_dashes; - double dash_offset; - - ... - } - -Use a single space before a left parenthesis, except where the -standard will not allow it, (eg. when defining a parameterized macro). - -Don't eliminate newlines just because things would still fit on one -line. This breaks the expected visual structure of the code making it -much harder to read and understand: - - if (condition) foo (); else bar (); /* Yuck! */ - -Do eliminate trailing whitespace (space or tab characters) on any -line. Also, avoid putting initial or final blank lines into any file, -and never use multiple blank lines instead of a single blank line. - -Do enable the default git pre-commit hook that detect trailing -whitespace for you and help you to avoid corrupting cairo's tree with -it. Do that as follows: - - chmod a+x .git/hooks/pre-commit - -You might also find the git-stripspace utility helpful which acts as a -filter to remove trailing whitespace as well as initial, final, and -duplicate blank lines. - -As a special case of the bracing and whitespace guidelines, function -definitions should always take the following form: - - void - my_function (argument) - { - do_my_things (); - } - -And function prototypes should similarly have the return type (and -associated specifiers and qualifiers) on a line above the function, so -that the function name is flush left. - -Break up long lines (> ~80 characters) and use whitespace to align -things nicely. For example the arguments in a long list to a function -call should all be aligned with each other: - - align_function_arguments (argument_the_first, - argument_the_second, - argument_the_third); - -And as a special rule, in a function prototype, (as well as in the -definition), whitespace should be inserted between the parameter types -and names so that the names are aligned: - - void - align_parameter_names_in_prototypes (const char *char_star_arg, - int int_arg, - double *double_star_arg, - double double_arg); - -Note that parameters with a * prefix are aligned one character to the -left so that the actual names are aligned. - -Managing nested blocks ----------------------- -Long blocks that are deeply nested make the code very hard to -read. Fortunately such blocks often indicate logically distinct chunks -of functionality that are begging to be split into their own -functions. Please listen to the blocks when they beg. - -In other cases, gratuitous nesting comes about because the primary -functionality gets buried in a nested block rather than living at the -primary level where it belongs. Consider the following: - - foo = malloc (sizeof (foo_t)); - if (foo) { /* Yuck! */ - ... - /* lots of code to initialize foo */ - ... - return SUCCESS; - } - return FAILURE; - -This kind of gratuitous nesting can be avoided by following a pattern -of handling exceptional cases early and returning: - - foo = malloc (sizeof (foo_t)); - if (foo == NULL) - return FAILURE; - - ... - /* lots of code to initialize foo */ - ... - return SUCCESS; - -The return statement is often the best thing to use in a pattern like -this. If it's not available due to additional nesting above which -require some cleanup after the current block, then consider splitting -the current block into a new function before using goto. - -Memory allocation ------------------ - -Because much of cairo's data consists of dynamically allocated arrays, -it's very easy to introduce integer overflow issues whenever malloc() -is called. Use the _cairo_malloc2(), _cairo_malloc3(), and -_cairo_malloc2_add1 macros to avoid these cases; these macros check -for overflow and will return NULL in that case. - - malloc (n * size) => _cairo_malloc_ab (n, size) - e.g. malloc (num_elts * sizeof(some_type)) => - _cairo_malloc2 (num_elts, sizeof(some_type)) - - malloc (a * b * size) => _cairo_malloc_abc (a, b, size) - e.g. malloc (width * height * 4) => - _cairo_malloc3 (width, height, 4) - - malloc (n * size + k) => _cairo_malloc_ab_plus_c (n, size, k) - e.g. malloc (num * sizeof(entry) + sizeof(header)) => - _cairo_malloc2k (num, sizeof(entry), sizeof(header)) - -In general, be wary of performing any arithmetic operations in an -argument to malloc. You should explicitly check for integer overflow -yourself in any more complex situations. - -Mode lines ----------- - -So given the rules above, what is the best way to simplify one's life as -a code monkey? Get your editor to do most of the tedious work of -beautifying your code! - -As a reward for reading this far, here are some mode lines for the more -popular editors: -/* - * vim:sw=4:sts=4:ts=8:tw=78:fo=tcroq:cindent:cino=\:0,(0 - * vim:isk=a-z,A-Z,48-57,_,.,-,> - */ - - -TODO ----- - -Write rules for common editors to use this style. Also cleanup/unify -the modelines in the source files. diff --git a/Build/source/libs/cairo/cairo-1.14.2/COPYING b/Build/source/libs/cairo/cairo-1.14.2/COPYING deleted file mode 100644 index f54969f1c94..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/COPYING +++ /dev/null @@ -1,33 +0,0 @@ -Cairo is free software. - -Every source file in the implementation[*] of cairo is available to be -redistributed and/or modified under the terms of either the GNU Lesser -General Public License (LGPL) version 2.1 or the Mozilla Public -License (MPL) version 1.1. Some files are available under more -liberal terms, but we believe that in all cases, each file may be used -under either the LGPL or the MPL. - -See the following files in this directory for the precise terms and -conditions of either license: - - COPYING-LGPL-2.1 - COPYING-MPL-1.1 - -Please see each file in the implementation for copyright and licensing -information, (in the opening comment of each file). - -[*] The implementation of cairo is contained entirely within the "src" -directory of the cairo source distribution. There are other components -of the cairo source distribution (such as the "test", "util", and "perf") -that are auxiliary to the library itself. None of the source code in these -directories contributes to a build of the cairo library itself, (libcairo.so -or cairo.dll or similar). - -These auxiliary components are also free software, but may be under -different license terms than cairo itself. For example, most of the -test cases in the perf and test directories are made available under -an MIT license to simplify any use of this code for reference purposes -in using cairo itself. Other files might be available under the GNU -General Public License (GPL), for example. Again, please see the COPYING -file under each directory and the opening comment of each file for copyright -and licensing information. diff --git a/Build/source/libs/cairo/cairo-1.14.2/COPYING-LGPL-2.1 b/Build/source/libs/cairo/cairo-1.14.2/COPYING-LGPL-2.1 deleted file mode 100644 index f1ed6182c52..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/COPYING-LGPL-2.1 +++ /dev/null @@ -1,510 +0,0 @@ - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations -below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it -becomes a de-facto standard. To achieve this, non-free programs must -be allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control -compilation and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at least - three years, to give the same user the materials specified in - Subsection 6a, above, for a charge no more than the cost of - performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply, and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License -may add an explicit geographical distribution limitation excluding those -countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms -of the ordinary General Public License). - - To apply these terms, attach the following notices to the library. -It is safest to attach them to the start of each source file to most -effectively convey the exclusion of warranty; and each file should -have at least the "copyright" line and a pointer to where the full -notice is found. - - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or -your school, if any, to sign a "copyright disclaimer" for the library, -if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James - Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/Build/source/libs/cairo/cairo-1.14.2/COPYING-MPL-1.1 b/Build/source/libs/cairo/cairo-1.14.2/COPYING-MPL-1.1 deleted file mode 100644 index 7714141d154..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/COPYING-MPL-1.1 +++ /dev/null @@ -1,470 +0,0 @@ - MOZILLA PUBLIC LICENSE - Version 1.1 - - --------------- - -1. Definitions. - - 1.0.1. "Commercial Use" means distribution or otherwise making the - Covered Code available to a third party. - - 1.1. "Contributor" means each entity that creates or contributes to - the creation of Modifications. - - 1.2. "Contributor Version" means the combination of the Original - Code, prior Modifications used by a Contributor, and the Modifications - made by that particular Contributor. - - 1.3. "Covered Code" means the Original Code or Modifications or the - combination of the Original Code and Modifications, in each case - including portions thereof. - - 1.4. "Electronic Distribution Mechanism" means a mechanism generally - accepted in the software development community for the electronic - transfer of data. - - 1.5. "Executable" means Covered Code in any form other than Source - Code. - - 1.6. "Initial Developer" means the individual or entity identified - as the Initial Developer in the Source Code notice required by Exhibit - A. - - 1.7. "Larger Work" means a work which combines Covered Code or - portions thereof with code not governed by the terms of this License. - - 1.8. "License" means this document. - - 1.8.1. "Licensable" means having the right to grant, to the maximum - extent possible, whether at the time of the initial grant or - subsequently acquired, any and all of the rights conveyed herein. - - 1.9. "Modifications" means any addition to or deletion from the - substance or structure of either the Original Code or any previous - Modifications. When Covered Code is released as a series of files, a - Modification is: - A. Any addition to or deletion from the contents of a file - containing Original Code or previous Modifications. - - B. Any new file that contains any part of the Original Code or - previous Modifications. - - 1.10. "Original Code" means Source Code of computer software code - which is described in the Source Code notice required by Exhibit A as - Original Code, and which, at the time of its release under this - License is not already Covered Code governed by this License. - - 1.10.1. "Patent Claims" means any patent claim(s), now owned or - hereafter acquired, including without limitation, method, process, - and apparatus claims, in any patent Licensable by grantor. - - 1.11. "Source Code" means the preferred form of the Covered Code for - making modifications to it, including all modules it contains, plus - any associated interface definition files, scripts used to control - compilation and installation of an Executable, or source code - differential comparisons against either the Original Code or another - well known, available Covered Code of the Contributor's choice. The - Source Code can be in a compressed or archival form, provided the - appropriate decompression or de-archiving software is widely available - for no charge. - - 1.12. "You" (or "Your") means an individual or a legal entity - exercising rights under, and complying with all of the terms of, this - License or a future version of this License issued under Section 6.1. - For legal entities, "You" includes any entity which controls, is - controlled by, or is under common control with You. For purposes of - this definition, "control" means (a) the power, direct or indirect, - to cause the direction or management of such entity, whether by - contract or otherwise, or (b) ownership of more than fifty percent - (50%) of the outstanding shares or beneficial ownership of such - entity. - -2. Source Code License. - - 2.1. The Initial Developer Grant. - The Initial Developer hereby grants You a world-wide, royalty-free, - non-exclusive license, subject to third party intellectual property - claims: - (a) under intellectual property rights (other than patent or - trademark) Licensable by Initial Developer to use, reproduce, - modify, display, perform, sublicense and distribute the Original - Code (or portions thereof) with or without Modifications, and/or - as part of a Larger Work; and - - (b) under Patents Claims infringed by the making, using or - selling of Original Code, to make, have made, use, practice, - sell, and offer for sale, and/or otherwise dispose of the - Original Code (or portions thereof). - - (c) the licenses granted in this Section 2.1(a) and (b) are - effective on the date Initial Developer first distributes - Original Code under the terms of this License. - - (d) Notwithstanding Section 2.1(b) above, no patent license is - granted: 1) for code that You delete from the Original Code; 2) - separate from the Original Code; or 3) for infringements caused - by: i) the modification of the Original Code or ii) the - combination of the Original Code with other software or devices. - - 2.2. Contributor Grant. - Subject to third party intellectual property claims, each Contributor - hereby grants You a world-wide, royalty-free, non-exclusive license - - (a) under intellectual property rights (other than patent or - trademark) Licensable by Contributor, to use, reproduce, modify, - display, perform, sublicense and distribute the Modifications - created by such Contributor (or portions thereof) either on an - unmodified basis, with other Modifications, as Covered Code - and/or as part of a Larger Work; and - - (b) under Patent Claims infringed by the making, using, or - selling of Modifications made by that Contributor either alone - and/or in combination with its Contributor Version (or portions - of such combination), to make, use, sell, offer for sale, have - made, and/or otherwise dispose of: 1) Modifications made by that - Contributor (or portions thereof); and 2) the combination of - Modifications made by that Contributor with its Contributor - Version (or portions of such combination). - - (c) the licenses granted in Sections 2.2(a) and 2.2(b) are - effective on the date Contributor first makes Commercial Use of - the Covered Code. - - (d) Notwithstanding Section 2.2(b) above, no patent license is - granted: 1) for any code that Contributor has deleted from the - Contributor Version; 2) separate from the Contributor Version; - 3) for infringements caused by: i) third party modifications of - Contributor Version or ii) the combination of Modifications made - by that Contributor with other software (except as part of the - Contributor Version) or other devices; or 4) under Patent Claims - infringed by Covered Code in the absence of Modifications made by - that Contributor. - -3. Distribution Obligations. - - 3.1. Application of License. - The Modifications which You create or to which You contribute are - governed by the terms of this License, including without limitation - Section 2.2. The Source Code version of Covered Code may be - distributed only under the terms of this License or a future version - of this License released under Section 6.1, and You must include a - copy of this License with every copy of the Source Code You - distribute. You may not offer or impose any terms on any Source Code - version that alters or restricts the applicable version of this - License or the recipients' rights hereunder. However, You may include - an additional document offering the additional rights described in - Section 3.5. - - 3.2. Availability of Source Code. - Any Modification which You create or to which You contribute must be - made available in Source Code form under the terms of this License - either on the same media as an Executable version or via an accepted - Electronic Distribution Mechanism to anyone to whom you made an - Executable version available; and if made available via Electronic - Distribution Mechanism, must remain available for at least twelve (12) - months after the date it initially became available, or at least six - (6) months after a subsequent version of that particular Modification - has been made available to such recipients. You are responsible for - ensuring that the Source Code version remains available even if the - Electronic Distribution Mechanism is maintained by a third party. - - 3.3. Description of Modifications. - You must cause all Covered Code to which You contribute to contain a - file documenting the changes You made to create that Covered Code and - the date of any change. You must include a prominent statement that - the Modification is derived, directly or indirectly, from Original - Code provided by the Initial Developer and including the name of the - Initial Developer in (a) the Source Code, and (b) in any notice in an - Executable version or related documentation in which You describe the - origin or ownership of the Covered Code. - - 3.4. Intellectual Property Matters - (a) Third Party Claims. - If Contributor has knowledge that a license under a third party's - intellectual property rights is required to exercise the rights - granted by such Contributor under Sections 2.1 or 2.2, - Contributor must include a text file with the Source Code - distribution titled "LEGAL" which describes the claim and the - party making the claim in sufficient detail that a recipient will - know whom to contact. If Contributor obtains such knowledge after - the Modification is made available as described in Section 3.2, - Contributor shall promptly modify the LEGAL file in all copies - Contributor makes available thereafter and shall take other steps - (such as notifying appropriate mailing lists or newsgroups) - reasonably calculated to inform those who received the Covered - Code that new knowledge has been obtained. - - (b) Contributor APIs. - If Contributor's Modifications include an application programming - interface and Contributor has knowledge of patent licenses which - are reasonably necessary to implement that API, Contributor must - also include this information in the LEGAL file. - - (c) Representations. - Contributor represents that, except as disclosed pursuant to - Section 3.4(a) above, Contributor believes that Contributor's - Modifications are Contributor's original creation(s) and/or - Contributor has sufficient rights to grant the rights conveyed by - this License. - - 3.5. Required Notices. - You must duplicate the notice in Exhibit A in each file of the Source - Code. If it is not possible to put such notice in a particular Source - Code file due to its structure, then You must include such notice in a - location (such as a relevant directory) where a user would be likely - to look for such a notice. If You created one or more Modification(s) - You may add your name as a Contributor to the notice described in - Exhibit A. You must also duplicate this License in any documentation - for the Source Code where You describe recipients' rights or ownership - rights relating to Covered Code. You may choose to offer, and to - charge a fee for, warranty, support, indemnity or liability - obligations to one or more recipients of Covered Code. However, You - may do so only on Your own behalf, and not on behalf of the Initial - Developer or any Contributor. You must make it absolutely clear than - any such warranty, support, indemnity or liability obligation is - offered by You alone, and You hereby agree to indemnify the Initial - Developer and every Contributor for any liability incurred by the - Initial Developer or such Contributor as a result of warranty, - support, indemnity or liability terms You offer. - - 3.6. Distribution of Executable Versions. - You may distribute Covered Code in Executable form only if the - requirements of Section 3.1-3.5 have been met for that Covered Code, - and if You include a notice stating that the Source Code version of - the Covered Code is available under the terms of this License, - including a description of how and where You have fulfilled the - obligations of Section 3.2. The notice must be conspicuously included - in any notice in an Executable version, related documentation or - collateral in which You describe recipients' rights relating to the - Covered Code. You may distribute the Executable version of Covered - Code or ownership rights under a license of Your choice, which may - contain terms different from this License, provided that You are in - compliance with the terms of this License and that the license for the - Executable version does not attempt to limit or alter the recipient's - rights in the Source Code version from the rights set forth in this - License. If You distribute the Executable version under a different - license You must make it absolutely clear that any terms which differ - from this License are offered by You alone, not by the Initial - Developer or any Contributor. You hereby agree to indemnify the - Initial Developer and every Contributor for any liability incurred by - the Initial Developer or such Contributor as a result of any such - terms You offer. - - 3.7. Larger Works. - You may create a Larger Work by combining Covered Code with other code - not governed by the terms of this License and distribute the Larger - Work as a single product. In such a case, You must make sure the - requirements of this License are fulfilled for the Covered Code. - -4. Inability to Comply Due to Statute or Regulation. - - If it is impossible for You to comply with any of the terms of this - License with respect to some or all of the Covered Code due to - statute, judicial order, or regulation then You must: (a) comply with - the terms of this License to the maximum extent possible; and (b) - describe the limitations and the code they affect. Such description - must be included in the LEGAL file described in Section 3.4 and must - be included with all distributions of the Source Code. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Application of this License. - - This License applies to code to which the Initial Developer has - attached the notice in Exhibit A and to related Covered Code. - -6. Versions of the License. - - 6.1. New Versions. - Netscape Communications Corporation ("Netscape") may publish revised - and/or new versions of the License from time to time. Each version - will be given a distinguishing version number. - - 6.2. Effect of New Versions. - Once Covered Code has been published under a particular version of the - License, You may always continue to use it under the terms of that - version. You may also choose to use such Covered Code under the terms - of any subsequent version of the License published by Netscape. No one - other than Netscape has the right to modify the terms applicable to - Covered Code created under this License. - - 6.3. Derivative Works. - If You create or use a modified version of this License (which you may - only do in order to apply it to code which is not already Covered Code - governed by this License), You must (a) rename Your license so that - the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", - "MPL", "NPL" or any confusingly similar phrase do not appear in your - license (except to note that your license differs from this License) - and (b) otherwise make it clear that Your version of the license - contains terms which differ from the Mozilla Public License and - Netscape Public License. (Filling in the name of the Initial - Developer, Original Code or Contributor in the notice described in - Exhibit A shall not of themselves be deemed to be modifications of - this License.) - -7. DISCLAIMER OF WARRANTY. - - COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF - DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. - THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE - IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, - YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE - COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER - OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF - ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. - -8. TERMINATION. - - 8.1. This License and the rights granted hereunder will terminate - automatically if You fail to comply with terms herein and fail to cure - such breach within 30 days of becoming aware of the breach. All - sublicenses to the Covered Code which are properly granted shall - survive any termination of this License. Provisions which, by their - nature, must remain in effect beyond the termination of this License - shall survive. - - 8.2. If You initiate litigation by asserting a patent infringement - claim (excluding declatory judgment actions) against Initial Developer - or a Contributor (the Initial Developer or Contributor against whom - You file such action is referred to as "Participant") alleging that: - - (a) such Participant's Contributor Version directly or indirectly - infringes any patent, then any and all rights granted by such - Participant to You under Sections 2.1 and/or 2.2 of this License - shall, upon 60 days notice from Participant terminate prospectively, - unless if within 60 days after receipt of notice You either: (i) - agree in writing to pay Participant a mutually agreeable reasonable - royalty for Your past and future use of Modifications made by such - Participant, or (ii) withdraw Your litigation claim with respect to - the Contributor Version against such Participant. If within 60 days - of notice, a reasonable royalty and payment arrangement are not - mutually agreed upon in writing by the parties or the litigation claim - is not withdrawn, the rights granted by Participant to You under - Sections 2.1 and/or 2.2 automatically terminate at the expiration of - the 60 day notice period specified above. - - (b) any software, hardware, or device, other than such Participant's - Contributor Version, directly or indirectly infringes any patent, then - any rights granted to You by such Participant under Sections 2.1(b) - and 2.2(b) are revoked effective as of the date You first made, used, - sold, distributed, or had made, Modifications made by that - Participant. - - 8.3. If You assert a patent infringement claim against Participant - alleging that such Participant's Contributor Version directly or - indirectly infringes any patent where such claim is resolved (such as - by license or settlement) prior to the initiation of patent - infringement litigation, then the reasonable value of the licenses - granted by such Participant under Sections 2.1 or 2.2 shall be taken - into account in determining the amount or value of any payment or - license. - - 8.4. In the event of termination under Sections 8.1 or 8.2 above, - all end user license agreements (excluding distributors and resellers) - which have been validly granted by You or any distributor hereunder - prior to termination shall survive termination. - -9. LIMITATION OF LIABILITY. - - UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT - (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL - DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, - OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR - ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY - CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, - WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER - COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN - INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF - LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY - RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW - PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE - EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO - THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. - -10. U.S. GOVERNMENT END USERS. - - The Covered Code is a "commercial item," as that term is defined in - 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer - software" and "commercial computer software documentation," as such - terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 - C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), - all U.S. Government End Users acquire Covered Code with only those - rights set forth herein. - -11. MISCELLANEOUS. - - This License represents the complete agreement concerning subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. This License shall be governed by - California law provisions (except to the extent applicable law, if - any, provides otherwise), excluding its conflict-of-law provisions. - With respect to disputes in which at least one party is a citizen of, - or an entity chartered or registered to do business in the United - States of America, any litigation relating to this License shall be - subject to the jurisdiction of the Federal Courts of the Northern - District of California, with venue lying in Santa Clara County, - California, with the losing party responsible for costs, including - without limitation, court costs and reasonable attorneys' fees and - expenses. The application of the United Nations Convention on - Contracts for the International Sale of Goods is expressly excluded. - Any law or regulation which provides that the language of a contract - shall be construed against the drafter shall not apply to this - License. - -12. RESPONSIBILITY FOR CLAIMS. - - As between Initial Developer and the Contributors, each party is - responsible for claims and damages arising, directly or indirectly, - out of its utilization of rights under this License and You agree to - work with Initial Developer and Contributors to distribute such - responsibility on an equitable basis. Nothing herein is intended or - shall be deemed to constitute any admission of liability. - -13. MULTIPLE-LICENSED CODE. - - Initial Developer may designate portions of the Covered Code as - "Multiple-Licensed". "Multiple-Licensed" means that the Initial - Developer permits you to utilize portions of the Covered Code under - Your choice of the NPL or the alternative licenses, if any, specified - by the Initial Developer in the file described in Exhibit A. - -EXHIBIT A -Mozilla Public License. - - ``The contents of this file are subject to the Mozilla Public License - Version 1.1 (the "License"); you may not use this file except in - compliance with the License. You may obtain a copy of the License at - http://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - License for the specific language governing rights and limitations - under the License. - - The Original Code is ______________________________________. - - The Initial Developer of the Original Code is ________________________. - Portions created by ______________________ are Copyright (C) ______ - _______________________. All Rights Reserved. - - Contributor(s): ______________________________________. - - Alternatively, the contents of this file may be used under the terms - of the _____ license (the "[___] License"), in which case the - provisions of [______] License are applicable instead of those - above. If you wish to allow use of your version of this file only - under the terms of the [____] License and not to allow others to use - your version of this file under the MPL, indicate your decision by - deleting the provisions above and replace them with the notice and - other provisions required by the [___] License. If you do not delete - the provisions above, a recipient may use your version of this file - under either the MPL or the [___] License." - - [NOTE: The text of this Exhibit A may differ slightly from the text of - the notices in the Source Code files of the Original Code. You should - use the text of this Exhibit A rather than the text found in the - Original Code Source Code for Your Modifications.] - diff --git a/Build/source/libs/cairo/cairo-1.14.2/HACKING b/Build/source/libs/cairo/cairo-1.14.2/HACKING deleted file mode 100644 index aba2c545bb9..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/HACKING +++ /dev/null @@ -1,185 +0,0 @@ -Hacking Cairo -============= - -This is a high-level guide to how the cairo distribution is organized -and how to get started hacking on it. Make sure you read through the -file README before continuing. - - -Coding Style ------------- - -The easiest way to write code in the cairo style is to follow code close -to the place you are hacking, but if you want a written down set of -rules, see file CODING_STYLE. - -Files for backends that depend on languages other than C (C++ or -Objective C for example) may use features specific to those languages. -For example, "//" comments are allowed, though discouraged, in those files. - - -Contact -------- - -Various ways to get in touch with other cairo developers and maintainers -have been enumerated at: - - http://cairographics.org/contact/ - -Most of that information is also reflected in the following sections. - - -Mailing Lists -------------- - -There are various mailing lists that are useful when developing cairo -code. A complete list is always available at: - - http://cairographics.org/lists/ - -It is recommended that cairo developers subscribe to all those lists. -The cairo list by itself generates much more traffic than the others -combined, so developers and contributors should not be intimidated by -the -commit and -bugs lists. - - -Bug Tracking System -------------------- - -We use a standard bugzilla bug tracking system available at: - - http://bugs.freedesktop.org/ - -See file named BUGS for detailed information on reporting bugs. In short, -for straight bug reports, it's best to report them there such that they -are not lost or forgotten. For discussion of new features or -complicated issues, use the mailing list. - - -IRC ---- - -It's a great idea to hang around the cairo IRC channel if you have any -interest in cairo. We use the #cairo channel on irc.freenode.net. - -Make sure you introduce yourself if your nick is not easy to match to -the name you use on the mailing list. - - -Version Control System ----------------------- - -We use /git/ for version control. See: - - http://cairographics.org/download/ - -For more information on using git, see: - - http://freedesktop.org/wiki/Infrastructure/git/ - - -Build System ------------- - -We use the autotools build system with cairo, but with various -customizations and advanced features. Reading configure.in is your -best bet to understanding it, or just ask on IRC. - -To bootstrap the build system run ./autogen.sh. After that the -regular "./configure; make; make install" sequence can be used. -See file named INSTALL for more details. - -There is limited support for a win32 build system. -See README.win32 and Makefile.win32 files in various directories. - - -ChangeLog ---------- - -We generate ChangeLog files automatically from the git commit log. -No manual ChangeLog writing is necessary. - - -Copyrights and Licensing ------------------------- - -The cairo library is dual-licensed under LGPL and MPL. See the file -named COPYING for details. The test suites are more liberal, and are -allowed to include GPL code. - -When writing new code, update the file headers to add your (or your -employers) copyright line and contributor line. If adding new files -or splitting a file, copy the file header from other files. - - -Source Code ------------ - -The library source code and headers live in the src/ directory. -See src/README for more information. - - -Regression Test Suite ---------------------- - -Cairo has a fairly extensive regression-testing suite. Indeed, without -these tests it would be impossible to make a cairo release without -introducing tens of regressions. We still manage to introduce -regressions with each release even with the hundreds of tests we already -have. - -The regression test suite is located under the test/ directory. -See test/README for more information. - - -Performance Test Suite ----------------------- - -There is a performance test suite located under the perf/ directory. -A collection of traces of real-world behavior are also available in the -cairo-traces repository, which can be used in isolation or hooked in -with the main performance test suite. See perf/README for more -information. - - -Boilerplate ------------ - -The cairo-boilerplate is a small private library used by the regression -and performance test suites. It includes the boilerplace code needed -to initialize various backends for the test suites, as well as allow -tweaking some of the internal workings of the backends for more testing. - -The boilerplate code is localted under the boilerplate/ directory. -See boilerplate/README for more information. - - -Documentation -------------- - -Cairo uses the gtk-doc system for reference API documentation. - -The reference documentation is located under doc/public. -See doc/public/README for more information. - -For more documentation including frequently asked questions, tutorials, -samples, roadmap, todo list, etc visit: - - http://cairographics.org/documentation/ - -Some of those should gradually be moved to doc/. - - -Utilities ---------- - -We have developed several utilities useful for writing cairo or code -that uses cairo. These tools can be found under the util/ directory. -See util/README for more information. - - -Releasing ---------- - -Now you are a cairo maintainer, so what? See file named RELEASING. - diff --git a/Build/source/libs/cairo/cairo-1.14.2/INSTALL b/Build/source/libs/cairo/cairo-1.14.2/INSTALL deleted file mode 100644 index 9db68dee2ba..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/INSTALL +++ /dev/null @@ -1,184 +0,0 @@ -Quick-start build instructions ------------------------------- -1) Configure the package: - - ./configure - -2) Compile it: - - make - -3) Install it: - - make install - -This final step may require temporary root access (eg. with sudo) if -you don't have write permission to the directory in which cairo will -be installed. - -NOTE: If you are working with source from git/cvs rather than from a tar -file, then you should use ./autogen.sh in place of ./configure -anywhere it is mentioned in these instructions. - -More detailed build instructions --------------------------------- -1) Configure the package - - The first step in building cairo is to configure the package by - running the configure script. [Note: if you don't have a configure - script, skip down below to the Extremely detailed build - instructions.] - - The configure script attempts to automatically detect as much as - possible about your system. So, you should primarily just accept - its defaults by running: - - ./configure - - The configure script does accept a large number of options for - fine-tuning its behavior. See "./configure --help" for a complete - list. The most commonly used options are discussed here. - - --prefix=PREFIX - - This option specifies the directory under which the software - should be installed. By default configure will choose a - directory such as /usr/local. If you would like to install - cairo to some other location, pass the director to configure - with the --prefix option. For example: - - ./configure --prefix=/opt/cairo - - would install cairo into the /opt/cairo directory. You could - also choose a prefix directory within your home directory if - you don't have write access to any system-wide directory. - - After installing into a custom prefix, you will need to set - some environment variables to allow the software to be - found. Assuming the /opt/cairo prefix and assuming you are - using the bash shell, the following environment variables - should be set: - - PKG_CONFIG_PATH=/opt/cairo/lib/pkgconfig - LD_LIBRARY_PATH=/opt/cairo/lib - export PKG_CONFIG_PATH LD_LIBRARY_PATH - - (NOTE: On Mac OS X, at least, use DYLD_LIBRARY_PATH in place - of LD_LIBRARY_PATH above.) - - --enable-XYZ - --enable-XYZ=yes - --enable-XYZ=auto - --enable-XYZ=no - --disable-XYZ - - Cairo's various font and surface backends and other features can be - enabled or disabled at configure time. Features can be divided into - three categories based on their default state: - - * default=yes: These are the recommended features like PNG functions - and PS/PDF/SVG backends. It is highly recommended to not disable - these features but if that's really what one wants, they can be - disabled using --disable-XYZ. - - * default=auto: These are the "native" features, that is, they are - platform specific, like the Xlib surface backend. You probably - want one or two of these. They will be automatically enabled if - all their required facilities are available. Or you can use - --enable-XYZ or --disable-XYZ to make your desire clear, and then - cairo errs during configure if your intention cannot be followed. - - * default=no: These are the "experimental" features, and hence by - default off. Use --enabled-XYZ to enable them. - - The list of all features and their default state can be seen in the - output of ./configure --help. - -2) Compile the package: - - This step is very simple. Just: - - make - - The Makefiles included with cairo are designed to work on as many - different systems as possible. - - When cairo is compiled, you can also run some automated tests of - cairo with: - - make check - - NOTE: Some versions of X servers will cause the -xlib tests to - report failures in make check even when cairo is working just - fine. If you see failures in nothing but -xlib tests, please - examine the corresponding -xlib-out.png images and compare them to - the -ref.png reference images (the -xlib-diff.png images might also - be useful). If the results seem "close enough" please do not report - a bug against cairo as the "failures" you are seeing are just due - to subtle variations in X server implementations. - -3) Install the package: - - The final step is to install the package with: - - make install - - If you are installing to a system-wide location you may need to - temporarily acquire root access in order to perform this - operation. A good way to do this is to use the sudo program: - - sudo make install - -Extremely detailed build instructions -------------------------------------- -So you want to build cairo but it didn't come with a configure -script. This is probably because you have checked out the latest -in-development code via git. If you need to be on the bleeding edge, -(for example, because you're wanting to develop some aspect of cairo -itself), then you're in the right place and should read on. - -However, if you don't need such a bleeding-edge version of cairo, then -you might prefer to start by building the latest stable cairo release: - - http://cairographics.org/releases - -or perhaps the latest (unstable) development snapshot: - - http://cairographics.org/snapshots - -There you'll find nicely packaged tar files that include a configure -script so you can go back the the simpler instructions above. - -But you're still reading, so you're someone that loves to -learn. Excellent! We hope you'll learn enough to make some excellent -contributions to cairo. Since you're not using a packaged tar file, -you're going to need some additional tools beyond just a C compiler in -order to compile cairo. Specifically, you need the following utilities: - - automake - autoconf - autoheader - aclocal - libtoolize - pkg-config [at least version 0.16] - gtk-doc (recommended) - -Hopefully your platform of choice has packages readily available so -that you can easily install things with your system's package -management tool, (such as "apt-get install automake" on Debian or "yum -install automake" on Fedora, etc.). Note that Mac OS X ships with -glibtoolize instead of libtoolize. - -Once you have all of those packages installed, the next step is to run -the autogen.sh script. That can be as simple as: - - ./autogen.sh - -But before you run that command, note that the autogen.sh script -accepts all the same arguments as the configure script, (and in fact, -will generate the configure script and run it with the arguments you -provide). So go back up to step (1) above and see what additional -arguments you might want to pass, (such as prefix). Then continue with -the instructions, simply using ./autogen.sh in place of ./configure. - -Happy hacking! diff --git a/Build/source/libs/cairo/cairo-1.14.2/KNOWN_ISSUES b/Build/source/libs/cairo/cairo-1.14.2/KNOWN_ISSUES deleted file mode 100644 index c367f918ea3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/KNOWN_ISSUES +++ /dev/null @@ -1,3 +0,0 @@ -Known Issues ------------- -None diff --git a/Build/source/libs/cairo/cairo-1.14.2/Makefile.am b/Build/source/libs/cairo/cairo-1.14.2/Makefile.am deleted file mode 100644 index 03fa3523649..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/Makefile.am +++ /dev/null @@ -1,83 +0,0 @@ -include $(top_srcdir)/build/Makefile.am.common - -EXTRA_DIST += \ - KNOWN_ISSUES \ - README.win32 \ - Makefile.win32 \ - build/Makefile.win32.common \ - build/Makefile.win32.inform \ - build/Makefile.win32.features \ - build/Makefile.win32.features-h \ - $(NULL) -#MAINTAINERCLEANFILES += \ -# $(srcdir)/build/Makefile.win32.features \ -# $(srcdir)/build/Makefile.win32.features-h \ -# $(NULL) - -ACLOCAL_AMFLAGS = -I build ${ACLOCAL_FLAGS} - -DIST_SUBDIRS = src doc util boilerplate test perf -SUBDIRS = src doc util -# libpng is required for our test programs -if CAIRO_HAS_PNG_FUNCTIONS -SUBDIRS += boilerplate test perf -endif - -configure: cairo-version.h - -doc: - cd doc && $(MAKE) $(AM_MAKEFLAGS) $@ -test retest recheck: all - cd test && $(MAKE) $(AM_MAKEFLAGS) $@ -perf: all - cd perf && $(MAKE) $(AM_MAKEFLAGS) $@ -check-valgrind: all - cd test && $(MAKE) $(AM_MAKEFLAGS) check-valgrind - cd perf && $(MAKE) $(AM_MAKEFLAGS) check-valgrind -.PHONY: doc test retest recheck perf check-valgrind - - -EXTRA_DIST += \ - AUTHORS \ - BIBLIOGRAPHY \ - BUGS \ - CODING_STYLE \ - COPYING \ - COPYING-LGPL-2.1 \ - COPYING-MPL-1.1 \ - HACKING \ - INSTALL \ - NEWS \ - PORTING_GUIDE \ - README \ - RELEASING \ - autogen.sh \ - cairo-version.h \ - $(NULL) - -DISTCLEANFILES += config.cache - -MAINTAINERCLEANFILES += \ - $(srcdir)/aclocal.m4 \ - $(srcdir)/autoscan.log \ - $(srcdir)/build/compile \ - $(srcdir)/build/config.guess \ - $(srcdir)/build/config.sub \ - $(srcdir)/build/depcomp \ - $(srcdir)/build/install-sh \ - $(srcdir)/build/ltmain.sh \ - $(srcdir)/build/missing \ - $(srcdir)/build/mkinstalldirs \ - $(srcdir)/config.h.in \ - $(srcdir)/configure.scan \ - $(NULL) - -DISTCHECK_CONFIGURE_FLAGS = \ - --enable-gtk-doc \ - --enable-test-surfaces \ - --enable-full-testing \ - $(NULL) - -include $(srcdir)/build/Makefile.am.changelog -include $(srcdir)/build/Makefile.am.releasing -include $(srcdir)/build/Makefile.am.analysis diff --git a/Build/source/libs/cairo/cairo-1.14.2/Makefile.win32 b/Build/source/libs/cairo/cairo-1.14.2/Makefile.win32 deleted file mode 100644 index fbad7f3e4c9..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/Makefile.win32 +++ /dev/null @@ -1,24 +0,0 @@ -default: all - -# Do not edit this file. -# Edit build/Makefile.win32.common for customization - -top_srcdir = . -include $(top_srcdir)/build/Makefile.win32.inform - -all: cairo - -cairo: inform - @$(MAKE) -C src -f Makefile.win32 - -perf: inform - @$(MAKE) -C perf -f Makefile.win32 perf - -test: inform - @$(MAKE) -C test -f Makefile.win32 test - -clean: - @$(MAKE) -C boilerplate -f Makefile.win32 clean - @$(MAKE) -C perf -f Makefile.win32 clean - @$(MAKE) -C src -f Makefile.win32 clean - @$(MAKE) -C test -f Makefile.win32 clean diff --git a/Build/source/libs/cairo/cairo-1.14.2/NEWS b/Build/source/libs/cairo/cairo-1.14.2/NEWS deleted file mode 100644 index 93b650ef59f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/NEWS +++ /dev/null @@ -1,7366 +0,0 @@ -Release 1.14.2 (2014-03-09 Bryce Harrington ) -==================================================================== -This release provides collected bug fixes, along with one feature -enhancement for the xcb backend, and a small performance improvement for -fonts. - -The running theme of the bug fixes is platform-specific issues, both -build and run-time. Platforms with fixes include Sparc, AIX, Windows -(mingw), and Windows (MSVC8). Memory leaks, valgrind issues, and PDF -issues round out our list. - -It's come to light that changes in cairo 1.14 resulted in breakage on -MacOS X 10.4. We've not yet determined whether to fix up the support, -or excise the 10.4-specific code and support only OS X 10.5 or newer. -Meantime, we'll only advertise cairo as working on OS X 10.5. - -Features --------- - * Improve xcb's handling of per-screen subpixel ordering. If no - Xft.rgba property is specified, default to the screen's subpixel - order. - -API Changes ------------ -None - -Dependency Changes ------------------- -None - -Performance Optimizations -------------------------- - * Improve performance of cpu_to_be32 and be32_to_cpu, making truetype - subsetting of large fonts run about 15% faster. - -Bug Fixes ---------- - * Fix unaligned access on sparc with the compact font format (CFF). - Unlike truetype, all data in CFF is not aligned. - (Debian bug #712836) - * Fix unaligned access on sparc with tor-scan-converter's memory pool. - * Fix crash when loading a PDF with a transformed image. - (fdo bug #85151) - * Fix regression on mingw for bigendian test due to removal of file - extension for executables. - (fdo bug #85120) - * Fix handling of backslash in PDF interpreter - (fdo bug #85662) - * Fix crash in xlib and xcb renderers when swapping a 0-sized glyph - * Fix bug with RTL text in PDF operators - (fdo bug #86461) - * Fix compilation 'cairo-path-stroke-traps.c' with MSVC8 - (fdo bug #84908) - * Fix crash in _fill_xrgb32_lerp_opaque_spans when a span length is - negative. - * Fix valgrind error by releasing pattern created by - cairo_pattern_create_rgb(). - * Fix valgrind errors when running cairo-test-suite. - * Fix memory leak in recording surface replays - (fdo bug #87898) - * Fix destruction of fonts in api-special-cases test. - (fdo bug #87567) - * Fix duplicated surface push on similar-image, preventing trivial GTK3 - program traces from being replayable, with an error message about - invalid values for the size of the input. - (fdo bug #73580) - * Fix crash when win32 surface's image size does not cover the entire - surface. - (fdo bug #53121) - * Fix crash due to obsolete CGFontGetGlyphPath call - (fdo bug #84324) - * Fix several build issues on AIX - (fdo bugs #89338, #89340, #89356, #89354) - * Fix various documentation warnings and errors - -Release 1.14.0 (2014-10-13 Bryce Harrington ) -==================================================================== -Hard to believe it's been over a year since our last release, but it's -not for lack of activity. This release includes contributions of a wide -assortment of bug fixes, build system improvements, warnings cleanups, -codebase refactoring, test suite repairs, and static analysis work. - -This release is lighter on features (compared with 1.12.10) but includes -a highly demanded rehaul of our image downscaling functionality, which -solves a serious problem experienced by Inkscape users when shrinking -embedded bitmaps in SVG files. The new scaling algorithms are used by -the image backend and by other backends as needed for fallbacks. - - -Features --------- - - Filtering improvements for the image backend, in particular - down-scaling of images produces filtered images that depend on all the - pixels of the source. When using the image backend you get the - following settings: - - CAIRO_FILTER_GOOD: uses a box filter for scales less than .75 in - either direction. For scales larger than this, the same filter as - CAIRO_FILTER_BILINEAR is used. - - CAIRO_FILTER_BEST: uses a Catmull-Rom filter always. When upscaling - more than 2x this will produce anti-aliased square pixels, similar - to OS/X. - - CAIRO_FILTER_GAUSSIAN: uses PIXMAN_FILTER_BEST, which in current - pixman is the same as BILINEAR. (This is subject to change in the - future). - - xlib and xcb also use the image fallback for GOOD/BEST filters, but - note that other backends do not implement these filtering fixes yet, - however other actions may cause them to use an image fallback which - will cause these filters to be used. - - Improve handling of device transformation and scaling, allowing Cairo - to now support scaling at a device level, permitting easier, more - transparent HiDPI support. - - Support JBIG2 mime data in PDF. This allows embedding of more - compressed JPEG formats within PDF, rather than including the full - uncompressed image. Also, reduce the number of transparency groups - used by PDF to keep the file size small and viewing/printing of the - PDF fast. - - Expand the embedding section to include stencil mask support. - - Reorder font declarations to be in natural order. - - Update the Skia backend to build against current Skia (as of June - 2014). - - Drop Link-Time Optimization (LTO) support from build system. This - seems to have caused much trouble for unclear benefit, and most - distros are reverting or disabling it anyway. - - Optimize VBO size on GL to 1M and to 16k for EGL. This improves - (theoretical) performance for desktop GLX use cases while avoiding - hitting VBO memory size limitations on embedded devices. - -API Changes ------------ - - cairo_surface_set_device_scale, cairo_surface_get_device_scale: - - Sets a scale that is multiplied to the device coordinates - determined by the CTM when drawing to @surface. One common use for - this is to render to very high resolution display devices at a scale - factor, so that code that assumes 1 pixel will be a certain size - will still work. - - cairo_egl_device_get_display, cairo_egl_device_get_context: - - Support get/set of EGLContext and EGLDisplay for egl-based cairo - devices, similar to GLX. - -Dependency Changes ------------------- - - Cairo now requires glib 2.14 for its gobject helper functions, - and pixman 0.30 for downscaling. - - -Bug fixes ---------- - - Don't embed CMYK Jpeg images in svg. - - Fix tests to place output in proper location. - - Fix determination of alpha for all surfaces when recording. - - Extend oversize check to cairo_gl_surface_create_for_texture, so an - error surface is returned if the texture is too large to render to. - - Fix embedding of mime data in PDF and PS files. - - Remove useless error handling in *_reply() functions in XCB. - - Fix a double-free exposed by multithreaded apps creating and - destroying the same font concurrently. - https://bugs.freedesktop.org/show_bug.cgi?id=69470 - - Fix corrupt stacks produced by bugs in operand emission for trace. - - Fix out of bounds array access in format cache for xlib - - Don't rename glyphs used by seac operator. This can cause certain - combined characters to use their decorations (e.g. umlauts on ö) to be - lost during printing of PDFs using evince. - https://bugs.freedesktop.org/show_bug.cgi?id=70364 - - Fix crash on calling cairo_create with a finished surface - - Fix SSIZE_T definition problem when making with MSYS on Windows7 - - Fix one off issue in gl context cleanup - - Fix usage of CAIRO_STACK_ARRAY_LENGTH - - Fix rectangle stroke with non rectilinear pen - - Fix imagemask with pattern source failure on some printers. This bug - could cause files converted using pdftops to fail for example on Ricoh - printers, or opening in Adobe Distiller on Windows. - https://bugs.freedesktop.org/show_bug.cgi?id=69485 - - Fix whitespace in font names - - Fix page size in generated PDFs. When printing using pdftocairo on - larger page sizes, such as 11x17, the image would be cropped to letter - size. - https://bugs.freedesktop.org/show_bug.cgi?id=73452 - - Fix path-currentpoint test by preserving current-point in - copy_path()/append_path() sequence - - Fix generation of HTML in code docs for - cairo-format-stride-for-width. Raw HTML code was being passed - to the browser, instead of displaying normally. - https://bugs.freedesktop.org/show_bug.cgi?id=63257 - - Fix spelling of "tessellator" throughout code. We're using the - American rather than British spelling of this word. - https://bugs.freedesktop.org/show_bug.cgi?id=50411 - - Fix crash in pixman_image_composite32 - - Fix crash when trying to modify a (const) all-clipped cairo_clip_t - https://bugs.freedesktop.org/show_bug.cgi?id=75819 - - Add check_composite method to all compositors, to fix crashes in the - test suite. - - Fix crash in Firefox when scrolling on certain pages. - - Fix memory leaks found by static analysis. - - Fix build of any2ppm if fork is not available. - - Fix broken build for Qt backend, due to missing libstdc++. - - Fix typo in two cairo_uint128 functions. Fixes potential build issues - on systems without a uint128 type. - - Fix build when --enable-pdf=no - - Fix cache_frozen assertions for Win32 print. - - Correctly check for xcb image surface for inplace upload - - Fix webkit-based web browser crashes due to empty boxes by skipping - over them when tesselating. - - Make pixman, libpng, and zlib paths commandline configurable for win32 - builds. - - Fix image scale on Win32 when GDI scale is not identity. - - Fix float endian configure test when using clang -O4 - - Fix compilation with Android bionic libc - - Don't try to build util/sphinx on Windows - - Fix loss of precision when emitting joins. This was caused by - discrepancies in line gradients when passing trapezoids around. - - Fix loss of precision and associated rendering issues in - cairo-tor-scan-converter from projection onto sample grid. - - Fix pixman oversampling of neighbouring edges within a cell by - eliminating self-intersections for the pixman traps compositor. - - Fix multi-line string splitting in PDFs - - Various cleanups and fixes to warnings, documentation, tests, and - build system. Improve error handling and return value checks. - Cleanup XFAIL tests and reference images. Cover recently added - functionality. - - -Release 1.12.16 (2013-08-21 Chris Wilson ) -=================================================================== -Thanks to everybody who reported a bug and helped us develop a fix, -we have amassed quite a few bug fixes. There are still more outstanding -bugs that seek attention and a little bit of TLC, but this release has -been delayed long enough... - -Bug fixes ---------- - - Set the correct orientation for simple boxes with a negative scale - factor. - - Fix the creation of the shading dictionary in PDF. - - Fix a crash in PDF when incorporating an image with CAIRO_EXTEND_PAD. - https://bugs.freedesktop.org/show_bug.cgi?id=61451 - - Avoid upscaling bitmap fonts if possible. - - Fix an assertion failure within the mempool allocator for shared memory. - - Fix allocation size for CFF subsets. - - Export cairo_matrix_t for GObject bindings. - - Fix a double free in the Quartz backend. - https://bugs.freedesktop.org/show_bug.cgi?id=62885 - - Fix origin of GDI StretchBlits for the Windows backend - https://bugs.freedesktop.org/show_bug.cgi?id=61876 - - Fix error propagation for requests to create a similar surface with - negative size. - https://bugs.freedesktop.org/show_bug.cgi?id=63196 - - Fix complex clipping of trapezoids with regions - https://bugzilla.gnome.org/show_bug.cgi?id=697357 - - Stop leaking the image data when loading PNGs - - Fix unbounded operations with a clip mask through the span compositor - https://bugs.freedesktop.org/show_bug.cgi?id=61592 - - Add missing checks before rendering to a finished surface - so we return - an error rather than hit an assert. - https://bugs.freedesktop.org/show_bug.cgi?id=68014 - - Prevent an assertion failure when creating similar GL surfaces larger - than supported by hardware. - - Prevent a double free of a similar image under Windows. - https://bugs.freedesktop.org/show_bug.cgi?id=63787 - - -Release 1.12.14 (2013-02-10 Chris Wilson ) -=================================================================== -In the last week we had a few more bugs reported and promptly resolved. -As these are a combination of regressions and stability issues, it is -time for a prompt update and release. Many thanks to everyone for -testing and reporting issues, and helping to make Cairo better. - -Bug fixes ---------- - - Prevent user callbacks accessing user-data during destroy to prevent - use-after-free bugs. - https://bugzilla.mozilla.org/show_bug.cgi?id=722975 - - Use standard names for glyphs in subset fonts (PDF). - https://bugs.freedesktop.org/show_bug.cgi?id=60248 - - Fix detection of Win98. The logic for detecting Win98 (and its broken - AlphaBlend()) was inverted, disabling AlphaBlend() for everyone. - - Prevent numeric overflow from extrapolating polygon edges to the clip - boundary and causing severe render artifacts. - https://bugs.freedesktop.org/show_bug.cgi?id=60489 - - Fix computation of glyph string coordinates when breaking up runs - for xlib. - - Fix an assertion in the win32 backend for failing to clear its - similar-images. - https://bugs.freedesktop.org/show_bug.cgi?id=60519 - - -Release 1.12.12 (2013-01-31 Chris Wilson ) -=================================================================== -The goal of this release is to fix the synchronisation problems that -were exhibited in the SHM transport for cairo-xlib. This cropped up -any place that tried to rapidly push fresh pixel data to the X server -through an ordinary image surface, such as gimp-2.9 and evince. - -Bug fixes ---------- - - Avoid replacing the entire image when uploading subimages - https://bugs.freedesktop.org/show_bug.cgi?id=59635 - - Force synchronisation for scratch SHM image buffers, so that we do - not overwrite data as it is being read by X. - https://bugs.freedesktop.org/show_bug.cgi?id=59635 (also) - - Fix typos in detecting multisampling for the GL (MSAA) backend. - - Fix a memory leak in the GL (MSAA) backend. - - Fix a reference counting bug when mapping a GL surface to an image. - - -Release 1.12.10 (2013-01-16 Chris Wilson ) -=================================================================== -A heap of bug fixes everywhere, and the gradual completion of the MSAA -backend for cairo-gl. Perhaps the most noteworthy set of the bugfixes -was the crusage lead by Behdad Eshfabod to make font handling by -pango/cairo/fontconfig fully threadsafe. This testing revealed a couple -of races that needed fixing in Cairo's scaled-font and glyph cache. - -Bug fixes ---------- - - Append coincident elements to the recording's surface bbtree so that - the list is not corrupted and the overlapping elements lost. - - Fix cairo-trace to correctly record map-to-image/unmap-image and then - replay them. - - Ignore MappingNotifies when running the XCB testsuite as they are sent - to all clients when the keyboard changes. The testsuite would detect - the unexpected event and complain. - - Handle very large images in the XCB backend. - - Fix a memory leak in the xlib/shm layer, and prevent use of the SHM - surfaces after the display is closed. - https://bugs.freedesktop.org/show_bug.cgi?id=58253 - - Handle resizing of bitmap fonts, in preparation for a fix to - fontconfig to correctly pass on the user request for scaling. - - Always include subroutine 4 (hint replacement idion) when subsetting - type 1 fonts in order to prevent a crash in cgpdftops on Mac OS/X - - Fix a couple of typos in the cairo-gobject.h header files for - introspection. - - Prevent a mutex deadlock when freeing a scaled-glyph containing a - recording-surface that itself references another scaled-glyph. - https://bugs.freedesktop.org/show_bug.cgi?id=54950 - - Make scaled-font cache actually thread-safe and prevent - use-after-frees. - - Restore support for older versions of XRender. A couple of typos and a - few forgotten chunks prevented the xlib compositor from running - correctly with XRender < 0.10. Note that there are still a few - regressions remaining. - - -Release 1.12.8 (2012-11-24 Chris Wilson ) -=================================================================== -Another couple of weeks and a few more bugs have been found and fixed, -it is time to push the next point release. Many thanks to everyone who -reported their issues and helped us track down the bugs and helped -testing the fixes. - -Bug fixes ---------- - - Expand the sanity checking for broken combinations of XSendEvent and - ShmCompletionEvent. - - Notice that "The X.Org Foundation" sometimes also identifies itself - as "The Xorg Foundation". - - Handle various ages of libXext and its Shm headers. - - Fix the invalid clipping of the source drawable when using SHM - transport to upload images. - https://bugs.freedesktop.org/show_bug.cgi?id=56547 - - Handle all Type1 postscript operators for better font compatibility. - https://bugs.freedesktop.org/show_bug.cgi?id=56265 - - Fix a couple of memory leaks in Type1 font subsetting - https://bugs.freedesktop.org/show_bug.cgi?id=56566 - - Tighten the evaluation of the start/stop pen vertices, and catch a few - instances where we would use a fan instead of a bevel. - https://bugs.freedesktop.org/show_bug.cgi?id=56432 - - Fix assumption that geometric clipping always succeeds with the - span-compositor. - https://bugs.freedesktop.org/show_bug.cgi?id=56574 - - Fix call to spline intersection when evaluating whether a stoke is - visible. - - Remember to copy inferior sources when using SHM to readback the - surface for use as a source. - -Release 1.12.6 (2012-10-22 Chris Wilson ) -=================================================================== -Thanks to everyone who download cairo-1.12.4 and gave us their feedback. -It truly was invaluable and has helped us to fix many portability issues -that crept in with some of the new features. This release aims to fix -those stability issues and run on a wider range of systems. - -Bug fixes ---------- - - Fix the recording surface to actually snapshot the source and so fix - PDF drawing. - - Calling XSendEvent with an XShmCompletionEvent is incompatabile with - older Xorg servers. - - Reorder CloseDisplay chain so that XShm is not reinstantiated after - shutdown, causing a potential crash if the Display was immediately - recreated using the same memory address. - - Make sure that the Xserver has attached to the SHM segment before - deleting it from the global namespace on systems that do not support - deferred deletion. - - Type1 subsetting support for PDF (and PS) was once again improved to - work with a larger number of PDF readers. - - GLESv2 build fixes and improved support for embedded GPUs. - - Tweak the invisible pen detection for applications that are currently - using too large values for geometric tolerance. - - A build fix for older freetype libraries. - - -Release 1.12.4 (2012-10-05 Chris Wilson ) -=================================================================== -More bugs, and more importantly, more fixes. On the cairo-gl side, we -have refinements to the MSAA compositor which enables hardware -acceleration of comparitively low-quality antialiasing - which is useful -in animations and on very high density screens. For cairo-xlib, we have -finally enabled SHM transport for image transfers to and from the X -server. A long standing required feature, SHM transport offers a notable -reduction in rendering latency by reducing the number of copies -required to upload image data - given hardware and driver support, -cairo-xlib can now perform zero copy uploads onto the GPU. And as usual -Adrian Johnson has been very busy fixing many different corner cases in -cairo-pdf, impoving opacity groups and font subsetting. Last, but not -least, for cairo-image Søren Sandmann Pedersen added support for -rendering glyphs to pixman and using that from within cairo. The new -glyph rendering facility reduces the overhead for setting up the -compositing operation, improving glyph thoughput for the image backend -by a factor of about 4. And before he did so, he also fixed up a few -bugs in the existing glyph rendering code. So many thanks to Andrea -Canciani, Adrian Johnson, Chuanbo Weng, Dongyeon Kim, Henry Song, Martin -Robinson, Søren Sandmann Pedersen and Uli Schlachter for their -contributions, finding and fixing bugs. - -Bug fixes ---------- - - Interior boxes were being dropped when amalgamating regions during - tesselation. - https://bugs.freedesktop.org/show_bug.cgi?id=49446 - - Allow building without gtk-doc installed - - Invalid edge generation whilst reducing complex polygons. - https://bugs.freedesktop.org/show_bug.cgi?id=50852 - - Stroking around tight cusps - - Use locale correct formats for reading font subsetting and valid - buffers. - https://bugs.freedesktop.org/show_bug.cgi?id=51443 - - Ensure that the type1 subset includes all the glyph encodings - https://bugs.freedesktop.org/show_bug.cgi?id=53040 - - Upload the whole source for a repeating pattern. - https://bugs.freedesktop.org/show_bug.cgi?id=51910 - - Fix damage tracking to handle continuation chunks corectly and so - prevent crashes on win32. - https://bugs.freedesktop.org/show_bug.cgi?id=53384 - - Avoid emitting miter joins for degenerate line segments - https://bugzilla.mozilla.org/show_bug.cgi?id=407107 - - Convert the relative path semgents into the backend coordinates - and then back again to user coordinates (cairo_copy_path, - cairo_append_path) - https://bugs.freedesktop.org/show_bug.cgi?id=54732 - - Fix extents computations for a degenerate path consisting only of a - move-to - https://bugs.freedesktop.org/show_bug.cgi?id=54549 - - Prevent crashing on a degenerate project edge after polygon - intersection - https://bugs.freedesktop.org/show_bug.cgi?id=54822 - - - -Release 1.12.2 (2012-04-29 Chris Wilson ) -=================================================================== -After such a long gestation period for the release of Cairo 1.12, we -inevitably accumulated a few bugs that were flushed out by broadening the -test base. Thanks to everybody who tried the release, apologies to any one -unfortunate enough to encounter a bug and many thanks for reporting it. As -a result Adrian Johnson, Alexandros Frantzis, Andrea Canciani, Kalev -Lember, Maarten Bosman, Marcus Meissner, Nis Martensen and Uli Schlachter -have squashed many more bugs and improved the documentation. I would -strongly recommend everyone to upgrade to cairo-1.12.2. --Chris - -Bug fixes ---------- - - Allow applications to create 0x0 xlib surfaces, such as used by LibreOffice. - https://bugs.freedesktop.org/show_bug.cgi?id=49118 - - Trim composite extents for SOURCE/CLEAR operators to the mask. - - Use fallback fonts in PDF for unhandled computed glyph widths - https://bugs.freedesktop.org/show_bug.cgi?id=48349 - - Handle snapshots of recording surfaces for analysing pattern extents. - Fixes a regression of reporting the PDF bounding box as being the page size. - - Fix allocation size for PDF pattern ids. - Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49089 - - Fix emission of rectilinear dashed segments, with and without scaling, and - application of degenerate line joins. - - Clamp unbounded fixup polygons to the clip extents. - - Prevent infinite loop due to rounding errors whilst incrementing along dashes. - - Prevent overflow for inline a8 span filling. - - Miscellaneous build fixes for Cygwin on Windows and Solaris. - -Release 1.12.0 (2012-03-23 Chris Wilson ) -=================================================================== -It's taken over 18 months, but the wait is finally over. A new cairo release! -We are pleased to annouce a new stable release of Cairo that brings many -new features and performance improvements, all whilst maintaining -compatibility with cairo-1.0 and all releases since. We recommend anyone -using a previous release of Cairo to upgrade to 1.12.0. - -The major feature of this release is the introduction of a new procedural -pattern; the mesh gradient. This, albeit complex, gradient is constructed -from a set of cubic Bezier patches and is a superset of all other gradient -surfaces which allows for the construction of incredibily detailed patterns. -In PDF parlance, the mesh gradient corresponds with type 7 patterns. Many -thanks to Andrea Canciani for bringing this to Cairo, and for his work on -making gradient handling robust. - -Not content with just adding another procedural pattern, Cairo 1.12 also -adds new API to create a callback pattern, -cairo_pattern_create_raster_source, that allows the application to -provide the pixel data for the region of interest at the time of -rendering. This can be used for instance, by an application to decode -compressed images on demand and to keep a cache of those decompressed -images, independently of Cairo. When combined with the recording -surface, it should form a useful basis for a deferred renderer. - -With the release of cairo-1.12, we also introduce a new supported -backend for interoperating with X using XCB. Uli Schlachter, also -maintainer of awesome and contributor to libxcb, has volunteered to -maintain cairo-xcb for us. Thanks Uli! - -For cairo-1.12, we have also added some common API to address any -surface as an image and so allow direct modification of the raster data. -Previously, only the Quartz and Win32 backends supported a very narrow -interface to allow for efficient pixel upload. Now with -cairo_surface_create_similar_image, cairo_surface_map_to_image, and -cairo_surface_unmap_image, Cairo exports a consistent method for -treating those surfaces as an image and so allow modification inplace. -These are the same routines used internally, and should support -efficient transfer or direct mapping of the target surfaces as -applicable. - -Another focus over the past year has been to address many performance -issues, without sacrificing the composition model. To accomplish the -goal, once again the rasterisation pipeline was overhauled and made -explicit, giving the backends the freedom to implement their own -specific pipeline whilst also providing a library of common routines -from which to build the pipeline. For instance, this allows the image -backend and the gl backend to composite scan line primitives inplace, -and to then implement custom fallbacks to catch the corner cases that do -not map onto their fastest paths. Similarly, this allows for the Xlib -backend to implement trapezoidation without compromising the other -backends, yet still allow for the pipeline to be used elsewhere for -testing and fallbacks. Clipping was once again overhauled, so that the -common cases for the raster pipelines could be captured and processed -with fast paths with the emphasis on performing geometric clipping to -reduce the frequency of using multi-pass clipmasks. Stroking was made -faster, both by providing specialised fast-paths for simple, yet frequent, -cases (such as stroking around a rectangle) and by reducing the number -of edges generated by the general stroker. - -As part of the focus on performance, Cairo 1.12 introduces some -antialias hints (NONE, FAST, GOOD, BEST) that are interpolated by the -rasterisers to fine tune their performance versus quality. Cairo 1.12 -also introduces a new observation architecture, -cairo_surface_observer_t, which can be used to analyse the amount of -time consumed by drawing commands and help identify inefficiencies in -both Cairo and the application. - -Last, but by no means least, the OpenGL backend has seen significant -work including the port to GLESv2 and the exploitation of advanced -hardware features. Interesting times. - -As always, I would like to thank everyone who contributed to Cairo, -not only through writing code, but also submitting documentation, bug -reports, suggestions and generally having fun with Cairo! In particular -though this release could not have happened without the efforts of -Adrian Johnson, Alexandros Frantiz, Andrea Canicani, Martin Robinson, -Nis Martensen, and Uli Schlachter. Thanks. --Chris - -Snapshot 1.11.4 (2012-13-12) -============================ -The cairo community is pleased to finally announce the long aniticpated -release candidate for 1.12, 1.11.4, of the cairo graphics library. This -is the first major update to cairo in over a year and brings a large -number of new features; undoubtably a few bugs as well. - -While many people have contributed and have helped to test the release, -providing feedback on 1.10 and suggesting improvements, this release -is the result of a few persevering souls who deserve recognition for their -outstanding contributions: Andrea Canciani (all round bug fixing, -performance tuning and master of the gradients), Adrian Johnson (PDF -supremo) and Uli Schlachter (who stepped forward as maintainer for the -XCB backend). - -Major additions since 1.11.2: - - * cairo_surface_map_to_image API for pixel level access to any surface - - * New antialias hints to control the trade-off between speed and quality - - * A callback pattern, cairo_pattern_create_raster_source, for lazy - decoding of image data. - - * cairo_surface_observer_t, a new type of surface to gather performance - statistics - - * XCB as a supported backend - - * A rewritten compositor pipeline for performance improvements for, but not - limited to, the xlib and image backends. - From ION and PineView through to SandyBridge, every machine I have shows - across the board performance improvement on the cairo-traces: - - i5-2520m gnome-system-monitor: 5.97x speedup - pnv gnome-system-monitor: 4.86x speedup - i5-2520m firefox-asteroids: 4.66x speedup - pnv firefox-asteroids: 4.43x speedup - image firefox-canvas: 3.82x speedup - i5-2520m firefox-canvas-alpha: 3.49x speedup - image firefox-asteroids: 2.87x speedup - pnv firefox-talos-svg: 2.83x speedup - ion grads-heat-map: 2.75x speedup - pnv firefox-canvas-alpha: 2.66x speedup - image gnome-system-monitor: 2.66x speedup - image swfdec-giant-steps: 2.46x speedup - image firefox-canvas-alpha: 2.14x speedup - i5-2520m firefox-talos-svg: 2.03x speedup - image grads-heat-map: 2.02x speedup - ion gnome-system-monitor: 2.00x speedup - pnv firefox-particles: 1.99x speedup - i5-2520m grads-heat-map: 1.96x speedup - pnv firefox-canvas: 1.92x speedup - ion firefox-particles: 1.80x speedup - image poppler-reseau: 1.77x speedup - pnv xfce4-terminal-a1: 1.72x speedup - image firefox-talos-svg: 1.65x speedup - pnv grads-heat-map: 1.63x speedup - i5-2520m firefox-canvas: 1.63x speedup - pnv swfdec-youtube: 1.62x speedup - image ocitysmap: 1.59x speedup - i5-2520m firefox-fishbowl: 1.56x speedup - i5-2520m poppler-reseau: 1.50x speedup - i5-2520m evolution: 1.50x speedup - i5-2520m midori-zoomed: 1.43x speedup - pnv firefox-planet-gnome: 1.42x speedup - i5-2520m firefox-talos-gfx: 1.41x speedup - i5-2520m gvim: 1.41x speedup - pnv ocitysmap: 1.37x speedup - image poppler: 1.31x speedup - ion firefox-canvas-alpha: 1.35x speedup - ion firefox-talos-svg: 1.34x speedup - i5-2520m ocitysmap: 1.32x speedup - pnv poppler-reseau: 1.31x speedup - i5-2520m firefox-planet-gnome: 1.31x speedup - pnv firefox-fishbowl: 1.30x speedup - pnv evolution: 1.28x speedup - image gvim: 1.27x speedup - i5-2520m swfdec-youtube: 1.25x speedup - pnv gnome-terminal-vim: 1.27x speedup - pnv gvim: 1.25x speedup - image firefox-planet-gnome: 1.25x speedup - image swfdec-youtube: 1.25x speedup - ... - -And a plethora of minor improvements everywhere! --Chris - -Snapshot 1.11.2 (2011-01-23) -=========================== - -In this first snapshot along the way to cairo-1.12.0, we are very excited -to announce the introduction of Bezier surface gradients, known as type -6/7 gradients in PS/PDF parlance. This is the culmination of much work by -the dynamic duo: Adrian Johnson and Andrea Canciani. Thanks guys! - -Also, I want to warmly welcome Uli Schlachter who recently joined the -Cairo community on a mission. That mission is to make cairo-xcb a -supported backend for 1.12. And for this snapshot he has made great -strides in fixing all the bugs I had left behind. Thanks Uli! - -And we have also seen a new contributor, Alexandros Frantzis, who has -begun bringing up cairo-gl for GLESv2 devices. Thanks Alex! - -And lastly, I must also thank Adrian and Andrea for the vast numbers of -bugs that they have tackled between them, fixing all those little corner -cases that lie hidden until too late. - -API additions: - -The ability to construct piece-wise Bezier surface gradients: - - cairo_pattern_create_mesh - - constructs a pattern of type CAIRO_PATTERN_TYPE_MESH using - - cairo_pattern_mesh_begin_patch - cairo_pattern_mesh_end_patch - cairo_pattern_mesh_curve_to - cairo_pattern_mesh_line_to - cairo_pattern_mesh_move_to - cairo_pattern_mesh_set_control_point - cairo_pattern_mesh_set_corner_color_rgb - cairo_pattern_mesh_set_corner_color_rgba - cairo_pattern_mesh_get_patch_count - cairo_pattern_mesh_get_path - cairo_pattern_mesh_get_corner_color_rgba - cairo_pattern_mesh_get_control_point - -The introduction of a unique ID accessible via the mime data type: - CAIRO_MIME_TYPE_UNIQUE_ID - - - - - -Release 1.10.2 (2010-12-25 Chris Wilson ) -=================================================================== -The cairo community is pleased to announce the 1.10.2 release of the -cairo graphics library. This is the first update to cairo's stable 1.10 -series and contains a large number of bug fixes. - -While many people have contributed and have help to test the release, -2 people deserve special recognition for their efforts in tracking down -and fixing bugs, Andrea Canciani and Adrian Johnson. Thanks to their -tremendous efforts, and of all cairo contributors, it is much -appreciated. - -We recommend everyone upgrade to cairo 1.10.2 and hope that everyone -will continue to have lots of fun with cairo! - --Chris - -Bug fixes ---------- - - Fix embedding of grayscale jpegs in PS. - https://bugs.freedesktop.org/show_bug.cgi?id=31632 - - Fix the reported path of extents containing a curve. - - Fix the compositing of unaligned boxes. - - Reset the clipper in PDF upon finish. - - Fix degenerates arcs to become a degenerate line. - - Build support for autoconf 2.67 - - Fix painting of transformed patterns in PS - - Fix the EPS bounding box for PS - https://bugs.freedesktop.org/show_bug.cgi?id=24688 - - Fix the missing content for EPS - https://bugs.freedesktop.org/show_bug.cgi?id=24688 - - Fix regression upon changing page size in PS/PDF - https://bugs.freedesktop.org/show_bug.cgi?id=24691 - - Only use ActualText with PDF-1.5 documents - - Fix the bbox for type1 fallbacks. - - Reset the color after ending the context in PDF - https://bugs.freedesktop.org/show_bug.cgi?id=31140 - - Fix the advance of subsetted type1 fonts - https://bugs.freedesktop.org/show_bug.cgi?id=31062 - - Fix handling of EXTEND_NONE gradients for PDF - - Restrict in-place optimisation for a8 image masks with SOURCE - - -Release 1.10.0 (2010-09-06 Chris Wilson ) -=================================================================== -The cairo community is astounded (and flabbergast) to finally announce -the 1.10.0 release of the cairo graphics library. This is a major update -to cairo, with new features and enhanced functionality which maintains -compatibility for applications written using any previous major cairo -release, (1.8, 1.6, 1.4, 1.2, or 1.0). We recommend that anybody using -a previous version of cairo upgrade to cairo 1.10.0. - -One of the more interesting departures for cairo for this release is the -inclusion of a tracing utility, cairo-trace. cairo-trace generates a -human-readable, replayable, compact representation of the sequences of -drawing commands made by an application. This can be used to inspecting -applications to understand issues and as a means for profiling -real-world usage of cairo. - -The traces generated by cairo-trace have been collected in - - git://git.cairographics.org/git/cairo-traces - -and have driven the performance tuning of cairo over the last couple of -years. In particular, the image backend is much faster with a new -polygon rasterisation and a complete overhaul of the tessellator. Not -only is this faster, but also eliminates visual artifacts from -self-intersecting strokes. Not only has cairo-trace been driving -performance improvements within cairo, but as a repeatable means of -driving complex graphics it has been used to tune OpenGL, DDX, and -pixman. - -Cairo's API has been extended to better support printing, notably -through the ability to include a single compressed representation of an -image for patterns used throughout a document, leading to dramatic file -size reductions. Also the meta-surface used to record the vector -commands compromising a drawing sequence is now exposed as a -CAIRO_SURFACE_TYPE_RECORDING, along with a new surface that is a child of a -larger surface, CAIRO_SURFACE_TYPE_SUBSURFACE. One typical usage of a -subsurface would be as a source glyph in a texture atlas, or as a -restricted subwindow within a canvas. - -Cairo's API has also resurrected the RGB16 format from the past as -the prevalence of 16-bit framebuffers has not diminished and is a -fore-taste of the extended format support we anticipate in the future. -Increasing cairo's utility, we introduce the cairo_region_t for handling -sets of pixel aligned rectangles commonly used in graphics applications. -This is a merger of the GdkRegion and the pixman_region_t, hopefully -providing the utility of the former with the speed of the latter. - -Furthermore cairo has been reworked to interoperate more closely with -various acceleration architectures, gaining the ability to share -those hardware resources through the new cairo_device_t. For instance, -with the new OpenGL backend that supersedes the Glitz backend, hardware -and rendering operations can be shared between a classic OpenGL -application mixing libVA for the hardware assisted video decode with -cairo for high quality overlays all within the same OpenGL canvas. - -Many thanks for the hard work of Adrian Johnson, Andrea Canciani, Behdad -Esfahbod, Benjamin Otte, Carl Worth, Carlos Garcia Campos, Chris Wilson, -Eric Anholt, Jeff Muizelaar, Karl Tomlinson, M Joonas Pihlaja, Søren -Sandmann Pedersen and many others that have contributed over the last -couple of years to cairo. Thank you all! - -Snapshot 1.9.14 (2010-07-26) -============================ - - A quiet couple of weeks, hopefully Cairo is seeing widescale deployment and - we are being to see the results of the stabilisation effort. Clipping bugs - seems to have been the order of the last couple of weeks, with a couple - reported and duly fixed. Thank you Igor Nikitin and Karl Tomlinsion for - finding those regressions. At this point all that seems to remain to do is - to fix the outstanding regressions in the PDF backend... - -Bugs fixes ----------- - - Clip doesn't work for text on the image backend - https://bugs.freedesktop.org/show_bug.cgi?id=29008 - - Add explicit dependency for cxx - https://bugs.freedesktop.org/show_bug.cgi?id=29114 - - Fix regressions in reporting clip extents - https://bugs.freedesktop.org/show_bug.cgi?id=29120 - https://bugs.freedesktop.org/show_bug.cgi?id=29121 - https://bugs.freedesktop.org/show_bug.cgi?id=29122 - https://bugs.freedesktop.org/show_bug.cgi?id=29124 - https://bugs.freedesktop.org/show_bug.cgi?id=29125 - - -Snapshot 1.9.12 (2010-07-12) -============================ - - A couple of weeks spent fixing those annoying bugs and cleaning up the build - system; the list of outstanding tasks to complete for the stable release is - finally shrinking. The chief bug fixer has been Benjamin Otte who not only - made sure that the public API is consistent and being tested for its - consistency, but also ensured that the documentation was up-to-date and - spent time clarifying cases where even the Cairo developers have come - unstuck in the past. Many thanks, Benjamin. However, he was not alone, - as Andrea Canciani continued his fine work in isolating broken corner cases - and proceeding to fix them, and tidying up the quartz backend. And last, but - definitely not least, M Joonas Pihlaja tried building Cairo across a - perverse range of systems and fixed up all the loose bits of code that came - unravelled. Thanks everybody! - -API Changes ------------ - - cairo_surface_set_mime_data, cairo_surface_get_mime_data: - - The length parameter is now an unsigned long (as opposed to an unsigned - int). The parameter is intended to be an equivalent to a size_t without - requiring POSIX types and be large enough to store the size of the - largest possible allocation. - - cairo_gl_surface_create_for_texture: - - This a new surface constructor for cairo-gl that explicitly enables - render-to-texture for foreign, i.e. application, textures. - - cairo_region_xor, cairo_region_xor_rectangle - - A couple of utility routines add to the region handling interface for - the purpose of replacing existing GdkRegion functionality. - -Bugs fixes ----------- - - https://bugs.launchpad.net/ubuntu/+source/cairo/+bug/600622 - - Inkscape was caught in the act of attempting to modify a finished surface. - Unfortunately, we had the ordering of our guards and assertions wrong and - so an ordinary application error was triggering an assert in Cairo. This - lead Benjamin to add a test case to ensure that the entire public API - could handle erroneous input and then proceeded to fix a whole slew of - uncovered bugs. - - - https://bugs.freedesktop.org/show_bug.cgi?id=28888 - - A regression introduced by the special casing of uploading images to an - xlib surface in-place which was ignoring the translation applied to the - image. - - -Snapshot 1.9.10 (2010-06-26) -============================ - - The first "quick" snapshot in the run up to the stable release. The - last snapshot was picked up by the bleeding edge distributions and so the - bug reports have to started to roll in. The most frequent of these are the - introduction of rendering errors by applications that modify a surface - without subsequently calling cairo_surface_mark_dirty(). Make sure the - application developers are aware of increased reliance on strict use of the - Cairo API before 1.10 is released! - - The usual slew of bugs reported and we would like to thank Zoxc for - contributing the WGL interface for cairo-gl, and finding more build - failures on win32. And it just wouldn't be a 1.9 snapshot unless - Benjamin Otte improved the error handling within cairo-gl, as well as - isolating and fixing some more errors in the test suite. The biggest bug of - the snapshot turned out to be a major sign extension issue that had lain - hidden for many years and was suddenly exposed by incorrectly rounding - rectangles when performing non-antialiased rendering. Also to the relief - of many we have included the downstream patch to honour the user's LCD - filtering preferences for subpixel rendering of fonts. The interface - remains private for the time being, whilst the proposed public API is - finalized. - -API changes ------------ - None. - -Snapshot 1.9.8 (2010-06-12) -=========================== - - One major API changes since the last snapshot, and a whole slew of bugs - fixed and inconsistencies eliminated. Far too many bugs fixed to - individually identify. We need to thank Benjamin Otte for his fantastic - work on the cairo-gl backend making it faster and more robust, Andrea - Canciani for finding so many bugs and developing test cases for them, as - well fixing them. And last but not least we must all thank Adrian Johnson for - continuing to eliminate bugs and improving the PostScript and PDF backends. - - This snapshot represents almost 4 months of bug fixing, bringing Cairo to - a point where we consider it almost ready to be a candidate for release. - There are a few known bugs left to be fixed, being tracked in - https://bugs.freedesktop.org/show_bug.cgi?id=24384, so please give Cairo a - whirl and report any regressions. The plan is to release a new snapshot - every other week leading to a 1.10 release with a target date of - 2010-08-16. - -API additions -------------- - CAIRO_FORMAT_RGB16_565 - - 16 bit devices still remain popular, and so with great demand, - CAIRO_FORMAT_RGB16_565 has been restored enabling applications to create - and use 16 bit images as sources and render targets. - - cairo_surface_create_for_rectangle() - - It is common practice to cut an image up into many smaller pieces and use - each of those as a source - a technique called texture atlasing. - cairo_surface_create_for_rectangle() extends Cairo to directly support use - of these subregions of another cairo_surface_t both as a source and as a - render target. - - cairo_region_create() - cairo_region_create_rectangle() - cairo_region_create_rectangles() - cairo_region_copy() - cairo_region_reference() - cairo_region_destroy() - cairo_region_equal() - cairo_region_status() - cairo_region_get_extents() - cairo_region_num_rectangles() - cairo_region_get_rectangle() - cairo_region_is_empty() - cairo_region_contains_rectangle() - cairo_region_contains_point() - cairo_region_translate() - cairo_region_subtract() - cairo_region_subtract_rectangle() - cairo_region_intersect() - cairo_region_intersect_rectangle() - cairo_region_union() - cairo_region_union_rectangle() - - The Cairo region API was actually added a couple of snapshots ago, but we - forgot to mention it at the time. A simple API for the handling of - rectangular pixel-aligned regions by Soeren Sandmann. - - -Backend-specific improvements ------------------------------ -cairo-gl - - Benjamin Otte made more than 200 commits in which he refactored the cairo-gl - backend, reducing a lot of code duplication and enabled him to begin working - on improving performance by reducing state changes and associated overhead. - -cairo-xlib - - Access to the underlying connection to the Display is now thread-safe - enabling cairo-xlib to be used in a multi-threaded application without fear - of random corruption. Thanks Benjamin Otte! - - cairo-xlib will now attempt to use PolyModeImprecise when compositing - trapezoids (i.e. a fill or a stroke operation with a non-trivial path) which - should allow hardware drivers more scope for accelerating the operation at - the cost of potentially incurring minute rendering errors. The mode can be - forced back to PolyModePrecise by setting the antialias parameter to - CAIRO_ANTIALIAS_SUBPIXEL. - -cairo-svg - - A notable improvement was contributed by Alexander Shulgin to enable SVG to - reference external image through the use an extended MIME data type. - -Snapshot 1.9.6 (2010-02-19) -=========================== -API additions -------------- - Add cairo_device_t - - The device is a generic method for accessing the underlying interface - with the native graphics subsystem, typically the X connection or - perhaps the GL context. By exposing a cairo_device_t on a surface and - its various methods we enable finer control over interoperability with - external interactions of the device by applications. The use case in - mind is, for example, a multi-threaded gstreamer which needs to serialise - its own direct access to the device along with Cairo's across many - threads. - - Secondly, the cairo_device_t is a unifying API for the mismash of - backend specific methods for controlling creation of surfaces with - explicit devices and a convenient hook for debugging and introspection. - - The principal components of the API are the memory management of: - - cairo_device_reference(), - cairo_device_finish() and - cairo_device_destroy(); - - along with a pair of routines for serialising interaction: - - cairo_device_acquire() and - cairo_device_release() - - and a method to flush any outstanding accesses: - - cairo_device_flush(). - - The device for a particular surface may be retrieved using: - - cairo_surface_get_device(). - - The device returned is owned by the surface. - -API changes (to API new in the cairo 1.9.x series) --------------------------------------------------- - cairo_recording_surface_create() - cairo_recording_surface_ink_extents() - - These are the replacement names for the functions previously named - cairo_meta_surface_create and cairo_meta_surface_ink_extents. - - cairo_surface_set_mime_data - - This interface is now changed such that the MIME data will be - detached if the surface is modified at all. This guarantees that - the MIME data will not become out of synch due to surface - modifications, and also means that for the MIME data to be useful, - it must be set after all modifications to the surface are - complete. - -API removal (of experiment API) -------------------------------- - The cairo-glitz backend is removed entirely, (in favor of the new - cairo-gl backend). See below for more on cairo-gl. - -Generic fixes -------------- - - Many improvements for drawing of dashed strokes - - Fix incorrect handling of negative offset - Faster computation of first dash (avoids near-infinite looping) - Approximate extremely fine dash patterns with appropriate alpha value - - Optimize spans-based renderers for repeated rows, (such as in a rounded rectangle) - -Backend-specific improvements ------------------------------ -cairo-drm - - This is a new, direct-rendering backend that supports Intel graphics - chipsets in the i915 and i965 families. It's still experimental and - will likely remain that way for a while. It's already got extremely - good performance on the hardware it supports, so if nothing else - provides a working proof and performance target for the cairo-gl - work for Intel graphics. - -cairo-gl - - Start using GLSL to accelerate many operations. Many thanks to Eric - Anholt and T. Zachary Laine for this work. For the first time, we - have what looks like what will be a very compelling OpenGL-based - backend for cairo (in terms of both quality and performance). - - See this writeup from Eric for more details on recent progress of - cairo-gl (which he presented at FOSDEM 2010): - - http://anholt.livejournal.com/42146.html - -cairo-image - - The image backend is made dramatically faster (3-5 times faster for - benchmarks consisting primarily of glyph rendering). - -cairo-quartz fixes: - - Many fixes from Robert O'Callahan and Andrea Canciani including: - - Fixed gradient pattern painting - Improved A8 image handling - Fixes for "unbounded" and other compositing operators - -cairo-pdf fixes: - - Improvements to embedding of JPEG and JPEG2000 data. - -cairo-ps fixes: - - Fix printing of rotated user fonts. - -Snapshot 1.9.4 (2009-10-15) -=========================== -API additions: - - cairo_meta_surface_create() - cairo_meta_surface_ink_extents() - - Finally exporting the internal meta-surface so that applications - have a method to record and replay a sequence of drawing commands. - - cairo_in_clip() - - Determines whether a given point is inside the current clip. - ??? Should this be called cairo_in_paint() instead? in-clip is the test - that is performed, but in-paint would be similar to in-fill and in-stroke. - -New utilities: - - cairo-test-trace - - A companion to cairo-perf-trace, this utility replays a trace against - multiple targets in parallel and looks for differences in the output, - and then records any drawing commands that cause a failure. - Future plans: - Further minimisation of the fail trace using "delta debugging". - More control over test/reference targets. - -Backend improvements: - - xlib - - Server-side gradients. The theory is that we can offload computation - of gradients to the GPU and avoid pushing large images over the - connection. Even if the driver has to fallback and use pixman to render - a temporary source, it should be able to do so in a more efficient manner - than Cairo itself. However, cairo-perf suggests otherwise: - - On tiny, Celeron/i915: - - before: firefox-20090601 211.585 - after: firefox-20090601 270.939 - - and on tiger, CoreDuo/nvidia: - - before: firefox-20090601 70.143 - after: firefox-20090601 87.326 - - In particular, looking at tiny: - - xlib-rgba paint-with-alpha_linear-rgba_over-512 47.11 (47.16 0.05%) -> 123.42 (123.72 0.13%): 2.62x slowdown - █▋ - xlib-rgba paint-with-alpha_linear3-rgba_over-512 47.27 (47.32 0.04%) -> 123.78 (124.04 0.13%): 2.62x slowdown - █▋ - - -New experimental backends: - - QT - - OpenVG - The initial work was done by Øyvind Kolås, and made ready for - inclusion by Pierre Tardy. - - OpenGL - An advanced OpenGL compositor. The aim is to write a integrate - directed rendering using OpenGL at a high-level into Cairo. In - contrast to the previous attempt using Glitz which tried to - implement the RENDER protocol on top of OpenGL, using the - high-level interface should permit greater flexibility and - more offloading onto the GPU. - The initial work on the backend was performed by Eric Anholt. - -Long standing bugs fixed: - - Self-intersecting strokes. - - A long standing bug where the coverage from overlapping semi-opaque - strokes (including neighbouring edges) was simply summed in lieu of - a costly global calculation has been fixed (by performing the costly - global calculation!) In order to mitigate the extra cost, the - tessellator has been overhauled and tune, which handles the fallback - for when we are unable to use the new span rasteriser on the stroke - (e.g. when using the current RENDER protocol). The large number of - pixel artefacts that implementing self-intersection elimination - removes is ample justification for the potential performance - regression. If you unfortunately do suffer a substantial performance - regression in your application, please consider obtaining a - cairo-trace and submitting it to us for analysis and inclusion into - our performance suite. - -Special thanks: - - To the AuroraUX team for providing access to one of their OpenSolaris - machines for cairo and pixman development. http://www.auroraux.org/ - -Snapshot 1.9.2 (2009-06-12) -=========================== -API additions: - - cairo_surface_set_mime_data() - cairo_surface_get_mime_data() - - Should this take unsigned int, unsigned long or size_t for the length - parameter? (Some datasets may be >4GiB in size.) - - Associate an alternate, compressed, representation for a surface. - Currently: - "image/jp2" (JPEG2000) is understood by PDF >= 1.5 - "image/jpeg" is understood by PDF,PS,SVG,win32-printing. - "image/png" is understood by SVG. - - cairo_pdf_version_t - cairo_pdf_surface_restrict_to_version() - cairo_pdf_get_versions() - cairo_pdf_version_to_string() - - Similar to restrict to version and level found in SVG and PS, - these limit the features used in the output to comply with the PDF - specification for that version. - - CAIRO_STATUS_INVALID_SIZE - Indicates that the request surface size is not supported by the - backend. This generally indicates that the request is too large. - - CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED - Indicates that a required callback for a user-font was not implemented. - - CAIRO_STATUS_LAST_STATUS - This is a special value to indicate the number of status values enumerated - at compile time. (This may differ to the number known at run-time.) - - The built-in twin font is now called "@cairo:" and supports a limited set - of options like "@cairo:mono". Where are these specified? - - cairo_in_fill() now uses HTML Canvas semantics, all edges are inside. - -New experimental backends: - - CairoScript - -New utility: - - cairo-trace and cairo-perf-trace - - cairo-trace generates a human-readable, replayable, compact(-ish!) - representation of the sequences of drawing commands made by an - application. - - Under the util/cairo-script directory is a library to replay traces. - - perf/cairo-perf-trace replays traces against multiple backends - and makes useful benchmark reports. This is integrated with - 'make perf'. You may collect your own traces or take advantage - of traces collected by the community: - - git://git.cairographics.org/git/cairo-traces - - (Put this into perf/cairo-traces to run these as part of "make perf".) - - There is additional WIP in building a debugging tool for cairo applications - based on CairoScript (currently very preliminary, mostly serves to show - that GtkSourceView is too slow) : - - people.freedesktop.org:~ickle/sphinx - -Test suite overhaul: - - The test suite is undergoing an overhaul, primarily to improve its speed - and utility. (Expect more changes in the near future to improve XFAIL - handling.) - -Optimisations: - polygon rasterisation! Joonas implemented the Tor polygon scan converter, - on typical geometry is about 30% faster for the image backend. - - Bovine Polaroids! For those not in on the joke, this is the long - awaited "copy-on-write snapshot" or "COW snapshot" support. The - user-visible feature is that including the same image multiple times - into a PDF file should result in only a single instance of that - image in the final output. This is unlike previous versions of cairo - which would generate very large PDF files with multiple copies of - the same image. Adrian says that the PDF is not quite working as - well as it should yet, so we hope for futher improvements before - cairo 1.10. - -Bug fixes: - - EXTEND_PAD. - - Better handling of large scale-factors on image patterns. - - Emit /Interpolate for PS,PDF images. - - Global glyph cache - cap on the total number of inactive glyphs, - should prove fairer for fonts with larger glyph sets. - - Compilation without fontconfig - - Improved handling of low-bitdepth sources (e.g. copying the contents - of 16-bit xserver windows) - -Regressions: - - cairo_traps_extract_region >10x slower. Fix pending. - -Still to come: - - Region tracking API (ssp) for damage tracking, hit testing etc - mime-surface - - An expiremental OpenGL backend? - - Tweaks to tessellator, allocations of patterns, delayed - initialisation of the xlib backend (reduce the cairo overhead of - render_bench by ~80%). - - -Release 1.8.8 (2009-06-16 Chris Wilson ) -================================================================== -The cairo community is pleased to announce the 1.8.8 release of the -cairo graphics library. This is the fourth update to cairo's stable -1.8 series and contains a small number of bug fixes (in particular a -few corrections to the documentation and a few fixes in the FreeType font -backend). This is being released just over six months after cairo 1.8.6. - -We recommend that everyone using cairo upgrade to 1.8.8. - --Chris - -Build fixes ------------ -There were reports of incompatibilities with the autotools bundled in with -the 1.8.6 tarball. This release has been built with automake-1.10.2 and -autoconf-2.63. - -The configure check for FreeType has been improved: - - typo in check for version of freetype in configure script - https://bugs.freedesktop.org/show_bug.cgi?id=19283 - -Compilation on 64-bit MacOS/X fixes: - - Cannot build cairo_quartz_font_face_create_for_atsu_font_id on 64-bit Mac OS X - https://bugs.freedesktop.org/show_bug.cgi?id=15702 - -Bug fixes ---------- -Uninitialised status return within _cairo_clip_intersect_mask(). This caused -random crashes and general mayhem as an error could be generated causing all -rendering to the context to stop. - -Avoid transforming nearly-degenerate matrices into degenerate matrices: - - Painting stops in this case, using -moz-transform: scale, rotate and video - https://bugzilla.mozilla.org/show_bug.cgi?id=467423 - -A few FreeType font handling bugs were fixed: - - Rendering with PANGO_GRAVITY_EAST leads to different results with image and pdf - https://bugs.freedesktop.org/show_bug.cgi?id=21985 - - Don't call FT_Done_Face() on faces we did not create - - zombie ft_font_face / ft_unscaled_font mutual referencing problems - http://bugs.freedesktop.org/show_bug.cgi?id=21706 - -Ensure win32 font backend sets the return value to -1 (indicating the absent -glyph) if the font index lookup for the unicode character fails. And -similarly fix a bug where a fatal error was raised for an invalid glyph. - - cairo_scaled_font_glyph_extents breaks with invalid glyph id - http://bugs.freedesktop.org/show_bug.cgi?id=20255 - -Various improvements to the documentation, reported by Truc Troung: - - https://bugs.freedesktop.org/show_bug.cgi?id=20095 - https://bugs.freedesktop.org/show_bug.cgi?id=20154 - https://bugs.freedesktop.org/show_bug.cgi?id=20180 - https://bugs.freedesktop.org/show_bug.cgi?id=20183 - https://bugs.freedesktop.org/show_bug.cgi?id=20182 - https://bugs.freedesktop.org/show_bug.cgi?id=20441 - - -Release 1.8.6 (2008-12-13 Chris Wilson ) -================================================================== -The cairo community is pleased to announce the 1.8.6 release of the -cairo graphics library. This is the third update to cairo's stable -1.8 series and contains a small number of bug fixes (in particular a -few fixes for failures of cairo 1.8.4 on Quartz and PDF, and build fixes for -a couple of backends). This is being released just under a month after -cairo 1.8.4. - -We recommend that everyone using cairo upgrade to 1.8.6. - --Chris - -Build fixes ------------ -Fix build of DirectFB backend with debugging enabled: - - Bug in _cairo_directfb_surface_release_source_image function - http://bugs.freedesktop.org/show_bug.cgi?id=18322 - -Fix build on OS/2. - -Bug fixes ---------- -Workaround a mis-compilation of cairo_matrix_invert() that generated invalid -matrices and triggered assertion failures later. The issue was reported by -Peter Hercek. - -Invalid computation of the modulus: - - https://bugzilla.mozilla.org/show_bug.cgi?id=466258 - -Invalid referencing of patterns in the Quartz backend: - - Failed assertion `CAIRO_REFERENCE_COUNT_HAS_REFERENCE - (&pattern->ref_count)' when using cairo quartz backend - http://bugs.freedesktop.org/show_bug.cgi?id=18632 - -Invalid references to glyphs after early culling, causing segmentation faults -in the PDF backend: - - http://lists.cairographics.org/archives/cairo/2008-December/015976.html - -Check for XRender in the XCB backend, or else we may attempt an invalid memory -access: - - XCB backend fails with missing render. - https://bugs.freedesktop.org/show_bug.cgi?id=18588 - -Release 1.8.4 (2008-11-14 Carl Worth ) -========================================================= -The cairo community is pleased to announce the 1.8.4 release of the -cairo graphics library. This is the second update to cairo's stable -1.8 series and contains a small number of bug fixes, (in particular a -few fixes for build failures of cairo 1.8.2 on various systems). This -is being released just over two weeks after cairo 1.8.2. - -We recommend that everyone using cairo upgrade to 1.8.4. - --Carl - -Build fixes ------------ -Fix build with older XRender that doesn't define RepeatNone: - - Build of xlib backend fails against old XRender (RepeatNone undeclared) - https://bugs.freedesktop.org/show_bug.cgi?id=18385 - -Fix build with bash version <= 3.0: - - doltlibtool broken on linux with bash 3.00.0 - https://bugs.freedesktop.org/show_bug.cgi?id=18363 - -Bug fixes ---------- -Avoid triggering a bug in X.org server 6.9 resulting in a hung machine -requiring a reboot: - - https://bugs.freedesktop.org/show_bug.cgi?id=15628#c2 - -Fix display of user fonts as exercised by proposed support for type3 -fonts in poppler (unsigned promotion fixes): - - Use cairo user-font for Type 3 fonts - http://lists.freedesktop.org/archives/poppler/2008-October/004181.html - -Avoid miscomputing size of fallback images required when rendering -with CLEAR, IN, or SOURCE operator to vector surfaces, (PS, PDF, SVG, -etc.). - -Be more tolerant of broken fonts when subsetting type1 fonts: - - Error handling in cairo_type1_font_subset_get_glyph_names_and_widths - http://lists.cairographics.org/archives/cairo/2008-October/015569.html - -Fix cairo_fill_extents, cairo_stroke_extents, cairo_path_extents, to -correctly allow NULL parameters as documented. - -Fix potential crash on emitting a type3 glyph after having drawn text -paths from the same font, (for example with cairo_text_path). - -Release 1.8.2 (2008-10-29 Carl Worth ) -========================================================= -The cairo community is pleased to announce the 1.8.2 release of the -cairo graphics library. This is the first update to cairo's stable 1.8 -series and contains a large number of bug fixes. It is being released -just over one month since cairo 1.8.0. - -This release consists primarily of bug fixes, but there is one notable -new feature, (the ability to build cairo without an external font -backend), and there are a few optimizations as well. See below for -details on these changes and the most important bug fixes. - -While many people have contributed to this release, Chris Wilson -deserves particular mention. He has contributed well over twice as -many changes to cairo since 1.8.0 than everyone else combined. We -greatly appreciate the tremendous efforts of Chris and all cairo -contributors. - -We recommend everyone upgrade to cairo 1.8.2 and hope that everyone -will have lots of fun with cairo! - --Carl - -New feature ------------ -It is now possible to build cairo without any font backend, (such as -freetype, win32 or quartz). This is most useful when the application -provides custom font rendering through the user-font API. But in the -case where no external font backend is available, and no user-font is -provided, cairo will render with a failsafe font, (a stroked font -covering visible ASCII character). (Behdad Esfahbod) - -Optimizations -------------- -Dramatically speed up compilation with dolt (removes much of the -libtool overhead) (Behdad Esfahbod with thanks to Josh Triplett). - -Several minor optimizations to tessellator (special-cased comparisons, -faster insert for skiplist, etc.) (Chris Wilson). - -Optimize away fractional translation component when doing -EXTEND_NEAREST filtering, (for better performance). - -General bug fixes ------------------ -Allow cloning sub-regions of similar surfaces to fix this bug -(Chris Wilson): - - Crafted gif file will crash firefox - [XError: 'BadAlloc (insufficient resources for operation)'] - https://bugzilla.mozilla.org/show_bug.cgi?id=424333 - -Fix some matrix confusion to fix this regression (Chris Wilson): - - Translucent star exports in a wrong way to PDF - https://bugs.launchpad.net/inkscape/+bug/234546 - -Fix some long-standing bugs with respect to properly computing the -extents of transformed, filtered surfaces (Owen Taylor, Carl Worth, -and Chris Wilson): - - Bad clipping with EXTEND_NONE - http://bugs.freedesktop.org/show_bug.cgi?id=15349 - - Improve filtering handling in cairo-pattern.c - http://bugs.freedesktop.org/show_bug.cgi?id=15367 - - Many thanks to Chris Wilson for digging out and cleaning up - these fixes. - -Fix compilation on Solaris 10 (Chris Wilson): - - Cairo requires -DREENTRANT (along with -D_POSIX_THREAD_SEMANTICS) - to compile on Solaris 10 with pthreads - https://bugs.freedesktop.org/show_bug.cgi?id=18010 - -Fix very old bug causing dashes to be rendered at the wrong length in -fallback images (Adrian Johnson) - - Dashed strokes too long in fallback images - https://bugs.freedesktop.org/show_bug.cgi?id=9189 - -Fix broken dashing when a dashed path starts outside the clip region -(Chris Wilson). - -Avoid range overflow when computing large patterns (Benjamin Otte and -Chris Wilson). - -Avoid crashing due to an invalid font with an incorrect entry in its -CMAP table (Adrian Johnson). - -Fix bugs in computing maximum size of text requests that can be sent -with the Render extension, (avoiding potential crashes when rendering -large amounts of text) (Behdad Esfahbod and Chris Wilson). - -Fix rendering of operators unbounded by the mask (Chris Wilson). - -Fix compilation on systems without compiler support for a native -64-bit type (Chris Wilson). - -Fix several cases of missing error-status propagation. (Chris Wilson, -doing the work he seems to never tire of). - -Fix several locking issues found with the lockdep valgrind skin (Chris -Wilson). - -Backend-specific bug fixes --------------------------- -xlib: Avoid crash due to attempting XRender calls on pixmaps with -formats not supported by the Render extension (Chris Wilson): - - XRender crashes due to NULL pointer from Cairo on SGI O2 - https://bugs.freedesktop.org/show_bug.cgi?id=11734 - -xlib: Add support for XImages with depth of 4, 20, 24, or 28 bits -(Chris Wilson): - - cairo doesn't support 24 bits per pixel mode on X11 - https://bugs.freedesktop.org/show_bug.cgi?id=9102 - -xlib: Avoid mistakenly considering two surfaces as similar just -because their depths match (while their Render formats do not) (Karl -Tomlinson). - -ps: Fix slight mis-scaling of bitmapped fonts (Adrian Johnson) - -svg: Correctly emit comp-op for paint, mask, and show_glyphs -operations (Emmanuel Pacaud). - -svg: Use finer-grained fallbacks for SVG 1.2 (as PS and PDF backends -have been doing since 1.6.0) (Chris Wilson). - -win32: Fallback to DIB if DDB create fails for -cairo_surface_create_similar (Vladimir Vukicevic). - -win32: Fix compatibility with Windows Mobile (Vladimir Vukicevic). - -win32: Fix static builds to not do __declspec(dllimport) on public -functions. This requires the user to set a CAIRO_WIN32_STATIC_BUILD -environment variable when compiling (Behdad Esfahbod). - -Release 1.8.0 (2008-09-25 Carl Worth ) -========================================================= -The cairo community is happy (and relieved) to announce the 1.8.0 -release of the cairo graphics library. This is a major update to -cairo, with new features and enhanced functionality which maintains -compatibility for applications written using any previous major cairo -release, (1.6, 1.4, 1.2, or 1.0). We recommend that anybody using a -previous version of cairo upgrade to cairo 1.8.0. - -The dominant theme of this release is improvements to cairo's ability -to handle text. The highlights include a new "user fonts" feature as -well as a new cairo_show_text_glyphs API which allows glyphs to be -embedded in PDF output along with their original text, (for searching, -selection, and copy-and-paste). Another major feature is a revamp of -cairo's build system making it much easier to build cairo on various -platforms. - -See below for more details. - -User fonts ----------- -This new API allows the user of cairo API to provide drawings for -glyphs in a font. A common use for this is implementing fonts in -non-standard formats, like SVG fonts and Flash fonts. This API can -also be used by applications to provide custom glyph shapes for fonts -while still getting access to cairo's glyph caches. See -test/user-font.c and test/user-font-proxy.c for usage examples. This -is based on early work by Kristian Høgsberg. Thanks Kristian! - -This new API consists of the following functions (and corresponding -_get functions): - - cairo_user_font_face_create - - cairo_user_font_face_set_init_func - cairo_user_font_face_set_render_glyph_func - cairo_user_font_face_set_text_to_glyphs_func - cairo_user_font_face_set_unicode_to_glyph_func - -An additional, new API is - - cairo_scaled_font_text_to_glyphs - -We were previously reluctant to provide this function as -text-to-glyphs support in cairo was limited to "toy" font -functionality, not really interesting for real-world text -processing. However, with user fonts landing, this API is needed to -expose full access to how user fonts convert text to glyphs. This is -expected to be used by text toolkits like Pango, as well as "proxy" -user-font implementations. - -cairo_show_text_glyphs ----------------------- -This new API allows the caller of cairo to provide text data -corresponding to glyphs being drawn. The PDF backend implements this -new API so that complex text can be copied out of cairo's PDF output -correctly and reliably, (assuming the user of cairo calls -cairo_show_text_glyphs). The cairo_show_text_glyphs API is definitely -the most daunting API to debut in cairo. It is anticipated that pango -(and similar high-level text libraries) will be the primary users of -this API. In fact, pango 1.22 already uses cairo_show_text_glyphs. -Behdad was the architect and implementor of this effort. Thanks, -Behdad! - -The cairo_show_text_glyphs API includes the following new functions: - - cairo_show_text_glyphs - - cairo_glyph_allocate - cairo_glyph_free - - cairo_text_cluster_allocate - cairo_text_cluster_free - - cairo_surface_has_show_text_glyphs - -Build system revamp -------------------- -The primary goal of the revamp is to make the build system less -fragile, (particularly for non-Linux platforms). For example, now -people building on win32 will no longer need to maintain a -platform-specific list of files to be built. See the new README.win32 -for details. Also, the .so file will now be installed with a different -naming scheme, (for example, 1.7.6 will install with a .10800 -suffix). Many thanks to Behdad and his small army of helpers! - -Assorted API additions ----------------------- -For API completeness, several missing "getter" functions were added: - - cairo_scaled_font_get_scale_matrix - - cairo_surface_get_fallback_resolution - - cairo_toy_font_face_create - cairo_toy_font_face_get_family - cairo_toy_font_face_get_slant - cairo_toy_font_face_get_weight - -The new cairo_toy_font_face functions provide access to functionality -and settings provided by cairo_select_font_face(). Thanks Behdad! - -cairo-ps/cairo-pdf: More efficient output ------------------------------------------ -Adrian Johnson has been busy fixing all kinds of bugs in PS and PDF -backends, as well making them generate much more compact output by -avoiding things like re-emitting the color or linestyle on every -drawing operation. Thanks Adrian! - -cairo-xlib: dithering ---------------------- -Dithering: Cairo now does simple dithering when rendering to legacy X -servers. This is most visible with 8-bit visuals. Thanks Behdad! - -cairo-xlib: Avoid rendering glyphs out of surface bounds --------------------------------------------------------- -This seemingly harmless optimization exposed a bug in OpenOffice.org 3 -versions where OO.o was passing bogus surface extents to cairo, -resulting in no text rendered in OO.o. Please contact your -distribution's OO.o maintainers if you see this bug and point them to -the following URL: - - https://bugs.freedesktop.org/show_bug.cgi?id=16209 - -cairo-xlib: Improved performance with X server without Render -------------------------------------------------------------- -Cairo now performs better on remote X servers that lack the Render -extension by being smarter about using X core protocol facilities -instead of falling back to doing all rendering on the client side. - -cairo-ft: respecting FC_FT_FACE -------------------------------- -Previously it was impossible to instruct cairo to do emboldening on a -font face object created from an FT_Face. Cairo now respects and uses -the FC_FT_FACE fontconfig pattern element, so emboldening can be -achieved by using cairo_ft_font_face_create_for_pattern() and a -carefully crafted pattern using FC_FT_FACE and FC_EMBOLDEN. Thanks -Behdad! - -cairo-directfb: backend improvements ------------------------------------- -The directfb backend, though still unsupported, has seen a good deal -of improvements. Thanks Vlad! - -Bug fixing and optimizations ----------------------------- -xlib: Faster bookkeeping (Karl Tomlinson) - https://bugzilla.mozilla.org/show_bug.cgi?id=453199#c5 - -PS: Fix gradients with non-constant alpha (Chris Wilson) - -Fix deadlock in user-font code (Richard Hughes and Behdad Esfahbod) - http://bugs.freedesktop.org/show_bug.cgi?id=16819 - -Countless other bugs have been fixed and optimizations made, many of -them thanks to Chris Wilson. Thanks Chris and others! - -Note also that the code that had been in cairo 1.7.x calling into -freetype's optional lcd_filter function was removed from cairo before -the 1.8.0 release. We do expect this code to come back in some form in -the future. - -Snapshot 1.7.6 (2008-09-17 Carl Worth ) -========================================================== -The cairo community is happy to announce the 1.7.6 snapshot of the -cairo graphics library. This is a "release candidate" for the upcoming -1.8.0 release, so we will greatly appreciate any reports of problems -in this release, and no major changes are currently planned before -1.8. - -Notable changes in 1.7.6 ------------------------- -The largest number of changes since 1.7.4 did not change the -implementation of cairo itself, but instead revamped cairo's build -system. The primary goal of the revamp is to make the build system -less fragile, (particularly for non-Linux platforms). For example, now -people building on win32 will no longer need to maintain a -platform-specific list of files to be built. Also, the .so file will -now be installed with a different naming scheme, (for example, 1.7.6 -will install with a .10706 suffix). Much thanks, Behdad! - -And, as usual, Chris Wilson has made another large round of robustness -improvements, (eliminating dead code, fixing propagation of error -status values, test suite improvements, etc. etc.). Thanks as always, -Chris! - -API changes since 1.7.4 ------------------------ -There have been a few changes of API that was new during the 1.7 -series: - -* Remove cairo_font_options_set_lcd_filter - and cairo_font_options_get_lcd_filter - - Motivation: At the Cairo Summit, this API was determined to be too - specific to the freetype font backend to be in the general - API. A similar API with a cairo_ft prefix might be introduced - in the future. Note that cairo will still respect the - corresponding fontconfig settings for these options. - -* Replace cairo_has_show_glyphs - with cairo_surface_has_show_glyphs - - Motivation: This really is a surface-specific interface, and the - convenience function on the cairo_t is not obviously - necessary. An application can easily call: - - cairo_surface_has_show_glyphs (cairo_get_target (cr)); - - as needed. - -* Add cairo_text_cluster_flags_t - to cairo_show_text_glyphs - cairo_scaled_font_text_to_glyphs - cairo_user_scaled_font_text_to_glyphs_func_t - - Motivation: This flag, (and specifically the - CAIRO_TEXT_CLUSTER_FLAG_BACKWARD value), replaces the - cairo_bool_t backward argument in each of the above - interfaces. This leads to more readable user code, and also - allows future extensibility. - -As always, there are no changes to any API from any major cairo -release, (1.0.x, 1.2.x, 1.4.x, 1.6.x). Cairo maintains the same -compatibility promise it always has. - -Bug fixes since 1.7.4 ---------------------- -xlib: Faster bookkeeping (Karl Tomlinson) - https://bugzilla.mozilla.org/show_bug.cgi?id=453199#c5 - -PS: Fix gradients with non-constant alpha (Chris Wilson) - -Fix deadlock in user-font code (Richard Hughes and Behdad Esfahbod) - http://bugs.freedesktop.org/show_bug.cgi?id=16819 - -Several other minor fixes. - -Snapshot 1.7.4 (2008-08-11 Behdad Esfahbod ) -=============================================================== -The cairo community is embarrassed to announce availability of the 1.7.4 -snapshot of the cairo graphics library. This is a followup release to the -1.7.2 snapshot to ship a tarball that can actually be built. The only -change since 1.7.4 is including the missing header file -cairo-user-font-private.h in the distribution. - -Snapshot 1.7.2 (2008-08-11 Behdad Esfahbod ) -=============================================================== -The cairo community is finally ready to announce availability of the 1.7.2 -snapshot of the cairo graphics library. This is embarrassingly the first -snapshot in the 1.7 unstable series of cairo, leading to the eventual release -of cairo 1.8, currently planned for late September. - -This snapshot comes four months after the 1.6.4 release. We have done a -really bad job on getting development snapshots out this cycle, but -hopefully all the API changes for 1.8 are now finished and the remaining -weeks will be spent on bug-fixing. There is more than 400 commits worth -of changes in this snapshot, and those can use some testing. Read on! - -Text, text, and more text! --------------------------- -The dominant theme of this release, and 1.8 in general, is improvements -around cairo text API. Here is a high-level list of changes with text -handling: - -User fonts ----------- -This is new API allowing the user of cairo API to provide drawings for glyphs -in a font. This is most useful in implementing fonts in non-standard formats, -like SVG fonts and Flash fonts, but can also be used by games and other -applications to draw "funky" fonts. See test/user-font.c and -test/user-font-proxy.c for usage examples. This is based on early work by -Kristian Høgsberg. Thanks Kristian! - -show_text_glyphs ----------------- -This new API allows the caller of cairo to mark text glyphs with their -original text. The PDF backend implements this new API and latest Pango -master uses it. The result is (when bugs are fixed) that complex text can be -copied out of pangocairo's PDF output correctly and reliably. There are bugs -to fix though. A few poppler bugs, and some more in cairo and pango. - -To test show_text_glyph, just grab pango master and this cairo snapshot and -print text in gedit. Open in acroread or evince, select all, copy, paste -in gedit and compare. The Arabic text with diacritic marks is particularly -showing bad. Try with pango/pango-view/HELLO.txt if you are brave -enough. The Indic text is showing improvements, but is still coming out -buggy. - -LCD subpixel filtering using FreeType -------------------------------------- -FreeType 2.3.5 added support for various LCD subpixel filtering, and -fontconfig 2.6.0 added support for configuring LCD filter on a font by font -basis. Cairo now relies on FreeType and fontconfig for subpixel filtering. -This work is based on David Turner's original patch to cairo, maintained -and tested by Sylvain Pasche and others. Thanks all! - -Toy font face constructor and getter ------------------------------------- -Mostly for API completion, but also useful for higher level (like Pango) to -hook into what the user has set using cairo_select_font_face(), making that -toy API a bit more useful. - -FreeType: respecting FC_FT_FACE -------------------------------- -Previously it was impossible to instruct cairo to do emboldening on a font -face object created from an FT_Face. Cairo now respects and uses the -FC_FT_FACE fontconfig pattern element, so emboldening can be achieved by -using cairo_ft_font_face_create_for_pattern() and a carefully crafted pattern -using FC_FT_FACE and FC_EMBOLDEN. - - -PS/PDF: More efficient output ------------------------------ -Adrian Johnson has been busy fixing all kinds of bugs in PS and PDF -backends, as well making them generate much more compact output by avoiding -things like re-emitting the color or linestyle on every drawing operation. -Thanks Adrian! - - -Xlib: Dithering ---------------- -Cairo now does simple dithering when rendering to legacy X servers. This is -mostly visible with 8-bit visuals. - -Xlib: Avoid rendering glyphs out of surface bounds --------------------------------------------------- -This seemingly harmless change manifested a bug with OpenOffice.org 3 versions -where OO.o was passing bogus surface extents to cairo, resulting in no text -rendered in OO.o. Please contact your distro's OO.o maintainers if you see -this bug and point them to the following URL: - - https://bugs.freedesktop.org/show_bug.cgi?id=16209 - -Xlib: Improved performance with Xrender-less X servers ------------------------------------------------------- -Cairo now performs better on remote, Xrender-less X servers by being smarter -about using X core protocol facilities instead of falling back to doing all -rendering on the client side. - - -Directfb: backend improvements ------------------------------- -The directfb backend, though still unsupported, has seen a good deal of -improvements. Thanks Vlad! - - -Bug fixing and optimizations ----------------------------- -Countless bugs have been fixed and optimizations made, many of them thanks to -Chris Wilson. Thanks Chris! - - -API additions -------------- - -cairo_show_text_glyphs - - This is a new text rendering API. Being a more advanced version of - cairo_show_glyphs(), it is aimed for use by higher-level text toolkits like - Pango, and enables better text extraction from output generated by backends - like PDF and SVG. The PDF backend already implements it, and the upcoming - Pango release will use it. - - To make that API work, a bunch of other additions were made: - -cairo_glyph_allocate -cairo_glyph_free -cairo_text_cluster_t -cairo_text_cluster_allocate -cairo_text_cluster_free -cairo_surface_has_show_text_glyphs - - -cairo_user_font_face_create - - This is the "user" font face constructor, accompanied by a variety of method - signatures, getters, and setters for a callback-based font backend: - -CAIRO_FONT_TYPE_USER -cairo_user_scaled_font_init_func_t -cairo_user_scaled_font_render_glyph_func_t -cairo_user_scaled_font_text_to_glyphs_func_t -cairo_user_scaled_font_unicode_to_glyph_func_t -cairo_user_font_face_set_init_func -cairo_user_font_face_set_render_glyph_func -cairo_user_font_face_set_text_to_glyphs_func -cairo_user_font_face_set_unicode_to_glyph_func -cairo_user_font_face_get_init_func -cairo_user_font_face_get_render_glyph_func -cairo_user_font_face_get_text_to_glyphs_func -cairo_user_font_face_get_unicode_to_glyph_func - - -cairo_scaled_font_text_to_glyphs - - We were previously reluctant to provide this function as text-to-glyphs - support in cairo was limited to "toy" font functionality, not really - interesting for real-world text processing. However, with user-fonts - landing, this API is needed to expose full access to how user-fonts - convert text to glyphs. This is expected to be used by text toolkits like - Pango, as well as "proxy" user-font implementations. - - -cairo_lcd_filter_t -cairo_font_options_set_lcd_filter -cairo_font_options_get_lcd_filter - - These add the possibility to choose between various available LCD subpixel - filters. The available filter values are modeled after what FreeType - provides. - - -cairo_toy_font_face_create -cairo_toy_font_face_get_family -cairo_toy_font_face_get_slant -cairo_toy_font_face_get_weight - - These provide access to functionality and settings provided by - cairo_select_font_face(). - - -cairo_scaled_font_get_scale_matrix -cairo_surface_get_fallback_resolution - - For API completeness. - - -Various new values for cairo_status_t enum - - -Known issues: - -- Type3 fonts generated by cairo's PDF backend may show up in poppler/Evince - in a different color than expected. This is fixed in poppler master branch. - This mostly affects cairo user fonts. The test case test/user-font.c - demonstrates this. - -- User fonts using other fonts in their rendering are currently embedded in - PDF as fallback bitmap glyphs. This will be (hopefully) fixed before 1.8. - The test case test/user-font-proxy.c demonstrates this. - - -Release 1.6.4 (2008-04-11 Carl Worth ) -========================================================= -The cairo community is wildly embarrassed to announce the 1.6.4 -release of the cairo graphics library. This release reverts the xlib -locking change introduced in 1.6.4, (and the application crashes that -it caused). The community would be glad to sack its current release -manager and is accepting applications for someone who could do the job -with more discipline. - -Revert 'add missing locking in cairo-xlib' ------------------------------------------- -This change was introduced in cairo 1.6.2, but also introduced a bug -which causes many cairo-xlib applications to crash, (with a -segmentation fault inside of XSetClipMask). Instead of attempting -another fix for the broken fix, the change in 1.6.2 has been -reverted. The original bug which the change was addressing has been -present since at least cairo 1.4, so it is not expected that leaving -this bug unfixed will cause any new problems for applications moving -from cairo 1.4 to cairo 1.6. - -At this point, the code of cairo 1.6.4 differs from cairo 1.6.0 only -in the fix for the PostScript-printer crashes. - -Tweak build to avoid linking with g++ -------------------------------------- -Cairo 1.6.4 avoids a quirk in automake that was causing the cairo -library to be linked with g++ and linked against libstdc++ even when -only C source files were compiled for the library. - -Release 1.6.2 (2008-04-11 Carl Worth ) -========================================================= -The cairo community is pleased (but somewhat sheepish) to announce the -1.6.2 release of the cairo graphics library. This is an update to -yesterday's 1.6.0 release with an important fix to prevent cairo's -PostScript output from crashing some printers. This release also -includes a locking fix for cairo's xlib backend to improve thread -safety. There are no changes beyond these two fixes. - -Fix for PostScript printer crash --------------------------------- -Adrian Johnson discovered that cairo 1.6.0 was being a bit hard on -PostScript printers, by changing the font matrix very frequently. This -causes some PostScript interpreters to allocate new font objects every -few glyphs, eventually exhausting available resources. The fix -involves leaving translational components of the font matrix as zero, -so that the PostScript interpreter sees an identical font matrix -repeatedly, and can more easily share internal font object resources. - -This fix has been tested to resolve the bugs posted here, (for both -Xerox and Dell printers): - - Printing some PDFs from evince is crashing our Xerox printer - http://bugs.freedesktop.org/show_bug.cgi?id=15348 - - Cairo-generated postscript blocks Dell 5100cn - http://bugs.freedesktop.org/show_bug.cgi?id=15445 - -Add missing locking in cairo-xlib ---------------------------------- -Chris Wilson noticed that cairo 1.6.0 was manipulating an internal -cache of GC object within cairo's Xlib backend without proper -locking. The missing locking could cause failures for multi-threaded -applications. He fixed this in 1.6.2 by adding the missing locks. - -Release 1.6.0 (2008-04-10 Carl Worth ) -========================================================= -The cairo community is quite pleased to announce the 1.6.0 release of -the cairo graphics library. This is a major update to cairo, with new -features and enhanced functionality which maintains compatibility for -applications written using cairo 1.4, 1.2, or 1.0. We recommend that -anybody using a previous version of cairo upgrade to cairo 1.6.0. - -The most significant new features in this release are dramatically -improved PDF and PostScript[*] output, support for arbitrary X server -visuals (including PseudoColor), a new Quartz backend, and and a new -"win32 printing" backend. See below for more details on these and -other new features. - -New dependency on external pixman library (Thanks, Søren!) ----------------------------------------------------------- -As of cairo 1.6, cairo now depends on the pixman library, for which -the latest release can be obtained alongside cairo: - - http://cairographics.org/releases/pixman-0.10.0.tar.gz - -This library provides all software rendering for cairo, (the -implementation of the image backend as well as any image fallbacks -required for other backends). This is the same code that was -previously included as part of cairo itself, but is now an external -library so that it can be shared by both cairo and by the X server, -(which is where the code originated). - -Improved PDF, PostScript, and SVG output (Thanks, Adrian!) ----------------------------------------------------------- -Users of the cairo-pdf, cairo-ps, and cairo-svg should see a dramatic -improvement from cairo 1.2/1.4 to 1.6. With this release there are now -almost no operations that will result in unnecessary rasterization in -the PDF and PostScript. Rasterized "image fallbacks" are restricted -only to minimal portions of the document where something is being -drawn with cairo that is beyond the native capabilities of the -document, (this is rare for PDF or SVG, but occurs when blending -translucent objects for PostScript). - -This means that the final output will be of higher quality, and will -also be much smaller, and therefore will print more quickly. The -machinery for doing analysis and minimal fallbacks also benefits the -win32-printing surface described below. - -In addition to doing less rasterization, the PostScript and PDF output -also has several other improvements to make the output more efficient -and more compatible with specifications. - -[*] Note: Just before this release, a bug has been reported that the -PostScript output from cairo can crash some printers, (so far the -following models have been reported as problematic Xerox Workcentre -7228 or 7328 and Dell 5100cn). We will implement a workaround as soon -as we can learn exactly what in cairo's output these printers object -to, (and we could use help from users that have access to misbehaving -printers). This bug is being tracked here: - - Printing some PDFs from evince is crashing our Xerox printer - http://bugs.freedesktop.org/show_bug.cgi?id=15348 - -New support for arbitrary X server visuals (Thanks, Keith and Behdad!) ----------------------------------------------------------------------- -As of cairo 1.6, cairo should now work with an arbitrary TrueColor or -8-bit PseudoColor X server visual. Previous versions of cairo did not -support these X servers and refused to draw anything. We're pleased to -announce that this limitation has been lifted and people stuck with -ancient display systems need no longer be stuck with ancient software -just because of cairo. - -New, supported Quartz backend for Mac OS X (Thanks, Brian and Vladimir!) ------------------------------------------------------------------------- -As of cairo 1.6, the cairo-quartz backend is now marked as "supported" -rather than "experimental" as in previous cairo releases. Its API now -has guarantees of API stability into future cairo releases, and its -output quality is comparable to other backends. There have been -significant improvements to cairo-quartz since 1.4. It now uses many -fewer image fallbacks, (meaning better performance), and has greatly -improved text rendering. - -New, "win32 printing" backend (Thanks, Adrian and Vladimir!) ------------------------------------------------------------- -A new win32-printing surface has been added with an interface very -similar to the original win32 surface, (both accept an HDC -parameter). But this new surface should only be called with a printing -DC, and will result in all drawing commands being stored into a -meta-surface and emitted after each page is complete. This allows -cairo to analyze the contents, (as it does with PDF, PostScript, and -SVG backends), and to do minimal image-based fallbacks as -necessary. The analysis keeps things as efficient as possible, while -the presence of fallbacks, (when necessary), ensure the consistent, -high-quality output expected from cairo. - -Robustness fixes (Thanks, Chris!) ---------------------------------- -There has been a tremendous number of improvements to cairo's -robustness. Areas that have been improved include: - - * Proper reporting of errors - - * Responding correctly to invalid input - - * Avoiding integer overflows - - * Avoiding memory leaks on error-recovery paths - - * Making reference counting thread safe - - * Exhaustive testing of memory allocation points - -Other fixes (Thanks, everybody!) --------------------------------- -Cairo's internal fixed-point representation has been changed from -16.16 to 24.8. This has a direct impact on applications as it allows -much larger objects to be drawn before internal limits in cairo make -the drawing not work. - -The CAIRO_EXTEND_PAD mode is now fully supported by surface -patterns. This mode allows applications to use cairo_rectangle and -cairo_fill to draw scaled images with high-quality bilinear filtering -for the internal of the image, but without any objectionably blurry -edges, (as would happen with the default EXTEND_NONE and cairo_paint). - -Rendering with CAIRO_ANTIALIAS_NONE has been fixed to be more -predictable, (previously image rendering and geometry rendering would -be slightly misaligned with respect to each other). - -The reference manual at http://cairographics.org/manual now documents -100% of the functions and types in cairo's public API. - -API additions -------------- -Several small features have been added to cairo with new API functions: - -cairo_format_stride_for_width - - Must be called to compute a properly aligned stride value before - calling cairo_image_surface_create_for_data. - -cairo_has_current_point - - Allows querying if there is a current point defined for the - current path. - -cairo_path_extents - - Allows querying for path extents, (independent of any fill or - stroke parameters). - -cairo_surface_copy_page -cairo_surface_show_page - - Allow beginning a new document page without requiring a cairo_t - object. - -cairo_ps_surface_restrict_to_level -cairo_ps_get_levels -cairo_ps_level_to_string -cairo_ps_surface_set_eps - - Allow controlling the Post PostScript level, (2 or 3), to - target, as well as to generate Encapsulated PostScript (EPS). - -cairo_quartz_font_face_create_for_cgfont - - Create a quartz-specific cairo_font_face_t from a CGFontRef. - -cairo_win32_font_face_create_for_logfontw_hfont - - Create a win32-specific cairo_font_face from a LOGFONTW and an - HFONT together. - -Thanks, Everyone! ------------------ -I've accounted for 32 distinct people with attributed code added to -cairo between 1.4.14 and 1.6.0, (their names are below). That's an -impressive number, but there are certainly dozens more that -contributed with testing, suggestions, clarifying questions, and -encouragement. I'm grateful for the friendships that have developed as -we have worked on cairo together. Thanks to everyone for making this -all so much fun! - -Adrian Johnson, Alp Toker, Antoine Azar, Behdad Esfahbod, -Benjamin Otte, Bernardo Innocenti, Bertram Felgenhauer, -Boying Lu, Brian Ewins, Carl Worth, Chris Heath, Chris Wilson, -Claudio Ciccani, Emmanuel Pacaud, Jeff Muizelaar, Jeremy Huddleston, -Jim Meyering, Jinghua Luo, Jody Goldberg, Jonathan Gramain, -Keith Packard, Ken Herron, Kouhei Sutou, Kristian Høgsberg, -Larry Ewing, Martin Ejdestig, Nis Martensen, Peter Weilbacher, -Richard Hult, Shailendra Jain, Søren Sandmann Pedersen, -Vladimir Vukicevic - -Snapshot 1.5.20 (2008-04-04 Carl Worth ) -=========================================================== -This is the tenth snapshot in cairo's unstable 1.5 series. It comes -just two days (and only one working day) after the 1.5.18 -snapshot. The quick snapshot is due to two embarrassing bugs (both -affecting cairo-xlib) that had been introduced in the 1.5.18 -snapshot. The fixes for these are described below along with a few -other fixes, (which hopefully aren't introducing new bugs this time). - -cairo-xlib ----------- -Revert fix from 1.5.18 to allow pattern expansion based on the filter -mode. This fix seemed so boring, (the use case it addresses is almost -never used in practice), that it didn't even get mentioned in the -1.5.18 release notes. However, the "fix" happened to break rendering -that is always used resulting in corrupt image rendering in mozilla, -evolution, and probably everything else that uses cairo. - -Fix to avoid BadMatch errors in cairo_surface_create_similar. These -were introduced, (inadvertently, of course), as part of the fix in -1.5.18 for creating similar surfaces without the Render -extension. Again, thanks to mozilla, (and Vladimir Vukicevic in -particular), for noticing our mistake. - -general -------- -Correctly handle an in-error surface in -cairo_surface_write_to_png. Previously this function would cause an -assertion failure if you gave it a finished surface. Now it cleanly -returns a CAIRO_STATUS_SURFACE_FINISHED result instead. - -Avoid potentially infinite wandering through memory inside -_cairo_hull_prev_valid. Thanks to Jonathan Watt for noticing this -problem: - - https://bugzilla.mozilla.org/show_bug.cgi?id=306649#c21 - -cairo-pdf ---------- -Fix generation of "soft" masks made by drawing to a similar surface -and then calling cairo_mask_surface() with it. - -cairo-svg ---------- -Fix for code that uses cairo_mask() on an intermediate surface which -is later passed to cairo_mask_surface(). - -Snapshot 1.5.18 (2008-04-05 Carl Worth ) -=========================================================== -This is the ninth snapshot in cairo's unstable 1.5 series. It comes -just 4 days after the 1.5.16 snapshot. We had hoped to not need -another snapshot before the final 1.6.0 release, but several critical -bugs were found and fixed in the last few days, so we thought it -important to let people test the fixes with this snapshot. See below -for details. - -documentation -------------- -The README now lists necessary dependencies. - -Various graphics state defaults are now documented, (source pattern is -opaque black, line width is 2.0, line join is miter, line cap is butt, -miter limit is 10.0, etc.). - -general -------- -Several cleanups have been made along many error-path returns, -(carefully propagating up the original error status values, cleaning -up memory leaks during error recovery, etc.). This is yet another in -Chris "ickle" Wilson's long series of error-handling cleanups during -the 1.5 series. - -Avoid undesired clipping when drawing scaled surface patterns with -bilinear filtering. - -cairo-pdf ---------- -Fix emission of 1-bit alpha masks in PDF output. - -Fix a bug that would cause glyphs to be misplaced along the Y axis: - - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%23474136 - - Originally, an issue about a crash, but later leading to the - misplaced glyphs issue being discovered. - -cairo-ps --------- -Fix misplaced glyphs in cairo's PostScript output. - - This issue occurs when consecutive glyphs are placed far - apart. This case is exercised by the new ft-show-glyphs-table test - case, which was originally inspired by the Debian bug #23474136 - mentioned above. - -Fix more misplaced glyphs in cairo's PostScript output: - - The issue here showed up under very particular circumstance, (when - converting a PDF file with a CFF font with CID Identity-H encoding - and using glyph 0, (defined by the CFF specification as .notdef) - as a space instead). More concretely, this problem appeared when - converting the UbuntuDesktop.pdf file mentioned in this bug - report: - - https://bugs.freedesktop.org/show_bug.cgi?id=15348#c3 - - As usual with arcane font-encoding-specific bugs like this, many - thanks to Adrian Johnson for his magical ability to dive into - specifications and emerge almost instantaneously with fixes. And - thanks to Sebastien Bacher for bringing the bug to our attention. - -cairo-xlib ----------- -Fix serious failure on X servers without the Render extension. - - Since the 1.5.14 snapshot (with support for PseudoColor visuals), - any application attempting to create a "similar" xlib surface would - fail on an X server without the Render extension. Thanks to - Frederic Crozat for pointing out that cairo's test suite was - entirely failing when run against Xvfb. - -Avoid crashing cairo-xlib applications for too-large glyphs - - Naively sending glyphs of any size to the X server will eventually - violate the X limit on maximum request sizes. We now properly - detect when a glyph would be too large and use existing fallbacks - to render the glyph rather than trying to send it to the X server. - -Enable the buggy_repeat workaround for Xorg servers < 1.4 - - We have determined that Xorg 1.3.0 (as packaged in Fedora 8 at - least) has a bug that can result in an X server crash when cairo - uses certain X Render repeat operations, (as exercised by cairo's - extend-reflect test). We avoid this crash by using fallbacks - whenever a repeating surface is needed for any Xorg server with a - version less than 1.4. This is slower, but should prevent the - crash. - - (Meanwhile, there appears to be a separate bug where some X - servers or specific X-server drivers will use random pixmap data - when asked to draw a repeating surface. The buggy_repeat - workaround would also avoid those problems, but we have not yet - characterized whether the new "version < 1.4" is a good - characterization of those problems or not.) - -cairo-quartz-font ------------------ -Implement cairo_font_extents for this backend. - -The cairo-quartz-font implementation added in the 1.5.14 snapshot was -entirely missing support for the cairo_font_extents function. Thanks to -Richard Hult for pointing out this obvious shortcoming, (and obvious -lack of coverage in our test suite): - - CGFont backend returns 0 font extents - https://bugs.freedesktop.org/show_bug.cgi?id=15319 - -Snapshot 1.5.16 (2008-04-01 Carl Worth ) -=========================================================== -This is the eighth snapshot in cairo's unstable 1.5 series. It comes -less than two weeks after the 1.5.14 snapshot and it really is a -legitimate snapshot, (in spite of sharing this date with that of many -bogus announcements). The major change in this snapshot is that the -cairo-quartz backend is now officially "supported", including new API -to construct a font face from a CGFontRef . Also several bug fixes -have been fixed in many backends. See below for details. - -general -------- -Cairo now depends on pixman 0.10.0 which was recently released. The -latest pixman release can always be found alongside cairo releases at: - - http://cairographics.org/releases - -Increase the precision of color stops for gradients. This fixes a -regression in gradient rendering that had been present since the -1.5.12 snapshot. - -paginated (all of ps, pdf, svg, and win32-printing) ---------------------------------------------------- -Fix assertion failure when some drawing elements are outside the page -boundaries, (this bug was noticed when using Inkscape to print a -drawing with landscape orientation to a portrait-oriented piece of -paper). - -cairo-ps --------- -Fix of bug causing incorrect glyph positioning. - -Fix handling of CAIRO_OPERATOR_SOURCE. - -cairo-pdf ---------- -More reduction of unnecessary digits of precision in PDF output. - -Fix handling of CAIRO_OPERATOR_SOURCE. - -cairo-svg ---------- -Fix bug in usage of libpng that was preventing cairo_mask from working -with the svg backend. - -Fix transformation of source pattern for cairo_stroke(). - -cairo-win32-printing --------------------- -Fix fallback resolution, (thanks again to inkscape users/developers -for helping us find this one). - -cairo-quartz ------------- -Mark the cairo-quartz backend as "supported" rather than -"experimental". This means the following: - - * The backend will now be built by default (if possible). - - * We are committing that the backend-specific API (as published in - cairo-quartz.h) are stable and will be supported in all future - cairo 1.x releases. - - * We are committing that the output quality of this backend - compares favorably with other cairo backends, (and that quality - is ensured by good results from the cairo test suite). - - * We recommend that distributions build and distribute this - backend when possible. - -Note that the cairo_quartz_image API (in cairo-quartz-image.h) is -still experimental, will not build by default, (pass ---enable-quartz-image to configure to build it), and may see API -changes before it is marked as "supported" in a future release. - -Put the CAIRO_FONT_TYPE_ATSUI name back into -cairo-deprecated.h. Without this, the cairo 1.5.14 snapshot broke all -builds for applications using the C++ cairomm bindings (and perhaps -others) which have the CAIRO_FONT_TYPE_ATSUI name in their header -files. This breakage happened even for applications not using -cairo-quartz at all. - - Note: Even though the CAIRO_FONT_TYPE_ATSUI name is provided to - avoid this build breakage, we still recommend that bindings and - applications move to the new, and more accurate, - CAIRO_FONT_TYPE_QUARTZ name. - -Replace the implementation of cairo-quartz-font to use CFFont instead -of ATSUI. The CGFont API is a better fit than ATSUI, and this new -implementation is also more correct than the old one as well. - -This also adds the following new API call: - - cairo_public cairo_font_face_t * - cairo_quartz_font_face_create_for_cgfont (CGFontRef font); - -The previous cairo_quartz_font_face_create_for_atsu_font_id function -continues to exist and is part of the supported API going -forward. (However, the old name of that same function, which was -cairo_atsui_font_face_create_for_atsu_font_id is officially -deprecated. Any source code using the old name should be updated to -use the new name.) - -Fix transformation of source pattern for cairo_stroke(). - -cairo-win32 ------------ -Avoid crash in create_similar is cairo_win32_surface_create fails. - -Snapshot 1.5.14 (2008-03-20 Carl Worth ) -=========================================================== -This is the seventh snapshot in cairo's unstable 1.5 series. It comes -3 weeks after the 1.5.12 snapshot. This snapshot includes support for -arbitrary X server visuals, (including PseudoColor), which was the -final remaining cairo-specific item on the cairo 1.6 roadmap. It also -includes a huge number of improvements to the cairo-quartz backend. So -this is effectively a cairo 1.6 release candidate. We expect very few -changes from now until 1.6 and only for specific bug fixes. - -API Change ----------- -Rename ATSUI font backend to Quartz font backend. This affects the -following usage: - - --enable-atsui -> --enable-quartz-font - CAIRO_HAS_ATSUI_FONT -> CAIRO_HAS_QUARTZ_FONT - CAIRO_FONT_TYPE_ATSUI -> CAIRO_FONT_TYPE_QUARTZ - - cairo_atsui_font_face_create_for_atsu_font_id -> - cairo_quartz_font_font_create_for_atsu_font_id - -This API change is justified by the cairo-quartz backend still be -marked as "experimental" rather than "supported", (though this is one -step toward making the change to "supported" before 1.6). Cairo will -still provide ABI compatibility with the old symbol name, however. - -paginated (all of ps, pdf, svg, and win32-printing) ---------------------------------------------------- -Optimize by not analyzing an image surface for transparency more than -once, (previously all images were analyzed twice). - -cairo-ps and cairo-pdf ----------------------- -Avoiding emitting a matrix into the stroke output when unnecessary, -(making output size more efficient). - -Reduce rounding error of path shapes by factoring large scale factors -out of the path matrix, (ensuring that a fixed-number of printed -digits for path coordinates contains as much information as possible). - -Reduce excess digits for text position coordinates. This makes the -output file size much smaller without making the result any less -correct. - -cairo-ps --------- -Eliminate bug causing extraneous text repetition on Linux PostScript -output in some cases. - - See: Mozilla Bug 419917 – Printed page contents are reflected - inside bordered tables (Linux-only) - - https://bugzilla.mozilla.org/show_bug.cgi?id=419917 - -Optimize output when EXTEND_PAD is used. - -cairo-pdf ---------- -Fix to not use fill-stroke operator with transparent fill, (else PDF -output doesn't match the cairo-defined correct result). See: - - https://bugs.launchpad.net/inkscape/+bug/202096 - -cairo-svg ---------- -Fix stroke of path with a non-solid-color source pattern: - - http://bugs.freedesktop.org/show_bug.cgi?id=14556 - -cairo-quartz ------------- -Fix text rendering with gradient or image source pattern. - -Handling antialiasing correctly for cairo_stroke(), cairo_clip(), and -cairo_show_text()/cairo_show_glyphs(). - -Correctly handle gradients with non-identity transformations: - - Fixes http://bugs.freedesktop.org/show_bug.cgi?id=14248 - -Add native implementation of REPEAT and REFLECT extend modes for -gradients. - -Fix implementation for the "unbounded" operators, (CAIRO_OPERATOR_OUT, -_IN, _DEST_IN, and _DEST_ATOP). - -Correctly handle endiannees in multi-architecture compiles on Mac OS -X. - -Avoid behavior which would cause Core Graphics to print warnings to -the console in some cases. - -cairo-win32 ------------ -Fix handling of miter limit. - -cairo-win32-printing --------------------- -Fix to not use a 1bpp temporary surface in some cases while printing, -(so grayscale data is preserved rather than just becoming black and -white). - -cairo-xlib ----------- -Add support for rendering to arbitrary TrueColor X server -visuals. This fixes at least the following bugs: - - cairo doesn't support 8-bit truecolor visuals - https://bugs.freedesktop.org/show_bug.cgi?id=7735 - - cairo doesn't support 655 xlib format - https://bugs.freedesktop.org/show_bug.cgi?id=9719 - -Add support for rendering to 8-bit PseudoColor X server visuals. This -fixes the following bug: - - Cairo doesn't support 8-bit pseudocolor visuals - https://bugs.freedesktop.org/show_bug.cgi?id=4945 - -Snapshot 1.5.12 (2008-02-28 Carl Worth ) -=========================================================== -This is the sixth snapshot in cairo's unstable 1.5 series. It comes 1 -week after the 1.5.10 snapshot. This snapshot includes the -long-awaited change from 16.16 to 24.8 fixed-point values, (see below -for why you should care). It also includes several backend-specific -bug fixes. - -24.8 fixed-point format ------------------------ -Cairo has always converted path coordinates to a fixed-point -representation very early in its processing. Historically, this has -been a 32-bit representation with 16 bits of integer for the -device-pixel grid and 16 bits of sub-pixel positioning. The choice of -16 bits for the integer coordinate space was based on the 16-bit limit -for X Window drawables. - -This 16-bit limit has proven problematic for many applications. It's -an especially vexing problem when targeting non-X backends that don't -have any 16-bit restriction. But even when targeting cairo-xlib, it's -often desirable to draw a large shape, (say a background rectangle), -that extends beyond the surface bounds and expect it to fill the -surface completely, (rather than overflowing and triggering random -behavior). - -Meanwhile, nobody has ever really needed 16 bits of sub-pixel -precision. - -With this snapshot, the fixed-point system is still in place and is -still using a 32-bit representation, (future versions of cairo might -move entirely to floating-point when targeting PDF output for -example). But the representation now provides 24 bits of pixel -addressing and only 8 bits of sub-pixel positioning. This should give -a much less stifling space to many applications. - -However, the underlying pixman library still has 16-bit limitations in -many places, (it has its roots in the X server as well). Until those -are also fixed, applications targeting cairo image surfaces, or -hitting software fallbacks when targeting other surfaces will still -encounter problems with device-space values needing more than 16 -integer bits. - -generic fixes -------------- -Add a few tests to the test suite to increase coverage. - -Cleanup a few error-handling paths, (propagate error correctly). - -cairo-ft --------- -Fix handling of font sizes smaller than 1 device pixel. - -cairo-pdf ---------- -Fix to properly save/restore clip when analyzing meta-surface -patterns, (fixing a couple of test-suite failures). - -Implement native support for CAIRO_OPERATOR_SOURCE when the source -pattern is opaque. - -Emit rectangles as PDF rectangles ("re" operator) rather than as -general paths. - -cairo-ps --------- -Fix to work properly with the 16.16->24.8 change. - -cairo-svg ---------- -Fix CAIRO_EXTEND_REFLECT by using an image fallback, (there's no -direct SVG support for reflected patterns). - -Fix the use of alpha-only masks, (such as CAIRO_FORMAT_A8). - -cairo-quartz ------------- -Add new API for efficiently using image data as a source: - - cairo_surface_t * - cairo_quartz_image_surface_create (cairo_surface_t *image_surface); - - cairo_surface_t * - cairo_quartz_image_surface_get_image (cairo_surface_t *surface); - -For full documentation, see: - - http://cairographics.org/manual/cairo-Quartz-Surfaces.html#cairo-quartz-image-surface-create - -Several fixes for cairo_mask(). - -cairo-atsui ------------ -Change default from from Monaco to Helvetica to be more consistent -with other font backends. - -Snapshot 1.5.10 (2008-02-20 Carl Worth ) -=========================================================== -This is the fifth snapshot in cairo's unstable 1.5 series. It comes 3 -weeks after the 1.5.8 snapshot. This snapshot adds one new API -function, (cairo_has_current_point), and the usual mix of -improvements, (more efficient PostScript/PDF output, optimized -stroking), and fixes (more robust error-handling, etc.). See below for -details. - -New API -------- -Add a new function to query if there is a current point: - - cairo_bool_t - cairo_has_current_point (cairo_t *cr); - -There is no current point immediately after cairo_create(), nor after -cairo_new_path() or cairo_new_sub_path(). There is a current point -after any of the path-creation functions, (cairo_move_to, -cairo_line_to, cairo_curve_to, etc.). - -With this new function, we also revert the change of the return type -of cairo_get_current_point from cairo 1.5.8, (it's now a void function -again). - -Optimizations -------------- -Optimize stroking code to avoid repeated calculation of redundant -values, (particularly significant for very large, offscreen paths). - -General fixes -------------- -Patch a few more potential buffer overruns, (due to integer -overflow). - -Many fixes and improvements to cairo's error-handling, (ensure that -correct error values are returned, clean up memory leaks on -error-handling paths, etc.). - -Fix a potential infinite loop when stroking a spline with a pen that -has been transformed to a line segment. - -Remove treating NULL as a synonym for a valid cairo_font_options_t* -with default values, (a change that had been introduced as of cairo -1.5.8). - -Remove the altered handling of tolerance and fallback-resolution that -had been introduced as of cairo 1.5.4. - -cairo-xlib ----------- -Pass the original Drawable, (as opposed to the root window), to -XCreatePixmap when creating a similar surface. This gives the X server -more information so that it can be clever and efficient. - -cairo-pdf ---------- -Fix the rendering of repeating and reflecting patterns. - -Ensure miter limit is always >= 1, (smaller limits are not meaningful, -but they can cause some PDF viewers to fail to display pages). - -Generate more efficient output when the same path is used for both -fill and stroke. - -cairo-ps --------- -Start sharing much of the cairo-pdf code rather than implementing very -similar code in cairo-ps. - -Implement native support for repeating and reflecting linear -gradients. - -Implement reflected surface patterns. - -Ensure miter limit is always >= 1, (smaller limits are not meaningful, -but they can cause some PostScript viewers to crash). - -Generate PostScript that will perform more efficiently and use less -memory on printers, (use currentfile instead of a giant string array -for image data, and avoid using PostScript patterns for paint() and -fill() when possible). - -cairo-svg ---------- -Avoid unnecessary rasterization when copying a "similar" surface to -another svg surface, (allow the SOURCE operator to be implemented with -all-vector operations if there are no underlying objects). - -cairo-atsui ------------ -Eliminate infinite loop when attempting to render an empty string. - -Snapshot 1.5.8 (2008-01-30 Carl Worth ) -========================================================== -This is the fourth snapshot in cairo's unstable 1.5 series. It comes 2 -weeks after the 1.5.6 snapshot. It adds a few new API functions. Most -notably all callers of cairo_image_surface_create_for_data should now -be calling cairo_format_stride_for_width to compute a legal stride -value. See below for more details. - -New API in cairo 1.5.8 ----------------------- -We've added a new function that should be called to compute a legal -stride value before allocating data to be used with -cairo_image_surface_create_for_data: - - int - cairo_format_stride_for_width (cairo_format_t format, - int width); - -We've also added a new cairo_path_extents function that can be used to -compute a bounding box for geometry such as a single line segment, -(contrast with cairo_path_extents and cairo_stroke_extents): - - void - cairo_path_extents (cairo_t *cr, - double *x1, double *y1, - double *x2, double *y2); - -And finally, we've added a function to allow for querying the -XRenderPictFormat of a cairo-xlib surface: - - XRenderPictFormat * - cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface); - -API changes ------------ -Fix return types of cairo_surface_show_page and -cairo_surface_copy_page. This is an API change to functions that are -new in the 1.5 series, so not an API break compared to any stable -cairo release, (1.0.x, 1.2.x, 1.4.x). - -Change the return type of cairo_get_current_point() from void to -cairo_status_t. This allows the caller to receive a -CAIRO_STATUS_NO_CURRENT_POINT value to distinguish the a current point -at the origin from no current point existing. - -Performance improvement ------------------------ -Improve performance of clipping by using an optimized code path -internally, (with the ADD operator instead of IN). - -General bug fixes ------------------ -Fix various cairo_*_extents functions to initialize the return-value -variables even in the case of a cairo_t in error. - -Treat NULL as a legitimate value for cairo_font_options_t*. [NOTE: -On discussion afterwards, we decided against this change so it has -been removed as of cairo 1.5.10.] - -Fix rendering with CAIRO_ANTIALIAS_NONE to be more predictable, (that -is, to avoid seams appearing when geometry and imagery share an -identical edge). Portions of this fix are in the pixman library and -will appear in a future release of that library. - -Avoid triggering an error for a font size of 0. - -Miscellaneous changes ---------------------- -Require pixman >= 0.9.6. - -There has been a tremendous amount improvement to cairo's -documentation. We're delighted that 100% of the public API has at -least some documentation in the API reference manual. Many thanks to -Behdad Esfahbod and Nis Martensen for leading this effort. - -cairo-pdf and cairo-ps ----------------------- -Eliminate failure when a Type 1 font is embedded with an explicit -glyph 0. - -cairo-pdf ---------- -Implement a more correct and more efficient approach for patterns with -an extend mode of CAIRO_EXTEND_REFLECT. - -cairo-ps --------- -Fix image masks to properly pack and pad mask bits. - -cairo-quartz ------------- -Take care to only use DrawTiledImage for integer-aligned images, (and -use slower paths to get the correct result in other cases). - -cairo-win32 ------------ -Fix for older versions of mingw. - -Improve the handling of the clipping with the win32 and win32-printing -surfaces. - -Fix rendering of non black/white text. - -Snapshot 1.5.6 (2008-01-15 Carl Worth ) -========================================================== -This is the third snapshot in cairo's unstable 1.5 series. It comes -about 6 weeks after the 1.5.4 snapshot. The only API addition compared -to 1.5.4 is very minor, (a new value CAIRO_STATUS_TEMP_FILE_ERROR). -The remainder of the changes are the usual accumulation of bug fixes -and improvements. See below for details. - -General bug fixes ------------------ -Fix handling of fonts that contain a mixture of outline and bitmapped -glyphs. There was a change in this handling in 1.5.4 that improved -some cases and also regressed other cases. Now, all cases should be -handled quite well. - -Fix alignment issues that were causing SIGBUS failures on SPARC. - -Fix a regression (which first appeared in 1.5.2) where stroking under -a large scale would sometimes incorrectly replace a miter join with a -bevel join. (Thanks to Keith Packard.) - -Fix reporting of zero-sized extents to be {0,0} rather than -{INT_MAX,INT_MIN}. This avoids several integer overflow and -allocations of massive regions in some cases. - -Fix failures of gradients with no stops, (quartz, ps, and pdf). - -Fix handling of Type 1 fonts on Windows platforms. - -Fix handling of Type 1 fonts with no specific family name in the font -itself, (generate a CairoFont-x-y name). - -Handle NULL string values in cairo_show_text, cairo_show_glyphs, and -friends. - -Many robustness improvements along error-handling paths, (thanks as -always, to Chris "ickle" Wilson). - -Various other minor fixes. - -Paginated backends (PDF/PostScript/win32-printing) --------------------------------------------------- -Avoid unnecessary rasterization when using a paginated surface as a -source, (such as drawing from one pdf surface to another). - -Fix replaying of paginated surface with more than one level of push/pop -group. - -cairo-xlib ----------- -Fix xlib backend to not consider recent X server release as having a -buggy repeat implementation in the Render extension. - -cairo-pdf ---------- -Fix PDF output to avoid triggering very slow rendering in PDF viewers, -(avoid starting and stopping the content stream for each pattern -emission). - -Support CAIRO_OPERATOR_SOURCE in cases where there is nothing below -the object being drawn. - -Fix to avoid seams appearing between multiple fallback regions. - -cairo-ps (PostScript) ---------------------- -Use correct bounding box in Type 3 fonts. - -Fix several bugs in cairo's PostScript output. These include making -the PostScript output more compatible with recent versions of -ghostscript that are more strict about Type 3 fonts, for -example. - -Fix for win32 to not attempt to create temporary files in the root -directory, (where the user may not have write permission). - -Avoid generating Level 3 PostScript if Level 2 is sufficient. Also, -add code in output documents to alert the user if Level 3 PostScript -is handed to a device that cannot handle PostScript beyond Level -2. - -cairo-directfb --------------- -Various performance optimizations. - -Fixed support for small surfaces (less than 8x8). - -Provide support for environment variables CAIRO_DIRECTFB_NO_ACCEL to -disable acceleration and CAIRO_DIRECTFB_ARGB_FONT to enable ARGB fonts -instead of A8. - -cairo-os2 ---------- -Allow OS/2 APIs instead of C library allocation functions. - -Snapshot 1.5.4 (2007-12-05 Carl Worth ) -========================================================== -This is the second snapshot in cairo's unstable 1.5 series. It comes -just over 1 month after the 1.5.2 snapshot. There are no API changes -or additions in 1.5.4 compared to 1.5.2, but there are several bug -fixes, and some optimizations. Most of these apply to particular -backends. See below for details. - -General improvements --------------------- -Use less memory for spline approximation calculations. - -Change how the tolerance value is interpreted with regard to -fallback-resolution. [Note: On further discussion, we decided against -this change for now. It is removed as of cairo 1.5.10.] - -Fix precision of floating-point values in vector-output backends to -avoid rounding errors with very small numbers. - -Xlib improvements ------------------ -Fix bug in glyph rendering with xlib, (due to everything being clipped -out). This was a regression in the 1.5.2 snapshot that was visible in -the GIMP, for example. See: - - cairo 1.5.2 causes font problems in GIMP 2.4 status bar and evolution 2.12.1 - https://bugs.freedesktop.org/show_bug.cgi?id=13084 - -PostScript improvements ------------------------ -Fix bug leading to invalid PostScript files when rendering -text, (need "0 0 xyshow" instead of "0 xyshow"). - -Fix many issues with Type 3 fonts, including making the resulting text -extractable. - -Quartz improvements -------------------- -Fix font metrics height value for ATSUI, (helps webkit on GTK+ OS X -layout nicely). - -Fix gradients. - -Fix EXTEND_NONE mode for patterns. - -Fix cairo_quartz_surface_create to properly clear the new surface -in cairo_quartz_surface_create. - -Fix to correctly handle 0x0 sized surfaces. - -Optimize drawing of EXTEND_REPEAT patterns for OS X 10.5. - -Snapshot 1.5.2 (2007-10-30 Carl Worth ) -========================================================== -This is the first snapshot in cairo's unstable 1.5 series. It comes 4 -months after the 1.4.10 release. This snapshot includes significant -improvements to PDF and PostScript output, which is one of the things -in which we're most interested in getting feedback. There are a couple -of minor API additions, and several optimizations, (primarily in the -"print/vector" backends). And there are dozens of bug fixes and -robustness improvements. - -New dependency on external pixman library ------------------------------------------ -A significant change in this snapshot compared to all previous cairo -releases is that cairo now depends on an external "pixman" library for -its software rendering. Previously this same code was compiled -internally as part of cairo, but now the code is separate so that both -cairo and the X server can now share common code, (thanks very much to -Søren Sandmann for his work on separating pixman and maintaining it). - -So users will need to acquire and build pixman before being able to -build cairo. The current release is 0.9.6 and can be obtained from -here: - - http://cairographics.org/releases/pixman-0.9.6.tar.gz - - which can be verified with: - - http://cairographics.org/releases/pixman-0.9.6.tar.gz.sha1 - 66f01a682c64403a3d7a855ba5aa609ed93bcb9e pixman-0.9.6.tar.gz - - http://cairographics.org/releases/pixman-0.9.6.tar.gz.sha1.asc - (signed by Carl Worth) - -Major PDF/PostScript improvements ---------------------------------- -Adrian Johnson has done some long-awaited work to make cairo's PDF and -PostScript output more interesting than ever before. First, many -operations that previously triggered image fallbacks will now be -rendered as native vectors. These operations include: - - PDF: cairo_push_group, cairo_surface_create_similar, - cairo_mask, A8/A1 surface sources, repeating/reflecting linear - gradients. - - PostScript: cairo_push_group, cairo_surface_create_similar, - gradients, bilevel alpha masks, (for example, all values either 0 or - 255 for an A8 mask). - -Not only that, but when an image fallback is required, it will now be -limited to only the necessary region. For example, a tiny translucent -image overlaying a small portion of text would previously caused an -entire PostScript page to be rendered as a giant image. Now, the -majority of that page will be nice text, and there will only be a tiny -image in the output. - -Additionally, the PostScript output now carefully encodes text so that -if it is subsequently converted to PDF, the text will be -selectable. - -This is very exciting progress, and we're hoping to hear from users -during the 1.5 series about how things have improved, (for example, -inkscape users doing cairo-based PDF export: please let us know how -things look). And feel free to pass your thanks along to Adrian for his excellent work. - -NOTE: This much improved PDF output makes more sophisticated use of -functionality in the PDF specification. This means that cairo's output -will sometimes expose bugs in some free software PDF viewers, (evince, -poppler, and xpdf, for example), that are not yet ready for such PDF -files. We're working with the poppler maintainers to get these bugs -fixed as quickly as possible. In the meantime, please double-check -with other PDF viewers if cairo-generated PDF files are not being -rendered correctly. It may be due to a bug in the viewer rather than -in the PDF file that cairo has created. - -Robustness improvements ------------------------ -Chris Wilson has made the largest contribution by far to cairo 1.5.2, -(in number of commits). His more than 150 commits include a huge -number of fixes to increase cairo's robustness. These fixes make cairo -more robust against invalid and degenerate input, (NaN, empty path, -etc.), against size-0 malloc calls, against memory leaks on -error-recovery paths, and against other failures during error -handling. He also implemented atomic operations to cairo, and used -them to fix cairo's previously non-thread-safe reference counting, -again improving robustness. - -Chris has put a tremendous amount of time and effort into writing -analysis tools for this work, and in running those tools and fixing -the problems they report. We're very grateful for this work, and hope -that all cairo users appreciate the more robust implementation that -results from it. - -This work is largely thankless, so it might make sense to notice -sometime that cairo has been running quite smoothly for you, and when -you do, send a quick "thank you" off to Chris Wilson, since it -is all definitely running smoother thanks to his work. - -New API -------- -There are no major additions to cairo's core API. The only new, -generic functions are: - - void - cairo_surface_copy_page (cairo_surface_t *surface); - - void - cairo_surface_show_page (cairo_surface_t *surface); - -which can now be used much more conveniently than the existing -cairo_copy_page and cairo_show_page functions in some -situations. These functions act identically, but require only a -cairo_surface_t* and not a cairo_t*. - -All other API additions are specific to particular backends. - -New cairo-win32 API (new font face function and "win32 printing" surface) -------------------------------------------------------------------------- -There is a new function for creating a win32 font face for both a -logfontw and an hfont together. This complements the existing -functions for creating a font face from one or the other: - - cairo_font_face_t * - cairo_win32_font_face_create_for_logfontw_hfont (LOGFONTW *logfont, - HFONT font); - -There is also a new "win32 printing" surface: - - cairo_surface_t * - cairo_win32_printing_surface_create (HDC hdc); - -This interface looks identical to the original -cairo_win32_surface_create, (both accept and HDC), but the behavior of -this new surface is very different. It should only be called with a -printing DC, and will result in all drawing commands being stored into -a meta-surface and emitted after each page is complete, with analysis -to do as minimal image-based fallbacks as necessary. The behavior and -implementation shares much with the PDF and PostScript backends. - -New cairo-ps API (EPS and PostScript level control) ---------------------------------------------------- -An often requested feature has been the ability to generate -Encapsulated PostScript (EPS) with cairo. We have that now with the -following very simple API. Just do cairo_ps_surface_create as usual -then call this function with a true value: - - void - cairo_ps_surface_set_eps (cairo_surface_t *surface, - cairo_bool_t eps); - -[NOTE: As always with snapshots, it's possible---though not very -likely---that the API could still be modified before a final -release. For example, this is the first public cairo function that -accepts a Boolean parameter. I'm generally opposed to Boolean -parameters, but this is probably the one case where I'm willing to -accept one, (namely a "set" function that accepts a single Boolean).] - -Also, it is now possible to control what PostScript level to target, -(either level 2 or level 3), with the following new API: - - typedef enum _cairo_ps_level { - CAIRO_PS_LEVEL_2, - CAIRO_PS_LEVEL_3 - } cairo_ps_level_t; - - void - cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, - cairo_ps_level_t level); - - void - cairo_ps_get_levels (cairo_ps_level_t const **levels, - int *num_levels); - - const char * - cairo_ps_level_to_string (cairo_ps_level_t level); - -Improvement for cairo-quartz ----------------------------- -Brian Ewins had contributed several improvements to cairo-quartz. These -include an implementation of EXTEND_NONE for linear and radial -gradients, (so this extend mode will no longer trigger image fallbacks -for these gradients), as well as native surface-mask clipping, (only -on OS X 10.4+ where the CGContextClipToMask function is available). - -He also fixed a semantic mismatch between cairo and quartz for dashing -with an odd number of entries in the dash array. - -We're grateful for Brian since not many quartz-specific improvements -to cairo would be happening without him. - -Optimizations -------------- -Optimize SVG output for when the same path is both filled and stroked, -and avoid unnecessary identity matrix in SVG output. (Emmanuel Pacaud). - -Optimize PS output to take less space (Ken Herron). - -Make PS output more compliant with DSC recommendations (avoid initclip -and copy_page) (Adrian Johnson). - -Make PDF output more compact (Adrian Johnson). - -Release glyph surfaces after uploading them to the X server, (should -save some memory for many xlib-using cairo application). (Behdad -Esfahbod). - -Optimize cairo-win32 to use fewer GDI objects (Vladimir Vukicevic). - -win32-printing: Avoid falling back to images when alpha == 255 -everywhere. (Adrian Johnson). - -win32-printing: Avoid falling back for cairo_push_group and -cairo_surface_create_similar. (Adrian Johnson) - -Bug fixes ---------- -Avoid potential integer overflows when allocating large buffers -(Vladimir Vukicevic). - -Preparations to allow the 16.16 fixed-point format to change to -24.8 (Vladimir Vukicevic). - -Fix bugs for unsupported X server visuals (rgb565, rgb555, bgr888, and -abgr8888). (Carl Worth and Vladimir Vukicevic) - -Fix bugs in PDF gradients (Adrian Johnson). - -Fix cairo-xlib to build without requiring Xrender header -files (Behdad Esfahbod). - -Make cairo more resilient in the case of glyphs not being available in -the current font. (Behdad Esfahbod) - -Prevent crashes when both atsui and ft font backends are compiled in -(Brian Ewins). - -Make font subsetting code more robust against fonts that don't include -optional tables (Adrian Johnson). - -Fix CFF subsetting bug, (which manifested by generating PDF files that -Apple's Preview viewer could not read) (Adrian Johnson). - -Fixed error handling for quartz and ATSUI backends (Brian Ewins). - -Avoid rounding problems by pre-transforming to avoid integer-only -restrictions on transformation in GDI (Adrian Johnson). - -Fixed an obscure bug (#7245) computing extents for some stroked -paths (Carl Worth). - -Fix crashes due to extreme transformation of the pen, (seems to show -up in many .swf files for some reason) (Carl Worth). - -Release 1.4.10 (2007-06-27 Carl Worth ) -========================================================== -This is the fifth update in cairo's stable 1.4 series. It comes -roughly three weeks after the 1.4.8 release. The most significant -change in this release is a fix to avoid an X error in certain cases, -(that were causing OpenOffice.org to crash in Fedora). There is also a -semantic change to include child window contents when using an xlib -surface as a source, an optimization when drawing many rectangles, and -several minor fixes. - -Eliminate X errors that were killing OO.o (Chris Wilson) --------------------------------------------------------- -Cairo is fixed to avoid the X errors propagated when cleaning up -Render Pictures after the application had already destroyed the -Drawable they reference. (It would be nice if the X server wouldn't -complain that some cleanup work is already done, but there you have -it.) This fixes the bug causing OpenOffice.org to crash as described -here: - - XError on right click menus in OOo. - https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=243811 - -Use IncludeInferiors when using xlib surface as a source (Ryan Lortie) ----------------------------------------------------------------------- -When an xlib surface is used as the source of a draw operation the -contents of child windows are now included in the source data. The -semantics of drawing to xlib surfaces are unchanged (ie: draws are -still clipped by child windows overlapping the destination window). - -Optimize drawing of many rectangles (Vladimir Vukicevic) --------------------------------------------------------- -Avoid O(N*N) loop when filling many axis-aligned rectangles, (either -many rectangles as separate sub-paths or due to dashing). - -Miscellaneous fixes -------------------- -Fix cairo-perf on Solaris by linking to librt. (Behdad Esfahbod) - -Fix make check for systems that require executable files to have a -particular extension. (Behdad Esfahbod) - -Eliminate some warnings in cairo-quartz. (Brian Ewins) - -Fix build-breaking typo for cairo-directfb. (Chris Wilson) - -Release 1.4.8 (2007-06-07 Carl Worth ) -========================================================= -This is the fourth update in cairo's stable 1.4 series. It comes just -over five weeks after the 1.4.6 release. This release includes a -thread-safe surface-cache for solid patterns which significantly -improves text rendering with the xlib backend. Also, dozens of error -paths in cairo have been fixed thanks to extensive fault-injection -testing by Chris Wilson. - -Surface cache for solid patterns --------------------------------- -Originally written by Jorn Baayen, the introduction of a small cache -for surfaces created for solid patterns improves performance -dramatically. For example, this reduces the volume of X requests -during text rendering to the same level as Xft. - -This cache first made its appearance in a 1.3.x snapshot, but was -removed before appearing in any previous major release due to -complications with multi-threaded programs. For example, programs like -evince that would carefully restrict usage of cairo-xlib to a single -thread were unpleasantly surprised to find that using cairo-image in a -separate thread could trigger X requests. - -Behdad Esfahbod designed a fix which was implemented by Chris -Wilson. Now, the necessary X requests are queued up until the next -time the application directly operates on an xlib surface. - -Improved error handling paths ------------------------------- -Chris Wilson continued the excellent work he started in cairo 1.4.4 to -make cairo much more robust against out-of-memory and other errors. He -applied his memory allocation fault injection cairo's main test suite, -(previously he had applied it to cairo's performance suite). - -Chris's testing found dozens of bugs which he fixed. Many of these -bugs had perhaps never been hit by any users. But at least one was -hit by the gnome-about program which resulted in dozens of duplicated -bug reports against that program: - - http://bugzilla.gnome.org/show_bug.cgi?id=431990 - -We were very pleasantly surprised to see this bug get fixed as a -side-effect of Chris's work. Well done, Chris! - -Other fixes ------------ -Cleanup of mutex declarations (Behdad Esfahbod) - -Remove unnecessary clip region from SVG output (Emmanuel Pacaud) - -Remove Xsun from the buggy_repeat blacklist (Elaine Xiong) - -ATSUI: Fix glyph measurement: faster and more correct (Brian Ewins) - -Quartz: fixed 'extend' behaviour for patterns, improved pattern performance, -and a few smaller correctness fixes. (Brian Ewins, Vladimir Vukicevic) - -Release 1.4.6 (2007-05-01 Carl Worth ) -========================================================= -This is the third update in cairo's stable 1.4 series. It comes a -little less than three weeks since the 1.4.4 release. This release -fixes the broken mutex initialization that made cairo 1.4.4 unusable -on win32, OS/2, and BeOS systems. This release also adds significant -improvements to cairo's PDF backend, (native gradients!), and a couple -of performance optimizations, (one of which is very significant for -users of the xlib backend). See below for more details. - -Repaired mutex initialization ------------------------------ -We apologize that cairo 1.4.4 did little more than crash on many -platforms which are less-frequently used by the most regular cairo -maintainers, (win32, OS/2, and BeOS). The mutex initialization -problems that caused those crashes should be fixed now. And to avoid -similar problems in the future, we've now started posting pre-release -snapshots to get better testing, (subscribe to cairo@cairographics.org -if you're interested in getting notified of those and testing them). - -PDF Improvements ----------------- -Thanks to Adrian Johnson, (cairo PDF hacker extraordinaire), we have -several improvements to cairo's PDF backend to announce: - -Native gradients: - - As of cairo 1.4.6, cairo will now generate native PDF gradients in - many cases, (previously, the presence of a gradient on any page - would force rasterized output for that page). Currently, only - gradients with extend types of PAD (the default) or NONE will - generate native PDF gradients---others will still trigger - rasterization, (but look for support for other extend modes in a - future release). Many thanks to Miklós Erdélyi as well, who did the - initial work for this support. - -Better compatibility with PDF viewers: - - The PDF output from cairo should now be displayed correctly by a - wider range of PDF viewers. Adrian tested cairo's PDF output against - many PDF viewers, identified a common bug in many of those viewers - (ignoring the CTM matrix in some cases), and modified cairo's output - to avoid triggering that bugs (pre-transforming coordinates and - using an identity matrix). - -Better OpenType/CFF subsetting: - - Cairo will now embed CFF and TrueType fonts as CID fonts. - -Performance optimizations -------------------------- -Faster cairo_paint_with_alpha: - - The cairo_paint_with_alpha call is used to apply a uniform alpha - mask to a pattern. For example, it can be used to gradually fade an - image out or in. Jeff Muizelaar fixed some missing/broken - optimizations within the implementation of this function resulting - in cairo_paint_with_alpha being up to 4 times faster when using - cairo's image backend. - -Optimize rendering of "off-screen" geometry: - - Something that applications often do is to ask cairo to render - things that are either partially or wholly outside the current clip - region. Since 1.4.0 the image backend has been fixed to not waste - too much time in this case. But other backends have still been - suffering. - - In particular, the xlib backend has often performed quite badly in - this situation. This is due to a bug in the implementation of - trapezoid rasterization in many X servers. - - Now, in cairo 1.4.6 there is a higher-level fix for this - situation. Cairo now eliminates or clips trapezoids that are wholly - or partially outside the clip region before handing the trapezoids - to the backend. This means that the X server's performance bug is - avoided in almost all cases. - - The net result is that doing an extreme zoom-in of vector-based - objects drawn with cairo might have previously brought the X server - to its knees as it allocated buffers large enough to fit all of the - geometry, (whether visible or not). But now the memory usage should - be bounded and performance should be dramatically better. - -Miscellaneous -------------- -Behdad contributed an impressively long series of changes that -organizes cairo's internals in several ways that will be very -beneficial to cairo developers. Thanks, Behdad! - -Behdad has also provided a utility for generating malloc statistics, -(which was used during the great malloc purges of 1.4.2 and -1.4.4). This utility isn't specific to cairo so may be of benefit to -others. It is found in cairo/util/malloc-stats.c and here are Behdad's -notes on using it: - - To build, do: - - make malloc-stats.so - - inside util/, and to use, run: - - LD_PRELOAD=malloc-stats.so some-program - - For binaries managed by libtool, eg, cairo-perf, do: - - ../libtool --mode=execute /bin/true ./cairo-perf - LD_PRELOAD="../util/malloc-stats.so" .libs/lt-cairo-perf - -Finally, the cairo-perf-diff-files utility was enhanced to allow for -generating performance reports from several runs of the same backend -while some system variables were changed. For example, this is now -being used to allow cairo-perf to measure the performance of various -different acceleration architectures and configuration options of the -X.org X server. - -Release 1.4.4 (2007-04-13 Carl Worth ) -========================================================= -This is the second update release in cairo's stable 1.4 series. It -comes just less than a month after 1.4.2. The changes since 1.4.2 -consist primarily of bug fixes, but also include at least one -optimization. See below for details. - -Of all the work that went into the 1.4.4 release - -There have been lots of individuals doing lots of great work on cairo, -but two efforts during the 1.4.4 series deserve particular mention: - -Internal cleanup of error handling, (Chris Wilson) --------------------------------------------------- -Chris contributed a tremendous series of patches (74 patches!) to -improve cairo's handling of out-of-memory and other errors. He began -by adding gcc's warn_unused_attribute to as many functions as -possible, and then launched into the ambitious efforts of adding -correct code to quiet the dozens of resulting warnings. - -Chris also wrote a custom valgrind skin to systematically inject -malloc failures into cairo, and did all the work necessary to verify -that cairo's performance test suite runs to completion without -crashing. - -The end result is a much more robust implementation. Previously, many -error conditions would have gone unnoticed and would have led to -assertion failures, segmentation faults, or other harder-to-diagnose -problems. Now, more than ever, cairo should cleanly let the user know -of problems through cairo_status and other similar status -functions. Well done, Chris! - -More malloc reduction, (Mathias Hasselmann) -------------------------------------------- -After 1.4.0, Behdad launched an effort to chase down excessive calls -to malloc within the implementation of cairo. He fixed a lot of -malloc-happy objects for 1.4.2, but one of the worst offenders, -(pixman regions), was left around. Mathias contributed an excellent -series of 15 patches to finish off this effort. - -The end result is a cairo that calls malloc much less often than it -did before. Compared to 1.4.2, 55% of the calls to malloc have been -eliminate, (and 60% have been eliminated compared to 1.4.0). Well -done, Mathias! - -Other improvements since 1.4.2 ------------------------------- -• Centralize mutex declarations (will reduce future build breaks), - (Mathias Hasselmann) - -• Reduce malloc by caching recently freed pattern objects (Chris - Wilson) - -• Fix some broken composite operations (David Reveman) - https://bugs.freedesktop.org/show_bug.cgi?id=5777 - -Backend-specific fixes ----------------------- -PDF: - • Use TJ operator for more compact representation of glyphs (Adrian - Johnson) - - • Fix glyph positioning bug when glyphs are not horizontal - http://lists.freedesktop.org/archives/cairo/2007-April/010337.html - -win32: - • Fix crash when rendering with bitmap fonts (Carl Worth) - https://bugzilla.mozilla.org/show_bug.cgi?id=376498 - -xlib: - • Turn metrics-hinting on by default (Behdad Esfahbod) - - • Fix edge-effect problem with transformed images drawn to xlib - (Behdad Esfahbod) - https://bugs.freedesktop.org/show_bug.cgi?id=10508 - - • Avoid dereferencing a NULL screen. (Chris Wilson) - https://bugs.freedesktop.org/show_bug.cgi?id=10517 - -Quartz/ATSUI: - • Fix scaling of glyph surfaces - (Brian Ewins) - https://bugs.freedesktop.org/show_bug.cgi?id=9568 - - • Fix compilation failure when both xlib and quartz enabled - (Brian Ewins) - - • Fix rounding bug leading to incorrectly positioned glyphs - (Robert O'Callahan) - https://bugs.freedesktop.org/show_bug.cgi?id=10531 - -Release 1.4.2 (2007-03-19 Carl Worth ) -========================================================= -This is the first update release in cairo's stable 1.4 series. It -comes just less than 2 weeks after 1.4.0. We hadn't anticipated an -update this early, but we've managed to collect some important fixes -that we wanted to get out to cairo users as soon as possible, (6 fixes -for crashes, 1 case where graphical elements would not be drawn at -all, a handful of backend-specific bugs, and several important build -fixes). - -There's almost nothing but bug fixes in this release, (see below one -optimization that Behdad did sneak in), so we recommend that everyone -upgrade to this release when possible. - -Thanks to the many people that worked to fix these bugs, and those -that did the work to report them and to test the fixes, (wherever -possible both names are credited below). - -Critical fixes --------------- -• Fix a crash due to a LOCK vs. UNLOCK typo (M. Drochner fixing Carl - Worth's embarrassing typo). - - http://bugs.freedesktop.org/show_bug.cgi?id=10235 - -• Fix potential buffer overflow, which on some systems with a checking - variant of snprintf would lead to a crash (Adrian Johnson, Stanislav - Brabec, and sangu). - - https://bugs.freedesktop.org/show_bug.cgi?id=10267 - https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=232576 - -• Fix a crash in cairo_stroke_extents or cairo_in_stroke when line - width is 0.0. (Carl Worth and Sebastien Bacher) - - https://bugs.freedesktop.org/show_bug.cgi?id=10231 - -• Fix a crash on certain combinations of X server/video drivers (Carl - Worth and Tomas Carnecky). - - https://bugs.freedesktop.org/show_bug.cgi?id=10250 - -• Fix a crash due to mishandling of invalid user input (Carl Worth and - Alexander Darovsky). - - https://bugs.freedesktop.org/show_bug.cgi?id=9844 - -• xlib: Cleanup server-side glyph caches on XCloseDisplay. This - eliminated a crash detected by the perf suite, (and that - applications could have run into as well). (Chris Wilson) - -Other bug fixes ---------------- -• Fix for some geometry which simply disappeared under some - transformations---a stroked line with an extreme skew in X, for - example (Carl Worth and Jonathan Watt). - - https://bugzilla.mozilla.org/show_bug.cgi?id=373632 - -• SVG: Fix radial gradients for CAIRO_EXTEND_REFLECT and when r0 > r1 - (Emmanuel Pacaud). - -• PDF: Set page group color space to DeviceRGB. - - This fixes incorrect (muddy) transparent colors when rendering cairo - PDF output in some viewers. (Adrian Johnson, Adam Goode, and - MenTaLguY). - - http://lists.freedesktop.org/archives/cairo/2006-November/008551.html - -• win32: Return correct metrics when hinting is off, and fix font - descent computation (Behdad Esfahbod). - -• quartz: Fix glyph interfaces to correctly return user-space rather - than device-space coordinates (Brian Ewins). - - https://bugs.freedesktop.org/show_bug.cgi?id=9568 - -• xcb: Fix parameter-order confusion with xcb_create_pixmap, which now - makes all tests that pass with xlib now pass with xcb (Carl Worth, - Jamey Sharp). - -• Fix some memory leaks in the perf suite (Chris Wilson). - -• Fix perf suite to consider changes in pixman/src (Mathias - Hasselmann). - -Build fixes ------------ -• Don't include pre-generated cairo-features.h file. This was causing - build failures when building with the directfb backend enabled - (Behdad Esfahbod). - - https://bugs.freedesktop.org/show_bug.cgi?id=10189 - -• Eliminate use of maintainer mode from cairo's automake/configure - script. This means that updates to files such as Makefile.am will - take effect, (by rerunning automake and friends as necessary) when - invoking make rather than being silently ignored. (Behdad Esfahbod) - -• Don't compile cairo-deflate-stream.c, which depends on zlib, unless - building the pdf backend which requires it. (Carl Worth, Tor - Lillqvist) - - https://bugs.freedesktop.org/show_bug.cgi?id=10202 - -• Don't make the ps backend link against zlib anymore, since it - doesn't require it (Carl Worth). - -• Use "find !" rather than "find -not" for better portability (Thomas - Klausner). - - https://bugs.freedesktop.org/show_bug.cgi?id=10226 - -• Don't use unsupported visibility attribute "hidden" on Solaris - (Gilles Dauphin, Thomas Klausner). - - https://bugs.freedesktop.org/show_bug.cgi?id=10227 - -Optimization ------------- -• It was Behdad that suggested we focus strictly on bug fixes now that - we shipped so many performance improvements in 1.4.0, but it was - also Behdad that got distracted by the chance to remove a lot of - mallocs from cairo. Paths, gstates, trapezoids, splines, polygons, - and gradient color stops will now use small, stack-allocated buffers - in the most common cases rather than calling malloc as - often. (Behdad Esfahbod). And look for more from Mathias Hasselmann - soon. - -Release 1.4.0 (2007-03-06 Carl Worth ) -========================================================= -The many people[*] who have been working hard on cairo are very -pleased to announce the long-awaited release of cairo 1.4. This -release comes 4 months after the last stable update release (1.2.6) -and 9 months since the initial release of 1.2.0. - -The release notes below are intended to capture the highlights of the -changes that have occurred from the 1.2 series to the new 1.4.0 -release. - -Performance improvements ------------------------- -Within the cairo project, the last 6 months or so has seen an intense -effort focusing on the performance of cairo itself. That effort has -paid off considerably, as can be seen in the following highlights of -some of the performance differences from cairo 1.2.6 to cairo 1.4.0. - -(Note: The performance results reported here were measured on an x86 -laptop. Many of the improvements in 1.4---particular those involving -text rendering---are even more dramatic on embedded platforms without -hardware floating-point units. Such devices played an important part -of many of the optimizations that found their way into cairo over the -last few months.) - -• Dramatic improvement when drawing objects that are mostly off-screen - with the image backend (with the xlib backend this case is still - slow due to an X server bug): - - image-rgba long-lines-uncropped-100 479.64 -> 4.98: 96.24x speedup - ███████████████████████████████████████████████▋ - -• Dramatic improvement when copying a small fraction of an image - surface to an xlib surface: - - xlib-rgba subimage_copy-512 3.93 -> 0.07: 54.52x speedup - ██████████████████████████▊ - -• Dramatic improvement to tessellation speed for complex objects: - - image-rgb tessellate-256-100 874.16 -> 34.79: 25.13x speedup - ████████████▏ - xlib-rgba zrusin_another_fill-415 148.40 -> 13.85: 10.72x speedup - ████▉ - xlib-rgb world_map-800 680.20 -> 345.54: 1.97x speedup - ▌ - -• Dramatic improvement to the speed of stroking rectilinear shapes, - (such as the outline of a rectangle or "box"): - - image-rgb box-outline-stroke-100 0.18 -> 0.01: 24.22x speedup - ███████████▋ - xlib-rgb box-outline-stroke-100 0.46 -> 0.06: 8.05x speedup - ███▌ - - -• Dramatic improvements to text rendering speeds: - - xlib-rgba text_image_rgba_over-256 63.12 -> 9.61: 6.57x speedup - ██▊ - -• 3x improvements to floating-point to fixed-point conversion speeds: - - image-rgba pattern_create_radial-16 9.29 -> 3.44: 2.70x speedup - ▉ - -• 2x improvements to linear gradient computation: - - image-rgb paint_linear_rgb_source-512 26.22 -> 11.61: 2.26x speedup - ▋ - -• 2x improvement to a case common in PDF rendering: - - image-rgb unaligned_clip-100 0.10 -> 0.06: 1.81x speedup - ▍ - -• 1.3x improvement to rectangle filling speed (note: this improvement - is new since 1.3.16---previously this test case was a 1.3x slowdown - compared to 1.2.6): - - image-rgba rectangles-512 6.19 -> 4.37: 1.42x speedup - ▎ - xlib-rgba rectangles-512 7.48 -> 5.58: 1.34x speedup - ▏ - -NOTE: In spite of our best efforts, there are some measurable -performance regressions in 1.4 compared to 1.2. It appears that the -primary problem is the increased overhead of the new tessellator when -drawing many, very simple shapes. The following test cases capture -some of that slowdown: - - image-rgba mosaic_tessellate_lines-800 11.03 -> 14.29: 1.30x slowdown - ▏ - image-rgba box-outline-fill-100 0.01 -> 0.01: 1.26x slowdown - ▏ - image-rgba fill_solid_rgb_over-64 0.20 -> 0.22: 1.12x slowdown - - image-rgba fill_image_rgba_over-64 0.23 -> 0.25: 1.10x slowdown - - xlib-rgb paint_image_rgba_source-256 3.24 -> 3.47: 1.07x slowdown - -We did put some special effort into eliminating this slowdown for the -very common case of drawing axis-aligned rectangles with an identity -matrix (see the box-outline-stroke and rectangles speedup numbers -above). Eliminating the rest of this slowdown will be a worthwhile -project going forward. - -Also note that the "box-outline-fill" case is a slowdown while -"box-outline-stroke" is a (huge) speedup. These two test cases -resulted from the fact that some GTK+ theme authors were filling -between two rectangles to avoid slow performance from the more natural -means of achieving the same shape by stroking a single rectangle. With -1.4 that workaround should definitely be eliminated as it will now -cause things to perform more slowly. - -Greatly improved PDF output ---------------------------- -We are very happy to be able to announce that cairo-generated PDF -output will now have text that can be selected, cut-and-pasted, and -searched with most capable PDF viewer applications. This is something -that was not ever possible with cairo 1.2. - -Also, the PDF output now has much more compact encoding of text than -before. Cairo is now much more careful to not embed multiple copies of -the same font at different sizes. It also compresses text and font -streams within the PDF output. - -API additions -------------- -There are several new functions available in 1.4 that were not -available in 1.2. Curiously, almost all of the new functions simply -allow the user to query state that has been set in cairo (many new -"get" functions) rather than providing any fundamentally new -operations. The new functionality is: - -• Getting information about the current clip region - - cairo_clip_extents - cairo_copy_clip_rectangle_list - cairo_rectangle_list_destroy - -• Getting information about the current dash setting - - cairo_get_dash_count - cairo_get_dash - -• Getting information from a pattern - - cairo_pattern_get_rgba - cairo_pattern_get_surface - cairo_pattern_get_color_stop_rgba - cairo_pattern_get_color_stop_count - cairo_pattern_get_linear_points - cairo_pattern_get_radial_circles - -• Getting the current scaled font - - cairo_get_scaled_font - -• Getting reference counts - - cairo_get_reference_count - cairo_surface_get_reference_count - cairo_pattern_get_reference_count - cairo_font_face_get_reference_count - cairo_scaled_font_get_reference_count - -• Setting/getting user data on objects - - cairo_set_user_data - cairo_get_user_data - cairo_pattern_set_user_data - cairo_pattern_get_user_data - cairo_scaled_font_set_user_data - cairo_scaled_font_get_user_data - -• New cairo-win32 functions: - - cairo_win32_surface_create_with_ddb - cairo_win32_surface_get_image - cairo_win32_scaled_font_get_logical_to_device - cairo_win32_scaled_font_get_device_to_logical - -API deprecation ---------------- -The CAIRO_FORMAT_RGB16_565 enum value has been deprecated. It never -worked as a format value for cairo_image_surface_create, and it wasn't -necessary for supporting 16-bit 565 X server visuals. - -A sampling of bug fixes in cairo 1.4 ------------------------------------- - • Fixed radial gradients - • Fixed dashing (degenerate and "leaky" cases) - • Fixed transformed images in PDF/PS output (eliminate bogus repeating) - • Eliminate errors from CAIRO_EXTEND_REFLECT and CAIRO_EXTEND_PAD - • cairo_show_page no longer needed for single-page output - • SVG: Fix bug preventing text from appearing in many viewers - • cairo-ft: Return correct metrics when hinting is off - • Eliminate crash in cairo_create_similar if nil surface is returned - • Eliminate crash after INVALID_RESTORE error - • Fix many bugs related to multi-threaded use and locking - • Fix for glyph spacing 32 times larger than desired (cairo-win32) - • Fixed several problems in cairo-atsui (assertion failures) - • Fix PDF output to avoid problems when printing from Acrobat Reader - • Fix segfault on Mac OS X (measuring a zero-length string) - • Fix text extents to not include the size of non-inked characters - • Fix for glyph cache race condition in glitz backend (Jinghua Luo) - • Fix make check to work on OPD platforms (IA64 or PPC64) - • Fix compilation problems of cairo "wideint" code on some platforms - • Many, many others... - -Experimental backends (quartz, XCB, OS/2, BeOS, directfb) ---------------------------------------------------------- -None of cairo's experimental backends are graduating to "supported" -status with 1.4.0, but two of them in particular (quartz and xcb), are -very close. - -The quartz baceknd has been entirely rewritten and is now much more -efficient. The XCB backend has been updated to track the latest XCB -API (which recently had a 1.0 release). - -We hope to see these backends become supported in a future release, -(once they are passing all the tests in cairo's test suite). - -The experimental OS/2 backend is new in cairo 1.4 compared to cairo -1.2. - -Documentation improvements --------------------------- -We have added documentation for several functions and types that -were previously undocumented, and improved documentation on other -ones. As of this release, there remain only two undocumented -symbols: cairo_filter_t and cairo_operator_t. - -[*]Thanks to everyone ---------------------- -I've accounted for 41 distinct people with attributed code added to -cairo between 1.2.6 and 1.4.0, (their names are below). That's an -impressive number, but there are certainly dozens more that -contributed with testing, suggestions, clarifying questions, and -encouragement. I'm grateful for the friendships that have developed as -we have worked on cairo together. Thanks to everyone for making this -all so much fun! - -Adrian Johnson, Alfred Peng, Alp Toker, Behdad Esfahbod, -Benjamin Otte, Brian Ewins, Carl Worth, Christian Biesinger, -Christopher (Monty) Montgomery, Daniel Amelang, Dan Williams, -Dave Yeo, David Turner, Emmanuel Pacaud, Eugeniy Meshcheryakov, -Frederic Crozat, Hans Breuer, Ian Osgood, Jamey Sharp, Jeff Muizelaar, -Jeff Smith, Jinghua Luo, Jonathan Watt, Joonas Pihlaja, Jorn Baayen, -Kalle Vahlman, Kjartan Maraas, Kristian Høgsberg, M Joonas Pihlaja, -Mathias Hasselmann, Mathieu Lacage, Michael Emmel, Nicholas Miell, -Pavel Roskin, Peter Weilbacher, Robert O'Callahan, -Soren Sandmann Pedersen, Stuart Parmenter, T Rowley, -Vladimir Vukicevic - -Snapshot 1.3.16 (2007-03-02 Carl Worth ) -=========================================================== -New API functions ------------------ -A few new public functions have been added to the cairo API since the -1.3.14 snapshot. These include a function to query the current scaled -font: - - cairo_get_scaled_font - -New functions to query the reference count of all cairo objects: - - cairo_get_reference_count - - cairo_surface_get_reference_count - cairo_pattern_get_reference_count - - cairo_font_face_get_reference_count - cairo_scaled_font_get_reference_count - -And new functions to allow the use of user_data with any cairo object, -(previously these were only available on cairo_surface_t and -cairo_font_face_t objects): - - cairo_set_user_data - cairo_get_user_data - - cairo_pattern_set_user_data - cairo_pattern_get_user_data - - cairo_scaled_font_set_user_data - cairo_scaled_font_get_user_data - -Usability improvement for PDF/PS/SVG generation ------------------------------------------------ -In previous versions of cairo, generating single-page output with the -cairo-pdf, cairo-ps, or cairo-svg backends required a final call to -cairo_show_page. This was often quite confusing as people would port -functional code from a non-paginated backend and be totally mystified -as to why the output was blank until they learned to add this call. - -Now that call to cairo_show_page is optional, (it will be generated -implicitly if the user does not call it). So cairo_show_page is only -needed to explicitly separate multiple pages. - -Greatly improved PDF output ---------------------------- -We are very happy to be able to announce that cairo-generated PDF -output will now have text that can be selected, cut-and-paste, and -searched with most capable PDF viewer applications. This is something -that was not ever possible with cairo 1.2. - -Also, the PDF output now has much more compact encoding of text than -before. Cairo is now much more careful to not embed multiple copies of -the same font at different sizes. It also compresses text and font -streams within the PDF output. - -Major bug fixes ---------------- - • Fixed radial gradients - - The rendering of radial gradients has been greatly improved. In - the cairo 1.2 series, there was a serious regression affecting - radial gradients---results would be very incorrect unless one of - the gradient circles had a radius of 0.0 and a center point within - the other circle. These bugs have now been fixed. - - • Fixed dashing - - Several fixes have been made to the implementation of dashed - stroking. Previously, some dashed, stroked rectangles would - mis-render and fill half of the rectangle with a large triangular - shape. This bug has now been fixed. - - • Fixed transformed images in PDF/PS output - - In previous versions of cairo, painting with an image-based source - surface pattern to the PDF or PS backends would cause many kinds - of incorrect results. One of the most common problems was that an - image would be repeated many times even when the user had - explicitly requested no repetition with CAIRO_EXTEND_NONE. These - bugs have now been fixed. - - • Eliminate errors from CAIRO_EXTEND_REFLECT and CAIRO_EXTEND_PAD - - In the 1.2 version of cairo any use of CAIRO_EXTEND_REFLECT or - CAIRO_EXTEND_PAD with a surface-based pattern resulted in an - error, (cairo would stop rendering). This bug has now been - fixed. - - Now, CAIRO_EXTEND_REFLECT should work properly with surface - patterns. - - CAIRO_EXTEND_PAD is still not working correctly, but it will now - simply behave as CAIRO_EXTEND_NONE rather than triggering the - error. - -New rewrite of quartz backend (still experimental) --------------------------------------------------- -Cairo's quartz backend has been entirely rewritten and is now much -more efficient. This backend is still marked as experimental, not -supported, but it is now much closer to becoming an officially -supported backend. (For people that used the experimental nquartz -backend in previous snapshots, that implementation has now been -renamed from "nquartz" to "quartz" and has replaced the old quartz -backend.) - -Documentation improvements --------------------------- -We have added documentation for several functions and types that -were previously undocumented, and improved documentation on other -ones. As of this release, there remain only two undocumented -symbols: cairo_filter_t and cairo_operator_t. - -Other bug fixes ---------------- - • cairo-svg: Fix bug that was preventing text from appearing in many - viewers - - • cairo-ft: Return correct metrics when hinting is off - - • Cairo 1.3.14 deadlocks in cairo_scaled_font_glyph_extents or - _cairo_ft_unscaled_font_lock_face - - https://bugs.freedesktop.org/show_bug.cgi?id=10035 - - • cairo crashes in cairo_create_similar if nil surface returned by - other->backend->create_similar - - https://bugs.freedesktop.org/show_bug.cgi?id=9844 - - • evolution crash in _cairo_gstate_backend_to_user() - https://bugs.freedesktop.org/show_bug.cgi?id=9906 - - • Fix memory leak in rectilinear stroking code - -Things not in this release --------------------------- - • Solid-surface-pattern cache: This patch had been applied during - the 1.3.x series, but it was reverted due to some inter-thread - problems it caused. The patch is interesting since it made a big - benefit for text rendering performance---so we'll work to bring a - corrected version of this patch back as soon as possible. - -Snapshot 1.3.14 (2006-02-13 Carl Worth ) -=========================================================== -This is the seventh development snapshot in the 1.3 series, (and there -likely won't be many more before the 1.4.0 release). It comes just -over 3 weeks after the 1.3.12 snapshot. - -Since we're so close to the 1.4.0 release, there are not a lot of new -features nor even a lot of new performance improvements in this -snapshot. Instead, there are a great number of bug fixes. Some are -long-standing bugs that we're glad to say goodbye to, and several are -fixes for regressions that were introduced as part of the optimization -efforts during the 1.3.x series. - -PDF text selection fixed ------------------------- -The inability to correctly select text in cairo-generated PDF has been -a defect ever since the initial support for the PDF backend in the -cairo 1.2.0 release. With the 1.3.14 snapshot, in most situations, and -with most PDF viewer applications, the PDF generated by cairo will -allow text to be correctly selected for copy-and-paste, (as well as -searching). - -We're very excited about this new functionality, (and very grateful to -Adrian Johnson, Behdad Esfahbod, and others that have put a lot of -work into this lately). Please test this new ability and give feedback -on the cairo@cairographics.org list. - -Many thread-safety issues fixed -------------------------------- -We've discovered that no release of cairo has ever provided safe text -rendering from a multi-threaded application. With the 1.3.14 snapshot -a huge number of the bugs in this area have been fixed, and multiple -application dvelopers have now reported success at writing -multi-threaded applications with cairo. - -Other fixes ------------ -Fixed a bug that was causing glyph spacing to be 32 times larger than -desired when using cairo-win32. - -Fixed a regression in the rendering of linear gradients that had been -present since the 1.3.8 snapshot. - -Fixed several problems in cairo-atsui that were leading to assertion -failures when rendering text. - -Fix corrupted results when rendering a transformed source image -surface to an xlib surface. This was a regression that had been -present since the 1.3.2 snapshot. - -Fixed PDF output to prevent problems printing from some versions of -Acrobat Reader, (a single glyph was being substituted for every -glyph). - -And many other fixes as well, (see the logs for details). - -Snapshot 1.3.12 (2007-01-20 Carl Worth ) -=========================================================== -The relentless march toward the cairo 1.4 release continues, (even if -slightly late out of the starting blocks in 2007). This is the sixth -development snapshot in the 1.3 series. It comes 4 weeks after the -1.3.10 snapshot. - -Performance ------------ -As usual, this snapshot has some fun performance improvements to show -off: - -image-rgba long-lines-uncropped-100 470.08 -> 4.95: 94.91x speedup -███████████████████████████████████████████████ -image-rgb long-lines-uncropped-100 461.60 -> 4.96: 93.02x speedup -██████████████████████████████████████████████ - -This 100x improvement, (and yes, that's 100x, not 100%), in the image -backend occurs when drawing large shapes where only a fraction of the -shape actually appears in the final result, (the rest being outside -the bounds of the destination surface). Many applications should see -speedups here, and the actual amount of speedup depends on the ratio -of non-visible to visible portions of geometry. - -[Note: There remains a similar performance bug when drawing mostly -non-visible objects with the xlib backend. This is due to a similar -bug in the X server itself, but we hope a future cairo snapshot will -workaround that bug to get a similar speedup with the xlib backend.] - -image-rgba unaligned_clip-100 0.09 -> 0.06: 1.67x speedup -▍ -image-rgb unaligned_clip-100 0.09 -> 0.06: 1.66x speedup -▍ - -This speedup is due to further MMX optimization by Soeren Sandmann for -a case commonly hit when rendering PDF files, (and thanks to Jeff -Muizelaar for writing code to extract the test case for us). - -There's another MMX optimization in this snapshot (without a fancy -speedup chart) by Dan Williams which improves compositing performance -specifically for the OLPC machine. - -Thanks to Adrian Johnson, cairo's PDF output is now much more -efficient in the way it encodes text output. By reducing redundant -information and adding compression to text output streams, Adrian -achieved a ~25x improvement in the efficiency of encoding text in PDF -files, (was ~45 bytes per glyph and is now ~1.6 bytes per glyph). - -Bug fixes ---------- -In addition to those performance improvements, this snapshot includes -several bug fixes: - - * A huge number of bug fixes for cairo-atsui text rendering, (for mac - OS X). These bugs affect font selection, glyph positioning, glyph - rendering, etc. One noteworthy bug fixes is that - cairo_select_font_face will no longer arbitrarily select bold nor - italic when not requested, (at least not when using a standard CSS2 - font family name such as "serif", "sans-serif", "monospace", etc.). - All these fixes are thanks to Brian Ewins who continues to do a - great job as the new cairo-atsui maintainer. - - * Fix PDF output so that images that are scaled down no longer - mysteriously repeat (Carl Worth). - - * Fix segfault on Mac OS X dues to attempt to measure extents of a - zero-length string (Behdad Esfahbod). - - * Fix text extents to not include the size of initial/trailing - non-inked characters (Behdad Esfahbod). - -API tweaks ----------- -Three functions have had API changes to improve consistency. Note that -the API functions being changed here are all functions that were -introduced as new functions during these 1.3.x snapshots. As always, -there will not be any API changes to functions included in a major -release (1.2.x, 1.4.x, etc.) of cairo. - -The changes are as follows: - - * Rename of cairo_copy_clip_rectangles to cairo_copy_clip_rectangle_list. - - * Change cairo_get_dash_count to return an int rather than accepting a - pointer to an int for the return value. - - * Change cairo_get_dash to have a void return type rather than - returning cairo_status_t. - -It's possible there will be one more round of changes to these -functions, (and perhaps cairo_get_color_stop as well), as we seek to -establish a unifying convention for returning lists of values. - -Snapshot 1.3.10 (2006-12-23 Carl Worth ) -=========================================================== -Santa Claus is coming just a little bit early this year, and he's -bringing a shiny new cairo snapshot for all the good little boys and -girls to play with. - -This is the fifth development snapshot in the 1.3 series. It comes 9 -days after the 1.3.8 snapshot, and still well within our goal of -having a new snapshot every week, (though don't expect one next -week---we'll all be too stuffed with sugar plums). - -Speaking of sugar plums, there's a sweet treat waiting in this cairo -snapshot---greatly improved performance for stroking rectilinear -shapes, like the ever common rectangle: - -image-rgb box-outline-stroke-100 0.18 -> 0.01: 25.58x speedup -████████████████████████▋ -image-rgba box-outline-stroke-100 0.18 -> 0.01: 25.57x speedup -████████████████████████▋ -xlib-rgb box-outline-stroke-100 0.49 -> 0.06: 8.67x speedup -███████▋ -xlib-rgba box-outline-stroke-100 0.22 -> 0.04: 5.39x speedup -████▍ - -In past releases of cairo, some people had noticed that using -cairo_stroke to draw rectilinear shapes could be awfully slow. Many -people had worked around this by using cairo_fill with a more complex -path and gotten a 5-15x performance benefit from that. - -If you're one of those people, please rip that workaround out, as now -the more natural use of cairo_stroke should be 1.2-2x faster than the -unnatural use of cairo_fill. - -And if you hadn't ever implemented that workaround, then you just -might get to see your stroked rectangles now get drawn 5-25x faster. - -Beyond that performance fix, there are a handful of bug fixes in this -snapshot: - - * Fix for glyph cache race condition in glitz backend (Jinghua Luo) - - * Many fixes for ATSUI text rendering (Brian Ewins) - - * Un-break recent optimization-triggered regression in rendering text - with a translation in the font matrix (Behdad Esfahbod) - - * Fix make check to work on OPD platforms (IA64 or PPC64) - (Frederic Crozat) - - * Fix a couple of character spacing issues on Windows - (Jonathan Watt) - -Have fun with that, everybody, and we'll be back for more in the new -year, (with a plan to add the last of our performance improvements in -this round, fix a few bad, lingering bugs, and then finish off a nice, -stable 1.4 release before the end of January). - --Carl - -Snapshot 1.3.8 (2006-12-14 Carl Worth ) -========================================================== -This is the fourth development snapshot in the 1.3 series. It comes -just slightly more than one week after the 1.3.6 snapshot. - -After the bug fixes in 1.3.6, we're back to our original program of -weekly snapshots, each one faster than the one from the week -before. Cairo 1.3.8 brings a 2x improvement in the speed of rendering -linear gradients (thanks to David Turner), and a significant reduction -in X traffic when rendering text (thanks to Xan Lopez and Behdad -Esfahbod), making cairo behave very much like Xft does. - -A few other things in the 1.3.8 snapshot worth noting include a more -forgiving image comparator in the test suite, (using the "perceptual -diff" metric and GPL implementation by Hector Yee[*]), a bug fix for -broken linking on x86_64 (thanks to M Joonas Pihlaja) and an even -better implementation of _cairo_lround, (not faster, but supporting a -more complete input range), from Daniel Amelang. - -[*] http://pdiff.sourceforge.net/ - -Snapshot 1.3.6 (2006-12-06 Carl Worth ) -========================================================== -This is the third development snapshot in the 1.3 series. It comes two -weeks after the 1.3.4 snapshot. - -We don't have fancy performance charts this week as the primary -changes in this snapshot are bug fixes. The performance work continues -and the next snapshot (planned for one week from today) should include -several improvements. The bug fixes in this snapshot include: - - * Fix undesirable rounding in glyph positioning (Dan Amelang) - - This bug was noticed by several users, most commonly by seeing - improper text spacing or scrambled glyphs as drawn by nautilus. For - example: - - Update to cairo-1.3.4 worsen font rendering - https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=217819 - - * Fix reduced range of valid input coordinates to tessellator - (M Joonas Pihlaja) - - This bug was causing lots of assertion failures in mozilla as - mentioned here: - - CAIRO_BO_GUARD_BITS and coordinate space? - http://lists.freedesktop.org/archives/cairo/2006-December/008743.html - - * Fix several regressions in new tessellator (M Joonas Pihlaja) - - Joonas just had a good eye for detail here. I don't think any - external cairo users had noticed any of these bugs yet. - - * Fix compilation problems of cairo "wideint" code on some platforms - (Mathieu Lacage) - - * Fix failed configure due to broken grep (Dan Amelang) - - This bug was reported here: - - AX_C_FLOAT_WORDS_BIGENDIAN doesn't work because grep doesn't - work with binary file - https://bugs.freedesktop.org/show_bug.cgi?id=9124 - - * Remove the pkg-config minimum version requirement (Behdad Esfahbod) - - Some systems ship with pkg-config 0.15 and there was really no good - reason for cairo to insist on having version 0.19 before it would - build. - -There is also one new (but inert) feature in this snapshot. There's a -new option that can be passed to cairo's configure script: - - --disable-some-floating-point - - Disable certain code paths that rely heavily on double precision - floating-point calculation. This option can improve - performance on systems without a double precision floating-point - unit, but might degrade performance on those that do. - -As of this snapshot, this option does not make any change to cairo, -but it is possible that future versions of cairo will respect this -option and change the implementation of various functions as -appropriate. - -Snapshot 1.3.4 (2006-11-22 Carl Worth ) -========================================================== -This is the second development snapshot in the 1.3 series. It comes -one week after the 1.3.2 snapshot. - -This snapshot has a couple of significant performance improvements, -and also adds new support for producing multi-page SVG output, (when -targeting SVG 1.2)---thanks to Emmanuel Pacaud. The details of the -performance improvements are as follows: - -1. The long-awaited "new tessellator". - - The credit for this being an improvement goes to Joonas Pihlaja. He - took my really slow code and really put it through its paces to get - the dramatic performance improvement seen below (up to 38x faster - on realistic cases, and more than 10x faster for the zrusin_another - test). - - His own writeup of the work he did is quite thorough, but more than - can be quoted here. Please see his post for the interesting details: - - http://lists.freedesktop.org/archives/cairo/2006-November/008483.html - - (Though note that this snapshot also includes some additional, - significant improvements that were only sketched out in that - email---see "Generating fewer trapezoids"). - -2. More floating-point improvements - - Daniel Amelang continues to work the magic he began in the 1.3.2 - snapshot. This time he short-circuits floating-point - transformations by identity matrices and applies the earlier - floating-to-fixed-point technique to the problem of rounding. - - The improvements here will primarily benefit text performance, and - will benefit platforms without hardware floating-point more than - those that have it, (some text tests show 20% improvement on an x86 - machine and closer to 80% improvement on arm). - -The performance chart comparing 1.3.2 to 1.3.4 really speaks for -itself, (this is on an x86 laptop). This is quite a lot of progress -for one week: - - xlib-rgb stroke_similar_rgba_over-256 74.99 1.45% -> 2.03 68.38%: 36.86x speedup -███████████████████████████████████▉ - xlib-rgb stroke_similar_rgba_source-256 78.23 1.43% -> 3.30 67.05%: 23.71x speedup -██████████████████████▊ - xlib-rgba tessellate-256-100 820.42 0.15% -> 35.06 2.84%: 23.40x speedup -██████████████████████▍ -image-rgba tessellate-256-100 819.55 0.32% -> 35.04 3.56%: 23.39x speedup -██████████████████████▍ - xlib-rgb stroke_image_rgba_over-256 78.10 1.43% -> 4.33 65.56%: 18.04x speedup -█████████████████ - xlib-rgb stroke_image_rgba_source-256 80.11 1.63% -> 5.75 63.99%: 13.94x speedup -█████████████ - xlib-rgba zrusin_another_tessellate-415 89.22 0.35% -> 8.38 5.23%: 10.65x speedup -█████████▋ -image-rgba zrusin_another_tessellate-415 87.38 0.89% -> 8.37 5.22%: 10.44x speedup -█████████▍ -image-rgba zrusin_another_fill-415 117.67 1.34% -> 12.88 2.77%: 9.14x speedup -████████▏ - xlib-rgba zrusin_another_fill-415 140.52 1.57% -> 15.79 2.88%: 8.90x speedup -███████▉ -image-rgba tessellate-64-100 9.68 3.42% -> 1.42 0.60%: 6.82x speedup -█████▉ - xlib-rgba tessellate-64-100 9.78 4.35% -> 1.45 0.83%: 6.72x speedup -█████▊ - xlib-rgb stroke_linear_rgba_over-256 46.01 2.44% -> 7.74 54.51%: 5.94x speedup -█████ - xlib-rgb stroke_linear_rgba_source-256 48.09 2.15% -> 9.14 53.00%: 5.26x speedup -████▎ - xlib-rgb stroke_radial_rgba_over-256 50.96 2.34% -> 12.46 47.99%: 4.09x speedup -███▏ - xlib-rgb stroke_radial_rgba_source-256 53.06 1.57% -> 13.96 46.57%: 3.80x speedup -██▊ -image-rgba paint_similar_rgba_source-256 0.12 1.57% -> 0.08 9.92%: 1.42x speedup -▍ -image-rgba paint_image_rgba_source-256 0.12 2.49% -> 0.08 10.70%: 1.41x speedup -▍ -image-rgba world_map-800 356.28 0.46% -> 275.72 1.15%: 1.29x speedup -▎ - xlib-rgba world_map-800 456.81 0.39% -> 357.95 1.39%: 1.28x speedup -▎ -image-rgb tessellate-16-100 0.09 0.57% -> 0.07 3.43%: 1.23x speedup -▎ -image-rgba tessellate-16-100 0.09 0.06% -> 0.07 2.46%: 1.23x speedup -▎ -image-rgba text_solid_rgb_over-256 5.39 4.01% -> 4.47 0.70%: 1.21x speedup -▎ -image-rgba text_solid_rgba_over-256 5.37 0.82% -> 4.45 0.75%: 1.21x speedup -▎ -image-rgba text_image_rgb_over-64 0.78 0.10% -> 0.65 0.74%: 1.20x speedup -▎ -image-rgba text_image_rgba_over-64 0.78 0.29% -> 0.65 0.68%: 1.19x speedup -▎ -image-rgb text_solid_rgb_over-64 0.76 2.45% -> 0.63 0.81%: 1.19x speedup -▎ -image-rgba text_solid_rgba_over-64 0.76 0.33% -> 0.64 0.66%: 1.19x speedup -▎ -image-rgba text_similar_rgba_over-256 5.99 4.72% -> 5.04 1.09%: 1.19x speedup -▎ - -We should point out that there is some potential for slowdown in this -snapshot. The following are the worst slowdowns reported by the cairo -performance suite when comparing 1.3.2 to 1.3.4: - -image-rgba subimage_copy-256 0.01 0.87% -> 0.01 3.61%: 1.45x slowdown -▌ - xlib-rgb paint_solid_rgb_over-256 0.31 10.23% -> 0.38 0.33%: 1.26x slowdown -▎ -image-rgba box-outline-fill-100 0.01 0.30% -> 0.01 2.52%: 1.21x slowdown -▎ -image-rgba fill_solid_rgb_over-64 0.20 1.22% -> 0.22 1.59%: 1.12x slowdown -▏ -image-rgb fill_similar_rgb_over-64 0.21 1.04% -> 0.24 1.06%: 1.11x slowdown -▏ -image-rgba fill_image_rgb_over-64 0.21 1.19% -> 0.24 0.72%: 1.11x slowdown -▏ -image-rgba fill_similar_rgb_over-64 0.21 0.18% -> 0.24 0.30%: 1.11x slowdown -▏ -image-rgb fill_solid_rgba_over-64 0.22 1.66% -> 0.24 1.15%: 1.11x slowdown -▏ -image-rgb fill_image_rgb_over-64 0.21 0.14% -> 0.24 0.80%: 1.11x slowdown -▏ -image-rgba fill_image_rgba_over-64 0.22 1.34% -> 0.25 0.20%: 1.11x slowdown -▏ -image-rgba fill_solid_rgba_over-64 0.22 1.48% -> 0.24 0.95%: 1.11x slowdown -▏ -image-rgb fill_similar_rgba_over-64 0.22 1.13% -> 0.25 1.25%: 1.10x slowdown -▏ - -The 45% slowdown for subimage_copy is an extreme case. It's unlikely -to hit many applications unless they often use cairo_rectangle; -cairo_fill to copy a single pixel at a time. In any case, it shows a -worst-case impact of the overhead of the new tessellator. The other -slowdowns (~ 10%) are probably more realistic, and still very -concerning. - -We will work to ensure that performance regressions like these are not -present from one major release of cairo to the next, (for example, -from 1.2 to 1.4). - -But we're putting this 1.3.4 snapshot out there now, even with this -potential slowdown so that people can experiment with it. If you've -got complex geometry, we hope you will see some benefit from the new -tessellator. If you've got primarily simple geometry, we hope things -won't slowdown too much, but please let us know what slowdown you see, -if any, so we can calibrate our performance suite against real-world -impacts. - -Thanks, and have fun with cairo! - -Snapshot 1.3.2 (2006-11-14 Carl Worth ) -========================================================== -This is the first development snapshot since the 1.2 stable series -branched off shortly after the 1.2.4 release in August 2006. - -This snapshot includes all the bug fixes from the 1.2.6 release, -(since they originated here on the 1.3 branch first and were -cherry-picked over to 1.2). But more importantly, it contains some new -API in preparation for a future 1.4 release, and most importantly, it -contains several performance improvements. - -The bug fixes will not be reviewed here, as most of them are already -described in the 1.2.6 release notes. But details for the new API and -some performance improvements are included here. - -As with all snapshots, this is experimental code, and the new API -added here is still experimental and is not guaranteed to appear -unchanged in any future release of cairo. - -API additions -------------- -Several new API additions are available in this release. There is a -common theme among all the additions in that they allow cairo to -advertise information about its state that it was refusing to -volunteer earlier. So this isn't groundbreaking new functionality, but -it is essential for easily achieving several tasks. - -The new functions can be divided into three categories: - - Getting information about the current clip region - ------------------------------------------------- - cairo_clip_extents - cairo_copy_clip_rectangles - cairo_rectangle_list_destroy - - Getting information about the current dash setting - -------------------------------------------------- - cairo_get_dash_count - cairo_get_dash - - Getting information from a pattern - ---------------------------------- - cairo_pattern_get_rgba - cairo_pattern_get_surface - cairo_pattern_get_color_stop_rgba - cairo_pattern_get_color_stop_count - cairo_pattern_get_linear_points - cairo_pattern_get_radial_circles - -In each of these areas, we have new API for providing a list of -uniform values from cairo. The closest thing we had to this before was -cairo_copy_path, (which is rather unique in providing a list of -non-uniform data). - -The copy_clip_rectangles/rectangle_list_destroy functions follow a -style similar to that of cairo_copy_path. Meanwhile, the dash and -pattern color stop functions introduce a new style in which there is a -single call to return the number of elements available (get_dash_count -and get_color_stop_count) and then a function to be called once to get -each element (get_dash and get_color_stop_rgba). - -I'm interested in hearing feedback from users of these new API -functions, particularly from people writing language bindings. One -open question is whether the clip "getter" functionality should adopt -a style similar to that of the new dash and color_stop interfaces. - -API deprecation ---------------- -The CAIRO_FORMAT_RGB16_565 enum value has been deprecated. It never -worked as a format value for cairo_image_surface_create, and it wasn't -necessary for supporting 16-bit 565 X server visuals. - -XCB backend changes -------------------- -The XCB backend has been updated to track the latest XCB API (which -recently had a 1.0 release). - -New quartz backend ------------------- -Vladimir Vukicevic has written a new "native quartz" backend which -will eventually replace the current "image-surface wrapping" quartz -backend. For now, both backends are available, (the old one is -"quartz" and the new one is "nquartz"). But it is anticipated that the -new backend will replace the old one and take on the "quartz" name -before this backend is marked as supported in a release of cairo. - -New OS/2 backend ----------------- -Doodle and Peter Weilbacher have contributed a new, experimental -backend for using cairo on OS/2 systems. - -Performance improvements ------------------------- -Here are some highlights from cairo's performance suite showing -improvements from cairo 1.2.6 to cairo 1.3.2. The command used to -generate this data is: - - ./cairo-perf-diff 1.2.6 HEAD - -available in the perf/ directory of a recent checkout of cairo's -source, (the cairo-perf-diff script does require a git checkout and -will not work from a tar file---though ./cairo-perf can still be used -to generate a single report there and ./cairo-perf-diff-files can be -used to compare two reports). - -Results are described below both for an x86 laptop (with an old Radeon -video card, recent X.org build, XAA, free software drivers), as well -as for a Nokia 770. First the x86 results with comments on each, (all -times are reported in milliseconds). - -Copying subsets of an image surface to an xlib surface (much faster) --------------------------------------------------------------------- - xlib-rgba subimage_copy-512 10.50 -> : 53.97x speedup -█████████████████████████████████████████████████████ - -Thanks to Christopher (Monty) Montgomery for this big performance -improvement. Any application which has a large image surface and is -copying small pieces of it at a time to an xlib surface, (imagine an -application that loads a single image containing all the "sprites" for -that application), will benefit from this fix. The larger the ratio of -the image surface to the portion being copied, the larger the benefit. - -Floating-point conversion (3x faster) -------------------------------------- - xlib-rgba pattern_create_radial-16 27.75 -> 3.93 : 2.94x speedup -██ -image-rgb pattern_create_radial-16 26.06 -> 3.74 : 2.90x speedup -█▉ - -Thanks to Daniel Amelang, (and others who had contributed the idea -earlier), for this nice improvement in the speed of converting -floating-point values to fixed-point. - -Text rendering (1.3 - 2x faster) ------------------------------- - xlib-rgba text_image_rgba_source-256 319.73 -> 62.40 : 2.13x speedup -█▏ -image-rgb text_solid_rgba_over-64 2.85 -> 0.88 : 1.35x speedup -▍ - -I don't think we've ever set out to improve text performance -specifically, but we did it a bit anyway. I believe the extra -improvement in the xlib backend is due to Monty's image copying fix -above, and the rest is due to the floating-point conversion speedup. - -Thin stroke improvements (1.5x faster) ---------------------------------------------- -image-rgb world_map-800 1641.09 -> 414.77 : 1.65x speedup -▋ - xlib-rgba world_map-800 1939.66 -> 529.94 : 1.52x speedup -▌ - -The most modest stuff to announce in this release is the 50% -improvement I made in the world_map case. This is in improvement that -should help basically anything that is doing strokes with many -straight line segments, (and the thinner the better, since that makes -tessellation dominate rasterization). The fixes here are to use a -custom quadrilateral tessellator rather than the generic tessellator -for straight line segments and the miter joins. - -Performance results from the Nokia 770 --------------------------------------- - xlib-rgba subimage_copy-512 55.88 -> 2.04 : 27.34x speedup -██████████████████████████▍ - xlib-rgb text_image_rgb_over-256 1487.58 -> 294.43 : 5.05x speedup -████ -image-rgb pattern_create_radial-16 187.13 -> 91.86 : 2.04x speedup -█ - xlib-rgba world_map-800 21261.41 -> 15628.02 : 1.36x speedup -▍ - -Here we see that the subimage_copy improvement was only about half as -large as the corresponding improvement on my laptop, (27x faster -compared to 54x) and the floating-point conversion fix also was quite -as significant, (2x compared to 3x). Oddly the improvement to text -rendering performance was more than twice as good (5x compared to -2x). I don't know what the reason for that is, but I don't think it's -anything anybody should complain about. - -Release 1.2.6 (2006-11-02 Behdad Esfahbod ) -============================================================== -This is the third bug fix release in the 1.2 series, coming less than -two months after the 1.2.4 release made on August 18. - -The 1.2.4 release turned out to be a pretty solid one, except for a crasher -bug when forwarding an X connection where the client and the server have -varying byte orders, eg. from a PPC to an i686. Other than that, various -other small bugs have been fixed. - -Various improvements have been made in the testing infrastructure to prevent -false positives, and to make sure the generated cairo shared object behaves as -expected in terms of exported symbols and relocations. - -There were a total of 89 changes since 1.2.4. The following list the most -important ones: - -Common fixes ------------- -- Avoid unsigned loop control variable to eliminate infinite, - memory-scribbling loop. (#7593) -- Fix cairo_image_surface_create to report INVALID_FORMAT errors. - Previously the detected error was being lost and a nil surface was - returned that erroneously reported CAIRO_STATUS_NO_MEMORY. -- Change _cairo_color_compute_shorts to not rely on any particular - floating-point epsilon value. (#7497) -- Fix infinite-join test case (bug #8379) -- Pass correct surface to create_similar in _cairo_clip_init_deep_copy(). - -PS/PDF fixes ------------- -- Fix Type 1 embedding in PDF. -- Correct the value of /LastChar in the PDF Type 1 font dictionary. -- Improve error checking in TrueType subsetting. -- Compute right index when looking up left side bearing. (bug #8180) -- Correct an unsigned to signed conversion problem in truetype subsetting - bbox. -- Type1 subsetting: Don't put .notdef in Encoding when there are 256 glyphs. -- Add cairo version to PS header / PDF document info dictionary. -- Set CTM before path construction. - -Win32 fixes ------------ -- Get correct unhinted outlines on win32. (bug 7603) -- Make cairo as a win32 static library possible. -- Use CAIRO_FORMAT_RGB24 for BITSPIXEL==32 surfaces too. - -Build system fixes ------------------- -- Define WINVER if it's not defined. (bug 6456) -- Fix the AMD64 final link by removing SLIM from pixman. -- Misc win32 compilation fixes. -- Add Sun Pro C definition of pixman_private. -- Use pixman_private consistently as prefix not suffix. -- Added three tests check-plt.sh, check-def.sh, and check-header.sh that check - that the shared object, the .def file, and the public headers agree about - the exported symbols. -- Require pkg-config 0.19. (#8686) - - -Release 1.2.4 (2006-08-18 Carl Worth ) -========================================================= -This is the second bug fix release in the 1.2 series, coming less than -two weeks after the 1.2.2 release made on August 8. - -The big motivation for a quick release was that there were a log of -build system snags that people ran into with the 1.2.2 release. But, -by the time we got those all done, we found that we had a bunch of -fixes for cairo's rendering as well. So there's a lot of goodness in -here for such a short time period. - -Rendering fixes ---------------- -Fix image surfaces to not be clipped when used as a source (Vladimir Vukicevic) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=72e25648c4c4bc82ddd938aa4e05887a293f0d8b - -Fix a couple of corner cases in dashing degenerate paths (Jeff Muizelaar) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=fbb1758ba8384650157b2bbbc93d161b0c2a05f0 - -Fix support for type1 fonts on win32 (Adrian Johnson) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=da1019c9138695cb838a54f8b871bbfd0e8996d7 - -Fix assertion failure when rotating bitmap fonts (Carl Worth) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=0bfa6d4f33b8ddb5dc55bbe419c15df4af856ff9 - -Fix assertion failure when calling cairo_text_path with bitmap fonts (Carl Worth) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=9878a033531e6b96b5f27e69e10e90dee7440cd9 - -Fix mis-handling of cairo_close_path in some situations (Tim Rowley, Carl Worth) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=53f74e59faf1af78f2f0741ccf1f23aa5dad4efc - -Respect font_matrix translation in _cairo_gstate_glyph_path (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=f183b835b111d23e838889178aa8106ec84663b3 - -Fix vertical metrics adjustment to work with non-identity shapes (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=b7bc263842a798d657a95e539e1693372448837f - -[PS] Set correct ImageMatrix in _cairo_ps_surface_emit_bitmap_glyph_data (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=d47388ad759b0a1a0869655a87d9b5eb6ae2445d - -Build system fixes ------------------- -Fix xlib detection to prefer pkg-config to avoid false libXt dependency (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=0e78e7144353703cbd28aae6a67cd9ca261f1d68 - -Fix typos causing win32 build problem with PS,PDF, and SVG backends (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=aea83b908d020e26732753830bb3056e6702a774 - -Fix configure cache to not use stale results (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=6d0e3260444a2d5b6fb0cb223ac79f1c0e7b3a6e - -Fix to not pass unsupported warning options to the compiler (Jens Granseuer) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=97524a8fdb899de1ae4a3e920fb7bda6d76c5571 - -Fix to allow env. variables such as png_REQUIRES to override configure detection (Jens Granseuer) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=abd16e47d6331bd3811c908e524b4dcb6bd23bf0 - -Fix test suite to not use an old system cairo when converting svg2png (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=6122cc85c8f71b1ba2df3ab86907768edebe1781 - -Fix test suite to not require signal.h to be present (Behdad Esfahbod) -http://gitweb.freedesktop.org/?p=cairo;a=commit;h=6f8cf53b1e1ccdbe1ab6a275656b19c6e5120e40 - -Code cleanups -------------- -Many useful warnings cleanups from sparse, valgrind, and careful eyes -(Kjartan Maraas, Pavel Roskin) - -Release 1.2.2 (2006-08-08 Carl Worth ) -========================================================= -This is the first bug fix release in the 1.2 series since the original -1.2.0 release made six weeks ago. - -There were some very serious bugs in the 1.2.0 release, (see below), -so everybody is encouraged to upgrade from 1.2.0 to 1.2.2. The 1.2.2 -release maintains source and binary compatibility with 1.2.0 and does -not make any API additions. - -Fix crashes with BGR X servers ------------------------------- -With cairo 1.2.0 many people reported problems with all cairo-using -programs, (including all GTK+ programs with GTK+ >= 2.8) immediately -crashing with a complaint about an unsupported image format. This bug -affected X servers that do not provide the Render extension and that -provide a visual with BGR rather than RGB channel order. - -report: https://bugs.freedesktop.org/show_bug.cgi?id=7294 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=9ae66174e774b57f16ad791452ed44efc2770a59 - -Fix the "disappearing text" bug -------------------------------- -With cairo 1.2.0 many people reported that text would disappear from -applications, sometimes reappearing with mouse motion or -selection. The text would disappear after the first space in a string -of text. This bug was caused by an underlying bug in (very common) X -servers, and only affected text rendered without antialiasing, (either -a bitmap font or a vector font with antialiasing disabled). The bug -was also exacerbated by a KDE migration bug that caused antialiasing -to be disabled more than desired. - -report: https://bugs.freedesktop.org/show_bug.cgi?id=7494 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=456cdb3058f3b416109a9600167cd8842300ae14 -see also: -Xorg: https://bugs.freedesktop.org/show_bug.cgi?id=7681 -KDE: http://qa.mandriva.com/show_bug.cgi?id=23990 - -Fix broken image fallback scaling (aka. "broken printing") ----------------------------------------------------------- -The various "print" backends, (pdf, ps, and svg), sometimes fallback -to using image-based rendering for some operations. In cairo 1.2.0 -these image fallbacks were scaled improperly. Applications using cairo -can influence the resolution of the image fallbacks with -cairo_surface_set_fallback_resolution. With the bug, any value other -than 72.0 would lead to incorrect results, (larger values would lead -to increasingly shrunken output). - -report: https://bugs.freedesktop.org/show_bug.cgi?id=7533 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=1feb4291cf7813494355459bb547eec604c54ffb - -Fix inadvertent semantic change of font matrix translation (Behdad Esfahbod) ----------------------------------------------------------------------------- -The 1.2.0 release introduced an inadvertent change to how the -translation components of a font matrix are interpreted. In the 1.0 -series, font matrix translation could be used to offset the glyph -origin, (though glyph metrics were reported incorrectly in -1.0). However in 1.2.0, the translation was applied to the advance -values between each glyph. The 1.2.0 behavior is fairly useless in -practice, and it was not intentional to introduce a semantic -change. With 1.2.2 we return to the 1.0 semantics, with a much better -implementation that provides correct glyph metrics. - -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=84840e6bba6e72aa88fad7a0ee929e8955ba9051 - -Fix create_similar to preserve fallback resolution and font options (Behdad Esfahbod) -------------------------------------------------------------------------------------- -There has been a long-standing issue with cairo_surface_create_similar -such that font options and other settings from the original -destination surface would not be preserved to the intermediate -"similar" surface. This could result in incorrect rendering -(particularly with respect to text hinting/antialiasing) with -fallbacks, for example. - -report: https://bugs.freedesktop.org/show_bug.cgi?id=4106 -fixes: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=9fcb3c32c1f16fe6ab913e27eb54d18b7d9a06b0 - http://gitweb.freedesktop.org/?p=cairo;a=commit;h=bdb4e1edadb78a2118ff70b28163f8bd4317f1ec - -xlib: Fix text performance regression from 1.0 to 1.2.0 (Vladimir Vukicevic) ----------------------------------------------------------------------------- -Several people noticed that upgrading from cairo 1.0 to cairo 1.2.0 -caused a significant performance regression when using the xlib -backend. This performance regression was particularly noticeable when -doing lots of text rendering and when using a high-latency connection -to the X server, (such as a remote X server over an ssh -connection). The slowdown was identified and fixed in 1.2.2. - -report: https://bugs.freedesktop.org/show_bug.cgi?id=7514 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=b7191885c88068dad57d68ced69a752d1162b12c - -PDF: Eliminate dependency on FreeType library dependency (Adrian Johnson) -------------------------------------------------------------------------- -The cairo 1.2 series adds a supported pdf backend to cairo. In cairo -1.2.0 this backend required the freetype library, which was an -undesirable dependency on systems such as win32, (cairo is designed to -always prefer the "native" font system). As of cairo 1.2.2 the -freetype library is not required to use the pdf backend on the win32 -platform. - -report: https://bugs.freedesktop.org/show_bug.cgi?id=7538 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=a0989f427be87c60415963dd6822b3c5c3781691 - -PDF: Fix broken output on amd64 (Adrian Johnson) ------------------------------------------------- -report: http://bugzilla.gnome.org/show_bug.cgi?id=349826 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=f4b12e497b7ac282b2f6831b8fb68deebc412e60 - -PS: Fix broken output for truetype fonts > 64k (Adrian Johnson) ---------------------------------------------------------------- -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=067d97eb1793a6b0d0dddfbd0b54117844511a94 - -PDF: Fix so that dashing doesn't get stuck on (Kent Worsnop) ------------------------------------------------------------- -Kent notices that with the PDF backend in cairo 1.2.0 as soon as a -stroke was performed with dashing, all subsequent strokes would also -be dashed. There was no way to turn dashing off again. - -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=778c4730a86296bf0a71080cf7008d7291792256 - -Fix memory leaks in failure paths in gradient creation (Alfred Peng) --------------------------------------------------------------------- -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=db06681b487873788b51a6766894fc619eb8d8f2 - -Fix memory leak in _cairo_surface_show_glyphs (Chris Wilson) ------------------------------------------------------------- -report: https://bugs.freedesktop.org/show_bug.cgi?id=7766 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=e2fddcccb43d06486d3680a19cfdd5a54963fcbd - -Solaris: Add definition of cairo_private for some Sun compilers (Alfred Peng) ------------------------------------------------------------------------------ -report: https://bugzilla.mozilla.org/show_bug.cgi?id=341874 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=04757a3aa8deeff3265719ebe01b021638990ec6 - -Solaris: Change version number of Sun's Xorg server with buggy repeat (Brian Cameron) -------------------------------------------------------------------------------------- -report: https://bugs.freedesktop.org/show_bug.cgi?id=7483 -fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=e0ad1aa995bcec4246c0b8ab0d5a5a79871ce235 - -Various memory leak fixes -------------------------- -Fix memory leak in _cairo_surface_show_glyphs (bug 7766) -Fix file handle leak in failure path (bug 7616) -Fix some memory leaks in the test cases. -Fix some memory leaks in font subsetting code used in print backends. - -Documentation improvements (Behdad Esfahbod) --------------------------------------------- -Added new documentation for several functions (cairo_show_page, -cairo_copy_page, cairo_in_stroke, cairo_in_fill). - -Fixed some syntax errors that were preventing some existing -documentation from being published. - -Fixed several minor typographical errors. - -Added an index for new symbols in 1.2. - -Release 1.2.0 (2006-06-27 Carl Worth ) -========================================================= -This is the culmination of the work that has gone on within the 1.1 -branch of cairo. - -There has been one API addition since the cairo 1.1.10 snapshot: - - cairo_xlib_surface_get_width - cairo_xlib_surface_get_height - -There's also a new feature without any API change: - - Dots can now be drawn by using CAIRO_LINE_CAP_ROUND with - degenerate sub-paths, (cairo_move_to() followed by either - cairo_close_path() or a cairo_line_to() to the same location). - -And at least the following bugs have been fixed: - - 6759 fontconfig option AntiAlias doesn't work in cairo 1.1.2 - 6955 Some characters aren't displayed when using xlib (cache u... - 7268 positive device_offset values don't work as source - * PDF emit_glyph function needs to support bitmapped glyphs - * PS emit_glyph function needs to support bitmapped glyphs - * SVG emit_glyph function needs to support bitmapped glyphs - * PDF: minefield page one is falling back unnecessarily - * PS/PDF: Fix broken placement for vertical glyphs - * PS: Fix to not draw BUTT-capped zero-length dash segments - * Do device offset before float->fixed conversion - http://bugzilla.gnome.org/show_bug.cgi?id=332266 - * PS: Fix source surfaces with transformations - * PS: Fix to not draw BUTT-capped degnerate sub-paths - * PS: Don't walk off end of array when printing "~>" - * Fix some memory leaks in the test suite rig - * SVG: Fix memory leak when using cairo_mask - * Fix EXTEND_REFLECT and EXTEND_PAD to not crash (though these are - still not yet fully implemented for surface patterns). - -This has been a tremendous effort by everyone, and I'm proud to have -been a part of it. Congratulations to all contributors to cairo! - -Snapshot 1.1.10 (2006-06-16 Carl Worth ) -=========================================================== -This is the fifth in a series of snapshots working toward the 1.2 -release of cairo. - -The primary motivation for this snapshot is to fix a long-standing bug -that had long been silent, but as of the 1.1.8 snapshot started -causing crashes when run against 16-bit depth X servers, (often Xvnc -or Xnest). The fix for this adds a new CAIRO_FORMAT_RGB16_565 to the -API. - -This snapshot also includes a rewrite of cairo's SVG backend to -eliminate the dependency on libxml2. With this in place, cairo 1.2 -will not depend on any libraries that cairo 1.0 did not. - -As usual, there are also a few fixes for minor bugs. - -Snapshot 1.1.8 (2006-06-14 Carl Worth ) -========================================================== -This is the fourth in a series of snapshots working toward the 1.2 -release of cairo. At this point, all major features of the 1.2 release -are in place, leaving just a few bug fixes left. - -In particular, there well be no additional API changes between this -1.1.8 snapshot and the 1.2 release. - -The announcement for 1.1.6 mentioned several API changes being -considered. Only one of these changes was actually implemented -(set_dpi -> fallback_resolution). This change does introduce one -source-level incompatibility with respect to previous 1.1.x snapshots, -so see below for details. - -Here is an abbreviated summary of changes since the 1.1.6 snapshot: - -** API Change ** ----------------- -According to the plan mentioned in the 1.1.6 notes, one source-level -incompatible change has been implemented. The following three -functions have been removed from cairo's API: - - cairo_pdf_surface_set_dpi - cairo_ps_surface_set_dpi - cairo_svg_surface_set_dpi - -and in their place the following function has been added: - - cairo_surface_set_fallback_resolution - -The signature and semantics of the function remains the same, so it is -a simple matter of changing the name of the function when calling -it. As a transition mechanism, this snapshot will (on many systems) -build to include the old symbols so that code previously compiled will -still run. However, all source code using the old names must be -updated before it will compile. And the upcoming 1.2 release is not -anticipated to include the old symbols. - -Finally, it should be pointed out that the old symbols never existed -in the supported API of any stable release of cairo. (In the stable -1.0 releases the PDF, PS, and SVG backends were advertised as -experimental and unstable.) - -And, as always, cairo continues to maintain source and binary -compatibility between major releases. So applications compiled against -supported backends in a stable release of cairo (1.0.4 say) will -continue to compile and run without modification against new major -releases (1.2.0 say) without modification. - -API additions -------------- -The following new functions have been added to cairo's API: - - cairo_surface_get_content - cairo_debug_reset_static_data - cairo_image_surface_get_data - cairo_image_surface_get_format - cairo_image_surface_get_stride - cairo_win32_font_face_create_for_hfont - -New, backend-specific pkg-config files --------------------------------------- -In addition to the original cairo.pc file, cairo will also now install -a pkg-config files for each configured backend, (for example -cairo-pdf.pc, cairo-svg.pc, cairo-xlib.pc, cairo-win32.pc, etc.) this -also includes optional font backends (such as cairo-ft.pc) and the -optional png functionality (cairo-png.pc). - -These new pkg-config files should be very convenient for allowing -cairo-using code to easily check for the existing of optional -functionality in cairo without having to write complex rules to grub -through cairo header files or the compiled library looking for -symbols. - -Printing backend (PS, PDF, and SVG) ------------------------------------ -Improving the quality of the "printing" backends has been a priority -of the development between cairo 1.1.6 and cairo 1.1.8. - -The big improvement here is in the area of text output. Previously, at -best, text was output as paths without taking advantage of any font -support available in the output file format. - -Now, at the minimum text paths will be shared by using type3 fonts -(for PS and PDF---and similarly, defs for SVG). Also, if possible, -type3 and truetype fonts will be embedded in PostScript and PDF -output. There are still some known bugs with this, (for example, -selecting text in a cairo-generated PDF file with an embedded truetype -font does not work). So there will be some more changes in this area -before cairo 1.2, but do try test this feature out as it exists so -far. - -Many thanks to Kristian Høgsberg for the truetype and type1 font -embedding. - -win32 backend -------------- -Performance improvements by preferring GDI over pixman rendering when possible. -Fixes for text rendering. - -xlib backend ------------- -Fix potentially big performance bug by making xlib's create_similar -try harder to create a pixmap of a depth matching that of the screen. - -Bug fixes ---------- -Among various other fixes, the following bugs listed in bugzilla have -been fixed: - - Bug 2488: Patch to fix pixman samping location bug (#2488). - https://bugs.freedesktop.org/show_bug.cgi?id=2488 - - Bug 4196: undef MIN an MAX before defining to avoid duplicate definition - https://bugs.freedesktop.org/show_bug.cgi?id=4196 - - Bug 4723: configure.in: Fix m4 quoting when examining pkg-config version - https://bugs.freedesktop.org/show_bug.cgi?id=4723 - - Bug 4882: Flag Sun's X server has having buggy_repeat. - https://bugs.freedesktop.org/show_bug.cgi?id=4882 - - Bug 5306: test/pdf2png: Add missing include of stdio.h - https://bugs.freedesktop.org/show_bug.cgi?id=5306 - - Bug 7075: Fix make clean to remove cairo.def - https://bugs.freedesktop.org/show_bug.cgi?id=7075 - -(Many thanks to Behdad Esfahbod for helping us track down and fix many -of these.) - -Snapshot 1.1.6 (2006-05-04 Carl Worth ) -========================================================== -This is the third in a series of snapshots working toward the imminent -1.2 release of cairo. For a list of items still needing work on the -cairo 1.2 roadmap, please see: - - http://cairographics.org/ROADMAP - -As can be seen in that list, there are no longer any API additions -left on the roadmap. Instead, there is a feature (PDF type 3 fonts) a -performance optimization (X server gradients) and a list of bug -fixes. This gives us a fair amount of freedom to cut the 1.2 release -at almost any point by deciding to defer remaining bug fixes to -subsequent maintenance releases such as 1.2.2 and 1.2.4. - -Before we will do that, we must first be wiling to commit to all the -new API additions. As a heads-up, there are a couple of potential API -changes being considered. (Note that these are changes to new API -introduced during 1.1 so these will not introduce API -incompatibilities compared to the stable 1.0 series). The changes -being considered are: - - cairo_get_group_target: may acquire x and y offset return - parameters. May also be eliminated in favor of - cairo_get_target assuming its role - - cairo_pdf_surface_set_dpi: - cairo_ps_surface_set_dpi: - cairo_svg_surface_set_dpi: These functions may be removed in favor - of a new cairo_surface_set_fallback_resolution - -Additionally there is the possibility of a slight change in the -semantics of cairo_set_line_width. We believe the current behavior of the sequence: - - cairo_set_line_width; ... change CTM ...; cairo_stroke; - -is buggy. It is currently behaving the same as: - - ... change CTM ...; cairo_set_line_width; cairo_stroke; - -We are considering fixing this bug before 1.2 with the hope that -nobody is already relying on the buggy behavior described here. Do -shout if you suspect you might be in that position. - -The items included in this snapshot (since the 1.1.4 snapshot) are -described below. - -API additions -------------- -The long-awaited group-rendering support is now available with the -following function calls: - - cairo_push_group - cairo_push_group_with_content - cairo_pop_group - cairo_pop_group_to_source - cairo_get_group_target - -This API provides a much more convenient mechanism for doing rendering -to an intermediate surface without the need to manually create a -temporary cairo_surface_t and a temporary cairo_t and clean them up -afterwards. - -Add the following missing get function to complement -cairo_surface_set_device_offset: - - cairo_surface_get_device_offset - -PDF backend (API addition) --------------------------- -The PDF backend now provides for per-page size changes, (similar to -what the PostScript backend got in the 1.1.4 snapshot). The new API -is: - - cairo_pdf_surface_set_size - -Xlib backend (API additions) ----------------------------- -The following functions have been added to allow the extraction of -Xlib surface: - - cairo_xlib_surface_get_display - cairo_xlib_surface_get_drawable - cairo_xlib_surface_get_screen - cairo_xlib_surface_get_visual - cairo_xlib_surface_get_depth - -XCB backend (experimental) --------------------------- -Update backend so that it now compiles with the recent XCB 0.9 release. - -Bug fixes and memory leak cleanup ---------------------------------- -Various little things, nothing too significant though. - -Snapshot 1.1.4 (2006-05-03 Carl Worth ) -========================================================== -This is the second in a series of snapshots working toward the -upcoming 1.2 release of cairo. For a list of items still needing work -on the cairo 1.2 roadmap, please see: - - http://cairographics.org/ROADMAP - -The items included in this snapshot (since the 1.1.2 snapshot) are -described below. - -PostScript backend: new printing-oriented API ---------------------------------------------- -We anticipate that with cairo 1.2, toolkits will begin to use cairo -for printing on systems that use PostScript as the spool format. To -support this use case, we have added 4 new function calls that are -specific to the PostScript backend: - - cairo_ps_surface_set_size - cairo_ps_surface_dsc_comment - cairo_ps_surface_dsc_begin_setup - cairo_ps_surface_dsc_begin_page_setup - -These functions allow variation of the page size/orientation from one -page to the next in the PostScript output. They also allow the toolkit -to provide per-document and per-page printer control options in a -device-independent way, (for example, by using PPD options and -emitting them as DSC comments into the PostScript output). This should -allow toolkits to provide very fine-grained control of many options -available in printers, (media size, media type, tray selection, etc.). - -SVG backend: builds by default, version control ------------------------------------------------ -The SVG backend continues to see major improvements. It is expected -that the SVG backend will be a supported backend in the 1.2 -release. This backend will now be built by default if its dependencies -(freetype and libxml2) are met. - -Additionally, the SVG backend now has flexibility with regard to what -version of SVG it targets. It will target SVG 1.1 by default, which -will require image fallbacks for some of the "fancier" cairo -compositing operators. Or with the following new function calls: - - cairo_svg_surface_restrict_to_version - cairo_svg_get_versions - cairo_svg_version_to_string - -it can be made to target SVG 1.2 in which there is native support for -these compositing operators. - -Bug fixes ---------- -At least the following bugs have been fixed since the 1.1.2 snapshot: - -crash at XRenderAddGlyphs -https://bugs.freedesktop.org/show_bug.cgi?id=4705 - -Can't build cairo-1.1.2 on opensolaris due to " void function cannot return value" -https://bugs.freedesktop.org/show_bug.cgi?id=6792 - -Missing out-of-memory check at gfx/cairo/cairo/src/cairo-atsui-font.c:185 -https://bugzilla.mozilla.org/show_bug.cgi?id=336129 - -A couple of memory leaks. - -Snapshot 1.1.2 (2006-04-25 Carl Worth ) -========================================================== -This is the first in a series of snapshots working toward the upcoming -1.2 release of cairo. (Subsequent snapshot will use successive even -numbers for the third digit, 1.1.4, 1.1.6, etc.) This snapshot is -backwards-compatible with the 1.0 series---it makes a few API -additions but does not remove any API. - -PostScript and PDF backends are no longer "experimental" --------------------------------------------------------- -The major theme of the 1.2 release is improved PostScript and PDF -backends for cairo. Unlike the 1.0 series, in the 1.2 series these -backends will not be marked as experimental and will be enabled by -default. We encourage people to test this snapshot and the PS/PDF -backends in particular as much as possible. - -The PostScript and PDF output is not yet ideal. - - * One major problem with the PostScript output is that image - fallbacks are used more often than strictly necessary, and the - image fallbacks are at a lower resolution than desired, (the - cairo_ps_surface_set_dpi call is ignored). - - * The major drawback of the current PDF backend implementation is - its text support. Every glyph is represented by a filled path in - the PDF file. The causes file sizes to be much larger and - rendering to be much slower than desired. - -It is anticipated that both of these shortcomings will see some -improvements before the final 1.2 release. - -In spite of those shortcomings, we hope that the PS and PDF backends -will yield faithful results for pretty much any cairo operations you -can throw at them. Please let us know if you are getting obviously -"different" results from the PS/PDF backends than from the image or -xlib backends. - -Other new experimental backends -------------------------------- -This snapshot includes three new backends that did not exist in the -1.0 series: - - * beos backend - - * directfb backend - - * svg backend - -These are all currently marked "experimental" and are disabled by -default. But the SVG backend in particular has seen a lot of recent -development and is very close to passing the entire cairo test -suite. It is possible that this backend will become a fully supported -backend by the time of the cairo 1.2 release. - -Public API additions --------------------- -There have been a few new API functions added to cairo, including: - -New get_type functions for querying sub-types of object: - - cairo_surface_get_type - cairo_pattern_get_type - cairo_font_face_get_type - cairo_scaled_font_get_type - -More convenience in working with cairo_scaled_font_t with new getter -functions: - - cairo_scaled_font_get_font_face - cairo_scaled_font_get_font_matrix - cairo_scaled_font_get_ctm - cairo_scaled_font_get_font_options - -As well as a convenience function for setting a scaled font into a -cairo context: - - cairo_set_scaled_font - -and a function to allow text extents to be queried directly from a -scaled font, (without requiring a cairo_surface_t or a cairo_t): - - cairo_scaled_font_text_extents - -These new scaled font functions were motivated by the needs of the -pango library. - -Finally, a new path-construction function was added which clears the -current point in preparation for a new sub path. This makes cairo_arc -easier to use in some situations: - - cairo_new_sub_path - -Before the 1.2 release is final we do still plan a few more API -additions specifically motivated by the needs of Mozilla/Firefox. - -Optimizations and bug fixes ---------------------------- -Shortly after the 1.0 maintenance series branched off the mainline -there was a major rework of the cairo font internals. This should -provide some good performance benefits, but it's also another area -people should look at closely for potential regressions. - -There has not yet been any widespread, systematic optimization of -cairo, but various performance improvements have been made, (and some -of them are fairly significant). So if some things seem faster than -1.0 then things are good. If there are any performance regressions -compared to 1.0 then there is a real problem and we would like to hear -about that. - -There has been a huge number of bug fixes---too many to mention in -detail. Again, things should be better, and never worse compared to -1.0. Please let us know if your testing shows otherwise. - -Release 1.0.2 (2005-10-03 Carl Worth ) -========================================================= -For each bug number XXXX below, see: - - https://bugs.freedesktop.org/show_bug.cgi?id=XXXX - -for more details. - -General bug fixes ------------------ - * 4408 - Add support for dashing of stroked curves - (Carl Worth) - - * 4409 - Fix dashing so that each dash is capped on both ends - (Carl Worth) - - * 4414 - Prevent SIGILL failures (proper use of -mmmx and -msse flags) - (Sebastien Bacher, Billy Biggs) - - * 4299 - Fix crashes with text display in multi-threaded program - (Alexey Shabalin, Carl Worth) - - * 4401 - Do not use sincos function since it is buggy on some platforms) - (Tim Mooney, Carl Worth) - - * 4245 - Fix several bugs in the test suite exposed by amd64 systems - (Seemant Kulleen, Carl Worth) - - * 4321 - Add missing byteswapping on GetImage/PutImage - (Sjoerd Simons, Owen Taylor) - - * 4220 - Make the check for rectangular trapezoids simpler and more accurate - (Richard Stellingwerff, Owen Taylor) - - * 4260 - Add missing channel-order swapping for antialised fonts - (Barbie LeVile, Owen Taylor) - - * 4283 - Fix compilation failure with aggressive inlining (gcc -O3) - (Marco Manfredini, Owen Taylor) - - * 4208 - Fix some warnings from sparse - (Kjartan Maraas, Billy Biggs) - - * 4269 - Fix to not crash when compiled with -fomit-frame-pointer - (Ronald Wahl, Owen Taylor) - - * 4263 - Improve performance for vertical gradients - (Richard Stellingwerff, Owen Taylor) - - * 4231 - * 4298 - Accomodate gentoo and Mandriva versions in X server vendor string check - (Billy Biggs, Frederic Crozat, Owen Taylor) - -win32-specific fixes --------------------- - * 4599 - Fix "missing wedges" on some stroked paths (win32) - (Tim Rowley, Jonathan Watt, Bertram Felgenhauer, Carl Worth, Keith Packard) - - * 4612 - Fix disappearing text if first character out of surface (win32) - (Tim Rowley) - - * 4602 - Fix shutdown of cairo from failing intermediate, size-0 bitmaps (win32) - Aka. the "white rectangles" bug from mozilla-svg testing - (Tim Rowley) - - * Various portability improvements for win32 - (Hans Breuer, Owen Taylor, Carl Worth) - - * 4593 - Fix font sizes to match user expectations (win32) - (Tor Lillqvist, Owen Taylor) - - * 3927 - Fix to report metrics of size 0 for glyph-not-available (win32) - (Hans Breuer, Owen Taylor, Tor Lillqvist) - - * Add locking primitives for win32 - (Hans Breuer) - -xlib-specific fixes -------------------- - * Fix crash from size-0 pixmap due to empty clip region (xlib) - (Radek Doulík, Carl Worth) - -Release 1.0.0 (2005-08-24 Carl Worth ) -========================================================= -Experimental backends ---------------------- - * The Glitz, PS, PDF, Quartz, and XCB backends have been declared - experimental, and are not part of the API guarantees that accompany - this release. They are not built by default, even when the required - libraries are available, and must be enabled explicitly with - --enable-ps, --enable-pdf, --enable-quartz or --enable-xcb. - - It is very painful for us to be pushing out a major release without - these backends enabled. There has been a tremendous amount of work - put into each one and all are quite functional to some - extent. However, each also has some limitations. And none of these - backends have been tested to the level of completeness and - correctness that we expect from cairo backends. - - We do encourage people to experiment with these backends and report - success, failure, or means of improving them. - -Operator behavior ------------------ - * Prior to 0.9.0 the SOURCE, CLEAR and a number of other operators - behaved in an inconsistent and buggy fashion and could affect areas - outside the clip mask. In 0.9.0, these six "unbounded" operators - were fixed to consistently clear areas outside the shape but within - the clip mask. This is useful behavior for an operator such as IN, - but not what was expected for SOURCE and CLEAR. So, in this release - the behavior of SOURCE and CLEAR has been changed again. They now - affect areas only within both the source and shape. We can write - the new operators as: - - SOURCE: dest' = (mask IN clip) ? source : dest - CLEAR: dest' = (mask IN clip) ? 0 : dest - -Behavior and API changes ------------------------- - * Setting the filter on a gradient pattern would change the - interpolation between color stops away from the normal linear - interpolation. This dubious behavior has been removed. - - * The CAIRO_CONTENT_VALID() and CAIRO_FORMAT_VALID() macros -- - implementation details that leaked into cairo.h -- have been moved - into an internal header. - - * The cairo_show_text function now advances the current point - according to the total advance values of the string. - -API additions -------------- - * cairo_set_dash can now detect error and can set - CAIRO_STATUS_INVALID_DASH. - -Features --------- - * When compiled against recent versions of fontconfig and FreeType, - artificial bold fonts can now be turned on from fonts.conf using - the FC_EMBOLDEN fontconfig key. - -Optimization ------------- - * The compositing code from the 'xserver' code tree has now been - completely merged into libpixman. This includes MMX optimization of - common operations. - - * The image transformation code in libpixman has been improved and - now performs significantly faster. - -Bug fixes ---------- - * Several crashes related to corruption in the font caches have been - fixed. - - * All test cases now match pixel-for-pixel on x86 and PPC; this - required fixing bugs in the compositing, stroking, and pattern - rendering code. - - * Negative dash offsets have been fixed to work correctly. - - * The stroking of paths with mutiple subpaths has now been fixed to - apply caps to all subpaths rather than just the last one. - - * Many build fixes for better portability on various systems. - - * Lots of other bug fixes, but we're too tired to describe them in - more detail here. - -Release 0.9.2 (2005-08-13 Carl Worth ) -========================================================= -Release numbering ------------------ - * You will notice that this release jumped from 0.9.0 to 0.9.2. We've - decided to use an odd micro version number (eg. 0.9.1) to indicate - in-progress development between releases. As soon as 0.9.2 is - tagged, the version will be incremented in CVS to 0.9.3 where it - will stay until just before 0.9.4 is built, uploaded, and tagged. - - So, even-micro == a released version, odd-micro == something in-between. - -Libpixman dependency dropped ----------------------------- - * As of this release, the dependency on an external libpixman has - been dropped. Instead, the code from libpixman needed for cairo has - been incorporated into the cairo source tree. The motivation for - this change is that while cairo's API is stable and ready to be - maintained after the 1.0 release, libpixman's API is not, so we do - not want to expose it at this time. - - Also, the incorporation of libpixman into cairo also renames all - previously-public libpixman symbols in order to avoid any conflict - with a future release of libpixman - -API additions -------------- - * Macros and functions have been added so that the version of cairo - can be queried at either compile-time or at run-time. The version - is made available as both a human-readable string and as a single - integer: - - CAIRO_VERSION_STRING eg. "0.9.2" - CAIRO_VERSION eg. 000902 - - const char* - cairo_version_string (void); /* eg. "0.9.2" */ - - int - cairo_version (void); /* eg. 000902 */ - - A macro is provided to convert a three-part component version into - the encoded single-integer form: - - CAIRO_VERSION_ENCODE(X,Y,Z) - - For example, the CAIRO_VERSION value of 000902 is obtained as - CAIRO_VERSION_ENCODE(0,9,2). The intent is to make version - comparisons easy, either at compile-time: - - #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(0,9,2) - ... - #endif - - Or at run-time: - - if (cairo_version() >= CAIRO_VERSION_ENCODE(0,9,2)) { /* ... */ } - -Thread safety -------------- - * This release adds pthread-based locking (when available) to make - the caches used by cairo safe for threaded programs. Some may - remember a failed experiment with this locking between the 0.5.1 - and 0.5.2 snapshots, (where even single-threaded programs that - linked with -lpthread would deadlock). We believe that that problem - has been fixed, so we are looking forward to testing and reports - from users with threaded applications. - -Bug fixes ---------- - * The XCB and Quartz backends failed to compiled in the 0.9.0 release - due to minor syntax errors. These have now been fixed. - - * Various crashes in glitz and pixman due to size 0 glyphs have been - fixed. - -Release 0.9.0 (2005-08-08 Carl Worth ) -========================================================= -Soname change -------------- - * In all prior snapshots, the libtool library versioning was set to - 1:0:0. As this release is intended to mark the beginning of - backwards-compatible releases, the versioning has been incremented - to 2:0:0. You will notice that the numeric extension on the - installed library filename will change similarly. - - This change will also require all cairo-using applications to be - recompiled. We recognize that this may cause some frustration since - this release is backwards-compatible with 0.6.0 and in that sense - "shouldn't" require re-compilation. However, since all historical - snapshots have used the same 1:0:0 version in spite of incompatible - API changes between them, it was essential that the upcoming 1.0 - release series have distinct library versioning. - - All future releases will use the library versioning to properly - indicate compatibility between releases. So, any application - re-compiled now to work with the 0.9.0 will not need to be - recompiled when a compatible 1.0 release of cairo is made in the - future. - -API additions -------------- - * Add new function calls to set/get the current antialiasing mode in - the graphics state: - - cairo_set_antialias - cairo_get_antialias - - This call accepts the same modes recently added for font options - (NONE or GRAY) but affects the rendering of geometry other than - text. The intent of this call is to enable more precise control of - which pixels are affected by each operation, for example to allow - for full-scene antialiasing for seam-free rendering. It is not - expected that non-antialiased rendering will perform better than - anti-aliased rendering. - - * Three new functions were added to provide support for mixed cairo- - and non-cairo drawing to the same surface: - - cairo_surface_mark_dirty - cairo_surface_mark_dirty_rectangle - cairo_surface_flush - - * The return type of the several "reference" functions was change, - (API compatibly), from void to the same type as the argument. The - affected functions are: - - cairo_font_face_reference - cairo_scaled_font_reference - cairo_pattern_reference - cairo_surface_reference - cairo_reference - - This allows a convenient way to assign and reference in a single - statement. - -Semantic changes ----------------- - * The behavior of cairo_set_source with a pattern with a non-identity - matrix was previously not well-defined. The new behavior is as - follows: - - The pattern's transformation matrix will be locked to the - user space in effect at the time of cairo_set_source(). This means - that further modifications of the CTM will not affect the source - pattern. - -cairo-win32 ------------ - * Some portability improvements, (eg. workaround for missing stdint.h). - -cairo-ft --------- - * Updated to allow compilation with older versions of freetype. - -Bug fixes ---------- - * Fix the unbounded operators to actually produce a correct result, - (previously the results were artificially restricted to the - bounding box of whatever shape was being drawn rather than - extending out infinitely). The fixed operators are: - - CAIRO_OPERATOR_CLEAR - CAIRO_OPERATOR_SOURCE - CAIRO_OPERATOR_OUT - CAIRO_OPERATOR_IN - CAIRO_OPERATOR_DEST_IN - CAIRO_OPERATOR_DEST_ATOP - - * Fix cairo_mask and cairo_mask_surface to transform the mask by the - current transformation matrix (CTM). - - * Fix cairo_set_source to lock the CTM used to transform the pattern. - - * Workaround for X server Render bug involving repeating patterns - with a general transformation matrix. - - * cairo_get_font_face fixed to return a "nil" font face object rather - than NULL on error. - - * cairo_set_font_face fixed to not crash if given a NULL font face, - (which is the documented interface for restoring the default font - face). - - * Fix xlib glyphset caching to not try to free a NULL glyph. - -Snapshot 0.6.0 (2005-07-28 Carl Worth ) -========================================================== -API changes ------------ -* The prototypes of the following functions have changed: - - cairo_xlib_surface_create_with_xrender_format - cairo_xlib_surface_create_for_bitmap - - A Screen* parameter has been added to each. This allows the cairo - xlib backend to work correctly with multi-head X servers. - -* The following function has been modified: - - cairo_scaled_font_create - - to accept a cairo_font_options_t*. See below fore more details. - -* All opaque, reference-counted cairo objects have now been moved to a - standard error-handling scheme. The new objects to receive this - treatment are cairo_font_face_t, cairo_scaled_font_t, and - cairo_surface_t. (Previous snapshots already provided this scheme - for cairo_t, cairo_path_t, and cairo_pattern_t.) - - This changes two functions to have a return type of void rather than - cairo_status_t: - - cairo_scaled_font_extent - cairo_surface_finish - - And significantly, none of the create functions for any of the - objects listed above will return NULL. The pointer returned from any - function will now always be a valid pointer and should always be - passed to the corresponding destroy function when finished - - The simplest strategy for porting code is to switch from: - - object = cairo__create (); - if (object == NULL) - goto BAILOUT; - - /* act on object */ - - cairo__destroy (object); - - to: - - object = cairo__create (); - if (cairo__status (object)) - goto BAILOUT; - - /* act on object */ - - cairo__destroy (object); - - But significantly, it is not required to check for an error status - before the "act on object" portions of the code above. All - operations on an object with an error status are, by definition, - no-ops without side effect. So new code might be written in an - easier-to-read style of: - - object = cairo__create (); - - /* act on object */ - - cairo__destroy (object); - - with cairo__status checks placed only at strategic - locations. For example, passing an error object to another object, - (eg. cairo_set_source with an in-error pattern), will propagate the - error to the subsequent object (eg. the cairo_t). This means that - error checking can often be deferred even beyond the destruction of - a temporary object. - -API additions -------------- -* New functions for checking the status of objects that have been - switched to the common error-handling scheme: - - cairo_font_face_status - cairo_scaled_font_status - cairo_surface_status - -* The _cairo_error function which was added in 0.5.1 has now been made - much more useful. In 0.5.1 only errors on cairo_t objects passed - through _cairo_error. Now, an error on any object should pass - through _cairo_error making it much more reliable as a debugging - mechanism for finding when an error first occurs. - -* Added new font options support with a myriad of functions: - - cairo_font_options_create - cairo_font_options_copy - cairo_font_options_destroy - - cairo_font_options_status - - cairo_font_options_merge - cairo_font_options_equal - cairo_font_options_hash - - cairo_font_options_set_antialias - cairo_font_options_get_antialias - cairo_font_options_set_subpixel_order - cairo_font_options_get_subpixel_order - cairo_font_options_set_hint_style - cairo_font_options_get_hint_style - cairo_font_options_set_hint_metrics - cairo_font_options_get_hint_metrics - - cairo_surface_get_font_options - - cairo_ft_font_options_substitute - - cairo_set_font_options - cairo_get_font_options - - This new font options support allows the application to have much - more fine-grained control over how fonts are rendered. - Significantly, it also allows surface backends to have some - influence over the process. For example, the xlib backend now - queries existing Xft properties to set font option defaults. - -* New function: - - cairo_xlib_surface_set_drawable - - which allows the target drawable for an xlib cairo_surface_t to be - changed to another with the same format, screen, and display. This - is necessary in certain double-buffering techniques. - -New features ------------- -* Sub-pixel text antialiasing is now supported. - -Bug fixes ---------- -* Fixed assertion failure in cairo_surface_create_similar when - application commits an error by passing a cairo_format_t rather than - a cairo_content_t. - -* Avoid division by zero in various places (cairo-ft). - -* Fix infinite loop when using non-default visuals (cairo-xlib). - -* Eliminate segfault in cairo_image_surface_create_from_png_stream. - -* Prevent errant sign-extension of masks on 64-bit architectures - (cairo-xlib and cairo-xcb). - -* Other miscellaneous fixes. - -Snapshot 0.5.2 (2005-07-18 Carl Worth ) -========================================================== -API changes ------------ -* New functions for creating patterns of a single color: - - cairo_pattern_create_rgb - cairo_pattern_create_rgba - -* Change cairo_surface_create_similar to accept a new type of - cairo_content_t rather than cairo_format_t: - - typedef enum _cairo_content { - CAIRO_CONTENT_COLOR = 0x1000, - CAIRO_CONTENT_ALPHA = 0x2000, - CAIRO_CONTENT_COLOR_ALPHA = 0x3000 - } cairo_content_t; - -* Add new CAIRO_FORMAT_VALID and CAIRO_CONTENT_VALID macros. - -* Remove unused status value: - - CAIRO_STATUS_NO_TARGET_SURFACE - -* Add new status values: - - CAIRO_STATUS_INVALID_STATUS - -* Require libpixman >= 0.1.5 (for necessary bug fixes) - -Bug fixes ---------- -* Fix cairo_surface_write_to_png for RGB24 images. - -* Fix broken metrics and rendering for bitmap fonts. Add mostly - useless bitmap glyph transformation. - -* Fix glyph caches to not eject entries that might be immediately - needed, (fixing intermittent crashes when rendering text). - -* Fix all memory leaks found by running "make check-valgrind". - -ATSUI backend changes ---------------------- -* Allow building against < 10.3 SDK. - -* Prevent crash on empty strings. - -Glitz backend changes ---------------------- -* Require glitz >= 0.4.4. - -* Use frame buffer objects instead of pbuffers for accelerated - offscreen drawing. - -* Minor improvement to gradient pattern creation. - -PostScript backend fixes ------------------------- -* Rewrite of the PS backend to generate more interesting output that - the old big-image implementation. - -Win32 backend fixes -------------------- -* Implement glyph path support. - -* Fix swap of blue and green values in the fill_rectangles path. - -Xlib backend fixes ------------------- -* Add optimization to use XCopyArea rather than XRenderComposite when - transforming only with an integer translation, and using SOURCE - operator or OVER with a source pattern without alpha. - -Snapshot 0.5.1 (2005-06-20 Carl Worth ) -========================================================== -API changes ------------ -* Removed cairo_status_string(cairo_t*) and add - cairo_status_to_string(cairo_status_t) in its place. Code using - cairo_status_string can be ported forward as follows: - - cairo_status (cr); - -> - cairo_status_to_string (cairo_status (cr)); - -* Removed the BAD_NESTING restriction which means that two different - cairo_t objects can now interleave drawing to the same - cairo_surface_t without causing an error. - -* The following functions which previously had a return type of - cairo_status_t now have a return type of void: - - cairo_pattern_add_color_stop_rgba - cairo_pattern_set_matrix - cairo_pattern_get_matrix - cairo_pattern_set_extend - cairo_pattern_set_filter - - See discussion of cairo_pattern_status below for more details. - -API additions -------------- -* Improved error handling: - - cairo_status_t - cairo_pattern_status (cairo_pattern_t *pattern); - - This snapshot expands the status-based error handling scheme from - cairo_t to cairo_path_t and cairo_pattern_t. It also expands the - scheme so that object-creating functions, (cairo_create, - cairo_pattern_create_*, cairo_copy_path_*), are now guaranteed to - not return NULL. Instead, in the case of out-of-memory these - functions will return a static object with - status==CAIRO_STATUS_NO_MEMORY. The status can be checked with the - functions cairo_status and cairo_pattern_status, or by direct - inspection of the new status field in cairo_path_t. - - Please note that some objects, including cairo_surface_t and all of - the font-related objects have not been converted to this - error-handling scheme. - -* In addition to the above changes, a new private function has been added: - - _cairo_error - - This function can be used to set a breakpoint in a debugger to make - it easier to find programming error in cairo-using code. (Currently, - _cairo_error is called when any error is detected within a cairo_t - context, but is not called for non-cairo_t errors such as for - cairo_path_t and cairo_pattern_t). - -* Fixed cairo_path_data_t so that its enum is visible to C++ code, (as - cairo_path_data_type_t). - -Performance improvements ------------------------- -* Made a minor performance improvement for clipping, (restrict clip - surface to the new intersected bounds). - -* Optimize rendering of a solid source pattern with a pixel-aligned - rectangular path to use backend clipping rather than rasterization - and backend compositing. - -* Optimize cairo_paint_with_alpha to defer to cairo_paint when alpha - is 1.0. - -Bug fixes ---------- -* Fixed memory leak in cairo_copy_path. - -* A build fix for non-srcdir builds. - -PDF backend fixes ------------------ -* New support for path-based clipping. - -* Fix for text rotated to angles other than multiples of π/2. - -Win32 backend fixes -------------------- -* Fix for text extents. - -Xlib backend ------------- -* Implemented a complex workaround for X server bug[*] related to - Render-based compositing with untransformed, repeating source - pictures. The workaround uses core Xlib when possible for - performance, (ie. with CAIRO_OPERATOR_SOURCE or CAIRO_OPERATOR_OVER - with an opaque source surface), and falls back to the pixman - image-based compositing otherwise. - - [*] https://bugs.freedesktop.org/show_bug.cgi?id=3566 - -* Various bug fixes, particularly in the fallback paths. - -Snapshot 0.5.0 (2005-05-17 Carl Worth ) -========================================================== -This is a pretty big, and fairly significant snapshot. It represents -between 2 and 3 months of solid work from a lot of people on improving -the API as much as possible. I'd like to express my appreciation and -congratulations to everyone who has worked on the big API Shakeup, -(whether in email battles over names, or fixing my silly bugs). - -This snapshot will require some effort on the part of users, since -there are a _lot_ of API changes (ie. no cairo program ever written is -safe --- they're all broken now in at least one way). But, in spite of -that, we do encourage everyone to move their code to this snapshot as -soon as possible. And we're doing everything we can think of to make -the transition as smooth as possible. - -The idea behind 0.5 is that we've tried to make every good API change -we could want now, and get them all done with. That is, between now -and the 1.0 release of cairo, we expect very few new API changes, -(though some will certainly sneak in). We will have some significant -additions, but the pain of moving code from cairo 0.4 to cairo 0.5 -should be a one time experience, and things should be much smoother as -we continue to move toward cairo 1.0. - -And with so many changes coming out for the first time in this 0.5 -release, we really do need a lot of people trying this out to make -sure the ideas are solid before we freeze the API in preparation for -the 1.0 release. - -OK, enough introduction. Here is a (not-quite-complete) description of -the API removals, changes and additions in this snapshot, (compared to -0.4.0) - -API removals -============ -The following public functions have been removed: - -- cairo_set_target_* - - This is a big change. See the description of cairo_create in - the API changes section for how to deal with this. - -- cairo_set_alpha - - Alpha blending hasn't gone away; there's just a much more - unified rendering model now. Almost all uses of - cairo_set_alpha will be trivially replaced with - cairo_set_source_rgba and a few others will be replaced just - as easily with cairo_paint_with_alpha. - -- cairo_show_surface - - Another useful function that we realized was muddling up the - rendering model. The replacement is quite easy: - cairo_set_source_surface and cairo_paint. - -- cairo_matrix_create -- cairo_matrix_destroy -- cairo_matrix_copy -- cairo_matrix_get_affine - - These functions supported an opaque cairo_matrix_t. We now - have an exposed cairo_matrix_t structure, so these can be - dropped. - -- cairo_surface_set_repeat -- cairo_surface_set_matrix -- cairo_surface_set_filter - - These properties don't belong on surfaces. If you were using - them, you'll just want to instead use - cairo_pattern_create_for_surface and then set these properties - on the pattern. - -- cairo_copy - - This was a confusing function and hopefully nobody will miss - it. But if you really don't find cairo_save/restore adequate, - let us know and we have another idea for a potential - replacement. - -And while we're on the subject of removals, we carefully tightened up -the cairo header files so they no longer gratuitously include header -files that are not strictly necessary, (stdio.h, stdint.h, pixman.h, -Xrender.h, etc. and their dependencies). This may lead to some -surprising errors, so keep your eyes open for that. - -API changes -=========== -Here are some of the API changes that have occurred: - -~ cairo_create(void) -> cairo_create(cairo_surface_t *) - - This is the big change that breaks every program. The ability - to re-target a cairo_t was not particularly useful, but it did - introduce a lot of muddy semantic questions. To eliminate - that, cairo_create now requires its target surface to be - passed in at creation time. This isn't too hard to cope with - as the typical first operation after cairo_create was often - cairo_set_target_foo. So the order of those two swap and the - application instead has cairo_foo_surface_create, then - cairo_create. - -~ cairo_current_* -> cairo_get_* - - We had a strange mixture of cairo_get and cairo_current - functions. They've all been standardized on cairo_get, (though - note one is cairo_get_current_point). - -~ CAIRO_OPERATOR_SRC -> CAIRO_OPERATOR_SOURCE -~ CAIRO_OPERATOR_OVER_REVERSE -> CAIRO_OPERATOR_DEST_OVER - - Many of the cairo_operator_t symbolic values were renamed to - reduce the amount of abbreviation. The confusing "OP_REVERSE" - naming was also changed to use "DEST_OP" instead which is - easier to read and has wider acceptance in other - libraries/languages. - -~ cairo_set_pattern -> cairo_set_source -~ cairo_set_rgb_color -> cairo_set_source_rgb - - All of the various functions that changed the source - color/pattern were unified to use cairo_set_source names to - make the relation more clear. - -~ cairo_transform_point -> cairo_user_to_device -~ cairo_transform_distance -> cairo_user_to_device_distance -~ cairo_inverse_transform_point -> cairo_device_to_user -~ cairo_inverse_transform_distance -> cairo_device_to_user_distance - - These names just seemed a lot more clear. - -~ cairo_init_clip -> cairo_reset_clip -~ cairo_concat_matrix -> cairo_transform - - More abbreviation elimination - -~ cairo_current_path -> cairo_copy_path -~ cairo_current_path_flat -> cairo_copy_path_flat - - The former mechanism for examining the current path was a - function that required 3 or 4 callbacks. This was more - complexity than warranted in most situations. The new - cairo_copy_path function copies the current path into an - exposed data structure, and the documentation provides a - convenient idiom for navigating the path data. - -API additions -------------- -+ cairo_paint - - A generalized version of the painting operators cairo_stroke - and cairo_fill. The cairo_paint call applies the source paint - everywhere within the current clip region. Very useful for - clearing a surface to a solid color, or painting an image, - (see cairo_set_source_surface). - -+ cairo_paint_with_alpha - - Like cairo_paint but applying some alpha to the source, - (making the source paint translucent, eg. to blend an image on - top of another). - -+ cairo_mask - - A more generalized version of cairo_paint_with_alpha which - allows a pattern to specify the amount of translucence at each - point rather than using a constant value everywhere. - -+ cairo_mask_surface - - A convenience function on cairo_mask for when the mask pattern - is already contained within a surface. - -+ cairo_surface_set_user_data -+ cairo_surface_get_user_data -+ cairo_font_face_set_user_data -+ cairo_font_face_get_user_data - - Associate arbitrary data with a surface or font face for later - retrieval. Get notified when a surface or font face object is - destroyed. - -+ cairo_surface_finish - - Allows the user to instruct cairo to finish all of its - operations for a given surface. This provides a safe point for - doing things such as flushing and closing files that the - surface may have had open for writing. - -+ cairo_fill_preserve -+ cairo_stroke_preserve -+ cairo_clip_preserve - - One interesting change in cairo is that the path is no longer - part of the graphics state managed by - cairo_save/restore. This allows functions to construct paths - without interfering with the graphics state. But it prevents - the traditional idiom for fill-and-stroke: - - cairo_save; cairo_fill; cairo_restore; cairo_stroke - - Instead we know have alternate versions cairo cairo_fill, - cairo_stroke, and cairo_clip that preserve the current path - rather than consuming it. So the idiom now becomes simply: - - cairo_fill_preserve; cairo_stroke - -+ cairo_surface_write_to_png -+ cairo_surface_write_to_png_stream - - In place of a single PNG backend, now a surface created - through any backend (except PDF currently) can be written out - to a PNG image. - -+ cairo_image_surface_create_from_png -+ cairo_image_surface_create_from_png_stream - - And its just as easy to load a PNG image into a surface as well. - -+ cairo_append_path - - With the new, exposed path data structure, it's now possible - to append bulk path data to the current path, (rather than - issuing a long sequence of cairo_move_to/line_to/curve_to - function calls). - -Xlib and XCB backends ---------------------- - -Any cairo_format_t and Colormap arguments have been dropped from -cairo_xlib_surface_create. There are also two new -cairo_xlib|xcb_surface_create functions: - - cairo_xlib|xcb_surface_create_for_bitmap - (Particular for creating A1 surfaces) - cairo_xlib|xcb_surface_create_with_xrender_format - (For any other surface types, not described by a Visual*) - -All of these surface create functions now accept width and height. In -addition, there are new cairo_xlib|xcb_surface_set_size functions -which must be called each time a window that is underlying a surface -changes size. - -Print backends (PS and PDF) ---------------------------- -The old FILE* based interfaces have been eliminated. In their place we -have two different functions. One accepts a simple const char -*filename. The other is a more general function which accepts a -callback write function and a void* closure. This should allow the -flexibility needed to hook up with various stream object in many -languages. - -In addition, when specifying the surface size during construction, the -units are now device-space units (ie. points) rather than inches. This -provides consistency with all the other surface types and also makes -it much easier to reason about the size of the surface when drawing to -it with the default identity matrix. - -Finally, the DPI parameters, which are only needed to control the -quality of fallbacks, have been made optional. Nothing is required -during surface_create (300 DPI is assumed) and -cairo_ps|pdf_surface_set_dpi can be used to set alternate values if -needed. - -Font system ------------ -Owen very graciously listened to feedback after the big font rework he -had done for 0.4, and came up with way to improve it even more. In 0.4 -there was a cairo_font_t that was always pre-scaled. Now, there is an -unscaled cairo_font_face_t which is easier to construct, (eg. no -scaling matrix required) and work with, (it can be scaled and -transformed after being set on the graphics state). And the font size -manipulation functions are much easier. You can set an explicit size -and read/modify/write the font matrix with: - - cairo_set_font_size - cairo_get_font_matrix - cairo_set_font_matrix - -(Previously you could only multiply in a scale factor or a matrix.) A -pleasant side effect is that we can (and do) now have a default font -size that is reasonable, as opposed to the old default height of one -device-space unit which was useless until scaled. - -Of course, the old pre-scaled font had allowed some performance -benefits when getting many metrics for a font. Those benefits are -still made available through the new cairo_scaled_font_t. And a -cairo_font_face_t can be "promoted" to a cairo_scaled_font_t by -suppling a font_matrix and the desired CTM. - -Quartz backend --------------- -Tim Rowley put in the work to bring the Quartz backend back after it -had been disabled in the 0.4.0 snapshot. He was not able to bring back -the function that allows one to create a cairo_font_t from an ATSUI -style: - - cairo_font_t * - cairo_atsui_font_create (ATSUStyle style); - -because he didn't have a test case for it. If you care about this -function, please provide a fairly minimal test and we'll try to bring -it back in an upcoming snapshot. - -Snapshot 0.4.0 (2005-03-08 Carl Worth ) -========================================================== -New documentation ------------------ -Owen Taylor has converted cairo's documentation system to gtk-doc and -has begun some long-needed work on the documentation, which can now be -viewed online here: - - http://cairographics.org/manual/ - -New backend: win32 ------------------- -This is the first snapshot to include a functional win32 backend, -(thanks to Owen Taylor). The interface is as follows: - - #include - - void - cairo_set_target_win32 (cairo_t *cr, - HDC hdc); - - cairo_surface_t * - cairo_win32_surface_create (HDC hdc); - - cairo_font_t * - cairo_win32_font_create_for_logfontw (LOGFONTW *logfont, - cairo_matrix_t *scale); - - cairo_status_t - cairo_win32_font_select_font (cairo_font_t *font, - HDC hdc); - - void - cairo_win32_font_done_font (cairo_font_t *font); - - double - cairo_win32_font_get_scale_factor (cairo_font_t *font); - -And see also the documentation at: - -http://cairographics.org/manual/cairo-Microsoft-Windows-Backend.html - -Disabled backend: quartz ------------------------- -Unfortunately, the quartz backend code is currently out of date with -respect to some recent backend interface changes. So, the quartz -backend is disabled in this snapshot. - -If the quartz backend is brought up-to-date before the next snapshot, -we would be glad to make a 0.4.1 snapshot that re-enables it, (we do -not expect many more big backend interface changes). - -API Changes ------------ -The font system has been revamped, (as Owen Taylor's work with -integrating pango and cairo gave us the first serious usage of the -non-toy font API). - -One fundamental, user-visible change is that the cairo_font_t object -now represents a font that is scaled to a particular device -resolution. Further changes are described below. - - cairo.h - ------- - Removed cairo_font_set_transform and cairo_font_current_transform. - - Added cairo_font_extents and cairo_font_glyph_extents. See - documentation for details: - - http://cairographics.org/manual/cairo-cairo-t.html#cairo-font-extents - - cairo-ft.h - ---------- - The cairo_ft_font API changed considerably. Please see the - documentation for details: - - http://cairographics.org/manual/cairo-FreeType-Fonts.html - -Performance ------------ -Make the fast-path clipping (pixel-aligned rectangles) faster. - -Add optimization for applying a constant alpha to a pattern. - -Optimize gradients that are horizontal or vertical in device space. - -Xlib: When RENDER is not available, use image surfaces for -intermediate surfaces rather than xlib surfaces. - -Backend-specific changes ------------------------- - Glitz - ----- - Major update to glitz backend. The output quality should now be just - as good as the image and xlib backends. - - Track changes to glitz 0.4.0. - - PDF - --- - Various improvements to produce more conformant output. - -Internals ---------- -David Reveman contributed a large re-work of the cairo_pattern_t -implementation, providing cleaner code and more optimization -opportunities. - - Backend interface changes - ------------------------- - Rework backend interface to accept patterns, not surfaces for source - and mask. - - Remove set_matrix, set_filter, and set_repeat functions. - - More sophisticated backend interface for image fallbacks, - ({acquire,release}_{source,dest}_image() and clone_similar). - -Bug fixes ---------- -Only install header files for backends that have been compiled. - -Fixed some rounding errors leading to incorrectly placed glyphs. - -Many other minor fixes. - -Snapshot 0.3.0 (2005-01-21 Carl Worth ) -========================================================== -Major API changes ------------------ -1) The public header files will no longer be directly installed into - the system include directory. They will now be installed in a - subdirectory named "cairo", (eg. in /usr/include/cairo rather than - in /usr/include). - - As always, the easiest way for applications to discover the - location of the header file is to let pkg-config generate the - necessary -I CFLAGS and -L/-l LDFLAGS. For example: - - cc `pkg-config --cflags --libs cairo` -o foo foo.c - - IMPORTANT: Users with old versions of cairo installed will need to - manually remove cairo.h and cairo-features.h from the - system include directories in order to prevent the old - headers from being used in preference to the new ones. - -2) The backend-specific portions of the old monolithic cairo.h have - been split out into individual public header files. The new files - are: - - cairo-atsui.h - cairo-ft.h - cairo-glitz.h - cairo-pdf.h - cairo-png.h - cairo-ps.h - cairo-quartz.h - cairo-xcb.h - cairo-xlib.h - - Applications will need to be modified to explicitly include the new - header files where appropriate. - -3) There are two new graphics backends in this snapshot, a PDF - backend, and a Quartz backend. There is also one new font backend, - ATSUI. - -PDF backend ------------ -Kristian Høgsberg has contributed a new backend to allow cairo-based -applications to generate PDF output. The interface for creating a PDF -surface is similar to that of the PS backend, as can be seen in -cairo-pdf.h: - - void - cairo_set_target_pdf (cairo_t *cr, - FILE *file, - double width_inches, - double height_inches, - double x_pixels_per_inch, - double y_pixels_per_inch); - - cairo_surface_t * - cairo_pdf_surface_create (FILE *file, - double width_inches, - double height_inches, - double x_pixels_per_inch, - double y_pixels_per_inch); - -Once a PDF surface has been created, applications can draw to it as -any other cairo surface. - -This code is still a bit rough around the edges, and does not yet -support clipping, surface patterns, or transparent gradients. Text -only works with TrueType fonts at this point and only black text is -supported. Also, the size of the generated PDF files is currently -quite big. - -Kristian is still actively developing this backend, so watch this -space for future progress. - -Quartz backend --------------- -Calum Robinson has contributed a new backend to allow cairo -applications to target native Mac OS X windows through the Quartz -API. Geoff Norton integrated this backend into the current -configure-based build system, while Calum also provided Xcode build -support in the separate "macosx" module available in CVS. - -The new interface, available in cairo-quartz.h, is as follows: - - void - cairo_set_target_quartz_context (cairo_t *cr, - CGContextRef context, - int width, - int height); - - cairo_surface_t * - cairo_quartz_surface_create (CGContextRef context, - int width, - int height); - -There is an example program available in CVS in cairo-demo/quartz. It -is a port of Keith Packard's fdclock program originally written for -the xlib backend. A screenshot of this program running on Mac OS X is -available here: - - http://cairographics.org/~cworth/images/fdclock-quartz.png - -ATSUI font backend ------------------- -This new font backend complements the Quartz backend by allowing -applications to use native font selection on Mac OS X. The interface -is a single new function: - - cairo_font_t * - cairo_atsui_font_create (ATSUStyle style); - -Minor API changes ------------------ -Prototype for non-existent function "cairo_ft_font_destroy" removed. - -Now depends on libpixman 0.1.2 or newer, (0.1.3 is being released -concurrently and has some useful performance improvements). - -Default paint color is now opaque black, (was opaque white). Default -background color is transparent (as before). - -Renamed "struct cairo" to "struct _cairo" to free up the word "cairo" -from the C++ identifier name space. - -Functions returning multiple return values through provided pointers, -(cairo_matrix_get_affine, cairo_current_point, and -cairo_current_color_rgb), will now accept NULL for values the user -wants to ignore. - -CAIRO_HAS_FREETYPE_FONT has now been renamed to CAIRO_HAS_FT_FONT. - -Performance improvements ------------------------- -Alexander Larsson provided some fantastic performance improvements -yielding a 10000% performance improvement in his application, (when -also including his performance work in libpixman-0.1.3). These include - - * Fixed handling of cache misses. - - * Creating intermediate clip surfaces at the minimal size required. - - * Eliminating roundtrips when creating intermediate Xlib surfaces. - -Implementation --------------- -Major re-work of font metrics system by Keith Packard. Font metrics -should now be much more reliable. - -Glitz backend -------------- -Updated for glitz-0.3.0. -Bug fixes in reference counting. - -Test suite ----------- -New tests for cache crashing, rotating text, improper filling of -complex polygons, and leaky rasterization. - -Bug fixes ---------- -Fixed assertion failure when selecting the same font multiple times in -sequence. - -Fixed reference counting so cache_destroy functions work. - -Remove unintended copyright statement from files generated with -PostScript backend. - -Fixed to eliminate new warnings from gcc 3.4 and gcc 4. - -Snapshot 0.2.0 (2004-10-27 Carl Worth ) -=========================================================== -New license: LGPL/MPL ---------------------- -The most significant news with this release is that the license of -cairo has changed. It is now dual-licensed under the LGPL and the -MPL. For details see the COPYING file as well as COPYING-LGPL-2.1 and -COPYING-MPL-1.1. - -I express my thanks to everyone involved in the license change process -for their patience and support! - -New font and glyph internals ----------------------------- -Graydon Hoare has put a tremendous amount of work into new internals -for handling fonts and glyphs, including caches where appropriate. -This work has no impact on the user-level API, but should result in -great performance improvements for applications using text. - -New test suite --------------- -This snapshot of cairo includes a (small) test suite in -cairo/test. The tests can be run with "make check". The test suite was -designed to make it very easy to add new tests, and we hope to see -many contributions here. As you find bugs, please try adding a minimal -test case to the suite, and submit it with the bug report to the -cairo@cairographics.org mailing list. This will make it much easier -for us to track progress in fixing bugs. - -New name for glitz backend --------------------------- -The gl backend has now been renamed to the glitz backend. This means -that the following names have changed: - - CAIRO_HAS_GL_SURFACE -> CAIRO_HAS_GLITZ_SURFACE - cairo_set_target_gl -> cairo_set_target_glitz - cairo_gl_surface_create -> cairo_glitz_surface_create - -This change obviously breaks backwards compatibility for applications -using the old gl backend. - -Up-to-date with latest glitz snapshots --------------------------------------- -This snapshot of cairo is now up to date with the latest glitz -snapshot, (currently 0.2.3). We know that the latest cairo and glitz -snapshots have been incompatible for a very long time. We've finally -fixed that now and we're determined to not let that happen again. - -Revert some tessellation regression bugs ----------------------------------------- -People that have been seeing some tessellation bugs, (eg. leaked -fills), in the CVS version of cairo may have better luck with this -release. A change since the last snapshot was identified to trigger -some of these bugs and was reverted before making the snapshot. The -behavior should be the same as the previous (0.1.23) snapshot. - -Miscellaneous changes ---------------------- -Changed CAIRO_FILTER_DEFAULT to CAIRO_FILTER_BEST to make gradients -easier. - -Track XCB API change regarding iterators. - -Various bug fixes ------------------ -Fix calculation of required number of vertices for pen. - -Fix to avoid zero-dimensioned pixmaps. - -Fix broken sort of pen vertices. - -Fix bug when cairo_show_text called with a NULL string. - -Fix clipping bugs. - -Fix bug in computing image length with XCB. - -Fix infinite loop bug in cairo_arc. - -Fix memory management interactions with libpixman. - -Snapshot 0.1.23 (2004-05-11 Carl Worth ) -======================================================== -Fixes for gcc 3.4 ------------------ -Fix prototype mismatches so that cairo can be built by gcc 3.4. - -Updates to track glitz ----------------------- -Various fixes to support the latest glitz snapshot (0.1.2). - -Gradient updates ----------------- -Radial gradients now support both inner and outer circles. -Transformed linear gradients are now properly handled. -Fixes for extend type reflect. - -Glitz updates -------------- -Converted shading routines to use fixed point values and introduced a -shading operator structure for more efficient shading calculations. -Support compositing with mask surface when mask is solid or -multi-texturing is available. - -PNG backend cleanups --------------------- -Fix output to properly compensate for pre-multiplied alpha format in cairo. -Add support for A8 and A1 image formats. - -Bug fixes ---------- -Avoid crash or infinite loop on null strings and degeneratively short -splines. - -New? bugs in cairo_clip ------------------------ -There are some fairly serious bugs in cairo_clip. It is sometimes -causing an incorrect result. And even when it does work, it is -sometimes so slow as to be unusable. Some of these bugs may not be -new, (indeed cairo_clip has only ever had a braindead-slow -implementation), but I think they're worth mentioning here. - -Snapshot 0.1.22 (2004-04-16 Carl Worth ) -======================================================== -Cairo was updated to track the changes in libpixman, and now depends -on libpixman version 0.1.1. - -Snapshot 0.1.21 (2004-04-09 David Reveman ) -============================================================= -New OpenGL backend ------------------- -The OpenGL backend provides hardware accelerated output for -X11 and OS X. The significant new functions are: - - cairo_set_target_gl - cairo_gl_surface_create - -Automatic detection of available backends ------------------------------------------ -The configure script now automatically detect what backends are -available, (use ./configure --disable-`backend' to prevent -compilation of specific backends). - -Snapshot 0.1.20 (2004-04-06 Carl Worth ) -======================================================== -New pattern API ---------------- -David Reveman has contributed a new pattern API which enable linear -and radial gradient patterns in addition to the original surface-based -patterns. The significant new top-level functions are: - - cairo_pattern_create_linear - cairo_pattern_create_radial - cairo_pattern_create_for_surface - cairo_pattern_add_color_stop - cairo_set_pattern - -Any code using the old cairo_set_pattern, (which accepted a -cairo_surface_t rather than a cairo_pattern_t), will need to be -updated. - -Update to XCB backend ---------------------- -The XCB backend is now enabled by default, (use ./configure ---disable-xcb to turn it off). - -Faster clipping ---------------- -Graydon Hoare has added optimizations that make cairo_clip much faster -when the path is a pixel-aligned, rectangular region. - -Bug fixes. - -Snapshot 0.1.19 (2004-02-24 Carl Worth ) -======================================================== -New PNG backend ---------------- -Olivier Andrieu contributed a new PNG backend. It builds on the -existing image backend to make it easy to render "directly" to a -.png file. The user never needs to deal with the actual image -buffer. The significant new functions are: - - cairo_set_target_png - cairo_png_surface_create - -The PNG backend is not enabled by default so that by default there is -not a new dependency on libpng. Use ./configure --enable-png to enable -this backend. - -Snapshot 0.1.18 (2004-02-17 Carl Worth ) -======================================================== -Path query functionality ------------------------- -It's now possible to query the current path. The two new functions -are: - - cairo_current_path - cairo_current_path_flat - -Each function accepts a number of callback functions that will be -called for each element in the path (move_to, line_to, curve_to, -close_path). The cairo_current_path_flat function does not accept a -curve_to callback. Instead, all curved portions of the path will be -converted to line segments, (within the current tolerance value). This -can be handy for doing things like text-on-path without having to -manually interpolate Bézier splines. - -New XCB backend ---------------- -Jamey Sharp has contributed a second X backend that uses the new, lean -XCB library rather than Xlib. It cannot currently be compiled at the -same time as the Xlib backend. See ./configure --enable-xcb. - -Build fixes for cygwin. - -Bug fixes. - -Snapshot 0.1.17 (2003-12-16 Carl Worth ) -======================================================== - -Better text support -------------------- -This snapshot provides much better text support by implementing the -following four functions: - - cairo_text_extents - cairo_glyph_extents - cairo_text_path - cairo_glyph_path - -The text/glyph_extents functions can be used to determine the bounding -box (and advance) for text as if drawn by show_text/glyphs. - -The text/glyph_path objects functions place text shapes on the current -path, where they can be subsequently manipulated. For example, -following these functions with cairo_stroke allows outline text to be -drawn. Calling cairo_clip allows clipping to a text-shaped region. - -Combined dependencies ---------------------- -The cairo core now depends only on the libpixman library. This single -library replaces the three previous libraries libic, libpixregion, and -slim. Thanks to Dave Beckett for all of -the heavy lifting with this renaming effort. - -Conditional compilation of backends ------------------------------------ -Cairo now allows optional backends to be disabled at compile time. The -following options may now be passed to the configure script: - - --disable-xlib - --disable-ps - -Note that the first option is a change from the old --without-x option -which will no longer have any effect. - -OS X supported - several byte-order issues resolved ---------------------------------------------------- -Cairo has now been successfully compiled under OS X. Testing revealed -that there were some byte-order problems in the PostScript backend and -the PNG generation in the demos. These have now been resolved. - -2003-10 -======= -Graydon Hoare implemented the first real text -support using Freetype/fontconfig, (previous versions of cairo used -Xft and could only draw text when using an X backend). - -2003-09 -======= -Graydon Hoare added the first real support for -running cairo with a non-render-aware X server. - -Jamey Sharp virtualized the backend font and -surface interfaces in September, 2003. - -2003-06 -======= -Xr is renamed cairo to avoid confusion since it no longer had a strict -dependence on X. - -2003-05 -======= -A new image surface backend is added to Xr. Keith Packard - wrote the image compositing code in libic that is -used for the image_surface backend. This code was originally written -as the software fallback for the render extension within the X -server. - -2002-06 -======= -Carl Worth wrote the first lines of Xr, after Keith -Packard proposed the plan for a stateful drawing -library in C providing a PostScript-like rendering model. - - LocalWords: mutex BeOS extraordinaire distro's URL lcd bool tarball diff --git a/Build/source/libs/cairo/cairo-1.14.2/PORTING_GUIDE b/Build/source/libs/cairo/cairo-1.14.2/PORTING_GUIDE deleted file mode 100644 index 7488173c46b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/PORTING_GUIDE +++ /dev/null @@ -1,265 +0,0 @@ - ...-----=======-----... - Cairo 1.0 Porting Guide - ...-----=======-----... - -Here are some notes on more easily porting cairo_code from cairo 0.4 -to cairo 1.0. It is sorted roughly in order of importance, (the items -near the top are expected to affect the most people). - -Automated API renamings -======================= -There have been a lot of simple renamings where the functionality is -the same but the name of the symbol is different. We have provided a -script to automate the conversion of these symbols. It can be found -within the cairo distribution in: - - util/cairo-api-update - -This script is used by installing it somewhere on your PATH, and the -running it and providing the names of your source files on the command -line. For example: - - cairo-api-update *.[ch] - -The script will first save backup copies of each file (renamed with a -.bak extension) and then will perform all of the simple renamings. - -For your benefit, the script also produces messages giving filenames -and line numbers for several of the manual API updates that you will -need to perform as described below. - - -Manual API changes -================== -This section of the porting guide describes changes you will have to -manually make to your source code. In addition to the information in -this guide, the cairo-api-update script will notify you of some of -these issues as described above. - -Cairo's deprecation warnings ----------------------------- -Also, if your compiler provides warnings for implicit declarations of -functions, (eg. "gcc -Wall"), then simply attempting to compile your -program will cause cairo to generate messages intended to guide you -through the porting process. - -For example, if you neglect to update an old call to -cairo_set_target_drawable, you might see an error message as follows: - - foo.c:10: warning: implicit declaration of function - ‘cairo_set_target_drawable_DEPRECATED_BY_cairo_xlib_surface_create’ - -This message is indicating to you that the deprecatd function -cairo_set_target_drawable appears in your program foo.c on line 10, -and you should rewrite your program to call cairo_xlib_surface_create -instead. - -The remainder of this porting guide is arranged as a set of common -code patterns that appear in old (cairo-0.4) code and how it should be -transformed to new (cairo-0.5) code. - -cairo_create ------------- -Was: cr = cairo_create (); - cairo_set_target_foo (cr, args); - /* draw */ - cairo_destroy (cr); - -Now: cairo_surface_t *surface; - - surface = cairo_foo_surface_create (args); - cr = cairo_create (surface); - /* draw */ - cairo_destroy (cr); - cairo_surface_destroy (surface); - -Or: cairo_surface_t *surface; - - surface = cairo_foo_surface_create (args); - cr = cairo_create (surface); - cairo_surface_destroy (surface); - /* draw */ - cairo_destroy (cr); - -NOTE: Many of the cairo_foo_surface_create functions accept the - identical arguments as the the old cairo_set_target_foo - functions, (minus the cairo_t*), making this transformation - quite easy. One notable exception is cairo_set_target_drawable - which, when it becomes cairo_xlib_surface_create must pickup new - arguments for the Visual*, the width, and the height. - -cairo_set_alpha (1) -------------------- -Was: cairo_set_rgb_color (cr, red, green, blue); - cairo_set_alpha (cr, alpha); - -Now: cairo_set_source_rgba (cr, red, green, blue, alpha); - -cairo_show_surface ------------------- -Was: cairo_show_surface (cr, surface, width, height); - -Now: cairo_set_source_surface (cr, surface, x, y); - cairo_paint (cr); - -NOTE: The type signatures of cairo_show_surface and cairo_set_source - are the same, but pay attention that cairo_show_surface required - the width and height, while cairo_set_source_surface requires - the X,Y location to where the surface will be placed. - -cairo_set_alpha (2) -------------------- -Was: cairo_set_alpha (cr, alpha); - cairo_show_surface (cr, surface, width, height); - -Now: cairo_set_source_surface (cr, surface, x, y); - cairo_paint_with_alpha (cr, alpha); - -filling and stroking --------------------- -Was: cairo_save (cr); - /* set fill color */ - cairo_fiill (cr); - cairo_restore (cr); - /* set stroke color */ - cairo_stroke (cr); - -Now: /* set fill color */ - cairo_fill_preserve (cr); - /* set stroke color */ - cairo_stroke (cr); - -NOTE: The current path is no longer saved/restored by - cairo_save/cairo_restore. This can lead to some subtle - surprises, so look out. - -cairo_matrix_t --------------- -Was: cairo_matrix_t *matrix; - - matrix = cairo_matrix_create (); - /* Do stuff with matrix */ - cairo_matrix_destroy (matrix); - -Now: cairo_matrix_t matrix; - cairo_matrix_init_identity (&matrix); - /* Do stuff with &matrix */ - -NOTE: If you are really lazy, you can still use a cairo_matrix_t* and - avoid putting the &matrix all over by just replacing - cairo_matrix_create() with malloc() and cairo_matrix_destroy() - with free(). That's not as nice, and you still need to be - careful to see if you need to initialize it to an identity - matrix as cairo_matrix_create() did for you. - -Rendering to a temporary surface --------------------------------- -Was: cairo_save (cr); - { - cairo_set_target_surface (cr, temporary); - /* draw through cr onto temporary */ - } - cairo_restore (cr); - /* use temporary as source on cr */ - -Now: { - cr2 = cairo_create (temporary); - /* draw through cr2 onto temporary */ - cairo_destory (cr2); - } - /* use temporary as source on cr */ - -NOTE: Having to create another cairo_t is a bit annoying, but having - to invent a new name for it is just awful, (imagine a deeply - nested version of this code). Fortunately, the style above is - just a stop-gap measure until the new group API comes along. - -Iterating over a path ---------------------- -Was: cairo_current_path (cr, - my_move_to, - my_line_to, - my_curve_to, - my_close_path, - closure); - -Now: int i; - cairo_path_t *path; - cairo_path_data_t *data; - - path = cairo_copy_path (cr); - - for (i=0; i < path->num_data; i += path->data[i].header.length) { - data = &path->data[i]; - switch (data->header.type) { - case CAIRO_PATH_MOVE_TO: - my_move_to (closure, data[1].point.x, data[1].point.y); - break; - case CAIRO_PATH_LINE_TO: - my_line_to (closure, data[1].point.x, data[1].point.y); - break; - case CAIRO_PATH_CURVE_TO: - my_curve_to (closure, data[1].point.x, data[1].point.y, - data[2].point.x, data[2].point.y, - data[3].point.x, data[3].point.y); - break; - case CAIRO_PATH_CLOSE_PATH: - my_close_path (closure); - break; - } - } - cairo_path_destroy (path); - -NOTE: This version makes it looks like the new form is a _lot_ more - verbose than the old version. But realize that the old version - required the support of 4 additional functions. The new approach - allows great flexibility including the ability to inline the - entire operation within the switch statement when appropriate. - -Erasing a surface to transparent --------------------------------- -Was: cairo_set_rgb_color (cr, 0., 0., 0.); - cairo_set_alpha (cr, 0.) - cairo_set_operator (cr, CAIRO_OPERATOR_SRC); - cairo_rectangle (cr, 0., 0., surface_width, surface_height); - cairo_fill (cr); - - or: cairo_set_rgb_color (cr, 0., 0., 0.); - cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - cairo_rectangle (cr, 0., 0., surface_width, surface_height); - cairo_fill (cr); - -Now: cairo_set_source_rgba (cr, 0., 0., 0., 0.); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (cr); - - or: cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - cairo_paint (cr); - -NOTE: Using cairo_rectangle and fill would still work just fine. It's - just a lot more convenient to use cairo_paint now, (particularly - as it doesn't require you to even know what the bounds of the - target surface are). - -Drawing to a PNG file ---------------------- -Was: file = fopen (filename, "w"); - cr = cairo_create (); - cairo_set_target_png (cr, file, format, width, height); - /* draw image */ - cairo_destroy (cr); - fclose (file); - -Now: surface = cairo_image_surface_create (format, width, height); - cr = cairo_create (surface); - /* draw image */ - cairo_surface_write_to_png (surface, filename); - cairo_destroy (cr); - cairo_surface_destroy (surface); - -NOTE: The png backend is gone. So there is no cairo_png_surface_create - to take the place of cairo_set_target_png. And notice that we - used an image surface here, but it is just as easy to use - cairo_surface_write_to_png with an xlib or other surface, (but - not PDF at the moment). This is one of the big advantages of - this approach as opposed to a PNG surface. diff --git a/Build/source/libs/cairo/cairo-1.14.2/README b/Build/source/libs/cairo/cairo-1.14.2/README deleted file mode 100644 index 0be9947d548..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/README +++ /dev/null @@ -1,204 +0,0 @@ -Cairo - Multi-platform 2D graphics library -http://cairographics.org - -What is cairo -============= -Cairo is a 2D graphics library with support for multiple output -devices. Currently supported output targets include the X Window -System (via both Xlib and XCB), quartz, win32, and image buffers, -as well as PDF, PostScript, and SVG file output. Experimental backends -include OpenGL, BeOS, OS/2, and DirectFB. - -Cairo is designed to produce consistent output on all output media -while taking advantage of display hardware acceleration when available -(for example, through the X Render Extension). - -The cairo API provides operations similar to the drawing operators of -PostScript and PDF. Operations in cairo include stroking and filling -cubic Bézier splines, transforming and compositing translucent images, -and antialiased text rendering. All drawing operations can be -transformed by any affine transformation (scale, rotation, shear, -etc.). - -Cairo has been designed to let you draw anything you want in a modern -2D graphical user interface. At the same time, the cairo API has been -designed to be as fun and easy to learn as possible. If you're not -having fun while programming with cairo, then we have failed -somewhere---let us know and we'll try to fix it next time around. - -Cairo is free software and is available to be redistributed and/or -modified under the terms of either the GNU Lesser General Public -License (LGPL) version 2.1 or the Mozilla Public License (MPL) version -1.1. - -Where to get more information about cairo -========================================= -The primary source of information about cairo is: - - http://cairographics.org/ - -The latest versions of cairo can always be found at: - - http://cairographics.org/download - -Documentation on using cairo and frequently-asked questions: - - http://cairographics.org/documentation - http://cairographics.org/FAQ - -Mailing lists for contacting cairo users and developers: - - http://cairographics.org/lists - -Roadmap and unscheduled things to do, (please feel free to help out): - - http://cairographics.org/roadmap - http://cairographics.org/todo - -Dependencies -============ -The set of libraries needed to compile cairo depends on which backends -are enabled when cairo is configured. So look at the list below to -determine which dependencies are needed for the backends of interest. - -For the surface backends, we have both "supported" and "experimental" -backends. Further, the supported backends can be divided into the -"standard" backends which can be easily built on any platform, and the -"platform" backends which depend on some underlying platform-specific -system, (such as the X Window System or some other window system). - -As an example, for a standard Linux build similar to what's shipped by -your distro, (with image, png, pdf, PostScript, svg, and xlib surface -backends, and the freetype font backend), the following sample commands -will install necessary dependencies: - - Debian (and similar): - - apt-get build-dep cairo - - Fedora (and similar): - - yum install libpng-devel zlib-devel libXrender-devel fontconfig-devel - -Technically you probably don't need pixman from the distribution since -if you're manually compiling Cairo you probably want an updated pixman -as well. However, if you follow the default settings and install pixman -to /usr/local, your Cairo build should properly use it in preference to -the system pixman. - - -Supported, "standard" surface backends ------------------------------------- - image backend (required) - ------------------------ - pixman >= 0.30.0 http://cairographics.org/releases - - png support (can be left out if desired, but many - ----------- applications expect it to be present) - libpng http://www.libpng.org/pub/png/libpng.html - - pdf backend - ----------- - zlib http://www.gzip.org/zlib - - postscript backend - ------------------ - zlib http://www.gzip.org/zlib - - svg backend - ----------- - [none] - -Supported, "platform" surface backends ------------------------------------ - xlib backend - ------------ - X11 http://freedesktop.org/Software/xlibs - - xlib-xrender backend - -------------------- - Xrender >= 0.6 http://freedesktop.org/Software/xlibs - - quartz backend - -------------- - MacOS X >= 10.5 with Xcode >= 3.0 - - win32 backend - ------------- - Microsoft Windows 2000 or newer[*]. - - xcb backend - ----------- - XCB http://xcb.freedesktop.org - -Font backends (required to have at least one) ---------------------------------------------- - freetype font backend - --------------------- - freetype >= 2.1.9 http://freetype.org - fontconfig http://fontconfig.org - - quartz-font backend - ------------------- - MacOS X >= 10.4 with Xcode >= 2.4 - - win32 font backend - ------------------ - Microsoft Windows 2000 or newer[*]. - - [*] The Win32 backend should work on Windows 2000 and newer - (excluding Windows Me.) Most testing has been done on - Windows XP. While some portions of the code have been - adapted to work on older versions of Windows, considerable - work still needs to be done to get cairo running in those - environments. - - Cairo can be compiled on Windows with either the gcc - toolchain (see http://www.mingw.org) or with Microsoft - Visual C++. If the gcc toolchain is used, the standard - build instructions using configure apply, (see INSTALL). - If Visual C++ is desired, GNU make is required and - Makefile.win32 can be used via 'make -f Makefile.win32'. - The compiler, include paths, and library paths must be set - up correctly in the environment. - - MSVC versions earlier than 7.1 are known to miscompile - parts of cairo and pixman, and so should be avoided. MSVC - 7.1 or later, including the free Microsoft Visual Studio - Express editions, produce correct code. - -Experimental surface backends ------------------------------ - beos backend - ------------ - No dependencies in itself other than an installed BeOS system, but cairo - requires a font backend. See the freetype dependency list. - - os2 backend - ----------- - Cairo should run on any recent version of OS/2 or eComStation, but it - requires a font backend. See the freetype dependency list. Ready to use - packages and developer dependencies are available at Netlabs: - ftp://ftp.netlabs.org/pub/cairo - - skia backend - ------------ - Requires the skia library as of June 2014. Since skia is not - API stable, building against newer (or older) versions of skia - will probably fail. - - -Compiling -========= -See the INSTALL document for build instructions. - - -History -======= -Cairo was originally developed by Carl Worth and -Keith Packard . Many thanks are due to Lyle Ramshaw -without whose patient help our ignorance would be much more apparent. - -Since the original development, many more people have contributed to -cairo. See the AUTHORS files for as complete a list as we've been able -to compile so far. diff --git a/Build/source/libs/cairo/cairo-1.14.2/README.win32 b/Build/source/libs/cairo/cairo-1.14.2/README.win32 deleted file mode 100644 index ff962b72a68..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/README.win32 +++ /dev/null @@ -1,66 +0,0 @@ -Building Cairo on Windows -========================= -There are two primary ways to build Cairo on Windows. You can use a -UNIX emulation based setup, such as Cygwin or MSYS, with the -conventional configure script shipped with Cairo releases. In this -configuration, you will build with GCC and (implicitly) libtool. In -the Cygwin case you end up with a DLL that depends on Cygwin and -should be used only from Cygwin applications. In the MSYS case you end -up with a "normal" Win32 DLL that can be used either from GCC- or -Microsoft Visual C++-compiled code. In theory, this technique is no -different than the ordinary build process for the Cairo library. In -practise there are lots of small details that can go wrong. - -The second way is to use a GNU-compatible make, but build using -Microsoft's Visual C++ compiler to produce native libraries. This is -the setup this README.win32 is written for. Also the DLL produced this -way is usable either from GCC- or MSVC-compiled code. - -Tools required -============== -You will need GNU make, version 3.80 or later. Earlier versions or -other modern make implementations may work, but are not guaranteed to. - -You will also need Microsoft Visual C++. Version 7 has been most -heavily tested, but other versions are likely to work fine. - -Libraries required -================== -Cairo requires a compatible version of the pixman library. Full build -instructions are beyond the scope of this document; however, using the -same tools, it should be possible to build pixman simply by entering -the pixman/src directory and typing: - - make -f Makefile.win32 CFG=release - -Depending on your feature set, you may also need zlib and libpng. - -Building -======== -There are a few files that you will need to edit. First, you must -determine which features will be built. Edit -build/Makefile.win32.features and set the features as desired. Note -that most features have external dependencies; specifically, -CAIRO_HAS_PNG_FUNCTIONS requires libpng to be present, and -CAIRO_HAS_PS_SURFACE and CAIRO_HAS_PDF_SURFACE both require zlib. - -To ensure that the compiler can find all dependencies, you may need to -edit build/Makefile.win32.common. In particular, ensure that -PIXMAN_CFLAGS contains a -I parameter pointing to the location of -your pixman header files and that PIXMAN_LIBS points to the actual -location of your pixman-1.lib file. You may also need to edit the -various occurrences of CAIRO_LIBS to point to other libraries -correctly. Note also that if you wish to link statically with zlib, -you should replace zdll.lib with zlib.lib. - -Finally, from the top Cairo directory, type: - - make -f Makefile.win32 CFG=release - -If this command succeeds, you will end up with src/release/cairo.dll. -To successfully use Cairo from your own programs, you will probably -want to move this file to some central location. You will also -probably want to copy the Cairo header files. These should be placed -in a cairo subdirectory (for instance, c:/code/common/include/cairo). -The exact set to copy depends on your features and is reported to you -at the end of the build. diff --git a/Build/source/libs/cairo/cairo-1.14.2/RELEASING b/Build/source/libs/cairo/cairo-1.14.2/RELEASING deleted file mode 100644 index f6f5eeb5125..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/RELEASING +++ /dev/null @@ -1,142 +0,0 @@ -Here are the steps to follow to create a new cairo release: - -1) Ensure that there are no local, uncommitted/unpushed - modifications. You're probably in a good state if both "git diff - HEAD" and "git log master..origin/master" give no output. Also make - sure you have libglib2.0-doc installed (else you'll get excessive - gtk-doc cross reference warnings in the next step). - -2) Verify that the code passes "make distcheck" - - First, make sure you have 'nm' and 'readelf' commands in PATH. - this should be OK with any Linux distro. - - Running "make distcheck" should result in no warnings or - errors and end with a message of the form: - - ============================================= - cairo-X.Y.Z archives ready for distribution: - cairo-X.Y.Z.tar.gz - ============================================= - - (But the tar file isn't actually ready yet, as we still have - some more steps to follow). - - Note that it's allowed (and perhaps recommended) to run the - "make distcheck" step against an all-software X server such as - Xvfb to avoid getting tripped up by any X-server-driver-specific - bugs. See test/README for details - - If you get errors about local PLT entries, you get the list of - cairo entries with the error. For each of these, a call to - slim_hidden_def and slim_hidden_proto is needed in the cairo - implementation in the style of other similar calls. - - In the unfortunate case that you have to push a snapshot out - (note, I said snapshot, not release) without the entire test - suite passing, here's the magic env vars to set when doing - 'make distcheck' and 'make release-publish' that will let you - get away with it. At any cost, never ever release without - (implied) distchecking. Every time we got around it, it turned - out to be a disaster. Anyway, here's the pass code: - - DISPLAY= CAIRO_TEST_TARGET=" " - -3) Fill out an entry in the NEWS file - - Sift through the logs since the last release. This is most - easily done with a command such as: - - git log --stat X.Y.Z.. - - where X.Y.Z is the previous release version. - - Summarize major changes briefly in a style similar to other - entries in NEWS. Take special care to note any additions in - the API. These should be easy to find by noting modifications - to .h files in the log command above. And more specifically, - the following command will show each patch that has changed a - public header file since the given version: - - find src/ -name '*.h' ! -name '*-private.h' ! -name 'cairoint.h' ! -name 'cairo-*features*.h' | \ - xargs git diff X.Y.Z.. -- - -4) Increment cairo_version_{minor|micro} in cairo-version.h: - - If there are backward-incompatible changes in the API, stop - now and don't release. Go back and fix the API instead. Cairo - is intended to remain backwards-compatible as far as API. - - So cairo_version_major will not be incremented unless we come - up with a new versioning scheme to take advantage of it. - - If there are API additions, then increment cairo_version_minor - and reset cairo_version_micro to 0. NOTE: The minor version is - only incremented for releases, not for snapshots. - - Otherwise, (i.e. there are only bug fixes), increment - cairo_version_micro to the next larger (even) number. - -5) Commit the changes to NEWS and cairo-version.h - - It's especially important to mention the new version number in your - commit log. - -6) Run "make release-publish" which will perform the following steps - for you: - - * Generate ChangeLog files out of git repository - * Check that ChangeLog files were generated properly - * Check that the version number ends with an even micro component - * Check that no release exists with the current version - * Verify that make distcheck completes successfully - * Generate the final tar file - * Generate an sha1sum file - * Sign the sha1sum using your GPG setup (asks for your GPG password) - * scp the three files to appear on http://cairographics.org/releases - * Generate a versioned manual and upload it to appear as both: - http://cairographics.org/manual-X.Y.Z - http://cairographics.org/manual - * Place local copies of the three files in the releases directory - * Create a LATEST-package-version file (after deleting any old one) - * Tag the entire source tree with a tag of the form X.Y.Z, and sign - the tag with your GPG key (asks for your GPG password, and you - may need to set GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL to match - your public-key's setting or this fails.) - * Provide some text for the release announcement (see below). - If for some reason you lost this message, "make release-publish-message" - prints it for you. - -7) Increment cairo_version_micro to the next larger (odd) number in - cairo-version.h, commit, and push. - -8) Push the newly created tag out to the central tree with a command - something like: - - git push upstream master X.Y.Z - -9) Edit the cairo bugzilla product and add the new version numbers. Note - that you need to add two versions. One for the release/snapshot (with - an even micro version), another with the post-release version (with an - odd micro version). - -10) Send a message to cairo-announce@cairographics.org and CC - gnome-announce-list@gnome.org and ftp-release@lists.freedesktop.org - (pr@lwn.net as well for major releases) to announce the new release - using the text provided from "make release-publish", adding the excerpt - from NEWS, your signature, followed by the standard "What is cairo" and - "Where to get more information about cairo" blurbs from README, and - finally the shortlog of all changes since last release, generated by: - - git shortlog X.Y.Z... - - where X.Y.Z is the last released version. - -11) Edit the cairo wiki to add the announcement to the NEWS page and - the front page. (just the parts before your signature). - -12) For minor releases (no X.Y change), notify desktop-devel-list@gnome.org - or update the ExternalDependencies page for the current cycle if you - know where it is. Currently it's: - - http://live.gnome.org/TwoPointNineteen/ExternalDependencies diff --git a/Build/source/libs/cairo/cairo-1.14.2/acinclude.m4 b/Build/source/libs/cairo/cairo-1.14.2/acinclude.m4 deleted file mode 100644 index dcf54f9357d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/acinclude.m4 +++ /dev/null @@ -1,55 +0,0 @@ -dnl -*- mode: autoconf -*- - -dnl [m4_newline] didn't appear until autoconf 2.62 -m4_ifdef([m4_newline],,[m4_define([m4_newline],[ -])]) - -dnl These are not available in autoconf 2.59 - -m4_ifdef([m4_foreach_w],,[m4_define([m4_foreach_w], -[m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) - -m4_ifdef([AS_CASE],,[ -m4_define([_AS_CASE], -[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], - [$#], 1, [ *) $1 ;;], - [$#], 2, [ $1) m4_default([$2], [:]) ;;], - [ $1) m4_default([$2], [:]) ;; -$0(m4_shift2($@))])dnl -]) -m4_defun([AS_CASE], -[m4_ifval([$2$3], -[case $1 in -_AS_CASE(m4_shift($@)) -esac -])dnl -])# AS_CASE -]) - -m4_ifdef([m4_shift2],, [m4_define([m4_shift2], [m4_shift(m4_shift($@))])]) - - -dnl ========================================================================== - -dnl This has to be in acinclude.m4 as it includes other files - -dnl Parse Version.mk and declare m4 variables out of it -m4_define([CAIRO_PARSE_VERSION],dnl - m4_translit(dnl - m4_bpatsubst(m4_include(cairo-version.h), - [^.define \([a-zA-Z0-9_]*\) *\([0-9][0-9]*\)], - [[m4_define(\1, \2)]]), - [A-Z], [a-z])dnl -)dnl - -dnl ========================================================================== - -m4_pattern_forbid([^cr_]) - -dnl AC_AUTOCONF_VERSION was introduced in 2.62, so its definition works as -dnl a conditional on version >= 2.62. Older versions did not call -dnl m4_pattern_allow from AC_DEFINE and friends. To avoid lots of warnings we -dnl only forbid CAIRO_ if autoconf is recent enough. -m4_ifdef([AC_AUTOCONF_VERSION], -[m4_pattern_forbid([CAIRO])], -[m4_pattern_forbid([_CAIRO])]) diff --git a/Build/source/libs/cairo/cairo-1.14.2/autogen.sh b/Build/source/libs/cairo/cairo-1.14.2/autogen.sh deleted file mode 100755 index 4d113f8be5f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/autogen.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -# Run this to generate all the initial makefiles, etc. - -test -n "$srcdir" || srcdir=`dirname "$0"` -test -n "$srcdir" || srcdir=. - -ORIGDIR=`pwd` -cd $srcdir - -AUTORECONF=`which autoreconf` -if test -z $AUTORECONF; then - echo "*** No autoreconf found, please intall it ***" - exit 1 -fi - -GTKDOCIZE=`which gtkdocize` -if test -z $GTKDOCIZE; then - echo "*** No GTK-Doc found, documentation won't be generated ***" -else - gtkdocize || exit $? -fi - -# create dummy */Makefile.am.features and ChangeLog to make automake happy -> boilerplate/Makefile.am.features -> src/Makefile.am.features -touch ChangeLog - -autoreconf --install --verbose || exit $? - -cd $ORIGDIR -test -n "$NOCONFIGURE" || "$srcdir/configure" "$@" diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.analysis b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.analysis deleted file mode 100644 index a44077ab453..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.analysis +++ /dev/null @@ -1,37 +0,0 @@ -if CAIRO_HAS_LCOV -# use recursive makes in order to ignore errors during check/perf -lcov: - -$(MAKE) $(AM_MAKEFLAGS) check - $(MAKE) $(AM_MAKEFLAGS) genlcov -lcov-perf: - -$(MAKE) $(AM_MAKEFLAGS) perf - $(MAKE) $(AM_MAKEFLAGS) genlcov - -# we have to massage the lcov.info file slightly to hide the effect of libtool -# placing the objects files in the .libs/ directory separate from the *.c -genlcov: - $(LTP) --directory $(top_builddir) --path $(top_builddir) --capture --output-file cairo-lcov.info --test-name CAIRO_TEST --no-checksum - $(SED) -e 's#.libs/##' \ - -e 's#boilerplate/src#src#' \ - -e 's#$(shell pwd)#$(shell cd $(top_srcdir) && pwd)#' \ - < cairo-lcov.info > cairo-lcov.info.tmp - LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory cairo-lcov --title "Cairo Code Coverage" --show-details cairo-lcov.info.tmp - $(RM) cairo-lcov.info.tmp - -html-local: lcov -else -lcov lcov-perf genlcov: - @echo You need to configure Cairo with support for gcov enabled. - @echo e.g, ./configure --enable-gcov -endif - -lcov-clean: -if CAIRO_HAS_LCOV - -$(LTP) --directory $(top_builddir) -z -endif - -$(RM) -r cairo-lcov.info cairo-lcov - -$(FIND) -name '*.gcda' -print | $(XARGS) $(RM) - -distclean-local: lcov-clean - -.PHONY: lcov lcov-perf genlcov lcov-clean diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.changelog b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.changelog deleted file mode 100644 index 07e603695cf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.changelog +++ /dev/null @@ -1,82 +0,0 @@ -# Creating ChangeLog files from git log: - -# We always create a ChangeLog that contains the most recent changes, and -# multiple others for changes between major releases (other than the last such -# segment that we put in 'ChangeLog'. The old ones are named -# ChangeLog.pre-X.Y where X.Y is the version number of the major release. - -CURR_CHANGELOG_VERSION=$(CAIRO_VERSION_MAJOR).$$(echo "($(CAIRO_VERSION_MINOR)+1)/2*2" | bc) -# examines $version -PREV_CHANGELOG_VERSION=$$(if test "x$$(echo "($$version-0.1)*2/2"|bc)" = "x$$(echo "$$version*2/2"|bc)"; \ - then echo "$$version-$$(echo "$$version" | sed 's/[0-9]/0/g;s/[0-9]$$/2/')"; \ - else echo "$$version-1.0"; \ - fi | bc | sed 's/[.]0*/./;s/^0[.]\?$$/initial/;s/[.]$$/.0/') - -CHANGELOGS = ChangeLog \ - `version=$(CURR_CHANGELOG_VERSION); \ - version=$(PREV_CHANGELOG_VERSION); \ - while test "x$$version" != xinitial; do \ - echo ChangeLog.pre-$$version; \ - version=$(PREV_CHANGELOG_VERSION); \ - done` - -MAINTAINERCLEANFILES += $(srcdir)/ChangeLog $(srcdir)/ChangeLog.pre-* -DISTCLEANFILES += $(srcdir)/ChangeLog.cache-* - -changelogs: - @$(MAKE) $(AM_MAKEFLAGS) $(CHANGELOGS) - -dist-hook: changelogs - changelogs="$(CHANGELOGS)"; \ - for changelog in $$changelogs; do \ - cp $(srcdir)/$$changelog $(distdir)/ 2>/dev/null || \ - cp $$changelog $(distdir)/; \ - done - -$(srcdir)/ChangeLog: - @if test -d "$(srcdir)/.git"; then \ - version=$(CURR_CHANGELOG_VERSION); \ - prev=$(PREV_CHANGELOG_VERSION).0; \ - nearest_tag=`git describe | sed 's/-.*//'`; \ - before=$(srcdir)/ChangeLog.cache-$$prev..$$nearest_tag; \ - after=$(srcdir)/ChangeLog.cache-$$nearest_tag..; \ - $(MAKE) $(AM_MAKEFLAGS) $$before $$after && \ - echo Creating $@ && \ - { echo '# Generated by configure. Do not edit.'; echo; \ - cat $$after; echo; cat $$before; } > $@; \ - else \ - test -f $@ || \ - (echo A git checkout is required to generate $@ >&2 && \ - echo A git checkout is required to generate this file >> $@); \ - fi - -DISTCLEANFILES += ChangeLog.cache-* - -ChangeLog.cache-*..: .git - -ChangeLog%: $(srcdir)/ChangeLog% - -$(srcdir)/ChangeLog.cache-% $(srcdir)/ChangeLog.pre-%: - @echo Creating $@ - @if test -d "$(srcdir)/.git"; then \ - (cd "$(srcdir)" && \ - version=$$(echo "$@" | sed 's/.*ChangeLog\([.].*-\)\?//'); \ - if echo "$@" | grep -q '^ChangeLog[.]cache'; then \ - spec=$$version; \ - else \ - to=$$version; \ - test "x$$version" = x && version=$(CURR_CHANGELOG_VERSION); \ - from=$(PREV_CHANGELOG_VERSION); \ - test "x$$to" = x || to=$$to.0; \ - test "x$$from" = xinitial || from=$$from.0; \ - spec=$$from..$$to; \ - fi; \ - $(top_srcdir)/build/missing --run git log --stat "$$spec") > $@.tmp \ - && mv -f $@.tmp $@ \ - || ($(RM) $@.tmp; \ - echo Failed to generate $@, your $@ may be outdated >&2); \ - else \ - echo A git checkout is required to generate $@ >&2; \ - fi - -.PHONY: changelogs ChangeLog $(srcdir)/ChangeLog diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.common b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.common deleted file mode 100644 index b955af58fdf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.common +++ /dev/null @@ -1,14 +0,0 @@ -BUILT_SOURCES = -CLEANFILES = -DISTCLEANFILES = -EXTRA_DIST = -EXTRA_LTLIBRARIES = -EXTRA_PROGRAMS = -MAINTAINERCLEANFILES = -TESTS = -check_PROGRAMS = - -CLEANFILES += *.i *.s *.gch -CLEANFILES += $(EXTRA_LTLIBRARIES) $(EXTRA_PROGRAMS) $(check_PROGRAMS) -DISTCLEANFILES += $(BUILT_SOURCES) -MAINTAINERCLEANFILES += Makefile.in diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.gtk-doc b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.gtk-doc deleted file mode 100644 index c3d642b097b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.gtk-doc +++ /dev/null @@ -1,190 +0,0 @@ -# BEFORE MODIFYING THIS FILE: -# -# This file is a descendant of an old copy of gtk-doc.make, modified for cairo minimally: -# -# - Moved to build/ -# - Made it append to EXTRA_DIST and CLEANFILES -# - Instead of all-local, make "doc" build docs, and err if gtk-doc not enabled -# - Some other changed introduced in 7f114b781f5c530d57530e5f76402e41cdabac6b -# -# Before changing it, check to see if a newer gtk-doc.make has fixed the issue you are facing. -# From time to time, it would be nice to udpate this to the latest copy of gtk-doc.make, but -# please do review all the differences and port our modifications forward. -# - -# -*- mode: makefile -*- - -#################################### -# Everything below here is generic # -#################################### - -if GTK_DOC_USE_LIBTOOL -GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -else -GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -endif - -# We set GPATH here; this gives us semantics for GNU make -# which are more like other make's VPATH, when it comes to -# whether a source that is a target of one rule is then -# searched for in VPATH/GPATH. -# -GPATH = $(srcdir) - -TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) - -EXTRA_DIST += \ - $(content_files) \ - $(HTML_IMAGES) \ - $(DOC_MAIN_SGML_FILE) \ - $(DOC_MODULE)-sections.txt \ - $(DOC_MODULE)-overrides.txt - -DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp \ - $(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp - -SCANOBJ_FILES = \ - $(DOC_MODULE).args \ - $(DOC_MODULE).hierarchy \ - $(DOC_MODULE).interfaces \ - $(DOC_MODULE).prerequisites \ - $(DOC_MODULE).signals - -REPORT_FILES = \ - $(DOC_MODULE)-undocumented.txt \ - $(DOC_MODULE)-undeclared.txt \ - $(DOC_MODULE)-unused.txt - -CLEANFILES += $(SCANOBJ_FILES) $(REPORT_FILES) $(DOC_STAMPS) - -if ENABLE_GTK_DOC -doc: html-build.stamp -else -doc: - @echo "*** gtk-doc must be installed (and --enable-gtk-doc) in order to make doc" - @false -endif - -docs: html-build.stamp - -#### scan #### - -scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB) $(EXTRA_HFILES) - @echo 'gtk-doc: Scanning header files' - @-chmod -R u+w $(srcdir) - gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="$(IGNORE_HFILES)" $(SCAN_OPTIONS) $(EXTRA_HFILES) --output-dir=$(srcdir) - if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null 2>&1 ; then \ - CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" CFLAGS="$(GTKDOC_CFLAGS)" LDFLAGS="$(GTKDOC_LIBS)" gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \ - else \ - cd $(srcdir) ; \ - for i in $(SCANOBJ_FILES) ; do \ - test -f $$i || touch $$i ; \ - done \ - fi - touch scan-build.stamp - -$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt: scan-build.stamp - @true - -#### templates #### - -tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt - @echo 'gtk-doc: Rebuilding template files' - @-chmod -R u+w $(srcdir) - cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE) $(MKTMPL_OPTIONS) - touch tmpl-build.stamp - -tmpl.stamp: tmpl-build.stamp - @true - -tmpl/*.sgml: - @true - - -#### xml #### - -# gtkdoc-mkdb is broken and requires a --root-dir=$(srcdir) option -# The _srcdir diversion is fragile but works for make check; make distcheck -sgml-build.stamp: tmpl.stamp $(HFILE_GLOB) $(CFILE_GLOB) $(DOC_MODULE)-sections.txt $(srcdir)/tmpl/*.sgml $(expand_content_files) - @echo 'gtk-doc: Building XML' - @-chmod -R u+w $(srcdir) - _srcdir="`pwd`/$(DOC_SOURCE_DIR)"; \ - cd $(srcdir) && gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$$_srcdir --output-format=xml --expand-content-files="$(expand_content_files)" --main-sgml-file=$(DOC_MAIN_SGML_FILE) $(MKDB_OPTIONS) - touch sgml-build.stamp - -sgml.stamp: sgml-build.stamp - @true - -#### html #### - -html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) - @echo 'gtk-doc: Building HTML' - @-chmod -R u+w $(srcdir) - rm -rf $(srcdir)/html - mkdir $(srcdir)/html - cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) - test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html ) - @echo 'gtk-doc: Fixing cross-references' - cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS) - touch html-build.stamp - -############## - -clean-local: - rm -f *~ *.bak - rm -rf .libs - -distclean-local: - cd $(srcdir) && \ - rm -rf xml $(REPORT_FILES) \ - $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt - -maintainer-clean-local: clean - cd $(srcdir) && rm -rf xml html - -install-data-local: - -installfiles=`echo $(srcdir)/html/*`; \ - if test "$$installfiles" = '$(srcdir)/html/*'; \ - then echo '-- Nothing to install' ; \ - else \ - $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR); \ - for i in $$installfiles; do \ - echo '-- Installing '$$i ; \ - $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \ - done; \ - echo '-- Installing $(srcdir)/html/index.sgml' ; \ - $(INSTALL_DATA) $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) || :; \ - which gtkdoc-rebase >/dev/null && \ - gtkdoc-rebase --relative --dest-dir=$(DESTDIR) --html-dir=$(DESTDIR)$(TARGET_DIR) ; \ - fi - - -uninstall-local: - rm -f $(DESTDIR)$(TARGET_DIR)/* - -# -# Require gtk-doc when making dist -# -if ENABLE_GTK_DOC -dist-check-gtkdoc: -else -dist-check-gtkdoc: - @echo "*** gtk-doc must be installed (and --enable-gtk-doc) in order to make dist" - @false -endif - -dist-hook: dist-check-gtkdoc dist-hook-local - mkdir $(distdir)/tmpl - mkdir $(distdir)/xml - mkdir $(distdir)/html - -cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl - -cp $(srcdir)/xml/*.xml $(distdir)/xml - cp $(srcdir)/html/* $(distdir)/html - -cp $(srcdir)/$(DOC_MODULE).types $(distdir)/ - -cp $(srcdir)/$(DOC_MODULE)-sections.txt $(distdir)/ - cd $(distdir) && rm -f $(DISTCLEANFILES) - -gtkdoc-rebase --online --relative --html-dir=$(distdir)/html - -.PHONY : dist-hook-local docs diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.releasing b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.releasing deleted file mode 100644 index b17faabce2f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.am.releasing +++ /dev/null @@ -1,194 +0,0 @@ -# Some custom targets to make it easier to release things. -# -# To make real stable releases or devel snapshots, use either: -# make release-check -# or make release-publish -# -# To make a quick properly named (date and git hash stamped) tarball: -# make snapshot - - -TAR_OPTIONS = --owner=0 --group=0 - -dist-hook: dist-clear-sticky-bits - -# Clean up any sticky bits we may inherit from parent dir -dist-clear-sticky-bits: - chmod -R a-s $(distdir) - - -snapshot: - distdir="$(distdir)-`date '+%Y%m%d'`"; \ - test -d "$(srcdir)/.git" && distdir=$$distdir-`cd "$(srcdir)" && git rev-parse HEAD | cut -c 1-6`; \ - TAR_OPTIONS="$(TAR_OPTIONS)" $(MAKE) $(AM_MAKEFLAGS) distdir="$$distdir" snapshot-dist - -snapshot-dist: dist - @(echo "$(distdir) archives ready for distribution: "; \ - list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ - sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' - -RELEASE_OR_SNAPSHOT = $$(if test "x$(CAIRO_VERSION_MINOR)" = "x$$(echo "$(CAIRO_VERSION_MINOR)/2*2" | bc)" ; then echo release; else echo snapshot; fi) -RELEASE_UPLOAD_HOST = cairographics.org -RELEASE_UPLOAD_BASE = /srv/cairo.freedesktop.org/www -RELEASE_UPLOAD_DIR = $(RELEASE_UPLOAD_BASE)/$(RELEASE_OR_SNAPSHOT)s -RELEASE_URL_BASE = http://cairographics.org/$(RELEASE_OR_SNAPSHOT)s -RELEASE_ANNOUNCE_LIST = cairo-announce@cairographics.org (and CC gnome-announce-list@gnome.org) - -MANUAL_VERSIONED = manual-$(VERSION) -MANUAL_TAR_FILE = $(MANUAL_VERSIONED).tar.gz -MANUAL_UPLOAD_DIR = $(RELEASE_UPLOAD_BASE) - -tar_file = $(PACKAGE)-$(VERSION).tar.xz -sha1_file = $(tar_file).sha1 -gpg_file = $(sha1_file).asc - -$(sha1_file): $(tar_file) - sha1sum $^ > $@ - -$(gpg_file): $(sha1_file) - @echo "Please enter your GPG password to sign the checksum." - gpg --armor --sign $^ - -release-verify-sane-changelogs: changelogs - @echo -n "Checking that the ChangeLog files are sane..." - @if grep -q "is required to generate" $(CHANGELOGS); then \ - (echo "Ouch." && echo "Some of the ChangeLogs are not generated correctly." \ - && echo "Remove ChangeLog* and make changelogs" \ - && false); else :; fi - @echo "Good." - -release-verify-sane-tests: - @echo "Checking that the test suite is sane..." - @cd test && $(MAKE) $(AM_MAKEFLAGS) release-verify-sane-tests - -release-verify-even-micro: - @echo -n "Checking that $(VERSION) has an even micro component..." - @test "$(CAIRO_VERSION_MICRO)" = "`echo $(CAIRO_VERSION_MICRO)/2*2 | bc`" \ - || (echo "Ouch." && echo "The version micro component '$(CAIRO_VERSION_MICRO)' is not an even number." \ - && echo "The version in configure.in must be incremented before a new release." \ - && false) - @echo "Good." - -release-verify-newer: - @echo -n "Checking that no $(VERSION) release already exists..." - @ssh $(RELEASE_UPLOAD_HOST) test ! -e $(RELEASE_UPLOAD_DIR)/$(tar_file) \ - || (echo "Ouch." && echo "Found: $(RELEASE_UPLOAD_HOST):$(RELEASE_UPLOAD_DIR)/$(tar_file)" \ - && echo "Are you sure you have an updated checkout?" \ - && echo "This should never happen." \ - && false) - @echo "Good." - -release-remove-old: - $(RM) $(tar_file) $(sha1_file) $(gpg_file) - - -# Strict ordering enforced for parallel make to work -release-check: \ - release-verify-even-micro \ - release-verify-sane-changelogs \ - release-verify-sane-tests \ - release-verify-newer \ - $(NULL) - $(MAKE) $(AM_MAKEFLAGS) release-remove-old - TAR_OPTIONS="$(TAR_OPTIONS)" $(MAKE) $(AM_MAKEFLAGS) distcheck - -release-upload: $(tar_file) $(sha1_file) $(gpg_file) - mkdir -p releases - scp $(tar_file) $(sha1_file) $(gpg_file) $(RELEASE_UPLOAD_HOST):$(RELEASE_UPLOAD_DIR) - mv $(tar_file) $(sha1_file) $(gpg_file) releases - ssh $(RELEASE_UPLOAD_HOST) "rm -f $(RELEASE_UPLOAD_DIR)/LATEST-$(PACKAGE)-[0-9]* && ln -s $(tar_file) $(RELEASE_UPLOAD_DIR)/LATEST-$(PACKAGE)-$(VERSION)" - git tag -s -m "cairo $(CAIRO_VERSION_MAJOR).$(CAIRO_VERSION_MINOR).$(CAIRO_VERSION_MICRO) release" $(CAIRO_VERSION_MAJOR).$(CAIRO_VERSION_MINOR).$(CAIRO_VERSION_MICRO) - -release-publish-message: releases/$(sha1_file) - @echo "Please follow the instructions in RELEASING to push stuff out and" - @echo "send out the announcement mails. Here is the excerpt you need:" - @echo "" - @echo "Subject: $(PACKAGE) $(RELEASE_OR_SNAPSHOT) $(VERSION) now available" - @echo "" - @echo "============================== CUT HERE ==============================" - @echo "A new $(PACKAGE) $(RELEASE_OR_SNAPSHOT) $(VERSION) is now available from:" - @echo "" - @echo " $(RELEASE_URL_BASE)/$(tar_file)" - @echo "" - @echo " which can be verified with:" - @echo "" - @echo " $(RELEASE_URL_BASE)/$(sha1_file)" - @echo -n " " - @cat releases/$(sha1_file) - @echo "" - @echo " $(RELEASE_URL_BASE)/$(gpg_file)" - @echo " (signed by `getent passwd "$$USER" | cut -d: -f 5 | cut -d, -f 1`)" - @echo "" - @echo " Additionally, a git clone of the source tree:" - @echo "" - @echo " git clone git://git.cairographics.org/git/cairo" - @echo "" - @echo " will include a signed $(VERSION) tag which points to a commit named:" - @echo " `git cat-file tag $(VERSION) | grep ^object | sed -e 's,object ,,'`" - @echo "" - @echo " which can be verified with:" - @echo " git verify-tag $(VERSION)" - @echo "" - @echo " and can be checked out with a command such as:" - @echo " git checkout -b build $(VERSION)" - @echo "" - @echo "============================== CUT HERE ==============================" - -doc-publish-versioned: doc - rm -rf ./$(MANUAL_VERSIONED) - cp -a doc/public/html $(MANUAL_VERSIONED) - tar czf $(MANUAL_TAR_FILE) $(MANUAL_VERSIONED) - scp $(MANUAL_TAR_FILE) $(RELEASE_UPLOAD_HOST):$(MANUAL_UPLOAD_DIR) - ssh $(RELEASE_UPLOAD_HOST) "cd $(MANUAL_UPLOAD_DIR) && tar xzf $(MANUAL_TAR_FILE) && ln -sf $(MANUAL_TAR_FILE) cairo-$(MANUAL_TAR_FILE)" - -doc-publish-symlinks: - ssh $(RELEASE_UPLOAD_HOST) "cd $(MANUAL_UPLOAD_DIR) && rm -f manual && ln -s $(MANUAL_VERSIONED) manual && ln -sf $(MANUAL_TAR_FILE) cairo-manual.tar.gz" - -doc-publish: - $(MAKE) $(AM_MAKEFLAGS) doc-publish-versioned - @if test "$(RELEASE_OR_SNAPSHOT)" = release; then $(MAKE) $(AM_MAKEFLAGS) doc-publish-symlinks; fi - -# Strict ordering enforced for parallel make to work -release-publish: release-check - $(MAKE) $(AM_MAKEFLAGS) release-upload - $(MAKE) $(AM_MAKEFLAGS) doc-publish - $(MAKE) $(AM_MAKEFLAGS) release-publish-message - -if OS_WIN32 - -# Win32 package zipfiles -runtime_zip_file = $(PACKAGE)-$(VERSION).zip -developer_zip_file = $(PACKAGE)-dev-$(VERSION).zip - -$(runtime_zip_file): install - -$(RM) $@ - pwd=`pwd`; cd $(prefix); \ - zip "$$pwd"/$@ bin/libcairo-$(CAIRO_VERSION_SONUM).dll - -$(developer_zip_file): install - -$(RM) $@ - pwd=`pwd`; cd $(prefix); \ - zip -r "$$pwd"/$@ include/cairo lib/libcairo.dll.a lib/cairo.lib lib/pkgconfig/cairo.pc lib/pkgconfig/cairo-*.pc share/gtk-doc/html/cairo - -zips: $(runtime_zip_file) $(developer_zip_file) - -endif - - -.PHONY: \ - dist-clear-sticky-bits \ - doc-publish \ - doc-publish-symlinks \ - doc-publish-versioned \ - release-check \ - release-publish \ - release-publish-message \ - release-remove-old \ - release-upload \ - release-verify-even-micro \ - release-verify-newer \ - release-verify-sane-changelogs \ - release-verify-sane-tests \ - snapshot \ - snapshot-dist \ - $(NULL) diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.common b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.common deleted file mode 100644 index 7d7e9735f15..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.common +++ /dev/null @@ -1,74 +0,0 @@ -default: all - -# -# Edit build/Makefile.win32.features to enable features to build -# -include $(top_srcdir)/build/Makefile.win32.inform -include $(top_srcdir)/build/Makefile.win32.features -include $(top_srcdir)/build/Makefile.win32.features-h - -ifeq ($(top_builddir),) -top_builddir = $(top_srcdir) -endif - -CC := cl -LD := link -AR := lib - -ifeq ($(CFG),debug) -CFG_CFLAGS := -MDd -Od -Zi -CFG_LDFLAGS := -DEBUG -else -CFG_CFLAGS := -MD -O2 -CFG_LDFLAGS := -endif - -ifeq ($(PIXMAN_PATH),) -PIXMAN_PATH := $(top_builddir)/../pixman -endif -PIXMAN_CFLAGS := -I$(PIXMAN_PATH)/pixman/ -PIXMAN_LIBS := $(PIXMAN_PATH)/pixman/$(CFG)/pixman-1.lib - -CAIRO_LIBS = gdi32.lib msimg32.lib user32.lib - -ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) -ifeq ($(LIBPNG_PATH),) -LIBPNG_PATH := $(top_builddir)/../libpng -endif -LIBPNG_CFLAGS += -I$(LIBPNG_PATH)/ -CAIRO_LIBS += $(LIBPNG_PATH)/libpng.lib -endif - -ifeq ($(CAIRO_HAS_PS_SURFACE)$(CAIRO_HAS_PDF_SURFACE),00) -else -ifeq ($(ZLIB_PATH),) -ZLIB_PATH := $(top_builddir)/../zlib -endif -ZLIB_CFLAGS += -I$(ZLIB_PATH)/ -CAIRO_LIBS += $(ZLIB_PATH)/zdll.lib -endif - -DEFAULT_CFLAGS = -nologo $(CFG_CFLAGS) -DEFAULT_CFLAGS += -I. -I$(top_srcdir) -I$(top_srcdir)/src -DEFAULT_CFLAGS += $(PIXMAN_CFLAGS) $(LIBPNG_CFLAGS) $(ZLIB_CFLAGS) - -CAIRO_CFLAGS = $(DEFAULT_CFLAGS) $(CFLAGS) - -DEFAULT_LDFLAGS = -nologo $(CFG_LDFLAGS) -DEFAULT_ARFLAGS = -nologo - -CAIRO_LDFLAGS = $(DEFAULT_LDFLAGS) $(LDFLAGS) -CAIRO_ARFLAGS = $(DEFAULT_ARFLAGS) $(LDFLAGS) - -# Some generic rules - -$(CFG)/%.obj: %.c $(top_srcdir)/src/cairo-features.h - @mkdir -p $(CFG)/`dirname $<` - @$(CC) $(CAIRO_CFLAGS) -c -Fo"$@" $< - -$(CFG)/%-static.obj: %.c $(top_srcdir)/src/cairo-features.h - @mkdir -p $(CFG)/`dirname $<` - @$(CC) $(CAIRO_CFLAGS) -c -DCAIRO_WIN32_STATIC_BUILD=1 -Fo"$@" $< - -clean: - @rm -f $(CFG)/*.obj $(CFG)/*.dll $(CFG)/*.lib $(CFG)/*.pdb $(CFG)/*.ilk || exit 0 diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features deleted file mode 100644 index 8cb155dc084..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by configure. Modify to customize. - -CAIRO_HAS_XLIB_SURFACE=0 -CAIRO_HAS_XLIB_XRENDER_SURFACE=0 -CAIRO_HAS_XCB_SURFACE=0 -CAIRO_HAS_XLIB_XCB_FUNCTIONS=0 -CAIRO_HAS_XCB_SHM_FUNCTIONS=0 -CAIRO_HAS_QT_SURFACE=0 -CAIRO_HAS_QUARTZ_SURFACE=0 -CAIRO_HAS_QUARTZ_FONT=0 -CAIRO_HAS_QUARTZ_IMAGE_SURFACE=0 -CAIRO_HAS_WIN32_SURFACE=1 -CAIRO_HAS_WIN32_FONT=1 -CAIRO_HAS_SKIA_SURFACE=0 -CAIRO_HAS_OS2_SURFACE=0 -CAIRO_HAS_BEOS_SURFACE=0 -CAIRO_HAS_DRM_SURFACE=0 -CAIRO_HAS_GALLIUM_SURFACE=0 -CAIRO_HAS_PNG_FUNCTIONS=1 -CAIRO_HAS_GL_SURFACE=0 -CAIRO_HAS_GLESV2_SURFACE=0 -CAIRO_HAS_COGL_SURFACE=0 -CAIRO_HAS_DIRECTFB_SURFACE=0 -CAIRO_HAS_VG_SURFACE=0 -CAIRO_HAS_EGL_FUNCTIONS=0 -CAIRO_HAS_GLX_FUNCTIONS=0 -CAIRO_HAS_WGL_FUNCTIONS=0 -CAIRO_HAS_SCRIPT_SURFACE=1 -CAIRO_HAS_FT_FONT=0 -CAIRO_HAS_FC_FONT=0 -CAIRO_HAS_PS_SURFACE=1 -CAIRO_HAS_PDF_SURFACE=1 -CAIRO_HAS_SVG_SURFACE=1 -CAIRO_HAS_TEST_SURFACES=0 -CAIRO_HAS_TEE_SURFACE=0 -CAIRO_HAS_XML_SURFACE=0 -CAIRO_HAS_PTHREAD=0 -CAIRO_HAS_GOBJECT_FUNCTIONS=0 -CAIRO_HAS_TRACE=0 -CAIRO_HAS_INTERPRETER=1 -CAIRO_HAS_SYMBOL_LOOKUP=0 diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features-h b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features-h deleted file mode 100644 index 13904cfa9f0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.features-h +++ /dev/null @@ -1,130 +0,0 @@ -# Generated by configure. Do not edit. - -$(top_srcdir)/src/cairo-features.h: $(top_srcdir)/build/Makefile.win32.features - @echo "Generating src/cairo-features.h" - @echo "/* Generated by Makefile.win32.features-h. Do not edit. */" > $(top_srcdir)/src/cairo-features.h - @echo "#ifndef CAIRO_FEATURES_H" >> $(top_srcdir)/src/cairo-features.h - @echo "#define CAIRO_FEATURES_H 1" >> $(top_srcdir)/src/cairo-features.h -ifeq ($(CAIRO_HAS_XLIB_SURFACE),1) - @echo "#define CAIRO_HAS_XLIB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_XLIB_XRENDER_SURFACE),1) - @echo "#define CAIRO_HAS_XLIB_XRENDER_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_XCB_SURFACE),1) - @echo "#define CAIRO_HAS_XCB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_XLIB_XCB_FUNCTIONS),1) - @echo "#define CAIRO_HAS_XLIB_XCB_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_XCB_SHM_FUNCTIONS),1) - @echo "#define CAIRO_HAS_XCB_SHM_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_QT_SURFACE),1) - @echo "#define CAIRO_HAS_QT_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_QUARTZ_SURFACE),1) - @echo "#define CAIRO_HAS_QUARTZ_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_QUARTZ_FONT),1) - @echo "#define CAIRO_HAS_QUARTZ_FONT 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_QUARTZ_IMAGE_SURFACE),1) - @echo "#define CAIRO_HAS_QUARTZ_IMAGE_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_WIN32_SURFACE),1) - @echo "#define CAIRO_HAS_WIN32_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_WIN32_FONT),1) - @echo "#define CAIRO_HAS_WIN32_FONT 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_SKIA_SURFACE),1) - @echo "#define CAIRO_HAS_SKIA_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_OS2_SURFACE),1) - @echo "#define CAIRO_HAS_OS2_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_BEOS_SURFACE),1) - @echo "#define CAIRO_HAS_BEOS_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_DRM_SURFACE),1) - @echo "#define CAIRO_HAS_DRM_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1) - @echo "#define CAIRO_HAS_GALLIUM_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) - @echo "#define CAIRO_HAS_PNG_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_GL_SURFACE),1) - @echo "#define CAIRO_HAS_GL_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_GLESV2_SURFACE),1) - @echo "#define CAIRO_HAS_GLESV2_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_COGL_SURFACE),1) - @echo "#define CAIRO_HAS_COGL_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1) - @echo "#define CAIRO_HAS_DIRECTFB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_VG_SURFACE),1) - @echo "#define CAIRO_HAS_VG_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1) - @echo "#define CAIRO_HAS_EGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_GLX_FUNCTIONS),1) - @echo "#define CAIRO_HAS_GLX_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1) - @echo "#define CAIRO_HAS_WGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1) - @echo "#define CAIRO_HAS_SCRIPT_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_FT_FONT),1) - @echo "#define CAIRO_HAS_FT_FONT 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_FC_FONT),1) - @echo "#define CAIRO_HAS_FC_FONT 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_PS_SURFACE),1) - @echo "#define CAIRO_HAS_PS_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_PDF_SURFACE),1) - @echo "#define CAIRO_HAS_PDF_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_SVG_SURFACE),1) - @echo "#define CAIRO_HAS_SVG_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_TEST_SURFACES),1) - @echo "#define CAIRO_HAS_TEST_SURFACES 1" >> $(top_srcdir)/src/cairo-features.h -endif - @echo "#define CAIRO_HAS_IMAGE_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h - @echo "#define CAIRO_HAS_MIME_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h - @echo "#define CAIRO_HAS_RECORDING_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h - @echo "#define CAIRO_HAS_OBSERVER_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -ifeq ($(CAIRO_HAS_TEE_SURFACE),1) - @echo "#define CAIRO_HAS_TEE_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_XML_SURFACE),1) - @echo "#define CAIRO_HAS_XML_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h -endif - @echo "#define CAIRO_HAS_USER_FONT 1" >> $(top_srcdir)/src/cairo-features.h -ifeq ($(CAIRO_HAS_PTHREAD),1) - @echo "#define CAIRO_HAS_PTHREAD 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_GOBJECT_FUNCTIONS),1) - @echo "#define CAIRO_HAS_GOBJECT_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_TRACE),1) - @echo "#define CAIRO_HAS_TRACE 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_INTERPRETER),1) - @echo "#define CAIRO_HAS_INTERPRETER 1" >> $(top_srcdir)/src/cairo-features.h -endif -ifeq ($(CAIRO_HAS_SYMBOL_LOOKUP),1) - @echo "#define CAIRO_HAS_SYMBOL_LOOKUP 1" >> $(top_srcdir)/src/cairo-features.h -endif - @echo "#endif" >> $(top_srcdir)/src/cairo-features.h diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.inform b/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.inform deleted file mode 100644 index ba11165050a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/Makefile.win32.inform +++ /dev/null @@ -1,13 +0,0 @@ -inform: - @echo -ifneq ($(CFG),release) -ifneq ($(CFG),debug) - @echo "Invalid configuration "$(CFG)" specified." - @echo -n "You must specify a configuration when " - @echo "running make, e.g. make CFG=debug" - @echo - @echo -n "Possible choices for configuration are " - @echo "'release' and 'debug'" - @exit 1 -endif -endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.cairo.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.cairo.m4 deleted file mode 100644 index 2f4873b043f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.cairo.m4 +++ /dev/null @@ -1,216 +0,0 @@ -dnl ========================================================================== -dnl -dnl Cairo-specific macros -dnl - -dnl ========================================================================== - -dnl Usage: -dnl CAIRO_BIGENDIAN -dnl -AC_DEFUN([CAIRO_BIGENDIAN], -[dnl - case $host_os in - darwin*) - AH_VERBATIM([X_BYTE_ORDER], -[ -/* Deal with multiple architecture compiles on Mac OS X */ -#ifdef __APPLE_CC__ -#ifdef __BIG_ENDIAN__ -#define WORDS_BIGENDIAN 1 -#define FLOAT_WORDS_BIGENDIAN 1 -#else -#undef WORDS_BIGENDIAN -#undef FLOAT_WORDS_BIGENDIAN -#endif -#endif -]) - ;; - *) - AC_C_BIGENDIAN - AX_C_FLOAT_WORDS_BIGENDIAN - ;; - esac -]) - -dnl CAIRO_CHECK_FUNCS_WITH_FLAGS(FUNCTION..., CFLAGS, LIBS -dnl [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Like AC_CHECK_FUNCS but with additional CFLAGS and LIBS -dnl -------------------------------------------------------------------- -AC_DEFUN([CAIRO_CHECK_FUNCS_WITH_FLAGS], -[dnl - _save_cflags="$CFLAGS" - _save_libs="$LIBS" - CFLAGS="$CFLAGS $2" - LIBS="$LIBS $3" - AC_CHECK_FUNCS($1, $4, $5) - CFLAGS="$_save_cflags" - LIBS="$_save_libs" -]) - -dnl CAIRO_CONFIG_COMMANDS is like AC_CONFIG_COMMANDS, except that: -dnl -dnl 1) It redirects the stdout of the command to the file. -dnl 2) It does not recreate the file if contents didn't change. -dnl -AC_DEFUN([CAIRO_CONFIG_COMMANDS], -[dnl - AC_CONFIG_COMMANDS($1, - [ - _config_file=$1 - _tmp_file=cairoconf.tmp - AC_MSG_NOTICE([creating $_config_file]) - { - $2 - } >> "$_tmp_file" || - AC_MSG_ERROR([failed to write to $_tmp_file]) - - if cmp -s "$_tmp_file" "$_config_file"; then - AC_MSG_NOTICE([$_config_file is unchanged]) - rm -f "$_tmp_file" - else - mv "$_tmp_file" "$_config_file" || - AC_MSG_ERROR([failed to update $_config_file]) - fi - ], $3) -]) - -dnl CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(env-setup, program, -dnl true-action, false-action) -dnl -dnl Compile and link the program with the given environment setup. -dnl The global cairo_cc_flag is set to "yes" or "no" according as -dnl the link succeeded or not. The link step must complete without -dnl warnings or errors to stderr. -dnl -dnl Perform true-action on success and false-action on failure. -dnl The values of CFLAGS, LIBS, LDFLAGS are saved before env-setup -dnl is executed and restored right before the end of the macro. -AC_DEFUN([CAIRO_CC_TRY_LINK_WITH_ENV_SILENT],[dnl - # AC_LANG_PROGRAM() produces a main() w/o args, - # but -Wold-style-definition doesn't like that. - # We need _some_ program so that we don't get - # warnings about empty compilation units, so always - # append a reasonable main(). - _compile_program="$2"' - int main(int c, char **v) { (void)c; (void)v; return 0; }' - - _save_cflags="$CFLAGS" - _save_ldflags="$LDFLAGS" - _save_libs="$LIBS" - $1 - AC_LINK_IFELSE( - [AC_LANG_SOURCE([$_compile_program])], - [cairo_cc_stderr=`test -f conftest.err && cat conftest.err` - cairo_cc_flag=yes], - [cairo_cc_stderr=`test -f conftest.err && cat conftest.err` - cairo_cc_flag=no]) - - if test "x$cairo_cc_stderr" != "x"; then - cairo_cc_flag=no - fi - - if test "x$cairo_cc_flag" = "xyes"; then - ifelse([$3], , :, [$3]) - else - ifelse([$4], , :, [$4]) - fi - CFLAGS="$_save_cflags" - LDFLAGS="$_save_ldflags" - LIBS="$_save_libs" -]) - -dnl check compiler flags with a program and no muttering. -AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT], -[dnl (flags..., optional program, true-action, false-action) - CAIRO_CC_TRY_LINK_WITH_ENV_SILENT([CFLAGS="$CFLAGS $1"], - [$2], [$3], [$4]) -]) - -dnl find a -Werror equivalent -AC_DEFUN([CAIRO_CC_CHECK_WERROR], -[dnl - _test_WERROR=${WERROR+set} - if test "z$_test_WERROR" != zset; then - WERROR="" - for _werror in -Werror -errwarn; do - AC_MSG_CHECKING([whether $CC supports $_werror]) - CAIRO_CC_TRY_FLAG_SILENT( - [$_werror],, - [WERROR="$WERROR $_werror"], - [:]) - AC_MSG_RESULT($cairo_cc_flag) - done - fi -]) - -dnl check compiler flags possibly using -Werror if available. -AC_DEFUN([CAIRO_CC_TRY_FLAG], -[dnl (flags..., optional program, true-action, false-action) - CAIRO_CC_CHECK_WERROR - AC_MSG_CHECKING([whether $CC supports $1]) - CAIRO_CC_TRY_FLAG_SILENT([$WERROR $1], [$2], [$3], [$4]) - AC_MSG_RESULT([$cairo_cc_flag]) -]) - -dnl Usage: -dnl CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES -AC_DEFUN([CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES], -[dnl - AC_CACHE_CHECK([for native atomic primitives], cairo_cv_atomic_primitives, - [ - cairo_cv_atomic_primitives="none" - - AC_TRY_LINK([ -int atomic_add(int i) { return __sync_fetch_and_add (&i, 1); } -int atomic_cmpxchg(int i, int j, int k) { return __sync_val_compare_and_swap (&i, j, k); } -], [], - cairo_cv_atomic_primitives="Intel" - ) - - if test "x$cairo_cv_atomic_primitives" = "xnone"; then - AC_CHECK_HEADER([atomic_ops.h], - cairo_cv_atomic_primitives="libatomic-ops") - fi - - if test "x$cairo_cv_atomic_primitives" = "xnone"; then - AC_CHECK_HEADER([libkern/OSAtomic.h], - cairo_cv_atomic_primitives="OSAtomic") - fi - ]) - if test "x$cairo_cv_atomic_primitives" = xIntel; then - AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, - [Enable if your compiler supports the Intel __sync_* atomic primitives]) - fi - - if test "x$cairo_cv_atomic_primitives" = "xlibatomic-ops"; then - AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, - [Enable if you have libatomic-ops-dev installed]) - fi - - if test "x$cairo_cv_atomic_primitives" = xOSAtomic; then - AC_DEFINE(HAVE_OS_ATOMIC_OPS, 1, - [Enable if you have MacOS X atomic operations]) - fi -]) - -dnl Usage: -dnl CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER -AC_DEFUN([CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER], -[dnl - AC_CACHE_CHECK([whether atomic ops require a memory barrier], cairo_cv_atomic_op_needs_memory_barrier, - [ - case $host_cpu in - i?86) cairo_cv_atomic_op_needs_memory_barrier="no" ;; - x86_64) cairo_cv_atomic_op_needs_memory_barrier="no" ;; - arm*) cairo_cv_atomic_op_needs_memory_barrier="no" ;; - *) cairo_cv_atomic_op_needs_memory_barrier="yes" ;; - esac - ]) - if test "x$cairo_cv_atomic_op_needs_memory_barrier" = "xyes"; then - AC_DEFINE_UNQUOTED(ATOMIC_OP_NEEDS_MEMORY_BARRIER, 1, - [whether memory barriers are needed around atomic operations]) - fi -]) - -AC_DEFUN([CAIRO_TEXT_WRAP], [m4_text_wrap([$1], [$2],, 78)]) diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.compare.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.compare.m4 deleted file mode 100644 index bd6c51b289d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.compare.m4 +++ /dev/null @@ -1,162 +0,0 @@ -dnl @synopsis AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) -dnl -dnl This macro compares two version strings. It is used heavily in the -dnl macro _AX_PATH_BDB for library checking. Due to the various number -dnl of minor-version numbers that can exist, and the fact that string -dnl comparisons are not compatible with numeric comparisons, this is -dnl not necessarily trivial to do in a autoconf script. This macro -dnl makes doing these comparisons easy. -dnl -dnl The six basic comparisons are available, as well as checking -dnl equality limited to a certain number of minor-version levels. -dnl -dnl The operator OP determines what type of comparison to do, and can -dnl be one of: -dnl -dnl eq - equal (test A == B) -dnl ne - not equal (test A != B) -dnl le - less than or equal (test A <= B) -dnl ge - greater than or equal (test A >= B) -dnl lt - less than (test A < B) -dnl gt - greater than (test A > B) -dnl -dnl Additionally, the eq and ne operator can have a number after it to -dnl limit the test to that number of minor versions. -dnl -dnl eq0 - equal up to the length of the shorter version -dnl ne0 - not equal up to the length of the shorter version -dnl eqN - equal up to N sub-version levels -dnl neN - not equal up to N sub-version levels -dnl -dnl When the condition is true, shell commands ACTION-IF-TRUE are run, -dnl otherwise shell commands ACTION-IF-FALSE are run. The environment -dnl variable 'ax_compare_version' is always set to either 'true' or -dnl 'false' as well. -dnl -dnl Examples: -dnl -dnl AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) -dnl AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) -dnl -dnl would both be true. -dnl -dnl AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) -dnl AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) -dnl -dnl would both be false. -dnl -dnl AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) -dnl -dnl would be true because it is only comparing two minor versions. -dnl -dnl AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) -dnl -dnl would be true because it is only comparing the lesser number of -dnl minor versions of the two values. -dnl -dnl Note: The characters that separate the version numbers do not -dnl matter. An empty string is the same as version 0. OP is evaluated -dnl by autoconf, not configure, so must be a string, not a variable. -dnl -dnl The author would like to acknowledge Guido Draheim whose advice -dnl about the m4_case and m4_ifvaln functions make this macro only -dnl include the portions necessary to perform the specific comparison -dnl specified by the OP argument in the final configure script. -dnl -dnl @category Misc -dnl @author Tim Toolan -dnl @version 2004-03-01 -dnl @license GPLWithACException - -dnl ######################################################################### -AC_DEFUN([AX_COMPARE_VERSION], [ - # Used to indicate true or false condition - ax_compare_version=false - - # Convert the two version strings to be compared into a format that - # allows a simple string comparison. The end result is that a version - # string of the form 1.12.5-r617 will be converted to the form - # 0001001200050617. In other words, each number is zero padded to four - # digits, and non digits are removed. - AS_VAR_PUSHDEF([A],[ax_compare_version_A]) - A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ - -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/[[^0-9]]//g'` - - AS_VAR_PUSHDEF([B],[ax_compare_version_B]) - B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ - -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/[[^0-9]]//g'` - - dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary - dnl # then the first line is used to determine if the condition is true. - dnl # The sed right after the echo is to remove any indented white space. - m4_case(m4_tolower($2), - [lt],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` - ], - [gt],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` - ], - [le],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` - ], - [ge],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` - ],[ - dnl Split the operator from the subversion count if present. - m4_bmatch(m4_substr($2,2), - [0],[ - # A count of zero means use the length of the shorter version. - # Determine the number of characters in A and B. - ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'` - ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'` - - # Set A to no more than B's length and B to no more than A's length. - A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` - B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` - ], - [[0-9]+],[ - # A count greater than zero means use only that many subversions - A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` - B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` - ], - [.+],[ - AC_WARNING( - [illegal OP numeric parameter: $2]) - ],[]) - - # Pad zeros at end of numbers to make same length. - ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" - B="$B`echo $A | sed 's/./0/g'`" - A="$ax_compare_version_tmp_A" - - # Check for equality or inequality as necessary. - m4_case(m4_tolower(m4_substr($2,0,2)), - [eq],[ - test "x$A" = "x$B" && ax_compare_version=true - ], - [ne],[ - test "x$A" != "x$B" && ax_compare_version=true - ],[ - AC_WARNING([illegal OP parameter: $2]) - ]) - ]) - - AS_VAR_POPDEF([A])dnl - AS_VAR_POPDEF([B])dnl - - dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. - if test "$ax_compare_version" = "true" ; then - m4_ifvaln([$4],[$4],[:])dnl - m4_ifvaln([$5],[else $5])dnl - fi -]) dnl AX_COMPARE_VERSION diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.enable.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.enable.m4 deleted file mode 100644 index f3522b9832c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.enable.m4 +++ /dev/null @@ -1,409 +0,0 @@ -dnl -dnl These are the facilities for enable/disabling various features, -dnl and for collecting CFLAGS/LIBS and generating per feature .pc -dnl files, assembling list of source files to compile, creating -dnl cairo-features.h and other generated files, etc... -dnl - -dnl =========================================================================== - -dnl -dnl Define a macro to enable features -dnl - Macro: _CAIRO_ENABLE (ID, NAME, WHAT, DEFAULT, COMMANDS) -dnl -dnl where: -dnl -dnl ID is the sub-namespace in function names, eg. "ft" for cairo_ft_... -dnl NAME is the human-readable name of the feature, eg. "FreeType font" -dnl WHAT is the type of feature: -dnl "surface" for surface backends -dnl "font" for font backends -dnl "functions" for set of functions -dnl "" for private configurations -dnl DEFAULT is the default state of the feature: -dnl "no" for experimental features, eg. your favorite new backend -dnl "yes" for recommended features, eg. png functions -dnl "auto" for other supported features, eg. xlib surface backend -dnl "always" for mandatory features (can't be disabled), eg. image surface backend -dnl COMMANDS are run to check whether the feature can be enabled. -dnl They should set use_$(ID) to something other than yes if the -dnl feature cannot be built, eg. "no (requires SomeThing)". It then -dnl should also set $(ID)_REQUIRES/CFLAGS/LIBS/... -dnl appropriately. Look at the macro definition for more details, -dnl or ask if in doubt. -dnl -AC_DEFUN([_CAIRO_ENABLE], -[dnl - dnl Sanity check ID - m4_if( - [$1], - m4_tolower(AS_TR_SH([$1])), - , - [m4_fatal([invalid feature name `$1'])] - )dnl - m4_pushdef([cr_feature], [$1])dnl - m4_pushdef([cr_feature_name], m4_normalize([$2]))dnl - m4_pushdef([cr_feature_what], m4_normalize([$3]))dnl - m4_pushdef([cr_feature_default], m4_normalize([$4]))dnl - m4_pushdef([cr_feature_commands], [$5])dnl - dnl - m4_pushdef([cr_feature_arg], m4_translit([$1],_,-))dnl - dnl - dnl Sanity check default - m4_case( - cr_feature_default, - [no],, - [yes],, - [auto],, - [always],, - [m4_fatal([Invalid default value `]cr_feature_default[' for feature `]cr_feature['])] - )dnl - dnl - m4_if(cr_feature_default, [always], - [dnl - enable_$1=yes - ],[dnl - AC_ARG_ENABLE(cr_feature_arg, - AS_HELP_STRING([--enable-]cr_feature_arg[=@<:@no/auto/yes@:>@], - [Enable cairo's ]cr_feature_name[ feature @<:@default=]cr_feature_default[@:>@]), - enable_$1=$enableval, enable_$1=cr_feature_default) - ])dnl - dnl - AS_CASE([$enable_$1], - [no],[dnl - use_$1="no (disabled, use --enable-cr_feature_arg to enable)" - ],dnl - [yes|auto],[dnl - AC_MSG_CHECKING([for cairo's ]cr_feature_name[ feature]) - echo - - use_[]$1=yes - CAIRO_FEATURE_VARS_FOREACH(cr_var, [cr_feature[_]cr_var[=]_CAIRO_SH_ESCAPE_UNQUOTED(m4_do([cr_var_default_]cr_var[_value]))]m4_newline) - - cr_feature_commands - - AC_MSG_CHECKING([whether cairo's ]cr_feature_name[ feature could be enabled]) - AC_MSG_RESULT([$use_$1]) - - AS_IF([test "x$enable_$1" = "xyes" -a "x$use_$1" != xyes], - [dnl - AC_MSG_ERROR( - m4_case(cr_feature_default, - [always], [mandatory], - [yes], [recommended], - , [requested] - ) cr_feature_name[ feature could not be enabled]) - ])dnl - ],dnl - [dnl - AC_MSG_ERROR([invalid argument passed to --enable-]cr_feature_arg[: `$use_$1', should be one of @<:@no/auto/yes@:>@]) - ])dnl - - AS_IF([test "x$use_$1" = "xyes"], - [dnl - CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH([cr_var], - [dnl - CAIRO_ACCUMULATE_UNQUOTED_BEFORE(cr_var, [$]cr_feature[_]cr_var) - ])dnl - ],[dnl - dnl If not enabled, empty the vars so no one accidentally uses them. - CAIRO_FEATURE_VARS_FOREACH([cr_var], [unset cr_feature[_]cr_var]m4_newline) - ])dnl - - _CAIRO_FEATURE_HOOKS(cr_feature, cr_feature_name, cr_feature_default, cr_feature_what)dnl - - m4_popdef([cr_feature])dnl - m4_popdef([cr_feature_name])dnl - m4_popdef([cr_feature_what])dnl - m4_popdef([cr_feature_default])dnl - m4_popdef([cr_feature_commands])dnl - m4_popdef([cr_feature_arg])dnl -]) - - -dnl =========================================================================== - -m4_define([_CAIRO_FEATURE_VARS]) - -dnl -dnl CAIRO_FEATURE_VARS_REGISTER(VARS, DEFAULT-VALUE=[]) -dnl -dnl Registers variables to be collected from feature-enabling code segments. -dnl VARS should be a whitespace-separate list of variable names. -dnl -dnl DEFAULT-VALUE is m4 macros to set default value of VARS -dnl -AC_DEFUN([CAIRO_FEATURE_VARS_REGISTER], -[dnl - m4_foreach_w([cr_var], [$1], - [m4_append_uniq([_CAIRO_FEATURE_VARS], cr_var, [ ],, - [m4_fatal([Feature variable `]cr_var[' already registered])])])dnl - m4_foreach_w([cr_var], [$1], - [dnl - m4_define([cr_var_default_]cr_var[_value], m4_default([$2],[[$ac_env_[]]cr_feature[[]_]]cr_var[[_value]]))dnl - ])dnl -]) - -dnl -dnl CAIRO_FEATURE_VARS_FOREACH(VAR, COMMANDS) -dnl -dnl Run COMMANDS for each registered feature variable. -dnl Defines VAR to the variable being processed. -dnl -AC_DEFUN([CAIRO_FEATURE_VARS_FOREACH], -[dnl - m4_foreach_w([$1], _CAIRO_FEATURE_VARS, [$2])dnl -]) - - -dnl =========================================================================== - -m4_define([_CAIRO_ACCUMULATORS])dnl - -m4_define([_CAIRO_ACCUMULATORS_REGISTER], -[dnl - m4_foreach_w([cr_var], [$1], - [m4_append_uniq([_CAIRO_ACCUMULATORS], cr_var, [ ],, - [m4_fatal([Accumulator `]cr_var[' already registered])])])dnl - m4_foreach_w([cr_var], [$1], [m4_define([cr_acc_]cr_var[_sep], [$2])])dnl - m4_foreach_w([cr_var], [$1], [[CAIRO_]cr_var[=$3]]m4_newline)dnl - m4_foreach_w([cr_var], [$1], [m4_pattern_allow([CAIRO_]cr_var)])dnl -])dnl - -m4_define([_CAIRO_SH_ESCAPE],['m4_bpatsubst([$1],['],[\\'])'])dnl -m4_define([_CAIRO_SH_ESCAPE_UNQUOTED],["m4_bpatsubst([$1],["],[\\"])"])dnl - -dnl -dnl CAIRO_ACCUMULATORS_REGISTER(VARS, SEPARATOR=[], INITIAL-VALUE=[]) -dnl -dnl Registers accumulators. An accumulator is a shell variable that can -dnl be accumulated to. The macros take care of adding a SEPARATOR between -dnl accumulated values. -dnl -dnl VARS should be a whitespace-separate list of variable names. The actual -dnl shell variable resulting for each variable is prefixed with CAIRO_. -dnl -AC_DEFUN([CAIRO_ACCUMULATORS_REGISTER], -[dnl - _CAIRO_ACCUMULATORS_REGISTER([$1],[$2],_CAIRO_SH_ESCAPE([$3]))dnl -])dnl - -dnl -dnl Like CAIRO_ACCUMULATORS_REGISTER but INITIAL-VALUE is left unquoted, -dnl so it can reference other shell variables for example. -dnl -AC_DEFUN([CAIRO_ACCUMULATORS_REGISTER_UNQUOTED], -[dnl - _CAIRO_ACCUMULATORS_REGISTER([$1],[$2],_CAIRO_SH_ESCAPE_UNQUOTED([$3]))dnl -])dnl - -m4_define([_CAIRO_ACCUMULATOR_CHECK], -[dnl - m4_ifdef([cr_acc_$1_sep],,[m4_fatal([Accumulator `]$1[' not defined.])])dnl -])dnl - -m4_define([_CAIRO_ACCUMULATE], -[dnl - _CAIRO_ACCUMULATOR_CHECK([$1])dnl - m4_ifval([$2], [$3]m4_newline)dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATE(VAR, VALUE) -dnl -dnl Appends VALUE to accumulator VAR -dnl -AC_DEFUN([CAIRO_ACCUMULATE], -[dnl - _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["_CAIRO_SH_ESCAPE([$2])])dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATE_BEFORE(VAR, VALUE) -dnl -dnl Prepends VALUE to accumulator VAR -dnl -AC_DEFUN([CAIRO_ACCUMULATE_BEFORE], -[dnl - _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1=_CAIRO_SH_ESCAPE([$2])"]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl -])dnl - -m4_define([_CAIRO_ACCUMULATE_UNQUOTED], -[dnl - _CAIRO_ACCUMULATOR_CHECK([$1])dnl - m4_ifval([$2], [m4_bmatch([$2],[[$]],[test -n "$2" &&]) $3]m4_newline)dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATE_UNQUOTED(VAR, VALUE) -dnl -dnl Like CAIRO_ACCUMULATE but VALUE is left unquoted, -dnl so it can reference other shell variables for example. -dnl -AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED], -[dnl - _CAIRO_ACCUMULATE_UNQUOTED([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["]_CAIRO_SH_ESCAPE_UNQUOTED([$2]))dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATE_UNQUOTED_BEFORE(VAR, VALUE) -dnl -dnl Like CAIRO_ACCUMULATE_BEFORE but VALUE is left unquoted, -dnl so it can reference other shell variables for example. -dnl -AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_BEFORE], -[dnl - _CAIRO_ACCUMULATE_UNQUOTED([$1], [$2], [CAIRO_$1=]_CAIRO_SH_ESCAPE_UNQUOTED([$2])["]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED(VAR, VALUE) -dnl -dnl Like CAIRO_ACCUMULATE_UNQUOTED but VALUE is not tested for emptiness. -dnl -AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED], -[dnl - _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["]_CAIRO_SH_ESCAPE_UNQUOTED([$2]))dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED_BEFORE(VAR, VALUE) -dnl -dnl Like CAIRO_ACCUMULATE_UNQUOTED_BEFORE but VALUE is not tested for emptiness. -dnl -AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_BEFORE], -[dnl - _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1=]_CAIRO_SH_ESCAPE_UNQUOTED([$2])["]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATORS_FOREACH(VAR, COMMANDS) -dnl -dnl Run COMMANDS for each registered accumulator. -dnl Defines VAR to the accumulator being processed. -dnl -AC_DEFUN([CAIRO_ACCUMULATORS_FOREACH], -[dnl - m4_foreach_w([$1], _CAIRO_ACCUMULATORS, [$2])dnl -])dnl - - -dnl =========================================================================== - -m4_define([_CAIRO_ACCUMULATED_FEATURE_VARS])dnl - -dnl -dnl CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER(VARS, DEFAULT-VALUE=[], SEPARATOR=[], INITIAL-VALUE=[]) -dnl -dnl Defines VARS as feature variables and accumulators. Also accumulates -dnl (prepending, not appending) feature values for VARS. -dnl -AC_DEFUN([CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER], -[dnl - m4_foreach_w([cr_var], [$1], - [m4_append_uniq([_CAIRO_ACCUMULATED_FEATURE_VARS], cr_var, [ ],, - [m4_fatal([Accumulated feature variable `]cr_var[' already registered])])])dnl - CAIRO_FEATURE_VARS_REGISTER([$1],[$2])dnl - CAIRO_ACCUMULATORS_REGISTER_UNQUOTED([$1],[$3],[$4])dnl -])dnl - -dnl -dnl CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH(VAR, COMMANDS) -dnl -dnl Run COMMANDS for each registered accumulated feature variable. -dnl Defines VAR to the variable being processed. -dnl -AC_DEFUN([CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH], -[dnl - m4_foreach_w([$1], _CAIRO_ACCUMULATED_FEATURE_VARS, [$2])dnl -])dnl - -dnl =========================================================================== - -dnl -dnl CAIRO_FEATURE_IF_ENABLED(FEATURE=cr_feature, COMMANDS) -dnl -dnl Run COMMANDS if FEATURE is enabled. -dnl -AC_DEFUN([CAIRO_FEATURE_IF_ENABLED], -[dnl - AS_IF([test "x$use_]m4_default([$1], cr_feature)[" = xyes], [$2], [$3])dnl -])dnl - -m4_define([_CAIRO_FEATURE_HOOK_MATCH_SH_BOOL], -[dnl - m4_case([$1], - [*], [$3], - [no], [AS_IF([test "x$2" != xyes], [:m4_newline()$3])], - [yes], [AS_IF([test "x$2" = xyes], [:m4_newline()$3])], - [m4_fatal([Invalid ENABLED value `]$1['])])dnl -])dnl - -m4_define([_CAIRO_FEATURE_HOOK_MATCH_M4], -[dnl - m4_case([$1], - [*], [$3], - [$2], [$3], - [!$2], , - [m4_bmatch([$1], [^!], [$3])])dnl -])dnl - -m4_define([_CAIRO_FEATURE_HOOKS])dnl - -dnl -dnl CAIRO_FEATURE_HOOK_REGISTER(ENABLED, DEFAULT, WHAT, COMMANDS) -dnl -dnl ENABLED is the feature enabledness to match -dnl DEFAULT is the default value of features to match -dnl WHAT is the type of features to match -dnl COMMANDS is commands to run for matched features. -dnl -dnl Runs COMMANDS for features matching ENABLED, DEFAULT, and WHAT. -dnl Hooks are run for each feature in the order they are added. -dnl -dnl DEFAULT and WHAT are matched like this: -dnl [*] matches all values -dnl [val] matches [val] -dnl [!val] matches anything other than [val] -dnl -dnl ENABLED is matched like this: -dnl [yes] matches enabled features -dnl [no] matches disabled features -dnl [*] matches all features -dnl -dnl The following macros can be used in COMMANDS: -dnl -dnl cr_feature expands to the feature id, eg "ft" -dnl cr_feature_name expands to the human-readable name of the feature, eg. "FreeType font" -dnl cr_feature_default expands to the default state of the feature: -dnl "no" for experimental features, eg. your favorite new backend -dnl "yes" for recommended features, eg. png functions -dnl "auto" for other supported features, eg. xlib surface backend -dnl "always" for mandatory features (can't be disabled), eg. image surface backend -dnl cr_what expands to the type of feature: -dnl "surface" for surface backends -dnl "font" for font backends -dnl "functions" for set of functions -dnl "" for private configurations -dnl -dnl These four values are also set as $1 to $4. To know if feature was -dnl enabled from within COMMANDS, use CAIRO_FEATURE_IF_ENABLED: -dnl -dnl CAIRO_FEATURE_IF_ENABLED($1, [IF-ENABLED], [IF-DISABLED]) -dnl -dnl or compare $use_$1 to string "yes". As in: -dnl -dnl AS_IF([test "x$use_$1" = "xyes"], [IF-ENABLED], [IF-DISABLED]) -dnl -AC_DEFUN([CAIRO_FEATURE_HOOK_REGISTER], -[dnl - m4_append([_CAIRO_FEATURE_HOOKS], - [dnl - _CAIRO_FEATURE_HOOK_MATCH_M4([$2], cr_feature_default, - [_CAIRO_FEATURE_HOOK_MATCH_M4([$3], cr_feature_what, - [_CAIRO_FEATURE_HOOK_MATCH_SH_BOOL([$1], [$use_]cr_feature, - [$4] - )])])dnl - ], m4_newline)dnl -])dnl - diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.float.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.float.m4 deleted file mode 100644 index 8f85f0862ba..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.float.m4 +++ /dev/null @@ -1,65 +0,0 @@ -# AX_C_FLOAT_WORDS_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], -# [ACTION-IF-UNKNOWN]) -# -# Checks the ordering of words within a multi-word float. This check -# is necessary because on some systems (e.g. certain ARM systems), the -# float word ordering can be different from the byte ordering. In a -# multi-word float context, "big-endian" implies that the word containing -# the sign bit is found in the memory location with the lowest address. -# This implemenation was inspired by the AC_C_BIGENDIAN macro in autoconf. -# ------------------------------------------------------------------------- -AC_DEFUN([AX_C_FLOAT_WORDS_BIGENDIAN], - [AC_CACHE_CHECK(whether float word ordering is bigendian, - ax_cv_c_float_words_bigendian, [ - -# The endianess is detected by first compiling C code that contains a special -# double float value, then grepping the resulting object file for certain -# strings of ascii values. The double is specially crafted to have a -# binary representation that corresponds with a simple string. In this -# implementation, the string "noonsees" was selected because the individual -# word values ("noon" and "sees") are palindromes, thus making this test -# byte-order agnostic. If grep finds the string "noonsees" in the object -# file, the target platform stores float words in big-endian order. If grep -# finds "seesnoon", float words are in little-endian order. If neither value -# is found, the user is instructed to specify the ordering. - -ax_cv_c_float_words_bigendian=unknown -AC_LINK_IFELSE([AC_LANG_SOURCE([[ - -double d __attribute__((used)) = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0; -int main() { return 0; } - -]])], [ - -if strings - conftest$ac_exeext | grep noonsees >/dev/null ; then - ax_cv_c_float_words_bigendian=yes -fi -if strings - conftest$ac_exeext | grep seesnoon >/dev/null ; then - if test "$ax_cv_c_float_words_bigendian" = unknown; then - ax_cv_c_float_words_bigendian=no - else - ax_cv_c_float_words_bigendian=unknown - fi -fi - -])]) - -case $ax_cv_c_float_words_bigendian in - yes) - m4_default([$1], - [AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1, - [Define to 1 if your system stores words within floats - with the most significant word first])]) ;; - no) - $2 ;; - *) - m4_default([$3], - [AC_MSG_ERROR([ - -Unknown float word ordering. You need to manually preset -ax_cv_c_float_words_bigendian=no (or yes) according to your system. - - ])]) ;; -esac - -])# AX_C_FLOAT_WORDS_BIGENDIAN diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.makefile.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.makefile.m4 deleted file mode 100644 index 70777810d14..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.makefile.m4 +++ /dev/null @@ -1,234 +0,0 @@ -dnl -dnl These are the facilities for generating Makefile.am.features and -dnl Makefile.win32.features files. -dnl - -dnl =========================================================================== - -dnl -dnl Define cr_feature_tag ala other cr_feature_* macros -dnl Expands to CAIRO_HAS_FEATURE_ID -dnl -m4_define([_CAIRO_BUILD_FEATURE_TAG_NORMALIZED], - [CAIRO_HAS_[$1]m4_bmatch([$1],[$2$],,[$2])])dnl -m4_define([_CAIRO_BUILD_FEATURE_TAG], - [_CAIRO_BUILD_FEATURE_TAG_NORMALIZED(AS_TR_CPP([$1]),AS_TR_CPP(m4_ifval([$2],[ $2])))])dnl -m4_define([cr_feature_tag], - [_CAIRO_BUILD_FEATURE_TAG(cr_feature,cr_feature_what)])dnl - - -dnl =========================================================================== -dnl -dnl CAIRO_INIT_MAKEFILES([AUX-DIR]) -dnl -dnl Sets up automake and win32 conditionals for all features -dnl -AC_DEFUN([CAIRO_INIT_MAKEFILES], -[dnl - dnl Allow feature tags in the output - m4_pattern_allow(^CAIRO_HAS_)dnl - - dnl Automake conditionals for non-builtin features - CAIRO_FEATURE_HOOK_REGISTER(*,!always,*, - [dnl - AM_CONDITIONAL(cr_feature_tag, [test "x$use_]cr_feature[" = xyes])dnl - ])dnl - - CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([_],[$1],[],[[# Generated by configure. Modify to customize.]])dnl - CAIRO_MAKEFILE_ACCUMULATE_FEATURE([_],*,!always,*,[cr_feature_tag=m4_if(cr_feature_default,[yes],1,[m4_bmatch(cr_feature,[win32],1,0)])])dnl -])dnl - -dnl =========================================================================== - -m4_define([_CAIRO_MAKEFILES])dnl - -dnl -dnl CAIRO_CONFIG_MAKEFILE(TAG, DIR, [SUFFIX], [HEADER]) -dnl -dnl Create DIR/Makefile.{am,win32}.SUFFIX files -dnl TAG is a TAG used by other CAIRO_MAKEFILE_* macros to append to these -dnl Makefile's. -dnl -dnl HEADER is appended at the top of the Makefile's. If HEADER is not -dnl set, the generic "Generated by configure. Do not edit." comment -dnl is added. -dnl -AC_DEFUN([CAIRO_CONFIG_MAKEFILE], -[dnl - m4_append_uniq([_CAIRO_MAKEFILES], [$1], [ ])dnl - CAIRO_CONFIG_MAKEFILE_PRIVATE([$1], [$2], [$3], [$4])dnl -])dnl - -dnl Like CAIRO_CONFIG_MAKEFILE but only generate win32 makefile -AC_DEFUN([CAIRO_CONFIG_MAKEFILE_WIN32], -[dnl - m4_append_uniq([_CAIRO_MAKEFILES], [$1], [ ])dnl - CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([$1], [$2], [$3], [$4])dnl -])dnl - -dnl Like CAIRO_CONFIG_MAKEFILE but only generate automake makefile -AC_DEFUN([CAIRO_CONFIG_MAKEFILE_AMAKE], -[dnl - m4_append_uniq([_CAIRO_MAKEFILES], [$1], [ ])dnl - CAIRO_CONFIG_MAKEFILE_PRIVATE_AMAKE([$1], [$2], [$3], [$4])dnl -])dnl - -dnl -dnl CAIRO_CONFIG_MAKEFILE_PRIVATE(TAG, DIR, [SUFFIX], [HEADER]) -dnl -dnl Like CAIRO_CONFIG_MAKEFILE but this makefile tag won't match -dnl against '*' in makefile accumulators. -dnl -AC_DEFUN([CAIRO_CONFIG_MAKEFILE_PRIVATE], -[dnl - m4_ifdef([cr_make_$1_dir], - [m4_fatal([Makefile `$1' already registered])])dnl - m4_define([cr_make_$1_dir],[$2])dnl - - CAIRO_CONFIG_MAKEFILE_PRIVATE_AMAKE([$1], [$2], [$3], [$4])dnl - CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([$1], [$2], [$3], [$4])dnl -])dnl - -dnl Like CAIRO_CONFIG_MAKEFILE_PRIVATE but only generate automake makefile -AC_DEFUN([CAIRO_CONFIG_MAKEFILE_PRIVATE_AMAKE], -[dnl - m4_ifdef([cr_make_$1_dir_amake], - [m4_fatal([Automake makefile `$1' already registered])])dnl - m4_define([cr_make_$1_dir_amake],[$2])dnl - m4_define([cr_make_$1_dir_any],[$2])dnl - - dnl Accumulators - CAIRO_ACCUMULATORS_REGISTER(MAKEFILE_$1_AMAKE, m4_newline, m4_default([$4],[[# Generated by configure. Do not edit.]])m4_newline)dnl - - dnl Generate - CAIRO_CONFIG_COMMANDS([$srcdir/]m4_if([$2],[.],,[$2/])[Makefile.am.]m4_default([$3],[features]), - [echo "$CAIRO_MAKEFILE_$1_AMAKE"], - [CAIRO_MAKEFILE_$1_AMAKE='$CAIRO_MAKEFILE_$1_AMAKE'])dnl -])dnl - -dnl Like CAIRO_CONFIG_MAKEFILE_PRIVATE but only generate win32 makefile -AC_DEFUN([CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32], -[dnl - m4_ifdef([cr_make_$1_dir_win32], - [m4_fatal([Win32 makefile `$1' already registered])])dnl - m4_define([cr_make_$1_dir_win32],[$2])dnl - m4_define([cr_make_$1_dir_any],[$2])dnl - - dnl Accumulators - CAIRO_ACCUMULATORS_REGISTER(MAKEFILE_$1_WIN32, m4_newline, m4_default([$4],[[# Generated by configure. Do not edit.]])m4_newline)dnl - - dnl Generate - CAIRO_CONFIG_COMMANDS([$srcdir/]m4_if([$2],[.],,[$2/])[Makefile.win32.]m4_default([$3],[features]), - [echo "$CAIRO_MAKEFILE_$1_WIN32"], - [CAIRO_MAKEFILE_$1_WIN32='$CAIRO_MAKEFILE_$1_WIN32'])dnl -])dnl - - -m4_define([_CAIRO_MAKEFILE_CHECK], -[dnl - m4_ifdef([cr_make_$1_dir_any],,[m4_fatal([Makefile `]$1[' not defined.])])dnl -])dnl - - -dnl -dnl CAIRO_MAKEFILE_INCLUDE(TAG, FILE) -dnl -dnl Include FILE from Makefile's for TAG. FILE should be placed -dnl relative to directory for TAG. If TAG is *, FILE is included from -dnl all Makefile's. -dnl -AC_DEFUN([CAIRO_MAKEFILE_INCLUDE], -[dnl - m4_if([$1],[*],,[_CAIRO_MAKEFILE_CHECK([$1])])dnl - m4_foreach_w([cr_makefile], m4_if([$1],[*],_CAIRO_MAKEFILES,[$1]), - [dnl - m4_ifdef([cr_make_]cr_makefile[_dir_amake],dnl - [CAIRO_ACCUMULATE([MAKEFILE_]cr_makefile[_AMAKE],[include $(top_srcdir)/cr_make_]cr_makefile[_dir_amake/$2]m4_newline)] - )dnl - m4_ifdef([cr_make_]cr_makefile[_dir_win32],dnl - [CAIRO_ACCUMULATE([MAKEFILE_]cr_makefile[_WIN32],[ifeq ($(top_srcdir),)]m4_newline[include $2]m4_newline[else]m4_newline[include $(top_srcdir)/cr_make_]cr_makefile[_dir_win32/$2]m4_newline[endif]m4_newline)] - )dnl - ])dnl -])dnl - - -m4_pattern_allow([cr_make_tmp]) - -dnl -dnl CAIRO_MAKEFILE_ACCUMULATE(TAG, CONTENT) -dnl -dnl Accumulates CONTENT to Makefile's for TAG. If TAG is *, -dnl CONTENT is added to all Makefile's. -dnl -AC_DEFUN([CAIRO_MAKEFILE_ACCUMULATE], -[dnl - m4_if([$1],[*],,[_CAIRO_MAKEFILE_CHECK([$1])])dnl - m4_foreach_w([cr_makefile], m4_if([$1],[*],_CAIRO_MAKEFILES,[$1]), - [dnl - m4_pushdef([cr_make_acc_contents],[$2])dnl - cr_make_tmp=_CAIRO_SH_ESCAPE(cr_make_acc_contents(cr_makefile)) - m4_popdef([cr_make_acc_contents])dnl - m4_ifdef([cr_make_]cr_makefile[_dir_amake],dnl - [CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED([MAKEFILE_]cr_makefile[_AMAKE], [$cr_make_tmp])] - )dnl - m4_ifdef([cr_make_]cr_makefile[_dir_win32],dnl - [CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED([MAKEFILE_]cr_makefile[_WIN32], [$cr_make_tmp])] - )dnl - ])dnl -])dnl - -m4_define([_CAIRO_MAKEFILE_ACCUMULATE_FEATURE], -[dnl - dnl Don't do a conditional for default=always features - m4_pushdef([cr_mk_acc_feat_enabled],m4_if([$2],[yes],[m4_if(cr_feature_default,[always],[*],[$2])],[$2]))dnl - m4_case(cr_mk_acc_feat_enabled, - [*],, - [yes], [CAIRO_ACCUMULATE([$1], [$3])], - [no], [CAIRO_ACCUMULATE([$1], [$3]m4_newline[$4])], - [m4_fatal([Invalid ENABLED value `]$2['])])dnl - CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED([$1], [$6])dnl - m4_case(cr_mk_acc_feat_enabled, - [*],, - [yes], [CAIRO_ACCUMULATE([$1], [$5])], - [no], [CAIRO_ACCUMULATE([$1], [$5])], - [m4_fatal([Invalid ENABLED value `]$2['])])dnl - m4_popdef([cr_mk_acc_feat_enabled])dnl -])dnl - -dnl -dnl CAIRO_MAKEFILE_ACCUMULATE_FEATURE(TAG, ENABLED, DEFAULT, WHAT, CONTENT) -dnl -dnl Accumulates CONTENT to Makefile's for TAG for each feature matching -dnl ENABLED, DEFAULT, and WHAT. Those parameters are similar to those -dnl passed to CAIRO_FEATURE_HOOK_REGISTER. -dnl If TAG is *, CONTENT is added to all Makefile's. -dnl -AC_DEFUN([CAIRO_MAKEFILE_ACCUMULATE_FEATURE], -[dnl - m4_if([$1],[*],,[_CAIRO_MAKEFILE_CHECK([$1])])dnl - m4_append([cr_make_acc_counter],[1],[])dnl - m4_define([cr_make_acc_contents]m4_len(cr_make_acc_counter), [$5])dnl - CAIRO_FEATURE_HOOK_REGISTER(*,[$3],[$4], - [dnl - m4_foreach_w([cr_makefile], m4_if([$1],[*],_CAIRO_MAKEFILES,[$1]), - [dnl - cr_make_tmp=_CAIRO_SH_ESCAPE(cr_make_acc_contents]]m4_len(cr_make_acc_counter)([[cr_makefile,]][$][1],[$][2],[$][3],[$][4])[[) - m4_ifdef([cr_make_]cr_makefile[_dir_amake], - [_CAIRO_MAKEFILE_ACCUMULATE_FEATURE( - [MAKEFILE_]cr_makefile[_AMAKE], - [$2], - [if ]cr_feature_tag, [else], [endif], - [$cr_make_tmp]) - ])dnl - m4_ifdef([cr_make_]cr_makefile[_dir_win32], - [_CAIRO_MAKEFILE_ACCUMULATE_FEATURE( - [MAKEFILE_]cr_makefile[_WIN32], - [$2], - [ifeq ($(]cr_feature_tag[),1)], [else], [endif], - [$cr_make_tmp])dnl - ])dnl - ])dnl - ])dnl -])dnl - -m4_define([cr_make_acc_counter])dnl diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.pkg.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.pkg.m4 deleted file mode 100644 index cf90a967880..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/aclocal.pkg.m4 +++ /dev/null @@ -1,157 +0,0 @@ -# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- -# -# Copyright © 2004 Scott James Remnant . -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# PKG_PROG_PKG_CONFIG([MIN-VERSION]) -# ---------------------------------- -AC_DEFUN([PKG_PROG_PKG_CONFIG], -[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) -m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) -AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl -if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then - AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) -fi -if test -n "$PKG_CONFIG"; then - _pkg_min_version=m4_default([$1], [0.9.0]) - AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) - if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - PKG_CONFIG="" - fi - -fi[]dnl -])# PKG_PROG_PKG_CONFIG - -# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) -# -# Check to see whether a particular set of modules exists. Similar -# to PKG_CHECK_MODULES(), but does not set variables or print errors. -# -# -# Similar to PKG_CHECK_MODULES, make sure that the first instance of -# this or PKG_CHECK_MODULES is called, or make sure to call -# PKG_CHECK_EXISTS manually -# -------------------------------------------------------------- -AC_DEFUN([PKG_CHECK_EXISTS], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl -if test -n "$PKG_CONFIG" && \ - AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then - m4_ifval([$2], [$2], [:]) -m4_ifvaln([$3], [else - $3])dnl -fi]) - - -# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) -# --------------------------------------------- -m4_define([_PKG_CONFIG], -[if test -n "$$1"; then - pkg_cv_[]$1="$$1" - elif test -n "$PKG_CONFIG"; then - PKG_CHECK_EXISTS([$3], - [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], - [pkg_failed=yes]) - else - pkg_failed=untried -fi[]dnl -])# _PKG_CONFIG - -# _PKG_SHORT_ERRORS_SUPPORTED -# ----------------------------- -AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) -if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then - _pkg_short_errors_supported=yes -else - _pkg_short_errors_supported=no -fi[]dnl -])# _PKG_SHORT_ERRORS_SUPPORTED - - -# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], -# [ACTION-IF-NOT-FOUND]) -# -# ACTION-IF-NOT-FOUND is not allowed to be empty, that trigger PKG_CONFIG_PATH error message. -# Use : or set a dummy variable to avoid that behavior. -# -# Note that if there is a possibility the first call to -# PKG_CHECK_MODULES might not happen, you should be sure to include an -# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac -# -# -# -------------------------------------------------------------- -AC_DEFUN([PKG_CHECK_MODULES], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl -AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl -AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl - -pkg_failed=no -AC_MSG_CHECKING([for $1]) - -_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) -_PKG_CONFIG([$1][_LIBS], [libs], [$2]) - -m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS -and $1[]_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details.]) - -if test $pkg_failed = yes; then - _PKG_SHORT_ERRORS_SUPPORTED - if test $_pkg_short_errors_supported = yes; then - $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1` - else - $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1` - fi - # Put the nasty error message in config.log where it belongs - echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD - - ifelse([$4], , [AC_MSG_ERROR(dnl -[Package requirements ($2) were not met: - -$$1_PKG_ERRORS - -Consider adjusting the PKG_CONFIG_PATH environment variable if you -installed software in a non-standard prefix. - -_PKG_TEXT -])], - [AC_MSG_RESULT([no]) - $4]) -elif test $pkg_failed = untried; then - ifelse([$4], , [AC_MSG_FAILURE(dnl -[The pkg-config script could not be found or is too old. Make sure it -is in your PATH or set the PKG_CONFIG environment variable to the full -path to pkg-config. - -_PKG_TEXT - -To get pkg-config, see .])], - [$4]) -else - $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS - $1[]_LIBS=$pkg_cv_[]$1[]_LIBS - AC_MSG_RESULT([yes]) - ifelse([$3], , :, [$3]) -fi[]dnl -])# PKG_CHECK_MODULES diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.analysis b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.analysis deleted file mode 100644 index 11c52e70d6e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.analysis +++ /dev/null @@ -1,106 +0,0 @@ -dnl =========================================================================== -dnl -dnl LCOV -dnl -cairo_has_lcov=no -AC_ARG_ENABLE(gcov, - AS_HELP_STRING([--enable-gcov], - [Enable gcov]), - [use_gcov=$enableval], [use_gcov=no]) - -if test "x$use_gcov" = "xyes"; then - dnl we need gcc: - if test "$GCC" != "yes"; then - AC_MSG_ERROR([GCC is required for --enable-gcov]) - fi - - dnl Check if ccache is being used - AC_CHECK_PROG(SHTOOL, shtool, shtool) - case `$SHTOOL path $CC` in - *ccache*[)] gcc_ccache=yes;; - *[)] gcc_ccache=no;; - esac - - if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then - AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) - fi - - ltp_version_list="1.7 1.6 1.5 1.4" - AC_CHECK_PROG(LTP, lcov, lcov) - AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml) - - if test "$LTP"; then - AC_CACHE_CHECK([for ltp version], cairo_cv_ltp_version, [ - cairo_cv_ltp_version=invalid - ltp_version=`$LTP -v 2>/dev/null | $SED -e 's/^.* //'` - for ltp_check_version in $ltp_version_list; do - if test "$ltp_version" = "$ltp_check_version"; then - cairo_cv_ltp_version="$ltp_check_version (ok)" - fi - done - ]) - fi - - case $cairo_cv_ltp_version in - ""|invalid[)] - ;; - *) - cairo_has_lcov=yes - ;; - esac - - if test "x$cairo_has_lcov" != "xyes"; then - AC_MSG_ERROR([[To enable code coverage reporting you must have one of the following LTP versions installed: $ltp_version_list. -Please install the Linux Test Project [http://ltp.sourceforge.net/], and try again.]]) - fi - - if test -z "$LTP_GENHTML"; then - AC_MSG_ERROR([[Could not find genhtml from the LTP package. -Please install the Linux Test Project [http://ltp.sourceforge.net/], and try again.]]) - fi - - AC_DEFINE(HAVE_GCOV, 1, [Whether you have gcov]) -dnl PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Makefile.gcov, $abs_srcdir) - - dnl Remove all optimization flags from CFLAGS - changequote({,}) - CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` - CAIRO_CFLAGS=`echo "$CAIRO_CFLAGS" | $SED -e 's/-O[0-9]*//g'` - changequote([,]) - - dnl Add the special gcc flags - dnl In order to workaround a debian bug in libtool where they strip - dnl $dependency_libs from the link line and CFLAGS, we need to pass - dnl --coverage via LDFLAGS. - CAIRO_CC_TRY_FLAG([--coverage],, - [ - CAIRO_CFLAGS="$CAIRO_CFLAGS -O0 --coverage" - CAIRO_LDFLAGS="$CAIRO_LDFLAGS -O0 --coverage" - ]) -fi -AM_CONDITIONAL(CAIRO_HAS_LCOV, test "x$cairo_has_lcov" = "xyes") - -dnl =========================================================================== -dnl Check for some custom valgrind modules -AC_ARG_ENABLE(valgrind, - AS_HELP_STRING([--disable-valgrind], - [Disable valgrind support]), - [use_valgrind=$enableval], [use_valgrind=yes]) - -if test "x$use_valgrind" = "xyes"; then - PKG_CHECK_MODULES(VALGRIND, valgrind, [ - _save_CFLAGS="$CFLAGS" - _save_CPPFLAGS="$CPPFLAGS" - CFLAGS="$CFLAGS $VALGRIND_CFLAGS" - CPPFLAGS="$CPPFLAGS $VALGRIND_CFLAGS" - AC_CHECK_HEADER([valgrind.h], [AC_DEFINE([HAVE_VALGRIND], [1], - [Define to 1 if you have Valgrind])]) - AC_CHECK_HEADER([lockdep.h], [AC_DEFINE([HAVE_LOCKDEP], [1], - [Define to 1 if you have the Valgrind lockdep tool])]) - AC_CHECK_HEADER([memfault.h], [AC_DEFINE([HAVE_MEMFAULT], [1], - [Define to 1 if you have the Valgrind memfault tool])]) - CAIRO_CFLAGS="$VALGRIND_CFLAGS $CAIRO_CFLAGS" - CFLAGS="$_save_CFLAGS" - CPPFLAGS="$_save_CPPFLAGS" - ], AC_MSG_RESULT(no)) -fi diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.features b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.features deleted file mode 100644 index e4a2aafcc82..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.features +++ /dev/null @@ -1,427 +0,0 @@ - -dnl -dnl Define macros to enable various features. -dnl - Macro: CAIRO_ENABLE_* (ID, NAME, DEFAULT, COMMANDS) -dnl -dnl where: -dnl -dnl ID is the feature id, eg. "ft" for cairo_ft_... -dnl NAME is the human-readable name of the feature, eg. "FreeType" -dnl DEFAULT is the default state of the feature: -dnl "no" for experimental backends, eg. your favorite new backend -dnl "yes" for mandatory backends, eg. png -dnl "auto" for other supported backends, eg. xlib -dnl COMMANDS are run to check whether the feature can be enabled. Their -dnl result may be cached, so user should not count on them being run. -dnl They should set use_$(ID) to something other than yes if the -dnl feature cannot be built, eg. "no (requires SomeThing)". It then -dnl should also set $(ID)_REQUIRES/CFLAGS/LIBS/... -dnl appropriately. Look at the macro definition for more details, -dnl or ask if in doubt. -dnl - -AC_DEFUN([CAIRO_ENABLE], - [_CAIRO_ENABLE([$1], [$2], , [$3],[$4])])dnl - -AC_DEFUN([CAIRO_ENABLE_SURFACE_BACKEND], - [_CAIRO_ENABLE([$1], [$2 surface backend], surface, [$3],[$4])])dnl - -AC_DEFUN([CAIRO_ENABLE_FONT_BACKEND], - [_CAIRO_ENABLE([$1], [$2 font backend], font, [$3],[$4])])dnl - -AC_DEFUN([CAIRO_ENABLE_FUNCTIONS], - [_CAIRO_ENABLE([$1], [$2 functions], functions, [$3],[$4])])dnl - - -dnl -dnl Define cr_feature_pc and friends ala other cr_feature_* macros -dnl -m4_define([cr_pc_modname], - [[cairo-]m4_translit([$1],_,-)])dnl -m4_define([cr_feature_pc], - [cr_pc_modname(cr_feature)[.pc]])dnl -m4_define([cr_feature_uninstalled_pc], - [cr_pc_modname(cr_feature)[-uninstalled.pc]])dnl - - -dnl =========================================================================== -dnl -dnl Hooks -dnl -dnl =========================================================================== - - -dnl =========================================================================== -dnl -dnl Generate {src,boilerplate}/Makefile.{am,win32}.config -dnl - -CAIRO_INIT_MAKEFILES([build]) -CAIRO_CONFIG_MAKEFILE([cairo], [src])dnl -CAIRO_CONFIG_MAKEFILE([cairo_boilerplate], [boilerplate])dnl -CAIRO_MAKEFILE_INCLUDE(*,[Makefile.sources])dnl -dnl An empty line per feature for readability -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,*,*,[])dnl - - -dnl Collect list of all supported public headers -CAIRO_MAKEFILE_ACCUMULATE(*, -[supported_$1_headers = $($1_headers)]dnl -)dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,!no,!, -[supported_$1_headers += $($1_$2_headers)]dnl -)dnl - -dnl Collect list of all unsupported public headers -CAIRO_MAKEFILE_ACCUMULATE(*, -[unsupported_$1_headers =]dnl -)dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,no,!, -[unsupported_$1_headers += $($1_$2_headers)]dnl -)dnl - -dnl Collect list of source files for all public features -CAIRO_MAKEFILE_ACCUMULATE(*, -[dnl -all_$1_headers = $($1_headers) -all_$1_private = $($1_private) -all_$1_cxx_sources = $($1_cxx_sources) -all_$1_sources = $($1_sources) -])dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,*,!, -[dnl -all_$1_headers += $($1_$2_headers) -all_$1_private += $($1_$2_private) -all_$1_cxx_sources += $($1_$2_cxx_sources) -all_$1_sources += $($1_$2_sources)]dnl -)dnl - -dnl Collect list of source files for enabled public features -CAIRO_MAKEFILE_ACCUMULATE(*, -[dnl -enabled_$1_headers = $($1_headers) -enabled_$1_private = $($1_private) -enabled_$1_cxx_sources = $($1_cxx_sources) -enabled_$1_sources = $($1_sources) -])dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,yes,*,!, -[dnl -enabled_$1_headers += $($1_$2_headers) -enabled_$1_private += $($1_$2_private) -enabled_$1_cxx_sources += $($1_$2_cxx_sources) -enabled_$1_sources += $($1_$2_sources)]dnl -)dnl - -dnl No public headers for private features - -dnl Collect list of source files for all private features -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,*,, -[dnl -all_$1_private += $($1_$2_private) $($1_$2_headers) -all_$1_cxx_sources += $($1_$2_cxx_sources) -all_$1_sources += $($1_$2_sources)]dnl -)dnl - -dnl Collect list of source files for enabled private features -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,yes,*,, -[dnl -enabled_$1_private += $($1_$2_private) $($1_$2_headers) -enabled_$1_cxx_sources += $($1_$2_cxx_sources) -enabled_$1_sources += $($1_$2_sources)]dnl -)dnl - - -dnl =========================================================================== -dnl -dnl Generate .pc files -dnl - -dnl All .pc files are generated automatically except for this one -AC_CONFIG_FILES([src/cairo.pc])dnl -AC_CONFIG_FILES([cairo-uninstalled.pc:src/cairo-uninstalled.pc.in])dnl - -dnl pkg-config requires, non-pkgconfig cflags and libs, and total cflags and libs -CAIRO_FEATURE_VARS_REGISTER([BASE],[cairo])dnl -CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER([REQUIRES],,[ ])dnl -CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER([CFLAGS NONPKGCONFIG_CFLAGS],,[ ])dnl -CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER([LIBS NONPKGCONFIG_LIBS],,[ ],[$LIBS])dnl -CAIRO_FEATURE_VARS_REGISTER([NONPKGCONFIG_EXTRA_LIBS])dnl -AC_SUBST(CAIRO_REQUIRES)dnl -AC_SUBST(CAIRO_CFLAGS)dnl -AC_SUBST(CAIRO_LDFLAGS)dnl -AC_SUBST(CAIRO_NONPKGCONFIG_CFLAGS)dnl -AC_SUBST(CAIRO_LIBS)dnl -AC_SUBST(CAIRO_NONPKGCONFIG_LIBS)dnl - -dnl add non-pkgconfig values -AC_CONFIG_COMMANDS_PRE( -[dnl -CAIRO_CFLAGS="$CAIRO_CFLAGS $CAIRO_NONPKGCONFIG_CFLAGS" -CAIRO_LIBS="$CAIRO_LIBS $CAIRO_NONPKGCONFIG_LIBS" -])dnl - -m4_define([_CAIRO_FEATURE_CONFIG_PKGCONFIG_FILE], -[dnl - AC_CONFIG_FILES([$3:$4], - [dnl - mv "$3" "$3.tmp" && - $SED "dnl - s%@FEATURE_PC@%]cr_pc_modname([$1])[%g;dnl - s%@FEATURE_NAME@%$2%g;dnl - s%@FEATURE_BASE@%$$1_BASE%g;dnl - s%@FEATURE_REQUIRES@%$$1_REQUIRES%g;dnl - s%@FEATURE_NONPKGCONFIG_LIBS@%$$1_NONPKGCONFIG_LIBS%g;dnl - s%@FEATURE_NONPKGCONFIG_EXTRA_LIBS@%$$1_NONPKGCONFIG_EXTRA_LIBS%g;dnl - s%@FEATURE_NONPKGCONFIG_CFLAGS@%$$1_NONPKGCONFIG_CFLAGS%g;dnl - " < "$3.tmp" > "$3" && rm -f "$3.tmp" || - AC_MSG_ERROR(failed to update $3) - ],[dnl - SED='$SED' - $1_BASE='$$1_BASE' - $1_REQUIRES='$$1_REQUIRES' - $1_NONPKGCONFIG_LIBS='$$1_NONPKGCONFIG_LIBS' - $1_NONPKGCONFIG_EXTRA_LIBS='$$1_NONPKGCONFIG_EXTRA_LIBS' - $1_NONPKGCONFIG_CFLAGS='$$1_NONPKGCONFIG_CFLAGS' - ])dnl -])dnl - -dnl Generate .pc files for enabled non-builtin public features -CAIRO_FEATURE_HOOK_REGISTER(yes,!always,!, -[dnl - _CAIRO_FEATURE_CONFIG_PKGCONFIG_FILE( - [$1], - cr_feature_name, - [src/]cr_feature_pc, - [src/cairo-features.pc.in] - )dnl -])dnl - -dnl Generate -uninstalled.pc files for enabled non-builtin public features -CAIRO_FEATURE_HOOK_REGISTER(yes,!always,!, -[dnl - _CAIRO_FEATURE_CONFIG_PKGCONFIG_FILE( - [$1], - cr_feature_name, - cr_feature_uninstalled_pc, - [src/cairo-features-uninstalled.pc.in] - )dnl -])dnl - - -dnl Collect list of .pc files for all non-builtin public features -CAIRO_MAKEFILE_ACCUMULATE(cairo, -[all_$1_pkgconf = cairo.pc])dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(cairo,*,!always,!, -[all_$1_pkgconf += cr_feature_pc])dnl - -dnl Collect list of .pc files for enabled non-builtin public features -CAIRO_MAKEFILE_ACCUMULATE(cairo, -[enabled_$1_pkgconf = cairo.pc])dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE(cairo,yes,!always,!, -[enabled_$1_pkgconf += cr_feature_pc])dnl - - -dnl =========================================================================== -dnl -dnl Generate src/cairo-features.h, src/cairo-supported-features.h, and -dnl src/cairo-features-win32.h -dnl - -dnl Collect list of enabled public features -CAIRO_ACCUMULATORS_REGISTER(FEATURES,[ ])dnl -CAIRO_FEATURE_HOOK_REGISTER(yes,*,!,dnl -[dnl - CAIRO_ACCUMULATE(FEATURES, cr_feature_tag)dnl -])dnl -dnl Collect list of all supported public features -CAIRO_ACCUMULATORS_REGISTER(SUPPORTED_FEATURES,[ ])dnl -CAIRO_FEATURE_HOOK_REGISTER(*,!no,!,dnl -[dnl - CAIRO_ACCUMULATE(SUPPORTED_FEATURES, cr_feature_tag) -])dnl -dnl Collect list of all supported disabled public features -CAIRO_ACCUMULATORS_REGISTER(NO_FEATURES,[ ])dnl -CAIRO_FEATURE_HOOK_REGISTER(no,!no,!, -[dnl - CAIRO_ACCUMULATE(NO_FEATURES, cr_feature_tag) -])dnl - -dnl Generate src/cairo-features.h -CAIRO_CONFIG_COMMANDS([src/cairo-features.h], -[dnl - echo '/* Generated by configure. Do not edit. */' - echo '#ifndef CAIRO_FEATURES_H' - echo '#define CAIRO_FEATURES_H' - echo '' - for FEATURE in $CAIRO_FEATURES; do - echo "#define $FEATURE 1" - done | LANG=C sort - echo '' - for FEATURE in $CAIRO_NO_FEATURES; do - echo "/*#undef $FEATURE */" - done | LANG=C sort - echo '' - echo '#endif' -],[dnl - CAIRO_FEATURES='$CAIRO_FEATURES' - CAIRO_NO_FEATURES='$CAIRO_NO_FEATURES' -])dnl -dnl Generate src/cairo-supported-features.h -CAIRO_CONFIG_COMMANDS([src/cairo-supported-features.h], -[dnl - echo '/* Generated by configure. Do not edit. */' - echo '#ifndef CAIRO_SUPPORTED_FEATURES_H' - echo '#define CAIRO_SUPPORTED_FEATURES_H' - echo '' - echo '/* This is a dummy header, to trick gtk-doc only */' - echo '' - for FEATURE in $CAIRO_SUPPORTED_FEATURES; do - echo "#define $FEATURE 1" - done - echo '' - echo '#endif' -],[dnl - CAIRO_SUPPORTED_FEATURES='$CAIRO_SUPPORTED_FEATURES' -])dnl - -dnl For enabled private features just define them in config.h. No fanfare! -CAIRO_FEATURE_HOOK_REGISTER(yes,*,, -[dnl - AC_DEFINE(cr_feature_tag, 1, [Define to 1 to enable cairo's ]cr_feature_name[ feature]) -])dnl - - -dnl Generate build/Makefile.win32.features-h that generates src/cairo-features.h -CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([win32_features_h],[build],[features-h]) -dnl -CAIRO_MAKEFILE_ACCUMULATE([win32_features_h], -[$(top_srcdir)/src/cairo-features.h: $(top_srcdir)/build/Makefile.win32.features - @echo "Generating src/cairo-features.h" - @echo "/* Generated by Makefile.win32.features-h. Do not edit. */" > $(top_srcdir)/src/cairo-features.h - @echo "[#]ifndef CAIRO_FEATURES_H" >> $(top_srcdir)/src/cairo-features.h - @echo "[#]define CAIRO_FEATURES_H 1" >> $(top_srcdir)/src/cairo-features.h]dnl -) -AC_CONFIG_COMMANDS_PRE( -[dnl - CAIRO_MAKEFILE_ACCUMULATE([win32_features_h], [ @echo "[#]endif" >> $(top_srcdir)/src/cairo-features.h]) -])dnl -CAIRO_MAKEFILE_ACCUMULATE_FEATURE([win32_features_h],yes,*,*,dnl -[ @echo "[#]define cr_feature_tag 1" >> $(top_srcdir)/src/cairo-features.h]dnl -)dnl - - -dnl =========================================================================== -dnl -dnl Report -dnl - -CAIRO_ACCUMULATORS_REGISTER([WARNING_MESSAGE],m4_newline()m4_newline)dnl - -dnl Collect warning message for enabled unsupported public features -CAIRO_FEATURE_HOOK_REGISTER(yes,no,!, -[dnl - CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([The ]cr_feature_name[ feature is still under active development and is included in this release only as a preview. It does NOT fully work yet and incompatible changes may yet be made to ]cr_feature_name[ specific API.], [--- ])) -])dnl - -dnl Collect warning message for disabled recommended features -CAIRO_FEATURE_HOOK_REGISTER(no,yes,*, -[dnl - CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([It is strongly recommended that you do NOT disable the ]cr_feature_name[ feature.], [+++ ])) -])dnl - - -dnl Collect enabled native surface/font backend features -CAIRO_ACCUMULATORS_REGISTER([NATIVE_SURFACE_BACKENDS])dnl -CAIRO_ACCUMULATORS_REGISTER([NATIVE_FONT_BACKENDS])dnl -CAIRO_FEATURE_HOOK_REGISTER(yes,auto,surface, -[dnl - CAIRO_ACCUMULATE([NATIVE_SURFACE_BACKENDS], [$1]) -])dnl -CAIRO_FEATURE_HOOK_REGISTER(yes,auto,font, -[dnl - CAIRO_ACCUMULATE([NATIVE_FONT_BACKENDS], [$1]) -])dnl - -dnl Collect warning message if no native surface/font backend feature enabled -AC_CONFIG_COMMANDS_PRE(dnl -[dnl - AS_IF([test -z "$CAIRO_NATIVE_SURFACE_BACKENDS"],dnl - [dnl - CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([No native surface backends enabled for your platform. It is strongly recommended that you enable the native surface backend feature for your platform.], [*** ])) - ]) - AS_IF([test -z "$CAIRO_NATIVE_FONT_BACKENDS"],dnl - [dnl - CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([No native font backends enabled for your platform. It is strongly recommended that you enable the native font backend feature for your platform.], [*** ])) - ]) -])dnl - - -AC_DEFUN([CAIRO_REPORT], -[dnl - V="$CAIRO_VERSION_MAJOR.$CAIRO_VERSION_MINOR.$CAIRO_VERSION_MICRO" - echo "" - echo "cairo (version $V [[$CAIRO_RELEASE_STATUS]]) will be compiled with:" - echo "" - echo "The following surface backends:" - echo " Image: yes (always builtin)" - echo " Recording: yes (always builtin)" - echo " Observer: yes (always builtin)" - echo " Mime: yes (always builtin)" - echo " Tee: $use_tee" - echo " XML: $use_xml" - echo " Skia: $use_skia" - echo " Xlib: $use_xlib" - echo " Xlib Xrender: $use_xlib_xrender" - echo " Qt: $use_qt" - echo " Quartz: $use_quartz" - echo " Quartz-image: $use_quartz_image" - echo " XCB: $use_xcb" - echo " Win32: $use_win32" - echo " OS2: $use_os2" - echo " CairoScript: $use_script" - echo " PostScript: $use_ps" - echo " PDF: $use_pdf" - echo " SVG: $use_svg" - echo " OpenGL: $use_gl" - echo " OpenGL ES 2.0: $use_glesv2" - echo " BeOS: $use_beos" - echo " DirectFB: $use_directfb" - echo " OpenVG: $use_vg" - echo " DRM: $use_drm" - echo " Cogl: $use_cogl" - echo "" - echo "The following font backends:" - echo " User: yes (always builtin)" - echo " FreeType: $use_ft" - echo " Fontconfig: $use_fc" - echo " Win32: $use_win32_font" - echo " Quartz: $use_quartz_font" - echo "" - echo "The following functions:" - echo " PNG functions: $use_png" - echo " GLX functions: $use_glx" - echo " WGL functions: $use_wgl" - echo " EGL functions: $use_egl" - echo " X11-xcb functions: $use_xlib_xcb" - echo " XCB-shm functions: $use_xcb_shm" - echo "" - echo "The following features and utilities:" - echo " cairo-trace: $use_trace" - echo " cairo-script-interpreter: $use_interpreter" - echo "" - echo "And the following internal features:" - echo " pthread: $use_pthread" - echo " gtk-doc: $enable_gtk_doc" - echo " gcov support: $use_gcov" - echo " symbol-lookup: $use_symbol_lookup" - echo " test surfaces: $use_test_surfaces" - echo " ps testing: $test_ps" - echo " pdf testing: $test_pdf" - echo " svg testing: $test_svg" - if test x"$use_win32" = "xyes"; then - echo " win32 printing testing: $test_win32_printing" - fi - echo "$CAIRO_WARNING_MESSAGE" - echo "" -])dnl - diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.noversion b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.noversion deleted file mode 100644 index 18c4bd5f7ae..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.noversion +++ /dev/null @@ -1,23 +0,0 @@ -dnl -dnl Version stuff -dnl - -dnl Disable autoconf's version macros. We try hard to not rebuild the entire -dnl library just because version changed. The PACKAGE_VERSION* stuff in -dnl config.h is negating all the effort. -dnl -dnl We're not actually supposed to be doing this, and indeed adding the -dnl AC_DEFINEs below causes confdefs.h to contain duplicate incompatible -dnl #defines for the same PACKAGE_* symbols. Those are provoking warnings -dnl from the compiler, and that throws our CAIRO_TRY_LINK_*_ checks off, -dnl because they think that there's something wrong with some flag they're -dnl testing rather than confdefs.h! So let's do the gross thing and puke -dnl into confdefs.h some #undefs. -echo '#undef PACKAGE_VERSION' >>confdefs.h -echo '#undef PACKAGE_STRING' >>confdefs.h -echo '#undef PACKAGE_NAME' >>confdefs.h -echo '#undef PACKAGE_TARNAME' >>confdefs.h -AC_DEFINE(PACKAGE_VERSION, [USE_cairo_version_OR_cairo_version_string_INSTEAD]) -AC_DEFINE(PACKAGE_STRING, [USE_cairo_version_OR_cairo_version_string_INSTEAD]) -AC_DEFINE(PACKAGE_NAME, [USE_cairo_INSTEAD]) -AC_DEFINE(PACKAGE_TARNAME, [USE_cairo_INSTEAD]) diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.pthread b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.pthread deleted file mode 100644 index 29c930da932..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.pthread +++ /dev/null @@ -1,253 +0,0 @@ -dnl Defines the macro CAIRO_CONFIGURE_PTHREAD to find a suitable -dnl pthread implementation. There are two levels of pthread conformance -dnl we are looking for: -dnl -dnl a) A minimal level denoted by -DCAIRO_HAS_PTHREAD=1: This level -dnl requires mutex and recursive mutexattr support. If possible we try -dnl to use weakly linked stubs from libc over the real pthread library. -dnl This level is required by the cairo library proper. If the user -dnl invokes configure with --enable-pthread=yes or -dnl --enable-pthread=always then we avoid trying to use weak stubs. -dnl -dnl b) A full level denoted by -DCAIRO_HAS_REAL_PTHREAD=1: This level -dnl requires full support from a real pthread library, including thread -dnl creation, joins, thread attribtues, etc. This level is required by -dnl multithreaded applications using cairo, such as the test suite -dnl binaries and cairo utilities. -dnl -dnl Usage: -dnl CAIRO_ENABLE(pthread, pthread, , -dnl [CAIRO_CONFIGURE_PTHREAD]) -dnl -dnl This should be invoked near the end of configure.ac so that -dnl the pthread specific CFLAGS and LIBS end up at the front -dnl of CAIRO_CFLAGS and CAIRO_LIBS -- this helps ensure that we -dnl really do get non-weak symbols from the actual pthread library -dnl rather than possible stubs in other libraries. -dnl -dnl The user can override the choices made by -dnl CAIRO_CONFIGURE_PTHREAD by using --enable-pthread=yes and -dnl giving PTHREAD_CFLAGS and PTHREAD_LIBS to configure. -dnl -dnl Sets environment variables: -dnl use_pthread="yes" | "no ()" -dnl have_pthread="yes" | "no ( - -pthread_mutex_t test_mutex_initializer = PTHREAD_MUTEX_INITIALIZER; -int test_mutex (void) -{ - int x = 0; - pthread_mutex_t mutex; - x |= pthread_mutex_init (&mutex, NULL); - x |= pthread_mutex_lock (&mutex); - x |= pthread_mutex_unlock (&mutex); - x |= pthread_mutex_destroy (&mutex); - return 0; -} - -int test_mutex_attr (void) -{ - int x = 0; - pthread_mutexattr_t attr; - pthread_mutex_t mutex; - x |= pthread_mutexattr_init (&attr); - x |= pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); - x |= pthread_mutex_init (&mutex, &attr); - x |= pthread_mutex_lock (&mutex); - x |= pthread_mutex_unlock (&mutex); - x |= pthread_mutex_destroy (&mutex); - x |= pthread_mutexattr_destroy (&attr); - return x; -}]) - -dnl ----------------------------------------------------------------------- -dnl A program to test all the features we want to be able to run the test -dnl suite or other thready cairo applications that want real threads. -m4_define([testsuite_pthread_program],[dnl -libcairo_pthread_program - -pthread_once_t once_control = PTHREAD_ONCE_INIT; -void test_once_init (void) {} -int test_once (void) -{ - return pthread_once (&once_control, test_once_init); -} - -pthread_key_t test_specific_key; -int test_specific (void) -{ - int x = 0; - x |= pthread_key_create (&test_specific_key, NULL); - x |= pthread_setspecific (test_specific_key, NULL); - x |= pthread_getspecific (test_specific_key) != NULL; - return x; -} - -void cleaner (void *arg) { (void)arg; } - -void * -test_thread_main (void *arg) -{ - pthread_cleanup_push (cleaner, arg); - pthread_exit (arg); - pthread_cleanup_pop (1); - return arg; -} - -int -test_threads (void) -{ - int x = 0; - pthread_t thread; - pthread_attr_t attr; - void *arg = NULL; - x |= pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - x |= pthread_create (&thread, &attr, test_thread_main, arg); - x |= pthread_equal (pthread_self(), thread); - x |= pthread_join (thread, &arg); - x |= pthread_attr_destroy (&attr); - return x; -}]) - -dnl ----------------------------------------------------------------------- - -dnl CAIRO_CHECK_PTHREAD(tag, cflags, libs, program, true-action, false-action) -dnl Set _{CFLAGS,LIBS} to {,} if we can compile and link -dnl with the given flags and libs. Execute on -dnl success and on failure. -AC_DEFUN([CAIRO_CHECK_PTHREAD],[dnl - CAIRO_CC_TRY_LINK_WITH_ENV_SILENT( - [CFLAGS="$CFLAGS $2"; - LIBS="$LIBS $3"], - [$4], - [$1_CFLAGS="$2"; - $1_LIBS="$3"; - $5], - [$1_CFLAGS=""; - $1_LIBS=""; - $6]) -]) - -dnl CAIRO_CONFIGURE_PTHREADS(): Look for pthreads. -dnl -dnl If the user specifies PTHREAD_CFLAGS and PTHREAD_LIBS then we use -dnl those. Otherwise we try CFLAGS=-D_REENTRANT and LIBS=-lpthread for -dnl full pthread support, and look for stubs in libc for the minimal -dnl pthread support. -dnl -dnl CFLAGS=-D_REENTRANT LIBS=-lpthread has been tested to work on: -dnl -dnl Solaris 9 (5.9) Sun C 5.8 Patch 121015-04 2007/01/10 -dnl OpenSolaris (5.11) Sun C 5.9 Patch 124868-08 2008/11/25 -dnl OpenSolaris (5.11) clang version 1.1 (trunk 90017) -dnl Tru64/OSF1 V5.1 Compaq C V6.5-003 -dnl Mac OS X 10.5.5 gcc 4.0.1 (Apple Inc. build 5465) -dnl Mac OS X 10.6 gcc 4.2.1 (Apple Inc. build 5659) -dnl FreeBSD 7.2 gcc 4.2 -dnl OpenBSD 4.5 gcc 3.3.5 (propolice) -dnl Debian Linux (Etch) gcc 4.3 -dnl -dnl Thread support is also in various libcs directly, so often using no -dnl flags at all works as well, but unfortunately Solaris 9 has -dnl practically _all_ of libpthread stubbed out in libc, so we cannot -dnl distinguish between a working libpthread and a stubbed out one by a -dnl link-only test. -dnl -dnl We also explicitly do not link to pthread-stubs or whatever other -dnl third-party stubs library, since that forces cairo clients to be -dnl extra careful when giving both libcairo and libpthread on the -dnl command line: the user would have to use "-lpthread -lcairo" rather -dnl than the more common "-lcairo -lpthread" to not accidentally use -dnl stubs pulled in by libcairo everywhere in the application. We -dnl might also need to have a way to teach pkg-config about library -dnl ordering constraints which aren't actual dependencies, and at this -dnl point it just starts doing my head in. -dnl -dnl If your unix-like doesn't work with the secret handshake -dnl -D_REENTRANT -lpthread and you can actually compile the rest of -dnl cairo just fine otherwise, please take a moment complain loudly -dnl to the cairo mailing list! -dnl -AC_DEFUN([CAIRO_CONFIGURE_PTHREAD],[dnl - dnl Try to use the user's PTHREAD_LIBS/CFLAGS - dnl if they're available. - if test "x$PTHREAD_CFLAGS" = "x"; then - PTHREAD_CFLAGS="-D_REENTRANT" - fi - if test "x$PTHREAD_LIBS" = "x"; then - PTHREAD_LIBS="-lpthread" - fi - - dnl First try to find the real pthreads. - CAIRO_CHECK_PTHREAD( - [real_pthread], [$PTHREAD_CFLAGS], [$PTHREAD_LIBS], - [testsuite_pthread_program], - [have_real_pthread=yes], - [have_real_pthread=no]) - if test "x$have_real_pthread" != "xyes"; then - dnl Give -pthread a go. - CAIRO_CHECK_PTHREAD( - [real_pthread], [-pthread], [], - [testsuite_pthread_program], - [have_real_pthread=yes], - [have_real_pthread="no (can't link with -lpthread or -pthread)"]) - fi - PTHREAD_CFLAGS= - PTHREAD_LIBS= - - dnl Check if we can use libc's stubs in libcairo. - dnl Only do this if the user hasn't explicitly enabled - dnl pthreads, but is relying on automatic configuration. - have_pthread="no" - if test "x$enable_pthread" != "xyes"; then - CAIRO_CHECK_PTHREAD( - [pthread], [-D_REENTRANT], [], - [libcairo_pthread_program], - [have_pthread=yes], - []) - fi - - dnl Default to using the real pthreads for libcairo. - if test "x$have_pthread" != "xyes"; then - have_pthread="$have_real_pthread"; - pthread_CFLAGS="$real_pthread_CFLAGS"; - pthread_LIBS="$real_pthread_LIBS"; - fi - - dnl Tell autoconf about the results. - if test "x$have_real_pthread" = "xyes"; then - AC_DEFINE([CAIRO_HAS_REAL_PTHREAD], 1, - [Define to 1 if we have full pthread support]) - fi - if test "x$have_pthread" = "xyes"; then - AC_DEFINE([CAIRO_HAS_PTHREAD], 1, - [Define to 1 f we have minimal pthread support]) - fi - - dnl Make sure we scored some pthreads. - if test "x$enable_pthread" = "xyes" -a "x$have_pthread" != "xyes"; then - AC_MSG_ERROR([pthread requested but not found]) - fi - - dnl Set the output variables for CAIRO_ENABLE. - use_pthread="$have_pthread" - pthread_REQUIRES="" -]) diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.system b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.system deleted file mode 100644 index b9d71c8d783..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.system +++ /dev/null @@ -1,160 +0,0 @@ -dnl -dnl Non-failing checks for functions, headers, libraries, etc go here -dnl - -dnl ==================================================================== -dnl Feature checks -dnl ==================================================================== - -AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes") -CAIRO_BIGENDIAN -AC_ARG_ENABLE(atomic, - [AS_HELP_STRING([--disable-atomic], - [disable use of native atomic operations])], - [use_atomic=$enableval], [use_atomic=yes]) -AS_IF([test "x$use_atomic" = "xyes"], [ - CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES - CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER -]) -AC_CHECK_SIZEOF(void *) -AC_CHECK_SIZEOF(int) -AC_CHECK_SIZEOF(long) -AC_CHECK_SIZEOF(long long) -AC_CHECK_SIZEOF(size_t) - -AC_MSG_CHECKING([for native Win32]) -case "$host" in - *-*-mingw*) - cairo_os_win32=yes - ;; - *) - cairo_os_win32=no - ;; -esac -AC_MSG_RESULT([$cairo_os_win32]) -AM_CONDITIONAL(OS_WIN32, test "$cairo_os_win32" = "yes") - -AC_MSG_CHECKING([for Sun Solaris (non-POSIX ctime_r)]) -case "$host" in - *-*-solaris*) - CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS" - solaris_posix_pthread=yes - ;; - *) - solaris_posix_pthread=no - ;; -esac -AC_MSG_RESULT([$solaris_posix_pthread]) - -dnl ==================================================================== -dnl Library checks -dnl ==================================================================== - -AC_CHECK_LIBM -LIBS="$LIBS $LIBM" - -AC_CHECK_LIB(rt, sched_yield) - -has_shm_open= -AC_CHECK_LIB(rt, shm_open, [ - SHM_LIBS=-lrt - has_shm_open=yes - ], [SHM_LIBS=]) -AM_CONDITIONAL(HAVE_SHM, test "x$has_shm_open" = "xyes") -AC_SUBST(SHM_LIBS) - -AC_CHECK_LIB(socket, connect, [SOCKET_LIBS=-lsocket], [SOCKET_LIBS=]) -CAIROBOILERPLATE_LIBS=$SOCKET_LIBS -AC_SUBST(CAIROBOILERPLATE_LIBS) - -dnl ==================================================================== -dnl Header/function checks -dnl ==================================================================== - -dnl check if we have a __builtin_return_address for the cairo-trace -dnl utility. -AC_MSG_CHECKING([for __builtin_return_address(0)]) -AC_TRY_COMPILE([],[__builtin_return_address(0);], - [have_builtin_return_address=yes], - [have_builtin_return_address=no]) -AC_MSG_RESULT($have_builtin_return_address) -if test "x$have_builtin_return_address" = "xyes"; then - AC_DEFINE(HAVE_BUILTIN_RETURN_ADDRESS, 1, - [Define to 1 if your compiler supports the __builtin_return_address() intrinsic.]) -fi - -dnl Checks for precise integer types -AC_CHECK_HEADERS([stdint.h inttypes.h sys/int_types.h]) -AC_CHECK_TYPES([uint64_t, uint128_t, __uint128_t]) - -dnl Check for socket support for any2ppm daemon -AC_CHECK_HEADERS([fcntl.h unistd.h signal.h sys/stat.h sys/socket.h sys/poll.h sys/un.h]) - -dnl Check for infinite loops -AC_CHECK_FUNCS([alarm]) - -dnl check for CPU affinity support -AC_CHECK_HEADERS([sched.h], [AC_CHECK_FUNCS([sched_getaffinity])]) - -dnl check for mmap support -AC_CHECK_HEADERS([sys/mman.h], [AC_CHECK_FUNCS([mmap])]) - -dnl check for clock_gettime() support -AC_CHECK_HEADERS([time.h], [AC_CHECK_FUNCS([clock_gettime])]) - -dnl check for GNU-extensions to fenv -AC_CHECK_HEADER(fenv.h, - [AC_CHECK_FUNCS(feenableexcept fedisableexcept feclearexcept)]) - -dnl check for misc headers and functions -AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h sys/wait.h]) -AC_CHECK_FUNCS([ctime_r drand48 flockfile funlockfile getline link strndup]) - -dnl check for win32 headers (this detects mingw as well) -AC_CHECK_HEADERS([windows.h], have_windows=yes, have_windows=no) - - -dnl Possible headers for mkdir -AC_CHECK_HEADERS([sys/stat.h io.h]) -AC_CHECK_FUNC(mkdir, - [AC_MSG_CHECKING([mkdir variant]) - mkdir_variant="unknown" - save_CFLAGS="$CFLAGS" - CFLAGS=$WARN_CFLAGS - AC_TRY_COMPILE([ -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif - ], - [mkdir ("hello.world", 0777)], - mkdir_variant="mkdir(path, mode)", - [AC_TRY_COMPILE([ -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif - ], - [mkdir ("hello.world")], - mkdir_variant="mkdir(path)")]) - AC_MSG_RESULT([$mkdir_variant]) - CFLAGS="$save_CFLAGS" - if test "x$mkdir_variant" = "xmkdir(path, mode)"; then - AC_DEFINE(HAVE_MKDIR, 2, - [Define to non-zero if your system has mkdir, and to 2 if your version of mkdir requires a mode parameter]) - else - AC_DEFINE(HAVE_MKDIR, 1, - [Define to non-zero if your system has mkdir, and to 2 if your version of mkdir requires a mode parameter]) - fi]) - -dnl =========================================================================== -dnl -dnl Test for the tools required for building one big test binary -dnl - -AC_CHECK_FUNCS(fork waitpid raise) - diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.tools b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.tools deleted file mode 100644 index a24dbcecb91..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.tools +++ /dev/null @@ -1,25 +0,0 @@ - -AC_PATH_PROG(FIND, find) -AC_PATH_PROG(XARGS, xargs) - -AC_PROG_CC -AC_PROG_CPP -AC_PROG_CXX dnl required for BeOS (and cannot be a conditional dependency) -AM_PROG_CC_C_O -AC_C_INLINE - -dnl =========================================================================== - -PKG_PROG_PKG_CONFIG() -if test "x$PKG_CONFIG" = x; then - AC_MSG_ERROR([pkg-config >= $PKGCONFIG_REQUIRED required but not found (http://pkgconfig.freedesktop.org/)]) -fi - -dnl Check for recent pkg-config which supports Requires.private -case `$PKG_CONFIG --version` in -[0.?|0.?.?|0.1[0-7]|0.1[0-7].?]) PKGCONFIG_REQUIRES="Requires"; ;; -*) PKGCONFIG_REQUIRES="Requires.private"; ;; -esac - -AC_SUBST(PKGCONFIG_REQUIRES) - diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.version b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.version deleted file mode 100644 index a91cee39eef..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.version +++ /dev/null @@ -1,42 +0,0 @@ -dnl -dnl Version stuff -dnl - -dnl This macro expands to one of 'git', 'snapshot', or 'release' -m4_define([cairo_release_status], - [m4_if(m4_eval(cairo_version_micro % 2), [1], [git], - [m4_if(m4_eval(cairo_version_minor % 2), [1], [snapshot], - [release])])]) - -dnl This is the .so/dll number. 2 for cairo-1.x.x -m4_define([cairo_version_sonum], m4_eval(cairo_version_major + 1)) - -dnl The libtool shared library version stuff -m4_define([cairo_version], - m4_eval(cairo_version_major*10000 + cairo_version_minor*100 + cairo_version_micro)) -m4_if(m4_eval(cairo_version_minor % 2), [1], - [ - dnl for unstable releases - m4_define([cairo_libtool_revision], 0) - ], - [ - dnl for stable releases - m4_define([cairo_libtool_revision], cairo_version_micro) - ]) -m4_define([cairo_libtool_current], - m4_eval(cairo_version_sonum + cairo_version - cairo_libtool_revision)) -m4_define([cairo_libtool_age], - m4_eval(cairo_libtool_current - cairo_version_sonum)) - -CAIRO_VERSION_MAJOR=cairo_version_major -CAIRO_VERSION_MINOR=cairo_version_minor -CAIRO_VERSION_MICRO=cairo_version_micro -CAIRO_VERSION_SONUM=cairo_version_sonum -CAIRO_RELEASE_STATUS=cairo_release_status -CAIRO_LIBTOOL_VERSION_INFO=cairo_libtool_current:cairo_libtool_revision:cairo_libtool_age -AC_SUBST(CAIRO_VERSION_MAJOR) -AC_SUBST(CAIRO_VERSION_MINOR) -AC_SUBST(CAIRO_VERSION_MICRO) -AC_SUBST(CAIRO_VERSION_SONUM) -AC_SUBST(CAIRO_RELEASE_STATUS) -AC_SUBST(CAIRO_LIBTOOL_VERSION_INFO) diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.warnings b/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.warnings deleted file mode 100644 index 74e6634b29c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/configure.ac.warnings +++ /dev/null @@ -1,99 +0,0 @@ -dnl Use lots of warning flags with with gcc and compatible compilers - -dnl Note: if you change the following variable, the cache is automatically -dnl skipped and all flags rechecked. So there's no need to do anything -dnl else. If for any reason you need to force a recheck, just change -dnl MAYBE_WARN in an ignorable way (like adding whitespace) - -# -Wcast-align generates lots of false positive reports we need to -# cast image data from uint8_t to uin32_t. - -# -Wlogical-op causes too much noise from strcmp("literal", str) - -MAYBE_WARN="-Wall -Wextra \ --Wmissing-declarations -Werror-implicit-function-declaration \ --Wpointer-arith -Wwrite-strings -Wsign-compare -Wpacked --Wswitch-enum -Wmissing-format-attribute -Wvolatile-register-var \ --Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \ --Wno-missing-field-initializers -Wno-unused-parameter \ --Wno-attributes -Wno-long-long -Winline" - -MAYBE_C_SPECIFIC_WARN="-Wold-style-definition \ --Wdeclaration-after-statement -Wstrict-prototypes \ --Wmissing-prototypes -Wbad-function-cast -Wnested-externs" - -# New -Wno options should be added here -# gcc-4.4 and later accept every -Wno- option but may complain later that this -# option is unknow each time another warning happen. -# -Wunused-but-set-variable is too noisy at present -NO_WARN="unused-but-set-variable" - -dnl Sun Studio 12 likes to rag at us for abusing enums like -dnl having cairo_status_t variables hold cairo_int_status_t -dnl values. It's bad, we know. Now please be quiet. -MAYBE_WARN="$MAYBE_WARN -erroff=E_ENUM_TYPE_MISMATCH_ARG \ - -erroff=E_ENUM_TYPE_MISMATCH_OP" - -dnl We also abuse the warning-flag facility to enable other compiler -dnl options. Namely, the following: -MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common" - -dnl Also to turn various gcc/glibc-specific preprocessor checks -MAYBE_WARN="$MAYBE_WARN -Wp,-D_FORTIFY_SOURCE=2" - -# invalidate cached value if MAYBE_WARN has changed -if test "x$cairo_cv_warn_maybe" != "x$MAYBE_WARN"; then - unset cairo_cv_warn_cflags -fi -AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [ - echo - WARN_CFLAGS="" - - # Some warning options are not supported by all versions of - # gcc, so test all desired options against the current - # compiler. - # - # Note that there are some order dependencies - # here. Specifically, an option that disables a warning will - # have no net effect if a later option then enables that - # warnings, (perhaps implicitly). So we put some grouped - # options (-Wall and -Wextra) up front and the -Wno options - # last. - - for W in $MAYBE_WARN; do - CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"]) - done - for W in $NO_WARN; do - CAIRO_CC_TRY_FLAG([-W$W -Wno-$W],, [WARN_CFLAGS="$WARN_CFLAGS -Wno-$W"]) - done - cairo_cv_warn_cflags=$WARN_CFLAGS - cairo_cv_warn_maybe="$MAYBE_WARN $MAYBE_C_SPECIFIC_WARN" - - AC_MSG_CHECKING([which warning flags were supported]) -]) -WARN_CFLAGS="$cairo_cv_warn_cflags" -CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS" - -# We only wish to enable attribute(warn_unused_result) if we can prevent -# gcc from generating thousands of warnings about the misapplication of the -# attribute to void functions and variables. -AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [ - AC_REQUIRE([AC_PROG_GREP]) - cairo_cv_warn_unused_result="" - if echo $WARN_CFLAGS | $GREP -e '-Wno-attributes' >/dev/null; then - CAIRO_CC_TRY_FLAG_SILENT( - [-Wno-attributes], - [__attribute__((__warn_unused_result__)) void f (void) {} - __attribute__((__warn_unused_result__)) int g;], - [cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"]) - fi -]) -AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result], - [Define to the value your compiler uses to support the warn-unused-result attribute]) - -dnl check linker flags -AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags, - [CAIRO_CC_TRY_FLAG_SILENT([-Wl,--allow-shlib-undefined], [], - [cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")]) -CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags" -AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS) diff --git a/Build/source/libs/cairo/cairo-1.14.2/build/gtk-doc.m4 b/Build/source/libs/cairo/cairo-1.14.2/build/gtk-doc.m4 deleted file mode 100644 index 36755432b50..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/build/gtk-doc.m4 +++ /dev/null @@ -1,88 +0,0 @@ -dnl -*- mode: autoconf -*- - -# serial 2 - -dnl Usage: -dnl GTK_DOC_CHECK([minimum-gtk-doc-version]) -AC_DEFUN([GTK_DOC_CHECK], -[ - AC_REQUIRE([PKG_PROG_PKG_CONFIG]) - AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first - AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first - - ifelse([$1],[],[gtk_doc_requires="gtk-doc"],[gtk_doc_requires="gtk-doc >= $1"]) - AC_MSG_CHECKING([for gtk-doc]) - PKG_CHECK_EXISTS([$gtk_doc_requires],[have_gtk_doc=yes],[have_gtk_doc=no]) - AC_MSG_RESULT($have_gtk_doc) - - if test "$have_gtk_doc" = "no"; then - AC_MSG_WARN([ - You will not be able to create source packages with 'make dist' - because $gtk_doc_requires is not found.]) - fi - - dnl check for tools we added during development - dnl Use AC_CHECK_PROG to avoid the check target using an absolute path that - dnl may not be writable by the user. Currently, automake requires that the - dnl test name must end in '.test'. - dnl https://bugzilla.gnome.org/show_bug.cgi?id=701638 - AC_CHECK_PROG([GTKDOC_CHECK],[gtkdoc-check],[gtkdoc-check.test]) - AC_PATH_PROG([GTKDOC_CHECK_PATH],[gtkdoc-check]) - AC_PATH_PROGS([GTKDOC_REBASE],[gtkdoc-rebase],[true]) - AC_PATH_PROG([GTKDOC_MKPDF],[gtkdoc-mkpdf]) - - dnl for overriding the documentation installation directory - AC_ARG_WITH([html-dir], - AS_HELP_STRING([--with-html-dir=PATH], [path to installed docs]),, - [with_html_dir='${datadir}/gtk-doc/html']) - HTML_DIR="$with_html_dir" - AC_SUBST([HTML_DIR]) - - dnl enable/disable documentation building - AC_ARG_ENABLE([gtk-doc], - AS_HELP_STRING([--enable-gtk-doc], - [use gtk-doc to build documentation [[default=no]]]),, - [enable_gtk_doc=no]) - - AC_MSG_CHECKING([whether to build gtk-doc documentation]) - AC_MSG_RESULT($enable_gtk_doc) - - if test "x$enable_gtk_doc" = "xyes" && test "$have_gtk_doc" = "no"; then - AC_MSG_ERROR([ - You must have $gtk_doc_requires installed to build documentation for - $PACKAGE_NAME. Please install gtk-doc or disable building the - documentation by adding '--disable-gtk-doc' to '[$]0'.]) - fi - - dnl don't check for glib if we build glib - if test "x$PACKAGE_NAME" != "xglib"; then - dnl don't fail if someone does not have glib - PKG_CHECK_MODULES(GTKDOC_DEPS, glib-2.0 >= 2.10.0 gobject-2.0 >= 2.10.0,,[:]) - fi - - dnl enable/disable output formats - AC_ARG_ENABLE([gtk-doc-html], - AS_HELP_STRING([--enable-gtk-doc-html], - [build documentation in html format [[default=yes]]]),, - [enable_gtk_doc_html=yes]) - AC_ARG_ENABLE([gtk-doc-pdf], - AS_HELP_STRING([--enable-gtk-doc-pdf], - [build documentation in pdf format [[default=no]]]),, - [enable_gtk_doc_pdf=no]) - - if test -z "$GTKDOC_MKPDF"; then - enable_gtk_doc_pdf=no - fi - - if test -z "$AM_DEFAULT_VERBOSITY"; then - AM_DEFAULT_VERBOSITY=1 - fi - AC_SUBST([AM_DEFAULT_VERBOSITY]) - - AM_CONDITIONAL([HAVE_GTK_DOC], [test x$have_gtk_doc = xyes]) - AM_CONDITIONAL([ENABLE_GTK_DOC], [test x$enable_gtk_doc = xyes]) - AM_CONDITIONAL([GTK_DOC_BUILD_HTML], [test x$enable_gtk_doc_html = xyes]) - AM_CONDITIONAL([GTK_DOC_BUILD_PDF], [test x$enable_gtk_doc_pdf = xyes]) - AM_CONDITIONAL([GTK_DOC_USE_LIBTOOL], [test -n "$LIBTOOL"]) - AM_CONDITIONAL([GTK_DOC_USE_REBASE], [test -n "$GTKDOC_REBASE"]) -]) diff --git a/Build/source/libs/cairo/cairo-1.14.2/cairo-version.h b/Build/source/libs/cairo/cairo-1.14.2/cairo-version.h deleted file mode 100644 index 516999ee6c3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/cairo-version.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CAIRO_VERSION_H -#define CAIRO_VERSION_H - -#define CAIRO_VERSION_MAJOR 1 -#define CAIRO_VERSION_MINOR 14 -#define CAIRO_VERSION_MICRO 2 - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/config.h.in b/Build/source/libs/cairo/cairo-1.14.2/config.h.in deleted file mode 100644 index 14e3f444003..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/config.h.in +++ /dev/null @@ -1,413 +0,0 @@ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -#undef AC_APPLE_UNIVERSAL_BUILD - -/* whether memory barriers are needed around atomic operations */ -#undef ATOMIC_OP_NEEDS_MEMORY_BARRIER - -/* Define to 1 if the PDF backend can be tested (need poppler and other - dependencies for pdf2png) */ -#undef CAIRO_CAN_TEST_PDF_SURFACE - -/* Define to 1 if the PS backend can be tested (needs ghostscript) */ -#undef CAIRO_CAN_TEST_PS_SURFACE - -/* Define to 1 if the SVG backend can be tested */ -#undef CAIRO_CAN_TEST_SVG_SURFACE - -/* Define to 1 if the Win32 Printing backend can be tested (needs ghostscript) - */ -#undef CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE - -/* Define to 1 if dlsym is available */ -#undef CAIRO_HAS_DLSYM - -/* Define to 1 to enable cairo's cairo-script-interpreter feature */ -#undef CAIRO_HAS_INTERPRETER - -/* Define to 1 to enable cairo's pthread feature */ -#undef CAIRO_HAS_PTHREAD - -/* Define to 1 if we have full pthread support */ -#undef CAIRO_HAS_REAL_PTHREAD - -/* Define to 1 if libspectre is available */ -#undef CAIRO_HAS_SPECTRE - -/* Define to 1 to enable cairo's symbol-lookup feature */ -#undef CAIRO_HAS_SYMBOL_LOOKUP - -/* Define to 1 to enable cairo's test surfaces feature */ -#undef CAIRO_HAS_TEST_SURFACES - -/* Define to 1 to enable cairo's cairo-trace feature */ -#undef CAIRO_HAS_TRACE - -/* Define to 1 to disable certain code paths that rely heavily on double - precision floating-point calculation */ -#undef DISABLE_SOME_FLOATING_POINT - -/* Define to 1 if your system stores words within floats with the most - significant word first */ -#undef FLOAT_WORDS_BIGENDIAN - -/* Enable pixman glyph cache */ -#undef HAS_PIXMAN_GLYPHS - -/* Define to 1 if you have the `alarm' function. */ -#undef HAVE_ALARM - -/* Define to 1 if you have the binutils development files installed */ -#undef HAVE_BFD - -/* Define to 1 if your compiler supports the __builtin_return_address() - intrinsic. */ -#undef HAVE_BUILTIN_RETURN_ADDRESS - -/* Define to 1 if you have the header file. */ -#undef HAVE_BYTESWAP_H - -/* Define to 1 if you have the `clock_gettime' function. */ -#undef HAVE_CLOCK_GETTIME - -/* Define to 1 if you have the `ctime_r' function. */ -#undef HAVE_CTIME_R - -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the `drand48' function. */ -#undef HAVE_DRAND48 - -/* Define to 1 if you have the `FcFini' function. */ -#undef HAVE_FCFINI - -/* Define to 1 if you have the `FcInit' function. */ -#undef HAVE_FCINIT - -/* Define to 1 if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define to 1 if you have the `feclearexcept' function. */ -#undef HAVE_FECLEAREXCEPT - -/* Define to 1 if you have the `fedisableexcept' function. */ -#undef HAVE_FEDISABLEEXCEPT - -/* Define to 1 if you have the `feenableexcept' function. */ -#undef HAVE_FEENABLEEXCEPT - -/* Define to 1 if you have the header file. */ -#undef HAVE_FENV_H - -/* Define to 1 if you have the `flockfile' function. */ -#undef HAVE_FLOCKFILE - -/* Define to 1 if you have the `fork' function. */ -#undef HAVE_FORK - -/* Define to 1 if you have the `FT_Get_X11_Font_Format' function. */ -#undef HAVE_FT_GET_X11_FONT_FORMAT - -/* Define to 1 if you have the `FT_GlyphSlot_Embolden' function. */ -#undef HAVE_FT_GLYPHSLOT_EMBOLDEN - -/* Define to 1 if you have the `FT_GlyphSlot_Oblique' function. */ -#undef HAVE_FT_GLYPHSLOT_OBLIQUE - -/* Define to 1 if you have the `FT_Library_SetLcdFilter' function. */ -#undef HAVE_FT_LIBRARY_SETLCDFILTER - -/* Define to 1 if you have the `FT_Load_Sfnt_Table' function. */ -#undef HAVE_FT_LOAD_SFNT_TABLE - -/* Define to 1 if you have the `funlockfile' function. */ -#undef HAVE_FUNLOCKFILE - -/* Whether you have gcov */ -#undef HAVE_GCOV - -/* Define to 1 if you have the `getline' function. */ -#undef HAVE_GETLINE - -/* Enable if your compiler supports the Intel __sync_* atomic primitives */ -#undef HAVE_INTEL_ATOMIC_PRIMITIVES - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_IO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_LIBGEN_H - -/* Define to 1 if you have the `rt' library (-lrt). */ -#undef HAVE_LIBRT - -/* Enable if you have libatomic-ops-dev installed */ -#undef HAVE_LIB_ATOMIC_OPS - -/* Define to 1 if you have the `link' function. */ -#undef HAVE_LINK - -/* Define to 1 if you have the Valgrind lockdep tool */ -#undef HAVE_LOCKDEP - -/* Define to 1 if you have lzo available */ -#undef HAVE_LZO - -/* Define to 1 if you have the Valgrind memfault tool */ -#undef HAVE_MEMFAULT - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to non-zero if your system has mkdir, and to 2 if your version of - mkdir requires a mode parameter */ -#undef HAVE_MKDIR - -/* Define to 1 if you have the `mmap' function. */ -#undef HAVE_MMAP - -/* Enable if you have MacOS X atomic operations */ -#undef HAVE_OS_ATOMIC_OPS - -/* Define to 1 if you have the `poppler_page_render' function. */ -#undef HAVE_POPPLER_PAGE_RENDER - -/* Define to 1 if you have the `raise' function. */ -#undef HAVE_RAISE - -/* Define to 1 if you have the `rsvg_pixbuf_from_file' function. */ -#undef HAVE_RSVG_PIXBUF_FROM_FILE - -/* Define to 1 if you have the `sched_getaffinity' function. */ -#undef HAVE_SCHED_GETAFFINITY - -/* Define to 1 if you have the header file. */ -#undef HAVE_SCHED_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SETJMP_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SIGNAL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the `strndup' function. */ -#undef HAVE_STRNDUP - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_INT_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_IOCTL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_MMAN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_POLL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SOCKET_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_UN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_WAIT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_TIME_H - -/* Define to 1 if the system has the type `uint128_t'. */ -#undef HAVE_UINT128_T - -/* Define to 1 if the system has the type `uint64_t'. */ -#undef HAVE_UINT64_T - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to 1 if you have Valgrind */ -#undef HAVE_VALGRIND - -/* Define to 1 if you have the `waitpid' function. */ -#undef HAVE_WAITPID - -/* Define to 1 if you have the header file. */ -#undef HAVE_WINDOWS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_X11_EXTENSIONS_SHMPROTO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_X11_EXTENSIONS_SHMSTR_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_X11_EXTENSIONS_XSHM_H - -/* Define to 1 if you have the `XRenderCreateConicalGradient' function. */ -#undef HAVE_XRENDERCREATECONICALGRADIENT - -/* Define to 1 if you have the `XRenderCreateLinearGradient' function. */ -#undef HAVE_XRENDERCREATELINEARGRADIENT - -/* Define to 1 if you have the `XRenderCreateRadialGradient' function. */ -#undef HAVE_XRENDERCREATERADIALGRADIENT - -/* Define to 1 if you have the `XRenderCreateSolidFill' function. */ -#undef HAVE_XRENDERCREATESOLIDFILL - -/* Define to 1 if you have zlib available */ -#undef HAVE_ZLIB - -/* Define to 1 if the system has the type `__uint128_t'. */ -#undef HAVE___UINT128_T - -/* Define to 1 if shared memory segments are released deferred. */ -#undef IPC_RMID_DEFERRED_RELEASE - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Shared library file extension */ -#undef SHARED_LIB_EXT - -/* The size of `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of `long long', as computed by sizeof. */ -#undef SIZEOF_LONG_LONG - -/* The size of `size_t', as computed by sizeof. */ -#undef SIZEOF_SIZE_T - -/* The size of `void *', as computed by sizeof. */ -#undef SIZEOF_VOID_P - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# undef _ALL_SOURCE -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# undef _POSIX_PTHREAD_SEMANTICS -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# undef _TANDEM_SOURCE -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif - - -/* Define to the value your compiler uses to support the warn-unused-result - attribute */ -#undef WARN_UNUSED_RESULT - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -# undef WORDS_BIGENDIAN -# endif -#endif - - -/* Deal with multiple architecture compiles on Mac OS X */ -#ifdef __APPLE_CC__ -#ifdef __BIG_ENDIAN__ -#define WORDS_BIGENDIAN 1 -#define FLOAT_WORDS_BIGENDIAN 1 -#else -#undef WORDS_BIGENDIAN -#undef FLOAT_WORDS_BIGENDIAN -#endif -#endif - - -/* Define to 1 if the X Window System is missing or not being used. */ -#undef X_DISPLAY_MISSING - -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -#undef _FILE_OFFSET_BITS - -/* Define for large files, on AIX-style hosts. */ -#undef _LARGE_FILES - -/* Define to 1 if on MINIX. */ -#undef _MINIX - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -#undef _POSIX_1_SOURCE - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -#undef _POSIX_SOURCE - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -#undef inline -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/configure.ac b/Build/source/libs/cairo/cairo-1.14.2/configure.ac deleted file mode 100644 index 2ce19599e30..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/configure.ac +++ /dev/null @@ -1,878 +0,0 @@ -AC_PREREQ([2.63]) -CAIRO_PARSE_VERSION -AC_INIT([cairo], - [cairo_version_major.cairo_version_minor.cairo_version_micro], - [http://bugs.freedesktop.org/enter_bug.cgi?product=cairo], - [cairo], - [http://cairographics.org/]) -AC_CONFIG_AUX_DIR(build) -AC_CONFIG_MACRO_DIR(build) -AC_USE_SYSTEM_EXTENSIONS -AC_CONFIG_SRCDIR(src/cairo.h) -AC_CONFIG_HEADERS(config.h) - -AC_CHECK_HEADERS([unistd.h sys/ioctl.h]) - -AM_INIT_AUTOMAKE([1.11 foreign -Wall no-define no-dist-gzip dist-xz]) -AM_SILENT_RULES([yes]) -m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) dnl Workaround for Automake 1.12 - -# Initialize libtool -LT_PREREQ([2.2]) -LT_INIT([win32-dll]) - -# Api documentation -GTK_DOC_CHECK([1.15],[--flavour no-tmpl]) - -AC_SYS_LARGEFILE - -dnl =========================================================================== -dnl -dnl The order of the includes here is rather important -dnl -m4_include(build/configure.ac.version) dnl macros setting up various version declares -m4_include(build/configure.ac.tools) dnl checks for tools we use -m4_include(build/configure.ac.features) dnl macros for backend/feature handling -m4_include(build/configure.ac.warnings) dnl checks for compiler warning -m4_include(build/configure.ac.system) dnl checks for system functions, headers, libs -m4_include(build/configure.ac.analysis) dnl checks for analysis tools (lcov, etc) -m4_include(build/configure.ac.noversion) dnl disable builtin libtool versioning -m4_include(build/configure.ac.pthread) dnl checks for pthreads -AC_CACHE_SAVE - -dnl =========================================================================== - -AC_CHECK_LIB(z, compress, - [AC_CHECK_HEADER(zlib.h, [ - have_libz=yes - AC_DEFINE(HAVE_ZLIB, 1, [Define to 1 if you have zlib available]) - ], - [have_libz="no (requires zlib http://www.gzip.org/zlib/)"])], - [have_libz="no (requires zlib http://www.gzip.org/zlib/)"]) - -save_LIBS="$LIBS" -AC_CHECK_LIB(lzo2, lzo2a_decompress, - [AC_CHECK_HEADER(lzo/lzo2a.h, [ - have_lzo=yes - AC_DEFINE(HAVE_LZO, 1, [Define to 1 if you have lzo available]) - lzo_LIBS="-llzo2" - ], - [have_lzo="no (requires lzpo http://www.oberhumer.com/opensource/lzo/)"])], - [have_lzo="no (requires lzpo http://www.oberhumer.com/opensource/lzo/)"]) -AC_SUBST(lzo_LIBS) -LIBS="$save_LIBS" - -AC_CHECK_LIB(dl, dlsym, - [have_dlsym=yes; have_dl=yes], - [have_dlsym=no; have_dl=no]) -if test "x$have_dlsym" = "xno"; then - AC_CHECK_FUNC(dlsym, [have_dlsym=yes], [have_dlsym=no]) -fi -AC_CHECK_HEADERS(dlfcn.h, [have_dlsym=yes], [have_dlsym=no]) -AM_CONDITIONAL(CAIRO_HAS_DL, test "x$have_dl" = "xyes") -if test "x$have_dlsym" = "xyes"; then - AC_DEFINE([CAIRO_HAS_DLSYM], 1, [Define to 1 if dlsym is available]) -fi -AM_CONDITIONAL(CAIRO_HAS_DLSYM, test "x$have_dlsym" = "xyes") - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(xlib, Xlib, auto, [ - xlib_REQUIRES="x11 xext" - PKG_CHECK_MODULES(xlib, $xlib_REQUIRES, , - [xlib_REQUIRES="" - AC_PATH_XTRA - if test "x$no_x" = xyes; then - use_xlib="no (requires X development libraries)" - else - xlib_NONPKGCONFIG_LIBS="$X_PRE_LIBS $X_LIBS -lX11 -lXext $X_EXTRA_LIBS" - xlib_NONPKGCONFIG_CFLAGS=$X_CFLAGS - fi]) - - AC_CHECK_HEADER(sys/ipc.h) - AC_CHECK_HEADER(sys/shm.h) - - if test "$ac_cv_header_sys_ipc_h" = "yes" -a "$ac_cv_header_sys_shm_h" = "yes"; then - AC_MSG_CHECKING(whether shmctl IPC_RMID allowes subsequent attaches) - AC_TRY_RUN([ - #include - #include - #include - int main() - { - char *shmaddr; - int id = shmget (IPC_PRIVATE, 4, IPC_CREAT | 0600); - if (id == -1) return 2; - shmaddr = shmat (id, 0, 0); - shmctl (id, IPC_RMID, 0); - if ((char*) shmat (id, 0, 0) == (char*) -1) { - shmdt (shmaddr); - return 1; - } - shmdt (shmaddr); - shmdt (shmaddr); - return 0; - } - ], - AC_DEFINE(IPC_RMID_DEFERRED_RELEASE, 1, - [Define to 1 if shared memory segments are released deferred.]) - AC_MSG_RESULT(yes), - AC_MSG_RESULT(no), - AC_MSG_RESULT(assuming no)) - fi - - AC_CHECK_HEADERS([X11/extensions/XShm.h X11/extensions/shmproto.h X11/extensions/shmstr.h], [], [], - [#include - #include ]) -]) - -CAIRO_ENABLE_SURFACE_BACKEND(xlib_xrender, Xlib Xrender, auto, [ - if test "x$use_xlib" != "xyes"; then - use_xlib_xrender="no (requires --enable-xlib)" - else - dnl Check for Xrender header files if the Xrender package is not installed: - xlib_xrender_BASE=cairo-xlib - xlib_xrender_REQUIRES="xrender >= 0.6" - PKG_CHECK_MODULES(xlib_xrender, $xlib_xrender_REQUIRES, , - [xlib_xrender_REQUIRES="" - old_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$CPPFLAGS $xlib_CFLAGS $xlib_NONPKGCONFIG_CFLAGS" - AC_CHECK_HEADER(X11/extensions/Xrender.h, - [xlib_xrender_NONPKGCONFIG_LIBS="-lXrender"], - [use_xlib_xrender="no (requires $xlib_xrender_REQUIRES http://freedesktop.org/Software/xlibs)"], - [#include ]) - CPPFLAGS=$old_CPPFLAGS - ]) - - old_CFLAGS=$CFLAGS - old_LIBS=$LIBS - CFLAGS="$CFLAGS $xlib_CFLAGS $xlib_NONPKGCONFIG_CFLAGS $xlib_xrender_CFLAGS $xlib_xrender_NONPKGCONFIG_CFLAGS" - LIBS="$LIBS $xlib_LIBS $xlib_NONPKGCONFIG_LIBS $xlib_xrender_LIBS $xlib_xrender_NONPKGCONFIG_LIBS" - AC_CHECK_FUNCS([XRenderCreateSolidFill XRenderCreateLinearGradient XRenderCreateRadialGradient XRenderCreateConicalGradient]) - CFLAGS=$old_CFLAGS - LIBS=$old_LIBS - - fi -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(xcb, XCB, auto, [ - xcb_REQUIRES="xcb >= 1.6 xcb-render >= 1.6" - PKG_CHECK_MODULES(xcb, $xcb_REQUIRES, , - [use_xcb="no (requires $xcb_REQUIRES http://xcb.freedesktop.org)"]) -]) - -CAIRO_ENABLE_FUNCTIONS(xlib_xcb, Xlib/XCB, no, [ - if test "x$use_xcb" = "xyes" -a "x$use_xlib" = "xyes"; then - xlib_xcb_REQUIRES="x11-xcb" - PKG_CHECK_MODULES(xlib_xcb, $xlib_xcb_REQUIRES, , - [use_xlib_xcb="no (requires $xlib_xcb_REQUIRES http://xcb.freedesktop.org)"]) - else - use_xlib_xcb="no (requires both --enable-xlib and --enable-xcb)" - fi -]) - -CAIRO_ENABLE_FUNCTIONS(xcb_shm, XCB/SHM, auto, [ - if test "x$use_xcb" = "xyes"; then - xcb_shm_REQUIRES="xcb-shm" - PKG_CHECK_MODULES(xcb_shm, $xcb_shm_REQUIRES, , - [use_xcb_shm="no (requires $xcb_shm http://xcb.freedesktop.org)"]) - else - use_xcb_shm="no (requires --enable-xcb)" - fi -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(qt, Qt, no, [ - qt_REQUIRES="QtGui >= 4.4.0" - PKG_CHECK_MODULES(qt, $qt_REQUIRES, , - [qt_REQUIRES="" - use_qt="no (requires Qt4 development libraries)" - ]) - qt_NONPKGCONFIG_LIBS="-lstdc++" -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(quartz, Quartz, auto, [ - dnl There is no pkgconfig for quartz; lets do a header check - AC_CHECK_HEADER(ApplicationServices/ApplicationServices.h, , [use_quartz="no (requires ApplicationServices framework)"]) - if test "x$use_quartz" != "xyes" ; then - dnl check for CoreGraphics as a separate framework - AC_CHECK_HEADER(CoreGraphics/CoreGraphics.h, , [use_quartz="no (requires CoreGraphics framework)"]) - quartz_LIBS="-Xlinker -framework -Xlinker CoreGraphics" - else - quartz_LIBS="-Xlinker -framework -Xlinker ApplicationServices" - fi -]) - -CAIRO_ENABLE_FONT_BACKEND(quartz_font, Quartz, auto, [ - use_quartz_font=$use_quartz -]) - -CAIRO_ENABLE_SURFACE_BACKEND(quartz_image, Quartz Image, no, [ - use_quartz_image=$use_quartz -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(win32, Microsoft Windows, auto, [ - if test "x$have_windows" != xyes; then - use_win32="no (requires a Win32 platform)" - fi - win32_LIBS="-lgdi32 -lmsimg32" -]) - -CAIRO_ENABLE_FONT_BACKEND(win32_font, Microsoft Windows, auto, [ - use_win32_font=$use_win32 -]) - -test_win32_printing=no -if test "x$use_win32" = "xyes"; then - AC_CHECK_PROG(GS, gs, gs) - if test "$GS"; then - AC_DEFINE([CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE], 1, [Define to 1 if the Win32 Printing backend can be tested (needs ghostscript)]) - test_win32_printing="yes" - else - AC_MSG_WARN([Win32 Printing backend will not be tested since ghostscript is not available]) - test_win32_printing="no (requires ghostscript)" - fi -fi - -AM_CONDITIONAL(CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE, test "x$test_win32_printing" = "xyes") - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(skia, Skia, no, [ - AC_ARG_WITH([skia], - [AS_HELP_STRING([--with-skia=/path/to/skia], - [directory to find compiled skia sources])], - [skia_DIR="$withval"], - [skia_DIR="`pwd`/../skia"]) - AC_ARG_WITH([skia-build-type], - [AS_HELP_STRING([--with-skia-build-type=(Release|Debug)] - [build of skia to link with, default is Release])], - [skia_BUILD_TYPE="$withval"], - [skia_BUILD_TYPE="Release"]) - skia_NONPKGCONFIG_CFLAGS="-I$skia_DIR/include/config -I$skia_DIR/include/core -I$skia_DIR/include/effects" - if test "x$skia_BUILD_TYPE" = "xRelease"; then - skia_NONPKGCONFIG_CFLAGS="-DSK_RELEASE -DSK_CAN_USE_FLOAT $skia_NONPKGCONFIG_CFLAGS" - fi - skia_NONPKGCONFIG_LIBS="-L$skia_DIR/out/$skia_BUILD_TYPE/lib.target/ -lskia -lstdc++" - AC_SUBST(skia_DIR) -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(os2, OS/2, no, [ - case "$host" in - *-*-os2*) - : - ;; - *) - use_os2="no (requires an OS/2 platform)" - ;; - esac -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(beos, BeOS/Zeta, no, [ - case "$host" in - *-*-beos) - beos_LIBS="" - dnl Add libbe and libzeta if available - AC_CHECK_LIB(be,main,beos_LIBS="$beos_LIBS -lbe") - AC_CHECK_LIB(zeta,main,beos_LIBS="$beos_LIBS -lzeta") - ;; - *) - use_beos="no (requires a BeOS platform)" - ;; - esac -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(drm, DRM, no, [ - drm_REQUIRES="libudev >= 136" - PKG_CHECK_MODULES(drm, $drm_REQUIRES, , - [use_drm="no (requires $drm_REQUIRES, udev is available from git://git.kernel.org/pub/scm/linux/hotplug/udev.git)"]) -]) - -CAIRO_ENABLE_SURFACE_BACKEND(gallium, Gallium3D, no, [ - if test "x$use_drm" = "xyes"; then - AC_ARG_WITH([gallium], - [AS_HELP_STRING([--with-gallium=/path/to/mesa], - [directory to find gallium enabled mesa])], - [mesa_DIR="$withval"], - [mesa_DIR="`pwd`/../mesa"]) - gallium_DIR="$mesa_DIR/src/gallium" - gallium_NONPKGCONFIG_CFLAGS="-I$mesa_DIR/include -I$mesa_DIR/src/mesa -I$gallium_DIR/include -I$gallium_DIR/auxiliary" - gallium_NONPKGCONFIG_LIBS="-lGL" - AC_SUBST(mesa_DIR) - AC_SUBST(gallium_DIR) - else - use_gallium="no (requires --enable-drm)" - fi -]) - -dnl =========================================================================== - -CAIRO_ENABLE_FUNCTIONS(png, PNG, yes, [ - use_png=no - AC_ARG_VAR([png_REQUIRES], [module name for libpng to search for using pkg-config]) - if test "x$png_REQUIRES" = x; then - # libpng13 is GnuWin32's libpng-1.2.8 :-( - for l in libpng libpng14 libpng12 libpng13 libpng10; do - if $PKG_CONFIG --exists $l ; then - png_REQUIRES=$l - use_png=yes - break - fi - done - else - use_png=yes - fi - - if test "x$use_png" = "xyes" ; then - PKG_CHECK_MODULES(png, $png_REQUIRES, , : ) - else - AC_MSG_WARN([Could not find libpng in the pkg-config search path]) - fi -]) - -dnl =========================================================================== -CAIRO_ENABLE_SURFACE_BACKEND(gl, OpenGL, no, [ - gl_REQUIRES="gl" - PKG_CHECK_MODULES(gl, $gl_REQUIRES,, [ - dnl Fallback to searching for headers - AC_CHECK_HEADER(GL/gl.h,, [use_gl="no (gl.pc nor OpenGL headers not found)"]) - if test "x$use_gl" = "xyes"; then - gl_NONPKGCONFIG_CFLAGS= - gl_NONPKGCONFIG_LIBS="-lGL" - fi]) - - if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then - gl_LIBS="$gl_LIBS -ldl" - fi - - need_glx_functions=yes - need_wgl_functions=yes - need_egl_functions=yes -]) - -dnl =========================================================================== -CAIRO_ENABLE_SURFACE_BACKEND(glesv2, OpenGLESv2, no, [ - glesv2_REQUIRES="glesv2" - PKG_CHECK_MODULES(glesv2, $glesv2_REQUIRES,, [ - dnl Fallback to searching for headers - AC_CHECK_HEADER(GLES2/gl2.h,, [use_glesv2="no (glesv2.pc nor OpenGL ES 2.0 headers not found)"]) - if test "x$use_glesv2" = "xyes"; then - glesv2_NONPKGCONFIG_CFLAGS= - glesv2_NONPKGCONFIG_LIBS="-lGLESv2" - fi]) - - if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then - glesv2_LIBS="$glesv2_LIBS -ldl" - fi - - if test "x$use_glesv2" = "xyes" -a "x$use_gl" = "xyes"; then - AC_MSG_ERROR([use either --enable-gl=yes or --enable-glesv2=yes. Not both at the same time.]) - fi - - need_egl_functions=yes -]) - -dnl =========================================================================== -CAIRO_ENABLE_SURFACE_BACKEND(cogl, Cogl, no, [ - cogl_REQUIRES="cogl-2.0-experimental" - PKG_CHECK_MODULES(cogl, $cogl_REQUIRES,, [use_cogl="no"]) -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(directfb, directfb, no, [ - directfb_REQUIRES=directfb - PKG_CHECK_MODULES(directfb, $directfb_REQUIRES, , - [use_directfb="no (requires $directfb_REQUIRES http://www.directfb.org)"]) -]) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(vg, OpenVG, no, [ - dnl There is no pkgconfig for OpenVG; lets do a header check - AC_CHECK_HEADER(VG/openvg.h,, [use_vg="no (OpenVG headers not found)"]) - if test "x$use_vg" = "xyes"; then - vg_NONPKGCONFIG_CFLAGS= - vg_NONPKGCONFIG_LIBS="-lOpenVG" - need_egl_functions=yes - need_glx_functions=yes - fi -]) - -CAIRO_ENABLE_FUNCTIONS(egl, EGL, auto, [ - if test "x$need_egl_functions" = "xyes"; then - egl_REQUIRES="egl" - PKG_CHECK_MODULES(egl, $egl_REQUIRES, , - [egl_REQUIRES="" - AC_CHECK_HEADER(EGL/egl.h,, [use_egl="no (EGL headers not found)"]) - if test "x$use_egl" = "xyes"; then - egl_NONPKGCONFIG_CFLAGS= - egl_NONPKGCONFIG_LIBS= - save_LIBS="$LIBS" - other_egl_LIBS="" - # Temporary workaround for missing link from egl13 - AC_CHECK_LIB(csi, csi_stream_attachresource, other_egl_LIBS="-lcsi") - LIBS="$other_egl_LIBS $LIBS" - for egl_lib in EGL egl13 egl12 egl11; do - if test -z "$egl_NONPKGCONFIG_LIBS"; then - AC_CHECK_LIB($egl_lib, eglGetError, egl_NONPKGCONFIG_LIBS="-l$egl_lib") - fi - done - if test -z "$egl_NONPKGCONFIG_LIBS"; then - use_egl="no (EGL library not found)" - else - egl_NONPKGCONFIG_LIBS="$egl_NONPKGCONFIG_LIBS $other_egl_LIBS" - fi - LIBS="$save_LIBS" - fi - ]) - else - use_egl="no (not required by any backend)" - fi -]) - -CAIRO_ENABLE_FUNCTIONS(glx, GLX, auto, [ - if test "x$need_glx_functions" = "xyes"; then - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $gl_CFLAGS $gl_NONPKGCONFIG_CFLAGS" - AC_CHECK_HEADER(GL/glx.h,, [use_glx="no (GLX headers not found)"]) - glx_NONPKGCONFIG_CFLAGS= - glx_NONPKGCONFIG_LIBS="-lGL" - CFLAGS="$save_CFLAGS" - else - use_glx="no (not required by any backend)" - fi -]) - -CAIRO_ENABLE_FUNCTIONS(wgl, WGL, auto, [ - if test "x$need_wgl_functions" = "xyes"; then - AC_CHECK_HEADER(windows.h,, [use_wgl="no (WGL headers not found)"]) - else - use_wgl="no (not required by any backend)" - fi -]) - -dnl =========================================================================== - -any2ppm_cs=no -CAIRO_ENABLE_SURFACE_BACKEND(script, script, yes, [ - any2ppm_cs=yes -]) - -dnl =========================================================================== - -# We use pkg-config to look for freetype2, but fall back to -# freetype-config if it fails. We prefer pkg-config, since we can -# then just put freetype2 >= $FREETYPE_MIN_VERSION in -# Requires.private, but at least up to 2003-06-07, there was no -# freetype2.pc in the release. -# -# FreeType versions come in three forms: -# release (such as 2.1.9) -# libtool (such as 9.7.3) (returned by freetype-config and pkg-config) -# platform-specific/soname (such as 6.3.4) -# and they recommend you never use the platform-specific version -# (see docs/VERSION.DLL in freetype2 sources) -# -# Set these as appropriate: - -# release number - for information only -FREETYPE_MIN_RELEASE=2.1.9 -# libtool-specific version - this is what is checked -FREETYPE_MIN_VERSION=9.7.3 - -CAIRO_ENABLE_FONT_BACKEND(ft, FreeType, auto, [ - - PKG_CHECK_MODULES(FREETYPE, freetype2 >= $FREETYPE_MIN_VERSION, - [freetype_pkgconfig=yes], - [freetype_pkgconfig=no]) - - if test "x$freetype_pkgconfig" = "xyes"; then - ft_REQUIRES="freetype2 >= $FREETYPE_MIN_VERSION $ft_REQUIRES" - else - - if test -z "$FREETYPE_CONFIG"; then - AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no) - fi - if test "x$FREETYPE_CONFIG" = "xno" ; then - use_ft='no (freetype-config not found in path or $FREETYPE_CONFIG)' - else - AC_MSG_CHECKING(freetype2 libtool version) - - FREETYPE_VERSION=`$FREETYPE_CONFIG --version` - AX_COMPARE_VERSION([$FREETYPE_VERSION], [gt], [$FREETYPE_MIN_VERSION], - [AC_MSG_RESULT($FREETYPE_VERSION - OK) - ft_NONPKGCONFIG_CFLAGS=`$FREETYPE_CONFIG --cflags` - ft_NONPKGCONFIG_LIBS=`$FREETYPE_CONFIG --libs`], - [AC_MSG_RESULT($FREETYPE_VERSION - Too old) - use_ft="no ($FREETYPE_VERSION found; version $FREETYPE_MIN_VERSION from release $FREETYPE_MIN_RELEASE required)"]) - fi - fi - - ft_CFLAGS="$FREETYPE_CFLAGS" - ft_LIBS="$FREETYPE_LIBS" -]) - -FONTCONFIG_MIN_VERSION=2.2.95 -CAIRO_ENABLE_FONT_BACKEND(fc, Fontconfig, auto, [ - use_fc=$use_ft - if test "x$use_fc" = "xyes"; then - fc_REQUIRES="fontconfig >= $FONTCONFIG_MIN_VERSION" - PKG_CHECK_MODULES(FONTCONFIG, $fc_REQUIRES,, - [use_fc="no (requires $fc_REQUIRES)"]) - fi - fc_CFLAGS="$FONTCONFIG_CFLAGS" - fc_LIBS="$FONTCONFIG_LIBS" -]) - -if test "x$use_ft" = "xyes"; then - _save_libs="$LIBS" - _save_cflags="$CFLAGS" - LIBS="$LIBS $ft_LIBS" - CFLAGS="$CFLAGS $ft_CFLAGS" - - AC_CHECK_FUNCS(FT_Get_X11_Font_Format FT_GlyphSlot_Embolden FT_GlyphSlot_Oblique FT_Load_Sfnt_Table FT_Library_SetLcdFilter) - - LIBS="$_save_libs" - CFLAGS="$_save_cflags" -fi - -if test "x$use_fc" = "xyes"; then - CAIRO_CHECK_FUNCS_WITH_FLAGS(FcInit FcFini, [$FONTCONFIG_CFLAGS], [$FONTCONFIG_LIBS]) -fi - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(ps, PostScript, yes, [ - # The ps backend requires zlib. - use_ps=$have_libz - ps_NONPKGCONFIG_LIBS=-lz -]) - -dnl =========================================================================== - -SPECTRE_VERSION_REQUIRED=0.2.0 -test_ps=no -any2ppm_ps=no -if test "x$use_ps" = "xyes"; then - AC_CHECK_PROG(GS, gs, gs) - if test "$GS"; then - AC_DEFINE([CAIRO_CAN_TEST_PS_SURFACE], 1, [Define to 1 if the PS backend can be tested (needs ghostscript)]) - test_ps="yes" - else - AC_MSG_WARN([PS backend will not be tested since ghostscript is not available]) - test_ps="no (requires ghostscript)" - fi - - libspectre_DEPENDENCY="libspectre >= $SPECTRE_VERSION_REQUIRED" - PKG_CHECK_MODULES(LIBSPECTRE, $libspectre_DEPENDENCY, - [any2ppm_ps=yes], - [test_ps="no (requires libspectre)"]) -fi - -AM_CONDITIONAL(CAIRO_CAN_TEST_PS_SURFACE, test "x$test_ps" = "xyes") -AM_CONDITIONAL(CAIRO_HAS_SPECTRE, test "x$any2ppm_ps" = "xyes") -if test "x$any2ppm_ps" = "xyes"; then - AC_DEFINE([CAIRO_HAS_SPECTRE], 1, [Define to 1 if libspectre is available]) -fi -AC_SUBST(LIBSPECTRE_CFLAGS) -AC_SUBST(LIBSPECTRE_LIBS) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(pdf, PDF, yes, [ - # The pdf backend requires zlib. - use_pdf=$have_libz - pdf_NONPKGCONFIG_LIBS=-lz -]) - -dnl =========================================================================== - -# poppler-0.17.4 fixes text-pattern and text-transform -POPPLER_VERSION_REQUIRED=0.17.4 -test_pdf=no -any2ppm_pdf=no -if test "x$use_pdf" = "xyes"; then - poppler_DEPENDENCY="poppler-glib >= $POPPLER_VERSION_REQUIRED" - PKG_CHECK_MODULES(POPPLER, $poppler_DEPENDENCY, - [CAIRO_CHECK_FUNCS_WITH_FLAGS(poppler_page_render, [$POPPLER_CFLAGS], [$POPPLER_LIBS], - [test_pdf=yes; any2ppm_pdf=yes], - [test_pdf="no (requires $poppler_DEPENDENCY)"])], - [test_pdf="no (requires $poppler_DEPENDENCY)"]) - if test "x$test_pdf" = "xyes"; then - AC_DEFINE([CAIRO_CAN_TEST_PDF_SURFACE], 1, [Define to 1 if the PDF backend can be tested (need poppler and other dependencies for pdf2png)]) - else - AC_MSG_WARN([PDF backend will not be tested since poppler >= $POPPLER_VERSION_REQUIRED is not available]) - fi -fi - -AM_CONDITIONAL(CAIRO_CAN_TEST_PDF_SURFACE, test "x$test_pdf" = "xyes") -AC_SUBST(POPPLER_CFLAGS) -AC_SUBST(POPPLER_LIBS) - -AM_CONDITIONAL(CAIRO_HAS_MULTI_PAGE_SURFACES, test "x$use_ps" = "xyes" -o "x$use_pdf" = "xyes") - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(svg, SVG, yes, [ - if test "x$use_png" != "xyes"; then - use_svg="no (requires --enable-png)" - fi -]) - -LIBRSVG_VERSION_REQUIRED=2.35.0 -test_svg=no -any2ppm_svg=no -if test "x$use_svg" = "xyes"; then - librsvg_DEPENDENCY="librsvg-2.0 >= $LIBRSVG_VERSION_REQUIRED" - PKG_CHECK_MODULES(LIBRSVG, $librsvg_DEPENDENCY gdk-2.0, - [CAIRO_CHECK_FUNCS_WITH_FLAGS(rsvg_pixbuf_from_file, [$LIBRSVG_CFLAGS], [$LIBRSVG_LIBS], - [test_svg=yes; any2ppm_svg=yes], - [test_svg="no (requires $librsvg_DEPENDENCY)"])], - [test_svg="no (requires $librsvg_DEPENDENCY)"]) - if test "x$test_svg" = "xyes"; then - AC_DEFINE([CAIRO_CAN_TEST_SVG_SURFACE], 1, [Define to 1 if the SVG backend can be tested]) - else - AC_MSG_WARN([SVG backend will not be tested since librsvg >= $LIBRSVG_VERSION_REQUIRED is not available]) - fi -fi - -AM_CONDITIONAL(CAIRO_CAN_TEST_SVG_SURFACE, test "x$test_svg" = "xyes") -AC_SUBST(LIBRSVG_CFLAGS) -AC_SUBST(LIBRSVG_LIBS) - -dnl =========================================================================== - -dnl XXX make this a private feature? -CAIRO_ENABLE(test_surfaces, test surfaces, no) - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(image, image, always, [ - pixman_REQUIRES="pixman-1 >= 0.30.0" - PKG_CHECK_MODULES(pixman, $pixman_REQUIRES, , - [use_image="no (requires $pixman_REQUIRES http://cairographics.org/releases/)"]) - image_REQUIRES=$pixman_REQUIRES - image_CFLAGS=$pixman_CFLAGS - image_LIBS=$pixman_LIBS -]) - -if pkg-config --exists 'pixman-1 >= 0.27.1'; then - AC_DEFINE([HAS_PIXMAN_GLYPHS], 1, [Enable pixman glyph cache]) -fi - - -dnl =========================================================================== - -CAIRO_ENABLE_SURFACE_BACKEND(mime, mime, always) -CAIRO_ENABLE_SURFACE_BACKEND(recording, recording, always) -CAIRO_ENABLE_SURFACE_BACKEND(observer, observer, always) -CAIRO_ENABLE_SURFACE_BACKEND(tee, tee, no) -CAIRO_ENABLE_SURFACE_BACKEND(xml, xml, no, [ - use_xml=$have_libz - xml_NONPKGCONFIG_LIBS=-lz -]) - -dnl =========================================================================== - -CAIRO_ENABLE_FONT_BACKEND(user, user, always) - -dnl =========================================================================== -dnl -dnl This needs to be last on our list of features so that the pthread libs and flags -dnl gets prefixed in front of everything else in CAIRO_{CFLAGS,LIBS}. -dnl -have_real_pthread=no -have_pthread=no -CAIRO_ENABLE(pthread, pthread, auto, [CAIRO_CONFIGURE_PTHREAD]) -AM_CONDITIONAL(HAVE_REAL_PTHREAD, test "x$use_pthread" = "xyes" -a "x$have_real_pthread" = "xyes") -AM_CONDITIONAL(HAVE_PTHREAD, test "x$use_pthread" = "xyes") -AC_SUBST(pthread_CFLAGS) -AC_SUBST(pthread_LIBS) -AC_SUBST(real_pthread_CFLAGS) -AC_SUBST(real_pthread_LIBS) - - -dnl =========================================================================== -dnl Build gobject integration library - -CAIRO_ENABLE_FUNCTIONS(gobject, gobject, auto, [ - gobject_REQUIRES="gobject-2.0 glib-2.0 >= 2.14" - PKG_CHECK_MODULES(GOBJECT, $gobject_REQUIRES, , - [use_gobject="no (requires $gobject_REQUIRES http://download.gnome.org/pub/GNOME/sources/glib/)"]) - gobject_NONPKGCONFIG_EXTRA_LIBS="-L\${libdir} -lcairo-gobject" -]) -dnl I'm too lazy to fix the caching properly -if test "x$use_gobject" = "xyes"; then - PKG_CHECK_MODULES(GOBJECT, $gobject_REQUIRES, : ) -fi - -dnl =========================================================================== -dnl Default to quick testing during development, but force a full test before -dnl release - -AC_ARG_ENABLE(full-testing, - AS_HELP_STRING([--enable-full-testing], - [Sets the test suite to perform full testing by default, which - will dramatically slow down make check, but is a - *requirement* before release.]), [ -if test "x$enableval" = "xyes"; then - CAIRO_TEST_MODE=full - AC_SUBST(CAIRO_TEST_MODE) -fi -]) - -dnl =========================================================================== -dnl Build the external converter if we have any of the test backends -AM_CONDITIONAL(BUILD_ANY2PPM, - test "x$any2ppm_svg" = "xyes" \ - -o "x$any2ppm_pdf" = "xyes" \ - -o "x$any2ppm_ps" = "xyes" \ - -o "x$any2ppm_cs" = "xyes") - -dnl =========================================================================== -dnl Some utilities need to dlopen the shared libraries, so they need to -dnl know how libtools will name them - -case $host in -*-*-darwin*) - SHLIB_EXT="dylib" - ;; -*) - SHLIB_EXT="so" - ;; -esac -AC_DEFINE_UNQUOTED(SHARED_LIB_EXT, "${SHLIB_EXT}", [Shared library file extension]) -AC_SUBST(SHLIB_EXT) - -dnl =========================================================================== -dnl The tracing utility requires LD_PRELOAD, so only build it for systems -dnl that are known to work. - -case $host in -*-linux*|*-*bsd*|*-solaris*|*-*-darwin*|*-dragonfly*|*-*-gnu*) - have_ld_preload="yes" - ;; -*) - have_ld_preload="no" - ;; -esac - -CAIRO_ENABLE(trace, cairo-trace, auto, [ - if test "x$have_ld_preload" != "xyes" -o \ - "x$have_libz" != "xyes" -o \ - "x$have_real_pthread" != "xyes" -o \ - "x$have_dlsym" != "xyes"; then - use_trace="no (requires dynamic linker and zlib and real pthreads)" - fi -]) - -CAIRO_ENABLE(interpreter, cairo-script-interpreter, yes, [ - if test "x$have_libz" != "xyes"; then - use_interpreter="no (requires zlib)" - fi -]) - -AC_CHECK_LIB(bfd, bfd_openr, - [AC_CHECK_HEADER(bfd.h, [have_bfd=yes], - [have_bfd=no])], [have_bfd=no]) -AC_CHECK_HEADER(libiberty.h,, [have_bfd=no]) -if test "x$have_bfd" = "xyes"; then - AC_DEFINE([HAVE_BFD], [1], [Define to 1 if you have the binutils development files installed]) - BFD_LIBS=-lbfd - AC_SUBST(BFD_LIBS) -fi - -CAIRO_ENABLE(symbol_lookup, symbol-lookup, auto, [ - if test "x$have_bfd" != "xyes"; then - use_symbol_lookup="no (requires bfd)" - fi -]) - -PKG_CHECK_MODULES(glib, glib-2.0, have_glib=yes, have_glib=no) -AC_SUBST(glib_CFLAGS) -AC_SUBST(glib_LIBS) -AM_CONDITIONAL(BUILD_SPHINX, test "x$have_glib" = "xyes" -a "x$have_windows" = "xno") - -save_LIBS="$LIBS" -AC_CHECK_LIB(rt, shm_open, shm_LIBS="-lrt") -AC_SUBST(shm_LIBS) -LIBS="$save_LIBS" - -dnl =========================================================================== - -AC_ARG_ENABLE(some-floating-point, - AS_HELP_STRING([--disable-some-floating-point], - [Disable certain code paths that rely heavily on double precision - floating-point calculation. This option can improve - performance on systems without a double precision floating-point - unit, but might degrade performance on those that do.]), [ -if test "x$enableval" = "xno"; then - # A value of 'no' for $enableval means that they want to disable, which - # means 'yes' for $disable_some_floating_point. - disable_some_floating_point=yes -fi -], [disable_some_floating_point=no]) - -AM_CONDITIONAL(DISABLE_SOME_FLOATING_POINT, - test "x$disable_some_floating_point" = "xyes") -if test "x$disable_some_floating_point" = "xyes"; then - AC_DEFINE(DISABLE_SOME_FLOATING_POINT, 1, - [Define to 1 to disable certain code paths that rely heavily on - double precision floating-point calculation]) -fi - -dnl =========================================================================== - -dnl Extra stuff we need to do when building C++ code -need_cxx="no" -AS_IF([test "x$use_skia" = "xyes"], [need_cxx="yes"]) -AS_IF([test "x$use_qt" = "xyes"], [need_cxx="yes"]) -AS_IF([test "x$use_beos" = "xyes"], [need_cxx="yes"]) - -AM_CONDITIONAL(BUILD_CXX, test "x$need_cxx" = "xyes") - -dnl =========================================================================== - -# We use GTK+ for some utility/debugging tools -PKG_CHECK_MODULES(gtk, "gtk+-2.0",have_gtk=yes, have_gtk=no) -AM_CONDITIONAL(HAVE_GTK, test "x$have_gtk" = "xyes") - -AC_CONFIG_FILES([ -Makefile -boilerplate/Makefile -src/Makefile -test/Makefile -test/pdiff/Makefile -perf/Makefile -perf/micro/Makefile -util/Makefile -util/cairo-fdr/Makefile -util/cairo-gobject/Makefile -util/cairo-missing/Makefile -util/cairo-script/Makefile -util/cairo-script/examples/Makefile -util/cairo-sphinx/Makefile -util/cairo-trace/Makefile -util/cairo-trace/cairo-trace -doc/Makefile -doc/public/Makefile -]) -AC_CONFIG_COMMANDS([cairo-trace], - [chmod a+x util/cairo-trace/cairo-trace]) - -AC_OUTPUT -CAIRO_REPORT diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am b/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am deleted file mode 100644 index acf0a828100..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am +++ /dev/null @@ -1,119 +0,0 @@ -# Note: All source files are listed in Makefile.sources. - -include $(top_srcdir)/build/Makefile.am.common -include $(srcdir)/Makefile.am.features - -EXTRA_DIST += Makefile.win32 Makefile.win32.features -#MAINTAINERCLEANFILES += $(srcdir)/Makefile.win32.features - -AM_CPPFLAGS = -I$(srcdir) $(CAIRO_CFLAGS) -AM_LDFLAGS = $(CAIRO_LDFLAGS) - -if OS_WIN32 -export_symbols = -export-symbols cairo.def -cairo_def_dependency = cairo.def -endif - -$(top_builddir)/config.h: $(top_srcdir)/config.h.in - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) config.h - -cairoincludedir = $(includedir)/cairo -cairoinclude_HEADERS = $(enabled_cairo_headers) - -lib_LTLIBRARIES = libcairo.la - -if BUILD_CXX -cairo_cxx_lib = libcairo_cxx.la -else -cairo_cxx_lib = -endif - -noinst_LTLIBRARIES = $(cairo_cxx_lib) -libcairo_cxx_la_SOURCES = \ - $(enabled_cairo_headers) \ - $(enabled_cairo_private) \ - $(enabled_cairo_cxx_sources) \ - $(NULL) -libcairo_cxx_la_LDFLAGS = $(AM_LDFLAGS) $(export_symbols) -libcairo_cxx_la_LIBADD = $(CAIRO_LIBS) -libcairo_cxx_la_DEPENDENCIES = $(cairo_def_dependency) - - -libcairo_la_SOURCES = \ - $(enabled_cairo_headers) \ - $(enabled_cairo_private) \ - $(enabled_cairo_sources) \ - $(NULL) -libcairo_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(CAIRO_LIBTOOL_VERSION_INFO) -no-undefined $(export_symbols) -libcairo_la_LIBADD = $(CAIRO_LIBS) \ - $(cairo_cxx_lib) -libcairo_la_DEPENDENCIES = $(cairo_def_dependency) $(cairo_cxx_lib) - -# Special headers -cairoinclude_HEADERS += $(top_srcdir)/cairo-version.h -libcairo_la_SOURCES += cairo-version.h -nodist_cairoinclude_HEADERS = cairo-features.h -nodist_libcairo_la_SOURCES = cairo-features.h -BUILT_SOURCES += cairo-features.h cairo-supported-features.h -DISTCLEANFILES += cairo-features.h cairo-supported-features.h -cairo-features.h cairo-supported-features.h: - cd $(top_builddir) && ./config.status src/$@ - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = $(enabled_cairo_pkgconf) - -CLEANFILES += cairo.def -cairo.def: cairo-features.h $(enabled_cairo_headers) - @echo Generating $@ - @(echo EXPORTS; \ - (cd $(srcdir); cat $(enabled_cairo_headers) || echo 'cairo_ERROR ()' ) | \ - $(EGREP) -v '^# *include' | \ - ( cat cairo-features.h - | $(CPP) -D__cplusplus - || echo 'cairo_ERROR ()' ) | \ - $(EGREP) '^cairo_.* \(' | \ - sed -e 's/[ ].*//' | \ - sort; \ - echo LIBRARY libcairo-$(CAIRO_VERSION_SONUM).dll; \ - ) >$@ - @ ! grep -q cairo_ERROR $@ || ($(RM) $@; false) - -TESTS_ENVIRONMENT = \ - srcdir="$(srcdir)" \ - MAKE="$(MAKE) $(AM_MAKEFLAGS)" \ - all_cairo_files="$(all_cairo_files)" \ - all_cairo_headers="$(all_cairo_headers)" \ - all_cairo_private="$(all_cairo_private)" \ - all_cairo_sources="$(all_cairo_sources)" \ - enabled_cairo_headers="$(enabled_cairo_headers)" \ - enabled_cairo_private="$(enabled_cairo_private)" \ - enabled_cairo_sources="$(enabled_cairo_sources)" \ - $(NULL) -TESTS_SH = \ - check-def.sh \ - check-doc-syntax.sh \ - check-headers.sh \ - check-plt.sh \ - check-preprocessor-syntax.sh \ - $(NULL) -TESTS += $(TESTS_SH) -if CROSS_COMPILING -else -TESTS += check-link$(EXEEXT) -endif - -EXTRA_DIST += $(TESTS_SH) check-has-hidden-symbols.c check-doc-syntax.awk -check_PROGRAMS += check-link -check_link_LDADD = libcairo.la - -check: headers-standalone - -PREPROCESS_ARGS = $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) -COMPILE_ARGS = $(PREPROCESS_ARGS) $(AM_CFLAGS) $(CFLAGS) - -# The pre-processed result is used by check-{def,plt}.sh to determine whether -# cairo has been compiled with symbol hiding. -.c.i: $(cairoinclude_HEADERS) $(nodist_cairoinclude_HEADERS) cairoint.h $(top_builddir)/config.h - $(CPP) $(PREPROCESS_ARGS) $< -o $@ -.c.s: $(cairoinclude_HEADERS) $(nodist_cairoinclude_HEADERS) cairoint.h $(top_builddir)/config.h - $(CC) $(COMPILE_ARGS) $< -S -o $@ - -include $(srcdir)/Makefile.am.analysis diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.analysis b/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.analysis deleted file mode 100644 index fab4cf7a514..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.analysis +++ /dev/null @@ -1,35 +0,0 @@ - -SPARSE = sparse -sparse: - @echo Checking enabled sources with sparse checker - @status=true; for f in $(enabled_cairo_sources) $(enabled_cairo_cxx_sources); do \ - echo $(SPARSE) $(PREPROCESS_ARGS) $(srcdir)/$$f; \ - $(SPARSE) $(PREPROCESS_ARGS) $(srcdir)/$$f || status=false; \ - done; $$status - -SPLINT = splint -badflag -splint: - @echo Checking enabled sources with splint checker - @status=true; for f in $(enabled_cairo_sources) $(enabled_cairo_cxx_sources); do \ - echo $(SPLINT) $(PREPROCESS_ARGS) $(srcdir)/$$f; \ - $(SPLINT) $(PREPROCESS_ARGS) $(srcdir)/$$f || status=false; \ - done; $$status - -UNO = uno -uno: - @echo Checking enabled sources with uno checker - cd $(srcdir); $(UNO) $(PREPROCESS_ARGS) -DHAVE_CONFIG_H -U__GNUC__ $(enabled_cairo_sources) - -headers-standalone: $(enabled_cairo_headers) $(enabled_cairo_private) - @echo Checking that enabled public/private headers can be compiled standalone - @status=true; for f in $(enabled_cairo_headers) $(enabled_cairo_private); do \ - echo " CHECK $$f"; \ - echo "#include \"$(srcdir)/$$f\"" > headers-standalone-tmp.c; \ - echo "int main(int argc, char * argv[]) { return 0; }" >> headers-standalone-tmp.c; \ - $(COMPILE) -o headers-standalone-tmp headers-standalone-tmp.c || status=false; \ - $(RM) headers-standalone-tmp headers-standalone-tmp.c; \ - done; $$status - @touch $@ -CLEANFILES += headers-standalone - -analysis: all headers-standalone sparse splint uno diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.features b/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.features deleted file mode 100644 index c58ac23da4e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.am.features +++ /dev/null @@ -1,657 +0,0 @@ -# Generated by configure. Do not edit. - -include $(top_srcdir)/src/Makefile.sources - -supported_cairo_headers = $(cairo_headers) -unsupported_cairo_headers = -all_cairo_headers = $(cairo_headers) -all_cairo_private = $(cairo_private) -all_cairo_cxx_sources = $(cairo_cxx_sources) -all_cairo_sources = $(cairo_sources) - -enabled_cairo_headers = $(cairo_headers) -enabled_cairo_private = $(cairo_private) -enabled_cairo_cxx_sources = $(cairo_cxx_sources) -enabled_cairo_sources = $(cairo_sources) - -all_cairo_pkgconf = cairo.pc -enabled_cairo_pkgconf = cairo.pc - -supported_cairo_headers += $(cairo_xlib_headers) -all_cairo_headers += $(cairo_xlib_headers) -all_cairo_private += $(cairo_xlib_private) -all_cairo_cxx_sources += $(cairo_xlib_cxx_sources) -all_cairo_sources += $(cairo_xlib_sources) -if CAIRO_HAS_XLIB_SURFACE -enabled_cairo_headers += $(cairo_xlib_headers) -enabled_cairo_private += $(cairo_xlib_private) -enabled_cairo_cxx_sources += $(cairo_xlib_cxx_sources) -enabled_cairo_sources += $(cairo_xlib_sources) -endif -all_cairo_pkgconf += cairo-xlib.pc -if CAIRO_HAS_XLIB_SURFACE -enabled_cairo_pkgconf += cairo-xlib.pc -endif - -supported_cairo_headers += $(cairo_xlib_xrender_headers) -all_cairo_headers += $(cairo_xlib_xrender_headers) -all_cairo_private += $(cairo_xlib_xrender_private) -all_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) -all_cairo_sources += $(cairo_xlib_xrender_sources) -if CAIRO_HAS_XLIB_XRENDER_SURFACE -enabled_cairo_headers += $(cairo_xlib_xrender_headers) -enabled_cairo_private += $(cairo_xlib_xrender_private) -enabled_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) -enabled_cairo_sources += $(cairo_xlib_xrender_sources) -endif -all_cairo_pkgconf += cairo-xlib-xrender.pc -if CAIRO_HAS_XLIB_XRENDER_SURFACE -enabled_cairo_pkgconf += cairo-xlib-xrender.pc -endif - -supported_cairo_headers += $(cairo_xcb_headers) -all_cairo_headers += $(cairo_xcb_headers) -all_cairo_private += $(cairo_xcb_private) -all_cairo_cxx_sources += $(cairo_xcb_cxx_sources) -all_cairo_sources += $(cairo_xcb_sources) -if CAIRO_HAS_XCB_SURFACE -enabled_cairo_headers += $(cairo_xcb_headers) -enabled_cairo_private += $(cairo_xcb_private) -enabled_cairo_cxx_sources += $(cairo_xcb_cxx_sources) -enabled_cairo_sources += $(cairo_xcb_sources) -endif -all_cairo_pkgconf += cairo-xcb.pc -if CAIRO_HAS_XCB_SURFACE -enabled_cairo_pkgconf += cairo-xcb.pc -endif - -unsupported_cairo_headers += $(cairo_xlib_xcb_headers) -all_cairo_headers += $(cairo_xlib_xcb_headers) -all_cairo_private += $(cairo_xlib_xcb_private) -all_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) -all_cairo_sources += $(cairo_xlib_xcb_sources) -if CAIRO_HAS_XLIB_XCB_FUNCTIONS -enabled_cairo_headers += $(cairo_xlib_xcb_headers) -enabled_cairo_private += $(cairo_xlib_xcb_private) -enabled_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) -enabled_cairo_sources += $(cairo_xlib_xcb_sources) -endif -all_cairo_pkgconf += cairo-xlib-xcb.pc -if CAIRO_HAS_XLIB_XCB_FUNCTIONS -enabled_cairo_pkgconf += cairo-xlib-xcb.pc -endif - -supported_cairo_headers += $(cairo_xcb_shm_headers) -all_cairo_headers += $(cairo_xcb_shm_headers) -all_cairo_private += $(cairo_xcb_shm_private) -all_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) -all_cairo_sources += $(cairo_xcb_shm_sources) -if CAIRO_HAS_XCB_SHM_FUNCTIONS -enabled_cairo_headers += $(cairo_xcb_shm_headers) -enabled_cairo_private += $(cairo_xcb_shm_private) -enabled_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) -enabled_cairo_sources += $(cairo_xcb_shm_sources) -endif -all_cairo_pkgconf += cairo-xcb-shm.pc -if CAIRO_HAS_XCB_SHM_FUNCTIONS -enabled_cairo_pkgconf += cairo-xcb-shm.pc -endif - -unsupported_cairo_headers += $(cairo_qt_headers) -all_cairo_headers += $(cairo_qt_headers) -all_cairo_private += $(cairo_qt_private) -all_cairo_cxx_sources += $(cairo_qt_cxx_sources) -all_cairo_sources += $(cairo_qt_sources) -if CAIRO_HAS_QT_SURFACE -enabled_cairo_headers += $(cairo_qt_headers) -enabled_cairo_private += $(cairo_qt_private) -enabled_cairo_cxx_sources += $(cairo_qt_cxx_sources) -enabled_cairo_sources += $(cairo_qt_sources) -endif -all_cairo_pkgconf += cairo-qt.pc -if CAIRO_HAS_QT_SURFACE -enabled_cairo_pkgconf += cairo-qt.pc -endif - -supported_cairo_headers += $(cairo_quartz_headers) -all_cairo_headers += $(cairo_quartz_headers) -all_cairo_private += $(cairo_quartz_private) -all_cairo_cxx_sources += $(cairo_quartz_cxx_sources) -all_cairo_sources += $(cairo_quartz_sources) -if CAIRO_HAS_QUARTZ_SURFACE -enabled_cairo_headers += $(cairo_quartz_headers) -enabled_cairo_private += $(cairo_quartz_private) -enabled_cairo_cxx_sources += $(cairo_quartz_cxx_sources) -enabled_cairo_sources += $(cairo_quartz_sources) -endif -all_cairo_pkgconf += cairo-quartz.pc -if CAIRO_HAS_QUARTZ_SURFACE -enabled_cairo_pkgconf += cairo-quartz.pc -endif - -supported_cairo_headers += $(cairo_quartz_font_headers) -all_cairo_headers += $(cairo_quartz_font_headers) -all_cairo_private += $(cairo_quartz_font_private) -all_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) -all_cairo_sources += $(cairo_quartz_font_sources) -if CAIRO_HAS_QUARTZ_FONT -enabled_cairo_headers += $(cairo_quartz_font_headers) -enabled_cairo_private += $(cairo_quartz_font_private) -enabled_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) -enabled_cairo_sources += $(cairo_quartz_font_sources) -endif -all_cairo_pkgconf += cairo-quartz-font.pc -if CAIRO_HAS_QUARTZ_FONT -enabled_cairo_pkgconf += cairo-quartz-font.pc -endif - -unsupported_cairo_headers += $(cairo_quartz_image_headers) -all_cairo_headers += $(cairo_quartz_image_headers) -all_cairo_private += $(cairo_quartz_image_private) -all_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) -all_cairo_sources += $(cairo_quartz_image_sources) -if CAIRO_HAS_QUARTZ_IMAGE_SURFACE -enabled_cairo_headers += $(cairo_quartz_image_headers) -enabled_cairo_private += $(cairo_quartz_image_private) -enabled_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) -enabled_cairo_sources += $(cairo_quartz_image_sources) -endif -all_cairo_pkgconf += cairo-quartz-image.pc -if CAIRO_HAS_QUARTZ_IMAGE_SURFACE -enabled_cairo_pkgconf += cairo-quartz-image.pc -endif - -supported_cairo_headers += $(cairo_win32_headers) -all_cairo_headers += $(cairo_win32_headers) -all_cairo_private += $(cairo_win32_private) -all_cairo_cxx_sources += $(cairo_win32_cxx_sources) -all_cairo_sources += $(cairo_win32_sources) -if CAIRO_HAS_WIN32_SURFACE -enabled_cairo_headers += $(cairo_win32_headers) -enabled_cairo_private += $(cairo_win32_private) -enabled_cairo_cxx_sources += $(cairo_win32_cxx_sources) -enabled_cairo_sources += $(cairo_win32_sources) -endif -all_cairo_pkgconf += cairo-win32.pc -if CAIRO_HAS_WIN32_SURFACE -enabled_cairo_pkgconf += cairo-win32.pc -endif - -supported_cairo_headers += $(cairo_win32_font_headers) -all_cairo_headers += $(cairo_win32_font_headers) -all_cairo_private += $(cairo_win32_font_private) -all_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) -all_cairo_sources += $(cairo_win32_font_sources) -if CAIRO_HAS_WIN32_FONT -enabled_cairo_headers += $(cairo_win32_font_headers) -enabled_cairo_private += $(cairo_win32_font_private) -enabled_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) -enabled_cairo_sources += $(cairo_win32_font_sources) -endif -all_cairo_pkgconf += cairo-win32-font.pc -if CAIRO_HAS_WIN32_FONT -enabled_cairo_pkgconf += cairo-win32-font.pc -endif - -unsupported_cairo_headers += $(cairo_skia_headers) -all_cairo_headers += $(cairo_skia_headers) -all_cairo_private += $(cairo_skia_private) -all_cairo_cxx_sources += $(cairo_skia_cxx_sources) -all_cairo_sources += $(cairo_skia_sources) -if CAIRO_HAS_SKIA_SURFACE -enabled_cairo_headers += $(cairo_skia_headers) -enabled_cairo_private += $(cairo_skia_private) -enabled_cairo_cxx_sources += $(cairo_skia_cxx_sources) -enabled_cairo_sources += $(cairo_skia_sources) -endif -all_cairo_pkgconf += cairo-skia.pc -if CAIRO_HAS_SKIA_SURFACE -enabled_cairo_pkgconf += cairo-skia.pc -endif - -unsupported_cairo_headers += $(cairo_os2_headers) -all_cairo_headers += $(cairo_os2_headers) -all_cairo_private += $(cairo_os2_private) -all_cairo_cxx_sources += $(cairo_os2_cxx_sources) -all_cairo_sources += $(cairo_os2_sources) -if CAIRO_HAS_OS2_SURFACE -enabled_cairo_headers += $(cairo_os2_headers) -enabled_cairo_private += $(cairo_os2_private) -enabled_cairo_cxx_sources += $(cairo_os2_cxx_sources) -enabled_cairo_sources += $(cairo_os2_sources) -endif -all_cairo_pkgconf += cairo-os2.pc -if CAIRO_HAS_OS2_SURFACE -enabled_cairo_pkgconf += cairo-os2.pc -endif - -unsupported_cairo_headers += $(cairo_beos_headers) -all_cairo_headers += $(cairo_beos_headers) -all_cairo_private += $(cairo_beos_private) -all_cairo_cxx_sources += $(cairo_beos_cxx_sources) -all_cairo_sources += $(cairo_beos_sources) -if CAIRO_HAS_BEOS_SURFACE -enabled_cairo_headers += $(cairo_beos_headers) -enabled_cairo_private += $(cairo_beos_private) -enabled_cairo_cxx_sources += $(cairo_beos_cxx_sources) -enabled_cairo_sources += $(cairo_beos_sources) -endif -all_cairo_pkgconf += cairo-beos.pc -if CAIRO_HAS_BEOS_SURFACE -enabled_cairo_pkgconf += cairo-beos.pc -endif - -unsupported_cairo_headers += $(cairo_drm_headers) -all_cairo_headers += $(cairo_drm_headers) -all_cairo_private += $(cairo_drm_private) -all_cairo_cxx_sources += $(cairo_drm_cxx_sources) -all_cairo_sources += $(cairo_drm_sources) -if CAIRO_HAS_DRM_SURFACE -enabled_cairo_headers += $(cairo_drm_headers) -enabled_cairo_private += $(cairo_drm_private) -enabled_cairo_cxx_sources += $(cairo_drm_cxx_sources) -enabled_cairo_sources += $(cairo_drm_sources) -endif -all_cairo_pkgconf += cairo-drm.pc -if CAIRO_HAS_DRM_SURFACE -enabled_cairo_pkgconf += cairo-drm.pc -endif - -unsupported_cairo_headers += $(cairo_gallium_headers) -all_cairo_headers += $(cairo_gallium_headers) -all_cairo_private += $(cairo_gallium_private) -all_cairo_cxx_sources += $(cairo_gallium_cxx_sources) -all_cairo_sources += $(cairo_gallium_sources) -if CAIRO_HAS_GALLIUM_SURFACE -enabled_cairo_headers += $(cairo_gallium_headers) -enabled_cairo_private += $(cairo_gallium_private) -enabled_cairo_cxx_sources += $(cairo_gallium_cxx_sources) -enabled_cairo_sources += $(cairo_gallium_sources) -endif -all_cairo_pkgconf += cairo-gallium.pc -if CAIRO_HAS_GALLIUM_SURFACE -enabled_cairo_pkgconf += cairo-gallium.pc -endif - -supported_cairo_headers += $(cairo_png_headers) -all_cairo_headers += $(cairo_png_headers) -all_cairo_private += $(cairo_png_private) -all_cairo_cxx_sources += $(cairo_png_cxx_sources) -all_cairo_sources += $(cairo_png_sources) -if CAIRO_HAS_PNG_FUNCTIONS -enabled_cairo_headers += $(cairo_png_headers) -enabled_cairo_private += $(cairo_png_private) -enabled_cairo_cxx_sources += $(cairo_png_cxx_sources) -enabled_cairo_sources += $(cairo_png_sources) -endif -all_cairo_pkgconf += cairo-png.pc -if CAIRO_HAS_PNG_FUNCTIONS -enabled_cairo_pkgconf += cairo-png.pc -endif - -unsupported_cairo_headers += $(cairo_gl_headers) -all_cairo_headers += $(cairo_gl_headers) -all_cairo_private += $(cairo_gl_private) -all_cairo_cxx_sources += $(cairo_gl_cxx_sources) -all_cairo_sources += $(cairo_gl_sources) -if CAIRO_HAS_GL_SURFACE -enabled_cairo_headers += $(cairo_gl_headers) -enabled_cairo_private += $(cairo_gl_private) -enabled_cairo_cxx_sources += $(cairo_gl_cxx_sources) -enabled_cairo_sources += $(cairo_gl_sources) -endif -all_cairo_pkgconf += cairo-gl.pc -if CAIRO_HAS_GL_SURFACE -enabled_cairo_pkgconf += cairo-gl.pc -endif - -unsupported_cairo_headers += $(cairo_glesv2_headers) -all_cairo_headers += $(cairo_glesv2_headers) -all_cairo_private += $(cairo_glesv2_private) -all_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) -all_cairo_sources += $(cairo_glesv2_sources) -if CAIRO_HAS_GLESV2_SURFACE -enabled_cairo_headers += $(cairo_glesv2_headers) -enabled_cairo_private += $(cairo_glesv2_private) -enabled_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) -enabled_cairo_sources += $(cairo_glesv2_sources) -endif -all_cairo_pkgconf += cairo-glesv2.pc -if CAIRO_HAS_GLESV2_SURFACE -enabled_cairo_pkgconf += cairo-glesv2.pc -endif - -unsupported_cairo_headers += $(cairo_cogl_headers) -all_cairo_headers += $(cairo_cogl_headers) -all_cairo_private += $(cairo_cogl_private) -all_cairo_cxx_sources += $(cairo_cogl_cxx_sources) -all_cairo_sources += $(cairo_cogl_sources) -if CAIRO_HAS_COGL_SURFACE -enabled_cairo_headers += $(cairo_cogl_headers) -enabled_cairo_private += $(cairo_cogl_private) -enabled_cairo_cxx_sources += $(cairo_cogl_cxx_sources) -enabled_cairo_sources += $(cairo_cogl_sources) -endif -all_cairo_pkgconf += cairo-cogl.pc -if CAIRO_HAS_COGL_SURFACE -enabled_cairo_pkgconf += cairo-cogl.pc -endif - -unsupported_cairo_headers += $(cairo_directfb_headers) -all_cairo_headers += $(cairo_directfb_headers) -all_cairo_private += $(cairo_directfb_private) -all_cairo_cxx_sources += $(cairo_directfb_cxx_sources) -all_cairo_sources += $(cairo_directfb_sources) -if CAIRO_HAS_DIRECTFB_SURFACE -enabled_cairo_headers += $(cairo_directfb_headers) -enabled_cairo_private += $(cairo_directfb_private) -enabled_cairo_cxx_sources += $(cairo_directfb_cxx_sources) -enabled_cairo_sources += $(cairo_directfb_sources) -endif -all_cairo_pkgconf += cairo-directfb.pc -if CAIRO_HAS_DIRECTFB_SURFACE -enabled_cairo_pkgconf += cairo-directfb.pc -endif - -unsupported_cairo_headers += $(cairo_vg_headers) -all_cairo_headers += $(cairo_vg_headers) -all_cairo_private += $(cairo_vg_private) -all_cairo_cxx_sources += $(cairo_vg_cxx_sources) -all_cairo_sources += $(cairo_vg_sources) -if CAIRO_HAS_VG_SURFACE -enabled_cairo_headers += $(cairo_vg_headers) -enabled_cairo_private += $(cairo_vg_private) -enabled_cairo_cxx_sources += $(cairo_vg_cxx_sources) -enabled_cairo_sources += $(cairo_vg_sources) -endif -all_cairo_pkgconf += cairo-vg.pc -if CAIRO_HAS_VG_SURFACE -enabled_cairo_pkgconf += cairo-vg.pc -endif - -supported_cairo_headers += $(cairo_egl_headers) -all_cairo_headers += $(cairo_egl_headers) -all_cairo_private += $(cairo_egl_private) -all_cairo_cxx_sources += $(cairo_egl_cxx_sources) -all_cairo_sources += $(cairo_egl_sources) -if CAIRO_HAS_EGL_FUNCTIONS -enabled_cairo_headers += $(cairo_egl_headers) -enabled_cairo_private += $(cairo_egl_private) -enabled_cairo_cxx_sources += $(cairo_egl_cxx_sources) -enabled_cairo_sources += $(cairo_egl_sources) -endif -all_cairo_pkgconf += cairo-egl.pc -if CAIRO_HAS_EGL_FUNCTIONS -enabled_cairo_pkgconf += cairo-egl.pc -endif - -supported_cairo_headers += $(cairo_glx_headers) -all_cairo_headers += $(cairo_glx_headers) -all_cairo_private += $(cairo_glx_private) -all_cairo_cxx_sources += $(cairo_glx_cxx_sources) -all_cairo_sources += $(cairo_glx_sources) -if CAIRO_HAS_GLX_FUNCTIONS -enabled_cairo_headers += $(cairo_glx_headers) -enabled_cairo_private += $(cairo_glx_private) -enabled_cairo_cxx_sources += $(cairo_glx_cxx_sources) -enabled_cairo_sources += $(cairo_glx_sources) -endif -all_cairo_pkgconf += cairo-glx.pc -if CAIRO_HAS_GLX_FUNCTIONS -enabled_cairo_pkgconf += cairo-glx.pc -endif - -supported_cairo_headers += $(cairo_wgl_headers) -all_cairo_headers += $(cairo_wgl_headers) -all_cairo_private += $(cairo_wgl_private) -all_cairo_cxx_sources += $(cairo_wgl_cxx_sources) -all_cairo_sources += $(cairo_wgl_sources) -if CAIRO_HAS_WGL_FUNCTIONS -enabled_cairo_headers += $(cairo_wgl_headers) -enabled_cairo_private += $(cairo_wgl_private) -enabled_cairo_cxx_sources += $(cairo_wgl_cxx_sources) -enabled_cairo_sources += $(cairo_wgl_sources) -endif -all_cairo_pkgconf += cairo-wgl.pc -if CAIRO_HAS_WGL_FUNCTIONS -enabled_cairo_pkgconf += cairo-wgl.pc -endif - -supported_cairo_headers += $(cairo_script_headers) -all_cairo_headers += $(cairo_script_headers) -all_cairo_private += $(cairo_script_private) -all_cairo_cxx_sources += $(cairo_script_cxx_sources) -all_cairo_sources += $(cairo_script_sources) -if CAIRO_HAS_SCRIPT_SURFACE -enabled_cairo_headers += $(cairo_script_headers) -enabled_cairo_private += $(cairo_script_private) -enabled_cairo_cxx_sources += $(cairo_script_cxx_sources) -enabled_cairo_sources += $(cairo_script_sources) -endif -all_cairo_pkgconf += cairo-script.pc -if CAIRO_HAS_SCRIPT_SURFACE -enabled_cairo_pkgconf += cairo-script.pc -endif - -supported_cairo_headers += $(cairo_ft_headers) -all_cairo_headers += $(cairo_ft_headers) -all_cairo_private += $(cairo_ft_private) -all_cairo_cxx_sources += $(cairo_ft_cxx_sources) -all_cairo_sources += $(cairo_ft_sources) -if CAIRO_HAS_FT_FONT -enabled_cairo_headers += $(cairo_ft_headers) -enabled_cairo_private += $(cairo_ft_private) -enabled_cairo_cxx_sources += $(cairo_ft_cxx_sources) -enabled_cairo_sources += $(cairo_ft_sources) -endif -all_cairo_pkgconf += cairo-ft.pc -if CAIRO_HAS_FT_FONT -enabled_cairo_pkgconf += cairo-ft.pc -endif - -supported_cairo_headers += $(cairo_fc_headers) -all_cairo_headers += $(cairo_fc_headers) -all_cairo_private += $(cairo_fc_private) -all_cairo_cxx_sources += $(cairo_fc_cxx_sources) -all_cairo_sources += $(cairo_fc_sources) -if CAIRO_HAS_FC_FONT -enabled_cairo_headers += $(cairo_fc_headers) -enabled_cairo_private += $(cairo_fc_private) -enabled_cairo_cxx_sources += $(cairo_fc_cxx_sources) -enabled_cairo_sources += $(cairo_fc_sources) -endif -all_cairo_pkgconf += cairo-fc.pc -if CAIRO_HAS_FC_FONT -enabled_cairo_pkgconf += cairo-fc.pc -endif - -supported_cairo_headers += $(cairo_ps_headers) -all_cairo_headers += $(cairo_ps_headers) -all_cairo_private += $(cairo_ps_private) -all_cairo_cxx_sources += $(cairo_ps_cxx_sources) -all_cairo_sources += $(cairo_ps_sources) -if CAIRO_HAS_PS_SURFACE -enabled_cairo_headers += $(cairo_ps_headers) -enabled_cairo_private += $(cairo_ps_private) -enabled_cairo_cxx_sources += $(cairo_ps_cxx_sources) -enabled_cairo_sources += $(cairo_ps_sources) -endif -all_cairo_pkgconf += cairo-ps.pc -if CAIRO_HAS_PS_SURFACE -enabled_cairo_pkgconf += cairo-ps.pc -endif - -supported_cairo_headers += $(cairo_pdf_headers) -all_cairo_headers += $(cairo_pdf_headers) -all_cairo_private += $(cairo_pdf_private) -all_cairo_cxx_sources += $(cairo_pdf_cxx_sources) -all_cairo_sources += $(cairo_pdf_sources) -if CAIRO_HAS_PDF_SURFACE -enabled_cairo_headers += $(cairo_pdf_headers) -enabled_cairo_private += $(cairo_pdf_private) -enabled_cairo_cxx_sources += $(cairo_pdf_cxx_sources) -enabled_cairo_sources += $(cairo_pdf_sources) -endif -all_cairo_pkgconf += cairo-pdf.pc -if CAIRO_HAS_PDF_SURFACE -enabled_cairo_pkgconf += cairo-pdf.pc -endif - -supported_cairo_headers += $(cairo_svg_headers) -all_cairo_headers += $(cairo_svg_headers) -all_cairo_private += $(cairo_svg_private) -all_cairo_cxx_sources += $(cairo_svg_cxx_sources) -all_cairo_sources += $(cairo_svg_sources) -if CAIRO_HAS_SVG_SURFACE -enabled_cairo_headers += $(cairo_svg_headers) -enabled_cairo_private += $(cairo_svg_private) -enabled_cairo_cxx_sources += $(cairo_svg_cxx_sources) -enabled_cairo_sources += $(cairo_svg_sources) -endif -all_cairo_pkgconf += cairo-svg.pc -if CAIRO_HAS_SVG_SURFACE -enabled_cairo_pkgconf += cairo-svg.pc -endif - -all_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) -all_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) -all_cairo_sources += $(cairo_test_surfaces_sources) -if CAIRO_HAS_TEST_SURFACES -enabled_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) -enabled_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) -enabled_cairo_sources += $(cairo_test_surfaces_sources) -endif - -supported_cairo_headers += $(cairo_image_headers) -all_cairo_headers += $(cairo_image_headers) -all_cairo_private += $(cairo_image_private) -all_cairo_cxx_sources += $(cairo_image_cxx_sources) -all_cairo_sources += $(cairo_image_sources) -enabled_cairo_headers += $(cairo_image_headers) -enabled_cairo_private += $(cairo_image_private) -enabled_cairo_cxx_sources += $(cairo_image_cxx_sources) -enabled_cairo_sources += $(cairo_image_sources) - -supported_cairo_headers += $(cairo_mime_headers) -all_cairo_headers += $(cairo_mime_headers) -all_cairo_private += $(cairo_mime_private) -all_cairo_cxx_sources += $(cairo_mime_cxx_sources) -all_cairo_sources += $(cairo_mime_sources) -enabled_cairo_headers += $(cairo_mime_headers) -enabled_cairo_private += $(cairo_mime_private) -enabled_cairo_cxx_sources += $(cairo_mime_cxx_sources) -enabled_cairo_sources += $(cairo_mime_sources) - -supported_cairo_headers += $(cairo_recording_headers) -all_cairo_headers += $(cairo_recording_headers) -all_cairo_private += $(cairo_recording_private) -all_cairo_cxx_sources += $(cairo_recording_cxx_sources) -all_cairo_sources += $(cairo_recording_sources) -enabled_cairo_headers += $(cairo_recording_headers) -enabled_cairo_private += $(cairo_recording_private) -enabled_cairo_cxx_sources += $(cairo_recording_cxx_sources) -enabled_cairo_sources += $(cairo_recording_sources) - -supported_cairo_headers += $(cairo_observer_headers) -all_cairo_headers += $(cairo_observer_headers) -all_cairo_private += $(cairo_observer_private) -all_cairo_cxx_sources += $(cairo_observer_cxx_sources) -all_cairo_sources += $(cairo_observer_sources) -enabled_cairo_headers += $(cairo_observer_headers) -enabled_cairo_private += $(cairo_observer_private) -enabled_cairo_cxx_sources += $(cairo_observer_cxx_sources) -enabled_cairo_sources += $(cairo_observer_sources) - -unsupported_cairo_headers += $(cairo_tee_headers) -all_cairo_headers += $(cairo_tee_headers) -all_cairo_private += $(cairo_tee_private) -all_cairo_cxx_sources += $(cairo_tee_cxx_sources) -all_cairo_sources += $(cairo_tee_sources) -if CAIRO_HAS_TEE_SURFACE -enabled_cairo_headers += $(cairo_tee_headers) -enabled_cairo_private += $(cairo_tee_private) -enabled_cairo_cxx_sources += $(cairo_tee_cxx_sources) -enabled_cairo_sources += $(cairo_tee_sources) -endif -all_cairo_pkgconf += cairo-tee.pc -if CAIRO_HAS_TEE_SURFACE -enabled_cairo_pkgconf += cairo-tee.pc -endif - -unsupported_cairo_headers += $(cairo_xml_headers) -all_cairo_headers += $(cairo_xml_headers) -all_cairo_private += $(cairo_xml_private) -all_cairo_cxx_sources += $(cairo_xml_cxx_sources) -all_cairo_sources += $(cairo_xml_sources) -if CAIRO_HAS_XML_SURFACE -enabled_cairo_headers += $(cairo_xml_headers) -enabled_cairo_private += $(cairo_xml_private) -enabled_cairo_cxx_sources += $(cairo_xml_cxx_sources) -enabled_cairo_sources += $(cairo_xml_sources) -endif -all_cairo_pkgconf += cairo-xml.pc -if CAIRO_HAS_XML_SURFACE -enabled_cairo_pkgconf += cairo-xml.pc -endif - -supported_cairo_headers += $(cairo_user_headers) -all_cairo_headers += $(cairo_user_headers) -all_cairo_private += $(cairo_user_private) -all_cairo_cxx_sources += $(cairo_user_cxx_sources) -all_cairo_sources += $(cairo_user_sources) -enabled_cairo_headers += $(cairo_user_headers) -enabled_cairo_private += $(cairo_user_private) -enabled_cairo_cxx_sources += $(cairo_user_cxx_sources) -enabled_cairo_sources += $(cairo_user_sources) - -all_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) -all_cairo_cxx_sources += $(cairo_pthread_cxx_sources) -all_cairo_sources += $(cairo_pthread_sources) -if CAIRO_HAS_PTHREAD -enabled_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) -enabled_cairo_cxx_sources += $(cairo_pthread_cxx_sources) -enabled_cairo_sources += $(cairo_pthread_sources) -endif - -supported_cairo_headers += $(cairo_gobject_headers) -all_cairo_headers += $(cairo_gobject_headers) -all_cairo_private += $(cairo_gobject_private) -all_cairo_cxx_sources += $(cairo_gobject_cxx_sources) -all_cairo_sources += $(cairo_gobject_sources) -if CAIRO_HAS_GOBJECT_FUNCTIONS -enabled_cairo_headers += $(cairo_gobject_headers) -enabled_cairo_private += $(cairo_gobject_private) -enabled_cairo_cxx_sources += $(cairo_gobject_cxx_sources) -enabled_cairo_sources += $(cairo_gobject_sources) -endif -all_cairo_pkgconf += cairo-gobject.pc -if CAIRO_HAS_GOBJECT_FUNCTIONS -enabled_cairo_pkgconf += cairo-gobject.pc -endif - -all_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) -all_cairo_cxx_sources += $(cairo_trace_cxx_sources) -all_cairo_sources += $(cairo_trace_sources) -if CAIRO_HAS_TRACE -enabled_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) -enabled_cairo_cxx_sources += $(cairo_trace_cxx_sources) -enabled_cairo_sources += $(cairo_trace_sources) -endif - -all_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) -all_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) -all_cairo_sources += $(cairo_interpreter_sources) -if CAIRO_HAS_INTERPRETER -enabled_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) -enabled_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) -enabled_cairo_sources += $(cairo_interpreter_sources) -endif - -all_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) -all_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) -all_cairo_sources += $(cairo_symbol_lookup_sources) -if CAIRO_HAS_SYMBOL_LOOKUP -enabled_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) -enabled_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) -enabled_cairo_sources += $(cairo_symbol_lookup_sources) -endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.sources b/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.sources deleted file mode 100644 index fac24d79d8a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.sources +++ /dev/null @@ -1,472 +0,0 @@ -# Makefile.sources -# -# This file is the canonical location listing all the source files used -# to build the cairo library. Every source file is categorized as one of: -# -# * public header file -# * private header file (must end in -private.h except for cairoint.h) -# * source code file -# -# Every source file should be specified exactly once, grouped with the -# feature that uses the source file. If more than one feature use the -# file (like pdf_operators or font_subset files), the files should be -# appended to to the base cairo files, and the code inside them -# enabled/disabled using C preprocessor macros defined in cairoint.h. -# See how pdf_operators or font_subset are handled. -# -# The sources are picked up according to the configured features -# by the generated file Makefile.am.features or Makefile.win32.features. -# -# These are a few special source files. Those are not included in this -# file to not confuse build systems. Each build system must handle them -# separately. These files include: -# -# * cairo-features.h: -# This file is generated by configure and includes macros signifying -# which features are enabled. This file should be installed like -# other public headers, but should NOT be distributed in the cairo -# distribution. -# -# * cairo-version.h: -# This is a dummy header file used during the build, but it should -# NOT be installed. Its sole purpose is to make sure changes in the -# cairo version do not trigger a full rebuild of the library, but -# just the functions actually using the version information. -# -# * $(top_srcdir)/cairo-version.h: -# This is the real file holding the cairo version number. This file -# should be installed like other public headers. This is used during -# the build by cairo-version.c only. -# -# * cairo-supported-features.h: -# This file is generated by configure and includes macros signifying -# all supported features. This is used by gtk-doc to generate -# documentation for all those macros, enabled or not. -# This file is NOT used during the build of the library and should -# NOT be installed or distributed. -# -# Please follow the strict syntax of this file, including keeping file -# lists sorted. -# - -cairo_headers = cairo.h cairo-deprecated.h -cairo_private = \ - cairoint.h \ - cairo-analysis-surface-private.h \ - cairo-arc-private.h \ - cairo-array-private.h \ - cairo-atomic-private.h \ - cairo-backend-private.h \ - cairo-box-inline.h \ - cairo-boxes-private.h \ - cairo-cache-private.h \ - cairo-clip-inline.h \ - cairo-clip-private.h \ - cairo-combsort-inline.h \ - cairo-compiler-private.h \ - cairo-compositor-private.h \ - cairo-contour-inline.h \ - cairo-contour-private.h \ - cairo-composite-rectangles-private.h \ - cairo-damage-private.h \ - cairo-default-context-private.h \ - cairo-device-private.h \ - cairo-error-inline.h \ - cairo-error-private.h \ - cairo-fixed-private.h \ - cairo-fixed-type-private.h \ - cairo-freelist-private.h \ - cairo-freelist-type-private.h \ - cairo-freed-pool-private.h \ - cairo-fontconfig-private.h \ - cairo-gstate-private.h \ - cairo-hash-private.h \ - cairo-image-info-private.h \ - cairo-image-surface-inline.h \ - cairo-image-surface-private.h \ - cairo-line-inline.h \ - cairo-line-private.h \ - cairo-list-inline.h \ - cairo-list-private.h \ - cairo-malloc-private.h \ - cairo-mempool-private.h \ - cairo-mutex-impl-private.h \ - cairo-mutex-list-private.h \ - cairo-mutex-private.h \ - cairo-mutex-type-private.h \ - cairo-output-stream-private.h \ - cairo-paginated-private.h \ - cairo-paginated-surface-private.h \ - cairo-path-fixed-private.h \ - cairo-path-private.h \ - cairo-pattern-inline.h \ - cairo-pattern-private.h \ - cairo-pixman-private.h \ - cairo-private.h \ - cairo-recording-surface-inline.h \ - cairo-recording-surface-private.h \ - cairo-reference-count-private.h \ - cairo-region-private.h \ - cairo-rtree-private.h \ - cairo-scaled-font-private.h \ - cairo-slope-private.h \ - cairo-spans-private.h \ - cairo-spans-compositor-private.h \ - cairo-stroke-dash-private.h \ - cairo-surface-inline.h \ - cairo-surface-private.h \ - cairo-surface-backend-private.h \ - cairo-surface-clipper-private.h \ - cairo-surface-fallback-private.h \ - cairo-surface-observer-inline.h \ - cairo-surface-observer-private.h \ - cairo-surface-offset-private.h \ - cairo-surface-subsurface-inline.h \ - cairo-surface-subsurface-private.h \ - cairo-surface-snapshot-inline.h \ - cairo-surface-snapshot-private.h \ - cairo-surface-wrapper-private.h \ - cairo-time-private.h \ - cairo-types-private.h \ - cairo-traps-private.h \ - cairo-tristrip-private.h \ - cairo-user-font-private.h \ - cairo-wideint-private.h \ - cairo-wideint-type-private.h \ - $(NULL) -cairo_sources = \ - cairo-analysis-surface.c \ - cairo-arc.c \ - cairo-array.c \ - cairo-atomic.c \ - cairo-base64-stream.c \ - cairo-base85-stream.c \ - cairo-bentley-ottmann.c \ - cairo-bentley-ottmann-rectangular.c \ - cairo-bentley-ottmann-rectilinear.c \ - cairo-botor-scan-converter.c \ - cairo-boxes.c \ - cairo-boxes-intersect.c \ - cairo.c \ - cairo-cache.c \ - cairo-clip.c \ - cairo-clip-boxes.c \ - cairo-clip-polygon.c \ - cairo-clip-region.c \ - cairo-clip-surface.c \ - cairo-color.c \ - cairo-composite-rectangles.c \ - cairo-compositor.c \ - cairo-contour.c \ - cairo-damage.c \ - cairo-debug.c \ - cairo-default-context.c \ - cairo-device.c \ - cairo-error.c \ - cairo-fallback-compositor.c \ - cairo-fixed.c \ - cairo-font-face.c \ - cairo-font-face-twin.c \ - cairo-font-face-twin-data.c \ - cairo-font-options.c \ - cairo-freelist.c \ - cairo-freed-pool.c \ - cairo-gstate.c \ - cairo-hash.c \ - cairo-hull.c \ - cairo-image-compositor.c \ - cairo-image-info.c \ - cairo-image-source.c \ - cairo-image-surface.c \ - cairo-line.c \ - cairo-lzw.c \ - cairo-matrix.c \ - cairo-mask-compositor.c \ - cairo-mesh-pattern-rasterizer.c \ - cairo-mempool.c \ - cairo-misc.c \ - cairo-mono-scan-converter.c \ - cairo-mutex.c \ - cairo-no-compositor.c \ - cairo-observer.c \ - cairo-output-stream.c \ - cairo-paginated-surface.c \ - cairo-path-bounds.c \ - cairo-path.c \ - cairo-path-fill.c \ - cairo-path-fixed.c \ - cairo-path-in-fill.c \ - cairo-path-stroke.c \ - cairo-path-stroke-boxes.c \ - cairo-path-stroke-polygon.c \ - cairo-path-stroke-traps.c \ - cairo-path-stroke-tristrip.c \ - cairo-pattern.c \ - cairo-pen.c \ - cairo-polygon.c \ - cairo-polygon-intersect.c \ - cairo-polygon-reduce.c \ - cairo-raster-source-pattern.c \ - cairo-recording-surface.c \ - cairo-rectangle.c \ - cairo-rectangular-scan-converter.c \ - cairo-region.c \ - cairo-rtree.c \ - cairo-scaled-font.c \ - cairo-shape-mask-compositor.c \ - cairo-slope.c \ - cairo-spans.c \ - cairo-spans-compositor.c \ - cairo-spline.c \ - cairo-stroke-dash.c \ - cairo-stroke-style.c \ - cairo-surface.c \ - cairo-surface-clipper.c \ - cairo-surface-fallback.c \ - cairo-surface-observer.c \ - cairo-surface-offset.c \ - cairo-surface-snapshot.c \ - cairo-surface-subsurface.c \ - cairo-surface-wrapper.c \ - cairo-time.c \ - cairo-tor-scan-converter.c \ - cairo-tor22-scan-converter.c \ - cairo-clip-tor-scan-converter.c \ - cairo-toy-font-face.c \ - cairo-traps.c \ - cairo-tristrip.c \ - cairo-traps-compositor.c \ - cairo-unicode.c \ - cairo-user-font.c \ - cairo-version.c \ - cairo-wideint.c \ - $(NULL) - -_cairo_font_subset_private = \ - cairo-scaled-font-subsets-private.h \ - cairo-truetype-subset-private.h \ - cairo-type1-private.h \ - cairo-type3-glyph-surface-private.h \ - $(NULL) -_cairo_font_subset_sources = \ - cairo-cff-subset.c \ - cairo-scaled-font-subsets.c \ - cairo-truetype-subset.c \ - cairo-type1-fallback.c \ - cairo-type1-glyph-names.c \ - cairo-type1-subset.c \ - cairo-type3-glyph-surface.c \ - $(NULL) -cairo_private += $(_cairo_font_subset_private) -cairo_sources += $(_cairo_font_subset_sources) - -cairo_egl_sources = -cairo_glx_sources = -cairo_wgl_sources = - -_cairo_pdf_operators_private = cairo-pdf-operators-private.h cairo-pdf-shading-private.h -_cairo_pdf_operators_sources = cairo-pdf-operators.c cairo-pdf-shading.c -cairo_private += $(_cairo_pdf_operators_private) -cairo_sources += $(_cairo_pdf_operators_sources) - -cairo_png_sources = cairo-png.c - -cairo_ps_headers = cairo-ps.h -cairo_ps_private = cairo-ps-surface-private.h -cairo_ps_sources = cairo-ps-surface.c - -_cairo_deflate_stream_sources = cairo-deflate-stream.c -cairo_sources += $(_cairo_deflate_stream_sources) - -cairo_pdf_headers = cairo-pdf.h -cairo_pdf_private = cairo-pdf-surface-private.h -cairo_pdf_sources = cairo-pdf-surface.c - -cairo_svg_headers = cairo-svg.h -cairo_svg_private = cairo-svg-surface-private.h -cairo_svg_sources = cairo-svg-surface.c - -cairo_ft_headers = cairo-ft.h -cairo_ft_private = cairo-ft-private.h -cairo_ft_sources = cairo-ft-font.c - -# These are private, even though they look like public headers -cairo_test_surfaces_private = \ - test-compositor-surface.h \ - test-compositor-surface-private.h \ - test-null-compositor-surface.h \ - test-paginated-surface.h \ - $(NULL) -cairo_test_surfaces_sources = \ - test-compositor-surface.c \ - test-null-compositor-surface.c \ - test-base-compositor-surface.c \ - test-paginated-surface.c \ - $(NULL) - -cairo_xlib_headers = cairo-xlib.h -cairo_xlib_private = \ - cairo-xlib-private.h \ - cairo-xlib-surface-private.h \ - cairo-xlib-xrender-private.h \ - $(NULL) -cairo_xlib_sources = \ - cairo-xlib-display.c \ - cairo-xlib-core-compositor.c \ - cairo-xlib-fallback-compositor.c \ - cairo-xlib-render-compositor.c \ - cairo-xlib-screen.c \ - cairo-xlib-source.c \ - cairo-xlib-surface.c \ - cairo-xlib-surface-shm.c \ - cairo-xlib-visual.c \ - cairo-xlib-xcb-surface.c \ - $(NULL) - -cairo_xlib_xrender_headers = cairo-xlib-xrender.h - -cairo_xcb_headers = cairo-xcb.h -cairo_xcb_private = cairo-xcb-private.h -cairo_xcb_sources = \ - cairo-xcb-connection.c \ - cairo-xcb-connection-core.c \ - cairo-xcb-connection-render.c \ - cairo-xcb-connection-shm.c \ - cairo-xcb-screen.c \ - cairo-xcb-shm.c \ - cairo-xcb-surface.c \ - cairo-xcb-surface-core.c \ - cairo-xcb-surface-render.c \ - cairo-xcb-resources.c \ - $(NULL) - -cairo_qt_headers = cairo-qt.h -cairo_qt_cxx_sources = cairo-qt-surface.cpp - -cairo_quartz_headers = cairo-quartz.h -cairo_quartz_private = cairo-quartz-private.h -cairo_quartz_sources = cairo-quartz-surface.c - -cairo_quartz_image_headers = cairo-quartz-image.h -cairo_quartz_image_sources = cairo-quartz-image-surface.c - -cairo_quartz_font_sources = cairo-quartz-font.c - -cairo_win32_headers = cairo-win32.h -cairo_win32_private = win32/cairo-win32-private.h -cairo_win32_sources = \ - win32/cairo-win32-debug.c \ - win32/cairo-win32-device.c \ - win32/cairo-win32-gdi-compositor.c \ - win32/cairo-win32-system.c \ - win32/cairo-win32-surface.c \ - win32/cairo-win32-display-surface.c \ - win32/cairo-win32-printing-surface.c \ - $(NULL) -cairo_win32_font_sources = \ - win32/cairo-win32-font.c \ - $(NULL) - -cairo_skia_headers = cairo-skia.h -cairo_skia_private = skia/cairo-skia-private.h -cairo_skia_cxx_sources = \ - skia/cairo-skia-context.cpp \ - skia/cairo-skia-surface.cpp \ - $(NULL) - -cairo_os2_headers = cairo-os2.h -cairo_os2_private = cairo-os2-private.h -cairo_os2_sources = cairo-os2-surface.c - -# automake is stupid enough to always use c++ linker if we enable the -# following lines, even if beos surface is not enabled. Disable it for now. -cairo_beos_headers = cairo-beos.h -cairo_beos_cxx_sources = cairo-beos-surface.cpp - -cairo_gl_headers = cairo-gl.h -cairo_gl_private = cairo-gl-private.h \ - cairo-gl-dispatch-private.h \ - cairo-gl-ext-def-private.h \ - cairo-gl-gradient-private.h - -cairo_gl_sources = cairo-gl-composite.c \ - cairo-gl-device.c \ - cairo-gl-dispatch.c \ - cairo-gl-glyphs.c \ - cairo-gl-gradient.c \ - cairo-gl-info.c \ - cairo-gl-operand.c \ - cairo-gl-shaders.c \ - cairo-gl-msaa-compositor.c \ - cairo-gl-spans-compositor.c \ - cairo-gl-traps-compositor.c \ - cairo-gl-source.c \ - cairo-gl-surface.c - -cairo_glesv2_headers = $(cairo_gl_headers) -cairo_glesv2_private = $(cairo_gl_private) -cairo_glesv2_sources = $(cairo_gl_sources) - -cairo_egl_sources += cairo-egl-context.c -cairo_glx_sources += cairo-glx-context.c -cairo_wgl_sources += cairo-wgl-context.c - -cairo_directfb_headers = cairo-directfb.h -cairo_directfb_sources = cairo-directfb-surface.c - -cairo_drm_headers = cairo-drm.h -cairo_drm_private = drm/cairo-drm-private.h \ - drm/cairo-drm-ioctl-private.h \ - drm/cairo-drm-intel-private.h \ - drm/cairo-drm-intel-brw-defines.h \ - drm/cairo-drm-intel-brw-structs.h \ - drm/cairo-drm-intel-brw-eu.h \ - drm/cairo-drm-intel-command-private.h \ - drm/cairo-drm-intel-ioctl-private.h \ - drm/cairo-drm-i915-private.h \ - drm/cairo-drm-i965-private.h \ - drm/cairo-drm-radeon-private.h -cairo_drm_sources = drm/cairo-drm.c \ - drm/cairo-drm-bo.c \ - drm/cairo-drm-surface.c \ - drm/cairo-drm-intel.c \ - drm/cairo-drm-intel-debug.c \ - drm/cairo-drm-intel-surface.c \ - drm/cairo-drm-i915-surface.c \ - drm/cairo-drm-i915-glyphs.c \ - drm/cairo-drm-i915-shader.c \ - drm/cairo-drm-i915-spans.c \ - drm/cairo-drm-i965-surface.c \ - drm/cairo-drm-i965-glyphs.c \ - drm/cairo-drm-i965-shader.c \ - drm/cairo-drm-i965-spans.c \ - drm/cairo-drm-intel-brw-eu.c \ - drm/cairo-drm-intel-brw-eu-emit.c \ - drm/cairo-drm-intel-brw-eu-util.c \ - drm/cairo-drm-radeon.c \ - drm/cairo-drm-radeon-surface.c -cairo_gallium_sources = drm/cairo-drm-gallium-surface.c - -cairo_script_headers = cairo-script.h -cairo_script_private = cairo-script-private.h -cairo_script_sources = cairo-script-surface.c - -cairo_tee_headers = cairo-tee.h -cairo_tee_private = cairo-tee-surface-private.h -cairo_tee_sources = cairo-tee-surface.c - -cairo_xml_headers = cairo-xml.h -cairo_xml_sources = cairo-xml-surface.c - -cairo_vg_headers = cairo-vg.h -cairo_vg_sources = cairo-vg-surface.c - -cairo_cogl_headers = cairo-cogl.h -cairo_cogl_private = cairo-cogl-private.h \ - cairo-cogl-gradient-private.h \ - cairo-cogl-context-private.h \ - cairo-cogl-utils-private.h -cairo_cogl_sources = cairo-cogl-surface.c \ - cairo-cogl-gradient.c \ - cairo-cogl-context.c \ - cairo-cogl-utils.c diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32 b/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32 deleted file mode 100644 index 864791f377b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32 +++ /dev/null @@ -1,29 +0,0 @@ -top_srcdir = .. -include $(top_srcdir)/build/Makefile.win32.common -include Makefile.win32.features - -SOURCES = $(enabled_cairo_sources) - -STATIC_SOURCES = cairo-system.c - -OBJECTS = $(patsubst %.c, $(CFG)/%.obj, $(SOURCES)) -OBJECTS_STATIC = $(patsubst %cairo-system.obj, %cairo-system-static.obj, $(OBJECTS)) - -static: inform $(CFG)/cairo-static.lib -dynamic: inform $(CFG)/cairo.dll - -$(CFG)/cairo.dll: $(OBJECTS) - @$(LD) $(CAIRO_LDFLAGS) -DLL -OUT:$@ $(CAIRO_LIBS) $(PIXMAN_LIBS) $(OBJECTS) - -$(CFG)/cairo-static.lib: $(OBJECTS_STATIC) - @$(AR) $(CAIRO_ARFLAGS) -OUT:$@ $(PIXMAN_LIBS) $(OBJECTS_STATIC) - -all: inform $(CFG)/cairo.dll $(CFG)/cairo-static.lib - @echo "Built successfully!" - @echo "You should copy the following files to a proper place now:" - @echo "" - @echo " cairo-version.h (NOTE: toplevel, not the src/cairo-version.h one!)" - @echo " src/cairo-features.h" - @for x in $(enabled_cairo_headers); do echo " src/$$x"; done - @echo " src/$(CFG)/cairo.dll" - @echo " src/$(CFG)/cairo-static.lib" diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32.features b/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32.features deleted file mode 100644 index 2274f4ad6cf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/Makefile.win32.features +++ /dev/null @@ -1,661 +0,0 @@ -# Generated by configure. Do not edit. - -ifeq ($(top_srcdir),) -include Makefile.sources -else -include $(top_srcdir)/src/Makefile.sources -endif - -supported_cairo_headers = $(cairo_headers) -unsupported_cairo_headers = -all_cairo_headers = $(cairo_headers) -all_cairo_private = $(cairo_private) -all_cairo_cxx_sources = $(cairo_cxx_sources) -all_cairo_sources = $(cairo_sources) - -enabled_cairo_headers = $(cairo_headers) -enabled_cairo_private = $(cairo_private) -enabled_cairo_cxx_sources = $(cairo_cxx_sources) -enabled_cairo_sources = $(cairo_sources) - -all_cairo_pkgconf = cairo.pc -enabled_cairo_pkgconf = cairo.pc - -supported_cairo_headers += $(cairo_xlib_headers) -all_cairo_headers += $(cairo_xlib_headers) -all_cairo_private += $(cairo_xlib_private) -all_cairo_cxx_sources += $(cairo_xlib_cxx_sources) -all_cairo_sources += $(cairo_xlib_sources) -ifeq ($(CAIRO_HAS_XLIB_SURFACE),1) -enabled_cairo_headers += $(cairo_xlib_headers) -enabled_cairo_private += $(cairo_xlib_private) -enabled_cairo_cxx_sources += $(cairo_xlib_cxx_sources) -enabled_cairo_sources += $(cairo_xlib_sources) -endif -all_cairo_pkgconf += cairo-xlib.pc -ifeq ($(CAIRO_HAS_XLIB_SURFACE),1) -enabled_cairo_pkgconf += cairo-xlib.pc -endif - -supported_cairo_headers += $(cairo_xlib_xrender_headers) -all_cairo_headers += $(cairo_xlib_xrender_headers) -all_cairo_private += $(cairo_xlib_xrender_private) -all_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) -all_cairo_sources += $(cairo_xlib_xrender_sources) -ifeq ($(CAIRO_HAS_XLIB_XRENDER_SURFACE),1) -enabled_cairo_headers += $(cairo_xlib_xrender_headers) -enabled_cairo_private += $(cairo_xlib_xrender_private) -enabled_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) -enabled_cairo_sources += $(cairo_xlib_xrender_sources) -endif -all_cairo_pkgconf += cairo-xlib-xrender.pc -ifeq ($(CAIRO_HAS_XLIB_XRENDER_SURFACE),1) -enabled_cairo_pkgconf += cairo-xlib-xrender.pc -endif - -supported_cairo_headers += $(cairo_xcb_headers) -all_cairo_headers += $(cairo_xcb_headers) -all_cairo_private += $(cairo_xcb_private) -all_cairo_cxx_sources += $(cairo_xcb_cxx_sources) -all_cairo_sources += $(cairo_xcb_sources) -ifeq ($(CAIRO_HAS_XCB_SURFACE),1) -enabled_cairo_headers += $(cairo_xcb_headers) -enabled_cairo_private += $(cairo_xcb_private) -enabled_cairo_cxx_sources += $(cairo_xcb_cxx_sources) -enabled_cairo_sources += $(cairo_xcb_sources) -endif -all_cairo_pkgconf += cairo-xcb.pc -ifeq ($(CAIRO_HAS_XCB_SURFACE),1) -enabled_cairo_pkgconf += cairo-xcb.pc -endif - -unsupported_cairo_headers += $(cairo_xlib_xcb_headers) -all_cairo_headers += $(cairo_xlib_xcb_headers) -all_cairo_private += $(cairo_xlib_xcb_private) -all_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) -all_cairo_sources += $(cairo_xlib_xcb_sources) -ifeq ($(CAIRO_HAS_XLIB_XCB_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_xlib_xcb_headers) -enabled_cairo_private += $(cairo_xlib_xcb_private) -enabled_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) -enabled_cairo_sources += $(cairo_xlib_xcb_sources) -endif -all_cairo_pkgconf += cairo-xlib-xcb.pc -ifeq ($(CAIRO_HAS_XLIB_XCB_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-xlib-xcb.pc -endif - -supported_cairo_headers += $(cairo_xcb_shm_headers) -all_cairo_headers += $(cairo_xcb_shm_headers) -all_cairo_private += $(cairo_xcb_shm_private) -all_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) -all_cairo_sources += $(cairo_xcb_shm_sources) -ifeq ($(CAIRO_HAS_XCB_SHM_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_xcb_shm_headers) -enabled_cairo_private += $(cairo_xcb_shm_private) -enabled_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) -enabled_cairo_sources += $(cairo_xcb_shm_sources) -endif -all_cairo_pkgconf += cairo-xcb-shm.pc -ifeq ($(CAIRO_HAS_XCB_SHM_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-xcb-shm.pc -endif - -unsupported_cairo_headers += $(cairo_qt_headers) -all_cairo_headers += $(cairo_qt_headers) -all_cairo_private += $(cairo_qt_private) -all_cairo_cxx_sources += $(cairo_qt_cxx_sources) -all_cairo_sources += $(cairo_qt_sources) -ifeq ($(CAIRO_HAS_QT_SURFACE),1) -enabled_cairo_headers += $(cairo_qt_headers) -enabled_cairo_private += $(cairo_qt_private) -enabled_cairo_cxx_sources += $(cairo_qt_cxx_sources) -enabled_cairo_sources += $(cairo_qt_sources) -endif -all_cairo_pkgconf += cairo-qt.pc -ifeq ($(CAIRO_HAS_QT_SURFACE),1) -enabled_cairo_pkgconf += cairo-qt.pc -endif - -supported_cairo_headers += $(cairo_quartz_headers) -all_cairo_headers += $(cairo_quartz_headers) -all_cairo_private += $(cairo_quartz_private) -all_cairo_cxx_sources += $(cairo_quartz_cxx_sources) -all_cairo_sources += $(cairo_quartz_sources) -ifeq ($(CAIRO_HAS_QUARTZ_SURFACE),1) -enabled_cairo_headers += $(cairo_quartz_headers) -enabled_cairo_private += $(cairo_quartz_private) -enabled_cairo_cxx_sources += $(cairo_quartz_cxx_sources) -enabled_cairo_sources += $(cairo_quartz_sources) -endif -all_cairo_pkgconf += cairo-quartz.pc -ifeq ($(CAIRO_HAS_QUARTZ_SURFACE),1) -enabled_cairo_pkgconf += cairo-quartz.pc -endif - -supported_cairo_headers += $(cairo_quartz_font_headers) -all_cairo_headers += $(cairo_quartz_font_headers) -all_cairo_private += $(cairo_quartz_font_private) -all_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) -all_cairo_sources += $(cairo_quartz_font_sources) -ifeq ($(CAIRO_HAS_QUARTZ_FONT),1) -enabled_cairo_headers += $(cairo_quartz_font_headers) -enabled_cairo_private += $(cairo_quartz_font_private) -enabled_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) -enabled_cairo_sources += $(cairo_quartz_font_sources) -endif -all_cairo_pkgconf += cairo-quartz-font.pc -ifeq ($(CAIRO_HAS_QUARTZ_FONT),1) -enabled_cairo_pkgconf += cairo-quartz-font.pc -endif - -unsupported_cairo_headers += $(cairo_quartz_image_headers) -all_cairo_headers += $(cairo_quartz_image_headers) -all_cairo_private += $(cairo_quartz_image_private) -all_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) -all_cairo_sources += $(cairo_quartz_image_sources) -ifeq ($(CAIRO_HAS_QUARTZ_IMAGE_SURFACE),1) -enabled_cairo_headers += $(cairo_quartz_image_headers) -enabled_cairo_private += $(cairo_quartz_image_private) -enabled_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) -enabled_cairo_sources += $(cairo_quartz_image_sources) -endif -all_cairo_pkgconf += cairo-quartz-image.pc -ifeq ($(CAIRO_HAS_QUARTZ_IMAGE_SURFACE),1) -enabled_cairo_pkgconf += cairo-quartz-image.pc -endif - -supported_cairo_headers += $(cairo_win32_headers) -all_cairo_headers += $(cairo_win32_headers) -all_cairo_private += $(cairo_win32_private) -all_cairo_cxx_sources += $(cairo_win32_cxx_sources) -all_cairo_sources += $(cairo_win32_sources) -ifeq ($(CAIRO_HAS_WIN32_SURFACE),1) -enabled_cairo_headers += $(cairo_win32_headers) -enabled_cairo_private += $(cairo_win32_private) -enabled_cairo_cxx_sources += $(cairo_win32_cxx_sources) -enabled_cairo_sources += $(cairo_win32_sources) -endif -all_cairo_pkgconf += cairo-win32.pc -ifeq ($(CAIRO_HAS_WIN32_SURFACE),1) -enabled_cairo_pkgconf += cairo-win32.pc -endif - -supported_cairo_headers += $(cairo_win32_font_headers) -all_cairo_headers += $(cairo_win32_font_headers) -all_cairo_private += $(cairo_win32_font_private) -all_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) -all_cairo_sources += $(cairo_win32_font_sources) -ifeq ($(CAIRO_HAS_WIN32_FONT),1) -enabled_cairo_headers += $(cairo_win32_font_headers) -enabled_cairo_private += $(cairo_win32_font_private) -enabled_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) -enabled_cairo_sources += $(cairo_win32_font_sources) -endif -all_cairo_pkgconf += cairo-win32-font.pc -ifeq ($(CAIRO_HAS_WIN32_FONT),1) -enabled_cairo_pkgconf += cairo-win32-font.pc -endif - -unsupported_cairo_headers += $(cairo_skia_headers) -all_cairo_headers += $(cairo_skia_headers) -all_cairo_private += $(cairo_skia_private) -all_cairo_cxx_sources += $(cairo_skia_cxx_sources) -all_cairo_sources += $(cairo_skia_sources) -ifeq ($(CAIRO_HAS_SKIA_SURFACE),1) -enabled_cairo_headers += $(cairo_skia_headers) -enabled_cairo_private += $(cairo_skia_private) -enabled_cairo_cxx_sources += $(cairo_skia_cxx_sources) -enabled_cairo_sources += $(cairo_skia_sources) -endif -all_cairo_pkgconf += cairo-skia.pc -ifeq ($(CAIRO_HAS_SKIA_SURFACE),1) -enabled_cairo_pkgconf += cairo-skia.pc -endif - -unsupported_cairo_headers += $(cairo_os2_headers) -all_cairo_headers += $(cairo_os2_headers) -all_cairo_private += $(cairo_os2_private) -all_cairo_cxx_sources += $(cairo_os2_cxx_sources) -all_cairo_sources += $(cairo_os2_sources) -ifeq ($(CAIRO_HAS_OS2_SURFACE),1) -enabled_cairo_headers += $(cairo_os2_headers) -enabled_cairo_private += $(cairo_os2_private) -enabled_cairo_cxx_sources += $(cairo_os2_cxx_sources) -enabled_cairo_sources += $(cairo_os2_sources) -endif -all_cairo_pkgconf += cairo-os2.pc -ifeq ($(CAIRO_HAS_OS2_SURFACE),1) -enabled_cairo_pkgconf += cairo-os2.pc -endif - -unsupported_cairo_headers += $(cairo_beos_headers) -all_cairo_headers += $(cairo_beos_headers) -all_cairo_private += $(cairo_beos_private) -all_cairo_cxx_sources += $(cairo_beos_cxx_sources) -all_cairo_sources += $(cairo_beos_sources) -ifeq ($(CAIRO_HAS_BEOS_SURFACE),1) -enabled_cairo_headers += $(cairo_beos_headers) -enabled_cairo_private += $(cairo_beos_private) -enabled_cairo_cxx_sources += $(cairo_beos_cxx_sources) -enabled_cairo_sources += $(cairo_beos_sources) -endif -all_cairo_pkgconf += cairo-beos.pc -ifeq ($(CAIRO_HAS_BEOS_SURFACE),1) -enabled_cairo_pkgconf += cairo-beos.pc -endif - -unsupported_cairo_headers += $(cairo_drm_headers) -all_cairo_headers += $(cairo_drm_headers) -all_cairo_private += $(cairo_drm_private) -all_cairo_cxx_sources += $(cairo_drm_cxx_sources) -all_cairo_sources += $(cairo_drm_sources) -ifeq ($(CAIRO_HAS_DRM_SURFACE),1) -enabled_cairo_headers += $(cairo_drm_headers) -enabled_cairo_private += $(cairo_drm_private) -enabled_cairo_cxx_sources += $(cairo_drm_cxx_sources) -enabled_cairo_sources += $(cairo_drm_sources) -endif -all_cairo_pkgconf += cairo-drm.pc -ifeq ($(CAIRO_HAS_DRM_SURFACE),1) -enabled_cairo_pkgconf += cairo-drm.pc -endif - -unsupported_cairo_headers += $(cairo_gallium_headers) -all_cairo_headers += $(cairo_gallium_headers) -all_cairo_private += $(cairo_gallium_private) -all_cairo_cxx_sources += $(cairo_gallium_cxx_sources) -all_cairo_sources += $(cairo_gallium_sources) -ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1) -enabled_cairo_headers += $(cairo_gallium_headers) -enabled_cairo_private += $(cairo_gallium_private) -enabled_cairo_cxx_sources += $(cairo_gallium_cxx_sources) -enabled_cairo_sources += $(cairo_gallium_sources) -endif -all_cairo_pkgconf += cairo-gallium.pc -ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1) -enabled_cairo_pkgconf += cairo-gallium.pc -endif - -supported_cairo_headers += $(cairo_png_headers) -all_cairo_headers += $(cairo_png_headers) -all_cairo_private += $(cairo_png_private) -all_cairo_cxx_sources += $(cairo_png_cxx_sources) -all_cairo_sources += $(cairo_png_sources) -ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_png_headers) -enabled_cairo_private += $(cairo_png_private) -enabled_cairo_cxx_sources += $(cairo_png_cxx_sources) -enabled_cairo_sources += $(cairo_png_sources) -endif -all_cairo_pkgconf += cairo-png.pc -ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-png.pc -endif - -unsupported_cairo_headers += $(cairo_gl_headers) -all_cairo_headers += $(cairo_gl_headers) -all_cairo_private += $(cairo_gl_private) -all_cairo_cxx_sources += $(cairo_gl_cxx_sources) -all_cairo_sources += $(cairo_gl_sources) -ifeq ($(CAIRO_HAS_GL_SURFACE),1) -enabled_cairo_headers += $(cairo_gl_headers) -enabled_cairo_private += $(cairo_gl_private) -enabled_cairo_cxx_sources += $(cairo_gl_cxx_sources) -enabled_cairo_sources += $(cairo_gl_sources) -endif -all_cairo_pkgconf += cairo-gl.pc -ifeq ($(CAIRO_HAS_GL_SURFACE),1) -enabled_cairo_pkgconf += cairo-gl.pc -endif - -unsupported_cairo_headers += $(cairo_glesv2_headers) -all_cairo_headers += $(cairo_glesv2_headers) -all_cairo_private += $(cairo_glesv2_private) -all_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) -all_cairo_sources += $(cairo_glesv2_sources) -ifeq ($(CAIRO_HAS_GLESV2_SURFACE),1) -enabled_cairo_headers += $(cairo_glesv2_headers) -enabled_cairo_private += $(cairo_glesv2_private) -enabled_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) -enabled_cairo_sources += $(cairo_glesv2_sources) -endif -all_cairo_pkgconf += cairo-glesv2.pc -ifeq ($(CAIRO_HAS_GLESV2_SURFACE),1) -enabled_cairo_pkgconf += cairo-glesv2.pc -endif - -unsupported_cairo_headers += $(cairo_cogl_headers) -all_cairo_headers += $(cairo_cogl_headers) -all_cairo_private += $(cairo_cogl_private) -all_cairo_cxx_sources += $(cairo_cogl_cxx_sources) -all_cairo_sources += $(cairo_cogl_sources) -ifeq ($(CAIRO_HAS_COGL_SURFACE),1) -enabled_cairo_headers += $(cairo_cogl_headers) -enabled_cairo_private += $(cairo_cogl_private) -enabled_cairo_cxx_sources += $(cairo_cogl_cxx_sources) -enabled_cairo_sources += $(cairo_cogl_sources) -endif -all_cairo_pkgconf += cairo-cogl.pc -ifeq ($(CAIRO_HAS_COGL_SURFACE),1) -enabled_cairo_pkgconf += cairo-cogl.pc -endif - -unsupported_cairo_headers += $(cairo_directfb_headers) -all_cairo_headers += $(cairo_directfb_headers) -all_cairo_private += $(cairo_directfb_private) -all_cairo_cxx_sources += $(cairo_directfb_cxx_sources) -all_cairo_sources += $(cairo_directfb_sources) -ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1) -enabled_cairo_headers += $(cairo_directfb_headers) -enabled_cairo_private += $(cairo_directfb_private) -enabled_cairo_cxx_sources += $(cairo_directfb_cxx_sources) -enabled_cairo_sources += $(cairo_directfb_sources) -endif -all_cairo_pkgconf += cairo-directfb.pc -ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1) -enabled_cairo_pkgconf += cairo-directfb.pc -endif - -unsupported_cairo_headers += $(cairo_vg_headers) -all_cairo_headers += $(cairo_vg_headers) -all_cairo_private += $(cairo_vg_private) -all_cairo_cxx_sources += $(cairo_vg_cxx_sources) -all_cairo_sources += $(cairo_vg_sources) -ifeq ($(CAIRO_HAS_VG_SURFACE),1) -enabled_cairo_headers += $(cairo_vg_headers) -enabled_cairo_private += $(cairo_vg_private) -enabled_cairo_cxx_sources += $(cairo_vg_cxx_sources) -enabled_cairo_sources += $(cairo_vg_sources) -endif -all_cairo_pkgconf += cairo-vg.pc -ifeq ($(CAIRO_HAS_VG_SURFACE),1) -enabled_cairo_pkgconf += cairo-vg.pc -endif - -supported_cairo_headers += $(cairo_egl_headers) -all_cairo_headers += $(cairo_egl_headers) -all_cairo_private += $(cairo_egl_private) -all_cairo_cxx_sources += $(cairo_egl_cxx_sources) -all_cairo_sources += $(cairo_egl_sources) -ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_egl_headers) -enabled_cairo_private += $(cairo_egl_private) -enabled_cairo_cxx_sources += $(cairo_egl_cxx_sources) -enabled_cairo_sources += $(cairo_egl_sources) -endif -all_cairo_pkgconf += cairo-egl.pc -ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-egl.pc -endif - -supported_cairo_headers += $(cairo_glx_headers) -all_cairo_headers += $(cairo_glx_headers) -all_cairo_private += $(cairo_glx_private) -all_cairo_cxx_sources += $(cairo_glx_cxx_sources) -all_cairo_sources += $(cairo_glx_sources) -ifeq ($(CAIRO_HAS_GLX_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_glx_headers) -enabled_cairo_private += $(cairo_glx_private) -enabled_cairo_cxx_sources += $(cairo_glx_cxx_sources) -enabled_cairo_sources += $(cairo_glx_sources) -endif -all_cairo_pkgconf += cairo-glx.pc -ifeq ($(CAIRO_HAS_GLX_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-glx.pc -endif - -supported_cairo_headers += $(cairo_wgl_headers) -all_cairo_headers += $(cairo_wgl_headers) -all_cairo_private += $(cairo_wgl_private) -all_cairo_cxx_sources += $(cairo_wgl_cxx_sources) -all_cairo_sources += $(cairo_wgl_sources) -ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_wgl_headers) -enabled_cairo_private += $(cairo_wgl_private) -enabled_cairo_cxx_sources += $(cairo_wgl_cxx_sources) -enabled_cairo_sources += $(cairo_wgl_sources) -endif -all_cairo_pkgconf += cairo-wgl.pc -ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-wgl.pc -endif - -supported_cairo_headers += $(cairo_script_headers) -all_cairo_headers += $(cairo_script_headers) -all_cairo_private += $(cairo_script_private) -all_cairo_cxx_sources += $(cairo_script_cxx_sources) -all_cairo_sources += $(cairo_script_sources) -ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1) -enabled_cairo_headers += $(cairo_script_headers) -enabled_cairo_private += $(cairo_script_private) -enabled_cairo_cxx_sources += $(cairo_script_cxx_sources) -enabled_cairo_sources += $(cairo_script_sources) -endif -all_cairo_pkgconf += cairo-script.pc -ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1) -enabled_cairo_pkgconf += cairo-script.pc -endif - -supported_cairo_headers += $(cairo_ft_headers) -all_cairo_headers += $(cairo_ft_headers) -all_cairo_private += $(cairo_ft_private) -all_cairo_cxx_sources += $(cairo_ft_cxx_sources) -all_cairo_sources += $(cairo_ft_sources) -ifeq ($(CAIRO_HAS_FT_FONT),1) -enabled_cairo_headers += $(cairo_ft_headers) -enabled_cairo_private += $(cairo_ft_private) -enabled_cairo_cxx_sources += $(cairo_ft_cxx_sources) -enabled_cairo_sources += $(cairo_ft_sources) -endif -all_cairo_pkgconf += cairo-ft.pc -ifeq ($(CAIRO_HAS_FT_FONT),1) -enabled_cairo_pkgconf += cairo-ft.pc -endif - -supported_cairo_headers += $(cairo_fc_headers) -all_cairo_headers += $(cairo_fc_headers) -all_cairo_private += $(cairo_fc_private) -all_cairo_cxx_sources += $(cairo_fc_cxx_sources) -all_cairo_sources += $(cairo_fc_sources) -ifeq ($(CAIRO_HAS_FC_FONT),1) -enabled_cairo_headers += $(cairo_fc_headers) -enabled_cairo_private += $(cairo_fc_private) -enabled_cairo_cxx_sources += $(cairo_fc_cxx_sources) -enabled_cairo_sources += $(cairo_fc_sources) -endif -all_cairo_pkgconf += cairo-fc.pc -ifeq ($(CAIRO_HAS_FC_FONT),1) -enabled_cairo_pkgconf += cairo-fc.pc -endif - -supported_cairo_headers += $(cairo_ps_headers) -all_cairo_headers += $(cairo_ps_headers) -all_cairo_private += $(cairo_ps_private) -all_cairo_cxx_sources += $(cairo_ps_cxx_sources) -all_cairo_sources += $(cairo_ps_sources) -ifeq ($(CAIRO_HAS_PS_SURFACE),1) -enabled_cairo_headers += $(cairo_ps_headers) -enabled_cairo_private += $(cairo_ps_private) -enabled_cairo_cxx_sources += $(cairo_ps_cxx_sources) -enabled_cairo_sources += $(cairo_ps_sources) -endif -all_cairo_pkgconf += cairo-ps.pc -ifeq ($(CAIRO_HAS_PS_SURFACE),1) -enabled_cairo_pkgconf += cairo-ps.pc -endif - -supported_cairo_headers += $(cairo_pdf_headers) -all_cairo_headers += $(cairo_pdf_headers) -all_cairo_private += $(cairo_pdf_private) -all_cairo_cxx_sources += $(cairo_pdf_cxx_sources) -all_cairo_sources += $(cairo_pdf_sources) -ifeq ($(CAIRO_HAS_PDF_SURFACE),1) -enabled_cairo_headers += $(cairo_pdf_headers) -enabled_cairo_private += $(cairo_pdf_private) -enabled_cairo_cxx_sources += $(cairo_pdf_cxx_sources) -enabled_cairo_sources += $(cairo_pdf_sources) -endif -all_cairo_pkgconf += cairo-pdf.pc -ifeq ($(CAIRO_HAS_PDF_SURFACE),1) -enabled_cairo_pkgconf += cairo-pdf.pc -endif - -supported_cairo_headers += $(cairo_svg_headers) -all_cairo_headers += $(cairo_svg_headers) -all_cairo_private += $(cairo_svg_private) -all_cairo_cxx_sources += $(cairo_svg_cxx_sources) -all_cairo_sources += $(cairo_svg_sources) -ifeq ($(CAIRO_HAS_SVG_SURFACE),1) -enabled_cairo_headers += $(cairo_svg_headers) -enabled_cairo_private += $(cairo_svg_private) -enabled_cairo_cxx_sources += $(cairo_svg_cxx_sources) -enabled_cairo_sources += $(cairo_svg_sources) -endif -all_cairo_pkgconf += cairo-svg.pc -ifeq ($(CAIRO_HAS_SVG_SURFACE),1) -enabled_cairo_pkgconf += cairo-svg.pc -endif - -all_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) -all_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) -all_cairo_sources += $(cairo_test_surfaces_sources) -ifeq ($(CAIRO_HAS_TEST_SURFACES),1) -enabled_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) -enabled_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) -enabled_cairo_sources += $(cairo_test_surfaces_sources) -endif - -supported_cairo_headers += $(cairo_image_headers) -all_cairo_headers += $(cairo_image_headers) -all_cairo_private += $(cairo_image_private) -all_cairo_cxx_sources += $(cairo_image_cxx_sources) -all_cairo_sources += $(cairo_image_sources) -enabled_cairo_headers += $(cairo_image_headers) -enabled_cairo_private += $(cairo_image_private) -enabled_cairo_cxx_sources += $(cairo_image_cxx_sources) -enabled_cairo_sources += $(cairo_image_sources) - -supported_cairo_headers += $(cairo_mime_headers) -all_cairo_headers += $(cairo_mime_headers) -all_cairo_private += $(cairo_mime_private) -all_cairo_cxx_sources += $(cairo_mime_cxx_sources) -all_cairo_sources += $(cairo_mime_sources) -enabled_cairo_headers += $(cairo_mime_headers) -enabled_cairo_private += $(cairo_mime_private) -enabled_cairo_cxx_sources += $(cairo_mime_cxx_sources) -enabled_cairo_sources += $(cairo_mime_sources) - -supported_cairo_headers += $(cairo_recording_headers) -all_cairo_headers += $(cairo_recording_headers) -all_cairo_private += $(cairo_recording_private) -all_cairo_cxx_sources += $(cairo_recording_cxx_sources) -all_cairo_sources += $(cairo_recording_sources) -enabled_cairo_headers += $(cairo_recording_headers) -enabled_cairo_private += $(cairo_recording_private) -enabled_cairo_cxx_sources += $(cairo_recording_cxx_sources) -enabled_cairo_sources += $(cairo_recording_sources) - -supported_cairo_headers += $(cairo_observer_headers) -all_cairo_headers += $(cairo_observer_headers) -all_cairo_private += $(cairo_observer_private) -all_cairo_cxx_sources += $(cairo_observer_cxx_sources) -all_cairo_sources += $(cairo_observer_sources) -enabled_cairo_headers += $(cairo_observer_headers) -enabled_cairo_private += $(cairo_observer_private) -enabled_cairo_cxx_sources += $(cairo_observer_cxx_sources) -enabled_cairo_sources += $(cairo_observer_sources) - -unsupported_cairo_headers += $(cairo_tee_headers) -all_cairo_headers += $(cairo_tee_headers) -all_cairo_private += $(cairo_tee_private) -all_cairo_cxx_sources += $(cairo_tee_cxx_sources) -all_cairo_sources += $(cairo_tee_sources) -ifeq ($(CAIRO_HAS_TEE_SURFACE),1) -enabled_cairo_headers += $(cairo_tee_headers) -enabled_cairo_private += $(cairo_tee_private) -enabled_cairo_cxx_sources += $(cairo_tee_cxx_sources) -enabled_cairo_sources += $(cairo_tee_sources) -endif -all_cairo_pkgconf += cairo-tee.pc -ifeq ($(CAIRO_HAS_TEE_SURFACE),1) -enabled_cairo_pkgconf += cairo-tee.pc -endif - -unsupported_cairo_headers += $(cairo_xml_headers) -all_cairo_headers += $(cairo_xml_headers) -all_cairo_private += $(cairo_xml_private) -all_cairo_cxx_sources += $(cairo_xml_cxx_sources) -all_cairo_sources += $(cairo_xml_sources) -ifeq ($(CAIRO_HAS_XML_SURFACE),1) -enabled_cairo_headers += $(cairo_xml_headers) -enabled_cairo_private += $(cairo_xml_private) -enabled_cairo_cxx_sources += $(cairo_xml_cxx_sources) -enabled_cairo_sources += $(cairo_xml_sources) -endif -all_cairo_pkgconf += cairo-xml.pc -ifeq ($(CAIRO_HAS_XML_SURFACE),1) -enabled_cairo_pkgconf += cairo-xml.pc -endif - -supported_cairo_headers += $(cairo_user_headers) -all_cairo_headers += $(cairo_user_headers) -all_cairo_private += $(cairo_user_private) -all_cairo_cxx_sources += $(cairo_user_cxx_sources) -all_cairo_sources += $(cairo_user_sources) -enabled_cairo_headers += $(cairo_user_headers) -enabled_cairo_private += $(cairo_user_private) -enabled_cairo_cxx_sources += $(cairo_user_cxx_sources) -enabled_cairo_sources += $(cairo_user_sources) - -all_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) -all_cairo_cxx_sources += $(cairo_pthread_cxx_sources) -all_cairo_sources += $(cairo_pthread_sources) -ifeq ($(CAIRO_HAS_PTHREAD),1) -enabled_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) -enabled_cairo_cxx_sources += $(cairo_pthread_cxx_sources) -enabled_cairo_sources += $(cairo_pthread_sources) -endif - -supported_cairo_headers += $(cairo_gobject_headers) -all_cairo_headers += $(cairo_gobject_headers) -all_cairo_private += $(cairo_gobject_private) -all_cairo_cxx_sources += $(cairo_gobject_cxx_sources) -all_cairo_sources += $(cairo_gobject_sources) -ifeq ($(CAIRO_HAS_GOBJECT_FUNCTIONS),1) -enabled_cairo_headers += $(cairo_gobject_headers) -enabled_cairo_private += $(cairo_gobject_private) -enabled_cairo_cxx_sources += $(cairo_gobject_cxx_sources) -enabled_cairo_sources += $(cairo_gobject_sources) -endif -all_cairo_pkgconf += cairo-gobject.pc -ifeq ($(CAIRO_HAS_GOBJECT_FUNCTIONS),1) -enabled_cairo_pkgconf += cairo-gobject.pc -endif - -all_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) -all_cairo_cxx_sources += $(cairo_trace_cxx_sources) -all_cairo_sources += $(cairo_trace_sources) -ifeq ($(CAIRO_HAS_TRACE),1) -enabled_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) -enabled_cairo_cxx_sources += $(cairo_trace_cxx_sources) -enabled_cairo_sources += $(cairo_trace_sources) -endif - -all_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) -all_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) -all_cairo_sources += $(cairo_interpreter_sources) -ifeq ($(CAIRO_HAS_INTERPRETER),1) -enabled_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) -enabled_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) -enabled_cairo_sources += $(cairo_interpreter_sources) -endif - -all_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) -all_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) -all_cairo_sources += $(cairo_symbol_lookup_sources) -ifeq ($(CAIRO_HAS_SYMBOL_LOOKUP),1) -enabled_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) -enabled_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) -enabled_cairo_sources += $(cairo_symbol_lookup_sources) -endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/README b/Build/source/libs/cairo/cairo-1.14.2/src/README deleted file mode 100644 index 03e4455ea58..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/README +++ /dev/null @@ -1,69 +0,0 @@ -Cairo Library Source Code -========================= - -This directory contains the source code of the cairo library. - - -Source Code Listing -------------------- - -The canonical list of source files is the file Makefile.sources. See that -file for how it works. - - -New Backends ------------- - -The rule of the thumb for adding new backends is to see how other -backends are integrated. Pick one of the simpler, unsupported, backends -and search the entire tree for it, and go from there. - -To add new backends you need to basically: - - * Modify $(top_srcdir)/configure.in to add checks for your backend. - - * Modify Makefile.sources to add source files for your backend, - - * Modify $(top_srcdir)/boilerplate/ to add boilerplate code for - testing your new backend. - - -New API -------- - -After adding new API, run "make check" in this directory and fix any -reported issues. Also add new API to the right location in -$(top_srcdir)/doc/public/cairo-sections.txt and run "make check" -in $(top_builddir)/doc/public to make sure that any newly added -documentation is correctly hooked up. - -Do not forget to add tests for the new API. See next section. - - -Tests ------ - -There are some tests in this directory that check the source code and -the build for various issues. The tests are very quick to run, and -particularly should be run after any documentation or API changes. It -does not hurt to run them after any source modification either. Run -them simply by calling: - - make check - -There are also extensive regression tests in $(top_srcdir)/test. It is -a good idea to run that test suite for any changes made to the source -code. Moreover, for any new feature, API, or bug fix, new tests should -be added to the regression test suite to test the new code. - - -Bibliography ------------- - -A detailed list of academic publications used in cairo code is available -in the file $(top_srcdir)/BIBLIOGRAPHY. Feel free to update as you -implement more papers. - -For more technical publications (eg. Adobe technical reports) just -point them out in a comment in the header of the file implementing them. - diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface-private.h deleted file mode 100644 index 1e054c209ab..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface-private.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © 2005 Keith Packard - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith Packard - */ - -#ifndef CAIRO_ANALYSIS_SURFACE_H -#define CAIRO_ANALYSIS_SURFACE_H - -#include "cairoint.h" - -cairo_private cairo_surface_t * -_cairo_analysis_surface_create (cairo_surface_t *target); - -cairo_private void -_cairo_analysis_surface_set_ctm (cairo_surface_t *surface, - const cairo_matrix_t *ctm); - -cairo_private void -_cairo_analysis_surface_get_ctm (cairo_surface_t *surface, - cairo_matrix_t *ctm); - -cairo_private cairo_region_t * -_cairo_analysis_surface_get_supported (cairo_surface_t *surface); - -cairo_private cairo_region_t * -_cairo_analysis_surface_get_unsupported (cairo_surface_t *surface); - -cairo_private cairo_bool_t -_cairo_analysis_surface_has_supported (cairo_surface_t *surface); - -cairo_private cairo_bool_t -_cairo_analysis_surface_has_unsupported (cairo_surface_t *surface); - -cairo_private void -_cairo_analysis_surface_get_bounding_box (cairo_surface_t *surface, - cairo_box_t *bbox); - -cairo_private cairo_int_status_t -_cairo_analysis_surface_merge_status (cairo_int_status_t status_a, - cairo_int_status_t status_b); - -cairo_private cairo_surface_t * -_cairo_null_surface_create (cairo_content_t content); - -#endif /* CAIRO_ANALYSIS_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface.c deleted file mode 100644 index 8516094c200..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-analysis-surface.c +++ /dev/null @@ -1,934 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * Copyright © 2007 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith Packard - * Adrian Johnson - */ - -#include "cairoint.h" - -#include "cairo-analysis-surface-private.h" -#include "cairo-box-inline.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-paginated-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-inline.h" -#include "cairo-region-private.h" - -typedef struct { - cairo_surface_t base; - - cairo_surface_t *target; - - cairo_bool_t first_op; - cairo_bool_t has_supported; - cairo_bool_t has_unsupported; - - cairo_region_t supported_region; - cairo_region_t fallback_region; - cairo_box_t page_bbox; - - cairo_bool_t has_ctm; - cairo_matrix_t ctm; - -} cairo_analysis_surface_t; - -cairo_int_status_t -_cairo_analysis_surface_merge_status (cairo_int_status_t status_a, - cairo_int_status_t status_b) -{ - /* fatal errors should be checked and propagated at source */ - assert (! _cairo_int_status_is_error (status_a)); - assert (! _cairo_int_status_is_error (status_b)); - - /* return the most important status */ - if (status_a == CAIRO_INT_STATUS_UNSUPPORTED || - status_b == CAIRO_INT_STATUS_UNSUPPORTED) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (status_a == CAIRO_INT_STATUS_IMAGE_FALLBACK || - status_b == CAIRO_INT_STATUS_IMAGE_FALLBACK) - return CAIRO_INT_STATUS_IMAGE_FALLBACK; - - if (status_a == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN || - status_b == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) - return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; - - if (status_a == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY || - status_b == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY) - return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; - - /* at this point we have checked all the valid internal codes, so... */ - assert (status_a == CAIRO_INT_STATUS_SUCCESS && - status_b == CAIRO_INT_STATUS_SUCCESS); - - return CAIRO_INT_STATUS_SUCCESS; -} - -struct proxy { - cairo_surface_t base; - cairo_surface_t *target; -}; - -static cairo_status_t -proxy_finish (void *abstract_surface) -{ - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t proxy_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_NULL, - proxy_finish, -}; - -static cairo_surface_t * -attach_proxy (cairo_surface_t *source, - cairo_surface_t *target) -{ - struct proxy *proxy; - - proxy = malloc (sizeof (*proxy)); - if (unlikely (proxy == NULL)) - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_surface_init (&proxy->base, &proxy_backend, NULL, target->content); - - proxy->target = target; - _cairo_surface_attach_snapshot (source, &proxy->base, NULL); - - return &proxy->base; -} - -static void -detach_proxy (cairo_surface_t *proxy) -{ - cairo_surface_finish (proxy); - cairo_surface_destroy (proxy); -} - -static cairo_int_status_t -_analyze_recording_surface_pattern (cairo_analysis_surface_t *surface, - const cairo_pattern_t *pattern) -{ - const cairo_surface_pattern_t *surface_pattern; - cairo_analysis_surface_t *tmp; - cairo_surface_t *source, *proxy; - cairo_matrix_t p2d; - cairo_status_t status, analysis_status; - - assert (pattern->type == CAIRO_PATTERN_TYPE_SURFACE); - surface_pattern = (const cairo_surface_pattern_t *) pattern; - assert (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING); - source = surface_pattern->surface; - - proxy = _cairo_surface_has_snapshot (source, &proxy_backend); - if (proxy != NULL) { - /* nothing untoward found so far */ - return CAIRO_STATUS_SUCCESS; - } - - tmp = (cairo_analysis_surface_t *) - _cairo_analysis_surface_create (surface->target); - if (unlikely (tmp->base.status)) - return tmp->base.status; - proxy = attach_proxy (source, &tmp->base); - - p2d = pattern->matrix; - status = cairo_matrix_invert (&p2d); - assert (status == CAIRO_STATUS_SUCCESS); - - cairo_matrix_multiply (&tmp->ctm, &p2d, &surface->ctm); - tmp->has_ctm = ! _cairo_matrix_is_identity (&tmp->ctm); - - source = _cairo_surface_get_source (source, NULL); - status = _cairo_recording_surface_replay_and_create_regions (source, - &tmp->base); - analysis_status = tmp->has_unsupported ? CAIRO_INT_STATUS_IMAGE_FALLBACK : CAIRO_INT_STATUS_SUCCESS; - detach_proxy (proxy); - cairo_surface_destroy (&tmp->base); - - if (unlikely (status)) - return status; - - return analysis_status; -} - -static cairo_int_status_t -_add_operation (cairo_analysis_surface_t *surface, - cairo_rectangle_int_t *rect, - cairo_int_status_t backend_status) -{ - cairo_int_status_t status; - cairo_box_t bbox; - - if (rect->width == 0 || rect->height == 0) { - /* Even though the operation is not visible we must be careful - * to not allow unsupported operations to be replayed to the - * backend during CAIRO_PAGINATED_MODE_RENDER */ - if (backend_status == CAIRO_INT_STATUS_SUCCESS || - backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY || - backend_status == CAIRO_INT_STATUS_NOTHING_TO_DO) - { - return CAIRO_INT_STATUS_SUCCESS; - } - else - { - return CAIRO_INT_STATUS_IMAGE_FALLBACK; - } - } - - _cairo_box_from_rectangle (&bbox, rect); - - if (surface->has_ctm) { - int tx, ty; - - if (_cairo_matrix_is_integer_translation (&surface->ctm, &tx, &ty)) { - rect->x += tx; - rect->y += ty; - - tx = _cairo_fixed_from_int (tx); - bbox.p1.x += tx; - bbox.p2.x += tx; - - ty = _cairo_fixed_from_int (ty); - bbox.p1.y += ty; - bbox.p2.y += ty; - } else { - _cairo_matrix_transform_bounding_box_fixed (&surface->ctm, - &bbox, NULL); - - if (bbox.p1.x == bbox.p2.x || bbox.p1.y == bbox.p2.y) { - /* Even though the operation is not visible we must be - * careful to not allow unsupported operations to be - * replayed to the backend during - * CAIRO_PAGINATED_MODE_RENDER */ - if (backend_status == CAIRO_INT_STATUS_SUCCESS || - backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY || - backend_status == CAIRO_INT_STATUS_NOTHING_TO_DO) - { - return CAIRO_INT_STATUS_SUCCESS; - } - else - { - return CAIRO_INT_STATUS_IMAGE_FALLBACK; - } - } - - _cairo_box_round_to_rectangle (&bbox, rect); - } - } - - if (surface->first_op) { - surface->first_op = FALSE; - surface->page_bbox = bbox; - } else - _cairo_box_add_box(&surface->page_bbox, &bbox); - - /* If the operation is completely enclosed within the fallback - * region there is no benefit in emitting a native operation as - * the fallback image will be painted on top. - */ - if (cairo_region_contains_rectangle (&surface->fallback_region, rect) == CAIRO_REGION_OVERLAP_IN) - return CAIRO_INT_STATUS_IMAGE_FALLBACK; - - if (backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY) { - /* A status of CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY indicates - * that the backend only supports this operation if the - * transparency removed. If the extents of this operation does - * not intersect any other native operation, the operation is - * natively supported and the backend will blend the - * transparency into the white background. - */ - if (cairo_region_contains_rectangle (&surface->supported_region, rect) == CAIRO_REGION_OVERLAP_OUT) - backend_status = CAIRO_INT_STATUS_SUCCESS; - } - - if (backend_status == CAIRO_INT_STATUS_SUCCESS) { - /* Add the operation to the supported region. Operations in - * this region will be emitted as native operations. - */ - surface->has_supported = TRUE; - return cairo_region_union_rectangle (&surface->supported_region, rect); - } - - /* Add the operation to the unsupported region. This region will - * be painted as an image after all native operations have been - * emitted. - */ - surface->has_unsupported = TRUE; - status = cairo_region_union_rectangle (&surface->fallback_region, rect); - - /* The status CAIRO_INT_STATUS_IMAGE_FALLBACK is used to indicate - * unsupported operations to the recording surface as using - * CAIRO_INT_STATUS_UNSUPPORTED would cause cairo-surface to - * invoke the cairo-surface-fallback path then return - * CAIRO_STATUS_SUCCESS. - */ - if (status == CAIRO_INT_STATUS_SUCCESS) - return CAIRO_INT_STATUS_IMAGE_FALLBACK; - else - return status; -} - -static cairo_status_t -_cairo_analysis_surface_finish (void *abstract_surface) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - _cairo_region_fini (&surface->supported_region); - _cairo_region_fini (&surface->fallback_region); - - cairo_surface_destroy (surface->target); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_analysis_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_analysis_surface_t *surface = abstract_surface; - - return _cairo_surface_get_extents (surface->target, rectangle); -} - -static void -_rectangle_intersect_clip (cairo_rectangle_int_t *extents, const cairo_clip_t *clip) -{ - if (clip != NULL) - _cairo_rectangle_intersect (extents, _cairo_clip_get_extents (clip)); -} - -static void -_cairo_analysis_surface_operation_extents (cairo_analysis_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip, - cairo_rectangle_int_t *extents) -{ - cairo_bool_t is_empty; - - is_empty = _cairo_surface_get_extents (&surface->base, extents); - - if (_cairo_operator_bounded_by_source (op)) { - cairo_rectangle_int_t source_extents; - - _cairo_pattern_get_extents (source, &source_extents); - _cairo_rectangle_intersect (extents, &source_extents); - } - - _rectangle_intersect_clip (extents, clip); -} - -static cairo_int_status_t -_cairo_analysis_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_analysis_surface_t *surface = abstract_surface; - cairo_int_status_t backend_status; - cairo_rectangle_int_t extents; - - if (surface->target->backend->paint == NULL) { - backend_status = CAIRO_INT_STATUS_UNSUPPORTED; - } else { - backend_status = - surface->target->backend->paint (surface->target, - op, source, clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - - if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) - backend_status = _analyze_recording_surface_pattern (surface, source); - - _cairo_analysis_surface_operation_extents (surface, - op, source, clip, - &extents); - - return _add_operation (surface, &extents, backend_status); -} - -static cairo_int_status_t -_cairo_analysis_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_analysis_surface_t *surface = abstract_surface; - cairo_int_status_t backend_status; - cairo_rectangle_int_t extents; - - if (surface->target->backend->mask == NULL) { - backend_status = CAIRO_INT_STATUS_UNSUPPORTED; - } else { - backend_status = - surface->target->backend->mask (surface->target, - op, source, mask, clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - - if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) { - cairo_int_status_t backend_source_status = CAIRO_STATUS_SUCCESS; - cairo_int_status_t backend_mask_status = CAIRO_STATUS_SUCCESS; - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_t *src_surface = ((cairo_surface_pattern_t *)source)->surface; - src_surface = _cairo_surface_get_source (src_surface, NULL); - if (_cairo_surface_is_recording (src_surface)) { - backend_source_status = - _analyze_recording_surface_pattern (surface, source); - if (_cairo_int_status_is_error (backend_source_status)) - return backend_source_status; - } - } - - if (mask->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_t *mask_surface = ((cairo_surface_pattern_t *)mask)->surface; - mask_surface = _cairo_surface_get_source (mask_surface, NULL); - if (_cairo_surface_is_recording (mask_surface)) { - backend_mask_status = - _analyze_recording_surface_pattern (surface, mask); - if (_cairo_int_status_is_error (backend_mask_status)) - return backend_mask_status; - } - } - - backend_status = - _cairo_analysis_surface_merge_status (backend_source_status, - backend_mask_status); - } - - _cairo_analysis_surface_operation_extents (surface, - op, source, clip, - &extents); - - if (_cairo_operator_bounded_by_mask (op)) { - cairo_rectangle_int_t mask_extents; - - _cairo_pattern_get_extents (mask, &mask_extents); - _cairo_rectangle_intersect (&extents, &mask_extents); - } - - return _add_operation (surface, &extents, backend_status); -} - -static cairo_int_status_t -_cairo_analysis_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_analysis_surface_t *surface = abstract_surface; - cairo_int_status_t backend_status; - cairo_rectangle_int_t extents; - - if (surface->target->backend->stroke == NULL) { - backend_status = CAIRO_INT_STATUS_UNSUPPORTED; - } else { - backend_status = - surface->target->backend->stroke (surface->target, op, - source, path, style, - ctm, ctm_inverse, - tolerance, antialias, - clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - - if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) - backend_status = _analyze_recording_surface_pattern (surface, source); - - _cairo_analysis_surface_operation_extents (surface, - op, source, clip, - &extents); - - if (_cairo_operator_bounded_by_mask (op)) { - cairo_rectangle_int_t mask_extents; - cairo_int_status_t status; - - status = _cairo_path_fixed_stroke_extents (path, style, - ctm, ctm_inverse, - tolerance, - &mask_extents); - if (unlikely (status)) - return status; - - _cairo_rectangle_intersect (&extents, &mask_extents); - } - - return _add_operation (surface, &extents, backend_status); -} - -static cairo_int_status_t -_cairo_analysis_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_analysis_surface_t *surface = abstract_surface; - cairo_int_status_t backend_status; - cairo_rectangle_int_t extents; - - if (surface->target->backend->fill == NULL) { - backend_status = CAIRO_INT_STATUS_UNSUPPORTED; - } else { - backend_status = - surface->target->backend->fill (surface->target, op, - source, path, fill_rule, - tolerance, antialias, - clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - - if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) - backend_status = _analyze_recording_surface_pattern (surface, source); - - _cairo_analysis_surface_operation_extents (surface, - op, source, clip, - &extents); - - if (_cairo_operator_bounded_by_mask (op)) { - cairo_rectangle_int_t mask_extents; - - _cairo_path_fixed_fill_extents (path, fill_rule, tolerance, - &mask_extents); - - _cairo_rectangle_intersect (&extents, &mask_extents); - } - - return _add_operation (surface, &extents, backend_status); -} - -static cairo_int_status_t -_cairo_analysis_surface_show_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_analysis_surface_t *surface = abstract_surface; - cairo_int_status_t status, backend_status; - cairo_rectangle_int_t extents, glyph_extents; - - /* Adapted from _cairo_surface_show_glyphs */ - if (surface->target->backend->show_glyphs != NULL) { - backend_status = - surface->target->backend->show_glyphs (surface->target, op, - source, - glyphs, num_glyphs, - scaled_font, - clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - else if (surface->target->backend->show_text_glyphs != NULL) - { - backend_status = - surface->target->backend->show_text_glyphs (surface->target, op, - source, - NULL, 0, - glyphs, num_glyphs, - NULL, 0, - FALSE, - scaled_font, - clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - else - { - backend_status = CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) - backend_status = _analyze_recording_surface_pattern (surface, source); - - _cairo_analysis_surface_operation_extents (surface, - op, source, clip, - &extents); - - if (_cairo_operator_bounded_by_mask (op)) { - status = _cairo_scaled_font_glyph_device_extents (scaled_font, - glyphs, - num_glyphs, - &glyph_extents, - NULL); - if (unlikely (status)) - return status; - - _cairo_rectangle_intersect (&extents, &glyph_extents); - } - - return _add_operation (surface, &extents, backend_status); -} - -static cairo_bool_t -_cairo_analysis_surface_has_show_text_glyphs (void *abstract_surface) -{ - cairo_analysis_surface_t *surface = abstract_surface; - - return cairo_surface_has_show_text_glyphs (surface->target); -} - -static cairo_int_status_t -_cairo_analysis_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_analysis_surface_t *surface = abstract_surface; - cairo_int_status_t status, backend_status; - cairo_rectangle_int_t extents, glyph_extents; - - /* Adapted from _cairo_surface_show_glyphs */ - backend_status = CAIRO_INT_STATUS_UNSUPPORTED; - if (surface->target->backend->show_text_glyphs != NULL) { - backend_status = - surface->target->backend->show_text_glyphs (surface->target, op, - source, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font, - clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - if (backend_status == CAIRO_INT_STATUS_UNSUPPORTED && - surface->target->backend->show_glyphs != NULL) - { - backend_status = - surface->target->backend->show_glyphs (surface->target, op, - source, - glyphs, num_glyphs, - scaled_font, - clip); - if (_cairo_int_status_is_error (backend_status)) - return backend_status; - } - - if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) - backend_status = _analyze_recording_surface_pattern (surface, source); - - _cairo_analysis_surface_operation_extents (surface, - op, source, clip, - &extents); - - if (_cairo_operator_bounded_by_mask (op)) { - status = _cairo_scaled_font_glyph_device_extents (scaled_font, - glyphs, - num_glyphs, - &glyph_extents, - NULL); - if (unlikely (status)) - return status; - - _cairo_rectangle_intersect (&extents, &glyph_extents); - } - - return _add_operation (surface, &extents, backend_status); -} - -static const cairo_surface_backend_t cairo_analysis_surface_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_ANALYSIS, - - _cairo_analysis_surface_finish, - NULL, - - NULL, /* create_similar */ - NULL, /* create_similar_image */ - NULL, /* map_to_image */ - NULL, /* unmap */ - - NULL, /* source */ - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_analysis_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_analysis_surface_paint, - _cairo_analysis_surface_mask, - _cairo_analysis_surface_stroke, - _cairo_analysis_surface_fill, - NULL, /* fill_stroke */ - _cairo_analysis_surface_show_glyphs, - _cairo_analysis_surface_has_show_text_glyphs, - _cairo_analysis_surface_show_text_glyphs -}; - -cairo_surface_t * -_cairo_analysis_surface_create (cairo_surface_t *target) -{ - cairo_analysis_surface_t *surface; - cairo_status_t status; - - status = target->status; - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - surface = malloc (sizeof (cairo_analysis_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - /* I believe the content type here is truly arbitrary. I'm quite - * sure nothing will ever use this value. */ - _cairo_surface_init (&surface->base, - &cairo_analysis_surface_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - cairo_matrix_init_identity (&surface->ctm); - surface->has_ctm = FALSE; - - surface->target = cairo_surface_reference (target); - surface->first_op = TRUE; - surface->has_supported = FALSE; - surface->has_unsupported = FALSE; - - _cairo_region_init (&surface->supported_region); - _cairo_region_init (&surface->fallback_region); - - surface->page_bbox.p1.x = 0; - surface->page_bbox.p1.y = 0; - surface->page_bbox.p2.x = 0; - surface->page_bbox.p2.y = 0; - - return &surface->base; -} - -void -_cairo_analysis_surface_set_ctm (cairo_surface_t *abstract_surface, - const cairo_matrix_t *ctm) -{ - cairo_analysis_surface_t *surface; - - if (abstract_surface->status) - return; - - surface = (cairo_analysis_surface_t *) abstract_surface; - - surface->ctm = *ctm; - surface->has_ctm = ! _cairo_matrix_is_identity (&surface->ctm); -} - -void -_cairo_analysis_surface_get_ctm (cairo_surface_t *abstract_surface, - cairo_matrix_t *ctm) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - *ctm = surface->ctm; -} - - -cairo_region_t * -_cairo_analysis_surface_get_supported (cairo_surface_t *abstract_surface) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - return &surface->supported_region; -} - -cairo_region_t * -_cairo_analysis_surface_get_unsupported (cairo_surface_t *abstract_surface) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - return &surface->fallback_region; -} - -cairo_bool_t -_cairo_analysis_surface_has_supported (cairo_surface_t *abstract_surface) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - return surface->has_supported; -} - -cairo_bool_t -_cairo_analysis_surface_has_unsupported (cairo_surface_t *abstract_surface) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - return surface->has_unsupported; -} - -void -_cairo_analysis_surface_get_bounding_box (cairo_surface_t *abstract_surface, - cairo_box_t *bbox) -{ - cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; - - *bbox = surface->page_bbox; -} - -/* null surface type: a surface that does nothing (has no side effects, yay!) */ - -static cairo_int_status_t -_return_success (void) -{ - return CAIRO_STATUS_SUCCESS; -} - -/* These typedefs are just to silence the compiler... */ -typedef cairo_int_status_t -(*_paint_func) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -typedef cairo_int_status_t -(*_mask_func) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -typedef cairo_int_status_t -(*_stroke_func) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -typedef cairo_int_status_t -(*_fill_func) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -typedef cairo_int_status_t -(*_show_glyphs_func) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - -static const cairo_surface_backend_t cairo_null_surface_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_NULL, - NULL, /* finish */ - - NULL, /* only accessed through the surface functions */ - - NULL, /* create_similar */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image*/ - - NULL, /* source */ - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - NULL, /* get_extents */ - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - (_paint_func) _return_success, /* paint */ - (_mask_func) _return_success, /* mask */ - (_stroke_func) _return_success, /* stroke */ - (_fill_func) _return_success, /* fill */ - NULL, /* fill_stroke */ - (_show_glyphs_func) _return_success, /* show_glyphs */ - NULL, /* has_show_text_glyphs */ - NULL /* show_text_glyphs */ -}; - -cairo_surface_t * -_cairo_null_surface_create (cairo_content_t content) -{ - cairo_surface_t *surface; - - surface = malloc (sizeof (cairo_surface_t)); - if (unlikely (surface == NULL)) { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - _cairo_surface_init (surface, - &cairo_null_surface_backend, - NULL, /* device */ - content); - - return surface; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc-private.h deleted file mode 100644 index a22c01ac90b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc-private.h +++ /dev/null @@ -1,61 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_ARC_PRIVATE_H -#define CAIRO_ARC_PRIVATE_H - -#include "cairoint.h" - -CAIRO_BEGIN_DECLS - -cairo_private void -_cairo_arc_path (cairo_t *cr, - double xc, - double yc, - double radius, - double angle1, - double angle2); - -cairo_private void -_cairo_arc_path_negative (cairo_t *cr, - double xc, - double yc, - double radius, - double angle1, - double angle2); - -CAIRO_END_DECLS - -#endif /* CAIRO_ARC_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc.c deleted file mode 100644 index 390397bae10..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-arc.c +++ /dev/null @@ -1,312 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-arc-private.h" - -#define MAX_FULL_CIRCLES 65536 - -/* Spline deviation from the circle in radius would be given by: - - error = sqrt (x**2 + y**2) - 1 - - A simpler error function to work with is: - - e = x**2 + y**2 - 1 - - From "Good approximation of circles by curvature-continuous Bezier - curves", Tor Dokken and Morten Daehlen, Computer Aided Geometric - Design 8 (1990) 22-41, we learn: - - abs (max(e)) = 4/27 * sin**6(angle/4) / cos**2(angle/4) - - and - abs (error) =~ 1/2 * e - - Of course, this error value applies only for the particular spline - approximation that is used in _cairo_gstate_arc_segment. -*/ -static double -_arc_error_normalized (double angle) -{ - return 2.0/27.0 * pow (sin (angle / 4), 6) / pow (cos (angle / 4), 2); -} - -static double -_arc_max_angle_for_tolerance_normalized (double tolerance) -{ - double angle, error; - int i; - - /* Use table lookup to reduce search time in most cases. */ - struct { - double angle; - double error; - } table[] = { - { M_PI / 1.0, 0.0185185185185185036127 }, - { M_PI / 2.0, 0.000272567143730179811158 }, - { M_PI / 3.0, 2.38647043651461047433e-05 }, - { M_PI / 4.0, 4.2455377443222443279e-06 }, - { M_PI / 5.0, 1.11281001494389081528e-06 }, - { M_PI / 6.0, 3.72662000942734705475e-07 }, - { M_PI / 7.0, 1.47783685574284411325e-07 }, - { M_PI / 8.0, 6.63240432022601149057e-08 }, - { M_PI / 9.0, 3.2715520137536980553e-08 }, - { M_PI / 10.0, 1.73863223499021216974e-08 }, - { M_PI / 11.0, 9.81410988043554039085e-09 }, - }; - int table_size = ARRAY_LENGTH (table); - - for (i = 0; i < table_size; i++) - if (table[i].error < tolerance) - return table[i].angle; - - ++i; - do { - angle = M_PI / i++; - error = _arc_error_normalized (angle); - } while (error > tolerance); - - return angle; -} - -static int -_arc_segments_needed (double angle, - double radius, - cairo_matrix_t *ctm, - double tolerance) -{ - double major_axis, max_angle; - - /* the error is amplified by at most the length of the - * major axis of the circle; see cairo-pen.c for a more detailed analysis - * of this. */ - major_axis = _cairo_matrix_transformed_circle_major_axis (ctm, radius); - max_angle = _arc_max_angle_for_tolerance_normalized (tolerance / major_axis); - - return ceil (fabs (angle) / max_angle); -} - -/* We want to draw a single spline approximating a circular arc radius - R from angle A to angle B. Since we want a symmetric spline that - matches the endpoints of the arc in position and slope, we know - that the spline control points must be: - - (R * cos(A), R * sin(A)) - (R * cos(A) - h * sin(A), R * sin(A) + h * cos (A)) - (R * cos(B) + h * sin(B), R * sin(B) - h * cos (B)) - (R * cos(B), R * sin(B)) - - for some value of h. - - "Approximation of circular arcs by cubic polynomials", Michael - Goldapp, Computer Aided Geometric Design 8 (1991) 227-238, provides - various values of h along with error analysis for each. - - From that paper, a very practical value of h is: - - h = 4/3 * R * tan(angle/4) - - This value does not give the spline with minimal error, but it does - provide a very good approximation, (6th-order convergence), and the - error expression is quite simple, (see the comment for - _arc_error_normalized). -*/ -static void -_cairo_arc_segment (cairo_t *cr, - double xc, - double yc, - double radius, - double angle_A, - double angle_B) -{ - double r_sin_A, r_cos_A; - double r_sin_B, r_cos_B; - double h; - - r_sin_A = radius * sin (angle_A); - r_cos_A = radius * cos (angle_A); - r_sin_B = radius * sin (angle_B); - r_cos_B = radius * cos (angle_B); - - h = 4.0/3.0 * tan ((angle_B - angle_A) / 4.0); - - cairo_curve_to (cr, - xc + r_cos_A - h * r_sin_A, - yc + r_sin_A + h * r_cos_A, - xc + r_cos_B + h * r_sin_B, - yc + r_sin_B - h * r_cos_B, - xc + r_cos_B, - yc + r_sin_B); -} - -static void -_cairo_arc_in_direction (cairo_t *cr, - double xc, - double yc, - double radius, - double angle_min, - double angle_max, - cairo_direction_t dir) -{ - if (cairo_status (cr)) - return; - - assert (angle_max >= angle_min); - - if (angle_max - angle_min > 2 * M_PI * MAX_FULL_CIRCLES) { - angle_max = fmod (angle_max - angle_min, 2 * M_PI); - angle_min = fmod (angle_min, 2 * M_PI); - angle_max += angle_min + 2 * M_PI * MAX_FULL_CIRCLES; - } - - /* Recurse if drawing arc larger than pi */ - if (angle_max - angle_min > M_PI) { - double angle_mid = angle_min + (angle_max - angle_min) / 2.0; - if (dir == CAIRO_DIRECTION_FORWARD) { - _cairo_arc_in_direction (cr, xc, yc, radius, - angle_min, angle_mid, - dir); - - _cairo_arc_in_direction (cr, xc, yc, radius, - angle_mid, angle_max, - dir); - } else { - _cairo_arc_in_direction (cr, xc, yc, radius, - angle_mid, angle_max, - dir); - - _cairo_arc_in_direction (cr, xc, yc, radius, - angle_min, angle_mid, - dir); - } - } else if (angle_max != angle_min) { - cairo_matrix_t ctm; - int i, segments; - double step; - - cairo_get_matrix (cr, &ctm); - segments = _arc_segments_needed (angle_max - angle_min, - radius, &ctm, - cairo_get_tolerance (cr)); - step = (angle_max - angle_min) / segments; - segments -= 1; - - if (dir == CAIRO_DIRECTION_REVERSE) { - double t; - - t = angle_min; - angle_min = angle_max; - angle_max = t; - - step = -step; - } - - cairo_line_to (cr, - xc + radius * cos (angle_min), - yc + radius * sin (angle_min)); - - for (i = 0; i < segments; i++, angle_min += step) { - _cairo_arc_segment (cr, xc, yc, radius, - angle_min, angle_min + step); - } - - _cairo_arc_segment (cr, xc, yc, radius, - angle_min, angle_max); - } else { - cairo_line_to (cr, - xc + radius * cos (angle_min), - yc + radius * sin (angle_min)); - } -} - -/** - * _cairo_arc_path: - * @cr: a cairo context - * @xc: X position of the center of the arc - * @yc: Y position of the center of the arc - * @radius: the radius of the arc - * @angle1: the start angle, in radians - * @angle2: the end angle, in radians - * - * Compute a path for the given arc and append it onto the current - * path within @cr. The arc will be accurate within the current - * tolerance and given the current transformation. - **/ -void -_cairo_arc_path (cairo_t *cr, - double xc, - double yc, - double radius, - double angle1, - double angle2) -{ - _cairo_arc_in_direction (cr, xc, yc, - radius, - angle1, angle2, - CAIRO_DIRECTION_FORWARD); -} - -/** - * _cairo_arc_path_negative: - * @xc: X position of the center of the arc - * @yc: Y position of the center of the arc - * @radius: the radius of the arc - * @angle1: the start angle, in radians - * @angle2: the end angle, in radians - * @ctm: the current transformation matrix - * @tolerance: the current tolerance value - * @path: the path onto which the arc will be appended - * - * Compute a path for the given arc (defined in the negative - * direction) and append it onto the current path within @cr. The arc - * will be accurate within the current tolerance and given the current - * transformation. - **/ -void -_cairo_arc_path_negative (cairo_t *cr, - double xc, - double yc, - double radius, - double angle1, - double angle2) -{ - _cairo_arc_in_direction (cr, xc, yc, - radius, - angle2, angle1, - CAIRO_DIRECTION_REVERSE); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-array-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-array-private.h deleted file mode 100644 index 35b29e5fc07..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-array-private.h +++ /dev/null @@ -1,90 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_ARRAY_PRIVATE_H -#define CAIRO_ARRAY_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-types-private.h" - -CAIRO_BEGIN_DECLS - -/* cairo-array.c structures and functions */ - -cairo_private void -_cairo_array_init (cairo_array_t *array, unsigned int element_size); - -cairo_private void -_cairo_array_fini (cairo_array_t *array); - -cairo_private cairo_status_t -_cairo_array_grow_by (cairo_array_t *array, unsigned int additional); - -cairo_private void -_cairo_array_truncate (cairo_array_t *array, unsigned int num_elements); - -cairo_private cairo_status_t -_cairo_array_append (cairo_array_t *array, const void *element); - -cairo_private cairo_status_t -_cairo_array_append_multiple (cairo_array_t *array, - const void *elements, - unsigned int num_elements); - -cairo_private cairo_status_t -_cairo_array_allocate (cairo_array_t *array, - unsigned int num_elements, - void **elements); - -cairo_private void * -_cairo_array_index (cairo_array_t *array, unsigned int index); - -cairo_private const void * -_cairo_array_index_const (const cairo_array_t *array, unsigned int index); - -cairo_private void -_cairo_array_copy_element (const cairo_array_t *array, unsigned int index, void *dst); - -cairo_private unsigned int -_cairo_array_num_elements (const cairo_array_t *array); - -cairo_private unsigned int -_cairo_array_size (const cairo_array_t *array); - -CAIRO_END_DECLS - -#endif /* CAIRO_ARRAY_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-array.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-array.c deleted file mode 100644 index 4f3c082ff6b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-array.c +++ /dev/null @@ -1,526 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Carl Worth - */ - -#include "cairoint.h" -#include "cairo-array-private.h" -#include "cairo-error-private.h" - -/** - * _cairo_array_init: - * - * Initialize a new #cairo_array_t object to store objects each of size - * @element_size. - * - * The #cairo_array_t object provides grow-by-doubling storage. It - * never interprets the data passed to it, nor does it provide any - * sort of callback mechanism for freeing resources held onto by - * stored objects. - * - * When finished using the array, _cairo_array_fini() should be - * called to free resources allocated during use of the array. - **/ -void -_cairo_array_init (cairo_array_t *array, unsigned int element_size) -{ - array->size = 0; - array->num_elements = 0; - array->element_size = element_size; - array->elements = NULL; -} - -/** - * _cairo_array_fini: - * @array: A #cairo_array_t - * - * Free all resources associated with @array. After this call, @array - * should not be used again without a subsequent call to - * _cairo_array_init() again first. - **/ -void -_cairo_array_fini (cairo_array_t *array) -{ - free (array->elements); -} - -/** - * _cairo_array_grow_by: - * @array: a #cairo_array_t - * - * Increase the size of @array (if needed) so that there are at least - * @additional free spaces in the array. The actual size of the array - * is always increased by doubling as many times as necessary. - **/ -cairo_status_t -_cairo_array_grow_by (cairo_array_t *array, unsigned int additional) -{ - char *new_elements; - unsigned int old_size = array->size; - unsigned int required_size = array->num_elements + additional; - unsigned int new_size; - - /* check for integer overflow */ - if (required_size > INT_MAX || required_size < array->num_elements) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (required_size <= old_size) - return CAIRO_STATUS_SUCCESS; - - if (old_size == 0) - new_size = 1; - else - new_size = old_size * 2; - - while (new_size < required_size) - new_size = new_size * 2; - - array->size = new_size; - new_elements = _cairo_realloc_ab (array->elements, - array->size, array->element_size); - - if (unlikely (new_elements == NULL)) { - array->size = old_size; - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - array->elements = new_elements; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_array_truncate: - * @array: a #cairo_array_t - * - * Truncate size of the array to @num_elements if less than the - * current size. No memory is actually freed. The stored objects - * beyond @num_elements are simply "forgotten". - **/ -void -_cairo_array_truncate (cairo_array_t *array, unsigned int num_elements) -{ - if (num_elements < array->num_elements) - array->num_elements = num_elements; -} - -/** - * _cairo_array_index: - * @array: a #cairo_array_t - * Returns: A pointer to the object stored at @index. - * - * If the resulting value is assigned to a pointer to an object of the same - * element_size as initially passed to _cairo_array_init() then that - * pointer may be used for further direct indexing with []. For - * example: - * - * - * cairo_array_t array; - * double *values; - * - * _cairo_array_init (&array, sizeof(double)); - * ... calls to _cairo_array_append() here ... - * - * values = _cairo_array_index (&array, 0); - * for (i = 0; i < _cairo_array_num_elements (&array); i++) - * ... use values[i] here ... - * - **/ -void * -_cairo_array_index (cairo_array_t *array, unsigned int index) -{ - /* We allow an index of 0 for the no-elements case. - * This makes for cleaner calling code which will often look like: - * - * elements = _cairo_array_index (array, 0); - * for (i=0; i < num_elements; i++) { - * ... use elements[i] here ... - * } - * - * which in the num_elements==0 case gets the NULL pointer here, - * but never dereferences it. - */ - if (index == 0 && array->num_elements == 0) - return NULL; - - assert (index < array->num_elements); - - return array->elements + index * array->element_size; -} - -/** - * _cairo_array_index_const: - * @array: a #cairo_array_t - * Returns: A pointer to the object stored at @index. - * - * If the resulting value is assigned to a pointer to an object of the same - * element_size as initially passed to _cairo_array_init() then that - * pointer may be used for further direct indexing with []. For - * example: - * - * - * cairo_array_t array; - * const double *values; - * - * _cairo_array_init (&array, sizeof(double)); - * ... calls to _cairo_array_append() here ... - * - * values = _cairo_array_index_const (&array, 0); - * for (i = 0; i < _cairo_array_num_elements (&array); i++) - * ... read values[i] here ... - * - **/ -const void * -_cairo_array_index_const (const cairo_array_t *array, unsigned int index) -{ - /* We allow an index of 0 for the no-elements case. - * This makes for cleaner calling code which will often look like: - * - * elements = _cairo_array_index_const (array, 0); - * for (i=0; i < num_elements; i++) { - * ... read elements[i] here ... - * } - * - * which in the num_elements==0 case gets the NULL pointer here, - * but never dereferences it. - */ - if (index == 0 && array->num_elements == 0) - return NULL; - - assert (index < array->num_elements); - - return array->elements + index * array->element_size; -} - -/** - * _cairo_array_copy_element: - * @array: a #cairo_array_t - * - * Copy a single element out of the array from index @index into the - * location pointed to by @dst. - **/ -void -_cairo_array_copy_element (const cairo_array_t *array, - unsigned int index, - void *dst) -{ - memcpy (dst, _cairo_array_index_const (array, index), array->element_size); -} - -/** - * _cairo_array_append: - * @array: a #cairo_array_t - * - * Append a single item onto the array by growing the array by at - * least one element, then copying element_size bytes from @element - * into the array. The address of the resulting object within the - * array can be determined with: - * - * _cairo_array_index (array, _cairo_array_num_elements (array) - 1); - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the - * operation. - **/ -cairo_status_t -_cairo_array_append (cairo_array_t *array, - const void *element) -{ - return _cairo_array_append_multiple (array, element, 1); -} - -/** - * _cairo_array_append_multiple: - * @array: a #cairo_array_t - * - * Append one or more items onto the array by growing the array by - * @num_elements, then copying @num_elements * element_size bytes from - * @elements into the array. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the - * operation. - **/ -cairo_status_t -_cairo_array_append_multiple (cairo_array_t *array, - const void *elements, - unsigned int num_elements) -{ - cairo_status_t status; - void *dest; - - status = _cairo_array_allocate (array, num_elements, &dest); - if (unlikely (status)) - return status; - - memcpy (dest, elements, num_elements * array->element_size); - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_array_allocate: - * @array: a #cairo_array_t - * - * Allocate space at the end of the array for @num_elements additional - * elements, providing the address of the new memory chunk in - * @elements. This memory will be unitialized, but will be accounted - * for in the return value of _cairo_array_num_elements(). - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the - * operation. - **/ -cairo_status_t -_cairo_array_allocate (cairo_array_t *array, - unsigned int num_elements, - void **elements) -{ - cairo_status_t status; - - status = _cairo_array_grow_by (array, num_elements); - if (unlikely (status)) - return status; - - assert (array->num_elements + num_elements <= array->size); - - *elements = array->elements + array->num_elements * array->element_size; - - array->num_elements += num_elements; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_array_num_elements: - * @array: a #cairo_array_t - * Returns: The number of elements stored in @array. - * - * This space was left intentionally blank, but gtk-doc filled it. - **/ -unsigned int -_cairo_array_num_elements (const cairo_array_t *array) -{ - return array->num_elements; -} - -/** - * _cairo_array_size: - * @array: a #cairo_array_t - * Returns: The number of elements for which there is currently space - * allocated in @array. - * - * This space was left intentionally blank, but gtk-doc filled it. - **/ -unsigned int -_cairo_array_size (const cairo_array_t *array) -{ - return array->size; -} - -/** - * _cairo_user_data_array_init: - * @array: a #cairo_user_data_array_t - * - * Initializes a #cairo_user_data_array_t structure for future - * use. After initialization, the array has no keys. Call - * _cairo_user_data_array_fini() to free any allocated memory - * when done using the array. - **/ -void -_cairo_user_data_array_init (cairo_user_data_array_t *array) -{ - _cairo_array_init (array, sizeof (cairo_user_data_slot_t)); -} - -/** - * _cairo_user_data_array_fini: - * @array: a #cairo_user_data_array_t - * - * Destroys all current keys in the user data array and deallocates - * any memory allocated for the array itself. - **/ -void -_cairo_user_data_array_fini (cairo_user_data_array_t *array) -{ - unsigned int num_slots; - - num_slots = array->num_elements; - if (num_slots) { - cairo_user_data_slot_t *slots; - - slots = _cairo_array_index (array, 0); - while (num_slots--) { - cairo_user_data_slot_t *s = &slots[num_slots]; - if (s->user_data != NULL && s->destroy != NULL) - s->destroy (s->user_data); - } - } - - _cairo_array_fini (array); -} - -/** - * _cairo_user_data_array_get_data: - * @array: a #cairo_user_data_array_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Returns user data previously attached using the specified - * key. If no user data has been attached with the given key this - * function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - **/ -void * -_cairo_user_data_array_get_data (cairo_user_data_array_t *array, - const cairo_user_data_key_t *key) -{ - int i, num_slots; - cairo_user_data_slot_t *slots; - - /* We allow this to support degenerate objects such as cairo_surface_nil. */ - if (array == NULL) - return NULL; - - num_slots = array->num_elements; - slots = _cairo_array_index (array, 0); - for (i = 0; i < num_slots; i++) { - if (slots[i].key == key) - return slots[i].user_data; - } - - return NULL; -} - -/** - * _cairo_user_data_array_set_data: - * @array: a #cairo_user_data_array_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach - * @destroy: a #cairo_destroy_func_t which will be called when the - * user data array is destroyed or when new user data is attached using the - * same key. - * - * Attaches user data to a user data array. To remove user data, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - **/ -cairo_status_t -_cairo_user_data_array_set_data (cairo_user_data_array_t *array, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - cairo_status_t status; - int i, num_slots; - cairo_user_data_slot_t *slots, *slot, new_slot; - - if (user_data) { - new_slot.key = key; - new_slot.user_data = user_data; - new_slot.destroy = destroy; - } else { - new_slot.key = NULL; - new_slot.user_data = NULL; - new_slot.destroy = NULL; - } - - slot = NULL; - num_slots = array->num_elements; - slots = _cairo_array_index (array, 0); - for (i = 0; i < num_slots; i++) { - if (slots[i].key == key) { - slot = &slots[i]; - if (slot->destroy && slot->user_data) - slot->destroy (slot->user_data); - break; - } - if (user_data && slots[i].user_data == NULL) { - slot = &slots[i]; /* Have to keep searching for an exact match */ - } - } - - if (slot) { - *slot = new_slot; - return CAIRO_STATUS_SUCCESS; - } - - status = _cairo_array_append (array, &new_slot); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_user_data_array_copy (cairo_user_data_array_t *dst, - const cairo_user_data_array_t *src) -{ - /* discard any existing user-data */ - if (dst->num_elements != 0) { - _cairo_user_data_array_fini (dst); - _cairo_user_data_array_init (dst); - } - - return _cairo_array_append_multiple (dst, - _cairo_array_index_const (src, 0), - src->num_elements); -} - -void -_cairo_user_data_array_foreach (cairo_user_data_array_t *array, - void (*func) (const void *key, - void *elt, - void *closure), - void *closure) -{ - cairo_user_data_slot_t *slots; - int i, num_slots; - - num_slots = array->num_elements; - slots = _cairo_array_index (array, 0); - for (i = 0; i < num_slots; i++) { - if (slots[i].user_data != NULL) - func (slots[i].key, slots[i].user_data, closure); - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic-private.h deleted file mode 100644 index 327fed1d928..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic-private.h +++ /dev/null @@ -1,272 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * Copyright © 2010 Andrea Canciani - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - * Andrea Canciani - */ - -#ifndef CAIRO_ATOMIC_PRIVATE_H -#define CAIRO_ATOMIC_PRIVATE_H - -# include "cairo-compiler-private.h" - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* The autoconf on OpenBSD 4.5 produces the malformed constant name - * SIZEOF_VOID__ rather than SIZEOF_VOID_P. Work around that here. */ -#if !defined(SIZEOF_VOID_P) && defined(SIZEOF_VOID__) -# define SIZEOF_VOID_P SIZEOF_VOID__ -#endif - -CAIRO_BEGIN_DECLS - -#if HAVE_INTEL_ATOMIC_PRIMITIVES - -#define HAS_ATOMIC_OPS 1 - -typedef int cairo_atomic_int_t; - -#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER -static cairo_always_inline cairo_atomic_int_t -_cairo_atomic_int_get (cairo_atomic_int_t *x) -{ - __sync_synchronize (); - return *x; -} - -static cairo_always_inline void * -_cairo_atomic_ptr_get (void **x) -{ - __sync_synchronize (); - return *x; -} -#else -# define _cairo_atomic_int_get(x) (*x) -# define _cairo_atomic_ptr_get(x) (*x) -#endif - -# define _cairo_atomic_int_inc(x) ((void) __sync_fetch_and_add(x, 1)) -# define _cairo_atomic_int_dec(x) ((void) __sync_fetch_and_add(x, -1)) -# define _cairo_atomic_int_dec_and_test(x) (__sync_fetch_and_add(x, -1) == 1) -# define _cairo_atomic_int_cmpxchg(x, oldv, newv) __sync_bool_compare_and_swap (x, oldv, newv) -# define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv) - -#if SIZEOF_VOID_P==SIZEOF_INT -typedef int cairo_atomic_intptr_t; -#elif SIZEOF_VOID_P==SIZEOF_LONG -typedef long cairo_atomic_intptr_t; -#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG -typedef long long cairo_atomic_intptr_t; -#else -#error No matching integer pointer type -#endif - -# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ - __sync_bool_compare_and_swap ((cairo_atomic_intptr_t*)x, (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv) - -# define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) \ - _cairo_atomic_intptr_to_voidptr (__sync_val_compare_and_swap ((cairo_atomic_intptr_t*)x, (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv)) - -#endif - -#if HAVE_LIB_ATOMIC_OPS -#include - -#define HAS_ATOMIC_OPS 1 - -typedef AO_t cairo_atomic_int_t; - -# define _cairo_atomic_int_get(x) (AO_load_full (x)) - -# define _cairo_atomic_int_inc(x) ((void) AO_fetch_and_add1_full(x)) -# define _cairo_atomic_int_dec(x) ((void) AO_fetch_and_sub1_full(x)) -# define _cairo_atomic_int_dec_and_test(x) (AO_fetch_and_sub1_full(x) == 1) -# define _cairo_atomic_int_cmpxchg(x, oldv, newv) AO_compare_and_swap_full(x, oldv, newv) - -#if SIZEOF_VOID_P==SIZEOF_INT -typedef unsigned int cairo_atomic_intptr_t; -#elif SIZEOF_VOID_P==SIZEOF_LONG -typedef unsigned long cairo_atomic_intptr_t; -#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG -typedef unsigned long long cairo_atomic_intptr_t; -#else -#error No matching integer pointer type -#endif - -# define _cairo_atomic_ptr_get(x) _cairo_atomic_intptr_to_voidptr (AO_load_full (x)) -# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ - _cairo_atomic_int_cmpxchg ((cairo_atomic_intptr_t*)(x), (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv) - -#endif - -#if HAVE_OS_ATOMIC_OPS -#include - -#define HAS_ATOMIC_OPS 1 - -typedef int32_t cairo_atomic_int_t; - -# define _cairo_atomic_int_get(x) (OSMemoryBarrier(), *(x)) - -# define _cairo_atomic_int_inc(x) ((void) OSAtomicIncrement32Barrier (x)) -# define _cairo_atomic_int_dec(x) ((void) OSAtomicDecrement32Barrier (x)) -# define _cairo_atomic_int_dec_and_test(x) (OSAtomicDecrement32Barrier (x) == 0) -# define _cairo_atomic_int_cmpxchg(x, oldv, newv) OSAtomicCompareAndSwap32Barrier(oldv, newv, x) - -#if SIZEOF_VOID_P==4 -typedef int32_t cairo_atomic_intptr_t; -# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ - OSAtomicCompareAndSwap32Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x) - -#elif SIZEOF_VOID_P==8 -typedef int64_t cairo_atomic_intptr_t; -# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ - OSAtomicCompareAndSwap64Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x) - -#else -#error No matching integer pointer type -#endif - -# define _cairo_atomic_ptr_get(x) (OSMemoryBarrier(), *(x)) - -#endif - -#ifndef HAS_ATOMIC_OPS - -#if SIZEOF_VOID_P==SIZEOF_INT -typedef unsigned int cairo_atomic_intptr_t; -#elif SIZEOF_VOID_P==SIZEOF_LONG -typedef unsigned long cairo_atomic_intptr_t; -#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG -typedef unsigned long long cairo_atomic_intptr_t; -#else -#error No matching integer pointer type -#endif - -typedef cairo_atomic_intptr_t cairo_atomic_int_t; - -cairo_private void -_cairo_atomic_int_inc (cairo_atomic_int_t *x); - -#define _cairo_atomic_int_dec(x) _cairo_atomic_int_dec_and_test(x) - -cairo_private cairo_bool_t -_cairo_atomic_int_dec_and_test (cairo_atomic_int_t *x); - -cairo_private cairo_atomic_int_t -_cairo_atomic_int_cmpxchg_return_old_impl (cairo_atomic_int_t *x, cairo_atomic_int_t oldv, cairo_atomic_int_t newv); - -cairo_private void * -_cairo_atomic_ptr_cmpxchg_return_old_impl (void **x, void *oldv, void *newv); - -#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_int_cmpxchg_return_old_impl (x, oldv, newv) -#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_ptr_cmpxchg_return_old_impl (x, oldv, newv) - -#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER -cairo_private cairo_atomic_int_t -_cairo_atomic_int_get (cairo_atomic_int_t *x); -# define _cairo_atomic_ptr_get(x) (void *) _cairo_atomic_int_get((cairo_atomic_int_t *) x) -#else -# define _cairo_atomic_int_get(x) (*x) -# define _cairo_atomic_ptr_get(x) (*x) -#endif - -#else - -/* Workaround GCC complaining about casts */ -static cairo_always_inline void * -_cairo_atomic_intptr_to_voidptr (cairo_atomic_intptr_t x) -{ - return (void *) x; -} - -static cairo_always_inline cairo_atomic_int_t -_cairo_atomic_int_cmpxchg_return_old_fallback(cairo_atomic_int_t *x, cairo_atomic_int_t oldv, cairo_atomic_int_t newv) -{ - cairo_atomic_int_t curr; - - do { - curr = _cairo_atomic_int_get (x); - } while (curr == oldv && !_cairo_atomic_int_cmpxchg (x, oldv, newv)); - - return curr; -} - -static cairo_always_inline void * -_cairo_atomic_ptr_cmpxchg_return_old_fallback(void **x, void *oldv, void *newv) -{ - void *curr; - - do { - curr = _cairo_atomic_ptr_get (x); - } while (curr == oldv && !_cairo_atomic_ptr_cmpxchg (x, oldv, newv)); - - return curr; -} -#endif - -#ifndef _cairo_atomic_int_cmpxchg_return_old -#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_int_cmpxchg_return_old_fallback (x, oldv, newv) -#endif - -#ifndef _cairo_atomic_ptr_cmpxchg_return_old -#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_ptr_cmpxchg_return_old_fallback (x, oldv, newv) -#endif - -#ifndef _cairo_atomic_int_cmpxchg -#define _cairo_atomic_int_cmpxchg(x, oldv, newv) (_cairo_atomic_int_cmpxchg_return_old (x, oldv, newv) == oldv) -#endif - -#ifndef _cairo_atomic_ptr_cmpxchg -#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) (_cairo_atomic_ptr_cmpxchg_return_old (x, oldv, newv) == oldv) -#endif - -#define _cairo_atomic_uint_get(x) _cairo_atomic_int_get(x) -#define _cairo_atomic_uint_cmpxchg(x, oldv, newv) \ - _cairo_atomic_int_cmpxchg((cairo_atomic_int_t *)x, oldv, newv) - -#define _cairo_status_set_error(status, err) do { \ - int ret__; \ - assert (err < CAIRO_STATUS_LAST_STATUS); \ - /* hide compiler warnings about cairo_status_t != int (gcc treats its as \ - * an unsigned integer instead, and about ignoring the return value. */ \ - ret__ = _cairo_atomic_int_cmpxchg ((cairo_atomic_int_t *) status, CAIRO_STATUS_SUCCESS, err); \ - (void) ret__; \ -} while (0) - -CAIRO_END_DECLS - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic.c deleted file mode 100644 index 909cfea4925..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-atomic.c +++ /dev/null @@ -1,106 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-atomic-private.h" -#include "cairo-mutex-private.h" - -#ifdef HAS_ATOMIC_OPS -COMPILE_TIME_ASSERT(sizeof(void*) == sizeof(int) || - sizeof(void*) == sizeof(long) || - sizeof(void*) == sizeof(long long)); -#else -void -_cairo_atomic_int_inc (cairo_atomic_intptr_t *x) -{ - CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); - *x += 1; - CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); -} - -cairo_bool_t -_cairo_atomic_int_dec_and_test (cairo_atomic_intptr_t *x) -{ - cairo_bool_t ret; - - CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); - ret = --*x == 0; - CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); - - return ret; -} - -cairo_atomic_intptr_t -_cairo_atomic_int_cmpxchg_return_old_impl (cairo_atomic_intptr_t *x, cairo_atomic_intptr_t oldv, cairo_atomic_intptr_t newv) -{ - cairo_atomic_intptr_t ret; - - CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); - ret = *x; - if (ret == oldv) - *x = newv; - CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); - - return ret; -} - -void * -_cairo_atomic_ptr_cmpxchg_return_old_impl (void **x, void *oldv, void *newv) -{ - void *ret; - - CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); - ret = *x; - if (ret == oldv) - *x = newv; - CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); - - return ret; -} - -#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER -cairo_atomic_intptr_t -_cairo_atomic_int_get (cairo_atomic_intptr_t *x) -{ - cairo_atomic_intptr_t ret; - - CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); - ret = *x; - CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); - - return ret; -} -#endif - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-backend-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-backend-private.h deleted file mode 100644 index b05eca59ab3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-backend-private.h +++ /dev/null @@ -1,201 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_BACKEND_PRIVATE_H -#define CAIRO_BACKEND_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-private.h" - -typedef enum _cairo_backend_type { - CAIRO_TYPE_DEFAULT, - CAIRO_TYPE_SKIA, -} cairo_backend_type_t; - -struct _cairo_backend { - cairo_backend_type_t type; - void (*destroy) (void *cr); - - cairo_surface_t *(*get_original_target) (void *cr); - cairo_surface_t *(*get_current_target) (void *cr); - - cairo_status_t (*save) (void *cr); - cairo_status_t (*restore) (void *cr); - - cairo_status_t (*push_group) (void *cr, cairo_content_t content); - cairo_pattern_t *(*pop_group) (void *cr); - - cairo_status_t (*set_source_rgba) (void *cr, double red, double green, double blue, double alpha); - cairo_status_t (*set_source_surface) (void *cr, cairo_surface_t *surface, double x, double y); - cairo_status_t (*set_source) (void *cr, cairo_pattern_t *source); - cairo_pattern_t *(*get_source) (void *cr); - - cairo_status_t (*set_antialias) (void *cr, cairo_antialias_t antialias); - cairo_status_t (*set_dash) (void *cr, const double *dashes, int num_dashes, double offset); - cairo_status_t (*set_fill_rule) (void *cr, cairo_fill_rule_t fill_rule); - cairo_status_t (*set_line_cap) (void *cr, cairo_line_cap_t line_cap); - cairo_status_t (*set_line_join) (void *cr, cairo_line_join_t line_join); - cairo_status_t (*set_line_width) (void *cr, double line_width); - cairo_status_t (*set_miter_limit) (void *cr, double limit); - cairo_status_t (*set_opacity) (void *cr, double opacity); - cairo_status_t (*set_operator) (void *cr, cairo_operator_t op); - cairo_status_t (*set_tolerance) (void *cr, double tolerance); - - cairo_antialias_t (*get_antialias) (void *cr); - void (*get_dash) (void *cr, double *dashes, int *num_dashes, double *offset); - cairo_fill_rule_t (*get_fill_rule) (void *cr); - cairo_line_cap_t (*get_line_cap) (void *cr); - cairo_line_join_t (*get_line_join) (void *cr); - double (*get_line_width) (void *cr); - double (*get_miter_limit) (void *cr); - double (*get_opacity) (void *cr); - cairo_operator_t (*get_operator) (void *cr); - double (*get_tolerance) (void *cr); - - cairo_status_t (*translate) (void *cr, double tx, double ty); - cairo_status_t (*scale) (void *cr, double sx, double sy); - cairo_status_t (*rotate) (void *cr, double theta); - cairo_status_t (*transform) (void *cr, const cairo_matrix_t *matrix); - cairo_status_t (*set_matrix) (void *cr, const cairo_matrix_t *matrix); - cairo_status_t (*set_identity_matrix) (void *cr); - void (*get_matrix) (void *cr, cairo_matrix_t *matrix); - - void (*user_to_device) (void *cr, double *x, double *y); - void (*user_to_device_distance) (void *cr, double *x, double *y); - void (*device_to_user) (void *cr, double *x, double *y); - void (*device_to_user_distance) (void *cr, double *x, double *y); - - void (*user_to_backend) (void *cr, double *x, double *y); - void (*user_to_backend_distance) (void *cr, double *x, double *y); - void (*backend_to_user) (void *cr, double *x, double *y); - void (*backend_to_user_distance) (void *cr, double *x, double *y); - - cairo_status_t (*new_path) (void *cr); - cairo_status_t (*new_sub_path) (void *cr); - cairo_status_t (*move_to) (void *cr, double x, double y); - cairo_status_t (*rel_move_to) (void *cr, double dx, double dy); - cairo_status_t (*line_to) (void *cr, double x, double y); - cairo_status_t (*rel_line_to) (void *cr, double dx, double dy); - cairo_status_t (*curve_to) (void *cr, double x1, double y1, double x2, double y2, double x3, double y3); - cairo_status_t (*rel_curve_to) (void *cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3); - cairo_status_t (*arc_to) (void *cr, double x1, double y1, double x2, double y2, double radius); - cairo_status_t (*rel_arc_to) (void *cr, double dx1, double dy1, double dx2, double dy2, double radius); - cairo_status_t (*close_path) (void *cr); - - cairo_status_t (*arc) (void *cr, double xc, double yc, double radius, double angle1, double angle2, cairo_bool_t forward); - cairo_status_t (*rectangle) (void *cr, double x, double y, double width, double height); - - void (*path_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); - cairo_bool_t (*has_current_point) (void *cr); - cairo_bool_t (*get_current_point) (void *cr, double *x, double *y); - - cairo_path_t *(*copy_path) (void *cr); - cairo_path_t *(*copy_path_flat) (void *cr); - cairo_status_t (*append_path) (void *cr, const cairo_path_t *path); - - cairo_status_t (*stroke_to_path) (void *cr); - - cairo_status_t (*clip) (void *cr); - cairo_status_t (*clip_preserve) (void *cr); - cairo_status_t (*in_clip) (void *cr, double x, double y, cairo_bool_t *inside); - cairo_status_t (*clip_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); - cairo_status_t (*reset_clip) (void *cr); - cairo_rectangle_list_t *(*clip_copy_rectangle_list) (void *cr); - - cairo_status_t (*paint) (void *cr); - cairo_status_t (*paint_with_alpha) (void *cr, double opacity); - cairo_status_t (*mask) (void *cr, cairo_pattern_t *pattern); - - cairo_status_t (*stroke) (void *cr); - cairo_status_t (*stroke_preserve) (void *cr); - cairo_status_t (*in_stroke) (void *cr, double x, double y, cairo_bool_t *inside); - cairo_status_t (*stroke_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); - - cairo_status_t (*fill) (void *cr); - cairo_status_t (*fill_preserve) (void *cr); - cairo_status_t (*in_fill) (void *cr, double x, double y, cairo_bool_t *inside); - cairo_status_t (*fill_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); - - cairo_status_t (*set_font_face) (void *cr, cairo_font_face_t *font_face); - cairo_font_face_t *(*get_font_face) (void *cr); - cairo_status_t (*set_font_size) (void *cr, double size); - cairo_status_t (*set_font_matrix) (void *cr, const cairo_matrix_t *matrix); - void (*get_font_matrix) (void *cr, cairo_matrix_t *matrix); - cairo_status_t (*set_font_options) (void *cr, const cairo_font_options_t *options); - void (*get_font_options) (void *cr, cairo_font_options_t *options); - cairo_status_t (*set_scaled_font) (void *cr, cairo_scaled_font_t *scaled_font); - cairo_scaled_font_t *(*get_scaled_font) (void *cr); - cairo_status_t (*font_extents) (void *cr, cairo_font_extents_t *extents); - - cairo_status_t (*glyphs) (void *cr, - const cairo_glyph_t *glyphs, int num_glyphs, - cairo_glyph_text_info_t *info); - cairo_status_t (*glyph_path) (void *cr, - const cairo_glyph_t *glyphs, int num_glyphs); - - cairo_status_t (*glyph_extents) (void *cr, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents); - - cairo_status_t (*copy_page) (void *cr); - cairo_status_t (*show_page) (void *cr); -}; - -static inline void -_cairo_backend_to_user (cairo_t *cr, double *x, double *y) -{ - cr->backend->backend_to_user (cr, x, y); -} - -static inline void -_cairo_backend_to_user_distance (cairo_t *cr, double *x, double *y) -{ - cr->backend->backend_to_user_distance (cr, x, y); -} - -static inline void -_cairo_user_to_backend (cairo_t *cr, double *x, double *y) -{ - cr->backend->user_to_backend (cr, x, y); -} - -static inline void -_cairo_user_to_backend_distance (cairo_t *cr, double *x, double *y) -{ - cr->backend->user_to_backend_distance (cr, x, y); -} - -#endif /* CAIRO_BACKEND_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-base64-stream.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-base64-stream.c deleted file mode 100644 index 636431372b5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-base64-stream.c +++ /dev/null @@ -1,144 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005-2007 Emmanuel Pacaud - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Author(s): - * Kristian Høgsberg - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-error-private.h" -#include "cairo-output-stream-private.h" - -typedef struct _cairo_base64_stream { - cairo_output_stream_t base; - cairo_output_stream_t *output; - unsigned int in_mem; - unsigned int trailing; - unsigned char src[3]; -} cairo_base64_stream_t; - -static char const base64_table[64] = -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -static cairo_status_t -_cairo_base64_stream_write (cairo_output_stream_t *base, - const unsigned char *data, - unsigned int length) -{ - cairo_base64_stream_t * stream = (cairo_base64_stream_t *) base; - unsigned char *src = stream->src; - unsigned int i; - - if (stream->in_mem + length < 3) { - for (i = 0; i < length; i++) { - src[i + stream->in_mem] = *data++; - } - stream->in_mem += length; - return CAIRO_STATUS_SUCCESS; - } - - do { - unsigned char dst[4]; - - for (i = stream->in_mem; i < 3; i++) { - src[i] = *data++; - length--; - } - stream->in_mem = 0; - - dst[0] = base64_table[src[0] >> 2]; - dst[1] = base64_table[(src[0] & 0x03) << 4 | src[1] >> 4]; - dst[2] = base64_table[(src[1] & 0x0f) << 2 | src[2] >> 6]; - dst[3] = base64_table[src[2] & 0xfc >> 2]; - /* Special case for the last missing bits */ - switch (stream->trailing) { - case 2: - dst[2] = '='; - case 1: - dst[3] = '='; - default: - break; - } - _cairo_output_stream_write (stream->output, dst, 4); - } while (length >= 3); - - for (i = 0; i < length; i++) { - src[i] = *data++; - } - stream->in_mem = length; - - return _cairo_output_stream_get_status (stream->output); -} - -static cairo_status_t -_cairo_base64_stream_close (cairo_output_stream_t *base) -{ - cairo_base64_stream_t *stream = (cairo_base64_stream_t *) base; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - if (stream->in_mem > 0) { - memset (stream->src + stream->in_mem, 0, 3 - stream->in_mem); - stream->trailing = 3 - stream->in_mem; - stream->in_mem = 3; - status = _cairo_base64_stream_write (base, NULL, 0); - } - - return status; -} - -cairo_output_stream_t * -_cairo_base64_stream_create (cairo_output_stream_t *output) -{ - cairo_base64_stream_t *stream; - - if (output->status) - return _cairo_output_stream_create_in_error (output->status); - - stream = malloc (sizeof (cairo_base64_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - _cairo_base64_stream_write, - NULL, - _cairo_base64_stream_close); - - stream->output = output; - stream->in_mem = 0; - stream->trailing = 0; - - return &stream->base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-base85-stream.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-base85-stream.c deleted file mode 100644 index f81affb49ea..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-base85-stream.c +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Author(s): - * Kristian Høgsberg - */ - -#include "cairoint.h" -#include "cairo-error-private.h" -#include "cairo-output-stream-private.h" - -typedef struct _cairo_base85_stream { - cairo_output_stream_t base; - cairo_output_stream_t *output; - unsigned char four_tuple[4]; - int pending; -} cairo_base85_stream_t; - -static void -_expand_four_tuple_to_five (unsigned char four_tuple[4], - unsigned char five_tuple[5], - cairo_bool_t *all_zero) -{ - uint32_t value; - int digit, i; - - value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3]; - if (all_zero) - *all_zero = TRUE; - for (i = 0; i < 5; i++) { - digit = value % 85; - if (digit != 0 && all_zero) - *all_zero = FALSE; - five_tuple[4-i] = digit + 33; - value = value / 85; - } -} - -static cairo_status_t -_cairo_base85_stream_write (cairo_output_stream_t *base, - const unsigned char *data, - unsigned int length) -{ - cairo_base85_stream_t *stream = (cairo_base85_stream_t *) base; - const unsigned char *ptr = data; - unsigned char five_tuple[5]; - cairo_bool_t is_zero; - - while (length) { - stream->four_tuple[stream->pending++] = *ptr++; - length--; - if (stream->pending == 4) { - _expand_four_tuple_to_five (stream->four_tuple, five_tuple, &is_zero); - if (is_zero) - _cairo_output_stream_write (stream->output, "z", 1); - else - _cairo_output_stream_write (stream->output, five_tuple, 5); - stream->pending = 0; - } - } - - return _cairo_output_stream_get_status (stream->output); -} - -static cairo_status_t -_cairo_base85_stream_close (cairo_output_stream_t *base) -{ - cairo_base85_stream_t *stream = (cairo_base85_stream_t *) base; - unsigned char five_tuple[5]; - - if (stream->pending) { - memset (stream->four_tuple + stream->pending, 0, 4 - stream->pending); - _expand_four_tuple_to_five (stream->four_tuple, five_tuple, NULL); - _cairo_output_stream_write (stream->output, five_tuple, stream->pending + 1); - } - - return _cairo_output_stream_get_status (stream->output); -} - -cairo_output_stream_t * -_cairo_base85_stream_create (cairo_output_stream_t *output) -{ - cairo_base85_stream_t *stream; - - if (output->status) - return _cairo_output_stream_create_in_error (output->status); - - stream = malloc (sizeof (cairo_base85_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - _cairo_base85_stream_write, - NULL, - _cairo_base85_stream_close); - stream->output = output; - stream->pending = 0; - - return &stream->base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectangular.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectangular.c deleted file mode 100644 index 5541bdc3a2d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectangular.c +++ /dev/null @@ -1,884 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-combsort-inline.h" -#include "cairo-list-private.h" -#include "cairo-traps-private.h" - -#include - -typedef struct _rectangle rectangle_t; -typedef struct _edge edge_t; - -struct _edge { - edge_t *next, *prev; - edge_t *right; - cairo_fixed_t x, top; - int dir; -}; - -struct _rectangle { - edge_t left, right; - int32_t top, bottom; -}; - -#define UNROLL3(x) x x x - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef struct _sweep_line { - rectangle_t **rectangles; - rectangle_t **stop; - edge_t head, tail, *insert, *cursor; - int32_t current_y; - int32_t last_y; - int stop_size; - - int32_t insert_x; - cairo_fill_rule_t fill_rule; - - cairo_bool_t do_traps; - void *container; - - jmp_buf unwind; -} sweep_line_t; - -#define DEBUG_TRAPS 0 - -#if DEBUG_TRAPS -static void -dump_traps (cairo_traps_t *traps, const char *filename) -{ - FILE *file; - int n; - - if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) - return; - - file = fopen (filename, "a"); - if (file != NULL) { - for (n = 0; n < traps->num_traps; n++) { - fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", - traps->traps[n].top, - traps->traps[n].bottom, - traps->traps[n].left.p1.x, - traps->traps[n].left.p1.y, - traps->traps[n].left.p2.x, - traps->traps[n].left.p2.y, - traps->traps[n].right.p1.x, - traps->traps[n].right.p1.y, - traps->traps[n].right.p2.x, - traps->traps[n].right.p2.y); - } - fprintf (file, "\n"); - fclose (file); - } -} -#else -#define dump_traps(traps, filename) -#endif - -static inline int -rectangle_compare_start (const rectangle_t *a, - const rectangle_t *b) -{ - return a->top - b->top; -} - -static inline int -rectangle_compare_stop (const rectangle_t *a, - const rectangle_t *b) -{ - return a->bottom - b->bottom; -} - -static inline void -pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle) -{ - rectangle_t **elements; - int i, parent; - - elements = sweep->stop; - for (i = ++sweep->stop_size; - i != PQ_FIRST_ENTRY && - rectangle_compare_stop (rectangle, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = rectangle; -} - -static inline void -rectangle_pop_stop (sweep_line_t *sweep) -{ - rectangle_t **elements = sweep->stop; - rectangle_t *tail; - int child, i; - - tail = elements[sweep->stop_size--]; - if (sweep->stop_size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= sweep->stop_size; - i = child) - { - if (child != sweep->stop_size && - rectangle_compare_stop (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (rectangle_compare_stop (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline rectangle_t * -rectangle_pop_start (sweep_line_t *sweep_line) -{ - return *sweep_line->rectangles++; -} - -static inline rectangle_t * -rectangle_peek_stop (sweep_line_t *sweep_line) -{ - return sweep_line->stop[PQ_FIRST_ENTRY]; -} - -CAIRO_COMBSORT_DECLARE (_rectangle_sort, - rectangle_t *, - rectangle_compare_start) - -static void -sweep_line_init (sweep_line_t *sweep_line, - rectangle_t **rectangles, - int num_rectangles, - cairo_fill_rule_t fill_rule, - cairo_bool_t do_traps, - void *container) -{ - rectangles[-2] = NULL; - rectangles[-1] = NULL; - rectangles[num_rectangles] = NULL; - sweep_line->rectangles = rectangles; - sweep_line->stop = rectangles - 2; - sweep_line->stop_size = 0; - - sweep_line->insert = NULL; - sweep_line->insert_x = INT_MAX; - sweep_line->cursor = &sweep_line->tail; - - sweep_line->head.dir = 0; - sweep_line->head.x = INT32_MIN; - sweep_line->head.right = NULL; - sweep_line->head.prev = NULL; - sweep_line->head.next = &sweep_line->tail; - sweep_line->tail.prev = &sweep_line->head; - sweep_line->tail.next = NULL; - sweep_line->tail.right = NULL; - sweep_line->tail.x = INT32_MAX; - sweep_line->tail.dir = 0; - - sweep_line->current_y = INT32_MIN; - sweep_line->last_y = INT32_MIN; - - sweep_line->fill_rule = fill_rule; - sweep_line->container = container; - sweep_line->do_traps = do_traps; -} - -static void -edge_end_box (sweep_line_t *sweep_line, edge_t *left, int32_t bot) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - /* Only emit (trivial) non-degenerate trapezoids with positive height. */ - if (likely (left->top < bot)) { - if (sweep_line->do_traps) { - cairo_line_t _left = { - { left->x, left->top }, - { left->x, bot }, - }, _right = { - { left->right->x, left->top }, - { left->right->x, bot }, - }; - _cairo_traps_add_trap (sweep_line->container, left->top, bot, &_left, &_right); - status = _cairo_traps_status ((cairo_traps_t *) sweep_line->container); - } else { - cairo_box_t box; - - box.p1.x = left->x; - box.p1.y = left->top; - box.p2.x = left->right->x; - box.p2.y = bot; - - status = _cairo_boxes_add (sweep_line->container, - CAIRO_ANTIALIAS_DEFAULT, - &box); - } - } - if (unlikely (status)) - longjmp (sweep_line->unwind, status); - - left->right = NULL; -} - -/* Start a new trapezoid at the given top y coordinate, whose edges - * are `edge' and `edge->next'. If `edge' already has a trapezoid, - * then either add it to the traps in `traps', if the trapezoid's - * right edge differs from `edge->next', or do nothing if the new - * trapezoid would be a continuation of the existing one. */ -static inline void -edge_start_or_continue_box (sweep_line_t *sweep_line, - edge_t *left, - edge_t *right, - int top) -{ - if (left->right == right) - return; - - if (left->right != NULL) { - if (left->right->x == right->x) { - /* continuation on right, so just swap edges */ - left->right = right; - return; - } - - edge_end_box (sweep_line, left, top); - } - - if (left->x != right->x) { - left->top = top; - left->right = right; - } -} -/* - * Merge two sorted edge lists. - * Input: - * - head_a: The head of the first list. - * - head_b: The head of the second list; head_b cannot be NULL. - * Output: - * Returns the head of the merged list. - * - * Implementation notes: - * To make it fast (in particular, to reduce to an insertion sort whenever - * one of the two input lists only has a single element) we iterate through - * a list until its head becomes greater than the head of the other list, - * then we switch their roles. As soon as one of the two lists is empty, we - * just attach the other one to the current list and exit. - * Writes to memory are only needed to "switch" lists (as it also requires - * attaching to the output list the list which we will be iterating next) and - * to attach the last non-empty list. - */ -static edge_t * -merge_sorted_edges (edge_t *head_a, edge_t *head_b) -{ - edge_t *head, *prev; - int32_t x; - - prev = head_a->prev; - if (head_a->x <= head_b->x) { - head = head_a; - } else { - head_b->prev = prev; - head = head_b; - goto start_with_b; - } - - do { - x = head_b->x; - while (head_a != NULL && head_a->x <= x) { - prev = head_a; - head_a = head_a->next; - } - - head_b->prev = prev; - prev->next = head_b; - if (head_a == NULL) - return head; - -start_with_b: - x = head_a->x; - while (head_b != NULL && head_b->x <= x) { - prev = head_b; - head_b = head_b->next; - } - - head_a->prev = prev; - prev->next = head_a; - if (head_b == NULL) - return head; - } while (1); -} - -/* - * Sort (part of) a list. - * Input: - * - list: The list to be sorted; list cannot be NULL. - * - limit: Recursion limit. - * Output: - * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the - * input list; if the input list has fewer elements, head_out be a sorted list - * containing all the elements of the input list. - * Returns the head of the list of unprocessed elements (NULL if the sorted list contains - * all the elements of the input list). - * - * Implementation notes: - * Special case single element list, unroll/inline the sorting of the first two elements. - * Some tail recursion is used since we iterate on the bottom-up solution of the problem - * (we start with a small sorted list and keep merging other lists of the same size to it). - */ -static edge_t * -sort_edges (edge_t *list, - unsigned int level, - edge_t **head_out) -{ - edge_t *head_other, *remaining; - unsigned int i; - - head_other = list->next; - - if (head_other == NULL) { - *head_out = list; - return NULL; - } - - remaining = head_other->next; - if (list->x <= head_other->x) { - *head_out = list; - head_other->next = NULL; - } else { - *head_out = head_other; - head_other->prev = list->prev; - head_other->next = list; - list->prev = head_other; - list->next = NULL; - } - - for (i = 0; i < level && remaining; i++) { - remaining = sort_edges (remaining, i, &head_other); - *head_out = merge_sorted_edges (*head_out, head_other); - } - - return remaining; -} - -static edge_t * -merge_unsorted_edges (edge_t *head, edge_t *unsorted) -{ - sort_edges (unsorted, UINT_MAX, &unsorted); - return merge_sorted_edges (head, unsorted); -} - -static void -active_edges_insert (sweep_line_t *sweep) -{ - edge_t *prev; - int x; - - x = sweep->insert_x; - prev = sweep->cursor; - if (prev->x > x) { - do { - prev = prev->prev; - } while (prev->x > x); - } else { - while (prev->next->x < x) - prev = prev->next; - } - - prev->next = merge_unsorted_edges (prev->next, sweep->insert); - sweep->cursor = sweep->insert; - sweep->insert = NULL; - sweep->insert_x = INT_MAX; -} - -static inline void -active_edges_to_traps (sweep_line_t *sweep) -{ - int top = sweep->current_y; - edge_t *pos; - - if (sweep->last_y == sweep->current_y) - return; - - if (sweep->insert) - active_edges_insert (sweep); - - pos = sweep->head.next; - if (pos == &sweep->tail) - return; - - if (sweep->fill_rule == CAIRO_FILL_RULE_WINDING) { - do { - edge_t *left, *right; - int winding; - - left = pos; - winding = left->dir; - - right = left->next; - - /* Check if there is a co-linear edge with an existing trap */ - while (right->x == left->x) { - if (right->right != NULL) { - assert (left->right == NULL); - /* continuation on left */ - left->top = right->top; - left->right = right->right; - right->right = NULL; - } - winding += right->dir; - right = right->next; - } - - if (winding == 0) { - if (left->right != NULL) - edge_end_box (sweep, left, top); - pos = right; - continue; - } - - do { - /* End all subsumed traps */ - if (unlikely (right->right != NULL)) - edge_end_box (sweep, right, top); - - /* Greedily search for the closing edge, so that we generate - * the * maximal span width with the minimal number of - * boxes. - */ - winding += right->dir; - if (winding == 0 && right->x != right->next->x) - break; - - right = right->next; - } while (TRUE); - - edge_start_or_continue_box (sweep, left, right, top); - - pos = right->next; - } while (pos != &sweep->tail); - } else { - do { - edge_t *right = pos->next; - int count = 0; - - do { - /* End all subsumed traps */ - if (unlikely (right->right != NULL)) - edge_end_box (sweep, right, top); - - /* skip co-linear edges */ - if (++count & 1 && right->x != right->next->x) - break; - - right = right->next; - } while (TRUE); - - edge_start_or_continue_box (sweep, pos, right, top); - - pos = right->next; - } while (pos != &sweep->tail); - } - - sweep->last_y = sweep->current_y; -} - -static inline void -sweep_line_delete_edge (sweep_line_t *sweep, edge_t *edge) -{ - if (edge->right != NULL) { - edge_t *next = edge->next; - if (next->x == edge->x) { - next->top = edge->top; - next->right = edge->right; - } else - edge_end_box (sweep, edge, sweep->current_y); - } - - if (sweep->cursor == edge) - sweep->cursor = edge->prev; - - edge->prev->next = edge->next; - edge->next->prev = edge->prev; -} - -static inline cairo_bool_t -sweep_line_delete (sweep_line_t *sweep, rectangle_t *rectangle) -{ - cairo_bool_t update; - - update = TRUE; - if (sweep->fill_rule == CAIRO_FILL_RULE_WINDING && - rectangle->left.prev->dir == rectangle->left.dir) - { - update = rectangle->left.next != &rectangle->right; - } - - sweep_line_delete_edge (sweep, &rectangle->left); - sweep_line_delete_edge (sweep, &rectangle->right); - - rectangle_pop_stop (sweep); - return update; -} - -static inline void -sweep_line_insert (sweep_line_t *sweep, rectangle_t *rectangle) -{ - if (sweep->insert) - sweep->insert->prev = &rectangle->right; - rectangle->right.next = sweep->insert; - rectangle->right.prev = &rectangle->left; - rectangle->left.next = &rectangle->right; - rectangle->left.prev = NULL; - sweep->insert = &rectangle->left; - if (rectangle->left.x < sweep->insert_x) - sweep->insert_x = rectangle->left.x; - - pqueue_push (sweep, rectangle); -} - -static cairo_status_t -_cairo_bentley_ottmann_tessellate_rectangular (rectangle_t **rectangles, - int num_rectangles, - cairo_fill_rule_t fill_rule, - cairo_bool_t do_traps, - void *container) -{ - sweep_line_t sweep_line; - rectangle_t *rectangle; - cairo_status_t status; - cairo_bool_t update = FALSE; - - sweep_line_init (&sweep_line, - rectangles, num_rectangles, - fill_rule, - do_traps, container); - if ((status = setjmp (sweep_line.unwind))) - return status; - - rectangle = rectangle_pop_start (&sweep_line); - do { - if (rectangle->top != sweep_line.current_y) { - rectangle_t *stop; - - stop = rectangle_peek_stop (&sweep_line); - while (stop != NULL && stop->bottom < rectangle->top) { - if (stop->bottom != sweep_line.current_y) { - if (update) { - active_edges_to_traps (&sweep_line); - update = FALSE; - } - - sweep_line.current_y = stop->bottom; - } - - update |= sweep_line_delete (&sweep_line, stop); - stop = rectangle_peek_stop (&sweep_line); - } - - if (update) { - active_edges_to_traps (&sweep_line); - update = FALSE; - } - - sweep_line.current_y = rectangle->top; - } - - do { - sweep_line_insert (&sweep_line, rectangle); - } while ((rectangle = rectangle_pop_start (&sweep_line)) != NULL && - sweep_line.current_y == rectangle->top); - update = TRUE; - } while (rectangle); - - while ((rectangle = rectangle_peek_stop (&sweep_line)) != NULL) { - if (rectangle->bottom != sweep_line.current_y) { - if (update) { - active_edges_to_traps (&sweep_line); - update = FALSE; - } - sweep_line.current_y = rectangle->bottom; - } - - update |= sweep_line_delete (&sweep_line, rectangle); - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_bentley_ottmann_tessellate_rectangular_traps (cairo_traps_t *traps, - cairo_fill_rule_t fill_rule) -{ - rectangle_t stack_rectangles[CAIRO_STACK_ARRAY_LENGTH (rectangle_t)]; - rectangle_t *stack_rectangles_ptrs[ARRAY_LENGTH (stack_rectangles) + 3]; - rectangle_t *rectangles, **rectangles_ptrs; - cairo_status_t status; - int i; - - if (unlikely (traps->num_traps <= 1)) - return CAIRO_STATUS_SUCCESS; - - assert (traps->is_rectangular); - - dump_traps (traps, "bo-rects-traps-in.txt"); - - rectangles = stack_rectangles; - rectangles_ptrs = stack_rectangles_ptrs; - if (traps->num_traps > ARRAY_LENGTH (stack_rectangles)) { - rectangles = _cairo_malloc_ab_plus_c (traps->num_traps, - sizeof (rectangle_t) + - sizeof (rectangle_t *), - 3*sizeof (rectangle_t *)); - if (unlikely (rectangles == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - rectangles_ptrs = (rectangle_t **) (rectangles + traps->num_traps); - } - - for (i = 0; i < traps->num_traps; i++) { - if (traps->traps[i].left.p1.x < traps->traps[i].right.p1.x) { - rectangles[i].left.x = traps->traps[i].left.p1.x; - rectangles[i].left.dir = 1; - - rectangles[i].right.x = traps->traps[i].right.p1.x; - rectangles[i].right.dir = -1; - } else { - rectangles[i].right.x = traps->traps[i].left.p1.x; - rectangles[i].right.dir = 1; - - rectangles[i].left.x = traps->traps[i].right.p1.x; - rectangles[i].left.dir = -1; - } - - rectangles[i].left.right = NULL; - rectangles[i].right.right = NULL; - - rectangles[i].top = traps->traps[i].top; - rectangles[i].bottom = traps->traps[i].bottom; - - rectangles_ptrs[i+2] = &rectangles[i]; - } - /* XXX incremental sort */ - _rectangle_sort (rectangles_ptrs+2, i); - - _cairo_traps_clear (traps); - status = _cairo_bentley_ottmann_tessellate_rectangular (rectangles_ptrs+2, i, - fill_rule, - TRUE, traps); - traps->is_rectilinear = TRUE; - traps->is_rectangular = TRUE; - - if (rectangles != stack_rectangles) - free (rectangles); - - dump_traps (traps, "bo-rects-traps-out.txt"); - - return status; -} - -cairo_status_t -_cairo_bentley_ottmann_tessellate_boxes (const cairo_boxes_t *in, - cairo_fill_rule_t fill_rule, - cairo_boxes_t *out) -{ - rectangle_t stack_rectangles[CAIRO_STACK_ARRAY_LENGTH (rectangle_t)]; - rectangle_t *stack_rectangles_ptrs[ARRAY_LENGTH (stack_rectangles) + 3]; - rectangle_t *rectangles, **rectangles_ptrs; - rectangle_t *stack_rectangles_chain[CAIRO_STACK_ARRAY_LENGTH (rectangle_t *) ]; - rectangle_t **rectangles_chain = NULL; - const struct _cairo_boxes_chunk *chunk; - cairo_status_t status; - int i, j, y_min, y_max; - - if (unlikely (in->num_boxes == 0)) { - _cairo_boxes_clear (out); - return CAIRO_STATUS_SUCCESS; - } - - if (in->num_boxes == 1) { - if (in == out) { - cairo_box_t *box = &in->chunks.base[0]; - - if (box->p1.x > box->p2.x) { - cairo_fixed_t tmp = box->p1.x; - box->p1.x = box->p2.x; - box->p2.x = tmp; - } - } else { - cairo_box_t box = in->chunks.base[0]; - - if (box.p1.x > box.p2.x) { - cairo_fixed_t tmp = box.p1.x; - box.p1.x = box.p2.x; - box.p2.x = tmp; - } - - _cairo_boxes_clear (out); - status = _cairo_boxes_add (out, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_STATUS_SUCCESS); - } - return CAIRO_STATUS_SUCCESS; - } - - y_min = INT_MAX; y_max = INT_MIN; - for (chunk = &in->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box = chunk->base; - for (i = 0; i < chunk->count; i++) { - if (box[i].p1.y < y_min) - y_min = box[i].p1.y; - if (box[i].p1.y > y_max) - y_max = box[i].p1.y; - } - } - y_min = _cairo_fixed_integer_floor (y_min); - y_max = _cairo_fixed_integer_floor (y_max) + 1; - y_max -= y_min; - - if (y_max < in->num_boxes) { - rectangles_chain = stack_rectangles_chain; - if (y_max > ARRAY_LENGTH (stack_rectangles_chain)) { - rectangles_chain = _cairo_malloc_ab (y_max, sizeof (rectangle_t *)); - if (unlikely (rectangles_chain == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - memset (rectangles_chain, 0, y_max * sizeof (rectangle_t*)); - } - - rectangles = stack_rectangles; - rectangles_ptrs = stack_rectangles_ptrs; - if (in->num_boxes > ARRAY_LENGTH (stack_rectangles)) { - rectangles = _cairo_malloc_ab_plus_c (in->num_boxes, - sizeof (rectangle_t) + - sizeof (rectangle_t *), - 3*sizeof (rectangle_t *)); - if (unlikely (rectangles == NULL)) { - if (rectangles_chain != stack_rectangles_chain) - free (rectangles_chain); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - rectangles_ptrs = (rectangle_t **) (rectangles + in->num_boxes); - } - - j = 0; - for (chunk = &in->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box = chunk->base; - for (i = 0; i < chunk->count; i++) { - int h; - - if (box[i].p1.x < box[i].p2.x) { - rectangles[j].left.x = box[i].p1.x; - rectangles[j].left.dir = 1; - - rectangles[j].right.x = box[i].p2.x; - rectangles[j].right.dir = -1; - } else { - rectangles[j].right.x = box[i].p1.x; - rectangles[j].right.dir = 1; - - rectangles[j].left.x = box[i].p2.x; - rectangles[j].left.dir = -1; - } - - rectangles[j].left.right = NULL; - rectangles[j].right.right = NULL; - - rectangles[j].top = box[i].p1.y; - rectangles[j].bottom = box[i].p2.y; - - if (rectangles_chain) { - h = _cairo_fixed_integer_floor (box[i].p1.y) - y_min; - rectangles[j].left.next = (edge_t *)rectangles_chain[h]; - rectangles_chain[h] = &rectangles[j]; - } else { - rectangles_ptrs[j+2] = &rectangles[j]; - } - j++; - } - } - - if (rectangles_chain) { - j = 2; - for (y_min = 0; y_min < y_max; y_min++) { - rectangle_t *r; - int start = j; - for (r = rectangles_chain[y_min]; r; r = (rectangle_t *)r->left.next) - rectangles_ptrs[j++] = r; - if (j > start + 1) - _rectangle_sort (rectangles_ptrs + start, j - start); - } - - if (rectangles_chain != stack_rectangles_chain) - free (rectangles_chain); - - j -= 2; - } else { - _rectangle_sort (rectangles_ptrs + 2, j); - } - - _cairo_boxes_clear (out); - status = _cairo_bentley_ottmann_tessellate_rectangular (rectangles_ptrs+2, j, - fill_rule, - FALSE, out); - if (rectangles != stack_rectangles) - free (rectangles); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectilinear.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectilinear.c deleted file mode 100644 index 7c0be69b712..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann-rectilinear.c +++ /dev/null @@ -1,600 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-boxes-private.h" -#include "cairo-combsort-inline.h" -#include "cairo-error-private.h" -#include "cairo-traps-private.h" - -typedef struct _cairo_bo_edge cairo_bo_edge_t; -typedef struct _cairo_bo_trap cairo_bo_trap_t; - -/* A deferred trapezoid of an edge */ -struct _cairo_bo_trap { - cairo_bo_edge_t *right; - int32_t top; -}; - -struct _cairo_bo_edge { - cairo_edge_t edge; - cairo_bo_edge_t *prev; - cairo_bo_edge_t *next; - cairo_bo_trap_t deferred_trap; -}; - -typedef enum { - CAIRO_BO_EVENT_TYPE_START, - CAIRO_BO_EVENT_TYPE_STOP -} cairo_bo_event_type_t; - -typedef struct _cairo_bo_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t *edge; -} cairo_bo_event_t; - -typedef struct _cairo_bo_sweep_line { - cairo_bo_event_t **events; - cairo_bo_edge_t *head; - cairo_bo_edge_t *stopped; - int32_t current_y; - cairo_bo_edge_t *current_edge; -} cairo_bo_sweep_line_t; - -static inline int -_cairo_point_compare (const cairo_point_t *a, - const cairo_point_t *b) -{ - int cmp; - - cmp = a->y - b->y; - if (likely (cmp)) - return cmp; - - return a->x - b->x; -} - -static inline int -_cairo_bo_edge_compare (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - int cmp; - - cmp = a->edge.line.p1.x - b->edge.line.p1.x; - if (likely (cmp)) - return cmp; - - return b->edge.bottom - a->edge.bottom; -} - -static inline int -cairo_bo_event_compare (const cairo_bo_event_t *a, - const cairo_bo_event_t *b) -{ - int cmp; - - cmp = _cairo_point_compare (&a->point, &b->point); - if (likely (cmp)) - return cmp; - - cmp = a->type - b->type; - if (cmp) - return cmp; - - return a - b; -} - -static inline cairo_bo_event_t * -_cairo_bo_event_dequeue (cairo_bo_sweep_line_t *sweep_line) -{ - return *sweep_line->events++; -} - -CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, - cairo_bo_event_t *, - cairo_bo_event_compare) - -static void -_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_event_t **events, - int num_events) -{ - _cairo_bo_event_queue_sort (events, num_events); - events[num_events] = NULL; - sweep_line->events = events; - - sweep_line->head = NULL; - sweep_line->current_y = INT32_MIN; - sweep_line->current_edge = NULL; -} - -static void -_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (sweep_line->current_edge != NULL) { - cairo_bo_edge_t *prev, *next; - int cmp; - - cmp = _cairo_bo_edge_compare (sweep_line->current_edge, edge); - if (cmp < 0) { - prev = sweep_line->current_edge; - next = prev->next; - while (next != NULL && _cairo_bo_edge_compare (next, edge) < 0) - prev = next, next = prev->next; - - prev->next = edge; - edge->prev = prev; - edge->next = next; - if (next != NULL) - next->prev = edge; - } else if (cmp > 0) { - next = sweep_line->current_edge; - prev = next->prev; - while (prev != NULL && _cairo_bo_edge_compare (prev, edge) > 0) - next = prev, prev = next->prev; - - next->prev = edge; - edge->next = next; - edge->prev = prev; - if (prev != NULL) - prev->next = edge; - else - sweep_line->head = edge; - } else { - prev = sweep_line->current_edge; - edge->prev = prev; - edge->next = prev->next; - if (prev->next != NULL) - prev->next->prev = edge; - prev->next = edge; - } - } else { - sweep_line->head = edge; - } - - sweep_line->current_edge = edge; -} - -static void -_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (edge->prev != NULL) - edge->prev->next = edge->next; - else - sweep_line->head = edge->next; - - if (edge->next != NULL) - edge->next->prev = edge->prev; - - if (sweep_line->current_edge == edge) - sweep_line->current_edge = edge->prev ? edge->prev : edge->next; -} - -static inline cairo_bool_t -edges_collinear (const cairo_bo_edge_t *a, const cairo_bo_edge_t *b) -{ - return a->edge.line.p1.x == b->edge.line.p1.x; -} - -static cairo_status_t -_cairo_bo_edge_end_trap (cairo_bo_edge_t *left, - int32_t bot, - cairo_bool_t do_traps, - void *container) -{ - cairo_bo_trap_t *trap = &left->deferred_trap; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - /* Only emit (trivial) non-degenerate trapezoids with positive height. */ - if (likely (trap->top < bot)) { - if (do_traps) { - _cairo_traps_add_trap (container, - trap->top, bot, - &left->edge.line, &trap->right->edge.line); - status = _cairo_traps_status ((cairo_traps_t *) container); - } else { - cairo_box_t box; - - box.p1.x = left->edge.line.p1.x; - box.p1.y = trap->top; - box.p2.x = trap->right->edge.line.p1.x; - box.p2.y = bot; - status = _cairo_boxes_add (container, CAIRO_ANTIALIAS_DEFAULT, &box); - } - } - - trap->right = NULL; - - return status; -} - -/* Start a new trapezoid at the given top y coordinate, whose edges - * are `edge' and `edge->next'. If `edge' already has a trapezoid, - * then either add it to the traps in `traps', if the trapezoid's - * right edge differs from `edge->next', or do nothing if the new - * trapezoid would be a continuation of the existing one. */ -static inline cairo_status_t -_cairo_bo_edge_start_or_continue_trap (cairo_bo_edge_t *left, - cairo_bo_edge_t *right, - int top, - cairo_bool_t do_traps, - void *container) -{ - cairo_status_t status; - - if (left->deferred_trap.right == right) - return CAIRO_STATUS_SUCCESS; - - if (left->deferred_trap.right != NULL) { - if (right != NULL && edges_collinear (left->deferred_trap.right, right)) - { - /* continuation on right, so just swap edges */ - left->deferred_trap.right = right; - return CAIRO_STATUS_SUCCESS; - } - - status = _cairo_bo_edge_end_trap (left, top, do_traps, container); - if (unlikely (status)) - return status; - } - - if (right != NULL && ! edges_collinear (left, right)) { - left->deferred_trap.top = top; - left->deferred_trap.right = right; - } - - return CAIRO_STATUS_SUCCESS; -} - -static inline cairo_status_t -_active_edges_to_traps (cairo_bo_edge_t *left, - int32_t top, - cairo_fill_rule_t fill_rule, - cairo_bool_t do_traps, - void *container) -{ - cairo_bo_edge_t *right; - cairo_status_t status; - - if (fill_rule == CAIRO_FILL_RULE_WINDING) { - while (left != NULL) { - int in_out; - - /* Greedily search for the closing edge, so that we generate the - * maximal span width with the minimal number of trapezoids. - */ - in_out = left->edge.dir; - - /* Check if there is a co-linear edge with an existing trap */ - right = left->next; - if (left->deferred_trap.right == NULL) { - while (right != NULL && right->deferred_trap.right == NULL) - right = right->next; - - if (right != NULL && edges_collinear (left, right)) { - /* continuation on left */ - left->deferred_trap = right->deferred_trap; - right->deferred_trap.right = NULL; - } - } - - /* End all subsumed traps */ - right = left->next; - while (right != NULL) { - if (right->deferred_trap.right != NULL) { - status = _cairo_bo_edge_end_trap (right, top, do_traps, container); - if (unlikely (status)) - return status; - } - - in_out += right->edge.dir; - if (in_out == 0) { - /* skip co-linear edges */ - if (right->next == NULL || - ! edges_collinear (right, right->next)) - { - break; - } - } - - right = right->next; - } - - status = _cairo_bo_edge_start_or_continue_trap (left, right, top, - do_traps, container); - if (unlikely (status)) - return status; - - left = right; - if (left != NULL) - left = left->next; - } - } else { - while (left != NULL) { - int in_out = 0; - - right = left->next; - while (right != NULL) { - if (right->deferred_trap.right != NULL) { - status = _cairo_bo_edge_end_trap (right, top, do_traps, container); - if (unlikely (status)) - return status; - } - - if ((in_out++ & 1) == 0) { - cairo_bo_edge_t *next; - cairo_bool_t skip = FALSE; - - /* skip co-linear edges */ - next = right->next; - if (next != NULL) - skip = edges_collinear (right, next); - - if (! skip) - break; - } - - right = right->next; - } - - status = _cairo_bo_edge_start_or_continue_trap (left, right, top, - do_traps, container); - if (unlikely (status)) - return status; - - left = right; - if (left != NULL) - left = left->next; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_bentley_ottmann_tessellate_rectilinear (cairo_bo_event_t **start_events, - int num_events, - cairo_fill_rule_t fill_rule, - cairo_bool_t do_traps, - void *container) -{ - cairo_bo_sweep_line_t sweep_line; - cairo_bo_event_t *event; - cairo_status_t status; - - _cairo_bo_sweep_line_init (&sweep_line, start_events, num_events); - - while ((event = _cairo_bo_event_dequeue (&sweep_line))) { - if (event->point.y != sweep_line.current_y) { - status = _active_edges_to_traps (sweep_line.head, - sweep_line.current_y, - fill_rule, do_traps, container); - if (unlikely (status)) - return status; - - sweep_line.current_y = event->point.y; - } - - switch (event->type) { - case CAIRO_BO_EVENT_TYPE_START: - _cairo_bo_sweep_line_insert (&sweep_line, event->edge); - break; - - case CAIRO_BO_EVENT_TYPE_STOP: - _cairo_bo_sweep_line_delete (&sweep_line, event->edge); - - if (event->edge->deferred_trap.right != NULL) { - status = _cairo_bo_edge_end_trap (event->edge, - sweep_line.current_y, - do_traps, container); - if (unlikely (status)) - return status; - } - - break; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (const cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_boxes_t *boxes) -{ - cairo_status_t status; - cairo_bo_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_event_t)]; - cairo_bo_event_t *events; - cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; - cairo_bo_event_t **event_ptrs; - cairo_bo_edge_t stack_edges[ARRAY_LENGTH (stack_events)]; - cairo_bo_edge_t *edges; - int num_events; - int i, j; - - if (unlikely (polygon->num_edges == 0)) - return CAIRO_STATUS_SUCCESS; - - num_events = 2 * polygon->num_edges; - - events = stack_events; - event_ptrs = stack_event_ptrs; - edges = stack_edges; - if (num_events > ARRAY_LENGTH (stack_events)) { - events = _cairo_malloc_ab_plus_c (num_events, - sizeof (cairo_bo_event_t) + - sizeof (cairo_bo_edge_t) + - sizeof (cairo_bo_event_t *), - sizeof (cairo_bo_event_t *)); - if (unlikely (events == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event_ptrs = (cairo_bo_event_t **) (events + num_events); - edges = (cairo_bo_edge_t *) (event_ptrs + num_events + 1); - } - - for (i = j = 0; i < polygon->num_edges; i++) { - edges[i].edge = polygon->edges[i]; - edges[i].deferred_trap.right = NULL; - edges[i].prev = NULL; - edges[i].next = NULL; - - event_ptrs[j] = &events[j]; - events[j].type = CAIRO_BO_EVENT_TYPE_START; - events[j].point.y = polygon->edges[i].top; - events[j].point.x = polygon->edges[i].line.p1.x; - events[j].edge = &edges[i]; - j++; - - event_ptrs[j] = &events[j]; - events[j].type = CAIRO_BO_EVENT_TYPE_STOP; - events[j].point.y = polygon->edges[i].bottom; - events[j].point.x = polygon->edges[i].line.p1.x; - events[j].edge = &edges[i]; - j++; - } - - status = _cairo_bentley_ottmann_tessellate_rectilinear (event_ptrs, j, - fill_rule, - FALSE, boxes); - if (events != stack_events) - free (events); - - return status; -} - -cairo_status_t -_cairo_bentley_ottmann_tessellate_rectilinear_traps (cairo_traps_t *traps, - cairo_fill_rule_t fill_rule) -{ - cairo_bo_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_event_t)]; - cairo_bo_event_t *events; - cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; - cairo_bo_event_t **event_ptrs; - cairo_bo_edge_t stack_edges[ARRAY_LENGTH (stack_events)]; - cairo_bo_edge_t *edges; - cairo_status_t status; - int i, j, k; - - if (unlikely (traps->num_traps == 0)) - return CAIRO_STATUS_SUCCESS; - - assert (traps->is_rectilinear); - - i = 4 * traps->num_traps; - - events = stack_events; - event_ptrs = stack_event_ptrs; - edges = stack_edges; - if (i > ARRAY_LENGTH (stack_events)) { - events = _cairo_malloc_ab_plus_c (i, - sizeof (cairo_bo_event_t) + - sizeof (cairo_bo_edge_t) + - sizeof (cairo_bo_event_t *), - sizeof (cairo_bo_event_t *)); - if (unlikely (events == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event_ptrs = (cairo_bo_event_t **) (events + i); - edges = (cairo_bo_edge_t *) (event_ptrs + i + 1); - } - - for (i = j = k = 0; i < traps->num_traps; i++) { - edges[k].edge.top = traps->traps[i].top; - edges[k].edge.bottom = traps->traps[i].bottom; - edges[k].edge.line = traps->traps[i].left; - edges[k].edge.dir = 1; - edges[k].deferred_trap.right = NULL; - edges[k].prev = NULL; - edges[k].next = NULL; - - event_ptrs[j] = &events[j]; - events[j].type = CAIRO_BO_EVENT_TYPE_START; - events[j].point.y = traps->traps[i].top; - events[j].point.x = traps->traps[i].left.p1.x; - events[j].edge = &edges[k]; - j++; - - event_ptrs[j] = &events[j]; - events[j].type = CAIRO_BO_EVENT_TYPE_STOP; - events[j].point.y = traps->traps[i].bottom; - events[j].point.x = traps->traps[i].left.p1.x; - events[j].edge = &edges[k]; - j++; - k++; - - edges[k].edge.top = traps->traps[i].top; - edges[k].edge.bottom = traps->traps[i].bottom; - edges[k].edge.line = traps->traps[i].right; - edges[k].edge.dir = -1; - edges[k].deferred_trap.right = NULL; - edges[k].prev = NULL; - edges[k].next = NULL; - - event_ptrs[j] = &events[j]; - events[j].type = CAIRO_BO_EVENT_TYPE_START; - events[j].point.y = traps->traps[i].top; - events[j].point.x = traps->traps[i].right.p1.x; - events[j].edge = &edges[k]; - j++; - - event_ptrs[j] = &events[j]; - events[j].type = CAIRO_BO_EVENT_TYPE_STOP; - events[j].point.y = traps->traps[i].bottom; - events[j].point.x = traps->traps[i].right.p1.x; - events[j].edge = &edges[k]; - j++; - k++; - } - - _cairo_traps_clear (traps); - status = _cairo_bentley_ottmann_tessellate_rectilinear (event_ptrs, j, - fill_rule, - TRUE, traps); - traps->is_rectilinear = TRUE; - - if (events != stack_events) - free (events); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann.c deleted file mode 100644 index 91e41f9c3cb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-bentley-ottmann.c +++ /dev/null @@ -1,1909 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-combsort-inline.h" -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" -#include "cairo-line-inline.h" -#include "cairo-traps-private.h" - -#define DEBUG_PRINT_STATE 0 -#define DEBUG_EVENTS 0 -#define DEBUG_TRAPS 0 - -typedef cairo_point_t cairo_bo_point32_t; - -typedef struct _cairo_bo_intersect_ordinate { - int32_t ordinate; - enum { EXACT, INEXACT } exactness; -} cairo_bo_intersect_ordinate_t; - -typedef struct _cairo_bo_intersect_point { - cairo_bo_intersect_ordinate_t x; - cairo_bo_intersect_ordinate_t y; -} cairo_bo_intersect_point_t; - -typedef struct _cairo_bo_edge cairo_bo_edge_t; -typedef struct _cairo_bo_trap cairo_bo_trap_t; - -/* A deferred trapezoid of an edge */ -struct _cairo_bo_trap { - cairo_bo_edge_t *right; - int32_t top; -}; - -struct _cairo_bo_edge { - cairo_edge_t edge; - cairo_bo_edge_t *prev; - cairo_bo_edge_t *next; - cairo_bo_edge_t *colinear; - cairo_bo_trap_t deferred_trap; -}; - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef enum { - CAIRO_BO_EVENT_TYPE_STOP, - CAIRO_BO_EVENT_TYPE_INTERSECTION, - CAIRO_BO_EVENT_TYPE_START -} cairo_bo_event_type_t; - -typedef struct _cairo_bo_event { - cairo_bo_event_type_t type; - cairo_point_t point; -} cairo_bo_event_t; - -typedef struct _cairo_bo_start_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t edge; -} cairo_bo_start_event_t; - -typedef struct _cairo_bo_queue_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t *e1; - cairo_bo_edge_t *e2; -} cairo_bo_queue_event_t; - -typedef struct _pqueue { - int size, max_size; - - cairo_bo_event_t **elements; - cairo_bo_event_t *elements_embedded[1024]; -} pqueue_t; - -typedef struct _cairo_bo_event_queue { - cairo_freepool_t pool; - pqueue_t pqueue; - cairo_bo_event_t **start_events; -} cairo_bo_event_queue_t; - -typedef struct _cairo_bo_sweep_line { - cairo_bo_edge_t *head; - cairo_bo_edge_t *stopped; - int32_t current_y; - cairo_bo_edge_t *current_edge; -} cairo_bo_sweep_line_t; - -#if DEBUG_TRAPS -static void -dump_traps (cairo_traps_t *traps, const char *filename) -{ - FILE *file; - cairo_box_t extents; - int n; - - if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) - return; - -#if 0 - if (traps->has_limits) { - printf ("%s: limits=(%d, %d, %d, %d)\n", - filename, - traps->limits.p1.x, traps->limits.p1.y, - traps->limits.p2.x, traps->limits.p2.y); - } -#endif - _cairo_traps_extents (traps, &extents); - printf ("%s: extents=(%d, %d, %d, %d)\n", - filename, - extents.p1.x, extents.p1.y, - extents.p2.x, extents.p2.y); - - file = fopen (filename, "a"); - if (file != NULL) { - for (n = 0; n < traps->num_traps; n++) { - fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", - traps->traps[n].top, - traps->traps[n].bottom, - traps->traps[n].left.p1.x, - traps->traps[n].left.p1.y, - traps->traps[n].left.p2.x, - traps->traps[n].left.p2.y, - traps->traps[n].right.p1.x, - traps->traps[n].right.p1.y, - traps->traps[n].right.p2.x, - traps->traps[n].right.p2.y); - } - fprintf (file, "\n"); - fclose (file); - } -} - -static void -dump_edges (cairo_bo_start_event_t *events, - int num_edges, - const char *filename) -{ - FILE *file; - int n; - - if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) - return; - - file = fopen (filename, "a"); - if (file != NULL) { - for (n = 0; n < num_edges; n++) { - fprintf (file, "(%d, %d), (%d, %d) %d %d %d\n", - events[n].edge.edge.line.p1.x, - events[n].edge.edge.line.p1.y, - events[n].edge.edge.line.p2.x, - events[n].edge.edge.line.p2.y, - events[n].edge.edge.top, - events[n].edge.edge.bottom, - events[n].edge.edge.dir); - } - fprintf (file, "\n"); - fclose (file); - } -} -#endif - -static cairo_fixed_t -_line_compute_intersection_x_for_y (const cairo_line_t *line, - cairo_fixed_t y) -{ - cairo_fixed_t x, dy; - - if (y == line->p1.y) - return line->p1.x; - if (y == line->p2.y) - return line->p2.x; - - x = line->p1.x; - dy = line->p2.y - line->p1.y; - if (dy != 0) { - x += _cairo_fixed_mul_div_floor (y - line->p1.y, - line->p2.x - line->p1.x, - dy); - } - - return x; -} - -static inline int -_cairo_bo_point32_compare (cairo_bo_point32_t const *a, - cairo_bo_point32_t const *b) -{ - int cmp; - - cmp = a->y - b->y; - if (cmp) - return cmp; - - return a->x - b->x; -} - -/* Compare the slope of a to the slope of b, returning 1, 0, -1 if the - * slope a is respectively greater than, equal to, or less than the - * slope of b. - * - * For each edge, consider the direction vector formed from: - * - * top -> bottom - * - * which is: - * - * (dx, dy) = (line.p2.x - line.p1.x, line.p2.y - line.p1.y) - * - * We then define the slope of each edge as dx/dy, (which is the - * inverse of the slope typically used in math instruction). We never - * compute a slope directly as the value approaches infinity, but we - * can derive a slope comparison without division as follows, (where - * the ? represents our compare operator). - * - * 1. slope(a) ? slope(b) - * 2. adx/ady ? bdx/bdy - * 3. (adx * bdy) ? (bdx * ady) - * - * Note that from step 2 to step 3 there is no change needed in the - * sign of the result since both ady and bdy are guaranteed to be - * greater than or equal to 0. - * - * When using this slope comparison to sort edges, some care is needed - * when interpreting the results. Since the slope compare operates on - * distance vectors from top to bottom it gives a correct left to - * right sort for edges that have a common top point, (such as two - * edges with start events at the same location). On the other hand, - * the sense of the result will be exactly reversed for two edges that - * have a common stop point. - */ -static inline int -_slope_compare (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t adx = a->edge.line.p2.x - a->edge.line.p1.x; - int32_t bdx = b->edge.line.p2.x - b->edge.line.p1.x; - - /* Since the dy's are all positive by construction we can fast - * path several common cases. - */ - - /* First check for vertical lines. */ - if (adx == 0) - return -bdx; - if (bdx == 0) - return adx; - - /* Then where the two edges point in different directions wrt x. */ - if ((adx ^ bdx) < 0) - return adx; - - /* Finally we actually need to do the general comparison. */ - { - int32_t ady = a->edge.line.p2.y - a->edge.line.p1.y; - int32_t bdy = b->edge.line.p2.y - b->edge.line.p1.y; - cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } -} - - -/* - * We need to compare the x-coordinate of a line for a particular y wrt to a - * given x, without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ X - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy (and (Y - A_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 64 bit arithmetic. - * - * See the similar discussion for _slope_compare() and - * edges_compare_x_for_y_general(). - */ -static int -edge_compare_for_y_against_x (const cairo_bo_edge_t *a, - int32_t y, - int32_t x) -{ - int32_t adx, ady; - int32_t dx, dy; - cairo_int64_t L, R; - - if (x < a->edge.line.p1.x && x < a->edge.line.p2.x) - return 1; - if (x > a->edge.line.p1.x && x > a->edge.line.p2.x) - return -1; - - adx = a->edge.line.p2.x - a->edge.line.p1.x; - dx = x - a->edge.line.p1.x; - - if (adx == 0) - return -dx; - if (dx == 0 || (adx ^ dx) < 0) - return adx; - - dy = y - a->edge.line.p1.y; - ady = a->edge.line.p2.y - a->edge.line.p1.y; - - L = _cairo_int32x32_64_mul (dy, adx); - R = _cairo_int32x32_64_mul (dx, ady); - - return _cairo_int64_cmp (L, R); -} - -static inline int -_cairo_bo_sweep_line_compare_edges (const cairo_bo_sweep_line_t *sweep_line, - const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - int cmp; - - cmp = cairo_lines_compare_at_y (&a->edge.line, - &b->edge.line, - sweep_line->current_y); - if (cmp) - return cmp; - - /* We've got two collinear edges now. */ - return b->edge.bottom - a->edge.bottom; -} - -static inline cairo_int64_t -det32_64 (int32_t a, int32_t b, - int32_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), - _cairo_int32x32_64_mul (b, c)); -} - -static inline cairo_int128_t -det64x32_128 (cairo_int64_t a, int32_t b, - cairo_int64_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), - _cairo_int64x32_128_mul (c, b)); -} - -/* Compute the intersection of two lines as defined by two edges. The - * result is provided as a coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or - * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. - */ -static cairo_bool_t -intersect_lines (cairo_bo_edge_t *a, - cairo_bo_edge_t *b, - cairo_bo_intersect_point_t *intersection) -{ - cairo_int64_t a_det, b_det; - - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm begins. - * What we're doing to mitigate this is to perform clamping in - * cairo_bo_tessellate_polygon(). - */ - int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; - int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; - - int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; - int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; - - cairo_int64_t den_det; - cairo_int64_t R; - cairo_quorem64_t qr; - - den_det = det32_64 (dx1, dy1, dx2, dy2); - - /* Q: Can we determine that the lines do not intersect (within range) - * much more cheaply than computing the intersection point i.e. by - * avoiding the division? - * - * X = ax + t * adx = bx + s * bdx; - * Y = ay + t * ady = by + s * bdy; - * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) - * => t * L = R - * - * Therefore we can reject any intersection (under the criteria for - * valid intersection events) if: - * L^R < 0 => t < 0, or - * L t > 1 - * - * (where top/bottom must at least extend to the line endpoints). - * - * A similar substitution can be performed for s, yielding: - * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) - */ - R = det32_64 (dx2, dy2, - b->edge.line.p1.x - a->edge.line.p1.x, - b->edge.line.p1.y - a->edge.line.p1.y); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - R = det32_64 (dy1, dx1, - a->edge.line.p1.y - b->edge.line.p1.y, - a->edge.line.p1.x - b->edge.line.p1.x); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - /* We now know that the two lines should intersect within range. */ - - a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, - a->edge.line.p2.x, a->edge.line.p2.y); - b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, - b->edge.line.p2.x, b->edge.line.p2.y); - - /* x = det (a_det, dx1, b_det, dx2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, - b_det, dx2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->x.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->x.exactness = INEXACT; - } -#endif - intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); - - /* y = det (a_det, dy1, b_det, dy2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, - b_det, dy2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->y.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->y.exactness = INEXACT; - } -#endif - intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); - - return TRUE; -} - -static int -_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t a, - int32_t b) -{ - /* First compare the quotient */ - if (a.ordinate > b) - return +1; - if (a.ordinate < b) - return -1; - /* With quotient identical, if remainder is 0 then compare equal */ - /* Otherwise, the non-zero remainder makes a > b */ - return INEXACT == a.exactness; -} - -/* Does the given edge contain the given point. The point must already - * be known to be contained within the line determined by the edge, - * (most likely the point results from an intersection of this edge - * with another). - * - * If we had exact arithmetic, then this function would simply be a - * matter of examining whether the y value of the point lies within - * the range of y values of the edge. But since intersection points - * are not exact due to being rounded to the nearest integer within - * the available precision, we must also examine the x value of the - * point. - * - * The definition of "contains" here is that the given intersection - * point will be seen by the sweep line after the start event for the - * given edge and before the stop event for the edge. See the comments - * in the implementation for more details. - */ -static cairo_bool_t -_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t *edge, - cairo_bo_intersect_point_t *point) -{ - int cmp_top, cmp_bottom; - - /* XXX: When running the actual algorithm, we don't actually need to - * compare against edge->top at all here, since any intersection above - * top is eliminated early via a slope comparison. We're leaving these - * here for now only for the sake of the quadratic-time intersection - * finder which needs them. - */ - - cmp_top = _cairo_bo_intersect_ordinate_32_compare (point->y, - edge->edge.top); - cmp_bottom = _cairo_bo_intersect_ordinate_32_compare (point->y, - edge->edge.bottom); - - if (cmp_top < 0 || cmp_bottom > 0) - { - return FALSE; - } - - if (cmp_top > 0 && cmp_bottom < 0) - { - return TRUE; - } - - /* At this stage, the point lies on the same y value as either - * edge->top or edge->bottom, so we have to examine the x value in - * order to properly determine containment. */ - - /* If the y value of the point is the same as the y value of the - * top of the edge, then the x value of the point must be greater - * to be considered as inside the edge. Similarly, if the y value - * of the point is the same as the y value of the bottom of the - * edge, then the x value of the point must be less to be - * considered as inside. */ - - if (cmp_top == 0) { - cairo_fixed_t top_x; - - top_x = _line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.top); - return _cairo_bo_intersect_ordinate_32_compare (point->x, top_x) > 0; - } else { /* cmp_bottom == 0 */ - cairo_fixed_t bot_x; - - bot_x = _line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.bottom); - return _cairo_bo_intersect_ordinate_32_compare (point->x, bot_x) < 0; - } -} - -/* Compute the intersection of two edges. The result is provided as a - * coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection - * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the - * intersection of the lines defined by the edges occurs outside of - * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges - * are exactly parallel. - * - * Note that when determining if a candidate intersection is "inside" - * an edge, we consider both the infinitesimal shortening and the - * infinitesimal tilt rules described by John Hobby. Specifically, if - * the intersection is exactly the same as an edge point, it is - * effectively outside (no intersection is returned). Also, if the - * intersection point has the same - */ -static cairo_bool_t -_cairo_bo_edge_intersect (cairo_bo_edge_t *a, - cairo_bo_edge_t *b, - cairo_bo_point32_t *intersection) -{ - cairo_bo_intersect_point_t quorem; - - if (! intersect_lines (a, b, &quorem)) - return FALSE; - - if (! _cairo_bo_edge_contains_intersect_point (a, &quorem)) - return FALSE; - - if (! _cairo_bo_edge_contains_intersect_point (b, &quorem)) - return FALSE; - - /* Now that we've correctly compared the intersection point and - * determined that it lies within the edge, then we know that we - * no longer need any more bits of storage for the intersection - * than we do for our edge coordinates. We also no longer need the - * remainder from the division. */ - intersection->x = quorem.x.ordinate; - intersection->y = quorem.y.ordinate; - - return TRUE; -} - -static inline int -cairo_bo_event_compare (const cairo_bo_event_t *a, - const cairo_bo_event_t *b) -{ - int cmp; - - cmp = _cairo_bo_point32_compare (&a->point, &b->point); - if (cmp) - return cmp; - - cmp = a->type - b->type; - if (cmp) - return cmp; - - return a - b; -} - -static inline void -_pqueue_init (pqueue_t *pq) -{ - pq->max_size = ARRAY_LENGTH (pq->elements_embedded); - pq->size = 0; - - pq->elements = pq->elements_embedded; -} - -static inline void -_pqueue_fini (pqueue_t *pq) -{ - if (pq->elements != pq->elements_embedded) - free (pq->elements); -} - -static cairo_status_t -_pqueue_grow (pqueue_t *pq) -{ - cairo_bo_event_t **new_elements; - pq->max_size *= 2; - - if (pq->elements == pq->elements_embedded) { - new_elements = _cairo_malloc_ab (pq->max_size, - sizeof (cairo_bo_event_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (new_elements, pq->elements_embedded, - sizeof (pq->elements_embedded)); - } else { - new_elements = _cairo_realloc_ab (pq->elements, - pq->max_size, - sizeof (cairo_bo_event_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pq->elements = new_elements; - return CAIRO_STATUS_SUCCESS; -} - -static inline cairo_status_t -_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event) -{ - cairo_bo_event_t **elements; - int i, parent; - - if (unlikely (pq->size + 1 == pq->max_size)) { - cairo_status_t status; - - status = _pqueue_grow (pq); - if (unlikely (status)) - return status; - } - - elements = pq->elements; - - for (i = ++pq->size; - i != PQ_FIRST_ENTRY && - cairo_bo_event_compare (event, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = event; - - return CAIRO_STATUS_SUCCESS; -} - -static inline void -_pqueue_pop (pqueue_t *pq) -{ - cairo_bo_event_t **elements = pq->elements; - cairo_bo_event_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - cairo_bo_event_compare (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (cairo_bo_event_compare (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline cairo_status_t -_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, - cairo_bo_event_type_t type, - cairo_bo_edge_t *e1, - cairo_bo_edge_t *e2, - const cairo_point_t *point) -{ - cairo_bo_queue_event_t *event; - - event = _cairo_freepool_alloc (&queue->pool); - if (unlikely (event == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event->type = type; - event->e1 = e1; - event->e2 = e2; - event->point = *point; - - return _pqueue_push (&queue->pqueue, (cairo_bo_event_t *) event); -} - -static void -_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue, - cairo_bo_event_t *event) -{ - _cairo_freepool_free (&queue->pool, event); -} - -static cairo_bo_event_t * -_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue) -{ - cairo_bo_event_t *event, *cmp; - - event = event_queue->pqueue.elements[PQ_FIRST_ENTRY]; - cmp = *event_queue->start_events; - if (event == NULL || - (cmp != NULL && cairo_bo_event_compare (cmp, event) < 0)) - { - event = cmp; - event_queue->start_events++; - } - else - { - _pqueue_pop (&event_queue->pqueue); - } - - return event; -} - -CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, - cairo_bo_event_t *, - cairo_bo_event_compare) - -static void -_cairo_bo_event_queue_init (cairo_bo_event_queue_t *event_queue, - cairo_bo_event_t **start_events, - int num_events) -{ - event_queue->start_events = start_events; - - _cairo_freepool_init (&event_queue->pool, - sizeof (cairo_bo_queue_event_t)); - _pqueue_init (&event_queue->pqueue); - event_queue->pqueue.elements[PQ_FIRST_ENTRY] = NULL; -} - -static cairo_status_t -_cairo_bo_event_queue_insert_stop (cairo_bo_event_queue_t *event_queue, - cairo_bo_edge_t *edge) -{ - cairo_bo_point32_t point; - - point.y = edge->edge.bottom; - point.x = _line_compute_intersection_x_for_y (&edge->edge.line, - point.y); - return _cairo_bo_event_queue_insert (event_queue, - CAIRO_BO_EVENT_TYPE_STOP, - edge, NULL, - &point); -} - -static void -_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) -{ - _pqueue_fini (&event_queue->pqueue); - _cairo_freepool_fini (&event_queue->pool); -} - -static inline cairo_status_t -_cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t *event_queue, - cairo_bo_edge_t *left, - cairo_bo_edge_t *right) -{ - cairo_bo_point32_t intersection; - - if (MAX (left->edge.line.p1.x, left->edge.line.p2.x) <= - MIN (right->edge.line.p1.x, right->edge.line.p2.x)) - return CAIRO_STATUS_SUCCESS; - - if (cairo_lines_equal (&left->edge.line, &right->edge.line)) - return CAIRO_STATUS_SUCCESS; - - /* The names "left" and "right" here are correct descriptions of - * the order of the two edges within the active edge list. So if a - * slope comparison also puts left less than right, then we know - * that the intersection of these two segments has already - * occurred before the current sweep line position. */ - if (_slope_compare (left, right) <= 0) - return CAIRO_STATUS_SUCCESS; - - if (! _cairo_bo_edge_intersect (left, right, &intersection)) - return CAIRO_STATUS_SUCCESS; - - return _cairo_bo_event_queue_insert (event_queue, - CAIRO_BO_EVENT_TYPE_INTERSECTION, - left, right, - &intersection); -} - -static void -_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line) -{ - sweep_line->head = NULL; - sweep_line->stopped = NULL; - sweep_line->current_y = INT32_MIN; - sweep_line->current_edge = NULL; -} - -static void -_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (sweep_line->current_edge != NULL) { - cairo_bo_edge_t *prev, *next; - int cmp; - - cmp = _cairo_bo_sweep_line_compare_edges (sweep_line, - sweep_line->current_edge, - edge); - if (cmp < 0) { - prev = sweep_line->current_edge; - next = prev->next; - while (next != NULL && - _cairo_bo_sweep_line_compare_edges (sweep_line, - next, edge) < 0) - { - prev = next, next = prev->next; - } - - prev->next = edge; - edge->prev = prev; - edge->next = next; - if (next != NULL) - next->prev = edge; - } else if (cmp > 0) { - next = sweep_line->current_edge; - prev = next->prev; - while (prev != NULL && - _cairo_bo_sweep_line_compare_edges (sweep_line, - prev, edge) > 0) - { - next = prev, prev = next->prev; - } - - next->prev = edge; - edge->next = next; - edge->prev = prev; - if (prev != NULL) - prev->next = edge; - else - sweep_line->head = edge; - } else { - prev = sweep_line->current_edge; - edge->prev = prev; - edge->next = prev->next; - if (prev->next != NULL) - prev->next->prev = edge; - prev->next = edge; - } - } else { - sweep_line->head = edge; - edge->next = NULL; - } - - sweep_line->current_edge = edge; -} - -static void -_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (edge->prev != NULL) - edge->prev->next = edge->next; - else - sweep_line->head = edge->next; - - if (edge->next != NULL) - edge->next->prev = edge->prev; - - if (sweep_line->current_edge == edge) - sweep_line->current_edge = edge->prev ? edge->prev : edge->next; -} - -static void -_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *left, - cairo_bo_edge_t *right) -{ - if (left->prev != NULL) - left->prev->next = right; - else - sweep_line->head = right; - - if (right->next != NULL) - right->next->prev = left; - - left->next = right->next; - right->next = left; - - right->prev = left->prev; - left->prev = right; -} - -#if DEBUG_PRINT_STATE -static void -_cairo_bo_edge_print (cairo_bo_edge_t *edge) -{ - printf ("(0x%x, 0x%x)-(0x%x, 0x%x)", - edge->edge.line.p1.x, edge->edge.line.p1.y, - edge->edge.line.p2.x, edge->edge.line.p2.y); -} - -static void -_cairo_bo_event_print (cairo_bo_event_t *event) -{ - switch (event->type) { - case CAIRO_BO_EVENT_TYPE_START: - printf ("Start: "); - break; - case CAIRO_BO_EVENT_TYPE_STOP: - printf ("Stop: "); - break; - case CAIRO_BO_EVENT_TYPE_INTERSECTION: - printf ("Intersection: "); - break; - } - printf ("(%d, %d)\t", event->point.x, event->point.y); - _cairo_bo_edge_print (event->e1); - if (event->type == CAIRO_BO_EVENT_TYPE_INTERSECTION) { - printf (" X "); - _cairo_bo_edge_print (event->e2); - } - printf ("\n"); -} - -static void -_cairo_bo_event_queue_print (cairo_bo_event_queue_t *event_queue) -{ - /* XXX: fixme to print the start/stop array too. */ - printf ("Event queue:\n"); -} - -static void -_cairo_bo_sweep_line_print (cairo_bo_sweep_line_t *sweep_line) -{ - cairo_bool_t first = TRUE; - cairo_bo_edge_t *edge; - - printf ("Sweep line from edge list: "); - first = TRUE; - for (edge = sweep_line->head; - edge; - edge = edge->next) - { - if (!first) - printf (", "); - _cairo_bo_edge_print (edge); - first = FALSE; - } - printf ("\n"); -} - -static void -print_state (const char *msg, - cairo_bo_event_t *event, - cairo_bo_event_queue_t *event_queue, - cairo_bo_sweep_line_t *sweep_line) -{ - printf ("%s ", msg); - _cairo_bo_event_print (event); - _cairo_bo_event_queue_print (event_queue); - _cairo_bo_sweep_line_print (sweep_line); - printf ("\n"); -} -#endif - -#if DEBUG_EVENTS -static void CAIRO_PRINTF_FORMAT (1, 2) -event_log (const char *fmt, ...) -{ - FILE *file; - - if (getenv ("CAIRO_DEBUG_EVENTS") == NULL) - return; - - file = fopen ("bo-events.txt", "a"); - if (file != NULL) { - va_list ap; - - va_start (ap, fmt); - vfprintf (file, fmt, ap); - va_end (ap); - - fclose (file); - } -} -#endif - -#define HAS_COLINEAR(a, b) ((cairo_bo_edge_t *)(((uintptr_t)(a))&~1) == (b)) -#define IS_COLINEAR(e) (((uintptr_t)(e))&1) -#define MARK_COLINEAR(e, v) ((cairo_bo_edge_t *)(((uintptr_t)(e))|(v))) - -static inline cairo_bool_t -edges_colinear (cairo_bo_edge_t *a, const cairo_bo_edge_t *b) -{ - unsigned p; - - if (HAS_COLINEAR(a->colinear, b)) - return IS_COLINEAR(a->colinear); - - if (HAS_COLINEAR(b->colinear, a)) { - p = IS_COLINEAR(b->colinear); - a->colinear = MARK_COLINEAR(b, p); - return p; - } - - p = 0; - p |= (a->edge.line.p1.x == b->edge.line.p1.x) << 0; - p |= (a->edge.line.p1.y == b->edge.line.p1.y) << 1; - p |= (a->edge.line.p2.x == b->edge.line.p2.x) << 3; - p |= (a->edge.line.p2.y == b->edge.line.p2.y) << 4; - if (p == ((1 << 0) | (1 << 1) | (1 << 3) | (1 << 4))) { - a->colinear = MARK_COLINEAR(b, 1); - return TRUE; - } - - if (_slope_compare (a, b)) { - a->colinear = MARK_COLINEAR(b, 0); - return FALSE; - } - - /* The choice of y is not truly arbitrary since we must guarantee that it - * is greater than the start of either line. - */ - if (p != 0) { - /* colinear if either end-point are coincident */ - p = (((p >> 1) & p) & 5) != 0; - } else if (a->edge.line.p1.y < b->edge.line.p1.y) { - p = edge_compare_for_y_against_x (b, - a->edge.line.p1.y, - a->edge.line.p1.x) == 0; - } else { - p = edge_compare_for_y_against_x (a, - b->edge.line.p1.y, - b->edge.line.p1.x) == 0; - } - - a->colinear = MARK_COLINEAR(b, p); - return p; -} - -/* Adds the trapezoid, if any, of the left edge to the #cairo_traps_t */ -static void -_cairo_bo_edge_end_trap (cairo_bo_edge_t *left, - int32_t bot, - cairo_traps_t *traps) -{ - cairo_bo_trap_t *trap = &left->deferred_trap; - - /* Only emit (trivial) non-degenerate trapezoids with positive height. */ - if (likely (trap->top < bot)) { - _cairo_traps_add_trap (traps, - trap->top, bot, - &left->edge.line, &trap->right->edge.line); - -#if DEBUG_PRINT_STATE - printf ("Deferred trap: left=(%x, %x)-(%x,%x) " - "right=(%x,%x)-(%x,%x) top=%x, bot=%x\n", - left->edge.line.p1.x, left->edge.line.p1.y, - left->edge.line.p2.x, left->edge.line.p2.y, - trap->right->edge.line.p1.x, trap->right->edge.line.p1.y, - trap->right->edge.line.p2.x, trap->right->edge.line.p2.y, - trap->top, bot); -#endif -#if DEBUG_EVENTS - event_log ("end trap: %lu %lu %d %d\n", - (long) left, - (long) trap->right, - trap->top, - bot); -#endif - } - - trap->right = NULL; -} - - -/* Start a new trapezoid at the given top y coordinate, whose edges - * are `edge' and `edge->next'. If `edge' already has a trapezoid, - * then either add it to the traps in `traps', if the trapezoid's - * right edge differs from `edge->next', or do nothing if the new - * trapezoid would be a continuation of the existing one. */ -static inline void -_cairo_bo_edge_start_or_continue_trap (cairo_bo_edge_t *left, - cairo_bo_edge_t *right, - int top, - cairo_traps_t *traps) -{ - if (left->deferred_trap.right == right) - return; - - assert (right); - if (left->deferred_trap.right != NULL) { - if (edges_colinear (left->deferred_trap.right, right)) - { - /* continuation on right, so just swap edges */ - left->deferred_trap.right = right; - return; - } - - _cairo_bo_edge_end_trap (left, top, traps); - } - - if (! edges_colinear (left, right)) { - left->deferred_trap.top = top; - left->deferred_trap.right = right; - -#if DEBUG_EVENTS - event_log ("begin trap: %lu %lu %d\n", - (long) left, - (long) right, - top); -#endif - } -} - -static inline void -_active_edges_to_traps (cairo_bo_edge_t *pos, - int32_t top, - unsigned mask, - cairo_traps_t *traps) -{ - cairo_bo_edge_t *left; - int in_out; - - -#if DEBUG_PRINT_STATE - printf ("Processing active edges for %x\n", top); -#endif - - in_out = 0; - left = pos; - while (pos != NULL) { - if (pos != left && pos->deferred_trap.right) { - /* XXX It shouldn't be possible to here with 2 deferred traps - * on colinear edges... See bug-bo-rictoz. - */ - if (left->deferred_trap.right == NULL && - edges_colinear (left, pos)) - { - /* continuation on left */ - left->deferred_trap = pos->deferred_trap; - pos->deferred_trap.right = NULL; - } - else - { - _cairo_bo_edge_end_trap (pos, top, traps); - } - } - - in_out += pos->edge.dir; - if ((in_out & mask) == 0) { - /* skip co-linear edges */ - if (pos->next == NULL || ! edges_colinear (pos, pos->next)) { - _cairo_bo_edge_start_or_continue_trap (left, pos, top, traps); - left = pos->next; - } - } - - pos = pos->next; - } -} - -/* Execute a single pass of the Bentley-Ottmann algorithm on edges, - * generating trapezoids according to the fill_rule and appending them - * to traps. */ -static cairo_status_t -_cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_event_t **start_events, - int num_events, - unsigned fill_rule, - cairo_traps_t *traps, - int *num_intersections) -{ - cairo_status_t status; - int intersection_count = 0; - cairo_bo_event_queue_t event_queue; - cairo_bo_sweep_line_t sweep_line; - cairo_bo_event_t *event; - cairo_bo_edge_t *left, *right; - cairo_bo_edge_t *e1, *e2; - - /* convert the fill_rule into a winding mask */ - if (fill_rule == CAIRO_FILL_RULE_WINDING) - fill_rule = (unsigned) -1; - else - fill_rule = 1; - -#if DEBUG_EVENTS - { - int i; - - for (i = 0; i < num_events; i++) { - cairo_bo_start_event_t *event = - ((cairo_bo_start_event_t **) start_events)[i]; - event_log ("edge: %lu (%d, %d) (%d, %d) (%d, %d) %d\n", - (long) &events[i].edge, - event->edge.edge.line.p1.x, - event->edge.edge.line.p1.y, - event->edge.edge.line.p2.x, - event->edge.edge.line.p2.y, - event->edge.top, - event->edge.bottom, - event->edge.edge.dir); - } - } -#endif - - _cairo_bo_event_queue_init (&event_queue, start_events, num_events); - _cairo_bo_sweep_line_init (&sweep_line); - - while ((event = _cairo_bo_event_dequeue (&event_queue))) { - if (event->point.y != sweep_line.current_y) { - for (e1 = sweep_line.stopped; e1; e1 = e1->next) { - if (e1->deferred_trap.right != NULL) { - _cairo_bo_edge_end_trap (e1, - e1->edge.bottom, - traps); - } - } - sweep_line.stopped = NULL; - - _active_edges_to_traps (sweep_line.head, - sweep_line.current_y, - fill_rule, traps); - - sweep_line.current_y = event->point.y; - } - -#if DEBUG_EVENTS - event_log ("event: %d (%ld, %ld) %lu, %lu\n", - event->type, - (long) event->point.x, - (long) event->point.y, - (long) event->e1, - (long) event->e2); -#endif - - switch (event->type) { - case CAIRO_BO_EVENT_TYPE_START: - e1 = &((cairo_bo_start_event_t *) event)->edge; - - _cairo_bo_sweep_line_insert (&sweep_line, e1); - - status = _cairo_bo_event_queue_insert_stop (&event_queue, e1); - if (unlikely (status)) - goto unwind; - - /* check to see if this is a continuation of a stopped edge */ - /* XXX change to an infinitesimal lengthening rule */ - for (left = sweep_line.stopped; left; left = left->next) { - if (e1->edge.top <= left->edge.bottom && - edges_colinear (e1, left)) - { - e1->deferred_trap = left->deferred_trap; - if (left->prev != NULL) - left->prev = left->next; - else - sweep_line.stopped = left->next; - if (left->next != NULL) - left->next->prev = left->prev; - break; - } - } - - left = e1->prev; - right = e1->next; - - if (left != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e1); - if (unlikely (status)) - goto unwind; - } - - if (right != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); - if (unlikely (status)) - goto unwind; - } - - break; - - case CAIRO_BO_EVENT_TYPE_STOP: - e1 = ((cairo_bo_queue_event_t *) event)->e1; - _cairo_bo_event_queue_delete (&event_queue, event); - - left = e1->prev; - right = e1->next; - - _cairo_bo_sweep_line_delete (&sweep_line, e1); - - /* first, check to see if we have a continuation via a fresh edge */ - if (e1->deferred_trap.right != NULL) { - e1->next = sweep_line.stopped; - if (sweep_line.stopped != NULL) - sweep_line.stopped->prev = e1; - sweep_line.stopped = e1; - e1->prev = NULL; - } - - if (left != NULL && right != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, right); - if (unlikely (status)) - goto unwind; - } - - break; - - case CAIRO_BO_EVENT_TYPE_INTERSECTION: - e1 = ((cairo_bo_queue_event_t *) event)->e1; - e2 = ((cairo_bo_queue_event_t *) event)->e2; - _cairo_bo_event_queue_delete (&event_queue, event); - - /* skip this intersection if its edges are not adjacent */ - if (e2 != e1->next) - break; - - intersection_count++; - - left = e1->prev; - right = e2->next; - - _cairo_bo_sweep_line_swap (&sweep_line, e1, e2); - - /* after the swap e2 is left of e1 */ - - if (left != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e2); - if (unlikely (status)) - goto unwind; - } - - if (right != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); - if (unlikely (status)) - goto unwind; - } - - break; - } - } - - *num_intersections = intersection_count; - for (e1 = sweep_line.stopped; e1; e1 = e1->next) { - if (e1->deferred_trap.right != NULL) { - _cairo_bo_edge_end_trap (e1, e1->edge.bottom, traps); - } - } - status = traps->status; - unwind: - _cairo_bo_event_queue_fini (&event_queue); - -#if DEBUG_EVENTS - event_log ("\n"); -#endif - - return status; -} - -cairo_status_t -_cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t *traps, - const cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule) -{ - int intersections; - cairo_bo_start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_start_event_t)]; - cairo_bo_start_event_t *events; - cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; - cairo_bo_event_t **event_ptrs; - cairo_bo_start_event_t *stack_event_y[64]; - cairo_bo_start_event_t **event_y = NULL; - int i, num_events, y, ymin, ymax; - cairo_status_t status; - - num_events = polygon->num_edges; - if (unlikely (0 == num_events)) - return CAIRO_STATUS_SUCCESS; - - if (polygon->num_limits) { - ymin = _cairo_fixed_integer_floor (polygon->limit.p1.y); - ymax = _cairo_fixed_integer_ceil (polygon->limit.p2.y) - ymin; - - if (ymax > 64) - event_y = _cairo_malloc_ab(sizeof (cairo_bo_event_t*), ymax); - else - event_y = stack_event_y; - memset (event_y, 0, ymax * sizeof(cairo_bo_event_t *)); - } - - events = stack_events; - event_ptrs = stack_event_ptrs; - if (num_events > ARRAY_LENGTH (stack_events)) { - events = _cairo_malloc_ab_plus_c (num_events, - sizeof (cairo_bo_start_event_t) + - sizeof (cairo_bo_event_t *), - sizeof (cairo_bo_event_t *)); - if (unlikely (events == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event_ptrs = (cairo_bo_event_t **) (events + num_events); - } - - for (i = 0; i < num_events; i++) { - events[i].type = CAIRO_BO_EVENT_TYPE_START; - events[i].point.y = polygon->edges[i].top; - events[i].point.x = - _line_compute_intersection_x_for_y (&polygon->edges[i].line, - events[i].point.y); - - events[i].edge.edge = polygon->edges[i]; - events[i].edge.deferred_trap.right = NULL; - events[i].edge.prev = NULL; - events[i].edge.next = NULL; - events[i].edge.colinear = NULL; - - if (event_y) { - y = _cairo_fixed_integer_floor (events[i].point.y) - ymin; - events[i].edge.next = (cairo_bo_edge_t *) event_y[y]; - event_y[y] = (cairo_bo_start_event_t *) &events[i]; - } else - event_ptrs[i] = (cairo_bo_event_t *) &events[i]; - } - - if (event_y) { - for (y = i = 0; y < ymax && i < num_events; y++) { - cairo_bo_start_event_t *e; - int j = i; - for (e = event_y[y]; e; e = (cairo_bo_start_event_t *)e->edge.next) - event_ptrs[i++] = (cairo_bo_event_t *) e; - if (i > j + 1) - _cairo_bo_event_queue_sort (event_ptrs+j, i-j); - } - if (event_y != stack_event_y) - free (event_y); - } else - _cairo_bo_event_queue_sort (event_ptrs, i); - event_ptrs[i] = NULL; - -#if DEBUG_TRAPS - dump_edges (events, num_events, "bo-polygon-edges.txt"); -#endif - - /* XXX: This would be the convenient place to throw in multiple - * passes of the Bentley-Ottmann algorithm. It would merely - * require storing the results of each pass into a temporary - * cairo_traps_t. */ - status = _cairo_bentley_ottmann_tessellate_bo_edges (event_ptrs, num_events, - fill_rule, traps, - &intersections); -#if DEBUG_TRAPS - dump_traps (traps, "bo-polygon-out.txt"); -#endif - - if (events != stack_events) - free (events); - - return status; -} - -cairo_status_t -_cairo_bentley_ottmann_tessellate_traps (cairo_traps_t *traps, - cairo_fill_rule_t fill_rule) -{ - cairo_status_t status; - cairo_polygon_t polygon; - int i; - - if (unlikely (0 == traps->num_traps)) - return CAIRO_STATUS_SUCCESS; - -#if DEBUG_TRAPS - dump_traps (traps, "bo-traps-in.txt"); -#endif - - _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); - - for (i = 0; i < traps->num_traps; i++) { - status = _cairo_polygon_add_line (&polygon, - &traps->traps[i].left, - traps->traps[i].top, - traps->traps[i].bottom, - 1); - if (unlikely (status)) - goto CLEANUP; - - status = _cairo_polygon_add_line (&polygon, - &traps->traps[i].right, - traps->traps[i].top, - traps->traps[i].bottom, - -1); - if (unlikely (status)) - goto CLEANUP; - } - - _cairo_traps_clear (traps); - status = _cairo_bentley_ottmann_tessellate_polygon (traps, - &polygon, - fill_rule); - -#if DEBUG_TRAPS - dump_traps (traps, "bo-traps-out.txt"); -#endif - - CLEANUP: - _cairo_polygon_fini (&polygon); - - return status; -} - -#if 0 -static cairo_bool_t -edges_have_an_intersection_quadratic (cairo_bo_edge_t *edges, - int num_edges) - -{ - int i, j; - cairo_bo_edge_t *a, *b; - cairo_bo_point32_t intersection; - - /* We must not be given any upside-down edges. */ - for (i = 0; i < num_edges; i++) { - assert (_cairo_bo_point32_compare (&edges[i].top, &edges[i].bottom) < 0); - edges[i].line.p1.x <<= CAIRO_BO_GUARD_BITS; - edges[i].line.p1.y <<= CAIRO_BO_GUARD_BITS; - edges[i].line.p2.x <<= CAIRO_BO_GUARD_BITS; - edges[i].line.p2.y <<= CAIRO_BO_GUARD_BITS; - } - - for (i = 0; i < num_edges; i++) { - for (j = 0; j < num_edges; j++) { - if (i == j) - continue; - - a = &edges[i]; - b = &edges[j]; - - if (! _cairo_bo_edge_intersect (a, b, &intersection)) - continue; - - printf ("Found intersection (%d,%d) between (%d,%d)-(%d,%d) and (%d,%d)-(%d,%d)\n", - intersection.x, - intersection.y, - a->line.p1.x, a->line.p1.y, - a->line.p2.x, a->line.p2.y, - b->line.p1.x, b->line.p1.y, - b->line.p2.x, b->line.p2.y); - - return TRUE; - } - } - return FALSE; -} - -#define TEST_MAX_EDGES 10 - -typedef struct test { - const char *name; - const char *description; - int num_edges; - cairo_bo_edge_t edges[TEST_MAX_EDGES]; -} test_t; - -static test_t -tests[] = { - { - "3 near misses", - "3 edges all intersecting very close to each other", - 3, - { - { { 4, 2}, {0, 0}, { 9, 9}, NULL, NULL }, - { { 7, 2}, {0, 0}, { 2, 3}, NULL, NULL }, - { { 5, 2}, {0, 0}, { 1, 7}, NULL, NULL } - } - }, - { - "inconsistent data", - "Derived from random testing---was leading to skip list and edge list disagreeing.", - 2, - { - { { 2, 3}, {0, 0}, { 8, 9}, NULL, NULL }, - { { 2, 3}, {0, 0}, { 6, 7}, NULL, NULL } - } - }, - { - "failed sort", - "A test derived from random testing that leads to an inconsistent sort --- looks like we just can't attempt to validate the sweep line with edge_compare?", - 3, - { - { { 6, 2}, {0, 0}, { 6, 5}, NULL, NULL }, - { { 3, 5}, {0, 0}, { 5, 6}, NULL, NULL }, - { { 9, 2}, {0, 0}, { 5, 6}, NULL, NULL }, - } - }, - { - "minimal-intersection", - "Intersection of a two from among the smallest possible edges.", - 2, - { - { { 0, 0}, {0, 0}, { 1, 1}, NULL, NULL }, - { { 1, 0}, {0, 0}, { 0, 1}, NULL, NULL } - } - }, - { - "simple", - "A simple intersection of two edges at an integer (2,2).", - 2, - { - { { 1, 1}, {0, 0}, { 3, 3}, NULL, NULL }, - { { 2, 1}, {0, 0}, { 2, 3}, NULL, NULL } - } - }, - { - "bend-to-horizontal", - "With intersection truncation one edge bends to horizontal", - 2, - { - { { 9, 1}, {0, 0}, {3, 7}, NULL, NULL }, - { { 3, 5}, {0, 0}, {9, 9}, NULL, NULL } - } - } -}; - -/* - { - "endpoint", - "An intersection that occurs at the endpoint of a segment.", - { - { { 4, 6}, { 5, 6}, NULL, { { NULL }} }, - { { 4, 5}, { 5, 7}, NULL, { { NULL }} }, - { { 0, 0}, { 0, 0}, NULL, { { NULL }} }, - } - } - { - name = "overlapping", - desc = "Parallel segments that share an endpoint, with different slopes.", - edges = { - { top = { x = 2, y = 0}, bottom = { x = 1, y = 1}}, - { top = { x = 2, y = 0}, bottom = { x = 0, y = 2}}, - { top = { x = 0, y = 3}, bottom = { x = 1, y = 3}}, - { top = { x = 0, y = 3}, bottom = { x = 2, y = 3}}, - { top = { x = 0, y = 4}, bottom = { x = 0, y = 6}}, - { top = { x = 0, y = 5}, bottom = { x = 0, y = 6}} - } - }, - { - name = "hobby_stage_3", - desc = "A particularly tricky part of the 3rd stage of the 'hobby' test below.", - edges = { - { top = { x = -1, y = -2}, bottom = { x = 4, y = 2}}, - { top = { x = 5, y = 3}, bottom = { x = 9, y = 5}}, - { top = { x = 5, y = 3}, bottom = { x = 6, y = 3}}, - } - }, - { - name = "hobby", - desc = "Example from John Hobby's paper. Requires 3 passes of the iterative algorithm.", - edges = { - { top = { x = 0, y = 0}, bottom = { x = 9, y = 5}}, - { top = { x = 0, y = 0}, bottom = { x = 13, y = 6}}, - { top = { x = -1, y = -2}, bottom = { x = 9, y = 5}} - } - }, - { - name = "slope", - desc = "Edges with same start/stop points but different slopes", - edges = { - { top = { x = 4, y = 1}, bottom = { x = 6, y = 3}}, - { top = { x = 4, y = 1}, bottom = { x = 2, y = 3}}, - { top = { x = 2, y = 4}, bottom = { x = 4, y = 6}}, - { top = { x = 6, y = 4}, bottom = { x = 4, y = 6}} - } - }, - { - name = "horizontal", - desc = "Test of a horizontal edge", - edges = { - { top = { x = 1, y = 1}, bottom = { x = 6, y = 6}}, - { top = { x = 2, y = 3}, bottom = { x = 5, y = 3}} - } - }, - { - name = "vertical", - desc = "Test of a vertical edge", - edges = { - { top = { x = 5, y = 1}, bottom = { x = 5, y = 7}}, - { top = { x = 2, y = 4}, bottom = { x = 8, y = 5}} - } - }, - { - name = "congruent", - desc = "Two overlapping edges with the same slope", - edges = { - { top = { x = 5, y = 1}, bottom = { x = 5, y = 7}}, - { top = { x = 5, y = 2}, bottom = { x = 5, y = 6}}, - { top = { x = 2, y = 4}, bottom = { x = 8, y = 5}} - } - }, - { - name = "multi", - desc = "Several segments with a common intersection point", - edges = { - { top = { x = 1, y = 2}, bottom = { x = 5, y = 4} }, - { top = { x = 1, y = 1}, bottom = { x = 5, y = 5} }, - { top = { x = 2, y = 1}, bottom = { x = 4, y = 5} }, - { top = { x = 4, y = 1}, bottom = { x = 2, y = 5} }, - { top = { x = 5, y = 1}, bottom = { x = 1, y = 5} }, - { top = { x = 5, y = 2}, bottom = { x = 1, y = 4} } - } - } -}; -*/ - -static int -run_test (const char *test_name, - cairo_bo_edge_t *test_edges, - int num_edges) -{ - int i, intersections, passes; - cairo_bo_edge_t *edges; - cairo_array_t intersected_edges; - - printf ("Testing: %s\n", test_name); - - _cairo_array_init (&intersected_edges, sizeof (cairo_bo_edge_t)); - - intersections = _cairo_bentley_ottmann_intersect_edges (test_edges, num_edges, &intersected_edges); - if (intersections) - printf ("Pass 1 found %d intersections:\n", intersections); - - - /* XXX: Multi-pass Bentley-Ottmmann. Preferable would be to add a - * pass of Hobby's tolerance-square algorithm instead. */ - passes = 1; - while (intersections) { - int num_edges = _cairo_array_num_elements (&intersected_edges); - passes++; - edges = _cairo_malloc_ab (num_edges, sizeof (cairo_bo_edge_t)); - assert (edges != NULL); - memcpy (edges, _cairo_array_index (&intersected_edges, 0), num_edges * sizeof (cairo_bo_edge_t)); - _cairo_array_fini (&intersected_edges); - _cairo_array_init (&intersected_edges, sizeof (cairo_bo_edge_t)); - intersections = _cairo_bentley_ottmann_intersect_edges (edges, num_edges, &intersected_edges); - free (edges); - - if (intersections){ - printf ("Pass %d found %d remaining intersections:\n", passes, intersections); - } else { - if (passes > 3) - for (i = 0; i < passes; i++) - printf ("*"); - printf ("No remainining intersections found after pass %d\n", passes); - } - } - - if (edges_have_an_intersection_quadratic (_cairo_array_index (&intersected_edges, 0), - _cairo_array_num_elements (&intersected_edges))) - printf ("*** FAIL ***\n"); - else - printf ("PASS\n"); - - _cairo_array_fini (&intersected_edges); - - return 0; -} - -#define MAX_RANDOM 300 - -int -main (void) -{ - char random_name[] = "random-XX"; - cairo_bo_edge_t random_edges[MAX_RANDOM], *edge; - unsigned int i, num_random; - test_t *test; - - for (i = 0; i < ARRAY_LENGTH (tests); i++) { - test = &tests[i]; - run_test (test->name, test->edges, test->num_edges); - } - - for (num_random = 0; num_random < MAX_RANDOM; num_random++) { - srand (0); - for (i = 0; i < num_random; i++) { - do { - edge = &random_edges[i]; - edge->line.p1.x = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); - edge->line.p1.y = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); - edge->line.p2.x = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); - edge->line.p2.y = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); - if (edge->line.p1.y > edge->line.p2.y) { - int32_t tmp = edge->line.p1.y; - edge->line.p1.y = edge->line.p2.y; - edge->line.p2.y = tmp; - } - } while (edge->line.p1.y == edge->line.p2.y); - } - - sprintf (random_name, "random-%02d", num_random); - - run_test (random_name, random_edges, num_random); - } - - return 0; -} -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos-surface.cpp b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos-surface.cpp deleted file mode 100644 index c97641685fc..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos-surface.cpp +++ /dev/null @@ -1,984 +0,0 @@ -/* vim:set ts=8 sw=4 noet cin: */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Christian Biesinger - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Christian Biesinger - * - * - * Contributor(s): - */ - -// This is a C++ file in order to use the C++ BeOS API - -#include "cairoint.h" - -#include "cairo-beos.h" - -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" - -#include - -#include -#include -#if 0 -#include -#endif -#include -#include -#include - -/** - * SECTION:beos-surface - * @Title: BeOS Surfaces - * @Short_Description: BeOS surface support - * @See_Also: #cairo_surface_t - * - * The BeOS surface is used to render cairo graphics to BeOS views - * and bitmaps. - **/ - -#define CAIRO_INT_STATUS_SUCCESS (cairo_int_status_t)(CAIRO_STATUS_SUCCESS) - -struct cairo_beos_surface_t { - cairo_surface_t base; - - cairo_region_t *clip_region; - - BView* view; - - /* - * A view is either attached to a bitmap, a window, or unattached. - * If it is attached to a window, we can copy data out of it using BScreen. - * If it is attached to a bitmap, we can read the bitmap data. - * If it is not attached, it doesn't draw anything, we need not bother. - * - * Since there doesn't seem to be a way to get the bitmap from a view if it - * is attached to one, we have to use a special surface creation function. - */ - - BBitmap* bitmap; - - // If true, surface and view should be deleted when this surface is - // destroyed - bool owns_bitmap_view; -}; - -class AutoLockView { - public: - AutoLockView(BView* view) : mView(view) { - mOK = mView->LockLooper(); - } - - ~AutoLockView() { - if (mOK) - mView->UnlockLooper(); - } - - operator bool() { - return mOK; - } - - private: - BView* mView; - bool mOK; -}; - -static cairo_surface_t * -_cairo_beos_surface_create_internal (BView* view, - BBitmap* bmp, - bool owns_bitmap_view = false); - -static inline BRect -_cairo_rectangle_to_brect (const cairo_rectangle_int_t* rect) -{ - // A BRect is one pixel wider than you'd think - return BRect (rect->x, rect->y, - rect->x + rect->width - 1, - rect->y + rect->height - 1); -} - -static inline cairo_rectangle_int_t -_brect_to_cairo_rectangle (const BRect &rect) -{ - cairo_rectangle_int_t retval; - retval.x = floor (rect.left); - retval.y = floor (rect.top); - retval.width = ceil (rect.right) - retval.x + 1; - retval.height = ceil (rect.bottom) - rectval.y + 1; - return retval; -} - -static inline rgb_color -_cairo_color_to_be_color (const cairo_color_t *color) -{ - // This factor ensures a uniform distribution of numbers - const float factor = 256 - 1e-5; - // Using doubles to have non-premultiplied colors - rgb_color be_color = { uint8(color->red * factor), - uint8(color->green * factor), - uint8(color->blue * factor), - uint8(color->alpha * factor) }; - - return be_color; -} - -enum ViewCopyStatus { - OK, - NOT_VISIBLE, // The view or the interest rect is not visible on screen - ERROR // The view was visible, but the rect could not be copied. Probably OOM -}; - -/** - * _cairo_beos_view_to_bitmap: - * @bitmap: [out] The resulting bitmap. - * @rect: [out] The rectangle that was copied, in the view's coordinate system - * @interestRect: If non-null, only this part of the view will be copied (view's coord system). - * - * Gets the contents of the view as a BBitmap*. Caller must delete the bitmap. - **/ -static ViewCopyStatus -_cairo_beos_view_to_bitmap (BView* view, - BBitmap** bitmap, - BRect* rect = NULL, - const BRect* interestRect = NULL) -{ - *bitmap = NULL; - - BWindow* wnd = view->Window(); - // If we have no window, can't do anything - if (!wnd) - return NOT_VISIBLE; - - view->Sync(); - wnd->Sync(); - -#if 0 - // Is it a direct window? - BDirectWindow* directWnd = dynamic_cast(wnd); - if (directWnd) { - // WRITEME - } -#endif - - // Is it visible? If so, we can copy the content off the screen - if (wnd->IsHidden()) - return NOT_VISIBLE; - - BRect rectToCopy(view->Bounds()); - if (interestRect) - rectToCopy = rectToCopy & *interestRect; - - if (!rectToCopy.IsValid()) - return NOT_VISIBLE; - - BScreen screen(wnd); - BRect screenRect(view->ConvertToScreen(rectToCopy)); - screenRect = screenRect & screen.Frame(); - - if (!screen.IsValid()) - return NOT_VISIBLE; - - if (rect) - *rect = view->ConvertFromScreen(screenRect); - - if (screen.GetBitmap(bitmap, false, &screenRect) == B_OK) - return OK; - - return ERROR; -} - -static void -unpremultiply_bgra (unsigned char* data, - int width, - int height, - int stride, - unsigned char* retdata) -{ - unsigned char* end = data + stride * height; - for (unsigned char* in = data, *out = retdata; - in < end; - in += stride, out += stride) - { - for (int i = 0; i < width; i ++) { - uint8_t *b = &out[4*i]; - uint32_t pixel; - uint8_t alpha; - - memcpy (&pixel, &data[4*i], sizeof (uint32_t)); - alpha = pixel & 0xff; - if (alpha == 0) { - b[0] = b[1] = b[2] = b[3] = 0; - } else { - b[0] = (((pixel >> 24) & 0xff) * 255 + alpha / 2) / alpha; - b[1] = (((pixel >> 16) & 0xff) * 255 + alpha / 2) / alpha; - b[2] = (((pixel >> 8) & 0xff) * 255 + alpha / 2) / alpha; - b[3] = alpha; - } - } - } -} - -static inline int -multiply_alpha (int alpha, int color) -{ - int temp = (alpha * color) + 0x80; - return ((temp + (temp >> 8)) >> 8); -} - -static unsigned char* -premultiply_bgra (unsigned char* data, - int width, - int height, - int stride) -{ - uint8_t * retdata = reinterpret_cast(_cairo_malloc_ab(height, stride)); - if (!retdata) - return NULL; - - uint8_t * end = data + stride * height; - for (uint8_t * in = data, *out = retdata; - in < end; - in += stride, out += stride) - { - for (int i = 0; i < width; i ++) { - uint8_t *base = &in[4*i]; - uint8_t alpha = base[3]; - uint32_t p; - - if (alpha == 0) { - p = 0; - } else { - uint8_t blue = base[0]; - uint8_t green = base[1]; - uint8_t red = base[2]; - - if (alpha != 0xff) { - blue = multiply_alpha (alpha, blue); - green = multiply_alpha (alpha, green); - red = multiply_alpha (alpha, red); - } - p = (alpha << 0) | (red << 8) | (green << 16) | (blue << 24); - } - memcpy (&out[4*i], &p, sizeof (uint32_t)); - } - } - return retdata; -} - -static cairo_int_status_t -_cairo_beos_surface_set_clip_region (cairo_beos_surface_t *surface, - cairo_region_t *region) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - AutoLockView locker(surface->view); - assert (locker); - - if (region == surface->clip_region) - return CAIRO_INT_STATUS_SUCCESS; - - cairo_region_destroy (surface->clip_region); - surface->clip_region = cairo_region_reference (region); - - if (region == NULL) { - // No clipping - surface->view->ConstrainClippingRegion(NULL); - return CAIRO_INT_STATUS_SUCCESS; - } - - int count = cairo_region_num_rectangles (region); - BRegion bregion; - for (int i = 0; i < count; ++i) { - cairo_rectangle_int_t rect; - - cairo_region_get_rectangle (region, i, &rect); - // Have to subtract one, because for pixman, the second coordinate - // lies outside the rectangle. - bregion.Include (_cairo_rectangle_to_brect (&rect)); - } - surface->view->ConstrainClippingRegion(&bregion); - return CAIRO_INT_STATUS_SUCCESS; -} - - -/** - * _cairo_beos_bitmap_to_surface: - * - * Returns an addrefed image surface for a BBitmap. The bitmap need not outlive - * the surface. - **/ -static cairo_image_surface_t* -_cairo_beos_bitmap_to_surface (BBitmap* bitmap) -{ - color_space format = bitmap->ColorSpace(); - if (format != B_RGB32 && format != B_RGBA32) { - BBitmap bmp(bitmap->Bounds(), B_RGB32, true); - BView view(bitmap->Bounds(), "Cairo bitmap drawing view", - B_FOLLOW_ALL_SIDES, 0); - bmp.AddChild(&view); - - view.LockLooper(); - - view.DrawBitmap(bitmap, BPoint(0.0, 0.0)); - view.Sync(); - - cairo_image_surface_t* imgsurf = _cairo_beos_bitmap_to_surface(&bmp); - - view.UnlockLooper(); - bmp.RemoveChild(&view); - return imgsurf; - } - - cairo_format_t cformat = format == B_RGB32 ? - CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32; - - BRect bounds(bitmap->Bounds()); - unsigned char* bits = reinterpret_cast(bitmap->Bits()); - int width = bounds.IntegerWidth() + 1; - int height = bounds.IntegerHeight() + 1; - unsigned char* premultiplied; - if (cformat == CAIRO_FORMAT_ARGB32) { - premultiplied = premultiply_bgra (bits, width, height, - bitmap->BytesPerRow()); - } else { - premultiplied = reinterpret_cast( - _cairo_malloc_ab(bitmap->BytesPerRow(), height)); - if (premultiplied) - memcpy(premultiplied, bits, bitmap->BytesPerRow() * height); - } - if (!premultiplied) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - cairo_image_surface_t* surf = reinterpret_cast - (cairo_image_surface_create_for_data(premultiplied, - cformat, - width, - height, - bitmap->BytesPerRow())); - if (surf->base.status) - free(premultiplied); - else - _cairo_image_surface_assume_ownership_of_data(surf); - return surf; -} - -/** - * _cairo_image_surface_to_bitmap: - * - * Converts an image surface to a BBitmap. The return value must be freed with - * delete. - **/ -static BBitmap* -_cairo_image_surface_to_bitmap (cairo_image_surface_t* surface) -{ - BRect size(0.0, 0.0, surface->width - 1, surface->height - 1); - switch (surface->format) { - case CAIRO_FORMAT_ARGB32: { - BBitmap* data = new BBitmap(size, B_RGBA32); - unpremultiply_bgra (surface->data, - surface->width, - surface->height, - surface->stride, - reinterpret_cast(data->Bits())); - return data; - } - case CAIRO_FORMAT_RGB24: { - BBitmap* data = new BBitmap(size, B_RGB32); - memcpy(data->Bits(), surface->data, surface->height * surface->stride); - return data; - } - default: - assert(0); - return NULL; - } -} - -/** - * _cairo_op_to_be_op: - * - * Converts a cairo drawing operator to a beos drawing_mode. Returns true if - * the operator could be converted, false otherwise. - **/ -static bool -_cairo_op_to_be_op (cairo_operator_t cairo_op, - drawing_mode* beos_op) -{ - switch (cairo_op) { - case CAIRO_OPERATOR_SOURCE: - *beos_op = B_OP_COPY; - return true; - case CAIRO_OPERATOR_OVER: - *beos_op = B_OP_ALPHA; - return true; - - case CAIRO_OPERATOR_ADD: - // Does not actually work - // XXX This is a fundamental compositing operator, it has to work! -#if 1 - return false; -#else - *beos_op = B_OP_ADD; - return true; -#endif - - case CAIRO_OPERATOR_CLEAR: - // Does not map to B_OP_ERASE - it replaces the dest with the low - // color, instead of transparency; could be done by setting low - // color appropriately. - - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_ATOP: - - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_DEST_ATOP: - - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_SATURATE: - - default: - return false; - } -} - -static cairo_surface_t * -_cairo_beos_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - - if (width <= 0) - width = 1; - if (height <= 0) - height = 1; - - BRect rect(0.0, 0.0, width - 1, height - 1); - BBitmap* bmp; - switch (content) { - case CAIRO_CONTENT_ALPHA: - return NULL; - case CAIRO_CONTENT_COLOR_ALPHA: - bmp = new BBitmap(rect, B_RGBA32, true); - break; - case CAIRO_CONTENT_COLOR: - // Match the color depth - if (surface->bitmap) { - color_space space = surface->bitmap->ColorSpace(); - // No alpha was requested -> make sure not to return - // a surface with alpha - if (space == B_RGBA32) - space = B_RGB32; - if (space == B_RGBA15) - space = B_RGB15; - bmp = new BBitmap(rect, space, true); - } else { - BScreen scr(surface->view->Window()); - color_space space = B_RGB32; - if (scr.IsValid()) - space = scr.ColorSpace(); - bmp = new BBitmap(rect, space, true); - } - break; - default: - ASSERT_NOT_REACHED; - return NULL; - } - BView* view = new BView(rect, "Cairo bitmap view", B_FOLLOW_ALL_SIDES, 0); - bmp->AddChild(view); - return _cairo_beos_surface_create_internal(view, bmp, true); -} - -static cairo_status_t -_cairo_beos_surface_finish (void *abstract_surface) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - if (surface->owns_bitmap_view) { - if (surface->bitmap) - surface->bitmap->RemoveChild(surface->view); - - delete surface->view; - delete surface->bitmap; - - surface->view = NULL; - surface->bitmap = NULL; - } - - cairo_region_destroy (surface->clip_region); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_beos_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - AutoLockView locker(surface->view); - if (!locker) - return CAIRO_STATUS_NO_MEMORY; /// XXX not exactly right, but what can we do? - - - surface->view->Sync(); - - if (surface->bitmap) { - *image_out = _cairo_beos_bitmap_to_surface (surface->bitmap); - if (unlikely ((*image_out)->base.status)) - return (*image_out)->base.status; - - *image_extra = NULL; - return CAIRO_STATUS_SUCCESS; - } - - BBitmap* bmp; - if (_cairo_beos_view_to_bitmap(surface->view, &bmp) != OK) - return CAIRO_STATUS_NO_MEMORY; /// XXX incorrect if the error was NOT_VISIBLE - - *image_out = _cairo_beos_bitmap_to_surface (bmp); - if (unlikely ((*image_out)->base.status)) { - delete bmp; - return (*image_out)->base.status; - } - *image_extra = bmp; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_beos_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); - - if (image_extra != NULL) { - BBitmap* bmp = static_cast(image_extra); - delete bmp; - } -} - -static cairo_status_t -_cairo_beos_surface_acquire_dest_image (void *abstract_surface, - cairo_rectangle_int_t *interest_rect, - cairo_image_surface_t **image_out, - cairo_rectangle_int_t *image_rect, - void **image_extra) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - - AutoLockView locker(surface->view); - if (!locker) { - *image_out = NULL; - *image_extra = NULL; - return (cairo_status_t) CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - if (surface->bitmap) { - surface->view->Sync(); - *image_out = _cairo_beos_bitmap_to_surface(surface->bitmap); - if (unlikely ((*image_out)->base.status)) - return (*image_out)->base.status; - - image_rect->x = 0; - image_rect->y = 0; - image_rect->width = (*image_out)->width; - image_rect->height = (*image_out)->height; - - *image_extra = NULL; - return CAIRO_STATUS_SUCCESS; - } - - BRect b_interest_rect (_cairo_rectangle_to_brect (interest_rect)); - - BRect rect; - BBitmap* bitmap; - ViewCopyStatus status = _cairo_beos_view_to_bitmap(surface->view, &bitmap, - &rect, &b_interest_rect); - if (status == NOT_VISIBLE) { - *image_out = NULL; - *image_extra = NULL; - return CAIRO_STATUS_SUCCESS; - } - if (status == ERROR) - return CAIRO_STATUS_NO_MEMORY; - - *image_rect = _brect_to_cairo_rectangle(rect); - *image_out = _cairo_beos_bitmap_to_surface(bitmap); - delete bitmap; - if (unlikely ((*image_out)->base.status)) - return (*image_out)->base.status; - - *image_extra = NULL; - - return CAIRO_STATUS_SUCCESS; -} - - -static void -_cairo_beos_surface_release_dest_image (void *abstract_surface, - cairo_rectangle_int_t *intersect_rect, - cairo_image_surface_t *image, - cairo_rectangle_int_t *image_rect, - void *image_extra) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - - AutoLockView locker(surface->view); - if (!locker) - return; - - BBitmap* bitmap_to_draw = _cairo_image_surface_to_bitmap(image); - surface->view->PushState(); - - surface->view->SetDrawingMode(B_OP_COPY); - - surface->view->DrawBitmap (bitmap_to_draw, - _cairo_rectangle_to_brect (image_rect)); - - surface->view->PopState(); - - delete bitmap_to_draw; - cairo_surface_destroy(&image->base); -} - -static cairo_int_status_t -_cairo_beos_surface_composite (cairo_operator_t op, - cairo_pattern_t *src, - cairo_pattern_t *mask, - void *dst, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height, - cairo_region_t *clip_region) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - dst); - cairo_int_status_t status; - AutoLockView locker(surface->view); - if (!locker) - return CAIRO_INT_STATUS_SUCCESS; - - drawing_mode mode; - if (!_cairo_op_to_be_op(op, &mode)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - // XXX Masks are not yet supported - if (mask) - return CAIRO_INT_STATUS_UNSUPPORTED; - - // XXX should eventually support the others - if (src->type != CAIRO_PATTERN_TYPE_SURFACE || - src->extend != CAIRO_EXTEND_NONE) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - // Can we maybe support other matrices as well? (scale? if the filter is right) - int itx, ity; - if (!_cairo_matrix_is_integer_translation(&src->matrix, &itx, &ity)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_beos_surface_set_clip_region (surface, clip_region); - if (unlikely (status)) - return status; - - BRect srcRect(src_x + itx, - src_y + ity, - src_x + itx + width - 1, - src_y + ity + height - 1); - BRect dstRect(dst_x, dst_y, dst_x + width - 1, dst_y + height - 1); - - cairo_surface_t* src_surface = reinterpret_cast(src)-> - surface; - - // Get a bitmap - BBitmap* bmp = NULL; - bool free_bmp = false; - if (_cairo_surface_is_image(src_surface)) { - cairo_image_surface_t* img_surface = - reinterpret_cast(src_surface); - - bmp = _cairo_image_surface_to_bitmap(img_surface); - free_bmp = true; - } else if (src_surface->backend == surface->base.backend) { - cairo_beos_surface_t *beos_surface = - reinterpret_cast(src_surface); - if (beos_surface->bitmap) { - AutoLockView locker(beos_surface->view); - if (locker) - beos_surface->view->Sync(); - bmp = beos_surface->bitmap; - } else { - _cairo_beos_view_to_bitmap(surface->view, &bmp); - free_bmp = true; - } - } - - if (!bmp) - return CAIRO_INT_STATUS_UNSUPPORTED; - - // So, BeOS seems to screw up painting an opaque bitmap onto a - // translucent one (it makes them partly transparent). Just return - // unsupported. - if (bmp->ColorSpace() == B_RGB32 && surface->bitmap && - surface->bitmap->ColorSpace() == B_RGBA32 && - (mode == B_OP_COPY || mode == B_OP_ALPHA)) - { - if (free_bmp) - delete bmp; - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - // Draw it on screen. - surface->view->PushState(); - - // If our image rect is only a subrect of the desired size, and we - // aren't using B_OP_ALPHA, then we need to fill the rect first. - if (mode == B_OP_COPY && !bmp->Bounds().Contains(srcRect)) { - rgb_color black = { 0, 0, 0, 0 }; - - surface->view->SetDrawingMode(mode); - surface->view->SetHighColor(black); - surface->view->FillRect(dstRect); - } - - if (mode == B_OP_ALPHA && bmp->ColorSpace() == B_RGB32) { - mode = B_OP_COPY; - } - surface->view->SetDrawingMode(mode); - - if (surface->bitmap && surface->bitmap->ColorSpace() == B_RGBA32) - surface->view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - else - surface->view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - - surface->view->DrawBitmap(bmp, srcRect, dstRect); - - surface->view->PopState(); - - if (free_bmp) - delete bmp; - - return CAIRO_INT_STATUS_SUCCESS; -} - - -static cairo_int_status_t -_cairo_beos_surface_fill_rectangles (void *abstract_surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_rectangle_int_t *rects, - int num_rects, - cairo_region_t *clip_region) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - cairo_int_status_t status; - - if (num_rects <= 0) - return CAIRO_INT_STATUS_SUCCESS; - - AutoLockView locker(surface->view); - if (!locker) - return CAIRO_INT_STATUS_SUCCESS; - - drawing_mode mode; - if (!_cairo_op_to_be_op(op, &mode)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_beos_surface_set_clip_region (surface, clip_region); - if (unlikely (status)) - return status; - - rgb_color be_color = _cairo_color_to_be_color(color); - - if (mode == B_OP_ALPHA && be_color.alpha == 0xFF) - mode = B_OP_COPY; - - // For CAIRO_OPERATOR_SOURCE, cairo expects us to use the premultiplied - // color info. This is only relevant when drawing into an rgb24 buffer - // (as for others, we can convert when asked for the image) - if (mode == B_OP_COPY && be_color.alpha != 0xFF && - (!surface->bitmap || surface->bitmap->ColorSpace() != B_RGBA32)) - { - be_color.red = color->red_short >> 8; - be_color.green = color->green_short >> 8; - be_color.blue = color->blue_short >> 8; - } - - surface->view->PushState(); - - surface->view->SetDrawingMode(mode); - surface->view->SetHighColor(be_color); - if (surface->bitmap && surface->bitmap->ColorSpace() == B_RGBA32) - surface->view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE); - else - surface->view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); - - for (int i = 0; i < num_rects; ++i) - surface->view->FillRect (_cairo_rectangle_to_brect (&rects[i])); - - surface->view->PopState(); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_beos_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_beos_surface_t *surface = reinterpret_cast( - abstract_surface); - AutoLockView locker(surface->view); - if (!locker) - return FALSE; - - *rectangle = _brect_to_cairo_rectangle (surface->view->Bounds()); - return TRUE; -} - -static const struct _cairo_surface_backend cairo_beos_surface_backend = { - CAIRO_SURFACE_TYPE_BEOS, - _cairo_beos_surface_create_similar, - _cairo_beos_surface_finish, - _cairo_beos_surface_acquire_source_image, - _cairo_beos_surface_release_source_image, - _cairo_beos_surface_acquire_dest_image, - _cairo_beos_surface_release_dest_image, - NULL, /* clone_similar */ - _cairo_beos_surface_composite, /* composite */ - _cairo_beos_surface_fill_rectangles, - NULL, /* composite_trapezoids */ - NULL, /* create_span_renderer */ - NULL, /* check_span_renderer */ - NULL, /* copy_page */ - NULL, /* show_page */ - _cairo_beos_surface_get_extents, - NULL, /* old_show_glyphs */ - NULL, /* get_font_options */ - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - NULL, /* scaled_font_fini */ - NULL, /* scaled_glyph_fini */ - - NULL, /* paint */ - NULL, /* mask */ - NULL, /* stroke */ - NULL, /* fill */ - NULL /* show_glyphs */ -}; - -static cairo_surface_t * -_cairo_beos_surface_create_internal (BView* view, - BBitmap* bmp, - bool owns_bitmap_view) -{ - // Must use malloc, because cairo code will use free() on the surface - cairo_beos_surface_t *surface = static_cast( - malloc(sizeof(cairo_beos_surface_t))); - if (surface == NULL) { - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return const_cast(&_cairo_surface_nil); - } - - cairo_content_t content = CAIRO_CONTENT_COLOR; - if (bmp && (bmp->ColorSpace() == B_RGBA32 || bmp->ColorSpace() == B_RGBA15)) - content = CAIRO_CONTENT_COLOR_ALPHA; - _cairo_surface_init (&surface->base, - &cairo_beos_surface_backend, - NULL, /* device */ - content); - - surface->view = view; - surface->bitmap = bmp; - surface->owns_bitmap_view = owns_bitmap_view; - - surface->clip_region = NULL; - - return &surface->base; -} - -/** - * cairo_beos_surface_create: - * @view: The view to draw on - * - * Creates a Cairo surface that draws onto a BeOS BView. - * The caller must ensure that the view does not get deleted before the surface. - * If the view is attached to a bitmap rather than an on-screen window, use - * cairo_beos_surface_create_for_bitmap() instead of this function. - * - * Since: TBD - **/ -cairo_surface_t * -cairo_beos_surface_create (BView* view) -{ - return cairo_beos_surface_create_for_bitmap(view, NULL); -} - -/** - * cairo_beos_surface_create_for_bitmap: - * @view: The view to draw on - * @bmp: The bitmap to which the view is attached - * - * Creates a Cairo surface that draws onto a BeOS BView which is attached to a - * BBitmap. - * The caller must ensure that the view and the bitmap do not get deleted - * before the surface. - * - * For views that draw to a bitmap (as opposed to a screen), use this function - * rather than cairo_beos_surface_create(). Not using this function WILL lead to - * incorrect behaviour. - * - * For now, only views that draw to the entire area of bmp are supported. - * The view must already be attached to the bitmap. - * - * Since: TBD - **/ -cairo_surface_t * -cairo_beos_surface_create_for_bitmap (BView* view, - BBitmap* bmp) -{ - return _cairo_beos_surface_create_internal(view, bmp); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos.h deleted file mode 100644 index fdb89a6c4dc..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-beos.h +++ /dev/null @@ -1,60 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Christian Biesinger - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Christian Biesinger - * - * - * Contributor(s): - */ - -#ifndef CAIRO_BEOS_H -#define CAIRO_BEOS_H - -#include "cairo.h" - -#if CAIRO_HAS_BEOS_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_beos_surface_create (BView* view); - -cairo_public cairo_surface_t * -cairo_beos_surface_create_for_bitmap (BView* view, - BBitmap* bmp); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_BEOS_SURFACE */ -# error Cairo was not compiled with support for the beos backend -#endif /* CAIRO_HAS_BEOS_SURFACE */ - -#endif /* CAIRO_BEOS_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-botor-scan-converter.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-botor-scan-converter.c deleted file mode 100644 index 515305bf24e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-botor-scan-converter.c +++ /dev/null @@ -1,2164 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2007 David Turner - * Copyright © 2008 M Joonas Pihlaja - * Copyright © 2008 Chris Wilson - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * M Joonas Pihlaja - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-list-inline.h" -#include "cairo-freelist-private.h" -#include "cairo-combsort-inline.h" - -#include - -#define STEP_X CAIRO_FIXED_ONE -#define STEP_Y CAIRO_FIXED_ONE -#define UNROLL3(x) x x x - -#define STEP_XY (2*STEP_X*STEP_Y) /* Unit area in the step. */ -#define AREA_TO_ALPHA(c) (((c)*255 + STEP_XY/2) / STEP_XY) - -typedef struct _cairo_bo_intersect_ordinate { - int32_t ordinate; - enum { EXACT, INEXACT } exactness; -} cairo_bo_intersect_ordinate_t; - -typedef struct _cairo_bo_intersect_point { - cairo_bo_intersect_ordinate_t x; - cairo_bo_intersect_ordinate_t y; -} cairo_bo_intersect_point_t; - -struct quorem { - cairo_fixed_t quo; - cairo_fixed_t rem; -}; - -struct run { - struct run *next; - int sign; - cairo_fixed_t y; -}; - -typedef struct edge { - cairo_list_t link; - - cairo_edge_t edge; - - /* Current x coordinate and advancement. - * Initialised to the x coordinate of the top of the - * edge. The quotient is in cairo_fixed_t units and the - * remainder is mod dy in cairo_fixed_t units. - */ - cairo_fixed_t dy; - struct quorem x; - struct quorem dxdy; - struct quorem dxdy_full; - - cairo_bool_t vertical; - unsigned int flags; - - int current_sign; - struct run *runs; -} edge_t; - -enum { - START = 0x1, - STOP = 0x2, -}; - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef enum { - EVENT_TYPE_STOP, - EVENT_TYPE_INTERSECTION, - EVENT_TYPE_START -} event_type_t; - -typedef struct _event { - cairo_fixed_t y; - event_type_t type; -} event_t; - -typedef struct _start_event { - cairo_fixed_t y; - event_type_t type; - edge_t *edge; -} start_event_t; - -typedef struct _queue_event { - cairo_fixed_t y; - event_type_t type; - edge_t *e1; - edge_t *e2; -} queue_event_t; - -typedef struct _pqueue { - int size, max_size; - - event_t **elements; - event_t *elements_embedded[1024]; -} pqueue_t; - -struct cell { - struct cell *prev; - struct cell *next; - int x; - int uncovered_area; - int covered_height; -}; - -typedef struct _sweep_line { - cairo_list_t active; - cairo_list_t stopped; - cairo_list_t *insert_cursor; - cairo_bool_t is_vertical; - - cairo_fixed_t current_row; - cairo_fixed_t current_subrow; - - struct coverage { - struct cell head; - struct cell tail; - - struct cell *cursor; - int count; - - cairo_freepool_t pool; - } coverage; - - struct event_queue { - pqueue_t pq; - event_t **start_events; - - cairo_freepool_t pool; - } queue; - - cairo_freepool_t runs; - - jmp_buf unwind; -} sweep_line_t; - -cairo_always_inline static struct quorem -floored_divrem (int a, int b) -{ - struct quorem qr; - qr.quo = a/b; - qr.rem = a%b; - if ((a^b)<0 && qr.rem) { - qr.quo--; - qr.rem += b; - } - return qr; -} - -static struct quorem -floored_muldivrem(int x, int a, int b) -{ - struct quorem qr; - long long xa = (long long)x*a; - qr.quo = xa/b; - qr.rem = xa%b; - if ((xa>=0) != (b>=0) && qr.rem) { - qr.quo--; - qr.rem += b; - } - return qr; -} - -static cairo_fixed_t -line_compute_intersection_x_for_y (const cairo_line_t *line, - cairo_fixed_t y) -{ - cairo_fixed_t x, dy; - - if (y == line->p1.y) - return line->p1.x; - if (y == line->p2.y) - return line->p2.x; - - x = line->p1.x; - dy = line->p2.y - line->p1.y; - if (dy != 0) { - x += _cairo_fixed_mul_div_floor (y - line->p1.y, - line->p2.x - line->p1.x, - dy); - } - - return x; -} - -/* - * We need to compare the x-coordinates of a pair of lines for a particular y, - * without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy - * - (Y - A_y) * A_dx * B_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 128 bit arithmetic. For certain, but common, - * input we can reduce this down to a single 32 bit compare by inspecting the - * deltas. - * - * (And put the burden of the work on developing fast 128 bit ops, which are - * required throughout the tessellator.) - * - * See the similar discussion for _slope_compare(). - */ -static int -edges_compare_x_for_y_general (const cairo_edge_t *a, - const cairo_edge_t *b, - int32_t y) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t dx; - int32_t adx, ady; - int32_t bdx, bdy; - enum { - HAVE_NONE = 0x0, - HAVE_DX = 0x1, - HAVE_ADX = 0x2, - HAVE_DX_ADX = HAVE_DX | HAVE_ADX, - HAVE_BDX = 0x4, - HAVE_DX_BDX = HAVE_DX | HAVE_BDX, - HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, - HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX - } have_dx_adx_bdx = HAVE_ALL; - - /* don't bother solving for abscissa if the edges' bounding boxes - * can be used to order them. */ - { - int32_t amin, amax; - int32_t bmin, bmax; - if (a->line.p1.x < a->line.p2.x) { - amin = a->line.p1.x; - amax = a->line.p2.x; - } else { - amin = a->line.p2.x; - amax = a->line.p1.x; - } - if (b->line.p1.x < b->line.p2.x) { - bmin = b->line.p1.x; - bmax = b->line.p2.x; - } else { - bmin = b->line.p2.x; - bmax = b->line.p1.x; - } - if (amax < bmin) return -1; - if (amin > bmax) return +1; - } - - ady = a->line.p2.y - a->line.p1.y; - adx = a->line.p2.x - a->line.p1.x; - if (adx == 0) - have_dx_adx_bdx &= ~HAVE_ADX; - - bdy = b->line.p2.y - b->line.p1.y; - bdx = b->line.p2.x - b->line.p1.x; - if (bdx == 0) - have_dx_adx_bdx &= ~HAVE_BDX; - - dx = a->line.p1.x - b->line.p1.x; - if (dx == 0) - have_dx_adx_bdx &= ~HAVE_DX; - -#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) -#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->line.p1.y) -#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->line.p1.y) - switch (have_dx_adx_bdx) { - default: - case HAVE_NONE: - return 0; - case HAVE_DX: - /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ - return dx; /* ady * bdy is positive definite */ - case HAVE_ADX: - /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ - return adx; /* bdy * (y - a->top.y) is positive definite */ - case HAVE_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy */ - return -bdx; /* ady * (y - b->top.y) is positive definite */ - case HAVE_ADX_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ - if ((adx ^ bdx) < 0) { - return adx; - } else if (a->line.p1.y == b->line.p1.y) { /* common origin */ - cairo_int64_t adx_bdy, bdx_ady; - - /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ - - adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } else - return _cairo_int128_cmp (A, B); - case HAVE_DX_ADX: - /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ - if ((-adx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t ady_dx, dy_adx; - - ady_dx = _cairo_int32x32_64_mul (ady, dx); - dy_adx = _cairo_int32x32_64_mul (a->line.p1.y - y, adx); - - return _cairo_int64_cmp (ady_dx, dy_adx); - } - case HAVE_DX_BDX: - /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ - if ((bdx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t bdy_dx, dy_bdx; - - bdy_dx = _cairo_int32x32_64_mul (bdy, dx); - dy_bdx = _cairo_int32x32_64_mul (y - b->line.p1.y, bdx); - - return _cairo_int64_cmp (bdy_dx, dy_bdx); - } - case HAVE_ALL: - /* XXX try comparing (a->line.p2.x - b->line.p2.x) et al */ - return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); - } -#undef B -#undef A -#undef L -} - -/* - * We need to compare the x-coordinate of a line for a particular y wrt to a - * given x, without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ X - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy (and (Y - A_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 64 bit arithmetic. - * - * See the similar discussion for _slope_compare() and - * edges_compare_x_for_y_general(). - */ -static int -edge_compare_for_y_against_x (const cairo_edge_t *a, - int32_t y, - int32_t x) -{ - int32_t adx, ady; - int32_t dx, dy; - cairo_int64_t L, R; - - if (a->line.p1.x <= a->line.p2.x) { - if (x < a->line.p1.x) - return 1; - if (x > a->line.p2.x) - return -1; - } else { - if (x < a->line.p2.x) - return 1; - if (x > a->line.p1.x) - return -1; - } - - adx = a->line.p2.x - a->line.p1.x; - dx = x - a->line.p1.x; - - if (adx == 0) - return -dx; - if (dx == 0 || (adx ^ dx) < 0) - return adx; - - dy = y - a->line.p1.y; - ady = a->line.p2.y - a->line.p1.y; - - L = _cairo_int32x32_64_mul (dy, adx); - R = _cairo_int32x32_64_mul (dx, ady); - - return _cairo_int64_cmp (L, R); -} - -static int -edges_compare_x_for_y (const cairo_edge_t *a, - const cairo_edge_t *b, - int32_t y) -{ - /* If the sweep-line is currently on an end-point of a line, - * then we know its precise x value (and considering that we often need to - * compare events at end-points, this happens frequently enough to warrant - * special casing). - */ - enum { - HAVE_NEITHER = 0x0, - HAVE_AX = 0x1, - HAVE_BX = 0x2, - HAVE_BOTH = HAVE_AX | HAVE_BX - } have_ax_bx = HAVE_BOTH; - int32_t ax, bx; - - /* XXX given we have x and dx? */ - - if (y == a->line.p1.y) - ax = a->line.p1.x; - else if (y == a->line.p2.y) - ax = a->line.p2.x; - else - have_ax_bx &= ~HAVE_AX; - - if (y == b->line.p1.y) - bx = b->line.p1.x; - else if (y == b->line.p2.y) - bx = b->line.p2.x; - else - have_ax_bx &= ~HAVE_BX; - - switch (have_ax_bx) { - default: - case HAVE_NEITHER: - return edges_compare_x_for_y_general (a, b, y); - case HAVE_AX: - return -edge_compare_for_y_against_x (b, y, ax); - case HAVE_BX: - return edge_compare_for_y_against_x (a, y, bx); - case HAVE_BOTH: - return ax - bx; - } -} - -static inline int -slope_compare (const edge_t *a, - const edge_t *b) -{ - cairo_int64_t L, R; - int cmp; - - cmp = a->dxdy.quo - b->dxdy.quo; - if (cmp) - return cmp; - - if (a->dxdy.rem == 0) - return -b->dxdy.rem; - if (b->dxdy.rem == 0) - return a->dxdy.rem; - - L = _cairo_int32x32_64_mul (b->dy, a->dxdy.rem); - R = _cairo_int32x32_64_mul (a->dy, b->dxdy.rem); - return _cairo_int64_cmp (L, R); -} - -static inline int -line_equal (const cairo_line_t *a, const cairo_line_t *b) -{ - return a->p1.x == b->p1.x && a->p1.y == b->p1.y && - a->p2.x == b->p2.x && a->p2.y == b->p2.y; -} - -static inline int -sweep_line_compare_edges (const edge_t *a, - const edge_t *b, - cairo_fixed_t y) -{ - int cmp; - - if (line_equal (&a->edge.line, &b->edge.line)) - return 0; - - cmp = edges_compare_x_for_y (&a->edge, &b->edge, y); - if (cmp) - return cmp; - - return slope_compare (a, b); -} - -static inline cairo_int64_t -det32_64 (int32_t a, int32_t b, - int32_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), - _cairo_int32x32_64_mul (b, c)); -} - -static inline cairo_int128_t -det64x32_128 (cairo_int64_t a, int32_t b, - cairo_int64_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), - _cairo_int64x32_128_mul (c, b)); -} - -/* Compute the intersection of two lines as defined by two edges. The - * result is provided as a coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or - * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. - */ -static cairo_bool_t -intersect_lines (const edge_t *a, const edge_t *b, - cairo_bo_intersect_point_t *intersection) -{ - cairo_int64_t a_det, b_det; - - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm begins. - * What we're doing to mitigate this is to perform clamping in - * cairo_bo_tessellate_polygon(). - */ - int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; - int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; - - int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; - int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; - - cairo_int64_t den_det; - cairo_int64_t R; - cairo_quorem64_t qr; - - den_det = det32_64 (dx1, dy1, dx2, dy2); - - /* Q: Can we determine that the lines do not intersect (within range) - * much more cheaply than computing the intersection point i.e. by - * avoiding the division? - * - * X = ax + t * adx = bx + s * bdx; - * Y = ay + t * ady = by + s * bdy; - * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) - * => t * L = R - * - * Therefore we can reject any intersection (under the criteria for - * valid intersection events) if: - * L^R < 0 => t < 0, or - * L t > 1 - * - * (where top/bottom must at least extend to the line endpoints). - * - * A similar substitution can be performed for s, yielding: - * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) - */ - R = det32_64 (dx2, dy2, - b->edge.line.p1.x - a->edge.line.p1.x, - b->edge.line.p1.y - a->edge.line.p1.y); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - R = det32_64 (dy1, dx1, - a->edge.line.p1.y - b->edge.line.p1.y, - a->edge.line.p1.x - b->edge.line.p1.x); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - /* We now know that the two lines should intersect within range. */ - - a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, - a->edge.line.p2.x, a->edge.line.p2.y); - b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, - b->edge.line.p2.x, b->edge.line.p2.y); - - /* x = det (a_det, dx1, b_det, dx2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, - b_det, dx2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->x.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->x.exactness = INEXACT; - } -#endif - intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); - - /* y = det (a_det, dy1, b_det, dy2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, - b_det, dy2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->y.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - /* compute ceiling away from zero */ - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - intersection->y.exactness = INEXACT; - } -#endif - intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); - - return TRUE; -} - -static int -bo_intersect_ordinate_32_compare (int32_t a, int32_t b, int exactness) -{ - int cmp; - - /* First compare the quotient */ - cmp = a - b; - if (cmp) - return cmp; - - /* With quotient identical, if remainder is 0 then compare equal */ - /* Otherwise, the non-zero remainder makes a > b */ - return -(INEXACT == exactness); -} - -/* Does the given edge contain the given point. The point must already - * be known to be contained within the line determined by the edge, - * (most likely the point results from an intersection of this edge - * with another). - * - * If we had exact arithmetic, then this function would simply be a - * matter of examining whether the y value of the point lies within - * the range of y values of the edge. But since intersection points - * are not exact due to being rounded to the nearest integer within - * the available precision, we must also examine the x value of the - * point. - * - * The definition of "contains" here is that the given intersection - * point will be seen by the sweep line after the start event for the - * given edge and before the stop event for the edge. See the comments - * in the implementation for more details. - */ -static cairo_bool_t -bo_edge_contains_intersect_point (const edge_t *edge, - cairo_bo_intersect_point_t *point) -{ - int cmp_top, cmp_bottom; - - /* XXX: When running the actual algorithm, we don't actually need to - * compare against edge->top at all here, since any intersection above - * top is eliminated early via a slope comparison. We're leaving these - * here for now only for the sake of the quadratic-time intersection - * finder which needs them. - */ - - cmp_top = bo_intersect_ordinate_32_compare (point->y.ordinate, - edge->edge.top, - point->y.exactness); - if (cmp_top < 0) - return FALSE; - - cmp_bottom = bo_intersect_ordinate_32_compare (point->y.ordinate, - edge->edge.bottom, - point->y.exactness); - if (cmp_bottom > 0) - return FALSE; - - if (cmp_top > 0 && cmp_bottom < 0) - return TRUE; - - /* At this stage, the point lies on the same y value as either - * edge->top or edge->bottom, so we have to examine the x value in - * order to properly determine containment. */ - - /* If the y value of the point is the same as the y value of the - * top of the edge, then the x value of the point must be greater - * to be considered as inside the edge. Similarly, if the y value - * of the point is the same as the y value of the bottom of the - * edge, then the x value of the point must be less to be - * considered as inside. */ - - if (cmp_top == 0) { - cairo_fixed_t top_x; - - top_x = line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.top); - return bo_intersect_ordinate_32_compare (top_x, point->x.ordinate, point->x.exactness) < 0; - } else { /* cmp_bottom == 0 */ - cairo_fixed_t bot_x; - - bot_x = line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.bottom); - return bo_intersect_ordinate_32_compare (point->x.ordinate, bot_x, point->x.exactness) < 0; - } -} - -static cairo_bool_t -edge_intersect (const edge_t *a, - const edge_t *b, - cairo_point_t *intersection) -{ - cairo_bo_intersect_point_t quorem; - - if (! intersect_lines (a, b, &quorem)) - return FALSE; - - if (a->edge.top != a->edge.line.p1.y || a->edge.bottom != a->edge.line.p2.y) { - if (! bo_edge_contains_intersect_point (a, &quorem)) - return FALSE; - } - - if (b->edge.top != b->edge.line.p1.y || b->edge.bottom != b->edge.line.p2.y) { - if (! bo_edge_contains_intersect_point (b, &quorem)) - return FALSE; - } - - /* Now that we've correctly compared the intersection point and - * determined that it lies within the edge, then we know that we - * no longer need any more bits of storage for the intersection - * than we do for our edge coordinates. We also no longer need the - * remainder from the division. */ - intersection->x = quorem.x.ordinate; - intersection->y = quorem.y.ordinate; - - return TRUE; -} - -static inline int -event_compare (const event_t *a, const event_t *b) -{ - return a->y - b->y; -} - -static void -pqueue_init (pqueue_t *pq) -{ - pq->max_size = ARRAY_LENGTH (pq->elements_embedded); - pq->size = 0; - - pq->elements = pq->elements_embedded; -} - -static void -pqueue_fini (pqueue_t *pq) -{ - if (pq->elements != pq->elements_embedded) - free (pq->elements); -} - -static cairo_bool_t -pqueue_grow (pqueue_t *pq) -{ - event_t **new_elements; - pq->max_size *= 2; - - if (pq->elements == pq->elements_embedded) { - new_elements = _cairo_malloc_ab (pq->max_size, - sizeof (event_t *)); - if (unlikely (new_elements == NULL)) - return FALSE; - - memcpy (new_elements, pq->elements_embedded, - sizeof (pq->elements_embedded)); - } else { - new_elements = _cairo_realloc_ab (pq->elements, - pq->max_size, - sizeof (event_t *)); - if (unlikely (new_elements == NULL)) - return FALSE; - } - - pq->elements = new_elements; - return TRUE; -} - -static inline void -pqueue_push (sweep_line_t *sweep_line, event_t *event) -{ - event_t **elements; - int i, parent; - - if (unlikely (sweep_line->queue.pq.size + 1 == sweep_line->queue.pq.max_size)) { - if (unlikely (! pqueue_grow (&sweep_line->queue.pq))) { - longjmp (sweep_line->unwind, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - } - - elements = sweep_line->queue.pq.elements; - for (i = ++sweep_line->queue.pq.size; - i != PQ_FIRST_ENTRY && - event_compare (event, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = event; -} - -static inline void -pqueue_pop (pqueue_t *pq) -{ - event_t **elements = pq->elements; - event_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - event_compare (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (event_compare (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline void -event_insert (sweep_line_t *sweep_line, - event_type_t type, - edge_t *e1, - edge_t *e2, - cairo_fixed_t y) -{ - queue_event_t *event; - - event = _cairo_freepool_alloc (&sweep_line->queue.pool); - if (unlikely (event == NULL)) { - longjmp (sweep_line->unwind, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - event->y = y; - event->type = type; - event->e1 = e1; - event->e2 = e2; - - pqueue_push (sweep_line, (event_t *) event); -} - -static void -event_delete (sweep_line_t *sweep_line, - event_t *event) -{ - _cairo_freepool_free (&sweep_line->queue.pool, event); -} - -static inline event_t * -event_next (sweep_line_t *sweep_line) -{ - event_t *event, *cmp; - - event = sweep_line->queue.pq.elements[PQ_FIRST_ENTRY]; - cmp = *sweep_line->queue.start_events; - if (event == NULL || - (cmp != NULL && event_compare (cmp, event) < 0)) - { - event = cmp; - sweep_line->queue.start_events++; - } - else - { - pqueue_pop (&sweep_line->queue.pq); - } - - return event; -} - -CAIRO_COMBSORT_DECLARE (start_event_sort, event_t *, event_compare) - -static inline void -event_insert_stop (sweep_line_t *sweep_line, - edge_t *edge) -{ - event_insert (sweep_line, - EVENT_TYPE_STOP, - edge, NULL, - edge->edge.bottom); -} - -static inline void -event_insert_if_intersect_below_current_y (sweep_line_t *sweep_line, - edge_t *left, - edge_t *right) -{ - cairo_point_t intersection; - - /* start points intersect */ - if (left->edge.line.p1.x == right->edge.line.p1.x && - left->edge.line.p1.y == right->edge.line.p1.y) - { - return; - } - - /* end points intersect, process DELETE events first */ - if (left->edge.line.p2.x == right->edge.line.p2.x && - left->edge.line.p2.y == right->edge.line.p2.y) - { - return; - } - - if (slope_compare (left, right) <= 0) - return; - - if (! edge_intersect (left, right, &intersection)) - return; - - event_insert (sweep_line, - EVENT_TYPE_INTERSECTION, - left, right, - intersection.y); -} - -static inline edge_t * -link_to_edge (cairo_list_t *link) -{ - return (edge_t *) link; -} - -static void -sweep_line_insert (sweep_line_t *sweep_line, - edge_t *edge) -{ - cairo_list_t *pos; - cairo_fixed_t y = sweep_line->current_subrow; - - pos = sweep_line->insert_cursor; - if (pos == &sweep_line->active) - pos = sweep_line->active.next; - if (pos != &sweep_line->active) { - int cmp; - - cmp = sweep_line_compare_edges (link_to_edge (pos), - edge, - y); - if (cmp < 0) { - while (pos->next != &sweep_line->active && - sweep_line_compare_edges (link_to_edge (pos->next), - edge, - y) < 0) - { - pos = pos->next; - } - } else if (cmp > 0) { - do { - pos = pos->prev; - } while (pos != &sweep_line->active && - sweep_line_compare_edges (link_to_edge (pos), - edge, - y) > 0); - } - } - cairo_list_add (&edge->link, pos); - sweep_line->insert_cursor = &edge->link; -} - -inline static void -coverage_rewind (struct coverage *cells) -{ - cells->cursor = &cells->head; -} - -static void -coverage_init (struct coverage *cells) -{ - _cairo_freepool_init (&cells->pool, - sizeof (struct cell)); - cells->head.prev = NULL; - cells->head.next = &cells->tail; - cells->head.x = INT_MIN; - cells->tail.prev = &cells->head; - cells->tail.next = NULL; - cells->tail.x = INT_MAX; - cells->count = 0; - coverage_rewind (cells); -} - -static void -coverage_fini (struct coverage *cells) -{ - _cairo_freepool_fini (&cells->pool); -} - -inline static void -coverage_reset (struct coverage *cells) -{ - cells->head.next = &cells->tail; - cells->tail.prev = &cells->head; - cells->count = 0; - _cairo_freepool_reset (&cells->pool); - coverage_rewind (cells); -} - -static struct cell * -coverage_alloc (sweep_line_t *sweep_line, - struct cell *tail, - int x) -{ - struct cell *cell; - - cell = _cairo_freepool_alloc (&sweep_line->coverage.pool); - if (unlikely (NULL == cell)) { - longjmp (sweep_line->unwind, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - tail->prev->next = cell; - cell->prev = tail->prev; - cell->next = tail; - tail->prev = cell; - cell->x = x; - cell->uncovered_area = 0; - cell->covered_height = 0; - sweep_line->coverage.count++; - return cell; -} - -inline static struct cell * -coverage_find (sweep_line_t *sweep_line, int x) -{ - struct cell *cell; - - cell = sweep_line->coverage.cursor; - if (unlikely (cell->x > x)) { - do { - if (cell->prev->x < x) - break; - cell = cell->prev; - } while (TRUE); - } else { - if (cell->x == x) - return cell; - - do { - UNROLL3({ - cell = cell->next; - if (cell->x >= x) - break; - }); - } while (TRUE); - } - - if (cell->x != x) - cell = coverage_alloc (sweep_line, cell, x); - - return sweep_line->coverage.cursor = cell; -} - -static void -coverage_render_cells (sweep_line_t *sweep_line, - cairo_fixed_t left, cairo_fixed_t right, - cairo_fixed_t y1, cairo_fixed_t y2, - int sign) -{ - int fx1, fx2; - int ix1, ix2; - int dx, dy; - - /* Orient the edge left-to-right. */ - dx = right - left; - if (dx >= 0) { - ix1 = _cairo_fixed_integer_part (left); - fx1 = _cairo_fixed_fractional_part (left); - - ix2 = _cairo_fixed_integer_part (right); - fx2 = _cairo_fixed_fractional_part (right); - - dy = y2 - y1; - } else { - ix1 = _cairo_fixed_integer_part (right); - fx1 = _cairo_fixed_fractional_part (right); - - ix2 = _cairo_fixed_integer_part (left); - fx2 = _cairo_fixed_fractional_part (left); - - dx = -dx; - sign = -sign; - dy = y1 - y2; - y1 = y2 - dy; - y2 = y1 + dy; - } - - /* Add coverage for all pixels [ix1,ix2] on this row crossed - * by the edge. */ - { - struct quorem y = floored_divrem ((STEP_X - fx1)*dy, dx); - struct cell *cell; - - cell = sweep_line->coverage.cursor; - if (cell->x != ix1) { - if (unlikely (cell->x > ix1)) { - do { - if (cell->prev->x < ix1) - break; - cell = cell->prev; - } while (TRUE); - } else do { - UNROLL3({ - if (cell->x >= ix1) - break; - cell = cell->next; - }); - } while (TRUE); - - if (cell->x != ix1) - cell = coverage_alloc (sweep_line, cell, ix1); - } - - cell->uncovered_area += sign * y.quo * (STEP_X + fx1); - cell->covered_height += sign * y.quo; - y.quo += y1; - - cell = cell->next; - if (cell->x != ++ix1) - cell = coverage_alloc (sweep_line, cell, ix1); - if (ix1 < ix2) { - struct quorem dydx_full = floored_divrem (STEP_X*dy, dx); - - do { - cairo_fixed_t y_skip = dydx_full.quo; - y.rem += dydx_full.rem; - if (y.rem >= dx) { - ++y_skip; - y.rem -= dx; - } - - y.quo += y_skip; - - y_skip *= sign; - cell->covered_height += y_skip; - cell->uncovered_area += y_skip*STEP_X; - - cell = cell->next; - if (cell->x != ++ix1) - cell = coverage_alloc (sweep_line, cell, ix1); - } while (ix1 != ix2); - } - cell->uncovered_area += sign*(y2 - y.quo)*fx2; - cell->covered_height += sign*(y2 - y.quo); - sweep_line->coverage.cursor = cell; - } -} - -inline static void -full_inc_edge (edge_t *edge) -{ - edge->x.quo += edge->dxdy_full.quo; - edge->x.rem += edge->dxdy_full.rem; - if (edge->x.rem >= 0) { - ++edge->x.quo; - edge->x.rem -= edge->dy; - } -} - -static void -full_add_edge (sweep_line_t *sweep_line, edge_t *edge, int sign) -{ - struct cell *cell; - cairo_fixed_t x1, x2; - int ix1, ix2; - int frac; - - edge->current_sign = sign; - - ix1 = _cairo_fixed_integer_part (edge->x.quo); - - if (edge->vertical) { - frac = _cairo_fixed_fractional_part (edge->x.quo); - cell = coverage_find (sweep_line, ix1); - cell->covered_height += sign * STEP_Y; - cell->uncovered_area += sign * 2 * frac * STEP_Y; - return; - } - - x1 = edge->x.quo; - full_inc_edge (edge); - x2 = edge->x.quo; - - ix2 = _cairo_fixed_integer_part (edge->x.quo); - - /* Edge is entirely within a column? */ - if (likely (ix1 == ix2)) { - frac = _cairo_fixed_fractional_part (x1) + - _cairo_fixed_fractional_part (x2); - cell = coverage_find (sweep_line, ix1); - cell->covered_height += sign * STEP_Y; - cell->uncovered_area += sign * frac * STEP_Y; - return; - } - - coverage_render_cells (sweep_line, x1, x2, 0, STEP_Y, sign); -} - -static void -full_nonzero (sweep_line_t *sweep_line) -{ - cairo_list_t *pos; - - sweep_line->is_vertical = TRUE; - pos = sweep_line->active.next; - do { - edge_t *left = link_to_edge (pos), *right; - int winding = left->edge.dir; - - sweep_line->is_vertical &= left->vertical; - - pos = left->link.next; - do { - if (unlikely (pos == &sweep_line->active)) { - full_add_edge (sweep_line, left, +1); - return; - } - - right = link_to_edge (pos); - pos = pos->next; - sweep_line->is_vertical &= right->vertical; - - winding += right->edge.dir; - if (0 == winding) { - if (pos == &sweep_line->active || - link_to_edge (pos)->x.quo != right->x.quo) - { - break; - } - } - - if (! right->vertical) - full_inc_edge (right); - } while (TRUE); - - full_add_edge (sweep_line, left, +1); - full_add_edge (sweep_line, right, -1); - } while (pos != &sweep_line->active); -} - -static void -full_evenodd (sweep_line_t *sweep_line) -{ - cairo_list_t *pos; - - sweep_line->is_vertical = TRUE; - pos = sweep_line->active.next; - do { - edge_t *left = link_to_edge (pos), *right; - int winding = 0; - - sweep_line->is_vertical &= left->vertical; - - pos = left->link.next; - do { - if (pos == &sweep_line->active) { - full_add_edge (sweep_line, left, +1); - return; - } - - right = link_to_edge (pos); - pos = pos->next; - sweep_line->is_vertical &= right->vertical; - - if (++winding & 1) { - if (pos == &sweep_line->active || - link_to_edge (pos)->x.quo != right->x.quo) - { - break; - } - } - - if (! right->vertical) - full_inc_edge (right); - } while (TRUE); - - full_add_edge (sweep_line, left, +1); - full_add_edge (sweep_line, right, -1); - } while (pos != &sweep_line->active); -} - -static void -render_rows (cairo_botor_scan_converter_t *self, - sweep_line_t *sweep_line, - int y, int height, - cairo_span_renderer_t *renderer) -{ - cairo_half_open_span_t spans_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_half_open_span_t)]; - cairo_half_open_span_t *spans = spans_stack; - struct cell *cell; - int prev_x, cover; - int num_spans; - cairo_status_t status; - - if (unlikely (sweep_line->coverage.count == 0)) { - status = renderer->render_rows (renderer, y, height, NULL, 0); - if (unlikely (status)) - longjmp (sweep_line->unwind, status); - return; - } - - /* Allocate enough spans for the row. */ - - num_spans = 2*sweep_line->coverage.count+2; - if (unlikely (num_spans > ARRAY_LENGTH (spans_stack))) { - spans = _cairo_malloc_ab (num_spans, sizeof (cairo_half_open_span_t)); - if (unlikely (spans == NULL)) { - longjmp (sweep_line->unwind, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - } - - /* Form the spans from the coverage and areas. */ - num_spans = 0; - prev_x = self->xmin; - cover = 0; - cell = sweep_line->coverage.head.next; - do { - int x = cell->x; - int area; - - if (x > prev_x) { - spans[num_spans].x = prev_x; - spans[num_spans].inverse = 0; - spans[num_spans].coverage = AREA_TO_ALPHA (cover); - ++num_spans; - } - - cover += cell->covered_height*STEP_X*2; - area = cover - cell->uncovered_area; - - spans[num_spans].x = x; - spans[num_spans].coverage = AREA_TO_ALPHA (area); - ++num_spans; - - prev_x = x + 1; - } while ((cell = cell->next) != &sweep_line->coverage.tail); - - if (prev_x <= self->xmax) { - spans[num_spans].x = prev_x; - spans[num_spans].inverse = 0; - spans[num_spans].coverage = AREA_TO_ALPHA (cover); - ++num_spans; - } - - if (cover && prev_x < self->xmax) { - spans[num_spans].x = self->xmax; - spans[num_spans].inverse = 1; - spans[num_spans].coverage = 0; - ++num_spans; - } - - status = renderer->render_rows (renderer, y, height, spans, num_spans); - - if (unlikely (spans != spans_stack)) - free (spans); - - coverage_reset (&sweep_line->coverage); - - if (unlikely (status)) - longjmp (sweep_line->unwind, status); -} - -static void -full_repeat (sweep_line_t *sweep) -{ - edge_t *edge; - - cairo_list_foreach_entry (edge, edge_t, &sweep->active, link) { - if (edge->current_sign) - full_add_edge (sweep, edge, edge->current_sign); - else if (! edge->vertical) - full_inc_edge (edge); - } -} - -static void -full_reset (sweep_line_t *sweep) -{ - edge_t *edge; - - cairo_list_foreach_entry (edge, edge_t, &sweep->active, link) - edge->current_sign = 0; -} - -static void -full_step (cairo_botor_scan_converter_t *self, - sweep_line_t *sweep_line, - cairo_fixed_t row, - cairo_span_renderer_t *renderer) -{ - int top, bottom; - - top = _cairo_fixed_integer_part (sweep_line->current_row); - bottom = _cairo_fixed_integer_part (row); - if (cairo_list_is_empty (&sweep_line->active)) { - cairo_status_t status; - - status = renderer->render_rows (renderer, top, bottom - top, NULL, 0); - if (unlikely (status)) - longjmp (sweep_line->unwind, status); - - return; - } - - if (self->fill_rule == CAIRO_FILL_RULE_WINDING) - full_nonzero (sweep_line); - else - full_evenodd (sweep_line); - - if (sweep_line->is_vertical || bottom == top + 1) { - render_rows (self, sweep_line, top, bottom - top, renderer); - full_reset (sweep_line); - return; - } - - render_rows (self, sweep_line, top++, 1, renderer); - do { - full_repeat (sweep_line); - render_rows (self, sweep_line, top, 1, renderer); - } while (++top != bottom); - - full_reset (sweep_line); -} - -cairo_always_inline static void -sub_inc_edge (edge_t *edge, - cairo_fixed_t height) -{ - if (height == 1) { - edge->x.quo += edge->dxdy.quo; - edge->x.rem += edge->dxdy.rem; - if (edge->x.rem >= 0) { - ++edge->x.quo; - edge->x.rem -= edge->dy; - } - } else { - edge->x.quo += height * edge->dxdy.quo; - edge->x.rem += height * edge->dxdy.rem; - if (edge->x.rem >= 0) { - int carry = edge->x.rem / edge->dy + 1; - edge->x.quo += carry; - edge->x.rem -= carry * edge->dy; - } - } -} - -static void -sub_add_run (sweep_line_t *sweep_line, edge_t *edge, int y, int sign) -{ - struct run *run; - - run = _cairo_freepool_alloc (&sweep_line->runs); - if (unlikely (run == NULL)) - longjmp (sweep_line->unwind, _cairo_error (CAIRO_STATUS_NO_MEMORY)); - - run->y = y; - run->sign = sign; - run->next = edge->runs; - edge->runs = run; - - edge->current_sign = sign; -} - -inline static cairo_bool_t -edges_coincident (edge_t *left, edge_t *right, cairo_fixed_t y) -{ - /* XXX is compare_x_for_y() worth executing during sub steps? */ - return line_equal (&left->edge.line, &right->edge.line); - //edges_compare_x_for_y (&left->edge, &right->edge, y) >= 0; -} - -static void -sub_nonzero (sweep_line_t *sweep_line) -{ - cairo_fixed_t y = sweep_line->current_subrow; - cairo_fixed_t fy = _cairo_fixed_fractional_part (y); - cairo_list_t *pos; - - pos = sweep_line->active.next; - do { - edge_t *left = link_to_edge (pos), *right; - int winding = left->edge.dir; - - pos = left->link.next; - do { - if (unlikely (pos == &sweep_line->active)) { - if (left->current_sign != +1) - sub_add_run (sweep_line, left, fy, +1); - return; - } - - right = link_to_edge (pos); - pos = pos->next; - - winding += right->edge.dir; - if (0 == winding) { - if (pos == &sweep_line->active || - ! edges_coincident (right, link_to_edge (pos), y)) - { - break; - } - } - - if (right->current_sign) - sub_add_run (sweep_line, right, fy, 0); - } while (TRUE); - - if (left->current_sign != +1) - sub_add_run (sweep_line, left, fy, +1); - if (right->current_sign != -1) - sub_add_run (sweep_line, right, fy, -1); - } while (pos != &sweep_line->active); -} - -static void -sub_evenodd (sweep_line_t *sweep_line) -{ - cairo_fixed_t y = sweep_line->current_subrow; - cairo_fixed_t fy = _cairo_fixed_fractional_part (y); - cairo_list_t *pos; - - pos = sweep_line->active.next; - do { - edge_t *left = link_to_edge (pos), *right; - int winding = 0; - - pos = left->link.next; - do { - if (unlikely (pos == &sweep_line->active)) { - if (left->current_sign != +1) - sub_add_run (sweep_line, left, fy, +1); - return; - } - - right = link_to_edge (pos); - pos = pos->next; - - if (++winding & 1) { - if (pos == &sweep_line->active || - ! edges_coincident (right, link_to_edge (pos), y)) - { - break; - } - } - - if (right->current_sign) - sub_add_run (sweep_line, right, fy, 0); - } while (TRUE); - - if (left->current_sign != +1) - sub_add_run (sweep_line, left, fy, +1); - if (right->current_sign != -1) - sub_add_run (sweep_line, right, fy, -1); - } while (pos != &sweep_line->active); -} - -cairo_always_inline static void -sub_step (cairo_botor_scan_converter_t *self, - sweep_line_t *sweep_line) -{ - if (cairo_list_is_empty (&sweep_line->active)) - return; - - if (self->fill_rule == CAIRO_FILL_RULE_WINDING) - sub_nonzero (sweep_line); - else - sub_evenodd (sweep_line); -} - -static void -coverage_render_runs (sweep_line_t *sweep, edge_t *edge, - cairo_fixed_t y1, cairo_fixed_t y2) -{ - struct run tail; - struct run *run = &tail; - - tail.next = NULL; - tail.y = y2; - - /* Order the runs top->bottom */ - while (edge->runs) { - struct run *r; - - r = edge->runs; - edge->runs = r->next; - r->next = run; - run = r; - } - - if (run->y > y1) - sub_inc_edge (edge, run->y - y1); - - do { - cairo_fixed_t x1, x2; - - y1 = run->y; - y2 = run->next->y; - - x1 = edge->x.quo; - if (y2 - y1 == STEP_Y) - full_inc_edge (edge); - else - sub_inc_edge (edge, y2 - y1); - x2 = edge->x.quo; - - if (run->sign) { - int ix1, ix2; - - ix1 = _cairo_fixed_integer_part (x1); - ix2 = _cairo_fixed_integer_part (x2); - - /* Edge is entirely within a column? */ - if (likely (ix1 == ix2)) { - struct cell *cell; - int frac; - - frac = _cairo_fixed_fractional_part (x1) + - _cairo_fixed_fractional_part (x2); - cell = coverage_find (sweep, ix1); - cell->covered_height += run->sign * (y2 - y1); - cell->uncovered_area += run->sign * (y2 - y1) * frac; - } else { - coverage_render_cells (sweep, x1, x2, y1, y2, run->sign); - } - } - - run = run->next; - } while (run->next != NULL); -} - -static void -coverage_render_vertical_runs (sweep_line_t *sweep, edge_t *edge, cairo_fixed_t y2) -{ - struct cell *cell; - struct run *run; - int height = 0; - - for (run = edge->runs; run != NULL; run = run->next) { - if (run->sign) - height += run->sign * (y2 - run->y); - y2 = run->y; - } - - cell = coverage_find (sweep, _cairo_fixed_integer_part (edge->x.quo)); - cell->covered_height += height; - cell->uncovered_area += 2 * _cairo_fixed_fractional_part (edge->x.quo) * height; -} - -cairo_always_inline static void -sub_emit (cairo_botor_scan_converter_t *self, - sweep_line_t *sweep, - cairo_span_renderer_t *renderer) -{ - edge_t *edge; - - sub_step (self, sweep); - - /* convert the runs into coverages */ - - cairo_list_foreach_entry (edge, edge_t, &sweep->active, link) { - if (edge->runs == NULL) { - if (! edge->vertical) { - if (edge->flags & START) { - sub_inc_edge (edge, - STEP_Y - _cairo_fixed_fractional_part (edge->edge.top)); - edge->flags &= ~START; - } else - full_inc_edge (edge); - } - } else { - if (edge->vertical) { - coverage_render_vertical_runs (sweep, edge, STEP_Y); - } else { - int y1 = 0; - if (edge->flags & START) { - y1 = _cairo_fixed_fractional_part (edge->edge.top); - edge->flags &= ~START; - } - coverage_render_runs (sweep, edge, y1, STEP_Y); - } - } - edge->current_sign = 0; - edge->runs = NULL; - } - - cairo_list_foreach_entry (edge, edge_t, &sweep->stopped, link) { - int y2 = _cairo_fixed_fractional_part (edge->edge.bottom); - if (edge->vertical) { - coverage_render_vertical_runs (sweep, edge, y2); - } else { - int y1 = 0; - if (edge->flags & START) - y1 = _cairo_fixed_fractional_part (edge->edge.top); - coverage_render_runs (sweep, edge, y1, y2); - } - } - cairo_list_init (&sweep->stopped); - - _cairo_freepool_reset (&sweep->runs); - - render_rows (self, sweep, - _cairo_fixed_integer_part (sweep->current_row), 1, - renderer); -} - -static void -sweep_line_init (sweep_line_t *sweep_line, - event_t **start_events, - int num_events) -{ - cairo_list_init (&sweep_line->active); - cairo_list_init (&sweep_line->stopped); - sweep_line->insert_cursor = &sweep_line->active; - - sweep_line->current_row = INT32_MIN; - sweep_line->current_subrow = INT32_MIN; - - coverage_init (&sweep_line->coverage); - _cairo_freepool_init (&sweep_line->runs, sizeof (struct run)); - - start_event_sort (start_events, num_events); - start_events[num_events] = NULL; - - sweep_line->queue.start_events = start_events; - - _cairo_freepool_init (&sweep_line->queue.pool, - sizeof (queue_event_t)); - pqueue_init (&sweep_line->queue.pq); - sweep_line->queue.pq.elements[PQ_FIRST_ENTRY] = NULL; -} - -static void -sweep_line_delete (sweep_line_t *sweep_line, - edge_t *edge) -{ - if (sweep_line->insert_cursor == &edge->link) - sweep_line->insert_cursor = edge->link.prev; - - cairo_list_del (&edge->link); - if (edge->runs) - cairo_list_add_tail (&edge->link, &sweep_line->stopped); - edge->flags |= STOP; -} - -static void -sweep_line_swap (sweep_line_t *sweep_line, - edge_t *left, - edge_t *right) -{ - right->link.prev = left->link.prev; - left->link.next = right->link.next; - right->link.next = &left->link; - left->link.prev = &right->link; - left->link.next->prev = &left->link; - right->link.prev->next = &right->link; -} - -static void -sweep_line_fini (sweep_line_t *sweep_line) -{ - pqueue_fini (&sweep_line->queue.pq); - _cairo_freepool_fini (&sweep_line->queue.pool); - coverage_fini (&sweep_line->coverage); - _cairo_freepool_fini (&sweep_line->runs); -} - -static cairo_status_t -botor_generate (cairo_botor_scan_converter_t *self, - event_t **start_events, - cairo_span_renderer_t *renderer) -{ - cairo_status_t status; - sweep_line_t sweep_line; - cairo_fixed_t ybot; - event_t *event; - cairo_list_t *left, *right; - edge_t *e1, *e2; - int bottom; - - sweep_line_init (&sweep_line, start_events, self->num_edges); - if ((status = setjmp (sweep_line.unwind))) - goto unwind; - - ybot = self->extents.p2.y; - sweep_line.current_subrow = self->extents.p1.y; - sweep_line.current_row = _cairo_fixed_floor (self->extents.p1.y); - event = *sweep_line.queue.start_events++; - do { - /* Can we process a full step in one go? */ - if (event->y >= sweep_line.current_row + STEP_Y) { - bottom = _cairo_fixed_floor (event->y); - full_step (self, &sweep_line, bottom, renderer); - sweep_line.current_row = bottom; - sweep_line.current_subrow = bottom; - } - - do { - if (event->y > sweep_line.current_subrow) { - sub_step (self, &sweep_line); - sweep_line.current_subrow = event->y; - } - - do { - /* Update the active list using Bentley-Ottmann */ - switch (event->type) { - case EVENT_TYPE_START: - e1 = ((start_event_t *) event)->edge; - - sweep_line_insert (&sweep_line, e1); - event_insert_stop (&sweep_line, e1); - - left = e1->link.prev; - right = e1->link.next; - - if (left != &sweep_line.active) { - event_insert_if_intersect_below_current_y (&sweep_line, - link_to_edge (left), e1); - } - - if (right != &sweep_line.active) { - event_insert_if_intersect_below_current_y (&sweep_line, - e1, link_to_edge (right)); - } - - break; - - case EVENT_TYPE_STOP: - e1 = ((queue_event_t *) event)->e1; - event_delete (&sweep_line, event); - - left = e1->link.prev; - right = e1->link.next; - - sweep_line_delete (&sweep_line, e1); - - if (left != &sweep_line.active && - right != &sweep_line.active) - { - event_insert_if_intersect_below_current_y (&sweep_line, - link_to_edge (left), - link_to_edge (right)); - } - - break; - - case EVENT_TYPE_INTERSECTION: - e1 = ((queue_event_t *) event)->e1; - e2 = ((queue_event_t *) event)->e2; - - event_delete (&sweep_line, event); - if (e1->flags & STOP) - break; - if (e2->flags & STOP) - break; - - /* skip this intersection if its edges are not adjacent */ - if (&e2->link != e1->link.next) - break; - - left = e1->link.prev; - right = e2->link.next; - - sweep_line_swap (&sweep_line, e1, e2); - - /* after the swap e2 is left of e1 */ - if (left != &sweep_line.active) { - event_insert_if_intersect_below_current_y (&sweep_line, - link_to_edge (left), e2); - } - - if (right != &sweep_line.active) { - event_insert_if_intersect_below_current_y (&sweep_line, - e1, link_to_edge (right)); - } - - break; - } - - event = event_next (&sweep_line); - if (event == NULL) - goto end; - } while (event->y == sweep_line.current_subrow); - } while (event->y < sweep_line.current_row + STEP_Y); - - bottom = sweep_line.current_row + STEP_Y; - sub_emit (self, &sweep_line, renderer); - sweep_line.current_subrow = bottom; - sweep_line.current_row = sweep_line.current_subrow; - } while (TRUE); - - end: - /* flush any partial spans */ - if (sweep_line.current_subrow != sweep_line.current_row) { - sub_emit (self, &sweep_line, renderer); - sweep_line.current_row += STEP_Y; - sweep_line.current_subrow = sweep_line.current_row; - } - /* clear the rest */ - if (sweep_line.current_subrow < ybot) { - bottom = _cairo_fixed_integer_part (sweep_line.current_row); - status = renderer->render_rows (renderer, - bottom, _cairo_fixed_integer_ceil (ybot) - bottom, - NULL, 0); - } - - unwind: - sweep_line_fini (&sweep_line); - - return status; -} - -static cairo_status_t -_cairo_botor_scan_converter_generate (void *converter, - cairo_span_renderer_t *renderer) -{ - cairo_botor_scan_converter_t *self = converter; - start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (start_event_t)]; - start_event_t *events; - event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; - event_t **event_ptrs; - struct _cairo_botor_scan_converter_chunk *chunk; - cairo_status_t status; - int num_events; - int i, j; - - num_events = self->num_edges; - if (unlikely (0 == num_events)) { - return renderer->render_rows (renderer, - _cairo_fixed_integer_floor (self->extents.p1.y), - _cairo_fixed_integer_ceil (self->extents.p2.y) - - _cairo_fixed_integer_floor (self->extents.p1.y), - NULL, 0); - } - - events = stack_events; - event_ptrs = stack_event_ptrs; - if (unlikely (num_events >= ARRAY_LENGTH (stack_events))) { - events = _cairo_malloc_ab_plus_c (num_events, - sizeof (start_event_t) + sizeof (event_t *), - sizeof (event_t *)); - if (unlikely (events == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event_ptrs = (event_t **) (events + num_events); - } - - j = 0; - for (chunk = &self->chunks; chunk != NULL; chunk = chunk->next) { - edge_t *edge; - - edge = chunk->base; - for (i = 0; i < chunk->count; i++) { - event_ptrs[j] = (event_t *) &events[j]; - - events[j].y = edge->edge.top; - events[j].type = EVENT_TYPE_START; - events[j].edge = edge; - - edge++, j++; - } - } - - status = botor_generate (self, event_ptrs, renderer); - - if (events != stack_events) - free (events); - - return status; -} - -static edge_t * -botor_allocate_edge (cairo_botor_scan_converter_t *self) -{ - struct _cairo_botor_scan_converter_chunk *chunk; - - chunk = self->tail; - if (chunk->count == chunk->size) { - int size; - - size = chunk->size * 2; - chunk->next = _cairo_malloc_ab_plus_c (size, - sizeof (edge_t), - sizeof (struct _cairo_botor_scan_converter_chunk)); - if (unlikely (chunk->next == NULL)) - return NULL; - - chunk = chunk->next; - chunk->next = NULL; - chunk->count = 0; - chunk->size = size; - chunk->base = chunk + 1; - self->tail = chunk; - } - - return (edge_t *) chunk->base + chunk->count++; -} - -static cairo_status_t -botor_add_edge (cairo_botor_scan_converter_t *self, - const cairo_edge_t *edge) -{ - edge_t *e; - cairo_fixed_t dx, dy; - - e = botor_allocate_edge (self); - if (unlikely (e == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - cairo_list_init (&e->link); - e->edge = *edge; - - dx = edge->line.p2.x - edge->line.p1.x; - dy = edge->line.p2.y - edge->line.p1.y; - e->dy = dy; - - if (dx == 0) { - e->vertical = TRUE; - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - e->dxdy.quo = 0; - e->dxdy.rem = 0; - e->dxdy_full.quo = 0; - e->dxdy_full.rem = 0; - } else { - e->vertical = FALSE; - e->dxdy = floored_divrem (dx, dy); - if (edge->top == edge->line.p1.y) { - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - } else { - e->x = floored_muldivrem (edge->top - edge->line.p1.y, - dx, dy); - e->x.quo += edge->line.p1.x; - } - - if (_cairo_fixed_integer_part (edge->bottom) - _cairo_fixed_integer_part (edge->top) > 1) { - e->dxdy_full = floored_muldivrem (STEP_Y, dx, dy); - } else { - e->dxdy_full.quo = 0; - e->dxdy_full.rem = 0; - } - } - - e->x.rem = -e->dy; - e->current_sign = 0; - e->runs = NULL; - e->flags = START; - - self->num_edges++; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_botor_scan_converter_destroy (void *converter) -{ - cairo_botor_scan_converter_t *self = converter; - struct _cairo_botor_scan_converter_chunk *chunk, *next; - - for (chunk = self->chunks.next; chunk != NULL; chunk = next) { - next = chunk->next; - free (chunk); - } -} - -void -_cairo_botor_scan_converter_init (cairo_botor_scan_converter_t *self, - const cairo_box_t *extents, - cairo_fill_rule_t fill_rule) -{ - self->base.destroy = _cairo_botor_scan_converter_destroy; - self->base.generate = _cairo_botor_scan_converter_generate; - - self->extents = *extents; - self->fill_rule = fill_rule; - - self->xmin = _cairo_fixed_integer_floor (extents->p1.x); - self->xmax = _cairo_fixed_integer_ceil (extents->p2.x); - - self->chunks.base = self->buf; - self->chunks.next = NULL; - self->chunks.count = 0; - self->chunks.size = sizeof (self->buf) / sizeof (edge_t); - self->tail = &self->chunks; - - self->num_edges = 0; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-box-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-box-inline.h deleted file mode 100644 index d6b994127e3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-box-inline.h +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Andrea Canciani - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Andrea Canciani - */ - -#ifndef CAIRO_BOX_H -#define CAIRO_BOX_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" -#include "cairo-fixed-private.h" - -static inline void -_cairo_box_set (cairo_box_t *box, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - box->p1 = *p1; - box->p2 = *p2; -} - -static inline void -_cairo_box_from_integers (cairo_box_t *box, int x, int y, int w, int h) -{ - box->p1.x = _cairo_fixed_from_int (x); - box->p1.y = _cairo_fixed_from_int (y); - box->p2.x = _cairo_fixed_from_int (x + w); - box->p2.y = _cairo_fixed_from_int (y + h); -} - -/* assumes box->p1 is top-left, p2 bottom-right */ -static inline void -_cairo_box_add_point (cairo_box_t *box, - const cairo_point_t *point) -{ - if (point->x < box->p1.x) - box->p1.x = point->x; - else if (point->x > box->p2.x) - box->p2.x = point->x; - - if (point->y < box->p1.y) - box->p1.y = point->y; - else if (point->y > box->p2.y) - box->p2.y = point->y; -} - -static inline void -_cairo_box_add_box (cairo_box_t *box, - const cairo_box_t *add) -{ - if (add->p1.x < box->p1.x) - box->p1.x = add->p1.x; - if (add->p2.x > box->p2.x) - box->p2.x = add->p2.x; - - if (add->p1.y < box->p1.y) - box->p1.y = add->p1.y; - if (add->p2.y > box->p2.y) - box->p2.y = add->p2.y; -} - -/* assumes box->p1 is top-left, p2 bottom-right */ -static inline cairo_bool_t -_cairo_box_contains_point (const cairo_box_t *box, - const cairo_point_t *point) -{ - return box->p1.x <= point->x && point->x <= box->p2.x && - box->p1.y <= point->y && point->y <= box->p2.y; -} - -static inline cairo_bool_t -_cairo_box_is_pixel_aligned (const cairo_box_t *box) -{ -#if CAIRO_FIXED_FRAC_BITS <= 8 && 0 - return ((box->p1.x & CAIRO_FIXED_FRAC_MASK) << 24 | - (box->p1.y & CAIRO_FIXED_FRAC_MASK) << 16 | - (box->p2.x & CAIRO_FIXED_FRAC_MASK) << 8 | - (box->p2.y & CAIRO_FIXED_FRAC_MASK) << 0) == 0; -#else /* GCC on i7 prefers this variant (bizarrely according to the profiler) */ - cairo_fixed_t f; - - f = 0; - f |= box->p1.x & CAIRO_FIXED_FRAC_MASK; - f |= box->p1.y & CAIRO_FIXED_FRAC_MASK; - f |= box->p2.x & CAIRO_FIXED_FRAC_MASK; - f |= box->p2.y & CAIRO_FIXED_FRAC_MASK; - - return f == 0; -#endif -} - -#endif /* CAIRO_BOX_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-intersect.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-intersect.c deleted file mode 100644 index 96ae66334e6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-intersect.c +++ /dev/null @@ -1,690 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-combsort-inline.h" -#include "cairo-list-private.h" - -#include - -typedef struct _rectangle rectangle_t; -typedef struct _edge edge_t; - -struct _edge { - edge_t *next, *prev; - edge_t *right; - cairo_fixed_t x, top; - int a_or_b; - int dir; -}; - -struct _rectangle { - edge_t left, right; - int32_t top, bottom; -}; - -#define UNROLL3(x) x x x - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef struct _pqueue { - int size, max_size; - - rectangle_t **elements; - rectangle_t *elements_embedded[1024]; -} pqueue_t; - -typedef struct _sweep_line { - rectangle_t **rectangles; - pqueue_t pq; - edge_t head, tail; - edge_t *insert_left, *insert_right; - int32_t current_y; - int32_t last_y; - - jmp_buf unwind; -} sweep_line_t; - -#define DEBUG_TRAPS 0 - -#if DEBUG_TRAPS -static void -dump_traps (cairo_traps_t *traps, const char *filename) -{ - FILE *file; - int n; - - if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) - return; - - file = fopen (filename, "a"); - if (file != NULL) { - for (n = 0; n < traps->num_traps; n++) { - fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", - traps->traps[n].top, - traps->traps[n].bottom, - traps->traps[n].left.p1.x, - traps->traps[n].left.p1.y, - traps->traps[n].left.p2.x, - traps->traps[n].left.p2.y, - traps->traps[n].right.p1.x, - traps->traps[n].right.p1.y, - traps->traps[n].right.p2.x, - traps->traps[n].right.p2.y); - } - fprintf (file, "\n"); - fclose (file); - } -} -#else -#define dump_traps(traps, filename) -#endif - -static inline int -rectangle_compare_start (const rectangle_t *a, - const rectangle_t *b) -{ - return a->top - b->top; -} - -static inline int -rectangle_compare_stop (const rectangle_t *a, - const rectangle_t *b) -{ - return a->bottom - b->bottom; -} - -static inline void -pqueue_init (pqueue_t *pq) -{ - pq->max_size = ARRAY_LENGTH (pq->elements_embedded); - pq->size = 0; - - pq->elements = pq->elements_embedded; - pq->elements[PQ_FIRST_ENTRY] = NULL; -} - -static inline void -pqueue_fini (pqueue_t *pq) -{ - if (pq->elements != pq->elements_embedded) - free (pq->elements); -} - -static cairo_bool_t -pqueue_grow (pqueue_t *pq) -{ - rectangle_t **new_elements; - pq->max_size *= 2; - - if (pq->elements == pq->elements_embedded) { - new_elements = _cairo_malloc_ab (pq->max_size, - sizeof (rectangle_t *)); - if (unlikely (new_elements == NULL)) - return FALSE; - - memcpy (new_elements, pq->elements_embedded, - sizeof (pq->elements_embedded)); - } else { - new_elements = _cairo_realloc_ab (pq->elements, - pq->max_size, - sizeof (rectangle_t *)); - if (unlikely (new_elements == NULL)) - return FALSE; - } - - pq->elements = new_elements; - return TRUE; -} - -static inline void -pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle) -{ - rectangle_t **elements; - int i, parent; - - if (unlikely (sweep->pq.size + 1 == sweep->pq.max_size)) { - if (unlikely (! pqueue_grow (&sweep->pq))) { - longjmp (sweep->unwind, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - } - - elements = sweep->pq.elements; - for (i = ++sweep->pq.size; - i != PQ_FIRST_ENTRY && - rectangle_compare_stop (rectangle, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = rectangle; -} - -static inline void -pqueue_pop (pqueue_t *pq) -{ - rectangle_t **elements = pq->elements; - rectangle_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - rectangle_compare_stop (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (rectangle_compare_stop (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline rectangle_t * -rectangle_pop_start (sweep_line_t *sweep_line) -{ - return *sweep_line->rectangles++; -} - -static inline rectangle_t * -rectangle_peek_stop (sweep_line_t *sweep_line) -{ - return sweep_line->pq.elements[PQ_FIRST_ENTRY]; -} - -CAIRO_COMBSORT_DECLARE (_rectangle_sort, - rectangle_t *, - rectangle_compare_start) - -static void -sweep_line_init (sweep_line_t *sweep_line, - rectangle_t **rectangles, - int num_rectangles) -{ - _rectangle_sort (rectangles, num_rectangles); - rectangles[num_rectangles] = NULL; - sweep_line->rectangles = rectangles; - - sweep_line->head.x = INT32_MIN; - sweep_line->head.right = NULL; - sweep_line->head.dir = 0; - sweep_line->head.next = &sweep_line->tail; - sweep_line->tail.x = INT32_MAX; - sweep_line->tail.right = NULL; - sweep_line->tail.dir = 0; - sweep_line->tail.prev = &sweep_line->head; - - sweep_line->insert_left = &sweep_line->tail; - sweep_line->insert_right = &sweep_line->tail; - - sweep_line->current_y = INT32_MIN; - sweep_line->last_y = INT32_MIN; - - pqueue_init (&sweep_line->pq); -} - -static void -sweep_line_fini (sweep_line_t *sweep_line) -{ - pqueue_fini (&sweep_line->pq); -} - -static void -end_box (sweep_line_t *sweep_line, edge_t *left, int32_t bot, cairo_boxes_t *out) -{ - if (likely (left->top < bot)) { - cairo_status_t status; - cairo_box_t box; - - box.p1.x = left->x; - box.p1.y = left->top; - box.p2.x = left->right->x; - box.p2.y = bot; - - status = _cairo_boxes_add (out, CAIRO_ANTIALIAS_DEFAULT, &box); - if (unlikely (status)) - longjmp (sweep_line->unwind, status); - } - - left->right = NULL; -} - -/* Start a new trapezoid at the given top y coordinate, whose edges - * are `edge' and `edge->next'. If `edge' already has a trapezoid, - * then either add it to the traps in `traps', if the trapezoid's - * right edge differs from `edge->next', or do nothing if the new - * trapezoid would be a continuation of the existing one. */ -static inline void -start_or_continue_box (sweep_line_t *sweep_line, - edge_t *left, - edge_t *right, - int top, - cairo_boxes_t *out) -{ - if (left->right == right) - return; - - if (left->right != NULL) { - if (right != NULL && left->right->x == right->x) { - /* continuation on right, so just swap edges */ - left->right = right; - return; - } - - end_box (sweep_line, left, top, out); - } - - if (right != NULL && left->x != right->x) { - left->top = top; - left->right = right; - } -} - -static inline int is_zero(const int *winding) -{ - return winding[0] == 0 || winding[1] == 0; -} - -static inline void -active_edges (sweep_line_t *sweep, cairo_boxes_t *out) -{ - int top = sweep->current_y; - int winding[2] = { 0 }; - edge_t *pos; - - if (sweep->last_y == sweep->current_y) - return; - - pos = sweep->head.next; - if (pos == &sweep->tail) - return; - - do { - edge_t *left, *right; - - left = pos; - do { - winding[left->a_or_b] += left->dir; - if (!is_zero (winding)) - break; - if (left->next == &sweep->tail) - goto out; - - if (unlikely (left->right != NULL)) - end_box (sweep, left, top, out); - - left = left->next; - } while (1); - - right = left->next; - do { - if (unlikely (right->right != NULL)) - end_box (sweep, right, top, out); - - winding[right->a_or_b] += right->dir; - if (is_zero (winding)) { - /* skip co-linear edges */ - if (likely (right->x != right->next->x)) - break; - } - - right = right->next; - } while (TRUE); - - start_or_continue_box (sweep, left, right, top, out); - - pos = right->next; - } while (pos != &sweep->tail); - -out: - sweep->last_y = sweep->current_y; -} - -static inline void -sweep_line_delete_edge (sweep_line_t *sweep_line, edge_t *edge, cairo_boxes_t *out) -{ - if (edge->right != NULL) { - edge_t *next = edge->next; - if (next->x == edge->x) { - next->top = edge->top; - next->right = edge->right; - } else { - end_box (sweep_line, edge, sweep_line->current_y, out); - } - } - - if (sweep_line->insert_left == edge) - sweep_line->insert_left = edge->next; - if (sweep_line->insert_right == edge) - sweep_line->insert_right = edge->next; - - edge->prev->next = edge->next; - edge->next->prev = edge->prev; -} - -static inline void -sweep_line_delete (sweep_line_t *sweep, - rectangle_t *rectangle, - cairo_boxes_t *out) -{ - sweep_line_delete_edge (sweep, &rectangle->left, out); - sweep_line_delete_edge (sweep, &rectangle->right, out); - - pqueue_pop (&sweep->pq); -} - -static inline void -insert_edge (edge_t *edge, edge_t *pos) -{ - if (pos->x != edge->x) { - if (pos->x > edge->x) { - do { - UNROLL3({ - if (pos->prev->x <= edge->x) - break; - pos = pos->prev; - }) - } while (TRUE); - } else { - do { - UNROLL3({ - pos = pos->next; - if (pos->x >= edge->x) - break; - }) - } while (TRUE); - } - } - - pos->prev->next = edge; - edge->prev = pos->prev; - edge->next = pos; - pos->prev = edge; -} - -static inline void -sweep_line_insert (sweep_line_t *sweep, rectangle_t *rectangle) -{ - edge_t *pos; - - /* right edge */ - pos = sweep->insert_right; - insert_edge (&rectangle->right, pos); - sweep->insert_right = &rectangle->right; - - /* left edge */ - pos = sweep->insert_left; - if (pos->x > sweep->insert_right->x) - pos = sweep->insert_right->prev; - insert_edge (&rectangle->left, pos); - sweep->insert_left = &rectangle->left; - - pqueue_push (sweep, rectangle); -} - -static cairo_status_t -intersect (rectangle_t **rectangles, int num_rectangles, cairo_boxes_t *out) -{ - sweep_line_t sweep_line; - rectangle_t *rectangle; - cairo_status_t status; - - sweep_line_init (&sweep_line, rectangles, num_rectangles); - if ((status = setjmp (sweep_line.unwind))) - goto unwind; - - rectangle = rectangle_pop_start (&sweep_line); - do { - if (rectangle->top != sweep_line.current_y) { - rectangle_t *stop; - - stop = rectangle_peek_stop (&sweep_line); - while (stop != NULL && stop->bottom < rectangle->top) { - if (stop->bottom != sweep_line.current_y) { - active_edges (&sweep_line, out); - sweep_line.current_y = stop->bottom; - } - - sweep_line_delete (&sweep_line, stop, out); - - stop = rectangle_peek_stop (&sweep_line); - } - - active_edges (&sweep_line, out); - sweep_line.current_y = rectangle->top; - } - - sweep_line_insert (&sweep_line, rectangle); - } while ((rectangle = rectangle_pop_start (&sweep_line)) != NULL); - - while ((rectangle = rectangle_peek_stop (&sweep_line)) != NULL) { - if (rectangle->bottom != sweep_line.current_y) { - active_edges (&sweep_line, out); - sweep_line.current_y = rectangle->bottom; - } - - sweep_line_delete (&sweep_line, rectangle, out); - } - -unwind: - sweep_line_fini (&sweep_line); - return status; -} - -static cairo_status_t -_cairo_boxes_intersect_with_box (const cairo_boxes_t *boxes, - const cairo_box_t *box, - cairo_boxes_t *out) -{ - cairo_status_t status; - int i, j; - - if (out == boxes) { /* inplace update */ - struct _cairo_boxes_chunk *chunk; - - out->num_boxes = 0; - for (chunk = &out->chunks; chunk != NULL; chunk = chunk->next) { - for (i = j = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - - b->p1.x = MAX (b->p1.x, box->p1.x); - b->p1.y = MAX (b->p1.y, box->p1.y); - b->p2.x = MIN (b->p2.x, box->p2.x); - b->p2.y = MIN (b->p2.y, box->p2.y); - if (b->p1.x < b->p2.x && b->p1.y < b->p2.y) { - if (i != j) - chunk->base[j] = *b; - j++; - } - } - /* XXX unlink empty chains? */ - chunk->count = j; - out->num_boxes += j; - } - } else { - const struct _cairo_boxes_chunk *chunk; - - _cairo_boxes_clear (out); - _cairo_boxes_limit (out, box, 1); - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - status = _cairo_boxes_add (out, - CAIRO_ANTIALIAS_DEFAULT, - &chunk->base[i]); - if (unlikely (status)) - return status; - } - } - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_boxes_intersect (const cairo_boxes_t *a, - const cairo_boxes_t *b, - cairo_boxes_t *out) -{ - rectangle_t stack_rectangles[CAIRO_STACK_ARRAY_LENGTH (rectangle_t)]; - rectangle_t *rectangles; - rectangle_t *stack_rectangles_ptrs[ARRAY_LENGTH (stack_rectangles) + 1]; - rectangle_t **rectangles_ptrs; - const struct _cairo_boxes_chunk *chunk; - cairo_status_t status; - int i, j, count; - - if (unlikely (a->num_boxes == 0 || b->num_boxes == 0)) { - _cairo_boxes_clear (out); - return CAIRO_STATUS_SUCCESS; - } - - if (a->num_boxes == 1) { - cairo_box_t box = a->chunks.base[0]; - return _cairo_boxes_intersect_with_box (b, &box, out); - } - if (b->num_boxes == 1) { - cairo_box_t box = b->chunks.base[0]; - return _cairo_boxes_intersect_with_box (a, &box, out); - } - - rectangles = stack_rectangles; - rectangles_ptrs = stack_rectangles_ptrs; - count = a->num_boxes + b->num_boxes; - if (count > ARRAY_LENGTH (stack_rectangles)) { - rectangles = _cairo_malloc_ab_plus_c (count, - sizeof (rectangle_t) + - sizeof (rectangle_t *), - sizeof (rectangle_t *)); - if (unlikely (rectangles == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - rectangles_ptrs = (rectangle_t **) (rectangles + count); - } - - j = 0; - for (chunk = &a->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box = chunk->base; - for (i = 0; i < chunk->count; i++) { - if (box[i].p1.x < box[i].p2.x) { - rectangles[j].left.x = box[i].p1.x; - rectangles[j].left.dir = 1; - - rectangles[j].right.x = box[i].p2.x; - rectangles[j].right.dir = -1; - } else { - rectangles[j].right.x = box[i].p1.x; - rectangles[j].right.dir = 1; - - rectangles[j].left.x = box[i].p2.x; - rectangles[j].left.dir = -1; - } - - rectangles[j].left.a_or_b = 0; - rectangles[j].left.right = NULL; - rectangles[j].right.a_or_b = 0; - rectangles[j].right.right = NULL; - - rectangles[j].top = box[i].p1.y; - rectangles[j].bottom = box[i].p2.y; - - rectangles_ptrs[j] = &rectangles[j]; - j++; - } - } - for (chunk = &b->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box = chunk->base; - for (i = 0; i < chunk->count; i++) { - if (box[i].p1.x < box[i].p2.x) { - rectangles[j].left.x = box[i].p1.x; - rectangles[j].left.dir = 1; - - rectangles[j].right.x = box[i].p2.x; - rectangles[j].right.dir = -1; - } else { - rectangles[j].right.x = box[i].p1.x; - rectangles[j].right.dir = 1; - - rectangles[j].left.x = box[i].p2.x; - rectangles[j].left.dir = -1; - } - - rectangles[j].left.a_or_b = 1; - rectangles[j].left.right = NULL; - rectangles[j].right.a_or_b = 1; - rectangles[j].right.right = NULL; - - rectangles[j].top = box[i].p1.y; - rectangles[j].bottom = box[i].p2.y; - - rectangles_ptrs[j] = &rectangles[j]; - j++; - } - } - assert (j == count); - - _cairo_boxes_clear (out); - status = intersect (rectangles_ptrs, j, out); - if (rectangles != stack_rectangles) - free (rectangles); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-private.h deleted file mode 100644 index d1f9dfcd1e5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes-private.h +++ /dev/null @@ -1,123 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_BOXES_H -#define CAIRO_BOXES_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" - -#include -#include - -struct _cairo_boxes_t { - cairo_status_t status; - - cairo_box_t limit; - const cairo_box_t *limits; - int num_limits; - - int num_boxes; - - unsigned int is_pixel_aligned; - - struct _cairo_boxes_chunk { - struct _cairo_boxes_chunk *next; - cairo_box_t *base; - int count; - int size; - } chunks, *tail; - cairo_box_t boxes_embedded[32]; -}; - -cairo_private void -_cairo_boxes_init (cairo_boxes_t *boxes); - -cairo_private void -_cairo_boxes_init_with_clip (cairo_boxes_t *boxes, - cairo_clip_t *clip); - -cairo_private void -_cairo_boxes_init_for_array (cairo_boxes_t *boxes, - cairo_box_t *array, - int num_boxes); - -cairo_private void -_cairo_boxes_init_from_rectangle (cairo_boxes_t *boxes, - int x, int y, int w, int h); - -cairo_private void -_cairo_boxes_limit (cairo_boxes_t *boxes, - const cairo_box_t *limits, - int num_limits); - -cairo_private cairo_status_t -_cairo_boxes_add (cairo_boxes_t *boxes, - cairo_antialias_t antialias, - const cairo_box_t *box); - -cairo_private void -_cairo_boxes_extents (const cairo_boxes_t *boxes, - cairo_box_t *box); - -cairo_private cairo_box_t * -_cairo_boxes_to_array (const cairo_boxes_t *boxes, - int *num_boxes, - cairo_bool_t force_allocation); - -cairo_private cairo_status_t -_cairo_boxes_intersect (const cairo_boxes_t *a, - const cairo_boxes_t *b, - cairo_boxes_t *out); - -cairo_private void -_cairo_boxes_clear (cairo_boxes_t *boxes); - -cairo_private_no_warn cairo_bool_t -_cairo_boxes_for_each_box (cairo_boxes_t *boxes, - cairo_bool_t (*func) (cairo_box_t *box, void *data), - void *data); - -cairo_private cairo_status_t -_cairo_rasterise_polygon_to_boxes (cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_boxes_t *boxes); - -cairo_private void -_cairo_boxes_fini (cairo_boxes_t *boxes); - -cairo_private void -_cairo_debug_print_boxes (FILE *stream, - const cairo_boxes_t *boxes); - -#endif /* CAIRO_BOXES_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes.c deleted file mode 100644 index 63b68ddfb90..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-boxes.c +++ /dev/null @@ -1,460 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" - -void -_cairo_boxes_init (cairo_boxes_t *boxes) -{ - boxes->status = CAIRO_STATUS_SUCCESS; - boxes->num_limits = 0; - boxes->num_boxes = 0; - - boxes->tail = &boxes->chunks; - boxes->chunks.next = NULL; - boxes->chunks.base = boxes->boxes_embedded; - boxes->chunks.size = ARRAY_LENGTH (boxes->boxes_embedded); - boxes->chunks.count = 0; - - boxes->is_pixel_aligned = TRUE; -} - -void -_cairo_boxes_init_from_rectangle (cairo_boxes_t *boxes, - int x, int y, int w, int h) -{ - _cairo_boxes_init (boxes); - - _cairo_box_from_integers (&boxes->chunks.base[0], x, y, w, h); - boxes->num_boxes = 1; -} - -void -_cairo_boxes_init_with_clip (cairo_boxes_t *boxes, - cairo_clip_t *clip) -{ - _cairo_boxes_init (boxes); - if (clip) - _cairo_boxes_limit (boxes, clip->boxes, clip->num_boxes); -} - -void -_cairo_boxes_init_for_array (cairo_boxes_t *boxes, - cairo_box_t *array, - int num_boxes) -{ - int n; - - boxes->status = CAIRO_STATUS_SUCCESS; - boxes->num_limits = 0; - boxes->num_boxes = num_boxes; - - boxes->tail = &boxes->chunks; - boxes->chunks.next = NULL; - boxes->chunks.base = array; - boxes->chunks.size = num_boxes; - boxes->chunks.count = num_boxes; - - for (n = 0; n < num_boxes; n++) { - if (! _cairo_fixed_is_integer (array[n].p1.x) || - ! _cairo_fixed_is_integer (array[n].p1.y) || - ! _cairo_fixed_is_integer (array[n].p2.x) || - ! _cairo_fixed_is_integer (array[n].p2.y)) - { - break; - } - } - - boxes->is_pixel_aligned = n == num_boxes; -} - -void -_cairo_boxes_limit (cairo_boxes_t *boxes, - const cairo_box_t *limits, - int num_limits) -{ - int n; - - boxes->limits = limits; - boxes->num_limits = num_limits; - - if (boxes->num_limits) { - boxes->limit = limits[0]; - for (n = 1; n < num_limits; n++) { - if (limits[n].p1.x < boxes->limit.p1.x) - boxes->limit.p1.x = limits[n].p1.x; - - if (limits[n].p1.y < boxes->limit.p1.y) - boxes->limit.p1.y = limits[n].p1.y; - - if (limits[n].p2.x > boxes->limit.p2.x) - boxes->limit.p2.x = limits[n].p2.x; - - if (limits[n].p2.y > boxes->limit.p2.y) - boxes->limit.p2.y = limits[n].p2.y; - } - } -} - -static void -_cairo_boxes_add_internal (cairo_boxes_t *boxes, - const cairo_box_t *box) -{ - struct _cairo_boxes_chunk *chunk; - - if (unlikely (boxes->status)) - return; - - chunk = boxes->tail; - if (unlikely (chunk->count == chunk->size)) { - int size; - - size = chunk->size * 2; - chunk->next = _cairo_malloc_ab_plus_c (size, - sizeof (cairo_box_t), - sizeof (struct _cairo_boxes_chunk)); - - if (unlikely (chunk->next == NULL)) { - boxes->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return; - } - - chunk = chunk->next; - boxes->tail = chunk; - - chunk->next = NULL; - chunk->count = 0; - chunk->size = size; - chunk->base = (cairo_box_t *) (chunk + 1); - } - - chunk->base[chunk->count++] = *box; - boxes->num_boxes++; - - if (boxes->is_pixel_aligned) - boxes->is_pixel_aligned = _cairo_box_is_pixel_aligned (box); -} - -cairo_status_t -_cairo_boxes_add (cairo_boxes_t *boxes, - cairo_antialias_t antialias, - const cairo_box_t *box) -{ - cairo_box_t b; - - if (antialias == CAIRO_ANTIALIAS_NONE) { - b.p1.x = _cairo_fixed_round_down (box->p1.x); - b.p1.y = _cairo_fixed_round_down (box->p1.y); - b.p2.x = _cairo_fixed_round_down (box->p2.x); - b.p2.y = _cairo_fixed_round_down (box->p2.y); - box = &b; - } - - if (box->p1.y == box->p2.y) - return CAIRO_STATUS_SUCCESS; - - if (box->p1.x == box->p2.x) - return CAIRO_STATUS_SUCCESS; - - if (boxes->num_limits) { - cairo_point_t p1, p2; - cairo_bool_t reversed = FALSE; - int n; - - /* support counter-clockwise winding for rectangular tessellation */ - if (box->p1.x < box->p2.x) { - p1.x = box->p1.x; - p2.x = box->p2.x; - } else { - p2.x = box->p1.x; - p1.x = box->p2.x; - reversed = ! reversed; - } - - if (p1.x >= boxes->limit.p2.x || p2.x <= boxes->limit.p1.x) - return CAIRO_STATUS_SUCCESS; - - if (box->p1.y < box->p2.y) { - p1.y = box->p1.y; - p2.y = box->p2.y; - } else { - p2.y = box->p1.y; - p1.y = box->p2.y; - reversed = ! reversed; - } - - if (p1.y >= boxes->limit.p2.y || p2.y <= boxes->limit.p1.y) - return CAIRO_STATUS_SUCCESS; - - for (n = 0; n < boxes->num_limits; n++) { - const cairo_box_t *limits = &boxes->limits[n]; - cairo_box_t _box; - cairo_point_t _p1, _p2; - - if (p1.x >= limits->p2.x || p2.x <= limits->p1.x) - continue; - if (p1.y >= limits->p2.y || p2.y <= limits->p1.y) - continue; - - /* Otherwise, clip the box to the limits. */ - _p1 = p1; - if (_p1.x < limits->p1.x) - _p1.x = limits->p1.x; - if (_p1.y < limits->p1.y) - _p1.y = limits->p1.y; - - _p2 = p2; - if (_p2.x > limits->p2.x) - _p2.x = limits->p2.x; - if (_p2.y > limits->p2.y) - _p2.y = limits->p2.y; - - if (_p2.y <= _p1.y || _p2.x <= _p1.x) - continue; - - _box.p1.y = _p1.y; - _box.p2.y = _p2.y; - if (reversed) { - _box.p1.x = _p2.x; - _box.p2.x = _p1.x; - } else { - _box.p1.x = _p1.x; - _box.p2.x = _p2.x; - } - - _cairo_boxes_add_internal (boxes, &_box); - } - } else { - _cairo_boxes_add_internal (boxes, box); - } - - return boxes->status; -} - -void -_cairo_boxes_extents (const cairo_boxes_t *boxes, - cairo_box_t *box) -{ - const struct _cairo_boxes_chunk *chunk; - cairo_box_t b; - int i; - - if (boxes->num_boxes == 0) { - box->p1.x = box->p1.y = box->p2.x = box->p2.y = 0; - return; - } - - b = boxes->chunks.base[0]; - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - if (chunk->base[i].p1.x < b.p1.x) - b.p1.x = chunk->base[i].p1.x; - - if (chunk->base[i].p1.y < b.p1.y) - b.p1.y = chunk->base[i].p1.y; - - if (chunk->base[i].p2.x > b.p2.x) - b.p2.x = chunk->base[i].p2.x; - - if (chunk->base[i].p2.y > b.p2.y) - b.p2.y = chunk->base[i].p2.y; - } - } - *box = b; -} - -void -_cairo_boxes_clear (cairo_boxes_t *boxes) -{ - struct _cairo_boxes_chunk *chunk, *next; - - for (chunk = boxes->chunks.next; chunk != NULL; chunk = next) { - next = chunk->next; - free (chunk); - } - - boxes->tail = &boxes->chunks; - boxes->chunks.next = 0; - boxes->chunks.count = 0; - boxes->chunks.base = boxes->boxes_embedded; - boxes->chunks.size = ARRAY_LENGTH (boxes->boxes_embedded); - boxes->num_boxes = 0; - - boxes->is_pixel_aligned = TRUE; -} - -cairo_box_t * -_cairo_boxes_to_array (const cairo_boxes_t *boxes, - int *num_boxes, - cairo_bool_t force_allocation) -{ - const struct _cairo_boxes_chunk *chunk; - cairo_box_t *box; - int i, j; - - *num_boxes = boxes->num_boxes; - if (boxes->chunks.next == NULL && ! force_allocation) - return boxes->chunks.base; - - box = _cairo_malloc_ab (boxes->num_boxes, sizeof (cairo_box_t)); - if (box == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - j = 0; - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) - box[j++] = chunk->base[i]; - } - - return box; -} - -void -_cairo_boxes_fini (cairo_boxes_t *boxes) -{ - struct _cairo_boxes_chunk *chunk, *next; - - for (chunk = boxes->chunks.next; chunk != NULL; chunk = next) { - next = chunk->next; - free (chunk); - } -} - -cairo_bool_t -_cairo_boxes_for_each_box (cairo_boxes_t *boxes, - cairo_bool_t (*func) (cairo_box_t *box, void *data), - void *data) -{ - struct _cairo_boxes_chunk *chunk; - int i; - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) - if (! func (&chunk->base[i], data)) - return FALSE; - } - - return TRUE; -} - -struct cairo_box_renderer { - cairo_span_renderer_t base; - cairo_boxes_t *boxes; -}; - -static cairo_status_t -span_to_boxes (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - struct cairo_box_renderer *r = abstract_renderer; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_box_t box; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - box.p1.y = _cairo_fixed_from_int (y); - box.p2.y = _cairo_fixed_from_int (y + h); - do { - if (spans[0].coverage) { - box.p1.x = _cairo_fixed_from_int(spans[0].x); - box.p2.x = _cairo_fixed_from_int(spans[1].x); - status = _cairo_boxes_add (r->boxes, CAIRO_ANTIALIAS_DEFAULT, &box); - } - spans++; - } while (--num_spans > 1 && status == CAIRO_STATUS_SUCCESS); - - return status; -} - -cairo_status_t -_cairo_rasterise_polygon_to_boxes (cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_boxes_t *boxes) -{ - struct cairo_box_renderer renderer; - cairo_scan_converter_t *converter; - cairo_int_status_t status; - cairo_rectangle_int_t r; - - TRACE ((stderr, "%s: fill_rule=%d\n", __FUNCTION__, fill_rule)); - - _cairo_box_round_to_rectangle (&polygon->extents, &r); - converter = _cairo_mono_scan_converter_create (r.x, r.y, - r.x + r.width, - r.y + r.height, - fill_rule); - status = _cairo_mono_scan_converter_add_polygon (converter, polygon); - if (unlikely (status)) - goto cleanup_converter; - - renderer.boxes = boxes; - renderer.base.render_rows = span_to_boxes; - - status = converter->generate (converter, &renderer.base); -cleanup_converter: - converter->destroy (converter); - return status; -} - -void -_cairo_debug_print_boxes (FILE *stream, const cairo_boxes_t *boxes) -{ - const struct _cairo_boxes_chunk *chunk; - cairo_box_t extents; - int i; - - _cairo_boxes_extents (boxes, &extents); - fprintf (stream, "boxes x %d: (%f, %f) x (%f, %f)\n", - boxes->num_boxes, - _cairo_fixed_to_double (extents.p1.x), - _cairo_fixed_to_double (extents.p1.y), - _cairo_fixed_to_double (extents.p2.x), - _cairo_fixed_to_double (extents.p2.y)); - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - fprintf (stderr, " box[%d]: (%f, %f), (%f, %f)\n", i, - _cairo_fixed_to_double (chunk->base[i].p1.x), - _cairo_fixed_to_double (chunk->base[i].p1.y), - _cairo_fixed_to_double (chunk->base[i].p2.x), - _cairo_fixed_to_double (chunk->base[i].p2.y)); - } - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache-private.h deleted file mode 100644 index 24b6d0b2092..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache-private.h +++ /dev/null @@ -1,145 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc. - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Keith Packard - * Graydon Hoare - * Carl Worth - */ - -#ifndef CAIRO_CACHE_PRIVATE_H -#define CAIRO_CACHE_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-types-private.h" - -/** - * _cairo_cache_entry: - * - * A #cairo_cache_entry_t contains both a key and a value for - * #cairo_cache_t. User-derived types for #cairo_cache_entry_t must - * have a #cairo_cache_entry_t as their first field. For example: - * - * typedef _my_entry { - * cairo_cache_entry_t base; - * ... Remainder of key and value fields here .. - * } my_entry_t; - * - * which then allows a pointer to my_entry_t to be passed to any of - * the #cairo_cache_t functions as follows without requiring a cast: - * - * _cairo_cache_insert (cache, &my_entry->base, size); - * - * IMPORTANT: The caller is responsible for initializing - * my_entry->base.hash with a hash code derived from the key. The - * essential property of the hash code is that keys_equal must never - * return %TRUE for two keys that have different hashes. The best hash - * code will reduce the frequency of two keys with the same code for - * which keys_equal returns %FALSE. - * - * The user must also initialize my_entry->base.size to indicate - * the size of the current entry. What units to use for size is - * entirely up to the caller, (though the same units must be used for - * the max_size parameter passed to _cairo_cache_create()). If all - * entries are close to the same size, the simplest thing to do is to - * just use units of "entries", (eg. set size==1 in all entries and - * set max_size to the number of entries which you want to be saved - * in the cache). - * - * Which parts of the entry make up the "key" and which part make up - * the value are entirely up to the caller, (as determined by the - * computation going into base.hash as well as the keys_equal - * function). A few of the #cairo_cache_t functions accept an entry which - * will be used exclusively as a "key", (indicated by a parameter name - * of key). In these cases, the value-related fields of the entry need - * not be initialized if so desired. - **/ -typedef struct _cairo_cache_entry { - unsigned long hash; - unsigned long size; -} cairo_cache_entry_t; - -typedef cairo_bool_t (*cairo_cache_predicate_func_t) (const void *entry); - -struct _cairo_cache { - cairo_hash_table_t *hash_table; - - cairo_cache_predicate_func_t predicate; - cairo_destroy_func_t entry_destroy; - - unsigned long max_size; - unsigned long size; - - int freeze_count; -}; - -typedef cairo_bool_t -(*cairo_cache_keys_equal_func_t) (const void *key_a, const void *key_b); - -typedef void -(*cairo_cache_callback_func_t) (void *entry, - void *closure); - -cairo_private cairo_status_t -_cairo_cache_init (cairo_cache_t *cache, - cairo_cache_keys_equal_func_t keys_equal, - cairo_cache_predicate_func_t predicate, - cairo_destroy_func_t entry_destroy, - unsigned long max_size); - -cairo_private void -_cairo_cache_fini (cairo_cache_t *cache); - -cairo_private void -_cairo_cache_freeze (cairo_cache_t *cache); - -cairo_private void -_cairo_cache_thaw (cairo_cache_t *cache); - -cairo_private void * -_cairo_cache_lookup (cairo_cache_t *cache, - cairo_cache_entry_t *key); - -cairo_private cairo_status_t -_cairo_cache_insert (cairo_cache_t *cache, - cairo_cache_entry_t *entry); - -cairo_private void -_cairo_cache_remove (cairo_cache_t *cache, - cairo_cache_entry_t *entry); - -cairo_private void -_cairo_cache_foreach (cairo_cache_t *cache, - cairo_cache_callback_func_t cache_callback, - void *closure); - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache.c deleted file mode 100644 index 5c4e4caa3d0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cache.c +++ /dev/null @@ -1,338 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc. - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Keith Packard - * Graydon Hoare - * Carl Worth - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -static void -_cairo_cache_shrink_to_accommodate (cairo_cache_t *cache, - unsigned long additional); - -static cairo_bool_t -_cairo_cache_entry_is_non_zero (const void *entry) -{ - return ((const cairo_cache_entry_t *) entry)->size; -} - - -/** - * _cairo_cache_init: - * @cache: the #cairo_cache_t to initialise - * @keys_equal: a function to return %TRUE if two keys are equal - * @entry_destroy: destroy notifier for cache entries - * @max_size: the maximum size for this cache - * Returns: the newly created #cairo_cache_t - * - * Creates a new cache using the keys_equal() function to determine - * the equality of entries. - * - * Data is provided to the cache in the form of user-derived version - * of #cairo_cache_entry_t. A cache entry must be able to hold hash - * code, a size, and the key/value pair being stored in the - * cache. Sometimes only the key will be necessary, (as in - * _cairo_cache_lookup()), and in these cases the value portion of the - * entry need not be initialized. - * - * The units for max_size can be chosen by the caller, but should be - * consistent with the units of the size field of cache entries. When - * adding an entry with _cairo_cache_insert() if the total size of - * entries in the cache would exceed max_size then entries will be - * removed at random until the new entry would fit or the cache is - * empty. Then the new entry is inserted. - * - * There are cases in which the automatic removal of entries is - * undesired. If the cache entries have reference counts, then it is a - * simple matter to use the reference counts to ensure that entries - * continue to live even after being ejected from the cache. However, - * in some cases the memory overhead of adding a reference count to - * the entry would be objectionable. In such cases, the - * _cairo_cache_freeze() and _cairo_cache_thaw() calls can be - * used to establish a window during which no automatic removal of - * entries will occur. - **/ -cairo_status_t -_cairo_cache_init (cairo_cache_t *cache, - cairo_cache_keys_equal_func_t keys_equal, - cairo_cache_predicate_func_t predicate, - cairo_destroy_func_t entry_destroy, - unsigned long max_size) -{ - cache->hash_table = _cairo_hash_table_create (keys_equal); - if (unlikely (cache->hash_table == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (predicate == NULL) - predicate = _cairo_cache_entry_is_non_zero; - cache->predicate = predicate; - cache->entry_destroy = entry_destroy; - - cache->max_size = max_size; - cache->size = 0; - - cache->freeze_count = 0; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_cache_pluck (void *entry, void *closure) -{ - _cairo_cache_remove (closure, entry); -} - -/** - * _cairo_cache_fini: - * @cache: a cache to destroy - * - * Immediately destroys the given cache, freeing all resources - * associated with it. As part of this process, the entry_destroy() - * function, (as passed to _cairo_cache_init()), will be called for - * each entry in the cache. - **/ -void -_cairo_cache_fini (cairo_cache_t *cache) -{ - _cairo_hash_table_foreach (cache->hash_table, - _cairo_cache_pluck, - cache); - assert (cache->size == 0); - _cairo_hash_table_destroy (cache->hash_table); -} - -/** - * _cairo_cache_freeze: - * @cache: a cache with some precious entries in it (or about to be - * added) - * - * Disable the automatic ejection of entries from the cache. For as - * long as the cache is "frozen", calls to _cairo_cache_insert() will - * add new entries to the cache regardless of how large the cache - * grows. See _cairo_cache_thaw(). - * - * Note: Multiple calls to _cairo_cache_freeze() will stack, in that - * the cache will remain "frozen" until a corresponding number of - * calls are made to _cairo_cache_thaw(). - **/ -void -_cairo_cache_freeze (cairo_cache_t *cache) -{ - assert (cache->freeze_count >= 0); - - cache->freeze_count++; -} - -/** - * _cairo_cache_thaw: - * @cache: a cache, just after the entries in it have become less - * precious - * - * Cancels the effects of _cairo_cache_freeze(). - * - * When a number of calls to _cairo_cache_thaw() is made corresponding - * to the number of calls to _cairo_cache_freeze() the cache will no - * longer be "frozen". If the cache had grown larger than max_size - * while frozen, entries will immediately be ejected (by random) from - * the cache until the cache is smaller than max_size. Also, the - * automatic ejection of entries on _cairo_cache_insert() will resume. - **/ -void -_cairo_cache_thaw (cairo_cache_t *cache) -{ - assert (cache->freeze_count > 0); - - if (--cache->freeze_count == 0) - _cairo_cache_shrink_to_accommodate (cache, 0); -} - -/** - * _cairo_cache_lookup: - * @cache: a cache - * @key: the key of interest - * @entry_return: pointer for return value - * - * Performs a lookup in @cache looking for an entry which has a key - * that matches @key, (as determined by the keys_equal() function - * passed to _cairo_cache_init()). - * - * Return value: %TRUE if there is an entry in the cache that matches - * @key, (which will now be in *entry_return). %FALSE otherwise, (in - * which case *entry_return will be %NULL). - **/ -void * -_cairo_cache_lookup (cairo_cache_t *cache, - cairo_cache_entry_t *key) -{ - return _cairo_hash_table_lookup (cache->hash_table, - (cairo_hash_entry_t *) key); -} - -/** - * _cairo_cache_remove_random: - * @cache: a cache - * - * Remove a random entry from the cache. - * - * Return value: %TRUE if an entry was successfully removed. - * %FALSE if there are no entries that can be removed. - **/ -static cairo_bool_t -_cairo_cache_remove_random (cairo_cache_t *cache) -{ - cairo_cache_entry_t *entry; - - entry = _cairo_hash_table_random_entry (cache->hash_table, - cache->predicate); - if (unlikely (entry == NULL)) - return FALSE; - - _cairo_cache_remove (cache, entry); - - return TRUE; -} - -/** - * _cairo_cache_shrink_to_accommodate: - * @cache: a cache - * @additional: additional size requested in bytes - * - * If cache is not frozen, eject entries randomly until the size of - * the cache is at least @additional bytes less than - * cache->max_size. That is, make enough room to accommodate a new - * entry of size @additional. - **/ -static void -_cairo_cache_shrink_to_accommodate (cairo_cache_t *cache, - unsigned long additional) -{ - while (cache->size + additional > cache->max_size) { - if (! _cairo_cache_remove_random (cache)) - return; - } -} - -/** - * _cairo_cache_insert: - * @cache: a cache - * @entry: an entry to be inserted - * - * Insert @entry into the cache. If an entry exists in the cache with - * a matching key, then the old entry will be removed first, (and the - * entry_destroy() callback will be called on it). - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available. - **/ -cairo_status_t -_cairo_cache_insert (cairo_cache_t *cache, - cairo_cache_entry_t *entry) -{ - cairo_status_t status; - - if (entry->size && ! cache->freeze_count) - _cairo_cache_shrink_to_accommodate (cache, entry->size); - - status = _cairo_hash_table_insert (cache->hash_table, - (cairo_hash_entry_t *) entry); - if (unlikely (status)) - return status; - - cache->size += entry->size; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_cache_remove: - * @cache: a cache - * @entry: an entry that exists in the cache - * - * Remove an existing entry from the cache. - **/ -void -_cairo_cache_remove (cairo_cache_t *cache, - cairo_cache_entry_t *entry) -{ - cache->size -= entry->size; - - _cairo_hash_table_remove (cache->hash_table, - (cairo_hash_entry_t *) entry); - - if (cache->entry_destroy) - cache->entry_destroy (entry); -} - -/** - * _cairo_cache_foreach: - * @cache: a cache - * @cache_callback: function to be called for each entry - * @closure: additional argument to be passed to @cache_callback - * - * Call @cache_callback for each entry in the cache, in a - * non-specified order. - **/ -void -_cairo_cache_foreach (cairo_cache_t *cache, - cairo_cache_callback_func_t cache_callback, - void *closure) -{ - _cairo_hash_table_foreach (cache->hash_table, - cache_callback, - closure); -} - -unsigned long -_cairo_hash_string (const char *c) -{ - /* This is the djb2 hash. */ - unsigned long hash = _CAIRO_HASH_INIT_VALUE; - while (c && *c) - hash = ((hash << 5) + hash) + *c++; - return hash; -} - -unsigned long -_cairo_hash_bytes (unsigned long hash, - const void *ptr, - unsigned int length) -{ - const uint8_t *bytes = ptr; - /* This is the djb2 hash. */ - while (length--) - hash = ((hash << 5) + hash) + *bytes++; - return hash; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cff-subset.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cff-subset.c deleted file mode 100644 index f15deb5ea6b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cff-subset.c +++ /dev/null @@ -1,3440 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - * Eugeniy Meshcheryakov - */ - -/* - * Useful links: - * http://www.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5176.CFF.pdf - * http://www.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5177.Type2.pdf - */ - -#define _BSD_SOURCE /* for snprintf(), strdup() */ -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-truetype-subset-private.h" -#include -#include - -/* CFF Dict Operators. If the high byte is 0 the command is encoded - * with a single byte. */ -#define BASEFONTNAME_OP 0x0c16 -#define CIDCOUNT_OP 0x0c22 -#define CHARSET_OP 0x000f -#define CHARSTRINGS_OP 0x0011 -#define COPYRIGHT_OP 0x0c00 -#define DEFAULTWIDTH_OP 0x0014 -#define ENCODING_OP 0x0010 -#define FAMILYNAME_OP 0x0003 -#define FDARRAY_OP 0x0c24 -#define FDSELECT_OP 0x0c25 -#define FONTBBOX_OP 0x0005 -#define FONTMATRIX_OP 0x0c07 -#define FONTNAME_OP 0x0c26 -#define FULLNAME_OP 0x0002 -#define LOCAL_SUB_OP 0x0013 -#define NOMINALWIDTH_OP 0x0015 -#define NOTICE_OP 0x0001 -#define POSTSCRIPT_OP 0x0c15 -#define PRIVATE_OP 0x0012 -#define ROS_OP 0x0c1e -#define UNIQUEID_OP 0x000d -#define VERSION_OP 0x0000 -#define WEIGHT_OP 0x0004 -#define XUID_OP 0x000e - -#define NUM_STD_STRINGS 391 - -/* Type 2 Charstring operators */ -#define TYPE2_hstem 0x0001 -#define TYPE2_vstem 0x0003 -#define TYPE2_callsubr 0x000a - -#define TYPE2_return 0x000b -#define TYPE2_endchar 0x000e - -#define TYPE2_hstemhm 0x0012 -#define TYPE2_hintmask 0x0013 -#define TYPE2_cntrmask 0x0014 -#define TYPE2_vstemhm 0x0017 -#define TYPE2_callgsubr 0x001d - -#define TYPE2_rmoveto 0x0015 -#define TYPE2_hmoveto 0x0016 -#define TYPE2_vmoveto 0x0004 - - -#define MAX_SUBROUTINE_NESTING 10 /* From Type2 Charstring spec */ - - -typedef struct _cff_header { - uint8_t major; - uint8_t minor; - uint8_t header_size; - uint8_t offset_size; -} cff_header_t; - -typedef struct _cff_index_element { - cairo_bool_t is_copy; - unsigned char *data; - int length; -} cff_index_element_t; - -typedef struct _cff_dict_operator { - cairo_hash_entry_t base; - - unsigned short operator; - unsigned char *operand; - int operand_length; - int operand_offset; -} cff_dict_operator_t; - -typedef struct _cairo_cff_font { - - cairo_scaled_font_subset_t *scaled_font_subset; - const cairo_scaled_font_backend_t *backend; - - /* Font Data */ - unsigned char *data; - unsigned long data_length; - unsigned char *current_ptr; - unsigned char *data_end; - cff_header_t *header; - char *font_name; - char *ps_name; - cairo_hash_table_t *top_dict; - cairo_hash_table_t *private_dict; - cairo_array_t strings_index; - cairo_array_t charstrings_index; - cairo_array_t global_sub_index; - cairo_array_t local_sub_index; - unsigned char *charset; - int num_glyphs; - cairo_bool_t is_cid; - cairo_bool_t is_opentype; - int units_per_em; - int global_sub_bias; - int local_sub_bias; - double default_width; - double nominal_width; - - /* CID Font Data */ - int *fdselect; - unsigned int num_fontdicts; - cairo_hash_table_t **fd_dict; - cairo_hash_table_t **fd_private_dict; - cairo_array_t *fd_local_sub_index; - int *fd_local_sub_bias; - double *fd_default_width; - double *fd_nominal_width; - - /* Subsetted Font Data */ - char *subset_font_name; - cairo_array_t charstrings_subset_index; - cairo_array_t strings_subset_index; - int euro_sid; - int *fdselect_subset; - unsigned int num_subset_fontdicts; - int *fd_subset_map; - int *private_dict_offset; - cairo_bool_t subset_subroutines; - cairo_bool_t *global_subs_used; - cairo_bool_t *local_subs_used; - cairo_bool_t **fd_local_subs_used; - cairo_array_t output; - - /* Subset Metrics */ - int *widths; - int x_min, y_min, x_max, y_max; - int ascent, descent; - - /* Type 2 charstring data */ - int type2_stack_size; - int type2_stack_top_value; - cairo_bool_t type2_stack_top_is_int; - int type2_num_hints; - int type2_hintmask_bytes; - int type2_nesting_level; - cairo_bool_t type2_seen_first_int; - cairo_bool_t type2_find_width; - cairo_bool_t type2_found_width; - int type2_width; - cairo_bool_t type2_has_path; - -} cairo_cff_font_t; - -/* Encoded integer using maximum sized encoding. This is required for - * operands that are later modified after encoding. */ -static unsigned char * -encode_integer_max (unsigned char *p, int i) -{ - *p++ = 29; - *p++ = i >> 24; - *p++ = (i >> 16) & 0xff; - *p++ = (i >> 8) & 0xff; - *p++ = i & 0xff; - return p; -} - -static unsigned char * -encode_integer (unsigned char *p, int i) -{ - if (i >= -107 && i <= 107) { - *p++ = i + 139; - } else if (i >= 108 && i <= 1131) { - i -= 108; - *p++ = (i >> 8)+ 247; - *p++ = i & 0xff; - } else if (i >= -1131 && i <= -108) { - i = -i - 108; - *p++ = (i >> 8)+ 251; - *p++ = i & 0xff; - } else if (i >= -32768 && i <= 32767) { - *p++ = 28; - *p++ = (i >> 8) & 0xff; - *p++ = i & 0xff; - } else { - p = encode_integer_max (p, i); - } - return p; -} - -static unsigned char * -decode_integer (unsigned char *p, int *integer) -{ - if (*p == 28) { - *integer = (int)(p[1]<<8 | p[2]); - p += 3; - } else if (*p == 29) { - *integer = (int)((p[1] << 24) | (p[2] << 16) | (p[3] << 8) | p[4]); - p += 5; - } else if (*p >= 32 && *p <= 246) { - *integer = *p++ - 139; - } else if (*p <= 250) { - *integer = (p[0] - 247) * 256 + p[1] + 108; - p += 2; - } else if (*p <= 254) { - *integer = -(p[0] - 251) * 256 - p[1] - 108; - p += 2; - } else { - *integer = 0; - p += 1; - } - return p; -} - -static char * -decode_nibble (int n, char *buf) -{ - switch (n) - { - case 0xa: - *buf++ = '.'; - break; - case 0xb: - *buf++ = 'E'; - break; - case 0xc: - *buf++ = 'E'; - *buf++ = '-'; - break; - case 0xd: - *buf++ = '-'; - break; - case 0xe: - *buf++ = '-'; - break; - case 0xf: - break; - default: - *buf++ = '0' + n; - break; - } - - return buf; -} - -static unsigned char * -decode_real (unsigned char *p, double *real) -{ - const char *decimal_point; - int decimal_point_len; - int n; - char buffer[100]; - char buffer2[200]; - char *q; - char *buf = buffer; - char *buf_end = buffer + sizeof (buffer); - - decimal_point = cairo_get_locale_decimal_point (); - decimal_point_len = strlen (decimal_point); - - assert (decimal_point_len != 0); - assert (sizeof(buffer) + decimal_point_len < sizeof(buffer2)); - - p++; - while (buf + 2 < buf_end) { - n = *p >> 4; - buf = decode_nibble (n, buf); - n = *p & 0x0f; - buf = decode_nibble (n, buf); - if ((*p & 0x0f) == 0x0f) { - p++; - break; - } - p++; - }; - *buf = 0; - - buf = buffer; - if (strchr (buffer, '.')) { - q = strchr (buffer, '.'); - strncpy (buffer2, buffer, q - buffer); - buf = buffer2 + (q - buffer); - strncpy (buf, decimal_point, decimal_point_len); - buf += decimal_point_len; - strcpy (buf, q + 1); - buf = buffer2; - } - - if (sscanf(buf, "%lf", real) != 1) - *real = 0.0; - - return p; -} - -static unsigned char * -decode_number (unsigned char *p, double *number) -{ - if (*p == 30) { - p = decode_real (p, number); - } else { - int i; - p = decode_integer (p, &i); - *number = i; - } - return p; -} - -static unsigned char * -decode_operator (unsigned char *p, unsigned short *operator) -{ - unsigned short op = 0; - - op = *p++; - if (op == 12) { - op <<= 8; - op |= *p++; - } - *operator = op; - return p; -} - -/* return 0 if not an operand */ -static int -operand_length (unsigned char *p) -{ - unsigned char *begin = p; - - if (*p == 28) - return 3; - - if (*p == 29) - return 5; - - if (*p >= 32 && *p <= 246) - return 1; - - if (*p >= 247 && *p <= 254) - return 2; - - if (*p == 30) { - while ((*p & 0x0f) != 0x0f) - p++; - return p - begin + 1; - } - - return 0; -} - -static unsigned char * -encode_index_offset (unsigned char *p, int offset_size, unsigned long offset) -{ - while (--offset_size >= 0) { - p[offset_size] = (unsigned char) (offset & 0xff); - offset >>= 8; - } - return p + offset_size; -} - -static unsigned long -decode_index_offset(unsigned char *p, int off_size) -{ - unsigned long offset = 0; - - while (off_size-- > 0) - offset = offset*256 + *p++; - return offset; -} - -static void -cff_index_init (cairo_array_t *index) -{ - _cairo_array_init (index, sizeof (cff_index_element_t)); -} - -static cairo_int_status_t -cff_index_read (cairo_array_t *index, unsigned char **ptr, unsigned char *end_ptr) -{ - cff_index_element_t element; - unsigned char *data, *p; - cairo_status_t status; - int offset_size, count, start, i; - int end = 0; - - p = *ptr; - if (p + 2 > end_ptr) - return CAIRO_INT_STATUS_UNSUPPORTED; - count = get_unaligned_be16 (p); - p += 2; - if (count > 0) { - offset_size = *p++; - if (p + (count + 1)*offset_size > end_ptr) - return CAIRO_INT_STATUS_UNSUPPORTED; - data = p + offset_size*(count + 1) - 1; - start = decode_index_offset (p, offset_size); - p += offset_size; - for (i = 0; i < count; i++) { - end = decode_index_offset (p, offset_size); - p += offset_size; - if (p > end_ptr) - return CAIRO_INT_STATUS_UNSUPPORTED; - element.length = end - start; - element.is_copy = FALSE; - element.data = data + start; - status = _cairo_array_append (index, &element); - if (unlikely (status)) - return status; - start = end; - } - p = data + end; - } - *ptr = p; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cff_index_write (cairo_array_t *index, cairo_array_t *output) -{ - int offset_size; - int offset; - int num_elem; - int i; - cff_index_element_t *element; - uint16_t count; - unsigned char buf[5]; - cairo_status_t status; - - num_elem = _cairo_array_num_elements (index); - count = cpu_to_be16 ((uint16_t) num_elem); - status = _cairo_array_append_multiple (output, &count, 2); - if (unlikely (status)) - return status; - - if (num_elem == 0) - return CAIRO_STATUS_SUCCESS; - - /* Find maximum offset to determine offset size */ - offset = 1; - for (i = 0; i < num_elem; i++) { - element = _cairo_array_index (index, i); - offset += element->length; - } - if (offset < 0x100) - offset_size = 1; - else if (offset < 0x10000) - offset_size = 2; - else if (offset < 0x1000000) - offset_size = 3; - else - offset_size = 4; - - buf[0] = (unsigned char) offset_size; - status = _cairo_array_append (output, buf); - if (unlikely (status)) - return status; - - offset = 1; - encode_index_offset (buf, offset_size, offset); - status = _cairo_array_append_multiple (output, buf, offset_size); - if (unlikely (status)) - return status; - - for (i = 0; i < num_elem; i++) { - element = _cairo_array_index (index, i); - offset += element->length; - encode_index_offset (buf, offset_size, offset); - status = _cairo_array_append_multiple (output, buf, offset_size); - if (unlikely (status)) - return status; - } - - for (i = 0; i < num_elem; i++) { - element = _cairo_array_index (index, i); - if (element->length > 0) { - status = _cairo_array_append_multiple (output, - element->data, - element->length); - } - if (unlikely (status)) - return status; - } - return CAIRO_STATUS_SUCCESS; -} - -static void -cff_index_set_object (cairo_array_t *index, int obj_index, - unsigned char *object , int length) -{ - cff_index_element_t *element; - - element = _cairo_array_index (index, obj_index); - if (element->is_copy) - free (element->data); - - element->data = object; - element->length = length; - element->is_copy = FALSE; -} - -static cairo_status_t -cff_index_append (cairo_array_t *index, unsigned char *object , int length) -{ - cff_index_element_t element; - - element.length = length; - element.is_copy = FALSE; - element.data = object; - - return _cairo_array_append (index, &element); -} - -static cairo_status_t -cff_index_append_copy (cairo_array_t *index, - const unsigned char *object, - unsigned int length) -{ - cff_index_element_t element; - cairo_status_t status; - - element.length = length; - element.is_copy = TRUE; - element.data = malloc (element.length); - if (unlikely (element.data == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (element.data, object, element.length); - - status = _cairo_array_append (index, &element); - if (unlikely (status)) { - free (element.data); - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -cff_index_fini (cairo_array_t *index) -{ - cff_index_element_t *element; - unsigned int i; - - for (i = 0; i < _cairo_array_num_elements (index); i++) { - element = _cairo_array_index (index, i); - if (element->is_copy && element->data) - free (element->data); - } - _cairo_array_fini (index); -} - -static cairo_bool_t -_cairo_cff_dict_equal (const void *key_a, const void *key_b) -{ - const cff_dict_operator_t *op_a = key_a; - const cff_dict_operator_t *op_b = key_b; - - return op_a->operator == op_b->operator; -} - -static cairo_status_t -cff_dict_init (cairo_hash_table_t **dict) -{ - *dict = _cairo_hash_table_create (_cairo_cff_dict_equal); - if (unlikely (*dict == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_dict_init_key (cff_dict_operator_t *key, int operator) -{ - key->base.hash = (unsigned long) operator; - key->operator = operator; -} - -static cairo_status_t -cff_dict_create_operator (int operator, - unsigned char *operand, - int size, - cff_dict_operator_t **out) -{ - cff_dict_operator_t *op; - - op = malloc (sizeof (cff_dict_operator_t)); - if (unlikely (op == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_dict_init_key (op, operator); - op->operand = malloc (size); - if (unlikely (op->operand == NULL)) { - free (op); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - memcpy (op->operand, operand, size); - op->operand_length = size; - op->operand_offset = -1; - - *out = op; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cff_dict_read (cairo_hash_table_t *dict, unsigned char *p, int dict_size) -{ - unsigned char *end; - cairo_array_t operands; - cff_dict_operator_t *op; - unsigned short operator; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - int size; - - end = p + dict_size; - _cairo_array_init (&operands, 1); - while (p < end) { - size = operand_length (p); - if (size != 0) { - status = _cairo_array_append_multiple (&operands, p, size); - if (unlikely (status)) - goto fail; - - p += size; - } else { - p = decode_operator (p, &operator); - status = cff_dict_create_operator (operator, - _cairo_array_index (&operands, 0), - _cairo_array_num_elements (&operands), - &op); - if (unlikely (status)) - goto fail; - - status = _cairo_hash_table_insert (dict, &op->base); - if (unlikely (status)) - goto fail; - - _cairo_array_truncate (&operands, 0); - } - } - -fail: - _cairo_array_fini (&operands); - - return status; -} - -static void -cff_dict_remove (cairo_hash_table_t *dict, unsigned short operator) -{ - cff_dict_operator_t key, *op; - - _cairo_dict_init_key (&key, operator); - op = _cairo_hash_table_lookup (dict, &key.base); - if (op != NULL) { - free (op->operand); - _cairo_hash_table_remove (dict, (cairo_hash_entry_t *) op); - free (op); - } -} - -static unsigned char * -cff_dict_get_operands (cairo_hash_table_t *dict, - unsigned short operator, - int *size) -{ - cff_dict_operator_t key, *op; - - _cairo_dict_init_key (&key, operator); - op = _cairo_hash_table_lookup (dict, &key.base); - if (op != NULL) { - *size = op->operand_length; - return op->operand; - } - - return NULL; -} - -static cairo_status_t -cff_dict_set_operands (cairo_hash_table_t *dict, - unsigned short operator, - unsigned char *operand, - int size) -{ - cff_dict_operator_t key, *op; - cairo_status_t status; - - _cairo_dict_init_key (&key, operator); - op = _cairo_hash_table_lookup (dict, &key.base); - if (op != NULL) { - free (op->operand); - op->operand = malloc (size); - if (unlikely (op->operand == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (op->operand, operand, size); - op->operand_length = size; - } - else - { - status = cff_dict_create_operator (operator, operand, size, &op); - if (unlikely (status)) - return status; - - status = _cairo_hash_table_insert (dict, &op->base); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static int -cff_dict_get_location (cairo_hash_table_t *dict, - unsigned short operator, - int *size) -{ - cff_dict_operator_t key, *op; - - _cairo_dict_init_key (&key, operator); - op = _cairo_hash_table_lookup (dict, &key.base); - if (op != NULL) { - *size = op->operand_length; - return op->operand_offset; - } - - return -1; -} - -typedef struct _dict_write_info { - cairo_array_t *output; - cairo_status_t status; -} dict_write_info_t; - -static void -cairo_dict_write_operator (cff_dict_operator_t *op, dict_write_info_t *write_info) -{ - unsigned char data; - - op->operand_offset = _cairo_array_num_elements (write_info->output); - write_info->status = _cairo_array_append_multiple (write_info->output, op->operand, op->operand_length); - if (write_info->status) - return; - - if (op->operator & 0xff00) { - data = op->operator >> 8; - write_info->status = _cairo_array_append (write_info->output, &data); - if (write_info->status) - return; - } - data = op->operator & 0xff; - write_info->status = _cairo_array_append (write_info->output, &data); -} - -static void -_cairo_dict_collect (void *entry, void *closure) -{ - dict_write_info_t *write_info = closure; - cff_dict_operator_t *op = entry; - - if (write_info->status) - return; - - /* The ROS operator is handled separately in cff_dict_write() */ - if (op->operator != ROS_OP) - cairo_dict_write_operator (op, write_info); -} - -static cairo_status_t -cff_dict_write (cairo_hash_table_t *dict, cairo_array_t *output) -{ - dict_write_info_t write_info; - cff_dict_operator_t key, *op; - - write_info.output = output; - write_info.status = CAIRO_STATUS_SUCCESS; - - /* The CFF specification requires that the Top Dict of CID fonts - * begin with the ROS operator. */ - _cairo_dict_init_key (&key, ROS_OP); - op = _cairo_hash_table_lookup (dict, &key.base); - if (op != NULL) - cairo_dict_write_operator (op, &write_info); - - _cairo_hash_table_foreach (dict, _cairo_dict_collect, &write_info); - - return write_info.status; -} - -static void -_cff_dict_entry_pluck (void *_entry, void *dict) -{ - cff_dict_operator_t *entry = _entry; - - _cairo_hash_table_remove (dict, &entry->base); - free (entry->operand); - free (entry); -} - -static void -cff_dict_fini (cairo_hash_table_t *dict) -{ - _cairo_hash_table_foreach (dict, _cff_dict_entry_pluck, dict); - _cairo_hash_table_destroy (dict); -} - -static cairo_int_status_t -cairo_cff_font_read_header (cairo_cff_font_t *font) -{ - if (font->data_length < sizeof (cff_header_t)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - - font->header = (cff_header_t *) font->data; - font->current_ptr = font->data + font->header->header_size; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_cff_font_read_name (cairo_cff_font_t *font) -{ - cairo_array_t index; - cairo_int_status_t status; - cff_index_element_t *element; - unsigned char *p; - int i, len; - - cff_index_init (&index); - status = cff_index_read (&index, &font->current_ptr, font->data_end); - if (!font->is_opentype) { - element = _cairo_array_index (&index, 0); - p = element->data; - len = element->length; - - /* If font name is prefixed with a subset tag, strip it off. */ - if (len > 7 && p[6] == '+') { - for (i = 0; i < 6; i++) - if (p[i] < 'A' || p[i] > 'Z') - break; - if (i == 6) { - p += 7; - len -= 7; - } - } - font->ps_name = malloc (len + 1); - if (unlikely (font->ps_name == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (font->ps_name, p, len); - font->ps_name[len] = 0; - - status = _cairo_escape_ps_name (&font->ps_name); - } - cff_index_fini (&index); - - return status; -} - -static cairo_int_status_t -cairo_cff_font_read_private_dict (cairo_cff_font_t *font, - cairo_hash_table_t *private_dict, - cairo_array_t *local_sub_index, - int *local_sub_bias, - cairo_bool_t **local_subs_used, - double *default_width, - double *nominal_width, - unsigned char *ptr, - int size) -{ - cairo_int_status_t status; - unsigned char buf[10]; - unsigned char *end_buf; - int offset; - int i; - unsigned char *operand; - unsigned char *p; - int num_subs; - - status = cff_dict_read (private_dict, ptr, size); - if (unlikely (status)) - return status; - - operand = cff_dict_get_operands (private_dict, LOCAL_SUB_OP, &i); - if (operand) { - decode_integer (operand, &offset); - p = ptr + offset; - status = cff_index_read (local_sub_index, &p, font->data_end); - if (unlikely (status)) - return status; - - /* Use maximum sized encoding to reserve space for later modification. */ - end_buf = encode_integer_max (buf, 0); - status = cff_dict_set_operands (private_dict, LOCAL_SUB_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - } - - *default_width = 0; - operand = cff_dict_get_operands (private_dict, DEFAULTWIDTH_OP, &i); - if (operand) - decode_number (operand, default_width); - - *nominal_width = 0; - operand = cff_dict_get_operands (private_dict, NOMINALWIDTH_OP, &i); - if (operand) - decode_number (operand, nominal_width); - - num_subs = _cairo_array_num_elements (local_sub_index); - *local_subs_used = calloc (num_subs, sizeof (cairo_bool_t)); - if (unlikely (*local_subs_used == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (num_subs < 1240) - *local_sub_bias = 107; - else if (num_subs < 33900) - *local_sub_bias = 1131; - else - *local_sub_bias = 32768; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_cff_font_read_fdselect (cairo_cff_font_t *font, unsigned char *p) -{ - int type, num_ranges, first, last, fd, i, j; - - font->fdselect = calloc (font->num_glyphs, sizeof (int)); - if (unlikely (font->fdselect == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - type = *p++; - if (type == 0) - { - for (i = 0; i < font->num_glyphs; i++) - font->fdselect[i] = *p++; - } else if (type == 3) { - num_ranges = get_unaligned_be16 (p); - p += 2; - for (i = 0; i < num_ranges; i++) - { - first = get_unaligned_be16 (p); - p += 2; - fd = *p++; - last = get_unaligned_be16 (p); - for (j = first; j < last; j++) - font->fdselect[j] = fd; - } - } else { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr) -{ - cairo_array_t index; - cff_index_element_t *element; - unsigned int i; - int size; - unsigned char *operand; - int offset; - cairo_int_status_t status; - unsigned char buf[100]; - unsigned char *end_buf; - - cff_index_init (&index); - status = cff_index_read (&index, &ptr, font->data_end); - if (unlikely (status)) - goto fail; - - font->num_fontdicts = _cairo_array_num_elements (&index); - - font->fd_dict = calloc (sizeof (cairo_hash_table_t *), font->num_fontdicts); - if (unlikely (font->fd_dict == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - font->fd_private_dict = calloc (sizeof (cairo_hash_table_t *), font->num_fontdicts); - if (unlikely (font->fd_private_dict == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - font->fd_local_sub_index = calloc (sizeof (cairo_array_t), font->num_fontdicts); - if (unlikely (font->fd_local_sub_index == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - font->fd_local_sub_bias = calloc (sizeof (int), font->num_fontdicts); - if (unlikely (font->fd_local_sub_bias == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - font->fd_local_subs_used = calloc (sizeof (cairo_bool_t *), font->num_fontdicts); - if (unlikely (font->fd_local_subs_used == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - font->fd_default_width = calloc (font->num_fontdicts, sizeof (double)); - if (unlikely (font->fd_default_width == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - font->fd_nominal_width = calloc (font->num_fontdicts, sizeof (double)); - if (unlikely (font->fd_nominal_width == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - - for (i = 0; i < font->num_fontdicts; i++) { - status = cff_dict_init (&font->fd_dict[i]); - if (unlikely (status)) - goto fail; - - element = _cairo_array_index (&index, i); - status = cff_dict_read (font->fd_dict[i], element->data, element->length); - if (unlikely (status)) - goto fail; - - operand = cff_dict_get_operands (font->fd_dict[i], PRIVATE_OP, &size); - if (operand == NULL) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto fail; - } - operand = decode_integer (operand, &size); - decode_integer (operand, &offset); - status = cff_dict_init (&font->fd_private_dict[i]); - if (unlikely (status)) - goto fail; - - cff_index_init (&font->fd_local_sub_index[i]); - status = cairo_cff_font_read_private_dict (font, - font->fd_private_dict[i], - &font->fd_local_sub_index[i], - &font->fd_local_sub_bias[i], - &font->fd_local_subs_used[i], - &font->fd_default_width[i], - &font->fd_nominal_width[i], - font->data + offset, - size); - if (unlikely (status)) - goto fail; - - /* Set integer operand to max value to use max size encoding to reserve - * space for any value later */ - end_buf = encode_integer_max (buf, 0); - end_buf = encode_integer_max (end_buf, 0); - status = cff_dict_set_operands (font->fd_dict[i], PRIVATE_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - } - - return CAIRO_STATUS_SUCCESS; - -fail: - cff_index_fini (&index); - - return status; -} - -static void -cairo_cff_font_read_font_metrics (cairo_cff_font_t *font, cairo_hash_table_t *top_dict) -{ - unsigned char *p; - unsigned char *end; - int size; - double x_min, y_min, x_max, y_max; - double xx, yx, xy, yy; - - x_min = 0.0; - y_min = 0.0; - x_max = 0.0; - y_max = 0.0; - p = cff_dict_get_operands (font->top_dict, FONTBBOX_OP, &size); - if (p) { - end = p + size; - if (p < end) - p = decode_number (p, &x_min); - if (p < end) - p = decode_number (p, &y_min); - if (p < end) - p = decode_number (p, &x_max); - if (p < end) - p = decode_number (p, &y_max); - } - font->x_min = floor (x_min); - font->y_min = floor (y_min); - font->x_max = floor (x_max); - font->y_max = floor (y_max); - font->ascent = font->y_max; - font->descent = font->y_min; - - xx = 0.001; - yx = 0.0; - xy = 0.0; - yy = 0.001; - p = cff_dict_get_operands (font->top_dict, FONTMATRIX_OP, &size); - if (p) { - end = p + size; - if (p < end) - p = decode_number (p, &xx); - if (p < end) - p = decode_number (p, &yx); - if (p < end) - p = decode_number (p, &xy); - if (p < end) - p = decode_number (p, &yy); - } - /* Freetype uses 1/yy to get units per EM */ - font->units_per_em = _cairo_round(1.0/yy); -} - -static cairo_int_status_t -cairo_cff_font_read_top_dict (cairo_cff_font_t *font) -{ - cairo_array_t index; - cff_index_element_t *element; - unsigned char buf[20]; - unsigned char *end_buf; - unsigned char *operand; - cairo_int_status_t status; - unsigned char *p; - int size; - int offset; - - cff_index_init (&index); - status = cff_index_read (&index, &font->current_ptr, font->data_end); - if (unlikely (status)) - goto fail; - - element = _cairo_array_index (&index, 0); - status = cff_dict_read (font->top_dict, element->data, element->length); - if (unlikely (status)) - goto fail; - - if (cff_dict_get_operands (font->top_dict, ROS_OP, &size) != NULL) - font->is_cid = TRUE; - else - font->is_cid = FALSE; - - operand = cff_dict_get_operands (font->top_dict, CHARSTRINGS_OP, &size); - decode_integer (operand, &offset); - p = font->data + offset; - status = cff_index_read (&font->charstrings_index, &p, font->data_end); - if (unlikely (status)) - goto fail; - font->num_glyphs = _cairo_array_num_elements (&font->charstrings_index); - - if (font->is_cid) { - operand = cff_dict_get_operands (font->top_dict, CHARSET_OP, &size); - if (!operand) - return CAIRO_INT_STATUS_UNSUPPORTED; - - decode_integer (operand, &offset); - font->charset = font->data + offset; - if (font->charset >= font->data_end) - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (!font->is_opentype) - cairo_cff_font_read_font_metrics (font, font->top_dict); - - if (font->is_cid) { - operand = cff_dict_get_operands (font->top_dict, FDSELECT_OP, &size); - decode_integer (operand, &offset); - status = cairo_cff_font_read_fdselect (font, font->data + offset); - if (unlikely (status)) - goto fail; - - operand = cff_dict_get_operands (font->top_dict, FDARRAY_OP, &size); - decode_integer (operand, &offset); - status = cairo_cff_font_read_cid_fontdict (font, font->data + offset); - if (unlikely (status)) - goto fail; - } else { - operand = cff_dict_get_operands (font->top_dict, PRIVATE_OP, &size); - operand = decode_integer (operand, &size); - decode_integer (operand, &offset); - status = cairo_cff_font_read_private_dict (font, - font->private_dict, - &font->local_sub_index, - &font->local_sub_bias, - &font->local_subs_used, - &font->default_width, - &font->nominal_width, - font->data + offset, - size); - if (unlikely (status)) - goto fail; - } - - /* Use maximum sized encoding to reserve space for later modification. */ - end_buf = encode_integer_max (buf, 0); - status = cff_dict_set_operands (font->top_dict, - CHARSTRINGS_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - - status = cff_dict_set_operands (font->top_dict, - CHARSET_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - - if (font->scaled_font_subset->is_latin) { - status = cff_dict_set_operands (font->top_dict, - ENCODING_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - - /* Private has two operands - size and offset */ - end_buf = encode_integer_max (end_buf, 0); - cff_dict_set_operands (font->top_dict, PRIVATE_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - - } else { - status = cff_dict_set_operands (font->top_dict, - FDSELECT_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - - status = cff_dict_set_operands (font->top_dict, - FDARRAY_OP, buf, end_buf - buf); - if (unlikely (status)) - goto fail; - - cff_dict_remove (font->top_dict, ENCODING_OP); - cff_dict_remove (font->top_dict, PRIVATE_OP); - } - - /* Remove the unique identifier operators as the subsetted font is - * not the same is the original font. */ - cff_dict_remove (font->top_dict, UNIQUEID_OP); - cff_dict_remove (font->top_dict, XUID_OP); - -fail: - cff_index_fini (&index); - - return status; -} - -static cairo_int_status_t -cairo_cff_font_read_strings (cairo_cff_font_t *font) -{ - return cff_index_read (&font->strings_index, &font->current_ptr, font->data_end); -} - -static cairo_int_status_t -cairo_cff_font_read_global_subroutines (cairo_cff_font_t *font) -{ - cairo_int_status_t status; - int num_subs; - - status = cff_index_read (&font->global_sub_index, &font->current_ptr, font->data_end); - if (unlikely (status)) - return status; - - num_subs = _cairo_array_num_elements (&font->global_sub_index); - font->global_subs_used = calloc (num_subs, sizeof(cairo_bool_t)); - if (unlikely (font->global_subs_used == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (num_subs < 1240) - font->global_sub_bias = 107; - else if (num_subs < 33900) - font->global_sub_bias = 1131; - else - font->global_sub_bias = 32768; - - return CAIRO_STATUS_SUCCESS; -} - -typedef cairo_int_status_t -(*font_read_t) (cairo_cff_font_t *font); - -static const font_read_t font_read_funcs[] = { - cairo_cff_font_read_header, - cairo_cff_font_read_name, - cairo_cff_font_read_top_dict, - cairo_cff_font_read_strings, - cairo_cff_font_read_global_subroutines, -}; - -static cairo_int_status_t -cairo_cff_font_read_font (cairo_cff_font_t *font) -{ - cairo_int_status_t status; - unsigned int i; - - for (i = 0; i < ARRAY_LENGTH (font_read_funcs); i++) { - status = font_read_funcs[i] (font); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_set_ros_strings (cairo_cff_font_t *font) -{ - cairo_status_t status; - unsigned char buf[30]; - unsigned char *p; - int sid1, sid2; - const char *registry = "Adobe"; - const char *ordering = "Identity"; - - sid1 = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); - status = cff_index_append_copy (&font->strings_subset_index, - (unsigned char *)registry, - strlen(registry)); - if (unlikely (status)) - return status; - - sid2 = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); - status = cff_index_append_copy (&font->strings_subset_index, - (unsigned char *)ordering, - strlen(ordering)); - if (unlikely (status)) - return status; - - p = encode_integer (buf, sid1); - p = encode_integer (p, sid2); - p = encode_integer (p, 0); - status = cff_dict_set_operands (font->top_dict, ROS_OP, buf, p - buf); - if (unlikely (status)) - return status; - - p = encode_integer (buf, font->scaled_font_subset->num_glyphs); - status = cff_dict_set_operands (font->top_dict, CIDCOUNT_OP, buf, p - buf); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_subset_dict_string(cairo_cff_font_t *font, - cairo_hash_table_t *dict, - int operator) -{ - int size; - unsigned char *p; - int sid; - unsigned char buf[100]; - cff_index_element_t *element; - cairo_status_t status; - - p = cff_dict_get_operands (dict, operator, &size); - if (!p) - return CAIRO_STATUS_SUCCESS; - - decode_integer (p, &sid); - if (sid < NUM_STD_STRINGS) - return CAIRO_STATUS_SUCCESS; - - element = _cairo_array_index (&font->strings_index, sid - NUM_STD_STRINGS); - sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); - status = cff_index_append (&font->strings_subset_index, element->data, element->length); - if (unlikely (status)) - return status; - - p = encode_integer (buf, sid); - status = cff_dict_set_operands (dict, operator, buf, p - buf); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static const int dict_strings[] = { - VERSION_OP, - NOTICE_OP, - COPYRIGHT_OP, - FULLNAME_OP, - FAMILYNAME_OP, - WEIGHT_OP, - POSTSCRIPT_OP, - BASEFONTNAME_OP, - FONTNAME_OP, -}; - -static cairo_status_t -cairo_cff_font_subset_dict_strings (cairo_cff_font_t *font, - cairo_hash_table_t *dict) -{ - cairo_status_t status; - unsigned int i; - - for (i = 0; i < ARRAY_LENGTH (dict_strings); i++) { - status = cairo_cff_font_subset_dict_string (font, dict, dict_strings[i]); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static unsigned char * -type2_decode_integer (unsigned char *p, int *integer) -{ - if (*p == 28) { - *integer = p[1] << 8 | p[2]; - p += 3; - } else if (*p <= 246) { - *integer = *p++ - 139; - } else if (*p <= 250) { - *integer = (p[0] - 247) * 256 + p[1] + 108; - p += 2; - } else if (*p <= 254) { - *integer = -(p[0] - 251) * 256 - p[1] - 108; - p += 2; - } else { /* *p == 255 */ - /* 16.16 fixed-point number. The fraction is ignored. */ - *integer = (int16_t)((p[1] << 8) | p[2]); - p += 5; - } - return p; -} - -/* Type 2 charstring parser for finding calls to local or global - * subroutines. For non Opentype CFF fonts it also gets the glyph - * widths. - * - * When we find a subroutine operator, the subroutine is marked as in - * use and recursively followed. The subroutine number is the value on - * the top of the stack when the subroutine operator is executed. In - * most fonts the subroutine number is encoded in an integer - * immediately preceding the subroutine operator. However it is - * possible for the subroutine number on the stack to be the result of - * a computation (in which case there will be an operator preceding - * the subroutine operator). If this occurs, subroutine subsetting is - * disabled since we can't easily determine which subroutines are - * used. - * - * The width, if present, is the first integer in the charstring. The - * only way to confirm if the integer at the start of the charstring is - * the width is when the first stack clearing operator is parsed, - * check if there is an extra integer left over on the stack. - * - * When the first stack clearing operator is encountered - * type2_find_width is set to FALSE and type2_found_width is set to - * TRUE if an extra argument is found, otherwise FALSE. - */ -static cairo_status_t -cairo_cff_parse_charstring (cairo_cff_font_t *font, - unsigned char *charstring, int length, - int glyph_id, - cairo_bool_t need_width) -{ - unsigned char *p = charstring; - unsigned char *end = charstring + length; - int integer; - int hint_bytes; - int sub_num; - cff_index_element_t *element; - int fd; - - while (p < end) { - if (*p == 28 || *p >= 32) { - /* Integer value */ - p = type2_decode_integer (p, &integer); - font->type2_stack_size++; - font->type2_stack_top_value = integer; - font->type2_stack_top_is_int = TRUE; - if (!font->type2_seen_first_int) { - font->type2_width = integer; - font->type2_seen_first_int = TRUE; - } - } else if (*p == TYPE2_hstem || *p == TYPE2_vstem || - *p == TYPE2_hstemhm || *p == TYPE2_vstemhm) { - /* Hint operator. The number of hints declared by the - * operator depends on the size of the stack. */ - font->type2_stack_top_is_int = FALSE; - font->type2_num_hints += font->type2_stack_size/2; - if (font->type2_find_width && font->type2_stack_size % 2) - font->type2_found_width = TRUE; - - font->type2_stack_size = 0; - font->type2_find_width = FALSE; - p++; - } else if (*p == TYPE2_hintmask || *p == TYPE2_cntrmask) { - /* Hintmask operator. These operators are followed by a - * variable length mask where the length depends on the - * number of hints declared. The first time this is called - * it is also an implicit vstem if there are arguments on - * the stack. */ - if (font->type2_hintmask_bytes == 0) { - font->type2_stack_top_is_int = FALSE; - font->type2_num_hints += font->type2_stack_size/2; - if (font->type2_find_width && font->type2_stack_size % 2) - font->type2_found_width = TRUE; - - font->type2_stack_size = 0; - font->type2_find_width = FALSE; - font->type2_hintmask_bytes = (font->type2_num_hints+7)/8; - } - - hint_bytes = font->type2_hintmask_bytes; - p++; - p += hint_bytes; - } else if (*p == TYPE2_rmoveto) { - if (font->type2_find_width && font->type2_stack_size > 2) - font->type2_found_width = TRUE; - - font->type2_stack_size = 0; - font->type2_find_width = FALSE; - font->type2_has_path = TRUE; - p++; - } else if (*p == TYPE2_hmoveto || *p == TYPE2_vmoveto) { - if (font->type2_find_width && font->type2_stack_size > 1) - font->type2_found_width = TRUE; - - font->type2_stack_size = 0; - font->type2_find_width = FALSE; - font->type2_has_path = TRUE; - p++; - } else if (*p == TYPE2_endchar) { - if (!font->type2_has_path && font->type2_stack_size > 3) - return CAIRO_INT_STATUS_UNSUPPORTED; /* seac (Ref Appendix C of Type 2 Charstring Format */ - - if (font->type2_find_width && font->type2_stack_size > 0) - font->type2_found_width = TRUE; - - return CAIRO_STATUS_SUCCESS; - } else if (*p == TYPE2_callsubr) { - /* call to local subroutine */ - if (! font->type2_stack_top_is_int) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (++font->type2_nesting_level > MAX_SUBROUTINE_NESTING) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p++; - font->type2_stack_top_is_int = FALSE; - font->type2_stack_size--; - if (font->type2_find_width && font->type2_stack_size == 0) - font->type2_seen_first_int = FALSE; - - if (font->is_cid) { - fd = font->fdselect[glyph_id]; - sub_num = font->type2_stack_top_value + font->fd_local_sub_bias[fd]; - element = _cairo_array_index (&font->fd_local_sub_index[fd], sub_num); - if (! font->fd_local_subs_used[fd][sub_num]) { - font->fd_local_subs_used[fd][sub_num] = TRUE; - cairo_cff_parse_charstring (font, element->data, element->length, glyph_id, need_width); - } - } else { - sub_num = font->type2_stack_top_value + font->local_sub_bias; - element = _cairo_array_index (&font->local_sub_index, sub_num); - if (! font->local_subs_used[sub_num] || - (need_width && !font->type2_found_width)) - { - font->local_subs_used[sub_num] = TRUE; - cairo_cff_parse_charstring (font, element->data, element->length, glyph_id, need_width); - } - } - font->type2_nesting_level--; - } else if (*p == TYPE2_callgsubr) { - /* call to global subroutine */ - if (! font->type2_stack_top_is_int) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (++font->type2_nesting_level > MAX_SUBROUTINE_NESTING) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p++; - font->type2_stack_size--; - font->type2_stack_top_is_int = FALSE; - if (font->type2_find_width && font->type2_stack_size == 0) - font->type2_seen_first_int = FALSE; - - sub_num = font->type2_stack_top_value + font->global_sub_bias; - element = _cairo_array_index (&font->global_sub_index, sub_num); - if (! font->global_subs_used[sub_num] || - (need_width && !font->type2_found_width)) - { - font->global_subs_used[sub_num] = TRUE; - cairo_cff_parse_charstring (font, element->data, element->length, glyph_id, need_width); - } - font->type2_nesting_level--; - } else if (*p == 12) { - /* 2 byte instruction */ - - /* All the 2 byte operators are either not valid before a - * stack clearing operator or they are one of the - * arithmetic, storage, or conditional operators. */ - if (need_width && font->type2_find_width) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p += 2; - font->type2_stack_top_is_int = FALSE; - } else { - /* 1 byte instruction */ - p++; - font->type2_stack_top_is_int = FALSE; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_find_width_and_subroutines_used (cairo_cff_font_t *font, - unsigned char *charstring, int length, - int glyph_id, int subset_id) -{ - cairo_status_t status; - int width; - int fd; - - font->type2_stack_size = 0; - font->type2_stack_top_value = 0;; - font->type2_stack_top_is_int = FALSE; - font->type2_num_hints = 0; - font->type2_hintmask_bytes = 0; - font->type2_nesting_level = 0; - font->type2_seen_first_int = FALSE; - font->type2_find_width = TRUE; - font->type2_found_width = FALSE; - font->type2_width = 0; - font->type2_has_path = FALSE; - - status = cairo_cff_parse_charstring (font, charstring, length, glyph_id, TRUE); - if (status) - return status; - - if (!font->is_opentype) { - if (font->is_cid) { - fd = font->fdselect[glyph_id]; - if (font->type2_found_width) - width = font->fd_nominal_width[fd] + font->type2_width; - else - width = font->fd_default_width[fd]; - } else { - if (font->type2_found_width) - width = font->nominal_width + font->type2_width; - else - width = font->default_width; - } - font->widths[subset_id] = width; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_cff_font_get_gid_for_cid (cairo_cff_font_t *font, unsigned long cid, unsigned long *gid) -{ - unsigned char *p; - unsigned long first_gid; - unsigned long first_cid; - int num_left; - unsigned long c, g; - - if (cid == 0) { - *gid = 0; - return CAIRO_STATUS_SUCCESS; - } - - switch (font->charset[0]) { - /* Format 0 */ - case 0: - p = font->charset + 1; - g = 1; - while (g <= (unsigned)font->num_glyphs && p < font->data_end) { - c = get_unaligned_be16 (p); - if (c == cid) { - *gid = g; - return CAIRO_STATUS_SUCCESS; - } - g++; - p += 2; - } - break; - - /* Format 1 */ - case 1: - first_gid = 1; - p = font->charset + 1; - while (first_gid <= (unsigned)font->num_glyphs && p + 2 < font->data_end) { - first_cid = get_unaligned_be16 (p); - num_left = p[2]; - if (cid >= first_cid && cid <= first_cid + num_left) { - *gid = first_gid + cid - first_cid; - return CAIRO_STATUS_SUCCESS; - } - first_gid += num_left + 1; - p += 3; - } - break; - - /* Format 2 */ - case 2: - first_gid = 1; - p = font->charset + 1; - while (first_gid <= (unsigned)font->num_glyphs && p + 3 < font->data_end) { - first_cid = get_unaligned_be16 (p); - num_left = get_unaligned_be16 (p+2); - if (cid >= first_cid && cid <= first_cid + num_left) { - *gid = first_gid + cid - first_cid; - return CAIRO_STATUS_SUCCESS; - } - first_gid += num_left + 1; - p += 4; - } - break; - - default: - break; - } - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_int_status_t -cairo_cff_font_subset_charstrings_and_subroutines (cairo_cff_font_t *font) -{ - cff_index_element_t *element; - unsigned int i; - cairo_int_status_t status; - unsigned long glyph, cid; - - font->subset_subroutines = TRUE; - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - if (font->is_cid) { - cid = font->scaled_font_subset->glyphs[i]; - status = cairo_cff_font_get_gid_for_cid (font, cid, &glyph); - if (unlikely (status)) - return status; - } else { - glyph = font->scaled_font_subset->glyphs[i]; - } - element = _cairo_array_index (&font->charstrings_index, glyph); - status = cff_index_append (&font->charstrings_subset_index, - element->data, - element->length); - if (unlikely (status)) - return status; - - if (font->subset_subroutines) { - status = cairo_cff_find_width_and_subroutines_used (font, - element->data, element->length, - glyph, i); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - /* If parsing the charstrings fails we embed all the - * subroutines. But if the font is not opentype we - * need to successfully parse all charstrings to get - * the widths. */ - font->subset_subroutines = FALSE; - if (!font->is_opentype) - return status; - } else if (unlikely (status)) { - return status; - } - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_subset_fontdict (cairo_cff_font_t *font) -{ - unsigned int i; - int fd; - int *reverse_map; - unsigned long cid, gid; - cairo_int_status_t status; - - font->fdselect_subset = calloc (font->scaled_font_subset->num_glyphs, - sizeof (int)); - if (unlikely (font->fdselect_subset == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->fd_subset_map = calloc (font->num_fontdicts, sizeof (int)); - if (unlikely (font->fd_subset_map == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->private_dict_offset = calloc (font->num_fontdicts, sizeof (int)); - if (unlikely (font->private_dict_offset == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - reverse_map = calloc (font->num_fontdicts, sizeof (int)); - if (unlikely (reverse_map == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - for (i = 0; i < font->num_fontdicts; i++) - reverse_map[i] = -1; - - font->num_subset_fontdicts = 0; - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - cid = font->scaled_font_subset->glyphs[i]; - status = cairo_cff_font_get_gid_for_cid (font, cid, &gid); - if (unlikely (status)) { - free (reverse_map); - return status; - } - - fd = font->fdselect[gid]; - if (reverse_map[fd] < 0) { - font->fd_subset_map[font->num_subset_fontdicts] = fd; - reverse_map[fd] = font->num_subset_fontdicts++; - } - font->fdselect_subset[i] = reverse_map[fd]; - } - - free (reverse_map); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_create_cid_fontdict (cairo_cff_font_t *font) -{ - unsigned char buf[100]; - unsigned char *end_buf; - cairo_status_t status; - - font->num_fontdicts = 1; - font->fd_dict = malloc (sizeof (cairo_hash_table_t *)); - if (unlikely (font->fd_dict == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (cff_dict_init (&font->fd_dict[0])) { - free (font->fd_dict); - font->fd_dict = NULL; - font->num_fontdicts = 0; - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - font->fd_subset_map = malloc (sizeof (int)); - if (unlikely (font->fd_subset_map == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->private_dict_offset = malloc (sizeof (int)); - if (unlikely (font->private_dict_offset == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->fd_subset_map[0] = 0; - font->num_subset_fontdicts = 1; - - /* Set integer operand to max value to use max size encoding to reserve - * space for any value later */ - end_buf = encode_integer_max (buf, 0); - end_buf = encode_integer_max (end_buf, 0); - status = cff_dict_set_operands (font->fd_dict[0], PRIVATE_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_subset_strings (cairo_cff_font_t *font) -{ - cairo_status_t status; - unsigned int i; - - status = cairo_cff_font_subset_dict_strings (font, font->top_dict); - if (unlikely (status)) - return status; - - if (font->is_cid) { - for (i = 0; i < font->num_subset_fontdicts; i++) { - status = cairo_cff_font_subset_dict_strings (font, font->fd_dict[font->fd_subset_map[i]]); - if (unlikely (status)) - return status; - - status = cairo_cff_font_subset_dict_strings (font, font->fd_private_dict[font->fd_subset_map[i]]); - if (unlikely (status)) - return status; - } - } else { - status = cairo_cff_font_subset_dict_strings (font, font->private_dict); - } - - return status; -} - -/* The Euro is the only the only character in the winansi encoding - * with a glyph name that is not a CFF standard string. As the strings - * are written before the charset, we need to check during the - * subsetting phase if the Euro glyph is required and add the - * glyphname to the list of strings to write out. - */ -static cairo_status_t -cairo_cff_font_add_euro_charset_string (cairo_cff_font_t *font) -{ - cairo_status_t status; - unsigned int i; - int ch; - const char *euro = "Euro"; - - for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { - ch = font->scaled_font_subset->to_latin_char[i]; - if (ch == 128) { - font->euro_sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); - status = cff_index_append_copy (&font->strings_subset_index, - (unsigned char *)euro, strlen(euro)); - return status; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_subset_font (cairo_cff_font_t *font) -{ - cairo_status_t status; - - if (!font->scaled_font_subset->is_latin) { - status = cairo_cff_font_set_ros_strings (font); - if (unlikely (status)) - return status; - } - - status = cairo_cff_font_subset_charstrings_and_subroutines (font); - if (unlikely (status)) - return status; - - if (!font->scaled_font_subset->is_latin) { - if (font->is_cid) - status = cairo_cff_font_subset_fontdict (font); - else - status = cairo_cff_font_create_cid_fontdict (font); - if (unlikely (status)) - return status; - } else { - font->private_dict_offset = malloc (sizeof (int)); - if (unlikely (font->private_dict_offset == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - status = cairo_cff_font_subset_strings (font); - if (unlikely (status)) - return status; - - if (font->scaled_font_subset->is_latin) - status = cairo_cff_font_add_euro_charset_string (font); - - return status; -} - -/* Set the operand of the specified operator in the (already written) - * top dict to point to the current position in the output - * array. Operands updated with this function must have previously - * been encoded with the 5-byte (max) integer encoding. */ -static void -cairo_cff_font_set_topdict_operator_to_cur_pos (cairo_cff_font_t *font, - int operator) -{ - int cur_pos; - int offset; - int size; - unsigned char buf[10]; - unsigned char *buf_end; - unsigned char *op_ptr; - - cur_pos = _cairo_array_num_elements (&font->output); - buf_end = encode_integer_max (buf, cur_pos); - offset = cff_dict_get_location (font->top_dict, operator, &size); - assert (offset > 0); - op_ptr = _cairo_array_index (&font->output, offset); - memcpy (op_ptr, buf, buf_end - buf); -} - -static cairo_status_t -cairo_cff_font_write_header (cairo_cff_font_t *font) -{ - return _cairo_array_append_multiple (&font->output, - font->header, - font->header->header_size); -} - -static cairo_status_t -cairo_cff_font_write_name (cairo_cff_font_t *font) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_array_t index; - - cff_index_init (&index); - - status = cff_index_append_copy (&index, - (unsigned char *) font->ps_name, - strlen(font->ps_name)); - if (unlikely (status)) - goto FAIL; - - status = cff_index_write (&index, &font->output); - if (unlikely (status)) - goto FAIL; - -FAIL: - cff_index_fini (&index); - - return status; -} - -static cairo_status_t -cairo_cff_font_write_top_dict (cairo_cff_font_t *font) -{ - uint16_t count; - unsigned char buf[10]; - unsigned char *p; - int offset_index; - int dict_start, dict_size; - int offset_size = 4; - cairo_status_t status; - - /* Write an index containing the top dict */ - - count = cpu_to_be16 (1); - status = _cairo_array_append_multiple (&font->output, &count, 2); - if (unlikely (status)) - return status; - buf[0] = offset_size; - status = _cairo_array_append (&font->output, buf); - if (unlikely (status)) - return status; - encode_index_offset (buf, offset_size, 1); - status = _cairo_array_append_multiple (&font->output, buf, offset_size); - if (unlikely (status)) - return status; - - /* Reserve space for last element of offset array and update after - * dict is written */ - offset_index = _cairo_array_num_elements (&font->output); - status = _cairo_array_append_multiple (&font->output, buf, offset_size); - if (unlikely (status)) - return status; - - dict_start = _cairo_array_num_elements (&font->output); - status = cff_dict_write (font->top_dict, &font->output); - if (unlikely (status)) - return status; - dict_size = _cairo_array_num_elements (&font->output) - dict_start; - - encode_index_offset (buf, offset_size, dict_size + 1); - p = _cairo_array_index (&font->output, offset_index); - memcpy (p, buf, offset_size); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_strings (cairo_cff_font_t *font) -{ - return cff_index_write (&font->strings_subset_index, &font->output); -} - -static cairo_status_t -cairo_cff_font_write_global_subrs (cairo_cff_font_t *font) -{ - unsigned int i; - unsigned char return_op = TYPE2_return; - - /* poppler and fontforge don't like zero length subroutines so we - * replace unused subroutines with a 'return' instruction. */ - if (font->subset_subroutines) { - for (i = 0; i < _cairo_array_num_elements (&font->global_sub_index); i++) { - if (! font->global_subs_used[i]) - cff_index_set_object (&font->global_sub_index, i, &return_op, 1); - } - } - - return cff_index_write (&font->global_sub_index, &font->output); -} - -static cairo_status_t -cairo_cff_font_write_encoding (cairo_cff_font_t *font) -{ - unsigned char buf[2]; - cairo_status_t status; - unsigned int i; - - cairo_cff_font_set_topdict_operator_to_cur_pos (font, ENCODING_OP); - buf[0] = 0; /* Format 0 */ - buf[1] = font->scaled_font_subset->num_glyphs - 1; - status = _cairo_array_append_multiple (&font->output, buf, 2); - if (unlikely (status)) - return status; - - for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { - unsigned char ch = font->scaled_font_subset->to_latin_char[i]; - status = _cairo_array_append (&font->output, &ch); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_fdselect (cairo_cff_font_t *font) -{ - unsigned char data; - unsigned int i; - cairo_int_status_t status; - - cairo_cff_font_set_topdict_operator_to_cur_pos (font, FDSELECT_OP); - - if (font->is_cid) { - data = 0; - status = _cairo_array_append (&font->output, &data); - if (unlikely (status)) - return status; - - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - data = font->fdselect_subset[i]; - status = _cairo_array_append (&font->output, &data); - if (unlikely (status)) - return status; - } - } else { - unsigned char byte; - uint16_t word; - - status = _cairo_array_grow_by (&font->output, 9); - if (unlikely (status)) - return status; - - byte = 3; - status = _cairo_array_append (&font->output, &byte); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - word = cpu_to_be16 (1); - status = _cairo_array_append_multiple (&font->output, &word, 2); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - word = cpu_to_be16 (0); - status = _cairo_array_append_multiple (&font->output, &word, 2); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - byte = 0; - status = _cairo_array_append (&font->output, &byte); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - word = cpu_to_be16 (font->scaled_font_subset->num_glyphs); - status = _cairo_array_append_multiple (&font->output, &word, 2); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - return CAIRO_STATUS_SUCCESS; -} - -/* Winansi to CFF standard strings mapping for characters 128 to 255 */ -static const int winansi_to_cff_std_string[] = { - /* 128 */ - 0, 0, 117, 101, 118, 121, 112, 113, - 126, 122, 192, 107, 142, 0, 199, 0, - /* 144 */ - 0, 65, 8, 105, 119, 116, 111, 137, - 127, 153, 221, 108, 148, 0, 228, 198, - /* 160 */ - 0, 96, 97, 98, 103, 100, 160, 102, - 131, 170, 139, 106, 151, 0, 165, 128, - /* 176 */ - 161, 156, 164, 169, 125, 152, 115, 114, - 133, 150, 143, 120, 158, 155, 163, 123, - /* 192 */ - 174, 171, 172, 176, 173, 175, 138, 177, - 181, 178, 179, 180, 185, 182, 183, 184, - /* 208 */ - 154, 186, 190, 187, 188, 191, 189, 168, - 141, 196, 193, 194, 195, 197, 157, 149, - /* 224 */ - 203, 200, 201, 205, 202, 204, 144, 206, - 210, 207, 208, 209, 214, 211, 212, 213, - /* 240 */ - 167, 215, 219, 216, 217, 220, 218, 159, - 147, 225, 222, 223, 224, 226, 162, 227, -}; - -static int -cairo_cff_font_get_sid_for_winansi_char (cairo_cff_font_t *font, int ch) -{ - int sid; - - if (ch == 39) { - sid = 104; - - } else if (ch == 96) { - sid = 124; - - } else if (ch >= 32 && ch <= 126) { - sid = ch - 31; - - } else if (ch == 128) { - assert (font->euro_sid >= NUM_STD_STRINGS); - sid = font->euro_sid; - - } else if (ch >= 128 && ch <= 255) { - sid = winansi_to_cff_std_string[ch - 128]; - - } else { - sid = 0; - } - - return sid; -} - -static cairo_status_t -cairo_cff_font_write_type1_charset (cairo_cff_font_t *font) -{ - unsigned char format = 0; - unsigned int i; - int ch, sid; - cairo_status_t status; - uint16_t sid_be16; - - cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSET_OP); - status = _cairo_array_append (&font->output, &format); - if (unlikely (status)) - return status; - - for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { - ch = font->scaled_font_subset->to_latin_char[i]; - sid = cairo_cff_font_get_sid_for_winansi_char (font, ch); - if (unlikely (status)) - return status; - - sid_be16 = cpu_to_be16(sid); - status = _cairo_array_append_multiple (&font->output, &sid_be16, sizeof(sid_be16)); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_cid_charset (cairo_cff_font_t *font) -{ - unsigned char byte; - uint16_t word; - cairo_status_t status; - - cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSET_OP); - status = _cairo_array_grow_by (&font->output, 5); - if (unlikely (status)) - return status; - - byte = 2; - status = _cairo_array_append (&font->output, &byte); - assert (status == CAIRO_STATUS_SUCCESS); - - word = cpu_to_be16 (1); - status = _cairo_array_append_multiple (&font->output, &word, 2); - assert (status == CAIRO_STATUS_SUCCESS); - - word = cpu_to_be16 (font->scaled_font_subset->num_glyphs - 2); - status = _cairo_array_append_multiple (&font->output, &word, 2); - assert (status == CAIRO_STATUS_SUCCESS); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_charstrings (cairo_cff_font_t *font) -{ - cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSTRINGS_OP); - - return cff_index_write (&font->charstrings_subset_index, &font->output); -} - -static cairo_status_t -cairo_cff_font_write_cid_fontdict (cairo_cff_font_t *font) -{ - unsigned int i; - cairo_int_status_t status; - unsigned int offset_array; - unsigned char *offset_array_ptr; - int offset_base; - uint16_t count; - uint8_t offset_size = 4; - - cairo_cff_font_set_topdict_operator_to_cur_pos (font, FDARRAY_OP); - count = cpu_to_be16 (font->num_subset_fontdicts); - status = _cairo_array_append_multiple (&font->output, &count, sizeof (uint16_t)); - if (unlikely (status)) - return status; - status = _cairo_array_append (&font->output, &offset_size); - if (unlikely (status)) - return status; - - offset_array = _cairo_array_num_elements (&font->output); - status = _cairo_array_allocate (&font->output, - (font->num_subset_fontdicts + 1)*offset_size, - (void **) &offset_array_ptr); - if (unlikely (status)) - return status; - offset_base = _cairo_array_num_elements (&font->output) - 1; - put_unaligned_be32(1, offset_array_ptr); - offset_array += sizeof(uint32_t); - for (i = 0; i < font->num_subset_fontdicts; i++) { - status = cff_dict_write (font->fd_dict[font->fd_subset_map[i]], - &font->output); - if (unlikely (status)) - return status; - - offset_array_ptr = _cairo_array_index (&font->output, offset_array); - put_unaligned_be32 (_cairo_array_num_elements (&font->output) - offset_base, - offset_array_ptr); - offset_array += sizeof(uint32_t); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_private_dict (cairo_cff_font_t *font, - int dict_num, - cairo_hash_table_t *parent_dict, - cairo_hash_table_t *private_dict) -{ - int offset; - int size; - unsigned char buf[10]; - unsigned char *buf_end; - unsigned char *p; - cairo_status_t status; - - /* Write private dict and update offset and size in top dict */ - font->private_dict_offset[dict_num] = _cairo_array_num_elements (&font->output); - status = cff_dict_write (private_dict, &font->output); - if (unlikely (status)) - return status; - - size = _cairo_array_num_elements (&font->output) - font->private_dict_offset[dict_num]; - /* private entry has two operands - size and offset */ - buf_end = encode_integer_max (buf, size); - buf_end = encode_integer_max (buf_end, font->private_dict_offset[dict_num]); - offset = cff_dict_get_location (parent_dict, PRIVATE_OP, &size); - assert (offset > 0); - p = _cairo_array_index (&font->output, offset); - memcpy (p, buf, buf_end - buf); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_local_sub (cairo_cff_font_t *font, - int dict_num, - cairo_hash_table_t *private_dict, - cairo_array_t *local_sub_index, - cairo_bool_t *local_subs_used) -{ - int offset; - int size; - unsigned char buf[10]; - unsigned char *buf_end; - unsigned char *p; - cairo_status_t status; - unsigned int i; - unsigned char return_op = TYPE2_return; - - if (_cairo_array_num_elements (local_sub_index) > 0) { - /* Write local subroutines and update offset in private - * dict. Local subroutines offset is relative to start of - * private dict */ - offset = _cairo_array_num_elements (&font->output) - font->private_dict_offset[dict_num]; - buf_end = encode_integer_max (buf, offset); - offset = cff_dict_get_location (private_dict, LOCAL_SUB_OP, &size); - assert (offset > 0); - p = _cairo_array_index (&font->output, offset); - memcpy (p, buf, buf_end - buf); - - /* poppler and fontforge don't like zero length subroutines so - * we replace unused subroutines with a 'return' instruction. - */ - if (font->subset_subroutines) { - for (i = 0; i < _cairo_array_num_elements (local_sub_index); i++) { - if (! local_subs_used[i]) - cff_index_set_object (local_sub_index, i, &return_op, 1); - } - } - status = cff_index_write (local_sub_index, &font->output); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - - -static cairo_status_t -cairo_cff_font_write_cid_private_dict_and_local_sub (cairo_cff_font_t *font) -{ - unsigned int i; - cairo_int_status_t status; - - if (font->is_cid) { - for (i = 0; i < font->num_subset_fontdicts; i++) { - status = cairo_cff_font_write_private_dict ( - font, - i, - font->fd_dict[font->fd_subset_map[i]], - font->fd_private_dict[font->fd_subset_map[i]]); - if (unlikely (status)) - return status; - } - - for (i = 0; i < font->num_subset_fontdicts; i++) { - status = cairo_cff_font_write_local_sub ( - font, - i, - font->fd_private_dict[font->fd_subset_map[i]], - &font->fd_local_sub_index[font->fd_subset_map[i]], - font->fd_local_subs_used[font->fd_subset_map[i]]); - if (unlikely (status)) - return status; - } - } else { - status = cairo_cff_font_write_private_dict (font, - 0, - font->fd_dict[0], - font->private_dict); - if (unlikely (status)) - return status; - - status = cairo_cff_font_write_local_sub (font, - 0, - font->private_dict, - &font->local_sub_index, - font->local_subs_used); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_cff_font_write_type1_private_dict_and_local_sub (cairo_cff_font_t *font) -{ - cairo_int_status_t status; - - status = cairo_cff_font_write_private_dict (font, - 0, - font->top_dict, - font->private_dict); - if (unlikely (status)) - return status; - - status = cairo_cff_font_write_local_sub (font, - 0, - font->private_dict, - &font->local_sub_index, - font->local_subs_used); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - - -typedef cairo_status_t -(*font_write_t) (cairo_cff_font_t *font); - -static const font_write_t font_write_cid_funcs[] = { - cairo_cff_font_write_header, - cairo_cff_font_write_name, - cairo_cff_font_write_top_dict, - cairo_cff_font_write_strings, - cairo_cff_font_write_global_subrs, - cairo_cff_font_write_cid_charset, - cairo_cff_font_write_fdselect, - cairo_cff_font_write_charstrings, - cairo_cff_font_write_cid_fontdict, - cairo_cff_font_write_cid_private_dict_and_local_sub, -}; - -static const font_write_t font_write_type1_funcs[] = { - cairo_cff_font_write_header, - cairo_cff_font_write_name, - cairo_cff_font_write_top_dict, - cairo_cff_font_write_strings, - cairo_cff_font_write_global_subrs, - cairo_cff_font_write_encoding, - cairo_cff_font_write_type1_charset, - cairo_cff_font_write_charstrings, - cairo_cff_font_write_type1_private_dict_and_local_sub, -}; - -static cairo_status_t -cairo_cff_font_write_subset (cairo_cff_font_t *font) -{ - cairo_int_status_t status; - unsigned int i; - - if (font->scaled_font_subset->is_latin) { - for (i = 0; i < ARRAY_LENGTH (font_write_type1_funcs); i++) { - status = font_write_type1_funcs[i] (font); - if (unlikely (status)) - return status; - } - } else { - for (i = 0; i < ARRAY_LENGTH (font_write_cid_funcs); i++) { - status = font_write_cid_funcs[i] (font); - if (unlikely (status)) - return status; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_cff_font_generate (cairo_cff_font_t *font, - const char **data, - unsigned long *length) -{ - cairo_int_status_t status; - - status = cairo_cff_font_read_font (font); - if (unlikely (status)) - return status; - - /* If the PS name is not found, create a CairoFont-x-y name. */ - if (font->ps_name == NULL) { - font->ps_name = malloc (30); - if (unlikely (font->ps_name == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - snprintf(font->ps_name, 30, "CairoFont-%u-%u", - font->scaled_font_subset->font_id, - font->scaled_font_subset->subset_id); - } - - status = cairo_cff_font_subset_font (font); - if (unlikely (status)) - return status; - - status = cairo_cff_font_write_subset (font); - if (unlikely (status)) - return status; - - - *data = _cairo_array_index (&font->output, 0); - *length = _cairo_array_num_elements (&font->output); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_cff_font_create_set_widths (cairo_cff_font_t *font) -{ - unsigned long size; - unsigned long long_entry_size; - unsigned long short_entry_size; - unsigned int i; - tt_hhea_t hhea; - int num_hmetrics; - uint16_t short_entry; - int glyph_index; - cairo_int_status_t status; - - size = sizeof (tt_hhea_t); - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hhea, 0, - (unsigned char*) &hhea, &size); - if (unlikely (status)) - return status; - num_hmetrics = be16_to_cpu (hhea.num_hmetrics); - - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - glyph_index = font->scaled_font_subset->glyphs[i]; - long_entry_size = 2 * sizeof (int16_t); - short_entry_size = sizeof (int16_t); - if (glyph_index < num_hmetrics) { - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hmtx, - glyph_index * long_entry_size, - (unsigned char *) &short_entry, - &short_entry_size); - if (unlikely (status)) - return status; - } - else - { - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hmtx, - (num_hmetrics - 1) * long_entry_size, - (unsigned char *) &short_entry, - &short_entry_size); - if (unlikely (status)) - return status; - } - font->widths[i] = be16_to_cpu (short_entry); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -check_fontdata_is_cff (const unsigned char *data, long length) -{ - cff_header_t *header; - - if (length < (long)sizeof (cff_header_t)) - return FALSE; - - header = (cff_header_t *) data; - if (header->major == 1 && - header->minor == 0 && - header->header_size == 4) - { - return TRUE; - } - - return FALSE; -} - -static cairo_int_status_t -_cairo_cff_font_load_opentype_cff (cairo_cff_font_t *font) -{ - const cairo_scaled_font_backend_t *backend = font->backend; - cairo_status_t status; - tt_head_t head; - tt_hhea_t hhea; - unsigned long size, data_length; - - if (!backend->load_truetype_table) - return CAIRO_INT_STATUS_UNSUPPORTED; - - data_length = 0; - status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_CFF, 0, NULL, &data_length); - if (status) - return status; - - size = sizeof (tt_head_t); - status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_head, 0, - (unsigned char *) &head, &size); - if (unlikely (status)) - return status; - - size = sizeof (tt_hhea_t); - status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hhea, 0, - (unsigned char *) &hhea, &size); - if (unlikely (status)) - return status; - - size = 0; - status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hmtx, 0, NULL, &size); - if (unlikely (status)) - return status; - - font->x_min = (int16_t) be16_to_cpu (head.x_min); - font->y_min = (int16_t) be16_to_cpu (head.y_min); - font->x_max = (int16_t) be16_to_cpu (head.x_max); - font->y_max = (int16_t) be16_to_cpu (head.y_max); - font->ascent = (int16_t) be16_to_cpu (hhea.ascender); - font->descent = (int16_t) be16_to_cpu (hhea.descender); - font->units_per_em = (int16_t) be16_to_cpu (head.units_per_em); - if (font->units_per_em == 0) - font->units_per_em = 1000; - - font->font_name = NULL; - status = _cairo_truetype_read_font_name (font->scaled_font_subset->scaled_font, - &font->ps_name, - &font->font_name); - if (_cairo_status_is_error (status)) - return status; - - font->is_opentype = TRUE; - font->data_length = data_length; - font->data = malloc (data_length); - if (unlikely (font->data == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_CFF, 0, font->data, - &font->data_length); - if (unlikely (status)) - return status; - - if (!check_fontdata_is_cff (font->data, data_length)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_cff_font_load_cff (cairo_cff_font_t *font) -{ - const cairo_scaled_font_backend_t *backend = font->backend; - cairo_status_t status; - unsigned long data_length; - - if (!backend->load_type1_data) - return CAIRO_INT_STATUS_UNSUPPORTED; - - data_length = 0; - status = backend->load_type1_data (font->scaled_font_subset->scaled_font, - 0, NULL, &data_length); - if (unlikely (status)) - return status; - - font->font_name = NULL; - font->is_opentype = FALSE; - font->data_length = data_length; - font->data = malloc (data_length); - if (unlikely (font->data == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = font->backend->load_type1_data (font->scaled_font_subset->scaled_font, - 0, font->data, &font->data_length); - if (unlikely (status)) - return status; - - if (!check_fontdata_is_cff (font->data, data_length)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_cff_font_create (cairo_scaled_font_subset_t *scaled_font_subset, - cairo_cff_font_t **font_return, - const char *subset_name) -{ - const cairo_scaled_font_backend_t *backend; - cairo_int_status_t status; - cairo_cff_font_t *font; - - backend = scaled_font_subset->scaled_font->backend; - - /* We need to use a fallback font generated from the synthesized outlines. */ - if (backend->is_synthetic && backend->is_synthetic (scaled_font_subset->scaled_font)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - font = calloc (1, sizeof (cairo_cff_font_t)); - if (unlikely (font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->backend = backend; - font->scaled_font_subset = scaled_font_subset; - - status = _cairo_cff_font_load_opentype_cff (font); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - status = _cairo_cff_font_load_cff (font); - if (status) - goto fail1; - - font->data_end = font->data + font->data_length; - _cairo_array_init (&font->output, sizeof (char)); - status = _cairo_array_grow_by (&font->output, 4096); - if (unlikely (status)) - goto fail2; - - font->subset_font_name = strdup (subset_name); - if (unlikely (font->subset_font_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - - font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int)); - if (unlikely (font->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - - if (font->is_opentype) { - status = cairo_cff_font_create_set_widths (font); - if (unlikely (status)) - goto fail4; - } - - status = cff_dict_init (&font->top_dict); - if (unlikely (status)) - goto fail4; - - status = cff_dict_init (&font->private_dict); - if (unlikely (status)) - goto fail5; - - cff_index_init (&font->strings_index); - cff_index_init (&font->charstrings_index); - cff_index_init (&font->global_sub_index); - cff_index_init (&font->local_sub_index); - cff_index_init (&font->charstrings_subset_index); - cff_index_init (&font->strings_subset_index); - font->euro_sid = 0; - font->fdselect = NULL; - font->fd_dict = NULL; - font->fd_private_dict = NULL; - font->fd_local_sub_index = NULL; - font->fd_local_sub_bias = NULL; - font->fdselect_subset = NULL; - font->fd_subset_map = NULL; - font->private_dict_offset = NULL; - font->global_subs_used = NULL; - font->local_subs_used = NULL; - font->fd_local_subs_used = NULL; - - *font_return = font; - - return CAIRO_STATUS_SUCCESS; - -fail5: - _cairo_hash_table_destroy (font->top_dict); -fail4: - free (font->widths); -fail3: - free (font->subset_font_name); -fail2: - free (font->ps_name); - _cairo_array_fini (&font->output); -fail1: - free (font->data); - free (font->font_name); - free (font); - - return status; -} - -static void -cairo_cff_font_destroy (cairo_cff_font_t *font) -{ - unsigned int i; - - free (font->widths); - free (font->font_name); - free (font->ps_name); - free (font->subset_font_name); - _cairo_array_fini (&font->output); - cff_dict_fini (font->top_dict); - cff_dict_fini (font->private_dict); - cff_index_fini (&font->strings_index); - cff_index_fini (&font->charstrings_index); - cff_index_fini (&font->global_sub_index); - cff_index_fini (&font->local_sub_index); - cff_index_fini (&font->charstrings_subset_index); - cff_index_fini (&font->strings_subset_index); - - /* If we bailed out early as a result of an error some of the - * following cairo_cff_font_t members may still be NULL */ - if (font->fd_dict) { - for (i = 0; i < font->num_fontdicts; i++) { - if (font->fd_dict[i]) - cff_dict_fini (font->fd_dict[i]); - } - free (font->fd_dict); - } - free (font->global_subs_used); - free (font->local_subs_used); - free (font->fd_subset_map); - free (font->private_dict_offset); - - if (font->is_cid) { - free (font->fdselect); - free (font->fdselect_subset); - if (font->fd_private_dict) { - for (i = 0; i < font->num_fontdicts; i++) { - if (font->fd_private_dict[i]) - cff_dict_fini (font->fd_private_dict[i]); - } - free (font->fd_private_dict); - } - if (font->fd_local_sub_index) { - for (i = 0; i < font->num_fontdicts; i++) - cff_index_fini (&font->fd_local_sub_index[i]); - free (font->fd_local_sub_index); - } - free (font->fd_local_sub_bias); - if (font->fd_local_subs_used) { - for (i = 0; i < font->num_fontdicts; i++) { - free (font->fd_local_subs_used[i]); - } - free (font->fd_local_subs_used); - } - free (font->fd_default_width); - free (font->fd_nominal_width); - } - - free (font->data); - - free (font); -} - -cairo_status_t -_cairo_cff_subset_init (cairo_cff_subset_t *cff_subset, - const char *subset_name, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_cff_font_t *font = NULL; /* squelch bogus compiler warning */ - cairo_status_t status; - const char *data = NULL; /* squelch bogus compiler warning */ - unsigned long length = 0; /* squelch bogus compiler warning */ - unsigned int i; - - status = _cairo_cff_font_create (font_subset, &font, subset_name); - if (unlikely (status)) - return status; - - status = cairo_cff_font_generate (font, &data, &length); - if (unlikely (status)) - goto fail1; - - cff_subset->ps_name = strdup (font->ps_name); - if (unlikely (cff_subset->ps_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - if (font->font_name) { - cff_subset->family_name_utf8 = strdup (font->font_name); - if (cff_subset->family_name_utf8 == NULL) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - } else { - cff_subset->family_name_utf8 = NULL; - } - - cff_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); - if (unlikely (cff_subset->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) - cff_subset->widths[i] = (double)font->widths[i]/font->units_per_em; - - cff_subset->x_min = (double)font->x_min/font->units_per_em; - cff_subset->y_min = (double)font->y_min/font->units_per_em; - cff_subset->x_max = (double)font->x_max/font->units_per_em; - cff_subset->y_max = (double)font->y_max/font->units_per_em; - cff_subset->ascent = (double)font->ascent/font->units_per_em; - cff_subset->descent = (double)font->descent/font->units_per_em; - - cff_subset->data = malloc (length); - if (unlikely (cff_subset->data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail4; - } - - memcpy (cff_subset->data, data, length); - cff_subset->data_length = length; - - cairo_cff_font_destroy (font); - - return CAIRO_STATUS_SUCCESS; - - fail4: - free (cff_subset->widths); - fail3: - free (cff_subset->family_name_utf8); - fail2: - free (cff_subset->ps_name); - fail1: - cairo_cff_font_destroy (font); - - return status; -} - -void -_cairo_cff_subset_fini (cairo_cff_subset_t *subset) -{ - free (subset->ps_name); - free (subset->family_name_utf8); - free (subset->widths); - free (subset->data); -} - -cairo_bool_t -_cairo_cff_scaled_font_is_cid_cff (cairo_scaled_font_t *scaled_font) -{ - const cairo_scaled_font_backend_t *backend; - cairo_int_status_t status; - unsigned char *data; - unsigned long data_length; - unsigned char *current_ptr; - unsigned char *data_end; - cff_header_t *header; - cff_index_element_t *element; - cairo_hash_table_t *top_dict; - cairo_array_t index; - int size; - cairo_bool_t is_cid = FALSE; - - backend = scaled_font->backend; - data = NULL; - data_length = 0; - status = CAIRO_INT_STATUS_UNSUPPORTED; - /* Try to load an OpenType/CFF font */ - if (backend->load_truetype_table && - (status = backend->load_truetype_table (scaled_font, TT_TAG_CFF, - 0, NULL, &data_length)) == CAIRO_INT_STATUS_SUCCESS) - { - data = malloc (data_length); - if (unlikely (data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - status = backend->load_truetype_table (scaled_font, TT_TAG_CFF, - 0, data, &data_length); - if (unlikely (status)) - goto fail1; - } - /* Try to load a CFF font */ - if (status == CAIRO_INT_STATUS_UNSUPPORTED && - backend->load_type1_data && - (status = backend->load_type1_data (scaled_font, - 0, NULL, &data_length)) == CAIRO_INT_STATUS_SUCCESS) - { - data = malloc (data_length); - if (unlikely (data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - status = backend->load_type1_data (scaled_font, 0, data, &data_length); - if (unlikely (status)) - goto fail1; - } - if (status) - goto fail1; - - /* Check if it looks like a CFF font */ - if (!check_fontdata_is_cff (data, data_length)) - goto fail1; - - data_end = data + data_length; - - /* skip header */ - if (data_length < sizeof (cff_header_t)) - goto fail1; - - header = (cff_header_t *) data; - current_ptr = data + header->header_size; - - /* skip name */ - cff_index_init (&index); - status = cff_index_read (&index, ¤t_ptr, data_end); - cff_index_fini (&index); - - if (status) - goto fail1; - - /* read top dict */ - cff_index_init (&index); - status = cff_index_read (&index, ¤t_ptr, data_end); - if (unlikely (status)) - goto fail2; - - status = cff_dict_init (&top_dict); - if (unlikely (status)) - goto fail2; - - element = _cairo_array_index (&index, 0); - status = cff_dict_read (top_dict, element->data, element->length); - if (unlikely (status)) - goto fail3; - - /* check for ROS operator indicating a CID font */ - if (cff_dict_get_operands (top_dict, ROS_OP, &size) != NULL) - is_cid = TRUE; - -fail3: - cff_dict_fini (top_dict); - -fail2: - cff_index_fini (&index); - -fail1: - free (data); - - return is_cid; -} - -static cairo_int_status_t -_cairo_cff_font_fallback_create (cairo_scaled_font_subset_t *scaled_font_subset, - cairo_cff_font_t **font_return, - const char *subset_name) -{ - cairo_status_t status; - cairo_cff_font_t *font; - - font = malloc (sizeof (cairo_cff_font_t)); - if (unlikely (font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->backend = NULL; - font->scaled_font_subset = scaled_font_subset; - - _cairo_array_init (&font->output, sizeof (char)); - status = _cairo_array_grow_by (&font->output, 4096); - if (unlikely (status)) - goto fail1; - - font->subset_font_name = strdup (subset_name); - if (unlikely (font->subset_font_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - font->ps_name = strdup (subset_name); - if (unlikely (font->ps_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - font->font_name = NULL; - - font->x_min = 0; - font->y_min = 0; - font->x_max = 0; - font->y_max = 0; - font->ascent = 0; - font->descent = 0; - - font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int)); - if (unlikely (font->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - - font->data_length = 0; - font->data = NULL; - font->data_end = NULL; - - status = cff_dict_init (&font->top_dict); - if (unlikely (status)) - goto fail4; - - status = cff_dict_init (&font->private_dict); - if (unlikely (status)) - goto fail5; - - cff_index_init (&font->strings_index); - cff_index_init (&font->charstrings_index); - cff_index_init (&font->global_sub_index); - cff_index_init (&font->local_sub_index); - cff_index_init (&font->charstrings_subset_index); - cff_index_init (&font->strings_subset_index); - font->global_subs_used = NULL; - font->local_subs_used = NULL; - font->subset_subroutines = FALSE; - font->fdselect = NULL; - font->fd_dict = NULL; - font->fd_private_dict = NULL; - font->fd_local_sub_index = NULL; - font->fdselect_subset = NULL; - font->fd_subset_map = NULL; - font->private_dict_offset = NULL; - - *font_return = font; - - return CAIRO_STATUS_SUCCESS; - -fail5: - _cairo_hash_table_destroy (font->top_dict); -fail4: - free (font->widths); -fail3: - free (font->font_name); - free (font->ps_name); -fail2: - free (font->subset_font_name); -fail1: - _cairo_array_fini (&font->output); - free (font); - return status; -} - -static cairo_int_status_t -cairo_cff_font_fallback_generate (cairo_cff_font_t *font, - cairo_type2_charstrings_t *type2_subset, - const char **data, - unsigned long *length) -{ - cairo_int_status_t status; - cff_header_t header; - cairo_array_t *charstring; - unsigned char buf[40]; - unsigned char *end_buf, *end_buf2; - unsigned int i; - int sid; - - /* Create header */ - header.major = 1; - header.minor = 0; - header.header_size = 4; - header.offset_size = 4; - font->header = &header; - - /* Create Top Dict */ - font->is_cid = FALSE; - - snprintf((char*)buf, sizeof(buf), "CairoFont-%u-%u", - font->scaled_font_subset->font_id, - font->scaled_font_subset->subset_id); - sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); - status = cff_index_append_copy (&font->strings_subset_index, - (unsigned char *)buf, - strlen((char*)buf)); - if (unlikely (status)) - return status; - - end_buf = encode_integer (buf, sid); - status = cff_dict_set_operands (font->top_dict, FULLNAME_OP, - buf, end_buf - buf); - if (unlikely (status)) - return status; - - status = cff_dict_set_operands (font->top_dict, FAMILYNAME_OP, - buf, end_buf - buf); - if (unlikely (status)) - return status; - - end_buf = encode_integer (buf, type2_subset->x_min); - end_buf = encode_integer (end_buf, type2_subset->y_min); - end_buf = encode_integer (end_buf, type2_subset->x_max); - end_buf = encode_integer (end_buf, type2_subset->y_max); - status = cff_dict_set_operands (font->top_dict, - FONTBBOX_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - - end_buf = encode_integer_max (buf, 0); - status = cff_dict_set_operands (font->top_dict, - CHARSTRINGS_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - - - if (font->scaled_font_subset->is_latin) { - status = cff_dict_set_operands (font->top_dict, - ENCODING_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - - /* Private has two operands - size and offset */ - end_buf2 = encode_integer_max (end_buf, 0); - cff_dict_set_operands (font->top_dict, PRIVATE_OP, buf, end_buf2 - buf); - if (unlikely (status)) - return status; - - } else { - status = cff_dict_set_operands (font->top_dict, - FDSELECT_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - - status = cff_dict_set_operands (font->top_dict, - FDARRAY_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - } - - status = cff_dict_set_operands (font->top_dict, - CHARSET_OP, buf, end_buf - buf); - if (unlikely (status)) - return status; - - if (!font->scaled_font_subset->is_latin) { - status = cairo_cff_font_set_ros_strings (font); - if (unlikely (status)) - return status; - - /* Create CID FD dictionary */ - status = cairo_cff_font_create_cid_fontdict (font); - if (unlikely (status)) - return status; - } else { - font->private_dict_offset = malloc (sizeof (int)); - if (unlikely (font->private_dict_offset == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* Create charstrings */ - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - charstring = _cairo_array_index(&type2_subset->charstrings, i); - - status = cff_index_append (&font->charstrings_subset_index, - _cairo_array_index (charstring, 0), - _cairo_array_num_elements (charstring)); - - if (unlikely (status)) - return status; - } - - if (font->scaled_font_subset->is_latin) - status = cairo_cff_font_add_euro_charset_string (font); - - status = cairo_cff_font_write_subset (font); - if (unlikely (status)) - return status; - - *data = _cairo_array_index (&font->output, 0); - *length = _cairo_array_num_elements (&font->output); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_cff_fallback_init (cairo_cff_subset_t *cff_subset, - const char *subset_name, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_cff_font_t *font = NULL; /* squelch bogus compiler warning */ - cairo_status_t status; - const char *data = NULL; /* squelch bogus compiler warning */ - unsigned long length = 0; /* squelch bogus compiler warning */ - unsigned int i; - cairo_type2_charstrings_t type2_subset; - - status = _cairo_cff_font_fallback_create (font_subset, &font, subset_name); - if (unlikely (status)) - return status; - - status = _cairo_type2_charstrings_init (&type2_subset, font_subset); - if (unlikely (status)) - goto fail1; - - status = cairo_cff_font_fallback_generate (font, &type2_subset, &data, &length); - if (unlikely (status)) - goto fail2; - - cff_subset->family_name_utf8 = NULL; - cff_subset->ps_name = strdup (font->ps_name); - if (unlikely (cff_subset->ps_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - - cff_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); - if (unlikely (cff_subset->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) - cff_subset->widths[i] = (double)type2_subset.widths[i]/1000; - - cff_subset->x_min = (double)type2_subset.x_min/1000; - cff_subset->y_min = (double)type2_subset.y_min/1000; - cff_subset->x_max = (double)type2_subset.x_max/1000; - cff_subset->y_max = (double)type2_subset.y_max/1000; - cff_subset->ascent = (double)type2_subset.y_max/1000; - cff_subset->descent = (double)type2_subset.y_min/1000; - - cff_subset->data = malloc (length); - if (unlikely (cff_subset->data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail4; - } - - memcpy (cff_subset->data, data, length); - cff_subset->data_length = length; - - _cairo_type2_charstrings_fini (&type2_subset); - cairo_cff_font_destroy (font); - - return CAIRO_STATUS_SUCCESS; - - fail4: - free (cff_subset->widths); - fail3: - free (cff_subset->ps_name); - fail2: - _cairo_type2_charstrings_fini (&type2_subset); - fail1: - cairo_cff_font_destroy (font); - - return status; -} - -void -_cairo_cff_fallback_fini (cairo_cff_subset_t *subset) -{ - free (subset->ps_name); - free (subset->widths); - free (subset->data); -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-boxes.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-boxes.c deleted file mode 100644 index 7bcbeb1918a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-boxes.c +++ /dev/null @@ -1,599 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-gstate-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-pattern-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-region-private.h" - -static inline int -pot (int v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} - -static cairo_bool_t -_cairo_clip_contains_rectangle_box (const cairo_clip_t *clip, - const cairo_rectangle_int_t *rect, - const cairo_box_t *box) -{ - int i; - - /* clip == NULL means no clip, so the clip contains everything */ - if (clip == NULL) - return TRUE; - - if (_cairo_clip_is_all_clipped (clip)) - return FALSE; - - /* If we have a non-trivial path, just say no */ - if (clip->path) - return FALSE; - - if (! _cairo_rectangle_contains_rectangle (&clip->extents, rect)) - return FALSE; - - if (clip->num_boxes == 0) - return TRUE; - - /* Check for a clip-box that wholly contains the rectangle */ - for (i = 0; i < clip->num_boxes; i++) { - if (box->p1.x >= clip->boxes[i].p1.x && - box->p1.y >= clip->boxes[i].p1.y && - box->p2.x <= clip->boxes[i].p2.x && - box->p2.y <= clip->boxes[i].p2.y) - { - return TRUE; - } - } - - return FALSE; -} - -cairo_bool_t -_cairo_clip_contains_box (const cairo_clip_t *clip, - const cairo_box_t *box) -{ - cairo_rectangle_int_t rect; - - _cairo_box_round_to_rectangle (box, &rect); - return _cairo_clip_contains_rectangle_box(clip, &rect, box); -} - -cairo_bool_t -_cairo_clip_contains_rectangle (const cairo_clip_t *clip, - const cairo_rectangle_int_t *rect) -{ - cairo_box_t box; - - box.p1.x = _cairo_fixed_from_int (rect->x); - box.p1.y = _cairo_fixed_from_int (rect->y); - box.p2.x = _cairo_fixed_from_int (rect->x + rect->width); - box.p2.y = _cairo_fixed_from_int (rect->y + rect->height); - - return _cairo_clip_contains_rectangle_box (clip, rect, &box); -} - -cairo_clip_t * -_cairo_clip_intersect_rectilinear_path (cairo_clip_t *clip, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias) -{ - cairo_status_t status; - cairo_boxes_t boxes; - - _cairo_boxes_init (&boxes); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - fill_rule, - antialias, - &boxes); - if (likely (status == CAIRO_STATUS_SUCCESS && boxes.num_boxes)) - clip = _cairo_clip_intersect_boxes (clip, &boxes); - else - clip = _cairo_clip_set_all_clipped (clip); - _cairo_boxes_fini (&boxes); - - return clip; -} - -static cairo_clip_t * -_cairo_clip_intersect_rectangle_box (cairo_clip_t *clip, - const cairo_rectangle_int_t *r, - const cairo_box_t *box) -{ - cairo_box_t extents_box; - cairo_bool_t changed = FALSE; - int i, j; - - if (clip == NULL) { - clip = _cairo_clip_create (); - if (clip == NULL) - return _cairo_clip_set_all_clipped (clip); - } - - if (clip->num_boxes == 0) { - clip->boxes = &clip->embedded_box; - clip->boxes[0] = *box; - clip->num_boxes = 1; - if (clip->path == NULL) { - clip->extents = *r; - } else { - if (! _cairo_rectangle_intersect (&clip->extents, r)) - return _cairo_clip_set_all_clipped (clip); - } - if (clip->path == NULL) - clip->is_region = _cairo_box_is_pixel_aligned (box); - return clip; - } - - /* Does the new box wholly subsume the clip? Perform a cheap check - * for the common condition of a single clip rectangle. - */ - if (clip->num_boxes == 1 && - clip->boxes[0].p1.x >= box->p1.x && - clip->boxes[0].p1.y >= box->p1.y && - clip->boxes[0].p2.x <= box->p2.x && - clip->boxes[0].p2.y <= box->p2.y) - { - return clip; - } - - for (i = j = 0; i < clip->num_boxes; i++) { - cairo_box_t *b = &clip->boxes[j]; - - if (j != i) - *b = clip->boxes[i]; - - if (box->p1.x > b->p1.x) - b->p1.x = box->p1.x, changed = TRUE; - if (box->p2.x < b->p2.x) - b->p2.x = box->p2.x, changed = TRUE; - - if (box->p1.y > b->p1.y) - b->p1.y = box->p1.y, changed = TRUE; - if (box->p2.y < b->p2.y) - b->p2.y = box->p2.y, changed = TRUE; - - j += b->p2.x > b->p1.x && b->p2.y > b->p1.y; - } - clip->num_boxes = j; - - if (clip->num_boxes == 0) - return _cairo_clip_set_all_clipped (clip); - - if (! changed) - return clip; - - extents_box = clip->boxes[0]; - for (i = 1; i < clip->num_boxes; i++) { - if (clip->boxes[i].p1.x < extents_box.p1.x) - extents_box.p1.x = clip->boxes[i].p1.x; - - if (clip->boxes[i].p1.y < extents_box.p1.y) - extents_box.p1.y = clip->boxes[i].p1.y; - - if (clip->boxes[i].p2.x > extents_box.p2.x) - extents_box.p2.x = clip->boxes[i].p2.x; - - if (clip->boxes[i].p2.y > extents_box.p2.y) - extents_box.p2.y = clip->boxes[i].p2.y; - } - - if (clip->path == NULL) { - _cairo_box_round_to_rectangle (&extents_box, &clip->extents); - } else { - cairo_rectangle_int_t extents_rect; - - _cairo_box_round_to_rectangle (&extents_box, &extents_rect); - if (! _cairo_rectangle_intersect (&clip->extents, &extents_rect)) - return _cairo_clip_set_all_clipped (clip); - } - - if (clip->region) { - cairo_region_destroy (clip->region); - clip->region = NULL; - } - - clip->is_region = FALSE; - return clip; -} - -cairo_clip_t * -_cairo_clip_intersect_box (cairo_clip_t *clip, - const cairo_box_t *box) -{ - cairo_rectangle_int_t r; - - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - _cairo_box_round_to_rectangle (box, &r); - if (r.width == 0 || r.height == 0) - return _cairo_clip_set_all_clipped (clip); - - return _cairo_clip_intersect_rectangle_box (clip, &r, box); -} - -cairo_clip_t * -_cairo_clip_intersect_boxes (cairo_clip_t *clip, - const cairo_boxes_t *boxes) -{ - cairo_boxes_t clip_boxes; - cairo_box_t limits; - cairo_rectangle_int_t extents; - - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - if (boxes->num_boxes == 0) - return _cairo_clip_set_all_clipped (clip); - - if (boxes->num_boxes == 1) - return _cairo_clip_intersect_box (clip, boxes->chunks.base); - - if (clip == NULL) - clip = _cairo_clip_create (); - - if (clip->num_boxes) { - _cairo_boxes_init_for_array (&clip_boxes, clip->boxes, clip->num_boxes); - if (unlikely (_cairo_boxes_intersect (&clip_boxes, boxes, &clip_boxes))) { - clip = _cairo_clip_set_all_clipped (clip); - goto out; - } - - if (clip->boxes != &clip->embedded_box) - free (clip->boxes); - - clip->boxes = NULL; - boxes = &clip_boxes; - } - - if (boxes->num_boxes == 0) { - clip = _cairo_clip_set_all_clipped (clip); - goto out; - } else if (boxes->num_boxes == 1) { - clip->boxes = &clip->embedded_box; - clip->boxes[0] = boxes->chunks.base[0]; - clip->num_boxes = 1; - } else { - clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes, TRUE); - } - _cairo_boxes_extents (boxes, &limits); - - _cairo_box_round_to_rectangle (&limits, &extents); - if (clip->path == NULL) { - clip->extents = extents; - } else if (! _cairo_rectangle_intersect (&clip->extents, &extents)) { - clip = _cairo_clip_set_all_clipped (clip); - goto out; - } - - if (clip->region) { - cairo_region_destroy (clip->region); - clip->region = NULL; - } - clip->is_region = FALSE; - -out: - if (boxes == &clip_boxes) - _cairo_boxes_fini (&clip_boxes); - - return clip; -} - -cairo_clip_t * -_cairo_clip_intersect_rectangle (cairo_clip_t *clip, - const cairo_rectangle_int_t *r) -{ - cairo_box_t box; - - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - if (r->width == 0 || r->height == 0) - return _cairo_clip_set_all_clipped (clip); - - box.p1.x = _cairo_fixed_from_int (r->x); - box.p1.y = _cairo_fixed_from_int (r->y); - box.p2.x = _cairo_fixed_from_int (r->x + r->width); - box.p2.y = _cairo_fixed_from_int (r->y + r->height); - - return _cairo_clip_intersect_rectangle_box (clip, r, &box); -} - -struct reduce { - cairo_clip_t *clip; - cairo_box_t limit; - cairo_box_t extents; - cairo_bool_t inside; - - cairo_point_t current_point; - cairo_point_t last_move_to; -}; - -static void -_add_clipped_edge (struct reduce *r, - const cairo_point_t *p1, - const cairo_point_t *p2, - int y1, int y2) -{ - cairo_fixed_t x; - - x = _cairo_edge_compute_intersection_x_for_y (p1, p2, y1); - if (x < r->extents.p1.x) - r->extents.p1.x = x; - - x = _cairo_edge_compute_intersection_x_for_y (p1, p2, y2); - if (x > r->extents.p2.x) - r->extents.p2.x = x; - - if (y1 < r->extents.p1.y) - r->extents.p1.y = y1; - - if (y2 > r->extents.p2.y) - r->extents.p2.y = y2; - - r->inside = TRUE; -} - -static void -_add_edge (struct reduce *r, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - int top, bottom; - int top_y, bot_y; - int n; - - if (p1->y < p2->y) { - top = p1->y; - bottom = p2->y; - } else { - top = p2->y; - bottom = p1->y; - } - - if (bottom < r->limit.p1.y || top > r->limit.p2.y) - return; - - if (p1->x > p2->x) { - const cairo_point_t *t = p1; - p1 = p2; - p2 = t; - } - - if (p2->x <= r->limit.p1.x || p1->x >= r->limit.p2.x) - return; - - for (n = 0; n < r->clip->num_boxes; n++) { - const cairo_box_t *limits = &r->clip->boxes[n]; - - if (bottom < limits->p1.y || top > limits->p2.y) - continue; - - if (p2->x <= limits->p1.x || p1->x >= limits->p2.x) - continue; - - if (p1->x >= limits->p1.x && p2->x <= limits->p1.x) { - top_y = top; - bot_y = bottom; - } else { - int p1_y, p2_y; - - p1_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, - limits->p1.x); - p2_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, - limits->p2.x); - if (p1_y < p2_y) { - top_y = p1_y; - bot_y = p2_y; - } else { - top_y = p2_y; - bot_y = p1_y; - } - - if (top_y < top) - top_y = top; - if (bot_y > bottom) - bot_y = bottom; - } - - if (top_y < limits->p1.y) - top_y = limits->p1.y; - - if (bot_y > limits->p2.y) - bot_y = limits->p2.y; - if (bot_y > top_y) - _add_clipped_edge (r, p1, p2, top_y, bot_y); - } -} - -static cairo_status_t -_reduce_line_to (void *closure, - const cairo_point_t *point) -{ - struct reduce *r = closure; - - _add_edge (r, &r->current_point, point); - r->current_point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_reduce_close (void *closure) -{ - struct reduce *r = closure; - - return _reduce_line_to (r, &r->last_move_to); -} - -static cairo_status_t -_reduce_move_to (void *closure, - const cairo_point_t *point) -{ - struct reduce *r = closure; - cairo_status_t status; - - /* close current subpath */ - status = _reduce_close (closure); - - /* make sure that the closure represents a degenerate path */ - r->current_point = *point; - r->last_move_to = *point; - - return status; -} - -static cairo_clip_t * -_cairo_clip_reduce_to_boxes (cairo_clip_t *clip) -{ - struct reduce r; - cairo_clip_path_t *clip_path; - cairo_status_t status; - - return clip; - if (clip->path == NULL) - return clip; - - r.clip = clip; - r.extents.p1.x = r.extents.p1.y = INT_MAX; - r.extents.p2.x = r.extents.p2.y = INT_MIN; - r.inside = FALSE; - - r.limit.p1.x = _cairo_fixed_from_int (clip->extents.x); - r.limit.p1.y = _cairo_fixed_from_int (clip->extents.y); - r.limit.p2.x = _cairo_fixed_from_int (clip->extents.x + clip->extents.width); - r.limit.p2.y = _cairo_fixed_from_int (clip->extents.y + clip->extents.height); - - clip_path = clip->path; - do { - r.current_point.x = 0; - r.current_point.y = 0; - r.last_move_to = r.current_point; - - status = _cairo_path_fixed_interpret_flat (&clip_path->path, - _reduce_move_to, - _reduce_line_to, - _reduce_close, - &r, - clip_path->tolerance); - assert (status == CAIRO_STATUS_SUCCESS); - _reduce_close (&r); - } while ((clip_path = clip_path->prev)); - - if (! r.inside) { - _cairo_clip_path_destroy (clip->path); - clip->path = NULL; - } - - return _cairo_clip_intersect_box (clip, &r.extents); -} - -cairo_clip_t * -_cairo_clip_reduce_to_rectangle (const cairo_clip_t *clip, - const cairo_rectangle_int_t *r) -{ - cairo_clip_t *copy; - - if (_cairo_clip_is_all_clipped (clip)) - return (cairo_clip_t *) clip; - - if (_cairo_clip_contains_rectangle (clip, r)) - return _cairo_clip_intersect_rectangle (NULL, r); - - copy = _cairo_clip_copy_intersect_rectangle (clip, r); - if (_cairo_clip_is_all_clipped (copy)) - return copy; - - return _cairo_clip_reduce_to_boxes (copy); -} - -cairo_clip_t * -_cairo_clip_reduce_for_composite (const cairo_clip_t *clip, - cairo_composite_rectangles_t *extents) -{ - const cairo_rectangle_int_t *r; - - r = extents->is_bounded ? &extents->bounded : &extents->unbounded; - return _cairo_clip_reduce_to_rectangle (clip, r); -} - -cairo_clip_t * -_cairo_clip_from_boxes (const cairo_boxes_t *boxes) -{ - cairo_box_t extents; - cairo_clip_t *clip = _cairo_clip_create (); - if (clip == NULL) - return _cairo_clip_set_all_clipped (clip); - - /* XXX cow-boxes? */ - if(boxes->num_boxes == 1) { - clip->boxes = &clip->embedded_box; - clip->boxes[0] = boxes->chunks.base[0]; - clip->num_boxes = 1; - } else { - clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes, TRUE); - if (clip->boxes == NULL) - return _cairo_clip_set_all_clipped (clip); - } - - _cairo_boxes_extents (boxes, &extents); - _cairo_box_round_to_rectangle (&extents, &clip->extents); - - return clip; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-inline.h deleted file mode 100644 index a9f23269223..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-inline.h +++ /dev/null @@ -1,83 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Chris Wilson - */ - -#ifndef CAIRO_CLIP_INLINE_H -#define CAIRO_CLIP_INLINE_H - -#include "cairo-clip-private.h" - -static inline cairo_bool_t _cairo_clip_is_all_clipped(const cairo_clip_t *clip) -{ - return clip == &__cairo_clip_all; -} - -static inline cairo_clip_t * -_cairo_clip_set_all_clipped (cairo_clip_t *clip) -{ - _cairo_clip_destroy (clip); - return (cairo_clip_t *) &__cairo_clip_all; -} - -static inline cairo_clip_t * -_cairo_clip_copy_intersect_rectangle (const cairo_clip_t *clip, - const cairo_rectangle_int_t *r) -{ - return _cairo_clip_intersect_rectangle (_cairo_clip_copy (clip), r); -} - -static inline cairo_clip_t * -_cairo_clip_copy_intersect_clip (const cairo_clip_t *clip, - const cairo_clip_t *other) -{ - return _cairo_clip_intersect_clip (_cairo_clip_copy (clip), other); -} - -static inline void -_cairo_clip_steal_boxes (cairo_clip_t *clip, cairo_boxes_t *boxes) -{ - _cairo_boxes_init_for_array (boxes, clip->boxes, clip->num_boxes); - clip->boxes = NULL; - clip->num_boxes = 0; -} - -static inline void -_cairo_clip_unsteal_boxes (cairo_clip_t *clip, cairo_boxes_t *boxes) -{ - clip->boxes = boxes->chunks.base; - clip->num_boxes = boxes->num_boxes; -} - -#endif /* CAIRO_CLIP_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-polygon.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-polygon.c deleted file mode 100644 index f40faefba80..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-polygon.c +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-gstate-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-pattern-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-region-private.h" - -static cairo_bool_t -can_convert_to_polygon (const cairo_clip_t *clip) -{ - cairo_clip_path_t *clip_path = clip->path; - cairo_antialias_t antialias = clip_path->antialias; - - while ((clip_path = clip_path->prev) != NULL) { - if (clip_path->antialias != antialias) - return FALSE; - } - - return TRUE; -} - -cairo_int_status_t -_cairo_clip_get_polygon (const cairo_clip_t *clip, - cairo_polygon_t *polygon, - cairo_fill_rule_t *fill_rule, - cairo_antialias_t *antialias) -{ - cairo_status_t status; - cairo_clip_path_t *clip_path; - - if (_cairo_clip_is_all_clipped (clip)) { - _cairo_polygon_init (polygon, NULL, 0); - return CAIRO_INT_STATUS_SUCCESS; - } - - /* If there is no clip, we need an infinite polygon */ - assert (clip && (clip->path || clip->num_boxes)); - - if (clip->path == NULL) { - *fill_rule = CAIRO_FILL_RULE_WINDING; - *antialias = CAIRO_ANTIALIAS_DEFAULT; - return _cairo_polygon_init_box_array (polygon, - clip->boxes, - clip->num_boxes); - } - - /* check that residual is all of the same type/tolerance */ - if (! can_convert_to_polygon (clip)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (clip->num_boxes < 2) - _cairo_polygon_init_with_clip (polygon, clip); - else - _cairo_polygon_init_with_clip (polygon, NULL); - - clip_path = clip->path; - *fill_rule = clip_path->fill_rule; - *antialias = clip_path->antialias; - - status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, - clip_path->tolerance, - polygon); - if (unlikely (status)) - goto err; - - if (clip->num_boxes > 1) { - status = _cairo_polygon_intersect_with_boxes (polygon, fill_rule, - clip->boxes, clip->num_boxes); - if (unlikely (status)) - goto err; - } - - polygon->limits = NULL; - polygon->num_limits = 0; - - while ((clip_path = clip_path->prev) != NULL) { - cairo_polygon_t next; - - _cairo_polygon_init (&next, NULL, 0); - status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, - clip_path->tolerance, - &next); - if (likely (status == CAIRO_STATUS_SUCCESS)) - status = _cairo_polygon_intersect (polygon, *fill_rule, - &next, clip_path->fill_rule); - _cairo_polygon_fini (&next); - if (unlikely (status)) - goto err; - - *fill_rule = CAIRO_FILL_RULE_WINDING; - } - - return CAIRO_STATUS_SUCCESS; - -err: - _cairo_polygon_fini (polygon); - return status; -} - -cairo_bool_t -_cairo_clip_is_polygon (const cairo_clip_t *clip) -{ - if (_cairo_clip_is_all_clipped (clip)) - return TRUE; - - /* If there is no clip, we need an infinite polygon */ - if (clip == NULL) - return FALSE; - - if (clip->path == NULL) - return TRUE; - - /* check that residual is all of the same type/tolerance */ - return can_convert_to_polygon (clip); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-private.h deleted file mode 100644 index 5fc05a64e93..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-private.h +++ /dev/null @@ -1,198 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Chris Wilson - */ - -#ifndef CAIRO_CLIP_PRIVATE_H -#define CAIRO_CLIP_PRIVATE_H - -#include "cairo-types-private.h" - -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-reference-count-private.h" - -extern const cairo_private cairo_rectangle_list_t _cairo_rectangles_nil; - -struct _cairo_clip_path { - cairo_reference_count_t ref_count; - cairo_path_fixed_t path; - cairo_fill_rule_t fill_rule; - double tolerance; - cairo_antialias_t antialias; - cairo_clip_path_t *prev; -}; - -struct _cairo_clip { - cairo_rectangle_int_t extents; - cairo_clip_path_t *path; - - cairo_box_t *boxes; - int num_boxes; - - cairo_region_t *region; - cairo_bool_t is_region; - - cairo_box_t embedded_box; -}; - -cairo_private cairo_clip_t * -_cairo_clip_create (void); - -cairo_private cairo_clip_path_t * -_cairo_clip_path_reference (cairo_clip_path_t *clip_path); - -cairo_private void -_cairo_clip_path_destroy (cairo_clip_path_t *clip_path); - -cairo_private void -_cairo_clip_destroy (cairo_clip_t *clip); - -cairo_private extern const cairo_clip_t __cairo_clip_all; - -cairo_private cairo_clip_t * -_cairo_clip_copy (const cairo_clip_t *clip); - -cairo_private cairo_clip_t * -_cairo_clip_copy_region (const cairo_clip_t *clip); - -cairo_private cairo_clip_t * -_cairo_clip_copy_path (const cairo_clip_t *clip); - -cairo_private cairo_clip_t * -_cairo_clip_translate (cairo_clip_t *clip, int tx, int ty); - -cairo_private cairo_clip_t * -_cairo_clip_transform (cairo_clip_t *clip, const cairo_matrix_t *m); - -cairo_private cairo_clip_t * -_cairo_clip_copy_with_translation (const cairo_clip_t *clip, int tx, int ty); - -cairo_private cairo_bool_t -_cairo_clip_equal (const cairo_clip_t *clip_a, - const cairo_clip_t *clip_b); - -cairo_private cairo_clip_t * -_cairo_clip_intersect_rectangle (cairo_clip_t *clip, - const cairo_rectangle_int_t *rectangle); - -cairo_private cairo_clip_t * -_cairo_clip_intersect_clip (cairo_clip_t *clip, - const cairo_clip_t *other); - -cairo_private cairo_clip_t * -_cairo_clip_intersect_box (cairo_clip_t *clip, - const cairo_box_t *box); - -cairo_private cairo_clip_t * -_cairo_clip_intersect_boxes (cairo_clip_t *clip, - const cairo_boxes_t *boxes); - -cairo_private cairo_clip_t * -_cairo_clip_intersect_rectilinear_path (cairo_clip_t *clip, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias); - -cairo_private cairo_clip_t * -_cairo_clip_intersect_path (cairo_clip_t *clip, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias); - -cairo_private const cairo_rectangle_int_t * -_cairo_clip_get_extents (const cairo_clip_t *clip); - -cairo_private cairo_surface_t * -_cairo_clip_get_surface (const cairo_clip_t *clip, cairo_surface_t *dst, int *tx, int *ty); - -cairo_private cairo_surface_t * -_cairo_clip_get_image (const cairo_clip_t *clip, - cairo_surface_t *target, - const cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_clip_combine_with_surface (const cairo_clip_t *clip, - cairo_surface_t *dst, - int dst_x, int dst_y); - -cairo_private cairo_clip_t * -_cairo_clip_from_boxes (const cairo_boxes_t *boxes); - -cairo_private cairo_region_t * -_cairo_clip_get_region (const cairo_clip_t *clip); - -cairo_private cairo_bool_t -_cairo_clip_is_region (const cairo_clip_t *clip); - -cairo_private cairo_clip_t * -_cairo_clip_reduce_to_rectangle (const cairo_clip_t *clip, - const cairo_rectangle_int_t *r); - -cairo_private cairo_clip_t * -_cairo_clip_reduce_for_composite (const cairo_clip_t *clip, - cairo_composite_rectangles_t *extents); - -cairo_private cairo_bool_t -_cairo_clip_contains_rectangle (const cairo_clip_t *clip, - const cairo_rectangle_int_t *rect); - -cairo_private cairo_bool_t -_cairo_clip_contains_box (const cairo_clip_t *clip, - const cairo_box_t *box); - -cairo_private cairo_bool_t -_cairo_clip_contains_extents (const cairo_clip_t *clip, - const cairo_composite_rectangles_t *extents); - -cairo_private cairo_rectangle_list_t* -_cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate); - -cairo_private cairo_rectangle_list_t * -_cairo_rectangle_list_create_in_error (cairo_status_t status); - -cairo_private cairo_bool_t -_cairo_clip_is_polygon (const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_clip_get_polygon (const cairo_clip_t *clip, - cairo_polygon_t *polygon, - cairo_fill_rule_t *fill_rule, - cairo_antialias_t *antialias); - -#endif /* CAIRO_CLIP_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-region.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-region.c deleted file mode 100644 index e3f4891e3f2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-region.c +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-gstate-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-pattern-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-region-private.h" - -static void -_cairo_clip_extract_region (cairo_clip_t *clip) -{ - cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)]; - cairo_rectangle_int_t *r = stack_rects; - cairo_bool_t is_region; - int i; - - if (clip->num_boxes == 0) - return; - - if (clip->num_boxes > ARRAY_LENGTH (stack_rects)) { - r = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_rectangle_int_t)); - if (r == NULL){ - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return; - } - } - - is_region = clip->path == NULL; - for (i = 0; i < clip->num_boxes; i++) { - cairo_box_t *b = &clip->boxes[i]; - if (is_region) - is_region = - _cairo_fixed_is_integer (b->p1.x | b->p1.y | b->p2.x | b->p2.y); - r[i].x = _cairo_fixed_integer_floor (b->p1.x); - r[i].y = _cairo_fixed_integer_floor (b->p1.y); - r[i].width = _cairo_fixed_integer_ceil (b->p2.x) - r[i].x; - r[i].height = _cairo_fixed_integer_ceil (b->p2.y) - r[i].y; - } - clip->is_region = is_region; - - clip->region = cairo_region_create_rectangles (r, i); - - if (r != stack_rects) - free (r); -} - -cairo_region_t * -_cairo_clip_get_region (const cairo_clip_t *clip) -{ - if (clip == NULL) - return NULL; - - if (clip->region == NULL) - _cairo_clip_extract_region ((cairo_clip_t *) clip); - - return clip->region; -} - -cairo_bool_t -_cairo_clip_is_region (const cairo_clip_t *clip) -{ - if (clip == NULL) - return TRUE; - - if (clip->is_region) - return TRUE; - - /* XXX Geometric reduction? */ - - if (clip->path) - return FALSE; - - if (clip->num_boxes == 0) - return TRUE; - - if (clip->region == NULL) - _cairo_clip_extract_region ((cairo_clip_t *) clip); - - return clip->is_region; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-surface.c deleted file mode 100644 index 85feaa649eb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-surface.c +++ /dev/null @@ -1,240 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-gstate-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-pattern-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-region-private.h" - -cairo_status_t -_cairo_clip_combine_with_surface (const cairo_clip_t *clip, - cairo_surface_t *dst, - int dst_x, int dst_y) -{ - cairo_clip_path_t *copy_path; - cairo_clip_path_t *clip_path; - cairo_clip_t *copy; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - copy = _cairo_clip_copy_with_translation (clip, -dst_x, -dst_y); - copy_path = copy->path; - copy->path = NULL; - - if (copy->boxes) { - status = _cairo_surface_paint (dst, - CAIRO_OPERATOR_IN, - &_cairo_pattern_white.base, - copy); - } - - clip = NULL; - if (_cairo_clip_is_region (copy)) - clip = copy; - clip_path = copy_path; - while (status == CAIRO_STATUS_SUCCESS && clip_path) { - status = _cairo_surface_fill (dst, - CAIRO_OPERATOR_IN, - &_cairo_pattern_white.base, - &clip_path->path, - clip_path->fill_rule, - clip_path->tolerance, - clip_path->antialias, - clip); - clip_path = clip_path->prev; - } - - copy->path = copy_path; - _cairo_clip_destroy (copy); - return status; -} - -static cairo_status_t -_cairo_path_fixed_add_box (cairo_path_fixed_t *path, - const cairo_box_t *box, - cairo_fixed_t fx, - cairo_fixed_t fy) -{ - cairo_status_t status; - - status = _cairo_path_fixed_move_to (path, box->p1.x + fx, box->p1.y + fy); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p2.x + fx, box->p1.y + fy); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p2.x + fx, box->p2.y + fy); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p1.x + fx, box->p2.y + fy); - if (unlikely (status)) - return status; - - return _cairo_path_fixed_close_path (path); -} - -cairo_surface_t * -_cairo_clip_get_surface (const cairo_clip_t *clip, - cairo_surface_t *target, - int *tx, int *ty) -{ - cairo_surface_t *surface; - cairo_status_t status; - cairo_clip_t *copy, *region; - cairo_clip_path_t *copy_path, *clip_path; - - if (clip->num_boxes) { - cairo_path_fixed_t path; - int i; - - surface = _cairo_surface_create_scratch (target, - CAIRO_CONTENT_ALPHA, - clip->extents.width, - clip->extents.height, - CAIRO_COLOR_TRANSPARENT); - if (unlikely (surface->status)) - return surface; - - _cairo_path_fixed_init (&path); - status = CAIRO_STATUS_SUCCESS; - for (i = 0; status == CAIRO_STATUS_SUCCESS && i < clip->num_boxes; i++) { - status = _cairo_path_fixed_add_box (&path, &clip->boxes[i], - -_cairo_fixed_from_int (clip->extents.x), - -_cairo_fixed_from_int (clip->extents.y)); - } - if (status == CAIRO_STATUS_SUCCESS) - status = _cairo_surface_fill (surface, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - &path, - CAIRO_FILL_RULE_WINDING, - 1., - CAIRO_ANTIALIAS_DEFAULT, - NULL); - _cairo_path_fixed_fini (&path); - if (unlikely (status)) { - cairo_surface_destroy (surface); - return _cairo_surface_create_in_error (status); - } - } else { - surface = _cairo_surface_create_scratch (target, - CAIRO_CONTENT_ALPHA, - clip->extents.width, - clip->extents.height, - CAIRO_COLOR_WHITE); - if (unlikely (surface->status)) - return surface; - } - - copy = _cairo_clip_copy_with_translation (clip, - -clip->extents.x, - -clip->extents.y); - copy_path = copy->path; - copy->path = NULL; - - region = copy; - if (! _cairo_clip_is_region (copy)) - region = _cairo_clip_copy_region (copy); - - status = CAIRO_STATUS_SUCCESS; - clip_path = copy_path; - while (status == CAIRO_STATUS_SUCCESS && clip_path) { - status = _cairo_surface_fill (surface, - CAIRO_OPERATOR_IN, - &_cairo_pattern_white.base, - &clip_path->path, - clip_path->fill_rule, - clip_path->tolerance, - clip_path->antialias, - region); - clip_path = clip_path->prev; - } - - copy->path = copy_path; - _cairo_clip_destroy (copy); - if (region != copy) - _cairo_clip_destroy (region); - - if (unlikely (status)) { - cairo_surface_destroy (surface); - return _cairo_surface_create_in_error (status); - } - - *tx = clip->extents.x; - *ty = clip->extents.y; - return surface; -} - -cairo_surface_t * -_cairo_clip_get_image (const cairo_clip_t *clip, - cairo_surface_t *target, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_t *surface; - cairo_status_t status; - - surface = cairo_surface_create_similar_image (target, - CAIRO_FORMAT_A8, - extents->width, - extents->height); - if (unlikely (surface->status)) - return surface; - - status = _cairo_surface_paint (surface, CAIRO_OPERATOR_SOURCE, - &_cairo_pattern_white.base, NULL); - if (likely (status == CAIRO_STATUS_SUCCESS)) - status = _cairo_clip_combine_with_surface (clip, surface, - extents->x, extents->y); - - if (unlikely (status)) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - - return surface; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-tor-scan-converter.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-tor-scan-converter.c deleted file mode 100644 index e32a5a9d9c7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip-tor-scan-converter.c +++ /dev/null @@ -1,1845 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* glitter-paths - polygon scan converter - * - * Copyright (c) 2008 M Joonas Pihlaja - * Copyright (c) 2007 David Turner - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -/* This is the Glitter paths scan converter incorporated into cairo. - * The source is from commit 734c53237a867a773640bd5b64816249fa1730f8 - * of - * - * http://gitweb.freedesktop.org/?p=users/joonas/glitter-paths - */ -/* Glitter-paths is a stand alone polygon rasteriser derived from - * David Turner's reimplementation of Tor Anderssons's 15x17 - * supersampling rasteriser from the Apparition graphics library. The - * main new feature here is cheaply choosing per-scan line between - * doing fully analytical coverage computation for an entire row at a - * time vs. using a supersampling approach. - * - * David Turner's code can be found at - * - * http://david.freetype.org/rasterizer-shootout/raster-comparison-20070813.tar.bz2 - * - * In particular this file incorporates large parts of ftgrays_tor10.h - * from raster-comparison-20070813.tar.bz2 - */ -/* Overview - * - * A scan converter's basic purpose to take polygon edges and convert - * them into an RLE compressed A8 mask. This one works in two phases: - * gathering edges and generating spans. - * - * 1) As the user feeds the scan converter edges they are vertically - * clipped and bucketted into a _polygon_ data structure. The edges - * are also snapped from the user's coordinates to the subpixel grid - * coordinates used during scan conversion. - * - * user - * | - * | edges - * V - * polygon buckets - * - * 2) Generating spans works by performing a vertical sweep of pixel - * rows from top to bottom and maintaining an _active_list_ of edges - * that intersect the row. From the active list the fill rule - * determines which edges are the left and right edges of the start of - * each span, and their contribution is then accumulated into a pixel - * coverage list (_cell_list_) as coverage deltas. Once the coverage - * deltas of all edges are known we can form spans of constant pixel - * coverage by summing the deltas during a traversal of the cell list. - * At the end of a pixel row the cell list is sent to a coverage - * blitter for rendering to some target surface. - * - * The pixel coverages are computed by either supersampling the row - * and box filtering a mono rasterisation, or by computing the exact - * coverages of edges in the active list. The supersampling method is - * used whenever some edge starts or stops within the row or there are - * edge intersections in the row. - * - * polygon bucket for \ - * current pixel row | - * | | - * | activate new edges | Repeat GRID_Y times if we - * V \ are supersampling this row, - * active list / or just once if we're computing - * | | analytical coverage. - * | coverage deltas | - * V | - * pixel coverage list / - * | - * V - * coverage blitter - */ -#include "cairoint.h" -#include "cairo-spans-private.h" -#include "cairo-error-private.h" - -#include -#include -#include -#include -#include - -/* The input coordinate scale and the rasterisation grid scales. */ -#define GLITTER_INPUT_BITS CAIRO_FIXED_FRAC_BITS -#define GRID_X_BITS CAIRO_FIXED_FRAC_BITS -#define GRID_Y 15 - -/* Set glitter up to use a cairo span renderer to do the coverage - * blitting. */ -struct pool; -struct cell_list; - -/*------------------------------------------------------------------------- - * glitter-paths.h - */ - -/* "Input scaled" numbers are fixed precision reals with multiplier - * 2**GLITTER_INPUT_BITS. Input coordinates are given to glitter as - * pixel scaled numbers. These get converted to the internal grid - * scaled numbers as soon as possible. Internal overflow is possible - * if GRID_X/Y inside glitter-paths.c is larger than - * 1< -#include -#include - -/* All polygon coordinates are snapped onto a subsample grid. "Grid - * scaled" numbers are fixed precision reals with multiplier GRID_X or - * GRID_Y. */ -typedef int grid_scaled_t; -typedef int grid_scaled_x_t; -typedef int grid_scaled_y_t; - -/* Default x/y scale factors. - * You can either define GRID_X/Y_BITS to get a power-of-two scale - * or define GRID_X/Y separately. */ -#if !defined(GRID_X) && !defined(GRID_X_BITS) -# define GRID_X_BITS 8 -#endif -#if !defined(GRID_Y) && !defined(GRID_Y_BITS) -# define GRID_Y 15 -#endif - -/* Use GRID_X/Y_BITS to define GRID_X/Y if they're available. */ -#ifdef GRID_X_BITS -# define GRID_X (1 << GRID_X_BITS) -#endif -#ifdef GRID_Y_BITS -# define GRID_Y (1 << GRID_Y_BITS) -#endif - -/* The GRID_X_TO_INT_FRAC macro splits a grid scaled coordinate into - * integer and fractional parts. The integer part is floored. */ -#if defined(GRID_X_TO_INT_FRAC) - /* do nothing */ -#elif defined(GRID_X_BITS) -# define GRID_X_TO_INT_FRAC(x, i, f) \ - _GRID_TO_INT_FRAC_shift(x, i, f, GRID_X_BITS) -#else -# define GRID_X_TO_INT_FRAC(x, i, f) \ - _GRID_TO_INT_FRAC_general(x, i, f, GRID_X) -#endif - -#define _GRID_TO_INT_FRAC_general(t, i, f, m) do { \ - (i) = (t) / (m); \ - (f) = (t) % (m); \ - if ((f) < 0) { \ - --(i); \ - (f) += (m); \ - } \ -} while (0) - -#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do { \ - (f) = (t) & ((1 << (b)) - 1); \ - (i) = (t) >> (b); \ -} while (0) - -/* A grid area is a real in [0,1] scaled by 2*GRID_X*GRID_Y. We want - * to be able to represent exactly areas of subpixel trapezoids whose - * vertices are given in grid scaled coordinates. The scale factor - * comes from needing to accurately represent the area 0.5*dx*dy of a - * triangle with base dx and height dy in grid scaled numbers. */ -typedef int grid_area_t; -#define GRID_XY (2*GRID_X*GRID_Y) /* Unit area on the grid. */ - -/* GRID_AREA_TO_ALPHA(area): map [0,GRID_XY] to [0,255]. */ -#if GRID_XY == 510 -# define GRID_AREA_TO_ALPHA(c) (((c)+1) >> 1) -#elif GRID_XY == 255 -# define GRID_AREA_TO_ALPHA(c) (c) -#elif GRID_XY == 64 -# define GRID_AREA_TO_ALPHA(c) (((c) << 2) | -(((c) & 0x40) >> 6)) -#elif GRID_XY == 128 -# define GRID_AREA_TO_ALPHA(c) ((((c) << 1) | -((c) >> 7)) & 255) -#elif GRID_XY == 256 -# define GRID_AREA_TO_ALPHA(c) (((c) | -((c) >> 8)) & 255) -#elif GRID_XY == 15 -# define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) -#elif GRID_XY == 2*256*15 -# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) -#else -# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) -#endif - -#define UNROLL3(x) x x x - -struct quorem { - int32_t quo; - int32_t rem; -}; - -/* Header for a chunk of memory in a memory pool. */ -struct _pool_chunk { - /* # bytes used in this chunk. */ - size_t size; - - /* # bytes total in this chunk */ - size_t capacity; - - /* Pointer to the previous chunk or %NULL if this is the sentinel - * chunk in the pool header. */ - struct _pool_chunk *prev_chunk; - - /* Actual data starts here. Well aligned for pointers. */ -}; - -/* A memory pool. This is supposed to be embedded on the stack or - * within some other structure. It may optionally be followed by an - * embedded array from which requests are fulfilled until - * malloc needs to be called to allocate a first real chunk. */ -struct pool { - /* Chunk we're allocating from. */ - struct _pool_chunk *current; - - jmp_buf *jmp; - - /* Free list of previously allocated chunks. All have >= default - * capacity. */ - struct _pool_chunk *first_free; - - /* The default capacity of a chunk. */ - size_t default_capacity; - - /* Header for the sentinel chunk. Directly following the pool - * struct should be some space for embedded elements from which - * the sentinel chunk allocates from. */ - struct _pool_chunk sentinel[1]; -}; - -/* A polygon edge. */ -struct edge { - /* Next in y-bucket or active list. */ - struct edge *next; - - /* Current x coordinate while the edge is on the active - * list. Initialised to the x coordinate of the top of the - * edge. The quotient is in grid_scaled_x_t units and the - * remainder is mod dy in grid_scaled_y_t units.*/ - struct quorem x; - - /* Advance of the current x when moving down a subsample line. */ - struct quorem dxdy; - - /* Advance of the current x when moving down a full pixel - * row. Only initialised when the height of the edge is large - * enough that there's a chance the edge could be stepped by a - * full row's worth of subsample rows at a time. */ - struct quorem dxdy_full; - - /* The clipped y of the top of the edge. */ - grid_scaled_y_t ytop; - - /* y2-y1 after orienting the edge downwards. */ - grid_scaled_y_t dy; - - /* Number of subsample rows remaining to scan convert of this - * edge. */ - grid_scaled_y_t height_left; - - /* Original sign of the edge: +1 for downwards, -1 for upwards - * edges. */ - int dir; - int vertical; - int clip; -}; - -/* Number of subsample rows per y-bucket. Must be GRID_Y. */ -#define EDGE_Y_BUCKET_HEIGHT GRID_Y - -#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/EDGE_Y_BUCKET_HEIGHT) - -/* A collection of sorted and vertically clipped edges of the polygon. - * Edges are moved from the polygon to an active list while scan - * converting. */ -struct polygon { - /* The vertical clip extents. */ - grid_scaled_y_t ymin, ymax; - - /* Array of edges all starting in the same bucket. An edge is put - * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when - * it is added to the polygon. */ - struct edge **y_buckets; - struct edge *y_buckets_embedded[64]; - - struct { - struct pool base[1]; - struct edge embedded[32]; - } edge_pool; -}; - -/* A cell records the effect on pixel coverage of polygon edges - * passing through a pixel. It contains two accumulators of pixel - * coverage. - * - * Consider the effects of a polygon edge on the coverage of a pixel - * it intersects and that of the following one. The coverage of the - * following pixel is the height of the edge multiplied by the width - * of the pixel, and the coverage of the pixel itself is the area of - * the trapezoid formed by the edge and the right side of the pixel. - * - * +-----------------------+-----------------------+ - * | | | - * | | | - * |_______________________|_______________________| - * | \...................|.......................|\ - * | \..................|.......................| | - * | \.................|.......................| | - * | \....covered.....|.......................| | - * | \....area.......|.......................| } covered height - * | \..............|.......................| | - * |uncovered\.............|.......................| | - * | area \............|.......................| | - * |___________\...........|.......................|/ - * | | | - * | | | - * | | | - * +-----------------------+-----------------------+ - * - * Since the coverage of the following pixel will always be a multiple - * of the width of the pixel, we can store the height of the covered - * area instead. The coverage of the pixel itself is the total - * coverage minus the area of the uncovered area to the left of the - * edge. As it's faster to compute the uncovered area we only store - * that and subtract it from the total coverage later when forming - * spans to blit. - * - * The heights and areas are signed, with left edges of the polygon - * having positive sign and right edges having negative sign. When - * two edges intersect they swap their left/rightness so their - * contribution above and below the intersection point must be - * computed separately. */ -struct cell { - struct cell *next; - int x; - grid_area_t uncovered_area; - grid_scaled_y_t covered_height; - grid_scaled_y_t clipped_height; -}; - -/* A cell list represents the scan line sparsely as cells ordered by - * ascending x. It is geared towards scanning the cells in order - * using an internal cursor. */ -struct cell_list { - /* Sentinel nodes */ - struct cell head, tail; - - /* Cursor state for iterating through the cell list. */ - struct cell *cursor; - - /* Cells in the cell list are owned by the cell list and are - * allocated from this pool. */ - struct { - struct pool base[1]; - struct cell embedded[32]; - } cell_pool; -}; - -struct cell_pair { - struct cell *cell1; - struct cell *cell2; -}; - -/* The active list contains edges in the current scan line ordered by - * the x-coordinate of the intercept of the edge and the scan line. */ -struct active_list { - /* Leftmost edge on the current scan line. */ - struct edge *head; - - /* A lower bound on the height of the active edges is used to - * estimate how soon some active edge ends. We can't advance the - * scan conversion by a full pixel row if an edge ends somewhere - * within it. */ - grid_scaled_y_t min_height; -}; - -struct glitter_scan_converter { - struct polygon polygon[1]; - struct active_list active[1]; - struct cell_list coverages[1]; - - /* Clip box. */ - grid_scaled_y_t ymin, ymax; -}; - -/* Compute the floored division a/b. Assumes / and % perform symmetric - * division. */ -inline static struct quorem -floored_divrem(int a, int b) -{ - struct quorem qr; - qr.quo = a/b; - qr.rem = a%b; - if ((a^b)<0 && qr.rem) { - qr.quo -= 1; - qr.rem += b; - } - return qr; -} - -/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric - * division. */ -static struct quorem -floored_muldivrem(int x, int a, int b) -{ - struct quorem qr; - long long xa = (long long)x*a; - qr.quo = xa/b; - qr.rem = xa%b; - if ((xa>=0) != (b>=0) && qr.rem) { - qr.quo -= 1; - qr.rem += b; - } - return qr; -} - -static struct _pool_chunk * -_pool_chunk_init( - struct _pool_chunk *p, - struct _pool_chunk *prev_chunk, - size_t capacity) -{ - p->prev_chunk = prev_chunk; - p->size = 0; - p->capacity = capacity; - return p; -} - -static struct _pool_chunk * -_pool_chunk_create(struct pool *pool, size_t size) -{ - struct _pool_chunk *p; - - p = malloc(size + sizeof(struct _pool_chunk)); - if (unlikely (NULL == p)) - longjmp (*pool->jmp, _cairo_error (CAIRO_STATUS_NO_MEMORY)); - - return _pool_chunk_init(p, pool->current, size); -} - -static void -pool_init(struct pool *pool, - jmp_buf *jmp, - size_t default_capacity, - size_t embedded_capacity) -{ - pool->jmp = jmp; - pool->current = pool->sentinel; - pool->first_free = NULL; - pool->default_capacity = default_capacity; - _pool_chunk_init(pool->sentinel, NULL, embedded_capacity); -} - -static void -pool_fini(struct pool *pool) -{ - struct _pool_chunk *p = pool->current; - do { - while (NULL != p) { - struct _pool_chunk *prev = p->prev_chunk; - if (p != pool->sentinel) - free(p); - p = prev; - } - p = pool->first_free; - pool->first_free = NULL; - } while (NULL != p); -} - -/* Satisfy an allocation by first allocating a new large enough chunk - * and adding it to the head of the pool's chunk list. This function - * is called as a fallback if pool_alloc() couldn't do a quick - * allocation from the current chunk in the pool. */ -static void * -_pool_alloc_from_new_chunk( - struct pool *pool, - size_t size) -{ - struct _pool_chunk *chunk; - void *obj; - size_t capacity; - - /* If the allocation is smaller than the default chunk size then - * try getting a chunk off the free list. Force alloc of a new - * chunk for large requests. */ - capacity = size; - chunk = NULL; - if (size < pool->default_capacity) { - capacity = pool->default_capacity; - chunk = pool->first_free; - if (chunk) { - pool->first_free = chunk->prev_chunk; - _pool_chunk_init(chunk, pool->current, chunk->capacity); - } - } - - if (NULL == chunk) - chunk = _pool_chunk_create (pool, capacity); - pool->current = chunk; - - obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); - chunk->size += size; - return obj; -} - -/* Allocate size bytes from the pool. The first allocated address - * returned from a pool is aligned to sizeof(void*). Subsequent - * addresses will maintain alignment as long as multiples of void* are - * allocated. Returns the address of a new memory area or %NULL on - * allocation failures. The pool retains ownership of the returned - * memory. */ -inline static void * -pool_alloc (struct pool *pool, size_t size) -{ - struct _pool_chunk *chunk = pool->current; - - if (size <= chunk->capacity - chunk->size) { - void *obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); - chunk->size += size; - return obj; - } else { - return _pool_alloc_from_new_chunk(pool, size); - } -} - -/* Relinquish all pool_alloced memory back to the pool. */ -static void -pool_reset (struct pool *pool) -{ - /* Transfer all used chunks to the chunk free list. */ - struct _pool_chunk *chunk = pool->current; - if (chunk != pool->sentinel) { - while (chunk->prev_chunk != pool->sentinel) { - chunk = chunk->prev_chunk; - } - chunk->prev_chunk = pool->first_free; - pool->first_free = pool->current; - } - /* Reset the sentinel as the current chunk. */ - pool->current = pool->sentinel; - pool->sentinel->size = 0; -} - -/* Rewinds the cell list's cursor to the beginning. After rewinding - * we're good to cell_list_find() the cell any x coordinate. */ -inline static void -cell_list_rewind (struct cell_list *cells) -{ - cells->cursor = &cells->head; -} - -/* Rewind the cell list if its cursor has been advanced past x. */ -inline static void -cell_list_maybe_rewind (struct cell_list *cells, int x) -{ - struct cell *tail = cells->cursor; - if (tail->x > x) - cell_list_rewind (cells); -} - -static void -cell_list_init(struct cell_list *cells, jmp_buf *jmp) -{ - pool_init(cells->cell_pool.base, jmp, - 256*sizeof(struct cell), - sizeof(cells->cell_pool.embedded)); - cells->tail.next = NULL; - cells->tail.x = INT_MAX; - cells->head.x = INT_MIN; - cells->head.next = &cells->tail; - cell_list_rewind (cells); -} - -static void -cell_list_fini(struct cell_list *cells) -{ - pool_fini (cells->cell_pool.base); -} - -/* Empty the cell list. This is called at the start of every pixel - * row. */ -inline static void -cell_list_reset (struct cell_list *cells) -{ - cell_list_rewind (cells); - cells->head.next = &cells->tail; - pool_reset (cells->cell_pool.base); -} - -static struct cell * -cell_list_alloc (struct cell_list *cells, - struct cell *tail, - int x) -{ - struct cell *cell; - - cell = pool_alloc (cells->cell_pool.base, sizeof (struct cell)); - cell->next = tail->next; - tail->next = cell; - cell->x = x; - cell->uncovered_area = 0; - cell->covered_height = 0; - cell->clipped_height = 0; - return cell; -} - -/* Find a cell at the given x-coordinate. Returns %NULL if a new cell - * needed to be allocated but couldn't be. Cells must be found with - * non-decreasing x-coordinate until the cell list is rewound using - * cell_list_rewind(). Ownership of the returned cell is retained by - * the cell list. */ -inline static struct cell * -cell_list_find (struct cell_list *cells, int x) -{ - struct cell *tail = cells->cursor; - - while (1) { - UNROLL3({ - if (tail->next->x > x) - break; - tail = tail->next; - }); - } - - if (tail->x != x) - tail = cell_list_alloc (cells, tail, x); - return cells->cursor = tail; - -} - -/* Find two cells at x1 and x2. This is exactly equivalent - * to - * - * pair.cell1 = cell_list_find(cells, x1); - * pair.cell2 = cell_list_find(cells, x2); - * - * except with less function call overhead. */ -inline static struct cell_pair -cell_list_find_pair(struct cell_list *cells, int x1, int x2) -{ - struct cell_pair pair; - - pair.cell1 = cells->cursor; - while (1) { - UNROLL3({ - if (pair.cell1->next->x > x1) - break; - pair.cell1 = pair.cell1->next; - }); - } - if (pair.cell1->x != x1) { - struct cell *cell = pool_alloc (cells->cell_pool.base, - sizeof (struct cell)); - cell->x = x1; - cell->uncovered_area = 0; - cell->covered_height = 0; - cell->clipped_height = 0; - cell->next = pair.cell1->next; - pair.cell1->next = cell; - pair.cell1 = cell; - } - - pair.cell2 = pair.cell1; - while (1) { - UNROLL3({ - if (pair.cell2->next->x > x2) - break; - pair.cell2 = pair.cell2->next; - }); - } - if (pair.cell2->x != x2) { - struct cell *cell = pool_alloc (cells->cell_pool.base, - sizeof (struct cell)); - cell->uncovered_area = 0; - cell->covered_height = 0; - cell->clipped_height = 0; - cell->x = x2; - cell->next = pair.cell2->next; - pair.cell2->next = cell; - pair.cell2 = cell; - } - - cells->cursor = pair.cell2; - return pair; -} - -/* Add a subpixel span covering [x1, x2) to the coverage cells. */ -inline static void -cell_list_add_subspan(struct cell_list *cells, - grid_scaled_x_t x1, - grid_scaled_x_t x2) -{ - int ix1, fx1; - int ix2, fx2; - - GRID_X_TO_INT_FRAC(x1, ix1, fx1); - GRID_X_TO_INT_FRAC(x2, ix2, fx2); - - if (ix1 != ix2) { - struct cell_pair p; - p = cell_list_find_pair(cells, ix1, ix2); - p.cell1->uncovered_area += 2*fx1; - ++p.cell1->covered_height; - p.cell2->uncovered_area -= 2*fx2; - --p.cell2->covered_height; - } else { - struct cell *cell = cell_list_find(cells, ix1); - cell->uncovered_area += 2*(fx1-fx2); - } -} - -/* Adds the analytical coverage of an edge crossing the current pixel - * row to the coverage cells and advances the edge's x position to the - * following row. - * - * This function is only called when we know that during this pixel row: - * - * 1) The relative order of all edges on the active list doesn't - * change. In particular, no edges intersect within this row to pixel - * precision. - * - * 2) No new edges start in this row. - * - * 3) No existing edges end mid-row. - * - * This function depends on being called with all edges from the - * active list in the order they appear on the list (i.e. with - * non-decreasing x-coordinate.) */ -static void -cell_list_render_edge( - struct cell_list *cells, - struct edge *edge, - int sign) -{ - grid_scaled_y_t y1, y2, dy; - grid_scaled_x_t dx; - int ix1, ix2; - grid_scaled_x_t fx1, fx2; - - struct quorem x1 = edge->x; - struct quorem x2 = x1; - - if (! edge->vertical) { - x2.quo += edge->dxdy_full.quo; - x2.rem += edge->dxdy_full.rem; - if (x2.rem >= 0) { - ++x2.quo; - x2.rem -= edge->dy; - } - - edge->x = x2; - } - - GRID_X_TO_INT_FRAC(x1.quo, ix1, fx1); - GRID_X_TO_INT_FRAC(x2.quo, ix2, fx2); - - /* Edge is entirely within a column? */ - if (ix1 == ix2) { - /* We always know that ix1 is >= the cell list cursor in this - * case due to the no-intersections precondition. */ - struct cell *cell = cell_list_find(cells, ix1); - cell->covered_height += sign*GRID_Y; - cell->uncovered_area += sign*(fx1 + fx2)*GRID_Y; - return; - } - - /* Orient the edge left-to-right. */ - dx = x2.quo - x1.quo; - if (dx >= 0) { - y1 = 0; - y2 = GRID_Y; - } else { - int tmp; - tmp = ix1; ix1 = ix2; ix2 = tmp; - tmp = fx1; fx1 = fx2; fx2 = tmp; - dx = -dx; - sign = -sign; - y1 = GRID_Y; - y2 = 0; - } - dy = y2 - y1; - - /* Add coverage for all pixels [ix1,ix2] on this row crossed - * by the edge. */ - { - struct cell_pair pair; - struct quorem y = floored_divrem((GRID_X - fx1)*dy, dx); - - /* When rendering a previous edge on the active list we may - * advance the cell list cursor past the leftmost pixel of the - * current edge even though the two edges don't intersect. - * e.g. consider two edges going down and rightwards: - * - * --\_+---\_+-----+-----+---- - * \_ \_ | | - * | \_ | \_ | | - * | \_| \_| | - * | \_ \_ | - * ----+-----+-\---+-\---+---- - * - * The left edge touches cells past the starting cell of the - * right edge. Fortunately such cases are rare. - * - * The rewinding is never necessary if the current edge stays - * within a single column because we've checked before calling - * this function that the active list order won't change. */ - cell_list_maybe_rewind(cells, ix1); - - pair = cell_list_find_pair(cells, ix1, ix1+1); - pair.cell1->uncovered_area += sign*y.quo*(GRID_X + fx1); - pair.cell1->covered_height += sign*y.quo; - y.quo += y1; - - if (ix1+1 < ix2) { - struct quorem dydx_full = floored_divrem(GRID_X*dy, dx); - struct cell *cell = pair.cell2; - - ++ix1; - do { - grid_scaled_y_t y_skip = dydx_full.quo; - y.rem += dydx_full.rem; - if (y.rem >= dx) { - ++y_skip; - y.rem -= dx; - } - - y.quo += y_skip; - - y_skip *= sign; - cell->uncovered_area += y_skip*GRID_X; - cell->covered_height += y_skip; - - ++ix1; - cell = cell_list_find(cells, ix1); - } while (ix1 != ix2); - - pair.cell2 = cell; - } - pair.cell2->uncovered_area += sign*(y2 - y.quo)*fx2; - pair.cell2->covered_height += sign*(y2 - y.quo); - } -} - -static void -polygon_init (struct polygon *polygon, jmp_buf *jmp) -{ - polygon->ymin = polygon->ymax = 0; - polygon->y_buckets = polygon->y_buckets_embedded; - pool_init (polygon->edge_pool.base, jmp, - 8192 - sizeof (struct _pool_chunk), - sizeof (polygon->edge_pool.embedded)); -} - -static void -polygon_fini (struct polygon *polygon) -{ - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - pool_fini (polygon->edge_pool.base); -} - -/* Empties the polygon of all edges. The polygon is then prepared to - * receive new edges and clip them to the vertical range - * [ymin,ymax). */ -static cairo_status_t -polygon_reset (struct polygon *polygon, - grid_scaled_y_t ymin, - grid_scaled_y_t ymax) -{ - unsigned h = ymax - ymin; - unsigned num_buckets = EDGE_Y_BUCKET_INDEX(ymax + EDGE_Y_BUCKET_HEIGHT-1, - ymin); - - pool_reset(polygon->edge_pool.base); - - if (unlikely (h > 0x7FFFFFFFU - EDGE_Y_BUCKET_HEIGHT)) - goto bail_no_mem; /* even if you could, you wouldn't want to. */ - - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - polygon->y_buckets = polygon->y_buckets_embedded; - if (num_buckets > ARRAY_LENGTH (polygon->y_buckets_embedded)) { - polygon->y_buckets = _cairo_malloc_ab (num_buckets, - sizeof (struct edge *)); - if (unlikely (NULL == polygon->y_buckets)) - goto bail_no_mem; - } - memset (polygon->y_buckets, 0, num_buckets * sizeof (struct edge *)); - - polygon->ymin = ymin; - polygon->ymax = ymax; - return CAIRO_STATUS_SUCCESS; - - bail_no_mem: - polygon->ymin = 0; - polygon->ymax = 0; - return CAIRO_STATUS_NO_MEMORY; -} - -static void -_polygon_insert_edge_into_its_y_bucket( - struct polygon *polygon, - struct edge *e) -{ - unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin); - struct edge **ptail = &polygon->y_buckets[ix]; - e->next = *ptail; - *ptail = e; -} - -inline static void -polygon_add_edge (struct polygon *polygon, - const cairo_edge_t *edge, - int clip) -{ - struct edge *e; - grid_scaled_x_t dx; - grid_scaled_y_t dy; - grid_scaled_y_t ytop, ybot; - grid_scaled_y_t ymin = polygon->ymin; - grid_scaled_y_t ymax = polygon->ymax; - - assert (edge->bottom > edge->top); - - if (unlikely (edge->top >= ymax || edge->bottom <= ymin)) - return; - - e = pool_alloc (polygon->edge_pool.base, sizeof (struct edge)); - - dx = edge->line.p2.x - edge->line.p1.x; - dy = edge->line.p2.y - edge->line.p1.y; - e->dy = dy; - e->dir = edge->dir; - e->clip = clip; - - ytop = edge->top >= ymin ? edge->top : ymin; - ybot = edge->bottom <= ymax ? edge->bottom : ymax; - e->ytop = ytop; - e->height_left = ybot - ytop; - - if (dx == 0) { - e->vertical = TRUE; - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - e->dxdy.quo = 0; - e->dxdy.rem = 0; - e->dxdy_full.quo = 0; - e->dxdy_full.rem = 0; - } else { - e->vertical = FALSE; - e->dxdy = floored_divrem (dx, dy); - if (ytop == edge->line.p1.y) { - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - } else { - e->x = floored_muldivrem (ytop - edge->line.p1.y, dx, dy); - e->x.quo += edge->line.p1.x; - } - - if (e->height_left >= GRID_Y) { - e->dxdy_full = floored_muldivrem (GRID_Y, dx, dy); - } else { - e->dxdy_full.quo = 0; - e->dxdy_full.rem = 0; - } - } - - _polygon_insert_edge_into_its_y_bucket (polygon, e); - - e->x.rem -= dy; /* Bias the remainder for faster - * edge advancement. */ -} - -static void -active_list_reset (struct active_list *active) -{ - active->head = NULL; - active->min_height = 0; -} - -static void -active_list_init(struct active_list *active) -{ - active_list_reset(active); -} - -/* - * Merge two sorted edge lists. - * Input: - * - head_a: The head of the first list. - * - head_b: The head of the second list; head_b cannot be NULL. - * Output: - * Returns the head of the merged list. - * - * Implementation notes: - * To make it fast (in particular, to reduce to an insertion sort whenever - * one of the two input lists only has a single element) we iterate through - * a list until its head becomes greater than the head of the other list, - * then we switch their roles. As soon as one of the two lists is empty, we - * just attach the other one to the current list and exit. - * Writes to memory are only needed to "switch" lists (as it also requires - * attaching to the output list the list which we will be iterating next) and - * to attach the last non-empty list. - */ -static struct edge * -merge_sorted_edges (struct edge *head_a, struct edge *head_b) -{ - struct edge *head, **next; - int32_t x; - - if (head_a == NULL) - return head_b; - - next = &head; - if (head_a->x.quo <= head_b->x.quo) { - head = head_a; - } else { - head = head_b; - goto start_with_b; - } - - do { - x = head_b->x.quo; - while (head_a != NULL && head_a->x.quo <= x) { - next = &head_a->next; - head_a = head_a->next; - } - - *next = head_b; - if (head_a == NULL) - return head; - -start_with_b: - x = head_a->x.quo; - while (head_b != NULL && head_b->x.quo <= x) { - next = &head_b->next; - head_b = head_b->next; - } - - *next = head_a; - if (head_b == NULL) - return head; - } while (1); -} - -/* - * Sort (part of) a list. - * Input: - * - list: The list to be sorted; list cannot be NULL. - * - limit: Recursion limit. - * Output: - * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the - * input list; if the input list has fewer elements, head_out be a sorted list - * containing all the elements of the input list. - * Returns the head of the list of unprocessed elements (NULL if the sorted list contains - * all the elements of the input list). - * - * Implementation notes: - * Special case single element list, unroll/inline the sorting of the first two elements. - * Some tail recursion is used since we iterate on the bottom-up solution of the problem - * (we start with a small sorted list and keep merging other lists of the same size to it). - */ -static struct edge * -sort_edges (struct edge *list, - unsigned int level, - struct edge **head_out) -{ - struct edge *head_other, *remaining; - unsigned int i; - - head_other = list->next; - - /* Single element list -> return */ - if (head_other == NULL) { - *head_out = list; - return NULL; - } - - /* Unroll the first iteration of the following loop (halves the number of calls to merge_sorted_edges): - * - Initialize remaining to be the list containing the elements after the second in the input list. - * - Initialize *head_out to be the sorted list containing the first two element. - */ - remaining = head_other->next; - if (list->x.quo <= head_other->x.quo) { - *head_out = list; - /* list->next = head_other; */ /* The input list is already like this. */ - head_other->next = NULL; - } else { - *head_out = head_other; - head_other->next = list; - list->next = NULL; - } - - for (i = 0; i < level && remaining; i++) { - /* Extract a sorted list of the same size as *head_out - * (2^(i+1) elements) from the list of remaining elements. */ - remaining = sort_edges (remaining, i, &head_other); - *head_out = merge_sorted_edges (*head_out, head_other); - } - - /* *head_out now contains (at most) 2^(level+1) elements. */ - - return remaining; -} - -/* Test if the edges on the active list can be safely advanced by a - * full row without intersections or any edges ending. */ -inline static int -active_list_can_step_full_row (struct active_list *active) -{ - const struct edge *e; - int prev_x = INT_MIN; - - /* Recomputes the minimum height of all edges on the active - * list if we have been dropping edges. */ - if (active->min_height <= 0) { - int min_height = INT_MAX; - - e = active->head; - while (NULL != e) { - if (e->height_left < min_height) - min_height = e->height_left; - e = e->next; - } - - active->min_height = min_height; - } - - if (active->min_height < GRID_Y) - return 0; - - /* Check for intersections as no edges end during the next row. */ - e = active->head; - while (NULL != e) { - struct quorem x = e->x; - - if (! e->vertical) { - x.quo += e->dxdy_full.quo; - x.rem += e->dxdy_full.rem; - if (x.rem >= 0) - ++x.quo; - } - - if (x.quo <= prev_x) - return 0; - - prev_x = x.quo; - e = e->next; - } - - return 1; -} - -/* Merges edges on the given subpixel row from the polygon to the - * active_list. */ -inline static void -active_list_merge_edges_from_polygon(struct active_list *active, - struct edge **ptail, - grid_scaled_y_t y, - struct polygon *polygon) -{ - /* Split off the edges on the current subrow and merge them into - * the active list. */ - int min_height = active->min_height; - struct edge *subrow_edges = NULL; - struct edge *tail = *ptail; - - do { - struct edge *next = tail->next; - - if (y == tail->ytop) { - tail->next = subrow_edges; - subrow_edges = tail; - - if (tail->height_left < min_height) - min_height = tail->height_left; - - *ptail = next; - } else - ptail = &tail->next; - - tail = next; - } while (tail); - - if (subrow_edges) { - sort_edges (subrow_edges, UINT_MAX, &subrow_edges); - active->head = merge_sorted_edges (active->head, subrow_edges); - active->min_height = min_height; - } -} - -/* Advance the edges on the active list by one subsample row by - * updating their x positions. Drop edges from the list that end. */ -inline static void -active_list_substep_edges(struct active_list *active) -{ - struct edge **cursor = &active->head; - grid_scaled_x_t prev_x = INT_MIN; - struct edge *unsorted = NULL; - struct edge *edge = *cursor; - - do { - UNROLL3({ - struct edge *next; - - if (NULL == edge) - break; - - next = edge->next; - if (--edge->height_left) { - edge->x.quo += edge->dxdy.quo; - edge->x.rem += edge->dxdy.rem; - if (edge->x.rem >= 0) { - ++edge->x.quo; - edge->x.rem -= edge->dy; - } - - if (edge->x.quo < prev_x) { - *cursor = next; - edge->next = unsorted; - unsorted = edge; - } else { - prev_x = edge->x.quo; - cursor = &edge->next; - } - } else { - *cursor = next; - } - edge = next; - }) - } while (1); - - if (unsorted) { - sort_edges (unsorted, UINT_MAX, &unsorted); - active->head = merge_sorted_edges (active->head, unsorted); - } -} - -inline static void -apply_nonzero_fill_rule_for_subrow (struct active_list *active, - struct cell_list *coverages) -{ - struct edge *edge = active->head; - int winding = 0; - int xstart; - int xend; - - cell_list_rewind (coverages); - - while (NULL != edge) { - xstart = edge->x.quo; - winding = edge->dir; - while (1) { - edge = edge->next; - if (NULL == edge) { - ASSERT_NOT_REACHED; - return; - } - - winding += edge->dir; - if (0 == winding) { - if (edge->next == NULL || edge->next->x.quo != edge->x.quo) - break; - } - } - - xend = edge->x.quo; - cell_list_add_subspan (coverages, xstart, xend); - - edge = edge->next; - } -} - -static void -apply_evenodd_fill_rule_for_subrow (struct active_list *active, - struct cell_list *coverages) -{ - struct edge *edge = active->head; - int xstart; - int xend; - - cell_list_rewind (coverages); - - while (NULL != edge) { - xstart = edge->x.quo; - - while (1) { - edge = edge->next; - if (NULL == edge) { - ASSERT_NOT_REACHED; - return; - } - - if (edge->next == NULL || edge->next->x.quo != edge->x.quo) - break; - - edge = edge->next; - } - - xend = edge->x.quo; - cell_list_add_subspan (coverages, xstart, xend); - - edge = edge->next; - } -} - -static void -apply_nonzero_fill_rule_and_step_edges (struct active_list *active, - struct cell_list *coverages) -{ - struct edge **cursor = &active->head; - struct edge *left_edge; - - left_edge = *cursor; - while (NULL != left_edge) { - struct edge *right_edge; - int winding = left_edge->dir; - - left_edge->height_left -= GRID_Y; - if (left_edge->height_left) - cursor = &left_edge->next; - else - *cursor = left_edge->next; - - while (1) { - right_edge = *cursor; - if (NULL == right_edge) { - cell_list_render_edge (coverages, left_edge, +1); - return; - } - - right_edge->height_left -= GRID_Y; - if (right_edge->height_left) - cursor = &right_edge->next; - else - *cursor = right_edge->next; - - winding += right_edge->dir; - if (0 == winding) { - if (right_edge->next == NULL || - right_edge->next->x.quo != right_edge->x.quo) - { - break; - } - } - - if (! right_edge->vertical) { - right_edge->x.quo += right_edge->dxdy_full.quo; - right_edge->x.rem += right_edge->dxdy_full.rem; - if (right_edge->x.rem >= 0) { - ++right_edge->x.quo; - right_edge->x.rem -= right_edge->dy; - } - } - } - - cell_list_render_edge (coverages, left_edge, +1); - cell_list_render_edge (coverages, right_edge, -1); - - left_edge = *cursor; - } -} - -static void -apply_evenodd_fill_rule_and_step_edges (struct active_list *active, - struct cell_list *coverages) -{ - struct edge **cursor = &active->head; - struct edge *left_edge; - - left_edge = *cursor; - while (NULL != left_edge) { - struct edge *right_edge; - - left_edge->height_left -= GRID_Y; - if (left_edge->height_left) - cursor = &left_edge->next; - else - *cursor = left_edge->next; - - while (1) { - right_edge = *cursor; - if (NULL == right_edge) { - cell_list_render_edge (coverages, left_edge, +1); - return; - } - - right_edge->height_left -= GRID_Y; - if (right_edge->height_left) - cursor = &right_edge->next; - else - *cursor = right_edge->next; - - if (right_edge->next == NULL || - right_edge->next->x.quo != right_edge->x.quo) - { - break; - } - - if (! right_edge->vertical) { - right_edge->x.quo += right_edge->dxdy_full.quo; - right_edge->x.rem += right_edge->dxdy_full.rem; - if (right_edge->x.rem >= 0) { - ++right_edge->x.quo; - right_edge->x.rem -= right_edge->dy; - } - } - } - - cell_list_render_edge (coverages, left_edge, +1); - cell_list_render_edge (coverages, right_edge, -1); - - left_edge = *cursor; - } -} - -static void -_glitter_scan_converter_init(glitter_scan_converter_t *converter, jmp_buf *jmp) -{ - polygon_init(converter->polygon, jmp); - active_list_init(converter->active); - cell_list_init(converter->coverages, jmp); - converter->ymin=0; - converter->ymax=0; -} - -static void -_glitter_scan_converter_fini(glitter_scan_converter_t *converter) -{ - polygon_fini(converter->polygon); - cell_list_fini(converter->coverages); - converter->ymin=0; - converter->ymax=0; -} - -static grid_scaled_t -int_to_grid_scaled(int i, int scale) -{ - /* Clamp to max/min representable scaled number. */ - if (i >= 0) { - if (i >= INT_MAX/scale) - i = INT_MAX/scale; - } - else { - if (i <= INT_MIN/scale) - i = INT_MIN/scale; - } - return i*scale; -} - -#define int_to_grid_scaled_x(x) int_to_grid_scaled((x), GRID_X) -#define int_to_grid_scaled_y(x) int_to_grid_scaled((x), GRID_Y) - -static cairo_status_t -glitter_scan_converter_reset(glitter_scan_converter_t *converter, - int ymin, int ymax) -{ - cairo_status_t status; - - converter->ymin = 0; - converter->ymax = 0; - - ymin = int_to_grid_scaled_y(ymin); - ymax = int_to_grid_scaled_y(ymax); - - active_list_reset(converter->active); - cell_list_reset(converter->coverages); - status = polygon_reset(converter->polygon, ymin, ymax); - if (status) - return status; - - converter->ymin = ymin; - converter->ymax = ymax; - return CAIRO_STATUS_SUCCESS; -} - -/* INPUT_TO_GRID_X/Y (in_coord, out_grid_scaled, grid_scale) - * These macros convert an input coordinate in the client's - * device space to the rasterisation grid. - */ -/* Gah.. this bit of ugly defines INPUT_TO_GRID_X/Y so as to use - * shifts if possible, and something saneish if not. - */ -#if !defined(INPUT_TO_GRID_Y) && defined(GRID_Y_BITS) && GRID_Y_BITS <= GLITTER_INPUT_BITS -# define INPUT_TO_GRID_Y(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_Y_BITS) -#else -# define INPUT_TO_GRID_Y(in, out) INPUT_TO_GRID_general(in, out, GRID_Y) -#endif - -#if !defined(INPUT_TO_GRID_X) && defined(GRID_X_BITS) && GRID_X_BITS <= GLITTER_INPUT_BITS -# define INPUT_TO_GRID_X(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_X_BITS) -#else -# define INPUT_TO_GRID_X(in, out) INPUT_TO_GRID_general(in, out, GRID_X) -#endif - -#define INPUT_TO_GRID_general(in, out, grid_scale) do { \ - long long tmp__ = (long long)(grid_scale) * (in); \ - tmp__ >>= GLITTER_INPUT_BITS; \ - (out) = tmp__; \ -} while (0) - -static void -glitter_scan_converter_add_edge (glitter_scan_converter_t *converter, - const cairo_edge_t *edge, - int clip) -{ - cairo_edge_t e; - - INPUT_TO_GRID_Y (edge->top, e.top); - INPUT_TO_GRID_Y (edge->bottom, e.bottom); - if (e.top >= e.bottom) - return; - - /* XXX: possible overflows if GRID_X/Y > 2**GLITTER_INPUT_BITS */ - INPUT_TO_GRID_Y (edge->line.p1.y, e.line.p1.y); - INPUT_TO_GRID_Y (edge->line.p2.y, e.line.p2.y); - if (e.line.p1.y == e.line.p2.y) - return; - - INPUT_TO_GRID_X (edge->line.p1.x, e.line.p1.x); - INPUT_TO_GRID_X (edge->line.p2.x, e.line.p2.x); - - e.dir = edge->dir; - - polygon_add_edge (converter->polygon, &e, clip); -} - -static cairo_bool_t -active_list_is_vertical (struct active_list *active) -{ - struct edge *e; - - for (e = active->head; e != NULL; e = e->next) { - if (! e->vertical) - return FALSE; - } - - return TRUE; -} - -static void -step_edges (struct active_list *active, int count) -{ - struct edge **cursor = &active->head; - struct edge *edge; - - for (edge = *cursor; edge != NULL; edge = *cursor) { - edge->height_left -= GRID_Y * count; - if (edge->height_left) - cursor = &edge->next; - else - *cursor = edge->next; - } -} - -static cairo_status_t -blit_coverages (struct cell_list *cells, - cairo_span_renderer_t *renderer, - struct pool *span_pool, - int y, int height) -{ - struct cell *cell = cells->head.next; - int prev_x = -1; - int cover = 0, last_cover = 0; - int clip = 0; - cairo_half_open_span_t *spans; - unsigned num_spans; - - assert (cell != &cells->tail); - - /* Count number of cells remaining. */ - { - struct cell *next = cell; - num_spans = 2; - while (next->next) { - next = next->next; - ++num_spans; - } - num_spans = 2*num_spans; - } - - /* Allocate enough spans for the row. */ - pool_reset (span_pool); - spans = pool_alloc (span_pool, sizeof(spans[0])*num_spans); - num_spans = 0; - - /* Form the spans from the coverages and areas. */ - for (; cell->next; cell = cell->next) { - int x = cell->x; - int area; - - if (x > prev_x && cover != last_cover) { - spans[num_spans].x = prev_x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); - spans[num_spans].inverse = 0; - last_cover = cover; - ++num_spans; - } - - cover += cell->covered_height*GRID_X*2; - clip += cell->covered_height*GRID_X*2; - area = cover - cell->uncovered_area; - - if (area != last_cover) { - spans[num_spans].x = x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (area); - spans[num_spans].inverse = 0; - last_cover = area; - ++num_spans; - } - - prev_x = x+1; - } - - /* Dump them into the renderer. */ - return renderer->render_rows (renderer, y, height, spans, num_spans); -} - -static void -glitter_scan_converter_render(glitter_scan_converter_t *converter, - int nonzero_fill, - cairo_span_renderer_t *span_renderer, - struct pool *span_pool) -{ - int i, j; - int ymax_i = converter->ymax / GRID_Y; - int ymin_i = converter->ymin / GRID_Y; - int h = ymax_i - ymin_i; - struct polygon *polygon = converter->polygon; - struct cell_list *coverages = converter->coverages; - struct active_list *active = converter->active; - - /* Render each pixel row. */ - for (i = 0; i < h; i = j) { - int do_full_step = 0; - - j = i + 1; - - /* Determine if we can ignore this row or use the full pixel - * stepper. */ - if (GRID_Y == EDGE_Y_BUCKET_HEIGHT && ! polygon->y_buckets[i]) { - if (! active->head) { - for (; j < h && ! polygon->y_buckets[j]; j++) - ; - continue; - } - - do_full_step = active_list_can_step_full_row (active); - } - - if (do_full_step) { - /* Step by a full pixel row's worth. */ - if (nonzero_fill) - apply_nonzero_fill_rule_and_step_edges (active, coverages); - else - apply_evenodd_fill_rule_and_step_edges (active, coverages); - - if (active_list_is_vertical (active)) { - while (j < h && - polygon->y_buckets[j] == NULL && - active->min_height >= 2*GRID_Y) - { - active->min_height -= GRID_Y; - j++; - } - if (j != i + 1) - step_edges (active, j - (i + 1)); - } - } else { - grid_scaled_y_t suby; - - /* Subsample this row. */ - for (suby = 0; suby < GRID_Y; suby++) { - grid_scaled_y_t y = (i+ymin_i)*GRID_Y + suby; - - if (polygon->y_buckets[i]) { - active_list_merge_edges_from_polygon (active, - &polygon->y_buckets[i], y, - polygon); - } - - if (nonzero_fill) - apply_nonzero_fill_rule_for_subrow (active, coverages); - else - apply_evenodd_fill_rule_for_subrow (active, coverages); - - active_list_substep_edges(active); - } - } - - blit_coverages (coverages, span_renderer, span_pool, i+ymin_i, j -i); - cell_list_reset (coverages); - - if (! active->head) - active->min_height = INT_MAX; - else - active->min_height -= GRID_Y; - } -} - -struct _cairo_clip_tor_scan_converter { - cairo_scan_converter_t base; - - glitter_scan_converter_t converter[1]; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - - cairo_fill_rule_t clip_fill_rule; - cairo_antialias_t clip_antialias; - - jmp_buf jmp; - - struct { - struct pool base[1]; - cairo_half_open_span_t embedded[32]; - } span_pool; -}; - -typedef struct _cairo_clip_tor_scan_converter cairo_clip_tor_scan_converter_t; - -static void -_cairo_clip_tor_scan_converter_destroy (void *converter) -{ - cairo_clip_tor_scan_converter_t *self = converter; - if (self == NULL) { - return; - } - _glitter_scan_converter_fini (self->converter); - pool_fini (self->span_pool.base); - free(self); -} - -static cairo_status_t -_cairo_clip_tor_scan_converter_generate (void *converter, - cairo_span_renderer_t *renderer) -{ - cairo_clip_tor_scan_converter_t *self = converter; - cairo_status_t status; - - if ((status = setjmp (self->jmp))) - return _cairo_scan_converter_set_error (self, _cairo_error (status)); - - glitter_scan_converter_render (self->converter, - self->fill_rule == CAIRO_FILL_RULE_WINDING, - renderer, - self->span_pool.base); - return CAIRO_STATUS_SUCCESS; -} - -cairo_scan_converter_t * -_cairo_clip_tor_scan_converter_create (cairo_clip_t *clip, - cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias) -{ - cairo_clip_tor_scan_converter_t *self; - cairo_polygon_t clipper; - cairo_status_t status; - int i; - - self = calloc (1, sizeof(struct _cairo_clip_tor_scan_converter)); - if (unlikely (self == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto bail_nomem; - } - - self->base.destroy = _cairo_clip_tor_scan_converter_destroy; - self->base.generate = _cairo_clip_tor_scan_converter_generate; - - pool_init (self->span_pool.base, &self->jmp, - 250 * sizeof(self->span_pool.embedded[0]), - sizeof(self->span_pool.embedded)); - - _glitter_scan_converter_init (self->converter, &self->jmp); - status = glitter_scan_converter_reset (self->converter, - clip->extents.y, - clip->extents.y + clip->extents.height); - if (unlikely (status)) - goto bail; - - self->fill_rule = fill_rule; - self->antialias = antialias; - - for (i = 0; i < polygon->num_edges; i++) - glitter_scan_converter_add_edge (self->converter, - &polygon->edges[i], - FALSE); - - status = _cairo_clip_get_polygon (clip, - &clipper, - &self->clip_fill_rule, - &self->clip_antialias); - if (unlikely (status)) - goto bail; - - for (i = 0; i < clipper.num_edges; i++) - glitter_scan_converter_add_edge (self->converter, - &clipper.edges[i], - TRUE); - _cairo_polygon_fini (&clipper); - - return &self->base; - - bail: - self->base.destroy(&self->base); - bail_nomem: - return _cairo_scan_converter_create_in_error (status); -} - diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip.c deleted file mode 100644 index 0df9b06bf60..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-clip.c +++ /dev/null @@ -1,838 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-gstate-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-pattern-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-region-private.h" - -static freed_pool_t clip_path_pool; -static freed_pool_t clip_pool; - -const cairo_clip_t __cairo_clip_all; - -static cairo_clip_path_t * -_cairo_clip_path_create (cairo_clip_t *clip) -{ - cairo_clip_path_t *clip_path; - - clip_path = _freed_pool_get (&clip_path_pool); - if (unlikely (clip_path == NULL)) { - clip_path = malloc (sizeof (cairo_clip_path_t)); - if (unlikely (clip_path == NULL)) - return NULL; - } - - CAIRO_REFERENCE_COUNT_INIT (&clip_path->ref_count, 1); - - clip_path->prev = clip->path; - clip->path = clip_path; - - return clip_path; -} - -cairo_clip_path_t * -_cairo_clip_path_reference (cairo_clip_path_t *clip_path) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&clip_path->ref_count)); - - _cairo_reference_count_inc (&clip_path->ref_count); - - return clip_path; -} - -void -_cairo_clip_path_destroy (cairo_clip_path_t *clip_path) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&clip_path->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&clip_path->ref_count)) - return; - - _cairo_path_fixed_fini (&clip_path->path); - - if (clip_path->prev != NULL) - _cairo_clip_path_destroy (clip_path->prev); - - _freed_pool_put (&clip_path_pool, clip_path); -} - -cairo_clip_t * -_cairo_clip_create (void) -{ - cairo_clip_t *clip; - - clip = _freed_pool_get (&clip_pool); - if (unlikely (clip == NULL)) { - clip = malloc (sizeof (cairo_clip_t)); - if (unlikely (clip == NULL)) - return NULL; - } - - clip->extents = _cairo_unbounded_rectangle; - - clip->path = NULL; - clip->boxes = NULL; - clip->num_boxes = 0; - clip->region = NULL; - clip->is_region = FALSE; - - return clip; -} - -void -_cairo_clip_destroy (cairo_clip_t *clip) -{ - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return; - - if (clip->path != NULL) - _cairo_clip_path_destroy (clip->path); - - if (clip->boxes != &clip->embedded_box) - free (clip->boxes); - cairo_region_destroy (clip->region); - - _freed_pool_put (&clip_pool, clip); -} - -cairo_clip_t * -_cairo_clip_copy (const cairo_clip_t *clip) -{ - cairo_clip_t *copy; - - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return (cairo_clip_t *) clip; - - copy = _cairo_clip_create (); - - if (clip->path) - copy->path = _cairo_clip_path_reference (clip->path); - - if (clip->num_boxes) { - if (clip->num_boxes == 1) { - copy->boxes = ©->embedded_box; - } else { - copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t)); - if (unlikely (copy->boxes == NULL)) - return _cairo_clip_set_all_clipped (copy); - } - - memcpy (copy->boxes, clip->boxes, - clip->num_boxes * sizeof (cairo_box_t)); - copy->num_boxes = clip->num_boxes; - } - - copy->extents = clip->extents; - copy->region = cairo_region_reference (clip->region); - copy->is_region = clip->is_region; - - return copy; -} - -cairo_clip_t * -_cairo_clip_copy_path (const cairo_clip_t *clip) -{ - cairo_clip_t *copy; - - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return (cairo_clip_t *) clip; - - assert (clip->num_boxes); - - copy = _cairo_clip_create (); - copy->extents = clip->extents; - if (clip->path) - copy->path = _cairo_clip_path_reference (clip->path); - - return copy; -} - -cairo_clip_t * -_cairo_clip_copy_region (const cairo_clip_t *clip) -{ - cairo_clip_t *copy; - int i; - - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return (cairo_clip_t *) clip; - - assert (clip->num_boxes); - - copy = _cairo_clip_create (); - copy->extents = clip->extents; - - if (clip->num_boxes == 1) { - copy->boxes = ©->embedded_box; - } else { - copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t)); - if (unlikely (copy->boxes == NULL)) - return _cairo_clip_set_all_clipped (copy); - } - - for (i = 0; i < clip->num_boxes; i++) { - copy->boxes[i].p1.x = _cairo_fixed_floor (clip->boxes[i].p1.x); - copy->boxes[i].p1.y = _cairo_fixed_floor (clip->boxes[i].p1.y); - copy->boxes[i].p2.x = _cairo_fixed_ceil (clip->boxes[i].p2.x); - copy->boxes[i].p2.y = _cairo_fixed_ceil (clip->boxes[i].p2.y); - } - copy->num_boxes = clip->num_boxes; - - copy->region = cairo_region_reference (clip->region); - copy->is_region = TRUE; - - return copy; -} - -cairo_clip_t * -_cairo_clip_intersect_path (cairo_clip_t *clip, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_clip_path_t *clip_path; - cairo_status_t status; - cairo_rectangle_int_t extents; - cairo_box_t box; - - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - /* catch the empty clip path */ - if (_cairo_path_fixed_fill_is_empty (path)) - return _cairo_clip_set_all_clipped (clip); - - if (_cairo_path_fixed_is_box (path, &box)) { - if (antialias == CAIRO_ANTIALIAS_NONE) { - box.p1.x = _cairo_fixed_round_down (box.p1.x); - box.p1.y = _cairo_fixed_round_down (box.p1.y); - box.p2.x = _cairo_fixed_round_down (box.p2.x); - box.p2.y = _cairo_fixed_round_down (box.p2.y); - } - - return _cairo_clip_intersect_box (clip, &box); - } - if (_cairo_path_fixed_fill_is_rectilinear (path)) - return _cairo_clip_intersect_rectilinear_path (clip, path, - fill_rule, antialias); - - _cairo_path_fixed_approximate_clip_extents (path, &extents); - if (extents.width == 0 || extents.height == 0) - return _cairo_clip_set_all_clipped (clip); - - clip = _cairo_clip_intersect_rectangle (clip, &extents); - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - clip_path = _cairo_clip_path_create (clip); - if (unlikely (clip_path == NULL)) - return _cairo_clip_set_all_clipped (clip); - - status = _cairo_path_fixed_init_copy (&clip_path->path, path); - if (unlikely (status)) - return _cairo_clip_set_all_clipped (clip); - - clip_path->fill_rule = fill_rule; - clip_path->tolerance = tolerance; - clip_path->antialias = antialias; - - if (clip->region) { - cairo_region_destroy (clip->region); - clip->region = NULL; - } - - clip->is_region = FALSE; - return clip; -} - -static cairo_clip_t * -_cairo_clip_intersect_clip_path (cairo_clip_t *clip, - const cairo_clip_path_t *clip_path) -{ - if (clip_path->prev) - clip = _cairo_clip_intersect_clip_path (clip, clip_path->prev); - - return _cairo_clip_intersect_path (clip, - &clip_path->path, - clip_path->fill_rule, - clip_path->tolerance, - clip_path->antialias); -} - -cairo_clip_t * -_cairo_clip_intersect_clip (cairo_clip_t *clip, - const cairo_clip_t *other) -{ - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - if (other == NULL) - return clip; - - if (clip == NULL) - return _cairo_clip_copy (other); - - if (_cairo_clip_is_all_clipped (other)) - return _cairo_clip_set_all_clipped (clip); - - if (! _cairo_rectangle_intersect (&clip->extents, &other->extents)) - return _cairo_clip_set_all_clipped (clip); - - if (other->num_boxes) { - cairo_boxes_t boxes; - - _cairo_boxes_init_for_array (&boxes, other->boxes, other->num_boxes); - clip = _cairo_clip_intersect_boxes (clip, &boxes); - } - - if (! _cairo_clip_is_all_clipped (clip)) { - if (other->path) { - if (clip->path == NULL) - clip->path = _cairo_clip_path_reference (other->path); - else - clip = _cairo_clip_intersect_clip_path (clip, other->path); - } - } - - if (clip->region) { - cairo_region_destroy (clip->region); - clip->region = NULL; - } - clip->is_region = FALSE; - - return clip; -} - -cairo_bool_t -_cairo_clip_equal (const cairo_clip_t *clip_a, - const cairo_clip_t *clip_b) -{ - const cairo_clip_path_t *cp_a, *cp_b; - - /* are both all-clipped or no-clip? */ - if (clip_a == clip_b) - return TRUE; - - /* or just one of them? */ - if (clip_a == NULL || clip_b == NULL || - _cairo_clip_is_all_clipped (clip_a) || - _cairo_clip_is_all_clipped (clip_b)) - { - return FALSE; - } - - /* We have a pair of normal clips, check their contents */ - - if (clip_a->num_boxes != clip_b->num_boxes) - return FALSE; - - if (memcmp (clip_a->boxes, clip_b->boxes, - sizeof (cairo_box_t) * clip_a->num_boxes)) - return FALSE; - - cp_a = clip_a->path; - cp_b = clip_b->path; - while (cp_a && cp_b) { - if (cp_a == cp_b) - return TRUE; - - /* XXX compare reduced polygons? */ - - if (cp_a->antialias != cp_b->antialias) - return FALSE; - - if (cp_a->tolerance != cp_b->tolerance) - return FALSE; - - if (cp_a->fill_rule != cp_b->fill_rule) - return FALSE; - - if (! _cairo_path_fixed_equal (&cp_a->path, - &cp_b->path)) - return FALSE; - - cp_a = cp_a->prev; - cp_b = cp_b->prev; - } - - return cp_a == NULL && cp_b == NULL; -} - -static cairo_clip_t * -_cairo_clip_path_copy_with_translation (cairo_clip_t *clip, - cairo_clip_path_t *other_path, - int fx, int fy) -{ - cairo_status_t status; - cairo_clip_path_t *clip_path; - - if (other_path->prev != NULL) - clip = _cairo_clip_path_copy_with_translation (clip, other_path->prev, - fx, fy); - if (_cairo_clip_is_all_clipped (clip)) - return clip; - - clip_path = _cairo_clip_path_create (clip); - if (unlikely (clip_path == NULL)) - return _cairo_clip_set_all_clipped (clip); - - status = _cairo_path_fixed_init_copy (&clip_path->path, - &other_path->path); - if (unlikely (status)) - return _cairo_clip_set_all_clipped (clip); - - _cairo_path_fixed_translate (&clip_path->path, fx, fy); - - clip_path->fill_rule = other_path->fill_rule; - clip_path->tolerance = other_path->tolerance; - clip_path->antialias = other_path->antialias; - - return clip; -} - -cairo_clip_t * -_cairo_clip_translate (cairo_clip_t *clip, int tx, int ty) -{ - int fx, fy, i; - cairo_clip_path_t *clip_path; - - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return clip; - - if (tx == 0 && ty == 0) - return clip; - - fx = _cairo_fixed_from_int (tx); - fy = _cairo_fixed_from_int (ty); - - for (i = 0; i < clip->num_boxes; i++) { - clip->boxes[i].p1.x += fx; - clip->boxes[i].p2.x += fx; - clip->boxes[i].p1.y += fy; - clip->boxes[i].p2.y += fy; - } - - clip->extents.x += tx; - clip->extents.y += ty; - - if (clip->path == NULL) - return clip; - - clip_path = clip->path; - clip->path = NULL; - clip = _cairo_clip_path_copy_with_translation (clip, clip_path, fx, fy); - _cairo_clip_path_destroy (clip_path); - - return clip; -} - -static cairo_status_t -_cairo_path_fixed_add_box (cairo_path_fixed_t *path, - const cairo_box_t *box) -{ - cairo_status_t status; - - status = _cairo_path_fixed_move_to (path, box->p1.x, box->p1.y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p2.x, box->p1.y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p2.x, box->p2.y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p1.x, box->p2.y); - if (unlikely (status)) - return status; - - return _cairo_path_fixed_close_path (path); -} - -static cairo_status_t -_cairo_path_fixed_init_from_boxes (cairo_path_fixed_t *path, - const cairo_boxes_t *boxes) -{ - cairo_status_t status; - const struct _cairo_boxes_chunk *chunk; - int i; - - _cairo_path_fixed_init (path); - if (boxes->num_boxes == 0) - return CAIRO_STATUS_SUCCESS; - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - status = _cairo_path_fixed_add_box (path, &chunk->base[i]); - if (unlikely (status)) { - _cairo_path_fixed_fini (path); - return status; - } - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_clip_t * -_cairo_clip_intersect_clip_path_transformed (cairo_clip_t *clip, - const cairo_clip_path_t *clip_path, - const cairo_matrix_t *m) -{ - cairo_path_fixed_t path; - - if (clip_path->prev) - clip = _cairo_clip_intersect_clip_path_transformed (clip, - clip_path->prev, - m); - - if (_cairo_path_fixed_init_copy (&path, &clip_path->path)) - return _cairo_clip_set_all_clipped (clip); - - _cairo_path_fixed_transform (&path, m); - - clip = _cairo_clip_intersect_path (clip, - &path, - clip_path->fill_rule, - clip_path->tolerance, - clip_path->antialias); - _cairo_path_fixed_fini (&path); - - return clip; -} - -cairo_clip_t * -_cairo_clip_transform (cairo_clip_t *clip, const cairo_matrix_t *m) -{ - cairo_clip_t *copy; - - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return clip; - - if (_cairo_matrix_is_translation (m)) - return _cairo_clip_translate (clip, m->x0, m->y0); - - copy = _cairo_clip_create (); - - if (clip->num_boxes) { - cairo_path_fixed_t path; - cairo_boxes_t boxes; - - _cairo_boxes_init_for_array (&boxes, clip->boxes, clip->num_boxes); - _cairo_path_fixed_init_from_boxes (&path, &boxes); - _cairo_path_fixed_transform (&path, m); - - copy = _cairo_clip_intersect_path (copy, &path, - CAIRO_FILL_RULE_WINDING, - 0.1, - CAIRO_ANTIALIAS_DEFAULT); - - _cairo_path_fixed_fini (&path); - } - - if (clip->path) - copy = _cairo_clip_intersect_clip_path_transformed (copy, clip->path,m); - - _cairo_clip_destroy (clip); - return copy; -} - -cairo_clip_t * -_cairo_clip_copy_with_translation (const cairo_clip_t *clip, int tx, int ty) -{ - cairo_clip_t *copy; - int fx, fy, i; - - if (clip == NULL || _cairo_clip_is_all_clipped (clip)) - return (cairo_clip_t *)clip; - - if (tx == 0 && ty == 0) - return _cairo_clip_copy (clip); - - copy = _cairo_clip_create (); - if (copy == NULL) - return _cairo_clip_set_all_clipped (copy); - - fx = _cairo_fixed_from_int (tx); - fy = _cairo_fixed_from_int (ty); - - if (clip->num_boxes) { - if (clip->num_boxes == 1) { - copy->boxes = ©->embedded_box; - } else { - copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t)); - if (unlikely (copy->boxes == NULL)) - return _cairo_clip_set_all_clipped (copy); - } - - for (i = 0; i < clip->num_boxes; i++) { - copy->boxes[i].p1.x = clip->boxes[i].p1.x + fx; - copy->boxes[i].p2.x = clip->boxes[i].p2.x + fx; - copy->boxes[i].p1.y = clip->boxes[i].p1.y + fy; - copy->boxes[i].p2.y = clip->boxes[i].p2.y + fy; - } - copy->num_boxes = clip->num_boxes; - } - - copy->extents = clip->extents; - copy->extents.x += tx; - copy->extents.y += ty; - - if (clip->path == NULL) - return copy; - - return _cairo_clip_path_copy_with_translation (copy, clip->path, fx, fy); -} - -cairo_bool_t -_cairo_clip_contains_extents (const cairo_clip_t *clip, - const cairo_composite_rectangles_t *extents) -{ - const cairo_rectangle_int_t *rect; - - rect = extents->is_bounded ? &extents->bounded : &extents->unbounded; - return _cairo_clip_contains_rectangle (clip, rect); -} - -void -_cairo_debug_print_clip (FILE *stream, const cairo_clip_t *clip) -{ - int i; - - if (clip == NULL) { - fprintf (stream, "no clip\n"); - return; - } - - if (_cairo_clip_is_all_clipped (clip)) { - fprintf (stream, "clip: all-clipped\n"); - return; - } - - fprintf (stream, "clip:\n"); - fprintf (stream, " extents: (%d, %d) x (%d, %d), is-region? %d", - clip->extents.x, clip->extents.y, - clip->extents.width, clip->extents.height, - clip->is_region); - - fprintf (stream, " num_boxes = %d\n", clip->num_boxes); - for (i = 0; i < clip->num_boxes; i++) { - fprintf (stream, " [%d] = (%f, %f), (%f, %f)\n", i, - _cairo_fixed_to_double (clip->boxes[i].p1.x), - _cairo_fixed_to_double (clip->boxes[i].p1.y), - _cairo_fixed_to_double (clip->boxes[i].p2.x), - _cairo_fixed_to_double (clip->boxes[i].p2.y)); - } - - if (clip->path) { - cairo_clip_path_t *clip_path = clip->path; - do { - fprintf (stream, "path: aa=%d, tolerance=%f, rule=%d: ", - clip_path->antialias, - clip_path->tolerance, - clip_path->fill_rule); - _cairo_debug_print_path (stream, &clip_path->path); - fprintf (stream, "\n"); - } while ((clip_path = clip_path->prev) != NULL); - } -} - -const cairo_rectangle_int_t * -_cairo_clip_get_extents (const cairo_clip_t *clip) -{ - if (clip == NULL) - return &_cairo_unbounded_rectangle; - - if (_cairo_clip_is_all_clipped (clip)) - return &_cairo_empty_rectangle; - - return &clip->extents; -} - -const cairo_rectangle_list_t _cairo_rectangles_nil = - { CAIRO_STATUS_NO_MEMORY, NULL, 0 }; -static const cairo_rectangle_list_t _cairo_rectangles_not_representable = - { CAIRO_STATUS_CLIP_NOT_REPRESENTABLE, NULL, 0 }; - -static cairo_bool_t -_cairo_clip_int_rect_to_user (cairo_gstate_t *gstate, - cairo_rectangle_int_t *clip_rect, - cairo_rectangle_t *user_rect) -{ - cairo_bool_t is_tight; - - double x1 = clip_rect->x; - double y1 = clip_rect->y; - double x2 = clip_rect->x + (int) clip_rect->width; - double y2 = clip_rect->y + (int) clip_rect->height; - - _cairo_gstate_backend_to_user_rectangle (gstate, - &x1, &y1, &x2, &y2, - &is_tight); - - user_rect->x = x1; - user_rect->y = y1; - user_rect->width = x2 - x1; - user_rect->height = y2 - y1; - - return is_tight; -} - -cairo_rectangle_list_t * -_cairo_rectangle_list_create_in_error (cairo_status_t status) -{ - cairo_rectangle_list_t *list; - - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_rectangle_list_t*) &_cairo_rectangles_nil; - if (status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) - return (cairo_rectangle_list_t*) &_cairo_rectangles_not_representable; - - list = malloc (sizeof (*list)); - if (unlikely (list == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_rectangle_list_t*) &_cairo_rectangles_nil; - } - - list->status = status; - list->rectangles = NULL; - list->num_rectangles = 0; - - return list; -} - -cairo_rectangle_list_t * -_cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate) -{ -#define ERROR_LIST(S) _cairo_rectangle_list_create_in_error (_cairo_error (S)) - - cairo_rectangle_list_t *list; - cairo_rectangle_t *rectangles = NULL; - cairo_region_t *region = NULL; - int n_rects = 0; - int i; - - if (clip == NULL) - return ERROR_LIST (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE); - - if (_cairo_clip_is_all_clipped (clip)) - goto DONE; - - if (! _cairo_clip_is_region (clip)) - return ERROR_LIST (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE); - - region = _cairo_clip_get_region (clip); - if (region == NULL) - return ERROR_LIST (CAIRO_STATUS_NO_MEMORY); - - n_rects = cairo_region_num_rectangles (region); - if (n_rects) { - rectangles = _cairo_malloc_ab (n_rects, sizeof (cairo_rectangle_t)); - if (unlikely (rectangles == NULL)) { - return ERROR_LIST (CAIRO_STATUS_NO_MEMORY); - } - - for (i = 0; i < n_rects; ++i) { - cairo_rectangle_int_t clip_rect; - - cairo_region_get_rectangle (region, i, &clip_rect); - - if (! _cairo_clip_int_rect_to_user (gstate, - &clip_rect, - &rectangles[i])) - { - free (rectangles); - return ERROR_LIST (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE); - } - } - } - - DONE: - list = malloc (sizeof (cairo_rectangle_list_t)); - if (unlikely (list == NULL)) { - free (rectangles); - return ERROR_LIST (CAIRO_STATUS_NO_MEMORY); - } - - list->status = CAIRO_STATUS_SUCCESS; - list->rectangles = rectangles; - list->num_rectangles = n_rects; - return list; - -#undef ERROR_LIST -} - -/** - * cairo_rectangle_list_destroy: - * @rectangle_list: a rectangle list, as obtained from cairo_copy_clip_rectangle_list() - * - * Unconditionally frees @rectangle_list and all associated - * references. After this call, the @rectangle_list pointer must not - * be dereferenced. - * - * Since: 1.4 - **/ -void -cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list) -{ - if (rectangle_list == NULL || rectangle_list == &_cairo_rectangles_nil || - rectangle_list == &_cairo_rectangles_not_representable) - return; - - free (rectangle_list->rectangles); - free (rectangle_list); -} - -void -_cairo_clip_reset_static_data (void) -{ - _freed_pool_reset (&clip_path_pool); - _freed_pool_reset (&clip_pool); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context-private.h deleted file mode 100644 index 0a7185ef1f5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context-private.h +++ /dev/null @@ -1,52 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ - -#ifndef CAIRO_COGL_CONTEXT_PRIVATE_H -#define CAIRO_COGL_CONTEXT_PRIVATE_H - -#include "cairo-default-context-private.h" -#include "cairo-cogl-private.h" - -typedef struct _cairo_cogl_context { - cairo_default_context_t base; - - cairo_cogl_device_t *dev; - int path_ctm_age; - cairo_path_fixed_t user_path; - - cairo_bool_t path_is_rectangle; - double x, y, width, height; -} cairo_cogl_context_t; - -cairo_t * -_cairo_cogl_context_create (void *target); - -#endif /* CAIRO_COGL_CONTEXT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context.c deleted file mode 100644 index 0116b0a5a93..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-context.c +++ /dev/null @@ -1,822 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ - -/* so long as we can verify that the ctm doesn't change multiple times - * during the construction of a path we can build a shadow - * #cairo_path_fixed_t in user coordinates that we can use to create a - * hash value for caching tessellations of that path. - * - * We need to hook into all the points where the ctm can be changed - * so we can bump a cr->path_ctm_age counter. - * - * We need to hook into all the points where the path can be modified - * so we can catch the start of a path and reset the cr->path_ctm_age - * counter at that point. - * - * When a draw operation is hit we can then check that the - * path_ctm_age == 0 and if so we create a hash of the path. - * - * We use this hash to lookup a #cairo_cogl_path_meta_t struct which - * may contain tessellated triangles for the path or may just contain - * a count of how many times the path has been re-seen (we only cache - * tessellated triangles if there is evidence that the path is being - * used multiple times because there is a cost involved in allocating - * a separate buffer for the triangles). - */ - -#include "cairoint.h" - -#include "cairo-cogl-context-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-arc-private.h" -#include "cairo-path-fixed-private.h" - -#include - -static freed_pool_t context_pool; - -void -_cairo_cogl_context_reset_static_data (void) -{ - _freed_pool_reset (&context_pool); -} - -static cairo_status_t -_cairo_cogl_context_rectangle_real (cairo_cogl_context_t *cr, - double x, double y, - double width, double height) -{ - cairo_status_t status; - status = cr->dev->backend_parent.rectangle (cr, x, y, width, height); - if (unlikely (status)) - return status; - - return _cairo_cogl_path_fixed_rectangle (&cr->user_path, - _cairo_fixed_from_double (x), - _cairo_fixed_from_double (y), - _cairo_fixed_from_double (width), - _cairo_fixed_from_double (height)); -} - -/* The idea here is that we have a simplified way of tracking rectangle paths - * because rectangles are perhaps the most common shape drawn with cairo. - * - * Basically we have a speculative store for a rectangle path that doesn't - * need to use the #cairo_path_fixed_t api to describe a rectangle in terms of - * (move_to,rel_line_to,rel_line_to,_rel_line_to,close) because if you profile - * heavy rectangle drawing with Cairo that process can be overly expensive. - * - * If the user asks to add more than just a rectangle to their current path - * then we "flush" any speculative rectangle stored into the current path - * before continuing to append their operations. - * - * In addition to the speculative store cairo-cogl also has a fast-path - * fill_rectangle drawing operation that further aims to minimize the cost - * of drawing rectangles. - */ -static cairo_status_t -_flush_cr_rectangle (cairo_cogl_context_t *cr) -{ - if (!cr->path_is_rectangle) - return CAIRO_STATUS_SUCCESS; - - cr->path_is_rectangle = FALSE; - return _cairo_cogl_context_rectangle_real (cr, cr->x, cr->y, cr->width, cr->height); -} - -static cairo_status_t -_cairo_cogl_context_restore (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.restore (abstract_cr); -} - -static cairo_status_t -_cairo_cogl_context_translate (void *abstract_cr, double tx, double ty) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.translate (abstract_cr, tx, ty); -} - -static cairo_status_t -_cairo_cogl_context_scale (void *abstract_cr, double sx, double sy) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.scale (abstract_cr, sx, sy); -} - -static cairo_status_t -_cairo_cogl_context_rotate (void *abstract_cr, double theta) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.rotate (abstract_cr, theta); -} - -static cairo_status_t -_cairo_cogl_context_transform (void *abstract_cr, const cairo_matrix_t *matrix) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.transform (abstract_cr, matrix); -} - -static cairo_status_t -_cairo_cogl_context_set_matrix (void *abstract_cr, const cairo_matrix_t *matrix) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.set_matrix (abstract_cr, matrix); -} - -static cairo_status_t -_cairo_cogl_context_set_identity_matrix (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - cr->path_ctm_age++; - return cr->dev->backend_parent.set_identity_matrix (abstract_cr); -} - -static cairo_status_t -_cairo_cogl_context_new_path (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.new_path (abstract_cr); - if (unlikely (status)) - return status; - - _cairo_path_fixed_fini (&cr->user_path); - _cairo_path_fixed_init (&cr->user_path); - cr->path_is_rectangle = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_context_new_sub_path (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.new_sub_path (abstract_cr); - if (unlikely (status)) - return status; - - _cairo_path_fixed_new_sub_path (&cr->user_path); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_context_move_to (void *abstract_cr, double x, double y) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_fixed_t x_fixed, y_fixed; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.move_to (abstract_cr, x, y); - if (unlikely (status)) - return status; - - x_fixed = _cairo_fixed_from_double (x); - y_fixed = _cairo_fixed_from_double (y); - - return _cairo_path_fixed_move_to (&cr->user_path, x_fixed, y_fixed); -} - -static cairo_status_t -_cairo_cogl_context_line_to (void *abstract_cr, double x, double y) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_fixed_t x_fixed, y_fixed; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.line_to (abstract_cr, x, y); - if (unlikely (status)) - return status; - - x_fixed = _cairo_fixed_from_double (x); - y_fixed = _cairo_fixed_from_double (y); - - if (cr->user_path.buf.base.num_ops == 0) - cr->path_ctm_age = 0; - - return _cairo_path_fixed_line_to (&cr->user_path, x_fixed, y_fixed); -} - -static cairo_status_t -_cairo_cogl_context_curve_to (void *abstract_cr, - double x1, double y1, - double x2, double y2, - double x3, double y3) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_fixed_t x1_fixed, y1_fixed; - cairo_fixed_t x2_fixed, y2_fixed; - cairo_fixed_t x3_fixed, y3_fixed; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.curve_to (abstract_cr, x1, y1, x2, y2, x3, y3); - if (unlikely (status)) - return status; - - x1_fixed = _cairo_fixed_from_double (x1); - y1_fixed = _cairo_fixed_from_double (y1); - - x2_fixed = _cairo_fixed_from_double (x2); - y2_fixed = _cairo_fixed_from_double (y2); - - x3_fixed = _cairo_fixed_from_double (x3); - y3_fixed = _cairo_fixed_from_double (y3); - - if (cr->user_path.buf.base.num_ops == 0) - cr->path_ctm_age = 0; - - return _cairo_path_fixed_curve_to (&cr->user_path, - x1_fixed, y1_fixed, - x2_fixed, y2_fixed, - x3_fixed, y3_fixed); -} - -static cairo_status_t -_cairo_cogl_context_arc (void *abstract_cr, - double xc, double yc, double radius, - double angle1, double angle2, - cairo_bool_t forward) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.arc (abstract_cr, xc, yc, radius, angle1, angle2, forward); - if (unlikely (status)) - return status; - - if (cr->user_path.buf.base.num_ops == 0) - cr->path_ctm_age = 0; - - /* Do nothing, successfully, if radius is <= 0 */ - if (radius <= 0.0) { - cairo_fixed_t x_fixed, y_fixed; - - x_fixed = _cairo_fixed_from_double (xc); - y_fixed = _cairo_fixed_from_double (yc); - status = _cairo_path_fixed_line_to (&cr->user_path, x_fixed, y_fixed); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (&cr->user_path, x_fixed, y_fixed); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; - } - - status = _cairo_cogl_context_line_to (cr, - xc + radius * cos (angle1), - yc + radius * sin (angle1)); - - if (unlikely (status)) - return status; - - if (forward) - _cairo_arc_path (&cr->base.base, xc, yc, radius, angle1, angle2); - else - _cairo_arc_path_negative (&cr->base.base, xc, yc, radius, angle1, angle2); - - return CAIRO_STATUS_SUCCESS; /* any error will have already been set on cr */ -} - -static cairo_status_t -_cairo_cogl_context_rel_move_to (void *abstract_cr, double dx, double dy) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_fixed_t dx_fixed, dy_fixed; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.rel_move_to (abstract_cr, dx, dy); - if (unlikely (status)) - return status; - - dx_fixed = _cairo_fixed_from_double (dx); - dy_fixed = _cairo_fixed_from_double (dy); - - return _cairo_path_fixed_rel_move_to (&cr->user_path, dx_fixed, dy_fixed); -} - -static cairo_status_t -_cairo_cogl_context_rel_line_to (void *abstract_cr, double dx, double dy) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_fixed_t dx_fixed, dy_fixed; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.rel_line_to (abstract_cr, dx, dy); - if (unlikely (status)) - return status; - - dx_fixed = _cairo_fixed_from_double (dx); - dy_fixed = _cairo_fixed_from_double (dy); - - if (cr->user_path.buf.base.num_ops == 0) - cr->path_ctm_age = 0; - - return _cairo_path_fixed_rel_line_to (&cr->user_path, dx_fixed, dy_fixed); -} - - -static cairo_status_t -_cairo_cogl_context_rel_curve_to (void *abstract_cr, - double dx1, double dy1, - double dx2, double dy2, - double dx3, double dy3) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_fixed_t dx1_fixed, dy1_fixed; - cairo_fixed_t dx2_fixed, dy2_fixed; - cairo_fixed_t dx3_fixed, dy3_fixed; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.rel_curve_to (abstract_cr, dx1, dy1, dx2, dy2, dx3, dy3); - if (unlikely (status)) - return status; - - dx1_fixed = _cairo_fixed_from_double (dx1); - dy1_fixed = _cairo_fixed_from_double (dy1); - - dx2_fixed = _cairo_fixed_from_double (dx2); - dy2_fixed = _cairo_fixed_from_double (dy2); - - dx3_fixed = _cairo_fixed_from_double (dx3); - dy3_fixed = _cairo_fixed_from_double (dy3); - - if (cr->user_path.buf.base.num_ops == 0) - cr->path_ctm_age = 0; - - return _cairo_path_fixed_rel_curve_to (&cr->user_path, - dx1_fixed, dy1_fixed, - dx2_fixed, dy2_fixed, - dx3_fixed, dy3_fixed); -} - -#if 0 -static cairo_status_t -_cairo_cogl_context_arc_to (void *abstract_cr, - double x1, double y1, - double x2, double y2, - double radius) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.arc_to (abstract_cr, x1, y1, x2, y2, radius); - if (unlikely (status)) - return status; -#warning "FIXME" -} - -static cairo_status_t -_cairo_cogl_rel_arc_to (void *cr, - double dx1, double dy1, - double dx2, double dy2, - double radius) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.rel_arc_to (abstract_cr, dx1, dy2, dx2, dy2, radius); - if (unlikely (status)) - return status; -#warning "FIXME" -} -#endif - -static cairo_status_t -_cairo_cogl_context_close_path (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - if (cr->path_is_rectangle) { - status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - status = cr->dev->backend_parent.close_path (abstract_cr); - if (unlikely (status)) - return status; - - if (cr->user_path.buf.base.num_ops == 0) - cr->path_ctm_age = 0; - - return _cairo_path_fixed_close_path (&cr->user_path); -} - -static cairo_status_t -_cairo_cogl_context_rectangle (void *abstract_cr, - double x, double y, - double width, double height) -{ - cairo_cogl_context_t *cr = abstract_cr; - - if (cr->user_path.buf.base.num_ops == 0) { - cr->path_ctm_age = 0; - -#if 1 - /* XXX: Since drawing rectangles is so common we have a - * fast-path for drawing a single rectangle. */ - cr->x = x; - cr->y = y; - cr->width = width; - cr->height = height; - cr->path_is_rectangle = TRUE; - return CAIRO_STATUS_SUCCESS; -#endif - } - - if (cr->path_is_rectangle) { - cairo_status_t status = _flush_cr_rectangle (cr); - if (unlikely (status)) - return status; - } - - return _cairo_cogl_context_rectangle_real (cr, x, y, width, height); -} - -/* Since the surface backend drawing operator functions don't get - * passed the current #cairo_t context we don't have a good way - * to get our user-coordinates path into our surface operator - * functions. - * - * For now we use this function to set side band data on the surface - * itself. - */ -static void -_cairo_cogl_surface_set_side_band_state (cairo_cogl_surface_t *surface, - cairo_cogl_context_t *cr) -{ - - if (cr->path_ctm_age <= 1) { - surface->user_path = &cr->user_path; - surface->ctm = &cr->base.gstate->ctm; - surface->ctm_inverse = &cr->base.gstate->ctm_inverse; - surface->path_is_rectangle = cr->path_is_rectangle; - if (surface->path_is_rectangle) { - surface->path_rectangle_x = cr->x; - surface->path_rectangle_y = cr->y; - surface->path_rectangle_width = cr->width; - surface->path_rectangle_height = cr->height; - } - } else { - surface->user_path = NULL; - surface->path_is_rectangle = FALSE; - } -} - -static cairo_status_t -_cairo_cogl_context_fill (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; - - if (cr->path_is_rectangle) { - status = _cairo_cogl_surface_fill_rectangle (cr->base.gstate->target, - cr->base.gstate->op, - cr->base.gstate->source, - cr->x, - cr->y, - cr->width, - cr->height, - &cr->base.gstate->ctm, - cr->base.gstate->clip); - if (status == CAIRO_STATUS_SUCCESS) - goto DONE; - _flush_cr_rectangle (cr); - } - - _cairo_cogl_surface_set_side_band_state (surface, cr); - - status = cr->dev->backend_parent.fill (abstract_cr); - if (unlikely (status)) - return status; - -DONE: - _cairo_path_fixed_fini (&cr->user_path); - _cairo_path_fixed_init (&cr->user_path); - cr->path_is_rectangle = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_context_fill_preserve (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; - - _cairo_cogl_surface_set_side_band_state (surface, cr); - - status = cr->dev->backend_parent.fill_preserve (abstract_cr); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_context_stroke (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; - - _cairo_cogl_surface_set_side_band_state (surface, cr); - - status = cr->dev->backend_parent.stroke (abstract_cr); - if (unlikely (status)) - return status; - - _cairo_path_fixed_fini (&cr->user_path); - _cairo_path_fixed_init (&cr->user_path); - cr->path_is_rectangle = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_context_stroke_preserve (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; - - _cairo_cogl_surface_set_side_band_state (surface, cr); - - status = cr->dev->backend_parent.stroke_preserve (abstract_cr); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_context_clip (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - cairo_status_t status; - - status = cr->dev->backend_parent.clip (abstract_cr); - if (unlikely (status)) - return status; - - _cairo_path_fixed_fini (&cr->user_path); - _cairo_path_fixed_init (&cr->user_path); - cr->path_is_rectangle = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_cogl_context_destroy (void *abstract_cr) -{ - cairo_cogl_context_t *cr = abstract_cr; - - _cairo_default_context_fini (&cr->base); - - _cairo_path_fixed_fini (&cr->user_path); - - /* mark the context as invalid to protect against misuse */ - cr->base.base.status = CAIRO_STATUS_NULL_POINTER; - _freed_pool_put (&context_pool, cr); -} - -/* We want to hook into the frontend of the path construction APIs so - * we can build up a path description in user coordinates instead of - * backend coordinates so that we can recognize user coordinate - * rectangles and so we can hash a user path independent of its - * transform. (With some care to catch unusual cases where the ctm - * changes mid-path) */ -cairo_t * -_cairo_cogl_context_create (void *target) -{ - cairo_cogl_surface_t *surface = target; - cairo_cogl_context_t *cr; - cairo_status_t status; - - cr = _freed_pool_get (&context_pool); - if (unlikely (cr == NULL)) { - cr = malloc (sizeof (cairo_cogl_context_t)); - if (unlikely (cr == NULL)) - return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - status = _cairo_default_context_init (&cr->base, target); - if (unlikely (status)) { - _freed_pool_put (&context_pool, cr); - return _cairo_create_in_error (status); - } - - cr->dev = (cairo_cogl_device_t *)surface->base.device; - - if (unlikely (cr->dev->backend_vtable_initialized == FALSE)) { - cairo_backend_t *backend = &cr->dev->backend; - memcpy (backend, cr->base.base.backend, sizeof (cairo_backend_t)); - memcpy (&cr->dev->backend_parent, cr->base.base.backend, sizeof (cairo_backend_t)); - - backend->destroy = _cairo_cogl_context_destroy; - - backend->restore = _cairo_cogl_context_restore; - backend->translate = _cairo_cogl_context_translate; - backend->scale = _cairo_cogl_context_scale; - backend->rotate = _cairo_cogl_context_rotate; - backend->transform = _cairo_cogl_context_transform; - backend->set_matrix = _cairo_cogl_context_set_matrix; - backend->set_identity_matrix = _cairo_cogl_context_set_identity_matrix; - - backend->new_path = _cairo_cogl_context_new_path; - backend->new_sub_path = _cairo_cogl_context_new_sub_path; - backend->move_to = _cairo_cogl_context_move_to; - backend->rel_move_to = _cairo_cogl_context_rel_move_to; - backend->line_to = _cairo_cogl_context_line_to; - backend->rel_line_to = _cairo_cogl_context_rel_line_to; - backend->curve_to = _cairo_cogl_context_curve_to; - backend->rel_curve_to = _cairo_cogl_context_rel_curve_to; -#if 0 - backend->arc_to = _cairo_cogl_context_arc_to; - backend->rel_arc_to = _cairo_cogl_context_rel_arc_to; -#endif - backend->close_path = _cairo_cogl_context_close_path; - //backend->arc = _cairo_cogl_context_arc; - backend->rectangle = _cairo_cogl_context_rectangle; - - /* Try to automatically catch if any new path APIs are added that mean - * we may need to overload more functions... */ - assert (((char *)&backend->path_extents - (char *)&backend->device_to_user_distance) - == (sizeof (void *) * 14)); - - backend->fill = _cairo_cogl_context_fill; - backend->fill_preserve = _cairo_cogl_context_fill_preserve; - backend->stroke = _cairo_cogl_context_stroke; - backend->stroke_preserve = _cairo_cogl_context_stroke_preserve; - backend->clip = _cairo_cogl_context_clip; - - cr->dev->backend_vtable_initialized = TRUE; - } - - cr->base.base.backend = &cr->dev->backend; - - _cairo_path_fixed_init (&cr->user_path); - cr->path_is_rectangle = FALSE; - - return &cr->base.base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient-private.h deleted file mode 100644 index fa684d2c6b0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient-private.h +++ /dev/null @@ -1,89 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ - -#ifndef CAIRO_COGL_GRADIENT_PRIVATE_H -#define CAIRO_COGL_GRADIENT_PRIVATE_H - -#include "cairoint.h" -#include "cairo-pattern-private.h" - -#include - -#define CAIRO_COGL_LINEAR_GRADIENT_CACHE_SIZE (1024 * 1024) - -typedef enum _cairo_cogl_gradient_compatibility { - CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD = 1<<0, - CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT = 1<<1, - CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT = 1<<2, - CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE = 1<<3 -} cairo_cogl_gradient_compatibility_t; -#define CAIRO_COGL_GRADIENT_CAN_EXTEND_ALL (CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD |\ - CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT|\ - CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT|\ - CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE) - -typedef struct _cairo_cogl_linear_texture_entry { - cairo_cogl_gradient_compatibility_t compatibility; - CoglTexture *texture; - float translate_x; - float scale_x; -} cairo_cogl_linear_texture_entry_t; - -typedef struct _cairo_cogl_linear_gradient { - cairo_cache_entry_t cache_entry; - cairo_reference_count_t ref_count; - GList *textures; - int n_stops; - const cairo_gradient_stop_t *stops; - cairo_gradient_stop_t stops_embedded[1]; -} cairo_cogl_linear_gradient_t; - -cairo_int_status_t -_cairo_cogl_get_linear_gradient (cairo_cogl_device_t *context, - cairo_extend_t extend_mode, - int n_stops, - const cairo_gradient_stop_t *stops, - cairo_cogl_linear_gradient_t **gradient_out); - -cairo_cogl_linear_texture_entry_t * -_cairo_cogl_linear_gradient_texture_for_extend (cairo_cogl_linear_gradient_t *gradient, - cairo_extend_t extend_mode); - -cairo_cogl_linear_gradient_t * -_cairo_cogl_linear_gradient_reference (cairo_cogl_linear_gradient_t *gradient); - -void -_cairo_cogl_linear_gradient_destroy (cairo_cogl_linear_gradient_t *gradient); - -cairo_bool_t -_cairo_cogl_linear_gradient_equal (const void *key_a, const void *key_b); - -#endif /* CAIRO_COGL_GRADIENT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient.c deleted file mode 100644 index f8c80041629..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-gradient.c +++ /dev/null @@ -1,642 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ -//#include "cairoint.h" - -#include "cairo-cogl-private.h" -#include "cairo-cogl-gradient-private.h" -#include "cairo-image-surface-private.h" - -#include -#include - -#define DUMP_GRADIENTS_TO_PNG - -static unsigned long -_cairo_cogl_linear_gradient_hash (unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - return _cairo_hash_bytes (n_stops, stops, - sizeof (cairo_gradient_stop_t) * n_stops); -} - -static cairo_cogl_linear_gradient_t * -_cairo_cogl_linear_gradient_lookup (cairo_cogl_device_t *ctx, - unsigned long hash, - unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - cairo_cogl_linear_gradient_t lookup; - - lookup.cache_entry.hash = hash, - lookup.n_stops = n_stops; - lookup.stops = stops; - - return _cairo_cache_lookup (&ctx->linear_cache, &lookup.cache_entry); -} - -cairo_bool_t -_cairo_cogl_linear_gradient_equal (const void *key_a, const void *key_b) -{ - const cairo_cogl_linear_gradient_t *a = key_a; - const cairo_cogl_linear_gradient_t *b = key_b; - - if (a->n_stops != b->n_stops) - return FALSE; - - return memcmp (a->stops, b->stops, a->n_stops * sizeof (cairo_gradient_stop_t)) == 0; -} - -cairo_cogl_linear_gradient_t * -_cairo_cogl_linear_gradient_reference (cairo_cogl_linear_gradient_t *gradient) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); - - _cairo_reference_count_inc (&gradient->ref_count); - - return gradient; -} - -void -_cairo_cogl_linear_gradient_destroy (cairo_cogl_linear_gradient_t *gradient) -{ - GList *l; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&gradient->ref_count)) - return; - - for (l = gradient->textures; l; l = l->next) { - cairo_cogl_linear_texture_entry_t *entry = l->data; - cogl_object_unref (entry->texture); - free (entry); - } - g_list_free (gradient->textures); - - free (gradient); -} - -static int -_cairo_cogl_util_next_p2 (int a) -{ - int rval = 1; - - while (rval < a) - rval <<= 1; - - return rval; -} - -static float -get_max_color_component_range (const cairo_color_stop_t *color0, const cairo_color_stop_t *color1) -{ - float range; - float max = 0; - - range = fabs (color0->red - color1->red); - max = MAX (range, max); - range = fabs (color0->green - color1->green); - max = MAX (range, max); - range = fabs (color0->blue - color1->blue); - max = MAX (range, max); - range = fabs (color0->alpha - color1->alpha); - max = MAX (range, max); - - return max; -} - -static int -_cairo_cogl_linear_gradient_width_for_stops (cairo_extend_t extend, - unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - unsigned int n; - float max_texels_per_unit_offset = 0; - float total_offset_range; - - /* Find the stop pair demanding the most precision because we are - * interpolating the largest color-component range. - * - * From that we can define the relative sizes of all the other - * stop pairs within our texture and thus the overall size. - * - * To determine the maximum number of texels for a given gap we - * look at the range of colors we are expected to interpolate (so - * long as the stop offsets are not degenerate) and we simply - * assume we want one texel for each unique color value possible - * for a one byte-per-component representation. - * XXX: maybe this is overkill and just allowing 128 levels - * instead of 256 would be enough and then we'd rely on the - * bilinear filtering to give the full range. - * - * XXX: potentially we could try and map offsets to pixels to come - * up with a more precise mapping, but we are aiming to cache - * the gradients so we can't make assumptions about how it will be - * scaled in the future. - */ - for (n = 1; n < n_stops; n++) { - float color_range; - float offset_range; - float texels; - float texels_per_unit_offset; - - /* note: degenerate stops don't need to be represented in the - * texture but we want to be sure that solid gaps get at least - * one texel and all other gaps get at least 2 texels. - */ - - if (stops[n].offset == stops[n-1].offset) - continue; - - color_range = get_max_color_component_range (&stops[n].color, &stops[n-1].color); - if (color_range == 0) - texels = 1; - else - texels = MAX (2, 256.0f * color_range); - - /* So how many texels would we need to map over the full [0,1] - * gradient range so this gap would have enough texels? ... */ - offset_range = stops[n].offset - stops[n - 1].offset; - texels_per_unit_offset = texels / offset_range; - - if (texels_per_unit_offset > max_texels_per_unit_offset) - max_texels_per_unit_offset = texels_per_unit_offset; - } - - total_offset_range = fabs (stops[n_stops - 1].offset - stops[0].offset); - return max_texels_per_unit_offset * total_offset_range; -} - -/* Aim to create gradient textures without an alpha component so we can avoid - * needing to use blending... */ -static CoglPixelFormat -_cairo_cogl_linear_gradient_format_for_stops (cairo_extend_t extend, - unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - unsigned int n; - - /* We have to add extra transparent texels to the end of the gradient to - * handle CAIRO_EXTEND_NONE... */ - if (extend == CAIRO_EXTEND_NONE) - return COGL_PIXEL_FORMAT_BGRA_8888_PRE; - - for (n = 1; n < n_stops; n++) { - if (stops[n].color.alpha != 1.0) - return COGL_PIXEL_FORMAT_BGRA_8888_PRE; - } - - return COGL_PIXEL_FORMAT_BGR_888; -} - -static cairo_cogl_gradient_compatibility_t -_cairo_cogl_compatibility_from_extend_mode (cairo_extend_t extend_mode) -{ - switch (extend_mode) - { - case CAIRO_EXTEND_NONE: - return CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE; - case CAIRO_EXTEND_PAD: - return CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD; - case CAIRO_EXTEND_REPEAT: - return CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT; - case CAIRO_EXTEND_REFLECT: - return CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT; - } - - assert (0); /* not reached */ - return CAIRO_EXTEND_NONE; -} - -cairo_cogl_linear_texture_entry_t * -_cairo_cogl_linear_gradient_texture_for_extend (cairo_cogl_linear_gradient_t *gradient, - cairo_extend_t extend_mode) -{ - GList *l; - cairo_cogl_gradient_compatibility_t compatibility = - _cairo_cogl_compatibility_from_extend_mode (extend_mode); - for (l = gradient->textures; l; l = l->next) { - cairo_cogl_linear_texture_entry_t *entry = l->data; - if (entry->compatibility & compatibility) - return entry; - } - return NULL; -} - -static void -color_stop_lerp (const cairo_color_stop_t *c0, - const cairo_color_stop_t *c1, - float factor, - cairo_color_stop_t *dest) -{ - /* NB: we always ignore the short members in this file so we don't need to - * worry about initializing them here. */ - dest->red = c0->red * (1.0f-factor) + c1->red * factor; - dest->green = c0->green * (1.0f-factor) + c1->green * factor; - dest->blue = c0->blue * (1.0f-factor) + c1->blue * factor; - dest->alpha = c0->alpha * (1.0f-factor) + c1->alpha * factor; -} - -static size_t -_cairo_cogl_linear_gradient_size (cairo_cogl_linear_gradient_t *gradient) -{ - GList *l; - size_t size = 0; - for (l = gradient->textures; l; l = l->next) { - cairo_cogl_linear_texture_entry_t *entry = l->data; - size += cogl_texture_get_width (entry->texture) * 4; - } - return size; -} - -static void -emit_stop (CoglVertexP2C4 **position, - float left, - float right, - const cairo_color_stop_t *left_color, - const cairo_color_stop_t *right_color) -{ - CoglVertexP2C4 *p = *position; - - guint8 lr = left_color->red * 255; - guint8 lg = left_color->green * 255; - guint8 lb = left_color->blue * 255; - guint8 la = left_color->alpha * 255; - - guint8 rr = right_color->red * 255; - guint8 rg = right_color->green * 255; - guint8 rb = right_color->blue * 255; - guint8 ra = right_color->alpha * 255; - - p[0].x = left; - p[0].y = 0; - p[0].r = lr; p[0].g = lg; p[0].b = lb; p[0].a = la; - p[1].x = left; - p[1].y = 1; - p[1].r = lr; p[1].g = lg; p[1].b = lb; p[1].a = la; - p[2].x = right; - p[2].y = 1; - p[2].r = rr; p[2].g = rg; p[2].b = rb; p[2].a = ra; - - p[3].x = left; - p[3].y = 0; - p[3].r = lr; p[3].g = lg; p[3].b = lb; p[3].a = la; - p[4].x = right; - p[4].y = 1; - p[4].r = rr; p[4].g = rg; p[4].b = rb; p[4].a = ra; - p[5].x = right; - p[5].y = 0; - p[5].r = rr; p[5].g = rg; p[5].b = rb; p[5].a = ra; - - *position = &p[6]; -} - -#ifdef DUMP_GRADIENTS_TO_PNG -static void -dump_gradient_to_png (CoglTexture *texture) -{ - cairo_image_surface_t *image = (cairo_image_surface_t *) - cairo_image_surface_create (CAIRO_FORMAT_ARGB32, - cogl_texture_get_width (texture), - cogl_texture_get_height (texture)); - CoglPixelFormat format; - static int gradient_id = 0; - char *gradient_name; - - if (image->base.status) - return; - -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - format = COGL_PIXEL_FORMAT_BGRA_8888_PRE; -#else - format = COGL_PIXEL_FORMAT_ARGB_8888_PRE; -#endif - cogl_texture_get_data (texture, - format, - 0, - image->data); - gradient_name = g_strdup_printf ("./gradient%d.png", gradient_id++); - g_print ("writing gradient: %s\n", gradient_name); - cairo_surface_write_to_png ((cairo_surface_t *)image, gradient_name); - g_free (gradient_name); -} -#endif - -cairo_int_status_t -_cairo_cogl_get_linear_gradient (cairo_cogl_device_t *device, - cairo_extend_t extend_mode, - int n_stops, - const cairo_gradient_stop_t *stops, - cairo_cogl_linear_gradient_t **gradient_out) -{ - unsigned long hash; - cairo_cogl_linear_gradient_t *gradient; - cairo_cogl_linear_texture_entry_t *entry; - cairo_gradient_stop_t *internal_stops; - int stop_offset; - int n_internal_stops; - int n; - cairo_cogl_gradient_compatibility_t compatibilities; - int width; - int left_padding = 0; - cairo_color_stop_t left_padding_color; - int right_padding = 0; - cairo_color_stop_t right_padding_color; - CoglPixelFormat format; - CoglTexture2D *tex; - GError *error = NULL; - int un_padded_width; - CoglHandle offscreen; - cairo_int_status_t status; - int n_quads; - int n_vertices; - float prev; - float right; - CoglVertexP2C4 *vertices; - CoglVertexP2C4 *p; - CoglPrimitive *prim; - - hash = _cairo_cogl_linear_gradient_hash (n_stops, stops); - - gradient = _cairo_cogl_linear_gradient_lookup (device, hash, n_stops, stops); - if (gradient) { - cairo_cogl_linear_texture_entry_t *entry = - _cairo_cogl_linear_gradient_texture_for_extend (gradient, extend_mode); - if (entry) { - *gradient_out = _cairo_cogl_linear_gradient_reference (gradient); - return CAIRO_INT_STATUS_SUCCESS; - } - } - - if (!gradient) { - gradient = malloc (sizeof (cairo_cogl_linear_gradient_t) + - sizeof (cairo_gradient_stop_t) * (n_stops - 1)); - if (!gradient) - return CAIRO_INT_STATUS_NO_MEMORY; - - CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 1); - /* NB: we update the cache_entry size at the end before - * [re]adding it to the cache. */ - gradient->cache_entry.hash = hash; - gradient->textures = NULL; - gradient->n_stops = n_stops; - gradient->stops = gradient->stops_embedded; - memcpy (gradient->stops_embedded, stops, sizeof (cairo_gradient_stop_t) * n_stops); - } else - _cairo_cogl_linear_gradient_reference (gradient); - - entry = malloc (sizeof (cairo_cogl_linear_texture_entry_t)); - if (!entry) { - status = CAIRO_INT_STATUS_NO_MEMORY; - goto BAIL; - } - - compatibilities = _cairo_cogl_compatibility_from_extend_mode (extend_mode); - - n_internal_stops = n_stops; - stop_offset = 0; - - /* We really need stops covering the full [0,1] range for repeat/reflect - * if we want to use sampler REPEAT/MIRROR wrap modes so we may need - * to add some extra stops... */ - if (extend_mode == CAIRO_EXTEND_REPEAT || extend_mode == CAIRO_EXTEND_REFLECT) - { - /* If we don't need any extra stops then actually the texture - * will be shareable for repeat and reflect... */ - compatibilities = (CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT | - CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT); - - if (stops[0].offset != 0) { - n_internal_stops++; - stop_offset++; - } - - if (stops[n_stops - 1].offset != 1) - n_internal_stops++; - } - - internal_stops = alloca (n_internal_stops * sizeof (cairo_gradient_stop_t)); - memcpy (&internal_stops[stop_offset], stops, sizeof (cairo_gradient_stop_t) * n_stops); - - /* cairo_color_stop_t values are all unpremultiplied but we need to - * interpolate premultiplied colors so we premultiply all the double - * components now. (skipping any extra stops added for repeat/reflect) - * - * Anothing thing to note is that by premultiplying the colors - * early we'll also reduce the range of colors to interpolate - * which can result in smaller gradient textures. - */ - for (n = stop_offset; n < n_stops; n++) { - cairo_color_stop_t *color = &internal_stops[n].color; - color->red *= color->alpha; - color->green *= color->alpha; - color->blue *= color->alpha; - } - - if (n_internal_stops != n_stops) - { - if (extend_mode == CAIRO_EXTEND_REPEAT) { - compatibilities &= ~CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT; - if (stops[0].offset != 0) { - /* what's the wrap-around distance between the user's end-stops? */ - double dx = (1.0 - stops[n_stops - 1].offset) + stops[0].offset; - internal_stops[0].offset = 0; - color_stop_lerp (&stops[0].color, - &stops[n_stops - 1].color, - stops[0].offset / dx, - &internal_stops[0].color); - } - if (stops[n_stops - 1].offset != 1) { - internal_stops[n_internal_stops - 1].offset = 1; - internal_stops[n_internal_stops - 1].color = internal_stops[0].color; - } - } else if (extend_mode == CAIRO_EXTEND_REFLECT) { - compatibilities &= ~CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT; - if (stops[0].offset != 0) { - internal_stops[0].offset = 0; - internal_stops[0].color = stops[n_stops - 1].color; - } - if (stops[n_stops - 1].offset != 1) { - internal_stops[n_internal_stops - 1].offset = 1; - internal_stops[n_internal_stops - 1].color = stops[0].color; - } - } - } - - stops = internal_stops; - n_stops = n_internal_stops; - - width = _cairo_cogl_linear_gradient_width_for_stops (extend_mode, n_stops, stops); - - if (extend_mode == CAIRO_EXTEND_PAD) { - - /* Here we need to guarantee that the edge texels of our - * texture correspond to the desired padding color so we - * can use CLAMP_TO_EDGE. - * - * For short stop-gaps and especially for degenerate stops - * it's possible that without special consideration the - * user's end stop colors would not be present in our final - * texture. - * - * To handle this we forcibly add two extra padding texels - * at the edges which extend beyond the [0,1] range of the - * gradient itself and we will later report a translate and - * scale transform to compensate for this. - */ - - /* XXX: If we consider generating a mipmap for our 1d texture - * at some point then we also need to consider how much - * padding to add to be sure lower mipmap levels still have - * the desired edge color (as opposed to a linear blend with - * other colors of the gradient). - */ - - left_padding = 1; - left_padding_color = stops[0].color; - right_padding = 1; - right_padding_color = stops[n_stops - 1].color; - } else if (extend_mode == CAIRO_EXTEND_NONE) { - /* We handle EXTEND_NONE by adding two extra, transparent, texels at - * the ends of the texture and use CLAMP_TO_EDGE. - * - * We add a scale and translate transform so to account for our texels - * extending beyond the [0,1] range. */ - - left_padding = 1; - left_padding_color.red = 0; - left_padding_color.green = 0; - left_padding_color.blue = 0; - left_padding_color.alpha = 0; - right_padding = 1; - right_padding_color = left_padding_color; - } - - /* If we still have stops that don't cover the full [0,1] range - * then we need to define a texture-coordinate scale + translate - * transform to account for that... */ - if (stops[n_stops - 1].offset - stops[0].offset < 1) { - float range = stops[n_stops - 1].offset - stops[0].offset; - entry->scale_x = 1.0 / range; - entry->translate_x = -(stops[0].offset * entry->scale_x); - } - - width += left_padding + right_padding; - - width = _cairo_cogl_util_next_p2 (width); - width = MIN (4096, width); /* lets not go too stupidly big! */ - format = _cairo_cogl_linear_gradient_format_for_stops (extend_mode, n_stops, stops); - - do { - tex = cogl_texture_2d_new_with_size (device->cogl_context, - width, - 1, - format, - &error); - if (!tex) - g_error_free (error); - } while (tex == NULL && width >> 1); - - if (!tex) { - status = CAIRO_INT_STATUS_NO_MEMORY; - goto BAIL; - } - - entry->texture = COGL_TEXTURE (tex); - entry->compatibility = compatibilities; - - un_padded_width = width - left_padding - right_padding; - - /* XXX: only when we know the final texture width can we calculate the - * scale and translate factors needed to account for padding... */ - if (un_padded_width != width) - entry->scale_x *= (float)un_padded_width / (float)width; - if (left_padding) - entry->translate_x += (entry->scale_x / (float)un_padded_width) * (float)left_padding; - - offscreen = cogl_offscreen_new_to_texture (tex); - cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen)); - cogl_ortho (0, width, 1, 0, -1, 100); - cogl_framebuffer_clear4f (COGL_FRAMEBUFFER (offscreen), - COGL_BUFFER_BIT_COLOR, - 0, 0, 0, 0); - - n_quads = n_stops - 1 + !!left_padding + !!right_padding; - n_vertices = 6 * n_quads; - vertices = alloca (sizeof (CoglVertexP2C4) * n_vertices); - p = vertices; - if (left_padding) - emit_stop (&p, 0, left_padding, &left_padding_color, &left_padding_color); - prev = (float)left_padding; - for (n = 1; n < n_stops; n++) { - right = (float)left_padding + (float)un_padded_width * stops[n].offset; - emit_stop (&p, prev, right, &stops[n-1].color, &stops[n].color); - prev = right; - } - if (right_padding) - emit_stop (&p, prev, width, &right_padding_color, &right_padding_color); - - prim = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, - n_vertices, - vertices); - /* Just use this as the simplest way to setup a default pipeline... */ - cogl_set_source_color4f (0, 0, 0, 0); - cogl_primitive_draw (prim); - cogl_object_unref (prim); - - cogl_pop_framebuffer (); - cogl_object_unref (offscreen); - - gradient->textures = g_list_prepend (gradient->textures, entry); - gradient->cache_entry.size = _cairo_cogl_linear_gradient_size (gradient); - -#ifdef DUMP_GRADIENTS_TO_PNG - dump_gradient_to_png (COGL_TEXTURE (tex)); -#endif - -#warning "FIXME:" - /* XXX: it seems the documentation of _cairo_cache_insert isn't true - it - * doesn't handle re-adding the same entry gracefully - the cache will - * just keep on growing and then it will start randomly evicting things - * pointlessly */ - /* we ignore errors here and just return an uncached gradient */ - if (likely (! _cairo_cache_insert (&device->linear_cache, &gradient->cache_entry))) - _cairo_cogl_linear_gradient_reference (gradient); - - *gradient_out = gradient; - return CAIRO_INT_STATUS_SUCCESS; - -BAIL: - free (entry); - if (gradient) - _cairo_cogl_linear_gradient_destroy (gradient); - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-private.h deleted file mode 100644 index 13fe5a8dc76..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-private.h +++ /dev/null @@ -1,164 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ - -#ifndef CAIRO_COGL_PRIVATE_H -#define CAIRO_COGL_PRIVATE_H - -#include "cairo-device-private.h" -#include "cairo-cache-private.h" -#include "cairo-backend-private.h" -#include "cairo-default-context-private.h" -#include "cairo-surface-private.h" - -#include - -typedef enum _cairo_cogl_template_type { - CAIRO_COGL_TEMPLATE_TYPE_SOLID, - CAIRO_COGL_TEMPLATE_TYPE_TEXTURE, - CAIRO_COGL_TEMPLATE_TYPE_MASK_SOLID, - CAIRO_COGL_TEMPLATE_TYPE_MASK_TEXTURE, - CAIRO_COGL_TEMPLATE_TYPE_COUNT -} cairo_cogl_template_type; - -typedef struct _cairo_cogl_device { - cairo_device_t base; - - cairo_bool_t backend_vtable_initialized; - cairo_backend_t backend; - - /* We save a copy of all the original backend methods that we override so - * we can chain up... - */ - cairo_backend_t backend_parent; - - CoglContext *cogl_context; - - CoglTexture *dummy_texture; - - /* This is a sparsely filled set of templates because we don't support - * the full range of operators that cairo has. All entries corresponding - * to unsupported operators are NULL. - * - * The CAIRO_OPERATOR_ADD is the operator enum with the highest value that - * we support so we at least cap the size of the array by that. - * - * For each operator we have a template for when we have a solid source - * and another for each texture format that could be used as a source. - */ - CoglPipeline *template_pipelines[CAIRO_OPERATOR_ADD + 1][CAIRO_COGL_TEMPLATE_TYPE_COUNT]; - - CoglMatrix identity; - - /* Caches 1d linear gradient textures */ - cairo_cache_t linear_cache; - - cairo_cache_t path_fill_staging_cache; - cairo_cache_t path_fill_prim_cache; - cairo_cache_t path_stroke_staging_cache; - cairo_cache_t path_stroke_prim_cache; -} cairo_cogl_device_t; - -typedef struct _cairo_cogl_clip_primitives { - cairo_t *clip; - CoglPrimitive **primitives; -} cairo_cogl_clip_primitives_t; - -typedef struct _cairo_cogl_surface { - cairo_surface_t base; - - CoglPixelFormat cogl_format; - cairo_bool_t ignore_alpha; - - /* We currently have 3 basic kinds of Cogl surfaces: - * 1) A light surface simply wrapping a CoglTexture - * 2) A CoglOffscreen framebuffer that implicitly also wraps a CoglTexture - * 3) A CoglOnscreen framebuffer which could potentially be mapped to - * a CoglTexture (e.g. via tfp on X11) but we don't currently do - * that. - */ - - CoglTexture *texture; - CoglFramebuffer *framebuffer; - - int width; - int height; - - GQueue *journal; - - CoglAttributeBuffer *buffer_stack; - size_t buffer_stack_size; - size_t buffer_stack_offset; - guint8 *buffer_stack_pointer; - - cairo_clip_t *last_clip; - - /* A small fifo of recently used cairo_clip_ts paired with CoglPrimitives - * that can be used to mask the stencil buffer. */ - GList *clips_fifo; - - int n_clip_updates_per_frame; - - /* Since the surface backend drawing operator functions don't get - * passed the current cairo_t context we don't have a good way - * to get our user-coordinates path into our surface_fill function. - * - * For now we use our _cairo_cogl_context_fill() wrapper to set this - * side band data on the surface... - */ - cairo_path_fixed_t *user_path; - cairo_matrix_t *ctm; - cairo_matrix_t *ctm_inverse; - cairo_bool_t path_is_rectangle; - double path_rectangle_x; - double path_rectangle_y; - double path_rectangle_width; - double path_rectangle_height; -} cairo_cogl_surface_t; - -cairo_status_t -_cairo_cogl_path_fixed_rectangle (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y, - cairo_fixed_t width, - cairo_fixed_t height); - -cairo_int_status_t -_cairo_cogl_surface_fill_rectangle (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - double x, - double y, - double width, - double height, - cairo_matrix_t *ctm, - const cairo_clip_t *clip); - -#endif /* CAIRO_COGL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-surface.c deleted file mode 100644 index c57fd7f433c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-surface.c +++ /dev/null @@ -1,2805 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ -#include "cairoint.h" - -#include "cairo-cache-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-fixed-private.h" -#include "cairo-device-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-cogl-private.h" -#include "cairo-cogl-gradient-private.h" -#include "cairo-arc-private.h" -#include "cairo-traps-private.h" -#include "cairo-cogl-context-private.h" -#include "cairo-cogl-utils-private.h" -#include "cairo-box-inline.h" -#include "cairo-surface-subsurface-inline.h" -#include "cairo-surface-fallback-private.h" -#include "cairo-surface-offset-private.h" - -#include "cairo-cogl.h" - -#include -#include - -#define CAIRO_COGL_DEBUG 0 -//#define FILL_WITH_COGL_PATH -//#define USE_CAIRO_PATH_FLATTENER -#define ENABLE_PATH_CACHE -//#define DISABLE_BATCHING -#define USE_COGL_RECTANGLE_API -#define ENABLE_RECTANGLES_FASTPATH - -#if defined (USE_COGL_RECTANGLE_API) || defined (ENABLE_PATH_CACHE) -#define NEED_COGL_CONTEXT -#endif - -#if CAIRO_COGL_DEBUG && __GNUC__ -#define UNSUPPORTED(reason) ({ \ - g_warning ("cairo-cogl: hit unsupported operation: %s", reason); \ - CAIRO_INT_STATUS_UNSUPPORTED; \ -}) -#else -#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED -#endif - -#define CAIRO_COGL_PATH_META_CACHE_SIZE (1024 * 1024) - -typedef struct _cairo_cogl_texture_attributes { - /* nabbed from cairo_surface_attributes_t... */ - cairo_matrix_t matrix; - cairo_extend_t extend; - cairo_filter_t filter; - cairo_bool_t has_component_alpha; - - CoglPipelineWrapMode s_wrap; - CoglPipelineWrapMode t_wrap; -} cairo_cogl_texture_attributes_t; - -typedef enum _cairo_cogl_journal_entry_type { - CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE, - CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE, - CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH, - CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP -} cairo_cogl_journal_entry_type_t; - -typedef struct _cairo_cogl_journal_entry { - cairo_cogl_journal_entry_type_t type; -} cairo_cogl_journal_entry_t; - -typedef struct _cairo_cogl_journal_clip_entry { - cairo_cogl_journal_entry_t base; - cairo_clip_t *clip; -} cairo_cogl_journal_clip_entry_t; - -typedef struct _cairo_cogl_journal_rect_entry { - cairo_cogl_journal_entry_t base; - CoglPipeline *pipeline; - float x; - float y; - float width; - float height; - int n_layers; - cairo_matrix_t ctm; -} cairo_cogl_journal_rect_entry_t; - -typedef struct _cairo_cogl_journal_prim_entry { - cairo_cogl_journal_entry_t base; - CoglPipeline *pipeline; - CoglPrimitive *primitive; - gboolean has_transform; - cairo_matrix_t transform; -} cairo_cogl_journal_prim_entry_t; - -typedef struct _cairo_cogl_journal_path_entry { - cairo_cogl_journal_entry_t base; - CoglPipeline *pipeline; - CoglPath *path; -} cairo_cogl_journal_path_entry_t; - -typedef struct _cairo_cogl_path_fill_meta { - cairo_cache_entry_t cache_entry; - cairo_reference_count_t ref_count; - int counter; - cairo_path_fixed_t *user_path; - cairo_matrix_t ctm_inverse; - - /* TODO */ -#if 0 - /* A cached path tessellation should be re-usable with different rotations - * and translations but not for different scales. - * - * one idea is to track the diagonal lenghts of a unit rectangle - * transformed through the original ctm use to tessellate the geometry - * so we can check what the lengths are for any new ctm to know if - * this geometry is compatible. - */ -#endif - - CoglPrimitive *prim; -} cairo_cogl_path_fill_meta_t; - -typedef struct _cairo_cogl_path_stroke_meta { - cairo_cache_entry_t cache_entry; - cairo_reference_count_t ref_count; - int counter; - cairo_path_fixed_t *user_path; - cairo_matrix_t ctm_inverse; - cairo_stroke_style_t style; - double tolerance; - - /* TODO */ -#if 0 - /* A cached path tessellation should be re-usable with different rotations - * and translations but not for different scales. - * - * one idea is to track the diagonal lenghts of a unit rectangle - * transformed through the original ctm use to tessellate the geometry - * so we can check what the lengths are for any new ctm to know if - * this geometry is compatible. - */ -#endif - - CoglPrimitive *prim; -} cairo_cogl_path_stroke_meta_t; - -static cairo_surface_t * -_cairo_cogl_surface_create_full (cairo_cogl_device_t *dev, - cairo_bool_t ignore_alpha, - CoglFramebuffer *framebuffer, - CoglTexture *texture); - -static cairo_int_status_t -_cairo_cogl_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -static void -_cairo_cogl_journal_flush (cairo_cogl_surface_t *surface); - -cairo_private extern const cairo_surface_backend_t _cairo_cogl_surface_backend; - -slim_hidden_proto (cairo_cogl_device_create); -slim_hidden_proto (cairo_cogl_surface_create); -slim_hidden_proto (cairo_cogl_surface_get_framebuffer); -slim_hidden_proto (cairo_cogl_surface_get_texture); -slim_hidden_proto (cairo_cogl_surface_end_frame); - -static cairo_cogl_device_t * -to_device (cairo_device_t *device) -{ - return (cairo_cogl_device_t *)device; -} - -/* moves trap points such that they become the actual corners of the trapezoid */ -static void -_sanitize_trap (cairo_trapezoid_t *t) -{ - cairo_trapezoid_t s = *t; - -#define FIX(lr, tb, p) \ - if (t->lr.p.y != t->tb) { \ - t->lr.p.x = s.lr.p2.x + _cairo_fixed_mul_div_floor (s.lr.p1.x - s.lr.p2.x, s.tb - s.lr.p2.y, s.lr.p1.y - s.lr.p2.y); \ - t->lr.p.y = s.tb; \ - } - FIX (left, top, p1); - FIX (left, bottom, p2); - FIX (right, top, p1); - FIX (right, bottom, p2); -} - -static cairo_status_t -_cairo_cogl_surface_ensure_framebuffer (cairo_cogl_surface_t *surface) -{ - GError *error = NULL; - - if (surface->framebuffer) - return CAIRO_STATUS_SUCCESS; - - surface->framebuffer = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (surface->texture)); - if (!cogl_framebuffer_allocate (surface->framebuffer, &error)) { - g_error_free (error); - cogl_object_unref (surface->framebuffer); - surface->framebuffer = NULL; - return CAIRO_STATUS_NO_MEMORY; - } - - cogl_push_framebuffer (surface->framebuffer); - cogl_ortho (0, surface->width, - surface->height, 0, - -1, 100); - cogl_pop_framebuffer (); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_cogl_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_cogl_surface_t *reference_surface = abstract_surface; - cairo_cogl_surface_t *surface; - CoglTexture *texture; - cairo_status_t status; - - texture = cogl_texture_new_with_size (width, height, - COGL_TEXTURE_NO_SLICING, - (content & CAIRO_CONTENT_COLOR) ? - COGL_PIXEL_FORMAT_BGRA_8888_PRE : - COGL_PIXEL_FORMAT_A_8); - if (!texture) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface = (cairo_cogl_surface_t *) - _cairo_cogl_surface_create_full (to_device(reference_surface->base.device), - (content & CAIRO_CONTENT_ALPHA) == 0, - NULL, - texture); - if (unlikely (surface->base.status)) - return &surface->base; - - status = _cairo_cogl_surface_ensure_framebuffer (surface); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return _cairo_surface_create_in_error (status); - } - - return &surface->base; -} - -static cairo_bool_t -_cairo_cogl_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_cogl_surface_t *surface = abstract_surface; - - extents->x = 0; - extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - - return TRUE; -} - -static void -_cairo_cogl_journal_free (cairo_cogl_surface_t *surface) -{ - GList *l; - - for (l = surface->journal->head; l; l = l->next) { - cairo_cogl_journal_entry_t *entry = l->data; - - if (entry->type == CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE) { - cairo_cogl_journal_prim_entry_t *prim_entry = - (cairo_cogl_journal_prim_entry_t *)entry; - cogl_object_unref (prim_entry->primitive); - } else if (entry->type == CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH) { - cairo_cogl_journal_path_entry_t *path_entry = - (cairo_cogl_journal_path_entry_t *)entry; - cogl_object_unref (path_entry->path); - } - } - - g_queue_free (surface->journal); - surface->journal = NULL; -} - -#ifdef FILL_WITH_COGL_PATH -static void -_cairo_cogl_journal_log_path (cairo_cogl_surface_t *surface, - CoglPipeline *pipeline, - CoglPath *path) -{ - cairo_cogl_journal_path_entry_t *entry; - - if (unlikely (surface->journal == NULL)) - surface->journal = g_queue_new (); - - /* FIXME: Instead of a GList here we should stack allocate the journal - * entries so it would be cheaper to allocate and they can all be freed in - * one go after flushing! */ - entry = g_slice_new (cairo_cogl_journal_path_entry_t); - entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH; - - entry->pipeline = cogl_object_ref (pipeline); - entry->path = cogl_object_ref (path); - - g_queue_push_tail (surface->journal, entry); - -#ifdef DISABLE_BATCHING - _cairo_cogl_journal_flush (surface); -#endif -} -#endif /* FILL_WITH_COGL_PATH */ - -static void -_cairo_cogl_journal_log_primitive (cairo_cogl_surface_t *surface, - CoglPipeline *pipeline, - CoglPrimitive *primitive, - cairo_matrix_t *transform) -{ - cairo_cogl_journal_prim_entry_t *entry; - - if (unlikely (surface->journal == NULL)) - surface->journal = g_queue_new (); - - /* FIXME: Instead of a GList here we should stack allocate the journal - * entries so it would be cheaper to allocate and they can all be freed in - * one go after flushing! */ - entry = g_slice_new (cairo_cogl_journal_prim_entry_t); - entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE; - - entry->pipeline = cogl_object_ref (pipeline); - - if (transform) { - entry->transform = *transform; - entry->has_transform = TRUE; - } else - entry->has_transform = FALSE; - - entry->primitive = cogl_object_ref (primitive); - - g_queue_push_tail (surface->journal, entry); - -#ifdef DISABLE_BATCHING - _cairo_cogl_journal_flush (surface); -#endif -} - -static void -_cairo_cogl_journal_log_rectangle (cairo_cogl_surface_t *surface, - CoglPipeline *pipeline, - float x, - float y, - float width, - float height, - int n_layers, - cairo_matrix_t *ctm) -{ - cairo_cogl_journal_rect_entry_t *entry; - - if (unlikely (surface->journal == NULL)) - surface->journal = g_queue_new (); - - /* FIXME: Instead of a GList here we should stack allocate the journal - * entries so it would be cheaper to allocate and they can all be freed in - * one go after flushing! */ - entry = g_slice_new (cairo_cogl_journal_rect_entry_t); - entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE; - - entry->pipeline = cogl_object_ref (pipeline); - - entry->x = x; - entry->y = y; - entry->width = width; - entry->height = height; - entry->ctm = *ctm; - - entry->n_layers = n_layers; - - g_queue_push_tail (surface->journal, entry); - -#ifdef DISABLE_BATCHING - _cairo_cogl_journal_flush (surface); -#endif -} - -static void -_cairo_cogl_journal_log_clip (cairo_cogl_surface_t *surface, - const cairo_clip_t *clip) -{ - cairo_cogl_journal_clip_entry_t *entry; - - if (unlikely (surface->journal == NULL)) - surface->journal = g_queue_new (); - - /* FIXME: Instead of a GList here we should stack allocate the journal - * entries so it would be cheaper to allocate and they can all be freed in - * one go after flushing! */ - entry = g_slice_new (cairo_cogl_journal_clip_entry_t); - entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP; - entry->clip = _cairo_clip_copy (clip); - - g_queue_push_tail (surface->journal, entry); -} - -static void -_cairo_cogl_journal_discard (cairo_cogl_surface_t *surface) -{ - GList *l; - - if (!surface->journal) { - assert (surface->last_clip == NULL); - return; - } - - if (surface->buffer_stack && surface->buffer_stack_offset) { - cogl_buffer_unmap (COGL_BUFFER (surface->buffer_stack)); - cogl_object_unref (surface->buffer_stack); - surface->buffer_stack = NULL; - } - - for (l = surface->journal->head; l; l = l->next) { - cairo_cogl_journal_entry_t *entry = l->data; - gsize entry_size; - - switch (entry->type) - { - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP: { - cairo_cogl_journal_clip_entry_t *clip_entry = - (cairo_cogl_journal_clip_entry_t *)entry; - _cairo_clip_destroy (clip_entry->clip); - entry_size = sizeof (cairo_cogl_journal_clip_entry_t); - break; - } - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE: { - cairo_cogl_journal_rect_entry_t *rect_entry = - (cairo_cogl_journal_rect_entry_t *)entry; - cogl_object_unref (rect_entry->pipeline); - entry_size = sizeof (cairo_cogl_journal_rect_entry_t); - break; - } - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE: { - cairo_cogl_journal_prim_entry_t *prim_entry = - (cairo_cogl_journal_prim_entry_t *)entry; - cogl_object_unref (prim_entry->pipeline); - cogl_object_unref (prim_entry->primitive); - entry_size = sizeof (cairo_cogl_journal_prim_entry_t); - break; - } - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH: { - cairo_cogl_journal_path_entry_t *path_entry = - (cairo_cogl_journal_path_entry_t *)entry; - cogl_object_unref (path_entry->pipeline); - cogl_object_unref (path_entry->path); - entry_size = sizeof (cairo_cogl_journal_path_entry_t); - break; - } - default: - assert (0); /* not reached! */ - entry_size = 0; /* avoid compiler warning */ - } - g_slice_free1 (entry_size, entry); - } - - g_queue_clear (surface->journal); - - if (surface->last_clip) { - _cairo_clip_destroy (surface->last_clip); - surface->last_clip = NULL; - } -} - -static CoglAttributeBuffer * -_cairo_cogl_surface_allocate_buffer_space (cairo_cogl_surface_t *surface, - size_t size, - size_t *offset, - void **pointer) -{ - /* XXX: In the Cogl journal we found it more efficient to have a pool of - * buffers that we re-cycle but for now we simply thow away our stack - * buffer each time we flush. */ - if (unlikely (surface->buffer_stack && - (surface->buffer_stack_size - surface->buffer_stack_offset) < size)) { - cogl_buffer_unmap (COGL_BUFFER (surface->buffer_stack)); - cogl_object_unref (surface->buffer_stack); - surface->buffer_stack = NULL; - surface->buffer_stack_size *= 2; - } - - if (unlikely (surface->buffer_stack_size < size)) - surface->buffer_stack_size = size * 2; - - if (unlikely (surface->buffer_stack == NULL)) { - surface->buffer_stack = cogl_attribute_buffer_new (surface->buffer_stack_size, NULL); - surface->buffer_stack_pointer = - cogl_buffer_map (COGL_BUFFER (surface->buffer_stack), - COGL_BUFFER_ACCESS_WRITE, - COGL_BUFFER_MAP_HINT_DISCARD); - surface->buffer_stack_offset = 0; - } - - *pointer = surface->buffer_stack_pointer + surface->buffer_stack_offset; - *offset = surface->buffer_stack_offset; - - surface->buffer_stack_offset += size; - return cogl_object_ref (surface->buffer_stack); -} - - -static CoglAttributeBuffer * -_cairo_cogl_traps_to_triangles_buffer (cairo_cogl_surface_t *surface, - cairo_traps_t *traps, - size_t *offset, - gboolean one_shot) -{ - CoglAttributeBuffer *buffer; - int n_traps = traps->num_traps; - int i; - CoglVertexP2 *triangles; - - if (one_shot) { - buffer = _cairo_cogl_surface_allocate_buffer_space (surface, - n_traps * sizeof (CoglVertexP2) * 6, - offset, - (void **)&triangles); - if (!buffer) - return NULL; - } else { - buffer = cogl_attribute_buffer_new (n_traps * sizeof (CoglVertexP2) * 6, NULL); - if (!buffer) - return NULL; - triangles = cogl_buffer_map (COGL_BUFFER (buffer), - COGL_BUFFER_ACCESS_WRITE, - COGL_BUFFER_MAP_HINT_DISCARD); - if (!triangles) - return NULL; - *offset = 0; - } - - /* XXX: This is can be very expensive. I'm not sure a.t.m if it's - * predominantly the bandwidth required or the cost of the fixed_to_float - * conversions but either way we should try using an index buffer to - * reduce the amount we upload by 1/3 (offset by allocating and uploading - * indices though) sadly though my experience with the intel mesa drivers - * is that slow paths can easily be hit when starting to use indices. - */ - for (i = 0; i < n_traps; i++) - { - CoglVertexP2 *p = &triangles[i * 6]; - cairo_trapezoid_t *trap = &traps->traps[i]; - - p[0].x = _cairo_cogl_util_fixed_to_float (trap->left.p1.x); - p[0].y = _cairo_cogl_util_fixed_to_float (trap->left.p1.y); - - p[1].x = _cairo_cogl_util_fixed_to_float (trap->left.p2.x); - p[1].y = _cairo_cogl_util_fixed_to_float (trap->left.p2.y); - - p[2].x = _cairo_cogl_util_fixed_to_float (trap->right.p2.x); - p[2].y = _cairo_cogl_util_fixed_to_float (trap->right.p2.y); - - p[3].x = _cairo_cogl_util_fixed_to_float (trap->left.p1.x); - p[3].y = _cairo_cogl_util_fixed_to_float (trap->left.p1.y); - - p[4].x = _cairo_cogl_util_fixed_to_float (trap->right.p2.x); - p[4].y = _cairo_cogl_util_fixed_to_float (trap->right.p2.y); - - p[5].x = _cairo_cogl_util_fixed_to_float (trap->right.p1.x); - p[5].y = _cairo_cogl_util_fixed_to_float (trap->right.p1.y); - } - - if (!one_shot) - cogl_buffer_unmap (COGL_BUFFER (buffer)); - - return buffer; -} - -/* Used for solid fills, in this case we just need a mesh made of - * a single (2-component) position attribute. */ -static CoglPrimitive * -_cairo_cogl_traps_to_composite_prim_p2 (cairo_cogl_surface_t *surface, - cairo_traps_t *traps, - gboolean one_shot) -{ - size_t offset; - CoglAttributeBuffer *buffer = _cairo_cogl_traps_to_triangles_buffer (surface, traps, &offset, one_shot); - CoglAttribute *pos = cogl_attribute_new (buffer, - "cogl_position_in", - sizeof (CoglVertexP2), - offset, - 2, - COGL_ATTRIBUTE_TYPE_FLOAT); - CoglPrimitive *prim; - - /* The attribute will have taken a reference on the buffer */ - cogl_object_unref (buffer); - - prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, - traps->num_traps * 6, pos, NULL); - - /* The primitive will now keep the attribute alive... */ - cogl_object_unref (pos); - - return prim; -} - -/* Used for surface fills, in this case we need a mesh made of a single - * (2-component) position attribute + we also alias the same attribute as - * (2-component) texture coordinates */ -static CoglPrimitive * -_cairo_cogl_traps_to_composite_prim_p2t2 (cairo_cogl_surface_t *surface, - cairo_traps_t *traps, - gboolean one_shot) -{ - size_t offset; - CoglAttributeBuffer *buffer = _cairo_cogl_traps_to_triangles_buffer (surface, traps, &offset, one_shot); - CoglAttribute *pos = cogl_attribute_new (buffer, - "cogl_position_in", - sizeof (CoglVertexP2), - offset, - 2, - COGL_ATTRIBUTE_TYPE_FLOAT); - CoglAttribute *tex_coords = cogl_attribute_new (buffer, - "cogl_tex_coord0_in", - sizeof (CoglVertexP2), - 0, - 2, - COGL_ATTRIBUTE_TYPE_FLOAT); - CoglPrimitive *prim; - - /* The attributes will have taken references on the buffer */ - cogl_object_unref (buffer); - - prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, - traps->num_traps * 6, pos, tex_coords, NULL); - - /* The primitive will now keep the attributes alive... */ - cogl_object_unref (pos); - cogl_object_unref (tex_coords); - - return prim; -} - -static CoglPrimitive * -_cairo_cogl_traps_to_composite_prim (cairo_cogl_surface_t *surface, - cairo_traps_t *traps, - int n_layers, - gboolean one_shot) -{ - int n_traps = traps->num_traps; - int i; - - /* XXX: Ideally we would skip tessellating to traps entirely since - * given their representation, conversion to triangles is quite expensive. - * - * This simplifies the conversion to triangles by making the end points of - * the two side lines actually just correspond to the corners of the - * traps. - */ - for (i = 0; i < n_traps; i++) - _sanitize_trap (&traps->traps[i]); - - if (n_layers == 0) - return _cairo_cogl_traps_to_composite_prim_p2 (surface, traps, one_shot); - else { - assert (n_layers == 1); - return _cairo_cogl_traps_to_composite_prim_p2t2 (surface, traps, one_shot); - } -} - -static cairo_int_status_t -_cairo_cogl_fill_to_primitive (cairo_cogl_surface_t *surface, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - int n_layers, - cairo_bool_t one_shot, - CoglPrimitive **primitive, - size_t *size) -{ - cairo_traps_t traps; - cairo_int_status_t status; - - _cairo_traps_init (&traps); - status = _cairo_path_fixed_fill_to_traps (path, fill_rule, tolerance, &traps); - if (unlikely (status)) - goto BAIL; - - if (traps.num_traps == 0) { - status = CAIRO_INT_STATUS_NOTHING_TO_DO; - goto BAIL; - } - - *size = traps.num_traps * sizeof (CoglVertexP2) * 6; - - *primitive = _cairo_cogl_traps_to_composite_prim (surface, &traps, n_layers, one_shot); - if (!*primitive) { - status = CAIRO_INT_STATUS_NO_MEMORY; - goto BAIL; - } - -BAIL: - _cairo_traps_fini (&traps); - return status; -} - -static void -_cairo_cogl_clip_push_box (const cairo_box_t *box) -{ - if (_cairo_box_is_pixel_aligned (box)) { - cairo_rectangle_int_t rect; - _cairo_box_round_to_rectangle (box, &rect); - cogl_clip_push_window_rectangle (rect.x, rect.y, - rect.width, rect.height); - } else { - double x1, y1, x2, y2; - _cairo_box_to_doubles (box, &x1, &y1, &x2, &y2); - cogl_clip_push_rectangle (x1, y1, x2, y2); - } -} - -static void -_cairo_cogl_journal_flush (cairo_cogl_surface_t *surface) -{ - GList *l; - int clip_stack_depth = 0; - int i; - - if (!surface->journal) - return; - - if (surface->buffer_stack && surface->buffer_stack_offset) { - cogl_buffer_unmap (COGL_BUFFER (surface->buffer_stack)); - cogl_object_unref (surface->buffer_stack); - surface->buffer_stack = NULL; - } - - cogl_set_framebuffer (surface->framebuffer); - - cogl_push_matrix (); - - for (l = surface->journal->head; l; l = l->next) { - cairo_cogl_journal_entry_t *entry = l->data; - - switch (entry->type) - { - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP: { - cairo_cogl_journal_clip_entry_t *clip_entry = - (cairo_cogl_journal_clip_entry_t *)entry; - cairo_clip_path_t *path; -#if 0 - cairo_bool_t checked_for_primitives = FALSE; - cairo_cogl_clip_primitives_t *clip_primitives; -#endif - - for (i = 0; i < clip_stack_depth; i++) - cogl_clip_pop (); - clip_stack_depth = 0; - - for (path = clip_entry->clip->path, i = 0; path; path = path->prev, i++) { - cairo_rectangle_int_t extents; - cairo_int_status_t status; - CoglPrimitive *prim; - size_t prim_size; - - _cairo_path_fixed_approximate_clip_extents (&path->path, &extents); - - /* TODO - maintain a fifo of the last 10 used clips with cached - * primitives to see if we can avoid tessellating the path and - * uploading the vertices... - */ -#if 0 - if (!checked_for_primitives) { - clip_primitives = find_clip_primitives (clip); - checked_for_primitives = TRUE; - } - if (clip_primitives) - prim = clip_primitives->primitives[i]; -#endif - status = _cairo_cogl_fill_to_primitive (surface, - &path->path, - path->fill_rule, - path->tolerance, - 0, - TRUE, - &prim, - &prim_size); - if (unlikely (status)) { - g_warning ("Failed to get primitive for clip path while flushing journal"); - continue; - } - clip_stack_depth++; - cogl_clip_push_primitive (prim, - extents.x, extents.y, - extents.x + extents.width, - extents.y + extents.height); - cogl_object_unref (prim); - } - - for (i = 0; i < clip_entry->clip->num_boxes; i++) { - clip_stack_depth++; - _cairo_cogl_clip_push_box (&clip_entry->clip->boxes[i]); - } - - surface->n_clip_updates_per_frame++; - break; - } - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE: { - cairo_cogl_journal_rect_entry_t *rect_entry = - (cairo_cogl_journal_rect_entry_t *)entry; - float tex_coords[8]; - float x1 = rect_entry->x; - float y1 = rect_entry->y; - float x2 = rect_entry->x + rect_entry->width; - float y2 = rect_entry->y + rect_entry->height; - cairo_matrix_t *ctm = &rect_entry->ctm; - float ctmfv[16] = { - ctm->xx, ctm->yx, 0, 0, - ctm->xy, ctm->yy, 0, 0, - 0, 0, 1, 0, - ctm->x0, ctm->y0, 0, 1 - }; - CoglMatrix transform; - - cogl_matrix_init_from_array (&transform, ctmfv); - - if (rect_entry->n_layers) { - g_assert (rect_entry->n_layers <= 2); - tex_coords[0] = x1; - tex_coords[1] = y1; - tex_coords[2] = x2; - tex_coords[3] = y2; - if (rect_entry->n_layers > 1) - memcpy (&tex_coords[4], tex_coords, sizeof (float) * 4); - } - - cogl_set_source (rect_entry->pipeline); - cogl_push_matrix (); - cogl_transform (&transform); - cogl_rectangle_with_multitexture_coords (x1, y1, x2, y2, - tex_coords, 4 * rect_entry->n_layers); - cogl_pop_matrix (); - break; - } - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE: { - cairo_cogl_journal_prim_entry_t *prim_entry = - (cairo_cogl_journal_prim_entry_t *)entry; - CoglMatrix transform; - - cogl_push_matrix (); - if (prim_entry->has_transform) { - cairo_matrix_t *ctm = &prim_entry->transform; - float ctmfv[16] = { - ctm->xx, ctm->yx, 0, 0, - ctm->xy, ctm->yy, 0, 0, - 0, 0, 1, 0, - ctm->x0, ctm->y0, 0, 1 - }; - cogl_matrix_init_from_array (&transform, ctmfv); - cogl_transform (&transform); - } else { - cogl_matrix_init_identity (&transform); - cogl_set_modelview_matrix (&transform); - } - - cogl_set_source (prim_entry->pipeline); - cogl_primitive_draw (prim_entry->primitive); - cogl_pop_matrix (); - break; - } - case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH: { - cairo_cogl_journal_path_entry_t *path_entry = - (cairo_cogl_journal_path_entry_t *)entry; - - cogl_set_source (path_entry->pipeline); - cogl_path_fill (path_entry->path); - break; - } - default: - assert (0); /* not reached! */ - } - } - - cogl_pop_matrix (); - - for (i = 0; i < clip_stack_depth; i++) - cogl_clip_pop (); - - _cairo_cogl_journal_discard (surface); -} - -static cairo_status_t -_cairo_cogl_surface_flush (void *abstract_surface, - unsigned flags) -{ - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; - - if (flags) - return CAIRO_STATUS_SUCCESS; - - _cairo_cogl_journal_flush (surface); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_surface_finish (void *abstract_surface) -{ - cairo_cogl_surface_t *surface = abstract_surface; - - if (surface->texture) - cogl_object_unref (surface->texture); - - if (surface->framebuffer) - cogl_object_unref (surface->framebuffer); - - if (surface->journal) - _cairo_cogl_journal_free (surface); - - /*XXX wtf */ - cairo_device_release (surface->base.device); - - return CAIRO_STATUS_SUCCESS; -} - -static CoglPixelFormat -get_cogl_format_from_cairo_format (cairo_format_t cairo_format); - -/* XXX: We often use RGBA format for onscreen framebuffers so make sure - * to handle CAIRO_FORMAT_INVALID sensibly */ -static cairo_format_t -get_cairo_format_from_cogl_format (CoglPixelFormat format) -{ - switch ((int)format) - { - case COGL_PIXEL_FORMAT_A_8: - return CAIRO_FORMAT_A8; - case COGL_PIXEL_FORMAT_RGB_565: - return CAIRO_FORMAT_RGB16_565; - - case COGL_PIXEL_FORMAT_BGRA_8888_PRE: - case COGL_PIXEL_FORMAT_ARGB_8888_PRE: - case COGL_PIXEL_FORMAT_RGBA_8888_PRE: - /* Note: this is ambiguous since CAIRO_FORMAT_RGB24 - * would also map to the same CoglPixelFormat */ - return CAIRO_FORMAT_ARGB32; - - default: - g_warning("bad format: %x a? %d, bgr? %d, pre %d, format: %d\n", - format, - format & COGL_A_BIT, - format & COGL_BGR_BIT, - format & COGL_PREMULT_BIT, - format & ~(COGL_A_BIT | COGL_BGR_BIT | COGL_PREMULT_BIT)); - return CAIRO_FORMAT_INVALID; - } -} - -static CoglPixelFormat -get_cogl_format_from_cairo_format (cairo_format_t cairo_format) -{ - switch (cairo_format) - { - case CAIRO_FORMAT_ARGB32: - case CAIRO_FORMAT_RGB24: -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - return COGL_PIXEL_FORMAT_BGRA_8888_PRE; -#else - return COGL_PIXEL_FORMAT_ARGB_8888_PRE; -#endif - case CAIRO_FORMAT_A8: - return COGL_PIXEL_FORMAT_A_8; - case CAIRO_FORMAT_RGB16_565: - return COGL_PIXEL_FORMAT_RGB_565; - case CAIRO_FORMAT_INVALID: - case CAIRO_FORMAT_A1: - case CAIRO_FORMAT_RGB30: - return 0; - } - - g_warn_if_reached (); - return 0; -} - -static cairo_status_t -_cairo_cogl_surface_read_rect_to_image_surface (cairo_cogl_surface_t *surface, - cairo_rectangle_int_t *interest, - cairo_image_surface_t **image_out) -{ - cairo_image_surface_t *image; - cairo_status_t status; - cairo_format_t cairo_format; - CoglPixelFormat cogl_format; - - /* TODO: Add cogl_texture_get_region() API so we don't have to ensure the - * surface is bound to an fbo to read back pixels */ - status = _cairo_cogl_surface_ensure_framebuffer (surface); - if (unlikely (status)) - return status; - - cairo_format = get_cairo_format_from_cogl_format (surface->cogl_format); - if (cairo_format == CAIRO_FORMAT_INVALID) { - cairo_format = CAIRO_FORMAT_ARGB32; - cogl_format = get_cogl_format_from_cairo_format (cairo_format); - } else { - cogl_format = cogl_framebuffer_get_color_format (surface->framebuffer); - } - - image = (cairo_image_surface_t *) - cairo_image_surface_create (cairo_format, surface->width, surface->height); - if (image->base.status) - return image->base.status; - - /* TODO: Add cogl_framebuffer_read_pixels() API */ - cogl_push_framebuffer (surface->framebuffer); - cogl_read_pixels (0, 0, surface->width, surface->height, - COGL_READ_PIXELS_COLOR_BUFFER, - cogl_format, - image->data); - cogl_pop_framebuffer (); - - *image_out = image; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_cogl_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_cogl_surface_t *surface = abstract_surface; - cairo_status_t status; - - if (surface->texture) { - cairo_format_t format = get_cairo_format_from_cogl_format (surface->cogl_format); - cairo_image_surface_t *image = (cairo_image_surface_t *) - cairo_image_surface_create (format, surface->width, surface->height); - if (image->base.status) - return image->base.status; - - cogl_texture_get_data (surface->texture, - cogl_texture_get_format (surface->texture), - 0, - image->data); - - image->base.is_clear = FALSE; - *image_out = image; - } else { - cairo_rectangle_int_t extents = { - 0, 0, surface->width, surface->height - }; - status = _cairo_cogl_surface_read_rect_to_image_surface (surface, &extents, - image_out); - if (unlikely (status)) - return status; - } - - *image_extra = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_cogl_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); -} - -static cairo_status_t -_cairo_cogl_surface_clear (cairo_cogl_surface_t *surface, - const cairo_color_t *color) -{ - /* Anything batched in the journal up until now is redundant... */ - _cairo_cogl_journal_discard (surface); - - /* XXX: we currently implicitly clear the depth and stencil buffer here - * but since we use the framebuffer_discard extension when available I - * suppose this doesn't matter too much. - * - * The main concern is that we want to avoid re-loading an external z - * buffer at the start of each frame, but also many gpu architectures have - * optimizations for how they handle the depth/stencil buffers and can get - * upset if they aren't cleared together at the start of the frame. - * - * FIXME: we need a way to assert that the clip stack currently isn't - * using the stencil buffer before clearing it here! - */ - cogl_framebuffer_clear4f (surface->framebuffer, - COGL_BUFFER_BIT_COLOR | - COGL_BUFFER_BIT_DEPTH | - COGL_BUFFER_BIT_STENCIL, - color->red * color->alpha, - color->green * color->alpha, - color->blue * color->alpha, - color->alpha); - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_cogl_path_fixed_rectangle (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y, - cairo_fixed_t width, - cairo_fixed_t height) -{ - cairo_status_t status; - - status = _cairo_path_fixed_move_to (path, x, y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_rel_line_to (path, width, 0); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_rel_line_to (path, 0, height); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_rel_line_to (path, -width, 0); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_close_path (path); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_cogl_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_cogl_surface_t *surface; - cairo_path_fixed_t path; - cairo_status_t status; - cairo_matrix_t identity; - - if (clip == NULL) { - if (op == CAIRO_OPERATOR_CLEAR) - return _cairo_cogl_surface_clear (abstract_surface, CAIRO_COLOR_TRANSPARENT); - else if (source->type == CAIRO_PATTERN_TYPE_SOLID && - (op == CAIRO_OPERATOR_SOURCE || - (op == CAIRO_OPERATOR_OVER && (((cairo_surface_t *)abstract_surface)->is_clear || _cairo_pattern_is_opaque_solid (source))))) { - return _cairo_cogl_surface_clear (abstract_surface, - &((cairo_solid_pattern_t *) source)->color); - } - } - - /* fallback to handling the paint in terms of a fill... */ - - surface = abstract_surface; - - _cairo_path_fixed_init (&path); - - status = _cairo_cogl_path_fixed_rectangle (&path, 0, 0, surface->width, surface->height); - if (unlikely (status)) - goto BAIL; - -#ifdef NEED_COGL_CONTEXT - /* XXX: in cairo-cogl-context.c we set some sideband data on the - * surface before issuing a fill so we need to do that here too... */ - surface->user_path = &path; - cairo_matrix_init_identity (&identity); - surface->ctm = &identity; - surface->ctm_inverse = &identity; - surface->path_is_rectangle = TRUE; - surface->path_rectangle_x = 0; - surface->path_rectangle_y = 0; - surface->path_rectangle_width = surface->width; - surface->path_rectangle_height = surface->height; -#endif - - status = _cairo_cogl_surface_fill (abstract_surface, - op, - source, - &path, - CAIRO_FILL_RULE_WINDING, - 1, - CAIRO_ANTIALIAS_DEFAULT, - clip); -BAIL: - _cairo_path_fixed_fini (&path); - return status; -} - -static CoglPipelineWrapMode -get_cogl_wrap_mode_for_extend (cairo_extend_t extend_mode) -{ - switch (extend_mode) - { - case CAIRO_EXTEND_NONE: - return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; - case CAIRO_EXTEND_PAD: - return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; - case CAIRO_EXTEND_REPEAT: - return COGL_PIPELINE_WRAP_MODE_REPEAT; - case CAIRO_EXTEND_REFLECT: - /* TODO: return COGL_PIPELINE_WRAP_MODE_MIRROR; */ - return CAIRO_EXTEND_REPEAT; - } - assert (0); /* not reached */ - return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; -} - -#if 0 -/* Given an arbitrary texture, check if it's already a pot texture and simply - * return it back if so. If not create a new pot texture, scale the old to - * fill it, unref the old and return a pointer to the new pot texture. */ -static cairo_int_status_t -_cairo_cogl_get_pot_texture (CoglContext *context, - CoglTexture *texture, - CoglTexture **pot_texture) -{ - int width = cogl_texture_get_width (texture); - int height = cogl_texture_get_height (texture); - int pot_width; - int pot_height; - CoglHandle offscreen = NULL; - CoglTexture2D *pot = NULL; - GError *error; - - pot_width = _cairo_cogl_util_next_p2 (width); - pot_height = _cairo_cogl_util_next_p2 (height); - - if (pot_width == width && pot_height == height) - return CAIRO_INT_STATUS_SUCCESS; - - for (;;) { - error = NULL; - pot = cogl_texture_2d_new_with_size (context, - pot_width, - pot_height, - cogl_texture_get_format (texture), - &error); - if (pot) - break; - else - g_error_free (error); - - if (pot_width > pot_height) - pot_width >>= 1; - else - pot_height >>= 1; - - if (!pot_width || !pot_height) - break; - } - - *pot_texture = COGL_TEXTURE (pot); - - if (!pot) - return CAIRO_INT_STATUS_NO_MEMORY; - - /* Use the GPU to do a bilinear filtered scale from npot to pot... */ - offscreen = cogl_offscreen_new_to_texture (COGL_TEXTURE (pot)); - error = NULL; - if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error)) { - /* NB: if we don't pass an error then Cogl is allowed to simply abort - * automatically. */ - g_error_free (error); - cogl_object_unref (pot); - *pot_texture = NULL; - return CAIRO_INT_STATUS_NO_MEMORY; - } - - cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen)); - cogl_set_source_texture (texture); - cogl_rectangle (-1, 1, 1, -1); - cogl_pop_framebuffer (); - - cogl_object_unref (offscreen); -} -#endif - -/* NB: a reference for the texture is transferred to the caller which should - * be unrefed */ -static CoglTexture * -_cairo_cogl_acquire_surface_texture (cairo_cogl_surface_t *reference_surface, - cairo_surface_t *abstract_surface) -{ - cairo_image_surface_t *image; - cairo_image_surface_t *acquired_image = NULL; - void *image_extra; - CoglPixelFormat format; - cairo_image_surface_t *image_clone = NULL; - CoglTexture2D *texture; - GError *error = NULL; - cairo_surface_t *clone; - - if (abstract_surface->device == reference_surface->base.device) { - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; - _cairo_cogl_surface_flush (surface, 0); - return surface->texture ? cogl_object_ref (surface->texture) : NULL; - } - - if (abstract_surface->type == CAIRO_SURFACE_TYPE_COGL) { - if (_cairo_surface_is_subsurface (abstract_surface)) { - cairo_cogl_surface_t *surface; - - surface = (cairo_cogl_surface_t *) - _cairo_surface_subsurface_get_target (abstract_surface); - if (surface->base.device == reference_surface->base.device) - return surface->texture ? cogl_object_ref (surface->texture) : NULL; - } - } - - clone = _cairo_surface_has_snapshot (abstract_surface, &_cairo_cogl_surface_backend); - if (clone) { - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)clone; - return surface->texture ? cogl_object_ref (surface->texture) : NULL; - } - - g_warning ("Uploading image surface to texture"); - - if (_cairo_surface_is_image (abstract_surface)) { - image = (cairo_image_surface_t *)abstract_surface; - } else { - cairo_status_t status = _cairo_surface_acquire_source_image (abstract_surface, - &acquired_image, &image_extra); - if (unlikely (status)) { - g_warning ("acquire_source_image failed: %s [%d]\n", - cairo_status_to_string (status), status); - return NULL; - } - image = acquired_image; - } - - format = get_cogl_format_from_cairo_format (image->format); - if (!format) - { - image_clone = _cairo_image_surface_coerce (image); - if (unlikely (image_clone->base.status)) { - g_warning ("image_surface_coerce failed"); - texture = NULL; - goto BAIL; - } - - format = get_cogl_format_from_cairo_format (image_clone->format); - assert (format); - } - - texture = cogl_texture_2d_new_from_data (to_device(reference_surface->base.device)->cogl_context, - image->width, - image->height, - format, /* incoming */ - format, /* desired */ - image->stride, - image->data, - &error); - if (!texture) { - g_warning ("Failed to allocate texture: %s", error->message); - g_error_free (error); - goto BAIL; - } - - clone = _cairo_cogl_surface_create_full (to_device(reference_surface->base.device), - reference_surface->ignore_alpha, - NULL, COGL_TEXTURE (texture)); - - _cairo_surface_attach_snapshot (abstract_surface, clone, NULL); - - /* Attaching the snapshot will take a reference on the clone surface... */ - cairo_surface_destroy (clone); - -BAIL: - if (image_clone) - cairo_surface_destroy (&image_clone->base); - if (acquired_image) - _cairo_surface_release_source_image (abstract_surface, acquired_image, image_extra); - - return COGL_TEXTURE (texture); -} - -/* NB: a reference for the texture is transferred to the caller which should - * be unrefed */ -static CoglTexture * -_cairo_cogl_acquire_pattern_texture (const cairo_pattern_t *pattern, - cairo_cogl_surface_t *destination, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - cairo_cogl_texture_attributes_t *attributes) -{ - CoglTexture *texture = NULL; - - switch ((int)pattern->type) - { - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_t *surface = ((cairo_surface_pattern_t *)pattern)->surface; - texture = _cairo_cogl_acquire_surface_texture (destination, surface); - if (!texture) - return NULL; - - /* XXX: determine if it would have no effect to change the - * extend mode to EXTEND_PAD instead since we can simply map - * EXTEND_PAD to CLAMP_TO_EDGE without needing fragment shader - * tricks or extra border texels. */ -#if 0 - /* TODO: We still need to consider HW such as SGX which doesn't have - * full support for NPOT textures. */ - if (pattern->extend == CAIRO_EXTEND_REPEAT || pattern->extend == CAIRO_EXTEND_REFLECT) { - _cairo_cogl_get_pot_texture (); - } -#endif - - cairo_matrix_init_identity (&attributes->matrix); - - /* Convert from un-normalized source coordinates in backend - * coordinates to normalized texture coordinates */ - cairo_matrix_scale (&attributes->matrix, - 1.0f / cogl_texture_get_width (texture), - 1.0f / cogl_texture_get_height (texture)); - - /* XXX: need to multiply in the pattern->matrix */ - - attributes->extend = pattern->extend; - attributes->filter = CAIRO_FILTER_BILINEAR; - attributes->has_component_alpha = pattern->has_component_alpha; - - attributes->s_wrap = get_cogl_wrap_mode_for_extend (pattern->extend); - attributes->t_wrap = attributes->s_wrap; - - return texture; - } - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: { - cairo_surface_t *surface; - cairo_matrix_t texture_matrix; - - surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, - extents->width, extents->height); - if (_cairo_surface_offset_paint (surface, - extents->x, extents->y, - CAIRO_OPERATOR_SOURCE, - pattern, NULL)) { - cairo_surface_destroy (surface); - return NULL; - } - - texture = _cairo_cogl_acquire_surface_texture (destination, surface); - if (!texture) - goto BAIL; - - cairo_matrix_init_identity (&texture_matrix); - - /* Convert from un-normalized source coordinates in backend - * coordinates to normalized texture coordinates */ - cairo_matrix_scale (&texture_matrix, - 1.0f / cogl_texture_get_width (texture), - 1.0f / cogl_texture_get_height (texture)); - - cairo_matrix_translate (&texture_matrix, -extents->x, -extents->y); - - attributes->matrix = texture_matrix; - attributes->extend = pattern->extend; - attributes->filter = CAIRO_FILTER_NEAREST; - attributes->has_component_alpha = pattern->has_component_alpha; - - /* any pattern extend modes have already been dealt with... */ - attributes->s_wrap = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; - attributes->t_wrap = attributes->s_wrap; - -BAIL: - cairo_surface_destroy (surface); - - return texture; - } - case CAIRO_PATTERN_TYPE_LINEAR: { - cairo_linear_pattern_t *linear_pattern = (cairo_linear_pattern_t *)pattern; - cairo_cogl_linear_gradient_t *gradient; - cairo_cogl_linear_texture_entry_t *linear_texture; - cairo_int_status_t status; - float a, b; - float dist; - float scale; - float angle; - - status = _cairo_cogl_get_linear_gradient (to_device(destination->base.device), - pattern->extend, - linear_pattern->base.n_stops, - linear_pattern->base.stops, - &gradient); - if (unlikely (status)) - return NULL; - - linear_texture = _cairo_cogl_linear_gradient_texture_for_extend (gradient, pattern->extend); - - attributes->extend = pattern->extend; - attributes->filter = CAIRO_FILTER_BILINEAR; - attributes->has_component_alpha = pattern->has_component_alpha; - attributes->s_wrap = get_cogl_wrap_mode_for_extend (pattern->extend); - attributes->t_wrap = COGL_PIPELINE_WRAP_MODE_REPEAT; - - cairo_matrix_init_identity (&attributes->matrix); - - a = linear_pattern->pd2.x - linear_pattern->pd1.x; - b = linear_pattern->pd2.y - linear_pattern->pd1.y; - dist = sqrtf (a*a + b*b); - scale = 1.0f / dist; - angle = - atan2f (b, a); - - cairo_matrix_rotate (&attributes->matrix, angle); - cairo_matrix_scale (&attributes->matrix, scale, scale); - - cairo_matrix_translate (&attributes->matrix, - -linear_pattern->pd1.x, - -linear_pattern->pd1.y); - - /* XXX: this caught me out: cairo doesn't follow the standard - * maths convention for multiplying two matrices A x B - cairo - * does B x A so the final matrix is as if A's transforms were - * applied first. - */ - cairo_matrix_multiply (&attributes->matrix, - &pattern->matrix, - &attributes->matrix); - - return cogl_object_ref (linear_texture->texture); - } - default: - g_warning ("Un-supported source type"); - return NULL; - } -} - -static void -set_layer_texture_with_attributes (CoglPipeline *pipeline, - int layer_index, - CoglTexture *texture, - cairo_cogl_texture_attributes_t *attributes) -{ - cogl_pipeline_set_layer_texture (pipeline, layer_index, texture); - - if (!_cairo_matrix_is_identity (&attributes->matrix)) { - cairo_matrix_t *m = &attributes->matrix; - float texture_matrixfv[16] = { - m->xx, m->yx, 0, 0, - m->xy, m->yy, 0, 0, - 0, 0, 1, 0, - m->x0, m->y0, 0, 1 - }; - CoglMatrix texture_matrix; - cogl_matrix_init_from_array (&texture_matrix, texture_matrixfv); - cogl_pipeline_set_layer_matrix (pipeline, layer_index, &texture_matrix); - } - - if (attributes->s_wrap != attributes->t_wrap) { - cogl_pipeline_set_layer_wrap_mode_s (pipeline, layer_index, attributes->s_wrap); - cogl_pipeline_set_layer_wrap_mode_t (pipeline, layer_index, attributes->t_wrap); - } else - cogl_pipeline_set_layer_wrap_mode (pipeline, layer_index, attributes->s_wrap); -} - -static CoglPipeline * -get_source_mask_operator_destination_pipeline (const cairo_pattern_t *mask, - const cairo_pattern_t *source, - cairo_operator_t op, - cairo_cogl_surface_t *destination, - cairo_composite_rectangles_t *extents) -{ - cairo_cogl_template_type template_type; - CoglPipeline *pipeline; - - switch ((int)source->type) - { - case CAIRO_PATTERN_TYPE_SOLID: - template_type = mask ? - CAIRO_COGL_TEMPLATE_TYPE_MASK_SOLID : CAIRO_COGL_TEMPLATE_TYPE_SOLID; - break; - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - template_type = mask ? - CAIRO_COGL_TEMPLATE_TYPE_MASK_TEXTURE : CAIRO_COGL_TEMPLATE_TYPE_TEXTURE; - break; - default: - g_warning ("Un-supported source type"); - return NULL; - } - - pipeline = cogl_pipeline_copy (to_device(destination->base.device)->template_pipelines[op][template_type]); - - if (source->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)source; - cogl_pipeline_set_color4f (pipeline, - solid_pattern->color.red * solid_pattern->color.alpha, - solid_pattern->color.green * solid_pattern->color.alpha, - solid_pattern->color.blue * solid_pattern->color.alpha, - solid_pattern->color.alpha); - } else { - cairo_cogl_texture_attributes_t attributes; - CoglTexture *texture = - _cairo_cogl_acquire_pattern_texture (source, destination, - &extents->bounded, - &extents->source_sample_area, - &attributes); - if (!texture) - goto BAIL; - set_layer_texture_with_attributes (pipeline, 0, texture, &attributes); - cogl_object_unref (texture); - } - - if (mask) { - if (mask->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)mask; - CoglColor color; - cogl_color_init_from_4f (&color, - solid_pattern->color.red * solid_pattern->color.alpha, - solid_pattern->color.green * solid_pattern->color.alpha, - solid_pattern->color.blue * solid_pattern->color.alpha, - solid_pattern->color.alpha); - cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color); - } else { - cairo_cogl_texture_attributes_t attributes; - CoglTexture *texture = - _cairo_cogl_acquire_pattern_texture (mask, destination, - &extents->bounded, - &extents->mask_sample_area, - &attributes); - if (!texture) - goto BAIL; - set_layer_texture_with_attributes (pipeline, 1, texture, &attributes); - cogl_object_unref (texture); - } - } - - return pipeline; - -BAIL: - cogl_object_unref (pipeline); - return NULL; -} - -#if 0 -CoglPrimitive * -_cairo_cogl_rectangle_new_p2t2t2 (float x, - float y, - float width, - float height) -{ - CoglVertexP2 vertices[] = { - {x, y}, {x, y + height}, {x + width, y + height}, - {x, y}, {x + width, y + height}, {x + width, y} - }; - CoglAttributeBuffer *buffer = cogl_attribute_buffer_new (sizeof (vertices)); - CoglAttribute *pos = cogl_attribute_new (buffer, - "cogl_position_in", - sizeof (CoglVertexP2), - 0, - 2, - COGL_ATTRIBUTE_TYPE_FLOAT); - CoglAttribute *tex_coords0 = cogl_attribute_new (buffer, - "cogl_tex_coord0_in", - sizeof (CoglVertexP2), - 0, - 2, - COGL_ATTRIBUTE_TYPE_FLOAT); - CoglAttribute *tex_coords0 = cogl_attribute_new (buffer, - "cogl_tex_coord0_in", - sizeof (CoglVertexP2), - 0, - 2, - COGL_ATTRIBUTE_TYPE_FLOAT); - CoglPrimitive *prim; - - cogl_buffer_set_data (COGL_BUFFER (buffer), 0, vertices, sizeof (vertices)); - - /* The attributes will now keep the buffer alive... */ - cogl_object_unref (buffer); - - prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, - 6, pos, tex_coords, NULL); - - /* The primitive will now keep the attribute alive... */ - cogl_object_unref (pos); - - return prim; -} -#endif - -static void -_cairo_cogl_log_clip (cairo_cogl_surface_t *surface, - const cairo_clip_t *clip) -{ - if (!_cairo_clip_equal (clip, surface->last_clip)) { - _cairo_cogl_journal_log_clip (surface, clip); - _cairo_clip_destroy (surface->last_clip); - surface->last_clip = _cairo_clip_copy (clip); - } -} - -static void -_cairo_cogl_maybe_log_clip (cairo_cogl_surface_t *surface, - cairo_composite_rectangles_t *composite) -{ - cairo_clip_t *clip = composite->clip; - - if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) - clip = NULL; - - if (clip == NULL) { - if (_cairo_composite_rectangles_can_reduce_clip (composite, - surface->last_clip)) - return; - } - - _cairo_cogl_log_clip (surface, clip); -} - -static cairo_bool_t -is_operator_supported (cairo_operator_t op) -{ - switch ((int)op) { - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_ADD: - return TRUE; - - default: - return FALSE; - } -} - -static cairo_int_status_t -_cairo_cogl_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_cogl_surface_t *surface = abstract_surface; - cairo_composite_rectangles_t extents; - cairo_status_t status; - CoglPipeline *pipeline; - cairo_matrix_t identity; - - /* XXX: Use this to smoke test the acquire_source/dest_image fallback - * paths... */ - //return CAIRO_INT_STATUS_UNSUPPORTED; - - if (!is_operator_supported (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_composite_rectangles_init_for_mask (&extents, - &surface->base, - op, source, mask, clip); - if (unlikely (status)) - return status; - - pipeline = get_source_mask_operator_destination_pipeline (mask, source, - op, surface, &extents); - if (!pipeline){ - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto BAIL; - } - - _cairo_cogl_maybe_log_clip (surface, &extents); - - cairo_matrix_init_identity (&identity); - _cairo_cogl_journal_log_rectangle (surface, pipeline, - extents.bounded.x, - extents.bounded.y, - extents.bounded.width, - extents.bounded.height, - 2, - &identity); - - /* The journal will take a reference on the pipeline and clip_path... */ - cogl_object_unref (pipeline); - -BAIL: - return status; -} - -static int -_cairo_cogl_source_n_layers (const cairo_pattern_t *source) -{ - switch ((int)source->type) - { - case CAIRO_PATTERN_TYPE_SOLID: - return 0; - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - case CAIRO_PATTERN_TYPE_SURFACE: - return 1; - default: - g_warning ("Unsupported source type"); - return 0; - } -} - -static cairo_bool_t -_cairo_cogl_path_fill_meta_equal (const void *key_a, const void *key_b) -{ - const cairo_cogl_path_fill_meta_t *meta0 = key_a; - const cairo_cogl_path_fill_meta_t *meta1 = key_b; - - return _cairo_path_fixed_equal (meta0->user_path, meta1->user_path); -} - -static cairo_bool_t -_cairo_cogl_stroke_style_equal (const cairo_stroke_style_t *a, - const cairo_stroke_style_t *b) -{ - if (a->line_width == b->line_width && - a->line_cap == b->line_cap && - a->line_join == b->line_join && - a->miter_limit == b->miter_limit && - a->num_dashes == b->num_dashes && - a->dash_offset == b->dash_offset) - { - unsigned int i; - for (i = 0; i < a->num_dashes; i++) { - if (a->dash[i] != b->dash[i]) - return FALSE; - } - } - return TRUE; -} - -static cairo_bool_t -_cairo_cogl_path_stroke_meta_equal (const void *key_a, const void *key_b) -{ - const cairo_cogl_path_stroke_meta_t *meta0 = key_a; - const cairo_cogl_path_stroke_meta_t *meta1 = key_b; - - return _cairo_cogl_stroke_style_equal (&meta0->style, &meta1->style) && - _cairo_path_fixed_equal (meta0->user_path, meta1->user_path); -} - -static cairo_cogl_path_stroke_meta_t * -_cairo_cogl_path_stroke_meta_reference (cairo_cogl_path_stroke_meta_t *meta) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); - - _cairo_reference_count_inc (&meta->ref_count); - - return meta; -} - -static void -_cairo_cogl_path_stroke_meta_destroy (cairo_cogl_path_stroke_meta_t *meta) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&meta->ref_count)) - return; - - _cairo_path_fixed_fini (meta->user_path); - free (meta->user_path); - - _cairo_stroke_style_fini (&meta->style); - - if (meta->prim) - cogl_object_unref (meta->prim); - - free (meta); -} - -static cairo_cogl_path_stroke_meta_t * -_cairo_cogl_path_stroke_meta_lookup (cairo_cogl_device_t *ctx, - unsigned long hash, - cairo_path_fixed_t *user_path, - const cairo_stroke_style_t *style, - double tolerance) -{ - cairo_cogl_path_stroke_meta_t *ret; - cairo_cogl_path_stroke_meta_t lookup; - - lookup.cache_entry.hash = hash; - lookup.user_path = user_path; - lookup.style = *style; - lookup.tolerance = tolerance; - - ret = _cairo_cache_lookup (&ctx->path_stroke_staging_cache, &lookup.cache_entry); - if (!ret) - ret = _cairo_cache_lookup (&ctx->path_stroke_prim_cache, &lookup.cache_entry); - return ret; -} - -static void -_cairo_cogl_path_stroke_meta_set_prim_size (cairo_cogl_surface_t *surface, - cairo_cogl_path_stroke_meta_t *meta, - size_t size) -{ - /* now that we know the meta structure is associated with a primitive - * we promote it from the staging cache into the primitive cache. - */ - - /* XXX: _cairo_cache borks if you try and remove an entry that's already - * been evicted so we explicitly look it up first... */ - if (_cairo_cache_lookup (&to_device(surface->base.device)->path_stroke_staging_cache, &meta->cache_entry)) { - _cairo_cogl_path_stroke_meta_reference (meta); - _cairo_cache_remove (&to_device(surface->base.device)->path_stroke_staging_cache, &meta->cache_entry); - } - - meta->cache_entry.size = size; - if (_cairo_cache_insert (&to_device(surface->base.device)->path_stroke_prim_cache, &meta->cache_entry) != - CAIRO_STATUS_SUCCESS) - _cairo_cogl_path_stroke_meta_destroy (meta); -} - -static unsigned int -_cairo_cogl_stroke_style_hash (unsigned int hash, - const cairo_stroke_style_t *style) -{ - unsigned int i; - hash = _cairo_hash_bytes (hash, &style->line_width, sizeof (style->line_width)); - hash = _cairo_hash_bytes (hash, &style->line_cap, sizeof (style->line_cap)); - hash = _cairo_hash_bytes (hash, &style->line_join, sizeof (style->line_join)); - hash = _cairo_hash_bytes (hash, &style->miter_limit, sizeof (style->miter_limit)); - hash = _cairo_hash_bytes (hash, &style->num_dashes, sizeof (style->num_dashes)); - hash = _cairo_hash_bytes (hash, &style->dash_offset, sizeof (style->dash_offset)); - for (i = 0; i < style->num_dashes; i++) - hash = _cairo_hash_bytes (hash, &style->dash[i], sizeof (double)); - return hash; -} - -static cairo_cogl_path_stroke_meta_t * -_cairo_cogl_get_path_stroke_meta (cairo_cogl_surface_t *surface, - const cairo_stroke_style_t *style, - double tolerance) -{ - unsigned long hash; - cairo_cogl_path_stroke_meta_t *meta = NULL; - cairo_path_fixed_t *meta_path = NULL; - cairo_status_t status; - - if (!surface->user_path) - return NULL; - - hash = _cairo_path_fixed_hash (surface->user_path); - hash = _cairo_cogl_stroke_style_hash (hash, style); - hash = _cairo_hash_bytes (hash, &tolerance, sizeof (tolerance)); - - meta = _cairo_cogl_path_stroke_meta_lookup (to_device(surface->base.device), hash, - surface->user_path, style, tolerance); - if (meta) - return meta; - - meta = calloc (1, sizeof (cairo_cogl_path_stroke_meta_t)); - if (!meta) - goto BAIL; - CAIRO_REFERENCE_COUNT_INIT (&meta->ref_count, 1); - meta->cache_entry.hash = hash; - meta->counter = 0; - meta_path = malloc (sizeof (cairo_path_fixed_t)); - if (!meta_path) - goto BAIL; - /* FIXME: we should add a ref-counted wrapper for our user_paths - * so we don't have to keep copying them here! */ - status = _cairo_path_fixed_init_copy (meta_path, surface->user_path); - if (unlikely (status)) - goto BAIL; - meta->user_path = meta_path; - meta->ctm_inverse = *surface->ctm_inverse; - - status = _cairo_stroke_style_init_copy (&meta->style, style); - if (unlikely (status)) { - _cairo_path_fixed_fini (meta_path); - goto BAIL; - } - meta->tolerance = tolerance; - - return meta; - -BAIL: - free (meta_path); - free (meta); - return NULL; -} - -static cairo_int_status_t -_cairo_cogl_stroke_to_primitive (cairo_cogl_surface_t *surface, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - int n_layers, - cairo_bool_t one_shot, - CoglPrimitive **primitive, - size_t *size) -{ - cairo_traps_t traps; - cairo_int_status_t status; - - _cairo_traps_init (&traps); - - status = _cairo_path_fixed_stroke_polygon_to_traps (path, style, - ctm, ctm_inverse, - tolerance, - &traps); - if (unlikely (status)) - goto BAIL; - - if (traps.num_traps == 0) { - status = CAIRO_INT_STATUS_NOTHING_TO_DO; - goto BAIL; - } - - *size = traps.num_traps * sizeof (CoglVertexP2) * 6; - - //g_print ("new stroke prim\n"); - *primitive = _cairo_cogl_traps_to_composite_prim (surface, &traps, n_layers, one_shot); - if (!*primitive) { - status = CAIRO_INT_STATUS_NO_MEMORY; - goto BAIL; - } - -BAIL: - _cairo_traps_fini (&traps); - return status; -} - -static cairo_int_status_t -_cairo_cogl_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; - cairo_composite_rectangles_t extents; - CoglPipeline *pipeline; - cairo_status_t status; -#ifdef ENABLE_PATH_CACHE - cairo_cogl_path_stroke_meta_t *meta = NULL; - cairo_matrix_t transform_matrix; -#endif - cairo_matrix_t *transform = NULL; - gboolean one_shot = TRUE; - CoglPrimitive *prim = NULL; - cairo_bool_t new_prim = FALSE; - - if (! is_operator_supported (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* FIXME - support unbounded operators */ - if (!_cairo_operator_bounded_by_mask (op)) { - /* Currently IN this is the only unbounded operator we aim to support - * in cairo-cogl. */ - assert (op == CAIRO_OPERATOR_IN); - g_warning ("FIXME: handle stroking with unbounded operators!"); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = _cairo_composite_rectangles_init_for_stroke (&extents, - &surface->base, - op, source, path, - style, - ctm, - clip); - if (unlikely (status)) - return status; - -#ifdef ENABLE_PATH_CACHE - /* FIXME: we are currently leaking the meta state if we don't reach - * the cache_insert at the end. */ - meta = _cairo_cogl_get_path_stroke_meta (surface, style, tolerance); - if (meta) { - prim = meta->prim; - if (prim) { - cairo_matrix_multiply (&transform_matrix, &meta->ctm_inverse, surface->ctm); - transform = &transform_matrix; - } else if (meta->counter++ > 10) - one_shot = FALSE; - } -#endif - - if (!prim) { - int n_layers = _cairo_cogl_source_n_layers (source); - size_t prim_size = 0; - status = _cairo_cogl_stroke_to_primitive (surface, path, style, - ctm, ctm_inverse, tolerance, - n_layers, one_shot, - &prim, &prim_size); - if (unlikely (status)) - return status; - new_prim = TRUE; -#if defined (ENABLE_PATH_CACHE) - if (meta) { - meta->prim = cogl_object_ref (prim); - _cairo_cogl_path_stroke_meta_set_prim_size (surface, meta, prim_size); - } -#endif - } - - pipeline = get_source_mask_operator_destination_pipeline (NULL, source, - op, surface, &extents); - if (!pipeline) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_cogl_maybe_log_clip (surface, &extents); - - _cairo_cogl_journal_log_primitive (surface, pipeline, prim, transform); - - /* The journal will take a reference on the pipeline and primitive... */ - cogl_object_unref (pipeline); - if (new_prim) - cogl_object_unref (prim); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_cogl_path_fill_meta_t * -_cairo_cogl_path_fill_meta_reference (cairo_cogl_path_fill_meta_t *meta) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); - - _cairo_reference_count_inc (&meta->ref_count); - - return meta; -} - -static void -_cairo_cogl_path_fill_meta_destroy (cairo_cogl_path_fill_meta_t *meta) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&meta->ref_count)) - return; - - _cairo_path_fixed_fini (meta->user_path); - free (meta->user_path); - - if (meta->prim) - cogl_object_unref (meta->prim); - - free (meta); -} - -static cairo_cogl_path_fill_meta_t * -_cairo_cogl_path_fill_meta_lookup (cairo_cogl_device_t *ctx, - unsigned long hash, - cairo_path_fixed_t *user_path) -{ - cairo_cogl_path_fill_meta_t *ret; - cairo_cogl_path_fill_meta_t lookup; - - lookup.cache_entry.hash = hash; - lookup.user_path = user_path; - - ret = _cairo_cache_lookup (&ctx->path_fill_staging_cache, &lookup.cache_entry); - if (!ret) - ret = _cairo_cache_lookup (&ctx->path_fill_prim_cache, &lookup.cache_entry); - return ret; -} - -static void -_cairo_cogl_path_fill_meta_set_prim_size (cairo_cogl_surface_t *surface, - cairo_cogl_path_fill_meta_t *meta, - size_t size) -{ - /* now that we know the meta structure is associated with a primitive - * we promote it from the staging cache into the primitive cache. - */ - - /* XXX: _cairo_cache borks if you try and remove an entry that's already - * been evicted so we explicitly look it up first... */ - if (_cairo_cache_lookup (&to_device(surface->base.device)->path_fill_staging_cache, &meta->cache_entry)) { - _cairo_cogl_path_fill_meta_reference (meta); - _cairo_cache_remove (&to_device(surface->base.device)->path_fill_staging_cache, &meta->cache_entry); - } - - meta->cache_entry.size = size; - if (_cairo_cache_insert (&to_device(surface->base.device)->path_fill_prim_cache, &meta->cache_entry) != - CAIRO_STATUS_SUCCESS) - _cairo_cogl_path_fill_meta_destroy (meta); -} - -static cairo_cogl_path_fill_meta_t * -_cairo_cogl_get_path_fill_meta (cairo_cogl_surface_t *surface) -{ - unsigned long hash; - cairo_cogl_path_fill_meta_t *meta = NULL; - cairo_path_fixed_t *meta_path = NULL; - cairo_status_t status; - - if (!surface->user_path) - return NULL; - - hash = _cairo_path_fixed_hash (surface->user_path); - - meta = _cairo_cogl_path_fill_meta_lookup (to_device(surface->base.device), - hash, surface->user_path); - if (meta) - return meta; - - meta = calloc (1, sizeof (cairo_cogl_path_fill_meta_t)); - if (!meta) - goto BAIL; - meta->cache_entry.hash = hash; - meta->counter = 0; - CAIRO_REFERENCE_COUNT_INIT (&meta->ref_count, 1); - meta_path = malloc (sizeof (cairo_path_fixed_t)); - if (!meta_path) - goto BAIL; - /* FIXME: we should add a ref-counted wrapper for our user_paths - * so we don't have to keep copying them here! */ - status = _cairo_path_fixed_init_copy (meta_path, surface->user_path); - if (unlikely (status)) - goto BAIL; - meta->user_path = meta_path; - meta->ctm_inverse = *surface->ctm_inverse; - - /* To start with - until we associate a CoglPrimitive with the meta - * structure - we keep the meta in a staging structure until we - * see whether it actually gets re-used. */ - meta->cache_entry.size = 1; - if (_cairo_cache_insert (&to_device(surface->base.device)->path_fill_staging_cache, &meta->cache_entry) != - CAIRO_STATUS_SUCCESS) - _cairo_cogl_path_fill_meta_destroy (meta); - - return meta; - -BAIL: - free (meta_path); - free (meta); - return NULL; -} - -static cairo_int_status_t -_cairo_cogl_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_cogl_surface_t *surface = abstract_surface; - cairo_composite_rectangles_t extents; - cairo_status_t status; -#ifdef ENABLE_PATH_CACHE - cairo_cogl_path_fill_meta_t *meta = NULL; - cairo_matrix_t transform_matrix; -#endif - cairo_matrix_t *transform = NULL; - cairo_bool_t one_shot = TRUE; - CoglPrimitive *prim = NULL; - cairo_bool_t new_prim = FALSE; - CoglPipeline *pipeline; - - if (! is_operator_supported (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* FIXME - support unbounded operators */ - if (!_cairo_operator_bounded_by_mask (op)) { - /* Currently IN this is the only unbounded operator we aim to support - * in cairo-cogl. */ - assert (op == CAIRO_OPERATOR_IN); - g_warning ("FIXME: handle filling with unbounded operators!"); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = _cairo_composite_rectangles_init_for_fill (&extents, - &surface->base, - op, source, path, - clip); - if (unlikely (status)) - return status; - -#ifndef FILL_WITH_COGL_PATH -#ifdef ENABLE_PATH_CACHE - meta = _cairo_cogl_get_path_fill_meta (surface); - if (meta) { - prim = meta->prim; - if (prim) { - cairo_matrix_multiply (&transform_matrix, &meta->ctm_inverse, surface->ctm); - transform = &transform_matrix; - } else if (meta->counter++ > 10) - one_shot = FALSE; - } -#endif /* ENABLE_PATH_CACHE */ - - if (!prim) { - int n_layers = _cairo_cogl_source_n_layers (source); - size_t prim_size; - status = _cairo_cogl_fill_to_primitive (surface, path, fill_rule, tolerance, - one_shot, n_layers, &prim, &prim_size); - if (unlikely (status)) - return status; - new_prim = TRUE; -#ifdef ENABLE_PATH_CACHE - if (meta) { - meta->prim = cogl_object_ref (prim); - _cairo_cogl_path_fill_meta_set_prim_size (surface, meta, prim_size); - } -#endif /* ENABLE_PATH_CACHE */ - } - -#endif /* !FILL_WITH_COGL_PATH */ - - pipeline = get_source_mask_operator_destination_pipeline (NULL, source, - op, surface, &extents); - if (!pipeline) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_cogl_maybe_log_clip (surface, &extents); - -#ifndef FILL_WITH_COGL_PATH - _cairo_cogl_journal_log_primitive (surface, pipeline, prim, transform); - /* The journal will take a reference on the prim */ - if (new_prim) - cogl_object_unref (prim); -#else - CoglPath * cogl_path = _cairo_cogl_util_path_from_cairo (path, fill_rule, tolerance); - _cairo_cogl_journal_log_path (surface, pipeline, cogl_path); - cogl_object_unref (cogl_path); -#endif - - /* The journal will take a reference on the pipeline... */ - cogl_object_unref (pipeline); - - return CAIRO_INT_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_cogl_surface_fill_rectangle (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - double x, - double y, - double width, - double height, - cairo_matrix_t *ctm, - const cairo_clip_t *clip) -{ - cairo_cogl_surface_t *surface = abstract_surface; - CoglPipeline *pipeline; - - if (! is_operator_supported (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* FIXME - support unbounded operators */ - if (!_cairo_operator_bounded_by_mask (op)) { - /* Currently IN this is the only unbounded operator we aim to support - * in cairo-cogl. */ - assert (op == CAIRO_OPERATOR_IN); - g_warning ("FIXME: handle filling with unbounded operators!"); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* FIXME */ -#if 0 - status = _cairo_composite_rectangles_init_for_fill_rectangle (&extents, - &surface->base, - op, source, path, - clip); - if (unlikely (status)) - return status; -#endif - - if (source->type == CAIRO_PATTERN_TYPE_SOLID) { - double x1 = x; - double y1 = y; - double x2 = x1 + width; - double y2 = y1 + height; - - pipeline = get_source_mask_operator_destination_pipeline (NULL, source, - op, surface, NULL); - if (!pipeline) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_cogl_log_clip (surface, clip); - - _cairo_cogl_journal_log_rectangle (surface, - pipeline, - x1, y1, x2, y2, - 0, - ctm); - return CAIRO_INT_STATUS_SUCCESS; - } else - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* TODO: - * We need to acquire the textures here, look at the corresponding - * attributes and see if this can be trivially handled by logging - * a textured rectangle only needing simple scaling or translation - * of texture coordinates. - * - * At this point we should also aim to remap the default - * EXTEND_NONE mode to EXTEND_PAD which is more efficient if we - * know it makes no difference either way since we can map that to - * CLAMP_TO_EDGE. - */ -} - -static cairo_int_status_t -_cairo_cogl_surface_show_glyphs (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -const cairo_surface_backend_t _cairo_cogl_surface_backend = { - CAIRO_SURFACE_TYPE_COGL, - _cairo_cogl_surface_finish, -#ifdef NEED_COGL_CONTEXT - _cairo_cogl_context_create, -#else - _cairo_default_context_create, -#endif - - _cairo_cogl_surface_create_similar, - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - _cairo_cogl_surface_acquire_source_image, - _cairo_cogl_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_cogl_surface_get_extents, - NULL, /* get_font_options */ - - _cairo_cogl_surface_flush, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_cogl_surface_paint, - _cairo_cogl_surface_mask, - _cairo_cogl_surface_stroke, - _cairo_cogl_surface_fill, - NULL, /* fill_stroke*/ - _cairo_surface_fallback_glyphs, -}; - -static cairo_surface_t * -_cairo_cogl_surface_create_full (cairo_cogl_device_t *dev, - cairo_bool_t ignore_alpha, - CoglFramebuffer *framebuffer, - CoglTexture *texture) -{ - cairo_cogl_surface_t *surface; - cairo_status_t status; - - status = cairo_device_acquire (&dev->base); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - surface = malloc (sizeof (cairo_cogl_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface->ignore_alpha = ignore_alpha; - - surface->framebuffer = framebuffer; - if (framebuffer) { - surface->width = cogl_framebuffer_get_width (framebuffer); - surface->height = cogl_framebuffer_get_height (framebuffer); - surface->cogl_format = cogl_framebuffer_get_color_format (framebuffer); - cogl_object_ref (framebuffer); - } - - /* FIXME: If texture == NULL and we are given an offscreen framebuffer - * then we want a way to poke inside the framebuffer to get a texture */ - surface->texture = texture; - if (texture) { - if (!framebuffer) { - surface->width = cogl_texture_get_width (texture); - surface->height = cogl_texture_get_height (texture); - surface->cogl_format = cogl_texture_get_format (texture); - } - cogl_object_ref (texture); - } - - assert(surface->width && surface->height); - - surface->journal = NULL; - - surface->buffer_stack = NULL; - surface->buffer_stack_size = 4096; - - surface->last_clip = NULL; - - surface->n_clip_updates_per_frame = 0; - - _cairo_surface_init (&surface->base, - &_cairo_cogl_surface_backend, - &dev->base, - CAIRO_CONTENT_COLOR_ALPHA); - - return &surface->base; -} - -cairo_surface_t * -cairo_cogl_surface_create (cairo_device_t *abstract_device, - CoglFramebuffer *framebuffer) -{ - cairo_cogl_device_t *dev = (cairo_cogl_device_t *)abstract_device; - - if (abstract_device == NULL) - return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_ERROR); - - if (abstract_device->status) - return _cairo_surface_create_in_error (abstract_device->status); - - if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_COGL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - - return _cairo_cogl_surface_create_full (dev, FALSE, framebuffer, NULL); -} -slim_hidden_def (cairo_cogl_surface_create); - -CoglFramebuffer * -cairo_cogl_surface_get_framebuffer (cairo_surface_t *abstract_surface) -{ - cairo_cogl_surface_t *surface; - - if (abstract_surface->backend != &_cairo_cogl_surface_backend) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - surface = (cairo_cogl_surface_t *) abstract_surface; - - return surface->framebuffer; -} -slim_hidden_def (cairo_cogl_surface_get_framebuffer); - -CoglTexture * -cairo_cogl_surface_get_texture (cairo_surface_t *abstract_surface) -{ - cairo_cogl_surface_t *surface; - - if (abstract_surface->backend != &_cairo_cogl_surface_backend) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - surface = (cairo_cogl_surface_t *) abstract_surface; - - return surface->texture; -} -slim_hidden_def (cairo_cogl_surface_get_texture); - -static cairo_status_t -_cairo_cogl_device_flush (void *device) -{ - cairo_status_t status; - - status = cairo_device_acquire (device); - if (unlikely (status)) - return status; - - /* XXX: we don't need to flush Cogl here, we just need to flush - * any batching we do of compositing primitives. */ - - cairo_device_release (device); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_cogl_device_finish (void *device) -{ - cairo_status_t status; - - status = cairo_device_acquire (device); - if (unlikely (status)) - return; - - /* XXX: Drop references to external resources */ - - cairo_device_release (device); -} - -static void -_cairo_cogl_device_destroy (void *device) -{ - cairo_cogl_device_t *dev = device; - - /* FIXME: Free stuff! */ - - g_free (dev); -} - -static const cairo_device_backend_t _cairo_cogl_device_backend = { - CAIRO_DEVICE_TYPE_COGL, - - NULL, /* lock */ - NULL, /* unlock */ - - _cairo_cogl_device_flush, - _cairo_cogl_device_finish, - _cairo_cogl_device_destroy, -}; - -static cairo_bool_t -set_blend (CoglPipeline *pipeline, const char *blend_string) -{ - GError *error = NULL; - if (!cogl_pipeline_set_blend (pipeline, blend_string, &error)) { - g_warning ("Unsupported blend string with current gpu/driver: %s", blend_string); - g_error_free (error); - return FALSE; - } - return TRUE; -} - -static cairo_bool_t -_cairo_cogl_setup_op_state (CoglPipeline *pipeline, cairo_operator_t op) -{ - cairo_bool_t status = FALSE; - - switch ((int)op) - { - case CAIRO_OPERATOR_SOURCE: - status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)"); - break; - case CAIRO_OPERATOR_OVER: - status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR * (1 - SRC_COLOR[A]))"); - break; - case CAIRO_OPERATOR_IN: - status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * DST_COLOR[A], 0)"); - break; - case CAIRO_OPERATOR_DEST_OVER: - status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), DST_COLOR)"); - break; - case CAIRO_OPERATOR_DEST_IN: - status = set_blend (pipeline, "RGBA = ADD (0, DST_COLOR * SRC_COLOR[A])"); - break; - case CAIRO_OPERATOR_ADD: - status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR)"); - break; - } - - return status; -} - -static void -create_templates_for_op (cairo_cogl_device_t *dev, cairo_operator_t op) -{ - CoglPipeline *base = cogl_pipeline_new (); - CoglPipeline *pipeline; - CoglColor color; - - if (!_cairo_cogl_setup_op_state (base, op)) { - cogl_object_unref (base); - return; - } - - dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID] = base; - - pipeline = cogl_pipeline_copy (base); - cogl_pipeline_set_layer_texture (pipeline, 0, dev->dummy_texture); - dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_TEXTURE] = pipeline; - - pipeline = cogl_pipeline_copy (base); - cogl_pipeline_set_layer_combine (pipeline, 1, - "RGBA = MODULATE (PREVIOUS, CONSTANT[A])", - NULL); - cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color); - cogl_pipeline_set_layer_texture (pipeline, 1, dev->dummy_texture); - dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_MASK_SOLID] = pipeline; - - pipeline = cogl_pipeline_copy (base); - cogl_pipeline_set_layer_combine (pipeline, 1, - "RGBA = MODULATE (PREVIOUS, TEXTURE[A])", - NULL); - cogl_pipeline_set_layer_texture (pipeline, 1, dev->dummy_texture); - dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_MASK_TEXTURE] = pipeline; -} - -cairo_device_t * -cairo_cogl_device_create (CoglContext *cogl_context) -{ - cairo_cogl_device_t *dev = g_new0 (cairo_cogl_device_t, 1); - cairo_status_t status; - - dev->backend_vtable_initialized = FALSE; - - dev->cogl_context = cogl_context; - - dev->dummy_texture = cogl_texture_new_with_size (1, 1, - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_ANY); - if (!dev->dummy_texture) - goto ERROR; - - memset (dev->template_pipelines, 0, sizeof (dev->template_pipelines)); - create_templates_for_op (dev, CAIRO_OPERATOR_SOURCE); - create_templates_for_op (dev, CAIRO_OPERATOR_OVER); - create_templates_for_op (dev, CAIRO_OPERATOR_IN); - create_templates_for_op (dev, CAIRO_OPERATOR_DEST_OVER); - create_templates_for_op (dev, CAIRO_OPERATOR_DEST_IN); - create_templates_for_op (dev, CAIRO_OPERATOR_ADD); - - status = _cairo_cache_init (&dev->linear_cache, - _cairo_cogl_linear_gradient_equal, - NULL, - (cairo_destroy_func_t) _cairo_cogl_linear_gradient_destroy, - CAIRO_COGL_LINEAR_GRADIENT_CACHE_SIZE); - if (unlikely (status)) - return _cairo_device_create_in_error(status); - - status = _cairo_cache_init (&dev->path_fill_staging_cache, - _cairo_cogl_path_fill_meta_equal, - NULL, - (cairo_destroy_func_t) _cairo_cogl_path_fill_meta_destroy, - 1000); - - status = _cairo_cache_init (&dev->path_stroke_staging_cache, - _cairo_cogl_path_stroke_meta_equal, - NULL, - (cairo_destroy_func_t) _cairo_cogl_path_stroke_meta_destroy, - 1000); - - status = _cairo_cache_init (&dev->path_fill_prim_cache, - _cairo_cogl_path_fill_meta_equal, - NULL, - (cairo_destroy_func_t) _cairo_cogl_path_fill_meta_destroy, - CAIRO_COGL_PATH_META_CACHE_SIZE); - - status = _cairo_cache_init (&dev->path_stroke_prim_cache, - _cairo_cogl_path_stroke_meta_equal, - NULL, - (cairo_destroy_func_t) _cairo_cogl_path_stroke_meta_destroy, - CAIRO_COGL_PATH_META_CACHE_SIZE); - - _cairo_device_init (&dev->base, &_cairo_cogl_device_backend); - return &dev->base; - -ERROR: - g_free (dev); - return _cairo_device_create_in_error (CAIRO_STATUS_DEVICE_ERROR); -} -slim_hidden_def (cairo_cogl_device_create); - -void -cairo_cogl_surface_end_frame (cairo_surface_t *abstract_surface) -{ - cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; - cairo_surface_flush (abstract_surface); - - //g_print ("n_clip_update_per_frame = %d\n", surface->n_clip_updates_per_frame); - surface->n_clip_updates_per_frame = 0; -} -slim_hidden_def (cairo_cogl_surface_end_frame); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils-private.h deleted file mode 100644 index ee77f3034c3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils-private.h +++ /dev/null @@ -1,54 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ - -#ifndef CAIRO_COGL_UTILS_PRIVATE_H -#define CAIRO_COGL_UTILS_PRIVATE_H - -#include "cairo-path-fixed-private.h" -#include - -CoglPath * -_cairo_cogl_util_path_from_cairo (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - float tolerance); - -int -_cairo_cogl_util_next_p2 (int a); - -#define CAIRO_FIXED_ONE_FLOAT ((float)(1 << CAIRO_FIXED_FRAC_BITS)) - -static inline float -_cairo_cogl_util_fixed_to_float (cairo_fixed_t f) -{ - return ((float) f) / CAIRO_FIXED_ONE_FLOAT; -} - -#endif /* CAIRO_COGL_UTILS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils.c deleted file mode 100644 index 4f02aaa52da..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl-utils.c +++ /dev/null @@ -1,126 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Robert Bragg - */ - -#include "cairoint.h" -#include "cairo-cogl-utils-private.h" - -#include -#include - -static cairo_status_t -_cogl_move_to (void *closure, - const cairo_point_t *point) -{ - cogl_path_move_to (closure, - _cairo_cogl_util_fixed_to_float (point->x), - _cairo_cogl_util_fixed_to_float (point->y)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cogl_line_to (void *closure, - const cairo_point_t *point) -{ - cogl_path_line_to (closure, - _cairo_cogl_util_fixed_to_float (point->x), - _cairo_cogl_util_fixed_to_float (point->y)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cogl_curve_to (void *closure, - const cairo_point_t *p0, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - cogl_path_curve_to (closure, - _cairo_cogl_util_fixed_to_float (p0->x), - _cairo_cogl_util_fixed_to_float (p0->y), - _cairo_cogl_util_fixed_to_float (p1->x), - _cairo_cogl_util_fixed_to_float (p1->y), - _cairo_cogl_util_fixed_to_float (p2->x), - _cairo_cogl_util_fixed_to_float (p2->y)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cogl_close_path (void *closure) -{ - cogl_path_close (closure); - return CAIRO_STATUS_SUCCESS; -} - -CoglPath * -_cairo_cogl_util_path_from_cairo (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - float tolerance) -{ - CoglPath *cogl_path = cogl_path_new (); - cairo_status_t status; - - if (fill_rule == CAIRO_FILL_RULE_EVEN_ODD) - cogl_path_set_fill_rule (cogl_path, COGL_PATH_FILL_RULE_EVEN_ODD); - else - cogl_path_set_fill_rule (cogl_path, COGL_PATH_FILL_RULE_NON_ZERO); - -#ifdef USE_CAIRO_PATH_FLATTENER - /* XXX: rely on cairo to do path flattening, since it seems Cogl's - * curve_to flattening is much slower */ - status = _cairo_path_fixed_interpret_flat (path, - _cogl_move_to, - _cogl_line_to, - _cogl_close_path, - cogl_path, - tolerance); -#else - status = _cairo_path_fixed_interpret (path, - _cogl_move_to, - _cogl_line_to, - _cogl_curve_to, - _cogl_close_path, - cogl_path); -#endif - - assert (status == CAIRO_STATUS_SUCCESS); - return cogl_path; -} - -int -_cairo_cogl_util_next_p2 (int a) -{ - int rval = 1; - - while (rval < a) - rval <<= 1; - - return rval; -} - diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl.h deleted file mode 100644 index f270d74d307..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-cogl.h +++ /dev/null @@ -1,69 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Corporation. - * - * Contributor(s): - * Robert Bragg - */ - -#ifndef CAIRO_VG_H -#define CAIRO_VG_H - -#include "cairo.h" - -#if CAIRO_HAS_COGL_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_device_t * -cairo_cogl_device_create (CoglContext *context); - -cairo_public cairo_surface_t * -cairo_cogl_surface_create (cairo_device_t *device, - CoglFramebuffer *framebuffer); - -cairo_public CoglFramebuffer * -cairo_cogl_surface_get_framebuffer (cairo_surface_t *surface); - -cairo_public CoglTexture * -cairo_cogl_surface_get_texture (cairo_surface_t *surface); - -cairo_public void -cairo_cogl_surface_end_frame (cairo_surface_t *surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_COGL_SURFACE*/ -# error Cairo was not compiled with support for the Cogl backend -#endif /* CAIRO_HAS_COGL_SURFACE*/ - -#endif /* CAIRO_COGL_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-color.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-color.c deleted file mode 100644 index c2a11a17738..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-color.c +++ /dev/null @@ -1,193 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -static cairo_color_t const cairo_color_white = { - 1.0, 1.0, 1.0, 1.0, - 0xffff, 0xffff, 0xffff, 0xffff -}; - -static cairo_color_t const cairo_color_black = { - 0.0, 0.0, 0.0, 1.0, - 0x0, 0x0, 0x0, 0xffff -}; - -static cairo_color_t const cairo_color_transparent = { - 0.0, 0.0, 0.0, 0.0, - 0x0, 0x0, 0x0, 0x0 -}; - -static cairo_color_t const cairo_color_magenta = { - 1.0, 0.0, 1.0, 1.0, - 0xffff, 0x0, 0xffff, 0xffff -}; - -const cairo_color_t * -_cairo_stock_color (cairo_stock_t stock) -{ - switch (stock) { - case CAIRO_STOCK_WHITE: - return &cairo_color_white; - case CAIRO_STOCK_BLACK: - return &cairo_color_black; - case CAIRO_STOCK_TRANSPARENT: - return &cairo_color_transparent; - - case CAIRO_STOCK_NUM_COLORS: - default: - ASSERT_NOT_REACHED; - /* If the user can get here somehow, give a color that indicates a - * problem. */ - return &cairo_color_magenta; - } -} - -/* Convert a double in [0.0, 1.0] to an integer in [0, 65535] - * The conversion is designed to choose the integer i such that - * i / 65535.0 is as close as possible to the input value. - */ -uint16_t -_cairo_color_double_to_short (double d) -{ - return d * 65535.0 + 0.5; -} - -static void -_cairo_color_compute_shorts (cairo_color_t *color) -{ - color->red_short = _cairo_color_double_to_short (color->red * color->alpha); - color->green_short = _cairo_color_double_to_short (color->green * color->alpha); - color->blue_short = _cairo_color_double_to_short (color->blue * color->alpha); - color->alpha_short = _cairo_color_double_to_short (color->alpha); -} - -void -_cairo_color_init_rgba (cairo_color_t *color, - double red, double green, double blue, - double alpha) -{ - color->red = red; - color->green = green; - color->blue = blue; - color->alpha = alpha; - - _cairo_color_compute_shorts (color); -} - -void -_cairo_color_multiply_alpha (cairo_color_t *color, - double alpha) -{ - color->alpha *= alpha; - - _cairo_color_compute_shorts (color); -} - -void -_cairo_color_get_rgba (cairo_color_t *color, - double *red, - double *green, - double *blue, - double *alpha) -{ - *red = color->red; - *green = color->green; - *blue = color->blue; - *alpha = color->alpha; -} - -void -_cairo_color_get_rgba_premultiplied (cairo_color_t *color, - double *red, - double *green, - double *blue, - double *alpha) -{ - *red = color->red * color->alpha; - *green = color->green * color->alpha; - *blue = color->blue * color->alpha; - *alpha = color->alpha; -} - -/* NB: This function works both for unmultiplied and premultiplied colors */ -cairo_bool_t -_cairo_color_equal (const cairo_color_t *color_a, - const cairo_color_t *color_b) -{ - if (color_a == color_b) - return TRUE; - - if (color_a->alpha_short != color_b->alpha_short) - return FALSE; - - if (color_a->alpha_short == 0) - return TRUE; - - return color_a->red_short == color_b->red_short && - color_a->green_short == color_b->green_short && - color_a->blue_short == color_b->blue_short; -} - -cairo_bool_t -_cairo_color_stop_equal (const cairo_color_stop_t *color_a, - const cairo_color_stop_t *color_b) -{ - if (color_a == color_b) - return TRUE; - - return color_a->alpha_short == color_b->alpha_short && - color_a->red_short == color_b->red_short && - color_a->green_short == color_b->green_short && - color_a->blue_short == color_b->blue_short; -} - -cairo_content_t -_cairo_color_get_content (const cairo_color_t *color) -{ - if (CAIRO_COLOR_IS_OPAQUE (color)) - return CAIRO_CONTENT_COLOR; - - if (color->red_short == 0 && - color->green_short == 0 && - color->blue_short == 0) - { - return CAIRO_CONTENT_ALPHA; - } - - return CAIRO_CONTENT_COLOR_ALPHA; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-combsort-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-combsort-inline.h deleted file mode 100644 index d359faeb5b8..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-combsort-inline.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -/* This fragment implements a comb sort (specifically combsort11) */ -#ifndef _HAVE_CAIRO_COMBSORT_NEWGAP -#define _HAVE_CAIRO_COMBSORT_NEWGAP -static inline unsigned int -_cairo_combsort_newgap (unsigned int gap) -{ - gap = 10 * gap / 13; - if (gap == 9 || gap == 10) - gap = 11; - if (gap < 1) - gap = 1; - return gap; -} -#endif - -#define CAIRO_COMBSORT_DECLARE(NAME, TYPE, CMP) \ -static void \ -NAME (TYPE *base, unsigned int nmemb) \ -{ \ - unsigned int gap = nmemb; \ - unsigned int i, j; \ - int swapped; \ - do { \ - gap = _cairo_combsort_newgap (gap); \ - swapped = gap > 1; \ - for (i = 0; i < nmemb-gap ; i++) { \ - j = i + gap; \ - if (CMP (base[i], base[j]) > 0 ) { \ - TYPE tmp; \ - tmp = base[i]; \ - base[i] = base[j]; \ - base[j] = tmp; \ - swapped = 1; \ - } \ - } \ - } while (swapped); \ -} - -#define CAIRO_COMBSORT_DECLARE_WITH_DATA(NAME, TYPE, CMP) \ -static void \ -NAME (TYPE *base, unsigned int nmemb, void *data) \ -{ \ - unsigned int gap = nmemb; \ - unsigned int i, j; \ - int swapped; \ - do { \ - gap = _cairo_combsort_newgap (gap); \ - swapped = gap > 1; \ - for (i = 0; i < nmemb-gap ; i++) { \ - j = i + gap; \ - if (CMP (base[i], base[j], data) > 0 ) { \ - TYPE tmp; \ - tmp = base[i]; \ - base[i] = base[j]; \ - base[j] = tmp; \ - swapped = 1; \ - } \ - } \ - } while (swapped); \ -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compiler-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compiler-private.h deleted file mode 100644 index 216e71b4ec3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compiler-private.h +++ /dev/null @@ -1,244 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_COMPILER_PRIVATE_H -#define CAIRO_COMPILER_PRIVATE_H - -#include "cairo.h" - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* Size in bytes of buffer to use off the stack per functions. - * Mostly used by text functions. For larger allocations, they'll - * malloc(). */ -#ifndef CAIRO_STACK_BUFFER_SIZE -#define CAIRO_STACK_BUFFER_SIZE (512 * sizeof (int)) -#endif - -#define CAIRO_STACK_ARRAY_LENGTH(T) (CAIRO_STACK_BUFFER_SIZE / sizeof(T)) - -/* - * The goal of this block is to define the following macros for - * providing faster linkage to functions in the public API for calls - * from within cairo. - * - * slim_hidden_proto(f) - * slim_hidden_proto_no_warn(f) - * - * Declares `f' as a library internal function and hides the - * function from the global symbol table. This macro must be - * expanded after `f' has been declared with a prototype but before - * any calls to the function are seen by the compiler. The no_warn - * variant inhibits warnings about the return value being unused at - * call sites. The macro works by renaming `f' to an internal name - * in the symbol table and hiding that. As far as cairo internal - * calls are concerned they're calling a library internal function - * and thus don't need to bounce via the PLT. - * - * slim_hidden_def(f) - * - * Exports `f' back to the global symbol table. This macro must be - * expanded right after the function definition and only for symbols - * hidden previously with slim_hidden_proto(). The macro works by - * adding a global entry to the symbol table which points at the - * internal name of `f' created by slim_hidden_proto(). - * - * Functions in the public API which aren't called by the library - * don't need to be hidden and re-exported using the slim hidden - * macros. - */ -#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun) -# define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private -# define slim_hidden_proto_no_warn(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn -# define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name)) -# define slim_hidden_int_name(name) INT_##name -# define slim_hidden_proto1(name, internal) \ - extern __typeof (name) name \ - __asm__ (slim_hidden_asmname (internal)) -# define slim_hidden_def1(name, internal) \ - extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name)) \ - __attribute__((__alias__(slim_hidden_asmname(internal)))) -# define slim_hidden_ulp slim_hidden_ulp1(__USER_LABEL_PREFIX__) -# define slim_hidden_ulp1(x) slim_hidden_ulp2(x) -# define slim_hidden_ulp2(x) #x -# define slim_hidden_asmname(name) slim_hidden_asmname1(name) -# define slim_hidden_asmname1(name) slim_hidden_ulp #name -#else -# define slim_hidden_proto(name) int _cairo_dummy_prototype(void) -# define slim_hidden_proto_no_warn(name) int _cairo_dummy_prototype(void) -# define slim_hidden_def(name) int _cairo_dummy_prototype(void) -#endif - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \ - __attribute__((__format__(__printf__, fmt_index, va_index))) -#else -#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) -#endif - -/* slim_internal.h */ -#define CAIRO_HAS_HIDDEN_SYMBOLS 1 -#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && \ - (defined(__ELF__) || defined(__APPLE__)) && \ - !defined(__sun) -#define cairo_private_no_warn __attribute__((__visibility__("hidden"))) -#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) -#define cairo_private_no_warn __hidden -#else /* not gcc >= 3.3 and not Sun Studio >= 8 */ -#define cairo_private_no_warn -#undef CAIRO_HAS_HIDDEN_SYMBOLS -#endif - -#ifndef WARN_UNUSED_RESULT -#define WARN_UNUSED_RESULT -#endif -/* Add attribute(warn_unused_result) if supported */ -#define cairo_warn WARN_UNUSED_RESULT -#define cairo_private cairo_private_no_warn cairo_warn - -/* This macro allow us to deprecate a function by providing an alias - for the old function name to the new function name. With this - macro, binary compatibility is preserved. The macro only works on - some platforms --- tough. - - Meanwhile, new definitions in the public header file break the - source code so that it will no longer link against the old - symbols. Instead it will give a descriptive error message - indicating that the old function has been deprecated by the new - function. -*/ -#if __GNUC__ >= 2 && defined(__ELF__) -# define CAIRO_FUNCTION_ALIAS(old, new) \ - extern __typeof (new) old \ - __asm__ ("" #old) \ - __attribute__((__alias__("" #new))) -#else -# define CAIRO_FUNCTION_ALIAS(old, new) -#endif - -/* - * Cairo uses the following function attributes in order to improve the - * generated code (effectively by manual inter-procedural analysis). - * - * 'cairo_pure': The function is only allowed to read from its arguments - * and global memory (i.e. following a pointer argument or - * accessing a shared variable). The return value should - * only depend on its arguments, and for an identical set of - * arguments should return the same value. - * - * 'cairo_const': The function is only allowed to read from its arguments. - * It is not allowed to access global memory. The return - * value should only depend its arguments, and for an - * identical set of arguments should return the same value. - * This is currently the most strict function attribute. - * - * Both these function attributes allow gcc to perform CSE and - * constant-folding, with 'cairo_const 'also guaranteeing that pointer contents - * do not change across the function call. - */ -#if __GNUC__ >= 3 -#define cairo_pure __attribute__((pure)) -#define cairo_const __attribute__((const)) -#define cairo_always_inline inline __attribute__((always_inline)) -#else -#define cairo_pure -#define cairo_const -#define cairo_always_inline inline -#endif - -#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) -#define likely(expr) (__builtin_expect (!!(expr), 1)) -#define unlikely(expr) (__builtin_expect (!!(expr), 0)) -#else -#define likely(expr) (expr) -#define unlikely(expr) (expr) -#endif - -#ifndef __GNUC__ -#undef __attribute__ -#define __attribute__(x) -#endif - -#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) -#define access _access -#define fdopen _fdopen -#define hypot _hypot -#define pclose _pclose -#define popen _popen -#define snprintf _snprintf -#define strdup _strdup -#define unlink _unlink -#define vsnprintf _vsnprintf -#endif - -#ifdef _MSC_VER -#ifndef __cplusplus -#undef inline -#define inline __inline -#endif -#endif - -#if defined(_MSC_VER) && defined(_M_IX86) -/* When compiling with /Gy and /OPT:ICF identical functions will be folded in together. - The CAIRO_ENSURE_UNIQUE macro ensures that a function is always unique and - will never be folded into another one. Something like this might eventually - be needed for GCC but it seems fine for now. */ -#define CAIRO_ENSURE_UNIQUE \ - do { \ - char file[] = __FILE__; \ - __asm { \ - __asm jmp __internal_skip_line_no \ - __asm _emit (__COUNTER__ & 0xff) \ - __asm _emit ((__COUNTER__>>8) & 0xff) \ - __asm _emit ((__COUNTER__>>16) & 0xff)\ - __asm _emit ((__COUNTER__>>24) & 0xff)\ - __asm lea eax, dword ptr file \ - __asm __internal_skip_line_no: \ - }; \ - } while (0) -#else -#define CAIRO_ENSURE_UNIQUE do { } while (0) -#endif - -#ifdef __STRICT_ANSI__ -#undef inline -#define inline __inline__ -#endif - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles-private.h deleted file mode 100644 index fd7728995de..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles-private.h +++ /dev/null @@ -1,159 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H -#define CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-error-private.h" -#include "cairo-pattern-private.h" - -CAIRO_BEGIN_DECLS - -/* Rectangles that take part in a composite operation. - * - * The source and mask track the extents of the respective patterns in device - * space. The unbounded rectangle is essentially the clip rectangle. And the - * intersection of all is the bounded rectangle, which is the minimum extents - * the operation may require. Whether or not the operation is actually bounded - * is tracked in the is_bounded boolean. - * - */ -struct _cairo_composite_rectangles { - cairo_surface_t *surface; - cairo_operator_t op; - - cairo_rectangle_int_t source; - cairo_rectangle_int_t mask; - cairo_rectangle_int_t destination; - - cairo_rectangle_int_t bounded; /* source? IN mask? IN unbounded */ - cairo_rectangle_int_t unbounded; /* destination IN clip */ - uint32_t is_bounded; - - cairo_rectangle_int_t source_sample_area; - cairo_rectangle_int_t mask_sample_area; - - cairo_pattern_union_t source_pattern; - cairo_pattern_union_t mask_pattern; - const cairo_pattern_t *original_source_pattern; - const cairo_pattern_t *original_mask_pattern; - - cairo_clip_t *clip; /* clip will be reduced to the minimal container */ -}; - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_paint (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_mask (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_stroke (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_fill (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_boxes (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_boxes_t *boxes, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_polygon (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_polygon_t *polygon, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_clip_t *clip, - cairo_bool_t *overlap); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_intersect_source_extents (cairo_composite_rectangles_t *extents, - const cairo_box_t *box); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t *extents, - const cairo_box_t *box); - -cairo_private cairo_bool_t -_cairo_composite_rectangles_can_reduce_clip (cairo_composite_rectangles_t *composite, - cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_composite_rectangles_add_to_damage (cairo_composite_rectangles_t *composite, - cairo_boxes_t *damage); - -cairo_private void -_cairo_composite_rectangles_fini (cairo_composite_rectangles_t *extents); - -CAIRO_END_DECLS - -#endif /* CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles.c deleted file mode 100644 index 6c3e97d4a97..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-composite-rectangles.c +++ /dev/null @@ -1,500 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-error-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-pattern-private.h" - -/* A collection of routines to facilitate writing compositors. */ - -void _cairo_composite_rectangles_fini (cairo_composite_rectangles_t *extents) -{ - _cairo_clip_destroy (extents->clip); -} - -static void -_cairo_composite_reduce_pattern (const cairo_pattern_t *src, - cairo_pattern_union_t *dst) -{ - int tx, ty; - - _cairo_pattern_init_static_copy (&dst->base, src); - if (dst->base.type == CAIRO_PATTERN_TYPE_SOLID) - return; - - dst->base.filter = _cairo_pattern_analyze_filter (&dst->base); - - tx = ty = 0; - if (_cairo_matrix_is_pixman_translation (&dst->base.matrix, - dst->base.filter, - &tx, &ty)) - { - dst->base.matrix.x0 = tx; - dst->base.matrix.y0 = ty; - } -} - -static inline cairo_bool_t -_cairo_composite_rectangles_init (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - if (_cairo_clip_is_all_clipped (clip)) - return FALSE; - - extents->surface = surface; - extents->op = op; - - _cairo_surface_get_extents (surface, &extents->destination); - extents->clip = NULL; - - extents->unbounded = extents->destination; - if (clip && ! _cairo_rectangle_intersect (&extents->unbounded, - _cairo_clip_get_extents (clip))) - return FALSE; - - extents->bounded = extents->unbounded; - extents->is_bounded = _cairo_operator_bounded_by_either (op); - - extents->original_source_pattern = source; - _cairo_composite_reduce_pattern (source, &extents->source_pattern); - - _cairo_pattern_get_extents (&extents->source_pattern.base, - &extents->source); - if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) { - if (! _cairo_rectangle_intersect (&extents->bounded, &extents->source)) - return FALSE; - } - - extents->original_mask_pattern = NULL; - extents->mask_pattern.base.type = CAIRO_PATTERN_TYPE_SOLID; - extents->mask_pattern.solid.color.alpha = 1.; /* XXX full initialisation? */ - extents->mask_pattern.solid.color.alpha_short = 0xffff; - - return TRUE; -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_paint (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - if (! _cairo_composite_rectangles_init (extents, - surface, op, source, clip)) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - extents->mask = extents->destination; - - extents->clip = _cairo_clip_reduce_for_composite (clip, extents); - if (_cairo_clip_is_all_clipped (extents->clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (! _cairo_rectangle_intersect (&extents->unbounded, - _cairo_clip_get_extents (extents->clip))) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) - _cairo_pattern_sampled_area (&extents->source_pattern.base, - &extents->bounded, - &extents->source_sample_area); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_composite_rectangles_intersect (cairo_composite_rectangles_t *extents, - const cairo_clip_t *clip) -{ - cairo_bool_t ret; - - ret = _cairo_rectangle_intersect (&extents->bounded, &extents->mask); - if (! ret && extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE)) { - extents->unbounded = extents->bounded; - } else if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) { - if (!_cairo_rectangle_intersect (&extents->unbounded, &extents->mask)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - extents->clip = _cairo_clip_reduce_for_composite (clip, extents); - if (_cairo_clip_is_all_clipped (extents->clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (! _cairo_rectangle_intersect (&extents->unbounded, - _cairo_clip_get_extents (extents->clip))) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (! _cairo_rectangle_intersect (&extents->bounded, - _cairo_clip_get_extents (extents->clip)) && - extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) - _cairo_pattern_sampled_area (&extents->source_pattern.base, - &extents->bounded, - &extents->source_sample_area); - if (extents->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) { - _cairo_pattern_sampled_area (&extents->mask_pattern.base, - &extents->bounded, - &extents->mask_sample_area); - if (extents->mask_sample_area.width == 0 || - extents->mask_sample_area.height == 0) { - _cairo_composite_rectangles_fini (extents); - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_composite_rectangles_intersect_source_extents (cairo_composite_rectangles_t *extents, - const cairo_box_t *box) -{ - cairo_rectangle_int_t rect; - cairo_clip_t *clip; - - _cairo_box_round_to_rectangle (box, &rect); - if (rect.x == extents->source.x && - rect.y == extents->source.y && - rect.width == extents->source.width && - rect.height == extents->source.height) - { - return CAIRO_INT_STATUS_SUCCESS; - } - - _cairo_rectangle_intersect (&extents->source, &rect); - - rect = extents->bounded; - if (! _cairo_rectangle_intersect (&extents->bounded, &extents->source) && - extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (rect.width == extents->bounded.width && - rect.height == extents->bounded.height) - return CAIRO_INT_STATUS_SUCCESS; - - if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE)) { - extents->unbounded = extents->bounded; - } else if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) { - if (!_cairo_rectangle_intersect (&extents->unbounded, &extents->mask)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - clip = extents->clip; - extents->clip = _cairo_clip_reduce_for_composite (clip, extents); - if (clip != extents->clip) - _cairo_clip_destroy (clip); - - if (_cairo_clip_is_all_clipped (extents->clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (! _cairo_rectangle_intersect (&extents->unbounded, - _cairo_clip_get_extents (extents->clip))) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) - _cairo_pattern_sampled_area (&extents->source_pattern.base, - &extents->bounded, - &extents->source_sample_area); - if (extents->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) { - _cairo_pattern_sampled_area (&extents->mask_pattern.base, - &extents->bounded, - &extents->mask_sample_area); - if (extents->mask_sample_area.width == 0 || - extents->mask_sample_area.height == 0) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t *extents, - const cairo_box_t *box) -{ - cairo_rectangle_int_t mask; - cairo_clip_t *clip; - - _cairo_box_round_to_rectangle (box, &mask); - if (mask.x == extents->mask.x && - mask.y == extents->mask.y && - mask.width == extents->mask.width && - mask.height == extents->mask.height) - { - return CAIRO_INT_STATUS_SUCCESS; - } - - _cairo_rectangle_intersect (&extents->mask, &mask); - - mask = extents->bounded; - if (! _cairo_rectangle_intersect (&extents->bounded, &extents->mask) && - extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (mask.width == extents->bounded.width && - mask.height == extents->bounded.height) - return CAIRO_INT_STATUS_SUCCESS; - - if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE)) { - extents->unbounded = extents->bounded; - } else if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) { - if (!_cairo_rectangle_intersect (&extents->unbounded, &extents->mask)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - clip = extents->clip; - extents->clip = _cairo_clip_reduce_for_composite (clip, extents); - if (clip != extents->clip) - _cairo_clip_destroy (clip); - - if (_cairo_clip_is_all_clipped (extents->clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (! _cairo_rectangle_intersect (&extents->unbounded, - _cairo_clip_get_extents (extents->clip))) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) - _cairo_pattern_sampled_area (&extents->source_pattern.base, - &extents->bounded, - &extents->source_sample_area); - if (extents->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) { - _cairo_pattern_sampled_area (&extents->mask_pattern.base, - &extents->bounded, - &extents->mask_sample_area); - if (extents->mask_sample_area.width == 0 || - extents->mask_sample_area.height == 0) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_mask (cairo_composite_rectangles_t *extents, - cairo_surface_t*surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - if (! _cairo_composite_rectangles_init (extents, - surface, op, source, clip)) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - extents->original_mask_pattern = mask; - _cairo_composite_reduce_pattern (mask, &extents->mask_pattern); - _cairo_pattern_get_extents (&extents->mask_pattern.base, &extents->mask); - - return _cairo_composite_rectangles_intersect (extents, clip); -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_stroke (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_clip_t *clip) -{ - if (! _cairo_composite_rectangles_init (extents, - surface, op, source, clip)) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - _cairo_path_fixed_approximate_stroke_extents (path, style, ctm, &extents->mask); - - return _cairo_composite_rectangles_intersect (extents, clip); -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_fill (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_clip_t *clip) -{ - if (! _cairo_composite_rectangles_init (extents, - surface, op, source, clip)) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - _cairo_path_fixed_approximate_fill_extents (path, &extents->mask); - - return _cairo_composite_rectangles_intersect (extents, clip); -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_polygon (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_polygon_t *polygon, - const cairo_clip_t *clip) -{ - if (! _cairo_composite_rectangles_init (extents, - surface, op, source, clip)) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - _cairo_box_round_to_rectangle (&polygon->extents, &extents->mask); - return _cairo_composite_rectangles_intersect (extents, clip); -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_boxes (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_boxes_t *boxes, - const cairo_clip_t *clip) -{ - cairo_box_t box; - - if (! _cairo_composite_rectangles_init (extents, - surface, op, source, clip)) - { - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - _cairo_boxes_extents (boxes, &box); - _cairo_box_round_to_rectangle (&box, &extents->mask); - return _cairo_composite_rectangles_intersect (extents, clip); -} - -cairo_int_status_t -_cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *extents, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_clip_t *clip, - cairo_bool_t *overlap) -{ - cairo_status_t status; - - if (! _cairo_composite_rectangles_init (extents, surface, op, source, clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - /* Computing the exact bbox and the overlap is expensive. - * First perform a cheap test to see if the glyphs are all clipped out. - */ - if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK && - _cairo_scaled_font_glyph_approximate_extents (scaled_font, - glyphs, num_glyphs, - &extents->mask)) - { - if (! _cairo_rectangle_intersect (&extents->bounded, &extents->mask)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - status = _cairo_scaled_font_glyph_device_extents (scaled_font, - glyphs, num_glyphs, - &extents->mask, - overlap); - if (unlikely (status)) - return status; - - if (overlap && *overlap && - scaled_font->options.antialias == CAIRO_ANTIALIAS_NONE && - _cairo_pattern_is_opaque_solid (&extents->source_pattern.base)) - { - *overlap = FALSE; - } - - return _cairo_composite_rectangles_intersect (extents, clip); -} - -cairo_bool_t -_cairo_composite_rectangles_can_reduce_clip (cairo_composite_rectangles_t *composite, - cairo_clip_t *clip) -{ - cairo_rectangle_int_t extents; - cairo_box_t box; - - if (clip == NULL) - return TRUE; - - extents = composite->destination; - if (composite->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) - _cairo_rectangle_intersect (&extents, &composite->source); - if (composite->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) - _cairo_rectangle_intersect (&extents, &composite->mask); - - _cairo_box_from_rectangle (&box, &extents); - return _cairo_clip_contains_box (clip, &box); -} - -cairo_int_status_t -_cairo_composite_rectangles_add_to_damage (cairo_composite_rectangles_t *composite, - cairo_boxes_t *damage) -{ - cairo_int_status_t status; - int n; - - for (n = 0; n < composite->clip->num_boxes; n++) { - status = _cairo_boxes_add (damage, - CAIRO_ANTIALIAS_NONE, - &composite->clip->boxes[n]); - if (unlikely (status)) - return status; - } - - return CAIRO_INT_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor-private.h deleted file mode 100644 index 019972333f3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor-private.h +++ /dev/null @@ -1,365 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_COMPOSITOR_PRIVATE_H -#define CAIRO_COMPOSITOR_PRIVATE_H - -#include "cairo-composite-rectangles-private.h" - -CAIRO_BEGIN_DECLS - -typedef struct { - cairo_scaled_font_t *font; - cairo_glyph_t *glyphs; - int num_glyphs; - cairo_bool_t use_mask; - cairo_rectangle_int_t extents; -} cairo_composite_glyphs_info_t; - -struct cairo_compositor { - const cairo_compositor_t *delegate; - - cairo_warn cairo_int_status_t - (*paint) (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents); - - cairo_warn cairo_int_status_t - (*mask) (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents); - - cairo_warn cairo_int_status_t - (*stroke) (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias); - - cairo_warn cairo_int_status_t - (*fill) (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias); - - cairo_warn cairo_int_status_t - (*glyphs) (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap); -}; - -struct cairo_mask_compositor { - cairo_compositor_t base; - - cairo_int_status_t (*acquire) (void *surface); - cairo_int_status_t (*release) (void *surface); - - cairo_int_status_t (*set_clip_region) (void *surface, - cairo_region_t *clip_region); - - cairo_surface_t * (*pattern_to_surface) (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y); - - cairo_int_status_t (*draw_image_boxes) (void *surface, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy); - - cairo_int_status_t (*copy_boxes) (void *surface, - cairo_surface_t *src, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents, - int dx, int dy); - - cairo_int_status_t - (*fill_rectangles) (void *surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_rectangle_int_t *rectangles, - int num_rects); - - cairo_int_status_t - (*fill_boxes) (void *surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes); - - cairo_int_status_t - (*check_composite) (const cairo_composite_rectangles_t *extents); - - cairo_int_status_t - (*composite) (void *dst, - cairo_operator_t op, - cairo_surface_t *src, - cairo_surface_t *mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height); - - cairo_int_status_t - (*composite_boxes) (void *surface, - cairo_operator_t op, - cairo_surface_t *source, - cairo_surface_t *mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents); - - cairo_int_status_t - (*check_composite_glyphs) (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs); - cairo_int_status_t - (*composite_glyphs) (void *surface, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info); -}; - -struct cairo_traps_compositor { - cairo_compositor_t base; - - cairo_int_status_t - (*acquire) (void *surface); - - cairo_int_status_t - (*release) (void *surface); - - cairo_int_status_t - (*set_clip_region) (void *surface, - cairo_region_t *clip_region); - - cairo_surface_t * - (*pattern_to_surface) (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y); - - cairo_int_status_t (*draw_image_boxes) (void *surface, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy); - - cairo_int_status_t (*copy_boxes) (void *surface, - cairo_surface_t *src, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents, - int dx, int dy); - - cairo_int_status_t - (*fill_boxes) (void *surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes); - - cairo_int_status_t - (*check_composite) (const cairo_composite_rectangles_t *extents); - - cairo_int_status_t - (*composite) (void *dst, - cairo_operator_t op, - cairo_surface_t *src, - cairo_surface_t *mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height); - cairo_int_status_t - (*lerp) (void *_dst, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height); - - cairo_int_status_t - (*composite_boxes) (void *surface, - cairo_operator_t op, - cairo_surface_t *source, - cairo_surface_t *mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents); - - cairo_int_status_t - (*composite_traps) (void *dst, - cairo_operator_t op, - cairo_surface_t *source, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_traps_t *traps); - - cairo_int_status_t - (*composite_tristrip) (void *dst, - cairo_operator_t op, - cairo_surface_t *source, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_tristrip_t *tristrip); - - cairo_int_status_t - (*check_composite_glyphs) (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs); - cairo_int_status_t - (*composite_glyphs) (void *surface, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info); -}; - -cairo_private extern const cairo_compositor_t __cairo_no_compositor; -cairo_private extern const cairo_compositor_t _cairo_fallback_compositor; - -cairo_private void -_cairo_mask_compositor_init (cairo_mask_compositor_t *compositor, - const cairo_compositor_t *delegate); - -cairo_private void -_cairo_shape_mask_compositor_init (cairo_compositor_t *compositor, - const cairo_compositor_t *delegate); - -cairo_private void -_cairo_traps_compositor_init (cairo_traps_compositor_t *compositor, - const cairo_compositor_t *delegate); - -cairo_private cairo_int_status_t -_cairo_compositor_paint (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_compositor_mask (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_compositor_stroke (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_compositor_fill (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - -CAIRO_END_DECLS - -#endif /* CAIRO_COMPOSITOR_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor.c deleted file mode 100644 index b31413b9964..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-compositor.c +++ /dev/null @@ -1,268 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-compositor-private.h" -#include "cairo-damage-private.h" -#include "cairo-error-private.h" - -cairo_int_status_t -_cairo_compositor_paint (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - status = _cairo_composite_rectangles_init_for_paint (&extents, surface, - op, source, - clip); - if (unlikely (status)) - return status; - - do { - while (compositor->paint == NULL) - compositor = compositor->delegate; - - status = compositor->paint (compositor, &extents); - - compositor = compositor->delegate; - } while (status == CAIRO_INT_STATUS_UNSUPPORTED); - - if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { - TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", - __FUNCTION__, - extents.unbounded.x, extents.unbounded.y, - extents.unbounded.width, extents.unbounded.height)); - surface->damage = _cairo_damage_add_rectangle (surface->damage, - &extents.unbounded); - } - - _cairo_composite_rectangles_fini (&extents); - - return status; -} - -cairo_int_status_t -_cairo_compositor_mask (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - status = _cairo_composite_rectangles_init_for_mask (&extents, surface, - op, source, mask, - clip); - if (unlikely (status)) - return status; - - do { - while (compositor->mask == NULL) - compositor = compositor->delegate; - - status = compositor->mask (compositor, &extents); - - compositor = compositor->delegate; - } while (status == CAIRO_INT_STATUS_UNSUPPORTED); - - if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { - TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", - __FUNCTION__, - extents.unbounded.x, extents.unbounded.y, - extents.unbounded.width, extents.unbounded.height)); - surface->damage = _cairo_damage_add_rectangle (surface->damage, - &extents.unbounded); - } - - _cairo_composite_rectangles_fini (&extents); - - return status; -} - -cairo_int_status_t -_cairo_compositor_stroke (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (_cairo_pen_vertices_needed (tolerance, style->line_width/2, ctm) <= 1) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - status = _cairo_composite_rectangles_init_for_stroke (&extents, surface, - op, source, - path, style, ctm, - clip); - if (unlikely (status)) - return status; - - do { - while (compositor->stroke == NULL) - compositor = compositor->delegate; - - status = compositor->stroke (compositor, &extents, - path, style, ctm, ctm_inverse, - tolerance, antialias); - - compositor = compositor->delegate; - } while (status == CAIRO_INT_STATUS_UNSUPPORTED); - - if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { - TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", - __FUNCTION__, - extents.unbounded.x, extents.unbounded.y, - extents.unbounded.width, extents.unbounded.height)); - surface->damage = _cairo_damage_add_rectangle (surface->damage, - &extents.unbounded); - } - - _cairo_composite_rectangles_fini (&extents); - - return status; -} - -cairo_int_status_t -_cairo_compositor_fill (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - status = _cairo_composite_rectangles_init_for_fill (&extents, surface, - op, source, path, - clip); - if (unlikely (status)) - return status; - - do { - while (compositor->fill == NULL) - compositor = compositor->delegate; - - status = compositor->fill (compositor, &extents, - path, fill_rule, tolerance, antialias); - - compositor = compositor->delegate; - } while (status == CAIRO_INT_STATUS_UNSUPPORTED); - - if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { - TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", - __FUNCTION__, - extents.unbounded.x, extents.unbounded.y, - extents.unbounded.width, extents.unbounded.height)); - surface->damage = _cairo_damage_add_rectangle (surface->damage, - &extents.unbounded); - } - - _cairo_composite_rectangles_fini (&extents); - - return status; -} - -cairo_int_status_t -_cairo_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_composite_rectangles_t extents; - cairo_bool_t overlap; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - status = _cairo_composite_rectangles_init_for_glyphs (&extents, surface, - op, source, - scaled_font, - glyphs, num_glyphs, - clip, &overlap); - if (unlikely (status)) - return status; - - do { - while (compositor->glyphs == NULL) - compositor = compositor->delegate; - - status = compositor->glyphs (compositor, &extents, - scaled_font, glyphs, num_glyphs, overlap); - - compositor = compositor->delegate; - } while (status == CAIRO_INT_STATUS_UNSUPPORTED); - - if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { - TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", - __FUNCTION__, - extents.unbounded.x, extents.unbounded.y, - extents.unbounded.width, extents.unbounded.height)); - surface->damage = _cairo_damage_add_rectangle (surface->damage, - &extents.unbounded); - } - - _cairo_composite_rectangles_fini (&extents); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-inline.h deleted file mode 100644 index 7972c1ac5e0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-inline.h +++ /dev/null @@ -1,80 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_CONTOUR_INLINE_H -#define CAIRO_CONTOUR_INLINE_H - -#include "cairo-contour-private.h" - -CAIRO_BEGIN_DECLS - -static inline cairo_int_status_t -_cairo_contour_add_point (cairo_contour_t *contour, - const cairo_point_t *point) -{ - struct _cairo_contour_chain *tail = contour->tail; - - if (unlikely (tail->num_points == tail->size_points)) - return __cairo_contour_add_point (contour, point); - - tail->points[tail->num_points++] = *point; - return CAIRO_INT_STATUS_SUCCESS; -} - -static inline cairo_point_t * -_cairo_contour_first_point (cairo_contour_t *c) -{ - return &c->chain.points[0]; -} - -static inline cairo_point_t * -_cairo_contour_last_point (cairo_contour_t *c) -{ - return &c->tail->points[c->tail->num_points-1]; -} - -static inline void -_cairo_contour_remove_last_point (cairo_contour_t *contour) -{ - if (contour->chain.num_points == 0) - return; - - if (--contour->tail->num_points == 0) - __cairo_contour_remove_last_chain (contour); -} - -CAIRO_END_DECLS - -#endif /* CAIRO_CONTOUR_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-private.h deleted file mode 100644 index 1dfc46f3acd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour-private.h +++ /dev/null @@ -1,124 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_CONTOUR_PRIVATE_H -#define CAIRO_CONTOUR_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" -#include "cairo-list-private.h" - -#include - -CAIRO_BEGIN_DECLS - -/* A contour is simply a closed chain of points that divide the infinite plane - * into inside and outside. Each contour is a simple polygon, that is it - * contains no holes or self-intersections, but maybe either concave or convex. - */ - -struct _cairo_contour_chain { - cairo_point_t *points; - int num_points, size_points; - struct _cairo_contour_chain *next; -}; - -struct _cairo_contour_iter { - cairo_point_t *point; - cairo_contour_chain_t *chain; -}; - -struct _cairo_contour { - cairo_list_t next; - int direction; - cairo_contour_chain_t chain, *tail; - - cairo_point_t embedded_points[64]; -}; - -/* Initial definition of a shape is a set of contours (some representing holes) */ -struct _cairo_shape { - cairo_list_t contours; -}; - -typedef struct _cairo_shape cairo_shape_t; - -#if 0 -cairo_private cairo_status_t -_cairo_shape_init_from_polygon (cairo_shape_t *shape, - const cairo_polygon_t *polygon); - -cairo_private cairo_status_t -_cairo_shape_reduce (cairo_shape_t *shape, double tolerance); -#endif - -cairo_private void -_cairo_contour_init (cairo_contour_t *contour, - int direction); - -cairo_private cairo_int_status_t -__cairo_contour_add_point (cairo_contour_t *contour, - const cairo_point_t *point); - -cairo_private void -_cairo_contour_simplify (cairo_contour_t *contour, double tolerance); - -cairo_private void -_cairo_contour_reverse (cairo_contour_t *contour); - -cairo_private cairo_int_status_t -_cairo_contour_add (cairo_contour_t *dst, - const cairo_contour_t *src); - -cairo_private cairo_int_status_t -_cairo_contour_add_reversed (cairo_contour_t *dst, - const cairo_contour_t *src); - -cairo_private void -__cairo_contour_remove_last_chain (cairo_contour_t *contour); - -cairo_private void -_cairo_contour_reset (cairo_contour_t *contour); - -cairo_private void -_cairo_contour_fini (cairo_contour_t *contour); - -cairo_private void -_cairo_debug_print_contour (FILE *file, cairo_contour_t *contour); - -CAIRO_END_DECLS - -#endif /* CAIRO_CONTOUR_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour.c deleted file mode 100644 index 9ad75bdbf8d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-contour.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2008 Chris Wilson - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" -#include "cairo-combsort-inline.h" -#include "cairo-contour-inline.h" -#include "cairo-contour-private.h" - -void -_cairo_contour_init (cairo_contour_t *contour, - int direction) -{ - contour->direction = direction; - contour->chain.points = contour->embedded_points; - contour->chain.next = NULL; - contour->chain.num_points = 0; - contour->chain.size_points = ARRAY_LENGTH (contour->embedded_points); - contour->tail = &contour->chain; -} - -cairo_int_status_t -__cairo_contour_add_point (cairo_contour_t *contour, - const cairo_point_t *point) -{ - cairo_contour_chain_t *tail = contour->tail; - cairo_contour_chain_t *next; - - assert (tail->next == NULL); - - next = _cairo_malloc_ab_plus_c (tail->size_points*2, - sizeof (cairo_point_t), - sizeof (cairo_contour_chain_t)); - if (unlikely (next == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - next->size_points = tail->size_points*2; - next->num_points = 1; - next->points = (cairo_point_t *)(next+1); - next->next = NULL; - tail->next = next; - contour->tail = next; - - next->points[0] = *point; - return CAIRO_INT_STATUS_SUCCESS; -} - -static void -first_inc (cairo_contour_t *contour, - cairo_point_t **p, - cairo_contour_chain_t **chain) -{ - if (*p == (*chain)->points + (*chain)->num_points) { - assert ((*chain)->next); - *chain = (*chain)->next; - *p = &(*chain)->points[0]; - } else - ++*p; -} - -static void -last_dec (cairo_contour_t *contour, - cairo_point_t **p, - cairo_contour_chain_t **chain) -{ - if (*p == (*chain)->points) { - cairo_contour_chain_t *prev; - assert (*chain != &contour->chain); - for (prev = &contour->chain; prev->next != *chain; prev = prev->next) - ; - *chain = prev; - *p = &(*chain)->points[(*chain)->num_points-1]; - } else - --*p; -} - -void -_cairo_contour_reverse (cairo_contour_t *contour) -{ - cairo_contour_chain_t *first_chain, *last_chain; - cairo_point_t *first, *last; - - contour->direction = -contour->direction; - - if (contour->chain.num_points <= 1) - return; - - first_chain = &contour->chain; - last_chain = contour->tail; - - first = &first_chain->points[0]; - last = &last_chain->points[last_chain->num_points-1]; - - while (first != last) { - cairo_point_t p; - - p = *first; - *first = *last; - *last = p; - - first_inc (contour, &first, &first_chain); - last_dec (contour, &last, &last_chain); - } -} - -cairo_int_status_t -_cairo_contour_add (cairo_contour_t *dst, - const cairo_contour_t *src) -{ - const cairo_contour_chain_t *chain; - cairo_int_status_t status; - int i; - - for (chain = &src->chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - status = _cairo_contour_add_point (dst, &chain->points[i]); - if (unlikely (status)) - return status; - } - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -static inline cairo_bool_t -iter_next (cairo_contour_iter_t *iter) -{ - if (iter->point == &iter->chain->points[iter->chain->size_points-1]) { - iter->chain = iter->chain->next; - if (iter->chain == NULL) - return FALSE; - - iter->point = &iter->chain->points[0]; - return TRUE; - } else { - iter->point++; - return TRUE; - } -} - -static cairo_bool_t -iter_equal (const cairo_contour_iter_t *i1, - const cairo_contour_iter_t *i2) -{ - return i1->chain == i2->chain && i1->point == i2->point; -} - -static void -iter_init (cairo_contour_iter_t *iter, cairo_contour_t *contour) -{ - iter->chain = &contour->chain; - iter->point = &contour->chain.points[0]; -} - -static void -iter_init_last (cairo_contour_iter_t *iter, cairo_contour_t *contour) -{ - iter->chain = contour->tail; - iter->point = &contour->tail->points[contour->tail->num_points-1]; -} - -static const cairo_contour_chain_t *prev_const_chain(const cairo_contour_t *contour, - const cairo_contour_chain_t *chain) -{ - const cairo_contour_chain_t *prev; - - if (chain == &contour->chain) - return NULL; - - for (prev = &contour->chain; prev->next != chain; prev = prev->next) - ; - - return prev; -} - -cairo_int_status_t -_cairo_contour_add_reversed (cairo_contour_t *dst, - const cairo_contour_t *src) -{ - const cairo_contour_chain_t *last; - cairo_int_status_t status; - int i; - - if (src->chain.num_points == 0) - return CAIRO_INT_STATUS_SUCCESS; - - for (last = src->tail; last; last = prev_const_chain (src, last)) { - for (i = last->num_points-1; i >= 0; i--) { - status = _cairo_contour_add_point (dst, &last->points[i]); - if (unlikely (status)) - return status; - } - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_uint64_t -point_distance_sq (const cairo_point_t *p1, - const cairo_point_t *p2) -{ - int32_t dx = p1->x - p2->x; - int32_t dy = p1->y - p2->y; - return _cairo_int32x32_64_mul (dx, dx) + _cairo_int32x32_64_mul (dy, dy); -} - -#define DELETED(p) ((p)->x == INT_MIN && (p)->y == INT_MAX) -#define MARK_DELETED(p) ((p)->x = INT_MIN, (p)->y = INT_MAX) - -static cairo_bool_t -_cairo_contour_simplify_chain (cairo_contour_t *contour, const double tolerance, - const cairo_contour_iter_t *first, - const cairo_contour_iter_t *last) -{ - cairo_contour_iter_t iter, furthest; - uint64_t max_error; - int x0, y0; - int nx, ny; - int count; - - iter = *first; - iter_next (&iter); - if (iter_equal (&iter, last)) - return FALSE; - - x0 = first->point->x; - y0 = first->point->y; - nx = last->point->y - y0; - ny = x0 - last->point->x; - - count = 0; - max_error = 0; - do { - cairo_point_t *p = iter.point; - if (! DELETED(p)) { - uint64_t d = (uint64_t)nx * (x0 - p->x) + (uint64_t)ny * (y0 - p->y); - if (d * d > max_error) { - max_error = d * d; - furthest = iter; - } - count++; - } - iter_next (&iter); - } while (! iter_equal (&iter, last)); - if (count == 0) - return FALSE; - - if (max_error > tolerance * ((uint64_t)nx * nx + (uint64_t)ny * ny)) { - cairo_bool_t simplified; - - simplified = FALSE; - simplified |= _cairo_contour_simplify_chain (contour, tolerance, - first, &furthest); - simplified |= _cairo_contour_simplify_chain (contour, tolerance, - &furthest, last); - return simplified; - } else { - iter = *first; - iter_next (&iter); - do { - MARK_DELETED (iter.point); - iter_next (&iter); - } while (! iter_equal (&iter, last)); - - return TRUE; - } -} - -void -_cairo_contour_simplify (cairo_contour_t *contour, double tolerance) -{ - cairo_contour_chain_t *chain; - cairo_point_t *last = NULL; - cairo_contour_iter_t iter, furthest; - cairo_bool_t simplified; - uint64_t max = 0; - int i; - - if (contour->chain.num_points <= 2) - return; - - tolerance = tolerance * CAIRO_FIXED_ONE; - tolerance *= tolerance; - - /* stage 1: vertex reduction */ - for (chain = &contour->chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - if (last == NULL || - point_distance_sq (last, &chain->points[i]) > tolerance) { - last = &chain->points[i]; - } else { - MARK_DELETED (&chain->points[i]); - } - } - } - - /* stage2: polygon simplification using Douglas-Peucker */ - do { - last = &contour->chain.points[0]; - iter_init (&furthest, contour); - max = 0; - for (chain = &contour->chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - uint64_t d; - - if (DELETED (&chain->points[i])) - continue; - - d = point_distance_sq (last, &chain->points[i]); - if (d > max) { - furthest.chain = chain; - furthest.point = &chain->points[i]; - max = d; - } - } - } - assert (max); - - simplified = FALSE; - iter_init (&iter, contour); - simplified |= _cairo_contour_simplify_chain (contour, tolerance, - &iter, &furthest); - - iter_init_last (&iter, contour); - if (! iter_equal (&furthest, &iter)) - simplified |= _cairo_contour_simplify_chain (contour, tolerance, - &furthest, &iter); - } while (simplified); - - iter_init (&iter, contour); - for (chain = &contour->chain; chain; chain = chain->next) { - int num_points = chain->num_points; - chain->num_points = 0; - for (i = 0; i < num_points; i++) { - if (! DELETED(&chain->points[i])) { - if (iter.point != &chain->points[i]) - *iter.point = chain->points[i]; - iter.chain->num_points++; - iter_next (&iter); - } - } - } - - if (iter.chain) { - cairo_contour_chain_t *next; - - for (chain = iter.chain->next; chain; chain = next) { - next = chain->next; - free (chain); - } - - iter.chain->next = NULL; - contour->tail = iter.chain; - } -} - -void -_cairo_contour_reset (cairo_contour_t *contour) -{ - _cairo_contour_fini (contour); - _cairo_contour_init (contour, contour->direction); -} - -void -_cairo_contour_fini (cairo_contour_t *contour) -{ - cairo_contour_chain_t *chain, *next; - - for (chain = contour->chain.next; chain; chain = next) { - next = chain->next; - free (chain); - } -} - -void -_cairo_debug_print_contour (FILE *file, cairo_contour_t *contour) -{ - cairo_contour_chain_t *chain; - int num_points, size_points; - int i; - - num_points = 0; - size_points = 0; - for (chain = &contour->chain; chain; chain = chain->next) { - num_points += chain->num_points; - size_points += chain->size_points; - } - - fprintf (file, "contour: direction=%d, num_points=%d / %d\n", - contour->direction, num_points, size_points); - - num_points = 0; - for (chain = &contour->chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - fprintf (file, " [%d] = (%f, %f)\n", - num_points++, - _cairo_fixed_to_double (chain->points[i].x), - _cairo_fixed_to_double (chain->points[i].y)); - } - } -} - -void -__cairo_contour_remove_last_chain (cairo_contour_t *contour) -{ - cairo_contour_chain_t *chain; - - if (contour->tail == &contour->chain) - return; - - for (chain = &contour->chain; chain->next != contour->tail; chain = chain->next) - ; - free (contour->tail); - contour->tail = chain; - chain->next = NULL; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage-private.h deleted file mode 100644 index 97b177e86b4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage-private.h +++ /dev/null @@ -1,85 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2012 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_DAMAGE_PRIVATE_H -#define CAIRO_DAMAGE_PRIVATE_H - -#include "cairo-types-private.h" - -#include - -CAIRO_BEGIN_DECLS - -struct _cairo_damage { - cairo_status_t status; - cairo_region_t *region; - - int dirty, remain; - struct _cairo_damage_chunk { - struct _cairo_damage_chunk *next; - cairo_box_t *base; - int count; - int size; - } chunks, *tail; - cairo_box_t boxes[32]; -}; - -cairo_private cairo_damage_t * -_cairo_damage_create (void); - -cairo_private cairo_damage_t * -_cairo_damage_create_in_error (cairo_status_t status); - -cairo_private cairo_damage_t * -_cairo_damage_add_box (cairo_damage_t *damage, - const cairo_box_t *box); - -cairo_private cairo_damage_t * -_cairo_damage_add_rectangle (cairo_damage_t *damage, - const cairo_rectangle_int_t *rect); - -cairo_private cairo_damage_t * -_cairo_damage_add_region (cairo_damage_t *damage, - const cairo_region_t *region); - -cairo_private cairo_damage_t * -_cairo_damage_reduce (cairo_damage_t *damage); - -cairo_private void -_cairo_damage_destroy (cairo_damage_t *damage); - -CAIRO_END_DECLS - -#endif /* CAIRO_DAMAGE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage.c deleted file mode 100644 index 63191fee95d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-damage.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright © 2012 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-damage-private.h" -#include "cairo-region-private.h" - -static const cairo_damage_t __cairo_damage__nil = { CAIRO_STATUS_NO_MEMORY }; - -cairo_damage_t * -_cairo_damage_create_in_error (cairo_status_t status) -{ - _cairo_error_throw (status); - return (cairo_damage_t *) &__cairo_damage__nil; -} - -cairo_damage_t * -_cairo_damage_create (void) -{ - cairo_damage_t *damage; - - damage = malloc (sizeof (*damage)); - if (unlikely (damage == NULL)) { - _cairo_error_throw(CAIRO_STATUS_NO_MEMORY); - return (cairo_damage_t *) &__cairo_damage__nil; - } - - damage->status = CAIRO_STATUS_SUCCESS; - damage->region = NULL; - damage->dirty = 0; - damage->tail = &damage->chunks; - damage->chunks.base = damage->boxes; - damage->chunks.size = ARRAY_LENGTH(damage->boxes); - damage->chunks.count = 0; - damage->chunks.next = NULL; - - damage->remain = damage->chunks.size; - - return damage; -} - -void -_cairo_damage_destroy (cairo_damage_t *damage) -{ - struct _cairo_damage_chunk *chunk, *next; - - if (damage == (cairo_damage_t *) &__cairo_damage__nil) - return; - - for (chunk = damage->chunks.next; chunk != NULL; chunk = next) { - next = chunk->next; - free (chunk); - } - cairo_region_destroy (damage->region); - free (damage); -} - -static cairo_damage_t * -_cairo_damage_add_boxes(cairo_damage_t *damage, - const cairo_box_t *boxes, - int count) -{ - struct _cairo_damage_chunk *chunk; - int n, size; - - TRACE ((stderr, "%s x%d\n", __FUNCTION__, count)); - - if (damage == NULL) - damage = _cairo_damage_create (); - if (damage->status) - return damage; - - damage->dirty += count; - - n = count; - if (n > damage->remain) - n = damage->remain; - - memcpy (damage->tail->base + damage->tail->count, boxes, - n * sizeof (cairo_box_t)); - - count -= n; - damage->tail->count += n; - damage->remain -= n; - - if (count == 0) - return damage; - - size = 2 * damage->tail->size; - if (size < count) - size = (count + 64) & ~63; - - chunk = malloc (sizeof (*chunk) + sizeof (cairo_box_t) * size); - if (unlikely (chunk == NULL)) { - _cairo_damage_destroy (damage); - return (cairo_damage_t *) &__cairo_damage__nil; - } - - chunk->next = NULL; - chunk->base = (cairo_box_t *) (chunk + 1); - chunk->size = size; - chunk->count = count; - - damage->tail->next = chunk; - damage->tail = chunk; - - memcpy (damage->tail->base, boxes + n, - count * sizeof (cairo_box_t)); - damage->remain = size - count; - - return damage; -} - -cairo_damage_t * -_cairo_damage_add_box(cairo_damage_t *damage, - const cairo_box_t *box) -{ - TRACE ((stderr, "%s: (%d, %d),(%d, %d)\n", __FUNCTION__, - box->p1.x, box->p1.y, box->p2.x, box->p2.y)); - - return _cairo_damage_add_boxes(damage, box, 1); -} - -cairo_damage_t * -_cairo_damage_add_rectangle(cairo_damage_t *damage, - const cairo_rectangle_int_t *r) -{ - cairo_box_t box; - - TRACE ((stderr, "%s: (%d, %d)x(%d, %d)\n", __FUNCTION__, - r->x, r->y, r->width, r->height)); - - box.p1.x = r->x; - box.p1.y = r->y; - box.p2.x = r->x + r->width; - box.p2.y = r->y + r->height; - - return _cairo_damage_add_boxes(damage, &box, 1); -} - -cairo_damage_t * -_cairo_damage_add_region (cairo_damage_t *damage, - const cairo_region_t *region) -{ - cairo_box_t *boxes; - int nbox; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - boxes = _cairo_region_get_boxes (region, &nbox); - return _cairo_damage_add_boxes(damage, boxes, nbox); -} - -cairo_damage_t * -_cairo_damage_reduce (cairo_damage_t *damage) -{ - cairo_box_t *free_boxes = NULL; - cairo_box_t *boxes, *b; - struct _cairo_damage_chunk *chunk, *last; - - TRACE ((stderr, "%s: dirty=%d\n", __FUNCTION__, - damage ? damage->dirty : -1)); - if (damage == NULL || damage->status || !damage->dirty) - return damage; - - if (damage->region) { - cairo_region_t *region; - - region = damage->region; - damage->region = NULL; - - damage = _cairo_damage_add_region (damage, region); - cairo_region_destroy (region); - - if (unlikely (damage->status)) - return damage; - } - - boxes = damage->tail->base; - if (damage->dirty > damage->tail->size) { - boxes = free_boxes = malloc (damage->dirty * sizeof (cairo_box_t)); - if (unlikely (boxes == NULL)) { - _cairo_damage_destroy (damage); - return (cairo_damage_t *) &__cairo_damage__nil; - } - - b = boxes; - last = NULL; - } else { - b = boxes + damage->tail->count; - last = damage->tail; - } - - for (chunk = &damage->chunks; chunk != last; chunk = chunk->next) { - memcpy (b, chunk->base, chunk->count * sizeof (cairo_box_t)); - b += chunk->count; - } - - damage->region = _cairo_region_create_from_boxes (boxes, damage->dirty); - free (free_boxes); - - if (unlikely (damage->region->status)) { - _cairo_damage_destroy (damage); - return (cairo_damage_t *) &__cairo_damage__nil; - } - - damage->dirty = 0; - return damage; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-debug.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-debug.c deleted file mode 100644 index 33d46aa3f79..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-debug.c +++ /dev/null @@ -1,304 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" -#include "cairo-image-surface-private.h" - -/** - * cairo_debug_reset_static_data: - * - * Resets all static data within cairo to its original state, - * (ie. identical to the state at the time of program invocation). For - * example, all caches within cairo will be flushed empty. - * - * This function is intended to be useful when using memory-checking - * tools such as valgrind. When valgrind's memcheck analyzes a - * cairo-using program without a call to cairo_debug_reset_static_data(), - * it will report all data reachable via cairo's static objects as - * "still reachable". Calling cairo_debug_reset_static_data() just prior - * to program termination will make it easier to get squeaky clean - * reports from valgrind. - * - * WARNING: It is only safe to call this function when there are no - * active cairo objects remaining, (ie. the appropriate destroy - * functions have been called as necessary). If there are active cairo - * objects, this call is likely to cause a crash, (eg. an assertion - * failure due to a hash table being destroyed when non-empty). - * - * Since: 1.0 - **/ -void -cairo_debug_reset_static_data (void) -{ - CAIRO_MUTEX_INITIALIZE (); - - _cairo_scaled_font_map_destroy (); - - _cairo_toy_font_face_reset_static_data (); - -#if CAIRO_HAS_FT_FONT - _cairo_ft_font_reset_static_data (); -#endif - -#if CAIRO_HAS_WIN32_FONT - _cairo_win32_font_reset_static_data (); -#endif - - _cairo_intern_string_reset_static_data (); - - _cairo_scaled_font_reset_static_data (); - - _cairo_pattern_reset_static_data (); - - _cairo_clip_reset_static_data (); - - _cairo_image_reset_static_data (); - -#if CAIRO_HAS_DRM_SURFACE - _cairo_drm_device_reset_static_data (); -#endif - - _cairo_default_context_reset_static_data (); - -#if CAIRO_HAS_COGL_SURFACE - _cairo_cogl_context_reset_static_data (); -#endif - - CAIRO_MUTEX_FINALIZE (); -} - -#if HAVE_VALGRIND -void -_cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface) -{ - const cairo_image_surface_t *image = (cairo_image_surface_t *) surface; - const uint8_t *bits; - int row, width; - - if (surface == NULL) - return; - - if (! RUNNING_ON_VALGRIND) - return; - - bits = image->data; - switch (image->format) { - case CAIRO_FORMAT_A1: - width = (image->width + 7)/8; - break; - case CAIRO_FORMAT_A8: - width = image->width; - break; - case CAIRO_FORMAT_RGB16_565: - width = image->width*2; - break; - case CAIRO_FORMAT_RGB24: - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_ARGB32: - width = image->width*4; - break; - case CAIRO_FORMAT_INVALID: - default: - /* XXX compute width from pixman bpp */ - return; - } - - for (row = 0; row < image->height; row++) { - VALGRIND_CHECK_MEM_IS_DEFINED (bits, width); - /* and then silence any future valgrind warnings */ - VALGRIND_MAKE_MEM_DEFINED (bits, width); - bits += image->stride; - } -} -#endif - - -#if 0 -void -_cairo_image_surface_write_to_ppm (cairo_image_surface_t *isurf, const char *fn) -{ - char *fmt; - if (isurf->format == CAIRO_FORMAT_ARGB32 || isurf->format == CAIRO_FORMAT_RGB24) - fmt = "P6"; - else if (isurf->format == CAIRO_FORMAT_A8) - fmt = "P5"; - else - return; - - FILE *fp = fopen(fn, "wb"); - if (!fp) - return; - - fprintf (fp, "%s %d %d 255\n", fmt,isurf->width, isurf->height); - for (int j = 0; j < isurf->height; j++) { - unsigned char *row = isurf->data + isurf->stride * j; - for (int i = 0; i < isurf->width; i++) { - if (isurf->format == CAIRO_FORMAT_ARGB32 || isurf->format == CAIRO_FORMAT_RGB24) { - unsigned char r = *row++; - unsigned char g = *row++; - unsigned char b = *row++; - *row++; - putc(r, fp); - putc(g, fp); - putc(b, fp); - } else { - unsigned char a = *row++; - putc(a, fp); - } - } - } - - fclose (fp); - - fprintf (stderr, "Wrote %s\n", fn); -} -#endif - -static cairo_status_t -_print_move_to (void *closure, - const cairo_point_t *point) -{ - fprintf (closure, - " %f %f m", - _cairo_fixed_to_double (point->x), - _cairo_fixed_to_double (point->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_print_line_to (void *closure, - const cairo_point_t *point) -{ - fprintf (closure, - " %f %f l", - _cairo_fixed_to_double (point->x), - _cairo_fixed_to_double (point->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_print_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - fprintf (closure, - " %f %f %f %f %f %f c", - _cairo_fixed_to_double (p1->x), - _cairo_fixed_to_double (p1->y), - _cairo_fixed_to_double (p2->x), - _cairo_fixed_to_double (p2->y), - _cairo_fixed_to_double (p3->x), - _cairo_fixed_to_double (p3->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_print_close (void *closure) -{ - fprintf (closure, " h"); - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_debug_print_path (FILE *stream, cairo_path_fixed_t *path) -{ - cairo_status_t status; - cairo_box_t box; - - fprintf (stream, - "path: extents=(%f, %f), (%f, %f)\n", - _cairo_fixed_to_double (path->extents.p1.x), - _cairo_fixed_to_double (path->extents.p1.y), - _cairo_fixed_to_double (path->extents.p2.x), - _cairo_fixed_to_double (path->extents.p2.y)); - - status = _cairo_path_fixed_interpret (path, - _print_move_to, - _print_line_to, - _print_curve_to, - _print_close, - stream); - assert (status == CAIRO_STATUS_SUCCESS); - - if (_cairo_path_fixed_is_box (path, &box)) { - fprintf (stream, "[box (%d, %d), (%d, %d)]", - box.p1.x, box.p1.y, box.p2.x, box.p2.y); - } - - printf ("\n"); -} - -void -_cairo_debug_print_polygon (FILE *stream, cairo_polygon_t *polygon) -{ - int n; - - fprintf (stream, - "polygon: extents=(%f, %f), (%f, %f)\n", - _cairo_fixed_to_double (polygon->extents.p1.x), - _cairo_fixed_to_double (polygon->extents.p1.y), - _cairo_fixed_to_double (polygon->extents.p2.x), - _cairo_fixed_to_double (polygon->extents.p2.y)); - if (polygon->num_limits) { - fprintf (stream, - " : limit=(%f, %f), (%f, %f) x %d\n", - _cairo_fixed_to_double (polygon->limit.p1.x), - _cairo_fixed_to_double (polygon->limit.p1.y), - _cairo_fixed_to_double (polygon->limit.p2.x), - _cairo_fixed_to_double (polygon->limit.p2.y), - polygon->num_limits); - } - - for (n = 0; n < polygon->num_edges; n++) { - cairo_edge_t *edge = &polygon->edges[n]; - - fprintf (stream, - " [%d] = [(%f, %f), (%f, %f)], top=%f, bottom=%f, dir=%d\n", - n, - _cairo_fixed_to_double (edge->line.p1.x), - _cairo_fixed_to_double (edge->line.p1.y), - _cairo_fixed_to_double (edge->line.p2.x), - _cairo_fixed_to_double (edge->line.p2.y), - _cairo_fixed_to_double (edge->top), - _cairo_fixed_to_double (edge->bottom), - edge->dir); - - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context-private.h deleted file mode 100644 index fd159b49670..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context-private.h +++ /dev/null @@ -1,68 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_DEFAULT_CONTEXT_PRIVATE_H -#define CAIRO_DEFAULT_CONTEXT_PRIVATE_H - -#include "cairo-private.h" -#include "cairo-gstate-private.h" -#include "cairo-path-fixed-private.h" - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_default_context cairo_default_context_t; - -struct _cairo_default_context { - cairo_t base; - - cairo_gstate_t *gstate; - cairo_gstate_t gstate_tail[2]; - cairo_gstate_t *gstate_freelist; - - cairo_path_fixed_t path[1]; -}; - -cairo_private cairo_t * -_cairo_default_context_create (void *target); - -cairo_private cairo_status_t -_cairo_default_context_init (cairo_default_context_t *cr, void *target); - -cairo_private void -_cairo_default_context_fini (cairo_default_context_t *cr); - -CAIRO_END_DECLS - -#endif /* CAIRO_DEFAULT_CONTEXT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context.c deleted file mode 100644 index 1e5067bf1b8..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-default-context.c +++ /dev/null @@ -1,1475 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-private.h" -#include "cairo-arc-private.h" -#include "cairo-backend-private.h" -#include "cairo-clip-inline.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-path-private.h" -#include "cairo-pattern-private.h" - -#define CAIRO_TOLERANCE_MINIMUM _cairo_fixed_to_double(1) - -#if !defined(INFINITY) -#define INFINITY HUGE_VAL -#endif - -static freed_pool_t context_pool; - -void -_cairo_default_context_reset_static_data (void) -{ - _freed_pool_reset (&context_pool); -} - -void -_cairo_default_context_fini (cairo_default_context_t *cr) -{ - while (cr->gstate != &cr->gstate_tail[0]) { - if (_cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist)) - break; - } - - _cairo_gstate_fini (cr->gstate); - cr->gstate_freelist = cr->gstate_freelist->next; /* skip over tail[1] */ - while (cr->gstate_freelist != NULL) { - cairo_gstate_t *gstate = cr->gstate_freelist; - cr->gstate_freelist = gstate->next; - free (gstate); - } - - _cairo_path_fixed_fini (cr->path); - - _cairo_fini (&cr->base); -} - -static void -_cairo_default_context_destroy (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_default_context_fini (cr); - - /* mark the context as invalid to protect against misuse */ - cr->base.status = CAIRO_STATUS_NULL_POINTER; - _freed_pool_put (&context_pool, cr); -} - -static cairo_surface_t * -_cairo_default_context_get_original_target (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_original_target (cr->gstate); -} - -static cairo_surface_t * -_cairo_default_context_get_current_target (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_target (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_save (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_save (&cr->gstate, &cr->gstate_freelist); -} - -static cairo_status_t -_cairo_default_context_restore (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - if (unlikely (_cairo_gstate_is_group (cr->gstate))) - return _cairo_error (CAIRO_STATUS_INVALID_RESTORE); - - return _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist); -} - -static cairo_status_t -_cairo_default_context_push_group (void *abstract_cr, cairo_content_t content) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_surface_t *group_surface; - cairo_clip_t *clip; - cairo_status_t status; - - clip = _cairo_gstate_get_clip (cr->gstate); - if (_cairo_clip_is_all_clipped (clip)) { - group_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); - status = group_surface->status; - if (unlikely (status)) - goto bail; - } else { - cairo_surface_t *parent_surface; - cairo_rectangle_int_t extents; - cairo_bool_t bounded, is_empty; - - parent_surface = _cairo_gstate_get_target (cr->gstate); - - if (unlikely (parent_surface->status)) - return parent_surface->status; - if (unlikely (parent_surface->finished)) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - /* Get the extents that we'll use in creating our new group surface */ - bounded = _cairo_surface_get_extents (parent_surface, &extents); - if (clip) - /* XXX: This assignment just fixes a compiler warning? */ - is_empty = _cairo_rectangle_intersect (&extents, - _cairo_clip_get_extents (clip)); - - if (!bounded) { - /* XXX: Generic solution? */ - group_surface = cairo_recording_surface_create (content, NULL); - extents.x = extents.y = 0; - } else { - group_surface = _cairo_surface_create_scratch (parent_surface, - content, - extents.width, - extents.height, - CAIRO_COLOR_TRANSPARENT); - } - status = group_surface->status; - if (unlikely (status)) - goto bail; - - /* Set device offsets on the new surface so that logically it appears at - * the same location on the parent surface -- when we pop_group this, - * the source pattern will get fixed up for the appropriate target surface - * device offsets, so we want to set our own surface offsets from /that/, - * and not from the device origin. */ - cairo_surface_set_device_offset (group_surface, - parent_surface->device_transform.x0 - extents.x, - parent_surface->device_transform.y0 - extents.y); - - cairo_surface_set_device_scale (group_surface, - parent_surface->device_transform.xx, - parent_surface->device_transform.yy); - - /* If we have a current path, we need to adjust it to compensate for - * the device offset just applied. */ - _cairo_path_fixed_translate (cr->path, - _cairo_fixed_from_int (-extents.x), - _cairo_fixed_from_int (-extents.y)); - } - - /* create a new gstate for the redirect */ - status = _cairo_gstate_save (&cr->gstate, &cr->gstate_freelist); - if (unlikely (status)) - goto bail; - - status = _cairo_gstate_redirect_target (cr->gstate, group_surface); - -bail: - cairo_surface_destroy (group_surface); - return status; -} - -static cairo_pattern_t * -_cairo_default_context_pop_group (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_surface_t *group_surface; - cairo_pattern_t *group_pattern; - cairo_surface_t *parent_surface; - cairo_matrix_t group_matrix; - cairo_status_t status; - - /* Verify that we are at the right nesting level */ - if (unlikely (! _cairo_gstate_is_group (cr->gstate))) - return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_POP_GROUP); - - /* Get a reference to the active surface before restoring */ - group_surface = _cairo_gstate_get_target (cr->gstate); - group_surface = cairo_surface_reference (group_surface); - - status = _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist); - assert (status == CAIRO_STATUS_SUCCESS); - - parent_surface = _cairo_gstate_get_target (cr->gstate); - - group_pattern = cairo_pattern_create_for_surface (group_surface); - status = group_pattern->status; - if (unlikely (status)) - goto done; - - _cairo_gstate_get_matrix (cr->gstate, &group_matrix); - cairo_pattern_set_matrix (group_pattern, &group_matrix); - - /* If we have a current path, we need to adjust it to compensate for - * the device offset just removed. */ - _cairo_path_fixed_translate (cr->path, - _cairo_fixed_from_int (parent_surface->device_transform.x0 - group_surface->device_transform.x0), - _cairo_fixed_from_int (parent_surface->device_transform.y0 - group_surface->device_transform.y0)); - -done: - cairo_surface_destroy (group_surface); - - return group_pattern; -} - -static cairo_status_t -_cairo_default_context_set_source (void *abstract_cr, - cairo_pattern_t *source) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_source (cr->gstate, source); -} - -static cairo_bool_t -_current_source_matches_solid (const cairo_pattern_t *pattern, - double red, - double green, - double blue, - double alpha) -{ - cairo_color_t color; - - if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) - return FALSE; - - red = _cairo_restrict_value (red, 0.0, 1.0); - green = _cairo_restrict_value (green, 0.0, 1.0); - blue = _cairo_restrict_value (blue, 0.0, 1.0); - alpha = _cairo_restrict_value (alpha, 0.0, 1.0); - - _cairo_color_init_rgba (&color, red, green, blue, alpha); - return _cairo_color_equal (&color, - &((cairo_solid_pattern_t *) pattern)->color); -} - -static cairo_status_t -_cairo_default_context_set_source_rgba (void *abstract_cr, double red, double green, double blue, double alpha) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_pattern_t *pattern; - cairo_status_t status; - - if (_current_source_matches_solid (cr->gstate->source, - red, green, blue, alpha)) - return CAIRO_STATUS_SUCCESS; - - /* push the current pattern to the freed lists */ - _cairo_default_context_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black); - - pattern = cairo_pattern_create_rgba (red, green, blue, alpha); - if (unlikely (pattern->status)) - return pattern->status; - - status = _cairo_default_context_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - - return status; -} - -static cairo_status_t -_cairo_default_context_set_source_surface (void *abstract_cr, - cairo_surface_t *surface, - double x, - double y) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_pattern_t *pattern; - cairo_matrix_t matrix; - cairo_status_t status; - - /* push the current pattern to the freed lists */ - _cairo_default_context_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black); - - pattern = cairo_pattern_create_for_surface (surface); - if (unlikely (pattern->status)) - return pattern->status; - - cairo_matrix_init_translate (&matrix, -x, -y); - cairo_pattern_set_matrix (pattern, &matrix); - - status = _cairo_default_context_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - - return status; -} - -static cairo_pattern_t * -_cairo_default_context_get_source (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_source (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_set_tolerance (void *abstract_cr, - double tolerance) -{ - cairo_default_context_t *cr = abstract_cr; - - if (tolerance < CAIRO_TOLERANCE_MINIMUM) - tolerance = CAIRO_TOLERANCE_MINIMUM; - - return _cairo_gstate_set_tolerance (cr->gstate, tolerance); -} - -static cairo_status_t -_cairo_default_context_set_operator (void *abstract_cr, cairo_operator_t op) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_operator (cr->gstate, op); -} - -static cairo_status_t -_cairo_default_context_set_opacity (void *abstract_cr, double opacity) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_opacity (cr->gstate, opacity); -} - -static cairo_status_t -_cairo_default_context_set_antialias (void *abstract_cr, - cairo_antialias_t antialias) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_antialias (cr->gstate, antialias); -} - -static cairo_status_t -_cairo_default_context_set_fill_rule (void *abstract_cr, - cairo_fill_rule_t fill_rule) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_fill_rule (cr->gstate, fill_rule); -} - -static cairo_status_t -_cairo_default_context_set_line_width (void *abstract_cr, - double line_width) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_line_width (cr->gstate, line_width); -} - -static cairo_status_t -_cairo_default_context_set_line_cap (void *abstract_cr, - cairo_line_cap_t line_cap) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_line_cap (cr->gstate, line_cap); -} - -static cairo_status_t -_cairo_default_context_set_line_join (void *abstract_cr, - cairo_line_join_t line_join) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_line_join (cr->gstate, line_join); -} - -static cairo_status_t -_cairo_default_context_set_dash (void *abstract_cr, - const double *dashes, - int num_dashes, - double offset) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_dash (cr->gstate, - dashes, num_dashes, offset); -} - -static cairo_status_t -_cairo_default_context_set_miter_limit (void *abstract_cr, - double limit) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_miter_limit (cr->gstate, limit); -} - -static cairo_antialias_t -_cairo_default_context_get_antialias (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_antialias (cr->gstate); -} - -static void -_cairo_default_context_get_dash (void *abstract_cr, - double *dashes, - int *num_dashes, - double *offset) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_get_dash (cr->gstate, dashes, num_dashes, offset); -} - -static cairo_fill_rule_t -_cairo_default_context_get_fill_rule (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_fill_rule (cr->gstate); -} - -static double -_cairo_default_context_get_line_width (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_line_width (cr->gstate); -} - -static cairo_line_cap_t -_cairo_default_context_get_line_cap (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_line_cap (cr->gstate); -} - -static cairo_line_join_t -_cairo_default_context_get_line_join (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_line_join (cr->gstate); -} - -static double -_cairo_default_context_get_miter_limit (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_miter_limit (cr->gstate); -} - -static cairo_operator_t -_cairo_default_context_get_operator (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_operator (cr->gstate); -} - -static double -_cairo_default_context_get_opacity (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_opacity (cr->gstate); -} - -static double -_cairo_default_context_get_tolerance (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_tolerance (cr->gstate); -} - - -/* Current tranformation matrix */ - -static cairo_status_t -_cairo_default_context_translate (void *abstract_cr, - double tx, - double ty) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_translate (cr->gstate, tx, ty); -} - -static cairo_status_t -_cairo_default_context_scale (void *abstract_cr, - double sx, - double sy) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_scale (cr->gstate, sx, sy); -} - -static cairo_status_t -_cairo_default_context_rotate (void *abstract_cr, - double theta) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_rotate (cr->gstate, theta); -} - -static cairo_status_t -_cairo_default_context_transform (void *abstract_cr, - const cairo_matrix_t *matrix) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_transform (cr->gstate, matrix); -} - -static cairo_status_t -_cairo_default_context_set_matrix (void *abstract_cr, - const cairo_matrix_t *matrix) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_matrix (cr->gstate, matrix); -} - -static cairo_status_t -_cairo_default_context_set_identity_matrix (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_identity_matrix (cr->gstate); - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_default_context_get_matrix (void *abstract_cr, - cairo_matrix_t *matrix) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_get_matrix (cr->gstate, matrix); -} - -static void -_cairo_default_context_user_to_device (void *abstract_cr, - double *x, - double *y) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_user_to_device (cr->gstate, x, y); -} - -static void -_cairo_default_context_user_to_device_distance (void *abstract_cr, double *dx, double *dy) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy); -} - -static void -_cairo_default_context_device_to_user (void *abstract_cr, - double *x, - double *y) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_device_to_user (cr->gstate, x, y); -} - -static void -_cairo_default_context_device_to_user_distance (void *abstract_cr, - double *dx, - double *dy) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy); -} - -static void -_cairo_default_context_backend_to_user (void *abstract_cr, - double *x, - double *y) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_backend_to_user (cr->gstate, x, y); -} - -static void -_cairo_default_context_backend_to_user_distance (void *abstract_cr, double *dx, double *dy) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_backend_to_user_distance (cr->gstate, dx, dy); -} - -static void -_cairo_default_context_user_to_backend (void *abstract_cr, - double *x, - double *y) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_user_to_backend (cr->gstate, x, y); -} - -static void -_cairo_default_context_user_to_backend_distance (void *abstract_cr, - double *dx, - double *dy) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_user_to_backend_distance (cr->gstate, dx, dy); -} - -/* Path constructor */ - -static cairo_status_t -_cairo_default_context_new_path (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_path_fixed_fini (cr->path); - _cairo_path_fixed_init (cr->path); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_default_context_new_sub_path (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_path_fixed_new_sub_path (cr->path); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_default_context_move_to (void *abstract_cr, double x, double y) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t x_fixed, y_fixed; - - _cairo_gstate_user_to_backend (cr->gstate, &x, &y); - x_fixed = _cairo_fixed_from_double (x); - y_fixed = _cairo_fixed_from_double (y); - - return _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed); -} - -static cairo_status_t -_cairo_default_context_line_to (void *abstract_cr, double x, double y) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t x_fixed, y_fixed; - - _cairo_gstate_user_to_backend (cr->gstate, &x, &y); - x_fixed = _cairo_fixed_from_double (x); - y_fixed = _cairo_fixed_from_double (y); - - return _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); -} - -static cairo_status_t -_cairo_default_context_curve_to (void *abstract_cr, - double x1, double y1, - double x2, double y2, - double x3, double y3) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t x1_fixed, y1_fixed; - cairo_fixed_t x2_fixed, y2_fixed; - cairo_fixed_t x3_fixed, y3_fixed; - - _cairo_gstate_user_to_backend (cr->gstate, &x1, &y1); - _cairo_gstate_user_to_backend (cr->gstate, &x2, &y2); - _cairo_gstate_user_to_backend (cr->gstate, &x3, &y3); - - x1_fixed = _cairo_fixed_from_double (x1); - y1_fixed = _cairo_fixed_from_double (y1); - - x2_fixed = _cairo_fixed_from_double (x2); - y2_fixed = _cairo_fixed_from_double (y2); - - x3_fixed = _cairo_fixed_from_double (x3); - y3_fixed = _cairo_fixed_from_double (y3); - - return _cairo_path_fixed_curve_to (cr->path, - x1_fixed, y1_fixed, - x2_fixed, y2_fixed, - x3_fixed, y3_fixed); -} - -static cairo_status_t -_cairo_default_context_arc (void *abstract_cr, - double xc, double yc, double radius, - double angle1, double angle2, - cairo_bool_t forward) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_status_t status; - - /* Do nothing, successfully, if radius is <= 0 */ - if (radius <= 0.0) { - cairo_fixed_t x_fixed, y_fixed; - - _cairo_gstate_user_to_backend (cr->gstate, &xc, &yc); - x_fixed = _cairo_fixed_from_double (xc); - y_fixed = _cairo_fixed_from_double (yc); - status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; - } - - status = _cairo_default_context_line_to (cr, - xc + radius * cos (angle1), - yc + radius * sin (angle1)); - - if (unlikely (status)) - return status; - - if (forward) - _cairo_arc_path (&cr->base, xc, yc, radius, angle1, angle2); - else - _cairo_arc_path_negative (&cr->base, xc, yc, radius, angle1, angle2); - - return CAIRO_STATUS_SUCCESS; /* any error will have already been set on cr */ -} - -static cairo_status_t -_cairo_default_context_rel_move_to (void *abstract_cr, double dx, double dy) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t dx_fixed, dy_fixed; - - _cairo_gstate_user_to_backend_distance (cr->gstate, &dx, &dy); - - dx_fixed = _cairo_fixed_from_double (dx); - dy_fixed = _cairo_fixed_from_double (dy); - - return _cairo_path_fixed_rel_move_to (cr->path, dx_fixed, dy_fixed); -} - -static cairo_status_t -_cairo_default_context_rel_line_to (void *abstract_cr, double dx, double dy) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t dx_fixed, dy_fixed; - - _cairo_gstate_user_to_backend_distance (cr->gstate, &dx, &dy); - - dx_fixed = _cairo_fixed_from_double (dx); - dy_fixed = _cairo_fixed_from_double (dy); - - return _cairo_path_fixed_rel_line_to (cr->path, dx_fixed, dy_fixed); -} - - -static cairo_status_t -_cairo_default_context_rel_curve_to (void *abstract_cr, - double dx1, double dy1, - double dx2, double dy2, - double dx3, double dy3) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t dx1_fixed, dy1_fixed; - cairo_fixed_t dx2_fixed, dy2_fixed; - cairo_fixed_t dx3_fixed, dy3_fixed; - - _cairo_gstate_user_to_backend_distance (cr->gstate, &dx1, &dy1); - _cairo_gstate_user_to_backend_distance (cr->gstate, &dx2, &dy2); - _cairo_gstate_user_to_backend_distance (cr->gstate, &dx3, &dy3); - - dx1_fixed = _cairo_fixed_from_double (dx1); - dy1_fixed = _cairo_fixed_from_double (dy1); - - dx2_fixed = _cairo_fixed_from_double (dx2); - dy2_fixed = _cairo_fixed_from_double (dy2); - - dx3_fixed = _cairo_fixed_from_double (dx3); - dy3_fixed = _cairo_fixed_from_double (dy3); - - return _cairo_path_fixed_rel_curve_to (cr->path, - dx1_fixed, dy1_fixed, - dx2_fixed, dy2_fixed, - dx3_fixed, dy3_fixed); -} - -static cairo_status_t -_cairo_default_context_close_path (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_path_fixed_close_path (cr->path); -} - -static cairo_status_t -_cairo_default_context_rectangle (void *abstract_cr, - double x, double y, - double width, double height) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_status_t status; - - status = _cairo_default_context_move_to (cr, x, y); - if (unlikely (status)) - return status; - - status = _cairo_default_context_rel_line_to (cr, width, 0); - if (unlikely (status)) - return status; - - status = _cairo_default_context_rel_line_to (cr, 0, height); - if (unlikely (status)) - return status; - - status = _cairo_default_context_rel_line_to (cr, -width, 0); - if (unlikely (status)) - return status; - - return _cairo_default_context_close_path (cr); -} - -static void -_cairo_default_context_path_extents (void *abstract_cr, - double *x1, - double *y1, - double *x2, - double *y2) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_path_extents (cr->gstate, - cr->path, - x1, y1, x2, y2); -} - -static cairo_bool_t -_cairo_default_context_has_current_point (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return cr->path->has_current_point; -} - -static cairo_bool_t -_cairo_default_context_get_current_point (void *abstract_cr, - double *x, - double *y) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_fixed_t x_fixed, y_fixed; - - if (_cairo_path_fixed_get_current_point (cr->path, &x_fixed, &y_fixed)) - { - *x = _cairo_fixed_to_double (x_fixed); - *y = _cairo_fixed_to_double (y_fixed); - _cairo_gstate_backend_to_user (cr->gstate, x, y); - - return TRUE; - } - else - { - return FALSE; - } -} - -static cairo_path_t * -_cairo_default_context_copy_path (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_path_create (cr->path, &cr->base); -} - -static cairo_path_t * -_cairo_default_context_copy_path_flat (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_path_create_flat (cr->path, &cr->base); -} - -static cairo_status_t -_cairo_default_context_append_path (void *abstract_cr, - const cairo_path_t *path) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_path_append_to_context (path, &cr->base); -} - -static cairo_status_t -_cairo_default_context_paint (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_paint (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_paint_with_alpha (void *abstract_cr, - double alpha) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_solid_pattern_t pattern; - cairo_status_t status; - cairo_color_t color; - - if (CAIRO_ALPHA_IS_OPAQUE (alpha)) - return _cairo_gstate_paint (cr->gstate); - - if (CAIRO_ALPHA_IS_ZERO (alpha) && - _cairo_operator_bounded_by_mask (cr->gstate->op)) { - return CAIRO_STATUS_SUCCESS; - } - - _cairo_color_init_rgba (&color, 0., 0., 0., alpha); - _cairo_pattern_init_solid (&pattern, &color); - - status = _cairo_gstate_mask (cr->gstate, &pattern.base); - _cairo_pattern_fini (&pattern.base); - - return status; -} - -static cairo_status_t -_cairo_default_context_mask (void *abstract_cr, - cairo_pattern_t *mask) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_mask (cr->gstate, mask); -} - -static cairo_status_t -_cairo_default_context_stroke_preserve (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_stroke (cr->gstate, cr->path); -} - -static cairo_status_t -_cairo_default_context_stroke (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_status_t status; - - status = _cairo_gstate_stroke (cr->gstate, cr->path); - if (unlikely (status)) - return status; - - return _cairo_default_context_new_path (cr); -} - -static cairo_status_t -_cairo_default_context_in_stroke (void *abstract_cr, - double x, double y, - cairo_bool_t *inside) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_in_stroke (cr->gstate, - cr->path, - x, y, - inside); -} - -static cairo_status_t -_cairo_default_context_stroke_extents (void *abstract_cr, - double *x1, double *y1, double *x2, double *y2) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_stroke_extents (cr->gstate, - cr->path, - x1, y1, x2, y2); -} - -static cairo_status_t -_cairo_default_context_fill_preserve (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_fill (cr->gstate, cr->path); -} - -static cairo_status_t -_cairo_default_context_fill (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_status_t status; - - status = _cairo_gstate_fill (cr->gstate, cr->path); - if (unlikely (status)) - return status; - - return _cairo_default_context_new_path (cr); -} - -static cairo_status_t -_cairo_default_context_in_fill (void *abstract_cr, - double x, double y, - cairo_bool_t *inside) -{ - cairo_default_context_t *cr = abstract_cr; - - *inside = _cairo_gstate_in_fill (cr->gstate, - cr->path, - x, y); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_default_context_fill_extents (void *abstract_cr, - double *x1, double *y1, double *x2, double *y2) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_fill_extents (cr->gstate, - cr->path, - x1, y1, x2, y2); -} - -static cairo_status_t -_cairo_default_context_clip_preserve (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_clip (cr->gstate, cr->path); -} - -static cairo_status_t -_cairo_default_context_clip (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_status_t status; - - status = _cairo_gstate_clip (cr->gstate, cr->path); - if (unlikely (status)) - return status; - - return _cairo_default_context_new_path (cr); -} - -static cairo_status_t -_cairo_default_context_in_clip (void *abstract_cr, - double x, double y, - cairo_bool_t *inside) -{ - cairo_default_context_t *cr = abstract_cr; - - *inside = _cairo_gstate_in_clip (cr->gstate, x, y); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_default_context_reset_clip (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_reset_clip (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_clip_extents (void *abstract_cr, - double *x1, double *y1, double *x2, double *y2) -{ - cairo_default_context_t *cr = abstract_cr; - - if (! _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2)) { - *x1 = -INFINITY; - *y1 = -INFINITY; - *x2 = +INFINITY; - *y2 = +INFINITY; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_rectangle_list_t * -_cairo_default_context_copy_clip_rectangle_list (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_copy_clip_rectangle_list (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_copy_page (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_copy_page (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_show_page (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_show_page (cr->gstate); -} - -static cairo_status_t -_cairo_default_context_set_font_face (void *abstract_cr, - cairo_font_face_t *font_face) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_font_face (cr->gstate, font_face); -} - -static cairo_font_face_t * -_cairo_default_context_get_font_face (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_font_face_t *font_face; - cairo_status_t status; - - status = _cairo_gstate_get_font_face (cr->gstate, &font_face); - if (unlikely (status)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *) &_cairo_font_face_nil; - } - - return font_face; -} - -static cairo_status_t -_cairo_default_context_font_extents (void *abstract_cr, - cairo_font_extents_t *extents) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_get_font_extents (cr->gstate, extents); -} - -static cairo_status_t -_cairo_default_context_set_font_size (void *abstract_cr, - double size) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_font_size (cr->gstate, size); -} - -static cairo_status_t -_cairo_default_context_set_font_matrix (void *abstract_cr, - const cairo_matrix_t *matrix) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_set_font_matrix (cr->gstate, matrix); -} - -static void -_cairo_default_context_get_font_matrix (void *abstract_cr, - cairo_matrix_t *matrix) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_get_font_matrix (cr->gstate, matrix); -} - -static cairo_status_t -_cairo_default_context_set_font_options (void *abstract_cr, - const cairo_font_options_t *options) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_set_font_options (cr->gstate, options); - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_default_context_get_font_options (void *abstract_cr, - cairo_font_options_t *options) -{ - cairo_default_context_t *cr = abstract_cr; - - _cairo_gstate_get_font_options (cr->gstate, options); -} - -static cairo_status_t -_cairo_default_context_set_scaled_font (void *abstract_cr, - cairo_scaled_font_t *scaled_font) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_bool_t was_previous; - cairo_status_t status; - - if (scaled_font == cr->gstate->scaled_font) - return CAIRO_STATUS_SUCCESS; - - was_previous = scaled_font == cr->gstate->previous_scaled_font; - - status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face); - if (unlikely (status)) - return status; - - status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix); - if (unlikely (status)) - return status; - - _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options); - - if (was_previous) - cr->gstate->scaled_font = cairo_scaled_font_reference (scaled_font); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_scaled_font_t * -_cairo_default_context_get_scaled_font (void *abstract_cr) -{ - cairo_default_context_t *cr = abstract_cr; - cairo_scaled_font_t *scaled_font; - cairo_status_t status; - - status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font); - if (unlikely (status)) - return _cairo_scaled_font_create_in_error (status); - - return scaled_font; -} - -static cairo_status_t -_cairo_default_context_glyphs (void *abstract_cr, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_glyph_text_info_t *info) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_show_text_glyphs (cr->gstate, glyphs, num_glyphs, info); -} - -static cairo_status_t -_cairo_default_context_glyph_path (void *abstract_cr, - const cairo_glyph_t *glyphs, - int num_glyphs) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_glyph_path (cr->gstate, - glyphs, num_glyphs, - cr->path); -} - -static cairo_status_t -_cairo_default_context_glyph_extents (void *abstract_cr, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents) -{ - cairo_default_context_t *cr = abstract_cr; - - return _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents); -} - -static const cairo_backend_t _cairo_default_context_backend = { - CAIRO_TYPE_DEFAULT, - _cairo_default_context_destroy, - - _cairo_default_context_get_original_target, - _cairo_default_context_get_current_target, - - _cairo_default_context_save, - _cairo_default_context_restore, - - _cairo_default_context_push_group, - _cairo_default_context_pop_group, - - _cairo_default_context_set_source_rgba, - _cairo_default_context_set_source_surface, - _cairo_default_context_set_source, - _cairo_default_context_get_source, - - _cairo_default_context_set_antialias, - _cairo_default_context_set_dash, - _cairo_default_context_set_fill_rule, - _cairo_default_context_set_line_cap, - _cairo_default_context_set_line_join, - _cairo_default_context_set_line_width, - _cairo_default_context_set_miter_limit, - _cairo_default_context_set_opacity, - _cairo_default_context_set_operator, - _cairo_default_context_set_tolerance, - _cairo_default_context_get_antialias, - _cairo_default_context_get_dash, - _cairo_default_context_get_fill_rule, - _cairo_default_context_get_line_cap, - _cairo_default_context_get_line_join, - _cairo_default_context_get_line_width, - _cairo_default_context_get_miter_limit, - _cairo_default_context_get_opacity, - _cairo_default_context_get_operator, - _cairo_default_context_get_tolerance, - - _cairo_default_context_translate, - _cairo_default_context_scale, - _cairo_default_context_rotate, - _cairo_default_context_transform, - _cairo_default_context_set_matrix, - _cairo_default_context_set_identity_matrix, - _cairo_default_context_get_matrix, - - _cairo_default_context_user_to_device, - _cairo_default_context_user_to_device_distance, - _cairo_default_context_device_to_user, - _cairo_default_context_device_to_user_distance, - - _cairo_default_context_user_to_backend, - _cairo_default_context_user_to_backend_distance, - _cairo_default_context_backend_to_user, - _cairo_default_context_backend_to_user_distance, - - _cairo_default_context_new_path, - _cairo_default_context_new_sub_path, - _cairo_default_context_move_to, - _cairo_default_context_rel_move_to, - _cairo_default_context_line_to, - _cairo_default_context_rel_line_to, - _cairo_default_context_curve_to, - _cairo_default_context_rel_curve_to, - NULL, /* arc-to */ - NULL, /* rel-arc-to */ - _cairo_default_context_close_path, - _cairo_default_context_arc, - _cairo_default_context_rectangle, - _cairo_default_context_path_extents, - _cairo_default_context_has_current_point, - _cairo_default_context_get_current_point, - _cairo_default_context_copy_path, - _cairo_default_context_copy_path_flat, - _cairo_default_context_append_path, - - NULL, /* stroke-to-path */ - - _cairo_default_context_clip, - _cairo_default_context_clip_preserve, - _cairo_default_context_in_clip, - _cairo_default_context_clip_extents, - _cairo_default_context_reset_clip, - _cairo_default_context_copy_clip_rectangle_list, - - _cairo_default_context_paint, - _cairo_default_context_paint_with_alpha, - _cairo_default_context_mask, - - _cairo_default_context_stroke, - _cairo_default_context_stroke_preserve, - _cairo_default_context_in_stroke, - _cairo_default_context_stroke_extents, - - _cairo_default_context_fill, - _cairo_default_context_fill_preserve, - _cairo_default_context_in_fill, - _cairo_default_context_fill_extents, - - _cairo_default_context_set_font_face, - _cairo_default_context_get_font_face, - _cairo_default_context_set_font_size, - _cairo_default_context_set_font_matrix, - _cairo_default_context_get_font_matrix, - _cairo_default_context_set_font_options, - _cairo_default_context_get_font_options, - _cairo_default_context_set_scaled_font, - _cairo_default_context_get_scaled_font, - _cairo_default_context_font_extents, - - _cairo_default_context_glyphs, - _cairo_default_context_glyph_path, - _cairo_default_context_glyph_extents, - - _cairo_default_context_copy_page, - _cairo_default_context_show_page, -}; - -cairo_status_t -_cairo_default_context_init (cairo_default_context_t *cr, void *target) -{ - _cairo_init (&cr->base, &_cairo_default_context_backend); - _cairo_path_fixed_init (cr->path); - - cr->gstate = &cr->gstate_tail[0]; - cr->gstate_freelist = &cr->gstate_tail[1]; - cr->gstate_tail[1].next = NULL; - - return _cairo_gstate_init (cr->gstate, target); -} - -cairo_t * -_cairo_default_context_create (void *target) -{ - cairo_default_context_t *cr; - cairo_status_t status; - - cr = _freed_pool_get (&context_pool); - if (unlikely (cr == NULL)) { - cr = malloc (sizeof (cairo_default_context_t)); - if (unlikely (cr == NULL)) - return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - status = _cairo_default_context_init (cr, target); - if (unlikely (status)) { - _freed_pool_put (&context_pool, cr); - return _cairo_create_in_error (status); - } - - return &cr->base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-deflate-stream.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-deflate-stream.c deleted file mode 100644 index ae23bda9472..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-deflate-stream.c +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Author(s): - * Adrian Johnson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_DEFLATE_STREAM - -#include "cairo-error-private.h" -#include "cairo-output-stream-private.h" -#include - -#define BUFFER_SIZE 16384 - -typedef struct _cairo_deflate_stream { - cairo_output_stream_t base; - cairo_output_stream_t *output; - z_stream zlib_stream; - unsigned char input_buf[BUFFER_SIZE]; - unsigned char output_buf[BUFFER_SIZE]; -} cairo_deflate_stream_t; - -static void -cairo_deflate_stream_deflate (cairo_deflate_stream_t *stream, cairo_bool_t flush) -{ - int ret; - cairo_bool_t finished; - - do { - ret = deflate (&stream->zlib_stream, flush ? Z_FINISH : Z_NO_FLUSH); - if (flush || stream->zlib_stream.avail_out == 0) - { - _cairo_output_stream_write (stream->output, - stream->output_buf, - BUFFER_SIZE - stream->zlib_stream.avail_out); - stream->zlib_stream.next_out = stream->output_buf; - stream->zlib_stream.avail_out = BUFFER_SIZE; - } - - finished = TRUE; - if (stream->zlib_stream.avail_in != 0) - finished = FALSE; - if (flush && ret != Z_STREAM_END) - finished = FALSE; - - } while (!finished); - - stream->zlib_stream.next_in = stream->input_buf; -} - -static cairo_status_t -_cairo_deflate_stream_write (cairo_output_stream_t *base, - const unsigned char *data, - unsigned int length) -{ - cairo_deflate_stream_t *stream = (cairo_deflate_stream_t *) base; - unsigned int count; - const unsigned char *p = data; - - while (length) { - count = length; - if (count > BUFFER_SIZE - stream->zlib_stream.avail_in) - count = BUFFER_SIZE - stream->zlib_stream.avail_in; - memcpy (stream->input_buf + stream->zlib_stream.avail_in, p, count); - p += count; - stream->zlib_stream.avail_in += count; - length -= count; - - if (stream->zlib_stream.avail_in == BUFFER_SIZE) - cairo_deflate_stream_deflate (stream, FALSE); - } - - return _cairo_output_stream_get_status (stream->output); -} - -static cairo_status_t -_cairo_deflate_stream_close (cairo_output_stream_t *base) -{ - cairo_deflate_stream_t *stream = (cairo_deflate_stream_t *) base; - - cairo_deflate_stream_deflate (stream, TRUE); - deflateEnd (&stream->zlib_stream); - - return _cairo_output_stream_get_status (stream->output); -} - -cairo_output_stream_t * -_cairo_deflate_stream_create (cairo_output_stream_t *output) -{ - cairo_deflate_stream_t *stream; - - if (output->status) - return _cairo_output_stream_create_in_error (output->status); - - stream = malloc (sizeof (cairo_deflate_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - _cairo_deflate_stream_write, - NULL, - _cairo_deflate_stream_close); - stream->output = output; - - stream->zlib_stream.zalloc = Z_NULL; - stream->zlib_stream.zfree = Z_NULL; - stream->zlib_stream.opaque = Z_NULL; - - if (deflateInit (&stream->zlib_stream, Z_DEFAULT_COMPRESSION) != Z_OK) { - free (stream); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - stream->zlib_stream.next_in = stream->input_buf; - stream->zlib_stream.avail_in = 0; - stream->zlib_stream.next_out = stream->output_buf; - stream->zlib_stream.avail_out = BUFFER_SIZE; - - return &stream->base; -} - -#endif /* CAIRO_HAS_DEFLATE_STREAM */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-deprecated.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-deprecated.h deleted file mode 100644 index 7a56aadbfe1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-deprecated.h +++ /dev/null @@ -1,123 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_DEPRECATED_H -#define CAIRO_DEPRECATED_H - -#define CAIRO_FONT_TYPE_ATSUI CAIRO_FONT_TYPE_QUARTZ - -/* Obsolete functions. These definitions exist to coerce the compiler - * into providing a little bit of guidance with its error - * messages. The idea is to help users port their old code without - * having to dig through lots of documentation. - * - * The first set of REPLACED_BY functions is for functions whose names - * have just been changed. So fixing these up is mechanical, (and - * automated by means of the cairo/util/cairo-api-update script. - * - * The second set of DEPRECATED_BY functions is for functions where - * the replacement is used in a different way, (ie. different - * arguments, multiple functions instead of one, etc). Fixing these up - * will require a bit more work on the user's part, (and hopefully we - * can get cairo-api-update to find these and print some guiding - * information). - */ -#define cairo_current_font_extents cairo_current_font_extents_REPLACED_BY_cairo_font_extents -#define cairo_get_font_extents cairo_get_font_extents_REPLACED_BY_cairo_font_extents -#define cairo_current_operator cairo_current_operator_REPLACED_BY_cairo_get_operator -#define cairo_current_tolerance cairo_current_tolerance_REPLACED_BY_cairo_get_tolerance -#define cairo_current_point cairo_current_point_REPLACED_BY_cairo_get_current_point -#define cairo_current_fill_rule cairo_current_fill_rule_REPLACED_BY_cairo_get_fill_rule -#define cairo_current_line_width cairo_current_line_width_REPLACED_BY_cairo_get_line_width -#define cairo_current_line_cap cairo_current_line_cap_REPLACED_BY_cairo_get_line_cap -#define cairo_current_line_join cairo_current_line_join_REPLACED_BY_cairo_get_line_join -#define cairo_current_miter_limit cairo_current_miter_limit_REPLACED_BY_cairo_get_miter_limit -#define cairo_current_matrix cairo_current_matrix_REPLACED_BY_cairo_get_matrix -#define cairo_current_target_surface cairo_current_target_surface_REPLACED_BY_cairo_get_target -#define cairo_get_status cairo_get_status_REPLACED_BY_cairo_status -#define cairo_concat_matrix cairo_concat_matrix_REPLACED_BY_cairo_transform -#define cairo_scale_font cairo_scale_font_REPLACED_BY_cairo_set_font_size -#define cairo_select_font cairo_select_font_REPLACED_BY_cairo_select_font_face -#define cairo_transform_font cairo_transform_font_REPLACED_BY_cairo_set_font_matrix -#define cairo_transform_point cairo_transform_point_REPLACED_BY_cairo_user_to_device -#define cairo_transform_distance cairo_transform_distance_REPLACED_BY_cairo_user_to_device_distance -#define cairo_inverse_transform_point cairo_inverse_transform_point_REPLACED_BY_cairo_device_to_user -#define cairo_inverse_transform_distance cairo_inverse_transform_distance_REPLACED_BY_cairo_device_to_user_distance -#define cairo_init_clip cairo_init_clip_REPLACED_BY_cairo_reset_clip -#define cairo_surface_create_for_image cairo_surface_create_for_image_REPLACED_BY_cairo_image_surface_create_for_data -#define cairo_default_matrix cairo_default_matrix_REPLACED_BY_cairo_identity_matrix -#define cairo_matrix_set_affine cairo_matrix_set_affine_REPLACED_BY_cairo_matrix_init -#define cairo_matrix_set_identity cairo_matrix_set_identity_REPLACED_BY_cairo_matrix_init_identity -#define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_REPLACED_BY_cairo_pattern_add_color_stop_rgba -#define cairo_set_rgb_color cairo_set_rgb_color_REPLACED_BY_cairo_set_source_rgb -#define cairo_set_pattern cairo_set_pattern_REPLACED_BY_cairo_set_source -#define cairo_xlib_surface_create_for_pixmap_with_visual cairo_xlib_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xlib_surface_create -#define cairo_xlib_surface_create_for_window_with_visual cairo_xlib_surface_create_for_window_with_visual_REPLACED_BY_cairo_xlib_surface_create -#define cairo_xcb_surface_create_for_pixmap_with_visual cairo_xcb_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xcb_surface_create -#define cairo_xcb_surface_create_for_window_with_visual cairo_xcb_surface_create_for_window_with_visual_REPLACED_BY_cairo_xcb_surface_create -#define cairo_ps_surface_set_dpi cairo_ps_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution -#define cairo_pdf_surface_set_dpi cairo_pdf_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution -#define cairo_svg_surface_set_dpi cairo_svg_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution -#define cairo_atsui_font_face_create_for_atsu_font_id cairo_atsui_font_face_create_for_atsu_font_id_REPLACED_BY_cairo_quartz_font_face_create_for_atsu_font_id - -#define cairo_current_path cairo_current_path_DEPRECATED_BY_cairo_copy_path -#define cairo_current_path_flat cairo_current_path_flat_DEPRECATED_BY_cairo_copy_path_flat -#define cairo_get_path cairo_get_path_DEPRECATED_BY_cairo_copy_path -#define cairo_get_path_flat cairo_get_path_flat_DEPRECATED_BY_cairo_get_path_flat -#define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba_OR_cairo_paint_with_alpha -#define cairo_show_surface cairo_show_surface_DEPRECATED_BY_cairo_set_source_surface_AND_cairo_paint -#define cairo_copy cairo_copy_DEPRECATED_BY_cairo_create_AND_MANY_INDIVIDUAL_FUNCTIONS -#define cairo_surface_set_repeat cairo_surface_set_repeat_DEPRECATED_BY_cairo_pattern_set_extend -#define cairo_surface_set_matrix cairo_surface_set_matrix_DEPRECATED_BY_cairo_pattern_set_matrix -#define cairo_surface_get_matrix cairo_surface_get_matrix_DEPRECATED_BY_cairo_pattern_get_matrix -#define cairo_surface_set_filter cairo_surface_set_filter_DEPRECATED_BY_cairo_pattern_set_filter -#define cairo_surface_get_filter cairo_surface_get_filter_DEPRECATED_BY_cairo_pattern_get_filter -#define cairo_matrix_create cairo_matrix_create_DEPRECATED_BY_cairo_matrix_t -#define cairo_matrix_destroy cairo_matrix_destroy_DEPRECATED_BY_cairo_matrix_t -#define cairo_matrix_copy cairo_matrix_copy_DEPRECATED_BY_cairo_matrix_t -#define cairo_matrix_get_affine cairo_matrix_get_affine_DEPRECATED_BY_cairo_matrix_t -#define cairo_set_target_surface cairo_set_target_surface_DEPRECATED_BY_cairo_create -#define cairo_set_target_image cairo_set_target_image_DEPRECATED_BY_cairo_image_surface_create_for_data -#define cairo_set_target_pdf cairo_set_target_pdf_DEPRECATED_BY_cairo_pdf_surface_create -#define cairo_set_target_png cairo_set_target_png_DEPRECATED_BY_cairo_surface_write_to_png -#define cairo_set_target_ps cairo_set_target_ps_DEPRECATED_BY_cairo_ps_surface_create -#define cairo_set_target_quartz cairo_set_target_quartz_DEPRECATED_BY_cairo_quartz_surface_create -#define cairo_set_target_win32 cairo_set_target_win32_DEPRECATED_BY_cairo_win32_surface_create -#define cairo_set_target_xcb cairo_set_target_xcb_DEPRECATED_BY_cairo_xcb_surface_create -#define cairo_set_target_drawable cairo_set_target_drawable_DEPRECATED_BY_cairo_xlib_surface_create -#define cairo_get_status_string cairo_get_status_string_DEPRECATED_BY_cairo_status_AND_cairo_status_to_string -#define cairo_status_string cairo_status_string_DEPRECATED_BY_cairo_status_AND_cairo_status_to_string - -#endif /* CAIRO_DEPRECATED_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-device-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-device-private.h deleted file mode 100644 index 6eb44f3b634..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-device-private.h +++ /dev/null @@ -1,86 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributors(s): - * Chris Wilson - */ - -#ifndef _CAIRO_DEVICE_PRIVATE_H_ -#define _CAIRO_DEVICE_PRIVATE_H_ - -#include "cairo-compiler-private.h" -#include "cairo-mutex-private.h" -#include "cairo-reference-count-private.h" -#include "cairo-types-private.h" - -struct _cairo_device { - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; - - const cairo_device_backend_t *backend; - - cairo_recursive_mutex_t mutex; - unsigned mutex_depth; - - cairo_bool_t finished; -}; - -struct _cairo_device_backend { - cairo_device_type_t type; - - void (*lock) (void *device); - void (*unlock) (void *device); - - cairo_warn cairo_status_t (*flush) (void *device); - void (*finish) (void *device); - void (*destroy) (void *device); -}; - -cairo_private cairo_device_t * -_cairo_device_create_in_error (cairo_status_t status); - -cairo_private void -_cairo_device_init (cairo_device_t *device, - const cairo_device_backend_t *backend); - -cairo_private cairo_status_t -_cairo_device_set_error (cairo_device_t *device, - cairo_status_t error); - -slim_hidden_proto_no_warn (cairo_device_reference); -slim_hidden_proto (cairo_device_acquire); -slim_hidden_proto (cairo_device_release); -slim_hidden_proto (cairo_device_flush); -slim_hidden_proto (cairo_device_finish); -slim_hidden_proto (cairo_device_destroy); - -#endif /* _CAIRO_DEVICE_PRIVATE_H_ */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-device.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-device.c deleted file mode 100644 index 585a9c1c41f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-device.c +++ /dev/null @@ -1,541 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributors(s): - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-device-private.h" -#include "cairo-error-private.h" - -/** - * SECTION:cairo-device - * @Title: cairo_device_t - * @Short_Description: interface to underlying rendering system - * @See_Also: #cairo_surface_t - * - * Devices are the abstraction Cairo employs for the rendering system - * used by a #cairo_surface_t. You can get the device of a surface using - * cairo_surface_get_device(). - * - * Devices are created using custom functions specific to the rendering - * system you want to use. See the documentation for the surface types - * for those functions. - * - * An important function that devices fulfill is sharing access to the - * rendering system between Cairo and your application. If you want to - * access a device directly that you used to draw to with Cairo, you must - * first call cairo_device_flush() to ensure that Cairo finishes all - * operations on the device and resets it to a clean state. - * - * Cairo also provides the functions cairo_device_acquire() and - * cairo_device_release() to synchronize access to the rendering system - * in a multithreaded environment. This is done internally, but can also - * be used by applications. - * - * Putting this all together, a function that works with devices should - * look something like this: - * - * void - * my_device_modifying_function (cairo_device_t *device) - * { - * cairo_status_t status; - * - * // Ensure the device is properly reset - * cairo_device_flush (device); - * // Try to acquire the device - * status = cairo_device_acquire (device); - * if (status != CAIRO_STATUS_SUCCESS) { - * printf ("Failed to acquire the device: %s\n", cairo_status_to_string (status)); - * return; - * } - * - * // Do the custom operations on the device here. - * // But do not call any Cairo functions that might acquire devices. - * - * // Release the device when done. - * cairo_device_release (device); - * } - * - * - * Please refer to the documentation of each backend for - * additional usage requirements, guarantees provided, and - * interactions with existing surface API of the device functions for - * surfaces of that type. - * - **/ - -static const cairo_device_t _nil_device = { - CAIRO_REFERENCE_COUNT_INVALID, - CAIRO_STATUS_NO_MEMORY, -}; - -static const cairo_device_t _mismatch_device = { - CAIRO_REFERENCE_COUNT_INVALID, - CAIRO_STATUS_DEVICE_TYPE_MISMATCH, -}; - -static const cairo_device_t _invalid_device = { - CAIRO_REFERENCE_COUNT_INVALID, - CAIRO_STATUS_DEVICE_ERROR, -}; - -cairo_device_t * -_cairo_device_create_in_error (cairo_status_t status) -{ - switch (status) { - case CAIRO_STATUS_NO_MEMORY: - return (cairo_device_t *) &_nil_device; - case CAIRO_STATUS_DEVICE_ERROR: - return (cairo_device_t *) &_invalid_device; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - return (cairo_device_t *) &_mismatch_device; - - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - /* fall-through */ - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_STATUS: - case CAIRO_STATUS_INVALID_FORMAT: - case CAIRO_STATUS_INVALID_VISUAL: - case CAIRO_STATUS_READ_ERROR: - case CAIRO_STATUS_WRITE_ERROR: - case CAIRO_STATUS_FILE_NOT_FOUND: - case CAIRO_STATUS_TEMP_FILE_ERROR: - case CAIRO_STATUS_INVALID_STRIDE: - case CAIRO_STATUS_INVALID_SIZE: - case CAIRO_STATUS_INVALID_RESTORE: - case CAIRO_STATUS_INVALID_POP_GROUP: - case CAIRO_STATUS_NO_CURRENT_POINT: - case CAIRO_STATUS_INVALID_MATRIX: - case CAIRO_STATUS_NULL_POINTER: - case CAIRO_STATUS_INVALID_STRING: - case CAIRO_STATUS_INVALID_PATH_DATA: - case CAIRO_STATUS_SURFACE_FINISHED: - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_DASH: - case CAIRO_STATUS_INVALID_DSC_COMMENT: - case CAIRO_STATUS_INVALID_INDEX: - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: - case CAIRO_STATUS_FONT_TYPE_MISMATCH: - case CAIRO_STATUS_USER_FONT_IMMUTABLE: - case CAIRO_STATUS_USER_FONT_ERROR: - case CAIRO_STATUS_NEGATIVE_COUNT: - case CAIRO_STATUS_INVALID_CLUSTERS: - case CAIRO_STATUS_INVALID_SLANT: - case CAIRO_STATUS_INVALID_WEIGHT: - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: - case CAIRO_STATUS_INVALID_CONTENT: - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: - case CAIRO_STATUS_DEVICE_FINISHED: - case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: - default: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_device_t *) &_nil_device; - } -} - -void -_cairo_device_init (cairo_device_t *device, - const cairo_device_backend_t *backend) -{ - CAIRO_REFERENCE_COUNT_INIT (&device->ref_count, 1); - device->status = CAIRO_STATUS_SUCCESS; - - device->backend = backend; - - CAIRO_RECURSIVE_MUTEX_INIT (device->mutex); - device->mutex_depth = 0; - - device->finished = FALSE; - - _cairo_user_data_array_init (&device->user_data); -} - -/** - * cairo_device_reference: - * @device: a #cairo_device_t - * - * Increases the reference count on @device by one. This prevents - * @device from being destroyed until a matching call to - * cairo_device_destroy() is made. - * - * The number of references to a #cairo_device_t can be get using - * cairo_device_get_reference_count(). - * - * Return value: the referenced #cairo_device_t. - * - * Since: 1.10 - **/ -cairo_device_t * -cairo_device_reference (cairo_device_t *device) -{ - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { - return device; - } - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&device->ref_count)); - _cairo_reference_count_inc (&device->ref_count); - - return device; -} -slim_hidden_def (cairo_device_reference); - -/** - * cairo_device_status: - * @device: a #cairo_device_t - * - * Checks whether an error has previously occurred for this - * device. - * - * Return value: %CAIRO_STATUS_SUCCESS on success or an error code if - * the device is in an error state. - * - * Since: 1.10 - **/ -cairo_status_t -cairo_device_status (cairo_device_t *device) -{ - if (device == NULL) - return CAIRO_STATUS_NULL_POINTER; - - return device->status; -} - -/** - * cairo_device_flush: - * @device: a #cairo_device_t - * - * Finish any pending operations for the device and also restore any - * temporary modifications cairo has made to the device's state. - * This function must be called before switching from using the - * device with Cairo to operating on it directly with native APIs. - * If the device doesn't support direct access, then this function - * does nothing. - * - * This function may acquire devices. - * - * Since: 1.10 - **/ -void -cairo_device_flush (cairo_device_t *device) -{ - cairo_status_t status; - - if (device == NULL || device->status) - return; - - if (device->finished) - return; - - if (device->backend->flush != NULL) { - status = device->backend->flush (device); - if (unlikely (status)) - status = _cairo_device_set_error (device, status); - } -} -slim_hidden_def (cairo_device_flush); - -/** - * cairo_device_finish: - * @device: the #cairo_device_t to finish - * - * This function finishes the device and drops all references to - * external resources. All surfaces, fonts and other objects created - * for this @device will be finished, too. - * Further operations on the @device will not affect the @device but - * will instead trigger a %CAIRO_STATUS_DEVICE_FINISHED error. - * - * When the last call to cairo_device_destroy() decreases the - * reference count to zero, cairo will call cairo_device_finish() if - * it hasn't been called already, before freeing the resources - * associated with the device. - * - * This function may acquire devices. - * - * Since: 1.10 - **/ -void -cairo_device_finish (cairo_device_t *device) -{ - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { - return; - } - - if (device->finished) - return; - - cairo_device_flush (device); - - if (device->backend->finish != NULL) - device->backend->finish (device); - - /* We only finish the device after the backend's callback returns because - * the device might still be needed during the callback - * (e.g. for cairo_device_acquire ()). - */ - device->finished = TRUE; -} -slim_hidden_def (cairo_device_finish); - -/** - * cairo_device_destroy: - * @device: a #cairo_device_t - * - * Decreases the reference count on @device by one. If the result is - * zero, then @device and all associated resources are freed. See - * cairo_device_reference(). - * - * This function may acquire devices if the last reference was dropped. - * - * Since: 1.10 - **/ -void -cairo_device_destroy (cairo_device_t *device) -{ - cairo_user_data_array_t user_data; - - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { - return; - } - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&device->ref_count)); - if (! _cairo_reference_count_dec_and_test (&device->ref_count)) - return; - - cairo_device_finish (device); - - assert (device->mutex_depth == 0); - CAIRO_MUTEX_FINI (device->mutex); - - user_data = device->user_data; - - device->backend->destroy (device); - - _cairo_user_data_array_fini (&user_data); - -} -slim_hidden_def (cairo_device_destroy); - -/** - * cairo_device_get_type: - * @device: a #cairo_device_t - * - * This function returns the type of the device. See #cairo_device_type_t - * for available types. - * - * Return value: The type of @device. - * - * Since: 1.10 - **/ -cairo_device_type_t -cairo_device_get_type (cairo_device_t *device) -{ - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { - return CAIRO_DEVICE_TYPE_INVALID; - } - - return device->backend->type; -} - -/** - * cairo_device_acquire: - * @device: a #cairo_device_t - * - * Acquires the @device for the current thread. This function will block - * until no other thread has acquired the device. - * - * If the return value is %CAIRO_STATUS_SUCCESS, you successfully acquired the - * device. From now on your thread owns the device and no other thread will be - * able to acquire it until a matching call to cairo_device_release(). It is - * allowed to recursively acquire the device multiple times from the same - * thread. - * - * You must never acquire two different devices at the same time - * unless this is explicitly allowed. Otherwise the possibility of deadlocks - * exist. - * - * As various Cairo functions can acquire devices when called, these functions - * may also cause deadlocks when you call them with an acquired device. So you - * must not have a device acquired when calling them. These functions are - * marked in the documentation. - * - * - * Return value: %CAIRO_STATUS_SUCCESS on success or an error code if - * the device is in an error state and could not be - * acquired. After a successful call to cairo_device_acquire(), - * a matching call to cairo_device_release() is required. - * - * Since: 1.10 - **/ -cairo_status_t -cairo_device_acquire (cairo_device_t *device) -{ - if (device == NULL) - return CAIRO_STATUS_SUCCESS; - - if (unlikely (device->status)) - return device->status; - - if (unlikely (device->finished)) - return _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_FINISHED); - - CAIRO_MUTEX_LOCK (device->mutex); - if (device->mutex_depth++ == 0) { - if (device->backend->lock != NULL) - device->backend->lock (device); - } - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_device_acquire); - -/** - * cairo_device_release: - * @device: a #cairo_device_t - * - * Releases a @device previously acquired using cairo_device_acquire(). See - * that function for details. - * - * Since: 1.10 - **/ -void -cairo_device_release (cairo_device_t *device) -{ - if (device == NULL) - return; - - assert (device->mutex_depth > 0); - - if (--device->mutex_depth == 0) { - if (device->backend->unlock != NULL) - device->backend->unlock (device); - } - - CAIRO_MUTEX_UNLOCK (device->mutex); -} -slim_hidden_def (cairo_device_release); - -cairo_status_t -_cairo_device_set_error (cairo_device_t *device, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return CAIRO_STATUS_SUCCESS; - - _cairo_status_set_error (&device->status, status); - - return _cairo_error (status); -} - -/** - * cairo_device_get_reference_count: - * @device: a #cairo_device_t - * - * Returns the current reference count of @device. - * - * Return value: the current reference count of @device. If the - * object is a nil object, 0 will be returned. - * - * Since: 1.10 - **/ -unsigned int -cairo_device_get_reference_count (cairo_device_t *device) -{ - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&device->ref_count); -} - -/** - * cairo_device_get_user_data: - * @device: a #cairo_device_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Return user data previously attached to @device using the - * specified key. If no user data has been attached with the given - * key this function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - * - * Since: 1.10 - **/ -void * -cairo_device_get_user_data (cairo_device_t *device, - const cairo_user_data_key_t *key) -{ - return _cairo_user_data_array_get_data (&device->user_data, - key); -} - -/** - * cairo_device_set_user_data: - * @device: a #cairo_device_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach to the #cairo_device_t - * @destroy: a #cairo_destroy_func_t which will be called when the - * #cairo_t is destroyed or when new user data is attached using the - * same key. - * - * Attach user data to @device. To remove user data from a surface, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.10 - **/ -cairo_status_t -cairo_device_set_user_data (cairo_device_t *device, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - return device->status; - - return _cairo_user_data_array_set_data (&device->user_data, - key, user_data, destroy); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb-surface.c deleted file mode 100644 index 5ac64ba98ee..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb-surface.c +++ /dev/null @@ -1,544 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2012 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-directfb.h" - -#include "cairo-clip-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-surface-fallback-private.h" - -#include - -#include -#include -#include -#include -#include - -slim_hidden_proto(cairo_directfb_surface_create); - -typedef struct _cairo_dfb_surface { - cairo_image_surface_t image; - - IDirectFB *dfb; - IDirectFBSurface *dfb_surface; - - unsigned blit_premultiplied : 1; -} cairo_dfb_surface_t; - -static cairo_content_t -_directfb_format_to_content (DFBSurfacePixelFormat format) -{ - cairo_content_t content = 0; - - if (DFB_PIXELFORMAT_HAS_ALPHA (format)) - content |= CAIRO_CONTENT_ALPHA; - if (DFB_COLOR_BITS_PER_PIXEL (format)) - content |= CAIRO_CONTENT_COLOR_ALPHA; - - assert(content); - return content; -} - -static inline pixman_format_code_t -_directfb_to_pixman_format (DFBSurfacePixelFormat format) -{ - switch (format) { - case DSPF_UNKNOWN: return 0; - case DSPF_ARGB1555: return PIXMAN_a1r5g5b5; - case DSPF_RGB16: return PIXMAN_r5g6b5; - case DSPF_RGB24: return PIXMAN_r8g8b8; - case DSPF_RGB32: return PIXMAN_x8r8g8b8; - case DSPF_ARGB: return PIXMAN_a8r8g8b8; - case DSPF_A8: return PIXMAN_a8; - case DSPF_YUY2: return PIXMAN_yuy2; - case DSPF_RGB332: return PIXMAN_r3g3b2; - case DSPF_UYVY: return 0; - case DSPF_I420: return 0; - case DSPF_YV12: return PIXMAN_yv12; - case DSPF_LUT8: return 0; - case DSPF_ALUT44: return 0; - case DSPF_AiRGB: return 0; - case DSPF_A1: return 0; /* bit reversed, oops */ - case DSPF_NV12: return 0; - case DSPF_NV16: return 0; - case DSPF_ARGB2554: return 0; - case DSPF_ARGB4444: return PIXMAN_a4r4g4b4; - case DSPF_NV21: return 0; - case DSPF_AYUV: return 0; - case DSPF_A4: return PIXMAN_a4; - case DSPF_ARGB1666: return 0; - case DSPF_ARGB6666: return 0; - case DSPF_RGB18: return 0; - case DSPF_LUT2: return 0; - case DSPF_RGB444: return PIXMAN_x4r4g4b4; - case DSPF_RGB555: return PIXMAN_x1r5g5b5; -#if DFB_NUM_PIXELFORMATS >= 29 - case DSPF_BGR555: return PIXMAN_x1b5g5r5; -#endif - } - return 0; -} - -static cairo_surface_t * -_cairo_dfb_surface_create_similar (void *abstract_src, - cairo_content_t content, - int width, - int height) -{ - cairo_dfb_surface_t *other = abstract_src; - DFBSurfacePixelFormat format; - IDirectFBSurface *buffer; - DFBSurfaceDescription dsc; - cairo_surface_t *surface; - - if (width <= 0 || height <= 0) - return _cairo_image_surface_create_with_content (content, width, height); - - switch (content) { - default: - ASSERT_NOT_REACHED; - case CAIRO_CONTENT_COLOR_ALPHA: - format = DSPF_ARGB; - break; - case CAIRO_CONTENT_COLOR: - format = DSPF_RGB32; - break; - case CAIRO_CONTENT_ALPHA: - format = DSPF_A8; - break; - } - - dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT; - dsc.caps = DSCAPS_PREMULTIPLIED; - dsc.width = width; - dsc.height = height; - dsc.pixelformat = format; - - if (other->dfb->CreateSurface (other->dfb, &dsc, &buffer)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_DEVICE_ERROR)); - - surface = cairo_directfb_surface_create (other->dfb, buffer); - buffer->Release (buffer); - - return surface; -} - -static cairo_status_t -_cairo_dfb_surface_finish (void *abstract_surface) -{ - cairo_dfb_surface_t *surface = abstract_surface; - - surface->dfb_surface->Release (surface->dfb_surface); - return _cairo_image_surface_finish (abstract_surface); -} - -static cairo_image_surface_t * -_cairo_dfb_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_dfb_surface_t *surface = abstract_surface; - - if (surface->image.pixman_image == NULL) { - IDirectFBSurface *buffer = surface->dfb_surface; - pixman_image_t *image; - void *data; - int pitch; - - if (buffer->Lock (buffer, DSLF_READ | DSLF_WRITE, &data, &pitch)) - return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - image = pixman_image_create_bits (surface->image.pixman_format, - surface->image.width, - surface->image.height, - data, pitch); - if (image == NULL) { - buffer->Unlock (buffer); - return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - _cairo_image_surface_init (&surface->image, image, surface->image.pixman_format); - } - - return _cairo_image_surface_map_to_image (&surface->image.base, extents); -} - -static cairo_int_status_t -_cairo_dfb_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_dfb_surface_t *surface = abstract_surface; - return _cairo_image_surface_unmap_image (&surface->image.base, image); -} - -static cairo_status_t -_cairo_dfb_surface_flush (void *abstract_surface, - unsigned flags) -{ - cairo_dfb_surface_t *surface = abstract_surface; - - if (flags) - return CAIRO_STATUS_SUCCESS; - - if (surface->image.pixman_image) { - surface->dfb_surface->Unlock (surface->dfb_surface); - - pixman_image_unref (surface->image.pixman_image); - surface->image.pixman_image = NULL; - surface->image.data = NULL; - } - - return CAIRO_STATUS_SUCCESS; -} - -#if 0 -static inline DFBSurfacePixelFormat -_directfb_from_pixman_format (pixman_format_code_t format) -{ - switch ((int) format) { - case PIXMAN_a1r5g5b5: return DSPF_ARGB1555; - case PIXMAN_r5g6b5: return DSPF_RGB16; - case PIXMAN_r8g8b8: return DSPF_RGB24; - case PIXMAN_x8r8g8b8: return DSPF_RGB32; - case PIXMAN_a8r8g8b8: return DSPF_ARGB; - case PIXMAN_a8: return DSPF_A8; - case PIXMAN_yuy2: return DSPF_YUY2; - case PIXMAN_r3g3b2: return DSPF_RGB332; - case PIXMAN_yv12: return DSPF_YV12; - case PIXMAN_a1: return DSPF_A1; /* bit reversed, oops */ - case PIXMAN_a4r4g4b4: return DSPF_ARGB4444; - case PIXMAN_a4: return DSPF_A4; - case PIXMAN_x4r4g4b4: return DSPF_RGB444; - case PIXMAN_x1r5g5b5: return DSPF_RGB555; -#if DFB_NUM_PIXELFORMATS >= 29 - case PIXMAN_x1b5g5r5: return DSPF_BGR555; -#endif - default: return 0; - } -} - -static cairo_bool_t -_directfb_get_operator (cairo_operator_t operator, - DFBSurfaceBlendFunction *ret_srcblend, - DFBSurfaceBlendFunction *ret_dstblend) -{ - DFBSurfaceBlendFunction srcblend = DSBF_ONE; - DFBSurfaceBlendFunction dstblend = DSBF_ZERO; - - switch (operator) { - case CAIRO_OPERATOR_CLEAR: - srcblend = DSBF_ZERO; - dstblend = DSBF_ZERO; - break; - case CAIRO_OPERATOR_SOURCE: - srcblend = DSBF_ONE; - dstblend = DSBF_ZERO; - break; - case CAIRO_OPERATOR_OVER: - srcblend = DSBF_ONE; - dstblend = DSBF_INVSRCALPHA; - break; - case CAIRO_OPERATOR_IN: - srcblend = DSBF_DESTALPHA; - dstblend = DSBF_ZERO; - break; - case CAIRO_OPERATOR_OUT: - srcblend = DSBF_INVDESTALPHA; - dstblend = DSBF_ZERO; - break; - case CAIRO_OPERATOR_ATOP: - srcblend = DSBF_DESTALPHA; - dstblend = DSBF_INVSRCALPHA; - break; - case CAIRO_OPERATOR_DEST: - srcblend = DSBF_ZERO; - dstblend = DSBF_ONE; - break; - case CAIRO_OPERATOR_DEST_OVER: - srcblend = DSBF_INVDESTALPHA; - dstblend = DSBF_ONE; - break; - case CAIRO_OPERATOR_DEST_IN: - srcblend = DSBF_ZERO; - dstblend = DSBF_SRCALPHA; - break; - case CAIRO_OPERATOR_DEST_OUT: - srcblend = DSBF_ZERO; - dstblend = DSBF_INVSRCALPHA; - break; - case CAIRO_OPERATOR_DEST_ATOP: - srcblend = DSBF_INVDESTALPHA; - dstblend = DSBF_SRCALPHA; - break; - case CAIRO_OPERATOR_XOR: - srcblend = DSBF_INVDESTALPHA; - dstblend = DSBF_INVSRCALPHA; - break; - case CAIRO_OPERATOR_ADD: - srcblend = DSBF_ONE; - dstblend = DSBF_ONE; - break; - case CAIRO_OPERATOR_SATURATE: - /* XXX This does not work. */ -#if 0 - srcblend = DSBF_SRCALPHASAT; - dstblend = DSBF_ONE; - break; -#endif - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - default: - return FALSE; - } - - *ret_srcblend = srcblend; - *ret_dstblend = dstblend; - - return TRUE; -} -#define RUN_CLIPPED(surface, clip_region, clip, func) {\ - if ((clip_region) != NULL) {\ - int n_clips = cairo_region_num_rectangles (clip_region), n; \ - for (n = 0; n < n_clips; n++) {\ - if (clip) {\ - DFBRegion reg, *cli = (clip); \ - cairo_rectangle_int_t rect; \ - cairo_region_get_rectangle (clip_region, n, &rect); \ - reg.x1 = rect.x; \ - reg.y1 = rect.y; \ - reg.x2 = rect.x + rect.width - 1; \ - reg.y2 = rect.y + rect.height - 1; \ - if (reg.x2 < cli->x1 || reg.y2 < cli->y1 ||\ - reg.x1 > cli->x2 || reg.y1 > cli->y2)\ - continue;\ - if (reg.x1 < cli->x1)\ - reg.x1 = cli->x1;\ - if (reg.y1 < cli->y1)\ - reg.y1 = cli->y1;\ - if (reg.x2 > cli->x2)\ - reg.x2 = cli->x2;\ - if (reg.y2 > cli->y2)\ - reg.y2 = cli->y2;\ - (surface)->dfbsurface->SetClip ((surface)->dfbsurface, ®);\ - } else {\ - DFBRegion reg; \ - cairo_rectangle_int_t rect; \ - cairo_region_get_rectangle (clip_region, n, &rect); \ - reg.x1 = rect.x; \ - reg.y1 = rect.y; \ - reg.x2 = rect.x + rect.width - 1; \ - reg.y2 = rect.y + rect.height - 1; \ - (surface)->dfbsurface->SetClip ((surface)->dfbsurface, ®); \ - }\ - func;\ - }\ - } else {\ - (surface)->dfbsurface->SetClip ((surface)->dfbsurface, clip);\ - func;\ - }\ -} - -static cairo_int_status_t -_cairo_dfb_surface_fill_rectangles (void *abstract_surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_rectangle_int_t *rects, - int n_rects) -{ - cairo_dfb_surface_t *dst = abstract_surface; - DFBSurfaceDrawingFlags flags; - DFBSurfaceBlendFunction sblend; - DFBSurfaceBlendFunction dblend; - DFBRectangle r[n_rects]; - int i; - - D_DEBUG_AT (CairoDFB_Render, - "%s( dst=%p, op=%d, color=%p, rects=%p, n_rects=%d ).\n", - __FUNCTION__, dst, op, color, rects, n_rects); - - if (! dst->supported_destination) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _directfb_get_operator (op, &sblend, &dblend)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (CAIRO_COLOR_IS_OPAQUE (color)) { - if (sblend == DSBF_SRCALPHA) - sblend = DSBF_ONE; - else if (sblend == DSBF_INVSRCALPHA) - sblend = DSBF_ZERO; - - if (dblend == DSBF_SRCALPHA) - dblend = DSBF_ONE; - else if (dblend == DSBF_INVSRCALPHA) - dblend = DSBF_ZERO; - } - if ((dst->base.content & CAIRO_CONTENT_ALPHA) == 0) { - if (sblend == DSBF_DESTALPHA) - sblend = DSBF_ONE; - else if (sblend == DSBF_INVDESTALPHA) - sblend = DSBF_ZERO; - - if (dblend == DSBF_DESTALPHA) - dblend = DSBF_ONE; - else if (dblend == DSBF_INVDESTALPHA) - dblend = DSBF_ZERO; - } - - flags = (sblend == DSBF_ONE && dblend == DSBF_ZERO) ? DSDRAW_NOFX : DSDRAW_BLEND; - dst->dfbsurface->SetDrawingFlags (dst->dfbsurface, flags); - if (flags & DSDRAW_BLEND) { - dst->dfbsurface->SetSrcBlendFunction (dst->dfbsurface, sblend); - dst->dfbsurface->SetDstBlendFunction (dst->dfbsurface, dblend); - } - - dst->dfbsurface->SetColor (dst->dfbsurface, - color->red_short >> 8, - color->green_short >> 8, - color->blue_short >> 8, - color->alpha_short >> 8); - - for (i = 0; i < n_rects; i++) { - r[i].x = rects[i].x; - r[i].y = rects[i].y; - r[i].w = rects[i].width; - r[i].h = rects[i].height; - } - - RUN_CLIPPED (dst, NULL, NULL, - dst->dfbsurface->FillRectangles (dst->dfbsurface, r, n_rects)); - - return CAIRO_STATUS_SUCCESS; -} -#endif - -static cairo_surface_backend_t -_cairo_dfb_surface_backend = { - CAIRO_SURFACE_TYPE_DIRECTFB, /*type*/ - _cairo_dfb_surface_finish, /*finish*/ - _cairo_default_context_create, - - _cairo_dfb_surface_create_similar,/*create_similar*/ - NULL, /* create similar image */ - _cairo_dfb_surface_map_to_image, - _cairo_dfb_surface_unmap_image, - - _cairo_surface_default_source, - _cairo_surface_default_acquire_source_image, - _cairo_surface_default_release_source_image, - NULL, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_image_surface_get_extents, - _cairo_image_surface_get_font_options, - - _cairo_dfb_surface_flush, - NULL, /* mark_dirty_rectangle */ - - _cairo_surface_fallback_paint, - _cairo_surface_fallback_mask, - _cairo_surface_fallback_stroke, - _cairo_surface_fallback_fill, - NULL, /* fill-stroke */ - _cairo_surface_fallback_glyphs, -}; - -cairo_surface_t * -cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *dfbsurface) -{ - cairo_dfb_surface_t *surface; - DFBSurfacePixelFormat format; - DFBSurfaceCapabilities caps; - pixman_format_code_t pixman_format; - int width, height; - - D_ASSERT (dfb != NULL); - D_ASSERT (dfbsurface != NULL); - - dfbsurface->GetPixelFormat (dfbsurface, &format); - dfbsurface->GetSize (dfbsurface, &width, &height); - - pixman_format = _directfb_to_pixman_format (format); - if (! pixman_format_supported_destination (pixman_format)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - - surface = calloc (1, sizeof (cairo_dfb_surface_t)); - if (surface == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - /* XXX dfb -> device */ - _cairo_surface_init (&surface->image.base, - &_cairo_dfb_surface_backend, - NULL, /* device */ - _directfb_format_to_content (format)); - - surface->image.pixman_format = pixman_format; - surface->image.format = _cairo_format_from_pixman_format (pixman_format); - - surface->image.width = width; - surface->image.height = height; - surface->image.depth = PIXMAN_FORMAT_DEPTH(pixman_format); - - surface->dfb = dfb; - surface->dfb_surface = dfbsurface; - dfbsurface->AddRef (dfbsurface); - - dfbsurface->GetCapabilities (dfbsurface, &caps); - if (caps & DSCAPS_PREMULTIPLIED) - surface->blit_premultiplied = TRUE; - - return &surface->image.base; -} -slim_hidden_def(cairo_directfb_surface_create); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb.h deleted file mode 100644 index e3d818c6687..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-directfb.h +++ /dev/null @@ -1,67 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -/* - * Environment variables affecting the backend: - * - * %CAIRO_DIRECTFB_NO_ACCEL (boolean) - * if found, disables acceleration at all - * - * %CAIRO_DIRECTFB_ARGB_FONT (boolean) - * if found, enables using ARGB fonts instead of A8 - */ - -#ifndef CAIRO_DIRECTFB_H -#define CAIRO_DIRECTFB_H - -#include "cairo.h" - -#if CAIRO_HAS_DIRECTFB_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *surface); - -CAIRO_END_DECLS - -#else /*CAIRO_HAS_DIRECTFB_SURFACE*/ -# error Cairo was not compiled with support for the directfb backend -#endif /*CAIRO_HAS_DIRECTFB_SURFACE*/ - -#endif /*CAIRO_DIRECTFB_H*/ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-drm.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-drm.h deleted file mode 100644 index 907610dcde8..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-drm.h +++ /dev/null @@ -1,120 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - */ - -#ifndef CAIRO_DRM_H -#define CAIRO_DRM_H - -#include "cairo.h" - -#if CAIRO_HAS_DRM_SURFACE - -CAIRO_BEGIN_DECLS - -struct udev_device; - -cairo_public cairo_device_t * -cairo_drm_device_get (struct udev_device *device); - -cairo_public cairo_device_t * -cairo_drm_device_get_for_fd (int fd); - -cairo_public cairo_device_t * -cairo_drm_device_default (void); - -cairo_public int -cairo_drm_device_get_fd (cairo_device_t *device); - -cairo_public void -cairo_drm_device_throttle (cairo_device_t *device); - -cairo_public cairo_surface_t * -cairo_drm_surface_create (cairo_device_t *device, - cairo_format_t format, - int width, int height); - -cairo_public cairo_surface_t * -cairo_drm_surface_create_for_name (cairo_device_t *device, - unsigned int name, - cairo_format_t format, - int width, int height, int stride); - -cairo_public cairo_surface_t * -cairo_drm_surface_create_from_cacheable_image (cairo_device_t *device, - cairo_surface_t *surface); - -cairo_public cairo_status_t -cairo_drm_surface_enable_scan_out (cairo_surface_t *surface); - -cairo_public unsigned int -cairo_drm_surface_get_handle (cairo_surface_t *surface); - -cairo_public unsigned int -cairo_drm_surface_get_name (cairo_surface_t *surface); - -cairo_public cairo_format_t -cairo_drm_surface_get_format (cairo_surface_t *surface); - -cairo_public int -cairo_drm_surface_get_width (cairo_surface_t *surface); - -cairo_public int -cairo_drm_surface_get_height (cairo_surface_t *surface); - -cairo_public int -cairo_drm_surface_get_stride (cairo_surface_t *surface); - -/* XXX map/unmap, general surface layer? */ - -/* Rough outline, culled from a conversation on IRC: - * map() returns an image-surface representation of the drm-surface, - * which you unmap() when you are finished, i.e. map() pulls the buffer back - * from the GPU, maps it into the CPU domain and gives you direct access to - * the pixels. With the unmap(), the buffer is ready to be used again by the - * GPU and *until* the unmap(), all operations will be done in software. - * - * (Technically calling cairo_surface_flush() on the underlying drm-surface - * will also disassociate the mapping.) -*/ -cairo_public cairo_surface_t * -cairo_drm_surface_map_to_image (cairo_surface_t *surface); - -cairo_public void -cairo_drm_surface_unmap (cairo_surface_t *drm_surface, - cairo_surface_t *image_surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_DRM_SURFACE */ -# error Cairo was not compiled with support for the DRM backend -#endif /* CAIRO_HAS_DRM_SURFACE */ - -#endif /* CAIRO_DRM_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-egl-context.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-egl-context.c deleted file mode 100644 index bf704c630fb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-egl-context.c +++ /dev/null @@ -1,317 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-error-private.h" - -typedef struct _cairo_egl_context { - cairo_gl_context_t base; - - EGLDisplay display; - EGLContext context; - - EGLSurface dummy_surface; - - EGLContext previous_context; - EGLSurface previous_surface; -} cairo_egl_context_t; - -typedef struct _cairo_egl_surface { - cairo_gl_surface_t base; - - EGLSurface egl; -} cairo_egl_surface_t; - - -static cairo_bool_t -_context_acquisition_changed_egl_state (cairo_egl_context_t *ctx, - EGLSurface current_surface) -{ - return ctx->previous_context != ctx->context || - ctx->previous_surface != current_surface; -} - -static EGLSurface -_egl_get_current_surface (cairo_egl_context_t *ctx) -{ - if (ctx->base.current_target == NULL || - _cairo_gl_surface_is_texture (ctx->base.current_target)) { - return ctx->dummy_surface; - } - - return ((cairo_egl_surface_t *) ctx->base.current_target)->egl; -} - -static void -_egl_query_current_state (cairo_egl_context_t *ctx) -{ - ctx->previous_surface = eglGetCurrentSurface (EGL_DRAW); - ctx->previous_context = eglGetCurrentContext (); - - /* If any of the values were none, assume they are all none. Not all - drivers seem well behaved when it comes to using these values across - multiple threads. */ - if (ctx->previous_surface == EGL_NO_SURFACE || - ctx->previous_context == EGL_NO_CONTEXT) { - ctx->previous_surface = EGL_NO_SURFACE; - ctx->previous_context = EGL_NO_CONTEXT; - } -} - -static void -_egl_acquire (void *abstract_ctx) -{ - cairo_egl_context_t *ctx = abstract_ctx; - EGLSurface current_surface = _egl_get_current_surface (ctx); - - _egl_query_current_state (ctx); - if (!_context_acquisition_changed_egl_state (ctx, current_surface)) - return; - - eglMakeCurrent (ctx->display, - current_surface, current_surface, ctx->context); -} - -static void -_egl_release (void *abstract_ctx) -{ - cairo_egl_context_t *ctx = abstract_ctx; - if (!ctx->base.thread_aware || - !_context_acquisition_changed_egl_state (ctx, - _egl_get_current_surface (ctx))) { - return; - } - - eglMakeCurrent (ctx->display, - EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); -} - -static void -_egl_make_current (void *abstract_ctx, - cairo_gl_surface_t *abstract_surface) -{ - cairo_egl_context_t *ctx = abstract_ctx; - cairo_egl_surface_t *surface = (cairo_egl_surface_t *) abstract_surface; - - eglMakeCurrent(ctx->display, surface->egl, surface->egl, ctx->context); -} - -static void -_egl_swap_buffers (void *abstract_ctx, - cairo_gl_surface_t *abstract_surface) -{ - cairo_egl_context_t *ctx = abstract_ctx; - cairo_egl_surface_t *surface = (cairo_egl_surface_t *) abstract_surface; - - eglSwapBuffers (ctx->display, surface->egl); -} - -static void -_egl_destroy (void *abstract_ctx) -{ - cairo_egl_context_t *ctx = abstract_ctx; - - eglMakeCurrent (ctx->display, - EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (ctx->dummy_surface != EGL_NO_SURFACE) - eglDestroySurface (ctx->display, ctx->dummy_surface); -} - -static cairo_bool_t -_egl_make_current_surfaceless(cairo_egl_context_t *ctx) -{ - const char *extensions; - - extensions = eglQueryString(ctx->display, EGL_EXTENSIONS); - if (strstr(extensions, "EGL_KHR_surfaceless_context") == NULL && - strstr(extensions, "EGL_KHR_surfaceless_opengl") == NULL) - return FALSE; - - if (!eglMakeCurrent(ctx->display, - EGL_NO_SURFACE, EGL_NO_SURFACE, ctx->context)) - return FALSE; - - return TRUE; -} - -cairo_device_t * -cairo_egl_device_create (EGLDisplay dpy, EGLContext egl) -{ - cairo_egl_context_t *ctx; - cairo_status_t status; - int attribs[] = { - EGL_WIDTH, 1, - EGL_HEIGHT, 1, - EGL_NONE, - }; - EGLConfig config; - EGLint numConfigs; - - ctx = calloc (1, sizeof (cairo_egl_context_t)); - if (unlikely (ctx == NULL)) - return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); - - ctx->display = dpy; - ctx->context = egl; - - ctx->base.acquire = _egl_acquire; - ctx->base.release = _egl_release; - ctx->base.make_current = _egl_make_current; - ctx->base.swap_buffers = _egl_swap_buffers; - ctx->base.destroy = _egl_destroy; - - /* We are about the change the current state of EGL, so we should - * query the pre-existing surface now instead of later. */ - _egl_query_current_state (ctx); - - if (!_egl_make_current_surfaceless (ctx)) { - /* Fall back to dummy surface, meh. */ - EGLint config_attribs[] = { - EGL_CONFIG_ID, 0, - EGL_NONE - }; - - /* - * In order to be able to make an egl context current when using a - * pbuffer surface, that surface must have been created with a config - * that is compatible with the context config. For Mesa, this means - * that the configs must be the same. - */ - eglQueryContext (dpy, egl, EGL_CONFIG_ID, &config_attribs[1]); - eglChooseConfig (dpy, config_attribs, &config, 1, &numConfigs); - - ctx->dummy_surface = eglCreatePbufferSurface (dpy, config, attribs); - if (ctx->dummy_surface == NULL) { - free (ctx); - return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) { - free (ctx); - return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - } - - status = _cairo_gl_dispatch_init (&ctx->base.dispatch, eglGetProcAddress); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - status = _cairo_gl_context_init (&ctx->base); - if (unlikely (status)) { - if (ctx->dummy_surface != EGL_NO_SURFACE) - eglDestroySurface (dpy, ctx->dummy_surface); - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - /* Tune the default VBO size to reduce overhead on embedded devices. - * This smaller size means that flushing needs to be done more often, - * but it is less demanding of scarce memory on embedded devices. - */ - ctx->base.vbo_size = 16*1024; - - eglMakeCurrent (dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - return &ctx->base.base; -} - -cairo_surface_t * -cairo_gl_surface_create_for_egl (cairo_device_t *device, - EGLSurface egl, - int width, - int height) -{ - cairo_egl_surface_t *surface; - - if (unlikely (device->status)) - return _cairo_surface_create_in_error (device->status); - - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - - if (width <= 0 || height <= 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - surface = calloc (1, sizeof (cairo_egl_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_gl_surface_init (device, &surface->base, - CAIRO_CONTENT_COLOR_ALPHA, width, height); - surface->egl = egl; - - return &surface->base.base; -} - -static cairo_bool_t is_egl_device (cairo_device_t *device) -{ - return (device->backend != NULL && - device->backend->type == CAIRO_DEVICE_TYPE_GL); -} - -static cairo_egl_context_t *to_egl_context (cairo_device_t *device) -{ - return (cairo_egl_context_t *) device; -} - -EGLDisplay -cairo_egl_device_get_display (cairo_device_t *device) -{ - if (! is_egl_device (device)) { - _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - return EGL_NO_DISPLAY; - } - - return to_egl_context (device)->display; -} - -cairo_public EGLContext -cairo_egl_device_get_context (cairo_device_t *device) -{ - if (! is_egl_device (device)) { - _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - return EGL_NO_CONTEXT; - } - - return to_egl_context (device)->context; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-inline.h deleted file mode 100644 index 9126c5e61eb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-inline.h +++ /dev/null @@ -1,52 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef _CAIRO_ERROR_INLINE_H_ -#define _CAIRO_ERROR_INLINE_H_ - -#include "cairo-error-private.h" - -CAIRO_BEGIN_DECLS - -static inline cairo_status_t -_cairo_public_status (cairo_int_status_t status) -{ - assert (status <= CAIRO_INT_STATUS_LAST_STATUS); - return (cairo_status_t) status; -} - -#endif /* _CAIRO_ERROR_INLINE_H_ */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-private.h deleted file mode 100644 index 178078ad614..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error-private.h +++ /dev/null @@ -1,127 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef _CAIRO_ERROR_PRIVATE_H_ -#define _CAIRO_ERROR_PRIVATE_H_ - -#include "cairo.h" -#include "cairo-compiler-private.h" -#include "cairo-types-private.h" - -#include - -CAIRO_BEGIN_DECLS - -/* _cairo_int_status: internal status - * - * Sure wish C had a real enum type so that this would be distinct - * from #cairo_status_t. Oh well, without that, I'll use this bogus 100 - * offset. We want to keep it fit in int8_t as the compiler may choose - * that for #cairo_status_t - */ -enum _cairo_int_status { - CAIRO_INT_STATUS_SUCCESS = 0, - - CAIRO_INT_STATUS_NO_MEMORY, - CAIRO_INT_STATUS_INVALID_RESTORE, - CAIRO_INT_STATUS_INVALID_POP_GROUP, - CAIRO_INT_STATUS_NO_CURRENT_POINT, - CAIRO_INT_STATUS_INVALID_MATRIX, - CAIRO_INT_STATUS_INVALID_STATUS, - CAIRO_INT_STATUS_NULL_POINTER, - CAIRO_INT_STATUS_INVALID_STRING, - CAIRO_INT_STATUS_INVALID_PATH_DATA, - CAIRO_INT_STATUS_READ_ERROR, - CAIRO_INT_STATUS_WRITE_ERROR, - CAIRO_INT_STATUS_SURFACE_FINISHED, - CAIRO_INT_STATUS_SURFACE_TYPE_MISMATCH, - CAIRO_INT_STATUS_PATTERN_TYPE_MISMATCH, - CAIRO_INT_STATUS_INVALID_CONTENT, - CAIRO_INT_STATUS_INVALID_FORMAT, - CAIRO_INT_STATUS_INVALID_VISUAL, - CAIRO_INT_STATUS_FILE_NOT_FOUND, - CAIRO_INT_STATUS_INVALID_DASH, - CAIRO_INT_STATUS_INVALID_DSC_COMMENT, - CAIRO_INT_STATUS_INVALID_INDEX, - CAIRO_INT_STATUS_CLIP_NOT_REPRESENTABLE, - CAIRO_INT_STATUS_TEMP_FILE_ERROR, - CAIRO_INT_STATUS_INVALID_STRIDE, - CAIRO_INT_STATUS_FONT_TYPE_MISMATCH, - CAIRO_INT_STATUS_USER_FONT_IMMUTABLE, - CAIRO_INT_STATUS_USER_FONT_ERROR, - CAIRO_INT_STATUS_NEGATIVE_COUNT, - CAIRO_INT_STATUS_INVALID_CLUSTERS, - CAIRO_INT_STATUS_INVALID_SLANT, - CAIRO_INT_STATUS_INVALID_WEIGHT, - CAIRO_INT_STATUS_INVALID_SIZE, - CAIRO_INT_STATUS_USER_FONT_NOT_IMPLEMENTED, - CAIRO_INT_STATUS_DEVICE_TYPE_MISMATCH, - CAIRO_INT_STATUS_DEVICE_ERROR, - CAIRO_INT_STATUS_INVALID_MESH_CONSTRUCTION, - CAIRO_INT_STATUS_DEVICE_FINISHED, - CAIRO_INT_STATUS_JBIG2_GLOBAL_MISSING, - - CAIRO_INT_STATUS_LAST_STATUS, - - CAIRO_INT_STATUS_UNSUPPORTED = 100, - CAIRO_INT_STATUS_DEGENERATE, - CAIRO_INT_STATUS_NOTHING_TO_DO, - CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY, - CAIRO_INT_STATUS_IMAGE_FALLBACK, - CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN, -}; - -typedef enum _cairo_int_status cairo_int_status_t; - -#define _cairo_status_is_error(status) \ - (status != CAIRO_STATUS_SUCCESS && status < CAIRO_STATUS_LAST_STATUS) - -#define _cairo_int_status_is_error(status) \ - (status != CAIRO_INT_STATUS_SUCCESS && status < CAIRO_INT_STATUS_LAST_STATUS) - -cairo_private cairo_status_t -_cairo_error (cairo_status_t status); - -/* hide compiler warnings when discarding the return value */ -#define _cairo_error_throw(status) do { \ - cairo_status_t status__ = _cairo_error (status); \ - (void) status__; \ -} while (0) - -CAIRO_END_DECLS - -#endif /* _CAIRO_ERROR_PRIVATE_H_ */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error.c deleted file mode 100644 index 1b9bd76be13..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-error.c +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" -#include "cairo-private.h" - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" - -#include - -/** - * _cairo_error: - * @status: a status value indicating an error, (eg. not - * %CAIRO_STATUS_SUCCESS) - * - * Checks that status is an error status, but does nothing else. - * - * All assignments of an error status to any user-visible object - * within the cairo application should result in a call to - * _cairo_error(). - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - * - * Return value: the error status. - **/ -cairo_status_t -_cairo_error (cairo_status_t status) -{ - CAIRO_ENSURE_UNIQUE; - assert (_cairo_status_is_error (status)); - - return status; -} - -COMPILE_TIME_ASSERT ((int)CAIRO_INT_STATUS_LAST_STATUS == (int)CAIRO_STATUS_LAST_STATUS); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fallback-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fallback-compositor.c deleted file mode 100644 index 3f6199fe2bb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fallback-compositor.c +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-compositor-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-offset-private.h" - -/* high-level compositor interface */ - -static cairo_int_status_t -_cairo_fallback_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_image_surface_t *image; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); - - status = _cairo_surface_offset_paint (&image->base, - extents->unbounded.x, - extents->unbounded.y, - extents->op, - &extents->source_pattern.base, - extents->clip); - - return _cairo_surface_unmap_image (extents->surface, image); -} - -static cairo_int_status_t -_cairo_fallback_compositor_mask (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_image_surface_t *image; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); - - status = _cairo_surface_offset_mask (&image->base, - extents->unbounded.x, - extents->unbounded.y, - extents->op, - &extents->source_pattern.base, - &extents->mask_pattern.base, - extents->clip); - - return _cairo_surface_unmap_image (extents->surface, image); -} - -static cairo_int_status_t -_cairo_fallback_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_image_surface_t *image; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); - - status = _cairo_surface_offset_stroke (&image->base, - extents->unbounded.x, - extents->unbounded.y, - extents->op, - &extents->source_pattern.base, - path, style, - ctm, ctm_inverse, - tolerance, - antialias, - extents->clip); - - return _cairo_surface_unmap_image (extents->surface, image); -} - -static cairo_int_status_t -_cairo_fallback_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_image_surface_t *image; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); - - status = _cairo_surface_offset_fill (&image->base, - extents->unbounded.x, - extents->unbounded.y, - extents->op, - &extents->source_pattern.base, - path, - fill_rule, tolerance, antialias, - extents->clip); - - return _cairo_surface_unmap_image (extents->surface, image); -} - -static cairo_int_status_t -_cairo_fallback_compositor_glyphs (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_image_surface_t *image; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); - - status = _cairo_surface_offset_glyphs (&image->base, - extents->unbounded.x, - extents->unbounded.y, - extents->op, - &extents->source_pattern.base, - scaled_font, glyphs, num_glyphs, - extents->clip); - - return _cairo_surface_unmap_image (extents->surface, image); -} - -const cairo_compositor_t _cairo_fallback_compositor = { - &__cairo_no_compositor, - - _cairo_fallback_compositor_paint, - _cairo_fallback_compositor_mask, - _cairo_fallback_compositor_stroke, - _cairo_fallback_compositor_fill, - _cairo_fallback_compositor_glyphs, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-features-uninstalled.pc.in b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-features-uninstalled.pc.in deleted file mode 100644 index b9cd9d3ad2b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-features-uninstalled.pc.in +++ /dev/null @@ -1,7 +0,0 @@ -Name: @FEATURE_PC@ -Description: @FEATURE_NAME@ for cairo graphics library -Version: @VERSION@ - -Requires: @FEATURE_BASE@ @FEATURE_REQUIRES@ -Libs: @FEATURE_NONPKGCONFIG_LIBS@ @FEATURE_NONPKGCONFIG_EXTRA_LIBS@ -Cflags: -I${pc_top_builddir}/${pcfiledir}/@srcdir@/src @FEATURE_NONPKGCONFIG_CFLAGS@ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-features.pc.in b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-features.pc.in deleted file mode 100644 index 9a4b657c8da..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-features.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: @FEATURE_PC@ -Description: @FEATURE_NAME@ for cairo graphics library -Version: @VERSION@ - -Requires: @FEATURE_BASE@ @FEATURE_REQUIRES@ -Libs: @FEATURE_NONPKGCONFIG_LIBS@ @FEATURE_NONPKGCONFIG_EXTRA_LIBS@ -Cflags: -I${includedir}/cairo @FEATURE_NONPKGCONFIG_CFLAGS@ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-private.h deleted file mode 100644 index 9ff8f750392..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-private.h +++ /dev/null @@ -1,395 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#ifndef CAIRO_FIXED_PRIVATE_H -#define CAIRO_FIXED_PRIVATE_H - -#include "cairo-fixed-type-private.h" - -#include "cairo-wideint-private.h" -#include "cairoint.h" - -/* Implementation */ - -#if (CAIRO_FIXED_BITS != 32) -# error CAIRO_FIXED_BITS must be 32, and the type must be a 32-bit type. -# error To remove this limitation, you will have to fix the tessellator. -#endif - -#define CAIRO_FIXED_ONE ((cairo_fixed_t)(1 << CAIRO_FIXED_FRAC_BITS)) -#define CAIRO_FIXED_ONE_DOUBLE ((double)(1 << CAIRO_FIXED_FRAC_BITS)) -#define CAIRO_FIXED_EPSILON ((cairo_fixed_t)(1)) - -#define CAIRO_FIXED_ERROR_DOUBLE (1. / (2 * CAIRO_FIXED_ONE_DOUBLE)) - -#define CAIRO_FIXED_FRAC_MASK ((cairo_fixed_t)(((cairo_fixed_unsigned_t)(-1)) >> (CAIRO_FIXED_BITS - CAIRO_FIXED_FRAC_BITS))) -#define CAIRO_FIXED_WHOLE_MASK (~CAIRO_FIXED_FRAC_MASK) - -static inline cairo_fixed_t -_cairo_fixed_from_int (int i) -{ - return i << CAIRO_FIXED_FRAC_BITS; -} - -/* This is the "magic number" approach to converting a double into fixed - * point as described here: - * - * http://www.stereopsis.com/sree/fpu2006.html (an overview) - * http://www.d6.com/users/checker/pdfs/gdmfp.pdf (in detail) - * - * The basic idea is to add a large enough number to the double that the - * literal floating point is moved up to the extent that it forces the - * double's value to be shifted down to the bottom of the mantissa (to make - * room for the large number being added in). Since the mantissa is, at a - * given moment in time, a fixed point integer itself, one can convert a - * float to various fixed point representations by moving around the point - * of a floating point number through arithmetic operations. This behavior - * is reliable on most modern platforms as it is mandated by the IEEE-754 - * standard for floating point arithmetic. - * - * For our purposes, a "magic number" must be carefully selected that is - * both large enough to produce the desired point-shifting effect, and also - * has no lower bits in its representation that would interfere with our - * value at the bottom of the mantissa. The magic number is calculated as - * follows: - * - * (2 ^ (MANTISSA_SIZE - FRACTIONAL_SIZE)) * 1.5 - * - * where in our case: - * - MANTISSA_SIZE for 64-bit doubles is 52 - * - FRACTIONAL_SIZE for 16.16 fixed point is 16 - * - * Although this approach provides a very large speedup of this function - * on a wide-array of systems, it does come with two caveats: - * - * 1) It uses banker's rounding as opposed to arithmetic rounding. - * 2) It doesn't function properly if the FPU is in single-precision - * mode. - */ - -/* The 16.16 number must always be available */ -#define CAIRO_MAGIC_NUMBER_FIXED_16_16 (103079215104.0) - -#if CAIRO_FIXED_BITS <= 32 -#define CAIRO_MAGIC_NUMBER_FIXED ((1LL << (52 - CAIRO_FIXED_FRAC_BITS)) * 1.5) - -/* For 32-bit fixed point numbers */ -static inline cairo_fixed_t -_cairo_fixed_from_double (double d) -{ - union { - double d; - int32_t i[2]; - } u; - - u.d = d + CAIRO_MAGIC_NUMBER_FIXED; -#ifdef FLOAT_WORDS_BIGENDIAN - return u.i[1]; -#else - return u.i[0]; -#endif -} - -#else -# error Please define a magic number for your fixed point type! -# error See cairo-fixed-private.h for details. -#endif - -static inline cairo_fixed_t -_cairo_fixed_from_26_6 (uint32_t i) -{ -#if CAIRO_FIXED_FRAC_BITS > 6 - return i << (CAIRO_FIXED_FRAC_BITS - 6); -#else - return i >> (6 - CAIRO_FIXED_FRAC_BITS); -#endif -} - -static inline cairo_fixed_t -_cairo_fixed_from_16_16 (uint32_t i) -{ -#if CAIRO_FIXED_FRAC_BITS > 16 - return i << (CAIRO_FIXED_FRAC_BITS - 16); -#else - return i >> (16 - CAIRO_FIXED_FRAC_BITS); -#endif -} - -static inline double -_cairo_fixed_to_double (cairo_fixed_t f) -{ - return ((double) f) / CAIRO_FIXED_ONE_DOUBLE; -} - -static inline int -_cairo_fixed_is_integer (cairo_fixed_t f) -{ - return (f & CAIRO_FIXED_FRAC_MASK) == 0; -} - -static inline cairo_fixed_t -_cairo_fixed_floor (cairo_fixed_t f) -{ - return f & ~CAIRO_FIXED_FRAC_MASK; -} - -static inline cairo_fixed_t -_cairo_fixed_ceil (cairo_fixed_t f) -{ - return _cairo_fixed_floor (f + CAIRO_FIXED_FRAC_MASK); -} - -static inline cairo_fixed_t -_cairo_fixed_round (cairo_fixed_t f) -{ - return _cairo_fixed_floor (f + (CAIRO_FIXED_FRAC_MASK+1)/2); -} - -static inline cairo_fixed_t -_cairo_fixed_round_down (cairo_fixed_t f) -{ - return _cairo_fixed_floor (f + CAIRO_FIXED_FRAC_MASK/2); -} - -static inline int -_cairo_fixed_integer_part (cairo_fixed_t f) -{ - return f >> CAIRO_FIXED_FRAC_BITS; -} - -static inline int -_cairo_fixed_integer_round (cairo_fixed_t f) -{ - return _cairo_fixed_integer_part (f + (CAIRO_FIXED_FRAC_MASK+1)/2); -} - -static inline int -_cairo_fixed_integer_round_down (cairo_fixed_t f) -{ - return _cairo_fixed_integer_part (f + CAIRO_FIXED_FRAC_MASK/2); -} - -static inline int -_cairo_fixed_fractional_part (cairo_fixed_t f) -{ - return f & CAIRO_FIXED_FRAC_MASK; -} - -static inline int -_cairo_fixed_integer_floor (cairo_fixed_t f) -{ - if (f >= 0) - return f >> CAIRO_FIXED_FRAC_BITS; - else - return -((-f - 1) >> CAIRO_FIXED_FRAC_BITS) - 1; -} - -static inline int -_cairo_fixed_integer_ceil (cairo_fixed_t f) -{ - if (f > 0) - return ((f - 1)>>CAIRO_FIXED_FRAC_BITS) + 1; - else - return - (-f >> CAIRO_FIXED_FRAC_BITS); -} - -/* A bunch of explicit 16.16 operators; we need these - * to interface with pixman and other backends that require - * 16.16 fixed point types. - */ -static inline cairo_fixed_16_16_t -_cairo_fixed_to_16_16 (cairo_fixed_t f) -{ -#if (CAIRO_FIXED_FRAC_BITS == 16) && (CAIRO_FIXED_BITS == 32) - return f; -#elif CAIRO_FIXED_FRAC_BITS > 16 - /* We're just dropping the low bits, so we won't ever got over/underflow here */ - return f >> (CAIRO_FIXED_FRAC_BITS - 16); -#else - cairo_fixed_16_16_t x; - - /* Handle overflow/underflow by clamping to the lowest/highest - * value representable as 16.16 - */ - if ((f >> CAIRO_FIXED_FRAC_BITS) < INT16_MIN) { - x = INT32_MIN; - } else if ((f >> CAIRO_FIXED_FRAC_BITS) > INT16_MAX) { - x = INT32_MAX; - } else { - x = f << (16 - CAIRO_FIXED_FRAC_BITS); - } - - return x; -#endif -} - -static inline cairo_fixed_16_16_t -_cairo_fixed_16_16_from_double (double d) -{ - union { - double d; - int32_t i[2]; - } u; - - u.d = d + CAIRO_MAGIC_NUMBER_FIXED_16_16; -#ifdef FLOAT_WORDS_BIGENDIAN - return u.i[1]; -#else - return u.i[0]; -#endif -} - -static inline int -_cairo_fixed_16_16_floor (cairo_fixed_16_16_t f) -{ - if (f >= 0) - return f >> 16; - else - return -((-f - 1) >> 16) - 1; -} - -static inline double -_cairo_fixed_16_16_to_double (cairo_fixed_16_16_t f) -{ - return ((double) f) / (double) (1 << 16); -} - -#if CAIRO_FIXED_BITS == 32 - -static inline cairo_fixed_t -_cairo_fixed_mul (cairo_fixed_t a, cairo_fixed_t b) -{ - cairo_int64_t temp = _cairo_int32x32_64_mul (a, b); - return _cairo_int64_to_int32(_cairo_int64_rsl (temp, CAIRO_FIXED_FRAC_BITS)); -} - -/* computes round (a * b / c) */ -static inline cairo_fixed_t -_cairo_fixed_mul_div (cairo_fixed_t a, cairo_fixed_t b, cairo_fixed_t c) -{ - cairo_int64_t ab = _cairo_int32x32_64_mul (a, b); - cairo_int64_t c64 = _cairo_int32_to_int64 (c); - return _cairo_int64_to_int32 (_cairo_int64_divrem (ab, c64).quo); -} - -/* computes floor (a * b / c) */ -static inline cairo_fixed_t -_cairo_fixed_mul_div_floor (cairo_fixed_t a, cairo_fixed_t b, cairo_fixed_t c) -{ - return _cairo_int64_32_div (_cairo_int32x32_64_mul (a, b), c); -} - -/* compute y from x so that (x,y), p1, and p2 are collinear */ -static inline cairo_fixed_t -_cairo_edge_compute_intersection_y_for_x (const cairo_point_t *p1, - const cairo_point_t *p2, - cairo_fixed_t x) -{ - cairo_fixed_t y, dx; - - if (x == p1->x) - return p1->y; - if (x == p2->x) - return p2->y; - - y = p1->y; - dx = p2->x - p1->x; - if (dx != 0) - y += _cairo_fixed_mul_div_floor (x - p1->x, p2->y - p1->y, dx); - - return y; -} - -/* compute x from y so that (x,y), p1, and p2 are collinear */ -static inline cairo_fixed_t -_cairo_edge_compute_intersection_x_for_y (const cairo_point_t *p1, - const cairo_point_t *p2, - cairo_fixed_t y) -{ - cairo_fixed_t x, dy; - - if (y == p1->y) - return p1->x; - if (y == p2->y) - return p2->x; - - x = p1->x; - dy = p2->y - p1->y; - if (dy != 0) - x += _cairo_fixed_mul_div_floor (y - p1->y, p2->x - p1->x, dy); - - return x; -} - -/* Intersect two segments based on the algorithm described at - * http://paulbourke.net/geometry/pointlineplane/. This implementation - * uses floating point math. */ -static inline cairo_bool_t -_slow_segment_intersection (const cairo_point_t *seg1_p1, - const cairo_point_t *seg1_p2, - const cairo_point_t *seg2_p1, - const cairo_point_t *seg2_p2, - cairo_point_t *intersection) -{ - double denominator, u_a, u_b; - double seg1_dx, seg1_dy, seg2_dx, seg2_dy, seg_start_dx, seg_start_dy; - - seg1_dx = _cairo_fixed_to_double (seg1_p2->x - seg1_p1->x); - seg1_dy = _cairo_fixed_to_double (seg1_p2->y - seg1_p1->y); - seg2_dx = _cairo_fixed_to_double (seg2_p2->x - seg2_p1->x); - seg2_dy = _cairo_fixed_to_double (seg2_p2->y - seg2_p1->y); - denominator = (seg2_dy * seg1_dx) - (seg2_dx * seg1_dy); - if (denominator == 0) - return FALSE; - - seg_start_dx = _cairo_fixed_to_double (seg1_p1->x - seg2_p1->x); - seg_start_dy = _cairo_fixed_to_double (seg1_p1->y - seg2_p1->y); - u_a = ((seg2_dx * seg_start_dy) - (seg2_dy * seg_start_dx)) / denominator; - u_b = ((seg1_dx * seg_start_dy) - (seg1_dy * seg_start_dx)) / denominator; - - if (u_a <= 0 || u_a >= 1 || u_b <= 0 || u_b >= 1) - return FALSE; - - intersection->x = seg1_p1->x + _cairo_fixed_from_double ((u_a * seg1_dx)); - intersection->y = seg1_p1->y + _cairo_fixed_from_double ((u_a * seg1_dy)); - return TRUE; -} - -#else -# error Please define multiplication and other operands for your fixed-point type size -#endif - -#endif /* CAIRO_FIXED_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-type-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-type-private.h deleted file mode 100644 index e9f26f61539..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed-type-private.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#ifndef CAIRO_FIXED_TYPE_PRIVATE_H -#define CAIRO_FIXED_TYPE_PRIVATE_H - -#include "cairo-wideint-type-private.h" - -/* - * Fixed-point configuration - */ - -typedef int32_t cairo_fixed_16_16_t; -typedef cairo_int64_t cairo_fixed_32_32_t; -typedef cairo_int64_t cairo_fixed_48_16_t; -typedef cairo_int128_t cairo_fixed_64_64_t; -typedef cairo_int128_t cairo_fixed_96_32_t; - -/* Eventually, we should allow changing this, but I think - * there are some assumptions in the tessellator about the - * size of a fixed type. For now, it must be 32. - */ -#define CAIRO_FIXED_BITS 32 - -/* The number of fractional bits. Changing this involves - * making sure that you compute a double-to-fixed magic number. - * (see below). - */ -#define CAIRO_FIXED_FRAC_BITS 8 - -/* A signed type %CAIRO_FIXED_BITS in size; the main fixed point type */ -typedef int32_t cairo_fixed_t; - -/* An unsigned type of the same size as #cairo_fixed_t */ -typedef uint32_t cairo_fixed_unsigned_t; - -typedef struct _cairo_point { - cairo_fixed_t x; - cairo_fixed_t y; -} cairo_point_t; - -#endif /* CAIRO_FIXED_TYPE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed.c deleted file mode 100644 index 03e05592354..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fixed.c +++ /dev/null @@ -1,39 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-fixed-private.h" diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin-data.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin-data.c deleted file mode 100644 index ff09cb2be10..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin-data.c +++ /dev/null @@ -1,1072 +0,0 @@ -/* See cairo-font-face-twin.c for copyright info */ - -#include "cairoint.h" - -const int8_t _cairo_twin_outlines[] = { -/* 0x0 '\0' offset 0 */ - 0, 24, 42, 0, 2, 2, - 0, 24, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 24, -42, - 'l', 24, 0, - 'l', 0, 0, - 'e', - 'X', 'X', -/* 0x20 ' ' offset 28 */ - 0, 4, 0, 0, 0, 0, - /* snap_x */ - /* snap_y */ - 'e', - 'X', 'X', 'X', - 'X', 'X', -/* 0x21 '!' offset 40 */ - 0, 0, 42, 0, 1, 3, - 0, /* snap_x */ - -42, -14, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, -14, - 'm', 0, 0, - 'l', 0, 0, - 'e', - 'X', 'X', 'X', 'X', 'X', 'X', - 'X', 'X', 'X', 'X', 'X', 'X', - 'X', 'X', 'X', 'X', 'X', 'X', - 'X', 'X', 'X', 'X', 'X', 'X', - 'X', 'X', 'X', -/* 0x22 '"' offset 90 */ - 0, 16, 42, -28, 2, 2, - 0, 16, /* snap_x */ - -42, -28, /* snap_y */ - 'm', 0, -42, - 'l', 0, -28, - 'm', 16, -42, - 'l', 16, -28, - 'e', - 'X', -/* 0x23 '#' offset 114 */ - 0, 30, 50, 14, 2, 5, - 0, 30, /* snap_x */ - -24, -21, -15, -12, 0, /* snap_y */ - 'm', 16, -50, - 'l', 2, 14, - 'm', 28, -50, - 'l', 14, 14, - 'm', 2, -24, - 'l', 30, -24, - 'm', 0, -12, - 'l', 28, -12, - 'e', -/* 0x24 '$' offset 152 */ - 0, 28, 50, 8, 4, 4, - 0, 10, 18, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 10, -50, - 'l', 10, 8, - 'm', 18, -50, - 'l', 18, 8, - 'm', 28, -36, - 'c', 24, -42, 18, -42, 14, -42, - 'c', 10, -42, 0, -42, 0, -34, - 'c', 0, -25, 8, -24, 14, -22, - 'c', 20, -20, 28, -19, 28, -9, - 'c', 28, 0, 18, 0, 14, 0, - 'c', 10, 0, 4, 0, 0, -6, - 'e', -/* 0x25 '%' offset 224 */ - 0, 36, 42, 0, 4, 7, - 0, 14, 22, 36, /* snap_x */ - -42, -38, -28, -21, -15, -14, 0, /* snap_y */ - 'm', 10, -42, - 'c', 12, -41, 14, -40, 14, -36, - 'c', 14, -30, 11, -28, 6, -28, - 'c', 2, -28, 0, -30, 0, -34, - 'c', 0, -39, 3, -42, 8, -42, - 'l', 10, -42, - 'c', 18, -37, 28, -37, 36, -42, - 'l', 0, 0, - 'm', 28, -14, - 'c', 24, -14, 22, -11, 22, -6, - 'c', 22, -2, 24, 0, 28, 0, - 'c', 33, 0, 36, -2, 36, -8, - 'c', 36, -12, 34, -14, 30, -14, - 'l', 28, -14, - 'e', - 'X', 'X', 'X', -/* 0x26 '&' offset 323 */ - 0, 40, 42, 0, 4, 4, - 0, 10, 22, 40, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 40, -24, - 'c', 40, -27, 39, -28, 37, -28, - 'c', 29, -28, 32, 0, 12, 0, - 'c', 0, 0, 0, -8, 0, -10, - 'c', 0, -24, 22, -20, 22, -34, - 'c', 22, -45, 10, -45, 10, -34, - 'c', 10, -27, 25, 0, 36, 0, - 'c', 39, 0, 40, -1, 40, -4, - 'e', -/* 0x27 ''' offset 390 */ - 0, 4, 42, -30, 2, 2, - 0, 4, /* snap_x */ - -42, -28, /* snap_y */ - 'm', 2, -38, - 'c', -1, -38, -1, -42, 2, -42, - 'c', 6, -42, 5, -33, 0, -30, - 'e', - 'X', -/* 0x28 '(' offset 419 */ - 0, 14, 50, 14, 2, 2, - 0, 14, /* snap_x */ - -50, 14, /* snap_y */ - 'm', 14, -50, - 'c', -5, -32, -5, -5, 14, 14, - 'e', - 'X', -/* 0x29 ')' offset 441 */ - 0, 14, 50, 14, 2, 2, - 0, 14, /* snap_x */ - -15, 14, /* snap_y */ - 'm', 0, -50, - 'c', 19, -34, 19, -2, 0, 14, - 'e', - 'X', -/* 0x2a '*' offset 463 */ - 0, 20, 30, -6, 3, 3, - 0, 10, 20, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 10, -30, - 'l', 10, -6, - 'm', 0, -24, - 'l', 20, -12, - 'm', 20, -24, - 'l', 0, -12, - 'e', -/* 0x2b '+' offset 494 */ - 0, 36, 36, 0, 3, 4, - 0, 18, 36, /* snap_x */ - -21, -18, -15, 0, /* snap_y */ - 'm', 18, -36, - 'l', 18, 0, - 'm', 0, -18, - 'l', 36, -18, - 'e', -/* 0x2c ',' offset 520 */ - 0, 4, 4, 8, 2, 3, - 0, 4, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 4, -2, - 'c', 4, 1, 0, 1, 0, -2, - 'c', 0, -5, 4, -5, 4, -2, - 'c', 4, 4, 2, 6, 0, 8, - 'e', -/* 0x2d '-' offset 556 */ - 0, 36, 18, -18, 2, 4, - 0, 36, /* snap_x */ - -21, -18, -15, 0, /* snap_y */ - 'm', 0, -18, - 'l', 36, -18, - 'e', -/* 0x2e '.' offset 575 */ - 0, 4, 4, 0, 2, 3, - 0, 4, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 2, -4, - 'c', -1, -4, -1, 0, 2, 0, - 'c', 5, 0, 5, -4, 2, -4, - 'e', -/* 0x2f '/' offset 604 */ - 0, 36, 50, 14, 2, 3, - 0, 36, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 36, -50, - 'l', 0, 14, - 'e', -/* 0x30 '0' offset 622 */ - 0, 28, 42, 0, 2, 4, - 0, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 14, -42, - 'c', 9, -42, 0, -42, 0, -21, - 'c', 0, 0, 9, 0, 14, 0, - 'c', 19, 0, 28, 0, 28, -21, - 'c', 28, -42, 19, -42, 14, -42, - 'E', -/* 0x31 '1' offset 666 */ - 0, 28, 42, 0, 2, 3, - 0, 17, 28 /* snap_x */ - -42, -34, 0, /* snap_y */ - 'm', 7, -34, - 'c', 11, -35, 15, -38, 17, -42, - 'l', 17, 0, - 'e', -/* 0x32 '2' offset 691 */ - 0, 28, 42, 0, 4, 4, - 0, 2, 26, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 2, -32, - 'c', 2, -34, 2, -42, 14, -42, - 'c', 26, -42, 26, -34, 26, -32, - 'c', 26, -30, 25, -25, 10, -10, - 'l', 0, 0, - 'l', 28, 0, - 'e', -/* 0x33 '3' offset 736 */ - 0, 28, 42, 0, 2, 5, - 0, 28, /* snap_x */ - -42, -26, -21, -15, 0, /* snap_y */ - 'm', 4, -42, - 'l', 26, -42, - 'l', 14, -26, - 'c', 21, -26, 28, -26, 28, -14, - 'c', 28, 0, 17, 0, 13, 0, - 'c', 8, 0, 3, -1, 0, -8, - 'e', -/* 0x34 '4' offset 780 */ - 0, 28, 42, 0, 3, 3, - 0, 20, 30, /* snap_x */ - -42, -14, 0, /* snap_y */ - 'm', 20, 0, - 'l', 20, -42, - 'l', 0, -14, - 'l', 30, -14, - 'e', - 'X', 'X', 'X', - 'X', -/* 0x35 '5' offset 809 */ - 0, 28, 42, 0, 2, 5, - 0, 28, /* snap_x */ - -42, -28, -21, -15, 0, /* snap_y */ - 'm', 24, -42, - 'l', 4, -42, - 'l', 2, -24, - 'c', 5, -27, 10, -28, 13, -28, - 'c', 16, -28, 28, -28, 28, -14, - 'c', 28, 0, 16, 0, 13, 0, - 'c', 10, 0, 3, 0, 0, -8, - 'e', -/* 0x36 '6' offset 860 */ - 0, 28, 42, 0, 2, 5, - 0, 26, /* snap_x */ - -42, -26, -21, -15, 0, /* snap_y */ - 'm', 24, -36, - 'c', 22, -41, 19, -42, 14, -42, - 'c', 9, -42, 0, -41, 0, -19, - 'c', 0, -1, 9, 0, 13, 0, - 'c', 18, 0, 26, -3, 26, -13, - 'c', 26, -18, 23, -26, 13, -26, - 'c', 10, -26, 1, -24, 0, -14, - 'e', -/* 0x37 '7' offset 919 */ - 0, 28, 42, 0, 2, 4, - 0, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 0, -42, - 'l', 28, -42, - 'l', 8, 0, - 'e', - 'X', 'X', 'X', -/* 0x38 '8' offset 944 */ - 0, 28, 42, 0, 4, 4, - 0, 2, 26, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 14, -42, - 'c', 5, -42, 2, -40, 2, -34, - 'c', 2, -18, 28, -32, 28, -11, - 'c', 28, 0, 18, 0, 14, 0, - 'c', 10, 0, 0, 0, 0, -11, - 'c', 0, -32, 26, -18, 26, -34, - 'c', 26, -40, 23, -42, 14, -42, - 'E', -/* 0x39 '9' offset 1004 */ - 0, 28, 42, 0, 2, 5, - 0, 26, /* snap_x */ - -42, -21, -16, -15, 0, /* snap_y */ - 'm', 26, -28, - 'c', 25, -16, 13, -16, 13, -16, - 'c', 8, -16, 0, -19, 0, -29, - 'c', 0, -34, 3, -42, 13, -42, - 'c', 24, -42, 26, -32, 26, -23, - 'c', 26, -14, 24, 0, 12, 0, - 'c', 7, 0, 4, -2, 2, -6, - 'e', -/* 0x3a ':' offset 1063 */ - 0, 4, 28, 0, 2, 3, - 0, 4, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 2, -28, - 'c', -1, -28, -1, -24, 2, -24, - 'c', 5, -24, 5, -28, 2, -28, - 'm', 2, -4, - 'c', -1, -4, -1, 0, 2, 0, - 'c', 5, 0, 5, -4, 2, -4, - 'e', -/* 0x3b ';' offset 1109 */ - 0, 4, 28, 8, 2, 3, - 0, 4, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 2, -28, - 'c', -1, -28, -1, -24, 2, -24, - 'c', 5, -24, 5, -28, 2, -28, - 'm', 4, -2, - 'c', 4, 1, 0, 1, 0, -2, - 'c', 0, -5, 4, -5, 4, -2, - 'c', 4, 3, 2, 6, 0, 8, - 'e', -/* 0x3c '<' offset 1162 */ - 0, 32, 36, 0, 2, 3, - 0, 32, /* snap_x */ - -36, -18, 0, /* snap_y */ - 'm', 32, -36, - 'l', 0, -18, - 'l', 32, 0, - 'e', -/* 0x3d '=' offset 1183 */ - 0, 36, 24, -12, 2, 2, - 0, 36, /* snap_x */ - -24, -15, /* snap_y */ - 'm', 0, -24, - 'l', 36, -24, - 'm', 0, -12, - 'l', 36, -12, - 'e', - 'X', 'X', 'X', -/* 0x3e '>' offset 1209 */ - 0, 32, 36, 0, 2, 3, - 0, 32, /* snap_x */ - -36, -18, 0, /* snap_y */ - 'm', 0, -36, - 'l', 32, -18, - 'l', 0, 0, - 'e', -/* 0x3f '?' offset 1230 */ - 0, 24, 42, 0, 3, 4, - 0, 12, 24, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 0, -32, - 'c', 0, -34, 0, -42, 12, -42, - 'c', 24, -42, 24, -34, 24, -32, - 'c', 24, -29, 24, -24, 12, -20, - 'l', 12, -14, - 'm', 12, 0, - 'l', 12, 0, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', -/* 0x40 '@' offset 1288 */ - 0, 42, 42, 0, 1, 6, - 30, /* snap_x */ - -42, -32, -21, -15, -10, 0, /* snap_y */ - 'm', 30, -26, - 'c', 28, -31, 24, -32, 21, -32, - 'c', 10, -32, 10, -23, 10, -19, - 'c', 10, -13, 11, -10, 19, -10, - 'c', 30, -10, 28, -21, 30, -32, - 'c', 27, -10, 30, -10, 34, -10, - 'c', 41, -10, 42, -19, 42, -22, - 'c', 42, -34, 34, -42, 21, -42, - 'c', 9, -42, 0, -34, 0, -21, - 'c', 0, -9, 8, 0, 21, 0, - 'c', 30, 0, 34, -3, 36, -6, - 'e', -/* 0x41 'A' offset 1375 */ - 0, 32, 42, 0, 2, 3, - 0, 32, /* snap_x */ - -42, -14, 0, /* snap_y */ - 'm', 0, 0, - 'l', 16, -42, - 'l', 32, 0, - 'm', 6, -14, - 'l', 26, -14, - 'e', - 'X', 'X', 'X', - 'X', -/* 0x42 'B' offset 1406 */ - 0, 28, 42, 0, 2, 3, - 0, 28, /* snap_x */ - -42, -22, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 18, -42, - 'c', 32, -42, 32, -22, 18, -22, - 'l', 0, -22, - 'l', 18, -22, - 'c', 32, -22, 32, 0, 18, 0, - 'E', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', -/* 0x43 'C' offset 1455 */ - 0, 30, 42, 0, 2, 4, - 0, 30, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 30, -32, - 'c', 26, -42, 21, -42, 16, -42, - 'c', 2, -42, 0, -29, 0, -21, - 'c', 0, -13, 2, 0, 16, 0, - 'c', 21, 0, 26, 0, 30, -10, - 'e', -/* 0x44 'D' offset 1499 */ - 0, 28, 42, 0, 2, 2, - 0, 28, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 14, -42, - 'c', 33, -42, 33, 0, 14, 0, - 'E', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', -/* 0x45 'E' offset 1534 */ - 0, 26, 42, 0, 2, 3, - 0, 26, /* snap_x */ - -42, -22, 0, /* snap_y */ - 'm', 26, -42, - 'l', 0, -42, - 'l', 0, 0, - 'l', 26, 0, - 'm', 0, -22, - 'l', 16, -22, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', -/* 0x46 'F' offset 1572 */ - 0, 26, 42, 0, 2, 3, - 0, 26, /* snap_x */ - -42, -22, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 26, -42, - 'm', 0, -22, - 'l', 16, -22, - 'e', - 'X', 'X', 'X', - 'X', 'X', -/* 0x47 'G' offset 1604 */ - 0, 30, 42, 0, 2, 5, - 0, 30, /* snap_x */ - -42, -21, -16, -15, 0, /* snap_y */ - 'm', 30, -32, - 'c', 26, -42, 21, -42, 16, -42, - 'c', 2, -42, 0, -29, 0, -21, - 'c', 0, -13, 2, 0, 16, 0, - 'c', 28, 0, 30, -7, 30, -16, - 'l', 20, -16, - 'e', - 'X', 'X', 'X', -/* 0x48 'H' offset 1655 */ - 0, 28, 42, 0, 2, 3, - 0, 28, /* snap_x */ - -42, -22, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'm', 28, -42, - 'l', 28, 0, - 'm', 0, -22, - 'l', 28, -22, - 'e', - 'X', -/* 0x49 'I' offset 1686 */ - 0, 0, 42, 0, 1, 2, - 0, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'e', - 'X', -/* 0x4a 'J' offset 1703 */ - 0, 20, 42, 0, 2, 3, - 0, 20, /* snap_x */ - -42, -15, 0, /* snap_y */ - 'm', 20, -42, - 'l', 20, -10, - 'c', 20, 3, 0, 3, 0, -10, - 'l', 0, -14, - 'e', -/* 0x4b 'K' offset 1731 */ - 0, 28, 42, 0, 2, 3, - 0, 28, /* snap_x */ - -42, -15, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'm', 28, -42, - 'l', 0, -14, - 'm', 10, -24, - 'l', 28, 0, - 'e', -/* 0x4c 'L' offset 1761 */ - 0, 24, 42, 0, 2, 2, - 0, 24, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'l', 24, 0, - 'e', - 'X', 'X', 'X', - 'X', -/* 0x4d 'M' offset 1785 */ - 0, 32, 42, 0, 2, 2, - 0, 32, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 16, 0, - 'l', 32, -42, - 'l', 32, 0, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', -/* 0x4e 'N' offset 1821 */ - 0, 28, 42, 0, 2, 2, - 0, 28, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 28, 0, - 'l', 28, -42, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', -/* 0x4f 'O' offset 1851 */ - 0, 32, 42, 0, 2, 4, - 0, 32, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 16, -42, - 'c', 2, -42, 0, -29, 0, -21, - 'c', 0, -13, 2, 0, 16, 0, - 'c', 30, 0, 32, -13, 32, -21, - 'c', 32, -29, 30, -42, 16, -42, - 'E', -/* 0x50 'P' offset 1895 */ - 0, 28, 42, 0, 2, 5, - 0, 28, /* snap_x */ - -42, -21, -20, -15, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 18, -42, - 'c', 32, -42, 32, -20, 18, -20, - 'l', 0, -20, - 'e', - 'X', 'X', 'X', -/* 0x51 'Q' offset 1931 */ - 0, 32, 42, 4, 2, 4, - 0, 32, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 16, -42, - 'c', 2, -42, 0, -29, 0, -21, - 'c', 0, -13, 2, 0, 16, 0, - 'c', 30, 0, 32, -13, 32, -21, - 'c', 32, -29, 30, -42, 16, -42, - 'M', 18, -8, - 'l', 30, 4, - 'e', -/* 0x52 'R' offset 1981 */ - 0, 28, 42, 0, 2, 5, - 0, 28, /* snap_x */ - -42, -22, -21, -15, 0, /* snap_y */ - 'm', 0, 0, - 'l', 0, -42, - 'l', 18, -42, - 'c', 32, -42, 31, -22, 18, -22, - 'l', 0, -22, - 'm', 14, -22, - 'l', 28, 0, - 'e', - 'X', 'X', 'X', -/* 0x53 'S' offset 2023 */ - 0, 28, 42, 0, 2, 4, - 0, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 28, -36, - 'c', 25, -41, 21, -42, 14, -42, - 'c', 10, -42, 0, -42, 0, -34, - 'c', 0, -17, 28, -28, 28, -9, - 'c', 28, 0, 19, 0, 14, 0, - 'c', 7, 0, 3, -1, 0, -6, - 'e', -/* 0x54 'T' offset 2074 */ - 0, 28, 42, 0, 3, 4, - 0, 14, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 14, -42, - 'l', 14, 0, - 'm', 0, -42, - 'l', 28, -42, - 'e', -/* 0x55 'U' offset 2100 */ - 0, 28, 42, 0, 2, 2, - 0, 28, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, -12, - 'c', 0, 4, 28, 4, 28, -12, - 'l', 28, -42, - 'e', - 'X', -/* 0x56 'V' offset 2128 */ - 0, 32, 42, 0, 2, 2, - 0, 32, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 16, 0, - 'l', 32, -42, - 'e', - 'X', 'X', 'X', - 'X', -/* 0x57 'W' offset 2152 */ - 0, 40, 42, 0, 2, 2, - 0, 40, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 10, 0, - 'l', 20, -42, - 'l', 30, 0, - 'l', 40, -42, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', -/* 0x58 'X' offset 2188 */ - 0, 28, 42, 0, 2, 2, - 0, 28, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 28, 0, - 'm', 28, -42, - 'l', 0, 0, - 'e', - 'X', -/* 0x59 'Y' offset 2212 */ - 0, 32, 42, 0, 3, 3, - 0, 16, 32, /* snap_x */ - -42, -21, 0, /* snap_y */ - 'm', 0, -42, - 'l', 16, -22, - 'l', 16, 0, - 'm', 32, -42, - 'l', 16, -22, - 'e', -/* 0x5a 'Z' offset 2240 */ - 0, 28, 42, 0, 2, 4, - 0, 28, /* snap_x */ - -42, -21, -15, 0, /* snap_y */ - 'm', 28, 0, - 'l', 0, 0, - 'l', 28, -42, - 'l', 0, -42, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', -/* 0x5b '[' offset 2271 */ - 0, 14, 44, 0, 2, 4, - 0, 14, /* snap_x */ - -44, -21, -15, 0, /* snap_y */ - 'm', 14, -44, - 'l', 0, -44, - 'l', 0, 0, - 'l', 14, 0, - 'e', -/* 0x5c '\' offset 2296 */ - 0, 36, 50, 14, 2, 3, - 0, 36, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 0, -50, - 'l', 36, 14, - 'e', -/* 0x5d ']' offset 2314 */ - 0, 14, 44, 0, 2, 4, - 0, 14, /* snap_x */ - -44, -21, -15, 0, /* snap_y */ - 'm', 0, -44, - 'l', 14, -44, - 'l', 14, 0, - 'l', 0, 0, - 'e', -/* 0x5e '^' offset 2339 */ - 0, 32, 46, -18, 2, 3, - 0, 32, /* snap_x */ - -21, -15, 0, /* snap_y */ - 'm', 0, -18, - 'l', 16, -46, - 'l', 32, -18, - 'e', - 'X', 'X', 'X', -/* 0x5f '_' offset 2363 */ - 0, 36, 0, 0, 2, 1, - 0, 36, /* snap_x */ - 0, /* snap_y */ - 'm', 0, 0, - 'l', 36, 0, - 'e', - 'X', 'X', -/* 0x60 '`' offset 2381 */ - 0, 4, 42, -30, 2, 2, - 0, 4, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 4, -42, - 'c', 2, -40, 0, -39, 0, -32, - 'c', 0, -31, 1, -30, 2, -30, - 'c', 5, -30, 5, -34, 2, -34, - 'e', - 'X', -/* 0x61 'a' offset 2417 */ - 0, 24, 28, 0, 2, 4, - 0, 24, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 24, -28, - 'l', 24, 0, - 'm', 24, -22, - 'c', 21, -27, 18, -28, 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 18, 0, 21, -1, 24, -6, - 'e', -/* 0x62 'b' offset 2467 */ - 0, 24, 42, 0, 2, 4, - 0, 24, /* snap_x */ - -42, -28, -15, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'm', 0, -22, - 'c', 3, -26, 6, -28, 11, -28, - 'c', 22, -28, 24, -19, 24, -14, - 'c', 24, -9, 22, 0, 11, 0, - 'c', 6, 0, 3, -2, 0, -6, - 'e', -/* 0x63 'c' offset 2517 */ - 0, 24, 28, 0, 2, 4, - 0, 24, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 24, -22, - 'c', 21, -26, 18, -28, 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 18, 0, 21, -2, 24, -6, - 'e', -/* 0x64 'd' offset 2561 */ - 0, 24, 42, 0, 2, 4, - 0, 24, /* snap_x */ - -42, -28, -15, 0, /* snap_y */ - 'm', 24, -42, - 'l', 24, 0, - 'm', 24, -22, - 'c', 21, -26, 18, -28, 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 18, 0, 21, -2, 24, -6, - 'e', -/* 0x65 'e' offset 2611 */ - 0, 24, 28, 0, 2, 5, - 0, 24, /* snap_x */ - -28, -21, -16, -15, 0, /* snap_y */ - 'm', 0, -16, - 'l', 24, -16, - 'c', 24, -20, 24, -28, 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 18, 0, 21, -2, 24, -6, - 'e', -/* 0x66 'f' offset 2659 */ - 0, 16, 42, 0, 3, 5, - 0, 6, 16, /* snap_x */ - -42, -28, -21, -15, 0, /* snap_y */ - 'm', 16, -42, - 'c', 8, -42, 6, -40, 6, -34, - 'l', 6, 0, - 'm', 0, -28, - 'l', 14, -28, - 'e', -/* 0x67 'g' offset 2693 */ - 0, 24, 28, 14, 2, 5, - 0, 24, /* snap_x */ - -28, -21, -15, 0, 14, /* snap_y */ - 'm', 24, -28, - 'l', 24, 4, - 'c', 23, 14, 16, 14, 13, 14, - 'c', 10, 14, 8, 14, 6, 12, - 'm', 24, -22, - 'c', 21, -26, 18, -28, 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 18, 0, 21, -2, 24, -6, - 'e', -/* 0x68 'h' offset 2758 */ - 0, 22, 42, 0, 2, 4, - 0, 22, /* snap_x */ - -42, -28, -15, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'm', 0, -20, - 'c', 8, -32, 22, -31, 22, -20, - 'l', 22, 0, - 'e', -/* 0x69 'i' offset 2790 */ - 0, 0, 44, 0, 1, 3, - 0, /* snap_x */ - -42, -28, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, -42, - 'm', 0, -28, - 'l', 0, 0, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', - 'X', 'X', -/* 0x6a 'j' offset 2826 */ - -8, 4, 44, 14, 3, 5, - -8, 2, 4, /* snap_x */ - -42, -21, -15, 0, 14, /* snap_y */ - 'm', 2, -42, - 'l', 2, -42, - 'm', 2, -28, - 'l', 2, 6, - 'c', 2, 13, -1, 14, -8, 14, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', -/* 0x6b 'k' offset 2870 */ - 0, 22, 42, 0, 2, 3, - 0, 22, /* snap_x */ - -42, -28, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'm', 20, -28, - 'l', 0, -8, - 'm', 8, -16, - 'l', 22, 0, - 'e', -/* 0x6c 'l' offset 2900 */ - 0, 0, 42, 0, 1, 2, - 0, /* snap_x */ - -42, 0, /* snap_y */ - 'm', 0, -42, - 'l', 0, 0, - 'e', - 'X', -/* 0x6d 'm' offset 2917 */ - 0, 44, 28, 0, 3, 3, - 0, 22, 44, /* snap_x */ - -28, -21, 0, /* snap_y */ - 'm', 0, -28, - 'l', 0, 0, - 'm', 0, -20, - 'c', 5, -29, 22, -33, 22, -20, - 'l', 22, 0, - 'm', 22, -20, - 'c', 27, -29, 44, -33, 44, -20, - 'l', 44, 0, - 'e', - 'X', -/* 0x6e 'n' offset 2963 */ - 0, 22, 28, 0, 2, 3, - 0, 22, /* snap_x */ - -28, -21, 0, /* snap_y */ - 'm', 0, -28, - 'l', 0, 0, - 'm', 0, -20, - 'c', 4, -28, 22, -34, 22, -20, - 'l', 22, 0, - 'e', - 'X', -/* 0x6f 'o' offset 2995 */ - 0, 26, 28, 0, 2, 4, - 0, 26, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 24, 0, 26, -9, 26, -14, - 'c', 26, -19, 24, -28, 13, -28, - 'E', -/* 0x70 'p' offset 3039 */ - 0, 24, 28, 14, 2, 4, - 0, 24, /* snap_x */ - -28, -21, 0, 14, /* snap_y */ - 'm', 0, -28, - 'l', 0, 14, - 'm', 0, -22, - 'c', 3, -26, 6, -28, 11, -28, - 'c', 22, -28, 24, -19, 24, -14, - 'c', 24, -9, 22, 0, 11, 0, - 'c', 6, 0, 3, -2, 0, -6, - 'e', -/* 0x71 'q' offset 3089 */ - 0, 24, 28, 14, 2, 4, - 0, 24, /* snap_x */ - -28, -21, 0, 14, /* snap_y */ - 'm', 24, -28, - 'l', 24, 14, - 'm', 24, -22, - 'c', 21, -26, 18, -28, 13, -28, - 'c', 2, -28, 0, -19, 0, -14, - 'c', 0, -9, 2, 0, 13, 0, - 'c', 18, 0, 21, -2, 24, -6, - 'e', -/* 0x72 'r' offset 3139 */ - 0, 16, 28, 0, 2, 4, - 0, 16, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 0, -28, - 'l', 0, 0, - 'm', 0, -16, - 'c', 2, -27, 7, -28, 16, -28, - 'e', -/* 0x73 's' offset 3168 */ - 0, 22, 28, 0, 2, 4, - 0, 22, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 22, -22, - 'c', 22, -27, 16, -28, 11, -28, - 'c', 4, -28, 0, -26, 0, -22, - 'c', 0, -11, 22, -20, 22, -7, - 'c', 22, 0, 17, 0, 11, 0, - 'c', 6, 0, 0, -1, 0, -6, - 'e', -/* 0x74 't' offset 3219 */ - 0, 16, 42, 0, 3, 4, - 0, 6, 16, /* snap_x */ - -42, -28, -21, 0, /* snap_y */ - 'm', 6, -42, - 'l', 6, -8, - 'c', 6, -2, 8, 0, 16, 0, - 'm', 0, -28, - 'l', 14, -28, - 'e', -/* 0x75 'u' offset 3252 */ - 0, 22, 28, 0, 2, 3, - 0, 22, /* snap_x */ - -28, -15, 0, /* snap_y */ - 'm', 0, -28, - 'l', 0, -8, - 'c', 0, 6, 18, 0, 22, -8, - 'm', 22, -28, - 'l', 22, 0, - 'e', -/* 0x76 'v' offset 3283 */ - 0, 24, 28, 0, 2, 3, - 0, 24, /* snap_x */ - -28, -15, 0, /* snap_y */ - 'm', 0, -28, - 'l', 12, 0, - 'l', 24, -28, - 'e', - 'X', 'X', 'X', -/* 0x77 'w' offset 3307 */ - 0, 32, 28, 0, 2, 3, - 0, 32, /* snap_x */ - -28, -15, 0, /* snap_y */ - 'm', 0, -28, - 'l', 8, 0, - 'l', 16, -28, - 'l', 24, 0, - 'l', 32, -28, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', - 'X', 'X', 'X', -/* 0x78 'x' offset 3343 */ - 0, 22, 28, 0, 2, 2, - 0, 22, /* snap_x */ - -28, 0, /* snap_y */ - 'm', 0, -28, - 'l', 22, 0, - 'm', 22, -28, - 'l', 0, 0, - 'e', - 'X', -/* 0x79 'y' offset 3367 */ - -2, 24, 28, 14, 2, 4, - 0, 24, /* snap_x */ - -28, -15, 0, 14, /* snap_y */ - 'm', 0, -28, - 'l', 12, 0, - 'm', 24, -28, - 'l', 12, 0, - 'c', 6, 13, 0, 14, -2, 14, - 'e', -/* 0x7a 'z' offset 3399 */ - 0, 22, 28, 0, 2, 4, - 0, 22, /* snap_x */ - -28, -21, -15, 0, /* snap_y */ - 'm', 22, 0, - 'l', 0, 0, - 'l', 22, -28, - 'l', 0, -28, - 'e', - 'X', 'X', 'X', - 'X', 'X', 'X', -/* 0x7b '{' offset 3430 */ - 0, 16, 44, 0, 3, 5, - 0, 6, 16, /* snap_x */ - -44, -24, -21, -15, 0, /* snap_y */ - 'm', 16, -44, - 'c', 10, -44, 6, -42, 6, -36, - 'l', 6, -24, - 'l', 0, -24, - 'l', 6, -24, - 'l', 6, -8, - 'c', 6, -2, 10, 0, 16, 0, - 'e', -/* 0x7c '|' offset 3474 */ - 0, 0, 50, 14, 1, 2, - 0, /* snap_x */ - -50, 14, /* snap_y */ - 'm', 0, -50, - 'l', 0, 14, - 'e', - 'X', -/* 0x7d '}' offset 3491 */ - 0, 16, 44, 0, 3, 5, - 0, 10, 16, /* snap_x */ - -44, -24, -21, -15, 0, /* snap_y */ - 'm', 0, -44, - 'c', 6, -44, 10, -42, 10, -36, - 'l', 10, -24, - 'l', 16, -24, - 'l', 10, -24, - 'l', 10, -8, - 'c', 10, -2, 6, 0, 0, 0, - 'e', -/* 0x7e '~' offset 3535 */ - 0, 36, 24, -12, 2, 5, - 0, 36, /* snap_x */ - -24, -21, -15, -12, 0, /* snap_y */ - 'm', 0, -14, - 'c', 1, -21, 4, -24, 8, -24, - 'c', 18, -24, 18, -12, 28, -12, - 'c', 32, -12, 35, -15, 36, -22, - 'e', -}; - -const uint16_t _cairo_twin_charmap[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 28, 40, 90, 114, 152, 224, 323, 390, - 419, 441, 463, 494, 520, 556, 575, 604, - 622, 666, 691, 736, 780, 809, 860, 919, - 944, 1004, 1063, 1109, 1162, 1183, 1209, 1230, - 1288, 1375, 1406, 1455, 1499, 1534, 1572, 1604, - 1655, 1686, 1703, 1731, 1761, 1785, 1821, 1851, - 1895, 1931, 1981, 2023, 2074, 2100, 2128, 2152, - 2188, 2212, 2240, 2271, 2296, 2314, 2339, 2363, - 2381, 2417, 2467, 2517, 2561, 2611, 2659, 2693, - 2758, 2790, 2826, 2870, 2900, 2917, 2963, 2995, - 3039, 3089, 3139, 3168, 3219, 3252, 3283, 3307, - 3343, 3367, 3399, 3430, 3474, 3491, 3535, 0, -}; - diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin.c deleted file mode 100644 index 2ad26302849..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face-twin.c +++ /dev/null @@ -1,752 +0,0 @@ -/* - * Copyright © 2004 Keith Packard - * Copyright © 2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith Packard - * Behdad Esfahbod - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -#include - -/* - * This file implements a user-font rendering the descendant of the Hershey - * font coded by Keith Packard for use in the Twin window system. - * The actual font data is in cairo-font-face-twin-data.c - * - * Ported to cairo user font and extended by Behdad Esfahbod. - */ - - - -static cairo_user_data_key_t twin_properties_key; - - -/* - * Face properties - */ - -/* We synthesize multiple faces from the twin data. Here is the parameters. */ - -/* The following tables and matching code are copied from Pango */ - -/* CSS weight */ -typedef enum { - TWIN_WEIGHT_THIN = 100, - TWIN_WEIGHT_ULTRALIGHT = 200, - TWIN_WEIGHT_LIGHT = 300, - TWIN_WEIGHT_BOOK = 380, - TWIN_WEIGHT_NORMAL = 400, - TWIN_WEIGHT_MEDIUM = 500, - TWIN_WEIGHT_SEMIBOLD = 600, - TWIN_WEIGHT_BOLD = 700, - TWIN_WEIGHT_ULTRABOLD = 800, - TWIN_WEIGHT_HEAVY = 900, - TWIN_WEIGHT_ULTRAHEAVY = 1000 -} twin_face_weight_t; - -/* CSS stretch */ -typedef enum { - TWIN_STRETCH_ULTRA_CONDENSED, - TWIN_STRETCH_EXTRA_CONDENSED, - TWIN_STRETCH_CONDENSED, - TWIN_STRETCH_SEMI_CONDENSED, - TWIN_STRETCH_NORMAL, - TWIN_STRETCH_SEMI_EXPANDED, - TWIN_STRETCH_EXPANDED, - TWIN_STRETCH_EXTRA_EXPANDED, - TWIN_STRETCH_ULTRA_EXPANDED -} twin_face_stretch_t; - -typedef struct -{ - int value; - const char str[16]; -} FieldMap; - -static const FieldMap slant_map[] = { - { CAIRO_FONT_SLANT_NORMAL, "" }, - { CAIRO_FONT_SLANT_NORMAL, "Roman" }, - { CAIRO_FONT_SLANT_OBLIQUE, "Oblique" }, - { CAIRO_FONT_SLANT_ITALIC, "Italic" } -}; - -static const FieldMap smallcaps_map[] = { - { FALSE, "" }, - { TRUE, "Small-Caps" } -}; - -static const FieldMap weight_map[] = { - { TWIN_WEIGHT_THIN, "Thin" }, - { TWIN_WEIGHT_ULTRALIGHT, "Ultra-Light" }, - { TWIN_WEIGHT_ULTRALIGHT, "Extra-Light" }, - { TWIN_WEIGHT_LIGHT, "Light" }, - { TWIN_WEIGHT_BOOK, "Book" }, - { TWIN_WEIGHT_NORMAL, "" }, - { TWIN_WEIGHT_NORMAL, "Regular" }, - { TWIN_WEIGHT_MEDIUM, "Medium" }, - { TWIN_WEIGHT_SEMIBOLD, "Semi-Bold" }, - { TWIN_WEIGHT_SEMIBOLD, "Demi-Bold" }, - { TWIN_WEIGHT_BOLD, "Bold" }, - { TWIN_WEIGHT_ULTRABOLD, "Ultra-Bold" }, - { TWIN_WEIGHT_ULTRABOLD, "Extra-Bold" }, - { TWIN_WEIGHT_HEAVY, "Heavy" }, - { TWIN_WEIGHT_HEAVY, "Black" }, - { TWIN_WEIGHT_ULTRAHEAVY, "Ultra-Heavy" }, - { TWIN_WEIGHT_ULTRAHEAVY, "Extra-Heavy" }, - { TWIN_WEIGHT_ULTRAHEAVY, "Ultra-Black" }, - { TWIN_WEIGHT_ULTRAHEAVY, "Extra-Black" } -}; - -static const FieldMap stretch_map[] = { - { TWIN_STRETCH_ULTRA_CONDENSED, "Ultra-Condensed" }, - { TWIN_STRETCH_EXTRA_CONDENSED, "Extra-Condensed" }, - { TWIN_STRETCH_CONDENSED, "Condensed" }, - { TWIN_STRETCH_SEMI_CONDENSED, "Semi-Condensed" }, - { TWIN_STRETCH_NORMAL, "" }, - { TWIN_STRETCH_SEMI_EXPANDED, "Semi-Expanded" }, - { TWIN_STRETCH_EXPANDED, "Expanded" }, - { TWIN_STRETCH_EXTRA_EXPANDED, "Extra-Expanded" }, - { TWIN_STRETCH_ULTRA_EXPANDED, "Ultra-Expanded" } -}; - -static const FieldMap monospace_map[] = { - { FALSE, "" }, - { TRUE, "Mono" }, - { TRUE, "Monospace" } -}; - - -typedef struct _twin_face_properties { - cairo_font_slant_t slant; - twin_face_weight_t weight; - twin_face_stretch_t stretch; - - /* lets have some fun */ - cairo_bool_t monospace; - cairo_bool_t smallcaps; -} twin_face_properties_t; - -static cairo_bool_t -field_matches (const char *s1, - const char *s2, - int len) -{ - int c1, c2; - - while (len && *s1 && *s2) - { -#define TOLOWER(c) \ - (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c)) - - c1 = TOLOWER (*s1); - c2 = TOLOWER (*s2); - if (c1 != c2) { - if (c1 == '-') { - s1++; - continue; - } - return FALSE; - } - s1++; s2++; - len--; - } - - return len == 0 && *s1 == '\0'; -} - -static cairo_bool_t -parse_int (const char *word, - size_t wordlen, - int *out) -{ - char *end; - long val = strtol (word, &end, 10); - int i = val; - - if (end != word && (end == word + wordlen) && val >= 0 && val == i) - { - if (out) - *out = i; - - return TRUE; - } - - return FALSE; -} - -static cairo_bool_t -find_field (const char *what, - const FieldMap *map, - int n_elements, - const char *str, - int len, - int *val) -{ - int i; - cairo_bool_t had_prefix = FALSE; - - if (what) - { - i = strlen (what); - if (len > i && 0 == strncmp (what, str, i) && str[i] == '=') - { - str += i + 1; - len -= i + 1; - had_prefix = TRUE; - } - } - - for (i=0; iNAME)) \ - return; \ - - FIELD (weight); - FIELD (slant); - FIELD (stretch); - FIELD (smallcaps); - FIELD (monospace); - -#undef FIELD -} - -static void -face_props_parse (twin_face_properties_t *props, - const char *s) -{ - const char *start, *end; - - for (start = end = s; *end; end++) { - if (*end != ' ' && *end != ':') - continue; - - if (start < end) - parse_field (props, start, end - start); - start = end + 1; - } - if (start < end) - parse_field (props, start, end - start); -} - -static twin_face_properties_t * -twin_font_face_create_properties (cairo_font_face_t *twin_face) -{ - twin_face_properties_t *props; - - props = malloc (sizeof (twin_face_properties_t)); - if (unlikely (props == NULL)) - return NULL; - - props->stretch = TWIN_STRETCH_NORMAL; - props->slant = CAIRO_FONT_SLANT_NORMAL; - props->weight = TWIN_WEIGHT_NORMAL; - props->monospace = FALSE; - props->smallcaps = FALSE; - - if (unlikely (cairo_font_face_set_user_data (twin_face, - &twin_properties_key, - props, free))) { - free (props); - return NULL; - } - - return props; -} - -static cairo_status_t -twin_font_face_set_properties_from_toy (cairo_font_face_t *twin_face, - cairo_toy_font_face_t *toy_face) -{ - twin_face_properties_t *props; - - props = twin_font_face_create_properties (twin_face); - if (unlikely (props == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - props->slant = toy_face->slant; - props->weight = toy_face->weight == CAIRO_FONT_WEIGHT_NORMAL ? - TWIN_WEIGHT_NORMAL : TWIN_WEIGHT_BOLD; - face_props_parse (props, toy_face->family); - - return CAIRO_STATUS_SUCCESS; -} - - -/* - * Scaled properties - */ - -typedef struct _twin_scaled_properties { - twin_face_properties_t *face_props; - - cairo_bool_t snap; /* hint outlines */ - - double weight; /* unhinted pen width */ - double penx, peny; /* hinted pen width */ - double marginl, marginr; /* hinted side margins */ - - double stretch; /* stretch factor */ -} twin_scaled_properties_t; - -static void -compute_hinting_scale (cairo_t *cr, - double x, double y, - double *scale, double *inv) -{ - cairo_user_to_device_distance (cr, &x, &y); - *scale = x == 0 ? y : y == 0 ? x :sqrt (x*x + y*y); - *inv = 1 / *scale; -} - -static void -compute_hinting_scales (cairo_t *cr, - double *x_scale, double *x_scale_inv, - double *y_scale, double *y_scale_inv) -{ - double x, y; - - x = 1; y = 0; - compute_hinting_scale (cr, x, y, x_scale, x_scale_inv); - - x = 0; y = 1; - compute_hinting_scale (cr, x, y, y_scale, y_scale_inv); -} - -#define SNAPXI(p) (_cairo_round ((p) * x_scale) * x_scale_inv) -#define SNAPYI(p) (_cairo_round ((p) * y_scale) * y_scale_inv) - -/* This controls the global font size */ -#define F(g) ((g) / 72.) - -static void -twin_hint_pen_and_margins(cairo_t *cr, - double *penx, double *peny, - double *marginl, double *marginr) -{ - double x_scale, x_scale_inv; - double y_scale, y_scale_inv; - double margin; - - compute_hinting_scales (cr, - &x_scale, &x_scale_inv, - &y_scale, &y_scale_inv); - - *penx = SNAPXI (*penx); - if (*penx < x_scale_inv) - *penx = x_scale_inv; - - *peny = SNAPYI (*peny); - if (*peny < y_scale_inv) - *peny = y_scale_inv; - - margin = *marginl + *marginr; - *marginl = SNAPXI (*marginl); - if (*marginl < x_scale_inv) - *marginl = x_scale_inv; - - *marginr = margin - *marginl; - if (*marginr < 0) - *marginr = 0; - *marginr = SNAPXI (*marginr); -} - -static cairo_status_t -twin_scaled_font_compute_properties (cairo_scaled_font_t *scaled_font, - cairo_t *cr) -{ - cairo_status_t status; - twin_scaled_properties_t *props; - - props = malloc (sizeof (twin_scaled_properties_t)); - if (unlikely (props == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - - props->face_props = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font), - &twin_properties_key); - - props->snap = scaled_font->options.hint_style > CAIRO_HINT_STYLE_NONE; - - /* weight */ - props->weight = props->face_props->weight * (F (4) / TWIN_WEIGHT_NORMAL); - - /* pen & margins */ - props->penx = props->peny = props->weight; - props->marginl = props->marginr = F (4); - if (scaled_font->options.hint_style > CAIRO_HINT_STYLE_SLIGHT) - twin_hint_pen_and_margins(cr, - &props->penx, &props->peny, - &props->marginl, &props->marginr); - - /* stretch */ - props->stretch = 1 + .1 * ((int) props->face_props->stretch - (int) TWIN_STRETCH_NORMAL); - - - /* Save it */ - status = cairo_scaled_font_set_user_data (scaled_font, - &twin_properties_key, - props, free); - if (unlikely (status)) - goto FREE_PROPS; - - return CAIRO_STATUS_SUCCESS; - -FREE_PROPS: - free (props); - return status; -} - - -/* - * User-font implementation - */ - -static cairo_status_t -twin_scaled_font_init (cairo_scaled_font_t *scaled_font, - cairo_t *cr, - cairo_font_extents_t *metrics) -{ - metrics->ascent = F (54); - metrics->descent = 1 - metrics->ascent; - - return twin_scaled_font_compute_properties (scaled_font, cr); -} - -#define TWIN_GLYPH_MAX_SNAP_X 4 -#define TWIN_GLYPH_MAX_SNAP_Y 7 - -typedef struct { - int n_snap_x; - int8_t snap_x[TWIN_GLYPH_MAX_SNAP_X]; - double snapped_x[TWIN_GLYPH_MAX_SNAP_X]; - int n_snap_y; - int8_t snap_y[TWIN_GLYPH_MAX_SNAP_Y]; - double snapped_y[TWIN_GLYPH_MAX_SNAP_Y]; -} twin_snap_info_t; - -#define twin_glyph_left(g) ((g)[0]) -#define twin_glyph_right(g) ((g)[1]) -#define twin_glyph_ascent(g) ((g)[2]) -#define twin_glyph_descent(g) ((g)[3]) - -#define twin_glyph_n_snap_x(g) ((g)[4]) -#define twin_glyph_n_snap_y(g) ((g)[5]) -#define twin_glyph_snap_x(g) (&g[6]) -#define twin_glyph_snap_y(g) (twin_glyph_snap_x(g) + twin_glyph_n_snap_x(g)) -#define twin_glyph_draw(g) (twin_glyph_snap_y(g) + twin_glyph_n_snap_y(g)) - -static void -twin_compute_snap (cairo_t *cr, - twin_snap_info_t *info, - const signed char *b) -{ - int s, n; - const signed char *snap; - double x_scale, x_scale_inv; - double y_scale, y_scale_inv; - - compute_hinting_scales (cr, - &x_scale, &x_scale_inv, - &y_scale, &y_scale_inv); - - snap = twin_glyph_snap_x (b); - n = twin_glyph_n_snap_x (b); - info->n_snap_x = n; - assert (n <= TWIN_GLYPH_MAX_SNAP_X); - for (s = 0; s < n; s++) { - info->snap_x[s] = snap[s]; - info->snapped_x[s] = SNAPXI (F (snap[s])); - } - - snap = twin_glyph_snap_y (b); - n = twin_glyph_n_snap_y (b); - info->n_snap_y = n; - assert (n <= TWIN_GLYPH_MAX_SNAP_Y); - for (s = 0; s < n; s++) { - info->snap_y[s] = snap[s]; - info->snapped_y[s] = SNAPYI (F (snap[s])); - } -} - -static double -twin_snap (int8_t v, int n, int8_t *snap, double *snapped) -{ - int s; - - if (!n) - return F(v); - - if (snap[0] == v) - return snapped[0]; - - for (s = 0; s < n - 1; s++) - { - if (snap[s+1] == v) - return snapped[s+1]; - - if (snap[s] <= v && v <= snap[s+1]) - { - int before = snap[s]; - int after = snap[s+1]; - int dist = after - before; - double snap_before = snapped[s]; - double snap_after = snapped[s+1]; - double dist_before = v - before; - return snap_before + (snap_after - snap_before) * dist_before / dist; - } - } - return F(v); -} - -#define SNAPX(p) twin_snap (p, info.n_snap_x, info.snap_x, info.snapped_x) -#define SNAPY(p) twin_snap (p, info.n_snap_y, info.snap_y, info.snapped_y) - -static cairo_status_t -twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font, - unsigned long glyph, - cairo_t *cr, - cairo_text_extents_t *metrics) -{ - double x1, y1, x2, y2, x3, y3; - double marginl; - twin_scaled_properties_t *props; - twin_snap_info_t info; - const int8_t *b; - const int8_t *g; - int8_t w; - double gw; - - props = cairo_scaled_font_get_user_data (scaled_font, &twin_properties_key); - - /* Save glyph space, we need it when stroking */ - cairo_save (cr); - - /* center the pen */ - cairo_translate (cr, props->penx * .5, -props->peny * .5); - - /* small-caps */ - if (props->face_props->smallcaps && glyph >= 'a' && glyph <= 'z') { - glyph += 'A' - 'a'; - /* 28 and 42 are small and capital letter heights of the glyph data */ - cairo_scale (cr, 1, 28. / 42); - } - - /* slant */ - if (props->face_props->slant != CAIRO_FONT_SLANT_NORMAL) { - cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0}; - cairo_transform (cr, &shear); - } - - b = _cairo_twin_outlines + - _cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph]; - g = twin_glyph_draw(b); - w = twin_glyph_right(b); - gw = F(w); - - marginl = props->marginl; - - /* monospace */ - if (props->face_props->monospace) { - double monow = F(24); - double extra = props->penx + props->marginl + props->marginr; - cairo_scale (cr, (monow + extra) / (gw + extra), 1); - gw = monow; - - /* resnap margin for new transform */ - { - double x, y, x_scale, x_scale_inv; - x = 1; y = 0; - compute_hinting_scale (cr, x, y, &x_scale, &x_scale_inv); - marginl = SNAPXI (marginl); - } - } - - cairo_translate (cr, marginl, 0); - - /* stretch */ - cairo_scale (cr, props->stretch, 1); - - if (props->snap) - twin_compute_snap (cr, &info, b); - else - info.n_snap_x = info.n_snap_y = 0; - - /* advance width */ - metrics->x_advance = gw * props->stretch + props->penx + props->marginl + props->marginr; - - /* glyph shape */ - for (;;) { - switch (*g++) { - case 'M': - cairo_close_path (cr); - /* fall through */ - case 'm': - x1 = SNAPX(*g++); - y1 = SNAPY(*g++); - cairo_move_to (cr, x1, y1); - continue; - case 'L': - cairo_close_path (cr); - /* fall through */ - case 'l': - x1 = SNAPX(*g++); - y1 = SNAPY(*g++); - cairo_line_to (cr, x1, y1); - continue; - case 'C': - cairo_close_path (cr); - /* fall through */ - case 'c': - x1 = SNAPX(*g++); - y1 = SNAPY(*g++); - x2 = SNAPX(*g++); - y2 = SNAPY(*g++); - x3 = SNAPX(*g++); - y3 = SNAPY(*g++); - cairo_curve_to (cr, x1, y1, x2, y2, x3, y3); - continue; - case 'E': - cairo_close_path (cr); - /* fall through */ - case 'e': - cairo_restore (cr); /* restore glyph space */ - cairo_set_tolerance (cr, 0.01); - cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_width (cr, 1); - cairo_scale (cr, props->penx, props->peny); - cairo_stroke (cr); - break; - case 'X': - /* filler */ - continue; - } - break; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -twin_scaled_font_unicode_to_glyph (cairo_scaled_font_t *scaled_font, - unsigned long unicode, - unsigned long *glyph) -{ - /* We use an identity charmap. Which means we could live - * with no unicode_to_glyph method too. But we define this - * to map all unknown chars to a single unknown glyph to - * reduce pressure on cache. */ - - if (likely (unicode < ARRAY_LENGTH (_cairo_twin_charmap))) - *glyph = unicode; - else - *glyph = 0; - - return CAIRO_STATUS_SUCCESS; -} - - -/* - * Face constructor - */ - -static cairo_font_face_t * -_cairo_font_face_twin_create_internal (void) -{ - cairo_font_face_t *twin_font_face; - - twin_font_face = cairo_user_font_face_create (); - cairo_user_font_face_set_init_func (twin_font_face, twin_scaled_font_init); - cairo_user_font_face_set_render_glyph_func (twin_font_face, twin_scaled_font_render_glyph); - cairo_user_font_face_set_unicode_to_glyph_func (twin_font_face, twin_scaled_font_unicode_to_glyph); - - return twin_font_face; -} - -cairo_font_face_t * -_cairo_font_face_twin_create_fallback (void) -{ - cairo_font_face_t *twin_font_face; - - twin_font_face = _cairo_font_face_twin_create_internal (); - if (! twin_font_face_create_properties (twin_font_face)) { - cairo_font_face_destroy (twin_font_face); - return (cairo_font_face_t *) &_cairo_font_face_nil; - } - - return twin_font_face; -} - -cairo_status_t -_cairo_font_face_twin_create_for_toy (cairo_toy_font_face_t *toy_face, - cairo_font_face_t **font_face) -{ - cairo_status_t status; - cairo_font_face_t *twin_font_face; - - twin_font_face = _cairo_font_face_twin_create_internal (); - status = twin_font_face_set_properties_from_toy (twin_font_face, toy_face); - if (status) { - cairo_font_face_destroy (twin_font_face); - return status; - } - - *font_face = twin_font_face; - - return CAIRO_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face.c deleted file mode 100644 index 3bcd2a1e6b3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-face.c +++ /dev/null @@ -1,338 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Graydon Hoare - * Owen Taylor - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -/** - * SECTION:cairo-font-face - * @Title: cairo_font_face_t - * @Short_Description: Base class for font faces - * @See_Also: #cairo_scaled_font_t - * - * #cairo_font_face_t represents a particular font at a particular weight, - * slant, and other characteristic but no size, transformation, or size. - * - * Font faces are created using font-backend-specific - * constructors, typically of the form - * cairo_backend_font_face_create(), - * or implicitly using the toy text API by way of - * cairo_select_font_face(). The resulting face can be accessed using - * cairo_get_font_face(). - **/ - -/* #cairo_font_face_t */ - -const cairo_font_face_t _cairo_font_face_nil = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_NO_MEMORY, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -cairo_status_t -_cairo_font_face_set_error (cairo_font_face_t *font_face, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&font_face->status, status); - - return _cairo_error (status); -} - -void -_cairo_font_face_init (cairo_font_face_t *font_face, - const cairo_font_face_backend_t *backend) -{ - CAIRO_MUTEX_INITIALIZE (); - - font_face->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (&font_face->ref_count, 1); - font_face->backend = backend; - - _cairo_user_data_array_init (&font_face->user_data); -} - -/** - * cairo_font_face_reference: - * @font_face: a #cairo_font_face_t, (may be %NULL in which case this - * function does nothing). - * - * Increases the reference count on @font_face by one. This prevents - * @font_face from being destroyed until a matching call to - * cairo_font_face_destroy() is made. - * - * The number of references to a #cairo_font_face_t can be get using - * cairo_font_face_get_reference_count(). - * - * Return value: the referenced #cairo_font_face_t. - * - * Since: 1.0 - **/ -cairo_font_face_t * -cairo_font_face_reference (cairo_font_face_t *font_face) -{ - if (font_face == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) - return font_face; - - /* We would normally assert that we have a reference here but we - * can't get away with that due to the zombie case as documented - * in _cairo_ft_font_face_destroy. */ - - _cairo_reference_count_inc (&font_face->ref_count); - - return font_face; -} -slim_hidden_def (cairo_font_face_reference); - -static inline cairo_bool_t -__put(cairo_reference_count_t *v) -{ - int c, old; - - c = CAIRO_REFERENCE_COUNT_GET_VALUE(v); - while (c != 1 && (old = _cairo_atomic_int_cmpxchg_return_old(&v->ref_count, c, c - 1)) != c) - c = old; - - return c != 1; -} - -cairo_bool_t -_cairo_font_face_destroy (void *abstract_face) -{ -#if 0 /* Nothing needs to be done, we can just drop the last reference */ - cairo_font_face_t *font_face = abstract_face; - return _cairo_reference_count_dec_and_test (&font_face->ref_count); -#endif - return TRUE; -} - -/** - * cairo_font_face_destroy: - * @font_face: a #cairo_font_face_t - * - * Decreases the reference count on @font_face by one. If the result - * is zero, then @font_face and all associated resources are freed. - * See cairo_font_face_reference(). - * - * Since: 1.0 - **/ -void -cairo_font_face_destroy (cairo_font_face_t *font_face) -{ - if (font_face == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->ref_count)); - - /* We allow resurrection to deal with some memory management for the - * FreeType backend where cairo_ft_font_face_t and cairo_ft_unscaled_font_t - * need to effectively mutually reference each other - */ - if (__put (&font_face->ref_count)) - return; - - if (! font_face->backend->destroy (font_face)) - return; - - _cairo_user_data_array_fini (&font_face->user_data); - - free (font_face); -} -slim_hidden_def (cairo_font_face_destroy); - -/** - * cairo_font_face_get_type: - * @font_face: a font face - * - * This function returns the type of the backend used to create - * a font face. See #cairo_font_type_t for available types. - * - * Return value: The type of @font_face. - * - * Since: 1.2 - **/ -cairo_font_type_t -cairo_font_face_get_type (cairo_font_face_t *font_face) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) - return CAIRO_FONT_TYPE_TOY; - - return font_face->backend->type; -} - -/** - * cairo_font_face_get_reference_count: - * @font_face: a #cairo_font_face_t - * - * Returns the current reference count of @font_face. - * - * Return value: the current reference count of @font_face. If the - * object is a nil object, 0 will be returned. - * - * Since: 1.4 - **/ -unsigned int -cairo_font_face_get_reference_count (cairo_font_face_t *font_face) -{ - if (font_face == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&font_face->ref_count); -} - -/** - * cairo_font_face_status: - * @font_face: a #cairo_font_face_t - * - * Checks whether an error has previously occurred for this - * font face - * - * Return value: %CAIRO_STATUS_SUCCESS or another error such as - * %CAIRO_STATUS_NO_MEMORY. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_font_face_status (cairo_font_face_t *font_face) -{ - return font_face->status; -} - -/** - * cairo_font_face_get_user_data: - * @font_face: a #cairo_font_face_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Return user data previously attached to @font_face using the specified - * key. If no user data has been attached with the given key this - * function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - * - * Since: 1.0 - **/ -void * -cairo_font_face_get_user_data (cairo_font_face_t *font_face, - const cairo_user_data_key_t *key) -{ - return _cairo_user_data_array_get_data (&font_face->user_data, - key); -} -slim_hidden_def (cairo_font_face_get_user_data); - -/** - * cairo_font_face_set_user_data: - * @font_face: a #cairo_font_face_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach to the font face - * @destroy: a #cairo_destroy_func_t which will be called when the - * font face is destroyed or when new user data is attached using the - * same key. - * - * Attach user data to @font_face. To remove user data from a font face, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_font_face_set_user_data (cairo_font_face_t *font_face, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) - return font_face->status; - - return _cairo_user_data_array_set_data (&font_face->user_data, - key, user_data, destroy); -} -slim_hidden_def (cairo_font_face_set_user_data); - -void -_cairo_unscaled_font_init (cairo_unscaled_font_t *unscaled_font, - const cairo_unscaled_font_backend_t *backend) -{ - CAIRO_REFERENCE_COUNT_INIT (&unscaled_font->ref_count, 1); - unscaled_font->backend = backend; -} - -cairo_unscaled_font_t * -_cairo_unscaled_font_reference (cairo_unscaled_font_t *unscaled_font) -{ - if (unscaled_font == NULL) - return NULL; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&unscaled_font->ref_count)); - - _cairo_reference_count_inc (&unscaled_font->ref_count); - - return unscaled_font; -} - -void -_cairo_unscaled_font_destroy (cairo_unscaled_font_t *unscaled_font) -{ - if (unscaled_font == NULL) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&unscaled_font->ref_count)); - - if (__put (&unscaled_font->ref_count)) - return; - - if (! unscaled_font->backend->destroy (unscaled_font)) - return; - - free (unscaled_font); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-options.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-options.c deleted file mode 100644 index ad28745e6b9..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-font-options.c +++ /dev/null @@ -1,535 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Owen Taylor - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -/** - * SECTION:cairo-font-options - * @Title: cairo_font_options_t - * @Short_Description: How a font should be rendered - * @See_Also: #cairo_scaled_font_t - * - * The font options specify how fonts should be rendered. Most of the - * time the font options implied by a surface are just right and do not - * need any changes, but for pixel-based targets tweaking font options - * may result in superior output on a particular display. - **/ - -static const cairo_font_options_t _cairo_font_options_nil = { - CAIRO_ANTIALIAS_DEFAULT, - CAIRO_SUBPIXEL_ORDER_DEFAULT, - CAIRO_LCD_FILTER_DEFAULT, - CAIRO_HINT_STYLE_DEFAULT, - CAIRO_HINT_METRICS_DEFAULT, - CAIRO_ROUND_GLYPH_POS_DEFAULT -}; - -/** - * _cairo_font_options_init_default: - * @options: a #cairo_font_options_t - * - * Initializes all fields of the font options object to default values. - **/ -void -_cairo_font_options_init_default (cairo_font_options_t *options) -{ - options->antialias = CAIRO_ANTIALIAS_DEFAULT; - options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; - options->lcd_filter = CAIRO_LCD_FILTER_DEFAULT; - options->hint_style = CAIRO_HINT_STYLE_DEFAULT; - options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT; - options->round_glyph_positions = CAIRO_ROUND_GLYPH_POS_DEFAULT; -} - -void -_cairo_font_options_init_copy (cairo_font_options_t *options, - const cairo_font_options_t *other) -{ - options->antialias = other->antialias; - options->subpixel_order = other->subpixel_order; - options->lcd_filter = other->lcd_filter; - options->hint_style = other->hint_style; - options->hint_metrics = other->hint_metrics; - options->round_glyph_positions = other->round_glyph_positions; -} - -/** - * cairo_font_options_create: - * - * Allocates a new font options object with all options initialized - * to default values. - * - * Return value: a newly allocated #cairo_font_options_t. Free with - * cairo_font_options_destroy(). This function always returns a - * valid pointer; if memory cannot be allocated, then a special - * error object is returned where all operations on the object do nothing. - * You can check for this with cairo_font_options_status(). - * - * Since: 1.0 - **/ -cairo_font_options_t * -cairo_font_options_create (void) -{ - cairo_font_options_t *options; - - options = malloc (sizeof (cairo_font_options_t)); - if (!options) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_options_t *) &_cairo_font_options_nil; - } - - _cairo_font_options_init_default (options); - - return options; -} - -/** - * cairo_font_options_copy: - * @original: a #cairo_font_options_t - * - * Allocates a new font options object copying the option values from - * @original. - * - * Return value: a newly allocated #cairo_font_options_t. Free with - * cairo_font_options_destroy(). This function always returns a - * valid pointer; if memory cannot be allocated, then a special - * error object is returned where all operations on the object do nothing. - * You can check for this with cairo_font_options_status(). - * - * Since: 1.0 - **/ -cairo_font_options_t * -cairo_font_options_copy (const cairo_font_options_t *original) -{ - cairo_font_options_t *options; - - if (cairo_font_options_status ((cairo_font_options_t *) original)) - return (cairo_font_options_t *) &_cairo_font_options_nil; - - options = malloc (sizeof (cairo_font_options_t)); - if (!options) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_options_t *) &_cairo_font_options_nil; - } - - _cairo_font_options_init_copy (options, original); - - return options; -} - -/** - * cairo_font_options_destroy: - * @options: a #cairo_font_options_t - * - * Destroys a #cairo_font_options_t object created with - * cairo_font_options_create() or cairo_font_options_copy(). - * - * Since: 1.0 - **/ -void -cairo_font_options_destroy (cairo_font_options_t *options) -{ - if (cairo_font_options_status (options)) - return; - - free (options); -} - -/** - * cairo_font_options_status: - * @options: a #cairo_font_options_t - * - * Checks whether an error has previously occurred for this - * font options object - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.0 - **/ -cairo_status_t -cairo_font_options_status (cairo_font_options_t *options) -{ - if (options == NULL) - return CAIRO_STATUS_NULL_POINTER; - else if (options == (cairo_font_options_t *) &_cairo_font_options_nil) - return CAIRO_STATUS_NO_MEMORY; - else - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_font_options_status); - -/** - * cairo_font_options_merge: - * @options: a #cairo_font_options_t - * @other: another #cairo_font_options_t - * - * Merges non-default options from @other into @options, replacing - * existing values. This operation can be thought of as somewhat - * similar to compositing @other onto @options with the operation - * of %CAIRO_OPERATOR_OVER. - * - * Since: 1.0 - **/ -void -cairo_font_options_merge (cairo_font_options_t *options, - const cairo_font_options_t *other) -{ - if (cairo_font_options_status (options)) - return; - - if (cairo_font_options_status ((cairo_font_options_t *) other)) - return; - - if (other->antialias != CAIRO_ANTIALIAS_DEFAULT) - options->antialias = other->antialias; - if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) - options->subpixel_order = other->subpixel_order; - if (other->lcd_filter != CAIRO_LCD_FILTER_DEFAULT) - options->lcd_filter = other->lcd_filter; - if (other->hint_style != CAIRO_HINT_STYLE_DEFAULT) - options->hint_style = other->hint_style; - if (other->hint_metrics != CAIRO_HINT_METRICS_DEFAULT) - options->hint_metrics = other->hint_metrics; - if (other->round_glyph_positions != CAIRO_ROUND_GLYPH_POS_DEFAULT) - options->round_glyph_positions = other->round_glyph_positions; -} -slim_hidden_def (cairo_font_options_merge); - -/** - * cairo_font_options_equal: - * @options: a #cairo_font_options_t - * @other: another #cairo_font_options_t - * - * Compares two font options objects for equality. - * - * Return value: %TRUE if all fields of the two font options objects match. - * Note that this function will return %FALSE if either object is in - * error. - * - * Since: 1.0 - **/ -cairo_bool_t -cairo_font_options_equal (const cairo_font_options_t *options, - const cairo_font_options_t *other) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return FALSE; - if (cairo_font_options_status ((cairo_font_options_t *) other)) - return FALSE; - - if (options == other) - return TRUE; - - return (options->antialias == other->antialias && - options->subpixel_order == other->subpixel_order && - options->lcd_filter == other->lcd_filter && - options->hint_style == other->hint_style && - options->hint_metrics == other->hint_metrics && - options->round_glyph_positions == other->round_glyph_positions); -} -slim_hidden_def (cairo_font_options_equal); - -/** - * cairo_font_options_hash: - * @options: a #cairo_font_options_t - * - * Compute a hash for the font options object; this value will - * be useful when storing an object containing a #cairo_font_options_t - * in a hash table. - * - * Return value: the hash value for the font options object. - * The return value can be cast to a 32-bit type if a - * 32-bit hash value is needed. - * - * Since: 1.0 - **/ -unsigned long -cairo_font_options_hash (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - options = &_cairo_font_options_nil; /* force default values */ - - return ((options->antialias) | - (options->subpixel_order << 4) | - (options->lcd_filter << 8) | - (options->hint_style << 12) | - (options->hint_metrics << 16)); -} -slim_hidden_def (cairo_font_options_hash); - -/** - * cairo_font_options_set_antialias: - * @options: a #cairo_font_options_t - * @antialias: the new antialiasing mode - * - * Sets the antialiasing mode for the font options object. This - * specifies the type of antialiasing to do when rendering text. - * - * Since: 1.0 - **/ -void -cairo_font_options_set_antialias (cairo_font_options_t *options, - cairo_antialias_t antialias) -{ - if (cairo_font_options_status (options)) - return; - - options->antialias = antialias; -} -slim_hidden_def (cairo_font_options_set_antialias); - -/** - * cairo_font_options_get_antialias: - * @options: a #cairo_font_options_t - * - * Gets the antialiasing mode for the font options object. - * - * Return value: the antialiasing mode - * - * Since: 1.0 - **/ -cairo_antialias_t -cairo_font_options_get_antialias (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return CAIRO_ANTIALIAS_DEFAULT; - - return options->antialias; -} - -/** - * cairo_font_options_set_subpixel_order: - * @options: a #cairo_font_options_t - * @subpixel_order: the new subpixel order - * - * Sets the subpixel order for the font options object. The subpixel - * order specifies the order of color elements within each pixel on - * the display device when rendering with an antialiasing mode of - * %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for - * #cairo_subpixel_order_t for full details. - * - * Since: 1.0 - **/ -void -cairo_font_options_set_subpixel_order (cairo_font_options_t *options, - cairo_subpixel_order_t subpixel_order) -{ - if (cairo_font_options_status (options)) - return; - - options->subpixel_order = subpixel_order; -} -slim_hidden_def (cairo_font_options_set_subpixel_order); - -/** - * cairo_font_options_get_subpixel_order: - * @options: a #cairo_font_options_t - * - * Gets the subpixel order for the font options object. - * See the documentation for #cairo_subpixel_order_t for full details. - * - * Return value: the subpixel order for the font options object - * - * Since: 1.0 - **/ -cairo_subpixel_order_t -cairo_font_options_get_subpixel_order (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return CAIRO_SUBPIXEL_ORDER_DEFAULT; - - return options->subpixel_order; -} - -/** - * _cairo_font_options_set_lcd_filter: - * @options: a #cairo_font_options_t - * @lcd_filter: the new LCD filter - * - * Sets the LCD filter for the font options object. The LCD filter - * specifies how pixels are filtered when rendered with an antialiasing - * mode of %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for - * #cairo_lcd_filter_t for full details. - **/ -void -_cairo_font_options_set_lcd_filter (cairo_font_options_t *options, - cairo_lcd_filter_t lcd_filter) -{ - if (cairo_font_options_status (options)) - return; - - options->lcd_filter = lcd_filter; -} - -/** - * _cairo_font_options_get_lcd_filter: - * @options: a #cairo_font_options_t - * - * Gets the LCD filter for the font options object. - * See the documentation for #cairo_lcd_filter_t for full details. - * - * Return value: the LCD filter for the font options object - **/ -cairo_lcd_filter_t -_cairo_font_options_get_lcd_filter (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return CAIRO_LCD_FILTER_DEFAULT; - - return options->lcd_filter; -} - -/** - * _cairo_font_options_set_round_glyph_positions: - * @options: a #cairo_font_options_t - * @round: the new rounding value - * - * Sets the rounding options for the font options object. If rounding is set, a - * glyph's position will be rounded to integer values. - **/ -void -_cairo_font_options_set_round_glyph_positions (cairo_font_options_t *options, - cairo_round_glyph_positions_t round) -{ - if (cairo_font_options_status (options)) - return; - - options->round_glyph_positions = round; -} - -/** - * _cairo_font_options_get_round_glyph_positions: - * @options: a #cairo_font_options_t - * - * Gets the glyph position rounding option for the font options object. - * - * Return value: The round glyph posistions flag for the font options object. - **/ -cairo_round_glyph_positions_t -_cairo_font_options_get_round_glyph_positions (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return CAIRO_ROUND_GLYPH_POS_DEFAULT; - - return options->round_glyph_positions; -} - -/** - * cairo_font_options_set_hint_style: - * @options: a #cairo_font_options_t - * @hint_style: the new hint style - * - * Sets the hint style for font outlines for the font options object. - * This controls whether to fit font outlines to the pixel grid, - * and if so, whether to optimize for fidelity or contrast. - * See the documentation for #cairo_hint_style_t for full details. - * - * Since: 1.0 - **/ -void -cairo_font_options_set_hint_style (cairo_font_options_t *options, - cairo_hint_style_t hint_style) -{ - if (cairo_font_options_status (options)) - return; - - options->hint_style = hint_style; -} -slim_hidden_def (cairo_font_options_set_hint_style); - -/** - * cairo_font_options_get_hint_style: - * @options: a #cairo_font_options_t - * - * Gets the hint style for font outlines for the font options object. - * See the documentation for #cairo_hint_style_t for full details. - * - * Return value: the hint style for the font options object - * - * Since: 1.0 - **/ -cairo_hint_style_t -cairo_font_options_get_hint_style (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return CAIRO_HINT_STYLE_DEFAULT; - - return options->hint_style; -} - -/** - * cairo_font_options_set_hint_metrics: - * @options: a #cairo_font_options_t - * @hint_metrics: the new metrics hinting mode - * - * Sets the metrics hinting mode for the font options object. This - * controls whether metrics are quantized to integer values in - * device units. - * See the documentation for #cairo_hint_metrics_t for full details. - * - * Since: 1.0 - **/ -void -cairo_font_options_set_hint_metrics (cairo_font_options_t *options, - cairo_hint_metrics_t hint_metrics) -{ - if (cairo_font_options_status (options)) - return; - - options->hint_metrics = hint_metrics; -} -slim_hidden_def (cairo_font_options_set_hint_metrics); - -/** - * cairo_font_options_get_hint_metrics: - * @options: a #cairo_font_options_t - * - * Gets the metrics hinting mode for the font options object. - * See the documentation for #cairo_hint_metrics_t for full details. - * - * Return value: the metrics hinting mode for the font options object - * - * Since: 1.0 - **/ -cairo_hint_metrics_t -cairo_font_options_get_hint_metrics (const cairo_font_options_t *options) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return CAIRO_HINT_METRICS_DEFAULT; - - return options->hint_metrics; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fontconfig-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fontconfig-private.h deleted file mode 100644 index ea873abe7e4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-fontconfig-private.h +++ /dev/null @@ -1,78 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2000 Keith Packard - * Copyright © 2005 Red Hat, Inc - * Copyright © 2010 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Graydon Hoare - * Owen Taylor - * Keith Packard - * Carl Worth - * Chris Wilson - */ - -#ifndef _CAIRO_FONTCONFIG_PRIVATE_H -#define _CAIRO_FONTCONFIG_PRIVATE_H - -#include "cairo.h" - -#if CAIRO_HAS_FC_FONT -#include -#include -#endif - -/* sub-pixel order */ -#ifndef FC_RGBA_UNKNOWN -#define FC_RGBA_UNKNOWN 0 -#define FC_RGBA_RGB 1 -#define FC_RGBA_BGR 2 -#define FC_RGBA_VRGB 3 -#define FC_RGBA_VBGR 4 -#define FC_RGBA_NONE 5 -#endif - -/* hinting style */ -#ifndef FC_HINT_NONE -#define FC_HINT_NONE 0 -#define FC_HINT_SLIGHT 1 -#define FC_HINT_MEDIUM 2 -#define FC_HINT_FULL 3 -#endif - -/* LCD filter */ -#ifndef FC_LCD_NONE -#define FC_LCD_NONE 0 -#define FC_LCD_DEFAULT 1 -#define FC_LCD_LIGHT 2 -#define FC_LCD_LEGACY 3 -#endif - -#endif /* _CAIRO_FONTCONFIG_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool-private.h deleted file mode 100644 index 0ec6de3d1f1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool-private.h +++ /dev/null @@ -1,139 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_FREED_POOL_H -#define CAIRO_FREED_POOL_H - -#include "cairoint.h" -#include "cairo-atomic-private.h" - -CAIRO_BEGIN_DECLS - -#define DISABLE_FREED_POOLS 0 - -#if HAS_ATOMIC_OPS && ! DISABLE_FREED_POOLS -/* Keep a stash of recently freed clip_paths, since we need to - * reallocate them frequently. - */ -#define MAX_FREED_POOL_SIZE 16 -typedef struct { - void *pool[MAX_FREED_POOL_SIZE]; - int top; -} freed_pool_t; - -static cairo_always_inline void * -_atomic_fetch (void **slot) -{ - void *ptr; - - do { - ptr = _cairo_atomic_ptr_get (slot); - } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); - - return ptr; -} - -static cairo_always_inline cairo_bool_t -_atomic_store (void **slot, void *ptr) -{ - return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr); -} - -cairo_private void * -_freed_pool_get_search (freed_pool_t *pool); - -static inline void * -_freed_pool_get (freed_pool_t *pool) -{ - void *ptr; - int i; - - i = pool->top - 1; - if (i < 0) - i = 0; - - ptr = _atomic_fetch (&pool->pool[i]); - if (likely (ptr != NULL)) { - pool->top = i; - return ptr; - } - - /* either empty or contended */ - return _freed_pool_get_search (pool); -} - -cairo_private void -_freed_pool_put_search (freed_pool_t *pool, void *ptr); - -static inline void -_freed_pool_put (freed_pool_t *pool, void *ptr) -{ - int i; - - i = pool->top; - if (likely (i < ARRAY_LENGTH (pool->pool) && - _atomic_store (&pool->pool[i], ptr))) - { - pool->top = i + 1; - return; - } - - /* either full or contended */ - _freed_pool_put_search (pool, ptr); -} - -cairo_private void -_freed_pool_reset (freed_pool_t *pool); - -#define HAS_FREED_POOL 1 - -#else - -/* A warning about an unused freed-pool in a build without atomics - * enabled usually indicates a missing _freed_pool_reset() in the - * static reset function */ - -typedef int freed_pool_t; - -#define _freed_pool_get(pool) NULL -#define _freed_pool_put(pool, ptr) free(ptr) -#define _freed_pool_reset(ptr) - -#endif - -CAIRO_END_DECLS - -#endif /* CAIRO_FREED_POOL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool.c deleted file mode 100644 index cfdc8e96b05..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freed-pool.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-freed-pool-private.h" - -#if HAS_FREED_POOL - -void * -_freed_pool_get_search (freed_pool_t *pool) -{ - void *ptr; - int i; - - for (i = ARRAY_LENGTH (pool->pool); i--;) { - ptr = _atomic_fetch (&pool->pool[i]); - if (ptr != NULL) { - pool->top = i; - return ptr; - } - } - - /* empty */ - pool->top = 0; - return NULL; -} - -void -_freed_pool_put_search (freed_pool_t *pool, void *ptr) -{ - int i; - - for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) { - if (_atomic_store (&pool->pool[i], ptr)) { - pool->top = i + 1; - return; - } - } - - /* full */ - pool->top = i; - free (ptr); -} - -void -_freed_pool_reset (freed_pool_t *pool) -{ - int i; - - for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) { - free (pool->pool[i]); - pool->pool[i] = NULL; - } - - pool->top = 0; -} - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-private.h deleted file mode 100644 index 8fe6516f385..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-private.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright © 2006 Joonas Pihlaja - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -#ifndef CAIRO_FREELIST_H -#define CAIRO_FREELIST_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" -#include "cairo-freelist-type-private.h" - -/* for stand-alone compilation*/ -#ifndef VG -#define VG(x) -#endif - -#ifndef NULL -#define NULL (void *) 0 -#endif - -/* Initialise a freelist that will be responsible for allocating - * nodes of size nodesize. */ -cairo_private void -_cairo_freelist_init (cairo_freelist_t *freelist, unsigned nodesize); - -/* Deallocate any nodes in the freelist. */ -cairo_private void -_cairo_freelist_fini (cairo_freelist_t *freelist); - -/* Allocate a new node from the freelist. If the freelist contains no - * nodes, a new one will be allocated using malloc(). The caller is - * responsible for calling _cairo_freelist_free() or free() on the - * returned node. Returns %NULL on memory allocation error. */ -cairo_private void * -_cairo_freelist_alloc (cairo_freelist_t *freelist); - -/* Allocate a new node from the freelist. If the freelist contains no - * nodes, a new one will be allocated using calloc(). The caller is - * responsible for calling _cairo_freelist_free() or free() on the - * returned node. Returns %NULL on memory allocation error. */ -cairo_private void * -_cairo_freelist_calloc (cairo_freelist_t *freelist); - -/* Return a node to the freelist. This does not deallocate the memory, - * but makes it available for later reuse by - * _cairo_freelist_alloc(). */ -cairo_private void -_cairo_freelist_free (cairo_freelist_t *freelist, void *node); - - -cairo_private void -_cairo_freepool_init (cairo_freepool_t *freepool, unsigned nodesize); - -cairo_private void -_cairo_freepool_fini (cairo_freepool_t *freepool); - -static inline void -_cairo_freepool_reset (cairo_freepool_t *freepool) -{ - while (freepool->pools != &freepool->embedded_pool) { - cairo_freelist_pool_t *pool = freepool->pools; - freepool->pools = pool->next; - pool->next = freepool->freepools; - freepool->freepools = pool; - } - - freepool->embedded_pool.rem = sizeof (freepool->embedded_data); - freepool->embedded_pool.data = freepool->embedded_data; -} - -cairo_private void * -_cairo_freepool_alloc_from_new_pool (cairo_freepool_t *freepool); - -static inline void * -_cairo_freepool_alloc_from_pool (cairo_freepool_t *freepool) -{ - cairo_freelist_pool_t *pool; - uint8_t *ptr; - - pool = freepool->pools; - if (unlikely (freepool->nodesize > pool->rem)) - return _cairo_freepool_alloc_from_new_pool (freepool); - - ptr = pool->data; - pool->data += freepool->nodesize; - pool->rem -= freepool->nodesize; - VG (VALGRIND_MAKE_MEM_UNDEFINED (ptr, freepool->nodesize)); - return ptr; -} - -static inline void * -_cairo_freepool_alloc (cairo_freepool_t *freepool) -{ - cairo_freelist_node_t *node; - - node = freepool->first_free_node; - if (node == NULL) - return _cairo_freepool_alloc_from_pool (freepool); - - VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); - freepool->first_free_node = node->next; - VG (VALGRIND_MAKE_MEM_UNDEFINED (node, freepool->nodesize)); - - return node; -} - -cairo_private cairo_status_t -_cairo_freepool_alloc_array (cairo_freepool_t *freepool, - int count, - void **array); - -static inline void -_cairo_freepool_free (cairo_freepool_t *freepool, void *ptr) -{ - cairo_freelist_node_t *node = ptr; - - node->next = freepool->first_free_node; - freepool->first_free_node = node; - VG (VALGRIND_MAKE_MEM_NOACCESS (node, freepool->nodesize)); -} - -#endif /* CAIRO_FREELIST_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-type-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-type-private.h deleted file mode 100644 index 4dd05646107..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist-type-private.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2010 Joonas Pihlaja - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -#ifndef CAIRO_FREELIST_TYPE_H -#define CAIRO_FREELIST_TYPE_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" - -typedef struct _cairo_freelist_node cairo_freelist_node_t; -struct _cairo_freelist_node { - cairo_freelist_node_t *next; -}; - -typedef struct _cairo_freelist { - cairo_freelist_node_t *first_free_node; - unsigned nodesize; -} cairo_freelist_t; - -typedef struct _cairo_freelist_pool cairo_freelist_pool_t; -struct _cairo_freelist_pool { - cairo_freelist_pool_t *next; - unsigned size, rem; - uint8_t *data; -}; - -typedef struct _cairo_freepool { - cairo_freelist_node_t *first_free_node; - cairo_freelist_pool_t *pools; - cairo_freelist_pool_t *freepools; - unsigned nodesize; - cairo_freelist_pool_t embedded_pool; - uint8_t embedded_data[1000]; -} cairo_freepool_t; - -#endif /* CAIRO_FREELIST_TYPE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist.c deleted file mode 100644 index d596eab81dc..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-freelist.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright © 2006 Joonas Pihlaja - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" - -void -_cairo_freelist_init (cairo_freelist_t *freelist, unsigned nodesize) -{ - memset (freelist, 0, sizeof (cairo_freelist_t)); - freelist->nodesize = nodesize; -} - -void -_cairo_freelist_fini (cairo_freelist_t *freelist) -{ - cairo_freelist_node_t *node = freelist->first_free_node; - while (node) { - cairo_freelist_node_t *next; - - VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); - next = node->next; - - free (node); - node = next; - } -} - -void * -_cairo_freelist_alloc (cairo_freelist_t *freelist) -{ - if (freelist->first_free_node) { - cairo_freelist_node_t *node; - - node = freelist->first_free_node; - VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); - freelist->first_free_node = node->next; - VG (VALGRIND_MAKE_MEM_UNDEFINED (node, freelist->nodesize)); - - return node; - } - - return malloc (freelist->nodesize); -} - -void * -_cairo_freelist_calloc (cairo_freelist_t *freelist) -{ - void *node = _cairo_freelist_alloc (freelist); - if (node) - memset (node, 0, freelist->nodesize); - return node; -} - -void -_cairo_freelist_free (cairo_freelist_t *freelist, void *voidnode) -{ - cairo_freelist_node_t *node = voidnode; - if (node) { - node->next = freelist->first_free_node; - freelist->first_free_node = node; - VG (VALGRIND_MAKE_MEM_NOACCESS (node, freelist->nodesize)); - } -} - -void -_cairo_freepool_init (cairo_freepool_t *freepool, unsigned nodesize) -{ - freepool->first_free_node = NULL; - freepool->pools = &freepool->embedded_pool; - freepool->freepools = NULL; - freepool->nodesize = nodesize; - - freepool->embedded_pool.next = NULL; - freepool->embedded_pool.size = sizeof (freepool->embedded_data); - freepool->embedded_pool.rem = sizeof (freepool->embedded_data); - freepool->embedded_pool.data = freepool->embedded_data; - - VG (VALGRIND_MAKE_MEM_NOACCESS (freepool->embedded_data, sizeof (freepool->embedded_data))); -} - -void -_cairo_freepool_fini (cairo_freepool_t *freepool) -{ - cairo_freelist_pool_t *pool; - - pool = freepool->pools; - while (pool != &freepool->embedded_pool) { - cairo_freelist_pool_t *next = pool->next; - free (pool); - pool = next; - } - - pool = freepool->freepools; - while (pool != NULL) { - cairo_freelist_pool_t *next = pool->next; - free (pool); - pool = next; - } - - VG (VALGRIND_MAKE_MEM_NOACCESS (freepool, sizeof (freepool))); -} - -void * -_cairo_freepool_alloc_from_new_pool (cairo_freepool_t *freepool) -{ - cairo_freelist_pool_t *pool; - int poolsize; - - if (freepool->freepools != NULL) { - pool = freepool->freepools; - freepool->freepools = pool->next; - - poolsize = pool->size; - } else { - if (freepool->pools != &freepool->embedded_pool) - poolsize = 2 * freepool->pools->size; - else - poolsize = (128 * freepool->nodesize + 8191) & -8192; - - pool = malloc (sizeof (cairo_freelist_pool_t) + poolsize); - if (unlikely (pool == NULL)) - return pool; - - pool->size = poolsize; - } - - pool->next = freepool->pools; - freepool->pools = pool; - - pool->rem = poolsize - freepool->nodesize; - pool->data = (uint8_t *) (pool + 1) + freepool->nodesize; - - VG (VALGRIND_MAKE_MEM_NOACCESS (pool->data, pool->rem)); - - return pool + 1; -} - -cairo_status_t -_cairo_freepool_alloc_array (cairo_freepool_t *freepool, - int count, - void **array) -{ - int i; - - for (i = 0; i < count; i++) { - cairo_freelist_node_t *node; - - node = freepool->first_free_node; - if (likely (node != NULL)) { - VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); - freepool->first_free_node = node->next; - VG (VALGRIND_MAKE_MEM_UNDEFINED (node, freepool->nodesize)); - } else { - node = _cairo_freepool_alloc_from_pool (freepool); - if (unlikely (node == NULL)) - goto CLEANUP; - } - - array[i] = node; - } - - return CAIRO_STATUS_SUCCESS; - - CLEANUP: - while (i--) - _cairo_freepool_free (freepool, array[i]); - - return _cairo_error (CAIRO_STATUS_NO_MEMORY); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-font.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-font.c deleted file mode 100644 index 87e733bb769..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-font.c +++ /dev/null @@ -1,3577 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2000 Keith Packard - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Graydon Hoare - * Owen Taylor - * Keith Packard - * Carl Worth - */ - -#define _BSD_SOURCE /* for strdup() */ -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-ft-private.h" -#include "cairo-pattern-private.h" -#include "cairo-pixman-private.h" - -#include - -#include "cairo-fontconfig-private.h" - -#include -#include FT_FREETYPE_H -#include FT_OUTLINE_H -#include FT_IMAGE_H -#include FT_BITMAP_H -#include FT_TRUETYPE_TABLES_H -#include FT_XFREE86_H -#if HAVE_FT_GLYPHSLOT_EMBOLDEN -#include FT_SYNTHESIS_H -#endif - -#if HAVE_FT_LIBRARY_SETLCDFILTER -#include FT_LCD_FILTER_H -#endif - -#if HAVE_UNISTD_H -#include -#else -#define access(p, m) 0 -#endif - -/* Fontconfig version older than 2.6 didn't have these options */ -#ifndef FC_LCD_FILTER -#define FC_LCD_FILTER "lcdfilter" -#endif -/* Some Ubuntu versions defined FC_LCD_FILTER without defining the following */ -#ifndef FC_LCD_NONE -#define FC_LCD_NONE 0 -#define FC_LCD_DEFAULT 1 -#define FC_LCD_LIGHT 2 -#define FC_LCD_LEGACY 3 -#endif - -/* FreeType version older than 2.3.5(?) didn't have these options */ -#ifndef FT_LCD_FILTER_NONE -#define FT_LCD_FILTER_NONE 0 -#define FT_LCD_FILTER_DEFAULT 1 -#define FT_LCD_FILTER_LIGHT 2 -#define FT_LCD_FILTER_LEGACY 16 -#endif - -#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0)) -#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0) -#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0)) -#define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0) - -/* This is the max number of FT_face objects we keep open at once - */ -#define MAX_OPEN_FACES 10 - -/** - * SECTION:cairo-ft - * @Title: FreeType Fonts - * @Short_Description: Font support for FreeType - * @See_Also: #cairo_font_face_t - * - * The FreeType font backend is primarily used to render text on GNU/Linux - * systems, but can be used on other platforms too. - **/ - -/** - * CAIRO_HAS_FT_FONT: - * - * Defined if the FreeType font backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.0 - **/ - -/** - * CAIRO_HAS_FC_FONT: - * - * Defined if the Fontconfig-specific functions of the FreeType font backend - * are available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.10 - **/ - -/* - * The simple 2x2 matrix is converted into separate scale and shape - * factors so that hinting works right - */ - -typedef struct _cairo_ft_font_transform { - double x_scale, y_scale; - double shape[2][2]; -} cairo_ft_font_transform_t; - -/* - * We create an object that corresponds to a single font on the disk; - * (identified by a filename/id pair) these are shared between all - * fonts using that file. For cairo_ft_font_face_create_for_ft_face(), we - * just create a one-off version with a permanent face value. - */ - -typedef struct _cairo_ft_font_face cairo_ft_font_face_t; - -struct _cairo_ft_unscaled_font { - cairo_unscaled_font_t base; - - cairo_bool_t from_face; /* was the FT_Face provided by user? */ - FT_Face face; /* provided or cached face */ - - /* only set if from_face is false */ - char *filename; - int id; - - /* We temporarily scale the unscaled font as needed */ - cairo_bool_t have_scale; - cairo_matrix_t current_scale; - double x_scale; /* Extracted X scale factor */ - double y_scale; /* Extracted Y scale factor */ - cairo_bool_t have_shape; /* true if the current scale has a non-scale component*/ - cairo_matrix_t current_shape; - FT_Matrix Current_Shape; - - cairo_mutex_t mutex; - int lock_count; - - cairo_ft_font_face_t *faces; /* Linked list of faces for this font */ -}; - -static int -_cairo_ft_unscaled_font_keys_equal (const void *key_a, - const void *key_b); - -static void -_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled); - -typedef struct _cairo_ft_options { - cairo_font_options_t base; - unsigned int load_flags; /* flags for FT_Load_Glyph */ - unsigned int synth_flags; -} cairo_ft_options_t; - -struct _cairo_ft_font_face { - cairo_font_face_t base; - - cairo_ft_unscaled_font_t *unscaled; - cairo_ft_options_t ft_options; - cairo_ft_font_face_t *next; - -#if CAIRO_HAS_FC_FONT - FcPattern *pattern; /* if pattern is set, the above fields will be NULL */ - cairo_font_face_t *resolved_font_face; - FcConfig *resolved_config; -#endif -}; - -static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend; - -#if CAIRO_HAS_FC_FONT -static cairo_status_t -_cairo_ft_font_options_substitute (const cairo_font_options_t *options, - FcPattern *pattern); - -static cairo_font_face_t * -_cairo_ft_resolve_pattern (FcPattern *pattern, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options); - -#endif - -/* - * We maintain a hash table to map file/id => #cairo_ft_unscaled_font_t. - * The hash table itself isn't limited in size. However, we limit the - * number of FT_Face objects we keep around; when we've exceeded that - * limit and need to create a new FT_Face, we dump the FT_Face from a - * random #cairo_ft_unscaled_font_t which has an unlocked FT_Face, (if - * there are any). - */ - -typedef struct _cairo_ft_unscaled_font_map { - cairo_hash_table_t *hash_table; - FT_Library ft_library; - int num_open_faces; -} cairo_ft_unscaled_font_map_t; - -static cairo_ft_unscaled_font_map_t *cairo_ft_unscaled_font_map = NULL; - - -static FT_Face -_cairo_ft_unscaled_font_lock_face (cairo_ft_unscaled_font_t *unscaled); - -static void -_cairo_ft_unscaled_font_unlock_face (cairo_ft_unscaled_font_t *unscaled); - -static cairo_bool_t -_cairo_ft_scaled_font_is_vertical (cairo_scaled_font_t *scaled_font); - - -static void -_font_map_release_face_lock_held (cairo_ft_unscaled_font_map_t *font_map, - cairo_ft_unscaled_font_t *unscaled) -{ - if (unscaled->face) { - FT_Done_Face (unscaled->face); - unscaled->face = NULL; - unscaled->have_scale = FALSE; - - font_map->num_open_faces--; - } -} - -static cairo_status_t -_cairo_ft_unscaled_font_map_create (void) -{ - cairo_ft_unscaled_font_map_t *font_map; - - /* This function is only intended to be called from - * _cairo_ft_unscaled_font_map_lock. So we'll crash if we can - * detect some other call path. */ - assert (cairo_ft_unscaled_font_map == NULL); - - font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t)); - if (unlikely (font_map == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font_map->hash_table = - _cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal); - - if (unlikely (font_map->hash_table == NULL)) - goto FAIL; - - if (unlikely (FT_Init_FreeType (&font_map->ft_library))) - goto FAIL; - - font_map->num_open_faces = 0; - - cairo_ft_unscaled_font_map = font_map; - return CAIRO_STATUS_SUCCESS; - -FAIL: - if (font_map->hash_table) - _cairo_hash_table_destroy (font_map->hash_table); - free (font_map); - - return _cairo_error (CAIRO_STATUS_NO_MEMORY); -} - - -static void -_cairo_ft_unscaled_font_map_pluck_entry (void *entry, void *closure) -{ - cairo_ft_unscaled_font_t *unscaled = entry; - cairo_ft_unscaled_font_map_t *font_map = closure; - - _cairo_hash_table_remove (font_map->hash_table, - &unscaled->base.hash_entry); - - if (! unscaled->from_face) - _font_map_release_face_lock_held (font_map, unscaled); - - _cairo_ft_unscaled_font_fini (unscaled); - free (unscaled); -} - -static void -_cairo_ft_unscaled_font_map_destroy (void) -{ - cairo_ft_unscaled_font_map_t *font_map; - - CAIRO_MUTEX_LOCK (_cairo_ft_unscaled_font_map_mutex); - font_map = cairo_ft_unscaled_font_map; - cairo_ft_unscaled_font_map = NULL; - CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); - - if (font_map != NULL) { - _cairo_hash_table_foreach (font_map->hash_table, - _cairo_ft_unscaled_font_map_pluck_entry, - font_map); - assert (font_map->num_open_faces == 0); - - FT_Done_FreeType (font_map->ft_library); - - _cairo_hash_table_destroy (font_map->hash_table); - - free (font_map); - } -} - -static cairo_ft_unscaled_font_map_t * -_cairo_ft_unscaled_font_map_lock (void) -{ - CAIRO_MUTEX_LOCK (_cairo_ft_unscaled_font_map_mutex); - - if (unlikely (cairo_ft_unscaled_font_map == NULL)) { - if (unlikely (_cairo_ft_unscaled_font_map_create ())) { - CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); - return NULL; - } - } - - return cairo_ft_unscaled_font_map; -} - -static void -_cairo_ft_unscaled_font_map_unlock (void) -{ - CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); -} - -static void -_cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key, - cairo_bool_t from_face, - char *filename, - int id, - FT_Face face) -{ - unsigned long hash; - - key->from_face = from_face; - key->filename = filename; - key->id = id; - key->face = face; - - hash = _cairo_hash_string (filename); - /* the constants are just arbitrary primes */ - hash += ((unsigned long) id) * 1607; - hash += ((unsigned long) face) * 2137; - - key->base.hash_entry.hash = hash; -} - -/** - * _cairo_ft_unscaled_font_init: - * - * Initialize a #cairo_ft_unscaled_font_t. - * - * There are two basic flavors of #cairo_ft_unscaled_font_t, one - * created from an FT_Face and the other created from a filename/id - * pair. These two flavors are identified as from_face and !from_face. - * - * To initialize a from_face font, pass filename==%NULL, id=0 and the - * desired face. - * - * To initialize a !from_face font, pass the filename/id as desired - * and face==%NULL. - * - * Note that the code handles these two flavors in very distinct - * ways. For example there is a hash_table mapping - * filename/id->#cairo_unscaled_font_t in the !from_face case, but no - * parallel in the from_face case, (where the calling code would have - * to do its own mapping to ensure similar sharing). - **/ -static cairo_status_t -_cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled, - cairo_bool_t from_face, - const char *filename, - int id, - FT_Face face) -{ - _cairo_unscaled_font_init (&unscaled->base, - &cairo_ft_unscaled_font_backend); - - if (from_face) { - unscaled->from_face = TRUE; - _cairo_ft_unscaled_font_init_key (unscaled, TRUE, NULL, 0, face); - } else { - char *filename_copy; - - unscaled->from_face = FALSE; - unscaled->face = NULL; - - filename_copy = strdup (filename); - if (unlikely (filename_copy == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_ft_unscaled_font_init_key (unscaled, FALSE, filename_copy, id, NULL); - } - - unscaled->have_scale = FALSE; - CAIRO_MUTEX_INIT (unscaled->mutex); - unscaled->lock_count = 0; - - unscaled->faces = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_ft_unscaled_font_fini: - * - * Free all data associated with a #cairo_ft_unscaled_font_t. - * - * CAUTION: The unscaled->face field must be %NULL before calling this - * function. This is because the #cairo_ft_unscaled_font_t_map keeps a - * count of these faces (font_map->num_open_faces) so it maintains the - * unscaled->face field while it has its lock held. See - * _font_map_release_face_lock_held(). - **/ -static void -_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled) -{ - assert (unscaled->face == NULL); - - free (unscaled->filename); - unscaled->filename = NULL; - - CAIRO_MUTEX_FINI (unscaled->mutex); -} - -static int -_cairo_ft_unscaled_font_keys_equal (const void *key_a, - const void *key_b) -{ - const cairo_ft_unscaled_font_t *unscaled_a = key_a; - const cairo_ft_unscaled_font_t *unscaled_b = key_b; - - if (unscaled_a->id == unscaled_b->id && - unscaled_a->from_face == unscaled_b->from_face) - { - if (unscaled_a->from_face) - return unscaled_a->face == unscaled_b->face; - - if (unscaled_a->filename == NULL && unscaled_b->filename == NULL) - return TRUE; - else if (unscaled_a->filename == NULL || unscaled_b->filename == NULL) - return FALSE; - else - return (strcmp (unscaled_a->filename, unscaled_b->filename) == 0); - } - - return FALSE; -} - -/* Finds or creates a #cairo_ft_unscaled_font_t for the filename/id from - * pattern. Returns a new reference to the unscaled font. - */ -static cairo_status_t -_cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face, - char *filename, - int id, - FT_Face font_face, - cairo_ft_unscaled_font_t **out) -{ - cairo_ft_unscaled_font_t key, *unscaled; - cairo_ft_unscaled_font_map_t *font_map; - cairo_status_t status; - - font_map = _cairo_ft_unscaled_font_map_lock (); - if (unlikely (font_map == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_ft_unscaled_font_init_key (&key, from_face, filename, id, font_face); - - /* Return existing unscaled font if it exists in the hash table. */ - unscaled = _cairo_hash_table_lookup (font_map->hash_table, - &key.base.hash_entry); - if (unscaled != NULL) { - _cairo_unscaled_font_reference (&unscaled->base); - goto DONE; - } - - /* Otherwise create it and insert into hash table. */ - unscaled = malloc (sizeof (cairo_ft_unscaled_font_t)); - if (unlikely (unscaled == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto UNWIND_FONT_MAP_LOCK; - } - - status = _cairo_ft_unscaled_font_init (unscaled, from_face, filename, id, font_face); - if (unlikely (status)) - goto UNWIND_UNSCALED_MALLOC; - - assert (unscaled->base.hash_entry.hash == key.base.hash_entry.hash); - status = _cairo_hash_table_insert (font_map->hash_table, - &unscaled->base.hash_entry); - if (unlikely (status)) - goto UNWIND_UNSCALED_FONT_INIT; - -DONE: - _cairo_ft_unscaled_font_map_unlock (); - *out = unscaled; - return CAIRO_STATUS_SUCCESS; - -UNWIND_UNSCALED_FONT_INIT: - _cairo_ft_unscaled_font_fini (unscaled); -UNWIND_UNSCALED_MALLOC: - free (unscaled); -UNWIND_FONT_MAP_LOCK: - _cairo_ft_unscaled_font_map_unlock (); - return status; -} - - -#if CAIRO_HAS_FC_FONT -static cairo_status_t -_cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern, - cairo_ft_unscaled_font_t **out) -{ - FT_Face font_face = NULL; - char *filename = NULL; - int id = 0; - FcResult ret; - - ret = FcPatternGetFTFace (pattern, FC_FT_FACE, 0, &font_face); - if (ret == FcResultMatch) - goto DONE; - if (ret == FcResultOutOfMemory) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - ret = FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **) &filename); - if (ret == FcResultOutOfMemory) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - if (ret == FcResultMatch) { - if (access (filename, R_OK) == 0) { - /* If FC_INDEX is not set, we just use 0 */ - ret = FcPatternGetInteger (pattern, FC_INDEX, 0, &id); - if (ret == FcResultOutOfMemory) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - goto DONE; - } else - return _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND); - } - - /* The pattern contains neither a face nor a filename, resolve it later. */ - *out = NULL; - return CAIRO_STATUS_SUCCESS; - -DONE: - return _cairo_ft_unscaled_font_create_internal (font_face != NULL, - filename, id, font_face, - out); -} -#endif - -static cairo_status_t -_cairo_ft_unscaled_font_create_from_face (FT_Face face, - cairo_ft_unscaled_font_t **out) -{ - return _cairo_ft_unscaled_font_create_internal (TRUE, NULL, 0, face, out); -} - -static cairo_bool_t -_cairo_ft_unscaled_font_destroy (void *abstract_font) -{ - cairo_ft_unscaled_font_t *unscaled = abstract_font; - cairo_ft_unscaled_font_map_t *font_map; - - font_map = _cairo_ft_unscaled_font_map_lock (); - /* All created objects must have been mapped in the font map. */ - assert (font_map != NULL); - - if (! _cairo_reference_count_dec_and_test (&unscaled->base.ref_count)) { - /* somebody recreated the font whilst we waited for the lock */ - _cairo_ft_unscaled_font_map_unlock (); - return FALSE; - } - - _cairo_hash_table_remove (font_map->hash_table, - &unscaled->base.hash_entry); - - if (unscaled->from_face) { - /* See comments in _ft_font_face_destroy about the "zombie" state - * for a _ft_font_face. - */ - if (unscaled->faces && unscaled->faces->unscaled == NULL) { - assert (unscaled->faces->next == NULL); - cairo_font_face_destroy (&unscaled->faces->base); - } - } else { - _font_map_release_face_lock_held (font_map, unscaled); - } - unscaled->face = NULL; - - _cairo_ft_unscaled_font_map_unlock (); - - _cairo_ft_unscaled_font_fini (unscaled); - return TRUE; -} - -static cairo_bool_t -_has_unlocked_face (const void *entry) -{ - const cairo_ft_unscaled_font_t *unscaled = entry; - - return (!unscaled->from_face && unscaled->lock_count == 0 && unscaled->face); -} - -/* Ensures that an unscaled font has a face object. If we exceed - * MAX_OPEN_FACES, try to close some. - * - * This differs from _cairo_ft_scaled_font_lock_face in that it doesn't - * set the scale on the face, but just returns it at the last scale. - */ -static cairo_warn FT_Face -_cairo_ft_unscaled_font_lock_face (cairo_ft_unscaled_font_t *unscaled) -{ - cairo_ft_unscaled_font_map_t *font_map; - FT_Face face = NULL; - - CAIRO_MUTEX_LOCK (unscaled->mutex); - unscaled->lock_count++; - - if (unscaled->face) - return unscaled->face; - - /* If this unscaled font was created from an FT_Face then we just - * returned it above. */ - assert (!unscaled->from_face); - - font_map = _cairo_ft_unscaled_font_map_lock (); - { - assert (font_map != NULL); - - while (font_map->num_open_faces >= MAX_OPEN_FACES) - { - cairo_ft_unscaled_font_t *entry; - - entry = _cairo_hash_table_random_entry (font_map->hash_table, - _has_unlocked_face); - if (entry == NULL) - break; - - _font_map_release_face_lock_held (font_map, entry); - } - } - _cairo_ft_unscaled_font_map_unlock (); - - if (FT_New_Face (font_map->ft_library, - unscaled->filename, - unscaled->id, - &face) != FT_Err_Ok) - { - unscaled->lock_count--; - CAIRO_MUTEX_UNLOCK (unscaled->mutex); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - unscaled->face = face; - - font_map->num_open_faces++; - - return face; -} - - -/* Unlock unscaled font locked with _cairo_ft_unscaled_font_lock_face - */ -static void -_cairo_ft_unscaled_font_unlock_face (cairo_ft_unscaled_font_t *unscaled) -{ - assert (unscaled->lock_count > 0); - - unscaled->lock_count--; - - CAIRO_MUTEX_UNLOCK (unscaled->mutex); -} - - -static cairo_status_t -_compute_transform (cairo_ft_font_transform_t *sf, - cairo_matrix_t *scale, - cairo_ft_unscaled_font_t *unscaled) -{ - cairo_status_t status; - double x_scale, y_scale; - cairo_matrix_t normalized = *scale; - - /* The font matrix has x and y "scale" components which we extract and - * use as character scale values. These influence the way freetype - * chooses hints, as well as selecting different bitmaps in - * hand-rendered fonts. We also copy the normalized matrix to - * freetype's transformation. - */ - - status = _cairo_matrix_compute_basis_scale_factors (scale, - &x_scale, &y_scale, - 1); - if (unlikely (status)) - return status; - - /* FreeType docs say this about x_scale and y_scale: - * "A character width or height smaller than 1pt is set to 1pt;" - * So, we cap them from below at 1.0 and let the FT transform - * take care of sub-1.0 scaling. */ - if (x_scale < 1.0) - x_scale = 1.0; - if (y_scale < 1.0) - y_scale = 1.0; - - if (unscaled && (unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) == 0) { - double min_distance = DBL_MAX; - cairo_bool_t magnify = TRUE; - int i; - double best_x_size = 0; - double best_y_size = 0; - - for (i = 0; i < unscaled->face->num_fixed_sizes; i++) { - double x_size = unscaled->face->available_sizes[i].x_ppem / 64.; - double y_size = unscaled->face->available_sizes[i].y_ppem / 64.; - double distance = y_size - y_scale; - - /* - * distance is positive if current strike is larger than desired - * size, and negative if smaller. - * - * We like to prefer down-scaling to upscaling. - */ - - if ((magnify && distance >= 0) || fabs (distance) <= min_distance) { - magnify = distance < 0; - min_distance = fabs (distance); - best_x_size = x_size; - best_y_size = y_size; - } - } - - x_scale = best_x_size; - y_scale = best_y_size; - } - - sf->x_scale = x_scale; - sf->y_scale = y_scale; - - cairo_matrix_scale (&normalized, 1.0 / x_scale, 1.0 / y_scale); - - _cairo_matrix_get_affine (&normalized, - &sf->shape[0][0], &sf->shape[0][1], - &sf->shape[1][0], &sf->shape[1][1], - NULL, NULL); - - return CAIRO_STATUS_SUCCESS; -} - -/* Temporarily scales an unscaled font to the give scale. We catch - * scaling to the same size, since changing a FT_Face is expensive. - */ -static cairo_status_t -_cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled, - cairo_matrix_t *scale) -{ - cairo_status_t status; - cairo_ft_font_transform_t sf; - FT_Matrix mat; - FT_Error error; - - assert (unscaled->face != NULL); - - if (unscaled->have_scale && - scale->xx == unscaled->current_scale.xx && - scale->yx == unscaled->current_scale.yx && - scale->xy == unscaled->current_scale.xy && - scale->yy == unscaled->current_scale.yy) - return CAIRO_STATUS_SUCCESS; - - unscaled->have_scale = TRUE; - unscaled->current_scale = *scale; - - status = _compute_transform (&sf, scale, unscaled); - if (unlikely (status)) - return status; - - unscaled->x_scale = sf.x_scale; - unscaled->y_scale = sf.y_scale; - - mat.xx = DOUBLE_TO_16_16(sf.shape[0][0]); - mat.yx = - DOUBLE_TO_16_16(sf.shape[0][1]); - mat.xy = - DOUBLE_TO_16_16(sf.shape[1][0]); - mat.yy = DOUBLE_TO_16_16(sf.shape[1][1]); - - unscaled->have_shape = (mat.xx != 0x10000 || - mat.yx != 0x00000 || - mat.xy != 0x00000 || - mat.yy != 0x10000); - - unscaled->Current_Shape = mat; - cairo_matrix_init (&unscaled->current_shape, - sf.shape[0][0], sf.shape[0][1], - sf.shape[1][0], sf.shape[1][1], - 0.0, 0.0); - - FT_Set_Transform(unscaled->face, &mat, NULL); - - error = FT_Set_Char_Size (unscaled->face, - sf.x_scale * 64.0 + .5, - sf.y_scale * 64.0 + .5, - 0, 0); - if (error) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} - -/* we sometimes need to convert the glyph bitmap in a FT_GlyphSlot - * into a different format. For example, we want to convert a - * FT_PIXEL_MODE_LCD or FT_PIXEL_MODE_LCD_V bitmap into a 32-bit - * ARGB or ABGR bitmap. - * - * this function prepares a target descriptor for this operation. - * - * input :: target bitmap descriptor. The function will set its - * 'width', 'rows' and 'pitch' fields, and only these - * - * slot :: the glyph slot containing the source bitmap. this - * function assumes that slot->format == FT_GLYPH_FORMAT_BITMAP - * - * mode :: the requested final rendering mode. supported values are - * MONO, NORMAL (i.e. gray), LCD and LCD_V - * - * the function returns the size in bytes of the corresponding buffer, - * it's up to the caller to allocate the corresponding memory block - * before calling _fill_xrender_bitmap - * - * it also returns -1 in case of error (e.g. incompatible arguments, - * like trying to convert a gray bitmap into a monochrome one) - */ -static int -_compute_xrender_bitmap_size(FT_Bitmap *target, - FT_GlyphSlot slot, - FT_Render_Mode mode) -{ - FT_Bitmap *ftbit; - int width, height, pitch; - - if (slot->format != FT_GLYPH_FORMAT_BITMAP) - return -1; - - /* compute the size of the final bitmap */ - ftbit = &slot->bitmap; - - width = ftbit->width; - height = ftbit->rows; - pitch = (width + 3) & ~3; - - switch (ftbit->pixel_mode) { - case FT_PIXEL_MODE_MONO: - if (mode == FT_RENDER_MODE_MONO) { - pitch = (((width + 31) & ~31) >> 3); - break; - } - /* fall-through */ - - case FT_PIXEL_MODE_GRAY: - if (mode == FT_RENDER_MODE_LCD || - mode == FT_RENDER_MODE_LCD_V) - { - /* each pixel is replicated into a 32-bit ARGB value */ - pitch = width * 4; - } - break; - - case FT_PIXEL_MODE_LCD: - if (mode != FT_RENDER_MODE_LCD) - return -1; - - /* horz pixel triplets are packed into 32-bit ARGB values */ - width /= 3; - pitch = width * 4; - break; - - case FT_PIXEL_MODE_LCD_V: - if (mode != FT_RENDER_MODE_LCD_V) - return -1; - - /* vert pixel triplets are packed into 32-bit ARGB values */ - height /= 3; - pitch = width * 4; - break; - - default: /* unsupported source format */ - return -1; - } - - target->width = width; - target->rows = height; - target->pitch = pitch; - target->buffer = NULL; - - return pitch * height; -} - -/* this functions converts the glyph bitmap found in a FT_GlyphSlot - * into a different format (see _compute_xrender_bitmap_size) - * - * you should call this function after _compute_xrender_bitmap_size - * - * target :: target bitmap descriptor. Note that its 'buffer' pointer - * must point to memory allocated by the caller - * - * slot :: the glyph slot containing the source bitmap - * - * mode :: the requested final rendering mode - * - * bgr :: boolean, set if BGR or VBGR pixel ordering is needed - */ -static void -_fill_xrender_bitmap(FT_Bitmap *target, - FT_GlyphSlot slot, - FT_Render_Mode mode, - int bgr) -{ - FT_Bitmap *ftbit = &slot->bitmap; - unsigned char *srcLine = ftbit->buffer; - unsigned char *dstLine = target->buffer; - int src_pitch = ftbit->pitch; - int width = target->width; - int height = target->rows; - int pitch = target->pitch; - int subpixel; - int h; - - subpixel = (mode == FT_RENDER_MODE_LCD || - mode == FT_RENDER_MODE_LCD_V); - - if (src_pitch < 0) - srcLine -= src_pitch * (ftbit->rows - 1); - - target->pixel_mode = ftbit->pixel_mode; - - switch (ftbit->pixel_mode) { - case FT_PIXEL_MODE_MONO: - if (subpixel) { - /* convert mono to ARGB32 values */ - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { - int x; - - for (x = 0; x < width; x++) { - if (srcLine[(x >> 3)] & (0x80 >> (x & 7))) - ((unsigned int *) dstLine)[x] = 0xffffffffU; - } - } - target->pixel_mode = FT_PIXEL_MODE_LCD; - - } else if (mode == FT_RENDER_MODE_NORMAL) { - /* convert mono to 8-bit gray */ - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { - int x; - - for (x = 0; x < width; x++) { - if (srcLine[(x >> 3)] & (0x80 >> (x & 7))) - dstLine[x] = 0xff; - } - } - target->pixel_mode = FT_PIXEL_MODE_GRAY; - - } else { - /* copy mono to mono */ - - int bytes = (width + 7) >> 3; - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) - memcpy (dstLine, srcLine, bytes); - } - break; - - case FT_PIXEL_MODE_GRAY: - if (subpixel) { - /* convert gray to ARGB32 values */ - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { - int x; - unsigned int *dst = (unsigned int *) dstLine; - - for (x = 0; x < width; x++) { - unsigned int pix = srcLine[x]; - - pix |= (pix << 8); - pix |= (pix << 16); - - dst[x] = pix; - } - } - target->pixel_mode = FT_PIXEL_MODE_LCD; - } else { - /* copy gray into gray */ - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) - memcpy (dstLine, srcLine, width); - } - break; - - case FT_PIXEL_MODE_LCD: - if (!bgr) { - /* convert horizontal RGB into ARGB32 */ - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { - int x; - unsigned char *src = srcLine; - unsigned int *dst = (unsigned int *) dstLine; - - for (x = 0; x < width; x++, src += 3) { - unsigned int pix; - - pix = ((unsigned int)src[0] << 16) | - ((unsigned int)src[1] << 8) | - ((unsigned int)src[2] ) | - ((unsigned int)src[1] << 24) ; - - dst[x] = pix; - } - } - } else { - /* convert horizontal BGR into ARGB32 */ - - for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { - - int x; - unsigned char *src = srcLine; - unsigned int *dst = (unsigned int *) dstLine; - - for (x = 0; x < width; x++, src += 3) { - unsigned int pix; - - pix = ((unsigned int)src[2] << 16) | - ((unsigned int)src[1] << 8) | - ((unsigned int)src[0] ) | - ((unsigned int)src[1] << 24) ; - - dst[x] = pix; - } - } - } - break; - - default: /* FT_PIXEL_MODE_LCD_V */ - /* convert vertical RGB into ARGB32 */ - if (!bgr) { - - for (h = height; h > 0; h--, srcLine += 3 * src_pitch, dstLine += pitch) { - int x; - unsigned char* src = srcLine; - unsigned int* dst = (unsigned int *) dstLine; - - for (x = 0; x < width; x++, src += 1) { - unsigned int pix; - pix = ((unsigned int)src[0] << 16) | - ((unsigned int)src[src_pitch] << 8) | - ((unsigned int)src[src_pitch*2] ) | - ((unsigned int)src[src_pitch] << 24) ; - dst[x] = pix; - } - } - } else { - - for (h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch) { - int x; - unsigned char *src = srcLine; - unsigned int *dst = (unsigned int *) dstLine; - - for (x = 0; x < width; x++, src += 1) { - unsigned int pix; - - pix = ((unsigned int)src[src_pitch * 2] << 16) | - ((unsigned int)src[src_pitch] << 8) | - ((unsigned int)src[0] ) | - ((unsigned int)src[src_pitch] << 24) ; - - dst[x] = pix; - } - } - } - } -} - - -/* Fills in val->image with an image surface created from @bitmap - */ -static cairo_status_t -_get_bitmap_surface (FT_Bitmap *bitmap, - FT_Library library, - cairo_bool_t own_buffer, - cairo_font_options_t *font_options, - cairo_image_surface_t **surface) -{ - unsigned int width, height; - unsigned char *data; - int format = CAIRO_FORMAT_A8; - int stride; - cairo_image_surface_t *image; - cairo_bool_t component_alpha = FALSE; - - width = bitmap->width; - height = bitmap->rows; - - if (width == 0 || height == 0) { - *surface = (cairo_image_surface_t *) - cairo_image_surface_create_for_data (NULL, format, 0, 0, 0); - return (*surface)->base.status; - } - - switch (bitmap->pixel_mode) { - case FT_PIXEL_MODE_MONO: - stride = (((width + 31) & ~31) >> 3); - if (own_buffer) { - data = bitmap->buffer; - assert (stride == bitmap->pitch); - } else { - data = _cairo_malloc_ab (height, stride); - if (!data) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (stride == bitmap->pitch) { - memcpy (data, bitmap->buffer, stride * height); - } else { - int i; - unsigned char *source, *dest; - - source = bitmap->buffer; - dest = data; - for (i = height; i; i--) { - memcpy (dest, source, bitmap->pitch); - memset (dest + bitmap->pitch, '\0', stride - bitmap->pitch); - - source += bitmap->pitch; - dest += stride; - } - } - } - -#ifndef WORDS_BIGENDIAN - { - uint8_t *d = data; - int count = stride * height; - - while (count--) { - *d = CAIRO_BITSWAP8 (*d); - d++; - } - } -#endif - format = CAIRO_FORMAT_A1; - break; - - case FT_PIXEL_MODE_LCD: - case FT_PIXEL_MODE_LCD_V: - case FT_PIXEL_MODE_GRAY: - if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL || - bitmap->pixel_mode == FT_PIXEL_MODE_GRAY) - { - stride = bitmap->pitch; - - /* We don't support stride not multiple of 4. */ - if (stride & 3) - { - assert (!own_buffer); - goto convert; - } - - if (own_buffer) { - data = bitmap->buffer; - } else { - data = _cairo_malloc_ab (height, stride); - if (!data) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (data, bitmap->buffer, stride * height); - } - - format = CAIRO_FORMAT_A8; - } else { - data = bitmap->buffer; - stride = bitmap->pitch; - format = CAIRO_FORMAT_ARGB32; - component_alpha = TRUE; - } - break; -#ifdef FT_LOAD_COLOR - case FT_PIXEL_MODE_BGRA: - stride = width * 4; - if (own_buffer) { - data = bitmap->buffer; - } else { - data = _cairo_malloc_ab (height, stride); - if (!data) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (data, bitmap->buffer, stride * height); - } - format = CAIRO_FORMAT_ARGB32; - break; -#endif - case FT_PIXEL_MODE_GRAY2: - case FT_PIXEL_MODE_GRAY4: - convert: - if (!own_buffer && library) - { - /* This is pretty much the only case that we can get in here. */ - /* Convert to 8bit grayscale. */ - - FT_Bitmap tmp; - FT_Int align; - - format = CAIRO_FORMAT_A8; - - align = cairo_format_stride_for_width (format, bitmap->width); - - FT_Bitmap_New( &tmp ); - - if (FT_Bitmap_Convert( library, bitmap, &tmp, align )) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - FT_Bitmap_Done( library, bitmap ); - *bitmap = tmp; - - stride = bitmap->pitch; - data = _cairo_malloc_ab (height, stride); - if (!data) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (bitmap->num_grays != 256) - { - unsigned int x, y; - unsigned int mul = 255 / (bitmap->num_grays - 1); - FT_Byte *p = bitmap->buffer; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) - p[x] *= mul; - p += bitmap->pitch; - } - } - - memcpy (data, bitmap->buffer, stride * height); - break; - } - /* These could be triggered by very rare types of TrueType fonts */ - default: - if (own_buffer) - free (bitmap->buffer); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* XXX */ - *surface = image = (cairo_image_surface_t *) - cairo_image_surface_create_for_data (data, - format, - width, height, stride); - if (image->base.status) { - free (data); - return (*surface)->base.status; - } - - if (component_alpha) - pixman_image_set_component_alpha (image->pixman_image, TRUE); - - _cairo_image_surface_assume_ownership_of_data (image); - - _cairo_debug_check_image_surface_is_defined (&image->base); - - return CAIRO_STATUS_SUCCESS; -} - -/* Converts an outline FT_GlyphSlot into an image - * - * This could go through _render_glyph_bitmap as well, letting - * FreeType convert the outline to a bitmap, but doing it ourselves - * has two minor advantages: first, we save a copy of the bitmap - * buffer: we can directly use the buffer that FreeType renders - * into. - * - * Second, it may help when we add support for subpixel - * rendering: the Xft code does it this way. (Keith thinks that - * it may also be possible to get the subpixel rendering with - * FT_Render_Glyph: something worth looking into in more detail - * when we add subpixel support. If so, we may want to eliminate - * this version of the code path entirely. - */ -static cairo_status_t -_render_glyph_outline (FT_Face face, - cairo_font_options_t *font_options, - cairo_image_surface_t **surface) -{ - int rgba = FC_RGBA_UNKNOWN; - int lcd_filter = FT_LCD_FILTER_LEGACY; - FT_GlyphSlot glyphslot = face->glyph; - FT_Outline *outline = &glyphslot->outline; - FT_Bitmap bitmap; - FT_BBox cbox; - unsigned int width, height; - cairo_status_t status; - FT_Error fterror; - FT_Library library = glyphslot->library; - FT_Render_Mode render_mode = FT_RENDER_MODE_NORMAL; - - switch (font_options->antialias) { - case CAIRO_ANTIALIAS_NONE: - render_mode = FT_RENDER_MODE_MONO; - break; - - case CAIRO_ANTIALIAS_SUBPIXEL: - case CAIRO_ANTIALIAS_BEST: - switch (font_options->subpixel_order) { - case CAIRO_SUBPIXEL_ORDER_DEFAULT: - case CAIRO_SUBPIXEL_ORDER_RGB: - case CAIRO_SUBPIXEL_ORDER_BGR: - render_mode = FT_RENDER_MODE_LCD; - break; - - case CAIRO_SUBPIXEL_ORDER_VRGB: - case CAIRO_SUBPIXEL_ORDER_VBGR: - render_mode = FT_RENDER_MODE_LCD_V; - break; - } - - switch (font_options->lcd_filter) { - case CAIRO_LCD_FILTER_NONE: - lcd_filter = FT_LCD_FILTER_NONE; - break; - case CAIRO_LCD_FILTER_DEFAULT: - case CAIRO_LCD_FILTER_INTRA_PIXEL: - lcd_filter = FT_LCD_FILTER_LEGACY; - break; - case CAIRO_LCD_FILTER_FIR3: - lcd_filter = FT_LCD_FILTER_LIGHT; - break; - case CAIRO_LCD_FILTER_FIR5: - lcd_filter = FT_LCD_FILTER_DEFAULT; - break; - } - - break; - - case CAIRO_ANTIALIAS_DEFAULT: - case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_GOOD: - case CAIRO_ANTIALIAS_FAST: - render_mode = FT_RENDER_MODE_NORMAL; - } - - FT_Outline_Get_CBox (outline, &cbox); - - cbox.xMin &= -64; - cbox.yMin &= -64; - cbox.xMax = (cbox.xMax + 63) & -64; - cbox.yMax = (cbox.yMax + 63) & -64; - - width = (unsigned int) ((cbox.xMax - cbox.xMin) >> 6); - height = (unsigned int) ((cbox.yMax - cbox.yMin) >> 6); - - if (width * height == 0) { - cairo_format_t format; - /* Looks like fb handles zero-sized images just fine */ - switch (render_mode) { - case FT_RENDER_MODE_MONO: - format = CAIRO_FORMAT_A1; - break; - case FT_RENDER_MODE_LCD: - case FT_RENDER_MODE_LCD_V: - format= CAIRO_FORMAT_ARGB32; - break; - case FT_RENDER_MODE_LIGHT: - case FT_RENDER_MODE_NORMAL: - case FT_RENDER_MODE_MAX: - default: - format = CAIRO_FORMAT_A8; - break; - } - - (*surface) = (cairo_image_surface_t *) - cairo_image_surface_create_for_data (NULL, format, 0, 0, 0); - if ((*surface)->base.status) - return (*surface)->base.status; - } else { - - int bitmap_size; - - switch (render_mode) { - case FT_RENDER_MODE_LCD: - if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_BGR) - rgba = FC_RGBA_BGR; - else - rgba = FC_RGBA_RGB; - break; - - case FT_RENDER_MODE_LCD_V: - if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_VBGR) - rgba = FC_RGBA_VBGR; - else - rgba = FC_RGBA_VRGB; - break; - - case FT_RENDER_MODE_MONO: - case FT_RENDER_MODE_LIGHT: - case FT_RENDER_MODE_NORMAL: - case FT_RENDER_MODE_MAX: - default: - break; - } - -#if HAVE_FT_LIBRARY_SETLCDFILTER - FT_Library_SetLcdFilter (library, lcd_filter); -#endif - - fterror = FT_Render_Glyph (face->glyph, render_mode); - -#if HAVE_FT_LIBRARY_SETLCDFILTER - FT_Library_SetLcdFilter (library, FT_LCD_FILTER_NONE); -#endif - - if (fterror != 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - bitmap_size = _compute_xrender_bitmap_size (&bitmap, - face->glyph, - render_mode); - if (bitmap_size < 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - bitmap.buffer = calloc (1, bitmap_size); - if (bitmap.buffer == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _fill_xrender_bitmap (&bitmap, face->glyph, render_mode, - (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR)); - - /* Note: - * _get_bitmap_surface will free bitmap.buffer if there is an error - */ - status = _get_bitmap_surface (&bitmap, NULL, TRUE, font_options, surface); - if (unlikely (status)) - return status; - - /* Note: the font's coordinate system is upside down from ours, so the - * Y coordinate of the control box needs to be negated. Moreover, device - * offsets are position of glyph origin relative to top left while xMin - * and yMax are offsets of top left relative to origin. Another negation. - */ - cairo_surface_set_device_offset (&(*surface)->base, - (double)-glyphslot->bitmap_left, - (double)+glyphslot->bitmap_top); - } - - return CAIRO_STATUS_SUCCESS; -} - -/* Converts a bitmap (or other) FT_GlyphSlot into an image */ -static cairo_status_t -_render_glyph_bitmap (FT_Face face, - cairo_font_options_t *font_options, - cairo_image_surface_t **surface) -{ - FT_GlyphSlot glyphslot = face->glyph; - cairo_status_t status; - FT_Error error; - - /* According to the FreeType docs, glyphslot->format could be - * something other than FT_GLYPH_FORMAT_OUTLINE or - * FT_GLYPH_FORMAT_BITMAP. Calling FT_Render_Glyph gives FreeType - * the opportunity to convert such to - * bitmap. FT_GLYPH_FORMAT_COMPOSITE will not be encountered since - * we avoid the FT_LOAD_NO_RECURSE flag. - */ - error = FT_Render_Glyph (glyphslot, FT_RENDER_MODE_NORMAL); - /* XXX ignoring all other errors for now. They are not fatal, typically - * just a glyph-not-found. */ - if (error == FT_Err_Out_Of_Memory) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _get_bitmap_surface (&glyphslot->bitmap, - glyphslot->library, - FALSE, font_options, - surface); - if (unlikely (status)) - return status; - - /* - * Note: the font's coordinate system is upside down from ours, so the - * Y coordinate of the control box needs to be negated. Moreover, device - * offsets are position of glyph origin relative to top left while - * bitmap_left and bitmap_top are offsets of top left relative to origin. - * Another negation. - */ - cairo_surface_set_device_offset (&(*surface)->base, - -glyphslot->bitmap_left, - +glyphslot->bitmap_top); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_transform_glyph_bitmap (cairo_matrix_t * shape, - cairo_image_surface_t ** surface) -{ - cairo_matrix_t original_to_transformed; - cairo_matrix_t transformed_to_original; - cairo_image_surface_t *old_image; - cairo_surface_t *image; - double x[4], y[4]; - double origin_x, origin_y; - int orig_width, orig_height; - int i; - int x_min, y_min, x_max, y_max; - int width, height; - cairo_status_t status; - cairo_surface_pattern_t pattern; - - /* We want to compute a transform that takes the origin - * (device_x_offset, device_y_offset) to 0,0, then applies - * the "shape" portion of the font transform - */ - original_to_transformed = *shape; - - cairo_surface_get_device_offset (&(*surface)->base, &origin_x, &origin_y); - orig_width = (*surface)->width; - orig_height = (*surface)->height; - - cairo_matrix_translate (&original_to_transformed, - -origin_x, -origin_y); - - /* Find the bounding box of the original bitmap under that - * transform - */ - x[0] = 0; y[0] = 0; - x[1] = orig_width; y[1] = 0; - x[2] = orig_width; y[2] = orig_height; - x[3] = 0; y[3] = orig_height; - - for (i = 0; i < 4; i++) - cairo_matrix_transform_point (&original_to_transformed, - &x[i], &y[i]); - - x_min = floor (x[0]); y_min = floor (y[0]); - x_max = ceil (x[0]); y_max = ceil (y[0]); - - for (i = 1; i < 4; i++) { - if (x[i] < x_min) - x_min = floor (x[i]); - else if (x[i] > x_max) - x_max = ceil (x[i]); - if (y[i] < y_min) - y_min = floor (y[i]); - else if (y[i] > y_max) - y_max = ceil (y[i]); - } - - /* Adjust the transform so that the bounding box starts at 0,0 ... - * this gives our final transform from original bitmap to transformed - * bitmap. - */ - original_to_transformed.x0 -= x_min; - original_to_transformed.y0 -= y_min; - - /* Create the transformed bitmap */ - width = x_max - x_min; - height = y_max - y_min; - - transformed_to_original = original_to_transformed; - status = cairo_matrix_invert (&transformed_to_original); - if (unlikely (status)) - return status; - - if ((*surface)->format == CAIRO_FORMAT_ARGB32 && - !pixman_image_get_component_alpha ((*surface)->pixman_image)) - image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); - else - image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height); - if (unlikely (image->status)) - return image->status; - - /* Draw the original bitmap transformed into the new bitmap - */ - _cairo_pattern_init_for_surface (&pattern, &(*surface)->base); - cairo_pattern_set_matrix (&pattern.base, &transformed_to_original); - - status = _cairo_surface_paint (image, - CAIRO_OPERATOR_SOURCE, - &pattern.base, - NULL); - - _cairo_pattern_fini (&pattern.base); - - if (unlikely (status)) { - cairo_surface_destroy (image); - return status; - } - - /* Now update the cache entry for the new bitmap, recomputing - * the origin based on the final transform. - */ - cairo_matrix_transform_point (&original_to_transformed, - &origin_x, &origin_y); - - old_image = (*surface); - (*surface) = (cairo_image_surface_t *)image; - cairo_surface_destroy (&old_image->base); - - cairo_surface_set_device_offset (&(*surface)->base, - _cairo_lround (origin_x), - _cairo_lround (origin_y)); - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend = { - _cairo_ft_unscaled_font_destroy, -#if 0 - _cairo_ft_unscaled_font_create_glyph -#endif -}; - -/* #cairo_ft_scaled_font_t */ - -typedef struct _cairo_ft_scaled_font { - cairo_scaled_font_t base; - cairo_ft_unscaled_font_t *unscaled; - cairo_ft_options_t ft_options; -} cairo_ft_scaled_font_t; - -static const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend; - -#if CAIRO_HAS_FC_FONT -/* The load flags passed to FT_Load_Glyph control aspects like hinting and - * antialiasing. Here we compute them from the fields of a FcPattern. - */ -static void -_get_pattern_ft_options (FcPattern *pattern, cairo_ft_options_t *ret) -{ - FcBool antialias, vertical_layout, hinting, autohint, bitmap, embolden; - cairo_ft_options_t ft_options; - int rgba; -#ifdef FC_HINT_STYLE - int hintstyle; -#endif - - _cairo_font_options_init_default (&ft_options.base); - ft_options.load_flags = FT_LOAD_DEFAULT; - ft_options.synth_flags = 0; - -#ifndef FC_EMBEDDED_BITMAP -#define FC_EMBEDDED_BITMAP "embeddedbitmap" -#endif - - /* Check whether to force use of embedded bitmaps */ - if (FcPatternGetBool (pattern, - FC_EMBEDDED_BITMAP, 0, &bitmap) != FcResultMatch) - bitmap = FcFalse; - - /* disable antialiasing if requested */ - if (FcPatternGetBool (pattern, - FC_ANTIALIAS, 0, &antialias) != FcResultMatch) - antialias = FcTrue; - - if (antialias) { - cairo_subpixel_order_t subpixel_order; - int lcd_filter; - - /* disable hinting if requested */ - if (FcPatternGetBool (pattern, - FC_HINTING, 0, &hinting) != FcResultMatch) - hinting = FcTrue; - - if (FcPatternGetInteger (pattern, - FC_RGBA, 0, &rgba) != FcResultMatch) - rgba = FC_RGBA_UNKNOWN; - - switch (rgba) { - case FC_RGBA_RGB: - subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; - break; - case FC_RGBA_BGR: - subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; - break; - case FC_RGBA_VRGB: - subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; - break; - case FC_RGBA_VBGR: - subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; - break; - case FC_RGBA_UNKNOWN: - case FC_RGBA_NONE: - default: - subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; - break; - } - - if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) { - ft_options.base.subpixel_order = subpixel_order; - ft_options.base.antialias = CAIRO_ANTIALIAS_SUBPIXEL; - } - - if (FcPatternGetInteger (pattern, - FC_LCD_FILTER, 0, &lcd_filter) == FcResultMatch) - { - switch (lcd_filter) { - case FC_LCD_NONE: - ft_options.base.lcd_filter = CAIRO_LCD_FILTER_NONE; - break; - case FC_LCD_DEFAULT: - ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR5; - break; - case FC_LCD_LIGHT: - ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR3; - break; - case FC_LCD_LEGACY: - ft_options.base.lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL; - break; - } - } - -#ifdef FC_HINT_STYLE - if (FcPatternGetInteger (pattern, - FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch) - hintstyle = FC_HINT_FULL; - - if (!hinting) - hintstyle = FC_HINT_NONE; - - switch (hintstyle) { - case FC_HINT_NONE: - ft_options.base.hint_style = CAIRO_HINT_STYLE_NONE; - break; - case FC_HINT_SLIGHT: - ft_options.base.hint_style = CAIRO_HINT_STYLE_SLIGHT; - break; - case FC_HINT_MEDIUM: - default: - ft_options.base.hint_style = CAIRO_HINT_STYLE_MEDIUM; - break; - case FC_HINT_FULL: - ft_options.base.hint_style = CAIRO_HINT_STYLE_FULL; - break; - } -#else /* !FC_HINT_STYLE */ - if (!hinting) { - ft_options.base.hint_style = CAIRO_HINT_STYLE_NONE; - } -#endif /* FC_HINT_STYLE */ - - /* Force embedded bitmaps off if no hinting requested */ - if (ft_options.base.hint_style == CAIRO_HINT_STYLE_NONE) - bitmap = FcFalse; - - if (!bitmap) - ft_options.load_flags |= FT_LOAD_NO_BITMAP; - - } else { - ft_options.base.antialias = CAIRO_ANTIALIAS_NONE; - } - - /* force autohinting if requested */ - if (FcPatternGetBool (pattern, - FC_AUTOHINT, 0, &autohint) != FcResultMatch) - autohint = FcFalse; - - if (autohint) - ft_options.load_flags |= FT_LOAD_FORCE_AUTOHINT; - - if (FcPatternGetBool (pattern, - FC_VERTICAL_LAYOUT, 0, &vertical_layout) != FcResultMatch) - vertical_layout = FcFalse; - - if (vertical_layout) - ft_options.load_flags |= FT_LOAD_VERTICAL_LAYOUT; - -#ifndef FC_EMBOLDEN -#define FC_EMBOLDEN "embolden" -#endif - if (FcPatternGetBool (pattern, - FC_EMBOLDEN, 0, &embolden) != FcResultMatch) - embolden = FcFalse; - - if (embolden) - ft_options.synth_flags |= CAIRO_FT_SYNTHESIZE_BOLD; - - *ret = ft_options; -} -#endif - -static void -_cairo_ft_options_merge (cairo_ft_options_t *options, - cairo_ft_options_t *other) -{ - int load_flags = other->load_flags; - int load_target = FT_LOAD_TARGET_NORMAL; - - /* clear load target mode */ - load_flags &= ~(FT_LOAD_TARGET_(FT_LOAD_TARGET_MODE(other->load_flags))); - - if (load_flags & FT_LOAD_NO_HINTING) - other->base.hint_style = CAIRO_HINT_STYLE_NONE; - - if (other->base.antialias == CAIRO_ANTIALIAS_NONE || - options->base.antialias == CAIRO_ANTIALIAS_NONE) { - options->base.antialias = CAIRO_ANTIALIAS_NONE; - options->base.subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; - } - - if (other->base.antialias == CAIRO_ANTIALIAS_SUBPIXEL && - (options->base.antialias == CAIRO_ANTIALIAS_DEFAULT || - options->base.antialias == CAIRO_ANTIALIAS_GRAY)) { - options->base.antialias = CAIRO_ANTIALIAS_SUBPIXEL; - options->base.subpixel_order = other->base.subpixel_order; - } - - if (options->base.hint_style == CAIRO_HINT_STYLE_DEFAULT) - options->base.hint_style = other->base.hint_style; - - if (other->base.hint_style == CAIRO_HINT_STYLE_NONE) - options->base.hint_style = CAIRO_HINT_STYLE_NONE; - - if (options->base.lcd_filter == CAIRO_LCD_FILTER_DEFAULT) - options->base.lcd_filter = other->base.lcd_filter; - - if (other->base.lcd_filter == CAIRO_LCD_FILTER_NONE) - options->base.lcd_filter = CAIRO_LCD_FILTER_NONE; - - if (options->base.antialias == CAIRO_ANTIALIAS_NONE) { - if (options->base.hint_style == CAIRO_HINT_STYLE_NONE) - load_flags |= FT_LOAD_NO_HINTING; - else - load_target = FT_LOAD_TARGET_MONO; - load_flags |= FT_LOAD_MONOCHROME; - } else { - switch (options->base.hint_style) { - case CAIRO_HINT_STYLE_NONE: - load_flags |= FT_LOAD_NO_HINTING; - break; - case CAIRO_HINT_STYLE_SLIGHT: - load_target = FT_LOAD_TARGET_LIGHT; - break; - case CAIRO_HINT_STYLE_MEDIUM: - break; - case CAIRO_HINT_STYLE_FULL: - case CAIRO_HINT_STYLE_DEFAULT: - if (options->base.antialias == CAIRO_ANTIALIAS_SUBPIXEL) { - switch (options->base.subpixel_order) { - case CAIRO_SUBPIXEL_ORDER_DEFAULT: - case CAIRO_SUBPIXEL_ORDER_RGB: - case CAIRO_SUBPIXEL_ORDER_BGR: - load_target = FT_LOAD_TARGET_LCD; - break; - case CAIRO_SUBPIXEL_ORDER_VRGB: - case CAIRO_SUBPIXEL_ORDER_VBGR: - load_target = FT_LOAD_TARGET_LCD_V; - break; - } - } - break; - } - } - - options->load_flags = load_flags | load_target; - options->synth_flags = other->synth_flags; -} - -static cairo_status_t -_cairo_ft_font_face_scaled_font_create (void *abstract_font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - cairo_scaled_font_t **font_out) -{ - cairo_ft_font_face_t *font_face = abstract_font_face; - cairo_ft_scaled_font_t *scaled_font; - FT_Face face; - FT_Size_Metrics *metrics; - cairo_font_extents_t fs_metrics; - cairo_status_t status; - cairo_ft_unscaled_font_t *unscaled; - - assert (font_face->unscaled); - - face = _cairo_ft_unscaled_font_lock_face (font_face->unscaled); - if (unlikely (face == NULL)) /* backend error */ - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - scaled_font = malloc (sizeof (cairo_ft_scaled_font_t)); - if (unlikely (scaled_font == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FAIL; - } - - scaled_font->unscaled = unscaled = font_face->unscaled; - _cairo_unscaled_font_reference (&unscaled->base); - - _cairo_font_options_init_copy (&scaled_font->ft_options.base, options); - _cairo_ft_options_merge (&scaled_font->ft_options, &font_face->ft_options); - - status = _cairo_scaled_font_init (&scaled_font->base, - &font_face->base, - font_matrix, ctm, options, - &_cairo_ft_scaled_font_backend); - if (unlikely (status)) - goto CLEANUP_SCALED_FONT; - - status = _cairo_ft_unscaled_font_set_scale (unscaled, - &scaled_font->base.scale); - if (unlikely (status)) { - /* This can only fail if we encounter an error with the underlying - * font, so propagate the error back to the font-face. */ - _cairo_ft_unscaled_font_unlock_face (unscaled); - _cairo_unscaled_font_destroy (&unscaled->base); - free (scaled_font); - return status; - } - - - metrics = &face->size->metrics; - - /* - * Get to unscaled metrics so that the upper level can get back to - * user space - * - * Also use this path for bitmap-only fonts. The other branch uses - * face members that are only relevant for scalable fonts. This is - * detected by simply checking for units_per_EM==0. - */ - if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF || - face->units_per_EM == 0) { - double x_factor, y_factor; - - if (unscaled->x_scale == 0) - x_factor = 0; - else - x_factor = 1 / unscaled->x_scale; - - if (unscaled->y_scale == 0) - y_factor = 0; - else - y_factor = 1 / unscaled->y_scale; - - fs_metrics.ascent = DOUBLE_FROM_26_6(metrics->ascender) * y_factor; - fs_metrics.descent = DOUBLE_FROM_26_6(- metrics->descender) * y_factor; - fs_metrics.height = DOUBLE_FROM_26_6(metrics->height) * y_factor; - if (!_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) { - fs_metrics.max_x_advance = DOUBLE_FROM_26_6(metrics->max_advance) * x_factor; - fs_metrics.max_y_advance = 0; - } else { - fs_metrics.max_x_advance = 0; - fs_metrics.max_y_advance = DOUBLE_FROM_26_6(metrics->max_advance) * y_factor; - } - } else { - double scale = face->units_per_EM; - - fs_metrics.ascent = face->ascender / scale; - fs_metrics.descent = - face->descender / scale; - fs_metrics.height = face->height / scale; - if (!_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) { - fs_metrics.max_x_advance = face->max_advance_width / scale; - fs_metrics.max_y_advance = 0; - } else { - fs_metrics.max_x_advance = 0; - fs_metrics.max_y_advance = face->max_advance_height / scale; - } - } - - status = _cairo_scaled_font_set_metrics (&scaled_font->base, &fs_metrics); - if (unlikely (status)) - goto CLEANUP_SCALED_FONT; - - _cairo_ft_unscaled_font_unlock_face (unscaled); - - *font_out = &scaled_font->base; - return CAIRO_STATUS_SUCCESS; - - CLEANUP_SCALED_FONT: - _cairo_unscaled_font_destroy (&unscaled->base); - free (scaled_font); - FAIL: - _cairo_ft_unscaled_font_unlock_face (font_face->unscaled); - *font_out = _cairo_scaled_font_create_in_error (status); - return CAIRO_STATUS_SUCCESS; /* non-backend error */ -} - -cairo_bool_t -_cairo_scaled_font_is_ft (cairo_scaled_font_t *scaled_font) -{ - return scaled_font->backend == &_cairo_ft_scaled_font_backend; -} - -static void -_cairo_ft_scaled_font_fini (void *abstract_font) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - - if (scaled_font == NULL) - return; - - _cairo_unscaled_font_destroy (&scaled_font->unscaled->base); -} - -static int -_move_to (FT_Vector *to, void *closure) -{ - cairo_path_fixed_t *path = closure; - cairo_fixed_t x, y; - - x = _cairo_fixed_from_26_6 (to->x); - y = _cairo_fixed_from_26_6 (to->y); - - if (_cairo_path_fixed_close_path (path) != CAIRO_STATUS_SUCCESS) - return 1; - if (_cairo_path_fixed_move_to (path, x, y) != CAIRO_STATUS_SUCCESS) - return 1; - - return 0; -} - -static int -_line_to (FT_Vector *to, void *closure) -{ - cairo_path_fixed_t *path = closure; - cairo_fixed_t x, y; - - x = _cairo_fixed_from_26_6 (to->x); - y = _cairo_fixed_from_26_6 (to->y); - - if (_cairo_path_fixed_line_to (path, x, y) != CAIRO_STATUS_SUCCESS) - return 1; - - return 0; -} - -static int -_conic_to (FT_Vector *control, FT_Vector *to, void *closure) -{ - cairo_path_fixed_t *path = closure; - - cairo_fixed_t x0, y0; - cairo_fixed_t x1, y1; - cairo_fixed_t x2, y2; - cairo_fixed_t x3, y3; - cairo_point_t conic; - - if (! _cairo_path_fixed_get_current_point (path, &x0, &y0)) - return 1; - - conic.x = _cairo_fixed_from_26_6 (control->x); - conic.y = _cairo_fixed_from_26_6 (control->y); - - x3 = _cairo_fixed_from_26_6 (to->x); - y3 = _cairo_fixed_from_26_6 (to->y); - - x1 = x0 + 2.0/3.0 * (conic.x - x0); - y1 = y0 + 2.0/3.0 * (conic.y - y0); - - x2 = x3 + 2.0/3.0 * (conic.x - x3); - y2 = y3 + 2.0/3.0 * (conic.y - y3); - - if (_cairo_path_fixed_curve_to (path, - x1, y1, - x2, y2, - x3, y3) != CAIRO_STATUS_SUCCESS) - return 1; - - return 0; -} - -static int -_cubic_to (FT_Vector *control1, FT_Vector *control2, - FT_Vector *to, void *closure) -{ - cairo_path_fixed_t *path = closure; - cairo_fixed_t x0, y0; - cairo_fixed_t x1, y1; - cairo_fixed_t x2, y2; - - x0 = _cairo_fixed_from_26_6 (control1->x); - y0 = _cairo_fixed_from_26_6 (control1->y); - - x1 = _cairo_fixed_from_26_6 (control2->x); - y1 = _cairo_fixed_from_26_6 (control2->y); - - x2 = _cairo_fixed_from_26_6 (to->x); - y2 = _cairo_fixed_from_26_6 (to->y); - - if (_cairo_path_fixed_curve_to (path, - x0, y0, - x1, y1, - x2, y2) != CAIRO_STATUS_SUCCESS) - return 1; - - return 0; -} - -static cairo_status_t -_decompose_glyph_outline (FT_Face face, - cairo_font_options_t *options, - cairo_path_fixed_t **pathp) -{ - static const FT_Outline_Funcs outline_funcs = { - (FT_Outline_MoveToFunc)_move_to, - (FT_Outline_LineToFunc)_line_to, - (FT_Outline_ConicToFunc)_conic_to, - (FT_Outline_CubicToFunc)_cubic_to, - 0, /* shift */ - 0, /* delta */ - }; - static const FT_Matrix invert_y = { - DOUBLE_TO_16_16 (1.0), 0, - 0, DOUBLE_TO_16_16 (-1.0), - }; - - FT_GlyphSlot glyph; - cairo_path_fixed_t *path; - cairo_status_t status; - - path = _cairo_path_fixed_create (); - if (!path) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - glyph = face->glyph; - - /* Font glyphs have an inverted Y axis compared to cairo. */ - FT_Outline_Transform (&glyph->outline, &invert_y); - if (FT_Outline_Decompose (&glyph->outline, &outline_funcs, path)) { - _cairo_path_fixed_destroy (path); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - status = _cairo_path_fixed_close_path (path); - if (unlikely (status)) { - _cairo_path_fixed_destroy (path); - return status; - } - - *pathp = path; - - return CAIRO_STATUS_SUCCESS; -} - -/* - * Translate glyph to match its metrics. - */ -static void -_cairo_ft_scaled_glyph_vertical_layout_bearing_fix (void *abstract_font, - FT_GlyphSlot glyph) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - FT_Vector vector; - - vector.x = glyph->metrics.vertBearingX - glyph->metrics.horiBearingX; - vector.y = -glyph->metrics.vertBearingY - glyph->metrics.horiBearingY; - - if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { - FT_Vector_Transform (&vector, &scaled_font->unscaled->Current_Shape); - FT_Outline_Translate(&glyph->outline, vector.x, vector.y); - } else if (glyph->format == FT_GLYPH_FORMAT_BITMAP) { - glyph->bitmap_left += vector.x / 64; - glyph->bitmap_top += vector.y / 64; - } -} - -static cairo_int_status_t -_cairo_ft_scaled_glyph_init (void *abstract_font, - cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_glyph_info_t info) -{ - cairo_text_extents_t fs_metrics; - cairo_ft_scaled_font_t *scaled_font = abstract_font; - cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; - FT_GlyphSlot glyph; - FT_Face face; - FT_Error error; - int load_flags = scaled_font->ft_options.load_flags; - FT_Glyph_Metrics *metrics; - double x_factor, y_factor; - cairo_bool_t vertical_layout = FALSE; - cairo_status_t status; - - face = _cairo_ft_unscaled_font_lock_face (unscaled); - if (!face) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled, - &scaled_font->base.scale); - if (unlikely (status)) - goto FAIL; - - /* Ignore global advance unconditionally */ - load_flags |= FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH; - - if ((info & CAIRO_SCALED_GLYPH_INFO_PATH) != 0 && - (info & CAIRO_SCALED_GLYPH_INFO_SURFACE) == 0) - load_flags |= FT_LOAD_NO_BITMAP; - - /* - * Don't pass FT_LOAD_VERTICAL_LAYOUT to FT_Load_Glyph here as - * suggested by freetype people. - */ - if (load_flags & FT_LOAD_VERTICAL_LAYOUT) { - load_flags &= ~FT_LOAD_VERTICAL_LAYOUT; - vertical_layout = TRUE; - } - -#ifdef FT_LOAD_COLOR - /* Color-glyph support: - * - * This flags needs plumbing through fontconfig (does it?), and - * maybe we should cache color and grayscale bitmaps separately - * such that users of the font (ie. the surface) can choose which - * version to use based on target content type. - * - * Moreover, none of our backends and compositors currently support - * color glyphs. As such, this is currently disabled. - */ - /* load_flags |= FT_LOAD_COLOR; */ -#endif - - error = FT_Load_Glyph (face, - _cairo_scaled_glyph_index(scaled_glyph), - load_flags); - /* XXX ignoring all other errors for now. They are not fatal, typically - * just a glyph-not-found. */ - if (error == FT_Err_Out_Of_Memory) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FAIL; - } - - glyph = face->glyph; - - /* - * synthesize glyphs if requested - */ -#if HAVE_FT_GLYPHSLOT_EMBOLDEN - if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_BOLD) - FT_GlyphSlot_Embolden (glyph); -#endif - -#if HAVE_FT_GLYPHSLOT_OBLIQUE - if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_OBLIQUE) - FT_GlyphSlot_Oblique (glyph); -#endif - - if (vertical_layout) - _cairo_ft_scaled_glyph_vertical_layout_bearing_fix (scaled_font, glyph); - - if (info & CAIRO_SCALED_GLYPH_INFO_METRICS) { - - cairo_bool_t hint_metrics = scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF; - /* - * Compute font-space metrics - */ - metrics = &glyph->metrics; - - if (unscaled->x_scale == 0) - x_factor = 0; - else - x_factor = 1 / unscaled->x_scale; - - if (unscaled->y_scale == 0) - y_factor = 0; - else - y_factor = 1 / unscaled->y_scale; - - /* - * Note: Y coordinates of the horizontal bearing need to be negated. - * - * Scale metrics back to glyph space from the scaled glyph space returned - * by FreeType - * - * If we want hinted metrics but aren't asking for hinted glyphs from - * FreeType, then we need to do the metric hinting ourselves. - */ - - if (hint_metrics && (load_flags & FT_LOAD_NO_HINTING)) - { - FT_Pos x1, x2; - FT_Pos y1, y2; - FT_Pos advance; - - if (!vertical_layout) { - x1 = (metrics->horiBearingX) & -64; - x2 = (metrics->horiBearingX + metrics->width + 63) & -64; - y1 = (-metrics->horiBearingY) & -64; - y2 = (-metrics->horiBearingY + metrics->height + 63) & -64; - - advance = ((metrics->horiAdvance + 32) & -64); - - fs_metrics.x_bearing = DOUBLE_FROM_26_6 (x1) * x_factor; - fs_metrics.y_bearing = DOUBLE_FROM_26_6 (y1) * y_factor; - - fs_metrics.width = DOUBLE_FROM_26_6 (x2 - x1) * x_factor; - fs_metrics.height = DOUBLE_FROM_26_6 (y2 - y1) * y_factor; - - fs_metrics.x_advance = DOUBLE_FROM_26_6 (advance) * x_factor; - fs_metrics.y_advance = 0; - } else { - x1 = (metrics->vertBearingX) & -64; - x2 = (metrics->vertBearingX + metrics->width + 63) & -64; - y1 = (metrics->vertBearingY) & -64; - y2 = (metrics->vertBearingY + metrics->height + 63) & -64; - - advance = ((metrics->vertAdvance + 32) & -64); - - fs_metrics.x_bearing = DOUBLE_FROM_26_6 (x1) * x_factor; - fs_metrics.y_bearing = DOUBLE_FROM_26_6 (y1) * y_factor; - - fs_metrics.width = DOUBLE_FROM_26_6 (x2 - x1) * x_factor; - fs_metrics.height = DOUBLE_FROM_26_6 (y2 - y1) * y_factor; - - fs_metrics.x_advance = 0; - fs_metrics.y_advance = DOUBLE_FROM_26_6 (advance) * y_factor; - } - } else { - fs_metrics.width = DOUBLE_FROM_26_6 (metrics->width) * x_factor; - fs_metrics.height = DOUBLE_FROM_26_6 (metrics->height) * y_factor; - - if (!vertical_layout) { - fs_metrics.x_bearing = DOUBLE_FROM_26_6 (metrics->horiBearingX) * x_factor; - fs_metrics.y_bearing = DOUBLE_FROM_26_6 (-metrics->horiBearingY) * y_factor; - - if (hint_metrics || glyph->format != FT_GLYPH_FORMAT_OUTLINE) - fs_metrics.x_advance = DOUBLE_FROM_26_6 (metrics->horiAdvance) * x_factor; - else - fs_metrics.x_advance = DOUBLE_FROM_16_16 (glyph->linearHoriAdvance) * x_factor; - fs_metrics.y_advance = 0 * y_factor; - } else { - fs_metrics.x_bearing = DOUBLE_FROM_26_6 (metrics->vertBearingX) * x_factor; - fs_metrics.y_bearing = DOUBLE_FROM_26_6 (metrics->vertBearingY) * y_factor; - - fs_metrics.x_advance = 0 * x_factor; - if (hint_metrics || glyph->format != FT_GLYPH_FORMAT_OUTLINE) - fs_metrics.y_advance = DOUBLE_FROM_26_6 (metrics->vertAdvance) * y_factor; - else - fs_metrics.y_advance = DOUBLE_FROM_16_16 (glyph->linearVertAdvance) * y_factor; - } - } - - _cairo_scaled_glyph_set_metrics (scaled_glyph, - &scaled_font->base, - &fs_metrics); - } - - if ((info & CAIRO_SCALED_GLYPH_INFO_SURFACE) != 0) { - cairo_image_surface_t *surface; - - if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { - status = _render_glyph_outline (face, &scaled_font->ft_options.base, - &surface); - } else { - status = _render_glyph_bitmap (face, &scaled_font->ft_options.base, - &surface); - if (likely (status == CAIRO_STATUS_SUCCESS) && - unscaled->have_shape) - { - status = _transform_glyph_bitmap (&unscaled->current_shape, - &surface); - if (unlikely (status)) - cairo_surface_destroy (&surface->base); - } - } - if (unlikely (status)) - goto FAIL; - - _cairo_scaled_glyph_set_surface (scaled_glyph, - &scaled_font->base, - surface); - } - - if (info & CAIRO_SCALED_GLYPH_INFO_PATH) { - cairo_path_fixed_t *path = NULL; /* hide compiler warning */ - - /* - * A kludge -- the above code will trash the outline, - * so reload it. This will probably never occur though - */ - if ((info & CAIRO_SCALED_GLYPH_INFO_SURFACE) != 0) { - error = FT_Load_Glyph (face, - _cairo_scaled_glyph_index(scaled_glyph), - load_flags | FT_LOAD_NO_BITMAP); - /* XXX ignoring all other errors for now. They are not fatal, typically - * just a glyph-not-found. */ - if (error == FT_Err_Out_Of_Memory) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FAIL; - } -#if HAVE_FT_GLYPHSLOT_EMBOLDEN - if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_BOLD) - FT_GlyphSlot_Embolden (glyph); -#endif -#if HAVE_FT_GLYPHSLOT_OBLIQUE - if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_OBLIQUE) - FT_GlyphSlot_Oblique (glyph); -#endif - if (vertical_layout) - _cairo_ft_scaled_glyph_vertical_layout_bearing_fix (scaled_font, glyph); - - } - if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) - status = _decompose_glyph_outline (face, &scaled_font->ft_options.base, - &path); - else - status = CAIRO_INT_STATUS_UNSUPPORTED; - - if (unlikely (status)) - goto FAIL; - - _cairo_scaled_glyph_set_path (scaled_glyph, - &scaled_font->base, - path); - } - FAIL: - _cairo_ft_unscaled_font_unlock_face (unscaled); - - return status; -} - -static unsigned long -_cairo_ft_ucs4_to_index (void *abstract_font, - uint32_t ucs4) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; - FT_Face face; - FT_UInt index; - - face = _cairo_ft_unscaled_font_lock_face (unscaled); - if (!face) - return 0; - -#if CAIRO_HAS_FC_FONT - index = FcFreeTypeCharIndex (face, ucs4); -#else - index = FT_Get_Char_Index (face, ucs4); -#endif - - _cairo_ft_unscaled_font_unlock_face (unscaled); - return index; -} - -static cairo_int_status_t -_cairo_ft_load_truetype_table (void *abstract_font, - unsigned long tag, - long offset, - unsigned char *buffer, - unsigned long *length) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; - FT_Face face; - cairo_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - /* We don't support the FreeType feature of loading a table - * without specifying the size since this may overflow our - * buffer. */ - assert (length != NULL); - - if (_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) - return CAIRO_INT_STATUS_UNSUPPORTED; - -#if HAVE_FT_LOAD_SFNT_TABLE - face = _cairo_ft_unscaled_font_lock_face (unscaled); - if (!face) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (FT_IS_SFNT (face)) { - if (buffer == NULL) - *length = 0; - - if (FT_Load_Sfnt_Table (face, tag, offset, buffer, length) == 0) - status = CAIRO_STATUS_SUCCESS; - } - - _cairo_ft_unscaled_font_unlock_face (unscaled); -#endif - - return status; -} - -static cairo_int_status_t -_cairo_ft_index_to_ucs4(void *abstract_font, - unsigned long index, - uint32_t *ucs4) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; - FT_Face face; - FT_ULong charcode; - FT_UInt gindex; - - face = _cairo_ft_unscaled_font_lock_face (unscaled); - if (!face) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - *ucs4 = (uint32_t) -1; - charcode = FT_Get_First_Char(face, &gindex); - while (gindex != 0) { - if (gindex == index) { - *ucs4 = charcode; - break; - } - charcode = FT_Get_Next_Char (face, charcode, &gindex); - } - - _cairo_ft_unscaled_font_unlock_face (unscaled); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_ft_is_synthetic (void *abstract_font) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - return scaled_font->ft_options.synth_flags != 0; -} - -static cairo_int_status_t -_cairo_index_to_glyph_name (void *abstract_font, - char **glyph_names, - int num_glyph_names, - unsigned long glyph_index, - unsigned long *glyph_array_index) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; - FT_Face face; - char buffer[256]; /* PLRM spcifies max name length of 127 */ - FT_Error error; - int i; - - face = _cairo_ft_unscaled_font_lock_face (unscaled); - if (!face) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - error = FT_Get_Glyph_Name (face, glyph_index, buffer, sizeof buffer); - - _cairo_ft_unscaled_font_unlock_face (unscaled); - - if (error != FT_Err_Ok) { - /* propagate fatal errors from FreeType */ - if (error == FT_Err_Out_Of_Memory) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* FT first numbers the glyphs in the order they are read from the - * Type 1 font. Then if .notdef is not the first glyph, the first - * glyph is swapped with .notdef to ensure that .notdef is at - * glyph index 0. - * - * As all but two glyphs in glyph_names already have the same - * index as the FT glyph index, we first check if - * glyph_names[glyph_index] is the name we are looking for. If not - * we fall back to searching the entire array. - */ - - if ((long)glyph_index < num_glyph_names && - strcmp (glyph_names[glyph_index], buffer) == 0) - { - *glyph_array_index = glyph_index; - - return CAIRO_STATUS_SUCCESS; - } - - for (i = 0; i < num_glyph_names; i++) { - if (strcmp (glyph_names[i], buffer) == 0) { - *glyph_array_index = i; - - return CAIRO_STATUS_SUCCESS; - } - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_bool_t -_ft_is_type1 (FT_Face face) -{ -#if HAVE_FT_GET_X11_FONT_FORMAT - const char *font_format = FT_Get_X11_Font_Format (face); - if (font_format && - (strcmp (font_format, "Type 1") == 0 || - strcmp (font_format, "CFF") == 0)) - { - return TRUE; - } -#endif - - return FALSE; -} - -static cairo_int_status_t -_cairo_ft_load_type1_data (void *abstract_font, - long offset, - unsigned char *buffer, - unsigned long *length) -{ - cairo_ft_scaled_font_t *scaled_font = abstract_font; - cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; - FT_Face face; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - unsigned long available_length; - unsigned long ret; - - assert (length != NULL); - - if (_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - face = _cairo_ft_unscaled_font_lock_face (unscaled); - if (!face) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - -#if HAVE_FT_LOAD_SFNT_TABLE - if (FT_IS_SFNT (face)) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto unlock; - } -#endif - - if (! _ft_is_type1 (face)) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto unlock; - } - - available_length = MAX (face->stream->size - offset, 0); - if (!buffer) { - *length = available_length; - } else { - if (*length > available_length) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - } else if (face->stream->read != NULL) { - /* Note that read() may be implemented as a macro, thanks POSIX!, so we - * need to wrap the following usage in parentheses in order to - * disambiguate it for the pre-processor - using the verbose function - * pointer dereference for clarity. - */ - ret = (* face->stream->read) (face->stream, - offset, - buffer, - *length); - if (ret != *length) - status = _cairo_error (CAIRO_STATUS_READ_ERROR); - } else { - memcpy (buffer, face->stream->base + offset, *length); - } - } - - unlock: - _cairo_ft_unscaled_font_unlock_face (unscaled); - - return status; -} - -static const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend = { - CAIRO_FONT_TYPE_FT, - _cairo_ft_scaled_font_fini, - _cairo_ft_scaled_glyph_init, - NULL, /* text_to_glyphs */ - _cairo_ft_ucs4_to_index, - _cairo_ft_load_truetype_table, - _cairo_ft_index_to_ucs4, - _cairo_ft_is_synthetic, - _cairo_index_to_glyph_name, - _cairo_ft_load_type1_data -}; - -/* #cairo_ft_font_face_t */ - -#if CAIRO_HAS_FC_FONT -static cairo_font_face_t * -_cairo_ft_font_face_create_for_pattern (FcPattern *pattern); - -static cairo_status_t -_cairo_ft_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, - cairo_font_face_t **font_face_out) -{ - cairo_font_face_t *font_face = (cairo_font_face_t *) &_cairo_font_face_nil; - FcPattern *pattern; - int fcslant; - int fcweight; - - pattern = FcPatternCreate (); - if (!pattern) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return font_face->status; - } - - if (!FcPatternAddString (pattern, - FC_FAMILY, (unsigned char *) toy_face->family)) - { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - goto FREE_PATTERN; - } - - switch (toy_face->slant) - { - case CAIRO_FONT_SLANT_ITALIC: - fcslant = FC_SLANT_ITALIC; - break; - case CAIRO_FONT_SLANT_OBLIQUE: - fcslant = FC_SLANT_OBLIQUE; - break; - case CAIRO_FONT_SLANT_NORMAL: - default: - fcslant = FC_SLANT_ROMAN; - break; - } - - if (!FcPatternAddInteger (pattern, FC_SLANT, fcslant)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - goto FREE_PATTERN; - } - - switch (toy_face->weight) - { - case CAIRO_FONT_WEIGHT_BOLD: - fcweight = FC_WEIGHT_BOLD; - break; - case CAIRO_FONT_WEIGHT_NORMAL: - default: - fcweight = FC_WEIGHT_MEDIUM; - break; - } - - if (!FcPatternAddInteger (pattern, FC_WEIGHT, fcweight)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - goto FREE_PATTERN; - } - - font_face = _cairo_ft_font_face_create_for_pattern (pattern); - - FREE_PATTERN: - FcPatternDestroy (pattern); - - *font_face_out = font_face; - return font_face->status; -} -#endif - -static cairo_bool_t -_cairo_ft_font_face_destroy (void *abstract_face) -{ - cairo_ft_font_face_t *font_face = abstract_face; - - /* When destroying a face created by cairo_ft_font_face_create_for_ft_face, - * we have a special "zombie" state for the face when the unscaled font - * is still alive but there are no other references to a font face with - * the same FT_Face. - * - * We go from: - * - * font_face ------> unscaled - * <-....weak....../ - * - * To: - * - * font_face <------- unscaled - */ - - if (font_face->unscaled && - font_face->unscaled->from_face && - font_face->next == NULL && - font_face->unscaled->faces == font_face && - CAIRO_REFERENCE_COUNT_GET_VALUE (&font_face->unscaled->base.ref_count) > 1) - { - _cairo_unscaled_font_destroy (&font_face->unscaled->base); - font_face->unscaled = NULL; - - return FALSE; - } - - if (font_face->unscaled) { - cairo_ft_font_face_t *tmp_face = NULL; - cairo_ft_font_face_t *last_face = NULL; - - /* Remove face from linked list */ - for (tmp_face = font_face->unscaled->faces; - tmp_face; - tmp_face = tmp_face->next) - { - if (tmp_face == font_face) { - if (last_face) - last_face->next = tmp_face->next; - else - font_face->unscaled->faces = tmp_face->next; - } - - last_face = tmp_face; - } - - _cairo_unscaled_font_destroy (&font_face->unscaled->base); - font_face->unscaled = NULL; - } - -#if CAIRO_HAS_FC_FONT - if (font_face->pattern) { - FcPatternDestroy (font_face->pattern); - cairo_font_face_destroy (font_face->resolved_font_face); - } -#endif - - return TRUE; -} - -static cairo_font_face_t * -_cairo_ft_font_face_get_implementation (void *abstract_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options) -{ - cairo_ft_font_face_t *font_face = abstract_face; - - /* The handling of font options is different depending on how the - * font face was created. When the user creates a font face with - * cairo_ft_font_face_create_for_ft_face(), then the load flags - * passed in augment the load flags for the options. But for - * cairo_ft_font_face_create_for_pattern(), the load flags are - * derived from a pattern where the user has called - * cairo_ft_font_options_substitute(), so *just* use those load - * flags and ignore the options. - */ - -#if CAIRO_HAS_FC_FONT - /* If we have an unresolved pattern, resolve it and create - * unscaled font. Otherwise, use the ones stored in font_face. - */ - if (font_face->pattern) { - cairo_font_face_t *resolved; - - /* Cache the resolved font whilst the FcConfig remains consistent. */ - resolved = font_face->resolved_font_face; - if (resolved != NULL) { - if (! FcInitBringUptoDate ()) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *) &_cairo_font_face_nil; - } - - if (font_face->resolved_config == FcConfigGetCurrent ()) - return cairo_font_face_reference (resolved); - - cairo_font_face_destroy (resolved); - font_face->resolved_font_face = NULL; - } - - resolved = _cairo_ft_resolve_pattern (font_face->pattern, - font_matrix, - ctm, - options); - if (unlikely (resolved->status)) - return resolved; - - font_face->resolved_font_face = cairo_font_face_reference (resolved); - font_face->resolved_config = FcConfigGetCurrent (); - - return resolved; - } -#endif - - return abstract_face; -} - -const cairo_font_face_backend_t _cairo_ft_font_face_backend = { - CAIRO_FONT_TYPE_FT, -#if CAIRO_HAS_FC_FONT - _cairo_ft_font_face_create_for_toy, -#else - NULL, -#endif - _cairo_ft_font_face_destroy, - _cairo_ft_font_face_scaled_font_create, - _cairo_ft_font_face_get_implementation -}; - -#if CAIRO_HAS_FC_FONT -static cairo_font_face_t * -_cairo_ft_font_face_create_for_pattern (FcPattern *pattern) -{ - cairo_ft_font_face_t *font_face; - - font_face = malloc (sizeof (cairo_ft_font_face_t)); - if (unlikely (font_face == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *) &_cairo_font_face_nil; - } - - font_face->unscaled = NULL; - font_face->next = NULL; - - font_face->pattern = FcPatternDuplicate (pattern); - if (unlikely (font_face->pattern == NULL)) { - free (font_face); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *) &_cairo_font_face_nil; - } - - font_face->resolved_font_face = NULL; - font_face->resolved_config = NULL; - - _cairo_font_face_init (&font_face->base, &_cairo_ft_font_face_backend); - - return &font_face->base; -} -#endif - -static cairo_font_face_t * -_cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled, - cairo_ft_options_t *ft_options) -{ - cairo_ft_font_face_t *font_face, **prev_font_face; - - /* Looked for an existing matching font face */ - for (font_face = unscaled->faces, prev_font_face = &unscaled->faces; - font_face; - prev_font_face = &font_face->next, font_face = font_face->next) - { - if (font_face->ft_options.load_flags == ft_options->load_flags && - font_face->ft_options.synth_flags == ft_options->synth_flags && - cairo_font_options_equal (&font_face->ft_options.base, &ft_options->base)) - { - if (font_face->base.status) { - /* The font_face has been left in an error state, abandon it. */ - *prev_font_face = font_face->next; - break; - } - - if (font_face->unscaled == NULL) { - /* Resurrect this "zombie" font_face (from - * _cairo_ft_font_face_destroy), switching its unscaled_font - * from owner to ownee. */ - font_face->unscaled = unscaled; - _cairo_unscaled_font_reference (&unscaled->base); - return &font_face->base; - } else - return cairo_font_face_reference (&font_face->base); - } - } - - /* No match found, create a new one */ - font_face = malloc (sizeof (cairo_ft_font_face_t)); - if (unlikely (!font_face)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *)&_cairo_font_face_nil; - } - - font_face->unscaled = unscaled; - _cairo_unscaled_font_reference (&unscaled->base); - - font_face->ft_options = *ft_options; - - if (unscaled->faces && unscaled->faces->unscaled == NULL) { - /* This "zombie" font_face (from _cairo_ft_font_face_destroy) - * is no longer needed. */ - assert (unscaled->from_face && unscaled->faces->next == NULL); - cairo_font_face_destroy (&unscaled->faces->base); - unscaled->faces = NULL; - } - - font_face->next = unscaled->faces; - unscaled->faces = font_face; - -#if CAIRO_HAS_FC_FONT - font_face->pattern = NULL; -#endif - - _cairo_font_face_init (&font_face->base, &_cairo_ft_font_face_backend); - - return &font_face->base; -} - -/* implement the platform-specific interface */ - -#if CAIRO_HAS_FC_FONT -static cairo_status_t -_cairo_ft_font_options_substitute (const cairo_font_options_t *options, - FcPattern *pattern) -{ - FcValue v; - - if (options->antialias != CAIRO_ANTIALIAS_DEFAULT) - { - if (FcPatternGet (pattern, FC_ANTIALIAS, 0, &v) == FcResultNoMatch) - { - if (! FcPatternAddBool (pattern, - FC_ANTIALIAS, - options->antialias != CAIRO_ANTIALIAS_NONE)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (options->antialias != CAIRO_ANTIALIAS_SUBPIXEL) { - FcPatternDel (pattern, FC_RGBA); - if (! FcPatternAddInteger (pattern, FC_RGBA, FC_RGBA_NONE)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - } - - if (options->antialias != CAIRO_ANTIALIAS_DEFAULT) - { - if (FcPatternGet (pattern, FC_RGBA, 0, &v) == FcResultNoMatch) - { - int rgba; - - if (options->antialias == CAIRO_ANTIALIAS_SUBPIXEL) { - switch (options->subpixel_order) { - case CAIRO_SUBPIXEL_ORDER_DEFAULT: - case CAIRO_SUBPIXEL_ORDER_RGB: - default: - rgba = FC_RGBA_RGB; - break; - case CAIRO_SUBPIXEL_ORDER_BGR: - rgba = FC_RGBA_BGR; - break; - case CAIRO_SUBPIXEL_ORDER_VRGB: - rgba = FC_RGBA_VRGB; - break; - case CAIRO_SUBPIXEL_ORDER_VBGR: - rgba = FC_RGBA_VBGR; - break; - } - } else { - rgba = FC_RGBA_NONE; - } - - if (! FcPatternAddInteger (pattern, FC_RGBA, rgba)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - if (options->lcd_filter != CAIRO_LCD_FILTER_DEFAULT) - { - if (FcPatternGet (pattern, FC_LCD_FILTER, 0, &v) == FcResultNoMatch) - { - int lcd_filter; - - switch (options->lcd_filter) { - case CAIRO_LCD_FILTER_NONE: - lcd_filter = FT_LCD_FILTER_NONE; - break; - case CAIRO_LCD_FILTER_DEFAULT: - case CAIRO_LCD_FILTER_INTRA_PIXEL: - lcd_filter = FT_LCD_FILTER_LEGACY; - break; - case CAIRO_LCD_FILTER_FIR3: - lcd_filter = FT_LCD_FILTER_LIGHT; - break; - default: - case CAIRO_LCD_FILTER_FIR5: - lcd_filter = FT_LCD_FILTER_DEFAULT; - break; - } - - if (! FcPatternAddInteger (pattern, FC_LCD_FILTER, lcd_filter)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - if (options->hint_style != CAIRO_HINT_STYLE_DEFAULT) - { - if (FcPatternGet (pattern, FC_HINTING, 0, &v) == FcResultNoMatch) - { - if (! FcPatternAddBool (pattern, - FC_HINTING, - options->hint_style != CAIRO_HINT_STYLE_NONE)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - -#ifdef FC_HINT_STYLE - if (FcPatternGet (pattern, FC_HINT_STYLE, 0, &v) == FcResultNoMatch) - { - int hint_style; - - switch (options->hint_style) { - case CAIRO_HINT_STYLE_NONE: - hint_style = FC_HINT_NONE; - break; - case CAIRO_HINT_STYLE_SLIGHT: - hint_style = FC_HINT_SLIGHT; - break; - case CAIRO_HINT_STYLE_MEDIUM: - hint_style = FC_HINT_MEDIUM; - break; - case CAIRO_HINT_STYLE_FULL: - case CAIRO_HINT_STYLE_DEFAULT: - default: - hint_style = FC_HINT_FULL; - break; - } - - if (! FcPatternAddInteger (pattern, FC_HINT_STYLE, hint_style)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } -#endif - } - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_ft_font_options_substitute: - * @options: a #cairo_font_options_t object - * @pattern: an existing #FcPattern - * - * Add options to a #FcPattern based on a #cairo_font_options_t font - * options object. Options that are already in the pattern, are not overridden, - * so you should call this function after calling FcConfigSubstitute() (the - * user's settings should override options based on the surface type), but - * before calling FcDefaultSubstitute(). - * - * Since: 1.0 - **/ -void -cairo_ft_font_options_substitute (const cairo_font_options_t *options, - FcPattern *pattern) -{ - if (cairo_font_options_status ((cairo_font_options_t *) options)) - return; - - _cairo_ft_font_options_substitute (options, pattern); -} - -static cairo_font_face_t * -_cairo_ft_resolve_pattern (FcPattern *pattern, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *font_options) -{ - cairo_status_t status; - - cairo_matrix_t scale; - FcPattern *resolved; - cairo_ft_font_transform_t sf; - FcResult result; - cairo_ft_unscaled_font_t *unscaled; - cairo_ft_options_t ft_options; - cairo_font_face_t *font_face; - - scale = *ctm; - scale.x0 = scale.y0 = 0; - cairo_matrix_multiply (&scale, - font_matrix, - &scale); - - status = _compute_transform (&sf, &scale, NULL); - if (unlikely (status)) - return (cairo_font_face_t *)&_cairo_font_face_nil; - - pattern = FcPatternDuplicate (pattern); - if (pattern == NULL) - return (cairo_font_face_t *)&_cairo_font_face_nil; - - if (! FcPatternAddDouble (pattern, FC_PIXEL_SIZE, sf.y_scale)) { - font_face = (cairo_font_face_t *)&_cairo_font_face_nil; - goto FREE_PATTERN; - } - - if (! FcConfigSubstitute (NULL, pattern, FcMatchPattern)) { - font_face = (cairo_font_face_t *)&_cairo_font_face_nil; - goto FREE_PATTERN; - } - - status = _cairo_ft_font_options_substitute (font_options, pattern); - if (status) { - font_face = (cairo_font_face_t *)&_cairo_font_face_nil; - goto FREE_PATTERN; - } - - FcDefaultSubstitute (pattern); - - status = _cairo_ft_unscaled_font_create_for_pattern (pattern, &unscaled); - if (unlikely (status)) { - font_face = (cairo_font_face_t *)&_cairo_font_face_nil; - goto FREE_PATTERN; - } - - if (unscaled == NULL) { - resolved = FcFontMatch (NULL, pattern, &result); - if (!resolved) { - /* We failed to find any font. Substitute twin so that the user can - * see something (and hopefully recognise that the font is missing) - * and not just receive a NO_MEMORY error during rendering. - */ - font_face = _cairo_font_face_twin_create_fallback (); - goto FREE_PATTERN; - } - - status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled); - if (unlikely (status || unscaled == NULL)) { - font_face = (cairo_font_face_t *)&_cairo_font_face_nil; - goto FREE_RESOLVED; - } - } else - resolved = pattern; - - _get_pattern_ft_options (resolved, &ft_options); - font_face = _cairo_ft_font_face_create (unscaled, &ft_options); - _cairo_unscaled_font_destroy (&unscaled->base); - -FREE_RESOLVED: - if (resolved != pattern) - FcPatternDestroy (resolved); - -FREE_PATTERN: - FcPatternDestroy (pattern); - - return font_face; -} - -/** - * cairo_ft_font_face_create_for_pattern: - * @pattern: A fontconfig pattern. Cairo makes a copy of the pattern - * if it needs to. You are free to modify or free @pattern after this call. - * - * Creates a new font face for the FreeType font backend based on a - * fontconfig pattern. This font can then be used with - * cairo_set_font_face() or cairo_scaled_font_create(). The - * #cairo_scaled_font_t returned from cairo_scaled_font_create() is - * also for the FreeType backend and can be used with functions such - * as cairo_ft_scaled_font_lock_face(). - * - * Font rendering options are represented both here and when you - * call cairo_scaled_font_create(). Font options that have a representation - * in a #FcPattern must be passed in here; to modify #FcPattern - * appropriately to reflect the options in a #cairo_font_options_t, call - * cairo_ft_font_options_substitute(). - * - * The pattern's FC_FT_FACE element is inspected first and if that is set, - * that will be the FreeType font face associated with the returned cairo - * font face. Otherwise the FC_FILE element is checked. If it's set, - * that and the value of the FC_INDEX element (defaults to zero) of @pattern - * are used to load a font face from file. - * - * If both steps from the previous paragraph fails, @pattern will be passed - * to FcConfigSubstitute, FcDefaultSubstitute, and finally FcFontMatch, - * and the resulting font pattern is used. - * - * If the FC_FT_FACE element of @pattern is set, the user is responsible - * for making sure that the referenced FT_Face remains valid for the life - * time of the returned #cairo_font_face_t. See - * cairo_ft_font_face_create_for_ft_face() for an example of how to couple - * the life time of the FT_Face to that of the cairo font-face. - * - * Return value: a newly created #cairo_font_face_t. Free with - * cairo_font_face_destroy() when you are done using it. - * - * Since: 1.0 - **/ -cairo_font_face_t * -cairo_ft_font_face_create_for_pattern (FcPattern *pattern) -{ - cairo_ft_unscaled_font_t *unscaled; - cairo_font_face_t *font_face; - cairo_ft_options_t ft_options; - cairo_status_t status; - - status = _cairo_ft_unscaled_font_create_for_pattern (pattern, &unscaled); - if (unlikely (status)) - return (cairo_font_face_t *) &_cairo_font_face_nil; - if (unlikely (unscaled == NULL)) { - /* Store the pattern. We will resolve it and create unscaled - * font when creating scaled fonts */ - return _cairo_ft_font_face_create_for_pattern (pattern); - } - - _get_pattern_ft_options (pattern, &ft_options); - font_face = _cairo_ft_font_face_create (unscaled, &ft_options); - _cairo_unscaled_font_destroy (&unscaled->base); - - return font_face; -} -#endif - -/** - * cairo_ft_font_face_create_for_ft_face: - * @face: A FreeType face object, already opened. This must - * be kept around until the face's ref_count drops to - * zero and it is freed. Since the face may be referenced - * internally to Cairo, the best way to determine when it - * is safe to free the face is to pass a - * #cairo_destroy_func_t to cairo_font_face_set_user_data() - * @load_flags: flags to pass to FT_Load_Glyph when loading - * glyphs from the font. These flags are OR'ed together with - * the flags derived from the #cairo_font_options_t passed - * to cairo_scaled_font_create(), so only a few values such - * as %FT_LOAD_VERTICAL_LAYOUT, and %FT_LOAD_FORCE_AUTOHINT - * are useful. You should not pass any of the flags affecting - * the load target, such as %FT_LOAD_TARGET_LIGHT. - * - * Creates a new font face for the FreeType font backend from a - * pre-opened FreeType face. This font can then be used with - * cairo_set_font_face() or cairo_scaled_font_create(). The - * #cairo_scaled_font_t returned from cairo_scaled_font_create() is - * also for the FreeType backend and can be used with functions such - * as cairo_ft_scaled_font_lock_face(). Note that Cairo may keep a reference - * to the FT_Face alive in a font-cache and the exact lifetime of the reference - * depends highly upon the exact usage pattern and is subject to external - * factors. You must not call FT_Done_Face() before the last reference to the - * #cairo_font_face_t has been dropped. - * - * As an example, below is how one might correctly couple the lifetime of - * the FreeType face object to the #cairo_font_face_t. - * - * - * static const cairo_user_data_key_t key; - * - * font_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0); - * status = cairo_font_face_set_user_data (font_face, &key, - * ft_face, (cairo_destroy_func_t) FT_Done_Face); - * if (status) { - * cairo_font_face_destroy (font_face); - * FT_Done_Face (ft_face); - * return ERROR; - * } - * - * - * Return value: a newly created #cairo_font_face_t. Free with - * cairo_font_face_destroy() when you are done using it. - * - * Since: 1.0 - **/ -cairo_font_face_t * -cairo_ft_font_face_create_for_ft_face (FT_Face face, - int load_flags) -{ - cairo_ft_unscaled_font_t *unscaled; - cairo_font_face_t *font_face; - cairo_ft_options_t ft_options; - cairo_status_t status; - - status = _cairo_ft_unscaled_font_create_from_face (face, &unscaled); - if (unlikely (status)) - return (cairo_font_face_t *)&_cairo_font_face_nil; - - ft_options.load_flags = load_flags; - ft_options.synth_flags = 0; - _cairo_font_options_init_default (&ft_options.base); - - font_face = _cairo_ft_font_face_create (unscaled, &ft_options); - _cairo_unscaled_font_destroy (&unscaled->base); - - return font_face; -} - -/** - * cairo_ft_font_face_set_synthesize: - * @font_face: The #cairo_ft_font_face_t object to modify - * @synth_flags: the set of synthesis options to enable - * - * FreeType provides the ability to synthesize different glyphs from a base - * font, which is useful if you lack those glyphs from a true bold or oblique - * font. See also #cairo_ft_synthesize_t. - * - * Since: 1.12 - **/ -void -cairo_ft_font_face_set_synthesize (cairo_font_face_t *font_face, - unsigned int synth_flags) -{ - cairo_ft_font_face_t *ft; - - if (font_face->backend->type != CAIRO_FONT_TYPE_FT) - return; - - ft = (cairo_ft_font_face_t *) font_face; - ft->ft_options.synth_flags |= synth_flags; -} - -/** - * cairo_ft_font_face_unset_synthesize: - * @font_face: The #cairo_ft_font_face_t object to modify - * @synth_flags: the set of synthesis options to disable - * - * See cairo_ft_font_face_set_synthesize(). - * - * Since: 1.12 - **/ -void -cairo_ft_font_face_unset_synthesize (cairo_font_face_t *font_face, - unsigned int synth_flags) -{ - cairo_ft_font_face_t *ft; - - if (font_face->backend->type != CAIRO_FONT_TYPE_FT) - return; - - ft = (cairo_ft_font_face_t *) font_face; - ft->ft_options.synth_flags &= ~synth_flags; -} - -/** - * cairo_ft_font_face_get_synthesize: - * @font_face: The #cairo_ft_font_face_t object to query - * - * See #cairo_ft_synthesize_t. - * - * Returns: the current set of synthesis options. - * - * Since: 1.12 - **/ -unsigned int -cairo_ft_font_face_get_synthesize (cairo_font_face_t *font_face) -{ - cairo_ft_font_face_t *ft; - - if (font_face->backend->type != CAIRO_FONT_TYPE_FT) - return 0; - - ft = (cairo_ft_font_face_t *) font_face; - return ft->ft_options.synth_flags; -} - -/** - * cairo_ft_scaled_font_lock_face: - * @scaled_font: A #cairo_scaled_font_t from the FreeType font backend. Such an - * object can be created by calling cairo_scaled_font_create() on a - * FreeType backend font face (see cairo_ft_font_face_create_for_pattern(), - * cairo_ft_font_face_create_for_ft_face()). - * - * cairo_ft_scaled_font_lock_face() gets the #FT_Face object from a FreeType - * backend font and scales it appropriately for the font. You must - * release the face with cairo_ft_scaled_font_unlock_face() - * when you are done using it. Since the #FT_Face object can be - * shared between multiple #cairo_scaled_font_t objects, you must not - * lock any other font objects until you unlock this one. A count is - * kept of the number of times cairo_ft_scaled_font_lock_face() is - * called. cairo_ft_scaled_font_unlock_face() must be called the same number - * of times. - * - * You must be careful when using this function in a library or in a - * threaded application, because freetype's design makes it unsafe to - * call freetype functions simultaneously from multiple threads, (even - * if using distinct FT_Face objects). Because of this, application - * code that acquires an FT_Face object with this call must add its - * own locking to protect any use of that object, (and which also must - * protect any other calls into cairo as almost any cairo function - * might result in a call into the freetype library). - * - * Return value: The #FT_Face object for @font, scaled appropriately, - * or %NULL if @scaled_font is in an error state (see - * cairo_scaled_font_status()) or there is insufficient memory. - * - * Since: 1.0 - **/ -FT_Face -cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font) -{ - cairo_ft_scaled_font_t *scaled_font = (cairo_ft_scaled_font_t *) abstract_font; - FT_Face face; - cairo_status_t status; - - if (! _cairo_scaled_font_is_ft (abstract_font)) { - _cairo_error_throw (CAIRO_STATUS_FONT_TYPE_MISMATCH); - return NULL; - } - - if (scaled_font->base.status) - return NULL; - - face = _cairo_ft_unscaled_font_lock_face (scaled_font->unscaled); - if (unlikely (face == NULL)) { - status = _cairo_scaled_font_set_error (&scaled_font->base, CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled, - &scaled_font->base.scale); - if (unlikely (status)) { - _cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled); - status = _cairo_scaled_font_set_error (&scaled_font->base, status); - return NULL; - } - - /* Note: We deliberately release the unscaled font's mutex here, - * so that we are not holding a lock across two separate calls to - * cairo function, (which would give the application some - * opportunity for creating deadlock. This is obviously unsafe, - * but as documented, the user must add manual locking when using - * this function. */ - CAIRO_MUTEX_UNLOCK (scaled_font->unscaled->mutex); - - return face; -} - -/** - * cairo_ft_scaled_font_unlock_face: - * @scaled_font: A #cairo_scaled_font_t from the FreeType font backend. Such an - * object can be created by calling cairo_scaled_font_create() on a - * FreeType backend font face (see cairo_ft_font_face_create_for_pattern(), - * cairo_ft_font_face_create_for_ft_face()). - * - * Releases a face obtained with cairo_ft_scaled_font_lock_face(). - * - * Since: 1.0 - **/ -void -cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *abstract_font) -{ - cairo_ft_scaled_font_t *scaled_font = (cairo_ft_scaled_font_t *) abstract_font; - - if (! _cairo_scaled_font_is_ft (abstract_font)) { - _cairo_error_throw (CAIRO_STATUS_FONT_TYPE_MISMATCH); - return; - } - - if (scaled_font->base.status) - return; - - /* Note: We released the unscaled font's mutex at the end of - * cairo_ft_scaled_font_lock_face, so we have to acquire it again - * as _cairo_ft_unscaled_font_unlock_face expects it to be held - * when we call into it. */ - CAIRO_MUTEX_LOCK (scaled_font->unscaled->mutex); - - _cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled); -} - -static cairo_bool_t -_cairo_ft_scaled_font_is_vertical (cairo_scaled_font_t *scaled_font) -{ - cairo_ft_scaled_font_t *ft_scaled_font; - - if (!_cairo_scaled_font_is_ft (scaled_font)) - return FALSE; - - ft_scaled_font = (cairo_ft_scaled_font_t *) scaled_font; - if (ft_scaled_font->ft_options.load_flags & FT_LOAD_VERTICAL_LAYOUT) - return TRUE; - return FALSE; -} - -unsigned int -_cairo_ft_scaled_font_get_load_flags (cairo_scaled_font_t *scaled_font) -{ - cairo_ft_scaled_font_t *ft_scaled_font; - - if (! _cairo_scaled_font_is_ft (scaled_font)) - return 0; - - ft_scaled_font = (cairo_ft_scaled_font_t *) scaled_font; - return ft_scaled_font->ft_options.load_flags; -} - -void -_cairo_ft_font_reset_static_data (void) -{ - _cairo_ft_unscaled_font_map_destroy (); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-private.h deleted file mode 100644 index 0dc8114726f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft-private.h +++ /dev/null @@ -1,61 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Graydon Hoare - * Owen Taylor - */ - -#ifndef CAIRO_FT_PRIVATE_H -#define CAIRO_FT_PRIVATE_H - -#include "cairoint.h" -#include "cairo-ft.h" - -#if CAIRO_HAS_FT_FONT - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_ft_unscaled_font cairo_ft_unscaled_font_t; - -cairo_private cairo_bool_t -_cairo_scaled_font_is_ft (cairo_scaled_font_t *scaled_font); - -/* These functions are needed by the PDF backend, which needs to keep track of the - * the different fonts-on-disk used by a document, so it can embed them - */ -cairo_private unsigned int -_cairo_ft_scaled_font_get_load_flags (cairo_scaled_font_t *scaled_font); - -CAIRO_END_DECLS - -#endif /* CAIRO_HAS_FT_FONT */ -#endif /* CAIRO_FT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft.h deleted file mode 100644 index 29c43c9655b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ft.h +++ /dev/null @@ -1,118 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Graydon Hoare - * Owen Taylor - */ - -#ifndef CAIRO_FT_H -#define CAIRO_FT_H - -#include "cairo.h" - -#if CAIRO_HAS_FT_FONT - -/* Fontconfig/Freetype platform-specific font interface */ - -#include -#include FT_FREETYPE_H - -#if CAIRO_HAS_FC_FONT -#include -#endif - -CAIRO_BEGIN_DECLS - -cairo_public cairo_font_face_t * -cairo_ft_font_face_create_for_ft_face (FT_Face face, - int load_flags); - -/** - * cairo_ft_synthesize_t: - * @CAIRO_FT_SYNTHESIZE_BOLD: Embolden the glyphs (redraw with a pixel offset) - * @CAIRO_FT_SYNTHESIZE_OBLIQUE: Slant the glyph outline by 12 degrees to the - * right. - * - * A set of synthesis options to control how FreeType renders the glyphs - * for a particular font face. - * - * Individual synthesis features of a #cairo_ft_font_face_t can be set - * using cairo_ft_font_face_set_synthesize(), or disabled using - * cairo_ft_font_face_unset_synthesize(). The currently enabled set of - * synthesis options can be queried with cairo_ft_font_face_get_synthesize(). - * - * Note: that when synthesizing glyphs, the font metrics returned will only - * be estimates. - * - * Since: 1.12 - **/ -typedef enum { - CAIRO_FT_SYNTHESIZE_BOLD = 1 << 0, - CAIRO_FT_SYNTHESIZE_OBLIQUE = 1 << 1 -} cairo_ft_synthesize_t; - -cairo_public void -cairo_ft_font_face_set_synthesize (cairo_font_face_t *font_face, - unsigned int synth_flags); - -cairo_public void -cairo_ft_font_face_unset_synthesize (cairo_font_face_t *font_face, - unsigned int synth_flags); - -cairo_public unsigned int -cairo_ft_font_face_get_synthesize (cairo_font_face_t *font_face); - - -cairo_public FT_Face -cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *scaled_font); - -cairo_public void -cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *scaled_font); - -#if CAIRO_HAS_FC_FONT - -cairo_public cairo_font_face_t * -cairo_ft_font_face_create_for_pattern (FcPattern *pattern); - -cairo_public void -cairo_ft_font_options_substitute (const cairo_font_options_t *options, - FcPattern *pattern); - -#endif - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_FT_FONT */ -# error Cairo was not compiled with support for the freetype font backend -#endif /* CAIRO_HAS_FT_FONT */ - -#endif /* CAIRO_FT_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-composite.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-composite.c deleted file mode 100644 index b50f9a76c52..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-composite.c +++ /dev/null @@ -1,1265 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * Copyright © 2011 Linaro Limited - * Copyright © 2011 Samsung Electronics - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - * Alexandros Frantzis - * Henry Song - * Martin Robinson - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" - -cairo_int_status_t -_cairo_gl_composite_set_source (cairo_gl_composite_t *setup, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen) -{ - _cairo_gl_operand_destroy (&setup->src); - return _cairo_gl_operand_init (&setup->src, pattern, setup->dst, - sample, extents, use_texgen); -} - -void -_cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup, - const cairo_gl_operand_t *source) -{ - _cairo_gl_operand_destroy (&setup->src); - _cairo_gl_operand_copy (&setup->src, source); -} - -void -_cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup, - const cairo_color_t *color) -{ - _cairo_gl_operand_destroy (&setup->src); - _cairo_gl_solid_operand_init (&setup->src, color); -} - -cairo_int_status_t -_cairo_gl_composite_set_mask (cairo_gl_composite_t *setup, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen) -{ - _cairo_gl_operand_destroy (&setup->mask); - if (pattern == NULL) - return CAIRO_STATUS_SUCCESS; - - return _cairo_gl_operand_init (&setup->mask, pattern, setup->dst, - sample, extents, use_texgen); -} - -void -_cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup, - const cairo_gl_operand_t *mask) -{ - _cairo_gl_operand_destroy (&setup->mask); - if (mask) - _cairo_gl_operand_copy (&setup->mask, mask); -} - -void -_cairo_gl_composite_set_spans (cairo_gl_composite_t *setup) -{ - setup->spans = TRUE; -} - -void -_cairo_gl_composite_set_multisample (cairo_gl_composite_t *setup) -{ - setup->multisample = TRUE; -} - -void -_cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup, - cairo_region_t *clip_region) -{ - setup->clip_region = clip_region; -} - -void -_cairo_gl_composite_set_clip (cairo_gl_composite_t *setup, - cairo_clip_t *clip) -{ - setup->clip = clip; -} - -static void -_cairo_gl_composite_bind_to_shader (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup) -{ - _cairo_gl_shader_bind_matrix4f(ctx, ctx->current_shader->mvp_location, - ctx->modelviewprojection_matrix); - _cairo_gl_operand_bind_to_shader (ctx, &setup->src, CAIRO_GL_TEX_SOURCE); - _cairo_gl_operand_bind_to_shader (ctx, &setup->mask, CAIRO_GL_TEX_MASK); -} - -static void -_cairo_gl_texture_set_filter (cairo_gl_context_t *ctx, - GLuint target, - cairo_filter_t filter) -{ - switch (filter) { - case CAIRO_FILTER_FAST: - case CAIRO_FILTER_NEAREST: - glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - break; - case CAIRO_FILTER_GOOD: - case CAIRO_FILTER_BEST: - case CAIRO_FILTER_BILINEAR: - glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - break; - default: - case CAIRO_FILTER_GAUSSIAN: - ASSERT_NOT_REACHED; - } -} - -static void -_cairo_gl_texture_set_extend (cairo_gl_context_t *ctx, - GLuint target, - cairo_extend_t extend) -{ - GLint wrap_mode; - assert (! _cairo_gl_device_requires_power_of_two_textures (&ctx->base) || - (extend != CAIRO_EXTEND_REPEAT && extend != CAIRO_EXTEND_REFLECT)); - - switch (extend) { - case CAIRO_EXTEND_NONE: - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) - wrap_mode = GL_CLAMP_TO_EDGE; - else - wrap_mode = GL_CLAMP_TO_BORDER; - break; - case CAIRO_EXTEND_PAD: - wrap_mode = GL_CLAMP_TO_EDGE; - break; - case CAIRO_EXTEND_REPEAT: - if (ctx->has_npot_repeat) - wrap_mode = GL_REPEAT; - else - wrap_mode = GL_CLAMP_TO_EDGE; - break; - case CAIRO_EXTEND_REFLECT: - if (ctx->has_npot_repeat) - wrap_mode = GL_MIRRORED_REPEAT; - else - wrap_mode = GL_CLAMP_TO_EDGE; - break; - default: - wrap_mode = 0; - } - - if (likely (wrap_mode)) { - glTexParameteri (target, GL_TEXTURE_WRAP_S, wrap_mode); - glTexParameteri (target, GL_TEXTURE_WRAP_T, wrap_mode); - } -} - - -static void -_cairo_gl_context_setup_operand (cairo_gl_context_t *ctx, - cairo_gl_tex_t tex_unit, - cairo_gl_operand_t *operand, - unsigned int vertex_offset, - cairo_bool_t vertex_size_changed) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - cairo_bool_t needs_setup; - - /* XXX: we need to do setup when switching from shaders - * to no shaders (or back) */ - needs_setup = vertex_size_changed; - needs_setup |= _cairo_gl_operand_needs_setup (&ctx->operands[tex_unit], - operand, - vertex_offset); - - if (needs_setup) { - _cairo_gl_composite_flush (ctx); - _cairo_gl_context_destroy_operand (ctx, tex_unit); - } - - memcpy (&ctx->operands[tex_unit], operand, sizeof (cairo_gl_operand_t)); - ctx->operands[tex_unit].vertex_offset = vertex_offset; - - if (! needs_setup) - return; - - switch (operand->type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - break; - /* fall through */ - case CAIRO_GL_OPERAND_CONSTANT: - break; - case CAIRO_GL_OPERAND_TEXTURE: - glActiveTexture (GL_TEXTURE0 + tex_unit); - glBindTexture (ctx->tex_target, operand->texture.tex); - _cairo_gl_texture_set_extend (ctx, ctx->tex_target, - operand->texture.attributes.extend); - _cairo_gl_texture_set_filter (ctx, ctx->tex_target, - operand->texture.attributes.filter); - - if (! operand->texture.texgen) { - dispatch->VertexAttribPointer (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit, 2, - GL_FLOAT, GL_FALSE, ctx->vertex_size, - ctx->vb + vertex_offset); - dispatch->EnableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); - } - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - glActiveTexture (GL_TEXTURE0 + tex_unit); - glBindTexture (ctx->tex_target, operand->gradient.gradient->tex); - _cairo_gl_texture_set_extend (ctx, ctx->tex_target, operand->gradient.extend); - _cairo_gl_texture_set_filter (ctx, ctx->tex_target, CAIRO_FILTER_BILINEAR); - - if (! operand->gradient.texgen) { - dispatch->VertexAttribPointer (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit, 2, - GL_FLOAT, GL_FALSE, ctx->vertex_size, - ctx->vb + vertex_offset); - dispatch->EnableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); - } - break; - } -} - -static void -_cairo_gl_context_setup_spans (cairo_gl_context_t *ctx, - cairo_bool_t spans_enabled, - unsigned int vertex_size, - unsigned int vertex_offset) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - - if (! spans_enabled) { - dispatch->DisableVertexAttribArray (CAIRO_GL_COLOR_ATTRIB_INDEX); - ctx->spans = FALSE; - return; - } - - dispatch->VertexAttribPointer (CAIRO_GL_COLOR_ATTRIB_INDEX, 4, - GL_UNSIGNED_BYTE, GL_TRUE, vertex_size, - ctx->vb + vertex_offset); - dispatch->EnableVertexAttribArray (CAIRO_GL_COLOR_ATTRIB_INDEX); - ctx->spans = TRUE; -} - -void -_cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx, - cairo_gl_tex_t tex_unit) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - - if (!_cairo_gl_context_is_flushed (ctx)) - _cairo_gl_composite_flush (ctx); - - switch (ctx->operands[tex_unit].type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - break; - /* fall through */ - case CAIRO_GL_OPERAND_CONSTANT: - break; - case CAIRO_GL_OPERAND_TEXTURE: - dispatch->DisableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - dispatch->DisableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); - break; - } - - memset (&ctx->operands[tex_unit], 0, sizeof (cairo_gl_operand_t)); -} - -static void -_cairo_gl_set_operator (cairo_gl_context_t *ctx, - cairo_operator_t op, - cairo_bool_t component_alpha) -{ - struct { - GLenum src; - GLenum dst; - } blend_factors[] = { - { GL_ZERO, GL_ZERO }, /* Clear */ - { GL_ONE, GL_ZERO }, /* Source */ - { GL_ONE, GL_ONE_MINUS_SRC_ALPHA }, /* Over */ - { GL_DST_ALPHA, GL_ZERO }, /* In */ - { GL_ONE_MINUS_DST_ALPHA, GL_ZERO }, /* Out */ - { GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, /* Atop */ - - { GL_ZERO, GL_ONE }, /* Dest */ - { GL_ONE_MINUS_DST_ALPHA, GL_ONE }, /* DestOver */ - { GL_ZERO, GL_SRC_ALPHA }, /* DestIn */ - { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }, /* DestOut */ - { GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA }, /* DestAtop */ - - { GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, /* Xor */ - { GL_ONE, GL_ONE }, /* Add */ - }; - GLenum src_factor, dst_factor; - - assert (op < ARRAY_LENGTH (blend_factors)); - /* different dst and component_alpha changes cause flushes elsewhere */ - if (ctx->current_operator != op) - _cairo_gl_composite_flush (ctx); - ctx->current_operator = op; - - src_factor = blend_factors[op].src; - dst_factor = blend_factors[op].dst; - - /* Even when the user requests CAIRO_CONTENT_COLOR, we use GL_RGBA - * due to texture filtering of GL_CLAMP_TO_BORDER. So fix those - * bits in that case. - */ - if (ctx->current_target->base.content == CAIRO_CONTENT_COLOR) { - if (src_factor == GL_ONE_MINUS_DST_ALPHA) - src_factor = GL_ZERO; - if (src_factor == GL_DST_ALPHA) - src_factor = GL_ONE; - } - - if (component_alpha) { - if (dst_factor == GL_ONE_MINUS_SRC_ALPHA) - dst_factor = GL_ONE_MINUS_SRC_COLOR; - if (dst_factor == GL_SRC_ALPHA) - dst_factor = GL_SRC_COLOR; - } - - if (ctx->current_target->base.content == CAIRO_CONTENT_ALPHA) { - glBlendFuncSeparate (GL_ZERO, GL_ZERO, src_factor, dst_factor); - } else if (ctx->current_target->base.content == CAIRO_CONTENT_COLOR) { - glBlendFuncSeparate (src_factor, dst_factor, GL_ONE, GL_ONE); - } else { - glBlendFunc (src_factor, dst_factor); - } -} - -static cairo_status_t -_cairo_gl_composite_begin_component_alpha (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup) -{ - cairo_gl_shader_t *pre_shader = NULL; - cairo_status_t status; - - /* For CLEAR, cairo's rendering equation (quoting Owen's description in: - * http://lists.cairographics.org/archives/cairo/2005-August/004992.html) - * is: - * mask IN clip ? src OP dest : dest - * or more simply: - * mask IN CLIP ? 0 : dest - * - * where the ternary operator A ? B : C is (A * B) + ((1 - A) * C). - * - * The model we use in _cairo_gl_set_operator() is Render's: - * src IN mask IN clip OP dest - * which would boil down to: - * 0 (bounded by the extents of the drawing). - * - * However, we can do a Render operation using an opaque source - * and DEST_OUT to produce: - * 1 IN mask IN clip DEST_OUT dest - * which is - * mask IN clip ? 0 : dest - */ - if (setup->op == CAIRO_OPERATOR_CLEAR) { - _cairo_gl_solid_operand_init (&setup->src, CAIRO_COLOR_WHITE); - setup->op = CAIRO_OPERATOR_DEST_OUT; - } - - /* - * implements component-alpha %CAIRO_OPERATOR_OVER using two passes of - * the simpler operations %CAIRO_OPERATOR_DEST_OUT and %CAIRO_OPERATOR_ADD. - * - * From http://anholt.livejournal.com/32058.html: - * - * The trouble is that component-alpha rendering requires two different sources - * for blending: one for the source value to the blender, which is the - * per-channel multiplication of source and mask, and one for the source alpha - * for multiplying with the destination channels, which is the multiplication - * of the source channels by the mask alpha. So the equation for Over is: - * - * dst.A = src.A * mask.A + (1 - (src.A * mask.A)) * dst.A - * dst.R = src.R * mask.R + (1 - (src.A * mask.R)) * dst.R - * dst.G = src.G * mask.G + (1 - (src.A * mask.G)) * dst.G - * dst.B = src.B * mask.B + (1 - (src.A * mask.B)) * dst.B - * - * But we can do some simpler operations, right? How about PictOpOutReverse, - * which has a source factor of 0 and dest factor of (1 - source alpha). We - * can get the source alpha value (srca.X = src.A * mask.X) out of the texture - * blenders pretty easily. So we can do a component-alpha OutReverse, which - * gets us: - * - * dst.A = 0 + (1 - (src.A * mask.A)) * dst.A - * dst.R = 0 + (1 - (src.A * mask.R)) * dst.R - * dst.G = 0 + (1 - (src.A * mask.G)) * dst.G - * dst.B = 0 + (1 - (src.A * mask.B)) * dst.B - * - * OK. And if an op doesn't use the source alpha value for the destination - * factor, then we can do the channel multiplication in the texture blenders - * to get the source value, and ignore the source alpha that we wouldn't use. - * We've supported this in the Radeon driver for a long time. An example would - * be PictOpAdd, which does: - * - * dst.A = src.A * mask.A + dst.A - * dst.R = src.R * mask.R + dst.R - * dst.G = src.G * mask.G + dst.G - * dst.B = src.B * mask.B + dst.B - * - * Hey, this looks good! If we do a PictOpOutReverse and then a PictOpAdd right - * after it, we get: - * - * dst.A = src.A * mask.A + ((1 - (src.A * mask.A)) * dst.A) - * dst.R = src.R * mask.R + ((1 - (src.A * mask.R)) * dst.R) - * dst.G = src.G * mask.G + ((1 - (src.A * mask.G)) * dst.G) - * dst.B = src.B * mask.B + ((1 - (src.A * mask.B)) * dst.B) - * - * This two-pass trickery could be avoided using a new GL extension that - * lets two values come out of the shader and into the blend unit. - */ - if (setup->op == CAIRO_OPERATOR_OVER) { - setup->op = CAIRO_OPERATOR_ADD; - status = _cairo_gl_get_shader_by_type (ctx, - &setup->src, - &setup->mask, - setup->spans, - CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA, - &pre_shader); - if (unlikely (status)) - return status; - } - - if (ctx->pre_shader != pre_shader) - _cairo_gl_composite_flush (ctx); - ctx->pre_shader = pre_shader; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_scissor_to_doubles (cairo_gl_surface_t *surface, - double x1, double y1, - double x2, double y2) -{ - double height; - - height = y2 - y1; - if (_cairo_gl_surface_is_texture (surface) == FALSE) - y1 = surface->height - (y1 + height); - glScissor (x1, y1, x2 - x1, height); - glEnable (GL_SCISSOR_TEST); -} - -void -_cairo_gl_scissor_to_rectangle (cairo_gl_surface_t *surface, - const cairo_rectangle_int_t *r) -{ - _scissor_to_doubles (surface, r->x, r->y, r->x+r->width, r->y+r->height); -} - -static void -_scissor_to_box (cairo_gl_surface_t *surface, - const cairo_box_t *box) -{ - double x1, y1, x2, y2; - _cairo_box_to_doubles (box, &x1, &y1, &x2, &y2); - _scissor_to_doubles (surface, x1, y1, x2, y2); -} - -static cairo_bool_t -_cairo_gl_composite_setup_vbo (cairo_gl_context_t *ctx, - unsigned int size_per_vertex) -{ - cairo_bool_t vertex_size_changed = ctx->vertex_size != size_per_vertex; - if (vertex_size_changed) { - ctx->vertex_size = size_per_vertex; - _cairo_gl_composite_flush (ctx); - } - - if (_cairo_gl_context_is_flushed (ctx)) { - ctx->dispatch.VertexAttribPointer (CAIRO_GL_VERTEX_ATTRIB_INDEX, 2, - GL_FLOAT, GL_FALSE, size_per_vertex, - ctx->vb); - ctx->dispatch.EnableVertexAttribArray (CAIRO_GL_VERTEX_ATTRIB_INDEX); - } - - return vertex_size_changed; -} - -static void -_disable_stencil_buffer (void) -{ - glDisable (GL_STENCIL_TEST); - glDepthMask (GL_FALSE); -} - -static cairo_int_status_t -_cairo_gl_composite_setup_painted_clipping (cairo_gl_composite_t *setup, - cairo_gl_context_t *ctx, - int vertex_size) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - - cairo_gl_surface_t *dst = setup->dst; - cairo_clip_t *clip = setup->clip; - - if (clip->num_boxes == 1 && clip->path == NULL) { - _scissor_to_box (dst, &clip->boxes[0]); - goto disable_stencil_buffer_and_return; - } - - if (! _cairo_gl_ensure_stencil (ctx, setup->dst)) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto disable_stencil_buffer_and_return; - } - - /* We only want to clear the part of the stencil buffer - * that we are about to use. It also does not hurt to - * scissor around the painted clip. */ - _cairo_gl_scissor_to_rectangle (dst, _cairo_clip_get_extents (clip)); - - /* The clip is not rectangular, so use the stencil buffer. */ - glDepthMask (GL_TRUE); - glEnable (GL_STENCIL_TEST); - - /* Texture surfaces have private depth/stencil buffers, so we can - * rely on any previous clip being cached there. */ - if (_cairo_gl_surface_is_texture (setup->dst)) { - cairo_clip_t *old_clip = setup->dst->clip_on_stencil_buffer; - if (_cairo_clip_equal (old_clip, setup->clip)) - goto activate_stencil_buffer_and_return; - - if (old_clip) { - _cairo_clip_destroy (setup->dst->clip_on_stencil_buffer); - } - - setup->dst->clip_on_stencil_buffer = _cairo_clip_copy (setup->clip); - } - - glClearStencil (0); - glClear (GL_STENCIL_BUFFER_BIT); - - glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc (GL_EQUAL, 1, 0xffffffff); - glColorMask (0, 0, 0, 0); - - status = _cairo_gl_msaa_compositor_draw_clip (ctx, setup, clip); - - if (unlikely (status)) { - glColorMask (1, 1, 1, 1); - goto disable_stencil_buffer_and_return; - } - - /* We want to only render to the stencil buffer, so draw everything now. - Flushing also unbinds the VBO, which we want to rebind for regular - drawing. */ - _cairo_gl_composite_flush (ctx); - _cairo_gl_composite_setup_vbo (ctx, vertex_size); - -activate_stencil_buffer_and_return: - glColorMask (1, 1, 1, 1); - glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc (GL_EQUAL, 1, 0xffffffff); - return CAIRO_INT_STATUS_SUCCESS; - -disable_stencil_buffer_and_return: - _disable_stencil_buffer (); - return status; -} - -static cairo_int_status_t -_cairo_gl_composite_setup_clipping (cairo_gl_composite_t *setup, - cairo_gl_context_t *ctx, - int vertex_size) -{ - cairo_bool_t clip_changing = TRUE; - cairo_bool_t clip_region_changing = TRUE; - - if (! ctx->clip && ! setup->clip && ! setup->clip_region && ! ctx->clip_region) - goto disable_all_clipping; - - clip_changing = ! _cairo_clip_equal (ctx->clip, setup->clip); - clip_region_changing = ! cairo_region_equal (ctx->clip_region, setup->clip_region); - if (! _cairo_gl_context_is_flushed (ctx) && - (clip_region_changing || clip_changing)) - _cairo_gl_composite_flush (ctx); - - assert (!setup->clip_region || !setup->clip); - - /* setup->clip is only used by the msaa compositor and setup->clip_region - * only by the other compositors, so it's safe to wait to clean up obsolete - * clips. */ - if (clip_region_changing) { - cairo_region_destroy (ctx->clip_region); - ctx->clip_region = cairo_region_reference (setup->clip_region); - } - if (clip_changing) { - _cairo_clip_destroy (ctx->clip); - ctx->clip = _cairo_clip_copy (setup->clip); - } - - /* For clip regions, we scissor right before drawing. */ - if (setup->clip_region) - goto disable_all_clipping; - - if (setup->clip) - return _cairo_gl_composite_setup_painted_clipping (setup, ctx, - vertex_size); -disable_all_clipping: - _disable_stencil_buffer (); - glDisable (GL_SCISSOR_TEST); - return CAIRO_INT_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gl_set_operands_and_operator (cairo_gl_composite_t *setup, - cairo_gl_context_t *ctx) -{ - unsigned int dst_size, src_size, mask_size, vertex_size; - cairo_status_t status; - cairo_gl_shader_t *shader; - cairo_bool_t component_alpha; - cairo_bool_t vertex_size_changed; - - component_alpha = - setup->mask.type == CAIRO_GL_OPERAND_TEXTURE && - setup->mask.texture.attributes.has_component_alpha; - - /* Do various magic for component alpha */ - if (component_alpha) { - status = _cairo_gl_composite_begin_component_alpha (ctx, setup); - if (unlikely (status)) - return status; - } else { - if (ctx->pre_shader) { - _cairo_gl_composite_flush (ctx); - ctx->pre_shader = NULL; - } - } - - status = _cairo_gl_get_shader_by_type (ctx, - &setup->src, - &setup->mask, - setup->spans, - component_alpha ? - CAIRO_GL_SHADER_IN_CA_SOURCE : - CAIRO_GL_SHADER_IN_NORMAL, - &shader); - if (unlikely (status)) { - ctx->pre_shader = NULL; - return status; - } - if (ctx->current_shader != shader) - _cairo_gl_composite_flush (ctx); - - status = CAIRO_STATUS_SUCCESS; - - dst_size = 2 * sizeof (GLfloat); - src_size = _cairo_gl_operand_get_vertex_size (&setup->src); - mask_size = _cairo_gl_operand_get_vertex_size (&setup->mask); - vertex_size = dst_size + src_size + mask_size; - - if (setup->spans) - vertex_size += sizeof (GLfloat); - - vertex_size_changed = _cairo_gl_composite_setup_vbo (ctx, vertex_size); - - _cairo_gl_context_setup_operand (ctx, CAIRO_GL_TEX_SOURCE, &setup->src, dst_size, vertex_size_changed); - _cairo_gl_context_setup_operand (ctx, CAIRO_GL_TEX_MASK, &setup->mask, dst_size + src_size, vertex_size_changed); - - _cairo_gl_context_setup_spans (ctx, setup->spans, vertex_size, - dst_size + src_size + mask_size); - - _cairo_gl_set_operator (ctx, setup->op, component_alpha); - - if (_cairo_gl_context_is_flushed (ctx)) { - if (ctx->pre_shader) { - _cairo_gl_set_shader (ctx, ctx->pre_shader); - _cairo_gl_composite_bind_to_shader (ctx, setup); - } - _cairo_gl_set_shader (ctx, shader); - _cairo_gl_composite_bind_to_shader (ctx, setup); - } - - return status; -} - -cairo_status_t -_cairo_gl_composite_begin (cairo_gl_composite_t *setup, - cairo_gl_context_t **ctx_out) -{ - cairo_gl_context_t *ctx; - cairo_status_t status; - - assert (setup->dst); - - status = _cairo_gl_context_acquire (setup->dst->base.device, &ctx); - if (unlikely (status)) - return status; - - _cairo_gl_context_set_destination (ctx, setup->dst, setup->multisample); - glEnable (GL_BLEND); - - status = _cairo_gl_set_operands_and_operator (setup, ctx); - if (unlikely (status)) - goto FAIL; - - status = _cairo_gl_composite_setup_clipping (setup, ctx, ctx->vertex_size); - if (unlikely (status)) - goto FAIL; - - *ctx_out = ctx; - -FAIL: - if (unlikely (status)) - status = _cairo_gl_context_release (ctx, status); - - return status; -} - -static inline void -_cairo_gl_composite_draw_tristrip (cairo_gl_context_t *ctx) -{ - cairo_array_t* indices = &ctx->tristrip_indices; - const unsigned short *indices_array = _cairo_array_index_const (indices, 0); - - if (ctx->pre_shader) { - cairo_gl_shader_t *prev_shader = ctx->current_shader; - - _cairo_gl_set_shader (ctx, ctx->pre_shader); - _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_DEST_OUT, TRUE); - glDrawElements (GL_TRIANGLE_STRIP, _cairo_array_num_elements (indices), GL_UNSIGNED_SHORT, indices_array); - - _cairo_gl_set_shader (ctx, prev_shader); - _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_ADD, TRUE); - } - - glDrawElements (GL_TRIANGLE_STRIP, _cairo_array_num_elements (indices), GL_UNSIGNED_SHORT, indices_array); - _cairo_array_truncate (indices, 0); -} - -static inline void -_cairo_gl_composite_draw_triangles (cairo_gl_context_t *ctx, - unsigned int count) -{ - if (! ctx->pre_shader) { - glDrawArrays (GL_TRIANGLES, 0, count); - } else { - cairo_gl_shader_t *prev_shader = ctx->current_shader; - - _cairo_gl_set_shader (ctx, ctx->pre_shader); - _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_DEST_OUT, TRUE); - glDrawArrays (GL_TRIANGLES, 0, count); - - _cairo_gl_set_shader (ctx, prev_shader); - _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_ADD, TRUE); - glDrawArrays (GL_TRIANGLES, 0, count); - } -} - -static void -_cairo_gl_composite_draw_triangles_with_clip_region (cairo_gl_context_t *ctx, - unsigned int count) -{ - int i, num_rectangles; - - if (!ctx->clip_region) { - _cairo_gl_composite_draw_triangles (ctx, count); - return; - } - - num_rectangles = cairo_region_num_rectangles (ctx->clip_region); - for (i = 0; i < num_rectangles; i++) { - cairo_rectangle_int_t rect; - - cairo_region_get_rectangle (ctx->clip_region, i, &rect); - - _cairo_gl_scissor_to_rectangle (ctx->current_target, &rect); - _cairo_gl_composite_draw_triangles (ctx, count); - } -} - -static void -_cairo_gl_composite_unmap_vertex_buffer (cairo_gl_context_t *ctx) -{ - ctx->vb_offset = 0; -} - -void -_cairo_gl_composite_flush (cairo_gl_context_t *ctx) -{ - unsigned int count; - int i; - - if (_cairo_gl_context_is_flushed (ctx)) - return; - - count = ctx->vb_offset / ctx->vertex_size; - _cairo_gl_composite_unmap_vertex_buffer (ctx); - - if (ctx->primitive_type == CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS) { - _cairo_gl_composite_draw_tristrip (ctx); - } else { - assert (ctx->primitive_type == CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); - _cairo_gl_composite_draw_triangles_with_clip_region (ctx, count); - } - - for (i = 0; i < ARRAY_LENGTH (&ctx->glyph_cache); i++) - _cairo_gl_glyph_cache_unlock (&ctx->glyph_cache[i]); -} - -static void -_cairo_gl_composite_prepare_buffer (cairo_gl_context_t *ctx, - unsigned int n_vertices, - cairo_gl_primitive_type_t primitive_type) -{ - if (ctx->primitive_type != primitive_type) { - _cairo_gl_composite_flush (ctx); - ctx->primitive_type = primitive_type; - } - - assert(ctx->vbo_size > 0); - if (ctx->vb_offset + n_vertices * ctx->vertex_size > ctx->vbo_size) - _cairo_gl_composite_flush (ctx); -} - -static inline void -_cairo_gl_composite_emit_vertex (cairo_gl_context_t *ctx, - GLfloat x, GLfloat y) -{ - GLfloat *vb = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; - - *vb++ = x; - *vb++ = y; - - _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_SOURCE], &vb, x, y); - _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_MASK ], &vb, x, y); - - ctx->vb_offset += ctx->vertex_size; -} - -static inline void -_cairo_gl_composite_emit_alpha_vertex (cairo_gl_context_t *ctx, - GLfloat x, GLfloat y, uint8_t alpha) -{ - GLfloat *vb = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; - union fi { - float f; - GLbyte bytes[4]; - } fi; - - *vb++ = x; - *vb++ = y; - - _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_SOURCE], &vb, x, y); - _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_MASK ], &vb, x, y); - - fi.bytes[0] = 0; - fi.bytes[1] = 0; - fi.bytes[2] = 0; - fi.bytes[3] = alpha; - *vb++ = fi.f; - - ctx->vb_offset += ctx->vertex_size; -} - -static void -_cairo_gl_composite_emit_point (cairo_gl_context_t *ctx, - const cairo_point_t *point) -{ - _cairo_gl_composite_emit_vertex (ctx, - _cairo_fixed_to_double (point->x), - _cairo_fixed_to_double (point->y)); -} - -static void -_cairo_gl_composite_emit_rect (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2) -{ - _cairo_gl_composite_prepare_buffer (ctx, 6, - CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); - - _cairo_gl_composite_emit_vertex (ctx, x1, y1); - _cairo_gl_composite_emit_vertex (ctx, x2, y1); - _cairo_gl_composite_emit_vertex (ctx, x1, y2); - - _cairo_gl_composite_emit_vertex (ctx, x2, y1); - _cairo_gl_composite_emit_vertex (ctx, x2, y2); - _cairo_gl_composite_emit_vertex (ctx, x1, y2); -} - -cairo_gl_emit_rect_t -_cairo_gl_context_choose_emit_rect (cairo_gl_context_t *ctx) -{ - return _cairo_gl_composite_emit_rect; -} - -void -_cairo_gl_context_emit_rect (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2) -{ - _cairo_gl_composite_emit_rect (ctx, x1, y1, x2, y2); -} - -static void -_cairo_gl_composite_emit_span (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2, - uint8_t alpha) -{ - _cairo_gl_composite_prepare_buffer (ctx, 6, - CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); - - _cairo_gl_composite_emit_alpha_vertex (ctx, x1, y1, alpha); - _cairo_gl_composite_emit_alpha_vertex (ctx, x2, y1, alpha); - _cairo_gl_composite_emit_alpha_vertex (ctx, x1, y2, alpha); - - _cairo_gl_composite_emit_alpha_vertex (ctx, x2, y1, alpha); - _cairo_gl_composite_emit_alpha_vertex (ctx, x2, y2, alpha); - _cairo_gl_composite_emit_alpha_vertex (ctx, x1, y2, alpha); -} - -static void -_cairo_gl_composite_emit_solid_span (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2, - uint8_t alpha) -{ - GLfloat *v; - union fi { - float f; - GLbyte bytes[4]; - } fi; - - _cairo_gl_composite_prepare_buffer (ctx, 6, - CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); - v = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; - - v[15] = v[ 6] = v[0] = x1; - v[10] = v[ 4] = v[1] = y1; - v[12] = v[ 9] = v[3] = x2; - v[16] = v[13] = v[7] = y2; - - fi.bytes[0] = 0; - fi.bytes[1] = 0; - fi.bytes[2] = 0; - fi.bytes[3] = alpha; - v[17] =v[14] = v[11] = v[8] = v[5] = v[2] = fi.f; - - ctx->vb_offset += 6*3 * sizeof(GLfloat); -} - -cairo_gl_emit_span_t -_cairo_gl_context_choose_emit_span (cairo_gl_context_t *ctx) -{ - if (ctx->operands[CAIRO_GL_TEX_MASK].type != CAIRO_GL_OPERAND_NONE) { - switch (ctx->operands[CAIRO_GL_TEX_MASK].type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - break; - - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - if (!ctx->operands[CAIRO_GL_TEX_MASK].gradient.texgen) - return _cairo_gl_composite_emit_span; - break; - - case CAIRO_GL_OPERAND_TEXTURE: - if (!ctx->operands[CAIRO_GL_TEX_MASK].texture.texgen) - return _cairo_gl_composite_emit_span; - break; - } - } - - switch (ctx->operands[CAIRO_GL_TEX_SOURCE].type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - break; - - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - if (!ctx->operands[CAIRO_GL_TEX_SOURCE].gradient.texgen) - return _cairo_gl_composite_emit_span; - break; - - case CAIRO_GL_OPERAND_TEXTURE: - if (!ctx->operands[CAIRO_GL_TEX_SOURCE].texture.texgen) - return _cairo_gl_composite_emit_span; - } - - return _cairo_gl_composite_emit_solid_span; -} - -static inline void -_cairo_gl_composite_emit_glyph_vertex (cairo_gl_context_t *ctx, - GLfloat x, GLfloat y, - GLfloat glyph_x, GLfloat glyph_y) -{ - GLfloat *vb = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; - - *vb++ = x; - *vb++ = y; - - _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_SOURCE], &vb, x, y); - - *vb++ = glyph_x; - *vb++ = glyph_y; - - ctx->vb_offset += ctx->vertex_size; -} - -static void -_cairo_gl_composite_emit_glyph (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2, - GLfloat glyph_x1, GLfloat glyph_y1, - GLfloat glyph_x2, GLfloat glyph_y2) -{ - _cairo_gl_composite_prepare_buffer (ctx, 6, - CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); - - _cairo_gl_composite_emit_glyph_vertex (ctx, x1, y1, glyph_x1, glyph_y1); - _cairo_gl_composite_emit_glyph_vertex (ctx, x2, y1, glyph_x2, glyph_y1); - _cairo_gl_composite_emit_glyph_vertex (ctx, x1, y2, glyph_x1, glyph_y2); - - _cairo_gl_composite_emit_glyph_vertex (ctx, x2, y1, glyph_x2, glyph_y1); - _cairo_gl_composite_emit_glyph_vertex (ctx, x2, y2, glyph_x2, glyph_y2); - _cairo_gl_composite_emit_glyph_vertex (ctx, x1, y2, glyph_x1, glyph_y2); -} - -static void -_cairo_gl_composite_emit_solid_glyph (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2, - GLfloat glyph_x1, GLfloat glyph_y1, - GLfloat glyph_x2, GLfloat glyph_y2) -{ - GLfloat *v; - - _cairo_gl_composite_prepare_buffer (ctx, 6, - CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); - - v = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; - - v[20] = v[ 8] = v[0] = x1; - v[13] = v[ 5] = v[1] = y1; - v[22] = v[10] = v[2] = glyph_x1; - v[15] = v[ 7] = v[3] = glyph_y1; - - v[16] = v[12] = v[4] = x2; - v[18] = v[14] = v[6] = glyph_x2; - - v[21] = v[17] = v[ 9] = y2; - v[23] = v[19] = v[11] = glyph_y2; - - ctx->vb_offset += 4 * 6 * sizeof (GLfloat); -} - -cairo_gl_emit_glyph_t -_cairo_gl_context_choose_emit_glyph (cairo_gl_context_t *ctx) -{ - switch (ctx->operands[CAIRO_GL_TEX_SOURCE].type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - return _cairo_gl_composite_emit_solid_glyph; - - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - case CAIRO_GL_OPERAND_TEXTURE: - return _cairo_gl_composite_emit_glyph; - } -} - -void -_cairo_gl_composite_fini (cairo_gl_composite_t *setup) -{ - _cairo_gl_operand_destroy (&setup->src); - _cairo_gl_operand_destroy (&setup->mask); -} - -cairo_status_t -_cairo_gl_composite_set_operator (cairo_gl_composite_t *setup, - cairo_operator_t op, - cairo_bool_t assume_component_alpha) -{ - if (assume_component_alpha) { - if (op != CAIRO_OPERATOR_CLEAR && - op != CAIRO_OPERATOR_OVER && - op != CAIRO_OPERATOR_ADD) - return UNSUPPORTED ("unsupported component alpha operator"); - } else { - if (! _cairo_gl_operator_is_supported (op)) - return UNSUPPORTED ("unsupported operator"); - } - - setup->op = op; - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gl_composite_init (cairo_gl_composite_t *setup, - cairo_operator_t op, - cairo_gl_surface_t *dst, - cairo_bool_t assume_component_alpha) -{ - cairo_status_t status; - - memset (setup, 0, sizeof (cairo_gl_composite_t)); - - status = _cairo_gl_composite_set_operator (setup, op, - assume_component_alpha); - if (status) - return status; - - setup->dst = dst; - setup->clip_region = dst->clip_region; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_gl_composite_append_vertex_indices (cairo_gl_context_t *ctx, - int number_of_new_indices) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - cairo_array_t *indices = &ctx->tristrip_indices; - int number_of_indices = _cairo_array_num_elements (indices); - unsigned short current_vertex_index = 0; - int i; - - assert (number_of_new_indices > 0); - - /* If any preexisting triangle triangle strip indices exist on this - context, we insert a set of degenerate triangles from the last - preexisting vertex to our first one. */ - if (number_of_indices > 0) { - const unsigned short *indices_array = _cairo_array_index_const (indices, 0); - current_vertex_index = indices_array[number_of_indices - 1]; - - status = _cairo_array_append (indices, ¤t_vertex_index); - if (unlikely (status)) - return status; - - current_vertex_index++; - status =_cairo_array_append (indices, ¤t_vertex_index); - if (unlikely (status)) - return status; - } - - for (i = 0; i < number_of_new_indices; i++) { - status = _cairo_array_append (indices, ¤t_vertex_index); - current_vertex_index++; - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - const cairo_point_t quad[4]) -{ - _cairo_gl_composite_prepare_buffer (ctx, 4, - CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS); - - _cairo_gl_composite_emit_point (ctx, &quad[0]); - _cairo_gl_composite_emit_point (ctx, &quad[1]); - - /* Cairo stores quad vertices in counter-clockwise order, but we need to - emit them from top to bottom in the triangle strip, so we need to reverse - the order of the last two vertices. */ - _cairo_gl_composite_emit_point (ctx, &quad[3]); - _cairo_gl_composite_emit_point (ctx, &quad[2]); - - return _cairo_gl_composite_append_vertex_indices (ctx, 4); -} - -cairo_int_status_t -_cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - const cairo_point_t triangle[3]) -{ - _cairo_gl_composite_prepare_buffer (ctx, 3, - CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS); - - _cairo_gl_composite_emit_point (ctx, &triangle[0]); - _cairo_gl_composite_emit_point (ctx, &triangle[1]); - _cairo_gl_composite_emit_point (ctx, &triangle[2]); - return _cairo_gl_composite_append_vertex_indices (ctx, 3); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-device.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-device.c deleted file mode 100644 index 7235d9ae123..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-device.c +++ /dev/null @@ -1,804 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * Copyright © 2010 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - * Alexandros Frantzis - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-gl-private.h" - -#define MAX_MSAA_SAMPLES 4 - -static void -_gl_lock (void *device) -{ - cairo_gl_context_t *ctx = (cairo_gl_context_t *) device; - - ctx->acquire (ctx); -} - -static void -_gl_unlock (void *device) -{ - cairo_gl_context_t *ctx = (cairo_gl_context_t *) device; - - ctx->release (ctx); -} - -static cairo_status_t -_gl_flush (void *device) -{ - cairo_gl_context_t *ctx; - cairo_status_t status; - - status = _cairo_gl_context_acquire (device, &ctx); - if (unlikely (status)) - return status; - - _cairo_gl_composite_flush (ctx); - - _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_SOURCE); - _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_MASK); - - if (ctx->clip_region) { - cairo_region_destroy (ctx->clip_region); - ctx->clip_region = NULL; - } - - ctx->current_target = NULL; - ctx->current_operator = -1; - ctx->vertex_size = 0; - ctx->pre_shader = NULL; - _cairo_gl_set_shader (ctx, NULL); - - ctx->dispatch.BindBuffer (GL_ARRAY_BUFFER, 0); - - glDisable (GL_SCISSOR_TEST); - glDisable (GL_BLEND); - - return _cairo_gl_context_release (ctx, status); -} - -static void -_gl_finish (void *device) -{ - cairo_gl_context_t *ctx = device; - int n; - - _gl_lock (device); - - _cairo_cache_fini (&ctx->gradients); - - _cairo_gl_context_fini_shaders (ctx); - - for (n = 0; n < ARRAY_LENGTH (ctx->glyph_cache); n++) - _cairo_gl_glyph_cache_fini (ctx, &ctx->glyph_cache[n]); - - _gl_unlock (device); -} - -static void -_gl_destroy (void *device) -{ - cairo_gl_context_t *ctx = device; - - ctx->acquire (ctx); - - while (! cairo_list_is_empty (&ctx->fonts)) { - cairo_gl_font_t *font; - - font = cairo_list_first_entry (&ctx->fonts, - cairo_gl_font_t, - link); - - cairo_list_del (&font->base.link); - cairo_list_del (&font->link); - free (font); - } - - _cairo_array_fini (&ctx->tristrip_indices); - - cairo_region_destroy (ctx->clip_region); - _cairo_clip_destroy (ctx->clip); - - free (ctx->vb); - - ctx->destroy (ctx); - - free (ctx); -} - -static const cairo_device_backend_t _cairo_gl_device_backend = { - CAIRO_DEVICE_TYPE_GL, - - _gl_lock, - _gl_unlock, - - _gl_flush, /* flush */ - _gl_finish, - _gl_destroy, -}; - -static cairo_bool_t -_cairo_gl_msaa_compositor_enabled (void) -{ - const char *env = getenv ("CAIRO_GL_COMPOSITOR"); - return env && strcmp(env, "msaa") == 0; -} - -static cairo_bool_t -test_can_read_bgra (cairo_gl_flavor_t gl_flavor) -{ - /* Desktop GL always supports BGRA formats. */ - if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - return TRUE; - - assert (gl_flavor == CAIRO_GL_FLAVOR_ES); - - /* For OpenGL ES we have to look for the specific extension and BGRA only - * matches cairo's integer packed bytes on little-endian machines. */ - if (!_cairo_is_little_endian()) - return FALSE; - return _cairo_gl_has_extension ("EXT_read_format_bgra"); -} - -cairo_status_t -_cairo_gl_context_init (cairo_gl_context_t *ctx) -{ - cairo_status_t status; - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - int gl_version = _cairo_gl_get_version (); - cairo_gl_flavor_t gl_flavor = _cairo_gl_get_flavor (); - int n; - - cairo_bool_t is_desktop = gl_flavor == CAIRO_GL_FLAVOR_DESKTOP; - cairo_bool_t is_gles = gl_flavor == CAIRO_GL_FLAVOR_ES; - - _cairo_device_init (&ctx->base, &_cairo_gl_device_backend); - - /* XXX The choice of compositor should be made automatically at runtime. - * However, it is useful to force one particular compositor whilst - * testing. - */ - if (_cairo_gl_msaa_compositor_enabled ()) - ctx->compositor = _cairo_gl_msaa_compositor_get (); - else - ctx->compositor = _cairo_gl_span_compositor_get (); - - - ctx->thread_aware = TRUE; - - memset (ctx->glyph_cache, 0, sizeof (ctx->glyph_cache)); - cairo_list_init (&ctx->fonts); - - /* Support only GL version >= 1.3 */ - if (gl_version < CAIRO_GL_VERSION_ENCODE (1, 3)) - return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - - /* Check for required extensions */ - if (is_desktop) { - if (_cairo_gl_has_extension ("GL_ARB_texture_non_power_of_two")) { - ctx->tex_target = GL_TEXTURE_2D; - ctx->has_npot_repeat = TRUE; - } else if (_cairo_gl_has_extension ("GL_ARB_texture_rectangle")) { - ctx->tex_target = GL_TEXTURE_RECTANGLE; - ctx->has_npot_repeat = FALSE; - } else - return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - } else { - ctx->tex_target = GL_TEXTURE_2D; - if (_cairo_gl_has_extension ("GL_OES_texture_npot") || - _cairo_gl_has_extension ("GL_IMG_texture_npot")) - ctx->has_npot_repeat = TRUE; - else - ctx->has_npot_repeat = FALSE; - } - - if (is_desktop && gl_version < CAIRO_GL_VERSION_ENCODE (2, 1) && - ! _cairo_gl_has_extension ("GL_ARB_pixel_buffer_object")) - return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - - if (is_gles && ! _cairo_gl_has_extension ("GL_EXT_texture_format_BGRA8888")) - return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - - ctx->has_map_buffer = - is_desktop || (is_gles && _cairo_gl_has_extension ("GL_OES_mapbuffer")); - - ctx->can_read_bgra = test_can_read_bgra (gl_flavor); - - ctx->has_mesa_pack_invert = - _cairo_gl_has_extension ("GL_MESA_pack_invert"); - - ctx->has_packed_depth_stencil = - (is_desktop && _cairo_gl_has_extension ("GL_EXT_packed_depth_stencil")) || - (is_gles && _cairo_gl_has_extension ("GL_OES_packed_depth_stencil")); - - ctx->num_samples = 1; - -#if CAIRO_HAS_GL_SURFACE - if (is_desktop && ctx->has_packed_depth_stencil && - (gl_version >= CAIRO_GL_VERSION_ENCODE (3, 0) || - _cairo_gl_has_extension ("GL_ARB_framebuffer_object") || - (_cairo_gl_has_extension ("GL_EXT_framebuffer_blit") && - _cairo_gl_has_extension ("GL_EXT_framebuffer_multisample")))) { - glGetIntegerv(GL_MAX_SAMPLES_EXT, &ctx->num_samples); - } -#endif - -#if CAIRO_HAS_GLESV2_SURFACE && defined(GL_MAX_SAMPLES_EXT) - if (is_gles && ctx->has_packed_depth_stencil && - _cairo_gl_has_extension ("GL_EXT_multisampled_render_to_texture")) { - glGetIntegerv(GL_MAX_SAMPLES_EXT, &ctx->num_samples); - } -#endif - -#if CAIRO_HAS_GLESV2_SURFACE && defined(GL_MAX_SAMPLES_IMG) - if (is_gles && ctx->has_packed_depth_stencil && - _cairo_gl_has_extension ("GL_IMG_multisampled_render_to_texture")) { - glGetIntegerv(GL_MAX_SAMPLES_IMG, &ctx->num_samples); - } -#endif - - ctx->supports_msaa = ctx->num_samples > 1; - if (ctx->num_samples > MAX_MSAA_SAMPLES) - ctx->num_samples = MAX_MSAA_SAMPLES; - - - ctx->current_operator = -1; - ctx->gl_flavor = gl_flavor; - - status = _cairo_gl_context_init_shaders (ctx); - if (unlikely (status)) - return status; - - status = _cairo_cache_init (&ctx->gradients, - _cairo_gl_gradient_equal, - NULL, - (cairo_destroy_func_t) _cairo_gl_gradient_destroy, - CAIRO_GL_GRADIENT_CACHE_SIZE); - if (unlikely (status)) - return status; - - ctx->vbo_size = _cairo_gl_get_vbo_size(); - - ctx->vb = malloc (ctx->vbo_size); - if (unlikely (ctx->vb == NULL)) { - _cairo_cache_fini (&ctx->gradients); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - ctx->primitive_type = CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES; - _cairo_array_init (&ctx->tristrip_indices, sizeof (unsigned short)); - - /* PBO for any sort of texture upload */ - dispatch->GenBuffers (1, &ctx->texture_load_pbo); - - ctx->max_framebuffer_size = 0; - glGetIntegerv (GL_MAX_RENDERBUFFER_SIZE, &ctx->max_framebuffer_size); - ctx->max_texture_size = 0; - glGetIntegerv (GL_MAX_TEXTURE_SIZE, &ctx->max_texture_size); - ctx->max_textures = 0; - glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS, &ctx->max_textures); - - for (n = 0; n < ARRAY_LENGTH (ctx->glyph_cache); n++) - _cairo_gl_glyph_cache_init (&ctx->glyph_cache[n]); - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gl_context_activate (cairo_gl_context_t *ctx, - cairo_gl_tex_t tex_unit) -{ - if (ctx->max_textures <= (GLint) tex_unit) { - if (tex_unit < 2) { - _cairo_gl_composite_flush (ctx); - _cairo_gl_context_destroy_operand (ctx, ctx->max_textures - 1); - } - glActiveTexture (ctx->max_textures - 1); - } else { - glActiveTexture (GL_TEXTURE0 + tex_unit); - } -} - -static GLenum -_get_depth_stencil_format (cairo_gl_context_t *ctx) -{ - /* This is necessary to properly handle the situation where both - OpenGL and OpenGLES are active and returning a sane default. */ -#if CAIRO_HAS_GL_SURFACE - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - return GL_DEPTH_STENCIL; -#endif - -#if CAIRO_HAS_GLESV2_SURFACE - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - return GL_DEPTH24_STENCIL8_OES; -#endif - -#if CAIRO_HAS_GL_SURFACE - return GL_DEPTH_STENCIL; -#elif CAIRO_HAS_GLESV2_SURFACE - return GL_DEPTH24_STENCIL8_OES; -#endif -} - -#if CAIRO_HAS_GLESV2_SURFACE -static void -_cairo_gl_ensure_msaa_gles_framebuffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - if (surface->msaa_active) - return; - - ctx->dispatch.FramebufferTexture2DMultisample(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - ctx->tex_target, - surface->tex, - 0, - ctx->num_samples); - - /* From now on MSAA will always be active on this surface. */ - surface->msaa_active = TRUE; -} -#endif - -static void -_cairo_gl_ensure_framebuffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - GLenum status; - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - - if (likely (surface->fb)) - return; - - /* Create a framebuffer object wrapping the texture so that we can render - * to it. - */ - dispatch->GenFramebuffers (1, &surface->fb); - dispatch->BindFramebuffer (GL_FRAMEBUFFER, surface->fb); - - /* Unlike for desktop GL we only maintain one multisampling framebuffer - for OpenGLES since the EXT_multisampled_render_to_texture extension - does not require an explicit multisample resolution. */ -#if CAIRO_HAS_GLESV2_SURFACE - if (surface->supports_msaa && _cairo_gl_msaa_compositor_enabled () && - ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { - _cairo_gl_ensure_msaa_gles_framebuffer (ctx, surface); - } else -#endif - dispatch->FramebufferTexture2D (GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - ctx->tex_target, - surface->tex, - 0); - -#if CAIRO_HAS_GL_SURFACE - glDrawBuffer (GL_COLOR_ATTACHMENT0); - glReadBuffer (GL_COLOR_ATTACHMENT0); -#endif - - status = dispatch->CheckFramebufferStatus (GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - const char *str; - switch (status) { - //case GL_FRAMEBUFFER_UNDEFINED: str= "undefined"; break; - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: str= "incomplete attachment"; break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: str= "incomplete/missing attachment"; break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: str= "incomplete draw buffer"; break; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: str= "incomplete read buffer"; break; - case GL_FRAMEBUFFER_UNSUPPORTED: str= "unsupported"; break; - case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: str= "incomplete multiple"; break; - default: str = "unknown error"; break; - } - - fprintf (stderr, - "destination is framebuffer incomplete: %s [%#x]\n", - str, status); - } -} -#if CAIRO_HAS_GL_SURFACE -static void -_cairo_gl_ensure_multisampling (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - assert (surface->supports_msaa); - assert (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP); - - if (surface->msaa_fb) - return; - - /* We maintain a separate framebuffer for multisampling operations. - This allows us to do a fast paint to the non-multisampling framebuffer - when mulitsampling is disabled. */ - ctx->dispatch.GenFramebuffers (1, &surface->msaa_fb); - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->msaa_fb); - ctx->dispatch.GenRenderbuffers (1, &surface->msaa_rb); - ctx->dispatch.BindRenderbuffer (GL_RENDERBUFFER, surface->msaa_rb); - - /* FIXME: For now we assume that textures passed from the outside have GL_RGBA - format, but eventually we need to expose a way for the API consumer to pass - this information. */ - ctx->dispatch.RenderbufferStorageMultisample (GL_RENDERBUFFER, - ctx->num_samples, - GL_RGBA, - surface->width, - surface->height); - ctx->dispatch.FramebufferRenderbuffer (GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_RENDERBUFFER, - surface->msaa_rb); - - /* Cairo surfaces start out initialized to transparent (black) */ - glDisable (GL_SCISSOR_TEST); - glClearColor (0, 0, 0, 0); - glClear (GL_COLOR_BUFFER_BIT); -} -#endif - -static cairo_bool_t -_cairo_gl_ensure_msaa_depth_stencil_buffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - if (surface->msaa_depth_stencil) - return TRUE; - - _cairo_gl_ensure_framebuffer (ctx, surface); -#if CAIRO_HAS_GL_SURFACE - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - _cairo_gl_ensure_multisampling (ctx, surface); -#endif - - dispatch->GenRenderbuffers (1, &surface->msaa_depth_stencil); - dispatch->BindRenderbuffer (GL_RENDERBUFFER, - surface->msaa_depth_stencil); - - dispatch->RenderbufferStorageMultisample (GL_RENDERBUFFER, - ctx->num_samples, - _get_depth_stencil_format (ctx), - surface->width, - surface->height); - -#if CAIRO_HAS_GL_SURFACE - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) { - dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, - GL_DEPTH_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, - surface->msaa_depth_stencil); - } -#endif - -#if CAIRO_HAS_GLESV2_SURFACE - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { - dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, - GL_DEPTH_ATTACHMENT, - GL_RENDERBUFFER, - surface->msaa_depth_stencil); - dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, - GL_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, - surface->msaa_depth_stencil); - } -#endif - - if (dispatch->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - dispatch->DeleteRenderbuffers (1, &surface->msaa_depth_stencil); - surface->msaa_depth_stencil = 0; - return FALSE; - } - - return TRUE; -} - -static cairo_bool_t -_cairo_gl_ensure_depth_stencil_buffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - - if (surface->depth_stencil) - return TRUE; - - _cairo_gl_ensure_framebuffer (ctx, surface); - - dispatch->GenRenderbuffers (1, &surface->depth_stencil); - dispatch->BindRenderbuffer (GL_RENDERBUFFER, surface->depth_stencil); - dispatch->RenderbufferStorage (GL_RENDERBUFFER, - _get_depth_stencil_format (ctx), - surface->width, surface->height); - - dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, surface->depth_stencil); - dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_RENDERBUFFER, surface->depth_stencil); - if (dispatch->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - dispatch->DeleteRenderbuffers (1, &surface->depth_stencil); - surface->depth_stencil = 0; - return FALSE; - } - - return TRUE; -} - -cairo_bool_t -_cairo_gl_ensure_stencil (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - if (! _cairo_gl_surface_is_texture (surface)) - return TRUE; /* best guess for now, will check later */ - if (! ctx->has_packed_depth_stencil) - return FALSE; - - if (surface->msaa_active) - return _cairo_gl_ensure_msaa_depth_stencil_buffer (ctx, surface); - else - return _cairo_gl_ensure_depth_stencil_buffer (ctx, surface); -} - -/* - * Stores a parallel projection transformation in matrix 'm', - * using column-major order. - * - * This is equivalent to: - * - * glLoadIdentity() - * gluOrtho2D() - * - * The calculation for the ortho tranformation was taken from the - * mesa source code. - */ -static void -_gl_identity_ortho (GLfloat *m, - GLfloat left, GLfloat right, - GLfloat bottom, GLfloat top) -{ -#define M(row,col) m[col*4+row] - M(0,0) = 2.f / (right - left); - M(0,1) = 0.f; - M(0,2) = 0.f; - M(0,3) = -(right + left) / (right - left); - - M(1,0) = 0.f; - M(1,1) = 2.f / (top - bottom); - M(1,2) = 0.f; - M(1,3) = -(top + bottom) / (top - bottom); - - M(2,0) = 0.f; - M(2,1) = 0.f; - M(2,2) = -1.f; - M(2,3) = 0.f; - - M(3,0) = 0.f; - M(3,1) = 0.f; - M(3,2) = 0.f; - M(3,3) = 1.f; -#undef M -} - -#if CAIRO_HAS_GL_SURFACE -static void -bind_multisample_framebuffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - cairo_bool_t stencil_test_enabled; - cairo_bool_t scissor_test_enabled; - - assert (surface->supports_msaa); - assert (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP); - - _cairo_gl_ensure_framebuffer (ctx, surface); - _cairo_gl_ensure_multisampling (ctx, surface); - - if (surface->msaa_active) { - glEnable (GL_MULTISAMPLE); - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->msaa_fb); - return; - } - - _cairo_gl_composite_flush (ctx); - - stencil_test_enabled = glIsEnabled (GL_STENCIL_TEST); - scissor_test_enabled = glIsEnabled (GL_SCISSOR_TEST); - glDisable (GL_STENCIL_TEST); - glDisable (GL_SCISSOR_TEST); - - glEnable (GL_MULTISAMPLE); - - /* The last time we drew to the surface, we were not using multisampling, - so we need to blit from the non-multisampling framebuffer into the - multisampling framebuffer. */ - ctx->dispatch.BindFramebuffer (GL_DRAW_FRAMEBUFFER, surface->msaa_fb); - ctx->dispatch.BindFramebuffer (GL_READ_FRAMEBUFFER, surface->fb); - ctx->dispatch.BlitFramebuffer (0, 0, surface->width, surface->height, - 0, 0, surface->width, surface->height, - GL_COLOR_BUFFER_BIT, GL_NEAREST); - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->msaa_fb); - - if (stencil_test_enabled) - glEnable (GL_STENCIL_TEST); - if (scissor_test_enabled) - glEnable (GL_SCISSOR_TEST); -} -#endif - -#if CAIRO_HAS_GL_SURFACE -static void -bind_singlesample_framebuffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface) -{ - cairo_bool_t stencil_test_enabled; - cairo_bool_t scissor_test_enabled; - - assert (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP); - _cairo_gl_ensure_framebuffer (ctx, surface); - - if (! surface->msaa_active) { - glDisable (GL_MULTISAMPLE); - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->fb); - return; - } - - _cairo_gl_composite_flush (ctx); - - stencil_test_enabled = glIsEnabled (GL_STENCIL_TEST); - scissor_test_enabled = glIsEnabled (GL_SCISSOR_TEST); - glDisable (GL_STENCIL_TEST); - glDisable (GL_SCISSOR_TEST); - - glDisable (GL_MULTISAMPLE); - - /* The last time we drew to the surface, we were using multisampling, - so we need to blit from the multisampling framebuffer into the - non-multisampling framebuffer. */ - ctx->dispatch.BindFramebuffer (GL_DRAW_FRAMEBUFFER, surface->fb); - ctx->dispatch.BindFramebuffer (GL_READ_FRAMEBUFFER, surface->msaa_fb); - ctx->dispatch.BlitFramebuffer (0, 0, surface->width, surface->height, - 0, 0, surface->width, surface->height, - GL_COLOR_BUFFER_BIT, GL_NEAREST); - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->fb); - - if (stencil_test_enabled) - glEnable (GL_STENCIL_TEST); - if (scissor_test_enabled) - glEnable (GL_SCISSOR_TEST); -} -#endif - -void -_cairo_gl_context_bind_framebuffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface, - cairo_bool_t multisampling) -{ - if (_cairo_gl_surface_is_texture (surface)) { - /* OpenGL ES surfaces only have either a multisample framebuffer or a - * singlesample framebuffer, so we cannot switch back and forth. */ - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { - _cairo_gl_ensure_framebuffer (ctx, surface); - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->fb); - return; - } - -#if CAIRO_HAS_GL_SURFACE - if (multisampling) - bind_multisample_framebuffer (ctx, surface); - else - bind_singlesample_framebuffer (ctx, surface); -#endif - } else { - ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, 0); - -#if CAIRO_HAS_GL_SURFACE - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) { - if (multisampling) - glEnable (GL_MULTISAMPLE); - else - glDisable (GL_MULTISAMPLE); - } -#endif - } - - surface->msaa_active = multisampling; -} - -void -_cairo_gl_context_set_destination (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface, - cairo_bool_t multisampling) -{ - cairo_bool_t changing_surface, changing_sampling; - - /* The decision whether or not to use multisampling happens when - * we create an OpenGL ES surface, so we can never switch modes. */ - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) - multisampling = surface->msaa_active; - - changing_surface = ctx->current_target != surface || surface->needs_update; - changing_sampling = surface->msaa_active != multisampling; - if (! changing_surface && ! changing_sampling) - return; - - if (! changing_surface) { - _cairo_gl_composite_flush (ctx); - _cairo_gl_context_bind_framebuffer (ctx, surface, multisampling); - return; - } - - _cairo_gl_composite_flush (ctx); - - ctx->current_target = surface; - surface->needs_update = FALSE; - - if (! _cairo_gl_surface_is_texture (surface)) { - ctx->make_current (ctx, surface); - } - - _cairo_gl_context_bind_framebuffer (ctx, surface, multisampling); - - if (! _cairo_gl_surface_is_texture (surface)) { -#if CAIRO_HAS_GL_SURFACE - glDrawBuffer (GL_BACK_LEFT); - glReadBuffer (GL_BACK_LEFT); -#endif - } - - glDisable (GL_DITHER); - glViewport (0, 0, surface->width, surface->height); - - if (_cairo_gl_surface_is_texture (surface)) - _gl_identity_ortho (ctx->modelviewprojection_matrix, - 0, surface->width, 0, surface->height); - else - _gl_identity_ortho (ctx->modelviewprojection_matrix, - 0, surface->width, surface->height, 0); -} - -void -cairo_gl_device_set_thread_aware (cairo_device_t *device, - cairo_bool_t thread_aware) -{ - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { - _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - return; - } - ((cairo_gl_context_t *) device)->thread_aware = thread_aware; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch-private.h deleted file mode 100644 index cabf76f0d6b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch-private.h +++ /dev/null @@ -1,129 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Alexandros Frantzis - */ - -#ifndef CAIRO_GL_DISPATCH_PRIVATE_H -#define CAIRO_GL_DISPATCH_PRIVATE_H - -#include "cairo-gl-private.h" -#include - -typedef enum _cairo_gl_dispatch_name { - CAIRO_GL_DISPATCH_NAME_CORE, - CAIRO_GL_DISPATCH_NAME_EXT, - CAIRO_GL_DISPATCH_NAME_ES, - CAIRO_GL_DISPATCH_NAME_COUNT -} cairo_gl_dispatch_name_t; - -typedef struct _cairo_gl_dispatch_entry { - const char *name[CAIRO_GL_DISPATCH_NAME_COUNT]; - size_t offset; -} cairo_gl_dispatch_entry_t; - -#define DISPATCH_ENTRY_ARB(name) { { "gl"#name, "gl"#name"ARB", "gl"#name }, \ - offsetof(cairo_gl_dispatch_t, name) } -#define DISPATCH_ENTRY_EXT(name) { { "gl"#name, "gl"#name"EXT", "gl"#name }, \ - offsetof(cairo_gl_dispatch_t, name) } -#define DISPATCH_ENTRY_ARB_OES(name) { { "gl"#name, "gl"#name"ARB", "gl"#name"OES" }, \ - offsetof(cairo_gl_dispatch_t, name) } -#define DISPATCH_ENTRY_EXT_IMG(name) { { "gl"#name, "gl"#name"EXT", "gl"#name"IMG" }, \ - offsetof(cairo_gl_dispatch_t, name) } -#define DISPATCH_ENTRY_CUSTOM(name, name2) { { "gl"#name, "gl"#name2, "gl"#name }, \ - offsetof(cairo_gl_dispatch_t, name)} -#define DISPATCH_ENTRY_LAST { { NULL, NULL, NULL }, 0 } - -cairo_private cairo_gl_dispatch_entry_t dispatch_buffers_entries[] = { - DISPATCH_ENTRY_ARB (GenBuffers), - DISPATCH_ENTRY_ARB (BindBuffer), - DISPATCH_ENTRY_ARB (BufferData), - DISPATCH_ENTRY_ARB_OES (MapBuffer), - DISPATCH_ENTRY_ARB_OES (UnmapBuffer), - DISPATCH_ENTRY_LAST -}; - -cairo_private cairo_gl_dispatch_entry_t dispatch_shaders_entries[] = { - /* Shaders */ - DISPATCH_ENTRY_CUSTOM (CreateShader, CreateShaderObjectARB), - DISPATCH_ENTRY_ARB (ShaderSource), - DISPATCH_ENTRY_ARB (CompileShader), - DISPATCH_ENTRY_CUSTOM (GetShaderiv, GetObjectParameterivARB), - DISPATCH_ENTRY_CUSTOM (GetShaderInfoLog, GetInfoLogARB), - DISPATCH_ENTRY_CUSTOM (DeleteShader, DeleteObjectARB), - - /* Programs */ - DISPATCH_ENTRY_CUSTOM (CreateProgram, CreateProgramObjectARB), - DISPATCH_ENTRY_CUSTOM (AttachShader, AttachObjectARB), - DISPATCH_ENTRY_CUSTOM (DeleteProgram, DeleteObjectARB), - DISPATCH_ENTRY_ARB (LinkProgram), - DISPATCH_ENTRY_CUSTOM (UseProgram, UseProgramObjectARB), - DISPATCH_ENTRY_CUSTOM (GetProgramiv, GetObjectParameterivARB), - DISPATCH_ENTRY_CUSTOM (GetProgramInfoLog, GetInfoLogARB), - - /* Uniforms */ - DISPATCH_ENTRY_ARB (GetUniformLocation), - DISPATCH_ENTRY_ARB (Uniform1f), - DISPATCH_ENTRY_ARB (Uniform2f), - DISPATCH_ENTRY_ARB (Uniform3f), - DISPATCH_ENTRY_ARB (Uniform4f), - DISPATCH_ENTRY_ARB (UniformMatrix3fv), - DISPATCH_ENTRY_ARB (UniformMatrix4fv), - DISPATCH_ENTRY_ARB (Uniform1i), - - /* Attributes */ - DISPATCH_ENTRY_ARB (BindAttribLocation), - DISPATCH_ENTRY_ARB (VertexAttribPointer), - DISPATCH_ENTRY_ARB (EnableVertexAttribArray), - DISPATCH_ENTRY_ARB (DisableVertexAttribArray), - - DISPATCH_ENTRY_LAST -}; - -cairo_private cairo_gl_dispatch_entry_t dispatch_fbo_entries[] = { - DISPATCH_ENTRY_EXT (GenFramebuffers), - DISPATCH_ENTRY_EXT (BindFramebuffer), - DISPATCH_ENTRY_EXT (FramebufferTexture2D), - DISPATCH_ENTRY_EXT (CheckFramebufferStatus), - DISPATCH_ENTRY_EXT (DeleteFramebuffers), - DISPATCH_ENTRY_EXT (GenRenderbuffers), - DISPATCH_ENTRY_EXT (BindRenderbuffer), - DISPATCH_ENTRY_EXT (RenderbufferStorage), - DISPATCH_ENTRY_EXT (FramebufferRenderbuffer), - DISPATCH_ENTRY_EXT (DeleteRenderbuffers), - DISPATCH_ENTRY_EXT (BlitFramebuffer), - DISPATCH_ENTRY_LAST -}; - -cairo_private cairo_gl_dispatch_entry_t dispatch_multisampling_entries[] = { - DISPATCH_ENTRY_EXT_IMG (RenderbufferStorageMultisample), - DISPATCH_ENTRY_EXT_IMG (FramebufferTexture2DMultisample), - DISPATCH_ENTRY_LAST -}; - -#endif /* CAIRO_GL_DISPATCH_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch.c deleted file mode 100644 index 76c3115ba37..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-dispatch.c +++ /dev/null @@ -1,261 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Alexandros Frantzis - */ - -#include "cairoint.h" -#include "cairo-gl-private.h" -#include "cairo-gl-dispatch-private.h" -#if CAIRO_HAS_DLSYM -#include -#endif - -#if CAIRO_HAS_DLSYM -static void * -_cairo_gl_dispatch_open_lib (void) -{ - return dlopen (NULL, RTLD_LAZY); -} - -static void -_cairo_gl_dispatch_close_lib (void *handle) -{ - dlclose (handle); -} - -static cairo_gl_generic_func_t -_cairo_gl_dispatch_get_proc_addr (void *handle, const char *name) -{ - return (cairo_gl_generic_func_t) dlsym (handle, name); -} -#else -static void * -_cairo_gl_dispatch_open_lib (void) -{ - return NULL; -} - -static void -_cairo_gl_dispatch_close_lib (void *handle) -{ - return; -} - -static cairo_gl_generic_func_t -_cairo_gl_dispatch_get_proc_addr (void *handle, const char *name) -{ - return NULL; -} -#endif /* CAIRO_HAS_DLSYM */ - - -static void -_cairo_gl_dispatch_init_entries (cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr, - cairo_gl_dispatch_entry_t *entries, - cairo_gl_dispatch_name_t dispatch_name) -{ - cairo_gl_dispatch_entry_t *entry = entries; - void *handle = _cairo_gl_dispatch_open_lib (); - - while (entry->name[CAIRO_GL_DISPATCH_NAME_CORE] != NULL) { - void *dispatch_ptr = &((char *) dispatch)[entry->offset]; - const char *name = entry->name[dispatch_name]; - - /* - * In strictly conforming EGL implementations, eglGetProcAddress() can - * be used only to get extension functions, but some of the functions - * we want belong to core GL(ES). If the *GetProcAddress function - * provided by the context fails, try to get the address of the wanted - * GL function using standard system facilities (eg dlsym() in *nix - * systems). - */ - cairo_gl_generic_func_t func = get_proc_addr (name); - if (func == NULL) - func = _cairo_gl_dispatch_get_proc_addr (handle, name); - - *((cairo_gl_generic_func_t *) dispatch_ptr) = func; - - ++entry; - } - - _cairo_gl_dispatch_close_lib (handle); -} - -static cairo_status_t -_cairo_gl_dispatch_init_buffers (cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr, - int gl_version, cairo_gl_flavor_t gl_flavor) -{ - cairo_gl_dispatch_name_t dispatch_name; - - if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - { - if (gl_version >= CAIRO_GL_VERSION_ENCODE (1, 5)) - dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; - else if (_cairo_gl_has_extension ("GL_ARB_vertex_buffer_object")) - dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; - else - return CAIRO_STATUS_DEVICE_ERROR; - } - else if (gl_flavor == CAIRO_GL_FLAVOR_ES && - gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) - { - dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; - } - else - { - return CAIRO_STATUS_DEVICE_ERROR; - } - - _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, - dispatch_buffers_entries, dispatch_name); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_dispatch_init_shaders (cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr, - int gl_version, cairo_gl_flavor_t gl_flavor) -{ - cairo_gl_dispatch_name_t dispatch_name; - - if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - { - if (gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) - dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; - else if (_cairo_gl_has_extension ("GL_ARB_shader_objects")) - dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; - else - return CAIRO_STATUS_DEVICE_ERROR; - } - else if (gl_flavor == CAIRO_GL_FLAVOR_ES && - gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) - { - dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; - } - else - { - return CAIRO_STATUS_DEVICE_ERROR; - } - - _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, - dispatch_shaders_entries, dispatch_name); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_dispatch_init_fbo (cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr, - int gl_version, cairo_gl_flavor_t gl_flavor) -{ - cairo_gl_dispatch_name_t dispatch_name; - - if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - { - if (gl_version >= CAIRO_GL_VERSION_ENCODE (3, 0) || - _cairo_gl_has_extension ("GL_ARB_framebuffer_object")) - dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; - else if (_cairo_gl_has_extension ("GL_EXT_framebuffer_object")) - dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; - else - return CAIRO_STATUS_DEVICE_ERROR; - } - else if (gl_flavor == CAIRO_GL_FLAVOR_ES && - gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) - { - dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; - } - else - { - return CAIRO_STATUS_DEVICE_ERROR; - } - - _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, - dispatch_fbo_entries, dispatch_name); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_dispatch_init_multisampling (cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr, - int gl_version, - cairo_gl_flavor_t gl_flavor) -{ - /* For the multisampling table, there are two GLES versions of the - * extension, so we put one in the EXT slot and one in the real ES slot.*/ - cairo_gl_dispatch_name_t dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; - if (gl_flavor == CAIRO_GL_FLAVOR_ES) { - if (_cairo_gl_has_extension ("GL_EXT_multisampled_render_to_texture")) - dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; - else if (_cairo_gl_has_extension ("GL_IMG_multisampled_render_to_texture")) - dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; - } - _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, - dispatch_multisampling_entries, - dispatch_name); - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gl_dispatch_init (cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr) -{ - cairo_status_t status; - int gl_version; - cairo_gl_flavor_t gl_flavor; - - gl_version = _cairo_gl_get_version (); - gl_flavor = _cairo_gl_get_flavor (); - - status = _cairo_gl_dispatch_init_buffers (dispatch, get_proc_addr, - gl_version, gl_flavor); - if (status != CAIRO_STATUS_SUCCESS) - return status; - - status = _cairo_gl_dispatch_init_shaders (dispatch, get_proc_addr, - gl_version, gl_flavor); - if (status != CAIRO_STATUS_SUCCESS) - return status; - - status = _cairo_gl_dispatch_init_fbo (dispatch, get_proc_addr, - gl_version, gl_flavor); - if (status != CAIRO_STATUS_SUCCESS) - return status; - - status = _cairo_gl_dispatch_init_multisampling (dispatch, get_proc_addr, - gl_version, gl_flavor); - if (status != CAIRO_STATUS_SUCCESS) - return status; - - return CAIRO_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-ext-def-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-ext-def-private.h deleted file mode 100644 index a261947bef0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-ext-def-private.h +++ /dev/null @@ -1,143 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Alexandros Frantzis - */ - -#ifndef CAIRO_GL_EXT_DEF_PRIVATE_H -#define CAIRO_GL_EXT_DEF_PRIVATE_H - -#ifndef GL_TEXTURE_RECTANGLE -#define GL_TEXTURE_RECTANGLE 0x84F5 -#endif - -#ifndef GL_ARRAY_BUFFER -#define GL_ARRAY_BUFFER 0x8892 -#endif - -#ifndef GL_STREAM_DRAW -#define GL_STREAM_DRAW 0x88E0 -#endif - -#ifndef GL_WRITE_ONLY -#define GL_WRITE_ONLY 0x88B9 -#endif - -#ifndef GL_PIXEL_UNPACK_BUFFER -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#endif - -#ifndef GL_FRAMEBUFFER -#define GL_FRAMEBUFFER 0x8D40 -#endif - -#ifndef GL_COLOR_ATTACHMENT0 -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#endif - -#ifndef GL_FRAMEBUFFER_COMPLETE -#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 0x8CDA -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC -#endif - -#ifndef GL_FRAMEBUFFER_UNSUPPORTED -#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD -#endif - -#ifndef GL_PACK_INVERT_MESA -#define GL_PACK_INVERT_MESA 0x8758 -#endif - -#ifndef GL_CLAMP_TO_BORDER -#define GL_CLAMP_TO_BORDER 0x812D -#endif - -#ifndef GL_BGR -#define GL_BGR 0x80E0 -#endif - -#ifndef GL_BGRA -#define GL_BGRA 0x80E1 -#endif - -#ifndef GL_RGBA8 -#define GL_RGBA8 0x8058 -#endif - -#ifndef GL_UNSIGNED_INT_8_8_8_8 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#endif - -#ifndef GL_UNSIGNED_SHORT_5_6_5_REV -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#endif - -#ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#endif - -#ifndef GL_UNSIGNED_INT_8_8_8_8_REV -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#endif - -#ifndef GL_PACK_ROW_LENGTH -#define GL_PACK_ROW_LENGTH 0x0D02 -#endif - -#ifndef GL_UNPACK_ROW_LENGTH -#define GL_UNPACK_ROW_LENGTH 0x0CF2 -#endif - -#ifndef GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 -#endif - -#endif /* CAIRO_GL_EXT_DEF_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-glyphs.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-glyphs.c deleted file mode 100644 index 8a1a548d939..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-glyphs.c +++ /dev/null @@ -1,503 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * Copyright © 2010 Intel Corporation - * Copyright © 2010 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributors: - * Benjamin Otte - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-rtree-private.h" - -#define GLYPH_CACHE_WIDTH 1024 -#define GLYPH_CACHE_HEIGHT 1024 -#define GLYPH_CACHE_MIN_SIZE 4 -#define GLYPH_CACHE_MAX_SIZE 128 - -typedef struct _cairo_gl_glyph { - cairo_rtree_node_t node; - cairo_scaled_glyph_private_t base; - cairo_scaled_glyph_t *glyph; - cairo_gl_glyph_cache_t *cache; - struct { float x, y; } p1, p2; -} cairo_gl_glyph_t; - -static void -_cairo_gl_node_destroy (cairo_rtree_node_t *node) -{ - cairo_gl_glyph_t *priv = cairo_container_of (node, cairo_gl_glyph_t, node); - cairo_scaled_glyph_t *glyph; - - glyph = priv->glyph; - if (glyph == NULL) - return; - - if (glyph->dev_private_key == priv->cache) { - glyph->dev_private = NULL; - glyph->dev_private_key = NULL; - } - cairo_list_del (&priv->base.link); - priv->glyph = NULL; -} - -static void -_cairo_gl_glyph_fini (cairo_scaled_glyph_private_t *glyph_private, - cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font) -{ - cairo_gl_glyph_t *priv = cairo_container_of (glyph_private, - cairo_gl_glyph_t, - base); - - assert (priv->glyph); - - _cairo_gl_node_destroy (&priv->node); - - /* XXX thread-safety? Probably ok due to the frozen scaled-font. */ - if (! priv->node.pinned) - _cairo_rtree_node_remove (&priv->cache->rtree, &priv->node); - - assert (priv->glyph == NULL); -} - -static cairo_int_status_t -_cairo_gl_glyph_cache_add_glyph (cairo_gl_context_t *ctx, - cairo_gl_glyph_cache_t *cache, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_image_surface_t *glyph_surface = scaled_glyph->surface; - cairo_gl_glyph_t *glyph_private; - cairo_rtree_node_t *node = NULL; - cairo_int_status_t status; - int width, height; - - width = glyph_surface->width; - if (width < GLYPH_CACHE_MIN_SIZE) - width = GLYPH_CACHE_MIN_SIZE; - height = glyph_surface->height; - if (height < GLYPH_CACHE_MIN_SIZE) - height = GLYPH_CACHE_MIN_SIZE; - - /* search for an available slot */ - status = _cairo_rtree_insert (&cache->rtree, width, height, &node); - /* search for an unlocked slot */ - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = _cairo_rtree_evict_random (&cache->rtree, - width, height, &node); - if (status == CAIRO_INT_STATUS_SUCCESS) { - status = _cairo_rtree_node_insert (&cache->rtree, - node, width, height, &node); - } - } - if (status) - return status; - - /* XXX: Make sure we use the mask texture. This should work automagically somehow */ - glActiveTexture (GL_TEXTURE1); - status = _cairo_gl_surface_draw_image (cache->surface, glyph_surface, - 0, 0, - glyph_surface->width, glyph_surface->height, - node->x, node->y, FALSE); - if (unlikely (status)) - return status; - - glyph_private = (cairo_gl_glyph_t *) node; - glyph_private->cache = cache; - glyph_private->glyph = scaled_glyph; - _cairo_scaled_glyph_attach_private (scaled_glyph, - &glyph_private->base, - cache, - _cairo_gl_glyph_fini); - - scaled_glyph->dev_private = glyph_private; - scaled_glyph->dev_private_key = cache; - - /* compute tex coords */ - glyph_private->p1.x = node->x; - glyph_private->p1.y = node->y; - glyph_private->p2.x = node->x + glyph_surface->width; - glyph_private->p2.y = node->y + glyph_surface->height; - if (! _cairo_gl_device_requires_power_of_two_textures (&ctx->base)) { - glyph_private->p1.x /= GLYPH_CACHE_WIDTH; - glyph_private->p2.x /= GLYPH_CACHE_WIDTH; - glyph_private->p1.y /= GLYPH_CACHE_HEIGHT; - glyph_private->p2.y /= GLYPH_CACHE_HEIGHT; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_gl_glyph_t * -_cairo_gl_glyph_cache_lock (cairo_gl_glyph_cache_t *cache, - cairo_scaled_glyph_t *scaled_glyph) -{ - return _cairo_rtree_pin (&cache->rtree, scaled_glyph->dev_private); -} - -static cairo_status_t -cairo_gl_context_get_glyph_cache (cairo_gl_context_t *ctx, - cairo_format_t format, - cairo_gl_glyph_cache_t **cache_out) -{ - cairo_gl_glyph_cache_t *cache; - cairo_content_t content; - - switch (format) { - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_RGB16_565: - case CAIRO_FORMAT_ARGB32: - case CAIRO_FORMAT_RGB24: - cache = &ctx->glyph_cache[0]; - content = CAIRO_CONTENT_COLOR_ALPHA; - break; - case CAIRO_FORMAT_A8: - case CAIRO_FORMAT_A1: - cache = &ctx->glyph_cache[1]; - content = CAIRO_CONTENT_ALPHA; - break; - default: - case CAIRO_FORMAT_INVALID: - ASSERT_NOT_REACHED; - return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); - } - - if (unlikely (cache->surface == NULL)) { - cairo_surface_t *surface; - - surface = _cairo_gl_surface_create_scratch_for_caching (ctx, - content, - GLYPH_CACHE_WIDTH, - GLYPH_CACHE_HEIGHT); - if (unlikely (surface->status)) - return surface->status; - - _cairo_surface_release_device_reference (surface); - - cache->surface = (cairo_gl_surface_t *)surface; - cache->surface->operand.texture.attributes.has_component_alpha = - content == CAIRO_CONTENT_COLOR_ALPHA; - } - - *cache_out = cache; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -render_glyphs (cairo_gl_surface_t *dst, - int dst_x, int dst_y, - cairo_operator_t op, - cairo_surface_t *source, - cairo_composite_glyphs_info_t *info, - cairo_bool_t *has_component_alpha, - cairo_clip_t *clip) -{ - cairo_format_t last_format = CAIRO_FORMAT_INVALID; - cairo_gl_glyph_cache_t *cache = NULL; - cairo_gl_context_t *ctx; - cairo_gl_emit_glyph_t emit = NULL; - cairo_gl_composite_t setup; - cairo_int_status_t status; - int i = 0; - - TRACE ((stderr, "%s (%d, %d)x(%d, %d)\n", __FUNCTION__, - info->extents.x, info->extents.y, - info->extents.width, info->extents.height)); - - *has_component_alpha = FALSE; - - status = _cairo_gl_context_acquire (dst->base.device, &ctx); - if (unlikely (status)) - return status; - - status = _cairo_gl_composite_init (&setup, op, dst, TRUE); - if (unlikely (status)) - goto FINISH; - - if (source == NULL) { - _cairo_gl_composite_set_solid_source (&setup, CAIRO_COLOR_WHITE); - } else { - _cairo_gl_composite_set_source_operand (&setup, - source_to_operand (source)); - - } - - _cairo_gl_composite_set_clip (&setup, clip); - - for (i = 0; i < info->num_glyphs; i++) { - cairo_scaled_glyph_t *scaled_glyph; - cairo_gl_glyph_t *glyph; - double x_offset, y_offset; - double x1, x2, y1, y2; - - status = _cairo_scaled_glyph_lookup (info->font, - info->glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - if (unlikely (status)) - goto FINISH; - - if (scaled_glyph->surface->width == 0 || - scaled_glyph->surface->height == 0) - { - continue; - } - if (scaled_glyph->surface->format != last_format) { - status = cairo_gl_context_get_glyph_cache (ctx, - scaled_glyph->surface->format, - &cache); - if (unlikely (status)) - goto FINISH; - - last_format = scaled_glyph->surface->format; - - _cairo_gl_composite_set_mask_operand (&setup, &cache->surface->operand); - *has_component_alpha |= cache->surface->operand.texture.attributes.has_component_alpha; - - /* XXX Shoot me. */ - status = _cairo_gl_composite_begin (&setup, &ctx); - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) - goto FINISH; - - emit = _cairo_gl_context_choose_emit_glyph (ctx); - } - - if (scaled_glyph->dev_private_key != cache) { - cairo_scaled_glyph_private_t *priv; - - priv = _cairo_scaled_glyph_find_private (scaled_glyph, cache); - if (priv) { - scaled_glyph->dev_private_key = cache; - scaled_glyph->dev_private = cairo_container_of (priv, - cairo_gl_glyph_t, - base); - } else { - status = _cairo_gl_glyph_cache_add_glyph (ctx, cache, scaled_glyph); - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - /* Cache is full, so flush existing prims and try again. */ - _cairo_gl_composite_flush (ctx); - _cairo_gl_glyph_cache_unlock (cache); - status = _cairo_gl_glyph_cache_add_glyph (ctx, cache, scaled_glyph); - } - - if (unlikely (_cairo_int_status_is_error (status))) - goto FINISH; - } - } - - x_offset = scaled_glyph->surface->base.device_transform.x0; - y_offset = scaled_glyph->surface->base.device_transform.y0; - - x1 = _cairo_lround (info->glyphs[i].x - x_offset - dst_x); - y1 = _cairo_lround (info->glyphs[i].y - y_offset - dst_y); - x2 = x1 + scaled_glyph->surface->width; - y2 = y1 + scaled_glyph->surface->height; - - glyph = _cairo_gl_glyph_cache_lock (cache, scaled_glyph); - assert (emit); - emit (ctx, - x1, y1, x2, y2, - glyph->p1.x, glyph->p1.y, - glyph->p2.x, glyph->p2.y); - } - - status = CAIRO_STATUS_SUCCESS; - FINISH: - status = _cairo_gl_context_release (ctx, status); - - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_int_status_t -render_glyphs_via_mask (cairo_gl_surface_t *dst, - int dst_x, int dst_y, - cairo_operator_t op, - cairo_surface_t *source, - cairo_composite_glyphs_info_t *info, - cairo_clip_t *clip) -{ - cairo_surface_t *mask; - cairo_status_t status; - cairo_bool_t has_component_alpha; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - /* XXX: For non-CA, this should be CAIRO_CONTENT_ALPHA to save memory */ - mask = cairo_gl_surface_create (dst->base.device, - CAIRO_CONTENT_COLOR_ALPHA, - info->extents.width, - info->extents.height); - if (unlikely (mask->status)) - return mask->status; - - status = render_glyphs ((cairo_gl_surface_t *) mask, - info->extents.x, info->extents.y, - CAIRO_OPERATOR_ADD, NULL, - info, &has_component_alpha, NULL); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - cairo_surface_pattern_t mask_pattern; - cairo_surface_pattern_t source_pattern; - cairo_rectangle_int_t clip_extents; - - mask->is_clear = FALSE; - _cairo_pattern_init_for_surface (&mask_pattern, mask); - mask_pattern.base.has_component_alpha = has_component_alpha; - mask_pattern.base.filter = CAIRO_FILTER_NEAREST; - mask_pattern.base.extend = CAIRO_EXTEND_NONE; - - cairo_matrix_init_translate (&mask_pattern.base.matrix, - dst_x-info->extents.x, dst_y-info->extents.y); - - _cairo_pattern_init_for_surface (&source_pattern, source); - cairo_matrix_init_translate (&source_pattern.base.matrix, - dst_x-info->extents.x, dst_y-info->extents.y); - - clip = _cairo_clip_copy (clip); - clip_extents.x = info->extents.x - dst_x; - clip_extents.y = info->extents.y - dst_y; - clip_extents.width = info->extents.width; - clip_extents.height = info->extents.height; - clip = _cairo_clip_intersect_rectangle (clip, &clip_extents); - - status = _cairo_surface_mask (&dst->base, op, - &source_pattern.base, - &mask_pattern.base, - clip); - - _cairo_clip_destroy (clip); - - _cairo_pattern_fini (&mask_pattern.base); - _cairo_pattern_fini (&source_pattern.base); - } - - cairo_surface_destroy (mask); - - return status; -} - -cairo_int_status_t -_cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs) -{ - if (! _cairo_gl_operator_is_supported (extents->op)) - return UNSUPPORTED ("unsupported operator"); - - /* XXX use individual masks for large glyphs? */ - if (ceil (scaled_font->max_scale) >= GLYPH_CACHE_MAX_SIZE) - return UNSUPPORTED ("glyphs too large"); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_gl_composite_glyphs_with_clip (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info, - cairo_clip_t *clip) -{ - cairo_gl_surface_t *dst = _dst; - cairo_bool_t has_component_alpha; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - /* If any of the glyphs require component alpha, we have to go through - * a mask, since only _cairo_gl_surface_composite() currently supports - * component alpha. - */ - if (!dst->base.is_clear && ! info->use_mask && op != CAIRO_OPERATOR_OVER && - (info->font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL || - info->font->options.antialias == CAIRO_ANTIALIAS_BEST)) - { - info->use_mask = TRUE; - } - - if (info->use_mask) { - return render_glyphs_via_mask (dst, dst_x, dst_y, - op, _src, info, clip); - } else { - return render_glyphs (dst, dst_x, dst_y, - op, _src, info, - &has_component_alpha, - clip); - } - -} - -cairo_int_status_t -_cairo_gl_composite_glyphs (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - return _cairo_gl_composite_glyphs_with_clip (_dst, op, _src, src_x, src_y, - dst_x, dst_y, info, NULL); -} - -void -_cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache) -{ - _cairo_rtree_init (&cache->rtree, - GLYPH_CACHE_WIDTH, - GLYPH_CACHE_HEIGHT, - GLYPH_CACHE_MIN_SIZE, - sizeof (cairo_gl_glyph_t), - _cairo_gl_node_destroy); -} - -void -_cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx, - cairo_gl_glyph_cache_t *cache) -{ - _cairo_rtree_fini (&cache->rtree); - cairo_surface_destroy (&cache->surface->base); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient-private.h deleted file mode 100644 index 77f9bbdc5f5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient-private.h +++ /dev/null @@ -1,93 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - */ - -#ifndef CAIRO_GL_GRADIENT_PRIVATE_H -#define CAIRO_GL_GRADIENT_PRIVATE_H - -#define GL_GLEXT_PROTOTYPES - -#include "cairo-cache-private.h" -#include "cairo-device-private.h" -#include "cairo-reference-count-private.h" -#include "cairo-pattern-private.h" -#include "cairo-types-private.h" - -#include "cairo-gl.h" - -#if CAIRO_HAS_GL_SURFACE -#include -#include -#elif CAIRO_HAS_GLESV2_SURFACE -#include -#include -#endif - -#define CAIRO_GL_GRADIENT_CACHE_SIZE 4096 - -/* XXX: Declare in a better place */ -typedef struct _cairo_gl_context cairo_gl_context_t; - -typedef struct _cairo_gl_gradient { - cairo_cache_entry_t cache_entry; - cairo_reference_count_t ref_count; - cairo_device_t *device; /* NB: we don't hold a reference */ - GLuint tex; - unsigned int n_stops; - const cairo_gradient_stop_t *stops; - cairo_gradient_stop_t stops_embedded[1]; -} cairo_gl_gradient_t; - -cairo_private cairo_int_status_t -_cairo_gl_gradient_create (cairo_gl_context_t *ctx, - unsigned int n_stops, - const cairo_gradient_stop_t *stops, - cairo_gl_gradient_t **gradient_out); - -cairo_private_no_warn cairo_gl_gradient_t * -_cairo_gl_gradient_reference (cairo_gl_gradient_t *gradient); - -cairo_private void -_cairo_gl_gradient_destroy (cairo_gl_gradient_t *gradient); - -cairo_private cairo_bool_t -_cairo_gl_gradient_equal (const void *key_a, const void *key_b); - - -#endif /* CAIRO_GL_GRADIENT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient.c deleted file mode 100644 index ac3292101ec..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-gradient.c +++ /dev/null @@ -1,338 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-gl-gradient-private.h" -#include "cairo-gl-private.h" - - -static int -_cairo_gl_gradient_sample_width (unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - unsigned int n; - int width; - - width = 8; - for (n = 1; n < n_stops; n++) { - double dx = stops[n].offset - stops[n-1].offset; - double delta, max; - int ramp; - - if (dx == 0) - return 1024; /* we need to emulate an infinitely sharp step */ - - max = fabs (stops[n].color.red - stops[n-1].color.red); - - delta = fabs (stops[n].color.green - stops[n-1].color.green); - if (delta > max) - max = delta; - - delta = fabs (stops[n].color.blue - stops[n-1].color.blue); - if (delta > max) - max = delta; - - delta = fabs (stops[n].color.alpha - stops[n-1].color.alpha); - if (delta > max) - max = delta; - - ramp = 128 * max / dx; - if (ramp > width) - width = ramp; - } - - return (width + 7) & -8; -} - -static uint8_t premultiply(double c, double a) -{ - int v = c * a * 256; - return v - (v >> 8); -} - -static uint32_t color_stop_to_pixel(const cairo_gradient_stop_t *stop) -{ - uint8_t a, r, g, b; - - a = stop->color.alpha_short >> 8; - r = premultiply(stop->color.red, stop->color.alpha); - g = premultiply(stop->color.green, stop->color.alpha); - b = premultiply(stop->color.blue, stop->color.alpha); - - if (_cairo_is_little_endian ()) - return a << 24 | r << 16 | g << 8 | b << 0; - else - return a << 0 | r << 8 | g << 16 | b << 24; -} - -static cairo_status_t -_cairo_gl_gradient_render (const cairo_gl_context_t *ctx, - unsigned int n_stops, - const cairo_gradient_stop_t *stops, - void *bytes, - int width) -{ - pixman_image_t *gradient, *image; - pixman_gradient_stop_t pixman_stops_stack[32]; - pixman_gradient_stop_t *pixman_stops; - pixman_point_fixed_t p1, p2; - unsigned int i; - pixman_format_code_t gradient_pixman_format; - - /* - * Ensure that the order of the gradient's components in memory is BGRA. - * This is done so that the gradient's pixel data is always suitable for - * texture upload using format=GL_BGRA and type=GL_UNSIGNED_BYTE. - */ - if (_cairo_is_little_endian ()) - gradient_pixman_format = PIXMAN_a8r8g8b8; - else - gradient_pixman_format = PIXMAN_b8g8r8a8; - - pixman_stops = pixman_stops_stack; - if (unlikely (n_stops > ARRAY_LENGTH (pixman_stops_stack))) { - pixman_stops = _cairo_malloc_ab (n_stops, - sizeof (pixman_gradient_stop_t)); - if (unlikely (pixman_stops == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - for (i = 0; i < n_stops; i++) { - pixman_stops[i].x = _cairo_fixed_16_16_from_double (stops[i].offset); - pixman_stops[i].color.red = stops[i].color.red_short; - pixman_stops[i].color.green = stops[i].color.green_short; - pixman_stops[i].color.blue = stops[i].color.blue_short; - pixman_stops[i].color.alpha = stops[i].color.alpha_short; - } - - p1.x = _cairo_fixed_16_16_from_double (0.5); - p1.y = 0; - p2.x = _cairo_fixed_16_16_from_double (width - 0.5); - p2.y = 0; - - gradient = pixman_image_create_linear_gradient (&p1, &p2, - pixman_stops, - n_stops); - if (pixman_stops != pixman_stops_stack) - free (pixman_stops); - - if (unlikely (gradient == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - pixman_image_set_filter (gradient, PIXMAN_FILTER_BILINEAR, NULL, 0); - pixman_image_set_repeat (gradient, PIXMAN_REPEAT_PAD); - - image = pixman_image_create_bits (gradient_pixman_format, width, 1, - bytes, sizeof(uint32_t)*width); - if (unlikely (image == NULL)) { - pixman_image_unref (gradient); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pixman_image_composite32 (PIXMAN_OP_SRC, - gradient, NULL, image, - 0, 0, - 0, 0, - 0, 0, - width, 1); - - pixman_image_unref (gradient); - pixman_image_unref (image); - - /* We need to fudge pixel 0 to hold the left-most color stop and not - * the neareset stop to the zeroth pixel centre in order to correctly - * populate the border color. For completeness, do both edges. - */ - ((uint32_t*)bytes)[0] = color_stop_to_pixel(&stops[0]); - ((uint32_t*)bytes)[width-1] = color_stop_to_pixel(&stops[n_stops-1]); - - return CAIRO_STATUS_SUCCESS; -} - -static unsigned long -_cairo_gl_gradient_hash (unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - return _cairo_hash_bytes (n_stops, - stops, - sizeof (cairo_gradient_stop_t) * n_stops); -} - -static cairo_gl_gradient_t * -_cairo_gl_gradient_lookup (cairo_gl_context_t *ctx, - unsigned long hash, - unsigned int n_stops, - const cairo_gradient_stop_t *stops) -{ - cairo_gl_gradient_t lookup; - - lookup.cache_entry.hash = hash, - lookup.n_stops = n_stops; - lookup.stops = stops; - - return _cairo_cache_lookup (&ctx->gradients, &lookup.cache_entry); -} - -cairo_bool_t -_cairo_gl_gradient_equal (const void *key_a, const void *key_b) -{ - const cairo_gl_gradient_t *a = key_a; - const cairo_gl_gradient_t *b = key_b; - - if (a->n_stops != b->n_stops) - return FALSE; - - return memcmp (a->stops, b->stops, a->n_stops * sizeof (cairo_gradient_stop_t)) == 0; -} - -cairo_int_status_t -_cairo_gl_gradient_create (cairo_gl_context_t *ctx, - unsigned int n_stops, - const cairo_gradient_stop_t *stops, - cairo_gl_gradient_t **gradient_out) -{ - unsigned long hash; - cairo_gl_gradient_t *gradient; - cairo_status_t status; - int tex_width; - GLint internal_format; - void *data; - - if ((unsigned int) ctx->max_texture_size / 2 <= n_stops) - return CAIRO_INT_STATUS_UNSUPPORTED; - - hash = _cairo_gl_gradient_hash (n_stops, stops); - - gradient = _cairo_gl_gradient_lookup (ctx, hash, n_stops, stops); - if (gradient) { - *gradient_out = _cairo_gl_gradient_reference (gradient); - return CAIRO_STATUS_SUCCESS; - } - - gradient = malloc (sizeof (cairo_gl_gradient_t) + sizeof (cairo_gradient_stop_t) * (n_stops - 1)); - if (gradient == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - tex_width = _cairo_gl_gradient_sample_width (n_stops, stops); - if (tex_width > ctx->max_texture_size) - tex_width = ctx->max_texture_size; - - CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 2); - gradient->cache_entry.hash = hash; - gradient->cache_entry.size = tex_width; - gradient->device = &ctx->base; - gradient->n_stops = n_stops; - gradient->stops = gradient->stops_embedded; - memcpy (gradient->stops_embedded, stops, n_stops * sizeof (cairo_gradient_stop_t)); - - glGenTextures (1, &gradient->tex); - _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); - glBindTexture (ctx->tex_target, gradient->tex); - - data = _cairo_malloc_ab (tex_width, sizeof (uint32_t)); - if (unlikely (data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup_gradient; - } - - status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width); - if (unlikely (status)) - goto cleanup_data; - - /* - * In OpenGL ES 2.0 no format conversion is allowed i.e. 'internalFormat' - * must match 'format' in glTexImage2D. - */ - if (_cairo_gl_get_flavor () == CAIRO_GL_FLAVOR_ES) - internal_format = GL_BGRA; - else - internal_format = GL_RGBA; - - glTexImage2D (ctx->tex_target, 0, internal_format, tex_width, 1, 0, - GL_BGRA, GL_UNSIGNED_BYTE, data); - - free (data); - - /* we ignore errors here and just return an uncached gradient */ - if (unlikely (_cairo_cache_insert (&ctx->gradients, &gradient->cache_entry))) - CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 1); - - *gradient_out = gradient; - return CAIRO_STATUS_SUCCESS; - -cleanup_data: - free (data); -cleanup_gradient: - free (gradient); - return status; -} - -cairo_gl_gradient_t * -_cairo_gl_gradient_reference (cairo_gl_gradient_t *gradient) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); - - _cairo_reference_count_inc (&gradient->ref_count); - - return gradient; -} - -void -_cairo_gl_gradient_destroy (cairo_gl_gradient_t *gradient) -{ - cairo_gl_context_t *ctx; - cairo_status_t ignore; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&gradient->ref_count)) - return; - - if (_cairo_gl_context_acquire (gradient->device, &ctx) == CAIRO_STATUS_SUCCESS) { - /* The gradient my still be active in the last operation, so flush */ - _cairo_gl_composite_flush (ctx); - glDeleteTextures (1, &gradient->tex); - ignore = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - } - - free (gradient); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-info.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-info.c deleted file mode 100644 index acefbb91059..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-info.c +++ /dev/null @@ -1,111 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Alexandros Frantzis - */ - -#include "cairoint.h" -#include "cairo-gl-private.h" - -#include - -int -_cairo_gl_get_version (void) -{ - int major, minor; - const char *version = (const char *) glGetString (GL_VERSION); - const char *dot = version == NULL ? NULL : strchr (version, '.'); - const char *major_start = dot; - - /* Sanity check */ - if (dot == NULL || dot == version || *(dot + 1) == '\0') { - major = 0; - minor = 0; - } else { - /* Find the start of the major version in the string */ - while (major_start > version && *major_start != ' ') - --major_start; - major = strtol (major_start, NULL, 10); - minor = strtol (dot + 1, NULL, 10); - } - - return CAIRO_GL_VERSION_ENCODE (major, minor); -} - -cairo_gl_flavor_t -_cairo_gl_get_flavor (void) -{ - const char *version = (const char *) glGetString (GL_VERSION); - cairo_gl_flavor_t flavor; - - if (version == NULL) - flavor = CAIRO_GL_FLAVOR_NONE; - else if (strstr (version, "OpenGL ES") != NULL) - flavor = CAIRO_GL_FLAVOR_ES; - else - flavor = CAIRO_GL_FLAVOR_DESKTOP; - - return flavor; -} - -unsigned long -_cairo_gl_get_vbo_size (void) -{ - unsigned long vbo_size; - - const char *env = getenv ("CAIRO_GL_VBO_SIZE"); - if (env == NULL) { - vbo_size = CAIRO_GL_VBO_SIZE_DEFAULT; - } else { - errno = 0; - vbo_size = strtol (env, NULL, 10); - assert (errno == 0); - assert (vbo_size > 0); - } - - return vbo_size; -} - -cairo_bool_t -_cairo_gl_has_extension (const char *ext) -{ - const char *extensions = (const char *) glGetString (GL_EXTENSIONS); - size_t len = strlen (ext); - const char *ext_ptr = extensions; - - if (unlikely (ext_ptr == NULL)) - return 0; - - while ((ext_ptr = strstr (ext_ptr, ext)) != NULL) { - if (ext_ptr[len] == ' ' || ext_ptr[len] == '\0') - break; - ext_ptr += len; - } - - return (ext_ptr != NULL); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-msaa-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-msaa-compositor.c deleted file mode 100644 index 83e8eb2d160..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-msaa-compositor.c +++ /dev/null @@ -1,944 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * Copyright © 2011 Samsung Electronics - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Henry Song - * Martin Robinson - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-gl-private.h" -#include "cairo-path-private.h" -#include "cairo-traps-private.h" - -static cairo_bool_t -can_use_msaa_compositor (cairo_gl_surface_t *surface, - cairo_antialias_t antialias); - -static void -query_surface_capabilities (cairo_gl_surface_t *surface); - -struct _tristrip_composite_info { - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; -}; - -static cairo_int_status_t -_draw_trap (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - cairo_trapezoid_t *trap) -{ - cairo_point_t quad[4]; - - quad[0].x = _cairo_edge_compute_intersection_x_for_y (&trap->left.p1, - &trap->left.p2, - trap->top); - quad[0].y = trap->top; - - quad[1].x = _cairo_edge_compute_intersection_x_for_y (&trap->left.p1, - &trap->left.p2, - trap->bottom); - quad[1].y = trap->bottom; - - quad[2].x = _cairo_edge_compute_intersection_x_for_y (&trap->right.p1, - &trap->right.p2, - trap->bottom); - quad[2].y = trap->bottom; - - quad[3].x = _cairo_edge_compute_intersection_x_for_y (&trap->right.p1, - &trap->right.p2, - trap->top); - quad[3].y = trap->top; - return _cairo_gl_composite_emit_quad_as_tristrip (ctx, setup, quad); -} - -static cairo_int_status_t -_draw_traps (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - cairo_traps_t *traps) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - int i; - - for (i = 0; i < traps->num_traps; i++) { - cairo_trapezoid_t *trap = traps->traps + i; - if (unlikely ((status = _draw_trap (ctx, setup, trap)))) - return status; - } - - return status; -} - -static cairo_int_status_t -_draw_int_rect (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - cairo_rectangle_int_t *rect) -{ - cairo_box_t box; - cairo_point_t quad[4]; - - _cairo_box_from_rectangle (&box, rect); - quad[0].x = box.p1.x; - quad[0].y = box.p1.y; - quad[1].x = box.p1.x; - quad[1].y = box.p2.y; - quad[2].x = box.p2.x; - quad[2].y = box.p2.y; - quad[3].x = box.p2.x; - quad[3].y = box.p1.y; - - return _cairo_gl_composite_emit_quad_as_tristrip (ctx, setup, quad); -} - -static cairo_int_status_t -_draw_triangle_fan (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - const cairo_point_t *midpt, - const cairo_point_t *points, - int npoints) -{ - int i; - - /* Our strategy here is to not even try to build a triangle fan, but to - draw each triangle as if it was an unconnected member of a triangle strip. */ - for (i = 1; i < npoints; i++) { - cairo_int_status_t status; - cairo_point_t triangle[3]; - - triangle[0] = *midpt; - triangle[1] = points[i - 1]; - triangle[2] = points[i]; - - status = _cairo_gl_composite_emit_triangle_as_tristrip (ctx, setup, triangle); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_clip_to_traps (cairo_clip_t *clip, - cairo_traps_t *traps) -{ - cairo_int_status_t status; - cairo_polygon_t polygon; - cairo_antialias_t antialias; - cairo_fill_rule_t fill_rule; - - _cairo_traps_init (traps); - - if (clip->num_boxes == 1 && clip->path == NULL) { - cairo_boxes_t boxes; - _cairo_boxes_init_for_array (&boxes, clip->boxes, clip->num_boxes); - return _cairo_traps_init_boxes (traps, &boxes); - } - - status = _cairo_clip_get_polygon (clip, &polygon, &fill_rule, &antialias); - if (unlikely (status)) - return status; - - /* We ignore the antialias mode of the clip here, since the user requested - * unantialiased rendering of their path and we expect that this stencil - * based rendering of the clip to be a reasonable approximation to - * the intersection between that clip and the path. - * - * In other words, what the user expects when they try to perform - * a geometric intersection between an unantialiased polygon and an - * antialiased polygon is open to interpretation. And we choose the fast - * option. - */ - - _cairo_traps_init (traps); - status = _cairo_bentley_ottmann_tessellate_polygon (traps, - &polygon, - fill_rule); - _cairo_polygon_fini (&polygon); - - return status; -} - -cairo_int_status_t -_cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - cairo_clip_t *clip) -{ - cairo_int_status_t status; - cairo_traps_t traps; - - status = _clip_to_traps (clip, &traps); - if (unlikely (status)) - return status; - status = _draw_traps (ctx, setup, &traps); - - _cairo_traps_fini (&traps); - return status; -} - -static cairo_bool_t -_should_use_unbounded_surface (cairo_composite_rectangles_t *composite) -{ - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - cairo_rectangle_int_t *source = &composite->source; - - if (composite->is_bounded) - return FALSE; - - /* This isn't just an optimization. It also detects when painting is used - to paint back the unbounded surface, preventing infinite recursion. */ - return ! (source->x <= 0 && source->y <= 0 && - source->height + source->y >= dst->height && - source->width + source->x >= dst->width); -} - -static cairo_surface_t* -_prepare_unbounded_surface (cairo_gl_surface_t *dst) -{ - - cairo_surface_t* surface = cairo_gl_surface_create (dst->base.device, - dst->base.content, - dst->width, - dst->height); - if (surface == NULL) - return NULL; - if (unlikely (surface->status)) { - cairo_surface_destroy (surface); - return NULL; - } - return surface; -} - -static cairo_int_status_t -_paint_back_unbounded_surface (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - cairo_surface_t *surface) -{ - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - cairo_int_status_t status; - - cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface); - if (unlikely (pattern->status)) { - status = pattern->status; - goto finish; - } - - status = _cairo_compositor_paint (compositor, &dst->base, - composite->op, pattern, - composite->clip); - -finish: - cairo_pattern_destroy (pattern); - cairo_surface_destroy (surface); - return status; -} - -static cairo_bool_t -can_use_msaa_compositor (cairo_gl_surface_t *surface, - cairo_antialias_t antialias) -{ - query_surface_capabilities (surface); - if (! surface->supports_stencil) - return FALSE; - - /* Multisampling OpenGL ES surfaces only maintain one multisampling - framebuffer and thus must use the spans compositor to do non-antialiased - rendering. */ - if (((cairo_gl_context_t *) surface->base.device)->gl_flavor == CAIRO_GL_FLAVOR_ES - && surface->supports_msaa - && antialias == CAIRO_ANTIALIAS_NONE) - return FALSE; - - /* The MSAA compositor has a single-sample mode, so we can - support non-antialiased rendering. */ - if (antialias == CAIRO_ANTIALIAS_NONE) - return TRUE; - - if (antialias == CAIRO_ANTIALIAS_FAST || antialias == CAIRO_ANTIALIAS_DEFAULT) - return surface->supports_msaa; - return FALSE; -} - -static void -_cairo_gl_msaa_compositor_set_clip (cairo_composite_rectangles_t *composite, - cairo_gl_composite_t *setup) -{ - if (_cairo_composite_rectangles_can_reduce_clip (composite, composite->clip)) - return; - _cairo_gl_composite_set_clip (setup, composite->clip); -} - -/* Masking with the SOURCE operator requires two passes. In the first - * pass we use the mask as the source to get: - * result = (1 - ma) * dst - * In the second pass we use the add operator to achieve: - * result = (src * ma) + dst - * Combined this produces: - * result = (src * ma) + (1 - ma) * dst - */ -static cairo_int_status_t -_cairo_gl_msaa_compositor_mask_source_operator (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite) -{ - cairo_gl_composite_t setup; - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - cairo_gl_context_t *ctx = NULL; - cairo_int_status_t status; - - cairo_clip_t *clip = composite->clip; - cairo_traps_t traps; - - /* If we have a non-rectangular clip, we can avoid using the stencil buffer - * for clipping and just draw the clip polygon. */ - if (clip) { - status = _clip_to_traps (clip, &traps); - if (unlikely (status)) { - _cairo_traps_fini (&traps); - return status; - } - } - - status = _cairo_gl_composite_init (&setup, - CAIRO_OPERATOR_DEST_OUT, - dst, - FALSE /* assume_component_alpha */); - if (unlikely (status)) - return status; - status = _cairo_gl_composite_set_source (&setup, - &composite->mask_pattern.base, - &composite->mask_sample_area, - &composite->bounded, - FALSE); - if (unlikely (status)) - goto finish; - _cairo_gl_composite_set_multisample (&setup); - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto finish; - - if (! clip) - status = _draw_int_rect (ctx, &setup, &composite->bounded); - else - status = _draw_traps (ctx, &setup, &traps); - if (unlikely (status)) - goto finish; - - /* Now draw the second pass. */ - status = _cairo_gl_composite_set_operator (&setup, CAIRO_OPERATOR_ADD, - FALSE /* assume_component_alpha */); - if (unlikely (status)) - goto finish; - status = _cairo_gl_composite_set_source (&setup, - &composite->source_pattern.base, - &composite->source_sample_area, - &composite->bounded, - FALSE); - if (unlikely (status)) - goto finish; - status = _cairo_gl_composite_set_mask (&setup, - &composite->mask_pattern.base, - &composite->source_sample_area, - &composite->bounded, - FALSE); - if (unlikely (status)) - goto finish; - status = _cairo_gl_set_operands_and_operator (&setup, ctx); - if (unlikely (status)) - goto finish; - - if (! clip) - status = _draw_int_rect (ctx, &setup, &composite->bounded); - else - status = _draw_traps (ctx, &setup, &traps); - -finish: - _cairo_gl_composite_fini (&setup); - if (ctx) - status = _cairo_gl_context_release (ctx, status); - if (clip) - _cairo_traps_fini (&traps); - - return status; -} - -static cairo_int_status_t -_cairo_gl_msaa_compositor_mask (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite) -{ - cairo_gl_composite_t setup; - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - cairo_gl_context_t *ctx = NULL; - cairo_int_status_t status; - cairo_operator_t op = composite->op; - cairo_clip_t *clip = composite->clip; - - if (! can_use_msaa_compositor (dst, CAIRO_ANTIALIAS_DEFAULT)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (composite->op == CAIRO_OPERATOR_CLEAR && - composite->original_mask_pattern != NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* GL compositing operators cannot properly represent a mask operation - using the SOURCE compositing operator in one pass. This only matters if - there actually is a mask (there isn't in a paint operation) and if the - mask isn't totally opaque. */ - if (op == CAIRO_OPERATOR_SOURCE && - composite->original_mask_pattern != NULL && - ! _cairo_pattern_is_opaque (&composite->mask_pattern.base, - &composite->mask_sample_area)) { - - if (! _cairo_pattern_is_opaque (&composite->source_pattern.base, - &composite->source_sample_area)) { - return _cairo_gl_msaa_compositor_mask_source_operator (compositor, composite); - } - - /* If the source is opaque the operation reduces to OVER. */ - op = CAIRO_OPERATOR_OVER; - } - - if (_should_use_unbounded_surface (composite)) { - cairo_surface_t* surface = _prepare_unbounded_surface (dst); - - if (unlikely (surface == NULL)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* This may be a paint operation. */ - if (composite->original_mask_pattern == NULL) { - status = _cairo_compositor_paint (compositor, surface, - CAIRO_OPERATOR_SOURCE, - &composite->source_pattern.base, - NULL); - } else { - status = _cairo_compositor_mask (compositor, surface, - CAIRO_OPERATOR_SOURCE, - &composite->source_pattern.base, - &composite->mask_pattern.base, - NULL); - } - - if (unlikely (status)) { - cairo_surface_destroy (surface); - return status; - } - - return _paint_back_unbounded_surface (compositor, composite, surface); - } - - status = _cairo_gl_composite_init (&setup, - op, - dst, - FALSE /* assume_component_alpha */); - if (unlikely (status)) - return status; - - status = _cairo_gl_composite_set_source (&setup, - &composite->source_pattern.base, - &composite->source_sample_area, - &composite->bounded, - FALSE); - if (unlikely (status)) - goto finish; - - if (composite->original_mask_pattern != NULL) { - status = _cairo_gl_composite_set_mask (&setup, - &composite->mask_pattern.base, - &composite->mask_sample_area, - &composite->bounded, - FALSE); - } - if (unlikely (status)) - goto finish; - - /* We always use multisampling here, because we do not yet have the smarts - to calculate when the clip or the source requires it. */ - _cairo_gl_composite_set_multisample (&setup); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto finish; - - if (! clip) - status = _draw_int_rect (ctx, &setup, &composite->bounded); - else - status = _cairo_gl_msaa_compositor_draw_clip (ctx, &setup, clip); - -finish: - _cairo_gl_composite_fini (&setup); - - if (ctx) - status = _cairo_gl_context_release (ctx, status); - - return status; -} - -static cairo_int_status_t -_cairo_gl_msaa_compositor_paint (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite) -{ - return _cairo_gl_msaa_compositor_mask (compositor, composite); -} - -static cairo_status_t -_stroke_shaper_add_triangle (void *closure, - const cairo_point_t triangle[3]) -{ - struct _tristrip_composite_info *info = closure; - return _cairo_gl_composite_emit_triangle_as_tristrip (info->ctx, - &info->setup, - triangle); -} - -static cairo_status_t -_stroke_shaper_add_triangle_fan (void *closure, - const cairo_point_t *midpoint, - const cairo_point_t *points, - int npoints) -{ - struct _tristrip_composite_info *info = closure; - return _draw_triangle_fan (info->ctx, &info->setup, - midpoint, points, npoints); -} - -static cairo_status_t -_stroke_shaper_add_quad (void *closure, - const cairo_point_t quad[4]) -{ - struct _tristrip_composite_info *info = closure; - return _cairo_gl_composite_emit_quad_as_tristrip (info->ctx, &info->setup, - quad); -} - -static cairo_int_status_t -_prevent_overlapping_strokes (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - cairo_composite_rectangles_t *composite, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm) -{ - cairo_rectangle_int_t stroke_extents; - - if (! _cairo_gl_ensure_stencil (ctx, setup->dst)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (_cairo_pattern_is_opaque (&composite->source_pattern.base, - &composite->source_sample_area)) - return CAIRO_INT_STATUS_SUCCESS; - - if (glIsEnabled (GL_STENCIL_TEST) == FALSE) { - cairo_bool_t scissor_was_enabled; - - /* In case we have pending operations we have to flush before - adding the stencil buffer. */ - _cairo_gl_composite_flush (ctx); - - /* Enable the stencil buffer, even if we are not using it for clipping, - so we can use it below to prevent overlapping shapes. We initialize - it all to one here which represents infinite clip. */ - glDepthMask (GL_TRUE); - glEnable (GL_STENCIL_TEST); - - /* We scissor here so that we don't have to clear the entire stencil - * buffer. If the scissor test is already enabled, it was enabled - * for clipping. In that case, instead of calculating an intersection, - * we just reuse it, and risk clearing too much. */ - scissor_was_enabled = glIsEnabled (GL_SCISSOR_TEST); - if (! scissor_was_enabled) { - _cairo_path_fixed_approximate_stroke_extents (path, style, ctm, - &stroke_extents); - _cairo_gl_scissor_to_rectangle (setup->dst, &stroke_extents); - } - glClearStencil (1); - glClear (GL_STENCIL_BUFFER_BIT); - if (! scissor_was_enabled) - glDisable (GL_SCISSOR_TEST); - - glStencilFunc (GL_EQUAL, 1, 1); - } - - /* This means that once we draw to a particular pixel nothing else can - be drawn there until the stencil buffer is reset or the stencil test - is disabled. */ - glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO); - - _cairo_clip_destroy (setup->dst->clip_on_stencil_buffer); - setup->dst->clip_on_stencil_buffer = NULL; - - return CAIRO_INT_STATUS_SUCCESS; -} - -static void -query_surface_capabilities (cairo_gl_surface_t *surface) -{ - GLint samples, stencil_bits; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - /* Texture surfaces are create in such a way that they always - have stencil and multisample bits if possible, so we don't - need to query their capabilities lazily. */ - if (_cairo_gl_surface_is_texture (surface)) - return; - if (surface->stencil_and_msaa_caps_initialized) - return; - - surface->stencil_and_msaa_caps_initialized = TRUE; - surface->supports_stencil = FALSE; - surface->supports_msaa = FALSE; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return; - - _cairo_gl_context_set_destination (ctx, surface, FALSE); - - glGetIntegerv(GL_SAMPLES, &samples); - glGetIntegerv(GL_STENCIL_BITS, &stencil_bits); - surface->supports_stencil = stencil_bits > 0; - surface->supports_msaa = samples > 1; - - status = _cairo_gl_context_release (ctx, status); -} - -static cairo_int_status_t -_cairo_gl_msaa_compositor_stroke (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_int_status_t status; - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - struct _tristrip_composite_info info; - - if (! can_use_msaa_compositor (dst, antialias)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (composite->is_bounded == FALSE) { - cairo_surface_t* surface = _prepare_unbounded_surface (dst); - - if (unlikely (surface == NULL)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_stroke (compositor, surface, - CAIRO_OPERATOR_SOURCE, - &composite->source_pattern.base, - path, style, ctm, ctm_inverse, - tolerance, antialias, NULL); - if (unlikely (status)) { - cairo_surface_destroy (surface); - return status; - } - - return _paint_back_unbounded_surface (compositor, composite, surface); - } - - status = _cairo_gl_composite_init (&info.setup, - composite->op, - dst, - FALSE /* assume_component_alpha */); - if (unlikely (status)) - return status; - - info.ctx = NULL; - - status = _cairo_gl_composite_set_source (&info.setup, - &composite->source_pattern.base, - &composite->source_sample_area, - &composite->bounded, - FALSE); - if (unlikely (status)) - goto finish; - - _cairo_gl_msaa_compositor_set_clip (composite, &info.setup); - if (antialias != CAIRO_ANTIALIAS_NONE) - _cairo_gl_composite_set_multisample (&info.setup); - - status = _cairo_gl_composite_begin (&info.setup, &info.ctx); - if (unlikely (status)) - goto finish; - - status = _prevent_overlapping_strokes (info.ctx, &info.setup, - composite, path, style, ctm); - if (unlikely (status)) - goto finish; - - status = _cairo_path_fixed_stroke_to_shaper ((cairo_path_fixed_t *) path, - style, - ctm, - ctm_inverse, - tolerance, - _stroke_shaper_add_triangle, - _stroke_shaper_add_triangle_fan, - _stroke_shaper_add_quad, - &info); - if (unlikely (status)) - goto finish; - -finish: - _cairo_gl_composite_fini (&info.setup); - - if (info.ctx) - status = _cairo_gl_context_release (info.ctx, status); - - return status; -} - -static cairo_int_status_t -_draw_simple_quad_path (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - const cairo_path_fixed_t *path) -{ - cairo_point_t triangle[3]; - cairo_int_status_t status; - const cairo_point_t *points; - - points = cairo_path_head (path)->points; - triangle[0] = points[0]; - triangle[1] = points[1]; - triangle[2] = points[2]; - status = _cairo_gl_composite_emit_triangle_as_tristrip (ctx, setup, triangle); - if (status) - return status; - - triangle[0] = points[2]; - triangle[1] = points[3]; - triangle[2] = points[0]; - return _cairo_gl_composite_emit_triangle_as_tristrip (ctx, setup, triangle); -} - -static cairo_int_status_t -_cairo_gl_msaa_compositor_fill (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_gl_composite_t setup; - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - cairo_gl_context_t *ctx = NULL; - cairo_int_status_t status; - cairo_traps_t traps; - cairo_bool_t draw_path_with_traps; - - if (! can_use_msaa_compositor (dst, antialias)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (composite->is_bounded == FALSE) { - cairo_surface_t* surface = _prepare_unbounded_surface (dst); - - if (unlikely (surface == NULL)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - - status = _cairo_compositor_fill (compositor, surface, - CAIRO_OPERATOR_SOURCE, - &composite->source_pattern.base, - path, fill_rule, tolerance, - antialias, NULL); - - if (unlikely (status)) { - cairo_surface_destroy (surface); - return status; - } - - return _paint_back_unbounded_surface (compositor, composite, surface); - } - - draw_path_with_traps = ! _cairo_path_fixed_is_simple_quad (path); - - if (draw_path_with_traps) { - _cairo_traps_init (&traps); - status = _cairo_path_fixed_fill_to_traps (path, fill_rule, tolerance, &traps); - if (unlikely (status)) - goto cleanup_traps; - } - - status = _cairo_gl_composite_init (&setup, - composite->op, - dst, - FALSE /* assume_component_alpha */); - if (unlikely (status)) - goto cleanup_traps; - - status = _cairo_gl_composite_set_source (&setup, - &composite->source_pattern.base, - &composite->source_sample_area, - &composite->bounded, - FALSE); - if (unlikely (status)) - goto cleanup_setup; - - _cairo_gl_msaa_compositor_set_clip (composite, &setup); - if (antialias != CAIRO_ANTIALIAS_NONE) - _cairo_gl_composite_set_multisample (&setup); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto cleanup_setup; - - if (! draw_path_with_traps) - status = _draw_simple_quad_path (ctx, &setup, path); - else - status = _draw_traps (ctx, &setup, &traps); - if (unlikely (status)) - goto cleanup_setup; - -cleanup_setup: - _cairo_gl_composite_fini (&setup); - - if (ctx) - status = _cairo_gl_context_release (ctx, status); - -cleanup_traps: - if (draw_path_with_traps) - _cairo_traps_fini (&traps); - - return status; -} - -static cairo_int_status_t -_cairo_gl_msaa_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_int_status_t status; - cairo_surface_t *src = NULL; - int src_x, src_y; - cairo_composite_glyphs_info_t info; - - cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; - - query_surface_capabilities (dst); - if (! dst->supports_stencil) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (composite->op == CAIRO_OPERATOR_CLEAR) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (composite->is_bounded == FALSE) { - cairo_surface_t* surface = _prepare_unbounded_surface (dst); - - if (unlikely (surface == NULL)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_glyphs (compositor, surface, - CAIRO_OPERATOR_SOURCE, - &composite->source_pattern.base, - glyphs, num_glyphs, - scaled_font, composite->clip); - - if (unlikely (status)) { - cairo_surface_destroy (surface); - return status; - } - - return _paint_back_unbounded_surface (compositor, composite, surface); - } - - src = _cairo_gl_pattern_to_source (&dst->base, - &composite->source_pattern.base, - FALSE, - &composite->bounded, - &composite->source_sample_area, - &src_x, &src_y); - if (unlikely (src->status)) { - status = src->status; - goto finish; - } - - status = _cairo_gl_check_composite_glyphs (composite, - scaled_font, glyphs, - &num_glyphs); - if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) - goto finish; - - info.font = scaled_font; - info.glyphs = glyphs; - info.num_glyphs = num_glyphs; - info.use_mask = overlap || ! composite->is_bounded || - composite->op == CAIRO_OPERATOR_SOURCE; - info.extents = composite->bounded; - - _cairo_scaled_font_freeze_cache (scaled_font); - status = _cairo_gl_composite_glyphs_with_clip (dst, composite->op, - src, src_x, src_y, - 0, 0, &info, - composite->clip); - - _cairo_scaled_font_thaw_cache (scaled_font); - -finish: - if (src) - cairo_surface_destroy (src); - - return status; -} - -static void -_cairo_gl_msaa_compositor_init (cairo_compositor_t *compositor, - const cairo_compositor_t *delegate) -{ - compositor->delegate = delegate; - - compositor->paint = _cairo_gl_msaa_compositor_paint; - compositor->mask = _cairo_gl_msaa_compositor_mask; - compositor->fill = _cairo_gl_msaa_compositor_fill; - compositor->stroke = _cairo_gl_msaa_compositor_stroke; - compositor->glyphs = _cairo_gl_msaa_compositor_glyphs; -} - -const cairo_compositor_t * -_cairo_gl_msaa_compositor_get (void) -{ - static cairo_compositor_t compositor; - if (compositor.delegate == NULL) - _cairo_gl_msaa_compositor_init (&compositor, - _cairo_gl_span_compositor_get ()); - - return &compositor; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-operand.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-operand.c deleted file mode 100644 index 40157471747..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-operand.c +++ /dev/null @@ -1,788 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-surface-offset-private.h" -#include "cairo-surface-subsurface-inline.h" - -static cairo_int_status_t -_cairo_gl_create_gradient_texture (cairo_gl_surface_t *dst, - const cairo_gradient_pattern_t *pattern, - cairo_gl_gradient_t **gradient) -{ - cairo_gl_context_t *ctx; - cairo_status_t status; - - status = _cairo_gl_context_acquire (dst->base.device, &ctx); - if (unlikely (status)) - return status; - - status = _cairo_gl_gradient_create (ctx, pattern->n_stops, pattern->stops, gradient); - - return _cairo_gl_context_release (ctx, status); -} - -static cairo_status_t -_cairo_gl_subsurface_clone_operand_init (cairo_gl_operand_t *operand, - const cairo_pattern_t *_src, - cairo_gl_surface_t *dst, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen) -{ - const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src; - cairo_surface_pattern_t local_pattern; - cairo_surface_subsurface_t *sub; - cairo_gl_surface_t *surface; - cairo_gl_context_t *ctx; - cairo_surface_attributes_t *attributes; - cairo_status_t status; - - sub = (cairo_surface_subsurface_t *) src->surface; - - if (sub->snapshot && - sub->snapshot->type == CAIRO_SURFACE_TYPE_GL && - sub->snapshot->device == dst->base.device) - { - surface = (cairo_gl_surface_t *) - cairo_surface_reference (sub->snapshot); - } - else - { - status = _cairo_gl_context_acquire (dst->base.device, &ctx); - if (unlikely (status)) - return status; - - /* XXX Trim surface to the sample area within the subsurface? */ - surface = (cairo_gl_surface_t *) - _cairo_gl_surface_create_scratch (ctx, - sub->target->content, - sub->extents.width, - sub->extents.height); - if (surface->base.status) - return _cairo_gl_context_release (ctx, surface->base.status); - - _cairo_pattern_init_for_surface (&local_pattern, sub->target); - cairo_matrix_init_translate (&local_pattern.base.matrix, - sub->extents.x, sub->extents.y); - local_pattern.base.filter = CAIRO_FILTER_NEAREST; - status = _cairo_surface_paint (&surface->base, - CAIRO_OPERATOR_SOURCE, - &local_pattern.base, - NULL); - _cairo_pattern_fini (&local_pattern.base); - - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return status; - } - - _cairo_surface_subsurface_set_snapshot (&sub->base, &surface->base); - } - - status = _cairo_gl_surface_resolve_multisampling (surface); - if (unlikely (status)) - return status; - - attributes = &operand->texture.attributes; - - operand->type = CAIRO_GL_OPERAND_TEXTURE; - operand->texture.surface = surface; - operand->texture.owns_surface = surface; - operand->texture.tex = surface->tex; - - if (_cairo_gl_device_requires_power_of_two_textures (dst->base.device)) { - attributes->matrix = src->base.matrix; - } else { - cairo_matrix_t m; - - cairo_matrix_init_scale (&m, - 1.0 / surface->width, - 1.0 / surface->height); - cairo_matrix_multiply (&attributes->matrix, &src->base.matrix, &m); - } - - attributes->extend = src->base.extend; - attributes->filter = src->base.filter; - attributes->has_component_alpha = src->base.has_component_alpha; - - operand->texture.texgen = use_texgen; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_subsurface_operand_init (cairo_gl_operand_t *operand, - const cairo_pattern_t *_src, - cairo_gl_surface_t *dst, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen) -{ - const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src; - cairo_surface_subsurface_t *sub; - cairo_gl_surface_t *surface; - cairo_surface_attributes_t *attributes; - cairo_int_status_t status; - - sub = (cairo_surface_subsurface_t *) src->surface; - - if (sample->x < 0 || sample->y < 0 || - sample->x + sample->width > sub->extents.width || - sample->y + sample->height > sub->extents.height) - { - return _cairo_gl_subsurface_clone_operand_init (operand, _src, - dst, sample, extents, - use_texgen); - } - - surface = (cairo_gl_surface_t *) sub->target; - if (surface->base.device && surface->base.device != dst->base.device) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_gl_surface_is_texture (surface)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_gl_surface_resolve_multisampling (surface); - if (unlikely (status)) - return status; - - /* Translate the matrix from - * (unnormalized src -> unnormalized src) to - * (unnormalized dst -> unnormalized src) - */ - _cairo_gl_operand_copy(operand, &surface->operand); - - attributes = &operand->texture.attributes; - attributes->matrix = src->base.matrix; - attributes->matrix.x0 += sub->extents.x; - attributes->matrix.y0 += sub->extents.y; - cairo_matrix_multiply (&attributes->matrix, - &attributes->matrix, - &surface->operand.texture.attributes.matrix); - - attributes->extend = src->base.extend; - attributes->filter = src->base.filter; - attributes->has_component_alpha = src->base.has_component_alpha; - - operand->texture.texgen = use_texgen; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_surface_operand_init (cairo_gl_operand_t *operand, - const cairo_pattern_t *_src, - cairo_gl_surface_t *dst, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen) -{ - const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src; - cairo_gl_surface_t *surface; - cairo_surface_attributes_t *attributes; - cairo_int_status_t status; - - surface = (cairo_gl_surface_t *) src->surface; - if (surface->base.type != CAIRO_SURFACE_TYPE_GL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (surface->base.backend->type != CAIRO_SURFACE_TYPE_GL) { - if (_cairo_surface_is_subsurface (&surface->base)) - return _cairo_gl_subsurface_operand_init (operand, _src, dst, - sample, extents, - use_texgen); - - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (surface->base.device && surface->base.device != dst->base.device) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (surface->base.device && ! _cairo_gl_surface_is_texture (surface)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_gl_surface_resolve_multisampling (surface); - if (unlikely (status)) - return status; - - _cairo_gl_operand_copy(operand, &surface->operand); - - attributes = &operand->texture.attributes; - cairo_matrix_multiply (&attributes->matrix, - &src->base.matrix, - &attributes->matrix); - - attributes->extend = src->base.extend; - attributes->filter = src->base.filter; - attributes->has_component_alpha = src->base.has_component_alpha; - - operand->texture.texgen = use_texgen; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_pattern_texture_setup (cairo_gl_operand_t *operand, - const cairo_pattern_t *_src, - cairo_gl_surface_t *dst, - const cairo_rectangle_int_t *extents) -{ - cairo_status_t status; - cairo_gl_surface_t *surface; - cairo_gl_context_t *ctx; - cairo_image_surface_t *image; - cairo_bool_t src_is_gl_surface = FALSE; - cairo_rectangle_int_t map_extents; - - if (_src->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_t* src_surface = ((cairo_surface_pattern_t *) _src)->surface; - src_is_gl_surface = src_surface->type == CAIRO_SURFACE_TYPE_GL; - } - - status = _cairo_gl_context_acquire (dst->base.device, &ctx); - if (unlikely (status)) - return status; - - surface = (cairo_gl_surface_t *) - _cairo_gl_surface_create_scratch (ctx, - CAIRO_CONTENT_COLOR_ALPHA, - extents->width, extents->height); - map_extents = *extents; - map_extents.x = map_extents.y = 0; - image = _cairo_surface_map_to_image (&surface->base, &map_extents); - - /* If the pattern is a GL surface, it belongs to some other GL context, - so we need to release this device while we paint it to the image. */ - if (src_is_gl_surface) { - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) - goto fail; - } - - status = _cairo_surface_offset_paint (&image->base, extents->x, extents->y, - CAIRO_OPERATOR_SOURCE, _src, NULL); - - if (src_is_gl_surface) { - status = _cairo_gl_context_acquire (dst->base.device, &ctx); - if (unlikely (status)) - goto fail; - } - - status = _cairo_surface_unmap_image (&surface->base, image); - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) - goto fail; - - *operand = surface->operand; - operand->texture.owns_surface = surface; - operand->texture.attributes.matrix.x0 -= extents->x * operand->texture.attributes.matrix.xx; - operand->texture.attributes.matrix.y0 -= extents->y * operand->texture.attributes.matrix.yy; - return CAIRO_STATUS_SUCCESS; - -fail: - cairo_surface_destroy (&surface->base); - return status; -} - -void -_cairo_gl_solid_operand_init (cairo_gl_operand_t *operand, - const cairo_color_t *color) -{ - operand->type = CAIRO_GL_OPERAND_CONSTANT; - operand->constant.color[0] = color->red * color->alpha; - operand->constant.color[1] = color->green * color->alpha; - operand->constant.color[2] = color->blue * color->alpha; - operand->constant.color[3] = color->alpha; -} - -void -_cairo_gl_operand_translate (cairo_gl_operand_t *operand, - double tx, double ty) -{ - switch (operand->type) { - case CAIRO_GL_OPERAND_TEXTURE: - operand->texture.attributes.matrix.x0 -= tx * operand->texture.attributes.matrix.xx; - operand->texture.attributes.matrix.y0 -= ty * operand->texture.attributes.matrix.yy; - break; - - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - operand->gradient.m.x0 -= tx * operand->gradient.m.xx; - operand->gradient.m.y0 -= ty * operand->gradient.m.yy; - break; - - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - case CAIRO_GL_OPERAND_COUNT: - default: - break; - } -} - -static cairo_status_t -_cairo_gl_gradient_operand_init (cairo_gl_operand_t *operand, - const cairo_pattern_t *pattern, - cairo_gl_surface_t *dst, - cairo_bool_t use_texgen) -{ - const cairo_gradient_pattern_t *gradient = (const cairo_gradient_pattern_t *)pattern; - cairo_status_t status; - - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - - if (! _cairo_gl_device_has_glsl (dst->base.device)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_gl_create_gradient_texture (dst, - gradient, - &operand->gradient.gradient); - if (unlikely (status)) - return status; - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; - double x0, y0, dx, dy, sf, offset; - - dx = linear->pd2.x - linear->pd1.x; - dy = linear->pd2.y - linear->pd1.y; - sf = 1.0 / (dx * dx + dy * dy); - dx *= sf; - dy *= sf; - - x0 = linear->pd1.x; - y0 = linear->pd1.y; - offset = dx * x0 + dy * y0; - - operand->type = CAIRO_GL_OPERAND_LINEAR_GRADIENT; - - cairo_matrix_init (&operand->gradient.m, dx, 0, dy, 1, -offset, 0); - if (! _cairo_matrix_is_identity (&pattern->matrix)) { - cairo_matrix_multiply (&operand->gradient.m, - &pattern->matrix, - &operand->gradient.m); - } - } else { - cairo_matrix_t m; - cairo_circle_double_t circles[2]; - double x0, y0, r0, dx, dy, dr; - - /* - * Some fragment shader implementations use half-floats to - * represent numbers, so the maximum number they can represent - * is about 2^14. Some intermediate computations used in the - * radial gradient shaders can produce results of up to 2*k^4. - * Setting k=8 makes the maximum result about 8192 (assuming - * that the extreme circles are not much smaller than the - * destination image). - */ - _cairo_gradient_pattern_fit_to_range (gradient, 8., - &operand->gradient.m, circles); - - x0 = circles[0].center.x; - y0 = circles[0].center.y; - r0 = circles[0].radius; - dx = circles[1].center.x - x0; - dy = circles[1].center.y - y0; - dr = circles[1].radius - r0; - - operand->gradient.a = dx * dx + dy * dy - dr * dr; - operand->gradient.radius_0 = r0; - operand->gradient.circle_d.center.x = dx; - operand->gradient.circle_d.center.y = dy; - operand->gradient.circle_d.radius = dr; - - if (operand->gradient.a == 0) - operand->type = CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0; - else if (pattern->extend == CAIRO_EXTEND_NONE) - operand->type = CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE; - else - operand->type = CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT; - - cairo_matrix_init_translate (&m, -x0, -y0); - cairo_matrix_multiply (&operand->gradient.m, - &operand->gradient.m, - &m); - } - - operand->gradient.extend = pattern->extend; - operand->gradient.texgen = use_texgen; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gl_operand_copy (cairo_gl_operand_t *dst, - const cairo_gl_operand_t *src) -{ - *dst = *src; - switch (dst->type) { - case CAIRO_GL_OPERAND_CONSTANT: - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - _cairo_gl_gradient_reference (dst->gradient.gradient); - break; - case CAIRO_GL_OPERAND_TEXTURE: - cairo_surface_reference (&dst->texture.owns_surface->base); - break; - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - break; - } -} - -void -_cairo_gl_operand_destroy (cairo_gl_operand_t *operand) -{ - switch (operand->type) { - case CAIRO_GL_OPERAND_CONSTANT: - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - _cairo_gl_gradient_destroy (operand->gradient.gradient); - break; - case CAIRO_GL_OPERAND_TEXTURE: - cairo_surface_destroy (&operand->texture.owns_surface->base); - break; - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - break; - } - - operand->type = CAIRO_GL_OPERAND_NONE; -} - -cairo_int_status_t -_cairo_gl_operand_init (cairo_gl_operand_t *operand, - const cairo_pattern_t *pattern, - cairo_gl_surface_t *dst, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s: type=%d\n", __FUNCTION__, pattern->type)); - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - _cairo_gl_solid_operand_init (operand, - &((cairo_solid_pattern_t *) pattern)->color); - return CAIRO_STATUS_SUCCESS; - case CAIRO_PATTERN_TYPE_SURFACE: - status = _cairo_gl_surface_operand_init (operand, pattern, dst, - sample, extents, use_texgen); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - break; - - return status; - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - status = _cairo_gl_gradient_operand_init (operand, pattern, dst, - use_texgen); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - break; - - return status; - - default: - case CAIRO_PATTERN_TYPE_MESH: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - break; - } - - return _cairo_gl_pattern_texture_setup (operand, pattern, dst, extents); -} - -cairo_filter_t -_cairo_gl_operand_get_filter (cairo_gl_operand_t *operand) -{ - cairo_filter_t filter; - - switch ((int) operand->type) { - case CAIRO_GL_OPERAND_TEXTURE: - filter = operand->texture.attributes.filter; - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - filter = CAIRO_FILTER_BILINEAR; - break; - default: - filter = CAIRO_FILTER_DEFAULT; - break; - } - - return filter; -} - -GLint -_cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand) -{ - cairo_filter_t filter = _cairo_gl_operand_get_filter (operand); - - return filter != CAIRO_FILTER_FAST && filter != CAIRO_FILTER_NEAREST ? - GL_LINEAR : - GL_NEAREST; -} - -cairo_extend_t -_cairo_gl_operand_get_extend (cairo_gl_operand_t *operand) -{ - cairo_extend_t extend; - - switch ((int) operand->type) { - case CAIRO_GL_OPERAND_TEXTURE: - extend = operand->texture.attributes.extend; - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - extend = operand->gradient.extend; - break; - default: - extend = CAIRO_EXTEND_NONE; - break; - } - - return extend; -} - - -void -_cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, - cairo_gl_operand_t *operand, - cairo_gl_tex_t tex_unit) -{ - const cairo_matrix_t *texgen = NULL; - - switch (operand->type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - return; - - case CAIRO_GL_OPERAND_CONSTANT: - _cairo_gl_shader_bind_vec4 (ctx, - ctx->current_shader->constant_location[tex_unit], - operand->constant.color[0], - operand->constant.color[1], - operand->constant.color[2], - operand->constant.color[3]); - return; - - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - _cairo_gl_shader_bind_float (ctx, - ctx->current_shader->a_location[tex_unit], - operand->gradient.a); - /* fall through */ - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - _cairo_gl_shader_bind_vec3 (ctx, - ctx->current_shader->circle_d_location[tex_unit], - operand->gradient.circle_d.center.x, - operand->gradient.circle_d.center.y, - operand->gradient.circle_d.radius); - _cairo_gl_shader_bind_float (ctx, - ctx->current_shader->radius_0_location[tex_unit], - operand->gradient.radius_0); - /* fall through */ - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_TEXTURE: - /* - * For GLES2 we use shaders to implement GL_CLAMP_TO_BORDER (used - * with CAIRO_EXTEND_NONE). When bilinear filtering is enabled, - * these shaders need the texture dimensions for their calculations. - */ - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && - _cairo_gl_operand_get_extend (operand) == CAIRO_EXTEND_NONE && - _cairo_gl_operand_get_gl_filter (operand) == GL_LINEAR) - { - float width, height; - if (operand->type == CAIRO_GL_OPERAND_TEXTURE) { - width = operand->texture.surface->width; - height = operand->texture.surface->height; - } - else { - width = operand->gradient.gradient->cache_entry.size, - height = 1; - } - _cairo_gl_shader_bind_vec2 (ctx, - ctx->current_shader->texdims_location[tex_unit], - width, height); - } - break; - } - - if (operand->type == CAIRO_GL_OPERAND_TEXTURE) { - if (operand->texture.texgen) - texgen = &operand->texture.attributes.matrix; - } else { - if (operand->gradient.texgen) - texgen = &operand->gradient.m; - } - if (texgen) { - _cairo_gl_shader_bind_matrix(ctx, - ctx->current_shader->texgen_location[tex_unit], - texgen); - } -} - - -cairo_bool_t -_cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest, - cairo_gl_operand_t *source, - unsigned int vertex_offset) -{ - if (dest->type != source->type) - return TRUE; - if (dest->vertex_offset != vertex_offset) - return TRUE; - - switch (source->type) { - case CAIRO_GL_OPERAND_NONE: - return FALSE; - case CAIRO_GL_OPERAND_CONSTANT: - return dest->constant.color[0] != source->constant.color[0] || - dest->constant.color[1] != source->constant.color[1] || - dest->constant.color[2] != source->constant.color[2] || - dest->constant.color[3] != source->constant.color[3]; - case CAIRO_GL_OPERAND_TEXTURE: - return dest->texture.surface != source->texture.surface || - dest->texture.attributes.extend != source->texture.attributes.extend || - dest->texture.attributes.filter != source->texture.attributes.filter || - dest->texture.attributes.has_component_alpha != source->texture.attributes.has_component_alpha; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - /* XXX: improve this */ - return TRUE; - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - break; - } - return TRUE; -} - -unsigned int -_cairo_gl_operand_get_vertex_size (const cairo_gl_operand_t *operand) -{ - switch (operand->type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - return 0; - case CAIRO_GL_OPERAND_TEXTURE: - return operand->texture.texgen ? 0 : 2 * sizeof (GLfloat); - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - return operand->gradient.texgen ? 0 : 2 * sizeof (GLfloat); - } -} - -void -_cairo_gl_operand_emit (cairo_gl_operand_t *operand, - GLfloat ** vb, - GLfloat x, - GLfloat y) -{ - switch (operand->type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - if (! operand->gradient.texgen) { - double s = x; - double t = y; - - cairo_matrix_transform_point (&operand->gradient.m, &s, &t); - - *(*vb)++ = s; - *(*vb)++ = t; - } - break; - case CAIRO_GL_OPERAND_TEXTURE: - if (! operand->texture.texgen) { - cairo_surface_attributes_t *src_attributes = &operand->texture.attributes; - double s = x; - double t = y; - - cairo_matrix_transform_point (&src_attributes->matrix, &s, &t); - *(*vb)++ = s; - *(*vb)++ = t; - } - break; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-private.h deleted file mode 100644 index cb915c8cf25..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-private.h +++ /dev/null @@ -1,853 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * Copyright © 2011 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - * T. Zachary Laine - * Alexandros Frantzis - */ - -#ifndef CAIRO_GL_PRIVATE_H -#define CAIRO_GL_PRIVATE_H - -#define GL_GLEXT_PROTOTYPES - -#include "cairoint.h" - -#include "cairo-gl.h" -#include "cairo-gl-gradient-private.h" - -#include "cairo-device-private.h" -#include "cairo-error-private.h" -#include "cairo-rtree-private.h" -#include "cairo-scaled-font-private.h" -#include "cairo-spans-compositor-private.h" -#include "cairo-array-private.h" - -#include - -#if CAIRO_HAS_GL_SURFACE -#include -#include -#elif CAIRO_HAS_GLESV2_SURFACE -#include -#include -#endif - -#include "cairo-gl-ext-def-private.h" - -#define DEBUG_GL 0 - -#if DEBUG_GL && __GNUC__ -#define UNSUPPORTED(reason) ({ \ - fprintf (stderr, \ - "cairo-gl: hit unsupported operation in %s(), line %d: %s\n", \ - __FUNCTION__, __LINE__, reason); \ - CAIRO_INT_STATUS_UNSUPPORTED; \ -}) -#else -#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED -#endif - -#define CAIRO_GL_VERSION_ENCODE(major, minor) ( \ - ((major) * 256) \ - + ((minor) * 1)) - -/* maximal number of shaders we keep in the cache. - * Random number that is hopefully big enough to not cause many cache evictions. */ -#define CAIRO_GL_MAX_SHADERS_PER_CONTEXT 64 - -/* VBO size that we allocate, smaller size means we gotta flush more often, - * but larger means hogging more memory and can cause trouble for drivers - * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment - * variable to set this to a different size. */ -#define CAIRO_GL_VBO_SIZE_DEFAULT (1024*1024) - -typedef struct _cairo_gl_surface cairo_gl_surface_t; - -/* GL flavor */ -typedef enum cairo_gl_flavor { - CAIRO_GL_FLAVOR_NONE = 0, - CAIRO_GL_FLAVOR_DESKTOP = 1, - CAIRO_GL_FLAVOR_ES = 2 -} cairo_gl_flavor_t; - -/* Indices for vertex attributes used by BindAttribLocation etc */ -enum { - CAIRO_GL_VERTEX_ATTRIB_INDEX = 0, - CAIRO_GL_COLOR_ATTRIB_INDEX = 1, - CAIRO_GL_TEXCOORD0_ATTRIB_INDEX = 2, - CAIRO_GL_TEXCOORD1_ATTRIB_INDEX = CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + 1 -}; - -typedef enum cairo_gl_operand_type { - CAIRO_GL_OPERAND_NONE, - CAIRO_GL_OPERAND_CONSTANT, - CAIRO_GL_OPERAND_TEXTURE, - CAIRO_GL_OPERAND_LINEAR_GRADIENT, - CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0, - CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE, - CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT, - - CAIRO_GL_OPERAND_COUNT -} cairo_gl_operand_type_t; - -/* This union structure describes a potential source or mask operand to the - * compositing equation. - */ -typedef struct cairo_gl_operand { - cairo_gl_operand_type_t type; - union { - struct { - GLuint tex; - cairo_gl_surface_t *surface; - cairo_gl_surface_t *owns_surface; - cairo_surface_attributes_t attributes; - int texgen; - } texture; - struct { - GLfloat color[4]; - } constant; - struct { - cairo_gl_gradient_t *gradient; - cairo_matrix_t m; - cairo_circle_double_t circle_d; - double radius_0, a; - cairo_extend_t extend; - int texgen; - } gradient; - }; - unsigned int vertex_offset; -} cairo_gl_operand_t; - -typedef struct cairo_gl_source { - cairo_surface_t base; - cairo_gl_operand_t operand; -} cairo_gl_source_t; - -struct _cairo_gl_surface { - cairo_surface_t base; - cairo_gl_operand_t operand; - - int width, height; - - GLuint tex; /* GL texture object containing our data. */ - GLuint fb; /* GL framebuffer object wrapping our data. */ - GLuint depth_stencil; /* GL renderbuffer object for holding stencil buffer clip. */ - -#if CAIRO_HAS_GL_SURFACE - GLuint msaa_rb; /* The ARB MSAA path uses a renderbuffer. */ - GLuint msaa_fb; -#endif - GLuint msaa_depth_stencil; - - cairo_bool_t stencil_and_msaa_caps_initialized; - cairo_bool_t supports_stencil; /* Stencil support for for non-texture surfaces. */ - cairo_bool_t supports_msaa; - cairo_bool_t msaa_active; /* Whether the multisampling - framebuffer is active or not. */ - cairo_clip_t *clip_on_stencil_buffer; - - int owns_tex; - cairo_bool_t needs_update; - - cairo_region_t *clip_region; -}; - -typedef struct cairo_gl_glyph_cache { - cairo_rtree_t rtree; - cairo_gl_surface_t *surface; -} cairo_gl_glyph_cache_t; - -typedef enum cairo_gl_tex { - CAIRO_GL_TEX_SOURCE = 0, - CAIRO_GL_TEX_MASK = 1, - CAIRO_GL_TEX_TEMP = 2 -} cairo_gl_tex_t; - -typedef struct cairo_gl_shader { - GLuint fragment_shader; - GLuint program; - GLint mvp_location; - GLint constant_location[2]; - GLint a_location[2]; - GLint circle_d_location[2]; - GLint radius_0_location[2]; - GLint texdims_location[2]; - GLint texgen_location[2]; -} cairo_gl_shader_t; - -typedef enum cairo_gl_shader_in { - CAIRO_GL_SHADER_IN_NORMAL, - CAIRO_GL_SHADER_IN_CA_SOURCE, - CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA, - - CAIRO_GL_SHADER_IN_COUNT -} cairo_gl_shader_in_t; - -typedef enum cairo_gl_var_type { - CAIRO_GL_VAR_NONE, - CAIRO_GL_VAR_TEXCOORDS, - CAIRO_GL_VAR_TEXGEN, -} cairo_gl_var_type_t; - -typedef enum cairo_gl_primitive_type { - CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES, - CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS -} cairo_gl_primitive_type_t; - -typedef void (*cairo_gl_emit_rect_t) (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2); - -typedef void (*cairo_gl_emit_span_t) (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2, - uint8_t alpha); - -typedef void (*cairo_gl_emit_glyph_t) (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2, - GLfloat glyph_x1, GLfloat glyph_y1, - GLfloat glyph_x2, GLfloat glyph_y2); - -#define cairo_gl_var_type_hash(src,mask,spans,dest) ((spans) << 5) | ((mask) << 3 | (src << 1) | (dest)) -#define CAIRO_GL_VAR_TYPE_MAX (1 << 6) - -typedef void (*cairo_gl_generic_func_t)(void); -typedef cairo_gl_generic_func_t (*cairo_gl_get_proc_addr_func_t)(const char *procname); - -typedef struct _cairo_gl_dispatch { - /* Buffers */ - void (*GenBuffers) (GLsizei n, GLuint *buffers); - void (*BindBuffer) (GLenum target, GLuint buffer); - void (*BufferData) (GLenum target, GLsizeiptr size, - const GLvoid* data, GLenum usage); - GLvoid *(*MapBuffer) (GLenum target, GLenum access); - GLboolean (*UnmapBuffer) (GLenum target); - - /* Shaders */ - GLuint (*CreateShader) (GLenum type); - void (*ShaderSource) (GLuint shader, GLsizei count, - const GLchar** string, const GLint* length); - void (*CompileShader) (GLuint shader); - void (*GetShaderiv) (GLuint shader, GLenum pname, GLint *params); - void (*GetShaderInfoLog) (GLuint shader, GLsizei bufSize, - GLsizei *length, GLchar *infoLog); - void (*DeleteShader) (GLuint shader); - - /* Programs */ - GLuint (*CreateProgram) (void); - void (*AttachShader) (GLuint program, GLuint shader); - void (*DeleteProgram) (GLuint program); - void (*LinkProgram) (GLuint program); - void (*UseProgram) (GLuint program); - void (*GetProgramiv) (GLuint program, GLenum pname, GLint *params); - void (*GetProgramInfoLog) (GLuint program, GLsizei bufSize, - GLsizei *length, GLchar *infoLog); - - /* Uniforms */ - GLint (*GetUniformLocation) (GLuint program, const GLchar* name); - void (*Uniform1f) (GLint location, GLfloat x); - void (*Uniform2f) (GLint location, GLfloat x, GLfloat y); - void (*Uniform3f) (GLint location, GLfloat x, GLfloat y, GLfloat z); - void (*Uniform4f) (GLint location, GLfloat x, GLfloat y, GLfloat z, - GLfloat w); - void (*UniformMatrix3fv) (GLint location, GLsizei count, - GLboolean transpose, const GLfloat *value); - void (*UniformMatrix4fv) (GLint location, GLsizei count, - GLboolean transpose, const GLfloat *value); - void (*Uniform1i) (GLint location, GLint x); - - /* Attributes */ - void (*BindAttribLocation) (GLuint program, GLuint index, - const GLchar *name); - void (*VertexAttribPointer) (GLuint index, GLint size, GLenum type, - GLboolean normalized, GLsizei stride, - const GLvoid *pointer); - void (*EnableVertexAttribArray) (GLuint index); - void (*DisableVertexAttribArray) (GLuint index); - - /* Framebuffer objects */ - void (*GenFramebuffers) (GLsizei n, GLuint* framebuffers); - void (*BindFramebuffer) (GLenum target, GLuint framebuffer); - void (*FramebufferTexture2D) (GLenum target, GLenum attachment, - GLenum textarget, GLuint texture, - GLint level); - GLenum (*CheckFramebufferStatus) (GLenum target); - void (*DeleteFramebuffers) (GLsizei n, const GLuint* framebuffers); - void (*GenRenderbuffers) (GLsizei n, GLuint *renderbuffers); - void (*BindRenderbuffer) (GLenum target, GLuint renderbuffer); - void (*RenderbufferStorage) (GLenum target, GLenum internal_format, - GLsizei width, GLsizei height); - void (*FramebufferRenderbuffer) (GLenum target, GLenum attachment, - GLenum renderbuffer_ttarget, GLuint renderbuffer); - void (*DeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers); - void (*BlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, - GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, - GLbitfield mask, GLenum filter); - void (*RenderbufferStorageMultisample) (GLenum target, GLsizei samples, - GLenum internalformat, - GLsizei width, GLsizei height); - void (*FramebufferTexture2DMultisample) (GLenum target, GLenum attachment, - GLenum textarget, GLuint texture, - GLint level, GLsizei samples); -} cairo_gl_dispatch_t; - -struct _cairo_gl_context { - cairo_device_t base; - - const cairo_compositor_t *compositor; - - GLuint texture_load_pbo; - GLint max_framebuffer_size; - GLint max_texture_size; - GLint max_textures; - GLenum tex_target; - - GLint num_samples; - cairo_bool_t supports_msaa; - char *vb; - - cairo_bool_t has_shader_support; - - GLuint vertex_shaders[CAIRO_GL_VAR_TYPE_MAX]; - cairo_gl_shader_t fill_rectangles_shader; - cairo_cache_t shaders; - - cairo_cache_t gradients; - - cairo_gl_glyph_cache_t glyph_cache[2]; - cairo_list_t fonts; - - cairo_gl_surface_t *current_target; - cairo_operator_t current_operator; - cairo_gl_shader_t *pre_shader; /* for component alpha */ - cairo_gl_shader_t *current_shader; - - cairo_gl_operand_t operands[2]; - cairo_bool_t spans; - - unsigned int vbo_size; - unsigned int vb_offset; - unsigned int vertex_size; - cairo_region_t *clip_region; - cairo_clip_t *clip; - - cairo_gl_primitive_type_t primitive_type; - cairo_array_t tristrip_indices; - - cairo_bool_t has_mesa_pack_invert; - cairo_gl_dispatch_t dispatch; - GLfloat modelviewprojection_matrix[16]; - cairo_gl_flavor_t gl_flavor; - cairo_bool_t has_map_buffer; - cairo_bool_t has_packed_depth_stencil; - cairo_bool_t has_npot_repeat; - cairo_bool_t can_read_bgra; - - cairo_bool_t thread_aware; - - void (*acquire) (void *ctx); - void (*release) (void *ctx); - - void (*make_current) (void *ctx, cairo_gl_surface_t *surface); - void (*swap_buffers)(void *ctx, cairo_gl_surface_t *surface); - void (*destroy) (void *ctx); -}; - -typedef struct _cairo_gl_composite { - cairo_gl_surface_t *dst; - cairo_operator_t op; - cairo_region_t *clip_region; - - cairo_gl_operand_t src; - cairo_gl_operand_t mask; - cairo_bool_t spans; - - cairo_clip_t *clip; - cairo_bool_t multisample; -} cairo_gl_composite_t; - -typedef struct _cairo_gl_font { - cairo_scaled_font_private_t base; - cairo_device_t *device; - cairo_list_t link; -} cairo_gl_font_t; - -static cairo_always_inline GLenum -_cairo_gl_get_error (void) -{ - GLenum err = glGetError(); - - if (unlikely (err)) - while (glGetError ()); - - return err; -} - -static inline cairo_device_t * -_cairo_gl_context_create_in_error (cairo_status_t status) -{ - return (cairo_device_t *) _cairo_device_create_in_error (status); -} - -cairo_private cairo_status_t -_cairo_gl_context_init (cairo_gl_context_t *ctx); - -cairo_private void -_cairo_gl_surface_init (cairo_device_t *device, - cairo_gl_surface_t *surface, - cairo_content_t content, - int width, int height); - -static cairo_always_inline cairo_bool_t cairo_warn -_cairo_gl_surface_is_texture (cairo_gl_surface_t *surface) -{ - return surface->tex != 0; -} - -cairo_private cairo_status_t -_cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, - cairo_image_surface_t *src, - int src_x, int src_y, - int width, int height, - int dst_x, int dst_y, - cairo_bool_t force_flush); - -cairo_private cairo_int_status_t -_cairo_gl_surface_resolve_multisampling (cairo_gl_surface_t *surface); - -static cairo_always_inline cairo_bool_t -_cairo_gl_device_has_glsl (cairo_device_t *device) -{ - return ((cairo_gl_context_t *) device)->has_shader_support; -} - -static cairo_always_inline cairo_bool_t -_cairo_gl_device_requires_power_of_two_textures (cairo_device_t *device) -{ - return ((cairo_gl_context_t *) device)->tex_target == GL_TEXTURE_RECTANGLE; -} - -static cairo_always_inline cairo_status_t cairo_warn -_cairo_gl_context_acquire (cairo_device_t *device, - cairo_gl_context_t **ctx) -{ - cairo_status_t status; - - status = cairo_device_acquire (device); - if (unlikely (status)) - return status; - - /* clear potential previous GL errors */ - _cairo_gl_get_error (); - - *ctx = (cairo_gl_context_t *) device; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_always_inline cairo_warn cairo_status_t -_cairo_gl_context_release (cairo_gl_context_t *ctx, cairo_status_t status) -{ - GLenum err; - - err = _cairo_gl_get_error (); - - if (unlikely (err)) { - cairo_status_t new_status; - new_status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - if (status == CAIRO_STATUS_SUCCESS) - status = new_status; - } - - cairo_device_release (&(ctx)->base); - - return status; -} - -cairo_private void -_cairo_gl_context_set_destination (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface, - cairo_bool_t multisampling); - -cairo_private void -_cairo_gl_context_bind_framebuffer (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface, - cairo_bool_t multisampling); - -cairo_private cairo_gl_emit_rect_t -_cairo_gl_context_choose_emit_rect (cairo_gl_context_t *ctx); - -cairo_private void -_cairo_gl_context_emit_rect (cairo_gl_context_t *ctx, - GLfloat x1, GLfloat y1, - GLfloat x2, GLfloat y2); - -cairo_private cairo_gl_emit_span_t -_cairo_gl_context_choose_emit_span (cairo_gl_context_t *ctx); - -cairo_private cairo_gl_emit_glyph_t -_cairo_gl_context_choose_emit_glyph (cairo_gl_context_t *ctx); - -cairo_private void -_cairo_gl_context_activate (cairo_gl_context_t *ctx, - cairo_gl_tex_t tex_unit); - -cairo_private cairo_bool_t -_cairo_gl_operator_is_supported (cairo_operator_t op); - -cairo_private cairo_bool_t -_cairo_gl_ensure_stencil (cairo_gl_context_t *ctx, - cairo_gl_surface_t *surface); - -cairo_private cairo_status_t -_cairo_gl_composite_init (cairo_gl_composite_t *setup, - cairo_operator_t op, - cairo_gl_surface_t *dst, - cairo_bool_t has_component_alpha); - -cairo_private void -_cairo_gl_composite_fini (cairo_gl_composite_t *setup); - -cairo_private cairo_status_t -_cairo_gl_composite_set_operator (cairo_gl_composite_t *setup, - cairo_operator_t op, - cairo_bool_t assume_component_alpha); - -cairo_private void -_cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup, - cairo_region_t *clip_region); - -cairo_private void -_cairo_gl_composite_set_clip(cairo_gl_composite_t *setup, - cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_gl_composite_set_source (cairo_gl_composite_t *setup, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen); - -cairo_private void -_cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup, - const cairo_color_t *color); - -cairo_private void -_cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup, - const cairo_gl_operand_t *source); - -cairo_private cairo_int_status_t -_cairo_gl_composite_set_mask (cairo_gl_composite_t *setup, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen); - -cairo_private void -_cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup, - const cairo_gl_operand_t *mask); - -cairo_private void -_cairo_gl_composite_set_spans (cairo_gl_composite_t *setup); - -cairo_private void -_cairo_gl_composite_set_multisample (cairo_gl_composite_t *setup); - -cairo_private cairo_status_t -_cairo_gl_composite_begin (cairo_gl_composite_t *setup, - cairo_gl_context_t **ctx); - -cairo_private cairo_status_t -_cairo_gl_set_operands_and_operator (cairo_gl_composite_t *setup, - cairo_gl_context_t *ctx); - -cairo_private void -_cairo_gl_composite_flush (cairo_gl_context_t *ctx); - -cairo_private cairo_int_status_t -_cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - const cairo_point_t quad[4]); - -cairo_private cairo_int_status_t -_cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - const cairo_point_t triangle[3]); - -cairo_private void -_cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx, - cairo_gl_tex_t tex_unit); - -cairo_private cairo_bool_t -_cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor, - pixman_format_code_t pixman_format, - GLenum *internal_format, GLenum *format, - GLenum *type, cairo_bool_t *has_alpha, - cairo_bool_t *needs_swap); - -cairo_private void -_cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache); - -cairo_private void -_cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx, - cairo_gl_glyph_cache_t *cache); - -cairo_private cairo_int_status_t -_cairo_gl_surface_show_glyphs (void *abstract_dst, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip, - int *remaining_glyphs); - -cairo_private cairo_status_t -_cairo_gl_context_init_shaders (cairo_gl_context_t *ctx); - -cairo_private void -_cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx); - -static cairo_always_inline cairo_bool_t -_cairo_gl_context_is_flushed (cairo_gl_context_t *ctx) -{ - return ctx->vb_offset == 0; -} - -cairo_private cairo_status_t -_cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx, - cairo_gl_operand_t *source, - cairo_gl_operand_t *mask, - cairo_bool_t use_coverage, - cairo_gl_shader_in_t in, - cairo_gl_shader_t **shader); - -cairo_private void -_cairo_gl_shader_bind_float (cairo_gl_context_t *ctx, - GLint location, - float value); - -cairo_private void -_cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx, - GLint location, - float value0, float value1); - -cairo_private void -_cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx, - GLint location, - float value0, - float value1, - float value2); - -cairo_private void -_cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx, - GLint location, - float value0, float value1, - float value2, float value3); - -cairo_private void -_cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx, - GLint location, - const cairo_matrix_t* m); - -cairo_private void -_cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx, - GLint location, - GLfloat* gl_m); - -cairo_private void -_cairo_gl_set_shader (cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader); - -cairo_private void -_cairo_gl_shader_fini (cairo_gl_context_t *ctx, cairo_gl_shader_t *shader); - -cairo_private int -_cairo_gl_get_version (void); - -cairo_private cairo_gl_flavor_t -_cairo_gl_get_flavor (void); - -cairo_private unsigned long -_cairo_gl_get_vbo_size (void); - -cairo_private cairo_bool_t -_cairo_gl_has_extension (const char *ext); - -cairo_private cairo_status_t -_cairo_gl_dispatch_init(cairo_gl_dispatch_t *dispatch, - cairo_gl_get_proc_addr_func_t get_proc_addr); - -cairo_private cairo_int_status_t -_cairo_gl_operand_init (cairo_gl_operand_t *operand, - const cairo_pattern_t *pattern, - cairo_gl_surface_t *dst, - const cairo_rectangle_int_t *sample, - const cairo_rectangle_int_t *extents, - cairo_bool_t use_texgen); - -cairo_private void -_cairo_gl_solid_operand_init (cairo_gl_operand_t *operand, - const cairo_color_t *color); - -cairo_private cairo_filter_t -_cairo_gl_operand_get_filter (cairo_gl_operand_t *operand); - -cairo_private GLint -_cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand); - -cairo_private cairo_extend_t -_cairo_gl_operand_get_extend (cairo_gl_operand_t *operand); - -cairo_private unsigned int -_cairo_gl_operand_get_vertex_size (const cairo_gl_operand_t *operand); - -cairo_private cairo_bool_t -_cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest, - cairo_gl_operand_t *source, - unsigned int vertex_offset); - -cairo_private void -_cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, - cairo_gl_operand_t *operand, - cairo_gl_tex_t tex_unit); - -cairo_private void -_cairo_gl_operand_emit (cairo_gl_operand_t *operand, - GLfloat ** vb, - GLfloat x, - GLfloat y); - -cairo_private void -_cairo_gl_operand_copy (cairo_gl_operand_t *dst, - const cairo_gl_operand_t *src); - -cairo_private void -_cairo_gl_operand_translate (cairo_gl_operand_t *operand, - double tx, double ty); - -cairo_private void -_cairo_gl_operand_destroy (cairo_gl_operand_t *operand); - -cairo_private const cairo_compositor_t * -_cairo_gl_msaa_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_gl_span_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_gl_traps_compositor_get (void); - -cairo_private cairo_int_status_t -_cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs); - -cairo_private cairo_int_status_t -_cairo_gl_composite_glyphs (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info); - -cairo_private cairo_int_status_t -_cairo_gl_composite_glyphs_with_clip (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info, - cairo_clip_t *clip); - -cairo_private cairo_surface_t * -_cairo_gl_surface_create_scratch (cairo_gl_context_t *ctx, - cairo_content_t content, - int width, - int height); - -cairo_private cairo_surface_t * -_cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx, - cairo_content_t content, - int width, - int height); - -cairo_private cairo_surface_t * -_cairo_gl_pattern_to_source (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y); - -cairo_private cairo_int_status_t -_cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - cairo_clip_t *clip); - -cairo_private cairo_surface_t * -_cairo_gl_white_source (void); - -cairo_private void -_cairo_gl_scissor_to_rectangle (cairo_gl_surface_t *surface, - const cairo_rectangle_int_t *r); - -static inline cairo_gl_operand_t * -source_to_operand (cairo_surface_t *surface) -{ - cairo_gl_source_t *source = (cairo_gl_source_t *)surface; - return source ? &source->operand : NULL; -} - -static inline void -_cairo_gl_glyph_cache_unlock (cairo_gl_glyph_cache_t *cache) -{ - _cairo_rtree_unpin (&cache->rtree); -} - - -slim_hidden_proto (cairo_gl_surface_create); -slim_hidden_proto (cairo_gl_surface_create_for_texture); - -#endif /* CAIRO_GL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-shaders.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-shaders.c deleted file mode 100644 index 27106066650..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-shaders.c +++ /dev/null @@ -1,1093 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 T. Zachary Laine - * Copyright © 2010 Eric Anholt - * Copyright © 2010 Red Hat, Inc - * Copyright © 2010 Linaro Limited - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is T. Zachary Laine. - * - * Contributor(s): - * Benjamin Otte - * Eric Anholt - * T. Zachary Laine - * Alexandros Frantzis - */ - -#include "cairoint.h" -#include "cairo-gl-private.h" -#include "cairo-error-private.h" -#include "cairo-output-stream-private.h" - -static cairo_status_t -_cairo_gl_shader_compile_and_link (cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader, - cairo_gl_var_type_t src, - cairo_gl_var_type_t mask, - cairo_bool_t use_coverage, - const char *fragment_text); - -typedef struct _cairo_shader_cache_entry { - cairo_cache_entry_t base; - - unsigned vertex; - - cairo_gl_operand_type_t src; - cairo_gl_operand_type_t mask; - cairo_gl_operand_type_t dest; - cairo_bool_t use_coverage; - - cairo_gl_shader_in_t in; - GLint src_gl_filter; - cairo_bool_t src_border_fade; - cairo_extend_t src_extend; - GLint mask_gl_filter; - cairo_bool_t mask_border_fade; - cairo_extend_t mask_extend; - - cairo_gl_context_t *ctx; /* XXX: needed to destroy the program */ - cairo_gl_shader_t shader; -} cairo_shader_cache_entry_t; - -static cairo_bool_t -_cairo_gl_shader_cache_equal_desktop (const void *key_a, const void *key_b) -{ - const cairo_shader_cache_entry_t *a = key_a; - const cairo_shader_cache_entry_t *b = key_b; - cairo_bool_t both_have_npot_repeat = - a->ctx->has_npot_repeat && b->ctx->has_npot_repeat; - - return (a->vertex == b->vertex && - a->src == b->src && - a->mask == b->mask && - a->dest == b->dest && - a->use_coverage == b->use_coverage && - a->in == b->in && - (both_have_npot_repeat || a->src_extend == b->src_extend) && - (both_have_npot_repeat || a->mask_extend == b->mask_extend)); -} - -/* - * For GLES2 we use more complicated shaders to implement missing GL - * features. In this case we need more parameters to uniquely identify - * a shader (vs _cairo_gl_shader_cache_equal_desktop()). - */ -static cairo_bool_t -_cairo_gl_shader_cache_equal_gles2 (const void *key_a, const void *key_b) -{ - const cairo_shader_cache_entry_t *a = key_a; - const cairo_shader_cache_entry_t *b = key_b; - cairo_bool_t both_have_npot_repeat = - a->ctx->has_npot_repeat && b->ctx->has_npot_repeat; - - return (a->vertex == b->vertex && - a->src == b->src && - a->mask == b->mask && - a->dest == b->dest && - a->use_coverage == b->use_coverage && - a->in == b->in && - a->src_gl_filter == b->src_gl_filter && - a->src_border_fade == b->src_border_fade && - (both_have_npot_repeat || a->src_extend == b->src_extend) && - a->mask_gl_filter == b->mask_gl_filter && - a->mask_border_fade == b->mask_border_fade && - (both_have_npot_repeat || a->mask_extend == b->mask_extend)); -} - -static unsigned long -_cairo_gl_shader_cache_hash (const cairo_shader_cache_entry_t *entry) -{ - return ((entry->src << 24) | (entry->mask << 16) | (entry->dest << 8) | (entry->in << 1) | entry->use_coverage) ^ entry->vertex; -} - -static void -_cairo_gl_shader_cache_destroy (void *data) -{ - cairo_shader_cache_entry_t *entry = data; - - _cairo_gl_shader_fini (entry->ctx, &entry->shader); - if (entry->ctx->current_shader == &entry->shader) - entry->ctx->current_shader = NULL; - free (entry); -} - -static void -_cairo_gl_shader_init (cairo_gl_shader_t *shader) -{ - shader->fragment_shader = 0; - shader->program = 0; -} - -cairo_status_t -_cairo_gl_context_init_shaders (cairo_gl_context_t *ctx) -{ - static const char *fill_fs_source = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "uniform vec4 color;\n" - "void main()\n" - "{\n" - " gl_FragColor = color;\n" - "}\n"; - cairo_status_t status; - - if (_cairo_gl_get_version () >= CAIRO_GL_VERSION_ENCODE (2, 0) || - (_cairo_gl_has_extension ("GL_ARB_shader_objects") && - _cairo_gl_has_extension ("GL_ARB_fragment_shader") && - _cairo_gl_has_extension ("GL_ARB_vertex_shader"))) { - ctx->has_shader_support = TRUE; - } else { - ctx->has_shader_support = FALSE; - fprintf (stderr, "Error: The cairo gl backend requires shader support!\n"); - return CAIRO_STATUS_DEVICE_ERROR; - } - - memset (ctx->vertex_shaders, 0, sizeof (ctx->vertex_shaders)); - - status = _cairo_cache_init (&ctx->shaders, - ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP ? - _cairo_gl_shader_cache_equal_desktop : - _cairo_gl_shader_cache_equal_gles2, - NULL, - _cairo_gl_shader_cache_destroy, - CAIRO_GL_MAX_SHADERS_PER_CONTEXT); - if (unlikely (status)) - return status; - - _cairo_gl_shader_init (&ctx->fill_rectangles_shader); - status = _cairo_gl_shader_compile_and_link (ctx, - &ctx->fill_rectangles_shader, - CAIRO_GL_VAR_NONE, - CAIRO_GL_VAR_NONE, - FALSE, - fill_fs_source); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx) -{ - int i; - - for (i = 0; i < CAIRO_GL_VAR_TYPE_MAX; i++) { - if (ctx->vertex_shaders[i]) - ctx->dispatch.DeleteShader (ctx->vertex_shaders[i]); - } - - _cairo_cache_fini (&ctx->shaders); -} - -void -_cairo_gl_shader_fini (cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader) -{ - if (shader->fragment_shader) - ctx->dispatch.DeleteShader (shader->fragment_shader); - - if (shader->program) - ctx->dispatch.DeleteProgram (shader->program); -} - -static const char *operand_names[] = { "source", "mask", "dest" }; - -static cairo_gl_var_type_t -cairo_gl_operand_get_var_type (cairo_gl_operand_t *operand) -{ - switch (operand->type) { - default: - case CAIRO_GL_OPERAND_COUNT: - ASSERT_NOT_REACHED; - case CAIRO_GL_OPERAND_NONE: - case CAIRO_GL_OPERAND_CONSTANT: - return CAIRO_GL_VAR_NONE; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - return operand->gradient.texgen ? CAIRO_GL_VAR_TEXGEN : CAIRO_GL_VAR_TEXCOORDS; - case CAIRO_GL_OPERAND_TEXTURE: - return operand->texture.texgen ? CAIRO_GL_VAR_TEXGEN : CAIRO_GL_VAR_TEXCOORDS; - } -} - -static void -cairo_gl_shader_emit_variable (cairo_output_stream_t *stream, - cairo_gl_var_type_t type, - cairo_gl_tex_t name) -{ - switch (type) { - default: - ASSERT_NOT_REACHED; - case CAIRO_GL_VAR_NONE: - break; - case CAIRO_GL_VAR_TEXCOORDS: - _cairo_output_stream_printf (stream, - "attribute vec4 MultiTexCoord%d;\n" - "varying vec2 %s_texcoords;\n", - name, - operand_names[name]); - break; - case CAIRO_GL_VAR_TEXGEN: - _cairo_output_stream_printf (stream, - "uniform mat3 %s_texgen;\n" - "varying vec2 %s_texcoords;\n", - operand_names[name], - operand_names[name]); - break; - } -} - -static void -cairo_gl_shader_emit_vertex (cairo_output_stream_t *stream, - cairo_gl_var_type_t type, - cairo_gl_tex_t name) -{ - switch (type) { - default: - ASSERT_NOT_REACHED; - case CAIRO_GL_VAR_NONE: - break; - case CAIRO_GL_VAR_TEXCOORDS: - _cairo_output_stream_printf (stream, - " %s_texcoords = MultiTexCoord%d.xy;\n", - operand_names[name], name); - break; - - case CAIRO_GL_VAR_TEXGEN: - _cairo_output_stream_printf (stream, - " %s_texcoords = (%s_texgen * Vertex.xyw).xy;\n", - operand_names[name], operand_names[name]); - break; - } -} - -static void -cairo_gl_shader_dcl_coverage (cairo_output_stream_t *stream) -{ - _cairo_output_stream_printf (stream, "varying float coverage;\n"); -} - -static void -cairo_gl_shader_def_coverage (cairo_output_stream_t *stream) -{ - _cairo_output_stream_printf (stream, " coverage = Color.a;\n"); -} - -static cairo_status_t -cairo_gl_shader_get_vertex_source (cairo_gl_var_type_t src, - cairo_gl_var_type_t mask, - cairo_bool_t use_coverage, - cairo_gl_var_type_t dest, - char **out) -{ - cairo_output_stream_t *stream = _cairo_memory_stream_create (); - unsigned char *source; - unsigned long length; - cairo_status_t status; - - cairo_gl_shader_emit_variable (stream, src, CAIRO_GL_TEX_SOURCE); - cairo_gl_shader_emit_variable (stream, mask, CAIRO_GL_TEX_MASK); - if (use_coverage) - cairo_gl_shader_dcl_coverage (stream); - - _cairo_output_stream_printf (stream, - "attribute vec4 Vertex;\n" - "attribute vec4 Color;\n" - "uniform mat4 ModelViewProjectionMatrix;\n" - "void main()\n" - "{\n" - " gl_Position = ModelViewProjectionMatrix * Vertex;\n"); - - cairo_gl_shader_emit_vertex (stream, src, CAIRO_GL_TEX_SOURCE); - cairo_gl_shader_emit_vertex (stream, mask, CAIRO_GL_TEX_MASK); - if (use_coverage) - cairo_gl_shader_def_coverage (stream); - - _cairo_output_stream_write (stream, - "}\n\0", 3); - - status = _cairo_memory_stream_destroy (stream, &source, &length); - if (unlikely (status)) - return status; - - *out = (char *) source; - return CAIRO_STATUS_SUCCESS; -} - -/* - * Returns whether an operand needs a special border fade fragment shader - * to simulate the GL_CLAMP_TO_BORDER wrapping method that is missing in GLES2. - */ -static cairo_bool_t -_cairo_gl_shader_needs_border_fade (cairo_gl_operand_t *operand) -{ - cairo_extend_t extend =_cairo_gl_operand_get_extend (operand); - - return extend == CAIRO_EXTEND_NONE && - (operand->type == CAIRO_GL_OPERAND_TEXTURE || - operand->type == CAIRO_GL_OPERAND_LINEAR_GRADIENT || - operand->type == CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE || - operand->type == CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0); -} - -static void -cairo_gl_shader_emit_color (cairo_output_stream_t *stream, - cairo_gl_context_t *ctx, - cairo_gl_operand_t *op, - cairo_gl_tex_t name) -{ - const char *namestr = operand_names[name]; - const char *rectstr = (ctx->tex_target == GL_TEXTURE_RECTANGLE ? "Rect" : ""); - - switch (op->type) { - case CAIRO_GL_OPERAND_COUNT: - default: - ASSERT_NOT_REACHED; - break; - case CAIRO_GL_OPERAND_NONE: - _cairo_output_stream_printf (stream, - "vec4 get_%s()\n" - "{\n" - " return vec4 (0, 0, 0, 1);\n" - "}\n", - namestr); - break; - case CAIRO_GL_OPERAND_CONSTANT: - _cairo_output_stream_printf (stream, - "uniform vec4 %s_constant;\n" - "vec4 get_%s()\n" - "{\n" - " return %s_constant;\n" - "}\n", - namestr, namestr, namestr); - break; - case CAIRO_GL_OPERAND_TEXTURE: - _cairo_output_stream_printf (stream, - "uniform sampler2D%s %s_sampler;\n" - "uniform vec2 %s_texdims;\n" - "varying vec2 %s_texcoords;\n" - "vec4 get_%s()\n" - "{\n", - rectstr, namestr, namestr, namestr, namestr); - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && - _cairo_gl_shader_needs_border_fade (op)) - { - _cairo_output_stream_printf (stream, - " vec2 border_fade = %s_border_fade (%s_texcoords, %s_texdims);\n" - " vec4 texel = texture2D%s (%s_sampler, %s_texcoords);\n" - " return texel * border_fade.x * border_fade.y;\n" - "}\n", - namestr, namestr, namestr, rectstr, namestr, namestr); - } - else - { - _cairo_output_stream_printf (stream, - " return texture2D%s (%s_sampler, %s_wrap (%s_texcoords));\n" - "}\n", - rectstr, namestr, namestr, namestr); - } - break; - case CAIRO_GL_OPERAND_LINEAR_GRADIENT: - _cairo_output_stream_printf (stream, - "varying vec2 %s_texcoords;\n" - "uniform vec2 %s_texdims;\n" - "uniform sampler2D%s %s_sampler;\n" - "\n" - "vec4 get_%s()\n" - "{\n", - namestr, namestr, rectstr, namestr, namestr); - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && - _cairo_gl_shader_needs_border_fade (op)) - { - _cairo_output_stream_printf (stream, - " float border_fade = %s_border_fade (%s_texcoords.x, %s_texdims.x);\n" - " vec4 texel = texture2D%s (%s_sampler, vec2 (%s_texcoords.x, 0.5));\n" - " return texel * border_fade;\n" - "}\n", - namestr, namestr, namestr, rectstr, namestr, namestr); - } - else - { - _cairo_output_stream_printf (stream, - " return texture2D%s (%s_sampler, %s_wrap (vec2 (%s_texcoords.x, 0.5)));\n" - "}\n", - rectstr, namestr, namestr, namestr); - } - break; - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: - _cairo_output_stream_printf (stream, - "varying vec2 %s_texcoords;\n" - "uniform vec2 %s_texdims;\n" - "uniform sampler2D%s %s_sampler;\n" - "uniform vec3 %s_circle_d;\n" - "uniform float %s_radius_0;\n" - "\n" - "vec4 get_%s()\n" - "{\n" - " vec3 pos = vec3 (%s_texcoords, %s_radius_0);\n" - " \n" - " float B = dot (pos, %s_circle_d);\n" - " float C = dot (pos, vec3 (pos.xy, -pos.z));\n" - " \n" - " float t = 0.5 * C / B;\n" - " float is_valid = step (-%s_radius_0, t * %s_circle_d.z);\n", - namestr, namestr, rectstr, namestr, namestr, namestr, namestr, - namestr, namestr, namestr, namestr, namestr); - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && - _cairo_gl_shader_needs_border_fade (op)) - { - _cairo_output_stream_printf (stream, - " float border_fade = %s_border_fade (t, %s_texdims.x);\n" - " vec4 texel = texture2D%s (%s_sampler, vec2 (t, 0.5));\n" - " return mix (vec4 (0.0), texel * border_fade, is_valid);\n" - "}\n", - namestr, namestr, rectstr, namestr); - } - else - { - _cairo_output_stream_printf (stream, - " vec4 texel = texture2D%s (%s_sampler, %s_wrap (vec2 (t, 0.5)));\n" - " return mix (vec4 (0.0), texel, is_valid);\n" - "}\n", - rectstr, namestr, namestr); - } - break; - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: - _cairo_output_stream_printf (stream, - "varying vec2 %s_texcoords;\n" - "uniform vec2 %s_texdims;\n" - "uniform sampler2D%s %s_sampler;\n" - "uniform vec3 %s_circle_d;\n" - "uniform float %s_a;\n" - "uniform float %s_radius_0;\n" - "\n" - "vec4 get_%s()\n" - "{\n" - " vec3 pos = vec3 (%s_texcoords, %s_radius_0);\n" - " \n" - " float B = dot (pos, %s_circle_d);\n" - " float C = dot (pos, vec3 (pos.xy, -pos.z));\n" - " \n" - " float det = dot (vec2 (B, %s_a), vec2 (B, -C));\n" - " float sqrtdet = sqrt (abs (det));\n" - " vec2 t = (B + vec2 (sqrtdet, -sqrtdet)) / %s_a;\n" - " \n" - " vec2 is_valid = step (vec2 (0.0), t) * step (t, vec2(1.0));\n" - " float has_color = step (0., det) * max (is_valid.x, is_valid.y);\n" - " \n" - " float upper_t = mix (t.y, t.x, is_valid.x);\n", - namestr, namestr, rectstr, namestr, namestr, namestr, namestr, - namestr, namestr, namestr, namestr, namestr, namestr); - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && - _cairo_gl_shader_needs_border_fade (op)) - { - _cairo_output_stream_printf (stream, - " float border_fade = %s_border_fade (upper_t, %s_texdims.x);\n" - " vec4 texel = texture2D%s (%s_sampler, vec2 (upper_t, 0.5));\n" - " return mix (vec4 (0.0), texel * border_fade, has_color);\n" - "}\n", - namestr, namestr, rectstr, namestr); - } - else - { - _cairo_output_stream_printf (stream, - " vec4 texel = texture2D%s (%s_sampler, %s_wrap (vec2(upper_t, 0.5)));\n" - " return mix (vec4 (0.0), texel, has_color);\n" - "}\n", - rectstr, namestr, namestr); - } - break; - case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: - _cairo_output_stream_printf (stream, - "varying vec2 %s_texcoords;\n" - "uniform sampler2D%s %s_sampler;\n" - "uniform vec3 %s_circle_d;\n" - "uniform float %s_a;\n" - "uniform float %s_radius_0;\n" - "\n" - "vec4 get_%s()\n" - "{\n" - " vec3 pos = vec3 (%s_texcoords, %s_radius_0);\n" - " \n" - " float B = dot (pos, %s_circle_d);\n" - " float C = dot (pos, vec3 (pos.xy, -pos.z));\n" - " \n" - " float det = dot (vec2 (B, %s_a), vec2 (B, -C));\n" - " float sqrtdet = sqrt (abs (det));\n" - " vec2 t = (B + vec2 (sqrtdet, -sqrtdet)) / %s_a;\n" - " \n" - " vec2 is_valid = step (vec2 (-%s_radius_0), t * %s_circle_d.z);\n" - " float has_color = step (0., det) * max (is_valid.x, is_valid.y);\n" - " \n" - " float upper_t = mix (t.y, t.x, is_valid.x);\n" - " vec4 texel = texture2D%s (%s_sampler, %s_wrap (vec2(upper_t, 0.5)));\n" - " return mix (vec4 (0.0), texel, has_color);\n" - "}\n", - namestr, rectstr, namestr, namestr, namestr, namestr, - namestr, namestr, namestr, namestr, namestr, - namestr, namestr, namestr, rectstr, namestr, namestr); - break; - } -} - -/* - * Emits the border fade functions used by an operand. - * - * If bilinear filtering is used, the emitted function performs a linear - * fade to transparency effect in the intervals [-1/2n, 1/2n] and - * [1 - 1/2n, 1 + 1/2n] (n: texture size). - * - * If nearest filtering is used, the emitted function just returns - * 0.0 for all values outside [0, 1). - */ -static void -_cairo_gl_shader_emit_border_fade (cairo_output_stream_t *stream, - cairo_gl_operand_t *operand, - cairo_gl_tex_t name) -{ - const char *namestr = operand_names[name]; - GLint gl_filter = _cairo_gl_operand_get_gl_filter (operand); - - /* 2D version */ - _cairo_output_stream_printf (stream, - "vec2 %s_border_fade (vec2 coords, vec2 dims)\n" - "{\n", - namestr); - - if (gl_filter == GL_LINEAR) - _cairo_output_stream_printf (stream, - " return clamp(-abs(dims * (coords - 0.5)) + (dims + vec2(1.0)) * 0.5, 0.0, 1.0);\n"); - else - _cairo_output_stream_printf (stream, - " bvec2 in_tex1 = greaterThanEqual (coords, vec2 (0.0));\n" - " bvec2 in_tex2 = lessThan (coords, vec2 (1.0));\n" - " return vec2 (float (all (in_tex1) && all (in_tex2)));\n"); - - _cairo_output_stream_printf (stream, "}\n"); - - /* 1D version */ - _cairo_output_stream_printf (stream, - "float %s_border_fade (float x, float dim)\n" - "{\n", - namestr); - if (gl_filter == GL_LINEAR) - _cairo_output_stream_printf (stream, - " return clamp(-abs(dim * (x - 0.5)) + (dim + 1.0) * 0.5, 0.0, 1.0);\n"); - else - _cairo_output_stream_printf (stream, - " bool in_tex = x >= 0.0 && x < 1.0;\n" - " return float (in_tex);\n"); - - _cairo_output_stream_printf (stream, "}\n"); -} - -/* - * Emits the wrap function used by an operand. - * - * In OpenGL ES 2.0, repeat wrap modes (GL_REPEAT and GL_MIRRORED REPEAT) are - * only available for NPOT textures if the GL_OES_texture_npot is supported. - * If GL_OES_texture_npot is not supported, we need to implement the wrapping - * functionality in the shader. - */ -static void -_cairo_gl_shader_emit_wrap (cairo_gl_context_t *ctx, - cairo_output_stream_t *stream, - cairo_gl_operand_t *operand, - cairo_gl_tex_t name) -{ - const char *namestr = operand_names[name]; - cairo_extend_t extend = _cairo_gl_operand_get_extend (operand); - - _cairo_output_stream_printf (stream, - "vec2 %s_wrap(vec2 coords)\n" - "{\n", - namestr); - - if (! ctx->has_npot_repeat && - (extend == CAIRO_EXTEND_REPEAT || extend == CAIRO_EXTEND_REFLECT)) - { - if (extend == CAIRO_EXTEND_REPEAT) { - _cairo_output_stream_printf (stream, - " return fract(coords);\n"); - } else { /* CAIRO_EXTEND_REFLECT */ - _cairo_output_stream_printf (stream, - " return mix(fract(coords), 1.0 - fract(coords), floor(mod(coords, 2.0)));\n"); - } - } - else - { - _cairo_output_stream_printf (stream, " return coords;\n"); - } - - _cairo_output_stream_printf (stream, "}\n"); -} - -static cairo_status_t -cairo_gl_shader_get_fragment_source (cairo_gl_context_t *ctx, - cairo_gl_shader_in_t in, - cairo_gl_operand_t *src, - cairo_gl_operand_t *mask, - cairo_bool_t use_coverage, - cairo_gl_operand_type_t dest_type, - char **out) -{ - cairo_output_stream_t *stream = _cairo_memory_stream_create (); - unsigned char *source; - unsigned long length; - cairo_status_t status; - const char *coverage_str; - - _cairo_output_stream_printf (stream, - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n"); - - _cairo_gl_shader_emit_wrap (ctx, stream, src, CAIRO_GL_TEX_SOURCE); - _cairo_gl_shader_emit_wrap (ctx, stream, mask, CAIRO_GL_TEX_MASK); - - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { - if (_cairo_gl_shader_needs_border_fade (src)) - _cairo_gl_shader_emit_border_fade (stream, src, CAIRO_GL_TEX_SOURCE); - if (_cairo_gl_shader_needs_border_fade (mask)) - _cairo_gl_shader_emit_border_fade (stream, mask, CAIRO_GL_TEX_MASK); - } - - cairo_gl_shader_emit_color (stream, ctx, src, CAIRO_GL_TEX_SOURCE); - cairo_gl_shader_emit_color (stream, ctx, mask, CAIRO_GL_TEX_MASK); - - coverage_str = ""; - if (use_coverage) { - _cairo_output_stream_printf (stream, "varying float coverage;\n"); - coverage_str = " * coverage"; - } - - _cairo_output_stream_printf (stream, - "void main()\n" - "{\n"); - switch (in) { - case CAIRO_GL_SHADER_IN_COUNT: - default: - ASSERT_NOT_REACHED; - case CAIRO_GL_SHADER_IN_NORMAL: - _cairo_output_stream_printf (stream, - " gl_FragColor = get_source() * get_mask().a%s;\n", - coverage_str); - break; - case CAIRO_GL_SHADER_IN_CA_SOURCE: - _cairo_output_stream_printf (stream, - " gl_FragColor = get_source() * get_mask()%s;\n", - coverage_str); - break; - case CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA: - _cairo_output_stream_printf (stream, - " gl_FragColor = get_source().a * get_mask()%s;\n", - coverage_str); - break; - } - - _cairo_output_stream_write (stream, - "}\n\0", 3); - - status = _cairo_memory_stream_destroy (stream, &source, &length); - if (unlikely (status)) - return status; - - *out = (char *) source; - return CAIRO_STATUS_SUCCESS; -} - -static void -compile_shader (cairo_gl_context_t *ctx, - GLuint *shader, - GLenum type, - const char *source) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - GLint success, log_size, num_chars; - char *log; - - *shader = dispatch->CreateShader (type); - dispatch->ShaderSource (*shader, 1, &source, 0); - dispatch->CompileShader (*shader); - dispatch->GetShaderiv (*shader, GL_COMPILE_STATUS, &success); - - if (success) - return; - - dispatch->GetShaderiv (*shader, GL_INFO_LOG_LENGTH, &log_size); - if (log_size < 0) { - printf ("OpenGL shader compilation failed.\n"); - ASSERT_NOT_REACHED; - return; - } - - log = _cairo_malloc (log_size + 1); - dispatch->GetShaderInfoLog (*shader, log_size, &num_chars, log); - log[num_chars] = '\0'; - - printf ("OpenGL shader compilation failed. Shader:\n%s\n", source); - printf ("OpenGL compilation log:\n%s\n", log); - - free (log); - ASSERT_NOT_REACHED; -} - -static void -link_shader_program (cairo_gl_context_t *ctx, - GLuint *program, - GLuint vert, - GLuint frag) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - GLint success, log_size, num_chars; - char *log; - - *program = dispatch->CreateProgram (); - dispatch->AttachShader (*program, vert); - dispatch->AttachShader (*program, frag); - - dispatch->BindAttribLocation (*program, CAIRO_GL_VERTEX_ATTRIB_INDEX, - "Vertex"); - dispatch->BindAttribLocation (*program, CAIRO_GL_COLOR_ATTRIB_INDEX, - "Color"); - dispatch->BindAttribLocation (*program, CAIRO_GL_TEXCOORD0_ATTRIB_INDEX, - "MultiTexCoord0"); - dispatch->BindAttribLocation (*program, CAIRO_GL_TEXCOORD1_ATTRIB_INDEX, - "MultiTexCoord1"); - - dispatch->LinkProgram (*program); - dispatch->GetProgramiv (*program, GL_LINK_STATUS, &success); - if (success) - return; - - dispatch->GetProgramiv (*program, GL_INFO_LOG_LENGTH, &log_size); - if (log_size < 0) { - printf ("OpenGL shader link failed.\n"); - ASSERT_NOT_REACHED; - return; - } - - log = _cairo_malloc (log_size + 1); - dispatch->GetProgramInfoLog (*program, log_size, &num_chars, log); - log[num_chars] = '\0'; - - printf ("OpenGL shader link failed:\n%s\n", log); - free (log); - ASSERT_NOT_REACHED; -} - -static GLint -_cairo_gl_get_op_uniform_location(cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader, - cairo_gl_tex_t tex_unit, - const char *suffix) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - char uniform_name[100]; - const char *unit_name[2] = { "source", "mask" }; - - snprintf (uniform_name, sizeof (uniform_name), "%s_%s", - unit_name[tex_unit], suffix); - - return dispatch->GetUniformLocation (shader->program, uniform_name); -} - -static cairo_status_t -_cairo_gl_shader_compile_and_link (cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader, - cairo_gl_var_type_t src, - cairo_gl_var_type_t mask, - cairo_bool_t use_coverage, - const char *fragment_text) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - unsigned int vertex_shader; - cairo_status_t status; - int i; - - assert (shader->program == 0); - - vertex_shader = cairo_gl_var_type_hash (src, mask, use_coverage, - CAIRO_GL_VAR_NONE); - if (ctx->vertex_shaders[vertex_shader] == 0) { - char *source; - - status = cairo_gl_shader_get_vertex_source (src, - mask, - use_coverage, - CAIRO_GL_VAR_NONE, - &source); - if (unlikely (status)) - goto FAILURE; - - compile_shader (ctx, &ctx->vertex_shaders[vertex_shader], - GL_VERTEX_SHADER, source); - free (source); - } - - compile_shader (ctx, &shader->fragment_shader, - GL_FRAGMENT_SHADER, fragment_text); - - link_shader_program (ctx, &shader->program, - ctx->vertex_shaders[vertex_shader], - shader->fragment_shader); - - shader->mvp_location = - dispatch->GetUniformLocation (shader->program, - "ModelViewProjectionMatrix"); - - for (i = 0; i < 2; i++) { - shader->constant_location[i] = - _cairo_gl_get_op_uniform_location (ctx, shader, i, "constant"); - shader->a_location[i] = - _cairo_gl_get_op_uniform_location (ctx, shader, i, "a"); - shader->circle_d_location[i] = - _cairo_gl_get_op_uniform_location (ctx, shader, i, "circle_d"); - shader->radius_0_location[i] = - _cairo_gl_get_op_uniform_location (ctx, shader, i, "radius_0"); - shader->texdims_location[i] = - _cairo_gl_get_op_uniform_location (ctx, shader, i, "texdims"); - shader->texgen_location[i] = - _cairo_gl_get_op_uniform_location (ctx, shader, i, "texgen"); - } - - return CAIRO_STATUS_SUCCESS; - - FAILURE: - _cairo_gl_shader_fini (ctx, shader); - shader->fragment_shader = 0; - shader->program = 0; - - return status; -} - -/* We always bind the source to texture unit 0 if present, and mask to - * texture unit 1 if present, so we can just initialize these once at - * compile time. - */ -static void -_cairo_gl_shader_set_samplers (cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - GLint location; - GLint saved_program; - - /* We have to save/restore the current program because we might be - * asked for a different program while a shader is bound. This shouldn't - * be a performance issue, since this is only called once per compile. - */ - glGetIntegerv (GL_CURRENT_PROGRAM, &saved_program); - dispatch->UseProgram (shader->program); - - location = dispatch->GetUniformLocation (shader->program, "source_sampler"); - if (location != -1) { - dispatch->Uniform1i (location, CAIRO_GL_TEX_SOURCE); - } - - location = dispatch->GetUniformLocation (shader->program, "mask_sampler"); - if (location != -1) { - dispatch->Uniform1i (location, CAIRO_GL_TEX_MASK); - } - - dispatch->UseProgram (saved_program); -} - -void -_cairo_gl_shader_bind_float (cairo_gl_context_t *ctx, - GLint location, - float value) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - assert (location != -1); - dispatch->Uniform1f (location, value); -} - -void -_cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx, - GLint location, - float value0, - float value1) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - assert (location != -1); - dispatch->Uniform2f (location, value0, value1); -} - -void -_cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx, - GLint location, - float value0, - float value1, - float value2) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - assert (location != -1); - dispatch->Uniform3f (location, value0, value1, value2); -} - -void -_cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx, - GLint location, - float value0, float value1, - float value2, float value3) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - assert (location != -1); - dispatch->Uniform4f (location, value0, value1, value2, value3); -} - -void -_cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx, - GLint location, - const cairo_matrix_t* m) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - float gl_m[9] = { - m->xx, m->xy, m->x0, - m->yx, m->yy, m->y0, - 0, 0, 1 - }; - assert (location != -1); - dispatch->UniformMatrix3fv (location, 1, GL_TRUE, gl_m); -} - -void -_cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx, - GLint location, GLfloat* gl_m) -{ - cairo_gl_dispatch_t *dispatch = &ctx->dispatch; - assert (location != -1); - dispatch->UniformMatrix4fv (location, 1, GL_FALSE, gl_m); -} - -void -_cairo_gl_set_shader (cairo_gl_context_t *ctx, - cairo_gl_shader_t *shader) -{ - if (ctx->current_shader == shader) - return; - - if (shader) - ctx->dispatch.UseProgram (shader->program); - else - ctx->dispatch.UseProgram (0); - - ctx->current_shader = shader; -} - -cairo_status_t -_cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx, - cairo_gl_operand_t *source, - cairo_gl_operand_t *mask, - cairo_bool_t use_coverage, - cairo_gl_shader_in_t in, - cairo_gl_shader_t **shader) -{ - cairo_shader_cache_entry_t lookup, *entry; - char *fs_source; - cairo_status_t status; - - lookup.ctx = ctx; - - lookup.vertex = cairo_gl_var_type_hash (cairo_gl_operand_get_var_type (source), - cairo_gl_operand_get_var_type (mask), - use_coverage, - CAIRO_GL_VAR_NONE); - - lookup.src = source->type; - lookup.mask = mask->type; - lookup.dest = CAIRO_GL_OPERAND_NONE; - lookup.use_coverage = use_coverage; - lookup.in = in; - lookup.src_gl_filter = _cairo_gl_operand_get_gl_filter (source); - lookup.src_border_fade = _cairo_gl_shader_needs_border_fade (source); - lookup.src_extend = _cairo_gl_operand_get_extend (source); - lookup.mask_gl_filter = _cairo_gl_operand_get_gl_filter (mask); - lookup.mask_border_fade = _cairo_gl_shader_needs_border_fade (mask); - lookup.mask_extend = _cairo_gl_operand_get_extend (mask); - lookup.base.hash = _cairo_gl_shader_cache_hash (&lookup); - lookup.base.size = 1; - - entry = _cairo_cache_lookup (&ctx->shaders, &lookup.base); - if (entry) { - assert (entry->shader.program); - *shader = &entry->shader; - return CAIRO_STATUS_SUCCESS; - } - - status = cairo_gl_shader_get_fragment_source (ctx, - in, - source, - mask, - use_coverage, - CAIRO_GL_OPERAND_NONE, - &fs_source); - if (unlikely (status)) - return status; - - entry = malloc (sizeof (cairo_shader_cache_entry_t)); - if (unlikely (entry == NULL)) { - free (fs_source); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - memcpy (entry, &lookup, sizeof (cairo_shader_cache_entry_t)); - - entry->ctx = ctx; - _cairo_gl_shader_init (&entry->shader); - status = _cairo_gl_shader_compile_and_link (ctx, - &entry->shader, - cairo_gl_operand_get_var_type (source), - cairo_gl_operand_get_var_type (mask), - use_coverage, - fs_source); - free (fs_source); - - if (unlikely (status)) { - free (entry); - return status; - } - - _cairo_gl_shader_set_samplers (ctx, &entry->shader); - - status = _cairo_cache_insert (&ctx->shaders, &entry->base); - if (unlikely (status)) { - _cairo_gl_shader_fini (ctx, &entry->shader); - free (entry); - return status; - } - - *shader = &entry->shader; - - return CAIRO_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-source.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-source.c deleted file mode 100644 index 12235295f40..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-source.c +++ /dev/null @@ -1,111 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-surface-backend-private.h" - -static cairo_status_t -_cairo_gl_source_finish (void *abstract_surface) -{ - cairo_gl_source_t *source = abstract_surface; - - _cairo_gl_operand_destroy (&source->operand); - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t cairo_gl_source_backend = { - CAIRO_SURFACE_TYPE_GL, - _cairo_gl_source_finish, - NULL, /* read-only wrapper */ -}; - -cairo_surface_t * -_cairo_gl_pattern_to_source (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_gl_source_t *source; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (pattern == NULL) - return _cairo_gl_white_source (); - - source = malloc (sizeof (*source)); - if (unlikely (source == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&source->base, - &cairo_gl_source_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - *src_x = *src_y = 0; - status = _cairo_gl_operand_init (&source->operand, pattern, - (cairo_gl_surface_t *)dst, - sample, extents, - FALSE); - if (unlikely (status)) { - cairo_surface_destroy (&source->base); - return _cairo_surface_create_in_error (status); - } - - return &source->base; -} - -cairo_surface_t * -_cairo_gl_white_source (void) -{ - cairo_gl_source_t *source; - - source = malloc (sizeof (*source)); - if (unlikely (source == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&source->base, - &cairo_gl_source_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - _cairo_gl_solid_operand_init (&source->operand, CAIRO_COLOR_WHITE); - - return &source->base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-spans-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-spans-compositor.c deleted file mode 100644 index 4317ccd074a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-spans-compositor.c +++ /dev/null @@ -1,553 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-spans-compositor-private.h" -#include "cairo-surface-backend-private.h" - -typedef struct _cairo_gl_span_renderer { - cairo_span_renderer_t base; - - cairo_gl_composite_t setup; - double opacity; - - cairo_gl_emit_span_t emit; - - int xmin, xmax; - int ymin, ymax; - - cairo_gl_context_t *ctx; -} cairo_gl_span_renderer_t; - -static cairo_status_t -_cairo_gl_bounded_opaque_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_gl_span_renderer_t *r = abstract_renderer; - cairo_gl_emit_span_t emit = r->emit; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - do { - if (spans[0].coverage) { - emit (r->ctx, - spans[0].x, y, - spans[1].x, y + height, - spans[0].coverage); - } - - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_bounded_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_gl_span_renderer_t *r = abstract_renderer; - cairo_gl_emit_span_t emit = r->emit; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - do { - if (spans[0].coverage) { - emit (r->ctx, - spans[0].x, y, - spans[1].x, y + height, - r->opacity * spans[0].coverage); - } - - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_unbounded_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_gl_span_renderer_t *r = abstract_renderer; - cairo_gl_emit_span_t emit = r->emit; - - if (y > r->ymin) { - emit (r->ctx, - r->xmin, r->ymin, - r->xmax, y, - 0); - } - - if (num_spans == 0) { - emit (r->ctx, - r->xmin, y, - r->xmax, y + height, - 0); - } else { - if (spans[0].x != r->xmin) { - emit (r->ctx, - r->xmin, y, - spans[0].x, y + height, - 0); - } - - do { - emit (r->ctx, - spans[0].x, y, - spans[1].x, y + height, - r->opacity * spans[0].coverage); - spans++; - } while (--num_spans > 1); - - if (spans[0].x != r->xmax) { - emit (r->ctx, - spans[0].x, y, - r->xmax, y + height, - 0); - } - } - - r->ymin = y + height; - return CAIRO_STATUS_SUCCESS; -} - -/* XXX */ -static cairo_status_t -_cairo_gl_clipped_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_gl_span_renderer_t *r = abstract_renderer; - cairo_gl_emit_span_t emit = r->emit; - - if (y > r->ymin) { - emit (r->ctx, - r->xmin, r->ymin, - r->xmax, y, - 0); - } - - if (num_spans == 0) { - emit (r->ctx, - r->xmin, y, - r->xmax, y + height, - 0); - } else { - if (spans[0].x != r->xmin) { - emit (r->ctx, - r->xmin, y, - spans[0].x, y + height, - 0); - } - - do { - emit (r->ctx, - spans[0].x, y, - spans[1].x, y + height, - r->opacity * spans[0].coverage); - spans++; - } while (--num_spans > 1); - - if (spans[0].x != r->xmax) { - emit (r->ctx, - spans[0].x, y, - r->xmax, y + height, - 0); - } - } - - r->ymin = y + height; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gl_finish_unbounded_spans (void *abstract_renderer) -{ - cairo_gl_span_renderer_t *r = abstract_renderer; - cairo_gl_emit_span_t emit = r->emit; - - if (r->ymax > r->ymin) { - emit (r->ctx, - r->xmin, r->ymin, - r->xmax, r->ymax, - 0); - } - - return _cairo_gl_context_release (r->ctx, CAIRO_STATUS_SUCCESS); -} - -static cairo_status_t -_cairo_gl_finish_bounded_spans (void *abstract_renderer) -{ - cairo_gl_span_renderer_t *r = abstract_renderer; - - return _cairo_gl_context_release (r->ctx, CAIRO_STATUS_SUCCESS); -} - -static void -emit_aligned_boxes (cairo_gl_context_t *ctx, - const cairo_boxes_t *boxes) -{ - const struct _cairo_boxes_chunk *chunk; - cairo_gl_emit_rect_t emit = _cairo_gl_context_choose_emit_rect (ctx); - int i; - - TRACE ((stderr, "%s: num_boxes=%d\n", __FUNCTION__, boxes->num_boxes)); - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - emit (ctx, x1, y1, x2, y2); - } - } -} - -static cairo_int_status_t -fill_boxes (void *_dst, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_solid_source (&setup, color); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - emit_aligned_boxes (ctx, boxes); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_int_status_t -draw_image_boxes (void *_dst, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy) -{ - cairo_gl_surface_t *dst = _dst; - struct _cairo_boxes_chunk *chunk; - int i; - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - int x = _cairo_fixed_integer_part (b->p1.x); - int y = _cairo_fixed_integer_part (b->p1.y); - int w = _cairo_fixed_integer_part (b->p2.x) - x; - int h = _cairo_fixed_integer_part (b->p2.y) - y; - cairo_status_t status; - - status = _cairo_gl_surface_draw_image (dst, image, - x + dx, y + dy, - w, h, - x, y, TRUE); - if (unlikely (status)) - return status; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t copy_boxes (void *_dst, - cairo_surface_t *_src, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents, - int dx, int dy) -{ - cairo_gl_surface_t *dst = _dst; - cairo_gl_surface_t *src = (cairo_gl_surface_t *)_src; - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (! _cairo_gl_surface_is_texture (src)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (src->base.device != dst->base.device) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_gl_composite_init (&setup, CAIRO_OPERATOR_SOURCE, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_source_operand (&setup, &src->operand); - _cairo_gl_operand_translate (&setup.src, -dx, -dy); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - emit_aligned_boxes (ctx, boxes); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_int_status_t -composite_boxes (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - cairo_gl_operand_t tmp_operand; - cairo_gl_operand_t *src_operand; - - TRACE ((stderr, "%s mask=(%d,%d), dst=(%d, %d)\n", __FUNCTION__, - mask_x, mask_y, dst_x, dst_y)); - - if (abstract_mask) { - if (op == CAIRO_OPERATOR_CLEAR) { - _cairo_gl_solid_operand_init (&tmp_operand, CAIRO_COLOR_WHITE); - src_operand = &tmp_operand; - op = CAIRO_OPERATOR_DEST_OUT; - } else if (op == CAIRO_OPERATOR_SOURCE) { - /* requires a LERP in the shader between dest and source */ - return CAIRO_INT_STATUS_UNSUPPORTED; - } else - src_operand = source_to_operand (abstract_src); - } else - src_operand = source_to_operand (abstract_src); - - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_source_operand (&setup, - src_operand); - _cairo_gl_operand_translate (&setup.src, -src_x, -src_y); - - _cairo_gl_composite_set_mask_operand (&setup, - source_to_operand (abstract_mask)); - _cairo_gl_operand_translate (&setup.mask, -mask_x, -mask_y); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - emit_aligned_boxes (ctx, boxes); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - if (src_operand == &tmp_operand) - _cairo_gl_operand_destroy (&tmp_operand); - return status; -} - -static cairo_int_status_t -_cairo_gl_span_renderer_init (cairo_abstract_span_renderer_t *_r, - const cairo_composite_rectangles_t *composite, - cairo_antialias_t antialias, - cairo_bool_t needs_clip) -{ - cairo_gl_span_renderer_t *r = (cairo_gl_span_renderer_t *)_r; - const cairo_pattern_t *source = &composite->source_pattern.base; - cairo_operator_t op = composite->op; - cairo_int_status_t status; - - if (op == CAIRO_OPERATOR_SOURCE) { - if (! _cairo_pattern_is_opaque (&composite->source_pattern.base, - &composite->source_sample_area)) - return CAIRO_INT_STATUS_UNSUPPORTED; - op = CAIRO_OPERATOR_OVER; - } - - /* XXX earlier! */ - if (op == CAIRO_OPERATOR_CLEAR) { - source = &_cairo_pattern_white.base; - op = CAIRO_OPERATOR_DEST_OUT; - } else if (composite->surface->is_clear && - (op == CAIRO_OPERATOR_SOURCE || - op == CAIRO_OPERATOR_OVER || - op == CAIRO_OPERATOR_ADD)) { - op = CAIRO_OPERATOR_SOURCE; - } else if (op == CAIRO_OPERATOR_SOURCE) { - /* no lerp equivalent without some major PITA */ - return CAIRO_INT_STATUS_UNSUPPORTED; - } else if (! _cairo_gl_operator_is_supported (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_gl_composite_init (&r->setup, - op, (cairo_gl_surface_t *)composite->surface, - FALSE); - if (unlikely (status)) - goto FAIL; - - status = _cairo_gl_composite_set_source (&r->setup, source, - &composite->source_sample_area, - &composite->unbounded, - TRUE); - if (unlikely (status)) - goto FAIL; - - r->opacity = 1.0; - if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { - r->opacity = composite->mask_pattern.solid.color.alpha; - } else { - status = _cairo_gl_composite_set_mask (&r->setup, - &composite->mask_pattern.base, - &composite->mask_sample_area, - &composite->unbounded, - TRUE); - if (unlikely (status)) - goto FAIL; - } - - _cairo_gl_composite_set_spans (&r->setup); - - status = _cairo_gl_composite_begin (&r->setup, &r->ctx); - if (unlikely (status)) - goto FAIL; - - r->emit = _cairo_gl_context_choose_emit_span (r->ctx); - if (composite->is_bounded) { - if (r->opacity == 1.) - r->base.render_rows = _cairo_gl_bounded_opaque_spans; - else - r->base.render_rows = _cairo_gl_bounded_spans; - r->base.finish = _cairo_gl_finish_bounded_spans; - } else { - if (needs_clip) - r->base.render_rows = _cairo_gl_clipped_spans; - else - r->base.render_rows = _cairo_gl_unbounded_spans; - r->base.finish = _cairo_gl_finish_unbounded_spans; - r->xmin = composite->unbounded.x; - r->xmax = composite->unbounded.x + composite->unbounded.width; - r->ymin = composite->unbounded.y; - r->ymax = composite->unbounded.y + composite->unbounded.height; - } - - return CAIRO_STATUS_SUCCESS; - -FAIL: - return status; -} - -static void -_cairo_gl_span_renderer_fini (cairo_abstract_span_renderer_t *_r, - cairo_int_status_t status) -{ - cairo_gl_span_renderer_t *r = (cairo_gl_span_renderer_t *) _r; - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - return; - - if (status == CAIRO_INT_STATUS_SUCCESS) - r->base.finish (r); - - _cairo_gl_composite_fini (&r->setup); -} - -const cairo_compositor_t * -_cairo_gl_span_compositor_get (void) -{ - static cairo_spans_compositor_t spans; - static cairo_compositor_t shape; - - if (spans.base.delegate == NULL) { - /* The fallback to traps here is essentially just for glyphs... */ - _cairo_shape_mask_compositor_init (&shape, - _cairo_gl_traps_compositor_get()); - shape.glyphs = NULL; - - _cairo_spans_compositor_init (&spans, &shape); - spans.fill_boxes = fill_boxes; - spans.draw_image_boxes = draw_image_boxes; - spans.copy_boxes = copy_boxes; - //spans.check_composite_boxes = check_composite_boxes; - spans.pattern_to_surface = _cairo_gl_pattern_to_source; - spans.composite_boxes = composite_boxes; - //spans.check_span_renderer = check_span_renderer; - spans.renderer_init = _cairo_gl_span_renderer_init; - spans.renderer_fini = _cairo_gl_span_renderer_fini; - } - - return &spans.base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-surface.c deleted file mode 100644 index cfccf4dfda5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-surface.c +++ /dev/null @@ -1,1459 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-surface-backend-private.h" - -static const cairo_surface_backend_t _cairo_gl_surface_backend; - -static cairo_status_t -_cairo_gl_surface_flush (void *abstract_surface, unsigned flags); - -static cairo_bool_t _cairo_surface_is_gl (cairo_surface_t *surface) -{ - return surface->backend == &_cairo_gl_surface_backend; -} - -static cairo_bool_t -_cairo_gl_get_image_format_and_type_gles2 (pixman_format_code_t pixman_format, - GLenum *internal_format, GLenum *format, - GLenum *type, cairo_bool_t *has_alpha, - cairo_bool_t *needs_swap) -{ - cairo_bool_t is_little_endian = _cairo_is_little_endian (); - - *has_alpha = TRUE; - - switch ((int) pixman_format) { - case PIXMAN_a8r8g8b8: - *internal_format = GL_BGRA; - *format = GL_BGRA; - *type = GL_UNSIGNED_BYTE; - *needs_swap = !is_little_endian; - return TRUE; - - case PIXMAN_x8r8g8b8: - *internal_format = GL_BGRA; - *format = GL_BGRA; - *type = GL_UNSIGNED_BYTE; - *has_alpha = FALSE; - *needs_swap = !is_little_endian; - return TRUE; - - case PIXMAN_a8b8g8r8: - *internal_format = GL_RGBA; - *format = GL_RGBA; - *type = GL_UNSIGNED_BYTE; - *needs_swap = !is_little_endian; - return TRUE; - - case PIXMAN_x8b8g8r8: - *internal_format = GL_RGBA; - *format = GL_RGBA; - *type = GL_UNSIGNED_BYTE; - *has_alpha = FALSE; - *needs_swap = !is_little_endian; - return TRUE; - - case PIXMAN_b8g8r8a8: - *internal_format = GL_BGRA; - *format = GL_BGRA; - *type = GL_UNSIGNED_BYTE; - *needs_swap = is_little_endian; - return TRUE; - - case PIXMAN_b8g8r8x8: - *internal_format = GL_BGRA; - *format = GL_BGRA; - *type = GL_UNSIGNED_BYTE; - *has_alpha = FALSE; - *needs_swap = is_little_endian; - return TRUE; - - case PIXMAN_r8g8b8: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_BYTE; - *needs_swap = is_little_endian; - return TRUE; - - case PIXMAN_b8g8r8: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_BYTE; - *needs_swap = !is_little_endian; - return TRUE; - - case PIXMAN_r5g6b5: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_SHORT_5_6_5; - *needs_swap = FALSE; - return TRUE; - - case PIXMAN_b5g6r5: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_SHORT_5_6_5; - *needs_swap = TRUE; - return TRUE; - - case PIXMAN_a1b5g5r5: - *internal_format = GL_RGBA; - *format = GL_RGBA; - *type = GL_UNSIGNED_SHORT_5_5_5_1; - *needs_swap = TRUE; - return TRUE; - - case PIXMAN_x1b5g5r5: - *internal_format = GL_RGBA; - *format = GL_RGBA; - *type = GL_UNSIGNED_SHORT_5_5_5_1; - *has_alpha = FALSE; - *needs_swap = TRUE; - return TRUE; - - case PIXMAN_a8: - *internal_format = GL_ALPHA; - *format = GL_ALPHA; - *type = GL_UNSIGNED_BYTE; - *needs_swap = FALSE; - return TRUE; - - default: - return FALSE; - } -} - -static cairo_bool_t -_cairo_gl_get_image_format_and_type_gl (pixman_format_code_t pixman_format, - GLenum *internal_format, GLenum *format, - GLenum *type, cairo_bool_t *has_alpha, - cairo_bool_t *needs_swap) -{ - *has_alpha = TRUE; - *needs_swap = FALSE; - - switch (pixman_format) { - case PIXMAN_a8r8g8b8: - *internal_format = GL_RGBA; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - return TRUE; - case PIXMAN_x8r8g8b8: - *internal_format = GL_RGB; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - *has_alpha = FALSE; - return TRUE; - case PIXMAN_a8b8g8r8: - *internal_format = GL_RGBA; - *format = GL_RGBA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - return TRUE; - case PIXMAN_x8b8g8r8: - *internal_format = GL_RGB; - *format = GL_RGBA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - *has_alpha = FALSE; - return TRUE; - case PIXMAN_b8g8r8a8: - *internal_format = GL_RGBA; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8; - return TRUE; - case PIXMAN_b8g8r8x8: - *internal_format = GL_RGB; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8; - *has_alpha = FALSE; - return TRUE; - case PIXMAN_r8g8b8: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_BYTE; - return TRUE; - case PIXMAN_b8g8r8: - *internal_format = GL_RGB; - *format = GL_BGR; - *type = GL_UNSIGNED_BYTE; - return TRUE; - case PIXMAN_r5g6b5: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_SHORT_5_6_5; - return TRUE; - case PIXMAN_b5g6r5: - *internal_format = GL_RGB; - *format = GL_RGB; - *type = GL_UNSIGNED_SHORT_5_6_5_REV; - return TRUE; - case PIXMAN_a1r5g5b5: - *internal_format = GL_RGBA; - *format = GL_BGRA; - *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - return TRUE; - case PIXMAN_x1r5g5b5: - *internal_format = GL_RGB; - *format = GL_BGRA; - *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - *has_alpha = FALSE; - return TRUE; - case PIXMAN_a1b5g5r5: - *internal_format = GL_RGBA; - *format = GL_RGBA; - *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - return TRUE; - case PIXMAN_x1b5g5r5: - *internal_format = GL_RGB; - *format = GL_RGBA; - *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - *has_alpha = FALSE; - return TRUE; - case PIXMAN_a8: - *internal_format = GL_ALPHA; - *format = GL_ALPHA; - *type = GL_UNSIGNED_BYTE; - return TRUE; - -#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,27,2) - case PIXMAN_a8r8g8b8_sRGB: -#endif - case PIXMAN_a2b10g10r10: - case PIXMAN_x2b10g10r10: - case PIXMAN_a4r4g4b4: - case PIXMAN_x4r4g4b4: - case PIXMAN_a4b4g4r4: - case PIXMAN_x4b4g4r4: - case PIXMAN_r3g3b2: - case PIXMAN_b2g3r3: - case PIXMAN_a2r2g2b2: - case PIXMAN_a2b2g2r2: - case PIXMAN_c8: - case PIXMAN_x4a4: - /* case PIXMAN_x4c4: */ - case PIXMAN_x4g4: - case PIXMAN_a4: - case PIXMAN_r1g2b1: - case PIXMAN_b1g2r1: - case PIXMAN_a1r1g1b1: - case PIXMAN_a1b1g1r1: - case PIXMAN_c4: - case PIXMAN_g4: - case PIXMAN_a1: - case PIXMAN_g1: - case PIXMAN_yuy2: - case PIXMAN_yv12: - case PIXMAN_x2r10g10b10: - case PIXMAN_a2r10g10b10: - case PIXMAN_r8g8b8x8: - case PIXMAN_r8g8b8a8: - case PIXMAN_x14r6g6b6: - default: - return FALSE; - } -} - -/* - * Extracts pixel data from an image surface. - */ -static cairo_status_t -_cairo_gl_surface_extract_image_data (cairo_image_surface_t *image, - int x, int y, - int width, int height, - void **output) -{ - int cpp = PIXMAN_FORMAT_BPP (image->pixman_format) / 8; - char *data = _cairo_malloc_ab (width * height, cpp); - char *dst = data; - unsigned char *src = image->data + y * image->stride + x * cpp; - int i; - - if (unlikely (data == NULL)) - return CAIRO_STATUS_NO_MEMORY; - - for (i = 0; i < height; i++) { - memcpy (dst, src, width * cpp); - src += image->stride; - dst += width * cpp; - } - - *output = data; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_bool_t -_cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor, - pixman_format_code_t pixman_format, - GLenum *internal_format, GLenum *format, - GLenum *type, cairo_bool_t *has_alpha, - cairo_bool_t *needs_swap) -{ - if (flavor == CAIRO_GL_FLAVOR_DESKTOP) - return _cairo_gl_get_image_format_and_type_gl (pixman_format, - internal_format, format, - type, has_alpha, - needs_swap); - else - return _cairo_gl_get_image_format_and_type_gles2 (pixman_format, - internal_format, format, - type, has_alpha, - needs_swap); - -} - -cairo_bool_t -_cairo_gl_operator_is_supported (cairo_operator_t op) -{ - return op < CAIRO_OPERATOR_SATURATE; -} - -static void -_cairo_gl_surface_embedded_operand_init (cairo_gl_surface_t *surface) -{ - cairo_gl_operand_t *operand = &surface->operand; - cairo_surface_attributes_t *attributes = &operand->texture.attributes; - - memset (operand, 0, sizeof (cairo_gl_operand_t)); - - operand->type = CAIRO_GL_OPERAND_TEXTURE; - operand->texture.surface = surface; - operand->texture.tex = surface->tex; - - if (_cairo_gl_device_requires_power_of_two_textures (surface->base.device)) { - cairo_matrix_init_identity (&attributes->matrix); - } else { - cairo_matrix_init_scale (&attributes->matrix, - 1.0 / surface->width, - 1.0 / surface->height); - } - - attributes->extend = CAIRO_EXTEND_NONE; - attributes->filter = CAIRO_FILTER_NEAREST; -} - -void -_cairo_gl_surface_init (cairo_device_t *device, - cairo_gl_surface_t *surface, - cairo_content_t content, - int width, int height) -{ - assert (width > 0 && height > 0); - - _cairo_surface_init (&surface->base, - &_cairo_gl_surface_backend, - device, - content); - - surface->width = width; - surface->height = height; - surface->needs_update = FALSE; - - _cairo_gl_surface_embedded_operand_init (surface); -} - -static cairo_bool_t -_cairo_gl_surface_size_valid_for_context (cairo_gl_context_t *ctx, - int width, int height) -{ - return width > 0 && height > 0 && - width <= ctx->max_framebuffer_size && - height <= ctx->max_framebuffer_size; -} - -static cairo_bool_t -_cairo_gl_surface_size_valid (cairo_gl_surface_t *surface, - int width, int height) -{ - cairo_gl_context_t *ctx = (cairo_gl_context_t *)surface->base.device; - return _cairo_gl_surface_size_valid_for_context (ctx, width, height); -} - -static cairo_surface_t * -_cairo_gl_surface_create_scratch_for_texture (cairo_gl_context_t *ctx, - cairo_content_t content, - GLuint tex, - int width, - int height) -{ - cairo_gl_surface_t *surface; - - surface = calloc (1, sizeof (cairo_gl_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface->tex = tex; - _cairo_gl_surface_init (&ctx->base, surface, content, width, height); - - surface->supports_msaa = ctx->supports_msaa; - surface->supports_stencil = TRUE; - - /* Create the texture used to store the surface's data. */ - _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); - glBindTexture (ctx->tex_target, surface->tex); - glTexParameteri (ctx->tex_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri (ctx->tex_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - return &surface->base; -} - -static cairo_surface_t * -_create_scratch_internal (cairo_gl_context_t *ctx, - cairo_content_t content, - int width, - int height, - cairo_bool_t for_caching) -{ - cairo_gl_surface_t *surface; - GLenum format; - GLuint tex; - - glGenTextures (1, &tex); - surface = (cairo_gl_surface_t *) - _cairo_gl_surface_create_scratch_for_texture (ctx, content, - tex, width, height); - if (unlikely (surface->base.status)) - return &surface->base; - - surface->owns_tex = TRUE; - - /* adjust the texture size after setting our real extents */ - if (width < 1) - width = 1; - if (height < 1) - height = 1; - - switch (content) { - default: - ASSERT_NOT_REACHED; - case CAIRO_CONTENT_COLOR_ALPHA: - format = GL_RGBA; - break; - case CAIRO_CONTENT_ALPHA: - /* When using GL_ALPHA, compositing doesn't work properly, but for - * caching surfaces, we are just uploading pixel data, so it isn't - * an issue. */ - if (for_caching) - format = GL_ALPHA; - else - format = GL_RGBA; - break; - case CAIRO_CONTENT_COLOR: - /* GL_RGB is almost what we want here -- sampling 1 alpha when - * texturing, using 1 as destination alpha factor in blending, - * etc. However, when filtering with GL_CLAMP_TO_BORDER, the - * alpha channel of the border color will also be clamped to - * 1, when we actually want the border color we explicitly - * specified. So, we have to store RGBA, and fill the alpha - * channel with 1 when blending. - */ - format = GL_RGBA; - break; - } - - glTexImage2D (ctx->tex_target, 0, format, width, height, 0, - format, GL_UNSIGNED_BYTE, NULL); - - return &surface->base; -} - -cairo_surface_t * -_cairo_gl_surface_create_scratch (cairo_gl_context_t *ctx, - cairo_content_t content, - int width, - int height) -{ - return _create_scratch_internal (ctx, content, width, height, FALSE); -} - -cairo_surface_t * -_cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx, - cairo_content_t content, - int width, - int height) -{ - return _create_scratch_internal (ctx, content, width, height, TRUE); -} - -static cairo_status_t -_cairo_gl_surface_clear (cairo_gl_surface_t *surface, - const cairo_color_t *color) -{ - cairo_gl_context_t *ctx; - cairo_status_t status; - double r, g, b, a; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return status; - - _cairo_gl_context_set_destination (ctx, surface, surface->msaa_active); - if (surface->base.content & CAIRO_CONTENT_COLOR) { - r = color->red * color->alpha; - g = color->green * color->alpha; - b = color->blue * color->alpha; - } else { - r = g = b = 0; - } - if (surface->base.content & CAIRO_CONTENT_ALPHA) { - a = color->alpha; - } else { - a = 1.0; - } - - glDisable (GL_SCISSOR_TEST); - glClearColor (r, g, b, a); - glClear (GL_COLOR_BUFFER_BIT); - - if (a == 0) - surface->base.is_clear = TRUE; - - return _cairo_gl_context_release (ctx, status); -} - -static cairo_surface_t * -_cairo_gl_surface_create_and_clear_scratch (cairo_gl_context_t *ctx, - cairo_content_t content, - int width, - int height) -{ - cairo_gl_surface_t *surface; - cairo_int_status_t status; - - surface = (cairo_gl_surface_t *) - _cairo_gl_surface_create_scratch (ctx, content, width, height); - if (unlikely (surface->base.status)) - return &surface->base; - - /* Cairo surfaces start out initialized to transparent (black) */ - status = _cairo_gl_surface_clear (surface, CAIRO_COLOR_TRANSPARENT); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return _cairo_surface_create_in_error (status); - } - - return &surface->base; -} - -cairo_surface_t * -cairo_gl_surface_create (cairo_device_t *abstract_device, - cairo_content_t content, - int width, - int height) -{ - cairo_gl_context_t *ctx; - cairo_gl_surface_t *surface; - cairo_status_t status; - - if (! CAIRO_CONTENT_VALID (content)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); - - if (abstract_device == NULL) - return _cairo_image_surface_create_with_content (content, width, height); - - if (abstract_device->status) - return _cairo_surface_create_in_error (abstract_device->status); - - if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_GL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - - status = _cairo_gl_context_acquire (abstract_device, &ctx); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (! _cairo_gl_surface_size_valid_for_context (ctx, width, height)) { - status = _cairo_gl_context_release (ctx, status); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - } - - surface = (cairo_gl_surface_t *) - _cairo_gl_surface_create_and_clear_scratch (ctx, content, width, height); - if (unlikely (surface->base.status)) { - status = _cairo_gl_context_release (ctx, surface->base.status); - cairo_surface_destroy (&surface->base); - return _cairo_surface_create_in_error (status); - } - - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return _cairo_surface_create_in_error (status); - } - - return &surface->base; -} -slim_hidden_def (cairo_gl_surface_create); - -/** - * cairo_gl_surface_create_for_texture: - * @content: type of content in the surface - * @tex: name of texture to use for storage of surface pixels - * @width: width of the surface, in pixels - * @height: height of the surface, in pixels - * - * Creates a GL surface for the specified texture with the specified - * content and dimensions. The texture must be kept around until the - * #cairo_surface_t is destroyed or cairo_surface_finish() is called - * on the surface. The initial contents of @tex will be used as the - * initial image contents; you must explicitly clear the buffer, - * using, for example, cairo_rectangle() and cairo_fill() if you want - * it cleared. The format of @tex should be compatible with @content, - * in the sense that it must have the color components required by - * @content. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: TBD - **/ -cairo_surface_t * -cairo_gl_surface_create_for_texture (cairo_device_t *abstract_device, - cairo_content_t content, - unsigned int tex, - int width, - int height) -{ - cairo_gl_context_t *ctx; - cairo_gl_surface_t *surface; - cairo_status_t status; - - if (! CAIRO_CONTENT_VALID (content)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); - - if (abstract_device == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); - - if (abstract_device->status) - return _cairo_surface_create_in_error (abstract_device->status); - - if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_GL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH)); - - status = _cairo_gl_context_acquire (abstract_device, &ctx); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (! _cairo_gl_surface_size_valid_for_context (ctx, width, height)) { - status = _cairo_gl_context_release (ctx, status); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - } - - surface = (cairo_gl_surface_t *) - _cairo_gl_surface_create_scratch_for_texture (ctx, content, - tex, width, height); - status = _cairo_gl_context_release (ctx, status); - - return &surface->base; -} -slim_hidden_def (cairo_gl_surface_create_for_texture); - - -void -cairo_gl_surface_set_size (cairo_surface_t *abstract_surface, - int width, - int height) -{ - cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (! _cairo_surface_is_gl (abstract_surface) || - _cairo_gl_surface_is_texture (surface)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - if (surface->width != width || surface->height != height) { - surface->needs_update = TRUE; - surface->width = width; - surface->height = height; - } -} - -int -cairo_gl_surface_get_width (cairo_surface_t *abstract_surface) -{ - cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; - - if (! _cairo_surface_is_gl (abstract_surface)) - return 0; - - return surface->width; -} - -int -cairo_gl_surface_get_height (cairo_surface_t *abstract_surface) -{ - cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; - - if (! _cairo_surface_is_gl (abstract_surface)) - return 0; - - return surface->height; -} - -void -cairo_gl_surface_swapbuffers (cairo_surface_t *abstract_surface) -{ - cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (! _cairo_surface_is_gl (abstract_surface)) { - _cairo_surface_set_error (abstract_surface, - CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return; - } - - if (! _cairo_gl_surface_is_texture (surface)) { - cairo_gl_context_t *ctx; - cairo_status_t status; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return; - - /* For swapping on EGL, at least, we need a valid context/target. */ - _cairo_gl_context_set_destination (ctx, surface, FALSE); - /* And in any case we should flush any pending operations. */ - _cairo_gl_composite_flush (ctx); - - ctx->swap_buffers (ctx, surface); - - status = _cairo_gl_context_release (ctx, status); - if (status) - status = _cairo_surface_set_error (abstract_surface, status); - } -} - -static cairo_surface_t * -_cairo_gl_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_surface_t *surface = abstract_surface; - cairo_gl_context_t *ctx; - cairo_status_t status; - - if (! _cairo_gl_surface_size_valid (abstract_surface, width, height)) - return _cairo_image_surface_create_with_content (content, width, height); - - status = _cairo_gl_context_acquire (surface->device, &ctx); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - surface = _cairo_gl_surface_create_and_clear_scratch (ctx, content, width, height); - - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) { - cairo_surface_destroy (surface); - return _cairo_surface_create_in_error (status); - } - - return surface; -} - -static cairo_int_status_t -_cairo_gl_surface_fill_alpha_channel (cairo_gl_surface_t *dst, - cairo_gl_context_t *ctx, - int x, int y, - int width, int height) -{ - cairo_gl_composite_t setup; - cairo_status_t status; - - _cairo_gl_composite_flush (ctx); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); - - status = _cairo_gl_composite_init (&setup, CAIRO_OPERATOR_SOURCE, - dst, FALSE); - if (unlikely (status)) - goto CLEANUP; - - _cairo_gl_composite_set_solid_source (&setup, CAIRO_COLOR_BLACK); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto CLEANUP; - - _cairo_gl_context_emit_rect (ctx, x, y, x + width, y + height); - - status = _cairo_gl_context_release (ctx, status); - - CLEANUP: - _cairo_gl_composite_fini (&setup); - - _cairo_gl_composite_flush (ctx); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - return status; -} - -cairo_status_t -_cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, - cairo_image_surface_t *src, - int src_x, int src_y, - int width, int height, - int dst_x, int dst_y, - cairo_bool_t force_flush) -{ - GLenum internal_format, format, type; - cairo_bool_t has_alpha, needs_swap; - cairo_image_surface_t *clone = NULL; - cairo_gl_context_t *ctx; - int cpp; - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - - status = _cairo_gl_context_acquire (dst->base.device, &ctx); - if (unlikely (status)) - return status; - - if (! _cairo_gl_get_image_format_and_type (ctx->gl_flavor, - src->pixman_format, - &internal_format, - &format, - &type, - &has_alpha, - &needs_swap)) - { - cairo_bool_t is_supported; - - clone = _cairo_image_surface_coerce (src); - if (unlikely (status = clone->base.status)) - goto FAIL; - - is_supported = - _cairo_gl_get_image_format_and_type (ctx->gl_flavor, - clone->pixman_format, - &internal_format, - &format, - &type, - &has_alpha, - &needs_swap); - assert (is_supported); - assert (!needs_swap); - src = clone; - } - - cpp = PIXMAN_FORMAT_BPP (src->pixman_format) / 8; - - if (force_flush) { - status = _cairo_gl_surface_flush (&dst->base, 0); - if (unlikely (status)) - goto FAIL; - } - - if (_cairo_gl_surface_is_texture (dst)) { - void *data_start = src->data + src_y * src->stride + src_x * cpp; - void *data_start_gles2 = NULL; - - /* - * Due to GL_UNPACK_ROW_LENGTH missing in GLES2 we have to extract the - * image data ourselves in some cases. In particular, we must extract - * the pixels if: - * a. we don't want full-length lines or - * b. the row stride cannot be handled by GL itself using a 4 byte - * alignment constraint - */ - if (src->stride < 0 || - (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && - (src->width * cpp < src->stride - 3 || - width != src->width))) - { - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - status = _cairo_gl_surface_extract_image_data (src, src_x, src_y, - width, height, - &data_start_gles2); - if (unlikely (status)) - goto FAIL; - - data_start = data_start_gles2; - } - else - { - glPixelStorei (GL_UNPACK_ALIGNMENT, 4); - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - glPixelStorei (GL_UNPACK_ROW_LENGTH, src->stride / cpp); - } - - _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); - glBindTexture (ctx->tex_target, dst->tex); - glTexParameteri (ctx->tex_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri (ctx->tex_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexSubImage2D (ctx->tex_target, 0, - dst_x, dst_y, width, height, - format, type, data_start); - - free (data_start_gles2); - - /* If we just treated some rgb-only data as rgba, then we have to - * go back and fix up the alpha channel where we filled in this - * texture data. - */ - if (!has_alpha) { - _cairo_gl_surface_fill_alpha_channel (dst, ctx, - dst_x, dst_y, - width, height); - } - } else { - cairo_surface_t *tmp; - - tmp = _cairo_gl_surface_create_scratch (ctx, - dst->base.content, - width, height); - if (unlikely (tmp->status)) - goto FAIL; - - status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *) tmp, - src, - src_x, src_y, - width, height, - 0, 0, force_flush); - if (status == CAIRO_INT_STATUS_SUCCESS) { - cairo_surface_pattern_t tmp_pattern; - cairo_rectangle_int_t r; - cairo_clip_t *clip; - - _cairo_pattern_init_for_surface (&tmp_pattern, tmp); - cairo_matrix_init_translate (&tmp_pattern.base.matrix, - -dst_x, -dst_y); - tmp_pattern.base.filter = CAIRO_FILTER_NEAREST; - tmp_pattern.base.extend = CAIRO_EXTEND_NONE; - - r.x = dst_x; - r.y = dst_y; - r.width = width; - r.height = height; - clip = _cairo_clip_intersect_rectangle (NULL, &r); - status = _cairo_surface_paint (&dst->base, - CAIRO_OPERATOR_SOURCE, - &tmp_pattern.base, - clip); - _cairo_clip_destroy (clip); - _cairo_pattern_fini (&tmp_pattern.base); - } - - cairo_surface_destroy (tmp); - } - -FAIL: - status = _cairo_gl_context_release (ctx, status); - - if (clone) - cairo_surface_destroy (&clone->base); - - return status; -} - -static int _cairo_gl_surface_flavor (cairo_gl_surface_t *surface) -{ - cairo_gl_context_t *ctx = (cairo_gl_context_t *)surface->base.device; - return ctx->gl_flavor; -} - -static cairo_status_t -_cairo_gl_surface_finish (void *abstract_surface) -{ - cairo_gl_surface_t *surface = abstract_surface; - cairo_status_t status; - cairo_gl_context_t *ctx; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return status; - - if (ctx->operands[CAIRO_GL_TEX_SOURCE].type == CAIRO_GL_OPERAND_TEXTURE && - ctx->operands[CAIRO_GL_TEX_SOURCE].texture.surface == surface) - _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_SOURCE); - if (ctx->operands[CAIRO_GL_TEX_MASK].type == CAIRO_GL_OPERAND_TEXTURE && - ctx->operands[CAIRO_GL_TEX_MASK].texture.surface == surface) - _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_MASK); - if (ctx->current_target == surface) - ctx->current_target = NULL; - - if (surface->fb) - ctx->dispatch.DeleteFramebuffers (1, &surface->fb); - if (surface->depth_stencil) - ctx->dispatch.DeleteRenderbuffers (1, &surface->depth_stencil); - if (surface->owns_tex) - glDeleteTextures (1, &surface->tex); - - if (surface->msaa_depth_stencil) - ctx->dispatch.DeleteRenderbuffers (1, &surface->msaa_depth_stencil); - -#if CAIRO_HAS_GL_SURFACE - if (surface->msaa_fb) - ctx->dispatch.DeleteFramebuffers (1, &surface->msaa_fb); - if (surface->msaa_rb) - ctx->dispatch.DeleteRenderbuffers (1, &surface->msaa_rb); -#endif - - _cairo_clip_destroy (surface->clip_on_stencil_buffer); - - return _cairo_gl_context_release (ctx, status); -} - -static cairo_image_surface_t * -_cairo_gl_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_gl_surface_t *surface = abstract_surface; - cairo_image_surface_t *image; - cairo_gl_context_t *ctx; - GLenum format, type; - pixman_format_code_t pixman_format; - unsigned int cpp; - cairo_bool_t flipped, mesa_invert; - cairo_status_t status; - int y; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) { - return _cairo_image_surface_create_in_error (status); - } - - /* Want to use a switch statement here but the compiler gets whiny. */ - if (surface->base.content == CAIRO_CONTENT_COLOR_ALPHA) { - format = GL_BGRA; - pixman_format = PIXMAN_a8r8g8b8; - type = GL_UNSIGNED_INT_8_8_8_8_REV; - cpp = 4; - } else if (surface->base.content == CAIRO_CONTENT_COLOR) { - format = GL_BGRA; - pixman_format = PIXMAN_x8r8g8b8; - type = GL_UNSIGNED_INT_8_8_8_8_REV; - cpp = 4; - } else if (surface->base.content == CAIRO_CONTENT_ALPHA) { - format = GL_ALPHA; - pixman_format = PIXMAN_a8; - type = GL_UNSIGNED_BYTE; - cpp = 1; - } else { - ASSERT_NOT_REACHED; - return NULL; - } - - if (_cairo_gl_surface_flavor (surface) == CAIRO_GL_FLAVOR_ES) { - /* If only RGBA is supported, we must download data in a compatible - * format. This means that pixman will convert the data on the CPU when - * interacting with other image surfaces. For ALPHA, GLES2 does not - * support GL_PACK_ROW_LENGTH anyway, and this makes sure that the - * pixman image that is created has row_stride = row_width * bpp. */ - if (surface->base.content == CAIRO_CONTENT_ALPHA || !ctx->can_read_bgra) { - cairo_bool_t little_endian = _cairo_is_little_endian (); - format = GL_RGBA; - - if (surface->base.content == CAIRO_CONTENT_COLOR) { - pixman_format = little_endian ? - PIXMAN_x8b8g8r8 : PIXMAN_r8g8b8x8; - } else { - pixman_format = little_endian ? - PIXMAN_a8b8g8r8 : PIXMAN_r8g8b8a8; - } - } - - /* GLES2 only supports GL_UNSIGNED_BYTE. */ - type = GL_UNSIGNED_BYTE; - cpp = 4; - } - - image = (cairo_image_surface_t*) - _cairo_image_surface_create_with_pixman_format (NULL, - pixman_format, - extents->width, - extents->height, - -1); - if (unlikely (image->base.status)) { - status = _cairo_gl_context_release (ctx, status); - return image; - } - - cairo_surface_set_device_offset (&image->base, -extents->x, -extents->y); - - /* If the original surface has not been modified or - * is clear, we can avoid downloading data. */ - if (surface->base.is_clear || surface->base.serial == 0) { - status = _cairo_gl_context_release (ctx, status); - return image; - } - - /* This is inefficient, as we'd rather just read the thing without making - * it the destination. But then, this is the fallback path, so let's not - * fall back instead. - */ - _cairo_gl_composite_flush (ctx); - _cairo_gl_context_set_destination (ctx, surface, FALSE); - - flipped = ! _cairo_gl_surface_is_texture (surface); - mesa_invert = flipped && ctx->has_mesa_pack_invert; - - glPixelStorei (GL_PACK_ALIGNMENT, 4); - if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) - glPixelStorei (GL_PACK_ROW_LENGTH, image->stride / cpp); - if (mesa_invert) - glPixelStorei (GL_PACK_INVERT_MESA, 1); - - y = extents->y; - if (flipped) - y = surface->height - extents->y - extents->height; - - glReadPixels (extents->x, y, - extents->width, extents->height, - format, type, image->data); - if (mesa_invert) - glPixelStorei (GL_PACK_INVERT_MESA, 0); - - status = _cairo_gl_context_release (ctx, status); - if (unlikely (status)) { - cairo_surface_destroy (&image->base); - return _cairo_image_surface_create_in_error (status); - } - - /* We must invert the image manualy if we lack GL_MESA_pack_invert */ - if (flipped && ! mesa_invert) { - uint8_t stack[1024], *row = stack; - uint8_t *top = image->data; - uint8_t *bot = image->data + (image->height-1)*image->stride; - - if (image->stride > (int)sizeof(stack)) { - row = malloc (image->stride); - if (unlikely (row == NULL)) { - cairo_surface_destroy (&image->base); - return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - } - - while (top < bot) { - memcpy (row, top, image->stride); - memcpy (top, bot, image->stride); - memcpy (bot, row, image->stride); - top += image->stride; - bot -= image->stride; - } - - if (row != stack) - free(row); - } - - image->base.is_clear = FALSE; - return image; -} - -static cairo_surface_t * -_cairo_gl_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_gl_surface_t *surface = abstract_surface; - - if (extents) { - extents->x = extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - } - - return &surface->base; -} - -static cairo_status_t -_cairo_gl_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_gl_surface_t *surface = abstract_surface; - cairo_rectangle_int_t extents; - - *image_extra = NULL; - - extents.x = extents.y = 0; - extents.width = surface->width; - extents.height = surface->height; - - *image_out = (cairo_image_surface_t *) - _cairo_gl_surface_map_to_image (surface, &extents); - return (*image_out)->base.status; -} - -static void -_cairo_gl_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); -} - -static cairo_int_status_t -_cairo_gl_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_int_status_t status; - - status = _cairo_gl_surface_draw_image (abstract_surface, image, - 0, 0, - image->width, image->height, - image->base.device_transform_inverse.x0, - image->base.device_transform_inverse.y0, - TRUE); - - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return status; -} - -static cairo_bool_t -_cairo_gl_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_gl_surface_t *surface = abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - rectangle->width = surface->width; - rectangle->height = surface->height; - - return TRUE; -} - -static cairo_status_t -_cairo_gl_surface_flush (void *abstract_surface, unsigned flags) -{ - cairo_gl_surface_t *surface = abstract_surface; - cairo_status_t status; - cairo_gl_context_t *ctx; - - if (flags) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return status; - - if ((ctx->operands[CAIRO_GL_TEX_SOURCE].type == CAIRO_GL_OPERAND_TEXTURE && - ctx->operands[CAIRO_GL_TEX_SOURCE].texture.surface == surface) || - (ctx->operands[CAIRO_GL_TEX_MASK].type == CAIRO_GL_OPERAND_TEXTURE && - ctx->operands[CAIRO_GL_TEX_MASK].texture.surface == surface) || - (ctx->current_target == surface)) - _cairo_gl_composite_flush (ctx); - - status = _cairo_gl_surface_resolve_multisampling (surface); - - return _cairo_gl_context_release (ctx, status); -} - -cairo_int_status_t -_cairo_gl_surface_resolve_multisampling (cairo_gl_surface_t *surface) -{ - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - if (! surface->msaa_active) - return CAIRO_INT_STATUS_SUCCESS; - - if (surface->base.device == NULL) - return CAIRO_INT_STATUS_SUCCESS; - - /* GLES surfaces do not need explicit resolution. */ - if (((cairo_gl_context_t *) surface->base.device)->gl_flavor == CAIRO_GL_FLAVOR_ES) - return CAIRO_INT_STATUS_SUCCESS; - - if (! _cairo_gl_surface_is_texture (surface)) - return CAIRO_INT_STATUS_SUCCESS; - - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return status; - - ctx->current_target = surface; - -#if CAIRO_HAS_GL_SURFACE - _cairo_gl_context_bind_framebuffer (ctx, surface, FALSE); -#endif - - status = _cairo_gl_context_release (ctx, status); - return status; -} - -static const cairo_compositor_t * -get_compositor (cairo_gl_surface_t *surface) -{ - cairo_gl_context_t *ctx = (cairo_gl_context_t *)surface->base.device; - return ctx->compositor; -} - -static cairo_int_status_t -_cairo_gl_surface_paint (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - /* simplify the common case of clearing the surface */ - if (clip == NULL) { - if (op == CAIRO_OPERATOR_CLEAR) - return _cairo_gl_surface_clear (surface, CAIRO_COLOR_TRANSPARENT); - else if (source->type == CAIRO_PATTERN_TYPE_SOLID && - (op == CAIRO_OPERATOR_SOURCE || - (op == CAIRO_OPERATOR_OVER && _cairo_pattern_is_opaque_solid (source)))) { - return _cairo_gl_surface_clear (surface, - &((cairo_solid_pattern_t *) source)->color); - } - } - - return _cairo_compositor_paint (get_compositor (surface), surface, - op, source, clip); -} - -static cairo_int_status_t -_cairo_gl_surface_mask (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - return _cairo_compositor_mask (get_compositor (surface), surface, - op, source, mask, clip); -} - -static cairo_int_status_t -_cairo_gl_surface_stroke (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - return _cairo_compositor_stroke (get_compositor (surface), surface, - op, source, path, style, - ctm, ctm_inverse, tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_gl_surface_fill (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - return _cairo_compositor_fill (get_compositor (surface), surface, - op, source, path, - fill_rule, tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_gl_surface_glyphs (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *font, - const cairo_clip_t *clip) -{ - return _cairo_compositor_glyphs (get_compositor (surface), surface, - op, source, glyphs, num_glyphs, font, - clip); -} - -static const cairo_surface_backend_t _cairo_gl_surface_backend = { - CAIRO_SURFACE_TYPE_GL, - _cairo_gl_surface_finish, - _cairo_default_context_create, - - _cairo_gl_surface_create_similar, - NULL, /* similar image */ - _cairo_gl_surface_map_to_image, - _cairo_gl_surface_unmap_image, - - _cairo_gl_surface_source, - _cairo_gl_surface_acquire_source_image, - _cairo_gl_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_gl_surface_get_extents, - _cairo_image_surface_get_font_options, - - _cairo_gl_surface_flush, - NULL, /* mark_dirty_rectangle */ - - _cairo_gl_surface_paint, - _cairo_gl_surface_mask, - _cairo_gl_surface_stroke, - _cairo_gl_surface_fill, - NULL, /* fill/stroke */ - _cairo_gl_surface_glyphs, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-traps-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-traps-compositor.c deleted file mode 100644 index 125ed4eabcb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl-traps-compositor.c +++ /dev/null @@ -1,558 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005,2010 Red Hat, Inc - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Benjamin Otte - * Carl Worth - * Chris Wilson - * Eric Anholt - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-spans-compositor-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-surface-offset-private.h" - -static cairo_int_status_t -acquire (void *abstract_dst) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -release (void *abstract_dst) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -set_clip_region (void *_surface, - cairo_region_t *region) -{ - cairo_gl_surface_t *surface = _surface; - - surface->clip_region = region; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -draw_image_boxes (void *_dst, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy) -{ - cairo_gl_surface_t *dst = _dst; - struct _cairo_boxes_chunk *chunk; - int i; - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - int x = _cairo_fixed_integer_part (b->p1.x); - int y = _cairo_fixed_integer_part (b->p1.y); - int w = _cairo_fixed_integer_part (b->p2.x) - x; - int h = _cairo_fixed_integer_part (b->p2.y) - y; - cairo_status_t status; - - status = _cairo_gl_surface_draw_image (dst, image, - x + dx, y + dy, - w, h, - x, y, - TRUE); - if (unlikely (status)) - return status; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -emit_aligned_boxes (cairo_gl_context_t *ctx, - const cairo_boxes_t *boxes) -{ - const struct _cairo_boxes_chunk *chunk; - cairo_gl_emit_rect_t emit = _cairo_gl_context_choose_emit_rect (ctx); - int i; - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - emit (ctx, x1, y1, x2, y2); - } - } -} - -static cairo_int_status_t -fill_boxes (void *_dst, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_solid_source (&setup, color); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - emit_aligned_boxes (ctx, boxes); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_int_status_t -composite_boxes (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_source_operand (&setup, - source_to_operand (abstract_src)); - _cairo_gl_operand_translate (&setup.src, dst_x-src_x, dst_y-src_y); - - _cairo_gl_composite_set_mask_operand (&setup, - source_to_operand (abstract_mask)); - _cairo_gl_operand_translate (&setup.mask, dst_x-mask_x, dst_y-mask_y); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - emit_aligned_boxes (ctx, boxes); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_int_status_t -composite (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_source_operand (&setup, - source_to_operand (abstract_src)); - _cairo_gl_operand_translate (&setup.src, dst_x-src_x, dst_y-src_y); - - _cairo_gl_composite_set_mask_operand (&setup, - source_to_operand (abstract_mask)); - _cairo_gl_operand_translate (&setup.mask, dst_x-mask_x, dst_y-mask_y); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - /* XXX clip */ - _cairo_gl_context_emit_rect (ctx, dst_x, dst_y, dst_x+width, dst_y+height); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_int_status_t -lerp (void *dst, - cairo_surface_t *src, - cairo_surface_t *mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - cairo_int_status_t status; - - /* we could avoid some repetition... */ - status = composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - mask_x, mask_y, - 0, 0, - dst_x, dst_y, - width, height); - if (unlikely (status)) - return status; - - status = composite (dst, CAIRO_OPERATOR_ADD, src, mask, - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -traps_to_operand (void *_dst, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_traps_t *traps, - cairo_gl_operand_t *operand, - int dst_x, int dst_y) -{ - pixman_format_code_t pixman_format; - pixman_image_t *pixman_image; - cairo_surface_t *image, *mask; - cairo_surface_pattern_t pattern; - cairo_status_t status; - - pixman_format = antialias != CAIRO_ANTIALIAS_NONE ? PIXMAN_a8 : PIXMAN_a1; - pixman_image = pixman_image_create_bits (pixman_format, - extents->width, - extents->height, - NULL, 0); - if (unlikely (pixman_image == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _pixman_image_add_traps (pixman_image, extents->x, extents->y, traps); - image = _cairo_image_surface_create_for_pixman_image (pixman_image, - pixman_format); - if (unlikely (image->status)) { - pixman_image_unref (pixman_image); - return image->status; - } - - /* GLES2 only supports RGB/RGBA when uploading */ - if (_cairo_gl_get_flavor () == CAIRO_GL_FLAVOR_ES) { - cairo_surface_pattern_t pattern; - cairo_surface_t *rgba_image; - - /* XXX perform this fixup inside _cairo_gl_draw_image() */ - - rgba_image = - _cairo_image_surface_create_with_pixman_format (NULL, - _cairo_is_little_endian () ? PIXMAN_a8b8g8r8 : PIXMAN_r8g8b8a8, - extents->width, - extents->height, - 0); - if (unlikely (rgba_image->status)) - return rgba_image->status; - - _cairo_pattern_init_for_surface (&pattern, image); - status = _cairo_surface_paint (rgba_image, CAIRO_OPERATOR_SOURCE, - &pattern.base, NULL); - _cairo_pattern_fini (&pattern.base); - - cairo_surface_destroy (image); - image = rgba_image; - - if (unlikely (status)) { - cairo_surface_destroy (image); - return status; - } - } - - mask = _cairo_surface_create_scratch (_dst, - CAIRO_CONTENT_COLOR_ALPHA, - extents->width, - extents->height, - NULL); - if (unlikely (mask->status)) { - cairo_surface_destroy (image); - return mask->status; - } - - status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *)mask, - (cairo_image_surface_t *)image, - 0, 0, - extents->width, extents->height, - 0, 0, - TRUE); - cairo_surface_destroy (image); - - if (unlikely (status)) - goto error; - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->x+dst_x, -extents->y+dst_y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - status = _cairo_gl_operand_init (operand, &pattern.base, _dst, - &_cairo_unbounded_rectangle, - &_cairo_unbounded_rectangle, - FALSE); - _cairo_pattern_fini (&pattern.base); - - if (unlikely (status)) - goto error; - - operand->texture.owns_surface = (cairo_gl_surface_t *)mask; - return CAIRO_STATUS_SUCCESS; - -error: - cairo_surface_destroy (mask); - return status; -} - -static cairo_int_status_t -composite_traps (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_traps_t *traps) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_int_status_t status; - - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_source_operand (&setup, - source_to_operand (abstract_src)); - _cairo_gl_operand_translate (&setup.src, -src_x-dst_x, -src_y-dst_y); - status = traps_to_operand (_dst, extents, antialias, traps, &setup.mask, dst_x, dst_y); - if (unlikely (status)) - goto FAIL; - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - /* XXX clip */ - _cairo_gl_context_emit_rect (ctx, - extents->x-dst_x, extents->y-dst_y, - extents->x-dst_x+extents->width, - extents->y-dst_y+extents->height); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - return status; -} - -static cairo_gl_surface_t * -tristrip_to_surface (void *_dst, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_tristrip_t *strip) -{ - pixman_format_code_t pixman_format; - pixman_image_t *pixman_image; - cairo_surface_t *image, *mask; - cairo_status_t status; - - pixman_format = antialias != CAIRO_ANTIALIAS_NONE ? PIXMAN_a8 : PIXMAN_a1, - pixman_image = pixman_image_create_bits (pixman_format, - extents->width, - extents->height, - NULL, 0); - if (unlikely (pixman_image == NULL)) - return (cairo_gl_surface_t *)_cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _pixman_image_add_tristrip (pixman_image, extents->x, extents->y, strip); - image = _cairo_image_surface_create_for_pixman_image (pixman_image, - pixman_format); - if (unlikely (image->status)) { - pixman_image_unref (pixman_image); - return (cairo_gl_surface_t *)image; - } - - mask = _cairo_surface_create_scratch (_dst, - CAIRO_CONTENT_COLOR_ALPHA, - extents->width, - extents->height, - NULL); - if (unlikely (mask->status)) { - cairo_surface_destroy (image); - return (cairo_gl_surface_t *)mask; - } - - status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *)mask, - (cairo_image_surface_t *)image, - 0, 0, - extents->width, extents->height, - 0, 0, - TRUE); - cairo_surface_destroy (image); - if (unlikely (status)) { - cairo_surface_destroy (mask); - return (cairo_gl_surface_t*)_cairo_surface_create_in_error (status); - } - - return (cairo_gl_surface_t*)mask; -} - -static cairo_int_status_t -composite_tristrip (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_tristrip_t *strip) -{ - cairo_gl_composite_t setup; - cairo_gl_context_t *ctx; - cairo_gl_surface_t *mask; - cairo_int_status_t status; - - mask = tristrip_to_surface (_dst, extents, antialias, strip); - if (unlikely (mask->base.status)) - return mask->base.status; - - status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); - if (unlikely (status)) - goto FAIL; - - _cairo_gl_composite_set_source_operand (&setup, - source_to_operand (abstract_src)); - - //_cairo_gl_composite_set_mask_surface (&setup, mask, 0, 0); - - status = _cairo_gl_composite_begin (&setup, &ctx); - if (unlikely (status)) - goto FAIL; - - /* XXX clip */ - _cairo_gl_context_emit_rect (ctx, - dst_x, dst_y, - dst_x+extents->width, - dst_y+extents->height); - status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); - -FAIL: - _cairo_gl_composite_fini (&setup); - cairo_surface_destroy (&mask->base); - return status; -} - -static cairo_int_status_t -check_composite (const cairo_composite_rectangles_t *extents) -{ - if (! _cairo_gl_operator_is_supported (extents->op)) - return UNSUPPORTED ("unsupported operator"); - - return CAIRO_STATUS_SUCCESS; -} - -const cairo_compositor_t * -_cairo_gl_traps_compositor_get (void) -{ - static cairo_traps_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_traps_compositor_init (&compositor, &_cairo_fallback_compositor); - compositor.acquire = acquire; - compositor.release = release; - compositor.set_clip_region = set_clip_region; - compositor.pattern_to_surface = _cairo_gl_pattern_to_source; - compositor.draw_image_boxes = draw_image_boxes; - //compositor.copy_boxes = copy_boxes; - compositor.fill_boxes = fill_boxes; - compositor.check_composite = check_composite; - compositor.composite = composite; - compositor.lerp = lerp; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - //compositor.check_composite_traps = check_composite_traps; - compositor.composite_traps = composite_traps; - //compositor.check_composite_tristrip = check_composite_traps; - compositor.composite_tristrip = composite_tristrip; - compositor.check_composite_glyphs = _cairo_gl_check_composite_glyphs; - compositor.composite_glyphs = _cairo_gl_composite_glyphs; - } - - return &compositor.base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl.h deleted file mode 100644 index 9fd7608f5cf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gl.h +++ /dev/null @@ -1,155 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Eric Anholt. - */ - -/* - * cairo-gl.h: - * - * The cairo-gl backend provides an implementation of possibly - * hardware-accelerated cairo rendering by targeting the OpenGL API. - * The goal of the cairo-gl backend is to provide better performance - * with equal functionality to cairo-image where possible. It does - * not directly provide for applying additional OpenGL effects to - * cairo surfaces. - * - * Cairo-gl allows interoperability with other GL rendering through GL - * context sharing. Cairo-gl surfaces are created in reference to a - * #cairo_device_t, which represents a GL context created by the user. - * When that GL context is created with its sharePtr set to another - * context (or vice versa), its objects (textures backing cairo-gl - * surfaces) can be accessed in the other OpenGL context. This allows - * cairo-gl to maintain its drawing state in one context while the - * user's 3D rendering occurs in the user's other context. - * - * However, as only one context can be current to a thread at a time, - * cairo-gl may make its context current to the thread on any cairo - * call which interacts with a cairo-gl surface or the cairo-gl - * device. As a result, the user must make their own context current - * between any cairo calls and their own OpenGL rendering. - **/ - -#ifndef CAIRO_GL_H -#define CAIRO_GL_H - -#include "cairo.h" - -#if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_gl_surface_create (cairo_device_t *device, - cairo_content_t content, - int width, int height); - -cairo_public cairo_surface_t * -cairo_gl_surface_create_for_texture (cairo_device_t *abstract_device, - cairo_content_t content, - unsigned int tex, - int width, int height); -cairo_public void -cairo_gl_surface_set_size (cairo_surface_t *surface, int width, int height); - -cairo_public int -cairo_gl_surface_get_width (cairo_surface_t *abstract_surface); - -cairo_public int -cairo_gl_surface_get_height (cairo_surface_t *abstract_surface); - -cairo_public void -cairo_gl_surface_swapbuffers (cairo_surface_t *surface); - -cairo_public void -cairo_gl_device_set_thread_aware (cairo_device_t *device, - cairo_bool_t thread_aware); - -#if CAIRO_HAS_GLX_FUNCTIONS -#include - -cairo_public cairo_device_t * -cairo_glx_device_create (Display *dpy, GLXContext gl_ctx); - -cairo_public Display * -cairo_glx_device_get_display (cairo_device_t *device); - -cairo_public GLXContext -cairo_glx_device_get_context (cairo_device_t *device); - -cairo_public cairo_surface_t * -cairo_gl_surface_create_for_window (cairo_device_t *device, - Window win, - int width, int height); -#endif - -#if CAIRO_HAS_WGL_FUNCTIONS -#include - -cairo_public cairo_device_t * -cairo_wgl_device_create (HGLRC rc); - -cairo_public HGLRC -cairo_wgl_device_get_context (cairo_device_t *device); - -cairo_public cairo_surface_t * -cairo_gl_surface_create_for_dc (cairo_device_t *device, - HDC dc, - int width, - int height); -#endif - -#if CAIRO_HAS_EGL_FUNCTIONS -#include - -cairo_public cairo_device_t * -cairo_egl_device_create (EGLDisplay dpy, EGLContext egl); - -cairo_public cairo_surface_t * -cairo_gl_surface_create_for_egl (cairo_device_t *device, - EGLSurface egl, - int width, - int height); - -cairo_public EGLDisplay -cairo_egl_device_get_display (cairo_device_t *device); - -cairo_public EGLSurface -cairo_egl_device_get_context (cairo_device_t *device); - -#endif - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_GL_SURFACE */ -# error Cairo was not compiled with support for the GL backend -#endif /* CAIRO_HAS_GL_SURFACE */ - -#endif /* CAIRO_GL_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-glx-context.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-glx-context.c deleted file mode 100644 index 3761b9079a4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-glx-context.c +++ /dev/null @@ -1,324 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-error-private.h" - -#include - -/* XXX needs hooking into XCloseDisplay() */ - -typedef struct _cairo_glx_context { - cairo_gl_context_t base; - - Display *display; - Window dummy_window; - GLXContext context; - - GLXDrawable previous_drawable; - GLXContext previous_context; - - cairo_bool_t has_multithread_makecurrent; -} cairo_glx_context_t; - -typedef struct _cairo_glx_surface { - cairo_gl_surface_t base; - - Window win; -} cairo_glx_surface_t; - -static cairo_bool_t -_context_acquisition_changed_glx_state (cairo_glx_context_t *ctx, - GLXDrawable current_drawable) -{ - return ctx->previous_drawable != current_drawable || - ctx->previous_context != ctx->context; -} - -static GLXDrawable -_glx_get_current_drawable (cairo_glx_context_t *ctx) -{ - if (ctx->base.current_target == NULL || - _cairo_gl_surface_is_texture (ctx->base.current_target)) { - return ctx->dummy_window; - } - - return ((cairo_glx_surface_t *) ctx->base.current_target)->win; -} - -static void -_glx_query_current_state (cairo_glx_context_t * ctx) -{ - ctx->previous_drawable = glXGetCurrentDrawable (); - ctx->previous_context = glXGetCurrentContext (); - - /* If any of the values were none, assume they are all none. Not all - drivers seem well behaved when it comes to using these values across - multiple threads. */ - if (ctx->previous_drawable == None || - ctx->previous_context == None) { - ctx->previous_drawable = None; - ctx->previous_context = None; - } -} - -static void -_glx_acquire (void *abstract_ctx) -{ - cairo_glx_context_t *ctx = abstract_ctx; - GLXDrawable current_drawable = _glx_get_current_drawable (ctx); - - _glx_query_current_state (ctx); - if (!_context_acquisition_changed_glx_state (ctx, current_drawable)) - return; - - glXMakeCurrent (ctx->display, current_drawable, ctx->context); -} - -static void -_glx_make_current (void *abstract_ctx, cairo_gl_surface_t *abstract_surface) -{ - cairo_glx_context_t *ctx = abstract_ctx; - cairo_glx_surface_t *surface = (cairo_glx_surface_t *) abstract_surface; - - /* Set the window as the target of our context. */ - glXMakeCurrent (ctx->display, surface->win, ctx->context); -} - -static void -_glx_release (void *abstract_ctx) -{ - cairo_glx_context_t *ctx = abstract_ctx; - - if (ctx->has_multithread_makecurrent || !ctx->base.thread_aware || - !_context_acquisition_changed_glx_state (ctx, - _glx_get_current_drawable (ctx))) { - return; - } - - glXMakeCurrent (ctx->display, None, None); -} - -static void -_glx_swap_buffers (void *abstract_ctx, - cairo_gl_surface_t *abstract_surface) -{ - cairo_glx_context_t *ctx = abstract_ctx; - cairo_glx_surface_t *surface = (cairo_glx_surface_t *) abstract_surface; - - glXSwapBuffers (ctx->display, surface->win); -} - -static void -_glx_destroy (void *abstract_ctx) -{ - cairo_glx_context_t *ctx = abstract_ctx; - - if (ctx->dummy_window != None) - XDestroyWindow (ctx->display, ctx->dummy_window); - - glXMakeCurrent (ctx->display, None, None); -} - -static cairo_status_t -_glx_dummy_window (Display *dpy, GLXContext gl_ctx, Window *dummy) -{ - int attr[3] = { GLX_FBCONFIG_ID, 0, None }; - GLXFBConfig *config; - XVisualInfo *vi; - Colormap cmap; - XSetWindowAttributes swa; - Window win = None; - int cnt; - - /* Create a dummy window created for the target GLX context that we can - * use to query the available GL/GLX extensions. - */ - glXQueryContext (dpy, gl_ctx, GLX_FBCONFIG_ID, &attr[1]); - - cnt = 0; - config = glXChooseFBConfig (dpy, DefaultScreen (dpy), attr, &cnt); - if (unlikely (cnt == 0)) - return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); - - vi = glXGetVisualFromFBConfig (dpy, config[0]); - XFree (config); - - if (unlikely (vi == NULL)) - return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); - - cmap = XCreateColormap (dpy, - RootWindow (dpy, vi->screen), - vi->visual, - AllocNone); - swa.colormap = cmap; - swa.border_pixel = 0; - win = XCreateWindow (dpy, RootWindow (dpy, vi->screen), - -1, -1, 1, 1, 0, - vi->depth, - InputOutput, - vi->visual, - CWBorderPixel | CWColormap, &swa); - XFreeColormap (dpy, cmap); - XFree (vi); - - XFlush (dpy); - if (unlikely (! glXMakeCurrent (dpy, win, gl_ctx))) { - XDestroyWindow (dpy, win); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - *dummy = win; - return CAIRO_STATUS_SUCCESS; -} - -cairo_device_t * -cairo_glx_device_create (Display *dpy, GLXContext gl_ctx) -{ - cairo_glx_context_t *ctx; - cairo_status_t status; - Window dummy = None; - const char *glx_extensions; - - ctx = calloc (1, sizeof (cairo_glx_context_t)); - if (unlikely (ctx == NULL)) - return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); - - /* glx_dummy_window will call glXMakeCurrent, so we need to - * query the current state of the context now. */ - _glx_query_current_state (ctx); - - status = _glx_dummy_window (dpy, gl_ctx, &dummy); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - ctx->display = dpy; - ctx->dummy_window = dummy; - ctx->context = gl_ctx; - - ctx->base.acquire = _glx_acquire; - ctx->base.release = _glx_release; - ctx->base.make_current = _glx_make_current; - ctx->base.swap_buffers = _glx_swap_buffers; - ctx->base.destroy = _glx_destroy; - - status = _cairo_gl_dispatch_init (&ctx->base.dispatch, - (cairo_gl_get_proc_addr_func_t) glXGetProcAddress); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - status = _cairo_gl_context_init (&ctx->base); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - glx_extensions = glXQueryExtensionsString (dpy, DefaultScreen (dpy)); - if (strstr(glx_extensions, "GLX_MESA_multithread_makecurrent")) { - ctx->has_multithread_makecurrent = TRUE; - } - - ctx->base.release (ctx); - - return &ctx->base.base; -} - -Display * -cairo_glx_device_get_display (cairo_device_t *device) -{ - cairo_glx_context_t *ctx; - - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { - _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - return NULL; - } - - ctx = (cairo_glx_context_t *) device; - - return ctx->display; -} - -GLXContext -cairo_glx_device_get_context (cairo_device_t *device) -{ - cairo_glx_context_t *ctx; - - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { - _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - return NULL; - } - - ctx = (cairo_glx_context_t *) device; - - return ctx->context; -} - -cairo_surface_t * -cairo_gl_surface_create_for_window (cairo_device_t *device, - Window win, - int width, - int height) -{ - cairo_glx_surface_t *surface; - - if (unlikely (device->status)) - return _cairo_surface_create_in_error (device->status); - - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - - if (width <= 0 || height <= 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - surface = calloc (1, sizeof (cairo_glx_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_gl_surface_init (device, &surface->base, - CAIRO_CONTENT_COLOR_ALPHA, width, height); - surface->win = win; - - return &surface->base.base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate-private.h deleted file mode 100644 index b2ccc76d145..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate-private.h +++ /dev/null @@ -1,387 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_GSTATE_PRIVATE_H -#define CAIRO_GSTATE_PRIVATE_H - -#include "cairo-clip-private.h" - -struct _cairo_gstate { - cairo_operator_t op; - - double opacity; - double tolerance; - cairo_antialias_t antialias; - - cairo_stroke_style_t stroke_style; - - cairo_fill_rule_t fill_rule; - - cairo_font_face_t *font_face; - cairo_scaled_font_t *scaled_font; /* Specific to the current CTM */ - cairo_scaled_font_t *previous_scaled_font; /* holdover */ - cairo_matrix_t font_matrix; - cairo_font_options_t font_options; - - cairo_clip_t *clip; - - cairo_surface_t *target; /* The target to which all rendering is directed */ - cairo_surface_t *parent_target; /* The previous target which was receiving rendering */ - cairo_surface_t *original_target; /* The original target the initial gstate was created with */ - - /* the user is allowed to update the device after we have cached the matrices... */ - cairo_observer_t device_transform_observer; - - cairo_matrix_t ctm; - cairo_matrix_t ctm_inverse; - cairo_matrix_t source_ctm_inverse; /* At the time ->source was set */ - cairo_bool_t is_identity; - - cairo_pattern_t *source; - - struct _cairo_gstate *next; -}; - -/* cairo-gstate.c */ -cairo_private cairo_status_t -_cairo_gstate_init (cairo_gstate_t *gstate, - cairo_surface_t *target); - -cairo_private void -_cairo_gstate_fini (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist); - -cairo_private cairo_status_t -_cairo_gstate_restore (cairo_gstate_t **gstate, cairo_gstate_t **freelist); - -cairo_private cairo_bool_t -_cairo_gstate_is_group (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child); - -cairo_private cairo_surface_t * -_cairo_gstate_get_target (cairo_gstate_t *gstate); - -cairo_private cairo_surface_t * -_cairo_gstate_get_original_target (cairo_gstate_t *gstate); - -cairo_private cairo_clip_t * -_cairo_gstate_get_clip (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_source (cairo_gstate_t *gstate, cairo_pattern_t *source); - -cairo_private cairo_pattern_t * -_cairo_gstate_get_source (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_operator (cairo_gstate_t *gstate, cairo_operator_t op); - -cairo_private cairo_operator_t -_cairo_gstate_get_operator (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_opacity (cairo_gstate_t *gstate, double opacity); - -cairo_private double -_cairo_gstate_get_opacity (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_tolerance (cairo_gstate_t *gstate, double tolerance); - -cairo_private double -_cairo_gstate_get_tolerance (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule); - -cairo_private cairo_fill_rule_t -_cairo_gstate_get_fill_rule (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_line_width (cairo_gstate_t *gstate, double width); - -cairo_private double -_cairo_gstate_get_line_width (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_line_cap (cairo_gstate_t *gstate, cairo_line_cap_t line_cap); - -cairo_private cairo_line_cap_t -_cairo_gstate_get_line_cap (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_line_join (cairo_gstate_t *gstate, cairo_line_join_t line_join); - -cairo_private cairo_line_join_t -_cairo_gstate_get_line_join (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dashes, double offset); - -cairo_private void -_cairo_gstate_get_dash (cairo_gstate_t *gstate, double *dash, int *num_dashes, double *offset); - -cairo_private cairo_status_t -_cairo_gstate_set_miter_limit (cairo_gstate_t *gstate, double limit); - -cairo_private double -_cairo_gstate_get_miter_limit (cairo_gstate_t *gstate); - -cairo_private void -_cairo_gstate_get_matrix (cairo_gstate_t *gstate, cairo_matrix_t *matrix); - -cairo_private cairo_status_t -_cairo_gstate_translate (cairo_gstate_t *gstate, double tx, double ty); - -cairo_private cairo_status_t -_cairo_gstate_scale (cairo_gstate_t *gstate, double sx, double sy); - -cairo_private cairo_status_t -_cairo_gstate_rotate (cairo_gstate_t *gstate, double angle); - -cairo_private cairo_status_t -_cairo_gstate_transform (cairo_gstate_t *gstate, - const cairo_matrix_t *matrix); - -cairo_private cairo_status_t -_cairo_gstate_set_matrix (cairo_gstate_t *gstate, - const cairo_matrix_t *matrix); - -cairo_private void -_cairo_gstate_identity_matrix (cairo_gstate_t *gstate); - -cairo_private void -_cairo_gstate_user_to_device (cairo_gstate_t *gstate, double *x, double *y); - -cairo_private void -_cairo_gstate_user_to_device_distance (cairo_gstate_t *gstate, double *dx, double *dy); - -cairo_private void -_cairo_gstate_device_to_user (cairo_gstate_t *gstate, double *x, double *y); - -cairo_private void -_cairo_gstate_device_to_user_distance (cairo_gstate_t *gstate, double *dx, double *dy); - -cairo_private void -_do_cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y); - -static inline void -_cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y) -{ - if (! gstate->is_identity) - _do_cairo_gstate_user_to_backend (gstate, x, y); -} - -cairo_private void -_do_cairo_gstate_user_to_backend_distance (cairo_gstate_t *gstate, double *x, double *y); - -static inline void -_cairo_gstate_user_to_backend_distance (cairo_gstate_t *gstate, double *x, double *y) -{ - if (! gstate->is_identity) - _do_cairo_gstate_user_to_backend_distance (gstate, x, y); -} - -cairo_private void -_do_cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y); - -static inline void -_cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y) -{ - if (! gstate->is_identity) - _do_cairo_gstate_backend_to_user (gstate, x, y); -} - -cairo_private void -_do_cairo_gstate_backend_to_user_distance (cairo_gstate_t *gstate, double *x, double *y); - -static inline void -_cairo_gstate_backend_to_user_distance (cairo_gstate_t *gstate, double *x, double *y) -{ - if (! gstate->is_identity) - _do_cairo_gstate_backend_to_user_distance (gstate, x, y); -} - -cairo_private void -_cairo_gstate_backend_to_user_rectangle (cairo_gstate_t *gstate, - double *x1, double *y1, - double *x2, double *y2, - cairo_bool_t *is_tight); - -cairo_private void -_cairo_gstate_path_extents (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double *x1, double *y1, - double *x2, double *y2); - -cairo_private cairo_status_t -_cairo_gstate_paint (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_mask (cairo_gstate_t *gstate, - cairo_pattern_t *mask); - -cairo_private cairo_status_t -_cairo_gstate_stroke (cairo_gstate_t *gstate, cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_gstate_copy_page (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_show_page (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_stroke_extents (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double *x1, double *y1, - double *x2, double *y2); - -cairo_private cairo_status_t -_cairo_gstate_fill_extents (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double *x1, double *y1, - double *x2, double *y2); - -cairo_private cairo_status_t -_cairo_gstate_in_stroke (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double x, - double y, - cairo_bool_t *inside_ret); - -cairo_private cairo_bool_t -_cairo_gstate_in_fill (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double x, - double y); - -cairo_private cairo_bool_t -_cairo_gstate_in_clip (cairo_gstate_t *gstate, - double x, - double y); - -cairo_private cairo_status_t -_cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_gstate_reset_clip (cairo_gstate_t *gstate); - -cairo_private cairo_bool_t -_cairo_gstate_clip_extents (cairo_gstate_t *gstate, - double *x1, - double *y1, - double *x2, - double *y2); - -cairo_private cairo_rectangle_list_t* -_cairo_gstate_copy_clip_rectangle_list (cairo_gstate_t *gstate); - -cairo_private cairo_status_t -_cairo_gstate_show_surface (cairo_gstate_t *gstate, - cairo_surface_t *surface, - double x, - double y, - double width, - double height); - -cairo_private cairo_status_t -_cairo_gstate_set_font_size (cairo_gstate_t *gstate, - double size); - -cairo_private void -_cairo_gstate_get_font_matrix (cairo_gstate_t *gstate, - cairo_matrix_t *matrix); - -cairo_private cairo_status_t -_cairo_gstate_set_font_matrix (cairo_gstate_t *gstate, - const cairo_matrix_t *matrix); - -cairo_private void -_cairo_gstate_get_font_options (cairo_gstate_t *gstate, - cairo_font_options_t *options); - -cairo_private void -_cairo_gstate_set_font_options (cairo_gstate_t *gstate, - const cairo_font_options_t *options); - -cairo_private cairo_status_t -_cairo_gstate_get_font_face (cairo_gstate_t *gstate, - cairo_font_face_t **font_face); - -cairo_private cairo_status_t -_cairo_gstate_get_scaled_font (cairo_gstate_t *gstate, - cairo_scaled_font_t **scaled_font); - -cairo_private cairo_status_t -_cairo_gstate_get_font_extents (cairo_gstate_t *gstate, - cairo_font_extents_t *extents); - -cairo_private cairo_status_t -_cairo_gstate_set_font_face (cairo_gstate_t *gstate, - cairo_font_face_t *font_face); - -cairo_private cairo_status_t -_cairo_gstate_glyph_extents (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents); - -cairo_private cairo_status_t -_cairo_gstate_show_text_glyphs (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_glyph_text_info_t *info); - -cairo_private cairo_status_t -_cairo_gstate_glyph_path (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_gstate_set_antialias (cairo_gstate_t *gstate, - cairo_antialias_t antialias); - -cairo_private cairo_antialias_t -_cairo_gstate_get_antialias (cairo_gstate_t *gstate); - -#endif /* CAIRO_GSTATE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate.c deleted file mode 100644 index b4e988e96d8..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-gstate.c +++ /dev/null @@ -1,2346 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-list-inline.h" -#include "cairo-gstate-private.h" -#include "cairo-pattern-private.h" -#include "cairo-traps-private.h" - -#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE) -#define ISFINITE(x) isfinite (x) -#else -#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */ -#endif - -static cairo_status_t -_cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other); - -static cairo_status_t -_cairo_gstate_ensure_font_face (cairo_gstate_t *gstate); - -static cairo_status_t -_cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate); - -static void -_cairo_gstate_unset_scaled_font (cairo_gstate_t *gstate); - -static void -_cairo_gstate_transform_glyphs_to_backend (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_glyph_t *transformed_glyphs, - int *num_transformed_glyphs, - cairo_text_cluster_t *transformed_clusters); - -static void -_cairo_gstate_update_device_transform (cairo_observer_t *observer, - void *arg) -{ - cairo_gstate_t *gstate = cairo_container_of (observer, - cairo_gstate_t, - device_transform_observer); - - gstate->is_identity = (_cairo_matrix_is_identity (&gstate->ctm) && - _cairo_matrix_is_identity (&gstate->target->device_transform)); -} - -cairo_status_t -_cairo_gstate_init (cairo_gstate_t *gstate, - cairo_surface_t *target) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (gstate, sizeof (cairo_gstate_t))); - - gstate->next = NULL; - - gstate->op = CAIRO_GSTATE_OPERATOR_DEFAULT; - gstate->opacity = 1.; - - gstate->tolerance = CAIRO_GSTATE_TOLERANCE_DEFAULT; - gstate->antialias = CAIRO_ANTIALIAS_DEFAULT; - - _cairo_stroke_style_init (&gstate->stroke_style); - - gstate->fill_rule = CAIRO_GSTATE_FILL_RULE_DEFAULT; - - gstate->font_face = NULL; - gstate->scaled_font = NULL; - gstate->previous_scaled_font = NULL; - - cairo_matrix_init_scale (&gstate->font_matrix, - CAIRO_GSTATE_DEFAULT_FONT_SIZE, - CAIRO_GSTATE_DEFAULT_FONT_SIZE); - - _cairo_font_options_init_default (&gstate->font_options); - - gstate->clip = NULL; - - gstate->target = cairo_surface_reference (target); - gstate->parent_target = NULL; - gstate->original_target = cairo_surface_reference (target); - - gstate->device_transform_observer.callback = _cairo_gstate_update_device_transform; - cairo_list_add (&gstate->device_transform_observer.link, - &gstate->target->device_transform_observers); - - gstate->is_identity = _cairo_matrix_is_identity (&gstate->target->device_transform); - cairo_matrix_init_identity (&gstate->ctm); - gstate->ctm_inverse = gstate->ctm; - gstate->source_ctm_inverse = gstate->ctm; - - gstate->source = (cairo_pattern_t *) &_cairo_pattern_black.base; - - /* Now that the gstate is fully initialized and ready for the eventual - * _cairo_gstate_fini(), we can check for errors (and not worry about - * the resource deallocation). */ - return target->status; -} - -/** - * _cairo_gstate_init_copy: - * - * Initialize @gstate by performing a deep copy of state fields from - * @other. Note that gstate->next is not copied but is set to %NULL by - * this function. - **/ -static cairo_status_t -_cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other) -{ - cairo_status_t status; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (gstate, sizeof (cairo_gstate_t))); - - gstate->op = other->op; - gstate->opacity = other->opacity; - - gstate->tolerance = other->tolerance; - gstate->antialias = other->antialias; - - status = _cairo_stroke_style_init_copy (&gstate->stroke_style, - &other->stroke_style); - if (unlikely (status)) - return status; - - gstate->fill_rule = other->fill_rule; - - gstate->font_face = cairo_font_face_reference (other->font_face); - gstate->scaled_font = cairo_scaled_font_reference (other->scaled_font); - gstate->previous_scaled_font = cairo_scaled_font_reference (other->previous_scaled_font); - - gstate->font_matrix = other->font_matrix; - - _cairo_font_options_init_copy (&gstate->font_options , &other->font_options); - - gstate->clip = _cairo_clip_copy (other->clip); - - gstate->target = cairo_surface_reference (other->target); - /* parent_target is always set to NULL; it's only ever set by redirect_target */ - gstate->parent_target = NULL; - gstate->original_target = cairo_surface_reference (other->original_target); - - gstate->device_transform_observer.callback = _cairo_gstate_update_device_transform; - cairo_list_add (&gstate->device_transform_observer.link, - &gstate->target->device_transform_observers); - - gstate->is_identity = other->is_identity; - gstate->ctm = other->ctm; - gstate->ctm_inverse = other->ctm_inverse; - gstate->source_ctm_inverse = other->source_ctm_inverse; - - gstate->source = cairo_pattern_reference (other->source); - - gstate->next = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gstate_fini (cairo_gstate_t *gstate) -{ - _cairo_stroke_style_fini (&gstate->stroke_style); - - cairo_font_face_destroy (gstate->font_face); - gstate->font_face = NULL; - - cairo_scaled_font_destroy (gstate->previous_scaled_font); - gstate->previous_scaled_font = NULL; - - cairo_scaled_font_destroy (gstate->scaled_font); - gstate->scaled_font = NULL; - - _cairo_clip_destroy (gstate->clip); - - cairo_list_del (&gstate->device_transform_observer.link); - - cairo_surface_destroy (gstate->target); - gstate->target = NULL; - - cairo_surface_destroy (gstate->parent_target); - gstate->parent_target = NULL; - - cairo_surface_destroy (gstate->original_target); - gstate->original_target = NULL; - - cairo_pattern_destroy (gstate->source); - gstate->source = NULL; - - VG (VALGRIND_MAKE_MEM_NOACCESS (gstate, sizeof (cairo_gstate_t))); -} - -/** - * _cairo_gstate_save: - * @gstate: input/output gstate pointer - * - * Makes a copy of the current state of @gstate and saves it - * to @gstate->next, then put the address of the newly allcated - * copy into @gstate. _cairo_gstate_restore() reverses this. - **/ -cairo_status_t -_cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist) -{ - cairo_gstate_t *top; - cairo_status_t status; - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - top = *freelist; - if (top == NULL) { - top = malloc (sizeof (cairo_gstate_t)); - if (unlikely (top == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - *freelist = top->next; - - status = _cairo_gstate_init_copy (top, *gstate); - if (unlikely (status)) { - top->next = *freelist; - *freelist = top; - return status; - } - - top->next = *gstate; - *gstate = top; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_gstate_restore: - * @gstate: input/output gstate pointer - * - * Reverses the effects of one _cairo_gstate_save() call. - **/ -cairo_status_t -_cairo_gstate_restore (cairo_gstate_t **gstate, cairo_gstate_t **freelist) -{ - cairo_gstate_t *top; - - top = *gstate; - if (top->next == NULL) - return _cairo_error (CAIRO_STATUS_INVALID_RESTORE); - - *gstate = top->next; - - _cairo_gstate_fini (top); - VG (VALGRIND_MAKE_MEM_UNDEFINED (&top->next, sizeof (cairo_gstate_t *))); - top->next = *freelist; - *freelist = top; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_gstate_redirect_target: - * @gstate: a #cairo_gstate_t - * @child: the new child target - * - * Redirect @gstate rendering to a "child" target. The original - * "parent" target with which the gstate was created will not be - * affected. See _cairo_gstate_get_target(). - **/ -cairo_status_t -_cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child) -{ - /* If this gstate is already redirected, this is an error; we need a - * new gstate to be able to redirect */ - assert (gstate->parent_target == NULL); - - /* Set up our new parent_target based on our current target; - * gstate->parent_target will take the ref that is held by gstate->target - */ - gstate->parent_target = gstate->target; - - /* Now set up our new target; we overwrite gstate->target directly, - * since its ref is now owned by gstate->parent_target */ - gstate->target = cairo_surface_reference (child); - gstate->is_identity &= _cairo_matrix_is_identity (&child->device_transform); - cairo_list_move (&gstate->device_transform_observer.link, - &gstate->target->device_transform_observers); - - /* The clip is in surface backend coordinates for the previous target; - * translate it into the child's backend coordinates. */ - _cairo_clip_destroy (gstate->clip); - gstate->clip = _cairo_clip_copy_with_translation (gstate->next->clip, - child->device_transform.x0 - gstate->parent_target->device_transform.x0, - child->device_transform.y0 - gstate->parent_target->device_transform.y0); - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_gstate_is_group: - * @gstate: a #cairo_gstate_t - * - * Check if _cairo_gstate_redirect_target has been called on the head - * of the stack. - * - * Return value: %TRUE if @gstate is redirected to a target different - * than the previous state in the stack, %FALSE otherwise. - **/ -cairo_bool_t -_cairo_gstate_is_group (cairo_gstate_t *gstate) -{ - return gstate->parent_target != NULL; -} - -/** - * _cairo_gstate_get_target: - * @gstate: a #cairo_gstate_t - * - * Return the current drawing target; if drawing is not redirected, - * this will be the same as _cairo_gstate_get_original_target(). - * - * Return value: the current target surface - **/ -cairo_surface_t * -_cairo_gstate_get_target (cairo_gstate_t *gstate) -{ - return gstate->target; -} - -/** - * _cairo_gstate_get_original_target: - * @gstate: a #cairo_gstate_t - * - * Return the original target with which @gstate was created. This - * function always returns the original target independent of any - * child target that may have been set with - * _cairo_gstate_redirect_target. - * - * Return value: the original target surface - **/ -cairo_surface_t * -_cairo_gstate_get_original_target (cairo_gstate_t *gstate) -{ - return gstate->original_target; -} - -/** - * _cairo_gstate_get_clip: - * @gstate: a #cairo_gstate_t - * - * This space left intentionally blank. - * - * Return value: a pointer to the gstate's #cairo_clip_t structure. - **/ -cairo_clip_t * -_cairo_gstate_get_clip (cairo_gstate_t *gstate) -{ - return gstate->clip; -} - -cairo_status_t -_cairo_gstate_set_source (cairo_gstate_t *gstate, - cairo_pattern_t *source) -{ - if (source->status) - return source->status; - - source = cairo_pattern_reference (source); - cairo_pattern_destroy (gstate->source); - gstate->source = source; - gstate->source_ctm_inverse = gstate->ctm_inverse; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_pattern_t * -_cairo_gstate_get_source (cairo_gstate_t *gstate) -{ - if (gstate->source == &_cairo_pattern_black.base) { - /* do not expose the static object to the user */ - gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK); - } - - return gstate->source; -} - -cairo_status_t -_cairo_gstate_set_operator (cairo_gstate_t *gstate, cairo_operator_t op) -{ - gstate->op = op; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_operator_t -_cairo_gstate_get_operator (cairo_gstate_t *gstate) -{ - return gstate->op; -} - -cairo_status_t -_cairo_gstate_set_opacity (cairo_gstate_t *gstate, double op) -{ - gstate->opacity = op; - - return CAIRO_STATUS_SUCCESS; -} - -double -_cairo_gstate_get_opacity (cairo_gstate_t *gstate) -{ - return gstate->opacity; -} - -cairo_status_t -_cairo_gstate_set_tolerance (cairo_gstate_t *gstate, double tolerance) -{ - gstate->tolerance = tolerance; - - return CAIRO_STATUS_SUCCESS; -} - -double -_cairo_gstate_get_tolerance (cairo_gstate_t *gstate) -{ - return gstate->tolerance; -} - -cairo_status_t -_cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule) -{ - gstate->fill_rule = fill_rule; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_fill_rule_t -_cairo_gstate_get_fill_rule (cairo_gstate_t *gstate) -{ - return gstate->fill_rule; -} - -cairo_status_t -_cairo_gstate_set_line_width (cairo_gstate_t *gstate, double width) -{ - gstate->stroke_style.line_width = width; - - return CAIRO_STATUS_SUCCESS; -} - -double -_cairo_gstate_get_line_width (cairo_gstate_t *gstate) -{ - return gstate->stroke_style.line_width; -} - -cairo_status_t -_cairo_gstate_set_line_cap (cairo_gstate_t *gstate, cairo_line_cap_t line_cap) -{ - gstate->stroke_style.line_cap = line_cap; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_line_cap_t -_cairo_gstate_get_line_cap (cairo_gstate_t *gstate) -{ - return gstate->stroke_style.line_cap; -} - -cairo_status_t -_cairo_gstate_set_line_join (cairo_gstate_t *gstate, cairo_line_join_t line_join) -{ - gstate->stroke_style.line_join = line_join; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_line_join_t -_cairo_gstate_get_line_join (cairo_gstate_t *gstate) -{ - return gstate->stroke_style.line_join; -} - -cairo_status_t -_cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dashes, double offset) -{ - double dash_total, on_total, off_total; - int i, j; - - free (gstate->stroke_style.dash); - - gstate->stroke_style.num_dashes = num_dashes; - - if (gstate->stroke_style.num_dashes == 0) { - gstate->stroke_style.dash = NULL; - gstate->stroke_style.dash_offset = 0.0; - return CAIRO_STATUS_SUCCESS; - } - - gstate->stroke_style.dash = _cairo_malloc_ab (gstate->stroke_style.num_dashes, sizeof (double)); - if (unlikely (gstate->stroke_style.dash == NULL)) { - gstate->stroke_style.num_dashes = 0; - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - on_total = off_total = dash_total = 0.0; - for (i = j = 0; i < num_dashes; i++) { - if (dash[i] < 0) - return _cairo_error (CAIRO_STATUS_INVALID_DASH); - - if (dash[i] == 0 && i > 0 && i < num_dashes - 1) { - if (dash[++i] < 0) - return _cairo_error (CAIRO_STATUS_INVALID_DASH); - - gstate->stroke_style.dash[j-1] += dash[i]; - gstate->stroke_style.num_dashes -= 2; - } else - gstate->stroke_style.dash[j++] = dash[i]; - - if (dash[i]) { - dash_total += dash[i]; - if ((i & 1) == 0) - on_total += dash[i]; - else - off_total += dash[i]; - } - } - - if (dash_total == 0.0) - return _cairo_error (CAIRO_STATUS_INVALID_DASH); - - /* An odd dash value indicate symmetric repeating, so the total - * is twice as long. */ - if (gstate->stroke_style.num_dashes & 1) { - dash_total *= 2; - on_total += off_total; - } - - if (dash_total - on_total < CAIRO_FIXED_ERROR_DOUBLE) { - /* Degenerate dash -> solid line */ - free (gstate->stroke_style.dash); - gstate->stroke_style.dash = NULL; - gstate->stroke_style.num_dashes = 0; - gstate->stroke_style.dash_offset = 0.0; - return CAIRO_STATUS_SUCCESS; - } - - /* The dashing code doesn't like a negative offset or a big positive - * offset, so we compute an equivalent offset which is guaranteed to be - * positive and less than twice the pattern length. */ - offset = fmod (offset, dash_total); - if (offset < 0.0) - offset += dash_total; - if (offset <= 0.0) /* Take care of -0 */ - offset = 0.0; - gstate->stroke_style.dash_offset = offset; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gstate_get_dash (cairo_gstate_t *gstate, - double *dashes, - int *num_dashes, - double *offset) -{ - if (dashes) { - memcpy (dashes, - gstate->stroke_style.dash, - sizeof (double) * gstate->stroke_style.num_dashes); - } - - if (num_dashes) - *num_dashes = gstate->stroke_style.num_dashes; - - if (offset) - *offset = gstate->stroke_style.dash_offset; -} - -cairo_status_t -_cairo_gstate_set_miter_limit (cairo_gstate_t *gstate, double limit) -{ - gstate->stroke_style.miter_limit = limit; - - return CAIRO_STATUS_SUCCESS; -} - -double -_cairo_gstate_get_miter_limit (cairo_gstate_t *gstate) -{ - return gstate->stroke_style.miter_limit; -} - -void -_cairo_gstate_get_matrix (cairo_gstate_t *gstate, cairo_matrix_t *matrix) -{ - *matrix = gstate->ctm; -} - -cairo_status_t -_cairo_gstate_translate (cairo_gstate_t *gstate, double tx, double ty) -{ - cairo_matrix_t tmp; - - if (! ISFINITE (tx) || ! ISFINITE (ty)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - _cairo_gstate_unset_scaled_font (gstate); - - cairo_matrix_init_translate (&tmp, tx, ty); - cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm); - gstate->is_identity = FALSE; - - /* paranoid check against gradual numerical instability */ - if (! _cairo_matrix_is_invertible (&gstate->ctm)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - cairo_matrix_init_translate (&tmp, -tx, -ty); - cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_scale (cairo_gstate_t *gstate, double sx, double sy) -{ - cairo_matrix_t tmp; - - if (sx * sy == 0.) /* either sx or sy is 0, or det == 0 due to underflow */ - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - if (! ISFINITE (sx) || ! ISFINITE (sy)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - _cairo_gstate_unset_scaled_font (gstate); - - cairo_matrix_init_scale (&tmp, sx, sy); - cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm); - gstate->is_identity = FALSE; - - /* paranoid check against gradual numerical instability */ - if (! _cairo_matrix_is_invertible (&gstate->ctm)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - cairo_matrix_init_scale (&tmp, 1/sx, 1/sy); - cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_rotate (cairo_gstate_t *gstate, double angle) -{ - cairo_matrix_t tmp; - - if (angle == 0.) - return CAIRO_STATUS_SUCCESS; - - if (! ISFINITE (angle)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - _cairo_gstate_unset_scaled_font (gstate); - - cairo_matrix_init_rotate (&tmp, angle); - cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm); - gstate->is_identity = FALSE; - - /* paranoid check against gradual numerical instability */ - if (! _cairo_matrix_is_invertible (&gstate->ctm)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - cairo_matrix_init_rotate (&tmp, -angle); - cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_transform (cairo_gstate_t *gstate, - const cairo_matrix_t *matrix) -{ - cairo_matrix_t tmp; - cairo_status_t status; - - if (! _cairo_matrix_is_invertible (matrix)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - if (_cairo_matrix_is_identity (matrix)) - return CAIRO_STATUS_SUCCESS; - - tmp = *matrix; - status = cairo_matrix_invert (&tmp); - if (unlikely (status)) - return status; - - _cairo_gstate_unset_scaled_font (gstate); - - cairo_matrix_multiply (&gstate->ctm, matrix, &gstate->ctm); - cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); - gstate->is_identity = FALSE; - - /* paranoid check against gradual numerical instability */ - if (! _cairo_matrix_is_invertible (&gstate->ctm)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_set_matrix (cairo_gstate_t *gstate, - const cairo_matrix_t *matrix) -{ - cairo_status_t status; - - if (memcmp (matrix, &gstate->ctm, sizeof (cairo_matrix_t)) == 0) - return CAIRO_STATUS_SUCCESS; - - if (! _cairo_matrix_is_invertible (matrix)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - if (_cairo_matrix_is_identity (matrix)) { - _cairo_gstate_identity_matrix (gstate); - return CAIRO_STATUS_SUCCESS; - } - - _cairo_gstate_unset_scaled_font (gstate); - - gstate->ctm = *matrix; - gstate->ctm_inverse = *matrix; - status = cairo_matrix_invert (&gstate->ctm_inverse); - assert (status == CAIRO_STATUS_SUCCESS); - gstate->is_identity = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gstate_identity_matrix (cairo_gstate_t *gstate) -{ - if (_cairo_matrix_is_identity (&gstate->ctm)) - return; - - _cairo_gstate_unset_scaled_font (gstate); - - cairo_matrix_init_identity (&gstate->ctm); - cairo_matrix_init_identity (&gstate->ctm_inverse); - gstate->is_identity = _cairo_matrix_is_identity (&gstate->target->device_transform); -} - -void -_cairo_gstate_user_to_device (cairo_gstate_t *gstate, double *x, double *y) -{ - cairo_matrix_transform_point (&gstate->ctm, x, y); -} - -void -_cairo_gstate_user_to_device_distance (cairo_gstate_t *gstate, - double *dx, double *dy) -{ - cairo_matrix_transform_distance (&gstate->ctm, dx, dy); -} - -void -_cairo_gstate_device_to_user (cairo_gstate_t *gstate, double *x, double *y) -{ - cairo_matrix_transform_point (&gstate->ctm_inverse, x, y); -} - -void -_cairo_gstate_device_to_user_distance (cairo_gstate_t *gstate, - double *dx, double *dy) -{ - cairo_matrix_transform_distance (&gstate->ctm_inverse, dx, dy); -} - -void -_do_cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y) -{ - cairo_matrix_transform_point (&gstate->ctm, x, y); - cairo_matrix_transform_point (&gstate->target->device_transform, x, y); -} - -void -_do_cairo_gstate_user_to_backend_distance (cairo_gstate_t *gstate, double *x, double *y) -{ - cairo_matrix_transform_distance (&gstate->ctm, x, y); - cairo_matrix_transform_distance (&gstate->target->device_transform, x, y); -} - -void -_do_cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y) -{ - cairo_matrix_transform_point (&gstate->target->device_transform_inverse, x, y); - cairo_matrix_transform_point (&gstate->ctm_inverse, x, y); -} - -void -_do_cairo_gstate_backend_to_user_distance (cairo_gstate_t *gstate, double *x, double *y) -{ - cairo_matrix_transform_distance (&gstate->target->device_transform_inverse, x, y); - cairo_matrix_transform_distance (&gstate->ctm_inverse, x, y); -} - -void -_cairo_gstate_backend_to_user_rectangle (cairo_gstate_t *gstate, - double *x1, double *y1, - double *x2, double *y2, - cairo_bool_t *is_tight) -{ - cairo_matrix_t matrix_inverse; - - if (! _cairo_matrix_is_identity (&gstate->target->device_transform_inverse) || - ! _cairo_matrix_is_identity (&gstate->ctm_inverse)) - { - cairo_matrix_multiply (&matrix_inverse, - &gstate->target->device_transform_inverse, - &gstate->ctm_inverse); - _cairo_matrix_transform_bounding_box (&matrix_inverse, - x1, y1, x2, y2, is_tight); - } - - else - { - if (is_tight) - *is_tight = TRUE; - } -} - -/* XXX: NYI -cairo_status_t -_cairo_gstate_stroke_to_path (cairo_gstate_t *gstate) -{ - cairo_status_t status; - - _cairo_pen_init (&gstate); - return CAIRO_STATUS_SUCCESS; -} -*/ - -void -_cairo_gstate_path_extents (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double *x1, double *y1, - double *x2, double *y2) -{ - cairo_box_t box; - double px1, py1, px2, py2; - - if (_cairo_path_fixed_extents (path, &box)) { - px1 = _cairo_fixed_to_double (box.p1.x); - py1 = _cairo_fixed_to_double (box.p1.y); - px2 = _cairo_fixed_to_double (box.p2.x); - py2 = _cairo_fixed_to_double (box.p2.y); - - _cairo_gstate_backend_to_user_rectangle (gstate, - &px1, &py1, &px2, &py2, - NULL); - } else { - px1 = 0.0; - py1 = 0.0; - px2 = 0.0; - py2 = 0.0; - } - - if (x1) - *x1 = px1; - if (y1) - *y1 = py1; - if (x2) - *x2 = px2; - if (y2) - *y2 = py2; -} - -static void -_cairo_gstate_copy_pattern (cairo_pattern_t *pattern, - const cairo_pattern_t *original) -{ - /* First check if the we can replace the original with a much simpler - * pattern. For example, gradients that are uniform or just have a single - * stop can sometimes be replaced with a solid. - */ - - if (_cairo_pattern_is_clear (original)) { - _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, - CAIRO_COLOR_TRANSPARENT); - return; - } - - if (original->type == CAIRO_PATTERN_TYPE_LINEAR || - original->type == CAIRO_PATTERN_TYPE_RADIAL) - { - cairo_color_t color; - if (_cairo_gradient_pattern_is_solid ((cairo_gradient_pattern_t *) original, - NULL, - &color)) - { - _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, - &color); - return; - } - } - - _cairo_pattern_init_static_copy (pattern, original); -} - -static void -_cairo_gstate_copy_transformed_pattern (cairo_gstate_t *gstate, - cairo_pattern_t *pattern, - const cairo_pattern_t *original, - const cairo_matrix_t *ctm_inverse) -{ - _cairo_gstate_copy_pattern (pattern, original); - - /* apply device_transform first so that it is transformed by ctm_inverse */ - if (original->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surface_pattern; - cairo_surface_t *surface; - - surface_pattern = (cairo_surface_pattern_t *) original; - surface = surface_pattern->surface; - - if (_cairo_surface_has_device_transform (surface)) - _cairo_pattern_pretransform (pattern, &surface->device_transform); - } - - if (! _cairo_matrix_is_identity (ctm_inverse)) - _cairo_pattern_transform (pattern, ctm_inverse); - - if (_cairo_surface_has_device_transform (gstate->target)) { - _cairo_pattern_transform (pattern, - &gstate->target->device_transform_inverse); - } -} - -static void -_cairo_gstate_copy_transformed_source (cairo_gstate_t *gstate, - cairo_pattern_t *pattern) -{ - _cairo_gstate_copy_transformed_pattern (gstate, pattern, - gstate->source, - &gstate->source_ctm_inverse); -} - -static void -_cairo_gstate_copy_transformed_mask (cairo_gstate_t *gstate, - cairo_pattern_t *pattern, - cairo_pattern_t *mask) -{ - _cairo_gstate_copy_transformed_pattern (gstate, pattern, - mask, - &gstate->ctm_inverse); -} - -static cairo_operator_t -_reduce_op (cairo_gstate_t *gstate) -{ - cairo_operator_t op; - const cairo_pattern_t *pattern; - - op = gstate->op; - if (op != CAIRO_OPERATOR_SOURCE) - return op; - - pattern = gstate->source; - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { - const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; - if (solid->color.alpha_short <= 0x00ff) { - op = CAIRO_OPERATOR_CLEAR; - } else if ((gstate->target->content & CAIRO_CONTENT_ALPHA) == 0) { - if ((solid->color.red_short | - solid->color.green_short | - solid->color.blue_short) <= 0x00ff) - { - op = CAIRO_OPERATOR_CLEAR; - } - } - } else if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - const cairo_surface_pattern_t *surface = (cairo_surface_pattern_t *) pattern; - if (surface->surface->is_clear && - surface->surface->content & CAIRO_CONTENT_ALPHA) - { - op = CAIRO_OPERATOR_CLEAR; - } - } else { - const cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern; - if (gradient->n_stops == 0) - op = CAIRO_OPERATOR_CLEAR; - } - - return op; -} - -static cairo_status_t -_cairo_gstate_get_pattern_status (const cairo_pattern_t *pattern) -{ - if (unlikely (pattern->type == CAIRO_PATTERN_TYPE_MESH && - ((const cairo_mesh_pattern_t *) pattern)->current_patch)) - { - /* If current patch != NULL, the pattern is under construction - * and cannot be used as a source */ - return CAIRO_STATUS_INVALID_MESH_CONSTRUCTION; - } - - return pattern->status; -} - -cairo_status_t -_cairo_gstate_paint (cairo_gstate_t *gstate) -{ - cairo_pattern_union_t source_pattern; - const cairo_pattern_t *pattern; - cairo_status_t status; - cairo_operator_t op; - - status = _cairo_gstate_get_pattern_status (gstate->source); - if (unlikely (status)) - return status; - - if (gstate->op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_clip_is_all_clipped (gstate->clip)) - return CAIRO_STATUS_SUCCESS; - - op = _reduce_op (gstate); - if (op == CAIRO_OPERATOR_CLEAR) { - pattern = &_cairo_pattern_clear.base; - } else { - _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); - pattern = &source_pattern.base; - } - - return _cairo_surface_paint (gstate->target, - op, pattern, - gstate->clip); -} - -cairo_status_t -_cairo_gstate_mask (cairo_gstate_t *gstate, - cairo_pattern_t *mask) -{ - cairo_pattern_union_t source_pattern, mask_pattern; - const cairo_pattern_t *source; - cairo_operator_t op; - cairo_status_t status; - - status = _cairo_gstate_get_pattern_status (mask); - if (unlikely (status)) - return status; - - status = _cairo_gstate_get_pattern_status (gstate->source); - if (unlikely (status)) - return status; - - if (gstate->op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_clip_is_all_clipped (gstate->clip)) - return CAIRO_STATUS_SUCCESS; - - assert (gstate->opacity == 1.0); - - if (_cairo_pattern_is_opaque (mask, NULL)) - return _cairo_gstate_paint (gstate); - - if (_cairo_pattern_is_clear (mask) && - _cairo_operator_bounded_by_mask (gstate->op)) - { - return CAIRO_STATUS_SUCCESS; - } - - op = _reduce_op (gstate); - if (op == CAIRO_OPERATOR_CLEAR) { - source = &_cairo_pattern_clear.base; - } else { - _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); - source = &source_pattern.base; - } - _cairo_gstate_copy_transformed_mask (gstate, &mask_pattern.base, mask); - - if (source->type == CAIRO_PATTERN_TYPE_SOLID && - mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && - _cairo_operator_bounded_by_source (op)) - { - const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) source; - cairo_color_t combined; - - if (mask_pattern.base.has_component_alpha) { -#define M(R, A, B, c) R.c = A.c * B.c - M(combined, solid->color, mask_pattern.solid.color, red); - M(combined, solid->color, mask_pattern.solid.color, green); - M(combined, solid->color, mask_pattern.solid.color, blue); - M(combined, solid->color, mask_pattern.solid.color, alpha); -#undef M - } else { - combined = solid->color; - _cairo_color_multiply_alpha (&combined, mask_pattern.solid.color.alpha); - } - - _cairo_pattern_init_solid (&source_pattern.solid, &combined); - - status = _cairo_surface_paint (gstate->target, op, - &source_pattern.base, - gstate->clip); - } - else - { - status = _cairo_surface_mask (gstate->target, op, - source, - &mask_pattern.base, - gstate->clip); - } - - return status; -} - -cairo_status_t -_cairo_gstate_stroke (cairo_gstate_t *gstate, cairo_path_fixed_t *path) -{ - cairo_pattern_union_t source_pattern; - cairo_stroke_style_t style; - double dash[2]; - cairo_status_t status; - cairo_matrix_t aggregate_transform; - cairo_matrix_t aggregate_transform_inverse; - - status = _cairo_gstate_get_pattern_status (gstate->source); - if (unlikely (status)) - return status; - - if (gstate->op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (gstate->stroke_style.line_width <= 0.0) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_clip_is_all_clipped (gstate->clip)) - return CAIRO_STATUS_SUCCESS; - - assert (gstate->opacity == 1.0); - - cairo_matrix_multiply (&aggregate_transform, - &gstate->ctm, - &gstate->target->device_transform); - cairo_matrix_multiply (&aggregate_transform_inverse, - &gstate->target->device_transform_inverse, - &gstate->ctm_inverse); - - memcpy (&style, &gstate->stroke_style, sizeof (gstate->stroke_style)); - if (_cairo_stroke_style_dash_can_approximate (&gstate->stroke_style, &aggregate_transform, gstate->tolerance)) { - style.dash = dash; - _cairo_stroke_style_dash_approximate (&gstate->stroke_style, &gstate->ctm, gstate->tolerance, - &style.dash_offset, - style.dash, - &style.num_dashes); - } - - _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); - - return _cairo_surface_stroke (gstate->target, - gstate->op, - &source_pattern.base, - path, - &style, - &aggregate_transform, - &aggregate_transform_inverse, - gstate->tolerance, - gstate->antialias, - gstate->clip); -} - -cairo_status_t -_cairo_gstate_in_stroke (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double x, - double y, - cairo_bool_t *inside_ret) -{ - cairo_status_t status; - cairo_rectangle_int_t extents; - cairo_box_t limit; - cairo_traps_t traps; - - if (gstate->stroke_style.line_width <= 0.0) { - *inside_ret = FALSE; - return CAIRO_STATUS_SUCCESS; - } - - _cairo_gstate_user_to_backend (gstate, &x, &y); - - /* Before we perform the expensive stroke analysis, - * check whether the point is within the extents of the path. - */ - _cairo_path_fixed_approximate_stroke_extents (path, - &gstate->stroke_style, - &gstate->ctm, - &extents); - if (x < extents.x || x > extents.x + extents.width || - y < extents.y || y > extents.y + extents.height) - { - *inside_ret = FALSE; - return CAIRO_STATUS_SUCCESS; - } - - limit.p1.x = _cairo_fixed_from_double (x) - 1; - limit.p1.y = _cairo_fixed_from_double (y) - 1; - limit.p2.x = limit.p1.x + 2; - limit.p2.y = limit.p1.y + 2; - - _cairo_traps_init (&traps); - _cairo_traps_limit (&traps, &limit, 1); - - status = _cairo_path_fixed_stroke_polygon_to_traps (path, - &gstate->stroke_style, - &gstate->ctm, - &gstate->ctm_inverse, - gstate->tolerance, - &traps); - if (unlikely (status)) - goto BAIL; - - *inside_ret = _cairo_traps_contain (&traps, x, y); - -BAIL: - _cairo_traps_fini (&traps); - - return status; -} - -cairo_status_t -_cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path) -{ - cairo_status_t status; - - status = _cairo_gstate_get_pattern_status (gstate->source); - if (unlikely (status)) - return status; - - if (gstate->op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_clip_is_all_clipped (gstate->clip)) - return CAIRO_STATUS_SUCCESS; - - assert (gstate->opacity == 1.0); - - if (_cairo_path_fixed_fill_is_empty (path)) { - if (_cairo_operator_bounded_by_mask (gstate->op)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_paint (gstate->target, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - gstate->clip); - } else { - cairo_pattern_union_t source_pattern; - const cairo_pattern_t *pattern; - cairo_operator_t op; - cairo_rectangle_int_t extents; - cairo_box_t box; - - op = _reduce_op (gstate); - if (op == CAIRO_OPERATOR_CLEAR) { - pattern = &_cairo_pattern_clear.base; - } else { - _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); - pattern = &source_pattern.base; - } - - /* Toolkits often paint the entire background with a fill */ - if (_cairo_surface_get_extents (gstate->target, &extents) && - _cairo_path_fixed_is_box (path, &box) && - box.p1.x <= _cairo_fixed_from_int (extents.x) && - box.p1.y <= _cairo_fixed_from_int (extents.y) && - box.p2.x >= _cairo_fixed_from_int (extents.x + extents.width) && - box.p2.y >= _cairo_fixed_from_int (extents.y + extents.height)) - { - status = _cairo_surface_paint (gstate->target, op, pattern, - gstate->clip); - } - else - { - status = _cairo_surface_fill (gstate->target, op, pattern, - path, - gstate->fill_rule, - gstate->tolerance, - gstate->antialias, - gstate->clip); - } - } - - return status; -} - -cairo_bool_t -_cairo_gstate_in_fill (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double x, - double y) -{ - _cairo_gstate_user_to_backend (gstate, &x, &y); - - return _cairo_path_fixed_in_fill (path, - gstate->fill_rule, - gstate->tolerance, - x, y); -} - -cairo_bool_t -_cairo_gstate_in_clip (cairo_gstate_t *gstate, - double x, - double y) -{ - cairo_clip_t *clip = gstate->clip; - int i; - - if (_cairo_clip_is_all_clipped (clip)) - return FALSE; - - if (clip == NULL) - return TRUE; - - _cairo_gstate_user_to_backend (gstate, &x, &y); - - if (x < clip->extents.x || - x >= clip->extents.x + clip->extents.width || - y < clip->extents.y || - y >= clip->extents.y + clip->extents.height) - { - return FALSE; - } - - if (clip->num_boxes) { - int fx, fy; - - fx = _cairo_fixed_from_double (x); - fy = _cairo_fixed_from_double (y); - for (i = 0; i < clip->num_boxes; i++) { - if (fx >= clip->boxes[i].p1.x && fx <= clip->boxes[i].p2.x && - fy >= clip->boxes[i].p1.y && fy <= clip->boxes[i].p2.y) - break; - } - if (i == clip->num_boxes) - return FALSE; - } - - if (clip->path) { - cairo_clip_path_t *clip_path = clip->path; - do { - if (! _cairo_path_fixed_in_fill (&clip_path->path, - clip_path->fill_rule, - clip_path->tolerance, - x, y)) - return FALSE; - } while ((clip_path = clip_path->prev) != NULL); - } - - return TRUE; -} - -cairo_status_t -_cairo_gstate_copy_page (cairo_gstate_t *gstate) -{ - cairo_surface_copy_page (gstate->target); - return cairo_surface_status (gstate->target); -} - -cairo_status_t -_cairo_gstate_show_page (cairo_gstate_t *gstate) -{ - cairo_surface_show_page (gstate->target); - return cairo_surface_status (gstate->target); -} - -static void -_cairo_gstate_extents_to_user_rectangle (cairo_gstate_t *gstate, - const cairo_box_t *extents, - double *x1, double *y1, - double *x2, double *y2) -{ - double px1, py1, px2, py2; - - px1 = _cairo_fixed_to_double (extents->p1.x); - py1 = _cairo_fixed_to_double (extents->p1.y); - px2 = _cairo_fixed_to_double (extents->p2.x); - py2 = _cairo_fixed_to_double (extents->p2.y); - - _cairo_gstate_backend_to_user_rectangle (gstate, - &px1, &py1, &px2, &py2, - NULL); - if (x1) - *x1 = px1; - if (y1) - *y1 = py1; - if (x2) - *x2 = px2; - if (y2) - *y2 = py2; -} - -cairo_status_t -_cairo_gstate_stroke_extents (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double *x1, double *y1, - double *x2, double *y2) -{ - cairo_int_status_t status; - cairo_box_t extents; - cairo_bool_t empty; - - if (x1) - *x1 = 0.0; - if (y1) - *y1 = 0.0; - if (x2) - *x2 = 0.0; - if (y2) - *y2 = 0.0; - - if (gstate->stroke_style.line_width <= 0.0) - return CAIRO_STATUS_SUCCESS; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_stroke_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init (&boxes); - status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, - &gstate->stroke_style, - &gstate->ctm, - gstate->antialias, - &boxes); - empty = boxes.num_boxes == 0; - if (! empty) - _cairo_boxes_extents (&boxes, &extents); - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_polygon_t polygon; - - _cairo_polygon_init (&polygon, NULL, 0); - status = _cairo_path_fixed_stroke_to_polygon (path, - &gstate->stroke_style, - &gstate->ctm, - &gstate->ctm_inverse, - gstate->tolerance, - &polygon); - empty = polygon.num_edges == 0; - if (! empty) - extents = polygon.extents; - _cairo_polygon_fini (&polygon); - } - if (! empty) { - _cairo_gstate_extents_to_user_rectangle (gstate, &extents, - x1, y1, x2, y2); - } - - return status; -} - -cairo_status_t -_cairo_gstate_fill_extents (cairo_gstate_t *gstate, - cairo_path_fixed_t *path, - double *x1, double *y1, - double *x2, double *y2) -{ - cairo_status_t status; - cairo_box_t extents; - cairo_bool_t empty; - - if (x1) - *x1 = 0.0; - if (y1) - *y1 = 0.0; - if (x2) - *x2 = 0.0; - if (y2) - *y2 = 0.0; - - if (_cairo_path_fixed_fill_is_empty (path)) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_path_fixed_fill_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init (&boxes); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - gstate->fill_rule, - gstate->antialias, - &boxes); - empty = boxes.num_boxes == 0; - if (! empty) - _cairo_boxes_extents (&boxes, &extents); - - _cairo_boxes_fini (&boxes); - } else { - cairo_traps_t traps; - - _cairo_traps_init (&traps); - - status = _cairo_path_fixed_fill_to_traps (path, - gstate->fill_rule, - gstate->tolerance, - &traps); - empty = traps.num_traps == 0; - if (! empty) - _cairo_traps_extents (&traps, &extents); - - _cairo_traps_fini (&traps); - } - - if (! empty) { - _cairo_gstate_extents_to_user_rectangle (gstate, &extents, - x1, y1, x2, y2); - } - - return status; -} - -cairo_status_t -_cairo_gstate_reset_clip (cairo_gstate_t *gstate) -{ - _cairo_clip_destroy (gstate->clip); - gstate->clip = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path) -{ - gstate->clip = - _cairo_clip_intersect_path (gstate->clip, - path, - gstate->fill_rule, - gstate->tolerance, - gstate->antialias); - /* XXX */ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_gstate_int_clip_extents (cairo_gstate_t *gstate, - cairo_rectangle_int_t *extents) -{ - cairo_bool_t is_bounded; - - is_bounded = _cairo_surface_get_extents (gstate->target, extents); - - if (gstate->clip) { - _cairo_rectangle_intersect (extents, - _cairo_clip_get_extents (gstate->clip)); - is_bounded = TRUE; - } - - return is_bounded; -} - -cairo_bool_t -_cairo_gstate_clip_extents (cairo_gstate_t *gstate, - double *x1, - double *y1, - double *x2, - double *y2) -{ - cairo_rectangle_int_t extents; - double px1, py1, px2, py2; - - if (! _cairo_gstate_int_clip_extents (gstate, &extents)) - return FALSE; - - px1 = extents.x; - py1 = extents.y; - px2 = extents.x + (int) extents.width; - py2 = extents.y + (int) extents.height; - - _cairo_gstate_backend_to_user_rectangle (gstate, - &px1, &py1, &px2, &py2, - NULL); - - if (x1) - *x1 = px1; - if (y1) - *y1 = py1; - if (x2) - *x2 = px2; - if (y2) - *y2 = py2; - - return TRUE; -} - -cairo_rectangle_list_t* -_cairo_gstate_copy_clip_rectangle_list (cairo_gstate_t *gstate) -{ - cairo_rectangle_int_t extents; - cairo_rectangle_list_t *list; - cairo_clip_t *clip; - - if (_cairo_surface_get_extents (gstate->target, &extents)) - clip = _cairo_clip_copy_intersect_rectangle (gstate->clip, &extents); - else - clip = gstate->clip; - - list = _cairo_clip_copy_rectangle_list (clip, gstate); - - if (clip != gstate->clip) - _cairo_clip_destroy (clip); - - return list; -} - -static void -_cairo_gstate_unset_scaled_font (cairo_gstate_t *gstate) -{ - if (gstate->scaled_font == NULL) - return; - - if (gstate->previous_scaled_font != NULL) - cairo_scaled_font_destroy (gstate->previous_scaled_font); - - gstate->previous_scaled_font = gstate->scaled_font; - gstate->scaled_font = NULL; -} - -cairo_status_t -_cairo_gstate_set_font_size (cairo_gstate_t *gstate, - double size) -{ - _cairo_gstate_unset_scaled_font (gstate); - - cairo_matrix_init_scale (&gstate->font_matrix, size, size); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_set_font_matrix (cairo_gstate_t *gstate, - const cairo_matrix_t *matrix) -{ - if (memcmp (matrix, &gstate->font_matrix, sizeof (cairo_matrix_t)) == 0) - return CAIRO_STATUS_SUCCESS; - - _cairo_gstate_unset_scaled_font (gstate); - - gstate->font_matrix = *matrix; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_gstate_get_font_matrix (cairo_gstate_t *gstate, - cairo_matrix_t *matrix) -{ - *matrix = gstate->font_matrix; -} - -void -_cairo_gstate_set_font_options (cairo_gstate_t *gstate, - const cairo_font_options_t *options) -{ - if (memcmp (options, &gstate->font_options, sizeof (cairo_font_options_t)) == 0) - return; - - _cairo_gstate_unset_scaled_font (gstate); - - _cairo_font_options_init_copy (&gstate->font_options, options); -} - -void -_cairo_gstate_get_font_options (cairo_gstate_t *gstate, - cairo_font_options_t *options) -{ - *options = gstate->font_options; -} - -cairo_status_t -_cairo_gstate_get_font_face (cairo_gstate_t *gstate, - cairo_font_face_t **font_face) -{ - cairo_status_t status; - - status = _cairo_gstate_ensure_font_face (gstate); - if (unlikely (status)) - return status; - - *font_face = gstate->font_face; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_get_scaled_font (cairo_gstate_t *gstate, - cairo_scaled_font_t **scaled_font) -{ - cairo_status_t status; - - status = _cairo_gstate_ensure_scaled_font (gstate); - if (unlikely (status)) - return status; - - *scaled_font = gstate->scaled_font; - - return CAIRO_STATUS_SUCCESS; -} - -/* - * Like everything else in this file, fonts involve Too Many Coordinate Spaces; - * it is easy to get confused about what's going on. - * - * The user's view - * --------------- - * - * Users ask for things in user space. When cairo starts, a user space unit - * is about 1/96 inch, which is similar to (but importantly different from) - * the normal "point" units most users think in terms of. When a user - * selects a font, its scale is set to "one user unit". The user can then - * independently scale the user coordinate system *or* the font matrix, in - * order to adjust the rendered size of the font. - * - * Metrics are returned in user space, whether they are obtained from - * the currently selected font in a #cairo_t or from a #cairo_scaled_font_t - * which is a font specialized to a particular scale matrix, CTM, and target - * surface. - * - * The font's view - * --------------- - * - * Fonts are designed and stored (in say .ttf files) in "font space", which - * describes an "EM Square" (a design tile) and has some abstract number - * such as 1000, 1024, or 2048 units per "EM". This is basically an - * uninteresting space for us, but we need to remember that it exists. - * - * Font resources (from libraries or operating systems) render themselves - * to a particular device. Since they do not want to make most programmers - * worry about the font design space, the scaling API is simplified to - * involve just telling the font the required pixel size of the EM square - * (that is, in device space). - * - * - * Cairo's gstate view - * ------------------- - * - * In addition to the CTM and CTM inverse, we keep a matrix in the gstate - * called the "font matrix" which describes the user's most recent - * font-scaling or font-transforming request. This is kept in terms of an - * abstract scale factor, composed with the CTM and used to set the font's - * pixel size. So if the user asks to "scale the font by 12", the matrix - * is: - * - * [ 12.0, 0.0, 0.0, 12.0, 0.0, 0.0 ] - * - * It is an affine matrix, like all cairo matrices, where its tx and ty - * components are used to "nudging" fonts around and are handled in gstate - * and then ignored by the "scaled-font" layer. - * - * In order to perform any action on a font, we must build an object - * called a #cairo_font_scale_t; this contains the central 2x2 matrix - * resulting from "font matrix * CTM" (sans the font matrix translation - * components as stated in the previous paragraph). - * - * We pass this to the font when making requests of it, which causes it to - * reply for a particular [user request, device] combination, under the CTM - * (to accommodate the "zoom in" == "bigger fonts" issue above). - * - * The other terms in our communication with the font are therefore in - * device space. When we ask it to perform text->glyph conversion, it will - * produce a glyph string in device space. Glyph vectors we pass to it for - * measuring or rendering should be in device space. The metrics which we - * get back from the font will be in device space. The contents of the - * global glyph image cache will be in device space. - * - * - * Cairo's public view - * ------------------- - * - * Since the values entering and leaving via public API calls are in user - * space, the gstate functions typically need to multiply arguments by the - * CTM (for user-input glyph vectors), and return values by the CTM inverse - * (for font responses such as metrics or glyph vectors). - * - */ - -static cairo_status_t -_cairo_gstate_ensure_font_face (cairo_gstate_t *gstate) -{ - cairo_font_face_t *font_face; - - if (gstate->font_face != NULL) - return gstate->font_face->status; - - - font_face = cairo_toy_font_face_create (CAIRO_FONT_FAMILY_DEFAULT, - CAIRO_FONT_SLANT_DEFAULT, - CAIRO_FONT_WEIGHT_DEFAULT); - if (font_face->status) - return font_face->status; - - gstate->font_face = font_face; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate) -{ - cairo_status_t status; - cairo_font_options_t options; - cairo_scaled_font_t *scaled_font; - cairo_matrix_t font_ctm; - - if (gstate->scaled_font != NULL) - return gstate->scaled_font->status; - - status = _cairo_gstate_ensure_font_face (gstate); - if (unlikely (status)) - return status; - - cairo_surface_get_font_options (gstate->target, &options); - cairo_font_options_merge (&options, &gstate->font_options); - - cairo_matrix_multiply (&font_ctm, - &gstate->ctm, - &gstate->target->device_transform); - - scaled_font = cairo_scaled_font_create (gstate->font_face, - &gstate->font_matrix, - &font_ctm, - &options); - - status = cairo_scaled_font_status (scaled_font); - if (unlikely (status)) - return status; - - gstate->scaled_font = scaled_font; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_get_font_extents (cairo_gstate_t *gstate, - cairo_font_extents_t *extents) -{ - cairo_status_t status = _cairo_gstate_ensure_scaled_font (gstate); - if (unlikely (status)) - return status; - - cairo_scaled_font_extents (gstate->scaled_font, extents); - - return cairo_scaled_font_status (gstate->scaled_font); -} - -cairo_status_t -_cairo_gstate_set_font_face (cairo_gstate_t *gstate, - cairo_font_face_t *font_face) -{ - if (font_face && font_face->status) - return _cairo_error (font_face->status); - - if (font_face == gstate->font_face) - return CAIRO_STATUS_SUCCESS; - - cairo_font_face_destroy (gstate->font_face); - gstate->font_face = cairo_font_face_reference (font_face); - - _cairo_gstate_unset_scaled_font (gstate); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_gstate_glyph_extents (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents) -{ - cairo_status_t status; - - status = _cairo_gstate_ensure_scaled_font (gstate); - if (unlikely (status)) - return status; - - cairo_scaled_font_glyph_extents (gstate->scaled_font, - glyphs, num_glyphs, - extents); - - return cairo_scaled_font_status (gstate->scaled_font); -} - -cairo_status_t -_cairo_gstate_show_text_glyphs (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_glyph_text_info_t *info) -{ - cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; - cairo_text_cluster_t stack_transformed_clusters[CAIRO_STACK_ARRAY_LENGTH (cairo_text_cluster_t)]; - cairo_pattern_union_t source_pattern; - cairo_glyph_t *transformed_glyphs; - const cairo_pattern_t *pattern; - cairo_text_cluster_t *transformed_clusters; - cairo_operator_t op; - cairo_status_t status; - - status = _cairo_gstate_get_pattern_status (gstate->source); - if (unlikely (status)) - return status; - - if (gstate->op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_clip_is_all_clipped (gstate->clip)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_gstate_ensure_scaled_font (gstate); - if (unlikely (status)) - return status; - - transformed_glyphs = stack_transformed_glyphs; - transformed_clusters = stack_transformed_clusters; - - if (num_glyphs > ARRAY_LENGTH (stack_transformed_glyphs)) { - transformed_glyphs = cairo_glyph_allocate (num_glyphs); - if (unlikely (transformed_glyphs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - if (info != NULL) { - if (info->num_clusters > ARRAY_LENGTH (stack_transformed_clusters)) { - transformed_clusters = cairo_text_cluster_allocate (info->num_clusters); - if (unlikely (transformed_clusters == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_GLYPHS; - } - } - - _cairo_gstate_transform_glyphs_to_backend (gstate, - glyphs, num_glyphs, - info->clusters, - info->num_clusters, - info->cluster_flags, - transformed_glyphs, - &num_glyphs, - transformed_clusters); - } else { - _cairo_gstate_transform_glyphs_to_backend (gstate, - glyphs, num_glyphs, - NULL, 0, 0, - transformed_glyphs, - &num_glyphs, - NULL); - } - - if (num_glyphs == 0) - goto CLEANUP_GLYPHS; - - op = _reduce_op (gstate); - if (op == CAIRO_OPERATOR_CLEAR) { - pattern = &_cairo_pattern_clear.base; - } else { - _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); - pattern = &source_pattern.base; - } - - /* For really huge font sizes, we can just do path;fill instead of - * show_glyphs, as show_glyphs would put excess pressure on the cache, - * and moreover, not all components below us correctly handle huge font - * sizes. I wanted to set the limit at 256. But alas, seems like cairo's - * rasterizer is something like ten times slower than freetype's for huge - * sizes. So, no win just yet. For now, do it for insanely-huge sizes, - * just to make sure we don't make anyone unhappy. When we get a really - * fast rasterizer in cairo, we may want to readjust this. - * - * Needless to say, do this only if show_text_glyphs is not available. */ - if (cairo_surface_has_show_text_glyphs (gstate->target) || - _cairo_scaled_font_get_max_scale (gstate->scaled_font) <= 10240) - { - - if (info != NULL) { - status = _cairo_surface_show_text_glyphs (gstate->target, op, pattern, - info->utf8, info->utf8_len, - transformed_glyphs, num_glyphs, - transformed_clusters, info->num_clusters, - info->cluster_flags, - gstate->scaled_font, - gstate->clip); - } else { - status = _cairo_surface_show_text_glyphs (gstate->target, op, pattern, - NULL, 0, - transformed_glyphs, num_glyphs, - NULL, 0, 0, - gstate->scaled_font, - gstate->clip); - } - } - else - { - cairo_path_fixed_t path; - - _cairo_path_fixed_init (&path); - - status = _cairo_scaled_font_glyph_path (gstate->scaled_font, - transformed_glyphs, num_glyphs, - &path); - - if (status == CAIRO_STATUS_SUCCESS) { - status = _cairo_surface_fill (gstate->target, op, pattern, - &path, - CAIRO_FILL_RULE_WINDING, - gstate->tolerance, - gstate->scaled_font->options.antialias, - gstate->clip); - } - - _cairo_path_fixed_fini (&path); - } - -CLEANUP_GLYPHS: - if (transformed_glyphs != stack_transformed_glyphs) - cairo_glyph_free (transformed_glyphs); - if (transformed_clusters != stack_transformed_clusters) - cairo_text_cluster_free (transformed_clusters); - - return status; -} - -cairo_status_t -_cairo_gstate_glyph_path (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_path_fixed_t *path) -{ - cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; - cairo_glyph_t *transformed_glyphs; - cairo_status_t status; - - status = _cairo_gstate_ensure_scaled_font (gstate); - if (unlikely (status)) - return status; - - if (num_glyphs < ARRAY_LENGTH (stack_transformed_glyphs)) { - transformed_glyphs = stack_transformed_glyphs; - } else { - transformed_glyphs = cairo_glyph_allocate (num_glyphs); - if (unlikely (transformed_glyphs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_gstate_transform_glyphs_to_backend (gstate, - glyphs, num_glyphs, - NULL, 0, 0, - transformed_glyphs, - &num_glyphs, NULL); - - status = _cairo_scaled_font_glyph_path (gstate->scaled_font, - transformed_glyphs, num_glyphs, - path); - - if (transformed_glyphs != stack_transformed_glyphs) - cairo_glyph_free (transformed_glyphs); - - return status; -} - -cairo_status_t -_cairo_gstate_set_antialias (cairo_gstate_t *gstate, - cairo_antialias_t antialias) -{ - gstate->antialias = antialias; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_antialias_t -_cairo_gstate_get_antialias (cairo_gstate_t *gstate) -{ - return gstate->antialias; -} - -/** - * _cairo_gstate_transform_glyphs_to_backend: - * @gstate: a #cairo_gstate_t - * @glyphs: the array of #cairo_glyph_t objects to be transformed - * @num_glyphs: the number of elements in @glyphs - * @transformed_glyphs: a pre-allocated array of at least @num_glyphs - * #cairo_glyph_t objects - * @num_transformed_glyphs: the number of elements in @transformed_glyphs - * after dropping out of bounds glyphs, or %NULL if glyphs shouldn't be - * dropped - * - * Transform an array of glyphs to backend space by first adding the offset - * of the font matrix, then transforming from user space to backend space. - * The result of the transformation is placed in @transformed_glyphs. - * - * This also uses information from the scaled font and the surface to - * cull/drop glyphs that will not be visible. - **/ -static void -_cairo_gstate_transform_glyphs_to_backend (cairo_gstate_t *gstate, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_glyph_t *transformed_glyphs, - int *num_transformed_glyphs, - cairo_text_cluster_t *transformed_clusters) -{ - cairo_rectangle_int_t surface_extents; - cairo_matrix_t *ctm = &gstate->ctm; - cairo_matrix_t *font_matrix = &gstate->font_matrix; - cairo_matrix_t *device_transform = &gstate->target->device_transform; - cairo_bool_t drop = FALSE; - double x1 = 0, x2 = 0, y1 = 0, y2 = 0; - int i, j, k; - - drop = TRUE; - if (! _cairo_gstate_int_clip_extents (gstate, &surface_extents)) { - drop = FALSE; /* unbounded surface */ - } else { - double scale10 = 10 * _cairo_scaled_font_get_max_scale (gstate->scaled_font); - if (surface_extents.width == 0 || surface_extents.height == 0) { - /* No visible area. Don't draw anything */ - *num_transformed_glyphs = 0; - return; - } - /* XXX We currently drop any glyphs that has its position outside - * of the surface boundaries by a safety margin depending on the - * font scale. This however can fail in extreme cases where the - * font has really long swashes for example... We can correctly - * handle that by looking the glyph up and using its device bbox - * to device if it's going to be visible, but I'm not inclined to - * do that now. - */ - x1 = surface_extents.x - scale10; - y1 = surface_extents.y - scale10; - x2 = surface_extents.x + (int) surface_extents.width + scale10; - y2 = surface_extents.y + (int) surface_extents.height + scale10; - } - - if (!drop) - *num_transformed_glyphs = num_glyphs; - -#define KEEP_GLYPH(glyph) (x1 <= glyph.x && glyph.x <= x2 && y1 <= glyph.y && glyph.y <= y2) - - j = 0; - if (_cairo_matrix_is_identity (ctm) && - _cairo_matrix_is_identity (device_transform) && - font_matrix->x0 == 0 && font_matrix->y0 == 0) - { - if (! drop) { - memcpy (transformed_glyphs, glyphs, - num_glyphs * sizeof (cairo_glyph_t)); - memcpy (transformed_clusters, clusters, - num_clusters * sizeof (cairo_text_cluster_t)); - j = num_glyphs; - } else if (num_clusters == 0) { - for (i = 0; i < num_glyphs; i++) { - transformed_glyphs[j].index = glyphs[i].index; - transformed_glyphs[j].x = glyphs[i].x; - transformed_glyphs[j].y = glyphs[i].y; - if (KEEP_GLYPH (transformed_glyphs[j])) - j++; - } - } else { - const cairo_glyph_t *cur_glyph; - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph = glyphs + num_glyphs - 1; - else - cur_glyph = glyphs; - - for (i = 0; i < num_clusters; i++) { - cairo_bool_t cluster_visible = FALSE; - - for (k = 0; k < clusters[i].num_glyphs; k++) { - transformed_glyphs[j+k].index = cur_glyph->index; - transformed_glyphs[j+k].x = cur_glyph->x; - transformed_glyphs[j+k].y = cur_glyph->y; - if (KEEP_GLYPH (transformed_glyphs[j+k])) - cluster_visible = TRUE; - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph--; - else - cur_glyph++; - } - - transformed_clusters[i] = clusters[i]; - if (cluster_visible) - j += k; - else - transformed_clusters[i].num_glyphs = 0; - } - } - } - else if (_cairo_matrix_is_translation (ctm) && - _cairo_matrix_is_translation (device_transform)) - { - double tx = font_matrix->x0 + ctm->x0 + device_transform->x0; - double ty = font_matrix->y0 + ctm->y0 + device_transform->y0; - - if (! drop || num_clusters == 0) { - for (i = 0; i < num_glyphs; i++) { - transformed_glyphs[j].index = glyphs[i].index; - transformed_glyphs[j].x = glyphs[i].x + tx; - transformed_glyphs[j].y = glyphs[i].y + ty; - if (!drop || KEEP_GLYPH (transformed_glyphs[j])) - j++; - } - memcpy (transformed_clusters, clusters, - num_clusters * sizeof (cairo_text_cluster_t)); - } else { - const cairo_glyph_t *cur_glyph; - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph = glyphs + num_glyphs - 1; - else - cur_glyph = glyphs; - - for (i = 0; i < num_clusters; i++) { - cairo_bool_t cluster_visible = FALSE; - - for (k = 0; k < clusters[i].num_glyphs; k++) { - transformed_glyphs[j+k].index = cur_glyph->index; - transformed_glyphs[j+k].x = cur_glyph->x + tx; - transformed_glyphs[j+k].y = cur_glyph->y + ty; - if (KEEP_GLYPH (transformed_glyphs[j+k])) - cluster_visible = TRUE; - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph--; - else - cur_glyph++; - } - - transformed_clusters[i] = clusters[i]; - if (cluster_visible) - j += k; - else - transformed_clusters[i].num_glyphs = 0; - } - } - } - else - { - cairo_matrix_t aggregate_transform; - - cairo_matrix_init_translate (&aggregate_transform, - gstate->font_matrix.x0, - gstate->font_matrix.y0); - cairo_matrix_multiply (&aggregate_transform, - &aggregate_transform, ctm); - cairo_matrix_multiply (&aggregate_transform, - &aggregate_transform, device_transform); - - if (! drop || num_clusters == 0) { - for (i = 0; i < num_glyphs; i++) { - transformed_glyphs[j] = glyphs[i]; - cairo_matrix_transform_point (&aggregate_transform, - &transformed_glyphs[j].x, - &transformed_glyphs[j].y); - if (! drop || KEEP_GLYPH (transformed_glyphs[j])) - j++; - } - memcpy (transformed_clusters, clusters, - num_clusters * sizeof (cairo_text_cluster_t)); - } else { - const cairo_glyph_t *cur_glyph; - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph = glyphs + num_glyphs - 1; - else - cur_glyph = glyphs; - - for (i = 0; i < num_clusters; i++) { - cairo_bool_t cluster_visible = FALSE; - for (k = 0; k < clusters[i].num_glyphs; k++) { - transformed_glyphs[j+k] = *cur_glyph; - cairo_matrix_transform_point (&aggregate_transform, - &transformed_glyphs[j+k].x, - &transformed_glyphs[j+k].y); - if (KEEP_GLYPH (transformed_glyphs[j+k])) - cluster_visible = TRUE; - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph--; - else - cur_glyph++; - } - - transformed_clusters[i] = clusters[i]; - if (cluster_visible) - j += k; - else - transformed_clusters[i].num_glyphs = 0; - } - } - } - *num_transformed_glyphs = j; - - if (num_clusters != 0 && cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) { - for (i = 0; i < --j; i++) { - cairo_glyph_t tmp; - - tmp = transformed_glyphs[i]; - transformed_glyphs[i] = transformed_glyphs[j]; - transformed_glyphs[j] = tmp; - } - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash-private.h deleted file mode 100644 index 30e51ffe669..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash-private.h +++ /dev/null @@ -1,87 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc. - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Keith Packard - * Graydon Hoare - * Carl Worth - */ - -#ifndef CAIRO_HASH_PRIVATE_H -#define CAIRO_HASH_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-types-private.h" - -/* XXX: I'd like this file to be self-contained in terms of - * includeability, but that's not really possible with the current - * monolithic cairoint.h. So, for now, just include cairoint.h instead - * if you want to include this file. */ - -typedef cairo_bool_t -(*cairo_hash_keys_equal_func_t) (const void *key_a, const void *key_b); - -typedef cairo_bool_t -(*cairo_hash_predicate_func_t) (const void *entry); - -typedef void -(*cairo_hash_callback_func_t) (void *entry, - void *closure); - -cairo_private cairo_hash_table_t * -_cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal); - -cairo_private void -_cairo_hash_table_destroy (cairo_hash_table_t *hash_table); - -cairo_private void * -_cairo_hash_table_lookup (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key); - -cairo_private void * -_cairo_hash_table_random_entry (cairo_hash_table_t *hash_table, - cairo_hash_predicate_func_t predicate); - -cairo_private cairo_status_t -_cairo_hash_table_insert (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *entry); - -cairo_private void -_cairo_hash_table_remove (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key); - -cairo_private void -_cairo_hash_table_foreach (cairo_hash_table_t *hash_table, - cairo_hash_callback_func_t hash_callback, - void *closure); - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash.c deleted file mode 100644 index 928c74b8bd6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hash.c +++ /dev/null @@ -1,578 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc. - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Keith Packard - * Graydon Hoare - * Carl Worth - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -/* - * An entry can be in one of three states: - * - * FREE: Entry has never been used, terminates all searches. - * Appears in the table as a %NULL pointer. - * - * DEAD: Entry had been live in the past. A dead entry can be reused - * but does not terminate a search for an exact entry. - * Appears in the table as a pointer to DEAD_ENTRY. - * - * LIVE: Entry is currently being used. - * Appears in the table as any non-%NULL, non-DEAD_ENTRY pointer. - */ - -#define DEAD_ENTRY ((cairo_hash_entry_t *) 0x1) - -#define ENTRY_IS_FREE(entry) ((entry) == NULL) -#define ENTRY_IS_DEAD(entry) ((entry) == DEAD_ENTRY) -#define ENTRY_IS_LIVE(entry) ((entry) > DEAD_ENTRY) - -/* - * This table is open-addressed with double hashing. Each table size - * is a prime and it makes for the "first" hash modulus; a second - * prime (2 less than the first prime) serves as the "second" hash - * modulus, which is smaller and thus guarantees a complete - * permutation of table indices. - * - * Hash tables are rehashed in order to keep between 12.5% and 50% - * entries in the hash table alive and at least 25% free. When table - * size is changed, the new table has about 25% live elements. - * - * The free entries guarantee an expected constant-time lookup. - * Doubling/halving the table in the described fashion guarantees - * amortized O(1) insertion/removal. - * - * This structure, and accompanying table, is borrowed/modified from the - * file xserver/render/glyph.c in the freedesktop.org x server, with - * permission (and suggested modification of doubling sizes) by Keith - * Packard. - */ - -static const unsigned long hash_table_sizes[] = { - 43, - 73, - 151, - 283, - 571, - 1153, - 2269, - 4519, - 9013, - 18043, - 36109, - 72091, - 144409, - 288361, - 576883, - 1153459, - 2307163, - 4613893, - 9227641, - 18455029, - 36911011, - 73819861, - 147639589, - 295279081, - 590559793 -}; - -struct _cairo_hash_table { - cairo_hash_keys_equal_func_t keys_equal; - - cairo_hash_entry_t *cache[32]; - - const unsigned long *table_size; - cairo_hash_entry_t **entries; - - unsigned long live_entries; - unsigned long free_entries; - unsigned long iterating; /* Iterating, no insert, no resize */ -}; - -/** - * _cairo_hash_table_uid_keys_equal: - * @key_a: the first key to be compared - * @key_b: the second key to be compared - * - * Provides a #cairo_hash_keys_equal_func_t which always returns - * %TRUE. This is useful to create hash tables using keys whose hash - * completely describes the key, because in this special case - * comparing the hashes is sufficient to guarantee that the keys are - * equal. - * - * Return value: %TRUE. - **/ -static cairo_bool_t -_cairo_hash_table_uid_keys_equal (const void *key_a, const void *key_b) -{ - return TRUE; -} - -/** - * _cairo_hash_table_create: - * @keys_equal: a function to return %TRUE if two keys are equal - * - * Creates a new hash table which will use the keys_equal() function - * to compare hash keys. Data is provided to the hash table in the - * form of user-derived versions of #cairo_hash_entry_t. A hash entry - * must be able to hold both a key (including a hash code) and a - * value. Sometimes only the key will be necessary, (as in - * _cairo_hash_table_remove), and other times both a key and a value - * will be necessary, (as in _cairo_hash_table_insert). - * - * If @keys_equal is %NULL, two keys will be considered equal if and - * only if their hashes are equal. - * - * See #cairo_hash_entry_t for more details. - * - * Return value: the new hash table or %NULL if out of memory. - **/ -cairo_hash_table_t * -_cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal) -{ - cairo_hash_table_t *hash_table; - - hash_table = malloc (sizeof (cairo_hash_table_t)); - if (unlikely (hash_table == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - if (keys_equal == NULL) - hash_table->keys_equal = _cairo_hash_table_uid_keys_equal; - else - hash_table->keys_equal = keys_equal; - - memset (&hash_table->cache, 0, sizeof (hash_table->cache)); - hash_table->table_size = &hash_table_sizes[0]; - - hash_table->entries = calloc (*hash_table->table_size, - sizeof (cairo_hash_entry_t *)); - if (unlikely (hash_table->entries == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - free (hash_table); - return NULL; - } - - hash_table->live_entries = 0; - hash_table->free_entries = *hash_table->table_size; - hash_table->iterating = 0; - - return hash_table; -} - -/** - * _cairo_hash_table_destroy: - * @hash_table: an empty hash table to destroy - * - * Immediately destroys the given hash table, freeing all resources - * associated with it. - * - * WARNING: The hash_table must have no live entries in it before - * _cairo_hash_table_destroy is called. It is a fatal error otherwise, - * and this function will halt. The rationale for this behavior is to - * avoid memory leaks and to avoid needless complication of the API - * with destroy notifiy callbacks. - * - * WARNING: The hash_table must have no running iterators in it when - * _cairo_hash_table_destroy is called. It is a fatal error otherwise, - * and this function will halt. - **/ -void -_cairo_hash_table_destroy (cairo_hash_table_t *hash_table) -{ - /* The hash table must be empty. Otherwise, halt. */ - assert (hash_table->live_entries == 0); - /* No iterators can be running. Otherwise, halt. */ - assert (hash_table->iterating == 0); - - free (hash_table->entries); - free (hash_table); -} - -static cairo_hash_entry_t ** -_cairo_hash_table_lookup_unique_key (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key) -{ - unsigned long table_size, i, idx, step; - cairo_hash_entry_t **entry; - - table_size = *hash_table->table_size; - idx = key->hash % table_size; - - entry = &hash_table->entries[idx]; - if (! ENTRY_IS_LIVE (*entry)) - return entry; - - i = 1; - step = 1 + key->hash % (table_size - 2); - do { - idx += step; - if (idx >= table_size) - idx -= table_size; - - entry = &hash_table->entries[idx]; - if (! ENTRY_IS_LIVE (*entry)) - return entry; - } while (++i < table_size); - - ASSERT_NOT_REACHED; - return NULL; -} - -/** - * _cairo_hash_table_manage: - * @hash_table: a hash table - * - * Resize the hash table if the number of entries has gotten much - * bigger or smaller than the ideal number of entries for the current - * size and guarantee some free entries to be used as lookup - * termination points. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if out of memory. - **/ -static cairo_status_t -_cairo_hash_table_manage (cairo_hash_table_t *hash_table) -{ - cairo_hash_table_t tmp; - unsigned long new_size, i; - - /* Keep between 12.5% and 50% entries in the hash table alive and - * at least 25% free. */ - unsigned long live_high = *hash_table->table_size >> 1; - unsigned long live_low = live_high >> 2; - unsigned long free_low = live_high >> 1; - - tmp = *hash_table; - - if (hash_table->live_entries > live_high) - { - tmp.table_size = hash_table->table_size + 1; - /* This code is being abused if we can't make a table big enough. */ - assert (tmp.table_size - hash_table_sizes < - ARRAY_LENGTH (hash_table_sizes)); - } - else if (hash_table->live_entries < live_low) - { - /* Can't shrink if we're at the smallest size */ - if (hash_table->table_size == &hash_table_sizes[0]) - tmp.table_size = hash_table->table_size; - else - tmp.table_size = hash_table->table_size - 1; - } - - if (tmp.table_size == hash_table->table_size && - hash_table->free_entries > free_low) - { - /* The number of live entries is within the desired bounds - * (we're not going to resize the table) and we have enough - * free entries. Do nothing. */ - return CAIRO_STATUS_SUCCESS; - } - - new_size = *tmp.table_size; - tmp.entries = calloc (new_size, sizeof (cairo_hash_entry_t*)); - if (unlikely (tmp.entries == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - for (i = 0; i < *hash_table->table_size; ++i) { - if (ENTRY_IS_LIVE (hash_table->entries[i])) { - *_cairo_hash_table_lookup_unique_key (&tmp, hash_table->entries[i]) - = hash_table->entries[i]; - } - } - - free (hash_table->entries); - hash_table->entries = tmp.entries; - hash_table->table_size = tmp.table_size; - hash_table->free_entries = new_size - hash_table->live_entries; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_hash_table_lookup: - * @hash_table: a hash table - * @key: the key of interest - * - * Performs a lookup in @hash_table looking for an entry which has a - * key that matches @key, (as determined by the keys_equal() function - * passed to _cairo_hash_table_create). - * - * Return value: the matching entry, of %NULL if no match was found. - **/ -void * -_cairo_hash_table_lookup (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key) -{ - cairo_hash_entry_t *entry; - unsigned long table_size, i, idx, step; - unsigned long hash = key->hash; - - entry = hash_table->cache[hash & 31]; - if (entry && entry->hash == hash && hash_table->keys_equal (key, entry)) - return entry; - - table_size = *hash_table->table_size; - idx = hash % table_size; - - entry = hash_table->entries[idx]; - if (ENTRY_IS_LIVE (entry)) { - if (entry->hash == hash && hash_table->keys_equal (key, entry)) - goto insert_cache; - } else if (ENTRY_IS_FREE (entry)) - return NULL; - - i = 1; - step = 1 + hash % (table_size - 2); - do { - idx += step; - if (idx >= table_size) - idx -= table_size; - - entry = hash_table->entries[idx]; - if (ENTRY_IS_LIVE (entry)) { - if (entry->hash == hash && hash_table->keys_equal (key, entry)) - goto insert_cache; - } else if (ENTRY_IS_FREE (entry)) - return NULL; - } while (++i < table_size); - - ASSERT_NOT_REACHED; - return NULL; - -insert_cache: - hash_table->cache[hash & 31] = entry; - return entry; -} - -/** - * _cairo_hash_table_random_entry: - * @hash_table: a hash table - * @predicate: a predicate function. - * - * Find a random entry in the hash table satisfying the given - * @predicate. - * - * We use the same algorithm as the lookup algorithm to walk over the - * entries in the hash table in a pseudo-random order. Walking - * linearly would favor entries following gaps in the hash table. We - * could also call rand() repeatedly, which works well for almost-full - * tables, but degrades when the table is almost empty, or predicate - * returns %TRUE for most entries. - * - * Return value: a random live entry or %NULL if there are no entries - * that match the given predicate. In particular, if predicate is - * %NULL, a %NULL return value indicates that the table is empty. - **/ -void * -_cairo_hash_table_random_entry (cairo_hash_table_t *hash_table, - cairo_hash_predicate_func_t predicate) -{ - cairo_hash_entry_t *entry; - unsigned long hash; - unsigned long table_size, i, idx, step; - - assert (predicate != NULL); - - table_size = *hash_table->table_size; - hash = rand (); - idx = hash % table_size; - - entry = hash_table->entries[idx]; - if (ENTRY_IS_LIVE (entry) && predicate (entry)) - return entry; - - i = 1; - step = 1 + hash % (table_size - 2); - do { - idx += step; - if (idx >= table_size) - idx -= table_size; - - entry = hash_table->entries[idx]; - if (ENTRY_IS_LIVE (entry) && predicate (entry)) - return entry; - } while (++i < table_size); - - return NULL; -} - -/** - * _cairo_hash_table_insert: - * @hash_table: a hash table - * @key_and_value: an entry to be inserted - * - * Insert the entry #key_and_value into the hash table. - * - * WARNING: There must not be an existing entry in the hash table - * with a matching key. - * - * WARNING: It is a fatal error to insert an element while - * an iterator is running - * - * Instead of using insert to replace an entry, consider just editing - * the entry obtained with _cairo_hash_table_lookup. Or if absolutely - * necessary, use _cairo_hash_table_remove first. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available. - **/ -cairo_status_t -_cairo_hash_table_insert (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key_and_value) -{ - cairo_hash_entry_t **entry; - cairo_status_t status; - - /* Insert is illegal while an iterator is running. */ - assert (hash_table->iterating == 0); - - status = _cairo_hash_table_manage (hash_table); - if (unlikely (status)) - return status; - - entry = _cairo_hash_table_lookup_unique_key (hash_table, key_and_value); - - if (ENTRY_IS_FREE (*entry)) - hash_table->free_entries--; - - *entry = key_and_value; - hash_table->cache[key_and_value->hash & 31] = key_and_value; - hash_table->live_entries++; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_hash_entry_t ** -_cairo_hash_table_lookup_exact_key (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key) -{ - unsigned long table_size, i, idx, step; - cairo_hash_entry_t **entry; - - table_size = *hash_table->table_size; - idx = key->hash % table_size; - - entry = &hash_table->entries[idx]; - if (*entry == key) - return entry; - - i = 1; - step = 1 + key->hash % (table_size - 2); - do { - idx += step; - if (idx >= table_size) - idx -= table_size; - - entry = &hash_table->entries[idx]; - if (*entry == key) - return entry; - } while (++i < table_size); - - ASSERT_NOT_REACHED; - return NULL; -} -/** - * _cairo_hash_table_remove: - * @hash_table: a hash table - * @key: key of entry to be removed - * - * Remove an entry from the hash table which points to @key. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful or - * %CAIRO_STATUS_NO_MEMORY if out of memory. - **/ -void -_cairo_hash_table_remove (cairo_hash_table_t *hash_table, - cairo_hash_entry_t *key) -{ - *_cairo_hash_table_lookup_exact_key (hash_table, key) = DEAD_ENTRY; - hash_table->live_entries--; - hash_table->cache[key->hash & 31] = NULL; - - /* Check for table resize. Don't do this when iterating as this will - * reorder elements of the table and cause the iteration to potentially - * skip some elements. */ - if (hash_table->iterating == 0) { - /* This call _can_ fail, but only in failing to allocate new - * memory to shrink the hash table. It does leave the table in a - * consistent state, and we've already succeeded in removing the - * entry, so we don't examine the failure status of this call. */ - _cairo_hash_table_manage (hash_table); - } -} - -/** - * _cairo_hash_table_foreach: - * @hash_table: a hash table - * @hash_callback: function to be called for each live entry - * @closure: additional argument to be passed to @hash_callback - * - * Call @hash_callback for each live entry in the hash table, in a - * non-specified order. - * - * Entries in @hash_table may be removed by code executed from @hash_callback. - * - * Entries may not be inserted to @hash_table, nor may @hash_table - * be destroyed by code executed from @hash_callback. The relevant - * functions will halt in these cases. - **/ -void -_cairo_hash_table_foreach (cairo_hash_table_t *hash_table, - cairo_hash_callback_func_t hash_callback, - void *closure) -{ - unsigned long i; - cairo_hash_entry_t *entry; - - /* Mark the table for iteration */ - ++hash_table->iterating; - for (i = 0; i < *hash_table->table_size; i++) { - entry = hash_table->entries[i]; - if (ENTRY_IS_LIVE(entry)) - hash_callback (entry, closure); - } - /* If some elements were deleted during the iteration, - * the table may need resizing. Just do this every time - * as the check is inexpensive. - */ - if (--hash_table->iterating == 0) { - /* Should we fail to shrink the hash table, it is left unaltered, - * and we don't need to propagate the error status. */ - _cairo_hash_table_manage (hash_table); - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hull.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hull.c deleted file mode 100644 index c65593327f6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-hull.c +++ /dev/null @@ -1,235 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-slope-private.h" - -typedef struct cairo_hull { - cairo_point_t point; - cairo_slope_t slope; - int discard; - int id; -} cairo_hull_t; - -static void -_cairo_hull_init (cairo_hull_t *hull, - cairo_pen_vertex_t *vertices, - int num_vertices) -{ - cairo_point_t *p, *extremum, tmp; - int i; - - extremum = &vertices[0].point; - for (i = 1; i < num_vertices; i++) { - p = &vertices[i].point; - if (p->y < extremum->y || (p->y == extremum->y && p->x < extremum->x)) - extremum = p; - } - /* Put the extremal point at the beginning of the array */ - tmp = *extremum; - *extremum = vertices[0].point; - vertices[0].point = tmp; - - for (i = 0; i < num_vertices; i++) { - hull[i].point = vertices[i].point; - _cairo_slope_init (&hull[i].slope, &hull[0].point, &hull[i].point); - - /* give each point a unique id for later comparison */ - hull[i].id = i; - - /* Don't discard by default */ - hull[i].discard = 0; - - /* Discard all points coincident with the extremal point */ - if (i != 0 && hull[i].slope.dx == 0 && hull[i].slope.dy == 0) - hull[i].discard = 1; - } -} - -static inline cairo_int64_t -_slope_length (cairo_slope_t *slope) -{ - return _cairo_int64_add (_cairo_int32x32_64_mul (slope->dx, slope->dx), - _cairo_int32x32_64_mul (slope->dy, slope->dy)); -} - -static int -_cairo_hull_vertex_compare (const void *av, const void *bv) -{ - cairo_hull_t *a = (cairo_hull_t *) av; - cairo_hull_t *b = (cairo_hull_t *) bv; - int ret; - - /* Some libraries are reported to actually compare identical - * pointers and require the result to be 0. This is the crazy world we - * have to live in. - */ - if (a == b) - return 0; - - ret = _cairo_slope_compare (&a->slope, &b->slope); - - /* - * In the case of two vertices with identical slope from the - * extremal point discard the nearer point. - */ - if (ret == 0) { - int cmp; - - cmp = _cairo_int64_cmp (_slope_length (&a->slope), - _slope_length (&b->slope)); - - /* - * Use the points' ids to ensure a well-defined ordering, - * and avoid setting discard on both points. - */ - if (cmp < 0 || (cmp == 0 && a->id < b->id)) { - a->discard = 1; - ret = -1; - } else { - b->discard = 1; - ret = 1; - } - } - - return ret; -} - -static int -_cairo_hull_prev_valid (cairo_hull_t *hull, int num_hull, int index) -{ - /* hull[0] is always valid, and we never need to wraparound, (if - * we are passed an index of 0 here, then the calling loop is just - * about to terminate). */ - if (index == 0) - return 0; - - do { - index--; - } while (hull[index].discard); - - return index; -} - -static int -_cairo_hull_next_valid (cairo_hull_t *hull, int num_hull, int index) -{ - do { - index = (index + 1) % num_hull; - } while (hull[index].discard); - - return index; -} - -static void -_cairo_hull_eliminate_concave (cairo_hull_t *hull, int num_hull) -{ - int i, j, k; - cairo_slope_t slope_ij, slope_jk; - - i = 0; - j = _cairo_hull_next_valid (hull, num_hull, i); - k = _cairo_hull_next_valid (hull, num_hull, j); - - do { - _cairo_slope_init (&slope_ij, &hull[i].point, &hull[j].point); - _cairo_slope_init (&slope_jk, &hull[j].point, &hull[k].point); - - /* Is the angle formed by ij and jk concave? */ - if (_cairo_slope_compare (&slope_ij, &slope_jk) >= 0) { - if (i == k) - return; - hull[j].discard = 1; - j = i; - i = _cairo_hull_prev_valid (hull, num_hull, j); - } else { - i = j; - j = k; - k = _cairo_hull_next_valid (hull, num_hull, j); - } - } while (j != 0); -} - -static void -_cairo_hull_to_pen (cairo_hull_t *hull, cairo_pen_vertex_t *vertices, int *num_vertices) -{ - int i, j = 0; - - for (i = 0; i < *num_vertices; i++) { - if (hull[i].discard) - continue; - vertices[j++].point = hull[i].point; - } - - *num_vertices = j; -} - -/* Given a set of vertices, compute the convex hull using the Graham - scan algorithm. */ -cairo_status_t -_cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices) -{ - cairo_hull_t hull_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_hull_t)]; - cairo_hull_t *hull; - int num_hull = *num_vertices; - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (num_hull > ARRAY_LENGTH (hull_stack)) { - hull = _cairo_malloc_ab (num_hull, sizeof (cairo_hull_t)); - if (unlikely (hull == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else { - hull = hull_stack; - } - - _cairo_hull_init (hull, vertices, num_hull); - - qsort (hull + 1, num_hull - 1, - sizeof (cairo_hull_t), _cairo_hull_vertex_compare); - - _cairo_hull_eliminate_concave (hull, num_hull); - - _cairo_hull_to_pen (hull, vertices, num_vertices); - - if (hull != hull_stack) - free (hull); - - return CAIRO_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-compositor.c deleted file mode 100644 index 48072f81bd0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-compositor.c +++ /dev/null @@ -1,3137 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * Copyright © 2009,2010,2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* The primarily reason for keeping a traps-compositor around is - * for validating cairo-xlib (which currently also uses traps). - */ - -#include "cairoint.h" - -#include "cairo-image-surface-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-spans-compositor-private.h" - -#include "cairo-region-private.h" -#include "cairo-traps-private.h" -#include "cairo-tristrip-private.h" - -#include "cairo-pixman-private.h" - -static pixman_image_t * -to_pixman_image (cairo_surface_t *s) -{ - return ((cairo_image_surface_t *)s)->pixman_image; -} - -static cairo_int_status_t -acquire (void *abstract_dst) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -release (void *abstract_dst) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -set_clip_region (void *_surface, - cairo_region_t *region) -{ - cairo_image_surface_t *surface = _surface; - pixman_region32_t *rgn = region ? ®ion->rgn : NULL; - - if (! pixman_image_set_clip_region32 (surface->pixman_image, rgn)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -draw_image_boxes (void *_dst, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy) -{ - cairo_image_surface_t *dst = _dst; - struct _cairo_boxes_chunk *chunk; - int i; - - TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - int x = _cairo_fixed_integer_part (b->p1.x); - int y = _cairo_fixed_integer_part (b->p1.y); - int w = _cairo_fixed_integer_part (b->p2.x) - x; - int h = _cairo_fixed_integer_part (b->p2.y) - y; - if (dst->pixman_format != image->pixman_format || - ! pixman_blt ((uint32_t *)image->data, (uint32_t *)dst->data, - image->stride / sizeof (uint32_t), - dst->stride / sizeof (uint32_t), - PIXMAN_FORMAT_BPP (image->pixman_format), - PIXMAN_FORMAT_BPP (dst->pixman_format), - x + dx, y + dy, - x, y, - w, h)) - { - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, NULL, dst->pixman_image, - x + dx, y + dy, - 0, 0, - x, y, - w, h); - } - } - } - return CAIRO_STATUS_SUCCESS; -} - -static inline uint32_t -color_to_uint32 (const cairo_color_t *color) -{ - return - (color->alpha_short >> 8 << 24) | - (color->red_short >> 8 << 16) | - (color->green_short & 0xff00) | - (color->blue_short >> 8); -} - -static inline cairo_bool_t -color_to_pixel (const cairo_color_t *color, - pixman_format_code_t format, - uint32_t *pixel) -{ - uint32_t c; - - if (!(format == PIXMAN_a8r8g8b8 || - format == PIXMAN_x8r8g8b8 || - format == PIXMAN_a8b8g8r8 || - format == PIXMAN_x8b8g8r8 || - format == PIXMAN_b8g8r8a8 || - format == PIXMAN_b8g8r8x8 || - format == PIXMAN_r5g6b5 || - format == PIXMAN_b5g6r5 || - format == PIXMAN_a8)) - { - return FALSE; - } - - c = color_to_uint32 (color); - - if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_ABGR) { - c = ((c & 0xff000000) >> 0) | - ((c & 0x00ff0000) >> 16) | - ((c & 0x0000ff00) >> 0) | - ((c & 0x000000ff) << 16); - } - - if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_BGRA) { - c = ((c & 0xff000000) >> 24) | - ((c & 0x00ff0000) >> 8) | - ((c & 0x0000ff00) << 8) | - ((c & 0x000000ff) << 24); - } - - if (format == PIXMAN_a8) { - c = c >> 24; - } else if (format == PIXMAN_r5g6b5 || format == PIXMAN_b5g6r5) { - c = ((((c) >> 3) & 0x001f) | - (((c) >> 5) & 0x07e0) | - (((c) >> 8) & 0xf800)); - } - - *pixel = c; - return TRUE; -} - -static pixman_op_t -_pixman_operator (cairo_operator_t op) -{ - switch ((int) op) { - case CAIRO_OPERATOR_CLEAR: - return PIXMAN_OP_CLEAR; - - case CAIRO_OPERATOR_SOURCE: - return PIXMAN_OP_SRC; - case CAIRO_OPERATOR_OVER: - return PIXMAN_OP_OVER; - case CAIRO_OPERATOR_IN: - return PIXMAN_OP_IN; - case CAIRO_OPERATOR_OUT: - return PIXMAN_OP_OUT; - case CAIRO_OPERATOR_ATOP: - return PIXMAN_OP_ATOP; - - case CAIRO_OPERATOR_DEST: - return PIXMAN_OP_DST; - case CAIRO_OPERATOR_DEST_OVER: - return PIXMAN_OP_OVER_REVERSE; - case CAIRO_OPERATOR_DEST_IN: - return PIXMAN_OP_IN_REVERSE; - case CAIRO_OPERATOR_DEST_OUT: - return PIXMAN_OP_OUT_REVERSE; - case CAIRO_OPERATOR_DEST_ATOP: - return PIXMAN_OP_ATOP_REVERSE; - - case CAIRO_OPERATOR_XOR: - return PIXMAN_OP_XOR; - case CAIRO_OPERATOR_ADD: - return PIXMAN_OP_ADD; - case CAIRO_OPERATOR_SATURATE: - return PIXMAN_OP_SATURATE; - - case CAIRO_OPERATOR_MULTIPLY: - return PIXMAN_OP_MULTIPLY; - case CAIRO_OPERATOR_SCREEN: - return PIXMAN_OP_SCREEN; - case CAIRO_OPERATOR_OVERLAY: - return PIXMAN_OP_OVERLAY; - case CAIRO_OPERATOR_DARKEN: - return PIXMAN_OP_DARKEN; - case CAIRO_OPERATOR_LIGHTEN: - return PIXMAN_OP_LIGHTEN; - case CAIRO_OPERATOR_COLOR_DODGE: - return PIXMAN_OP_COLOR_DODGE; - case CAIRO_OPERATOR_COLOR_BURN: - return PIXMAN_OP_COLOR_BURN; - case CAIRO_OPERATOR_HARD_LIGHT: - return PIXMAN_OP_HARD_LIGHT; - case CAIRO_OPERATOR_SOFT_LIGHT: - return PIXMAN_OP_SOFT_LIGHT; - case CAIRO_OPERATOR_DIFFERENCE: - return PIXMAN_OP_DIFFERENCE; - case CAIRO_OPERATOR_EXCLUSION: - return PIXMAN_OP_EXCLUSION; - case CAIRO_OPERATOR_HSL_HUE: - return PIXMAN_OP_HSL_HUE; - case CAIRO_OPERATOR_HSL_SATURATION: - return PIXMAN_OP_HSL_SATURATION; - case CAIRO_OPERATOR_HSL_COLOR: - return PIXMAN_OP_HSL_COLOR; - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return PIXMAN_OP_HSL_LUMINOSITY; - - default: - ASSERT_NOT_REACHED; - return PIXMAN_OP_OVER; - } -} - -static cairo_bool_t -__fill_reduces_to_source (cairo_operator_t op, - const cairo_color_t *color, - const cairo_image_surface_t *dst) -{ - if (op == CAIRO_OPERATOR_SOURCE || op == CAIRO_OPERATOR_CLEAR) - return TRUE; - if (op == CAIRO_OPERATOR_OVER && CAIRO_COLOR_IS_OPAQUE (color)) - return TRUE; - if (dst->base.is_clear) - return op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD; - - return FALSE; -} - -static cairo_bool_t -fill_reduces_to_source (cairo_operator_t op, - const cairo_color_t *color, - const cairo_image_surface_t *dst, - uint32_t *pixel) -{ - if (__fill_reduces_to_source (op, color, dst)) { - return color_to_pixel (color, dst->pixman_format, pixel); - } - - return FALSE; -} - -static cairo_int_status_t -fill_rectangles (void *_dst, - cairo_operator_t op, - const cairo_color_t *color, - cairo_rectangle_int_t *rects, - int num_rects) -{ - cairo_image_surface_t *dst = _dst; - uint32_t pixel; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (fill_reduces_to_source (op, color, dst, &pixel)) { - for (i = 0; i < num_rects; i++) { - pixman_fill ((uint32_t *) dst->data, dst->stride / sizeof (uint32_t), - PIXMAN_FORMAT_BPP (dst->pixman_format), - rects[i].x, rects[i].y, - rects[i].width, rects[i].height, - pixel); - } - } else { - pixman_image_t *src = _pixman_image_for_color (color); - if (unlikely (src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - op = _pixman_operator (op); - for (i = 0; i < num_rects; i++) { - pixman_image_composite32 (op, - src, NULL, dst->pixman_image, - 0, 0, - 0, 0, - rects[i].x, rects[i].y, - rects[i].width, rects[i].height); - } - - pixman_image_unref (src); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -fill_boxes (void *_dst, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - cairo_image_surface_t *dst = _dst; - struct _cairo_boxes_chunk *chunk; - uint32_t pixel; - int i; - - TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); - - if (fill_reduces_to_source (op, color, dst, &pixel)) { - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int w = _cairo_fixed_integer_part (chunk->base[i].p2.x) - x; - int h = _cairo_fixed_integer_part (chunk->base[i].p2.y) - y; - pixman_fill ((uint32_t *) dst->data, - dst->stride / sizeof (uint32_t), - PIXMAN_FORMAT_BPP (dst->pixman_format), - x, y, w, h, pixel); - } - } - } - else - { - pixman_image_t *src = _pixman_image_for_color (color); - if (unlikely (src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - op = _pixman_operator (op); - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - pixman_image_composite32 (op, - src, NULL, dst->pixman_image, - 0, 0, - 0, 0, - x1, y1, - x2-x1, y2-y1); - } - } - - pixman_image_unref (src); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - cairo_image_source_t *src = (cairo_image_source_t *)abstract_src; - cairo_image_source_t *mask = (cairo_image_source_t *)abstract_mask; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (mask) { - pixman_image_composite32 (_pixman_operator (op), - src->pixman_image, mask->pixman_image, to_pixman_image (_dst), - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height); - } else { - pixman_image_composite32 (_pixman_operator (op), - src->pixman_image, NULL, to_pixman_image (_dst), - src_x, src_y, - 0, 0, - dst_x, dst_y, - width, height); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -lerp (void *_dst, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - cairo_image_surface_t *dst = _dst; - cairo_image_source_t *src = (cairo_image_source_t *)abstract_src; - cairo_image_source_t *mask = (cairo_image_source_t *)abstract_mask; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - -#if PIXMAN_HAS_OP_LERP - pixman_image_composite32 (PIXMAN_OP_LERP_SRC, - src->pixman_image, mask->pixman_image, dst->pixman_image, - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height); -#else - /* Punch the clip out of the destination */ - TRACE ((stderr, "%s - OUT_REVERSE (mask=%d/%p, dst=%d/%p)\n", - __FUNCTION__, - mask->base.unique_id, mask->pixman_image, - dst->base.unique_id, dst->pixman_image)); - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - mask->pixman_image, NULL, dst->pixman_image, - mask_x, mask_y, - 0, 0, - dst_x, dst_y, - width, height); - - /* Now add the two results together */ - TRACE ((stderr, "%s - ADD (src=%d/%p, mask=%d/%p, dst=%d/%p)\n", - __FUNCTION__, - src->base.unique_id, src->pixman_image, - mask->base.unique_id, mask->pixman_image, - dst->base.unique_id, dst->pixman_image)); - pixman_image_composite32 (PIXMAN_OP_ADD, - src->pixman_image, mask->pixman_image, dst->pixman_image, - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height); -#endif - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_boxes (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents) -{ - pixman_image_t *dst = to_pixman_image (_dst); - pixman_image_t *src = ((cairo_image_source_t *)abstract_src)->pixman_image; - pixman_image_t *mask = abstract_mask ? ((cairo_image_source_t *)abstract_mask)->pixman_image : NULL; - pixman_image_t *free_src = NULL; - struct _cairo_boxes_chunk *chunk; - int i; - - /* XXX consider using a region? saves multiple prepare-composite */ - TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); - - if (((cairo_surface_t *)_dst)->is_clear && - (op == CAIRO_OPERATOR_SOURCE || - op == CAIRO_OPERATOR_OVER || - op == CAIRO_OPERATOR_ADD)) { - op = PIXMAN_OP_SRC; - } else if (mask) { - if (op == CAIRO_OPERATOR_CLEAR) { -#if PIXMAN_HAS_OP_LERP - op = PIXMAN_OP_LERP_CLEAR; -#else - free_src = src = _pixman_image_for_color (CAIRO_COLOR_WHITE); - if (unlikely (src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - op = PIXMAN_OP_OUT_REVERSE; -#endif - } else if (op == CAIRO_OPERATOR_SOURCE) { -#if PIXMAN_HAS_OP_LERP - op = PIXMAN_OP_LERP_SRC; -#else - return CAIRO_INT_STATUS_UNSUPPORTED; -#endif - } else { - op = _pixman_operator (op); - } - } else { - op = _pixman_operator (op); - } - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - - pixman_image_composite32 (op, src, mask, dst, - x1 + src_x, y1 + src_y, - x1 + mask_x, y1 + mask_y, - x1 + dst_x, y1 + dst_y, - x2 - x1, y2 - y1); - } - } - - if (free_src) - pixman_image_unref (free_src); - - return CAIRO_STATUS_SUCCESS; -} - -#define CAIRO_FIXED_16_16_MIN _cairo_fixed_from_int (-32768) -#define CAIRO_FIXED_16_16_MAX _cairo_fixed_from_int (32767) - -static cairo_bool_t -line_exceeds_16_16 (const cairo_line_t *line) -{ - return - line->p1.x <= CAIRO_FIXED_16_16_MIN || - line->p1.x >= CAIRO_FIXED_16_16_MAX || - - line->p2.x <= CAIRO_FIXED_16_16_MIN || - line->p2.x >= CAIRO_FIXED_16_16_MAX || - - line->p1.y <= CAIRO_FIXED_16_16_MIN || - line->p1.y >= CAIRO_FIXED_16_16_MAX || - - line->p2.y <= CAIRO_FIXED_16_16_MIN || - line->p2.y >= CAIRO_FIXED_16_16_MAX; -} - -static void -project_line_x_onto_16_16 (const cairo_line_t *line, - cairo_fixed_t top, - cairo_fixed_t bottom, - pixman_line_fixed_t *out) -{ - /* XXX use fixed-point arithmetic? */ - cairo_point_double_t p1, p2; - double m; - - p1.x = _cairo_fixed_to_double (line->p1.x); - p1.y = _cairo_fixed_to_double (line->p1.y); - - p2.x = _cairo_fixed_to_double (line->p2.x); - p2.y = _cairo_fixed_to_double (line->p2.y); - - m = (p2.x - p1.x) / (p2.y - p1.y); - out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); - out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); -} - -void -_pixman_image_add_traps (pixman_image_t *image, - int dst_x, int dst_y, - cairo_traps_t *traps) -{ - cairo_trapezoid_t *t = traps->traps; - int num_traps = traps->num_traps; - while (num_traps--) { - pixman_trapezoid_t trap; - - /* top/bottom will be clamped to surface bounds */ - trap.top = _cairo_fixed_to_16_16 (t->top); - trap.bottom = _cairo_fixed_to_16_16 (t->bottom); - - /* However, all the other coordinates will have been left untouched so - * as not to introduce numerical error. Recompute them if they - * exceed the 16.16 limits. - */ - if (unlikely (line_exceeds_16_16 (&t->left))) { - project_line_x_onto_16_16 (&t->left, t->top, t->bottom, &trap.left); - trap.left.p1.y = trap.top; - trap.left.p2.y = trap.bottom; - } else { - trap.left.p1.x = _cairo_fixed_to_16_16 (t->left.p1.x); - trap.left.p1.y = _cairo_fixed_to_16_16 (t->left.p1.y); - trap.left.p2.x = _cairo_fixed_to_16_16 (t->left.p2.x); - trap.left.p2.y = _cairo_fixed_to_16_16 (t->left.p2.y); - } - - if (unlikely (line_exceeds_16_16 (&t->right))) { - project_line_x_onto_16_16 (&t->right, t->top, t->bottom, &trap.right); - trap.right.p1.y = trap.top; - trap.right.p2.y = trap.bottom; - } else { - trap.right.p1.x = _cairo_fixed_to_16_16 (t->right.p1.x); - trap.right.p1.y = _cairo_fixed_to_16_16 (t->right.p1.y); - trap.right.p2.x = _cairo_fixed_to_16_16 (t->right.p2.x); - trap.right.p2.y = _cairo_fixed_to_16_16 (t->right.p2.y); - } - - pixman_rasterize_trapezoid (image, &trap, -dst_x, -dst_y); - t++; - } -} - -static cairo_int_status_t -composite_traps (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_traps_t *traps) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *) _dst; - cairo_image_source_t *src = (cairo_image_source_t *) abstract_src; - cairo_int_status_t status; - pixman_image_t *mask; - pixman_format_code_t format; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - /* pixman doesn't eliminate self-intersecting trapezoids/edges */ - status = _cairo_bentley_ottmann_tessellate_traps (traps, - CAIRO_FILL_RULE_WINDING); - if (status != CAIRO_INT_STATUS_SUCCESS) - return status; - - /* Special case adding trapezoids onto a mask surface; we want to avoid - * creating an intermediate temporary mask unnecessarily. - * - * We make the assumption here that the portion of the trapezoids - * contained within the surface is bounded by [dst_x,dst_y,width,height]; - * the Cairo core code passes bounds based on the trapezoid extents. - */ - format = antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8; - if (dst->pixman_format == format && - (abstract_src == NULL || - (op == CAIRO_OPERATOR_ADD && src->is_opaque_solid))) - { - _pixman_image_add_traps (dst->pixman_image, dst_x, dst_y, traps); - return CAIRO_STATUS_SUCCESS; - } - - mask = pixman_image_create_bits (format, - extents->width, extents->height, - NULL, 0); - if (unlikely (mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _pixman_image_add_traps (mask, extents->x, extents->y, traps); - pixman_image_composite32 (_pixman_operator (op), - src->pixman_image, mask, dst->pixman_image, - extents->x + src_x, extents->y + src_y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - pixman_image_unref (mask); - - return CAIRO_STATUS_SUCCESS; -} - -#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) -static void -set_point (pixman_point_fixed_t *p, cairo_point_t *c) -{ - p->x = _cairo_fixed_to_16_16 (c->x); - p->y = _cairo_fixed_to_16_16 (c->y); -} - -void -_pixman_image_add_tristrip (pixman_image_t *image, - int dst_x, int dst_y, - cairo_tristrip_t *strip) -{ - pixman_triangle_t tri; - pixman_point_fixed_t *p[3] = {&tri.p1, &tri.p2, &tri.p3 }; - int n; - - set_point (p[0], &strip->points[0]); - set_point (p[1], &strip->points[1]); - set_point (p[2], &strip->points[2]); - pixman_add_triangles (image, -dst_x, -dst_y, 1, &tri); - for (n = 3; n < strip->num_points; n++) { - set_point (p[n%3], &strip->points[n]); - pixman_add_triangles (image, -dst_x, -dst_y, 1, &tri); - } -} - -static cairo_int_status_t -composite_tristrip (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_tristrip_t *strip) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *) _dst; - cairo_image_source_t *src = (cairo_image_source_t *) abstract_src; - pixman_image_t *mask; - pixman_format_code_t format; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (strip->num_points < 3) - return CAIRO_STATUS_SUCCESS; - - if (1) { /* pixman doesn't eliminate self-intersecting triangles/edges */ - cairo_int_status_t status; - cairo_traps_t traps; - int n; - - _cairo_traps_init (&traps); - for (n = 0; n < strip->num_points; n++) { - cairo_point_t p[4]; - - p[0] = strip->points[0]; - p[1] = strip->points[1]; - p[2] = strip->points[2]; - p[3] = strip->points[0]; - - _cairo_traps_tessellate_convex_quad (&traps, p); - } - status = composite_traps (_dst, op, abstract_src, - src_x, src_y, - dst_x, dst_y, - extents, antialias, &traps); - _cairo_traps_fini (&traps); - - return status; - } - - format = antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8; - if (dst->pixman_format == format && - (abstract_src == NULL || - (op == CAIRO_OPERATOR_ADD && src->is_opaque_solid))) - { - _pixman_image_add_tristrip (dst->pixman_image, dst_x, dst_y, strip); - return CAIRO_STATUS_SUCCESS; - } - - mask = pixman_image_create_bits (format, - extents->width, extents->height, - NULL, 0); - if (unlikely (mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _pixman_image_add_tristrip (mask, extents->x, extents->y, strip); - pixman_image_composite32 (_pixman_operator (op), - src->pixman_image, mask, dst->pixman_image, - extents->x + src_x, extents->y + src_y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - pixman_image_unref (mask); - - return CAIRO_STATUS_SUCCESS; -} -#endif - -static cairo_int_status_t -check_composite_glyphs (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs) -{ - return CAIRO_STATUS_SUCCESS; -} - -#if HAS_PIXMAN_GLYPHS -static pixman_glyph_cache_t *global_glyph_cache; - -static inline pixman_glyph_cache_t * -get_glyph_cache (void) -{ - if (!global_glyph_cache) - global_glyph_cache = pixman_glyph_cache_create (); - - return global_glyph_cache; -} - -void -_cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_t *scaled_glyph) -{ - CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); - - if (global_glyph_cache) { - pixman_glyph_cache_remove ( - global_glyph_cache, scaled_font, - (void *)_cairo_scaled_glyph_index (scaled_glyph)); - } - - CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); -} - -static cairo_int_status_t -composite_glyphs (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - pixman_glyph_cache_t *glyph_cache; - pixman_glyph_t pglyphs_stack[CAIRO_STACK_ARRAY_LENGTH (pixman_glyph_t)]; - pixman_glyph_t *pglyphs = pglyphs_stack; - pixman_glyph_t *pg; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); - - glyph_cache = get_glyph_cache(); - if (unlikely (glyph_cache == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto out_unlock; - } - - pixman_glyph_cache_freeze (glyph_cache); - - if (info->num_glyphs > ARRAY_LENGTH (pglyphs_stack)) { - pglyphs = _cairo_malloc_ab (info->num_glyphs, sizeof (pixman_glyph_t)); - if (unlikely (pglyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto out_thaw; - } - } - - pg = pglyphs; - for (i = 0; i < info->num_glyphs; i++) { - unsigned long index = info->glyphs[i].index; - const void *glyph; - - glyph = pixman_glyph_cache_lookup (glyph_cache, info->font, (void *)index); - if (!glyph) { - cairo_scaled_glyph_t *scaled_glyph; - cairo_image_surface_t *glyph_surface; - - /* This call can actually end up recursing, so we have to - * drop the mutex around it. - */ - CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); - status = _cairo_scaled_glyph_lookup (info->font, index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); - - if (unlikely (status)) - goto out_thaw; - - glyph_surface = scaled_glyph->surface; - glyph = pixman_glyph_cache_insert (glyph_cache, info->font, (void *)index, - glyph_surface->base.device_transform.x0, - glyph_surface->base.device_transform.y0, - glyph_surface->pixman_image); - if (unlikely (!glyph)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto out_thaw; - } - } - - pg->x = _cairo_lround (info->glyphs[i].x); - pg->y = _cairo_lround (info->glyphs[i].y); - pg->glyph = glyph; - pg++; - } - - if (info->use_mask) { - pixman_format_code_t mask_format; - - mask_format = pixman_glyph_get_mask_format (glyph_cache, pg - pglyphs, pglyphs); - - pixman_composite_glyphs (_pixman_operator (op), - ((cairo_image_source_t *)_src)->pixman_image, - to_pixman_image (_dst), - mask_format, - info->extents.x + src_x, info->extents.y + src_y, - info->extents.x, info->extents.y, - info->extents.x - dst_x, info->extents.y - dst_y, - info->extents.width, info->extents.height, - glyph_cache, pg - pglyphs, pglyphs); - } else { - pixman_composite_glyphs_no_mask (_pixman_operator (op), - ((cairo_image_source_t *)_src)->pixman_image, - to_pixman_image (_dst), - src_x, src_y, - - dst_x, - dst_y, - glyph_cache, pg - pglyphs, pglyphs); - } - -out_thaw: - pixman_glyph_cache_thaw (glyph_cache); - - if (pglyphs != pglyphs_stack) - free(pglyphs); - -out_unlock: - CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); - return status; -} -#else -void -_cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_t *scaled_glyph) -{ -} - -static cairo_int_status_t -composite_one_glyph (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - cairo_image_surface_t *glyph_surface; - cairo_scaled_glyph_t *scaled_glyph; - cairo_status_t status; - int x, y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = _cairo_scaled_glyph_lookup (info->font, - info->glyphs[0].index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - - if (unlikely (status)) - return status; - - glyph_surface = scaled_glyph->surface; - if (glyph_surface->width == 0 || glyph_surface->height == 0) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - /* round glyph locations to the nearest pixel */ - /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ - x = _cairo_lround (info->glyphs[0].x - - glyph_surface->base.device_transform.x0); - y = _cairo_lround (info->glyphs[0].y - - glyph_surface->base.device_transform.y0); - - pixman_image_composite32 (_pixman_operator (op), - ((cairo_image_source_t *)_src)->pixman_image, - glyph_surface->pixman_image, - to_pixman_image (_dst), - x + src_x, y + src_y, - 0, 0, - x - dst_x, y - dst_y, - glyph_surface->width, - glyph_surface->height); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_glyphs_via_mask (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - cairo_scaled_glyph_t *glyph_cache[64]; - pixman_image_t *white = _pixman_image_for_color (CAIRO_COLOR_WHITE); - cairo_scaled_glyph_t *scaled_glyph; - uint8_t buf[2048]; - pixman_image_t *mask; - pixman_format_code_t format; - cairo_status_t status; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (unlikely (white == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* XXX convert the glyphs to common formats a8/a8r8g8b8 to hit - * optimised paths through pixman. Should we increase the bit - * depth of the target surface, we should reconsider the appropriate - * mask formats. - */ - - status = _cairo_scaled_glyph_lookup (info->font, - info->glyphs[0].index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - if (unlikely (status)) { - pixman_image_unref (white); - return status; - } - - memset (glyph_cache, 0, sizeof (glyph_cache)); - glyph_cache[info->glyphs[0].index % ARRAY_LENGTH (glyph_cache)] = scaled_glyph; - - format = PIXMAN_a8; - i = (info->extents.width + 3) & ~3; - if (scaled_glyph->surface->base.content & CAIRO_CONTENT_COLOR) { - format = PIXMAN_a8r8g8b8; - i = info->extents.width * 4; - } - - if (i * info->extents.height > (int) sizeof (buf)) { - mask = pixman_image_create_bits (format, - info->extents.width, - info->extents.height, - NULL, 0); - } else { - memset (buf, 0, i * info->extents.height); - mask = pixman_image_create_bits (format, - info->extents.width, - info->extents.height, - (uint32_t *)buf, i); - } - if (unlikely (mask == NULL)) { - pixman_image_unref (white); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - status = CAIRO_STATUS_SUCCESS; - for (i = 0; i < info->num_glyphs; i++) { - unsigned long glyph_index = info->glyphs[i].index; - int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); - cairo_image_surface_t *glyph_surface; - int x, y; - - scaled_glyph = glyph_cache[cache_index]; - if (scaled_glyph == NULL || - _cairo_scaled_glyph_index (scaled_glyph) != glyph_index) - { - status = _cairo_scaled_glyph_lookup (info->font, glyph_index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - - if (unlikely (status)) { - pixman_image_unref (mask); - pixman_image_unref (white); - return status; - } - - glyph_cache[cache_index] = scaled_glyph; - } - - glyph_surface = scaled_glyph->surface; - if (glyph_surface->width && glyph_surface->height) { - if (glyph_surface->base.content & CAIRO_CONTENT_COLOR && - format == PIXMAN_a8) { - pixman_image_t *ca_mask; - - format = PIXMAN_a8r8g8b8; - ca_mask = pixman_image_create_bits (format, - info->extents.width, - info->extents.height, - NULL, 0); - if (unlikely (ca_mask == NULL)) { - pixman_image_unref (mask); - pixman_image_unref (white); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pixman_image_composite32 (PIXMAN_OP_SRC, - white, mask, ca_mask, - 0, 0, - 0, 0, - 0, 0, - info->extents.width, - info->extents.height); - pixman_image_unref (mask); - mask = ca_mask; - } - - /* round glyph locations to the nearest pixel */ - /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ - x = _cairo_lround (info->glyphs[i].x - - glyph_surface->base.device_transform.x0); - y = _cairo_lround (info->glyphs[i].y - - glyph_surface->base.device_transform.y0); - - if (glyph_surface->pixman_format == format) { - pixman_image_composite32 (PIXMAN_OP_ADD, - glyph_surface->pixman_image, NULL, mask, - 0, 0, - 0, 0, - x - info->extents.x, y - info->extents.y, - glyph_surface->width, - glyph_surface->height); - } else { - pixman_image_composite32 (PIXMAN_OP_ADD, - white, glyph_surface->pixman_image, mask, - 0, 0, - 0, 0, - x - info->extents.x, y - info->extents.y, - glyph_surface->width, - glyph_surface->height); - } - } - } - - if (format == PIXMAN_a8r8g8b8) - pixman_image_set_component_alpha (mask, TRUE); - - pixman_image_composite32 (_pixman_operator (op), - ((cairo_image_source_t *)_src)->pixman_image, - mask, - to_pixman_image (_dst), - info->extents.x + src_x, info->extents.y + src_y, - 0, 0, - info->extents.x - dst_x, info->extents.y - dst_y, - info->extents.width, info->extents.height); - pixman_image_unref (mask); - pixman_image_unref (white); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_glyphs (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - cairo_scaled_glyph_t *glyph_cache[64]; - pixman_image_t *dst, *src; - cairo_status_t status; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (info->num_glyphs == 1) - return composite_one_glyph(_dst, op, _src, src_x, src_y, dst_x, dst_y, info); - - if (info->use_mask) - return composite_glyphs_via_mask(_dst, op, _src, src_x, src_y, dst_x, dst_y, info); - - op = _pixman_operator (op); - dst = to_pixman_image (_dst); - src = ((cairo_image_source_t *)_src)->pixman_image; - - memset (glyph_cache, 0, sizeof (glyph_cache)); - status = CAIRO_STATUS_SUCCESS; - - for (i = 0; i < info->num_glyphs; i++) { - int x, y; - cairo_image_surface_t *glyph_surface; - cairo_scaled_glyph_t *scaled_glyph; - unsigned long glyph_index = info->glyphs[i].index; - int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); - - scaled_glyph = glyph_cache[cache_index]; - if (scaled_glyph == NULL || - _cairo_scaled_glyph_index (scaled_glyph) != glyph_index) - { - status = _cairo_scaled_glyph_lookup (info->font, glyph_index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - - if (unlikely (status)) - break; - - glyph_cache[cache_index] = scaled_glyph; - } - - glyph_surface = scaled_glyph->surface; - if (glyph_surface->width && glyph_surface->height) { - /* round glyph locations to the nearest pixel */ - /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ - x = _cairo_lround (info->glyphs[i].x - - glyph_surface->base.device_transform.x0); - y = _cairo_lround (info->glyphs[i].y - - glyph_surface->base.device_transform.y0); - - pixman_image_composite32 (op, src, glyph_surface->pixman_image, dst, - x + src_x, y + src_y, - 0, 0, - x - dst_x, y - dst_y, - glyph_surface->width, - glyph_surface->height); - } - } - - return status; -} -#endif - -static cairo_int_status_t -check_composite (const cairo_composite_rectangles_t *extents) -{ - return CAIRO_STATUS_SUCCESS; -} - -const cairo_compositor_t * -_cairo_image_traps_compositor_get (void) -{ - static cairo_traps_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_traps_compositor_init (&compositor, - &__cairo_no_compositor); - compositor.acquire = acquire; - compositor.release = release; - compositor.set_clip_region = set_clip_region; - compositor.pattern_to_surface = _cairo_image_source_create_for_pattern; - compositor.draw_image_boxes = draw_image_boxes; - //compositor.copy_boxes = copy_boxes; - compositor.fill_boxes = fill_boxes; - compositor.check_composite = check_composite; - compositor.composite = composite; - compositor.lerp = lerp; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - //compositor.check_composite_traps = check_composite_traps; - compositor.composite_traps = composite_traps; - //compositor.check_composite_tristrip = check_composite_traps; -#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) - compositor.composite_tristrip = composite_tristrip; -#endif - compositor.check_composite_glyphs = check_composite_glyphs; - compositor.composite_glyphs = composite_glyphs; - } - - return &compositor.base; -} - -const cairo_compositor_t * -_cairo_image_mask_compositor_get (void) -{ - static cairo_mask_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_mask_compositor_init (&compositor, - _cairo_image_traps_compositor_get ()); - compositor.acquire = acquire; - compositor.release = release; - compositor.set_clip_region = set_clip_region; - compositor.pattern_to_surface = _cairo_image_source_create_for_pattern; - compositor.draw_image_boxes = draw_image_boxes; - compositor.fill_rectangles = fill_rectangles; - compositor.fill_boxes = fill_boxes; - compositor.check_composite = check_composite; - compositor.composite = composite; - //compositor.lerp = lerp; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - compositor.check_composite_glyphs = check_composite_glyphs; - compositor.composite_glyphs = composite_glyphs; - } - - return &compositor.base; -} - -#if PIXMAN_HAS_COMPOSITOR -typedef struct _cairo_image_span_renderer { - cairo_span_renderer_t base; - - pixman_image_compositor_t *compositor; - pixman_image_t *src, *mask; - float opacity; - cairo_rectangle_int_t extents; -} cairo_image_span_renderer_t; -COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t)); - -static cairo_status_t -_cairo_image_bounded_opaque_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - do { - if (spans[0].coverage) - pixman_image_compositor_blt (r->compositor, - spans[0].x, y, - spans[1].x - spans[0].x, height, - spans[0].coverage); - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_image_bounded_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - do { - if (spans[0].coverage) { - pixman_image_compositor_blt (r->compositor, - spans[0].x, y, - spans[1].x - spans[0].x, height, - r->opacity * spans[0].coverage); - } - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_image_unbounded_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - assert (y + height <= r->extents.height); - if (y > r->extents.y) { - pixman_image_compositor_blt (r->compositor, - r->extents.x, r->extents.y, - r->extents.width, y - r->extents.y, - 0); - } - - if (num_spans == 0) { - pixman_image_compositor_blt (r->compositor, - r->extents.x, y, - r->extents.width, height, - 0); - } else { - if (spans[0].x != r->extents.x) { - pixman_image_compositor_blt (r->compositor, - r->extents.x, y, - spans[0].x - r->extents.x, - height, - 0); - } - - do { - assert (spans[0].x < r->extents.x + r->extents.width); - pixman_image_compositor_blt (r->compositor, - spans[0].x, y, - spans[1].x - spans[0].x, height, - r->opacity * spans[0].coverage); - spans++; - } while (--num_spans > 1); - - if (spans[0].x != r->extents.x + r->extents.width) { - assert (spans[0].x < r->extents.x + r->extents.width); - pixman_image_compositor_blt (r->compositor, - spans[0].x, y, - r->extents.x + r->extents.width - spans[0].x, height, - 0); - } - } - - r->extents.y = y + height; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_image_clipped_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - assert (num_spans); - - do { - if (! spans[0].inverse) - pixman_image_compositor_blt (r->compositor, - spans[0].x, y, - spans[1].x - spans[0].x, height, - r->opacity * spans[0].coverage); - spans++; - } while (--num_spans > 1); - - r->extents.y = y + height; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_image_finish_unbounded_spans (void *abstract_renderer) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (r->extents.y < r->extents.height) { - pixman_image_compositor_blt (r->compositor, - r->extents.x, r->extents.y, - r->extents.width, - r->extents.height - r->extents.y, - 0); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -span_renderer_init (cairo_abstract_span_renderer_t *_r, - const cairo_composite_rectangles_t *composite, - cairo_bool_t needs_clip) -{ - cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; - cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; - const cairo_pattern_t *source = &composite->source_pattern.base; - cairo_operator_t op = composite->op; - int src_x, src_y; - int mask_x, mask_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (op == CAIRO_OPERATOR_CLEAR) { - op = PIXMAN_OP_LERP_CLEAR; - } else if (dst->base.is_clear && - (op == CAIRO_OPERATOR_SOURCE || - op == CAIRO_OPERATOR_OVER || - op == CAIRO_OPERATOR_ADD)) { - op = PIXMAN_OP_SRC; - } else if (op == CAIRO_OPERATOR_SOURCE) { - op = PIXMAN_OP_LERP_SRC; - } else { - op = _pixman_operator (op); - } - - r->compositor = NULL; - r->mask = NULL; - r->src = _pixman_image_for_pattern (dst, source, FALSE, - &composite->unbounded, - &composite->source_sample_area, - &src_x, &src_y); - if (unlikely (r->src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - r->opacity = 1.0; - if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { - r->opacity = composite->mask_pattern.solid.color.alpha; - } else { - r->mask = _pixman_image_for_pattern (dst, - &composite->mask_pattern.base, - TRUE, - &composite->unbounded, - &composite->mask_sample_area, - &mask_x, &mask_y); - if (unlikely (r->mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* XXX Component-alpha? */ - if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && - _cairo_pattern_is_opaque (source, &composite->source_sample_area)) - { - pixman_image_unref (r->src); - r->src = r->mask; - src_x = mask_x; - src_y = mask_y; - r->mask = NULL; - } - } - - if (composite->is_bounded) { - if (r->opacity == 1.) - r->base.render_rows = _cairo_image_bounded_opaque_spans; - else - r->base.render_rows = _cairo_image_bounded_spans; - r->base.finish = NULL; - } else { - if (needs_clip) - r->base.render_rows = _cairo_image_clipped_spans; - else - r->base.render_rows = _cairo_image_unbounded_spans; - r->base.finish = _cairo_image_finish_unbounded_spans; - r->extents = composite->unbounded; - r->extents.height += r->extents.y; - } - - r->compositor = - pixman_image_create_compositor (op, r->src, r->mask, dst->pixman_image, - composite->unbounded.x + src_x, - composite->unbounded.y + src_y, - composite->unbounded.x + mask_x, - composite->unbounded.y + mask_y, - composite->unbounded.x, - composite->unbounded.y, - composite->unbounded.width, - composite->unbounded.height); - if (unlikely (r->compositor == NULL)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - return CAIRO_STATUS_SUCCESS; -} - -static void -span_renderer_fini (cairo_abstract_span_renderer_t *_r, - cairo_int_status_t status) -{ - cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *) _r; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (status == CAIRO_INT_STATUS_SUCCESS && r->base.finish) - r->base.finish (r); - - if (r->compositor) - pixman_image_compositor_destroy (r->compositor); - - if (r->src) - pixman_image_unref (r->src); - if (r->mask) - pixman_image_unref (r->mask); -} -#else -typedef struct _cairo_image_span_renderer { - cairo_span_renderer_t base; - - const cairo_composite_rectangles_t *composite; - - float opacity; - uint8_t op; - int bpp; - - pixman_image_t *src, *mask; - union { - struct fill { - int stride; - uint8_t *data; - uint32_t pixel; - } fill; - struct blit { - int stride; - uint8_t *data; - int src_stride; - uint8_t *src_data; - } blit; - struct composite { - pixman_image_t *dst; - int src_x, src_y; - int mask_x, mask_y; - int run_length; - } composite; - struct finish { - cairo_rectangle_int_t extents; - int src_x, src_y; - int stride; - uint8_t *data; - } mask; - } u; - uint8_t _buf[0]; -#define SZ_BUF (int)(sizeof (cairo_abstract_span_renderer_t) - sizeof (cairo_image_span_renderer_t)) -} cairo_image_span_renderer_t; -COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t)); - -static cairo_status_t -_cairo_image_spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - uint8_t *mask, *row; - int len; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - mask = r->u.mask.data + (y - r->u.mask.extents.y) * r->u.mask.stride; - mask += spans[0].x - r->u.mask.extents.x; - row = mask; - - do { - len = spans[1].x - spans[0].x; - if (spans[0].coverage) { - *row++ = r->opacity * spans[0].coverage; - if (--len) - memset (row, row[-1], len); - } - row += len; - spans++; - } while (--num_spans > 1); - - len = row - mask; - row = mask; - while (--height) { - mask += r->u.mask.stride; - memcpy (mask, row, len); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_image_spans_and_zero (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - uint8_t *mask; - int len; - - mask = r->u.mask.data; - if (y > r->u.mask.extents.y) { - len = (y - r->u.mask.extents.y) * r->u.mask.stride; - memset (mask, 0, len); - mask += len; - } - - r->u.mask.extents.y = y + height; - r->u.mask.data = mask + height * r->u.mask.stride; - if (num_spans == 0) { - memset (mask, 0, height * r->u.mask.stride); - } else { - uint8_t *row = mask; - - if (spans[0].x != r->u.mask.extents.x) { - len = spans[0].x - r->u.mask.extents.x; - memset (row, 0, len); - row += len; - } - - do { - len = spans[1].x - spans[0].x; - *row++ = r->opacity * spans[0].coverage; - if (len > 1) { - memset (row, row[-1], --len); - row += len; - } - spans++; - } while (--num_spans > 1); - - if (spans[0].x != r->u.mask.extents.x + r->u.mask.extents.width) { - len = r->u.mask.extents.x + r->u.mask.extents.width - spans[0].x; - memset (row, 0, len); - } - - row = mask; - while (--height) { - mask += r->u.mask.stride; - memcpy (mask, row, r->u.mask.extents.width); - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_image_finish_spans_and_zero (void *abstract_renderer) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (r->u.mask.extents.y < r->u.mask.extents.height) - memset (r->u.mask.data, 0, (r->u.mask.extents.height - r->u.mask.extents.y) * r->u.mask.stride); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_fill8_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - do { - if (spans[0].coverage) { - int len = spans[1].x - spans[0].x; - uint8_t *d = r->u.fill.data + r->u.fill.stride*y + spans[0].x; - if (len == 1) - *d = r->u.fill.pixel; - else - memset(d, r->u.fill.pixel, len); - } - spans++; - } while (--num_spans > 1); - } else { - do { - if (spans[0].coverage) { - int yy = y, hh = h; - do { - int len = spans[1].x - spans[0].x; - uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; - if (len == 1) - *d = r->u.fill.pixel; - else - memset(d, r->u.fill.pixel, len); - yy++; - } while (--hh); - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_fill16_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - do { - if (spans[0].coverage) { - int len = spans[1].x - spans[0].x; - uint16_t *d = (uint16_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*2); - while (len--) - *d++ = r->u.fill.pixel; - } - spans++; - } while (--num_spans > 1); - } else { - do { - if (spans[0].coverage) { - int yy = y, hh = h; - do { - int len = spans[1].x - spans[0].x; - uint16_t *d = (uint16_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*2); - while (len--) - *d++ = r->u.fill.pixel; - yy++; - } while (--hh); - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_fill32_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - do { - if (spans[0].coverage) { - int len = spans[1].x - spans[0].x; - if (len > 32) { - pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), r->bpp, - spans[0].x, y, len, 1, r->u.fill.pixel); - } else { - uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); - while (len--) - *d++ = r->u.fill.pixel; - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - if (spans[0].coverage) { - if (spans[1].x - spans[0].x > 16) { - pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), r->bpp, - spans[0].x, y, spans[1].x - spans[0].x, h, - r->u.fill.pixel); - } else { - int yy = y, hh = h; - do { - int len = spans[1].x - spans[0].x; - uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); - while (len--) - *d++ = r->u.fill.pixel; - yy++; - } while (--hh); - } - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -#if 0 -static cairo_status_t -_fill_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - do { - if (spans[0].coverage) { - pixman_fill ((uint32_t *) r->data, r->stride, r->bpp, - spans[0].x, y, - spans[1].x - spans[0].x, h, - r->pixel); - } - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} -#endif - -static cairo_status_t -_blit_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - int cpp; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - cpp = r->bpp/8; - if (likely (h == 1)) { - uint8_t *src = r->u.blit.src_data + y*r->u.blit.src_stride; - uint8_t *dst = r->u.blit.data + y*r->u.blit.stride; - do { - if (spans[0].coverage) { - void *s = src + spans[0].x*cpp; - void *d = dst + spans[0].x*cpp; - int len = (spans[1].x - spans[0].x) * cpp; - switch (len) { - case 1: - *(uint8_t *)d = *(uint8_t *)s; - break; - case 2: - *(uint16_t *)d = *(uint16_t *)s; - break; - case 4: - *(uint32_t *)d = *(uint32_t *)s; - break; -#if HAVE_UINT64_T - case 8: - *(uint64_t *)d = *(uint64_t *)s; - break; -#endif - default: - memcpy(d, s, len); - break; - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - if (spans[0].coverage) { - int yy = y, hh = h; - do { - void *src = r->u.blit.src_data + yy*r->u.blit.src_stride + spans[0].x*cpp; - void *dst = r->u.blit.data + yy*r->u.blit.stride + spans[0].x*cpp; - int len = (spans[1].x - spans[0].x) * cpp; - switch (len) { - case 1: - *(uint8_t *)dst = *(uint8_t *)src; - break; - case 2: - *(uint16_t *)dst = *(uint16_t *)src; - break; - case 4: - *(uint32_t *)dst = *(uint32_t *)src; - break; -#if HAVE_UINT64_T - case 8: - *(uint64_t *)dst = *(uint64_t *)src; - break; -#endif - default: - memcpy(dst, src, len); - break; - } - yy++; - } while (--hh); - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_mono_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - do { - if (spans[0].coverage) { - pixman_image_composite32 (r->op, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, - 0, 0, - spans[0].x, y, - spans[1].x - spans[0].x, h); - } - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_mono_unbounded_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) { - pixman_image_composite32 (PIXMAN_OP_CLEAR, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, - 0, 0, - r->composite->unbounded.x, y, - r->composite->unbounded.width, h); - r->u.composite.mask_y = y + h; - return CAIRO_STATUS_SUCCESS; - } - - if (y != r->u.composite.mask_y) { - pixman_image_composite32 (PIXMAN_OP_CLEAR, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, - 0, 0, - r->composite->unbounded.x, r->u.composite.mask_y, - r->composite->unbounded.width, y - r->u.composite.mask_y); - } - - if (spans[0].x != r->composite->unbounded.x) { - pixman_image_composite32 (PIXMAN_OP_CLEAR, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, - 0, 0, - r->composite->unbounded.x, y, - spans[0].x - r->composite->unbounded.x, h); - } - - do { - int op = spans[0].coverage ? r->op : PIXMAN_OP_CLEAR; - pixman_image_composite32 (op, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, - 0, 0, - spans[0].x, y, - spans[1].x - spans[0].x, h); - spans++; - } while (--num_spans > 1); - - if (spans[0].x != r->composite->unbounded.x + r->composite->unbounded.width) { - pixman_image_composite32 (PIXMAN_OP_CLEAR, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, - 0, 0, - spans[0].x, y, - r->composite->unbounded.x + r->composite->unbounded.width - spans[0].x, h); - } - - r->u.composite.mask_y = y + h; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_mono_finish_unbounded_spans (void *abstract_renderer) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (r->u.composite.mask_y < r->composite->unbounded.y + r->composite->unbounded.height) { - pixman_image_composite32 (PIXMAN_OP_CLEAR, - r->src, NULL, r->u.composite.dst, - r->composite->unbounded.x + r->u.composite.src_x, r->u.composite.mask_y + r->u.composite.src_y, - 0, 0, - r->composite->unbounded.x, r->u.composite.mask_y, - r->composite->unbounded.width, - r->composite->unbounded.y + r->composite->unbounded.height - r->u.composite.mask_y); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -mono_renderer_init (cairo_image_span_renderer_t *r, - const cairo_composite_rectangles_t *composite, - cairo_antialias_t antialias, - cairo_bool_t needs_clip) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; - - if (antialias != CAIRO_ANTIALIAS_NONE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (!_cairo_pattern_is_opaque_solid (&composite->mask_pattern.base)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - r->base.render_rows = NULL; - if (composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { - const cairo_color_t *color; - - color = &composite->source_pattern.solid.color; - if (composite->op == CAIRO_OPERATOR_CLEAR) - color = CAIRO_COLOR_TRANSPARENT; - - if (fill_reduces_to_source (composite->op, color, dst, &r->u.fill.pixel)) { - /* Use plain C for the fill operations as the span length is - * typically small, too small to payback the startup overheads of - * using SSE2 etc. - */ - switch (PIXMAN_FORMAT_BPP(dst->pixman_format)) { - case 8: r->base.render_rows = _fill8_spans; break; - case 16: r->base.render_rows = _fill16_spans; break; - case 32: r->base.render_rows = _fill32_spans; break; - default: break; - } - r->u.fill.data = dst->data; - r->u.fill.stride = dst->stride; - } - } else if ((composite->op == CAIRO_OPERATOR_SOURCE || - (composite->op == CAIRO_OPERATOR_OVER && - (dst->base.is_clear || (dst->base.content & CAIRO_CONTENT_ALPHA) == 0))) && - composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && - composite->source_pattern.surface.surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE && - to_image_surface(composite->source_pattern.surface.surface)->format == dst->format) - { - cairo_image_surface_t *src = - to_image_surface(composite->source_pattern.surface.surface); - int tx, ty; - - if (_cairo_matrix_is_integer_translation(&composite->source_pattern.base.matrix, - &tx, &ty) && - composite->bounded.x + tx >= 0 && - composite->bounded.y + ty >= 0 && - composite->bounded.x + composite->bounded.width + tx <= src->width && - composite->bounded.y + composite->bounded.height + ty <= src->height) { - - r->u.blit.stride = dst->stride; - r->u.blit.data = dst->data; - r->u.blit.src_stride = src->stride; - r->u.blit.src_data = src->data + src->stride * ty + tx * 4; - r->base.render_rows = _blit_spans; - } - } - - if (r->base.render_rows == NULL) { - r->src = _pixman_image_for_pattern (dst, &composite->source_pattern.base, FALSE, - &composite->unbounded, - &composite->source_sample_area, - &r->u.composite.src_x, &r->u.composite.src_y); - if (unlikely (r->src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - r->u.composite.dst = to_pixman_image (composite->surface); - r->op = _pixman_operator (composite->op); - if (composite->is_bounded == 0) { - r->base.render_rows = _mono_unbounded_spans; - r->base.finish = _mono_finish_unbounded_spans; - r->u.composite.mask_y = composite->unbounded.y; - } else - r->base.render_rows = _mono_spans; - } - r->bpp = PIXMAN_FORMAT_BPP(dst->pixman_format); - - return CAIRO_INT_STATUS_SUCCESS; -} - -#define ONE_HALF 0x7f -#define RB_MASK 0x00ff00ff -#define RB_ONE_HALF 0x007f007f -#define RB_MASK_PLUS_ONE 0x01000100 -#define G_SHIFT 8 -static inline uint32_t -mul8x2_8 (uint32_t a, uint8_t b) -{ - uint32_t t = (a & RB_MASK) * b + RB_ONE_HALF; - return ((t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT) & RB_MASK; -} - -static inline uint32_t -add8x2_8x2 (uint32_t a, uint32_t b) -{ - uint32_t t = a + b; - t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK); - return t & RB_MASK; -} - -static inline uint8_t -mul8_8 (uint8_t a, uint8_t b) -{ - uint16_t t = a * (uint16_t)b + ONE_HALF; - return ((t >> G_SHIFT) + t) >> G_SHIFT; -} - -static inline uint32_t -lerp8x4 (uint32_t src, uint8_t a, uint32_t dst) -{ - return (add8x2_8x2 (mul8x2_8 (src, a), - mul8x2_8 (dst, ~a)) | - add8x2_8x2 (mul8x2_8 (src >> G_SHIFT, a), - mul8x2_8 (dst >> G_SHIFT, ~a)) << G_SHIFT); -} - -static cairo_status_t -_fill_a8_lerp_opaque_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - uint8_t *d = r->u.fill.data + r->u.fill.stride*y; - do { - uint8_t a = spans[0].coverage; - if (a) { - int len = spans[1].x - spans[0].x; - if (a == 0xff) { - memset(d + spans[0].x, r->u.fill.pixel, len); - } else { - uint8_t s = mul8_8(a, r->u.fill.pixel); - uint8_t *dst = d + spans[0].x; - a = ~a; - while (len--) { - uint8_t t = mul8_8(*dst, a); - *dst++ = t + s; - } - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - uint8_t a = spans[0].coverage; - if (a) { - int yy = y, hh = h; - if (a == 0xff) { - do { - int len = spans[1].x - spans[0].x; - uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; - memset(d, r->u.fill.pixel, len); - yy++; - } while (--hh); - } else { - uint8_t s = mul8_8(a, r->u.fill.pixel); - a = ~a; - do { - int len = spans[1].x - spans[0].x; - uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; - while (len--) { - uint8_t t = mul8_8(*d, a); - *d++ = t + s; - } - yy++; - } while (--hh); - } - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_fill_xrgb32_lerp_opaque_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - do { - uint8_t a = spans[0].coverage; - if (a) { - int len = spans[1].x - spans[0].x; - uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); - if (a == 0xff) { - if (len > 31) { - pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), 32, - spans[0].x, y, len, 1, r->u.fill.pixel); - } else { - uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); - while (len-- > 0) - *d++ = r->u.fill.pixel; - } - } else while (len-- > 0) { - *d = lerp8x4 (r->u.fill.pixel, a, *d); - d++; - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - uint8_t a = spans[0].coverage; - if (a) { - if (a == 0xff) { - if (spans[1].x - spans[0].x > 16) { - pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), 32, - spans[0].x, y, spans[1].x - spans[0].x, h, - r->u.fill.pixel); - } else { - int yy = y, hh = h; - do { - int len = spans[1].x - spans[0].x; - uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); - while (len--) - *d++ = r->u.fill.pixel; - yy++; - } while (--hh); - } - } else { - int yy = y, hh = h; - do { - int len = spans[1].x - spans[0].x; - uint32_t *d = (uint32_t *)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); - while (len--) { - *d = lerp8x4 (r->u.fill.pixel, a, *d); - d++; - } - yy++; - } while (--hh); - } - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_fill_a8_lerp_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - do { - uint8_t a = mul8_8 (spans[0].coverage, r->bpp); - if (a) { - int len = spans[1].x - spans[0].x; - uint8_t *d = r->u.fill.data + r->u.fill.stride*y + spans[0].x; - uint16_t p = (uint16_t)a * r->u.fill.pixel + 0x7f; - uint16_t ia = ~a; - while (len--) { - uint16_t t = *d*ia + p; - *d++ = (t + (t>>8)) >> 8; - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - uint8_t a = mul8_8 (spans[0].coverage, r->bpp); - if (a) { - int yy = y, hh = h; - uint16_t p = (uint16_t)a * r->u.fill.pixel + 0x7f; - uint16_t ia = ~a; - do { - int len = spans[1].x - spans[0].x; - uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; - while (len--) { - uint16_t t = *d*ia + p; - *d++ = (t + (t>>8)) >> 8; - } - yy++; - } while (--hh); - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_fill_xrgb32_lerp_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - do { - uint8_t a = mul8_8 (spans[0].coverage, r->bpp); - if (a) { - int len = spans[1].x - spans[0].x; - uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); - while (len--) { - *d = lerp8x4 (r->u.fill.pixel, a, *d); - d++; - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - uint8_t a = mul8_8 (spans[0].coverage, r->bpp); - if (a) { - int yy = y, hh = h; - do { - int len = spans[1].x - spans[0].x; - uint32_t *d = (uint32_t *)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); - while (len--) { - *d = lerp8x4 (r->u.fill.pixel, a, *d); - d++; - } - yy++; - } while (--hh); - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_blit_xrgb32_lerp_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (likely(h == 1)) { - uint8_t *src = r->u.blit.src_data + y*r->u.blit.src_stride; - uint8_t *dst = r->u.blit.data + y*r->u.blit.stride; - do { - uint8_t a = mul8_8 (spans[0].coverage, r->bpp); - if (a) { - uint32_t *s = (uint32_t*)src + spans[0].x; - uint32_t *d = (uint32_t*)dst + spans[0].x; - int len = spans[1].x - spans[0].x; - if (a == 0xff) { - if (len == 1) - *d = *s; - else - memcpy(d, s, len*4); - } else { - while (len--) { - *d = lerp8x4 (*s, a, *d); - s++, d++; - } - } - } - spans++; - } while (--num_spans > 1); - } else { - do { - uint8_t a = mul8_8 (spans[0].coverage, r->bpp); - if (a) { - int yy = y, hh = h; - do { - uint32_t *s = (uint32_t *)(r->u.blit.src_data + yy*r->u.blit.src_stride + spans[0].x * 4); - uint32_t *d = (uint32_t *)(r->u.blit.data + yy*r->u.blit.stride + spans[0].x * 4); - int len = spans[1].x - spans[0].x; - if (a == 0xff) { - if (len == 1) - *d = *s; - else - memcpy(d, s, len * 4); - } else { - while (len--) { - *d = lerp8x4 (*s, a, *d); - s++, d++; - } - } - yy++; - } while (--hh); - } - spans++; - } while (--num_spans > 1); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_inplace_spans (void *abstract_renderer, - int y, int h, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - uint8_t *mask; - int x0, x1; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - if (num_spans == 2 && spans[0].coverage == 0xff) { - pixman_image_composite32 (r->op, r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - spans[0].x, y, - spans[1].x - spans[0].x, h); - return CAIRO_STATUS_SUCCESS; - } - - mask = (uint8_t *)pixman_image_get_data (r->mask); - x1 = x0 = spans[0].x; - do { - int len = spans[1].x - spans[0].x; - *mask++ = spans[0].coverage; - if (len > 1) { - if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) { - if (x1 != x0) { - pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - x1 - x0, h); - } - pixman_image_composite32 (r->op, r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - spans[0].x, y, - len, h); - mask = (uint8_t *)pixman_image_get_data (r->mask); - x0 = spans[1].x; - } else if (spans[0].coverage == 0x0 && - x1 - x0 > r->u.composite.run_length) { - pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - x1 - x0, h); - mask = (uint8_t *)pixman_image_get_data (r->mask); - x0 = spans[1].x; - }else { - memset (mask, spans[0].coverage, --len); - mask += len; - } - } - x1 = spans[1].x; - spans++; - } while (--num_spans > 1); - - if (x1 != x0) { - pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - x1 - x0, h); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_inplace_opacity_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - uint8_t *mask; - int x0, x1; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - mask = (uint8_t *)pixman_image_get_data (r->mask); - x1 = x0 = spans[0].x; - do { - int len = spans[1].x - spans[0].x; - uint8_t m = mul8_8(spans[0].coverage, r->bpp); - *mask++ = m; - if (len > 1) { - if (m == 0 && - x1 - x0 > r->u.composite.run_length) { - pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - x1 - x0, h); - mask = (uint8_t *)pixman_image_get_data (r->mask); - x0 = spans[1].x; - }else { - memset (mask, m, --len); - mask += len; - } - } - x1 = spans[1].x; - spans++; - } while (--num_spans > 1); - - if (x1 != x0) { - pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - x1 - x0, h); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_inplace_src_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - uint8_t *m; - int x0; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - x0 = spans[0].x; - m = r->_buf; - do { - int len = spans[1].x - spans[0].x; - if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) { - if (spans[0].x != x0) { -#if PIXMAN_HAS_OP_LERP - pixman_image_composite32 (PIXMAN_OP_LERP_SRC, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#else - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - r->mask, NULL, r->u.composite.dst, - 0, 0, - 0, 0, - x0, y, - spans[0].x - x0, h); - pixman_image_composite32 (PIXMAN_OP_ADD, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#endif - } - - pixman_image_composite32 (PIXMAN_OP_SRC, - r->src, NULL, r->u.composite.dst, - spans[0].x + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - spans[0].x, y, - spans[1].x - spans[0].x, h); - - m = r->_buf; - x0 = spans[1].x; - } else if (spans[0].coverage == 0x0) { - if (spans[0].x != x0) { -#if PIXMAN_HAS_OP_LERP - pixman_image_composite32 (PIXMAN_OP_LERP_SRC, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#else - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - r->mask, NULL, r->u.composite.dst, - 0, 0, - 0, 0, - x0, y, - spans[0].x - x0, h); - pixman_image_composite32 (PIXMAN_OP_ADD, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#endif - } - - m = r->_buf; - x0 = spans[1].x; - } else { - *m++ = spans[0].coverage; - if (len > 1) { - memset (m, spans[0].coverage, --len); - m += len; - } - } - spans++; - } while (--num_spans > 1); - - if (spans[0].x != x0) { -#if PIXMAN_HAS_OP_LERP - pixman_image_composite32 (PIXMAN_OP_LERP_SRC, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#else - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - r->mask, NULL, r->u.composite.dst, - 0, 0, - 0, 0, - x0, y, - spans[0].x - x0, h); - pixman_image_composite32 (PIXMAN_OP_ADD, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#endif - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_inplace_src_opacity_spans (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - cairo_image_span_renderer_t *r = abstract_renderer; - uint8_t *mask; - int x0; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - x0 = spans[0].x; - mask = (uint8_t *)pixman_image_get_data (r->mask); - do { - int len = spans[1].x - spans[0].x; - uint8_t m = mul8_8(spans[0].coverage, r->bpp); - if (m == 0) { - if (spans[0].x != x0) { -#if PIXMAN_HAS_OP_LERP - pixman_image_composite32 (PIXMAN_OP_LERP_SRC, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#else - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - r->mask, NULL, r->u.composite.dst, - 0, 0, - 0, 0, - x0, y, - spans[0].x - x0, h); - pixman_image_composite32 (PIXMAN_OP_ADD, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#endif - } - - mask = (uint8_t *)pixman_image_get_data (r->mask); - x0 = spans[1].x; - } else { - *mask++ = m; - if (len > 1) { - memset (mask, m, --len); - mask += len; - } - } - spans++; - } while (--num_spans > 1); - - if (spans[0].x != x0) { -#if PIXMAN_HAS_OP_LERP - pixman_image_composite32 (PIXMAN_OP_LERP_SRC, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#else - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - r->mask, NULL, r->u.composite.dst, - 0, 0, - 0, 0, - x0, y, - spans[0].x - x0, h); - pixman_image_composite32 (PIXMAN_OP_ADD, - r->src, r->mask, r->u.composite.dst, - x0 + r->u.composite.src_x, - y + r->u.composite.src_y, - 0, 0, - x0, y, - spans[0].x - x0, h); -#endif - } - - return CAIRO_STATUS_SUCCESS; -} - -static void free_pixels (pixman_image_t *image, void *data) -{ - free (data); -} - -static cairo_int_status_t -inplace_renderer_init (cairo_image_span_renderer_t *r, - const cairo_composite_rectangles_t *composite, - cairo_antialias_t antialias, - cairo_bool_t needs_clip) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; - uint8_t *buf; - - if (composite->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) - return CAIRO_INT_STATUS_UNSUPPORTED; - - r->base.render_rows = NULL; - r->bpp = composite->mask_pattern.solid.color.alpha_short >> 8; - - if (composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { - const cairo_color_t *color; - - color = &composite->source_pattern.solid.color; - if (composite->op == CAIRO_OPERATOR_CLEAR) - color = CAIRO_COLOR_TRANSPARENT; - - if (fill_reduces_to_source (composite->op, color, dst, &r->u.fill.pixel)) { - /* Use plain C for the fill operations as the span length is - * typically small, too small to payback the startup overheads of - * using SSE2 etc. - */ - if (r->bpp == 0xff) { - switch (dst->format) { - case CAIRO_FORMAT_A8: - r->base.render_rows = _fill_a8_lerp_opaque_spans; - break; - case CAIRO_FORMAT_RGB24: - case CAIRO_FORMAT_ARGB32: - r->base.render_rows = _fill_xrgb32_lerp_opaque_spans; - break; - case CAIRO_FORMAT_A1: - case CAIRO_FORMAT_RGB16_565: - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_INVALID: - default: break; - } - } else { - switch (dst->format) { - case CAIRO_FORMAT_A8: - r->base.render_rows = _fill_a8_lerp_spans; - break; - case CAIRO_FORMAT_RGB24: - case CAIRO_FORMAT_ARGB32: - r->base.render_rows = _fill_xrgb32_lerp_spans; - break; - case CAIRO_FORMAT_A1: - case CAIRO_FORMAT_RGB16_565: - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_INVALID: - default: break; - } - } - r->u.fill.data = dst->data; - r->u.fill.stride = dst->stride; - } - } else if ((dst->format == CAIRO_FORMAT_ARGB32 || dst->format == CAIRO_FORMAT_RGB24) && - (composite->op == CAIRO_OPERATOR_SOURCE || - (composite->op == CAIRO_OPERATOR_OVER && - (dst->base.is_clear || (dst->base.content & CAIRO_CONTENT_ALPHA) == 0))) && - composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && - composite->source_pattern.surface.surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE && - to_image_surface(composite->source_pattern.surface.surface)->format == dst->format) - { - cairo_image_surface_t *src = - to_image_surface(composite->source_pattern.surface.surface); - int tx, ty; - - if (_cairo_matrix_is_integer_translation(&composite->source_pattern.base.matrix, - &tx, &ty) && - composite->bounded.x + tx >= 0 && - composite->bounded.y + ty >= 0 && - composite->bounded.x + composite->bounded.width + tx <= src->width && - composite->bounded.y + composite->bounded.height + ty <= src->height) { - - assert(PIXMAN_FORMAT_BPP(dst->pixman_format) == 32); - r->u.blit.stride = dst->stride; - r->u.blit.data = dst->data; - r->u.blit.src_stride = src->stride; - r->u.blit.src_data = src->data + src->stride * ty + tx * 4; - r->base.render_rows = _blit_xrgb32_lerp_spans; - } - } - if (r->base.render_rows == NULL) { - const cairo_pattern_t *src = &composite->source_pattern.base; - unsigned int width; - - if (composite->is_bounded == 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - r->base.render_rows = r->bpp == 0xff ? _inplace_spans : _inplace_opacity_spans; - width = (composite->bounded.width + 3) & ~3; - - r->u.composite.run_length = 8; - if (src->type == CAIRO_PATTERN_TYPE_LINEAR || - src->type == CAIRO_PATTERN_TYPE_RADIAL) - r->u.composite.run_length = 256; - if (dst->base.is_clear && - (composite->op == CAIRO_OPERATOR_SOURCE || - composite->op == CAIRO_OPERATOR_OVER || - composite->op == CAIRO_OPERATOR_ADD)) { - r->op = PIXMAN_OP_SRC; - } else if (composite->op == CAIRO_OPERATOR_SOURCE) { - r->base.render_rows = r->bpp == 0xff ? _inplace_src_spans : _inplace_src_opacity_spans; - r->u.composite.mask_y = r->composite->unbounded.y; - width = (composite->unbounded.width + 3) & ~3; - } else if (composite->op == CAIRO_OPERATOR_CLEAR) { - r->op = PIXMAN_OP_OUT_REVERSE; - src = NULL; - } else { - r->op = _pixman_operator (composite->op); - } - - r->src = _pixman_image_for_pattern (dst, src, FALSE, - &composite->bounded, - &composite->source_sample_area, - &r->u.composite.src_x, &r->u.composite.src_y); - if (unlikely (r->src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* Create an effectively unbounded mask by repeating the single line */ - buf = r->_buf; - if (width > SZ_BUF) { - buf = malloc (width); - if (unlikely (buf == NULL)) { - pixman_image_unref (r->src); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - r->mask = pixman_image_create_bits (PIXMAN_a8, - width, composite->unbounded.height, - (uint32_t *)buf, 0); - if (unlikely (r->mask == NULL)) { - pixman_image_unref (r->src); - if (buf != r->_buf) - free (buf); - return _cairo_error(CAIRO_STATUS_NO_MEMORY); - } - - if (buf != r->_buf) - pixman_image_set_destroy_function (r->mask, free_pixels, buf); - - r->u.composite.dst = dst->pixman_image; - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -span_renderer_init (cairo_abstract_span_renderer_t *_r, - const cairo_composite_rectangles_t *composite, - cairo_antialias_t antialias, - cairo_bool_t needs_clip) -{ - cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; - cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; - const cairo_pattern_t *source = &composite->source_pattern.base; - cairo_operator_t op = composite->op; - cairo_int_status_t status; - - TRACE ((stderr, "%s: antialias=%d, needs_clip=%d\n", __FUNCTION__, - antialias, needs_clip)); - - if (needs_clip) - return CAIRO_INT_STATUS_UNSUPPORTED; - - r->composite = composite; - r->mask = NULL; - r->src = NULL; - r->base.finish = NULL; - - status = mono_renderer_init (r, composite, antialias, needs_clip); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = inplace_renderer_init (r, composite, antialias, needs_clip); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - r->bpp = 0; - - if (op == CAIRO_OPERATOR_CLEAR) { -#if PIXMAN_HAS_OP_LERP - op = PIXMAN_OP_LERP_CLEAR; -#else - source = &_cairo_pattern_white.base; - op = PIXMAN_OP_OUT_REVERSE; -#endif - } else if (dst->base.is_clear && - (op == CAIRO_OPERATOR_SOURCE || - op == CAIRO_OPERATOR_OVER || - op == CAIRO_OPERATOR_ADD)) { - op = PIXMAN_OP_SRC; - } else if (op == CAIRO_OPERATOR_SOURCE) { - if (_cairo_pattern_is_opaque (&composite->source_pattern.base, - &composite->source_sample_area)) - { - op = PIXMAN_OP_OVER; - } - else - { -#if PIXMAN_HAS_OP_LERP - op = PIXMAN_OP_LERP_SRC; -#else - return CAIRO_INT_STATUS_UNSUPPORTED; -#endif - } - } else { - op = _pixman_operator (op); - } - r->op = op; - - r->src = _pixman_image_for_pattern (dst, source, FALSE, - &composite->unbounded, - &composite->source_sample_area, - &r->u.mask.src_x, &r->u.mask.src_y); - if (unlikely (r->src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - r->opacity = 1.0; - if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { - r->opacity = composite->mask_pattern.solid.color.alpha; - } else { - pixman_image_t *mask; - int mask_x, mask_y; - - mask = _pixman_image_for_pattern (dst, - &composite->mask_pattern.base, - TRUE, - &composite->unbounded, - &composite->mask_sample_area, - &mask_x, &mask_y); - if (unlikely (mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* XXX Component-alpha? */ - if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && - _cairo_pattern_is_opaque (source, &composite->source_sample_area)) - { - pixman_image_unref (r->src); - r->src = mask; - r->u.mask.src_x = mask_x; - r->u.mask.src_y = mask_y; - mask = NULL; - } - - if (mask) { - pixman_image_unref (mask); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - - r->u.mask.extents = composite->unbounded; - r->u.mask.stride = (r->u.mask.extents.width + 3) & ~3; - if (r->u.mask.extents.height * r->u.mask.stride > SZ_BUF) { - r->mask = pixman_image_create_bits (PIXMAN_a8, - r->u.mask.extents.width, - r->u.mask.extents.height, - NULL, 0); - - r->base.render_rows = _cairo_image_spans; - r->base.finish = NULL; - } else { - r->mask = pixman_image_create_bits (PIXMAN_a8, - r->u.mask.extents.width, - r->u.mask.extents.height, - (uint32_t *)r->_buf, r->u.mask.stride); - - r->base.render_rows = _cairo_image_spans_and_zero; - r->base.finish = _cairo_image_finish_spans_and_zero; - } - if (unlikely (r->mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - r->u.mask.data = (uint8_t *) pixman_image_get_data (r->mask); - r->u.mask.stride = pixman_image_get_stride (r->mask); - - r->u.mask.extents.height += r->u.mask.extents.y; - return CAIRO_STATUS_SUCCESS; -} - -static void -span_renderer_fini (cairo_abstract_span_renderer_t *_r, - cairo_int_status_t status) -{ - cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *) _r; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - if (r->base.finish) - r->base.finish (r); - } - if (likely (status == CAIRO_INT_STATUS_SUCCESS && r->bpp == 0)) { - const cairo_composite_rectangles_t *composite = r->composite; - - pixman_image_composite32 (r->op, r->src, r->mask, - to_pixman_image (composite->surface), - composite->unbounded.x + r->u.mask.src_x, - composite->unbounded.y + r->u.mask.src_y, - 0, 0, - composite->unbounded.x, - composite->unbounded.y, - composite->unbounded.width, - composite->unbounded.height); - } - - if (r->src) - pixman_image_unref (r->src); - if (r->mask) - pixman_image_unref (r->mask); -} -#endif - -const cairo_compositor_t * -_cairo_image_spans_compositor_get (void) -{ - static cairo_spans_compositor_t spans; - static cairo_compositor_t shape; - - if (spans.base.delegate == NULL) { - _cairo_shape_mask_compositor_init (&shape, - _cairo_image_traps_compositor_get()); - shape.glyphs = NULL; - - _cairo_spans_compositor_init (&spans, &shape); - - spans.flags = 0; -#if PIXMAN_HAS_OP_LERP - spans.flags |= CAIRO_SPANS_COMPOSITOR_HAS_LERP; -#endif - - //spans.acquire = acquire; - //spans.release = release; - spans.fill_boxes = fill_boxes; - spans.draw_image_boxes = draw_image_boxes; - //spans.copy_boxes = copy_boxes; - spans.pattern_to_surface = _cairo_image_source_create_for_pattern; - //spans.check_composite_boxes = check_composite_boxes; - spans.composite_boxes = composite_boxes; - //spans.check_span_renderer = check_span_renderer; - spans.renderer_init = span_renderer_init; - spans.renderer_fini = span_renderer_fini; - } - - return &spans.base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info-private.h deleted file mode 100644 index e64928e40ec..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info-private.h +++ /dev/null @@ -1,68 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - */ - -#ifndef CAIRO_IMAGE_INFO_PRIVATE_H -#define CAIRO_IMAGE_INFO_PRIVATE_H - -#include "cairoint.h" - -typedef struct _cairo_image_info { - int width; - int height; - int num_components; - int bits_per_component; -} cairo_image_info_t; - -cairo_private cairo_int_status_t -_cairo_image_info_get_jpeg_info (cairo_image_info_t *info, - const unsigned char *data, - long length); - -cairo_private cairo_int_status_t -_cairo_image_info_get_jpx_info (cairo_image_info_t *info, - const unsigned char *data, - unsigned long length); - -cairo_private cairo_int_status_t -_cairo_image_info_get_png_info (cairo_image_info_t *info, - const unsigned char *data, - unsigned long length); - -cairo_private cairo_int_status_t -_cairo_image_info_get_jbig2_info (cairo_image_info_t *info, - const unsigned char *data, - unsigned long length); - -#endif /* CAIRO_IMAGE_INFO_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info.c deleted file mode 100644 index 26e7ae5afd1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-info.c +++ /dev/null @@ -1,421 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-image-info-private.h" - -/* JPEG (image/jpeg) - * - * http://www.w3.org/Graphics/JPEG/itu-t81.pdf - */ - -/* Markers with no parameters. All other markers are followed by a two - * byte length of the parameters. */ -#define TEM 0x01 -#define RST_begin 0xd0 -#define RST_end 0xd7 -#define SOI 0xd8 -#define EOI 0xd9 - -/* Start of frame markers. */ -#define SOF0 0xc0 -#define SOF1 0xc1 -#define SOF2 0xc2 -#define SOF3 0xc3 -#define SOF5 0xc5 -#define SOF6 0xc6 -#define SOF7 0xc7 -#define SOF9 0xc9 -#define SOF10 0xca -#define SOF11 0xcb -#define SOF13 0xcd -#define SOF14 0xce -#define SOF15 0xcf - -static const unsigned char * -_jpeg_skip_segment (const unsigned char *p) -{ - int len; - - p++; - len = (p[0] << 8) | p[1]; - - return p + len; -} - -static void -_jpeg_extract_info (cairo_image_info_t *info, const unsigned char *p) -{ - info->width = (p[6] << 8) + p[7]; - info->height = (p[4] << 8) + p[5]; - info->num_components = p[8]; - info->bits_per_component = p[3]; -} - -cairo_int_status_t -_cairo_image_info_get_jpeg_info (cairo_image_info_t *info, - const unsigned char *data, - long length) -{ - const unsigned char *p = data; - - while (p + 1 < data + length) { - if (*p != 0xff) - return CAIRO_INT_STATUS_UNSUPPORTED; - p++; - - switch (*p) { - /* skip fill bytes */ - case 0xff: - p++; - break; - - case TEM: - case SOI: - case EOI: - p++; - break; - - case SOF0: - case SOF1: - case SOF2: - case SOF3: - case SOF5: - case SOF6: - case SOF7: - case SOF9: - case SOF10: - case SOF11: - case SOF13: - case SOF14: - case SOF15: - /* Start of frame found. Extract the image parameters. */ - if (p + 8 > data + length) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _jpeg_extract_info (info, p); - return CAIRO_STATUS_SUCCESS; - - default: - if (*p >= RST_begin && *p <= RST_end) { - p++; - break; - } - - if (p + 2 > data + length) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p = _jpeg_skip_segment (p); - break; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -/* JPEG 2000 (image/jp2) - * - * http://www.jpeg.org/public/15444-1annexi.pdf - */ - -#define JPX_FILETYPE 0x66747970 -#define JPX_JP2_HEADER 0x6A703268 -#define JPX_IMAGE_HEADER 0x69686472 - -static const unsigned char _jpx_signature[] = { - 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a -}; - -static const unsigned char * -_jpx_next_box (const unsigned char *p) -{ - return p + get_unaligned_be32 (p); -} - -static const unsigned char * -_jpx_get_box_contents (const unsigned char *p) -{ - return p + 8; -} - -static cairo_bool_t -_jpx_match_box (const unsigned char *p, const unsigned char *end, uint32_t type) -{ - uint32_t length; - - if (p + 8 < end) { - length = get_unaligned_be32 (p); - if (get_unaligned_be32 (p + 4) == type && p + length < end) - return TRUE; - } - - return FALSE; -} - -static const unsigned char * -_jpx_find_box (const unsigned char *p, const unsigned char *end, uint32_t type) -{ - while (p < end) { - if (_jpx_match_box (p, end, type)) - return p; - p = _jpx_next_box (p); - } - - return NULL; -} - -static void -_jpx_extract_info (const unsigned char *p, cairo_image_info_t *info) -{ - info->height = get_unaligned_be32 (p); - info->width = get_unaligned_be32 (p + 4); - info->num_components = (p[8] << 8) + p[9]; - info->bits_per_component = p[10]; -} - -cairo_int_status_t -_cairo_image_info_get_jpx_info (cairo_image_info_t *info, - const unsigned char *data, - unsigned long length) -{ - const unsigned char *p = data; - const unsigned char *end = data + length; - - /* First 12 bytes must be the JPEG 2000 signature box. */ - if (length < ARRAY_LENGTH(_jpx_signature) || - memcmp(p, _jpx_signature, ARRAY_LENGTH(_jpx_signature)) != 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p += ARRAY_LENGTH(_jpx_signature); - - /* Next box must be a File Type Box */ - if (! _jpx_match_box (p, end, JPX_FILETYPE)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p = _jpx_next_box (p); - - /* Locate the JP2 header box. */ - p = _jpx_find_box (p, end, JPX_JP2_HEADER); - if (!p) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Step into the JP2 header box. First box must be the Image - * Header */ - p = _jpx_get_box_contents (p); - if (! _jpx_match_box (p, end, JPX_IMAGE_HEADER)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Get the image info */ - p = _jpx_get_box_contents (p); - _jpx_extract_info (p, info); - - return CAIRO_STATUS_SUCCESS; -} - -/* PNG (image/png) - * - * http://www.w3.org/TR/2003/REC-PNG-20031110/ - */ - -#define PNG_IHDR 0x49484452 - -static const unsigned char _png_magic[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; - -cairo_int_status_t -_cairo_image_info_get_png_info (cairo_image_info_t *info, - const unsigned char *data, - unsigned long length) -{ - const unsigned char *p = data; - const unsigned char *end = data + length; - - if (length < 8 || memcmp (data, _png_magic, 8) != 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p += 8; - - /* The first chunk must be IDHR. IDHR has 13 bytes of data plus - * the 12 bytes of overhead for the chunk. */ - if (p + 13 + 12 > end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p += 4; - if (get_unaligned_be32 (p) != PNG_IHDR) - return CAIRO_INT_STATUS_UNSUPPORTED; - - p += 4; - info->width = get_unaligned_be32 (p); - p += 4; - info->height = get_unaligned_be32 (p); - - return CAIRO_STATUS_SUCCESS; -} - -static const unsigned char * -_jbig2_find_data_end (const unsigned char *p, - const unsigned char *end, - int type) -{ - unsigned char end_seq[2]; - int mmr; - - /* Segments of type "Immediate generic region" may have an - * unspecified data length. The JBIG2 specification specifies the - * method to find the end of the data for these segments. */ - if (type == 36 || type == 38 || type == 39) { - if (p + 18 < end) { - mmr = p[17] & 0x01; - if (mmr) { - /* MMR encoding ends with 0x00, 0x00 */ - end_seq[0] = 0x00; - end_seq[1] = 0x00; - } else { - /* Template encoding ends with 0xff, 0xac */ - end_seq[0] = 0xff; - end_seq[1] = 0xac; - } - p += 18; - while (p < end) { - if (p[0] == end_seq[0] && p[1] == end_seq[1]) { - /* Skip the 2 terminating bytes and the 4 byte row count that follows. */ - p += 6; - if (p < end) - return p; - } - p++; - } - } - } - - return NULL; -} - -static const unsigned char * -_jbig2_get_next_segment (const unsigned char *p, - const unsigned char *end, - int *type, - const unsigned char **data, - unsigned long *data_len) -{ - unsigned long seg_num; - cairo_bool_t big_page_size; - int num_segs; - int ref_seg_bytes; - int referred_size; - - if (p + 6 >= end) - return NULL; - - seg_num = get_unaligned_be32 (p); - *type = p[4] & 0x3f; - big_page_size = (p[4] & 0x40) != 0; - p += 5; - - num_segs = p[0] >> 5; - if (num_segs == 7) { - num_segs = get_unaligned_be32 (p) & 0x1fffffff; - ref_seg_bytes = 4 + ((num_segs + 1)/8); - } else { - ref_seg_bytes = 1; - } - p += ref_seg_bytes; - - if (seg_num <= 256) - referred_size = 1; - else if (seg_num <= 65536) - referred_size = 2; - else - referred_size = 4; - - p += num_segs * referred_size; - p += big_page_size ? 4 : 1; - if (p + 4 >= end) - return NULL; - - *data_len = get_unaligned_be32 (p); - p += 4; - *data = p; - - if (*data_len == 0xffffffff) { - /* if data length is -1 we have to scan through the data to find the end */ - p = _jbig2_find_data_end (*data, end, *type); - if (!p || p >= end) - return NULL; - - *data_len = p - *data; - } else { - p += *data_len; - } - - if (p < end) - return p; - else - return NULL; -} - -static void -_jbig2_extract_info (cairo_image_info_t *info, const unsigned char *p) -{ - info->width = get_unaligned_be32 (p); - info->height = get_unaligned_be32 (p + 4); - info->num_components = 1; - info->bits_per_component = 1; -} - -cairo_int_status_t -_cairo_image_info_get_jbig2_info (cairo_image_info_t *info, - const unsigned char *data, - unsigned long length) -{ - const unsigned char *p = data; - const unsigned char *end = data + length; - int seg_type; - const unsigned char *seg_data; - unsigned long seg_data_len; - - while (p && p < end) { - p = _jbig2_get_next_segment (p, end, &seg_type, &seg_data, &seg_data_len); - if (p && seg_type == 48 && seg_data_len > 8) { - /* page information segment */ - _jbig2_extract_info (info, seg_data); - return CAIRO_STATUS_SUCCESS; - } - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-source.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-source.c deleted file mode 100644 index 950053db2c1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-source.c +++ /dev/null @@ -1,1601 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * Copyright © 2009,2010,2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* The purpose of this file/surface is to simply translate a pattern - * to a pixman_image_t and thence to feed it back to the general - * compositor interface. - */ - -#include "cairoint.h" - -#include "cairo-image-surface-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-error-private.h" -#include "cairo-pattern-inline.h" -#include "cairo-paginated-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-observer-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-private.h" - -#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ - -#if CAIRO_NO_MUTEX -#define PIXMAN_HAS_ATOMIC_OPS 1 -#endif - -#if PIXMAN_HAS_ATOMIC_OPS -static pixman_image_t *__pixman_transparent_image; -static pixman_image_t *__pixman_black_image; -static pixman_image_t *__pixman_white_image; - -static pixman_image_t * -_pixman_transparent_image (void) -{ - pixman_image_t *image; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = __pixman_transparent_image; - if (unlikely (image == NULL)) { - pixman_color_t color; - - color.red = 0x00; - color.green = 0x00; - color.blue = 0x00; - color.alpha = 0x00; - - image = pixman_image_create_solid_fill (&color); - if (unlikely (image == NULL)) - return NULL; - - if (_cairo_atomic_ptr_cmpxchg (&__pixman_transparent_image, - NULL, image)) - { - pixman_image_ref (image); - } - } else { - pixman_image_ref (image); - } - - return image; -} - -static pixman_image_t * -_pixman_black_image (void) -{ - pixman_image_t *image; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = __pixman_black_image; - if (unlikely (image == NULL)) { - pixman_color_t color; - - color.red = 0x00; - color.green = 0x00; - color.blue = 0x00; - color.alpha = 0xffff; - - image = pixman_image_create_solid_fill (&color); - if (unlikely (image == NULL)) - return NULL; - - if (_cairo_atomic_ptr_cmpxchg (&__pixman_black_image, - NULL, image)) - { - pixman_image_ref (image); - } - } else { - pixman_image_ref (image); - } - - return image; -} - -static pixman_image_t * -_pixman_white_image (void) -{ - pixman_image_t *image; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - image = __pixman_white_image; - if (unlikely (image == NULL)) { - pixman_color_t color; - - color.red = 0xffff; - color.green = 0xffff; - color.blue = 0xffff; - color.alpha = 0xffff; - - image = pixman_image_create_solid_fill (&color); - if (unlikely (image == NULL)) - return NULL; - - if (_cairo_atomic_ptr_cmpxchg (&__pixman_white_image, - NULL, image)) - { - pixman_image_ref (image); - } - } else { - pixman_image_ref (image); - } - - return image; -} - -static uint32_t -hars_petruska_f54_1_random (void) -{ -#define rol(x,k) ((x << k) | (x >> (32-k))) - static uint32_t x; - return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; -#undef rol -} - -static struct { - cairo_color_t color; - pixman_image_t *image; -} cache[16]; -static int n_cached; - -#else /* !PIXMAN_HAS_ATOMIC_OPS */ -static pixman_image_t * -_pixman_transparent_image (void) -{ - TRACE ((stderr, "%s\n", __FUNCTION__)); - return _pixman_image_for_color (CAIRO_COLOR_TRANSPARENT); -} - -static pixman_image_t * -_pixman_black_image (void) -{ - TRACE ((stderr, "%s\n", __FUNCTION__)); - return _pixman_image_for_color (CAIRO_COLOR_BLACK); -} - -static pixman_image_t * -_pixman_white_image (void) -{ - TRACE ((stderr, "%s\n", __FUNCTION__)); - return _pixman_image_for_color (CAIRO_COLOR_WHITE); -} -#endif /* !PIXMAN_HAS_ATOMIC_OPS */ - - -pixman_image_t * -_pixman_image_for_color (const cairo_color_t *cairo_color) -{ - pixman_color_t color; - pixman_image_t *image; - -#if PIXMAN_HAS_ATOMIC_OPS - int i; - - if (CAIRO_COLOR_IS_CLEAR (cairo_color)) - return _pixman_transparent_image (); - - if (CAIRO_COLOR_IS_OPAQUE (cairo_color)) { - if (cairo_color->red_short <= 0x00ff && - cairo_color->green_short <= 0x00ff && - cairo_color->blue_short <= 0x00ff) - { - return _pixman_black_image (); - } - - if (cairo_color->red_short >= 0xff00 && - cairo_color->green_short >= 0xff00 && - cairo_color->blue_short >= 0xff00) - { - return _pixman_white_image (); - } - } - - CAIRO_MUTEX_LOCK (_cairo_image_solid_cache_mutex); - for (i = 0; i < n_cached; i++) { - if (_cairo_color_equal (&cache[i].color, cairo_color)) { - image = pixman_image_ref (cache[i].image); - goto UNLOCK; - } - } -#endif - - color.red = cairo_color->red_short; - color.green = cairo_color->green_short; - color.blue = cairo_color->blue_short; - color.alpha = cairo_color->alpha_short; - - image = pixman_image_create_solid_fill (&color); -#if PIXMAN_HAS_ATOMIC_OPS - if (image == NULL) - goto UNLOCK; - - if (n_cached < ARRAY_LENGTH (cache)) { - i = n_cached++; - } else { - i = hars_petruska_f54_1_random () % ARRAY_LENGTH (cache); - pixman_image_unref (cache[i].image); - } - cache[i].image = pixman_image_ref (image); - cache[i].color = *cairo_color; - -UNLOCK: - CAIRO_MUTEX_UNLOCK (_cairo_image_solid_cache_mutex); -#endif - return image; -} - - -void -_cairo_image_reset_static_data (void) -{ -#if PIXMAN_HAS_ATOMIC_OPS - while (n_cached) - pixman_image_unref (cache[--n_cached].image); - - if (__pixman_transparent_image) { - pixman_image_unref (__pixman_transparent_image); - __pixman_transparent_image = NULL; - } - - if (__pixman_black_image) { - pixman_image_unref (__pixman_black_image); - __pixman_black_image = NULL; - } - - if (__pixman_white_image) { - pixman_image_unref (__pixman_white_image); - __pixman_white_image = NULL; - } -#endif -} - -static pixman_image_t * -_pixman_image_for_gradient (const cairo_gradient_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - int *ix, int *iy) -{ - pixman_image_t *pixman_image; - pixman_gradient_stop_t pixman_stops_static[2]; - pixman_gradient_stop_t *pixman_stops = pixman_stops_static; - pixman_transform_t pixman_transform; - cairo_matrix_t matrix; - cairo_circle_double_t extremes[2]; - pixman_point_fixed_t p1, p2; - unsigned int i; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (pattern->n_stops > ARRAY_LENGTH(pixman_stops_static)) { - pixman_stops = _cairo_malloc_ab (pattern->n_stops, - sizeof(pixman_gradient_stop_t)); - if (unlikely (pixman_stops == NULL)) - return NULL; - } - - for (i = 0; i < pattern->n_stops; i++) { - pixman_stops[i].x = _cairo_fixed_16_16_from_double (pattern->stops[i].offset); - pixman_stops[i].color.red = pattern->stops[i].color.red_short; - pixman_stops[i].color.green = pattern->stops[i].color.green_short; - pixman_stops[i].color.blue = pattern->stops[i].color.blue_short; - pixman_stops[i].color.alpha = pattern->stops[i].color.alpha_short; - } - - _cairo_gradient_pattern_fit_to_range (pattern, PIXMAN_MAX_INT >> 1, &matrix, extremes); - - p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); - p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); - p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); - p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); - - if (pattern->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - pixman_image = pixman_image_create_linear_gradient (&p1, &p2, - pixman_stops, - pattern->n_stops); - } else { - pixman_fixed_t r1, r2; - - r1 = _cairo_fixed_16_16_from_double (extremes[0].radius); - r2 = _cairo_fixed_16_16_from_double (extremes[1].radius); - - pixman_image = pixman_image_create_radial_gradient (&p1, &p2, r1, r2, - pixman_stops, - pattern->n_stops); - } - - if (pixman_stops != pixman_stops_static) - free (pixman_stops); - - if (unlikely (pixman_image == NULL)) - return NULL; - - *ix = *iy = 0; - status = _cairo_matrix_to_pixman_matrix_offset (&matrix, pattern->base.filter, - extents->x + extents->width/2., - extents->y + extents->height/2., - &pixman_transform, ix, iy); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - if (unlikely (status != CAIRO_INT_STATUS_SUCCESS) || - ! pixman_image_set_transform (pixman_image, &pixman_transform)) - { - pixman_image_unref (pixman_image); - return NULL; - } - } - - { - pixman_repeat_t pixman_repeat; - - switch (pattern->base.extend) { - default: - case CAIRO_EXTEND_NONE: - pixman_repeat = PIXMAN_REPEAT_NONE; - break; - case CAIRO_EXTEND_REPEAT: - pixman_repeat = PIXMAN_REPEAT_NORMAL; - break; - case CAIRO_EXTEND_REFLECT: - pixman_repeat = PIXMAN_REPEAT_REFLECT; - break; - case CAIRO_EXTEND_PAD: - pixman_repeat = PIXMAN_REPEAT_PAD; - break; - } - - pixman_image_set_repeat (pixman_image, pixman_repeat); - } - - return pixman_image; -} - -static pixman_image_t * -_pixman_image_for_mesh (const cairo_mesh_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - int *tx, int *ty) -{ - pixman_image_t *image; - int width, height; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - *tx = -extents->x; - *ty = -extents->y; - width = extents->width; - height = extents->height; - - image = pixman_image_create_bits (PIXMAN_a8r8g8b8, width, height, NULL, 0); - if (unlikely (image == NULL)) - return NULL; - - _cairo_mesh_pattern_rasterize (pattern, - pixman_image_get_data (image), - width, height, - pixman_image_get_stride (image), - *tx, *ty); - return image; -} - -struct acquire_source_cleanup { - cairo_surface_t *surface; - cairo_image_surface_t *image; - void *image_extra; -}; - -static void -_acquire_source_cleanup (pixman_image_t *pixman_image, - void *closure) -{ - struct acquire_source_cleanup *data = closure; - - _cairo_surface_release_source_image (data->surface, - data->image, - data->image_extra); - free (data); -} - -static void -_defer_free_cleanup (pixman_image_t *pixman_image, - void *closure) -{ - cairo_surface_destroy (closure); -} - -static uint16_t -expand_channel (uint16_t v, uint32_t bits) -{ - int offset = 16 - bits; - while (offset > 0) { - v |= v >> bits; - offset -= bits; - bits += bits; - } - return v; -} - -static pixman_image_t * -_pixel_to_solid (cairo_image_surface_t *image, int x, int y) -{ - uint32_t pixel; - pixman_color_t color; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - switch (image->format) { - default: - case CAIRO_FORMAT_INVALID: - ASSERT_NOT_REACHED; - return NULL; - - case CAIRO_FORMAT_A1: - pixel = *(uint8_t *) (image->data + y * image->stride + x/8); - return pixel & (1 << (x&7)) ? _pixman_black_image () : _pixman_transparent_image (); - - case CAIRO_FORMAT_A8: - color.alpha = *(uint8_t *) (image->data + y * image->stride + x); - color.alpha |= color.alpha << 8; - if (color.alpha == 0) - return _pixman_transparent_image (); - if (color.alpha == 0xffff) - return _pixman_black_image (); - - color.red = color.green = color.blue = 0; - return pixman_image_create_solid_fill (&color); - - case CAIRO_FORMAT_RGB16_565: - pixel = *(uint16_t *) (image->data + y * image->stride + 2 * x); - if (pixel == 0) - return _pixman_black_image (); - if (pixel == 0xffff) - return _pixman_white_image (); - - color.alpha = 0xffff; - color.red = expand_channel ((pixel >> 11 & 0x1f) << 11, 5); - color.green = expand_channel ((pixel >> 5 & 0x3f) << 10, 6); - color.blue = expand_channel ((pixel & 0x1f) << 11, 5); - return pixman_image_create_solid_fill (&color); - - case CAIRO_FORMAT_RGB30: - pixel = *(uint32_t *) (image->data + y * image->stride + 4 * x); - pixel &= 0x3fffffff; /* ignore alpha bits */ - if (pixel == 0) - return _pixman_black_image (); - if (pixel == 0x3fffffff) - return _pixman_white_image (); - - /* convert 10bpc to 16bpc */ - color.alpha = 0xffff; - color.red = expand_channel((pixel >> 20) & 0x3fff, 10); - color.green = expand_channel((pixel >> 10) & 0x3fff, 10); - color.blue = expand_channel(pixel & 0x3fff, 10); - return pixman_image_create_solid_fill (&color); - - case CAIRO_FORMAT_ARGB32: - case CAIRO_FORMAT_RGB24: - pixel = *(uint32_t *) (image->data + y * image->stride + 4 * x); - color.alpha = image->format == CAIRO_FORMAT_ARGB32 ? (pixel >> 24) | (pixel >> 16 & 0xff00) : 0xffff; - if (color.alpha == 0) - return _pixman_transparent_image (); - if (pixel == 0xffffffff) - return _pixman_white_image (); - if (color.alpha == 0xffff && (pixel & 0xffffff) == 0) - return _pixman_black_image (); - - color.red = (pixel >> 16 & 0xff) | (pixel >> 8 & 0xff00); - color.green = (pixel >> 8 & 0xff) | (pixel & 0xff00); - color.blue = (pixel & 0xff) | (pixel << 8 & 0xff00); - return pixman_image_create_solid_fill (&color); - } -} - -/* ========================================================================== */ - -/* Index into filter table */ -typedef enum -{ - KERNEL_IMPULSE, - KERNEL_BOX, - KERNEL_LINEAR, - KERNEL_MITCHELL, - KERNEL_NOTCH, - KERNEL_CATMULL_ROM, - KERNEL_LANCZOS3, - KERNEL_LANCZOS3_STRETCHED, - KERNEL_TENT -} kernel_t; - -/* Produce contribution of a filter of size r for pixel centered on x. - For a typical low-pass function this evaluates the function at x/r. - If the frequency is higher than 1/2, such as when r is less than 1, - this may need to integrate several samples, see cubic for examples. -*/ -typedef double (* kernel_func_t) (double x, double r); - -/* Return maximum number of pixels that will be non-zero. Except for - impluse this is the maximum of 2 and the width of the non-zero part - of the filter rounded up to the next integer. -*/ -typedef int (* kernel_width_func_t) (double r); - -/* Table of filters */ -typedef struct -{ - kernel_t kernel; - kernel_func_t func; - kernel_width_func_t width; -} filter_info_t; - -/* PIXMAN_KERNEL_IMPULSE: Returns pixel nearest the center. This - matches PIXMAN_FILTER_NEAREST. This is useful if you wish to - combine the result of nearest in one direction with another filter - in the other. -*/ - -static double -impulse_kernel (double x, double r) -{ - return 1; -} - -static int -impulse_width (double r) -{ - return 1; -} - -/* PIXMAN_KERNEL_BOX: Intersection of a box of width r with square - pixels. This is the smallest possible filter such that the output - image contains an equal contribution from all the input - pixels. Lots of software uses this. The function is a trapazoid of - width r+1, not a box. - - When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and - PIXMAN_KERNEL_TENT all produce the same filter, allowing - them to be exchanged at this point. -*/ - -static double -box_kernel (double x, double r) -{ - return MAX (0.0, MIN (MIN (r, 1.0), - MIN ((r + 1) / 2 - x, (r + 1) / 2 + x))); -} - -static int -box_width (double r) -{ - return r < 1.0 ? 2 : ceil(r + 1); -} - -/* PIXMAN_KERNEL_LINEAR: Weighted sum of the two pixels nearest the - center, or a triangle of width 2. This matches - PIXMAN_FILTER_BILINEAR. This is useful if you wish to combine the - result of bilinear in one direction with another filter in the - other. This is not a good filter if r > 1. You may actually want - PIXMAN_FILTER_TENT. - - When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and - PIXMAN_KERNEL_TENT all produce the same filter, allowing - them to be exchanged at this point. -*/ - -static double -linear_kernel (double x, double r) -{ - return MAX (1.0 - fabs(x), 0.0); -} - -static int -linear_width (double r) -{ - return 2; -} - -/* Cubic functions described in the Mitchell-Netravali paper. - http://mentallandscape.com/Papers_siggraph88.pdf. This describes - all possible cubic functions that can be used for sampling. -*/ - -static double -general_cubic (double x, double r, double B, double C) -{ - double ax; - if (r < 1.0) - return - general_cubic(x * 2 - .5, r * 2, B, C) + - general_cubic(x * 2 + .5, r * 2, B, C); - - ax = fabs (x / r); - - if (ax < 1) - { - return (((12 - 9 * B - 6 * C) * ax + - (-18 + 12 * B + 6 * C)) * ax * ax + - (6 - 2 * B)) / 6; - } - else if (ax < 2) - { - return ((((-B - 6 * C) * ax + - (6 * B + 30 * C)) * ax + - (-12 * B - 48 * C)) * ax + - (8 * B + 24 * C)) / 6; - } - else - { - return 0.0; - } -} - -static int -cubic_width (double r) -{ - return MAX (2, ceil (r * 4)); -} - -/* PIXMAN_KERNEL_CATMULL_ROM: Catmull-Rom interpolation. Often called - "cubic interpolation", "b-spline", or just "cubic" by other - software. This filter has negative values so it can produce ringing - and output pixels outside the range of input pixels. This is very - close to lanczos2 so there is no reason to supply that as well. -*/ - -static double -cubic_kernel (double x, double r) -{ - return general_cubic (x, r, 0.0, 0.5); -} - -/* PIXMAN_KERNEL_MITCHELL: Cubic recommended by the Mitchell-Netravali - paper. This has negative values and because the values at +/-1 are - not zero it does not interpolate the pixels, meaning it will change - an image even if there is no translation. -*/ - -static double -mitchell_kernel (double x, double r) -{ - return general_cubic (x, r, 1/3.0, 1/3.0); -} - -/* PIXMAN_KERNEL_NOTCH: Cubic recommended by the Mitchell-Netravali - paper to remove postaliasing artifacts. This does not remove - aliasing already present in the source image, though it may appear - to due to it's excessive blurriness. In any case this is more - useful than gaussian for image reconstruction. -*/ - -static double -notch_kernel (double x, double r) -{ - return general_cubic (x, r, 1.5, -0.25); -} - -/* PIXMAN_KERNEL_LANCZOS3: lanczos windowed sinc function from -3 to - +3. Very popular with high-end software though I think any - advantage over cubics is hidden by quantization and programming - mistakes. You will see LANCZOS5 or even 7 sometimes. -*/ - -static double -sinc (double x) -{ - return x ? sin (M_PI * x) / (M_PI * x) : 1.0; -} - -static double -lanczos (double x, double n) -{ - return fabs (x) < n ? sinc (x) * sinc (x * (1.0 / n)) : 0.0; -} - -static double -lanczos3_kernel (double x, double r) -{ - if (r < 1.0) - return - lanczos3_kernel (x * 2 - .5, r * 2) + - lanczos3_kernel (x * 2 + .5, r * 2); - else - return lanczos (x / r, 3.0); -} - -static int -lanczos3_width (double r) -{ - return MAX (2, ceil (r * 6)); -} - -/* PIXMAN_KERNEL_LANCZOS3_STRETCHED - The LANCZOS3 kernel widened by - 4/3. Recommended by Jim Blinn - http://graphics.cs.cmu.edu/nsp/course/15-462/Fall07/462/papers/jaggy.pdf -*/ - -static double -nice_kernel (double x, double r) -{ - return lanczos3_kernel (x, r * (4.0/3)); -} - -static int -nice_width (double r) -{ - return MAX (2.0, ceil (r * 8)); -} - -/* PIXMAN_KERNEL_TENT: Triangle of width 2r. Lots of software uses - this as a "better" filter, twice the size of a box but smaller than - a cubic. - - When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and - PIXMAN_KERNEL_TENT all produce the same filter, allowing - them to be exchanged at this point. -*/ - -static double -tent_kernel (double x, double r) -{ - if (r < 1.0) - return box_kernel(x, r); - else - return MAX (1.0 - fabs(x / r), 0.0); -} - -static int -tent_width (double r) -{ - return r < 1.0 ? 2 : ceil(2 * r); -} - - -static const filter_info_t filters[] = -{ - { KERNEL_IMPULSE, impulse_kernel, impulse_width }, - { KERNEL_BOX, box_kernel, box_width }, - { KERNEL_LINEAR, linear_kernel, linear_width }, - { KERNEL_MITCHELL, mitchell_kernel, cubic_width }, - { KERNEL_NOTCH, notch_kernel, cubic_width }, - { KERNEL_CATMULL_ROM, cubic_kernel, cubic_width }, - { KERNEL_LANCZOS3, lanczos3_kernel, lanczos3_width }, - { KERNEL_LANCZOS3_STRETCHED,nice_kernel, nice_width }, - { KERNEL_TENT, tent_kernel, tent_width } -}; - -/* Fills in one dimension of the filter array */ -static void get_filter(kernel_t filter, double r, - int width, int subsample, - pixman_fixed_t* out) -{ - int i; - pixman_fixed_t *p = out; - int n_phases = 1 << subsample; - double step = 1.0 / n_phases; - kernel_func_t func = filters[filter].func; - - /* special-case the impulse filter: */ - if (width <= 1) - { - for (i = 0; i < n_phases; ++i) - *p++ = pixman_fixed_1; - return; - } - - for (i = 0; i < n_phases; ++i) - { - double frac = (i + .5) * step; - /* Center of left-most pixel: */ - double x1 = ceil (frac - width / 2.0 - 0.5) - frac + 0.5; - double total = 0; - pixman_fixed_t new_total = 0; - int j; - - for (j = 0; j < width; ++j) - { - double v = func(x1 + j, r); - total += v; - p[j] = pixman_double_to_fixed (v); - } - - /* Normalize */ - total = 1 / total; - for (j = 0; j < width; ++j) - new_total += (p[j] *= total); - - /* Put any error on center pixel */ - p[width / 2] += (pixman_fixed_1 - new_total); - - p += width; - } -} - - -/* Create the parameter list for a SEPARABLE_CONVOLUTION filter - * with the given kernels and scale parameters. - */ -static pixman_fixed_t * -create_separable_convolution (int *n_values, - kernel_t xfilter, - double sx, - kernel_t yfilter, - double sy) -{ - int xwidth, xsubsample, ywidth, ysubsample, size_x, size_y; - pixman_fixed_t *params; - - xwidth = filters[xfilter].width(sx); - xsubsample = 0; - if (xwidth > 1) - while (sx * (1 << xsubsample) <= 128.0) xsubsample++; - size_x = (1 << xsubsample) * xwidth; - - ywidth = filters[yfilter].width(sy); - ysubsample = 0; - if (ywidth > 1) - while (sy * (1 << ysubsample) <= 128.0) ysubsample++; - size_y = (1 << ysubsample) * ywidth; - - *n_values = 4 + size_x + size_y; - params = malloc (*n_values * sizeof (pixman_fixed_t)); - if (!params) return 0; - - params[0] = pixman_int_to_fixed (xwidth); - params[1] = pixman_int_to_fixed (ywidth); - params[2] = pixman_int_to_fixed (xsubsample); - params[3] = pixman_int_to_fixed (ysubsample); - - get_filter(xfilter, sx, xwidth, xsubsample, params + 4); - get_filter(yfilter, sy, ywidth, ysubsample, params + 4 + size_x); - - return params; -} - -/* ========================================================================== */ - -static cairo_bool_t -_pixman_image_set_properties (pixman_image_t *pixman_image, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - int *ix,int *iy) -{ - pixman_transform_t pixman_transform; - cairo_int_status_t status; - - status = _cairo_matrix_to_pixman_matrix_offset (&pattern->matrix, - pattern->filter, - extents->x + extents->width/2., - extents->y + extents->height/2., - &pixman_transform, ix, iy); - if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) - { - /* If the transform is an identity, we don't need to set it - * and we can use any filtering, so choose the fastest one. */ - pixman_image_set_filter (pixman_image, PIXMAN_FILTER_NEAREST, NULL, 0); - } - else if (unlikely (status != CAIRO_INT_STATUS_SUCCESS || - ! pixman_image_set_transform (pixman_image, - &pixman_transform))) - { - return FALSE; - } - else - { - pixman_filter_t pixman_filter; - kernel_t kernel; - double dx, dy; - - /* Compute scale factors from the pattern matrix. These scale - * factors are from user to pattern space, and as such they - * are greater than 1.0 for downscaling and less than 1.0 for - * upscaling. The factors are the size of an axis-aligned - * rectangle with the same area as the parallelgram a 1x1 - * square transforms to. - */ - dx = hypot (pattern->matrix.xx, pattern->matrix.xy); - dy = hypot (pattern->matrix.yx, pattern->matrix.yy); - - /* Clip at maximum pixman_fixed number. Besides making it - * passable to pixman, this avoids errors from inf and nan. - */ - if (! (dx < 0x7FFF)) dx = 0x7FFF; - if (! (dy < 0x7FFF)) dy = 0x7FFF; - - switch (pattern->filter) { - case CAIRO_FILTER_FAST: - pixman_filter = PIXMAN_FILTER_FAST; - break; - case CAIRO_FILTER_GOOD: - pixman_filter = PIXMAN_FILTER_SEPARABLE_CONVOLUTION; - kernel = KERNEL_BOX; - /* Clip the filter size to prevent extreme slowness. This - value could be raised if 2-pass filtering is done */ - if (dx > 16.0) dx = 16.0; - if (dy > 16.0) dy = 16.0; - /* Match the bilinear filter for scales > .75: */ - if (dx < 1.0/0.75) dx = 1.0; - if (dy < 1.0/0.75) dy = 1.0; - break; - case CAIRO_FILTER_BEST: - pixman_filter = PIXMAN_FILTER_SEPARABLE_CONVOLUTION; - kernel = KERNEL_CATMULL_ROM; /* LANCZOS3 is better but not much */ - /* Clip the filter size to prevent extreme slowness. This - value could be raised if 2-pass filtering is done */ - if (dx > 16.0) { dx = 16.0; kernel = KERNEL_BOX; } - /* blur up to 2x scale, then blend to square pixels for larger: */ - else if (dx < 1.0) { - if (dx < 1.0/128) dx = 1.0/127; - else if (dx < 0.5) dx = 1.0 / (1.0 / dx - 1.0); - else dx = 1.0; - } - if (dy > 16.0) { dy = 16.0; kernel = KERNEL_BOX; } - else if (dy < 1.0) { - if (dy < 1.0/128) dy = 1.0/127; - else if (dy < 0.5) dy = 1.0 / (1.0 / dy - 1.0); - else dy = 1.0; - } - break; - case CAIRO_FILTER_NEAREST: - pixman_filter = PIXMAN_FILTER_NEAREST; - break; - case CAIRO_FILTER_BILINEAR: - pixman_filter = PIXMAN_FILTER_BILINEAR; - break; - case CAIRO_FILTER_GAUSSIAN: - /* XXX: The GAUSSIAN value has no implementation in cairo - * whatsoever, so it was really a mistake to have it in the - * API. We could fix this by officially deprecating it, or - * else inventing semantics and providing an actual - * implementation for it. */ - default: - pixman_filter = PIXMAN_FILTER_BEST; - } - - if (pixman_filter == PIXMAN_FILTER_SEPARABLE_CONVOLUTION) { - int n_params; - pixman_fixed_t *params; - params = create_separable_convolution - (&n_params, kernel, dx, kernel, dy); - pixman_image_set_filter (pixman_image, pixman_filter, - params, n_params); - free (params); - } else { - pixman_image_set_filter (pixman_image, pixman_filter, NULL, 0); - } - } - - { - pixman_repeat_t pixman_repeat; - - switch (pattern->extend) { - default: - case CAIRO_EXTEND_NONE: - pixman_repeat = PIXMAN_REPEAT_NONE; - break; - case CAIRO_EXTEND_REPEAT: - pixman_repeat = PIXMAN_REPEAT_NORMAL; - break; - case CAIRO_EXTEND_REFLECT: - pixman_repeat = PIXMAN_REPEAT_REFLECT; - break; - case CAIRO_EXTEND_PAD: - pixman_repeat = PIXMAN_REPEAT_PAD; - break; - } - - pixman_image_set_repeat (pixman_image, pixman_repeat); - } - - if (pattern->has_component_alpha) - pixman_image_set_component_alpha (pixman_image, TRUE); - - return TRUE; -} - -struct proxy { - cairo_surface_t base; - cairo_surface_t *image; -}; - -static cairo_status_t -proxy_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - struct proxy *proxy = abstract_surface; - return _cairo_surface_acquire_source_image (proxy->image, image_out, image_extra); -} - -static void -proxy_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - struct proxy *proxy = abstract_surface; - _cairo_surface_release_source_image (proxy->image, image, image_extra); -} - -static cairo_status_t -proxy_finish (void *abstract_surface) -{ - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t proxy_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_NULL, - proxy_finish, - NULL, - - NULL, /* create similar */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - proxy_acquire_source_image, - proxy_release_source_image, -}; - -static cairo_surface_t * -attach_proxy (cairo_surface_t *source, - cairo_surface_t *image) -{ - struct proxy *proxy; - - proxy = malloc (sizeof (*proxy)); - if (unlikely (proxy == NULL)) - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_surface_init (&proxy->base, &proxy_backend, NULL, image->content); - - proxy->image = image; - _cairo_surface_attach_snapshot (source, &proxy->base, NULL); - - return &proxy->base; -} - -static void -detach_proxy (cairo_surface_t *source, - cairo_surface_t *proxy) -{ - cairo_surface_finish (proxy); - cairo_surface_destroy (proxy); -} - -static cairo_surface_t * -get_proxy (cairo_surface_t *proxy) -{ - return ((struct proxy *)proxy)->image; -} - -static pixman_image_t * -_pixman_image_for_recording (cairo_image_surface_t *dst, - const cairo_surface_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *ix, int *iy) -{ - cairo_surface_t *source, *clone, *proxy; - cairo_rectangle_int_t limit; - pixman_image_t *pixman_image; - cairo_status_t status; - cairo_extend_t extend; - cairo_matrix_t *m, matrix; - int tx = 0, ty = 0; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - *ix = *iy = 0; - - source = _cairo_pattern_get_source (pattern, &limit); - - extend = pattern->base.extend; - if (_cairo_rectangle_contains_rectangle (&limit, sample)) - extend = CAIRO_EXTEND_NONE; - if (extend == CAIRO_EXTEND_NONE) { - if (! _cairo_rectangle_intersect (&limit, sample)) - return _pixman_transparent_image (); - - if (! _cairo_matrix_is_identity (&pattern->base.matrix)) { - double x1, y1, x2, y2; - - matrix = pattern->base.matrix; - status = cairo_matrix_invert (&matrix); - assert (status == CAIRO_STATUS_SUCCESS); - - x1 = limit.x; - y1 = limit.y; - x2 = limit.x + limit.width; - y2 = limit.y + limit.height; - - _cairo_matrix_transform_bounding_box (&matrix, - &x1, &y1, &x2, &y2, NULL); - - limit.x = floor (x1); - limit.y = floor (y1); - limit.width = ceil (x2) - limit.x; - limit.height = ceil (y2) - limit.y; - } - } - tx = limit.x; - ty = limit.y; - - /* XXX transformations! */ - proxy = _cairo_surface_has_snapshot (source, &proxy_backend); - if (proxy != NULL) { - clone = cairo_surface_reference (get_proxy (proxy)); - goto done; - } - - if (is_mask) { - clone = cairo_image_surface_create (CAIRO_FORMAT_A8, - limit.width, limit.height); - } else { - if (dst->base.content == source->content) - clone = cairo_image_surface_create (dst->format, - limit.width, limit.height); - else - clone = _cairo_image_surface_create_with_content (source->content, - limit.width, - limit.height); - } - - m = NULL; - if (extend == CAIRO_EXTEND_NONE) { - matrix = pattern->base.matrix; - if (tx | ty) - cairo_matrix_translate (&matrix, tx, ty); - m = &matrix; - } else { - /* XXX extract scale factor for repeating patterns */ - } - - /* Handle recursion by returning future reads from the current image */ - proxy = attach_proxy (source, clone); - status = _cairo_recording_surface_replay_with_clip (source, m, clone, NULL); - detach_proxy (source, proxy); - if (unlikely (status)) { - cairo_surface_destroy (clone); - return NULL; - } - -done: - pixman_image = pixman_image_ref (((cairo_image_surface_t *)clone)->pixman_image); - cairo_surface_destroy (clone); - - *ix = -limit.x; - *iy = -limit.y; - if (extend != CAIRO_EXTEND_NONE) { - if (! _pixman_image_set_properties (pixman_image, - &pattern->base, extents, - ix, iy)) { - pixman_image_unref (pixman_image); - pixman_image= NULL; - } - } - - return pixman_image; -} - -static pixman_image_t * -_pixman_image_for_surface (cairo_image_surface_t *dst, - const cairo_surface_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *ix, int *iy) -{ - cairo_extend_t extend = pattern->base.extend; - pixman_image_t *pixman_image; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - *ix = *iy = 0; - pixman_image = NULL; - if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - return _pixman_image_for_recording(dst, pattern, - is_mask, extents, sample, - ix, iy); - - if (pattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE && - (! is_mask || ! pattern->base.has_component_alpha || - (pattern->surface->content & CAIRO_CONTENT_COLOR) == 0)) - { - cairo_surface_t *defer_free = NULL; - cairo_image_surface_t *source = (cairo_image_surface_t *) pattern->surface; - cairo_surface_type_t type; - - if (_cairo_surface_is_snapshot (&source->base)) { - defer_free = _cairo_surface_snapshot_get_target (&source->base); - source = (cairo_image_surface_t *) defer_free; - } - - type = source->base.backend->type; - if (type == CAIRO_SURFACE_TYPE_IMAGE) { - if (extend != CAIRO_EXTEND_NONE && - sample->x >= 0 && - sample->y >= 0 && - sample->x + sample->width <= source->width && - sample->y + sample->height <= source->height) - { - extend = CAIRO_EXTEND_NONE; - } - - if (sample->width == 1 && sample->height == 1) { - if (sample->x < 0 || - sample->y < 0 || - sample->x >= source->width || - sample->y >= source->height) - { - if (extend == CAIRO_EXTEND_NONE) { - cairo_surface_destroy (defer_free); - return _pixman_transparent_image (); - } - } - else - { - pixman_image = _pixel_to_solid (source, - sample->x, sample->y); - if (pixman_image) { - cairo_surface_destroy (defer_free); - return pixman_image; - } - } - } - -#if PIXMAN_HAS_ATOMIC_OPS - /* avoid allocating a 'pattern' image if we can reuse the original */ - if (extend == CAIRO_EXTEND_NONE && - _cairo_matrix_is_pixman_translation (&pattern->base.matrix, - pattern->base.filter, - ix, iy)) - { - cairo_surface_destroy (defer_free); - return pixman_image_ref (source->pixman_image); - } -#endif - - pixman_image = pixman_image_create_bits (source->pixman_format, - source->width, - source->height, - (uint32_t *) source->data, - source->stride); - if (unlikely (pixman_image == NULL)) { - cairo_surface_destroy (defer_free); - return NULL; - } - - if (defer_free) { - pixman_image_set_destroy_function (pixman_image, - _defer_free_cleanup, - defer_free); - } - } else if (type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub; - cairo_bool_t is_contained = FALSE; - - sub = (cairo_surface_subsurface_t *) source; - source = (cairo_image_surface_t *) sub->target; - - if (sample->x >= 0 && - sample->y >= 0 && - sample->x + sample->width <= sub->extents.width && - sample->y + sample->height <= sub->extents.height) - { - is_contained = TRUE; - } - - if (sample->width == 1 && sample->height == 1) { - if (is_contained) { - pixman_image = _pixel_to_solid (source, - sub->extents.x + sample->x, - sub->extents.y + sample->y); - if (pixman_image) - return pixman_image; - } else { - if (extend == CAIRO_EXTEND_NONE) - return _pixman_transparent_image (); - } - } - -#if PIXMAN_HAS_ATOMIC_OPS - *ix = sub->extents.x; - *iy = sub->extents.y; - if (is_contained && - _cairo_matrix_is_pixman_translation (&pattern->base.matrix, - pattern->base.filter, - ix, iy)) - { - return pixman_image_ref (source->pixman_image); - } -#endif - - /* Avoid sub-byte offsets, force a copy in that case. */ - if (PIXMAN_FORMAT_BPP (source->pixman_format) >= 8) { - if (is_contained) { - void *data = source->data - + sub->extents.x * PIXMAN_FORMAT_BPP(source->pixman_format)/8 - + sub->extents.y * source->stride; - pixman_image = pixman_image_create_bits (source->pixman_format, - sub->extents.width, - sub->extents.height, - data, - source->stride); - if (unlikely (pixman_image == NULL)) - return NULL; - } else { - /* XXX for a simple translation and EXTEND_NONE we can - * fix up the pattern matrix instead. - */ - } - } - } - } - - if (pixman_image == NULL) { - struct acquire_source_cleanup *cleanup; - cairo_image_surface_t *image; - void *extra; - cairo_status_t status; - - status = _cairo_surface_acquire_source_image (pattern->surface, &image, &extra); - if (unlikely (status)) - return NULL; - - pixman_image = pixman_image_create_bits (image->pixman_format, - image->width, - image->height, - (uint32_t *) image->data, - image->stride); - if (unlikely (pixman_image == NULL)) { - _cairo_surface_release_source_image (pattern->surface, image, extra); - return NULL; - } - - cleanup = malloc (sizeof (*cleanup)); - if (unlikely (cleanup == NULL)) { - _cairo_surface_release_source_image (pattern->surface, image, extra); - pixman_image_unref (pixman_image); - return NULL; - } - - cleanup->surface = pattern->surface; - cleanup->image = image; - cleanup->image_extra = extra; - pixman_image_set_destroy_function (pixman_image, - _acquire_source_cleanup, cleanup); - } - - if (! _pixman_image_set_properties (pixman_image, - &pattern->base, extents, - ix, iy)) { - pixman_image_unref (pixman_image); - pixman_image= NULL; - } - - return pixman_image; -} - -struct raster_source_cleanup { - const cairo_pattern_t *pattern; - cairo_surface_t *surface; - cairo_image_surface_t *image; - void *image_extra; -}; - -static void -_raster_source_cleanup (pixman_image_t *pixman_image, - void *closure) -{ - struct raster_source_cleanup *data = closure; - - _cairo_surface_release_source_image (data->surface, - data->image, - data->image_extra); - - _cairo_raster_source_pattern_release (data->pattern, - data->surface); - - free (data); -} - -static pixman_image_t * -_pixman_image_for_raster (cairo_image_surface_t *dst, - const cairo_raster_source_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *ix, int *iy) -{ - pixman_image_t *pixman_image; - struct raster_source_cleanup *cleanup; - cairo_image_surface_t *image; - void *extra; - cairo_status_t status; - cairo_surface_t *surface; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - *ix = *iy = 0; - - surface = _cairo_raster_source_pattern_acquire (&pattern->base, - &dst->base, NULL); - if (unlikely (surface == NULL || surface->status)) - return NULL; - - status = _cairo_surface_acquire_source_image (surface, &image, &extra); - if (unlikely (status)) { - _cairo_raster_source_pattern_release (&pattern->base, surface); - return NULL; - } - - assert (image->width == pattern->extents.width); - assert (image->height == pattern->extents.height); - - pixman_image = pixman_image_create_bits (image->pixman_format, - image->width, - image->height, - (uint32_t *) image->data, - image->stride); - if (unlikely (pixman_image == NULL)) { - _cairo_surface_release_source_image (surface, image, extra); - _cairo_raster_source_pattern_release (&pattern->base, surface); - return NULL; - } - - cleanup = malloc (sizeof (*cleanup)); - if (unlikely (cleanup == NULL)) { - pixman_image_unref (pixman_image); - _cairo_surface_release_source_image (surface, image, extra); - _cairo_raster_source_pattern_release (&pattern->base, surface); - return NULL; - } - - cleanup->pattern = &pattern->base; - cleanup->surface = surface; - cleanup->image = image; - cleanup->image_extra = extra; - pixman_image_set_destroy_function (pixman_image, - _raster_source_cleanup, cleanup); - - if (! _pixman_image_set_properties (pixman_image, - &pattern->base, extents, - ix, iy)) { - pixman_image_unref (pixman_image); - pixman_image= NULL; - } - - return pixman_image; -} - -pixman_image_t * -_pixman_image_for_pattern (cairo_image_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *tx, int *ty) -{ - *tx = *ty = 0; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (pattern == NULL) - return _pixman_white_image (); - - switch (pattern->type) { - default: - ASSERT_NOT_REACHED; - case CAIRO_PATTERN_TYPE_SOLID: - return _pixman_image_for_color (&((const cairo_solid_pattern_t *) pattern)->color); - - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_LINEAR: - return _pixman_image_for_gradient ((const cairo_gradient_pattern_t *) pattern, - extents, tx, ty); - - case CAIRO_PATTERN_TYPE_MESH: - return _pixman_image_for_mesh ((const cairo_mesh_pattern_t *) pattern, - extents, tx, ty); - - case CAIRO_PATTERN_TYPE_SURFACE: - return _pixman_image_for_surface (dst, - (const cairo_surface_pattern_t *) pattern, - is_mask, extents, sample, - tx, ty); - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _pixman_image_for_raster (dst, - (const cairo_raster_source_pattern_t *) pattern, - is_mask, extents, sample, - tx, ty); - } -} - -static cairo_status_t -_cairo_image_source_finish (void *abstract_surface) -{ - cairo_image_source_t *source = abstract_surface; - - pixman_image_unref (source->pixman_image); - return CAIRO_STATUS_SUCCESS; -} - -const cairo_surface_backend_t _cairo_image_source_backend = { - CAIRO_SURFACE_TYPE_IMAGE, - _cairo_image_source_finish, - NULL, /* read-only wrapper */ -}; - -cairo_surface_t * -_cairo_image_source_create_for_pattern (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_image_source_t *source; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - source = malloc (sizeof (cairo_image_source_t)); - if (unlikely (source == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - source->pixman_image = - _pixman_image_for_pattern ((cairo_image_surface_t *)dst, - pattern, is_mask, - extents, sample, - src_x, src_y); - if (unlikely (source->pixman_image == NULL)) { - free (source); - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_surface_init (&source->base, - &_cairo_image_source_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - source->is_opaque_solid = - pattern == NULL || _cairo_pattern_is_opaque_solid (pattern); - - return &source->base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-inline.h deleted file mode 100644 index 743d5fd3e75..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-inline.h +++ /dev/null @@ -1,96 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_IMAGE_SURFACE_INLINE_H -#define CAIRO_IMAGE_SURFACE_INLINE_H - -#include "cairo-surface-private.h" -#include "cairo-image-surface-private.h" - -CAIRO_BEGIN_DECLS - -static inline cairo_image_surface_t * -_cairo_image_surface_create_in_error (cairo_status_t status) -{ - return (cairo_image_surface_t *) _cairo_surface_create_in_error (status); -} - -static inline void -_cairo_image_surface_set_parent (cairo_image_surface_t *image, - cairo_surface_t *parent) -{ - image->parent = parent; -} - -static inline cairo_bool_t -_cairo_image_surface_is_clone (cairo_image_surface_t *image) -{ - return image->parent != NULL; -} - -/** - * _cairo_surface_is_image: - * @surface: a #cairo_surface_t - * - * Checks if a surface is an #cairo_image_surface_t - * - * Return value: %TRUE if the surface is an image surface - **/ -static inline cairo_bool_t -_cairo_surface_is_image (const cairo_surface_t *surface) -{ - /* _cairo_surface_nil sets a NULL backend so be safe */ - return surface->backend && surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE; -} - -/** - * _cairo_surface_is_image_source: - * @surface: a #cairo_surface_t - * - * Checks if a surface is an #cairo_image_source_t - * - * Return value: %TRUE if the surface is an image source - **/ -static inline cairo_bool_t -_cairo_surface_is_image_source (const cairo_surface_t *surface) -{ - return surface->backend == &_cairo_image_source_backend; -} - -CAIRO_END_DECLS - -#endif /* CAIRO_IMAGE_SURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-private.h deleted file mode 100644 index 8ca694c5e3e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface-private.h +++ /dev/null @@ -1,238 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_IMAGE_SURFACE_PRIVATE_H -#define CAIRO_IMAGE_SURFACE_PRIVATE_H - -#include "cairo-surface-private.h" - -#include - -CAIRO_BEGIN_DECLS - -/* The canonical image backend */ -struct _cairo_image_surface { - cairo_surface_t base; - - pixman_image_t *pixman_image; - const cairo_compositor_t *compositor; - - /* Parenting is tricky wrt lifetime tracking... - * - * One use for tracking the parent of an image surface is for - * create_similar_image() where we wish to create a device specific - * surface but return an image surface to the user. In such a case, - * the image may be owned by the device specific surface, its parent, - * but the user lifetime tracking is then performed on the image. So - * when the image is then finalized we call cairo_surface_destroy() - * on the parent. However, for normal usage where the lifetime tracking - * is done on the parent surface, we need to be careful to unhook - * the image->parent pointer before finalizing the image. - */ - cairo_surface_t *parent; - - pixman_format_code_t pixman_format; - cairo_format_t format; - unsigned char *data; - - int width; - int height; - int stride; - int depth; - - unsigned owns_data : 1; - unsigned transparency : 2; - unsigned color : 2; -}; -#define to_image_surface(S) ((cairo_image_surface_t *)(S)) - -/* A wrapper for holding pixman images returned by create_for_pattern */ -typedef struct _cairo_image_source { - cairo_surface_t base; - - pixman_image_t *pixman_image; - unsigned is_opaque_solid : 1; -} cairo_image_source_t; - -cairo_private extern const cairo_surface_backend_t _cairo_image_surface_backend; -cairo_private extern const cairo_surface_backend_t _cairo_image_source_backend; - -cairo_private const cairo_compositor_t * -_cairo_image_mask_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_image_traps_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_image_spans_compositor_get (void); - -#define _cairo_image_default_compositor_get _cairo_image_spans_compositor_get - -cairo_private cairo_int_status_t -_cairo_image_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_image_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_image_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_image_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_image_surface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - -cairo_private void -_cairo_image_surface_init (cairo_image_surface_t *surface, - pixman_image_t *pixman_image, - pixman_format_code_t pixman_format); - -cairo_private cairo_surface_t * -_cairo_image_surface_create_similar (void *abstract_other, - cairo_content_t content, - int width, - int height); - -cairo_private cairo_image_surface_t * -_cairo_image_surface_map_to_image (void *abstract_other, - const cairo_rectangle_int_t *extents); - -cairo_private cairo_int_status_t -_cairo_image_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image); - -cairo_private cairo_surface_t * -_cairo_image_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_image_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra); - -cairo_private void -_cairo_image_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra); - -cairo_private cairo_surface_t * -_cairo_image_surface_snapshot (void *abstract_surface); - -cairo_private_no_warn cairo_bool_t -_cairo_image_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle); - -cairo_private void -_cairo_image_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options); - -cairo_private cairo_surface_t * -_cairo_image_source_create_for_pattern (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y); - -cairo_private cairo_status_t -_cairo_image_surface_finish (void *abstract_surface); - -cairo_private pixman_image_t * -_pixman_image_for_color (const cairo_color_t *cairo_color); - -cairo_private pixman_image_t * -_pixman_image_for_pattern (cairo_image_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *tx, int *ty); - -cairo_private void -_pixman_image_add_traps (pixman_image_t *image, - int dst_x, int dst_y, - cairo_traps_t *traps); - -cairo_private void -_pixman_image_add_tristrip (pixman_image_t *image, - int dst_x, int dst_y, - cairo_tristrip_t *strip); - -cairo_private cairo_image_surface_t * -_cairo_image_surface_clone_subimage (cairo_surface_t *surface, - const cairo_rectangle_int_t *extents); - -/* Similar to clone; but allow format conversion */ -cairo_private cairo_image_surface_t * -_cairo_image_surface_create_from_image (cairo_image_surface_t *other, - pixman_format_code_t format, - int x, int y, int width, int height, - int stride); - -CAIRO_END_DECLS - -#endif /* CAIRO_IMAGE_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface.c deleted file mode 100644 index 1fd563d1c34..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-image-surface.c +++ /dev/null @@ -1,1321 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * Copyright © 2009,2010,2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-boxes-private.h" -#include "cairo-clip-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-paginated-private.h" -#include "cairo-pattern-private.h" -#include "cairo-pixman-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-region-private.h" -#include "cairo-scaled-font-private.h" -#include "cairo-surface-snapshot-private.h" -#include "cairo-surface-subsurface-private.h" - -/* Limit on the width / height of an image surface in pixels. This is - * mainly determined by coordinates of things sent to pixman at the - * moment being in 16.16 format. */ -#define MAX_IMAGE_SIZE 32767 - -/** - * SECTION:cairo-image - * @Title: Image Surfaces - * @Short_Description: Rendering to memory buffers - * @See_Also: #cairo_surface_t - * - * Image surfaces provide the ability to render to memory buffers - * either allocated by cairo or by the calling code. The supported - * image formats are those defined in #cairo_format_t. - **/ - -/** - * CAIRO_HAS_IMAGE_SURFACE: - * - * Defined if the image surface backend is available. - * The image surface backend is always built in. - * This macro was added for completeness in cairo 1.8. - * - * Since: 1.8 - **/ - -static cairo_bool_t -_cairo_image_surface_is_size_valid (int width, int height) -{ - return 0 <= width && width <= MAX_IMAGE_SIZE && - 0 <= height && height <= MAX_IMAGE_SIZE; -} - -cairo_format_t -_cairo_format_from_pixman_format (pixman_format_code_t pixman_format) -{ - switch (pixman_format) { - case PIXMAN_a8r8g8b8: - return CAIRO_FORMAT_ARGB32; - case PIXMAN_x2r10g10b10: - return CAIRO_FORMAT_RGB30; - case PIXMAN_x8r8g8b8: - return CAIRO_FORMAT_RGB24; - case PIXMAN_a8: - return CAIRO_FORMAT_A8; - case PIXMAN_a1: - return CAIRO_FORMAT_A1; - case PIXMAN_r5g6b5: - return CAIRO_FORMAT_RGB16_565; -#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) - case PIXMAN_r8g8b8a8: case PIXMAN_r8g8b8x8: -#endif -#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,27,2) - case PIXMAN_a8r8g8b8_sRGB: -#endif - case PIXMAN_a8b8g8r8: case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8: - case PIXMAN_b8g8r8: case PIXMAN_b5g6r5: - case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5: - case PIXMAN_x1b5g5r5: case PIXMAN_a4r4g4b4: case PIXMAN_x4r4g4b4: - case PIXMAN_a4b4g4r4: case PIXMAN_x4b4g4r4: case PIXMAN_r3g3b2: - case PIXMAN_b2g3r3: case PIXMAN_a2r2g2b2: case PIXMAN_a2b2g2r2: - case PIXMAN_c8: case PIXMAN_g8: case PIXMAN_x4a4: - case PIXMAN_a4: case PIXMAN_r1g2b1: case PIXMAN_b1g2r1: - case PIXMAN_a1r1g1b1: case PIXMAN_a1b1g1r1: case PIXMAN_c4: - case PIXMAN_g4: case PIXMAN_g1: - case PIXMAN_yuy2: case PIXMAN_yv12: - case PIXMAN_b8g8r8x8: - case PIXMAN_b8g8r8a8: - case PIXMAN_a2b10g10r10: - case PIXMAN_x2b10g10r10: - case PIXMAN_a2r10g10b10: -#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) - case PIXMAN_x14r6g6b6: -#endif - default: - return CAIRO_FORMAT_INVALID; - } - - return CAIRO_FORMAT_INVALID; -} - -cairo_content_t -_cairo_content_from_pixman_format (pixman_format_code_t pixman_format) -{ - cairo_content_t content; - - content = 0; - if (PIXMAN_FORMAT_RGB (pixman_format)) - content |= CAIRO_CONTENT_COLOR; - if (PIXMAN_FORMAT_A (pixman_format)) - content |= CAIRO_CONTENT_ALPHA; - - return content; -} - -void -_cairo_image_surface_init (cairo_image_surface_t *surface, - pixman_image_t *pixman_image, - pixman_format_code_t pixman_format) -{ - surface->parent = NULL; - surface->pixman_image = pixman_image; - - surface->pixman_format = pixman_format; - surface->format = _cairo_format_from_pixman_format (pixman_format); - surface->data = (uint8_t *) pixman_image_get_data (pixman_image); - surface->owns_data = FALSE; - surface->transparency = CAIRO_IMAGE_UNKNOWN; - surface->color = CAIRO_IMAGE_UNKNOWN_COLOR; - - surface->width = pixman_image_get_width (pixman_image); - surface->height = pixman_image_get_height (pixman_image); - surface->stride = pixman_image_get_stride (pixman_image); - surface->depth = pixman_image_get_depth (pixman_image); - - surface->base.is_clear = surface->width == 0 || surface->height == 0; - - surface->compositor = _cairo_image_spans_compositor_get (); -} - -cairo_surface_t * -_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image, - pixman_format_code_t pixman_format) -{ - cairo_image_surface_t *surface; - - surface = malloc (sizeof (cairo_image_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_image_surface_backend, - NULL, /* device */ - _cairo_content_from_pixman_format (pixman_format)); - - _cairo_image_surface_init (surface, pixman_image, pixman_format); - - return &surface->base; -} - -cairo_bool_t -_pixman_format_from_masks (cairo_format_masks_t *masks, - pixman_format_code_t *format_ret) -{ - pixman_format_code_t format; - int format_type; - int a, r, g, b; - cairo_format_masks_t format_masks; - - a = _cairo_popcount (masks->alpha_mask); - r = _cairo_popcount (masks->red_mask); - g = _cairo_popcount (masks->green_mask); - b = _cairo_popcount (masks->blue_mask); - - if (masks->red_mask) { - if (masks->red_mask > masks->blue_mask) - format_type = PIXMAN_TYPE_ARGB; - else - format_type = PIXMAN_TYPE_ABGR; - } else if (masks->alpha_mask) { - format_type = PIXMAN_TYPE_A; - } else { - return FALSE; - } - - format = PIXMAN_FORMAT (masks->bpp, format_type, a, r, g, b); - - if (! pixman_format_supported_destination (format)) - return FALSE; - - /* Sanity check that we got out of PIXMAN_FORMAT exactly what we - * expected. This avoid any problems from something bizarre like - * alpha in the least-significant bits, or insane channel order, - * or whatever. */ - if (!_pixman_format_to_masks (format, &format_masks) || - masks->bpp != format_masks.bpp || - masks->red_mask != format_masks.red_mask || - masks->green_mask != format_masks.green_mask || - masks->blue_mask != format_masks.blue_mask) - { - return FALSE; - } - - *format_ret = format; - return TRUE; -} - -/* A mask consisting of N bits set to 1. */ -#define MASK(N) ((1UL << (N))-1) - -cairo_bool_t -_pixman_format_to_masks (pixman_format_code_t format, - cairo_format_masks_t *masks) -{ - int a, r, g, b; - - masks->bpp = PIXMAN_FORMAT_BPP (format); - - /* Number of bits in each channel */ - a = PIXMAN_FORMAT_A (format); - r = PIXMAN_FORMAT_R (format); - g = PIXMAN_FORMAT_G (format); - b = PIXMAN_FORMAT_B (format); - - switch (PIXMAN_FORMAT_TYPE (format)) { - case PIXMAN_TYPE_ARGB: - masks->alpha_mask = MASK (a) << (r + g + b); - masks->red_mask = MASK (r) << (g + b); - masks->green_mask = MASK (g) << (b); - masks->blue_mask = MASK (b); - return TRUE; - case PIXMAN_TYPE_ABGR: - masks->alpha_mask = MASK (a) << (b + g + r); - masks->blue_mask = MASK (b) << (g + r); - masks->green_mask = MASK (g) << (r); - masks->red_mask = MASK (r); - return TRUE; -#ifdef PIXMAN_TYPE_BGRA - case PIXMAN_TYPE_BGRA: - masks->blue_mask = MASK (b) << (masks->bpp - b); - masks->green_mask = MASK (g) << (masks->bpp - b - g); - masks->red_mask = MASK (r) << (masks->bpp - b - g - r); - masks->alpha_mask = MASK (a); - return TRUE; -#endif - case PIXMAN_TYPE_A: - masks->alpha_mask = MASK (a); - masks->red_mask = 0; - masks->green_mask = 0; - masks->blue_mask = 0; - return TRUE; - case PIXMAN_TYPE_OTHER: - case PIXMAN_TYPE_COLOR: - case PIXMAN_TYPE_GRAY: - case PIXMAN_TYPE_YUY2: - case PIXMAN_TYPE_YV12: - default: - masks->alpha_mask = 0; - masks->red_mask = 0; - masks->green_mask = 0; - masks->blue_mask = 0; - return FALSE; - } -} - -pixman_format_code_t -_cairo_format_to_pixman_format_code (cairo_format_t format) -{ - pixman_format_code_t ret; - switch (format) { - case CAIRO_FORMAT_A1: - ret = PIXMAN_a1; - break; - case CAIRO_FORMAT_A8: - ret = PIXMAN_a8; - break; - case CAIRO_FORMAT_RGB24: - ret = PIXMAN_x8r8g8b8; - break; - case CAIRO_FORMAT_RGB30: - ret = PIXMAN_x2r10g10b10; - break; - case CAIRO_FORMAT_RGB16_565: - ret = PIXMAN_r5g6b5; - break; - case CAIRO_FORMAT_ARGB32: - case CAIRO_FORMAT_INVALID: - default: - ret = PIXMAN_a8r8g8b8; - break; - } - return ret; -} - -cairo_surface_t * -_cairo_image_surface_create_with_pixman_format (unsigned char *data, - pixman_format_code_t pixman_format, - int width, - int height, - int stride) -{ - cairo_surface_t *surface; - pixman_image_t *pixman_image; - - if (! _cairo_image_surface_is_size_valid (width, height)) - { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - } - - pixman_image = pixman_image_create_bits (pixman_format, width, height, - (uint32_t *) data, stride); - - if (unlikely (pixman_image == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface = _cairo_image_surface_create_for_pixman_image (pixman_image, - pixman_format); - if (unlikely (surface->status)) { - pixman_image_unref (pixman_image); - return surface; - } - - /* we can not make any assumptions about the initial state of user data */ - surface->is_clear = data == NULL; - return surface; -} - -/** - * cairo_image_surface_create: - * @format: format of pixels in the surface to create - * @width: width of the surface, in pixels - * @height: height of the surface, in pixels - * - * Creates an image surface of the specified format and - * dimensions. Initially the surface contents are all - * 0. (Specifically, within each pixel, each color or alpha channel - * belonging to format will be 0. The contents of bits within a pixel, - * but not belonging to the given format are undefined). - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_image_surface_create (cairo_format_t format, - int width, - int height) -{ - pixman_format_code_t pixman_format; - - if (! CAIRO_FORMAT_VALID (format)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - - pixman_format = _cairo_format_to_pixman_format_code (format); - - return _cairo_image_surface_create_with_pixman_format (NULL, pixman_format, - width, height, -1); -} -slim_hidden_def (cairo_image_surface_create); - - cairo_surface_t * -_cairo_image_surface_create_with_content (cairo_content_t content, - int width, - int height) -{ - return cairo_image_surface_create (_cairo_format_from_content (content), - width, height); -} - -/** - * cairo_format_stride_for_width: - * @format: A #cairo_format_t value - * @width: The desired width of an image surface to be created. - * - * This function provides a stride value that will respect all - * alignment requirements of the accelerated image-rendering code - * within cairo. Typical usage will be of the form: - * - * - * int stride; - * unsigned char *data; - * cairo_surface_t *surface; - * - * stride = cairo_format_stride_for_width (format, width); - * data = malloc (stride * height); - * surface = cairo_image_surface_create_for_data (data, format, - * width, height, - * stride); - * - * - * Return value: the appropriate stride to use given the desired - * format and width, or -1 if either the format is invalid or the width - * too large. - * - * Since: 1.6 - **/ - int -cairo_format_stride_for_width (cairo_format_t format, - int width) -{ - int bpp; - - if (! CAIRO_FORMAT_VALID (format)) { - _cairo_error_throw (CAIRO_STATUS_INVALID_FORMAT); - return -1; - } - - bpp = _cairo_format_bits_per_pixel (format); - if ((unsigned) (width) >= (INT32_MAX - 7) / (unsigned) (bpp)) - return -1; - - return CAIRO_STRIDE_FOR_WIDTH_BPP (width, bpp); -} -slim_hidden_def (cairo_format_stride_for_width); - -/** - * cairo_image_surface_create_for_data: - * @data: a pointer to a buffer supplied by the application in which - * to write contents. This pointer must be suitably aligned for any - * kind of variable, (for example, a pointer returned by malloc). - * @format: the format of pixels in the buffer - * @width: the width of the image to be stored in the buffer - * @height: the height of the image to be stored in the buffer - * @stride: the number of bytes between the start of rows in the - * buffer as allocated. This value should always be computed by - * cairo_format_stride_for_width() before allocating the data - * buffer. - * - * Creates an image surface for the provided pixel data. The output - * buffer must be kept around until the #cairo_surface_t is destroyed - * or cairo_surface_finish() is called on the surface. The initial - * contents of @data will be used as the initial image contents; you - * must explicitly clear the buffer, using, for example, - * cairo_rectangle() and cairo_fill() if you want it cleared. - * - * Note that the stride may be larger than - * width*bytes_per_pixel to provide proper alignment for each pixel - * and row. This alignment is required to allow high-performance rendering - * within cairo. The correct way to obtain a legal stride value is to - * call cairo_format_stride_for_width() with the desired format and - * maximum image width value, and then use the resulting stride value - * to allocate the data and to create the image surface. See - * cairo_format_stride_for_width() for example code. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface in the case of an error such as out of - * memory or an invalid stride value. In case of invalid stride value - * the error status of the returned surface will be - * %CAIRO_STATUS_INVALID_STRIDE. You can use - * cairo_surface_status() to check for this. - * - * See cairo_surface_set_user_data() for a means of attaching a - * destroy-notification fallback to the surface if necessary. - * - * Since: 1.0 - **/ - cairo_surface_t * -cairo_image_surface_create_for_data (unsigned char *data, - cairo_format_t format, - int width, - int height, - int stride) -{ - pixman_format_code_t pixman_format; - int minstride; - - if (! CAIRO_FORMAT_VALID (format)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - - if ((stride & (CAIRO_STRIDE_ALIGNMENT-1)) != 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); - - if (! _cairo_image_surface_is_size_valid (width, height)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - minstride = cairo_format_stride_for_width (format, width); - if (stride < 0) { - if (stride > -minstride) { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); - } - } else { - if (stride < minstride) { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); - } - } - - pixman_format = _cairo_format_to_pixman_format_code (format); - return _cairo_image_surface_create_with_pixman_format (data, - pixman_format, - width, height, - stride); -} -slim_hidden_def (cairo_image_surface_create_for_data); - -/** - * cairo_image_surface_get_data: - * @surface: a #cairo_image_surface_t - * - * Get a pointer to the data of the image surface, for direct - * inspection or modification. - * - * A call to cairo_surface_flush() is required before accessing the - * pixel data to ensure that all pending drawing operations are - * finished. A call to cairo_surface_mark_dirty() is required after - * the data is modified. - * - * Return value: a pointer to the image data of this surface or %NULL - * if @surface is not an image surface, or if cairo_surface_finish() - * has been called. - * - * Since: 1.2 - **/ -unsigned char * -cairo_image_surface_get_data (cairo_surface_t *surface) -{ - cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; - - if (! _cairo_surface_is_image (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return image_surface->data; -} -slim_hidden_def (cairo_image_surface_get_data); - -/** - * cairo_image_surface_get_format: - * @surface: a #cairo_image_surface_t - * - * Get the format of the surface. - * - * Return value: the format of the surface - * - * Since: 1.2 - **/ -cairo_format_t -cairo_image_surface_get_format (cairo_surface_t *surface) -{ - cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; - - if (! _cairo_surface_is_image (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return CAIRO_FORMAT_INVALID; - } - - return image_surface->format; -} -slim_hidden_def (cairo_image_surface_get_format); - -/** - * cairo_image_surface_get_width: - * @surface: a #cairo_image_surface_t - * - * Get the width of the image surface in pixels. - * - * Return value: the width of the surface in pixels. - * - * Since: 1.0 - **/ -int -cairo_image_surface_get_width (cairo_surface_t *surface) -{ - cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; - - if (! _cairo_surface_is_image (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return image_surface->width; -} -slim_hidden_def (cairo_image_surface_get_width); - -/** - * cairo_image_surface_get_height: - * @surface: a #cairo_image_surface_t - * - * Get the height of the image surface in pixels. - * - * Return value: the height of the surface in pixels. - * - * Since: 1.0 - **/ -int -cairo_image_surface_get_height (cairo_surface_t *surface) -{ - cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; - - if (! _cairo_surface_is_image (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return image_surface->height; -} -slim_hidden_def (cairo_image_surface_get_height); - -/** - * cairo_image_surface_get_stride: - * @surface: a #cairo_image_surface_t - * - * Get the stride of the image surface in bytes - * - * Return value: the stride of the image surface in bytes (or 0 if - * @surface is not an image surface). The stride is the distance in - * bytes from the beginning of one row of the image data to the - * beginning of the next row. - * - * Since: 1.2 - **/ -int -cairo_image_surface_get_stride (cairo_surface_t *surface) -{ - - cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; - - if (! _cairo_surface_is_image (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return image_surface->stride; -} -slim_hidden_def (cairo_image_surface_get_stride); - - cairo_format_t -_cairo_format_from_content (cairo_content_t content) -{ - switch (content) { - case CAIRO_CONTENT_COLOR: - return CAIRO_FORMAT_RGB24; - case CAIRO_CONTENT_ALPHA: - return CAIRO_FORMAT_A8; - case CAIRO_CONTENT_COLOR_ALPHA: - return CAIRO_FORMAT_ARGB32; - } - - ASSERT_NOT_REACHED; - return CAIRO_FORMAT_INVALID; -} - - cairo_content_t -_cairo_content_from_format (cairo_format_t format) -{ - switch (format) { - case CAIRO_FORMAT_ARGB32: - return CAIRO_CONTENT_COLOR_ALPHA; - case CAIRO_FORMAT_RGB30: - return CAIRO_CONTENT_COLOR; - case CAIRO_FORMAT_RGB24: - return CAIRO_CONTENT_COLOR; - case CAIRO_FORMAT_RGB16_565: - return CAIRO_CONTENT_COLOR; - case CAIRO_FORMAT_A8: - case CAIRO_FORMAT_A1: - return CAIRO_CONTENT_ALPHA; - case CAIRO_FORMAT_INVALID: - break; - } - - ASSERT_NOT_REACHED; - return CAIRO_CONTENT_COLOR_ALPHA; -} - - int -_cairo_format_bits_per_pixel (cairo_format_t format) -{ - switch (format) { - case CAIRO_FORMAT_ARGB32: - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_RGB24: - return 32; - case CAIRO_FORMAT_RGB16_565: - return 16; - case CAIRO_FORMAT_A8: - return 8; - case CAIRO_FORMAT_A1: - return 1; - case CAIRO_FORMAT_INVALID: - default: - ASSERT_NOT_REACHED; - return 0; - } -} - -cairo_surface_t * -_cairo_image_surface_create_similar (void *abstract_other, - cairo_content_t content, - int width, - int height) -{ - cairo_image_surface_t *other = abstract_other; - - TRACE ((stderr, "%s (other=%u)\n", __FUNCTION__, other->base.unique_id)); - - if (! _cairo_image_surface_is_size_valid (width, height)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - if (content == other->base.content) { - return _cairo_image_surface_create_with_pixman_format (NULL, - other->pixman_format, - width, height, - 0); - } - - return _cairo_image_surface_create_with_content (content, - width, height); -} - -cairo_surface_t * -_cairo_image_surface_snapshot (void *abstract_surface) -{ - cairo_image_surface_t *image = abstract_surface; - cairo_image_surface_t *clone; - - /* If we own the image, we can simply steal the memory for the snapshot */ - if (image->owns_data && image->base._finishing) { - clone = (cairo_image_surface_t *) - _cairo_image_surface_create_for_pixman_image (image->pixman_image, - image->pixman_format); - if (unlikely (clone->base.status)) - return &clone->base; - - image->pixman_image = NULL; - image->owns_data = FALSE; - - clone->transparency = image->transparency; - clone->color = image->color; - - clone->owns_data = TRUE; - return &clone->base; - } - - clone = (cairo_image_surface_t *) - _cairo_image_surface_create_with_pixman_format (NULL, - image->pixman_format, - image->width, - image->height, - 0); - if (unlikely (clone->base.status)) - return &clone->base; - - if (clone->stride == image->stride) { - memcpy (clone->data, image->data, clone->stride * clone->height); - } else { - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, NULL, clone->pixman_image, - 0, 0, - 0, 0, - 0, 0, - image->width, image->height); - } - clone->base.is_clear = FALSE; - return &clone->base; -} - -cairo_image_surface_t * -_cairo_image_surface_map_to_image (void *abstract_other, - const cairo_rectangle_int_t *extents) -{ - cairo_image_surface_t *other = abstract_other; - cairo_surface_t *surface; - uint8_t *data; - - data = other->data; - data += extents->y * other->stride; - data += extents->x * PIXMAN_FORMAT_BPP (other->pixman_format)/ 8; - - surface = - _cairo_image_surface_create_with_pixman_format (data, - other->pixman_format, - extents->width, - extents->height, - other->stride); - - cairo_surface_set_device_offset (surface, -extents->x, -extents->y); - return (cairo_image_surface_t *) surface; -} - -cairo_int_status_t -_cairo_image_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return CAIRO_INT_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_image_surface_finish (void *abstract_surface) -{ - cairo_image_surface_t *surface = abstract_surface; - - if (surface->pixman_image) { - pixman_image_unref (surface->pixman_image); - surface->pixman_image = NULL; - } - - if (surface->owns_data) { - free (surface->data); - surface->data = NULL; - } - - if (surface->parent) { - cairo_surface_t *parent = surface->parent; - surface->parent = NULL; - cairo_surface_destroy (parent); - } - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface) -{ - surface->owns_data = TRUE; -} - -cairo_surface_t * -_cairo_image_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_image_surface_t *surface = abstract_surface; - - if (extents) { - extents->x = extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - } - - return &surface->base; -} - -cairo_status_t -_cairo_image_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - *image_out = abstract_surface; - *image_extra = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_image_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ -} - -/* high level image interface */ -cairo_bool_t -_cairo_image_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_image_surface_t *surface = abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - rectangle->width = surface->width; - rectangle->height = surface->height; - - return TRUE; -} - -cairo_int_status_t -_cairo_image_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_image_surface_t *surface = abstract_surface; - - TRACE ((stderr, "%s (surface=%d)\n", - __FUNCTION__, surface->base.unique_id)); - - return _cairo_compositor_paint (surface->compositor, - &surface->base, op, source, clip); -} - -cairo_int_status_t -_cairo_image_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_image_surface_t *surface = abstract_surface; - - TRACE ((stderr, "%s (surface=%d)\n", - __FUNCTION__, surface->base.unique_id)); - - return _cairo_compositor_mask (surface->compositor, - &surface->base, op, source, mask, clip); -} - -cairo_int_status_t -_cairo_image_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_image_surface_t *surface = abstract_surface; - - TRACE ((stderr, "%s (surface=%d)\n", - __FUNCTION__, surface->base.unique_id)); - - return _cairo_compositor_stroke (surface->compositor, &surface->base, - op, source, path, - style, ctm, ctm_inverse, - tolerance, antialias, clip); -} - -cairo_int_status_t -_cairo_image_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_image_surface_t *surface = abstract_surface; - - TRACE ((stderr, "%s (surface=%d)\n", - __FUNCTION__, surface->base.unique_id)); - - return _cairo_compositor_fill (surface->compositor, &surface->base, - op, source, path, - fill_rule, tolerance, antialias, - clip); -} - -cairo_int_status_t -_cairo_image_surface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_image_surface_t *surface = abstract_surface; - - TRACE ((stderr, "%s (surface=%d)\n", - __FUNCTION__, surface->base.unique_id)); - - return _cairo_compositor_glyphs (surface->compositor, &surface->base, - op, source, - glyphs, num_glyphs, scaled_font, - clip); -} - -void -_cairo_image_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - _cairo_font_options_init_default (options); - - cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON); - _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_ON); -} - -const cairo_surface_backend_t _cairo_image_surface_backend = { - CAIRO_SURFACE_TYPE_IMAGE, - _cairo_image_surface_finish, - - _cairo_default_context_create, - - _cairo_image_surface_create_similar, - NULL, /* create similar image */ - _cairo_image_surface_map_to_image, - _cairo_image_surface_unmap_image, - - _cairo_image_surface_source, - _cairo_image_surface_acquire_source_image, - _cairo_image_surface_release_source_image, - _cairo_image_surface_snapshot, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_image_surface_get_extents, - _cairo_image_surface_get_font_options, - - NULL, /* flush */ - NULL, - - _cairo_image_surface_paint, - _cairo_image_surface_mask, - _cairo_image_surface_stroke, - _cairo_image_surface_fill, - NULL, /* fill-stroke */ - _cairo_image_surface_glyphs, -}; - -/* A convenience function for when one needs to coerce an image - * surface to an alternate format. */ -cairo_image_surface_t * -_cairo_image_surface_coerce (cairo_image_surface_t *surface) -{ - return _cairo_image_surface_coerce_to_format (surface, - _cairo_format_from_content (surface->base.content)); -} - -/* A convenience function for when one needs to coerce an image - * surface to an alternate format. */ -cairo_image_surface_t * -_cairo_image_surface_coerce_to_format (cairo_image_surface_t *surface, - cairo_format_t format) -{ - cairo_image_surface_t *clone; - cairo_status_t status; - - status = surface->base.status; - if (unlikely (status)) - return (cairo_image_surface_t *)_cairo_surface_create_in_error (status); - - if (surface->format == format) - return (cairo_image_surface_t *)cairo_surface_reference(&surface->base); - - clone = (cairo_image_surface_t *) - cairo_image_surface_create (format, surface->width, surface->height); - if (unlikely (clone->base.status)) - return clone; - - pixman_image_composite32 (PIXMAN_OP_SRC, - surface->pixman_image, NULL, clone->pixman_image, - 0, 0, - 0, 0, - 0, 0, - surface->width, surface->height); - clone->base.is_clear = FALSE; - - clone->base.device_transform = - surface->base.device_transform; - clone->base.device_transform_inverse = - surface->base.device_transform_inverse; - - return clone; -} - -cairo_image_surface_t * -_cairo_image_surface_create_from_image (cairo_image_surface_t *other, - pixman_format_code_t format, - int x, int y, - int width, int height, int stride) -{ - cairo_image_surface_t *surface; - cairo_status_t status; - pixman_image_t *image; - void *mem = NULL; - - status = other->base.status; - if (unlikely (status)) - goto cleanup; - - if (stride) { - mem = _cairo_malloc_ab (height, stride); - if (unlikely (mem == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - } - - image = pixman_image_create_bits (format, width, height, mem, stride); - if (unlikely (image == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup_mem; - } - - surface = (cairo_image_surface_t *) - _cairo_image_surface_create_for_pixman_image (image, format); - if (unlikely (surface->base.status)) { - status = surface->base.status; - goto cleanup_image; - } - - pixman_image_composite32 (PIXMAN_OP_SRC, - other->pixman_image, NULL, image, - x, y, - 0, 0, - 0, 0, - width, height); - surface->base.is_clear = FALSE; - surface->owns_data = mem != NULL; - - return surface; - -cleanup_image: - pixman_image_unref (image); -cleanup_mem: - free (mem); -cleanup: - return (cairo_image_surface_t *) _cairo_surface_create_in_error (status); -} - -cairo_image_transparency_t -_cairo_image_analyze_transparency (cairo_image_surface_t *image) -{ - int x, y; - - if (image->transparency != CAIRO_IMAGE_UNKNOWN) - return image->transparency; - - if ((image->base.content & CAIRO_CONTENT_ALPHA) == 0) - return image->transparency = CAIRO_IMAGE_IS_OPAQUE; - - if (image->base.is_clear) - return image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; - - if ((image->base.content & CAIRO_CONTENT_COLOR) == 0) { - if (image->format == CAIRO_FORMAT_A1) { - return image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; - } else if (image->format == CAIRO_FORMAT_A8) { - for (y = 0; y < image->height; y++) { - uint8_t *alpha = (uint8_t *) (image->data + y * image->stride); - - for (x = 0; x < image->width; x++, alpha++) { - if (*alpha > 0 && *alpha < 255) - return image->transparency = CAIRO_IMAGE_HAS_ALPHA; - } - } - return image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; - } else { - return image->transparency = CAIRO_IMAGE_HAS_ALPHA; - } - } - - if (image->format == CAIRO_FORMAT_RGB16_565) { - image->transparency = CAIRO_IMAGE_IS_OPAQUE; - return CAIRO_IMAGE_IS_OPAQUE; - } - - if (image->format != CAIRO_FORMAT_ARGB32) - return image->transparency = CAIRO_IMAGE_HAS_ALPHA; - - image->transparency = CAIRO_IMAGE_IS_OPAQUE; - for (y = 0; y < image->height; y++) { - uint32_t *pixel = (uint32_t *) (image->data + y * image->stride); - - for (x = 0; x < image->width; x++, pixel++) { - int a = (*pixel & 0xff000000) >> 24; - if (a > 0 && a < 255) { - return image->transparency = CAIRO_IMAGE_HAS_ALPHA; - } else if (a == 0) { - image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; - } - } - } - - return image->transparency; -} - -cairo_image_color_t -_cairo_image_analyze_color (cairo_image_surface_t *image) -{ - int x, y; - - if (image->color != CAIRO_IMAGE_UNKNOWN_COLOR) - return image->color; - - if (image->format == CAIRO_FORMAT_A1) - return image->color = CAIRO_IMAGE_IS_MONOCHROME; - - if (image->format == CAIRO_FORMAT_A8) - return image->color = CAIRO_IMAGE_IS_GRAYSCALE; - - if (image->format == CAIRO_FORMAT_ARGB32) { - image->color = CAIRO_IMAGE_IS_MONOCHROME; - for (y = 0; y < image->height; y++) { - uint32_t *pixel = (uint32_t *) (image->data + y * image->stride); - - for (x = 0; x < image->width; x++, pixel++) { - int a = (*pixel & 0xff000000) >> 24; - int r = (*pixel & 0x00ff0000) >> 16; - int g = (*pixel & 0x0000ff00) >> 8; - int b = (*pixel & 0x000000ff); - if (a == 0) { - r = g = b = 0; - } else { - r = (r * 255 + a / 2) / a; - g = (g * 255 + a / 2) / a; - b = (b * 255 + a / 2) / a; - } - if (!(r == g && g == b)) - return image->color = CAIRO_IMAGE_IS_COLOR; - else if (r > 0 && r < 255) - image->color = CAIRO_IMAGE_IS_GRAYSCALE; - } - } - return image->color; - } - - if (image->format == CAIRO_FORMAT_RGB24) { - image->color = CAIRO_IMAGE_IS_MONOCHROME; - for (y = 0; y < image->height; y++) { - uint32_t *pixel = (uint32_t *) (image->data + y * image->stride); - - for (x = 0; x < image->width; x++, pixel++) { - int r = (*pixel & 0x00ff0000) >> 16; - int g = (*pixel & 0x0000ff00) >> 8; - int b = (*pixel & 0x000000ff); - if (!(r == g && g == b)) - return image->color = CAIRO_IMAGE_IS_COLOR; - else if (r > 0 && r < 255) - image->color = CAIRO_IMAGE_IS_GRAYSCALE; - } - } - return image->color; - } - - return image->color = CAIRO_IMAGE_IS_COLOR; -} - -cairo_image_surface_t * -_cairo_image_surface_clone_subimage (cairo_surface_t *surface, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_t *image; - cairo_surface_pattern_t pattern; - cairo_status_t status; - - image = cairo_surface_create_similar_image (surface, - _cairo_format_from_content (surface->content), - extents->width, - extents->height); - if (image->status) - return to_image_surface (image); - - /* TODO: check me with non-identity device_transform. Should we - * clone the scaling, too? */ - cairo_surface_set_device_offset (image, - -extents->x, - -extents->y); - - _cairo_pattern_init_for_surface (&pattern, surface); - pattern.base.filter = CAIRO_FILTER_NEAREST; - - status = _cairo_surface_paint (image, - CAIRO_OPERATOR_SOURCE, - &pattern.base, - NULL); - - _cairo_pattern_fini (&pattern.base); - - if (unlikely (status)) - goto error; - - /* We use the parent as a flag during map-to-image/umap-image that the - * resultant image came from a fallback rather than as direct call - * to the backend's map_to_image(). Whilst we use it as a simple flag, - * we need to make sure the parent surface obeys the reference counting - * semantics and is consistent for all callers. - */ - _cairo_image_surface_set_parent (to_image_surface (image), - cairo_surface_reference (surface)); - - return to_image_surface (image); - -error: - cairo_surface_destroy (image); - return to_image_surface (_cairo_surface_create_in_error (status)); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-inline.h deleted file mode 100644 index 71cc5e7ebf4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-inline.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2014 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - */ - -#ifndef CAIRO_LINE_INLINE_H -#define CAIRO_LINE_INLINE_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" -#include "cairo-fixed-private.h" -#include "cairo-line-private.h" - -static inline int -cairo_lines_equal (const cairo_line_t *a, const cairo_line_t *b) -{ - return (a->p1.x == b->p1.x && a->p1.y == b->p1.y && - a->p2.x == b->p2.x && a->p2.y == b->p2.y); -} - -#endif /* CAIRO_LINE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-private.h deleted file mode 100644 index 08bf4b3587c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line-private.h +++ /dev/null @@ -1,51 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2014 Intel Corporation, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - */ - -#ifndef CAIRO_LINE_PRIVATE_H -#define CAIRO_LINE_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-error-private.h" -#include "cairo-compiler-private.h" - -CAIRO_BEGIN_DECLS - -cairo_private int -cairo_lines_compare_at_y(const cairo_line_t *a, - const cairo_line_t *b, - int y); - -CAIRO_END_DECLS - -#endif /* CAIRO_LINE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line.c deleted file mode 100644 index cb13927bdce..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-line.c +++ /dev/null @@ -1,306 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2008 Chris Wilson - * Copyright © 2014 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - * - */ - -#include "cairoint.h" - -#include "cairo-line-inline.h" -#include "cairo-slope-private.h" - -static int -line_compare_for_y_against_x (const cairo_line_t *a, - int32_t y, - int32_t x) -{ - int32_t adx, ady; - int32_t dx, dy; - cairo_int64_t L, R; - - if (x < a->p1.x && x < a->p2.x) - return 1; - if (x > a->p1.x && x > a->p2.x) - return -1; - - adx = a->p2.x - a->p1.x; - dx = x - a->p1.x; - - if (adx == 0) - return -dx; - if (dx == 0 || (adx ^ dx) < 0) - return adx; - - dy = y - a->p1.y; - ady = a->p2.y - a->p1.y; - - L = _cairo_int32x32_64_mul (dy, adx); - R = _cairo_int32x32_64_mul (dx, ady); - - return _cairo_int64_cmp (L, R); -} - -/* - * We need to compare the x-coordinates of a pair of lines for a particular y, - * without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy - * - (Y - A_y) * A_dx * B_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 128 bit arithmetic. For certain, but common, - * input we can reduce this down to a single 32 bit compare by inspecting the - * deltas. - * - * (And put the burden of the work on developing fast 128 bit ops, which are - * required throughout the tessellator.) - * - * See the similar discussion for _slope_compare(). - */ -static int -lines_compare_x_for_y_general (const cairo_line_t *a, - const cairo_line_t *b, - int32_t y) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t dx; - int32_t adx, ady; - int32_t bdx, bdy; - enum { - HAVE_NONE = 0x0, - HAVE_DX = 0x1, - HAVE_ADX = 0x2, - HAVE_DX_ADX = HAVE_DX | HAVE_ADX, - HAVE_BDX = 0x4, - HAVE_DX_BDX = HAVE_DX | HAVE_BDX, - HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, - HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX - } have_dx_adx_bdx = HAVE_ALL; - - ady = a->p2.y - a->p1.y; - adx = a->p2.x - a->p1.x; - if (adx == 0) - have_dx_adx_bdx &= ~HAVE_ADX; - - bdy = b->p2.y - b->p1.y; - bdx = b->p2.x - b->p1.x; - if (bdx == 0) - have_dx_adx_bdx &= ~HAVE_BDX; - - dx = a->p1.x - b->p1.x; - if (dx == 0) - have_dx_adx_bdx &= ~HAVE_DX; - -#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) -#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->p1.y) -#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->p1.y) - switch (have_dx_adx_bdx) { - default: - case HAVE_NONE: - return 0; - case HAVE_DX: - /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ - return dx; /* ady * bdy is positive definite */ - case HAVE_ADX: - /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ - return adx; /* bdy * (y - a->top.y) is positive definite */ - case HAVE_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy */ - return -bdx; /* ady * (y - b->top.y) is positive definite */ - case HAVE_ADX_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ - if ((adx ^ bdx) < 0) { - return adx; - } else if (a->p1.y == b->p1.y) { /* common origin */ - cairo_int64_t adx_bdy, bdx_ady; - - /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ - - adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } else - return _cairo_int128_cmp (A, B); - case HAVE_DX_ADX: - /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ - if ((-adx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t ady_dx, dy_adx; - - ady_dx = _cairo_int32x32_64_mul (ady, dx); - dy_adx = _cairo_int32x32_64_mul (a->p1.y - y, adx); - - return _cairo_int64_cmp (ady_dx, dy_adx); - } - case HAVE_DX_BDX: - /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ - if ((bdx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t bdy_dx, dy_bdx; - - bdy_dx = _cairo_int32x32_64_mul (bdy, dx); - dy_bdx = _cairo_int32x32_64_mul (y - b->p1.y, bdx); - - return _cairo_int64_cmp (bdy_dx, dy_bdx); - } - case HAVE_ALL: - /* XXX try comparing (a->p2.x - b->p2.x) et al */ - return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); - } -#undef B -#undef A -#undef L -} - -static int -lines_compare_x_for_y (const cairo_line_t *a, - const cairo_line_t *b, - int32_t y) -{ - /* If the sweep-line is currently on an end-point of a line, - * then we know its precise x value (and considering that we often need to - * compare events at end-points, this happens frequently enough to warrant - * special casing). - */ - enum { - HAVE_NEITHER = 0x0, - HAVE_AX = 0x1, - HAVE_BX = 0x2, - HAVE_BOTH = HAVE_AX | HAVE_BX - } have_ax_bx = HAVE_BOTH; - int32_t ax, bx; - - if (y == a->p1.y) - ax = a->p1.x; - else if (y == a->p2.y) - ax = a->p2.x; - else - have_ax_bx &= ~HAVE_AX; - - if (y == b->p1.y) - bx = b->p1.x; - else if (y == b->p2.y) - bx = b->p2.x; - else - have_ax_bx &= ~HAVE_BX; - - switch (have_ax_bx) { - default: - case HAVE_NEITHER: - return lines_compare_x_for_y_general (a, b, y); - case HAVE_AX: - return -line_compare_for_y_against_x (b, y, ax); - case HAVE_BX: - return line_compare_for_y_against_x (a, y, bx); - case HAVE_BOTH: - return ax - bx; - } -} - -static int bbox_compare (const cairo_line_t *a, - const cairo_line_t *b) -{ - int32_t amin, amax; - int32_t bmin, bmax; - - if (a->p1.x < a->p2.x) { - amin = a->p1.x; - amax = a->p2.x; - } else { - amin = a->p2.x; - amax = a->p1.x; - } - - if (b->p1.x < b->p2.x) { - bmin = b->p1.x; - bmax = b->p2.x; - } else { - bmin = b->p2.x; - bmax = b->p1.x; - } - - if (amax < bmin) - return -1; - - if (amin > bmax) - return +1; - - return 0; -} - -int cairo_lines_compare_at_y (const cairo_line_t *a, - const cairo_line_t *b, - int y) -{ - cairo_slope_t sa, sb; - int ret; - - if (cairo_lines_equal (a, b)) - return 0; - - /* Don't bother solving for abscissa if the edges' bounding boxes - * can be used to order them. - */ - ret = bbox_compare (a, b); - if (ret) - return ret; - - ret = lines_compare_x_for_y (a, b, y); - if (ret) - return ret; - - _cairo_slope_init (&sa, &a->p1, &a->p2); - _cairo_slope_init (&sb, &b->p1, &b->p2); - - return _cairo_slope_compare (&sb, &sa); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-inline.h deleted file mode 100644 index 0955178d24f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-inline.h +++ /dev/null @@ -1,215 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - * - */ - -#ifndef CAIRO_LIST_INLINE_H -#define CAIRO_LIST_INLINE_H - -#include "cairo-list-private.h" - -#define cairo_list_entry(ptr, type, member) \ - cairo_container_of(ptr, type, member) - -#define cairo_list_first_entry(ptr, type, member) \ - cairo_list_entry((ptr)->next, type, member) - -#define cairo_list_last_entry(ptr, type, member) \ - cairo_list_entry((ptr)->prev, type, member) - -#define cairo_list_foreach(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) - -#define cairo_list_foreach_entry(pos, type, head, member) \ - for (pos = cairo_list_entry((head)->next, type, member);\ - &pos->member != (head); \ - pos = cairo_list_entry(pos->member.next, type, member)) - -#define cairo_list_foreach_entry_safe(pos, n, type, head, member) \ - for (pos = cairo_list_entry ((head)->next, type, member),\ - n = cairo_list_entry (pos->member.next, type, member);\ - &pos->member != (head); \ - pos = n, n = cairo_list_entry (n->member.next, type, member)) - -#define cairo_list_foreach_entry_reverse(pos, type, head, member) \ - for (pos = cairo_list_entry((head)->prev, type, member);\ - &pos->member != (head); \ - pos = cairo_list_entry(pos->member.prev, type, member)) - -#define cairo_list_foreach_entry_reverse_safe(pos, n, type, head, member) \ - for (pos = cairo_list_entry((head)->prev, type, member),\ - n = cairo_list_entry (pos->member.prev, type, member);\ - &pos->member != (head); \ - pos = n, n = cairo_list_entry (n->member.prev, type, member)) - -#ifdef CAIRO_LIST_DEBUG -static inline void -_cairo_list_validate (const cairo_list_t *link) -{ - assert (link->next->prev == link); - assert (link->prev->next == link); -} -static inline void -cairo_list_validate (const cairo_list_t *head) -{ - cairo_list_t *link; - - cairo_list_foreach (link, head) - _cairo_list_validate (link); -} -static inline cairo_bool_t -cairo_list_is_empty (const cairo_list_t *head); -static inline void -cairo_list_validate_is_empty (const cairo_list_t *head) -{ - assert (head->next == NULL || (cairo_list_is_empty (head) && head->next == head->prev)); -} -#else -#define _cairo_list_validate(link) -#define cairo_list_validate(head) -#define cairo_list_validate_is_empty(head) -#endif - -static inline void -cairo_list_init (cairo_list_t *entry) -{ - entry->next = entry; - entry->prev = entry; -} - -static inline void -__cairo_list_add (cairo_list_t *entry, - cairo_list_t *prev, - cairo_list_t *next) -{ - next->prev = entry; - entry->next = next; - entry->prev = prev; - prev->next = entry; -} - -static inline void -cairo_list_add (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - cairo_list_validate_is_empty (entry); - __cairo_list_add (entry, head, head->next); - cairo_list_validate (head); -} - -static inline void -cairo_list_add_tail (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - cairo_list_validate_is_empty (entry); - __cairo_list_add (entry, head->prev, head); - cairo_list_validate (head); -} - -static inline void -__cairo_list_del (cairo_list_t *prev, cairo_list_t *next) -{ - next->prev = prev; - prev->next = next; -} - -static inline void -_cairo_list_del (cairo_list_t *entry) -{ - __cairo_list_del (entry->prev, entry->next); -} - -static inline void -cairo_list_del (cairo_list_t *entry) -{ - _cairo_list_del (entry); - cairo_list_init (entry); -} - -static inline void -cairo_list_move (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - __cairo_list_del (entry->prev, entry->next); - __cairo_list_add (entry, head, head->next); - cairo_list_validate (head); -} - -static inline void -cairo_list_move_tail (cairo_list_t *entry, cairo_list_t *head) -{ - cairo_list_validate (head); - __cairo_list_del (entry->prev, entry->next); - __cairo_list_add (entry, head->prev, head); - cairo_list_validate (head); -} - -static inline void -cairo_list_swap (cairo_list_t *entry, cairo_list_t *other) -{ - __cairo_list_add (entry, other->prev, other->next); - cairo_list_init (other); -} - -static inline cairo_bool_t -cairo_list_is_first (const cairo_list_t *entry, - const cairo_list_t *head) -{ - cairo_list_validate (head); - return entry->prev == head; -} - -static inline cairo_bool_t -cairo_list_is_last (const cairo_list_t *entry, - const cairo_list_t *head) -{ - cairo_list_validate (head); - return entry->next == head; -} - -static inline cairo_bool_t -cairo_list_is_empty (const cairo_list_t *head) -{ - cairo_list_validate (head); - return head->next == head; -} - -static inline cairo_bool_t -cairo_list_is_singular (const cairo_list_t *head) -{ - cairo_list_validate (head); - return head->next == head || head->next == head->prev; -} - -#endif /* CAIRO_LIST_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-private.h deleted file mode 100644 index 9f39b668f82..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-list-private.h +++ /dev/null @@ -1,48 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - * - */ - -#ifndef CAIRO_LIST_PRIVATE_H -#define CAIRO_LIST_PRIVATE_H - -#include "cairo-compiler-private.h" - -/* Basic circular, doubly linked list implementation */ - -typedef struct _cairo_list { - struct _cairo_list *next, *prev; -} cairo_list_t; - -#endif /* CAIRO_LIST_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-lzw.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-lzw.c deleted file mode 100644 index de7f9998376..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-lzw.c +++ /dev/null @@ -1,404 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -typedef struct _lzw_buf { - cairo_status_t status; - - unsigned char *data; - int data_size; - int num_data; - uint32_t pending; - unsigned int pending_bits; -} lzw_buf_t; - -/* An lzw_buf_t is a simple, growable chunk of memory for holding - * variable-size objects of up to 16 bits each. - * - * Initialize an lzw_buf_t to the given size in bytes. - * - * To store objects into the lzw_buf_t, call _lzw_buf_store_bits and - * when finished, call _lzw_buf_store_pending, (which flushes out the - * last few bits that hadn't yet made a complete byte yet). - * - * Instead of returning failure from any functions, lzw_buf_t provides - * a status value that the caller can query, (and should query at - * least once when done with the object). The status value will be - * either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY; - */ -static void -_lzw_buf_init (lzw_buf_t *buf, int size) -{ - if (size == 0) - size = 16; - - buf->status = CAIRO_STATUS_SUCCESS; - buf->data_size = size; - buf->num_data = 0; - buf->pending = 0; - buf->pending_bits = 0; - - buf->data = malloc (size); - if (unlikely (buf->data == NULL)) { - buf->data_size = 0; - buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return; - } -} - -/* Increase the buffer size by doubling. - * - * Returns %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - */ -static cairo_status_t -_lzw_buf_grow (lzw_buf_t *buf) -{ - int new_size = buf->data_size * 2; - unsigned char *new_data; - - if (buf->status) - return buf->status; - - new_data = NULL; - /* check for integer overflow */ - if (new_size / 2 == buf->data_size) - new_data = realloc (buf->data, new_size); - - if (unlikely (new_data == NULL)) { - free (buf->data); - buf->data_size = 0; - buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return buf->status; - } - - buf->data = new_data; - buf->data_size = new_size; - - return CAIRO_STATUS_SUCCESS; -} - -/* Store the lowest num_bits bits of values into buf. - * - * Note: The bits of value above size_in_bits must be 0, (so don't lie - * about the size). - * - * See also _lzw_buf_store_pending which must be called after the last - * call to _lzw_buf_store_bits. - * - * Sets buf->status to either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY. - */ -static void -_lzw_buf_store_bits (lzw_buf_t *buf, uint16_t value, int num_bits) -{ - cairo_status_t status; - - assert (value <= (1 << num_bits) - 1); - - if (buf->status) - return; - - buf->pending = (buf->pending << num_bits) | value; - buf->pending_bits += num_bits; - - while (buf->pending_bits >= 8) { - if (buf->num_data >= buf->data_size) { - status = _lzw_buf_grow (buf); - if (unlikely (status)) - return; - } - buf->data[buf->num_data++] = buf->pending >> (buf->pending_bits - 8); - buf->pending_bits -= 8; - } -} - -/* Store the last remaining pending bits into the buffer. - * - * Note: This function must be called after the last call to - * _lzw_buf_store_bits. - * - * Sets buf->status to either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY. - */ -static void -_lzw_buf_store_pending (lzw_buf_t *buf) -{ - cairo_status_t status; - - if (buf->status) - return; - - if (buf->pending_bits == 0) - return; - - assert (buf->pending_bits < 8); - - if (buf->num_data >= buf->data_size) { - status = _lzw_buf_grow (buf); - if (unlikely (status)) - return; - } - - buf->data[buf->num_data++] = buf->pending << (8 - buf->pending_bits); - buf->pending_bits = 0; -} - -/* LZW defines a few magic code values */ -#define LZW_CODE_CLEAR_TABLE 256 -#define LZW_CODE_EOD 257 -#define LZW_CODE_FIRST 258 - -/* We pack three separate values into a symbol as follows: - * - * 12 bits (31 down to 20): CODE: code value used to represent this symbol - * 12 bits (19 down to 8): PREV: previous code value in chain - * 8 bits ( 7 down to 0): NEXT: next byte value in chain - */ -typedef uint32_t lzw_symbol_t; - -#define LZW_SYMBOL_SET(sym, prev, next) ((sym) = ((prev) << 8)|(next)) -#define LZW_SYMBOL_SET_CODE(sym, code, prev, next) ((sym) = ((code << 20)|(prev) << 8)|(next)) -#define LZW_SYMBOL_GET_CODE(sym) (((sym) >> 20)) -#define LZW_SYMBOL_GET_PREV(sym) (((sym) >> 8) & 0x7ff) -#define LZW_SYMBOL_GET_BYTE(sym) (((sym) >> 0) & 0x0ff) - -/* The PREV+NEXT fields can be seen as the key used to fetch values - * from the hash table, while the code is the value fetched. - */ -#define LZW_SYMBOL_KEY_MASK 0x000fffff - -/* Since code values are only stored starting with 258 we can safely - * use a zero value to represent free slots in the hash table. */ -#define LZW_SYMBOL_FREE 0x00000000 - -/* These really aren't very free for modifying. First, the PostScript - * specification sets the 9-12 bit range. Second, the encoding of - * lzw_symbol_t above also relies on 2 of LZW_BITS_MAX plus one byte - * fitting within 32 bits. - * - * But other than that, the LZW compression scheme could function with - * more bits per code. - */ -#define LZW_BITS_MIN 9 -#define LZW_BITS_MAX 12 -#define LZW_BITS_BOUNDARY(bits) ((1<<(bits))-1) -#define LZW_MAX_SYMBOLS (1<table, 0, LZW_SYMBOL_TABLE_SIZE * sizeof (lzw_symbol_t)); -} - -/* Lookup a symbol in the symbol table. The PREV and NEXT fields of - * symbol form the key for the lookup. - * - * If successful, then this function returns %TRUE and slot_ret will be - * left pointing at the result that will have the CODE field of - * interest. - * - * If the lookup fails, then this function returns %FALSE and slot_ret - * will be pointing at the location in the table to which a new CODE - * value should be stored along with PREV and NEXT. - */ -static cairo_bool_t -_lzw_symbol_table_lookup (lzw_symbol_table_t *table, - lzw_symbol_t symbol, - lzw_symbol_t **slot_ret) -{ - /* The algorithm here is identical to that in cairo-hash.c. We - * copy it here to allow for a rather more efficient - * implementation due to several circumstances that do not apply - * to the more general case: - * - * 1) We have a known bound on the total number of symbols, so we - * have a fixed-size table without any copying when growing - * - * 2) We never delete any entries, so we don't need to - * support/check for DEAD entries during lookup. - * - * 3) The object fits in 32 bits so we store each object in its - * entirety within the table rather than storing objects - * externally and putting pointers in the table, (which here - * would just double the storage requirements and have negative - * impacts on memory locality). - */ - int i, idx, step, hash = symbol & LZW_SYMBOL_KEY_MASK; - lzw_symbol_t candidate; - - idx = hash % LZW_SYMBOL_MOD1; - step = 0; - - *slot_ret = NULL; - for (i = 0; i < LZW_SYMBOL_TABLE_SIZE; i++) - { - candidate = table->table[idx]; - if (candidate == LZW_SYMBOL_FREE) - { - *slot_ret = &table->table[idx]; - return FALSE; - } - else /* candidate is LIVE */ - { - if ((candidate & LZW_SYMBOL_KEY_MASK) == - (symbol & LZW_SYMBOL_KEY_MASK)) - { - *slot_ret = &table->table[idx]; - return TRUE; - } - } - - if (step == 0) { - step = hash % LZW_SYMBOL_MOD2; - if (step == 0) - step = 1; - } - - idx += step; - if (idx >= LZW_SYMBOL_TABLE_SIZE) - idx -= LZW_SYMBOL_TABLE_SIZE; - } - - return FALSE; -} - -/* Compress a bytestream using the LZW algorithm. - * - * This is an original implementation based on reading the - * specification of the LZWDecode filter in the PostScript Language - * Reference. The free parameters in the LZW algorithm are set to the - * values mandated by PostScript, (symbols encoded with widths from 9 - * to 12 bits). - * - * This function returns a pointer to a newly allocated buffer holding - * the compressed data, or %NULL if an out-of-memory situation - * occurs. - * - * Notice that any one of the _lzw_buf functions called here could - * trigger an out-of-memory condition. But lzw_buf_t uses cairo's - * shutdown-on-error idiom, so it's safe to continue to call into - * lzw_buf without having to check for errors, (until a final check at - * the end). - */ -unsigned char * -_cairo_lzw_compress (unsigned char *data, unsigned long *size_in_out) -{ - int bytes_remaining = *size_in_out; - lzw_buf_t buf; - lzw_symbol_table_t table; - lzw_symbol_t symbol, *slot = NULL; /* just to squelch a warning */ - int code_next = LZW_CODE_FIRST; - int code_bits = LZW_BITS_MIN; - int prev, next = 0; /* just to squelch a warning */ - - if (*size_in_out == 0) - return NULL; - - _lzw_buf_init (&buf, *size_in_out); - - _lzw_symbol_table_init (&table); - - /* The LZW header is a clear table code. */ - _lzw_buf_store_bits (&buf, LZW_CODE_CLEAR_TABLE, code_bits); - - while (1) { - - /* Find the longest existing code in the symbol table that - * matches the current input, if any. */ - prev = *data++; - bytes_remaining--; - if (bytes_remaining) { - do - { - next = *data++; - bytes_remaining--; - LZW_SYMBOL_SET (symbol, prev, next); - if (_lzw_symbol_table_lookup (&table, symbol, &slot)) - prev = LZW_SYMBOL_GET_CODE (*slot); - } while (bytes_remaining && *slot != LZW_SYMBOL_FREE); - if (*slot == LZW_SYMBOL_FREE) { - data--; - bytes_remaining++; - } - } - - /* Write the code into the output. This is either a byte read - * directly from the input, or a code from the last successful - * lookup. */ - _lzw_buf_store_bits (&buf, prev, code_bits); - - if (bytes_remaining == 0) - break; - - LZW_SYMBOL_SET_CODE (*slot, code_next++, prev, next); - - if (code_next > LZW_BITS_BOUNDARY(code_bits)) - { - code_bits++; - if (code_bits > LZW_BITS_MAX) { - _lzw_symbol_table_init (&table); - _lzw_buf_store_bits (&buf, LZW_CODE_CLEAR_TABLE, code_bits - 1); - code_bits = LZW_BITS_MIN; - code_next = LZW_CODE_FIRST; - } - } - } - - /* The LZW footer is an end-of-data code. */ - _lzw_buf_store_bits (&buf, LZW_CODE_EOD, code_bits); - - _lzw_buf_store_pending (&buf); - - /* See if we ever ran out of memory while writing to buf. */ - if (buf.status == CAIRO_STATUS_NO_MEMORY) { - *size_in_out = 0; - return NULL; - } - - assert (buf.status == CAIRO_STATUS_SUCCESS); - - *size_in_out = buf.num_data; - return buf.data; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-malloc-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-malloc-private.h deleted file mode 100644 index 1e2c67f8d9a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-malloc-private.h +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#ifndef CAIRO_MALLOC_PRIVATE_H -#define CAIRO_MALLOC_PRIVATE_H - -#include "cairo-wideint-private.h" -#include - -#if HAVE_MEMFAULT -#include -#define CAIRO_INJECT_FAULT() MEMFAULT_INJECT_FAULT() -#else -#define CAIRO_INJECT_FAULT() 0 -#endif - -/** - * _cairo_malloc: - * @size: size in bytes - * - * Allocate @size memory using malloc(). - * The memory should be freed using free(). - * malloc is skipped, if 0 bytes are requested, and %NULL will be returned. - * - * Return value: A pointer to the newly allocated memory, or %NULL in - * case of malloc() failure or size is 0. - **/ - -#define _cairo_malloc(size) \ - ((size) ? malloc((unsigned) (size)) : NULL) - -/** - * _cairo_malloc_ab: - * @a: number of elements to allocate - * @size: size of each element - * - * Allocates @a*@size memory using _cairo_malloc(), taking care to not - * overflow when doing the multiplication. Behaves much like - * calloc(), except that the returned memory is not set to zero. - * The memory should be freed using free(). - * - * @size should be a constant so that the compiler can optimize - * out a constant division. - * - * Return value: A pointer to the newly allocated memory, or %NULL in - * case of malloc() failure or overflow. - **/ - -#define _cairo_malloc_ab(a, size) \ - ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ - _cairo_malloc((unsigned) (a) * (unsigned) (size))) - -/** - * _cairo_realloc_ab: - * @ptr: original pointer to block of memory to be resized - * @a: number of elements to allocate - * @size: size of each element - * - * Reallocates @ptr a block of @a*@size memory using realloc(), taking - * care to not overflow when doing the multiplication. The memory - * should be freed using free(). - * - * @size should be a constant so that the compiler can optimize - * out a constant division. - * - * Return value: A pointer to the newly allocated memory, or %NULL in - * case of realloc() failure or overflow (whereupon the original block - * of memory * is left untouched). - **/ - -#define _cairo_realloc_ab(ptr, a, size) \ - ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ - realloc(ptr, (unsigned) (a) * (unsigned) (size))) - -/** - * _cairo_malloc_abc: - * @a: first factor of number of elements to allocate - * @b: second factor of number of elements to allocate - * @size: size of each element - * - * Allocates @a*@b*@size memory using _cairo_malloc(), taking care to not - * overflow when doing the multiplication. Behaves like - * _cairo_malloc_ab(). The memory should be freed using free(). - * - * @size should be a constant so that the compiler can optimize - * out a constant division. - * - * Return value: A pointer to the newly allocated memory, or %NULL in - * case of malloc() failure or overflow. - **/ - -#define _cairo_malloc_abc(a, b, size) \ - ((b) && (unsigned) (a) >= INT32_MAX / (unsigned) (b) ? NULL : \ - (size) && (unsigned) ((a)*(b)) >= INT32_MAX / (unsigned) (size) ? NULL : \ - _cairo_malloc((unsigned) (a) * (unsigned) (b) * (unsigned) (size))) - -/** - * _cairo_malloc_ab_plus_c: - * @a: number of elements to allocate - * @size: size of each element - * @c: additional size to allocate - * - * Allocates @a*@size+@c memory using _cairo_malloc(), taking care to not - * overflow when doing the arithmetic. Behaves similar to - * _cairo_malloc_ab(). The memory should be freed using free(). - * - * Return value: A pointer to the newly allocated memory, or %NULL in - * case of malloc() failure or overflow. - **/ - -#define _cairo_malloc_ab_plus_c(a, size, c) \ - ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ - (unsigned) (c) >= INT32_MAX - (unsigned) (a) * (unsigned) (size) ? NULL : \ - _cairo_malloc((unsigned) (a) * (unsigned) (size) + (unsigned) (c))) - -#endif /* CAIRO_MALLOC_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mask-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mask-compositor.c deleted file mode 100644 index 4d6b118dda5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mask-compositor.c +++ /dev/null @@ -1,1481 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -/* This compositor renders the shape to a mask using an image surface - * then calls composite. - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-compositor-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-pattern-inline.h" -#include "cairo-region-private.h" -#include "cairo-surface-observer-private.h" -#include "cairo-surface-offset-private.h" -#include "cairo-surface-snapshot-private.h" -#include "cairo-surface-subsurface-private.h" - -typedef cairo_int_status_t -(*draw_func_t) (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *src, - const cairo_rectangle_int_t *src_sample, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip); - -static void do_unaligned_row(void (*blt)(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage), - void *closure, - const cairo_box_t *b, - int tx, int y, int h, - uint16_t coverage) -{ - int x1 = _cairo_fixed_integer_part (b->p1.x) - tx; - int x2 = _cairo_fixed_integer_part (b->p2.x) - tx; - if (x2 > x1) { - if (! _cairo_fixed_is_integer (b->p1.x)) { - blt(closure, x1, y, 1, h, - coverage * (256 - _cairo_fixed_fractional_part (b->p1.x))); - x1++; - } - - if (x2 > x1) - blt(closure, x1, y, x2-x1, h, (coverage << 8) - (coverage >> 8)); - - if (! _cairo_fixed_is_integer (b->p2.x)) - blt(closure, x2, y, 1, h, - coverage * _cairo_fixed_fractional_part (b->p2.x)); - } else - blt(closure, x1, y, 1, h, - coverage * (b->p2.x - b->p1.x)); -} - -static void do_unaligned_box(void (*blt)(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage), - void *closure, - const cairo_box_t *b, int tx, int ty) -{ - int y1 = _cairo_fixed_integer_part (b->p1.y) - ty; - int y2 = _cairo_fixed_integer_part (b->p2.y) - ty; - if (y2 > y1) { - if (! _cairo_fixed_is_integer (b->p1.y)) { - do_unaligned_row(blt, closure, b, tx, y1, 1, - 256 - _cairo_fixed_fractional_part (b->p1.y)); - y1++; - } - - if (y2 > y1) - do_unaligned_row(blt, closure, b, tx, y1, y2-y1, 256); - - if (! _cairo_fixed_is_integer (b->p2.y)) - do_unaligned_row(blt, closure, b, tx, y2, 1, - _cairo_fixed_fractional_part (b->p2.y)); - } else - do_unaligned_row(blt, closure, b, tx, y1, 1, - b->p2.y - b->p1.y); -} - -struct blt_in { - const cairo_mask_compositor_t *compositor; - cairo_surface_t *dst; -}; - -static void blt_in(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct blt_in *info = closure; - cairo_color_t color; - cairo_rectangle_int_t rect; - - if (coverage == 0xffff) - return; - - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - - _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double) 0xffff); - info->compositor->fill_rectangles (info->dst, CAIRO_OPERATOR_IN, - &color, &rect, 1); -} - -static cairo_surface_t * -create_composite_mask (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - void *draw_closure, - draw_func_t draw_func, - draw_func_t mask_func, - const cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *surface; - cairo_int_status_t status; - struct blt_in info; - int i; - - surface = _cairo_surface_create_scratch (dst, CAIRO_CONTENT_ALPHA, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (surface->status)) - return surface; - - status = compositor->acquire (surface); - if (unlikely (status)) { - cairo_surface_destroy (surface); - return _cairo_int_surface_create_in_error (status); - } - - if (!surface->is_clear) { - cairo_rectangle_int_t rect; - - rect.x = rect.y = 0; - rect.width = extents->bounded.width; - rect.height = extents->bounded.height; - - status = compositor->fill_rectangles (surface, CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &rect, 1); - if (unlikely (status)) - goto error; - } - - if (mask_func) { - status = mask_func (compositor, surface, draw_closure, - CAIRO_OPERATOR_SOURCE, NULL, NULL, - extents->bounded.x, extents->bounded.y, - &extents->bounded, extents->clip); - if (likely (status != CAIRO_INT_STATUS_UNSUPPORTED)) - goto out; - } - - /* Is it worth setting the clip region here? */ - status = draw_func (compositor, surface, draw_closure, - CAIRO_OPERATOR_ADD, NULL, NULL, - extents->bounded.x, extents->bounded.y, - &extents->bounded, NULL); - if (unlikely (status)) - goto error; - - info.compositor = compositor; - info.dst = surface; - for (i = 0; i < extents->clip->num_boxes; i++) { - cairo_box_t *b = &extents->clip->boxes[i]; - - if (! _cairo_fixed_is_integer (b->p1.x) || - ! _cairo_fixed_is_integer (b->p1.y) || - ! _cairo_fixed_is_integer (b->p2.x) || - ! _cairo_fixed_is_integer (b->p2.y)) - { - do_unaligned_box(blt_in, &info, b, - extents->bounded.x, - extents->bounded.y); - } - } - - if (extents->clip->path != NULL) { - status = _cairo_clip_combine_with_surface (extents->clip, surface, - extents->bounded.x, - extents->bounded.y); - if (unlikely (status)) - goto error; - } - -out: - compositor->release (surface); - surface->is_clear = FALSE; - return surface; - -error: - compositor->release (surface); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - cairo_surface_destroy (surface); - surface = _cairo_int_surface_create_in_error (status); - } - return surface; -} - -/* Handles compositing with a clip surface when the operator allows - * us to combine the clip with the mask - */ -static cairo_status_t -clip_and_composite_with_mask (const cairo_mask_compositor_t *compositor, - void *draw_closure, - draw_func_t draw_func, - draw_func_t mask_func, - cairo_operator_t op, - cairo_pattern_t *pattern, - const cairo_composite_rectangles_t*extents) -{ - cairo_surface_t *dst = extents->surface; - cairo_surface_t *mask, *src; - int src_x, src_y; - - mask = create_composite_mask (compositor, dst, draw_closure, - draw_func, mask_func, - extents); - if (unlikely (mask->status)) - return mask->status; - - if (pattern != NULL || dst->content != CAIRO_CONTENT_ALPHA) { - src = compositor->pattern_to_surface (dst, - &extents->source_pattern.base, - FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (unlikely (src->status)) { - cairo_surface_destroy (mask); - return src->status; - } - - compositor->composite (dst, op, src, mask, - extents->bounded.x + src_x, - extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - cairo_surface_destroy (src); - } else { - compositor->composite (dst, op, mask, NULL, - 0, 0, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } - cairo_surface_destroy (mask); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -get_clip_source (const cairo_mask_compositor_t *compositor, - cairo_clip_t *clip, - cairo_surface_t *dst, - const cairo_rectangle_int_t *bounds, - int *out_x, int *out_y) -{ - cairo_surface_pattern_t pattern; - cairo_rectangle_int_t r; - cairo_surface_t *surface; - - surface = _cairo_clip_get_image (clip, dst, bounds); - if (unlikely (surface->status)) - return surface; - - _cairo_pattern_init_for_surface (&pattern, surface); - pattern.base.filter = CAIRO_FILTER_NEAREST; - cairo_surface_destroy (surface); - - r.x = r.y = 0; - r.width = bounds->width; - r.height = bounds->height; - - surface = compositor->pattern_to_surface (dst, &pattern.base, TRUE, - &r, &r, out_x, out_y); - _cairo_pattern_fini (&pattern.base); - - *out_x += -bounds->x; - *out_y += -bounds->y; - return surface; -} - -/* Handles compositing with a clip surface when we have to do the operation - * in two pieces and combine them together. - */ -static cairo_status_t -clip_and_composite_combine (const cairo_mask_compositor_t *compositor, - void *draw_closure, - draw_func_t draw_func, - cairo_operator_t op, - const cairo_pattern_t *pattern, - const cairo_composite_rectangles_t*extents) -{ - cairo_surface_t *dst = extents->surface; - cairo_surface_t *tmp, *clip; - cairo_status_t status; - int clip_x, clip_y; - - tmp = _cairo_surface_create_scratch (dst, dst->content, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (tmp->status)) - return tmp->status; - - compositor->composite (tmp, CAIRO_OPERATOR_SOURCE, dst, NULL, - extents->bounded.x, extents->bounded.y, - 0, 0, - 0, 0, - extents->bounded.width, extents->bounded.height); - - status = draw_func (compositor, tmp, draw_closure, op, - pattern, &extents->source_sample_area, - extents->bounded.x, extents->bounded.y, - &extents->bounded, NULL); - if (unlikely (status)) - goto cleanup; - - clip = get_clip_source (compositor, - extents->clip, dst, &extents->bounded, - &clip_x, &clip_y); - if (unlikely ((status = clip->status))) - goto cleanup; - - if (dst->is_clear) { - compositor->composite (dst, CAIRO_OPERATOR_SOURCE, tmp, clip, - 0, 0, - clip_x, clip_y, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } else { - /* Punch the clip out of the destination */ - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, clip, NULL, - clip_x, clip_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - /* Now add the two results together */ - compositor->composite (dst, CAIRO_OPERATOR_ADD, tmp, clip, - 0, 0, - clip_x, clip_y, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } - cairo_surface_destroy (clip); - -cleanup: - cairo_surface_destroy (tmp); - return status; -} - -/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's - * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) - */ -static cairo_status_t -clip_and_composite_source (const cairo_mask_compositor_t *compositor, - void *draw_closure, - draw_func_t draw_func, - draw_func_t mask_func, - cairo_pattern_t *pattern, - const cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *dst = extents->surface; - cairo_surface_t *mask, *src; - int src_x, src_y; - - /* Create a surface that is mask IN clip */ - mask = create_composite_mask (compositor, dst, draw_closure, - draw_func, mask_func, - extents); - if (unlikely (mask->status)) - return mask->status; - - src = compositor->pattern_to_surface (dst, - pattern, - FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (unlikely (src->status)) { - cairo_surface_destroy (mask); - return src->status; - } - - if (dst->is_clear) { - compositor->composite (dst, CAIRO_OPERATOR_SOURCE, src, mask, - extents->bounded.x + src_x, extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } else { - /* Compute dest' = dest OUT (mask IN clip) */ - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - 0, 0, 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - /* Now compute (src IN (mask IN clip)) ADD dest' */ - compositor->composite (dst, CAIRO_OPERATOR_ADD, src, mask, - extents->bounded.x + src_x, extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } - - cairo_surface_destroy (src); - cairo_surface_destroy (mask); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -can_reduce_alpha_op (cairo_operator_t op) -{ - int iop = op; - switch (iop) { - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_ADD: - return TRUE; - default: - return FALSE; - } -} - -static cairo_bool_t -reduce_alpha_op (cairo_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *pattern) -{ - return dst->is_clear && - dst->content == CAIRO_CONTENT_ALPHA && - _cairo_pattern_is_opaque_solid (pattern) && - can_reduce_alpha_op (op); -} - -static cairo_status_t -fixup_unbounded (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - const cairo_composite_rectangles_t *extents) -{ - cairo_rectangle_int_t rects[4]; - int n; - - if (extents->bounded.width == extents->unbounded.width && - extents->bounded.height == extents->unbounded.height) - { - return CAIRO_STATUS_SUCCESS; - } - - n = 0; - if (extents->bounded.width == 0 || extents->bounded.height == 0) { - rects[n].x = extents->unbounded.x; - rects[n].width = extents->unbounded.width; - rects[n].y = extents->unbounded.y; - rects[n].height = extents->unbounded.height; - n++; - } else { - /* top */ - if (extents->bounded.y != extents->unbounded.y) { - rects[n].x = extents->unbounded.x; - rects[n].width = extents->unbounded.width; - rects[n].y = extents->unbounded.y; - rects[n].height = extents->bounded.y - extents->unbounded.y; - n++; - } - /* left */ - if (extents->bounded.x != extents->unbounded.x) { - rects[n].x = extents->unbounded.x; - rects[n].width = extents->bounded.x - extents->unbounded.x; - rects[n].y = extents->bounded.y; - rects[n].height = extents->bounded.height; - n++; - } - /* right */ - if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { - rects[n].x = extents->bounded.x + extents->bounded.width; - rects[n].width = extents->unbounded.x + extents->unbounded.width - rects[n].x; - rects[n].y = extents->bounded.y; - rects[n].height = extents->bounded.height; - n++; - } - /* bottom */ - if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { - rects[n].x = extents->unbounded.x; - rects[n].width = extents->unbounded.width; - rects[n].y = extents->bounded.y + extents->bounded.height; - rects[n].height = extents->unbounded.y + extents->unbounded.height - rects[n].y; - n++; - } - } - - return compositor->fill_rectangles (dst, CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - rects, n); -} - -static cairo_status_t -fixup_unbounded_with_mask (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - const cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *mask; - int mask_x, mask_y; - - mask = get_clip_source (compositor, - extents->clip, dst, &extents->unbounded, - &mask_x, &mask_y); - if (unlikely (mask->status)) - return mask->status; - - /* top */ - if (extents->bounded.y != extents->unbounded.y) { - int x = extents->unbounded.x; - int y = extents->unbounded.y; - int width = extents->unbounded.width; - int height = extents->bounded.y - y; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - x + mask_x, y + mask_y, - 0, 0, - x, y, - width, height); - } - - /* left */ - if (extents->bounded.x != extents->unbounded.x) { - int x = extents->unbounded.x; - int y = extents->bounded.y; - int width = extents->bounded.x - x; - int height = extents->bounded.height; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - x + mask_x, y + mask_y, - 0, 0, - x, y, - width, height); - } - - /* right */ - if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { - int x = extents->bounded.x + extents->bounded.width; - int y = extents->bounded.y; - int width = extents->unbounded.x + extents->unbounded.width - x; - int height = extents->bounded.height; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - x + mask_x, y + mask_y, - 0, 0, - x, y, - width, height); - } - - /* bottom */ - if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { - int x = extents->unbounded.x; - int y = extents->bounded.y + extents->bounded.height; - int width = extents->unbounded.width; - int height = extents->unbounded.y + extents->unbounded.height - y; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - x + mask_x, y + mask_y, - 0, 0, - x, y, - width, height); - } - - cairo_surface_destroy (mask); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -fixup_unbounded_boxes (const cairo_mask_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - cairo_boxes_t clear; - cairo_region_t *clip_region; - cairo_box_t box; - cairo_status_t status; - struct _cairo_boxes_chunk *chunk; - int i; - - assert (boxes->is_pixel_aligned); - - clip_region = NULL; - if (_cairo_clip_is_region (extents->clip) && - (clip_region = _cairo_clip_get_region (extents->clip)) && - cairo_region_contains_rectangle (clip_region, - &extents->bounded) == CAIRO_REGION_OVERLAP_IN) - clip_region = NULL; - - - if (boxes->num_boxes <= 1 && clip_region == NULL) - return fixup_unbounded (compositor, dst, extents); - - _cairo_boxes_init (&clear); - - box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); - box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); - box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); - box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); - - if (clip_region == NULL) { - cairo_boxes_t tmp; - - _cairo_boxes_init (&tmp); - - status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_STATUS_SUCCESS); - - tmp.chunks.next = &boxes->chunks; - tmp.num_boxes += boxes->num_boxes; - - status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, - CAIRO_FILL_RULE_WINDING, - &clear); - - tmp.chunks.next = NULL; - } else { - pixman_box32_t *pbox; - - pbox = pixman_region32_rectangles (&clip_region->rgn, &i); - _cairo_boxes_limit (&clear, (cairo_box_t *) pbox, i); - - status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_STATUS_SUCCESS); - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - status = _cairo_boxes_add (&clear, - CAIRO_ANTIALIAS_DEFAULT, - &chunk->base[i]); - if (unlikely (status)) { - _cairo_boxes_fini (&clear); - return status; - } - } - } - - status = _cairo_bentley_ottmann_tessellate_boxes (&clear, - CAIRO_FILL_RULE_WINDING, - &clear); - } - - if (likely (status == CAIRO_STATUS_SUCCESS)) { - status = compositor->fill_boxes (dst, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - } - - _cairo_boxes_fini (&clear); - - return status; -} - -enum { - NEED_CLIP_REGION = 0x1, - NEED_CLIP_SURFACE = 0x2, - FORCE_CLIP_REGION = 0x4, -}; - -static cairo_bool_t -need_bounded_clip (cairo_composite_rectangles_t *extents) -{ - unsigned int flags = NEED_CLIP_REGION; - if (! _cairo_clip_is_region (extents->clip)) - flags |= NEED_CLIP_SURFACE; - return flags; -} - -static cairo_bool_t -need_unbounded_clip (cairo_composite_rectangles_t *extents) -{ - unsigned int flags = 0; - if (! extents->is_bounded) { - flags |= NEED_CLIP_REGION; - if (! _cairo_clip_is_region (extents->clip)) - flags |= NEED_CLIP_SURFACE; - } - if (extents->clip->path != NULL) - flags |= NEED_CLIP_SURFACE; - return flags; -} - -static cairo_status_t -clip_and_composite (const cairo_mask_compositor_t *compositor, - draw_func_t draw_func, - draw_func_t mask_func, - void *draw_closure, - cairo_composite_rectangles_t*extents, - unsigned int need_clip) -{ - cairo_surface_t *dst = extents->surface; - cairo_operator_t op = extents->op; - cairo_pattern_t *src = &extents->source_pattern.base; - cairo_region_t *clip_region = NULL; - cairo_status_t status; - - compositor->acquire (dst); - - if (need_clip & NEED_CLIP_REGION) { - clip_region = _cairo_clip_get_region (extents->clip); - if ((need_clip & FORCE_CLIP_REGION) == 0 && - _cairo_composite_rectangles_can_reduce_clip (extents, - extents->clip)) - clip_region = NULL; - if (clip_region != NULL) { - status = compositor->set_clip_region (dst, clip_region); - if (unlikely (status)) { - compositor->release (dst); - return status; - } - } - } - - if (reduce_alpha_op (dst, op, &extents->source_pattern.base)) { - op = CAIRO_OPERATOR_ADD; - src = NULL; - } - - if (op == CAIRO_OPERATOR_SOURCE) { - status = clip_and_composite_source (compositor, - draw_closure, draw_func, mask_func, - src, extents); - } else { - if (op == CAIRO_OPERATOR_CLEAR) { - op = CAIRO_OPERATOR_DEST_OUT; - src = NULL; - } - - if (need_clip & NEED_CLIP_SURFACE) { - if (extents->is_bounded) { - status = clip_and_composite_with_mask (compositor, - draw_closure, - draw_func, - mask_func, - op, src, extents); - } else { - status = clip_and_composite_combine (compositor, - draw_closure, - draw_func, - op, src, extents); - } - } else { - status = draw_func (compositor, - dst, draw_closure, - op, src, &extents->source_sample_area, - 0, 0, - &extents->bounded, - extents->clip); - } - } - - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { - if (need_clip & NEED_CLIP_SURFACE) - status = fixup_unbounded_with_mask (compositor, dst, extents); - else - status = fixup_unbounded (compositor, dst, extents); - } - - if (clip_region) - compositor->set_clip_region (dst, NULL); - - compositor->release (dst); - - return status; -} - -static cairo_int_status_t -trim_extents_to_boxes (cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_box_t box; - - _cairo_boxes_extents (boxes, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_status_t -upload_boxes (const cairo_mask_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - const cairo_pattern_t *source = &extents->source_pattern.base; - cairo_surface_t *src; - cairo_rectangle_int_t limit; - cairo_int_status_t status; - int tx, ty; - - src = _cairo_pattern_get_source ((cairo_surface_pattern_t *)source, &limit); - if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Check that the data is entirely within the image */ - if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width || - extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height) - return CAIRO_INT_STATUS_UNSUPPORTED; - - tx += limit.x; - ty += limit.y; - - if (src->type == CAIRO_SURFACE_TYPE_IMAGE) - status = compositor->draw_image_boxes (dst, - (cairo_image_surface_t *)src, - boxes, tx, ty); - else - status = compositor->copy_boxes (dst, src, boxes, &extents->bounded, - tx, ty); - - return status; -} - -static cairo_status_t -composite_boxes (const cairo_mask_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - cairo_operator_t op = extents->op; - const cairo_pattern_t *source = &extents->source_pattern.base; - cairo_bool_t need_clip_mask = extents->clip->path != NULL; - cairo_status_t status; - - if (need_clip_mask && - (! extents->is_bounded || op == CAIRO_OPERATOR_SOURCE)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = compositor->acquire (dst); - if (unlikely (status)) - return status; - - if (! need_clip_mask && source->type == CAIRO_PATTERN_TYPE_SOLID) { - const cairo_color_t *color; - - color = &((cairo_solid_pattern_t *) source)->color; - status = compositor->fill_boxes (dst, op, color, boxes); - } else { - cairo_surface_t *src, *mask = NULL; - int src_x, src_y; - int mask_x = 0, mask_y = 0; - - if (need_clip_mask) { - mask = get_clip_source (compositor, - extents->clip, dst, &extents->bounded, - &mask_x, &mask_y); - if (unlikely (mask->status)) - return mask->status; - - if (op == CAIRO_OPERATOR_CLEAR) { - source = NULL; - op = CAIRO_OPERATOR_DEST_OUT; - } - } - - if (source || mask == NULL) { - src = compositor->pattern_to_surface (dst, source, FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - } else { - src = mask; - src_x = mask_x; - src_y = mask_y; - mask = NULL; - } - - status = compositor->composite_boxes (dst, op, src, mask, - src_x, src_y, - mask_x, mask_y, - 0, 0, - boxes, &extents->bounded); - - cairo_surface_destroy (src); - cairo_surface_destroy (mask); - } - - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) - status = fixup_unbounded_boxes (compositor, extents, boxes); - - compositor->release (dst); - - return status; -} - -static cairo_status_t -clip_and_composite_boxes (const cairo_mask_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - cairo_int_status_t status; - - if (boxes->num_boxes == 0) { - if (extents->is_bounded) - return CAIRO_STATUS_SUCCESS; - - return fixup_unbounded_boxes (compositor, extents, boxes); - } - - if (! boxes->is_pixel_aligned) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = trim_extents_to_boxes (extents, boxes); - if (unlikely (status)) - return status; - - if (extents->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && - extents->clip->path == NULL && - (extents->op == CAIRO_OPERATOR_SOURCE || - (dst->is_clear && (extents->op == CAIRO_OPERATOR_OVER || - extents->op == CAIRO_OPERATOR_ADD)))) - { - status = upload_boxes (compositor, extents, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - return composite_boxes (compositor, extents, boxes); -} - -/* high-level compositor interface */ - -static cairo_int_status_t -_cairo_mask_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; - cairo_boxes_t boxes; - cairo_int_status_t status; - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - _cairo_clip_steal_boxes (extents->clip, &boxes); - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_clip_unsteal_boxes (extents->clip, &boxes); - - return status; -} - -struct composite_opacity_info { - const cairo_mask_compositor_t *compositor; - uint8_t op; - cairo_surface_t *dst; - cairo_surface_t *src; - int src_x, src_y; - double opacity; -}; - -static void composite_opacity(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct composite_opacity_info *info = closure; - const cairo_mask_compositor_t *compositor = info->compositor; - cairo_surface_t *mask; - int mask_x, mask_y; - cairo_color_t color; - cairo_solid_pattern_t solid; - - _cairo_color_init_rgba (&color, 0, 0, 0, info->opacity * coverage); - _cairo_pattern_init_solid (&solid, &color); - mask = compositor->pattern_to_surface (info->dst, &solid.base, TRUE, - &_cairo_unbounded_rectangle, - &_cairo_unbounded_rectangle, - &mask_x, &mask_y); - if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { - if (info->src) { - compositor->composite (info->dst, info->op, info->src, mask, - x + info->src_x, y + info->src_y, - mask_x, mask_y, - x, y, - w, h); - } else { - compositor->composite (info->dst, info->op, mask, NULL, - mask_x, mask_y, - 0, 0, - x, y, - w, h); - } - } - - cairo_surface_destroy (mask); -} - -static cairo_int_status_t -composite_opacity_boxes (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - const cairo_rectangle_int_t *src_sample, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - const cairo_solid_pattern_t *mask_pattern = closure; - struct composite_opacity_info info; - int i; - - assert (clip); - - info.compositor = compositor; - info.op = op; - info.dst = dst; - - if (src_pattern != NULL) { - info.src = compositor->pattern_to_surface (dst, src_pattern, FALSE, - extents, src_sample, - &info.src_x, &info.src_y); - if (unlikely (info.src->status)) - return info.src->status; - } else - info.src = NULL; - - info.opacity = mask_pattern->color.alpha / (double) 0xffff; - - /* XXX for lots of boxes create a clip region for the fully opaque areas */ - for (i = 0; i < clip->num_boxes; i++) - do_unaligned_box(composite_opacity, &info, - &clip->boxes[i], dst_x, dst_y); - cairo_surface_destroy (info.src); - - return CAIRO_STATUS_SUCCESS; -} - -struct composite_box_info { - const cairo_mask_compositor_t *compositor; - cairo_surface_t *dst; - cairo_surface_t *src; - int src_x, src_y; - uint8_t op; -}; - -static void composite_box(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct composite_box_info *info = closure; - const cairo_mask_compositor_t *compositor = info->compositor; - - if (! CAIRO_ALPHA_SHORT_IS_OPAQUE (coverage)) { - cairo_surface_t *mask; - cairo_color_t color; - cairo_solid_pattern_t solid; - int mask_x, mask_y; - - _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double)0xffff); - _cairo_pattern_init_solid (&solid, &color); - - mask = compositor->pattern_to_surface (info->dst, &solid.base, FALSE, - &_cairo_unbounded_rectangle, - &_cairo_unbounded_rectangle, - &mask_x, &mask_y); - - if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { - compositor->composite (info->dst, info->op, info->src, mask, - x + info->src_x, y + info->src_y, - mask_x, mask_y, - x, y, - w, h); - } - - cairo_surface_destroy (mask); - } else { - compositor->composite (info->dst, info->op, info->src, NULL, - x + info->src_x, y + info->src_y, - 0, 0, - x, y, - w, h); - } -} - -static cairo_int_status_t -composite_mask_clip_boxes (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - const cairo_rectangle_int_t *src_sample, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - cairo_composite_rectangles_t *composite = closure; - struct composite_box_info info; - int i; - - assert (src_pattern == NULL); - assert (op == CAIRO_OPERATOR_SOURCE); - - info.compositor = compositor; - info.op = CAIRO_OPERATOR_SOURCE; - info.dst = dst; - info.src = compositor->pattern_to_surface (dst, - &composite->mask_pattern.base, - FALSE, extents, - &composite->mask_sample_area, - &info.src_x, &info.src_y); - if (unlikely (info.src->status)) - return info.src->status; - - info.src_x += dst_x; - info.src_y += dst_y; - - for (i = 0; i < clip->num_boxes; i++) - do_unaligned_box(composite_box, &info, &clip->boxes[i], dst_x, dst_y); - - cairo_surface_destroy (info.src); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_mask (const cairo_mask_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - const cairo_rectangle_int_t *src_sample, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - cairo_composite_rectangles_t *composite = closure; - cairo_surface_t *src, *mask; - int src_x, src_y; - int mask_x, mask_y; - - if (src_pattern != NULL) { - src = compositor->pattern_to_surface (dst, src_pattern, FALSE, - extents, src_sample, - &src_x, &src_y); - if (unlikely (src->status)) - return src->status; - - mask = compositor->pattern_to_surface (dst, &composite->mask_pattern.base, TRUE, - extents, &composite->mask_sample_area, - &mask_x, &mask_y); - if (unlikely (mask->status)) { - cairo_surface_destroy (src); - return mask->status; - } - - compositor->composite (dst, op, src, mask, - extents->x + src_x, extents->y + src_y, - extents->x + mask_x, extents->y + mask_y, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - cairo_surface_destroy (mask); - cairo_surface_destroy (src); - } else { - src = compositor->pattern_to_surface (dst, &composite->mask_pattern.base, FALSE, - extents, &composite->mask_sample_area, - &src_x, &src_y); - if (unlikely (src->status)) - return src->status; - - compositor->composite (dst, op, src, NULL, - extents->x + src_x, extents->y + src_y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - cairo_surface_destroy (src); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_mask_compositor_mask (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - if (extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && - extents->clip->path == NULL && - _cairo_clip_is_region (extents->clip)) { - status = clip_and_composite (compositor, - composite_opacity_boxes, - composite_opacity_boxes, - &extents->mask_pattern.solid, - extents, need_unbounded_clip (extents)); - } else { - status = clip_and_composite (compositor, - composite_mask, - extents->clip->path == NULL ? composite_mask_clip_boxes : NULL, - extents, - extents, need_bounded_clip (extents)); - } - - return status; -} - -static cairo_int_status_t -_cairo_mask_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; - cairo_surface_t *mask; - cairo_surface_pattern_t pattern; - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - if (_cairo_path_fixed_stroke_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, extents->clip); - status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, - style, - ctm, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - mask = cairo_surface_create_similar_image (extents->surface, - CAIRO_FORMAT_A8, - extents->bounded.width, - extents->bounded.height); - if (unlikely (mask->status)) - return mask->status; - - status = _cairo_surface_offset_stroke (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - path, style, ctm, ctm_inverse, - tolerance, antialias, - extents->clip); - if (unlikely (status)) { - cairo_surface_destroy (mask); - return status; - } - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_surface_destroy (mask); - - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->bounded.x, - -extents->bounded.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - status = _cairo_surface_mask (extents->surface, - extents->op, - &extents->source_pattern.base, - &pattern.base, - extents->clip); - _cairo_pattern_fini (&pattern.base); - } - - return status; -} - -static cairo_int_status_t -_cairo_mask_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; - cairo_surface_t *mask; - cairo_surface_pattern_t pattern; - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - if (_cairo_path_fixed_fill_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, extents->clip); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - fill_rule, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - mask = cairo_surface_create_similar_image (extents->surface, - CAIRO_FORMAT_A8, - extents->bounded.width, - extents->bounded.height); - if (unlikely (mask->status)) - return mask->status; - - status = _cairo_surface_offset_fill (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - path, fill_rule, tolerance, antialias, - extents->clip); - if (unlikely (status)) { - cairo_surface_destroy (mask); - return status; - } - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_surface_destroy (mask); - - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->bounded.x, - -extents->bounded.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - status = _cairo_surface_mask (extents->surface, - extents->op, - &extents->source_pattern.base, - &pattern.base, - extents->clip); - _cairo_pattern_fini (&pattern.base); - } - - return status; -} - -static cairo_int_status_t -_cairo_mask_compositor_glyphs (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; - cairo_surface_t *mask; - cairo_surface_pattern_t pattern; - cairo_int_status_t status; - - status = compositor->check_composite (extents); - if (unlikely (status)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - mask = cairo_surface_create_similar_image (extents->surface, - CAIRO_FORMAT_A8, - extents->bounded.width, - extents->bounded.height); - if (unlikely (mask->status)) - return mask->status; - - status = _cairo_surface_offset_glyphs (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - scaled_font, glyphs, num_glyphs, - extents->clip); - if (unlikely (status)) { - cairo_surface_destroy (mask); - return status; - } - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_surface_destroy (mask); - - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->bounded.x, - -extents->bounded.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - status = _cairo_surface_mask (extents->surface, - extents->op, - &extents->source_pattern.base, - &pattern.base, - extents->clip); - _cairo_pattern_fini (&pattern.base); - - return status; -} - -void -_cairo_mask_compositor_init (cairo_mask_compositor_t *compositor, - const cairo_compositor_t *delegate) -{ - compositor->base.delegate = delegate; - - compositor->base.paint = _cairo_mask_compositor_paint; - compositor->base.mask = _cairo_mask_compositor_mask; - compositor->base.fill = _cairo_mask_compositor_fill; - compositor->base.stroke = _cairo_mask_compositor_stroke; - compositor->base.glyphs = _cairo_mask_compositor_glyphs; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-matrix.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-matrix.c deleted file mode 100644 index ae498f5151a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-matrix.c +++ /dev/null @@ -1,1212 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" -#include "cairo-error-private.h" -#include - -#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ - -#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE) -#define ISFINITE(x) isfinite (x) -#else -#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */ -#endif - -/** - * SECTION:cairo-matrix - * @Title: cairo_matrix_t - * @Short_Description: Generic matrix operations - * @See_Also: #cairo_t - * - * #cairo_matrix_t is used throughout cairo to convert between different - * coordinate spaces. A #cairo_matrix_t holds an affine transformation, - * such as a scale, rotation, shear, or a combination of these. - * The transformation of a point (x,y) - * is given by: - * - * - * x_new = xx * x + xy * y + x0; - * y_new = yx * x + yy * y + y0; - * - * - * The current transformation matrix of a #cairo_t, represented as a - * #cairo_matrix_t, defines the transformation from user-space - * coordinates to device-space coordinates. See cairo_get_matrix() and - * cairo_set_matrix(). - **/ - -static void -_cairo_matrix_scalar_multiply (cairo_matrix_t *matrix, double scalar); - -static void -_cairo_matrix_compute_adjoint (cairo_matrix_t *matrix); - -/** - * cairo_matrix_init_identity: - * @matrix: a #cairo_matrix_t - * - * Modifies @matrix to be an identity transformation. - * - * Since: 1.0 - **/ -void -cairo_matrix_init_identity (cairo_matrix_t *matrix) -{ - cairo_matrix_init (matrix, - 1, 0, - 0, 1, - 0, 0); -} -slim_hidden_def(cairo_matrix_init_identity); - -/** - * cairo_matrix_init: - * @matrix: a #cairo_matrix_t - * @xx: xx component of the affine transformation - * @yx: yx component of the affine transformation - * @xy: xy component of the affine transformation - * @yy: yy component of the affine transformation - * @x0: X translation component of the affine transformation - * @y0: Y translation component of the affine transformation - * - * Sets @matrix to be the affine transformation given by - * @xx, @yx, @xy, @yy, @x0, @y0. The transformation is given - * by: - * - * x_new = xx * x + xy * y + x0; - * y_new = yx * x + yy * y + y0; - * - * - * Since: 1.0 - **/ -void -cairo_matrix_init (cairo_matrix_t *matrix, - double xx, double yx, - - double xy, double yy, - double x0, double y0) -{ - matrix->xx = xx; matrix->yx = yx; - matrix->xy = xy; matrix->yy = yy; - matrix->x0 = x0; matrix->y0 = y0; -} -slim_hidden_def(cairo_matrix_init); - -/** - * _cairo_matrix_get_affine: - * @matrix: a #cairo_matrix_t - * @xx: location to store xx component of matrix - * @yx: location to store yx component of matrix - * @xy: location to store xy component of matrix - * @yy: location to store yy component of matrix - * @x0: location to store x0 (X-translation component) of matrix, or %NULL - * @y0: location to store y0 (Y-translation component) of matrix, or %NULL - * - * Gets the matrix values for the affine transformation that @matrix represents. - * See cairo_matrix_init(). - * - * - * This function is a leftover from the old public API, but is still - * mildly useful as an internal means for getting at the matrix - * members in a positional way. For example, when reassigning to some - * external matrix type, or when renaming members to more meaningful - * names (such as a,b,c,d,e,f) for particular manipulations. - **/ -void -_cairo_matrix_get_affine (const cairo_matrix_t *matrix, - double *xx, double *yx, - double *xy, double *yy, - double *x0, double *y0) -{ - *xx = matrix->xx; - *yx = matrix->yx; - - *xy = matrix->xy; - *yy = matrix->yy; - - if (x0) - *x0 = matrix->x0; - if (y0) - *y0 = matrix->y0; -} - -/** - * cairo_matrix_init_translate: - * @matrix: a #cairo_matrix_t - * @tx: amount to translate in the X direction - * @ty: amount to translate in the Y direction - * - * Initializes @matrix to a transformation that translates by @tx and - * @ty in the X and Y dimensions, respectively. - * - * Since: 1.0 - **/ -void -cairo_matrix_init_translate (cairo_matrix_t *matrix, - double tx, double ty) -{ - cairo_matrix_init (matrix, - 1, 0, - 0, 1, - tx, ty); -} -slim_hidden_def(cairo_matrix_init_translate); - -/** - * cairo_matrix_translate: - * @matrix: a #cairo_matrix_t - * @tx: amount to translate in the X direction - * @ty: amount to translate in the Y direction - * - * Applies a translation by @tx, @ty to the transformation in - * @matrix. The effect of the new transformation is to first translate - * the coordinates by @tx and @ty, then apply the original transformation - * to the coordinates. - * - * Since: 1.0 - **/ -void -cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty) -{ - cairo_matrix_t tmp; - - cairo_matrix_init_translate (&tmp, tx, ty); - - cairo_matrix_multiply (matrix, &tmp, matrix); -} -slim_hidden_def (cairo_matrix_translate); - -/** - * cairo_matrix_init_scale: - * @matrix: a #cairo_matrix_t - * @sx: scale factor in the X direction - * @sy: scale factor in the Y direction - * - * Initializes @matrix to a transformation that scales by @sx and @sy - * in the X and Y dimensions, respectively. - * - * Since: 1.0 - **/ -void -cairo_matrix_init_scale (cairo_matrix_t *matrix, - double sx, double sy) -{ - cairo_matrix_init (matrix, - sx, 0, - 0, sy, - 0, 0); -} -slim_hidden_def(cairo_matrix_init_scale); - -/** - * cairo_matrix_scale: - * @matrix: a #cairo_matrix_t - * @sx: scale factor in the X direction - * @sy: scale factor in the Y direction - * - * Applies scaling by @sx, @sy to the transformation in @matrix. The - * effect of the new transformation is to first scale the coordinates - * by @sx and @sy, then apply the original transformation to the coordinates. - * - * Since: 1.0 - **/ -void -cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy) -{ - cairo_matrix_t tmp; - - cairo_matrix_init_scale (&tmp, sx, sy); - - cairo_matrix_multiply (matrix, &tmp, matrix); -} -slim_hidden_def(cairo_matrix_scale); - -/** - * cairo_matrix_init_rotate: - * @matrix: a #cairo_matrix_t - * @radians: angle of rotation, in radians. The direction of rotation - * is defined such that positive angles rotate in the direction from - * the positive X axis toward the positive Y axis. With the default - * axis orientation of cairo, positive angles rotate in a clockwise - * direction. - * - * Initialized @matrix to a transformation that rotates by @radians. - * - * Since: 1.0 - **/ -void -cairo_matrix_init_rotate (cairo_matrix_t *matrix, - double radians) -{ - double s; - double c; - - s = sin (radians); - c = cos (radians); - - cairo_matrix_init (matrix, - c, s, - -s, c, - 0, 0); -} -slim_hidden_def(cairo_matrix_init_rotate); - -/** - * cairo_matrix_rotate: - * @matrix: a #cairo_matrix_t - * @radians: angle of rotation, in radians. The direction of rotation - * is defined such that positive angles rotate in the direction from - * the positive X axis toward the positive Y axis. With the default - * axis orientation of cairo, positive angles rotate in a clockwise - * direction. - * - * Applies rotation by @radians to the transformation in - * @matrix. The effect of the new transformation is to first rotate the - * coordinates by @radians, then apply the original transformation - * to the coordinates. - * - * Since: 1.0 - **/ -void -cairo_matrix_rotate (cairo_matrix_t *matrix, double radians) -{ - cairo_matrix_t tmp; - - cairo_matrix_init_rotate (&tmp, radians); - - cairo_matrix_multiply (matrix, &tmp, matrix); -} - -/** - * cairo_matrix_multiply: - * @result: a #cairo_matrix_t in which to store the result - * @a: a #cairo_matrix_t - * @b: a #cairo_matrix_t - * - * Multiplies the affine transformations in @a and @b together - * and stores the result in @result. The effect of the resulting - * transformation is to first apply the transformation in @a to the - * coordinates and then apply the transformation in @b to the - * coordinates. - * - * It is allowable for @result to be identical to either @a or @b. - * - * Since: 1.0 - **/ -/* - * XXX: The ordering of the arguments to this function corresponds - * to [row_vector]*A*B. If we want to use column vectors instead, - * then we need to switch the two arguments and fix up all - * uses. - */ -void -cairo_matrix_multiply (cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b) -{ - cairo_matrix_t r; - - r.xx = a->xx * b->xx + a->yx * b->xy; - r.yx = a->xx * b->yx + a->yx * b->yy; - - r.xy = a->xy * b->xx + a->yy * b->xy; - r.yy = a->xy * b->yx + a->yy * b->yy; - - r.x0 = a->x0 * b->xx + a->y0 * b->xy + b->x0; - r.y0 = a->x0 * b->yx + a->y0 * b->yy + b->y0; - - *result = r; -} -slim_hidden_def(cairo_matrix_multiply); - -void -_cairo_matrix_multiply (cairo_matrix_t *r, - const cairo_matrix_t *a, - const cairo_matrix_t *b) -{ - r->xx = a->xx * b->xx + a->yx * b->xy; - r->yx = a->xx * b->yx + a->yx * b->yy; - - r->xy = a->xy * b->xx + a->yy * b->xy; - r->yy = a->xy * b->yx + a->yy * b->yy; - - r->x0 = a->x0 * b->xx + a->y0 * b->xy + b->x0; - r->y0 = a->x0 * b->yx + a->y0 * b->yy + b->y0; -} - -/** - * cairo_matrix_transform_distance: - * @matrix: a #cairo_matrix_t - * @dx: X component of a distance vector. An in/out parameter - * @dy: Y component of a distance vector. An in/out parameter - * - * Transforms the distance vector (@dx,@dy) by @matrix. This is - * similar to cairo_matrix_transform_point() except that the translation - * components of the transformation are ignored. The calculation of - * the returned vector is as follows: - * - * - * dx2 = dx1 * a + dy1 * c; - * dy2 = dx1 * b + dy1 * d; - * - * - * Affine transformations are position invariant, so the same vector - * always transforms to the same vector. If (@x1,@y1) transforms - * to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to - * (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2. - * - * Since: 1.0 - **/ -void -cairo_matrix_transform_distance (const cairo_matrix_t *matrix, double *dx, double *dy) -{ - double new_x, new_y; - - new_x = (matrix->xx * *dx + matrix->xy * *dy); - new_y = (matrix->yx * *dx + matrix->yy * *dy); - - *dx = new_x; - *dy = new_y; -} -slim_hidden_def(cairo_matrix_transform_distance); - -/** - * cairo_matrix_transform_point: - * @matrix: a #cairo_matrix_t - * @x: X position. An in/out parameter - * @y: Y position. An in/out parameter - * - * Transforms the point (@x, @y) by @matrix. - * - * Since: 1.0 - **/ -void -cairo_matrix_transform_point (const cairo_matrix_t *matrix, double *x, double *y) -{ - cairo_matrix_transform_distance (matrix, x, y); - - *x += matrix->x0; - *y += matrix->y0; -} -slim_hidden_def(cairo_matrix_transform_point); - -void -_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix, - double *x1, double *y1, - double *x2, double *y2, - cairo_bool_t *is_tight) -{ - int i; - double quad_x[4], quad_y[4]; - double min_x, max_x; - double min_y, max_y; - - if (matrix->xy == 0. && matrix->yx == 0.) { - /* non-rotation/skew matrix, just map the two extreme points */ - - if (matrix->xx != 1.) { - quad_x[0] = *x1 * matrix->xx; - quad_x[1] = *x2 * matrix->xx; - if (quad_x[0] < quad_x[1]) { - *x1 = quad_x[0]; - *x2 = quad_x[1]; - } else { - *x1 = quad_x[1]; - *x2 = quad_x[0]; - } - } - if (matrix->x0 != 0.) { - *x1 += matrix->x0; - *x2 += matrix->x0; - } - - if (matrix->yy != 1.) { - quad_y[0] = *y1 * matrix->yy; - quad_y[1] = *y2 * matrix->yy; - if (quad_y[0] < quad_y[1]) { - *y1 = quad_y[0]; - *y2 = quad_y[1]; - } else { - *y1 = quad_y[1]; - *y2 = quad_y[0]; - } - } - if (matrix->y0 != 0.) { - *y1 += matrix->y0; - *y2 += matrix->y0; - } - - if (is_tight) - *is_tight = TRUE; - - return; - } - - /* general matrix */ - quad_x[0] = *x1; - quad_y[0] = *y1; - cairo_matrix_transform_point (matrix, &quad_x[0], &quad_y[0]); - - quad_x[1] = *x2; - quad_y[1] = *y1; - cairo_matrix_transform_point (matrix, &quad_x[1], &quad_y[1]); - - quad_x[2] = *x1; - quad_y[2] = *y2; - cairo_matrix_transform_point (matrix, &quad_x[2], &quad_y[2]); - - quad_x[3] = *x2; - quad_y[3] = *y2; - cairo_matrix_transform_point (matrix, &quad_x[3], &quad_y[3]); - - min_x = max_x = quad_x[0]; - min_y = max_y = quad_y[0]; - - for (i=1; i < 4; i++) { - if (quad_x[i] < min_x) - min_x = quad_x[i]; - if (quad_x[i] > max_x) - max_x = quad_x[i]; - - if (quad_y[i] < min_y) - min_y = quad_y[i]; - if (quad_y[i] > max_y) - max_y = quad_y[i]; - } - - *x1 = min_x; - *y1 = min_y; - *x2 = max_x; - *y2 = max_y; - - if (is_tight) { - /* it's tight if and only if the four corner points form an axis-aligned - rectangle. - And that's true if and only if we can derive corners 0 and 3 from - corners 1 and 2 in one of two straightforward ways... - We could use a tolerance here but for now we'll fall back to FALSE in the case - of floating point error. - */ - *is_tight = - (quad_x[1] == quad_x[0] && quad_y[1] == quad_y[3] && - quad_x[2] == quad_x[3] && quad_y[2] == quad_y[0]) || - (quad_x[1] == quad_x[3] && quad_y[1] == quad_y[0] && - quad_x[2] == quad_x[0] && quad_y[2] == quad_y[3]); - } -} - -cairo_private void -_cairo_matrix_transform_bounding_box_fixed (const cairo_matrix_t *matrix, - cairo_box_t *bbox, - cairo_bool_t *is_tight) -{ - double x1, y1, x2, y2; - - _cairo_box_to_doubles (bbox, &x1, &y1, &x2, &y2); - _cairo_matrix_transform_bounding_box (matrix, &x1, &y1, &x2, &y2, is_tight); - _cairo_box_from_doubles (bbox, &x1, &y1, &x2, &y2); -} - -static void -_cairo_matrix_scalar_multiply (cairo_matrix_t *matrix, double scalar) -{ - matrix->xx *= scalar; - matrix->yx *= scalar; - - matrix->xy *= scalar; - matrix->yy *= scalar; - - matrix->x0 *= scalar; - matrix->y0 *= scalar; -} - -/* This function isn't a correct adjoint in that the implicit 1 in the - homogeneous result should actually be ad-bc instead. But, since this - adjoint is only used in the computation of the inverse, which - divides by det (A)=ad-bc anyway, everything works out in the end. */ -static void -_cairo_matrix_compute_adjoint (cairo_matrix_t *matrix) -{ - /* adj (A) = transpose (C:cofactor (A,i,j)) */ - double a, b, c, d, tx, ty; - - _cairo_matrix_get_affine (matrix, - &a, &b, - &c, &d, - &tx, &ty); - - cairo_matrix_init (matrix, - d, -b, - -c, a, - c*ty - d*tx, b*tx - a*ty); -} - -/** - * cairo_matrix_invert: - * @matrix: a #cairo_matrix_t - * - * Changes @matrix to be the inverse of its original value. Not - * all transformation matrices have inverses; if the matrix - * collapses points together (it is degenerate), - * then it has no inverse and this function will fail. - * - * Returns: If @matrix has an inverse, modifies @matrix to - * be the inverse matrix and returns %CAIRO_STATUS_SUCCESS. Otherwise, - * returns %CAIRO_STATUS_INVALID_MATRIX. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_matrix_invert (cairo_matrix_t *matrix) -{ - double det; - - /* Simple scaling|translation matrices are quite common... */ - if (matrix->xy == 0. && matrix->yx == 0.) { - matrix->x0 = -matrix->x0; - matrix->y0 = -matrix->y0; - - if (matrix->xx != 1.) { - if (matrix->xx == 0.) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - matrix->xx = 1. / matrix->xx; - matrix->x0 *= matrix->xx; - } - - if (matrix->yy != 1.) { - if (matrix->yy == 0.) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - matrix->yy = 1. / matrix->yy; - matrix->y0 *= matrix->yy; - } - - return CAIRO_STATUS_SUCCESS; - } - - /* inv (A) = 1/det (A) * adj (A) */ - det = _cairo_matrix_compute_determinant (matrix); - - if (! ISFINITE (det)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - if (det == 0) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - _cairo_matrix_compute_adjoint (matrix); - _cairo_matrix_scalar_multiply (matrix, 1 / det); - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def(cairo_matrix_invert); - -cairo_bool_t -_cairo_matrix_is_invertible (const cairo_matrix_t *matrix) -{ - double det; - - det = _cairo_matrix_compute_determinant (matrix); - - return ISFINITE (det) && det != 0.; -} - -cairo_bool_t -_cairo_matrix_is_scale_0 (const cairo_matrix_t *matrix) -{ - return matrix->xx == 0. && - matrix->xy == 0. && - matrix->yx == 0. && - matrix->yy == 0.; -} - -double -_cairo_matrix_compute_determinant (const cairo_matrix_t *matrix) -{ - double a, b, c, d; - - a = matrix->xx; b = matrix->yx; - c = matrix->xy; d = matrix->yy; - - return a*d - b*c; -} - -/** - * _cairo_matrix_compute_basis_scale_factors: - * @matrix: a matrix - * @basis_scale: the scale factor in the direction of basis - * @normal_scale: the scale factor in the direction normal to the basis - * @x_basis: basis to use. X basis if true, Y basis otherwise. - * - * Computes |Mv| and det(M)/|Mv| for v=[1,0] if x_basis is true, and v=[0,1] - * otherwise, and M is @matrix. - * - * Return value: the scale factor of @matrix on the height of the font, - * or 1.0 if @matrix is %NULL. - **/ -cairo_status_t -_cairo_matrix_compute_basis_scale_factors (const cairo_matrix_t *matrix, - double *basis_scale, double *normal_scale, - cairo_bool_t x_basis) -{ - double det; - - det = _cairo_matrix_compute_determinant (matrix); - - if (! ISFINITE (det)) - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - - if (det == 0) - { - *basis_scale = *normal_scale = 0; - } - else - { - double x = x_basis != 0; - double y = x == 0; - double major, minor; - - cairo_matrix_transform_distance (matrix, &x, &y); - major = hypot (x, y); - /* - * ignore mirroring - */ - if (det < 0) - det = -det; - if (major) - minor = det / major; - else - minor = 0.0; - if (x_basis) - { - *basis_scale = major; - *normal_scale = minor; - } - else - { - *basis_scale = minor; - *normal_scale = major; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_bool_t -_cairo_matrix_is_integer_translation (const cairo_matrix_t *matrix, - int *itx, int *ity) -{ - if (_cairo_matrix_is_translation (matrix)) - { - cairo_fixed_t x0_fixed = _cairo_fixed_from_double (matrix->x0); - cairo_fixed_t y0_fixed = _cairo_fixed_from_double (matrix->y0); - - if (_cairo_fixed_is_integer (x0_fixed) && - _cairo_fixed_is_integer (y0_fixed)) - { - if (itx) - *itx = _cairo_fixed_integer_part (x0_fixed); - if (ity) - *ity = _cairo_fixed_integer_part (y0_fixed); - - return TRUE; - } - } - - return FALSE; -} - -#define SCALING_EPSILON _cairo_fixed_to_double(1) - -/* This only returns true if the matrix is 90 degree rotations or - * flips. It appears calling code is relying on this. It will return - * false for other rotations even if the scale is one. Approximations - * are allowed to handle matricies filled in using trig functions - * such as sin(M_PI_2). - */ -cairo_bool_t -_cairo_matrix_has_unity_scale (const cairo_matrix_t *matrix) -{ - /* check that the determinant is near +/-1 */ - double det = _cairo_matrix_compute_determinant (matrix); - if (fabs (det * det - 1.0) < SCALING_EPSILON) { - /* check that one axis is close to zero */ - if (fabs (matrix->xy) < SCALING_EPSILON && - fabs (matrix->yx) < SCALING_EPSILON) - return TRUE; - if (fabs (matrix->xx) < SCALING_EPSILON && - fabs (matrix->yy) < SCALING_EPSILON) - return TRUE; - /* If rotations are allowed then it must instead test for - * orthogonality. This is xx*xy+yx*yy ~= 0. - */ - } - return FALSE; -} - -/* By pixel exact here, we mean a matrix that is composed only of - * 90 degree rotations, flips, and integer translations and produces a 1:1 - * mapping between source and destination pixels. If we transform an image - * with a pixel-exact matrix, filtering is not useful. - */ -cairo_bool_t -_cairo_matrix_is_pixel_exact (const cairo_matrix_t *matrix) -{ - cairo_fixed_t x0_fixed, y0_fixed; - - if (! _cairo_matrix_has_unity_scale (matrix)) - return FALSE; - - x0_fixed = _cairo_fixed_from_double (matrix->x0); - y0_fixed = _cairo_fixed_from_double (matrix->y0); - - return _cairo_fixed_is_integer (x0_fixed) && _cairo_fixed_is_integer (y0_fixed); -} - -/* - A circle in user space is transformed into an ellipse in device space. - - The following is a derivation of a formula to calculate the length of the - major axis for this ellipse; this is useful for error bounds calculations. - - Thanks to Walter Brisken for this derivation: - - 1. First some notation: - - All capital letters represent vectors in two dimensions. A prime ' - represents a transformed coordinate. Matrices are written in underlined - form, ie _R_. Lowercase letters represent scalar real values. - - 2. The question has been posed: What is the maximum expansion factor - achieved by the linear transformation - - X' = X _R_ - - where _R_ is a real-valued 2x2 matrix with entries: - - _R_ = [a b] - [c d] . - - In other words, what is the maximum radius, MAX[ |X'| ], reached for any - X on the unit circle ( |X| = 1 ) ? - - 3. Some useful formulae - - (A) through (C) below are standard double-angle formulae. (D) is a lesser - known result and is derived below: - - (A) sin²(θ) = (1 - cos(2*θ))/2 - (B) cos²(θ) = (1 + cos(2*θ))/2 - (C) sin(θ)*cos(θ) = sin(2*θ)/2 - (D) MAX[a*cos(θ) + b*sin(θ)] = sqrt(a² + b²) - - Proof of (D): - - find the maximum of the function by setting the derivative to zero: - - -a*sin(θ)+b*cos(θ) = 0 - - From this it follows that - - tan(θ) = b/a - - and hence - - sin(θ) = b/sqrt(a² + b²) - - and - - cos(θ) = a/sqrt(a² + b²) - - Thus the maximum value is - - MAX[a*cos(θ) + b*sin(θ)] = (a² + b²)/sqrt(a² + b²) - = sqrt(a² + b²) - - 4. Derivation of maximum expansion - - To find MAX[ |X'| ] we search brute force method using calculus. The unit - circle on which X is constrained is to be parameterized by t: - - X(θ) = (cos(θ), sin(θ)) - - Thus - - X'(θ) = X(θ) * _R_ = (cos(θ), sin(θ)) * [a b] - [c d] - = (a*cos(θ) + c*sin(θ), b*cos(θ) + d*sin(θ)). - - Define - - r(θ) = |X'(θ)| - - Thus - - r²(θ) = (a*cos(θ) + c*sin(θ))² + (b*cos(θ) + d*sin(θ))² - = (a² + b²)*cos²(θ) + (c² + d²)*sin²(θ) - + 2*(a*c + b*d)*cos(θ)*sin(θ) - - Now apply the double angle formulae (A) to (C) from above: - - r²(θ) = (a² + b² + c² + d²)/2 - + (a² + b² - c² - d²)*cos(2*θ)/2 - + (a*c + b*d)*sin(2*θ) - = f + g*cos(φ) + h*sin(φ) - - Where - - f = (a² + b² + c² + d²)/2 - g = (a² + b² - c² - d²)/2 - h = (a*c + d*d) - φ = 2*θ - - It is clear that MAX[ |X'| ] = sqrt(MAX[ r² ]). Here we determine MAX[ r² ] - using (D) from above: - - MAX[ r² ] = f + sqrt(g² + h²) - - And finally - - MAX[ |X'| ] = sqrt( f + sqrt(g² + h²) ) - - Which is the solution to this problem. - - Walter Brisken - 2004/10/08 - - (Note that the minor axis length is at the minimum of the above solution, - which is just sqrt ( f - sqrt(g² + h²) ) given the symmetry of (D)). - - - For another derivation of the same result, using Singular Value Decomposition, - see doc/tutorial/src/singular.c. -*/ - -/* determine the length of the major axis of a circle of the given radius - after applying the transformation matrix. */ -double -_cairo_matrix_transformed_circle_major_axis (const cairo_matrix_t *matrix, - double radius) -{ - double a, b, c, d, f, g, h, i, j; - - if (_cairo_matrix_has_unity_scale (matrix)) - return radius; - - _cairo_matrix_get_affine (matrix, - &a, &b, - &c, &d, - NULL, NULL); - - i = a*a + b*b; - j = c*c + d*d; - - f = 0.5 * (i + j); - g = 0.5 * (i - j); - h = a*c + b*d; - - return radius * sqrt (f + hypot (g, h)); - - /* - * we don't need the minor axis length, which is - * double min = radius * sqrt (f - sqrt (g*g+h*h)); - */ -} - -static const pixman_transform_t pixman_identity_transform = {{ - {1 << 16, 0, 0}, - { 0, 1 << 16, 0}, - { 0, 0, 1 << 16} - }}; - -static cairo_status_t -_cairo_matrix_to_pixman_matrix (const cairo_matrix_t *matrix, - pixman_transform_t *pixman_transform, - double xc, - double yc) -{ - cairo_matrix_t inv; - unsigned max_iterations; - - pixman_transform->matrix[0][0] = _cairo_fixed_16_16_from_double (matrix->xx); - pixman_transform->matrix[0][1] = _cairo_fixed_16_16_from_double (matrix->xy); - pixman_transform->matrix[0][2] = _cairo_fixed_16_16_from_double (matrix->x0); - - pixman_transform->matrix[1][0] = _cairo_fixed_16_16_from_double (matrix->yx); - pixman_transform->matrix[1][1] = _cairo_fixed_16_16_from_double (matrix->yy); - pixman_transform->matrix[1][2] = _cairo_fixed_16_16_from_double (matrix->y0); - - pixman_transform->matrix[2][0] = 0; - pixman_transform->matrix[2][1] = 0; - pixman_transform->matrix[2][2] = 1 << 16; - - /* The conversion above breaks cairo's translation invariance: - * a translation of (a, b) in device space translates to - * a translation of (xx * a + xy * b, yx * a + yy * b) - * for cairo, while pixman uses rounded versions of xx ... yy. - * This error increases as a and b get larger. - * - * To compensate for this, we fix the point (xc, yc) in pattern - * space and adjust pixman's transform to agree with cairo's at - * that point. - */ - - if (_cairo_matrix_has_unity_scale (matrix)) - return CAIRO_STATUS_SUCCESS; - - if (unlikely (fabs (matrix->xx) > PIXMAN_MAX_INT || - fabs (matrix->xy) > PIXMAN_MAX_INT || - fabs (matrix->x0) > PIXMAN_MAX_INT || - fabs (matrix->yx) > PIXMAN_MAX_INT || - fabs (matrix->yy) > PIXMAN_MAX_INT || - fabs (matrix->y0) > PIXMAN_MAX_INT)) - { - return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); - } - - /* Note: If we can't invert the transformation, skip the adjustment. */ - inv = *matrix; - if (cairo_matrix_invert (&inv) != CAIRO_STATUS_SUCCESS) - return CAIRO_STATUS_SUCCESS; - - /* find the pattern space coordinate that maps to (xc, yc) */ - max_iterations = 5; - do { - double x,y; - pixman_vector_t vector; - cairo_fixed_16_16_t dx, dy; - - vector.vector[0] = _cairo_fixed_16_16_from_double (xc); - vector.vector[1] = _cairo_fixed_16_16_from_double (yc); - vector.vector[2] = 1 << 16; - - /* If we can't transform the reference point, skip the adjustment. */ - if (! pixman_transform_point_3d (pixman_transform, &vector)) - return CAIRO_STATUS_SUCCESS; - - x = pixman_fixed_to_double (vector.vector[0]); - y = pixman_fixed_to_double (vector.vector[1]); - cairo_matrix_transform_point (&inv, &x, &y); - - /* Ideally, the vector should now be (xc, yc). - * We can now compensate for the resulting error. - */ - x -= xc; - y -= yc; - cairo_matrix_transform_distance (matrix, &x, &y); - dx = _cairo_fixed_16_16_from_double (x); - dy = _cairo_fixed_16_16_from_double (y); - pixman_transform->matrix[0][2] -= dx; - pixman_transform->matrix[1][2] -= dy; - - if (dx == 0 && dy == 0) - return CAIRO_STATUS_SUCCESS; - } while (--max_iterations); - - /* We didn't find an exact match between cairo and pixman, but - * the matrix should be mostly correct */ - return CAIRO_STATUS_SUCCESS; -} - -static inline double -_pixman_nearest_sample (double d) -{ - return ceil (d - .5); -} - -/** - * _cairo_matrix_is_pixman_translation: - * @matrix: a matrix - * @filter: the filter to be used on the pattern transformed by @matrix - * @x_offset: the translation in the X direction - * @y_offset: the translation in the Y direction - * - * Checks if @matrix translated by (x_offset, y_offset) can be - * represented using just an offset (within the range pixman can - * accept) and an identity matrix. - * - * Passing a non-zero value in x_offset/y_offset has the same effect - * as applying cairo_matrix_translate(matrix, x_offset, y_offset) and - * setting x_offset and y_offset to 0. - * - * Upon return x_offset and y_offset contain the translation vector if - * the return value is %TRUE. If the return value is %FALSE, they will - * not be modified. - * - * Return value: %TRUE if @matrix can be represented as a pixman - * translation, %FALSE otherwise. - **/ -cairo_bool_t -_cairo_matrix_is_pixman_translation (const cairo_matrix_t *matrix, - cairo_filter_t filter, - int *x_offset, - int *y_offset) -{ - double tx, ty; - - if (!_cairo_matrix_is_translation (matrix)) - return FALSE; - - if (matrix->x0 == 0. && matrix->y0 == 0.) - return TRUE; - - tx = matrix->x0 + *x_offset; - ty = matrix->y0 + *y_offset; - - if (filter == CAIRO_FILTER_FAST || filter == CAIRO_FILTER_NEAREST) { - tx = _pixman_nearest_sample (tx); - ty = _pixman_nearest_sample (ty); - } else if (tx != floor (tx) || ty != floor (ty)) { - return FALSE; - } - - if (fabs (tx) > PIXMAN_MAX_INT || fabs (ty) > PIXMAN_MAX_INT) - return FALSE; - - *x_offset = _cairo_lround (tx); - *y_offset = _cairo_lround (ty); - return TRUE; -} - -/** - * _cairo_matrix_to_pixman_matrix_offset: - * @matrix: a matrix - * @filter: the filter to be used on the pattern transformed by @matrix - * @xc: the X coordinate of the point to fix in pattern space - * @yc: the Y coordinate of the point to fix in pattern space - * @out_transform: the transformation which best approximates @matrix - * @x_offset: the translation in the X direction - * @y_offset: the translation in the Y direction - * - * This function tries to represent @matrix translated by (x_offset, - * y_offset) as a %pixman_transform_t and an translation. - * - * Passing a non-zero value in x_offset/y_offset has the same effect - * as applying cairo_matrix_translate(matrix, x_offset, y_offset) and - * setting x_offset and y_offset to 0. - * - * If it is possible to represent the matrix with an identity - * %pixman_transform_t and a translation within the valid range for - * pixman, this function will set @out_transform to be the identity, - * @x_offset and @y_offset to be the translation vector and will - * return %CAIRO_INT_STATUS_NOTHING_TO_DO. Otherwise it will try to - * evenly divide the translational component of @matrix between - * @out_transform and (@x_offset, @y_offset). - * - * Upon return x_offset and y_offset contain the translation vector. - * - * Return value: %CAIRO_INT_STATUS_NOTHING_TO_DO if the out_transform - * is the identity, %CAIRO_STATUS_INVALID_MATRIX if it was not - * possible to represent @matrix as a pixman_transform_t without - * overflows, %CAIRO_STATUS_SUCCESS otherwise. - **/ -cairo_status_t -_cairo_matrix_to_pixman_matrix_offset (const cairo_matrix_t *matrix, - cairo_filter_t filter, - double xc, - double yc, - pixman_transform_t *out_transform, - int *x_offset, - int *y_offset) -{ - cairo_bool_t is_pixman_translation; - - is_pixman_translation = _cairo_matrix_is_pixman_translation (matrix, - filter, - x_offset, - y_offset); - - if (is_pixman_translation) { - *out_transform = pixman_identity_transform; - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } else { - cairo_matrix_t m; - - m = *matrix; - cairo_matrix_translate (&m, *x_offset, *y_offset); - if (m.x0 != 0.0 || m.y0 != 0.0) { - double tx, ty, norm; - int i, j; - - /* pixman also limits the [xy]_offset to 16 bits so evenly - * spread the bits between the two. - * - * To do this, find the solutions of: - * |x| = |x*m.xx + y*m.xy + m.x0| - * |y| = |x*m.yx + y*m.yy + m.y0| - * - * and select the one whose maximum norm is smallest. - */ - tx = m.x0; - ty = m.y0; - norm = MAX (fabs (tx), fabs (ty)); - - for (i = -1; i < 2; i+=2) { - for (j = -1; j < 2; j+=2) { - double x, y, den, new_norm; - - den = (m.xx + i) * (m.yy + j) - m.xy * m.yx; - if (fabs (den) < DBL_EPSILON) - continue; - - x = m.y0 * m.xy - m.x0 * (m.yy + j); - y = m.x0 * m.yx - m.y0 * (m.xx + i); - - den = 1 / den; - x *= den; - y *= den; - - new_norm = MAX (fabs (x), fabs (y)); - if (norm > new_norm) { - norm = new_norm; - tx = x; - ty = y; - } - } - } - - tx = floor (tx); - ty = floor (ty); - *x_offset = -tx; - *y_offset = -ty; - cairo_matrix_translate (&m, tx, ty); - } else { - *x_offset = 0; - *y_offset = 0; - } - - return _cairo_matrix_to_pixman_matrix (&m, out_transform, xc, yc); - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool-private.h deleted file mode 100644 index a09f6ce51f6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool-private.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributors(s): - * Chris Wilson - */ - -#ifndef CAIRO_MEMPOOL_PRIVATE_H -#define CAIRO_MEMPOOL_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" - -#include /* for size_t */ - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_mempool cairo_mempool_t; - -struct _cairo_mempool { - char *base; - struct _cairo_memblock { - int bits; - cairo_list_t link; - } *blocks; - cairo_list_t free[32]; - unsigned char *map; - - unsigned int num_blocks; - int min_bits; /* Minimum block size is 1 << min_bits */ - int num_sizes; - int max_free_bits; - - size_t free_bytes; - size_t max_bytes; -}; - -cairo_private cairo_status_t -_cairo_mempool_init (cairo_mempool_t *pool, - void *base, - size_t bytes, - int min_bits, - int num_sizes); - -cairo_private void * -_cairo_mempool_alloc (cairo_mempool_t *pi, size_t bytes); - -cairo_private void -_cairo_mempool_free (cairo_mempool_t *pi, void *storage); - -cairo_private void -_cairo_mempool_fini (cairo_mempool_t *pool); - -CAIRO_END_DECLS - -#endif /* CAIRO_MEMPOOL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool.c deleted file mode 100644 index 751ede320f3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mempool.c +++ /dev/null @@ -1,369 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipoolent may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributors(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-mempool-private.h" -#include "cairo-list-inline.h" - -/* a simple buddy allocator for memory pools - * XXX fragmentation? use Doug Lea's malloc? - */ - -#define BITTEST(p, n) ((p)->map[(n) >> 3] & (128 >> ((n) & 7))) -#define BITSET(p, n) ((p)->map[(n) >> 3] |= (128 >> ((n) & 7))) -#define BITCLEAR(p, n) ((p)->map[(n) >> 3] &= ~(128 >> ((n) & 7))) - -static void -clear_bits (cairo_mempool_t *pool, size_t first, size_t last) -{ - size_t i, n = last; - size_t first_full = (first + 7) & ~7; - size_t past_full = last & ~7; - size_t bytes; - - if (n > first_full) - n = first_full; - for (i = first; i < n; i++) - BITCLEAR (pool, i); - - if (past_full > first_full) { - bytes = past_full - first_full; - bytes = bytes >> 3; - memset (pool->map + (first_full >> 3), 0, bytes); - } - - if (past_full < n) - past_full = n; - for (i = past_full; i < last; i++) - BITCLEAR (pool, i); -} - -static void -free_bits (cairo_mempool_t *pool, size_t start, int bits, cairo_bool_t clear) -{ - struct _cairo_memblock *block; - - if (clear) - clear_bits (pool, start, start + (1 << bits)); - - block = pool->blocks + start; - block->bits = bits; - - cairo_list_add (&block->link, &pool->free[bits]); - - pool->free_bytes += 1 << (bits + pool->min_bits); - if (bits > pool->max_free_bits) - pool->max_free_bits = bits; -} - -/* Add a chunk to the free list */ -static void -free_blocks (cairo_mempool_t *pool, - size_t first, - size_t last, - cairo_bool_t clear) -{ - size_t i, len; - int bits = 0; - - for (i = first, len = 1; i < last; i += len) { - /* To avoid cost quadratic in the number of different - * blocks produced from this chunk of store, we have to - * use the size of the previous block produced from this - * chunk as the starting point to work out the size of the - * next block we can produce. If you look at the binary - * representation of the starting points of the blocks - * produced, you can see that you first of all increase the - * size of the blocks produced up to some maximum as the - * address dealt with gets offsets added on which zap out - * low order bits, then decrease as the low order bits of the - * final block produced get added in. E.g. as you go from - * 001 to 0111 you generate blocks - * of size 001 at 001 taking you to 010 - * of size 010 at 010 taking you to 100 - * of size 010 at 100 taking you to 110 - * of size 001 at 110 taking you to 111 - * So the maximum total cost of the loops below this comment - * is one trip from the lowest blocksize to the highest and - * back again. - */ - while (bits < pool->num_sizes - 1) { - size_t next_bits = bits + 1; - size_t next_len = len << 1; - - if (i + next_bits > last) { - /* off end of chunk to be freed */ - break; - } - - if (i & (next_len - 1)) /* block would not be on boundary */ - break; - - bits = next_bits; - len = next_len; - } - - do { - if (i + len <= last && /* off end of chunk to be freed */ - (i & (len - 1)) == 0) /* block would not be on boundary */ - break; - - bits--; len >>=1; - } while (len); - - if (len == 0) - break; - - free_bits (pool, i, bits, clear); - } -} - -static struct _cairo_memblock * -get_buddy (cairo_mempool_t *pool, size_t offset, int bits) -{ - struct _cairo_memblock *block; - - if (offset + (1 << bits) >= pool->num_blocks) - return NULL; /* invalid */ - - if (BITTEST (pool, offset + (1 << bits) - 1)) - return NULL; /* buddy is allocated */ - - block = pool->blocks + offset; - if (block->bits != bits) - return NULL; /* buddy is partially allocated */ - - return block; -} - -static void -merge_buddies (cairo_mempool_t *pool, - struct _cairo_memblock *block, - int max_bits) -{ - size_t block_offset = block - pool->blocks; - int bits = block->bits; - - while (bits < max_bits - 1) { - /* while you can, merge two blocks and get a legal block size */ - size_t buddy_offset = block_offset ^ (1 << bits); - - block = get_buddy (pool, buddy_offset, bits); - if (block == NULL) - break; - - cairo_list_del (&block->link); - - /* Merged block starts at buddy */ - if (buddy_offset < block_offset) - block_offset = buddy_offset; - - bits++; - } - - block = pool->blocks + block_offset; - block->bits = bits; - cairo_list_add (&block->link, &pool->free[bits]); - - if (bits > pool->max_free_bits) - pool->max_free_bits = bits; -} - -/* attempt to merge all available buddies up to a particular size */ -static int -merge_bits (cairo_mempool_t *pool, int max_bits) -{ - struct _cairo_memblock *block, *buddy, *next; - int bits; - - for (bits = 0; bits < max_bits - 1; bits++) { - cairo_list_foreach_entry_safe (block, next, - struct _cairo_memblock, - &pool->free[bits], - link) - { - size_t buddy_offset = (block - pool->blocks) ^ (1 << bits); - - buddy = get_buddy (pool, buddy_offset, bits); - if (buddy == NULL) - continue; - - if (buddy == next) { - next = cairo_container_of (buddy->link.next, - struct _cairo_memblock, - link); - } - - cairo_list_del (&block->link); - merge_buddies (pool, block, max_bits); - } - } - - return pool->max_free_bits; -} - -/* find store for 1 << bits blocks */ -static void * -buddy_malloc (cairo_mempool_t *pool, int bits) -{ - size_t past, offset; - struct _cairo_memblock *block; - int b; - - if (bits > pool->max_free_bits && bits > merge_bits (pool, bits)) - return NULL; - - /* Find a list with blocks big enough on it */ - block = NULL; - for (b = bits; b <= pool->max_free_bits; b++) { - if (! cairo_list_is_empty (&pool->free[b])) { - block = cairo_list_first_entry (&pool->free[b], - struct _cairo_memblock, - link); - break; - } - } - assert (block != NULL); - - cairo_list_del (&block->link); - - while (cairo_list_is_empty (&pool->free[pool->max_free_bits])) { - if (--pool->max_free_bits == -1) - break; - } - - /* Mark end of allocated area */ - offset = block - pool->blocks; - past = offset + (1 << bits); - BITSET (pool, past - 1); - block->bits = bits; - - /* If we used a larger free block than we needed, free the rest */ - pool->free_bytes -= 1 << (b + pool->min_bits); - free_blocks (pool, past, offset + (1 << b), 0); - - return pool->base + ((block - pool->blocks) << pool->min_bits); -} - -cairo_status_t -_cairo_mempool_init (cairo_mempool_t *pool, - void *base, size_t bytes, - int min_bits, int num_sizes) -{ - unsigned long tmp; - int num_blocks; - int i; - - /* Align the start to an integral chunk */ - tmp = ((unsigned long) base) & ((1 << min_bits) - 1); - if (tmp) { - tmp = (1 << min_bits) - tmp; - base = (char *)base + tmp; - bytes -= tmp; - } - - assert ((((unsigned long) base) & ((1 << min_bits) - 1)) == 0); - assert (num_sizes < ARRAY_LENGTH (pool->free)); - - pool->base = base; - pool->free_bytes = 0; - pool->max_bytes = bytes; - pool->max_free_bits = -1; - - num_blocks = bytes >> min_bits; - pool->blocks = calloc (num_blocks, sizeof (struct _cairo_memblock)); - if (pool->blocks == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - pool->num_blocks = num_blocks; - pool->min_bits = min_bits; - pool->num_sizes = num_sizes; - - for (i = 0; i < ARRAY_LENGTH (pool->free); i++) - cairo_list_init (&pool->free[i]); - - pool->map = malloc ((num_blocks + 7) >> 3); - if (pool->map == NULL) { - free (pool->blocks); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - memset (pool->map, -1, (num_blocks + 7) >> 3); - clear_bits (pool, 0, num_blocks); - - /* Now add all blocks to the free list */ - free_blocks (pool, 0, num_blocks, 1); - - return CAIRO_STATUS_SUCCESS; -} - -void * -_cairo_mempool_alloc (cairo_mempool_t *pool, size_t bytes) -{ - size_t size; - int bits; - - size = 1 << pool->min_bits; - for (bits = 0; size < bytes; bits++) - size <<= 1; - if (bits >= pool->num_sizes) - return NULL; - - return buddy_malloc (pool, bits); -} - -void -_cairo_mempool_free (cairo_mempool_t *pool, void *storage) -{ - size_t block_offset; - struct _cairo_memblock *block; - - block_offset = ((char *)storage - pool->base) >> pool->min_bits; - block = pool->blocks + block_offset; - - BITCLEAR (pool, block_offset + ((1 << block->bits) - 1)); - pool->free_bytes += 1 << (block->bits + pool->min_bits); - - merge_buddies (pool, block, pool->num_sizes); -} - -void -_cairo_mempool_fini (cairo_mempool_t *pool) -{ - free (pool->map); - free (pool->blocks); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mesh-pattern-rasterizer.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mesh-pattern-rasterizer.c deleted file mode 100644 index 1b63ca8a660..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mesh-pattern-rasterizer.c +++ /dev/null @@ -1,941 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright 2009 Andrea Canciani - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Andrea Canciani. - * - * Contributor(s): - * Andrea Canciani - */ - -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-pattern-private.h" - -/* - * Rasterizer for mesh patterns. - * - * This implementation is based on techniques derived from several - * papers (available from ACM): - * - * - Lien, Shantz and Pratt "Adaptive Forward Differencing for - * Rendering Curves and Surfaces" (discussion of the AFD technique, - * bound of 1/sqrt(2) on step length without proof) - * - * - Popescu and Rosen, "Forward rasterization" (description of - * forward rasterization, proof of the previous bound) - * - * - Klassen, "Integer Forward Differencing of Cubic Polynomials: - * Analysis and Algorithms" - * - * - Klassen, "Exact Integer Hybrid Subdivision and Forward - * Differencing of Cubics" (improving the bound on the minimum - * number of steps) - * - * - Chang, Shantz and Rocchetti, "Rendering Cubic Curves and Surfaces - * with Integer Adaptive Forward Differencing" (analysis of forward - * differencing applied to Bezier patches) - * - * Notes: - * - Poor performance expected in degenerate cases - * - * - Patches mostly outside the drawing area are drawn completely (and - * clipped), wasting time - * - * - Both previous problems are greatly reduced by splitting until a - * reasonably small size and clipping the new tiles: execution time - * is quadratic in the convex-hull diameter instead than linear to - * the painted area. Splitting the tiles doesn't change the painted - * area but (usually) reduces the bounding box area (bbox area can - * remain the same after splitting, but cannot grow) - * - * - The initial implementation used adaptive forward differencing, - * but simple forward differencing scored better in benchmarks - * - * Idea: - * - * We do a sampling over the cubic patch with step du and dv (in the - * two parameters) that guarantees that any point of our sampling will - * be at most at 1/sqrt(2) from its adjacent points. In formulae - * (assuming B is the patch): - * - * |B(u,v) - B(u+du,v)| < 1/sqrt(2) - * |B(u,v) - B(u,v+dv)| < 1/sqrt(2) - * - * This means that every pixel covered by the patch will contain at - * least one of the samples, thus forward rasterization can be - * performed. Sketch of proof (from Popescu and Rosen): - * - * Let's take the P pixel we're interested into. If we assume it to be - * square, its boundaries define 9 regions on the plane: - * - * 1|2|3 - * -+-+- - * 8|P|4 - * -+-+- - * 7|6|5 - * - * Let's check that the pixel P will contain at least one point - * assuming that it is covered by the patch. - * - * Since the pixel is covered by the patch, its center will belong to - * (at least) one of the quads: - * - * {(B(u,v), B(u+du,v), B(u,v+dv), B(u+du,v+dv)) for u,v in [0,1]} - * - * If P doesn't contain any of the corners of the quad: - * - * - if one of the corners is in 1,3,5 or 7, other two of them have to - * be in 2,4,6 or 8, thus if the last corner is not in P, the length - * of one of the edges will be > 1/sqrt(2) - * - * - if none of the corners is in 1,3,5 or 7, all of them are in 2,4,6 - * and/or 8. If they are all in different regions, they can't - * satisfy the distance constraint. If two of them are in the same - * region (let's say 2), no point is in 6 and again it is impossible - * to have the center of P in the quad respecting the distance - * constraint (both these assertions can be checked by continuity - * considering the length of the edges of a quad with the vertices - * on the edges of P) - * - * Each of the cases led to a contradiction, so P contains at least - * one of the corners of the quad. - */ - -/* - * Make sure that errors are less than 1 in fixed point math if you - * change these values. - * - * The error is amplified by about steps^3/4 times. - * The rasterizer always uses a number of steps that is a power of 2. - * - * 256 is the maximum allowed number of steps (to have error < 1) - * using 8.24 for the differences. - */ -#define STEPS_MAX_V 256.0 -#define STEPS_MAX_U 256.0 - -/* - * If the patch/curve is only partially visible, split it to a finer - * resolution to get higher chances to clip (part of) it. - * - * These values have not been computed, but simply obtained - * empirically (by benchmarking some patches). They should never be - * greater than STEPS_MAX_V (or STEPS_MAX_U), but they can be as small - * as 1 (depending on how much you want to spend time in splitting the - * patch/curve when trying to save some rasterization time). - */ -#define STEPS_CLIP_V 64.0 -#define STEPS_CLIP_U 64.0 - - -/* Utils */ -static inline double -sqlen (cairo_point_double_t p0, cairo_point_double_t p1) -{ - cairo_point_double_t delta; - - delta.x = p0.x - p1.x; - delta.y = p0.y - p1.y; - - return delta.x * delta.x + delta.y * delta.y; -} - -static inline int16_t -_color_delta_to_shifted_short (int32_t from, int32_t to, int shift) -{ - int32_t delta = to - from; - - /* We need to round toward zero, because otherwise adding the - * delta 2^shift times can overflow */ - if (delta >= 0) - return delta >> shift; - else - return -((-delta) >> shift); -} - -/* - * Convert a number of steps to the equivalent shift. - * - * Input: the square of the minimum number of steps - * - * Output: the smallest integer x such that 2^x > steps - */ -static inline int -sqsteps2shift (double steps_sq) -{ - int r; - frexp (MAX (1.0, steps_sq), &r); - return (r + 1) >> 1; -} - -/* - * FD functions - * - * A Bezier curve is defined (with respect to a parameter t in - * [0,1]) from its nodes (x,y,z,w) like this: - * - * B(t) = x(1-t)^3 + 3yt(1-t)^2 + 3zt^2(1-t) + wt^3 - * - * To efficiently evaluate a Bezier curve, the rasterizer uses forward - * differences. Given x, y, z, w (the 4 nodes of the Bezier curve), it - * is possible to convert them to forward differences form and walk - * over the curve using fd_init (), fd_down () and fd_fwd (). - * - * f[0] is always the value of the Bezier curve for "current" t. - */ - -/* - * Initialize the coefficient for forward differences. - * - * Input: x,y,z,w are the 4 nodes of the Bezier curve - * - * Output: f[i] is the i-th difference of the curve - * - * f[0] is the value of the curve for t==0, i.e. f[0]==x. - * - * The initial step is 1; this means that each step increases t by 1 - * (so fd_init () immediately followed by fd_fwd (f) n times makes - * f[0] be the value of the curve for t==n). - */ -static inline void -fd_init (double x, double y, double z, double w, double f[4]) -{ - f[0] = x; - f[1] = w - x; - f[2] = 6. * (w - 2. * z + y); - f[3] = 6. * (w - 3. * z + 3. * y - x); -} - -/* - * Halve the step of the coefficients for forward differences. - * - * Input: f[i] is the i-th difference of the curve - * - * Output: f[i] is the i-th difference of the curve with half the - * original step - * - * f[0] is not affected, so the current t is not changed. - * - * The other coefficients are changed so that the step is half the - * original step. This means that doing fd_fwd (f) n times with the - * input f results in the same f[0] as doing fd_fwd (f) 2n times with - * the output f. - */ -static inline void -fd_down (double f[4]) -{ - f[3] *= 0.125; - f[2] = f[2] * 0.25 - f[3]; - f[1] = (f[1] - f[2]) * 0.5; -} - -/* - * Perform one step of forward differences along the curve. - * - * Input: f[i] is the i-th difference of the curve - * - * Output: f[i] is the i-th difference of the curve after one step - */ -static inline void -fd_fwd (double f[4]) -{ - f[0] += f[1]; - f[1] += f[2]; - f[2] += f[3]; -} - -/* - * Transform to integer forward differences. - * - * Input: d[n] is the n-th difference (in double precision) - * - * Output: i[n] is the n-th difference (in fixed point precision) - * - * i[0] is 9.23 fixed point, other differences are 4.28 fixed point. - */ -static inline void -fd_fixed (double d[4], int32_t i[4]) -{ - i[0] = _cairo_fixed_16_16_from_double (256 * 2 * d[0]); - i[1] = _cairo_fixed_16_16_from_double (256 * 16 * d[1]); - i[2] = _cairo_fixed_16_16_from_double (256 * 16 * d[2]); - i[3] = _cairo_fixed_16_16_from_double (256 * 16 * d[3]); -} - -/* - * Perform one step of integer forward differences along the curve. - * - * Input: f[n] is the n-th difference - * - * Output: f[n] is the n-th difference - * - * f[0] is 9.23 fixed point, other differences are 4.28 fixed point. - */ -static inline void -fd_fixed_fwd (int32_t f[4]) -{ - f[0] += (f[1] >> 5) + ((f[1] >> 4) & 1); - f[1] += f[2]; - f[2] += f[3]; -} - -/* - * Compute the minimum number of steps that guarantee that walking - * over a curve will leave no holes. - * - * Input: p[0..3] the nodes of the Bezier curve - * - * Returns: the square of the number of steps - * - * Idea: - * - * We want to make sure that at every step we move by less than - * 1/sqrt(2). - * - * The derivative of the cubic Bezier with nodes (p0, p1, p2, p3) is - * the quadratic Bezier with nodes (p1-p0, p2-p1, p3-p2) scaled by 3, - * so (since a Bezier curve is always bounded by its convex hull), we - * can say that: - * - * max(|B'(t)|) <= 3 max (|p1-p0|, |p2-p1|, |p3-p2|) - * - * We can improve this by noticing that a quadratic Bezier (a,b,c) is - * bounded by the quad (a,lerp(a,b,t),lerp(b,c,t),c) for any t, so - * (substituting the previous values, using t=0.5 and simplifying): - * - * max(|B'(t)|) <= 3 max (|p1-p0|, |p2-p0|/2, |p3-p1|/2, |p3-p2|) - * - * So, to guarantee a maximum step length of 1/sqrt(2) we must do: - * - * 3 max (|p1-p0|, |p2-p0|/2, |p3-p1|/2, |p3-p2|) sqrt(2) steps - */ -static inline double -bezier_steps_sq (cairo_point_double_t p[4]) -{ - double tmp = sqlen (p[0], p[1]); - tmp = MAX (tmp, sqlen (p[2], p[3])); - tmp = MAX (tmp, sqlen (p[0], p[2]) * .25); - tmp = MAX (tmp, sqlen (p[1], p[3]) * .25); - return 18.0 * tmp; -} - -/* - * Split a 1D Bezier cubic using de Casteljau's algorithm. - * - * Input: x,y,z,w the nodes of the Bezier curve - * - * Output: x0,y0,z0,w0 and x1,y1,z1,w1 are respectively the nodes of - * the first half and of the second half of the curve - * - * The output control nodes have to be distinct. - */ -static inline void -split_bezier_1D (double x, double y, double z, double w, - double *x0, double *y0, double *z0, double *w0, - double *x1, double *y1, double *z1, double *w1) -{ - double tmp; - - *x0 = x; - *w1 = w; - - tmp = 0.5 * (y + z); - *y0 = 0.5 * (x + y); - *z1 = 0.5 * (z + w); - - *z0 = 0.5 * (*y0 + tmp); - *y1 = 0.5 * (tmp + *z1); - - *w0 = *x1 = 0.5 * (*z0 + *y1); -} - -/* - * Split a Bezier curve using de Casteljau's algorithm. - * - * Input: p[0..3] the nodes of the Bezier curve - * - * Output: fst_half[0..3] and snd_half[0..3] are respectively the - * nodes of the first and of the second half of the curve - * - * fst_half and snd_half must be different, but they can be the same as - * nodes. - */ -static void -split_bezier (cairo_point_double_t p[4], - cairo_point_double_t fst_half[4], - cairo_point_double_t snd_half[4]) -{ - split_bezier_1D (p[0].x, p[1].x, p[2].x, p[3].x, - &fst_half[0].x, &fst_half[1].x, &fst_half[2].x, &fst_half[3].x, - &snd_half[0].x, &snd_half[1].x, &snd_half[2].x, &snd_half[3].x); - - split_bezier_1D (p[0].y, p[1].y, p[2].y, p[3].y, - &fst_half[0].y, &fst_half[1].y, &fst_half[2].y, &fst_half[3].y, - &snd_half[0].y, &snd_half[1].y, &snd_half[2].y, &snd_half[3].y); -} - - -typedef enum _intersection { - INSIDE = -1, /* the interval is entirely contained in the reference interval */ - OUTSIDE = 0, /* the interval has no intersection with the reference interval */ - PARTIAL = 1 /* the interval intersects the reference interval (but is not fully inside it) */ -} intersection_t; - -/* - * Check if an interval if inside another. - * - * Input: a,b are the extrema of the first interval - * c,d are the extrema of the second interval - * - * Returns: INSIDE iff [a,b) intersection [c,d) = [a,b) - * OUTSIDE iff [a,b) intersection [c,d) = {} - * PARTIAL otherwise - * - * The function assumes a < b and c < d - * - * Note: Bitwise-anding the results along each component gives the - * expected result for [a,b) x [A,B) intersection [c,d) x [C,D). - */ -static inline int -intersect_interval (double a, double b, double c, double d) -{ - if (c <= a && b <= d) - return INSIDE; - else if (a >= d || b <= c) - return OUTSIDE; - else - return PARTIAL; -} - -/* - * Set the color of a pixel. - * - * Input: data is the base pointer of the image - * width, height are the dimensions of the image - * stride is the stride in bytes between adjacent rows - * x, y are the coordinates of the pixel to be colored - * r,g,b,a are the color components of the color to be set - * - * Output: the (x,y) pixel in data has the (r,g,b,a) color - * - * The input color components are not premultiplied, but the data - * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, - * premultiplied). - * - * If the pixel to be set is outside the image, this function does - * nothing. - */ -static inline void -draw_pixel (unsigned char *data, int width, int height, int stride, - int x, int y, uint16_t r, uint16_t g, uint16_t b, uint16_t a) -{ - if (likely (0 <= x && 0 <= y && x < width && y < height)) { - uint32_t tr, tg, tb, ta; - - /* Premultiply and round */ - ta = a; - tr = r * ta + 0x8000; - tg = g * ta + 0x8000; - tb = b * ta + 0x8000; - - tr += tr >> 16; - tg += tg >> 16; - tb += tb >> 16; - - *((uint32_t*) (data + y*stride + 4*x)) = ((ta << 16) & 0xff000000) | - ((tr >> 8) & 0xff0000) | ((tg >> 16) & 0xff00) | (tb >> 24); - } -} - -/* - * Forward-rasterize a cubic curve using forward differences. - * - * Input: data is the base pointer of the image - * width, height are the dimensions of the image - * stride is the stride in bytes between adjacent rows - * ushift is log2(n) if n is the number of desired steps - * dxu[i], dyu[i] are the x,y forward differences of the curve - * r0,g0,b0,a0 are the color components of the start point - * r3,g3,b3,a3 are the color components of the end point - * - * Output: data will be changed to have the requested curve drawn in - * the specified colors - * - * The input color components are not premultiplied, but the data - * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, - * premultiplied). - * - * The function draws n+1 pixels, that is from the point at step 0 to - * the point at step n, both included. This is the discrete equivalent - * to drawing the curve for values of the interpolation parameter in - * [0,1] (including both extremes). - */ -static inline void -rasterize_bezier_curve (unsigned char *data, int width, int height, int stride, - int ushift, double dxu[4], double dyu[4], - uint16_t r0, uint16_t g0, uint16_t b0, uint16_t a0, - uint16_t r3, uint16_t g3, uint16_t b3, uint16_t a3) -{ - int32_t xu[4], yu[4]; - int x0, y0, u, usteps = 1 << ushift; - - uint16_t r = r0, g = g0, b = b0, a = a0; - int16_t dr = _color_delta_to_shifted_short (r0, r3, ushift); - int16_t dg = _color_delta_to_shifted_short (g0, g3, ushift); - int16_t db = _color_delta_to_shifted_short (b0, b3, ushift); - int16_t da = _color_delta_to_shifted_short (a0, a3, ushift); - - fd_fixed (dxu, xu); - fd_fixed (dyu, yu); - - /* - * Use (dxu[0],dyu[0]) as origin for the forward differences. - * - * This makes it possible to handle much larger coordinates (the - * ones that can be represented as cairo_fixed_t) - */ - x0 = _cairo_fixed_from_double (dxu[0]); - y0 = _cairo_fixed_from_double (dyu[0]); - xu[0] = 0; - yu[0] = 0; - - for (u = 0; u <= usteps; ++u) { - /* - * This rasterizer assumes that pixels are integer aligned - * squares, so a generic (x,y) point belongs to the pixel with - * top-left coordinates (floor(x), floor(y)) - */ - - int x = _cairo_fixed_integer_floor (x0 + (xu[0] >> 15) + ((xu[0] >> 14) & 1)); - int y = _cairo_fixed_integer_floor (y0 + (yu[0] >> 15) + ((yu[0] >> 14) & 1)); - - draw_pixel (data, width, height, stride, x, y, r, g, b, a); - - fd_fixed_fwd (xu); - fd_fixed_fwd (yu); - r += dr; - g += dg; - b += db; - a += da; - } -} - -/* - * Clip, split and rasterize a Bezier curve. - * - * Input: data is the base pointer of the image - * width, height are the dimensions of the image - * stride is the stride in bytes between adjacent rows - * p[i] is the i-th node of the Bezier curve - * c0[i] is the i-th color component at the start point - * c3[i] is the i-th color component at the end point - * - * Output: data will be changed to have the requested curve drawn in - * the specified colors - * - * The input color components are not premultiplied, but the data - * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, - * premultiplied). - * - * The color components are red, green, blue and alpha, in this order. - * - * The function guarantees that it will draw the curve with a step - * small enough to never have a distance above 1/sqrt(2) between two - * consecutive points (which is needed to ensure that no hole can - * appear when using this function to rasterize a patch). - */ -static void -draw_bezier_curve (unsigned char *data, int width, int height, int stride, - cairo_point_double_t p[4], double c0[4], double c3[4]) -{ - double top, bottom, left, right, steps_sq; - int i, v; - - top = bottom = p[0].y; - for (i = 1; i < 4; ++i) { - top = MIN (top, p[i].y); - bottom = MAX (bottom, p[i].y); - } - - /* Check visibility */ - v = intersect_interval (top, bottom, 0, height); - if (v == OUTSIDE) - return; - - left = right = p[0].x; - for (i = 1; i < 4; ++i) { - left = MIN (left, p[i].x); - right = MAX (right, p[i].x); - } - - v &= intersect_interval (left, right, 0, width); - if (v == OUTSIDE) - return; - - steps_sq = bezier_steps_sq (p); - if (steps_sq >= (v == INSIDE ? STEPS_MAX_U * STEPS_MAX_U : STEPS_CLIP_U * STEPS_CLIP_U)) { - /* - * The number of steps is greater than the threshold. This - * means that either the error would become too big if we - * directly rasterized it or that we can probably save some - * time by splitting the curve and clipping part of it - */ - cairo_point_double_t first[4], second[4]; - double midc[4]; - split_bezier (p, first, second); - midc[0] = (c0[0] + c3[0]) * 0.5; - midc[1] = (c0[1] + c3[1]) * 0.5; - midc[2] = (c0[2] + c3[2]) * 0.5; - midc[3] = (c0[3] + c3[3]) * 0.5; - draw_bezier_curve (data, width, height, stride, first, c0, midc); - draw_bezier_curve (data, width, height, stride, second, midc, c3); - } else { - double xu[4], yu[4]; - int ushift = sqsteps2shift (steps_sq), k; - - fd_init (p[0].x, p[1].x, p[2].x, p[3].x, xu); - fd_init (p[0].y, p[1].y, p[2].y, p[3].y, yu); - - for (k = 0; k < ushift; ++k) { - fd_down (xu); - fd_down (yu); - } - - rasterize_bezier_curve (data, width, height, stride, ushift, - xu, yu, - _cairo_color_double_to_short (c0[0]), - _cairo_color_double_to_short (c0[1]), - _cairo_color_double_to_short (c0[2]), - _cairo_color_double_to_short (c0[3]), - _cairo_color_double_to_short (c3[0]), - _cairo_color_double_to_short (c3[1]), - _cairo_color_double_to_short (c3[2]), - _cairo_color_double_to_short (c3[3])); - - /* Draw the end point, to make sure that we didn't leave it - * out because of rounding */ - draw_pixel (data, width, height, stride, - _cairo_fixed_integer_floor (_cairo_fixed_from_double (p[3].x)), - _cairo_fixed_integer_floor (_cairo_fixed_from_double (p[3].y)), - _cairo_color_double_to_short (c3[0]), - _cairo_color_double_to_short (c3[1]), - _cairo_color_double_to_short (c3[2]), - _cairo_color_double_to_short (c3[3])); - } -} - -/* - * Forward-rasterize a cubic Bezier patch using forward differences. - * - * Input: data is the base pointer of the image - * width, height are the dimensions of the image - * stride is the stride in bytes between adjacent rows - * vshift is log2(n) if n is the number of desired steps - * p[i][j], p[i][j] are the the nodes of the Bezier patch - * col[i][j] is the j-th color component of the i-th corner - * - * Output: data will be changed to have the requested patch drawn in - * the specified colors - * - * The nodes of the patch are as follows: - * - * u\v 0 - > 1 - * 0 p00 p01 p02 p03 - * | p10 p11 p12 p13 - * v p20 p21 p22 p23 - * 1 p30 p31 p32 p33 - * - * i.e. u varies along the first component (rows), v varies along the - * second one (columns). - * - * The color components are red, green, blue and alpha, in this order. - * c[0..3] are the colors in p00, p30, p03, p33 respectively - * - * The input color components are not premultiplied, but the data - * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, - * premultiplied). - * - * If the patch folds over itself, the part with the highest v - * parameter is considered above. If both have the same v, the one - * with the highest u parameter is above. - * - * The function draws n+1 curves, that is from the curve at step 0 to - * the curve at step n, both included. This is the discrete equivalent - * to drawing the patch for values of the interpolation parameter in - * [0,1] (including both extremes). - */ -static inline void -rasterize_bezier_patch (unsigned char *data, int width, int height, int stride, int vshift, - cairo_point_double_t p[4][4], double col[4][4]) -{ - double pv[4][2][4], cstart[4], cend[4], dcstart[4], dcend[4]; - int v, i, k; - - v = 1 << vshift; - - /* - * pv[i][0] is the function (represented using forward - * differences) mapping v to the x coordinate of the i-th node of - * the Bezier curve with parameter u. - * (Likewise p[i][0] gives the y coordinate). - * - * This means that (pv[0][0][0],pv[0][1][0]), - * (pv[1][0][0],pv[1][1][0]), (pv[2][0][0],pv[2][1][0]) and - * (pv[3][0][0],pv[3][1][0]) are the nodes of the Bezier curve for - * the "current" v value (see the FD comments for more details). - */ - for (i = 0; i < 4; ++i) { - fd_init (p[i][0].x, p[i][1].x, p[i][2].x, p[i][3].x, pv[i][0]); - fd_init (p[i][0].y, p[i][1].y, p[i][2].y, p[i][3].y, pv[i][1]); - for (k = 0; k < vshift; ++k) { - fd_down (pv[i][0]); - fd_down (pv[i][1]); - } - } - - for (i = 0; i < 4; ++i) { - cstart[i] = col[0][i]; - cend[i] = col[1][i]; - dcstart[i] = (col[2][i] - col[0][i]) / v; - dcend[i] = (col[3][i] - col[1][i]) / v; - } - - v++; - while (v--) { - cairo_point_double_t nodes[4]; - for (i = 0; i < 4; ++i) { - nodes[i].x = pv[i][0][0]; - nodes[i].y = pv[i][1][0]; - } - - draw_bezier_curve (data, width, height, stride, nodes, cstart, cend); - - for (i = 0; i < 4; ++i) { - fd_fwd (pv[i][0]); - fd_fwd (pv[i][1]); - cstart[i] += dcstart[i]; - cend[i] += dcend[i]; - } - } -} - -/* - * Clip, split and rasterize a Bezier cubic patch. - * - * Input: data is the base pointer of the image - * width, height are the dimensions of the image - * stride is the stride in bytes between adjacent rows - * p[i][j], p[i][j] are the nodes of the patch - * col[i][j] is the j-th color component of the i-th corner - * - * Output: data will be changed to have the requested patch drawn in - * the specified colors - * - * The nodes of the patch are as follows: - * - * u\v 0 - > 1 - * 0 p00 p01 p02 p03 - * | p10 p11 p12 p13 - * v p20 p21 p22 p23 - * 1 p30 p31 p32 p33 - * - * i.e. u varies along the first component (rows), v varies along the - * second one (columns). - * - * The color components are red, green, blue and alpha, in this order. - * c[0..3] are the colors in p00, p30, p03, p33 respectively - * - * The input color components are not premultiplied, but the data - * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, - * premultiplied). - * - * If the patch folds over itself, the part with the highest v - * parameter is considered above. If both have the same v, the one - * with the highest u parameter is above. - * - * The function guarantees that it will draw the patch with a step - * small enough to never have a distance above 1/sqrt(2) between two - * adjacent points (which guarantees that no hole can appear). - * - * This function can be used to rasterize a tile of PDF type 7 - * shadings (see http://www.adobe.com/devnet/pdf/pdf_reference.html). - */ -static void -draw_bezier_patch (unsigned char *data, int width, int height, int stride, - cairo_point_double_t p[4][4], double c[4][4]) -{ - double top, bottom, left, right, steps_sq; - int i, j, v; - - top = bottom = p[0][0].y; - for (i = 0; i < 4; ++i) { - for (j= 0; j < 4; ++j) { - top = MIN (top, p[i][j].y); - bottom = MAX (bottom, p[i][j].y); - } - } - - v = intersect_interval (top, bottom, 0, height); - if (v == OUTSIDE) - return; - - left = right = p[0][0].x; - for (i = 0; i < 4; ++i) { - for (j= 0; j < 4; ++j) { - left = MIN (left, p[i][j].x); - right = MAX (right, p[i][j].x); - } - } - - v &= intersect_interval (left, right, 0, width); - if (v == OUTSIDE) - return; - - steps_sq = 0; - for (i = 0; i < 4; ++i) - steps_sq = MAX (steps_sq, bezier_steps_sq (p[i])); - - if (steps_sq >= (v == INSIDE ? STEPS_MAX_V * STEPS_MAX_V : STEPS_CLIP_V * STEPS_CLIP_V)) { - /* The number of steps is greater than the threshold. This - * means that either the error would become too big if we - * directly rasterized it or that we can probably save some - * time by splitting the curve and clipping part of it. The - * patch is only split in the v direction to guarantee that - * rasterizing each part will overwrite parts with low v with - * overlapping parts with higher v. */ - - cairo_point_double_t first[4][4], second[4][4]; - double subc[4][4]; - - for (i = 0; i < 4; ++i) - split_bezier (p[i], first[i], second[i]); - - for (i = 0; i < 4; ++i) { - subc[0][i] = c[0][i]; - subc[1][i] = c[1][i]; - subc[2][i] = 0.5 * (c[0][i] + c[2][i]); - subc[3][i] = 0.5 * (c[1][i] + c[3][i]); - } - - draw_bezier_patch (data, width, height, stride, first, subc); - - for (i = 0; i < 4; ++i) { - subc[0][i] = subc[2][i]; - subc[1][i] = subc[3][i]; - subc[2][i] = c[2][i]; - subc[3][i] = c[3][i]; - } - draw_bezier_patch (data, width, height, stride, second, subc); - } else { - rasterize_bezier_patch (data, width, height, stride, sqsteps2shift (steps_sq), p, c); - } -} - -/* - * Draw a tensor product shading pattern. - * - * Input: mesh is the mesh pattern - * data is the base pointer of the image - * width, height are the dimensions of the image - * stride is the stride in bytes between adjacent rows - * - * Output: data will be changed to have the pattern drawn on it - * - * data is assumed to be clear and its content is assumed to be in - * CAIRO_FORMAT_ARGB32 (8 bpc, premultiplied). - * - * This function can be used to rasterize a PDF type 7 shading (see - * http://www.adobe.com/devnet/pdf/pdf_reference.html). - */ -void -_cairo_mesh_pattern_rasterize (const cairo_mesh_pattern_t *mesh, - void *data, - int width, - int height, - int stride, - double x_offset, - double y_offset) -{ - cairo_point_double_t nodes[4][4]; - double colors[4][4]; - cairo_matrix_t p2u; - unsigned int i, j, k, n; - cairo_status_t status; - const cairo_mesh_patch_t *patch; - const cairo_color_t *c; - - assert (mesh->base.status == CAIRO_STATUS_SUCCESS); - assert (mesh->current_patch == NULL); - - p2u = mesh->base.matrix; - status = cairo_matrix_invert (&p2u); - assert (status == CAIRO_STATUS_SUCCESS); - - n = _cairo_array_num_elements (&mesh->patches); - patch = _cairo_array_index_const (&mesh->patches, 0); - for (i = 0; i < n; i++) { - for (j = 0; j < 4; j++) { - for (k = 0; k < 4; k++) { - nodes[j][k] = patch->points[j][k]; - cairo_matrix_transform_point (&p2u, &nodes[j][k].x, &nodes[j][k].y); - nodes[j][k].x += x_offset; - nodes[j][k].y += y_offset; - } - } - - c = &patch->colors[0]; - colors[0][0] = c->red; - colors[0][1] = c->green; - colors[0][2] = c->blue; - colors[0][3] = c->alpha; - - c = &patch->colors[3]; - colors[1][0] = c->red; - colors[1][1] = c->green; - colors[1][2] = c->blue; - colors[1][3] = c->alpha; - - c = &patch->colors[1]; - colors[2][0] = c->red; - colors[2][1] = c->green; - colors[2][2] = c->blue; - colors[2][3] = c->alpha; - - c = &patch->colors[2]; - colors[3][0] = c->red; - colors[3][1] = c->green; - colors[3][2] = c->blue; - colors[3][3] = c->alpha; - - draw_bezier_patch (data, width, height, stride, nodes, colors); - patch++; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-misc.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-misc.c deleted file mode 100644 index df8a4efc940..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-misc.c +++ /dev/null @@ -1,955 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2007 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Adrian Johnson - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -COMPILE_TIME_ASSERT ((int)CAIRO_STATUS_LAST_STATUS < (int)CAIRO_INT_STATUS_UNSUPPORTED); -COMPILE_TIME_ASSERT (CAIRO_INT_STATUS_LAST_STATUS <= 127); - -/** - * SECTION:cairo-status - * @Title: Error handling - * @Short_Description: Decoding cairo's status - * @See_Also: cairo_status(), cairo_surface_status(), cairo_pattern_status(), - * cairo_font_face_status(), cairo_scaled_font_status(), - * cairo_region_status() - * - * Cairo uses a single status type to represent all kinds of errors. A status - * value of %CAIRO_STATUS_SUCCESS represents no error and has an integer value - * of zero. All other status values represent an error. - * - * Cairo's error handling is designed to be easy to use and safe. All major - * cairo objects retain an error status internally which - * can be queried anytime by the users using cairo*_status() calls. In - * the mean time, it is safe to call all cairo functions normally even if the - * underlying object is in an error status. This means that no error handling - * code is required before or after each individual cairo function call. - **/ - -/* Public stuff */ - -/** - * cairo_status_to_string: - * @status: a cairo status - * - * Provides a human-readable description of a #cairo_status_t. - * - * Returns: a string representation of the status - * - * Since: 1.0 - **/ -const char * -cairo_status_to_string (cairo_status_t status) -{ - switch (status) { - case CAIRO_STATUS_SUCCESS: - return "no error has occurred"; - case CAIRO_STATUS_NO_MEMORY: - return "out of memory"; - case CAIRO_STATUS_INVALID_RESTORE: - return "cairo_restore() without matching cairo_save()"; - case CAIRO_STATUS_INVALID_POP_GROUP: - return "no saved group to pop, i.e. cairo_pop_group() without matching cairo_push_group()"; - case CAIRO_STATUS_NO_CURRENT_POINT: - return "no current point defined"; - case CAIRO_STATUS_INVALID_MATRIX: - return "invalid matrix (not invertible)"; - case CAIRO_STATUS_INVALID_STATUS: - return "invalid value for an input cairo_status_t"; - case CAIRO_STATUS_NULL_POINTER: - return "NULL pointer"; - case CAIRO_STATUS_INVALID_STRING: - return "input string not valid UTF-8"; - case CAIRO_STATUS_INVALID_PATH_DATA: - return "input path data not valid"; - case CAIRO_STATUS_READ_ERROR: - return "error while reading from input stream"; - case CAIRO_STATUS_WRITE_ERROR: - return "error while writing to output stream"; - case CAIRO_STATUS_SURFACE_FINISHED: - return "the target surface has been finished"; - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - return "the surface type is not appropriate for the operation"; - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: - return "the pattern type is not appropriate for the operation"; - case CAIRO_STATUS_INVALID_CONTENT: - return "invalid value for an input cairo_content_t"; - case CAIRO_STATUS_INVALID_FORMAT: - return "invalid value for an input cairo_format_t"; - case CAIRO_STATUS_INVALID_VISUAL: - return "invalid value for an input Visual*"; - case CAIRO_STATUS_FILE_NOT_FOUND: - return "file not found"; - case CAIRO_STATUS_INVALID_DASH: - return "invalid value for a dash setting"; - case CAIRO_STATUS_INVALID_DSC_COMMENT: - return "invalid value for a DSC comment"; - case CAIRO_STATUS_INVALID_INDEX: - return "invalid index passed to getter"; - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: - return "clip region not representable in desired format"; - case CAIRO_STATUS_TEMP_FILE_ERROR: - return "error creating or writing to a temporary file"; - case CAIRO_STATUS_INVALID_STRIDE: - return "invalid value for stride"; - case CAIRO_STATUS_FONT_TYPE_MISMATCH: - return "the font type is not appropriate for the operation"; - case CAIRO_STATUS_USER_FONT_IMMUTABLE: - return "the user-font is immutable"; - case CAIRO_STATUS_USER_FONT_ERROR: - return "error occurred in a user-font callback function"; - case CAIRO_STATUS_NEGATIVE_COUNT: - return "negative number used where it is not allowed"; - case CAIRO_STATUS_INVALID_CLUSTERS: - return "input clusters do not represent the accompanying text and glyph arrays"; - case CAIRO_STATUS_INVALID_SLANT: - return "invalid value for an input cairo_font_slant_t"; - case CAIRO_STATUS_INVALID_WEIGHT: - return "invalid value for an input cairo_font_weight_t"; - case CAIRO_STATUS_INVALID_SIZE: - return "invalid value (typically too big) for the size of the input (surface, pattern, etc.)"; - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: - return "user-font method not implemented"; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - return "the device type is not appropriate for the operation"; - case CAIRO_STATUS_DEVICE_ERROR: - return "an operation to the device caused an unspecified error"; - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: - return "invalid operation during mesh pattern construction"; - case CAIRO_STATUS_DEVICE_FINISHED: - return "the target device has been finished"; - case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: - return "CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID used but no CAIRO_MIME_TYPE_JBIG2_GLOBAL data provided"; - default: - case CAIRO_STATUS_LAST_STATUS: - return ""; - } -} - - -/** - * cairo_glyph_allocate: - * @num_glyphs: number of glyphs to allocate - * - * Allocates an array of #cairo_glyph_t's. - * This function is only useful in implementations of - * #cairo_user_scaled_font_text_to_glyphs_func_t where the user - * needs to allocate an array of glyphs that cairo will free. - * For all other uses, user can use their own allocation method - * for glyphs. - * - * This function returns %NULL if @num_glyphs is not positive, - * or if out of memory. That means, the %NULL return value - * signals out-of-memory only if @num_glyphs was positive. - * - * Returns: the newly allocated array of glyphs that should be - * freed using cairo_glyph_free() - * - * Since: 1.8 - **/ -cairo_glyph_t * -cairo_glyph_allocate (int num_glyphs) -{ - if (num_glyphs <= 0) - return NULL; - - return _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); -} -slim_hidden_def (cairo_glyph_allocate); - -/** - * cairo_glyph_free: - * @glyphs: array of glyphs to free, or %NULL - * - * Frees an array of #cairo_glyph_t's allocated using cairo_glyph_allocate(). - * This function is only useful to free glyph array returned - * by cairo_scaled_font_text_to_glyphs() where cairo returns - * an array of glyphs that the user will free. - * For all other uses, user can use their own allocation method - * for glyphs. - * - * Since: 1.8 - **/ -void -cairo_glyph_free (cairo_glyph_t *glyphs) -{ - free (glyphs); -} -slim_hidden_def (cairo_glyph_free); - -/** - * cairo_text_cluster_allocate: - * @num_clusters: number of text_clusters to allocate - * - * Allocates an array of #cairo_text_cluster_t's. - * This function is only useful in implementations of - * #cairo_user_scaled_font_text_to_glyphs_func_t where the user - * needs to allocate an array of text clusters that cairo will free. - * For all other uses, user can use their own allocation method - * for text clusters. - * - * This function returns %NULL if @num_clusters is not positive, - * or if out of memory. That means, the %NULL return value - * signals out-of-memory only if @num_clusters was positive. - * - * Returns: the newly allocated array of text clusters that should be - * freed using cairo_text_cluster_free() - * - * Since: 1.8 - **/ -cairo_text_cluster_t * -cairo_text_cluster_allocate (int num_clusters) -{ - if (num_clusters <= 0) - return NULL; - - return _cairo_malloc_ab (num_clusters, sizeof (cairo_text_cluster_t)); -} -slim_hidden_def (cairo_text_cluster_allocate); - -/** - * cairo_text_cluster_free: - * @clusters: array of text clusters to free, or %NULL - * - * Frees an array of #cairo_text_cluster's allocated using cairo_text_cluster_allocate(). - * This function is only useful to free text cluster array returned - * by cairo_scaled_font_text_to_glyphs() where cairo returns - * an array of text clusters that the user will free. - * For all other uses, user can use their own allocation method - * for text clusters. - * - * Since: 1.8 - **/ -void -cairo_text_cluster_free (cairo_text_cluster_t *clusters) -{ - free (clusters); -} -slim_hidden_def (cairo_text_cluster_free); - - -/* Private stuff */ - -/** - * _cairo_validate_text_clusters: - * @utf8: UTF-8 text - * @utf8_len: length of @utf8 in bytes - * @glyphs: array of glyphs - * @num_glyphs: number of glyphs - * @clusters: array of cluster mapping information - * @num_clusters: number of clusters in the mapping - * @cluster_flags: cluster flags - * - * Check that clusters cover the entire glyphs and utf8 arrays, - * and that cluster boundaries are UTF-8 boundaries. - * - * Return value: %CAIRO_STATUS_SUCCESS upon success, or - * %CAIRO_STATUS_INVALID_CLUSTERS on error. - * The error is either invalid UTF-8 input, - * or bad cluster mapping. - **/ -cairo_status_t -_cairo_validate_text_clusters (const char *utf8, - int utf8_len, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags) -{ - cairo_status_t status; - unsigned int n_bytes = 0; - unsigned int n_glyphs = 0; - int i; - - for (i = 0; i < num_clusters; i++) { - int cluster_bytes = clusters[i].num_bytes; - int cluster_glyphs = clusters[i].num_glyphs; - - if (cluster_bytes < 0 || cluster_glyphs < 0) - goto BAD; - - /* A cluster should cover at least one character or glyph. - * I can't see any use for a 0,0 cluster. - * I can't see an immediate use for a zero-text cluster - * right now either, but they don't harm. - * Zero-glyph clusters on the other hand are useful for - * things like U+200C ZERO WIDTH NON-JOINER */ - if (cluster_bytes == 0 && cluster_glyphs == 0) - goto BAD; - - /* Since n_bytes and n_glyphs are unsigned, but the rest of - * values involved are signed, we can detect overflow easily */ - if (n_bytes+cluster_bytes > (unsigned int)utf8_len || n_glyphs+cluster_glyphs > (unsigned int)num_glyphs) - goto BAD; - - /* Make sure we've got valid UTF-8 for the cluster */ - status = _cairo_utf8_to_ucs4 (utf8+n_bytes, cluster_bytes, NULL, NULL); - if (unlikely (status)) - return _cairo_error (CAIRO_STATUS_INVALID_CLUSTERS); - - n_bytes += cluster_bytes ; - n_glyphs += cluster_glyphs; - } - - if (n_bytes != (unsigned int) utf8_len || n_glyphs != (unsigned int) num_glyphs) { - BAD: - return _cairo_error (CAIRO_STATUS_INVALID_CLUSTERS); - } - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_operator_bounded_by_mask: - * @op: a #cairo_operator_t - * - * A bounded operator is one where mask pixel - * of zero results in no effect on the destination image. - * - * Unbounded operators often require special handling; if you, for - * example, draw trapezoids with an unbounded operator, the effect - * extends past the bounding box of the trapezoids. - * - * Return value: %TRUE if the operator is bounded by the mask operand - **/ -cairo_bool_t -_cairo_operator_bounded_by_mask (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_ATOP: - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return TRUE; - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_ATOP: - return FALSE; - } - - ASSERT_NOT_REACHED; - return FALSE; -} - -/** - * _cairo_operator_bounded_by_source: - * @op: a #cairo_operator_t - * - * A bounded operator is one where source pixels of zero - * (in all four components, r, g, b and a) effect no change - * in the resulting destination image. - * - * Unbounded operators often require special handling; if you, for - * example, copy a surface with the SOURCE operator, the effect - * extends past the bounding box of the source surface. - * - * Return value: %TRUE if the operator is bounded by the source operand - **/ -cairo_bool_t -_cairo_operator_bounded_by_source (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_ATOP: - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return TRUE; - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_ATOP: - return FALSE; - } - - ASSERT_NOT_REACHED; - return FALSE; -} - -uint32_t -_cairo_operator_bounded_by_either (cairo_operator_t op) -{ - switch (op) { - default: - ASSERT_NOT_REACHED; - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_ATOP: - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE; - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - return CAIRO_OPERATOR_BOUND_BY_MASK; - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_ATOP: - return 0; - } - -} - -#if DISABLE_SOME_FLOATING_POINT -/* This function is identical to the C99 function lround(), except that it - * performs arithmetic rounding (floor(d + .5) instead of away-from-zero rounding) and - * has a valid input range of (INT_MIN, INT_MAX] instead of - * [INT_MIN, INT_MAX]. It is much faster on both x86 and FPU-less systems - * than other commonly used methods for rounding (lround, round, rint, lrint - * or float (d + 0.5)). - * - * The reason why this function is much faster on x86 than other - * methods is due to the fact that it avoids the fldcw instruction. - * This instruction incurs a large performance penalty on modern Intel - * processors due to how it prevents efficient instruction pipelining. - * - * The reason why this function is much faster on FPU-less systems is for - * an entirely different reason. All common rounding methods involve multiple - * floating-point operations. Each one of these operations has to be - * emulated in software, which adds up to be a large performance penalty. - * This function doesn't perform any floating-point calculations, and thus - * avoids this penalty. - */ -int -_cairo_lround (double d) -{ - uint32_t top, shift_amount, output; - union { - double d; - uint64_t ui64; - uint32_t ui32[2]; - } u; - - u.d = d; - - /* If the integer word order doesn't match the float word order, we swap - * the words of the input double. This is needed because we will be - * treating the whole double as a 64-bit unsigned integer. Notice that we - * use WORDS_BIGENDIAN to detect the integer word order, which isn't - * exactly correct because WORDS_BIGENDIAN refers to byte order, not word - * order. Thus, we are making the assumption that the byte order is the - * same as the integer word order which, on the modern machines that we - * care about, is OK. - */ -#if ( defined(FLOAT_WORDS_BIGENDIAN) && !defined(WORDS_BIGENDIAN)) || \ - (!defined(FLOAT_WORDS_BIGENDIAN) && defined(WORDS_BIGENDIAN)) - { - uint32_t temp = u.ui32[0]; - u.ui32[0] = u.ui32[1]; - u.ui32[1] = temp; - } -#endif - -#ifdef WORDS_BIGENDIAN - #define MSW (0) /* Most Significant Word */ - #define LSW (1) /* Least Significant Word */ -#else - #define MSW (1) - #define LSW (0) -#endif - - /* By shifting the most significant word of the input double to the - * right 20 places, we get the very "top" of the double where the exponent - * and sign bit lie. - */ - top = u.ui32[MSW] >> 20; - - /* Here, we calculate how much we have to shift the mantissa to normalize - * it to an integer value. We extract the exponent "top" by masking out the - * sign bit, then we calculate the shift amount by subtracting the exponent - * from the bias. Notice that the correct bias for 64-bit doubles is - * actually 1075, but we use 1053 instead for two reasons: - * - * 1) To perform rounding later on, we will first need the target - * value in a 31.1 fixed-point format. Thus, the bias needs to be one - * less: (1075 - 1: 1074). - * - * 2) To avoid shifting the mantissa as a full 64-bit integer (which is - * costly on certain architectures), we break the shift into two parts. - * First, the upper and lower parts of the mantissa are shifted - * individually by a constant amount that all valid inputs will require - * at the very least. This amount is chosen to be 21, because this will - * allow the two parts of the mantissa to later be combined into a - * single 32-bit representation, on which the remainder of the shift - * will be performed. Thus, we decrease the bias by an additional 21: - * (1074 - 21: 1053). - */ - shift_amount = 1053 - (top & 0x7FF); - - /* We are done with the exponent portion in "top", so here we shift it off - * the end. - */ - top >>= 11; - - /* Before we perform any operations on the mantissa, we need to OR in - * the implicit 1 at the top (see the IEEE-754 spec). We needn't mask - * off the sign bit nor the exponent bits because these higher bits won't - * make a bit of difference in the rest of our calculations. - */ - u.ui32[MSW] |= 0x100000; - - /* If the input double is negative, we have to decrease the mantissa - * by a hair. This is an important part of performing arithmetic rounding, - * as negative numbers must round towards positive infinity in the - * halfwase case of -x.5. Since "top" contains only the sign bit at this - * point, we can just decrease the mantissa by the value of "top". - */ - u.ui64 -= top; - - /* By decrementing "top", we create a bitmask with a value of either - * 0x0 (if the input was negative) or 0xFFFFFFFF (if the input was positive - * and thus the unsigned subtraction underflowed) that we'll use later. - */ - top--; - - /* Here, we shift the mantissa by the constant value as described above. - * We can emulate a 64-bit shift right by 21 through shifting the top 32 - * bits left 11 places and ORing in the bottom 32 bits shifted 21 places - * to the right. Both parts of the mantissa are now packed into a single - * 32-bit integer. Although we severely truncate the lower part in the - * process, we still have enough significant bits to perform the conversion - * without error (for all valid inputs). - */ - output = (u.ui32[MSW] << 11) | (u.ui32[LSW] >> 21); - - /* Next, we perform the shift that converts the X.Y fixed-point number - * currently found in "output" to the desired 31.1 fixed-point format - * needed for the following rounding step. It is important to consider - * all possible values for "shift_amount" at this point: - * - * - {shift_amount < 0} Since shift_amount is an unsigned integer, it - * really can't have a value less than zero. But, if the shift_amount - * calculation above caused underflow (which would happen with - * input > INT_MAX or input <= INT_MIN) then shift_amount will now be - * a very large number, and so this shift will result in complete - * garbage. But that's OK, as the input was out of our range, so our - * output is undefined. - * - * - {shift_amount > 31} If the magnitude of the input was very small - * (i.e. |input| << 1.0), shift_amount will have a value greater than - * 31. Thus, this shift will also result in garbage. After performing - * the shift, we will zero-out "output" if this is the case. - * - * - {0 <= shift_amount < 32} In this case, the shift will properly convert - * the mantissa into a 31.1 fixed-point number. - */ - output >>= shift_amount; - - /* This is where we perform rounding with the 31.1 fixed-point number. - * Since what we're after is arithmetic rounding, we simply add the single - * fractional bit into the integer part of "output", and just keep the - * integer part. - */ - output = (output >> 1) + (output & 1); - - /* Here, we zero-out the result if the magnitude if the input was very small - * (as explained in the section above). Notice that all input out of the - * valid range is also caught by this condition, which means we produce 0 - * for all invalid input, which is a nice side effect. - * - * The most straightforward way to do this would be: - * - * if (shift_amount > 31) - * output = 0; - * - * But we can use a little trick to avoid the potential branch. The - * expression (shift_amount > 31) will be either 1 or 0, which when - * decremented will be either 0x0 or 0xFFFFFFFF (unsigned underflow), - * which can be used to conditionally mask away all the bits in "output" - * (in the 0x0 case), effectively zeroing it out. Certain, compilers would - * have done this for us automatically. - */ - output &= ((shift_amount > 31) - 1); - - /* If the input double was a negative number, then we have to negate our - * output. The most straightforward way to do this would be: - * - * if (!top) - * output = -output; - * - * as "top" at this point is either 0x0 (if the input was negative) or - * 0xFFFFFFFF (if the input was positive). But, we can use a trick to - * avoid the branch. Observe that the following snippet of code has the - * same effect as the reference snippet above: - * - * if (!top) - * output = 0 - output; - * else - * output = output - 0; - * - * Armed with the bitmask found in "top", we can condense the two statements - * into the following: - * - * output = (output & top) - (output & ~top); - * - * where, in the case that the input double was negative, "top" will be 0, - * and the statement will be equivalent to: - * - * output = (0) - (output); - * - * and if the input double was positive, "top" will be 0xFFFFFFFF, and the - * statement will be equivalent to: - * - * output = (output) - (0); - * - * Which, as pointed out earlier, is equivalent to the original reference - * snippet. - */ - output = (output & top) - (output & ~top); - - return output; -#undef MSW -#undef LSW -} -#endif - -/* Convert a 32-bit IEEE single precision floating point number to a - * 'half' representation (s10.5) - */ -uint16_t -_cairo_half_from_float (float f) -{ - union { - uint32_t ui; - float f; - } u; - int s, e, m; - - u.f = f; - s = (u.ui >> 16) & 0x00008000; - e = ((u.ui >> 23) & 0x000000ff) - (127 - 15); - m = u.ui & 0x007fffff; - if (e <= 0) { - if (e < -10) { - /* underflow */ - return 0; - } - - m = (m | 0x00800000) >> (1 - e); - - /* round to nearest, round 0.5 up. */ - if (m & 0x00001000) - m += 0x00002000; - return s | (m >> 13); - } else if (e == 0xff - (127 - 15)) { - if (m == 0) { - /* infinity */ - return s | 0x7c00; - } else { - /* nan */ - m >>= 13; - return s | 0x7c00 | m | (m == 0); - } - } else { - /* round to nearest, round 0.5 up. */ - if (m & 0x00001000) { - m += 0x00002000; - - if (m & 0x00800000) { - m = 0; - e += 1; - } - } - - if (e > 30) { - /* overflow -> infinity */ - return s | 0x7c00; - } - - return s | (e << 10) | (m >> 13); - } -} - -#ifndef __BIONIC__ -# include - -const char * -cairo_get_locale_decimal_point (void) -{ - struct lconv *locale_data = localeconv (); - return locale_data->decimal_point; -} - -#else -/* Android's Bionic libc doesn't provide decimal_point */ -const char * -cairo_get_locale_decimal_point (void) -{ - return '.'; -} -#endif - -#ifdef _WIN32 - -#define WIN32_LEAN_AND_MEAN -/* We require Windows 2000 features such as ETO_PDY */ -#if !defined(WINVER) || (WINVER < 0x0500) -# define WINVER 0x0500 -#endif -#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) -# define _WIN32_WINNT 0x0500 -#endif - -#include -#include - -#if !_WIN32_WCE -/* tmpfile() replacement for Windows. - * - * On Windows tmpfile() creates the file in the root directory. This - * may fail due to unsufficient privileges. However, this isn't a - * problem on Windows CE so we don't use it there. - */ -FILE * -_cairo_win32_tmpfile (void) -{ - DWORD path_len; - WCHAR path_name[MAX_PATH + 1]; - WCHAR file_name[MAX_PATH + 1]; - HANDLE handle; - int fd; - FILE *fp; - - path_len = GetTempPathW (MAX_PATH, path_name); - if (path_len <= 0 || path_len >= MAX_PATH) - return NULL; - - if (GetTempFileNameW (path_name, L"ps_", 0, file_name) == 0) - return NULL; - - handle = CreateFileW (file_name, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, - NULL); - if (handle == INVALID_HANDLE_VALUE) { - DeleteFileW (file_name); - return NULL; - } - - fd = _open_osfhandle((intptr_t) handle, 0); - if (fd < 0) { - CloseHandle (handle); - return NULL; - } - - fp = fdopen(fd, "w+b"); - if (fp == NULL) { - _close(fd); - return NULL; - } - - return fp; -} -#endif /* !_WIN32_WCE */ - -#endif /* _WIN32 */ - -typedef struct _cairo_intern_string { - cairo_hash_entry_t hash_entry; - int len; - char *string; -} cairo_intern_string_t; - -static cairo_hash_table_t *_cairo_intern_string_ht; - -static unsigned long -_intern_string_hash (const char *str, int len) -{ - const signed char *p = (const signed char *) str; - unsigned int h = *p; - - for (p += 1; --len; p++) - h = (h << 5) - h + *p; - - return h; -} - -static cairo_bool_t -_intern_string_equal (const void *_a, const void *_b) -{ - const cairo_intern_string_t *a = _a; - const cairo_intern_string_t *b = _b; - - if (a->len != b->len) - return FALSE; - - return memcmp (a->string, b->string, a->len) == 0; -} - -cairo_status_t -_cairo_intern_string (const char **str_inout, int len) -{ - char *str = (char *) *str_inout; - cairo_intern_string_t tmpl, *istring; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (len < 0) - len = strlen (str); - tmpl.hash_entry.hash = _intern_string_hash (str, len); - tmpl.len = len; - tmpl.string = (char *) str; - - CAIRO_MUTEX_LOCK (_cairo_intern_string_mutex); - if (_cairo_intern_string_ht == NULL) { - _cairo_intern_string_ht = _cairo_hash_table_create (_intern_string_equal); - if (unlikely (_cairo_intern_string_ht == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - } - - istring = _cairo_hash_table_lookup (_cairo_intern_string_ht, - &tmpl.hash_entry); - if (istring == NULL) { - istring = malloc (sizeof (cairo_intern_string_t) + len + 1); - if (likely (istring != NULL)) { - istring->hash_entry.hash = tmpl.hash_entry.hash; - istring->len = tmpl.len; - istring->string = (char *) (istring + 1); - memcpy (istring->string, str, len); - istring->string[len] = '\0'; - - status = _cairo_hash_table_insert (_cairo_intern_string_ht, - &istring->hash_entry); - if (unlikely (status)) { - free (istring); - goto BAIL; - } - } else { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - } - - *str_inout = istring->string; - - BAIL: - CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex); - return status; -} - -static void -_intern_string_pluck (void *entry, void *closure) -{ - _cairo_hash_table_remove (closure, entry); - free (entry); -} - -void -_cairo_intern_string_reset_static_data (void) -{ - CAIRO_MUTEX_LOCK (_cairo_intern_string_mutex); - if (_cairo_intern_string_ht != NULL) { - _cairo_hash_table_foreach (_cairo_intern_string_ht, - _intern_string_pluck, - _cairo_intern_string_ht); - _cairo_hash_table_destroy(_cairo_intern_string_ht); - _cairo_intern_string_ht = NULL; - } - CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mono-scan-converter.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mono-scan-converter.c deleted file mode 100644 index 2a9546cf82a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mono-scan-converter.c +++ /dev/null @@ -1,612 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* - * Copyright (c) 2011 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -#include "cairoint.h" -#include "cairo-spans-private.h" -#include "cairo-error-private.h" - -#include -#include -#include - -struct quorem { - int32_t quo; - int32_t rem; -}; - -struct edge { - struct edge *next, *prev; - - int32_t height_left; - int32_t dir; - int32_t vertical; - - int32_t dy; - struct quorem x; - struct quorem dxdy; -}; - -/* A collection of sorted and vertically clipped edges of the polygon. - * Edges are moved from the polygon to an active list while scan - * converting. */ -struct polygon { - /* The vertical clip extents. */ - int32_t ymin, ymax; - - int num_edges; - struct edge *edges; - - /* Array of edges all starting in the same bucket. An edge is put - * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when - * it is added to the polygon. */ - struct edge **y_buckets; - - struct edge *y_buckets_embedded[64]; - struct edge edges_embedded[32]; -}; - -struct mono_scan_converter { - struct polygon polygon[1]; - - /* Leftmost edge on the current scan line. */ - struct edge head, tail; - int is_vertical; - - cairo_half_open_span_t *spans; - cairo_half_open_span_t spans_embedded[64]; - int num_spans; - - /* Clip box. */ - int32_t xmin, xmax; - int32_t ymin, ymax; -}; - -#define I(x) _cairo_fixed_integer_round_down(x) - -/* Compute the floored division a/b. Assumes / and % perform symmetric - * division. */ -inline static struct quorem -floored_divrem(int a, int b) -{ - struct quorem qr; - qr.quo = a/b; - qr.rem = a%b; - if ((a^b)<0 && qr.rem) { - qr.quo -= 1; - qr.rem += b; - } - return qr; -} - -/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric - * division. */ -static struct quorem -floored_muldivrem(int x, int a, int b) -{ - struct quorem qr; - long long xa = (long long)x*a; - qr.quo = xa/b; - qr.rem = xa%b; - if ((xa>=0) != (b>=0) && qr.rem) { - qr.quo -= 1; - qr.rem += b; - } - return qr; -} - -static cairo_status_t -polygon_init (struct polygon *polygon, int ymin, int ymax) -{ - unsigned h = ymax - ymin + 1; - - polygon->y_buckets = polygon->y_buckets_embedded; - if (h > ARRAY_LENGTH (polygon->y_buckets_embedded)) { - polygon->y_buckets = _cairo_malloc_ab (h, sizeof (struct edge *)); - if (unlikely (NULL == polygon->y_buckets)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - memset (polygon->y_buckets, 0, h * sizeof (struct edge *)); - polygon->y_buckets[h-1] = (void *)-1; - - polygon->ymin = ymin; - polygon->ymax = ymax; - return CAIRO_STATUS_SUCCESS; -} - -static void -polygon_fini (struct polygon *polygon) -{ - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - if (polygon->edges != polygon->edges_embedded) - free (polygon->edges); -} - -static void -_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, - struct edge *e, - int y) -{ - struct edge **ptail = &polygon->y_buckets[y - polygon->ymin]; - if (*ptail) - (*ptail)->prev = e; - e->next = *ptail; - e->prev = NULL; - *ptail = e; -} - -inline static void -polygon_add_edge (struct polygon *polygon, - const cairo_edge_t *edge) -{ - struct edge *e; - cairo_fixed_t dx; - cairo_fixed_t dy; - int y, ytop, ybot; - int ymin = polygon->ymin; - int ymax = polygon->ymax; - - y = I(edge->top); - ytop = MAX(y, ymin); - - y = I(edge->bottom); - ybot = MIN(y, ymax); - - if (ybot <= ytop) - return; - - e = polygon->edges + polygon->num_edges++; - e->height_left = ybot - ytop; - e->dir = edge->dir; - - dx = edge->line.p2.x - edge->line.p1.x; - dy = edge->line.p2.y - edge->line.p1.y; - - if (dx == 0) { - e->vertical = TRUE; - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - e->dxdy.quo = 0; - e->dxdy.rem = 0; - e->dy = 0; - } else { - e->vertical = FALSE; - e->dxdy = floored_muldivrem (dx, CAIRO_FIXED_ONE, dy); - e->dy = dy; - - e->x = floored_muldivrem (ytop * CAIRO_FIXED_ONE + CAIRO_FIXED_FRAC_MASK/2 - edge->line.p1.y, - dx, dy); - e->x.quo += edge->line.p1.x; - } - e->x.rem -= dy; - - _polygon_insert_edge_into_its_y_bucket (polygon, e, ytop); -} - -static struct edge * -merge_sorted_edges (struct edge *head_a, struct edge *head_b) -{ - struct edge *head, **next, *prev; - int32_t x; - - prev = head_a->prev; - next = &head; - if (head_a->x.quo <= head_b->x.quo) { - head = head_a; - } else { - head = head_b; - head_b->prev = prev; - goto start_with_b; - } - - do { - x = head_b->x.quo; - while (head_a != NULL && head_a->x.quo <= x) { - prev = head_a; - next = &head_a->next; - head_a = head_a->next; - } - - head_b->prev = prev; - *next = head_b; - if (head_a == NULL) - return head; - -start_with_b: - x = head_a->x.quo; - while (head_b != NULL && head_b->x.quo <= x) { - prev = head_b; - next = &head_b->next; - head_b = head_b->next; - } - - head_a->prev = prev; - *next = head_a; - if (head_b == NULL) - return head; - } while (1); -} - -static struct edge * -sort_edges (struct edge *list, - unsigned int level, - struct edge **head_out) -{ - struct edge *head_other, *remaining; - unsigned int i; - - head_other = list->next; - - if (head_other == NULL) { - *head_out = list; - return NULL; - } - - remaining = head_other->next; - if (list->x.quo <= head_other->x.quo) { - *head_out = list; - head_other->next = NULL; - } else { - *head_out = head_other; - head_other->prev = list->prev; - head_other->next = list; - list->prev = head_other; - list->next = NULL; - } - - for (i = 0; i < level && remaining; i++) { - remaining = sort_edges (remaining, i, &head_other); - *head_out = merge_sorted_edges (*head_out, head_other); - } - - return remaining; -} - -static struct edge * -merge_unsorted_edges (struct edge *head, struct edge *unsorted) -{ - sort_edges (unsorted, UINT_MAX, &unsorted); - return merge_sorted_edges (head, unsorted); -} - -inline static void -active_list_merge_edges (struct mono_scan_converter *c, struct edge *edges) -{ - struct edge *e; - - for (e = edges; c->is_vertical && e; e = e->next) - c->is_vertical = e->vertical; - - c->head.next = merge_unsorted_edges (c->head.next, edges); -} - -inline static void -add_span (struct mono_scan_converter *c, int x1, int x2) -{ - int n; - - if (x1 < c->xmin) - x1 = c->xmin; - if (x2 > c->xmax) - x2 = c->xmax; - if (x2 <= x1) - return; - - n = c->num_spans++; - c->spans[n].x = x1; - c->spans[n].coverage = 255; - - n = c->num_spans++; - c->spans[n].x = x2; - c->spans[n].coverage = 0; -} - -inline static void -row (struct mono_scan_converter *c, unsigned int mask) -{ - struct edge *edge = c->head.next; - int xstart = INT_MIN, prev_x = INT_MIN; - int winding = 0; - - c->num_spans = 0; - while (&c->tail != edge) { - struct edge *next = edge->next; - int xend = I(edge->x.quo); - - if (--edge->height_left) { - if (!edge->vertical) { - edge->x.quo += edge->dxdy.quo; - edge->x.rem += edge->dxdy.rem; - if (edge->x.rem >= 0) { - ++edge->x.quo; - edge->x.rem -= edge->dy; - } - } - - if (edge->x.quo < prev_x) { - struct edge *pos = edge->prev; - pos->next = next; - next->prev = pos; - do { - pos = pos->prev; - } while (edge->x.quo < pos->x.quo); - pos->next->prev = edge; - edge->next = pos->next; - edge->prev = pos; - pos->next = edge; - } else - prev_x = edge->x.quo; - } else { - edge->prev->next = next; - next->prev = edge->prev; - } - - winding += edge->dir; - if ((winding & mask) == 0) { - if (I(next->x.quo) > xend + 1) { - add_span (c, xstart, xend); - xstart = INT_MIN; - } - } else if (xstart == INT_MIN) - xstart = xend; - - edge = next; - } -} - -inline static void dec (struct edge *e, int h) -{ - e->height_left -= h; - if (e->height_left == 0) { - e->prev->next = e->next; - e->next->prev = e->prev; - } -} - -static cairo_status_t -_mono_scan_converter_init(struct mono_scan_converter *c, - int xmin, int ymin, - int xmax, int ymax) -{ - cairo_status_t status; - int max_num_spans; - - status = polygon_init (c->polygon, ymin, ymax); - if (unlikely (status)) - return status; - - max_num_spans = xmax - xmin + 1; - if (max_num_spans > ARRAY_LENGTH(c->spans_embedded)) { - c->spans = _cairo_malloc_ab (max_num_spans, - sizeof (cairo_half_open_span_t)); - if (unlikely (c->spans == NULL)) { - polygon_fini (c->polygon); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } else - c->spans = c->spans_embedded; - - c->xmin = xmin; - c->xmax = xmax; - c->ymin = ymin; - c->ymax = ymax; - - c->head.vertical = 1; - c->head.height_left = INT_MAX; - c->head.x.quo = _cairo_fixed_from_int (_cairo_fixed_integer_part (INT_MIN)); - c->head.prev = NULL; - c->head.next = &c->tail; - c->tail.prev = &c->head; - c->tail.next = NULL; - c->tail.x.quo = _cairo_fixed_from_int (_cairo_fixed_integer_part (INT_MAX)); - c->tail.height_left = INT_MAX; - c->tail.vertical = 1; - - c->is_vertical = 1; - return CAIRO_STATUS_SUCCESS; -} - -static void -_mono_scan_converter_fini(struct mono_scan_converter *self) -{ - if (self->spans != self->spans_embedded) - free (self->spans); - - polygon_fini(self->polygon); -} - -static cairo_status_t -mono_scan_converter_allocate_edges(struct mono_scan_converter *c, - int num_edges) - -{ - c->polygon->num_edges = 0; - c->polygon->edges = c->polygon->edges_embedded; - if (num_edges > ARRAY_LENGTH (c->polygon->edges_embedded)) { - c->polygon->edges = _cairo_malloc_ab (num_edges, sizeof (struct edge)); - if (unlikely (c->polygon->edges == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -mono_scan_converter_add_edge (struct mono_scan_converter *c, - const cairo_edge_t *edge) -{ - polygon_add_edge (c->polygon, edge); -} - -static void -step_edges (struct mono_scan_converter *c, int count) -{ - struct edge *edge; - - for (edge = c->head.next; edge != &c->tail; edge = edge->next) { - edge->height_left -= count; - if (! edge->height_left) { - edge->prev->next = edge->next; - edge->next->prev = edge->prev; - } - } -} - -static cairo_status_t -mono_scan_converter_render(struct mono_scan_converter *c, - unsigned int winding_mask, - cairo_span_renderer_t *renderer) -{ - struct polygon *polygon = c->polygon; - int i, j, h = c->ymax - c->ymin; - cairo_status_t status; - - for (i = 0; i < h; i = j) { - j = i + 1; - - if (polygon->y_buckets[i]) - active_list_merge_edges (c, polygon->y_buckets[i]); - - if (c->is_vertical) { - int min_height; - struct edge *e; - - e = c->head.next; - min_height = e->height_left; - while (e != &c->tail) { - if (e->height_left < min_height) - min_height = e->height_left; - e = e->next; - } - - while (--min_height >= 1 && polygon->y_buckets[j] == NULL) - j++; - if (j != i + 1) - step_edges (c, j - (i + 1)); - } - - row (c, winding_mask); - if (c->num_spans) { - status = renderer->render_rows (renderer, c->ymin+i, j-i, - c->spans, c->num_spans); - if (unlikely (status)) - return status; - } - - /* XXX recompute after dropping edges? */ - if (c->head.next == &c->tail) - c->is_vertical = 1; - } - - return CAIRO_STATUS_SUCCESS; -} - -struct _cairo_mono_scan_converter { - cairo_scan_converter_t base; - - struct mono_scan_converter converter[1]; - cairo_fill_rule_t fill_rule; -}; - -typedef struct _cairo_mono_scan_converter cairo_mono_scan_converter_t; - -static void -_cairo_mono_scan_converter_destroy (void *converter) -{ - cairo_mono_scan_converter_t *self = converter; - _mono_scan_converter_fini (self->converter); - free(self); -} - -cairo_status_t -_cairo_mono_scan_converter_add_polygon (void *converter, - const cairo_polygon_t *polygon) -{ - cairo_mono_scan_converter_t *self = converter; - cairo_status_t status; - int i; - -#if 0 - FILE *file = fopen ("polygon.txt", "w"); - _cairo_debug_print_polygon (file, polygon); - fclose (file); -#endif - - status = mono_scan_converter_allocate_edges (self->converter, - polygon->num_edges); - if (unlikely (status)) - return status; - - for (i = 0; i < polygon->num_edges; i++) - mono_scan_converter_add_edge (self->converter, &polygon->edges[i]); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_mono_scan_converter_generate (void *converter, - cairo_span_renderer_t *renderer) -{ - cairo_mono_scan_converter_t *self = converter; - - return mono_scan_converter_render (self->converter, - self->fill_rule == CAIRO_FILL_RULE_WINDING ? ~0 : 1, - renderer); -} - -cairo_scan_converter_t * -_cairo_mono_scan_converter_create (int xmin, - int ymin, - int xmax, - int ymax, - cairo_fill_rule_t fill_rule) -{ - cairo_mono_scan_converter_t *self; - cairo_status_t status; - - self = malloc (sizeof(struct _cairo_mono_scan_converter)); - if (unlikely (self == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto bail_nomem; - } - - self->base.destroy = _cairo_mono_scan_converter_destroy; - self->base.generate = _cairo_mono_scan_converter_generate; - - status = _mono_scan_converter_init (self->converter, - xmin, ymin, xmax, ymax); - if (unlikely (status)) - goto bail; - - self->fill_rule = fill_rule; - - return &self->base; - - bail: - self->base.destroy(&self->base); - bail_nomem: - return _cairo_scan_converter_create_in_error (status); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-impl-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-impl-private.h deleted file mode 100644 index 25223f3eac0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-impl-private.h +++ /dev/null @@ -1,278 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005,2007 Red Hat, Inc. - * Copyright © 2007 Mathias Hasselmann - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Mathias Hasselmann - * Behdad Esfahbod - */ - -#ifndef CAIRO_MUTEX_IMPL_PRIVATE_H -#define CAIRO_MUTEX_IMPL_PRIVATE_H - -#include "cairo.h" - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#if HAVE_LOCKDEP -#include -#endif - -/* A fully qualified no-operation statement */ -#define CAIRO_MUTEX_IMPL_NOOP do {/*no-op*/} while (0) -/* And one that evaluates its argument once */ -#define CAIRO_MUTEX_IMPL_NOOP1(expr) do { (void)(expr); } while (0) -/* Note: 'if (expr) {}' is an alternative to '(void)(expr);' that will 'use' the - * result of __attribute__((warn_used_result)) functions. */ - -/* Cairo mutex implementation: - * - * Any new mutex implementation needs to do the following: - * - * - Condition on the right header or feature. Headers are - * preferred as eg. you still can use win32 mutex implementation - * on a win32 system even if you do not compile the win32 - * surface/backend. - * - * - typedef #cairo_mutex_impl_t to the proper mutex type on your target - * system. Note that you may or may not need to use a pointer, - * depending on what kinds of initialization your mutex - * implementation supports. No trailing semicolon needed. - * You should be able to compile the following snippet (don't try - * running it): - * - * - * cairo_mutex_impl_t _cairo_some_mutex; - * - * - * - #define %CAIRO_MUTEX_IMPL_ 1 with suitable name for your platform. You - * can later use this symbol in cairo-system.c. - * - * - #define CAIRO_MUTEX_IMPL_LOCK(mutex) and CAIRO_MUTEX_IMPL_UNLOCK(mutex) to - * proper statement to lock/unlock the mutex object passed in. - * You can (and should) assume that the mutex is already - * initialized, and is-not-already-locked/is-locked, - * respectively. Use the "do { ... } while (0)" idiom if necessary. - * No trailing semicolons are needed (in any macro you define here). - * You should be able to compile the following snippet: - * - * - * cairo_mutex_impl_t _cairo_some_mutex; - * - * if (1) - * CAIRO_MUTEX_IMPL_LOCK (_cairo_some_mutex); - * else - * CAIRO_MUTEX_IMPL_UNLOCK (_cairo_some_mutex); - * - * - * - #define %CAIRO_MUTEX_IMPL_NIL_INITIALIZER to something that can - * initialize the #cairo_mutex_impl_t type you defined. Most of the - * time one of 0, %NULL, or {} works. At this point - * you should be able to compile the following snippet: - * - * - * cairo_mutex_impl_t _cairo_some_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; - * - * if (1) - * CAIRO_MUTEX_IMPL_LOCK (_cairo_some_mutex); - * else - * CAIRO_MUTEX_IMPL_UNLOCK (_cairo_some_mutex); - * - * - * - If the above code is not enough to initialize a mutex on - * your platform, #define CAIRO_MUTEX_IMPL_INIT(mutex) to statement - * to initialize the mutex (allocate resources, etc). Such that - * you should be able to compile AND RUN the following snippet: - * - * - * cairo_mutex_impl_t _cairo_some_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; - * - * CAIRO_MUTEX_IMPL_INIT (_cairo_some_mutex); - * - * if (1) - * CAIRO_MUTEX_IMPL_LOCK (_cairo_some_mutex); - * else - * CAIRO_MUTEX_IMPL_UNLOCK (_cairo_some_mutex); - * - * - * - If you define CAIRO_MUTEX_IMPL_INIT(mutex), cairo will use it to - * initialize all static mutex'es. If for any reason that should - * not happen (eg. %CAIRO_MUTEX_IMPL_INIT is just a faster way than - * what cairo does using %CAIRO_MUTEX_IMPL_NIL_INITIALIZER), then - * - * #define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP - * - * - * - If your system supports freeing a mutex object (deallocating - * resources, etc), then #define CAIRO_MUTEX_IMPL_FINI(mutex) to do - * that. - * - * - If you define CAIRO_MUTEX_IMPL_FINI(mutex), cairo will use it to - * define a finalizer function to finalize all static mutex'es. - * However, it's up to you to call CAIRO_MUTEX_IMPL_FINALIZE() at - * proper places, eg. when the system is unloading the cairo library. - * So, if for any reason finalizing static mutex'es is not needed - * (eg. you never call CAIRO_MUTEX_IMPL_FINALIZE()), then - * - * #define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP - * - * - * - That is all. If for any reason you think the above API is - * not enough to implement #cairo_mutex_impl_t on your system, please - * stop and write to the cairo mailing list about it. DO NOT - * poke around cairo-mutex-private.h for possible solutions. - */ - -#if CAIRO_NO_MUTEX - -/* No mutexes */ - - typedef int cairo_mutex_impl_t; - -# define CAIRO_MUTEX_IMPL_NO 1 -# define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP -# define CAIRO_MUTEX_IMPL_LOCK(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) -# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) -# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER 0 - -# define CAIRO_MUTEX_HAS_RECURSIVE_IMPL 1 - - typedef int cairo_recursive_mutex_impl_t; - -# define CAIRO_RECURSIVE_MUTEX_IMPL_INIT(mutex) -# define CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER 0 - -#elif defined(_WIN32) /******************************************************/ - -#define WIN32_LEAN_AND_MEAN -/* We require Windows 2000 features such as ETO_PDY */ -#if !defined(WINVER) || (WINVER < 0x0500) -# define WINVER 0x0500 -#endif -#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) -# define _WIN32_WINNT 0x0500 -#endif - -# include - - typedef CRITICAL_SECTION cairo_mutex_impl_t; - -# define CAIRO_MUTEX_IMPL_WIN32 1 -# define CAIRO_MUTEX_IMPL_LOCK(mutex) EnterCriticalSection (&(mutex)) -# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) LeaveCriticalSection (&(mutex)) -# define CAIRO_MUTEX_IMPL_INIT(mutex) InitializeCriticalSection (&(mutex)) -# define CAIRO_MUTEX_IMPL_FINI(mutex) DeleteCriticalSection (&(mutex)) -# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 } - -#elif defined __OS2__ /******************************************************/ - -# define INCL_BASE -# define INCL_PM -# include - - typedef HMTX cairo_mutex_impl_t; - -# define CAIRO_MUTEX_IMPL_OS2 1 -# define CAIRO_MUTEX_IMPL_LOCK(mutex) DosRequestMutexSem(mutex, SEM_INDEFINITE_WAIT) -# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) DosReleaseMutexSem(mutex) -# define CAIRO_MUTEX_IMPL_INIT(mutex) DosCreateMutexSem (NULL, &(mutex), 0L, FALSE) -# define CAIRO_MUTEX_IMPL_FINI(mutex) DosCloseMutexSem (mutex) -# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER 0 - -#elif CAIRO_HAS_BEOS_SURFACE /***********************************************/ - - typedef BLocker* cairo_mutex_impl_t; - -# define CAIRO_MUTEX_IMPL_BEOS 1 -# define CAIRO_MUTEX_IMPL_LOCK(mutex) (mutex)->Lock() -# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) (mutex)->Unlock() -# define CAIRO_MUTEX_IMPL_INIT(mutex) (mutex) = new BLocker() -# define CAIRO_MUTEX_IMPL_FINI(mutex) delete (mutex) -# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER NULL - -#elif CAIRO_HAS_PTHREAD /* and finally if there are no native mutexes ********/ - -# include - - typedef pthread_mutex_t cairo_mutex_impl_t; - typedef pthread_mutex_t cairo_recursive_mutex_impl_t; - -# define CAIRO_MUTEX_IMPL_PTHREAD 1 -#if HAVE_LOCKDEP -/* expose all mutexes to the validator */ -# define CAIRO_MUTEX_IMPL_INIT(mutex) pthread_mutex_init (&(mutex), NULL) -#endif -# define CAIRO_MUTEX_IMPL_LOCK(mutex) pthread_mutex_lock (&(mutex)) -# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) -#if HAVE_LOCKDEP -# define CAIRO_MUTEX_IS_LOCKED(mutex) LOCKDEP_IS_LOCKED (&(mutex)) -# define CAIRO_MUTEX_IS_UNLOCKED(mutex) LOCKDEP_IS_UNLOCKED (&(mutex)) -#endif -# define CAIRO_MUTEX_IMPL_FINI(mutex) pthread_mutex_destroy (&(mutex)) -#if ! HAVE_LOCKDEP -# define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP -#endif -# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER - -# define CAIRO_MUTEX_HAS_RECURSIVE_IMPL 1 -# define CAIRO_RECURSIVE_MUTEX_IMPL_INIT(mutex) do { \ - pthread_mutexattr_t attr; \ - pthread_mutexattr_init (&attr); \ - pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); \ - pthread_mutex_init (&(mutex), &attr); \ - pthread_mutexattr_destroy (&attr); \ -} while (0) -# define CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP - -#else /**********************************************************************/ - -# error "XXX: No mutex implementation found. Cairo will not work with multiple threads. Define CAIRO_NO_MUTEX to 1 to acknowledge and accept this limitation and compile cairo without thread-safety support." - -#endif - -/* By default mutex implementations are assumed to be recursive */ -#if ! CAIRO_MUTEX_HAS_RECURSIVE_IMPL - -# define CAIRO_MUTEX_HAS_RECURSIVE_IMPL 1 - - typedef cairo_mutex_impl_t cairo_recursive_mutex_impl_t; - -# define CAIRO_RECURSIVE_MUTEX_IMPL_INIT(mutex) CAIRO_MUTEX_IMPL_INIT(mutex) -# define CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER CAIRO_MUTEX_IMPL_NIL_INITIALIZER - -#endif - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-list-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-list-private.h deleted file mode 100644 index f46afadb04b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-list-private.h +++ /dev/null @@ -1,78 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Mathias Hasselmann - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Mathias Hasselmann - */ - -#ifndef CAIRO_FEATURES_H -/* This block is to just make this header file standalone */ -#define CAIRO_MUTEX_DECLARE(mutex) -#endif - -CAIRO_MUTEX_DECLARE (_cairo_pattern_solid_surface_cache_lock) - -CAIRO_MUTEX_DECLARE (_cairo_image_solid_cache_mutex) - -CAIRO_MUTEX_DECLARE (_cairo_toy_font_face_mutex) -CAIRO_MUTEX_DECLARE (_cairo_intern_string_mutex) -CAIRO_MUTEX_DECLARE (_cairo_scaled_font_map_mutex) -CAIRO_MUTEX_DECLARE (_cairo_scaled_glyph_page_cache_mutex) -CAIRO_MUTEX_DECLARE (_cairo_scaled_font_error_mutex) -CAIRO_MUTEX_DECLARE (_cairo_glyph_cache_mutex) - -#if CAIRO_HAS_FT_FONT -CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_font_map_mutex) -#endif - -#if CAIRO_HAS_WIN32_FONT -CAIRO_MUTEX_DECLARE (_cairo_win32_font_face_mutex) -#endif - -#if CAIRO_HAS_XLIB_SURFACE -CAIRO_MUTEX_DECLARE (_cairo_xlib_display_mutex) -#endif - -#if CAIRO_HAS_XCB_SURFACE -CAIRO_MUTEX_DECLARE (_cairo_xcb_connections_mutex) -#endif - -#if CAIRO_HAS_GL_SURFACE -CAIRO_MUTEX_DECLARE (_cairo_gl_context_mutex) -#endif - -#if !defined (HAS_ATOMIC_OPS) || defined (ATOMIC_OP_NEEDS_MEMORY_BARRIER) -CAIRO_MUTEX_DECLARE (_cairo_atomic_mutex) -#endif - -#if CAIRO_HAS_DRM_SURFACE -CAIRO_MUTEX_DECLARE (_cairo_drm_device_mutex) -#endif -/* Undefine, to err on unintended inclusion */ -#undef CAIRO_MUTEX_DECLARE diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-private.h deleted file mode 100644 index 61a7160a066..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-private.h +++ /dev/null @@ -1,67 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005,2007 Red Hat, Inc. - * Copyright © 2007 Mathias Hasselmann - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Mathias Hasselmann - * Behdad Esfahbod - */ - -#ifndef CAIRO_MUTEX_PRIVATE_H -#define CAIRO_MUTEX_PRIVATE_H - -#include "cairo-mutex-type-private.h" - -CAIRO_BEGIN_DECLS - -#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER -cairo_private void _cairo_mutex_initialize (void); -#endif -#if _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER -cairo_private void _cairo_mutex_finalize (void); -#endif -/* only if using static initializer and/or finalizer define the boolean */ -#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER - cairo_private extern cairo_bool_t _cairo_mutex_initialized; -#endif - -/* Finally, extern the static mutexes and undef */ - -#define CAIRO_MUTEX_DECLARE(mutex) cairo_private extern cairo_mutex_t mutex; -#include "cairo-mutex-list-private.h" -#undef CAIRO_MUTEX_DECLARE - -CAIRO_END_DECLS - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-type-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-type-private.h deleted file mode 100644 index e8c493985c9..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex-type-private.h +++ /dev/null @@ -1,194 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005,2007 Red Hat, Inc. - * Copyright © 2007 Mathias Hasselmann - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Mathias Hasselmann - * Behdad Esfahbod - */ - -#ifndef CAIRO_MUTEX_TYPE_PRIVATE_H -#define CAIRO_MUTEX_TYPE_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-mutex-impl-private.h" - -/* Only the following four are mandatory at this point */ -#ifndef CAIRO_MUTEX_IMPL_LOCK -# error "CAIRO_MUTEX_IMPL_LOCK not defined. Check cairo-mutex-impl-private.h." -#endif -#ifndef CAIRO_MUTEX_IMPL_UNLOCK -# error "CAIRO_MUTEX_IMPL_UNLOCK not defined. Check cairo-mutex-impl-private.h." -#endif -#ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER -# error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined. Check cairo-mutex-impl-private.h." -#endif -#ifndef CAIRO_RECURSIVE_MUTEX_IMPL_INIT -# error "CAIRO_RECURSIVE_MUTEX_IMPL_INIT not defined. Check cairo-mutex-impl-private.h." -#endif - - -/* make sure implementations don't fool us: we decide these ourself */ -#undef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER -#undef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER - - -#ifdef CAIRO_MUTEX_IMPL_INIT - -/* If %CAIRO_MUTEX_IMPL_INIT is defined, we may need to initialize all - * static mutex'es. */ -# ifndef CAIRO_MUTEX_IMPL_INITIALIZE -# define CAIRO_MUTEX_IMPL_INITIALIZE() do { \ - if (!_cairo_mutex_initialized) \ - _cairo_mutex_initialize (); \ - } while(0) - -/* and make sure we implement the above */ -# define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 1 -# endif /* CAIRO_MUTEX_IMPL_INITIALIZE */ - -#else /* no CAIRO_MUTEX_IMPL_INIT */ - -/* Otherwise we probably don't need to initialize static mutex'es, */ -# ifndef CAIRO_MUTEX_IMPL_INITIALIZE -# define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP -# endif /* CAIRO_MUTEX_IMPL_INITIALIZE */ - -/* and dynamic ones can be initialized using the static initializer. */ -# define CAIRO_MUTEX_IMPL_INIT(mutex) do { \ - cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; \ - memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \ - } while (0) - -#endif /* CAIRO_MUTEX_IMPL_INIT */ - -#ifdef CAIRO_MUTEX_IMPL_FINI - -/* If %CAIRO_MUTEX_IMPL_FINI is defined, we may need to finalize all - * static mutex'es. */ -# ifndef CAIRO_MUTEX_IMPL_FINALIZE -# define CAIRO_MUTEX_IMPL_FINALIZE() do { \ - if (_cairo_mutex_initialized) \ - _cairo_mutex_finalize (); \ - } while(0) - -/* and make sure we implement the above */ -# define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 1 -# endif /* CAIRO_MUTEX_IMPL_FINALIZE */ - -#else /* no CAIRO_MUTEX_IMPL_FINI */ - -/* Otherwise we probably don't need to finalize static mutex'es, */ -# ifndef CAIRO_MUTEX_IMPL_FINALIZE -# define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP -# endif /* CAIRO_MUTEX_IMPL_FINALIZE */ - -/* neither do the dynamic ones. */ -# define CAIRO_MUTEX_IMPL_FINI(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) - -#endif /* CAIRO_MUTEX_IMPL_FINI */ - - -#ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER -#define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 0 -#endif -#ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER -#define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 0 -#endif - - -/* Make sure everything we want is defined */ -#ifndef CAIRO_MUTEX_IMPL_INITIALIZE -# error "CAIRO_MUTEX_IMPL_INITIALIZE not defined" -#endif -#ifndef CAIRO_MUTEX_IMPL_FINALIZE -# error "CAIRO_MUTEX_IMPL_FINALIZE not defined" -#endif -#ifndef CAIRO_MUTEX_IMPL_LOCK -# error "CAIRO_MUTEX_IMPL_LOCK not defined" -#endif -#ifndef CAIRO_MUTEX_IMPL_UNLOCK -# error "CAIRO_MUTEX_IMPL_UNLOCK not defined" -#endif -#ifndef CAIRO_MUTEX_IMPL_INIT -# error "CAIRO_MUTEX_IMPL_INIT not defined" -#endif -#ifndef CAIRO_MUTEX_IMPL_FINI -# error "CAIRO_MUTEX_IMPL_FINI not defined" -#endif -#ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER -# error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined" -#endif - - -/* Public interface. */ - -/* By default it simply uses the implementation provided. - * But we can provide for debugging features by overriding them */ - -#ifndef CAIRO_MUTEX_DEBUG -typedef cairo_mutex_impl_t cairo_mutex_t; -typedef cairo_recursive_mutex_impl_t cairo_recursive_mutex_t; -#else -# define cairo_mutex_t cairo_mutex_impl_t -#endif - -#define CAIRO_MUTEX_INITIALIZE CAIRO_MUTEX_IMPL_INITIALIZE -#define CAIRO_MUTEX_FINALIZE CAIRO_MUTEX_IMPL_FINALIZE -#define CAIRO_MUTEX_LOCK CAIRO_MUTEX_IMPL_LOCK -#define CAIRO_MUTEX_UNLOCK CAIRO_MUTEX_IMPL_UNLOCK -#define CAIRO_MUTEX_INIT CAIRO_MUTEX_IMPL_INIT -#define CAIRO_MUTEX_FINI CAIRO_MUTEX_IMPL_FINI -#define CAIRO_MUTEX_NIL_INITIALIZER CAIRO_MUTEX_IMPL_NIL_INITIALIZER - -#define CAIRO_RECURSIVE_MUTEX_INIT CAIRO_RECURSIVE_MUTEX_IMPL_INIT -#define CAIRO_RECURSIVE_MUTEX_NIL_INITIALIZER CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER - -#ifndef CAIRO_MUTEX_IS_LOCKED -# define CAIRO_MUTEX_IS_LOCKED(name) 1 -#endif -#ifndef CAIRO_MUTEX_IS_UNLOCKED -# define CAIRO_MUTEX_IS_UNLOCKED(name) 1 -#endif - - -/* Debugging support */ - -#ifdef CAIRO_MUTEX_DEBUG - -/* TODO add mutex debugging facilities here (eg deadlock detection) */ - -#endif /* CAIRO_MUTEX_DEBUG */ - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex.c deleted file mode 100644 index 0a31dced3e1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-mutex.c +++ /dev/null @@ -1,82 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Mathias Hasselmann - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Mathias Hasselmann - */ - -#include "cairoint.h" - -#include "cairo-mutex-private.h" - -#define CAIRO_MUTEX_DECLARE(mutex) cairo_mutex_t mutex = CAIRO_MUTEX_NIL_INITIALIZER; -#include "cairo-mutex-list-private.h" -#undef CAIRO_MUTEX_DECLARE - -#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER - -# if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER -# define _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE FALSE -# else -# define _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE TRUE -# endif - -cairo_bool_t _cairo_mutex_initialized = _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE; - -# undef _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE - -#endif - -#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER -void _cairo_mutex_initialize (void) -{ - if (_cairo_mutex_initialized) - return; - - _cairo_mutex_initialized = TRUE; - -#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (mutex); -#include "cairo-mutex-list-private.h" -#undef CAIRO_MUTEX_DECLARE -} -#endif - -#if _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER -void _cairo_mutex_finalize (void) -{ - if (!_cairo_mutex_initialized) - return; - - _cairo_mutex_initialized = FALSE; - -#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_FINI (mutex); -#include "cairo-mutex-list-private.h" -#undef CAIRO_MUTEX_DECLARE -} -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-no-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-no-compositor.c deleted file mode 100644 index 1602a12f63a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-no-compositor.c +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-compositor-private.h" - -static cairo_int_status_t -_cairo_no_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_no_compositor_mask (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents) -{ - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_no_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_no_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_no_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -const cairo_compositor_t __cairo_no_compositor = { - NULL, - _cairo_no_compositor_paint, - _cairo_no_compositor_mask, - _cairo_no_compositor_stroke, - _cairo_no_compositor_fill, - _cairo_no_compositor_glyphs, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-observer.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-observer.c deleted file mode 100644 index 36d6b93bd63..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-observer.c +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2010 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-list-inline.h" - -void -_cairo_observers_notify (cairo_list_t *observers, void *arg) -{ - cairo_observer_t *obs, *next; - - cairo_list_foreach_entry_safe (obs, next, - cairo_observer_t, - observers, link) - { - obs->callback (obs, arg); - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-private.h deleted file mode 100644 index 829dd3c8d41..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-private.h +++ /dev/null @@ -1,67 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* cairo - a vector graphics library with display and print output - * - * Copyright (c) 2005-2006 netlabs.org - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is - * Doodle - * - * Contributor(s): - * Peter Weilbacher - */ - -#ifndef CAIRO_OS2_PRIVATE_H -#define CAIRO_OS2_PRIVATE_H - -#include "cairo-os2.h" -#include "cairoint.h" - -typedef struct _cairo_os2_surface -{ - cairo_surface_t base; - - /* Mutex semaphore to protect private fields from concurrent access */ - HMTX hmtx_use_private_fields; - /* Private fields: */ - HPS hps_client_window; - HWND hwnd_client_window; - BITMAPINFO2 bitmap_info; - unsigned char *pixels; - cairo_image_surface_t *image_surface; - int pixel_array_lend_count; - HEV hev_pixel_array_came_back; - - RECTL rcl_dirty_area; - cairo_bool_t dirty_area_present; - - /* General flags: */ - cairo_bool_t blit_as_changes; - cairo_bool_t use_24bpp; -} cairo_os2_surface_t; - -#endif /* CAIRO_OS2_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-surface.c deleted file mode 100644 index 1ab50f97798..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2-surface.c +++ /dev/null @@ -1,1415 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* cairo - a vector graphics library with display and print output - * - * Copyright (c) 2005-2006 netlabs.org - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is - * Doodle - * - * Contributor(s): - * Peter Weilbacher - * Rich Walsh - */ - -#include "cairoint.h" - -#include "cairo-os2-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-surface-fallback-private.h" -#include "cairo-image-surface-private.h" - -#if CAIRO_HAS_FC_FONT -#include -#endif - -#include -#ifdef BUILD_CAIRO_DLL -# include "cairo-os2.h" -# ifndef __WATCOMC__ -# include -# endif -#endif - -/* - * Here comes the extra API for the OS/2 platform. Currently it consists - * of two extra functions, the cairo_os2_init() and the - * cairo_os2_fini(). Both of them are called automatically if - * Cairo is compiled to be a DLL file, but you have to call them before - * using the Cairo API if you link to Cairo statically! - * - * You'll also find the code in here which deals with DLL initialization - * and termination, if the code is built to be a DLL. - * (if BUILD_CAIRO_DLL is defined) - */ - -/* Initialization counter: */ -static int cairo_os2_initialization_count = 0; - -static inline void -DisableFPUException (void) -{ - unsigned short usCW; - - /* Some OS/2 PM API calls modify the FPU Control Word, - * but forget to restore it. - * - * This can result in XCPT_FLOAT_INVALID_OPCODE exceptions, - * so to be sure, we disable Invalid Opcode FPU exception - * before using FPU stuffs. - */ - usCW = _control87 (0, 0); - usCW = usCW | EM_INVALID | 0x80; - _control87 (usCW, MCW_EM | 0x80); -} - -/** - * cairo_os2_init: - * - * Initializes the Cairo library. This function is automatically called if - * Cairo was compiled to be a DLL (however it's not a problem if it's called - * multiple times). But if you link to Cairo statically, you have to call it - * once to set up Cairo's internal structures and mutexes. - * - * Since: 1.4 - **/ -cairo_public void -cairo_os2_init (void) -{ - /* This may initialize some stuffs, like create mutex semaphores etc.. */ - - cairo_os2_initialization_count++; - if (cairo_os2_initialization_count > 1) return; - - DisableFPUException (); - -#if CAIRO_HAS_FC_FONT - /* Initialize FontConfig */ - FcInit (); -#endif - - CAIRO_MUTEX_INITIALIZE (); -} - -/** - * cairo_os2_fini: - * - * Uninitializes the Cairo library. This function is automatically called if - * Cairo was compiled to be a DLL (however it's not a problem if it's called - * multiple times). But if you link to Cairo statically, you have to call it - * once to shut down Cairo, to let it free all the resources it has allocated. - * - * Since: 1.4 - **/ -cairo_public void -cairo_os2_fini (void) -{ - /* This has to uninitialize some stuffs, like destroy mutex semaphores etc.. */ - - if (cairo_os2_initialization_count <= 0) return; - cairo_os2_initialization_count--; - if (cairo_os2_initialization_count > 0) return; - - DisableFPUException (); - - cairo_debug_reset_static_data (); - -#if CAIRO_HAS_FC_FONT -# if HAVE_FCFINI - /* Uninitialize FontConfig */ - FcFini (); -# endif -#endif - -#ifdef __WATCOMC__ - /* It can happen that the libraries we use have memory leaks, - * so there are still memory chunks allocated at this point. - * In these cases, Watcom might still have a bigger memory chunk, - * called "the heap" allocated from the OS. - * As we want to minimize the memory we lose from the point of - * view of the OS, we call this function to shrink that heap - * as much as possible. - */ - _heapshrink (); -#else - /* GCC has a heapmin function that approximately corresponds to - * what the Watcom function does - */ - _heapmin (); -#endif -} - -/* - * This function calls the allocation function depending on which - * method was compiled into the library: it can be native allocation - * (DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free). - * Actually, for pixel buffers that we use this function for, cairo - * uses _cairo_malloc_abc, so we use that here, too. And use the - * change to check the size argument - */ -void *_buffer_alloc (size_t a, size_t b, const unsigned int size) -{ - size_t nbytes; - void *buffer = NULL; - - if (!a || !b || !size || - a >= INT32_MAX / b || a*b >= INT32_MAX / size) { - return NULL; - } - nbytes = a * b * size; - -#ifdef OS2_USE_PLATFORM_ALLOC - /* Using OBJ_ANY on a machine that isn't configured for hi-mem - * will cause ERROR_INVALID_PARAMETER. If this occurs, or this - * build doesn't have hi-mem enabled, fall back to using lo-mem. - */ -#ifdef OS2_HIGH_MEMORY - if (!DosAllocMem (&buffer, nbytes, - OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT)) - return buffer; -#endif - if (DosAllocMem (&buffer, nbytes, - PAG_READ | PAG_WRITE | PAG_COMMIT)) - return NULL; -#else - /* Clear the malloc'd buffer the way DosAllocMem() does. */ - buffer = malloc (nbytes); - if (buffer) { - memset (buffer, 0, nbytes); - } -#endif - return buffer; -} - -/* - * This function selects the free function depending on which - * allocation method was compiled into the library - */ -void _buffer_free (void *buffer) -{ -#ifdef OS2_USE_PLATFORM_ALLOC - DosFreeMem (buffer); -#else - free (buffer); -#endif -} - -/* XXX - * The cairo_os2_ini() and cairo_os2_fini() functions should be removed and - * the LibMain code moved to cairo-system.c. It should also call - * cairo_debug_reset_static_data() instead of duplicating its logic... - */ - -#ifdef BUILD_CAIRO_DLL -/* The main DLL entry for DLL initialization and uninitialization */ -/* Only include this code if we're about to build a DLL. */ - -#ifdef __WATCOMC__ -unsigned _System -LibMain (unsigned hmod, - unsigned termination) -#else -unsigned long _System -_DLL_InitTerm (unsigned long hModule, - unsigned long termination) -#endif -{ - if (termination) { - /* Unloading the DLL */ - cairo_os2_fini (); - -#ifndef __WATCOMC__ - /* Uninitialize RTL of GCC */ - __ctordtorTerm (); - _CRT_term (); -#endif - return 1; - } else { - /* Loading the DLL */ -#ifndef __WATCOMC__ - /* Initialize RTL of GCC */ - if (_CRT_init () != 0) - return 0; - __ctordtorInit (); -#endif - - cairo_os2_init (); - return 1; - } -} - -#endif /* BUILD_CAIRO_DLL */ - -/* - * The following part of the source file contains the code which might - * be called the "core" of the OS/2 backend support. This contains the - * OS/2 surface support functions and structures. - */ - -/* Forward declaration */ -static const cairo_surface_backend_t cairo_os2_surface_backend; - -/* Unpublished API: - * GpiEnableYInversion = PMGPI.723 - * GpiQueryYInversion = PMGPI.726 - * BOOL APIENTRY GpiEnableYInversion (HPS hps, LONG lHeight); - * LONG APIENTRY GpiQueryYInversion (HPS hps); - */ -BOOL APIENTRY GpiEnableYInversion (HPS hps, LONG lHeight); -LONG APIENTRY GpiQueryYInversion (HPS hps); - -#ifdef __WATCOMC__ -/* Function declaration for GpiDrawBits () (missing from OpenWatcom headers) */ -LONG APIENTRY GpiDrawBits (HPS hps, - PVOID pBits, - PBITMAPINFO2 pbmiInfoTable, - LONG lCount, - PPOINTL aptlPoints, - LONG lRop, - ULONG flOptions); -#endif - -static void -_cairo_os2_surface_blit_pixels (cairo_os2_surface_t *surface, - HPS hps_begin_paint, - PRECTL prcl_begin_paint_rect) -{ - POINTL aptlPoints[4]; - LONG lOldYInversion; - LONG rc = GPI_OK; - - /* Check the limits (may not be necessary) */ - if (prcl_begin_paint_rect->xLeft < 0) - prcl_begin_paint_rect->xLeft = 0; - if (prcl_begin_paint_rect->yBottom < 0) - prcl_begin_paint_rect->yBottom = 0; - if (prcl_begin_paint_rect->xRight > (LONG) surface->bitmap_info.cx) - prcl_begin_paint_rect->xRight = (LONG) surface->bitmap_info.cx; - if (prcl_begin_paint_rect->yTop > (LONG) surface->bitmap_info.cy) - prcl_begin_paint_rect->yTop = (LONG) surface->bitmap_info.cy; - - /* Exit if the rectangle is empty */ - if (prcl_begin_paint_rect->xLeft >= prcl_begin_paint_rect->xRight || - prcl_begin_paint_rect->yBottom >= prcl_begin_paint_rect->yTop) - return; - - /* Set the Target & Source coordinates */ - *((PRECTL)&aptlPoints[0]) = *prcl_begin_paint_rect; - *((PRECTL)&aptlPoints[2]) = *prcl_begin_paint_rect; - - /* Make the Target coordinates non-inclusive */ - aptlPoints[1].x -= 1; - aptlPoints[1].y -= 1; - - /* Enable Y Inversion for the HPS, so GpiDrawBits will - * work with upside-top image, not with upside-down image! - */ - lOldYInversion = GpiQueryYInversion (hps_begin_paint); - GpiEnableYInversion (hps_begin_paint, surface->bitmap_info.cy-1); - - /* Debug code to draw rectangle limits */ -#if 0 - { - int x, y; - unsigned char *pixels; - - pixels = surface->pixels; - for (x = 0; x < surface->bitmap_info.cx; x++) { - for (y = 0; y < surface->bitmap_info.cy; y++) { - if ((x == 0) || - (y == 0) || - (x == y) || - (x >= surface->bitmap_info.cx-1) || - (y >= surface->bitmap_info.cy-1)) - { - pixels[y*surface->bitmap_info.cx*4+x*4] = 255; - } - } - } - } -#endif - if (!surface->use_24bpp) { - rc = GpiDrawBits (hps_begin_paint, - surface->pixels, - &(surface->bitmap_info), - 4, - aptlPoints, - ROP_SRCCOPY, - BBO_IGNORE); - if (rc != GPI_OK) - surface->use_24bpp = TRUE; - } - - if (surface->use_24bpp) { - /* If GpiDrawBits () failed then this is most likely because the - * display driver could not handle a 32bit bitmap. So we need to - * - create a buffer that only contains 3 bytes per pixel - * - change the bitmap info header to contain 24bit - * - pass the new buffer to GpiDrawBits () again - * - clean up the new buffer - */ - BITMAPINFO2 bmpinfo; - unsigned char *pchPixBuf; - unsigned char *pchTarget; - ULONG *pulSource; - ULONG ulX; - ULONG ulY; - ULONG ulPad; - - /* Set up the bitmap header, but this time for 24bit depth. */ - bmpinfo = surface->bitmap_info; - bmpinfo.cBitCount = 24; - - /* The start of each row has to be DWORD aligned. Calculate the - * of number aligned bytes per row, the total size of the bitmap, - * and the number of padding bytes at the end of each row. - */ - ulX = (((bmpinfo.cx * bmpinfo.cBitCount) + 31) / 32) * 4; - bmpinfo.cbImage = ulX * bmpinfo.cy; - ulPad = ulX - bmpinfo.cx * 3; - - /* Allocate temporary pixel buffer. If the rows don't need - * padding, it has to be 1 byte larger than the size of the - * bitmap or else the high-order byte from the last source - * row will end up in unallocated memory. - */ - pchPixBuf = (unsigned char *)_buffer_alloc (1, 1, - bmpinfo.cbImage + (ulPad ? 0 : 1)); - - if (pchPixBuf) { - /* Copy 4 bytes from the source but advance the target ptr only - * 3 bytes, so the high-order alpha byte will be overwritten by - * the next copy. At the end of each row, skip over the padding. - */ - pchTarget = pchPixBuf; - pulSource = (ULONG*)surface->pixels; - for (ulY = bmpinfo.cy; ulY; ulY--) { - for (ulX = bmpinfo.cx; ulX; ulX--) { - *((ULONG*)pchTarget) = *pulSource++; - pchTarget += 3; - } - pchTarget += ulPad; - } - - rc = GpiDrawBits (hps_begin_paint, - pchPixBuf, - &bmpinfo, - 4, - aptlPoints, - ROP_SRCCOPY, - BBO_IGNORE); - if (rc != GPI_OK) - surface->use_24bpp = FALSE; - - _buffer_free (pchPixBuf); - } - } - - /* Restore Y inversion */ - GpiEnableYInversion (hps_begin_paint, lOldYInversion); -} - -static void -_cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface, - HPS hps_begin_paint, - PRECTL prcl_begin_paint_rect) -{ - HPS hps; - HDC hdc; - SIZEL sizlTemp; - HBITMAP hbmpTemp; - BITMAPINFO2 bmi2Temp; - POINTL aptlPoints[4]; - int y; - unsigned char *pchTemp; - - /* To copy pixels from screen to our buffer, we do the following steps: - * - * - Blit pixels from screen to a HBITMAP: - * -- Create Memory Device Context - * -- Create a PS into it - * -- Create a HBITMAP - * -- Select HBITMAP into memory PS - * -- Blit dirty pixels from screen to HBITMAP - * - Copy HBITMAP lines (pixels) into our buffer - * - Free resources - */ - - /* Create a memory device context */ - hdc = DevOpenDC (0, OD_MEMORY,"*",0L, NULL, NULLHANDLE); - if (!hdc) { - return; - } - - /* Create a memory PS */ - sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft; - sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom; - hps = GpiCreatePS (0, - hdc, - &sizlTemp, - PU_PELS | GPIT_NORMAL | GPIA_ASSOC); - if (!hps) { - DevCloseDC (hdc); - return; - } - - /* Create an uninitialized bitmap. */ - /* Prepare BITMAPINFO2 structure for our buffer */ - memset (&bmi2Temp, 0, sizeof (bmi2Temp)); - bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2); - bmi2Temp.cx = sizlTemp.cx; - bmi2Temp.cy = sizlTemp.cy; - bmi2Temp.cPlanes = 1; - bmi2Temp.cBitCount = 32; - - hbmpTemp = GpiCreateBitmap (hps, - (PBITMAPINFOHEADER2) &bmi2Temp, - 0, - NULL, - NULL); - - if (!hbmpTemp) { - GpiDestroyPS (hps); - DevCloseDC (hdc); - return; - } - - /* Select the bitmap into the memory device context. */ - GpiSetBitmap (hps, hbmpTemp); - - /* Target coordinates (Noninclusive) */ - aptlPoints[0].x = 0; - aptlPoints[0].y = 0; - - aptlPoints[1].x = sizlTemp.cx; - aptlPoints[1].y = sizlTemp.cy; - - /* Source coordinates (Inclusive) */ - aptlPoints[2].x = prcl_begin_paint_rect->xLeft; - aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom; - - aptlPoints[3].x = prcl_begin_paint_rect->xRight; - aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop; - - /* Blit pixels from screen to bitmap */ - GpiBitBlt (hps, - hps_begin_paint, - 4, - aptlPoints, - ROP_SRCCOPY, - BBO_IGNORE); - - /* Now we have to extract the pixels from the bitmap. */ - pchTemp = - surface->pixels + - (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 + - prcl_begin_paint_rect->xLeft*4; - for (y = 0; y < sizlTemp.cy; y++) { - /* Get one line of pixels */ - GpiQueryBitmapBits (hps, - sizlTemp.cy - y - 1, /* lScanStart */ - 1, /* lScans */ - (PBYTE)pchTemp, - &bmi2Temp); - - /* Go for next line */ - pchTemp += surface->bitmap_info.cx*4; - } - - /* Clean up resources */ - GpiSetBitmap (hps, (HBITMAP) NULL); - GpiDeleteBitmap (hbmpTemp); - GpiDestroyPS (hps); - DevCloseDC (hdc); -} - -static cairo_status_t -_cairo_os2_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; - - DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); - - /* Increase lend counter */ - surface->pixel_array_lend_count++; - - *image_out = surface->image_surface; - *image_extra = NULL; - - DosReleaseMutexSem (surface->hmtx_use_private_fields); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_os2_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; - - /* Decrease Lend counter! */ - DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); - - if (surface->pixel_array_lend_count > 0) - surface->pixel_array_lend_count--; - DosPostEventSem (surface->hev_pixel_array_came_back); - - DosReleaseMutexSem (surface->hmtx_use_private_fields); -} - -static cairo_image_surface_t * -_cairo_os2_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; - - DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); - /* Increase lend counter */ - surface->pixel_array_lend_count++; - DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); - - /* XXX: BROKEN! */ - *image_out = _cairo_surface_create_for_rectangle_int (surface->image_surface, - extents); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_os2_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; - - /* So, we got back the image, and if all goes well, then - * something has been changed inside the interest_rect. - * So, we blit it to the screen! - */ - if (surface->blit_as_changes) { - RECTL rclToBlit; - - /* Get mutex, we'll work with the pixel array! */ - if (DosRequestMutexSem (surface->hmtx_use_private_fields, - SEM_INDEFINITE_WAIT) != NO_ERROR) - { - /* Could not get mutex! */ - return; - } - - rclToBlit.xLeft = image->base.device_transform_inverse.x0; - rclToBlit.xRight = rclToBlit.xLeft + image->width; /* Noninclusive */ - rclToBlit.yTop = image->base.device_transform_inverse.y0; - rclToBlit.yBottom = rclToBlit.yTop + image->height; /* Noninclusive */ - - if (surface->hwnd_client_window) { - /* We know the HWND, so let's invalidate the window region, - * so the application will redraw itself, using the - * cairo_os2_surface_refresh_window () API from its own PM thread. - * - * This is the safe method, which should be preferred every time. - */ - rclToBlit.yTop = surface->bitmap_info.cy - rclToBlit.yTop; - rclToBlit.yBottom = surface->bitmap_info.cy - rclToBlit.yTop; - WinInvalidateRect (surface->hwnd_client_window, - &rclToBlit, - FALSE); - } else { - /* We don't know the HWND, so try to blit the pixels from here! - * Please note that it can be problematic if this is not the PM thread! - * - * It can cause internal PM stuffs to be screwed up, for some reason. - * Please always tell the HWND to the surface using the - * cairo_os2_surface_set_hwnd () API, and call cairo_os2_surface_refresh_window () - * from your WM_PAINT, if it's possible! - */ - _cairo_os2_surface_blit_pixels (surface, - surface->hps_client_window, - &rclToBlit); - } - - DosReleaseMutexSem (surface->hmtx_use_private_fields); - } - /* Also decrease Lend counter! */ - DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); - - if (surface->pixel_array_lend_count > 0) - surface->pixel_array_lend_count--; - DosPostEventSem (surface->hev_pixel_array_came_back); - - DosReleaseMutexSem (surface->hmtx_use_private_fields); -} - -static cairo_bool_t -_cairo_os2_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - rectangle->width = surface->bitmap_info.cx; - rectangle->height = surface->bitmap_info.cy; - - return TRUE; -} - -/** - * cairo_os2_surface_create: - * @hps_client_window: the presentation handle to bind the surface to - * @width: the width of the surface - * @height: the height of the surface - * - * Create a Cairo surface which is bound to a given presentation space (HPS). - * The caller retains ownership of the HPS and must dispose of it after the - * the surface has been destroyed. The surface will be created to have the - * given size. By default every change to the surface will be made visible - * immediately by blitting it into the window. This can be changed with - * cairo_os2_surface_set_manual_window_refresh(). - * Note that the surface will contain garbage when created, so the pixels - * have to be initialized by hand first. You can use the Cairo functions to - * fill it with black, or use cairo_surface_mark_dirty() to fill the surface - * with pixels from the window/HPS. - * - * Return value: the newly created surface - * - * Since: 1.4 - **/ -cairo_surface_t * -cairo_os2_surface_create (HPS hps_client_window, - int width, - int height) -{ - cairo_os2_surface_t *local_os2_surface = 0; - cairo_status_t status; - int rc; - - /* Check the size of the window */ - if ((width <= 0) || (height <= 0)) { - status = _cairo_error (CAIRO_STATUS_INVALID_SIZE); - goto error_exit; - } - - /* Allocate an OS/2 surface structure. */ - local_os2_surface = (cairo_os2_surface_t *) malloc (sizeof (cairo_os2_surface_t)); - if (!local_os2_surface) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto error_exit; - } - - memset(local_os2_surface, 0, sizeof(cairo_os2_surface_t)); - - /* Allocate resources: mutex & event semaphores and the pixel buffer */ - if (DosCreateMutexSem (NULL, - &(local_os2_surface->hmtx_use_private_fields), - 0, - FALSE)) - { - status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - goto error_exit; - } - - if (DosCreateEventSem (NULL, - &(local_os2_surface->hev_pixel_array_came_back), - 0, - FALSE)) - { - status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); - goto error_exit; - } - - local_os2_surface->pixels = (unsigned char *) _buffer_alloc (height, width, 4); - if (!local_os2_surface->pixels) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto error_exit; - } - - /* Create image surface from pixel array */ - local_os2_surface->image_surface = (cairo_image_surface_t *) - cairo_image_surface_create_for_data (local_os2_surface->pixels, - CAIRO_FORMAT_ARGB32, - width, /* Width */ - height, /* Height */ - width * 4); /* Rowstride */ - status = local_os2_surface->image_surface->base.status; - if (status) - goto error_exit; - - /* Set values for OS/2-specific data that aren't zero/NULL/FALSE. - * Note: hps_client_window may be null if this was called by - * cairo_os2_surface_create_for_window(). - */ - local_os2_surface->hps_client_window = hps_client_window; - local_os2_surface->blit_as_changes = TRUE; - - /* Prepare BITMAPINFO2 structure for our buffer */ - local_os2_surface->bitmap_info.cbFix = sizeof (BITMAPINFOHEADER2); - local_os2_surface->bitmap_info.cx = width; - local_os2_surface->bitmap_info.cy = height; - local_os2_surface->bitmap_info.cPlanes = 1; - local_os2_surface->bitmap_info.cBitCount = 32; - - /* Initialize base surface */ - _cairo_surface_init (&local_os2_surface->base, - &cairo_os2_surface_backend, - NULL, /* device */ - _cairo_content_from_format (CAIRO_FORMAT_ARGB32)); - - /* Successful exit */ - return (cairo_surface_t *)local_os2_surface; - - error_exit: - - /* This point will only be reached if an error occurred */ - - if (local_os2_surface) { - if (local_os2_surface->pixels) - _buffer_free (local_os2_surface->pixels); - if (local_os2_surface->hev_pixel_array_came_back) - DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); - if (local_os2_surface->hmtx_use_private_fields) - DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); - free (local_os2_surface); - } - - return _cairo_surface_create_in_error (status); -} - -/** - * cairo_os2_surface_create_for_window: - * @hwnd_client_window: the window handle to bind the surface to - * @width: the width of the surface - * @height: the height of the surface - * - * Create a Cairo surface which is bound to a given window; the caller retains - * ownership of the window. This is a convenience function for use with - * windows that will only be updated when cairo_os2_surface_refresh_window() - * is called (usually in response to a WM_PAINT message). It avoids the need - * to create a persistent HPS for every window and assumes that one will be - * supplied by the caller when a cairo function needs one. If it isn't, an - * HPS will be created on-the-fly and released before the function which needs - * it returns. - * - * Return value: the newly created surface - * - * Since: 1.10 - **/ -cairo_surface_t * -cairo_os2_surface_create_for_window (HWND hwnd_client_window, - int width, - int height) -{ - cairo_os2_surface_t *local_os2_surface; - - /* A window handle must be provided. */ - if (!hwnd_client_window) { - return _cairo_surface_create_in_error ( - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - /* Create the surface. */ - local_os2_surface = (cairo_os2_surface_t *) - cairo_os2_surface_create (0, width, height); - - /* If successful, save the hwnd & turn off automatic repainting. */ - if (!local_os2_surface->image_surface->base.status) { - local_os2_surface->hwnd_client_window = hwnd_client_window; - local_os2_surface->blit_as_changes = FALSE; - } - - return (cairo_surface_t *)local_os2_surface; -} - -/** - * cairo_os2_surface_set_size: - * @surface: the cairo surface to resize - * @new_width: the new width of the surface - * @new_height: the new height of the surface - * @timeout: timeout value in milliseconds - * - * When the client window is resized, call this API to set the new size in the - * underlying surface accordingly. This function will reallocate everything, - * so you'll have to redraw everything in the surface after this call. - * The surface will contain garbage after the resizing. So the notes of - * cairo_os2_surface_create() apply here, too. - * - * The timeout value specifies how long the function should wait on other parts - * of the program to release the buffers. It is necessary, because it can happen - * that Cairo is just drawing something into the surface while we want to - * destroy and recreate it. - * - * Return value: %CAIRO_STATUS_SUCCESS if the surface could be resized, - * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface, - * %CAIRO_STATUS_INVALID_SIZE for invalid sizes - * %CAIRO_STATUS_NO_MEMORY if the new size could not be allocated, or if the - * timeout happened before all the buffers were released - * - * Since: 1.4 - **/ -int -cairo_os2_surface_set_size (cairo_surface_t *surface, - int new_width, - int new_height, - int timeout) -{ - cairo_os2_surface_t *local_os2_surface; - unsigned char *pchNewPixels; - int rc; - cairo_image_surface_t *pNewImageSurface; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - } - - if ((new_width <= 0) || - (new_height <= 0)) - { - /* Invalid size! */ - return _cairo_error (CAIRO_STATUS_INVALID_SIZE); - } - - /* Allocate memory for new stuffs */ - pchNewPixels = (unsigned char *) _buffer_alloc (new_height, new_width, 4); - if (!pchNewPixels) { - /* Not enough memory for the pixels! - * Everything remains the same! - */ - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* Create image surface from new pixel array */ - pNewImageSurface = (cairo_image_surface_t *) - cairo_image_surface_create_for_data (pchNewPixels, - CAIRO_FORMAT_ARGB32, - new_width, /* Width */ - new_height, /* Height */ - new_width * 4); /* Rowstride */ - - if (pNewImageSurface->base.status) { - /* Could not create image surface! - * Everything remains the same! - */ - _buffer_free (pchNewPixels); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* Okay, new memory allocated, so it's time to swap old buffers - * to new ones! - */ - if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)!=NO_ERROR) { - /* Could not get mutex! - * Everything remains the same! - */ - cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface); - _buffer_free (pchNewPixels); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* We have to make sure that we won't destroy a surface which - * is lent to some other code (Cairo is drawing into it)! - */ - while (local_os2_surface->pixel_array_lend_count > 0) { - ULONG ulPostCount; - DosResetEventSem (local_os2_surface->hev_pixel_array_came_back, &ulPostCount); - DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); - /* Wait for somebody to return the pixels! */ - rc = DosWaitEventSem (local_os2_surface->hev_pixel_array_came_back, timeout); - if (rc != NO_ERROR) { - /* Either timeout or something wrong... Exit. */ - cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface); - _buffer_free (pchNewPixels); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - /* Okay, grab mutex and check counter again! */ - if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) - != NO_ERROR) - { - /* Could not get mutex! - * Everything remains the same! - */ - cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface); - _buffer_free (pchNewPixels); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - /* Destroy old image surface */ - cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface)); - /* Destroy old pixel buffer */ - _buffer_free (local_os2_surface->pixels); - /* Set new image surface */ - local_os2_surface->image_surface = pNewImageSurface; - /* Set new pixel buffer */ - local_os2_surface->pixels = pchNewPixels; - /* Change bitmap2 structure */ - local_os2_surface->bitmap_info.cx = new_width; - local_os2_surface->bitmap_info.cy = new_height; - - DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_os2_surface_refresh_window: - * @surface: the cairo surface to refresh - * @hps_begin_paint: the presentation handle of the window to refresh - * @prcl_begin_paint_rect: the rectangle to redraw - * - * This function can be used to force a repaint of a given area of the client - * window. It should usually be called from the WM_PAINT processing of the - * window procedure. However, it can be called any time a given part of the - * window has to be updated. - * - * The HPS and RECTL to be passed can be taken from the usual WinBeginPaint call - * of the window procedure, but you can also get the HPS using WinGetPS, and you - * can assemble your own update rectangle by hand. - * If hps_begin_paint is %NULL, the function will use the HPS passed into - * cairo_os2_surface_create(). If @prcl_begin_paint_rect is %NULL, the function - * will query the current window size and repaint the whole window. - * - * Cairo assumes that if you set the HWND to the surface using - * cairo_os2_surface_set_hwnd(), this function will be called by the application - * every time it gets a WM_PAINT for that HWND. If the HWND is set in the - * surface, Cairo uses this function to handle dirty areas too. - * - * Since: 1.4 - **/ -void -cairo_os2_surface_refresh_window (cairo_surface_t *surface, - HPS hps_begin_paint, - PRECTL prcl_begin_paint_rect) -{ - cairo_os2_surface_t *local_os2_surface; - RECTL rclTemp; - HPS hpsTemp = 0; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return; - } - - /* If an HPS wasn't provided, see if we can get one. */ - if (!hps_begin_paint) { - hps_begin_paint = local_os2_surface->hps_client_window; - if (!hps_begin_paint) { - if (local_os2_surface->hwnd_client_window) { - hpsTemp = WinGetPS(local_os2_surface->hwnd_client_window); - hps_begin_paint = hpsTemp; - } - /* No HPS & no way to get one, so exit */ - if (!hps_begin_paint) - return; - } - } - - if (prcl_begin_paint_rect == NULL) { - /* Update the whole window! */ - rclTemp.xLeft = 0; - rclTemp.xRight = local_os2_surface->bitmap_info.cx; - rclTemp.yTop = local_os2_surface->bitmap_info.cy; - rclTemp.yBottom = 0; - } else { - /* Use the rectangle we got passed as parameter! */ - rclTemp.xLeft = prcl_begin_paint_rect->xLeft; - rclTemp.xRight = prcl_begin_paint_rect->xRight; - rclTemp.yTop = local_os2_surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom; - rclTemp.yBottom = local_os2_surface->bitmap_info.cy - prcl_begin_paint_rect->yTop ; - } - - /* Get mutex, we'll work with the pixel array! */ - if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) - != NO_ERROR) - { - /* Could not get mutex! */ - if (hpsTemp) - WinReleasePS(hpsTemp); - return; - } - - if ((local_os2_surface->dirty_area_present) && - (local_os2_surface->rcl_dirty_area.xLeft == rclTemp.xLeft) && - (local_os2_surface->rcl_dirty_area.xRight == rclTemp.xRight) && - (local_os2_surface->rcl_dirty_area.yTop == rclTemp.yTop) && - (local_os2_surface->rcl_dirty_area.yBottom == rclTemp.yBottom)) - { - /* Aha, this call was because of a dirty area, so in this case we - * have to blit the pixels from the screen to the surface! - */ - local_os2_surface->dirty_area_present = FALSE; - _cairo_os2_surface_get_pixels_from_screen (local_os2_surface, - hps_begin_paint, - &rclTemp); - } else { - /* Okay, we have the surface, have the HPS - * (might be from WinBeginPaint () or from WinGetPS () ) - * Now blit there the stuffs! - */ - _cairo_os2_surface_blit_pixels (local_os2_surface, - hps_begin_paint, - &rclTemp); - } - - DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); - - if (hpsTemp) - WinReleasePS(hpsTemp); -} - -static cairo_status_t -_cairo_os2_surface_finish (void *abstract_surface) -{ - cairo_os2_surface_t *local_os2_surface; - - local_os2_surface = (cairo_os2_surface_t *) abstract_surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - } - - DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); - - /* Destroy old image surface */ - cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface)); - /* Destroy old pixel buffer */ - _buffer_free (local_os2_surface->pixels); - DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); - DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); - - /* The memory itself will be free'd by the cairo_surface_destroy () - * who called us. - */ - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_os2_surface_set_hwnd: - * @surface: the cairo surface to associate with the window handle - * @hwnd_client_window: the window handle of the client window - * - * Sets window handle for surface; the caller retains ownership of the window. - * If Cairo wants to blit into the window because it is set to blit as the - * surface changes (see cairo_os2_surface_set_manual_window_refresh()), then - * there are two ways it can choose: - * If it knows the HWND of the surface, then it invalidates that area, so the - * application will get a WM_PAINT message and it can call - * cairo_os2_surface_refresh_window() to redraw that area. Otherwise cairo itself - * will use the HPS it got at surface creation time, and blit the pixels itself. - * It's also a solution, but experience shows that if this happens from a non-PM - * thread, then it can screw up PM internals. - * - * So, best solution is to set the HWND for the surface after the surface - * creation, so every blit will be done from application's message processing - * loop, which is the safest way to do. - * - * Since: 1.4 - **/ -void -cairo_os2_surface_set_hwnd (cairo_surface_t *surface, - HWND hwnd_client_window) -{ - cairo_os2_surface_t *local_os2_surface; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return; - } - - if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) - != NO_ERROR) - { - /* Could not get mutex! */ - return; - } - - local_os2_surface->hwnd_client_window = hwnd_client_window; - - DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); -} - -/** - * cairo_os2_surface_set_manual_window_refresh: - * @surface: the cairo surface to set the refresh mode for - * @manual_refresh: the switch for manual surface refresh - * - * This API can tell Cairo if it should show every change to this surface - * immediately in the window or if it should be cached and will only be visible - * once the user calls cairo_os2_surface_refresh_window() explicitly. If the - * HWND was not set in the cairo surface, then the HPS will be used to blit the - * graphics. Otherwise it will invalidate the given window region so the user - * will get the WM_PAINT message to redraw that area of the window. - * - * So, if you're only interested in displaying the final result after several - * drawing operations, you might get better performance if you put the surface - * into manual refresh mode by passing a true value to this function. Then call - * cairo_os2_surface_refresh() whenever desired. - * - * Since: 1.4 - **/ -void -cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface, - cairo_bool_t manual_refresh) -{ - cairo_os2_surface_t *local_os2_surface; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return; - } - - local_os2_surface->blit_as_changes = !manual_refresh; -} - -/** - * cairo_os2_surface_get_manual_window_refresh: - * @surface: the cairo surface to query the refresh mode from - * - * This space left intentionally blank. - * - * Return value: current refresh mode of the surface (true by default) - * - * Since: 1.4 - **/ -cairo_bool_t -cairo_os2_surface_get_manual_window_refresh (cairo_surface_t *surface) -{ - cairo_os2_surface_t *local_os2_surface; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return FALSE; - } - - return !(local_os2_surface->blit_as_changes); -} - -/** - * cairo_os2_surface_get_hps: - * @surface: the cairo surface to be querued - * @hps: HPS currently associated with the surface (if any) - * - * This API retrieves the HPS associated with the surface. - * - * Return value: %CAIRO_STATUS_SUCCESS if the hps could be retrieved, - * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface, - * %CAIRO_STATUS_NULL_POINTER if the hps argument is null - * - * Since: 1.10 - **/ -cairo_status_t -cairo_os2_surface_get_hps (cairo_surface_t *surface, - HPS *hps) -{ - cairo_os2_surface_t *local_os2_surface; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - } - if (!hps) - { - return _cairo_error (CAIRO_STATUS_NULL_POINTER); - } - *hps = local_os2_surface->hps_client_window; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_os2_surface_set_hps: - * @surface: the cairo surface to associate with the HPS - * @hps: new HPS to be associated with the surface (the HPS may be null) - * - * This API replaces the HPS associated with the surface with a new one. - * The caller retains ownership of the HPS and must dispose of it after - * the surface has been destroyed or it has been replaced by another - * call to this function. - * - * Return value: %CAIRO_STATUS_SUCCESS if the hps could be replaced, - * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface, - * - * Since: 1.10 - **/ -cairo_status_t -cairo_os2_surface_set_hps (cairo_surface_t *surface, - HPS hps) -{ - cairo_os2_surface_t *local_os2_surface; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - } - local_os2_surface->hps_client_window = hps; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_os2_surface_mark_dirty_rectangle (void *surface, - int x, - int y, - int width, - int height) -{ - cairo_os2_surface_t *local_os2_surface; - RECTL rclToBlit; - - local_os2_surface = (cairo_os2_surface_t *) surface; - if ((!local_os2_surface) || - (local_os2_surface->base.backend != &cairo_os2_surface_backend)) - { - /* Invalid parameter (wrong surface)! */ - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - } - - /* Get mutex, we'll work with the pixel array! */ - if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) - != NO_ERROR) - { - /* Could not get mutex! */ - return CAIRO_STATUS_NO_MEMORY; - } - - /* Check for defaults */ - if (width < 0) - width = local_os2_surface->bitmap_info.cx; - if (height < 0) - height = local_os2_surface->bitmap_info.cy; - - if (local_os2_surface->hwnd_client_window) { - /* We know the HWND, so let's invalidate the window region, - * so the application will redraw itself, using the - * cairo_os2_surface_refresh_window () API from its own PM thread. - * From that function we'll note that it's not a redraw but a - * dirty-rectangle deal stuff, so we'll handle the things from - * there. - * - * This is the safe method, which should be preferred every time. - */ - rclToBlit.xLeft = x; - rclToBlit.xRight = x + width; /* Noninclusive */ - rclToBlit.yTop = local_os2_surface->bitmap_info.cy - (y); - rclToBlit.yBottom = local_os2_surface->bitmap_info.cy - (y + height); /* Noninclusive */ - -#if 0 - if (local_os2_surface->dirty_area_present) { - /* Yikes, there is already a dirty area which should be - * cleaned up, but we'll overwrite it. Sorry. - * TODO: Something clever should be done here. - */ - } -#endif - - /* Set up dirty area reminder stuff */ - memcpy (&(local_os2_surface->rcl_dirty_area), &rclToBlit, sizeof (RECTL)); - local_os2_surface->dirty_area_present = TRUE; - - /* Invalidate window area */ - WinInvalidateRect (local_os2_surface->hwnd_client_window, - &rclToBlit, - FALSE); - } else { - /* We don't know the HWND, so try to blit the pixels from here! - * Please note that it can be problematic if this is not the PM thread! - * - * It can cause internal PM stuffs to be scewed up, for some reason. - * Please always tell the HWND to the surface using the - * cairo_os2_surface_set_hwnd () API, and call cairo_os2_surface_refresh_window () - * from your WM_PAINT, if it's possible! - */ - - rclToBlit.xLeft = x; - rclToBlit.xRight = x + width; /* Noninclusive */ - rclToBlit.yBottom = y; - rclToBlit.yTop = y + height; /* Noninclusive */ - /* Now get the pixels from the screen! */ - _cairo_os2_surface_get_pixels_from_screen (local_os2_surface, - local_os2_surface->hps_client_window, - &rclToBlit); - } - - DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); - - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t cairo_os2_surface_backend = { - CAIRO_SURFACE_TYPE_OS2, - _cairo_os2_surface_finish, - _cairo_default_context_create, - - NULL, /* create_similar */ - NULL, /* create_similar_image */ - _cairo_os2_surface_map_to_image, - _cairo_os2_surface_unmap_image, - - _cairo_surface_default_source, - _cairo_os2_surface_acquire_source_image, - _cairo_os2_surface_release_source_image, - NULL, /* snapshot */ - - _cairo_os2_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - _cairo_os2_surface_mark_dirty_rectangle, - - _cairo_surface_fallback_paint, - _cairo_surface_fallback_mask, - _cairo_surface_fallback_fill, - _cairo_surface_fallback_stroke, - NULL, /* fill/stroke */ - _cairo_surface_fallback_glyphs, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2.h deleted file mode 100644 index d23f2dec42a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-os2.h +++ /dev/null @@ -1,110 +0,0 @@ -/* vim: set sw=4 sts=4 et cin: */ -/* cairo - a vector graphics library with display and print output - * - * Copyright (c) 2005-2006 netlabs.org - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is - * Doodle - * - * Contributor(s): - * Peter Weilbacher - * Rich Walsh - */ - -#ifndef _CAIRO_OS2_H_ -#define _CAIRO_OS2_H_ - -#define INCL_DOS -#define INCL_DOSSEMAPHORES -#define INCL_DOSERRORS -#define INCL_WIN -#define INCL_GPI - -#include "cairo.h" - -#include - -CAIRO_BEGIN_DECLS - -/* The OS/2 Specific Cairo API */ - -cairo_public void -cairo_os2_init (void); - -cairo_public void -cairo_os2_fini (void); - -#if CAIRO_HAS_OS2_SURFACE - -cairo_public cairo_surface_t * -cairo_os2_surface_create (HPS hps_client_window, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_os2_surface_create_for_window (HWND hwnd_client_window, - int width, - int height); - -cairo_public void -cairo_os2_surface_set_hwnd (cairo_surface_t *surface, - HWND hwnd_client_window); - -cairo_public int -cairo_os2_surface_set_size (cairo_surface_t *surface, - int new_width, - int new_height, - int timeout); - -cairo_public void -cairo_os2_surface_refresh_window (cairo_surface_t *surface, - HPS hps_begin_paint, - PRECTL prcl_begin_paint_rect); - -cairo_public void -cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface, - cairo_bool_t manual_refresh); - -cairo_public cairo_bool_t -cairo_os2_surface_get_manual_window_refresh (cairo_surface_t *surface); - -cairo_public cairo_status_t -cairo_os2_surface_get_hps (cairo_surface_t *surface, - HPS *hps); - -cairo_public cairo_status_t -cairo_os2_surface_set_hps (cairo_surface_t *surface, - HPS hps); - -#else /* CAIRO_HAS_OS2_SURFACE */ -# error Cairo was not compiled with support for the OS/2 backend -#endif /* CAIRO_HAS_OS2_SURFACE */ - -CAIRO_END_DECLS - -#endif /* _CAIRO_OS2_H_ */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream-private.h deleted file mode 100644 index 2542646b860..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream-private.h +++ /dev/null @@ -1,201 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Author(s): - * Kristian Høgsberg - */ - -#ifndef CAIRO_OUTPUT_STREAM_PRIVATE_H -#define CAIRO_OUTPUT_STREAM_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-types-private.h" - -#include -#include -#include - -typedef cairo_status_t -(*cairo_output_stream_write_func_t) (cairo_output_stream_t *output_stream, - const unsigned char *data, - unsigned int length); - -typedef cairo_status_t -(*cairo_output_stream_flush_func_t) (cairo_output_stream_t *output_stream); - -typedef cairo_status_t -(*cairo_output_stream_close_func_t) (cairo_output_stream_t *output_stream); - -struct _cairo_output_stream { - cairo_output_stream_write_func_t write_func; - cairo_output_stream_flush_func_t flush_func; - cairo_output_stream_close_func_t close_func; - unsigned long position; - cairo_status_t status; - cairo_bool_t closed; -}; - -extern const cairo_private cairo_output_stream_t _cairo_output_stream_nil; - -cairo_private void -_cairo_output_stream_init (cairo_output_stream_t *stream, - cairo_output_stream_write_func_t write_func, - cairo_output_stream_flush_func_t flush_func, - cairo_output_stream_close_func_t close_func); - -cairo_private cairo_status_t -_cairo_output_stream_fini (cairo_output_stream_t *stream); - - -/* We already have the following declared in cairo.h: - -typedef cairo_status_t (*cairo_write_func_t) (void *closure, - const unsigned char *data, - unsigned int length); -*/ -typedef cairo_status_t (*cairo_close_func_t) (void *closure); - - -/* This function never returns %NULL. If an error occurs (NO_MEMORY) - * while trying to create the output stream this function returns a - * valid pointer to a nil output stream. - * - * Note that even with a nil surface, the close_func callback will be - * called by a call to _cairo_output_stream_close or - * _cairo_output_stream_destroy. - */ -cairo_private cairo_output_stream_t * -_cairo_output_stream_create (cairo_write_func_t write_func, - cairo_close_func_t close_func, - void *closure); - -cairo_private cairo_output_stream_t * -_cairo_output_stream_create_in_error (cairo_status_t status); - -/* Tries to flush any buffer maintained by the stream or its delegates. */ -cairo_private cairo_status_t -_cairo_output_stream_flush (cairo_output_stream_t *stream); - -/* Returns the final status value associated with this object, just - * before its last gasp. This final status value will capture any - * status failure returned by the stream's close_func as well. */ -cairo_private cairo_status_t -_cairo_output_stream_close (cairo_output_stream_t *stream); - -/* Returns the final status value associated with this object, just - * before its last gasp. This final status value will capture any - * status failure returned by the stream's close_func as well. */ -cairo_private cairo_status_t -_cairo_output_stream_destroy (cairo_output_stream_t *stream); - -cairo_private void -_cairo_output_stream_write (cairo_output_stream_t *stream, - const void *data, size_t length); - -cairo_private void -_cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, - const unsigned char *data, - size_t length); - -cairo_private void -_cairo_output_stream_vprintf (cairo_output_stream_t *stream, - const char *fmt, - va_list ap) CAIRO_PRINTF_FORMAT ( 2, 0); - -cairo_private void -_cairo_output_stream_printf (cairo_output_stream_t *stream, - const char *fmt, - ...) CAIRO_PRINTF_FORMAT (2, 3); - -/* Print matrix element values with rounding of insignificant digits. */ -cairo_private void -_cairo_output_stream_print_matrix (cairo_output_stream_t *stream, - const cairo_matrix_t *matrix); - -cairo_private long -_cairo_output_stream_get_position (cairo_output_stream_t *stream); - -cairo_private cairo_status_t -_cairo_output_stream_get_status (cairo_output_stream_t *stream); - -/* This function never returns %NULL. If an error occurs (NO_MEMORY or - * WRITE_ERROR) while trying to create the output stream this function - * returns a valid pointer to a nil output stream. - * - * Note: Even if a nil surface is returned, the caller should still - * call _cairo_output_stream_destroy (or _cairo_output_stream_close at - * least) in order to ensure that everything is properly cleaned up. - */ -cairo_private cairo_output_stream_t * -_cairo_output_stream_create_for_filename (const char *filename); - -/* This function never returns %NULL. If an error occurs (NO_MEMORY or - * WRITE_ERROR) while trying to create the output stream this function - * returns a valid pointer to a nil output stream. - * - * The caller still "owns" file and is responsible for calling fclose - * on it when finished. The stream will not do this itself. - */ -cairo_private cairo_output_stream_t * -_cairo_output_stream_create_for_file (FILE *file); - -cairo_private cairo_output_stream_t * -_cairo_memory_stream_create (void); - -cairo_private void -_cairo_memory_stream_copy (cairo_output_stream_t *base, - cairo_output_stream_t *dest); - -cairo_private int -_cairo_memory_stream_length (cairo_output_stream_t *stream); - -cairo_private cairo_status_t -_cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream, - unsigned char **data_out, - unsigned long *length_out); - -cairo_private cairo_output_stream_t * -_cairo_null_stream_create (void); - -/* cairo-base85-stream.c */ -cairo_private cairo_output_stream_t * -_cairo_base85_stream_create (cairo_output_stream_t *output); - -/* cairo-base64-stream.c */ -cairo_private cairo_output_stream_t * -_cairo_base64_stream_create (cairo_output_stream_t *output); - -/* cairo-deflate-stream.c */ -cairo_private cairo_output_stream_t * -_cairo_deflate_stream_create (cairo_output_stream_t *output); - - -#endif /* CAIRO_OUTPUT_STREAM_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream.c deleted file mode 100644 index 369a59bfba8..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-output-stream.c +++ /dev/null @@ -1,802 +0,0 @@ -/* cairo-output-stream.c: Output stream abstraction - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Author(s): - * Kristian Høgsberg - */ - -#define _BSD_SOURCE /* for snprintf() */ -#include "cairoint.h" - -#include "cairo-output-stream-private.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" -#include "cairo-compiler-private.h" - -#include -#include - -/* Numbers printed with %f are printed with this number of significant - * digits after the decimal. - */ -#define SIGNIFICANT_DIGITS_AFTER_DECIMAL 6 - -/* Numbers printed with %g are assumed to only have %CAIRO_FIXED_FRAC_BITS - * bits of precision available after the decimal point. - * - * FIXED_POINT_DECIMAL_DIGITS specifies the minimum number of decimal - * digits after the decimal point required to preserve the available - * precision. - * - * The conversion is: - * - * - * FIXED_POINT_DECIMAL_DIGITS = ceil( CAIRO_FIXED_FRAC_BITS * ln(2)/ln(10) ) - * - * - * We can replace ceil(x) with (int)(x+1) since x will never be an - * integer for any likely value of %CAIRO_FIXED_FRAC_BITS. - */ -#define FIXED_POINT_DECIMAL_DIGITS ((int)(CAIRO_FIXED_FRAC_BITS*0.301029996 + 1)) - -void -_cairo_output_stream_init (cairo_output_stream_t *stream, - cairo_output_stream_write_func_t write_func, - cairo_output_stream_flush_func_t flush_func, - cairo_output_stream_close_func_t close_func) -{ - stream->write_func = write_func; - stream->flush_func = flush_func; - stream->close_func = close_func; - stream->position = 0; - stream->status = CAIRO_STATUS_SUCCESS; - stream->closed = FALSE; -} - -cairo_status_t -_cairo_output_stream_fini (cairo_output_stream_t *stream) -{ - return _cairo_output_stream_close (stream); -} - -const cairo_output_stream_t _cairo_output_stream_nil = { - NULL, /* write_func */ - NULL, /* flush_func */ - NULL, /* close_func */ - 0, /* position */ - CAIRO_STATUS_NO_MEMORY, - FALSE /* closed */ -}; - -static const cairo_output_stream_t _cairo_output_stream_nil_write_error = { - NULL, /* write_func */ - NULL, /* flush_func */ - NULL, /* close_func */ - 0, /* position */ - CAIRO_STATUS_WRITE_ERROR, - FALSE /* closed */ -}; - -typedef struct _cairo_output_stream_with_closure { - cairo_output_stream_t base; - cairo_write_func_t write_func; - cairo_close_func_t close_func; - void *closure; -} cairo_output_stream_with_closure_t; - - -static cairo_status_t -closure_write (cairo_output_stream_t *stream, - const unsigned char *data, unsigned int length) -{ - cairo_output_stream_with_closure_t *stream_with_closure = - (cairo_output_stream_with_closure_t *) stream; - - if (stream_with_closure->write_func == NULL) - return CAIRO_STATUS_SUCCESS; - - return stream_with_closure->write_func (stream_with_closure->closure, - data, length); -} - -static cairo_status_t -closure_close (cairo_output_stream_t *stream) -{ - cairo_output_stream_with_closure_t *stream_with_closure = - (cairo_output_stream_with_closure_t *) stream; - - if (stream_with_closure->close_func != NULL) - return stream_with_closure->close_func (stream_with_closure->closure); - else - return CAIRO_STATUS_SUCCESS; -} - -cairo_output_stream_t * -_cairo_output_stream_create (cairo_write_func_t write_func, - cairo_close_func_t close_func, - void *closure) -{ - cairo_output_stream_with_closure_t *stream; - - stream = malloc (sizeof (cairo_output_stream_with_closure_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - closure_write, NULL, closure_close); - stream->write_func = write_func; - stream->close_func = close_func; - stream->closure = closure; - - return &stream->base; -} - -cairo_output_stream_t * -_cairo_output_stream_create_in_error (cairo_status_t status) -{ - cairo_output_stream_t *stream; - - /* check for the common ones */ - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - if (status == CAIRO_STATUS_WRITE_ERROR) - return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error; - - stream = malloc (sizeof (cairo_output_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (stream, NULL, NULL, NULL); - stream->status = status; - - return stream; -} - -cairo_status_t -_cairo_output_stream_flush (cairo_output_stream_t *stream) -{ - cairo_status_t status; - - if (stream->closed) - return stream->status; - - if (stream == &_cairo_output_stream_nil || - stream == &_cairo_output_stream_nil_write_error) - { - return stream->status; - } - - if (stream->flush_func) { - status = stream->flush_func (stream); - /* Don't overwrite a pre-existing status failure. */ - if (stream->status == CAIRO_STATUS_SUCCESS) - stream->status = status; - } - - return stream->status; -} - -cairo_status_t -_cairo_output_stream_close (cairo_output_stream_t *stream) -{ - cairo_status_t status; - - if (stream->closed) - return stream->status; - - if (stream == &_cairo_output_stream_nil || - stream == &_cairo_output_stream_nil_write_error) - { - return stream->status; - } - - if (stream->close_func) { - status = stream->close_func (stream); - /* Don't overwrite a pre-existing status failure. */ - if (stream->status == CAIRO_STATUS_SUCCESS) - stream->status = status; - } - - stream->closed = TRUE; - - return stream->status; -} - -cairo_status_t -_cairo_output_stream_destroy (cairo_output_stream_t *stream) -{ - cairo_status_t status; - - assert (stream != NULL); - - if (stream == &_cairo_output_stream_nil || - stream == &_cairo_output_stream_nil_write_error) - { - return stream->status; - } - - status = _cairo_output_stream_fini (stream); - free (stream); - - return status; -} - -void -_cairo_output_stream_write (cairo_output_stream_t *stream, - const void *data, size_t length) -{ - if (length == 0) - return; - - if (stream->status) - return; - - stream->status = stream->write_func (stream, data, length); - stream->position += length; -} - -void -_cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, - const unsigned char *data, - size_t length) -{ - const char hex_chars[] = "0123456789abcdef"; - char buffer[2]; - unsigned int i, column; - - if (stream->status) - return; - - for (i = 0, column = 0; i < length; i++, column++) { - if (column == 38) { - _cairo_output_stream_write (stream, "\n", 1); - column = 0; - } - buffer[0] = hex_chars[(data[i] >> 4) & 0x0f]; - buffer[1] = hex_chars[data[i] & 0x0f]; - _cairo_output_stream_write (stream, buffer, 2); - } -} - -/* Format a double in a locale independent way and trim trailing - * zeros. Based on code from Alex Larson . - * http://mail.gnome.org/archives/gtk-devel-list/2001-October/msg00087.html - * - * The code in the patch is copyright Red Hat, Inc under the LGPL, but - * has been relicensed under the LGPL/MPL dual license for inclusion - * into cairo (see COPYING). -- Kristian Høgsberg - */ -static void -_cairo_dtostr (char *buffer, size_t size, double d, cairo_bool_t limited_precision) -{ - const char *decimal_point; - int decimal_point_len; - char *p; - int decimal_len; - int num_zeros, decimal_digits; - - /* Omit the minus sign from negative zero. */ - if (d == 0.0) - d = 0.0; - - decimal_point = cairo_get_locale_decimal_point (); - decimal_point_len = strlen (decimal_point); - - assert (decimal_point_len != 0); - - if (limited_precision) { - snprintf (buffer, size, "%.*f", FIXED_POINT_DECIMAL_DIGITS, d); - } else { - /* Using "%f" to print numbers less than 0.1 will result in - * reduced precision due to the default 6 digits after the - * decimal point. - * - * For numbers is < 0.1, we print with maximum precision and count - * the number of zeros between the decimal point and the first - * significant digit. We then print the number again with the - * number of decimal places that gives us the required number of - * significant digits. This ensures the number is correctly - * rounded. - */ - if (fabs (d) >= 0.1) { - snprintf (buffer, size, "%f", d); - } else { - snprintf (buffer, size, "%.18f", d); - p = buffer; - - if (*p == '+' || *p == '-') - p++; - - while (_cairo_isdigit (*p)) - p++; - - if (strncmp (p, decimal_point, decimal_point_len) == 0) - p += decimal_point_len; - - num_zeros = 0; - while (*p++ == '0') - num_zeros++; - - decimal_digits = num_zeros + SIGNIFICANT_DIGITS_AFTER_DECIMAL; - - if (decimal_digits < 18) - snprintf (buffer, size, "%.*f", decimal_digits, d); - } - } - p = buffer; - - if (*p == '+' || *p == '-') - p++; - - while (_cairo_isdigit (*p)) - p++; - - if (strncmp (p, decimal_point, decimal_point_len) == 0) { - *p = '.'; - decimal_len = strlen (p + decimal_point_len); - memmove (p + 1, p + decimal_point_len, decimal_len); - p[1 + decimal_len] = 0; - - /* Remove trailing zeros and decimal point if possible. */ - for (p = p + decimal_len; *p == '0'; p--) - *p = 0; - - if (*p == '.') { - *p = 0; - p--; - } - } -} - -enum { - LENGTH_MODIFIER_LONG = 0x100 -}; - -/* Here's a limited reimplementation of printf. The reason for doing - * this is primarily to special case handling of doubles. We want - * locale independent formatting of doubles and we want to trim - * trailing zeros. This is handled by dtostr() above, and the code - * below handles everything else by calling snprintf() to do the - * formatting. This functionality is only for internal use and we - * only implement the formats we actually use. - */ -void -_cairo_output_stream_vprintf (cairo_output_stream_t *stream, - const char *fmt, va_list ap) -{ -#define SINGLE_FMT_BUFFER_SIZE 32 - char buffer[512], single_fmt[SINGLE_FMT_BUFFER_SIZE]; - int single_fmt_length; - char *p; - const char *f, *start; - int length_modifier, width; - cairo_bool_t var_width; - - if (stream->status) - return; - - f = fmt; - p = buffer; - while (*f != '\0') { - if (p == buffer + sizeof (buffer)) { - _cairo_output_stream_write (stream, buffer, sizeof (buffer)); - p = buffer; - } - - if (*f != '%') { - *p++ = *f++; - continue; - } - - start = f; - f++; - - if (*f == '0') - f++; - - var_width = FALSE; - if (*f == '*') { - var_width = TRUE; - f++; - } - - while (_cairo_isdigit (*f)) - f++; - - length_modifier = 0; - if (*f == 'l') { - length_modifier = LENGTH_MODIFIER_LONG; - f++; - } - - /* The only format strings exist in the cairo implementation - * itself. So there's an internal consistency problem if any - * of them is larger than our format buffer size. */ - single_fmt_length = f - start + 1; - assert (single_fmt_length + 1 <= SINGLE_FMT_BUFFER_SIZE); - - /* Reuse the format string for this conversion. */ - memcpy (single_fmt, start, single_fmt_length); - single_fmt[single_fmt_length] = '\0'; - - /* Flush contents of buffer before snprintf()'ing into it. */ - _cairo_output_stream_write (stream, buffer, p - buffer); - - /* We group signed and unsigned together in this switch, the - * only thing that matters here is the size of the arguments, - * since we're just passing the data through to sprintf(). */ - switch (*f | length_modifier) { - case '%': - buffer[0] = *f; - buffer[1] = 0; - break; - case 'd': - case 'u': - case 'o': - case 'x': - case 'X': - if (var_width) { - width = va_arg (ap, int); - snprintf (buffer, sizeof buffer, - single_fmt, width, va_arg (ap, int)); - } else { - snprintf (buffer, sizeof buffer, single_fmt, va_arg (ap, int)); - } - break; - case 'd' | LENGTH_MODIFIER_LONG: - case 'u' | LENGTH_MODIFIER_LONG: - case 'o' | LENGTH_MODIFIER_LONG: - case 'x' | LENGTH_MODIFIER_LONG: - case 'X' | LENGTH_MODIFIER_LONG: - if (var_width) { - width = va_arg (ap, int); - snprintf (buffer, sizeof buffer, - single_fmt, width, va_arg (ap, long int)); - } else { - snprintf (buffer, sizeof buffer, - single_fmt, va_arg (ap, long int)); - } - break; - case 's': - snprintf (buffer, sizeof buffer, - single_fmt, va_arg (ap, const char *)); - break; - case 'f': - _cairo_dtostr (buffer, sizeof buffer, va_arg (ap, double), FALSE); - break; - case 'g': - _cairo_dtostr (buffer, sizeof buffer, va_arg (ap, double), TRUE); - break; - case 'c': - buffer[0] = va_arg (ap, int); - buffer[1] = 0; - break; - default: - ASSERT_NOT_REACHED; - } - p = buffer + strlen (buffer); - f++; - } - - _cairo_output_stream_write (stream, buffer, p - buffer); -} - -void -_cairo_output_stream_printf (cairo_output_stream_t *stream, - const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - - _cairo_output_stream_vprintf (stream, fmt, ap); - - va_end (ap); -} - -/* Matrix elements that are smaller than the value of the largest element * MATRIX_ROUNDING_TOLERANCE - * are rounded down to zero. */ -#define MATRIX_ROUNDING_TOLERANCE 1e-12 - -void -_cairo_output_stream_print_matrix (cairo_output_stream_t *stream, - const cairo_matrix_t *matrix) -{ - cairo_matrix_t m; - double s, e; - - m = *matrix; - s = fabs (m.xx); - if (fabs (m.xy) > s) - s = fabs (m.xy); - if (fabs (m.yx) > s) - s = fabs (m.yx); - if (fabs (m.yy) > s) - s = fabs (m.yy); - - e = s * MATRIX_ROUNDING_TOLERANCE; - if (fabs(m.xx) < e) - m.xx = 0; - if (fabs(m.xy) < e) - m.xy = 0; - if (fabs(m.yx) < e) - m.yx = 0; - if (fabs(m.yy) < e) - m.yy = 0; - if (fabs(m.x0) < e) - m.x0 = 0; - if (fabs(m.y0) < e) - m.y0 = 0; - - _cairo_output_stream_printf (stream, - "%f %f %f %f %f %f", - m.xx, m.yx, m.xy, m.yy, m.x0, m.y0); -} - -long -_cairo_output_stream_get_position (cairo_output_stream_t *stream) -{ - return stream->position; -} - -cairo_status_t -_cairo_output_stream_get_status (cairo_output_stream_t *stream) -{ - return stream->status; -} - -/* Maybe this should be a configure time option, so embedded targets - * don't have to pull in stdio. */ - - -typedef struct _stdio_stream { - cairo_output_stream_t base; - FILE *file; -} stdio_stream_t; - -static cairo_status_t -stdio_write (cairo_output_stream_t *base, - const unsigned char *data, unsigned int length) -{ - stdio_stream_t *stream = (stdio_stream_t *) base; - - if (fwrite (data, 1, length, stream->file) != length) - return _cairo_error (CAIRO_STATUS_WRITE_ERROR); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -stdio_flush (cairo_output_stream_t *base) -{ - stdio_stream_t *stream = (stdio_stream_t *) base; - - fflush (stream->file); - - if (ferror (stream->file)) - return _cairo_error (CAIRO_STATUS_WRITE_ERROR); - else - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -stdio_close (cairo_output_stream_t *base) -{ - cairo_status_t status; - stdio_stream_t *stream = (stdio_stream_t *) base; - - status = stdio_flush (base); - - fclose (stream->file); - - return status; -} - -cairo_output_stream_t * -_cairo_output_stream_create_for_file (FILE *file) -{ - stdio_stream_t *stream; - - if (file == NULL) { - _cairo_error_throw (CAIRO_STATUS_WRITE_ERROR); - return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error; - } - - stream = malloc (sizeof *stream); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - stdio_write, stdio_flush, stdio_flush); - stream->file = file; - - return &stream->base; -} - -cairo_output_stream_t * -_cairo_output_stream_create_for_filename (const char *filename) -{ - stdio_stream_t *stream; - FILE *file; - - if (filename == NULL) - return _cairo_null_stream_create (); - - file = fopen (filename, "wb"); - if (file == NULL) { - switch (errno) { - case ENOMEM: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - default: - _cairo_error_throw (CAIRO_STATUS_WRITE_ERROR); - return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error; - } - } - - stream = malloc (sizeof *stream); - if (unlikely (stream == NULL)) { - fclose (file); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - stdio_write, stdio_flush, stdio_close); - stream->file = file; - - return &stream->base; -} - - -typedef struct _memory_stream { - cairo_output_stream_t base; - cairo_array_t array; -} memory_stream_t; - -static cairo_status_t -memory_write (cairo_output_stream_t *base, - const unsigned char *data, unsigned int length) -{ - memory_stream_t *stream = (memory_stream_t *) base; - - return _cairo_array_append_multiple (&stream->array, data, length); -} - -static cairo_status_t -memory_close (cairo_output_stream_t *base) -{ - memory_stream_t *stream = (memory_stream_t *) base; - - _cairo_array_fini (&stream->array); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_output_stream_t * -_cairo_memory_stream_create (void) -{ - memory_stream_t *stream; - - stream = malloc (sizeof *stream); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, memory_write, NULL, memory_close); - _cairo_array_init (&stream->array, 1); - - return &stream->base; -} - -cairo_status_t -_cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream, - unsigned char **data_out, - unsigned long *length_out) -{ - memory_stream_t *stream; - cairo_status_t status; - - status = abstract_stream->status; - if (unlikely (status)) - return _cairo_output_stream_destroy (abstract_stream); - - stream = (memory_stream_t *) abstract_stream; - - *length_out = _cairo_array_num_elements (&stream->array); - *data_out = malloc (*length_out); - if (unlikely (*data_out == NULL)) { - status = _cairo_output_stream_destroy (abstract_stream); - assert (status == CAIRO_STATUS_SUCCESS); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - memcpy (*data_out, _cairo_array_index (&stream->array, 0), *length_out); - - return _cairo_output_stream_destroy (abstract_stream); -} - -void -_cairo_memory_stream_copy (cairo_output_stream_t *base, - cairo_output_stream_t *dest) -{ - memory_stream_t *stream = (memory_stream_t *) base; - - if (dest->status) - return; - - if (base->status) { - dest->status = base->status; - return; - } - - _cairo_output_stream_write (dest, - _cairo_array_index (&stream->array, 0), - _cairo_array_num_elements (&stream->array)); -} - -int -_cairo_memory_stream_length (cairo_output_stream_t *base) -{ - memory_stream_t *stream = (memory_stream_t *) base; - - return _cairo_array_num_elements (&stream->array); -} - -static cairo_status_t -null_write (cairo_output_stream_t *base, - const unsigned char *data, unsigned int length) -{ - return CAIRO_STATUS_SUCCESS; -} - -cairo_output_stream_t * -_cairo_null_stream_create (void) -{ - cairo_output_stream_t *stream; - - stream = malloc (sizeof *stream); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (stream, null_write, NULL, NULL); - - return stream; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-private.h deleted file mode 100644 index b827faba0ef..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-private.h +++ /dev/null @@ -1,168 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - */ - -#ifndef CAIRO_PAGINATED_H -#define CAIRO_PAGINATED_H - -#include "cairoint.h" - -struct _cairo_paginated_surface_backend { - /* Optional. Will be called once for each page. - * - * Note: With respect to the order of drawing operations as seen - * by the target, this call will occur before any drawing - * operations for the relevant page. However, with respect to the - * function calls as made by the user, this call will be *after* - * any drawing operations for the page, (that is, it will occur - * during the user's call to cairo_show_page or cairo_copy_page). - */ - cairo_warn cairo_int_status_t - (*start_page) (void *surface); - - /* Required. Will be called twice for each page, once with an - * argument of CAIRO_PAGINATED_MODE_ANALYZE and once with - * CAIRO_PAGINATED_MODE_RENDER. See more details in the - * documentation for _cairo_paginated_surface_create below. - */ - void - (*set_paginated_mode) (void *surface, - cairo_paginated_mode_t mode); - - /* Optional. Specifies the smallest box that encloses all objects - * on the page. Will be called at the end of the ANALYZE phase but - * before the mode is changed to RENDER. - */ - cairo_warn cairo_int_status_t - (*set_bounding_box) (void *surface, - cairo_box_t *bbox); - - /* Optional. Indicates whether the page requires fallback images. - * Will be called at the end of the ANALYZE phase but before the - * mode is changed to RENDER. - */ - cairo_warn cairo_int_status_t - (*set_fallback_images_required) (void *surface, - cairo_bool_t fallbacks_required); - - cairo_bool_t - (*supports_fine_grained_fallbacks) (void *surface); -}; - -/* A #cairo_paginated_surface_t provides a very convenient wrapper that - * is well-suited for doing the analysis common to most surfaces that - * have paginated output, (that is, things directed at printers, or - * for saving content in files such as PostScript or PDF files). - * - * To use the paginated surface, you'll first need to create your - * 'real' surface using _cairo_surface_init() and the standard - * #cairo_surface_backend_t. Then you also call - * _cairo_paginated_surface_create which takes its own, much simpler, - * #cairo_paginated_surface_backend_t. You are free to return the result - * of _cairo_paginated_surface_create() from your public - * cairo__surface_create(). The paginated backend will be careful - * to not let the user see that they really got a "wrapped" - * surface. See test-paginated-surface.c for a fairly minimal example - * of a paginated-using surface. That should be a reasonable example - * to follow. - * - * What the paginated surface does is first save all drawing - * operations for a page into a recording-surface. Then when the user calls - * cairo_show_page(), the paginated surface performs the following - * sequence of operations (using the backend functions passed to - * cairo_paginated_surface_create()): - * - * 1. Calls start_page() (if not %NULL). At this point, it is appropriate - * for the target to emit any page-specific header information into - * its output. - * - * 2. Calls set_paginated_mode() with an argument of %CAIRO_PAGINATED_MODE_ANALYZE - * - * 3. Replays the recording-surface to the target surface, (with an - * analysis surface inserted between which watches the return value - * from each operation). This analysis stage is used to decide which - * operations will require fallbacks. - * - * 4. Calls set_bounding_box() to provide the target surface with the - * tight bounding box of the page. - * - * 5. Calls set_paginated_mode() with an argument of %CAIRO_PAGINATED_MODE_RENDER - * - * 6. Replays a subset of the recording-surface operations to the target surface - * - * 7. Calls set_paginated_mode() with an argument of %CAIRO_PAGINATED_MODE_FALLBACK - * - * 8. Replays the remaining operations to an image surface, sets an - * appropriate clip on the target, then paints the resulting image - * surface to the target. - * - * So, the target will see drawing operations during three separate - * stages, (ANALYZE, RENDER and FALLBACK). During the ANALYZE phase - * the target should not actually perform any rendering, (for example, - * if performing output to a file, no output should be generated - * during this stage). Instead the drawing functions simply need to - * return %CAIRO_STATUS_SUCCESS or %CAIRO_INT_STATUS_UNSUPPORTED to - * indicate whether rendering would be supported. And it should do - * this as quickly as possible. The FALLBACK phase allows the surface - * to distinguish fallback images from native rendering in case they - * need to be handled as a special case. - * - * Note: The paginated surface layer assumes that the target surface - * is "blank" by default at the beginning of each page, without any - * need for an explicit erase operation, (as opposed to an image - * surface, for example, which might have uninitialized content - * originally). As such, it optimizes away CLEAR operations that - * happen at the beginning of each page---the target surface will not - * even see these operations. - */ -cairo_private cairo_surface_t * -_cairo_paginated_surface_create (cairo_surface_t *target, - cairo_content_t content, - const cairo_paginated_surface_backend_t *backend); - -cairo_private cairo_surface_t * -_cairo_paginated_surface_get_target (cairo_surface_t *surface); - -cairo_private cairo_surface_t * -_cairo_paginated_surface_get_recording (cairo_surface_t *surface); - -cairo_private cairo_bool_t -_cairo_surface_is_paginated (cairo_surface_t *surface); - -cairo_private cairo_status_t -_cairo_paginated_surface_set_size (cairo_surface_t *surface, - int width, - int height); - -#endif /* CAIRO_PAGINATED_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface-private.h deleted file mode 100644 index ebf4b342492..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface-private.h +++ /dev/null @@ -1,62 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - */ - -#ifndef CAIRO_PAGINATED_SURFACE_H -#define CAIRO_PAGINATED_SURFACE_H - -#include "cairo.h" - -#include "cairo-surface-private.h" - -typedef struct _cairo_paginated_surface { - cairo_surface_t base; - - /* The target surface to hold the final result. */ - cairo_surface_t *target; - - cairo_content_t content; - - /* Paginated-surface specific functions for the target */ - const cairo_paginated_surface_backend_t *backend; - - /* A cairo_recording_surface to record all operations. To be replayed - * against target, and also against image surface as necessary for - * fallbacks. */ - cairo_surface_t *recording_surface; - - int page_num; -} cairo_paginated_surface_t; - -#endif /* CAIRO_PAGINATED_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface.c deleted file mode 100644 index 68e4e0e34fd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-paginated-surface.c +++ /dev/null @@ -1,716 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * Copyright © 2007 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - * Keith Packard - * Adrian Johnson - */ - -/* The paginated surface layer exists to provide as much code sharing - * as possible for the various paginated surface backends in cairo - * (PostScript, PDF, etc.). See cairo-paginated-private.h for - * more details on how it works and how to use it. - */ - -#include "cairoint.h" - -#include "cairo-paginated-private.h" -#include "cairo-paginated-surface-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-analysis-surface-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-subsurface-inline.h" - -static const cairo_surface_backend_t cairo_paginated_surface_backend; - -static cairo_int_status_t -_cairo_paginated_surface_show_page (void *abstract_surface); - -static cairo_surface_t * -_cairo_paginated_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_rectangle_t rect; - rect.x = rect.y = 0.; - rect.width = width; - rect.height = height; - return cairo_recording_surface_create (content, &rect); -} - -static cairo_surface_t * -_create_recording_surface_for_target (cairo_surface_t *target, - cairo_content_t content) -{ - cairo_rectangle_int_t rect; - - if (_cairo_surface_get_extents (target, &rect)) { - cairo_rectangle_t recording_extents; - - recording_extents.x = rect.x; - recording_extents.y = rect.y; - recording_extents.width = rect.width; - recording_extents.height = rect.height; - - return cairo_recording_surface_create (content, &recording_extents); - } else { - return cairo_recording_surface_create (content, NULL); - } -} - -cairo_surface_t * -_cairo_paginated_surface_create (cairo_surface_t *target, - cairo_content_t content, - const cairo_paginated_surface_backend_t *backend) -{ - cairo_paginated_surface_t *surface; - cairo_status_t status; - - surface = malloc (sizeof (cairo_paginated_surface_t)); - if (unlikely (surface == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FAIL; - } - - _cairo_surface_init (&surface->base, - &cairo_paginated_surface_backend, - NULL, /* device */ - content); - - /* Override surface->base.type with target's type so we don't leak - * evidence of the paginated wrapper out to the user. */ - surface->base.type = target->type; - - surface->target = cairo_surface_reference (target); - - surface->content = content; - surface->backend = backend; - - surface->recording_surface = _create_recording_surface_for_target (target, content); - status = surface->recording_surface->status; - if (unlikely (status)) - goto FAIL_CLEANUP_SURFACE; - - surface->page_num = 1; - surface->base.is_clear = TRUE; - - return &surface->base; - - FAIL_CLEANUP_SURFACE: - cairo_surface_destroy (target); - free (surface); - FAIL: - return _cairo_surface_create_in_error (status); -} - -cairo_bool_t -_cairo_surface_is_paginated (cairo_surface_t *surface) -{ - return surface->backend == &cairo_paginated_surface_backend; -} - -cairo_surface_t * -_cairo_paginated_surface_get_target (cairo_surface_t *surface) -{ - cairo_paginated_surface_t *paginated_surface; - - assert (_cairo_surface_is_paginated (surface)); - - paginated_surface = (cairo_paginated_surface_t *) surface; - return paginated_surface->target; -} - -cairo_surface_t * -_cairo_paginated_surface_get_recording (cairo_surface_t *surface) -{ - cairo_paginated_surface_t *paginated_surface; - - assert (_cairo_surface_is_paginated (surface)); - - paginated_surface = (cairo_paginated_surface_t *) surface; - return paginated_surface->recording_surface; -} - -cairo_status_t -_cairo_paginated_surface_set_size (cairo_surface_t *surface, - int width, - int height) -{ - cairo_paginated_surface_t *paginated_surface; - cairo_status_t status; - cairo_rectangle_t recording_extents; - - assert (_cairo_surface_is_paginated (surface)); - - paginated_surface = (cairo_paginated_surface_t *) surface; - - recording_extents.x = 0; - recording_extents.y = 0; - recording_extents.width = width; - recording_extents.height = height; - - cairo_surface_destroy (paginated_surface->recording_surface); - paginated_surface->recording_surface = cairo_recording_surface_create (paginated_surface->content, - &recording_extents); - status = paginated_surface->recording_surface->status; - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_paginated_surface_finish (void *abstract_surface) -{ - cairo_paginated_surface_t *surface = abstract_surface; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - if (! surface->base.is_clear || surface->page_num == 1) { - /* Bypass some of the sanity checking in cairo-surface.c, as we - * know that the surface is finished... - */ - status = _cairo_paginated_surface_show_page (surface); - } - - /* XXX We want to propagate any errors from destroy(), but those are not - * returned via the api. So we need to explicitly finish the target, - * and check the status afterwards. However, we can only call finish() - * on the target, if we own it. - */ - if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->target->ref_count) == 1) - cairo_surface_finish (surface->target); - if (status == CAIRO_STATUS_SUCCESS) - status = cairo_surface_status (surface->target); - cairo_surface_destroy (surface->target); - - cairo_surface_finish (surface->recording_surface); - if (status == CAIRO_STATUS_SUCCESS) - status = cairo_surface_status (surface->recording_surface); - cairo_surface_destroy (surface->recording_surface); - - return status; -} - -static cairo_surface_t * -_cairo_paginated_surface_create_image_surface (void *abstract_surface, - int width, - int height) -{ - cairo_paginated_surface_t *surface = abstract_surface; - cairo_surface_t *image; - cairo_font_options_t options; - - image = _cairo_image_surface_create_with_content (surface->content, - width, - height); - - cairo_surface_get_font_options (&surface->base, &options); - _cairo_surface_set_font_options (image, &options); - - return image; -} - -static cairo_surface_t * -_cairo_paginated_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_paginated_surface_t *surface = abstract_surface; - return _cairo_surface_get_source (surface->target, extents); -} - -static cairo_status_t -_cairo_paginated_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_paginated_surface_t *surface = abstract_surface; - cairo_bool_t is_bounded; - cairo_surface_t *image; - cairo_status_t status; - cairo_rectangle_int_t extents; - - is_bounded = _cairo_surface_get_extents (surface->target, &extents); - if (! is_bounded) - return CAIRO_INT_STATUS_UNSUPPORTED; - - image = _cairo_paginated_surface_create_image_surface (surface, - extents.width, - extents.height); - - status = _cairo_recording_surface_replay (surface->recording_surface, image); - if (unlikely (status)) { - cairo_surface_destroy (image); - return status; - } - - *image_out = (cairo_image_surface_t*) image; - *image_extra = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_paginated_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); -} - -static cairo_int_status_t -_paint_fallback_image (cairo_paginated_surface_t *surface, - cairo_rectangle_int_t *rect) -{ - double x_scale = surface->base.x_fallback_resolution / surface->target->x_resolution; - double y_scale = surface->base.y_fallback_resolution / surface->target->y_resolution; - int x, y, width, height; - cairo_status_t status; - cairo_surface_t *image; - cairo_surface_pattern_t pattern; - cairo_clip_t *clip; - - x = rect->x; - y = rect->y; - width = rect->width; - height = rect->height; - image = _cairo_paginated_surface_create_image_surface (surface, - ceil (width * x_scale), - ceil (height * y_scale)); - cairo_surface_set_device_scale (image, x_scale, y_scale); - /* set_device_offset just sets the x0/y0 components of the matrix; - * so we have to do the scaling manually. */ - cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale); - - status = _cairo_recording_surface_replay (surface->recording_surface, image); - if (unlikely (status)) - goto CLEANUP_IMAGE; - - _cairo_pattern_init_for_surface (&pattern, image); - cairo_matrix_init (&pattern.base.matrix, - x_scale, 0, 0, y_scale, -x*x_scale, -y*y_scale); - /* the fallback should be rendered at native resolution, so disable - * filtering (if possible) to avoid introducing potential artifacts. */ - pattern.base.filter = CAIRO_FILTER_NEAREST; - - clip = _cairo_clip_intersect_rectangle (NULL, rect); - status = _cairo_surface_paint (surface->target, - CAIRO_OPERATOR_SOURCE, - &pattern.base, clip); - _cairo_clip_destroy (clip); - _cairo_pattern_fini (&pattern.base); - -CLEANUP_IMAGE: - cairo_surface_destroy (image); - - return status; -} - -static cairo_int_status_t -_paint_page (cairo_paginated_surface_t *surface) -{ - cairo_surface_t *analysis; - cairo_int_status_t status; - cairo_bool_t has_supported, has_page_fallback, has_finegrained_fallback; - - if (unlikely (surface->target->status)) - return surface->target->status; - - analysis = _cairo_analysis_surface_create (surface->target); - if (unlikely (analysis->status)) - return _cairo_surface_set_error (surface->target, analysis->status); - - surface->backend->set_paginated_mode (surface->target, - CAIRO_PAGINATED_MODE_ANALYZE); - status = _cairo_recording_surface_replay_and_create_regions (surface->recording_surface, - analysis); - if (status) - goto FAIL; - - assert (analysis->status == CAIRO_STATUS_SUCCESS); - - if (surface->backend->set_bounding_box) { - cairo_box_t bbox; - - _cairo_analysis_surface_get_bounding_box (analysis, &bbox); - status = surface->backend->set_bounding_box (surface->target, &bbox); - if (unlikely (status)) - goto FAIL; - } - - if (surface->backend->set_fallback_images_required) { - cairo_bool_t has_fallbacks = _cairo_analysis_surface_has_unsupported (analysis); - - status = surface->backend->set_fallback_images_required (surface->target, - has_fallbacks); - if (unlikely (status)) - goto FAIL; - } - - /* Finer grained fallbacks are currently only supported for some - * surface types */ - if (surface->backend->supports_fine_grained_fallbacks != NULL && - surface->backend->supports_fine_grained_fallbacks (surface->target)) - { - has_supported = _cairo_analysis_surface_has_supported (analysis); - has_page_fallback = FALSE; - has_finegrained_fallback = _cairo_analysis_surface_has_unsupported (analysis); - } - else - { - if (_cairo_analysis_surface_has_unsupported (analysis)) { - has_supported = FALSE; - has_page_fallback = TRUE; - } else { - has_supported = TRUE; - has_page_fallback = FALSE; - } - has_finegrained_fallback = FALSE; - } - - if (has_supported) { - surface->backend->set_paginated_mode (surface->target, - CAIRO_PAGINATED_MODE_RENDER); - - status = _cairo_recording_surface_replay_region (surface->recording_surface, - NULL, - surface->target, - CAIRO_RECORDING_REGION_NATIVE); - assert (status != CAIRO_INT_STATUS_UNSUPPORTED); - if (unlikely (status)) - goto FAIL; - } - - if (has_page_fallback) { - cairo_rectangle_int_t extents; - cairo_bool_t is_bounded; - - surface->backend->set_paginated_mode (surface->target, - CAIRO_PAGINATED_MODE_FALLBACK); - - is_bounded = _cairo_surface_get_extents (surface->target, &extents); - if (! is_bounded) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto FAIL; - } - - status = _paint_fallback_image (surface, &extents); - if (unlikely (status)) - goto FAIL; - } - - if (has_finegrained_fallback) { - cairo_region_t *region; - int num_rects, i; - - surface->backend->set_paginated_mode (surface->target, - CAIRO_PAGINATED_MODE_FALLBACK); - - region = _cairo_analysis_surface_get_unsupported (analysis); - - num_rects = cairo_region_num_rectangles (region); - for (i = 0; i < num_rects; i++) { - cairo_rectangle_int_t rect; - - cairo_region_get_rectangle (region, i, &rect); - status = _paint_fallback_image (surface, &rect); - if (unlikely (status)) - goto FAIL; - } - } - - FAIL: - cairo_surface_destroy (analysis); - - return _cairo_surface_set_error (surface->target, status); -} - -static cairo_status_t -_start_page (cairo_paginated_surface_t *surface) -{ - if (surface->target->status) - return surface->target->status; - - if (! surface->backend->start_page) - return CAIRO_STATUS_SUCCESS; - - return _cairo_surface_set_error (surface->target, - surface->backend->start_page (surface->target)); -} - -static cairo_int_status_t -_cairo_paginated_surface_copy_page (void *abstract_surface) -{ - cairo_status_t status; - cairo_paginated_surface_t *surface = abstract_surface; - - status = _start_page (surface); - if (unlikely (status)) - return status; - - status = _paint_page (surface); - if (unlikely (status)) - return status; - - surface->page_num++; - - /* XXX: It might make sense to add some support here for calling - * cairo_surface_copy_page on the target surface. It would be an - * optimization for the output, but the interaction with image - * fallbacks gets tricky. For now, we just let the target see a - * show_page and we implement the copying by simply not destroying - * the recording-surface. */ - - cairo_surface_show_page (surface->target); - return cairo_surface_status (surface->target); -} - -static cairo_int_status_t -_cairo_paginated_surface_show_page (void *abstract_surface) -{ - cairo_status_t status; - cairo_paginated_surface_t *surface = abstract_surface; - - status = _start_page (surface); - if (unlikely (status)) - return status; - - status = _paint_page (surface); - if (unlikely (status)) - return status; - - cairo_surface_show_page (surface->target); - status = surface->target->status; - if (unlikely (status)) - return status; - - status = surface->recording_surface->status; - if (unlikely (status)) - return status; - - if (! surface->base.finished) { - cairo_surface_destroy (surface->recording_surface); - - surface->recording_surface = _create_recording_surface_for_target (surface->target, - surface->content); - status = surface->recording_surface->status; - if (unlikely (status)) - return status; - - surface->page_num++; - surface->base.is_clear = TRUE; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_paginated_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_get_extents (surface->target, rectangle); -} - -static void -_cairo_paginated_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - cairo_surface_get_font_options (surface->target, options); -} - -static cairo_int_status_t -_cairo_paginated_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_paint (surface->recording_surface, op, source, clip); -} - -static cairo_int_status_t -_cairo_paginated_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_mask (surface->recording_surface, op, source, mask, clip); -} - -static cairo_int_status_t -_cairo_paginated_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_stroke (surface->recording_surface, op, source, - path, style, - ctm, ctm_inverse, - tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_paginated_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_fill (surface->recording_surface, op, source, - path, fill_rule, - tolerance, antialias, - clip); -} - -static cairo_bool_t -_cairo_paginated_surface_has_show_text_glyphs (void *abstract_surface) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return cairo_surface_has_show_text_glyphs (surface->target); -} - -static cairo_int_status_t -_cairo_paginated_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_show_text_glyphs (surface->recording_surface, op, source, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font, - clip); -} - -static const char ** -_cairo_paginated_surface_get_supported_mime_types (void *abstract_surface) -{ - cairo_paginated_surface_t *surface = abstract_surface; - - if (surface->target->backend->get_supported_mime_types) - return surface->target->backend->get_supported_mime_types (surface->target); - - return NULL; -} - -static cairo_surface_t * -_cairo_paginated_surface_snapshot (void *abstract_other) -{ - cairo_paginated_surface_t *other = abstract_other; - - return other->recording_surface->backend->snapshot (other->recording_surface); -} - -static cairo_t * -_cairo_paginated_context_create (void *target) -{ - cairo_paginated_surface_t *surface = target; - - if (_cairo_surface_is_subsurface (&surface->base)) - surface = (cairo_paginated_surface_t *) - _cairo_surface_subsurface_get_target (&surface->base); - - return surface->recording_surface->backend->create_context (target); -} - -static const cairo_surface_backend_t cairo_paginated_surface_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, - _cairo_paginated_surface_finish, - - _cairo_paginated_context_create, - - _cairo_paginated_surface_create_similar, - NULL, /* create simlar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_paginated_surface_source, - _cairo_paginated_surface_acquire_source_image, - _cairo_paginated_surface_release_source_image, - _cairo_paginated_surface_snapshot, - - _cairo_paginated_surface_copy_page, - _cairo_paginated_surface_show_page, - - _cairo_paginated_surface_get_extents, - _cairo_paginated_surface_get_font_options, - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_paginated_surface_paint, - _cairo_paginated_surface_mask, - _cairo_paginated_surface_stroke, - _cairo_paginated_surface_fill, - NULL, /* fill_stroke */ - NULL, /* show_glyphs */ - _cairo_paginated_surface_has_show_text_glyphs, - _cairo_paginated_surface_show_text_glyphs, - _cairo_paginated_surface_get_supported_mime_types, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-bounds.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-bounds.c deleted file mode 100644 index 9c7222426d3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-bounds.c +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" -#include "cairo-box-inline.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" - -typedef struct _cairo_path_bounder { - cairo_point_t current_point; - cairo_bool_t has_extents; - cairo_box_t extents; -} cairo_path_bounder_t; - -static cairo_status_t -_cairo_path_bounder_move_to (void *closure, - const cairo_point_t *point) -{ - cairo_path_bounder_t *bounder = closure; - - bounder->current_point = *point; - - if (likely (bounder->has_extents)) { - _cairo_box_add_point (&bounder->extents, point); - } else { - bounder->has_extents = TRUE; - _cairo_box_set (&bounder->extents, point, point); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_bounder_line_to (void *closure, - const cairo_point_t *point) -{ - cairo_path_bounder_t *bounder = closure; - - bounder->current_point = *point; - _cairo_box_add_point (&bounder->extents, point); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_bounder_curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - cairo_path_bounder_t *bounder = closure; - - _cairo_box_add_curve_to (&bounder->extents, - &bounder->current_point, - b, c, d); - bounder->current_point = *d; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_bounder_close_path (void *closure) -{ - return CAIRO_STATUS_SUCCESS; -} - -cairo_bool_t -_cairo_path_bounder_extents (const cairo_path_fixed_t *path, - cairo_box_t *extents) -{ - cairo_path_bounder_t bounder; - cairo_status_t status; - - bounder.has_extents = FALSE; - status = _cairo_path_fixed_interpret (path, - _cairo_path_bounder_move_to, - _cairo_path_bounder_line_to, - _cairo_path_bounder_curve_to, - _cairo_path_bounder_close_path, - &bounder); - assert (!status); - - if (bounder.has_extents) - *extents = bounder.extents; - - return bounder.has_extents; -} - -void -_cairo_path_fixed_approximate_clip_extents (const cairo_path_fixed_t *path, - cairo_rectangle_int_t *extents) -{ - _cairo_path_fixed_approximate_fill_extents (path, extents); -} - -void -_cairo_path_fixed_approximate_fill_extents (const cairo_path_fixed_t *path, - cairo_rectangle_int_t *extents) -{ - _cairo_path_fixed_fill_extents (path, CAIRO_FILL_RULE_WINDING, 0, extents); -} - -void -_cairo_path_fixed_fill_extents (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_rectangle_int_t *extents) -{ - if (path->extents.p1.x < path->extents.p2.x && - path->extents.p1.y < path->extents.p2.y) { - _cairo_box_round_to_rectangle (&path->extents, extents); - } else { - extents->x = extents->y = 0; - extents->width = extents->height = 0; - } -} - -/* Adjusts the fill extents (above) by the device-space pen. */ -void -_cairo_path_fixed_approximate_stroke_extents (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - cairo_rectangle_int_t *extents) -{ - if (path->has_extents) { - cairo_box_t box_extents; - double dx, dy; - - _cairo_stroke_style_max_distance_from_path (style, path, ctm, &dx, &dy); - - box_extents = path->extents; - box_extents.p1.x -= _cairo_fixed_from_double (dx); - box_extents.p1.y -= _cairo_fixed_from_double (dy); - box_extents.p2.x += _cairo_fixed_from_double (dx); - box_extents.p2.y += _cairo_fixed_from_double (dy); - - _cairo_box_round_to_rectangle (&box_extents, extents); - } else { - extents->x = extents->y = 0; - extents->width = extents->height = 0; - } -} - -cairo_status_t -_cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_rectangle_int_t *extents) -{ - cairo_polygon_t polygon; - cairo_status_t status; - - _cairo_polygon_init (&polygon, NULL, 0); - status = _cairo_path_fixed_stroke_to_polygon (path, - stroke_style, - ctm, ctm_inverse, - tolerance, - &polygon); - _cairo_box_round_to_rectangle (&polygon.extents, extents); - _cairo_polygon_fini (&polygon); - - return status; -} - -cairo_bool_t -_cairo_path_fixed_extents (const cairo_path_fixed_t *path, - cairo_box_t *box) -{ - *box = path->extents; - return path->has_extents; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fill.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fill.c deleted file mode 100644 index 4000c9c586e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fill.c +++ /dev/null @@ -1,341 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-region-private.h" -#include "cairo-traps-private.h" - -typedef struct cairo_filler { - cairo_polygon_t *polygon; - double tolerance; - - cairo_box_t limit; - cairo_bool_t has_limits; - - cairo_point_t current_point; - cairo_point_t last_move_to; -} cairo_filler_t; - -static cairo_status_t -_cairo_filler_line_to (void *closure, - const cairo_point_t *point) -{ - cairo_filler_t *filler = closure; - cairo_status_t status; - - status = _cairo_polygon_add_external_edge (filler->polygon, - &filler->current_point, - point); - - filler->current_point = *point; - - return status; -} - -static cairo_status_t -_cairo_filler_close (void *closure) -{ - cairo_filler_t *filler = closure; - - /* close the subpath */ - return _cairo_filler_line_to (closure, &filler->last_move_to); -} - -static cairo_status_t -_cairo_filler_move_to (void *closure, - const cairo_point_t *point) -{ - cairo_filler_t *filler = closure; - cairo_status_t status; - - /* close current subpath */ - status = _cairo_filler_close (closure); - if (unlikely (status)) - return status; - - /* make sure that the closure represents a degenerate path */ - filler->current_point = *point; - filler->last_move_to = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_filler_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - cairo_filler_t *filler = closure; - cairo_spline_t spline; - - if (filler->has_limits) { - if (! _cairo_spline_intersects (&filler->current_point, p1, p2, p3, - &filler->limit)) - return _cairo_filler_line_to (filler, p3); - } - - if (! _cairo_spline_init (&spline, - (cairo_spline_add_point_func_t)_cairo_filler_line_to, filler, - &filler->current_point, p1, p2, p3)) - { - return _cairo_filler_line_to (closure, p3); - } - - return _cairo_spline_decompose (&spline, filler->tolerance); -} - -cairo_status_t -_cairo_path_fixed_fill_to_polygon (const cairo_path_fixed_t *path, - double tolerance, - cairo_polygon_t *polygon) -{ - cairo_filler_t filler; - cairo_status_t status; - - filler.polygon = polygon; - filler.tolerance = tolerance; - - filler.has_limits = FALSE; - if (polygon->num_limits) { - filler.has_limits = TRUE; - filler.limit = polygon->limit; - } - - /* make sure that the closure represents a degenerate path */ - filler.current_point.x = 0; - filler.current_point.y = 0; - filler.last_move_to = filler.current_point; - - status = _cairo_path_fixed_interpret (path, - _cairo_filler_move_to, - _cairo_filler_line_to, - _cairo_filler_curve_to, - _cairo_filler_close, - &filler); - if (unlikely (status)) - return status; - - return _cairo_filler_close (&filler); -} - -typedef struct cairo_filler_rectilinear_aligned { - cairo_polygon_t *polygon; - - cairo_point_t current_point; - cairo_point_t last_move_to; -} cairo_filler_ra_t; - -static cairo_status_t -_cairo_filler_ra_line_to (void *closure, - const cairo_point_t *point) -{ - cairo_filler_ra_t *filler = closure; - cairo_status_t status; - cairo_point_t p; - - p.x = _cairo_fixed_round_down (point->x); - p.y = _cairo_fixed_round_down (point->y); - - status = _cairo_polygon_add_external_edge (filler->polygon, - &filler->current_point, - &p); - - filler->current_point = p; - - return status; -} - -static cairo_status_t -_cairo_filler_ra_close (void *closure) -{ - cairo_filler_ra_t *filler = closure; - return _cairo_filler_ra_line_to (closure, &filler->last_move_to); -} - -static cairo_status_t -_cairo_filler_ra_move_to (void *closure, - const cairo_point_t *point) -{ - cairo_filler_ra_t *filler = closure; - cairo_status_t status; - cairo_point_t p; - - /* close current subpath */ - status = _cairo_filler_ra_close (closure); - if (unlikely (status)) - return status; - - p.x = _cairo_fixed_round_down (point->x); - p.y = _cairo_fixed_round_down (point->y); - - /* make sure that the closure represents a degenerate path */ - filler->current_point = p; - filler->last_move_to = p; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_path_fixed_fill_rectilinear_to_polygon (const cairo_path_fixed_t *path, - cairo_antialias_t antialias, - cairo_polygon_t *polygon) -{ - cairo_filler_ra_t filler; - cairo_status_t status; - - if (antialias != CAIRO_ANTIALIAS_NONE) - return _cairo_path_fixed_fill_to_polygon (path, 0., polygon); - - filler.polygon = polygon; - - /* make sure that the closure represents a degenerate path */ - filler.current_point.x = 0; - filler.current_point.y = 0; - filler.last_move_to = filler.current_point; - - status = _cairo_path_fixed_interpret_flat (path, - _cairo_filler_ra_move_to, - _cairo_filler_ra_line_to, - _cairo_filler_ra_close, - &filler, - 0.); - if (unlikely (status)) - return status; - - return _cairo_filler_ra_close (&filler); -} - -cairo_status_t -_cairo_path_fixed_fill_to_traps (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_traps_t *traps) -{ - cairo_polygon_t polygon; - cairo_status_t status; - - if (_cairo_path_fixed_fill_is_empty (path)) - return CAIRO_STATUS_SUCCESS; - - _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); - status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); - if (unlikely (status || polygon.num_edges == 0)) - goto CLEANUP; - - status = _cairo_bentley_ottmann_tessellate_polygon (traps, - &polygon, fill_rule); - - CLEANUP: - _cairo_polygon_fini (&polygon); - return status; -} - -static cairo_status_t -_cairo_path_fixed_fill_rectilinear_tessellate_to_boxes (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias, - cairo_boxes_t *boxes) -{ - cairo_polygon_t polygon; - cairo_status_t status; - - _cairo_polygon_init (&polygon, boxes->limits, boxes->num_limits); - boxes->num_limits = 0; - - /* tolerance will be ignored as the path is rectilinear */ - status = _cairo_path_fixed_fill_rectilinear_to_polygon (path, antialias, &polygon); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - status = - _cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (&polygon, - fill_rule, - boxes); - } - - _cairo_polygon_fini (&polygon); - - return status; -} - -cairo_status_t -_cairo_path_fixed_fill_rectilinear_to_boxes (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias, - cairo_boxes_t *boxes) -{ - cairo_path_fixed_iter_t iter; - cairo_status_t status; - cairo_box_t box; - - if (_cairo_path_fixed_is_box (path, &box)) - return _cairo_boxes_add (boxes, antialias, &box); - - _cairo_path_fixed_iter_init (&iter, path); - while (_cairo_path_fixed_iter_is_fill_box (&iter, &box)) { - if (box.p1.y == box.p2.y || box.p1.x == box.p2.x) - continue; - - if (box.p1.y > box.p2.y) { - cairo_fixed_t t; - - t = box.p1.y; - box.p1.y = box.p2.y; - box.p2.y = t; - - t = box.p1.x; - box.p1.x = box.p2.x; - box.p2.x = t; - } - - status = _cairo_boxes_add (boxes, antialias, &box); - if (unlikely (status)) - return status; - } - - if (_cairo_path_fixed_iter_at_end (&iter)) - return _cairo_bentley_ottmann_tessellate_boxes (boxes, fill_rule, boxes); - - /* path is not rectangular, try extracting clipped rectilinear edges */ - _cairo_boxes_clear (boxes); - return _cairo_path_fixed_fill_rectilinear_tessellate_to_boxes (path, - fill_rule, - antialias, - boxes); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed-private.h deleted file mode 100644 index cf7cd0836fb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed-private.h +++ /dev/null @@ -1,206 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PATH_FIXED_PRIVATE_H -#define CAIRO_PATH_FIXED_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" -#include "cairo-list-private.h" - -#define WATCH_PATH 0 -#if WATCH_PATH -#include -#endif - -enum cairo_path_op { - CAIRO_PATH_OP_MOVE_TO = 0, - CAIRO_PATH_OP_LINE_TO = 1, - CAIRO_PATH_OP_CURVE_TO = 2, - CAIRO_PATH_OP_CLOSE_PATH = 3 -}; - -/* we want to make sure a single byte is used for the enum */ -typedef char cairo_path_op_t; - -/* make _cairo_path_fixed fit into ~512 bytes -- about 50 items */ -#define CAIRO_PATH_BUF_SIZE ((512 - sizeof (cairo_path_buf_t)) \ - / (2 * sizeof (cairo_point_t) + sizeof (cairo_path_op_t))) - -#define cairo_path_head(path__) (&(path__)->buf.base) -#define cairo_path_tail(path__) cairo_path_buf_prev (cairo_path_head (path__)) - -#define cairo_path_buf_next(pos__) \ - cairo_list_entry ((pos__)->link.next, cairo_path_buf_t, link) -#define cairo_path_buf_prev(pos__) \ - cairo_list_entry ((pos__)->link.prev, cairo_path_buf_t, link) - -#define cairo_path_foreach_buf_start(pos__, path__) \ - pos__ = cairo_path_head (path__); do -#define cairo_path_foreach_buf_end(pos__, path__) \ - while ((pos__ = cairo_path_buf_next (pos__)) != cairo_path_head (path__)) - - -typedef struct _cairo_path_buf { - cairo_list_t link; - unsigned int num_ops; - unsigned int size_ops; - unsigned int num_points; - unsigned int size_points; - - cairo_path_op_t *op; - cairo_point_t *points; -} cairo_path_buf_t; - -typedef struct _cairo_path_buf_fixed { - cairo_path_buf_t base; - - cairo_path_op_t op[CAIRO_PATH_BUF_SIZE]; - cairo_point_t points[2 * CAIRO_PATH_BUF_SIZE]; -} cairo_path_buf_fixed_t; - -/* - NOTES: - has_curve_to => !stroke_is_rectilinear - fill_is_rectilinear => stroke_is_rectilinear - fill_is_empty => fill_is_rectilinear - fill_maybe_region => fill_is_rectilinear -*/ -struct _cairo_path_fixed { - cairo_point_t last_move_point; - cairo_point_t current_point; - unsigned int has_current_point : 1; - unsigned int needs_move_to : 1; - unsigned int has_extents : 1; - unsigned int has_curve_to : 1; - unsigned int stroke_is_rectilinear : 1; - unsigned int fill_is_rectilinear : 1; - unsigned int fill_maybe_region : 1; - unsigned int fill_is_empty : 1; - - cairo_box_t extents; - - cairo_path_buf_fixed_t buf; -}; - -cairo_private void -_cairo_path_fixed_translate (cairo_path_fixed_t *path, - cairo_fixed_t offx, - cairo_fixed_t offy); - -cairo_private cairo_status_t -_cairo_path_fixed_append (cairo_path_fixed_t *path, - const cairo_path_fixed_t *other, - cairo_fixed_t tx, - cairo_fixed_t ty); - -cairo_private unsigned long -_cairo_path_fixed_hash (const cairo_path_fixed_t *path); - -cairo_private unsigned long -_cairo_path_fixed_size (const cairo_path_fixed_t *path); - -cairo_private cairo_bool_t -_cairo_path_fixed_equal (const cairo_path_fixed_t *a, - const cairo_path_fixed_t *b); - -typedef struct _cairo_path_fixed_iter { - const cairo_path_buf_t *first; - const cairo_path_buf_t *buf; - unsigned int n_op; - unsigned int n_point; -} cairo_path_fixed_iter_t; - -cairo_private void -_cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter, - const cairo_path_fixed_t *path); - -cairo_private cairo_bool_t -_cairo_path_fixed_iter_is_fill_box (cairo_path_fixed_iter_t *_iter, - cairo_box_t *box); - -cairo_private cairo_bool_t -_cairo_path_fixed_iter_at_end (const cairo_path_fixed_iter_t *iter); - -static inline cairo_bool_t -_cairo_path_fixed_fill_is_empty (const cairo_path_fixed_t *path) -{ - return path->fill_is_empty; -} - -static inline cairo_bool_t -_cairo_path_fixed_fill_is_rectilinear (const cairo_path_fixed_t *path) -{ - if (! path->fill_is_rectilinear) - return 0; - - if (! path->has_current_point || path->needs_move_to) - return 1; - - /* check whether the implicit close preserves the rectilinear property */ - return path->current_point.x == path->last_move_point.x || - path->current_point.y == path->last_move_point.y; -} - -static inline cairo_bool_t -_cairo_path_fixed_stroke_is_rectilinear (const cairo_path_fixed_t *path) -{ - return path->stroke_is_rectilinear; -} - -static inline cairo_bool_t -_cairo_path_fixed_fill_maybe_region (const cairo_path_fixed_t *path) -{ - if (! path->fill_maybe_region) - return 0; - - if (! path->has_current_point || path->needs_move_to) - return 1; - - /* check whether the implicit close preserves the rectilinear property - * (the integer point property is automatically preserved) - */ - return path->current_point.x == path->last_move_point.x || - path->current_point.y == path->last_move_point.y; -} - -cairo_private cairo_bool_t -_cairo_path_fixed_is_stroke_box (const cairo_path_fixed_t *path, - cairo_box_t *box); - -cairo_private cairo_bool_t -_cairo_path_fixed_is_simple_quad (const cairo_path_fixed_t *path); - -#endif /* CAIRO_PATH_FIXED_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed.c deleted file mode 100644 index 4bbf496f075..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-fixed.c +++ /dev/null @@ -1,1589 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-error-private.h" -#include "cairo-list-inline.h" -#include "cairo-path-fixed-private.h" -#include "cairo-slope-private.h" - -static cairo_status_t -_cairo_path_fixed_add (cairo_path_fixed_t *path, - cairo_path_op_t op, - const cairo_point_t *points, - int num_points); - -static void -_cairo_path_fixed_add_buf (cairo_path_fixed_t *path, - cairo_path_buf_t *buf); - -static cairo_path_buf_t * -_cairo_path_buf_create (int size_ops, int size_points); - -static void -_cairo_path_buf_destroy (cairo_path_buf_t *buf); - -static void -_cairo_path_buf_add_op (cairo_path_buf_t *buf, - cairo_path_op_t op); - -static void -_cairo_path_buf_add_points (cairo_path_buf_t *buf, - const cairo_point_t *points, - int num_points); - -void -_cairo_path_fixed_init (cairo_path_fixed_t *path) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (path, sizeof (cairo_path_fixed_t))); - - cairo_list_init (&path->buf.base.link); - - path->buf.base.num_ops = 0; - path->buf.base.num_points = 0; - path->buf.base.size_ops = ARRAY_LENGTH (path->buf.op); - path->buf.base.size_points = ARRAY_LENGTH (path->buf.points); - path->buf.base.op = path->buf.op; - path->buf.base.points = path->buf.points; - - path->current_point.x = 0; - path->current_point.y = 0; - path->last_move_point = path->current_point; - - path->has_current_point = FALSE; - path->needs_move_to = TRUE; - path->has_extents = FALSE; - path->has_curve_to = FALSE; - path->stroke_is_rectilinear = TRUE; - path->fill_is_rectilinear = TRUE; - path->fill_maybe_region = TRUE; - path->fill_is_empty = TRUE; - - path->extents.p1.x = path->extents.p1.y = 0; - path->extents.p2.x = path->extents.p2.y = 0; -} - -cairo_status_t -_cairo_path_fixed_init_copy (cairo_path_fixed_t *path, - const cairo_path_fixed_t *other) -{ - cairo_path_buf_t *buf, *other_buf; - unsigned int num_points, num_ops; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (path, sizeof (cairo_path_fixed_t))); - - cairo_list_init (&path->buf.base.link); - - path->buf.base.op = path->buf.op; - path->buf.base.points = path->buf.points; - path->buf.base.size_ops = ARRAY_LENGTH (path->buf.op); - path->buf.base.size_points = ARRAY_LENGTH (path->buf.points); - - path->current_point = other->current_point; - path->last_move_point = other->last_move_point; - - path->has_current_point = other->has_current_point; - path->needs_move_to = other->needs_move_to; - path->has_extents = other->has_extents; - path->has_curve_to = other->has_curve_to; - path->stroke_is_rectilinear = other->stroke_is_rectilinear; - path->fill_is_rectilinear = other->fill_is_rectilinear; - path->fill_maybe_region = other->fill_maybe_region; - path->fill_is_empty = other->fill_is_empty; - - path->extents = other->extents; - - path->buf.base.num_ops = other->buf.base.num_ops; - path->buf.base.num_points = other->buf.base.num_points; - memcpy (path->buf.op, other->buf.base.op, - other->buf.base.num_ops * sizeof (other->buf.op[0])); - memcpy (path->buf.points, other->buf.points, - other->buf.base.num_points * sizeof (other->buf.points[0])); - - num_points = num_ops = 0; - for (other_buf = cairo_path_buf_next (cairo_path_head (other)); - other_buf != cairo_path_head (other); - other_buf = cairo_path_buf_next (other_buf)) - { - num_ops += other_buf->num_ops; - num_points += other_buf->num_points; - } - - if (num_ops) { - buf = _cairo_path_buf_create (num_ops, num_points); - if (unlikely (buf == NULL)) { - _cairo_path_fixed_fini (path); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - for (other_buf = cairo_path_buf_next (cairo_path_head (other)); - other_buf != cairo_path_head (other); - other_buf = cairo_path_buf_next (other_buf)) - { - memcpy (buf->op + buf->num_ops, other_buf->op, - other_buf->num_ops * sizeof (buf->op[0])); - buf->num_ops += other_buf->num_ops; - - memcpy (buf->points + buf->num_points, other_buf->points, - other_buf->num_points * sizeof (buf->points[0])); - buf->num_points += other_buf->num_points; - } - - _cairo_path_fixed_add_buf (path, buf); - } - - return CAIRO_STATUS_SUCCESS; -} - -unsigned long -_cairo_path_fixed_hash (const cairo_path_fixed_t *path) -{ - unsigned long hash = _CAIRO_HASH_INIT_VALUE; - const cairo_path_buf_t *buf; - unsigned int count; - - count = 0; - cairo_path_foreach_buf_start (buf, path) { - hash = _cairo_hash_bytes (hash, buf->op, - buf->num_ops * sizeof (buf->op[0])); - count += buf->num_ops; - } cairo_path_foreach_buf_end (buf, path); - hash = _cairo_hash_bytes (hash, &count, sizeof (count)); - - count = 0; - cairo_path_foreach_buf_start (buf, path) { - hash = _cairo_hash_bytes (hash, buf->points, - buf->num_points * sizeof (buf->points[0])); - count += buf->num_points; - } cairo_path_foreach_buf_end (buf, path); - hash = _cairo_hash_bytes (hash, &count, sizeof (count)); - - return hash; -} - -unsigned long -_cairo_path_fixed_size (const cairo_path_fixed_t *path) -{ - const cairo_path_buf_t *buf; - int num_points, num_ops; - - num_ops = num_points = 0; - cairo_path_foreach_buf_start (buf, path) { - num_ops += buf->num_ops; - num_points += buf->num_points; - } cairo_path_foreach_buf_end (buf, path); - - return num_ops * sizeof (buf->op[0]) + - num_points * sizeof (buf->points[0]); -} - -cairo_bool_t -_cairo_path_fixed_equal (const cairo_path_fixed_t *a, - const cairo_path_fixed_t *b) -{ - const cairo_path_buf_t *buf_a, *buf_b; - const cairo_path_op_t *ops_a, *ops_b; - const cairo_point_t *points_a, *points_b; - int num_points_a, num_ops_a; - int num_points_b, num_ops_b; - - if (a == b) - return TRUE; - - /* use the flags to quickly differentiate based on contents */ - if (a->has_curve_to != b->has_curve_to) - { - return FALSE; - } - - if (a->extents.p1.x != b->extents.p1.x || - a->extents.p1.y != b->extents.p1.y || - a->extents.p2.x != b->extents.p2.x || - a->extents.p2.y != b->extents.p2.y) - { - return FALSE; - } - - num_ops_a = num_points_a = 0; - cairo_path_foreach_buf_start (buf_a, a) { - num_ops_a += buf_a->num_ops; - num_points_a += buf_a->num_points; - } cairo_path_foreach_buf_end (buf_a, a); - - num_ops_b = num_points_b = 0; - cairo_path_foreach_buf_start (buf_b, b) { - num_ops_b += buf_b->num_ops; - num_points_b += buf_b->num_points; - } cairo_path_foreach_buf_end (buf_b, b); - - if (num_ops_a == 0 && num_ops_b == 0) - return TRUE; - - if (num_ops_a != num_ops_b || num_points_a != num_points_b) - return FALSE; - - buf_a = cairo_path_head (a); - num_points_a = buf_a->num_points; - num_ops_a = buf_a->num_ops; - ops_a = buf_a->op; - points_a = buf_a->points; - - buf_b = cairo_path_head (b); - num_points_b = buf_b->num_points; - num_ops_b = buf_b->num_ops; - ops_b = buf_b->op; - points_b = buf_b->points; - - while (TRUE) { - int num_ops = MIN (num_ops_a, num_ops_b); - int num_points = MIN (num_points_a, num_points_b); - - if (memcmp (ops_a, ops_b, num_ops * sizeof (cairo_path_op_t))) - return FALSE; - if (memcmp (points_a, points_b, num_points * sizeof (cairo_point_t))) - return FALSE; - - num_ops_a -= num_ops; - ops_a += num_ops; - num_points_a -= num_points; - points_a += num_points; - if (num_ops_a == 0 || num_points_a == 0) { - if (num_ops_a || num_points_a) - return FALSE; - - buf_a = cairo_path_buf_next (buf_a); - if (buf_a == cairo_path_head (a)) - break; - - num_points_a = buf_a->num_points; - num_ops_a = buf_a->num_ops; - ops_a = buf_a->op; - points_a = buf_a->points; - } - - num_ops_b -= num_ops; - ops_b += num_ops; - num_points_b -= num_points; - points_b += num_points; - if (num_ops_b == 0 || num_points_b == 0) { - if (num_ops_b || num_points_b) - return FALSE; - - buf_b = cairo_path_buf_next (buf_b); - if (buf_b == cairo_path_head (b)) - break; - - num_points_b = buf_b->num_points; - num_ops_b = buf_b->num_ops; - ops_b = buf_b->op; - points_b = buf_b->points; - } - } - - return TRUE; -} - -cairo_path_fixed_t * -_cairo_path_fixed_create (void) -{ - cairo_path_fixed_t *path; - - path = malloc (sizeof (cairo_path_fixed_t)); - if (!path) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - _cairo_path_fixed_init (path); - return path; -} - -void -_cairo_path_fixed_fini (cairo_path_fixed_t *path) -{ - cairo_path_buf_t *buf; - - buf = cairo_path_buf_next (cairo_path_head (path)); - while (buf != cairo_path_head (path)) { - cairo_path_buf_t *this = buf; - buf = cairo_path_buf_next (buf); - _cairo_path_buf_destroy (this); - } - - VG (VALGRIND_MAKE_MEM_NOACCESS (path, sizeof (cairo_path_fixed_t))); -} - -void -_cairo_path_fixed_destroy (cairo_path_fixed_t *path) -{ - _cairo_path_fixed_fini (path); - free (path); -} - -static cairo_path_op_t -_cairo_path_fixed_last_op (cairo_path_fixed_t *path) -{ - cairo_path_buf_t *buf; - - buf = cairo_path_tail (path); - assert (buf->num_ops != 0); - - return buf->op[buf->num_ops - 1]; -} - -static inline const cairo_point_t * -_cairo_path_fixed_penultimate_point (cairo_path_fixed_t *path) -{ - cairo_path_buf_t *buf; - - buf = cairo_path_tail (path); - if (likely (buf->num_points >= 2)) { - return &buf->points[buf->num_points - 2]; - } else { - cairo_path_buf_t *prev_buf = cairo_path_buf_prev (buf); - - assert (prev_buf->num_points >= 2 - buf->num_points); - return &prev_buf->points[prev_buf->num_points - (2 - buf->num_points)]; - } -} - -static void -_cairo_path_fixed_drop_line_to (cairo_path_fixed_t *path) -{ - cairo_path_buf_t *buf; - - assert (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO); - - buf = cairo_path_tail (path); - buf->num_points--; - buf->num_ops--; -} - -cairo_status_t -_cairo_path_fixed_move_to (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y) -{ - _cairo_path_fixed_new_sub_path (path); - - path->has_current_point = TRUE; - path->current_point.x = x; - path->current_point.y = y; - path->last_move_point = path->current_point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_fixed_move_to_apply (cairo_path_fixed_t *path) -{ - if (likely (! path->needs_move_to)) - return CAIRO_STATUS_SUCCESS; - - path->needs_move_to = FALSE; - - if (path->has_extents) { - _cairo_box_add_point (&path->extents, &path->current_point); - } else { - _cairo_box_set (&path->extents, &path->current_point, &path->current_point); - path->has_extents = TRUE; - } - - if (path->fill_maybe_region) { - path->fill_maybe_region = _cairo_fixed_is_integer (path->current_point.x) && - _cairo_fixed_is_integer (path->current_point.y); - } - - path->last_move_point = path->current_point; - - return _cairo_path_fixed_add (path, CAIRO_PATH_OP_MOVE_TO, &path->current_point, 1); -} - -void -_cairo_path_fixed_new_sub_path (cairo_path_fixed_t *path) -{ - if (! path->needs_move_to) { - /* If the current subpath doesn't need_move_to, it contains at least one command */ - if (path->fill_is_rectilinear) { - /* Implicitly close for fill */ - path->fill_is_rectilinear = path->current_point.x == path->last_move_point.x || - path->current_point.y == path->last_move_point.y; - path->fill_maybe_region &= path->fill_is_rectilinear; - } - path->needs_move_to = TRUE; - } - - path->has_current_point = FALSE; -} - -cairo_status_t -_cairo_path_fixed_rel_move_to (cairo_path_fixed_t *path, - cairo_fixed_t dx, - cairo_fixed_t dy) -{ - if (unlikely (! path->has_current_point)) - return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); - - return _cairo_path_fixed_move_to (path, - path->current_point.x + dx, - path->current_point.y + dy); - -} - -cairo_status_t -_cairo_path_fixed_line_to (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y) -{ - cairo_status_t status; - cairo_point_t point; - - point.x = x; - point.y = y; - - /* When there is not yet a current point, the line_to operation - * becomes a move_to instead. Note: We have to do this by - * explicitly calling into _cairo_path_fixed_move_to to ensure - * that the last_move_point state is updated properly. - */ - if (! path->has_current_point) - return _cairo_path_fixed_move_to (path, point.x, point.y); - - status = _cairo_path_fixed_move_to_apply (path); - if (unlikely (status)) - return status; - - /* If the previous op was but the initial MOVE_TO and this segment - * is degenerate, then we can simply skip this point. Note that - * a move-to followed by a degenerate line-to is a valid path for - * stroking, but at all other times is simply a degenerate segment. - */ - if (_cairo_path_fixed_last_op (path) != CAIRO_PATH_OP_MOVE_TO) { - if (x == path->current_point.x && y == path->current_point.y) - return CAIRO_STATUS_SUCCESS; - } - - /* If the previous op was also a LINE_TO with the same gradient, - * then just change its end-point rather than adding a new op. - */ - if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) { - const cairo_point_t *p; - - p = _cairo_path_fixed_penultimate_point (path); - if (p->x == path->current_point.x && p->y == path->current_point.y) { - /* previous line element was degenerate, replace */ - _cairo_path_fixed_drop_line_to (path); - } else { - cairo_slope_t prev, self; - - _cairo_slope_init (&prev, p, &path->current_point); - _cairo_slope_init (&self, &path->current_point, &point); - if (_cairo_slope_equal (&prev, &self) && - /* cannot trim anti-parallel segments whilst stroking */ - ! _cairo_slope_backwards (&prev, &self)) - { - _cairo_path_fixed_drop_line_to (path); - /* In this case the flags might be more restrictive than - * what we actually need. - * When changing the flags definition we should check if - * changing the line_to point can affect them. - */ - } - } - } - - if (path->stroke_is_rectilinear) { - path->stroke_is_rectilinear = path->current_point.x == x || - path->current_point.y == y; - path->fill_is_rectilinear &= path->stroke_is_rectilinear; - path->fill_maybe_region &= path->fill_is_rectilinear; - if (path->fill_maybe_region) { - path->fill_maybe_region = _cairo_fixed_is_integer (x) && - _cairo_fixed_is_integer (y); - } - if (path->fill_is_empty) { - path->fill_is_empty = path->current_point.x == x && - path->current_point.y == y; - } - } - - path->current_point = point; - - _cairo_box_add_point (&path->extents, &point); - - return _cairo_path_fixed_add (path, CAIRO_PATH_OP_LINE_TO, &point, 1); -} - -cairo_status_t -_cairo_path_fixed_rel_line_to (cairo_path_fixed_t *path, - cairo_fixed_t dx, - cairo_fixed_t dy) -{ - if (unlikely (! path->has_current_point)) - return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); - - return _cairo_path_fixed_line_to (path, - path->current_point.x + dx, - path->current_point.y + dy); -} - -cairo_status_t -_cairo_path_fixed_curve_to (cairo_path_fixed_t *path, - cairo_fixed_t x0, cairo_fixed_t y0, - cairo_fixed_t x1, cairo_fixed_t y1, - cairo_fixed_t x2, cairo_fixed_t y2) -{ - cairo_status_t status; - cairo_point_t point[3]; - - /* If this curves does not move, replace it with a line-to. - * This frequently happens with rounded-rectangles and r==0. - */ - if (path->current_point.x == x2 && path->current_point.y == y2) { - if (x1 == x2 && x0 == x2 && y1 == y2 && y0 == y2) - return _cairo_path_fixed_line_to (path, x2, y2); - - /* We may want to check for the absence of a cusp, in which case - * we can also replace the curve-to with a line-to. - */ - } - - /* make sure subpaths are started properly */ - if (! path->has_current_point) { - status = _cairo_path_fixed_move_to (path, x0, y0); - assert (status == CAIRO_STATUS_SUCCESS); - } - - status = _cairo_path_fixed_move_to_apply (path); - if (unlikely (status)) - return status; - - /* If the previous op was a degenerate LINE_TO, drop it. */ - if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) { - const cairo_point_t *p; - - p = _cairo_path_fixed_penultimate_point (path); - if (p->x == path->current_point.x && p->y == path->current_point.y) { - /* previous line element was degenerate, replace */ - _cairo_path_fixed_drop_line_to (path); - } - } - - point[0].x = x0; point[0].y = y0; - point[1].x = x1; point[1].y = y1; - point[2].x = x2; point[2].y = y2; - - _cairo_box_add_curve_to (&path->extents, &path->current_point, - &point[0], &point[1], &point[2]); - - path->current_point = point[2]; - path->has_curve_to = TRUE; - path->stroke_is_rectilinear = FALSE; - path->fill_is_rectilinear = FALSE; - path->fill_maybe_region = FALSE; - path->fill_is_empty = FALSE; - - return _cairo_path_fixed_add (path, CAIRO_PATH_OP_CURVE_TO, point, 3); -} - -cairo_status_t -_cairo_path_fixed_rel_curve_to (cairo_path_fixed_t *path, - cairo_fixed_t dx0, cairo_fixed_t dy0, - cairo_fixed_t dx1, cairo_fixed_t dy1, - cairo_fixed_t dx2, cairo_fixed_t dy2) -{ - if (unlikely (! path->has_current_point)) - return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); - - return _cairo_path_fixed_curve_to (path, - path->current_point.x + dx0, - path->current_point.y + dy0, - - path->current_point.x + dx1, - path->current_point.y + dy1, - - path->current_point.x + dx2, - path->current_point.y + dy2); -} - -cairo_status_t -_cairo_path_fixed_close_path (cairo_path_fixed_t *path) -{ - cairo_status_t status; - - if (! path->has_current_point) - return CAIRO_STATUS_SUCCESS; - - /* - * Add a line_to, to compute flags and solve any degeneracy. - * It will be removed later (if it was actually added). - */ - status = _cairo_path_fixed_line_to (path, - path->last_move_point.x, - path->last_move_point.y); - if (unlikely (status)) - return status; - - /* - * If the command used to close the path is a line_to, drop it. - * We must check that last command is actually a line_to, - * because the path could have been closed with a curve_to (and - * the previous line_to not added as it would be degenerate). - */ - if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) - _cairo_path_fixed_drop_line_to (path); - - path->needs_move_to = TRUE; /* After close_path, add an implicit move_to */ - - return _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0); -} - -cairo_bool_t -_cairo_path_fixed_get_current_point (cairo_path_fixed_t *path, - cairo_fixed_t *x, - cairo_fixed_t *y) -{ - if (! path->has_current_point) - return FALSE; - - *x = path->current_point.x; - *y = path->current_point.y; - - return TRUE; -} - -static cairo_status_t -_cairo_path_fixed_add (cairo_path_fixed_t *path, - cairo_path_op_t op, - const cairo_point_t *points, - int num_points) -{ - cairo_path_buf_t *buf = cairo_path_tail (path); - - if (buf->num_ops + 1 > buf->size_ops || - buf->num_points + num_points > buf->size_points) - { - buf = _cairo_path_buf_create (buf->num_ops * 2, buf->num_points * 2); - if (unlikely (buf == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_path_fixed_add_buf (path, buf); - } - - if (WATCH_PATH) { - const char *op_str[] = { - "move-to", - "line-to", - "curve-to", - "close-path", - }; - char buf[1024]; - int len = 0; - int i; - - len += snprintf (buf + len, sizeof (buf), "["); - for (i = 0; i < num_points; i++) { - if (i != 0) - len += snprintf (buf + len, sizeof (buf), " "); - len += snprintf (buf + len, sizeof (buf), "(%f, %f)", - _cairo_fixed_to_double (points[i].x), - _cairo_fixed_to_double (points[i].y)); - } - len += snprintf (buf + len, sizeof (buf), "]"); - -#define STRINGIFYFLAG(x) (path->x ? #x " " : "") - fprintf (stderr, - "_cairo_path_fixed_add (%s, %s) [%s%s%s%s%s%s%s%s]\n", - op_str[(int) op], buf, - STRINGIFYFLAG(has_current_point), - STRINGIFYFLAG(needs_move_to), - STRINGIFYFLAG(has_extents), - STRINGIFYFLAG(has_curve_to), - STRINGIFYFLAG(stroke_is_rectilinear), - STRINGIFYFLAG(fill_is_rectilinear), - STRINGIFYFLAG(fill_is_empty), - STRINGIFYFLAG(fill_maybe_region) - ); -#undef STRINGIFYFLAG - } - - _cairo_path_buf_add_op (buf, op); - _cairo_path_buf_add_points (buf, points, num_points); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_path_fixed_add_buf (cairo_path_fixed_t *path, - cairo_path_buf_t *buf) -{ - cairo_list_add_tail (&buf->link, &cairo_path_head (path)->link); -} - -COMPILE_TIME_ASSERT (sizeof (cairo_path_op_t) == 1); -static cairo_path_buf_t * -_cairo_path_buf_create (int size_ops, int size_points) -{ - cairo_path_buf_t *buf; - - /* adjust size_ops to ensure that buf->points is naturally aligned */ - size_ops += sizeof (double) - ((sizeof (cairo_path_buf_t) + size_ops) % sizeof (double)); - buf = _cairo_malloc_ab_plus_c (size_points, sizeof (cairo_point_t), size_ops + sizeof (cairo_path_buf_t)); - if (buf) { - buf->num_ops = 0; - buf->num_points = 0; - buf->size_ops = size_ops; - buf->size_points = size_points; - - buf->op = (cairo_path_op_t *) (buf + 1); - buf->points = (cairo_point_t *) (buf->op + size_ops); - } - - return buf; -} - -static void -_cairo_path_buf_destroy (cairo_path_buf_t *buf) -{ - free (buf); -} - -static void -_cairo_path_buf_add_op (cairo_path_buf_t *buf, - cairo_path_op_t op) -{ - buf->op[buf->num_ops++] = op; -} - -static void -_cairo_path_buf_add_points (cairo_path_buf_t *buf, - const cairo_point_t *points, - int num_points) -{ - if (num_points == 0) - return; - - memcpy (buf->points + buf->num_points, - points, - sizeof (points[0]) * num_points); - buf->num_points += num_points; -} - -cairo_status_t -_cairo_path_fixed_interpret (const cairo_path_fixed_t *path, - cairo_path_fixed_move_to_func_t *move_to, - cairo_path_fixed_line_to_func_t *line_to, - cairo_path_fixed_curve_to_func_t *curve_to, - cairo_path_fixed_close_path_func_t *close_path, - void *closure) -{ - const cairo_path_buf_t *buf; - cairo_status_t status; - - cairo_path_foreach_buf_start (buf, path) { - const cairo_point_t *points = buf->points; - unsigned int i; - - for (i = 0; i < buf->num_ops; i++) { - switch (buf->op[i]) { - case CAIRO_PATH_OP_MOVE_TO: - status = (*move_to) (closure, &points[0]); - points += 1; - break; - case CAIRO_PATH_OP_LINE_TO: - status = (*line_to) (closure, &points[0]); - points += 1; - break; - case CAIRO_PATH_OP_CURVE_TO: - status = (*curve_to) (closure, &points[0], &points[1], &points[2]); - points += 3; - break; - default: - ASSERT_NOT_REACHED; - case CAIRO_PATH_OP_CLOSE_PATH: - status = (*close_path) (closure); - break; - } - - if (unlikely (status)) - return status; - } - } cairo_path_foreach_buf_end (buf, path); - - if (path->needs_move_to && path->has_current_point) - return (*move_to) (closure, &path->current_point); - - return CAIRO_STATUS_SUCCESS; -} - -typedef struct _cairo_path_fixed_append_closure { - cairo_point_t offset; - cairo_path_fixed_t *path; -} cairo_path_fixed_append_closure_t; - -static cairo_status_t -_append_move_to (void *abstract_closure, - const cairo_point_t *point) -{ - cairo_path_fixed_append_closure_t *closure = abstract_closure; - - return _cairo_path_fixed_move_to (closure->path, - point->x + closure->offset.x, - point->y + closure->offset.y); -} - -static cairo_status_t -_append_line_to (void *abstract_closure, - const cairo_point_t *point) -{ - cairo_path_fixed_append_closure_t *closure = abstract_closure; - - return _cairo_path_fixed_line_to (closure->path, - point->x + closure->offset.x, - point->y + closure->offset.y); -} - -static cairo_status_t -_append_curve_to (void *abstract_closure, - const cairo_point_t *p0, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - cairo_path_fixed_append_closure_t *closure = abstract_closure; - - return _cairo_path_fixed_curve_to (closure->path, - p0->x + closure->offset.x, - p0->y + closure->offset.y, - p1->x + closure->offset.x, - p1->y + closure->offset.y, - p2->x + closure->offset.x, - p2->y + closure->offset.y); -} - -static cairo_status_t -_append_close_path (void *abstract_closure) -{ - cairo_path_fixed_append_closure_t *closure = abstract_closure; - - return _cairo_path_fixed_close_path (closure->path); -} - -cairo_status_t -_cairo_path_fixed_append (cairo_path_fixed_t *path, - const cairo_path_fixed_t *other, - cairo_fixed_t tx, - cairo_fixed_t ty) -{ - cairo_path_fixed_append_closure_t closure; - - closure.path = path; - closure.offset.x = tx; - closure.offset.y = ty; - - return _cairo_path_fixed_interpret (other, - _append_move_to, - _append_line_to, - _append_curve_to, - _append_close_path, - &closure); -} - -static void -_cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path, - cairo_fixed_t offx, - cairo_fixed_t offy, - cairo_fixed_t scalex, - cairo_fixed_t scaley) -{ - cairo_path_buf_t *buf; - unsigned int i; - - if (scalex == CAIRO_FIXED_ONE && scaley == CAIRO_FIXED_ONE) { - _cairo_path_fixed_translate (path, offx, offy); - return; - } - - path->last_move_point.x = _cairo_fixed_mul (scalex, path->last_move_point.x) + offx; - path->last_move_point.y = _cairo_fixed_mul (scaley, path->last_move_point.y) + offy; - path->current_point.x = _cairo_fixed_mul (scalex, path->current_point.x) + offx; - path->current_point.y = _cairo_fixed_mul (scaley, path->current_point.y) + offy; - - path->fill_maybe_region = TRUE; - - cairo_path_foreach_buf_start (buf, path) { - for (i = 0; i < buf->num_points; i++) { - if (scalex != CAIRO_FIXED_ONE) - buf->points[i].x = _cairo_fixed_mul (buf->points[i].x, scalex); - buf->points[i].x += offx; - - if (scaley != CAIRO_FIXED_ONE) - buf->points[i].y = _cairo_fixed_mul (buf->points[i].y, scaley); - buf->points[i].y += offy; - - if (path->fill_maybe_region) { - path->fill_maybe_region = _cairo_fixed_is_integer (buf->points[i].x) && - _cairo_fixed_is_integer (buf->points[i].y); - } - } - } cairo_path_foreach_buf_end (buf, path); - - path->fill_maybe_region &= path->fill_is_rectilinear; - - path->extents.p1.x = _cairo_fixed_mul (scalex, path->extents.p1.x) + offx; - path->extents.p2.x = _cairo_fixed_mul (scalex, path->extents.p2.x) + offx; - if (scalex < 0) { - cairo_fixed_t t = path->extents.p1.x; - path->extents.p1.x = path->extents.p2.x; - path->extents.p2.x = t; - } - - path->extents.p1.y = _cairo_fixed_mul (scaley, path->extents.p1.y) + offy; - path->extents.p2.y = _cairo_fixed_mul (scaley, path->extents.p2.y) + offy; - if (scaley < 0) { - cairo_fixed_t t = path->extents.p1.y; - path->extents.p1.y = path->extents.p2.y; - path->extents.p2.y = t; - } -} - -void -_cairo_path_fixed_translate (cairo_path_fixed_t *path, - cairo_fixed_t offx, - cairo_fixed_t offy) -{ - cairo_path_buf_t *buf; - unsigned int i; - - if (offx == 0 && offy == 0) - return; - - path->last_move_point.x += offx; - path->last_move_point.y += offy; - path->current_point.x += offx; - path->current_point.y += offy; - - path->fill_maybe_region = TRUE; - - cairo_path_foreach_buf_start (buf, path) { - for (i = 0; i < buf->num_points; i++) { - buf->points[i].x += offx; - buf->points[i].y += offy; - - if (path->fill_maybe_region) { - path->fill_maybe_region = _cairo_fixed_is_integer (buf->points[i].x) && - _cairo_fixed_is_integer (buf->points[i].y); - } - } - } cairo_path_foreach_buf_end (buf, path); - - path->fill_maybe_region &= path->fill_is_rectilinear; - - path->extents.p1.x += offx; - path->extents.p1.y += offy; - path->extents.p2.x += offx; - path->extents.p2.y += offy; -} - - -static inline void -_cairo_path_fixed_transform_point (cairo_point_t *p, - const cairo_matrix_t *matrix) -{ - double dx, dy; - - dx = _cairo_fixed_to_double (p->x); - dy = _cairo_fixed_to_double (p->y); - cairo_matrix_transform_point (matrix, &dx, &dy); - p->x = _cairo_fixed_from_double (dx); - p->y = _cairo_fixed_from_double (dy); -} - -/** - * _cairo_path_fixed_transform: - * @path: a #cairo_path_fixed_t to be transformed - * @matrix: a #cairo_matrix_t - * - * Transform the fixed-point path according to the given matrix. - * There is a fast path for the case where @matrix has no rotation - * or shear. - **/ -void -_cairo_path_fixed_transform (cairo_path_fixed_t *path, - const cairo_matrix_t *matrix) -{ - cairo_box_t extents; - cairo_point_t point; - cairo_path_buf_t *buf; - unsigned int i; - - if (matrix->yx == 0.0 && matrix->xy == 0.0) { - /* Fast path for the common case of scale+transform */ - _cairo_path_fixed_offset_and_scale (path, - _cairo_fixed_from_double (matrix->x0), - _cairo_fixed_from_double (matrix->y0), - _cairo_fixed_from_double (matrix->xx), - _cairo_fixed_from_double (matrix->yy)); - return; - } - - _cairo_path_fixed_transform_point (&path->last_move_point, matrix); - _cairo_path_fixed_transform_point (&path->current_point, matrix); - - buf = cairo_path_head (path); - if (buf->num_points == 0) - return; - - extents = path->extents; - point = buf->points[0]; - _cairo_path_fixed_transform_point (&point, matrix); - _cairo_box_set (&path->extents, &point, &point); - - cairo_path_foreach_buf_start (buf, path) { - for (i = 0; i < buf->num_points; i++) { - _cairo_path_fixed_transform_point (&buf->points[i], matrix); - _cairo_box_add_point (&path->extents, &buf->points[i]); - } - } cairo_path_foreach_buf_end (buf, path); - - if (path->has_curve_to) { - cairo_bool_t is_tight; - - _cairo_matrix_transform_bounding_box_fixed (matrix, &extents, &is_tight); - if (!is_tight) { - cairo_bool_t has_extents; - - has_extents = _cairo_path_bounder_extents (path, &extents); - assert (has_extents); - } - path->extents = extents; - } - - /* flags might become more strict than needed */ - path->stroke_is_rectilinear = FALSE; - path->fill_is_rectilinear = FALSE; - path->fill_is_empty = FALSE; - path->fill_maybe_region = FALSE; -} - -/* Closure for path flattening */ -typedef struct cairo_path_flattener { - double tolerance; - cairo_point_t current_point; - cairo_path_fixed_move_to_func_t *move_to; - cairo_path_fixed_line_to_func_t *line_to; - cairo_path_fixed_close_path_func_t *close_path; - void *closure; -} cpf_t; - -static cairo_status_t -_cpf_move_to (void *closure, - const cairo_point_t *point) -{ - cpf_t *cpf = closure; - - cpf->current_point = *point; - - return cpf->move_to (cpf->closure, point); -} - -static cairo_status_t -_cpf_line_to (void *closure, - const cairo_point_t *point) -{ - cpf_t *cpf = closure; - - cpf->current_point = *point; - - return cpf->line_to (cpf->closure, point); -} - -static cairo_status_t -_cpf_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - cpf_t *cpf = closure; - cairo_spline_t spline; - - cairo_point_t *p0 = &cpf->current_point; - - if (! _cairo_spline_init (&spline, - (cairo_spline_add_point_func_t)cpf->line_to, - cpf->closure, - p0, p1, p2, p3)) - { - return _cpf_line_to (closure, p3); - } - - cpf->current_point = *p3; - - return _cairo_spline_decompose (&spline, cpf->tolerance); -} - -static cairo_status_t -_cpf_close_path (void *closure) -{ - cpf_t *cpf = closure; - - return cpf->close_path (cpf->closure); -} - -cairo_status_t -_cairo_path_fixed_interpret_flat (const cairo_path_fixed_t *path, - cairo_path_fixed_move_to_func_t *move_to, - cairo_path_fixed_line_to_func_t *line_to, - cairo_path_fixed_close_path_func_t *close_path, - void *closure, - double tolerance) -{ - cpf_t flattener; - - if (! path->has_curve_to) { - return _cairo_path_fixed_interpret (path, - move_to, - line_to, - NULL, - close_path, - closure); - } - - flattener.tolerance = tolerance; - flattener.move_to = move_to; - flattener.line_to = line_to; - flattener.close_path = close_path; - flattener.closure = closure; - return _cairo_path_fixed_interpret (path, - _cpf_move_to, - _cpf_line_to, - _cpf_curve_to, - _cpf_close_path, - &flattener); -} - -static inline void -_canonical_box (cairo_box_t *box, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - if (p1->x <= p2->x) { - box->p1.x = p1->x; - box->p2.x = p2->x; - } else { - box->p1.x = p2->x; - box->p2.x = p1->x; - } - - if (p1->y <= p2->y) { - box->p1.y = p1->y; - box->p2.y = p2->y; - } else { - box->p1.y = p2->y; - box->p2.y = p1->y; - } -} - -static inline cairo_bool_t -_path_is_quad (const cairo_path_fixed_t *path) -{ - const cairo_path_buf_t *buf = cairo_path_head (path); - - /* Do we have the right number of ops? */ - if (buf->num_ops < 4 || buf->num_ops > 6) - return FALSE; - - /* Check whether the ops are those that would be used for a rectangle */ - if (buf->op[0] != CAIRO_PATH_OP_MOVE_TO || - buf->op[1] != CAIRO_PATH_OP_LINE_TO || - buf->op[2] != CAIRO_PATH_OP_LINE_TO || - buf->op[3] != CAIRO_PATH_OP_LINE_TO) - { - return FALSE; - } - - /* we accept an implicit close for filled paths */ - if (buf->num_ops > 4) { - /* Now, there are choices. The rectangle might end with a LINE_TO - * (to the original point), but this isn't required. If it - * doesn't, then it must end with a CLOSE_PATH. */ - if (buf->op[4] == CAIRO_PATH_OP_LINE_TO) { - if (buf->points[4].x != buf->points[0].x || - buf->points[4].y != buf->points[0].y) - return FALSE; - } else if (buf->op[4] != CAIRO_PATH_OP_CLOSE_PATH) { - return FALSE; - } - - if (buf->num_ops == 6) { - /* A trailing CLOSE_PATH or MOVE_TO is ok */ - if (buf->op[5] != CAIRO_PATH_OP_MOVE_TO && - buf->op[5] != CAIRO_PATH_OP_CLOSE_PATH) - return FALSE; - } - } - - return TRUE; -} - -static inline cairo_bool_t -_points_form_rect (const cairo_point_t *points) -{ - if (points[0].y == points[1].y && - points[1].x == points[2].x && - points[2].y == points[3].y && - points[3].x == points[0].x) - return TRUE; - if (points[0].x == points[1].x && - points[1].y == points[2].y && - points[2].x == points[3].x && - points[3].y == points[0].y) - return TRUE; - return FALSE; -} - -/* - * Check whether the given path contains a single rectangle. - */ -cairo_bool_t -_cairo_path_fixed_is_box (const cairo_path_fixed_t *path, - cairo_box_t *box) -{ - const cairo_path_buf_t *buf; - - if (! path->fill_is_rectilinear) - return FALSE; - - if (! _path_is_quad (path)) - return FALSE; - - buf = cairo_path_head (path); - if (_points_form_rect (buf->points)) { - _canonical_box (box, &buf->points[0], &buf->points[2]); - return TRUE; - } - - return FALSE; -} - -/* Determine whether two lines A->B and C->D intersect based on the - * algorithm described here: http://paulbourke.net/geometry/pointlineplane/ */ -static inline cairo_bool_t -_lines_intersect_or_are_coincident (cairo_point_t a, - cairo_point_t b, - cairo_point_t c, - cairo_point_t d) -{ - cairo_int64_t numerator_a, numerator_b, denominator; - cairo_bool_t denominator_negative; - - denominator = _cairo_int64_sub (_cairo_int32x32_64_mul (d.y - c.y, b.x - a.x), - _cairo_int32x32_64_mul (d.x - c.x, b.y - a.y)); - numerator_a = _cairo_int64_sub (_cairo_int32x32_64_mul (d.x - c.x, a.y - c.y), - _cairo_int32x32_64_mul (d.y - c.y, a.x - c.x)); - numerator_b = _cairo_int64_sub (_cairo_int32x32_64_mul (b.x - a.x, a.y - c.y), - _cairo_int32x32_64_mul (b.y - a.y, a.x - c.x)); - - if (_cairo_int64_is_zero (denominator)) { - /* If the denominator and numerators are both zero, - * the lines are coincident. */ - if (_cairo_int64_is_zero (numerator_a) && _cairo_int64_is_zero (numerator_b)) - return TRUE; - - /* Otherwise, a zero denominator indicates the lines are - * parallel and never intersect. */ - return FALSE; - } - - /* The lines intersect if both quotients are between 0 and 1 (exclusive). */ - - /* We first test whether either quotient is a negative number. */ - denominator_negative = _cairo_int64_negative (denominator); - if (_cairo_int64_negative (numerator_a) ^ denominator_negative) - return FALSE; - if (_cairo_int64_negative (numerator_b) ^ denominator_negative) - return FALSE; - - /* A zero quotient indicates an "intersection" at an endpoint, which - * we aren't considering a true intersection. */ - if (_cairo_int64_is_zero (numerator_a) || _cairo_int64_is_zero (numerator_b)) - return FALSE; - - /* If the absolute value of the numerator is larger than or equal to the - * denominator the result of the division would be greater than or equal - * to one. */ - if (! denominator_negative) { - if (! _cairo_int64_lt (numerator_a, denominator) || - ! _cairo_int64_lt (numerator_b, denominator)) - return FALSE; - } else { - if (! _cairo_int64_lt (denominator, numerator_a) || - ! _cairo_int64_lt (denominator, numerator_b)) - return FALSE; - } - - return TRUE; -} - -cairo_bool_t -_cairo_path_fixed_is_simple_quad (const cairo_path_fixed_t *path) -{ - const cairo_point_t *points; - - if (! _path_is_quad (path)) - return FALSE; - - points = cairo_path_head (path)->points; - if (_points_form_rect (points)) - return TRUE; - - if (_lines_intersect_or_are_coincident (points[0], points[1], - points[3], points[2])) - return FALSE; - - if (_lines_intersect_or_are_coincident (points[0], points[3], - points[1], points[2])) - return FALSE; - - return TRUE; -} - -cairo_bool_t -_cairo_path_fixed_is_stroke_box (const cairo_path_fixed_t *path, - cairo_box_t *box) -{ - const cairo_path_buf_t *buf = cairo_path_head (path); - - if (! path->fill_is_rectilinear) - return FALSE; - - /* Do we have the right number of ops? */ - if (buf->num_ops != 5) - return FALSE; - - /* Check whether the ops are those that would be used for a rectangle */ - if (buf->op[0] != CAIRO_PATH_OP_MOVE_TO || - buf->op[1] != CAIRO_PATH_OP_LINE_TO || - buf->op[2] != CAIRO_PATH_OP_LINE_TO || - buf->op[3] != CAIRO_PATH_OP_LINE_TO || - buf->op[4] != CAIRO_PATH_OP_CLOSE_PATH) - { - return FALSE; - } - - /* Ok, we may have a box, if the points line up */ - if (buf->points[0].y == buf->points[1].y && - buf->points[1].x == buf->points[2].x && - buf->points[2].y == buf->points[3].y && - buf->points[3].x == buf->points[0].x) - { - _canonical_box (box, &buf->points[0], &buf->points[2]); - return TRUE; - } - - if (buf->points[0].x == buf->points[1].x && - buf->points[1].y == buf->points[2].y && - buf->points[2].x == buf->points[3].x && - buf->points[3].y == buf->points[0].y) - { - _canonical_box (box, &buf->points[0], &buf->points[2]); - return TRUE; - } - - return FALSE; -} - -/* - * Check whether the given path contains a single rectangle - * that is logically equivalent to: - * - * cairo_move_to (cr, x, y); - * cairo_rel_line_to (cr, width, 0); - * cairo_rel_line_to (cr, 0, height); - * cairo_rel_line_to (cr, -width, 0); - * cairo_close_path (cr); - * - */ -cairo_bool_t -_cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path, - cairo_box_t *box) -{ - const cairo_path_buf_t *buf; - - if (! _cairo_path_fixed_is_box (path, box)) - return FALSE; - - /* This check is valid because the current implementation of - * _cairo_path_fixed_is_box () only accepts rectangles like: - * move,line,line,line[,line|close[,close|move]]. */ - buf = cairo_path_head (path); - if (buf->num_ops > 4) - return TRUE; - - return FALSE; -} - -void -_cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter, - const cairo_path_fixed_t *path) -{ - iter->first = iter->buf = cairo_path_head (path); - iter->n_op = 0; - iter->n_point = 0; -} - -static cairo_bool_t -_cairo_path_fixed_iter_next_op (cairo_path_fixed_iter_t *iter) -{ - if (++iter->n_op >= iter->buf->num_ops) { - iter->buf = cairo_path_buf_next (iter->buf); - if (iter->buf == iter->first) { - iter->buf = NULL; - return FALSE; - } - - iter->n_op = 0; - iter->n_point = 0; - } - - return TRUE; -} - -cairo_bool_t -_cairo_path_fixed_iter_is_fill_box (cairo_path_fixed_iter_t *_iter, - cairo_box_t *box) -{ - cairo_point_t points[5]; - cairo_path_fixed_iter_t iter; - - if (_iter->buf == NULL) - return FALSE; - - iter = *_iter; - - if (iter.n_op == iter.buf->num_ops && ! _cairo_path_fixed_iter_next_op (&iter)) - return FALSE; - - /* Check whether the ops are those that would be used for a rectangle */ - if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_MOVE_TO) - return FALSE; - points[0] = iter.buf->points[iter.n_point++]; - if (! _cairo_path_fixed_iter_next_op (&iter)) - return FALSE; - - if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_LINE_TO) - return FALSE; - points[1] = iter.buf->points[iter.n_point++]; - if (! _cairo_path_fixed_iter_next_op (&iter)) - return FALSE; - - /* a horizontal/vertical closed line is also a degenerate rectangle */ - switch (iter.buf->op[iter.n_op]) { - case CAIRO_PATH_OP_CLOSE_PATH: - _cairo_path_fixed_iter_next_op (&iter); - case CAIRO_PATH_OP_MOVE_TO: /* implicit close */ - box->p1 = box->p2 = points[0]; - *_iter = iter; - return TRUE; - default: - return FALSE; - case CAIRO_PATH_OP_LINE_TO: - break; - } - - points[2] = iter.buf->points[iter.n_point++]; - if (! _cairo_path_fixed_iter_next_op (&iter)) - return FALSE; - - if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_LINE_TO) - return FALSE; - points[3] = iter.buf->points[iter.n_point++]; - - /* Now, there are choices. The rectangle might end with a LINE_TO - * (to the original point), but this isn't required. If it - * doesn't, then it must end with a CLOSE_PATH (which may be implicit). */ - if (! _cairo_path_fixed_iter_next_op (&iter)) { - /* implicit close due to fill */ - } else if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_LINE_TO) { - points[4] = iter.buf->points[iter.n_point++]; - if (points[4].x != points[0].x || points[4].y != points[0].y) - return FALSE; - _cairo_path_fixed_iter_next_op (&iter); - } else if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_CLOSE_PATH) { - _cairo_path_fixed_iter_next_op (&iter); - } else if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_MOVE_TO) { - /* implicit close-path due to new-sub-path */ - } else { - return FALSE; - } - - /* Ok, we may have a box, if the points line up */ - if (points[0].y == points[1].y && - points[1].x == points[2].x && - points[2].y == points[3].y && - points[3].x == points[0].x) - { - box->p1 = points[0]; - box->p2 = points[2]; - *_iter = iter; - return TRUE; - } - - if (points[0].x == points[1].x && - points[1].y == points[2].y && - points[2].x == points[3].x && - points[3].y == points[0].y) - { - box->p1 = points[1]; - box->p2 = points[3]; - *_iter = iter; - return TRUE; - } - - return FALSE; -} - -cairo_bool_t -_cairo_path_fixed_iter_at_end (const cairo_path_fixed_iter_t *iter) -{ - if (iter->buf == NULL) - return TRUE; - - return iter->n_op == iter->buf->num_ops; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-in-fill.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-in-fill.c deleted file mode 100644 index 1787fb1a3ba..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-in-fill.c +++ /dev/null @@ -1,290 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-path-fixed-private.h" - -typedef struct cairo_in_fill { - double tolerance; - cairo_bool_t on_edge; - int winding; - - cairo_fixed_t x, y; - - cairo_bool_t has_current_point; - cairo_point_t current_point; - cairo_point_t first_point; -} cairo_in_fill_t; - -static void -_cairo_in_fill_init (cairo_in_fill_t *in_fill, - double tolerance, - double x, - double y) -{ - in_fill->on_edge = FALSE; - in_fill->winding = 0; - in_fill->tolerance = tolerance; - - in_fill->x = _cairo_fixed_from_double (x); - in_fill->y = _cairo_fixed_from_double (y); - - in_fill->has_current_point = FALSE; - in_fill->current_point.x = 0; - in_fill->current_point.y = 0; -} - -static void -_cairo_in_fill_fini (cairo_in_fill_t *in_fill) -{ -} - -static int -edge_compare_for_y_against_x (const cairo_point_t *p1, - const cairo_point_t *p2, - cairo_fixed_t y, - cairo_fixed_t x) -{ - cairo_fixed_t adx, ady; - cairo_fixed_t dx, dy; - cairo_int64_t L, R; - - adx = p2->x - p1->x; - dx = x - p1->x; - - if (adx == 0) - return -dx; - if ((adx ^ dx) < 0) - return adx; - - dy = y - p1->y; - ady = p2->y - p1->y; - - L = _cairo_int32x32_64_mul (dy, adx); - R = _cairo_int32x32_64_mul (dx, ady); - - return _cairo_int64_cmp (L, R); -} - -static void -_cairo_in_fill_add_edge (cairo_in_fill_t *in_fill, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - int dir; - - if (in_fill->on_edge) - return; - - /* count the number of edge crossing to -∞ */ - - dir = 1; - if (p2->y < p1->y) { - const cairo_point_t *tmp; - - tmp = p1; - p1 = p2; - p2 = tmp; - - dir = -1; - } - - /* First check whether the query is on an edge */ - if ((p1->x == in_fill->x && p1->y == in_fill->y) || - (p2->x == in_fill->x && p2->y == in_fill->y) || - (! (p2->y < in_fill->y || p1->y > in_fill->y || - (p1->x > in_fill->x && p2->x > in_fill->x) || - (p1->x < in_fill->x && p2->x < in_fill->x)) && - edge_compare_for_y_against_x (p1, p2, in_fill->y, in_fill->x) == 0)) - { - in_fill->on_edge = TRUE; - return; - } - - /* edge is entirely above or below, note the shortening rule */ - if (p2->y <= in_fill->y || p1->y > in_fill->y) - return; - - /* edge lies wholly to the right */ - if (p1->x >= in_fill->x && p2->x >= in_fill->x) - return; - - if ((p1->x <= in_fill->x && p2->x <= in_fill->x) || - edge_compare_for_y_against_x (p1, p2, in_fill->y, in_fill->x) < 0) - { - in_fill->winding += dir; - } -} - -static cairo_status_t -_cairo_in_fill_move_to (void *closure, - const cairo_point_t *point) -{ - cairo_in_fill_t *in_fill = closure; - - /* implicit close path */ - if (in_fill->has_current_point) { - _cairo_in_fill_add_edge (in_fill, - &in_fill->current_point, - &in_fill->first_point); - } - - in_fill->first_point = *point; - in_fill->current_point = *point; - in_fill->has_current_point = TRUE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_in_fill_line_to (void *closure, - const cairo_point_t *point) -{ - cairo_in_fill_t *in_fill = closure; - - if (in_fill->has_current_point) - _cairo_in_fill_add_edge (in_fill, &in_fill->current_point, point); - - in_fill->current_point = *point; - in_fill->has_current_point = TRUE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_in_fill_curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - cairo_in_fill_t *in_fill = closure; - cairo_spline_t spline; - cairo_fixed_t top, bot, left; - - /* first reject based on bbox */ - bot = top = in_fill->current_point.y; - if (b->y < top) top = b->y; - if (b->y > bot) bot = b->y; - if (c->y < top) top = c->y; - if (c->y > bot) bot = c->y; - if (d->y < top) top = d->y; - if (d->y > bot) bot = d->y; - if (bot < in_fill->y || top > in_fill->y) { - in_fill->current_point = *d; - return CAIRO_STATUS_SUCCESS; - } - - left = in_fill->current_point.x; - if (b->x < left) left = b->x; - if (c->x < left) left = c->x; - if (d->x < left) left = d->x; - if (left > in_fill->x) { - in_fill->current_point = *d; - return CAIRO_STATUS_SUCCESS; - } - - /* XXX Investigate direct inspection of the inflections? */ - if (! _cairo_spline_init (&spline, - (cairo_spline_add_point_func_t)_cairo_in_fill_line_to, - in_fill, - &in_fill->current_point, b, c, d)) - { - return CAIRO_STATUS_SUCCESS; - } - - return _cairo_spline_decompose (&spline, in_fill->tolerance); -} - -static cairo_status_t -_cairo_in_fill_close_path (void *closure) -{ - cairo_in_fill_t *in_fill = closure; - - if (in_fill->has_current_point) { - _cairo_in_fill_add_edge (in_fill, - &in_fill->current_point, - &in_fill->first_point); - - in_fill->has_current_point = FALSE; - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_bool_t -_cairo_path_fixed_in_fill (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - double x, - double y) -{ - cairo_in_fill_t in_fill; - cairo_status_t status; - cairo_bool_t is_inside; - - if (_cairo_path_fixed_fill_is_empty (path)) - return FALSE; - - _cairo_in_fill_init (&in_fill, tolerance, x, y); - - status = _cairo_path_fixed_interpret (path, - _cairo_in_fill_move_to, - _cairo_in_fill_line_to, - _cairo_in_fill_curve_to, - _cairo_in_fill_close_path, - &in_fill); - assert (status == CAIRO_STATUS_SUCCESS); - - _cairo_in_fill_close_path (&in_fill); - - if (in_fill.on_edge) { - is_inside = TRUE; - } else switch (fill_rule) { - case CAIRO_FILL_RULE_EVEN_ODD: - is_inside = in_fill.winding & 1; - break; - case CAIRO_FILL_RULE_WINDING: - is_inside = in_fill.winding != 0; - break; - default: - ASSERT_NOT_REACHED; - is_inside = FALSE; - break; - } - - _cairo_in_fill_fini (&in_fill); - - return is_inside; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-private.h deleted file mode 100644 index 7b54317e20e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-private.h +++ /dev/null @@ -1,57 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2006 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PATH_PRIVATE_H -#define CAIRO_PATH_PRIVATE_H - -#include "cairoint.h" - -cairo_private cairo_path_t * -_cairo_path_create (cairo_path_fixed_t *path, - cairo_t *cr); - -cairo_private cairo_path_t * -_cairo_path_create_flat (cairo_path_fixed_t *path, - cairo_t *cr); - -cairo_private cairo_path_t * -_cairo_path_create_in_error (cairo_status_t status); - -cairo_private cairo_status_t -_cairo_path_append_to_context (const cairo_path_t *path, - cairo_t *cr); - -#endif /* CAIRO_PATH_DATA_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-boxes.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-boxes.c deleted file mode 100644 index 7f25bf76cf7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-boxes.c +++ /dev/null @@ -1,711 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#define _BSD_SOURCE /* for hypot() */ -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-slope-private.h" -#include "cairo-stroke-dash-private.h" - -typedef struct _segment_t { - cairo_point_t p1, p2; - unsigned flags; -#define HORIZONTAL 0x1 -#define FORWARDS 0x2 -#define JOIN 0x4 -} segment_t; - -typedef struct _cairo_rectilinear_stroker { - const cairo_stroke_style_t *stroke_style; - const cairo_matrix_t *ctm; - cairo_antialias_t antialias; - - cairo_fixed_t half_line_x, half_line_y; - cairo_boxes_t *boxes; - cairo_point_t current_point; - cairo_point_t first_point; - cairo_bool_t open_sub_path; - - cairo_stroker_dash_t dash; - - cairo_bool_t has_bounds; - cairo_box_t bounds; - - int num_segments; - int segments_size; - segment_t *segments; - segment_t segments_embedded[8]; /* common case is a single rectangle */ -} cairo_rectilinear_stroker_t; - -static void -_cairo_rectilinear_stroker_limit (cairo_rectilinear_stroker_t *stroker, - const cairo_box_t *boxes, - int num_boxes) -{ - stroker->has_bounds = TRUE; - _cairo_boxes_get_extents (boxes, num_boxes, &stroker->bounds); - - stroker->bounds.p1.x -= stroker->half_line_x; - stroker->bounds.p2.x += stroker->half_line_x; - - stroker->bounds.p1.y -= stroker->half_line_y; - stroker->bounds.p2.y += stroker->half_line_y; -} - -static cairo_bool_t -_cairo_rectilinear_stroker_init (cairo_rectilinear_stroker_t *stroker, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - cairo_antialias_t antialias, - cairo_boxes_t *boxes) -{ - /* This special-case rectilinear stroker only supports - * miter-joined lines (not curves) and a translation-only matrix - * (though it could probably be extended to support a matrix with - * uniform, integer scaling). - * - * It also only supports horizontal and vertical line_to - * elements. But we don't catch that here, but instead return - * UNSUPPORTED from _cairo_rectilinear_stroker_line_to if any - * non-rectilinear line_to is encountered. - */ - if (stroke_style->line_join != CAIRO_LINE_JOIN_MITER) - return FALSE; - - /* If the miter limit turns right angles into bevels, then we - * can't use this optimization. Remember, the ratio is - * 1/sin(ɸ/2). So the cutoff is 1/sin(π/4.0) or ⎷2, - * which we round for safety. */ - if (stroke_style->miter_limit < M_SQRT2) - return FALSE; - - if (! (stroke_style->line_cap == CAIRO_LINE_CAP_BUTT || - stroke_style->line_cap == CAIRO_LINE_CAP_SQUARE)) - { - return FALSE; - } - - if (! _cairo_matrix_is_scale (ctm)) - return FALSE; - - stroker->stroke_style = stroke_style; - stroker->ctm = ctm; - stroker->antialias = antialias; - - stroker->half_line_x = - _cairo_fixed_from_double (fabs(ctm->xx) * stroke_style->line_width / 2.0); - stroker->half_line_y = - _cairo_fixed_from_double (fabs(ctm->yy) * stroke_style->line_width / 2.0); - - stroker->open_sub_path = FALSE; - stroker->segments = stroker->segments_embedded; - stroker->segments_size = ARRAY_LENGTH (stroker->segments_embedded); - stroker->num_segments = 0; - - _cairo_stroker_dash_init (&stroker->dash, stroke_style); - - stroker->has_bounds = FALSE; - - stroker->boxes = boxes; - - return TRUE; -} - -static void -_cairo_rectilinear_stroker_fini (cairo_rectilinear_stroker_t *stroker) -{ - if (stroker->segments != stroker->segments_embedded) - free (stroker->segments); -} - -static cairo_status_t -_cairo_rectilinear_stroker_add_segment (cairo_rectilinear_stroker_t *stroker, - const cairo_point_t *p1, - const cairo_point_t *p2, - unsigned flags) -{ - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (stroker->num_segments == stroker->segments_size) { - int new_size = stroker->segments_size * 2; - segment_t *new_segments; - - if (stroker->segments == stroker->segments_embedded) { - new_segments = _cairo_malloc_ab (new_size, sizeof (segment_t)); - if (unlikely (new_segments == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (new_segments, stroker->segments, - stroker->num_segments * sizeof (segment_t)); - } else { - new_segments = _cairo_realloc_ab (stroker->segments, - new_size, sizeof (segment_t)); - if (unlikely (new_segments == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - stroker->segments_size = new_size; - stroker->segments = new_segments; - } - - stroker->segments[stroker->num_segments].p1 = *p1; - stroker->segments[stroker->num_segments].p2 = *p2; - stroker->segments[stroker->num_segments].flags = flags; - stroker->num_segments++; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_rectilinear_stroker_emit_segments (cairo_rectilinear_stroker_t *stroker) -{ - cairo_line_cap_t line_cap = stroker->stroke_style->line_cap; - cairo_fixed_t half_line_x = stroker->half_line_x; - cairo_fixed_t half_line_y = stroker->half_line_y; - cairo_status_t status; - int i, j; - - /* For each segment we generate a single rectangle. - * This rectangle is based on a perpendicular extension (by half the - * line width) of the segment endpoints * after some adjustments of the - * endpoints to account for caps and joins. - */ - for (i = 0; i < stroker->num_segments; i++) { - cairo_bool_t lengthen_initial, lengthen_final; - cairo_point_t *a, *b; - cairo_box_t box; - - a = &stroker->segments[i].p1; - b = &stroker->segments[i].p2; - - /* We adjust the initial point of the segment to extend the - * rectangle to include the previous cap or join, (this - * adjustment applies to all segments except for the first - * segment of open, butt-capped paths). However, we must be - * careful not to emit a miter join across a degenerate segment - * which has been elided. - * - * Overlapping segments will be eliminated by the tessellation. - * Ideally, we would not emit these self-intersections at all, - * but that is tricky with segments shorter than half_line_width. - */ - j = i == 0 ? stroker->num_segments - 1 : i-1; - lengthen_initial = (stroker->segments[i].flags ^ stroker->segments[j].flags) & HORIZONTAL; - j = i == stroker->num_segments - 1 ? 0 : i+1; - lengthen_final = (stroker->segments[i].flags ^ stroker->segments[j].flags) & HORIZONTAL; - if (stroker->open_sub_path) { - if (i == 0) - lengthen_initial = line_cap != CAIRO_LINE_CAP_BUTT; - - if (i == stroker->num_segments - 1) - lengthen_final = line_cap != CAIRO_LINE_CAP_BUTT; - } - - /* Perform the adjustments of the endpoints. */ - if (lengthen_initial | lengthen_final) { - if (a->y == b->y) { - if (a->x < b->x) { - if (lengthen_initial) - a->x -= half_line_x; - if (lengthen_final) - b->x += half_line_x; - } else { - if (lengthen_initial) - a->x += half_line_x; - if (lengthen_final) - b->x -= half_line_x; - } - } else { - if (a->y < b->y) { - if (lengthen_initial) - a->y -= half_line_y; - if (lengthen_final) - b->y += half_line_y; - } else { - if (lengthen_initial) - a->y += half_line_y; - if (lengthen_final) - b->y -= half_line_y; - } - } - } - - /* Form the rectangle by expanding by half the line width in - * either perpendicular direction. */ - if (a->y == b->y) { - a->y -= half_line_y; - b->y += half_line_y; - } else { - a->x -= half_line_x; - b->x += half_line_x; - } - - if (a->x < b->x) { - box.p1.x = a->x; - box.p2.x = b->x; - } else { - box.p1.x = b->x; - box.p2.x = a->x; - } - if (a->y < b->y) { - box.p1.y = a->y; - box.p2.y = b->y; - } else { - box.p1.y = b->y; - box.p2.y = a->y; - } - - status = _cairo_boxes_add (stroker->boxes, stroker->antialias, &box); - if (unlikely (status)) - return status; - } - - stroker->num_segments = 0; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_rectilinear_stroker_emit_segments_dashed (cairo_rectilinear_stroker_t *stroker) -{ - cairo_status_t status; - cairo_line_cap_t line_cap = stroker->stroke_style->line_cap; - cairo_fixed_t half_line_x = stroker->half_line_x; - cairo_fixed_t half_line_y = stroker->half_line_y; - int i; - - for (i = 0; i < stroker->num_segments; i++) { - cairo_point_t *a, *b; - cairo_bool_t is_horizontal; - cairo_box_t box; - - a = &stroker->segments[i].p1; - b = &stroker->segments[i].p2; - - is_horizontal = stroker->segments[i].flags & HORIZONTAL; - - /* Handle the joins for a potentially degenerate segment. */ - if (line_cap == CAIRO_LINE_CAP_BUTT && - stroker->segments[i].flags & JOIN && - (i != stroker->num_segments - 1 || - (! stroker->open_sub_path && stroker->dash.dash_starts_on))) - { - cairo_slope_t out_slope; - int j = (i + 1) % stroker->num_segments; - cairo_bool_t forwards = !!(stroker->segments[i].flags & FORWARDS); - - _cairo_slope_init (&out_slope, - &stroker->segments[j].p1, - &stroker->segments[j].p2); - box.p2 = box.p1 = stroker->segments[i].p2; - - if (is_horizontal) { - if (forwards) - box.p2.x += half_line_x; - else - box.p1.x -= half_line_x; - - if (out_slope.dy > 0) - box.p1.y -= half_line_y; - else - box.p2.y += half_line_y; - } else { - if (forwards) - box.p2.y += half_line_y; - else - box.p1.y -= half_line_y; - - if (out_slope.dx > 0) - box.p1.x -= half_line_x; - else - box.p2.x += half_line_x; - } - - status = _cairo_boxes_add (stroker->boxes, stroker->antialias, &box); - if (unlikely (status)) - return status; - } - - /* Perform the adjustments of the endpoints. */ - if (is_horizontal) { - if (line_cap == CAIRO_LINE_CAP_SQUARE) { - if (a->x <= b->x) { - a->x -= half_line_x; - b->x += half_line_x; - } else { - a->x += half_line_x; - b->x -= half_line_x; - } - } - - a->y += half_line_y; - b->y -= half_line_y; - } else { - if (line_cap == CAIRO_LINE_CAP_SQUARE) { - if (a->y <= b->y) { - a->y -= half_line_y; - b->y += half_line_y; - } else { - a->y += half_line_y; - b->y -= half_line_y; - } - } - - a->x += half_line_x; - b->x -= half_line_x; - } - - if (a->x == b->x && a->y == b->y) - continue; - - if (a->x < b->x) { - box.p1.x = a->x; - box.p2.x = b->x; - } else { - box.p1.x = b->x; - box.p2.x = a->x; - } - if (a->y < b->y) { - box.p1.y = a->y; - box.p2.y = b->y; - } else { - box.p1.y = b->y; - box.p2.y = a->y; - } - - status = _cairo_boxes_add (stroker->boxes, stroker->antialias, &box); - if (unlikely (status)) - return status; - } - - stroker->num_segments = 0; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_rectilinear_stroker_move_to (void *closure, - const cairo_point_t *point) -{ - cairo_rectilinear_stroker_t *stroker = closure; - cairo_status_t status; - - if (stroker->dash.dashed) - status = _cairo_rectilinear_stroker_emit_segments_dashed (stroker); - else - status = _cairo_rectilinear_stroker_emit_segments (stroker); - if (unlikely (status)) - return status; - - /* reset the dash pattern for new sub paths */ - _cairo_stroker_dash_start (&stroker->dash); - - stroker->current_point = *point; - stroker->first_point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_rectilinear_stroker_line_to (void *closure, - const cairo_point_t *b) -{ - cairo_rectilinear_stroker_t *stroker = closure; - cairo_point_t *a = &stroker->current_point; - cairo_status_t status; - - /* We only support horizontal or vertical elements. */ - assert (a->x == b->x || a->y == b->y); - - /* We don't draw anything for degenerate paths. */ - if (a->x == b->x && a->y == b->y) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_rectilinear_stroker_add_segment (stroker, a, b, - (a->y == b->y) | JOIN); - - stroker->current_point = *b; - stroker->open_sub_path = TRUE; - - return status; -} - -static cairo_status_t -_cairo_rectilinear_stroker_line_to_dashed (void *closure, - const cairo_point_t *point) -{ - cairo_rectilinear_stroker_t *stroker = closure; - const cairo_point_t *a = &stroker->current_point; - const cairo_point_t *b = point; - cairo_bool_t fully_in_bounds; - double sf, sign, remain; - cairo_fixed_t mag; - cairo_status_t status; - cairo_line_t segment; - cairo_bool_t dash_on = FALSE; - unsigned is_horizontal; - - /* We don't draw anything for degenerate paths. */ - if (a->x == b->x && a->y == b->y) - return CAIRO_STATUS_SUCCESS; - - /* We only support horizontal or vertical elements. */ - assert (a->x == b->x || a->y == b->y); - - fully_in_bounds = TRUE; - if (stroker->has_bounds && - (! _cairo_box_contains_point (&stroker->bounds, a) || - ! _cairo_box_contains_point (&stroker->bounds, b))) - { - fully_in_bounds = FALSE; - } - - is_horizontal = a->y == b->y; - if (is_horizontal) { - mag = b->x - a->x; - sf = fabs (stroker->ctm->xx); - } else { - mag = b->y - a->y; - sf = fabs (stroker->ctm->yy); - } - if (mag < 0) { - remain = _cairo_fixed_to_double (-mag); - sign = 1.; - } else { - remain = _cairo_fixed_to_double (mag); - is_horizontal |= FORWARDS; - sign = -1.; - } - - segment.p2 = segment.p1 = *a; - while (remain > 0.) { - double step_length; - - step_length = MIN (sf * stroker->dash.dash_remain, remain); - remain -= step_length; - - mag = _cairo_fixed_from_double (sign*remain); - if (is_horizontal & 0x1) - segment.p2.x = b->x + mag; - else - segment.p2.y = b->y + mag; - - if (stroker->dash.dash_on && - (fully_in_bounds || - _cairo_box_intersects_line_segment (&stroker->bounds, &segment))) - { - status = _cairo_rectilinear_stroker_add_segment (stroker, - &segment.p1, - &segment.p2, - is_horizontal | (remain <= 0.) << 2); - if (unlikely (status)) - return status; - - dash_on = TRUE; - } - else - { - dash_on = FALSE; - } - - _cairo_stroker_dash_step (&stroker->dash, step_length / sf); - segment.p1 = segment.p2; - } - - if (stroker->dash.dash_on && ! dash_on && - (fully_in_bounds || - _cairo_box_intersects_line_segment (&stroker->bounds, &segment))) - { - - /* This segment ends on a transition to dash_on, compute a new face - * and add cap for the beginning of the next dash_on step. - */ - - status = _cairo_rectilinear_stroker_add_segment (stroker, - &segment.p1, - &segment.p1, - is_horizontal | JOIN); - if (unlikely (status)) - return status; - } - - stroker->current_point = *point; - stroker->open_sub_path = TRUE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_rectilinear_stroker_close_path (void *closure) -{ - cairo_rectilinear_stroker_t *stroker = closure; - cairo_status_t status; - - /* We don't draw anything for degenerate paths. */ - if (! stroker->open_sub_path) - return CAIRO_STATUS_SUCCESS; - - if (stroker->dash.dashed) { - status = _cairo_rectilinear_stroker_line_to_dashed (stroker, - &stroker->first_point); - } else { - status = _cairo_rectilinear_stroker_line_to (stroker, - &stroker->first_point); - } - if (unlikely (status)) - return status; - - stroker->open_sub_path = FALSE; - - if (stroker->dash.dashed) - status = _cairo_rectilinear_stroker_emit_segments_dashed (stroker); - else - status = _cairo_rectilinear_stroker_emit_segments (stroker); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_path_fixed_stroke_rectilinear_to_boxes (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - cairo_antialias_t antialias, - cairo_boxes_t *boxes) -{ - cairo_rectilinear_stroker_t rectilinear_stroker; - cairo_int_status_t status; - cairo_box_t box; - - assert (_cairo_path_fixed_stroke_is_rectilinear (path)); - - if (! _cairo_rectilinear_stroker_init (&rectilinear_stroker, - stroke_style, ctm, antialias, - boxes)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (! rectilinear_stroker.dash.dashed && - _cairo_path_fixed_is_stroke_box (path, &box) && - /* if the segments overlap we need to feed them into the tessellator */ - box.p2.x - box.p1.x > 2* rectilinear_stroker.half_line_x && - box.p2.y - box.p1.y > 2* rectilinear_stroker.half_line_y) - { - cairo_box_t b; - - /* top */ - b.p1.x = box.p1.x - rectilinear_stroker.half_line_x; - b.p2.x = box.p2.x + rectilinear_stroker.half_line_x; - b.p1.y = box.p1.y - rectilinear_stroker.half_line_y; - b.p2.y = box.p1.y + rectilinear_stroker.half_line_y; - status = _cairo_boxes_add (boxes, antialias, &b); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - /* left (excluding top/bottom) */ - b.p1.x = box.p1.x - rectilinear_stroker.half_line_x; - b.p2.x = box.p1.x + rectilinear_stroker.half_line_x; - b.p1.y = box.p1.y + rectilinear_stroker.half_line_y; - b.p2.y = box.p2.y - rectilinear_stroker.half_line_y; - status = _cairo_boxes_add (boxes, antialias, &b); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - /* right (excluding top/bottom) */ - b.p1.x = box.p2.x - rectilinear_stroker.half_line_x; - b.p2.x = box.p2.x + rectilinear_stroker.half_line_x; - b.p1.y = box.p1.y + rectilinear_stroker.half_line_y; - b.p2.y = box.p2.y - rectilinear_stroker.half_line_y; - status = _cairo_boxes_add (boxes, antialias, &b); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - /* bottom */ - b.p1.x = box.p1.x - rectilinear_stroker.half_line_x; - b.p2.x = box.p2.x + rectilinear_stroker.half_line_x; - b.p1.y = box.p2.y - rectilinear_stroker.half_line_y; - b.p2.y = box.p2.y + rectilinear_stroker.half_line_y; - status = _cairo_boxes_add (boxes, antialias, &b); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - goto done; - } - - if (boxes->num_limits) { - _cairo_rectilinear_stroker_limit (&rectilinear_stroker, - boxes->limits, - boxes->num_limits); - } - - status = _cairo_path_fixed_interpret (path, - _cairo_rectilinear_stroker_move_to, - rectilinear_stroker.dash.dashed ? - _cairo_rectilinear_stroker_line_to_dashed : - _cairo_rectilinear_stroker_line_to, - NULL, - _cairo_rectilinear_stroker_close_path, - &rectilinear_stroker); - if (unlikely (status)) - goto BAIL; - - if (rectilinear_stroker.dash.dashed) - status = _cairo_rectilinear_stroker_emit_segments_dashed (&rectilinear_stroker); - else - status = _cairo_rectilinear_stroker_emit_segments (&rectilinear_stroker); - if (unlikely (status)) - goto BAIL; - - /* As we incrementally tessellate, we do not eliminate self-intersections */ - status = _cairo_bentley_ottmann_tessellate_boxes (boxes, - CAIRO_FILL_RULE_WINDING, - boxes); - if (unlikely (status)) - goto BAIL; - -done: - _cairo_rectilinear_stroker_fini (&rectilinear_stroker); - return CAIRO_STATUS_SUCCESS; - -BAIL: - _cairo_rectilinear_stroker_fini (&rectilinear_stroker); - _cairo_boxes_clear (boxes); - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-polygon.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-polygon.c deleted file mode 100644 index e5082bbec68..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-polygon.c +++ /dev/null @@ -1,1364 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#define _BSD_SOURCE /* for hypot() */ -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-contour-inline.h" -#include "cairo-contour-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-slope-private.h" - -#define DEBUG 0 - -struct stroker { - cairo_stroke_style_t style; - -#if DEBUG - cairo_contour_t path; -#endif - - struct stroke_contour { - /* Note that these are not strictly contours as they may intersect */ - cairo_contour_t contour; - } cw, ccw; - cairo_uint64_t contour_tolerance; - cairo_polygon_t *polygon; - - const cairo_matrix_t *ctm; - const cairo_matrix_t *ctm_inverse; - double tolerance; - double spline_cusp_tolerance; - double half_line_width; - cairo_bool_t ctm_det_positive; - - cairo_pen_t pen; - - cairo_point_t first_point; - - cairo_bool_t has_initial_sub_path; - - cairo_bool_t has_current_face; - cairo_stroke_face_t current_face; - - cairo_bool_t has_first_face; - cairo_stroke_face_t first_face; - - cairo_bool_t has_bounds; - cairo_box_t bounds; -}; - -static inline double -normalize_slope (double *dx, double *dy); - -static void -compute_face (const cairo_point_t *point, - const cairo_slope_t *dev_slope, - struct stroker *stroker, - cairo_stroke_face_t *face); - -static cairo_uint64_t -point_distance_sq (const cairo_point_t *p1, - const cairo_point_t *p2) -{ - int32_t dx = p1->x - p2->x; - int32_t dy = p1->y - p2->y; - return _cairo_int32x32_64_mul (dx, dx) + _cairo_int32x32_64_mul (dy, dy); -} - -static cairo_bool_t -within_tolerance (const cairo_point_t *p1, - const cairo_point_t *p2, - cairo_uint64_t tolerance) -{ - return FALSE; - return _cairo_int64_lt (point_distance_sq (p1, p2), tolerance); -} - -static void -contour_add_point (struct stroker *stroker, - struct stroke_contour *c, - const cairo_point_t *point) -{ - if (! within_tolerance (point, _cairo_contour_last_point (&c->contour), - stroker->contour_tolerance)) - _cairo_contour_add_point (&c->contour, point); - //*_cairo_contour_last_point (&c->contour) = *point; -} - -static void -translate_point (cairo_point_t *point, const cairo_point_t *offset) -{ - point->x += offset->x; - point->y += offset->y; -} - -static int -slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) -{ - double c = (dx1 * dy2 - dx2 * dy1); - - if (c > 0) return 1; - if (c < 0) return -1; - return 0; -} - -static inline int -range_step (int i, int step, int max) -{ - i += step; - if (i < 0) - i = max - 1; - if (i >= max) - i = 0; - return i; -} - -/* - * Construct a fan around the midpoint using the vertices from pen between - * inpt and outpt. - */ -static void -add_fan (struct stroker *stroker, - const cairo_slope_t *in_vector, - const cairo_slope_t *out_vector, - const cairo_point_t *midpt, - cairo_bool_t clockwise, - struct stroke_contour *c) -{ - cairo_pen_t *pen = &stroker->pen; - int start, stop; - - if (stroker->has_bounds && - ! _cairo_box_contains_point (&stroker->bounds, midpt)) - return; - - assert (stroker->pen.num_vertices); - - if (clockwise) { - _cairo_pen_find_active_cw_vertices (pen, - in_vector, out_vector, - &start, &stop); - while (start != stop) { - cairo_point_t p = *midpt; - translate_point (&p, &pen->vertices[start].point); - contour_add_point (stroker, c, &p); - - if (++start == pen->num_vertices) - start = 0; - } - } else { - _cairo_pen_find_active_ccw_vertices (pen, - in_vector, out_vector, - &start, &stop); - while (start != stop) { - cairo_point_t p = *midpt; - translate_point (&p, &pen->vertices[start].point); - contour_add_point (stroker, c, &p); - - if (start-- == 0) - start += pen->num_vertices; - } - } -} - -static int -join_is_clockwise (const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - return _cairo_slope_compare (&in->dev_vector, &out->dev_vector) < 0; -} - -static void -inner_join (struct stroker *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out, - int clockwise) -{ -#if 0 - cairo_point_t last; - const cairo_point_t *p, *outpt; - struct stroke_contour *inner; - cairo_int64_t d_p, d_last; - cairo_int64_t half_line_width; - cairo_bool_t negate; - - /* XXX line segments shorter than line-width */ - - if (clockwise) { - inner = &stroker->ccw; - outpt = &out->ccw; - negate = 1; - } else { - inner = &stroker->cw; - outpt = &out->cw; - negate = 0; - } - - half_line_width = CAIRO_FIXED_ONE*CAIRO_FIXED_ONE/2 * stroker->style.line_width * out->length + .5; - - /* On the inside, the previous end-point is always - * closer to the new face by definition. - */ - last = *_cairo_contour_last_point (&inner->contour); - d_last = distance_from_face (out, &last, negate); - _cairo_contour_remove_last_point (&inner->contour); - -prev: - if (inner->contour.chain.num_points == 0) { - contour_add_point (stroker, inner, outpt); - return; - } - p = _cairo_contour_last_point (&inner->contour); - d_p = distance_from_face (out, p, negate); - if (_cairo_int64_lt (d_p, half_line_width) && - !_cairo_int64_negative (distance_along_face (out, p))) - { - last = *p; - d_last = d_p; - _cairo_contour_remove_last_point (&inner->contour); - goto prev; - } - - compute_inner_joint (&last, d_last, p, d_p, half_line_width); - contour_add_point (stroker, inner, &last); -#else - const cairo_point_t *outpt; - struct stroke_contour *inner; - - if (clockwise) { - inner = &stroker->ccw; - outpt = &out->ccw; - } else { - inner = &stroker->cw; - outpt = &out->cw; - } - contour_add_point (stroker, inner, &in->point); - contour_add_point (stroker, inner, outpt); -#endif -} - -static void -inner_close (struct stroker *stroker, - const cairo_stroke_face_t *in, - cairo_stroke_face_t *out) -{ -#if 0 - cairo_point_t last; - const cairo_point_t *p, *outpt, *inpt; - struct stroke_contour *inner; - struct _cairo_contour_chain *chain; - - /* XXX line segments shorter than line-width */ - - if (join_is_clockwise (in, out)) { - inner = &stroker->ccw; - outpt = &in->ccw; - inpt = &out->ccw; - } else { - inner = &stroker->cw; - outpt = &in->cw; - inpt = &out->cw; - } - - if (inner->contour.chain.num_points == 0) { - contour_add_point (stroker, inner, &in->point); - contour_add_point (stroker, inner, inpt); - *_cairo_contour_first_point (&inner->contour) = - *_cairo_contour_last_point (&inner->contour); - return; - } - - line_width = stroker->style.line_width/2; - line_width *= CAIRO_FIXED_ONE; - - d_last = sign * distance_from_face (out, outpt); - last = *outpt; - - for (chain = &inner->contour.chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - p = &chain->points[i]; - if ((d_p = sign * distance_from_face (in, p)) >= line_width && - distance_from_edge (stroker, inpt, &last, p) < line_width) - { - goto out; - } - - if (p->x != last.x || p->y != last.y) { - last = *p; - d_last = d_p; - } - } - } -out: - - if (d_p != d_last) { - double dot = (line_width - d_last) / (d_p - d_last); - last.x += dot * (p->x - last.x); - last.y += dot * (p->y - last.y); - } - *_cairo_contour_last_point (&inner->contour) = last; - - for (chain = &inner->contour.chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - cairo_point_t *pp = &chain->points[i]; - if (pp == p) - return; - *pp = last; - } - } -#else - const cairo_point_t *inpt; - struct stroke_contour *inner; - - if (join_is_clockwise (in, out)) { - inner = &stroker->ccw; - inpt = &out->ccw; - } else { - inner = &stroker->cw; - inpt = &out->cw; - } - - contour_add_point (stroker, inner, &in->point); - contour_add_point (stroker, inner, inpt); - *_cairo_contour_first_point (&inner->contour) = - *_cairo_contour_last_point (&inner->contour); -#endif -} - -static void -outer_close (struct stroker *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - const cairo_point_t *inpt, *outpt; - struct stroke_contour *outer; - int clockwise; - - if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && - in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) - { - return; - } - - clockwise = join_is_clockwise (in, out); - if (clockwise) { - inpt = &in->cw; - outpt = &out->cw; - outer = &stroker->cw; - } else { - inpt = &in->ccw; - outpt = &out->ccw; - outer = &stroker->ccw; - } - - if (within_tolerance (inpt, outpt, stroker->contour_tolerance)) { - *_cairo_contour_first_point (&outer->contour) = - *_cairo_contour_last_point (&outer->contour); - return; - } - - switch (stroker->style.line_join) { - case CAIRO_LINE_JOIN_ROUND: - /* construct a fan around the common midpoint */ - if ((in->dev_slope.x * out->dev_slope.x + - in->dev_slope.y * out->dev_slope.y) < stroker->spline_cusp_tolerance) - { - add_fan (stroker, - &in->dev_vector, &out->dev_vector, &in->point, - clockwise, outer); - break; - } - - case CAIRO_LINE_JOIN_MITER: - default: { - /* dot product of incoming slope vector with outgoing slope vector */ - double in_dot_out = in->dev_slope.x * out->dev_slope.x + - in->dev_slope.y * out->dev_slope.y; - double ml = stroker->style.miter_limit; - - /* Check the miter limit -- lines meeting at an acute angle - * can generate long miters, the limit converts them to bevel - * - * Consider the miter join formed when two line segments - * meet at an angle psi: - * - * /.\ - * /. .\ - * /./ \.\ - * /./psi\.\ - * - * We can zoom in on the right half of that to see: - * - * |\ - * | \ psi/2 - * | \ - * | \ - * | \ - * | \ - * miter \ - * length \ - * | \ - * | .\ - * | . \ - * |. line \ - * \ width \ - * \ \ - * - * - * The right triangle in that figure, (the line-width side is - * shown faintly with three '.' characters), gives us the - * following expression relating miter length, angle and line - * width: - * - * 1 /sin (psi/2) = miter_length / line_width - * - * The right-hand side of this relationship is the same ratio - * in which the miter limit (ml) is expressed. We want to know - * when the miter length is within the miter limit. That is - * when the following condition holds: - * - * 1/sin(psi/2) <= ml - * 1 <= ml sin(psi/2) - * 1 <= ml² sin²(psi/2) - * 2 <= ml² 2 sin²(psi/2) - * 2·sin²(psi/2) = 1-cos(psi) - * 2 <= ml² (1-cos(psi)) - * - * in · out = |in| |out| cos (psi) - * - * in and out are both unit vectors, so: - * - * in · out = cos (psi) - * - * 2 <= ml² (1 - in · out) - * - */ - if (2 <= ml * ml * (1 + in_dot_out)) { - double x1, y1, x2, y2; - double mx, my; - double dx1, dx2, dy1, dy2; - double ix, iy; - double fdx1, fdy1, fdx2, fdy2; - double mdx, mdy; - - /* - * we've got the points already transformed to device - * space, but need to do some computation with them and - * also need to transform the slope from user space to - * device space - */ - /* outer point of incoming line face */ - x1 = _cairo_fixed_to_double (inpt->x); - y1 = _cairo_fixed_to_double (inpt->y); - dx1 = in->dev_slope.x; - dy1 = in->dev_slope.y; - - /* outer point of outgoing line face */ - x2 = _cairo_fixed_to_double (outpt->x); - y2 = _cairo_fixed_to_double (outpt->y); - dx2 = out->dev_slope.x; - dy2 = out->dev_slope.y; - - /* - * Compute the location of the outer corner of the miter. - * That's pretty easy -- just the intersection of the two - * outer edges. We've got slopes and points on each - * of those edges. Compute my directly, then compute - * mx by using the edge with the larger dy; that avoids - * dividing by values close to zero. - */ - my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / - (dx1 * dy2 - dx2 * dy1)); - if (fabs (dy1) >= fabs (dy2)) - mx = (my - y1) * dx1 / dy1 + x1; - else - mx = (my - y2) * dx2 / dy2 + x2; - - /* - * When the two outer edges are nearly parallel, slight - * perturbations in the position of the outer points of the lines - * caused by representing them in fixed point form can cause the - * intersection point of the miter to move a large amount. If - * that moves the miter intersection from between the two faces, - * then draw a bevel instead. - */ - - ix = _cairo_fixed_to_double (in->point.x); - iy = _cairo_fixed_to_double (in->point.y); - - /* slope of one face */ - fdx1 = x1 - ix; fdy1 = y1 - iy; - - /* slope of the other face */ - fdx2 = x2 - ix; fdy2 = y2 - iy; - - /* slope from the intersection to the miter point */ - mdx = mx - ix; mdy = my - iy; - - /* - * Make sure the miter point line lies between the two - * faces by comparing the slopes - */ - if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != - slope_compare_sgn (fdx2, fdy2, mdx, mdy)) - { - cairo_point_t p; - - p.x = _cairo_fixed_from_double (mx); - p.y = _cairo_fixed_from_double (my); - - *_cairo_contour_last_point (&outer->contour) = p; - *_cairo_contour_first_point (&outer->contour) = p; - return; - } - } - break; - } - - case CAIRO_LINE_JOIN_BEVEL: - break; - } - contour_add_point (stroker, outer, outpt); -} - -static void -outer_join (struct stroker *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out, - int clockwise) -{ - const cairo_point_t *inpt, *outpt; - struct stroke_contour *outer; - - if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && - in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) - { - return; - } - if (clockwise) { - inpt = &in->cw; - outpt = &out->cw; - outer = &stroker->cw; - } else { - inpt = &in->ccw; - outpt = &out->ccw; - outer = &stroker->ccw; - } - - switch (stroker->style.line_join) { - case CAIRO_LINE_JOIN_ROUND: - /* construct a fan around the common midpoint */ - add_fan (stroker, - &in->dev_vector, &out->dev_vector, &in->point, - clockwise, outer); - break; - - case CAIRO_LINE_JOIN_MITER: - default: { - /* dot product of incoming slope vector with outgoing slope vector */ - double in_dot_out = in->dev_slope.x * out->dev_slope.x + - in->dev_slope.y * out->dev_slope.y; - double ml = stroker->style.miter_limit; - - /* Check the miter limit -- lines meeting at an acute angle - * can generate long miters, the limit converts them to bevel - * - * Consider the miter join formed when two line segments - * meet at an angle psi: - * - * /.\ - * /. .\ - * /./ \.\ - * /./psi\.\ - * - * We can zoom in on the right half of that to see: - * - * |\ - * | \ psi/2 - * | \ - * | \ - * | \ - * | \ - * miter \ - * length \ - * | \ - * | .\ - * | . \ - * |. line \ - * \ width \ - * \ \ - * - * - * The right triangle in that figure, (the line-width side is - * shown faintly with three '.' characters), gives us the - * following expression relating miter length, angle and line - * width: - * - * 1 /sin (psi/2) = miter_length / line_width - * - * The right-hand side of this relationship is the same ratio - * in which the miter limit (ml) is expressed. We want to know - * when the miter length is within the miter limit. That is - * when the following condition holds: - * - * 1/sin(psi/2) <= ml - * 1 <= ml sin(psi/2) - * 1 <= ml² sin²(psi/2) - * 2 <= ml² 2 sin²(psi/2) - * 2·sin²(psi/2) = 1-cos(psi) - * 2 <= ml² (1-cos(psi)) - * - * in · out = |in| |out| cos (psi) - * - * in and out are both unit vectors, so: - * - * in · out = cos (psi) - * - * 2 <= ml² (1 - in · out) - * - */ - if (2 <= ml * ml * (1 + in_dot_out)) { - double x1, y1, x2, y2; - double mx, my; - double dx1, dx2, dy1, dy2; - double ix, iy; - double fdx1, fdy1, fdx2, fdy2; - double mdx, mdy; - - /* - * we've got the points already transformed to device - * space, but need to do some computation with them and - * also need to transform the slope from user space to - * device space - */ - /* outer point of incoming line face */ - x1 = _cairo_fixed_to_double (inpt->x); - y1 = _cairo_fixed_to_double (inpt->y); - dx1 = in->dev_slope.x; - dy1 = in->dev_slope.y; - - /* outer point of outgoing line face */ - x2 = _cairo_fixed_to_double (outpt->x); - y2 = _cairo_fixed_to_double (outpt->y); - dx2 = out->dev_slope.x; - dy2 = out->dev_slope.y; - - /* - * Compute the location of the outer corner of the miter. - * That's pretty easy -- just the intersection of the two - * outer edges. We've got slopes and points on each - * of those edges. Compute my directly, then compute - * mx by using the edge with the larger dy; that avoids - * dividing by values close to zero. - */ - my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / - (dx1 * dy2 - dx2 * dy1)); - if (fabs (dy1) >= fabs (dy2)) - mx = (my - y1) * dx1 / dy1 + x1; - else - mx = (my - y2) * dx2 / dy2 + x2; - - /* - * When the two outer edges are nearly parallel, slight - * perturbations in the position of the outer points of the lines - * caused by representing them in fixed point form can cause the - * intersection point of the miter to move a large amount. If - * that moves the miter intersection from between the two faces, - * then draw a bevel instead. - */ - - ix = _cairo_fixed_to_double (in->point.x); - iy = _cairo_fixed_to_double (in->point.y); - - /* slope of one face */ - fdx1 = x1 - ix; fdy1 = y1 - iy; - - /* slope of the other face */ - fdx2 = x2 - ix; fdy2 = y2 - iy; - - /* slope from the intersection to the miter point */ - mdx = mx - ix; mdy = my - iy; - - /* - * Make sure the miter point line lies between the two - * faces by comparing the slopes - */ - if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != - slope_compare_sgn (fdx2, fdy2, mdx, mdy)) - { - cairo_point_t p; - - p.x = _cairo_fixed_from_double (mx); - p.y = _cairo_fixed_from_double (my); - - *_cairo_contour_last_point (&outer->contour) = p; - return; - } - } - break; - } - - case CAIRO_LINE_JOIN_BEVEL: - break; - } - contour_add_point (stroker,outer, outpt); -} - -static void -add_cap (struct stroker *stroker, - const cairo_stroke_face_t *f, - struct stroke_contour *c) -{ - switch (stroker->style.line_cap) { - case CAIRO_LINE_CAP_ROUND: { - cairo_slope_t slope; - - slope.dx = -f->dev_vector.dx; - slope.dy = -f->dev_vector.dy; - - add_fan (stroker, &f->dev_vector, &slope, &f->point, FALSE, c); - break; - } - - case CAIRO_LINE_CAP_SQUARE: { - cairo_slope_t fvector; - cairo_point_t p; - double dx, dy; - - dx = f->usr_vector.x; - dy = f->usr_vector.y; - dx *= stroker->half_line_width; - dy *= stroker->half_line_width; - cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); - fvector.dx = _cairo_fixed_from_double (dx); - fvector.dy = _cairo_fixed_from_double (dy); - - p.x = f->ccw.x + fvector.dx; - p.y = f->ccw.y + fvector.dy; - contour_add_point (stroker, c, &p); - - p.x = f->cw.x + fvector.dx; - p.y = f->cw.y + fvector.dy; - contour_add_point (stroker, c, &p); - } - - case CAIRO_LINE_CAP_BUTT: - default: - break; - } - contour_add_point (stroker, c, &f->cw); -} - -static void -add_leading_cap (struct stroker *stroker, - const cairo_stroke_face_t *face, - struct stroke_contour *c) -{ - cairo_stroke_face_t reversed; - cairo_point_t t; - - reversed = *face; - - /* The initial cap needs an outward facing vector. Reverse everything */ - reversed.usr_vector.x = -reversed.usr_vector.x; - reversed.usr_vector.y = -reversed.usr_vector.y; - reversed.dev_vector.dx = -reversed.dev_vector.dx; - reversed.dev_vector.dy = -reversed.dev_vector.dy; - - t = reversed.cw; - reversed.cw = reversed.ccw; - reversed.ccw = t; - - add_cap (stroker, &reversed, c); -} - -static void -add_trailing_cap (struct stroker *stroker, - const cairo_stroke_face_t *face, - struct stroke_contour *c) -{ - add_cap (stroker, face, c); -} - -static inline double -normalize_slope (double *dx, double *dy) -{ - double dx0 = *dx, dy0 = *dy; - double mag; - - assert (dx0 != 0.0 || dy0 != 0.0); - - if (dx0 == 0.0) { - *dx = 0.0; - if (dy0 > 0.0) { - mag = dy0; - *dy = 1.0; - } else { - mag = -dy0; - *dy = -1.0; - } - } else if (dy0 == 0.0) { - *dy = 0.0; - if (dx0 > 0.0) { - mag = dx0; - *dx = 1.0; - } else { - mag = -dx0; - *dx = -1.0; - } - } else { - mag = hypot (dx0, dy0); - *dx = dx0 / mag; - *dy = dy0 / mag; - } - - return mag; -} - -static void -compute_face (const cairo_point_t *point, - const cairo_slope_t *dev_slope, - struct stroker *stroker, - cairo_stroke_face_t *face) -{ - double face_dx, face_dy; - cairo_point_t offset_ccw, offset_cw; - double slope_dx, slope_dy; - - slope_dx = _cairo_fixed_to_double (dev_slope->dx); - slope_dy = _cairo_fixed_to_double (dev_slope->dy); - face->length = normalize_slope (&slope_dx, &slope_dy); - face->dev_slope.x = slope_dx; - face->dev_slope.y = slope_dy; - - /* - * rotate to get a line_width/2 vector along the face, note that - * the vector must be rotated the right direction in device space, - * but by 90° in user space. So, the rotation depends on - * whether the ctm reflects or not, and that can be determined - * by looking at the determinant of the matrix. - */ - if (! _cairo_matrix_is_identity (stroker->ctm_inverse)) { - /* Normalize the matrix! */ - cairo_matrix_transform_distance (stroker->ctm_inverse, - &slope_dx, &slope_dy); - normalize_slope (&slope_dx, &slope_dy); - - if (stroker->ctm_det_positive) { - face_dx = - slope_dy * stroker->half_line_width; - face_dy = slope_dx * stroker->half_line_width; - } else { - face_dx = slope_dy * stroker->half_line_width; - face_dy = - slope_dx * stroker->half_line_width; - } - - /* back to device space */ - cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); - } else { - face_dx = - slope_dy * stroker->half_line_width; - face_dy = slope_dx * stroker->half_line_width; - } - - offset_ccw.x = _cairo_fixed_from_double (face_dx); - offset_ccw.y = _cairo_fixed_from_double (face_dy); - offset_cw.x = -offset_ccw.x; - offset_cw.y = -offset_ccw.y; - - face->ccw = *point; - translate_point (&face->ccw, &offset_ccw); - - face->point = *point; - - face->cw = *point; - translate_point (&face->cw, &offset_cw); - - face->usr_vector.x = slope_dx; - face->usr_vector.y = slope_dy; - - face->dev_vector = *dev_slope; -} - -static void -add_caps (struct stroker *stroker) -{ - /* check for a degenerative sub_path */ - if (stroker->has_initial_sub_path && - ! stroker->has_first_face && - ! stroker->has_current_face && - stroker->style.line_cap == CAIRO_LINE_CAP_ROUND) - { - /* pick an arbitrary slope to use */ - cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; - cairo_stroke_face_t face; - - /* arbitrarily choose first_point */ - compute_face (&stroker->first_point, &slope, stroker, &face); - - add_leading_cap (stroker, &face, &stroker->ccw); - add_trailing_cap (stroker, &face, &stroker->ccw); - - /* ensure the circle is complete */ - _cairo_contour_add_point (&stroker->ccw.contour, - _cairo_contour_first_point (&stroker->ccw.contour)); - - _cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); - _cairo_contour_reset (&stroker->ccw.contour); - } else { - if (stroker->has_current_face) - add_trailing_cap (stroker, &stroker->current_face, &stroker->ccw); - -#if DEBUG - { - FILE *file = fopen ("contours.txt", "a"); - _cairo_debug_print_contour (file, &stroker->path); - _cairo_debug_print_contour (file, &stroker->cw.contour); - _cairo_debug_print_contour (file, &stroker->ccw.contour); - fclose (file); - _cairo_contour_reset (&stroker->path); - } -#endif - - _cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); - _cairo_contour_reset (&stroker->ccw.contour); - - if (stroker->has_first_face) { - _cairo_contour_add_point (&stroker->ccw.contour, - &stroker->first_face.cw); - add_leading_cap (stroker, &stroker->first_face, &stroker->ccw); -#if DEBUG - { - FILE *file = fopen ("contours.txt", "a"); - _cairo_debug_print_contour (file, &stroker->ccw.contour); - fclose (file); - } -#endif - - _cairo_polygon_add_contour (stroker->polygon, - &stroker->ccw.contour); - _cairo_contour_reset (&stroker->ccw.contour); - } - - _cairo_polygon_add_contour (stroker->polygon, &stroker->cw.contour); - _cairo_contour_reset (&stroker->cw.contour); - } -} - -static cairo_status_t -close_path (void *closure); - -static cairo_status_t -move_to (void *closure, - const cairo_point_t *point) -{ - struct stroker *stroker = closure; - - /* Cap the start and end of the previous sub path as needed */ - add_caps (stroker); - - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - stroker->has_initial_sub_path = FALSE; - - stroker->first_point = *point; - -#if DEBUG - _cairo_contour_add_point (&stroker->path, point); -#endif - - stroker->current_face.point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -line_to (void *closure, - const cairo_point_t *point) -{ - struct stroker *stroker = closure; - cairo_stroke_face_t start; - cairo_point_t *p1 = &stroker->current_face.point; - cairo_slope_t dev_slope; - - stroker->has_initial_sub_path = TRUE; - - if (p1->x == point->x && p1->y == point->y) - return CAIRO_STATUS_SUCCESS; - -#if DEBUG - _cairo_contour_add_point (&stroker->path, point); -#endif - - _cairo_slope_init (&dev_slope, p1, point); - compute_face (p1, &dev_slope, stroker, &start); - - if (stroker->has_current_face) { - int clockwise = _cairo_slope_compare (&stroker->current_face.dev_vector, - &start.dev_vector); - if (clockwise) { - clockwise = clockwise < 0; - /* Join with final face from previous segment */ - if (! within_tolerance (&stroker->current_face.ccw, &start.ccw, - stroker->contour_tolerance) || - ! within_tolerance (&stroker->current_face.cw, &start.cw, - stroker->contour_tolerance)) - { - outer_join (stroker, &stroker->current_face, &start, clockwise); - inner_join (stroker, &stroker->current_face, &start, clockwise); - } - } - } else { - if (! stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = start; - stroker->has_first_face = TRUE; - } - stroker->has_current_face = TRUE; - - contour_add_point (stroker, &stroker->cw, &start.cw); - contour_add_point (stroker, &stroker->ccw, &start.ccw); - } - - stroker->current_face = start; - stroker->current_face.point = *point; - stroker->current_face.ccw.x += dev_slope.dx; - stroker->current_face.ccw.y += dev_slope.dy; - stroker->current_face.cw.x += dev_slope.dx; - stroker->current_face.cw.y += dev_slope.dy; - - contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw); - contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -spline_to (void *closure, - const cairo_point_t *point, - const cairo_slope_t *tangent) -{ - struct stroker *stroker = closure; - cairo_stroke_face_t face; - -#if DEBUG - _cairo_contour_add_point (&stroker->path, point); -#endif - if ((tangent->dx | tangent->dy) == 0) { - struct stroke_contour *outer; - cairo_point_t t; - int clockwise; - - face = stroker->current_face; - - face.usr_vector.x = -face.usr_vector.x; - face.usr_vector.y = -face.usr_vector.y; - face.dev_vector.dx = -face.dev_vector.dx; - face.dev_vector.dy = -face.dev_vector.dy; - - t = face.cw; - face.cw = face.ccw; - face.ccw = t; - - clockwise = join_is_clockwise (&stroker->current_face, &face); - if (clockwise) { - outer = &stroker->cw; - } else { - outer = &stroker->ccw; - } - - add_fan (stroker, - &stroker->current_face.dev_vector, - &face.dev_vector, - &stroker->current_face.point, - clockwise, outer); - } else { - compute_face (point, tangent, stroker, &face); - - if ((face.dev_slope.x * stroker->current_face.dev_slope.x + - face.dev_slope.y * stroker->current_face.dev_slope.y) < stroker->spline_cusp_tolerance) - { - struct stroke_contour *outer; - int clockwise = join_is_clockwise (&stroker->current_face, &face); - - stroker->current_face.cw.x += face.point.x - stroker->current_face.point.x; - stroker->current_face.cw.y += face.point.y - stroker->current_face.point.y; - contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw); - - stroker->current_face.ccw.x += face.point.x - stroker->current_face.point.x; - stroker->current_face.ccw.y += face.point.y - stroker->current_face.point.y; - contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw); - - if (clockwise) { - outer = &stroker->cw; - } else { - outer = &stroker->ccw; - } - add_fan (stroker, - &stroker->current_face.dev_vector, - &face.dev_vector, - &stroker->current_face.point, - clockwise, outer); - } - - contour_add_point (stroker, &stroker->cw, &face.cw); - contour_add_point (stroker, &stroker->ccw, &face.ccw); - } - - stroker->current_face = face; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - struct stroker *stroker = closure; - cairo_spline_t spline; - cairo_stroke_face_t face; - - if (stroker->has_bounds && - ! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, - &stroker->bounds)) - return line_to (closure, d); - - if (! _cairo_spline_init (&spline, spline_to, stroker, - &stroker->current_face.point, b, c, d)) - return line_to (closure, d); - - compute_face (&stroker->current_face.point, &spline.initial_slope, - stroker, &face); - - if (stroker->has_current_face) { - int clockwise = join_is_clockwise (&stroker->current_face, &face); - /* Join with final face from previous segment */ - outer_join (stroker, &stroker->current_face, &face, clockwise); - inner_join (stroker, &stroker->current_face, &face, clockwise); - } else { - if (! stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = face; - stroker->has_first_face = TRUE; - } - stroker->has_current_face = TRUE; - - contour_add_point (stroker, &stroker->cw, &face.cw); - contour_add_point (stroker, &stroker->ccw, &face.ccw); - } - stroker->current_face = face; - - return _cairo_spline_decompose (&spline, stroker->tolerance); -} - -static cairo_status_t -close_path (void *closure) -{ - struct stroker *stroker = closure; - cairo_status_t status; - - status = line_to (stroker, &stroker->first_point); - if (unlikely (status)) - return status; - - if (stroker->has_first_face && stroker->has_current_face) { - /* Join first and final faces of sub path */ - outer_close (stroker, &stroker->current_face, &stroker->first_face); - inner_close (stroker, &stroker->current_face, &stroker->first_face); -#if 0 - *_cairo_contour_first_point (&stroker->ccw.contour) = - *_cairo_contour_last_point (&stroker->ccw.contour); - - *_cairo_contour_first_point (&stroker->cw.contour) = - *_cairo_contour_last_point (&stroker->cw.contour); -#endif - - _cairo_polygon_add_contour (stroker->polygon, &stroker->cw.contour); - _cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); - -#if DEBUG - { - FILE *file = fopen ("contours.txt", "a"); - _cairo_debug_print_contour (file, &stroker->path); - _cairo_debug_print_contour (file, &stroker->cw.contour); - _cairo_debug_print_contour (file, &stroker->ccw.contour); - fclose (file); - - _cairo_contour_reset (&stroker->path); - } -#endif - _cairo_contour_reset (&stroker->cw.contour); - _cairo_contour_reset (&stroker->ccw.contour); - } else { - /* Cap the start and end of the sub path as needed */ - add_caps (stroker); - } - - stroker->has_initial_sub_path = FALSE; - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_path_fixed_stroke_to_polygon (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_polygon_t *polygon) -{ - struct stroker stroker; - cairo_status_t status; - - if (style->num_dashes) { - return _cairo_path_fixed_stroke_dashed_to_polygon (path, - style, - ctm, - ctm_inverse, - tolerance, - polygon); - } - - stroker.has_bounds = polygon->num_limits; - if (stroker.has_bounds) { - /* Extend the bounds in each direction to account for the maximum area - * we might generate trapezoids, to capture line segments that are - * outside of the bounds but which might generate rendering that's - * within bounds. - */ - double dx, dy; - cairo_fixed_t fdx, fdy; - int i; - - stroker.bounds = polygon->limits[0]; - for (i = 1; i < polygon->num_limits; i++) - _cairo_box_add_box (&stroker.bounds, &polygon->limits[i]); - - _cairo_stroke_style_max_distance_from_path (style, path, ctm, &dx, &dy); - fdx = _cairo_fixed_from_double (dx); - fdy = _cairo_fixed_from_double (dy); - - stroker.bounds.p1.x -= fdx; - stroker.bounds.p2.x += fdx; - stroker.bounds.p1.y -= fdy; - stroker.bounds.p2.y += fdy; - } - - stroker.style = *style; - stroker.ctm = ctm; - stroker.ctm_inverse = ctm_inverse; - stroker.tolerance = tolerance; - stroker.half_line_width = style->line_width / 2.; - /* To test whether we need to join two segments of a spline using - * a round-join or a bevel-join, we can inspect the angle between the - * two segments. If the difference between the chord distance - * (half-line-width times the cosine of the bisection angle) and the - * half-line-width itself is greater than tolerance then we need to - * inject a point. - */ - stroker.spline_cusp_tolerance = 1 - tolerance / stroker.half_line_width; - stroker.spline_cusp_tolerance *= stroker.spline_cusp_tolerance; - stroker.spline_cusp_tolerance *= 2; - stroker.spline_cusp_tolerance -= 1; - stroker.ctm_det_positive = - _cairo_matrix_compute_determinant (ctm) >= 0.0; - - stroker.pen.num_vertices = 0; - if (path->has_curve_to || - style->line_join == CAIRO_LINE_JOIN_ROUND || - style->line_cap == CAIRO_LINE_CAP_ROUND) { - status = _cairo_pen_init (&stroker.pen, - stroker.half_line_width, - tolerance, ctm); - if (unlikely (status)) - return status; - - /* If the line width is so small that the pen is reduced to a - single point, then we have nothing to do. */ - if (stroker.pen.num_vertices <= 1) - return CAIRO_STATUS_SUCCESS; - } - - stroker.has_current_face = FALSE; - stroker.has_first_face = FALSE; - stroker.has_initial_sub_path = FALSE; - -#if DEBUG - remove ("contours.txt"); - remove ("polygons.txt"); - _cairo_contour_init (&stroker.path, 0); -#endif - _cairo_contour_init (&stroker.cw.contour, 1); - _cairo_contour_init (&stroker.ccw.contour, -1); - tolerance *= CAIRO_FIXED_ONE; - tolerance *= tolerance; - stroker.contour_tolerance = tolerance; - stroker.polygon = polygon; - - status = _cairo_path_fixed_interpret (path, - move_to, - line_to, - curve_to, - close_path, - &stroker); - /* Cap the start and end of the final sub path as needed */ - if (likely (status == CAIRO_STATUS_SUCCESS)) - add_caps (&stroker); - - _cairo_contour_fini (&stroker.cw.contour); - _cairo_contour_fini (&stroker.ccw.contour); - if (stroker.pen.num_vertices) - _cairo_pen_fini (&stroker.pen); - -#if DEBUG - { - FILE *file = fopen ("polygons.txt", "a"); - _cairo_debug_print_polygon (file, polygon); - fclose (file); - } -#endif - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-traps.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-traps.c deleted file mode 100644 index da54e5a358f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-traps.c +++ /dev/null @@ -1,1149 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2013 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-path-fixed-private.h" -#include "cairo-slope-private.h" -#include "cairo-stroke-dash-private.h" -#include "cairo-traps-private.h" - -#include - -struct stroker { - const cairo_stroke_style_t *style; - - const cairo_matrix_t *ctm; - const cairo_matrix_t *ctm_inverse; - double spline_cusp_tolerance; - double half_line_width; - double tolerance; - double ctm_determinant; - cairo_bool_t ctm_det_positive; - cairo_line_join_t line_join; - - cairo_traps_t *traps; - - cairo_pen_t pen; - - cairo_point_t first_point; - - cairo_bool_t has_initial_sub_path; - - cairo_bool_t has_current_face; - cairo_stroke_face_t current_face; - - cairo_bool_t has_first_face; - cairo_stroke_face_t first_face; - - cairo_stroker_dash_t dash; - - cairo_bool_t has_bounds; - cairo_box_t tight_bounds; - cairo_box_t line_bounds; - cairo_box_t join_bounds; -}; - -static cairo_status_t -stroker_init (struct stroker *stroker, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_traps_t *traps) -{ - cairo_status_t status; - - stroker->style = style; - stroker->ctm = ctm; - stroker->ctm_inverse = NULL; - if (! _cairo_matrix_is_identity (ctm_inverse)) - stroker->ctm_inverse = ctm_inverse; - stroker->line_join = style->line_join; - stroker->half_line_width = style->line_width / 2.0; - stroker->tolerance = tolerance; - stroker->traps = traps; - - /* To test whether we need to join two segments of a spline using - * a round-join or a bevel-join, we can inspect the angle between the - * two segments. If the difference between the chord distance - * (half-line-width times the cosine of the bisection angle) and the - * half-line-width itself is greater than tolerance then we need to - * inject a point. - */ - stroker->spline_cusp_tolerance = 1 - tolerance / stroker->half_line_width; - stroker->spline_cusp_tolerance *= stroker->spline_cusp_tolerance; - stroker->spline_cusp_tolerance *= 2; - stroker->spline_cusp_tolerance -= 1; - - stroker->ctm_determinant = _cairo_matrix_compute_determinant (stroker->ctm); - stroker->ctm_det_positive = stroker->ctm_determinant >= 0.0; - - status = _cairo_pen_init (&stroker->pen, - stroker->half_line_width, - tolerance, ctm); - if (unlikely (status)) - return status; - - stroker->has_current_face = FALSE; - stroker->has_first_face = FALSE; - stroker->has_initial_sub_path = FALSE; - - _cairo_stroker_dash_init (&stroker->dash, style); - - stroker->has_bounds = traps->num_limits; - if (stroker->has_bounds) { - /* Extend the bounds in each direction to account for the maximum area - * we might generate trapezoids, to capture line segments that are outside - * of the bounds but which might generate rendering that's within bounds. - */ - double dx, dy; - cairo_fixed_t fdx, fdy; - - stroker->tight_bounds = traps->bounds; - - _cairo_stroke_style_max_distance_from_path (stroker->style, path, - stroker->ctm, &dx, &dy); - - _cairo_stroke_style_max_line_distance_from_path (stroker->style, path, - stroker->ctm, &dx, &dy); - - fdx = _cairo_fixed_from_double (dx); - fdy = _cairo_fixed_from_double (dy); - - stroker->line_bounds = stroker->tight_bounds; - stroker->line_bounds.p1.x -= fdx; - stroker->line_bounds.p2.x += fdx; - stroker->line_bounds.p1.y -= fdy; - stroker->line_bounds.p2.y += fdy; - - _cairo_stroke_style_max_join_distance_from_path (stroker->style, path, - stroker->ctm, &dx, &dy); - - fdx = _cairo_fixed_from_double (dx); - fdy = _cairo_fixed_from_double (dy); - - stroker->join_bounds = stroker->tight_bounds; - stroker->join_bounds.p1.x -= fdx; - stroker->join_bounds.p2.x += fdx; - stroker->join_bounds.p1.y -= fdy; - stroker->join_bounds.p2.y += fdy; - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -stroker_fini (struct stroker *stroker) -{ - _cairo_pen_fini (&stroker->pen); -} - -static void -translate_point (cairo_point_t *point, cairo_point_t *offset) -{ - point->x += offset->x; - point->y += offset->y; -} - -static int -join_is_clockwise (const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - return _cairo_slope_compare (&in->dev_vector, &out->dev_vector) < 0; -} - -static int -slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) -{ - double c = dx1 * dy2 - dx2 * dy1; - if (c > 0) return 1; - if (c < 0) return -1; - return 0; -} - -static cairo_bool_t -stroker_intersects_join (const struct stroker *stroker, - const cairo_point_t *in, - const cairo_point_t *out) -{ - cairo_line_t segment; - - if (! stroker->has_bounds) - return TRUE; - - segment.p1 = *in; - segment.p2 = *out; - return _cairo_box_intersects_line_segment (&stroker->join_bounds, &segment); -} - -static void -join (struct stroker *stroker, - cairo_stroke_face_t *in, - cairo_stroke_face_t *out) -{ - int clockwise = join_is_clockwise (out, in); - cairo_point_t *inpt, *outpt; - - if (in->cw.x == out->cw.x && - in->cw.y == out->cw.y && - in->ccw.x == out->ccw.x && - in->ccw.y == out->ccw.y) - { - return; - } - - if (clockwise) { - inpt = &in->ccw; - outpt = &out->ccw; - } else { - inpt = &in->cw; - outpt = &out->cw; - } - - if (! stroker_intersects_join (stroker, inpt, outpt)) - return; - - switch (stroker->line_join) { - case CAIRO_LINE_JOIN_ROUND: - /* construct a fan around the common midpoint */ - if ((in->dev_slope.x * out->dev_slope.x + - in->dev_slope.y * out->dev_slope.y) < stroker->spline_cusp_tolerance) - { - int start, stop; - cairo_point_t tri[3], edges[4]; - cairo_pen_t *pen = &stroker->pen; - - edges[0] = in->cw; - edges[1] = in->ccw; - tri[0] = in->point; - tri[1] = *inpt; - if (clockwise) { - _cairo_pen_find_active_ccw_vertices (pen, - &in->dev_vector, &out->dev_vector, - &start, &stop); - while (start != stop) { - tri[2] = in->point; - translate_point (&tri[2], &pen->vertices[start].point); - edges[2] = in->point; - edges[3] = tri[2]; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, - tri, edges); - tri[1] = tri[2]; - edges[0] = edges[2]; - edges[1] = edges[3]; - - if (start-- == 0) - start += pen->num_vertices; - } - } else { - _cairo_pen_find_active_cw_vertices (pen, - &in->dev_vector, &out->dev_vector, - &start, &stop); - while (start != stop) { - tri[2] = in->point; - translate_point (&tri[2], &pen->vertices[start].point); - edges[2] = in->point; - edges[3] = tri[2]; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, - tri, edges); - tri[1] = tri[2]; - edges[0] = edges[2]; - edges[1] = edges[3]; - - if (++start == pen->num_vertices) - start = 0; - } - } - tri[2] = *outpt; - edges[2] = out->cw; - edges[3] = out->ccw; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, - tri, edges); - } else { - cairo_point_t t[] = { { in->point.x, in->point.y}, { inpt->x, inpt->y }, { outpt->x, outpt->y } }; - cairo_point_t e[] = { { in->cw.x, in->cw.y}, { in->ccw.x, in->ccw.y }, - { out->cw.x, out->cw.y}, { out->ccw.x, out->ccw.y } }; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, t, e); - } - break; - - case CAIRO_LINE_JOIN_MITER: - default: { - /* dot product of incoming slope vector with outgoing slope vector */ - double in_dot_out = (-in->usr_vector.x * out->usr_vector.x + - -in->usr_vector.y * out->usr_vector.y); - double ml = stroker->style->miter_limit; - - /* Check the miter limit -- lines meeting at an acute angle - * can generate long miters, the limit converts them to bevel - * - * Consider the miter join formed when two line segments - * meet at an angle psi: - * - * /.\ - * /. .\ - * /./ \.\ - * /./psi\.\ - * - * We can zoom in on the right half of that to see: - * - * |\ - * | \ psi/2 - * | \ - * | \ - * | \ - * | \ - * miter \ - * length \ - * | \ - * | .\ - * | . \ - * |. line \ - * \ width \ - * \ \ - * - * - * The right triangle in that figure, (the line-width side is - * shown faintly with three '.' characters), gives us the - * following expression relating miter length, angle and line - * width: - * - * 1 /sin (psi/2) = miter_length / line_width - * - * The right-hand side of this relationship is the same ratio - * in which the miter limit (ml) is expressed. We want to know - * when the miter length is within the miter limit. That is - * when the following condition holds: - * - * 1/sin(psi/2) <= ml - * 1 <= ml sin(psi/2) - * 1 <= ml² sin²(psi/2) - * 2 <= ml² 2 sin²(psi/2) - * 2·sin²(psi/2) = 1-cos(psi) - * 2 <= ml² (1-cos(psi)) - * - * in · out = |in| |out| cos (psi) - * - * in and out are both unit vectors, so: - * - * in · out = cos (psi) - * - * 2 <= ml² (1 - in · out) - * - */ - if (2 <= ml * ml * (1 - in_dot_out)) { - double x1, y1, x2, y2; - double mx, my; - double dx1, dx2, dy1, dy2; - cairo_point_t outer; - cairo_point_t quad[4]; - double ix, iy; - double fdx1, fdy1, fdx2, fdy2; - double mdx, mdy; - - /* - * we've got the points already transformed to device - * space, but need to do some computation with them and - * also need to transform the slope from user space to - * device space - */ - /* outer point of incoming line face */ - x1 = _cairo_fixed_to_double (inpt->x); - y1 = _cairo_fixed_to_double (inpt->y); - dx1 = in->usr_vector.x; - dy1 = in->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); - - /* outer point of outgoing line face */ - x2 = _cairo_fixed_to_double (outpt->x); - y2 = _cairo_fixed_to_double (outpt->y); - dx2 = out->usr_vector.x; - dy2 = out->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); - - /* - * Compute the location of the outer corner of the miter. - * That's pretty easy -- just the intersection of the two - * outer edges. We've got slopes and points on each - * of those edges. Compute my directly, then compute - * mx by using the edge with the larger dy; that avoids - * dividing by values close to zero. - */ - my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / - (dx1 * dy2 - dx2 * dy1)); - if (fabs (dy1) >= fabs (dy2)) - mx = (my - y1) * dx1 / dy1 + x1; - else - mx = (my - y2) * dx2 / dy2 + x2; - - /* - * When the two outer edges are nearly parallel, slight - * perturbations in the position of the outer points of the lines - * caused by representing them in fixed point form can cause the - * intersection point of the miter to move a large amount. If - * that moves the miter intersection from between the two faces, - * then draw a bevel instead. - */ - - ix = _cairo_fixed_to_double (in->point.x); - iy = _cairo_fixed_to_double (in->point.y); - - /* slope of one face */ - fdx1 = x1 - ix; fdy1 = y1 - iy; - - /* slope of the other face */ - fdx2 = x2 - ix; fdy2 = y2 - iy; - - /* slope from the intersection to the miter point */ - mdx = mx - ix; mdy = my - iy; - - /* - * Make sure the miter point line lies between the two - * faces by comparing the slopes - */ - if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != - slope_compare_sgn (fdx2, fdy2, mdx, mdy)) - { - /* - * Draw the quadrilateral - */ - outer.x = _cairo_fixed_from_double (mx); - outer.y = _cairo_fixed_from_double (my); - - quad[0] = in->point; - quad[1] = *inpt; - quad[2] = outer; - quad[3] = *outpt; - - _cairo_traps_tessellate_convex_quad (stroker->traps, quad); - break; - } - } - /* fall through ... */ - } - - case CAIRO_LINE_JOIN_BEVEL: { - cairo_point_t t[] = { { in->point.x, in->point.y }, { inpt->x, inpt->y }, { outpt->x, outpt->y } }; - cairo_point_t e[] = { { in->cw.x, in->cw.y }, { in->ccw.x, in->ccw.y }, - { out->cw.x, out->cw.y }, { out->ccw.x, out->ccw.y } }; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, t, e); - break; - } - } -} - -static void -add_cap (struct stroker *stroker, cairo_stroke_face_t *f) -{ - switch (stroker->style->line_cap) { - case CAIRO_LINE_CAP_ROUND: { - int start, stop; - cairo_slope_t in_slope, out_slope; - cairo_point_t tri[3], edges[4]; - cairo_pen_t *pen = &stroker->pen; - - in_slope = f->dev_vector; - out_slope.dx = -in_slope.dx; - out_slope.dy = -in_slope.dy; - _cairo_pen_find_active_cw_vertices (pen, &in_slope, &out_slope, - &start, &stop); - edges[0] = f->cw; - edges[1] = f->ccw; - tri[0] = f->point; - tri[1] = f->cw; - while (start != stop) { - tri[2] = f->point; - translate_point (&tri[2], &pen->vertices[start].point); - edges[2] = f->point; - edges[3] = tri[2]; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, - tri, edges); - - tri[1] = tri[2]; - edges[0] = edges[2]; - edges[1] = edges[3]; - if (++start == pen->num_vertices) - start = 0; - } - tri[2] = f->ccw; - edges[2] = f->cw; - edges[3] = f->ccw; - _cairo_traps_tessellate_triangle_with_edges (stroker->traps, - tri, edges); - break; - } - - case CAIRO_LINE_CAP_SQUARE: { - double dx, dy; - cairo_slope_t fvector; - cairo_point_t quad[4]; - - dx = f->usr_vector.x; - dy = f->usr_vector.y; - dx *= stroker->half_line_width; - dy *= stroker->half_line_width; - cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); - fvector.dx = _cairo_fixed_from_double (dx); - fvector.dy = _cairo_fixed_from_double (dy); - - quad[0] = f->cw; - quad[1].x = f->cw.x + fvector.dx; - quad[1].y = f->cw.y + fvector.dy; - quad[2].x = f->ccw.x + fvector.dx; - quad[2].y = f->ccw.y + fvector.dy; - quad[3] = f->ccw; - - _cairo_traps_tessellate_convex_quad (stroker->traps, quad); - break; - } - - case CAIRO_LINE_CAP_BUTT: - default: - break; - } -} - -static void -add_leading_cap (struct stroker *stroker, - cairo_stroke_face_t *face) -{ - cairo_stroke_face_t reversed; - cairo_point_t t; - - reversed = *face; - - /* The initial cap needs an outward facing vector. Reverse everything */ - reversed.usr_vector.x = -reversed.usr_vector.x; - reversed.usr_vector.y = -reversed.usr_vector.y; - reversed.dev_vector.dx = -reversed.dev_vector.dx; - reversed.dev_vector.dy = -reversed.dev_vector.dy; - t = reversed.cw; - reversed.cw = reversed.ccw; - reversed.ccw = t; - - add_cap (stroker, &reversed); -} - -static void -add_trailing_cap (struct stroker *stroker, cairo_stroke_face_t *face) -{ - add_cap (stroker, face); -} - -static inline double -normalize_slope (double *dx, double *dy) -{ - double dx0 = *dx, dy0 = *dy; - - if (dx0 == 0.0 && dy0 == 0.0) - return 0; - - if (dx0 == 0.0) { - *dx = 0.0; - if (dy0 > 0.0) { - *dy = 1.0; - return dy0; - } else { - *dy = -1.0; - return -dy0; - } - } else if (dy0 == 0.0) { - *dy = 0.0; - if (dx0 > 0.0) { - *dx = 1.0; - return dx0; - } else { - *dx = -1.0; - return -dx0; - } - } else { - double mag = hypot (dx0, dy0); - *dx = dx0 / mag; - *dy = dy0 / mag; - return mag; - } -} - -static void -compute_face (const cairo_point_t *point, - const cairo_slope_t *dev_slope, - struct stroker *stroker, - cairo_stroke_face_t *face) -{ - double face_dx, face_dy; - cairo_point_t offset_ccw, offset_cw; - double slope_dx, slope_dy; - - slope_dx = _cairo_fixed_to_double (dev_slope->dx); - slope_dy = _cairo_fixed_to_double (dev_slope->dy); - face->length = normalize_slope (&slope_dx, &slope_dy); - face->dev_slope.x = slope_dx; - face->dev_slope.y = slope_dy; - - /* - * rotate to get a line_width/2 vector along the face, note that - * the vector must be rotated the right direction in device space, - * but by 90° in user space. So, the rotation depends on - * whether the ctm reflects or not, and that can be determined - * by looking at the determinant of the matrix. - */ - if (stroker->ctm_inverse) { - cairo_matrix_transform_distance (stroker->ctm_inverse, &slope_dx, &slope_dy); - normalize_slope (&slope_dx, &slope_dy); - - if (stroker->ctm_det_positive) { - face_dx = - slope_dy * stroker->half_line_width; - face_dy = slope_dx * stroker->half_line_width; - } else { - face_dx = slope_dy * stroker->half_line_width; - face_dy = - slope_dx * stroker->half_line_width; - } - - /* back to device space */ - cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); - } else { - face_dx = - slope_dy * stroker->half_line_width; - face_dy = slope_dx * stroker->half_line_width; - } - - offset_ccw.x = _cairo_fixed_from_double (face_dx); - offset_ccw.y = _cairo_fixed_from_double (face_dy); - offset_cw.x = -offset_ccw.x; - offset_cw.y = -offset_ccw.y; - - face->ccw = *point; - translate_point (&face->ccw, &offset_ccw); - - face->point = *point; - - face->cw = *point; - translate_point (&face->cw, &offset_cw); - - face->usr_vector.x = slope_dx; - face->usr_vector.y = slope_dy; - - face->dev_vector = *dev_slope; -} - -static void -add_caps (struct stroker *stroker) -{ - /* check for a degenerative sub_path */ - if (stroker->has_initial_sub_path && - !stroker->has_first_face && - !stroker->has_current_face && - stroker->style->line_cap == CAIRO_LINE_CAP_ROUND) - { - /* pick an arbitrary slope to use */ - cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; - cairo_stroke_face_t face; - - /* arbitrarily choose first_point - * first_point and current_point should be the same */ - compute_face (&stroker->first_point, &slope, stroker, &face); - - add_leading_cap (stroker, &face); - add_trailing_cap (stroker, &face); - } - - if (stroker->has_first_face) - add_leading_cap (stroker, &stroker->first_face); - - if (stroker->has_current_face) - add_trailing_cap (stroker, &stroker->current_face); -} - -static cairo_bool_t -stroker_intersects_edge (const struct stroker *stroker, - const cairo_stroke_face_t *start, - const cairo_stroke_face_t *end) -{ - cairo_box_t box; - - if (! stroker->has_bounds) - return TRUE; - - if (_cairo_box_contains_point (&stroker->tight_bounds, &start->cw)) - return TRUE; - box.p2 = box.p1 = start->cw; - - if (_cairo_box_contains_point (&stroker->tight_bounds, &start->ccw)) - return TRUE; - _cairo_box_add_point (&box, &start->ccw); - - if (_cairo_box_contains_point (&stroker->tight_bounds, &end->cw)) - return TRUE; - _cairo_box_add_point (&box, &end->cw); - - if (_cairo_box_contains_point (&stroker->tight_bounds, &end->ccw)) - return TRUE; - _cairo_box_add_point (&box, &end->ccw); - - return (box.p2.x > stroker->tight_bounds.p1.x && - box.p1.x < stroker->tight_bounds.p2.x && - box.p2.y > stroker->tight_bounds.p1.y && - box.p1.y < stroker->tight_bounds.p2.y); -} - -static void -add_sub_edge (struct stroker *stroker, - const cairo_point_t *p1, const cairo_point_t *p2, - const cairo_slope_t *dev_slope, - cairo_stroke_face_t *start, cairo_stroke_face_t *end) -{ - cairo_point_t rectangle[4]; - - compute_face (p1, dev_slope, stroker, start); - - *end = *start; - end->point = *p2; - rectangle[0].x = p2->x - p1->x; - rectangle[0].y = p2->y - p1->y; - translate_point (&end->ccw, &rectangle[0]); - translate_point (&end->cw, &rectangle[0]); - - if (p1->x == p2->x && p1->y == p2->y) - return; - - if (! stroker_intersects_edge (stroker, start, end)) - return; - - rectangle[0] = start->cw; - rectangle[1] = start->ccw; - rectangle[2] = end->ccw; - rectangle[3] = end->cw; - - _cairo_traps_tessellate_convex_quad (stroker->traps, rectangle); -} - -static cairo_status_t -move_to (void *closure, const cairo_point_t *point) -{ - struct stroker *stroker = closure; - - /* Cap the start and end of the previous sub path as needed */ - add_caps (stroker); - - stroker->first_point = *point; - stroker->current_face.point = *point; - - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - stroker->has_initial_sub_path = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -move_to_dashed (void *closure, const cairo_point_t *point) -{ - /* reset the dash pattern for new sub paths */ - struct stroker *stroker = closure; - - _cairo_stroker_dash_start (&stroker->dash); - return move_to (closure, point); -} - -static cairo_status_t -line_to (void *closure, const cairo_point_t *point) -{ - struct stroker *stroker = closure; - cairo_stroke_face_t start, end; - const cairo_point_t *p1 = &stroker->current_face.point; - const cairo_point_t *p2 = point; - cairo_slope_t dev_slope; - - stroker->has_initial_sub_path = TRUE; - - if (p1->x == p2->x && p1->y == p2->y) - return CAIRO_STATUS_SUCCESS; - - _cairo_slope_init (&dev_slope, p1, p2); - add_sub_edge (stroker, p1, p2, &dev_slope, &start, &end); - - if (stroker->has_current_face) { - /* Join with final face from previous segment */ - join (stroker, &stroker->current_face, &start); - } else if (!stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = start; - stroker->has_first_face = TRUE; - } - stroker->current_face = end; - stroker->has_current_face = TRUE; - - return CAIRO_STATUS_SUCCESS; -} - -/* - * Dashed lines. Cap each dash end, join around turns when on - */ -static cairo_status_t -line_to_dashed (void *closure, const cairo_point_t *point) -{ - struct stroker *stroker = closure; - double mag, remain, step_length = 0; - double slope_dx, slope_dy; - double dx2, dy2; - cairo_stroke_face_t sub_start, sub_end; - const cairo_point_t *p1 = &stroker->current_face.point; - const cairo_point_t *p2 = point; - cairo_slope_t dev_slope; - cairo_line_t segment; - cairo_bool_t fully_in_bounds; - - stroker->has_initial_sub_path = stroker->dash.dash_starts_on; - - if (p1->x == p2->x && p1->y == p2->y) - return CAIRO_STATUS_SUCCESS; - - fully_in_bounds = TRUE; - if (stroker->has_bounds && - (! _cairo_box_contains_point (&stroker->join_bounds, p1) || - ! _cairo_box_contains_point (&stroker->join_bounds, p2))) - { - fully_in_bounds = FALSE; - } - - _cairo_slope_init (&dev_slope, p1, p2); - - slope_dx = _cairo_fixed_to_double (p2->x - p1->x); - slope_dy = _cairo_fixed_to_double (p2->y - p1->y); - - if (stroker->ctm_inverse) - cairo_matrix_transform_distance (stroker->ctm_inverse, &slope_dx, &slope_dy); - mag = normalize_slope (&slope_dx, &slope_dy); - if (mag <= DBL_EPSILON) - return CAIRO_STATUS_SUCCESS; - - remain = mag; - segment.p1 = *p1; - while (remain) { - step_length = MIN (stroker->dash.dash_remain, remain); - remain -= step_length; - dx2 = slope_dx * (mag - remain); - dy2 = slope_dy * (mag - remain); - cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); - segment.p2.x = _cairo_fixed_from_double (dx2) + p1->x; - segment.p2.y = _cairo_fixed_from_double (dy2) + p1->y; - - if (stroker->dash.dash_on && - (fully_in_bounds || - (! stroker->has_first_face && stroker->dash.dash_starts_on) || - _cairo_box_intersects_line_segment (&stroker->join_bounds, &segment))) - { - add_sub_edge (stroker, - &segment.p1, &segment.p2, - &dev_slope, - &sub_start, &sub_end); - - if (stroker->has_current_face) { - /* Join with final face from previous segment */ - join (stroker, &stroker->current_face, &sub_start); - - stroker->has_current_face = FALSE; - } else if (! stroker->has_first_face && stroker->dash.dash_starts_on) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = sub_start; - stroker->has_first_face = TRUE; - } else { - /* Cap dash start if not connecting to a previous segment */ - add_leading_cap (stroker, &sub_start); - } - - if (remain) { - /* Cap dash end if not at end of segment */ - add_trailing_cap (stroker, &sub_end); - } else { - stroker->current_face = sub_end; - stroker->has_current_face = TRUE; - } - } else { - if (stroker->has_current_face) { - /* Cap final face from previous segment */ - add_trailing_cap (stroker, &stroker->current_face); - - stroker->has_current_face = FALSE; - } - } - - _cairo_stroker_dash_step (&stroker->dash, step_length); - segment.p1 = segment.p2; - } - - if (stroker->dash.dash_on && ! stroker->has_current_face) { - /* This segment ends on a transition to dash_on, compute a new face - * and add cap for the beginning of the next dash_on step. - * - * Note: this will create a degenerate cap if this is not the last line - * in the path. Whether this behaviour is desirable or not is debatable. - * On one side these degenerate caps can not be reproduced with regular - * path stroking. - * On the other hand, Acroread 7 also produces the degenerate caps. - */ - compute_face (point, &dev_slope, stroker, &stroker->current_face); - - add_leading_cap (stroker, &stroker->current_face); - - stroker->has_current_face = TRUE; - } else - stroker->current_face.point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -spline_to (void *closure, - const cairo_point_t *point, - const cairo_slope_t *tangent) -{ - struct stroker *stroker = closure; - cairo_stroke_face_t face; - - if ((tangent->dx | tangent->dy) == 0) { - cairo_point_t t; - - face = stroker->current_face; - - face.usr_vector.x = -face.usr_vector.x; - face.usr_vector.y = -face.usr_vector.y; - face.dev_slope.x = -face.dev_slope.x; - face.dev_slope.y = -face.dev_slope.y; - face.dev_vector.dx = -face.dev_vector.dx; - face.dev_vector.dy = -face.dev_vector.dy; - - t = face.cw; - face.cw = face.ccw; - face.ccw = t; - - join (stroker, &stroker->current_face, &face); - } else { - cairo_point_t rectangle[4]; - - compute_face (&stroker->current_face.point, tangent, stroker, &face); - join (stroker, &stroker->current_face, &face); - - rectangle[0] = face.cw; - rectangle[1] = face.ccw; - - rectangle[2].x = point->x - face.point.x; - rectangle[2].y = point->y - face.point.y; - face.point = *point; - translate_point (&face.ccw, &rectangle[2]); - translate_point (&face.cw, &rectangle[2]); - - rectangle[2] = face.ccw; - rectangle[3] = face.cw; - - _cairo_traps_tessellate_convex_quad (stroker->traps, rectangle); - } - - stroker->current_face = face; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - struct stroker *stroker = closure; - cairo_line_join_t line_join_save; - cairo_spline_t spline; - cairo_stroke_face_t face; - cairo_status_t status; - - if (stroker->has_bounds && - ! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, - &stroker->line_bounds)) - return line_to (closure, d); - - if (! _cairo_spline_init (&spline, spline_to, stroker, - &stroker->current_face.point, b, c, d)) - return line_to (closure, d); - - compute_face (&stroker->current_face.point, &spline.initial_slope, - stroker, &face); - - if (stroker->has_current_face) { - /* Join with final face from previous segment */ - join (stroker, &stroker->current_face, &face); - } else { - if (! stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = face; - stroker->has_first_face = TRUE; - } - stroker->has_current_face = TRUE; - } - stroker->current_face = face; - - /* Temporarily modify the stroker to use round joins to guarantee - * smooth stroked curves. */ - line_join_save = stroker->line_join; - stroker->line_join = CAIRO_LINE_JOIN_ROUND; - - status = _cairo_spline_decompose (&spline, stroker->tolerance); - - stroker->line_join = line_join_save; - - return status; -} - -static cairo_status_t -curve_to_dashed (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - struct stroker *stroker = closure; - cairo_spline_t spline; - cairo_line_join_t line_join_save; - cairo_spline_add_point_func_t func; - cairo_status_t status; - - func = (cairo_spline_add_point_func_t)line_to_dashed; - - if (stroker->has_bounds && - ! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, - &stroker->line_bounds)) - return func (closure, d, NULL); - - if (! _cairo_spline_init (&spline, func, stroker, - &stroker->current_face.point, b, c, d)) - return func (closure, d, NULL); - - /* Temporarily modify the stroker to use round joins to guarantee - * smooth stroked curves. */ - line_join_save = stroker->line_join; - stroker->line_join = CAIRO_LINE_JOIN_ROUND; - - status = _cairo_spline_decompose (&spline, stroker->tolerance); - - stroker->line_join = line_join_save; - - return status; -} - -static cairo_status_t -_close_path (struct stroker *stroker) -{ - if (stroker->has_first_face && stroker->has_current_face) { - /* Join first and final faces of sub path */ - join (stroker, &stroker->current_face, &stroker->first_face); - } else { - /* Cap the start and end of the sub path as needed */ - add_caps (stroker); - } - - stroker->has_initial_sub_path = FALSE; - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -close_path (void *closure) -{ - struct stroker *stroker = closure; - cairo_status_t status; - - status = line_to (stroker, &stroker->first_point); - if (unlikely (status)) - return status; - - return _close_path (stroker); -} - -static cairo_status_t -close_path_dashed (void *closure) -{ - struct stroker *stroker = closure; - cairo_status_t status; - - status = line_to_dashed (stroker, &stroker->first_point); - if (unlikely (status)) - return status; - - return _close_path (stroker); -} - -cairo_int_status_t -_cairo_path_fixed_stroke_to_traps (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_traps_t *traps) -{ - struct stroker stroker; - cairo_status_t status; - - status = stroker_init (&stroker, path, style, - ctm, ctm_inverse, tolerance, - traps); - if (unlikely (status)) - return status; - - if (stroker.dash.dashed) - status = _cairo_path_fixed_interpret (path, - move_to_dashed, - line_to_dashed, - curve_to_dashed, - close_path_dashed, - &stroker); - else - status = _cairo_path_fixed_interpret (path, - move_to, - line_to, - curve_to, - close_path, - &stroker); - assert(status == CAIRO_STATUS_SUCCESS); - add_caps (&stroker); - - stroker_fini (&stroker); - - return traps->status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-tristrip.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-tristrip.c deleted file mode 100644 index 6ce4131cc0f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke-tristrip.c +++ /dev/null @@ -1,1088 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#define _BSD_SOURCE /* for hypot() */ -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-slope-private.h" -#include "cairo-tristrip-private.h" - -struct stroker { - cairo_stroke_style_t style; - - cairo_tristrip_t *strip; - - const cairo_matrix_t *ctm; - const cairo_matrix_t *ctm_inverse; - double tolerance; - cairo_bool_t ctm_det_positive; - - cairo_pen_t pen; - - cairo_bool_t has_sub_path; - - cairo_point_t first_point; - - cairo_bool_t has_current_face; - cairo_stroke_face_t current_face; - - cairo_bool_t has_first_face; - cairo_stroke_face_t first_face; - - cairo_box_t limit; - cairo_bool_t has_limits; -}; - -static inline double -normalize_slope (double *dx, double *dy); - -static void -compute_face (const cairo_point_t *point, - const cairo_slope_t *dev_slope, - struct stroker *stroker, - cairo_stroke_face_t *face); - -static void -translate_point (cairo_point_t *point, const cairo_point_t *offset) -{ - point->x += offset->x; - point->y += offset->y; -} - -static int -slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) -{ - double c = (dx1 * dy2 - dx2 * dy1); - - if (c > 0) return 1; - if (c < 0) return -1; - return 0; -} - -static inline int -range_step (int i, int step, int max) -{ - i += step; - if (i < 0) - i = max - 1; - if (i >= max) - i = 0; - return i; -} - -/* - * Construct a fan around the midpoint using the vertices from pen between - * inpt and outpt. - */ -static void -add_fan (struct stroker *stroker, - const cairo_slope_t *in_vector, - const cairo_slope_t *out_vector, - const cairo_point_t *midpt, - const cairo_point_t *inpt, - const cairo_point_t *outpt, - cairo_bool_t clockwise) -{ - int start, stop, step, i, npoints; - - if (clockwise) { - step = 1; - - start = _cairo_pen_find_active_cw_vertex_index (&stroker->pen, - in_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[start].slope_cw, - in_vector) < 0) - start = range_step (start, 1, stroker->pen.num_vertices); - - stop = _cairo_pen_find_active_cw_vertex_index (&stroker->pen, - out_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_ccw, - out_vector) > 0) - { - stop = range_step (stop, -1, stroker->pen.num_vertices); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_cw, - in_vector) < 0) - return; - } - - npoints = stop - start; - } else { - step = -1; - - start = _cairo_pen_find_active_ccw_vertex_index (&stroker->pen, - in_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[start].slope_ccw, - in_vector) < 0) - start = range_step (start, -1, stroker->pen.num_vertices); - - stop = _cairo_pen_find_active_ccw_vertex_index (&stroker->pen, - out_vector); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_cw, - out_vector) > 0) - { - stop = range_step (stop, 1, stroker->pen.num_vertices); - if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_ccw, - in_vector) < 0) - return; - } - - npoints = start - stop; - } - stop = range_step (stop, step, stroker->pen.num_vertices); - if (npoints < 0) - npoints += stroker->pen.num_vertices; - if (npoints <= 1) - return; - - for (i = start; - i != stop; - i = range_step (i, step, stroker->pen.num_vertices)) - { - cairo_point_t p = *midpt; - translate_point (&p, &stroker->pen.vertices[i].point); - //contour_add_point (stroker, c, &p); - } -} - -static int -join_is_clockwise (const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - return _cairo_slope_compare (&in->dev_vector, &out->dev_vector) < 0; -} - -static void -inner_join (struct stroker *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out, - int clockwise) -{ - const cairo_point_t *outpt; - - if (clockwise) { - outpt = &out->ccw; - } else { - outpt = &out->cw; - } - //contour_add_point (stroker, inner, &in->point); - //contour_add_point (stroker, inner, outpt); -} - -static void -inner_close (struct stroker *stroker, - const cairo_stroke_face_t *in, - cairo_stroke_face_t *out) -{ - const cairo_point_t *inpt; - - if (join_is_clockwise (in, out)) { - inpt = &out->ccw; - } else { - inpt = &out->cw; - } - - //contour_add_point (stroker, inner, &in->point); - //contour_add_point (stroker, inner, inpt); - //*_cairo_contour_first_point (&inner->contour) = - //*_cairo_contour_last_point (&inner->contour); -} - -static void -outer_close (struct stroker *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - const cairo_point_t *inpt, *outpt; - int clockwise; - - if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && - in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) - { - return; - } - clockwise = join_is_clockwise (in, out); - if (clockwise) { - inpt = &in->cw; - outpt = &out->cw; - } else { - inpt = &in->ccw; - outpt = &out->ccw; - } - - switch (stroker->style.line_join) { - case CAIRO_LINE_JOIN_ROUND: - /* construct a fan around the common midpoint */ - add_fan (stroker, - &in->dev_vector, - &out->dev_vector, - &in->point, inpt, outpt, - clockwise); - break; - - case CAIRO_LINE_JOIN_MITER: - default: { - /* dot product of incoming slope vector with outgoing slope vector */ - double in_dot_out = -in->usr_vector.x * out->usr_vector.x + - -in->usr_vector.y * out->usr_vector.y; - double ml = stroker->style.miter_limit; - - /* Check the miter limit -- lines meeting at an acute angle - * can generate long miters, the limit converts them to bevel - * - * Consider the miter join formed when two line segments - * meet at an angle psi: - * - * /.\ - * /. .\ - * /./ \.\ - * /./psi\.\ - * - * We can zoom in on the right half of that to see: - * - * |\ - * | \ psi/2 - * | \ - * | \ - * | \ - * | \ - * miter \ - * length \ - * | \ - * | .\ - * | . \ - * |. line \ - * \ width \ - * \ \ - * - * - * The right triangle in that figure, (the line-width side is - * shown faintly with three '.' characters), gives us the - * following expression relating miter length, angle and line - * width: - * - * 1 /sin (psi/2) = miter_length / line_width - * - * The right-hand side of this relationship is the same ratio - * in which the miter limit (ml) is expressed. We want to know - * when the miter length is within the miter limit. That is - * when the following condition holds: - * - * 1/sin(psi/2) <= ml - * 1 <= ml sin(psi/2) - * 1 <= ml² sin²(psi/2) - * 2 <= ml² 2 sin²(psi/2) - * 2·sin²(psi/2) = 1-cos(psi) - * 2 <= ml² (1-cos(psi)) - * - * in · out = |in| |out| cos (psi) - * - * in and out are both unit vectors, so: - * - * in · out = cos (psi) - * - * 2 <= ml² (1 - in · out) - * - */ - if (2 <= ml * ml * (1 - in_dot_out)) { - double x1, y1, x2, y2; - double mx, my; - double dx1, dx2, dy1, dy2; - double ix, iy; - double fdx1, fdy1, fdx2, fdy2; - double mdx, mdy; - - /* - * we've got the points already transformed to device - * space, but need to do some computation with them and - * also need to transform the slope from user space to - * device space - */ - /* outer point of incoming line face */ - x1 = _cairo_fixed_to_double (inpt->x); - y1 = _cairo_fixed_to_double (inpt->y); - dx1 = in->usr_vector.x; - dy1 = in->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); - - /* outer point of outgoing line face */ - x2 = _cairo_fixed_to_double (outpt->x); - y2 = _cairo_fixed_to_double (outpt->y); - dx2 = out->usr_vector.x; - dy2 = out->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); - - /* - * Compute the location of the outer corner of the miter. - * That's pretty easy -- just the intersection of the two - * outer edges. We've got slopes and points on each - * of those edges. Compute my directly, then compute - * mx by using the edge with the larger dy; that avoids - * dividing by values close to zero. - */ - my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / - (dx1 * dy2 - dx2 * dy1)); - if (fabs (dy1) >= fabs (dy2)) - mx = (my - y1) * dx1 / dy1 + x1; - else - mx = (my - y2) * dx2 / dy2 + x2; - - /* - * When the two outer edges are nearly parallel, slight - * perturbations in the position of the outer points of the lines - * caused by representing them in fixed point form can cause the - * intersection point of the miter to move a large amount. If - * that moves the miter intersection from between the two faces, - * then draw a bevel instead. - */ - - ix = _cairo_fixed_to_double (in->point.x); - iy = _cairo_fixed_to_double (in->point.y); - - /* slope of one face */ - fdx1 = x1 - ix; fdy1 = y1 - iy; - - /* slope of the other face */ - fdx2 = x2 - ix; fdy2 = y2 - iy; - - /* slope from the intersection to the miter point */ - mdx = mx - ix; mdy = my - iy; - - /* - * Make sure the miter point line lies between the two - * faces by comparing the slopes - */ - if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != - slope_compare_sgn (fdx2, fdy2, mdx, mdy)) - { - cairo_point_t p; - - p.x = _cairo_fixed_from_double (mx); - p.y = _cairo_fixed_from_double (my); - - //*_cairo_contour_last_point (&outer->contour) = p; - //*_cairo_contour_first_point (&outer->contour) = p; - return; - } - } - break; - } - - case CAIRO_LINE_JOIN_BEVEL: - break; - } - //contour_add_point (stroker, outer, outpt); -} - -static void -outer_join (struct stroker *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out, - int clockwise) -{ - const cairo_point_t *inpt, *outpt; - - if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && - in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) - { - return; - } - if (clockwise) { - inpt = &in->cw; - outpt = &out->cw; - } else { - inpt = &in->ccw; - outpt = &out->ccw; - } - - switch (stroker->style.line_join) { - case CAIRO_LINE_JOIN_ROUND: - /* construct a fan around the common midpoint */ - add_fan (stroker, - &in->dev_vector, - &out->dev_vector, - &in->point, inpt, outpt, - clockwise); - break; - - case CAIRO_LINE_JOIN_MITER: - default: { - /* dot product of incoming slope vector with outgoing slope vector */ - double in_dot_out = -in->usr_vector.x * out->usr_vector.x + - -in->usr_vector.y * out->usr_vector.y; - double ml = stroker->style.miter_limit; - - /* Check the miter limit -- lines meeting at an acute angle - * can generate long miters, the limit converts them to bevel - * - * Consider the miter join formed when two line segments - * meet at an angle psi: - * - * /.\ - * /. .\ - * /./ \.\ - * /./psi\.\ - * - * We can zoom in on the right half of that to see: - * - * |\ - * | \ psi/2 - * | \ - * | \ - * | \ - * | \ - * miter \ - * length \ - * | \ - * | .\ - * | . \ - * |. line \ - * \ width \ - * \ \ - * - * - * The right triangle in that figure, (the line-width side is - * shown faintly with three '.' characters), gives us the - * following expression relating miter length, angle and line - * width: - * - * 1 /sin (psi/2) = miter_length / line_width - * - * The right-hand side of this relationship is the same ratio - * in which the miter limit (ml) is expressed. We want to know - * when the miter length is within the miter limit. That is - * when the following condition holds: - * - * 1/sin(psi/2) <= ml - * 1 <= ml sin(psi/2) - * 1 <= ml² sin²(psi/2) - * 2 <= ml² 2 sin²(psi/2) - * 2·sin²(psi/2) = 1-cos(psi) - * 2 <= ml² (1-cos(psi)) - * - * in · out = |in| |out| cos (psi) - * - * in and out are both unit vectors, so: - * - * in · out = cos (psi) - * - * 2 <= ml² (1 - in · out) - * - */ - if (2 <= ml * ml * (1 - in_dot_out)) { - double x1, y1, x2, y2; - double mx, my; - double dx1, dx2, dy1, dy2; - double ix, iy; - double fdx1, fdy1, fdx2, fdy2; - double mdx, mdy; - - /* - * we've got the points already transformed to device - * space, but need to do some computation with them and - * also need to transform the slope from user space to - * device space - */ - /* outer point of incoming line face */ - x1 = _cairo_fixed_to_double (inpt->x); - y1 = _cairo_fixed_to_double (inpt->y); - dx1 = in->usr_vector.x; - dy1 = in->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); - - /* outer point of outgoing line face */ - x2 = _cairo_fixed_to_double (outpt->x); - y2 = _cairo_fixed_to_double (outpt->y); - dx2 = out->usr_vector.x; - dy2 = out->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); - - /* - * Compute the location of the outer corner of the miter. - * That's pretty easy -- just the intersection of the two - * outer edges. We've got slopes and points on each - * of those edges. Compute my directly, then compute - * mx by using the edge with the larger dy; that avoids - * dividing by values close to zero. - */ - my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / - (dx1 * dy2 - dx2 * dy1)); - if (fabs (dy1) >= fabs (dy2)) - mx = (my - y1) * dx1 / dy1 + x1; - else - mx = (my - y2) * dx2 / dy2 + x2; - - /* - * When the two outer edges are nearly parallel, slight - * perturbations in the position of the outer points of the lines - * caused by representing them in fixed point form can cause the - * intersection point of the miter to move a large amount. If - * that moves the miter intersection from between the two faces, - * then draw a bevel instead. - */ - - ix = _cairo_fixed_to_double (in->point.x); - iy = _cairo_fixed_to_double (in->point.y); - - /* slope of one face */ - fdx1 = x1 - ix; fdy1 = y1 - iy; - - /* slope of the other face */ - fdx2 = x2 - ix; fdy2 = y2 - iy; - - /* slope from the intersection to the miter point */ - mdx = mx - ix; mdy = my - iy; - - /* - * Make sure the miter point line lies between the two - * faces by comparing the slopes - */ - if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != - slope_compare_sgn (fdx2, fdy2, mdx, mdy)) - { - cairo_point_t p; - - p.x = _cairo_fixed_from_double (mx); - p.y = _cairo_fixed_from_double (my); - - //*_cairo_contour_last_point (&outer->contour) = p; - return; - } - } - break; - } - - case CAIRO_LINE_JOIN_BEVEL: - break; - } - //contour_add_point (stroker,outer, outpt); -} - -static void -add_cap (struct stroker *stroker, - const cairo_stroke_face_t *f) -{ - switch (stroker->style.line_cap) { - case CAIRO_LINE_CAP_ROUND: { - cairo_slope_t slope; - - slope.dx = -f->dev_vector.dx; - slope.dy = -f->dev_vector.dy; - - add_fan (stroker, &f->dev_vector, &slope, - &f->point, &f->ccw, &f->cw, - FALSE); - break; - } - - case CAIRO_LINE_CAP_SQUARE: { - double dx, dy; - cairo_slope_t fvector; - cairo_point_t quad[4]; - - dx = f->usr_vector.x; - dy = f->usr_vector.y; - dx *= stroker->style.line_width / 2.0; - dy *= stroker->style.line_width / 2.0; - cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); - fvector.dx = _cairo_fixed_from_double (dx); - fvector.dy = _cairo_fixed_from_double (dy); - - quad[0] = f->ccw; - quad[1].x = f->ccw.x + fvector.dx; - quad[1].y = f->ccw.y + fvector.dy; - quad[2].x = f->cw.x + fvector.dx; - quad[2].y = f->cw.y + fvector.dy; - quad[3] = f->cw; - - //contour_add_point (stroker, c, &quad[1]); - //contour_add_point (stroker, c, &quad[2]); - } - - case CAIRO_LINE_CAP_BUTT: - default: - break; - } - //contour_add_point (stroker, c, &f->cw); -} - -static void -add_leading_cap (struct stroker *stroker, - const cairo_stroke_face_t *face) -{ - cairo_stroke_face_t reversed; - cairo_point_t t; - - reversed = *face; - - /* The initial cap needs an outward facing vector. Reverse everything */ - reversed.usr_vector.x = -reversed.usr_vector.x; - reversed.usr_vector.y = -reversed.usr_vector.y; - reversed.dev_vector.dx = -reversed.dev_vector.dx; - reversed.dev_vector.dy = -reversed.dev_vector.dy; - - t = reversed.cw; - reversed.cw = reversed.ccw; - reversed.ccw = t; - - add_cap (stroker, &reversed); -} - -static void -add_trailing_cap (struct stroker *stroker, - const cairo_stroke_face_t *face) -{ - add_cap (stroker, face); -} - -static inline double -normalize_slope (double *dx, double *dy) -{ - double dx0 = *dx, dy0 = *dy; - double mag; - - assert (dx0 != 0.0 || dy0 != 0.0); - - if (dx0 == 0.0) { - *dx = 0.0; - if (dy0 > 0.0) { - mag = dy0; - *dy = 1.0; - } else { - mag = -dy0; - *dy = -1.0; - } - } else if (dy0 == 0.0) { - *dy = 0.0; - if (dx0 > 0.0) { - mag = dx0; - *dx = 1.0; - } else { - mag = -dx0; - *dx = -1.0; - } - } else { - mag = hypot (dx0, dy0); - *dx = dx0 / mag; - *dy = dy0 / mag; - } - - return mag; -} - -static void -compute_face (const cairo_point_t *point, - const cairo_slope_t *dev_slope, - struct stroker *stroker, - cairo_stroke_face_t *face) -{ - double face_dx, face_dy; - cairo_point_t offset_ccw, offset_cw; - double slope_dx, slope_dy; - - slope_dx = _cairo_fixed_to_double (dev_slope->dx); - slope_dy = _cairo_fixed_to_double (dev_slope->dy); - face->length = normalize_slope (&slope_dx, &slope_dy); - face->dev_slope.x = slope_dx; - face->dev_slope.y = slope_dy; - - /* - * rotate to get a line_width/2 vector along the face, note that - * the vector must be rotated the right direction in device space, - * but by 90° in user space. So, the rotation depends on - * whether the ctm reflects or not, and that can be determined - * by looking at the determinant of the matrix. - */ - if (! _cairo_matrix_is_identity (stroker->ctm_inverse)) { - /* Normalize the matrix! */ - cairo_matrix_transform_distance (stroker->ctm_inverse, - &slope_dx, &slope_dy); - normalize_slope (&slope_dx, &slope_dy); - - if (stroker->ctm_det_positive) { - face_dx = - slope_dy * (stroker->style.line_width / 2.0); - face_dy = slope_dx * (stroker->style.line_width / 2.0); - } else { - face_dx = slope_dy * (stroker->style.line_width / 2.0); - face_dy = - slope_dx * (stroker->style.line_width / 2.0); - } - - /* back to device space */ - cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); - } else { - face_dx = - slope_dy * (stroker->style.line_width / 2.0); - face_dy = slope_dx * (stroker->style.line_width / 2.0); - } - - offset_ccw.x = _cairo_fixed_from_double (face_dx); - offset_ccw.y = _cairo_fixed_from_double (face_dy); - offset_cw.x = -offset_ccw.x; - offset_cw.y = -offset_ccw.y; - - face->ccw = *point; - translate_point (&face->ccw, &offset_ccw); - - face->point = *point; - - face->cw = *point; - translate_point (&face->cw, &offset_cw); - - face->usr_vector.x = slope_dx; - face->usr_vector.y = slope_dy; - - face->dev_vector = *dev_slope; -} - -static void -add_caps (struct stroker *stroker) -{ - /* check for a degenerative sub_path */ - if (stroker->has_sub_path && - ! stroker->has_first_face && - ! stroker->has_current_face && - stroker->style.line_cap == CAIRO_LINE_CAP_ROUND) - { - /* pick an arbitrary slope to use */ - cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; - cairo_stroke_face_t face; - - /* arbitrarily choose first_point */ - compute_face (&stroker->first_point, &slope, stroker, &face); - - add_leading_cap (stroker, &face); - add_trailing_cap (stroker, &face); - - /* ensure the circle is complete */ - //_cairo_contour_add_point (&stroker->ccw.contour, - //_cairo_contour_first_point (&stroker->ccw.contour)); - } else { - if (stroker->has_current_face) - add_trailing_cap (stroker, &stroker->current_face); - - //_cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); - //_cairo_contour_reset (&stroker->ccw.contour); - - if (stroker->has_first_face) { - //_cairo_contour_add_point (&stroker->ccw.contour, - //&stroker->first_face.cw); - add_leading_cap (stroker, &stroker->first_face); - //_cairo_polygon_add_contour (stroker->polygon, - //&stroker->ccw.contour); - //_cairo_contour_reset (&stroker->ccw.contour); - } - } -} - -static cairo_status_t -move_to (void *closure, - const cairo_point_t *point) -{ - struct stroker *stroker = closure; - - /* Cap the start and end of the previous sub path as needed */ - add_caps (stroker); - - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - stroker->has_sub_path = FALSE; - - stroker->first_point = *point; - - stroker->current_face.point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -line_to (void *closure, - const cairo_point_t *point) -{ - struct stroker *stroker = closure; - cairo_stroke_face_t start; - cairo_point_t *p1 = &stroker->current_face.point; - cairo_slope_t dev_slope; - - stroker->has_sub_path = TRUE; - - if (p1->x == point->x && p1->y == point->y) - return CAIRO_STATUS_SUCCESS; - - _cairo_slope_init (&dev_slope, p1, point); - compute_face (p1, &dev_slope, stroker, &start); - - if (stroker->has_current_face) { - int clockwise = join_is_clockwise (&stroker->current_face, &start); - /* Join with final face from previous segment */ - outer_join (stroker, &stroker->current_face, &start, clockwise); - inner_join (stroker, &stroker->current_face, &start, clockwise); - } else { - if (! stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = start; - _cairo_tristrip_move_to (stroker->strip, &start.cw); - stroker->has_first_face = TRUE; - } - stroker->has_current_face = TRUE; - - _cairo_tristrip_add_point (stroker->strip, &start.cw); - _cairo_tristrip_add_point (stroker->strip, &start.ccw); - } - - stroker->current_face = start; - stroker->current_face.point = *point; - stroker->current_face.ccw.x += dev_slope.dx; - stroker->current_face.ccw.y += dev_slope.dy; - stroker->current_face.cw.x += dev_slope.dx; - stroker->current_face.cw.y += dev_slope.dy; - - _cairo_tristrip_add_point (stroker->strip, &stroker->current_face.cw); - _cairo_tristrip_add_point (stroker->strip, &stroker->current_face.ccw); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -spline_to (void *closure, - const cairo_point_t *point, - const cairo_slope_t *tangent) -{ - struct stroker *stroker = closure; - cairo_stroke_face_t face; - - if (tangent->dx == 0 && tangent->dy == 0) { - const cairo_point_t *inpt, *outpt; - cairo_point_t t; - int clockwise; - - face = stroker->current_face; - - face.usr_vector.x = -face.usr_vector.x; - face.usr_vector.y = -face.usr_vector.y; - face.dev_vector.dx = -face.dev_vector.dx; - face.dev_vector.dy = -face.dev_vector.dy; - - t = face.cw; - face.cw = face.ccw; - face.ccw = t; - - clockwise = join_is_clockwise (&stroker->current_face, &face); - if (clockwise) { - inpt = &stroker->current_face.cw; - outpt = &face.cw; - } else { - inpt = &stroker->current_face.ccw; - outpt = &face.ccw; - } - - add_fan (stroker, - &stroker->current_face.dev_vector, - &face.dev_vector, - &stroker->current_face.point, inpt, outpt, - clockwise); - } else { - compute_face (point, tangent, stroker, &face); - - if (face.dev_slope.x * stroker->current_face.dev_slope.x + - face.dev_slope.y * stroker->current_face.dev_slope.y < 0) - { - const cairo_point_t *inpt, *outpt; - int clockwise = join_is_clockwise (&stroker->current_face, &face); - - stroker->current_face.cw.x += face.point.x - stroker->current_face.point.x; - stroker->current_face.cw.y += face.point.y - stroker->current_face.point.y; - //contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw); - - stroker->current_face.ccw.x += face.point.x - stroker->current_face.point.x; - stroker->current_face.ccw.y += face.point.y - stroker->current_face.point.y; - //contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw); - - if (clockwise) { - inpt = &stroker->current_face.cw; - outpt = &face.cw; - } else { - inpt = &stroker->current_face.ccw; - outpt = &face.ccw; - } - add_fan (stroker, - &stroker->current_face.dev_vector, - &face.dev_vector, - &stroker->current_face.point, inpt, outpt, - clockwise); - } - - _cairo_tristrip_add_point (stroker->strip, &face.cw); - _cairo_tristrip_add_point (stroker->strip, &face.ccw); - } - - stroker->current_face = face; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - struct stroker *stroker = closure; - cairo_spline_t spline; - cairo_stroke_face_t face; - - if (stroker->has_limits) { - if (! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, - &stroker->limit)) - return line_to (closure, d); - } - - if (! _cairo_spline_init (&spline, spline_to, stroker, - &stroker->current_face.point, b, c, d)) - return line_to (closure, d); - - compute_face (&stroker->current_face.point, &spline.initial_slope, - stroker, &face); - - if (stroker->has_current_face) { - int clockwise = join_is_clockwise (&stroker->current_face, &face); - /* Join with final face from previous segment */ - outer_join (stroker, &stroker->current_face, &face, clockwise); - inner_join (stroker, &stroker->current_face, &face, clockwise); - } else { - if (! stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = face; - _cairo_tristrip_move_to (stroker->strip, &face.cw); - stroker->has_first_face = TRUE; - } - stroker->has_current_face = TRUE; - - _cairo_tristrip_add_point (stroker->strip, &face.cw); - _cairo_tristrip_add_point (stroker->strip, &face.ccw); - } - stroker->current_face = face; - - return _cairo_spline_decompose (&spline, stroker->tolerance); -} - -static cairo_status_t -close_path (void *closure) -{ - struct stroker *stroker = closure; - cairo_status_t status; - - status = line_to (stroker, &stroker->first_point); - if (unlikely (status)) - return status; - - if (stroker->has_first_face && stroker->has_current_face) { - /* Join first and final faces of sub path */ - outer_close (stroker, &stroker->current_face, &stroker->first_face); - inner_close (stroker, &stroker->current_face, &stroker->first_face); - } else { - /* Cap the start and end of the sub path as needed */ - add_caps (stroker); - } - - stroker->has_sub_path = FALSE; - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_path_fixed_stroke_to_tristrip (const cairo_path_fixed_t *path, - const cairo_stroke_style_t*style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_tristrip_t *strip) -{ - struct stroker stroker; - cairo_int_status_t status; - int i; - - if (style->num_dashes) - return CAIRO_INT_STATUS_UNSUPPORTED; - - stroker.style = *style; - stroker.ctm = ctm; - stroker.ctm_inverse = ctm_inverse; - stroker.tolerance = tolerance; - - stroker.ctm_det_positive = - _cairo_matrix_compute_determinant (ctm) >= 0.0; - - status = _cairo_pen_init (&stroker.pen, - style->line_width / 2.0, - tolerance, ctm); - if (unlikely (status)) - return status; - - if (stroker.pen.num_vertices <= 1) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - stroker.has_current_face = FALSE; - stroker.has_first_face = FALSE; - stroker.has_sub_path = FALSE; - - stroker.has_limits = strip->num_limits > 0; - stroker.limit = strip->limits[0]; - for (i = 1; i < strip->num_limits; i++) - _cairo_box_add_box (&stroker.limit, &strip->limits[i]); - - stroker.strip = strip; - - status = _cairo_path_fixed_interpret (path, - move_to, - line_to, - curve_to, - close_path, - &stroker); - /* Cap the start and end of the final sub path as needed */ - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - add_caps (&stroker); - - _cairo_pen_fini (&stroker.pen); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke.c deleted file mode 100644 index 4d4ede81361..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path-stroke.c +++ /dev/null @@ -1,1485 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#define _BSD_SOURCE /* for hypot() */ -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-slope-private.h" -#include "cairo-stroke-dash-private.h" -#include "cairo-traps-private.h" - -typedef struct cairo_stroker { - cairo_stroke_style_t style; - - const cairo_matrix_t *ctm; - const cairo_matrix_t *ctm_inverse; - double half_line_width; - double tolerance; - double spline_cusp_tolerance; - double ctm_determinant; - cairo_bool_t ctm_det_positive; - - void *closure; - cairo_status_t (*add_external_edge) (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2); - cairo_status_t (*add_triangle) (void *closure, - const cairo_point_t triangle[3]); - cairo_status_t (*add_triangle_fan) (void *closure, - const cairo_point_t *midpt, - const cairo_point_t *points, - int npoints); - cairo_status_t (*add_convex_quad) (void *closure, - const cairo_point_t quad[4]); - - cairo_pen_t pen; - - cairo_point_t current_point; - cairo_point_t first_point; - - cairo_bool_t has_initial_sub_path; - - cairo_bool_t has_current_face; - cairo_stroke_face_t current_face; - - cairo_bool_t has_first_face; - cairo_stroke_face_t first_face; - - cairo_stroker_dash_t dash; - - cairo_bool_t has_bounds; - cairo_box_t bounds; -} cairo_stroker_t; - -static void -_cairo_stroker_limit (cairo_stroker_t *stroker, - const cairo_path_fixed_t *path, - const cairo_box_t *boxes, - int num_boxes) -{ - double dx, dy; - cairo_fixed_t fdx, fdy; - - stroker->has_bounds = TRUE; - _cairo_boxes_get_extents (boxes, num_boxes, &stroker->bounds); - - /* Extend the bounds in each direction to account for the maximum area - * we might generate trapezoids, to capture line segments that are outside - * of the bounds but which might generate rendering that's within bounds. - */ - - _cairo_stroke_style_max_distance_from_path (&stroker->style, path, - stroker->ctm, &dx, &dy); - - fdx = _cairo_fixed_from_double (dx); - fdy = _cairo_fixed_from_double (dy); - - stroker->bounds.p1.x -= fdx; - stroker->bounds.p2.x += fdx; - - stroker->bounds.p1.y -= fdy; - stroker->bounds.p2.y += fdy; -} - -static cairo_status_t -_cairo_stroker_init (cairo_stroker_t *stroker, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - const cairo_box_t *limits, - int num_limits) -{ - cairo_status_t status; - - stroker->style = *stroke_style; - stroker->ctm = ctm; - stroker->ctm_inverse = ctm_inverse; - stroker->tolerance = tolerance; - stroker->half_line_width = stroke_style->line_width / 2.0; - - /* To test whether we need to join two segments of a spline using - * a round-join or a bevel-join, we can inspect the angle between the - * two segments. If the difference between the chord distance - * (half-line-width times the cosine of the bisection angle) and the - * half-line-width itself is greater than tolerance then we need to - * inject a point. - */ - stroker->spline_cusp_tolerance = 1 - tolerance / stroker->half_line_width; - stroker->spline_cusp_tolerance *= stroker->spline_cusp_tolerance; - stroker->spline_cusp_tolerance *= 2; - stroker->spline_cusp_tolerance -= 1; - - stroker->ctm_determinant = _cairo_matrix_compute_determinant (stroker->ctm); - stroker->ctm_det_positive = stroker->ctm_determinant >= 0.0; - - status = _cairo_pen_init (&stroker->pen, - stroker->half_line_width, tolerance, ctm); - if (unlikely (status)) - return status; - - stroker->has_current_face = FALSE; - stroker->has_first_face = FALSE; - stroker->has_initial_sub_path = FALSE; - - _cairo_stroker_dash_init (&stroker->dash, stroke_style); - - stroker->add_external_edge = NULL; - - stroker->has_bounds = FALSE; - if (num_limits) - _cairo_stroker_limit (stroker, path, limits, num_limits); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_stroker_fini (cairo_stroker_t *stroker) -{ - _cairo_pen_fini (&stroker->pen); -} - -static void -_translate_point (cairo_point_t *point, const cairo_point_t *offset) -{ - point->x += offset->x; - point->y += offset->y; -} - -static int -_cairo_stroker_join_is_clockwise (const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - cairo_slope_t in_slope, out_slope; - - _cairo_slope_init (&in_slope, &in->point, &in->cw); - _cairo_slope_init (&out_slope, &out->point, &out->cw); - - return _cairo_slope_compare (&in_slope, &out_slope) < 0; -} - -/** - * _cairo_slope_compare_sgn: - * - * Return -1, 0 or 1 depending on the relative slopes of - * two lines. - **/ -static int -_cairo_slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) -{ - double c = (dx1 * dy2 - dx2 * dy1); - - if (c > 0) return 1; - if (c < 0) return -1; - return 0; -} - -static inline int -_range_step (int i, int step, int max) -{ - i += step; - if (i < 0) - i = max - 1; - if (i >= max) - i = 0; - return i; -} - -/* - * Construct a fan around the midpoint using the vertices from pen between - * inpt and outpt. - */ -static cairo_status_t -_tessellate_fan (cairo_stroker_t *stroker, - const cairo_slope_t *in_vector, - const cairo_slope_t *out_vector, - const cairo_point_t *midpt, - const cairo_point_t *inpt, - const cairo_point_t *outpt, - cairo_bool_t clockwise) -{ - cairo_point_t stack_points[64], *points = stack_points; - cairo_pen_t *pen = &stroker->pen; - int start, stop, num_points = 0; - cairo_status_t status; - - if (stroker->has_bounds && - ! _cairo_box_contains_point (&stroker->bounds, midpt)) - goto BEVEL; - - assert (stroker->pen.num_vertices); - - if (clockwise) { - _cairo_pen_find_active_ccw_vertices (pen, - in_vector, out_vector, - &start, &stop); - if (stroker->add_external_edge) { - cairo_point_t last; - last = *inpt; - while (start != stop) { - cairo_point_t p = *midpt; - _translate_point (&p, &pen->vertices[start].point); - - status = stroker->add_external_edge (stroker->closure, - &last, &p); - if (unlikely (status)) - return status; - last = p; - - if (start-- == 0) - start += pen->num_vertices; - } - status = stroker->add_external_edge (stroker->closure, - &last, outpt); - } else { - if (start == stop) - goto BEVEL; - - num_points = stop - start; - if (num_points < 0) - num_points += pen->num_vertices; - num_points += 2; - if (num_points > ARRAY_LENGTH(stack_points)) { - points = _cairo_malloc_ab (num_points, sizeof (cairo_point_t)); - if (unlikely (points == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - points[0] = *inpt; - num_points = 1; - while (start != stop) { - points[num_points] = *midpt; - _translate_point (&points[num_points], &pen->vertices[start].point); - num_points++; - - if (start-- == 0) - start += pen->num_vertices; - } - points[num_points++] = *outpt; - } - } else { - _cairo_pen_find_active_cw_vertices (pen, - in_vector, out_vector, - &start, &stop); - if (stroker->add_external_edge) { - cairo_point_t last; - last = *inpt; - while (start != stop) { - cairo_point_t p = *midpt; - _translate_point (&p, &pen->vertices[start].point); - - status = stroker->add_external_edge (stroker->closure, - &p, &last); - if (unlikely (status)) - return status; - last = p; - - if (++start == pen->num_vertices) - start = 0; - } - status = stroker->add_external_edge (stroker->closure, - outpt, &last); - } else { - if (start == stop) - goto BEVEL; - - num_points = stop - start; - if (num_points < 0) - num_points += pen->num_vertices; - num_points += 2; - if (num_points > ARRAY_LENGTH(stack_points)) { - points = _cairo_malloc_ab (num_points, sizeof (cairo_point_t)); - if (unlikely (points == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - points[0] = *inpt; - num_points = 1; - while (start != stop) { - points[num_points] = *midpt; - _translate_point (&points[num_points], &pen->vertices[start].point); - num_points++; - - if (++start == pen->num_vertices) - start = 0; - } - points[num_points++] = *outpt; - } - } - - if (num_points) { - status = stroker->add_triangle_fan (stroker->closure, - midpt, points, num_points); - } - - if (points != stack_points) - free (points); - - return status; - -BEVEL: - /* Ensure a leak free connection... */ - if (stroker->add_external_edge != NULL) { - if (clockwise) - return stroker->add_external_edge (stroker->closure, inpt, outpt); - else - return stroker->add_external_edge (stroker->closure, outpt, inpt); - } else { - stack_points[0] = *midpt; - stack_points[1] = *inpt; - stack_points[2] = *outpt; - return stroker->add_triangle (stroker->closure, stack_points); - } -} - -static cairo_status_t -_cairo_stroker_join (cairo_stroker_t *stroker, - const cairo_stroke_face_t *in, - const cairo_stroke_face_t *out) -{ - int clockwise = _cairo_stroker_join_is_clockwise (out, in); - const cairo_point_t *inpt, *outpt; - cairo_point_t points[4]; - cairo_status_t status; - - if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && - in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) - { - return CAIRO_STATUS_SUCCESS; - } - - if (clockwise) { - if (stroker->add_external_edge != NULL) { - status = stroker->add_external_edge (stroker->closure, - &out->cw, &in->point); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &in->point, &in->cw); - if (unlikely (status)) - return status; - } - - inpt = &in->ccw; - outpt = &out->ccw; - } else { - if (stroker->add_external_edge != NULL) { - status = stroker->add_external_edge (stroker->closure, - &in->ccw, &in->point); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &in->point, &out->ccw); - if (unlikely (status)) - return status; - } - - inpt = &in->cw; - outpt = &out->cw; - } - - switch (stroker->style.line_join) { - case CAIRO_LINE_JOIN_ROUND: - /* construct a fan around the common midpoint */ - return _tessellate_fan (stroker, - &in->dev_vector, - &out->dev_vector, - &in->point, inpt, outpt, - clockwise); - - case CAIRO_LINE_JOIN_MITER: - default: { - /* dot product of incoming slope vector with outgoing slope vector */ - double in_dot_out = -in->usr_vector.x * out->usr_vector.x + - -in->usr_vector.y * out->usr_vector.y; - double ml = stroker->style.miter_limit; - - /* Check the miter limit -- lines meeting at an acute angle - * can generate long miters, the limit converts them to bevel - * - * Consider the miter join formed when two line segments - * meet at an angle psi: - * - * /.\ - * /. .\ - * /./ \.\ - * /./psi\.\ - * - * We can zoom in on the right half of that to see: - * - * |\ - * | \ psi/2 - * | \ - * | \ - * | \ - * | \ - * miter \ - * length \ - * | \ - * | .\ - * | . \ - * |. line \ - * \ width \ - * \ \ - * - * - * The right triangle in that figure, (the line-width side is - * shown faintly with three '.' characters), gives us the - * following expression relating miter length, angle and line - * width: - * - * 1 /sin (psi/2) = miter_length / line_width - * - * The right-hand side of this relationship is the same ratio - * in which the miter limit (ml) is expressed. We want to know - * when the miter length is within the miter limit. That is - * when the following condition holds: - * - * 1/sin(psi/2) <= ml - * 1 <= ml sin(psi/2) - * 1 <= ml² sin²(psi/2) - * 2 <= ml² 2 sin²(psi/2) - * 2·sin²(psi/2) = 1-cos(psi) - * 2 <= ml² (1-cos(psi)) - * - * in · out = |in| |out| cos (psi) - * - * in and out are both unit vectors, so: - * - * in · out = cos (psi) - * - * 2 <= ml² (1 - in · out) - * - */ - if (2 <= ml * ml * (1 - in_dot_out)) { - double x1, y1, x2, y2; - double mx, my; - double dx1, dx2, dy1, dy2; - double ix, iy; - double fdx1, fdy1, fdx2, fdy2; - double mdx, mdy; - - /* - * we've got the points already transformed to device - * space, but need to do some computation with them and - * also need to transform the slope from user space to - * device space - */ - /* outer point of incoming line face */ - x1 = _cairo_fixed_to_double (inpt->x); - y1 = _cairo_fixed_to_double (inpt->y); - dx1 = in->usr_vector.x; - dy1 = in->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); - - /* outer point of outgoing line face */ - x2 = _cairo_fixed_to_double (outpt->x); - y2 = _cairo_fixed_to_double (outpt->y); - dx2 = out->usr_vector.x; - dy2 = out->usr_vector.y; - cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); - - /* - * Compute the location of the outer corner of the miter. - * That's pretty easy -- just the intersection of the two - * outer edges. We've got slopes and points on each - * of those edges. Compute my directly, then compute - * mx by using the edge with the larger dy; that avoids - * dividing by values close to zero. - */ - my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / - (dx1 * dy2 - dx2 * dy1)); - if (fabs (dy1) >= fabs (dy2)) - mx = (my - y1) * dx1 / dy1 + x1; - else - mx = (my - y2) * dx2 / dy2 + x2; - - /* - * When the two outer edges are nearly parallel, slight - * perturbations in the position of the outer points of the lines - * caused by representing them in fixed point form can cause the - * intersection point of the miter to move a large amount. If - * that moves the miter intersection from between the two faces, - * then draw a bevel instead. - */ - - ix = _cairo_fixed_to_double (in->point.x); - iy = _cairo_fixed_to_double (in->point.y); - - /* slope of one face */ - fdx1 = x1 - ix; fdy1 = y1 - iy; - - /* slope of the other face */ - fdx2 = x2 - ix; fdy2 = y2 - iy; - - /* slope from the intersection to the miter point */ - mdx = mx - ix; mdy = my - iy; - - /* - * Make sure the miter point line lies between the two - * faces by comparing the slopes - */ - if (_cairo_slope_compare_sgn (fdx1, fdy1, mdx, mdy) != - _cairo_slope_compare_sgn (fdx2, fdy2, mdx, mdy)) - { - if (stroker->add_external_edge != NULL) { - points[0].x = _cairo_fixed_from_double (mx); - points[0].y = _cairo_fixed_from_double (my); - - if (clockwise) { - status = stroker->add_external_edge (stroker->closure, - inpt, &points[0]); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &points[0], outpt); - if (unlikely (status)) - return status; - } else { - status = stroker->add_external_edge (stroker->closure, - outpt, &points[0]); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &points[0], inpt); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; - } else { - points[0] = in->point; - points[1] = *inpt; - points[2].x = _cairo_fixed_from_double (mx); - points[2].y = _cairo_fixed_from_double (my); - points[3] = *outpt; - - return stroker->add_convex_quad (stroker->closure, points); - } - } - } - } - - /* fall through ... */ - - case CAIRO_LINE_JOIN_BEVEL: - if (stroker->add_external_edge != NULL) { - if (clockwise) { - return stroker->add_external_edge (stroker->closure, - inpt, outpt); - } else { - return stroker->add_external_edge (stroker->closure, - outpt, inpt); - } - } else { - points[0] = in->point; - points[1] = *inpt; - points[2] = *outpt; - - return stroker->add_triangle (stroker->closure, points); - } - } -} - -static cairo_status_t -_cairo_stroker_add_cap (cairo_stroker_t *stroker, - const cairo_stroke_face_t *f) -{ - switch (stroker->style.line_cap) { - case CAIRO_LINE_CAP_ROUND: { - cairo_slope_t slope; - - slope.dx = -f->dev_vector.dx; - slope.dy = -f->dev_vector.dy; - - return _tessellate_fan (stroker, - &f->dev_vector, - &slope, - &f->point, &f->cw, &f->ccw, - FALSE); - - } - - case CAIRO_LINE_CAP_SQUARE: { - double dx, dy; - cairo_slope_t fvector; - cairo_point_t quad[4]; - - dx = f->usr_vector.x; - dy = f->usr_vector.y; - dx *= stroker->half_line_width; - dy *= stroker->half_line_width; - cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); - fvector.dx = _cairo_fixed_from_double (dx); - fvector.dy = _cairo_fixed_from_double (dy); - - quad[0] = f->ccw; - quad[1].x = f->ccw.x + fvector.dx; - quad[1].y = f->ccw.y + fvector.dy; - quad[2].x = f->cw.x + fvector.dx; - quad[2].y = f->cw.y + fvector.dy; - quad[3] = f->cw; - - if (stroker->add_external_edge != NULL) { - cairo_status_t status; - - status = stroker->add_external_edge (stroker->closure, - &quad[0], &quad[1]); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &quad[1], &quad[2]); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &quad[2], &quad[3]); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; - } else { - return stroker->add_convex_quad (stroker->closure, quad); - } - } - - case CAIRO_LINE_CAP_BUTT: - default: - if (stroker->add_external_edge != NULL) { - return stroker->add_external_edge (stroker->closure, - &f->ccw, &f->cw); - } else { - return CAIRO_STATUS_SUCCESS; - } - } -} - -static cairo_status_t -_cairo_stroker_add_leading_cap (cairo_stroker_t *stroker, - const cairo_stroke_face_t *face) -{ - cairo_stroke_face_t reversed; - cairo_point_t t; - - reversed = *face; - - /* The initial cap needs an outward facing vector. Reverse everything */ - reversed.usr_vector.x = -reversed.usr_vector.x; - reversed.usr_vector.y = -reversed.usr_vector.y; - reversed.dev_vector.dx = -reversed.dev_vector.dx; - reversed.dev_vector.dy = -reversed.dev_vector.dy; - t = reversed.cw; - reversed.cw = reversed.ccw; - reversed.ccw = t; - - return _cairo_stroker_add_cap (stroker, &reversed); -} - -static cairo_status_t -_cairo_stroker_add_trailing_cap (cairo_stroker_t *stroker, - const cairo_stroke_face_t *face) -{ - return _cairo_stroker_add_cap (stroker, face); -} - -static inline cairo_bool_t -_compute_normalized_device_slope (double *dx, double *dy, - const cairo_matrix_t *ctm_inverse, - double *mag_out) -{ - double dx0 = *dx, dy0 = *dy; - double mag; - - cairo_matrix_transform_distance (ctm_inverse, &dx0, &dy0); - - if (dx0 == 0.0 && dy0 == 0.0) { - if (mag_out) - *mag_out = 0.0; - return FALSE; - } - - if (dx0 == 0.0) { - *dx = 0.0; - if (dy0 > 0.0) { - mag = dy0; - *dy = 1.0; - } else { - mag = -dy0; - *dy = -1.0; - } - } else if (dy0 == 0.0) { - *dy = 0.0; - if (dx0 > 0.0) { - mag = dx0; - *dx = 1.0; - } else { - mag = -dx0; - *dx = -1.0; - } - } else { - mag = hypot (dx0, dy0); - *dx = dx0 / mag; - *dy = dy0 / mag; - } - - if (mag_out) - *mag_out = mag; - - return TRUE; -} - -static void -_compute_face (const cairo_point_t *point, - const cairo_slope_t *dev_slope, - double slope_dx, - double slope_dy, - cairo_stroker_t *stroker, - cairo_stroke_face_t *face) -{ - double face_dx, face_dy; - cairo_point_t offset_ccw, offset_cw; - - /* - * rotate to get a line_width/2 vector along the face, note that - * the vector must be rotated the right direction in device space, - * but by 90° in user space. So, the rotation depends on - * whether the ctm reflects or not, and that can be determined - * by looking at the determinant of the matrix. - */ - if (stroker->ctm_det_positive) - { - face_dx = - slope_dy * stroker->half_line_width; - face_dy = slope_dx * stroker->half_line_width; - } - else - { - face_dx = slope_dy * stroker->half_line_width; - face_dy = - slope_dx * stroker->half_line_width; - } - - /* back to device space */ - cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); - - offset_ccw.x = _cairo_fixed_from_double (face_dx); - offset_ccw.y = _cairo_fixed_from_double (face_dy); - offset_cw.x = -offset_ccw.x; - offset_cw.y = -offset_ccw.y; - - face->ccw = *point; - _translate_point (&face->ccw, &offset_ccw); - - face->point = *point; - - face->cw = *point; - _translate_point (&face->cw, &offset_cw); - - face->usr_vector.x = slope_dx; - face->usr_vector.y = slope_dy; - - face->dev_vector = *dev_slope; -} - -static cairo_status_t -_cairo_stroker_add_caps (cairo_stroker_t *stroker) -{ - cairo_status_t status; - - /* check for a degenerative sub_path */ - if (stroker->has_initial_sub_path - && ! stroker->has_first_face - && ! stroker->has_current_face - && stroker->style.line_cap == CAIRO_LINE_CAP_ROUND) - { - /* pick an arbitrary slope to use */ - double dx = 1.0, dy = 0.0; - cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; - cairo_stroke_face_t face; - - _compute_normalized_device_slope (&dx, &dy, - stroker->ctm_inverse, NULL); - - /* arbitrarily choose first_point - * first_point and current_point should be the same */ - _compute_face (&stroker->first_point, &slope, dx, dy, stroker, &face); - - status = _cairo_stroker_add_leading_cap (stroker, &face); - if (unlikely (status)) - return status; - - status = _cairo_stroker_add_trailing_cap (stroker, &face); - if (unlikely (status)) - return status; - } - - if (stroker->has_first_face) { - status = _cairo_stroker_add_leading_cap (stroker, - &stroker->first_face); - if (unlikely (status)) - return status; - } - - if (stroker->has_current_face) { - status = _cairo_stroker_add_trailing_cap (stroker, - &stroker->current_face); - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_stroker_add_sub_edge (cairo_stroker_t *stroker, - const cairo_point_t *p1, - const cairo_point_t *p2, - cairo_slope_t *dev_slope, - double slope_dx, double slope_dy, - cairo_stroke_face_t *start, - cairo_stroke_face_t *end) -{ - _compute_face (p1, dev_slope, slope_dx, slope_dy, stroker, start); - *end = *start; - - if (p1->x == p2->x && p1->y == p2->y) - return CAIRO_STATUS_SUCCESS; - - end->point = *p2; - end->ccw.x += p2->x - p1->x; - end->ccw.y += p2->y - p1->y; - end->cw.x += p2->x - p1->x; - end->cw.y += p2->y - p1->y; - - if (stroker->add_external_edge != NULL) { - cairo_status_t status; - - status = stroker->add_external_edge (stroker->closure, - &end->cw, &start->cw); - if (unlikely (status)) - return status; - - status = stroker->add_external_edge (stroker->closure, - &start->ccw, &end->ccw); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; - } else { - cairo_point_t quad[4]; - - quad[0] = start->cw; - quad[1] = end->cw; - quad[2] = end->ccw; - quad[3] = start->ccw; - - return stroker->add_convex_quad (stroker->closure, quad); - } -} - -static cairo_status_t -_cairo_stroker_move_to (void *closure, - const cairo_point_t *point) -{ - cairo_stroker_t *stroker = closure; - cairo_status_t status; - - /* reset the dash pattern for new sub paths */ - _cairo_stroker_dash_start (&stroker->dash); - - /* Cap the start and end of the previous sub path as needed */ - status = _cairo_stroker_add_caps (stroker); - if (unlikely (status)) - return status; - - stroker->first_point = *point; - stroker->current_point = *point; - - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - stroker->has_initial_sub_path = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_stroker_line_to (void *closure, - const cairo_point_t *point) -{ - cairo_stroker_t *stroker = closure; - cairo_stroke_face_t start, end; - cairo_point_t *p1 = &stroker->current_point; - cairo_slope_t dev_slope; - double slope_dx, slope_dy; - cairo_status_t status; - - stroker->has_initial_sub_path = TRUE; - - if (p1->x == point->x && p1->y == point->y) - return CAIRO_STATUS_SUCCESS; - - _cairo_slope_init (&dev_slope, p1, point); - slope_dx = _cairo_fixed_to_double (point->x - p1->x); - slope_dy = _cairo_fixed_to_double (point->y - p1->y); - _compute_normalized_device_slope (&slope_dx, &slope_dy, - stroker->ctm_inverse, NULL); - - status = _cairo_stroker_add_sub_edge (stroker, - p1, point, - &dev_slope, - slope_dx, slope_dy, - &start, &end); - if (unlikely (status)) - return status; - - if (stroker->has_current_face) { - /* Join with final face from previous segment */ - status = _cairo_stroker_join (stroker, - &stroker->current_face, - &start); - if (unlikely (status)) - return status; - } else if (! stroker->has_first_face) { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = start; - stroker->has_first_face = TRUE; - } - stroker->current_face = end; - stroker->has_current_face = TRUE; - - stroker->current_point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_stroker_spline_to (void *closure, - const cairo_point_t *point, - const cairo_slope_t *tangent) -{ - cairo_stroker_t *stroker = closure; - cairo_stroke_face_t new_face; - double slope_dx, slope_dy; - cairo_point_t points[3]; - cairo_point_t intersect_point; - - stroker->has_initial_sub_path = TRUE; - - if (stroker->current_point.x == point->x && - stroker->current_point.y == point->y) - return CAIRO_STATUS_SUCCESS; - - slope_dx = _cairo_fixed_to_double (tangent->dx); - slope_dy = _cairo_fixed_to_double (tangent->dy); - - if (! _compute_normalized_device_slope (&slope_dx, &slope_dy, - stroker->ctm_inverse, NULL)) - return CAIRO_STATUS_SUCCESS; - - _compute_face (point, tangent, - slope_dx, slope_dy, - stroker, &new_face); - - assert (stroker->has_current_face); - - if ((new_face.dev_slope.x * stroker->current_face.dev_slope.x + - new_face.dev_slope.y * stroker->current_face.dev_slope.y) < stroker->spline_cusp_tolerance) { - - const cairo_point_t *inpt, *outpt; - int clockwise = _cairo_stroker_join_is_clockwise (&new_face, - &stroker->current_face); - - if (clockwise) { - inpt = &stroker->current_face.cw; - outpt = &new_face.cw; - } else { - inpt = &stroker->current_face.ccw; - outpt = &new_face.ccw; - } - - _tessellate_fan (stroker, - &stroker->current_face.dev_vector, - &new_face.dev_vector, - &stroker->current_face.point, - inpt, outpt, - clockwise); - } - - if (_slow_segment_intersection (&stroker->current_face.cw, - &stroker->current_face.ccw, - &new_face.cw, - &new_face.ccw, - &intersect_point)) { - points[0] = stroker->current_face.ccw; - points[1] = new_face.ccw; - points[2] = intersect_point; - stroker->add_triangle (stroker->closure, points); - - points[0] = stroker->current_face.cw; - points[1] = new_face.cw; - stroker->add_triangle (stroker->closure, points); - } else { - points[0] = stroker->current_face.ccw; - points[1] = stroker->current_face.cw; - points[2] = new_face.cw; - stroker->add_triangle (stroker->closure, points); - - points[0] = stroker->current_face.ccw; - points[1] = new_face.cw; - points[2] = new_face.ccw; - stroker->add_triangle (stroker->closure, points); - } - - stroker->current_face = new_face; - stroker->has_current_face = TRUE; - stroker->current_point = *point; - - return CAIRO_STATUS_SUCCESS; -} - -/* - * Dashed lines. Cap each dash end, join around turns when on - */ -static cairo_status_t -_cairo_stroker_line_to_dashed (void *closure, - const cairo_point_t *p2) -{ - cairo_stroker_t *stroker = closure; - double mag, remain, step_length = 0; - double slope_dx, slope_dy; - double dx2, dy2; - cairo_stroke_face_t sub_start, sub_end; - cairo_point_t *p1 = &stroker->current_point; - cairo_slope_t dev_slope; - cairo_line_t segment; - cairo_bool_t fully_in_bounds; - cairo_status_t status; - - stroker->has_initial_sub_path = stroker->dash.dash_starts_on; - - if (p1->x == p2->x && p1->y == p2->y) - return CAIRO_STATUS_SUCCESS; - - fully_in_bounds = TRUE; - if (stroker->has_bounds && - (! _cairo_box_contains_point (&stroker->bounds, p1) || - ! _cairo_box_contains_point (&stroker->bounds, p2))) - { - fully_in_bounds = FALSE; - } - - _cairo_slope_init (&dev_slope, p1, p2); - - slope_dx = _cairo_fixed_to_double (p2->x - p1->x); - slope_dy = _cairo_fixed_to_double (p2->y - p1->y); - - if (! _compute_normalized_device_slope (&slope_dx, &slope_dy, - stroker->ctm_inverse, &mag)) - { - return CAIRO_STATUS_SUCCESS; - } - - remain = mag; - segment.p1 = *p1; - while (remain) { - step_length = MIN (stroker->dash.dash_remain, remain); - remain -= step_length; - dx2 = slope_dx * (mag - remain); - dy2 = slope_dy * (mag - remain); - cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); - segment.p2.x = _cairo_fixed_from_double (dx2) + p1->x; - segment.p2.y = _cairo_fixed_from_double (dy2) + p1->y; - - if (stroker->dash.dash_on && - (fully_in_bounds || - (! stroker->has_first_face && stroker->dash.dash_starts_on) || - _cairo_box_intersects_line_segment (&stroker->bounds, &segment))) - { - status = _cairo_stroker_add_sub_edge (stroker, - &segment.p1, &segment.p2, - &dev_slope, - slope_dx, slope_dy, - &sub_start, &sub_end); - if (unlikely (status)) - return status; - - if (stroker->has_current_face) - { - /* Join with final face from previous segment */ - status = _cairo_stroker_join (stroker, - &stroker->current_face, - &sub_start); - if (unlikely (status)) - return status; - - stroker->has_current_face = FALSE; - } - else if (! stroker->has_first_face && - stroker->dash.dash_starts_on) - { - /* Save sub path's first face in case needed for closing join */ - stroker->first_face = sub_start; - stroker->has_first_face = TRUE; - } - else - { - /* Cap dash start if not connecting to a previous segment */ - status = _cairo_stroker_add_leading_cap (stroker, &sub_start); - if (unlikely (status)) - return status; - } - - if (remain) { - /* Cap dash end if not at end of segment */ - status = _cairo_stroker_add_trailing_cap (stroker, &sub_end); - if (unlikely (status)) - return status; - } else { - stroker->current_face = sub_end; - stroker->has_current_face = TRUE; - } - } else { - if (stroker->has_current_face) { - /* Cap final face from previous segment */ - status = _cairo_stroker_add_trailing_cap (stroker, - &stroker->current_face); - if (unlikely (status)) - return status; - - stroker->has_current_face = FALSE; - } - } - - _cairo_stroker_dash_step (&stroker->dash, step_length); - segment.p1 = segment.p2; - } - - if (stroker->dash.dash_on && ! stroker->has_current_face) { - /* This segment ends on a transition to dash_on, compute a new face - * and add cap for the beginning of the next dash_on step. - * - * Note: this will create a degenerate cap if this is not the last line - * in the path. Whether this behaviour is desirable or not is debatable. - * On one side these degenerate caps can not be reproduced with regular - * path stroking. - * On the other hand, Acroread 7 also produces the degenerate caps. - */ - _compute_face (p2, &dev_slope, - slope_dx, slope_dy, - stroker, - &stroker->current_face); - - status = _cairo_stroker_add_leading_cap (stroker, - &stroker->current_face); - if (unlikely (status)) - return status; - - stroker->has_current_face = TRUE; - } - - stroker->current_point = *p2; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_stroker_curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - cairo_stroker_t *stroker = closure; - cairo_spline_t spline; - cairo_line_join_t line_join_save; - cairo_stroke_face_t face; - double slope_dx, slope_dy; - cairo_spline_add_point_func_t line_to; - cairo_spline_add_point_func_t spline_to; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - line_to = stroker->dash.dashed ? - (cairo_spline_add_point_func_t) _cairo_stroker_line_to_dashed : - (cairo_spline_add_point_func_t) _cairo_stroker_line_to; - - /* spline_to is only capable of rendering non-degenerate splines. */ - spline_to = stroker->dash.dashed ? - (cairo_spline_add_point_func_t) _cairo_stroker_line_to_dashed : - (cairo_spline_add_point_func_t) _cairo_stroker_spline_to; - - if (! _cairo_spline_init (&spline, - spline_to, - stroker, - &stroker->current_point, b, c, d)) - { - cairo_slope_t fallback_slope; - _cairo_slope_init (&fallback_slope, &stroker->current_point, d); - return line_to (closure, d, &fallback_slope); - } - - /* If the line width is so small that the pen is reduced to a - single point, then we have nothing to do. */ - if (stroker->pen.num_vertices <= 1) - return CAIRO_STATUS_SUCCESS; - - /* Compute the initial face */ - if (! stroker->dash.dashed || stroker->dash.dash_on) { - slope_dx = _cairo_fixed_to_double (spline.initial_slope.dx); - slope_dy = _cairo_fixed_to_double (spline.initial_slope.dy); - if (_compute_normalized_device_slope (&slope_dx, &slope_dy, - stroker->ctm_inverse, NULL)) - { - _compute_face (&stroker->current_point, - &spline.initial_slope, - slope_dx, slope_dy, - stroker, &face); - } - if (stroker->has_current_face) { - status = _cairo_stroker_join (stroker, - &stroker->current_face, &face); - if (unlikely (status)) - return status; - } else if (! stroker->has_first_face) { - stroker->first_face = face; - stroker->has_first_face = TRUE; - } - - stroker->current_face = face; - stroker->has_current_face = TRUE; - } - - /* Temporarily modify the stroker to use round joins to guarantee - * smooth stroked curves. */ - line_join_save = stroker->style.line_join; - stroker->style.line_join = CAIRO_LINE_JOIN_ROUND; - - status = _cairo_spline_decompose (&spline, stroker->tolerance); - if (unlikely (status)) - return status; - - /* And join the final face */ - if (! stroker->dash.dashed || stroker->dash.dash_on) { - slope_dx = _cairo_fixed_to_double (spline.final_slope.dx); - slope_dy = _cairo_fixed_to_double (spline.final_slope.dy); - if (_compute_normalized_device_slope (&slope_dx, &slope_dy, - stroker->ctm_inverse, NULL)) - { - _compute_face (&stroker->current_point, - &spline.final_slope, - slope_dx, slope_dy, - stroker, &face); - } - - status = _cairo_stroker_join (stroker, &stroker->current_face, &face); - if (unlikely (status)) - return status; - - stroker->current_face = face; - } - - stroker->style.line_join = line_join_save; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_stroker_close_path (void *closure) -{ - cairo_stroker_t *stroker = closure; - cairo_status_t status; - - if (stroker->dash.dashed) - status = _cairo_stroker_line_to_dashed (stroker, &stroker->first_point); - else - status = _cairo_stroker_line_to (stroker, &stroker->first_point); - if (unlikely (status)) - return status; - - if (stroker->has_first_face && stroker->has_current_face) { - /* Join first and final faces of sub path */ - status = _cairo_stroker_join (stroker, - &stroker->current_face, - &stroker->first_face); - if (unlikely (status)) - return status; - } else { - /* Cap the start and end of the sub path as needed */ - status = _cairo_stroker_add_caps (stroker); - if (unlikely (status)) - return status; - } - - stroker->has_initial_sub_path = FALSE; - stroker->has_first_face = FALSE; - stroker->has_current_face = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_path_fixed_stroke_to_shaper (cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_status_t (*add_triangle) (void *closure, - const cairo_point_t triangle[3]), - cairo_status_t (*add_triangle_fan) (void *closure, - const cairo_point_t *midpt, - const cairo_point_t *points, - int npoints), - cairo_status_t (*add_convex_quad) (void *closure, - const cairo_point_t quad[4]), - void *closure) -{ - cairo_stroker_t stroker; - cairo_status_t status; - - status = _cairo_stroker_init (&stroker, path, stroke_style, - ctm, ctm_inverse, tolerance, - NULL, 0); - if (unlikely (status)) - return status; - - stroker.add_triangle = add_triangle; - stroker.add_triangle_fan = add_triangle_fan; - stroker.add_convex_quad = add_convex_quad; - stroker.closure = closure; - - status = _cairo_path_fixed_interpret (path, - _cairo_stroker_move_to, - stroker.dash.dashed ? - _cairo_stroker_line_to_dashed : - _cairo_stroker_line_to, - _cairo_stroker_curve_to, - _cairo_stroker_close_path, - &stroker); - - if (unlikely (status)) - goto BAIL; - - /* Cap the start and end of the final sub path as needed */ - status = _cairo_stroker_add_caps (&stroker); - -BAIL: - _cairo_stroker_fini (&stroker); - - return status; -} - -cairo_status_t -_cairo_path_fixed_stroke_dashed_to_polygon (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_polygon_t *polygon) -{ - cairo_stroker_t stroker; - cairo_status_t status; - - status = _cairo_stroker_init (&stroker, path, stroke_style, - ctm, ctm_inverse, tolerance, - polygon->limits, polygon->num_limits); - if (unlikely (status)) - return status; - - stroker.add_external_edge = _cairo_polygon_add_external_edge, - stroker.closure = polygon; - - status = _cairo_path_fixed_interpret (path, - _cairo_stroker_move_to, - stroker.dash.dashed ? - _cairo_stroker_line_to_dashed : - _cairo_stroker_line_to, - _cairo_stroker_curve_to, - _cairo_stroker_close_path, - &stroker); - - if (unlikely (status)) - goto BAIL; - - /* Cap the start and end of the final sub path as needed */ - status = _cairo_stroker_add_caps (&stroker); - -BAIL: - _cairo_stroker_fini (&stroker); - - return status; -} - -cairo_int_status_t -_cairo_path_fixed_stroke_polygon_to_traps (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_traps_t *traps) -{ - cairo_int_status_t status; - cairo_polygon_t polygon; - - _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); - status = _cairo_path_fixed_stroke_to_polygon (path, - stroke_style, - ctm, - ctm_inverse, - tolerance, - &polygon); - if (unlikely (status)) - goto BAIL; - - status = _cairo_polygon_status (&polygon); - if (unlikely (status)) - goto BAIL; - - status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, - CAIRO_FILL_RULE_WINDING); - -BAIL: - _cairo_polygon_fini (&polygon); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path.c deleted file mode 100644 index 43cd175a3c5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-path.c +++ /dev/null @@ -1,479 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2006 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-private.h" -#include "cairo-backend-private.h" -#include "cairo-error-private.h" -#include "cairo-path-private.h" -#include "cairo-path-fixed-private.h" - -/** - * SECTION:cairo-paths - * @Title: Paths - * @Short_Description: Creating paths and manipulating path data - * - * Paths are the most basic drawing tools and are primarily used to implicitly - * generate simple masks. - **/ - -static const cairo_path_t _cairo_path_nil = { CAIRO_STATUS_NO_MEMORY, NULL, 0 }; - -/* Closure for path interpretation. */ -typedef struct cairo_path_count { - int count; -} cpc_t; - -static cairo_status_t -_cpc_move_to (void *closure, - const cairo_point_t *point) -{ - cpc_t *cpc = closure; - - cpc->count += 2; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cpc_line_to (void *closure, - const cairo_point_t *point) -{ - cpc_t *cpc = closure; - - cpc->count += 2; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cpc_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - cpc_t *cpc = closure; - - cpc->count += 4; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cpc_close_path (void *closure) -{ - cpc_t *cpc = closure; - - cpc->count += 1; - - return CAIRO_STATUS_SUCCESS; -} - -static int -_cairo_path_count (cairo_path_t *path, - cairo_path_fixed_t *path_fixed, - double tolerance, - cairo_bool_t flatten) -{ - cairo_status_t status; - cpc_t cpc; - - cpc.count = 0; - - if (flatten) { - status = _cairo_path_fixed_interpret_flat (path_fixed, - _cpc_move_to, - _cpc_line_to, - _cpc_close_path, - &cpc, - tolerance); - } else { - status = _cairo_path_fixed_interpret (path_fixed, - _cpc_move_to, - _cpc_line_to, - _cpc_curve_to, - _cpc_close_path, - &cpc); - } - - if (unlikely (status)) - return -1; - - return cpc.count; -} - -/* Closure for path interpretation. */ -typedef struct cairo_path_populate { - cairo_path_data_t *data; - cairo_t *cr; -} cpp_t; - -static cairo_status_t -_cpp_move_to (void *closure, - const cairo_point_t *point) -{ - cpp_t *cpp = closure; - cairo_path_data_t *data = cpp->data; - double x, y; - - x = _cairo_fixed_to_double (point->x); - y = _cairo_fixed_to_double (point->y); - - _cairo_backend_to_user (cpp->cr, &x, &y); - - data->header.type = CAIRO_PATH_MOVE_TO; - data->header.length = 2; - - /* We index from 1 to leave room for data->header */ - data[1].point.x = x; - data[1].point.y = y; - - cpp->data += data->header.length; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cpp_line_to (void *closure, - const cairo_point_t *point) -{ - cpp_t *cpp = closure; - cairo_path_data_t *data = cpp->data; - double x, y; - - x = _cairo_fixed_to_double (point->x); - y = _cairo_fixed_to_double (point->y); - - _cairo_backend_to_user (cpp->cr, &x, &y); - - data->header.type = CAIRO_PATH_LINE_TO; - data->header.length = 2; - - /* We index from 1 to leave room for data->header */ - data[1].point.x = x; - data[1].point.y = y; - - cpp->data += data->header.length; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cpp_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - cpp_t *cpp = closure; - cairo_path_data_t *data = cpp->data; - double x1, y1; - double x2, y2; - double x3, y3; - - x1 = _cairo_fixed_to_double (p1->x); - y1 = _cairo_fixed_to_double (p1->y); - _cairo_backend_to_user (cpp->cr, &x1, &y1); - - x2 = _cairo_fixed_to_double (p2->x); - y2 = _cairo_fixed_to_double (p2->y); - _cairo_backend_to_user (cpp->cr, &x2, &y2); - - x3 = _cairo_fixed_to_double (p3->x); - y3 = _cairo_fixed_to_double (p3->y); - _cairo_backend_to_user (cpp->cr, &x3, &y3); - - data->header.type = CAIRO_PATH_CURVE_TO; - data->header.length = 4; - - /* We index from 1 to leave room for data->header */ - data[1].point.x = x1; - data[1].point.y = y1; - - data[2].point.x = x2; - data[2].point.y = y2; - - data[3].point.x = x3; - data[3].point.y = y3; - - cpp->data += data->header.length; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cpp_close_path (void *closure) -{ - cpp_t *cpp = closure; - cairo_path_data_t *data = cpp->data; - - data->header.type = CAIRO_PATH_CLOSE_PATH; - data->header.length = 1; - - cpp->data += data->header.length; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_populate (cairo_path_t *path, - cairo_path_fixed_t *path_fixed, - cairo_t *cr, - cairo_bool_t flatten) -{ - cairo_status_t status; - cpp_t cpp; - - cpp.data = path->data; - cpp.cr = cr; - - if (flatten) { - status = _cairo_path_fixed_interpret_flat (path_fixed, - _cpp_move_to, - _cpp_line_to, - _cpp_close_path, - &cpp, - cairo_get_tolerance (cr)); - } else { - status = _cairo_path_fixed_interpret (path_fixed, - _cpp_move_to, - _cpp_line_to, - _cpp_curve_to, - _cpp_close_path, - &cpp); - } - - if (unlikely (status)) - return status; - - /* Sanity check the count */ - assert (cpp.data - path->data == path->num_data); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_path_t * -_cairo_path_create_in_error (cairo_status_t status) -{ - cairo_path_t *path; - - /* special case NO_MEMORY so as to avoid allocations */ - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_path_t*) &_cairo_path_nil; - - path = malloc (sizeof (cairo_path_t)); - if (unlikely (path == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_path_t*) &_cairo_path_nil; - } - - path->num_data = 0; - path->data = NULL; - path->status = status; - - return path; -} - -static cairo_path_t * -_cairo_path_create_internal (cairo_path_fixed_t *path_fixed, - cairo_t *cr, - cairo_bool_t flatten) -{ - cairo_path_t *path; - - path = malloc (sizeof (cairo_path_t)); - if (unlikely (path == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_path_t*) &_cairo_path_nil; - } - - path->num_data = _cairo_path_count (path, path_fixed, - cairo_get_tolerance (cr), - flatten); - if (path->num_data < 0) { - free (path); - return (cairo_path_t*) &_cairo_path_nil; - } - - if (path->num_data) { - path->data = _cairo_malloc_ab (path->num_data, - sizeof (cairo_path_data_t)); - if (unlikely (path->data == NULL)) { - free (path); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_path_t*) &_cairo_path_nil; - } - - path->status = _cairo_path_populate (path, path_fixed, cr, flatten); - } else { - path->data = NULL; - path->status = CAIRO_STATUS_SUCCESS; - } - - return path; -} - -/** - * cairo_path_destroy: - * @path: a path previously returned by either cairo_copy_path() or - * cairo_copy_path_flat(). - * - * Immediately releases all memory associated with @path. After a call - * to cairo_path_destroy() the @path pointer is no longer valid and - * should not be used further. - * - * Note: cairo_path_destroy() should only be called with a - * pointer to a #cairo_path_t returned by a cairo function. Any path - * that is created manually (ie. outside of cairo) should be destroyed - * manually as well. - * - * Since: 1.0 - **/ -void -cairo_path_destroy (cairo_path_t *path) -{ - if (path == NULL || path == &_cairo_path_nil) - return; - - free (path->data); - - free (path); -} -slim_hidden_def (cairo_path_destroy); - -/** - * _cairo_path_create: - * @path: a fixed-point, device-space path to be converted and copied - * @cr: the current graphics context - * - * Creates a user-space #cairo_path_t copy of the given device-space - * @path. The @cr parameter provides the inverse CTM for the - * conversion. - * - * Return value: the new copy of the path. If there is insufficient - * memory a pointer to a special static nil #cairo_path_t will be - * returned instead with status==%CAIRO_STATUS_NO_MEMORY and - * data==%NULL. - **/ -cairo_path_t * -_cairo_path_create (cairo_path_fixed_t *path, - cairo_t *cr) -{ - return _cairo_path_create_internal (path, cr, FALSE); -} - -/** - * _cairo_path_create_flat: - * @path: a fixed-point, device-space path to be flattened, converted and copied - * @cr: the current graphics context - * - * Creates a flattened, user-space #cairo_path_t copy of the given - * device-space @path. The @cr parameter provide the inverse CTM - * for the conversion, as well as the tolerance value to control the - * accuracy of the flattening. - * - * Return value: the flattened copy of the path. If there is insufficient - * memory a pointer to a special static nil #cairo_path_t will be - * returned instead with status==%CAIRO_STATUS_NO_MEMORY and - * data==%NULL. - **/ -cairo_path_t * -_cairo_path_create_flat (cairo_path_fixed_t *path, - cairo_t *cr) -{ - return _cairo_path_create_internal (path, cr, TRUE); -} - -/** - * _cairo_path_append_to_context: - * @path: the path data to be appended - * @cr: a cairo context - * - * Append @path to the current path within @cr. - * - * Return value: %CAIRO_STATUS_INVALID_PATH_DATA if the data in @path - * is invalid, and %CAIRO_STATUS_SUCCESS otherwise. - **/ -cairo_status_t -_cairo_path_append_to_context (const cairo_path_t *path, - cairo_t *cr) -{ - const cairo_path_data_t *p, *end; - - end = &path->data[path->num_data]; - for (p = &path->data[0]; p < end; p += p->header.length) { - switch (p->header.type) { - case CAIRO_PATH_MOVE_TO: - if (unlikely (p->header.length < 2)) - return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); - - cairo_move_to (cr, p[1].point.x, p[1].point.y); - break; - - case CAIRO_PATH_LINE_TO: - if (unlikely (p->header.length < 2)) - return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); - - cairo_line_to (cr, p[1].point.x, p[1].point.y); - break; - - case CAIRO_PATH_CURVE_TO: - if (unlikely (p->header.length < 4)) - return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); - - cairo_curve_to (cr, - p[1].point.x, p[1].point.y, - p[2].point.x, p[2].point.y, - p[3].point.x, p[3].point.y); - break; - - case CAIRO_PATH_CLOSE_PATH: - if (unlikely (p->header.length < 1)) - return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); - - cairo_close_path (cr); - break; - - default: - return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); - } - - if (unlikely (cr->status)) - return cr->status; - } - - return CAIRO_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-inline.h deleted file mode 100644 index 97e8ea034e4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-inline.h +++ /dev/null @@ -1,65 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PATTERN_INLINE_H -#define CAIRO_PATTERN_INLINE_H - -#include "cairo-pattern-private.h" - -#include "cairo-list-inline.h" - -CAIRO_BEGIN_DECLS - -static inline void -_cairo_pattern_add_observer (cairo_pattern_t *pattern, - cairo_pattern_observer_t *observer, - void (*func) (cairo_pattern_observer_t *, - cairo_pattern_t *, - unsigned int)) -{ - observer->notify = func; - cairo_list_add (&observer->link, &pattern->observers); -} - -static inline cairo_surface_t * -_cairo_pattern_get_source (const cairo_surface_pattern_t *pattern, - cairo_rectangle_int_t *extents) -{ - return _cairo_surface_get_source (pattern->surface, extents); -} - -CAIRO_END_DECLS - -#endif /* CAIRO_PATTERN_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-private.h deleted file mode 100644 index be8ab9fc239..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern-private.h +++ /dev/null @@ -1,369 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PATTERN_PRIVATE_H -#define CAIRO_PATTERN_PRIVATE_H - -#include "cairo-error-private.h" -#include "cairo-types-private.h" -#include "cairo-list-private.h" -#include "cairo-surface-private.h" - -#include /* FILE* */ - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_pattern_observer cairo_pattern_observer_t; - -enum { - CAIRO_PATTERN_NOTIFY_MATRIX = 0x1, - CAIRO_PATTERN_NOTIFY_FILTER = 0x2, - CAIRO_PATTERN_NOTIFY_EXTEND = 0x4, - CAIRO_PATTERN_NOTIFY_OPACITY = 0x9, -}; - -struct _cairo_pattern_observer { - void (*notify) (cairo_pattern_observer_t *, - cairo_pattern_t *pattern, - unsigned int flags); - cairo_list_t link; -}; - -struct _cairo_pattern { - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; - cairo_list_t observers; - - cairo_pattern_type_t type; - - cairo_filter_t filter; - cairo_extend_t extend; - cairo_bool_t has_component_alpha; - - cairo_matrix_t matrix; - double opacity; -}; - -struct _cairo_solid_pattern { - cairo_pattern_t base; - cairo_color_t color; -}; - -typedef struct _cairo_surface_pattern { - cairo_pattern_t base; - - cairo_surface_t *surface; -} cairo_surface_pattern_t; - -typedef struct _cairo_gradient_stop { - double offset; - cairo_color_stop_t color; -} cairo_gradient_stop_t; - -typedef struct _cairo_gradient_pattern { - cairo_pattern_t base; - - unsigned int n_stops; - unsigned int stops_size; - cairo_gradient_stop_t *stops; - cairo_gradient_stop_t stops_embedded[2]; -} cairo_gradient_pattern_t; - -typedef struct _cairo_linear_pattern { - cairo_gradient_pattern_t base; - - cairo_point_double_t pd1; - cairo_point_double_t pd2; -} cairo_linear_pattern_t; - -typedef struct _cairo_radial_pattern { - cairo_gradient_pattern_t base; - - cairo_circle_double_t cd1; - cairo_circle_double_t cd2; -} cairo_radial_pattern_t; - -typedef union { - cairo_gradient_pattern_t base; - - cairo_linear_pattern_t linear; - cairo_radial_pattern_t radial; -} cairo_gradient_pattern_union_t; - -/* - * A mesh patch is a tensor-product patch (bicubic Bezier surface - * patch). It has 16 control points. Each set of 4 points along the - * sides of the 4x4 grid of control points is a Bezier curve that - * defines one side of the patch. A color is assigned to each - * corner. The inner 4 points provide additional control over the - * shape and the color mapping. - * - * Cairo uses the same convention as the PDF Reference for numbering - * the points and side of the patch. - * - * - * Side 1 - * - * p[0][3] p[1][3] p[2][3] p[3][3] - * Side 0 p[0][2] p[1][2] p[2][2] p[3][2] Side 2 - * p[0][1] p[1][1] p[2][1] p[3][1] - * p[0][0] p[1][0] p[2][0] p[3][0] - * - * Side 3 - * - * - * Point Color - * ------------------------- - * points[0][0] colors[0] - * points[0][3] colors[1] - * points[3][3] colors[2] - * points[3][0] colors[3] - */ - -typedef struct _cairo_mesh_patch { - cairo_point_double_t points[4][4]; - cairo_color_t colors[4]; -} cairo_mesh_patch_t; - -typedef struct _cairo_mesh_pattern { - cairo_pattern_t base; - - cairo_array_t patches; - cairo_mesh_patch_t *current_patch; - int current_side; - cairo_bool_t has_control_point[4]; - cairo_bool_t has_color[4]; -} cairo_mesh_pattern_t; - -typedef struct _cairo_raster_source_pattern { - cairo_pattern_t base; - - cairo_content_t content; - cairo_rectangle_int_t extents; - - cairo_raster_source_acquire_func_t acquire; - cairo_raster_source_release_func_t release; - cairo_raster_source_snapshot_func_t snapshot; - cairo_raster_source_copy_func_t copy; - cairo_raster_source_finish_func_t finish; - - /* an explicit pre-allocated member in preference to the general user-data */ - void *user_data; -} cairo_raster_source_pattern_t; - -typedef union { - cairo_pattern_t base; - - cairo_solid_pattern_t solid; - cairo_surface_pattern_t surface; - cairo_gradient_pattern_union_t gradient; - cairo_mesh_pattern_t mesh; - cairo_raster_source_pattern_t raster_source; -} cairo_pattern_union_t; - -/* cairo-pattern.c */ - -cairo_private cairo_pattern_t * -_cairo_pattern_create_in_error (cairo_status_t status); - -cairo_private cairo_status_t -_cairo_pattern_create_copy (cairo_pattern_t **pattern, - const cairo_pattern_t *other); - -cairo_private void -_cairo_pattern_init (cairo_pattern_t *pattern, - cairo_pattern_type_t type); - -cairo_private cairo_status_t -_cairo_pattern_init_copy (cairo_pattern_t *pattern, - const cairo_pattern_t *other); - -cairo_private void -_cairo_pattern_init_static_copy (cairo_pattern_t *pattern, - const cairo_pattern_t *other); - -cairo_private cairo_status_t -_cairo_pattern_init_snapshot (cairo_pattern_t *pattern, - const cairo_pattern_t *other); - -cairo_private void -_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, - const cairo_color_t *color); - -cairo_private void -_cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, - cairo_surface_t *surface); - -cairo_private void -_cairo_pattern_fini (cairo_pattern_t *pattern); - -cairo_private cairo_pattern_t * -_cairo_pattern_create_solid (const cairo_color_t *color); - -cairo_private void -_cairo_pattern_transform (cairo_pattern_t *pattern, - const cairo_matrix_t *ctm_inverse); - -cairo_private void -_cairo_pattern_pretransform (cairo_pattern_t *pattern, - const cairo_matrix_t *ctm); - -cairo_private cairo_bool_t -_cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern); - -cairo_private cairo_bool_t -_cairo_pattern_is_opaque (const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents); - -cairo_private cairo_bool_t -_cairo_pattern_is_clear (const cairo_pattern_t *pattern); - -cairo_private cairo_bool_t -_cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, - const cairo_rectangle_int_t *extents, - cairo_color_t *color); - -cairo_private void -_cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient, - double max_value, - cairo_matrix_t *out_matrix, - cairo_circle_double_t out_circle[2]); - -cairo_private cairo_bool_t -_cairo_radial_pattern_focus_is_inside (const cairo_radial_pattern_t *radial); - -cairo_private void -_cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient, - double x0, double y0, - double x1, double y1, - double tolerance, - double out_range[2]); - -cairo_private void -_cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient, - double t, - cairo_circle_double_t *out_circle); - -cairo_private void -_cairo_pattern_alpha_range (const cairo_pattern_t *pattern, - double *out_min, - double *out_max); - -cairo_private cairo_bool_t -_cairo_mesh_pattern_coord_box (const cairo_mesh_pattern_t *mesh, - double *out_xmin, - double *out_ymin, - double *out_xmax, - double *out_ymax); - -cairo_private void -_cairo_pattern_sampled_area (const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - cairo_rectangle_int_t *sample); - -cairo_private void -_cairo_pattern_get_extents (const cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents); - -cairo_private cairo_int_status_t -_cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents); - -cairo_private unsigned long -_cairo_pattern_hash (const cairo_pattern_t *pattern); - -cairo_private unsigned long -_cairo_linear_pattern_hash (unsigned long hash, - const cairo_linear_pattern_t *linear); - -cairo_private unsigned long -_cairo_radial_pattern_hash (unsigned long hash, - const cairo_radial_pattern_t *radial); - -cairo_private cairo_bool_t -_cairo_linear_pattern_equal (const cairo_linear_pattern_t *a, - const cairo_linear_pattern_t *b); - -cairo_private unsigned long -_cairo_pattern_size (const cairo_pattern_t *pattern); - -cairo_private cairo_bool_t -_cairo_radial_pattern_equal (const cairo_radial_pattern_t *a, - const cairo_radial_pattern_t *b); - -cairo_private cairo_bool_t -_cairo_pattern_equal (const cairo_pattern_t *a, - const cairo_pattern_t *b); - -cairo_private cairo_filter_t -_cairo_pattern_analyze_filter (const cairo_pattern_t *pattern); - -/* cairo-mesh-pattern-rasterizer.c */ - -cairo_private void -_cairo_mesh_pattern_rasterize (const cairo_mesh_pattern_t *mesh, - void *data, - int width, - int height, - int stride, - double x_offset, - double y_offset); - -cairo_private cairo_surface_t * -_cairo_raster_source_pattern_acquire (const cairo_pattern_t *abstract_pattern, - cairo_surface_t *target, - const cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_raster_source_pattern_release (const cairo_pattern_t *abstract_pattern, - cairo_surface_t *surface); - -cairo_private cairo_status_t -_cairo_raster_source_pattern_snapshot (cairo_pattern_t *abstract_pattern); - -cairo_private cairo_status_t -_cairo_raster_source_pattern_init_copy (cairo_pattern_t *pattern, - const cairo_pattern_t *other); - -cairo_private void -_cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern); - -cairo_private void -_cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern); - -CAIRO_END_DECLS - -#endif /* CAIRO_PATTERN_PRIVATE */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern.c deleted file mode 100644 index ac5d7af20a2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pattern.c +++ /dev/null @@ -1,4699 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 David Reveman - * Copyright © 2005 Red Hat, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of David - * Reveman not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. David Reveman makes no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR - * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Authors: David Reveman - * Keith Packard - * Carl Worth - */ - -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" -#include "cairo-freed-pool-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-path-private.h" -#include "cairo-pattern-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-surface-snapshot-inline.h" - -#include - -#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ - -/** - * SECTION:cairo-pattern - * @Title: cairo_pattern_t - * @Short_Description: Sources for drawing - * @See_Also: #cairo_t, #cairo_surface_t - * - * #cairo_pattern_t is the paint with which cairo draws. - * The primary use of patterns is as the source for all cairo drawing - * operations, although they can also be used as masks, that is, as the - * brush too. - * - * A cairo pattern is created by using one of the many constructors, - * of the form - * cairo_pattern_create_type() - * or implicitly through - * cairo_set_source_type() - * functions. - **/ - -static freed_pool_t freed_pattern_pool[5]; - -static const cairo_solid_pattern_t _cairo_pattern_nil = { - { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_NO_MEMORY, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { NULL, NULL }, /* observers */ - - CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_FILTER_DEFAULT, /* filter */ - CAIRO_EXTEND_GRADIENT_DEFAULT, /* extend */ - FALSE, /* has component alpha */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - 1.0 /* opacity */ - } -}; - -static const cairo_solid_pattern_t _cairo_pattern_nil_null_pointer = { - { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_NULL_POINTER, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { NULL, NULL }, /* observers */ - - CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_FILTER_DEFAULT, /* filter */ - CAIRO_EXTEND_GRADIENT_DEFAULT, /* extend */ - FALSE, /* has component alpha */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - 1.0 /* opacity */ - } -}; - -const cairo_solid_pattern_t _cairo_pattern_black = { - { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_SUCCESS, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { NULL, NULL }, /* observers */ - - CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_FILTER_NEAREST, /* filter */ - CAIRO_EXTEND_REPEAT, /* extend */ - FALSE, /* has component alpha */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - 1.0 /* opacity */ - }, - { 0., 0., 0., 1., 0, 0, 0, 0xffff },/* color (double rgba, short rgba) */ -}; - -const cairo_solid_pattern_t _cairo_pattern_clear = { - { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_SUCCESS, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { NULL, NULL }, /* observers */ - - CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_FILTER_NEAREST, /* filter */ - CAIRO_EXTEND_REPEAT, /* extend */ - FALSE, /* has component alpha */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - 1.0 /* opacity */ - }, - { 0., 0., 0., 0., 0, 0, 0, 0 },/* color (double rgba, short rgba) */ -}; - -const cairo_solid_pattern_t _cairo_pattern_white = { - { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_SUCCESS, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { NULL, NULL }, /* observers */ - - CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_FILTER_NEAREST, /* filter */ - CAIRO_EXTEND_REPEAT, /* extend */ - FALSE, /* has component alpha */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - 1.0 /* opacity */ - }, - { 1., 1., 1., 1., 0xffff, 0xffff, 0xffff, 0xffff },/* color (double rgba, short rgba) */ -}; - -static void -_cairo_pattern_notify_observers (cairo_pattern_t *pattern, - unsigned int flags) -{ - cairo_pattern_observer_t *pos; - - cairo_list_foreach_entry (pos, cairo_pattern_observer_t, &pattern->observers, link) - pos->notify (pos, pattern, flags); -} - -/** - * _cairo_pattern_set_error: - * @pattern: a pattern - * @status: a status value indicating an error - * - * Atomically sets pattern->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS. - * - * All assignments of an error status to pattern->status should happen - * through _cairo_pattern_set_error(). Note that due to the nature of - * the atomic operation, it is not safe to call this function on the nil - * objects. - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - **/ -static cairo_status_t -_cairo_pattern_set_error (cairo_pattern_t *pattern, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&pattern->status, status); - - return _cairo_error (status); -} - -void -_cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type) -{ -#if HAVE_VALGRIND - switch (type) { - case CAIRO_PATTERN_TYPE_SOLID: - VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_solid_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_SURFACE: - VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_surface_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_LINEAR: - VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_linear_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_RADIAL: - VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_radial_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_MESH: - VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_mesh_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - break; - } -#endif - - pattern->type = type; - pattern->status = CAIRO_STATUS_SUCCESS; - - /* Set the reference count to zero for on-stack patterns. - * Callers needs to explicitly increment the count for heap allocations. */ - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); - - _cairo_user_data_array_init (&pattern->user_data); - - if (type == CAIRO_PATTERN_TYPE_SURFACE || - type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) - pattern->extend = CAIRO_EXTEND_SURFACE_DEFAULT; - else - pattern->extend = CAIRO_EXTEND_GRADIENT_DEFAULT; - - pattern->filter = CAIRO_FILTER_DEFAULT; - pattern->opacity = 1.0; - - pattern->has_component_alpha = FALSE; - - cairo_matrix_init_identity (&pattern->matrix); - - cairo_list_init (&pattern->observers); -} - -static cairo_status_t -_cairo_gradient_pattern_init_copy (cairo_gradient_pattern_t *pattern, - const cairo_gradient_pattern_t *other) -{ - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (other->base.type == CAIRO_PATTERN_TYPE_LINEAR) - { - cairo_linear_pattern_t *dst = (cairo_linear_pattern_t *) pattern; - cairo_linear_pattern_t *src = (cairo_linear_pattern_t *) other; - - *dst = *src; - } - else - { - cairo_radial_pattern_t *dst = (cairo_radial_pattern_t *) pattern; - cairo_radial_pattern_t *src = (cairo_radial_pattern_t *) other; - - *dst = *src; - } - - if (other->stops == other->stops_embedded) - pattern->stops = pattern->stops_embedded; - else if (other->stops) - { - pattern->stops = _cairo_malloc_ab (other->stops_size, - sizeof (cairo_gradient_stop_t)); - if (unlikely (pattern->stops == NULL)) { - pattern->stops_size = 0; - pattern->n_stops = 0; - return _cairo_pattern_set_error (&pattern->base, CAIRO_STATUS_NO_MEMORY); - } - - memcpy (pattern->stops, other->stops, - other->n_stops * sizeof (cairo_gradient_stop_t)); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_mesh_pattern_init_copy (cairo_mesh_pattern_t *pattern, - const cairo_mesh_pattern_t *other) -{ - *pattern = *other; - - _cairo_array_init (&pattern->patches, sizeof (cairo_mesh_patch_t)); - return _cairo_array_append_multiple (&pattern->patches, - _cairo_array_index_const (&other->patches, 0), - _cairo_array_num_elements (&other->patches)); -} - -cairo_status_t -_cairo_pattern_init_copy (cairo_pattern_t *pattern, - const cairo_pattern_t *other) -{ - cairo_status_t status; - - if (other->status) - return _cairo_pattern_set_error (pattern, other->status); - - switch (other->type) { - case CAIRO_PATTERN_TYPE_SOLID: { - cairo_solid_pattern_t *dst = (cairo_solid_pattern_t *) pattern; - cairo_solid_pattern_t *src = (cairo_solid_pattern_t *) other; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_solid_pattern_t))); - - *dst = *src; - } break; - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_pattern_t *dst = (cairo_surface_pattern_t *) pattern; - cairo_surface_pattern_t *src = (cairo_surface_pattern_t *) other; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_surface_pattern_t))); - - *dst = *src; - cairo_surface_reference (dst->surface); - } break; - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: { - cairo_gradient_pattern_t *dst = (cairo_gradient_pattern_t *) pattern; - cairo_gradient_pattern_t *src = (cairo_gradient_pattern_t *) other; - - if (other->type == CAIRO_PATTERN_TYPE_LINEAR) { - VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_linear_pattern_t))); - } else { - VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_radial_pattern_t))); - } - - status = _cairo_gradient_pattern_init_copy (dst, src); - if (unlikely (status)) - return status; - - } break; - case CAIRO_PATTERN_TYPE_MESH: { - cairo_mesh_pattern_t *dst = (cairo_mesh_pattern_t *) pattern; - cairo_mesh_pattern_t *src = (cairo_mesh_pattern_t *) other; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_mesh_pattern_t))); - - status = _cairo_mesh_pattern_init_copy (dst, src); - if (unlikely (status)) - return status; - - } break; - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: { - status = _cairo_raster_source_pattern_init_copy (pattern, other); - if (unlikely (status)) - return status; - } break; - } - - /* The reference count and user_data array are unique to the copy. */ - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); - _cairo_user_data_array_init (&pattern->user_data); - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_pattern_init_static_copy (cairo_pattern_t *pattern, - const cairo_pattern_t *other) -{ - int size; - - assert (other->status == CAIRO_STATUS_SUCCESS); - - switch (other->type) { - default: - ASSERT_NOT_REACHED; - case CAIRO_PATTERN_TYPE_SOLID: - size = sizeof (cairo_solid_pattern_t); - break; - case CAIRO_PATTERN_TYPE_SURFACE: - size = sizeof (cairo_surface_pattern_t); - break; - case CAIRO_PATTERN_TYPE_LINEAR: - size = sizeof (cairo_linear_pattern_t); - break; - case CAIRO_PATTERN_TYPE_RADIAL: - size = sizeof (cairo_radial_pattern_t); - break; - case CAIRO_PATTERN_TYPE_MESH: - size = sizeof (cairo_mesh_pattern_t); - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - size = sizeof (cairo_raster_source_pattern_t); - break; - } - - memcpy (pattern, other, size); - - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); - _cairo_user_data_array_init (&pattern->user_data); -} - -cairo_status_t -_cairo_pattern_init_snapshot (cairo_pattern_t *pattern, - const cairo_pattern_t *other) -{ - cairo_status_t status; - - /* We don't bother doing any fancy copy-on-write implementation - * for the pattern's data. It's generally quite tiny. */ - status = _cairo_pattern_init_copy (pattern, other); - if (unlikely (status)) - return status; - - /* But we do let the surface snapshot stuff be as fancy as it - * would like to be. */ - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surface_pattern = - (cairo_surface_pattern_t *) pattern; - cairo_surface_t *surface = surface_pattern->surface; - - surface_pattern->surface = _cairo_surface_snapshot (surface); - - cairo_surface_destroy (surface); - - status = surface_pattern->surface->status; - } else if (pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) - status = _cairo_raster_source_pattern_snapshot (pattern); - - return status; -} - -void -_cairo_pattern_fini (cairo_pattern_t *pattern) -{ - _cairo_user_data_array_fini (&pattern->user_data); - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - break; - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_pattern_t *surface_pattern = - (cairo_surface_pattern_t *) pattern; - - cairo_surface_destroy (surface_pattern->surface); - } break; - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: { - cairo_gradient_pattern_t *gradient = - (cairo_gradient_pattern_t *) pattern; - - if (gradient->stops && gradient->stops != gradient->stops_embedded) - free (gradient->stops); - } break; - case CAIRO_PATTERN_TYPE_MESH: { - cairo_mesh_pattern_t *mesh = - (cairo_mesh_pattern_t *) pattern; - - _cairo_array_fini (&mesh->patches); - } break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - _cairo_raster_source_pattern_finish (pattern); - break; - } - -#if HAVE_VALGRIND - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_solid_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_SURFACE: - VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_surface_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_LINEAR: - VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_linear_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_RADIAL: - VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_radial_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_MESH: - VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_mesh_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - break; - } -#endif -} - -cairo_status_t -_cairo_pattern_create_copy (cairo_pattern_t **pattern_out, - const cairo_pattern_t *other) -{ - cairo_pattern_t *pattern; - cairo_status_t status; - - if (other->status) - return other->status; - - switch (other->type) { - case CAIRO_PATTERN_TYPE_SOLID: - pattern = malloc (sizeof (cairo_solid_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_SURFACE: - pattern = malloc (sizeof (cairo_surface_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_LINEAR: - pattern = malloc (sizeof (cairo_linear_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_RADIAL: - pattern = malloc (sizeof (cairo_radial_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_MESH: - pattern = malloc (sizeof (cairo_mesh_pattern_t)); - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - pattern = malloc (sizeof (cairo_raster_source_pattern_t)); - break; - default: - ASSERT_NOT_REACHED; - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - } - if (unlikely (pattern == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_pattern_init_copy (pattern, other); - if (unlikely (status)) { - free (pattern); - return status; - } - - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 1); - *pattern_out = pattern; - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, - const cairo_color_t *color) -{ - _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SOLID); - pattern->color = *color; -} - -void -_cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, - cairo_surface_t *surface) -{ - if (surface->status) { - /* Force to solid to simplify the pattern_fini process. */ - _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SOLID); - _cairo_pattern_set_error (&pattern->base, surface->status); - return; - } - - _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SURFACE); - - pattern->surface = cairo_surface_reference (surface); -} - -static void -_cairo_pattern_init_gradient (cairo_gradient_pattern_t *pattern, - cairo_pattern_type_t type) -{ - _cairo_pattern_init (&pattern->base, type); - - pattern->n_stops = 0; - pattern->stops_size = 0; - pattern->stops = NULL; -} - -static void -_cairo_pattern_init_linear (cairo_linear_pattern_t *pattern, - double x0, double y0, double x1, double y1) -{ - _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_LINEAR); - - pattern->pd1.x = x0; - pattern->pd1.y = y0; - pattern->pd2.x = x1; - pattern->pd2.y = y1; -} - -static void -_cairo_pattern_init_radial (cairo_radial_pattern_t *pattern, - double cx0, double cy0, double radius0, - double cx1, double cy1, double radius1) -{ - _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_RADIAL); - - pattern->cd1.center.x = cx0; - pattern->cd1.center.y = cy0; - pattern->cd1.radius = fabs (radius0); - pattern->cd2.center.x = cx1; - pattern->cd2.center.y = cy1; - pattern->cd2.radius = fabs (radius1); -} - -cairo_pattern_t * -_cairo_pattern_create_solid (const cairo_color_t *color) -{ - cairo_solid_pattern_t *pattern; - - pattern = - _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_SOLID]); - if (unlikely (pattern == NULL)) { - /* None cached, need to create a new pattern. */ - pattern = malloc (sizeof (cairo_solid_pattern_t)); - if (unlikely (pattern == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_pattern_t *) &_cairo_pattern_nil; - } - } - - _cairo_pattern_init_solid (pattern, color); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - - return &pattern->base; -} - -cairo_pattern_t * -_cairo_pattern_create_in_error (cairo_status_t status) -{ - cairo_pattern_t *pattern; - - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_pattern_t *)&_cairo_pattern_nil.base; - - CAIRO_MUTEX_INITIALIZE (); - - pattern = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK); - if (pattern->status == CAIRO_STATUS_SUCCESS) - status = _cairo_pattern_set_error (pattern, status); - - return pattern; -} - -/** - * cairo_pattern_create_rgb: - * @red: red component of the color - * @green: green component of the color - * @blue: blue component of the color - * - * Creates a new #cairo_pattern_t corresponding to an opaque color. The - * color components are floating point numbers in the range 0 to 1. - * If the values passed in are outside that range, they will be - * clamped. - * - * Return value: the newly created #cairo_pattern_t if successful, or - * an error pattern in case of no memory. The caller owns the - * returned object and should call cairo_pattern_destroy() when - * finished with it. - * - * This function will always return a valid pointer, but if an error - * occurred the pattern status will be set to an error. To inspect - * the status of a pattern use cairo_pattern_status(). - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_pattern_create_rgb (double red, double green, double blue) -{ - return cairo_pattern_create_rgba (red, green, blue, 1.0); -} -slim_hidden_def (cairo_pattern_create_rgb); - -/** - * cairo_pattern_create_rgba: - * @red: red component of the color - * @green: green component of the color - * @blue: blue component of the color - * @alpha: alpha component of the color - * - * Creates a new #cairo_pattern_t corresponding to a translucent color. - * The color components are floating point numbers in the range 0 to - * 1. If the values passed in are outside that range, they will be - * clamped. - * - * Return value: the newly created #cairo_pattern_t if successful, or - * an error pattern in case of no memory. The caller owns the - * returned object and should call cairo_pattern_destroy() when - * finished with it. - * - * This function will always return a valid pointer, but if an error - * occurred the pattern status will be set to an error. To inspect - * the status of a pattern use cairo_pattern_status(). - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_pattern_create_rgba (double red, double green, double blue, - double alpha) -{ - cairo_color_t color; - - red = _cairo_restrict_value (red, 0.0, 1.0); - green = _cairo_restrict_value (green, 0.0, 1.0); - blue = _cairo_restrict_value (blue, 0.0, 1.0); - alpha = _cairo_restrict_value (alpha, 0.0, 1.0); - - _cairo_color_init_rgba (&color, red, green, blue, alpha); - - CAIRO_MUTEX_INITIALIZE (); - - return _cairo_pattern_create_solid (&color); -} -slim_hidden_def (cairo_pattern_create_rgba); - -/** - * cairo_pattern_create_for_surface: - * @surface: the surface - * - * Create a new #cairo_pattern_t for the given surface. - * - * Return value: the newly created #cairo_pattern_t if successful, or - * an error pattern in case of no memory. The caller owns the - * returned object and should call cairo_pattern_destroy() when - * finished with it. - * - * This function will always return a valid pointer, but if an error - * occurred the pattern status will be set to an error. To inspect - * the status of a pattern use cairo_pattern_status(). - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_pattern_create_for_surface (cairo_surface_t *surface) -{ - cairo_surface_pattern_t *pattern; - - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NULL_POINTER); - return (cairo_pattern_t*) &_cairo_pattern_nil_null_pointer; - } - - if (surface->status) - return _cairo_pattern_create_in_error (surface->status); - - pattern = - _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_SURFACE]); - if (unlikely (pattern == NULL)) { - pattern = malloc (sizeof (cairo_surface_pattern_t)); - if (unlikely (pattern == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_pattern_t *)&_cairo_pattern_nil.base; - } - } - - CAIRO_MUTEX_INITIALIZE (); - - _cairo_pattern_init_for_surface (pattern, surface); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - - return &pattern->base; -} -slim_hidden_def (cairo_pattern_create_for_surface); - -/** - * cairo_pattern_create_linear: - * @x0: x coordinate of the start point - * @y0: y coordinate of the start point - * @x1: x coordinate of the end point - * @y1: y coordinate of the end point - * - * Create a new linear gradient #cairo_pattern_t along the line defined - * by (x0, y0) and (x1, y1). Before using the gradient pattern, a - * number of color stops should be defined using - * cairo_pattern_add_color_stop_rgb() or - * cairo_pattern_add_color_stop_rgba(). - * - * Note: The coordinates here are in pattern space. For a new pattern, - * pattern space is identical to user space, but the relationship - * between the spaces can be changed with cairo_pattern_set_matrix(). - * - * Return value: the newly created #cairo_pattern_t if successful, or - * an error pattern in case of no memory. The caller owns the - * returned object and should call cairo_pattern_destroy() when - * finished with it. - * - * This function will always return a valid pointer, but if an error - * occurred the pattern status will be set to an error. To inspect - * the status of a pattern use cairo_pattern_status(). - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_pattern_create_linear (double x0, double y0, double x1, double y1) -{ - cairo_linear_pattern_t *pattern; - - pattern = - _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_LINEAR]); - if (unlikely (pattern == NULL)) { - pattern = malloc (sizeof (cairo_linear_pattern_t)); - if (unlikely (pattern == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_pattern_t *) &_cairo_pattern_nil.base; - } - } - - CAIRO_MUTEX_INITIALIZE (); - - _cairo_pattern_init_linear (pattern, x0, y0, x1, y1); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); - - return &pattern->base.base; -} - -/** - * cairo_pattern_create_radial: - * @cx0: x coordinate for the center of the start circle - * @cy0: y coordinate for the center of the start circle - * @radius0: radius of the start circle - * @cx1: x coordinate for the center of the end circle - * @cy1: y coordinate for the center of the end circle - * @radius1: radius of the end circle - * - * Creates a new radial gradient #cairo_pattern_t between the two - * circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1). Before using the - * gradient pattern, a number of color stops should be defined using - * cairo_pattern_add_color_stop_rgb() or - * cairo_pattern_add_color_stop_rgba(). - * - * Note: The coordinates here are in pattern space. For a new pattern, - * pattern space is identical to user space, but the relationship - * between the spaces can be changed with cairo_pattern_set_matrix(). - * - * Return value: the newly created #cairo_pattern_t if successful, or - * an error pattern in case of no memory. The caller owns the - * returned object and should call cairo_pattern_destroy() when - * finished with it. - * - * This function will always return a valid pointer, but if an error - * occurred the pattern status will be set to an error. To inspect - * the status of a pattern use cairo_pattern_status(). - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_pattern_create_radial (double cx0, double cy0, double radius0, - double cx1, double cy1, double radius1) -{ - cairo_radial_pattern_t *pattern; - - pattern = - _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_RADIAL]); - if (unlikely (pattern == NULL)) { - pattern = malloc (sizeof (cairo_radial_pattern_t)); - if (unlikely (pattern == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_pattern_t *) &_cairo_pattern_nil.base; - } - } - - CAIRO_MUTEX_INITIALIZE (); - - _cairo_pattern_init_radial (pattern, cx0, cy0, radius0, cx1, cy1, radius1); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); - - return &pattern->base.base; -} - -/* This order is specified in the diagram in the documentation for - * cairo_pattern_create_mesh() */ -static const int mesh_path_point_i[12] = { 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1 }; -static const int mesh_path_point_j[12] = { 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0 }; -static const int mesh_control_point_i[4] = { 1, 1, 2, 2 }; -static const int mesh_control_point_j[4] = { 1, 2, 2, 1 }; - -/** - * cairo_pattern_create_mesh: - * - * Create a new mesh pattern. - * - * Mesh patterns are tensor-product patch meshes (type 7 shadings in - * PDF). Mesh patterns may also be used to create other types of - * shadings that are special cases of tensor-product patch meshes such - * as Coons patch meshes (type 6 shading in PDF) and Gouraud-shaded - * triangle meshes (type 4 and 5 shadings in PDF). - * - * Mesh patterns consist of one or more tensor-product patches, which - * should be defined before using the mesh pattern. Using a mesh - * pattern with a partially defined patch as source or mask will put - * the context in an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * A tensor-product patch is defined by 4 Bézier curves (side 0, 1, 2, - * 3) and by 4 additional control points (P0, P1, P2, P3) that provide - * further control over the patch and complete the definition of the - * tensor-product patch. The corner C0 is the first point of the - * patch. - * - * Degenerate sides are permitted so straight lines may be used. A - * zero length line on one side may be used to create 3 sided patches. - * - * - * C1 Side 1 C2 - * +---------------+ - * | | - * | P1 P2 | - * | | - * Side 0 | | Side 2 - * | | - * | | - * | P0 P3 | - * | | - * +---------------+ - * C0 Side 3 C3 - * - * - * Each patch is constructed by first calling - * cairo_mesh_pattern_begin_patch(), then cairo_mesh_pattern_move_to() - * to specify the first point in the patch (C0). Then the sides are - * specified with calls to cairo_mesh_pattern_curve_to() and - * cairo_mesh_pattern_line_to(). - * - * The four additional control points (P0, P1, P2, P3) in a patch can - * be specified with cairo_mesh_pattern_set_control_point(). - * - * At each corner of the patch (C0, C1, C2, C3) a color may be - * specified with cairo_mesh_pattern_set_corner_color_rgb() or - * cairo_mesh_pattern_set_corner_color_rgba(). Any corner whose color - * is not explicitly specified defaults to transparent black. - * - * A Coons patch is a special case of the tensor-product patch where - * the control points are implicitly defined by the sides of the - * patch. The default value for any control point not specified is the - * implicit value for a Coons patch, i.e. if no control points are - * specified the patch is a Coons patch. - * - * A triangle is a special case of the tensor-product patch where the - * control points are implicitly defined by the sides of the patch, - * all the sides are lines and one of them has length 0, i.e. if the - * patch is specified using just 3 lines, it is a triangle. If the - * corners connected by the 0-length side have the same color, the - * patch is a Gouraud-shaded triangle. - * - * Patches may be oriented differently to the above diagram. For - * example the first point could be at the top left. The diagram only - * shows the relationship between the sides, corners and control - * points. Regardless of where the first point is located, when - * specifying colors, corner 0 will always be the first point, corner - * 1 the point between side 0 and side 1 etc. - * - * Calling cairo_mesh_pattern_end_patch() completes the current - * patch. If less than 4 sides have been defined, the first missing - * side is defined as a line from the current point to the first point - * of the patch (C0) and the other sides are degenerate lines from C0 - * to C0. The corners between the added sides will all be coincident - * with C0 of the patch and their color will be set to be the same as - * the color of C0. - * - * Additional patches may be added with additional calls to - * cairo_mesh_pattern_begin_patch()/cairo_mesh_pattern_end_patch(). - * - * - * cairo_pattern_t *pattern = cairo_pattern_create_mesh (); - * - * /* Add a Coons patch */ - * cairo_mesh_pattern_begin_patch (pattern); - * cairo_mesh_pattern_move_to (pattern, 0, 0); - * cairo_mesh_pattern_curve_to (pattern, 30, -30, 60, 30, 100, 0); - * cairo_mesh_pattern_curve_to (pattern, 60, 30, 130, 60, 100, 100); - * cairo_mesh_pattern_curve_to (pattern, 60, 70, 30, 130, 0, 100); - * cairo_mesh_pattern_curve_to (pattern, 30, 70, -30, 30, 0, 0); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); - * cairo_mesh_pattern_end_patch (pattern); - * - * /* Add a Gouraud-shaded triangle */ - * cairo_mesh_pattern_begin_patch (pattern) - * cairo_mesh_pattern_move_to (pattern, 100, 100); - * cairo_mesh_pattern_line_to (pattern, 130, 130); - * cairo_mesh_pattern_line_to (pattern, 130, 70); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); - * cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); - * cairo_mesh_pattern_end_patch (pattern) - * - * - * When two patches overlap, the last one that has been added is drawn - * over the first one. - * - * When a patch folds over itself, points are sorted depending on - * their parameter coordinates inside the patch. The v coordinate - * ranges from 0 to 1 when moving from side 3 to side 1; the u - * coordinate ranges from 0 to 1 when going from side 0 to side - * 2. Points with higher v coordinate hide points with lower v - * coordinate. When two points have the same v coordinate, the one - * with higher u coordinate is above. This means that points nearer to - * side 1 are above points nearer to side 3; when this is not - * sufficient to decide which point is above (for example when both - * points belong to side 1 or side 3) points nearer to side 2 are - * above points nearer to side 0. - * - * For a complete definition of tensor-product patches, see the PDF - * specification (ISO32000), which describes the parametrization in - * detail. - * - * Note: The coordinates are always in pattern space. For a new - * pattern, pattern space is identical to user space, but the - * relationship between the spaces can be changed with - * cairo_pattern_set_matrix(). - * - * Return value: the newly created #cairo_pattern_t if successful, or - * an error pattern in case of no memory. The caller owns the returned - * object and should call cairo_pattern_destroy() when finished with - * it. - * - * This function will always return a valid pointer, but if an error - * occurred the pattern status will be set to an error. To inspect the - * status of a pattern use cairo_pattern_status(). - * - * Since: 1.12 - **/ -cairo_pattern_t * -cairo_pattern_create_mesh (void) -{ - cairo_mesh_pattern_t *pattern; - - pattern = - _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_MESH]); - if (unlikely (pattern == NULL)) { - pattern = malloc (sizeof (cairo_mesh_pattern_t)); - if (unlikely (pattern == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_pattern_t *) &_cairo_pattern_nil.base; - } - } - - CAIRO_MUTEX_INITIALIZE (); - - _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_MESH); - _cairo_array_init (&pattern->patches, sizeof (cairo_mesh_patch_t)); - pattern->current_patch = NULL; - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - - return &pattern->base; -} - -/** - * cairo_pattern_reference: - * @pattern: a #cairo_pattern_t - * - * Increases the reference count on @pattern by one. This prevents - * @pattern from being destroyed until a matching call to - * cairo_pattern_destroy() is made. - * - * The number of references to a #cairo_pattern_t can be get using - * cairo_pattern_get_reference_count(). - * - * Return value: the referenced #cairo_pattern_t. - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_pattern_reference (cairo_pattern_t *pattern) -{ - if (pattern == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) - return pattern; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&pattern->ref_count)); - - _cairo_reference_count_inc (&pattern->ref_count); - - return pattern; -} -slim_hidden_def (cairo_pattern_reference); - -/** - * cairo_pattern_get_type: - * @pattern: a #cairo_pattern_t - * - * This function returns the type a pattern. - * See #cairo_pattern_type_t for available types. - * - * Return value: The type of @pattern. - * - * Since: 1.2 - **/ -cairo_pattern_type_t -cairo_pattern_get_type (cairo_pattern_t *pattern) -{ - return pattern->type; -} - -/** - * cairo_pattern_status: - * @pattern: a #cairo_pattern_t - * - * Checks whether an error has previously occurred for this - * pattern. - * - * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_STATUS_NO_MEMORY, - * %CAIRO_STATUS_INVALID_MATRIX, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH, - * or %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_pattern_status (cairo_pattern_t *pattern) -{ - return pattern->status; -} - -/** - * cairo_pattern_destroy: - * @pattern: a #cairo_pattern_t - * - * Decreases the reference count on @pattern by one. If the result is - * zero, then @pattern and all associated resources are freed. See - * cairo_pattern_reference(). - * - * Since: 1.0 - **/ -void -cairo_pattern_destroy (cairo_pattern_t *pattern) -{ - cairo_pattern_type_t type; - - if (pattern == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&pattern->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&pattern->ref_count)) - return; - - type = pattern->type; - _cairo_pattern_fini (pattern); - - /* maintain a small cache of freed patterns */ - if (type < ARRAY_LENGTH (freed_pattern_pool)) - _freed_pool_put (&freed_pattern_pool[type], pattern); - else - free (pattern); -} -slim_hidden_def (cairo_pattern_destroy); - -/** - * cairo_pattern_get_reference_count: - * @pattern: a #cairo_pattern_t - * - * Returns the current reference count of @pattern. - * - * Return value: the current reference count of @pattern. If the - * object is a nil object, 0 will be returned. - * - * Since: 1.4 - **/ -unsigned int -cairo_pattern_get_reference_count (cairo_pattern_t *pattern) -{ - if (pattern == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&pattern->ref_count); -} - -/** - * cairo_pattern_get_user_data: - * @pattern: a #cairo_pattern_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Return user data previously attached to @pattern using the - * specified key. If no user data has been attached with the given - * key this function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - * - * Since: 1.4 - **/ -void * -cairo_pattern_get_user_data (cairo_pattern_t *pattern, - const cairo_user_data_key_t *key) -{ - return _cairo_user_data_array_get_data (&pattern->user_data, - key); -} - -/** - * cairo_pattern_set_user_data: - * @pattern: a #cairo_pattern_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach to the #cairo_pattern_t - * @destroy: a #cairo_destroy_func_t which will be called when the - * #cairo_t is destroyed or when new user data is attached using the - * same key. - * - * Attach user data to @pattern. To remove user data from a surface, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_set_user_data (cairo_pattern_t *pattern, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) - return pattern->status; - - return _cairo_user_data_array_set_data (&pattern->user_data, - key, user_data, destroy); -} - -/** - * cairo_mesh_pattern_begin_patch: - * @pattern: a #cairo_pattern_t - * - * Begin a patch in a mesh pattern. - * - * After calling this function, the patch shape should be defined with - * cairo_mesh_pattern_move_to(), cairo_mesh_pattern_line_to() and - * cairo_mesh_pattern_curve_to(). - * - * After defining the patch, cairo_mesh_pattern_end_patch() must be - * called before using @pattern as a source or mask. - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern already has a - * current patch, it will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_begin_patch (cairo_pattern_t *pattern) -{ - cairo_mesh_pattern_t *mesh; - cairo_status_t status; - cairo_mesh_patch_t *current_patch; - int i; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - if (unlikely (mesh->current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - status = _cairo_array_allocate (&mesh->patches, 1, (void **) ¤t_patch); - if (unlikely (status)) { - _cairo_pattern_set_error (pattern, status); - return; - } - - mesh->current_patch = current_patch; - mesh->current_side = -2; /* no current point */ - - for (i = 0; i < 4; i++) - mesh->has_control_point[i] = FALSE; - - for (i = 0; i < 4; i++) - mesh->has_color[i] = FALSE; -} - - -static void -_calc_control_point (cairo_mesh_patch_t *patch, int control_point) -{ - /* The Coons patch is a special case of the Tensor Product patch - * where the four control points are: - * - * P11 = S(1/3, 1/3) - * P12 = S(1/3, 2/3) - * P21 = S(2/3, 1/3) - * P22 = S(2/3, 2/3) - * - * where S is the gradient surface. - * - * When one or more control points has not been specified - * calculated the Coons patch control points are substituted. If - * no control points are specified the gradient will be a Coons - * patch. - * - * The equations below are defined in the ISO32000 standard. - */ - cairo_point_double_t *p[3][3]; - int cp_i, cp_j, i, j; - - cp_i = mesh_control_point_i[control_point]; - cp_j = mesh_control_point_j[control_point]; - - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) - p[i][j] = &patch->points[cp_i ^ i][cp_j ^ j]; - - p[0][0]->x = (- 4 * p[1][1]->x - + 6 * (p[1][0]->x + p[0][1]->x) - - 2 * (p[1][2]->x + p[2][1]->x) - + 3 * (p[2][0]->x + p[0][2]->x) - - 1 * p[2][2]->x) * (1. / 9); - - p[0][0]->y = (- 4 * p[1][1]->y - + 6 * (p[1][0]->y + p[0][1]->y) - - 2 * (p[1][2]->y + p[2][1]->y) - + 3 * (p[2][0]->y + p[0][2]->y) - - 1 * p[2][2]->y) * (1. / 9); -} - -/** - * cairo_mesh_pattern_end_patch: - * @pattern: a #cairo_pattern_t - * - * Indicates the end of the current patch in a mesh pattern. - * - * If the current patch has less than 4 sides, it is closed with a - * straight line from the current point to the first point of the - * patch as if cairo_mesh_pattern_line_to() was used. - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current - * patch or the current patch has no current point, @pattern will be - * put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_end_patch (cairo_pattern_t *pattern) -{ - cairo_mesh_pattern_t *mesh; - cairo_mesh_patch_t *current_patch; - int i; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - current_patch = mesh->current_patch; - if (unlikely (!current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - if (unlikely (mesh->current_side == -2)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - while (mesh->current_side < 3) { - int corner_num; - - cairo_mesh_pattern_line_to (pattern, - current_patch->points[0][0].x, - current_patch->points[0][0].y); - - corner_num = mesh->current_side + 1; - if (corner_num < 4 && ! mesh->has_color[corner_num]) { - current_patch->colors[corner_num] = current_patch->colors[0]; - mesh->has_color[corner_num] = TRUE; - } - } - - for (i = 0; i < 4; i++) { - if (! mesh->has_control_point[i]) - _calc_control_point (current_patch, i); - } - - for (i = 0; i < 4; i++) { - if (! mesh->has_color[i]) - current_patch->colors[i] = *CAIRO_COLOR_TRANSPARENT; - } - - mesh->current_patch = NULL; -} - -/** - * cairo_mesh_pattern_curve_to: - * @pattern: a #cairo_pattern_t - * @x1: the X coordinate of the first control point - * @y1: the Y coordinate of the first control point - * @x2: the X coordinate of the second control point - * @y2: the Y coordinate of the second control point - * @x3: the X coordinate of the end of the curve - * @y3: the Y coordinate of the end of the curve - * - * Adds a cubic Bézier spline to the current patch from the current - * point to position (@x3, @y3) in pattern-space coordinates, using - * (@x1, @y1) and (@x2, @y2) as the control points. - * - * If the current patch has no current point before the call to - * cairo_mesh_pattern_curve_to(), this function will behave as if - * preceded by a call to cairo_mesh_pattern_move_to(@pattern, @x1, - * @y1). - * - * After this call the current point will be (@x3, @y3). - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current - * patch or the current patch already has 4 sides, @pattern will be - * put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_curve_to (cairo_pattern_t *pattern, - double x1, double y1, - double x2, double y2, - double x3, double y3) -{ - cairo_mesh_pattern_t *mesh; - int current_point, i, j; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - if (unlikely (!mesh->current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - if (unlikely (mesh->current_side == 3)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - if (mesh->current_side == -2) - cairo_mesh_pattern_move_to (pattern, x1, y1); - - assert (mesh->current_side >= -1); - assert (pattern->status == CAIRO_STATUS_SUCCESS); - - mesh->current_side++; - - current_point = 3 * mesh->current_side; - - current_point++; - i = mesh_path_point_i[current_point]; - j = mesh_path_point_j[current_point]; - mesh->current_patch->points[i][j].x = x1; - mesh->current_patch->points[i][j].y = y1; - - current_point++; - i = mesh_path_point_i[current_point]; - j = mesh_path_point_j[current_point]; - mesh->current_patch->points[i][j].x = x2; - mesh->current_patch->points[i][j].y = y2; - - current_point++; - if (current_point < 12) { - i = mesh_path_point_i[current_point]; - j = mesh_path_point_j[current_point]; - mesh->current_patch->points[i][j].x = x3; - mesh->current_patch->points[i][j].y = y3; - } -} -slim_hidden_def (cairo_mesh_pattern_curve_to); - -/** - * cairo_mesh_pattern_line_to: - * @pattern: a #cairo_pattern_t - * @x: the X coordinate of the end of the new line - * @y: the Y coordinate of the end of the new line - * - * Adds a line to the current patch from the current point to position - * (@x, @y) in pattern-space coordinates. - * - * If there is no current point before the call to - * cairo_mesh_pattern_line_to() this function will behave as - * cairo_mesh_pattern_move_to(@pattern, @x, @y). - * - * After this call the current point will be (@x, @y). - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current - * patch or the current patch already has 4 sides, @pattern will be - * put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_line_to (cairo_pattern_t *pattern, - double x, double y) -{ - cairo_mesh_pattern_t *mesh; - cairo_point_double_t last_point; - int last_point_idx, i, j; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - if (unlikely (!mesh->current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - if (unlikely (mesh->current_side == 3)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - if (mesh->current_side == -2) { - cairo_mesh_pattern_move_to (pattern, x, y); - return; - } - - last_point_idx = 3 * (mesh->current_side + 1); - i = mesh_path_point_i[last_point_idx]; - j = mesh_path_point_j[last_point_idx]; - - last_point = mesh->current_patch->points[i][j]; - - cairo_mesh_pattern_curve_to (pattern, - (2 * last_point.x + x) * (1. / 3), - (2 * last_point.y + y) * (1. / 3), - (last_point.x + 2 * x) * (1. / 3), - (last_point.y + 2 * y) * (1. / 3), - x, y); -} -slim_hidden_def (cairo_mesh_pattern_line_to); - -/** - * cairo_mesh_pattern_move_to: - * @pattern: a #cairo_pattern_t - * @x: the X coordinate of the new position - * @y: the Y coordinate of the new position - * - * Define the first point of the current patch in a mesh pattern. - * - * After this call the current point will be (@x, @y). - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current - * patch or the current patch already has at least one side, @pattern - * will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_move_to (cairo_pattern_t *pattern, - double x, double y) -{ - cairo_mesh_pattern_t *mesh; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - if (unlikely (!mesh->current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - if (unlikely (mesh->current_side >= 0)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - mesh->current_side = -1; - mesh->current_patch->points[0][0].x = x; - mesh->current_patch->points[0][0].y = y; -} -slim_hidden_def (cairo_mesh_pattern_move_to); - -/** - * cairo_mesh_pattern_set_control_point: - * @pattern: a #cairo_pattern_t - * @point_num: the control point to set the position for - * @x: the X coordinate of the control point - * @y: the Y coordinate of the control point - * - * Set an internal control point of the current patch. - * - * Valid values for @point_num are from 0 to 3 and identify the - * control points as explained in cairo_pattern_create_mesh(). - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @point_num is not valid, - * @pattern will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_INDEX. If @pattern has no current patch, - * @pattern will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_set_control_point (cairo_pattern_t *pattern, - unsigned int point_num, - double x, - double y) -{ - cairo_mesh_pattern_t *mesh; - int i, j; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - if (unlikely (point_num > 3)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_INDEX); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - if (unlikely (!mesh->current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - i = mesh_control_point_i[point_num]; - j = mesh_control_point_j[point_num]; - - mesh->current_patch->points[i][j].x = x; - mesh->current_patch->points[i][j].y = y; - mesh->has_control_point[point_num] = TRUE; -} - -/* make room for at least one more color stop */ -static cairo_status_t -_cairo_pattern_gradient_grow (cairo_gradient_pattern_t *pattern) -{ - cairo_gradient_stop_t *new_stops; - int old_size = pattern->stops_size; - int embedded_size = ARRAY_LENGTH (pattern->stops_embedded); - int new_size = 2 * MAX (old_size, 4); - - /* we have a local buffer at pattern->stops_embedded. try to fulfill the request - * from there. */ - if (old_size < embedded_size) { - pattern->stops = pattern->stops_embedded; - pattern->stops_size = embedded_size; - return CAIRO_STATUS_SUCCESS; - } - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - assert (pattern->n_stops <= pattern->stops_size); - - if (pattern->stops == pattern->stops_embedded) { - new_stops = _cairo_malloc_ab (new_size, sizeof (cairo_gradient_stop_t)); - if (new_stops) - memcpy (new_stops, pattern->stops, old_size * sizeof (cairo_gradient_stop_t)); - } else { - new_stops = _cairo_realloc_ab (pattern->stops, - new_size, - sizeof (cairo_gradient_stop_t)); - } - - if (unlikely (new_stops == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - pattern->stops = new_stops; - pattern->stops_size = new_size; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_mesh_pattern_set_corner_color (cairo_mesh_pattern_t *mesh, - unsigned int corner_num, - double red, double green, double blue, - double alpha) -{ - cairo_color_t *color; - - assert (mesh->current_patch); - assert (corner_num <= 3); - - color = &mesh->current_patch->colors[corner_num]; - color->red = red; - color->green = green; - color->blue = blue; - color->alpha = alpha; - - color->red_short = _cairo_color_double_to_short (red); - color->green_short = _cairo_color_double_to_short (green); - color->blue_short = _cairo_color_double_to_short (blue); - color->alpha_short = _cairo_color_double_to_short (alpha); - - mesh->has_color[corner_num] = TRUE; -} - -/** - * cairo_mesh_pattern_set_corner_color_rgb: - * @pattern: a #cairo_pattern_t - * @corner_num: the corner to set the color for - * @red: red component of color - * @green: green component of color - * @blue: blue component of color - * - * Sets the color of a corner of the current patch in a mesh pattern. - * - * The color is specified in the same way as in cairo_set_source_rgb(). - * - * Valid values for @corner_num are from 0 to 3 and identify the - * corners as explained in cairo_pattern_create_mesh(). - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @corner_num is not valid, - * @pattern will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_INDEX. If @pattern has no current patch, - * @pattern will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_set_corner_color_rgb (cairo_pattern_t *pattern, - unsigned int corner_num, - double red, double green, double blue) -{ - cairo_mesh_pattern_set_corner_color_rgba (pattern, corner_num, red, green, blue, 1.0); -} - -/** - * cairo_mesh_pattern_set_corner_color_rgba: - * @pattern: a #cairo_pattern_t - * @corner_num: the corner to set the color for - * @red: red component of color - * @green: green component of color - * @blue: blue component of color - * @alpha: alpha component of color - * - * Sets the color of a corner of the current patch in a mesh pattern. - * - * The color is specified in the same way as in cairo_set_source_rgba(). - * - * Valid values for @corner_num are from 0 to 3 and identify the - * corners as explained in cairo_pattern_create_mesh(). - * - * Note: If @pattern is not a mesh pattern then @pattern will be put - * into an error status with a status of - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @corner_num is not valid, - * @pattern will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_INDEX. If @pattern has no current patch, - * @pattern will be put into an error status with a status of - * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. - * - * Since: 1.12 - **/ -void -cairo_mesh_pattern_set_corner_color_rgba (cairo_pattern_t *pattern, - unsigned int corner_num, - double red, double green, double blue, - double alpha) -{ - cairo_mesh_pattern_t *mesh; - - if (unlikely (pattern->status)) - return; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - if (unlikely (corner_num > 3)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_INDEX); - return; - } - - mesh = (cairo_mesh_pattern_t *) pattern; - if (unlikely (!mesh->current_patch)) { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); - return; - } - - red = _cairo_restrict_value (red, 0.0, 1.0); - green = _cairo_restrict_value (green, 0.0, 1.0); - blue = _cairo_restrict_value (blue, 0.0, 1.0); - alpha = _cairo_restrict_value (alpha, 0.0, 1.0); - - _cairo_mesh_pattern_set_corner_color (mesh, corner_num, red, green, blue, alpha); -} -slim_hidden_def (cairo_mesh_pattern_set_corner_color_rgba); - -static void -_cairo_pattern_add_color_stop (cairo_gradient_pattern_t *pattern, - double offset, - double red, - double green, - double blue, - double alpha) -{ - cairo_gradient_stop_t *stops; - unsigned int i; - - if (pattern->n_stops >= pattern->stops_size) { - cairo_status_t status = _cairo_pattern_gradient_grow (pattern); - if (unlikely (status)) { - status = _cairo_pattern_set_error (&pattern->base, status); - return; - } - } - - stops = pattern->stops; - - for (i = 0; i < pattern->n_stops; i++) - { - if (offset < stops[i].offset) - { - memmove (&stops[i + 1], &stops[i], - sizeof (cairo_gradient_stop_t) * (pattern->n_stops - i)); - - break; - } - } - - stops[i].offset = offset; - - stops[i].color.red = red; - stops[i].color.green = green; - stops[i].color.blue = blue; - stops[i].color.alpha = alpha; - - stops[i].color.red_short = _cairo_color_double_to_short (red); - stops[i].color.green_short = _cairo_color_double_to_short (green); - stops[i].color.blue_short = _cairo_color_double_to_short (blue); - stops[i].color.alpha_short = _cairo_color_double_to_short (alpha); - - pattern->n_stops++; -} - -/** - * cairo_pattern_add_color_stop_rgb: - * @pattern: a #cairo_pattern_t - * @offset: an offset in the range [0.0 .. 1.0] - * @red: red component of color - * @green: green component of color - * @blue: blue component of color - * - * Adds an opaque color stop to a gradient pattern. The offset - * specifies the location along the gradient's control vector. For - * example, a linear gradient's control vector is from (x0,y0) to - * (x1,y1) while a radial gradient's control vector is from any point - * on the start circle to the corresponding point on the end circle. - * - * The color is specified in the same way as in cairo_set_source_rgb(). - * - * If two (or more) stops are specified with identical offset values, - * they will be sorted according to the order in which the stops are - * added, (stops added earlier will compare less than stops added - * later). This can be useful for reliably making sharp color - * transitions instead of the typical blend. - * - * - * Note: If the pattern is not a gradient pattern, (eg. a linear or - * radial pattern), then the pattern will be put into an error status - * with a status of %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. - * - * Since: 1.0 - **/ -void -cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, - double offset, - double red, - double green, - double blue) -{ - cairo_pattern_add_color_stop_rgba (pattern, offset, red, green, blue, 1.0); -} - -/** - * cairo_pattern_add_color_stop_rgba: - * @pattern: a #cairo_pattern_t - * @offset: an offset in the range [0.0 .. 1.0] - * @red: red component of color - * @green: green component of color - * @blue: blue component of color - * @alpha: alpha component of color - * - * Adds a translucent color stop to a gradient pattern. The offset - * specifies the location along the gradient's control vector. For - * example, a linear gradient's control vector is from (x0,y0) to - * (x1,y1) while a radial gradient's control vector is from any point - * on the start circle to the corresponding point on the end circle. - * - * The color is specified in the same way as in cairo_set_source_rgba(). - * - * If two (or more) stops are specified with identical offset values, - * they will be sorted according to the order in which the stops are - * added, (stops added earlier will compare less than stops added - * later). This can be useful for reliably making sharp color - * transitions instead of the typical blend. - * - * Note: If the pattern is not a gradient pattern, (eg. a linear or - * radial pattern), then the pattern will be put into an error status - * with a status of %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. - * - * Since: 1.0 - **/ -void -cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, - double offset, - double red, - double green, - double blue, - double alpha) -{ - if (pattern->status) - return; - - if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && - pattern->type != CAIRO_PATTERN_TYPE_RADIAL) - { - _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - return; - } - - offset = _cairo_restrict_value (offset, 0.0, 1.0); - red = _cairo_restrict_value (red, 0.0, 1.0); - green = _cairo_restrict_value (green, 0.0, 1.0); - blue = _cairo_restrict_value (blue, 0.0, 1.0); - alpha = _cairo_restrict_value (alpha, 0.0, 1.0); - - _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern, - offset, red, green, blue, alpha); -} -slim_hidden_def (cairo_pattern_add_color_stop_rgba); - -/** - * cairo_pattern_set_matrix: - * @pattern: a #cairo_pattern_t - * @matrix: a #cairo_matrix_t - * - * Sets the pattern's transformation matrix to @matrix. This matrix is - * a transformation from user space to pattern space. - * - * When a pattern is first created it always has the identity matrix - * for its transformation matrix, which means that pattern space is - * initially identical to user space. - * - * Important: Please note that the direction of this transformation - * matrix is from user space to pattern space. This means that if you - * imagine the flow from a pattern to user space (and on to device - * space), then coordinates in that flow will be transformed by the - * inverse of the pattern matrix. - * - * For example, if you want to make a pattern appear twice as large as - * it does by default the correct code to use is: - * - * - * cairo_matrix_init_scale (&matrix, 0.5, 0.5); - * cairo_pattern_set_matrix (pattern, &matrix); - * - * - * Meanwhile, using values of 2.0 rather than 0.5 in the code above - * would cause the pattern to appear at half of its default size. - * - * Also, please note the discussion of the user-space locking - * semantics of cairo_set_source(). - * - * Since: 1.0 - **/ -void -cairo_pattern_set_matrix (cairo_pattern_t *pattern, - const cairo_matrix_t *matrix) -{ - cairo_matrix_t inverse; - cairo_status_t status; - - if (pattern->status) - return; - - if (memcmp (&pattern->matrix, matrix, sizeof (cairo_matrix_t)) == 0) - return; - - pattern->matrix = *matrix; - _cairo_pattern_notify_observers (pattern, CAIRO_PATTERN_NOTIFY_MATRIX); - - inverse = *matrix; - status = cairo_matrix_invert (&inverse); - if (unlikely (status)) - status = _cairo_pattern_set_error (pattern, status); -} -slim_hidden_def (cairo_pattern_set_matrix); - -/** - * cairo_pattern_get_matrix: - * @pattern: a #cairo_pattern_t - * @matrix: return value for the matrix - * - * Stores the pattern's transformation matrix into @matrix. - * - * Since: 1.0 - **/ -void -cairo_pattern_get_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix) -{ - *matrix = pattern->matrix; -} - -/** - * cairo_pattern_set_filter: - * @pattern: a #cairo_pattern_t - * @filter: a #cairo_filter_t describing the filter to use for resizing - * the pattern - * - * Sets the filter to be used for resizing when using this pattern. - * See #cairo_filter_t for details on each filter. - * - * * Note that you might want to control filtering even when you do not - * have an explicit #cairo_pattern_t object, (for example when using - * cairo_set_source_surface()). In these cases, it is convenient to - * use cairo_get_source() to get access to the pattern that cairo - * creates implicitly. For example: - * - * - * cairo_set_source_surface (cr, image, x, y); - * cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); - * - * - * Since: 1.0 - **/ -void -cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter) -{ - if (pattern->status) - return; - - pattern->filter = filter; - _cairo_pattern_notify_observers (pattern, CAIRO_PATTERN_NOTIFY_FILTER); -} - -/** - * cairo_pattern_get_filter: - * @pattern: a #cairo_pattern_t - * - * Gets the current filter for a pattern. See #cairo_filter_t - * for details on each filter. - * - * Return value: the current filter used for resizing the pattern. - * - * Since: 1.0 - **/ -cairo_filter_t -cairo_pattern_get_filter (cairo_pattern_t *pattern) -{ - return pattern->filter; -} - -/** - * cairo_pattern_set_extend: - * @pattern: a #cairo_pattern_t - * @extend: a #cairo_extend_t describing how the area outside of the - * pattern will be drawn - * - * Sets the mode to be used for drawing outside the area of a pattern. - * See #cairo_extend_t for details on the semantics of each extend - * strategy. - * - * The default extend mode is %CAIRO_EXTEND_NONE for surface patterns - * and %CAIRO_EXTEND_PAD for gradient patterns. - * - * Since: 1.0 - **/ -void -cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend) -{ - if (pattern->status) - return; - - pattern->extend = extend; - _cairo_pattern_notify_observers (pattern, CAIRO_PATTERN_NOTIFY_EXTEND); -} - -/** - * cairo_pattern_get_extend: - * @pattern: a #cairo_pattern_t - * - * Gets the current extend mode for a pattern. See #cairo_extend_t - * for details on the semantics of each extend strategy. - * - * Return value: the current extend strategy used for drawing the - * pattern. - * - * Since: 1.0 - **/ -cairo_extend_t -cairo_pattern_get_extend (cairo_pattern_t *pattern) -{ - return pattern->extend; -} -slim_hidden_def (cairo_pattern_get_extend); - -void -_cairo_pattern_pretransform (cairo_pattern_t *pattern, - const cairo_matrix_t *ctm) -{ - if (pattern->status) - return; - - cairo_matrix_multiply (&pattern->matrix, &pattern->matrix, ctm); -} - -void -_cairo_pattern_transform (cairo_pattern_t *pattern, - const cairo_matrix_t *ctm_inverse) -{ - if (pattern->status) - return; - - cairo_matrix_multiply (&pattern->matrix, ctm_inverse, &pattern->matrix); -} - -static cairo_bool_t -_linear_pattern_is_degenerate (const cairo_linear_pattern_t *linear) -{ - return fabs (linear->pd1.x - linear->pd2.x) < DBL_EPSILON && - fabs (linear->pd1.y - linear->pd2.y) < DBL_EPSILON; -} - -static cairo_bool_t -_radial_pattern_is_degenerate (const cairo_radial_pattern_t *radial) -{ - /* A radial pattern is considered degenerate if it can be - * represented as a solid or clear pattern. This corresponds to - * one of the two cases: - * - * 1) The radii are both very small: - * |dr| < DBL_EPSILON && min (r0, r1) < DBL_EPSILON - * - * 2) The two circles have about the same radius and are very - * close to each other (approximately a cylinder gradient that - * doesn't move with the parameter): - * |dr| < DBL_EPSILON && max (|dx|, |dy|) < 2 * DBL_EPSILON - * - * These checks are consistent with the assumptions used in - * _cairo_radial_pattern_box_to_parameter (). - */ - - return fabs (radial->cd1.radius - radial->cd2.radius) < DBL_EPSILON && - (MIN (radial->cd1.radius, radial->cd2.radius) < DBL_EPSILON || - MAX (fabs (radial->cd1.center.x - radial->cd2.center.x), - fabs (radial->cd1.center.y - radial->cd2.center.y)) < 2 * DBL_EPSILON); -} - -static void -_cairo_linear_pattern_box_to_parameter (const cairo_linear_pattern_t *linear, - double x0, double y0, - double x1, double y1, - double range[2]) -{ - double t0, tdx, tdy; - double p1x, p1y, pdx, pdy, invsqnorm; - - assert (! _linear_pattern_is_degenerate (linear)); - - /* - * Linear gradients are othrogonal to the line passing through - * their extremes. Because of convexity, the parameter range can - * be computed as the convex hull (one the real line) of the - * parameter values of the 4 corners of the box. - * - * The parameter value t for a point (x,y) can be computed as: - * - * t = (p2 - p1) . (x,y) / |p2 - p1|^2 - * - * t0 is the t value for the top left corner - * tdx is the difference between left and right corners - * tdy is the difference between top and bottom corners - */ - - p1x = linear->pd1.x; - p1y = linear->pd1.y; - pdx = linear->pd2.x - p1x; - pdy = linear->pd2.y - p1y; - invsqnorm = 1.0 / (pdx * pdx + pdy * pdy); - pdx *= invsqnorm; - pdy *= invsqnorm; - - t0 = (x0 - p1x) * pdx + (y0 - p1y) * pdy; - tdx = (x1 - x0) * pdx; - tdy = (y1 - y0) * pdy; - - /* - * Because of the linearity of the t value, tdx can simply be - * added the t0 to move along the top edge. After this, range[0] - * and range[1] represent the parameter range for the top edge, so - * extending it to include the whole box simply requires adding - * tdy to the correct extreme. - */ - - range[0] = range[1] = t0; - if (tdx < 0) - range[0] += tdx; - else - range[1] += tdx; - - if (tdy < 0) - range[0] += tdy; - else - range[1] += tdy; -} - -static cairo_bool_t -_extend_range (double range[2], double value, cairo_bool_t valid) -{ - if (!valid) - range[0] = range[1] = value; - else if (value < range[0]) - range[0] = value; - else if (value > range[1]) - range[1] = value; - - return TRUE; -} - -/* - * _cairo_radial_pattern_focus_is_inside: - * - * Returns %TRUE if and only if the focus point exists and is - * contained in one of the two extreme circles. This condition is - * equivalent to one of the two extreme circles being completely - * contained in the other one. - * - * Note: if the focus is on the border of one of the two circles (in - * which case the circles are tangent in the focus point), it is not - * considered as contained in the circle, hence this function returns - * %FALSE. - * - */ -cairo_bool_t -_cairo_radial_pattern_focus_is_inside (const cairo_radial_pattern_t *radial) -{ - double cx, cy, cr, dx, dy, dr; - - cx = radial->cd1.center.x; - cy = radial->cd1.center.y; - cr = radial->cd1.radius; - dx = radial->cd2.center.x - cx; - dy = radial->cd2.center.y - cy; - dr = radial->cd2.radius - cr; - - return dx*dx + dy*dy < dr*dr; -} - -static void -_cairo_radial_pattern_box_to_parameter (const cairo_radial_pattern_t *radial, - double x0, double y0, - double x1, double y1, - double tolerance, - double range[2]) -{ - double cx, cy, cr, dx, dy, dr; - double a, x_focus, y_focus; - double mindr, minx, miny, maxx, maxy; - cairo_bool_t valid; - - assert (! _radial_pattern_is_degenerate (radial)); - assert (x0 < x1); - assert (y0 < y1); - - tolerance = MAX (tolerance, DBL_EPSILON); - - range[0] = range[1] = 0; - valid = FALSE; - - x_focus = y_focus = 0; /* silence gcc */ - - cx = radial->cd1.center.x; - cy = radial->cd1.center.y; - cr = radial->cd1.radius; - dx = radial->cd2.center.x - cx; - dy = radial->cd2.center.y - cy; - dr = radial->cd2.radius - cr; - - /* translate by -(cx, cy) to simplify computations */ - x0 -= cx; - y0 -= cy; - x1 -= cx; - y1 -= cy; - - /* enlarge boundaries slightly to avoid rounding problems in the - * parameter range computation */ - x0 -= DBL_EPSILON; - y0 -= DBL_EPSILON; - x1 += DBL_EPSILON; - y1 += DBL_EPSILON; - - /* enlarge boundaries even more to avoid rounding problems when - * testing if a point belongs to the box */ - minx = x0 - DBL_EPSILON; - miny = y0 - DBL_EPSILON; - maxx = x1 + DBL_EPSILON; - maxy = y1 + DBL_EPSILON; - - /* we dont' allow negative radiuses, so we will be checking that - * t*dr >= mindr to consider t valid */ - mindr = -(cr + DBL_EPSILON); - - /* - * After the previous transformations, the start circle is - * centered in the origin and has radius cr. A 1-unit change in - * the t parameter corresponds to dx,dy,dr changes in the x,y,r of - * the circle (center coordinates, radius). - * - * To compute the minimum range needed to correctly draw the - * pattern, we start with an empty range and extend it to include - * the circles touching the bounding box or within it. - */ - - /* - * Focus, the point where the circle has radius == 0. - * - * r = cr + t * dr = 0 - * t = -cr / dr - * - * If the radius is constant (dr == 0) there is no focus (the - * gradient represents a cylinder instead of a cone). - */ - if (fabs (dr) >= DBL_EPSILON) { - double t_focus; - - t_focus = -cr / dr; - x_focus = t_focus * dx; - y_focus = t_focus * dy; - if (minx <= x_focus && x_focus <= maxx && - miny <= y_focus && y_focus <= maxy) - { - valid = _extend_range (range, t_focus, valid); - } - } - - /* - * Circles externally tangent to box edges. - * - * All circles have center in (dx, dy) * t - * - * If the circle is tangent to the line defined by the edge of the - * box, then at least one of the following holds true: - * - * (dx*t) + (cr + dr*t) == x0 (left edge) - * (dx*t) - (cr + dr*t) == x1 (right edge) - * (dy*t) + (cr + dr*t) == y0 (top edge) - * (dy*t) - (cr + dr*t) == y1 (bottom edge) - * - * The solution is only valid if the tangent point is actually on - * the edge, i.e. if its y coordinate is in [y0,y1] for left/right - * edges and if its x coordinate is in [x0,x1] for top/bottom - * edges. - * - * For the first equation: - * - * (dx + dr) * t = x0 - cr - * t = (x0 - cr) / (dx + dr) - * y = dy * t - * - * in the code this becomes: - * - * t_edge = (num) / (den) - * v = (delta) * t_edge - * - * If the denominator in t is 0, the pattern is tangent to a line - * parallel to the edge under examination. The corner-case where - * the boundary line is the same as the edge is handled by the - * focus point case and/or by the a==0 case. - */ -#define T_EDGE(num,den,delta,lower,upper) \ - if (fabs (den) >= DBL_EPSILON) { \ - double t_edge, v; \ - \ - t_edge = (num) / (den); \ - v = t_edge * (delta); \ - if (t_edge * dr >= mindr && (lower) <= v && v <= (upper)) \ - valid = _extend_range (range, t_edge, valid); \ - } - - /* circles tangent (externally) to left/right/top/bottom edge */ - T_EDGE (x0 - cr, dx + dr, dy, miny, maxy); - T_EDGE (x1 + cr, dx - dr, dy, miny, maxy); - T_EDGE (y0 - cr, dy + dr, dx, minx, maxx); - T_EDGE (y1 + cr, dy - dr, dx, minx, maxx); - -#undef T_EDGE - - /* - * Circles passing through a corner. - * - * A circle passing through the point (x,y) satisfies: - * - * (x-t*dx)^2 + (y-t*dy)^2 == (cr + t*dr)^2 - * - * If we set: - * a = dx^2 + dy^2 - dr^2 - * b = x*dx + y*dy + cr*dr - * c = x^2 + y^2 - cr^2 - * we have: - * a*t^2 - 2*b*t + c == 0 - */ - a = dx * dx + dy * dy - dr * dr; - if (fabs (a) < DBL_EPSILON * DBL_EPSILON) { - double b, maxd2; - - /* Ensure that gradients with both a and dr small are - * considered degenerate. - * The floating point version of the degeneracy test implemented - * in _radial_pattern_is_degenerate() is: - * - * 1) The circles are practically the same size: - * |dr| < DBL_EPSILON - * AND - * 2a) The circles are both very small: - * min (r0, r1) < DBL_EPSILON - * OR - * 2b) The circles are very close to each other: - * max (|dx|, |dy|) < 2 * DBL_EPSILON - * - * Assuming that the gradient is not degenerate, we want to - * show that |a| < DBL_EPSILON^2 implies |dr| >= DBL_EPSILON. - * - * If the gradient is not degenerate yet it has |dr| < - * DBL_EPSILON, (2b) is false, thus: - * - * max (|dx|, |dy|) >= 2*DBL_EPSILON - * which implies: - * 4*DBL_EPSILON^2 <= max (|dx|, |dy|)^2 <= dx^2 + dy^2 - * - * From the definition of a, we get: - * a = dx^2 + dy^2 - dr^2 < DBL_EPSILON^2 - * dx^2 + dy^2 - DBL_EPSILON^2 < dr^2 - * 3*DBL_EPSILON^2 < dr^2 - * - * which is inconsistent with the hypotheses, thus |dr| < - * DBL_EPSILON is false or the gradient is degenerate. - */ - assert (fabs (dr) >= DBL_EPSILON); - - /* - * If a == 0, all the circles are tangent to a line in the - * focus point. If this line is within the box extents, we - * should add the circle with infinite radius, but this would - * make the range unbounded, so we add the smallest circle whose - * distance to the desired (degenerate) circle within the - * bounding box does not exceed tolerance. - * - * The equation of the line is b==0, i.e.: - * x*dx + y*dy + cr*dr == 0 - * - * We compute the intersection of the line with the box and - * keep the intersection with maximum square distance (maxd2) - * from the focus point. - * - * In the code the intersection is represented in another - * coordinate system, whose origin is the focus point and - * which has a u,v axes, which are respectively orthogonal and - * parallel to the edge being intersected. - * - * The intersection is valid only if it belongs to the box, - * otherwise it is ignored. - * - * For example: - * - * y = y0 - * x*dx + y0*dy + cr*dr == 0 - * x = -(y0*dy + cr*dr) / dx - * - * which in (u,v) is: - * u = y0 - y_focus - * v = -(y0*dy + cr*dr) / dx - x_focus - * - * In the code: - * u = (edge) - (u_origin) - * v = -((edge) * (delta) + cr*dr) / (den) - v_focus - */ -#define T_EDGE(edge,delta,den,lower,upper,u_origin,v_origin) \ - if (fabs (den) >= DBL_EPSILON) { \ - double v; \ - \ - v = -((edge) * (delta) + cr * dr) / (den); \ - if ((lower) <= v && v <= (upper)) { \ - double u, d2; \ - \ - u = (edge) - (u_origin); \ - v -= (v_origin); \ - d2 = u*u + v*v; \ - if (maxd2 < d2) \ - maxd2 = d2; \ - } \ - } - - maxd2 = 0; - - /* degenerate circles (lines) passing through each edge */ - T_EDGE (y0, dy, dx, minx, maxx, y_focus, x_focus); - T_EDGE (y1, dy, dx, minx, maxx, y_focus, x_focus); - T_EDGE (x0, dx, dy, miny, maxy, x_focus, y_focus); - T_EDGE (x1, dx, dy, miny, maxy, x_focus, y_focus); - -#undef T_EDGE - - /* - * The limit circle can be transformed rigidly to the y=0 line - * and the circles tangent to it in (0,0) are: - * - * x^2 + (y-r)^2 = r^2 <=> x^2 + y^2 - 2*y*r = 0 - * - * y is the distance from the line, in our case tolerance; - * x is the distance along the line, i.e. sqrt(maxd2), - * so: - * - * r = cr + dr * t = (maxd2 + tolerance^2) / (2*tolerance) - * t = (r - cr) / dr = - * (maxd2 + tolerance^2 - 2*tolerance*cr) / (2*tolerance*dr) - */ - if (maxd2 > 0) { - double t_limit = maxd2 + tolerance*tolerance - 2*tolerance*cr; - t_limit /= 2 * tolerance * dr; - valid = _extend_range (range, t_limit, valid); - } - - /* - * Nondegenerate, nonlimit circles passing through the corners. - * - * a == 0 && a*t^2 - 2*b*t + c == 0 - * - * t = c / (2*b) - * - * The b == 0 case has just been handled, so we only have to - * compute this if b != 0. - */ -#define T_CORNER(x,y) \ - b = (x) * dx + (y) * dy + cr * dr; \ - if (fabs (b) >= DBL_EPSILON) { \ - double t_corner; \ - double x2 = (x) * (x); \ - double y2 = (y) * (y); \ - double cr2 = (cr) * (cr); \ - double c = x2 + y2 - cr2; \ - \ - t_corner = 0.5 * c / b; \ - if (t_corner * dr >= mindr) \ - valid = _extend_range (range, t_corner, valid); \ - } - - /* circles touching each corner */ - T_CORNER (x0, y0); - T_CORNER (x0, y1); - T_CORNER (x1, y0); - T_CORNER (x1, y1); - -#undef T_CORNER - } else { - double inva, b, c, d; - - inva = 1 / a; - - /* - * Nondegenerate, nonlimit circles passing through the corners. - * - * a != 0 && a*t^2 - 2*b*t + c == 0 - * - * t = (b +- sqrt (b*b - a*c)) / a - * - * If the argument of sqrt() is negative, then no circle - * passes through the corner. - */ -#define T_CORNER(x,y) \ - b = (x) * dx + (y) * dy + cr * dr; \ - c = (x) * (x) + (y) * (y) - cr * cr; \ - d = b * b - a * c; \ - if (d >= 0) { \ - double t_corner; \ - \ - d = sqrt (d); \ - t_corner = (b + d) * inva; \ - if (t_corner * dr >= mindr) \ - valid = _extend_range (range, t_corner, valid); \ - t_corner = (b - d) * inva; \ - if (t_corner * dr >= mindr) \ - valid = _extend_range (range, t_corner, valid); \ - } - - /* circles touching each corner */ - T_CORNER (x0, y0); - T_CORNER (x0, y1); - T_CORNER (x1, y0); - T_CORNER (x1, y1); - -#undef T_CORNER - } -} - -/** - * _cairo_gradient_pattern_box_to_parameter: - * - * Compute a interpolation range sufficient to draw (within the given - * tolerance) the gradient in the given box getting the same result as - * using the (-inf, +inf) range. - * - * Assumes that the pattern is not degenerate. This can be guaranteed - * by simplifying it to a solid clear if _cairo_pattern_is_clear or to - * a solid color if _cairo_gradient_pattern_is_solid. - * - * The range isn't guaranteed to be minimal, but it tries to. - **/ -void -_cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient, - double x0, double y0, - double x1, double y1, - double tolerance, - double out_range[2]) -{ - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - _cairo_linear_pattern_box_to_parameter ((cairo_linear_pattern_t *) gradient, - x0, y0, x1, y1, out_range); - } else { - _cairo_radial_pattern_box_to_parameter ((cairo_radial_pattern_t *) gradient, - x0, y0, x1, y1, tolerance, out_range); - } -} - -/** - * _cairo_gradient_pattern_interpolate: - * - * Interpolate between the start and end objects of linear or radial - * gradients. The interpolated object is stored in out_circle, with - * the radius being zero in the linear gradient case. - **/ -void -_cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient, - double t, - cairo_circle_double_t *out_circle) -{ - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - -#define lerp(a,b) (a)*(1-t) + (b)*t - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; - out_circle->center.x = lerp (linear->pd1.x, linear->pd2.x); - out_circle->center.y = lerp (linear->pd1.y, linear->pd2.y); - out_circle->radius = 0; - } else { - cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient; - out_circle->center.x = lerp (radial->cd1.center.x, radial->cd2.center.x); - out_circle->center.y = lerp (radial->cd1.center.y, radial->cd2.center.y); - out_circle->radius = lerp (radial->cd1.radius , radial->cd2.radius); - } - -#undef lerp -} - - -/** - * _cairo_gradient_pattern_fit_to_range: - * - * Scale the extremes of a gradient to guarantee that the coordinates - * and their deltas are within the range (-max_value, max_value). The - * new extremes are stored in out_circle. - * - * The pattern matrix is scaled to guarantee that the aspect of the - * gradient is the same and the result is stored in out_matrix. - * - **/ -void -_cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient, - double max_value, - cairo_matrix_t *out_matrix, - cairo_circle_double_t out_circle[2]) -{ - double dim; - - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; - - out_circle[0].center = linear->pd1; - out_circle[0].radius = 0; - out_circle[1].center = linear->pd2; - out_circle[1].radius = 0; - - dim = fabs (linear->pd1.x); - dim = MAX (dim, fabs (linear->pd1.y)); - dim = MAX (dim, fabs (linear->pd2.x)); - dim = MAX (dim, fabs (linear->pd2.y)); - dim = MAX (dim, fabs (linear->pd1.x - linear->pd2.x)); - dim = MAX (dim, fabs (linear->pd1.y - linear->pd2.y)); - } else { - cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient; - - out_circle[0] = radial->cd1; - out_circle[1] = radial->cd2; - - dim = fabs (radial->cd1.center.x); - dim = MAX (dim, fabs (radial->cd1.center.y)); - dim = MAX (dim, fabs (radial->cd1.radius)); - dim = MAX (dim, fabs (radial->cd2.center.x)); - dim = MAX (dim, fabs (radial->cd2.center.y)); - dim = MAX (dim, fabs (radial->cd2.radius)); - dim = MAX (dim, fabs (radial->cd1.center.x - radial->cd2.center.x)); - dim = MAX (dim, fabs (radial->cd1.center.y - radial->cd2.center.y)); - dim = MAX (dim, fabs (radial->cd1.radius - radial->cd2.radius)); - } - - if (unlikely (dim > max_value)) { - cairo_matrix_t scale; - - dim = max_value / dim; - - out_circle[0].center.x *= dim; - out_circle[0].center.y *= dim; - out_circle[0].radius *= dim; - out_circle[1].center.x *= dim; - out_circle[1].center.y *= dim; - out_circle[1].radius *= dim; - - cairo_matrix_init_scale (&scale, dim, dim); - cairo_matrix_multiply (out_matrix, &gradient->base.matrix, &scale); - } else { - *out_matrix = gradient->base.matrix; - } -} - -static cairo_bool_t -_gradient_is_clear (const cairo_gradient_pattern_t *gradient, - const cairo_rectangle_int_t *extents) -{ - unsigned int i; - - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - - if (gradient->n_stops == 0 || - (gradient->base.extend == CAIRO_EXTEND_NONE && - gradient->stops[0].offset == gradient->stops[gradient->n_stops - 1].offset)) - return TRUE; - - if (gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL) { - /* degenerate radial gradients are clear */ - if (_radial_pattern_is_degenerate ((cairo_radial_pattern_t *) gradient)) - return TRUE; - } else if (gradient->base.extend == CAIRO_EXTEND_NONE) { - /* EXTEND_NONE degenerate linear gradients are clear */ - if (_linear_pattern_is_degenerate ((cairo_linear_pattern_t *) gradient)) - return TRUE; - } - - /* Check if the extents intersect the drawn part of the pattern. */ - if (extents != NULL && - (gradient->base.extend == CAIRO_EXTEND_NONE || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL)) - { - double t[2]; - - _cairo_gradient_pattern_box_to_parameter (gradient, - extents->x, - extents->y, - extents->x + extents->width, - extents->y + extents->height, - DBL_EPSILON, - t); - - if (gradient->base.extend == CAIRO_EXTEND_NONE && - (t[0] >= gradient->stops[gradient->n_stops - 1].offset || - t[1] <= gradient->stops[0].offset)) - { - return TRUE; - } - - if (t[0] == t[1]) - return TRUE; - } - - for (i = 0; i < gradient->n_stops; i++) - if (! CAIRO_COLOR_IS_CLEAR (&gradient->stops[i].color)) - return FALSE; - - return TRUE; -} - -static void -_gradient_color_average (const cairo_gradient_pattern_t *gradient, - cairo_color_t *color) -{ - double delta0, delta1; - double r, g, b, a; - unsigned int i, start = 1, end; - - assert (gradient->n_stops > 0); - assert (gradient->base.extend != CAIRO_EXTEND_NONE); - - if (gradient->n_stops == 1) { - _cairo_color_init_rgba (color, - gradient->stops[0].color.red, - gradient->stops[0].color.green, - gradient->stops[0].color.blue, - gradient->stops[0].color.alpha); - return; - } - - end = gradient->n_stops - 1; - - switch (gradient->base.extend) { - case CAIRO_EXTEND_REPEAT: - /* - * Sa, Sb and Sy, Sz are the first two and last two stops respectively. - * The weight of the first and last stop can be computed as the area of - * the following triangles (taken with height 1, since the whole [0-1] - * will have total weight 1 this way): b*h/2 - * - * + + - * / |\ / | \ - * / | \ / | \ - * / | \ / | \ - * ~~~~~+---+---+---+~~~~~~~+-------+---+---+~~~~~ - * -1+Sz 0 Sa Sb Sy Sz 1 1+Sa - * - * For the first stop: (Sb-(-1+Sz)/2 = (1+Sb-Sz)/2 - * For the last stop: ((1+Sa)-Sy)/2 = (1+Sa-Sy)/2 - * Halving the result is done after summing up all the areas. - */ - delta0 = 1.0 + gradient->stops[1].offset - gradient->stops[end].offset; - delta1 = 1.0 + gradient->stops[0].offset - gradient->stops[end-1].offset; - break; - - case CAIRO_EXTEND_REFLECT: - /* - * Sa, Sb and Sy, Sz are the first two and last two stops respectively. - * The weight of the first and last stop can be computed as the area of - * the following trapezoids (taken with height 1, since the whole [0-1] - * will have total weight 1 this way): (b+B)*h/2 - * - * +-------+ +---+ - * | |\ / | | - * | | \ / | | - * | | \ / | | - * +-------+---+~~~~~~~+-------+---+ - * 0 Sa Sb Sy Sz 1 - * - * For the first stop: (Sa+Sb)/2 - * For the last stop: ((1-Sz) + (1-Sy))/2 = (2-Sy-Sz)/2 - * Halving the result is done after summing up all the areas. - */ - delta0 = gradient->stops[0].offset + gradient->stops[1].offset; - delta1 = 2.0 - gradient->stops[end-1].offset - gradient->stops[end].offset; - break; - - case CAIRO_EXTEND_PAD: - /* PAD is computed as the average of the first and last stop: - * - take both of them with weight 1 (they will be halved - * after the whole sum has been computed). - * - avoid summing any of the inner stops. - */ - delta0 = delta1 = 1.0; - start = end; - break; - - case CAIRO_EXTEND_NONE: - default: - ASSERT_NOT_REACHED; - _cairo_color_init_rgba (color, 0, 0, 0, 0); - return; - } - - r = delta0 * gradient->stops[0].color.red; - g = delta0 * gradient->stops[0].color.green; - b = delta0 * gradient->stops[0].color.blue; - a = delta0 * gradient->stops[0].color.alpha; - - for (i = start; i < end; ++i) { - /* Inner stops weight is the same as the area of the triangle they influence - * (which goes from the stop before to the stop after), again with height 1 - * since the whole must sum up to 1: b*h/2 - * Halving is done after the whole sum has been computed. - */ - double delta = gradient->stops[i+1].offset - gradient->stops[i-1].offset; - r += delta * gradient->stops[i].color.red; - g += delta * gradient->stops[i].color.green; - b += delta * gradient->stops[i].color.blue; - a += delta * gradient->stops[i].color.alpha; - } - - r += delta1 * gradient->stops[end].color.red; - g += delta1 * gradient->stops[end].color.green; - b += delta1 * gradient->stops[end].color.blue; - a += delta1 * gradient->stops[end].color.alpha; - - _cairo_color_init_rgba (color, r * .5, g * .5, b * .5, a * .5); -} - -/** - * _cairo_pattern_alpha_range: - * - * Convenience function to determine the minimum and maximum alpha in - * the drawn part of a pattern (i.e. ignoring clear parts caused by - * extend modes and/or pattern shape). - * - * If not NULL, out_min and out_max will be set respectively to the - * minimum and maximum alpha value of the pattern. - **/ -void -_cairo_pattern_alpha_range (const cairo_pattern_t *pattern, - double *out_min, - double *out_max) -{ - double alpha_min, alpha_max; - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: { - const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; - alpha_min = alpha_max = solid->color.alpha; - break; - } - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: { - const cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern; - unsigned int i; - - assert (gradient->n_stops >= 1); - - alpha_min = alpha_max = gradient->stops[0].color.alpha; - for (i = 1; i < gradient->n_stops; i++) { - if (alpha_min > gradient->stops[i].color.alpha) - alpha_min = gradient->stops[i].color.alpha; - else if (alpha_max < gradient->stops[i].color.alpha) - alpha_max = gradient->stops[i].color.alpha; - } - - break; - } - - case CAIRO_PATTERN_TYPE_MESH: { - const cairo_mesh_pattern_t *mesh = (const cairo_mesh_pattern_t *) pattern; - const cairo_mesh_patch_t *patch = _cairo_array_index_const (&mesh->patches, 0); - unsigned int i, j, n = _cairo_array_num_elements (&mesh->patches); - - assert (n >= 1); - - alpha_min = alpha_max = patch[0].colors[0].alpha; - for (i = 0; i < n; i++) { - for (j = 0; j < 4; j++) { - if (patch[i].colors[j].alpha < alpha_min) - alpha_min = patch[i].colors[j].alpha; - else if (patch[i].colors[j].alpha > alpha_max) - alpha_max = patch[i].colors[j].alpha; - } - } - - break; - } - - default: - ASSERT_NOT_REACHED; - /* fall through */ - - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - alpha_min = 0; - alpha_max = 1; - break; - } - - if (out_min) - *out_min = alpha_min; - if (out_max) - *out_max = alpha_max; -} - -/** - * _cairo_mesh_pattern_coord_box: - * - * Convenience function to determine the range of the coordinates of - * the points used to define the patches of the mesh. - * - * This is guaranteed to contain the pattern extents, but might not be - * tight, just like a Bezier curve is always inside the convex hull of - * the control points. - * - * This function cannot be used while the mesh is being constructed. - * - * The function returns TRUE and sets the output parametes to define - * the coodrinate range if the mesh pattern contains at least one - * patch, otherwise it returns FALSE. - **/ -cairo_bool_t -_cairo_mesh_pattern_coord_box (const cairo_mesh_pattern_t *mesh, - double *out_xmin, - double *out_ymin, - double *out_xmax, - double *out_ymax) -{ - const cairo_mesh_patch_t *patch; - unsigned int num_patches, i, j, k; - double x0, y0, x1, y1; - - assert (mesh->current_patch == NULL); - - num_patches = _cairo_array_num_elements (&mesh->patches); - - if (num_patches == 0) - return FALSE; - - patch = _cairo_array_index_const (&mesh->patches, 0); - x0 = x1 = patch->points[0][0].x; - y0 = y1 = patch->points[0][0].y; - - for (i = 0; i < num_patches; i++) { - for (j = 0; j < 4; j++) { - for (k = 0; k < 4; k++) { - x0 = MIN (x0, patch[i].points[j][k].x); - y0 = MIN (y0, patch[i].points[j][k].y); - x1 = MAX (x1, patch[i].points[j][k].x); - y1 = MAX (y1, patch[i].points[j][k].y); - } - } - } - - *out_xmin = x0; - *out_ymin = y0; - *out_xmax = x1; - *out_ymax = y1; - - return TRUE; -} - -/** - * _cairo_gradient_pattern_is_solid: - * - * Convenience function to determine whether a gradient pattern is - * a solid color within the given extents. In this case the color - * argument is initialized to the color the pattern represents. - * This functions doesn't handle completely transparent gradients, - * thus it should be called only after _cairo_pattern_is_clear has - * returned FALSE. - * - * Return value: %TRUE if the pattern is a solid color. - **/ -cairo_bool_t -_cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, - const cairo_rectangle_int_t *extents, - cairo_color_t *color) -{ - unsigned int i; - - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - - /* TODO: radial */ - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; - if (_linear_pattern_is_degenerate (linear)) { - _gradient_color_average (gradient, color); - return TRUE; - } - - if (gradient->base.extend == CAIRO_EXTEND_NONE) { - double t[2]; - - /* We already know that the pattern is not clear, thus if some - * part of it is clear, the whole is not solid. - */ - - if (extents == NULL) - return FALSE; - - _cairo_linear_pattern_box_to_parameter (linear, - extents->x, - extents->y, - extents->x + extents->width, - extents->y + extents->height, - t); - - if (t[0] < 0.0 || t[1] > 1.0) - return FALSE; - } - } else - return FALSE; - - for (i = 1; i < gradient->n_stops; i++) - if (! _cairo_color_stop_equal (&gradient->stops[0].color, - &gradient->stops[i].color)) - return FALSE; - - _cairo_color_init_rgba (color, - gradient->stops[0].color.red, - gradient->stops[0].color.green, - gradient->stops[0].color.blue, - gradient->stops[0].color.alpha); - - return TRUE; -} - -static cairo_bool_t -_mesh_is_clear (const cairo_mesh_pattern_t *mesh) -{ - double x1, y1, x2, y2; - cairo_bool_t is_valid; - - is_valid = _cairo_mesh_pattern_coord_box (mesh, &x1, &y1, &x2, &y2); - if (!is_valid) - return TRUE; - - if (x2 - x1 < DBL_EPSILON || y2 - y1 < DBL_EPSILON) - return TRUE; - - return FALSE; -} - -/** - * _cairo_pattern_is_opaque_solid: - * - * Convenience function to determine whether a pattern is an opaque - * (alpha==1.0) solid color pattern. This is done by testing whether - * the pattern's alpha value when converted to a byte is 255, so if a - * backend actually supported deep alpha channels this function might - * not do the right thing. - * - * Return value: %TRUE if the pattern is an opaque, solid color. - **/ -cairo_bool_t -_cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern) -{ - cairo_solid_pattern_t *solid; - - if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) - return FALSE; - - solid = (cairo_solid_pattern_t *) pattern; - - return CAIRO_COLOR_IS_OPAQUE (&solid->color); -} - -static cairo_bool_t -_surface_is_opaque (const cairo_surface_pattern_t *pattern, - const cairo_rectangle_int_t *sample) -{ - cairo_rectangle_int_t extents; - - if (pattern->surface->content & CAIRO_CONTENT_ALPHA) - return FALSE; - - if (pattern->base.extend != CAIRO_EXTEND_NONE) - return TRUE; - - if (! _cairo_surface_get_extents (pattern->surface, &extents)) - return TRUE; - - if (sample == NULL) - return FALSE; - - return _cairo_rectangle_contains_rectangle (&extents, sample); -} - -static cairo_bool_t -_raster_source_is_opaque (const cairo_raster_source_pattern_t *pattern, - const cairo_rectangle_int_t *sample) -{ - if (pattern->content & CAIRO_CONTENT_ALPHA) - return FALSE; - - if (pattern->base.extend != CAIRO_EXTEND_NONE) - return TRUE; - - if (sample == NULL) - return FALSE; - - return _cairo_rectangle_contains_rectangle (&pattern->extents, sample); -} - -static cairo_bool_t -_surface_is_clear (const cairo_surface_pattern_t *pattern) -{ - cairo_rectangle_int_t extents; - - if (_cairo_surface_get_extents (pattern->surface, &extents) && - (extents.width == 0 || extents.height == 0)) - return TRUE; - - return pattern->surface->is_clear && - pattern->surface->content & CAIRO_CONTENT_ALPHA; -} - -static cairo_bool_t -_raster_source_is_clear (const cairo_raster_source_pattern_t *pattern) -{ - return pattern->extents.width == 0 || pattern->extents.height == 0; -} - -static cairo_bool_t -_gradient_is_opaque (const cairo_gradient_pattern_t *gradient, - const cairo_rectangle_int_t *sample) -{ - unsigned int i; - - assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || - gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); - - if (gradient->n_stops == 0 || - (gradient->base.extend == CAIRO_EXTEND_NONE && - gradient->stops[0].offset == gradient->stops[gradient->n_stops - 1].offset)) - return FALSE; - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - if (gradient->base.extend == CAIRO_EXTEND_NONE) { - double t[2]; - cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; - - /* EXTEND_NONE degenerate radial gradients are clear */ - if (_linear_pattern_is_degenerate (linear)) - return FALSE; - - if (sample == NULL) - return FALSE; - - _cairo_linear_pattern_box_to_parameter (linear, - sample->x, - sample->y, - sample->x + sample->width, - sample->y + sample->height, - t); - - if (t[0] < 0.0 || t[1] > 1.0) - return FALSE; - } - } else - return FALSE; /* TODO: check actual intersection */ - - for (i = 0; i < gradient->n_stops; i++) - if (! CAIRO_COLOR_IS_OPAQUE (&gradient->stops[i].color)) - return FALSE; - - return TRUE; -} - -/** - * _cairo_pattern_is_opaque: - * - * Convenience function to determine whether a pattern is an opaque - * pattern (of any type). The same caveats that apply to - * _cairo_pattern_is_opaque_solid apply here as well. - * - * Return value: %TRUE if the pattern is a opaque. - **/ -cairo_bool_t -_cairo_pattern_is_opaque (const cairo_pattern_t *abstract_pattern, - const cairo_rectangle_int_t *sample) -{ - const cairo_pattern_union_t *pattern; - - if (abstract_pattern->has_component_alpha) - return FALSE; - - pattern = (cairo_pattern_union_t *) abstract_pattern; - switch (pattern->base.type) { - case CAIRO_PATTERN_TYPE_SOLID: - return _cairo_pattern_is_opaque_solid (abstract_pattern); - case CAIRO_PATTERN_TYPE_SURFACE: - return _surface_is_opaque (&pattern->surface, sample); - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _raster_source_is_opaque (&pattern->raster_source, sample); - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - return _gradient_is_opaque (&pattern->gradient.base, sample); - case CAIRO_PATTERN_TYPE_MESH: - return FALSE; - } - - ASSERT_NOT_REACHED; - return FALSE; -} - -cairo_bool_t -_cairo_pattern_is_clear (const cairo_pattern_t *abstract_pattern) -{ - const cairo_pattern_union_t *pattern; - - if (abstract_pattern->has_component_alpha) - return FALSE; - - pattern = (cairo_pattern_union_t *) abstract_pattern; - switch (abstract_pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return CAIRO_COLOR_IS_CLEAR (&pattern->solid.color); - case CAIRO_PATTERN_TYPE_SURFACE: - return _surface_is_clear (&pattern->surface); - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _raster_source_is_clear (&pattern->raster_source); - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - return _gradient_is_clear (&pattern->gradient.base, NULL); - case CAIRO_PATTERN_TYPE_MESH: - return _mesh_is_clear (&pattern->mesh); - } - - ASSERT_NOT_REACHED; - return FALSE; -} - -/* - * Will given row of back-translation matrix work with bilinear scale? - * This is true for scales larger than 1. Also it was judged acceptable - * for scales larger than .75. And if there is integer translation - * then a scale of exactly .5 works. - */ -static int -use_bilinear(double x, double y, double t) -{ - /* This is the inverse matrix! */ - double h = x*x + y*y; - if (h < 1.0 / (0.75 * 0.75)) - return TRUE; /* scale > .75 */ - if ((h > 3.99 && h < 4.01) /* scale is 1/2 */ - && !_cairo_fixed_from_double(x*y) /* parallel to an axis */ - && _cairo_fixed_is_integer (_cairo_fixed_from_double (t))) - return TRUE; - return FALSE; -} - -/** - * _cairo_pattern_analyze_filter: - * @pattern: surface pattern - * Returns: the optimized #cairo_filter_t to use with @pattern. - * - * Possibly optimize the filter to a simpler value depending on transformation - **/ -cairo_filter_t -_cairo_pattern_analyze_filter (const cairo_pattern_t *pattern) -{ - switch (pattern->filter) { - case CAIRO_FILTER_GOOD: - case CAIRO_FILTER_BEST: - case CAIRO_FILTER_BILINEAR: - case CAIRO_FILTER_FAST: - /* If source pixels map 1:1 onto destination pixels, we do - * not need to filter (and do not want to filter, since it - * will cause blurriness) - */ - if (_cairo_matrix_is_pixel_exact (&pattern->matrix)) { - return CAIRO_FILTER_NEAREST; - } else { - /* Use BILINEAR for any scale greater than .75 instead - * of GOOD. For scales of 1 and larger this is identical, - * for the smaller sizes it was judged that the artifacts - * were not worse than the artifacts from a box filer. - * BILINEAR can also be used if the scale is exactly .5 - * and the translation in that direction is an integer. - */ - if (pattern->filter == CAIRO_FILTER_GOOD && - use_bilinear (pattern->matrix.xx, pattern->matrix.xy, - pattern->matrix.x0) && - use_bilinear (pattern->matrix.yx, pattern->matrix.yy, - pattern->matrix.y0)) - return CAIRO_FILTER_BILINEAR; - } - break; - - case CAIRO_FILTER_NEAREST: - case CAIRO_FILTER_GAUSSIAN: - default: - break; - } - - return pattern->filter; -} - -/** - * _cairo_hypot: - * Returns: value similar to hypot(@x,@y) - * - * May want to replace this with Manhattan distance (abs(x)+abs(y)) if - * hypot is too slow, as there is no need for accuracy here. - **/ -static inline double -_cairo_hypot(double x, double y) -{ - return hypot(x, y); -} - -/** - * _cairo_pattern_sampled_area: - * - * Return region of @pattern that will be sampled to fill @extents, - * based on the transformation and filter. - * - * This does not include pixels that are mulitiplied by values very - * close to zero by the ends of filters. This is so that transforms - * that should be the identity or 90 degree rotations do not expand - * the source unexpectedly. - * - * XXX: We don't actually have any way of querying the backend for - * the filter radius, so we just guess base on what we know that - * backends do currently (see bug #10508) - **/ -void -_cairo_pattern_sampled_area (const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - cairo_rectangle_int_t *sample) -{ - double x1, x2, y1, y2; - double padx, pady; - - /* Assume filters are interpolating, which means identity - cannot change the image */ - if (_cairo_matrix_is_identity (&pattern->matrix)) { - *sample = *extents; - return; - } - - /* Transform the centers of the corner pixels */ - x1 = extents->x + 0.5; - y1 = extents->y + 0.5; - x2 = x1 + (extents->width - 1); - y2 = y1 + (extents->height - 1); - _cairo_matrix_transform_bounding_box (&pattern->matrix, - &x1, &y1, &x2, &y2, - NULL); - - /* How far away from center will it actually sample? - * This is the distance from a transformed pixel center to the - * furthest sample of reasonable size. - */ - switch (pattern->filter) { - case CAIRO_FILTER_NEAREST: - case CAIRO_FILTER_FAST: - /* Correct value is zero, but when the sample is on an integer - * it is unknown if the backend will sample the pixel to the - * left or right. This value makes it include both possible pixels. - */ - padx = pady = 0.004; - break; - case CAIRO_FILTER_BILINEAR: - case CAIRO_FILTER_GAUSSIAN: - default: - /* Correct value is .5 */ - padx = pady = 0.495; - break; - case CAIRO_FILTER_GOOD: - /* Correct value is max(width,1)*.5 */ - padx = _cairo_hypot (pattern->matrix.xx, pattern->matrix.xy); - if (padx <= 1.0) padx = 0.495; - else if (padx >= 16.0) padx = 7.92; - else padx *= 0.495; - pady = _cairo_hypot (pattern->matrix.yx, pattern->matrix.yy); - if (pady <= 1.0) pady = 0.495; - else if (pady >= 16.0) pady = 7.92; - else pady *= 0.495; - break; - case CAIRO_FILTER_BEST: - /* Correct value is width*2 */ - padx = _cairo_hypot (pattern->matrix.xx, pattern->matrix.xy) * 1.98; - if (padx > 7.92) padx = 7.92; - pady = _cairo_hypot (pattern->matrix.yx, pattern->matrix.yy) * 1.98; - if (pady > 7.92) pady = 7.92; - break; - } - - /* round furthest samples to edge of pixels */ - x1 = floor (x1 - padx); - if (x1 < CAIRO_RECT_INT_MIN) x1 = CAIRO_RECT_INT_MIN; - sample->x = x1; - - y1 = floor (y1 - pady); - if (y1 < CAIRO_RECT_INT_MIN) y1 = CAIRO_RECT_INT_MIN; - sample->y = y1; - - x2 = floor (x2 + padx) + 1.0; - if (x2 > CAIRO_RECT_INT_MAX) x2 = CAIRO_RECT_INT_MAX; - sample->width = x2 - x1; - - y2 = floor (y2 + pady) + 1.0; - if (y2 > CAIRO_RECT_INT_MAX) y2 = CAIRO_RECT_INT_MAX; - sample->height = y2 - y1; -} - -/** - * _cairo_pattern_get_extents: - * - * Return the "target-space" extents of @pattern in @extents. - * - * For unbounded patterns, the @extents will be initialized with - * "infinite" extents, (minimum and maximum fixed-point values). - * - * XXX: Currently, bounded gradient patterns will also return - * "infinite" extents, though it would be possible to optimize these - * with a little more work. - **/ -void -_cairo_pattern_get_extents (const cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents) -{ - double x1, y1, x2, y2; - int ix1, ix2, iy1, iy2; - cairo_bool_t round_x = FALSE; - cairo_bool_t round_y = FALSE; - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - goto UNBOUNDED; - - case CAIRO_PATTERN_TYPE_SURFACE: - { - cairo_rectangle_int_t surface_extents; - const cairo_surface_pattern_t *surface_pattern = - (const cairo_surface_pattern_t *) pattern; - cairo_surface_t *surface = surface_pattern->surface; - - if (! _cairo_surface_get_extents (surface, &surface_extents)) - goto UNBOUNDED; - - if (surface_extents.width == 0 || surface_extents.height == 0) - goto EMPTY; - - if (pattern->extend != CAIRO_EXTEND_NONE) - goto UNBOUNDED; - - x1 = surface_extents.x; - y1 = surface_extents.y; - x2 = surface_extents.x + (int) surface_extents.width; - y2 = surface_extents.y + (int) surface_extents.height; - - goto HANDLE_FILTER; - } - break; - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - { - const cairo_raster_source_pattern_t *raster = - (const cairo_raster_source_pattern_t *) pattern; - - if (raster->extents.width == 0 || raster->extents.height == 0) - goto EMPTY; - - if (pattern->extend != CAIRO_EXTEND_NONE) - goto UNBOUNDED; - - x1 = raster->extents.x; - y1 = raster->extents.y; - x2 = raster->extents.x + (int) raster->extents.width; - y2 = raster->extents.y + (int) raster->extents.height; - } - HANDLE_FILTER: - switch (pattern->filter) { - case CAIRO_FILTER_NEAREST: - case CAIRO_FILTER_FAST: - round_x = round_y = TRUE; - /* We don't know which way .5 will go, so fudge it slightly. */ - x1 -= 0.004; - y1 -= 0.004; - x2 += 0.004; - y2 += 0.004; - break; - case CAIRO_FILTER_BEST: - /* Assume best filter will produce nice antialiased edges */ - break; - case CAIRO_FILTER_BILINEAR: - case CAIRO_FILTER_GAUSSIAN: - case CAIRO_FILTER_GOOD: - default: - /* These filters can blur the edge out 1/2 pixel when scaling up */ - if (_cairo_hypot (pattern->matrix.xx, pattern->matrix.yx) < 1.0) { - x1 -= 0.5; - x2 += 0.5; - round_x = TRUE; - } - if (_cairo_hypot (pattern->matrix.xy, pattern->matrix.yy) < 1.0) { - y1 -= 0.5; - y2 += 0.5; - round_y = TRUE; - } - break; - } - break; - - case CAIRO_PATTERN_TYPE_RADIAL: - { - const cairo_radial_pattern_t *radial = - (const cairo_radial_pattern_t *) pattern; - double cx1, cy1; - double cx2, cy2; - double r1, r2; - - if (_radial_pattern_is_degenerate (radial)) { - /* cairo-gstate should have optimised degenerate - * patterns to solid clear patterns, so we can ignore - * them here. */ - goto EMPTY; - } - - /* TODO: in some cases (focus outside/on the circle) it is - * half-bounded. */ - if (pattern->extend != CAIRO_EXTEND_NONE) - goto UNBOUNDED; - - cx1 = radial->cd1.center.x; - cy1 = radial->cd1.center.y; - r1 = radial->cd1.radius; - - cx2 = radial->cd2.center.x; - cy2 = radial->cd2.center.y; - r2 = radial->cd2.radius; - - x1 = MIN (cx1 - r1, cx2 - r2); - y1 = MIN (cy1 - r1, cy2 - r2); - x2 = MAX (cx1 + r1, cx2 + r2); - y2 = MAX (cy1 + r1, cy2 + r2); - } - break; - - case CAIRO_PATTERN_TYPE_LINEAR: - { - const cairo_linear_pattern_t *linear = - (const cairo_linear_pattern_t *) pattern; - - if (pattern->extend != CAIRO_EXTEND_NONE) - goto UNBOUNDED; - - if (_linear_pattern_is_degenerate (linear)) { - /* cairo-gstate should have optimised degenerate - * patterns to solid ones, so we can again ignore - * them here. */ - goto EMPTY; - } - - /* TODO: to get tight extents, use the matrix to transform - * the pattern instead of transforming the extents later. */ - if (pattern->matrix.xy != 0. || pattern->matrix.yx != 0.) - goto UNBOUNDED; - - if (linear->pd1.x == linear->pd2.x) { - x1 = -HUGE_VAL; - x2 = HUGE_VAL; - y1 = MIN (linear->pd1.y, linear->pd2.y); - y2 = MAX (linear->pd1.y, linear->pd2.y); - } else if (linear->pd1.y == linear->pd2.y) { - x1 = MIN (linear->pd1.x, linear->pd2.x); - x2 = MAX (linear->pd1.x, linear->pd2.x); - y1 = -HUGE_VAL; - y2 = HUGE_VAL; - } else { - goto UNBOUNDED; - } - - /* The current linear renderer just point-samples in the middle - of the pixels, similar to the NEAREST filter: */ - round_x = round_y = TRUE; - } - break; - - case CAIRO_PATTERN_TYPE_MESH: - { - const cairo_mesh_pattern_t *mesh = - (const cairo_mesh_pattern_t *) pattern; - if (! _cairo_mesh_pattern_coord_box (mesh, &x1, &y1, &x2, &y2)) - goto EMPTY; - } - break; - - default: - ASSERT_NOT_REACHED; - } - - if (_cairo_matrix_is_translation (&pattern->matrix)) { - x1 -= pattern->matrix.x0; x2 -= pattern->matrix.x0; - y1 -= pattern->matrix.y0; y2 -= pattern->matrix.y0; - } else { - cairo_matrix_t imatrix; - cairo_status_t status; - - imatrix = pattern->matrix; - status = cairo_matrix_invert (&imatrix); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - _cairo_matrix_transform_bounding_box (&imatrix, - &x1, &y1, &x2, &y2, - NULL); - } - - if (!round_x) { - x1 -= 0.5; - x2 += 0.5; - } - if (x1 < CAIRO_RECT_INT_MIN) - ix1 = CAIRO_RECT_INT_MIN; - else - ix1 = _cairo_lround (x1); - if (x2 > CAIRO_RECT_INT_MAX) - ix2 = CAIRO_RECT_INT_MAX; - else - ix2 = _cairo_lround (x2); - extents->x = ix1; extents->width = ix2 - ix1; - - if (!round_y) { - y1 -= 0.5; - y2 += 0.5; - } - if (y1 < CAIRO_RECT_INT_MIN) - iy1 = CAIRO_RECT_INT_MIN; - else - iy1 = _cairo_lround (y1); - if (y2 > CAIRO_RECT_INT_MAX) - iy2 = CAIRO_RECT_INT_MAX; - else - iy2 = _cairo_lround (y2); - extents->y = iy1; extents->height = iy2 - iy1; - - return; - - UNBOUNDED: - /* unbounded patterns -> 'infinite' extents */ - _cairo_unbounded_rectangle_init (extents); - return; - - EMPTY: - extents->x = extents->y = 0; - extents->width = extents->height = 0; - return; -} - -/** - * _cairo_pattern_get_ink_extents: - * - * Return the "target-space" inked extents of @pattern in @extents. - **/ -cairo_int_status_t -_cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents) -{ - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE && - pattern->extend == CAIRO_EXTEND_NONE) - { - const cairo_surface_pattern_t *surface_pattern = - (const cairo_surface_pattern_t *) pattern; - cairo_surface_t *surface = surface_pattern->surface; - - surface = _cairo_surface_get_source (surface, NULL); - if (_cairo_surface_is_recording (surface)) { - cairo_matrix_t imatrix; - cairo_box_t box; - cairo_status_t status; - - imatrix = pattern->matrix; - status = cairo_matrix_invert (&imatrix); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - status = _cairo_recording_surface_get_ink_bbox ((cairo_recording_surface_t *)surface, - &box, &imatrix); - if (unlikely (status)) - return status; - - _cairo_box_round_to_rectangle (&box, extents); - return CAIRO_STATUS_SUCCESS; - } - } - - _cairo_pattern_get_extents (pattern, extents); - return CAIRO_STATUS_SUCCESS; -} - -static unsigned long -_cairo_solid_pattern_hash (unsigned long hash, - const cairo_solid_pattern_t *solid) -{ - hash = _cairo_hash_bytes (hash, &solid->color, sizeof (solid->color)); - - return hash; -} - -static unsigned long -_cairo_gradient_color_stops_hash (unsigned long hash, - const cairo_gradient_pattern_t *gradient) -{ - unsigned int n; - - hash = _cairo_hash_bytes (hash, - &gradient->n_stops, - sizeof (gradient->n_stops)); - - for (n = 0; n < gradient->n_stops; n++) { - hash = _cairo_hash_bytes (hash, - &gradient->stops[n].offset, - sizeof (double)); - hash = _cairo_hash_bytes (hash, - &gradient->stops[n].color, - sizeof (cairo_color_stop_t)); - } - - return hash; -} - -unsigned long -_cairo_linear_pattern_hash (unsigned long hash, - const cairo_linear_pattern_t *linear) -{ - hash = _cairo_hash_bytes (hash, &linear->pd1, sizeof (linear->pd1)); - hash = _cairo_hash_bytes (hash, &linear->pd2, sizeof (linear->pd2)); - - return _cairo_gradient_color_stops_hash (hash, &linear->base); -} - -unsigned long -_cairo_radial_pattern_hash (unsigned long hash, - const cairo_radial_pattern_t *radial) -{ - hash = _cairo_hash_bytes (hash, &radial->cd1.center, sizeof (radial->cd1.center)); - hash = _cairo_hash_bytes (hash, &radial->cd1.radius, sizeof (radial->cd1.radius)); - hash = _cairo_hash_bytes (hash, &radial->cd2.center, sizeof (radial->cd2.center)); - hash = _cairo_hash_bytes (hash, &radial->cd2.radius, sizeof (radial->cd2.radius)); - - return _cairo_gradient_color_stops_hash (hash, &radial->base); -} - -static unsigned long -_cairo_mesh_pattern_hash (unsigned long hash, const cairo_mesh_pattern_t *mesh) -{ - const cairo_mesh_patch_t *patch = _cairo_array_index_const (&mesh->patches, 0); - unsigned int i, n = _cairo_array_num_elements (&mesh->patches); - - for (i = 0; i < n; i++) - hash = _cairo_hash_bytes (hash, patch + i, sizeof (cairo_mesh_patch_t)); - - return hash; -} - -static unsigned long -_cairo_surface_pattern_hash (unsigned long hash, - const cairo_surface_pattern_t *surface) -{ - hash ^= surface->surface->unique_id; - - return hash; -} - -static unsigned long -_cairo_raster_source_pattern_hash (unsigned long hash, - const cairo_raster_source_pattern_t *raster) -{ - hash ^= (uintptr_t)raster->user_data; - - return hash; -} - -unsigned long -_cairo_pattern_hash (const cairo_pattern_t *pattern) -{ - unsigned long hash = _CAIRO_HASH_INIT_VALUE; - - if (pattern->status) - return 0; - - hash = _cairo_hash_bytes (hash, &pattern->type, sizeof (pattern->type)); - if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) { - hash = _cairo_hash_bytes (hash, - &pattern->matrix, sizeof (pattern->matrix)); - hash = _cairo_hash_bytes (hash, - &pattern->filter, sizeof (pattern->filter)); - hash = _cairo_hash_bytes (hash, - &pattern->extend, sizeof (pattern->extend)); - hash = _cairo_hash_bytes (hash, - &pattern->has_component_alpha, - sizeof (pattern->has_component_alpha)); - } - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return _cairo_solid_pattern_hash (hash, (cairo_solid_pattern_t *) pattern); - case CAIRO_PATTERN_TYPE_LINEAR: - return _cairo_linear_pattern_hash (hash, (cairo_linear_pattern_t *) pattern); - case CAIRO_PATTERN_TYPE_RADIAL: - return _cairo_radial_pattern_hash (hash, (cairo_radial_pattern_t *) pattern); - case CAIRO_PATTERN_TYPE_MESH: - return _cairo_mesh_pattern_hash (hash, (cairo_mesh_pattern_t *) pattern); - case CAIRO_PATTERN_TYPE_SURFACE: - return _cairo_surface_pattern_hash (hash, (cairo_surface_pattern_t *) pattern); - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _cairo_raster_source_pattern_hash (hash, (cairo_raster_source_pattern_t *) pattern); - default: - ASSERT_NOT_REACHED; - return FALSE; - } -} - -static cairo_bool_t -_cairo_solid_pattern_equal (const cairo_solid_pattern_t *a, - const cairo_solid_pattern_t *b) -{ - return _cairo_color_equal (&a->color, &b->color); -} - -static cairo_bool_t -_cairo_gradient_color_stops_equal (const cairo_gradient_pattern_t *a, - const cairo_gradient_pattern_t *b) -{ - unsigned int n; - - if (a->n_stops != b->n_stops) - return FALSE; - - for (n = 0; n < a->n_stops; n++) { - if (a->stops[n].offset != b->stops[n].offset) - return FALSE; - if (! _cairo_color_stop_equal (&a->stops[n].color, &b->stops[n].color)) - return FALSE; - } - - return TRUE; -} - -cairo_bool_t -_cairo_linear_pattern_equal (const cairo_linear_pattern_t *a, - const cairo_linear_pattern_t *b) -{ - if (a->pd1.x != b->pd1.x) - return FALSE; - - if (a->pd1.y != b->pd1.y) - return FALSE; - - if (a->pd2.x != b->pd2.x) - return FALSE; - - if (a->pd2.y != b->pd2.y) - return FALSE; - - return _cairo_gradient_color_stops_equal (&a->base, &b->base); -} - -cairo_bool_t -_cairo_radial_pattern_equal (const cairo_radial_pattern_t *a, - const cairo_radial_pattern_t *b) -{ - if (a->cd1.center.x != b->cd1.center.x) - return FALSE; - - if (a->cd1.center.y != b->cd1.center.y) - return FALSE; - - if (a->cd1.radius != b->cd1.radius) - return FALSE; - - if (a->cd2.center.x != b->cd2.center.x) - return FALSE; - - if (a->cd2.center.y != b->cd2.center.y) - return FALSE; - - if (a->cd2.radius != b->cd2.radius) - return FALSE; - - return _cairo_gradient_color_stops_equal (&a->base, &b->base); -} - -static cairo_bool_t -_cairo_mesh_pattern_equal (const cairo_mesh_pattern_t *a, - const cairo_mesh_pattern_t *b) -{ - const cairo_mesh_patch_t *patch_a, *patch_b; - unsigned int i, num_patches_a, num_patches_b; - - num_patches_a = _cairo_array_num_elements (&a->patches); - num_patches_b = _cairo_array_num_elements (&b->patches); - - if (num_patches_a != num_patches_b) - return FALSE; - - for (i = 0; i < num_patches_a; i++) { - patch_a = _cairo_array_index_const (&a->patches, i); - patch_b = _cairo_array_index_const (&b->patches, i); - if (memcmp (patch_a, patch_b, sizeof(cairo_mesh_patch_t)) != 0) - return FALSE; - } - - return TRUE; -} - -static cairo_bool_t -_cairo_surface_pattern_equal (const cairo_surface_pattern_t *a, - const cairo_surface_pattern_t *b) -{ - return a->surface->unique_id == b->surface->unique_id; -} - -static cairo_bool_t -_cairo_raster_source_pattern_equal (const cairo_raster_source_pattern_t *a, - const cairo_raster_source_pattern_t *b) -{ - return a->user_data == b->user_data; -} - -cairo_bool_t -_cairo_pattern_equal (const cairo_pattern_t *a, const cairo_pattern_t *b) -{ - if (a->status || b->status) - return FALSE; - - if (a == b) - return TRUE; - - if (a->type != b->type) - return FALSE; - - if (a->has_component_alpha != b->has_component_alpha) - return FALSE; - - if (a->type != CAIRO_PATTERN_TYPE_SOLID) { - if (memcmp (&a->matrix, &b->matrix, sizeof (cairo_matrix_t))) - return FALSE; - - if (a->filter != b->filter) - return FALSE; - - if (a->extend != b->extend) - return FALSE; - } - - switch (a->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return _cairo_solid_pattern_equal ((cairo_solid_pattern_t *) a, - (cairo_solid_pattern_t *) b); - case CAIRO_PATTERN_TYPE_LINEAR: - return _cairo_linear_pattern_equal ((cairo_linear_pattern_t *) a, - (cairo_linear_pattern_t *) b); - case CAIRO_PATTERN_TYPE_RADIAL: - return _cairo_radial_pattern_equal ((cairo_radial_pattern_t *) a, - (cairo_radial_pattern_t *) b); - case CAIRO_PATTERN_TYPE_MESH: - return _cairo_mesh_pattern_equal ((cairo_mesh_pattern_t *) a, - (cairo_mesh_pattern_t *) b); - case CAIRO_PATTERN_TYPE_SURFACE: - return _cairo_surface_pattern_equal ((cairo_surface_pattern_t *) a, - (cairo_surface_pattern_t *) b); - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _cairo_raster_source_pattern_equal ((cairo_raster_source_pattern_t *) a, - (cairo_raster_source_pattern_t *) b); - default: - ASSERT_NOT_REACHED; - return FALSE; - } -} - -/** - * cairo_pattern_get_rgba: - * @pattern: a #cairo_pattern_t - * @red: return value for red component of color, or %NULL - * @green: return value for green component of color, or %NULL - * @blue: return value for blue component of color, or %NULL - * @alpha: return value for alpha component of color, or %NULL - * - * Gets the solid color for a solid color pattern. - * - * Return value: %CAIRO_STATUS_SUCCESS, or - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a solid - * color pattern. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_get_rgba (cairo_pattern_t *pattern, - double *red, double *green, - double *blue, double *alpha) -{ - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) pattern; - double r0, g0, b0, a0; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - _cairo_color_get_rgba (&solid->color, &r0, &g0, &b0, &a0); - - if (red) - *red = r0; - if (green) - *green = g0; - if (blue) - *blue = b0; - if (alpha) - *alpha = a0; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_pattern_get_surface: - * @pattern: a #cairo_pattern_t - * @surface: return value for surface of pattern, or %NULL - * - * Gets the surface of a surface pattern. The reference returned in - * @surface is owned by the pattern; the caller should call - * cairo_surface_reference() if the surface is to be retained. - * - * Return value: %CAIRO_STATUS_SUCCESS, or - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a surface - * pattern. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_get_surface (cairo_pattern_t *pattern, - cairo_surface_t **surface) -{ - cairo_surface_pattern_t *spat = (cairo_surface_pattern_t*) pattern; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (surface) - *surface = spat->surface; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_pattern_get_color_stop_rgba: - * @pattern: a #cairo_pattern_t - * @index: index of the stop to return data for - * @offset: return value for the offset of the stop, or %NULL - * @red: return value for red component of color, or %NULL - * @green: return value for green component of color, or %NULL - * @blue: return value for blue component of color, or %NULL - * @alpha: return value for alpha component of color, or %NULL - * - * Gets the color and offset information at the given @index for a - * gradient pattern. Values of @index range from 0 to n-1 - * where n is the number returned - * by cairo_pattern_get_color_stop_count(). - * - * Return value: %CAIRO_STATUS_SUCCESS, or %CAIRO_STATUS_INVALID_INDEX - * if @index is not valid for the given pattern. If the pattern is - * not a gradient pattern, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH is - * returned. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern, - int index, double *offset, - double *red, double *green, - double *blue, double *alpha) -{ - cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t*) pattern; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && - pattern->type != CAIRO_PATTERN_TYPE_RADIAL) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (index < 0 || (unsigned int) index >= gradient->n_stops) - return _cairo_error (CAIRO_STATUS_INVALID_INDEX); - - if (offset) - *offset = gradient->stops[index].offset; - if (red) - *red = gradient->stops[index].color.red; - if (green) - *green = gradient->stops[index].color.green; - if (blue) - *blue = gradient->stops[index].color.blue; - if (alpha) - *alpha = gradient->stops[index].color.alpha; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_pattern_get_color_stop_count: - * @pattern: a #cairo_pattern_t - * @count: return value for the number of color stops, or %NULL - * - * Gets the number of color stops specified in the given gradient - * pattern. - * - * Return value: %CAIRO_STATUS_SUCCESS, or - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a gradient - * pattern. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern, - int *count) -{ - cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t*) pattern; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && - pattern->type != CAIRO_PATTERN_TYPE_RADIAL) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (count) - *count = gradient->n_stops; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_pattern_get_linear_points: - * @pattern: a #cairo_pattern_t - * @x0: return value for the x coordinate of the first point, or %NULL - * @y0: return value for the y coordinate of the first point, or %NULL - * @x1: return value for the x coordinate of the second point, or %NULL - * @y1: return value for the y coordinate of the second point, or %NULL - * - * Gets the gradient endpoints for a linear gradient. - * - * Return value: %CAIRO_STATUS_SUCCESS, or - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a linear - * gradient pattern. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_get_linear_points (cairo_pattern_t *pattern, - double *x0, double *y0, - double *x1, double *y1) -{ - cairo_linear_pattern_t *linear = (cairo_linear_pattern_t*) pattern; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (x0) - *x0 = linear->pd1.x; - if (y0) - *y0 = linear->pd1.y; - if (x1) - *x1 = linear->pd2.x; - if (y1) - *y1 = linear->pd2.y; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_pattern_get_radial_circles: - * @pattern: a #cairo_pattern_t - * @x0: return value for the x coordinate of the center of the first circle, or %NULL - * @y0: return value for the y coordinate of the center of the first circle, or %NULL - * @r0: return value for the radius of the first circle, or %NULL - * @x1: return value for the x coordinate of the center of the second circle, or %NULL - * @y1: return value for the y coordinate of the center of the second circle, or %NULL - * @r1: return value for the radius of the second circle, or %NULL - * - * Gets the gradient endpoint circles for a radial gradient, each - * specified as a center coordinate and a radius. - * - * Return value: %CAIRO_STATUS_SUCCESS, or - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a radial - * gradient pattern. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_pattern_get_radial_circles (cairo_pattern_t *pattern, - double *x0, double *y0, double *r0, - double *x1, double *y1, double *r1) -{ - cairo_radial_pattern_t *radial = (cairo_radial_pattern_t*) pattern; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_RADIAL) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (x0) - *x0 = radial->cd1.center.x; - if (y0) - *y0 = radial->cd1.center.y; - if (r0) - *r0 = radial->cd1.radius; - if (x1) - *x1 = radial->cd2.center.x; - if (y1) - *y1 = radial->cd2.center.y; - if (r1) - *r1 = radial->cd2.radius; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_mesh_pattern_get_patch_count: - * @pattern: a #cairo_pattern_t - * @count: return value for the number patches, or %NULL - * - * Gets the number of patches specified in the given mesh pattern. - * - * The number only includes patches which have been finished by - * calling cairo_mesh_pattern_end_patch(). For example it will be 0 - * during the definition of the first patch. - * - * Return value: %CAIRO_STATUS_SUCCESS, or - * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a mesh - * pattern. - * - * Since: 1.12 - **/ -cairo_status_t -cairo_mesh_pattern_get_patch_count (cairo_pattern_t *pattern, - unsigned int *count) -{ - cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; - - if (unlikely (pattern->status)) - return pattern->status; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (count) { - *count = _cairo_array_num_elements (&mesh->patches); - if (mesh->current_patch) - *count -= 1; - } - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_mesh_pattern_get_patch_count); - -/** - * cairo_mesh_pattern_get_path: - * @pattern: a #cairo_pattern_t - * @patch_num: the patch number to return data for - * - * Gets path defining the patch @patch_num for a mesh - * pattern. - * - * @patch_num can range from 0 to n-1 where n is the number returned by - * cairo_mesh_pattern_get_patch_count(). - * - * Return value: the path defining the patch, or a path with status - * %CAIRO_STATUS_INVALID_INDEX if @patch_num or @point_num is not - * valid for @pattern. If @pattern is not a mesh pattern, a path with - * status %CAIRO_STATUS_PATTERN_TYPE_MISMATCH is returned. - * - * Since: 1.12 - **/ -cairo_path_t * -cairo_mesh_pattern_get_path (cairo_pattern_t *pattern, - unsigned int patch_num) -{ - cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; - const cairo_mesh_patch_t *patch; - cairo_path_t *path; - cairo_path_data_t *data; - unsigned int patch_count; - int l, current_point; - - if (unlikely (pattern->status)) - return _cairo_path_create_in_error (pattern->status); - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) - return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH)); - - patch_count = _cairo_array_num_elements (&mesh->patches); - if (mesh->current_patch) - patch_count--; - - if (unlikely (patch_num >= patch_count)) - return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_INDEX)); - - patch = _cairo_array_index_const (&mesh->patches, patch_num); - - path = malloc (sizeof (cairo_path_t)); - if (path == NULL) - return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - path->num_data = 18; - path->data = _cairo_malloc_ab (path->num_data, - sizeof (cairo_path_data_t)); - if (path->data == NULL) { - free (path); - return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - data = path->data; - data[0].header.type = CAIRO_PATH_MOVE_TO; - data[0].header.length = 2; - data[1].point.x = patch->points[0][0].x; - data[1].point.y = patch->points[0][0].y; - data += data[0].header.length; - - current_point = 0; - - for (l = 0; l < 4; l++) { - int i, j, k; - - data[0].header.type = CAIRO_PATH_CURVE_TO; - data[0].header.length = 4; - - for (k = 1; k < 4; k++) { - current_point = (current_point + 1) % 12; - i = mesh_path_point_i[current_point]; - j = mesh_path_point_j[current_point]; - data[k].point.x = patch->points[i][j].x; - data[k].point.y = patch->points[i][j].y; - } - - data += data[0].header.length; - } - - path->status = CAIRO_STATUS_SUCCESS; - - return path; -} -slim_hidden_def (cairo_mesh_pattern_get_path); - -/** - * cairo_mesh_pattern_get_corner_color_rgba: - * @pattern: a #cairo_pattern_t - * @patch_num: the patch number to return data for - * @corner_num: the corner number to return data for - * @red: return value for red component of color, or %NULL - * @green: return value for green component of color, or %NULL - * @blue: return value for blue component of color, or %NULL - * @alpha: return value for alpha component of color, or %NULL - * - * Gets the color information in corner @corner_num of patch - * @patch_num for a mesh pattern. - * - * @patch_num can range from 0 to n-1 where n is the number returned by - * cairo_mesh_pattern_get_patch_count(). - * - * Valid values for @corner_num are from 0 to 3 and identify the - * corners as explained in cairo_pattern_create_mesh(). - * - * Return value: %CAIRO_STATUS_SUCCESS, or %CAIRO_STATUS_INVALID_INDEX - * if @patch_num or @corner_num is not valid for @pattern. If - * @pattern is not a mesh pattern, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH - * is returned. - * - * Since: 1.12 - **/ -cairo_status_t -cairo_mesh_pattern_get_corner_color_rgba (cairo_pattern_t *pattern, - unsigned int patch_num, - unsigned int corner_num, - double *red, double *green, - double *blue, double *alpha) -{ - cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; - unsigned int patch_count; - const cairo_mesh_patch_t *patch; - - if (unlikely (pattern->status)) - return pattern->status; - - if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (unlikely (corner_num > 3)) - return _cairo_error (CAIRO_STATUS_INVALID_INDEX); - - patch_count = _cairo_array_num_elements (&mesh->patches); - if (mesh->current_patch) - patch_count--; - - if (unlikely (patch_num >= patch_count)) - return _cairo_error (CAIRO_STATUS_INVALID_INDEX); - - patch = _cairo_array_index_const (&mesh->patches, patch_num); - - if (red) - *red = patch->colors[corner_num].red; - if (green) - *green = patch->colors[corner_num].green; - if (blue) - *blue = patch->colors[corner_num].blue; - if (alpha) - *alpha = patch->colors[corner_num].alpha; - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_mesh_pattern_get_corner_color_rgba); - -/** - * cairo_mesh_pattern_get_control_point: - * @pattern: a #cairo_pattern_t - * @patch_num: the patch number to return data for - * @point_num: the control point number to return data for - * @x: return value for the x coordinate of the control point, or %NULL - * @y: return value for the y coordinate of the control point, or %NULL - * - * Gets the control point @point_num of patch @patch_num for a mesh - * pattern. - * - * @patch_num can range from 0 to n-1 where n is the number returned by - * cairo_mesh_pattern_get_patch_count(). - * - * Valid values for @point_num are from 0 to 3 and identify the - * control points as explained in cairo_pattern_create_mesh(). - * - * Return value: %CAIRO_STATUS_SUCCESS, or %CAIRO_STATUS_INVALID_INDEX - * if @patch_num or @point_num is not valid for @pattern. If @pattern - * is not a mesh pattern, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH is - * returned. - * - * Since: 1.12 - **/ -cairo_status_t -cairo_mesh_pattern_get_control_point (cairo_pattern_t *pattern, - unsigned int patch_num, - unsigned int point_num, - double *x, double *y) -{ - cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; - const cairo_mesh_patch_t *patch; - unsigned int patch_count; - int i, j; - - if (pattern->status) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_MESH) - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - - if (point_num > 3) - return _cairo_error (CAIRO_STATUS_INVALID_INDEX); - - patch_count = _cairo_array_num_elements (&mesh->patches); - if (mesh->current_patch) - patch_count--; - - if (unlikely (patch_num >= patch_count)) - return _cairo_error (CAIRO_STATUS_INVALID_INDEX); - - patch = _cairo_array_index_const (&mesh->patches, patch_num); - - i = mesh_control_point_i[point_num]; - j = mesh_control_point_j[point_num]; - - if (x) - *x = patch->points[i][j].x; - if (y) - *y = patch->points[i][j].y; - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_mesh_pattern_get_control_point); - -void -_cairo_pattern_reset_static_data (void) -{ - int i; - - for (i = 0; i < ARRAY_LENGTH (freed_pattern_pool); i++) - _freed_pool_reset (&freed_pattern_pool[i]); -} - -static void -_cairo_debug_print_surface_pattern (FILE *file, - const cairo_surface_pattern_t *pattern) -{ - printf (" surface type: %d\n", pattern->surface->type); -} - -static void -_cairo_debug_print_raster_source_pattern (FILE *file, - const cairo_raster_source_pattern_t *raster) -{ - printf (" content: %x, size %dx%d\n", raster->content, raster->extents.width, raster->extents.height); -} - -static void -_cairo_debug_print_linear_pattern (FILE *file, - const cairo_linear_pattern_t *pattern) -{ -} - -static void -_cairo_debug_print_radial_pattern (FILE *file, - const cairo_radial_pattern_t *pattern) -{ -} - -static void -_cairo_debug_print_mesh_pattern (FILE *file, - const cairo_mesh_pattern_t *pattern) -{ -} - -void -_cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern) -{ - const char *s; - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: s = "solid"; break; - case CAIRO_PATTERN_TYPE_SURFACE: s = "surface"; break; - case CAIRO_PATTERN_TYPE_LINEAR: s = "linear"; break; - case CAIRO_PATTERN_TYPE_RADIAL: s = "radial"; break; - case CAIRO_PATTERN_TYPE_MESH: s = "mesh"; break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: s = "raster"; break; - default: s = "invalid"; ASSERT_NOT_REACHED; break; - } - - fprintf (file, "pattern: %s\n", s); - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) - return; - - switch (pattern->extend) { - case CAIRO_EXTEND_NONE: s = "none"; break; - case CAIRO_EXTEND_REPEAT: s = "repeat"; break; - case CAIRO_EXTEND_REFLECT: s = "reflect"; break; - case CAIRO_EXTEND_PAD: s = "pad"; break; - default: s = "invalid"; ASSERT_NOT_REACHED; break; - } - fprintf (file, " extend: %s\n", s); - - switch (pattern->filter) { - case CAIRO_FILTER_FAST: s = "fast"; break; - case CAIRO_FILTER_GOOD: s = "good"; break; - case CAIRO_FILTER_BEST: s = "best"; break; - case CAIRO_FILTER_NEAREST: s = "nearest"; break; - case CAIRO_FILTER_BILINEAR: s = "bilinear"; break; - case CAIRO_FILTER_GAUSSIAN: s = "guassian"; break; - default: s = "invalid"; ASSERT_NOT_REACHED; break; - } - fprintf (file, " filter: %s\n", s); - fprintf (file, " matrix: [%g %g %g %g %g %g]\n", - pattern->matrix.xx, pattern->matrix.yx, - pattern->matrix.xy, pattern->matrix.yy, - pattern->matrix.x0, pattern->matrix.y0); - switch (pattern->type) { - default: - case CAIRO_PATTERN_TYPE_SOLID: - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - _cairo_debug_print_raster_source_pattern (file, (cairo_raster_source_pattern_t *)pattern); - break; - case CAIRO_PATTERN_TYPE_SURFACE: - _cairo_debug_print_surface_pattern (file, (cairo_surface_pattern_t *)pattern); - break; - case CAIRO_PATTERN_TYPE_LINEAR: - _cairo_debug_print_linear_pattern (file, (cairo_linear_pattern_t *)pattern); - break; - case CAIRO_PATTERN_TYPE_RADIAL: - _cairo_debug_print_radial_pattern (file, (cairo_radial_pattern_t *)pattern); - break; - case CAIRO_PATTERN_TYPE_MESH: - _cairo_debug_print_mesh_pattern (file, (cairo_mesh_pattern_t *)pattern); - break; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators-private.h deleted file mode 100644 index 4314a042e81..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators-private.h +++ /dev/null @@ -1,176 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * Copyright © 2006 Red Hat, Inc - * Copyright © 2007 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Carl Worth - * Adrian Johnson - */ - -#ifndef CAIRO_PDF_OPERATORS_H -#define CAIRO_PDF_OPERATORS_H - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" -#include "cairo-types-private.h" - -/* The glyph buffer size is based on the expected maximum glyphs in a - * line so that an entire line can be emitted in as one string. If the - * glyphs in a line exceeds this size the only downside is the slight - * overhead of emitting two strings. - */ -#define PDF_GLYPH_BUFFER_SIZE 200 - -typedef cairo_int_status_t -(*cairo_pdf_operators_use_font_subset_t) (unsigned int font_id, - unsigned int subset_id, - void *closure); - -typedef struct _cairo_pdf_glyph { - unsigned int glyph_index; - double x_position; - double x_advance; -} cairo_pdf_glyph_t; - -typedef struct _cairo_pdf_operators { - cairo_output_stream_t *stream; - cairo_matrix_t cairo_to_pdf; - cairo_scaled_font_subsets_t *font_subsets; - cairo_pdf_operators_use_font_subset_t use_font_subset; - void *use_font_subset_closure; - cairo_bool_t ps_output; /* output is for PostScript */ - cairo_bool_t use_actual_text; - cairo_bool_t in_text_object; /* inside BT/ET pair */ - - /* PDF text state */ - cairo_bool_t is_new_text_object; /* text object started but matrix and font not yet selected */ - unsigned int font_id; - unsigned int subset_id; - cairo_matrix_t text_matrix; /* PDF text matrix (Tlm in the PDF reference) */ - cairo_matrix_t cairo_to_pdftext; /* translate cairo coords to PDF text space */ - cairo_matrix_t font_matrix_inverse; - double cur_x; /* Current position in PDF text space (Tm in the PDF reference) */ - double cur_y; - int hex_width; - cairo_bool_t is_latin; - int num_glyphs; - double glyph_buf_x_pos; - cairo_pdf_glyph_t glyphs[PDF_GLYPH_BUFFER_SIZE]; - - /* PDF line style */ - cairo_bool_t has_line_style; - double line_width; - cairo_line_cap_t line_cap; - cairo_line_join_t line_join; - double miter_limit; - cairo_bool_t has_dashes; -} cairo_pdf_operators_t; - -cairo_private void -_cairo_pdf_operators_init (cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream, - cairo_matrix_t *cairo_to_pdf, - cairo_scaled_font_subsets_t *font_subsets, - cairo_bool_t ps); - -cairo_private cairo_status_t -_cairo_pdf_operators_fini (cairo_pdf_operators_t *pdf_operators); - -cairo_private void -_cairo_pdf_operators_set_font_subsets_callback (cairo_pdf_operators_t *pdf_operators, - cairo_pdf_operators_use_font_subset_t use_font_subset, - void *closure); - -cairo_private void -_cairo_pdf_operators_set_stream (cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream); - - -cairo_private void -_cairo_pdf_operators_set_cairo_to_pdf_matrix (cairo_pdf_operators_t *pdf_operators, - cairo_matrix_t *cairo_to_pdf); - -cairo_private void -_cairo_pdf_operators_enable_actual_text (cairo_pdf_operators_t *pdf_operators, - cairo_bool_t enable); - -cairo_private cairo_status_t -_cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators); - -cairo_private void -_cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators); - -cairo_private cairo_int_status_t -_cairo_pdf_operators_clip (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_int_status_t -_cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t *pdf_operators, - const cairo_stroke_style_t *style, - double scale); - -cairo_private cairo_int_status_t -_cairo_pdf_operators_stroke (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse); - -cairo_private cairo_int_status_t -_cairo_pdf_operators_fill (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_int_status_t -_cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse); - -cairo_private cairo_int_status_t -_cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t *pdf_operators, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font); - -#endif /* CAIRO_PDF_OPERATORS_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators.c deleted file mode 100644 index dcee25f0c23..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-operators.c +++ /dev/null @@ -1,1560 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * Copyright © 2006 Red Hat, Inc - * Copyright © 2007, 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Carl Worth - * Adrian Johnson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_PDF_OPERATORS - -#include "cairo-error-private.h" -#include "cairo-pdf-operators-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-scaled-font-subsets-private.h" - -static cairo_status_t -_cairo_pdf_operators_end_text (cairo_pdf_operators_t *pdf_operators); - - -void -_cairo_pdf_operators_init (cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream, - cairo_matrix_t *cairo_to_pdf, - cairo_scaled_font_subsets_t *font_subsets, - cairo_bool_t ps) -{ - pdf_operators->stream = stream; - pdf_operators->cairo_to_pdf = *cairo_to_pdf; - pdf_operators->font_subsets = font_subsets; - pdf_operators->ps_output = ps; - pdf_operators->use_font_subset = NULL; - pdf_operators->use_font_subset_closure = NULL; - pdf_operators->in_text_object = FALSE; - pdf_operators->num_glyphs = 0; - pdf_operators->has_line_style = FALSE; - pdf_operators->use_actual_text = FALSE; -} - -cairo_status_t -_cairo_pdf_operators_fini (cairo_pdf_operators_t *pdf_operators) -{ - return _cairo_pdf_operators_flush (pdf_operators); -} - -void -_cairo_pdf_operators_set_font_subsets_callback (cairo_pdf_operators_t *pdf_operators, - cairo_pdf_operators_use_font_subset_t use_font_subset, - void *closure) -{ - pdf_operators->use_font_subset = use_font_subset; - pdf_operators->use_font_subset_closure = closure; -} - -/* Change the output stream to a different stream. - * _cairo_pdf_operators_flush() should always be called before calling - * this function. - */ -void -_cairo_pdf_operators_set_stream (cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream) -{ - pdf_operators->stream = stream; - pdf_operators->has_line_style = FALSE; -} - -void -_cairo_pdf_operators_set_cairo_to_pdf_matrix (cairo_pdf_operators_t *pdf_operators, - cairo_matrix_t *cairo_to_pdf) -{ - pdf_operators->cairo_to_pdf = *cairo_to_pdf; - pdf_operators->has_line_style = FALSE; -} - -cairo_private void -_cairo_pdf_operators_enable_actual_text (cairo_pdf_operators_t *pdf_operators, - cairo_bool_t enable) -{ - pdf_operators->use_actual_text = enable; -} - -/* Finish writing out any pending commands to the stream. This - * function must be called by the surface before emitting anything - * into the PDF stream. - * - * pdf_operators may leave the emitted PDF for some operations - * unfinished in case subsequent operations can be merged. This - * function will finish off any incomplete operation so the stream - * will be in a state where the surface may emit its own PDF - * operations (eg changing patterns). - * - */ -cairo_status_t -_cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - if (pdf_operators->in_text_object) - status = _cairo_pdf_operators_end_text (pdf_operators); - - return status; -} - -/* Reset the known graphics state of the PDF consumer. ie no - * assumptions will be made about the state. The next time a - * particular graphics state is required (eg line width) the state - * operator is always emitted and then remembered for subsequent - * operatations. - * - * This should be called when starting a new stream or after emitting - * the 'Q' operator (where pdf-operators functions were called inside - * the q/Q pair). - */ -void -_cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators) -{ - pdf_operators->has_line_style = FALSE; -} - -/* A word wrap stream can be used as a filter to do word wrapping on - * top of an existing output stream. The word wrapping is quite - * simple, using isspace to determine characters that separate - * words. Any word that will cause the column count exceed the given - * max_column will have a '\n' character emitted before it. - * - * The stream is careful to maintain integrity for words that cross - * the boundary from one call to write to the next. - * - * Note: This stream does not guarantee that the output will never - * exceed max_column. In particular, if a single word is larger than - * max_column it will not be broken up. - */ - -typedef enum _cairo_word_wrap_state { - WRAP_STATE_DELIMITER, - WRAP_STATE_WORD, - WRAP_STATE_STRING, - WRAP_STATE_HEXSTRING -} cairo_word_wrap_state_t; - - -typedef struct _word_wrap_stream { - cairo_output_stream_t base; - cairo_output_stream_t *output; - int max_column; - cairo_bool_t ps_output; - int column; - cairo_word_wrap_state_t state; - cairo_bool_t in_escape; - int escape_digits; -} word_wrap_stream_t; - - - -/* Emit word bytes up to the next delimiter character */ -static int -_word_wrap_stream_count_word_up_to (word_wrap_stream_t *stream, - const unsigned char *data, int length) -{ - const unsigned char *s = data; - int count = 0; - - while (length--) { - if (_cairo_isspace (*s) || *s == '<' || *s == '(') { - stream->state = WRAP_STATE_DELIMITER; - break; - } - - count++; - stream->column++; - s++; - } - - if (count) - _cairo_output_stream_write (stream->output, data, count); - - return count; -} - - -/* Emit hexstring bytes up to either the end of the ASCII hexstring or the number - * of columns remaining. - */ -static int -_word_wrap_stream_count_hexstring_up_to (word_wrap_stream_t *stream, - const unsigned char *data, int length) -{ - const unsigned char *s = data; - int count = 0; - cairo_bool_t newline = FALSE; - - while (length--) { - count++; - stream->column++; - if (*s == '>') { - stream->state = WRAP_STATE_DELIMITER; - break; - } - - if (stream->column > stream->max_column) { - newline = TRUE; - break; - } - s++; - } - - if (count) - _cairo_output_stream_write (stream->output, data, count); - - if (newline) { - _cairo_output_stream_printf (stream->output, "\n"); - stream->column = 0; - } - - return count; -} - -/* Count up to either the end of the string or the number of columns - * remaining. - */ -static int -_word_wrap_stream_count_string_up_to (word_wrap_stream_t *stream, - const unsigned char *data, int length) -{ - const unsigned char *s = data; - int count = 0; - cairo_bool_t newline = FALSE; - - while (length--) { - count++; - stream->column++; - if (!stream->in_escape) { - if (*s == ')') { - stream->state = WRAP_STATE_DELIMITER; - break; - } - if (*s == '\\') { - stream->in_escape = TRUE; - stream->escape_digits = 0; - } else if (stream->ps_output && stream->column > stream->max_column) { - newline = TRUE; - break; - } - } else { - if (!_cairo_isdigit(*s) || ++stream->escape_digits == 3) - stream->in_escape = FALSE; - } - s++; - } - - if (count) - _cairo_output_stream_write (stream->output, data, count); - - if (newline) { - _cairo_output_stream_printf (stream->output, "\\\n"); - stream->column = 0; - } - - return count; -} - -static cairo_status_t -_word_wrap_stream_write (cairo_output_stream_t *base, - const unsigned char *data, - unsigned int length) -{ - word_wrap_stream_t *stream = (word_wrap_stream_t *) base; - int count; - - while (length) { - switch (stream->state) { - case WRAP_STATE_WORD: - count = _word_wrap_stream_count_word_up_to (stream, data, length); - break; - case WRAP_STATE_HEXSTRING: - count = _word_wrap_stream_count_hexstring_up_to (stream, data, length); - break; - case WRAP_STATE_STRING: - count = _word_wrap_stream_count_string_up_to (stream, data, length); - break; - case WRAP_STATE_DELIMITER: - count = 1; - stream->column++; - if (*data == '\n' || stream->column >= stream->max_column) { - _cairo_output_stream_printf (stream->output, "\n"); - stream->column = 0; - } else if (*data == '<') { - stream->state = WRAP_STATE_HEXSTRING; - } else if (*data == '(') { - stream->state = WRAP_STATE_STRING; - } else if (!_cairo_isspace (*data)) { - stream->state = WRAP_STATE_WORD; - } - if (*data != '\n') - _cairo_output_stream_write (stream->output, data, 1); - break; - - default: - ASSERT_NOT_REACHED; - count = length; - break; - } - data += count; - length -= count; - } - - return _cairo_output_stream_get_status (stream->output); -} - -static cairo_status_t -_word_wrap_stream_close (cairo_output_stream_t *base) -{ - word_wrap_stream_t *stream = (word_wrap_stream_t *) base; - - return _cairo_output_stream_get_status (stream->output); -} - -static cairo_output_stream_t * -_word_wrap_stream_create (cairo_output_stream_t *output, cairo_bool_t ps, int max_column) -{ - word_wrap_stream_t *stream; - - if (output->status) - return _cairo_output_stream_create_in_error (output->status); - - stream = malloc (sizeof (word_wrap_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - _word_wrap_stream_write, - NULL, - _word_wrap_stream_close); - stream->output = output; - stream->max_column = max_column; - stream->ps_output = ps; - stream->column = 0; - stream->state = WRAP_STATE_DELIMITER; - stream->in_escape = FALSE; - stream->escape_digits = 0; - - return &stream->base; -} - -typedef struct _pdf_path_info { - cairo_output_stream_t *output; - cairo_matrix_t *path_transform; - cairo_line_cap_t line_cap; - cairo_point_t last_move_to_point; - cairo_bool_t has_sub_path; -} pdf_path_info_t; - -static cairo_status_t -_cairo_pdf_path_move_to (void *closure, - const cairo_point_t *point) -{ - pdf_path_info_t *info = closure; - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - info->last_move_to_point = *point; - info->has_sub_path = FALSE; - cairo_matrix_transform_point (info->path_transform, &x, &y); - _cairo_output_stream_printf (info->output, - "%g %g m ", x, y); - - return _cairo_output_stream_get_status (info->output); -} - -static cairo_status_t -_cairo_pdf_path_line_to (void *closure, - const cairo_point_t *point) -{ - pdf_path_info_t *info = closure; - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (info->line_cap != CAIRO_LINE_CAP_ROUND && - ! info->has_sub_path && - point->x == info->last_move_to_point.x && - point->y == info->last_move_to_point.y) - { - return CAIRO_STATUS_SUCCESS; - } - - info->has_sub_path = TRUE; - cairo_matrix_transform_point (info->path_transform, &x, &y); - _cairo_output_stream_printf (info->output, - "%g %g l ", x, y); - - return _cairo_output_stream_get_status (info->output); -} - -static cairo_status_t -_cairo_pdf_path_curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - pdf_path_info_t *info = closure; - double bx = _cairo_fixed_to_double (b->x); - double by = _cairo_fixed_to_double (b->y); - double cx = _cairo_fixed_to_double (c->x); - double cy = _cairo_fixed_to_double (c->y); - double dx = _cairo_fixed_to_double (d->x); - double dy = _cairo_fixed_to_double (d->y); - - info->has_sub_path = TRUE; - cairo_matrix_transform_point (info->path_transform, &bx, &by); - cairo_matrix_transform_point (info->path_transform, &cx, &cy); - cairo_matrix_transform_point (info->path_transform, &dx, &dy); - _cairo_output_stream_printf (info->output, - "%g %g %g %g %g %g c ", - bx, by, cx, cy, dx, dy); - return _cairo_output_stream_get_status (info->output); -} - -static cairo_status_t -_cairo_pdf_path_close_path (void *closure) -{ - pdf_path_info_t *info = closure; - - if (info->line_cap != CAIRO_LINE_CAP_ROUND && - ! info->has_sub_path) - { - return CAIRO_STATUS_SUCCESS; - } - - _cairo_output_stream_printf (info->output, - "h\n"); - - return _cairo_output_stream_get_status (info->output); -} - -static cairo_status_t -_cairo_pdf_path_rectangle (pdf_path_info_t *info, cairo_box_t *box) -{ - double x1 = _cairo_fixed_to_double (box->p1.x); - double y1 = _cairo_fixed_to_double (box->p1.y); - double x2 = _cairo_fixed_to_double (box->p2.x); - double y2 = _cairo_fixed_to_double (box->p2.y); - - cairo_matrix_transform_point (info->path_transform, &x1, &y1); - cairo_matrix_transform_point (info->path_transform, &x2, &y2); - _cairo_output_stream_printf (info->output, - "%g %g %g %g re ", - x1, y1, x2 - x1, y2 - y1); - - return _cairo_output_stream_get_status (info->output); -} - -/* The line cap value is needed to workaround the fact that PostScript - * and PDF semantics for stroking degenerate sub-paths do not match - * cairo semantics. (PostScript draws something for any line cap - * value, while cairo draws something only for round caps). - * - * When using this function to emit a path to be filled, rather than - * stroked, simply pass %CAIRO_LINE_CAP_ROUND which will guarantee that - * the stroke workaround will not modify the path being emitted. - */ -static cairo_status_t -_cairo_pdf_operators_emit_path (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t*path, - cairo_matrix_t *path_transform, - cairo_line_cap_t line_cap) -{ - cairo_output_stream_t *word_wrap; - cairo_status_t status, status2; - pdf_path_info_t info; - cairo_box_t box; - - word_wrap = _word_wrap_stream_create (pdf_operators->stream, pdf_operators->ps_output, 72); - status = _cairo_output_stream_get_status (word_wrap); - if (unlikely (status)) - return _cairo_output_stream_destroy (word_wrap); - - info.output = word_wrap; - info.path_transform = path_transform; - info.line_cap = line_cap; - if (_cairo_path_fixed_is_rectangle (path, &box) && - ((path_transform->xx == 0 && path_transform->yy == 0) || - (path_transform->xy == 0 && path_transform->yx == 0))) { - status = _cairo_pdf_path_rectangle (&info, &box); - } else { - status = _cairo_path_fixed_interpret (path, - _cairo_pdf_path_move_to, - _cairo_pdf_path_line_to, - _cairo_pdf_path_curve_to, - _cairo_pdf_path_close_path, - &info); - } - - status2 = _cairo_output_stream_destroy (word_wrap); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - return status; -} - -cairo_int_status_t -_cairo_pdf_operators_clip (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule) -{ - const char *pdf_operator; - cairo_status_t status; - - if (pdf_operators->in_text_object) { - status = _cairo_pdf_operators_end_text (pdf_operators); - if (unlikely (status)) - return status; - } - - if (! path->has_current_point) { - /* construct an empty path */ - _cairo_output_stream_printf (pdf_operators->stream, "0 0 m "); - } else { - status = _cairo_pdf_operators_emit_path (pdf_operators, - path, - &pdf_operators->cairo_to_pdf, - CAIRO_LINE_CAP_ROUND); - if (unlikely (status)) - return status; - } - - switch (fill_rule) { - default: - ASSERT_NOT_REACHED; - case CAIRO_FILL_RULE_WINDING: - pdf_operator = "W"; - break; - case CAIRO_FILL_RULE_EVEN_ODD: - pdf_operator = "W*"; - break; - } - - _cairo_output_stream_printf (pdf_operators->stream, - "%s n\n", - pdf_operator); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -static int -_cairo_pdf_line_cap (cairo_line_cap_t cap) -{ - switch (cap) { - case CAIRO_LINE_CAP_BUTT: - return 0; - case CAIRO_LINE_CAP_ROUND: - return 1; - case CAIRO_LINE_CAP_SQUARE: - return 2; - default: - ASSERT_NOT_REACHED; - return 0; - } -} - -static int -_cairo_pdf_line_join (cairo_line_join_t join) -{ - switch (join) { - case CAIRO_LINE_JOIN_MITER: - return 0; - case CAIRO_LINE_JOIN_ROUND: - return 1; - case CAIRO_LINE_JOIN_BEVEL: - return 2; - default: - ASSERT_NOT_REACHED; - return 0; - } -} - -cairo_int_status_t -_cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t *pdf_operators, - const cairo_stroke_style_t *style, - double scale) -{ - double *dash = style->dash; - int num_dashes = style->num_dashes; - double dash_offset = style->dash_offset; - double line_width = style->line_width * scale; - - /* PostScript has "special needs" when it comes to zero-length - * dash segments with butt caps. It apparently (at least - * according to ghostscript) draws hairlines for this - * case. That's not what the cairo semantics want, so we first - * touch up the array to eliminate any 0.0 values that will - * result in "on" segments. - */ - if (num_dashes && style->line_cap == CAIRO_LINE_CAP_BUTT) { - int i; - - /* If there's an odd number of dash values they will each get - * interpreted as both on and off. So we first explicitly - * expand the array to remove the duplicate usage so that we - * can modify some of the values. - */ - if (num_dashes % 2) { - dash = _cairo_malloc_abc (num_dashes, 2, sizeof (double)); - if (unlikely (dash == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (dash, style->dash, num_dashes * sizeof (double)); - memcpy (dash + num_dashes, style->dash, num_dashes * sizeof (double)); - - num_dashes *= 2; - } - - for (i = 0; i < num_dashes; i += 2) { - if (dash[i] == 0.0) { - /* Do not modify the dashes in-place, as we may need to also - * replay this stroke to an image fallback. - */ - if (dash == style->dash) { - dash = _cairo_malloc_ab (num_dashes, sizeof (double)); - if (unlikely (dash == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - memcpy (dash, style->dash, num_dashes * sizeof (double)); - } - - /* If we're at the front of the list, we first rotate - * two elements from the end of the list to the front - * of the list before folding away the 0.0. Or, if - * there are only two dash elements, then there is - * nothing at all to draw. - */ - if (i == 0) { - double last_two[2]; - - if (num_dashes == 2) { - free (dash); - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - /* The cases of num_dashes == 0, 1, or 3 elements - * cannot exist, so the rotation of 2 elements - * will always be safe */ - memcpy (last_two, dash + num_dashes - 2, sizeof (last_two)); - memmove (dash + 2, dash, (num_dashes - 2) * sizeof (double)); - memcpy (dash, last_two, sizeof (last_two)); - dash_offset += dash[0] + dash[1]; - i = 2; - } - dash[i-1] += dash[i+1]; - num_dashes -= 2; - memmove (dash + i, dash + i + 2, (num_dashes - i) * sizeof (double)); - /* If we might have just rotated, it's possible that - * we rotated a 0.0 value to the front of the list. - * Set i to -2 so it will get incremented to 0. */ - if (i == 2) - i = -2; - } - } - } - - if (!pdf_operators->has_line_style || pdf_operators->line_width != line_width) { - _cairo_output_stream_printf (pdf_operators->stream, - "%f w\n", - line_width); - pdf_operators->line_width = line_width; - } - - if (!pdf_operators->has_line_style || pdf_operators->line_cap != style->line_cap) { - _cairo_output_stream_printf (pdf_operators->stream, - "%d J\n", - _cairo_pdf_line_cap (style->line_cap)); - pdf_operators->line_cap = style->line_cap; - } - - if (!pdf_operators->has_line_style || pdf_operators->line_join != style->line_join) { - _cairo_output_stream_printf (pdf_operators->stream, - "%d j\n", - _cairo_pdf_line_join (style->line_join)); - pdf_operators->line_join = style->line_join; - } - - if (num_dashes) { - int d; - - _cairo_output_stream_printf (pdf_operators->stream, "["); - for (d = 0; d < num_dashes; d++) - _cairo_output_stream_printf (pdf_operators->stream, " %f", dash[d] * scale); - _cairo_output_stream_printf (pdf_operators->stream, "] %f d\n", - dash_offset * scale); - pdf_operators->has_dashes = TRUE; - } else if (!pdf_operators->has_line_style || pdf_operators->has_dashes) { - _cairo_output_stream_printf (pdf_operators->stream, "[] 0.0 d\n"); - pdf_operators->has_dashes = FALSE; - } - if (dash != style->dash) - free (dash); - - if (!pdf_operators->has_line_style || pdf_operators->miter_limit != style->miter_limit) { - _cairo_output_stream_printf (pdf_operators->stream, - "%f M ", - style->miter_limit < 1.0 ? 1.0 : style->miter_limit); - pdf_operators->miter_limit = style->miter_limit; - } - pdf_operators->has_line_style = TRUE; - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -/* Scale the matrix so the largest absolute value of the non - * translation components is 1.0. Return the scale required to restore - * the matrix to the original values. - * - * eg the matrix [ 100 0 0 50 20 10 ] - * - * is rescaled to [ 1 0 0 0.5 0.2 0.1 ] - * and the scale returned is 100 - */ -static void -_cairo_matrix_factor_out_scale (cairo_matrix_t *m, double *scale) -{ - double s; - - s = fabs (m->xx); - if (fabs (m->xy) > s) - s = fabs (m->xy); - if (fabs (m->yx) > s) - s = fabs (m->yx); - if (fabs (m->yy) > s) - s = fabs (m->yy); - *scale = s; - s = 1.0/s; - cairo_matrix_scale (m, s, s); -} - -static cairo_int_status_t -_cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - const char *pdf_operator) -{ - cairo_int_status_t status; - cairo_matrix_t m, path_transform; - cairo_bool_t has_ctm = TRUE; - double scale = 1.0; - - if (pdf_operators->in_text_object) { - status = _cairo_pdf_operators_end_text (pdf_operators); - if (unlikely (status)) - return status; - } - - /* Optimize away the stroke ctm when it does not affect the - * stroke. There are other ctm cases that could be optimized - * however this is the most common. - */ - if (fabs(ctm->xx) == 1.0 && fabs(ctm->yy) == 1.0 && - fabs(ctm->xy) == 0.0 && fabs(ctm->yx) == 0.0) - { - has_ctm = FALSE; - } - - /* The PDF CTM is transformed to the user space CTM when stroking - * so the corect pen shape will be used. This also requires that - * the path be transformed to user space when emitted. The - * conversion of path coordinates to user space may cause rounding - * errors. For example the device space point (1.234, 3.142) when - * transformed to a user space CTM of [100 0 0 100 0 0] will be - * emitted as (0.012, 0.031). - * - * To avoid the rounding problem we scale the user space CTM - * matrix so that all the non translation components of the matrix - * are <= 1. The line width and and dashes are scaled by the - * inverse of the scale applied to the CTM. This maintains the - * shape of the stroke pen while keeping the user space CTM within - * the range that maximizes the precision of the emitted path. - */ - if (has_ctm) { - m = *ctm; - /* Zero out the translation since it does not affect the pen - * shape however it may cause unnecessary digits to be emitted. - */ - m.x0 = 0.0; - m.y0 = 0.0; - _cairo_matrix_factor_out_scale (&m, &scale); - path_transform = m; - status = cairo_matrix_invert (&path_transform); - if (unlikely (status)) - return status; - - cairo_matrix_multiply (&m, &m, &pdf_operators->cairo_to_pdf); - } - - status = _cairo_pdf_operators_emit_stroke_style (pdf_operators, style, scale); - if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) - return CAIRO_STATUS_SUCCESS; - if (unlikely (status)) - return status; - - if (has_ctm) { - _cairo_output_stream_printf (pdf_operators->stream, "q "); - _cairo_output_stream_print_matrix (pdf_operators->stream, &m); - _cairo_output_stream_printf (pdf_operators->stream, " cm\n"); - } else { - path_transform = pdf_operators->cairo_to_pdf; - } - - status = _cairo_pdf_operators_emit_path (pdf_operators, - path, - &path_transform, - style->line_cap); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (pdf_operators->stream, "%s", pdf_operator); - if (has_ctm) - _cairo_output_stream_printf (pdf_operators->stream, " Q"); - - _cairo_output_stream_printf (pdf_operators->stream, "\n"); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -cairo_int_status_t -_cairo_pdf_operators_stroke (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse) -{ - return _cairo_pdf_operators_emit_stroke (pdf_operators, - path, - style, - ctm, - ctm_inverse, - "S"); -} - -cairo_int_status_t -_cairo_pdf_operators_fill (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule) -{ - const char *pdf_operator; - cairo_status_t status; - - if (pdf_operators->in_text_object) { - status = _cairo_pdf_operators_end_text (pdf_operators); - if (unlikely (status)) - return status; - } - - status = _cairo_pdf_operators_emit_path (pdf_operators, - path, - &pdf_operators->cairo_to_pdf, - CAIRO_LINE_CAP_ROUND); - if (unlikely (status)) - return status; - - switch (fill_rule) { - default: - ASSERT_NOT_REACHED; - case CAIRO_FILL_RULE_WINDING: - pdf_operator = "f"; - break; - case CAIRO_FILL_RULE_EVEN_ODD: - pdf_operator = "f*"; - break; - } - - _cairo_output_stream_printf (pdf_operators->stream, - "%s\n", - pdf_operator); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -cairo_int_status_t -_cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t *pdf_operators, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse) -{ - const char *operator; - - switch (fill_rule) { - default: - ASSERT_NOT_REACHED; - case CAIRO_FILL_RULE_WINDING: - operator = "B"; - break; - case CAIRO_FILL_RULE_EVEN_ODD: - operator = "B*"; - break; - } - - return _cairo_pdf_operators_emit_stroke (pdf_operators, - path, - style, - ctm, - ctm_inverse, - operator); -} - -static void -_cairo_pdf_operators_emit_glyph_index (cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream, - unsigned int glyph) -{ - if (pdf_operators->is_latin) { - if (glyph == '(' || glyph == ')' || glyph == '\\') - _cairo_output_stream_printf (stream, "\\%c", glyph); - else if (glyph >= 0x20 && glyph <= 0x7e) - _cairo_output_stream_printf (stream, "%c", glyph); - else - _cairo_output_stream_printf (stream, "\\%03o", glyph); - } else { - _cairo_output_stream_printf (stream, - "%0*x", - pdf_operators->hex_width, - glyph); - } -} - -#define GLYPH_POSITION_TOLERANCE 0.001 - -/* Emit the string of glyphs using the 'Tj' operator. This requires - * that the glyphs are positioned at their natural glyph advances. */ -static cairo_status_t -_cairo_pdf_operators_emit_glyph_string (cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream) -{ - int i; - - _cairo_output_stream_printf (stream, "%s", pdf_operators->is_latin ? "(" : "<"); - for (i = 0; i < pdf_operators->num_glyphs; i++) { - _cairo_pdf_operators_emit_glyph_index (pdf_operators, - stream, - pdf_operators->glyphs[i].glyph_index); - pdf_operators->cur_x += pdf_operators->glyphs[i].x_advance; - } - _cairo_output_stream_printf (stream, "%sTj\n", pdf_operators->is_latin ? ")" : ">"); - - return _cairo_output_stream_get_status (stream); -} - -/* Emit the string of glyphs using the 'TJ' operator. - * - * The TJ operator takes an array of strings of glyphs. Each string of - * glyphs is displayed using the glyph advances of each glyph to - * position the glyphs. A relative adjustment to the glyph advance may - * be specified by including the adjustment between two strings. The - * adjustment is in units of text space * -1000. - */ -static cairo_status_t -_cairo_pdf_operators_emit_glyph_string_with_positioning ( - cairo_pdf_operators_t *pdf_operators, - cairo_output_stream_t *stream) -{ - int i; - - _cairo_output_stream_printf (stream, "[%s", pdf_operators->is_latin ? "(" : "<"); - for (i = 0; i < pdf_operators->num_glyphs; i++) { - if (pdf_operators->glyphs[i].x_position != pdf_operators->cur_x) - { - double delta = pdf_operators->glyphs[i].x_position - pdf_operators->cur_x; - int rounded_delta; - - delta = -1000.0*delta; - /* As the delta is in 1/1000 of a unit of text space, - * rounding to an integer should still provide sufficient - * precision. We round the delta before adding to Tm_x so - * that we keep track of the accumulated rounding error in - * the PDF interpreter and compensate for it when - * calculating subsequent deltas. - */ - rounded_delta = _cairo_lround (delta); - if (abs(rounded_delta) < 3) - rounded_delta = 0; - if (rounded_delta != 0) { - if (pdf_operators->is_latin) { - _cairo_output_stream_printf (stream, - ")%d(", - rounded_delta); - } else { - _cairo_output_stream_printf (stream, - ">%d<", - rounded_delta); - } - } - - /* Convert the rounded delta back to text - * space before adding to the current text - * position. */ - delta = rounded_delta/-1000.0; - pdf_operators->cur_x += delta; - } - - _cairo_pdf_operators_emit_glyph_index (pdf_operators, - stream, - pdf_operators->glyphs[i].glyph_index); - pdf_operators->cur_x += pdf_operators->glyphs[i].x_advance; - } - _cairo_output_stream_printf (stream, "%s]TJ\n", pdf_operators->is_latin ? ")" : ">"); - - return _cairo_output_stream_get_status (stream); -} - -static cairo_status_t -_cairo_pdf_operators_flush_glyphs (cairo_pdf_operators_t *pdf_operators) -{ - cairo_output_stream_t *word_wrap_stream; - cairo_status_t status, status2; - int i; - double x; - - if (pdf_operators->num_glyphs == 0) - return CAIRO_STATUS_SUCCESS; - - word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, pdf_operators->ps_output, 72); - status = _cairo_output_stream_get_status (word_wrap_stream); - if (unlikely (status)) - return _cairo_output_stream_destroy (word_wrap_stream); - - /* Check if glyph advance used to position every glyph */ - x = pdf_operators->cur_x; - for (i = 0; i < pdf_operators->num_glyphs; i++) { - if (fabs(pdf_operators->glyphs[i].x_position - x) > GLYPH_POSITION_TOLERANCE) - break; - x += pdf_operators->glyphs[i].x_advance; - } - if (i == pdf_operators->num_glyphs) { - status = _cairo_pdf_operators_emit_glyph_string (pdf_operators, - word_wrap_stream); - } else { - status = _cairo_pdf_operators_emit_glyph_string_with_positioning ( - pdf_operators, word_wrap_stream); - } - - pdf_operators->num_glyphs = 0; - pdf_operators->glyph_buf_x_pos = pdf_operators->cur_x; - status2 = _cairo_output_stream_destroy (word_wrap_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - return status; -} - -static cairo_status_t -_cairo_pdf_operators_add_glyph (cairo_pdf_operators_t *pdf_operators, - cairo_scaled_font_subsets_glyph_t *glyph, - double x_position) -{ - double x, y; - - x = glyph->x_advance; - y = glyph->y_advance; - if (glyph->is_scaled) - cairo_matrix_transform_distance (&pdf_operators->font_matrix_inverse, &x, &y); - - pdf_operators->glyphs[pdf_operators->num_glyphs].x_position = x_position; - pdf_operators->glyphs[pdf_operators->num_glyphs].glyph_index = glyph->subset_glyph_index; - pdf_operators->glyphs[pdf_operators->num_glyphs].x_advance = x; - pdf_operators->glyph_buf_x_pos += x; - pdf_operators->num_glyphs++; - if (pdf_operators->num_glyphs == PDF_GLYPH_BUFFER_SIZE) - return _cairo_pdf_operators_flush_glyphs (pdf_operators); - - return CAIRO_STATUS_SUCCESS; -} - -/* Use 'Tm' operator to set the PDF text matrix. */ -static cairo_status_t -_cairo_pdf_operators_set_text_matrix (cairo_pdf_operators_t *pdf_operators, - cairo_matrix_t *matrix) -{ - cairo_matrix_t inverse; - cairo_status_t status; - - /* We require the matrix to be invertable. */ - inverse = *matrix; - status = cairo_matrix_invert (&inverse); - if (unlikely (status)) - return status; - - pdf_operators->text_matrix = *matrix; - pdf_operators->cur_x = 0; - pdf_operators->cur_y = 0; - pdf_operators->glyph_buf_x_pos = 0; - _cairo_output_stream_print_matrix (pdf_operators->stream, &pdf_operators->text_matrix); - _cairo_output_stream_printf (pdf_operators->stream, " Tm\n"); - - pdf_operators->cairo_to_pdftext = *matrix; - status = cairo_matrix_invert (&pdf_operators->cairo_to_pdftext); - assert (status == CAIRO_STATUS_SUCCESS); - cairo_matrix_multiply (&pdf_operators->cairo_to_pdftext, - &pdf_operators->cairo_to_pdf, - &pdf_operators->cairo_to_pdftext); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -#define TEXT_MATRIX_TOLERANCE 1e-6 - -/* Set the translation components of the PDF text matrix to x, y. The - * 'Td' operator is used to transform the text matrix. - */ -static cairo_status_t -_cairo_pdf_operators_set_text_position (cairo_pdf_operators_t *pdf_operators, - double x, - double y) -{ - cairo_matrix_t translate, inverse; - cairo_status_t status; - - /* The Td operator transforms the text_matrix with: - * - * text_matrix' = T x text_matrix - * - * where T is a translation matrix with the translation components - * set to the Td operands tx and ty. - */ - inverse = pdf_operators->text_matrix; - status = cairo_matrix_invert (&inverse); - assert (status == CAIRO_STATUS_SUCCESS); - pdf_operators->text_matrix.x0 = x; - pdf_operators->text_matrix.y0 = y; - cairo_matrix_multiply (&translate, &pdf_operators->text_matrix, &inverse); - if (fabs(translate.x0) < TEXT_MATRIX_TOLERANCE) - translate.x0 = 0.0; - if (fabs(translate.y0) < TEXT_MATRIX_TOLERANCE) - translate.y0 = 0.0; - _cairo_output_stream_printf (pdf_operators->stream, - "%f %f Td\n", - translate.x0, - translate.y0); - pdf_operators->cur_x = 0; - pdf_operators->cur_y = 0; - pdf_operators->glyph_buf_x_pos = 0; - - pdf_operators->cairo_to_pdftext = pdf_operators->text_matrix; - status = cairo_matrix_invert (&pdf_operators->cairo_to_pdftext); - assert (status == CAIRO_STATUS_SUCCESS); - cairo_matrix_multiply (&pdf_operators->cairo_to_pdftext, - &pdf_operators->cairo_to_pdf, - &pdf_operators->cairo_to_pdftext); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -/* Select the font using the 'Tf' operator. The font size is set to 1 - * as we use the 'Tm' operator to set the font scale. - */ -static cairo_status_t -_cairo_pdf_operators_set_font_subset (cairo_pdf_operators_t *pdf_operators, - cairo_scaled_font_subsets_glyph_t *subset_glyph) -{ - cairo_status_t status; - - _cairo_output_stream_printf (pdf_operators->stream, - "/f-%d-%d 1 Tf\n", - subset_glyph->font_id, - subset_glyph->subset_id); - if (pdf_operators->use_font_subset) { - status = pdf_operators->use_font_subset (subset_glyph->font_id, - subset_glyph->subset_id, - pdf_operators->use_font_subset_closure); - if (unlikely (status)) - return status; - } - pdf_operators->font_id = subset_glyph->font_id; - pdf_operators->subset_id = subset_glyph->subset_id; - pdf_operators->is_latin = subset_glyph->is_latin; - - if (subset_glyph->is_composite) - pdf_operators->hex_width = 4; - else - pdf_operators->hex_width = 2; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_pdf_operators_begin_text (cairo_pdf_operators_t *pdf_operators) -{ - _cairo_output_stream_printf (pdf_operators->stream, "BT\n"); - - pdf_operators->in_text_object = TRUE; - pdf_operators->num_glyphs = 0; - pdf_operators->glyph_buf_x_pos = 0; - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -static cairo_status_t -_cairo_pdf_operators_end_text (cairo_pdf_operators_t *pdf_operators) -{ - cairo_status_t status; - - status = _cairo_pdf_operators_flush_glyphs (pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (pdf_operators->stream, "ET\n"); - - pdf_operators->in_text_object = FALSE; - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -/* Compare the scale components of two matrices. The translation - * components are ignored. */ -static cairo_bool_t -_cairo_matrix_scale_equal (cairo_matrix_t *a, cairo_matrix_t *b) -{ - return (a->xx == b->xx && - a->xy == b->xy && - a->yx == b->yx && - a->yy == b->yy); -} - -static cairo_status_t -_cairo_pdf_operators_begin_actualtext (cairo_pdf_operators_t *pdf_operators, - const char *utf8, - int utf8_len) -{ - uint16_t *utf16; - int utf16_len; - cairo_status_t status; - int i; - - _cairo_output_stream_printf (pdf_operators->stream, "/Span << /ActualText stream, - "%04x", (int) (utf16[i])); - } - free (utf16); - } - _cairo_output_stream_printf (pdf_operators->stream, "> >> BDC\n"); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -static cairo_status_t -_cairo_pdf_operators_end_actualtext (cairo_pdf_operators_t *pdf_operators) -{ - _cairo_output_stream_printf (pdf_operators->stream, "EMC\n"); - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -static cairo_status_t -_cairo_pdf_operators_emit_glyph (cairo_pdf_operators_t *pdf_operators, - cairo_glyph_t *glyph, - cairo_scaled_font_subsets_glyph_t *subset_glyph) -{ - double x, y; - cairo_status_t status; - - if (pdf_operators->is_new_text_object || - pdf_operators->font_id != subset_glyph->font_id || - pdf_operators->subset_id != subset_glyph->subset_id) - { - status = _cairo_pdf_operators_flush_glyphs (pdf_operators); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_set_font_subset (pdf_operators, subset_glyph); - if (unlikely (status)) - return status; - - pdf_operators->is_new_text_object = FALSE; - } - - x = glyph->x; - y = glyph->y; - cairo_matrix_transform_point (&pdf_operators->cairo_to_pdftext, &x, &y); - - /* The TJ operator for displaying text strings can only set - * the horizontal position of the glyphs. If the y position - * (in text space) changes, use the Td operator to change the - * current position to the next glyph. We also use the Td - * operator to move the current position if the horizontal - * position changes by more than 10 (in text space - * units). This is becauses the horizontal glyph positioning - * in the TJ operator is intended for kerning and there may be - * PDF consumers that do not handle very large position - * adjustments in TJ. - */ - if (fabs(x - pdf_operators->glyph_buf_x_pos) > 10 || - fabs(y - pdf_operators->cur_y) > GLYPH_POSITION_TOLERANCE) - { - status = _cairo_pdf_operators_flush_glyphs (pdf_operators); - if (unlikely (status)) - return status; - - x = glyph->x; - y = glyph->y; - cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &x, &y); - status = _cairo_pdf_operators_set_text_position (pdf_operators, x, y); - if (unlikely (status)) - return status; - - x = 0.0; - y = 0.0; - } - - status = _cairo_pdf_operators_add_glyph (pdf_operators, - subset_glyph, - x); - return status; -} - -/* A utf8_len of -1 indicates no unicode text. A utf8_len = 0 is an - * empty string. - */ -static cairo_int_status_t -_cairo_pdf_operators_emit_cluster (cairo_pdf_operators_t *pdf_operators, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font) -{ - cairo_scaled_font_subsets_glyph_t subset_glyph; - cairo_glyph_t *cur_glyph; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - int i; - - /* If the cluster maps 1 glyph to 1 or more unicode characters, we - * first try _map_glyph() with the unicode string to see if it can - * use toUnicode to map our glyph to the unicode. This will fail - * if the glyph is already mapped to a different unicode string. - * - * We also go through this path if no unicode mapping was - * supplied (utf8_len < 0). - * - * Mapping a glyph to a zero length unicode string requires the - * use of ActualText. - */ - if (num_glyphs == 1 && utf8_len != 0) { - status = _cairo_scaled_font_subsets_map_glyph (pdf_operators->font_subsets, - scaled_font, - glyphs->index, - utf8, - utf8_len, - &subset_glyph); - if (unlikely (status)) - return status; - - if (subset_glyph.utf8_is_mapped || utf8_len < 0) { - status = _cairo_pdf_operators_emit_glyph (pdf_operators, - glyphs, - &subset_glyph); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; - } - } - - if (pdf_operators->use_actual_text) { - /* Fallback to using ActualText to map zero or more glyphs to a - * unicode string. */ - status = _cairo_pdf_operators_flush_glyphs (pdf_operators); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_begin_actualtext (pdf_operators, utf8, utf8_len); - if (unlikely (status)) - return status; - } - - if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) - cur_glyph = glyphs + num_glyphs - 1; - else - cur_glyph = glyphs; - - /* XXX - * If no glyphs, we should put *something* here for the text to be selectable. */ - for (i = 0; i < num_glyphs; i++) { - status = _cairo_scaled_font_subsets_map_glyph (pdf_operators->font_subsets, - scaled_font, - cur_glyph->index, - NULL, -1, - &subset_glyph); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_emit_glyph (pdf_operators, - cur_glyph, - &subset_glyph); - if (unlikely (status)) - return status; - - if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) - cur_glyph--; - else - cur_glyph++; - } - - if (pdf_operators->use_actual_text) { - status = _cairo_pdf_operators_flush_glyphs (pdf_operators); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_end_actualtext (pdf_operators); - } - - return status; -} - -cairo_int_status_t -_cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t *pdf_operators, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font) -{ - cairo_status_t status; - int i; - cairo_matrix_t text_matrix, invert_y_axis; - double x, y; - const char *cur_text; - cairo_glyph_t *cur_glyph; - - pdf_operators->font_matrix_inverse = scaled_font->font_matrix; - status = cairo_matrix_invert (&pdf_operators->font_matrix_inverse); - if (status == CAIRO_STATUS_INVALID_MATRIX) - return CAIRO_STATUS_SUCCESS; - assert (status == CAIRO_STATUS_SUCCESS); - - pdf_operators->is_new_text_object = FALSE; - if (pdf_operators->in_text_object == FALSE) { - status = _cairo_pdf_operators_begin_text (pdf_operators); - if (unlikely (status)) - return status; - - /* Force Tm and Tf to be emitted when starting a new text - * object.*/ - pdf_operators->is_new_text_object = TRUE; - } - - cairo_matrix_init_scale (&invert_y_axis, 1, -1); - text_matrix = scaled_font->scale; - - /* Invert y axis in font space */ - cairo_matrix_multiply (&text_matrix, &text_matrix, &invert_y_axis); - - /* Invert y axis in device space */ - cairo_matrix_multiply (&text_matrix, &invert_y_axis, &text_matrix); - - if (pdf_operators->is_new_text_object || - ! _cairo_matrix_scale_equal (&pdf_operators->text_matrix, &text_matrix)) - { - status = _cairo_pdf_operators_flush_glyphs (pdf_operators); - if (unlikely (status)) - return status; - - x = glyphs[0].x; - y = glyphs[0].y; - cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &x, &y); - text_matrix.x0 = x; - text_matrix.y0 = y; - status = _cairo_pdf_operators_set_text_matrix (pdf_operators, &text_matrix); - if (status == CAIRO_STATUS_INVALID_MATRIX) - return CAIRO_STATUS_SUCCESS; - if (unlikely (status)) - return status; - } - - if (num_clusters > 0) { - cur_text = utf8; - if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) - cur_glyph = glyphs + num_glyphs; - else - cur_glyph = glyphs; - for (i = 0; i < num_clusters; i++) { - if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) - cur_glyph -= clusters[i].num_glyphs; - status = _cairo_pdf_operators_emit_cluster (pdf_operators, - cur_text, - clusters[i].num_bytes, - cur_glyph, - clusters[i].num_glyphs, - cluster_flags, - scaled_font); - if (unlikely (status)) - return status; - - cur_text += clusters[i].num_bytes; - if (!(cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) - cur_glyph += clusters[i].num_glyphs; - } - } else { - for (i = 0; i < num_glyphs; i++) { - status = _cairo_pdf_operators_emit_cluster (pdf_operators, - NULL, - -1, /* no unicode string available */ - &glyphs[i], - 1, - FALSE, - scaled_font); - if (unlikely (status)) - return status; - } - } - - return _cairo_output_stream_get_status (pdf_operators->stream); -} - -#endif /* CAIRO_HAS_PDF_OPERATORS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading-private.h deleted file mode 100644 index 0ca8cb7d518..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading-private.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - */ - -#ifndef CAIRO_PDF_SHADING_H -#define CAIRO_PDF_SHADING_H - -#include "cairo-compiler-private.h" -#include "cairo-types-private.h" -#include "cairo-pattern-private.h" - - -typedef struct _cairo_pdf_shading { - int shading_type; - int bits_per_coordinate; - int bits_per_component; - int bits_per_flag; - double *decode_array; - int decode_array_length; - unsigned char *data; - unsigned long data_length; -} cairo_pdf_shading_t; - - -/** - * _cairo_pdf_shading_init_color: - * @shading: a #cairo_pdf_shading_t to initialize - * @pattern: the #cairo_mesh_pattern_t to initialize from - * - * Generate the PDF shading dictionary data for the a PDF type 7 - * shading from RGB part of the specified mesh pattern. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_pdf_shading_init_color (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *pattern); - - -/** - * _cairo_pdf_shading_init_alpha: - * @shading: a #cairo_pdf_shading_t to initialize - * @pattern: the #cairo_mesh_pattern_t to initialize from - * - * Generate the PDF shading dictionary data for a PDF type 7 - * shading from alpha part of the specified mesh pattern. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_pdf_shading_init_alpha (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *pattern); - -/** - * _cairo_pdf_shading_fini: - * @shading: a #cairo_pdf_shading_t - * - * Free all resources associated with @shading. After this call, - * @shading should not be used again without a subsequent call to - * _cairo_pdf_shading_init() again first. - **/ -cairo_private void -_cairo_pdf_shading_fini (cairo_pdf_shading_t *shading); - - -#endif /* CAIRO_PDF_SHADING_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading.c deleted file mode 100644 index 646e2cd4902..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-shading.c +++ /dev/null @@ -1,279 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_PDF_OPERATORS - -#include "cairo-pdf-shading-private.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" -#include - -static unsigned char * -encode_coordinate (unsigned char *p, double c) -{ - uint32_t f; - - f = c; - *p++ = f >> 24; - *p++ = (f >> 16) & 0xff; - *p++ = (f >> 8) & 0xff; - *p++ = f & 0xff; - - return p; -} - -static unsigned char * -encode_point (unsigned char *p, const cairo_point_double_t *point) -{ - p = encode_coordinate (p, point->x); - p = encode_coordinate (p, point->y); - - return p; -} - -static unsigned char * -encode_color_component (unsigned char *p, double color) -{ - uint16_t c; - - c = _cairo_color_double_to_short (color); - *p++ = c >> 8; - *p++ = c & 0xff; - - return p; -} - -static unsigned char * -encode_color (unsigned char *p, const cairo_color_t *color) -{ - p = encode_color_component (p, color->red); - p = encode_color_component (p, color->green); - p = encode_color_component (p, color->blue); - - return p; -} - -static unsigned char * -encode_alpha (unsigned char *p, const cairo_color_t *color) -{ - p = encode_color_component (p, color->alpha); - - return p; -} - -static cairo_status_t -_cairo_pdf_shading_generate_decode_array (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *mesh, - cairo_bool_t is_alpha) -{ - unsigned int num_color_components, i; - cairo_bool_t is_valid; - - if (is_alpha) - num_color_components = 1; - else - num_color_components = 3; - - shading->decode_array_length = 4 + num_color_components * 2; - shading->decode_array = _cairo_malloc_ab (shading->decode_array_length, - sizeof (double)); - if (unlikely (shading->decode_array == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - is_valid = _cairo_mesh_pattern_coord_box (mesh, - &shading->decode_array[0], - &shading->decode_array[2], - &shading->decode_array[1], - &shading->decode_array[3]); - - assert (is_valid); - assert (shading->decode_array[1] - shading->decode_array[0] >= DBL_EPSILON); - assert (shading->decode_array[3] - shading->decode_array[2] >= DBL_EPSILON); - - for (i = 0; i < num_color_components; i++) { - shading->decode_array[4 + 2*i] = 0; - shading->decode_array[5 + 2*i] = 1; - } - - return CAIRO_STATUS_SUCCESS; -} - -/* The ISO32000 specification mandates this order for the points which - * define the patch. */ -static const int pdf_points_order_i[16] = { - 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2 }; -static const int pdf_points_order_j[16] = { - 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1 }; - -static cairo_status_t -_cairo_pdf_shading_generate_data (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *mesh, - cairo_bool_t is_alpha) -{ - const cairo_mesh_patch_t *patch; - double x_off, y_off, x_scale, y_scale; - unsigned int num_patches; - unsigned int num_color_components; - unsigned char *p; - unsigned int i, j; - - if (is_alpha) - num_color_components = 1; - else - num_color_components = 3; - - num_patches = _cairo_array_num_elements (&mesh->patches); - patch = _cairo_array_index_const (&mesh->patches, 0); - - /* Each patch requires: - * - * 1 flag - 1 byte - * 16 points. Each point is 2 coordinates. Each coordinate is - * stored in 4 bytes. - * - * 4 colors. Each color is stored in 2 bytes * num_color_components. - */ - shading->data_length = num_patches * (1 + 16 * 2 * 4 + 4 * 2 * num_color_components); - shading->data = malloc (shading->data_length); - if (unlikely (shading->data == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - x_off = shading->decode_array[0]; - y_off = shading->decode_array[2]; - x_scale = UINT32_MAX / (shading->decode_array[1] - x_off); - y_scale = UINT32_MAX / (shading->decode_array[3] - y_off); - - p = shading->data; - for (i = 0; i < num_patches; i++) { - /* edge flag */ - *p++ = 0; - - /* 16 points */ - for (j = 0; j < 16; j++) { - cairo_point_double_t point; - int pi, pj; - - pi = pdf_points_order_i[j]; - pj = pdf_points_order_j[j]; - point = patch[i].points[pi][pj]; - - /* Transform the point as specified in the decode array */ - point.x -= x_off; - point.y -= y_off; - point.x *= x_scale; - point.y *= y_scale; - - /* Make sure that rounding errors don't cause - * wraparounds */ - point.x = _cairo_restrict_value (point.x, 0, UINT32_MAX); - point.y = _cairo_restrict_value (point.y, 0, UINT32_MAX); - - p = encode_point (p, &point); - } - - /* 4 colors */ - for (j = 0; j < 4; j++) { - if (is_alpha) - p = encode_alpha (p, &patch[i].colors[j]); - else - p = encode_color (p, &patch[i].colors[j]); - } - } - - assert (p == shading->data + shading->data_length); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_pdf_shading_init (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *mesh, - cairo_bool_t is_alpha) -{ - cairo_status_t status; - - assert (mesh->base.status == CAIRO_STATUS_SUCCESS); - assert (mesh->current_patch == NULL); - - shading->shading_type = 7; - - /* - * Coordinates from the minimum to the maximum value of the mesh - * map to the [0..UINT32_MAX] range and are represented as - * uint32_t values. - * - * Color components are represented as uint16_t (in a 0.16 fixed - * point format, as in the rest of cairo). - */ - shading->bits_per_coordinate = 32; - shading->bits_per_component = 16; - shading->bits_per_flag = 8; - - shading->decode_array = NULL; - shading->data = NULL; - - status = _cairo_pdf_shading_generate_decode_array (shading, mesh, is_alpha); - if (unlikely (status)) - return status; - - return _cairo_pdf_shading_generate_data (shading, mesh, is_alpha); -} - -cairo_status_t -_cairo_pdf_shading_init_color (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *pattern) -{ - return _cairo_pdf_shading_init (shading, pattern, FALSE); -} - -cairo_status_t -_cairo_pdf_shading_init_alpha (cairo_pdf_shading_t *shading, - const cairo_mesh_pattern_t *pattern) -{ - return _cairo_pdf_shading_init (shading, pattern, TRUE); -} - -void -_cairo_pdf_shading_fini (cairo_pdf_shading_t *shading) -{ - free (shading->data); - free (shading->decode_array); -} - -#endif /* CAIRO_HAS_PDF_OPERATORS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface-private.h deleted file mode 100644 index 618ca4ede9f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface-private.h +++ /dev/null @@ -1,218 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * Copyright © 2006 Red Hat, Inc - * Copyright © 2007, 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Carl Worth - * Adrian Johnson - */ - -#ifndef CAIRO_PDF_SURFACE_PRIVATE_H -#define CAIRO_PDF_SURFACE_PRIVATE_H - -#include "cairo-pdf.h" - -#include "cairo-surface-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-pdf-operators-private.h" -#include "cairo-path-fixed-private.h" - -typedef struct _cairo_pdf_resource { - unsigned int id; -} cairo_pdf_resource_t; - -#define CAIRO_NUM_OPERATORS (CAIRO_OPERATOR_HSL_LUMINOSITY + 1) - -typedef struct _cairo_pdf_group_resources { - cairo_bool_t operators[CAIRO_NUM_OPERATORS]; - cairo_array_t alphas; - cairo_array_t smasks; - cairo_array_t patterns; - cairo_array_t shadings; - cairo_array_t xobjects; - cairo_array_t fonts; -} cairo_pdf_group_resources_t; - -typedef struct _cairo_pdf_source_surface_entry { - cairo_hash_entry_t base; - unsigned int id; - unsigned char *unique_id; - unsigned long unique_id_length; - cairo_operator_t operator; - cairo_bool_t interpolate; - cairo_bool_t stencil_mask; - cairo_bool_t smask; - cairo_pdf_resource_t surface_res; - cairo_pdf_resource_t smask_res; - int width; - int height; - cairo_rectangle_int_t extents; -} cairo_pdf_source_surface_entry_t; - -typedef struct _cairo_pdf_source_surface { - cairo_pattern_type_t type; - cairo_surface_t *surface; - cairo_pattern_t *raster_pattern; - cairo_pdf_source_surface_entry_t *hash_entry; -} cairo_pdf_source_surface_t; - -typedef struct _cairo_pdf_pattern { - double width; - double height; - cairo_rectangle_int_t extents; - cairo_pattern_t *pattern; - cairo_pdf_resource_t pattern_res; - cairo_pdf_resource_t gstate_res; - cairo_operator_t operator; - cairo_bool_t is_shading; -} cairo_pdf_pattern_t; - -typedef enum _cairo_pdf_operation { - PDF_PAINT, - PDF_MASK, - PDF_FILL, - PDF_STROKE, - PDF_SHOW_GLYPHS -} cairo_pdf_operation_t; - -typedef struct _cairo_pdf_smask_group { - double width; - double height; - cairo_rectangle_int_t extents; - cairo_pdf_resource_t group_res; - cairo_pdf_operation_t operation; - cairo_pattern_t *source; - cairo_pdf_resource_t source_res; - cairo_pattern_t *mask; - cairo_path_fixed_t path; - cairo_fill_rule_t fill_rule; - cairo_stroke_style_t style; - cairo_matrix_t ctm; - cairo_matrix_t ctm_inverse; - char *utf8; - int utf8_len; - cairo_glyph_t *glyphs; - int num_glyphs; - cairo_text_cluster_t *clusters; - int num_clusters; - cairo_bool_t cluster_flags; - cairo_scaled_font_t *scaled_font; -} cairo_pdf_smask_group_t; - -typedef struct _cairo_pdf_jbig2_global { - unsigned char *id; - unsigned long id_length; - cairo_pdf_resource_t res; - cairo_bool_t emitted; -} cairo_pdf_jbig2_global_t; - -typedef struct _cairo_pdf_surface cairo_pdf_surface_t; - -struct _cairo_pdf_surface { - cairo_surface_t base; - - /* Prefer the name "output" here to avoid confusion over the - * structure within a PDF document known as a "stream". */ - cairo_output_stream_t *output; - - double width; - double height; - cairo_matrix_t cairo_to_pdf; - - cairo_array_t objects; - cairo_array_t pages; - cairo_array_t rgb_linear_functions; - cairo_array_t alpha_linear_functions; - cairo_array_t page_patterns; - cairo_array_t page_surfaces; - cairo_hash_table_t *all_surfaces; - cairo_array_t smask_groups; - cairo_array_t knockout_group; - cairo_array_t jbig2_global; - - cairo_scaled_font_subsets_t *font_subsets; - cairo_array_t fonts; - - cairo_pdf_resource_t next_available_resource; - cairo_pdf_resource_t pages_resource; - - cairo_pdf_version_t pdf_version; - cairo_bool_t compress_content; - - cairo_pdf_resource_t content; - cairo_pdf_resource_t content_resources; - cairo_pdf_group_resources_t resources; - cairo_bool_t has_fallback_images; - cairo_bool_t header_emitted; - - struct { - cairo_bool_t active; - cairo_pdf_resource_t self; - cairo_pdf_resource_t length; - long start_offset; - cairo_bool_t compressed; - cairo_output_stream_t *old_output; - } pdf_stream; - - struct { - cairo_bool_t active; - cairo_output_stream_t *stream; - cairo_output_stream_t *mem_stream; - cairo_output_stream_t *old_output; - cairo_pdf_resource_t resource; - cairo_box_double_t bbox; - cairo_bool_t is_knockout; - } group_stream; - - cairo_surface_clipper_t clipper; - - cairo_pdf_operators_t pdf_operators; - cairo_paginated_mode_t paginated_mode; - cairo_bool_t select_pattern_gstate_saved; - - cairo_bool_t force_fallbacks; - - cairo_operator_t current_operator; - cairo_bool_t current_pattern_is_solid_color; - cairo_bool_t current_color_is_stroke; - double current_color_red; - double current_color_green; - double current_color_blue; - double current_color_alpha; - - cairo_surface_t *paginated_surface; -}; - -#endif /* CAIRO_PDF_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface.c deleted file mode 100644 index fd52b0d3ed6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf-surface.c +++ /dev/null @@ -1,7880 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * Copyright © 2006 Red Hat, Inc - * Copyright © 2007, 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Carl Worth - * Adrian Johnson - */ - -#define _BSD_SOURCE /* for snprintf() */ -#include "cairoint.h" - -#include "cairo-pdf.h" -#include "cairo-pdf-surface-private.h" -#include "cairo-pdf-operators-private.h" -#include "cairo-pdf-shading-private.h" - -#include "cairo-array-private.h" -#include "cairo-analysis-surface-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-image-info-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-paginated-private.h" -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-private.h" -#include "cairo-type3-glyph-surface-private.h" - -#include -#include - -/* Issues: - * - * - We embed an image in the stream each time it's composited. We - * could add generation counters to surfaces and remember the stream - * ID for a particular generation for a particular surface. - * - * - Backend specific meta data. - */ - -/* - * Page Structure of the Generated PDF: - * - * Each page requiring fallbacks images contains a knockout group at - * the top level. The first operation of the knockout group paints a - * group containing all the supported drawing operations. Fallback - * images (if any) are painted in the knockout group. This ensures - * that fallback images do not composite with any content under the - * fallback images. - * - * Streams: - * - * This PDF surface has three types of streams: - * - PDF Stream - * - Content Stream - * - Group Stream - * - * Calling _cairo_output_stream_printf (surface->output, ...) will - * write to the currently open stream. - * - * PDF Stream: - * A PDF Stream may be opened and closed with the following functions: - * _cairo_pdf_surface_open stream () - * _cairo_pdf_surface_close_stream () - * - * PDF Streams are written directly to the PDF file. They are used for - * fonts, images and patterns. - * - * Content Stream: - * The Content Stream is opened and closed with the following functions: - * _cairo_pdf_surface_open_content_stream () - * _cairo_pdf_surface_close_content_stream () - * - * The Content Stream contains the text and graphics operators. - * - * Group Stream: - * A Group Stream may be opened and closed with the following functions: - * _cairo_pdf_surface_open_group () - * _cairo_pdf_surface_close_group () - * - * A Group Stream is a Form XObject. It is used for short sequences - * of operators. As the content is very short the group is stored in - * memory until it is closed. This allows some optimization such as - * including the Resource dictionary and stream length inside the - * XObject instead of using an indirect object. - */ - -/** - * SECTION:cairo-pdf - * @Title: PDF Surfaces - * @Short_Description: Rendering PDF documents - * @See_Also: #cairo_surface_t - * - * The PDF surface is used to render cairo graphics to Adobe - * PDF files and is a multi-page vector surface backend. - * - * The following mime types are supported: %CAIRO_MIME_TYPE_JPEG, - * %CAIRO_MIME_TYPE_JP2, %CAIRO_MIME_TYPE_UNIQUE_ID, - * %CAIRO_MIME_TYPE_JBIG2, %CAIRO_MIME_TYPE_JBIG2_GLOBAL, - * %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID. - * - * JBIG2 data in PDF must be in the embedded format as descibed in - * ISO/IEC 11544. Image specific JBIG2 data must be in - * %CAIRO_MIME_TYPE_JBIG2. Any global segments in the JBIG2 data - * (segments with page association field set to 0) must be in - * %CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data may be shared by - * multiple images. All images sharing the same global data must set - * %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID to a unique identifer. At least - * one of the images must provide the global data using - * %CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data will only be - * embedded once but shared by all JBIG2 images with the same - * %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID. - **/ - -static cairo_bool_t -_cairo_pdf_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle); - -/** - * CAIRO_HAS_PDF_SURFACE: - * - * Defined if the PDF surface backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.2 - **/ - -static const cairo_pdf_version_t _cairo_pdf_versions[] = -{ - CAIRO_PDF_VERSION_1_4, - CAIRO_PDF_VERSION_1_5 -}; - -#define CAIRO_PDF_VERSION_LAST ARRAY_LENGTH (_cairo_pdf_versions) - -static const char * _cairo_pdf_version_strings[CAIRO_PDF_VERSION_LAST] = -{ - "PDF 1.4", - "PDF 1.5" -}; - -static const char *_cairo_pdf_supported_mime_types[] = -{ - CAIRO_MIME_TYPE_JPEG, - CAIRO_MIME_TYPE_JP2, - CAIRO_MIME_TYPE_UNIQUE_ID, - CAIRO_MIME_TYPE_JBIG2, - CAIRO_MIME_TYPE_JBIG2_GLOBAL, - CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, - NULL -}; - -typedef struct _cairo_pdf_object { - long offset; -} cairo_pdf_object_t; - -typedef struct _cairo_pdf_font { - unsigned int font_id; - unsigned int subset_id; - cairo_pdf_resource_t subset_resource; -} cairo_pdf_font_t; - -typedef struct _cairo_pdf_rgb_linear_function { - cairo_pdf_resource_t resource; - double color1[3]; - double color2[3]; -} cairo_pdf_rgb_linear_function_t; - -typedef struct _cairo_pdf_alpha_linear_function { - cairo_pdf_resource_t resource; - double alpha1; - double alpha2; -} cairo_pdf_alpha_linear_function_t; - -static cairo_pdf_resource_t -_cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface); - -static void -_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface); - -static void -_cairo_pdf_smask_group_destroy (cairo_pdf_smask_group_t *group); - -static cairo_int_status_t -_cairo_pdf_surface_add_font (unsigned int font_id, - unsigned int subset_id, - void *closure); - -static void -_cairo_pdf_group_resources_init (cairo_pdf_group_resources_t *res); - -static cairo_int_status_t -_cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t *resource, - cairo_bool_t compressed, - const char *fmt, - ...) CAIRO_PRINTF_FORMAT(4, 5); -static cairo_int_status_t -_cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface); - -static cairo_int_status_t -_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface); - -static void -_cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface); - -static cairo_pdf_resource_t -_cairo_pdf_surface_write_info (cairo_pdf_surface_t *surface); - -static cairo_pdf_resource_t -_cairo_pdf_surface_write_catalog (cairo_pdf_surface_t *surface); - -static long -_cairo_pdf_surface_write_xref (cairo_pdf_surface_t *surface); - -static cairo_int_status_t -_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface); - -static cairo_int_status_t -_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface); - -static cairo_bool_t -_cairo_pdf_source_surface_equal (const void *key_a, const void *key_b); - -static const cairo_surface_backend_t cairo_pdf_surface_backend; -static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend; - -static cairo_pdf_resource_t -_cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface) -{ - cairo_pdf_resource_t resource; - cairo_int_status_t status; - cairo_pdf_object_t object; - - object.offset = _cairo_output_stream_get_position (surface->output); - - status = _cairo_array_append (&surface->objects, &object); - if (unlikely (status)) { - resource.id = 0; - return resource; - } - - resource = surface->next_available_resource; - surface->next_available_resource.id++; - - return resource; -} - -static void -_cairo_pdf_surface_update_object (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t resource) -{ - cairo_pdf_object_t *object; - - object = _cairo_array_index (&surface->objects, resource.id - 1); - object->offset = _cairo_output_stream_get_position (surface->output); -} - -static void -_cairo_pdf_surface_set_size_internal (cairo_pdf_surface_t *surface, - double width, - double height) -{ - surface->width = width; - surface->height = height; - cairo_matrix_init (&surface->cairo_to_pdf, 1, 0, 0, -1, 0, height); - _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, - &surface->cairo_to_pdf); -} - -static cairo_bool_t -_path_covers_bbox (cairo_pdf_surface_t *surface, - cairo_path_fixed_t *path) -{ - cairo_box_t box; - - return _cairo_path_fixed_is_box (path, &box) && - box.p1.x <= 0 && - box.p1.y <= 0 && - box.p2.x >= _cairo_fixed_from_double (surface->width) && - box.p2.y >= _cairo_fixed_from_double (surface->height); -} - -static cairo_status_t -_cairo_pdf_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_pdf_surface_t *surface = cairo_container_of (clipper, - cairo_pdf_surface_t, - clipper); - cairo_int_status_t status; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - if (path == NULL) { - _cairo_output_stream_printf (surface->output, "Q q\n"); - - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - - return CAIRO_STATUS_SUCCESS; - } - - if (_path_covers_bbox (surface, path)) - return CAIRO_STATUS_SUCCESS; - - return _cairo_pdf_operators_clip (&surface->pdf_operators, path, fill_rule); -} - -static cairo_surface_t * -_cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *output, - double width, - double height) -{ - cairo_pdf_surface_t *surface; - cairo_status_t status, status_ignored; - - surface = malloc (sizeof (cairo_pdf_surface_t)); - if (unlikely (surface == NULL)) { - /* destroy stream on behalf of caller */ - status = _cairo_output_stream_destroy (output); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - _cairo_surface_init (&surface->base, - &cairo_pdf_surface_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - surface->output = output; - surface->width = width; - surface->height = height; - cairo_matrix_init (&surface->cairo_to_pdf, 1, 0, 0, -1, 0, height); - - _cairo_array_init (&surface->objects, sizeof (cairo_pdf_object_t)); - _cairo_array_init (&surface->pages, sizeof (cairo_pdf_resource_t)); - _cairo_array_init (&surface->rgb_linear_functions, sizeof (cairo_pdf_rgb_linear_function_t)); - _cairo_array_init (&surface->alpha_linear_functions, sizeof (cairo_pdf_alpha_linear_function_t)); - _cairo_array_init (&surface->fonts, sizeof (cairo_pdf_font_t)); - _cairo_array_init (&surface->smask_groups, sizeof (cairo_pdf_smask_group_t *)); - _cairo_array_init (&surface->knockout_group, sizeof (cairo_pdf_resource_t)); - - _cairo_array_init (&surface->page_patterns, sizeof (cairo_pdf_pattern_t)); - _cairo_array_init (&surface->page_surfaces, sizeof (cairo_pdf_source_surface_t)); - _cairo_array_init (&surface->jbig2_global, sizeof (cairo_pdf_jbig2_global_t)); - surface->all_surfaces = _cairo_hash_table_create (_cairo_pdf_source_surface_equal); - if (unlikely (surface->all_surfaces == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL0; - } - - _cairo_pdf_group_resources_init (&surface->resources); - - surface->font_subsets = _cairo_scaled_font_subsets_create_composite (); - if (! surface->font_subsets) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL1; - } - - _cairo_scaled_font_subsets_enable_latin_subset (surface->font_subsets, TRUE); - - surface->next_available_resource.id = 1; - surface->pages_resource = _cairo_pdf_surface_new_object (surface); - if (surface->pages_resource.id == 0) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL2; - } - - surface->pdf_version = CAIRO_PDF_VERSION_1_5; - surface->compress_content = TRUE; - surface->pdf_stream.active = FALSE; - surface->pdf_stream.old_output = NULL; - surface->group_stream.active = FALSE; - surface->group_stream.stream = NULL; - surface->group_stream.mem_stream = NULL; - - surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE; - - surface->force_fallbacks = FALSE; - surface->select_pattern_gstate_saved = FALSE; - surface->current_pattern_is_solid_color = FALSE; - surface->current_operator = CAIRO_OPERATOR_OVER; - surface->header_emitted = FALSE; - - _cairo_surface_clipper_init (&surface->clipper, - _cairo_pdf_surface_clipper_intersect_clip_path); - - _cairo_pdf_operators_init (&surface->pdf_operators, - surface->output, - &surface->cairo_to_pdf, - surface->font_subsets, - FALSE); - _cairo_pdf_operators_set_font_subsets_callback (&surface->pdf_operators, - _cairo_pdf_surface_add_font, - surface); - _cairo_pdf_operators_enable_actual_text(&surface->pdf_operators, TRUE); - - surface->paginated_surface = _cairo_paginated_surface_create ( - &surface->base, - CAIRO_CONTENT_COLOR_ALPHA, - &cairo_pdf_surface_paginated_backend); - - status = surface->paginated_surface->status; - if (status == CAIRO_STATUS_SUCCESS) { - /* paginated keeps the only reference to surface now, drop ours */ - cairo_surface_destroy (&surface->base); - return surface->paginated_surface; - } - -BAIL2: - _cairo_scaled_font_subsets_destroy (surface->font_subsets); -BAIL1: - _cairo_hash_table_destroy (surface->all_surfaces); -BAIL0: - _cairo_array_fini (&surface->objects); - free (surface); - - /* destroy stream on behalf of caller */ - status_ignored = _cairo_output_stream_destroy (output); - - return _cairo_surface_create_in_error (status); -} - -/** - * cairo_pdf_surface_create_for_stream: - * @write_func: a #cairo_write_func_t to accept the output data, may be %NULL - * to indicate a no-op @write_func. With a no-op @write_func, - * the surface may be queried or used as a source without - * generating any temporary files. - * @closure: the closure argument for @write_func - * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) - * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) - * - * Creates a PDF surface of the specified size in points to be written - * incrementally to the stream represented by @write_func and @closure. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, - void *closure, - double width_in_points, - double height_in_points) -{ - cairo_output_stream_t *output; - - output = _cairo_output_stream_create (write_func, NULL, closure); - if (_cairo_output_stream_get_status (output)) - return _cairo_surface_create_in_error (_cairo_output_stream_destroy (output)); - - return _cairo_pdf_surface_create_for_stream_internal (output, - width_in_points, - height_in_points); -} - -/** - * cairo_pdf_surface_create: - * @filename: a filename for the PDF output (must be writable), %NULL may be - * used to specify no output. This will generate a PDF surface that - * may be queried and used as a source, without generating a - * temporary file. - * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) - * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) - * - * Creates a PDF surface of the specified size in points to be written - * to @filename. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_pdf_surface_create (const char *filename, - double width_in_points, - double height_in_points) -{ - cairo_output_stream_t *output; - - output = _cairo_output_stream_create_for_filename (filename); - if (_cairo_output_stream_get_status (output)) - return _cairo_surface_create_in_error (_cairo_output_stream_destroy (output)); - - return _cairo_pdf_surface_create_for_stream_internal (output, - width_in_points, - height_in_points); -} - -static cairo_bool_t -_cairo_surface_is_pdf (cairo_surface_t *surface) -{ - return surface->backend == &cairo_pdf_surface_backend; -} - -/* If the abstract_surface is a paginated surface, and that paginated - * surface's target is a pdf_surface, then set pdf_surface to that - * target. Otherwise return FALSE. - */ -static cairo_bool_t -_extract_pdf_surface (cairo_surface_t *surface, - cairo_pdf_surface_t **pdf_surface) -{ - cairo_surface_t *target; - cairo_status_t status_ignored; - - if (surface->status) - return FALSE; - if (surface->finished) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (! _cairo_surface_is_paginated (surface)) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return FALSE; - } - - target = _cairo_paginated_surface_get_target (surface); - if (target->status) { - status_ignored = _cairo_surface_set_error (surface, - target->status); - return FALSE; - } - if (target->finished) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (! _cairo_surface_is_pdf (target)) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return FALSE; - } - - *pdf_surface = (cairo_pdf_surface_t *) target; - return TRUE; -} - -/** - * cairo_pdf_surface_restrict_to_version: - * @surface: a PDF #cairo_surface_t - * @version: PDF version - * - * Restricts the generated PDF file to @version. See cairo_pdf_get_versions() - * for a list of available version values that can be used here. - * - * This function should only be called before any drawing operations - * have been performed on the given surface. The simplest way to do - * this is to call this function immediately after creating the - * surface. - * - * Since: 1.10 - **/ -void -cairo_pdf_surface_restrict_to_version (cairo_surface_t *abstract_surface, - cairo_pdf_version_t version) -{ - cairo_pdf_surface_t *surface = NULL; /* hide compiler warning */ - - if (! _extract_pdf_surface (abstract_surface, &surface)) - return; - - if (version < CAIRO_PDF_VERSION_LAST) - surface->pdf_version = version; - - _cairo_pdf_operators_enable_actual_text(&surface->pdf_operators, - version >= CAIRO_PDF_VERSION_1_5); -} - -/** - * cairo_pdf_get_versions: - * @versions: supported version list - * @num_versions: list length - * - * Used to retrieve the list of supported versions. See - * cairo_pdf_surface_restrict_to_version(). - * - * Since: 1.10 - **/ -void -cairo_pdf_get_versions (cairo_pdf_version_t const **versions, - int *num_versions) -{ - if (versions != NULL) - *versions = _cairo_pdf_versions; - - if (num_versions != NULL) - *num_versions = CAIRO_PDF_VERSION_LAST; -} - -/** - * cairo_pdf_version_to_string: - * @version: a version id - * - * Get the string representation of the given @version id. This function - * will return %NULL if @version isn't valid. See cairo_pdf_get_versions() - * for a way to get the list of valid version ids. - * - * Return value: the string associated to given version. - * - * Since: 1.10 - **/ -const char * -cairo_pdf_version_to_string (cairo_pdf_version_t version) -{ - if (version >= CAIRO_PDF_VERSION_LAST) - return NULL; - - return _cairo_pdf_version_strings[version]; -} - -/** - * cairo_pdf_surface_set_size: - * @surface: a PDF #cairo_surface_t - * @width_in_points: new surface width, in points (1 point == 1/72.0 inch) - * @height_in_points: new surface height, in points (1 point == 1/72.0 inch) - * - * Changes the size of a PDF surface for the current (and - * subsequent) pages. - * - * This function should only be called before any drawing operations - * have been performed on the current page. The simplest way to do - * this is to call this function immediately after creating the - * surface or immediately after completing a page with either - * cairo_show_page() or cairo_copy_page(). - * - * Since: 1.2 - **/ -void -cairo_pdf_surface_set_size (cairo_surface_t *surface, - double width_in_points, - double height_in_points) -{ - cairo_pdf_surface_t *pdf_surface = NULL; /* hide compiler warning */ - cairo_status_t status; - - if (! _extract_pdf_surface (surface, &pdf_surface)) - return; - - _cairo_pdf_surface_set_size_internal (pdf_surface, - width_in_points, - height_in_points); - status = _cairo_paginated_surface_set_size (pdf_surface->paginated_surface, - width_in_points, - height_in_points); - if (status) - status = _cairo_surface_set_error (surface, status); -} - -static void -_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface) -{ - int i, size; - cairo_pdf_pattern_t *pattern; - cairo_pdf_source_surface_t *src_surface; - cairo_pdf_smask_group_t *group; - - size = _cairo_array_num_elements (&surface->page_patterns); - for (i = 0; i < size; i++) { - pattern = (cairo_pdf_pattern_t *) _cairo_array_index (&surface->page_patterns, i); - cairo_pattern_destroy (pattern->pattern); - } - _cairo_array_truncate (&surface->page_patterns, 0); - - size = _cairo_array_num_elements (&surface->page_surfaces); - for (i = 0; i < size; i++) { - src_surface = (cairo_pdf_source_surface_t *) _cairo_array_index (&surface->page_surfaces, i); - cairo_surface_destroy (src_surface->surface); - } - _cairo_array_truncate (&surface->page_surfaces, 0); - - size = _cairo_array_num_elements (&surface->smask_groups); - for (i = 0; i < size; i++) { - _cairo_array_copy_element (&surface->smask_groups, i, &group); - _cairo_pdf_smask_group_destroy (group); - } - _cairo_array_truncate (&surface->smask_groups, 0); - _cairo_array_truncate (&surface->knockout_group, 0); -} - -static void -_cairo_pdf_group_resources_init (cairo_pdf_group_resources_t *res) -{ - int i; - - for (i = 0; i < CAIRO_NUM_OPERATORS; i++) - res->operators[i] = FALSE; - - _cairo_array_init (&res->alphas, sizeof (double)); - _cairo_array_init (&res->smasks, sizeof (cairo_pdf_resource_t)); - _cairo_array_init (&res->patterns, sizeof (cairo_pdf_resource_t)); - _cairo_array_init (&res->shadings, sizeof (cairo_pdf_resource_t)); - _cairo_array_init (&res->xobjects, sizeof (cairo_pdf_resource_t)); - _cairo_array_init (&res->fonts, sizeof (cairo_pdf_font_t)); -} - -static void -_cairo_pdf_group_resources_fini (cairo_pdf_group_resources_t *res) -{ - _cairo_array_fini (&res->alphas); - _cairo_array_fini (&res->smasks); - _cairo_array_fini (&res->patterns); - _cairo_array_fini (&res->shadings); - _cairo_array_fini (&res->xobjects); - _cairo_array_fini (&res->fonts); -} - -static void -_cairo_pdf_group_resources_clear (cairo_pdf_group_resources_t *res) -{ - int i; - - for (i = 0; i < CAIRO_NUM_OPERATORS; i++) - res->operators[i] = FALSE; - - _cairo_array_truncate (&res->alphas, 0); - _cairo_array_truncate (&res->smasks, 0); - _cairo_array_truncate (&res->patterns, 0); - _cairo_array_truncate (&res->shadings, 0); - _cairo_array_truncate (&res->xobjects, 0); - _cairo_array_truncate (&res->fonts, 0); -} - -static void -_cairo_pdf_surface_add_operator (cairo_pdf_surface_t *surface, - cairo_operator_t op) -{ - cairo_pdf_group_resources_t *res = &surface->resources; - - res->operators[op] = TRUE; -} - -static cairo_int_status_t -_cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, - double alpha, - int *index) -{ - int num_alphas, i; - double other; - cairo_int_status_t status; - cairo_pdf_group_resources_t *res = &surface->resources; - - num_alphas = _cairo_array_num_elements (&res->alphas); - for (i = 0; i < num_alphas; i++) { - _cairo_array_copy_element (&res->alphas, i, &other); - if (alpha == other) { - *index = i; - return CAIRO_STATUS_SUCCESS; - } - } - - status = _cairo_array_append (&res->alphas, &alpha); - if (unlikely (status)) - return status; - - *index = _cairo_array_num_elements (&res->alphas) - 1; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_add_smask (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t smask) -{ - return _cairo_array_append (&(surface->resources.smasks), &smask); -} - -static cairo_int_status_t -_cairo_pdf_surface_add_pattern (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t pattern) -{ - return _cairo_array_append (&(surface->resources.patterns), &pattern); -} - -static cairo_int_status_t -_cairo_pdf_surface_add_shading (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t shading) -{ - return _cairo_array_append (&(surface->resources.shadings), &shading); -} - - -static cairo_int_status_t -_cairo_pdf_surface_add_xobject (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t xobject) -{ - return _cairo_array_append (&(surface->resources.xobjects), &xobject); -} - -static cairo_int_status_t -_cairo_pdf_surface_add_font (unsigned int font_id, - unsigned int subset_id, - void *closure) -{ - cairo_pdf_surface_t *surface = closure; - cairo_pdf_font_t font; - int num_fonts, i; - cairo_int_status_t status; - cairo_pdf_group_resources_t *res = &surface->resources; - - num_fonts = _cairo_array_num_elements (&res->fonts); - for (i = 0; i < num_fonts; i++) { - _cairo_array_copy_element (&res->fonts, i, &font); - if (font.font_id == font_id && - font.subset_id == subset_id) - return CAIRO_STATUS_SUCCESS; - } - - num_fonts = _cairo_array_num_elements (&surface->fonts); - for (i = 0; i < num_fonts; i++) { - _cairo_array_copy_element (&surface->fonts, i, &font); - if (font.font_id == font_id && - font.subset_id == subset_id) - return _cairo_array_append (&res->fonts, &font); - } - - font.font_id = font_id; - font.subset_id = subset_id; - font.subset_resource = _cairo_pdf_surface_new_object (surface); - if (font.subset_resource.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_array_append (&surface->fonts, &font); - if (unlikely (status)) - return status; - - return _cairo_array_append (&res->fonts, &font); -} - -static cairo_pdf_resource_t -_cairo_pdf_surface_get_font_resource (cairo_pdf_surface_t *surface, - unsigned int font_id, - unsigned int subset_id) -{ - cairo_pdf_font_t font; - int num_fonts, i; - - num_fonts = _cairo_array_num_elements (&surface->fonts); - for (i = 0; i < num_fonts; i++) { - _cairo_array_copy_element (&surface->fonts, i, &font); - if (font.font_id == font_id && font.subset_id == subset_id) - return font.subset_resource; - } - - font.subset_resource.id = 0; - return font.subset_resource; -} - -static const char * -_cairo_operator_to_pdf_blend_mode (cairo_operator_t op) -{ - switch (op) { - /* The extend blend mode operators */ - case CAIRO_OPERATOR_MULTIPLY: return "Multiply"; - case CAIRO_OPERATOR_SCREEN: return "Screen"; - case CAIRO_OPERATOR_OVERLAY: return "Overlay"; - case CAIRO_OPERATOR_DARKEN: return "Darken"; - case CAIRO_OPERATOR_LIGHTEN: return "Lighten"; - case CAIRO_OPERATOR_COLOR_DODGE: return "ColorDodge"; - case CAIRO_OPERATOR_COLOR_BURN: return "ColorBurn"; - case CAIRO_OPERATOR_HARD_LIGHT: return "HardLight"; - case CAIRO_OPERATOR_SOFT_LIGHT: return "SoftLight"; - case CAIRO_OPERATOR_DIFFERENCE: return "Difference"; - case CAIRO_OPERATOR_EXCLUSION: return "Exclusion"; - case CAIRO_OPERATOR_HSL_HUE: return "Hue"; - case CAIRO_OPERATOR_HSL_SATURATION: return "Saturation"; - case CAIRO_OPERATOR_HSL_COLOR: return "Color"; - case CAIRO_OPERATOR_HSL_LUMINOSITY: return "Luminosity"; - - default: - /* The original Porter-Duff set */ - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_ATOP: - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_DEST_ATOP: - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - return "Normal"; - } -} - -static void -_cairo_pdf_surface_emit_group_resources (cairo_pdf_surface_t *surface, - cairo_pdf_group_resources_t *res) -{ - int num_alphas, num_smasks, num_resources, i; - double alpha; - cairo_pdf_resource_t *smask, *pattern, *shading, *xobject; - cairo_pdf_font_t *font; - - _cairo_output_stream_printf (surface->output, "<<\n"); - - num_alphas = _cairo_array_num_elements (&res->alphas); - num_smasks = _cairo_array_num_elements (&res->smasks); - if (num_alphas > 0 || num_smasks > 0) { - _cairo_output_stream_printf (surface->output, - " /ExtGState <<\n"); - - for (i = 0; i < CAIRO_NUM_OPERATORS; i++) { - if (res->operators[i]) { - _cairo_output_stream_printf (surface->output, - " /b%d << /BM /%s >>\n", - i, _cairo_operator_to_pdf_blend_mode(i)); - } - } - - for (i = 0; i < num_alphas; i++) { - _cairo_array_copy_element (&res->alphas, i, &alpha); - _cairo_output_stream_printf (surface->output, - " /a%d << /CA %f /ca %f >>\n", - i, alpha, alpha); - } - - for (i = 0; i < num_smasks; i++) { - smask = _cairo_array_index (&res->smasks, i); - _cairo_output_stream_printf (surface->output, - " /s%d %d 0 R\n", - smask->id, smask->id); - } - - _cairo_output_stream_printf (surface->output, - " >>\n"); - } - - num_resources = _cairo_array_num_elements (&res->patterns); - if (num_resources > 0) { - _cairo_output_stream_printf (surface->output, - " /Pattern <<"); - for (i = 0; i < num_resources; i++) { - pattern = _cairo_array_index (&res->patterns, i); - _cairo_output_stream_printf (surface->output, - " /p%d %d 0 R", - pattern->id, pattern->id); - } - - _cairo_output_stream_printf (surface->output, - " >>\n"); - } - - num_resources = _cairo_array_num_elements (&res->shadings); - if (num_resources > 0) { - _cairo_output_stream_printf (surface->output, - " /Shading <<"); - for (i = 0; i < num_resources; i++) { - shading = _cairo_array_index (&res->shadings, i); - _cairo_output_stream_printf (surface->output, - " /sh%d %d 0 R", - shading->id, shading->id); - } - - _cairo_output_stream_printf (surface->output, - " >>\n"); - } - - num_resources = _cairo_array_num_elements (&res->xobjects); - if (num_resources > 0) { - _cairo_output_stream_printf (surface->output, - " /XObject <<"); - - for (i = 0; i < num_resources; i++) { - xobject = _cairo_array_index (&res->xobjects, i); - _cairo_output_stream_printf (surface->output, - " /x%d %d 0 R", - xobject->id, xobject->id); - } - - _cairo_output_stream_printf (surface->output, - " >>\n"); - } - - num_resources = _cairo_array_num_elements (&res->fonts); - if (num_resources > 0) { - _cairo_output_stream_printf (surface->output," /Font <<\n"); - for (i = 0; i < num_resources; i++) { - font = _cairo_array_index (&res->fonts, i); - _cairo_output_stream_printf (surface->output, - " /f-%d-%d %d 0 R\n", - font->font_id, - font->subset_id, - font->subset_resource.id); - } - _cairo_output_stream_printf (surface->output, " >>\n"); - } - - _cairo_output_stream_printf (surface->output, - ">>\n"); -} - -static cairo_pdf_smask_group_t * -_cairo_pdf_surface_create_smask_group (cairo_pdf_surface_t *surface, - const cairo_rectangle_int_t *extents) -{ - cairo_pdf_smask_group_t *group; - - group = calloc (1, sizeof (cairo_pdf_smask_group_t)); - if (unlikely (group == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - group->group_res = _cairo_pdf_surface_new_object (surface); - if (group->group_res.id == 0) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - free (group); - return NULL; - } - group->width = surface->width; - group->height = surface->height; - if (extents != NULL) { - group->extents = *extents; - } else { - group->extents.x = 0; - group->extents.y = 0; - group->extents.width = surface->width; - group->extents.height = surface->height; - } - group->extents = *extents; - - return group; -} - -static void -_cairo_pdf_smask_group_destroy (cairo_pdf_smask_group_t *group) -{ - if (group->operation == PDF_FILL || group->operation == PDF_STROKE) - _cairo_path_fixed_fini (&group->path); - if (group->source) - cairo_pattern_destroy (group->source); - if (group->mask) - cairo_pattern_destroy (group->mask); - free (group->utf8); - free (group->glyphs); - free (group->clusters); - if (group->scaled_font) - cairo_scaled_font_destroy (group->scaled_font); - free (group); -} - -static cairo_int_status_t -_cairo_pdf_surface_add_smask_group (cairo_pdf_surface_t *surface, - cairo_pdf_smask_group_t *group) -{ - return _cairo_array_append (&surface->smask_groups, &group); -} - -static cairo_bool_t -_cairo_pdf_source_surface_equal (const void *key_a, const void *key_b) -{ - const cairo_pdf_source_surface_entry_t *a = key_a; - const cairo_pdf_source_surface_entry_t *b = key_b; - - if (a->interpolate != b->interpolate) - return FALSE; - - if (a->unique_id && b->unique_id && a->unique_id_length == b->unique_id_length) - return (memcmp (a->unique_id, b->unique_id, a->unique_id_length) == 0); - - return (a->id == b->id); -} - -static void -_cairo_pdf_source_surface_init_key (cairo_pdf_source_surface_entry_t *key) -{ - if (key->unique_id && key->unique_id_length > 0) { - key->base.hash = _cairo_hash_bytes (_CAIRO_HASH_INIT_VALUE, - key->unique_id, key->unique_id_length); - } else { - key->base.hash = key->id; - } -} - -static cairo_int_status_t -_cairo_pdf_surface_acquire_source_image_from_pattern (cairo_pdf_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_image_surface_t **image, - void **image_extra) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) pattern; - return _cairo_surface_acquire_source_image (surf_pat->surface, image, image_extra); - } break; - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: { - cairo_surface_t *surf; - surf = _cairo_raster_source_pattern_acquire (pattern, &surface->base, NULL); - if (!surf) - return CAIRO_INT_STATUS_UNSUPPORTED; - assert (_cairo_surface_is_image (surf)); - *image = (cairo_image_surface_t *) surf; - } break; - - case CAIRO_PATTERN_TYPE_SOLID: - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - default: - ASSERT_NOT_REACHED; - break; - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_pdf_surface_release_source_image_from_pattern (cairo_pdf_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_image_surface_t *image, - void *image_extra) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) pattern; - _cairo_surface_release_source_image (surf_pat->surface, image, image_extra); - } break; - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - _cairo_raster_source_pattern_release (pattern, &image->base); - break; - - case CAIRO_PATTERN_TYPE_SOLID: - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - default: - - ASSERT_NOT_REACHED; - break; - } -} - -static cairo_int_status_t -_get_jbig2_image_info (cairo_surface_t *source, - cairo_image_info_t *info, - const unsigned char **mime_data, - unsigned long *mime_data_length) -{ - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2, - mime_data, mime_data_length); - if (*mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return _cairo_image_info_get_jbig2_info (info, *mime_data, *mime_data_length); -} - -static cairo_int_status_t -_get_jpx_image_info (cairo_surface_t *source, - cairo_image_info_t *info, - const unsigned char **mime_data, - unsigned long *mime_data_length) -{ - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JP2, - mime_data, mime_data_length); - if (*mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return _cairo_image_info_get_jpx_info (info, *mime_data, *mime_data_length); -} - -static cairo_int_status_t -_get_jpeg_image_info (cairo_surface_t *source, - cairo_image_info_t *info, - const unsigned char **mime_data, - unsigned long *mime_data_length) -{ - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG, - mime_data, mime_data_length); - if (*mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return _cairo_image_info_get_jpeg_info (info, *mime_data, *mime_data_length); -} - -static cairo_int_status_t -_get_source_surface_size (cairo_surface_t *source, - int *width, - int *height, - cairo_rectangle_int_t *extents) -{ - cairo_int_status_t status; - cairo_image_info_t info; - const unsigned char *mime_data; - unsigned long mime_data_length; - - if (source->type == CAIRO_SURFACE_TYPE_RECORDING) { - if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; - - *extents = sub->extents; - *width = extents->width; - *height = extents->height; - } else { - cairo_surface_t *free_me = NULL; - cairo_rectangle_int_t surf_extents; - cairo_box_t box; - cairo_bool_t bounded; - - if (_cairo_surface_is_snapshot (source)) - free_me = source = _cairo_surface_snapshot_get_target (source); - - status = _cairo_recording_surface_get_ink_bbox ((cairo_recording_surface_t *)source, - &box, NULL); - if (unlikely (status)) { - cairo_surface_destroy (free_me); - return status; - } - - bounded = _cairo_surface_get_extents (source, &surf_extents); - cairo_surface_destroy (free_me); - - *width = surf_extents.width; - *height = surf_extents.height; - - _cairo_box_round_to_rectangle (&box, extents); - } - - return CAIRO_STATUS_SUCCESS; - } - - extents->x = 0; - extents->y = 0; - - status = _get_jbig2_image_info (source, &info, &mime_data, &mime_data_length); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) { - *width = info.width; - *height = info.height; - extents->width = info.width; - extents->height = info.height; - return status; - } - - status = _get_jpx_image_info (source, &info, &mime_data, &mime_data_length); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) { - *width = info.width; - *height = info.height; - extents->width = info.width; - extents->height = info.height; - return status; - } - - status = _get_jpeg_image_info (source, &info, &mime_data, &mime_data_length); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) { - *width = info.width; - *height = info.height; - extents->width = info.width; - extents->height = info.height; - return status; - } - - if (! _cairo_surface_get_extents (source, extents)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - *width = extents->width; - *height = extents->height; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_pdf_surface_add_source_surface: - * @surface: the pdf surface - * @source_surface: A #cairo_surface_t to use as the source surface - * @source_pattern: A #cairo_pattern_t of type SURFACE or RASTER_SOURCE to use as the source - * @op: the operator used to composite this source - * @filter: filter type of the source pattern - * @stencil_mask: if true, the surface will be written to the PDF as an /ImageMask - * @smask: if true, only the alpha channel will be written (images only) - * @extents: extents of the operation that is using this source - * @smask_res: if not NULL, the image written will specify this resource as the smask for the image (images only) - * @surface_res: return PDF resource number of the surface - * @width: returns width of surface - * @height: returns height of surface - * @x_offset: x offset of surface - * @t_offset: y offset of surface - * @source_extents: returns extents of source (either ink extents or extents needed to cover @extents) - * - * Add surface or raster_source pattern to list of surfaces to be - * written to the PDF file when the current page is finished. Returns - * a PDF resource to reference the image. A hash table of all images - * in the PDF files (keyed by CAIRO_MIME_TYPE_UNIQUE_ID or surface - * unique_id) to ensure surfaces with the same id are only written - * once to the PDF file. - * - * Only one of @source_pattern or @source_surface is to be - * specified. Set the other to NULL. - **/ -static cairo_int_status_t -_cairo_pdf_surface_add_source_surface (cairo_pdf_surface_t *surface, - cairo_surface_t *source_surface, - const cairo_pattern_t *source_pattern, - cairo_operator_t op, - cairo_filter_t filter, - cairo_bool_t stencil_mask, - cairo_bool_t smask, - const cairo_rectangle_int_t *extents, - cairo_pdf_resource_t *smask_res, - cairo_pdf_resource_t *surface_res, - int *width, - int *height, - double *x_offset, - double *y_offset, - cairo_rectangle_int_t *source_extents) -{ - cairo_pdf_source_surface_t src_surface; - cairo_pdf_source_surface_entry_t surface_key; - cairo_pdf_source_surface_entry_t *surface_entry; - cairo_int_status_t status; - cairo_bool_t interpolate; - unsigned char *unique_id = NULL; - unsigned long unique_id_length = 0; - cairo_image_surface_t *image; - void *image_extra; - - switch (filter) { - default: - case CAIRO_FILTER_GOOD: - case CAIRO_FILTER_BEST: - case CAIRO_FILTER_BILINEAR: - interpolate = TRUE; - break; - case CAIRO_FILTER_FAST: - case CAIRO_FILTER_NEAREST: - case CAIRO_FILTER_GAUSSIAN: - interpolate = FALSE; - break; - } - - *x_offset = 0; - *y_offset = 0; - if (source_pattern) { - if (source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { - status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source_pattern, - &image, &image_extra); - if (unlikely (status)) - return status; - source_surface = &image->base; - cairo_surface_get_device_offset (source_surface, x_offset, y_offset); - } else { - cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) source_pattern; - source_surface = surface_pattern->surface; - } - } - - surface_key.id = source_surface->unique_id; - surface_key.interpolate = interpolate; - cairo_surface_get_mime_data (source_surface, CAIRO_MIME_TYPE_UNIQUE_ID, - (const unsigned char **) &surface_key.unique_id, - &surface_key.unique_id_length); - _cairo_pdf_source_surface_init_key (&surface_key); - surface_entry = _cairo_hash_table_lookup (surface->all_surfaces, &surface_key.base); - if (surface_entry) { - *surface_res = surface_entry->surface_res; - *width = surface_entry->width; - *height = surface_entry->height; - *source_extents = surface_entry->extents; - status = CAIRO_STATUS_SUCCESS; - } else { - status = _get_source_surface_size (source_surface, - width, - height, - source_extents); - if (unlikely(status)) - goto release_source; - - if (surface_key.unique_id && surface_key.unique_id_length > 0) { - unique_id = _cairo_malloc (surface_key.unique_id_length); - if (unique_id == NULL) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto release_source; - } - - unique_id_length = surface_key.unique_id_length; - memcpy (unique_id, surface_key.unique_id, unique_id_length); - } else { - unique_id = NULL; - unique_id_length = 0; - } - } - -release_source: - if (source_pattern && source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) - _cairo_pdf_surface_release_source_image_from_pattern (surface, source_pattern, image, image_extra); - - if (status || surface_entry) - return status; - - surface_entry = malloc (sizeof (cairo_pdf_source_surface_entry_t)); - if (surface_entry == NULL) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - surface_entry->id = surface_key.id; - surface_entry->operator = op; - surface_entry->interpolate = interpolate; - surface_entry->stencil_mask = stencil_mask; - surface_entry->smask = smask; - surface_entry->unique_id_length = unique_id_length; - surface_entry->unique_id = unique_id; - surface_entry->width = *width; - surface_entry->height = *height; - surface_entry->extents = *source_extents; - if (smask_res) - surface_entry->smask_res = *smask_res; - else - surface_entry->smask_res.id = 0; - _cairo_pdf_source_surface_init_key (surface_entry); - - src_surface.hash_entry = surface_entry; - if (source_pattern && source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { - src_surface.type = CAIRO_PATTERN_TYPE_RASTER_SOURCE; - src_surface.surface = NULL; - status = _cairo_pattern_create_copy (&src_surface.raster_pattern, source_pattern); - if (unlikely (status)) - goto fail2; - - } else { - src_surface.type = CAIRO_PATTERN_TYPE_SURFACE; - src_surface.surface = cairo_surface_reference (source_surface); - src_surface.raster_pattern = NULL; - } - - surface_entry->surface_res = _cairo_pdf_surface_new_object (surface); - if (surface_entry->surface_res.id == 0) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - - status = _cairo_array_append (&surface->page_surfaces, &src_surface); - if (unlikely (status)) - goto fail3; - - status = _cairo_hash_table_insert (surface->all_surfaces, - &surface_entry->base); - if (unlikely(status)) - goto fail3; - - *surface_res = surface_entry->surface_res; - - return status; - -fail3: - if (source_pattern && source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) - cairo_pattern_destroy (src_surface.raster_pattern); - else - cairo_surface_destroy (src_surface.surface); - -fail2: - free (surface_entry); - -fail1: - free (unique_id); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_add_pdf_pattern_or_shading (cairo_pdf_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_operator_t op, - const cairo_rectangle_int_t *extents, - cairo_bool_t is_shading, - cairo_pdf_resource_t *pattern_res, - cairo_pdf_resource_t *gstate_res) -{ - cairo_pdf_pattern_t pdf_pattern; - cairo_int_status_t status; - - pdf_pattern.is_shading = is_shading; - pdf_pattern.operator = op; - - /* Solid colors are emitted into the content stream */ - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { - pattern_res->id = 0; - gstate_res->id = 0; - return CAIRO_INT_STATUS_SUCCESS; - } - - status = _cairo_pattern_create_copy (&pdf_pattern.pattern, pattern); - if (unlikely (status)) - return status; - - pdf_pattern.pattern_res = _cairo_pdf_surface_new_object (surface); - if (pdf_pattern.pattern_res.id == 0) { - cairo_pattern_destroy (pdf_pattern.pattern); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pdf_pattern.gstate_res.id = 0; - - /* gradient patterns require an smask object to implement transparency */ - if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || - pattern->type == CAIRO_PATTERN_TYPE_RADIAL || - pattern->type == CAIRO_PATTERN_TYPE_MESH) - { - double min_alpha; - - _cairo_pattern_alpha_range (pattern, &min_alpha, NULL); - if (! CAIRO_ALPHA_IS_OPAQUE (min_alpha)) { - pdf_pattern.gstate_res = _cairo_pdf_surface_new_object (surface); - if (pdf_pattern.gstate_res.id == 0) { - cairo_pattern_destroy (pdf_pattern.pattern); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - } - - pdf_pattern.width = surface->width; - pdf_pattern.height = surface->height; - if (extents != NULL) { - pdf_pattern.extents = *extents; - } else { - pdf_pattern.extents.x = 0; - pdf_pattern.extents.y = 0; - pdf_pattern.extents.width = surface->width; - pdf_pattern.extents.height = surface->height; - } - - *pattern_res = pdf_pattern.pattern_res; - *gstate_res = pdf_pattern.gstate_res; - - status = _cairo_array_append (&surface->page_patterns, &pdf_pattern); - if (unlikely (status)) { - cairo_pattern_destroy (pdf_pattern.pattern); - return status; - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -/* Get BBox in PDF coordinates from extents in cairo coordinates */ -static void -_get_bbox_from_extents (double surface_height, - const cairo_rectangle_int_t *extents, - cairo_box_double_t *bbox) -{ - bbox->p1.x = extents->x; - bbox->p1.y = surface_height - (extents->y + extents->height); - bbox->p2.x = extents->x + extents->width; - bbox->p2.y = surface_height - extents->y; -} - -static cairo_int_status_t -_cairo_pdf_surface_add_pdf_shading (cairo_pdf_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_operator_t op, - const cairo_rectangle_int_t *extents, - cairo_pdf_resource_t *shading_res, - cairo_pdf_resource_t *gstate_res) -{ - return _cairo_pdf_surface_add_pdf_pattern_or_shading (surface, - pattern, - op, - extents, - TRUE, - shading_res, - gstate_res); -} - -static cairo_int_status_t -_cairo_pdf_surface_add_pdf_pattern (cairo_pdf_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_operator_t op, - const cairo_rectangle_int_t *extents, - cairo_pdf_resource_t *pattern_res, - cairo_pdf_resource_t *gstate_res) -{ - return _cairo_pdf_surface_add_pdf_pattern_or_shading (surface, - pattern, - op, - extents, - FALSE, - pattern_res, - gstate_res); -} - -static cairo_int_status_t -_cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t *resource, - cairo_bool_t compressed, - const char *fmt, - ...) -{ - va_list ap; - cairo_pdf_resource_t self, length; - cairo_output_stream_t *output = NULL; - - if (resource) { - self = *resource; - _cairo_pdf_surface_update_object (surface, self); - } else { - self = _cairo_pdf_surface_new_object (surface); - if (self.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - length = _cairo_pdf_surface_new_object (surface); - if (length.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (compressed) { - output = _cairo_deflate_stream_create (surface->output); - if (_cairo_output_stream_get_status (output)) - return _cairo_output_stream_destroy (output); - } - - surface->pdf_stream.active = TRUE; - surface->pdf_stream.self = self; - surface->pdf_stream.length = length; - surface->pdf_stream.compressed = compressed; - surface->current_pattern_is_solid_color = FALSE; - surface->current_operator = CAIRO_OPERATOR_OVER; - _cairo_pdf_operators_reset (&surface->pdf_operators); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Length %d 0 R\n", - surface->pdf_stream.self.id, - surface->pdf_stream.length.id); - if (compressed) - _cairo_output_stream_printf (surface->output, - " /Filter /FlateDecode\n"); - - if (fmt != NULL) { - va_start (ap, fmt); - _cairo_output_stream_vprintf (surface->output, fmt, ap); - va_end (ap); - } - - _cairo_output_stream_printf (surface->output, - ">>\n" - "stream\n"); - - surface->pdf_stream.start_offset = _cairo_output_stream_get_position (surface->output); - - if (compressed) { - assert (surface->pdf_stream.old_output == NULL); - surface->pdf_stream.old_output = surface->output; - surface->output = output; - _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); - } - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -_cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface) -{ - cairo_int_status_t status; - long length; - - if (! surface->pdf_stream.active) - return CAIRO_INT_STATUS_SUCCESS; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - - if (surface->pdf_stream.compressed) { - cairo_int_status_t status2; - - status2 = _cairo_output_stream_destroy (surface->output); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = status2; - - surface->output = surface->pdf_stream.old_output; - _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); - surface->pdf_stream.old_output = NULL; - } - - length = _cairo_output_stream_get_position (surface->output) - - surface->pdf_stream.start_offset; - _cairo_output_stream_printf (surface->output, - "\n" - "endstream\n" - "endobj\n"); - - _cairo_pdf_surface_update_object (surface, - surface->pdf_stream.length); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - " %ld\n" - "endobj\n", - surface->pdf_stream.length.id, - length); - - surface->pdf_stream.active = FALSE; - - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = _cairo_output_stream_get_status (surface->output); - - return status; -} - -static void -_cairo_pdf_surface_write_memory_stream (cairo_pdf_surface_t *surface, - cairo_output_stream_t *mem_stream, - cairo_pdf_resource_t resource, - cairo_pdf_group_resources_t *resources, - cairo_bool_t is_knockout_group, - const cairo_box_double_t *bbox) -{ - _cairo_pdf_surface_update_object (surface, resource); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /XObject\n" - " /Length %d\n", - resource.id, - _cairo_memory_stream_length (mem_stream)); - - if (surface->compress_content) { - _cairo_output_stream_printf (surface->output, - " /Filter /FlateDecode\n"); - } - - _cairo_output_stream_printf (surface->output, - " /Subtype /Form\n" - " /BBox [ %f %f %f %f ]\n" - " /Group <<\n" - " /Type /Group\n" - " /S /Transparency\n" - " /I true\n" - " /CS /DeviceRGB\n", - bbox->p1.x, bbox->p1.y, bbox->p2.x, bbox->p2.y); - - if (is_knockout_group) - _cairo_output_stream_printf (surface->output, - " /K true\n"); - - _cairo_output_stream_printf (surface->output, - " >>\n" - " /Resources\n"); - _cairo_pdf_surface_emit_group_resources (surface, resources); - _cairo_output_stream_printf (surface->output, - ">>\n" - "stream\n"); - _cairo_memory_stream_copy (mem_stream, surface->output); - _cairo_output_stream_printf (surface->output, - "endstream\n" - "endobj\n"); -} - -static cairo_int_status_t -_cairo_pdf_surface_open_group (cairo_pdf_surface_t *surface, - const cairo_box_double_t *bbox, - cairo_pdf_resource_t *resource) -{ - cairo_int_status_t status; - - assert (surface->pdf_stream.active == FALSE); - assert (surface->group_stream.active == FALSE); - - surface->group_stream.active = TRUE; - surface->current_pattern_is_solid_color = FALSE; - surface->current_operator = CAIRO_OPERATOR_OVER; - _cairo_pdf_operators_reset (&surface->pdf_operators); - - surface->group_stream.mem_stream = _cairo_memory_stream_create (); - - if (surface->compress_content) { - surface->group_stream.stream = - _cairo_deflate_stream_create (surface->group_stream.mem_stream); - } else { - surface->group_stream.stream = surface->group_stream.mem_stream; - } - status = _cairo_output_stream_get_status (surface->group_stream.stream); - - surface->group_stream.old_output = surface->output; - surface->output = surface->group_stream.stream; - _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); - _cairo_pdf_group_resources_clear (&surface->resources); - - if (resource) { - surface->group_stream.resource = *resource; - } else { - surface->group_stream.resource = _cairo_pdf_surface_new_object (surface); - if (surface->group_stream.resource.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - surface->group_stream.is_knockout = FALSE; - surface->group_stream.bbox = *bbox; - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_open_knockout_group (cairo_pdf_surface_t *surface, - const cairo_box_double_t *bbox) -{ - cairo_int_status_t status; - - status = _cairo_pdf_surface_open_group (surface, bbox, NULL); - if (unlikely (status)) - return status; - - surface->group_stream.is_knockout = TRUE; - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_close_group (cairo_pdf_surface_t *surface, - cairo_pdf_resource_t *group) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS, status2; - - assert (surface->pdf_stream.active == FALSE); - assert (surface->group_stream.active == TRUE); - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - if (surface->compress_content) { - status = _cairo_output_stream_destroy (surface->group_stream.stream); - surface->group_stream.stream = NULL; - - _cairo_output_stream_printf (surface->group_stream.mem_stream, - "\n"); - } - surface->output = surface->group_stream.old_output; - _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); - surface->group_stream.active = FALSE; - _cairo_pdf_surface_write_memory_stream (surface, - surface->group_stream.mem_stream, - surface->group_stream.resource, - &surface->resources, - surface->group_stream.is_knockout, - &surface->group_stream.bbox); - if (group) - *group = surface->group_stream.resource; - - status2 = _cairo_output_stream_destroy (surface->group_stream.mem_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - - surface->group_stream.mem_stream = NULL; - surface->group_stream.stream = NULL; - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface, - const cairo_box_double_t *bbox, - cairo_pdf_resource_t *resource, - cairo_bool_t is_form, - cairo_bool_t is_group) -{ - cairo_int_status_t status; - - assert (surface->pdf_stream.active == FALSE); - assert (surface->group_stream.active == FALSE); - - surface->content_resources = _cairo_pdf_surface_new_object (surface); - if (surface->content_resources.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - if (is_form) { - assert (bbox != NULL); - - if (is_group) { - status = - _cairo_pdf_surface_open_stream (surface, - resource, - surface->compress_content, - " /Type /XObject\n" - " /Subtype /Form\n" - " /BBox [ %f %f %f %f ]\n" - " /Group <<\n" - " /Type /Group\n" - " /S /Transparency\n" - " /I true\n" - " /CS /DeviceRGB\n" - " >>\n" - " /Resources %d 0 R\n", - bbox->p1.x, - bbox->p1.y, - bbox->p2.x, - bbox->p2.y, - surface->content_resources.id); - } else { - status = - _cairo_pdf_surface_open_stream (surface, - resource, - surface->compress_content, - " /Type /XObject\n" - " /Subtype /Form\n" - " /BBox [ %f %f %f %f ]\n" - " /Resources %d 0 R\n", - bbox->p1.x, - bbox->p1.y, - bbox->p2.x, - bbox->p2.y, - surface->content_resources.id); - } - } else { - status = - _cairo_pdf_surface_open_stream (surface, - resource, - surface->compress_content, - NULL); - } - if (unlikely (status)) - return status; - - surface->content = surface->pdf_stream.self; - - _cairo_output_stream_printf (surface->output, "q\n"); - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -_cairo_pdf_surface_close_content_stream (cairo_pdf_surface_t *surface) -{ - cairo_int_status_t status; - - assert (surface->pdf_stream.active == TRUE); - assert (surface->group_stream.active == FALSE); - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "Q\n"); - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) - return status; - - _cairo_pdf_surface_update_object (surface, surface->content_resources); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n", - surface->content_resources.id); - _cairo_pdf_surface_emit_group_resources (surface, &surface->resources); - _cairo_output_stream_printf (surface->output, - "endobj\n"); - - return _cairo_output_stream_get_status (surface->output); -} - -static void -_cairo_pdf_source_surface_entry_pluck (void *entry, void *closure) -{ - cairo_pdf_source_surface_entry_t *surface_entry = entry; - cairo_hash_table_t *patterns = closure; - - _cairo_hash_table_remove (patterns, &surface_entry->base); - free (surface_entry->unique_id); - - free (surface_entry); -} - -static cairo_status_t -_cairo_pdf_surface_finish (void *abstract_surface) -{ - cairo_pdf_surface_t *surface = abstract_surface; - long offset; - cairo_pdf_resource_t info, catalog; - cairo_status_t status, status2; - int size, i; - cairo_pdf_jbig2_global_t *global; - - status = surface->base.status; - if (status == CAIRO_STATUS_SUCCESS) - status = _cairo_pdf_surface_emit_font_subsets (surface); - - _cairo_pdf_surface_write_pages (surface); - - info = _cairo_pdf_surface_write_info (surface); - if (info.id == 0 && status == CAIRO_STATUS_SUCCESS) - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - - catalog = _cairo_pdf_surface_write_catalog (surface); - if (catalog.id == 0 && status == CAIRO_STATUS_SUCCESS) - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - - offset = _cairo_pdf_surface_write_xref (surface); - - _cairo_output_stream_printf (surface->output, - "trailer\n" - "<< /Size %d\n" - " /Root %d 0 R\n" - " /Info %d 0 R\n" - ">>\n", - surface->next_available_resource.id, - catalog.id, - info.id); - - _cairo_output_stream_printf (surface->output, - "startxref\n" - "%ld\n" - "%%%%EOF\n", - offset); - - /* pdf_operators has already been flushed when the last stream was - * closed so we should never be writing anything here - however, - * the stream may itself be in an error state. */ - status2 = _cairo_pdf_operators_fini (&surface->pdf_operators); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - /* close any active streams still open due to fatal errors */ - status2 = _cairo_pdf_surface_close_stream (surface); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - if (surface->group_stream.stream != NULL) { - status2 = _cairo_output_stream_destroy (surface->group_stream.stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - } - if (surface->group_stream.mem_stream != NULL) { - status2 = _cairo_output_stream_destroy (surface->group_stream.mem_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - } - if (surface->pdf_stream.active) - surface->output = surface->pdf_stream.old_output; - if (surface->group_stream.active) - surface->output = surface->group_stream.old_output; - - /* and finish the pdf surface */ - status2 = _cairo_output_stream_destroy (surface->output); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - _cairo_pdf_surface_clear (surface); - _cairo_pdf_group_resources_fini (&surface->resources); - - _cairo_array_fini (&surface->objects); - _cairo_array_fini (&surface->pages); - _cairo_array_fini (&surface->rgb_linear_functions); - _cairo_array_fini (&surface->alpha_linear_functions); - _cairo_array_fini (&surface->page_patterns); - _cairo_array_fini (&surface->page_surfaces); - _cairo_hash_table_foreach (surface->all_surfaces, - _cairo_pdf_source_surface_entry_pluck, - surface->all_surfaces); - _cairo_hash_table_destroy (surface->all_surfaces); - _cairo_array_fini (&surface->smask_groups); - _cairo_array_fini (&surface->fonts); - _cairo_array_fini (&surface->knockout_group); - - if (surface->font_subsets) { - _cairo_scaled_font_subsets_destroy (surface->font_subsets); - surface->font_subsets = NULL; - } - - size = _cairo_array_num_elements (&surface->jbig2_global); - for (i = 0; i < size; i++) { - global = (cairo_pdf_jbig2_global_t *) _cairo_array_index (&surface->jbig2_global, i); - free(global->id); - if (!global->emitted) - return _cairo_error (CAIRO_STATUS_JBIG2_GLOBAL_MISSING); - } - _cairo_array_fini (&surface->jbig2_global); - - _cairo_array_truncate (&surface->page_surfaces, 0); - - _cairo_surface_clipper_reset (&surface->clipper); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_start_page (void *abstract_surface) -{ - cairo_pdf_surface_t *surface = abstract_surface; - - /* Document header */ - if (! surface->header_emitted) { - const char *version; - - switch (surface->pdf_version) { - case CAIRO_PDF_VERSION_1_4: - version = "1.4"; - break; - default: - case CAIRO_PDF_VERSION_1_5: - version = "1.5"; - break; - } - - _cairo_output_stream_printf (surface->output, - "%%PDF-%s\n", version); - _cairo_output_stream_printf (surface->output, - "%%%c%c%c%c\n", 181, 237, 174, 251); - surface->header_emitted = TRUE; - } - - _cairo_pdf_group_resources_clear (&surface->resources); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_has_fallback_images (void *abstract_surface, - cairo_bool_t has_fallbacks) -{ - cairo_int_status_t status; - cairo_pdf_surface_t *surface = abstract_surface; - cairo_box_double_t bbox; - - surface->has_fallback_images = has_fallbacks; - bbox.p1.x = 0; - bbox.p1.y = 0; - bbox.p2.x = surface->width; - bbox.p2.y = surface->height; - status = _cairo_pdf_surface_open_content_stream (surface, &bbox, NULL, has_fallbacks, has_fallbacks); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_pdf_surface_supports_fine_grained_fallbacks (void *abstract_surface) -{ - return TRUE; -} - -static cairo_int_status_t -_cairo_pdf_surface_add_padded_image_surface (cairo_pdf_surface_t *surface, - const cairo_pattern_t *source, - const cairo_rectangle_int_t *extents, - cairo_pdf_resource_t *surface_res, - int *width, - int *height, - double *x_offset, - double *y_offset) -{ - cairo_image_surface_t *image; - cairo_surface_t *pad_image; - void *image_extra; - cairo_int_status_t status; - int w, h; - cairo_rectangle_int_t extents2; - cairo_box_t box; - cairo_rectangle_int_t rect; - cairo_surface_pattern_t pad_pattern; - - status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source, - &image, &image_extra); - if (unlikely (status)) - return status; - - pad_image = &image->base; - - /* get the operation extents in pattern space */ - _cairo_box_from_rectangle (&box, extents); - _cairo_matrix_transform_bounding_box_fixed (&source->matrix, &box, NULL); - _cairo_box_round_to_rectangle (&box, &rect); - - /* Check if image needs padding to fill extents */ - w = image->width; - h = image->height; - if (_cairo_fixed_integer_ceil(box.p1.x) < 0 || - _cairo_fixed_integer_ceil(box.p1.y) < 0 || - _cairo_fixed_integer_floor(box.p2.x) > w || - _cairo_fixed_integer_floor(box.p2.y) > h) - { - pad_image = _cairo_image_surface_create_with_content (image->base.content, - rect.width, - rect.height); - if (pad_image->status) { - status = pad_image->status; - goto BAIL; - } - - _cairo_pattern_init_for_surface (&pad_pattern, &image->base); - cairo_matrix_init_translate (&pad_pattern.base.matrix, rect.x, rect.y); - pad_pattern.base.extend = CAIRO_EXTEND_PAD; - status = _cairo_surface_paint (pad_image, - CAIRO_OPERATOR_SOURCE, &pad_pattern.base, - NULL); - _cairo_pattern_fini (&pad_pattern.base); - if (unlikely (status)) - goto BAIL; - } - - status = _cairo_pdf_surface_add_source_surface (surface, - pad_image, - NULL, - FALSE, - source->filter, - FALSE, - FALSE, - extents, - NULL, - surface_res, - width, - height, - x_offset, - y_offset, - &extents2); - if (unlikely (status)) - goto BAIL; - - if (pad_image != &image->base) { - /* If using a padded image, replace _add_source_surface - * x/y_offset with padded image offset. Note: - * _add_source_surface only sets a non zero x/y_offset for - * RASTER_SOURCE patterns. _add_source_surface will always set - * x/y_offset to 0 for surfaces so we can ignore the returned - * offset and replace it with the offset required for the - * padded image */ - *x_offset = rect.x; - *y_offset = rect.y; - } - -BAIL: - if (pad_image != &image->base) - cairo_surface_destroy (pad_image); - - _cairo_pdf_surface_release_source_image_from_pattern (surface, source, image, image_extra); - - return status; -} - -/* Emit alpha channel from the image into stream_res. - */ -static cairo_int_status_t -_cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface, - cairo_image_surface_t *image, - cairo_bool_t stencil_mask, - cairo_bool_t interpolate, - cairo_pdf_resource_t *stream_res) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - char *alpha; - unsigned long alpha_size; - uint32_t *pixel32; - uint8_t *pixel8; - int i, x, y, bit, a; - cairo_image_transparency_t transparency; - - /* This is the only image format we support, which simplifies things. */ - assert (image->format == CAIRO_FORMAT_ARGB32 || - image->format == CAIRO_FORMAT_RGB24 || - image->format == CAIRO_FORMAT_A8 || - image->format == CAIRO_FORMAT_A1 ); - - transparency = _cairo_image_analyze_transparency (image); - if (stencil_mask) { - assert (transparency == CAIRO_IMAGE_IS_OPAQUE || - transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA); - } else { - assert (transparency != CAIRO_IMAGE_IS_OPAQUE); - } - - if (transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA || transparency == CAIRO_IMAGE_IS_OPAQUE) { - alpha_size = (image->width + 7) / 8 * image->height; - alpha = _cairo_malloc_ab ((image->width+7) / 8, image->height); - } else { - alpha_size = image->height * image->width; - alpha = _cairo_malloc_ab (image->height, image->width); - } - - if (unlikely (alpha == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP; - } - - i = 0; - for (y = 0; y < image->height; y++) { - if (transparency == CAIRO_IMAGE_IS_OPAQUE) { - for (x = 0; x < (image->width + 7) / 8; x++) - alpha[i++] = 0xff; - } else if (image->format == CAIRO_FORMAT_A1) { - pixel8 = (uint8_t *) (image->data + y * image->stride); - - for (x = 0; x < (image->width + 7) / 8; x++, pixel8++) { - a = *pixel8; - a = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (a); - alpha[i++] = a; - } - } else { - pixel8 = (uint8_t *) (image->data + y * image->stride); - pixel32 = (uint32_t *) (image->data + y * image->stride); - bit = 7; - for (x = 0; x < image->width; x++) { - if (image->format == CAIRO_FORMAT_ARGB32) { - a = (*pixel32 & 0xff000000) >> 24; - pixel32++; - } else { - a = *pixel8; - pixel8++; - } - - if (transparency == CAIRO_IMAGE_HAS_ALPHA) { - alpha[i++] = a; - } else { /* transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA or CAIRO_IMAGE_IS_OPAQUE */ - if (bit == 7) - alpha[i] = 0; - if (a != 0) - alpha[i] |= (1 << bit); - bit--; - if (bit < 0) { - bit = 7; - i++; - } - } - } - if (bit != 7) - i++; - } - } - - if (stencil_mask) { - status = _cairo_pdf_surface_open_stream (surface, - stream_res, - TRUE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /ImageMask true\n" - " /Width %d\n" - " /Height %d\n" - " /Interpolate %s\n" - " /BitsPerComponent 1\n" - " /Decode [1 0]\n", - image->width, image->height, - interpolate ? "true" : "false"); - } else { - status = _cairo_pdf_surface_open_stream (surface, - stream_res, - TRUE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /Width %d\n" - " /Height %d\n" - " /ColorSpace /DeviceGray\n" - " /Interpolate %s\n" - " /BitsPerComponent %d\n", - image->width, image->height, - interpolate ? "true" : "false", - transparency == CAIRO_IMAGE_HAS_ALPHA ? 8 : 1); - } - if (unlikely (status)) - goto CLEANUP_ALPHA; - - _cairo_output_stream_write (surface->output, alpha, alpha_size); - status = _cairo_pdf_surface_close_stream (surface); - - CLEANUP_ALPHA: - free (alpha); - CLEANUP: - return status; -} - -/** - * _cairo_pdf_surface_emit_image: - * @surface: the pdf surface - * @image_surf: The image to write - * @surface_entry: Contains image resource, smask resource, interpolate and stencil mask parameters. - * - * Emit an image stream using the @image_res resource and write out - * the image data from @image_surf. If @smask_res is not null, @smask_res will - * be specified as the smask for the image. Otherwise emit the an smask if - * the image is requires one. - **/ -static cairo_int_status_t -_cairo_pdf_surface_emit_image (cairo_pdf_surface_t *surface, - cairo_image_surface_t *image_surf, - cairo_pdf_source_surface_entry_t *surface_entry) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - char *data; - unsigned long data_size; - uint32_t *pixel; - int i, x, y, bit; - cairo_pdf_resource_t smask = {0}; /* squelch bogus compiler warning */ - cairo_bool_t need_smask; - cairo_image_color_t color; - cairo_image_surface_t *image; - cairo_image_transparency_t transparency; - char smask_buf[30]; - - image = image_surf; - if (image->format != CAIRO_FORMAT_RGB24 && - image->format != CAIRO_FORMAT_ARGB32 && - image->format != CAIRO_FORMAT_A8 && - image->format != CAIRO_FORMAT_A1) - { - cairo_surface_t *surf; - cairo_surface_pattern_t pattern; - - surf = _cairo_image_surface_create_with_content (image_surf->base.content, - image_surf->width, - image_surf->height); - image = (cairo_image_surface_t *) surf; - if (surf->status) { - status = surf->status; - goto CLEANUP; - } - - _cairo_pattern_init_for_surface (&pattern, &image_surf->base); - status = _cairo_surface_paint (surf, - CAIRO_OPERATOR_SOURCE, &pattern.base, - NULL); - _cairo_pattern_fini (&pattern.base); - if (unlikely (status)) - goto CLEANUP; - } - - if (surface_entry->smask || surface_entry->stencil_mask) { - return _cairo_pdf_surface_emit_smask (surface, image, - surface_entry->stencil_mask, - surface_entry->interpolate, - &surface_entry->surface_res); - } - - color = _cairo_image_analyze_color (image); - switch (color) { - default: - case CAIRO_IMAGE_UNKNOWN_COLOR: - ASSERT_NOT_REACHED; - case CAIRO_IMAGE_IS_COLOR: - data_size = image->height * image->width * 3; - data = _cairo_malloc_abc (image->width, image->height, 3); - break; - - case CAIRO_IMAGE_IS_GRAYSCALE: - data_size = image->height * image->width; - data = _cairo_malloc_ab (image->width, image->height); - break; - case CAIRO_IMAGE_IS_MONOCHROME: - data_size = (image->width + 7) / 8 * image->height; - data = _cairo_malloc_ab ((image->width+7) / 8, image->height); - break; - } - if (unlikely (data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP; - } - - i = 0; - for (y = 0; y < image->height; y++) { - pixel = (uint32_t *) (image->data + y * image->stride); - - bit = 7; - for (x = 0; x < image->width; x++, pixel++) { - int r, g, b; - - /* XXX: We're un-premultiplying alpha here. My reading of the PDF - * specification suggests that we should be able to avoid having - * to do this by filling in the SMask's Matte dictionary - * appropriately, but my attempts to do that so far have - * failed. */ - if (image->format == CAIRO_FORMAT_ARGB32) { - uint8_t a; - a = (*pixel & 0xff000000) >> 24; - if (a == 0) { - r = g = b = 0; - } else { - r = (((*pixel & 0xff0000) >> 16) * 255 + a / 2) / a; - g = (((*pixel & 0x00ff00) >> 8) * 255 + a / 2) / a; - b = (((*pixel & 0x0000ff) >> 0) * 255 + a / 2) / a; - } - } else if (image->format == CAIRO_FORMAT_RGB24) { - r = (*pixel & 0x00ff0000) >> 16; - g = (*pixel & 0x0000ff00) >> 8; - b = (*pixel & 0x000000ff) >> 0; - } else { - r = g = b = 0; - } - - switch (color) { - case CAIRO_IMAGE_IS_COLOR: - case CAIRO_IMAGE_UNKNOWN_COLOR: - data[i++] = r; - data[i++] = g; - data[i++] = b; - break; - - case CAIRO_IMAGE_IS_GRAYSCALE: - data[i++] = r; - break; - - case CAIRO_IMAGE_IS_MONOCHROME: - if (bit == 7) - data[i] = 0; - if (r != 0) - data[i] |= (1 << bit); - bit--; - if (bit < 0) { - bit = 7; - i++; - } - break; - } - } - if (bit != 7) - i++; - } - - if (surface_entry->smask_res.id != 0) { - need_smask = TRUE; - smask = surface_entry->smask_res; - } else { - need_smask = FALSE; - if (image->format == CAIRO_FORMAT_ARGB32 || - image->format == CAIRO_FORMAT_A8 || - image->format == CAIRO_FORMAT_A1) - { - transparency = _cairo_image_analyze_transparency (image); - if (transparency != CAIRO_IMAGE_IS_OPAQUE) { - need_smask = TRUE; - smask = _cairo_pdf_surface_new_object (surface); - if (smask.id == 0) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_RGB; - } - - status = _cairo_pdf_surface_emit_smask (surface, image, FALSE, surface_entry->interpolate, &smask); - if (unlikely (status)) - goto CLEANUP_RGB; - } - } - } - - if (need_smask) - snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", smask.id); - else - smask_buf[0] = 0; - - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - TRUE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /Width %d\n" - " /Height %d\n" - " /ColorSpace %s\n" - " /Interpolate %s\n" - " /BitsPerComponent %d\n" - "%s", - image->width, - image->height, - color == CAIRO_IMAGE_IS_COLOR ? "/DeviceRGB" : "/DeviceGray", - surface_entry->interpolate ? "true" : "false", - color == CAIRO_IMAGE_IS_MONOCHROME? 1 : 8, - smask_buf); - if (unlikely (status)) - goto CLEANUP_RGB; - -#undef IMAGE_DICTIONARY - - _cairo_output_stream_write (surface->output, data, data_size); - status = _cairo_pdf_surface_close_stream (surface); - -CLEANUP_RGB: - free (data); -CLEANUP: - if (image != image_surf) - cairo_surface_destroy (&image->base); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_lookup_jbig2_global (cairo_pdf_surface_t *surface, - const unsigned char *global_id, - unsigned long global_id_length, - cairo_pdf_jbig2_global_t **entry) -{ - cairo_pdf_jbig2_global_t global; - int size, i; - cairo_int_status_t status; - - size = _cairo_array_num_elements (&surface->jbig2_global); - for (i = 0; i < size; i++) { - *entry = (cairo_pdf_jbig2_global_t *) _cairo_array_index (&surface->jbig2_global, i); - if ((*entry)->id && global_id && (*entry)->id_length == global_id_length - && memcmp((*entry)->id, global_id, global_id_length) == 0) { - return CAIRO_STATUS_SUCCESS; - } - } - - global.id = malloc(global_id_length); - if (unlikely (global.id == NULL)) { - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - memcpy (global.id, global_id, global_id_length); - global.id_length = global_id_length; - global.res = _cairo_pdf_surface_new_object (surface); - if (global.res.id == 0) { - free(global.id); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - global.emitted = FALSE; - status = _cairo_array_append (&surface->jbig2_global, &global); - if (unlikely(status)) - return status; - - size = _cairo_array_num_elements (&surface->jbig2_global); - *entry = (cairo_pdf_jbig2_global_t *) _cairo_array_index (&surface->jbig2_global, size - 1); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_jbig2_image (cairo_pdf_surface_t *surface, - cairo_surface_t *source, - cairo_pdf_source_surface_entry_t *surface_entry) -{ - cairo_int_status_t status; - const unsigned char *mime_data; - unsigned long mime_data_length; - cairo_image_info_t info; - const unsigned char *global_id; - unsigned long global_id_length; - const unsigned char *global_data; - unsigned long global_data_length; - cairo_pdf_jbig2_global_t *global_entry = NULL; /* hide compiler warning */ - char smask_buf[30]; - char decode_parms_buf[100]; - - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2, - &mime_data, &mime_data_length); - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_image_info_get_jbig2_info (&info, mime_data, mime_data_length); - if (status) - return status; - - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, - &global_id, &global_id_length); - if (global_id && global_id_length > 0) { - status = _cairo_pdf_surface_lookup_jbig2_global (surface, global_id, global_id_length, &global_entry); - if (unlikely(status)) - return status; - - if (!global_entry->emitted) { - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2_GLOBAL, - &global_data, &global_data_length); - if (global_data) { - status = _cairo_pdf_surface_open_stream (surface, &global_entry->res, FALSE, NULL); - if (unlikely(status)) - return status; - - _cairo_output_stream_write (surface->output, global_data, global_data_length); - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely(status)) - return status; - - global_entry->emitted = TRUE; - } - } - - snprintf(decode_parms_buf, sizeof(decode_parms_buf), - " /DecodeParms << /JBIG2Globals %d 0 R >>\n", global_entry->res.id); - } else { - decode_parms_buf[0] = 0; - } - - if (surface_entry->smask_res.id) - snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", surface_entry->smask_res.id); - else - smask_buf[0] = 0; - - if (surface_entry->stencil_mask) { - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - FALSE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /ImageMask true\n" - " /Width %d\n" - " /Height %d\n" - " /Interpolate %s\n" - " /BitsPerComponent 1\n" - " /Decode [1 0]\n" - " /Filter /JPXDecode\n" - "%s", - info.width, - info.height, - surface_entry->interpolate ? "true" : "false", - decode_parms_buf); - } else { - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - FALSE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /Width %d\n" - " /Height %d\n" - " /ColorSpace /DeviceGray\n" - " /BitsPerComponent 1\n" - " /Interpolate %s\n" - "%s" - " /Filter /JBIG2Decode\n" - "%s", - info.width, - info.height, - surface_entry->interpolate ? "true" : "false", - smask_buf, - decode_parms_buf); - } - if (unlikely(status)) - return status; - - _cairo_output_stream_write (surface->output, mime_data, mime_data_length); - status = _cairo_pdf_surface_close_stream (surface); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_jpx_image (cairo_pdf_surface_t *surface, - cairo_surface_t *source, - cairo_pdf_source_surface_entry_t *surface_entry) -{ - cairo_int_status_t status; - const unsigned char *mime_data; - unsigned long mime_data_length; - cairo_image_info_t info; - char smask_buf[30]; - - if (surface->pdf_version < CAIRO_PDF_VERSION_1_5) - return CAIRO_INT_STATUS_UNSUPPORTED; - - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JP2, - &mime_data, &mime_data_length); - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_image_info_get_jpx_info (&info, mime_data, mime_data_length); - if (status) - return status; - - if ((surface_entry->smask || surface_entry->stencil_mask) && info.num_components != 1) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface_entry->stencil_mask) && info.bits_per_component != 1) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (surface_entry->smask_res.id) - snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", surface_entry->smask_res.id); - else - smask_buf[0] = 0; - - if (surface_entry->stencil_mask) { - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - FALSE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /ImageMask true\n" - " /Width %d\n" - " /Height %d\n" - " /Interpolate %s\n" - " /BitsPerComponent 1\n" - " /Decode [1 0]\n" - " /Filter /JPXDecode\n", - info.width, - info.height, - surface_entry->interpolate ? "true" : "false"); - } else { - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - FALSE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /Width %d\n" - " /Height %d\n" - " /Interpolate %s\n" - "%s" - " /Filter /JPXDecode\n", - info.width, - info.height, - surface_entry->interpolate ? "true" : "false", - smask_buf); - } - if (status) - return status; - - _cairo_output_stream_write (surface->output, mime_data, mime_data_length); - status = _cairo_pdf_surface_close_stream (surface); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_jpeg_image (cairo_pdf_surface_t *surface, - cairo_surface_t *source, - cairo_pdf_source_surface_entry_t *surface_entry) -{ - cairo_int_status_t status; - const unsigned char *mime_data; - unsigned long mime_data_length; - cairo_image_info_t info; - const char *colorspace; - char smask_buf[30]; - - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG, - &mime_data, &mime_data_length); - if (unlikely (source->status)) - return source->status; - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_image_info_get_jpeg_info (&info, mime_data, mime_data_length); - if (unlikely (status)) - return status; - - if ((surface_entry->smask || surface_entry->stencil_mask) && info.num_components != 1) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface_entry->stencil_mask) && info.bits_per_component != 1) - return CAIRO_INT_STATUS_UNSUPPORTED; - - switch (info.num_components) { - case 1: - colorspace = "/DeviceGray"; - break; - case 3: - colorspace = "/DeviceRGB"; - break; - case 4: - colorspace = "/DeviceCMYK"; - break; - default: - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (surface_entry->smask_res.id) - snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", surface_entry->smask_res.id); - else - smask_buf[0] = 0; - - if (surface_entry->stencil_mask) { - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - FALSE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /ImageMask true\n" - " /Width %d\n" - " /Height %d\n" - " /Interpolate %s\n" - " /BitsPerComponent 1\n" - " /Decode [1 0]\n" - " /Filter /DCTDecode\n", - info.width, - info.height, - surface_entry->interpolate ? "true" : "false"); - } else { - status = _cairo_pdf_surface_open_stream (surface, - &surface_entry->surface_res, - FALSE, - " /Type /XObject\n" - " /Subtype /Image\n" - " /Width %d\n" - " /Height %d\n" - " /ColorSpace %s\n" - " /Interpolate %s\n" - " /BitsPerComponent %d\n" - "%s" - " /Filter /DCTDecode\n", - info.width, - info.height, - colorspace, - surface_entry->interpolate ? "true" : "false", - info.bits_per_component, - smask_buf); - } - if (unlikely (status)) - return status; - - _cairo_output_stream_write (surface->output, mime_data, mime_data_length); - status = _cairo_pdf_surface_close_stream (surface); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_image_surface (cairo_pdf_surface_t *surface, - cairo_pdf_source_surface_t *source) -{ - cairo_image_surface_t *image; - void *image_extra; - cairo_int_status_t status; - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { - status = _cairo_pdf_surface_emit_jbig2_image (surface, source->surface, source->hash_entry); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_pdf_surface_emit_jpx_image (surface, source->surface, source->hash_entry); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_pdf_surface_emit_jpeg_image (surface, source->surface, source->hash_entry); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { - status = _cairo_surface_acquire_source_image (source->surface, &image, &image_extra); - } else { - status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source->raster_pattern, - &image, &image_extra); - } - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_image (surface, - image, - source->hash_entry); - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) - _cairo_surface_release_source_image (source->surface, image, image_extra); - else - _cairo_pdf_surface_release_source_image_from_pattern (surface, source->raster_pattern, - image, image_extra); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_recording_surface (cairo_pdf_surface_t *surface, - cairo_pdf_source_surface_t *pdf_source) -{ - double old_width, old_height; - cairo_paginated_mode_t old_paginated_mode; - cairo_surface_clipper_t old_clipper; - cairo_box_double_t bbox; - cairo_int_status_t status; - int alpha = 0; - cairo_surface_t *free_me = NULL; - cairo_surface_t *source; - const cairo_rectangle_int_t *extents; - int width; - int height; - cairo_bool_t is_subsurface; - cairo_bool_t transparency_group; - cairo_recording_surface_t *recording; - - assert (pdf_source->type == CAIRO_PATTERN_TYPE_SURFACE); - extents = &pdf_source->hash_entry->extents; - width = pdf_source->hash_entry->width; - height = pdf_source->hash_entry->height; - is_subsurface = FALSE; - source = pdf_source->surface; - if (_cairo_surface_is_snapshot (source)) { - free_me = source = _cairo_surface_snapshot_get_target (source); - } else if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; - - source = sub->target; - extents = &sub->extents; - width = extents->width; - height = extents->height; - is_subsurface = TRUE; - } - - assert (source->type == CAIRO_SURFACE_TYPE_RECORDING); - recording = (cairo_recording_surface_t *) source; - - old_width = surface->width; - old_height = surface->height; - old_paginated_mode = surface->paginated_mode; - old_clipper = surface->clipper; - _cairo_surface_clipper_init (&surface->clipper, - _cairo_pdf_surface_clipper_intersect_clip_path); - - _cairo_pdf_surface_set_size_internal (surface, width, height); - - /* Patterns are emitted after fallback images. The paginated mode - * needs to be set to _RENDER while the recording surface is replayed - * back to this surface. - */ - surface->paginated_mode = CAIRO_PAGINATED_MODE_RENDER; - _cairo_pdf_group_resources_clear (&surface->resources); - _get_bbox_from_extents (height, extents, &bbox); - - /* We can optimize away the transparency group allowing the viewer - * to replay the group in place when all operators are OVER and the - * recording contains only opaque and/or clear alpha. - */ - transparency_group = !(pdf_source->hash_entry->operator == CAIRO_OPERATOR_OVER && - _cairo_recording_surface_has_only_bilevel_alpha (recording) && - _cairo_recording_surface_has_only_op_over (recording)); - status = _cairo_pdf_surface_open_content_stream (surface, &bbox, &pdf_source->hash_entry->surface_res, - TRUE, transparency_group); - if (unlikely (status)) - goto err; - - if (source->content == CAIRO_CONTENT_COLOR) { - status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); - if (unlikely (status)) - goto err; - - _cairo_output_stream_printf (surface->output, - "q /a%d gs 0 0 0 rg 0 0 %f %f re f Q\n", - alpha, - surface->width, - surface->height); - } - - status = _cairo_recording_surface_replay_region (source, - is_subsurface ? extents : NULL, - &surface->base, - CAIRO_RECORDING_REGION_NATIVE); - assert (status != CAIRO_INT_STATUS_UNSUPPORTED); - if (unlikely (status)) - goto err; - - status = _cairo_pdf_surface_close_content_stream (surface); - - _cairo_surface_clipper_reset (&surface->clipper); - surface->clipper = old_clipper; - _cairo_pdf_surface_set_size_internal (surface, - old_width, - old_height); - surface->paginated_mode = old_paginated_mode; - -err: - cairo_surface_destroy (free_me); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_surface (cairo_pdf_surface_t *surface, - cairo_pdf_source_surface_t *src_surface) -{ - if (src_surface->type == CAIRO_PATTERN_TYPE_SURFACE && - src_surface->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - return _cairo_pdf_surface_emit_recording_surface (surface, src_surface); - - return _cairo_pdf_surface_emit_image_surface (surface, src_surface); -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface, - cairo_pdf_pattern_t *pdf_pattern) -{ - cairo_pattern_t *pattern = pdf_pattern->pattern; - cairo_int_status_t status; - cairo_pdf_resource_t pattern_resource = {0}; - cairo_matrix_t cairo_p2d, pdf_p2d; - cairo_extend_t extend = cairo_pattern_get_extend (pattern); - double xstep, ystep; - cairo_rectangle_int_t pattern_extents; - int pattern_width = 0; /* squelch bogus compiler warning */ - int pattern_height = 0; /* squelch bogus compiler warning */ - double x_offset; - double y_offset; - char draw_surface[200]; - cairo_box_double_t bbox; - - if (pattern->extend == CAIRO_EXTEND_PAD) { - status = _cairo_pdf_surface_add_padded_image_surface (surface, - pattern, - &pdf_pattern->extents, - &pattern_resource, - &pattern_width, - &pattern_height, - &x_offset, - &y_offset); - pattern_extents.x = 0; - pattern_extents.y = 0; - pattern_extents.width = pattern_width; - pattern_extents.height = pattern_height; - } else { - status = _cairo_pdf_surface_add_source_surface (surface, - NULL, - pattern, - pdf_pattern->operator, - pattern->filter, - FALSE, - FALSE, - &pdf_pattern->extents, - NULL, - &pattern_resource, - &pattern_width, - &pattern_height, - &x_offset, - &y_offset, - &pattern_extents); - } - if (unlikely (status)) - return status; - - switch (extend) { - case CAIRO_EXTEND_PAD: - case CAIRO_EXTEND_NONE: - { - /* In PS/PDF, (as far as I can tell), all patterns are - * repeating. So we support cairo's EXTEND_NONE semantics - * by setting the repeat step size to a size large enough - * to guarantee that no more than a single occurrence will - * be visible. - * - * First, map the surface extents into pattern space (since - * xstep and ystep are in pattern space). Then use an upper - * bound on the length of the diagonal of the pattern image - * and the surface as repeat size. This guarantees to never - * repeat visibly. - */ - double x1 = 0.0, y1 = 0.0; - double x2 = surface->width, y2 = surface->height; - _cairo_matrix_transform_bounding_box (&pattern->matrix, - &x1, &y1, &x2, &y2, - NULL); - - /* Rather than computing precise bounds of the union, just - * add the surface extents unconditionally. We only - * required an answer that's large enough, we don't really - * care if it's not as tight as possible.*/ - xstep = ystep = ceil ((x2 - x1) + (y2 - y1) + - pattern_width + pattern_height); - } - break; - case CAIRO_EXTEND_REPEAT: - xstep = pattern_width; - ystep = pattern_height; - break; - case CAIRO_EXTEND_REFLECT: - pattern_extents.x = 0; - pattern_extents.y = 0; - pattern_extents.width = pattern_width*2; - pattern_extents.height = pattern_height*2; - xstep = pattern_width*2; - ystep = pattern_height*2; - break; - /* All the rest (if any) should have been analyzed away, so this - * case should be unreachable. */ - default: - ASSERT_NOT_REACHED; - xstep = 0; - ystep = 0; - } - - /* At this point, (that is, within the surface backend interface), - * the pattern's matrix maps from cairo's device space to cairo's - * pattern space, (both with their origin at the upper-left, and - * cairo's pattern space of size width,height). - * - * Then, we must emit a PDF pattern object that maps from its own - * pattern space, (which has a size that we establish in the BBox - * dictionary entry), to the PDF page's *initial* space, (which - * does not benefit from the Y-axis flipping matrix that we emit - * on each page). So the PDF patterns matrix maps from a - * (width,height) pattern space to a device space with the origin - * in the lower-left corner. - * - * So to handle all of that, we start with an identity matrix for - * the PDF pattern to device matrix. We translate it up by the - * image height then flip it in the Y direction, (moving us from - * the PDF origin to cairo's origin). We then multiply in the - * inverse of the cairo pattern matrix, (since it maps from device - * to pattern, while we're setting up pattern to device). Finally, - * we translate back down by the image height and flip again to - * end up at the lower-left origin that PDF expects. - * - * Additionally, within the stream that paints the pattern itself, - * we are using a PDF image object that has a size of (1,1) so we - * have to scale it up by the image width and height to fill our - * pattern cell. - */ - cairo_p2d = pattern->matrix; - status = cairo_matrix_invert (&cairo_p2d); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - - cairo_matrix_multiply (&pdf_p2d, &cairo_p2d, &surface->cairo_to_pdf); - cairo_matrix_translate (&pdf_p2d, -x_offset, -y_offset); - cairo_matrix_translate (&pdf_p2d, 0.0, pattern_height); - cairo_matrix_scale (&pdf_p2d, 1.0, -1.0); - - _get_bbox_from_extents (pattern_height, &pattern_extents, &bbox); - _cairo_pdf_surface_update_object (surface, pdf_pattern->pattern_res); - status = _cairo_pdf_surface_open_stream (surface, - &pdf_pattern->pattern_res, - FALSE, - " /PatternType 1\n" - " /BBox [ %f %f %f %f ]\n" - " /XStep %f\n" - " /YStep %f\n" - " /TilingType 1\n" - " /PaintType 1\n" - " /Matrix [ %f %f %f %f %f %f ]\n" - " /Resources << /XObject << /x%d %d 0 R >> >>\n", - bbox.p1.x, bbox.p1.y, bbox.p2.x, bbox.p2.y, - xstep, ystep, - pdf_p2d.xx, pdf_p2d.yx, - pdf_p2d.xy, pdf_p2d.yy, - pdf_p2d.x0, pdf_p2d.y0, - pattern_resource.id, - pattern_resource.id); - if (unlikely (status)) - return status; - - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *) pattern)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { - snprintf(draw_surface, - sizeof (draw_surface), - "/x%d Do\n", - pattern_resource.id); - } else { - snprintf(draw_surface, - sizeof (draw_surface), - "q %d 0 0 %d 0 0 cm /x%d Do Q", - pattern_width, - pattern_height, - pattern_resource.id); - } - - if (extend == CAIRO_EXTEND_REFLECT) { - _cairo_output_stream_printf (surface->output, - "q 0 0 %d %d re W n %s Q\n" - "q -1 0 0 1 %d 0 cm 0 0 %d %d re W n %s Q\n" - "q 1 0 0 -1 0 %d cm 0 0 %d %d re W n %s Q\n" - "q -1 0 0 -1 %d %d cm 0 0 %d %d re W n %s Q\n", - pattern_width, pattern_height, - draw_surface, - pattern_width*2, pattern_width, pattern_height, - draw_surface, - pattern_height*2, pattern_width, pattern_height, - draw_surface, - pattern_width*2, pattern_height*2, pattern_width, pattern_height, - draw_surface); - } else { - _cairo_output_stream_printf (surface->output, - " %s \n", - draw_surface); - } - - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) - return status; - - return _cairo_output_stream_get_status (surface->output); -} - -typedef struct _cairo_pdf_color_stop { - double offset; - double color[4]; - cairo_pdf_resource_t resource; -} cairo_pdf_color_stop_t; - -static cairo_int_status_t -cairo_pdf_surface_emit_rgb_linear_function (cairo_pdf_surface_t *surface, - cairo_pdf_color_stop_t *stop1, - cairo_pdf_color_stop_t *stop2, - cairo_pdf_resource_t *function) -{ - int num_elems, i; - cairo_pdf_rgb_linear_function_t elem; - cairo_pdf_resource_t res; - cairo_int_status_t status; - - num_elems = _cairo_array_num_elements (&surface->rgb_linear_functions); - for (i = 0; i < num_elems; i++) { - _cairo_array_copy_element (&surface->rgb_linear_functions, i, &elem); - if (memcmp (&elem.color1[0], &stop1->color[0], sizeof (double)*3) != 0) - continue; - if (memcmp (&elem.color2[0], &stop2->color[0], sizeof (double)*3) != 0) - continue; - *function = elem.resource; - return CAIRO_STATUS_SUCCESS; - } - - res = _cairo_pdf_surface_new_object (surface); - if (res.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /FunctionType 2\n" - " /Domain [ 0 1 ]\n" - " /C0 [ %f %f %f ]\n" - " /C1 [ %f %f %f ]\n" - " /N 1\n" - ">>\n" - "endobj\n", - res.id, - stop1->color[0], - stop1->color[1], - stop1->color[2], - stop2->color[0], - stop2->color[1], - stop2->color[2]); - - elem.resource = res; - memcpy (&elem.color1[0], &stop1->color[0], sizeof (double)*3); - memcpy (&elem.color2[0], &stop2->color[0], sizeof (double)*3); - - status = _cairo_array_append (&surface->rgb_linear_functions, &elem); - *function = res; - - return status; -} - -static cairo_int_status_t -cairo_pdf_surface_emit_alpha_linear_function (cairo_pdf_surface_t *surface, - cairo_pdf_color_stop_t *stop1, - cairo_pdf_color_stop_t *stop2, - cairo_pdf_resource_t *function) -{ - int num_elems, i; - cairo_pdf_alpha_linear_function_t elem; - cairo_pdf_resource_t res; - cairo_int_status_t status; - - num_elems = _cairo_array_num_elements (&surface->alpha_linear_functions); - for (i = 0; i < num_elems; i++) { - _cairo_array_copy_element (&surface->alpha_linear_functions, i, &elem); - if (elem.alpha1 != stop1->color[3]) - continue; - if (elem.alpha2 != stop2->color[3]) - continue; - *function = elem.resource; - return CAIRO_STATUS_SUCCESS; - } - - res = _cairo_pdf_surface_new_object (surface); - if (res.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /FunctionType 2\n" - " /Domain [ 0 1 ]\n" - " /C0 [ %f ]\n" - " /C1 [ %f ]\n" - " /N 1\n" - ">>\n" - "endobj\n", - res.id, - stop1->color[3], - stop2->color[3]); - - elem.resource = res; - elem.alpha1 = stop1->color[3]; - elem.alpha2 = stop2->color[3]; - - status = _cairo_array_append (&surface->alpha_linear_functions, &elem); - *function = res; - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_stitched_colorgradient (cairo_pdf_surface_t *surface, - unsigned int n_stops, - cairo_pdf_color_stop_t *stops, - cairo_bool_t is_alpha, - cairo_pdf_resource_t *function) -{ - cairo_pdf_resource_t res; - unsigned int i; - cairo_int_status_t status; - - /* emit linear gradients between pairs of subsequent stops... */ - for (i = 0; i < n_stops-1; i++) { - if (is_alpha) { - status = cairo_pdf_surface_emit_alpha_linear_function (surface, - &stops[i], - &stops[i+1], - &stops[i].resource); - if (unlikely (status)) - return status; - } else { - status = cairo_pdf_surface_emit_rgb_linear_function (surface, - &stops[i], - &stops[i+1], - &stops[i].resource); - if (unlikely (status)) - return status; - } - } - - /* ... and stitch them together */ - res = _cairo_pdf_surface_new_object (surface); - if (res.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /FunctionType 3\n" - " /Domain [ %f %f ]\n", - res.id, - stops[0].offset, - stops[n_stops - 1].offset); - - _cairo_output_stream_printf (surface->output, - " /Functions [ "); - for (i = 0; i < n_stops-1; i++) - _cairo_output_stream_printf (surface->output, - "%d 0 R ", stops[i].resource.id); - _cairo_output_stream_printf (surface->output, - "]\n"); - - _cairo_output_stream_printf (surface->output, - " /Bounds [ "); - for (i = 1; i < n_stops-1; i++) - _cairo_output_stream_printf (surface->output, - "%f ", stops[i].offset); - _cairo_output_stream_printf (surface->output, - "]\n"); - - _cairo_output_stream_printf (surface->output, - " /Encode [ "); - for (i = 1; i < n_stops; i++) - _cairo_output_stream_printf (surface->output, - "0 1 "); - _cairo_output_stream_printf (surface->output, - "]\n"); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - - *function = res; - - return _cairo_output_stream_get_status (surface->output); -} - - -static void -calc_gradient_color (cairo_pdf_color_stop_t *new_stop, - cairo_pdf_color_stop_t *stop1, - cairo_pdf_color_stop_t *stop2) -{ - int i; - double offset = stop1->offset / (stop1->offset + 1.0 - stop2->offset); - - for (i = 0; i < 4; i++) - new_stop->color[i] = stop1->color[i] + offset*(stop2->color[i] - stop1->color[i]); -} - -#define COLOR_STOP_EPSILON 1e-6 - -static cairo_int_status_t -_cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t *surface, - cairo_gradient_pattern_t *pattern, - cairo_pdf_resource_t *color_function, - cairo_pdf_resource_t *alpha_function) -{ - cairo_pdf_color_stop_t *allstops, *stops; - unsigned int n_stops; - unsigned int i; - cairo_bool_t emit_alpha = FALSE; - cairo_int_status_t status; - - color_function->id = 0; - alpha_function->id = 0; - - allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_pdf_color_stop_t)); - if (unlikely (allstops == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - stops = &allstops[1]; - n_stops = pattern->n_stops; - - for (i = 0; i < n_stops; i++) { - stops[i].color[0] = pattern->stops[i].color.red; - stops[i].color[1] = pattern->stops[i].color.green; - stops[i].color[2] = pattern->stops[i].color.blue; - stops[i].color[3] = pattern->stops[i].color.alpha; - if (!CAIRO_ALPHA_IS_OPAQUE (stops[i].color[3])) - emit_alpha = TRUE; - stops[i].offset = pattern->stops[i].offset; - } - - if (pattern->base.extend == CAIRO_EXTEND_REPEAT || - pattern->base.extend == CAIRO_EXTEND_REFLECT) { - if (stops[0].offset > COLOR_STOP_EPSILON) { - if (pattern->base.extend == CAIRO_EXTEND_REFLECT) - memcpy (allstops, stops, sizeof (cairo_pdf_color_stop_t)); - else - calc_gradient_color (&allstops[0], &stops[0], &stops[n_stops-1]); - stops = allstops; - n_stops++; - } - stops[0].offset = 0.0; - - if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) { - if (pattern->base.extend == CAIRO_EXTEND_REFLECT) { - memcpy (&stops[n_stops], - &stops[n_stops - 1], - sizeof (cairo_pdf_color_stop_t)); - } else { - calc_gradient_color (&stops[n_stops], &stops[0], &stops[n_stops-1]); - } - n_stops++; - } - stops[n_stops-1].offset = 1.0; - } - - if (stops[0].offset == stops[n_stops - 1].offset) { - /* - * The first and the last stops have the same offset, but we - * don't want a function with an empty domain, because that - * would provoke underdefined behaviour from rasterisers. - * This can only happen with EXTEND_PAD, because EXTEND_NONE - * is optimised into a clear pattern in cairo-gstate, and - * REFLECT/REPEAT are always transformed to have the first - * stop at t=0 and the last stop at t=1. Thus we want a step - * function going from the first color to the last one. - * - * This can be accomplished by stitching three functions: - * - a constant first color function, - * - a step from the first color to the last color (with empty domain) - * - a constant last color function - */ - cairo_pdf_color_stop_t pad_stops[4]; - - assert (pattern->base.extend == CAIRO_EXTEND_PAD); - - pad_stops[0] = pad_stops[1] = stops[0]; - pad_stops[2] = pad_stops[3] = stops[n_stops - 1]; - - pad_stops[0].offset = 0; - pad_stops[3].offset = 1; - - status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, - 4, - pad_stops, - FALSE, - color_function); - if (unlikely (status)) - goto BAIL; - - if (emit_alpha) { - status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, - 4, - pad_stops, - TRUE, - alpha_function); - if (unlikely (status)) - goto BAIL; - } - } else if (n_stops == 2) { - /* no need for stitched function */ - status = cairo_pdf_surface_emit_rgb_linear_function (surface, - &stops[0], - &stops[n_stops - 1], - color_function); - if (unlikely (status)) - goto BAIL; - - if (emit_alpha) { - status = cairo_pdf_surface_emit_alpha_linear_function (surface, - &stops[0], - &stops[n_stops - 1], - alpha_function); - if (unlikely (status)) - goto BAIL; - } - } else { - /* multiple stops: stitch. XXX possible optimization: regularly spaced - * stops do not require stitching. XXX */ - status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, - n_stops, - stops, - FALSE, - color_function); - if (unlikely (status)) - goto BAIL; - - if (emit_alpha) { - status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, - n_stops, - stops, - TRUE, - alpha_function); - if (unlikely (status)) - goto BAIL; - } - } - -BAIL: - free (allstops); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_repeating_function (cairo_pdf_surface_t *surface, - cairo_gradient_pattern_t *pattern, - cairo_pdf_resource_t *function, - int begin, - int end) -{ - cairo_pdf_resource_t res; - int i; - - res = _cairo_pdf_surface_new_object (surface); - if (res.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /FunctionType 3\n" - " /Domain [ %d %d ]\n", - res.id, - begin, - end); - - _cairo_output_stream_printf (surface->output, - " /Functions [ "); - for (i = begin; i < end; i++) - _cairo_output_stream_printf (surface->output, - "%d 0 R ", function->id); - _cairo_output_stream_printf (surface->output, - "]\n"); - - _cairo_output_stream_printf (surface->output, - " /Bounds [ "); - for (i = begin + 1; i < end; i++) - _cairo_output_stream_printf (surface->output, - "%d ", i); - _cairo_output_stream_printf (surface->output, - "]\n"); - - _cairo_output_stream_printf (surface->output, - " /Encode [ "); - for (i = begin; i < end; i++) { - if ((i % 2) && pattern->base.extend == CAIRO_EXTEND_REFLECT) { - _cairo_output_stream_printf (surface->output, - "1 0 "); - } else { - _cairo_output_stream_printf (surface->output, - "0 1 "); - } - } - _cairo_output_stream_printf (surface->output, - "]\n"); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - - *function = res; - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -cairo_pdf_surface_emit_transparency_group (cairo_pdf_surface_t *surface, - cairo_pdf_pattern_t *pdf_pattern, - cairo_pdf_resource_t gstate_resource, - cairo_pdf_resource_t gradient_mask) -{ - cairo_pdf_resource_t smask_resource; - cairo_int_status_t status; - char buf[100]; - double x1, y1, x2, y2; - - if (pdf_pattern->is_shading) { - snprintf(buf, sizeof(buf), - " /Shading\n" - " << /sh%d %d 0 R >>\n", - gradient_mask.id, - gradient_mask.id); - } else { - snprintf(buf, sizeof(buf), - " /Pattern\n" - " << /p%d %d 0 R >>\n", - gradient_mask.id, - gradient_mask.id); - } - - if (pdf_pattern->is_shading) { - cairo_box_t box; - - /* When emitting a shading operator we are in cairo pattern - * coordinates. _cairo_pdf_surface_paint_gradient has set the - * ctm to the pattern matrix (including the convertion from - * pdf to cairo coordinates) */ - _cairo_box_from_rectangle (&box, &pdf_pattern->extents); - _cairo_box_to_doubles (&box, &x1, &y1, &x2, &y2); - _cairo_matrix_transform_bounding_box (&pdf_pattern->pattern->matrix, &x1, &y1, &x2, &y2, NULL); - } else { - cairo_box_double_t box; - - /* When emitting a shading pattern we are in pdf page - * coordinates. The color and alpha shading patterns painted - * in the XObject below contain the cairo pattern to pdf page - * matrix in the /Matrix entry of the pattern. */ - _get_bbox_from_extents (pdf_pattern->height, &pdf_pattern->extents, &box); - x1 = box.p1.x; - y1 = box.p1.y; - x2 = box.p2.x; - y2 = box.p2.y; - } - status = _cairo_pdf_surface_open_stream (surface, - NULL, - surface->compress_content, - " /Type /XObject\n" - " /Subtype /Form\n" - " /FormType 1\n" - " /BBox [ %f %f %f %f ]\n" - " /Resources\n" - " << /ExtGState\n" - " << /a0 << /ca 1 /CA 1 >>" - " >>\n" - "%s" - " >>\n" - " /Group\n" - " << /Type /Group\n" - " /S /Transparency\n" - " /I true\n" - " /CS /DeviceGray\n" - " >>\n", - x1,y1,x2,y2, - buf); - if (unlikely (status)) - return status; - - if (pdf_pattern->is_shading) { - _cairo_output_stream_printf (surface->output, - "/a0 gs /sh%d sh\n", - gradient_mask.id); - } else { - _cairo_output_stream_printf (surface->output, - "q\n" - "/a0 gs\n" - "/Pattern cs /p%d scn\n" - "0 0 %f %f re\n" - "f\n" - "Q\n", - gradient_mask.id, - surface->width, - surface->height); - } - - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) - return status; - - smask_resource = _cairo_pdf_surface_new_object (surface); - if (smask_resource.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Mask\n" - " /S /Luminosity\n" - " /G %d 0 R\n" - ">>\n" - "endobj\n", - smask_resource.id, - surface->pdf_stream.self.id); - - /* Create GState which uses the transparency group as an SMask. */ - _cairo_pdf_surface_update_object (surface, gstate_resource); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /ExtGState\n" - " /SMask %d 0 R\n" - " /ca 1\n" - " /CA 1\n" - " /AIS false\n" - ">>\n" - "endobj\n", - gstate_resource.id, - smask_resource.id); - - return _cairo_output_stream_get_status (surface->output); -} - -static void -_cairo_pdf_surface_output_gradient (cairo_pdf_surface_t *surface, - const cairo_pdf_pattern_t *pdf_pattern, - cairo_pdf_resource_t pattern_resource, - const cairo_matrix_t *pat_to_pdf, - const cairo_circle_double_t*start, - const cairo_circle_double_t*end, - const double *domain, - const char *colorspace, - cairo_pdf_resource_t color_function) -{ - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n", - pattern_resource.id); - - if (!pdf_pattern->is_shading) { - _cairo_output_stream_printf (surface->output, - "<< /Type /Pattern\n" - " /PatternType 2\n" - " /Matrix [ "); - _cairo_output_stream_print_matrix (surface->output, pat_to_pdf); - _cairo_output_stream_printf (surface->output, - " ]\n" - " /Shading\n"); - } - - if (pdf_pattern->pattern->type == CAIRO_PATTERN_TYPE_LINEAR) { - _cairo_output_stream_printf (surface->output, - " << /ShadingType 2\n" - " /ColorSpace %s\n" - " /Coords [ %f %f %f %f ]\n", - colorspace, - start->center.x, start->center.y, - end->center.x, end->center.y); - } else { - _cairo_output_stream_printf (surface->output, - " << /ShadingType 3\n" - " /ColorSpace %s\n" - " /Coords [ %f %f %f %f %f %f ]\n", - colorspace, - start->center.x, start->center.y, - MAX (start->radius, 0), - end->center.x, end->center.y, - MAX (end->radius, 0)); - } - - _cairo_output_stream_printf (surface->output, - " /Domain [ %f %f ]\n", - domain[0], domain[1]); - - if (pdf_pattern->pattern->extend != CAIRO_EXTEND_NONE) { - _cairo_output_stream_printf (surface->output, - " /Extend [ true true ]\n"); - } else { - _cairo_output_stream_printf (surface->output, - " /Extend [ false false ]\n"); - } - - _cairo_output_stream_printf (surface->output, - " /Function %d 0 R\n" - " >>\n", - color_function.id); - - if (!pdf_pattern->is_shading) { - _cairo_output_stream_printf (surface->output, - ">>\n"); - } - - _cairo_output_stream_printf (surface->output, - "endobj\n"); -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_gradient (cairo_pdf_surface_t *surface, - cairo_pdf_pattern_t *pdf_pattern) -{ - cairo_gradient_pattern_t *pattern = (cairo_gradient_pattern_t *) pdf_pattern->pattern; - cairo_pdf_resource_t color_function, alpha_function; - cairo_matrix_t pat_to_pdf; - cairo_circle_double_t start, end; - double domain[2]; - cairo_int_status_t status; - - assert (pattern->n_stops != 0); - - status = _cairo_pdf_surface_emit_pattern_stops (surface, - pattern, - &color_function, - &alpha_function); - if (unlikely (status)) - return status; - - pat_to_pdf = pattern->base.matrix; - status = cairo_matrix_invert (&pat_to_pdf); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf); - - if (pattern->base.extend == CAIRO_EXTEND_REPEAT || - pattern->base.extend == CAIRO_EXTEND_REFLECT) - { - double bounds_x1, bounds_x2, bounds_y1, bounds_y2; - double x_scale, y_scale, tolerance; - - /* TODO: use tighter extents */ - bounds_x1 = 0; - bounds_y1 = 0; - bounds_x2 = surface->width; - bounds_y2 = surface->height; - _cairo_matrix_transform_bounding_box (&pattern->base.matrix, - &bounds_x1, &bounds_y1, - &bounds_x2, &bounds_y2, - NULL); - - x_scale = surface->base.x_resolution / surface->base.x_fallback_resolution; - y_scale = surface->base.y_resolution / surface->base.y_fallback_resolution; - - tolerance = fabs (_cairo_matrix_compute_determinant (&pattern->base.matrix)); - tolerance /= _cairo_matrix_transformed_circle_major_axis (&pattern->base.matrix, 1); - tolerance *= MIN (x_scale, y_scale); - - _cairo_gradient_pattern_box_to_parameter (pattern, - bounds_x1, bounds_y1, - bounds_x2, bounds_y2, - tolerance, domain); - } else if (pattern->stops[0].offset == pattern->stops[pattern->n_stops - 1].offset) { - /* - * If the first and the last stop offset are the same, then - * the color function is a step function. - * _cairo_ps_surface_emit_pattern_stops emits it as a stitched - * function no matter how many stops the pattern has. The - * domain of the stitched function will be [0 1] in this case. - * - * This is done to avoid emitting degenerate gradients for - * EXTEND_PAD patterns having a step color function. - */ - domain[0] = 0.0; - domain[1] = 1.0; - - assert (pattern->base.extend == CAIRO_EXTEND_PAD); - } else { - domain[0] = pattern->stops[0].offset; - domain[1] = pattern->stops[pattern->n_stops - 1].offset; - } - - /* PDF requires the first and last stop to be the same as the - * extreme coordinates. For repeating patterns this moves the - * extreme coordinates out to the begin/end of the repeating - * function. For non repeating patterns this may move the extreme - * coordinates in if there are not stops at offset 0 and 1. */ - _cairo_gradient_pattern_interpolate (pattern, domain[0], &start); - _cairo_gradient_pattern_interpolate (pattern, domain[1], &end); - - if (pattern->base.extend == CAIRO_EXTEND_REPEAT || - pattern->base.extend == CAIRO_EXTEND_REFLECT) - { - int repeat_begin, repeat_end; - - repeat_begin = floor (domain[0]); - repeat_end = ceil (domain[1]); - - status = _cairo_pdf_surface_emit_repeating_function (surface, - pattern, - &color_function, - repeat_begin, - repeat_end); - if (unlikely (status)) - return status; - - if (alpha_function.id != 0) { - status = _cairo_pdf_surface_emit_repeating_function (surface, - pattern, - &alpha_function, - repeat_begin, - repeat_end); - if (unlikely (status)) - return status; - } - } else if (pattern->n_stops <= 2) { - /* For EXTEND_NONE and EXTEND_PAD if there are only two stops a - * Type 2 function is used by itself without a stitching - * function. Type 2 functions always have the domain [0 1] */ - domain[0] = 0.0; - domain[1] = 1.0; - } - - _cairo_pdf_surface_update_object (surface, pdf_pattern->pattern_res); - _cairo_pdf_surface_output_gradient (surface, pdf_pattern, - pdf_pattern->pattern_res, - &pat_to_pdf, &start, &end, domain, - "/DeviceRGB", color_function); - - if (alpha_function.id != 0) { - cairo_pdf_resource_t mask_resource; - - assert (pdf_pattern->gstate_res.id != 0); - - /* Create pattern for SMask. */ - mask_resource = _cairo_pdf_surface_new_object (surface); - if (mask_resource.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_pdf_surface_output_gradient (surface, pdf_pattern, - mask_resource, - &pat_to_pdf, &start, &end, domain, - "/DeviceGray", alpha_function); - - status = cairo_pdf_surface_emit_transparency_group (surface, - pdf_pattern, - pdf_pattern->gstate_res, - mask_resource); - if (unlikely (status)) - return status; - } - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_mesh_pattern (cairo_pdf_surface_t *surface, - cairo_pdf_pattern_t *pdf_pattern) -{ - cairo_matrix_t pat_to_pdf; - cairo_int_status_t status; - cairo_pattern_t *pattern = pdf_pattern->pattern; - cairo_pdf_shading_t shading; - int i; - cairo_pdf_resource_t res; - - pat_to_pdf = pattern->matrix; - status = cairo_matrix_invert (&pat_to_pdf); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - - cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf); - - status = _cairo_pdf_shading_init_color (&shading, (cairo_mesh_pattern_t *) pattern); - if (unlikely (status)) - return status; - - res = _cairo_pdf_surface_new_object (surface); - if (unlikely (res.id == 0)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /ShadingType %d\n" - " /ColorSpace /DeviceRGB\n" - " /BitsPerCoordinate %d\n" - " /BitsPerComponent %d\n" - " /BitsPerFlag %d\n" - " /Decode [", - res.id, - shading.shading_type, - shading.bits_per_coordinate, - shading.bits_per_component, - shading.bits_per_flag); - - for (i = 0; i < shading.decode_array_length; i++) - _cairo_output_stream_printf (surface->output, "%f ", shading.decode_array[i]); - - _cairo_output_stream_printf (surface->output, - "]\n" - " /Length %ld\n" - ">>\n" - "stream\n", - shading.data_length); - - _cairo_output_stream_write (surface->output, shading.data, shading.data_length); - - _cairo_output_stream_printf (surface->output, - "\nendstream\n" - "endobj\n"); - - _cairo_pdf_shading_fini (&shading); - - _cairo_pdf_surface_update_object (surface, pdf_pattern->pattern_res); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Pattern\n" - " /PatternType 2\n" - " /Matrix [ ", - pdf_pattern->pattern_res.id); - _cairo_output_stream_print_matrix (surface->output, &pat_to_pdf); - _cairo_output_stream_printf (surface->output, - " ]\n" - " /Shading %d 0 R\n" - ">>\n" - "endobj\n", - res.id); - - if (pdf_pattern->gstate_res.id != 0) { - cairo_pdf_resource_t mask_resource; - - /* Create pattern for SMask. */ - res = _cairo_pdf_surface_new_object (surface); - if (unlikely (res.id == 0)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_pdf_shading_init_alpha (&shading, (cairo_mesh_pattern_t *) pattern); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /ShadingType %d\n" - " /ColorSpace /DeviceGray\n" - " /BitsPerCoordinate %d\n" - " /BitsPerComponent %d\n" - " /BitsPerFlag %d\n" - " /Decode [", - res.id, - shading.shading_type, - shading.bits_per_coordinate, - shading.bits_per_component, - shading.bits_per_flag); - - for (i = 0; i < shading.decode_array_length; i++) - _cairo_output_stream_printf (surface->output, "%f ", shading.decode_array[i]); - - _cairo_output_stream_printf (surface->output, - "]\n" - " /Length %ld\n" - ">>\n" - "stream\n", - shading.data_length); - - _cairo_output_stream_write (surface->output, shading.data, shading.data_length); - - _cairo_output_stream_printf (surface->output, - "\nendstream\n" - "endobj\n"); - _cairo_pdf_shading_fini (&shading); - - mask_resource = _cairo_pdf_surface_new_object (surface); - if (unlikely (mask_resource.id == 0)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Pattern\n" - " /PatternType 2\n" - " /Matrix [ ", - mask_resource.id); - _cairo_output_stream_print_matrix (surface->output, &pat_to_pdf); - _cairo_output_stream_printf (surface->output, - " ]\n" - " /Shading %d 0 R\n" - ">>\n" - "endobj\n", - res.id); - - status = cairo_pdf_surface_emit_transparency_group (surface, - pdf_pattern, - pdf_pattern->gstate_res, - mask_resource); - if (unlikely (status)) - return status; - } - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_pattern (cairo_pdf_surface_t *surface, cairo_pdf_pattern_t *pdf_pattern) -{ - double old_width, old_height; - cairo_int_status_t status; - - old_width = surface->width; - old_height = surface->height; - _cairo_pdf_surface_set_size_internal (surface, - pdf_pattern->width, - pdf_pattern->height); - - switch (pdf_pattern->pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - ASSERT_NOT_REACHED; - status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - break; - - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - status = _cairo_pdf_surface_emit_surface_pattern (surface, pdf_pattern); - break; - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - status = _cairo_pdf_surface_emit_gradient (surface, pdf_pattern); - break; - - case CAIRO_PATTERN_TYPE_MESH: - status = _cairo_pdf_surface_emit_mesh_pattern (surface, pdf_pattern); - break; - - default: - ASSERT_NOT_REACHED; - status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); - break; - } - - _cairo_pdf_surface_set_size_internal (surface, - old_width, - old_height); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_paint_surface_pattern (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_rectangle_int_t *extents, - cairo_pdf_resource_t *smask_res, - cairo_bool_t stencil_mask) -{ - cairo_pdf_resource_t surface_res; - int width, height; - cairo_matrix_t cairo_p2d, pdf_p2d; - cairo_int_status_t status; - int alpha; - cairo_rectangle_int_t extents2; - double x_offset; - double y_offset; - - if (source->extend == CAIRO_EXTEND_PAD && - !(source->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *)source)->surface->type == CAIRO_SURFACE_TYPE_RECORDING)) - { - status = _cairo_pdf_surface_add_padded_image_surface (surface, - source, - extents, - &surface_res, - &width, - &height, - &x_offset, - &y_offset); - } else { - status = _cairo_pdf_surface_add_source_surface (surface, - NULL, - source, - op, - source->filter, - stencil_mask, - FALSE, - extents, - smask_res, - &surface_res, - &width, - &height, - &x_offset, - &y_offset, - &extents2); - } - if (unlikely (status)) - return status; - - cairo_p2d = source->matrix; - status = cairo_matrix_invert (&cairo_p2d); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - - pdf_p2d = surface->cairo_to_pdf; - cairo_matrix_multiply (&pdf_p2d, &cairo_p2d, &pdf_p2d); - cairo_matrix_translate (&pdf_p2d, x_offset, y_offset); - cairo_matrix_translate (&pdf_p2d, 0.0, height); - cairo_matrix_scale (&pdf_p2d, 1.0, -1.0); - if (!(source->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *)source)->surface->type == CAIRO_SURFACE_TYPE_RECORDING)) - { - cairo_matrix_scale (&pdf_p2d, width, height); - } - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - if (! _cairo_matrix_is_identity (&pdf_p2d)) { - _cairo_output_stream_print_matrix (surface->output, &pdf_p2d); - _cairo_output_stream_printf (surface->output, " cm\n"); - } - - status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); - if (unlikely (status)) - return status; - - if (stencil_mask) { - _cairo_output_stream_printf (surface->output, - "/x%d Do\n", - surface_res.id); - } else { - _cairo_output_stream_printf (surface->output, - "/a%d gs /x%d Do\n", - alpha, - surface_res.id); - } - - return _cairo_pdf_surface_add_xobject (surface, surface_res); -} - -static cairo_int_status_t -_cairo_pdf_surface_paint_gradient (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_rectangle_int_t *extents) -{ - cairo_pdf_resource_t shading_res, gstate_res; - cairo_matrix_t pat_to_pdf; - cairo_int_status_t status; - int alpha; - - status = _cairo_pdf_surface_add_pdf_shading (surface, source, - op, extents, - &shading_res, &gstate_res); - if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO)) - return CAIRO_INT_STATUS_SUCCESS; - if (unlikely (status)) - return status; - - pat_to_pdf = source->matrix; - status = cairo_matrix_invert (&pat_to_pdf); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf); - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - if (! _cairo_matrix_is_identity (&pat_to_pdf)) { - _cairo_output_stream_print_matrix (surface->output, &pat_to_pdf); - _cairo_output_stream_printf (surface->output, " cm\n"); - } - - status = _cairo_pdf_surface_add_shading (surface, shading_res); - if (unlikely (status)) - return status; - - if (gstate_res.id != 0) { - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "/s%d gs /sh%d sh\n", - gstate_res.id, - shading_res.id); - } else { - status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "/a%d gs /sh%d sh\n", - alpha, - shading_res.id); - } - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_paint_pattern (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_rectangle_int_t *extents, - cairo_bool_t mask) -{ - switch (source->type) { - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _cairo_pdf_surface_paint_surface_pattern (surface, - op, - source, - extents, - NULL, - mask); - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - return _cairo_pdf_surface_paint_gradient (surface, - op, - source, - extents); - - case CAIRO_PATTERN_TYPE_SOLID: - default: - ASSERT_NOT_REACHED; - return CAIRO_STATUS_SUCCESS; - } -} - -static cairo_bool_t -_can_paint_pattern (const cairo_pattern_t *pattern) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return FALSE; - - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return (pattern->extend == CAIRO_EXTEND_NONE || - pattern->extend == CAIRO_EXTEND_PAD); - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - return TRUE; - - case CAIRO_PATTERN_TYPE_MESH: - return FALSE; - - default: - ASSERT_NOT_REACHED; - return FALSE; - } -} - -static cairo_int_status_t -_cairo_pdf_surface_select_operator (cairo_pdf_surface_t *surface, - cairo_operator_t op) -{ - cairo_int_status_t status; - - if (op == surface->current_operator) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "/b%d gs\n", op); - surface->current_operator = op; - _cairo_pdf_surface_add_operator (surface, op); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_pdf_resource_t pattern_res, - cairo_bool_t is_stroke) -{ - cairo_int_status_t status; - int alpha; - const cairo_color_t *solid_color = NULL; - - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { - const cairo_solid_pattern_t *solid = (const cairo_solid_pattern_t *) pattern; - - solid_color = &solid->color; - } - - if (solid_color != NULL) { - if (surface->current_pattern_is_solid_color == FALSE || - surface->current_color_red != solid_color->red || - surface->current_color_green != solid_color->green || - surface->current_color_blue != solid_color->blue || - surface->current_color_is_stroke != is_stroke) - { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "%f %f %f ", - solid_color->red, - solid_color->green, - solid_color->blue); - - if (is_stroke) - _cairo_output_stream_printf (surface->output, "RG "); - else - _cairo_output_stream_printf (surface->output, "rg "); - - surface->current_color_red = solid_color->red; - surface->current_color_green = solid_color->green; - surface->current_color_blue = solid_color->blue; - surface->current_color_is_stroke = is_stroke; - } - - if (surface->current_pattern_is_solid_color == FALSE || - surface->current_color_alpha != solid_color->alpha) - { - status = _cairo_pdf_surface_add_alpha (surface, solid_color->alpha, &alpha); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "/a%d gs\n", - alpha); - surface->current_color_alpha = solid_color->alpha; - } - - surface->current_pattern_is_solid_color = TRUE; - } else { - status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_add_pattern (surface, pattern_res); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - /* fill-stroke calls select_pattern twice. Don't save if the - * gstate is already saved. */ - if (!surface->select_pattern_gstate_saved) - _cairo_output_stream_printf (surface->output, "q "); - - if (is_stroke) { - _cairo_output_stream_printf (surface->output, - "/Pattern CS /p%d SCN ", - pattern_res.id); - } else { - _cairo_output_stream_printf (surface->output, - "/Pattern cs /p%d scn ", - pattern_res.id); - } - _cairo_output_stream_printf (surface->output, - "/a%d gs\n", - alpha); - surface->select_pattern_gstate_saved = TRUE; - surface->current_pattern_is_solid_color = FALSE; - } - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -_cairo_pdf_surface_unselect_pattern (cairo_pdf_surface_t *surface) -{ - cairo_int_status_t status; - - if (surface->select_pattern_gstate_saved) { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "Q\n"); - _cairo_pdf_operators_reset (&surface->pdf_operators); - surface->current_pattern_is_solid_color = FALSE; - } - surface->select_pattern_gstate_saved = FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_show_page (void *abstract_surface) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - status = _cairo_pdf_surface_close_content_stream (surface); - if (unlikely (status)) - return status; - - _cairo_surface_clipper_reset (&surface->clipper); - - status = _cairo_pdf_surface_write_page (surface); - if (unlikely (status)) - return status; - - _cairo_pdf_surface_clear (surface); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_pdf_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_pdf_surface_t *surface = abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - - /* XXX: The conversion to integers here is pretty bogus, (not to - * mention the arbitrary limitation of width to a short(!). We - * may need to come up with a better interface for get_size. - */ - rectangle->width = ceil (surface->width); - rectangle->height = ceil (surface->height); - - return TRUE; -} - -static void -_cairo_pdf_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - _cairo_font_options_init_default (options); - - cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); - cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); - _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); -} - -static cairo_pdf_resource_t -_cairo_pdf_surface_write_info (cairo_pdf_surface_t *surface) -{ - cairo_pdf_resource_t info; - - info = _cairo_pdf_surface_new_object (surface); - if (info.id == 0) - return info; - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Creator (cairo %s (http://cairographics.org))\n" - " /Producer (cairo %s (http://cairographics.org))\n" - ">>\n" - "endobj\n", - info.id, - cairo_version_string (), - cairo_version_string ()); - - return info; -} - -static void -_cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface) -{ - cairo_pdf_resource_t page; - int num_pages, i; - - _cairo_pdf_surface_update_object (surface, surface->pages_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Pages\n" - " /Kids [ ", - surface->pages_resource.id); - - num_pages = _cairo_array_num_elements (&surface->pages); - for (i = 0; i < num_pages; i++) { - _cairo_array_copy_element (&surface->pages, i, &page); - _cairo_output_stream_printf (surface->output, "%d 0 R ", page.id); - } - - _cairo_output_stream_printf (surface->output, "]\n"); - _cairo_output_stream_printf (surface->output, " /Count %d\n", num_pages); - - - /* TODO: Figure out which other defaults to be inherited by /Page - * objects. */ - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); -} - -static cairo_int_status_t -_utf8_to_pdf_string (const char *utf8, char **str_out) -{ - int i; - int len; - cairo_bool_t ascii; - char *str; - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - - ascii = TRUE; - len = strlen (utf8); - for (i = 0; i < len; i++) { - unsigned c = utf8[i]; - if (c < 32 || c > 126 || c == '(' || c == ')' || c == '\\') { - ascii = FALSE; - break; - } - } - - if (ascii) { - str = malloc (len + 3); - if (str == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - str[0] = '('; - for (i = 0; i < len; i++) - str[i+1] = utf8[i]; - str[i+1] = ')'; - str[i+2] = 0; - } else { - uint16_t *utf16 = NULL; - int utf16_len = 0; - - status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len); - if (unlikely (status)) - return status; - - str = malloc (utf16_len*4 + 7); - if (str == NULL) { - free (utf16); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - strcpy (str, ""); - free (utf16); - } - *str_out = str; - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_unicode_for_glyph (cairo_pdf_surface_t *surface, - const char *utf8) -{ - uint16_t *utf16 = NULL; - int utf16_len = 0; - cairo_int_status_t status; - int i; - - if (utf8 && *utf8) { - status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len); - if (unlikely (status)) - return status; - } - - _cairo_output_stream_printf (surface->output, "<"); - if (utf16 == NULL || utf16_len == 0) { - /* According to the "ToUnicode Mapping File Tutorial" - * http://www.adobe.com/devnet/acrobat/pdfs/5411.ToUnicode.pdf - * - * Glyphs that do not map to a Unicode code point must be - * mapped to 0xfffd "REPLACEMENT CHARACTER". - */ - _cairo_output_stream_printf (surface->output, - "fffd"); - } else { - for (i = 0; i < utf16_len; i++) - _cairo_output_stream_printf (surface->output, - "%04x", (int) (utf16[i])); - } - _cairo_output_stream_printf (surface->output, ">"); - - free (utf16); - - return CAIRO_STATUS_SUCCESS; -} - -/* Bob Jenkins hash - * - * Public domain code from: - * http://burtleburtle.net/bob/hash/doobs.html - */ - -#define HASH_MIX(a,b,c) \ -{ \ - a -= b; a -= c; a ^= (c>>13); \ - b -= c; b -= a; b ^= (a<<8); \ - c -= a; c -= b; c ^= (b>>13); \ - a -= b; a -= c; a ^= (c>>12); \ - b -= c; b -= a; b ^= (a<<16); \ - c -= a; c -= b; c ^= (b>>5); \ - a -= b; a -= c; a ^= (c>>3); \ - b -= c; b -= a; b ^= (a<<10); \ - c -= a; c -= b; c ^= (b>>15); \ -} - -static uint32_t -_hash_data (const unsigned char *data, int length, uint32_t initval) -{ - uint32_t a, b, c, len; - - len = length; - a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */ - c = initval; /* the previous hash value */ - - while (len >= 12) { - a += (data[0] + ((uint32_t)data[1]<<8) + ((uint32_t)data[2]<<16) + ((uint32_t)data[3]<<24)); - b += (data[4] + ((uint32_t)data[5]<<8) + ((uint32_t)data[6]<<16) + ((uint32_t)data[7]<<24)); - c += (data[8] + ((uint32_t)data[9]<<8) + ((uint32_t)data[10]<<16)+ ((uint32_t)data[11]<<24)); - HASH_MIX (a,b,c); - data += 12; - len -= 12; - } - - c += length; - switch(len) { - case 11: c+= ((uint32_t) data[10] << 24); - case 10: c+= ((uint32_t) data[9] << 16); - case 9 : c+= ((uint32_t) data[8] << 8); - case 8 : b+= ((uint32_t) data[7] << 24); - case 7 : b+= ((uint32_t) data[6] << 16); - case 6 : b+= ((uint32_t) data[5] << 8); - case 5 : b+= data[4]; - case 4 : a+= ((uint32_t) data[3] << 24); - case 3 : a+= ((uint32_t) data[2] << 16); - case 2 : a+= ((uint32_t) data[1] << 8); - case 1 : a+= data[0]; - } - HASH_MIX (a,b,c); - - return c; -} - -static void -_create_font_subset_tag (cairo_scaled_font_subset_t *font_subset, - const char *font_name, - char *tag) -{ - uint32_t hash; - int i; - long numerator; - ldiv_t d; - - hash = _hash_data ((unsigned char *) font_name, strlen(font_name), 0); - hash = _hash_data ((unsigned char *) (font_subset->glyphs), - font_subset->num_glyphs * sizeof(unsigned long), hash); - - numerator = abs (hash); - for (i = 0; i < 6; i++) { - d = ldiv (numerator, 26); - numerator = d.quot; - tag[i] = 'A' + d.rem; - } - tag[i] = 0; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset, - cairo_pdf_resource_t *stream) -{ - unsigned int i, num_bfchar; - cairo_int_status_t status; - - stream->id = 0; - - status = _cairo_pdf_surface_open_stream (surface, - NULL, - surface->compress_content, - NULL); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "/CIDInit /ProcSet findresource begin\n" - "12 dict begin\n" - "begincmap\n" - "/CIDSystemInfo\n" - "<< /Registry (Adobe)\n" - " /Ordering (UCS)\n" - " /Supplement 0\n" - ">> def\n" - "/CMapName /Adobe-Identity-UCS def\n" - "/CMapType 2 def\n" - "1 begincodespacerange\n"); - - if (font_subset->is_composite && !font_subset->is_latin) { - _cairo_output_stream_printf (surface->output, - "<0000> \n"); - } else { - _cairo_output_stream_printf (surface->output, - "<00> \n"); - } - - _cairo_output_stream_printf (surface->output, - "endcodespacerange\n"); - - if (font_subset->is_scaled) { - /* Type 3 fonts include glyph 0 in the subset */ - num_bfchar = font_subset->num_glyphs; - - /* The CMap specification has a limit of 100 characters per beginbfchar operator */ - _cairo_output_stream_printf (surface->output, - "%d beginbfchar\n", - num_bfchar > 100 ? 100 : num_bfchar); - - for (i = 0; i < num_bfchar; i++) { - if (i != 0 && i % 100 == 0) { - _cairo_output_stream_printf (surface->output, - "endbfchar\n" - "%d beginbfchar\n", - num_bfchar - i > 100 ? 100 : num_bfchar - i); - } - _cairo_output_stream_printf (surface->output, "<%02x> ", i); - status = _cairo_pdf_surface_emit_unicode_for_glyph (surface, - font_subset->utf8[i]); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "\n"); - } - } else { - /* Other fonts reserve glyph 0 for .notdef. Omit glyph 0 from the /ToUnicode map */ - num_bfchar = font_subset->num_glyphs - 1; - - /* The CMap specification has a limit of 100 characters per beginbfchar operator */ - _cairo_output_stream_printf (surface->output, - "%d beginbfchar\n", - num_bfchar > 100 ? 100 : num_bfchar); - - for (i = 0; i < num_bfchar; i++) { - if (i != 0 && i % 100 == 0) { - _cairo_output_stream_printf (surface->output, - "endbfchar\n" - "%d beginbfchar\n", - num_bfchar - i > 100 ? 100 : num_bfchar - i); - } - if (font_subset->is_latin) - _cairo_output_stream_printf (surface->output, "<%02x> ", font_subset->to_latin_char[i + 1]); - else if (font_subset->is_composite) - _cairo_output_stream_printf (surface->output, "<%04x> ", i + 1); - else - _cairo_output_stream_printf (surface->output, "<%02x> ", i + 1); - - status = _cairo_pdf_surface_emit_unicode_for_glyph (surface, - font_subset->utf8[i + 1]); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "\n"); - } - } - - _cairo_output_stream_printf (surface->output, - "endbfchar\n"); - - _cairo_output_stream_printf (surface->output, - "endcmap\n" - "CMapName currentdict /CMap defineresource pop\n" - "end\n" - "end\n"); - - *stream = surface->pdf_stream.self; - return _cairo_pdf_surface_close_stream (surface); -} - -#define PDF_UNITS_PER_EM 1000 - -static cairo_int_status_t -_cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset, - cairo_cff_subset_t *subset) -{ - cairo_pdf_resource_t stream, descriptor, cidfont_dict; - cairo_pdf_resource_t subset_resource, to_unicode_stream; - cairo_pdf_font_t font; - unsigned int i, last_glyph; - cairo_int_status_t status; - char tag[10]; - - _create_font_subset_tag (font_subset, subset->ps_name, tag); - - subset_resource = _cairo_pdf_surface_get_font_resource (surface, - font_subset->font_id, - font_subset->subset_id); - if (subset_resource.id == 0) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_pdf_surface_open_stream (surface, - NULL, - TRUE, - font_subset->is_latin ? - " /Subtype /Type1C\n" : - " /Subtype /CIDFontType0C\n"); - if (unlikely (status)) - return status; - - stream = surface->pdf_stream.self; - _cairo_output_stream_write (surface->output, - subset->data, subset->data_length); - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_to_unicode_stream (surface, - font_subset, - &to_unicode_stream); - if (_cairo_int_status_is_error (status)) - return status; - - descriptor = _cairo_pdf_surface_new_object (surface); - if (descriptor.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /FontDescriptor\n" - " /FontName /%s+%s\n", - descriptor.id, - tag, - subset->ps_name); - - if (subset->family_name_utf8) { - char *pdf_str; - - status = _utf8_to_pdf_string (subset->family_name_utf8, &pdf_str); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - " /FontFamily %s\n", - pdf_str); - free (pdf_str); - } - - _cairo_output_stream_printf (surface->output, - " /Flags 4\n" - " /FontBBox [ %ld %ld %ld %ld ]\n" - " /ItalicAngle 0\n" - " /Ascent %ld\n" - " /Descent %ld\n" - " /CapHeight %ld\n" - " /StemV 80\n" - " /StemH 80\n" - " /FontFile3 %u 0 R\n" - ">>\n" - "endobj\n", - (long)(subset->x_min*PDF_UNITS_PER_EM), - (long)(subset->y_min*PDF_UNITS_PER_EM), - (long)(subset->x_max*PDF_UNITS_PER_EM), - (long)(subset->y_max*PDF_UNITS_PER_EM), - (long)(subset->ascent*PDF_UNITS_PER_EM), - (long)(subset->descent*PDF_UNITS_PER_EM), - (long)(subset->y_max*PDF_UNITS_PER_EM), - stream.id); - - if (font_subset->is_latin) { - /* find last glyph used */ - for (i = 255; i >= 32; i--) - if (font_subset->latin_to_subset_glyph_index[i] > 0) - break; - - last_glyph = i; - _cairo_pdf_surface_update_object (surface, subset_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /Type1\n" - " /BaseFont /%s+%s\n" - " /FirstChar 32\n" - " /LastChar %d\n" - " /FontDescriptor %d 0 R\n" - " /Encoding /WinAnsiEncoding\n" - " /Widths [", - subset_resource.id, - tag, - subset->ps_name, - last_glyph, - descriptor.id); - - for (i = 32; i < last_glyph + 1; i++) { - int glyph = font_subset->latin_to_subset_glyph_index[i]; - if (glyph > 0) { - _cairo_output_stream_printf (surface->output, - " %ld", - (long)(subset->widths[glyph]*PDF_UNITS_PER_EM)); - } else { - _cairo_output_stream_printf (surface->output, " 0"); - } - } - - _cairo_output_stream_printf (surface->output, - " ]\n"); - - if (to_unicode_stream.id != 0) - _cairo_output_stream_printf (surface->output, - " /ToUnicode %d 0 R\n", - to_unicode_stream.id); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - } else { - cidfont_dict = _cairo_pdf_surface_new_object (surface); - if (cidfont_dict.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /CIDFontType0\n" - " /BaseFont /%s+%s\n" - " /CIDSystemInfo\n" - " << /Registry (Adobe)\n" - " /Ordering (Identity)\n" - " /Supplement 0\n" - " >>\n" - " /FontDescriptor %d 0 R\n" - " /W [0 [", - cidfont_dict.id, - tag, - subset->ps_name, - descriptor.id); - - for (i = 0; i < font_subset->num_glyphs; i++) - _cairo_output_stream_printf (surface->output, - " %ld", - (long)(subset->widths[i]*PDF_UNITS_PER_EM)); - - _cairo_output_stream_printf (surface->output, - " ]]\n" - ">>\n" - "endobj\n"); - - _cairo_pdf_surface_update_object (surface, subset_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /Type0\n" - " /BaseFont /%s+%s\n" - " /Encoding /Identity-H\n" - " /DescendantFonts [ %d 0 R]\n", - subset_resource.id, - tag, - subset->ps_name, - cidfont_dict.id); - - if (to_unicode_stream.id != 0) - _cairo_output_stream_printf (surface->output, - " /ToUnicode %d 0 R\n", - to_unicode_stream.id); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - } - - font.font_id = font_subset->font_id; - font.subset_id = font_subset->subset_id; - font.subset_resource = subset_resource; - status = _cairo_array_append (&surface->fonts, &font); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_cff_font_subset (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_int_status_t status; - cairo_cff_subset_t subset; - char name[64]; - - snprintf (name, sizeof name, "CairoFont-%d-%d", - font_subset->font_id, font_subset->subset_id); - status = _cairo_cff_subset_init (&subset, name, font_subset); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset); - - _cairo_cff_subset_fini (&subset); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_cff_fallback_font (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_int_status_t status; - cairo_cff_subset_t subset; - char name[64]; - - /* CFF fallback subsetting does not work with 8-bit glyphs unless - * they are a latin subset */ - if (!font_subset->is_composite && !font_subset->is_latin) - return CAIRO_INT_STATUS_UNSUPPORTED; - - snprintf (name, sizeof name, "CairoFont-%d-%d", - font_subset->font_id, font_subset->subset_id); - status = _cairo_cff_fallback_init (&subset, name, font_subset); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset); - - _cairo_cff_fallback_fini (&subset); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset, - cairo_type1_subset_t *subset) -{ - cairo_pdf_resource_t stream, descriptor, subset_resource, to_unicode_stream; - cairo_pdf_font_t font; - cairo_int_status_t status; - unsigned long length; - unsigned int i, last_glyph; - char tag[10]; - - _create_font_subset_tag (font_subset, subset->base_font, tag); - - subset_resource = _cairo_pdf_surface_get_font_resource (surface, - font_subset->font_id, - font_subset->subset_id); - if (subset_resource.id == 0) - return CAIRO_STATUS_SUCCESS; - - length = subset->header_length + subset->data_length + subset->trailer_length; - status = _cairo_pdf_surface_open_stream (surface, - NULL, - TRUE, - " /Length1 %lu\n" - " /Length2 %lu\n" - " /Length3 %lu\n", - subset->header_length, - subset->data_length, - subset->trailer_length); - if (unlikely (status)) - return status; - - stream = surface->pdf_stream.self; - _cairo_output_stream_write (surface->output, subset->data, length); - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_to_unicode_stream (surface, - font_subset, - &to_unicode_stream); - if (_cairo_int_status_is_error (status)) - return status; - - last_glyph = font_subset->num_glyphs - 1; - if (font_subset->is_latin) { - /* find last glyph used */ - for (i = 255; i >= 32; i--) - if (font_subset->latin_to_subset_glyph_index[i] > 0) - break; - - last_glyph = i; - } - - descriptor = _cairo_pdf_surface_new_object (surface); - if (descriptor.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /FontDescriptor\n" - " /FontName /%s+%s\n" - " /Flags 4\n" - " /FontBBox [ %ld %ld %ld %ld ]\n" - " /ItalicAngle 0\n" - " /Ascent %ld\n" - " /Descent %ld\n" - " /CapHeight %ld\n" - " /StemV 80\n" - " /StemH 80\n" - " /FontFile %u 0 R\n" - ">>\n" - "endobj\n", - descriptor.id, - tag, - subset->base_font, - (long)(subset->x_min*PDF_UNITS_PER_EM), - (long)(subset->y_min*PDF_UNITS_PER_EM), - (long)(subset->x_max*PDF_UNITS_PER_EM), - (long)(subset->y_max*PDF_UNITS_PER_EM), - (long)(subset->ascent*PDF_UNITS_PER_EM), - (long)(subset->descent*PDF_UNITS_PER_EM), - (long)(subset->y_max*PDF_UNITS_PER_EM), - stream.id); - - _cairo_pdf_surface_update_object (surface, subset_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /Type1\n" - " /BaseFont /%s+%s\n" - " /FirstChar %d\n" - " /LastChar %d\n" - " /FontDescriptor %d 0 R\n", - subset_resource.id, - tag, - subset->base_font, - font_subset->is_latin ? 32 : 0, - last_glyph, - descriptor.id); - - if (font_subset->is_latin) - _cairo_output_stream_printf (surface->output, " /Encoding /WinAnsiEncoding\n"); - - _cairo_output_stream_printf (surface->output, " /Widths ["); - if (font_subset->is_latin) { - for (i = 32; i < last_glyph + 1; i++) { - int glyph = font_subset->latin_to_subset_glyph_index[i]; - if (glyph > 0) { - _cairo_output_stream_printf (surface->output, - " %ld", - (long)(subset->widths[glyph]*PDF_UNITS_PER_EM)); - } else { - _cairo_output_stream_printf (surface->output, " 0"); - } - } - } else { - for (i = 0; i < font_subset->num_glyphs; i++) - _cairo_output_stream_printf (surface->output, - " %ld", - (long)(subset->widths[i]*PDF_UNITS_PER_EM)); - } - - _cairo_output_stream_printf (surface->output, - " ]\n"); - - if (to_unicode_stream.id != 0) - _cairo_output_stream_printf (surface->output, - " /ToUnicode %d 0 R\n", - to_unicode_stream.id); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - - font.font_id = font_subset->font_id; - font.subset_id = font_subset->subset_id; - font.subset_resource = subset_resource; - return _cairo_array_append (&surface->fonts, &font); -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_type1_font_subset (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_int_status_t status; - cairo_type1_subset_t subset; - char name[64]; - - /* 16-bit glyphs not compatible with Type 1 fonts */ - if (font_subset->is_composite && !font_subset->is_latin) - return CAIRO_INT_STATUS_UNSUPPORTED; - - snprintf (name, sizeof name, "CairoFont-%d-%d", - font_subset->font_id, font_subset->subset_id); - status = _cairo_type1_subset_init (&subset, name, font_subset, FALSE); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset); - - _cairo_type1_subset_fini (&subset); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_type1_fallback_font (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_int_status_t status; - cairo_type1_subset_t subset; - char name[64]; - - /* 16-bit glyphs not compatible with Type 1 fonts */ - if (font_subset->is_composite && !font_subset->is_latin) - return CAIRO_INT_STATUS_UNSUPPORTED; - - snprintf (name, sizeof name, "CairoFont-%d-%d", - font_subset->font_id, font_subset->subset_id); - status = _cairo_type1_fallback_init_binary (&subset, name, font_subset); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset); - - _cairo_type1_fallback_fini (&subset); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_pdf_resource_t stream, descriptor, cidfont_dict; - cairo_pdf_resource_t subset_resource, to_unicode_stream; - cairo_int_status_t status; - cairo_pdf_font_t font; - cairo_truetype_subset_t subset; - unsigned int i, last_glyph; - char tag[10]; - - subset_resource = _cairo_pdf_surface_get_font_resource (surface, - font_subset->font_id, - font_subset->subset_id); - if (subset_resource.id == 0) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_truetype_subset_init_pdf (&subset, font_subset); - if (unlikely (status)) - return status; - - _create_font_subset_tag (font_subset, subset.ps_name, tag); - - status = _cairo_pdf_surface_open_stream (surface, - NULL, - TRUE, - " /Length1 %lu\n", - subset.data_length); - if (unlikely (status)) { - _cairo_truetype_subset_fini (&subset); - return status; - } - - stream = surface->pdf_stream.self; - _cairo_output_stream_write (surface->output, - subset.data, subset.data_length); - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) { - _cairo_truetype_subset_fini (&subset); - return status; - } - - status = _cairo_pdf_surface_emit_to_unicode_stream (surface, - font_subset, - &to_unicode_stream); - if (_cairo_int_status_is_error (status)) { - _cairo_truetype_subset_fini (&subset); - return status; - } - - descriptor = _cairo_pdf_surface_new_object (surface); - if (descriptor.id == 0) { - _cairo_truetype_subset_fini (&subset); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /FontDescriptor\n" - " /FontName /%s+%s\n", - descriptor.id, - tag, - subset.ps_name); - - if (subset.family_name_utf8) { - char *pdf_str; - - status = _utf8_to_pdf_string (subset.family_name_utf8, &pdf_str); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - " /FontFamily %s\n", - pdf_str); - free (pdf_str); - } - - _cairo_output_stream_printf (surface->output, - " /Flags %d\n" - " /FontBBox [ %ld %ld %ld %ld ]\n" - " /ItalicAngle 0\n" - " /Ascent %ld\n" - " /Descent %ld\n" - " /CapHeight %ld\n" - " /StemV 80\n" - " /StemH 80\n" - " /FontFile2 %u 0 R\n" - ">>\n" - "endobj\n", - font_subset->is_latin ? 32 : 4, - (long)(subset.x_min*PDF_UNITS_PER_EM), - (long)(subset.y_min*PDF_UNITS_PER_EM), - (long)(subset.x_max*PDF_UNITS_PER_EM), - (long)(subset.y_max*PDF_UNITS_PER_EM), - (long)(subset.ascent*PDF_UNITS_PER_EM), - (long)(subset.descent*PDF_UNITS_PER_EM), - (long)(subset.y_max*PDF_UNITS_PER_EM), - stream.id); - - if (font_subset->is_latin) { - /* find last glyph used */ - for (i = 255; i >= 32; i--) - if (font_subset->latin_to_subset_glyph_index[i] > 0) - break; - - last_glyph = i; - _cairo_pdf_surface_update_object (surface, subset_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /TrueType\n" - " /BaseFont /%s+%s\n" - " /FirstChar 32\n" - " /LastChar %d\n" - " /FontDescriptor %d 0 R\n" - " /Encoding /WinAnsiEncoding\n" - " /Widths [", - subset_resource.id, - tag, - subset.ps_name, - last_glyph, - descriptor.id); - - for (i = 32; i < last_glyph + 1; i++) { - int glyph = font_subset->latin_to_subset_glyph_index[i]; - if (glyph > 0) { - _cairo_output_stream_printf (surface->output, - " %ld", - (long)(subset.widths[glyph]*PDF_UNITS_PER_EM)); - } else { - _cairo_output_stream_printf (surface->output, " 0"); - } - } - - _cairo_output_stream_printf (surface->output, - " ]\n"); - - if (to_unicode_stream.id != 0) - _cairo_output_stream_printf (surface->output, - " /ToUnicode %d 0 R\n", - to_unicode_stream.id); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - } else { - cidfont_dict = _cairo_pdf_surface_new_object (surface); - if (cidfont_dict.id == 0) { - _cairo_truetype_subset_fini (&subset); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /CIDFontType2\n" - " /BaseFont /%s+%s\n" - " /CIDSystemInfo\n" - " << /Registry (Adobe)\n" - " /Ordering (Identity)\n" - " /Supplement 0\n" - " >>\n" - " /FontDescriptor %d 0 R\n" - " /W [0 [", - cidfont_dict.id, - tag, - subset.ps_name, - descriptor.id); - - for (i = 0; i < font_subset->num_glyphs; i++) - _cairo_output_stream_printf (surface->output, - " %ld", - (long)(subset.widths[i]*PDF_UNITS_PER_EM)); - - _cairo_output_stream_printf (surface->output, - " ]]\n" - ">>\n" - "endobj\n"); - - _cairo_pdf_surface_update_object (surface, subset_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /Type0\n" - " /BaseFont /%s+%s\n" - " /Encoding /Identity-H\n" - " /DescendantFonts [ %d 0 R]\n", - subset_resource.id, - tag, - subset.ps_name, - cidfont_dict.id); - - if (to_unicode_stream.id != 0) - _cairo_output_stream_printf (surface->output, - " /ToUnicode %d 0 R\n", - to_unicode_stream.id); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - } - - font.font_id = font_subset->font_id; - font.subset_id = font_subset->subset_id; - font.subset_resource = subset_resource; - status = _cairo_array_append (&surface->fonts, &font); - - _cairo_truetype_subset_fini (&subset); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_emit_imagemask (cairo_image_surface_t *image, - cairo_output_stream_t *stream) -{ - uint8_t *byte, output_byte; - int row, col, num_cols; - - /* The only image type supported by Type 3 fonts are 1-bit image - * masks */ - assert (image->format == CAIRO_FORMAT_A1); - - _cairo_output_stream_printf (stream, - "BI\n" - "/IM true\n" - "/W %d\n" - "/H %d\n" - "/BPC 1\n" - "/D [1 0]\n", - image->width, - image->height); - - _cairo_output_stream_printf (stream, - "ID "); - - num_cols = (image->width + 7) / 8; - for (row = 0; row < image->height; row++) { - byte = image->data + row * image->stride; - for (col = 0; col < num_cols; col++) { - output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte); - _cairo_output_stream_write (stream, &output_byte, 1); - byte++; - } - } - - _cairo_output_stream_printf (stream, - "\nEI\n"); - - return _cairo_output_stream_get_status (stream); -} - -static cairo_int_status_t -_cairo_pdf_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_pdf_surface_t *surface = closure; - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - cairo_int_status_t status2; - unsigned int i; - cairo_surface_t *type3_surface; - cairo_output_stream_t *null_stream; - - null_stream = _cairo_null_stream_create (); - type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, - null_stream, - _cairo_pdf_emit_imagemask, - surface->font_subsets, - FALSE); - if (unlikely (type3_surface->status)) { - status2 = _cairo_output_stream_destroy (null_stream); - return type3_surface->status; - } - - _cairo_type3_glyph_surface_set_font_subsets_callback (type3_surface, - _cairo_pdf_surface_add_font, - surface); - - for (i = 0; i < font_subset->num_glyphs; i++) { - status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface, - font_subset->glyphs[i]); - if (unlikely (status)) - break; - } - - cairo_surface_destroy (type3_surface); - status2 = _cairo_output_stream_destroy (null_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - cairo_pdf_resource_t *glyphs, encoding, char_procs, subset_resource, to_unicode_stream; - cairo_pdf_font_t font; - double *widths; - unsigned int i; - cairo_box_t font_bbox = {{0,0},{0,0}}; - cairo_box_t bbox = {{0,0},{0,0}}; - cairo_surface_t *type3_surface; - - if (font_subset->num_glyphs == 0) - return CAIRO_STATUS_SUCCESS; - - subset_resource = _cairo_pdf_surface_get_font_resource (surface, - font_subset->font_id, - font_subset->subset_id); - if (subset_resource.id == 0) - return CAIRO_STATUS_SUCCESS; - - glyphs = _cairo_malloc_ab (font_subset->num_glyphs, sizeof (cairo_pdf_resource_t)); - if (unlikely (glyphs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - widths = _cairo_malloc_ab (font_subset->num_glyphs, sizeof (double)); - if (unlikely (widths == NULL)) { - free (glyphs); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_pdf_group_resources_clear (&surface->resources); - type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, - NULL, - _cairo_pdf_emit_imagemask, - surface->font_subsets, - FALSE); - if (unlikely (type3_surface->status)) { - free (glyphs); - free (widths); - return type3_surface->status; - } - - _cairo_type3_glyph_surface_set_font_subsets_callback (type3_surface, - _cairo_pdf_surface_add_font, - surface); - - for (i = 0; i < font_subset->num_glyphs; i++) { - status = _cairo_pdf_surface_open_stream (surface, - NULL, - surface->compress_content, - NULL); - if (unlikely (status)) - break; - - glyphs[i] = surface->pdf_stream.self; - status = _cairo_type3_glyph_surface_emit_glyph (type3_surface, - surface->output, - font_subset->glyphs[i], - &bbox, - &widths[i]); - if (unlikely (status)) - break; - - status = _cairo_pdf_surface_close_stream (surface); - if (unlikely (status)) - break; - - if (i == 0) { - font_bbox.p1.x = bbox.p1.x; - font_bbox.p1.y = bbox.p1.y; - font_bbox.p2.x = bbox.p2.x; - font_bbox.p2.y = bbox.p2.y; - } else { - if (bbox.p1.x < font_bbox.p1.x) - font_bbox.p1.x = bbox.p1.x; - if (bbox.p1.y < font_bbox.p1.y) - font_bbox.p1.y = bbox.p1.y; - if (bbox.p2.x > font_bbox.p2.x) - font_bbox.p2.x = bbox.p2.x; - if (bbox.p2.y > font_bbox.p2.y) - font_bbox.p2.y = bbox.p2.y; - } - } - cairo_surface_destroy (type3_surface); - if (unlikely (status)) { - free (glyphs); - free (widths); - return status; - } - - encoding = _cairo_pdf_surface_new_object (surface); - if (encoding.id == 0) { - free (glyphs); - free (widths); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Encoding\n" - " /Differences [0", encoding.id); - for (i = 0; i < font_subset->num_glyphs; i++) - _cairo_output_stream_printf (surface->output, - " /%d", i); - _cairo_output_stream_printf (surface->output, - "]\n" - ">>\n" - "endobj\n"); - - char_procs = _cairo_pdf_surface_new_object (surface); - if (char_procs.id == 0) { - free (glyphs); - free (widths); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<<\n", char_procs.id); - for (i = 0; i < font_subset->num_glyphs; i++) - _cairo_output_stream_printf (surface->output, - " /%d %d 0 R\n", - i, glyphs[i].id); - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - - free (glyphs); - - status = _cairo_pdf_surface_emit_to_unicode_stream (surface, - font_subset, - &to_unicode_stream); - if (_cairo_int_status_is_error (status)) { - free (widths); - return status; - } - - _cairo_pdf_surface_update_object (surface, subset_resource); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Font\n" - " /Subtype /Type3\n" - " /FontBBox [%f %f %f %f]\n" - " /FontMatrix [ 1 0 0 1 0 0 ]\n" - " /Encoding %d 0 R\n" - " /CharProcs %d 0 R\n" - " /FirstChar 0\n" - " /LastChar %d\n", - subset_resource.id, - _cairo_fixed_to_double (font_bbox.p1.x), - - _cairo_fixed_to_double (font_bbox.p2.y), - _cairo_fixed_to_double (font_bbox.p2.x), - - _cairo_fixed_to_double (font_bbox.p1.y), - encoding.id, - char_procs.id, - font_subset->num_glyphs - 1); - - _cairo_output_stream_printf (surface->output, - " /Widths ["); - for (i = 0; i < font_subset->num_glyphs; i++) - _cairo_output_stream_printf (surface->output, " %f", widths[i]); - _cairo_output_stream_printf (surface->output, - "]\n"); - free (widths); - - _cairo_output_stream_printf (surface->output, - " /Resources\n"); - _cairo_pdf_surface_emit_group_resources (surface, &surface->resources); - - if (to_unicode_stream.id != 0) - _cairo_output_stream_printf (surface->output, - " /ToUnicode %d 0 R\n", - to_unicode_stream.id); - - _cairo_output_stream_printf (surface->output, - ">>\n" - "endobj\n"); - - font.font_id = font_subset->font_id; - font.subset_id = font_subset->subset_id; - font.subset_resource = subset_resource; - return _cairo_array_append (&surface->fonts, &font); -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_pdf_surface_t *surface = closure; - cairo_int_status_t status; - - status = _cairo_pdf_surface_emit_cff_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_pdf_surface_emit_truetype_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_pdf_surface_emit_type1_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_pdf_surface_emit_cff_fallback_font (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_pdf_surface_emit_type1_fallback_font (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_pdf_surface_t *surface = closure; - cairo_int_status_t status; - - status = _cairo_pdf_surface_emit_type3_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface) -{ - cairo_int_status_t status; - - status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, - _cairo_pdf_surface_analyze_user_font_subset, - surface); - if (unlikely (status)) - goto BAIL; - - status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets, - _cairo_pdf_surface_emit_unscaled_font_subset, - surface); - if (unlikely (status)) - goto BAIL; - - status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets, - _cairo_pdf_surface_emit_scaled_font_subset, - surface); - if (unlikely (status)) - goto BAIL; - - status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, - _cairo_pdf_surface_emit_scaled_font_subset, - surface); - -BAIL: - _cairo_scaled_font_subsets_destroy (surface->font_subsets); - surface->font_subsets = NULL; - - return status; -} - -static cairo_pdf_resource_t -_cairo_pdf_surface_write_catalog (cairo_pdf_surface_t *surface) -{ - cairo_pdf_resource_t catalog; - - catalog = _cairo_pdf_surface_new_object (surface); - if (catalog.id == 0) - return catalog; - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Catalog\n" - " /Pages %d 0 R\n" - ">>\n" - "endobj\n", - catalog.id, - surface->pages_resource.id); - - return catalog; -} - -static long -_cairo_pdf_surface_write_xref (cairo_pdf_surface_t *surface) -{ - cairo_pdf_object_t *object; - int num_objects, i; - long offset; - char buffer[11]; - - num_objects = _cairo_array_num_elements (&surface->objects); - - offset = _cairo_output_stream_get_position (surface->output); - _cairo_output_stream_printf (surface->output, - "xref\n" - "%d %d\n", - 0, num_objects + 1); - - _cairo_output_stream_printf (surface->output, - "0000000000 65535 f \n"); - for (i = 0; i < num_objects; i++) { - object = _cairo_array_index (&surface->objects, i); - snprintf (buffer, sizeof buffer, "%010ld", object->offset); - _cairo_output_stream_printf (surface->output, - "%s 00000 n \n", buffer); - } - - return offset; -} - -static cairo_int_status_t -_cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t *surface, - cairo_pdf_smask_group_t *group) -{ - cairo_pdf_resource_t mask_group; - cairo_pdf_resource_t smask; - cairo_pdf_smask_group_t *smask_group; - cairo_pdf_resource_t pattern_res, gstate_res; - cairo_int_status_t status; - cairo_box_double_t bbox; - - /* Create mask group */ - _get_bbox_from_extents (group->height, &group->extents, &bbox); - status = _cairo_pdf_surface_open_group (surface, &bbox, NULL); - if (unlikely (status)) - return status; - - if (_can_paint_pattern (group->mask)) { - _cairo_output_stream_printf (surface->output, "q\n"); - status = _cairo_pdf_surface_paint_pattern (surface, - CAIRO_OPERATOR_OVER, - group->mask, - &group->extents, - FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "Q\n"); - } else { - pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, group->mask, - CAIRO_OPERATOR_OVER, - NULL, - &pattern_res, &gstate_res); - if (unlikely (status)) - return status; - - if (gstate_res.id != 0) { - smask_group = _cairo_pdf_surface_create_smask_group (surface, &group->extents); - if (unlikely (smask_group == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - smask_group->width = group->width; - smask_group->height = group->height; - smask_group->operation = PDF_PAINT; - smask_group->source = cairo_pattern_reference (group->mask); - smask_group->source_res = pattern_res; - status = _cairo_pdf_surface_add_smask_group (surface, smask_group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (smask_group); - return status; - } - - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_add_xobject (surface, smask_group->group_res); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - gstate_res.id, - smask_group->group_res.id); - } else { - status = _cairo_pdf_surface_select_pattern (surface, group->mask, pattern_res, FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "%f %f %f %f re f\n", - bbox.p1.x, - bbox.p1.y, - bbox.p2.x - bbox.p1.x, - bbox.p2.y - bbox.p1.y); - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - return status; - } - } - - status = _cairo_pdf_surface_close_group (surface, &mask_group); - if (unlikely (status)) - return status; - - /* Create source group */ - status = _cairo_pdf_surface_open_group (surface, &bbox, &group->source_res); - if (unlikely (status)) - return status; - - if (_can_paint_pattern (group->source)) { - _cairo_output_stream_printf (surface->output, "q\n"); - status = _cairo_pdf_surface_paint_pattern (surface, - CAIRO_OPERATOR_OVER, - group->source, - &group->extents, - FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "Q\n"); - } else { - pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, group->source, - CAIRO_OPERATOR_OVER, - NULL, - &pattern_res, &gstate_res); - if (unlikely (status)) - return status; - - if (gstate_res.id != 0) { - smask_group = _cairo_pdf_surface_create_smask_group (surface, &group->extents); - if (unlikely (smask_group == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - smask_group->operation = PDF_PAINT; - smask_group->source = cairo_pattern_reference (group->source); - smask_group->source_res = pattern_res; - status = _cairo_pdf_surface_add_smask_group (surface, smask_group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (smask_group); - return status; - } - - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_add_xobject (surface, smask_group->group_res); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - gstate_res.id, - smask_group->group_res.id); - } else { - status = _cairo_pdf_surface_select_pattern (surface, group->source, pattern_res, FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "%f %f %f %f re f\n", - bbox.p1.x, - bbox.p1.y, - bbox.p2.x - bbox.p1.x, - bbox.p2.y - bbox.p1.y); - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - return status; - } - } - - status = _cairo_pdf_surface_close_group (surface, NULL); - if (unlikely (status)) - return status; - - /* Create an smask based on the alpha component of mask_group */ - smask = _cairo_pdf_surface_new_object (surface); - if (smask.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Mask\n" - " /S /Alpha\n" - " /G %d 0 R\n" - ">>\n" - "endobj\n", - smask.id, - mask_group.id); - - /* Create a GState that uses the smask */ - _cairo_pdf_surface_update_object (surface, group->group_res); - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /ExtGState\n" - " /SMask %d 0 R\n" - " /ca 1\n" - " /CA 1\n" - " /AIS false\n" - ">>\n" - "endobj\n", - group->group_res.id, - smask.id); - - return _cairo_output_stream_get_status (surface->output); -} - -static cairo_int_status_t -_cairo_pdf_surface_write_smask_group (cairo_pdf_surface_t *surface, - cairo_pdf_smask_group_t *group) -{ - double old_width, old_height; - cairo_int_status_t status; - cairo_box_double_t bbox; - - old_width = surface->width; - old_height = surface->height; - _cairo_pdf_surface_set_size_internal (surface, - group->width, - group->height); - /* _mask is a special case that requires two groups - source - * and mask as well as a smask and gstate dictionary */ - if (group->operation == PDF_MASK) { - status = _cairo_pdf_surface_write_mask_group (surface, group); - goto RESTORE_SIZE; - } - - _get_bbox_from_extents (group->height, &group->extents, &bbox); - status = _cairo_pdf_surface_open_group (surface, &bbox, &group->group_res); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_select_pattern (surface, - group->source, - group->source_res, - group->operation == PDF_STROKE); - if (unlikely (status)) - return status; - - switch (group->operation) { - case PDF_PAINT: - _cairo_output_stream_printf (surface->output, - "0 0 %f %f re f\n", - surface->width, surface->height); - break; - case PDF_MASK: - ASSERT_NOT_REACHED; - break; - case PDF_FILL: - status = _cairo_pdf_operators_fill (&surface->pdf_operators, - &group->path, - group->fill_rule); - break; - case PDF_STROKE: - status = _cairo_pdf_operators_stroke (&surface->pdf_operators, - &group->path, - &group->style, - &group->ctm, - &group->ctm_inverse); - break; - case PDF_SHOW_GLYPHS: - status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, - group->utf8, group->utf8_len, - group->glyphs, group->num_glyphs, - group->clusters, group->num_clusters, - group->cluster_flags, - group->scaled_font); - break; - } - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_close_group (surface, NULL); - -RESTORE_SIZE: - _cairo_pdf_surface_set_size_internal (surface, - old_width, - old_height); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_write_patterns_and_smask_groups (cairo_pdf_surface_t *surface) -{ - cairo_pdf_pattern_t pattern; - cairo_pdf_smask_group_t *group; - cairo_pdf_source_surface_t src_surface; - unsigned int pattern_index, group_index, surface_index; - cairo_int_status_t status; - - /* Writing out PDF_MASK groups will cause additional smask groups - * to be appended to surface->smask_groups. Additional patterns - * may also be appended to surface->patterns. - * - * Writing recording surface patterns will cause additional patterns - * and groups to be appended. - */ - pattern_index = 0; - group_index = 0; - surface_index = 0; - while ((pattern_index < _cairo_array_num_elements (&surface->page_patterns)) || - (group_index < _cairo_array_num_elements (&surface->smask_groups)) || - (surface_index < _cairo_array_num_elements (&surface->page_surfaces))) - { - for (; group_index < _cairo_array_num_elements (&surface->smask_groups); group_index++) { - _cairo_array_copy_element (&surface->smask_groups, group_index, &group); - status = _cairo_pdf_surface_write_smask_group (surface, group); - if (unlikely (status)) - return status; - } - - for (; pattern_index < _cairo_array_num_elements (&surface->page_patterns); pattern_index++) { - _cairo_array_copy_element (&surface->page_patterns, pattern_index, &pattern); - status = _cairo_pdf_surface_emit_pattern (surface, &pattern); - if (unlikely (status)) - return status; - } - - for (; surface_index < _cairo_array_num_elements (&surface->page_surfaces); surface_index++) { - _cairo_array_copy_element (&surface->page_surfaces, surface_index, &src_surface); - status = _cairo_pdf_surface_emit_surface (surface, &src_surface); - if (unlikely (status)) - return status; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface) -{ - cairo_pdf_resource_t page, knockout, res; - cairo_int_status_t status; - unsigned int i, len; - - _cairo_pdf_group_resources_clear (&surface->resources); - if (surface->has_fallback_images) { - cairo_rectangle_int_t extents; - cairo_box_double_t bbox; - - extents.x = 0; - extents.y = 0; - extents.width = ceil (surface->width); - extents.height = ceil (surface->height); - _get_bbox_from_extents (surface->height, &extents, &bbox); - status = _cairo_pdf_surface_open_knockout_group (surface, &bbox); - if (unlikely (status)) - return status; - - len = _cairo_array_num_elements (&surface->knockout_group); - for (i = 0; i < len; i++) { - _cairo_array_copy_element (&surface->knockout_group, i, &res); - _cairo_output_stream_printf (surface->output, - "/x%d Do\n", - res.id); - status = _cairo_pdf_surface_add_xobject (surface, res); - if (unlikely (status)) - return status; - } - _cairo_output_stream_printf (surface->output, - "/x%d Do\n", - surface->content.id); - status = _cairo_pdf_surface_add_xobject (surface, surface->content); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_close_group (surface, &knockout); - if (unlikely (status)) - return status; - - _cairo_pdf_group_resources_clear (&surface->resources); - status = _cairo_pdf_surface_open_content_stream (surface, NULL, NULL, FALSE, FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, - "/x%d Do\n", - knockout.id); - status = _cairo_pdf_surface_add_xobject (surface, knockout); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_close_content_stream (surface); - if (unlikely (status)) - return status; - } - - page = _cairo_pdf_surface_new_object (surface); - if (page.id == 0) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->output, - "%d 0 obj\n" - "<< /Type /Page\n" - " /Parent %d 0 R\n" - " /MediaBox [ 0 0 %f %f ]\n" - " /Contents %d 0 R\n" - " /Group <<\n" - " /Type /Group\n" - " /S /Transparency\n" - " /I true\n" - " /CS /DeviceRGB\n" - " >>\n" - " /Resources %d 0 R\n" - ">>\n" - "endobj\n", - page.id, - surface->pages_resource.id, - surface->width, - surface->height, - surface->content.id, - surface->content_resources.id); - - status = _cairo_array_append (&surface->pages, &page); - if (unlikely (status)) - return status; - - status = _cairo_pdf_surface_write_patterns_and_smask_groups (surface); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_pdf_surface_analyze_surface_pattern_transparency (cairo_pdf_surface_t *surface, - cairo_surface_pattern_t *pattern) -{ - cairo_image_surface_t *image; - void *image_extra; - cairo_int_status_t status; - cairo_image_transparency_t transparency; - - status = _cairo_surface_acquire_source_image (pattern->surface, - &image, - &image_extra); - if (unlikely (status)) - return status; - - if (image->base.status) - return image->base.status; - - transparency = _cairo_image_analyze_transparency (image); - if (transparency == CAIRO_IMAGE_IS_OPAQUE) - status = CAIRO_STATUS_SUCCESS; - else - status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; - - _cairo_surface_release_source_image (pattern->surface, image, image_extra); - - return status; -} - -static cairo_bool_t -_surface_pattern_supported (cairo_surface_pattern_t *pattern) -{ - cairo_extend_t extend; - - if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - return TRUE; - - if (pattern->surface->backend->acquire_source_image == NULL) - return FALSE; - - /* Does an ALPHA-only source surface even make sense? Maybe, but I - * don't think it's worth the extra code to support it. */ - -/* XXX: Need to write this function here... - if (pattern->surface->content == CAIRO_CONTENT_ALPHA) - return FALSE; -*/ - - extend = cairo_pattern_get_extend (&pattern->base); - switch (extend) { - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_REPEAT: - case CAIRO_EXTEND_REFLECT: - /* There's no point returning FALSE for EXTEND_PAD, as the image - * surface does not currently implement it either */ - case CAIRO_EXTEND_PAD: - return TRUE; - } - - ASSERT_NOT_REACHED; - return FALSE; -} - -static cairo_bool_t -_pattern_supported (const cairo_pattern_t *pattern) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return TRUE; - - case CAIRO_PATTERN_TYPE_SURFACE: - return _surface_pattern_supported ((cairo_surface_pattern_t *) pattern); - - default: - ASSERT_NOT_REACHED; - return FALSE; - } -} - -static cairo_bool_t -_pdf_operator_supported (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return TRUE; - - default: - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_ATOP: - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_DEST_ATOP: - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - return FALSE; - } -} - -static cairo_int_status_t -_cairo_pdf_surface_analyze_operation (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - if (surface->force_fallbacks && - surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (! _pattern_supported (pattern)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (_pdf_operator_supported (op)) { - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; - - if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { - if (pattern->extend == CAIRO_EXTEND_PAD) { - cairo_box_t box; - cairo_rectangle_int_t rect; - cairo_rectangle_int_t rec_extents; - - /* get the operation extents in pattern space */ - _cairo_box_from_rectangle (&box, extents); - _cairo_matrix_transform_bounding_box_fixed (&pattern->matrix, &box, NULL); - _cairo_box_round_to_rectangle (&box, &rect); - - /* Check if surface needs padding to fill extents */ - if (_cairo_surface_get_extents (surface_pattern->surface, &rec_extents)) { - if (_cairo_fixed_integer_ceil(box.p1.x) < rec_extents.x || - _cairo_fixed_integer_ceil(box.p1.y) < rec_extents.y || - _cairo_fixed_integer_floor(box.p2.y) > rec_extents.x + rec_extents.width || - _cairo_fixed_integer_floor(box.p2.y) > rec_extents.y + rec_extents.height) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - } - return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; - } - } - - return CAIRO_STATUS_SUCCESS; - } - - - /* The SOURCE operator is supported if the pattern is opaque or if - * there is nothing painted underneath. */ - if (op == CAIRO_OPERATOR_SOURCE) { - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; - - if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { - if (_cairo_pattern_is_opaque (pattern, extents)) { - return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; - } else { - /* FIXME: The analysis surface does not yet have - * the capability to analyze a non opaque recording - * surface and mark it supported if there is - * nothing underneath. For now recording surfaces of - * type CONTENT_COLOR_ALPHA painted with - * OPERATOR_SOURCE will result in a fallback - * image. */ - - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } else { - return _cairo_pdf_surface_analyze_surface_pattern_transparency (surface, - surface_pattern); - } - } - - if (_cairo_pattern_is_opaque (pattern, extents)) - return CAIRO_STATUS_SUCCESS; - else - return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_bool_t -_cairo_pdf_surface_operation_supported (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - return _cairo_pdf_surface_analyze_operation (surface, op, pattern, extents) != CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_int_status_t -_cairo_pdf_surface_start_fallback (cairo_pdf_surface_t *surface) -{ - cairo_box_double_t bbox; - cairo_int_status_t status; - - status = _cairo_pdf_surface_close_content_stream (surface); - if (unlikely (status)) - return status; - - status = _cairo_array_append (&surface->knockout_group, &surface->content); - if (unlikely (status)) - return status; - - _cairo_pdf_group_resources_clear (&surface->resources); - bbox.p1.x = 0; - bbox.p1.y = 0; - bbox.p2.x = surface->width; - bbox.p2.y = surface->height; - return _cairo_pdf_surface_open_content_stream (surface, &bbox, NULL, TRUE, TRUE); -} - -/* If source is an opaque image and mask is an image and both images - * have the same bounding box we can emit them as a image/smask pair. - */ -static cairo_int_status_t -_cairo_pdf_surface_emit_combined_smask (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_rectangle_int_t *extents) -{ - cairo_int_status_t status; - cairo_image_surface_t *image; - void *image_extra; - cairo_image_transparency_t transparency; - cairo_pdf_resource_t smask_res; - int src_width, src_height; - int mask_width, mask_height; - double src_x_offset, src_y_offset; - double mask_x_offset, mask_y_offset; - double src_x1, src_y1, src_x2, src_y2; - double mask_x1, mask_y1, mask_x2, mask_y2; - cairo_matrix_t p2u; - double src_radius, mask_radius, e; - cairo_rectangle_int_t extents2; - cairo_bool_t need_smask; - - /* Check that source and mask are images */ - - if (!((source->type == CAIRO_PATTERN_TYPE_SURFACE || source->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) && - (mask->type == CAIRO_PATTERN_TYPE_SURFACE || mask->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *) source)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (mask->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *) mask)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (source->extend != CAIRO_EXTEND_NONE || mask->extend != CAIRO_EXTEND_NONE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Check that source is opaque and get image sizes */ - - status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source, - &image, &image_extra); - if (unlikely (status)) - return status; - - if (image->base.status) - return image->base.status; - - src_width = image->width; - src_height = image->height; - if (source->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { - cairo_surface_get_device_offset (&image->base, &src_x_offset, &src_y_offset); - } else { - src_x_offset = 0; - src_y_offset = 0; - } - - transparency = _cairo_image_analyze_transparency (image); - _cairo_pdf_surface_release_source_image_from_pattern (surface, source, image, image_extra); - - if (transparency != CAIRO_IMAGE_IS_OPAQUE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, mask, - &image, &image_extra); - if (unlikely (status)) - return status; - - if (image->base.status) - return image->base.status; - - mask_width = image->width; - mask_height = image->height; - if (mask->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { - cairo_surface_get_device_offset (&image->base, &mask_x_offset, &mask_y_offset); - } else { - mask_x_offset = 0; - mask_y_offset = 0; - } - - transparency = _cairo_image_analyze_transparency (image); - need_smask = transparency != CAIRO_IMAGE_IS_OPAQUE; - - _cairo_pdf_surface_release_source_image_from_pattern (surface, mask, image, image_extra); - - /* Check that both images have the same extents with a tolerance - * of half the smallest source pixel. */ - - p2u = source->matrix; - status = cairo_matrix_invert (&p2u); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - src_x1 = 0; - src_y1 = 0; - src_x2 = src_width; - src_y2 = src_height; - cairo_matrix_transform_point (&p2u, &src_x1, &src_y1); - cairo_matrix_transform_point (&p2u, &src_x2, &src_y2); - src_radius = _cairo_matrix_transformed_circle_major_axis (&p2u, 0.5); - - p2u = mask->matrix; - status = cairo_matrix_invert (&p2u); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_INT_STATUS_SUCCESS); - mask_x1 = 0; - mask_y1 = 0; - mask_x2 = mask_width; - mask_y2 = mask_height; - cairo_matrix_transform_point (&p2u, &mask_x1, &mask_y1); - cairo_matrix_transform_point (&p2u, &mask_x2, &mask_y2); - mask_radius = _cairo_matrix_transformed_circle_major_axis (&p2u, 0.5); - - if (src_radius < mask_radius) - e = src_radius; - else - e = mask_radius; - - if (fabs(src_x1 - mask_x1) > e || - fabs(src_x2 - mask_x2) > e || - fabs(src_y1 - mask_y1) > e || - fabs(src_y2 - mask_y2) > e) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Check both images have same device offset */ - if (fabs(src_x_offset - mask_x_offset) > e || - fabs(src_y_offset - mask_y_offset) > e) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (need_smask) { - status = _cairo_pdf_surface_add_source_surface (surface, - NULL, - mask, - op, - source->filter, - FALSE, - TRUE, - extents, - NULL, - &smask_res, - &mask_width, - &mask_height, - &mask_x_offset, - &mask_y_offset, - &extents2); - if (unlikely (status)) - return status; - } - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "q\n"); - status = _cairo_pdf_surface_paint_surface_pattern (surface, op, source, extents, - need_smask ? &smask_res : NULL, - FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "Q\n"); - - status = _cairo_output_stream_get_status (surface->output); - - - return status; -} - -/* A PDF stencil mask is an A1 mask used with the current color */ -static cairo_int_status_t -_cairo_pdf_surface_emit_stencil_mask (cairo_pdf_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_rectangle_int_t *extents) -{ - cairo_int_status_t status; - cairo_image_surface_t *image; - void *image_extra; - cairo_image_transparency_t transparency; - cairo_pdf_resource_t pattern_res = {0}; - - if (! (source->type == CAIRO_PATTERN_TYPE_SOLID && - (mask->type == CAIRO_PATTERN_TYPE_SURFACE || mask->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (mask->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *) mask)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, mask, - &image, &image_extra); - if (unlikely (status)) - return status; - - if (image->base.status) - return image->base.status; - - transparency = _cairo_image_analyze_transparency (image); - if (transparency != CAIRO_IMAGE_IS_OPAQUE && - transparency != CAIRO_IMAGE_HAS_BILEVEL_ALPHA) - { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - - status = _cairo_pdf_surface_select_pattern (surface, source, - pattern_res, FALSE); - if (unlikely (status)) - return status; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "q\n"); - status = _cairo_pdf_surface_paint_surface_pattern (surface, op, mask, extents, NULL, TRUE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->output, "Q\n"); - - status = _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_pdf_surface_release_source_image_from_pattern (surface, mask, image, image_extra); - - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_set_clip (cairo_pdf_surface_t *surface, - cairo_composite_rectangles_t *composite) -{ - cairo_clip_t *clip = composite->clip; - - if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) - clip = NULL; - - if (clip == NULL) { - if (_cairo_composite_rectangles_can_reduce_clip (composite, - surface->clipper.clip)) - return CAIRO_STATUS_SUCCESS; - } - - return _cairo_surface_clipper_set_clip (&surface->clipper, clip); -} - -static cairo_int_status_t -_cairo_pdf_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_pdf_smask_group_t *group; - cairo_pdf_resource_t pattern_res, gstate_res; - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - status = _cairo_composite_rectangles_init_for_paint (&extents, - &surface->base, - op, source, clip); - if (unlikely (status)) - return status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); - goto cleanup; - } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { - status = _cairo_pdf_surface_start_fallback (surface); - if (unlikely (status)) - goto cleanup; - } - - assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); - - status = _cairo_pdf_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_operator (surface, op); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - - if (_can_paint_pattern (source)) { - _cairo_output_stream_printf (surface->output, "q\n"); - status = _cairo_pdf_surface_paint_pattern (surface, - op, - source, - &extents.bounded, - FALSE); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, "Q\n"); - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - } - - pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, - &extents.bounded, - &pattern_res, &gstate_res); - if (unlikely (status)) - goto cleanup; - - if (gstate_res.id != 0) { - group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); - if (unlikely (group == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - - group->operation = PDF_PAINT; - status = _cairo_pattern_create_copy (&group->source, source); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - group->source_res = pattern_res; - status = _cairo_pdf_surface_add_smask_group (surface, group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_add_xobject (surface, group->group_res); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - gstate_res.id, - group->group_res.id); - } else { - status = _cairo_pdf_surface_select_pattern (surface, source, - pattern_res, FALSE); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, - "0 0 %f %f re f\n", - surface->width, surface->height); - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - goto cleanup; - } - - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_pdf_smask_group_t *group; - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - cairo_rectangle_int_t r; - cairo_box_t box; - - status = _cairo_composite_rectangles_init_for_mask (&extents, - &surface->base, - op, source, mask, clip); - if (unlikely (status)) - return status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - cairo_int_status_t source_status, mask_status; - - status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); - if (_cairo_int_status_is_error (status)) - goto cleanup; - source_status = status; - - if (mask->has_component_alpha) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - } else { - status = _cairo_pdf_surface_analyze_operation (surface, op, mask, &extents.bounded); - if (_cairo_int_status_is_error (status)) - goto cleanup; - } - mask_status = status; - - _cairo_composite_rectangles_fini (&extents); - return _cairo_analysis_surface_merge_status (source_status, - mask_status); - } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { - status = _cairo_pdf_surface_start_fallback (surface); - if (unlikely (status)) - goto cleanup; - } - - assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); - assert (_cairo_pdf_surface_operation_supported (surface, op, mask, &extents.bounded)); - - /* get the accurate extents */ - status = _cairo_pattern_get_ink_extents (source, &r); - if (unlikely (status)) - goto cleanup; - - /* XXX slight impedance mismatch */ - _cairo_box_from_rectangle (&box, &r); - status = _cairo_composite_rectangles_intersect_source_extents (&extents, - &box); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pattern_get_ink_extents (mask, &r); - if (unlikely (status)) - goto cleanup; - - _cairo_box_from_rectangle (&box, &r); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, - &box); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_operator (surface, op); - if (unlikely (status)) - goto cleanup; - - /* Check if we can combine source and mask into a smask image */ - status = _cairo_pdf_surface_emit_combined_smask (surface, op, source, mask, &extents.bounded); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - goto cleanup; - - /* Check if we can use a stencil mask */ - status = _cairo_pdf_surface_emit_stencil_mask (surface, op, source, mask, &extents.bounded); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - goto cleanup; - - group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); - if (unlikely (group == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - - group->operation = PDF_MASK; - status = _cairo_pattern_create_copy (&group->source, source); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - status = _cairo_pattern_create_copy (&group->mask, mask); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - group->source_res = _cairo_pdf_surface_new_object (surface); - if (group->source_res.id == 0) { - _cairo_pdf_smask_group_destroy (group); - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - - status = _cairo_pdf_surface_add_smask_group (surface, group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - status = _cairo_pdf_surface_add_smask (surface, group->group_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_add_xobject (surface, group->source_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - group->group_res.id, - group->source_res.id); - - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_pdf_smask_group_t *group; - cairo_pdf_resource_t pattern_res, gstate_res; - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - status = _cairo_composite_rectangles_init_for_stroke (&extents, - &surface->base, - op, source, - path, style, ctm, - clip); - if (unlikely (status)) - return status; - - /* use the more accurate extents */ - if (extents.is_bounded) { - cairo_rectangle_int_t mask; - cairo_box_t box; - - status = _cairo_path_fixed_stroke_extents (path, style, - ctm, ctm_inverse, - tolerance, - &mask); - if (unlikely (status)) - goto cleanup; - - _cairo_box_from_rectangle (&box, &mask); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, - &box); - if (unlikely (status)) - goto cleanup; - } - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); - goto cleanup; - } - - assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); - - status = _cairo_pdf_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup; - - pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, - &extents.bounded, - &pattern_res, &gstate_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_operator (surface, op); - if (unlikely (status)) - goto cleanup; - - if (gstate_res.id != 0) { - group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); - if (unlikely (group == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - - group->operation = PDF_STROKE; - status = _cairo_pattern_create_copy (&group->source, source); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - group->source_res = pattern_res; - status = _cairo_path_fixed_init_copy (&group->path, path); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - group->style = *style; - group->ctm = *ctm; - group->ctm_inverse = *ctm_inverse; - status = _cairo_pdf_surface_add_smask_group (surface, group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_add_xobject (surface, group->group_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - gstate_res.id, - group->group_res.id); - } else { - status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, TRUE); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_stroke (&surface->pdf_operators, - path, - style, - ctm, - ctm_inverse); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - goto cleanup; - } - - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_int_status_t status; - cairo_pdf_smask_group_t *group; - cairo_pdf_resource_t pattern_res, gstate_res; - cairo_composite_rectangles_t extents; - - status = _cairo_composite_rectangles_init_for_fill (&extents, - &surface->base, - op, source, path, - clip); - if (unlikely (status)) - return status; - - /* use the more accurate extents */ - if (extents.is_bounded) { - cairo_rectangle_int_t mask; - cairo_box_t box; - - _cairo_path_fixed_fill_extents (path, - fill_rule, - tolerance, - &mask); - - _cairo_box_from_rectangle (&box, &mask); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, - &box); - if (unlikely (status)) - goto cleanup; - } - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); - goto cleanup; - } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { - status = _cairo_pdf_surface_start_fallback (surface); - if (unlikely (status)) - goto cleanup; - } - - assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); - - status = _cairo_pdf_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_operator (surface, op); - if (unlikely (status)) - goto cleanup; - - if (_can_paint_pattern (source)) { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, "q\n"); - status = _cairo_pdf_operators_clip (&surface->pdf_operators, - path, - fill_rule); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_paint_pattern (surface, - op, - source, - &extents.bounded, - FALSE); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, "Q\n"); - status = _cairo_output_stream_get_status (surface->output); - goto cleanup; - } - - pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, - &extents.bounded, - &pattern_res, &gstate_res); - if (unlikely (status)) - goto cleanup; - - if (gstate_res.id != 0) { - group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); - if (unlikely (group == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - - group->operation = PDF_FILL; - status = _cairo_pattern_create_copy (&group->source, source); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - group->source_res = pattern_res; - status = _cairo_path_fixed_init_copy (&group->path, path); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - group->fill_rule = fill_rule; - status = _cairo_pdf_surface_add_smask_group (surface, group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_add_xobject (surface, group->group_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - gstate_res.id, - group->group_res.id); - } else { - status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_fill (&surface->pdf_operators, - path, - fill_rule); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - goto cleanup; - } - - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_pdf_surface_fill_stroke (void *abstract_surface, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - const cairo_path_fixed_t*path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_int_status_t status; - cairo_pdf_resource_t fill_pattern_res, stroke_pattern_res, gstate_res; - cairo_composite_rectangles_t extents; - - /* During analysis we return unsupported and let the _fill and - * _stroke functions that are on the fallback path do the analysis - * for us. During render we may still encounter unsupported - * combinations of fill/stroke patterns. However we can return - * unsupported anytime to let the _fill and _stroke functions take - * over. - */ - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* PDF rendering of fill-stroke is not the same as cairo when - * either the fill or stroke is not opaque. - */ - if ( !_cairo_pattern_is_opaque (fill_source, NULL) || - !_cairo_pattern_is_opaque (stroke_source, NULL)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (fill_op != stroke_op) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Compute the operation extents using the stroke which will naturally - * be larger than the fill extents. - */ - status = _cairo_composite_rectangles_init_for_stroke (&extents, - &surface->base, - stroke_op, stroke_source, - path, stroke_style, stroke_ctm, - clip); - if (unlikely (status)) - return status; - - /* use the more accurate extents */ - if (extents.is_bounded) { - cairo_rectangle_int_t mask; - cairo_box_t box; - - status = _cairo_path_fixed_stroke_extents (path, stroke_style, - stroke_ctm, stroke_ctm_inverse, - stroke_tolerance, - &mask); - if (unlikely (status)) - goto cleanup; - - _cairo_box_from_rectangle (&box, &mask); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, - &box); - if (unlikely (status)) - goto cleanup; - } - - status = _cairo_pdf_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_operator (surface, fill_op); - if (unlikely (status)) - goto cleanup; - - /* use the more accurate extents */ - if (extents.is_bounded) { - cairo_rectangle_int_t mask; - cairo_box_t box; - - _cairo_path_fixed_fill_extents (path, - fill_rule, - fill_tolerance, - &mask); - - _cairo_box_from_rectangle (&box, &mask); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, - &box); - if (unlikely (status)) - goto cleanup; - } - - fill_pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, fill_source, - fill_op, - &extents.bounded, - &fill_pattern_res, - &gstate_res); - if (unlikely (status)) - goto cleanup; - - assert (gstate_res.id == 0); - - stroke_pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, - stroke_source, - stroke_op, - &extents.bounded, - &stroke_pattern_res, - &gstate_res); - if (unlikely (status)) - goto cleanup; - - assert (gstate_res.id == 0); - - /* As PDF has separate graphics state for fill and stroke we can - * select both at the same time */ - status = _cairo_pdf_surface_select_pattern (surface, fill_source, - fill_pattern_res, FALSE); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_pattern (surface, stroke_source, - stroke_pattern_res, TRUE); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_fill_stroke (&surface->pdf_operators, - path, - fill_rule, - stroke_style, - stroke_ctm, - stroke_ctm_inverse); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - goto cleanup; - - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_bool_t -_cairo_pdf_surface_has_show_text_glyphs (void *abstract_surface) -{ - return TRUE; -} - -static cairo_int_status_t -_cairo_pdf_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_pdf_surface_t *surface = abstract_surface; - cairo_pdf_smask_group_t *group; - cairo_pdf_resource_t pattern_res, gstate_res; - cairo_composite_rectangles_t extents; - cairo_bool_t overlap; - cairo_int_status_t status; - - status = _cairo_composite_rectangles_init_for_glyphs (&extents, - &surface->base, - op, source, - scaled_font, - glyphs, num_glyphs, - clip, - &overlap); - if (unlikely (status)) - return status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); - goto cleanup; - } - - assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); - - status = _cairo_pdf_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup; - - pattern_res.id = 0; - gstate_res.id = 0; - status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, - &extents.bounded, - &pattern_res, &gstate_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_select_operator (surface, op); - if (unlikely (status)) - goto cleanup; - - if (gstate_res.id != 0) { - group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); - if (unlikely (group == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - - group->operation = PDF_SHOW_GLYPHS; - status = _cairo_pattern_create_copy (&group->source, source); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - group->source_res = pattern_res; - - if (utf8_len) { - group->utf8 = malloc (utf8_len); - if (unlikely (group->utf8 == NULL)) { - _cairo_pdf_smask_group_destroy (group); - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - memcpy (group->utf8, utf8, utf8_len); - } - group->utf8_len = utf8_len; - - if (num_glyphs) { - group->glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); - if (unlikely (group->glyphs == NULL)) { - _cairo_pdf_smask_group_destroy (group); - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - memcpy (group->glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); - } - group->num_glyphs = num_glyphs; - - if (num_clusters) { - group->clusters = _cairo_malloc_ab (num_clusters, sizeof (cairo_text_cluster_t)); - if (unlikely (group->clusters == NULL)) { - _cairo_pdf_smask_group_destroy (group); - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto cleanup; - } - memcpy (group->clusters, clusters, sizeof (cairo_text_cluster_t) * num_clusters); - } - group->num_clusters = num_clusters; - - group->scaled_font = cairo_scaled_font_reference (scaled_font); - status = _cairo_pdf_surface_add_smask_group (surface, group); - if (unlikely (status)) { - _cairo_pdf_smask_group_destroy (group); - goto cleanup; - } - - status = _cairo_pdf_surface_add_smask (surface, gstate_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_add_xobject (surface, group->group_res); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - - _cairo_output_stream_printf (surface->output, - "q /s%d gs /x%d Do Q\n", - gstate_res.id, - group->group_res.id); - } else { - status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE); - if (unlikely (status)) - goto cleanup; - - /* Each call to show_glyphs() with a transclucent pattern must - * be in a separate text object otherwise overlapping text - * from separate calls to show_glyphs will not composite with - * each other. */ - if (! _cairo_pattern_is_opaque (source, &extents.bounded)) { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup; - } - - status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_surface_unselect_pattern (surface); - if (unlikely (status)) - goto cleanup; - } - - _cairo_composite_rectangles_fini (&extents); - return _cairo_output_stream_get_status (surface->output); - -cleanup: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static const char ** -_cairo_pdf_surface_get_supported_mime_types (void *abstract_surface) -{ - return _cairo_pdf_supported_mime_types; -} - -static void -_cairo_pdf_surface_set_paginated_mode (void *abstract_surface, - cairo_paginated_mode_t paginated_mode) -{ - cairo_pdf_surface_t *surface = abstract_surface; - - surface->paginated_mode = paginated_mode; -} - -static const cairo_surface_backend_t cairo_pdf_surface_backend = { - CAIRO_SURFACE_TYPE_PDF, - _cairo_pdf_surface_finish, - - _cairo_default_context_create, - - NULL, /* create similar: handled by wrapper */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* _cairo_pdf_surface_copy_page */ - _cairo_pdf_surface_show_page, - - _cairo_pdf_surface_get_extents, - _cairo_pdf_surface_get_font_options, - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - /* Here are the drawing functions */ - _cairo_pdf_surface_paint, - _cairo_pdf_surface_mask, - _cairo_pdf_surface_stroke, - _cairo_pdf_surface_fill, - _cairo_pdf_surface_fill_stroke, - NULL, /* show_glyphs */ - _cairo_pdf_surface_has_show_text_glyphs, - _cairo_pdf_surface_show_text_glyphs, - _cairo_pdf_surface_get_supported_mime_types, -}; - -static const cairo_paginated_surface_backend_t -cairo_pdf_surface_paginated_backend = { - _cairo_pdf_surface_start_page, - _cairo_pdf_surface_set_paginated_mode, - NULL, /* set_bounding_box */ - _cairo_pdf_surface_has_fallback_images, - _cairo_pdf_surface_supports_fine_grained_fallbacks, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf.h deleted file mode 100644 index 1bc8524f2b1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pdf.h +++ /dev/null @@ -1,94 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PDF_H -#define CAIRO_PDF_H - -#include "cairo.h" - -#if CAIRO_HAS_PDF_SURFACE - -CAIRO_BEGIN_DECLS - -/** - * cairo_pdf_version_t: - * @CAIRO_PDF_VERSION_1_4: The version 1.4 of the PDF specification. (Since 1.10) - * @CAIRO_PDF_VERSION_1_5: The version 1.5 of the PDF specification. (Since 1.10) - * - * #cairo_pdf_version_t is used to describe the version number of the PDF - * specification that a generated PDF file will conform to. - * - * Since: 1.10 - **/ -typedef enum _cairo_pdf_version { - CAIRO_PDF_VERSION_1_4, - CAIRO_PDF_VERSION_1_5 -} cairo_pdf_version_t; - -cairo_public cairo_surface_t * -cairo_pdf_surface_create (const char *filename, - double width_in_points, - double height_in_points); - -cairo_public cairo_surface_t * -cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, - void *closure, - double width_in_points, - double height_in_points); - -cairo_public void -cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface, - cairo_pdf_version_t version); - -cairo_public void -cairo_pdf_get_versions (cairo_pdf_version_t const **versions, - int *num_versions); - -cairo_public const char * -cairo_pdf_version_to_string (cairo_pdf_version_t version); - -cairo_public void -cairo_pdf_surface_set_size (cairo_surface_t *surface, - double width_in_points, - double height_in_points); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_PDF_SURFACE */ -# error Cairo was not compiled with support for the pdf backend -#endif /* CAIRO_HAS_PDF_SURFACE */ - -#endif /* CAIRO_PDF_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pen.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pen.c deleted file mode 100644 index 61be0e8299d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pen.c +++ /dev/null @@ -1,475 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-slope-private.h" - -static void -_cairo_pen_compute_slopes (cairo_pen_t *pen); - -cairo_status_t -_cairo_pen_init (cairo_pen_t *pen, - double radius, - double tolerance, - const cairo_matrix_t *ctm) -{ - int i; - int reflect; - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - VG (VALGRIND_MAKE_MEM_UNDEFINED (pen, sizeof (cairo_pen_t))); - - pen->radius = radius; - pen->tolerance = tolerance; - - reflect = _cairo_matrix_compute_determinant (ctm) < 0.; - - pen->num_vertices = _cairo_pen_vertices_needed (tolerance, - radius, - ctm); - - if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) { - pen->vertices = _cairo_malloc_ab (pen->num_vertices, - sizeof (cairo_pen_vertex_t)); - if (unlikely (pen->vertices == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else { - pen->vertices = pen->vertices_embedded; - } - - /* - * Compute pen coordinates. To generate the right ellipse, compute points around - * a circle in user space and transform them to device space. To get a consistent - * orientation in device space, flip the pen if the transformation matrix - * is reflecting - */ - for (i=0; i < pen->num_vertices; i++) { - cairo_pen_vertex_t *v = &pen->vertices[i]; - double theta = 2 * M_PI * i / (double) pen->num_vertices, dx, dy; - if (reflect) - theta = -theta; - dx = radius * cos (theta); - dy = radius * sin (theta); - cairo_matrix_transform_distance (ctm, &dx, &dy); - v->point.x = _cairo_fixed_from_double (dx); - v->point.y = _cairo_fixed_from_double (dy); - } - - _cairo_pen_compute_slopes (pen); - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_pen_fini (cairo_pen_t *pen) -{ - if (pen->vertices != pen->vertices_embedded) - free (pen->vertices); - - - VG (VALGRIND_MAKE_MEM_NOACCESS (pen, sizeof (cairo_pen_t))); -} - -cairo_status_t -_cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (pen, sizeof (cairo_pen_t))); - - *pen = *other; - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - pen->vertices = pen->vertices_embedded; - if (pen->num_vertices) { - if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) { - pen->vertices = _cairo_malloc_ab (pen->num_vertices, - sizeof (cairo_pen_vertex_t)); - if (unlikely (pen->vertices == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - memcpy (pen->vertices, other->vertices, - pen->num_vertices * sizeof (cairo_pen_vertex_t)); - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points) -{ - cairo_status_t status; - int num_vertices; - int i; - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - num_vertices = pen->num_vertices + num_points; - if (num_vertices > ARRAY_LENGTH (pen->vertices_embedded) || - pen->vertices != pen->vertices_embedded) - { - cairo_pen_vertex_t *vertices; - - if (pen->vertices == pen->vertices_embedded) { - vertices = _cairo_malloc_ab (num_vertices, - sizeof (cairo_pen_vertex_t)); - if (unlikely (vertices == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (vertices, pen->vertices, - pen->num_vertices * sizeof (cairo_pen_vertex_t)); - } else { - vertices = _cairo_realloc_ab (pen->vertices, - num_vertices, - sizeof (cairo_pen_vertex_t)); - if (unlikely (vertices == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pen->vertices = vertices; - } - - pen->num_vertices = num_vertices; - - /* initialize new vertices */ - for (i=0; i < num_points; i++) - pen->vertices[pen->num_vertices-num_points+i].point = point[i]; - - status = _cairo_hull_compute (pen->vertices, &pen->num_vertices); - if (unlikely (status)) - return status; - - _cairo_pen_compute_slopes (pen); - - return CAIRO_STATUS_SUCCESS; -} - -/* -The circular pen in user space is transformed into an ellipse in -device space. - -We construct the pen by computing points along the circumference -using equally spaced angles. - -We show that this approximation to the ellipse has maximum error at the -major axis of the ellipse. - -Set - - M = major axis length - m = minor axis length - -Align 'M' along the X axis and 'm' along the Y axis and draw -an ellipse parameterized by angle 't': - - x = M cos t y = m sin t - -Perturb t by ± d and compute two new points (x+,y+), (x-,y-). -The distance from the average of these two points to (x,y) represents -the maximum error in approximating the ellipse with a polygon formed -from vertices 2∆ radians apart. - - x+ = M cos (t+∆) y+ = m sin (t+∆) - x- = M cos (t-∆) y- = m sin (t-∆) - -Now compute the approximation error, E: - - Ex = (x - (x+ + x-) / 2) - Ex = (M cos(t) - (Mcos(t+∆) + Mcos(t-∆))/2) - = M (cos(t) - (cos(t)cos(∆) + sin(t)sin(∆) + - cos(t)cos(∆) - sin(t)sin(∆))/2) - = M(cos(t) - cos(t)cos(∆)) - = M cos(t) (1 - cos(∆)) - - Ey = y - (y+ - y-) / 2 - = m sin (t) - (m sin(t+∆) + m sin(t-∆)) / 2 - = m (sin(t) - (sin(t)cos(∆) + cos(t)sin(∆) + - sin(t)cos(∆) - cos(t)sin(∆))/2) - = m (sin(t) - sin(t)cos(∆)) - = m sin(t) (1 - cos(∆)) - - E² = Ex² + Ey² - = (M cos(t) (1 - cos (∆)))² + (m sin(t) (1-cos(∆)))² - = (1 - cos(∆))² (M² cos²(t) + m² sin²(t)) - = (1 - cos(∆))² ((m² + M² - m²) cos² (t) + m² sin²(t)) - = (1 - cos(∆))² (M² - m²) cos² (t) + (1 - cos(∆))² m² - -Find the extremum by differentiation wrt t and setting that to zero - -∂(E²)/∂(t) = (1-cos(∆))² (M² - m²) (-2 cos(t) sin(t)) - - 0 = 2 cos (t) sin (t) - 0 = sin (2t) - t = nπ - -Which is to say that the maximum and minimum errors occur on the -axes of the ellipse at 0 and π radians: - - E²(0) = (1-cos(∆))² (M² - m²) + (1-cos(∆))² m² - = (1-cos(∆))² M² - E²(π) = (1-cos(∆))² m² - -maximum error = M (1-cos(∆)) -minimum error = m (1-cos(∆)) - -We must make maximum error ≤ tolerance, so compute the ∆ needed: - - tolerance = M (1-cos(∆)) - tolerance / M = 1 - cos (∆) - cos(∆) = 1 - tolerance/M - ∆ = acos (1 - tolerance / M); - -Remembering that ∆ is half of our angle between vertices, -the number of vertices is then - - vertices = ceil(2π/2∆). - = ceil(π/∆). - -Note that this also equation works for M == m (a circle) as it -doesn't matter where on the circle the error is computed. -*/ - -int -_cairo_pen_vertices_needed (double tolerance, - double radius, - const cairo_matrix_t *matrix) -{ - /* - * the pen is a circle that gets transformed to an ellipse by matrix. - * compute major axis length for a pen with the specified radius. - * we don't need the minor axis length. - */ - double major_axis = _cairo_matrix_transformed_circle_major_axis (matrix, - radius); - int num_vertices; - - if (tolerance >= 4*major_axis) { /* XXX relaxed from 2*major for inkscape */ - num_vertices = 1; - } else if (tolerance >= major_axis) { - num_vertices = 4; - } else { - num_vertices = ceil (2*M_PI / acos (1 - tolerance / major_axis)); - - /* number of vertices must be even */ - if (num_vertices % 2) - num_vertices++; - - /* And we must always have at least 4 vertices. */ - if (num_vertices < 4) - num_vertices = 4; - } - - return num_vertices; -} - -static void -_cairo_pen_compute_slopes (cairo_pen_t *pen) -{ - int i, i_prev; - cairo_pen_vertex_t *prev, *v, *next; - - for (i=0, i_prev = pen->num_vertices - 1; - i < pen->num_vertices; - i_prev = i++) { - prev = &pen->vertices[i_prev]; - v = &pen->vertices[i]; - next = &pen->vertices[(i + 1) % pen->num_vertices]; - - _cairo_slope_init (&v->slope_cw, &prev->point, &v->point); - _cairo_slope_init (&v->slope_ccw, &v->point, &next->point); - } -} -/* - * Find active pen vertex for clockwise edge of stroke at the given slope. - * - * The strictness of the inequalities here is delicate. The issue is - * that the slope_ccw member of one pen vertex will be equivalent to - * the slope_cw member of the next pen vertex in a counterclockwise - * order. However, for this function, we care strongly about which - * vertex is returned. - * - * [I think the "care strongly" above has to do with ensuring that the - * pen's "extra points" from the spline's initial and final slopes are - * properly found when beginning the spline stroking.] - */ -int -_cairo_pen_find_active_cw_vertex_index (const cairo_pen_t *pen, - const cairo_slope_t *slope) -{ - int i; - - for (i=0; i < pen->num_vertices; i++) { - if ((_cairo_slope_compare (slope, &pen->vertices[i].slope_ccw) < 0) && - (_cairo_slope_compare (slope, &pen->vertices[i].slope_cw) >= 0)) - break; - } - - /* If the desired slope cannot be found between any of the pen - * vertices, then we must have a degenerate pen, (such as a pen - * that's been transformed to a line). In that case, we consider - * the first pen vertex as the appropriate clockwise vertex. - */ - if (i == pen->num_vertices) - i = 0; - - return i; -} - -/* Find active pen vertex for counterclockwise edge of stroke at the given slope. - * - * Note: See the comments for _cairo_pen_find_active_cw_vertex_index - * for some details about the strictness of the inequalities here. - */ -int -_cairo_pen_find_active_ccw_vertex_index (const cairo_pen_t *pen, - const cairo_slope_t *slope) -{ - cairo_slope_t slope_reverse; - int i; - - slope_reverse = *slope; - slope_reverse.dx = -slope_reverse.dx; - slope_reverse.dy = -slope_reverse.dy; - - for (i=pen->num_vertices-1; i >= 0; i--) { - if ((_cairo_slope_compare (&pen->vertices[i].slope_ccw, &slope_reverse) >= 0) && - (_cairo_slope_compare (&pen->vertices[i].slope_cw, &slope_reverse) < 0)) - break; - } - - /* If the desired slope cannot be found between any of the pen - * vertices, then we must have a degenerate pen, (such as a pen - * that's been transformed to a line). In that case, we consider - * the last pen vertex as the appropriate counterclockwise vertex. - */ - if (i < 0) - i = pen->num_vertices - 1; - - return i; -} - -void -_cairo_pen_find_active_cw_vertices (const cairo_pen_t *pen, - const cairo_slope_t *in, - const cairo_slope_t *out, - int *start, int *stop) -{ - - int lo = 0, hi = pen->num_vertices; - int i; - - i = (lo + hi) >> 1; - do { - if (_cairo_slope_compare (&pen->vertices[i].slope_cw, in) < 0) - lo = i; - else - hi = i; - i = (lo + hi) >> 1; - } while (hi - lo > 1); - if (_cairo_slope_compare (&pen->vertices[i].slope_cw, in) < 0) - if (++i == pen->num_vertices) - i = 0; - *start = i; - - if (_cairo_slope_compare (out, &pen->vertices[i].slope_ccw) >= 0) { - lo = i; - hi = i + pen->num_vertices; - i = (lo + hi) >> 1; - do { - int j = i; - if (j >= pen->num_vertices) - j -= pen->num_vertices; - if (_cairo_slope_compare (&pen->vertices[j].slope_cw, out) > 0) - hi = i; - else - lo = i; - i = (lo + hi) >> 1; - } while (hi - lo > 1); - if (i >= pen->num_vertices) - i -= pen->num_vertices; - } - *stop = i; -} - -void -_cairo_pen_find_active_ccw_vertices (const cairo_pen_t *pen, - const cairo_slope_t *in, - const cairo_slope_t *out, - int *start, int *stop) -{ - int lo = 0, hi = pen->num_vertices; - int i; - - i = (lo + hi) >> 1; - do { - if (_cairo_slope_compare (in, &pen->vertices[i].slope_ccw) < 0) - lo = i; - else - hi = i; - i = (lo + hi) >> 1; - } while (hi - lo > 1); - if (_cairo_slope_compare (in, &pen->vertices[i].slope_ccw) < 0) - if (++i == pen->num_vertices) - i = 0; - *start = i; - - if (_cairo_slope_compare (&pen->vertices[i].slope_cw, out) <= 0) { - lo = i; - hi = i + pen->num_vertices; - i = (lo + hi) >> 1; - do { - int j = i; - if (j >= pen->num_vertices) - j -= pen->num_vertices; - if (_cairo_slope_compare (out, &pen->vertices[j].slope_ccw) > 0) - hi = i; - else - lo = i; - i = (lo + hi) >> 1; - } while (hi - lo > 1); - if (i >= pen->num_vertices) - i -= pen->num_vertices; - } - *stop = i; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pixman-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pixman-private.h deleted file mode 100644 index d705025c8ee..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-pixman-private.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright ©2013 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_PIXMAN_PRIVATE_H -#define CAIRO_PIXMAN_PRIVATE_H - -#include "cairo-pixman-private.h" /* keep make check happy */ - -#include - -#if PIXMAN_VERSION < PIXMAN_VERSION_ENCODE(0,22,0) -#define pixman_image_composite32 pixman_image_composite -#define pixman_image_get_component_alpha(i) 0 -#define pixman_image_set_component_alpha(i, x) do { } while (0) -#endif - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-png.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-png.c deleted file mode 100644 index 068617d588d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-png.c +++ /dev/null @@ -1,819 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-output-stream-private.h" - -#include -#include -#include - -/** - * SECTION:cairo-png - * @Title: PNG Support - * @Short_Description: Reading and writing PNG images - * @See_Also: #cairo_surface_t - * - * The PNG functions allow reading PNG images into image surfaces, and writing - * any surface to a PNG file. - * - * It is a toy API. It only offers very simple support for reading and - * writing PNG files, which is sufficient for testing and - * demonstration purposes. Applications which need more control over - * the generated PNG file should access the pixel data directly, using - * cairo_image_surface_get_data() or a backend-specific access - * function, and process it with another library, e.g. gdk-pixbuf or - * libpng. - **/ - -/** - * CAIRO_HAS_PNG_FUNCTIONS: - * - * Defined if the PNG functions are available. - * This macro can be used to conditionally compile code using the cairo - * PNG functions. - * - * Since: 1.0 - **/ - -struct png_read_closure_t { - cairo_read_func_t read_func; - void *closure; - cairo_output_stream_t *png_data; -}; - - -/* Unpremultiplies data and converts native endian ARGB => RGBA bytes */ -static void -unpremultiply_data (png_structp png, png_row_infop row_info, png_bytep data) -{ - unsigned int i; - - for (i = 0; i < row_info->rowbytes; i += 4) { - uint8_t *b = &data[i]; - uint32_t pixel; - uint8_t alpha; - - memcpy (&pixel, b, sizeof (uint32_t)); - alpha = (pixel & 0xff000000) >> 24; - if (alpha == 0) { - b[0] = b[1] = b[2] = b[3] = 0; - } else { - b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha; - b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha; - b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha; - b[3] = alpha; - } - } -} - -/* Converts native endian xRGB => RGBx bytes */ -static void -convert_data_to_bytes (png_structp png, png_row_infop row_info, png_bytep data) -{ - unsigned int i; - - for (i = 0; i < row_info->rowbytes; i += 4) { - uint8_t *b = &data[i]; - uint32_t pixel; - - memcpy (&pixel, b, sizeof (uint32_t)); - - b[0] = (pixel & 0xff0000) >> 16; - b[1] = (pixel & 0x00ff00) >> 8; - b[2] = (pixel & 0x0000ff) >> 0; - b[3] = 0; - } -} - -/* Use a couple of simple error callbacks that do not print anything to - * stderr and rely on the user to check for errors via the #cairo_status_t - * return. - */ -static void -png_simple_error_callback (png_structp png, - png_const_charp error_msg) -{ - cairo_status_t *error = png_get_error_ptr (png); - - /* default to the most likely error */ - if (*error == CAIRO_STATUS_SUCCESS) - *error = _cairo_error (CAIRO_STATUS_NO_MEMORY); - -#ifdef PNG_SETJMP_SUPPORTED - longjmp (png_jmpbuf (png), 1); -#endif - - /* if we get here, then we have to choice but to abort ... */ -} - -static void -png_simple_warning_callback (png_structp png, - png_const_charp error_msg) -{ - /* png does not expect to abort and will try to tidy up and continue - * loading the image after a warning. So we also want to return the - * (incorrect?) surface. - * - * We use our own warning callback to squelch any attempts by libpng - * to write to stderr as we may not be in control of that output. - */ -} - - -/* Starting with libpng-1.2.30, we must explicitly specify an output_flush_fn. - * Otherwise, we will segfault if we are writing to a stream. */ -static void -png_simple_output_flush_fn (png_structp png_ptr) -{ -} - -static cairo_status_t -write_png (cairo_surface_t *surface, - png_rw_ptr write_func, - void *closure) -{ - int i; - cairo_int_status_t status; - cairo_image_surface_t *image; - cairo_image_surface_t * volatile clone; - void *image_extra; - png_struct *png; - png_info *info; - png_byte **volatile rows = NULL; - png_color_16 white; - int png_color_type; - int bpc; - - status = _cairo_surface_acquire_source_image (surface, - &image, - &image_extra); - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - else if (unlikely (status)) - return status; - - /* PNG complains about "Image width or height is zero in IHDR" */ - if (image->width == 0 || image->height == 0) { - status = _cairo_error (CAIRO_STATUS_WRITE_ERROR); - goto BAIL1; - } - - /* Handle the various fallback formats (e.g. low bit-depth XServers) - * by coercing them to a simpler format using pixman. - */ - clone = _cairo_image_surface_coerce (image); - status = clone->base.status; - if (unlikely (status)) - goto BAIL1; - - rows = _cairo_malloc_ab (clone->height, sizeof (png_byte*)); - if (unlikely (rows == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL2; - } - - for (i = 0; i < clone->height; i++) - rows[i] = (png_byte *) clone->data + i * clone->stride; - - png = png_create_write_struct (PNG_LIBPNG_VER_STRING, &status, - png_simple_error_callback, - png_simple_warning_callback); - if (unlikely (png == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL3; - } - - info = png_create_info_struct (png); - if (unlikely (info == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL4; - } - -#ifdef PNG_SETJMP_SUPPORTED - if (setjmp (png_jmpbuf (png))) - goto BAIL4; -#endif - - png_set_write_fn (png, closure, write_func, png_simple_output_flush_fn); - - switch (clone->format) { - case CAIRO_FORMAT_ARGB32: - bpc = 8; - if (_cairo_image_analyze_transparency (clone) == CAIRO_IMAGE_IS_OPAQUE) - png_color_type = PNG_COLOR_TYPE_RGB; - else - png_color_type = PNG_COLOR_TYPE_RGB_ALPHA; - break; - case CAIRO_FORMAT_RGB30: - bpc = 10; - png_color_type = PNG_COLOR_TYPE_RGB; - break; - case CAIRO_FORMAT_RGB24: - bpc = 8; - png_color_type = PNG_COLOR_TYPE_RGB; - break; - case CAIRO_FORMAT_A8: - bpc = 8; - png_color_type = PNG_COLOR_TYPE_GRAY; - break; - case CAIRO_FORMAT_A1: - bpc = 1; - png_color_type = PNG_COLOR_TYPE_GRAY; -#ifndef WORDS_BIGENDIAN - png_set_packswap (png); -#endif - break; - case CAIRO_FORMAT_INVALID: - case CAIRO_FORMAT_RGB16_565: - default: - status = _cairo_error (CAIRO_STATUS_INVALID_FORMAT); - goto BAIL4; - } - - png_set_IHDR (png, info, - clone->width, - clone->height, bpc, - png_color_type, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - - white.gray = (1 << bpc) - 1; - white.red = white.blue = white.green = white.gray; - png_set_bKGD (png, info, &white); - - if (0) { /* XXX extract meta-data from surface (i.e. creation date) */ - png_time pt; - - png_convert_from_time_t (&pt, time (NULL)); - png_set_tIME (png, info, &pt); - } - - /* We have to call png_write_info() before setting up the write - * transformation, since it stores data internally in 'png' - * that is needed for the write transformation functions to work. - */ - png_write_info (png, info); - - if (png_color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - png_set_write_user_transform_fn (png, unpremultiply_data); - } else if (png_color_type == PNG_COLOR_TYPE_RGB) { - png_set_write_user_transform_fn (png, convert_data_to_bytes); - png_set_filler (png, 0, PNG_FILLER_AFTER); - } - - png_write_image (png, rows); - png_write_end (png, info); - -BAIL4: - png_destroy_write_struct (&png, &info); -BAIL3: - free (rows); -BAIL2: - cairo_surface_destroy (&clone->base); -BAIL1: - _cairo_surface_release_source_image (surface, image, image_extra); - - return status; -} - -static void -stdio_write_func (png_structp png, png_bytep data, png_size_t size) -{ - FILE *fp; - - fp = png_get_io_ptr (png); - while (size) { - size_t ret = fwrite (data, 1, size, fp); - size -= ret; - data += ret; - if (size && ferror (fp)) { - cairo_status_t *error = png_get_error_ptr (png); - if (*error == CAIRO_STATUS_SUCCESS) - *error = _cairo_error (CAIRO_STATUS_WRITE_ERROR); - png_error (png, NULL); - } - } -} - -/** - * cairo_surface_write_to_png: - * @surface: a #cairo_surface_t with pixel contents - * @filename: the name of a file to write to - * - * Writes the contents of @surface to a new file @filename as a PNG - * image. - * - * Return value: %CAIRO_STATUS_SUCCESS if the PNG file was written - * successfully. Otherwise, %CAIRO_STATUS_NO_MEMORY if memory could not - * be allocated for the operation or - * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have - * pixel contents, or %CAIRO_STATUS_WRITE_ERROR if an I/O error occurs - * while attempting to write the file. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_surface_write_to_png (cairo_surface_t *surface, - const char *filename) -{ - FILE *fp; - cairo_status_t status; - - if (surface->status) - return surface->status; - - if (surface->finished) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - fp = fopen (filename, "wb"); - if (fp == NULL) { - switch (errno) { - case ENOMEM: - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - default: - return _cairo_error (CAIRO_STATUS_WRITE_ERROR); - } - } - - status = write_png (surface, stdio_write_func, fp); - - if (fclose (fp) && status == CAIRO_STATUS_SUCCESS) - status = _cairo_error (CAIRO_STATUS_WRITE_ERROR); - - return status; -} - -struct png_write_closure_t { - cairo_write_func_t write_func; - void *closure; -}; - -static void -stream_write_func (png_structp png, png_bytep data, png_size_t size) -{ - cairo_status_t status; - struct png_write_closure_t *png_closure; - - png_closure = png_get_io_ptr (png); - status = png_closure->write_func (png_closure->closure, data, size); - if (unlikely (status)) { - cairo_status_t *error = png_get_error_ptr (png); - if (*error == CAIRO_STATUS_SUCCESS) - *error = status; - png_error (png, NULL); - } -} - -/** - * cairo_surface_write_to_png_stream: - * @surface: a #cairo_surface_t with pixel contents - * @write_func: a #cairo_write_func_t - * @closure: closure data for the write function - * - * Writes the image surface to the write function. - * - * Return value: %CAIRO_STATUS_SUCCESS if the PNG file was written - * successfully. Otherwise, %CAIRO_STATUS_NO_MEMORY is returned if - * memory could not be allocated for the operation, - * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have - * pixel contents. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_surface_write_to_png_stream (cairo_surface_t *surface, - cairo_write_func_t write_func, - void *closure) -{ - struct png_write_closure_t png_closure; - - if (surface->status) - return surface->status; - - if (surface->finished) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - png_closure.write_func = write_func; - png_closure.closure = closure; - - return write_png (surface, stream_write_func, &png_closure); -} -slim_hidden_def (cairo_surface_write_to_png_stream); - -static inline int -multiply_alpha (int alpha, int color) -{ - int temp = (alpha * color) + 0x80; - return ((temp + (temp >> 8)) >> 8); -} - -/* Premultiplies data and converts RGBA bytes => native endian */ -static void -premultiply_data (png_structp png, - png_row_infop row_info, - png_bytep data) -{ - unsigned int i; - - for (i = 0; i < row_info->rowbytes; i += 4) { - uint8_t *base = &data[i]; - uint8_t alpha = base[3]; - uint32_t p; - - if (alpha == 0) { - p = 0; - } else { - uint8_t red = base[0]; - uint8_t green = base[1]; - uint8_t blue = base[2]; - - if (alpha != 0xff) { - red = multiply_alpha (alpha, red); - green = multiply_alpha (alpha, green); - blue = multiply_alpha (alpha, blue); - } - p = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0); - } - memcpy (base, &p, sizeof (uint32_t)); - } -} - -/* Converts RGBx bytes to native endian xRGB */ -static void -convert_bytes_to_data (png_structp png, png_row_infop row_info, png_bytep data) -{ - unsigned int i; - - for (i = 0; i < row_info->rowbytes; i += 4) { - uint8_t *base = &data[i]; - uint8_t red = base[0]; - uint8_t green = base[1]; - uint8_t blue = base[2]; - uint32_t pixel; - - pixel = (0xff << 24) | (red << 16) | (green << 8) | (blue << 0); - memcpy (base, &pixel, sizeof (uint32_t)); - } -} - -static cairo_status_t -stdio_read_func (void *closure, unsigned char *data, unsigned int size) -{ - FILE *file = closure; - - while (size) { - size_t ret; - - ret = fread (data, 1, size, file); - size -= ret; - data += ret; - - if (size && (feof (file) || ferror (file))) - return _cairo_error (CAIRO_STATUS_READ_ERROR); - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -stream_read_func (png_structp png, png_bytep data, png_size_t size) -{ - cairo_status_t status; - struct png_read_closure_t *png_closure; - - png_closure = png_get_io_ptr (png); - status = png_closure->read_func (png_closure->closure, data, size); - if (unlikely (status)) { - cairo_status_t *error = png_get_error_ptr (png); - if (*error == CAIRO_STATUS_SUCCESS) - *error = status; - png_error (png, NULL); - } - - _cairo_output_stream_write (png_closure->png_data, data, size); -} - -static cairo_surface_t * -read_png (struct png_read_closure_t *png_closure) -{ - cairo_surface_t *surface; - png_struct *png = NULL; - png_info *info; - png_byte *data = NULL; - png_byte **row_pointers = NULL; - png_uint_32 png_width, png_height; - int depth, color_type, interlace, stride; - unsigned int i; - cairo_format_t format; - cairo_status_t status; - unsigned char *mime_data; - unsigned long mime_data_length; - - png_closure->png_data = _cairo_memory_stream_create (); - - /* XXX: Perhaps we'll want some other error handlers? */ - png = png_create_read_struct (PNG_LIBPNG_VER_STRING, - &status, - png_simple_error_callback, - png_simple_warning_callback); - if (unlikely (png == NULL)) { - surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - goto BAIL; - } - - info = png_create_info_struct (png); - if (unlikely (info == NULL)) { - surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - goto BAIL; - } - - png_set_read_fn (png, png_closure, stream_read_func); - - status = CAIRO_STATUS_SUCCESS; -#ifdef PNG_SETJMP_SUPPORTED - if (setjmp (png_jmpbuf (png))) { - surface = _cairo_surface_create_in_error (status); - goto BAIL; - } -#endif - - png_read_info (png, info); - - png_get_IHDR (png, info, - &png_width, &png_height, &depth, - &color_type, &interlace, NULL, NULL); - if (unlikely (status)) { /* catch any early warnings */ - surface = _cairo_surface_create_in_error (status); - goto BAIL; - } - - /* convert palette/gray image to rgb */ - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb (png); - - /* expand gray bit depth if needed */ - if (color_type == PNG_COLOR_TYPE_GRAY) { -#if PNG_LIBPNG_VER >= 10209 - png_set_expand_gray_1_2_4_to_8 (png); -#else - png_set_gray_1_2_4_to_8 (png); -#endif - } - - /* transform transparency to alpha */ - if (png_get_valid (png, info, PNG_INFO_tRNS)) - png_set_tRNS_to_alpha (png); - - if (depth == 16) - png_set_strip_16 (png); - - if (depth < 8) - png_set_packing (png); - - /* convert grayscale to RGB */ - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - png_set_gray_to_rgb (png); - } - - if (interlace != PNG_INTERLACE_NONE) - png_set_interlace_handling (png); - - png_set_filler (png, 0xff, PNG_FILLER_AFTER); - - /* recheck header after setting EXPAND options */ - png_read_update_info (png, info); - png_get_IHDR (png, info, - &png_width, &png_height, &depth, - &color_type, &interlace, NULL, NULL); - if (depth != 8 || - ! (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA)) - { - surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_READ_ERROR)); - goto BAIL; - } - - switch (color_type) { - default: - ASSERT_NOT_REACHED; - /* fall-through just in case ;-) */ - - case PNG_COLOR_TYPE_RGB_ALPHA: - format = CAIRO_FORMAT_ARGB32; - png_set_read_user_transform_fn (png, premultiply_data); - break; - - case PNG_COLOR_TYPE_RGB: - format = CAIRO_FORMAT_RGB24; - png_set_read_user_transform_fn (png, convert_bytes_to_data); - break; - } - - stride = cairo_format_stride_for_width (format, png_width); - if (stride < 0) { - surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); - goto BAIL; - } - - data = _cairo_malloc_ab (png_height, stride); - if (unlikely (data == NULL)) { - surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - goto BAIL; - } - - row_pointers = _cairo_malloc_ab (png_height, sizeof (char *)); - if (unlikely (row_pointers == NULL)) { - surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - goto BAIL; - } - - for (i = 0; i < png_height; i++) - row_pointers[i] = &data[i * stride]; - - png_read_image (png, row_pointers); - png_read_end (png, info); - - if (unlikely (status)) { /* catch any late warnings - probably hit an error already */ - surface = _cairo_surface_create_in_error (status); - goto BAIL; - } - - surface = cairo_image_surface_create_for_data (data, format, - png_width, png_height, - stride); - if (surface->status) - goto BAIL; - - _cairo_image_surface_assume_ownership_of_data ((cairo_image_surface_t*)surface); - data = NULL; - - _cairo_debug_check_image_surface_is_defined (surface); - - status = _cairo_memory_stream_destroy (png_closure->png_data, - &mime_data, - &mime_data_length); - png_closure->png_data = NULL; - if (unlikely (status)) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - goto BAIL; - } - - status = cairo_surface_set_mime_data (surface, - CAIRO_MIME_TYPE_PNG, - mime_data, - mime_data_length, - free, - mime_data); - if (unlikely (status)) { - free (mime_data); - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - goto BAIL; - } - - BAIL: - free (row_pointers); - free (data); - if (png != NULL) - png_destroy_read_struct (&png, &info, NULL); - if (png_closure->png_data != NULL) { - cairo_status_t status_ignored; - - status_ignored = _cairo_output_stream_destroy (png_closure->png_data); - } - - return surface; -} - -/** - * cairo_image_surface_create_from_png: - * @filename: name of PNG file to load - * - * Creates a new image surface and initializes the contents to the - * given PNG file. - * - * Return value: a new #cairo_surface_t initialized with the contents - * of the PNG file, or a "nil" surface if any error occurred. A nil - * surface can be checked for with cairo_surface_status(surface) which - * may return one of the following values: - * - * %CAIRO_STATUS_NO_MEMORY - * %CAIRO_STATUS_FILE_NOT_FOUND - * %CAIRO_STATUS_READ_ERROR - * - * Alternatively, you can allow errors to propagate through the drawing - * operations and check the status on the context upon completion - * using cairo_status(). - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_image_surface_create_from_png (const char *filename) -{ - struct png_read_closure_t png_closure; - cairo_surface_t *surface; - - png_closure.closure = fopen (filename, "rb"); - if (png_closure.closure == NULL) { - cairo_status_t status; - switch (errno) { - case ENOMEM: - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - break; - case ENOENT: - status = _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND); - break; - default: - status = _cairo_error (CAIRO_STATUS_READ_ERROR); - break; - } - return _cairo_surface_create_in_error (status); - } - - png_closure.read_func = stdio_read_func; - - surface = read_png (&png_closure); - - fclose (png_closure.closure); - - return surface; -} - -/** - * cairo_image_surface_create_from_png_stream: - * @read_func: function called to read the data of the file - * @closure: data to pass to @read_func. - * - * Creates a new image surface from PNG data read incrementally - * via the @read_func function. - * - * Return value: a new #cairo_surface_t initialized with the contents - * of the PNG file or a "nil" surface if the data read is not a valid PNG image - * or memory could not be allocated for the operation. A nil - * surface can be checked for with cairo_surface_status(surface) which - * may return one of the following values: - * - * %CAIRO_STATUS_NO_MEMORY - * %CAIRO_STATUS_READ_ERROR - * - * Alternatively, you can allow errors to propagate through the drawing - * operations and check the status on the context upon completion - * using cairo_status(). - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, - void *closure) -{ - struct png_read_closure_t png_closure; - - png_closure.read_func = read_func; - png_closure.closure = closure; - - return read_png (&png_closure); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-intersect.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-intersect.c deleted file mode 100644 index 2cd73d2e56b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-intersect.c +++ /dev/null @@ -1,1532 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" -#include "cairo-combsort-inline.h" - -typedef cairo_point_t cairo_bo_point32_t; - -typedef struct _cairo_bo_intersect_ordinate { - int32_t ordinate; - enum { EXACT, INEXACT } exactness; -} cairo_bo_intersect_ordinate_t; - -typedef struct _cairo_bo_intersect_point { - cairo_bo_intersect_ordinate_t x; - cairo_bo_intersect_ordinate_t y; -} cairo_bo_intersect_point_t; - -typedef struct _cairo_bo_edge cairo_bo_edge_t; - -typedef struct _cairo_bo_deferred { - cairo_bo_edge_t *other; - int32_t top; -} cairo_bo_deferred_t; - -struct _cairo_bo_edge { - int a_or_b; - cairo_edge_t edge; - cairo_bo_edge_t *prev; - cairo_bo_edge_t *next; - cairo_bo_deferred_t deferred; -}; - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef enum { - CAIRO_BO_EVENT_TYPE_STOP, - CAIRO_BO_EVENT_TYPE_INTERSECTION, - CAIRO_BO_EVENT_TYPE_START -} cairo_bo_event_type_t; - -typedef struct _cairo_bo_event { - cairo_bo_event_type_t type; - cairo_point_t point; -} cairo_bo_event_t; - -typedef struct _cairo_bo_start_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t edge; -} cairo_bo_start_event_t; - -typedef struct _cairo_bo_queue_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t *e1; - cairo_bo_edge_t *e2; -} cairo_bo_queue_event_t; - -typedef struct _pqueue { - int size, max_size; - - cairo_bo_event_t **elements; - cairo_bo_event_t *elements_embedded[1024]; -} pqueue_t; - -typedef struct _cairo_bo_event_queue { - cairo_freepool_t pool; - pqueue_t pqueue; - cairo_bo_event_t **start_events; -} cairo_bo_event_queue_t; - -typedef struct _cairo_bo_sweep_line { - cairo_bo_edge_t *head; - int32_t current_y; - cairo_bo_edge_t *current_edge; -} cairo_bo_sweep_line_t; - -static cairo_fixed_t -_line_compute_intersection_x_for_y (const cairo_line_t *line, - cairo_fixed_t y) -{ - cairo_fixed_t x, dy; - - if (y == line->p1.y) - return line->p1.x; - if (y == line->p2.y) - return line->p2.x; - - x = line->p1.x; - dy = line->p2.y - line->p1.y; - if (dy != 0) { - x += _cairo_fixed_mul_div_floor (y - line->p1.y, - line->p2.x - line->p1.x, - dy); - } - - return x; -} - -static inline int -_cairo_bo_point32_compare (cairo_bo_point32_t const *a, - cairo_bo_point32_t const *b) -{ - int cmp; - - cmp = a->y - b->y; - if (cmp) - return cmp; - - return a->x - b->x; -} - -/* Compare the slope of a to the slope of b, returning 1, 0, -1 if the - * slope a is respectively greater than, equal to, or less than the - * slope of b. - * - * For each edge, consider the direction vector formed from: - * - * top -> bottom - * - * which is: - * - * (dx, dy) = (line.p2.x - line.p1.x, line.p2.y - line.p1.y) - * - * We then define the slope of each edge as dx/dy, (which is the - * inverse of the slope typically used in math instruction). We never - * compute a slope directly as the value approaches infinity, but we - * can derive a slope comparison without division as follows, (where - * the ? represents our compare operator). - * - * 1. slope(a) ? slope(b) - * 2. adx/ady ? bdx/bdy - * 3. (adx * bdy) ? (bdx * ady) - * - * Note that from step 2 to step 3 there is no change needed in the - * sign of the result since both ady and bdy are guaranteed to be - * greater than or equal to 0. - * - * When using this slope comparison to sort edges, some care is needed - * when interpreting the results. Since the slope compare operates on - * distance vectors from top to bottom it gives a correct left to - * right sort for edges that have a common top point, (such as two - * edges with start events at the same location). On the other hand, - * the sense of the result will be exactly reversed for two edges that - * have a common stop point. - */ -static inline int -_slope_compare (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t adx = a->edge.line.p2.x - a->edge.line.p1.x; - int32_t bdx = b->edge.line.p2.x - b->edge.line.p1.x; - - /* Since the dy's are all positive by construction we can fast - * path several common cases. - */ - - /* First check for vertical lines. */ - if (adx == 0) - return -bdx; - if (bdx == 0) - return adx; - - /* Then where the two edges point in different directions wrt x. */ - if ((adx ^ bdx) < 0) - return adx; - - /* Finally we actually need to do the general comparison. */ - { - int32_t ady = a->edge.line.p2.y - a->edge.line.p1.y; - int32_t bdy = b->edge.line.p2.y - b->edge.line.p1.y; - cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } -} - -/* - * We need to compare the x-coordinates of a pair of lines for a particular y, - * without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy - * - (Y - A_y) * A_dx * B_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 128 bit arithmetic. For certain, but common, - * input we can reduce this down to a single 32 bit compare by inspecting the - * deltas. - * - * (And put the burden of the work on developing fast 128 bit ops, which are - * required throughout the tessellator.) - * - * See the similar discussion for _slope_compare(). - */ -static int -edges_compare_x_for_y_general (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b, - int32_t y) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t dx; - int32_t adx, ady; - int32_t bdx, bdy; - enum { - HAVE_NONE = 0x0, - HAVE_DX = 0x1, - HAVE_ADX = 0x2, - HAVE_DX_ADX = HAVE_DX | HAVE_ADX, - HAVE_BDX = 0x4, - HAVE_DX_BDX = HAVE_DX | HAVE_BDX, - HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, - HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX - } have_dx_adx_bdx = HAVE_ALL; - - /* don't bother solving for abscissa if the edges' bounding boxes - * can be used to order them. */ - { - int32_t amin, amax; - int32_t bmin, bmax; - if (a->edge.line.p1.x < a->edge.line.p2.x) { - amin = a->edge.line.p1.x; - amax = a->edge.line.p2.x; - } else { - amin = a->edge.line.p2.x; - amax = a->edge.line.p1.x; - } - if (b->edge.line.p1.x < b->edge.line.p2.x) { - bmin = b->edge.line.p1.x; - bmax = b->edge.line.p2.x; - } else { - bmin = b->edge.line.p2.x; - bmax = b->edge.line.p1.x; - } - if (amax < bmin) return -1; - if (amin > bmax) return +1; - } - - ady = a->edge.line.p2.y - a->edge.line.p1.y; - adx = a->edge.line.p2.x - a->edge.line.p1.x; - if (adx == 0) - have_dx_adx_bdx &= ~HAVE_ADX; - - bdy = b->edge.line.p2.y - b->edge.line.p1.y; - bdx = b->edge.line.p2.x - b->edge.line.p1.x; - if (bdx == 0) - have_dx_adx_bdx &= ~HAVE_BDX; - - dx = a->edge.line.p1.x - b->edge.line.p1.x; - if (dx == 0) - have_dx_adx_bdx &= ~HAVE_DX; - -#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) -#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->edge.line.p1.y) -#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->edge.line.p1.y) - switch (have_dx_adx_bdx) { - default: - case HAVE_NONE: - return 0; - case HAVE_DX: - /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ - return dx; /* ady * bdy is positive definite */ - case HAVE_ADX: - /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ - return adx; /* bdy * (y - a->top.y) is positive definite */ - case HAVE_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy */ - return -bdx; /* ady * (y - b->top.y) is positive definite */ - case HAVE_ADX_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ - if ((adx ^ bdx) < 0) { - return adx; - } else if (a->edge.line.p1.y == b->edge.line.p1.y) { /* common origin */ - cairo_int64_t adx_bdy, bdx_ady; - - /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ - - adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } else - return _cairo_int128_cmp (A, B); - case HAVE_DX_ADX: - /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ - if ((-adx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t ady_dx, dy_adx; - - ady_dx = _cairo_int32x32_64_mul (ady, dx); - dy_adx = _cairo_int32x32_64_mul (a->edge.line.p1.y - y, adx); - - return _cairo_int64_cmp (ady_dx, dy_adx); - } - case HAVE_DX_BDX: - /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ - if ((bdx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t bdy_dx, dy_bdx; - - bdy_dx = _cairo_int32x32_64_mul (bdy, dx); - dy_bdx = _cairo_int32x32_64_mul (y - b->edge.line.p1.y, bdx); - - return _cairo_int64_cmp (bdy_dx, dy_bdx); - } - case HAVE_ALL: - /* XXX try comparing (a->edge.line.p2.x - b->edge.line.p2.x) et al */ - return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); - } -#undef B -#undef A -#undef L -} - -/* - * We need to compare the x-coordinate of a line for a particular y wrt to a - * given x, without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ X - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy (and (Y - A_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 64 bit arithmetic. - * - * See the similar discussion for _slope_compare() and - * edges_compare_x_for_y_general(). - */ -static int -edge_compare_for_y_against_x (const cairo_bo_edge_t *a, - int32_t y, - int32_t x) -{ - int32_t adx, ady; - int32_t dx, dy; - cairo_int64_t L, R; - - if (x < a->edge.line.p1.x && x < a->edge.line.p2.x) - return 1; - if (x > a->edge.line.p1.x && x > a->edge.line.p2.x) - return -1; - - adx = a->edge.line.p2.x - a->edge.line.p1.x; - dx = x - a->edge.line.p1.x; - - if (adx == 0) - return -dx; - if (dx == 0 || (adx ^ dx) < 0) - return adx; - - dy = y - a->edge.line.p1.y; - ady = a->edge.line.p2.y - a->edge.line.p1.y; - - L = _cairo_int32x32_64_mul (dy, adx); - R = _cairo_int32x32_64_mul (dx, ady); - - return _cairo_int64_cmp (L, R); -} - -static int -edges_compare_x_for_y (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b, - int32_t y) -{ - /* If the sweep-line is currently on an end-point of a line, - * then we know its precise x value (and considering that we often need to - * compare events at end-points, this happens frequently enough to warrant - * special casing). - */ - enum { - HAVE_NEITHER = 0x0, - HAVE_AX = 0x1, - HAVE_BX = 0x2, - HAVE_BOTH = HAVE_AX | HAVE_BX - } have_ax_bx = HAVE_BOTH; - int32_t ax, bx; - - if (y == a->edge.line.p1.y) - ax = a->edge.line.p1.x; - else if (y == a->edge.line.p2.y) - ax = a->edge.line.p2.x; - else - have_ax_bx &= ~HAVE_AX; - - if (y == b->edge.line.p1.y) - bx = b->edge.line.p1.x; - else if (y == b->edge.line.p2.y) - bx = b->edge.line.p2.x; - else - have_ax_bx &= ~HAVE_BX; - - switch (have_ax_bx) { - default: - case HAVE_NEITHER: - return edges_compare_x_for_y_general (a, b, y); - case HAVE_AX: - return -edge_compare_for_y_against_x (b, y, ax); - case HAVE_BX: - return edge_compare_for_y_against_x (a, y, bx); - case HAVE_BOTH: - return ax - bx; - } -} - -static inline int -_line_equal (const cairo_line_t *a, const cairo_line_t *b) -{ - return a->p1.x == b->p1.x && a->p1.y == b->p1.y && - a->p2.x == b->p2.x && a->p2.y == b->p2.y; -} - -static int -_cairo_bo_sweep_line_compare_edges (cairo_bo_sweep_line_t *sweep_line, - const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - int cmp; - - /* compare the edges if not identical */ - if (! _line_equal (&a->edge.line, &b->edge.line)) { - cmp = edges_compare_x_for_y (a, b, sweep_line->current_y); - if (cmp) - return cmp; - - /* The two edges intersect exactly at y, so fall back on slope - * comparison. We know that this compare_edges function will be - * called only when starting a new edge, (not when stopping an - * edge), so we don't have to worry about conditionally inverting - * the sense of _slope_compare. */ - cmp = _slope_compare (a, b); - if (cmp) - return cmp; - } - - /* We've got two collinear edges now. */ - return b->edge.bottom - a->edge.bottom; -} - -static inline cairo_int64_t -det32_64 (int32_t a, int32_t b, - int32_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), - _cairo_int32x32_64_mul (b, c)); -} - -static inline cairo_int128_t -det64x32_128 (cairo_int64_t a, int32_t b, - cairo_int64_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), - _cairo_int64x32_128_mul (c, b)); -} - -/* Compute the intersection of two lines as defined by two edges. The - * result is provided as a coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or - * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. - */ -static cairo_bool_t -intersect_lines (cairo_bo_edge_t *a, - cairo_bo_edge_t *b, - cairo_bo_intersect_point_t *intersection) -{ - cairo_int64_t a_det, b_det; - - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm begins. - * What we're doing to mitigate this is to perform clamping in - * cairo_bo_tessellate_polygon(). - */ - int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; - int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; - - int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; - int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; - - cairo_int64_t den_det; - cairo_int64_t R; - cairo_quorem64_t qr; - - den_det = det32_64 (dx1, dy1, dx2, dy2); - - /* Q: Can we determine that the lines do not intersect (within range) - * much more cheaply than computing the intersection point i.e. by - * avoiding the division? - * - * X = ax + t * adx = bx + s * bdx; - * Y = ay + t * ady = by + s * bdy; - * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) - * => t * L = R - * - * Therefore we can reject any intersection (under the criteria for - * valid intersection events) if: - * L^R < 0 => t < 0, or - * L t > 1 - * - * (where top/bottom must at least extend to the line endpoints). - * - * A similar substitution can be performed for s, yielding: - * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) - */ - R = det32_64 (dx2, dy2, - b->edge.line.p1.x - a->edge.line.p1.x, - b->edge.line.p1.y - a->edge.line.p1.y); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - R = det32_64 (dy1, dx1, - a->edge.line.p1.y - b->edge.line.p1.y, - a->edge.line.p1.x - b->edge.line.p1.x); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - /* We now know that the two lines should intersect within range. */ - - a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, - a->edge.line.p2.x, a->edge.line.p2.y); - b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, - b->edge.line.p2.x, b->edge.line.p2.y); - - /* x = det (a_det, dx1, b_det, dx2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, - b_det, dx2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->x.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->x.exactness = INEXACT; - } -#endif - intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); - - /* y = det (a_det, dy1, b_det, dy2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, - b_det, dy2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->y.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->y.exactness = INEXACT; - } -#endif - intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); - - return TRUE; -} - -static int -_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t a, - int32_t b) -{ - /* First compare the quotient */ - if (a.ordinate > b) - return +1; - if (a.ordinate < b) - return -1; - /* With quotient identical, if remainder is 0 then compare equal */ - /* Otherwise, the non-zero remainder makes a > b */ - return INEXACT == a.exactness; -} - -/* Does the given edge contain the given point. The point must already - * be known to be contained within the line determined by the edge, - * (most likely the point results from an intersection of this edge - * with another). - * - * If we had exact arithmetic, then this function would simply be a - * matter of examining whether the y value of the point lies within - * the range of y values of the edge. But since intersection points - * are not exact due to being rounded to the nearest integer within - * the available precision, we must also examine the x value of the - * point. - * - * The definition of "contains" here is that the given intersection - * point will be seen by the sweep line after the start event for the - * given edge and before the stop event for the edge. See the comments - * in the implementation for more details. - */ -static cairo_bool_t -_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t *edge, - cairo_bo_intersect_point_t *point) -{ - int cmp_top, cmp_bottom; - - /* XXX: When running the actual algorithm, we don't actually need to - * compare against edge->top at all here, since any intersection above - * top is eliminated early via a slope comparison. We're leaving these - * here for now only for the sake of the quadratic-time intersection - * finder which needs them. - */ - - cmp_top = _cairo_bo_intersect_ordinate_32_compare (point->y, - edge->edge.top); - cmp_bottom = _cairo_bo_intersect_ordinate_32_compare (point->y, - edge->edge.bottom); - - if (cmp_top < 0 || cmp_bottom > 0) - { - return FALSE; - } - - if (cmp_top > 0 && cmp_bottom < 0) - { - return TRUE; - } - - /* At this stage, the point lies on the same y value as either - * edge->top or edge->bottom, so we have to examine the x value in - * order to properly determine containment. */ - - /* If the y value of the point is the same as the y value of the - * top of the edge, then the x value of the point must be greater - * to be considered as inside the edge. Similarly, if the y value - * of the point is the same as the y value of the bottom of the - * edge, then the x value of the point must be less to be - * considered as inside. */ - - if (cmp_top == 0) { - cairo_fixed_t top_x; - - top_x = _line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.top); - return _cairo_bo_intersect_ordinate_32_compare (point->x, top_x) > 0; - } else { /* cmp_bottom == 0 */ - cairo_fixed_t bot_x; - - bot_x = _line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.bottom); - return _cairo_bo_intersect_ordinate_32_compare (point->x, bot_x) < 0; - } -} - -/* Compute the intersection of two edges. The result is provided as a - * coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection - * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the - * intersection of the lines defined by the edges occurs outside of - * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges - * are exactly parallel. - * - * Note that when determining if a candidate intersection is "inside" - * an edge, we consider both the infinitesimal shortening and the - * infinitesimal tilt rules described by John Hobby. Specifically, if - * the intersection is exactly the same as an edge point, it is - * effectively outside (no intersection is returned). Also, if the - * intersection point has the same - */ -static cairo_bool_t -_cairo_bo_edge_intersect (cairo_bo_edge_t *a, - cairo_bo_edge_t *b, - cairo_bo_point32_t *intersection) -{ - cairo_bo_intersect_point_t quorem; - - if (! intersect_lines (a, b, &quorem)) - return FALSE; - - if (! _cairo_bo_edge_contains_intersect_point (a, &quorem)) - return FALSE; - - if (! _cairo_bo_edge_contains_intersect_point (b, &quorem)) - return FALSE; - - /* Now that we've correctly compared the intersection point and - * determined that it lies within the edge, then we know that we - * no longer need any more bits of storage for the intersection - * than we do for our edge coordinates. We also no longer need the - * remainder from the division. */ - intersection->x = quorem.x.ordinate; - intersection->y = quorem.y.ordinate; - - return TRUE; -} - -static inline int -cairo_bo_event_compare (const cairo_bo_event_t *a, - const cairo_bo_event_t *b) -{ - int cmp; - - cmp = _cairo_bo_point32_compare (&a->point, &b->point); - if (cmp) - return cmp; - - cmp = a->type - b->type; - if (cmp) - return cmp; - - return a - b; -} - -static inline void -_pqueue_init (pqueue_t *pq) -{ - pq->max_size = ARRAY_LENGTH (pq->elements_embedded); - pq->size = 0; - - pq->elements = pq->elements_embedded; -} - -static inline void -_pqueue_fini (pqueue_t *pq) -{ - if (pq->elements != pq->elements_embedded) - free (pq->elements); -} - -static cairo_status_t -_pqueue_grow (pqueue_t *pq) -{ - cairo_bo_event_t **new_elements; - pq->max_size *= 2; - - if (pq->elements == pq->elements_embedded) { - new_elements = _cairo_malloc_ab (pq->max_size, - sizeof (cairo_bo_event_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (new_elements, pq->elements_embedded, - sizeof (pq->elements_embedded)); - } else { - new_elements = _cairo_realloc_ab (pq->elements, - pq->max_size, - sizeof (cairo_bo_event_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pq->elements = new_elements; - return CAIRO_STATUS_SUCCESS; -} - -static inline cairo_status_t -_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event) -{ - cairo_bo_event_t **elements; - int i, parent; - - if (unlikely (pq->size + 1 == pq->max_size)) { - cairo_status_t status; - - status = _pqueue_grow (pq); - if (unlikely (status)) - return status; - } - - elements = pq->elements; - - for (i = ++pq->size; - i != PQ_FIRST_ENTRY && - cairo_bo_event_compare (event, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = event; - - return CAIRO_STATUS_SUCCESS; -} - -static inline void -_pqueue_pop (pqueue_t *pq) -{ - cairo_bo_event_t **elements = pq->elements; - cairo_bo_event_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - cairo_bo_event_compare (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (cairo_bo_event_compare (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline cairo_status_t -_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, - cairo_bo_event_type_t type, - cairo_bo_edge_t *e1, - cairo_bo_edge_t *e2, - const cairo_point_t *point) -{ - cairo_bo_queue_event_t *event; - - event = _cairo_freepool_alloc (&queue->pool); - if (unlikely (event == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event->type = type; - event->e1 = e1; - event->e2 = e2; - event->point = *point; - - return _pqueue_push (&queue->pqueue, (cairo_bo_event_t *) event); -} - -static void -_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue, - cairo_bo_event_t *event) -{ - _cairo_freepool_free (&queue->pool, event); -} - -static cairo_bo_event_t * -_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue) -{ - cairo_bo_event_t *event, *cmp; - - event = event_queue->pqueue.elements[PQ_FIRST_ENTRY]; - cmp = *event_queue->start_events; - if (event == NULL || - (cmp != NULL && cairo_bo_event_compare (cmp, event) < 0)) - { - event = cmp; - event_queue->start_events++; - } - else - { - _pqueue_pop (&event_queue->pqueue); - } - - return event; -} - -CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, - cairo_bo_event_t *, - cairo_bo_event_compare) - -static void -_cairo_bo_event_queue_init (cairo_bo_event_queue_t *event_queue, - cairo_bo_event_t **start_events, - int num_events) -{ - _cairo_bo_event_queue_sort (start_events, num_events); - start_events[num_events] = NULL; - - event_queue->start_events = start_events; - - _cairo_freepool_init (&event_queue->pool, - sizeof (cairo_bo_queue_event_t)); - _pqueue_init (&event_queue->pqueue); - event_queue->pqueue.elements[PQ_FIRST_ENTRY] = NULL; -} - -static cairo_status_t -event_queue_insert_stop (cairo_bo_event_queue_t *event_queue, - cairo_bo_edge_t *edge) -{ - cairo_bo_point32_t point; - - point.y = edge->edge.bottom; - point.x = _line_compute_intersection_x_for_y (&edge->edge.line, - point.y); - return _cairo_bo_event_queue_insert (event_queue, - CAIRO_BO_EVENT_TYPE_STOP, - edge, NULL, - &point); -} - -static void -_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) -{ - _pqueue_fini (&event_queue->pqueue); - _cairo_freepool_fini (&event_queue->pool); -} - -static inline cairo_status_t -event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t *event_queue, - cairo_bo_edge_t *left, - cairo_bo_edge_t *right) -{ - cairo_bo_point32_t intersection; - - if (_line_equal (&left->edge.line, &right->edge.line)) - return CAIRO_STATUS_SUCCESS; - - /* The names "left" and "right" here are correct descriptions of - * the order of the two edges within the active edge list. So if a - * slope comparison also puts left less than right, then we know - * that the intersection of these two segments has already - * occurred before the current sweep line position. */ - if (_slope_compare (left, right) <= 0) - return CAIRO_STATUS_SUCCESS; - - if (! _cairo_bo_edge_intersect (left, right, &intersection)) - return CAIRO_STATUS_SUCCESS; - - return _cairo_bo_event_queue_insert (event_queue, - CAIRO_BO_EVENT_TYPE_INTERSECTION, - left, right, - &intersection); -} - -static void -_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line) -{ - sweep_line->head = NULL; - sweep_line->current_y = INT32_MIN; - sweep_line->current_edge = NULL; -} - -static cairo_status_t -sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (sweep_line->current_edge != NULL) { - cairo_bo_edge_t *prev, *next; - int cmp; - - cmp = _cairo_bo_sweep_line_compare_edges (sweep_line, - sweep_line->current_edge, - edge); - if (cmp < 0) { - prev = sweep_line->current_edge; - next = prev->next; - while (next != NULL && - _cairo_bo_sweep_line_compare_edges (sweep_line, - next, edge) < 0) - { - prev = next, next = prev->next; - } - - prev->next = edge; - edge->prev = prev; - edge->next = next; - if (next != NULL) - next->prev = edge; - } else if (cmp > 0) { - next = sweep_line->current_edge; - prev = next->prev; - while (prev != NULL && - _cairo_bo_sweep_line_compare_edges (sweep_line, - prev, edge) > 0) - { - next = prev, prev = next->prev; - } - - next->prev = edge; - edge->next = next; - edge->prev = prev; - if (prev != NULL) - prev->next = edge; - else - sweep_line->head = edge; - } else { - prev = sweep_line->current_edge; - edge->prev = prev; - edge->next = prev->next; - if (prev->next != NULL) - prev->next->prev = edge; - prev->next = edge; - } - } else { - sweep_line->head = edge; - } - - sweep_line->current_edge = edge; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (edge->prev != NULL) - edge->prev->next = edge->next; - else - sweep_line->head = edge->next; - - if (edge->next != NULL) - edge->next->prev = edge->prev; - - if (sweep_line->current_edge == edge) - sweep_line->current_edge = edge->prev ? edge->prev : edge->next; -} - -static void -_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *left, - cairo_bo_edge_t *right) -{ - if (left->prev != NULL) - left->prev->next = right; - else - sweep_line->head = right; - - if (right->next != NULL) - right->next->prev = left; - - left->next = right->next; - right->next = left; - - right->prev = left->prev; - left->prev = right; -} - -static inline cairo_bool_t -edges_colinear (const cairo_bo_edge_t *a, const cairo_bo_edge_t *b) -{ - if (_line_equal (&a->edge.line, &b->edge.line)) - return TRUE; - - if (_slope_compare (a, b)) - return FALSE; - - /* The choice of y is not truly arbitrary since we must guarantee that it - * is greater than the start of either line. - */ - if (a->edge.line.p1.y == b->edge.line.p1.y) { - return a->edge.line.p1.x == b->edge.line.p1.x; - } else if (a->edge.line.p1.y < b->edge.line.p1.y) { - return edge_compare_for_y_against_x (b, - a->edge.line.p1.y, - a->edge.line.p1.x) == 0; - } else { - return edge_compare_for_y_against_x (a, - b->edge.line.p1.y, - b->edge.line.p1.x) == 0; - } -} - -static void -edges_end (cairo_bo_edge_t *left, - int32_t bot, - cairo_polygon_t *polygon) -{ - cairo_bo_deferred_t *l = &left->deferred; - cairo_bo_edge_t *right = l->other; - - assert(right->deferred.other == NULL); - if (likely (l->top < bot)) { - _cairo_polygon_add_line (polygon, &left->edge.line, l->top, bot, 1); - _cairo_polygon_add_line (polygon, &right->edge.line, l->top, bot, -1); - } - - l->other = NULL; -} - -static inline void -edges_start_or_continue (cairo_bo_edge_t *left, - cairo_bo_edge_t *right, - int top, - cairo_polygon_t *polygon) -{ - assert (right->deferred.other == NULL); - - if (left->deferred.other == right) - return; - - if (left->deferred.other != NULL) { - if (right != NULL && edges_colinear (left->deferred.other, right)) { - cairo_bo_edge_t *old = left->deferred.other; - - /* continuation on right, extend right to cover both */ - assert (old->deferred.other == NULL); - assert (old->edge.line.p2.y > old->edge.line.p1.y); - - if (old->edge.line.p1.y < right->edge.line.p1.y) - right->edge.line.p1 = old->edge.line.p1; - if (old->edge.line.p2.y > right->edge.line.p2.y) - right->edge.line.p2 = old->edge.line.p2; - left->deferred.other = right; - return; - } - - edges_end (left, top, polygon); - } - - if (right != NULL && ! edges_colinear (left, right)) { - left->deferred.top = top; - left->deferred.other = right; - } -} - -#define is_zero(w) ((w)[0] == 0 || (w)[1] == 0) - -static inline void -active_edges (cairo_bo_edge_t *left, - int32_t top, - cairo_polygon_t *polygon) -{ - cairo_bo_edge_t *right; - int winding[2] = {0, 0}; - - /* Yes, this is naive. Consider this a placeholder. */ - - while (left != NULL) { - assert (is_zero (winding)); - - do { - winding[left->a_or_b] += left->edge.dir; - if (! is_zero (winding)) - break; - - if unlikely ((left->deferred.other)) - edges_end (left, top, polygon); - - left = left->next; - if (! left) - return; - } while (1); - - right = left->next; - do { - if unlikely ((right->deferred.other)) - edges_end (right, top, polygon); - - winding[right->a_or_b] += right->edge.dir; - if (is_zero (winding)) { - if (right->next == NULL || - ! edges_colinear (right, right->next)) - break; - } - - right = right->next; - } while (1); - - edges_start_or_continue (left, right, top, polygon); - - left = right->next; - } -} - -static cairo_status_t -intersection_sweep (cairo_bo_event_t **start_events, - int num_events, - cairo_polygon_t *polygon) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; /* silence compiler */ - cairo_bo_event_queue_t event_queue; - cairo_bo_sweep_line_t sweep_line; - cairo_bo_event_t *event; - cairo_bo_edge_t *left, *right; - cairo_bo_edge_t *e1, *e2; - - _cairo_bo_event_queue_init (&event_queue, start_events, num_events); - _cairo_bo_sweep_line_init (&sweep_line); - - while ((event = _cairo_bo_event_dequeue (&event_queue))) { - if (event->point.y != sweep_line.current_y) { - active_edges (sweep_line.head, - sweep_line.current_y, - polygon); - sweep_line.current_y = event->point.y; - } - - switch (event->type) { - case CAIRO_BO_EVENT_TYPE_START: - e1 = &((cairo_bo_start_event_t *) event)->edge; - - status = sweep_line_insert (&sweep_line, e1); - if (unlikely (status)) - goto unwind; - - status = event_queue_insert_stop (&event_queue, e1); - if (unlikely (status)) - goto unwind; - - left = e1->prev; - right = e1->next; - - if (left != NULL) { - status = event_queue_insert_if_intersect_below_current_y (&event_queue, left, e1); - if (unlikely (status)) - goto unwind; - } - - if (right != NULL) { - status = event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); - if (unlikely (status)) - goto unwind; - } - - break; - - case CAIRO_BO_EVENT_TYPE_STOP: - e1 = ((cairo_bo_queue_event_t *) event)->e1; - _cairo_bo_event_queue_delete (&event_queue, event); - - if (e1->deferred.other) - edges_end (e1, sweep_line.current_y, polygon); - - left = e1->prev; - right = e1->next; - - _cairo_bo_sweep_line_delete (&sweep_line, e1); - - if (left != NULL && right != NULL) { - status = event_queue_insert_if_intersect_below_current_y (&event_queue, left, right); - if (unlikely (status)) - goto unwind; - } - - break; - - case CAIRO_BO_EVENT_TYPE_INTERSECTION: - e1 = ((cairo_bo_queue_event_t *) event)->e1; - e2 = ((cairo_bo_queue_event_t *) event)->e2; - _cairo_bo_event_queue_delete (&event_queue, event); - - /* skip this intersection if its edges are not adjacent */ - if (e2 != e1->next) - break; - - if (e1->deferred.other) - edges_end (e1, sweep_line.current_y, polygon); - if (e2->deferred.other) - edges_end (e2, sweep_line.current_y, polygon); - - left = e1->prev; - right = e2->next; - - _cairo_bo_sweep_line_swap (&sweep_line, e1, e2); - - /* after the swap e2 is left of e1 */ - - if (left != NULL) { - status = event_queue_insert_if_intersect_below_current_y (&event_queue, left, e2); - if (unlikely (status)) - goto unwind; - } - - if (right != NULL) { - status = event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); - if (unlikely (status)) - goto unwind; - } - - break; - } - } - - unwind: - _cairo_bo_event_queue_fini (&event_queue); - - return status; -} - -cairo_status_t -_cairo_polygon_intersect (cairo_polygon_t *a, int winding_a, - cairo_polygon_t *b, int winding_b) -{ - cairo_status_t status; - cairo_bo_start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_start_event_t)]; - cairo_bo_start_event_t *events; - cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; - cairo_bo_event_t **event_ptrs; - int num_events; - int i, j; - - /* XXX lazy */ - if (winding_a != CAIRO_FILL_RULE_WINDING) { - status = _cairo_polygon_reduce (a, winding_a); - if (unlikely (status)) - return status; - } - - if (winding_b != CAIRO_FILL_RULE_WINDING) { - status = _cairo_polygon_reduce (b, winding_b); - if (unlikely (status)) - return status; - } - - if (unlikely (0 == a->num_edges)) - return CAIRO_STATUS_SUCCESS; - - if (unlikely (0 == b->num_edges)) { - a->num_edges = 0; - return CAIRO_STATUS_SUCCESS; - } - - events = stack_events; - event_ptrs = stack_event_ptrs; - num_events = a->num_edges + b->num_edges; - if (num_events > ARRAY_LENGTH (stack_events)) { - events = _cairo_malloc_ab_plus_c (num_events, - sizeof (cairo_bo_start_event_t) + - sizeof (cairo_bo_event_t *), - sizeof (cairo_bo_event_t *)); - if (unlikely (events == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event_ptrs = (cairo_bo_event_t **) (events + num_events); - } - - j = 0; - for (i = 0; i < a->num_edges; i++) { - event_ptrs[j] = (cairo_bo_event_t *) &events[j]; - - events[j].type = CAIRO_BO_EVENT_TYPE_START; - events[j].point.y = a->edges[i].top; - events[j].point.x = - _line_compute_intersection_x_for_y (&a->edges[i].line, - events[j].point.y); - - events[j].edge.a_or_b = 0; - events[j].edge.edge = a->edges[i]; - events[j].edge.deferred.other = NULL; - events[j].edge.prev = NULL; - events[j].edge.next = NULL; - j++; - } - - for (i = 0; i < b->num_edges; i++) { - event_ptrs[j] = (cairo_bo_event_t *) &events[j]; - - events[j].type = CAIRO_BO_EVENT_TYPE_START; - events[j].point.y = b->edges[i].top; - events[j].point.x = - _line_compute_intersection_x_for_y (&b->edges[i].line, - events[j].point.y); - - events[j].edge.a_or_b = 1; - events[j].edge.edge = b->edges[i]; - events[j].edge.deferred.other = NULL; - events[j].edge.prev = NULL; - events[j].edge.next = NULL; - j++; - } - assert (j == num_events); - -#if 0 - { - FILE *file = fopen ("clip_a.txt", "w"); - _cairo_debug_print_polygon (file, a); - fclose (file); - } - { - FILE *file = fopen ("clip_b.txt", "w"); - _cairo_debug_print_polygon (file, b); - fclose (file); - } -#endif - - a->num_edges = 0; - status = intersection_sweep (event_ptrs, num_events, a); - if (events != stack_events) - free (events); - -#if 0 - { - FILE *file = fopen ("clip_result.txt", "w"); - _cairo_debug_print_polygon (file, a); - fclose (file); - } -#endif - - return status; -} - -cairo_status_t -_cairo_polygon_intersect_with_boxes (cairo_polygon_t *polygon, - cairo_fill_rule_t *winding, - cairo_box_t *boxes, - int num_boxes) -{ - cairo_polygon_t b; - cairo_status_t status; - int n; - - if (num_boxes == 0) { - polygon->num_edges = 0; - return CAIRO_STATUS_SUCCESS; - } - - for (n = 0; n < num_boxes; n++) { - if (polygon->extents.p1.x >= boxes[n].p1.x && - polygon->extents.p2.x <= boxes[n].p2.x && - polygon->extents.p1.y >= boxes[n].p1.y && - polygon->extents.p2.y <= boxes[n].p2.y) - { - return CAIRO_STATUS_SUCCESS; - } - } - - _cairo_polygon_init (&b, NULL, 0); - for (n = 0; n < num_boxes; n++) { - if (boxes[n].p2.x > polygon->extents.p1.x && - boxes[n].p1.x < polygon->extents.p2.x && - boxes[n].p2.y > polygon->extents.p1.y && - boxes[n].p1.y < polygon->extents.p2.y) - { - cairo_point_t p1, p2; - - p1.y = boxes[n].p1.y; - p2.y = boxes[n].p2.y; - - p2.x = p1.x = boxes[n].p1.x; - _cairo_polygon_add_external_edge (&b, &p1, &p2); - - p2.x = p1.x = boxes[n].p2.x; - _cairo_polygon_add_external_edge (&b, &p2, &p1); - } - } - - status = _cairo_polygon_intersect (polygon, *winding, - &b, CAIRO_FILL_RULE_WINDING); - _cairo_polygon_fini (&b); - - *winding = CAIRO_FILL_RULE_WINDING; - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-reduce.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-reduce.c deleted file mode 100644 index ea457fe4edf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon-reduce.c +++ /dev/null @@ -1,1438 +0,0 @@ -/* - * Copyright © 2004 Carl Worth - * Copyright © 2006 Red Hat, Inc. - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Carl Worth - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -/* Provide definitions for standalone compilation */ -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" -#include "cairo-combsort-inline.h" - -#define DEBUG_POLYGON 0 - -typedef cairo_point_t cairo_bo_point32_t; - -typedef struct _cairo_bo_intersect_ordinate { - int32_t ordinate; - enum { EXACT, INEXACT } exactness; -} cairo_bo_intersect_ordinate_t; - -typedef struct _cairo_bo_intersect_point { - cairo_bo_intersect_ordinate_t x; - cairo_bo_intersect_ordinate_t y; -} cairo_bo_intersect_point_t; - -typedef struct _cairo_bo_edge cairo_bo_edge_t; - -typedef struct _cairo_bo_deferred { - cairo_bo_edge_t *right; - int32_t top; -} cairo_bo_deferred_t; - -struct _cairo_bo_edge { - cairo_edge_t edge; - cairo_bo_edge_t *prev; - cairo_bo_edge_t *next; - cairo_bo_deferred_t deferred; -}; - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef enum { - CAIRO_BO_EVENT_TYPE_STOP, - CAIRO_BO_EVENT_TYPE_INTERSECTION, - CAIRO_BO_EVENT_TYPE_START -} cairo_bo_event_type_t; - -typedef struct _cairo_bo_event { - cairo_bo_event_type_t type; - cairo_point_t point; -} cairo_bo_event_t; - -typedef struct _cairo_bo_start_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t edge; -} cairo_bo_start_event_t; - -typedef struct _cairo_bo_queue_event { - cairo_bo_event_type_t type; - cairo_point_t point; - cairo_bo_edge_t *e1; - cairo_bo_edge_t *e2; -} cairo_bo_queue_event_t; - -typedef struct _pqueue { - int size, max_size; - - cairo_bo_event_t **elements; - cairo_bo_event_t *elements_embedded[1024]; -} pqueue_t; - -typedef struct _cairo_bo_event_queue { - cairo_freepool_t pool; - pqueue_t pqueue; - cairo_bo_event_t **start_events; -} cairo_bo_event_queue_t; - -typedef struct _cairo_bo_sweep_line { - cairo_bo_edge_t *head; - int32_t current_y; - cairo_bo_edge_t *current_edge; -} cairo_bo_sweep_line_t; - -static cairo_fixed_t -_line_compute_intersection_x_for_y (const cairo_line_t *line, - cairo_fixed_t y) -{ - cairo_fixed_t x, dy; - - if (y == line->p1.y) - return line->p1.x; - if (y == line->p2.y) - return line->p2.x; - - x = line->p1.x; - dy = line->p2.y - line->p1.y; - if (dy != 0) { - x += _cairo_fixed_mul_div_floor (y - line->p1.y, - line->p2.x - line->p1.x, - dy); - } - - return x; -} - -static inline int -_cairo_bo_point32_compare (cairo_bo_point32_t const *a, - cairo_bo_point32_t const *b) -{ - int cmp; - - cmp = a->y - b->y; - if (cmp) - return cmp; - - return a->x - b->x; -} - -/* Compare the slope of a to the slope of b, returning 1, 0, -1 if the - * slope a is respectively greater than, equal to, or less than the - * slope of b. - * - * For each edge, consider the direction vector formed from: - * - * top -> bottom - * - * which is: - * - * (dx, dy) = (line.p2.x - line.p1.x, line.p2.y - line.p1.y) - * - * We then define the slope of each edge as dx/dy, (which is the - * inverse of the slope typically used in math instruction). We never - * compute a slope directly as the value approaches infinity, but we - * can derive a slope comparison without division as follows, (where - * the ? represents our compare operator). - * - * 1. slope(a) ? slope(b) - * 2. adx/ady ? bdx/bdy - * 3. (adx * bdy) ? (bdx * ady) - * - * Note that from step 2 to step 3 there is no change needed in the - * sign of the result since both ady and bdy are guaranteed to be - * greater than or equal to 0. - * - * When using this slope comparison to sort edges, some care is needed - * when interpreting the results. Since the slope compare operates on - * distance vectors from top to bottom it gives a correct left to - * right sort for edges that have a common top point, (such as two - * edges with start events at the same location). On the other hand, - * the sense of the result will be exactly reversed for two edges that - * have a common stop point. - */ -static inline int -_slope_compare (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t adx = a->edge.line.p2.x - a->edge.line.p1.x; - int32_t bdx = b->edge.line.p2.x - b->edge.line.p1.x; - - /* Since the dy's are all positive by construction we can fast - * path several common cases. - */ - - /* First check for vertical lines. */ - if (adx == 0) - return -bdx; - if (bdx == 0) - return adx; - - /* Then where the two edges point in different directions wrt x. */ - if ((adx ^ bdx) < 0) - return adx; - - /* Finally we actually need to do the general comparison. */ - { - int32_t ady = a->edge.line.p2.y - a->edge.line.p1.y; - int32_t bdy = b->edge.line.p2.y - b->edge.line.p1.y; - cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } -} - -/* - * We need to compare the x-coordinates of a pair of lines for a particular y, - * without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy - * - (Y - A_y) * A_dx * B_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 128 bit arithmetic. For certain, but common, - * input we can reduce this down to a single 32 bit compare by inspecting the - * deltas. - * - * (And put the burden of the work on developing fast 128 bit ops, which are - * required throughout the tessellator.) - * - * See the similar discussion for _slope_compare(). - */ -static int -edges_compare_x_for_y_general (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b, - int32_t y) -{ - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm - * begins. - */ - int32_t dx; - int32_t adx, ady; - int32_t bdx, bdy; - enum { - HAVE_NONE = 0x0, - HAVE_DX = 0x1, - HAVE_ADX = 0x2, - HAVE_DX_ADX = HAVE_DX | HAVE_ADX, - HAVE_BDX = 0x4, - HAVE_DX_BDX = HAVE_DX | HAVE_BDX, - HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, - HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX - } have_dx_adx_bdx = HAVE_ALL; - - /* don't bother solving for abscissa if the edges' bounding boxes - * can be used to order them. */ - { - int32_t amin, amax; - int32_t bmin, bmax; - if (a->edge.line.p1.x < a->edge.line.p2.x) { - amin = a->edge.line.p1.x; - amax = a->edge.line.p2.x; - } else { - amin = a->edge.line.p2.x; - amax = a->edge.line.p1.x; - } - if (b->edge.line.p1.x < b->edge.line.p2.x) { - bmin = b->edge.line.p1.x; - bmax = b->edge.line.p2.x; - } else { - bmin = b->edge.line.p2.x; - bmax = b->edge.line.p1.x; - } - if (amax < bmin) return -1; - if (amin > bmax) return +1; - } - - ady = a->edge.line.p2.y - a->edge.line.p1.y; - adx = a->edge.line.p2.x - a->edge.line.p1.x; - if (adx == 0) - have_dx_adx_bdx &= ~HAVE_ADX; - - bdy = b->edge.line.p2.y - b->edge.line.p1.y; - bdx = b->edge.line.p2.x - b->edge.line.p1.x; - if (bdx == 0) - have_dx_adx_bdx &= ~HAVE_BDX; - - dx = a->edge.line.p1.x - b->edge.line.p1.x; - if (dx == 0) - have_dx_adx_bdx &= ~HAVE_DX; - -#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) -#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->edge.line.p1.y) -#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->edge.line.p1.y) - switch (have_dx_adx_bdx) { - default: - case HAVE_NONE: - return 0; - case HAVE_DX: - /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ - return dx; /* ady * bdy is positive definite */ - case HAVE_ADX: - /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ - return adx; /* bdy * (y - a->top.y) is positive definite */ - case HAVE_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy */ - return -bdx; /* ady * (y - b->top.y) is positive definite */ - case HAVE_ADX_BDX: - /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ - if ((adx ^ bdx) < 0) { - return adx; - } else if (a->edge.line.p1.y == b->edge.line.p1.y) { /* common origin */ - cairo_int64_t adx_bdy, bdx_ady; - - /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ - - adx_bdy = _cairo_int32x32_64_mul (adx, bdy); - bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - - return _cairo_int64_cmp (adx_bdy, bdx_ady); - } else - return _cairo_int128_cmp (A, B); - case HAVE_DX_ADX: - /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ - if ((-adx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t ady_dx, dy_adx; - - ady_dx = _cairo_int32x32_64_mul (ady, dx); - dy_adx = _cairo_int32x32_64_mul (a->edge.line.p1.y - y, adx); - - return _cairo_int64_cmp (ady_dx, dy_adx); - } - case HAVE_DX_BDX: - /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ - if ((bdx ^ dx) < 0) { - return dx; - } else { - cairo_int64_t bdy_dx, dy_bdx; - - bdy_dx = _cairo_int32x32_64_mul (bdy, dx); - dy_bdx = _cairo_int32x32_64_mul (y - b->edge.line.p1.y, bdx); - - return _cairo_int64_cmp (bdy_dx, dy_bdx); - } - case HAVE_ALL: - /* XXX try comparing (a->edge.line.p2.x - b->edge.line.p2.x) et al */ - return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); - } -#undef B -#undef A -#undef L -} - -/* - * We need to compare the x-coordinate of a line for a particular y wrt to a - * given x, without loss of precision. - * - * The x-coordinate along an edge for a given y is: - * X = A_x + (Y - A_y) * A_dx / A_dy - * - * So the inequality we wish to test is: - * A_x + (Y - A_y) * A_dx / A_dy ∘ X - * where ∘ is our inequality operator. - * - * By construction, we know that A_dy (and (Y - A_y)) are - * all positive, so we can rearrange it thus without causing a sign change: - * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy - * - * Given the assumption that all the deltas fit within 32 bits, we can compute - * this comparison directly using 64 bit arithmetic. - * - * See the similar discussion for _slope_compare() and - * edges_compare_x_for_y_general(). - */ -static int -edge_compare_for_y_against_x (const cairo_bo_edge_t *a, - int32_t y, - int32_t x) -{ - int32_t adx, ady; - int32_t dx, dy; - cairo_int64_t L, R; - - if (x < a->edge.line.p1.x && x < a->edge.line.p2.x) - return 1; - if (x > a->edge.line.p1.x && x > a->edge.line.p2.x) - return -1; - - adx = a->edge.line.p2.x - a->edge.line.p1.x; - dx = x - a->edge.line.p1.x; - - if (adx == 0) - return -dx; - if (dx == 0 || (adx ^ dx) < 0) - return adx; - - dy = y - a->edge.line.p1.y; - ady = a->edge.line.p2.y - a->edge.line.p1.y; - - L = _cairo_int32x32_64_mul (dy, adx); - R = _cairo_int32x32_64_mul (dx, ady); - - return _cairo_int64_cmp (L, R); -} - -static int -edges_compare_x_for_y (const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b, - int32_t y) -{ - /* If the sweep-line is currently on an end-point of a line, - * then we know its precise x value (and considering that we often need to - * compare events at end-points, this happens frequently enough to warrant - * special casing). - */ - enum { - HAVE_NEITHER = 0x0, - HAVE_AX = 0x1, - HAVE_BX = 0x2, - HAVE_BOTH = HAVE_AX | HAVE_BX - } have_ax_bx = HAVE_BOTH; - int32_t ax, bx; - - if (y == a->edge.line.p1.y) - ax = a->edge.line.p1.x; - else if (y == a->edge.line.p2.y) - ax = a->edge.line.p2.x; - else - have_ax_bx &= ~HAVE_AX; - - if (y == b->edge.line.p1.y) - bx = b->edge.line.p1.x; - else if (y == b->edge.line.p2.y) - bx = b->edge.line.p2.x; - else - have_ax_bx &= ~HAVE_BX; - - switch (have_ax_bx) { - default: - case HAVE_NEITHER: - return edges_compare_x_for_y_general (a, b, y); - case HAVE_AX: - return -edge_compare_for_y_against_x (b, y, ax); - case HAVE_BX: - return edge_compare_for_y_against_x (a, y, bx); - case HAVE_BOTH: - return ax - bx; - } -} - -static inline int -_line_equal (const cairo_line_t *a, const cairo_line_t *b) -{ - return (a->p1.x == b->p1.x && a->p1.y == b->p1.y && - a->p2.x == b->p2.x && a->p2.y == b->p2.y); -} - -static int -_cairo_bo_sweep_line_compare_edges (cairo_bo_sweep_line_t *sweep_line, - const cairo_bo_edge_t *a, - const cairo_bo_edge_t *b) -{ - int cmp; - - /* compare the edges if not identical */ - if (! _line_equal (&a->edge.line, &b->edge.line)) { - cmp = edges_compare_x_for_y (a, b, sweep_line->current_y); - if (cmp) - return cmp; - - /* The two edges intersect exactly at y, so fall back on slope - * comparison. We know that this compare_edges function will be - * called only when starting a new edge, (not when stopping an - * edge), so we don't have to worry about conditionally inverting - * the sense of _slope_compare. */ - cmp = _slope_compare (a, b); - if (cmp) - return cmp; - } - - /* We've got two collinear edges now. */ - return b->edge.bottom - a->edge.bottom; -} - -static inline cairo_int64_t -det32_64 (int32_t a, int32_t b, - int32_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), - _cairo_int32x32_64_mul (b, c)); -} - -static inline cairo_int128_t -det64x32_128 (cairo_int64_t a, int32_t b, - cairo_int64_t c, int32_t d) -{ - /* det = a * d - b * c */ - return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), - _cairo_int64x32_128_mul (c, b)); -} - -/* Compute the intersection of two lines as defined by two edges. The - * result is provided as a coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or - * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. - */ -static cairo_bool_t -intersect_lines (cairo_bo_edge_t *a, - cairo_bo_edge_t *b, - cairo_bo_intersect_point_t *intersection) -{ - cairo_int64_t a_det, b_det; - - /* XXX: We're assuming here that dx and dy will still fit in 32 - * bits. That's not true in general as there could be overflow. We - * should prevent that before the tessellation algorithm begins. - * What we're doing to mitigate this is to perform clamping in - * cairo_bo_tessellate_polygon(). - */ - int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; - int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; - - int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; - int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; - - cairo_int64_t den_det; - cairo_int64_t R; - cairo_quorem64_t qr; - - den_det = det32_64 (dx1, dy1, dx2, dy2); - - /* Q: Can we determine that the lines do not intersect (within range) - * much more cheaply than computing the intersection point i.e. by - * avoiding the division? - * - * X = ax + t * adx = bx + s * bdx; - * Y = ay + t * ady = by + s * bdy; - * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) - * => t * L = R - * - * Therefore we can reject any intersection (under the criteria for - * valid intersection events) if: - * L^R < 0 => t < 0, or - * L t > 1 - * - * (where top/bottom must at least extend to the line endpoints). - * - * A similar substitution can be performed for s, yielding: - * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) - */ - R = det32_64 (dx2, dy2, - b->edge.line.p1.x - a->edge.line.p1.x, - b->edge.line.p1.y - a->edge.line.p1.y); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - R = det32_64 (dy1, dx1, - a->edge.line.p1.y - b->edge.line.p1.y, - a->edge.line.p1.x - b->edge.line.p1.x); - if (_cairo_int64_negative (den_det)) { - if (_cairo_int64_ge (den_det, R)) - return FALSE; - } else { - if (_cairo_int64_le (den_det, R)) - return FALSE; - } - - /* We now know that the two lines should intersect within range. */ - - a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, - a->edge.line.p2.x, a->edge.line.p2.y); - b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, - b->edge.line.p2.x, b->edge.line.p2.y); - - /* x = det (a_det, dx1, b_det, dx2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, - b_det, dx2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->x.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->x.exactness = INEXACT; - } -#endif - intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); - - /* y = det (a_det, dy1, b_det, dy2) / den_det */ - qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, - b_det, dy2), - den_det); - if (_cairo_int64_eq (qr.rem, den_det)) - return FALSE; -#if 0 - intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; -#else - intersection->y.exactness = EXACT; - if (! _cairo_int64_is_zero (qr.rem)) { - if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) - qr.rem = _cairo_int64_negate (qr.rem); - qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); - if (_cairo_int64_ge (qr.rem, den_det)) { - qr.quo = _cairo_int64_add (qr.quo, - _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); - } else - intersection->y.exactness = INEXACT; - } -#endif - intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); - - return TRUE; -} - -static int -_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t a, - int32_t b) -{ - /* First compare the quotient */ - if (a.ordinate > b) - return +1; - if (a.ordinate < b) - return -1; - /* With quotient identical, if remainder is 0 then compare equal */ - /* Otherwise, the non-zero remainder makes a > b */ - return INEXACT == a.exactness; -} - -/* Does the given edge contain the given point. The point must already - * be known to be contained within the line determined by the edge, - * (most likely the point results from an intersection of this edge - * with another). - * - * If we had exact arithmetic, then this function would simply be a - * matter of examining whether the y value of the point lies within - * the range of y values of the edge. But since intersection points - * are not exact due to being rounded to the nearest integer within - * the available precision, we must also examine the x value of the - * point. - * - * The definition of "contains" here is that the given intersection - * point will be seen by the sweep line after the start event for the - * given edge and before the stop event for the edge. See the comments - * in the implementation for more details. - */ -static cairo_bool_t -_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t *edge, - cairo_bo_intersect_point_t *point) -{ - int cmp_top, cmp_bottom; - - /* XXX: When running the actual algorithm, we don't actually need to - * compare against edge->top at all here, since any intersection above - * top is eliminated early via a slope comparison. We're leaving these - * here for now only for the sake of the quadratic-time intersection - * finder which needs them. - */ - - cmp_top = _cairo_bo_intersect_ordinate_32_compare (point->y, - edge->edge.top); - cmp_bottom = _cairo_bo_intersect_ordinate_32_compare (point->y, - edge->edge.bottom); - - if (cmp_top < 0 || cmp_bottom > 0) - { - return FALSE; - } - - if (cmp_top > 0 && cmp_bottom < 0) - { - return TRUE; - } - - /* At this stage, the point lies on the same y value as either - * edge->top or edge->bottom, so we have to examine the x value in - * order to properly determine containment. */ - - /* If the y value of the point is the same as the y value of the - * top of the edge, then the x value of the point must be greater - * to be considered as inside the edge. Similarly, if the y value - * of the point is the same as the y value of the bottom of the - * edge, then the x value of the point must be less to be - * considered as inside. */ - - if (cmp_top == 0) { - cairo_fixed_t top_x; - - top_x = _line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.top); - return _cairo_bo_intersect_ordinate_32_compare (point->x, top_x) > 0; - } else { /* cmp_bottom == 0 */ - cairo_fixed_t bot_x; - - bot_x = _line_compute_intersection_x_for_y (&edge->edge.line, - edge->edge.bottom); - return _cairo_bo_intersect_ordinate_32_compare (point->x, bot_x) < 0; - } -} - -/* Compute the intersection of two edges. The result is provided as a - * coordinate pair of 128-bit integers. - * - * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection - * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the - * intersection of the lines defined by the edges occurs outside of - * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges - * are exactly parallel. - * - * Note that when determining if a candidate intersection is "inside" - * an edge, we consider both the infinitesimal shortening and the - * infinitesimal tilt rules described by John Hobby. Specifically, if - * the intersection is exactly the same as an edge point, it is - * effectively outside (no intersection is returned). Also, if the - * intersection point has the same - */ -static cairo_bool_t -_cairo_bo_edge_intersect (cairo_bo_edge_t *a, - cairo_bo_edge_t *b, - cairo_bo_point32_t *intersection) -{ - cairo_bo_intersect_point_t quorem; - - if (! intersect_lines (a, b, &quorem)) - return FALSE; - - if (! _cairo_bo_edge_contains_intersect_point (a, &quorem)) - return FALSE; - - if (! _cairo_bo_edge_contains_intersect_point (b, &quorem)) - return FALSE; - - /* Now that we've correctly compared the intersection point and - * determined that it lies within the edge, then we know that we - * no longer need any more bits of storage for the intersection - * than we do for our edge coordinates. We also no longer need the - * remainder from the division. */ - intersection->x = quorem.x.ordinate; - intersection->y = quorem.y.ordinate; - - return TRUE; -} - -static inline int -cairo_bo_event_compare (const cairo_bo_event_t *a, - const cairo_bo_event_t *b) -{ - int cmp; - - cmp = _cairo_bo_point32_compare (&a->point, &b->point); - if (cmp) - return cmp; - - cmp = a->type - b->type; - if (cmp) - return cmp; - - return a - b; -} - -static inline void -_pqueue_init (pqueue_t *pq) -{ - pq->max_size = ARRAY_LENGTH (pq->elements_embedded); - pq->size = 0; - - pq->elements = pq->elements_embedded; -} - -static inline void -_pqueue_fini (pqueue_t *pq) -{ - if (pq->elements != pq->elements_embedded) - free (pq->elements); -} - -static cairo_status_t -_pqueue_grow (pqueue_t *pq) -{ - cairo_bo_event_t **new_elements; - pq->max_size *= 2; - - if (pq->elements == pq->elements_embedded) { - new_elements = _cairo_malloc_ab (pq->max_size, - sizeof (cairo_bo_event_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (new_elements, pq->elements_embedded, - sizeof (pq->elements_embedded)); - } else { - new_elements = _cairo_realloc_ab (pq->elements, - pq->max_size, - sizeof (cairo_bo_event_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pq->elements = new_elements; - return CAIRO_STATUS_SUCCESS; -} - -static inline cairo_status_t -_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event) -{ - cairo_bo_event_t **elements; - int i, parent; - - if (unlikely (pq->size + 1 == pq->max_size)) { - cairo_status_t status; - - status = _pqueue_grow (pq); - if (unlikely (status)) - return status; - } - - elements = pq->elements; - - for (i = ++pq->size; - i != PQ_FIRST_ENTRY && - cairo_bo_event_compare (event, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = event; - - return CAIRO_STATUS_SUCCESS; -} - -static inline void -_pqueue_pop (pqueue_t *pq) -{ - cairo_bo_event_t **elements = pq->elements; - cairo_bo_event_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - cairo_bo_event_compare (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (cairo_bo_event_compare (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline cairo_status_t -_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, - cairo_bo_event_type_t type, - cairo_bo_edge_t *e1, - cairo_bo_edge_t *e2, - const cairo_point_t *point) -{ - cairo_bo_queue_event_t *event; - - event = _cairo_freepool_alloc (&queue->pool); - if (unlikely (event == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event->type = type; - event->e1 = e1; - event->e2 = e2; - event->point = *point; - - return _pqueue_push (&queue->pqueue, (cairo_bo_event_t *) event); -} - -static void -_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue, - cairo_bo_event_t *event) -{ - _cairo_freepool_free (&queue->pool, event); -} - -static cairo_bo_event_t * -_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue) -{ - cairo_bo_event_t *event, *cmp; - - event = event_queue->pqueue.elements[PQ_FIRST_ENTRY]; - cmp = *event_queue->start_events; - if (event == NULL || - (cmp != NULL && cairo_bo_event_compare (cmp, event) < 0)) - { - event = cmp; - event_queue->start_events++; - } - else - { - _pqueue_pop (&event_queue->pqueue); - } - - return event; -} - -CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, - cairo_bo_event_t *, - cairo_bo_event_compare) - -static void -_cairo_bo_event_queue_init (cairo_bo_event_queue_t *event_queue, - cairo_bo_event_t **start_events, - int num_events) -{ - _cairo_bo_event_queue_sort (start_events, num_events); - start_events[num_events] = NULL; - - event_queue->start_events = start_events; - - _cairo_freepool_init (&event_queue->pool, - sizeof (cairo_bo_queue_event_t)); - _pqueue_init (&event_queue->pqueue); - event_queue->pqueue.elements[PQ_FIRST_ENTRY] = NULL; -} - -static cairo_status_t -_cairo_bo_event_queue_insert_stop (cairo_bo_event_queue_t *event_queue, - cairo_bo_edge_t *edge) -{ - cairo_bo_point32_t point; - - point.y = edge->edge.bottom; - point.x = _line_compute_intersection_x_for_y (&edge->edge.line, - point.y); - return _cairo_bo_event_queue_insert (event_queue, - CAIRO_BO_EVENT_TYPE_STOP, - edge, NULL, - &point); -} - -static void -_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) -{ - _pqueue_fini (&event_queue->pqueue); - _cairo_freepool_fini (&event_queue->pool); -} - -static inline cairo_status_t -_cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t *event_queue, - cairo_bo_edge_t *left, - cairo_bo_edge_t *right) -{ - cairo_bo_point32_t intersection; - - if (_line_equal (&left->edge.line, &right->edge.line)) - return CAIRO_STATUS_SUCCESS; - - /* The names "left" and "right" here are correct descriptions of - * the order of the two edges within the active edge list. So if a - * slope comparison also puts left less than right, then we know - * that the intersection of these two segments has already - * occurred before the current sweep line position. */ - if (_slope_compare (left, right) <= 0) - return CAIRO_STATUS_SUCCESS; - - if (! _cairo_bo_edge_intersect (left, right, &intersection)) - return CAIRO_STATUS_SUCCESS; - - return _cairo_bo_event_queue_insert (event_queue, - CAIRO_BO_EVENT_TYPE_INTERSECTION, - left, right, - &intersection); -} - -static void -_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line) -{ - sweep_line->head = NULL; - sweep_line->current_y = INT32_MIN; - sweep_line->current_edge = NULL; -} - -static cairo_status_t -_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (sweep_line->current_edge != NULL) { - cairo_bo_edge_t *prev, *next; - int cmp; - - cmp = _cairo_bo_sweep_line_compare_edges (sweep_line, - sweep_line->current_edge, - edge); - if (cmp < 0) { - prev = sweep_line->current_edge; - next = prev->next; - while (next != NULL && - _cairo_bo_sweep_line_compare_edges (sweep_line, - next, edge) < 0) - { - prev = next, next = prev->next; - } - - prev->next = edge; - edge->prev = prev; - edge->next = next; - if (next != NULL) - next->prev = edge; - } else if (cmp > 0) { - next = sweep_line->current_edge; - prev = next->prev; - while (prev != NULL && - _cairo_bo_sweep_line_compare_edges (sweep_line, - prev, edge) > 0) - { - next = prev, prev = next->prev; - } - - next->prev = edge; - edge->next = next; - edge->prev = prev; - if (prev != NULL) - prev->next = edge; - else - sweep_line->head = edge; - } else { - prev = sweep_line->current_edge; - edge->prev = prev; - edge->next = prev->next; - if (prev->next != NULL) - prev->next->prev = edge; - prev->next = edge; - } - } else { - sweep_line->head = edge; - } - - sweep_line->current_edge = edge; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *edge) -{ - if (edge->prev != NULL) - edge->prev->next = edge->next; - else - sweep_line->head = edge->next; - - if (edge->next != NULL) - edge->next->prev = edge->prev; - - if (sweep_line->current_edge == edge) - sweep_line->current_edge = edge->prev ? edge->prev : edge->next; -} - -static void -_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t *sweep_line, - cairo_bo_edge_t *left, - cairo_bo_edge_t *right) -{ - if (left->prev != NULL) - left->prev->next = right; - else - sweep_line->head = right; - - if (right->next != NULL) - right->next->prev = left; - - left->next = right->next; - right->next = left; - - right->prev = left->prev; - left->prev = right; -} - -static inline cairo_bool_t -edges_colinear (const cairo_bo_edge_t *a, const cairo_bo_edge_t *b) -{ - if (_line_equal (&a->edge.line, &b->edge.line)) - return TRUE; - - if (_slope_compare (a, b)) - return FALSE; - - /* The choice of y is not truly arbitrary since we must guarantee that it - * is greater than the start of either line. - */ - if (a->edge.line.p1.y == b->edge.line.p1.y) { - return a->edge.line.p1.x == b->edge.line.p1.x; - } else if (a->edge.line.p2.y == b->edge.line.p2.y) { - return a->edge.line.p2.x == b->edge.line.p2.x; - } else if (a->edge.line.p1.y < b->edge.line.p1.y) { - return edge_compare_for_y_against_x (b, - a->edge.line.p1.y, - a->edge.line.p1.x) == 0; - } else { - return edge_compare_for_y_against_x (a, - b->edge.line.p1.y, - b->edge.line.p1.x) == 0; - } -} - -static void -_cairo_bo_edge_end (cairo_bo_edge_t *left, - int32_t bot, - cairo_polygon_t *polygon) -{ - cairo_bo_deferred_t *d = &left->deferred; - - if (likely (d->top < bot)) { - _cairo_polygon_add_line (polygon, - &left->edge.line, - d->top, bot, - 1); - _cairo_polygon_add_line (polygon, - &d->right->edge.line, - d->top, bot, - -1); - } - - d->right = NULL; -} - - -static inline void -_cairo_bo_edge_start_or_continue (cairo_bo_edge_t *left, - cairo_bo_edge_t *right, - int top, - cairo_polygon_t *polygon) -{ - if (left->deferred.right == right) - return; - - if (left->deferred.right != NULL) { - if (right != NULL && edges_colinear (left->deferred.right, right)) - { - /* continuation on right, so just swap edges */ - left->deferred.right = right; - return; - } - - _cairo_bo_edge_end (left, top, polygon); - } - - if (right != NULL && ! edges_colinear (left, right)) { - left->deferred.top = top; - left->deferred.right = right; - } -} - -static inline void -_active_edges_to_polygon (cairo_bo_edge_t *left, - int32_t top, - cairo_fill_rule_t fill_rule, - cairo_polygon_t *polygon) -{ - cairo_bo_edge_t *right; - unsigned int mask; - - if (fill_rule == CAIRO_FILL_RULE_WINDING) - mask = ~0; - else - mask = 1; - - while (left != NULL) { - int in_out = left->edge.dir; - - right = left->next; - if (left->deferred.right == NULL) { - while (right != NULL && right->deferred.right == NULL) - right = right->next; - - if (right != NULL && edges_colinear (left, right)) { - /* continuation on left */ - left->deferred = right->deferred; - right->deferred.right = NULL; - } - } - - right = left->next; - while (right != NULL) { - if (right->deferred.right != NULL) - _cairo_bo_edge_end (right, top, polygon); - - in_out += right->edge.dir; - if ((in_out & mask) == 0) { - /* skip co-linear edges */ - if (right->next == NULL || !edges_colinear (right, right->next)) - break; - } - - right = right->next; - } - - _cairo_bo_edge_start_or_continue (left, right, top, polygon); - - left = right; - if (left != NULL) - left = left->next; - } -} - - -static cairo_status_t -_cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_event_t **start_events, - int num_events, - cairo_fill_rule_t fill_rule, - cairo_polygon_t *polygon) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; /* silence compiler */ - cairo_bo_event_queue_t event_queue; - cairo_bo_sweep_line_t sweep_line; - cairo_bo_event_t *event; - cairo_bo_edge_t *left, *right; - cairo_bo_edge_t *e1, *e2; - - _cairo_bo_event_queue_init (&event_queue, start_events, num_events); - _cairo_bo_sweep_line_init (&sweep_line); - - while ((event = _cairo_bo_event_dequeue (&event_queue))) { - if (event->point.y != sweep_line.current_y) { - _active_edges_to_polygon (sweep_line.head, - sweep_line.current_y, - fill_rule, polygon); - - sweep_line.current_y = event->point.y; - } - - switch (event->type) { - case CAIRO_BO_EVENT_TYPE_START: - e1 = &((cairo_bo_start_event_t *) event)->edge; - - status = _cairo_bo_sweep_line_insert (&sweep_line, e1); - if (unlikely (status)) - goto unwind; - - status = _cairo_bo_event_queue_insert_stop (&event_queue, e1); - if (unlikely (status)) - goto unwind; - - left = e1->prev; - right = e1->next; - - if (left != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e1); - if (unlikely (status)) - goto unwind; - } - - if (right != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); - if (unlikely (status)) - goto unwind; - } - - break; - - case CAIRO_BO_EVENT_TYPE_STOP: - e1 = ((cairo_bo_queue_event_t *) event)->e1; - _cairo_bo_event_queue_delete (&event_queue, event); - - left = e1->prev; - right = e1->next; - - _cairo_bo_sweep_line_delete (&sweep_line, e1); - - if (e1->deferred.right != NULL) - _cairo_bo_edge_end (e1, e1->edge.bottom, polygon); - - if (left != NULL && right != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, right); - if (unlikely (status)) - goto unwind; - } - - break; - - case CAIRO_BO_EVENT_TYPE_INTERSECTION: - e1 = ((cairo_bo_queue_event_t *) event)->e1; - e2 = ((cairo_bo_queue_event_t *) event)->e2; - _cairo_bo_event_queue_delete (&event_queue, event); - - /* skip this intersection if its edges are not adjacent */ - if (e2 != e1->next) - break; - - left = e1->prev; - right = e2->next; - - _cairo_bo_sweep_line_swap (&sweep_line, e1, e2); - - /* after the swap e2 is left of e1 */ - - if (left != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e2); - if (unlikely (status)) - goto unwind; - } - - if (right != NULL) { - status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); - if (unlikely (status)) - goto unwind; - } - - break; - } - } - - unwind: - _cairo_bo_event_queue_fini (&event_queue); - - return status; -} - -cairo_status_t -_cairo_polygon_reduce (cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule) -{ - cairo_status_t status; - cairo_bo_start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_start_event_t)]; - cairo_bo_start_event_t *events; - cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; - cairo_bo_event_t **event_ptrs; - int num_limits; - int num_events; - int i; - - num_events = polygon->num_edges; - if (unlikely (0 == num_events)) - return CAIRO_STATUS_SUCCESS; - - if (DEBUG_POLYGON) { - FILE *file = fopen ("reduce_in.txt", "w"); - _cairo_debug_print_polygon (file, polygon); - fclose (file); - } - - events = stack_events; - event_ptrs = stack_event_ptrs; - if (num_events > ARRAY_LENGTH (stack_events)) { - events = _cairo_malloc_ab_plus_c (num_events, - sizeof (cairo_bo_start_event_t) + - sizeof (cairo_bo_event_t *), - sizeof (cairo_bo_event_t *)); - if (unlikely (events == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - event_ptrs = (cairo_bo_event_t **) (events + num_events); - } - - for (i = 0; i < num_events; i++) { - event_ptrs[i] = (cairo_bo_event_t *) &events[i]; - - events[i].type = CAIRO_BO_EVENT_TYPE_START; - events[i].point.y = polygon->edges[i].top; - events[i].point.x = - _line_compute_intersection_x_for_y (&polygon->edges[i].line, - events[i].point.y); - - events[i].edge.edge = polygon->edges[i]; - events[i].edge.deferred.right = NULL; - events[i].edge.prev = NULL; - events[i].edge.next = NULL; - } - - num_limits = polygon->num_limits; polygon->num_limits = 0; - polygon->num_edges = 0; - - status = _cairo_bentley_ottmann_tessellate_bo_edges (event_ptrs, - num_events, - fill_rule, - polygon); - polygon->num_limits = num_limits; - - if (events != stack_events) - free (events); - - if (DEBUG_POLYGON) { - FILE *file = fopen ("reduce_out.txt", "w"); - _cairo_debug_print_polygon (file, polygon); - fclose (file); - } - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon.c deleted file mode 100644 index b0424f6e72e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-polygon.c +++ /dev/null @@ -1,608 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-boxes-private.h" -#include "cairo-contour-private.h" -#include "cairo-error-private.h" - -#define DEBUG_POLYGON 0 - -#if DEBUG_POLYGON && !NDEBUG -static void -assert_last_edge_is_valid(cairo_polygon_t *polygon, - const cairo_box_t *limit) -{ - cairo_edge_t *edge; - cairo_fixed_t x; - - edge = &polygon->edges[polygon->num_edges-1]; - - assert (edge->bottom > edge->top); - assert (edge->top >= limit->p1.y); - assert (edge->bottom <= limit->p2.y); - - x = _cairo_edge_compute_intersection_x_for_y (&edge->line.p1, - &edge->line.p2, - edge->top); - assert (x >= limit->p1.x); - assert (x <= limit->p2.x); - - x = _cairo_edge_compute_intersection_x_for_y (&edge->line.p1, - &edge->line.p2, - edge->bottom); - assert (x >= limit->p1.x); - assert (x <= limit->p2.x); -} -#else -#define assert_last_edge_is_valid(p, l) -#endif - -static void -_cairo_polygon_add_edge (cairo_polygon_t *polygon, - const cairo_point_t *p1, - const cairo_point_t *p2, - int dir); - -void -_cairo_polygon_limit (cairo_polygon_t *polygon, - const cairo_box_t *limits, - int num_limits) -{ - int n; - - polygon->limits = limits; - polygon->num_limits = num_limits; - - if (polygon->num_limits) { - polygon->limit = limits[0]; - for (n = 1; n < num_limits; n++) { - if (limits[n].p1.x < polygon->limit.p1.x) - polygon->limit.p1.x = limits[n].p1.x; - - if (limits[n].p1.y < polygon->limit.p1.y) - polygon->limit.p1.y = limits[n].p1.y; - - if (limits[n].p2.x > polygon->limit.p2.x) - polygon->limit.p2.x = limits[n].p2.x; - - if (limits[n].p2.y > polygon->limit.p2.y) - polygon->limit.p2.y = limits[n].p2.y; - } - } -} - -void -_cairo_polygon_limit_to_clip (cairo_polygon_t *polygon, - const cairo_clip_t *clip) -{ - if (clip) - _cairo_polygon_limit (polygon, clip->boxes, clip->num_boxes); - else - _cairo_polygon_limit (polygon, 0, 0); -} - -void -_cairo_polygon_init (cairo_polygon_t *polygon, - const cairo_box_t *limits, - int num_limits) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t))); - - polygon->status = CAIRO_STATUS_SUCCESS; - - polygon->num_edges = 0; - - polygon->edges = polygon->edges_embedded; - polygon->edges_size = ARRAY_LENGTH (polygon->edges_embedded); - - polygon->extents.p1.x = polygon->extents.p1.y = INT32_MAX; - polygon->extents.p2.x = polygon->extents.p2.y = INT32_MIN; - - _cairo_polygon_limit (polygon, limits, num_limits); -} - -void -_cairo_polygon_init_with_clip (cairo_polygon_t *polygon, - const cairo_clip_t *clip) -{ - if (clip) - _cairo_polygon_init (polygon, clip->boxes, clip->num_boxes); - else - _cairo_polygon_init (polygon, 0, 0); -} - -cairo_status_t -_cairo_polygon_init_boxes (cairo_polygon_t *polygon, - const cairo_boxes_t *boxes) -{ - const struct _cairo_boxes_chunk *chunk; - int i; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t))); - - polygon->status = CAIRO_STATUS_SUCCESS; - - polygon->num_edges = 0; - - polygon->edges = polygon->edges_embedded; - polygon->edges_size = ARRAY_LENGTH (polygon->edges_embedded); - if (boxes->num_boxes > ARRAY_LENGTH (polygon->edges_embedded)/2) { - polygon->edges_size = 2 * boxes->num_boxes; - polygon->edges = _cairo_malloc_ab (polygon->edges_size, - 2*sizeof(cairo_edge_t)); - if (unlikely (polygon->edges == NULL)) - return polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - polygon->extents.p1.x = polygon->extents.p1.y = INT32_MAX; - polygon->extents.p2.x = polygon->extents.p2.y = INT32_MIN; - - polygon->limits = NULL; - polygon->num_limits = 0; - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_point_t p1, p2; - - p1 = chunk->base[i].p1; - p2.x = p1.x; - p2.y = chunk->base[i].p2.y; - _cairo_polygon_add_edge (polygon, &p1, &p2, 1); - - p1 = chunk->base[i].p2; - p2.x = p1.x; - p2.y = chunk->base[i].p1.y; - _cairo_polygon_add_edge (polygon, &p1, &p2, 1); - } - } - - return polygon->status; -} - -cairo_status_t -_cairo_polygon_init_box_array (cairo_polygon_t *polygon, - cairo_box_t *boxes, - int num_boxes) -{ - int i; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t))); - - polygon->status = CAIRO_STATUS_SUCCESS; - - polygon->num_edges = 0; - - polygon->edges = polygon->edges_embedded; - polygon->edges_size = ARRAY_LENGTH (polygon->edges_embedded); - if (num_boxes > ARRAY_LENGTH (polygon->edges_embedded)/2) { - polygon->edges_size = 2 * num_boxes; - polygon->edges = _cairo_malloc_ab (polygon->edges_size, - 2*sizeof(cairo_edge_t)); - if (unlikely (polygon->edges == NULL)) - return polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - polygon->extents.p1.x = polygon->extents.p1.y = INT32_MAX; - polygon->extents.p2.x = polygon->extents.p2.y = INT32_MIN; - - polygon->limits = NULL; - polygon->num_limits = 0; - - for (i = 0; i < num_boxes; i++) { - cairo_point_t p1, p2; - - p1 = boxes[i].p1; - p2.x = p1.x; - p2.y = boxes[i].p2.y; - _cairo_polygon_add_edge (polygon, &p1, &p2, 1); - - p1 = boxes[i].p2; - p2.x = p1.x; - p2.y = boxes[i].p1.y; - _cairo_polygon_add_edge (polygon, &p1, &p2, 1); - } - - return polygon->status; -} - - -void -_cairo_polygon_fini (cairo_polygon_t *polygon) -{ - if (polygon->edges != polygon->edges_embedded) - free (polygon->edges); - - VG (VALGRIND_MAKE_MEM_NOACCESS (polygon, sizeof (cairo_polygon_t))); -} - -/* make room for at least one more edge */ -static cairo_bool_t -_cairo_polygon_grow (cairo_polygon_t *polygon) -{ - cairo_edge_t *new_edges; - int old_size = polygon->edges_size; - int new_size = 4 * old_size; - - if (CAIRO_INJECT_FAULT ()) { - polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - if (polygon->edges == polygon->edges_embedded) { - new_edges = _cairo_malloc_ab (new_size, sizeof (cairo_edge_t)); - if (new_edges != NULL) - memcpy (new_edges, polygon->edges, old_size * sizeof (cairo_edge_t)); - } else { - new_edges = _cairo_realloc_ab (polygon->edges, - new_size, sizeof (cairo_edge_t)); - } - - if (unlikely (new_edges == NULL)) { - polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - polygon->edges = new_edges; - polygon->edges_size = new_size; - - return TRUE; -} - -static void -_add_edge (cairo_polygon_t *polygon, - const cairo_point_t *p1, - const cairo_point_t *p2, - int top, int bottom, - int dir) -{ - cairo_edge_t *edge; - - assert (top < bottom); - - if (unlikely (polygon->num_edges == polygon->edges_size)) { - if (! _cairo_polygon_grow (polygon)) - return; - } - - edge = &polygon->edges[polygon->num_edges++]; - edge->line.p1 = *p1; - edge->line.p2 = *p2; - edge->top = top; - edge->bottom = bottom; - edge->dir = dir; - - if (top < polygon->extents.p1.y) - polygon->extents.p1.y = top; - if (bottom > polygon->extents.p2.y) - polygon->extents.p2.y = bottom; - - if (p1->x < polygon->extents.p1.x || p1->x > polygon->extents.p2.x) { - cairo_fixed_t x = p1->x; - if (top != p1->y) - x = _cairo_edge_compute_intersection_x_for_y (p1, p2, top); - if (x < polygon->extents.p1.x) - polygon->extents.p1.x = x; - if (x > polygon->extents.p2.x) - polygon->extents.p2.x = x; - } - - if (p2->x < polygon->extents.p1.x || p2->x > polygon->extents.p2.x) { - cairo_fixed_t x = p2->x; - if (bottom != p2->y) - x = _cairo_edge_compute_intersection_x_for_y (p1, p2, bottom); - if (x < polygon->extents.p1.x) - polygon->extents.p1.x = x; - if (x > polygon->extents.p2.x) - polygon->extents.p2.x = x; - } -} - -static void -_add_clipped_edge (cairo_polygon_t *polygon, - const cairo_point_t *p1, - const cairo_point_t *p2, - const int top, const int bottom, - const int dir) -{ - cairo_point_t bot_left, top_right; - cairo_fixed_t top_y, bot_y; - int n; - - for (n = 0; n < polygon->num_limits; n++) { - const cairo_box_t *limits = &polygon->limits[n]; - cairo_fixed_t pleft, pright; - - if (top >= limits->p2.y) - continue; - if (bottom <= limits->p1.y) - continue; - - bot_left.x = limits->p1.x; - bot_left.y = limits->p2.y; - - top_right.x = limits->p2.x; - top_right.y = limits->p1.y; - - /* The useful region */ - top_y = MAX (top, limits->p1.y); - bot_y = MIN (bottom, limits->p2.y); - - /* The projection of the edge on the horizontal axis */ - pleft = MIN (p1->x, p2->x); - pright = MAX (p1->x, p2->x); - - if (limits->p1.x <= pleft && pright <= limits->p2.x) { - /* Projection of the edge completely contained in the box: - * clip vertically by restricting top and bottom */ - - _add_edge (polygon, p1, p2, top_y, bot_y, dir); - assert_last_edge_is_valid (polygon, limits); - } else if (pright <= limits->p1.x) { - /* Projection of the edge to the left of the box: - * replace with the left side of the box (clipped top/bottom) */ - - _add_edge (polygon, &limits->p1, &bot_left, top_y, bot_y, dir); - assert_last_edge_is_valid (polygon, limits); - } else if (limits->p2.x <= pleft) { - /* Projection of the edge to the right of the box: - * replace with the right side of the box (clipped top/bottom) */ - - _add_edge (polygon, &top_right, &limits->p2, top_y, bot_y, dir); - assert_last_edge_is_valid (polygon, limits); - } else { - /* The edge and the box intersect in a generic way */ - cairo_fixed_t left_y, right_y; - cairo_bool_t top_left_to_bottom_right; - - /* - * The edge intersects the lines corresponding to the left - * and right sides of the limit box at left_y and right_y, - * but we need to add edges for the range from top_y to - * bot_y. - * - * For both intersections, there are three cases: - * - * 1) It is outside the vertical range of the limit - * box. In this case we can simply further clip the - * edge we will be emitting (i.e. restrict its - * top/bottom limits to those of the limit box). - * - * 2) It is inside the vertical range of the limit - * box. In this case, we need to add the vertical edge - * connecting the correct vertex to the intersection, - * in order to preserve the winding count. - * - * 3) It is exactly on the box. In this case, do nothing. - * - * These operations restrict the active range (stored in - * top_y/bot_y) so that the p1-p2 edge is completely - * inside the box if it is clipped to this vertical range. - */ - - top_left_to_bottom_right = (p1->x <= p2->x) == (p1->y <= p2->y); - if (top_left_to_bottom_right) { - if (pleft >= limits->p1.x) { - left_y = top_y; - } else { - left_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, - limits->p1.x); - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) - left_y++; - } - - left_y = MIN (left_y, bot_y); - if (top_y < left_y) { - _add_edge (polygon, &limits->p1, &bot_left, - top_y, left_y, dir); - assert_last_edge_is_valid (polygon, limits); - top_y = left_y; - } - - if (pright <= limits->p2.x) { - right_y = bot_y; - } else { - right_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, - limits->p2.x); - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) - right_y--; - } - - right_y = MAX (right_y, top_y); - if (bot_y > right_y) { - _add_edge (polygon, &top_right, &limits->p2, - right_y, bot_y, dir); - assert_last_edge_is_valid (polygon, limits); - bot_y = right_y; - } - } else { - if (pright <= limits->p2.x) { - right_y = top_y; - } else { - right_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, - limits->p2.x); - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) - right_y++; - } - - right_y = MIN (right_y, bot_y); - if (top_y < right_y) { - _add_edge (polygon, &top_right, &limits->p2, - top_y, right_y, dir); - assert_last_edge_is_valid (polygon, limits); - top_y = right_y; - } - - if (pleft >= limits->p1.x) { - left_y = bot_y; - } else { - left_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, - limits->p1.x); - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) - left_y--; - } - - left_y = MAX (left_y, top_y); - if (bot_y > left_y) { - _add_edge (polygon, &limits->p1, &bot_left, - left_y, bot_y, dir); - assert_last_edge_is_valid (polygon, limits); - bot_y = left_y; - } - } - - if (top_y != bot_y) { - _add_edge (polygon, p1, p2, top_y, bot_y, dir); - assert_last_edge_is_valid (polygon, limits); - } - } - } -} - -static void -_cairo_polygon_add_edge (cairo_polygon_t *polygon, - const cairo_point_t *p1, - const cairo_point_t *p2, - int dir) -{ - /* drop horizontal edges */ - if (p1->y == p2->y) - return; - - if (p1->y > p2->y) { - const cairo_point_t *t; - t = p1, p1 = p2, p2 = t; - dir = -dir; - } - - if (polygon->num_limits) { - if (p2->y <= polygon->limit.p1.y) - return; - - if (p1->y >= polygon->limit.p2.y) - return; - - _add_clipped_edge (polygon, p1, p2, p1->y, p2->y, dir); - } else - _add_edge (polygon, p1, p2, p1->y, p2->y, dir); -} - -cairo_status_t -_cairo_polygon_add_external_edge (void *polygon, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - _cairo_polygon_add_edge (polygon, p1, p2, 1); - return _cairo_polygon_status (polygon); -} - -cairo_status_t -_cairo_polygon_add_line (cairo_polygon_t *polygon, - const cairo_line_t *line, - int top, int bottom, - int dir) -{ - /* drop horizontal edges */ - if (line->p1.y == line->p2.y) - return CAIRO_STATUS_SUCCESS; - - if (bottom <= top) - return CAIRO_STATUS_SUCCESS; - - if (polygon->num_limits) { - if (line->p2.y <= polygon->limit.p1.y) - return CAIRO_STATUS_SUCCESS; - - if (line->p1.y >= polygon->limit.p2.y) - return CAIRO_STATUS_SUCCESS; - - _add_clipped_edge (polygon, &line->p1, &line->p2, top, bottom, dir); - } else - _add_edge (polygon, &line->p1, &line->p2, top, bottom, dir); - - return polygon->status; -} - -cairo_status_t -_cairo_polygon_add_contour (cairo_polygon_t *polygon, - const cairo_contour_t *contour) -{ - const struct _cairo_contour_chain *chain; - const cairo_point_t *prev = NULL; - int i; - - if (contour->chain.num_points <= 1) - return CAIRO_INT_STATUS_SUCCESS; - - prev = &contour->chain.points[0]; - for (chain = &contour->chain; chain; chain = chain->next) { - for (i = 0; i < chain->num_points; i++) { - _cairo_polygon_add_edge (polygon, prev, &chain->points[i], - contour->direction); - prev = &chain->points[i]; - } - } - - return polygon->status; -} - -void -_cairo_polygon_translate (cairo_polygon_t *polygon, int dx, int dy) -{ - int n; - - dx = _cairo_fixed_from_int (dx); - dy = _cairo_fixed_from_int (dy); - - polygon->extents.p1.x += dx; - polygon->extents.p2.x += dx; - polygon->extents.p1.y += dy; - polygon->extents.p2.y += dy; - - for (n = 0; n < polygon->num_edges; n++) { - cairo_edge_t *e = &polygon->edges[n]; - - e->top += dy; - e->bottom += dy; - - e->line.p1.x += dx; - e->line.p2.x += dx; - e->line.p1.y += dy; - e->line.p2.y += dy; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-private.h deleted file mode 100644 index 9f4f55b7cea..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-private.h +++ /dev/null @@ -1,64 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PRIVATE_H -#define CAIRO_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-reference-count-private.h" - -CAIRO_BEGIN_DECLS - -struct _cairo { - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; - - const cairo_backend_t *backend; -}; - -cairo_private cairo_t * -_cairo_create_in_error (cairo_status_t status); - -cairo_private void -_cairo_init (cairo_t *cr, - const cairo_backend_t *backend); - -cairo_private void -_cairo_fini (cairo_t *cr); - -CAIRO_END_DECLS - -#endif /* CAIRO_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface-private.h deleted file mode 100644 index 1d5d27d4910..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface-private.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Keith Packard - */ - -#ifndef CAIRO_PS_SURFACE_PRIVATE_H -#define CAIRO_PS_SURFACE_PRIVATE_H - -#include "cairo-ps.h" - -#include "cairo-surface-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-pdf-operators-private.h" - -#include - -typedef struct cairo_ps_surface { - cairo_surface_t base; - - /* Here final_stream corresponds to the stream/file passed to - * cairo_ps_surface_create surface is built. Meanwhile stream is a - * temporary stream in which the file output is built, (so that - * the header can be built and inserted into the target stream - * before the contents of the temporary stream are copied). */ - cairo_output_stream_t *final_stream; - - FILE *tmpfile; - cairo_output_stream_t *stream; - - cairo_bool_t eps; - cairo_content_t content; - double width; - double height; - cairo_rectangle_int_t page_bbox; - int bbox_x1, bbox_y1, bbox_x2, bbox_y2; - cairo_matrix_t cairo_to_ps; - - cairo_bool_t use_string_datasource; - - cairo_bool_t current_pattern_is_solid_color; - cairo_color_t current_color; - - int num_pages; - - cairo_paginated_mode_t paginated_mode; - - cairo_bool_t force_fallbacks; - cairo_bool_t has_creation_date; - time_t creation_date; - - cairo_scaled_font_subsets_t *font_subsets; - - cairo_list_t document_media; - cairo_array_t dsc_header_comments; - cairo_array_t dsc_setup_comments; - cairo_array_t dsc_page_setup_comments; - - cairo_array_t *dsc_comment_target; - - cairo_ps_level_t ps_level; - cairo_ps_level_t ps_level_used; - - cairo_surface_clipper_t clipper; - - cairo_pdf_operators_t pdf_operators; - cairo_surface_t *paginated_surface; -} cairo_ps_surface_t; - -#endif /* CAIRO_PS_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface.c deleted file mode 100644 index 03eba62db5d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps-surface.c +++ /dev/null @@ -1,4694 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * Copyright © 2005 Red Hat, Inc - * Copyright © 2007,2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Keith Packard - * Adrian Johnson - */ - - -/* - * Design of the PS output: - * - * The PS output is harmonised with the PDF operations using PS procedures - * to emulate the PDF operators. - * - * This has a number of advantages: - * 1. A large chunk of code is shared between the PDF and PS backends. - * See cairo-pdf-operators. - * 2. Using gs to do PS -> PDF and PDF -> PS will always work well. - */ - -#define _BSD_SOURCE /* for ctime_r(), snprintf(), strdup() */ -#include "cairoint.h" - -#include "cairo-ps.h" -#include "cairo-ps-surface-private.h" - -#include "cairo-pdf-operators-private.h" -#include "cairo-pdf-shading-private.h" - -#include "cairo-array-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-list-inline.h" -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-paginated-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-type3-glyph-surface-private.h" -#include "cairo-image-info-private.h" - -#include -#include -#include -#include -#include - -#define DEBUG_PS 0 - -#if DEBUG_PS -#define DEBUG_FALLBACK(s) \ - fprintf (stderr, "%s::%d -- %s\n", __FUNCTION__, __LINE__, (s)) -#else -#define DEBUG_FALLBACK(s) -#endif - -#ifndef HAVE_CTIME_R -#define ctime_r(T, BUF) ctime (T) -#endif - -/** - * SECTION:cairo-ps - * @Title: PostScript Surfaces - * @Short_Description: Rendering PostScript documents - * @See_Also: #cairo_surface_t - * - * The PostScript surface is used to render cairo graphics to Adobe - * PostScript files and is a multi-page vector surface backend. - **/ - -/** - * CAIRO_HAS_PS_SURFACE: - * - * Defined if the PostScript surface backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.2 - **/ - -typedef enum { - CAIRO_PS_COMPRESS_NONE, - CAIRO_PS_COMPRESS_LZW, - CAIRO_PS_COMPRESS_DEFLATE - } cairo_ps_compress_t; - -static const cairo_surface_backend_t cairo_ps_surface_backend; -static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend; - -static cairo_bool_t -_cairo_ps_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle); - -static const cairo_ps_level_t _cairo_ps_levels[] = -{ - CAIRO_PS_LEVEL_2, - CAIRO_PS_LEVEL_3 -}; - -#define CAIRO_PS_LEVEL_LAST ARRAY_LENGTH (_cairo_ps_levels) - -static const char * _cairo_ps_level_strings[CAIRO_PS_LEVEL_LAST] = -{ - "PS Level 2", - "PS Level 3" -}; - -static const char *_cairo_ps_supported_mime_types[] = -{ - CAIRO_MIME_TYPE_JPEG, - NULL -}; - -typedef struct _cairo_page_standard_media { - const char *name; - int width; - int height; -} cairo_page_standard_media_t; - -static const cairo_page_standard_media_t _cairo_page_standard_media[] = -{ - { "A0", 2384, 3371 }, - { "A1", 1685, 2384 }, - { "A2", 1190, 1684 }, - { "A3", 842, 1190 }, - { "A4", 595, 842 }, - { "A5", 420, 595 }, - { "B4", 729, 1032 }, - { "B5", 516, 729 }, - { "Letter", 612, 792 }, - { "Tabloid", 792, 1224 }, - { "Ledger", 1224, 792 }, - { "Legal", 612, 1008 }, - { "Statement", 396, 612 }, - { "Executive", 540, 720 }, - { "Folio", 612, 936 }, - { "Quarto", 610, 780 }, - { "10x14", 720, 1008 }, -}; - -typedef struct _cairo_page_media { - char *name; - int width; - int height; - cairo_list_t link; -} cairo_page_media_t; - -static void -_cairo_ps_surface_emit_header (cairo_ps_surface_t *surface) -{ - char ctime_buf[26]; - time_t now; - char **comments; - int i, num_comments; - int level; - const char *eps_header = ""; - cairo_bool_t has_bbox; - - if (surface->has_creation_date) - now = surface->creation_date; - else - now = time (NULL); - - if (surface->ps_level_used == CAIRO_PS_LEVEL_2) - level = 2; - else - level = 3; - - if (surface->eps) - eps_header = " EPSF-3.0"; - - _cairo_output_stream_printf (surface->final_stream, - "%%!PS-Adobe-3.0%s\n" - "%%%%Creator: cairo %s (http://cairographics.org)\n" - "%%%%CreationDate: %s" - "%%%%Pages: %d\n", - eps_header, - cairo_version_string (), - ctime_r (&now, ctime_buf), - surface->num_pages); - - _cairo_output_stream_printf (surface->final_stream, - "%%%%DocumentData: Clean7Bit\n" - "%%%%LanguageLevel: %d\n", - level); - - if (!cairo_list_is_empty (&surface->document_media)) { - cairo_page_media_t *page; - cairo_bool_t first = TRUE; - - cairo_list_foreach_entry (page, cairo_page_media_t, &surface->document_media, link) { - if (first) { - _cairo_output_stream_printf (surface->final_stream, - "%%%%DocumentMedia: "); - first = FALSE; - } else { - _cairo_output_stream_printf (surface->final_stream, - "%%%%+ "); - } - _cairo_output_stream_printf (surface->final_stream, - "%s %d %d 0 () ()\n", - page->name, - page->width, - page->height); - } - } - - has_bbox = FALSE; - num_comments = _cairo_array_num_elements (&surface->dsc_header_comments); - comments = _cairo_array_index (&surface->dsc_header_comments, 0); - for (i = 0; i < num_comments; i++) { - _cairo_output_stream_printf (surface->final_stream, - "%s\n", comments[i]); - if (strncmp (comments[i], "%%BoundingBox:", 14) == 0) - has_bbox = TRUE; - - free (comments[i]); - comments[i] = NULL; - } - - if (!has_bbox) { - _cairo_output_stream_printf (surface->final_stream, - "%%%%BoundingBox: %d %d %d %d\n", - surface->bbox_x1, - surface->bbox_y1, - surface->bbox_x2, - surface->bbox_y2); - } - - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndComments\n"); - - _cairo_output_stream_printf (surface->final_stream, - "%%%%BeginProlog\n"); - - if (surface->eps) { - _cairo_output_stream_printf (surface->final_stream, - "save\n" - "50 dict begin\n"); - } else { - _cairo_output_stream_printf (surface->final_stream, - "/languagelevel where\n" - "{ pop languagelevel } { 1 } ifelse\n" - "%d lt { /Helvetica findfont 12 scalefont setfont 50 500 moveto\n" - " (This print job requires a PostScript Language Level %d printer.) show\n" - " showpage quit } if\n", - level, - level); - } - - _cairo_output_stream_printf (surface->final_stream, - "/q { gsave } bind def\n" - "/Q { grestore } bind def\n" - "/cm { 6 array astore concat } bind def\n" - "/w { setlinewidth } bind def\n" - "/J { setlinecap } bind def\n" - "/j { setlinejoin } bind def\n" - "/M { setmiterlimit } bind def\n" - "/d { setdash } bind def\n" - "/m { moveto } bind def\n" - "/l { lineto } bind def\n" - "/c { curveto } bind def\n" - "/h { closepath } bind def\n" - "/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto\n" - " 0 exch rlineto 0 rlineto closepath } bind def\n" - "/S { stroke } bind def\n" - "/f { fill } bind def\n" - "/f* { eofill } bind def\n" - "/n { newpath } bind def\n" - "/W { clip } bind def\n" - "/W* { eoclip } bind def\n" - "/BT { } bind def\n" - "/ET { } bind def\n" - "/pdfmark where { pop globaldict /?pdfmark /exec load put }\n" - " { globaldict begin /?pdfmark /pop load def /pdfmark\n" - " /cleartomark load def end } ifelse\n" - "/BDC { mark 3 1 roll /BDC pdfmark } bind def\n" - "/EMC { mark /EMC pdfmark } bind def\n" - "/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def\n" - "/Tj { show currentpoint cairo_store_point } bind def\n" - "/TJ {\n" - " {\n" - " dup\n" - " type /stringtype eq\n" - " { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse\n" - " } forall\n" - " currentpoint cairo_store_point\n" - "} bind def\n" - "/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore\n" - " cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def\n" - "/Tf { pop /cairo_font exch def /cairo_font_matrix where\n" - " { pop cairo_selectfont } if } bind def\n" - "/Td { matrix translate cairo_font_matrix matrix concatmatrix dup\n" - " /cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point\n" - " /cairo_font where { pop cairo_selectfont } if } bind def\n" - "/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def\n" - " cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def\n" - "/g { setgray } bind def\n" - "/rg { setrgbcolor } bind def\n" - "/d1 { setcachedevice } bind def\n"); - - if (!surface->eps) { - _cairo_output_stream_printf (surface->final_stream, - "/cairo_set_page_size {\n" - " %% Change paper size, but only if different from previous paper size otherwise\n" - " %% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size\n" - " %% so we use the same when checking if the size changes.\n" - " /setpagedevice where {\n" - " pop currentpagedevice\n" - " /PageSize known {\n" - " 2 copy\n" - " currentpagedevice /PageSize get aload pop\n" - " exch 4 1 roll\n" - " sub abs 5 gt\n" - " 3 1 roll\n" - " sub abs 5 gt\n" - " or\n" - " } {\n" - " true\n" - " } ifelse\n" - " {\n" - " 2 array astore\n" - " 2 dict begin\n" - " /PageSize exch def\n" - " /ImagingBBox null def\n" - " currentdict end\n" - " setpagedevice\n" - " } {\n" - " pop pop\n" - " } ifelse\n" - " } {\n" - " pop\n" - " } ifelse\n" - "} def\n"); - } - - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndProlog\n"); - _cairo_output_stream_printf (surface->final_stream, - "%%%%BeginSetup\n"); - - num_comments = _cairo_array_num_elements (&surface->dsc_setup_comments); - if (num_comments) { - comments = _cairo_array_index (&surface->dsc_setup_comments, 0); - for (i = 0; i < num_comments; i++) { - _cairo_output_stream_printf (surface->final_stream, - "%s\n", comments[i]); - free (comments[i]); - comments[i] = NULL; - } - } -} - -static cairo_status_t -_cairo_ps_surface_emit_type1_font_subset (cairo_ps_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) - - -{ - cairo_type1_subset_t subset; - cairo_status_t status; - int length; - char name[64]; - - snprintf (name, sizeof name, "f-%d-%d", - font_subset->font_id, font_subset->subset_id); - status = _cairo_type1_subset_init (&subset, name, font_subset, TRUE); - if (unlikely (status)) - return status; - - /* FIXME: Figure out document structure convention for fonts */ - -#if DEBUG_PS - _cairo_output_stream_printf (surface->final_stream, - "%% _cairo_ps_surface_emit_type1_font_subset\n"); -#endif - - _cairo_output_stream_printf (surface->final_stream, - "%%%%BeginResource: font %s\n", - subset.base_font); - length = subset.header_length + subset.data_length + subset.trailer_length; - _cairo_output_stream_write (surface->final_stream, subset.data, length); - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndResource\n"); - - _cairo_type1_subset_fini (&subset); - - return CAIRO_STATUS_SUCCESS; -} - - -static cairo_status_t -_cairo_ps_surface_emit_type1_font_fallback (cairo_ps_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) -{ - cairo_type1_subset_t subset; - cairo_status_t status; - int length; - char name[64]; - - snprintf (name, sizeof name, "f-%d-%d", - font_subset->font_id, font_subset->subset_id); - status = _cairo_type1_fallback_init_hex (&subset, name, font_subset); - if (unlikely (status)) - return status; - -#if DEBUG_PS - _cairo_output_stream_printf (surface->final_stream, - "%% _cairo_ps_surface_emit_type1_font_fallback\n"); -#endif - - _cairo_output_stream_printf (surface->final_stream, - "%%%%BeginResource: font %s\n", - subset.base_font); - length = subset.header_length + subset.data_length + subset.trailer_length; - _cairo_output_stream_write (surface->final_stream, subset.data, length); - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndResource\n"); - - _cairo_type1_fallback_fini (&subset); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) - - -{ - cairo_truetype_subset_t subset; - cairo_status_t status; - unsigned int i, begin, end; - - status = _cairo_truetype_subset_init_ps (&subset, font_subset); - if (unlikely (status)) - return status; - - /* FIXME: Figure out document structure convention for fonts */ - -#if DEBUG_PS - _cairo_output_stream_printf (surface->final_stream, - "%% _cairo_ps_surface_emit_truetype_font_subset\n"); -#endif - - _cairo_output_stream_printf (surface->final_stream, - "%%%%BeginResource: font %s\n", - subset.ps_name); - _cairo_output_stream_printf (surface->final_stream, - "11 dict begin\n" - "/FontType 42 def\n" - "/FontName /%s def\n" - "/PaintType 0 def\n" - "/FontMatrix [ 1 0 0 1 0 0 ] def\n" - "/FontBBox [ 0 0 0 0 ] def\n" - "/Encoding 256 array def\n" - "0 1 255 { Encoding exch /.notdef put } for\n", - subset.ps_name); - - /* FIXME: Figure out how subset->x_max etc maps to the /FontBBox */ - - if (font_subset->is_latin) { - for (i = 1; i < 256; i++) { - if (font_subset->latin_to_subset_glyph_index[i] > 0) { - if (font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (surface->final_stream, - "Encoding %d /%s put\n", - i, font_subset->glyph_names[font_subset->latin_to_subset_glyph_index[i]]); - } else { - _cairo_output_stream_printf (surface->final_stream, - "Encoding %d /g%ld put\n", i, font_subset->latin_to_subset_glyph_index[i]); - } - } - } - } else { - for (i = 1; i < font_subset->num_glyphs; i++) { - if (font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (surface->final_stream, - "Encoding %d /%s put\n", - i, font_subset->glyph_names[i]); - } else { - _cairo_output_stream_printf (surface->final_stream, - "Encoding %d /g%d put\n", i, i); - } - } - } - - _cairo_output_stream_printf (surface->final_stream, - "/CharStrings %d dict dup begin\n" - "/.notdef 0 def\n", - font_subset->num_glyphs); - - for (i = 1; i < font_subset->num_glyphs; i++) { - if (font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (surface->final_stream, - "/%s %d def\n", - font_subset->glyph_names[i], i); - } else { - _cairo_output_stream_printf (surface->final_stream, - "/g%d %d def\n", i, i); - } - } - - _cairo_output_stream_printf (surface->final_stream, - "end readonly def\n"); - - _cairo_output_stream_printf (surface->final_stream, - "/sfnts [\n"); - begin = 0; - end = 0; - for (i = 0; i < subset.num_string_offsets; i++) { - end = subset.string_offsets[i]; - _cairo_output_stream_printf (surface->final_stream,"<"); - _cairo_output_stream_write_hex_string (surface->final_stream, - subset.data + begin, end - begin); - _cairo_output_stream_printf (surface->final_stream,"00>\n"); - begin = end; - } - if (subset.data_length > end) { - _cairo_output_stream_printf (surface->final_stream,"<"); - _cairo_output_stream_write_hex_string (surface->final_stream, - subset.data + end, subset.data_length - end); - _cairo_output_stream_printf (surface->final_stream,"00>\n"); - } - - _cairo_output_stream_printf (surface->final_stream, - "] def\n" - "/f-%d-%d currentdict end definefont pop\n", - font_subset->font_id, - font_subset->subset_id); - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndResource\n"); - _cairo_truetype_subset_fini (&subset); - - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_ps_emit_imagemask (cairo_image_surface_t *image, - cairo_output_stream_t *stream) -{ - uint8_t *row, *byte; - int rows, cols; - - /* The only image type supported by Type 3 fonts are 1-bit image - * masks */ - assert (image->format == CAIRO_FORMAT_A1); - - _cairo_output_stream_printf (stream, - "<<\n" - " /ImageType 1\n" - " /Width %d\n" - " /Height %d\n" - " /ImageMatrix [%d 0 0 %d 0 %d]\n" - " /Decode [1 0]\n" - " /BitsPerComponent 1\n", - image->width, - image->height, - image->width, - -image->height, - image->height); - - _cairo_output_stream_printf (stream, - " /DataSource {<\n "); - for (row = image->data, rows = image->height; rows; row += image->stride, rows--) { - for (byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) { - uint8_t output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte); - _cairo_output_stream_printf (stream, "%02x ", output_byte); - } - _cairo_output_stream_printf (stream, "\n "); - } - _cairo_output_stream_printf (stream, ">}\n>>\n"); - - _cairo_output_stream_printf (stream, - "imagemask\n"); - - return _cairo_output_stream_get_status (stream); -} - -static cairo_int_status_t -_cairo_ps_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_ps_surface_t *surface = closure; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - unsigned int i; - cairo_surface_t *type3_surface; - - type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, - NULL, - _cairo_ps_emit_imagemask, - surface->font_subsets, - TRUE); - - for (i = 0; i < font_subset->num_glyphs; i++) { - status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface, - font_subset->glyphs[i]); - if (unlikely (status)) - break; - - } - cairo_surface_finish (type3_surface); - cairo_surface_destroy (type3_surface); - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t *surface, - cairo_scaled_font_subset_t *font_subset) - - -{ - cairo_status_t status; - unsigned int i; - cairo_box_t font_bbox = {{0,0},{0,0}}; - cairo_box_t bbox = {{0,0},{0,0}}; - cairo_surface_t *type3_surface; - double width; - - if (font_subset->num_glyphs == 0) - return CAIRO_STATUS_SUCCESS; - -#if DEBUG_PS - _cairo_output_stream_printf (surface->final_stream, - "%% _cairo_ps_surface_emit_type3_font_subset\n"); -#endif - - _cairo_output_stream_printf (surface->final_stream, - "%%%%BeginResource: font\n"); - _cairo_output_stream_printf (surface->final_stream, - "8 dict begin\n" - "/FontType 3 def\n" - "/FontMatrix [1 0 0 1 0 0] def\n" - "/Encoding 256 array def\n" - "0 1 255 { Encoding exch /.notdef put } for\n"); - - type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, - NULL, - _cairo_ps_emit_imagemask, - surface->font_subsets, - TRUE); - status = type3_surface->status; - if (unlikely (status)) - return status; - - for (i = 0; i < font_subset->num_glyphs; i++) { - if (font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (surface->final_stream, - "Encoding %d /%s put\n", - i, font_subset->glyph_names[i]); - } else { - _cairo_output_stream_printf (surface->final_stream, - "Encoding %d /g%d put\n", i, i); - } - } - - _cairo_output_stream_printf (surface->final_stream, - "/Glyphs [\n"); - - for (i = 0; i < font_subset->num_glyphs; i++) { - _cairo_output_stream_printf (surface->final_stream, - " { %% %d\n", i); - status = _cairo_type3_glyph_surface_emit_glyph (type3_surface, - surface->final_stream, - font_subset->glyphs[i], - &bbox, - &width); - if (unlikely (status)) - break; - - _cairo_output_stream_printf (surface->final_stream, - " }\n"); - if (i == 0) { - font_bbox.p1.x = bbox.p1.x; - font_bbox.p1.y = bbox.p1.y; - font_bbox.p2.x = bbox.p2.x; - font_bbox.p2.y = bbox.p2.y; - } else { - if (bbox.p1.x < font_bbox.p1.x) - font_bbox.p1.x = bbox.p1.x; - if (bbox.p1.y < font_bbox.p1.y) - font_bbox.p1.y = bbox.p1.y; - if (bbox.p2.x > font_bbox.p2.x) - font_bbox.p2.x = bbox.p2.x; - if (bbox.p2.y > font_bbox.p2.y) - font_bbox.p2.y = bbox.p2.y; - } - } - cairo_surface_finish (type3_surface); - cairo_surface_destroy (type3_surface); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->final_stream, - "] def\n" - "/FontBBox [%f %f %f %f] def\n" - "/BuildChar {\n" - " exch /Glyphs get\n" - " exch get\n" - " 10 dict begin exec end\n" - "} bind def\n" - "currentdict\n" - "end\n" - "/f-%d-%d exch definefont pop\n", - _cairo_fixed_to_double (font_bbox.p1.x), - - _cairo_fixed_to_double (font_bbox.p2.y), - _cairo_fixed_to_double (font_bbox.p2.x), - - _cairo_fixed_to_double (font_bbox.p1.y), - font_subset->font_id, - font_subset->subset_id); - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndResource\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_ps_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_ps_surface_t *surface = closure; - cairo_int_status_t status; - - status = _cairo_scaled_font_subset_create_glyph_names (font_subset); - if (_cairo_int_status_is_error (status)) - return status; - - status = _cairo_ps_surface_emit_type1_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_ps_surface_emit_truetype_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_ps_surface_emit_type1_font_fallback (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - ASSERT_NOT_REACHED; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_ps_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_ps_surface_t *surface = closure; - cairo_int_status_t status; - - status = _cairo_scaled_font_subset_create_glyph_names (font_subset); - if (_cairo_int_status_is_error (status)) - return status; - - status = _cairo_ps_surface_emit_type3_font_subset (surface, font_subset); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_ps_surface_emit_font_subsets (cairo_ps_surface_t *surface) -{ - cairo_status_t status; - -#if DEBUG_PS - _cairo_output_stream_printf (surface->final_stream, - "%% _cairo_ps_surface_emit_font_subsets\n"); -#endif - - status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, - _cairo_ps_surface_analyze_user_font_subset, - surface); - if (unlikely (status)) - return status; - - status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets, - _cairo_ps_surface_emit_unscaled_font_subset, - surface); - if (unlikely (status)) - return status; - - status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets, - _cairo_ps_surface_emit_scaled_font_subset, - surface); - if (unlikely (status)) - return status; - - return _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, - _cairo_ps_surface_emit_scaled_font_subset, - surface); -} - -static cairo_status_t -_cairo_ps_surface_emit_body (cairo_ps_surface_t *surface) -{ - char buf[4096]; - int n; - - if (ferror (surface->tmpfile) != 0) - return _cairo_error (CAIRO_STATUS_TEMP_FILE_ERROR); - - rewind (surface->tmpfile); - while ((n = fread (buf, 1, sizeof (buf), surface->tmpfile)) > 0) - _cairo_output_stream_write (surface->final_stream, buf, n); - - if (ferror (surface->tmpfile) != 0) - return _cairo_error (CAIRO_STATUS_TEMP_FILE_ERROR); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_ps_surface_emit_footer (cairo_ps_surface_t *surface) -{ - _cairo_output_stream_printf (surface->final_stream, - "%%%%Trailer\n"); - - if (surface->eps) { - _cairo_output_stream_printf (surface->final_stream, - "end restore\n"); - } - - _cairo_output_stream_printf (surface->final_stream, - "%%%%EOF\n"); -} - -static cairo_bool_t -_path_covers_bbox (cairo_ps_surface_t *surface, - cairo_path_fixed_t *path) -{ - cairo_box_t box; - - if (_cairo_path_fixed_is_box (path, &box)) { - cairo_rectangle_int_t rect; - - _cairo_box_round_to_rectangle (&box, &rect); - - /* skip trivial whole-page clips */ - if (_cairo_rectangle_intersect (&rect, &surface->page_bbox)) { - if (rect.x == surface->page_bbox.x && - rect.width == surface->page_bbox.width && - rect.y == surface->page_bbox.y && - rect.height == surface->page_bbox.height) - { - return TRUE; - } - } - } - - return FALSE; -} - -static cairo_status_t -_cairo_ps_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_ps_surface_t *surface = cairo_container_of (clipper, - cairo_ps_surface_t, - clipper); - cairo_output_stream_t *stream = surface->stream; - cairo_status_t status; - - assert (surface->paginated_mode != CAIRO_PAGINATED_MODE_ANALYZE); - -#if DEBUG_PS - _cairo_output_stream_printf (stream, - "%% _cairo_ps_surface_intersect_clip_path\n"); -#endif - - if (path == NULL) { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (stream, "Q q\n"); - - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - - return CAIRO_STATUS_SUCCESS; - } - - if (_path_covers_bbox (surface, path)) - return CAIRO_STATUS_SUCCESS; - - return _cairo_pdf_operators_clip (&surface->pdf_operators, - path, - fill_rule); -} - -/* PLRM specifies a tolerance of 5 points when matching page sizes */ -static cairo_bool_t -_ps_page_dimension_equal (int a, int b) -{ - return (abs (a - b) < 5); -} - -static const char * -_cairo_ps_surface_get_page_media (cairo_ps_surface_t *surface) -{ - int width, height, i; - char buf[50]; - cairo_page_media_t *page; - const char *page_name; - - width = _cairo_lround (surface->width); - height = _cairo_lround (surface->height); - - /* search previously used page sizes */ - cairo_list_foreach_entry (page, cairo_page_media_t, &surface->document_media, link) { - if (_ps_page_dimension_equal (width, page->width) && - _ps_page_dimension_equal (height, page->height)) - return page->name; - } - - /* search list of standard page sizes */ - page_name = NULL; - for (i = 0; i < ARRAY_LENGTH (_cairo_page_standard_media); i++) { - if (_ps_page_dimension_equal (width, _cairo_page_standard_media[i].width) && - _ps_page_dimension_equal (height, _cairo_page_standard_media[i].height)) - { - page_name = _cairo_page_standard_media[i].name; - width = _cairo_page_standard_media[i].width; - height = _cairo_page_standard_media[i].height; - break; - } - } - - page = malloc (sizeof (cairo_page_media_t)); - if (unlikely (page == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - if (page_name) { - page->name = strdup (page_name); - } else { - snprintf (buf, sizeof (buf), "%dx%dmm", - (int) _cairo_lround (surface->width * 25.4/72), - (int) _cairo_lround (surface->height * 25.4/72)); - page->name = strdup (buf); - } - - if (unlikely (page->name == NULL)) { - free (page); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - page->width = width; - page->height = height; - cairo_list_add_tail (&page->link, &surface->document_media); - - return page->name; -} - -static cairo_surface_t * -_cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, - double width, - double height) -{ - cairo_status_t status, status_ignored; - cairo_ps_surface_t *surface; - - surface = malloc (sizeof (cairo_ps_surface_t)); - if (unlikely (surface == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP; - } - - _cairo_surface_init (&surface->base, - &cairo_ps_surface_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - surface->final_stream = stream; - - surface->tmpfile = tmpfile (); - if (surface->tmpfile == NULL) { - switch (errno) { - case ENOMEM: - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - break; - default: - status = _cairo_error (CAIRO_STATUS_TEMP_FILE_ERROR); - break; - } - goto CLEANUP_SURFACE; - } - - surface->stream = _cairo_output_stream_create_for_file (surface->tmpfile); - status = _cairo_output_stream_get_status (surface->stream); - if (unlikely (status)) - goto CLEANUP_OUTPUT_STREAM; - - surface->font_subsets = _cairo_scaled_font_subsets_create_simple (); - if (unlikely (surface->font_subsets == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_OUTPUT_STREAM; - } - - _cairo_scaled_font_subsets_enable_latin_subset (surface->font_subsets, TRUE); - surface->has_creation_date = FALSE; - surface->eps = FALSE; - surface->ps_level = CAIRO_PS_LEVEL_3; - surface->ps_level_used = CAIRO_PS_LEVEL_2; - surface->width = width; - surface->height = height; - cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, height); - surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE; - surface->force_fallbacks = FALSE; - surface->content = CAIRO_CONTENT_COLOR_ALPHA; - surface->use_string_datasource = FALSE; - surface->current_pattern_is_solid_color = FALSE; - - surface->page_bbox.x = 0; - surface->page_bbox.y = 0; - surface->page_bbox.width = width; - surface->page_bbox.height = height; - - _cairo_surface_clipper_init (&surface->clipper, - _cairo_ps_surface_clipper_intersect_clip_path); - - _cairo_pdf_operators_init (&surface->pdf_operators, - surface->stream, - &surface->cairo_to_ps, - surface->font_subsets, - TRUE); - surface->num_pages = 0; - - cairo_list_init (&surface->document_media); - _cairo_array_init (&surface->dsc_header_comments, sizeof (char *)); - _cairo_array_init (&surface->dsc_setup_comments, sizeof (char *)); - _cairo_array_init (&surface->dsc_page_setup_comments, sizeof (char *)); - - surface->dsc_comment_target = &surface->dsc_header_comments; - - surface->paginated_surface = _cairo_paginated_surface_create ( - &surface->base, - CAIRO_CONTENT_COLOR_ALPHA, - &cairo_ps_surface_paginated_backend); - status = surface->paginated_surface->status; - if (status == CAIRO_STATUS_SUCCESS) { - /* paginated keeps the only reference to surface now, drop ours */ - cairo_surface_destroy (&surface->base); - return surface->paginated_surface; - } - - _cairo_scaled_font_subsets_destroy (surface->font_subsets); - CLEANUP_OUTPUT_STREAM: - status_ignored = _cairo_output_stream_destroy (surface->stream); - fclose (surface->tmpfile); - CLEANUP_SURFACE: - free (surface); - CLEANUP: - /* destroy stream on behalf of caller */ - status_ignored = _cairo_output_stream_destroy (stream); - - return _cairo_surface_create_in_error (status); -} - -/** - * cairo_ps_surface_create: - * @filename: a filename for the PS output (must be writable), %NULL may be - * used to specify no output. This will generate a PS surface that - * may be queried and used as a source, without generating a - * temporary file. - * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) - * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) - * - * Creates a PostScript surface of the specified size in points to be - * written to @filename. See cairo_ps_surface_create_for_stream() for - * a more flexible mechanism for handling the PostScript output than - * simply writing it to a named file. - * - * Note that the size of individual pages of the PostScript output can - * vary. See cairo_ps_surface_set_size(). - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_ps_surface_create (const char *filename, - double width_in_points, - double height_in_points) -{ - cairo_output_stream_t *stream; - - stream = _cairo_output_stream_create_for_filename (filename); - if (_cairo_output_stream_get_status (stream)) - return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); - - return _cairo_ps_surface_create_for_stream_internal (stream, - width_in_points, - height_in_points); -} - -/** - * cairo_ps_surface_create_for_stream: - * @write_func: a #cairo_write_func_t to accept the output data, may be %NULL - * to indicate a no-op @write_func. With a no-op @write_func, - * the surface may be queried or used as a source without - * generating any temporary files. - * @closure: the closure argument for @write_func - * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) - * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) - * - * Creates a PostScript surface of the specified size in points to be - * written incrementally to the stream represented by @write_func and - * @closure. See cairo_ps_surface_create() for a more convenient way - * to simply direct the PostScript output to a named file. - * - * Note that the size of individual pages of the PostScript - * output can vary. See cairo_ps_surface_set_size(). - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, - void *closure, - double width_in_points, - double height_in_points) -{ - cairo_output_stream_t *stream; - - stream = _cairo_output_stream_create (write_func, NULL, closure); - if (_cairo_output_stream_get_status (stream)) - return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); - - return _cairo_ps_surface_create_for_stream_internal (stream, - width_in_points, - height_in_points); -} - -static cairo_bool_t -_cairo_surface_is_ps (cairo_surface_t *surface) -{ - return surface->backend == &cairo_ps_surface_backend; -} - -/* If the abstract_surface is a paginated surface, and that paginated - * surface's target is a ps_surface, then set ps_surface to that - * target. Otherwise return FALSE. - */ -static cairo_bool_t -_extract_ps_surface (cairo_surface_t *surface, - cairo_bool_t set_error_on_failure, - cairo_ps_surface_t **ps_surface) -{ - cairo_surface_t *target; - - if (surface->status) - return FALSE; - if (surface->finished) { - if (set_error_on_failure) - _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (! _cairo_surface_is_paginated (surface)) { - if (set_error_on_failure) - _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return FALSE; - } - - target = _cairo_paginated_surface_get_target (surface); - if (target->status) { - if (set_error_on_failure) - _cairo_surface_set_error (surface, target->status); - return FALSE; - } - if (target->finished) { - if (set_error_on_failure) - _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (! _cairo_surface_is_ps (target)) { - if (set_error_on_failure) - _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return FALSE; - } - - *ps_surface = (cairo_ps_surface_t *) target; - return TRUE; -} - -/** - * cairo_ps_surface_restrict_to_level: - * @surface: a PostScript #cairo_surface_t - * @level: PostScript level - * - * Restricts the generated PostSript file to @level. See - * cairo_ps_get_levels() for a list of available level values that - * can be used here. - * - * This function should only be called before any drawing operations - * have been performed on the given surface. The simplest way to do - * this is to call this function immediately after creating the - * surface. - * - * Since: 1.6 - **/ -void -cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, - cairo_ps_level_t level) -{ - cairo_ps_surface_t *ps_surface = NULL; - - if (! _extract_ps_surface (surface, TRUE, &ps_surface)) - return; - - if (level < CAIRO_PS_LEVEL_LAST) - ps_surface->ps_level = level; -} - -/** - * cairo_ps_get_levels: - * @levels: supported level list - * @num_levels: list length - * - * Used to retrieve the list of supported levels. See - * cairo_ps_surface_restrict_to_level(). - * - * Since: 1.6 - **/ -void -cairo_ps_get_levels (cairo_ps_level_t const **levels, - int *num_levels) -{ - if (levels != NULL) - *levels = _cairo_ps_levels; - - if (num_levels != NULL) - *num_levels = CAIRO_PS_LEVEL_LAST; -} - -/** - * cairo_ps_level_to_string: - * @level: a level id - * - * Get the string representation of the given @level id. This function - * will return %NULL if @level id isn't valid. See cairo_ps_get_levels() - * for a way to get the list of valid level ids. - * - * Return value: the string associated to given level. - * - * Since: 1.6 - **/ -const char * -cairo_ps_level_to_string (cairo_ps_level_t level) -{ - if (level >= CAIRO_PS_LEVEL_LAST) - return NULL; - - return _cairo_ps_level_strings[level]; -} - -/** - * cairo_ps_surface_set_eps: - * @surface: a PostScript #cairo_surface_t - * @eps: %TRUE to output EPS format PostScript - * - * If @eps is %TRUE, the PostScript surface will output Encapsulated - * PostScript. - * - * This function should only be called before any drawing operations - * have been performed on the current page. The simplest way to do - * this is to call this function immediately after creating the - * surface. An Encapsulated PostScript file should never contain more - * than one page. - * - * Since: 1.6 - **/ -void -cairo_ps_surface_set_eps (cairo_surface_t *surface, - cairo_bool_t eps) -{ - cairo_ps_surface_t *ps_surface = NULL; - - if (! _extract_ps_surface (surface, TRUE, &ps_surface)) - return; - - ps_surface->eps = eps; -} - -/** - * cairo_ps_surface_get_eps: - * @surface: a PostScript #cairo_surface_t - * - * Check whether the PostScript surface will output Encapsulated PostScript. - * - * Return value: %TRUE if the surface will output Encapsulated PostScript. - * - * Since: 1.6 - **/ -cairo_public cairo_bool_t -cairo_ps_surface_get_eps (cairo_surface_t *surface) -{ - cairo_ps_surface_t *ps_surface = NULL; - - if (! _extract_ps_surface (surface, FALSE, &ps_surface)) - return FALSE; - - return ps_surface->eps; -} - -/** - * cairo_ps_surface_set_size: - * @surface: a PostScript #cairo_surface_t - * @width_in_points: new surface width, in points (1 point == 1/72.0 inch) - * @height_in_points: new surface height, in points (1 point == 1/72.0 inch) - * - * Changes the size of a PostScript surface for the current (and - * subsequent) pages. - * - * This function should only be called before any drawing operations - * have been performed on the current page. The simplest way to do - * this is to call this function immediately after creating the - * surface or immediately after completing a page with either - * cairo_show_page() or cairo_copy_page(). - * - * Since: 1.2 - **/ -void -cairo_ps_surface_set_size (cairo_surface_t *surface, - double width_in_points, - double height_in_points) -{ - cairo_ps_surface_t *ps_surface = NULL; - cairo_status_t status; - - if (! _extract_ps_surface (surface, TRUE, &ps_surface)) - return; - - ps_surface->width = width_in_points; - ps_surface->height = height_in_points; - cairo_matrix_init (&ps_surface->cairo_to_ps, 1, 0, 0, -1, 0, height_in_points); - _cairo_pdf_operators_set_cairo_to_pdf_matrix (&ps_surface->pdf_operators, - &ps_surface->cairo_to_ps); - status = _cairo_paginated_surface_set_size (ps_surface->paginated_surface, - width_in_points, - height_in_points); - if (status) - status = _cairo_surface_set_error (surface, status); -} - -/** - * cairo_ps_surface_dsc_comment: - * @surface: a PostScript #cairo_surface_t - * @comment: a comment string to be emitted into the PostScript output - * - * Emit a comment into the PostScript output for the given surface. - * - * The comment is expected to conform to the PostScript Language - * Document Structuring Conventions (DSC). Please see that manual for - * details on the available comments and their meanings. In - * particular, the \%\%IncludeFeature comment allows a - * device-independent means of controlling printer device features. So - * the PostScript Printer Description Files Specification will also be - * a useful reference. - * - * The comment string must begin with a percent character (\%) and the - * total length of the string (including any initial percent - * characters) must not exceed 255 characters. Violating either of - * these conditions will place @surface into an error state. But - * beyond these two conditions, this function will not enforce - * conformance of the comment with any particular specification. - * - * The comment string should not have a trailing newline. - * - * The DSC specifies different sections in which particular comments - * can appear. This function provides for comments to be emitted - * within three sections: the header, the Setup section, and the - * PageSetup section. Comments appearing in the first two sections - * apply to the entire document while comments in the BeginPageSetup - * section apply only to a single page. - * - * For comments to appear in the header section, this function should - * be called after the surface is created, but before a call to - * cairo_ps_surface_dsc_begin_setup(). - * - * For comments to appear in the Setup section, this function should - * be called after a call to cairo_ps_surface_dsc_begin_setup() but - * before a call to cairo_ps_surface_dsc_begin_page_setup(). - * - * For comments to appear in the PageSetup section, this function - * should be called after a call to - * cairo_ps_surface_dsc_begin_page_setup(). - * - * Note that it is only necessary to call - * cairo_ps_surface_dsc_begin_page_setup() for the first page of any - * surface. After a call to cairo_show_page() or cairo_copy_page() - * comments are unambiguously directed to the PageSetup section of the - * current page. But it doesn't hurt to call this function at the - * beginning of every page as that consistency may make the calling - * code simpler. - * - * As a final note, cairo automatically generates several comments on - * its own. As such, applications must not manually generate any of - * the following comments: - * - * Header section: \%!PS-Adobe-3.0, \%\%Creator, \%\%CreationDate, \%\%Pages, - * \%\%BoundingBox, \%\%DocumentData, \%\%LanguageLevel, \%\%EndComments. - * - * Setup section: \%\%BeginSetup, \%\%EndSetup - * - * PageSetup section: \%\%BeginPageSetup, \%\%PageBoundingBox, \%\%EndPageSetup. - * - * Other sections: \%\%BeginProlog, \%\%EndProlog, \%\%Page, \%\%Trailer, \%\%EOF - * - * Here is an example sequence showing how this function might be used: - * - * - * cairo_surface_t *surface = cairo_ps_surface_create (filename, width, height); - * ... - * cairo_ps_surface_dsc_comment (surface, "%%Title: My excellent document"); - * cairo_ps_surface_dsc_comment (surface, "%%Copyright: Copyright (C) 2006 Cairo Lover") - * ... - * cairo_ps_surface_dsc_begin_setup (surface); - * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor White"); - * ... - * cairo_ps_surface_dsc_begin_page_setup (surface); - * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A3"); - * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *InputSlot LargeCapacity"); - * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaType Glossy"); - * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor Blue"); - * ... draw to first page here .. - * cairo_show_page (cr); - * ... - * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A5"); - * ... - * - * - * Since: 1.2 - **/ -void -cairo_ps_surface_dsc_comment (cairo_surface_t *surface, - const char *comment) -{ - cairo_ps_surface_t *ps_surface = NULL; - cairo_status_t status; - char *comment_copy; - - if (! _extract_ps_surface (surface, TRUE, &ps_surface)) - return; - - /* A couple of sanity checks on the comment value. */ - if (comment == NULL) { - status = _cairo_surface_set_error (surface, CAIRO_STATUS_NULL_POINTER); - return; - } - - if (comment[0] != '%' || strlen (comment) > 255) { - status = _cairo_surface_set_error (surface, CAIRO_STATUS_INVALID_DSC_COMMENT); - return; - } - - /* Then, copy the comment and store it in the appropriate array. */ - comment_copy = strdup (comment); - if (unlikely (comment_copy == NULL)) { - status = _cairo_surface_set_error (surface, CAIRO_STATUS_NO_MEMORY); - return; - } - - status = _cairo_array_append (ps_surface->dsc_comment_target, &comment_copy); - if (unlikely (status)) { - free (comment_copy); - status = _cairo_surface_set_error (surface, status); - return; - } -} - -/** - * cairo_ps_surface_dsc_begin_setup: - * @surface: a PostScript #cairo_surface_t - * - * This function indicates that subsequent calls to - * cairo_ps_surface_dsc_comment() should direct comments to the Setup - * section of the PostScript output. - * - * This function should be called at most once per surface, and must - * be called before any call to cairo_ps_surface_dsc_begin_page_setup() - * and before any drawing is performed to the surface. - * - * See cairo_ps_surface_dsc_comment() for more details. - * - * Since: 1.2 - **/ -void -cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface) -{ - cairo_ps_surface_t *ps_surface = NULL; - - if (! _extract_ps_surface (surface, TRUE, &ps_surface)) - return; - - if (ps_surface->dsc_comment_target == &ps_surface->dsc_header_comments) - ps_surface->dsc_comment_target = &ps_surface->dsc_setup_comments; -} - -/** - * cairo_ps_surface_dsc_begin_page_setup: - * @surface: a PostScript #cairo_surface_t - * - * This function indicates that subsequent calls to - * cairo_ps_surface_dsc_comment() should direct comments to the - * PageSetup section of the PostScript output. - * - * This function call is only needed for the first page of a - * surface. It should be called after any call to - * cairo_ps_surface_dsc_begin_setup() and before any drawing is - * performed to the surface. - * - * See cairo_ps_surface_dsc_comment() for more details. - * - * Since: 1.2 - **/ -void -cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface) -{ - cairo_ps_surface_t *ps_surface = NULL; - - if (! _extract_ps_surface (surface, TRUE, &ps_surface)) - return; - - if (ps_surface->dsc_comment_target == &ps_surface->dsc_header_comments || - ps_surface->dsc_comment_target == &ps_surface->dsc_setup_comments) - { - ps_surface->dsc_comment_target = &ps_surface->dsc_page_setup_comments; - } -} - -static cairo_status_t -_cairo_ps_surface_finish (void *abstract_surface) -{ - cairo_status_t status, status2; - cairo_ps_surface_t *surface = abstract_surface; - int i, num_comments; - char **comments; - - status = surface->base.status; - if (unlikely (status)) - goto CLEANUP; - - _cairo_ps_surface_emit_header (surface); - - status = _cairo_ps_surface_emit_font_subsets (surface); - if (unlikely (status)) - goto CLEANUP; - - _cairo_output_stream_printf (surface->final_stream, - "%%%%EndSetup\n"); - - status = _cairo_ps_surface_emit_body (surface); - if (unlikely (status)) - goto CLEANUP; - - _cairo_ps_surface_emit_footer (surface); - -CLEANUP: - _cairo_scaled_font_subsets_destroy (surface->font_subsets); - - status2 = _cairo_output_stream_destroy (surface->stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - fclose (surface->tmpfile); - - status2 = _cairo_output_stream_destroy (surface->final_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - while (! cairo_list_is_empty (&surface->document_media)) { - cairo_page_media_t *page; - - page = cairo_list_first_entry (&surface->document_media, - cairo_page_media_t, - link); - cairo_list_del (&page->link); - free (page->name); - free (page); - } - - num_comments = _cairo_array_num_elements (&surface->dsc_header_comments); - comments = _cairo_array_index (&surface->dsc_header_comments, 0); - for (i = 0; i < num_comments; i++) - free (comments[i]); - _cairo_array_fini (&surface->dsc_header_comments); - - num_comments = _cairo_array_num_elements (&surface->dsc_setup_comments); - comments = _cairo_array_index (&surface->dsc_setup_comments, 0); - for (i = 0; i < num_comments; i++) - free (comments[i]); - _cairo_array_fini (&surface->dsc_setup_comments); - - num_comments = _cairo_array_num_elements (&surface->dsc_page_setup_comments); - comments = _cairo_array_index (&surface->dsc_page_setup_comments, 0); - for (i = 0; i < num_comments; i++) - free (comments[i]); - _cairo_array_fini (&surface->dsc_page_setup_comments); - - _cairo_surface_clipper_reset (&surface->clipper); - - return status; -} - -static cairo_int_status_t -_cairo_ps_surface_start_page (void *abstract_surface) -{ - cairo_ps_surface_t *surface = abstract_surface; - - /* Increment before print so page numbers start at 1. */ - surface->num_pages++; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_ps_surface_show_page (void *abstract_surface) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - if (surface->clipper.clip != NULL) - _cairo_surface_clipper_reset (&surface->clipper); - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->stream, - "Q Q\n" - "showpage\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -color_is_gray (double red, double green, double blue) -{ - const double epsilon = 0.00001; - - return (fabs (red - green) < epsilon && - fabs (red - blue) < epsilon); -} - -/** - * _cairo_ps_surface_acquire_source_surface_from_pattern: - * @surface: the ps surface - * @pattern: A #cairo_pattern_t of type SURFACE or RASTER_SOURCE to use as the source - * @extents: extents of the operation that is using this source - * @width: returns width of surface - * @height: returns height of surface - * @x_offset: returns x offset of surface - * @y_offset: returns y offset of surface - * @surface: returns surface of type image surface or recording surface - * @image_extra: returns image extra for image type surface - * - * Acquire source surface or raster source pattern. - **/ -static cairo_status_t -_cairo_ps_surface_acquire_source_surface_from_pattern (cairo_ps_surface_t *surface, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - int *width, - int *height, - double *x_offset, - double *y_offset, - cairo_surface_t **source_surface, - void **image_extra) -{ - cairo_status_t status; - cairo_image_surface_t *image; - - *x_offset = *y_offset = 0; - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_t *surf = ((cairo_surface_pattern_t *) pattern)->surface; - - if (surf->type == CAIRO_SURFACE_TYPE_RECORDING) { - if (surf->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) surf; - - *width = sub->extents.width; - *height = sub->extents.height; - } else { - cairo_surface_t *free_me = NULL; - cairo_recording_surface_t *recording_surface; - cairo_box_t bbox; - cairo_rectangle_int_t extents; - - recording_surface = (cairo_recording_surface_t *) surf; - if (_cairo_surface_is_snapshot (&recording_surface->base)) { - free_me = _cairo_surface_snapshot_get_target (&recording_surface->base); - recording_surface = (cairo_recording_surface_t *) free_me; - } - - status = _cairo_recording_surface_get_bbox (recording_surface, &bbox, NULL); - cairo_surface_destroy (free_me); - if (unlikely (status)) - return status; - - _cairo_box_round_to_rectangle (&bbox, &extents); - *width = extents.width; - *height = extents.height; - } - *source_surface = surf; - - return CAIRO_STATUS_SUCCESS; - } else { - status = _cairo_surface_acquire_source_image (surf, &image, image_extra); - if (unlikely (status)) - return status; - } - } break; - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: { - cairo_surface_t *surf; - cairo_box_t box; - cairo_rectangle_int_t rect; - - /* get the operation extents in pattern space */ - _cairo_box_from_rectangle (&box, extents); - _cairo_matrix_transform_bounding_box_fixed (&pattern->matrix, &box, NULL); - _cairo_box_round_to_rectangle (&box, &rect); - surf = _cairo_raster_source_pattern_acquire (pattern, &surface->base, &rect); - if (!surf) - return CAIRO_INT_STATUS_UNSUPPORTED; - assert (_cairo_surface_is_image (surf)); - image = (cairo_image_surface_t *) surf; - } break; - - case CAIRO_PATTERN_TYPE_SOLID: - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - default: - ASSERT_NOT_REACHED; - break; - } - - *width = image->width; - *height = image->height; - *source_surface = &image->base; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_ps_surface_release_source_surface_from_pattern (cairo_ps_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_surface_t *source, - void *image_extra) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SURFACE: { - cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) pattern; - if (surf_pat->surface->type != CAIRO_SURFACE_TYPE_RECORDING) { - cairo_image_surface_t *image = (cairo_image_surface_t *) source; - _cairo_surface_release_source_image (surf_pat->surface, image, image_extra); - } - } break; - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - _cairo_raster_source_pattern_release (pattern, source); - break; - - case CAIRO_PATTERN_TYPE_SOLID: - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - default: - - ASSERT_NOT_REACHED; - break; - } -} - -/** - * _cairo_ps_surface_create_padded_image_from_image: - * @surface: the ps surface - * @source: The source image - * @extents: extents of the operation that is using this source - * @width: returns width of padded image - * @height: returns height of padded image - * @x_offset: returns x offset of padded image - * @y_offset: returns y offset of padded image - * @image: returns the padded image or NULL if padding not required to fill @extents - * - * Creates a padded image if the source image does not fill the extents. - **/ -static cairo_status_t -_cairo_ps_surface_create_padded_image_from_image (cairo_ps_surface_t *surface, - cairo_image_surface_t *source, - const cairo_matrix_t *source_matrix, - const cairo_rectangle_int_t *extents, - int *width, - int *height, - double *x_offset, - double *y_offset, - cairo_image_surface_t **image) -{ - cairo_box_t box; - cairo_rectangle_int_t rect; - cairo_surface_t *pad_image; - cairo_surface_pattern_t pad_pattern; - int w, h; - cairo_int_status_t status; - - /* get the operation extents in pattern space */ - _cairo_box_from_rectangle (&box, extents); - _cairo_matrix_transform_bounding_box_fixed (source_matrix, &box, NULL); - _cairo_box_round_to_rectangle (&box, &rect); - - /* Check if image needs padding to fill extents. */ - w = source->width; - h = source->height; - if (_cairo_fixed_integer_ceil(box.p1.x) < 0 || - _cairo_fixed_integer_ceil(box.p1.y) < 0 || - _cairo_fixed_integer_floor(box.p2.y) > w || - _cairo_fixed_integer_floor(box.p2.y) > h) - { - pad_image = - _cairo_image_surface_create_with_pixman_format (NULL, - source->pixman_format, - rect.width, rect.height, - 0); - if (pad_image->status) - return pad_image->status; - - _cairo_pattern_init_for_surface (&pad_pattern, &source->base); - cairo_matrix_init_translate (&pad_pattern.base.matrix, rect.x, rect.y); - pad_pattern.base.extend = CAIRO_EXTEND_PAD; - status = _cairo_surface_paint (pad_image, - CAIRO_OPERATOR_SOURCE, - &pad_pattern.base, - NULL); - _cairo_pattern_fini (&pad_pattern.base); - *image = (cairo_image_surface_t *) pad_image; - *width = rect.width; - *height = rect.height; - *x_offset = rect.x; - *y_offset = rect.y; - } else { - *image = NULL; - status = CAIRO_STATUS_SUCCESS; - } - - return status; -} - -static cairo_int_status_t -_cairo_ps_surface_analyze_surface_pattern_transparency (cairo_ps_surface_t *surface, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - int width, height; - double x_offset, y_offset; - cairo_surface_t *source; - cairo_image_surface_t *image; - void *image_extra; - cairo_int_status_t status; - cairo_image_transparency_t transparency; - - status = _cairo_ps_surface_acquire_source_surface_from_pattern (surface, - pattern, - extents, - &width, - &height, - &x_offset, - &y_offset, - &source, - &image_extra); - if (unlikely (status)) - return status; - - image = (cairo_image_surface_t *) source; - if (image->base.status) - return image->base.status; - - transparency = _cairo_image_analyze_transparency (image); - switch (transparency) { - case CAIRO_IMAGE_IS_OPAQUE: - status = CAIRO_STATUS_SUCCESS; - break; - - case CAIRO_IMAGE_HAS_BILEVEL_ALPHA: - if (surface->ps_level == CAIRO_PS_LEVEL_2) { - status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; - } else { - surface->ps_level_used = CAIRO_PS_LEVEL_3; - status = CAIRO_STATUS_SUCCESS; - } - break; - - case CAIRO_IMAGE_HAS_ALPHA: - status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; - break; - - case CAIRO_IMAGE_UNKNOWN: - ASSERT_NOT_REACHED; - } - - _cairo_ps_surface_release_source_surface_from_pattern (surface, pattern, source, image_extra); - - return status; -} - -static cairo_bool_t -surface_pattern_supported (const cairo_surface_pattern_t *pattern) -{ - if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - return TRUE; - - if (pattern->surface->backend->acquire_source_image == NULL) - return FALSE; - - /* Does an ALPHA-only source surface even make sense? Maybe, but I - * don't think it's worth the extra code to support it. */ - -/* XXX: Need to write this function here... - content = pattern->surface->content; - if (content == CAIRO_CONTENT_ALPHA) - return FALSE; -*/ - - return TRUE; -} - -static cairo_bool_t -_gradient_pattern_supported (cairo_ps_surface_t *surface, - const cairo_pattern_t *pattern) -{ - double min_alpha, max_alpha; - - if (surface->ps_level == CAIRO_PS_LEVEL_2) - return FALSE; - - /* Alpha gradients are only supported (by flattening the alpha) - * if there is no variation in the alpha across the gradient. */ - _cairo_pattern_alpha_range (pattern, &min_alpha, &max_alpha); - if (min_alpha != max_alpha) - return FALSE; - - surface->ps_level_used = CAIRO_PS_LEVEL_3; - - return TRUE; -} - -static cairo_bool_t -pattern_supported (cairo_ps_surface_t *surface, const cairo_pattern_t *pattern) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return TRUE; - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - return _gradient_pattern_supported (surface, pattern); - - case CAIRO_PATTERN_TYPE_SURFACE: - return surface_pattern_supported ((cairo_surface_pattern_t *) pattern); - - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return TRUE; - - default: - ASSERT_NOT_REACHED; - return FALSE; - } -} - -static cairo_bool_t -mask_supported (cairo_ps_surface_t *surface, - const cairo_pattern_t *mask, - const cairo_rectangle_int_t *extents) -{ - if (surface->ps_level == CAIRO_PS_LEVEL_2) - return FALSE; - - if (mask->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) mask; - if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE) { - /* check if mask if opaque or bilevel alpha */ - if (_cairo_ps_surface_analyze_surface_pattern_transparency (surface, mask, extents) == CAIRO_INT_STATUS_SUCCESS) { - surface->ps_level_used = CAIRO_PS_LEVEL_3; - return TRUE; - } - } - } - - return FALSE; -} - -static cairo_int_status_t -_cairo_ps_surface_analyze_operation (cairo_ps_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern, - const cairo_pattern_t *mask, - const cairo_rectangle_int_t *extents) -{ - double min_alpha; - - if (surface->force_fallbacks && - surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (! pattern_supported (surface, pattern)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! (op == CAIRO_OPERATOR_SOURCE || op == CAIRO_OPERATOR_OVER)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Mask is only supported when the mask is an image with opaque or bilevel alpha. */ - if (mask && !mask_supported (surface, mask, extents)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; - - if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { - if (pattern->extend == CAIRO_EXTEND_PAD) { - cairo_box_t box; - cairo_rectangle_int_t rect; - cairo_rectangle_int_t rec_extents; - - /* get the operation extents in pattern space */ - _cairo_box_from_rectangle (&box, extents); - _cairo_matrix_transform_bounding_box_fixed (&pattern->matrix, &box, NULL); - _cairo_box_round_to_rectangle (&box, &rect); - - /* Check if surface needs padding to fill extents */ - if (_cairo_surface_get_extents (surface_pattern->surface, &rec_extents)) { - if (_cairo_fixed_integer_ceil(box.p1.x) < rec_extents.x || - _cairo_fixed_integer_ceil(box.p1.y) < rec_extents.y || - _cairo_fixed_integer_floor(box.p2.y) > rec_extents.x + rec_extents.width || - _cairo_fixed_integer_floor(box.p2.y) > rec_extents.y + rec_extents.height) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - } - return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; - } - } - - if (op == CAIRO_OPERATOR_SOURCE) { - if (mask) - return CAIRO_INT_STATUS_UNSUPPORTED; - else - return CAIRO_STATUS_SUCCESS; - } - - /* CAIRO_OPERATOR_OVER is only supported for opaque patterns. If - * the pattern contains transparency, we return - * CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY to the analysis - * surface. If the analysis surface determines that there is - * anything drawn under this operation, a fallback image will be - * used. Otherwise the operation will be replayed during the - * render stage and we blend the transparency into the white - * background to convert the pattern to opaque. - */ - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE || pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return _cairo_ps_surface_analyze_surface_pattern_transparency (surface, pattern, extents); - - /* Patterns whose drawn part is opaque are directly supported; - those whose drawn part is partially transparent can be - supported by flattening the alpha. */ - _cairo_pattern_alpha_range (pattern, &min_alpha, NULL); - if (CAIRO_ALPHA_IS_OPAQUE (min_alpha)) - return CAIRO_STATUS_SUCCESS; - - return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; -} - -static cairo_bool_t -_cairo_ps_surface_operation_supported (cairo_ps_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern, - const cairo_pattern_t *mask, - const cairo_rectangle_int_t *extents) -{ - return _cairo_ps_surface_analyze_operation (surface, op, pattern, mask, extents) != CAIRO_INT_STATUS_UNSUPPORTED; -} - -/* The "standard" implementation limit for PostScript string sizes is - * 65535 characters (see PostScript Language Reference, Appendix - * B). We go one short of that because we sometimes need two - * characters in a string to represent a single ASCII85 byte, (for the - * escape sequences "\\", "\(", and "\)") and we must not split these - * across two strings. So we'd be in trouble if we went right to the - * limit and one of these escape sequences just happened to land at - * the end. - */ -#define STRING_ARRAY_MAX_STRING_SIZE (65535-1) -#define STRING_ARRAY_MAX_COLUMN 72 - -typedef struct _string_array_stream { - cairo_output_stream_t base; - cairo_output_stream_t *output; - int column; - int string_size; - cairo_bool_t use_strings; -} string_array_stream_t; - -static cairo_status_t -_string_array_stream_write (cairo_output_stream_t *base, - const unsigned char *data, - unsigned int length) -{ - string_array_stream_t *stream = (string_array_stream_t *) base; - unsigned char c; - const unsigned char backslash = '\\'; - - if (length == 0) - return CAIRO_STATUS_SUCCESS; - - while (length--) { - if (stream->string_size == 0 && stream->use_strings) { - _cairo_output_stream_printf (stream->output, "("); - stream->column++; - } - - c = *data++; - if (stream->use_strings) { - switch (c) { - case '\\': - case '(': - case ')': - _cairo_output_stream_write (stream->output, &backslash, 1); - stream->column++; - stream->string_size++; - break; - } - } - /* Have to be careful to never split the final ~> sequence. */ - if (c == '~') { - _cairo_output_stream_write (stream->output, &c, 1); - stream->column++; - stream->string_size++; - - if (length-- == 0) - break; - - c = *data++; - } - _cairo_output_stream_write (stream->output, &c, 1); - stream->column++; - stream->string_size++; - - if (stream->use_strings && - stream->string_size >= STRING_ARRAY_MAX_STRING_SIZE) - { - _cairo_output_stream_printf (stream->output, ")\n"); - stream->string_size = 0; - stream->column = 0; - } - if (stream->column >= STRING_ARRAY_MAX_COLUMN) { - _cairo_output_stream_printf (stream->output, "\n "); - stream->string_size += 2; - stream->column = 1; - } - } - - return _cairo_output_stream_get_status (stream->output); -} - -static cairo_status_t -_string_array_stream_close (cairo_output_stream_t *base) -{ - cairo_status_t status; - string_array_stream_t *stream = (string_array_stream_t *) base; - - if (stream->use_strings) - _cairo_output_stream_printf (stream->output, ")\n"); - - status = _cairo_output_stream_get_status (stream->output); - - return status; -} - -/* A string_array_stream wraps an existing output stream. It takes the - * data provided to it and output one or more consecutive string - * objects, each within the standard PostScript implementation limit - * of 65k characters. - * - * The strings are each separated by a space character for easy - * inclusion within an array object, (but the array delimiters are not - * added by the string_array_stream). - * - * The string array stream is also careful to wrap the output within - * STRING_ARRAY_MAX_COLUMN columns (+/- 1). The stream also adds - * necessary escaping for special characters within a string, - * (specifically '\', '(', and ')'). - */ -static cairo_output_stream_t * -_string_array_stream_create (cairo_output_stream_t *output) -{ - string_array_stream_t *stream; - - stream = malloc (sizeof (string_array_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - _string_array_stream_write, - NULL, - _string_array_stream_close); - stream->output = output; - stream->column = 0; - stream->string_size = 0; - stream->use_strings = TRUE; - - return &stream->base; -} - -/* A base85_array_stream wraps an existing output stream. It wraps the - * output within STRING_ARRAY_MAX_COLUMN columns (+/- 1). The output - * is not enclosed in strings like string_array_stream. - */ -static cairo_output_stream_t * -_base85_array_stream_create (cairo_output_stream_t *output) -{ - string_array_stream_t *stream; - - stream = malloc (sizeof (string_array_stream_t)); - if (unlikely (stream == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_output_stream_t *) &_cairo_output_stream_nil; - } - - _cairo_output_stream_init (&stream->base, - _string_array_stream_write, - NULL, - _string_array_stream_close); - stream->output = output; - stream->column = 0; - stream->string_size = 0; - stream->use_strings = FALSE; - - return &stream->base; -} - - -/* PS Output - this section handles output of the parts of the recording - * surface we can render natively in PS. */ - -static cairo_status_t -_cairo_ps_surface_flatten_image_transparency (cairo_ps_surface_t *surface, - cairo_image_surface_t *image, - cairo_image_surface_t **opaque_image) -{ - cairo_surface_t *opaque; - cairo_surface_pattern_t pattern; - cairo_status_t status; - - opaque = cairo_image_surface_create (CAIRO_FORMAT_RGB24, - image->width, - image->height); - if (unlikely (opaque->status)) - return opaque->status; - - if (surface->content == CAIRO_CONTENT_COLOR_ALPHA) { - status = _cairo_surface_paint (opaque, - CAIRO_OPERATOR_SOURCE, - &_cairo_pattern_white.base, - NULL); - if (unlikely (status)) { - cairo_surface_destroy (opaque); - return status; - } - } - - _cairo_pattern_init_for_surface (&pattern, &image->base); - pattern.base.filter = CAIRO_FILTER_NEAREST; - status = _cairo_surface_paint (opaque, CAIRO_OPERATOR_OVER, &pattern.base, NULL); - _cairo_pattern_fini (&pattern.base); - if (unlikely (status)) { - cairo_surface_destroy (opaque); - return status; - } - - *opaque_image = (cairo_image_surface_t *) opaque; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_ps_surface_emit_base85_string (cairo_ps_surface_t *surface, - const unsigned char *data, - unsigned long length, - cairo_ps_compress_t compress, - cairo_bool_t use_strings) -{ - cairo_output_stream_t *base85_stream, *string_array_stream, *deflate_stream; - unsigned char *data_compressed; - unsigned long data_compressed_size; - cairo_status_t status, status2; - - if (use_strings) - string_array_stream = _string_array_stream_create (surface->stream); - else - string_array_stream = _base85_array_stream_create (surface->stream); - - status = _cairo_output_stream_get_status (string_array_stream); - if (unlikely (status)) - return _cairo_output_stream_destroy (string_array_stream); - - base85_stream = _cairo_base85_stream_create (string_array_stream); - status = _cairo_output_stream_get_status (base85_stream); - if (unlikely (status)) { - status2 = _cairo_output_stream_destroy (string_array_stream); - return _cairo_output_stream_destroy (base85_stream); - } - - switch (compress) { - case CAIRO_PS_COMPRESS_NONE: - _cairo_output_stream_write (base85_stream, data, length); - break; - - case CAIRO_PS_COMPRESS_LZW: - /* XXX: Should fix cairo-lzw to provide a stream-based interface - * instead. */ - data_compressed_size = length; - data_compressed = _cairo_lzw_compress ((unsigned char*)data, &data_compressed_size); - if (unlikely (data_compressed == NULL)) { - status = _cairo_output_stream_destroy (string_array_stream); - status = _cairo_output_stream_destroy (base85_stream); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - _cairo_output_stream_write (base85_stream, data_compressed, data_compressed_size); - free (data_compressed); - break; - - case CAIRO_PS_COMPRESS_DEFLATE: - deflate_stream = _cairo_deflate_stream_create (base85_stream); - if (_cairo_output_stream_get_status (deflate_stream)) { - return _cairo_output_stream_destroy (deflate_stream); - } - _cairo_output_stream_write (deflate_stream, data, length); - status = _cairo_output_stream_destroy (deflate_stream); - if (unlikely (status)) { - status2 = _cairo_output_stream_destroy (string_array_stream); - status2 = _cairo_output_stream_destroy (base85_stream); - return _cairo_output_stream_destroy (deflate_stream); - } - break; - } - status = _cairo_output_stream_destroy (base85_stream); - - /* Mark end of base85 data */ - _cairo_output_stream_printf (string_array_stream, "~>"); - status2 = _cairo_output_stream_destroy (string_array_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_image (cairo_ps_surface_t *surface, - cairo_image_surface_t *image_surf, - cairo_operator_t op, - cairo_filter_t filter, - cairo_bool_t stencil_mask) -{ - cairo_status_t status; - unsigned char *data; - unsigned long data_size; - cairo_image_surface_t *ps_image; - int x, y, i, a; - cairo_image_transparency_t transparency; - cairo_bool_t use_mask; - uint32_t *pixel32; - uint8_t *pixel8; - int bit; - cairo_image_color_t color; - const char *interpolate; - cairo_ps_compress_t compress; - const char *compress_filter; - cairo_image_surface_t *image; - - if (image_surf->base.status) - return image_surf->base.status; - - image = image_surf; - if (image->format != CAIRO_FORMAT_RGB24 && - image->format != CAIRO_FORMAT_ARGB32 && - image->format != CAIRO_FORMAT_A8 && - image->format != CAIRO_FORMAT_A1) - { - cairo_surface_t *surf; - cairo_surface_pattern_t pattern; - - surf = _cairo_image_surface_create_with_content (image_surf->base.content, - image_surf->width, - image_surf->height); - image = (cairo_image_surface_t *) surf; - if (surf->status) { - status = surf->status; - goto bail0; - } - - _cairo_pattern_init_for_surface (&pattern, &image_surf->base); - status = _cairo_surface_paint (surf, - CAIRO_OPERATOR_SOURCE, &pattern.base, - NULL); - _cairo_pattern_fini (&pattern.base); - if (unlikely (status)) - goto bail0; - } - ps_image = image; - - switch (filter) { - default: - case CAIRO_FILTER_GOOD: - case CAIRO_FILTER_BEST: - case CAIRO_FILTER_BILINEAR: - interpolate = "true"; - break; - case CAIRO_FILTER_FAST: - case CAIRO_FILTER_NEAREST: - case CAIRO_FILTER_GAUSSIAN: - interpolate = "false"; - break; - } - - if (stencil_mask) { - use_mask = FALSE; - color = CAIRO_IMAGE_IS_MONOCHROME; - transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; - } else { - transparency = _cairo_image_analyze_transparency (image); - - /* PostScript can not represent the alpha channel, so we blend the - current image over a white (or black for CONTENT_COLOR - surfaces) RGB surface to eliminate it. */ - - if (op == CAIRO_OPERATOR_SOURCE || - transparency == CAIRO_IMAGE_HAS_ALPHA || - (transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA && - surface->ps_level == CAIRO_PS_LEVEL_2)) - { - status = _cairo_ps_surface_flatten_image_transparency (surface, - image, - &ps_image); - if (unlikely (status)) - return status; - - use_mask = FALSE; - } else if (transparency == CAIRO_IMAGE_IS_OPAQUE) { - use_mask = FALSE; - } else { /* transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA */ - use_mask = TRUE; - } - - color = _cairo_image_analyze_color (ps_image); - } - - /* Type 2 (mask and image interleaved) has the mask and image - * samples interleaved by row. The mask row is first, one bit per - * pixel with (bit 7 first). The row is padded to byte - * boundaries. The image data is 3 bytes per pixel RGB format. */ - switch (color) { - default: - case CAIRO_IMAGE_UNKNOWN_COLOR: - ASSERT_NOT_REACHED; - case CAIRO_IMAGE_IS_COLOR: - data_size = ps_image->width * 3; - break; - case CAIRO_IMAGE_IS_GRAYSCALE: - data_size = ps_image->width; - break; - case CAIRO_IMAGE_IS_MONOCHROME: - data_size = (ps_image->width + 7)/8; - break; - } - if (use_mask) - data_size += (ps_image->width + 7)/8; - data_size *= ps_image->height; - data = malloc (data_size); - if (unlikely (data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto bail1; - } - - i = 0; - for (y = 0; y < ps_image->height; y++) { - if (stencil_mask || use_mask) { - /* mask row */ - if (ps_image->format == CAIRO_FORMAT_A1) { - pixel8 = (uint8_t *) (ps_image->data + y * ps_image->stride); - - for (x = 0; x < (ps_image->width + 7) / 8; x++, pixel8++) { - a = *pixel8; - a = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (a); - data[i++] = a; - } - } else { - pixel8 = (uint8_t *) (ps_image->data + y * ps_image->stride); - pixel32 = (uint32_t *) (ps_image->data + y * ps_image->stride); - bit = 7; - for (x = 0; x < ps_image->width; x++) { - if (ps_image->format == CAIRO_FORMAT_ARGB32) { - a = (*pixel32 & 0xff000000) >> 24; - pixel32++; - } else { - a = *pixel8; - pixel8++; - } - - if (transparency == CAIRO_IMAGE_HAS_ALPHA) { - data[i++] = a; - } else { /* transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA or CAIRO_IMAGE_IS_OPAQUE */ - if (bit == 7) - data[i] = 0; - if (a != 0) - data[i] |= (1 << bit); - bit--; - if (bit < 0) { - bit = 7; - i++; - } - } - } - if (bit != 7) - i++; - } - } - if (stencil_mask) - continue; - - /* image row*/ - pixel32 = (uint32_t *) (ps_image->data + y * ps_image->stride); - bit = 7; - for (x = 0; x < ps_image->width; x++, pixel32++) { - int r, g, b; - - if (ps_image->format == CAIRO_FORMAT_ARGB32) { - /* At this point ARGB32 images are either opaque or - * bilevel alpha so we don't need to unpremultiply. */ - if (((*pixel32 & 0xff000000) >> 24) == 0) { - r = g = b = 0; - } else { - r = (*pixel32 & 0x00ff0000) >> 16; - g = (*pixel32 & 0x0000ff00) >> 8; - b = (*pixel32 & 0x000000ff) >> 0; - } - } else if (ps_image->format == CAIRO_FORMAT_RGB24) { - r = (*pixel32 & 0x00ff0000) >> 16; - g = (*pixel32 & 0x0000ff00) >> 8; - b = (*pixel32 & 0x000000ff) >> 0; - } else { - r = g = b = 0; - } - - switch (color) { - case CAIRO_IMAGE_IS_COLOR: - case CAIRO_IMAGE_UNKNOWN_COLOR: - data[i++] = r; - data[i++] = g; - data[i++] = b; - break; - - case CAIRO_IMAGE_IS_GRAYSCALE: - data[i++] = r; - break; - - case CAIRO_IMAGE_IS_MONOCHROME: - if (bit == 7) - data[i] = 0; - if (r != 0) - data[i] |= (1 << bit); - bit--; - if (bit < 0) { - bit = 7; - i++; - } - break; - } - } - if (bit != 7) - i++; - } - - if (surface->ps_level == CAIRO_PS_LEVEL_2) { - compress = CAIRO_PS_COMPRESS_LZW; - compress_filter = "LZWDecode"; - } else { - compress = CAIRO_PS_COMPRESS_DEFLATE; - compress_filter = "FlateDecode"; - surface->ps_level_used = CAIRO_PS_LEVEL_3; - } - - if (surface->use_string_datasource) { - /* Emit the image data as a base85-encoded string which will - * be used as the data source for the image operator later. */ - _cairo_output_stream_printf (surface->stream, - "/CairoImageData [\n"); - - status = _cairo_ps_surface_emit_base85_string (surface, - data, - data_size, - compress, - TRUE); - if (unlikely (status)) - goto bail2; - - _cairo_output_stream_printf (surface->stream, - "] def\n"); - _cairo_output_stream_printf (surface->stream, - "/CairoImageDataIndex 0 def\n"); - } - - if (use_mask) { - _cairo_output_stream_printf (surface->stream, - "%s setcolorspace\n" - "5 dict dup begin\n" - " /ImageType 3 def\n" - " /InterleaveType 2 def\n" - " /DataDict 8 dict def\n" - " DataDict begin\n" - " /ImageType 1 def\n" - " /Width %d def\n" - " /Height %d def\n" - " /Interpolate %s def\n" - " /BitsPerComponent %d def\n" - " /Decode [ %s ] def\n", - color == CAIRO_IMAGE_IS_COLOR ? "/DeviceRGB" : "/DeviceGray", - ps_image->width, - ps_image->height, - interpolate, - color == CAIRO_IMAGE_IS_MONOCHROME ? 1 : 8, - color == CAIRO_IMAGE_IS_COLOR ? "0 1 0 1 0 1" : "0 1"); - - if (surface->use_string_datasource) { - _cairo_output_stream_printf (surface->stream, - " /DataSource {\n" - " CairoImageData CairoImageDataIndex get\n" - " /CairoImageDataIndex CairoImageDataIndex 1 add def\n" - " CairoImageDataIndex CairoImageData length 1 sub gt\n" - " { /CairoImageDataIndex 0 def } if\n" - " } /ASCII85Decode filter /%s filter def\n", - compress_filter); - } else { - _cairo_output_stream_printf (surface->stream, - " /DataSource currentfile /ASCII85Decode filter /%s filter def\n", - compress_filter); - } - - _cairo_output_stream_printf (surface->stream, - " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" - " end\n" - " /MaskDict 8 dict def\n" - " MaskDict begin\n" - " /ImageType 1 def\n" - " /Width %d def\n" - " /Height %d def\n" - " /Interpolate %s def\n" - " /BitsPerComponent 1 def\n" - " /Decode [ 1 0 ] def\n" - " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" - " end\n" - "end\n" - "image\n", - ps_image->height, - ps_image->width, - ps_image->height, - interpolate, - ps_image->height); - } else { - if (!stencil_mask) { - _cairo_output_stream_printf (surface->stream, - "%s setcolorspace\n", - color == CAIRO_IMAGE_IS_COLOR ? "/DeviceRGB" : "/DeviceGray"); - } - _cairo_output_stream_printf (surface->stream, - "8 dict dup begin\n" - " /ImageType 1 def\n" - " /Width %d def\n" - " /Height %d def\n" - " /Interpolate %s def\n" - " /BitsPerComponent %d def\n" - " /Decode [ %s ] def\n", - ps_image->width, - ps_image->height, - interpolate, - color == CAIRO_IMAGE_IS_MONOCHROME ? 1 : 8, - stencil_mask ? "1 0" : color == CAIRO_IMAGE_IS_COLOR ? "0 1 0 1 0 1" : "0 1"); - if (surface->use_string_datasource) { - _cairo_output_stream_printf (surface->stream, - " /DataSource {\n" - " CairoImageData CairoImageDataIndex get\n" - " /CairoImageDataIndex CairoImageDataIndex 1 add def\n" - " CairoImageDataIndex CairoImageData length 1 sub gt\n" - " { /CairoImageDataIndex 0 def } if\n" - " } /ASCII85Decode filter /%s filter def\n", - compress_filter); - } else { - _cairo_output_stream_printf (surface->stream, - " /DataSource currentfile /ASCII85Decode filter /%s filter def\n", - compress_filter); - } - - _cairo_output_stream_printf (surface->stream, - " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" - "end\n" - "%s\n", - ps_image->height, - stencil_mask ? "imagemask" : "image"); - } - - if (!surface->use_string_datasource) { - /* Emit the image data as a base85-encoded string which will - * be used as the data source for the image operator. */ - status = _cairo_ps_surface_emit_base85_string (surface, - data, - data_size, - compress, - FALSE); - _cairo_output_stream_printf (surface->stream, "\n"); - } else { - status = CAIRO_STATUS_SUCCESS; - } - -bail2: - free (data); - -bail1: - if (!use_mask && ps_image != image) - cairo_surface_destroy (&ps_image->base); - -bail0: - if (image != image_surf) - cairo_surface_destroy (&image->base); - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_jpeg_image (cairo_ps_surface_t *surface, - cairo_surface_t *source, - int width, - int height) -{ - cairo_status_t status; - const unsigned char *mime_data; - unsigned long mime_data_length; - cairo_image_info_t info; - const char *colorspace; - const char *decode; - - cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG, - &mime_data, &mime_data_length); - if (unlikely (source->status)) - return source->status; - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_image_info_get_jpeg_info (&info, mime_data, mime_data_length); - if (unlikely (status)) - return status; - - switch (info.num_components) { - case 1: - colorspace = "/DeviceGray"; - decode = "0 1"; - break; - case 3: - colorspace = "/DeviceRGB"; - decode = "0 1 0 1 0 1"; - break; - case 4: - colorspace = "/DeviceCMYK"; - decode = "0 1 0 1 0 1 0 1"; - break; - default: - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (surface->use_string_datasource) { - /* Emit the image data as a base85-encoded string which will - * be used as the data source for the image operator later. */ - _cairo_output_stream_printf (surface->stream, - "/CairoImageData [\n"); - - status = _cairo_ps_surface_emit_base85_string (surface, - mime_data, - mime_data_length, - CAIRO_PS_COMPRESS_NONE, - TRUE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->stream, - "] def\n"); - _cairo_output_stream_printf (surface->stream, - "/CairoImageDataIndex 0 def\n"); - } - - _cairo_output_stream_printf (surface->stream, - "%s setcolorspace\n" - "8 dict dup begin\n" - " /ImageType 1 def\n" - " /Width %d def\n" - " /Height %d def\n" - " /BitsPerComponent %d def\n" - " /Decode [ %s ] def\n", - colorspace, - info.width, - info.height, - info.bits_per_component, - decode); - - if (surface->use_string_datasource) { - _cairo_output_stream_printf (surface->stream, - " /DataSource {\n" - " CairoImageData CairoImageDataIndex get\n" - " /CairoImageDataIndex CairoImageDataIndex 1 add def\n" - " CairoImageDataIndex CairoImageData length 1 sub gt\n" - " { /CairoImageDataIndex 0 def } if\n" - " } /ASCII85Decode filter /DCTDecode filter def\n"); - } else { - _cairo_output_stream_printf (surface->stream, - " /DataSource currentfile /ASCII85Decode filter /DCTDecode filter def\n"); - } - - _cairo_output_stream_printf (surface->stream, - " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" - "end\n" - "image\n", - info.height); - - if (!surface->use_string_datasource) { - /* Emit the image data as a base85-encoded string which will - * be used as the data source for the image operator. */ - status = _cairo_ps_surface_emit_base85_string (surface, - mime_data, - mime_data_length, - CAIRO_PS_COMPRESS_NONE, - FALSE); - } - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_recording_surface (cairo_ps_surface_t *surface, - cairo_surface_t *recording_surface) -{ - double old_width, old_height; - cairo_matrix_t old_cairo_to_ps; - cairo_content_t old_content; - cairo_rectangle_int_t old_page_bbox; - cairo_surface_t *free_me = NULL; - cairo_surface_clipper_t old_clipper; - cairo_box_t bbox; - cairo_int_status_t status; - - old_content = surface->content; - old_width = surface->width; - old_height = surface->height; - old_page_bbox = surface->page_bbox; - old_cairo_to_ps = surface->cairo_to_ps; - old_clipper = surface->clipper; - _cairo_surface_clipper_init (&surface->clipper, - _cairo_ps_surface_clipper_intersect_clip_path); - - if (_cairo_surface_is_snapshot (recording_surface)) - free_me = recording_surface = _cairo_surface_snapshot_get_target (recording_surface); - - status = - _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface, - &bbox, - NULL); - if (unlikely (status)) - goto err; - -#if DEBUG_PS - _cairo_output_stream_printf (surface->stream, - "%% _cairo_ps_surface_emit_recording_surface (%f, %f), (%f, %f)\n", - _cairo_fixed_to_double (bbox.p1.x), - _cairo_fixed_to_double (bbox.p1.y), - _cairo_fixed_to_double (bbox.p2.x), - _cairo_fixed_to_double (bbox.p2.y)); -#endif - - surface->width = _cairo_fixed_to_double (bbox.p2.x - bbox.p1.x); - surface->height = _cairo_fixed_to_double (bbox.p2.y - bbox.p1.y); - _cairo_box_round_to_rectangle (&bbox, &surface->page_bbox); - - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, surface->height); - _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, - &surface->cairo_to_ps); - _cairo_output_stream_printf (surface->stream, " q\n"); - - if (recording_surface->content == CAIRO_CONTENT_COLOR) { - surface->content = CAIRO_CONTENT_COLOR; - _cairo_output_stream_printf (surface->stream, - " 0 g %d %d %d %d rectfill\n", - surface->page_bbox.x, - surface->page_bbox.y, - surface->page_bbox.width, - surface->page_bbox.height); - } - - status = _cairo_recording_surface_replay_region (recording_surface, - NULL, - &surface->base, - CAIRO_RECORDING_REGION_NATIVE); - assert (status != CAIRO_INT_STATUS_UNSUPPORTED); - if (unlikely (status)) - goto err; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto err; - - _cairo_output_stream_printf (surface->stream, " Q\n"); - - _cairo_surface_clipper_reset (&surface->clipper); - surface->clipper = old_clipper; - surface->content = old_content; - surface->width = old_width; - surface->height = old_height; - surface->page_bbox = old_page_bbox; - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - surface->cairo_to_ps = old_cairo_to_ps; - - _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, - &surface->cairo_to_ps); - -err: - cairo_surface_destroy (free_me); - return status; -} - -static cairo_int_status_t -_cairo_ps_surface_emit_recording_subsurface (cairo_ps_surface_t *surface, - cairo_surface_t *recording_surface, - const cairo_rectangle_int_t *extents) -{ - double old_width, old_height; - cairo_matrix_t old_cairo_to_ps; - cairo_content_t old_content; - cairo_rectangle_int_t old_page_bbox; - cairo_surface_clipper_t old_clipper; - cairo_surface_t *free_me = NULL; - cairo_int_status_t status; - - old_content = surface->content; - old_width = surface->width; - old_height = surface->height; - old_page_bbox = surface->page_bbox; - old_cairo_to_ps = surface->cairo_to_ps; - old_clipper = surface->clipper; - _cairo_surface_clipper_init (&surface->clipper, - _cairo_ps_surface_clipper_intersect_clip_path); - -#if DEBUG_PS - _cairo_output_stream_printf (surface->stream, - "%% _cairo_ps_surface_emit_recording_subsurface (%d, %d), (%d, %d)\n", - extents->x, extents->y, - extents->width, extents->height); -#endif - - surface->page_bbox.x = surface->page_bbox.y = 0; - surface->page_bbox.width = surface->width = extents->width; - surface->page_bbox.height = surface->height = extents->height; - - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, surface->height); - _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, - &surface->cairo_to_ps); - _cairo_output_stream_printf (surface->stream, " q\n"); - - if (_cairo_surface_is_snapshot (recording_surface)) - free_me = recording_surface = _cairo_surface_snapshot_get_target (recording_surface); - - if (recording_surface->content == CAIRO_CONTENT_COLOR) { - surface->content = CAIRO_CONTENT_COLOR; - _cairo_output_stream_printf (surface->stream, - " 0 g %d %d %d %d rectfill\n", - surface->page_bbox.x, - surface->page_bbox.y, - surface->page_bbox.width, - surface->page_bbox.height); - } - - status = _cairo_recording_surface_replay_region (recording_surface, - extents, - &surface->base, - CAIRO_RECORDING_REGION_NATIVE); - assert (status != CAIRO_INT_STATUS_UNSUPPORTED); - if (unlikely (status)) - goto err; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto err; - - _cairo_output_stream_printf (surface->stream, " Q\n"); - - _cairo_surface_clipper_reset (&surface->clipper); - surface->clipper = old_clipper; - surface->content = old_content; - surface->width = old_width; - surface->height = old_height; - surface->page_bbox = old_page_bbox; - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - surface->cairo_to_ps = old_cairo_to_ps; - - _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, - &surface->cairo_to_ps); - -err: - cairo_surface_destroy (free_me); - return status; -} - -static void -_cairo_ps_surface_flatten_transparency (cairo_ps_surface_t *surface, - const cairo_color_t *color, - double *red, - double *green, - double *blue) -{ - *red = color->red; - *green = color->green; - *blue = color->blue; - - if (! CAIRO_COLOR_IS_OPAQUE (color)) { - *red *= color->alpha; - *green *= color->alpha; - *blue *= color->alpha; - if (surface->content == CAIRO_CONTENT_COLOR_ALPHA) { - double one_minus_alpha = 1. - color->alpha; - *red += one_minus_alpha; - *green += one_minus_alpha; - *blue += one_minus_alpha; - } - } -} - -static void -_cairo_ps_surface_emit_solid_pattern (cairo_ps_surface_t *surface, - cairo_solid_pattern_t *pattern) -{ - double red, green, blue; - - _cairo_ps_surface_flatten_transparency (surface, &pattern->color, &red, &green, &blue); - - if (color_is_gray (red, green, blue)) - _cairo_output_stream_printf (surface->stream, - "%f g\n", - red); - else - _cairo_output_stream_printf (surface->stream, - "%f %f %f rg\n", - red, green, blue); -} - -static cairo_status_t -_cairo_ps_surface_emit_surface (cairo_ps_surface_t *surface, - cairo_pattern_t *source_pattern, - cairo_surface_t *source_surface, - cairo_operator_t op, - int width, - int height, - cairo_bool_t stencil_mask) -{ - cairo_int_status_t status; - - if (source_pattern->type == CAIRO_PATTERN_TYPE_SURFACE && - source_pattern->extend != CAIRO_EXTEND_PAD) - { - cairo_surface_t *surf = ((cairo_surface_pattern_t *) source_pattern)->surface; - - status = _cairo_ps_surface_emit_jpeg_image (surface, surf, width, height); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - if (source_surface->type == CAIRO_SURFACE_TYPE_RECORDING) { - if (source_surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source_surface; - status = _cairo_ps_surface_emit_recording_subsurface (surface, sub->target, &sub->extents); - } else { - status = _cairo_ps_surface_emit_recording_surface (surface, source_surface); - } - } else { - cairo_image_surface_t *image = (cairo_image_surface_t *) source_surface; - - status = _cairo_ps_surface_emit_image (surface, image, - op, source_pattern->filter, stencil_mask); - } - - return status; -} - - -static void -_path_fixed_init_rectangle (cairo_path_fixed_t *path, - cairo_rectangle_int_t *rect) -{ - cairo_status_t status; - - _cairo_path_fixed_init (path); - - status = _cairo_path_fixed_move_to (path, - _cairo_fixed_from_int (rect->x), - _cairo_fixed_from_int (rect->y)); - assert (status == CAIRO_STATUS_SUCCESS); - status = _cairo_path_fixed_rel_line_to (path, - _cairo_fixed_from_int (rect->width), - _cairo_fixed_from_int (0)); - assert (status == CAIRO_STATUS_SUCCESS); - status = _cairo_path_fixed_rel_line_to (path, - _cairo_fixed_from_int (0), - _cairo_fixed_from_int (rect->height)); - assert (status == CAIRO_STATUS_SUCCESS); - status = _cairo_path_fixed_rel_line_to (path, - _cairo_fixed_from_int (-rect->width), - _cairo_fixed_from_int (0)); - assert (status == CAIRO_STATUS_SUCCESS); - - status = _cairo_path_fixed_close_path (path); - assert (status == CAIRO_STATUS_SUCCESS); -} - -static cairo_status_t -_cairo_ps_surface_paint_surface (cairo_ps_surface_t *surface, - cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents, - cairo_operator_t op, - cairo_bool_t stencil_mask) -{ - cairo_status_t status; - int width, height; - cairo_matrix_t cairo_p2d, ps_p2d; - cairo_path_fixed_t path; - double x_offset, y_offset; - cairo_surface_t *source; - cairo_image_surface_t *image = NULL; - void *image_extra; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - status = _cairo_ps_surface_acquire_source_surface_from_pattern (surface, - pattern, - extents, - &width, &height, - &x_offset, &y_offset, - &source, - &image_extra); - if (unlikely (status)) - return status; - - if (pattern->extend == CAIRO_EXTEND_PAD && - pattern->type == CAIRO_PATTERN_TYPE_SURFACE && - ((cairo_surface_pattern_t *)pattern)->surface->type == CAIRO_SURFACE_TYPE_IMAGE) { - cairo_image_surface_t *img; - - img = (cairo_image_surface_t *) source; - status = _cairo_ps_surface_create_padded_image_from_image (surface, - img, - &pattern->matrix, - extents, - &width, &height, - &x_offset, &y_offset, - &image); - if (unlikely (status)) - goto release_source; - } - - _path_fixed_init_rectangle (&path, extents); - status = _cairo_pdf_operators_clip (&surface->pdf_operators, - &path, - CAIRO_FILL_RULE_WINDING); - _cairo_path_fixed_fini (&path); - if (unlikely (status)) - goto release_source; - - cairo_p2d = pattern->matrix; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { - double x_scale = cairo_p2d.xx; - double y_scale = cairo_p2d.yy; - - _cairo_output_stream_printf (surface->stream, - "%% Fallback Image: x=%f y=%f w=%d h=%d ", - -cairo_p2d.x0/x_scale, - -cairo_p2d.y0/y_scale, - (int)(width/x_scale), - (int)(height/y_scale)); - if (x_scale == y_scale) { - _cairo_output_stream_printf (surface->stream, - "res=%fppi ", - x_scale*72); - } else { - _cairo_output_stream_printf (surface->stream, - "res=%fx%fppi ", - x_scale*72, - y_scale*72); - } - _cairo_output_stream_printf (surface->stream, - "size=%ld\n", - (long)width*height*3); - } else { - if (op == CAIRO_OPERATOR_SOURCE) { - _cairo_output_stream_printf (surface->stream, - "%d g 0 0 %f %f rectfill\n", - surface->content == CAIRO_CONTENT_COLOR ? 0 : 1, - surface->width, - surface->height); - } - } - - status = cairo_matrix_invert (&cairo_p2d); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - ps_p2d = surface->cairo_to_ps; - cairo_matrix_multiply (&ps_p2d, &cairo_p2d, &ps_p2d); - cairo_matrix_translate (&ps_p2d, x_offset, y_offset); - cairo_matrix_translate (&ps_p2d, 0.0, height); - cairo_matrix_scale (&ps_p2d, 1.0, -1.0); - - if (! _cairo_matrix_is_identity (&ps_p2d)) { - _cairo_output_stream_printf (surface->stream, "[ "); - _cairo_output_stream_print_matrix (surface->stream, &ps_p2d); - _cairo_output_stream_printf (surface->stream, " ] concat\n"); - } - - status = _cairo_ps_surface_emit_surface (surface, - pattern, - image ? &image->base : source, - op, - width, height, - stencil_mask); - - release_source: - if (image) - cairo_surface_destroy (&image->base); - - _cairo_ps_surface_release_source_surface_from_pattern (surface, pattern, source, image_extra); - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t *surface, - cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents, - cairo_operator_t op) -{ - cairo_status_t status; - int pattern_width = 0; /* squelch bogus compiler warning */ - int pattern_height = 0; /* squelch bogus compiler warning */ - double xstep, ystep; - cairo_matrix_t cairo_p2d, ps_p2d; - cairo_bool_t old_use_string_datasource; - double x_offset, y_offset; - cairo_surface_t *source; - cairo_image_surface_t *image = NULL; - void *image_extra; - - cairo_p2d = pattern->matrix; - status = cairo_matrix_invert (&cairo_p2d); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - status = _cairo_ps_surface_acquire_source_surface_from_pattern (surface, - pattern, - extents, - &pattern_width, &pattern_height, - &x_offset, &y_offset, - &source, - &image_extra); - if (unlikely (status)) - return status; - - if (pattern->extend == CAIRO_EXTEND_PAD) { - cairo_image_surface_t *img; - - assert (source->type == CAIRO_SURFACE_TYPE_IMAGE); - img = (cairo_image_surface_t *) source; - status = _cairo_ps_surface_create_padded_image_from_image (surface, - img, - &pattern->matrix, - extents, - &pattern_width, &pattern_height, - &x_offset, &y_offset, - &image); - if (unlikely (status)) - goto release_source; - } - if (unlikely (status)) - goto release_source; - - switch (pattern->extend) { - case CAIRO_EXTEND_PAD: - case CAIRO_EXTEND_NONE: - { - /* In PS/PDF, (as far as I can tell), all patterns are - * repeating. So we support cairo's EXTEND_NONE semantics - * by setting the repeat step size to a size large enough - * to guarantee that no more than a single occurrence will - * be visible. - * - * First, map the surface extents into pattern space (since - * xstep and ystep are in pattern space). Then use an upper - * bound on the length of the diagonal of the pattern image - * and the surface as repeat size. This guarantees to never - * repeat visibly. - */ - double x1 = 0.0, y1 = 0.0; - double x2 = surface->width, y2 = surface->height; - _cairo_matrix_transform_bounding_box (&pattern->matrix, - &x1, &y1, &x2, &y2, - NULL); - - /* Rather than computing precise bounds of the union, just - * add the surface extents unconditionally. We only - * required an answer that's large enough, we don't really - * care if it's not as tight as possible.*/ - xstep = ystep = ceil ((x2 - x1) + (y2 - y1) + - pattern_width + pattern_height); - break; - } - case CAIRO_EXTEND_REPEAT: - xstep = pattern_width; - ystep = pattern_height; - break; - case CAIRO_EXTEND_REFLECT: - xstep = pattern_width*2; - ystep = pattern_height*2; - break; - /* All the rest (if any) should have been analyzed away, so these - * cases should be unreachable. */ - default: - ASSERT_NOT_REACHED; - xstep = 0; - ystep = 0; - } - - _cairo_output_stream_printf (surface->stream, - "/CairoPattern {\n"); - - old_use_string_datasource = surface->use_string_datasource; - surface->use_string_datasource = TRUE; - if (op == CAIRO_OPERATOR_SOURCE) { - _cairo_output_stream_printf (surface->stream, - "%d g 0 0 %f %f rectfill\n", - surface->content == CAIRO_CONTENT_COLOR ? 0 : 1, - xstep, ystep); - } - status = _cairo_ps_surface_emit_surface (surface, - pattern, - image ? &image->base : source, - op, - pattern_width, pattern_height, FALSE); - if (unlikely (status)) - goto release_source; - - surface->use_string_datasource = old_use_string_datasource; - _cairo_output_stream_printf (surface->stream, - "} bind def\n"); - - _cairo_output_stream_printf (surface->stream, - "<< /PatternType 1\n" - " /PaintType 1\n" - " /TilingType 1\n"); - _cairo_output_stream_printf (surface->stream, - " /XStep %f /YStep %f\n", - xstep, ystep); - - if (pattern->extend == CAIRO_EXTEND_REFLECT) { - _cairo_output_stream_printf (surface->stream, - " /BBox [0 0 %d %d]\n" - " /PaintProc {\n" - " pop CairoPattern\n" - " [-1 0 0 1 %d 0] concat CairoPattern\n" - " [ 1 0 0 -1 0 %d] concat CairoPattern\n" - " [-1 0 0 1 %d 0] concat CairoPattern\n" - " CairoPattern\n" - " } bind\n", - pattern_width*2, pattern_height*2, - pattern_width*2, - pattern_height*2, - pattern_width*2); - } else { - if (op == CAIRO_OPERATOR_SOURCE) { - _cairo_output_stream_printf (surface->stream, - " /BBox [0 0 %f %f]\n", - xstep, ystep); - } else { - _cairo_output_stream_printf (surface->stream, - " /BBox [0 0 %d %d]\n", - pattern_width, pattern_height); - } - _cairo_output_stream_printf (surface->stream, - " /PaintProc { pop CairoPattern }\n"); - } - - _cairo_output_stream_printf (surface->stream, - ">>\n"); - - cairo_p2d = pattern->matrix; - status = cairo_matrix_invert (&cairo_p2d); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - cairo_matrix_init_identity (&ps_p2d); - cairo_matrix_translate (&ps_p2d, 0.0, surface->height); - cairo_matrix_scale (&ps_p2d, 1.0, -1.0); - cairo_matrix_multiply (&ps_p2d, &cairo_p2d, &ps_p2d); - cairo_matrix_translate (&ps_p2d, 0.0, pattern_height); - cairo_matrix_scale (&ps_p2d, 1.0, -1.0); - - _cairo_output_stream_printf (surface->stream, "[ "); - _cairo_output_stream_print_matrix (surface->stream, &ps_p2d); - _cairo_output_stream_printf (surface->stream, - " ]\n" - "makepattern setpattern\n"); - - release_source: - if (image) - cairo_surface_destroy (&image->base); - - _cairo_ps_surface_release_source_surface_from_pattern (surface, pattern, source, image_extra); - - return status; -} - -typedef struct _cairo_ps_color_stop { - double offset; - double color[4]; -} cairo_ps_color_stop_t; - -static void -_cairo_ps_surface_emit_linear_colorgradient (cairo_ps_surface_t *surface, - cairo_ps_color_stop_t *stop1, - cairo_ps_color_stop_t *stop2) -{ - _cairo_output_stream_printf (surface->stream, - " << /FunctionType 2\n" - " /Domain [ 0 1 ]\n" - " /C0 [ %f %f %f ]\n" - " /C1 [ %f %f %f ]\n" - " /N 1\n" - " >>\n", - stop1->color[0], - stop1->color[1], - stop1->color[2], - stop2->color[0], - stop2->color[1], - stop2->color[2]); -} - -static void -_cairo_ps_surface_emit_stitched_colorgradient (cairo_ps_surface_t *surface, - unsigned int n_stops, - cairo_ps_color_stop_t stops[]) -{ - unsigned int i; - - _cairo_output_stream_printf (surface->stream, - "<< /FunctionType 3\n" - " /Domain [ 0 1 ]\n" - " /Functions [\n"); - for (i = 0; i < n_stops - 1; i++) - _cairo_ps_surface_emit_linear_colorgradient (surface, &stops[i], &stops[i+1]); - - _cairo_output_stream_printf (surface->stream, " ]\n"); - - _cairo_output_stream_printf (surface->stream, " /Bounds [ "); - for (i = 1; i < n_stops-1; i++) - _cairo_output_stream_printf (surface->stream, "%f ", stops[i].offset); - _cairo_output_stream_printf (surface->stream, "]\n"); - - _cairo_output_stream_printf (surface->stream, " /Encode [ 1 1 %d { pop 0 1 } for ]\n", - n_stops - 1); - - _cairo_output_stream_printf (surface->stream, ">>\n"); -} - -static void -calc_gradient_color (cairo_ps_color_stop_t *new_stop, - cairo_ps_color_stop_t *stop1, - cairo_ps_color_stop_t *stop2) -{ - int i; - double offset = stop1->offset / (stop1->offset + 1.0 - stop2->offset); - - for (i = 0; i < 4; i++) - new_stop->color[i] = stop1->color[i] + offset*(stop2->color[i] - stop1->color[i]); -} - -#define COLOR_STOP_EPSILON 1e-6 - -static cairo_status_t -_cairo_ps_surface_emit_pattern_stops (cairo_ps_surface_t *surface, - cairo_gradient_pattern_t *pattern) -{ - cairo_ps_color_stop_t *allstops, *stops; - unsigned int i, n_stops; - - allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_ps_color_stop_t)); - if (unlikely (allstops == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - stops = &allstops[1]; - n_stops = pattern->n_stops; - - for (i = 0; i < n_stops; i++) { - cairo_gradient_stop_t *stop = &pattern->stops[i]; - - stops[i].color[0] = stop->color.red; - stops[i].color[1] = stop->color.green; - stops[i].color[2] = stop->color.blue; - stops[i].color[3] = stop->color.alpha; - stops[i].offset = pattern->stops[i].offset; - } - - if (pattern->base.extend == CAIRO_EXTEND_REPEAT || - pattern->base.extend == CAIRO_EXTEND_REFLECT) - { - if (stops[0].offset > COLOR_STOP_EPSILON) { - if (pattern->base.extend == CAIRO_EXTEND_REFLECT) - memcpy (allstops, stops, sizeof (cairo_ps_color_stop_t)); - else - calc_gradient_color (&allstops[0], &stops[0], &stops[n_stops-1]); - stops = allstops; - n_stops++; - } - stops[0].offset = 0.0; - - if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) { - if (pattern->base.extend == CAIRO_EXTEND_REFLECT) { - memcpy (&stops[n_stops], - &stops[n_stops - 1], - sizeof (cairo_ps_color_stop_t)); - } else { - calc_gradient_color (&stops[n_stops], &stops[0], &stops[n_stops-1]); - } - n_stops++; - } - stops[n_stops-1].offset = 1.0; - } - - for (i = 0; i < n_stops; i++) { - double red, green, blue; - cairo_color_t color; - - _cairo_color_init_rgba (&color, - stops[i].color[0], - stops[i].color[1], - stops[i].color[2], - stops[i].color[3]); - _cairo_ps_surface_flatten_transparency (surface, &color, - &red, &green, &blue); - stops[i].color[0] = red; - stops[i].color[1] = green; - stops[i].color[2] = blue; - } - - _cairo_output_stream_printf (surface->stream, - "/CairoFunction\n"); - if (stops[0].offset == stops[n_stops - 1].offset) { - /* - * The first and the last stops have the same offset, but we - * don't want a function with an empty domain, because that - * would provoke underdefined behaviour from rasterisers. - * This can only happen with EXTEND_PAD, because EXTEND_NONE - * is optimised into a clear pattern in cairo-gstate, and - * REFLECT/REPEAT are always transformed to have the first - * stop at t=0 and the last stop at t=1. Thus we want a step - * function going from the first color to the last one. - * - * This can be accomplished by stitching three functions: - * - a constant first color function, - * - a step from the first color to the last color (with empty domain) - * - a constant last color function - */ - cairo_ps_color_stop_t pad_stops[4]; - - assert (pattern->base.extend == CAIRO_EXTEND_PAD); - - pad_stops[0] = pad_stops[1] = stops[0]; - pad_stops[2] = pad_stops[3] = stops[n_stops - 1]; - - pad_stops[0].offset = 0; - pad_stops[3].offset = 1; - - _cairo_ps_surface_emit_stitched_colorgradient (surface, 4, pad_stops); - } else if (n_stops == 2) { - /* no need for stitched function */ - _cairo_ps_surface_emit_linear_colorgradient (surface, &stops[0], &stops[1]); - } else { - /* multiple stops: stitch. XXX possible optimization: regulary spaced - * stops do not require stitching. XXX */ - _cairo_ps_surface_emit_stitched_colorgradient (surface, n_stops, stops); - } - _cairo_output_stream_printf (surface->stream, - "def\n"); - - free (allstops); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_ps_surface_emit_repeating_function (cairo_ps_surface_t *surface, - cairo_gradient_pattern_t *pattern, - int begin, - int end) -{ - _cairo_output_stream_printf (surface->stream, - "/CairoFunction\n" - "<< /FunctionType 3\n" - " /Domain [ %d %d ]\n" - " /Functions [ %d {CairoFunction} repeat ]\n" - " /Bounds [ %d 1 %d {} for ]\n", - begin, - end, - end - begin, - begin + 1, - end - 1); - - if (pattern->base.extend == CAIRO_EXTEND_REFLECT) { - _cairo_output_stream_printf (surface->stream, " /Encode [ %d 1 %d { 2 mod 0 eq {0 1} {1 0} ifelse } for ]\n", - begin, - end - 1); - } else { - _cairo_output_stream_printf (surface->stream, " /Encode [ %d 1 %d { pop 0 1 } for ]\n", - begin, - end - 1); - } - - _cairo_output_stream_printf (surface->stream, ">> def\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_ps_surface_emit_gradient (cairo_ps_surface_t *surface, - cairo_gradient_pattern_t *pattern, - cairo_bool_t is_ps_pattern) -{ - cairo_matrix_t pat_to_ps; - cairo_circle_double_t start, end; - double domain[2]; - cairo_status_t status; - - assert (pattern->n_stops != 0); - - status = _cairo_ps_surface_emit_pattern_stops (surface, pattern); - if (unlikely (status)) - return status; - - pat_to_ps = pattern->base.matrix; - status = cairo_matrix_invert (&pat_to_ps); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - cairo_matrix_multiply (&pat_to_ps, &pat_to_ps, &surface->cairo_to_ps); - - if (pattern->base.extend == CAIRO_EXTEND_REPEAT || - pattern->base.extend == CAIRO_EXTEND_REFLECT) - { - double bounds_x1, bounds_x2, bounds_y1, bounds_y2; - double x_scale, y_scale, tolerance; - - /* TODO: use tighter extents */ - bounds_x1 = 0; - bounds_y1 = 0; - bounds_x2 = surface->width; - bounds_y2 = surface->height; - _cairo_matrix_transform_bounding_box (&pattern->base.matrix, - &bounds_x1, &bounds_y1, - &bounds_x2, &bounds_y2, - NULL); - - x_scale = surface->base.x_resolution / surface->base.x_fallback_resolution; - y_scale = surface->base.y_resolution / surface->base.y_fallback_resolution; - - tolerance = fabs (_cairo_matrix_compute_determinant (&pattern->base.matrix)); - tolerance /= _cairo_matrix_transformed_circle_major_axis (&pattern->base.matrix, 1); - tolerance *= MIN (x_scale, y_scale); - - _cairo_gradient_pattern_box_to_parameter (pattern, - bounds_x1, bounds_y1, - bounds_x2, bounds_y2, - tolerance, domain); - } else if (pattern->stops[0].offset == pattern->stops[pattern->n_stops - 1].offset) { - /* - * If the first and the last stop offset are the same, then - * the color function is a step function. - * _cairo_ps_surface_emit_pattern_stops emits it as a stitched - * function no matter how many stops the pattern has. The - * domain of the stitched function will be [0 1] in this case. - * - * This is done to avoid emitting degenerate gradients for - * EXTEND_PAD patterns having a step color function. - */ - domain[0] = 0.0; - domain[1] = 1.0; - - assert (pattern->base.extend == CAIRO_EXTEND_PAD); - } else { - domain[0] = pattern->stops[0].offset; - domain[1] = pattern->stops[pattern->n_stops - 1].offset; - } - - /* PS requires the first and last stop to be the same as the - * extreme coordinates. For repeating patterns this moves the - * extreme coordinates out to the begin/end of the repeating - * function. For non repeating patterns this may move the extreme - * coordinates in if there are not stops at offset 0 and 1. */ - _cairo_gradient_pattern_interpolate (pattern, domain[0], &start); - _cairo_gradient_pattern_interpolate (pattern, domain[1], &end); - - if (pattern->base.extend == CAIRO_EXTEND_REPEAT || - pattern->base.extend == CAIRO_EXTEND_REFLECT) - { - int repeat_begin, repeat_end; - - repeat_begin = floor (domain[0]); - repeat_end = ceil (domain[1]); - - status = _cairo_ps_surface_emit_repeating_function (surface, - pattern, - repeat_begin, - repeat_end); - if (unlikely (status)) - return status; - } else if (pattern->n_stops <= 2) { - /* For EXTEND_NONE and EXTEND_PAD if there are only two stops a - * Type 2 function is used by itself without a stitching - * function. Type 2 functions always have the domain [0 1] */ - domain[0] = 0.0; - domain[1] = 1.0; - } - - if (is_ps_pattern) { - _cairo_output_stream_printf (surface->stream, - "<< /PatternType 2\n" - " /Shading\n"); - } - - if (pattern->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - _cairo_output_stream_printf (surface->stream, - " << /ShadingType 2\n" - " /ColorSpace /DeviceRGB\n" - " /Coords [ %f %f %f %f ]\n", - start.center.x, start.center.y, - end.center.x, end.center.y); - } else { - _cairo_output_stream_printf (surface->stream, - " << /ShadingType 3\n" - " /ColorSpace /DeviceRGB\n" - " /Coords [ %f %f %f %f %f %f ]\n", - start.center.x, start.center.y, - MAX (start.radius, 0), - end.center.x, end.center.y, - MAX (end.radius, 0)); - } - - if (pattern->base.extend != CAIRO_EXTEND_NONE) { - _cairo_output_stream_printf (surface->stream, - " /Extend [ true true ]\n"); - } else { - _cairo_output_stream_printf (surface->stream, - " /Extend [ false false ]\n"); - } - - if (domain[0] == 0.0 && domain[1] == 1.0) { - _cairo_output_stream_printf (surface->stream, - " /Function CairoFunction\n"); - } else { - _cairo_output_stream_printf (surface->stream, - " /Function <<\n" - " /FunctionType 3\n" - " /Domain [ 0 1 ]\n" - " /Bounds [ ]\n" - " /Encode [ %f %f ]\n" - " /Functions [ CairoFunction ]\n" - " >>\n", - domain[0], domain[1]); - } - - _cairo_output_stream_printf (surface->stream, - " >>\n"); - - if (is_ps_pattern) { - _cairo_output_stream_printf (surface->stream, - ">>\n" - "[ "); - _cairo_output_stream_print_matrix (surface->stream, &pat_to_ps); - _cairo_output_stream_printf (surface->stream, " ]\n" - "makepattern setpattern\n"); - } else { - _cairo_output_stream_printf (surface->stream, - "shfill\n"); - } - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_mesh_pattern (cairo_ps_surface_t *surface, - cairo_mesh_pattern_t *pattern, - cairo_bool_t is_ps_pattern) -{ - cairo_matrix_t pat_to_ps; - cairo_status_t status; - cairo_pdf_shading_t shading; - int i; - - if (_cairo_array_num_elements (&pattern->patches) == 0) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - pat_to_ps = pattern->base.matrix; - status = cairo_matrix_invert (&pat_to_ps); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - cairo_matrix_multiply (&pat_to_ps, &pat_to_ps, &surface->cairo_to_ps); - - status = _cairo_pdf_shading_init_color (&shading, pattern); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->stream, - "currentfile\n" - "/ASCII85Decode filter /FlateDecode filter /ReusableStreamDecode filter\n"); - - status = _cairo_ps_surface_emit_base85_string (surface, - shading.data, - shading.data_length, - CAIRO_PS_COMPRESS_DEFLATE, - FALSE); - if (status) - return status; - - _cairo_output_stream_printf (surface->stream, - "\n" - "/CairoData exch def\n"); - - if (is_ps_pattern) { - _cairo_output_stream_printf (surface->stream, - "<< /PatternType 2\n" - " /Shading\n"); - } - - _cairo_output_stream_printf (surface->stream, - " << /ShadingType %d\n" - " /ColorSpace /DeviceRGB\n" - " /DataSource CairoData\n" - " /BitsPerCoordinate %d\n" - " /BitsPerComponent %d\n" - " /BitsPerFlag %d\n" - " /Decode [", - shading.shading_type, - shading.bits_per_coordinate, - shading.bits_per_component, - shading.bits_per_flag); - - for (i = 0; i < shading.decode_array_length; i++) - _cairo_output_stream_printf (surface->stream, "%f ", shading.decode_array[i]); - - _cairo_output_stream_printf (surface->stream, - "]\n" - " >>\n"); - - if (is_ps_pattern) { - _cairo_output_stream_printf (surface->stream, - ">>\n" - "[ \n"); - _cairo_output_stream_print_matrix (surface->stream, &pat_to_ps); - _cairo_output_stream_printf (surface->stream, - " ]\n" - "makepattern\n" - "setpattern\n"); - } else { - _cairo_output_stream_printf (surface->stream, "shfill\n"); - } - - _cairo_output_stream_printf (surface->stream, - "currentdict /CairoData undef\n"); - - _cairo_pdf_shading_fini (&shading); - - return status; -} - -static cairo_status_t -_cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_rectangle_int_t *extents, - cairo_operator_t op) -{ - cairo_status_t status; - - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; - - if (surface->current_pattern_is_solid_color == FALSE || - ! _cairo_color_equal (&surface->current_color, &solid->color)) - { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); - - surface->current_pattern_is_solid_color = TRUE; - surface->current_color = solid->color; - } - - return CAIRO_STATUS_SUCCESS; - } - - surface->current_pattern_is_solid_color = FALSE; - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - return status; - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - - _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); - break; - - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - status = _cairo_ps_surface_emit_surface_pattern (surface, - (cairo_pattern_t *)pattern, - extents, - op); - if (unlikely (status)) - return status; - break; - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - status = _cairo_ps_surface_emit_gradient (surface, - (cairo_gradient_pattern_t *) pattern, - TRUE); - if (unlikely (status)) - return status; - break; - - case CAIRO_PATTERN_TYPE_MESH: - status = _cairo_ps_surface_emit_mesh_pattern (surface, - (cairo_mesh_pattern_t *) pattern, - TRUE); - if (unlikely (status)) - return status; - break; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_ps_surface_paint_gradient (cairo_ps_surface_t *surface, - const cairo_pattern_t *source, - const cairo_rectangle_int_t *extents) -{ - cairo_matrix_t pat_to_ps; - cairo_status_t status; - - pat_to_ps = source->matrix; - status = cairo_matrix_invert (&pat_to_ps); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - cairo_matrix_multiply (&pat_to_ps, &pat_to_ps, &surface->cairo_to_ps); - - if (! _cairo_matrix_is_identity (&pat_to_ps)) { - _cairo_output_stream_printf (surface->stream, "["); - _cairo_output_stream_print_matrix (surface->stream, &pat_to_ps); - _cairo_output_stream_printf (surface->stream, "] concat\n"); - } - - if (source->type == CAIRO_PATTERN_TYPE_MESH) { - status = _cairo_ps_surface_emit_mesh_pattern (surface, - (cairo_mesh_pattern_t *)source, - FALSE); - if (unlikely (status)) - return status; - } else { - status = _cairo_ps_surface_emit_gradient (surface, - (cairo_gradient_pattern_t *)source, - FALSE); - if (unlikely (status)) - return status; - } - - return status; -} - -static cairo_status_t -_cairo_ps_surface_paint_pattern (cairo_ps_surface_t *surface, - const cairo_pattern_t *source, - cairo_rectangle_int_t *extents, - cairo_operator_t op, - cairo_bool_t stencil_mask) -{ - switch (source->type) { - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _cairo_ps_surface_paint_surface (surface, - (cairo_pattern_t *)source, - extents, - op, - stencil_mask); - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - return _cairo_ps_surface_paint_gradient (surface, - source, - extents); - - case CAIRO_PATTERN_TYPE_SOLID: - default: - ASSERT_NOT_REACHED; - return CAIRO_STATUS_SUCCESS; - } -} - -static cairo_bool_t -_can_paint_pattern (const cairo_pattern_t *pattern) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return FALSE; - - case CAIRO_PATTERN_TYPE_SURFACE: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return (pattern->extend == CAIRO_EXTEND_NONE || - pattern->extend == CAIRO_EXTEND_PAD); - - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - return TRUE; - - default: - ASSERT_NOT_REACHED; - return FALSE; - } -} - -static cairo_bool_t -_cairo_ps_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_ps_surface_t *surface = abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - - /* XXX: The conversion to integers here is pretty bogus, (not to - * mention the aribitray limitation of width to a short(!). We - * may need to come up with a better interface for get_extents. - */ - rectangle->width = ceil (surface->width); - rectangle->height = ceil (surface->height); - - return TRUE; -} - -static void -_cairo_ps_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - _cairo_font_options_init_default (options); - - cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); - cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); - _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); -} - -static cairo_int_status_t -_cairo_ps_surface_set_clip (cairo_ps_surface_t *surface, - cairo_composite_rectangles_t *composite) -{ - cairo_clip_t *clip = composite->clip; - - if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) - clip = NULL; - - if (clip == NULL) { - if (_cairo_composite_rectangles_can_reduce_clip (composite, - surface->clipper.clip)) - return CAIRO_STATUS_SUCCESS; - } - - return _cairo_surface_clipper_set_clip (&surface->clipper, clip); -} - -static cairo_int_status_t -_cairo_ps_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_output_stream_t *stream = surface->stream; - cairo_composite_rectangles_t extents; - cairo_status_t status; - - status = _cairo_composite_rectangles_init_for_paint (&extents, - &surface->base, - op, source, clip); - if (unlikely (status)) - return status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); - goto cleanup_composite; - } - - assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); - -#if DEBUG_PS - _cairo_output_stream_printf (stream, - "%% _cairo_ps_surface_paint\n"); -#endif - - status = _cairo_ps_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup_composite; - - if (_can_paint_pattern (source)) { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_output_stream_printf (stream, "q\n"); - status = _cairo_ps_surface_paint_pattern (surface, - source, - &extents.bounded, op, FALSE); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_output_stream_printf (stream, "Q\n"); - } else { - status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_output_stream_printf (stream, "0 0 %f %f rectfill\n", - surface->width, surface->height); - } - -cleanup_composite: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_ps_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_output_stream_t *stream = surface->stream; - cairo_composite_rectangles_t extents; - cairo_status_t status; - - status = _cairo_composite_rectangles_init_for_mask (&extents, - &surface->base, - op, source, mask, clip); - if (unlikely (status)) - return status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_ps_surface_analyze_operation (surface, op, source, mask, &extents.bounded); - goto cleanup_composite; - } - - assert (_cairo_ps_surface_operation_supported (surface, op, source, mask, &extents.bounded)); - -#if DEBUG_PS - _cairo_output_stream_printf (stream, - "%% _cairo_ps_surface_mask\n"); -#endif - - status = _cairo_ps_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_output_stream_printf (stream, "q\n"); - status = _cairo_ps_surface_paint_pattern (surface, - mask, - &extents.bounded, op, TRUE); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_output_stream_printf (stream, "Q\n"); - -cleanup_composite: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_ps_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - status = _cairo_composite_rectangles_init_for_stroke (&extents, - &surface->base, - op, source, - path, style, ctm, - clip); - if (unlikely (status)) - return status; - - /* use the more accurate extents */ - { - cairo_rectangle_int_t r; - cairo_box_t b; - - status = _cairo_path_fixed_stroke_extents (path, style, - ctm, ctm_inverse, - tolerance, - &r); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_box_from_rectangle (&b, &r); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, &b); - if (unlikely (status)) - goto cleanup_composite; - } - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); - goto cleanup_composite; - } - - assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); - -#if DEBUG_PS - _cairo_output_stream_printf (surface->stream, - "%% _cairo_ps_surface_stroke\n"); -#endif - - status = _cairo_ps_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_pdf_operators_stroke (&surface->pdf_operators, - path, - style, - ctm, - ctm_inverse); - -cleanup_composite: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_int_status_t -_cairo_ps_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_composite_rectangles_t extents; - cairo_int_status_t status; - - status = _cairo_composite_rectangles_init_for_fill (&extents, - &surface->base, - op, source, path, - clip); - if (unlikely (status)) - return status; - - /* use the more accurate extents */ - { - cairo_rectangle_int_t r; - cairo_box_t b; - - _cairo_path_fixed_fill_extents (path, - fill_rule, - tolerance, - &r); - - _cairo_box_from_rectangle (&b, &r); - status = _cairo_composite_rectangles_intersect_mask_extents (&extents, &b); - if (unlikely (status)) - goto cleanup_composite; - } - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); - goto cleanup_composite; - } - - assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); - -#if DEBUG_PS - _cairo_output_stream_printf (surface->stream, - "%% _cairo_ps_surface_fill\n"); -#endif - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_ps_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup_composite; - - if (_can_paint_pattern (source)) { - _cairo_output_stream_printf (surface->stream, "q\n"); - - status = _cairo_pdf_operators_clip (&surface->pdf_operators, - path, - fill_rule); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_ps_surface_paint_pattern (surface, - source, - &extents.bounded, op, FALSE); - if (unlikely (status)) - goto cleanup_composite; - - _cairo_output_stream_printf (surface->stream, "Q\n"); - _cairo_pdf_operators_reset (&surface->pdf_operators); - } else { - status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_pdf_operators_fill (&surface->pdf_operators, - path, - fill_rule); - } - -cleanup_composite: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static cairo_bool_t -_cairo_ps_surface_has_show_text_glyphs (void *abstract_surface) -{ - return TRUE; -} - -static cairo_int_status_t -_cairo_ps_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_composite_rectangles_t extents; - cairo_bool_t overlap; - cairo_status_t status; - - status = _cairo_composite_rectangles_init_for_glyphs (&extents, - &surface->base, - op, source, - scaled_font, - glyphs, num_glyphs, - clip, - &overlap); - if (unlikely (status)) - return status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); - goto cleanup_composite; - } - - assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); - -#if DEBUG_PS - _cairo_output_stream_printf (surface->stream, - "%% _cairo_ps_surface_show_glyphs\n"); -#endif - - status = _cairo_ps_surface_set_clip (surface, &extents); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); - if (unlikely (status)) - goto cleanup_composite; - - status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font); - -cleanup_composite: - _cairo_composite_rectangles_fini (&extents); - return status; -} - -static const char ** -_cairo_ps_surface_get_supported_mime_types (void *abstract_surface) -{ - return _cairo_ps_supported_mime_types; -} - -static void -_cairo_ps_surface_set_paginated_mode (void *abstract_surface, - cairo_paginated_mode_t paginated_mode) -{ - cairo_ps_surface_t *surface = abstract_surface; - cairo_status_t status; - - surface->paginated_mode = paginated_mode; - - if (surface->clipper.clip != NULL) { - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - - _cairo_output_stream_printf (surface->stream, "Q q\n"); - _cairo_surface_clipper_reset (&surface->clipper); - } -} - -static cairo_int_status_t -_cairo_ps_surface_set_bounding_box (void *abstract_surface, - cairo_box_t *bbox) -{ - cairo_ps_surface_t *surface = abstract_surface; - int i, num_comments; - char **comments; - int x1, y1, x2, y2; - cairo_bool_t has_page_media, has_page_bbox; - const char *page_media; - - x1 = floor (_cairo_fixed_to_double (bbox->p1.x)); - y1 = floor (surface->height - _cairo_fixed_to_double (bbox->p2.y)); - x2 = ceil (_cairo_fixed_to_double (bbox->p2.x)); - y2 = ceil (surface->height - _cairo_fixed_to_double (bbox->p1.y)); - - surface->page_bbox.x = x1; - surface->page_bbox.y = y1; - surface->page_bbox.width = x2 - x1; - surface->page_bbox.height = y2 - y1; - - _cairo_output_stream_printf (surface->stream, - "%%%%Page: %d %d\n", - surface->num_pages, - surface->num_pages); - - _cairo_output_stream_printf (surface->stream, - "%%%%BeginPageSetup\n"); - - has_page_media = FALSE; - has_page_bbox = FALSE; - num_comments = _cairo_array_num_elements (&surface->dsc_page_setup_comments); - comments = _cairo_array_index (&surface->dsc_page_setup_comments, 0); - for (i = 0; i < num_comments; i++) { - _cairo_output_stream_printf (surface->stream, - "%s\n", comments[i]); - if (strncmp (comments[i], "%%PageMedia:", 11) == 0) - has_page_media = TRUE; - - if (strncmp (comments[i], "%%PageBoundingBox:", 18) == 0) - has_page_bbox = TRUE; - - free (comments[i]); - comments[i] = NULL; - } - _cairo_array_truncate (&surface->dsc_page_setup_comments, 0); - - if (!has_page_media && !surface->eps) { - page_media = _cairo_ps_surface_get_page_media (surface); - if (unlikely (page_media == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_output_stream_printf (surface->stream, - "%%%%PageMedia: %s\n", - page_media); - } - - if (!has_page_bbox) { - _cairo_output_stream_printf (surface->stream, - "%%%%PageBoundingBox: %d %d %d %d\n", - x1, y1, x2, y2); - } - - if (!surface->eps) { - _cairo_output_stream_printf (surface->stream, - "%f %f cairo_set_page_size\n", - ceil(surface->width), - ceil(surface->height)); - } - - _cairo_output_stream_printf (surface->stream, - "%%%%EndPageSetup\n" - "q %d %d %d %d rectclip q\n", - surface->page_bbox.x, - surface->page_bbox.y, - surface->page_bbox.width, - surface->page_bbox.height); - - if (surface->num_pages == 1) { - surface->bbox_x1 = x1; - surface->bbox_y1 = y1; - surface->bbox_x2 = x2; - surface->bbox_y2 = y2; - } else { - if (x1 < surface->bbox_x1) - surface->bbox_x1 = x1; - if (y1 < surface->bbox_y1) - surface->bbox_y1 = y1; - if (x2 > surface->bbox_x2) - surface->bbox_x2 = x2; - if (y2 > surface->bbox_y2) - surface->bbox_y2 = y2; - } - surface->current_pattern_is_solid_color = FALSE; - _cairo_pdf_operators_reset (&surface->pdf_operators); - - return _cairo_output_stream_get_status (surface->stream); -} - -static cairo_bool_t -_cairo_ps_surface_supports_fine_grained_fallbacks (void *abstract_surface) -{ - return TRUE; -} - -static const cairo_surface_backend_t cairo_ps_surface_backend = { - CAIRO_SURFACE_TYPE_PS, - _cairo_ps_surface_finish, - - _cairo_default_context_create, - - NULL, /* create similar: handled by wrapper */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* cairo_ps_surface_copy_page */ - _cairo_ps_surface_show_page, - - _cairo_ps_surface_get_extents, - _cairo_ps_surface_get_font_options, - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - /* Here are the drawing functions */ - - _cairo_ps_surface_paint, /* paint */ - _cairo_ps_surface_mask, - _cairo_ps_surface_stroke, - _cairo_ps_surface_fill, - NULL, /* fill-stroke */ - NULL, /* show_glyphs */ - _cairo_ps_surface_has_show_text_glyphs, - _cairo_ps_surface_show_text_glyphs, - _cairo_ps_surface_get_supported_mime_types, -}; - -static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend = { - _cairo_ps_surface_start_page, - _cairo_ps_surface_set_paginated_mode, - _cairo_ps_surface_set_bounding_box, - NULL, /* _cairo_ps_surface_has_fallback_images, */ - _cairo_ps_surface_supports_fine_grained_fallbacks, -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps.h deleted file mode 100644 index 33d0e0d941b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-ps.h +++ /dev/null @@ -1,116 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_PS_H -#define CAIRO_PS_H - -#include "cairo.h" - -#if CAIRO_HAS_PS_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -/* PS-surface functions */ - -/** - * cairo_ps_level_t: - * @CAIRO_PS_LEVEL_2: The language level 2 of the PostScript specification. (Since 1.6) - * @CAIRO_PS_LEVEL_3: The language level 3 of the PostScript specification. (Since 1.6) - * - * #cairo_ps_level_t is used to describe the language level of the - * PostScript Language Reference that a generated PostScript file will - * conform to. - * - * Since: 1.6 - **/ -typedef enum _cairo_ps_level { - CAIRO_PS_LEVEL_2, - CAIRO_PS_LEVEL_3 -} cairo_ps_level_t; - -cairo_public cairo_surface_t * -cairo_ps_surface_create (const char *filename, - double width_in_points, - double height_in_points); - -cairo_public cairo_surface_t * -cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, - void *closure, - double width_in_points, - double height_in_points); - -cairo_public void -cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, - cairo_ps_level_t level); - -cairo_public void -cairo_ps_get_levels (cairo_ps_level_t const **levels, - int *num_levels); - -cairo_public const char * -cairo_ps_level_to_string (cairo_ps_level_t level); - -cairo_public void -cairo_ps_surface_set_eps (cairo_surface_t *surface, - cairo_bool_t eps); - -cairo_public cairo_bool_t -cairo_ps_surface_get_eps (cairo_surface_t *surface); - -cairo_public void -cairo_ps_surface_set_size (cairo_surface_t *surface, - double width_in_points, - double height_in_points); - -cairo_public void -cairo_ps_surface_dsc_comment (cairo_surface_t *surface, - const char *comment); - -cairo_public void -cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface); - -cairo_public void -cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_PS_SURFACE */ -# error Cairo was not compiled with support for the ps backend -#endif /* CAIRO_HAS_PS_SURFACE */ - -#endif /* CAIRO_PS_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt-surface.cpp b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt-surface.cpp deleted file mode 100644 index 7ddad77df37..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt-surface.cpp +++ /dev/null @@ -1,1738 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Corporation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -/* Get INT16_MIN etc. as per C99 */ -#define __STDC_LIMIT_MACROS - -#include "cairoint.h" - -#include "cairo-clip-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-region-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-types-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-surface-fallback-private.h" - -#include "cairo-ft.h" -#include "cairo-qt.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if ((QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) || defined(QT_GLYPHS_API_BACKPORT)) && 0 -extern void qt_draw_glyphs(QPainter *, const quint32 *glyphs, const QPointF *positions, int count); -#endif - -#include - -/* Enable workaround slow regional Qt paths */ -#define ENABLE_FAST_FILL 0 -#define ENABLE_FAST_CLIP 0 - -#if 0 -#define D(x) x -static const char * -_opstr (cairo_operator_t op) -{ - const char *ops[] = { - "CLEAR", - "SOURCE", - "OVER", - "IN", - "OUT", - "ATOP", - "DEST", - "DEST_OVER", - "DEST_IN", - "DEST_OUT", - "DEST_ATOP", - "XOR", - "ADD", - "SATURATE" - }; - - if (op < CAIRO_OPERATOR_CLEAR || op > CAIRO_OPERATOR_SATURATE) - return "(\?\?\?)"; - - return ops[op]; -} -#else -#define D(x) do { } while(0) -#endif - -#ifndef CAIRO_INT_STATUS_SUCCESS -#define CAIRO_INT_STATUS_SUCCESS ((cairo_int_status_t) CAIRO_STATUS_SUCCESS) -#endif - -/* Qt::PenStyle optimization based on the assumption that dots are 1*w and dashes are 3*w. */ -#define DOT_LENGTH 1.0 -#define DASH_LENGTH 3.0 - -struct cairo_qt_surface_t { - cairo_surface_t base; - - cairo_bool_t supports_porter_duff; - - QPainter *p; - - /* The pixmap/image constructors will store their objects here */ - QPixmap *pixmap; - QImage *image; - - QRect window; - - cairo_surface_clipper_t clipper; - - cairo_surface_t *image_equiv; -}; - -/* Will be true if we ever try to create a QPixmap and end - * up with one without an alpha channel. - */ -static cairo_bool_t _qpixmaps_have_no_alpha = FALSE; - -/* - * Helper methods - */ - -static QPainter::CompositionMode -_qpainter_compositionmode_from_cairo_op (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_CLEAR: - return QPainter::CompositionMode_Clear; - - case CAIRO_OPERATOR_SOURCE: - return QPainter::CompositionMode_Source; - case CAIRO_OPERATOR_OVER: - return QPainter::CompositionMode_SourceOver; - case CAIRO_OPERATOR_IN: - return QPainter::CompositionMode_SourceIn; - case CAIRO_OPERATOR_OUT: - return QPainter::CompositionMode_SourceOut; - case CAIRO_OPERATOR_ATOP: - return QPainter::CompositionMode_SourceAtop; - - case CAIRO_OPERATOR_DEST: - return QPainter::CompositionMode_Destination; - case CAIRO_OPERATOR_DEST_OVER: - return QPainter::CompositionMode_DestinationOver; - case CAIRO_OPERATOR_DEST_IN: - return QPainter::CompositionMode_DestinationIn; - case CAIRO_OPERATOR_DEST_OUT: - return QPainter::CompositionMode_DestinationOut; - case CAIRO_OPERATOR_DEST_ATOP: - return QPainter::CompositionMode_DestinationAtop; - - case CAIRO_OPERATOR_XOR: - return QPainter::CompositionMode_Xor; - - default: - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - ASSERT_NOT_REACHED; - } -} - -static bool -_op_is_supported (cairo_qt_surface_t *qs, cairo_operator_t op) -{ - if (qs->p == NULL) - return false; - - if (qs->supports_porter_duff) { - switch (op) { - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_ATOP: - - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_DEST_ATOP: - - case CAIRO_OPERATOR_XOR: - return TRUE; - - default: - ASSERT_NOT_REACHED; - case CAIRO_OPERATOR_ADD: - case CAIRO_OPERATOR_SATURATE: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return FALSE; - - } - } else { - return op == CAIRO_OPERATOR_OVER; - } -} - -static cairo_format_t -_cairo_format_from_qimage_format (QImage::Format fmt) -{ - switch (fmt) { - case QImage::Format_ARGB32_Premultiplied: - return CAIRO_FORMAT_ARGB32; - case QImage::Format_RGB32: - return CAIRO_FORMAT_RGB24; - case QImage::Format_Indexed8: // XXX not quite - return CAIRO_FORMAT_A8; -#ifdef WORDS_BIGENDIAN - case QImage::Format_Mono: -#else - case QImage::Format_MonoLSB: -#endif - return CAIRO_FORMAT_A1; - - case QImage::Format_Invalid: -#ifdef WORDS_BIGENDIAN - case QImage::Format_MonoLSB: -#else - case QImage::Format_Mono: -#endif - case QImage::Format_ARGB32: - case QImage::Format_RGB16: - case QImage::Format_ARGB8565_Premultiplied: - case QImage::Format_RGB666: - case QImage::Format_ARGB6666_Premultiplied: - case QImage::Format_RGB555: - case QImage::Format_ARGB8555_Premultiplied: - case QImage::Format_RGB888: - case QImage::Format_RGB444: - case QImage::Format_ARGB4444_Premultiplied: - case QImage::NImageFormats: - default: - ASSERT_NOT_REACHED; - return (cairo_format_t) -1; - } -} - -static QImage::Format -_qimage_format_from_cairo_format (cairo_format_t fmt) -{ - switch (fmt) { - case CAIRO_FORMAT_INVALID: - ASSERT_NOT_REACHED; - case CAIRO_FORMAT_ARGB32: - return QImage::Format_ARGB32_Premultiplied; - case CAIRO_FORMAT_RGB24: - return QImage::Format_RGB32; - case CAIRO_FORMAT_RGB16_565: - return QImage::Format_RGB16; - case CAIRO_FORMAT_A8: - return QImage::Format_Indexed8; // XXX not quite - case CAIRO_FORMAT_A1: -#ifdef WORDS_BIGENDIAN - return QImage::Format_Mono; // XXX think we need to choose between this and LSB -#else - return QImage::Format_MonoLSB; -#endif - case CAIRO_FORMAT_RGB30: - return QImage::Format_Mono; - } - - return QImage::Format_Mono; -} - -static inline QMatrix -_qmatrix_from_cairo_matrix (const cairo_matrix_t& m) -{ - return QMatrix(m.xx, m.yx, m.xy, m.yy, m.x0, m.y0); -} - -/* Path conversion */ -typedef struct _qpainter_path_transform { - QPainterPath path; - const cairo_matrix_t *ctm_inverse; -} qpainter_path_data; - -/* cairo path -> execute in context */ -static cairo_status_t -_cairo_path_to_qpainterpath_move_to (void *closure, const cairo_point_t *point) -{ - qpainter_path_data *pdata = static_cast (closure); - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (pdata->ctm_inverse) - cairo_matrix_transform_point (pdata->ctm_inverse, &x, &y); - - pdata->path.moveTo(x, y); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_to_qpainterpath_line_to (void *closure, const cairo_point_t *point) -{ - qpainter_path_data *pdata = static_cast (closure); - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (pdata->ctm_inverse) - cairo_matrix_transform_point (pdata->ctm_inverse, &x, &y); - - pdata->path.lineTo(x, y); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_to_qpainterpath_curve_to (void *closure, const cairo_point_t *p0, const cairo_point_t *p1, const cairo_point_t *p2) -{ - qpainter_path_data *pdata = static_cast (closure); - double x0 = _cairo_fixed_to_double (p0->x); - double y0 = _cairo_fixed_to_double (p0->y); - double x1 = _cairo_fixed_to_double (p1->x); - double y1 = _cairo_fixed_to_double (p1->y); - double x2 = _cairo_fixed_to_double (p2->x); - double y2 = _cairo_fixed_to_double (p2->y); - - if (pdata->ctm_inverse) { - cairo_matrix_transform_point (pdata->ctm_inverse, &x0, &y0); - cairo_matrix_transform_point (pdata->ctm_inverse, &x1, &y1); - cairo_matrix_transform_point (pdata->ctm_inverse, &x2, &y2); - } - - pdata->path.cubicTo (x0, y0, x1, y1, x2, y2); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_to_qpainterpath_close_path (void *closure) -{ - qpainter_path_data *pdata = static_cast (closure); - - pdata->path.closeSubpath(); - - return CAIRO_STATUS_SUCCESS; -} - -static QPainterPath -path_to_qt (const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm_inverse = NULL) -{ - qpainter_path_data data; - cairo_status_t status; - - if (ctm_inverse && _cairo_matrix_is_identity (ctm_inverse)) - ctm_inverse = NULL; - data.ctm_inverse = ctm_inverse; - - status = _cairo_path_fixed_interpret (path, - _cairo_path_to_qpainterpath_move_to, - _cairo_path_to_qpainterpath_line_to, - _cairo_path_to_qpainterpath_curve_to, - _cairo_path_to_qpainterpath_close_path, - &data); - assert (status == CAIRO_STATUS_SUCCESS); - - return data.path; -} - -static inline QPainterPath -path_to_qt (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - cairo_matrix_t *ctm_inverse = NULL) -{ - QPainterPath qpath = path_to_qt (path, ctm_inverse); - - qpath.setFillRule (fill_rule == CAIRO_FILL_RULE_WINDING ? - Qt::WindingFill : - Qt::OddEvenFill); - - return qpath; -} - -/* - * Surface backend methods - */ -static cairo_surface_t * -_cairo_qt_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - bool use_pixmap; - - D(fprintf(stderr, "q[%p] create_similar: %d %d [%d] -> ", abstract_surface, width, height, content)); - - use_pixmap = qs->image == NULL; - if (use_pixmap) { - switch (content) { - case CAIRO_CONTENT_ALPHA: - use_pixmap = FALSE; - break; - case CAIRO_CONTENT_COLOR: - break; - case CAIRO_CONTENT_COLOR_ALPHA: - use_pixmap = ! _qpixmaps_have_no_alpha; - break; - } - } - - if (use_pixmap) { - cairo_surface_t *result = - cairo_qt_surface_create_with_qpixmap (content, width, height); - - /* XXX result->content is always content. ??? */ - if (result->content == content) { - D(fprintf(stderr, "qpixmap content: %d\n", content)); - return result; - } - - _qpixmaps_have_no_alpha = TRUE; - cairo_surface_destroy (result); - } - - D(fprintf (stderr, "qimage\n")); - return cairo_qt_surface_create_with_qimage - (_cairo_format_from_content (content), width, height); -} - -static cairo_status_t -_cairo_qt_surface_finish (void *abstract_surface) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] finish\n", abstract_surface)); - - /* Only delete p if we created it */ - if (qs->image || qs->pixmap) - delete qs->p; - else - qs->p->restore (); - - if (qs->image_equiv) - cairo_surface_destroy (qs->image_equiv); - - _cairo_surface_clipper_reset (&qs->clipper); - - if (qs->image) - delete qs->image; - - if (qs->pixmap) - delete qs->pixmap; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_qimg_destroy (void *closure) -{ - QImage *qimg = (QImage *) closure; - delete qimg; -} - -static cairo_status_t -_cairo_qt_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] acquire_source_image\n", abstract_surface)); - - *image_extra = NULL; - - if (qs->image_equiv) { - *image_out = (cairo_image_surface_t*) - cairo_surface_reference (qs->image_equiv); - - return CAIRO_STATUS_SUCCESS; - } - - if (qs->pixmap) { - QImage *qimg = new QImage(qs->pixmap->toImage()); - cairo_surface_t *image; - cairo_status_t status; - - image = cairo_image_surface_create_for_data (qimg->bits(), - _cairo_format_from_qimage_format (qimg->format()), - qimg->width(), qimg->height(), - qimg->bytesPerLine()); - - status = _cairo_user_data_array_set_data (&image->user_data, - (const cairo_user_data_key_t *)&_qimg_destroy, - qimg, - _qimg_destroy); - if (status) { - cairo_surface_destroy (image); - return status; - } - - *image_out = (cairo_image_surface_t *) image; - return CAIRO_STATUS_SUCCESS; - } - - return _cairo_error (CAIRO_STATUS_NO_MEMORY); -} - -static void -_cairo_qt_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - //cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] release_source_image\n", abstract_surface)); - - cairo_surface_destroy (&image->base); -} - -struct _qimage_surface { - cairo_image_surface_t image; - QImage *qimg; -}; - -static cairo_surface_t * -map_qimage_to_image (QImage *qimg, const cairo_rectangle_int_t *extents) -{ - struct _qimage_surface *surface; - pixman_image_t *pixman_image; - pixman_format_code_t pixman_format; - uint8_t *data; - - if (qimg == NULL) - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - switch (qimg->format()) { - case QImage::Format_ARGB32_Premultiplied: - pixman_format = PIXMAN_a8r8g8b8; - break; - case QImage::Format_RGB32: - pixman_format = PIXMAN_x8r8g8b8; - break; - case QImage::Format_Indexed8: // XXX not quite - pixman_format = PIXMAN_a8; - break; -#ifdef WORDS_BIGENDIAN - case QImage::Format_Mono: -#else - case QImage::Format_MonoLSB: -#endif - pixman_format = PIXMAN_a1; - break; - - case QImage::Format_Invalid: -#ifdef WORDS_BIGENDIAN - case QImage::Format_MonoLSB: -#else - case QImage::Format_Mono: -#endif - case QImage::Format_ARGB32: - case QImage::Format_RGB16: - case QImage::Format_ARGB8565_Premultiplied: - case QImage::Format_RGB666: - case QImage::Format_ARGB6666_Premultiplied: - case QImage::Format_RGB555: - case QImage::Format_ARGB8555_Premultiplied: - case QImage::Format_RGB888: - case QImage::Format_RGB444: - case QImage::Format_ARGB4444_Premultiplied: - case QImage::NImageFormats: - default: - delete qimg; - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_FORMAT); - } - - data = qimg->bits(); - data += extents->y * qimg->bytesPerLine(); - data += extents->x * PIXMAN_FORMAT_BPP (pixman_format) / 8; - - pixman_image = pixman_image_create_bits (pixman_format, - extents->width, - extents->height, - (uint32_t *)data, - qimg->bytesPerLine()); - if (pixman_image == NULL) { - delete qimg; - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - surface = (struct _qimage_surface *) malloc (sizeof(*surface)); - if (unlikely (surface == NULL)) { - pixman_image_unref (pixman_image); - delete qimg; - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_image_surface_init (&surface->image, pixman_image, pixman_format); - surface->qimg = qimg; - - cairo_surface_set_device_offset (&surface->image.base, - -extents->x, -extents->y); - - return &surface->image.base; -} - -static cairo_image_surface_t * -_cairo_qt_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - QImage *qimg = NULL; - - D(fprintf(stderr, "q[%p] acquire_dest_image\n", abstract_surface)); - - if (qs->image_equiv) - return _cairo_image_surface_map_to_image (qs->image_equiv, - extents); - - QPoint offset; - - if (qs->pixmap) { - qimg = new QImage(qs->pixmap->toImage()); - } else { - // Try to figure out what kind of QPaintDevice we have, and - // how we can grab an image from it - QPaintDevice *pd = qs->p->device(); - if (!pd) - return (cairo_image_surface_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - QPaintDevice *rpd = QPainter::redirected(pd, &offset); - if (rpd) - pd = rpd; - - if (pd->devType() == QInternal::Image) { - qimg = new QImage(((QImage*) pd)->copy()); - } else if (pd->devType() == QInternal::Pixmap) { - qimg = new QImage(((QPixmap*) pd)->toImage()); - } else if (pd->devType() == QInternal::Widget) { - qimg = new QImage(QPixmap::grabWindow(((QWidget*)pd)->winId()).toImage()); - } - } - - return (cairo_image_surface_t *) map_qimage_to_image (qimg, extents); -} - -static cairo_int_status_t -_cairo_qt_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] release_dest_image\n", abstract_surface)); - - if (!qs->image_equiv) { - struct _qimage_surface *qimage = (struct _qimage_surface *)image; - - // XXX should I be using setBackgroundMode here instead of setCompositionMode? - if (qs->supports_porter_duff) - qs->p->setCompositionMode (QPainter::CompositionMode_Source); - - qs->p->drawImage ((int)qimage->image.base.device_transform.x0, - (int)qimage->image.base.device_transform.y0, - *qimage->qimg, - (int)qimage->image.base.device_transform.x0, - (int)qimage->image.base.device_transform.y0, - (int)qimage->image.width, - (int)qimage->image.height); - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); - - delete qimage->qimg; - } - - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_qt_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - extents->x = qs->window.x(); - extents->y = qs->window.y(); - extents->width = qs->window.width(); - extents->height = qs->window.height(); - - return TRUE; -} - -static cairo_status_t -_cairo_qt_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_qt_surface_t *qs = cairo_container_of (clipper, - cairo_qt_surface_t, - clipper); - - if (path == NULL) { - if (qs->pixmap || qs->image) { - // we own p - qs->p->setClipping (false); - } else { - qs->p->restore (); - qs->p->save (); - } - } else { - // XXX Antialiasing is ignored - qs->p->setClipPath (path_to_qt (path, fill_rule), Qt::IntersectClip); - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_qt_surface_set_clip_region (cairo_qt_surface_t *qs, - const cairo_region_t *clip_region) -{ - _cairo_surface_clipper_reset (&qs->clipper); - - if (clip_region == NULL) { - // How the clip path is reset depends on whether we own p or not - if (qs->pixmap || qs->image) { - // we own p - qs->p->setClipping (false); - } else { - qs->p->restore (); - qs->p->save (); - } - } else { - QRegion qr; - int num_rects = cairo_region_num_rectangles (clip_region); - for (int i = 0; i < num_rects; ++i) { - cairo_rectangle_int_t rect; - - cairo_region_get_rectangle (clip_region, i, &rect); - - QRect r(rect.x, rect.y, rect.width, rect.height); - qr = qr.unite(r); - } - - qs->p->setClipRegion (qr, Qt::IntersectClip); - } -} - -static cairo_int_status_t -_cairo_qt_surface_set_clip (cairo_qt_surface_t *qs, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - D(fprintf(stderr, "q[%p] intersect_clip_path %s\n", abstract_surface, path ? "(path)" : "(clear)")); - - if (clip == NULL) { - _cairo_surface_clipper_reset (&qs->clipper); - // How the clip path is reset depends on whether we own p or not - if (qs->pixmap || qs->image) { - // we own p - qs->p->setClipping (false); - } else { - qs->p->restore (); - qs->p->save (); - } - - return CAIRO_INT_STATUS_SUCCESS; - } - -#if ENABLE_FAST_CLIP - // Qt will implicitly enable clipping, and will use ReplaceClip - // instead of IntersectClip if clipping was disabled before - - // Note: Qt is really bad at dealing with clip paths. It doesn't - // seem to usefully recognize rectangular paths, instead going down - // extremely slow paths whenever a clip path is set. So, - // we do a bunch of work here to try to get rectangles or regions - // down to Qt for clipping. - - cairo_region_t *clip_region = NULL; - - status = _cairo_clip_get_region (clip, &clip_region); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - // We weren't able to extract a region from the traps. - // Just hand the path down to QPainter. - status = (cairo_int_status_t) - _cairo_surface_clipper_set_clip (&qs->clipper, clip); - } else if (status == CAIRO_INT_STATUS_SUCCESS) { - _cairo_qt_surface_set_clip_region (qs, clip_region); - status = CAIRO_INT_STATUS_SUCCESS; - } -#else - status = (cairo_int_status_t) - _cairo_surface_clipper_set_clip (&qs->clipper, clip); -#endif - - return status; -} - -/* - * Brush conversion - */ - -struct PatternToBrushConverter { - PatternToBrushConverter (const cairo_pattern_t *pattern) - __attribute__ ((noinline)) : - mAcquiredImageParent(0), - mAcquiredImage(0), - mAcquiredImageExtra(0) - { - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) pattern; - QColor color; - color.setRgbF(solid->color.red, - solid->color.green, - solid->color.blue, - solid->color.alpha); - - mBrush = QBrush(color); - } else if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t*) pattern; - cairo_surface_t *surface = spattern->surface; - - if (surface->type == CAIRO_SURFACE_TYPE_QT) { - cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; - - if (qs->image) { - mBrush = QBrush(*qs->image); - } else if (qs->pixmap) { - mBrush = QBrush(*qs->pixmap); - } else { - // do something smart - mBrush = QBrush(0xff0000ff); - } - } else { - cairo_image_surface_t *isurf = NULL; - - if (surface->type == CAIRO_SURFACE_TYPE_IMAGE) { - isurf = (cairo_image_surface_t*) surface; - } else { - void *image_extra; - - if (_cairo_surface_acquire_source_image (surface, &isurf, &image_extra) == CAIRO_STATUS_SUCCESS) { - mAcquiredImageParent = surface; - mAcquiredImage = isurf; - mAcquiredImageExtra = image_extra; - } else { - isurf = NULL; - } - } - - if (isurf) { - mBrush = QBrush (QImage ((const uchar *) isurf->data, - isurf->width, - isurf->height, - isurf->stride, - _qimage_format_from_cairo_format (isurf->format))); - } else { - mBrush = QBrush(0x0000ffff); - } - } - } else if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || - pattern->type == CAIRO_PATTERN_TYPE_RADIAL) - { - QGradient *grad; - cairo_bool_t reverse_stops = FALSE; - cairo_bool_t emulate_reflect = FALSE; - double offset = 0.0; - - cairo_extend_t extend = pattern->extend; - - cairo_gradient_pattern_t *gpat = (cairo_gradient_pattern_t *) pattern; - - if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR) { - cairo_linear_pattern_t *lpat = (cairo_linear_pattern_t *) pattern; - grad = new QLinearGradient (lpat->pd1.x, lpat->pd1.y, - lpat->pd2.x, lpat->pd2.y); - } else if (pattern->type == CAIRO_PATTERN_TYPE_RADIAL) { - cairo_radial_pattern_t *rpat = (cairo_radial_pattern_t *) pattern; - - /* Based on the SVG surface code */ - - cairo_circle_double_t *c0, *c1; - double x0, y0, r0, x1, y1, r1; - - if (rpat->cd1.radius < rpat->cd2.radius) { - c0 = &rpat->cd1; - c1 = &rpat->cd2; - reverse_stops = FALSE; - } else { - c0 = &rpat->cd2; - c1 = &rpat->cd1; - reverse_stops = TRUE; - } - - x0 = c0->center.x; - y0 = c0->center.y; - r0 = c0->radius; - x1 = c1->center.x; - y1 = c1->center.y; - r1 = c1->radius; - - if (r0 == r1) { - grad = new QRadialGradient (x1, y1, r1, x1, y1); - } else { - double fx = (r1 * x0 - r0 * x1) / (r1 - r0); - double fy = (r1 * y0 - r0 * y1) / (r1 - r0); - - /* QPainter doesn't support the inner circle and use instead a gradient focal. - * That means we need to emulate the cairo behaviour by processing the - * cairo gradient stops. - * The CAIRO_EXTENT_NONE and CAIRO_EXTENT_PAD modes are quite easy to handle, - * it's just a matter of stop position translation and calculation of - * the corresponding SVG radial gradient focal. - * The CAIRO_EXTENT_REFLECT and CAIRO_EXTEND_REPEAT modes require to compute a new - * radial gradient, with an new outer circle, equal to r1 - r0 in the CAIRO_EXTEND_REPEAT - * case, and 2 * (r1 - r0) in the CAIRO_EXTENT_REFLECT case, and a new gradient stop - * list that maps to the original cairo stop list. - */ - if ((extend == CAIRO_EXTEND_REFLECT || extend == CAIRO_EXTEND_REPEAT) && r0 > 0.0) { - double r_org = r1; - double r, x, y; - - if (extend == CAIRO_EXTEND_REFLECT) { - r1 = 2 * r1 - r0; - emulate_reflect = TRUE; - } - - offset = fmod (r1, r1 - r0) / (r1 - r0) - 1.0; - r = r1 - r0; - - /* New position of outer circle. */ - x = r * (x1 - fx) / r_org + fx; - y = r * (y1 - fy) / r_org + fy; - - x1 = x; - y1 = y; - r1 = r; - r0 = 0.0; - } else { - offset = r0 / r1; - } - - grad = new QRadialGradient (x1, y1, r1, fx, fy); - - if (extend == CAIRO_EXTEND_NONE && r0 != 0.0) - grad->setColorAt (r0 / r1, Qt::transparent); - } - } - - switch (extend) { - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_PAD: - grad->setSpread(QGradient::PadSpread); - - grad->setColorAt (0.0, Qt::transparent); - grad->setColorAt (1.0, Qt::transparent); - break; - - case CAIRO_EXTEND_REFLECT: - grad->setSpread(QGradient::ReflectSpread); - break; - - case CAIRO_EXTEND_REPEAT: - grad->setSpread(QGradient::RepeatSpread); - break; - } - - for (unsigned int i = 0; i < gpat->n_stops; i++) { - int index = i; - if (reverse_stops) - index = gpat->n_stops - i - 1; - - double offset = gpat->stops[i].offset; - QColor color; - color.setRgbF (gpat->stops[i].color.red, - gpat->stops[i].color.green, - gpat->stops[i].color.blue, - gpat->stops[i].color.alpha); - - if (emulate_reflect) { - offset = offset / 2.0; - grad->setColorAt (1.0 - offset, color); - } - - grad->setColorAt (offset, color); - } - - mBrush = QBrush(*grad); - - delete grad; - } - - if (mBrush.style() != Qt::NoBrush && - pattern->type != CAIRO_PATTERN_TYPE_SOLID && - ! _cairo_matrix_is_identity (&pattern->matrix)) - { - cairo_matrix_t pm = pattern->matrix; - cairo_status_t status = cairo_matrix_invert (&pm); - assert (status == CAIRO_STATUS_SUCCESS); - mBrush.setMatrix (_qmatrix_from_cairo_matrix (pm)); - } - } - - ~PatternToBrushConverter () __attribute__ ((noinline)){ - if (mAcquiredImageParent) - _cairo_surface_release_source_image (mAcquiredImageParent, mAcquiredImage, mAcquiredImageExtra); - } - - operator QBrush& () { - return mBrush; - } - - QBrush mBrush; - - private: - cairo_surface_t *mAcquiredImageParent; - cairo_image_surface_t *mAcquiredImage; - void *mAcquiredImageExtra; -}; - -struct PatternToPenConverter { - PatternToPenConverter (const cairo_pattern_t *source, - const cairo_stroke_style_t *style) : - mBrushConverter(source) - { - Qt::PenJoinStyle join = Qt::MiterJoin; - Qt::PenCapStyle cap = Qt::SquareCap; - - switch (style->line_cap) { - case CAIRO_LINE_CAP_BUTT: - cap = Qt::FlatCap; - break; - case CAIRO_LINE_CAP_ROUND: - cap = Qt::RoundCap; - break; - case CAIRO_LINE_CAP_SQUARE: - cap = Qt::SquareCap; - break; - } - - switch (style->line_join) { - case CAIRO_LINE_JOIN_MITER: - join = Qt::MiterJoin; - break; - case CAIRO_LINE_JOIN_ROUND: - join = Qt::RoundJoin; - break; - case CAIRO_LINE_JOIN_BEVEL: - join = Qt::BevelJoin; - break; - } - - mPen = QPen(mBrushConverter, style->line_width, Qt::SolidLine, cap, join); - mPen.setMiterLimit (style->miter_limit); - - if (style->dash && style->num_dashes) { - Qt::PenStyle pstyle = Qt::NoPen; - - if (style->num_dashes == 2) { - if ((style->dash[0] == style->line_width && - style->dash[1] == style->line_width && style->line_width <= 2.0) || - (style->dash[0] == 0.0 && - style->dash[1] == style->line_width * 2 && cap == Qt::RoundCap)) - { - pstyle = Qt::DotLine; - } else if (style->dash[0] == style->line_width * DASH_LENGTH && - style->dash[1] == style->line_width * DASH_LENGTH && - cap == Qt::FlatCap) - { - pstyle = Qt::DashLine; - } - } - - if (pstyle != Qt::NoPen) { - mPen.setStyle(pstyle); - return; - } - - unsigned int odd_dash = style->num_dashes % 2; - - QVector dashes (odd_dash ? style->num_dashes * 2 : style->num_dashes); - for (unsigned int i = 0; i < odd_dash+1; i++) { - for (unsigned int j = 0; j < style->num_dashes; j++) { - // In Qt, the dash lengths are given in units of line width, whereas - // in cairo, they are in user-space units. We'll always apply the CTM, - // so all we have to do here is divide cairo's dash lengths by the line - // width. - dashes.append (style->dash[j] / style->line_width); - } - } - - mPen.setDashPattern(dashes); - mPen.setDashOffset(style->dash_offset / style->line_width); - } - } - - ~PatternToPenConverter() { } - - operator QPen& () { - return mPen; - } - - QPen mPen; - PatternToBrushConverter mBrushConverter; -}; - -/* - * Core drawing operations - */ - -static bool -_cairo_qt_fast_fill (cairo_qt_surface_t *qs, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path = NULL, - cairo_fill_rule_t fill_rule = CAIRO_FILL_RULE_WINDING, - double tolerance = 0.0, - cairo_antialias_t antialias = CAIRO_ANTIALIAS_NONE) -{ -#if ENABLE_FAST_FILL - QImage *qsSrc_image = NULL; - QPixmap *qsSrc_pixmap = NULL; - std::auto_ptr qsSrc_image_d; - - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t*) source; - if (spattern->surface->type == CAIRO_SURFACE_TYPE_QT) { - cairo_qt_surface_t *p = (cairo_qt_surface_t*) spattern->surface; - - qsSrc_image = p->image; - qsSrc_pixmap = p->pixmap; - } else if (spattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE) { - cairo_image_surface_t *p = (cairo_image_surface_t*) spattern->surface; - qsSrc_image = new QImage((const uchar*) p->data, - p->width, - p->height, - p->stride, - _qimage_format_from_cairo_format(p->format)); - qsSrc_image_d.reset(qsSrc_image); - } - } - - if (!qsSrc_image && !qsSrc_pixmap) - return false; - - // We can only drawTiledPixmap; there's no drawTiledImage - if (! qsSrc_pixmap && - (source->extend == CAIRO_EXTEND_REPEAT || - source->extend == CAIRO_EXTEND_REFLECT)) - { - return false; - } - - QMatrix sourceMatrix = _qmatrix_from_cairo_matrix (source->matrix); - - // We can draw this faster by clipping and calling drawImage/drawPixmap. - // Use our own clipping function so that we can get the - // region handling to end up with the fastest possible clip. - // - // XXX Antialiasing will fail pretty hard here, since we can't clip with AA - // with QPainter. - qs->p->save(); - - if (path) { - cairo_int_status_t status; - - cairo_clip_t clip, old_clip = qs->clipper.clip; - - _cairo_clip_init_copy (&clip, &qs->clipper.clip); - status = (cairo_int_status_t) _cairo_clip_clip (&clip, - path, - fill_rule, - tolerance, - antialias); - if (unlikely (status)) { - qs->p->restore(); - return false; - } - - status = _cairo_qt_surface_set_clip (qs, &clip); - if (unlikely (status)) { - qs->p->restore(); - return false; - } - - _cairo_clip_reset (&clip); - qs->clipper.clip = old_clip; - } - - qs->p->setWorldMatrix (sourceMatrix.inverted(), true); - - switch (source->extend) { - case CAIRO_EXTEND_REPEAT: - // XXX handle reflect by tiling 4 times first - case CAIRO_EXTEND_REFLECT: { - assert (qsSrc_pixmap); - - // Render the tiling to cover the entire destination window (because - // it'll be clipped). Transform the window rect by the inverse - // of the current world transform so that the device coordinates - // end up as the right thing. - QRectF dest = qs->p->worldTransform().inverted().mapRect(QRectF(qs->window)); - QPointF origin = sourceMatrix.map(QPointF(0.0, 0.0)); - - qs->p->drawTiledPixmap (dest, *qsSrc_pixmap, origin); - } - break; - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_PAD: // XXX not exactly right, but good enough - default: - if (qsSrc_image) - qs->p->drawImage (0, 0, *qsSrc_image); - else if (qsSrc_pixmap) - qs->p->drawPixmap (0, 0, *qsSrc_pixmap); - break; - } - - qs->p->restore(); - - return true; -#else - return false; -#endif -} - -static cairo_int_status_t -_cairo_qt_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - cairo_int_status_t status; - - D(fprintf(stderr, "q[%p] paint op:%s\n", abstract_surface, _opstr(op))); - - if (! _op_is_supported (qs, op)) - return _cairo_surface_fallback_paint (abstract_surface, op, source, clip); - - status = _cairo_qt_surface_set_clip (qs, clip); - if (unlikely (status)) - return status; - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op)); - - if (! _cairo_qt_fast_fill (qs, source)) { - PatternToBrushConverter brush (source); - qs->p->fillRect (qs->window, brush); - } - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_qt_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] fill op:%s\n", abstract_surface, _opstr(op))); - - if (! _op_is_supported (qs, op)) - return _cairo_surface_fallback_fill (abstract_surface, op, - source, path, fill_rule, - tolerance, antialias, clip); - - cairo_int_status_t status = _cairo_qt_surface_set_clip (qs, clip); - if (unlikely (status)) - return status; - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op)); - - // XXX Qt4.3, 4.4 misrenders some complex paths if antialiasing is - // enabled - //qs->p->setRenderHint (QPainter::Antialiasing, antialias == CAIRO_ANTIALIAS_NONE ? false : true); - qs->p->setRenderHint (QPainter::SmoothPixmapTransform, source->filter != CAIRO_FILTER_FAST); - - if (! _cairo_qt_fast_fill (qs, source, - path, fill_rule, tolerance, antialias)) - { - PatternToBrushConverter brush(source); - qs->p->fillPath (path_to_qt (path, fill_rule), brush); - } - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_qt_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] stroke op:%s\n", abstract_surface, _opstr(op))); - - if (! _op_is_supported (qs, op)) - return _cairo_surface_fallback_stroke (abstract_surface, op, - source, path, style, ctm, - ctm_inverse, tolerance, - antialias, clip); - - cairo_int_status_t int_status = _cairo_qt_surface_set_clip (qs, clip); - if (unlikely (int_status)) - return int_status; - - QMatrix savedMatrix = qs->p->worldMatrix(); - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op)); - - qs->p->setWorldMatrix (_qmatrix_from_cairo_matrix (*ctm), true); - // XXX Qt4.3, 4.4 misrenders some complex paths if antialiasing is - // enabled - //qs->p->setRenderHint (QPainter::Antialiasing, antialias == CAIRO_ANTIALIAS_NONE ? false : true); - qs->p->setRenderHint (QPainter::SmoothPixmapTransform, source->filter != CAIRO_FILTER_FAST); - - PatternToPenConverter pen(source, style); - - qs->p->setPen(pen); - qs->p->drawPath(path_to_qt (path, ctm_inverse)); - qs->p->setPen(Qt::black); - - qs->p->setWorldMatrix (savedMatrix, false); - - if (qs->supports_porter_duff) - qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_qt_surface_show_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ -#if ((QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) || defined(QT_GLYPHS_API_BACKPORT)) && 0 - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - // pick out the colour to use from the cairo source - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) source; - cairo_scaled_glyph_t* glyph; - // documentation says you have to freeze the cache, but I don't believe it - _cairo_scaled_font_freeze_cache(scaled_font); - - QColor tempColour(solid->color.red * 255, solid->color.green * 255, solid->color.blue * 255); - QVarLengthArray positions(num_glyphs); - QVarLengthArray glyphss(num_glyphs); - FT_Face face = cairo_ft_scaled_font_lock_face (scaled_font); - const FT_Size_Metrics& ftMetrics = face->size->metrics; - QFont font(face->family_name); - font.setStyleStrategy(QFont::NoFontMerging); - font.setBold(face->style_flags & FT_STYLE_FLAG_BOLD); - font.setItalic(face->style_flags & FT_STYLE_FLAG_ITALIC); - font.setKerning(face->face_flags & FT_FACE_FLAG_KERNING); - font.setPixelSize(ftMetrics.y_ppem); - cairo_ft_scaled_font_unlock_face(scaled_font); - qs->p->setFont(font); - qs->p->setPen(tempColour); - for (int currentGlyph = 0; currentGlyph < num_glyphs; currentGlyph++) { - positions[currentGlyph].setX(glyphs[currentGlyph].x); - positions[currentGlyph].setY(glyphs[currentGlyph].y); - glyphss[currentGlyph] = glyphs[currentGlyph].index; - } - qt_draw_glyphs(qs->p, glyphss.data(), positions.data(), num_glyphs); - _cairo_scaled_font_thaw_cache(scaled_font); - return CAIRO_INT_STATUS_SUCCESS; -#else - return _cairo_surface_fallback_glyphs (abstract_surface, op, - source, glyphs, num_glyphs, - scaled_font, clip); -#endif -} - -static cairo_int_status_t -_cairo_qt_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - D(fprintf(stderr, "q[%p] mask op:%s\n", abstract_surface, _opstr(op))); - - if (qs->p && mask->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid_mask = (cairo_solid_pattern_t *) mask; - cairo_int_status_t result; - - qs->p->setOpacity (solid_mask->color.alpha); - - result = _cairo_qt_surface_paint (abstract_surface, op, source, clip); - - qs->p->setOpacity (1.0); - - return result; - } - - // otherwise skip for now - return _cairo_surface_fallback_mask (abstract_surface, op, source, mask, clip); -} - -static cairo_status_t -_cairo_qt_surface_mark_dirty (void *abstract_surface, - int x, int y, - int width, int height) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; - - if (qs->p && !(qs->image || qs->pixmap)) - qs->p->save (); - - return CAIRO_STATUS_SUCCESS; -} - -/* - * Backend struct - */ - -static const cairo_surface_backend_t cairo_qt_surface_backend = { - CAIRO_SURFACE_TYPE_QT, - _cairo_qt_surface_finish, - - _cairo_default_context_create, /* XXX */ - - _cairo_qt_surface_create_similar, - NULL, /* similar image */ - _cairo_qt_surface_map_to_image, - _cairo_qt_surface_unmap_image, - - _cairo_surface_default_source, - _cairo_qt_surface_acquire_source_image, - _cairo_qt_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_qt_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - _cairo_qt_surface_mark_dirty, - - _cairo_qt_surface_paint, - _cairo_qt_surface_mask, - _cairo_qt_surface_stroke, - _cairo_qt_surface_fill, - NULL, /* fill_stroke */ - _cairo_qt_surface_show_glyphs -}; - -cairo_surface_t * -cairo_qt_surface_create (QPainter *painter) -{ - cairo_qt_surface_t *qs; - - qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); - if (qs == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - memset (qs, 0, sizeof(cairo_qt_surface_t)); - - _cairo_surface_init (&qs->base, - &cairo_qt_surface_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - _cairo_surface_clipper_init (&qs->clipper, - _cairo_qt_surface_clipper_intersect_clip_path); - - qs->p = painter; - if (qs->p->paintEngine()) - qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); - else - qs->supports_porter_duff = FALSE; - - // Save so that we can always get back to the original state - qs->p->save(); - - qs->window = painter->window(); - - D(fprintf(stderr, "qpainter_surface_create: window: [%d %d %d %d] pd:%d\n", - qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), - qs->supports_porter_duff)); - - return &qs->base; -} - -cairo_surface_t * -cairo_qt_surface_create_with_qimage (cairo_format_t format, - int width, - int height) -{ - cairo_qt_surface_t *qs; - - qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); - if (qs == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - memset (qs, 0, sizeof(cairo_qt_surface_t)); - - _cairo_surface_init (&qs->base, - &cairo_qt_surface_backend, - NULL, /* device */ - _cairo_content_from_format (format)); - - _cairo_surface_clipper_init (&qs->clipper, - _cairo_qt_surface_clipper_intersect_clip_path); - - - QImage *image = new QImage (width, height, - _qimage_format_from_cairo_format (format)); - - qs->image = image; - - if (!image->isNull()) { - qs->p = new QPainter(image); - qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); - } - - qs->image_equiv = cairo_image_surface_create_for_data (image->bits(), - format, - width, height, - image->bytesPerLine()); - - qs->window = QRect(0, 0, width, height); - - D(fprintf(stderr, "qpainter_surface_create: qimage: [%d %d %d %d] pd:%d\n", - qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), - qs->supports_porter_duff)); - - return &qs->base; -} - -cairo_surface_t * -cairo_qt_surface_create_with_qpixmap (cairo_content_t content, - int width, - int height) -{ - cairo_qt_surface_t *qs; - - if ((content & CAIRO_CONTENT_COLOR) == 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); - - qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); - if (qs == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - memset (qs, 0, sizeof(cairo_qt_surface_t)); - - QPixmap *pixmap = new QPixmap (width, height); - if (pixmap == NULL) { - free (qs); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - // By default, a QPixmap is opaque; however, if it's filled - // with a color with a transparency component, it is converted - // to a format that preserves transparency. - if (content == CAIRO_CONTENT_COLOR_ALPHA) - pixmap->fill(Qt::transparent); - - _cairo_surface_init (&qs->base, - &cairo_qt_surface_backend, - NULL, /* device */ - content); - - _cairo_surface_clipper_init (&qs->clipper, - _cairo_qt_surface_clipper_intersect_clip_path); - - qs->pixmap = pixmap; - - if (!pixmap->isNull()) { - qs->p = new QPainter(pixmap); - qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); - } - - qs->window = QRect(0, 0, width, height); - - D(fprintf(stderr, "qpainter_surface_create: qpixmap: [%d %d %d %d] pd:%d\n", - qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), - qs->supports_porter_duff)); - - return &qs->base; -} - -/** - * _cairo_surface_is_qt: - * @surface: a #cairo_surface_t - * - * Checks if a surface is a #cairo_qt_surface_t - * - * Return value: True if the surface is an qt surface - **/ -static inline cairo_bool_t -_cairo_surface_is_qt (cairo_surface_t *surface) -{ - return surface->backend == &cairo_qt_surface_backend; -} - -QPainter * -cairo_qt_surface_get_qpainter (cairo_surface_t *surface) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; - - /* Throw an error for a non-qt surface */ - if (! _cairo_surface_is_qt (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return qs->p; -} - -QImage * -cairo_qt_surface_get_qimage (cairo_surface_t *surface) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; - - /* Throw an error for a non-qt surface */ - if (! _cairo_surface_is_qt (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return qs->image; -} - -cairo_surface_t * -cairo_qt_surface_get_image (cairo_surface_t *surface) -{ - cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; - - /* Throw an error for a non-qt surface */ - if (! _cairo_surface_is_qt (surface)) { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - } - - return qs->image_equiv; -} - -/* - * TODO: - * - * - Figure out why QBrush isn't working with non-repeated images - * - * - Correct repeat mode; right now, every surface source is EXTEND_REPEAT - * - implement EXTEND_NONE (?? probably need to clip to the extents of the source) - * - implement EXTEND_REFLECT (create temporary and copy 4x, then EXTEND_REPEAT that) - * - * - stroke-image failure - * - * - Implement mask() with non-solid masks (probably will need to use a temporary and use IN) - * - * - Implement gradient sources - * - * - Make create_similar smarter -- create QPixmaps in more circumstances - * (e.g. if the pixmap can have alpha) - * - * - Implement show_glyphs() in terms of Qt - * - */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt.h deleted file mode 100644 index c20bbb18d0b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-qt.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Corporation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#ifndef CAIRO_QT_H -#define CAIRO_QT_H - -#include "cairo.h" - -#if CAIRO_HAS_QT_SURFACE - -#include -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_qt_surface_create (QPainter *painter); - -cairo_public cairo_surface_t * -cairo_qt_surface_create_with_qimage (cairo_format_t format, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_qt_surface_create_with_qpixmap (cairo_content_t content, - int width, - int height); - -cairo_public QPainter * -cairo_qt_surface_get_qpainter (cairo_surface_t *surface); - -/* XXX needs hooking to generic surface layer, my vote is for -cairo_public cairo_surface_t * -cairo_surface_map_image (cairo_surface_t *surface); -cairo_public void -cairo_surface_unmap_image (cairo_surface_t *surface, cairo_surface_t *image); -*/ -cairo_public cairo_surface_t * -cairo_qt_surface_get_image (cairo_surface_t *surface); - -cairo_public QImage * -cairo_qt_surface_get_qimage (cairo_surface_t *surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_QT_SURFACE */ - -# error Cairo was not compiled with support for the Qt backend - -#endif /* CAIRO_HAS_QT_SURFACE */ - -#endif /* CAIRO_QT_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-font.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-font.c deleted file mode 100644 index 02f34267b18..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-font.c +++ /dev/null @@ -1,859 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright � 2008 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#include "cairoint.h" - -#include - -#include "cairo-image-surface-private.h" -#include "cairo-quartz.h" -#include "cairo-quartz-private.h" - -#include "cairo-error-private.h" - -/** - * SECTION:cairo-quartz-fonts - * @Title: Quartz (CGFont) Fonts - * @Short_Description: Font support via CGFont on OS X - * @See_Also: #cairo_font_face_t - * - * The Quartz font backend is primarily used to render text on Apple - * MacOS X systems. The CGFont API is used for the internal - * implementation of the font backend methods. - **/ - -/** - * CAIRO_HAS_QUARTZ_FONT: - * - * Defined if the Quartz font backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.6 - **/ - -static CFDataRef (*CGFontCopyTableForTagPtr) (CGFontRef font, uint32_t tag) = NULL; - -/* CreateWithFontName exists in 10.5, but not in 10.4; CreateWithName isn't public in 10.4 */ -static CGFontRef (*CGFontCreateWithFontNamePtr) (CFStringRef) = NULL; -static CGFontRef (*CGFontCreateWithNamePtr) (const char *) = NULL; - -/* These aren't public before 10.5, and some have different names in 10.4 */ -static int (*CGFontGetUnitsPerEmPtr) (CGFontRef) = NULL; -static bool (*CGFontGetGlyphAdvancesPtr) (CGFontRef, const CGGlyph[], size_t, int[]) = NULL; -static bool (*CGFontGetGlyphBBoxesPtr) (CGFontRef, const CGGlyph[], size_t, CGRect[]) = NULL; -static CGRect (*CGFontGetFontBBoxPtr) (CGFontRef) = NULL; - -/* Not public, but present */ -static void (*CGFontGetGlyphsForUnicharsPtr) (CGFontRef, const UniChar[], const CGGlyph[], size_t) = NULL; -static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; -static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; - -/* CGFontGetHMetrics isn't public, but the other functions are public/present in 10.5 */ -typedef struct { - int ascent; - int descent; - int leading; -} quartz_CGFontMetrics; -static quartz_CGFontMetrics* (*CGFontGetHMetricsPtr) (CGFontRef fontRef) = NULL; -static int (*CGFontGetAscentPtr) (CGFontRef fontRef) = NULL; -static int (*CGFontGetDescentPtr) (CGFontRef fontRef) = NULL; -static int (*CGFontGetLeadingPtr) (CGFontRef fontRef) = NULL; - -/* Not public anymore in 64-bits nor in 10.7 */ -static ATSFontRef (*FMGetATSFontRefFromFontPtr) (FMFont iFont) = NULL; - -static cairo_bool_t _cairo_quartz_font_symbol_lookup_done = FALSE; -static cairo_bool_t _cairo_quartz_font_symbols_present = FALSE; - -static void -quartz_font_ensure_symbols(void) -{ - if (_cairo_quartz_font_symbol_lookup_done) - return; - - CGFontCopyTableForTagPtr = dlsym(RTLD_DEFAULT, "CGFontCopyTableForTag"); - - /* Look for the 10.5 versions first */ - CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBBoxes"); - if (!CGFontGetGlyphBBoxesPtr) - CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBoundingBoxes"); - - CGFontGetGlyphsForUnicharsPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnichars"); - if (!CGFontGetGlyphsForUnicharsPtr) - CGFontGetGlyphsForUnicharsPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnicodes"); - - CGFontGetFontBBoxPtr = dlsym(RTLD_DEFAULT, "CGFontGetFontBBox"); - - /* We just need one of these two */ - CGFontCreateWithFontNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithFontName"); - CGFontCreateWithNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithName"); - - /* These have the same name in 10.4 and 10.5 */ - CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm"); - CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphAdvances"); - - CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics"); - CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent"); - CGFontGetDescentPtr = dlsym(RTLD_DEFAULT, "CGFontGetDescent"); - CGFontGetLeadingPtr = dlsym(RTLD_DEFAULT, "CGFontGetLeading"); - - CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing"); - CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing"); - - FMGetATSFontRefFromFontPtr = dlsym(RTLD_DEFAULT, "FMGetATSFontRefFromFont"); - - if ((CGFontCreateWithFontNamePtr || CGFontCreateWithNamePtr) && - CGFontGetGlyphBBoxesPtr && - CGFontGetGlyphsForUnicharsPtr && - CGFontGetUnitsPerEmPtr && - CGFontGetGlyphAdvancesPtr && - (CGFontGetHMetricsPtr || (CGFontGetAscentPtr && CGFontGetDescentPtr && CGFontGetLeadingPtr))) - _cairo_quartz_font_symbols_present = TRUE; - - _cairo_quartz_font_symbol_lookup_done = TRUE; -} - -typedef struct _cairo_quartz_font_face cairo_quartz_font_face_t; -typedef struct _cairo_quartz_scaled_font cairo_quartz_scaled_font_t; - -struct _cairo_quartz_scaled_font { - cairo_scaled_font_t base; -}; - -struct _cairo_quartz_font_face { - cairo_font_face_t base; - - CGFontRef cgFont; -}; - -/* - * font face backend - */ - -static cairo_status_t -_cairo_quartz_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, - cairo_font_face_t **font_face) -{ - const char *family; - char *full_name; - CFStringRef cgFontName = NULL; - CGFontRef cgFont = NULL; - int loop; - - quartz_font_ensure_symbols(); - if (! _cairo_quartz_font_symbols_present) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - family = toy_face->family; - full_name = malloc (strlen (family) + 64); // give us a bit of room to tack on Bold, Oblique, etc. - /* handle CSS-ish faces */ - if (!strcmp(family, "serif") || !strcmp(family, "Times Roman")) - family = "Times"; - else if (!strcmp(family, "sans-serif") || !strcmp(family, "sans")) - family = "Helvetica"; - else if (!strcmp(family, "cursive")) - family = "Apple Chancery"; - else if (!strcmp(family, "fantasy")) - family = "Papyrus"; - else if (!strcmp(family, "monospace") || !strcmp(family, "mono")) - family = "Courier"; - - /* Try to build up the full name, e.g. "Helvetica Bold Oblique" first, - * then drop the bold, then drop the slant, then drop both.. finally - * just use "Helvetica". And if Helvetica doesn't exist, give up. - */ - for (loop = 0; loop < 5; loop++) { - if (loop == 4) - family = "Helvetica"; - - strcpy (full_name, family); - - if (loop < 3 && (loop & 1) == 0) { - if (toy_face->weight == CAIRO_FONT_WEIGHT_BOLD) - strcat (full_name, " Bold"); - } - - if (loop < 3 && (loop & 2) == 0) { - if (toy_face->slant == CAIRO_FONT_SLANT_ITALIC) - strcat (full_name, " Italic"); - else if (toy_face->slant == CAIRO_FONT_SLANT_OBLIQUE) - strcat (full_name, " Oblique"); - } - - if (CGFontCreateWithFontNamePtr) { - cgFontName = CFStringCreateWithCString (NULL, full_name, kCFStringEncodingASCII); - cgFont = CGFontCreateWithFontNamePtr (cgFontName); - CFRelease (cgFontName); - } else { - cgFont = CGFontCreateWithNamePtr (full_name); - } - - if (cgFont) - break; - } - - if (!cgFont) { - /* Give up */ - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - *font_face = cairo_quartz_font_face_create_for_cgfont (cgFont); - CGFontRelease (cgFont); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_quartz_font_face_destroy (void *abstract_face) -{ - cairo_quartz_font_face_t *font_face = (cairo_quartz_font_face_t*) abstract_face; - - CGFontRelease (font_face->cgFont); - return TRUE; -} - -static const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend; - -static cairo_status_t -_cairo_quartz_font_face_scaled_font_create (void *abstract_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - cairo_scaled_font_t **font_out) -{ - cairo_quartz_font_face_t *font_face = abstract_face; - cairo_quartz_scaled_font_t *font = NULL; - cairo_status_t status; - cairo_font_extents_t fs_metrics; - double ems; - CGRect bbox; - - quartz_font_ensure_symbols(); - if (!_cairo_quartz_font_symbols_present) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font = malloc(sizeof(cairo_quartz_scaled_font_t)); - if (font == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memset (font, 0, sizeof(cairo_quartz_scaled_font_t)); - - status = _cairo_scaled_font_init (&font->base, - &font_face->base, font_matrix, ctm, options, - &_cairo_quartz_scaled_font_backend); - if (status) - goto FINISH; - - ems = CGFontGetUnitsPerEmPtr (font_face->cgFont); - - /* initialize metrics */ - if (CGFontGetFontBBoxPtr && CGFontGetAscentPtr) { - fs_metrics.ascent = (CGFontGetAscentPtr (font_face->cgFont) / ems); - fs_metrics.descent = - (CGFontGetDescentPtr (font_face->cgFont) / ems); - fs_metrics.height = fs_metrics.ascent + fs_metrics.descent + - (CGFontGetLeadingPtr (font_face->cgFont) / ems); - - bbox = CGFontGetFontBBoxPtr (font_face->cgFont); - fs_metrics.max_x_advance = CGRectGetMaxX(bbox) / ems; - fs_metrics.max_y_advance = 0.0; - } else { - CGGlyph wGlyph; - UniChar u; - - quartz_CGFontMetrics *m; - m = CGFontGetHMetricsPtr (font_face->cgFont); - - /* On OX 10.4, GetHMetricsPtr sometimes returns NULL for unknown reasons */ - if (!m) { - status = _cairo_error(CAIRO_STATUS_NULL_POINTER); - goto FINISH; - } - - fs_metrics.ascent = (m->ascent / ems); - fs_metrics.descent = - (m->descent / ems); - fs_metrics.height = fs_metrics.ascent + fs_metrics.descent + (m->leading / ems); - - /* We kind of have to guess here; W's big, right? */ - u = (UniChar) 'W'; - CGFontGetGlyphsForUnicharsPtr (font_face->cgFont, &u, &wGlyph, 1); - if (wGlyph && CGFontGetGlyphBBoxesPtr (font_face->cgFont, &wGlyph, 1, &bbox)) { - fs_metrics.max_x_advance = CGRectGetMaxX(bbox) / ems; - fs_metrics.max_y_advance = 0.0; - } else { - fs_metrics.max_x_advance = 0.0; - fs_metrics.max_y_advance = 0.0; - } - } - - status = _cairo_scaled_font_set_metrics (&font->base, &fs_metrics); - -FINISH: - if (status != CAIRO_STATUS_SUCCESS) { - free (font); - } else { - *font_out = (cairo_scaled_font_t*) font; - } - - return status; -} - -const cairo_font_face_backend_t _cairo_quartz_font_face_backend = { - CAIRO_FONT_TYPE_QUARTZ, - _cairo_quartz_font_face_create_for_toy, - _cairo_quartz_font_face_destroy, - _cairo_quartz_font_face_scaled_font_create -}; - -/** - * cairo_quartz_font_face_create_for_cgfont: - * @font: a #CGFontRef obtained through a method external to cairo. - * - * Creates a new font for the Quartz font backend based on a - * #CGFontRef. This font can then be used with - * cairo_set_font_face() or cairo_scaled_font_create(). - * - * Return value: a newly created #cairo_font_face_t. Free with - * cairo_font_face_destroy() when you are done using it. - * - * Since: 1.6 - **/ -cairo_font_face_t * -cairo_quartz_font_face_create_for_cgfont (CGFontRef font) -{ - cairo_quartz_font_face_t *font_face; - - quartz_font_ensure_symbols(); - - font_face = malloc (sizeof (cairo_quartz_font_face_t)); - if (!font_face) { - cairo_status_t ignore_status; - ignore_status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *)&_cairo_font_face_nil; - } - - font_face->cgFont = CGFontRetain (font); - - _cairo_font_face_init (&font_face->base, &_cairo_quartz_font_face_backend); - - return &font_face->base; -} - -/* - * scaled font backend - */ - -static cairo_quartz_font_face_t * -_cairo_quartz_scaled_to_face (void *abstract_font) -{ - cairo_quartz_scaled_font_t *sfont = (cairo_quartz_scaled_font_t*) abstract_font; - cairo_font_face_t *font_face = sfont->base.font_face; - assert (font_face->backend->type == CAIRO_FONT_TYPE_QUARTZ); - return (cairo_quartz_font_face_t*) font_face; -} - -static void -_cairo_quartz_scaled_font_fini(void *abstract_font) -{ -} - -#define INVALID_GLYPH 0x00 - -static inline CGGlyph -_cairo_quartz_scaled_glyph_index (cairo_scaled_glyph_t *scaled_glyph) { - unsigned long index = _cairo_scaled_glyph_index (scaled_glyph); - if (index > 0xffff) - return INVALID_GLYPH; - return (CGGlyph) index; -} - -static cairo_int_status_t -_cairo_quartz_init_glyph_metrics (cairo_quartz_scaled_font_t *font, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - - cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); - cairo_text_extents_t extents = {0, 0, 0, 0, 0, 0}; - CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); - int advance; - CGRect bbox; - double emscale = CGFontGetUnitsPerEmPtr (font_face->cgFont); - double xmin, ymin, xmax, ymax; - - if (glyph == INVALID_GLYPH) - goto FAIL; - - if (!CGFontGetGlyphAdvancesPtr (font_face->cgFont, &glyph, 1, &advance) || - !CGFontGetGlyphBBoxesPtr (font_face->cgFont, &glyph, 1, &bbox)) - goto FAIL; - - /* broken fonts like Al Bayan return incorrect bounds for some null characters, - see https://bugzilla.mozilla.org/show_bug.cgi?id=534260 */ - if (unlikely (bbox.origin.x == -32767 && - bbox.origin.y == -32767 && - bbox.size.width == 65534 && - bbox.size.height == 65534)) { - bbox.origin.x = bbox.origin.y = 0; - bbox.size.width = bbox.size.height = 0; - } - - bbox = CGRectMake (bbox.origin.x / emscale, - bbox.origin.y / emscale, - bbox.size.width / emscale, - bbox.size.height / emscale); - - /* Should we want to always integer-align glyph extents, we can do so in this way */ -#if 0 - { - CGAffineTransform textMatrix; - textMatrix = CGAffineTransformMake (font->base.scale.xx, - -font->base.scale.yx, - -font->base.scale.xy, - font->base.scale.yy, - 0.0f, 0.0f); - - bbox = CGRectApplyAffineTransform (bbox, textMatrix); - bbox = CGRectIntegral (bbox); - bbox = CGRectApplyAffineTransform (bbox, CGAffineTransformInvert (textMatrix)); - } -#endif - -#if 0 - fprintf (stderr, "[0x%04x] bbox: %f %f %f %f\n", glyph, - bbox.origin.x / emscale, bbox.origin.y / emscale, - bbox.size.width / emscale, bbox.size.height / emscale); -#endif - - xmin = CGRectGetMinX(bbox); - ymin = CGRectGetMinY(bbox); - xmax = CGRectGetMaxX(bbox); - ymax = CGRectGetMaxY(bbox); - - extents.x_bearing = xmin; - extents.y_bearing = - ymax; - extents.width = xmax - xmin; - extents.height = ymax - ymin; - - extents.x_advance = (double) advance / emscale; - extents.y_advance = 0.0; - -#if 0 - fprintf (stderr, "[0x%04x] extents: bearings: %f %f dim: %f %f adv: %f\n\n", glyph, - extents.x_bearing, extents.y_bearing, extents.width, extents.height, extents.x_advance); -#endif - - FAIL: - _cairo_scaled_glyph_set_metrics (scaled_glyph, - &font->base, - &extents); - - return status; -} - -static void -_cairo_quartz_path_apply_func (void *info, const CGPathElement *el) -{ - cairo_path_fixed_t *path = (cairo_path_fixed_t *) info; - cairo_status_t status; - - switch (el->type) { - case kCGPathElementMoveToPoint: - status = _cairo_path_fixed_move_to (path, - _cairo_fixed_from_double(el->points[0].x), - _cairo_fixed_from_double(el->points[0].y)); - assert(!status); - break; - case kCGPathElementAddLineToPoint: - status = _cairo_path_fixed_line_to (path, - _cairo_fixed_from_double(el->points[0].x), - _cairo_fixed_from_double(el->points[0].y)); - assert(!status); - break; - case kCGPathElementAddQuadCurveToPoint: { - cairo_fixed_t fx, fy; - double x, y; - if (!_cairo_path_fixed_get_current_point (path, &fx, &fy)) - fx = fy = 0; - x = _cairo_fixed_to_double (fx); - y = _cairo_fixed_to_double (fy); - - status = _cairo_path_fixed_curve_to (path, - _cairo_fixed_from_double((x + el->points[0].x * 2.0) / 3.0), - _cairo_fixed_from_double((y + el->points[0].y * 2.0) / 3.0), - _cairo_fixed_from_double((el->points[0].x * 2.0 + el->points[1].x) / 3.0), - _cairo_fixed_from_double((el->points[0].y * 2.0 + el->points[1].y) / 3.0), - _cairo_fixed_from_double(el->points[1].x), - _cairo_fixed_from_double(el->points[1].y)); - } - assert(!status); - break; - case kCGPathElementAddCurveToPoint: - status = _cairo_path_fixed_curve_to (path, - _cairo_fixed_from_double(el->points[0].x), - _cairo_fixed_from_double(el->points[0].y), - _cairo_fixed_from_double(el->points[1].x), - _cairo_fixed_from_double(el->points[1].y), - _cairo_fixed_from_double(el->points[2].x), - _cairo_fixed_from_double(el->points[2].y)); - assert(!status); - break; - case kCGPathElementCloseSubpath: - status = _cairo_path_fixed_close_path (path); - assert(!status); - break; - } -} - -static cairo_int_status_t -_cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); - CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); - CGAffineTransform textMatrix; - CGPathRef glyphPath; - CTFontRef ctFont; - cairo_path_fixed_t *path; - - if (glyph == INVALID_GLYPH) { - _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, _cairo_path_fixed_create()); - return CAIRO_STATUS_SUCCESS; - } - - /* scale(1,-1) * font->base.scale */ - textMatrix = CGAffineTransformMake (font->base.scale.xx, - font->base.scale.yx, - -font->base.scale.xy, - -font->base.scale.yy, - 0, 0); - - ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 0.0, NULL, NULL); - glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix); - CFRelease (ctFont); - if (!glyphPath) - return CAIRO_INT_STATUS_UNSUPPORTED; - - path = _cairo_path_fixed_create (); - if (!path) { - CGPathRelease (glyphPath); - return _cairo_error(CAIRO_STATUS_NO_MEMORY); - } - - CGPathApply (glyphPath, path, _cairo_quartz_path_apply_func); - - CGPathRelease (glyphPath); - - _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, path); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - - cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); - - cairo_image_surface_t *surface = NULL; - - CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); - - int advance; - CGRect bbox; - double width, height; - double emscale = CGFontGetUnitsPerEmPtr (font_face->cgFont); - - CGContextRef cgContext = NULL; - CGAffineTransform textMatrix; - CGRect glyphRect, glyphRectInt; - CGPoint glyphOrigin; - - //fprintf (stderr, "scaled_glyph: %p surface: %p\n", scaled_glyph, scaled_glyph->surface); - - /* Create blank 2x2 image if we don't have this character. - * Maybe we should draw a better missing-glyph slug or something, - * but this is ok for now. - */ - if (glyph == INVALID_GLYPH) { - surface = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2); - status = cairo_surface_status ((cairo_surface_t *) surface); - if (status) - return status; - - _cairo_scaled_glyph_set_surface (scaled_glyph, - &font->base, - surface); - return CAIRO_STATUS_SUCCESS; - } - - if (!CGFontGetGlyphAdvancesPtr (font_face->cgFont, &glyph, 1, &advance) || - !CGFontGetGlyphBBoxesPtr (font_face->cgFont, &glyph, 1, &bbox)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* scale(1,-1) * font->base.scale * scale(1,-1) */ - textMatrix = CGAffineTransformMake (font->base.scale.xx, - -font->base.scale.yx, - -font->base.scale.xy, - font->base.scale.yy, - 0, -0); - glyphRect = CGRectMake (bbox.origin.x / emscale, - bbox.origin.y / emscale, - bbox.size.width / emscale, - bbox.size.height / emscale); - - glyphRect = CGRectApplyAffineTransform (glyphRect, textMatrix); - - /* Round the rectangle outwards, so that we don't have to deal - * with non-integer-pixel origins or dimensions. - */ - glyphRectInt = CGRectIntegral (glyphRect); - -#if 0 - fprintf (stderr, "glyphRect[o]: %f %f %f %f\n", - glyphRect.origin.x, glyphRect.origin.y, glyphRect.size.width, glyphRect.size.height); - fprintf (stderr, "glyphRectInt: %f %f %f %f\n", - glyphRectInt.origin.x, glyphRectInt.origin.y, glyphRectInt.size.width, glyphRectInt.size.height); -#endif - - glyphOrigin = glyphRectInt.origin; - - //textMatrix = CGAffineTransformConcat (textMatrix, CGAffineTransformInvert (ctm)); - - width = glyphRectInt.size.width; - height = glyphRectInt.size.height; - - //fprintf (stderr, "glyphRect[n]: %f %f %f %f\n", glyphRect.origin.x, glyphRect.origin.y, glyphRect.size.width, glyphRect.size.height); - - surface = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_A8, width, height); - if (surface->base.status) - return surface->base.status; - - if (surface->width != 0 && surface->height != 0) { - cgContext = CGBitmapContextCreate (surface->data, - surface->width, - surface->height, - 8, - surface->stride, - NULL, - kCGImageAlphaOnly); - - if (cgContext == NULL) { - cairo_surface_destroy (&surface->base); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - CGContextSetFont (cgContext, font_face->cgFont); - CGContextSetFontSize (cgContext, 1.0); - CGContextSetTextMatrix (cgContext, textMatrix); - - switch (font->base.options.antialias) { - case CAIRO_ANTIALIAS_SUBPIXEL: - case CAIRO_ANTIALIAS_BEST: - CGContextSetShouldAntialias (cgContext, TRUE); - CGContextSetShouldSmoothFonts (cgContext, TRUE); - if (CGContextSetAllowsFontSmoothingPtr && - !CGContextGetAllowsFontSmoothingPtr (cgContext)) - CGContextSetAllowsFontSmoothingPtr (cgContext, TRUE); - break; - case CAIRO_ANTIALIAS_NONE: - CGContextSetShouldAntialias (cgContext, FALSE); - break; - case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_GOOD: - case CAIRO_ANTIALIAS_FAST: - CGContextSetShouldAntialias (cgContext, TRUE); - CGContextSetShouldSmoothFonts (cgContext, FALSE); - break; - case CAIRO_ANTIALIAS_DEFAULT: - default: - /* Don't do anything */ - break; - } - - CGContextSetAlpha (cgContext, 1.0); - CGContextShowGlyphsAtPoint (cgContext, - glyphOrigin.x, - glyphOrigin.y, &glyph, 1); - - CGContextRelease (cgContext); - } - - cairo_surface_set_device_offset (&surface->base, - - glyphOrigin.x, - height + glyphOrigin.y); - - _cairo_scaled_glyph_set_surface (scaled_glyph, &font->base, surface); - - return status; -} - -static cairo_int_status_t -_cairo_quartz_scaled_glyph_init (void *abstract_font, - cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_glyph_info_t info) -{ - cairo_quartz_scaled_font_t *font = (cairo_quartz_scaled_font_t *) abstract_font; - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - - if (!status && (info & CAIRO_SCALED_GLYPH_INFO_METRICS)) - status = _cairo_quartz_init_glyph_metrics (font, scaled_glyph); - - if (!status && (info & CAIRO_SCALED_GLYPH_INFO_PATH)) - status = _cairo_quartz_init_glyph_path (font, scaled_glyph); - - if (!status && (info & CAIRO_SCALED_GLYPH_INFO_SURFACE)) - status = _cairo_quartz_init_glyph_surface (font, scaled_glyph); - - return status; -} - -static unsigned long -_cairo_quartz_ucs4_to_index (void *abstract_font, - uint32_t ucs4) -{ - cairo_quartz_scaled_font_t *font = (cairo_quartz_scaled_font_t*) abstract_font; - cairo_quartz_font_face_t *ffont = _cairo_quartz_scaled_to_face(font); - UniChar u = (UniChar) ucs4; - CGGlyph glyph; - - CGFontGetGlyphsForUnicharsPtr (ffont->cgFont, &u, &glyph, 1); - - return glyph; -} - -static cairo_int_status_t -_cairo_quartz_load_truetype_table (void *abstract_font, - unsigned long tag, - long offset, - unsigned char *buffer, - unsigned long *length) -{ - cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face (abstract_font); - CFDataRef data = NULL; - - if (likely (CGFontCopyTableForTagPtr)) - data = CGFontCopyTableForTagPtr (font_face->cgFont, tag); - - if (!data) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (buffer == NULL) { - *length = CFDataGetLength (data); - CFRelease (data); - return CAIRO_STATUS_SUCCESS; - } - - if (CFDataGetLength (data) < offset + (long) *length) { - CFRelease (data); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - CFDataGetBytes (data, CFRangeMake (offset, *length), buffer); - CFRelease (data); - - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend = { - CAIRO_FONT_TYPE_QUARTZ, - _cairo_quartz_scaled_font_fini, - _cairo_quartz_scaled_glyph_init, - NULL, /* text_to_glyphs */ - _cairo_quartz_ucs4_to_index, - _cairo_quartz_load_truetype_table, - NULL, /* map_glyphs_to_unicode */ -}; - -/* - * private methods that the quartz surface uses - */ - -CGFontRef -_cairo_quartz_scaled_font_get_cg_font_ref (cairo_scaled_font_t *abstract_font) -{ - cairo_quartz_font_face_t *ffont = _cairo_quartz_scaled_to_face(abstract_font); - - return ffont->cgFont; -} - -/* - * compat with old ATSUI backend - */ - -/** - * cairo_quartz_font_face_create_for_atsu_font_id: - * @font_id: an ATSUFontID for the font. - * - * Creates a new font for the Quartz font backend based on an - * #ATSUFontID. This font can then be used with - * cairo_set_font_face() or cairo_scaled_font_create(). - * - * Return value: a newly created #cairo_font_face_t. Free with - * cairo_font_face_destroy() when you are done using it. - * - * Since: 1.6 - **/ -cairo_font_face_t * -cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id) -{ - quartz_font_ensure_symbols(); - - if (FMGetATSFontRefFromFontPtr != NULL) { - ATSFontRef atsFont = FMGetATSFontRefFromFontPtr (font_id); - CGFontRef cgFont = CGFontCreateWithPlatformFont (&atsFont); - cairo_font_face_t *ff; - - ff = cairo_quartz_font_face_create_for_cgfont (cgFont); - - CGFontRelease (cgFont); - - return ff; - } else { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *)&_cairo_font_face_nil; - } -} - -/* This is the old name for the above function, exported for compat purposes */ -cairo_font_face_t *cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id); - -cairo_font_face_t * -cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id) -{ - return cairo_quartz_font_face_create_for_atsu_font_id (font_id); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image-surface.c deleted file mode 100644 index 498a7b06436..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image-surface.c +++ /dev/null @@ -1,387 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright � 2008 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#include "cairoint.h" - -#include "cairo-image-surface-inline.h" -#include "cairo-quartz-image.h" -#include "cairo-quartz-private.h" -#include "cairo-surface-backend-private.h" - -#include "cairo-error-private.h" -#include "cairo-default-context-private.h" - -#define SURFACE_ERROR_NO_MEMORY (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_NO_MEMORY))) -#define SURFACE_ERROR_TYPE_MISMATCH (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_SURFACE_TYPE_MISMATCH))) -#define SURFACE_ERROR_INVALID_SIZE (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_INVALID_SIZE))) -#define SURFACE_ERROR_INVALID_FORMAT (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_INVALID_FORMAT))) - -static void -DataProviderReleaseCallback (void *info, const void *data, size_t size) -{ - cairo_surface_t *surface = (cairo_surface_t *) info; - cairo_surface_destroy (surface); -} - -static cairo_surface_t * -_cairo_quartz_image_surface_create_similar (void *asurface, - cairo_content_t content, - int width, - int height) -{ - cairo_surface_t *isurf = - _cairo_image_surface_create_with_content (content, width, height); - cairo_surface_t *result = cairo_quartz_image_surface_create (isurf); - cairo_surface_destroy (isurf); - - return result; -} - -static cairo_surface_t * -_cairo_quartz_image_surface_create_similar_image (void *asurface, - cairo_format_t format, - int width, - int height) -{ - cairo_surface_t *isurf = cairo_image_surface_create (format, width, height); - cairo_surface_t *result = cairo_quartz_image_surface_create (isurf); - cairo_surface_destroy (isurf); - - return result; -} - -static cairo_status_t -_cairo_quartz_image_surface_finish (void *asurface) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; - - /* the imageSurface will be destroyed by the data provider's release callback */ - CGImageRelease (surface->image); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_quartz_image_surface_acquire_source_image (void *asurface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; - - *image_out = surface->imageSurface; - *image_extra = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_image_surface_t * -_cairo_quartz_image_surface_map_to_image (void *asurface, - const cairo_rectangle_int_t *extents) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; - return _cairo_surface_map_to_image (&surface->imageSurface->base, extents); -} - -static cairo_int_status_t -_cairo_quartz_image_surface_unmap_image (void *asurface, - cairo_image_surface_t *image) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; - return _cairo_surface_unmap_image (&surface->imageSurface->base, image); -} - -static cairo_bool_t -_cairo_quartz_image_surface_get_extents (void *asurface, - cairo_rectangle_int_t *extents) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; - - extents->x = 0; - extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - return TRUE; -} - -/* we assume some drawing happened to the image buffer; make sure it's - * represented in the CGImage on flush() - */ - -static cairo_status_t -_cairo_quartz_image_surface_flush (void *asurface, - unsigned flags) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; - CGImageRef oldImage = surface->image; - CGImageRef newImage = NULL; - - if (flags) - return CAIRO_STATUS_SUCCESS; - - /* XXX only flush if the image has been modified. */ - - /* To be released by the ReleaseCallback */ - cairo_surface_reference ((cairo_surface_t*) surface->imageSurface); - - newImage = CairoQuartzCreateCGImage (surface->imageSurface->format, - surface->imageSurface->width, - surface->imageSurface->height, - surface->imageSurface->stride, - surface->imageSurface->data, - TRUE, - NULL, - DataProviderReleaseCallback, - surface->imageSurface); - - surface->image = newImage; - CGImageRelease (oldImage); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_quartz_image_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_quartz_image_surface_t *surface = abstract_surface; - return _cairo_surface_paint (&surface->imageSurface->base, - op, source, clip); -} - -static cairo_int_status_t -_cairo_quartz_image_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_quartz_image_surface_t *surface = abstract_surface; - return _cairo_surface_mask (&surface->imageSurface->base, - op, source, mask, clip); -} - -static cairo_int_status_t -_cairo_quartz_image_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_quartz_image_surface_t *surface = abstract_surface; - return _cairo_surface_stroke (&surface->imageSurface->base, - op, source, path, - style, ctm, ctm_inverse, - tolerance, antialias, clip); -} - -static cairo_int_status_t -_cairo_quartz_image_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_quartz_image_surface_t *surface = abstract_surface; - return _cairo_surface_fill (&surface->imageSurface->base, - op, source, path, - fill_rule, tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_quartz_image_surface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_quartz_image_surface_t *surface = abstract_surface; - return _cairo_surface_show_text_glyphs (&surface->imageSurface->base, - op, source, - NULL, 0, - glyphs, num_glyphs, - NULL, 0, 0, - scaled_font, clip); -} - - -static const cairo_surface_backend_t cairo_quartz_image_surface_backend = { - CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, - _cairo_quartz_image_surface_finish, - - _cairo_default_context_create, - - _cairo_quartz_image_surface_create_similar, - _cairo_quartz_image_surface_create_similar_image, - _cairo_quartz_image_surface_map_to_image, - _cairo_quartz_image_surface_unmap_image, - - _cairo_surface_default_source, - _cairo_quartz_image_surface_acquire_source_image, - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_quartz_image_surface_get_extents, - NULL, /* get_font_options */ - - _cairo_quartz_image_surface_flush, - NULL, /* mark_dirty_rectangle */ - - _cairo_quartz_image_surface_paint, - _cairo_quartz_image_surface_mask, - _cairo_quartz_image_surface_stroke, - _cairo_quartz_image_surface_fill, - NULL, /* fill-stroke */ - _cairo_quartz_image_surface_glyphs, -}; - -/** - * cairo_quartz_image_surface_create: - * @image_surface: a cairo image surface to wrap with a quartz image surface - * - * Creates a Quartz surface backed by a CGImageRef that references the - * given image surface. The resulting surface can be rendered quickly - * when used as a source when rendering to a #cairo_quartz_surface. If - * the data in the image surface is ever updated, cairo_surface_flush() - * must be called on the #cairo_quartz_image_surface to ensure that the - * CGImageRef refers to the updated data. - * - * Return value: the newly created surface. - * - * Since: 1.6 - **/ -cairo_surface_t * -cairo_quartz_image_surface_create (cairo_surface_t *surface) -{ - cairo_quartz_image_surface_t *qisurf; - - CGImageRef image; - - cairo_image_surface_t *image_surface; - int width, height, stride; - cairo_format_t format; - unsigned char *data; - - if (surface->status) - return surface; - - if (! _cairo_surface_is_image (surface)) - return SURFACE_ERROR_TYPE_MISMATCH; - - image_surface = (cairo_image_surface_t*) surface; - width = image_surface->width; - height = image_surface->height; - stride = image_surface->stride; - format = image_surface->format; - data = image_surface->data; - - if (!_cairo_quartz_verify_surface_size(width, height)) - return SURFACE_ERROR_INVALID_SIZE; - - if (width == 0 || height == 0) - return SURFACE_ERROR_INVALID_SIZE; - - if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) - return SURFACE_ERROR_INVALID_FORMAT; - - qisurf = malloc(sizeof(cairo_quartz_image_surface_t)); - if (qisurf == NULL) - return SURFACE_ERROR_NO_MEMORY; - - memset (qisurf, 0, sizeof(cairo_quartz_image_surface_t)); - - /* In case the create_cgimage fails, this ref will - * be released via the callback (which will be called in - * case of failure.) - */ - cairo_surface_reference (surface); - - image = CairoQuartzCreateCGImage (format, - width, height, - stride, - data, - TRUE, - NULL, - DataProviderReleaseCallback, - image_surface); - - if (!image) { - free (qisurf); - return SURFACE_ERROR_NO_MEMORY; - } - - _cairo_surface_init (&qisurf->base, - &cairo_quartz_image_surface_backend, - NULL, /* device */ - _cairo_content_from_format (format)); - - qisurf->width = width; - qisurf->height = height; - - qisurf->image = image; - qisurf->imageSurface = image_surface; - - return &qisurf->base; -} - - -cairo_surface_t * -cairo_quartz_image_surface_get_image (cairo_surface_t *asurface) -{ - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t*) asurface; - - /* Throw an error for a non-quartz surface */ - if (! _cairo_surface_is_quartz (asurface)) { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - } - - return (cairo_surface_t*) surface->imageSurface; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image.h deleted file mode 100644 index dae234dacae..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-image.h +++ /dev/null @@ -1,59 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright 2008 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#ifndef CAIRO_QUARTZ_IMAGE_H -#define CAIRO_QUARTZ_IMAGE_H - -#include "cairo.h" - -#if CAIRO_HAS_QUARTZ_IMAGE_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_quartz_image_surface_create (cairo_surface_t *image_surface); - -cairo_public cairo_surface_t * -cairo_quartz_image_surface_get_image (cairo_surface_t *surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_QUARTZ_IMAGE_SURFACE */ -# error Cairo was not compiled with support for the quartz-image backend -#endif /* CAIRO_HAS_QUARTZ_IMAGE_SURFACE */ - -#endif /* CAIRO_QUARTZ_IMAGE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-private.h deleted file mode 100644 index 3ef14c3ae60..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-private.h +++ /dev/null @@ -1,109 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Calum Robinson - * Copyright (C) 2006,2007 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Calum Robinson - * - * Contributor(s): - * Calum Robinson - * Vladimir Vukicevic - */ - -#ifndef CAIRO_QUARTZ_PRIVATE_H -#define CAIRO_QUARTZ_PRIVATE_H - -#include "cairoint.h" - -#if CAIRO_HAS_QUARTZ_SURFACE -#include "cairo-quartz.h" -#include "cairo-surface-clipper-private.h" - -#ifdef CGFLOAT_DEFINED -typedef CGFloat cairo_quartz_float_t; -#else -typedef float cairo_quartz_float_t; -#endif - -typedef enum { - DO_DIRECT, - DO_SHADING, - DO_IMAGE, - DO_TILED_IMAGE -} cairo_quartz_action_t; - -typedef struct cairo_quartz_surface { - cairo_surface_t base; - - CGContextRef cgContext; - CGAffineTransform cgContextBaseCTM; - - void *imageData; - cairo_surface_t *imageSurfaceEquiv; - - cairo_surface_clipper_t clipper; - cairo_rectangle_int_t extents; - cairo_rectangle_int_t virtual_extents; -} cairo_quartz_surface_t; - -typedef struct cairo_quartz_image_surface { - cairo_surface_t base; - - int width, height; - - CGImageRef image; - cairo_image_surface_t *imageSurface; -} cairo_quartz_image_surface_t; - -cairo_private cairo_bool_t -_cairo_quartz_verify_surface_size(int width, int height); - -cairo_private cairo_bool_t -_cairo_surface_is_quartz (const cairo_surface_t *surface); - -cairo_private CGImageRef -CairoQuartzCreateCGImage (cairo_format_t format, - unsigned int width, - unsigned int height, - unsigned int stride, - void *data, - cairo_bool_t interpolate, - CGColorSpaceRef colorSpaceOverride, - CGDataProviderReleaseDataCallback releaseCallback, - void *releaseInfo); - -cairo_private CGFontRef -_cairo_quartz_scaled_font_get_cg_font_ref (cairo_scaled_font_t *sfont); - -#else - -# error Cairo was not compiled with support for the quartz backend - -#endif /* CAIRO_HAS_QUARTZ_SURFACE */ - -#endif /* CAIRO_QUARTZ_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-surface.c deleted file mode 100644 index 1116ff94c1e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz-surface.c +++ /dev/null @@ -1,2574 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright � 2006, 2007 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#define _GNU_SOURCE /* required for RTLD_DEFAULT */ -#include "cairoint.h" - -#include "cairo-quartz-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-recording-surface-private.h" - -#include - -#ifndef RTLD_DEFAULT -#define RTLD_DEFAULT ((void *) 0) -#endif - -#include - -#undef QUARTZ_DEBUG - -#ifdef QUARTZ_DEBUG -#define ND(_x) fprintf _x -#else -#define ND(_x) do {} while(0) -#endif - -#define IS_EMPTY(s) ((s)->extents.width == 0 || (s)->extents.height == 0) - -/** - * SECTION:cairo-quartz - * @Title: Quartz Surfaces - * @Short_Description: Rendering to Quartz surfaces - * @See_Also: #cairo_surface_t - * - * The Quartz surface is used to render cairo graphics targeting the - * Apple OS X Quartz rendering system. - **/ - -/** - * CAIRO_HAS_QUARTZ_SURFACE: - * - * Defined if the Quartz surface backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.6 - **/ - -#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -/* This method is private, but it exists. Its params are are exposed - * as args to the NS* method, but not as CG. - */ -enum PrivateCGCompositeMode { - kPrivateCGCompositeClear = 0, - kPrivateCGCompositeCopy = 1, - kPrivateCGCompositeSourceOver = 2, - kPrivateCGCompositeSourceIn = 3, - kPrivateCGCompositeSourceOut = 4, - kPrivateCGCompositeSourceAtop = 5, - kPrivateCGCompositeDestinationOver = 6, - kPrivateCGCompositeDestinationIn = 7, - kPrivateCGCompositeDestinationOut = 8, - kPrivateCGCompositeDestinationAtop = 9, - kPrivateCGCompositeXOR = 10, - kPrivateCGCompositePlusDarker = 11, // (max (0, (1-d) + (1-s))) - kPrivateCGCompositePlusLighter = 12, // (min (1, s + d)) -}; -typedef enum PrivateCGCompositeMode PrivateCGCompositeMode; -CG_EXTERN void CGContextSetCompositeOperation (CGContextRef, PrivateCGCompositeMode); -#endif - -/* Some of these are present in earlier versions of the OS than where - * they are public; other are not public at all - */ -/* public since 10.5 */ -static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL; - -/* public since 10.6 */ -static CGPathRef (*CGContextCopyPathPtr) (CGContextRef) = NULL; -static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; - -/* not yet public */ -static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL; -static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; - -static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE; - -/* - * Utility functions - */ - -#ifdef QUARTZ_DEBUG -static void quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest); -static void quartz_image_to_png (CGImageRef, char *dest); -#endif - -static cairo_quartz_surface_t * -_cairo_quartz_surface_create_internal (CGContextRef cgContext, - cairo_content_t content, - unsigned int width, - unsigned int height); - -/* Load all extra symbols */ -static void quartz_ensure_symbols (void) -{ - if (likely (_cairo_quartz_symbol_lookup_done)) - return; - - CGContextDrawTiledImagePtr = dlsym (RTLD_DEFAULT, "CGContextDrawTiledImage"); - CGContextGetTypePtr = dlsym (RTLD_DEFAULT, "CGContextGetType"); - CGContextCopyPathPtr = dlsym (RTLD_DEFAULT, "CGContextCopyPath"); - CGContextGetAllowsFontSmoothingPtr = dlsym (RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing"); - CGContextSetAllowsFontSmoothingPtr = dlsym (RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing"); - - _cairo_quartz_symbol_lookup_done = TRUE; -} - -CGImageRef -CairoQuartzCreateCGImage (cairo_format_t format, - unsigned int width, - unsigned int height, - unsigned int stride, - void *data, - cairo_bool_t interpolate, - CGColorSpaceRef colorSpaceOverride, - CGDataProviderReleaseDataCallback releaseCallback, - void *releaseInfo) -{ - CGImageRef image = NULL; - CGDataProviderRef dataProvider = NULL; - CGColorSpaceRef colorSpace = colorSpaceOverride; - CGBitmapInfo bitinfo = kCGBitmapByteOrder32Host; - int bitsPerComponent, bitsPerPixel; - - switch (format) { - case CAIRO_FORMAT_ARGB32: - if (colorSpace == NULL) - colorSpace = CGColorSpaceCreateDeviceRGB (); - bitinfo |= kCGImageAlphaPremultipliedFirst; - bitsPerComponent = 8; - bitsPerPixel = 32; - break; - - case CAIRO_FORMAT_RGB24: - if (colorSpace == NULL) - colorSpace = CGColorSpaceCreateDeviceRGB (); - bitinfo |= kCGImageAlphaNoneSkipFirst; - bitsPerComponent = 8; - bitsPerPixel = 32; - break; - - case CAIRO_FORMAT_A8: - bitsPerComponent = 8; - bitsPerPixel = 8; - break; - - case CAIRO_FORMAT_A1: -#ifdef WORDS_BIGENDIAN - bitsPerComponent = 1; - bitsPerPixel = 1; - break; -#endif - - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_RGB16_565: - case CAIRO_FORMAT_INVALID: - default: - return NULL; - } - - dataProvider = CGDataProviderCreateWithData (releaseInfo, - data, - height * stride, - releaseCallback); - - if (unlikely (!dataProvider)) { - // manually release - if (releaseCallback) - releaseCallback (releaseInfo, data, height * stride); - goto FINISH; - } - - if (format == CAIRO_FORMAT_A8 || format == CAIRO_FORMAT_A1) { - cairo_quartz_float_t decode[] = {1.0, 0.0}; - image = CGImageMaskCreate (width, height, - bitsPerComponent, - bitsPerPixel, - stride, - dataProvider, - decode, - interpolate); - } else - image = CGImageCreate (width, height, - bitsPerComponent, - bitsPerPixel, - stride, - colorSpace, - bitinfo, - dataProvider, - NULL, - interpolate, - kCGRenderingIntentDefault); - -FINISH: - - CGDataProviderRelease (dataProvider); - - if (colorSpace != colorSpaceOverride) - CGColorSpaceRelease (colorSpace); - - return image; -} - -static inline cairo_bool_t -_cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc) -{ - if (unlikely (cgc == NULL)) - return FALSE; - - if (likely (CGContextGetTypePtr)) { - /* 4 is the type value of a bitmap context */ - return CGContextGetTypePtr (cgc) == 4; - } - - /* This will cause a (harmless) warning to be printed if called on a non-bitmap context */ - return CGBitmapContextGetBitsPerPixel (cgc) != 0; -} - -/* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */ - -#define CG_MAX_HEIGHT SHRT_MAX -#define CG_MAX_WIDTH USHRT_MAX - -/* is the desired size of the surface within bounds? */ -cairo_bool_t -_cairo_quartz_verify_surface_size (int width, int height) -{ - /* hmmm, allow width, height == 0 ? */ - if (width < 0 || height < 0) - return FALSE; - - if (width > CG_MAX_WIDTH || height > CG_MAX_HEIGHT) - return FALSE; - - return TRUE; -} - -/* - * Cairo path -> Quartz path conversion helpers - */ - -/* cairo path -> execute in context */ -static cairo_status_t -_cairo_path_to_quartz_context_move_to (void *closure, - const cairo_point_t *point) -{ - //ND ((stderr, "moveto: %f %f\n", _cairo_fixed_to_double (point->x), _cairo_fixed_to_double (point->y))); - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - CGContextMoveToPoint (closure, x, y); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_to_quartz_context_line_to (void *closure, - const cairo_point_t *point) -{ - //ND ((stderr, "lineto: %f %f\n", _cairo_fixed_to_double (point->x), _cairo_fixed_to_double (point->y))); - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - CGContextAddLineToPoint (closure, x, y); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_to_quartz_context_curve_to (void *closure, - const cairo_point_t *p0, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - //ND ((stderr, "curveto: %f,%f %f,%f %f,%f\n", - // _cairo_fixed_to_double (p0->x), _cairo_fixed_to_double (p0->y), - // _cairo_fixed_to_double (p1->x), _cairo_fixed_to_double (p1->y), - // _cairo_fixed_to_double (p2->x), _cairo_fixed_to_double (p2->y))); - double x0 = _cairo_fixed_to_double (p0->x); - double y0 = _cairo_fixed_to_double (p0->y); - double x1 = _cairo_fixed_to_double (p1->x); - double y1 = _cairo_fixed_to_double (p1->y); - double x2 = _cairo_fixed_to_double (p2->x); - double y2 = _cairo_fixed_to_double (p2->y); - - CGContextAddCurveToPoint (closure, x0, y0, x1, y1, x2, y2); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_path_to_quartz_context_close_path (void *closure) -{ - //ND ((stderr, "closepath\n")); - CGContextClosePath (closure); - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_quartz_cairo_path_to_quartz_context (const cairo_path_fixed_t *path, - CGContextRef closure) -{ - cairo_status_t status; - - CGContextBeginPath (closure); - status = _cairo_path_fixed_interpret (path, - _cairo_path_to_quartz_context_move_to, - _cairo_path_to_quartz_context_line_to, - _cairo_path_to_quartz_context_curve_to, - _cairo_path_to_quartz_context_close_path, - closure); - - assert (status == CAIRO_STATUS_SUCCESS); -} - -/* - * Misc helpers/callbacks - */ - -#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -static PrivateCGCompositeMode -_cairo_quartz_cairo_operator_to_quartz_composite (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_CLEAR: - return kPrivateCGCompositeClear; - case CAIRO_OPERATOR_SOURCE: - return kPrivateCGCompositeCopy; - case CAIRO_OPERATOR_OVER: - return kPrivateCGCompositeSourceOver; - case CAIRO_OPERATOR_IN: - return kPrivateCGCompositeSourceIn; - case CAIRO_OPERATOR_OUT: - return kPrivateCGCompositeSourceOut; - case CAIRO_OPERATOR_ATOP: - return kPrivateCGCompositeSourceAtop; - case CAIRO_OPERATOR_DEST_OVER: - return kPrivateCGCompositeDestinationOver; - case CAIRO_OPERATOR_DEST_IN: - return kPrivateCGCompositeDestinationIn; - case CAIRO_OPERATOR_DEST_OUT: - return kPrivateCGCompositeDestinationOut; - case CAIRO_OPERATOR_DEST_ATOP: - return kPrivateCGCompositeDestinationAtop; - case CAIRO_OPERATOR_XOR: - return kPrivateCGCompositeXOR; - case CAIRO_OPERATOR_ADD: - return kPrivateCGCompositePlusLighter; - - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_SATURATE: - case CAIRO_OPERATOR_MULTIPLY: - case CAIRO_OPERATOR_SCREEN: - case CAIRO_OPERATOR_OVERLAY: - case CAIRO_OPERATOR_DARKEN: - case CAIRO_OPERATOR_LIGHTEN: - case CAIRO_OPERATOR_COLOR_DODGE: - case CAIRO_OPERATOR_COLOR_BURN: - case CAIRO_OPERATOR_HARD_LIGHT: - case CAIRO_OPERATOR_SOFT_LIGHT: - case CAIRO_OPERATOR_DIFFERENCE: - case CAIRO_OPERATOR_EXCLUSION: - case CAIRO_OPERATOR_HSL_HUE: - case CAIRO_OPERATOR_HSL_SATURATION: - case CAIRO_OPERATOR_HSL_COLOR: - case CAIRO_OPERATOR_HSL_LUMINOSITY: - default: - ASSERT_NOT_REACHED; - } -} -#endif - -static CGBlendMode -_cairo_quartz_cairo_operator_to_quartz_blend (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_MULTIPLY: - return kCGBlendModeMultiply; - case CAIRO_OPERATOR_SCREEN: - return kCGBlendModeScreen; - case CAIRO_OPERATOR_OVERLAY: - return kCGBlendModeOverlay; - case CAIRO_OPERATOR_DARKEN: - return kCGBlendModeDarken; - case CAIRO_OPERATOR_LIGHTEN: - return kCGBlendModeLighten; - case CAIRO_OPERATOR_COLOR_DODGE: - return kCGBlendModeColorDodge; - case CAIRO_OPERATOR_COLOR_BURN: - return kCGBlendModeColorBurn; - case CAIRO_OPERATOR_HARD_LIGHT: - return kCGBlendModeHardLight; - case CAIRO_OPERATOR_SOFT_LIGHT: - return kCGBlendModeSoftLight; - case CAIRO_OPERATOR_DIFFERENCE: - return kCGBlendModeDifference; - case CAIRO_OPERATOR_EXCLUSION: - return kCGBlendModeExclusion; - case CAIRO_OPERATOR_HSL_HUE: - return kCGBlendModeHue; - case CAIRO_OPERATOR_HSL_SATURATION: - return kCGBlendModeSaturation; - case CAIRO_OPERATOR_HSL_COLOR: - return kCGBlendModeColor; - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return kCGBlendModeLuminosity; - -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - case CAIRO_OPERATOR_CLEAR: - return kCGBlendModeClear; - case CAIRO_OPERATOR_SOURCE: - return kCGBlendModeCopy; - case CAIRO_OPERATOR_OVER: - return kCGBlendModeNormal; - case CAIRO_OPERATOR_IN: - return kCGBlendModeSourceIn; - case CAIRO_OPERATOR_OUT: - return kCGBlendModeSourceOut; - case CAIRO_OPERATOR_ATOP: - return kCGBlendModeSourceAtop; - case CAIRO_OPERATOR_DEST_OVER: - return kCGBlendModeDestinationOver; - case CAIRO_OPERATOR_DEST_IN: - return kCGBlendModeDestinationIn; - case CAIRO_OPERATOR_DEST_OUT: - return kCGBlendModeDestinationOut; - case CAIRO_OPERATOR_DEST_ATOP: - return kCGBlendModeDestinationAtop; - case CAIRO_OPERATOR_XOR: - return kCGBlendModeXOR; - case CAIRO_OPERATOR_ADD: - return kCGBlendModePlusLighter; -#else - case CAIRO_OPERATOR_CLEAR: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_OUT: - case CAIRO_OPERATOR_ATOP: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_DEST_OUT: - case CAIRO_OPERATOR_DEST_ATOP: - case CAIRO_OPERATOR_XOR: - case CAIRO_OPERATOR_ADD: -#endif - - case CAIRO_OPERATOR_DEST: - case CAIRO_OPERATOR_SATURATE: - default: - ASSERT_NOT_REACHED; - } -} - -static cairo_int_status_t -_cairo_cgcontext_set_cairo_operator (CGContextRef context, cairo_operator_t op) -{ - CGBlendMode blendmode; - - assert (op != CAIRO_OPERATOR_DEST); - - /* Quartz doesn't support SATURATE at all. COLOR_DODGE and - * COLOR_BURN in Quartz follow the ISO32000 definition, but cairo - * uses the definition from the Adobe Supplement. - */ - if (op == CAIRO_OPERATOR_SATURATE || - op == CAIRO_OPERATOR_COLOR_DODGE || - op == CAIRO_OPERATOR_COLOR_BURN) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - -#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 - if (op <= CAIRO_OPERATOR_ADD) { - PrivateCGCompositeMode compmode; - - compmode = _cairo_quartz_cairo_operator_to_quartz_composite (op); - CGContextSetCompositeOperation (context, compmode); - return CAIRO_STATUS_SUCCESS; - } -#endif - - blendmode = _cairo_quartz_cairo_operator_to_quartz_blend (op); - CGContextSetBlendMode (context, blendmode); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_quartz_surface_set_cairo_operator (cairo_quartz_surface_t *surface, cairo_operator_t op) -{ - ND((stderr, "%p _cairo_quartz_surface_set_cairo_operator %d\n", surface, op)); - - /* When the destination has no color components, we can avoid some - * fallbacks, but we have to workaround operators which behave - * differently in Quartz. */ - if (surface->base.content == CAIRO_CONTENT_ALPHA) { - assert (op != CAIRO_OPERATOR_ATOP); /* filtered by surface layer */ - - if (op == CAIRO_OPERATOR_SOURCE || - op == CAIRO_OPERATOR_IN || - op == CAIRO_OPERATOR_OUT || - op == CAIRO_OPERATOR_DEST_IN || - op == CAIRO_OPERATOR_DEST_ATOP || - op == CAIRO_OPERATOR_XOR) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (op == CAIRO_OPERATOR_DEST_OVER) - op = CAIRO_OPERATOR_OVER; - else if (op == CAIRO_OPERATOR_SATURATE) - op = CAIRO_OPERATOR_ADD; - else if (op == CAIRO_OPERATOR_COLOR_DODGE) - op = CAIRO_OPERATOR_OVER; - else if (op == CAIRO_OPERATOR_COLOR_BURN) - op = CAIRO_OPERATOR_OVER; - } - - return _cairo_cgcontext_set_cairo_operator (surface->cgContext, op); -} - -static inline CGLineCap -_cairo_quartz_cairo_line_cap_to_quartz (cairo_line_cap_t ccap) -{ - switch (ccap) { - default: - ASSERT_NOT_REACHED; - - case CAIRO_LINE_CAP_BUTT: - return kCGLineCapButt; - - case CAIRO_LINE_CAP_ROUND: - return kCGLineCapRound; - - case CAIRO_LINE_CAP_SQUARE: - return kCGLineCapSquare; - } -} - -static inline CGLineJoin -_cairo_quartz_cairo_line_join_to_quartz (cairo_line_join_t cjoin) -{ - switch (cjoin) { - default: - ASSERT_NOT_REACHED; - - case CAIRO_LINE_JOIN_MITER: - return kCGLineJoinMiter; - - case CAIRO_LINE_JOIN_ROUND: - return kCGLineJoinRound; - - case CAIRO_LINE_JOIN_BEVEL: - return kCGLineJoinBevel; - } -} - -static inline CGInterpolationQuality -_cairo_quartz_filter_to_quartz (cairo_filter_t filter) -{ - switch (filter) { - case CAIRO_FILTER_NEAREST: - case CAIRO_FILTER_FAST: - return kCGInterpolationNone; - - case CAIRO_FILTER_BEST: - case CAIRO_FILTER_GOOD: - case CAIRO_FILTER_BILINEAR: - case CAIRO_FILTER_GAUSSIAN: - return kCGInterpolationDefault; - - default: - ASSERT_NOT_REACHED; - return kCGInterpolationDefault; - } -} - -static inline void -_cairo_quartz_cairo_matrix_to_quartz (const cairo_matrix_t *src, - CGAffineTransform *dst) -{ - dst->a = src->xx; - dst->b = src->yx; - dst->c = src->xy; - dst->d = src->yy; - dst->tx = src->x0; - dst->ty = src->y0; -} - - -/* - * Source -> Quartz setup and finish functions - */ - -static void -ComputeGradientValue (void *info, - const cairo_quartz_float_t *in, - cairo_quartz_float_t *out) -{ - double fdist = *in; - const cairo_gradient_pattern_t *grad = (cairo_gradient_pattern_t*) info; - unsigned int i; - - /* Put fdist back in the 0.0..1.0 range if we're doing - * REPEAT/REFLECT - */ - if (grad->base.extend == CAIRO_EXTEND_REPEAT) { - fdist = fdist - floor (fdist); - } else if (grad->base.extend == CAIRO_EXTEND_REFLECT) { - fdist = fmod (fabs (fdist), 2.0); - if (fdist > 1.0) - fdist = 2.0 - fdist; - } - - for (i = 0; i < grad->n_stops; i++) - if (grad->stops[i].offset > fdist) - break; - - if (i == 0 || i == grad->n_stops) { - if (i == grad->n_stops) - --i; - out[0] = grad->stops[i].color.red; - out[1] = grad->stops[i].color.green; - out[2] = grad->stops[i].color.blue; - out[3] = grad->stops[i].color.alpha; - } else { - cairo_quartz_float_t ax = grad->stops[i-1].offset; - cairo_quartz_float_t bx = grad->stops[i].offset - ax; - cairo_quartz_float_t bp = (fdist - ax)/bx; - cairo_quartz_float_t ap = 1.0 - bp; - - out[0] = - grad->stops[i-1].color.red * ap + - grad->stops[i].color.red * bp; - out[1] = - grad->stops[i-1].color.green * ap + - grad->stops[i].color.green * bp; - out[2] = - grad->stops[i-1].color.blue * ap + - grad->stops[i].color.blue * bp; - out[3] = - grad->stops[i-1].color.alpha * ap + - grad->stops[i].color.alpha * bp; - } -} - -static const cairo_quartz_float_t gradient_output_value_ranges[8] = { - 0.f, 1.f, 0.f, 1.f, 0.f, 1.f, 0.f, 1.f -}; -static const CGFunctionCallbacks gradient_callbacks = { - 0, ComputeGradientValue, (CGFunctionReleaseInfoCallback) cairo_pattern_destroy -}; - -/* Quartz computes a small number of samples of the gradient color - * function. On MacOS X 10.5 it apparently computes only 1024 - * samples. */ -#define MAX_GRADIENT_RANGE 1024 - -static CGFunctionRef -CairoQuartzCreateGradientFunction (const cairo_gradient_pattern_t *gradient, - const cairo_rectangle_int_t *extents, - cairo_circle_double_t *start, - cairo_circle_double_t *end) -{ - cairo_pattern_t *pat; - cairo_quartz_float_t input_value_range[2]; - - if (gradient->base.extend != CAIRO_EXTEND_NONE) { - double bounds_x1, bounds_x2, bounds_y1, bounds_y2; - double t[2], tolerance; - - tolerance = fabs (_cairo_matrix_compute_determinant (&gradient->base.matrix)); - tolerance /= _cairo_matrix_transformed_circle_major_axis (&gradient->base.matrix, 1); - - bounds_x1 = extents->x; - bounds_y1 = extents->y; - bounds_x2 = extents->x + extents->width; - bounds_y2 = extents->y + extents->height; - _cairo_matrix_transform_bounding_box (&gradient->base.matrix, - &bounds_x1, &bounds_y1, - &bounds_x2, &bounds_y2, - NULL); - - _cairo_gradient_pattern_box_to_parameter (gradient, - bounds_x1, bounds_y1, - bounds_x2, bounds_y2, - tolerance, - t); - - if (gradient->base.extend == CAIRO_EXTEND_PAD) { - t[0] = MAX (t[0], -0.5); - t[1] = MIN (t[1], 1.5); - } else if (t[1] - t[0] > MAX_GRADIENT_RANGE) - return NULL; - - /* set the input range for the function -- the function knows how - to map values outside of 0.0 .. 1.0 to the correct color */ - input_value_range[0] = t[0]; - input_value_range[1] = t[1]; - } else { - input_value_range[0] = 0; - input_value_range[1] = 1; - } - - _cairo_gradient_pattern_interpolate (gradient, input_value_range[0], start); - _cairo_gradient_pattern_interpolate (gradient, input_value_range[1], end); - - if (_cairo_pattern_create_copy (&pat, &gradient->base)) - return NULL; - - return CGFunctionCreate (pat, - 1, - input_value_range, - 4, - gradient_output_value_ranges, - &gradient_callbacks); -} - -/* Obtain a CGImageRef from a #cairo_surface_t * */ - -typedef struct { - cairo_surface_t *surface; - cairo_image_surface_t *image_out; - void *image_extra; -} quartz_source_image_t; - -static void -DataProviderReleaseCallback (void *info, const void *data, size_t size) -{ - quartz_source_image_t *source_img = info; - _cairo_surface_release_source_image (source_img->surface, source_img->image_out, source_img->image_extra); - free (source_img); -} - -static cairo_status_t -_cairo_surface_to_cgimage (cairo_surface_t *source, - cairo_rectangle_int_t *extents, - cairo_format_t format, - cairo_matrix_t *matrix, - const cairo_clip_t *clip, - CGImageRef *image_out) -{ - cairo_status_t status; - quartz_source_image_t *source_img; - cairo_image_surface_t *image_surface; - - if (source->backend && source->backend->type == CAIRO_SURFACE_TYPE_QUARTZ_IMAGE) { - cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) source; - *image_out = CGImageRetain (surface->image); - return CAIRO_STATUS_SUCCESS; - } - - if (_cairo_surface_is_quartz (source)) { - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) source; - if (IS_EMPTY (surface)) { - *image_out = NULL; - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - if (_cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) { - *image_out = CGBitmapContextCreateImage (surface->cgContext); - if (*image_out) - return CAIRO_STATUS_SUCCESS; - } - } - - source_img = malloc (sizeof (quartz_source_image_t)); - if (unlikely (source_img == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - source_img->surface = source; - - if (source->type == CAIRO_SURFACE_TYPE_RECORDING) { - image_surface = (cairo_image_surface_t *) - cairo_image_surface_create (format, extents->width, extents->height); - if (unlikely (image_surface->base.status)) { - status = image_surface->base.status; - cairo_surface_destroy (&image_surface->base); - free (source_img); - return status; - } - - status = _cairo_recording_surface_replay_with_clip (source, - matrix, - &image_surface->base, - NULL); - if (unlikely (status)) { - cairo_surface_destroy (&image_surface->base); - free (source_img); - return status; - } - - source_img->image_out = image_surface; - source_img->image_extra = NULL; - - cairo_matrix_init_identity (matrix); - } - else { - status = _cairo_surface_acquire_source_image (source_img->surface, - &source_img->image_out, - &source_img->image_extra); - if (unlikely (status)) { - free (source_img); - return status; - } - } - - if (source_img->image_out->width == 0 || source_img->image_out->height == 0) { - *image_out = NULL; - DataProviderReleaseCallback (source_img, - source_img->image_out->data, - source_img->image_out->height * source_img->image_out->stride); - } else { - *image_out = CairoQuartzCreateCGImage (source_img->image_out->format, - source_img->image_out->width, - source_img->image_out->height, - source_img->image_out->stride, - source_img->image_out->data, - TRUE, - NULL, - DataProviderReleaseCallback, - source_img); - - /* TODO: differentiate memory error and unsupported surface type */ - if (unlikely (*image_out == NULL)) - status = CAIRO_INT_STATUS_UNSUPPORTED; - } - - return status; -} - -/* Generic #cairo_pattern_t -> CGPattern function */ - -typedef struct { - CGImageRef image; - CGRect imageBounds; - cairo_bool_t do_reflect; -} SurfacePatternDrawInfo; - -static void -SurfacePatternDrawFunc (void *ainfo, CGContextRef context) -{ - SurfacePatternDrawInfo *info = (SurfacePatternDrawInfo*) ainfo; - - CGContextTranslateCTM (context, 0, info->imageBounds.size.height); - CGContextScaleCTM (context, 1, -1); - - CGContextDrawImage (context, info->imageBounds, info->image); - if (info->do_reflect) { - /* draw 3 more copies of the image, flipped. - * DrawImage draws the image according to the current Y-direction into the rectangle given - * (imageBounds); at the time of the first DrawImage above, the origin is at the bottom left - * of the base image position, and the Y axis is extending upwards. - */ - - /* Make the y axis extend downwards, and draw a flipped image below */ - CGContextScaleCTM (context, 1, -1); - CGContextDrawImage (context, info->imageBounds, info->image); - - /* Shift over to the right, and flip vertically (translation is 2x, - * since we'll be flipping and thus rendering the rectangle "backwards" - */ - CGContextTranslateCTM (context, 2 * info->imageBounds.size.width, 0); - CGContextScaleCTM (context, -1, 1); - CGContextDrawImage (context, info->imageBounds, info->image); - - /* Then unflip the Y-axis again, and draw the image above the point. */ - CGContextScaleCTM (context, 1, -1); - CGContextDrawImage (context, info->imageBounds, info->image); - } -} - -static void -SurfacePatternReleaseInfoFunc (void *ainfo) -{ - SurfacePatternDrawInfo *info = (SurfacePatternDrawInfo*) ainfo; - - CGImageRelease (info->image); - free (info); -} - -static cairo_int_status_t -_cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t *dest, - const cairo_pattern_t *apattern, - const cairo_clip_t *clip, - CGPatternRef *cgpat) -{ - cairo_surface_pattern_t *spattern; - cairo_surface_t *pat_surf; - cairo_rectangle_int_t extents; - cairo_format_t format = _cairo_format_from_content (dest->base.content); - - CGImageRef image; - CGRect pbounds; - CGAffineTransform ptransform, stransform; - CGPatternCallbacks cb = { 0, - SurfacePatternDrawFunc, - SurfacePatternReleaseInfoFunc }; - SurfacePatternDrawInfo *info; - cairo_quartz_float_t rw, rh; - cairo_status_t status; - cairo_bool_t is_bounded; - - cairo_matrix_t m; - - /* SURFACE is the only type we'll handle here */ - assert (apattern->type == CAIRO_PATTERN_TYPE_SURFACE); - - spattern = (cairo_surface_pattern_t *) apattern; - pat_surf = spattern->surface; - - if (pat_surf->type != CAIRO_SURFACE_TYPE_RECORDING) { - is_bounded = _cairo_surface_get_extents (pat_surf, &extents); - assert (is_bounded); - } - else - _cairo_surface_get_extents (&dest->base, &extents); - - m = spattern->base.matrix; - status = _cairo_surface_to_cgimage (pat_surf, &extents, format, - &m, clip, &image); - if (unlikely (status)) - return status; - - info = malloc (sizeof (SurfacePatternDrawInfo)); - if (unlikely (!info)) - return CAIRO_STATUS_NO_MEMORY; - - /* XXX -- if we're printing, we may need to call CGImageCreateCopy to make sure - * that the data will stick around for this image when the printer gets to it. - * Otherwise, the underlying data store may disappear from under us! - * - * _cairo_surface_to_cgimage will copy when it converts non-Quartz surfaces, - * since the Quartz surfaces have a higher chance of sticking around. If the - * source is a quartz image surface, then it's set up to retain a ref to the - * image surface that it's backed by. - */ - info->image = image; - info->imageBounds = CGRectMake (0, 0, extents.width, extents.height); - info->do_reflect = FALSE; - - pbounds.origin.x = 0; - pbounds.origin.y = 0; - - if (spattern->base.extend == CAIRO_EXTEND_REFLECT) { - pbounds.size.width = 2.0 * extents.width; - pbounds.size.height = 2.0 * extents.height; - info->do_reflect = TRUE; - } else { - pbounds.size.width = extents.width; - pbounds.size.height = extents.height; - } - rw = pbounds.size.width; - rh = pbounds.size.height; - - cairo_matrix_invert (&m); - _cairo_quartz_cairo_matrix_to_quartz (&m, &stransform); - - /* The pattern matrix is relative to the bottom left, again; the - * incoming cairo pattern matrix is relative to the upper left. - * So we take the pattern matrix and the original context matrix, - * which gives us the correct base translation/y flip. - */ - ptransform = CGAffineTransformConcat (stransform, dest->cgContextBaseCTM); - -#ifdef QUARTZ_DEBUG - ND ((stderr, " pbounds: %f %f %f %f\n", pbounds.origin.x, pbounds.origin.y, pbounds.size.width, pbounds.size.height)); - ND ((stderr, " pattern xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", ptransform.tx, ptransform.ty, ptransform.a, ptransform.b, ptransform.c, ptransform.d)); - CGAffineTransform xform = CGContextGetCTM (dest->cgContext); - ND ((stderr, " context xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", xform.tx, xform.ty, xform.a, xform.b, xform.c, xform.d)); -#endif - - *cgpat = CGPatternCreate (info, - pbounds, - ptransform, - rw, rh, - kCGPatternTilingConstantSpacing, /* kCGPatternTilingNoDistortion, */ - TRUE, - &cb); - - return CAIRO_STATUS_SUCCESS; -} - -/* State used during a drawing operation. */ -typedef struct { - /* The destination of the mask */ - CGContextRef cgMaskContext; - - /* The destination of the drawing of the source */ - CGContextRef cgDrawContext; - - /* The filter to be used when drawing the source */ - CGInterpolationQuality filter; - - /* Action type */ - cairo_quartz_action_t action; - - /* Destination rect */ - CGRect rect; - - /* Used with DO_SHADING, DO_IMAGE and DO_TILED_IMAGE */ - CGAffineTransform transform; - - /* Used with DO_IMAGE and DO_TILED_IMAGE */ - CGImageRef image; - - /* Used with DO_SHADING */ - CGShadingRef shading; - - /* Temporary destination for unbounded operations */ - CGLayerRef layer; - CGRect clipRect; -} cairo_quartz_drawing_state_t; - -/* -Quartz does not support repeating radients. We handle repeating gradients -by manually extending the gradient and repeating color stops. We need to -minimize the number of repetitions since Quartz seems to sample our color -function across the entire range, even if part of that range is not needed -for the visible area of the gradient, and it samples with some fixed resolution, -so if the gradient range is too large it samples with very low resolution and -the gradient is very coarse. _cairo_quartz_create_gradient_function computes -the number of repetitions needed based on the extents. -*/ -static cairo_int_status_t -_cairo_quartz_setup_gradient_source (cairo_quartz_drawing_state_t *state, - const cairo_gradient_pattern_t *gradient, - const cairo_rectangle_int_t *extents) -{ - cairo_matrix_t mat; - cairo_circle_double_t start, end; - CGFunctionRef gradFunc; - CGColorSpaceRef rgb; - bool extend = gradient->base.extend != CAIRO_EXTEND_NONE; - - assert (gradient->n_stops > 0); - - mat = gradient->base.matrix; - cairo_matrix_invert (&mat); - _cairo_quartz_cairo_matrix_to_quartz (&mat, &state->transform); - - gradFunc = CairoQuartzCreateGradientFunction (gradient, extents, - &start, &end); - - if (unlikely (gradFunc == NULL)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - rgb = CGColorSpaceCreateDeviceRGB (); - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - state->shading = CGShadingCreateAxial (rgb, - CGPointMake (start.center.x, - start.center.y), - CGPointMake (end.center.x, - end.center.y), - gradFunc, - extend, extend); - } else { - state->shading = CGShadingCreateRadial (rgb, - CGPointMake (start.center.x, - start.center.y), - MAX (start.radius, 0), - CGPointMake (end.center.x, - end.center.y), - MAX (end.radius, 0), - gradFunc, - extend, extend); - } - - CGColorSpaceRelease (rgb); - CGFunctionRelease (gradFunc); - - state->action = DO_SHADING; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_quartz_setup_state (cairo_quartz_drawing_state_t *state, - cairo_composite_rectangles_t *composite) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) composite->surface; - cairo_operator_t op = composite->op; - const cairo_pattern_t *source = &composite->source_pattern.base; - const cairo_clip_t *clip = composite->clip; - cairo_bool_t needs_temp; - cairo_status_t status; - cairo_format_t format = _cairo_format_from_content (composite->surface->content); - - state->layer = NULL; - state->image = NULL; - state->shading = NULL; - state->cgDrawContext = NULL; - state->cgMaskContext = NULL; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - status = _cairo_quartz_surface_set_cairo_operator (surface, op); - if (unlikely (status)) - return status; - - /* Save before we change the pattern, colorspace, etc. so that - * we can restore and make sure that quartz releases our - * pattern (which may be stack allocated) - */ - - CGContextSaveGState (surface->cgContext); - state->clipRect = CGContextGetClipBoundingBox (surface->cgContext); - state->clipRect = CGRectIntegral (state->clipRect); - state->rect = state->clipRect; - - state->cgMaskContext = surface->cgContext; - state->cgDrawContext = state->cgMaskContext; - - state->filter = _cairo_quartz_filter_to_quartz (source->filter); - - if (op == CAIRO_OPERATOR_CLEAR) { - CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 1); - - state->action = DO_DIRECT; - return CAIRO_STATUS_SUCCESS; - } - - /* - * To implement mask unbounded operations Quartz needs a temporary - * surface which will be composited entirely (ignoring the mask). - * To implement source unbounded operations Quartz needs a - * temporary surface which allows extending the source to a size - * covering the whole mask, but there are some optimization - * opportunities: - * - * - CLEAR completely ignores the source, thus we can just use a - * solid color fill. - * - * - SOURCE can be implemented by drawing the source and clearing - * outside of the source as long as the two regions have no - * intersection. This happens when the source is a pixel-aligned - * rectangle. If the source is at least as big as the - * intersection between the clip rectangle and the mask - * rectangle, no clear operation is needed. - */ - needs_temp = ! _cairo_operator_bounded_by_mask (op); - - if (needs_temp) { - state->layer = CGLayerCreateWithContext (surface->cgContext, - state->clipRect.size, - NULL); - state->cgDrawContext = CGLayerGetContext (state->layer); - state->cgMaskContext = state->cgDrawContext; - CGContextTranslateCTM (state->cgDrawContext, - -state->clipRect.origin.x, - -state->clipRect.origin.y); - } - - if (source->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) source; - - CGContextSetRGBStrokeColor (state->cgDrawContext, - solid->color.red, - solid->color.green, - solid->color.blue, - solid->color.alpha); - CGContextSetRGBFillColor (state->cgDrawContext, - solid->color.red, - solid->color.green, - solid->color.blue, - solid->color.alpha); - - state->action = DO_DIRECT; - return CAIRO_STATUS_SUCCESS; - } - - if (source->type == CAIRO_PATTERN_TYPE_LINEAR || - source->type == CAIRO_PATTERN_TYPE_RADIAL) - { - const cairo_gradient_pattern_t *gpat = (const cairo_gradient_pattern_t *)source; - cairo_rectangle_int_t extents; - - extents = surface->virtual_extents; - extents.x -= surface->base.device_transform.x0; - extents.y -= surface->base.device_transform.y0; - _cairo_rectangle_union (&extents, &surface->extents); - - return _cairo_quartz_setup_gradient_source (state, gpat, &extents); - } - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE && - (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT))) - { - const cairo_surface_pattern_t *spat = (const cairo_surface_pattern_t *) source; - cairo_surface_t *pat_surf = spat->surface; - CGImageRef img; - cairo_matrix_t m = spat->base.matrix; - cairo_rectangle_int_t extents; - CGAffineTransform xform; - CGRect srcRect; - cairo_fixed_t fw, fh; - cairo_bool_t is_bounded; - - _cairo_surface_get_extents (composite->surface, &extents); - status = _cairo_surface_to_cgimage (pat_surf, &extents, format, - &m, clip, &img); - if (unlikely (status)) - return status; - - state->image = img; - - if (state->filter == kCGInterpolationNone && _cairo_matrix_is_translation (&m)) { - m.x0 = -ceil (m.x0 - 0.5); - m.y0 = -ceil (m.y0 - 0.5); - } else { - cairo_matrix_invert (&m); - } - - _cairo_quartz_cairo_matrix_to_quartz (&m, &state->transform); - - if (pat_surf->type != CAIRO_SURFACE_TYPE_RECORDING) { - is_bounded = _cairo_surface_get_extents (pat_surf, &extents); - assert (is_bounded); - } - - srcRect = CGRectMake (0, 0, extents.width, extents.height); - - if (source->extend == CAIRO_EXTEND_NONE) { - int x, y; - if (op == CAIRO_OPERATOR_SOURCE && - (pat_surf->content == CAIRO_CONTENT_ALPHA || - ! _cairo_matrix_is_integer_translation (&m, &x, &y))) - { - state->layer = CGLayerCreateWithContext (surface->cgContext, - state->clipRect.size, - NULL); - state->cgDrawContext = CGLayerGetContext (state->layer); - CGContextTranslateCTM (state->cgDrawContext, - -state->clipRect.origin.x, - -state->clipRect.origin.y); - } - - CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 1); - - state->rect = srcRect; - state->action = DO_IMAGE; - return CAIRO_STATUS_SUCCESS; - } - - CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 1); - - /* Quartz seems to tile images at pixel-aligned regions only -- this - * leads to seams if the image doesn't end up scaling to fill the - * space exactly. The CGPattern tiling approach doesn't have this - * problem. Check if we're going to fill up the space (within some - * epsilon), and if not, fall back to the CGPattern type. - */ - - xform = CGAffineTransformConcat (CGContextGetCTM (state->cgDrawContext), - state->transform); - - srcRect = CGRectApplyAffineTransform (srcRect, xform); - - fw = _cairo_fixed_from_double (srcRect.size.width); - fh = _cairo_fixed_from_double (srcRect.size.height); - - if ((fw & CAIRO_FIXED_FRAC_MASK) <= CAIRO_FIXED_EPSILON && - (fh & CAIRO_FIXED_FRAC_MASK) <= CAIRO_FIXED_EPSILON) - { - /* We're good to use DrawTiledImage, but ensure that - * the math works out */ - - srcRect.size.width = round (srcRect.size.width); - srcRect.size.height = round (srcRect.size.height); - - xform = CGAffineTransformInvert (xform); - - srcRect = CGRectApplyAffineTransform (srcRect, xform); - - state->rect = srcRect; - state->action = DO_TILED_IMAGE; - return CAIRO_STATUS_SUCCESS; - } - - /* Fall through to generic SURFACE case */ - } - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_quartz_float_t patternAlpha = 1.0f; - CGColorSpaceRef patternSpace; - CGPatternRef pattern = NULL; - cairo_int_status_t status; - - status = _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (surface, source, clip, &pattern); - if (unlikely (status)) - return status; - - patternSpace = CGColorSpaceCreatePattern (NULL); - CGContextSetFillColorSpace (state->cgDrawContext, patternSpace); - CGContextSetFillPattern (state->cgDrawContext, pattern, &patternAlpha); - CGContextSetStrokeColorSpace (state->cgDrawContext, patternSpace); - CGContextSetStrokePattern (state->cgDrawContext, pattern, &patternAlpha); - CGColorSpaceRelease (patternSpace); - - /* Quartz likes to munge the pattern phase (as yet unexplained - * why); force it to 0,0 as we've already baked in the correct - * pattern translation into the pattern matrix - */ - CGContextSetPatternPhase (state->cgDrawContext, CGSizeMake (0, 0)); - - CGPatternRelease (pattern); - - state->action = DO_DIRECT; - return CAIRO_STATUS_SUCCESS; - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static void -_cairo_quartz_teardown_state (cairo_quartz_drawing_state_t *state, - cairo_composite_rectangles_t *extents) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) extents->surface; - - if (state->layer) { - CGContextDrawLayerInRect (surface->cgContext, - state->clipRect, - state->layer); - CGLayerRelease (state->layer); - } - - if (state->cgMaskContext) - CGContextRestoreGState (surface->cgContext); - - if (state->image) - CGImageRelease (state->image); - - if (state->shading) - CGShadingRelease (state->shading); -} - -static void -_cairo_quartz_draw_source (cairo_quartz_drawing_state_t *state, - cairo_operator_t op) -{ - CGContextSetShouldAntialias (state->cgDrawContext, state->filter != kCGInterpolationNone); - CGContextSetInterpolationQuality(state->cgDrawContext, state->filter); - - if (state->action == DO_DIRECT) { - CGContextFillRect (state->cgDrawContext, state->rect); - return; - } - - CGContextConcatCTM (state->cgDrawContext, state->transform); - - if (state->action == DO_SHADING) { - CGContextDrawShading (state->cgDrawContext, state->shading); - return; - } - - CGContextTranslateCTM (state->cgDrawContext, 0, state->rect.size.height); - CGContextScaleCTM (state->cgDrawContext, 1, -1); - - if (state->action == DO_IMAGE) { - CGContextDrawImage (state->cgDrawContext, state->rect, state->image); - if (op == CAIRO_OPERATOR_SOURCE && - state->cgDrawContext == state->cgMaskContext) - { - CGContextBeginPath (state->cgDrawContext); - CGContextAddRect (state->cgDrawContext, state->rect); - - CGContextTranslateCTM (state->cgDrawContext, 0, state->rect.size.height); - CGContextScaleCTM (state->cgDrawContext, 1, -1); - CGContextConcatCTM (state->cgDrawContext, - CGAffineTransformInvert (state->transform)); - - CGContextAddRect (state->cgDrawContext, state->clipRect); - - CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 0); - CGContextEOFillPath (state->cgDrawContext); - } - } else { - CGContextDrawTiledImagePtr (state->cgDrawContext, state->rect, state->image); - } -} - -static cairo_image_surface_t * -_cairo_quartz_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; - unsigned int stride, bitinfo, bpp, color_comps; - CGColorSpaceRef colorspace; - void *imageData; - cairo_format_t format; - - if (surface->imageSurfaceEquiv) - return _cairo_surface_map_to_image (surface->imageSurfaceEquiv, extents); - - if (IS_EMPTY (surface)) - return (cairo_image_surface_t *) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); - - if (! _cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) - return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - bitinfo = CGBitmapContextGetBitmapInfo (surface->cgContext); - bpp = CGBitmapContextGetBitsPerPixel (surface->cgContext); - - // let's hope they don't add YUV under us - colorspace = CGBitmapContextGetColorSpace (surface->cgContext); - color_comps = CGColorSpaceGetNumberOfComponents (colorspace); - - /* XXX TODO: We can handle many more data formats by - * converting to pixman_format_t */ - - if (bpp == 32 && color_comps == 3 && - (bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst && - (bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host) - { - format = CAIRO_FORMAT_ARGB32; - } - else if (bpp == 32 && color_comps == 3 && - (bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst && - (bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host) - { - format = CAIRO_FORMAT_RGB24; - } - else if (bpp == 8 && color_comps == 1) - { - format = CAIRO_FORMAT_A1; - } - else - { - return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - imageData = CGBitmapContextGetData (surface->cgContext); - stride = CGBitmapContextGetBytesPerRow (surface->cgContext); - - return (cairo_image_surface_t *) cairo_image_surface_create_for_data (imageData, - format, - extents->width, - extents->height, - stride); -} - -static cairo_int_status_t -_cairo_quartz_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; - - if (surface->imageSurfaceEquiv) - return _cairo_surface_unmap_image (surface->imageSurfaceEquiv, image); - - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return CAIRO_STATUS_SUCCESS; -} - - -/* - * Cairo surface backend implementations - */ - -static cairo_status_t -_cairo_quartz_surface_finish (void *abstract_surface) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; - - ND ((stderr, "_cairo_quartz_surface_finish[%p] cgc: %p\n", surface, surface->cgContext)); - - if (IS_EMPTY (surface)) - return CAIRO_STATUS_SUCCESS; - - /* Restore our saved gstate that we use to reset clipping */ - CGContextRestoreGState (surface->cgContext); - _cairo_surface_clipper_reset (&surface->clipper); - - CGContextRelease (surface->cgContext); - - surface->cgContext = NULL; - - if (surface->imageSurfaceEquiv) { - cairo_surface_destroy (surface->imageSurfaceEquiv); - surface->imageSurfaceEquiv = NULL; - } - - free (surface->imageData); - surface->imageData = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_quartz_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; - - //ND ((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface)); - - *image_extra = NULL; - - *image_out = _cairo_quartz_surface_map_to_image (surface, &surface->extents); - if (unlikely (cairo_surface_status(&(*image_out)->base))) { - cairo_surface_destroy (&(*image_out)->base); - *image_out = NULL; - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_quartz_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - _cairo_quartz_surface_unmap_image (abstract_surface, image); -} - -static cairo_surface_t * -_cairo_quartz_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_quartz_surface_t *surface, *similar_quartz; - cairo_surface_t *similar; - cairo_format_t format; - - if (content == CAIRO_CONTENT_COLOR_ALPHA) - format = CAIRO_FORMAT_ARGB32; - else if (content == CAIRO_CONTENT_COLOR) - format = CAIRO_FORMAT_RGB24; - else if (content == CAIRO_CONTENT_ALPHA) - format = CAIRO_FORMAT_A8; - else - return NULL; - - // verify width and height of surface - if (!_cairo_quartz_verify_surface_size (width, height)) { - return _cairo_surface_create_in_error (_cairo_error - (CAIRO_STATUS_INVALID_SIZE)); - } - - similar = cairo_quartz_surface_create (format, width, height); - if (unlikely (similar->status)) - return similar; - - surface = (cairo_quartz_surface_t *) abstract_surface; - similar_quartz = (cairo_quartz_surface_t *) similar; - similar_quartz->virtual_extents = surface->virtual_extents; - - return similar; -} - -static cairo_bool_t -_cairo_quartz_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; - - *extents = surface->extents; - return TRUE; -} - -static cairo_int_status_t -_cairo_quartz_cg_paint (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_quartz_drawing_state_t state; - cairo_int_status_t rv; - - ND ((stderr, "%p _cairo_quartz_surface_paint op %d source->type %d\n", - extents->surface, extents->op, extents->source_pattern.base.type)); - - rv = _cairo_quartz_setup_state (&state, extents); - if (unlikely (rv)) - goto BAIL; - - _cairo_quartz_draw_source (&state, extents->op); - -BAIL: - _cairo_quartz_teardown_state (&state, extents); - - ND ((stderr, "-- paint\n")); - return rv; -} - -static cairo_int_status_t -_cairo_quartz_cg_mask_with_surface (cairo_composite_rectangles_t *extents, - cairo_surface_t *mask_surf, - const cairo_matrix_t *mask_mat, - CGInterpolationQuality filter) -{ - CGRect rect; - CGImageRef img; - cairo_status_t status; - CGAffineTransform mask_matrix; - cairo_quartz_drawing_state_t state; - cairo_format_t format = _cairo_format_from_content (extents->surface->content); - cairo_rectangle_int_t dest_extents; - cairo_matrix_t m = *mask_mat; - - _cairo_surface_get_extents (extents->surface, &dest_extents); - status = _cairo_surface_to_cgimage (mask_surf, &dest_extents, format, - &m, extents->clip, &img); - if (unlikely (status)) - return status; - - status = _cairo_quartz_setup_state (&state, extents); - if (unlikely (status)) - goto BAIL; - - rect = CGRectMake (0.0, 0.0, CGImageGetWidth (img), CGImageGetHeight (img)); - _cairo_quartz_cairo_matrix_to_quartz (&m, &mask_matrix); - - /* ClipToMask is essentially drawing an image, so we need to flip the CTM - * to get the image to appear oriented the right way */ - CGContextConcatCTM (state.cgMaskContext, CGAffineTransformInvert (mask_matrix)); - CGContextTranslateCTM (state.cgMaskContext, 0.0, rect.size.height); - CGContextScaleCTM (state.cgMaskContext, 1.0, -1.0); - - state.filter = filter; - - CGContextSetInterpolationQuality (state.cgMaskContext, filter); - CGContextSetShouldAntialias (state.cgMaskContext, filter != kCGInterpolationNone); - - CGContextClipToMask (state.cgMaskContext, rect, img); - - CGContextScaleCTM (state.cgMaskContext, 1.0, -1.0); - CGContextTranslateCTM (state.cgMaskContext, 0.0, -rect.size.height); - CGContextConcatCTM (state.cgMaskContext, mask_matrix); - - _cairo_quartz_draw_source (&state, extents->op); - -BAIL: - _cairo_quartz_teardown_state (&state, extents); - - CGImageRelease (img); - - return status; -} - -static cairo_int_status_t -_cairo_quartz_cg_mask_with_solid (cairo_quartz_surface_t *surface, - cairo_composite_rectangles_t *extents) -{ - cairo_quartz_drawing_state_t state; - double alpha = extents->mask_pattern.solid.color.alpha; - cairo_status_t status; - - status = _cairo_quartz_setup_state (&state, extents); - if (unlikely (status)) - return status; - - CGContextSetAlpha (surface->cgContext, alpha); - _cairo_quartz_draw_source (&state, extents->op); - - _cairo_quartz_teardown_state (&state, extents); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_quartz_cg_mask (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *)extents->surface; - const cairo_pattern_t *source = &extents->source_pattern.base; - const cairo_pattern_t *mask = &extents->mask_pattern.base; - cairo_surface_t *mask_surf; - cairo_matrix_t matrix; - cairo_status_t status; - cairo_bool_t need_temp; - CGInterpolationQuality filter; - - ND ((stderr, "%p _cairo_quartz_surface_mask op %d source->type %d mask->type %d\n", - extents->surface, extents->op, extents->source_pattern.base.type, - extents->mask_pattern.base.type)); - - if (mask->type == CAIRO_PATTERN_TYPE_SOLID) - return _cairo_quartz_cg_mask_with_solid (surface, extents); - - need_temp = (mask->type != CAIRO_PATTERN_TYPE_SURFACE || - mask->extend != CAIRO_EXTEND_NONE); - - filter = _cairo_quartz_filter_to_quartz (source->filter); - - if (! need_temp) { - mask_surf = extents->mask_pattern.surface.surface; - - /* When an opaque surface used as a mask in Quartz, its - * luminosity is used as the alpha value, so we con only use - * surfaces with alpha without creating a temporary mask. */ - need_temp = ! (mask_surf->content & CAIRO_CONTENT_ALPHA); - } - - if (! need_temp) { - CGInterpolationQuality mask_filter; - cairo_bool_t simple_transform; - - matrix = mask->matrix; - - mask_filter = _cairo_quartz_filter_to_quartz (mask->filter); - if (mask_filter == kCGInterpolationNone) { - simple_transform = _cairo_matrix_is_translation (&matrix); - if (simple_transform) { - matrix.x0 = ceil (matrix.x0 - 0.5); - matrix.y0 = ceil (matrix.y0 - 0.5); - } - } else { - simple_transform = _cairo_matrix_is_integer_translation (&matrix, - NULL, - NULL); - } - - /* Quartz only allows one interpolation to be set for mask and - * source, so we can skip the temp surface only if the source - * filtering makes the mask look correct. */ - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) - need_temp = ! (simple_transform || filter == mask_filter); - else - filter = mask_filter; - } - - if (need_temp) { - /* Render the mask to a surface */ - mask_surf = _cairo_quartz_surface_create_similar (surface, - CAIRO_CONTENT_ALPHA, - surface->extents.width, - surface->extents.height); - status = mask_surf->status; - if (unlikely (status)) - goto BAIL; - - /* mask_surf is clear, so use OVER instead of SOURCE to avoid a - * temporary layer or fallback to cairo-image. */ - status = _cairo_surface_paint (mask_surf, CAIRO_OPERATOR_OVER, mask, NULL); - if (unlikely (status)) - goto BAIL; - - cairo_matrix_init_identity (&matrix); - } - - status = _cairo_quartz_cg_mask_with_surface (extents, - mask_surf, &matrix, filter); - -BAIL: - - if (need_temp) - cairo_surface_destroy (mask_surf); - - return status; -} - -static cairo_int_status_t -_cairo_quartz_cg_fill (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_quartz_drawing_state_t state; - cairo_int_status_t rv = CAIRO_STATUS_SUCCESS; - - ND ((stderr, "%p _cairo_quartz_surface_fill op %d source->type %d\n", - extents->surface, extents->op, extents->source_pattern.base.type)); - - rv = _cairo_quartz_setup_state (&state, extents); - if (unlikely (rv)) - goto BAIL; - - CGContextSetShouldAntialias (state.cgMaskContext, (antialias != CAIRO_ANTIALIAS_NONE)); - - _cairo_quartz_cairo_path_to_quartz_context (path, state.cgMaskContext); - - if (state.action == DO_DIRECT) { - assert (state.cgDrawContext == state.cgMaskContext); - if (fill_rule == CAIRO_FILL_RULE_WINDING) - CGContextFillPath (state.cgMaskContext); - else - CGContextEOFillPath (state.cgMaskContext); - } else { - if (fill_rule == CAIRO_FILL_RULE_WINDING) - CGContextClip (state.cgMaskContext); - else - CGContextEOClip (state.cgMaskContext); - - _cairo_quartz_draw_source (&state, extents->op); - } - -BAIL: - _cairo_quartz_teardown_state (&state, extents); - - ND ((stderr, "-- fill\n")); - return rv; -} - -static cairo_int_status_t -_cairo_quartz_cg_stroke (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_quartz_drawing_state_t state; - cairo_int_status_t rv = CAIRO_STATUS_SUCCESS; - CGAffineTransform strokeTransform, invStrokeTransform; - - ND ((stderr, "%p _cairo_quartz_surface_stroke op %d source->type %d\n", - extents->surface, extents->op, extents->source_pattern.base.type)); - - rv = _cairo_quartz_setup_state (&state, extents); - if (unlikely (rv)) - goto BAIL; - - // Turning antialiasing off used to cause misrendering with - // single-pixel lines (e.g. 20,10.5 -> 21,10.5 end up being rendered as 2 pixels). - // That's been since fixed in at least 10.5, and in the latest 10.4 dot releases. - CGContextSetShouldAntialias (state.cgMaskContext, (antialias != CAIRO_ANTIALIAS_NONE)); - CGContextSetLineWidth (state.cgMaskContext, style->line_width); - CGContextSetLineCap (state.cgMaskContext, _cairo_quartz_cairo_line_cap_to_quartz (style->line_cap)); - CGContextSetLineJoin (state.cgMaskContext, _cairo_quartz_cairo_line_join_to_quartz (style->line_join)); - CGContextSetMiterLimit (state.cgMaskContext, style->miter_limit); - - if (style->dash && style->num_dashes) { - cairo_quartz_float_t sdash[CAIRO_STACK_ARRAY_LENGTH (cairo_quartz_float_t)]; - cairo_quartz_float_t *fdash = sdash; - unsigned int max_dashes = style->num_dashes; - unsigned int k; - - if (style->num_dashes%2) - max_dashes *= 2; - if (max_dashes > ARRAY_LENGTH (sdash)) - fdash = _cairo_malloc_ab (max_dashes, sizeof (cairo_quartz_float_t)); - if (unlikely (fdash == NULL)) { - rv = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - - for (k = 0; k < max_dashes; k++) - fdash[k] = (cairo_quartz_float_t) style->dash[k % style->num_dashes]; - - CGContextSetLineDash (state.cgMaskContext, style->dash_offset, fdash, max_dashes); - if (fdash != sdash) - free (fdash); - } else - CGContextSetLineDash (state.cgMaskContext, 0, NULL, 0); - - _cairo_quartz_cairo_path_to_quartz_context (path, state.cgMaskContext); - - _cairo_quartz_cairo_matrix_to_quartz (ctm, &strokeTransform); - CGContextConcatCTM (state.cgMaskContext, strokeTransform); - - if (state.action == DO_DIRECT) { - assert (state.cgDrawContext == state.cgMaskContext); - CGContextStrokePath (state.cgMaskContext); - } else { - CGContextReplacePathWithStrokedPath (state.cgMaskContext); - CGContextClip (state.cgMaskContext); - - _cairo_quartz_cairo_matrix_to_quartz (ctm_inverse, &invStrokeTransform); - CGContextConcatCTM (state.cgMaskContext, invStrokeTransform); - - _cairo_quartz_draw_source (&state, extents->op); - } - -BAIL: - _cairo_quartz_teardown_state (&state, extents); - - ND ((stderr, "-- stroke\n")); - return rv; -} - -#if CAIRO_HAS_QUARTZ_FONT -static cairo_int_status_t -_cairo_quartz_cg_glyphs (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - CGAffineTransform textTransform, invTextTransform; - CGGlyph glyphs_static[CAIRO_STACK_ARRAY_LENGTH (CGSize)]; - CGSize cg_advances_static[CAIRO_STACK_ARRAY_LENGTH (CGSize)]; - CGGlyph *cg_glyphs = &glyphs_static[0]; - CGSize *cg_advances = &cg_advances_static[0]; - COMPILE_TIME_ASSERT (sizeof (CGGlyph) <= sizeof (CGSize)); - - cairo_quartz_drawing_state_t state; - cairo_int_status_t rv = CAIRO_INT_STATUS_UNSUPPORTED; - cairo_quartz_float_t xprev, yprev; - int i; - CGFontRef cgfref = NULL; - - cairo_bool_t didForceFontSmoothing = FALSE; - - if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ) - return CAIRO_INT_STATUS_UNSUPPORTED; - - rv = _cairo_quartz_setup_state (&state, extents); - if (unlikely (rv)) - goto BAIL; - - if (state.action == DO_DIRECT) { - assert (state.cgDrawContext == state.cgMaskContext); - CGContextSetTextDrawingMode (state.cgMaskContext, kCGTextFill); - } else { - CGContextSetTextDrawingMode (state.cgMaskContext, kCGTextClip); - } - - /* this doesn't addref */ - cgfref = _cairo_quartz_scaled_font_get_cg_font_ref (scaled_font); - CGContextSetFont (state.cgMaskContext, cgfref); - CGContextSetFontSize (state.cgMaskContext, 1.0); - - switch (scaled_font->options.antialias) { - case CAIRO_ANTIALIAS_SUBPIXEL: - case CAIRO_ANTIALIAS_BEST: - CGContextSetShouldAntialias (state.cgMaskContext, TRUE); - CGContextSetShouldSmoothFonts (state.cgMaskContext, TRUE); - if (CGContextSetAllowsFontSmoothingPtr && - !CGContextGetAllowsFontSmoothingPtr (state.cgMaskContext)) - { - didForceFontSmoothing = TRUE; - CGContextSetAllowsFontSmoothingPtr (state.cgMaskContext, TRUE); - } - break; - case CAIRO_ANTIALIAS_NONE: - CGContextSetShouldAntialias (state.cgMaskContext, FALSE); - break; - case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_GOOD: - case CAIRO_ANTIALIAS_FAST: - CGContextSetShouldAntialias (state.cgMaskContext, TRUE); - CGContextSetShouldSmoothFonts (state.cgMaskContext, FALSE); - break; - case CAIRO_ANTIALIAS_DEFAULT: - /* Don't do anything */ - break; - } - - if (num_glyphs > ARRAY_LENGTH (glyphs_static)) { - cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof (CGGlyph) + sizeof (CGSize)); - if (unlikely (cg_glyphs == NULL)) { - rv = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - - cg_advances = (CGSize*) (cg_glyphs + num_glyphs); - } - - /* scale(1,-1) * scaled_font->scale */ - textTransform = CGAffineTransformMake (scaled_font->scale.xx, - scaled_font->scale.yx, - -scaled_font->scale.xy, - -scaled_font->scale.yy, - 0.0, 0.0); - - /* scaled_font->scale_inverse * scale(1,-1) */ - invTextTransform = CGAffineTransformMake (scaled_font->scale_inverse.xx, - -scaled_font->scale_inverse.yx, - scaled_font->scale_inverse.xy, - -scaled_font->scale_inverse.yy, - 0.0, 0.0); - - CGContextSetTextPosition (state.cgMaskContext, 0.0, 0.0); - CGContextSetTextMatrix (state.cgMaskContext, CGAffineTransformIdentity); - - /* Convert our glyph positions to glyph advances. We need n-1 advances, - * since the advance at index 0 is applied after glyph 0. */ - xprev = glyphs[0].x; - yprev = glyphs[0].y; - - cg_glyphs[0] = glyphs[0].index; - - for (i = 1; i < num_glyphs; i++) { - cairo_quartz_float_t xf = glyphs[i].x; - cairo_quartz_float_t yf = glyphs[i].y; - cg_glyphs[i] = glyphs[i].index; - cg_advances[i - 1] = CGSizeApplyAffineTransform (CGSizeMake (xf - xprev, yf - yprev), invTextTransform); - xprev = xf; - yprev = yf; - } - - /* Translate to the first glyph's position before drawing */ - CGContextTranslateCTM (state.cgMaskContext, glyphs[0].x, glyphs[0].y); - CGContextConcatCTM (state.cgMaskContext, textTransform); - - CGContextShowGlyphsWithAdvances (state.cgMaskContext, - cg_glyphs, - cg_advances, - num_glyphs); - - CGContextConcatCTM (state.cgMaskContext, invTextTransform); - CGContextTranslateCTM (state.cgMaskContext, -glyphs[0].x, -glyphs[0].y); - - if (state.action != DO_DIRECT) - _cairo_quartz_draw_source (&state, extents->op); - -BAIL: - if (didForceFontSmoothing) - CGContextSetAllowsFontSmoothingPtr (state.cgMaskContext, FALSE); - - _cairo_quartz_teardown_state (&state, extents); - - if (cg_glyphs != glyphs_static) - free (cg_glyphs); - - return rv; -} -#endif /* CAIRO_HAS_QUARTZ_FONT */ - -static const cairo_compositor_t _cairo_quartz_cg_compositor = { - &_cairo_fallback_compositor, - - _cairo_quartz_cg_paint, - _cairo_quartz_cg_mask, - _cairo_quartz_cg_stroke, - _cairo_quartz_cg_fill, -#if CAIRO_HAS_QUARTZ_FONT - _cairo_quartz_cg_glyphs, -#else - NULL, -#endif -}; - -static cairo_int_status_t -_cairo_quartz_surface_paint (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - return _cairo_compositor_paint (&_cairo_quartz_cg_compositor, - surface, op, source, clip); -} - -static cairo_int_status_t -_cairo_quartz_surface_mask (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - return _cairo_compositor_mask (&_cairo_quartz_cg_compositor, - surface, op, source, mask, - clip); -} - -static cairo_int_status_t -_cairo_quartz_surface_fill (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - return _cairo_compositor_fill (&_cairo_quartz_cg_compositor, - surface, op, source, path, - fill_rule, tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_quartz_surface_stroke (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - return _cairo_compositor_stroke (&_cairo_quartz_cg_compositor, - surface, op, source, path, - style, ctm,ctm_inverse, - tolerance, antialias, clip); -} - -static cairo_int_status_t -_cairo_quartz_surface_glyphs (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - return _cairo_compositor_glyphs (&_cairo_quartz_cg_compositor, - surface, op, source, - glyphs, num_glyphs, scaled_font, - clip); -} - -static cairo_status_t -_cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_quartz_surface_t *surface = - cairo_container_of (clipper, cairo_quartz_surface_t, clipper); - - ND ((stderr, "%p _cairo_quartz_surface_intersect_clip_path path: %p\n", surface, path)); - - if (IS_EMPTY (surface)) - return CAIRO_STATUS_SUCCESS; - - if (path == NULL) { - /* If we're being asked to reset the clip, we can only do it - * by restoring the gstate to our previous saved one, and - * saving it again. - * - * Note that this assumes that ALL quartz surface creation - * functions will do a SaveGState first; we do this in create_internal. - */ - CGContextRestoreGState (surface->cgContext); - CGContextSaveGState (surface->cgContext); - } else { - CGContextSetShouldAntialias (surface->cgContext, (antialias != CAIRO_ANTIALIAS_NONE)); - - _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext); - - if (fill_rule == CAIRO_FILL_RULE_WINDING) - CGContextClip (surface->cgContext); - else - CGContextEOClip (surface->cgContext); - } - - ND ((stderr, "-- intersect_clip_path\n")); - - return CAIRO_STATUS_SUCCESS; -} - -// XXXtodo implement show_page; need to figure out how to handle begin/end - -static const struct _cairo_surface_backend cairo_quartz_surface_backend = { - CAIRO_SURFACE_TYPE_QUARTZ, - _cairo_quartz_surface_finish, - - _cairo_default_context_create, - - _cairo_quartz_surface_create_similar, - NULL, /* similar image */ - _cairo_quartz_surface_map_to_image, - _cairo_quartz_surface_unmap_image, - - _cairo_surface_default_source, - _cairo_quartz_surface_acquire_source_image, - _cairo_quartz_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_quartz_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_quartz_surface_paint, - _cairo_quartz_surface_mask, - _cairo_quartz_surface_stroke, - _cairo_quartz_surface_fill, - NULL, /* fill-stroke */ - _cairo_quartz_surface_glyphs, -}; - -cairo_quartz_surface_t * -_cairo_quartz_surface_create_internal (CGContextRef cgContext, - cairo_content_t content, - unsigned int width, - unsigned int height) -{ - cairo_quartz_surface_t *surface; - - quartz_ensure_symbols (); - - /* Init the base surface */ - surface = malloc (sizeof (cairo_quartz_surface_t)); - if (unlikely (surface == NULL)) - return (cairo_quartz_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - memset (surface, 0, sizeof (cairo_quartz_surface_t)); - - _cairo_surface_init (&surface->base, - &cairo_quartz_surface_backend, - NULL, /* device */ - content); - - _cairo_surface_clipper_init (&surface->clipper, - _cairo_quartz_surface_clipper_intersect_clip_path); - - /* Save our extents */ - surface->extents.x = surface->extents.y = 0; - surface->extents.width = width; - surface->extents.height = height; - surface->virtual_extents = surface->extents; - - if (IS_EMPTY (surface)) { - surface->cgContext = NULL; - surface->cgContextBaseCTM = CGAffineTransformIdentity; - surface->imageData = NULL; - surface->base.is_clear = TRUE; - return surface; - } - - /* Save so we can always get back to a known-good CGContext -- this is - * required for proper behaviour of intersect_clip_path(NULL) - */ - CGContextSaveGState (cgContext); - - surface->cgContext = cgContext; - surface->cgContextBaseCTM = CGContextGetCTM (cgContext); - - surface->imageData = NULL; - surface->imageSurfaceEquiv = NULL; - - return surface; -} - -/** - * cairo_quartz_surface_create_for_cg_context: - * @cgContext: the existing CGContext for which to create the surface - * @width: width of the surface, in pixels - * @height: height of the surface, in pixels - * - * Creates a Quartz surface that wraps the given CGContext. The - * CGContext is assumed to be in the standard Cairo coordinate space - * (that is, with the origin at the upper left and the Y axis - * increasing downward). If the CGContext is in the Quartz coordinate - * space (with the origin at the bottom left), then it should be - * flipped before this function is called. The flip can be accomplished - * using a translate and a scale; for example: - * - * - * CGContextTranslateCTM (cgContext, 0.0, height); - * CGContextScaleCTM (cgContext, 1.0, -1.0); - * - * - * All Cairo operations are implemented in terms of Quartz operations, - * as long as Quartz-compatible elements are used (such as Quartz fonts). - * - * Return value: the newly created Cairo surface. - * - * Since: 1.6 - **/ - -cairo_surface_t * -cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext, - unsigned int width, - unsigned int height) -{ - cairo_quartz_surface_t *surf; - - surf = _cairo_quartz_surface_create_internal (cgContext, CAIRO_CONTENT_COLOR_ALPHA, - width, height); - if (likely (!surf->base.status)) - CGContextRetain (cgContext); - - return &surf->base; -} - -/** - * cairo_quartz_surface_create: - * @format: format of pixels in the surface to create - * @width: width of the surface, in pixels - * @height: height of the surface, in pixels - * - * Creates a Quartz surface backed by a CGBitmap. The surface is - * created using the Device RGB (or Device Gray, for A8) color space. - * All Cairo operations, including those that require software - * rendering, will succeed on this surface. - * - * Return value: the newly created surface. - * - * Since: 1.6 - **/ -cairo_surface_t * -cairo_quartz_surface_create (cairo_format_t format, - unsigned int width, - unsigned int height) -{ - cairo_quartz_surface_t *surf; - CGContextRef cgc; - CGColorSpaceRef cgColorspace; - CGBitmapInfo bitinfo; - void *imageData; - int stride; - int bitsPerComponent; - - if (!_cairo_quartz_verify_surface_size (width, height)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - if (width == 0 || height == 0) { - return &_cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format), - width, height)->base; - } - - if (format == CAIRO_FORMAT_ARGB32 || - format == CAIRO_FORMAT_RGB24) - { - cgColorspace = CGColorSpaceCreateDeviceRGB (); - bitinfo = kCGBitmapByteOrder32Host; - if (format == CAIRO_FORMAT_ARGB32) - bitinfo |= kCGImageAlphaPremultipliedFirst; - else - bitinfo |= kCGImageAlphaNoneSkipFirst; - bitsPerComponent = 8; - stride = width * 4; - } else if (format == CAIRO_FORMAT_A8) { - cgColorspace = NULL; - stride = width; - bitinfo = kCGImageAlphaOnly; - bitsPerComponent = 8; - } else if (format == CAIRO_FORMAT_A1) { - /* I don't think we can usefully support this, as defined by - * cairo_format_t -- these are 1-bit pixels stored in 32-bit - * quantities. - */ - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - } else { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - } - - /* The Apple docs say that for best performance, the stride and the data - * pointer should be 16-byte aligned. malloc already aligns to 16-bytes, - * so we don't have to anything special on allocation. - */ - stride = (stride + 15) & ~15; - - imageData = _cairo_malloc_ab (height, stride); - if (unlikely (!imageData)) { - CGColorSpaceRelease (cgColorspace); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - /* zero the memory to match the image surface behaviour */ - memset (imageData, 0, height * stride); - - cgc = CGBitmapContextCreate (imageData, - width, - height, - bitsPerComponent, - stride, - cgColorspace, - bitinfo); - CGColorSpaceRelease (cgColorspace); - - if (!cgc) { - free (imageData); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - /* flip the Y axis */ - CGContextTranslateCTM (cgc, 0.0, height); - CGContextScaleCTM (cgc, 1.0, -1.0); - - surf = _cairo_quartz_surface_create_internal (cgc, _cairo_content_from_format (format), - width, height); - if (surf->base.status) { - CGContextRelease (cgc); - free (imageData); - // create_internal will have set an error - return &surf->base; - } - - surf->base.is_clear = TRUE; - - surf->imageData = imageData; - surf->imageSurfaceEquiv = cairo_image_surface_create_for_data (imageData, format, width, height, stride); - - return &surf->base; -} - -/** - * cairo_quartz_surface_get_cg_context: - * @surface: the Cairo Quartz surface - * - * Returns the CGContextRef that the given Quartz surface is backed - * by. - * - * A call to cairo_surface_flush() is required before using the - * CGContextRef to ensure that all pending drawing operations are - * finished and to restore any temporary modification cairo has made - * to its state. A call to cairo_surface_mark_dirty() is required - * after the state or the content of the CGContextRef has been - * modified. - * - * Return value: the CGContextRef for the given surface. - * - * Since: 1.6 - **/ -CGContextRef -cairo_quartz_surface_get_cg_context (cairo_surface_t *surface) -{ - if (surface && _cairo_surface_is_quartz (surface)) { - cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t *) surface; - return quartz->cgContext; - } else - return NULL; -} - -/** - * _cairo_surface_is_quartz: - * @surface: a #cairo_surface_t - * - * Checks if a surface is a #cairo_quartz_surface_t - * - * Return value: True if the surface is an quartz surface - **/ -cairo_bool_t -_cairo_surface_is_quartz (const cairo_surface_t *surface) -{ - return surface->backend == &cairo_quartz_surface_backend; -} - -/* Debug stuff */ - -#ifdef QUARTZ_DEBUG - -#include - -void ExportCGImageToPNGFile (CGImageRef inImageRef, char* dest) -{ - Handle dataRef = NULL; - OSType dataRefType; - CFStringRef inPath = CFStringCreateWithCString (NULL, dest, kCFStringEncodingASCII); - - GraphicsExportComponent grex = 0; - unsigned long sizeWritten; - - ComponentResult result; - - // create the data reference - result = QTNewDataReferenceFromFullPathCFString (inPath, kQTNativeDefaultPathStyle, - 0, &dataRef, &dataRefType); - - if (NULL != dataRef && noErr == result) { - // get the PNG exporter - result = OpenADefaultComponent (GraphicsExporterComponentType, kQTFileTypePNG, - &grex); - - if (grex) { - // tell the exporter where to find its source image - result = GraphicsExportSetInputCGImage (grex, inImageRef); - - if (noErr == result) { - // tell the exporter where to save the exporter image - result = GraphicsExportSetOutputDataReference (grex, dataRef, - dataRefType); - - if (noErr == result) { - // write the PNG file - result = GraphicsExportDoExport (grex, &sizeWritten); - } - } - - // remember to close the component - CloseComponent (grex); - } - - // remember to dispose of the data reference handle - DisposeHandle (dataRef); - } -} - -void -quartz_image_to_png (CGImageRef imgref, char *dest) -{ - static int sctr = 0; - char sptr[] = "/Users/vladimir/Desktop/barXXXXX.png"; - - if (dest == NULL) { - fprintf (stderr, "** Writing %p to bar%d\n", imgref, sctr); - sprintf (sptr, "/Users/vladimir/Desktop/bar%d.png", sctr); - sctr++; - dest = sptr; - } - - ExportCGImageToPNGFile (imgref, dest); -} - -void -quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest) -{ - static int sctr = 0; - char sptr[] = "/Users/vladimir/Desktop/fooXXXXX.png"; - - if (nq->base.type != CAIRO_SURFACE_TYPE_QUARTZ) { - fprintf (stderr, "** quartz_surface_to_png: surface %p isn't quartz!\n", nq); - return; - } - - if (dest == NULL) { - fprintf (stderr, "** Writing %p to foo%d\n", nq, sctr); - sprintf (sptr, "/Users/vladimir/Desktop/foo%d.png", sctr); - sctr++; - dest = sptr; - } - - CGImageRef imgref = CGBitmapContextCreateImage (nq->cgContext); - if (imgref == NULL) { - fprintf (stderr, "quartz surface at %p is not a bitmap context!\n", nq); - return; - } - - ExportCGImageToPNGFile (imgref, dest); - - CGImageRelease (imgref); -} - -#endif /* QUARTZ_DEBUG */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz.h deleted file mode 100644 index 9be5f9ae5cf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-quartz.h +++ /dev/null @@ -1,82 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright 2006, 2007 Mozilla Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * - * Contributor(s): - * Vladimir Vukicevic - */ - -#ifndef CAIRO_QUARTZ_H -#define CAIRO_QUARTZ_H - -#include "cairo.h" - -#if CAIRO_HAS_QUARTZ_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_quartz_surface_create (cairo_format_t format, - unsigned int width, - unsigned int height); - -cairo_public cairo_surface_t * -cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext, - unsigned int width, - unsigned int height); - -cairo_public CGContextRef -cairo_quartz_surface_get_cg_context (cairo_surface_t *surface); - -#if CAIRO_HAS_QUARTZ_FONT - -/* - * Quartz font support - */ - -cairo_public cairo_font_face_t * -cairo_quartz_font_face_create_for_cgfont (CGFontRef font); - -cairo_public cairo_font_face_t * -cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id); - -#endif /* CAIRO_HAS_QUARTZ_FONT */ - -CAIRO_END_DECLS - -#else - -# error Cairo was not compiled with support for the quartz backend - -#endif /* CAIRO_HAS_QUARTZ_SURFACE */ - -#endif /* CAIRO_QUARTZ_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-raster-source-pattern.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-raster-source-pattern.c deleted file mode 100644 index 64520feae52..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-raster-source-pattern.c +++ /dev/null @@ -1,430 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-error-private.h" -#include "cairo-pattern-private.h" - -/** - * SECTION:cairo-raster-source - * @Title: Raster Sources - * @Short_Description: Supplying arbitrary image data - * @See_Also: #cairo_pattern_t - * - * The raster source provides the ability to supply arbitrary pixel data - * whilst rendering. The pixels are queried at the time of rasterisation - * by means of user callback functions, allowing for the ultimate - * flexibility. For example, in handling compressed image sources, you - * may keep a MRU cache of decompressed images and decompress sources on the - * fly and discard old ones to conserve memory. - * - * For the raster source to be effective, you must at least specify - * the acquire and release callbacks which are used to retrieve the pixel - * data for the region of interest and demark when it can be freed afterwards. - * Other callbacks are provided for when the pattern is copied temporarily - * during rasterisation, or more permanently as a snapshot in order to keep - * the pixel data available for printing. - **/ - -cairo_surface_t * -_cairo_raster_source_pattern_acquire (const cairo_pattern_t *abstract_pattern, - cairo_surface_t *target, - const cairo_rectangle_int_t *extents) -{ - cairo_raster_source_pattern_t *pattern = - (cairo_raster_source_pattern_t *) abstract_pattern; - - if (pattern->acquire == NULL) - return NULL; - - if (extents == NULL) - extents = &pattern->extents; - - return pattern->acquire (&pattern->base, pattern->user_data, - target, extents); -} - -void -_cairo_raster_source_pattern_release (const cairo_pattern_t *abstract_pattern, - cairo_surface_t *surface) -{ - cairo_raster_source_pattern_t *pattern = - (cairo_raster_source_pattern_t *) abstract_pattern; - - if (pattern->release == NULL) - return; - - pattern->release (&pattern->base, pattern->user_data, surface); -} - -cairo_status_t -_cairo_raster_source_pattern_init_copy (cairo_pattern_t *abstract_pattern, - const cairo_pattern_t *other) -{ - cairo_raster_source_pattern_t *pattern = - (cairo_raster_source_pattern_t *) abstract_pattern; - cairo_status_t status; - - VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_raster_source_pattern_t))); - memcpy(pattern, other, sizeof (cairo_raster_source_pattern_t)); - - status = CAIRO_STATUS_SUCCESS; - if (pattern->copy) - status = pattern->copy (&pattern->base, pattern->user_data, other); - - return status; -} - -cairo_status_t -_cairo_raster_source_pattern_snapshot (cairo_pattern_t *abstract_pattern) -{ - cairo_raster_source_pattern_t *pattern = - (cairo_raster_source_pattern_t *) abstract_pattern; - - if (pattern->snapshot == NULL) - return CAIRO_STATUS_SUCCESS; - - return pattern->snapshot (&pattern->base, pattern->user_data); -} - -void -_cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern) -{ - cairo_raster_source_pattern_t *pattern = - (cairo_raster_source_pattern_t *) abstract_pattern; - - if (pattern->finish == NULL) - return; - - pattern->finish (&pattern->base, pattern->user_data); -} - -/* Public interface */ - -/** - * cairo_pattern_create_raster_source: - * @user_data: the user data to be passed to all callbacks - * @content: content type for the pixel data that will be returned. Knowing - * the content type ahead of time is used for analysing the operation and - * picking the appropriate rendering path. - * @width: maximum size of the sample area - * @height: maximum size of the sample area - * - * Creates a new user pattern for providing pixel data. - * - * Use the setter functions to associate callbacks with the returned - * pattern. The only mandatory callback is acquire. - * - * Return value: a newly created #cairo_pattern_t. Free with - * cairo_pattern_destroy() when you are done using it. - * - * Since: 1.12 - **/ -cairo_pattern_t * -cairo_pattern_create_raster_source (void *user_data, - cairo_content_t content, - int width, int height) -{ - cairo_raster_source_pattern_t *pattern; - - CAIRO_MUTEX_INITIALIZE (); - - if (width < 0 || height < 0) - return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_SIZE); - - if (! CAIRO_CONTENT_VALID (content)) - return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_CONTENT); - - pattern = calloc (1, sizeof (*pattern)); - if (unlikely (pattern == NULL)) - return _cairo_pattern_create_in_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_pattern_init (&pattern->base, - CAIRO_PATTERN_TYPE_RASTER_SOURCE); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - - pattern->content = content; - - pattern->extents.x = 0; - pattern->extents.y = 0; - pattern->extents.width = width; - pattern->extents.height = height; - - pattern->user_data = user_data; - - return &pattern->base; -} - -/** - * cairo_raster_source_pattern_set_callback_data: - * @pattern: the pattern to update - * @data: the user data to be passed to all callbacks - * - * Updates the user data that is provided to all callbacks. - * - * Since: 1.12 - **/ -void -cairo_raster_source_pattern_set_callback_data (cairo_pattern_t *abstract_pattern, - void *data) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - pattern->user_data = data; -} - -/** - * cairo_raster_source_pattern_get_callback_data: - * @pattern: the pattern to update - * - * Queries the current user data. - * - * Return value: the current user-data passed to each callback - * - * Since: 1.12 - **/ -void * -cairo_raster_source_pattern_get_callback_data (cairo_pattern_t *abstract_pattern) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return NULL; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - return pattern->user_data; -} - -/** - * cairo_raster_source_pattern_set_acquire: - * @pattern: the pattern to update - * @acquire: acquire callback - * @release: release callback - * - * Specifies the callbacks used to generate the image surface for a rendering - * operation (acquire) and the function used to cleanup that surface afterwards. - * - * The @acquire callback should create a surface (preferably an image - * surface created to match the target using - * cairo_surface_create_similar_image()) that defines at least the region - * of interest specified by extents. The surface is allowed to be the entire - * sample area, but if it does contain a subsection of the sample area, - * the surface extents should be provided by setting the device offset (along - * with its width and height) using cairo_surface_set_device_offset(). - * - * Since: 1.12 - **/ -void -cairo_raster_source_pattern_set_acquire (cairo_pattern_t *abstract_pattern, - cairo_raster_source_acquire_func_t acquire, - cairo_raster_source_release_func_t release) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - pattern->acquire = acquire; - pattern->release = release; -} - -/** - * cairo_raster_source_pattern_get_acquire: - * @pattern: the pattern to query - * @acquire: return value for the current acquire callback - * @release: return value for the current release callback - * - * Queries the current acquire and release callbacks. - * - * Since: 1.12 - **/ -void -cairo_raster_source_pattern_get_acquire (cairo_pattern_t *abstract_pattern, - cairo_raster_source_acquire_func_t *acquire, - cairo_raster_source_release_func_t *release) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - if (acquire) - *acquire = pattern->acquire; - if (release) - *release = pattern->release; -} - -/** - * cairo_raster_source_pattern_set_snapshot: - * @pattern: the pattern to update - * @snapshot: snapshot callback - * - * Sets the callback that will be used whenever a snapshot is taken of the - * pattern, that is whenever the current contents of the pattern should be - * preserved for later use. This is typically invoked whilst printing. - * - * Since: 1.12 - **/ -void -cairo_raster_source_pattern_set_snapshot (cairo_pattern_t *abstract_pattern, - cairo_raster_source_snapshot_func_t snapshot) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - pattern->snapshot = snapshot; -} - -/** - * cairo_raster_source_pattern_get_snapshot: - * @pattern: the pattern to query - * - * Queries the current snapshot callback. - * - * Return value: the current snapshot callback - * - * Since: 1.12 - **/ -cairo_raster_source_snapshot_func_t -cairo_raster_source_pattern_get_snapshot (cairo_pattern_t *abstract_pattern) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return NULL; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - return pattern->snapshot; -} - -/** - * cairo_raster_source_pattern_set_copy: - * @pattern: the pattern to update - * @copy: the copy callback - * - * Updates the copy callback which is used whenever a temporary copy of the - * pattern is taken. - * - * Since: 1.12 - **/ -void -cairo_raster_source_pattern_set_copy (cairo_pattern_t *abstract_pattern, - cairo_raster_source_copy_func_t copy) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - pattern->copy = copy; -} - -/** - * cairo_raster_source_pattern_get_copy: - * @pattern: the pattern to query - * - * Queries the current copy callback. - * - * Return value: the current copy callback - * - * Since: 1.12 - **/ -cairo_raster_source_copy_func_t -cairo_raster_source_pattern_get_copy (cairo_pattern_t *abstract_pattern) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return NULL; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - return pattern->copy; -} - -/** - * cairo_raster_source_pattern_set_finish: - * @pattern: the pattern to update - * @finish: the finish callback - * - * Updates the finish callback which is used whenever a pattern (or a copy - * thereof) will no longer be used. - * - * Since: 1.12 - **/ -void -cairo_raster_source_pattern_set_finish (cairo_pattern_t *abstract_pattern, - cairo_raster_source_finish_func_t finish) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - pattern->finish = finish; -} - -/** - * cairo_raster_source_pattern_get_finish: - * @pattern: the pattern to query - * - * Queries the current finish callback. - * - * Return value: the current finish callback - * - * Since: 1.12 - **/ -cairo_raster_source_finish_func_t -cairo_raster_source_pattern_get_finish (cairo_pattern_t *abstract_pattern) -{ - cairo_raster_source_pattern_t *pattern; - - if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) - return NULL; - - pattern = (cairo_raster_source_pattern_t *) abstract_pattern; - return pattern->finish; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-inline.h deleted file mode 100644 index 9002ccd6938..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-inline.h +++ /dev/null @@ -1,68 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Adrian Johnson - */ - -#ifndef CAIRO_RECORDING_SURFACE_INLINE_H -#define CAIRO_RECORDING_SURFACE_INLINE_H - -#include "cairo-recording-surface-private.h" - -static inline cairo_bool_t -_cairo_recording_surface_get_bounds (cairo_surface_t *surface, - cairo_rectangle_t *extents) -{ - cairo_recording_surface_t *recording = (cairo_recording_surface_t *)surface; - if (recording->unbounded) - return FALSE; - - *extents = recording->extents_pixels; - return TRUE; -} - -/** - * _cairo_surface_is_recording: - * @surface: a #cairo_surface_t - * - * Checks if a surface is a #cairo_recording_surface_t - * - * Return value: %TRUE if the surface is a recording surface - **/ -static inline cairo_bool_t -_cairo_surface_is_recording (const cairo_surface_t *surface) -{ - return surface->backend->type == CAIRO_SURFACE_TYPE_RECORDING; -} - -#endif /* CAIRO_RECORDING_SURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-private.h deleted file mode 100644 index 456c63389b7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface-private.h +++ /dev/null @@ -1,195 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Adrian Johnson - */ - -#ifndef CAIRO_RECORDING_SURFACE_H -#define CAIRO_RECORDING_SURFACE_H - -#include "cairoint.h" -#include "cairo-path-fixed-private.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-backend-private.h" - -typedef enum { - /* The 5 basic drawing operations. */ - CAIRO_COMMAND_PAINT, - CAIRO_COMMAND_MASK, - CAIRO_COMMAND_STROKE, - CAIRO_COMMAND_FILL, - CAIRO_COMMAND_SHOW_TEXT_GLYPHS, -} cairo_command_type_t; - -typedef enum { - CAIRO_RECORDING_REGION_ALL, - CAIRO_RECORDING_REGION_NATIVE, - CAIRO_RECORDING_REGION_IMAGE_FALLBACK -} cairo_recording_region_type_t; - -typedef struct _cairo_command_header { - cairo_command_type_t type; - cairo_recording_region_type_t region; - cairo_operator_t op; - cairo_rectangle_int_t extents; - cairo_clip_t *clip; - - int index; - struct _cairo_command_header *chain; -} cairo_command_header_t; - -typedef struct _cairo_command_paint { - cairo_command_header_t header; - cairo_pattern_union_t source; -} cairo_command_paint_t; - -typedef struct _cairo_command_mask { - cairo_command_header_t header; - cairo_pattern_union_t source; - cairo_pattern_union_t mask; -} cairo_command_mask_t; - -typedef struct _cairo_command_stroke { - cairo_command_header_t header; - cairo_pattern_union_t source; - cairo_path_fixed_t path; - cairo_stroke_style_t style; - cairo_matrix_t ctm; - cairo_matrix_t ctm_inverse; - double tolerance; - cairo_antialias_t antialias; -} cairo_command_stroke_t; - -typedef struct _cairo_command_fill { - cairo_command_header_t header; - cairo_pattern_union_t source; - cairo_path_fixed_t path; - cairo_fill_rule_t fill_rule; - double tolerance; - cairo_antialias_t antialias; -} cairo_command_fill_t; - -typedef struct _cairo_command_show_text_glyphs { - cairo_command_header_t header; - cairo_pattern_union_t source; - char *utf8; - int utf8_len; - cairo_glyph_t *glyphs; - unsigned int num_glyphs; - cairo_text_cluster_t *clusters; - int num_clusters; - cairo_text_cluster_flags_t cluster_flags; - cairo_scaled_font_t *scaled_font; -} cairo_command_show_text_glyphs_t; - -typedef union _cairo_command { - cairo_command_header_t header; - - cairo_command_paint_t paint; - cairo_command_mask_t mask; - cairo_command_stroke_t stroke; - cairo_command_fill_t fill; - cairo_command_show_text_glyphs_t show_text_glyphs; -} cairo_command_t; - -typedef struct _cairo_recording_surface { - cairo_surface_t base; - - /* A recording-surface is logically unbounded, but when used as a - * source we need to render it to an image, so we need a size at - * which to create that image. */ - cairo_rectangle_t extents_pixels; - cairo_rectangle_int_t extents; - cairo_bool_t unbounded; - - cairo_array_t commands; - unsigned int *indices; - unsigned int num_indices; - cairo_bool_t optimize_clears; - cairo_bool_t has_bilevel_alpha; - cairo_bool_t has_only_op_over; - - struct bbtree { - cairo_box_t extents; - struct bbtree *left, *right; - cairo_command_header_t *chain; - } bbtree; -} cairo_recording_surface_t; - -slim_hidden_proto (cairo_recording_surface_create); - -cairo_private cairo_int_status_t -_cairo_recording_surface_get_path (cairo_surface_t *surface, - cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_recording_surface_replay_one (cairo_recording_surface_t *surface, - long unsigned index, - cairo_surface_t *target); - -cairo_private cairo_status_t -_cairo_recording_surface_replay (cairo_surface_t *surface, - cairo_surface_t *target); - -cairo_private cairo_status_t -_cairo_recording_surface_replay_with_clip (cairo_surface_t *surface, - const cairo_matrix_t *surface_transform, - cairo_surface_t *target, - const cairo_clip_t *target_clip); - -cairo_private cairo_status_t -_cairo_recording_surface_replay_and_create_regions (cairo_surface_t *surface, - cairo_surface_t *target); -cairo_private cairo_status_t -_cairo_recording_surface_replay_region (cairo_surface_t *surface, - const cairo_rectangle_int_t *surface_extents, - cairo_surface_t *target, - cairo_recording_region_type_t region); - -cairo_private cairo_status_t -_cairo_recording_surface_get_bbox (cairo_recording_surface_t *recording, - cairo_box_t *bbox, - const cairo_matrix_t *transform); - -cairo_private cairo_status_t -_cairo_recording_surface_get_ink_bbox (cairo_recording_surface_t *surface, - cairo_box_t *bbox, - const cairo_matrix_t *transform); - -cairo_private cairo_bool_t -_cairo_recording_surface_has_only_bilevel_alpha (cairo_recording_surface_t *surface); - -cairo_private cairo_bool_t -_cairo_recording_surface_has_only_op_over (cairo_recording_surface_t *surface); - -#endif /* CAIRO_RECORDING_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface.c deleted file mode 100644 index ce29b936630..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-recording-surface.c +++ /dev/null @@ -1,2188 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * Copyright © 2007 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Carl Worth - * Adrian Johnson - */ - -/** - * SECTION:cairo-recording - * @Title: Recording Surfaces - * @Short_Description: Records all drawing operations - * @See_Also: #cairo_surface_t - * - * A recording surface is a surface that records all drawing operations at - * the highest level of the surface backend interface, (that is, the - * level of paint, mask, stroke, fill, and show_text_glyphs). The recording - * surface can then be "replayed" against any target surface by using it - * as a source surface. - * - * If you want to replay a surface so that the results in target will be - * identical to the results that would have been obtained if the original - * operations applied to the recording surface had instead been applied to the - * target surface, you can use code like this: - * - * cairo_t *cr; - * - * cr = cairo_create (target); - * cairo_set_source_surface (cr, recording_surface, 0.0, 0.0); - * cairo_paint (cr); - * cairo_destroy (cr); - * - * - * A recording surface is logically unbounded, i.e. it has no implicit constraint - * on the size of the drawing surface. However, in practice this is rarely - * useful as you wish to replay against a particular target surface with - * known bounds. For this case, it is more efficient to specify the target - * extents to the recording surface upon creation. - * - * The recording phase of the recording surface is careful to snapshot all - * necessary objects (paths, patterns, etc.), in order to achieve - * accurate replay. The efficiency of the recording surface could be - * improved by improving the implementation of snapshot for the - * various objects. For example, it would be nice to have a - * copy-on-write implementation for _cairo_surface_snapshot. - **/ - -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-analysis-surface-private.h" -#include "cairo-clip-private.h" -#include "cairo-combsort-inline.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-wrapper-private.h" -#include "cairo-traps-private.h" - -typedef enum { - CAIRO_RECORDING_REPLAY, - CAIRO_RECORDING_CREATE_REGIONS -} cairo_recording_replay_type_t; - -static const cairo_surface_backend_t cairo_recording_surface_backend; - -/** - * CAIRO_HAS_RECORDING_SURFACE: - * - * Defined if the recording surface backend is available. - * The recording surface backend is always built in. - * This macro was added for completeness in cairo 1.10. - * - * Since: 1.10 - **/ - -/* Currently all recording surfaces do have a size which should be passed - * in as the maximum size of any target surface against which the - * recording-surface will ever be replayed. - * - * XXX: The naming of "pixels" in the size here is a misnomer. It's - * actually a size in whatever device-space units are desired (again, - * according to the intended replay target). - */ - -static int bbtree_left_or_right (struct bbtree *bbt, - const cairo_box_t *box) -{ - int left, right; - - if (bbt->left) { - cairo_box_t *e = &bbt->left->extents; - cairo_box_t b; - - b.p1.x = MIN (e->p1.x, box->p1.x); - b.p1.y = MIN (e->p1.y, box->p1.y); - b.p2.x = MAX (e->p2.x, box->p2.x); - b.p2.y = MAX (e->p2.y, box->p2.y); - - left = _cairo_fixed_integer_part (b.p2.x - b.p1.x) * _cairo_fixed_integer_part (b.p2.y - b.p1.y); - left -= _cairo_fixed_integer_part (e->p2.x - e->p1.x) * _cairo_fixed_integer_part (e->p2.y - e->p1.y); - } else - left = 0; - - if (bbt->right) { - cairo_box_t *e = &bbt->right->extents; - cairo_box_t b; - - b.p1.x = MIN (e->p1.x, box->p1.x); - b.p1.y = MIN (e->p1.y, box->p1.y); - b.p2.x = MAX (e->p2.x, box->p2.x); - b.p2.y = MAX (e->p2.y, box->p2.y); - - right = _cairo_fixed_integer_part (b.p2.x - b.p1.x) * _cairo_fixed_integer_part (b.p2.y - b.p1.y); - right -= _cairo_fixed_integer_part (e->p2.x - e->p1.x) * _cairo_fixed_integer_part (e->p2.y - e->p1.y); - } else - right = 0; - - return left <= right; -} - -#define INVALID_CHAIN ((cairo_command_header_t *)-1) - -static struct bbtree * -bbtree_new (const cairo_box_t *box, cairo_command_header_t *chain) -{ - struct bbtree *bbt = malloc (sizeof (*bbt)); - if (bbt == NULL) - return NULL; - bbt->extents = *box; - bbt->left = bbt->right = NULL; - bbt->chain = chain; - return bbt; -} - -static void -bbtree_init (struct bbtree *bbt, cairo_command_header_t *header) -{ - _cairo_box_from_rectangle (&bbt->extents, &header->extents); - bbt->chain = header; -} - -static cairo_status_t -bbtree_add (struct bbtree *bbt, - cairo_command_header_t *header, - const cairo_box_t *box) -{ - if (box->p1.x < bbt->extents.p1.x || box->p1.y < bbt->extents.p1.y || - box->p2.x > bbt->extents.p2.x || box->p2.y > bbt->extents.p2.y) - { - if (bbt->chain) { - if (bbtree_left_or_right (bbt, &bbt->extents)) { - if (bbt->left == NULL) { - bbt->left = bbtree_new (&bbt->extents, bbt->chain); - if (unlikely (bbt->left == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - bbtree_add (bbt->left, bbt->chain, &bbt->extents); - } else { - if (bbt->right == NULL) { - bbt->right = bbtree_new (&bbt->extents, bbt->chain); - if (unlikely (bbt->right == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - bbtree_add (bbt->right, bbt->chain, &bbt->extents); - } - - bbt->chain = NULL; - } - - bbt->extents.p1.x = MIN (bbt->extents.p1.x, box->p1.x); - bbt->extents.p1.y = MIN (bbt->extents.p1.y, box->p1.y); - bbt->extents.p2.x = MAX (bbt->extents.p2.x, box->p2.x); - bbt->extents.p2.y = MAX (bbt->extents.p2.y, box->p2.y); - } - - if (box->p1.x == bbt->extents.p1.x && box->p1.y == bbt->extents.p1.y && - box->p2.x == bbt->extents.p2.x && box->p2.y == bbt->extents.p2.y) - { - cairo_command_header_t *last = header; - while (last->chain) /* expected to be infrequent */ - last = last->chain; - last->chain = bbt->chain; - bbt->chain = header; - return CAIRO_STATUS_SUCCESS; - } - - if (bbtree_left_or_right (bbt, box)) { - if (bbt->left == NULL) { - bbt->left = bbtree_new (box, header); - if (unlikely (bbt->left == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - return bbtree_add (bbt->left, header, box); - } else { - if (bbt->right == NULL) { - bbt->right = bbtree_new (box, header); - if (unlikely (bbt->right == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - return bbtree_add (bbt->right, header, box); - } - - return CAIRO_STATUS_SUCCESS; -} - -static void bbtree_del (struct bbtree *bbt) -{ - if (bbt->left) - bbtree_del (bbt->left); - if (bbt->right) - bbtree_del (bbt->right); - - free (bbt); -} - -static cairo_bool_t box_outside (const cairo_box_t *a, const cairo_box_t *b) -{ - return - a->p1.x >= b->p2.x || a->p1.y >= b->p2.y || - a->p2.x <= b->p1.x || a->p2.y <= b->p1.y; -} - -static void -bbtree_foreach_mark_visible (struct bbtree *bbt, - const cairo_box_t *box, - unsigned int **indices) -{ - cairo_command_header_t *chain; - - for (chain = bbt->chain; chain; chain = chain->chain) - *(*indices)++ = chain->index; - - if (bbt->left && ! box_outside (box, &bbt->left->extents)) - bbtree_foreach_mark_visible (bbt->left, box, indices); - if (bbt->right && ! box_outside (box, &bbt->right->extents)) - bbtree_foreach_mark_visible (bbt->right, box, indices); -} - -static inline int intcmp (const unsigned int a, const unsigned int b) -{ - return a - b; -} -CAIRO_COMBSORT_DECLARE (sort_indices, unsigned int, intcmp) - -static inline int sizecmp (unsigned int a, unsigned int b, cairo_command_header_t **elements) -{ - const cairo_rectangle_int_t *r; - - r = &elements[a]->extents; - a = r->width * r->height; - - r = &elements[b]->extents; - b = r->width * r->height; - - return b - a; -} -CAIRO_COMBSORT_DECLARE_WITH_DATA (sort_commands, unsigned int, sizecmp) - -static void -_cairo_recording_surface_destroy_bbtree (cairo_recording_surface_t *surface) -{ - cairo_command_t **elements; - int i, num_elements; - - if (surface->bbtree.chain == INVALID_CHAIN) - return; - - if (surface->bbtree.left) { - bbtree_del (surface->bbtree.left); - surface->bbtree.left = NULL; - } - if (surface->bbtree.right) { - bbtree_del (surface->bbtree.right); - surface->bbtree.right = NULL; - } - - elements = _cairo_array_index (&surface->commands, 0); - num_elements = surface->commands.num_elements; - for (i = 0; i < num_elements; i++) - elements[i]->header.chain = NULL; - - surface->bbtree.chain = INVALID_CHAIN; -} - -static cairo_status_t -_cairo_recording_surface_create_bbtree (cairo_recording_surface_t *surface) -{ - cairo_command_t **elements = _cairo_array_index (&surface->commands, 0); - unsigned int *indices; - cairo_status_t status; - unsigned int i, count; - - count = surface->commands.num_elements; - if (count > surface->num_indices) { - free (surface->indices); - surface->indices = _cairo_malloc_ab (count, sizeof (int)); - if (unlikely (surface->indices == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - surface->num_indices = count; - } - - indices = surface->indices; - for (i = 0; i < count; i++) - indices[i] = i; - - sort_commands (indices, count, elements); - - bbtree_init (&surface->bbtree, &elements[indices[0]]->header); - for (i = 1; i < count; i++) { - cairo_command_header_t *header = &elements[indices[i]]->header; - cairo_box_t box; - - _cairo_box_from_rectangle (&box, &header->extents); - status = bbtree_add (&surface->bbtree, header, &box); - if (unlikely (status)) - goto cleanup; - } - - return CAIRO_STATUS_SUCCESS; - -cleanup: - bbtree_del (&surface->bbtree); - return status; -} - -/** - * cairo_recording_surface_create: - * @content: the content of the recording surface - * @extents: the extents to record in pixels, can be %NULL to record - * unbounded operations. - * - * Creates a recording-surface which can be used to record all drawing operations - * at the highest level (that is, the level of paint, mask, stroke, fill - * and show_text_glyphs). The recording surface can then be "replayed" against - * any target surface by using it as a source to drawing operations. - * - * The recording phase of the recording surface is careful to snapshot all - * necessary objects (paths, patterns, etc.), in order to achieve - * accurate replay. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * Since: 1.10 - **/ -cairo_surface_t * -cairo_recording_surface_create (cairo_content_t content, - const cairo_rectangle_t *extents) -{ - cairo_recording_surface_t *surface; - - surface = malloc (sizeof (cairo_recording_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &cairo_recording_surface_backend, - NULL, /* device */ - content); - - - surface->unbounded = TRUE; - - /* unbounded -> 'infinite' extents */ - if (extents != NULL) { - surface->extents_pixels = *extents; - - /* XXX check for overflow */ - surface->extents.x = floor (extents->x); - surface->extents.y = floor (extents->y); - surface->extents.width = ceil (extents->x + extents->width) - surface->extents.x; - surface->extents.height = ceil (extents->y + extents->height) - surface->extents.y; - - surface->unbounded = FALSE; - } - - _cairo_array_init (&surface->commands, sizeof (cairo_command_t *)); - - surface->base.is_clear = TRUE; - - surface->bbtree.left = surface->bbtree.right = NULL; - surface->bbtree.chain = INVALID_CHAIN; - - surface->indices = NULL; - surface->num_indices = 0; - surface->optimize_clears = TRUE; - surface->has_bilevel_alpha = FALSE; - surface->has_only_op_over = FALSE; - - return &surface->base; -} -slim_hidden_def (cairo_recording_surface_create); - -static cairo_surface_t * -_cairo_recording_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_rectangle_t extents; - extents.x = extents.y = 0; - extents.width = width; - extents.height = height; - return cairo_recording_surface_create (content, &extents); -} - -static cairo_status_t -_cairo_recording_surface_finish (void *abstract_surface) -{ - cairo_recording_surface_t *surface = abstract_surface; - cairo_command_t **elements; - int i, num_elements; - - num_elements = surface->commands.num_elements; - elements = _cairo_array_index (&surface->commands, 0); - for (i = 0; i < num_elements; i++) { - cairo_command_t *command = elements[i]; - - switch (command->header.type) { - case CAIRO_COMMAND_PAINT: - _cairo_pattern_fini (&command->paint.source.base); - break; - - case CAIRO_COMMAND_MASK: - _cairo_pattern_fini (&command->mask.source.base); - _cairo_pattern_fini (&command->mask.mask.base); - break; - - case CAIRO_COMMAND_STROKE: - _cairo_pattern_fini (&command->stroke.source.base); - _cairo_path_fixed_fini (&command->stroke.path); - _cairo_stroke_style_fini (&command->stroke.style); - break; - - case CAIRO_COMMAND_FILL: - _cairo_pattern_fini (&command->fill.source.base); - _cairo_path_fixed_fini (&command->fill.path); - break; - - case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: - _cairo_pattern_fini (&command->show_text_glyphs.source.base); - free (command->show_text_glyphs.utf8); - free (command->show_text_glyphs.glyphs); - free (command->show_text_glyphs.clusters); - cairo_scaled_font_destroy (command->show_text_glyphs.scaled_font); - break; - - default: - ASSERT_NOT_REACHED; - } - - _cairo_clip_destroy (command->header.clip); - free (command); - } - - _cairo_array_fini (&surface->commands); - - if (surface->bbtree.left) - bbtree_del (surface->bbtree.left); - if (surface->bbtree.right) - bbtree_del (surface->bbtree.right); - - free (surface->indices); - - return CAIRO_STATUS_SUCCESS; -} - -struct proxy { - cairo_surface_t base; - cairo_surface_t *image; -}; - -static cairo_status_t -proxy_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - struct proxy *proxy = abstract_surface; - return _cairo_surface_acquire_source_image (proxy->image, image_out, image_extra); -} - -static void -proxy_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - struct proxy *proxy = abstract_surface; - _cairo_surface_release_source_image (proxy->image, image, image_extra); -} - -static cairo_status_t -proxy_finish (void *abstract_surface) -{ - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t proxy_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_NULL, - proxy_finish, - NULL, - - NULL, /* create similar */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - proxy_acquire_source_image, - proxy_release_source_image, -}; - -static cairo_surface_t * -attach_proxy (cairo_surface_t *source, - cairo_surface_t *image) -{ - struct proxy *proxy; - - proxy = malloc (sizeof (*proxy)); - if (unlikely (proxy == NULL)) - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_surface_init (&proxy->base, &proxy_backend, NULL, image->content); - - proxy->image = image; - _cairo_surface_attach_snapshot (source, &proxy->base, NULL); - - return &proxy->base; -} - -static void -detach_proxy (cairo_surface_t *source, - cairo_surface_t *proxy) -{ - cairo_surface_finish (proxy); - cairo_surface_destroy (proxy); -} - -static cairo_surface_t * -get_proxy (cairo_surface_t *proxy) -{ - return ((struct proxy *)proxy)->image; -} - -static cairo_status_t -_cairo_recording_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_recording_surface_t *surface = abstract_surface; - cairo_surface_t *image, *proxy; - cairo_status_t status; - - proxy = _cairo_surface_has_snapshot (abstract_surface, &proxy_backend); - if (proxy != NULL) { - *image_out = (cairo_image_surface_t *) - cairo_surface_reference (get_proxy (proxy)); - *image_extra = NULL; - return CAIRO_STATUS_SUCCESS; - } - - assert (! surface->unbounded); - image = _cairo_image_surface_create_with_content (surface->base.content, - surface->extents.width, - surface->extents.height); - if (unlikely (image->status)) - return image->status; - - /* Handle recursion by returning future reads from the current image */ - proxy = attach_proxy (abstract_surface, image); - status = _cairo_recording_surface_replay (&surface->base, image); - detach_proxy (abstract_surface, proxy); - - if (unlikely (status)) { - cairo_surface_destroy (image); - return status; - } - - *image_out = (cairo_image_surface_t *) image; - *image_extra = NULL; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_recording_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); -} - -static cairo_status_t -_command_init (cairo_recording_surface_t *surface, - cairo_command_header_t *command, - cairo_command_type_t type, - cairo_operator_t op, - cairo_composite_rectangles_t *composite) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - command->type = type; - command->op = op; - command->region = CAIRO_RECORDING_REGION_ALL; - - command->extents = composite->unbounded; - command->chain = NULL; - command->index = surface->commands.num_elements; - - /* steal the clip */ - command->clip = NULL; - if (! _cairo_composite_rectangles_can_reduce_clip (composite, - composite->clip)) - { - command->clip = composite->clip; - composite->clip = NULL; - } - - return status; -} - -static void -_cairo_recording_surface_break_self_copy_loop (cairo_recording_surface_t *surface) -{ - cairo_surface_flush (&surface->base); -} - -static cairo_status_t -_cairo_recording_surface_commit (cairo_recording_surface_t *surface, - cairo_command_header_t *command) -{ - _cairo_recording_surface_break_self_copy_loop (surface); - return _cairo_array_append (&surface->commands, &command); -} - -static void -_cairo_recording_surface_reset (cairo_recording_surface_t *surface) -{ - /* Reset the commands and temporaries */ - _cairo_recording_surface_finish (surface); - - surface->bbtree.left = surface->bbtree.right = NULL; - surface->bbtree.chain = INVALID_CHAIN; - - surface->indices = NULL; - surface->num_indices = 0; - - _cairo_array_init (&surface->commands, sizeof (cairo_command_t *)); -} - -static cairo_bool_t -is_identity_recording_pattern (const cairo_pattern_t *pattern) -{ - cairo_surface_t *surface; - - if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) - return FALSE; - - if (!_cairo_matrix_is_identity(&pattern->matrix)) - return FALSE; - - surface = ((cairo_surface_pattern_t *)pattern)->surface; - return surface->backend->type == CAIRO_SURFACE_TYPE_RECORDING; -} - -static cairo_int_status_t -_cairo_recording_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_recording_surface_t *surface = abstract_surface; - cairo_command_paint_t *command; - cairo_composite_rectangles_t composite; - - TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); - - if (op == CAIRO_OPERATOR_CLEAR && clip == NULL) { - if (surface->optimize_clears) { - _cairo_recording_surface_reset (surface); - return CAIRO_STATUS_SUCCESS; - } - } - - if (clip == NULL && surface->optimize_clears && - (op == CAIRO_OPERATOR_SOURCE || - (op == CAIRO_OPERATOR_OVER && - (surface->base.is_clear || _cairo_pattern_is_opaque_solid (source))))) - { - _cairo_recording_surface_reset (surface); - if (is_identity_recording_pattern (source)) { - cairo_surface_t *src = ((cairo_surface_pattern_t *)source)->surface; - return _cairo_recording_surface_replay (src, &surface->base); - } - } - - status = _cairo_composite_rectangles_init_for_paint (&composite, - &surface->base, - op, source, - clip); - if (unlikely (status)) - return status; - - command = malloc (sizeof (cairo_command_paint_t)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_COMPOSITE; - } - - status = _command_init (surface, - &command->header, CAIRO_COMMAND_PAINT, op, - &composite); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_pattern_init_snapshot (&command->source.base, source); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto CLEANUP_SOURCE; - - _cairo_recording_surface_destroy_bbtree (surface); - - _cairo_composite_rectangles_fini (&composite); - return CAIRO_STATUS_SUCCESS; - - CLEANUP_SOURCE: - _cairo_pattern_fini (&command->source.base); - CLEANUP_COMMAND: - _cairo_clip_destroy (command->header.clip); - free (command); -CLEANUP_COMPOSITE: - _cairo_composite_rectangles_fini (&composite); - return status; -} - -static cairo_int_status_t -_cairo_recording_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_recording_surface_t *surface = abstract_surface; - cairo_command_mask_t *command; - cairo_composite_rectangles_t composite; - - TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); - - status = _cairo_composite_rectangles_init_for_mask (&composite, - &surface->base, - op, source, mask, - clip); - if (unlikely (status)) - return status; - - command = malloc (sizeof (cairo_command_mask_t)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_COMPOSITE; - } - - status = _command_init (surface, - &command->header, CAIRO_COMMAND_MASK, op, - &composite); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_pattern_init_snapshot (&command->source.base, source); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_pattern_init_snapshot (&command->mask.base, mask); - if (unlikely (status)) - goto CLEANUP_SOURCE; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto CLEANUP_MASK; - - _cairo_recording_surface_destroy_bbtree (surface); - - _cairo_composite_rectangles_fini (&composite); - return CAIRO_STATUS_SUCCESS; - - CLEANUP_MASK: - _cairo_pattern_fini (&command->mask.base); - CLEANUP_SOURCE: - _cairo_pattern_fini (&command->source.base); - CLEANUP_COMMAND: - _cairo_clip_destroy (command->header.clip); - free (command); -CLEANUP_COMPOSITE: - _cairo_composite_rectangles_fini (&composite); - return status; -} - -static cairo_int_status_t -_cairo_recording_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_recording_surface_t *surface = abstract_surface; - cairo_command_stroke_t *command; - cairo_composite_rectangles_t composite; - - TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); - - status = _cairo_composite_rectangles_init_for_stroke (&composite, - &surface->base, - op, source, - path, style, ctm, - clip); - if (unlikely (status)) - return status; - - command = malloc (sizeof (cairo_command_stroke_t)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_COMPOSITE; - } - - status = _command_init (surface, - &command->header, CAIRO_COMMAND_STROKE, op, - &composite); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_pattern_init_snapshot (&command->source.base, source); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_path_fixed_init_copy (&command->path, path); - if (unlikely (status)) - goto CLEANUP_SOURCE; - - status = _cairo_stroke_style_init_copy (&command->style, style); - if (unlikely (status)) - goto CLEANUP_PATH; - - command->ctm = *ctm; - command->ctm_inverse = *ctm_inverse; - command->tolerance = tolerance; - command->antialias = antialias; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto CLEANUP_STYLE; - - _cairo_recording_surface_destroy_bbtree (surface); - - _cairo_composite_rectangles_fini (&composite); - return CAIRO_STATUS_SUCCESS; - - CLEANUP_STYLE: - _cairo_stroke_style_fini (&command->style); - CLEANUP_PATH: - _cairo_path_fixed_fini (&command->path); - CLEANUP_SOURCE: - _cairo_pattern_fini (&command->source.base); - CLEANUP_COMMAND: - _cairo_clip_destroy (command->header.clip); - free (command); -CLEANUP_COMPOSITE: - _cairo_composite_rectangles_fini (&composite); - return status; -} - -static cairo_int_status_t -_cairo_recording_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_recording_surface_t *surface = abstract_surface; - cairo_command_fill_t *command; - cairo_composite_rectangles_t composite; - - TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); - - status = _cairo_composite_rectangles_init_for_fill (&composite, - &surface->base, - op, source, path, - clip); - if (unlikely (status)) - return status; - - command = malloc (sizeof (cairo_command_fill_t)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_COMPOSITE; - } - - status =_command_init (surface, - &command->header, CAIRO_COMMAND_FILL, op, - &composite); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_pattern_init_snapshot (&command->source.base, source); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_path_fixed_init_copy (&command->path, path); - if (unlikely (status)) - goto CLEANUP_SOURCE; - - command->fill_rule = fill_rule; - command->tolerance = tolerance; - command->antialias = antialias; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto CLEANUP_PATH; - - _cairo_recording_surface_destroy_bbtree (surface); - - _cairo_composite_rectangles_fini (&composite); - return CAIRO_STATUS_SUCCESS; - - CLEANUP_PATH: - _cairo_path_fixed_fini (&command->path); - CLEANUP_SOURCE: - _cairo_pattern_fini (&command->source.base); - CLEANUP_COMMAND: - _cairo_clip_destroy (command->header.clip); - free (command); -CLEANUP_COMPOSITE: - _cairo_composite_rectangles_fini (&composite); - return status; -} - -static cairo_bool_t -_cairo_recording_surface_has_show_text_glyphs (void *abstract_surface) -{ - return TRUE; -} - -static cairo_int_status_t -_cairo_recording_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_recording_surface_t *surface = abstract_surface; - cairo_command_show_text_glyphs_t *command; - cairo_composite_rectangles_t composite; - - TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); - - status = _cairo_composite_rectangles_init_for_glyphs (&composite, - &surface->base, - op, source, - scaled_font, - glyphs, num_glyphs, - clip, - NULL); - if (unlikely (status)) - return status; - - command = malloc (sizeof (cairo_command_show_text_glyphs_t)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_COMPOSITE; - } - - status = _command_init (surface, - &command->header, CAIRO_COMMAND_SHOW_TEXT_GLYPHS, - op, &composite); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - status = _cairo_pattern_init_snapshot (&command->source.base, source); - if (unlikely (status)) - goto CLEANUP_COMMAND; - - command->utf8 = NULL; - command->utf8_len = utf8_len; - command->glyphs = NULL; - command->num_glyphs = num_glyphs; - command->clusters = NULL; - command->num_clusters = num_clusters; - - if (utf8_len) { - command->utf8 = malloc (utf8_len); - if (unlikely (command->utf8 == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_ARRAYS; - } - memcpy (command->utf8, utf8, utf8_len); - } - if (num_glyphs) { - command->glyphs = _cairo_malloc_ab (num_glyphs, sizeof (glyphs[0])); - if (unlikely (command->glyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_ARRAYS; - } - memcpy (command->glyphs, glyphs, sizeof (glyphs[0]) * num_glyphs); - } - if (num_clusters) { - command->clusters = _cairo_malloc_ab (num_clusters, sizeof (clusters[0])); - if (unlikely (command->clusters == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_ARRAYS; - } - memcpy (command->clusters, clusters, sizeof (clusters[0]) * num_clusters); - } - - command->cluster_flags = cluster_flags; - - command->scaled_font = cairo_scaled_font_reference (scaled_font); - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto CLEANUP_SCALED_FONT; - - _cairo_composite_rectangles_fini (&composite); - return CAIRO_STATUS_SUCCESS; - - CLEANUP_SCALED_FONT: - cairo_scaled_font_destroy (command->scaled_font); - CLEANUP_ARRAYS: - free (command->utf8); - free (command->glyphs); - free (command->clusters); - - _cairo_pattern_fini (&command->source.base); - CLEANUP_COMMAND: - _cairo_clip_destroy (command->header.clip); - free (command); -CLEANUP_COMPOSITE: - _cairo_composite_rectangles_fini (&composite); - return status; -} - -static void -_command_init_copy (cairo_recording_surface_t *surface, - cairo_command_header_t *dst, - const cairo_command_header_t *src) -{ - dst->type = src->type; - dst->op = src->op; - dst->region = CAIRO_RECORDING_REGION_ALL; - - dst->extents = src->extents; - dst->chain = NULL; - dst->index = surface->commands.num_elements; - - dst->clip = _cairo_clip_copy (src->clip); -} - -static cairo_status_t -_cairo_recording_surface_copy__paint (cairo_recording_surface_t *surface, - const cairo_command_t *src) -{ - cairo_command_paint_t *command; - cairo_status_t status; - - command = malloc (sizeof (*command)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err; - } - - _command_init_copy (surface, &command->header, &src->header); - - status = _cairo_pattern_init_copy (&command->source.base, - &src->paint.source.base); - if (unlikely (status)) - goto err_command; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto err_source; - - return CAIRO_STATUS_SUCCESS; - -err_source: - _cairo_pattern_fini (&command->source.base); -err_command: - free(command); -err: - return status; -} - -static cairo_status_t -_cairo_recording_surface_copy__mask (cairo_recording_surface_t *surface, - const cairo_command_t *src) -{ - cairo_command_mask_t *command; - cairo_status_t status; - - command = malloc (sizeof (*command)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err; - } - - _command_init_copy (surface, &command->header, &src->header); - - status = _cairo_pattern_init_copy (&command->source.base, - &src->mask.source.base); - if (unlikely (status)) - goto err_command; - - status = _cairo_pattern_init_copy (&command->mask.base, - &src->mask.source.base); - if (unlikely (status)) - goto err_source; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto err_mask; - - return CAIRO_STATUS_SUCCESS; - -err_mask: - _cairo_pattern_fini (&command->mask.base); -err_source: - _cairo_pattern_fini (&command->source.base); -err_command: - free(command); -err: - return status; -} - -static cairo_status_t -_cairo_recording_surface_copy__stroke (cairo_recording_surface_t *surface, - const cairo_command_t *src) -{ - cairo_command_stroke_t *command; - cairo_status_t status; - - command = malloc (sizeof (*command)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err; - } - - _command_init_copy (surface, &command->header, &src->header); - - status = _cairo_pattern_init_copy (&command->source.base, - &src->stroke.source.base); - if (unlikely (status)) - goto err_command; - - status = _cairo_path_fixed_init_copy (&command->path, &src->stroke.path); - if (unlikely (status)) - goto err_source; - - status = _cairo_stroke_style_init_copy (&command->style, - &src->stroke.style); - if (unlikely (status)) - goto err_path; - - command->ctm = src->stroke.ctm; - command->ctm_inverse = src->stroke.ctm_inverse; - command->tolerance = src->stroke.tolerance; - command->antialias = src->stroke.antialias; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto err_style; - - return CAIRO_STATUS_SUCCESS; - -err_style: - _cairo_stroke_style_fini (&command->style); -err_path: - _cairo_path_fixed_fini (&command->path); -err_source: - _cairo_pattern_fini (&command->source.base); -err_command: - free(command); -err: - return status; -} - -static cairo_status_t -_cairo_recording_surface_copy__fill (cairo_recording_surface_t *surface, - const cairo_command_t *src) -{ - cairo_command_fill_t *command; - cairo_status_t status; - - command = malloc (sizeof (*command)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err; - } - - _command_init_copy (surface, &command->header, &src->header); - - status = _cairo_pattern_init_copy (&command->source.base, - &src->fill.source.base); - if (unlikely (status)) - goto err_command; - - status = _cairo_path_fixed_init_copy (&command->path, &src->fill.path); - if (unlikely (status)) - goto err_source; - - command->fill_rule = src->fill.fill_rule; - command->tolerance = src->fill.tolerance; - command->antialias = src->fill.antialias; - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto err_path; - - return CAIRO_STATUS_SUCCESS; - -err_path: - _cairo_path_fixed_fini (&command->path); -err_source: - _cairo_pattern_fini (&command->source.base); -err_command: - free(command); -err: - return status; -} - -static cairo_status_t -_cairo_recording_surface_copy__glyphs (cairo_recording_surface_t *surface, - const cairo_command_t *src) -{ - cairo_command_show_text_glyphs_t *command; - cairo_status_t status; - - command = malloc (sizeof (*command)); - if (unlikely (command == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err; - } - - _command_init_copy (surface, &command->header, &src->header); - - status = _cairo_pattern_init_copy (&command->source.base, - &src->show_text_glyphs.source.base); - if (unlikely (status)) - goto err_command; - - command->utf8 = NULL; - command->utf8_len = src->show_text_glyphs.utf8_len; - command->glyphs = NULL; - command->num_glyphs = src->show_text_glyphs.num_glyphs; - command->clusters = NULL; - command->num_clusters = src->show_text_glyphs.num_clusters; - - if (command->utf8_len) { - command->utf8 = malloc (command->utf8_len); - if (unlikely (command->utf8 == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err_arrays; - } - memcpy (command->utf8, src->show_text_glyphs.utf8, command->utf8_len); - } - if (command->num_glyphs) { - command->glyphs = _cairo_malloc_ab (command->num_glyphs, - sizeof (command->glyphs[0])); - if (unlikely (command->glyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err_arrays; - } - memcpy (command->glyphs, src->show_text_glyphs.glyphs, - sizeof (command->glyphs[0]) * command->num_glyphs); - } - if (command->num_clusters) { - command->clusters = _cairo_malloc_ab (command->num_clusters, - sizeof (command->clusters[0])); - if (unlikely (command->clusters == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto err_arrays; - } - memcpy (command->clusters, src->show_text_glyphs.clusters, - sizeof (command->clusters[0]) * command->num_clusters); - } - - command->cluster_flags = src->show_text_glyphs.cluster_flags; - - command->scaled_font = - cairo_scaled_font_reference (src->show_text_glyphs.scaled_font); - - status = _cairo_recording_surface_commit (surface, &command->header); - if (unlikely (status)) - goto err_arrays; - - return CAIRO_STATUS_SUCCESS; - -err_arrays: - free (command->utf8); - free (command->glyphs); - free (command->clusters); - _cairo_pattern_fini (&command->source.base); -err_command: - free(command); -err: - return status; -} - -static cairo_status_t -_cairo_recording_surface_copy (cairo_recording_surface_t *dst, - cairo_recording_surface_t *src) -{ - cairo_command_t **elements; - int i, num_elements; - cairo_status_t status; - - elements = _cairo_array_index (&src->commands, 0); - num_elements = src->commands.num_elements; - for (i = 0; i < num_elements; i++) { - const cairo_command_t *command = elements[i]; - - switch (command->header.type) { - case CAIRO_COMMAND_PAINT: - status = _cairo_recording_surface_copy__paint (dst, command); - break; - - case CAIRO_COMMAND_MASK: - status = _cairo_recording_surface_copy__mask (dst, command); - break; - - case CAIRO_COMMAND_STROKE: - status = _cairo_recording_surface_copy__stroke (dst, command); - break; - - case CAIRO_COMMAND_FILL: - status = _cairo_recording_surface_copy__fill (dst, command); - break; - - case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: - status = _cairo_recording_surface_copy__glyphs (dst, command); - break; - - default: - ASSERT_NOT_REACHED; - } - - if (unlikely (status)) - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_recording_surface_snapshot: - * @surface: a #cairo_surface_t which must be a recording surface - * - * Make an immutable copy of @surface. It is an error to call a - * surface-modifying function on the result of this function. - * - * The caller owns the return value and should call - * cairo_surface_destroy() when finished with it. This function will not - * return %NULL, but will return a nil surface instead. - * - * Return value: The snapshot surface. - **/ -static cairo_surface_t * -_cairo_recording_surface_snapshot (void *abstract_other) -{ - cairo_recording_surface_t *other = abstract_other; - cairo_recording_surface_t *surface; - cairo_status_t status; - - surface = malloc (sizeof (cairo_recording_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &cairo_recording_surface_backend, - NULL, /* device */ - other->base.content); - - surface->extents_pixels = other->extents_pixels; - surface->extents = other->extents; - surface->unbounded = other->unbounded; - - surface->base.is_clear = other->base.is_clear; - - surface->bbtree.left = surface->bbtree.right = NULL; - surface->bbtree.chain = INVALID_CHAIN; - - surface->indices = NULL; - surface->num_indices = 0; - surface->optimize_clears = TRUE; - - _cairo_array_init (&surface->commands, sizeof (cairo_command_t *)); - status = _cairo_recording_surface_copy (surface, other); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return _cairo_surface_create_in_error (status); - } - - return &surface->base; -} - -static cairo_bool_t -_cairo_recording_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_recording_surface_t *surface = abstract_surface; - - if (surface->unbounded) - return FALSE; - - *rectangle = surface->extents; - return TRUE; -} - -static const cairo_surface_backend_t cairo_recording_surface_backend = { - CAIRO_SURFACE_TYPE_RECORDING, - _cairo_recording_surface_finish, - - _cairo_default_context_create, - - _cairo_recording_surface_create_similar, - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - _cairo_recording_surface_acquire_source_image, - _cairo_recording_surface_release_source_image, - _cairo_recording_surface_snapshot, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_recording_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - /* Here are the 5 basic drawing operations, (which are in some - * sense the only things that cairo_recording_surface should need to - * implement). However, we implement the more generic show_text_glyphs - * instead of show_glyphs. One or the other is eough. */ - - _cairo_recording_surface_paint, - _cairo_recording_surface_mask, - _cairo_recording_surface_stroke, - _cairo_recording_surface_fill, - NULL, /* fill-stroke */ - NULL, - _cairo_recording_surface_has_show_text_glyphs, - _cairo_recording_surface_show_text_glyphs, -}; - -cairo_int_status_t -_cairo_recording_surface_get_path (cairo_surface_t *abstract_surface, - cairo_path_fixed_t *path) -{ - cairo_recording_surface_t *surface; - cairo_command_t **elements; - int i, num_elements; - cairo_int_status_t status; - - if (unlikely (abstract_surface->status)) - return abstract_surface->status; - - surface = (cairo_recording_surface_t *) abstract_surface; - status = CAIRO_STATUS_SUCCESS; - - num_elements = surface->commands.num_elements; - elements = _cairo_array_index (&surface->commands, 0); - for (i = 0; i < num_elements; i++) { - cairo_command_t *command = elements[i]; - - switch (command->header.type) { - case CAIRO_COMMAND_PAINT: - case CAIRO_COMMAND_MASK: - status = CAIRO_INT_STATUS_UNSUPPORTED; - break; - - case CAIRO_COMMAND_STROKE: - { - cairo_traps_t traps; - - _cairo_traps_init (&traps); - - /* XXX call cairo_stroke_to_path() when that is implemented */ - status = _cairo_path_fixed_stroke_polygon_to_traps (&command->stroke.path, - &command->stroke.style, - &command->stroke.ctm, - &command->stroke.ctm_inverse, - command->stroke.tolerance, - &traps); - - if (status == CAIRO_INT_STATUS_SUCCESS) - status = _cairo_traps_path (&traps, path); - - _cairo_traps_fini (&traps); - break; - } - case CAIRO_COMMAND_FILL: - { - status = _cairo_path_fixed_append (path, - &command->fill.path, - 0, 0); - break; - } - case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: - { - status = _cairo_scaled_font_glyph_path (command->show_text_glyphs.scaled_font, - command->show_text_glyphs.glyphs, - command->show_text_glyphs.num_glyphs, - path); - break; - } - - default: - ASSERT_NOT_REACHED; - } - - if (unlikely (status)) - break; - } - - return status; -} - -static int -_cairo_recording_surface_get_visible_commands (cairo_recording_surface_t *surface, - const cairo_rectangle_int_t *extents) -{ - unsigned int num_visible, *indices; - cairo_box_t box; - - if (surface->commands.num_elements == 0) - return 0; - - _cairo_box_from_rectangle (&box, extents); - - if (surface->bbtree.chain == INVALID_CHAIN) - _cairo_recording_surface_create_bbtree (surface); - - indices = surface->indices; - bbtree_foreach_mark_visible (&surface->bbtree, &box, &indices); - num_visible = indices - surface->indices; - if (num_visible > 1) - sort_indices (surface->indices, num_visible); - - return num_visible; -} - -static void -_cairo_recording_surface_merge_source_attributes (cairo_recording_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source) -{ - if (op != CAIRO_OPERATOR_OVER) - surface->has_only_op_over = FALSE; - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) source; - cairo_surface_t *surf = surf_pat->surface; - cairo_surface_t *free_me = NULL; - - if (_cairo_surface_is_snapshot (surf)) - free_me = surf = _cairo_surface_snapshot_get_target (surf); - - if (surf->type == CAIRO_SURFACE_TYPE_RECORDING) { - cairo_recording_surface_t *rec_surf = (cairo_recording_surface_t *) surf; - - if (! _cairo_recording_surface_has_only_bilevel_alpha (rec_surf)) - surface->has_bilevel_alpha = FALSE; - - if (! _cairo_recording_surface_has_only_op_over (rec_surf)) - surface->has_only_op_over = FALSE; - - } else if (surf->type == CAIRO_SURFACE_TYPE_IMAGE) { - cairo_image_surface_t *img_surf = (cairo_image_surface_t *) surf; - - if (_cairo_image_analyze_transparency (img_surf) == CAIRO_IMAGE_HAS_ALPHA) - surface->has_bilevel_alpha = FALSE; - - } else { - if (!_cairo_pattern_is_clear (source) && !_cairo_pattern_is_opaque (source, NULL)) - surface->has_bilevel_alpha = FALSE; - } - - cairo_surface_destroy (free_me); - return; - - } else if (source->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { - cairo_surface_t *image; - cairo_surface_t *raster; - - image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); - raster = _cairo_raster_source_pattern_acquire (source, image, NULL); - cairo_surface_destroy (image); - if (raster) { - if (raster->type == CAIRO_SURFACE_TYPE_IMAGE) { - if (_cairo_image_analyze_transparency ((cairo_image_surface_t *)raster) == CAIRO_IMAGE_HAS_ALPHA) - surface->has_bilevel_alpha = FALSE; - } - - _cairo_raster_source_pattern_release (source, raster); - if (raster->type == CAIRO_SURFACE_TYPE_IMAGE) - return; - } - } - - if (!_cairo_pattern_is_clear (source) && !_cairo_pattern_is_opaque (source, NULL)) - surface->has_bilevel_alpha = FALSE; -} - -static cairo_status_t -_cairo_recording_surface_replay_internal (cairo_recording_surface_t *surface, - const cairo_rectangle_int_t *surface_extents, - const cairo_matrix_t *surface_transform, - cairo_surface_t *target, - const cairo_clip_t *target_clip, - cairo_recording_replay_type_t type, - cairo_recording_region_type_t region) -{ - cairo_surface_wrapper_t wrapper; - cairo_command_t **elements; - cairo_bool_t replay_all = - type == CAIRO_RECORDING_REPLAY && - region == CAIRO_RECORDING_REGION_ALL; - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - cairo_rectangle_int_t extents; - cairo_bool_t use_indices = FALSE; - const cairo_rectangle_int_t *r; - unsigned int i, num_elements; - - if (unlikely (surface->base.status)) - return surface->base.status; - - if (unlikely (target->status)) - return target->status; - - if (unlikely (surface->base.finished)) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - if (surface->base.is_clear) - return CAIRO_STATUS_SUCCESS; - - assert (_cairo_surface_is_recording (&surface->base)); - - _cairo_surface_wrapper_init (&wrapper, target); - if (surface_extents) - _cairo_surface_wrapper_intersect_extents (&wrapper, surface_extents); - r = &_cairo_unbounded_rectangle; - if (! surface->unbounded) { - _cairo_surface_wrapper_intersect_extents (&wrapper, &surface->extents); - r = &surface->extents; - } - _cairo_surface_wrapper_set_inverse_transform (&wrapper, surface_transform); - _cairo_surface_wrapper_set_clip (&wrapper, target_clip); - - /* Compute the extents of the target clip in recorded device space */ - if (! _cairo_surface_wrapper_get_target_extents (&wrapper, &extents)) - goto done; - - surface->has_bilevel_alpha = TRUE; - surface->has_only_op_over = TRUE; - - num_elements = surface->commands.num_elements; - elements = _cairo_array_index (&surface->commands, 0); - if (extents.width < r->width || extents.height < r->height) { - num_elements = - _cairo_recording_surface_get_visible_commands (surface, &extents); - use_indices = num_elements != surface->commands.num_elements; - } - - for (i = 0; i < num_elements; i++) { - cairo_command_t *command = elements[use_indices ? surface->indices[i] : i]; - - if (! replay_all && command->header.region != region) - continue; - - if (! _cairo_rectangle_intersects (&extents, &command->header.extents)) - continue; - - switch (command->header.type) { - case CAIRO_COMMAND_PAINT: - status = _cairo_surface_wrapper_paint (&wrapper, - command->header.op, - &command->paint.source.base, - command->header.clip); - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->paint.source.base); - } - break; - - case CAIRO_COMMAND_MASK: - status = _cairo_surface_wrapper_mask (&wrapper, - command->header.op, - &command->mask.source.base, - &command->mask.mask.base, - command->header.clip); - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->mask.source.base); - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->mask.mask.base); - } - break; - - case CAIRO_COMMAND_STROKE: - status = _cairo_surface_wrapper_stroke (&wrapper, - command->header.op, - &command->stroke.source.base, - &command->stroke.path, - &command->stroke.style, - &command->stroke.ctm, - &command->stroke.ctm_inverse, - command->stroke.tolerance, - command->stroke.antialias, - command->header.clip); - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->stroke.source.base); - } - break; - - case CAIRO_COMMAND_FILL: - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_surface_wrapper_has_fill_stroke (&wrapper)) { - cairo_command_t *stroke_command; - - stroke_command = NULL; - if (type != CAIRO_RECORDING_CREATE_REGIONS && i < num_elements - 1) - stroke_command = elements[i + 1]; - - if (stroke_command != NULL && - type == CAIRO_RECORDING_REPLAY && - region != CAIRO_RECORDING_REGION_ALL) - { - if (stroke_command->header.region != region) - stroke_command = NULL; - } - - if (stroke_command != NULL && - stroke_command->header.type == CAIRO_COMMAND_STROKE && - _cairo_path_fixed_equal (&command->fill.path, - &stroke_command->stroke.path) && - _cairo_clip_equal (command->header.clip, - stroke_command->header.clip)) - { - status = _cairo_surface_wrapper_fill_stroke (&wrapper, - command->header.op, - &command->fill.source.base, - command->fill.fill_rule, - command->fill.tolerance, - command->fill.antialias, - &command->fill.path, - stroke_command->header.op, - &stroke_command->stroke.source.base, - &stroke_command->stroke.style, - &stroke_command->stroke.ctm, - &stroke_command->stroke.ctm_inverse, - stroke_command->stroke.tolerance, - stroke_command->stroke.antialias, - command->header.clip); - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->fill.source.base); - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->stroke.source.base); - } - i++; - } - } - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = _cairo_surface_wrapper_fill (&wrapper, - command->header.op, - &command->fill.source.base, - &command->fill.path, - command->fill.fill_rule, - command->fill.tolerance, - command->fill.antialias, - command->header.clip); - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->fill.source.base); - } - } - break; - - case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: - status = _cairo_surface_wrapper_show_text_glyphs (&wrapper, - command->header.op, - &command->show_text_glyphs.source.base, - command->show_text_glyphs.utf8, command->show_text_glyphs.utf8_len, - command->show_text_glyphs.glyphs, command->show_text_glyphs.num_glyphs, - command->show_text_glyphs.clusters, command->show_text_glyphs.num_clusters, - command->show_text_glyphs.cluster_flags, - command->show_text_glyphs.scaled_font, - command->header.clip); - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - _cairo_recording_surface_merge_source_attributes (surface, - command->header.op, - &command->show_text_glyphs.source.base); - } - break; - - default: - ASSERT_NOT_REACHED; - } - - if (type == CAIRO_RECORDING_CREATE_REGIONS) { - if (status == CAIRO_INT_STATUS_SUCCESS) { - command->header.region = CAIRO_RECORDING_REGION_NATIVE; - } else if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) { - command->header.region = CAIRO_RECORDING_REGION_IMAGE_FALLBACK; - status = CAIRO_INT_STATUS_SUCCESS; - } else { - assert (_cairo_int_status_is_error (status)); - } - } - - if (unlikely (status)) - break; - } - -done: - _cairo_surface_wrapper_fini (&wrapper); - return _cairo_surface_set_error (&surface->base, status); -} - -cairo_status_t -_cairo_recording_surface_replay_one (cairo_recording_surface_t *surface, - long unsigned index, - cairo_surface_t *target) -{ - cairo_surface_wrapper_t wrapper; - cairo_command_t **elements, *command; - cairo_int_status_t status; - - if (unlikely (surface->base.status)) - return surface->base.status; - - if (unlikely (target->status)) - return target->status; - - if (unlikely (surface->base.finished)) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - assert (_cairo_surface_is_recording (&surface->base)); - - /* XXX - * Use a surface wrapper because we may want to do transformed - * replay in the future. - */ - _cairo_surface_wrapper_init (&wrapper, target); - - if (index > surface->commands.num_elements) - return _cairo_error (CAIRO_STATUS_READ_ERROR); - - elements = _cairo_array_index (&surface->commands, 0); - command = elements[index]; - switch (command->header.type) { - case CAIRO_COMMAND_PAINT: - status = _cairo_surface_wrapper_paint (&wrapper, - command->header.op, - &command->paint.source.base, - command->header.clip); - break; - - case CAIRO_COMMAND_MASK: - status = _cairo_surface_wrapper_mask (&wrapper, - command->header.op, - &command->mask.source.base, - &command->mask.mask.base, - command->header.clip); - break; - - case CAIRO_COMMAND_STROKE: - status = _cairo_surface_wrapper_stroke (&wrapper, - command->header.op, - &command->stroke.source.base, - &command->stroke.path, - &command->stroke.style, - &command->stroke.ctm, - &command->stroke.ctm_inverse, - command->stroke.tolerance, - command->stroke.antialias, - command->header.clip); - break; - - case CAIRO_COMMAND_FILL: - status = _cairo_surface_wrapper_fill (&wrapper, - command->header.op, - &command->fill.source.base, - &command->fill.path, - command->fill.fill_rule, - command->fill.tolerance, - command->fill.antialias, - command->header.clip); - break; - - case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: - status = _cairo_surface_wrapper_show_text_glyphs (&wrapper, - command->header.op, - &command->show_text_glyphs.source.base, - command->show_text_glyphs.utf8, command->show_text_glyphs.utf8_len, - command->show_text_glyphs.glyphs, command->show_text_glyphs.num_glyphs, - command->show_text_glyphs.clusters, command->show_text_glyphs.num_clusters, - command->show_text_glyphs.cluster_flags, - command->show_text_glyphs.scaled_font, - command->header.clip); - break; - - default: - ASSERT_NOT_REACHED; - } - - _cairo_surface_wrapper_fini (&wrapper); - return _cairo_surface_set_error (&surface->base, status); -} -/** - * _cairo_recording_surface_replay: - * @surface: the #cairo_recording_surface_t - * @target: a target #cairo_surface_t onto which to replay the operations - * @width_pixels: width of the surface, in pixels - * @height_pixels: height of the surface, in pixels - * - * A recording surface can be "replayed" against any target surface, - * after which the results in target will be identical to the results - * that would have been obtained if the original operations applied to - * the recording surface had instead been applied to the target surface. - **/ -cairo_status_t -_cairo_recording_surface_replay (cairo_surface_t *surface, - cairo_surface_t *target) -{ - return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, NULL, NULL, - target, NULL, - CAIRO_RECORDING_REPLAY, - CAIRO_RECORDING_REGION_ALL); -} - -cairo_status_t -_cairo_recording_surface_replay_with_clip (cairo_surface_t *surface, - const cairo_matrix_t *surface_transform, - cairo_surface_t *target, - const cairo_clip_t *target_clip) -{ - return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, NULL, surface_transform, - target, target_clip, - CAIRO_RECORDING_REPLAY, - CAIRO_RECORDING_REGION_ALL); -} - -/* Replay recording to surface. When the return status of each operation is - * one of %CAIRO_STATUS_SUCCESS, %CAIRO_INT_STATUS_UNSUPPORTED, or - * %CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY the status of each operation - * will be stored in the recording surface. Any other status will abort the - * replay and return the status. - */ -cairo_status_t -_cairo_recording_surface_replay_and_create_regions (cairo_surface_t *surface, - cairo_surface_t *target) -{ - return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, NULL, NULL, - target, NULL, - CAIRO_RECORDING_CREATE_REGIONS, - CAIRO_RECORDING_REGION_ALL); -} - -cairo_status_t -_cairo_recording_surface_replay_region (cairo_surface_t *surface, - const cairo_rectangle_int_t *surface_extents, - cairo_surface_t *target, - cairo_recording_region_type_t region) -{ - return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, - surface_extents, NULL, - target, NULL, - CAIRO_RECORDING_REPLAY, - region); -} - -static cairo_status_t -_recording_surface_get_ink_bbox (cairo_recording_surface_t *surface, - cairo_box_t *bbox, - const cairo_matrix_t *transform) -{ - cairo_surface_t *null_surface; - cairo_surface_t *analysis_surface; - cairo_status_t status; - - null_surface = _cairo_null_surface_create (surface->base.content); - analysis_surface = _cairo_analysis_surface_create (null_surface); - cairo_surface_destroy (null_surface); - - status = analysis_surface->status; - if (unlikely (status)) - return status; - - if (transform != NULL) - _cairo_analysis_surface_set_ctm (analysis_surface, transform); - - status = _cairo_recording_surface_replay (&surface->base, analysis_surface); - _cairo_analysis_surface_get_bounding_box (analysis_surface, bbox); - cairo_surface_destroy (analysis_surface); - - return status; -} - -/** - * cairo_recording_surface_ink_extents: - * @surface: a #cairo_recording_surface_t - * @x0: the x-coordinate of the top-left of the ink bounding box - * @y0: the y-coordinate of the top-left of the ink bounding box - * @width: the width of the ink bounding box - * @height: the height of the ink bounding box - * - * Measures the extents of the operations stored within the recording-surface. - * This is useful to compute the required size of an image surface (or - * equivalent) into which to replay the full sequence of drawing operations. - * - * Since: 1.10 - **/ -void -cairo_recording_surface_ink_extents (cairo_surface_t *surface, - double *x0, - double *y0, - double *width, - double *height) -{ - cairo_status_t status; - cairo_box_t bbox; - - memset (&bbox, 0, sizeof (bbox)); - - if (surface->status || ! _cairo_surface_is_recording (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - goto DONE; - } - - status = _recording_surface_get_ink_bbox ((cairo_recording_surface_t *) surface, - &bbox, - NULL); - if (unlikely (status)) - status = _cairo_surface_set_error (surface, status); - -DONE: - if (x0) - *x0 = _cairo_fixed_to_double (bbox.p1.x); - if (y0) - *y0 = _cairo_fixed_to_double (bbox.p1.y); - if (width) - *width = _cairo_fixed_to_double (bbox.p2.x - bbox.p1.x); - if (height) - *height = _cairo_fixed_to_double (bbox.p2.y - bbox.p1.y); -} - -cairo_status_t -_cairo_recording_surface_get_bbox (cairo_recording_surface_t *surface, - cairo_box_t *bbox, - const cairo_matrix_t *transform) -{ - if (! surface->unbounded) { - _cairo_box_from_rectangle (bbox, &surface->extents); - if (transform != NULL) - _cairo_matrix_transform_bounding_box_fixed (transform, bbox, NULL); - - return CAIRO_STATUS_SUCCESS; - } - - return _recording_surface_get_ink_bbox (surface, bbox, transform); -} - -cairo_status_t -_cairo_recording_surface_get_ink_bbox (cairo_recording_surface_t *surface, - cairo_box_t *bbox, - const cairo_matrix_t *transform) -{ - return _recording_surface_get_ink_bbox (surface, bbox, transform); -} - -/** - * cairo_recording_surface_get_extents: - * @surface: a #cairo_recording_surface_t - * @extents: the #cairo_rectangle_t to be assigned the extents - * - * Get the extents of the recording-surface. - * - * Return value: %TRUE if the surface is bounded, of recording type, and - * not in an error state, otherwise %FALSE - * - * Since: 1.12 - **/ -cairo_bool_t -cairo_recording_surface_get_extents (cairo_surface_t *surface, - cairo_rectangle_t *extents) -{ - cairo_recording_surface_t *record; - - if (surface->status || ! _cairo_surface_is_recording (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return FALSE; - } - - record = (cairo_recording_surface_t *)surface; - if (record->unbounded) - return FALSE; - - *extents = record->extents_pixels; - return TRUE; -} - -cairo_bool_t -_cairo_recording_surface_has_only_bilevel_alpha (cairo_recording_surface_t *surface) -{ - return surface->has_bilevel_alpha; -} - -cairo_bool_t -_cairo_recording_surface_has_only_op_over (cairo_recording_surface_t *surface) -{ - return surface->has_only_op_over; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangle.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangle.c deleted file mode 100644 index 2d51d7b10a4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangle.c +++ /dev/null @@ -1,299 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2006 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" - -const cairo_rectangle_int_t _cairo_empty_rectangle = { 0, 0, 0, 0 }; -const cairo_rectangle_int_t _cairo_unbounded_rectangle = { - CAIRO_RECT_INT_MIN, CAIRO_RECT_INT_MIN, - CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN, - CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN, -}; - -cairo_private void -_cairo_box_from_doubles (cairo_box_t *box, - double *x1, double *y1, - double *x2, double *y2) -{ - box->p1.x = _cairo_fixed_from_double (*x1); - box->p1.y = _cairo_fixed_from_double (*y1); - box->p2.x = _cairo_fixed_from_double (*x2); - box->p2.y = _cairo_fixed_from_double (*y2); -} - -cairo_private void -_cairo_box_to_doubles (const cairo_box_t *box, - double *x1, double *y1, - double *x2, double *y2) -{ - *x1 = _cairo_fixed_to_double (box->p1.x); - *y1 = _cairo_fixed_to_double (box->p1.y); - *x2 = _cairo_fixed_to_double (box->p2.x); - *y2 = _cairo_fixed_to_double (box->p2.y); -} - -void -_cairo_box_from_rectangle (cairo_box_t *box, - const cairo_rectangle_int_t *rect) -{ - box->p1.x = _cairo_fixed_from_int (rect->x); - box->p1.y = _cairo_fixed_from_int (rect->y); - box->p2.x = _cairo_fixed_from_int (rect->x + rect->width); - box->p2.y = _cairo_fixed_from_int (rect->y + rect->height); -} - -void -_cairo_boxes_get_extents (const cairo_box_t *boxes, - int num_boxes, - cairo_box_t *extents) -{ - assert (num_boxes > 0); - *extents = *boxes; - while (--num_boxes) - _cairo_box_add_box (extents, ++boxes); -} - -/* XXX We currently have a confusing mix of boxes and rectangles as - * exemplified by this function. A #cairo_box_t is a rectangular area - * represented by the coordinates of the upper left and lower right - * corners, expressed in fixed point numbers. A #cairo_rectangle_int_t is - * also a rectangular area, but represented by the upper left corner - * and the width and the height, as integer numbers. - * - * This function converts a #cairo_box_t to a #cairo_rectangle_int_t by - * increasing the area to the nearest integer coordinates. We should - * standardize on #cairo_rectangle_fixed_t and #cairo_rectangle_int_t, and - * this function could be renamed to the more reasonable - * _cairo_rectangle_fixed_round. - */ - -void -_cairo_box_round_to_rectangle (const cairo_box_t *box, - cairo_rectangle_int_t *rectangle) -{ - rectangle->x = _cairo_fixed_integer_floor (box->p1.x); - rectangle->y = _cairo_fixed_integer_floor (box->p1.y); - rectangle->width = _cairo_fixed_integer_ceil (box->p2.x) - rectangle->x; - rectangle->height = _cairo_fixed_integer_ceil (box->p2.y) - rectangle->y; -} - -cairo_bool_t -_cairo_rectangle_intersect (cairo_rectangle_int_t *dst, - const cairo_rectangle_int_t *src) -{ - int x1, y1, x2, y2; - - x1 = MAX (dst->x, src->x); - y1 = MAX (dst->y, src->y); - /* Beware the unsigned promotion, fortunately we have bits to spare - * as (CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN) < UINT_MAX - */ - x2 = MIN (dst->x + (int) dst->width, src->x + (int) src->width); - y2 = MIN (dst->y + (int) dst->height, src->y + (int) src->height); - - if (x1 >= x2 || y1 >= y2) { - dst->x = 0; - dst->y = 0; - dst->width = 0; - dst->height = 0; - - return FALSE; - } else { - dst->x = x1; - dst->y = y1; - dst->width = x2 - x1; - dst->height = y2 - y1; - - return TRUE; - } -} - -/* Extends the dst rectangle to also contain src. - * If one of the rectangles is empty, the result is undefined - */ -void -_cairo_rectangle_union (cairo_rectangle_int_t *dst, - const cairo_rectangle_int_t *src) -{ - int x1, y1, x2, y2; - - x1 = MIN (dst->x, src->x); - y1 = MIN (dst->y, src->y); - /* Beware the unsigned promotion, fortunately we have bits to spare - * as (CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN) < UINT_MAX - */ - x2 = MAX (dst->x + (int) dst->width, src->x + (int) src->width); - y2 = MAX (dst->y + (int) dst->height, src->y + (int) src->height); - - dst->x = x1; - dst->y = y1; - dst->width = x2 - x1; - dst->height = y2 - y1; -} - -#define P1x (line->p1.x) -#define P1y (line->p1.y) -#define P2x (line->p2.x) -#define P2y (line->p2.y) -#define B1x (box->p1.x) -#define B1y (box->p1.y) -#define B2x (box->p2.x) -#define B2y (box->p2.y) - -/* - * Check whether any part of line intersects box. This function essentially - * computes whether the ray starting at line->p1 in the direction of line->p2 - * intersects the box before it reaches p2. Normally, this is done - * by dividing by the lengths of the line projected onto each axis. Because - * we're in fixed point, this function does a bit more work to avoid having to - * do the division -- we don't care about the actual intersection point, so - * it's of no interest to us. - */ - -cairo_bool_t -_cairo_box_intersects_line_segment (const cairo_box_t *box, cairo_line_t *line) -{ - cairo_fixed_t t1=0, t2=0, t3=0, t4=0; - cairo_int64_t t1y, t2y, t3x, t4x; - - cairo_fixed_t xlen, ylen; - - if (_cairo_box_contains_point (box, &line->p1) || - _cairo_box_contains_point (box, &line->p2)) - return TRUE; - - xlen = P2x - P1x; - ylen = P2y - P1y; - - if (xlen) { - if (xlen > 0) { - t1 = B1x - P1x; - t2 = B2x - P1x; - } else { - t1 = P1x - B2x; - t2 = P1x - B1x; - xlen = - xlen; - } - - if ((t1 < 0 || t1 > xlen) && - (t2 < 0 || t2 > xlen)) - return FALSE; - } else { - /* Fully vertical line -- check that X is in bounds */ - if (P1x < B1x || P1x > B2x) - return FALSE; - } - - if (ylen) { - if (ylen > 0) { - t3 = B1y - P1y; - t4 = B2y - P1y; - } else { - t3 = P1y - B2y; - t4 = P1y - B1y; - ylen = - ylen; - } - - if ((t3 < 0 || t3 > ylen) && - (t4 < 0 || t4 > ylen)) - return FALSE; - } else { - /* Fully horizontal line -- check Y */ - if (P1y < B1y || P1y > B2y) - return FALSE; - } - - /* If we had a horizontal or vertical line, then it's already been checked */ - if (P1x == P2x || P1y == P2y) - return TRUE; - - /* Check overlap. Note that t1 < t2 and t3 < t4 here. */ - t1y = _cairo_int32x32_64_mul (t1, ylen); - t2y = _cairo_int32x32_64_mul (t2, ylen); - t3x = _cairo_int32x32_64_mul (t3, xlen); - t4x = _cairo_int32x32_64_mul (t4, xlen); - - if (_cairo_int64_lt(t1y, t4x) && - _cairo_int64_lt(t3x, t2y)) - return TRUE; - - return FALSE; -} - -static cairo_status_t -_cairo_box_add_spline_point (void *closure, - const cairo_point_t *point, - const cairo_slope_t *tangent) -{ - _cairo_box_add_point (closure, point); - - return CAIRO_STATUS_SUCCESS; -} - -/* assumes a has been previously added */ -void -_cairo_box_add_curve_to (cairo_box_t *extents, - const cairo_point_t *a, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - _cairo_box_add_point (extents, d); - if (!_cairo_box_contains_point (extents, b) || - !_cairo_box_contains_point (extents, c)) - { - cairo_status_t status; - - status = _cairo_spline_bound (_cairo_box_add_spline_point, - extents, a, b, c, d); - assert (status == CAIRO_STATUS_SUCCESS); - } -} - -void -_cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti, - const cairo_rectangle_t *rectf) -{ - recti->x = floor (rectf->x); - recti->y = floor (rectf->y); - recti->width = ceil (rectf->x + rectf->width) - floor (rectf->x); - recti->height = ceil (rectf->y + rectf->height) - floor (rectf->y); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangular-scan-converter.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangular-scan-converter.c deleted file mode 100644 index e353b34e853..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rectangular-scan-converter.c +++ /dev/null @@ -1,791 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-combsort-inline.h" -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" -#include "cairo-list-private.h" -#include "cairo-spans-private.h" - -#include - -typedef struct _rectangle { - struct _rectangle *next, *prev; - cairo_fixed_t left, right; - cairo_fixed_t top, bottom; - int32_t top_y, bottom_y; - int dir; -} rectangle_t; - -#define UNROLL3(x) x x x - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -typedef struct _pqueue { - int size, max_size; - - rectangle_t **elements; - rectangle_t *elements_embedded[1024]; -} pqueue_t; - -typedef struct { - rectangle_t **start; - pqueue_t stop; - rectangle_t head, tail; - rectangle_t *insert_cursor; - int32_t current_y; - int32_t xmin, xmax; - - struct coverage { - struct cell { - struct cell *prev, *next; - int x, covered, uncovered; - } head, tail, *cursor; - unsigned int count; - cairo_freepool_t pool; - } coverage; - - cairo_half_open_span_t spans_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_half_open_span_t)]; - cairo_half_open_span_t *spans; - unsigned int num_spans; - unsigned int size_spans; - - jmp_buf jmpbuf; -} sweep_line_t; - -static inline int -rectangle_compare_start (const rectangle_t *a, - const rectangle_t *b) -{ - int cmp; - - cmp = a->top_y - b->top_y; - if (cmp) - return cmp; - - return a->left - b->left; -} - -static inline int -rectangle_compare_stop (const rectangle_t *a, - const rectangle_t *b) -{ - return a->bottom_y - b->bottom_y; -} - -static inline void -pqueue_init (pqueue_t *pq) -{ - pq->max_size = ARRAY_LENGTH (pq->elements_embedded); - pq->size = 0; - - pq->elements = pq->elements_embedded; - pq->elements[PQ_FIRST_ENTRY] = NULL; -} - -static inline void -pqueue_fini (pqueue_t *pq) -{ - if (pq->elements != pq->elements_embedded) - free (pq->elements); -} - -static cairo_bool_t -pqueue_grow (pqueue_t *pq) -{ - rectangle_t **new_elements; - pq->max_size *= 2; - - if (pq->elements == pq->elements_embedded) { - new_elements = _cairo_malloc_ab (pq->max_size, - sizeof (rectangle_t *)); - if (unlikely (new_elements == NULL)) - return FALSE; - - memcpy (new_elements, pq->elements_embedded, - sizeof (pq->elements_embedded)); - } else { - new_elements = _cairo_realloc_ab (pq->elements, - pq->max_size, - sizeof (rectangle_t *)); - if (unlikely (new_elements == NULL)) - return FALSE; - } - - pq->elements = new_elements; - return TRUE; -} - -static inline void -pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle) -{ - rectangle_t **elements; - int i, parent; - - if (unlikely (sweep->stop.size + 1 == sweep->stop.max_size)) { - if (unlikely (! pqueue_grow (&sweep->stop))) - longjmp (sweep->jmpbuf, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - elements = sweep->stop.elements; - for (i = ++sweep->stop.size; - i != PQ_FIRST_ENTRY && - rectangle_compare_stop (rectangle, - elements[parent = PQ_PARENT_INDEX (i)]) < 0; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = rectangle; -} - -static inline void -pqueue_pop (pqueue_t *pq) -{ - rectangle_t **elements = pq->elements; - rectangle_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - rectangle_compare_stop (elements[child+1], - elements[child]) < 0) - { - child++; - } - - if (rectangle_compare_stop (elements[child], tail) >= 0) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static inline rectangle_t * -peek_stop (sweep_line_t *sweep) -{ - return sweep->stop.elements[PQ_FIRST_ENTRY]; -} - -CAIRO_COMBSORT_DECLARE (rectangle_sort, rectangle_t *, rectangle_compare_start) - -static void -sweep_line_init (sweep_line_t *sweep) -{ - sweep->head.left = INT_MIN; - sweep->head.next = &sweep->tail; - sweep->tail.left = INT_MAX; - sweep->tail.prev = &sweep->head; - sweep->insert_cursor = &sweep->tail; - - _cairo_freepool_init (&sweep->coverage.pool, sizeof (struct cell)); - - sweep->spans = sweep->spans_stack; - sweep->size_spans = ARRAY_LENGTH (sweep->spans_stack); - - sweep->coverage.head.prev = NULL; - sweep->coverage.head.x = INT_MIN; - sweep->coverage.tail.next = NULL; - sweep->coverage.tail.x = INT_MAX; - - pqueue_init (&sweep->stop); -} - -static void -sweep_line_fini (sweep_line_t *sweep) -{ - _cairo_freepool_fini (&sweep->coverage.pool); - pqueue_fini (&sweep->stop); - - if (sweep->spans != sweep->spans_stack) - free (sweep->spans); -} - -static inline void -add_cell (sweep_line_t *sweep, int x, int covered, int uncovered) -{ - struct cell *cell; - - cell = sweep->coverage.cursor; - if (cell->x > x) { - do { - UNROLL3({ - if (cell->prev->x < x) - break; - cell = cell->prev; - }) - } while (TRUE); - } else { - if (cell->x == x) - goto found; - - do { - UNROLL3({ - cell = cell->next; - if (cell->x >= x) - break; - }) - } while (TRUE); - } - - if (x != cell->x) { - struct cell *c; - - sweep->coverage.count++; - - c = _cairo_freepool_alloc (&sweep->coverage.pool); - if (unlikely (c == NULL)) { - longjmp (sweep->jmpbuf, - _cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - cell->prev->next = c; - c->prev = cell->prev; - c->next = cell; - cell->prev = c; - - c->x = x; - c->covered = 0; - c->uncovered = 0; - - cell = c; - } - -found: - cell->covered += covered; - cell->uncovered += uncovered; - sweep->coverage.cursor = cell; -} - -static inline void -_active_edges_to_spans (sweep_line_t *sweep) -{ - int32_t y = sweep->current_y; - rectangle_t *rectangle; - int coverage, prev_coverage; - int prev_x; - struct cell *cell; - - sweep->num_spans = 0; - if (sweep->head.next == &sweep->tail) - return; - - sweep->coverage.head.next = &sweep->coverage.tail; - sweep->coverage.tail.prev = &sweep->coverage.head; - sweep->coverage.cursor = &sweep->coverage.tail; - sweep->coverage.count = 0; - - /* XXX cell coverage only changes when a rectangle appears or - * disappears. Try only modifying coverage at such times. - */ - for (rectangle = sweep->head.next; - rectangle != &sweep->tail; - rectangle = rectangle->next) - { - int height; - int frac, i; - - if (y == rectangle->bottom_y) { - height = rectangle->bottom & CAIRO_FIXED_FRAC_MASK; - if (height == 0) - continue; - } else - height = CAIRO_FIXED_ONE; - if (y == rectangle->top_y) - height -= rectangle->top & CAIRO_FIXED_FRAC_MASK; - height *= rectangle->dir; - - i = _cairo_fixed_integer_part (rectangle->left), - frac = _cairo_fixed_fractional_part (rectangle->left); - add_cell (sweep, i, - (CAIRO_FIXED_ONE-frac) * height, - frac * height); - - i = _cairo_fixed_integer_part (rectangle->right), - frac = _cairo_fixed_fractional_part (rectangle->right); - add_cell (sweep, i, - -(CAIRO_FIXED_ONE-frac) * height, - -frac * height); - } - - if (2*sweep->coverage.count >= sweep->size_spans) { - unsigned size; - - size = sweep->size_spans; - while (size <= 2*sweep->coverage.count) - size <<= 1; - - if (sweep->spans != sweep->spans_stack) - free (sweep->spans); - - sweep->spans = _cairo_malloc_ab (size, sizeof (cairo_half_open_span_t)); - if (unlikely (sweep->spans == NULL)) - longjmp (sweep->jmpbuf, _cairo_error (CAIRO_STATUS_NO_MEMORY)); - - sweep->size_spans = size; - } - - prev_coverage = coverage = 0; - prev_x = INT_MIN; - for (cell = sweep->coverage.head.next; cell != &sweep->coverage.tail; cell = cell->next) { - if (cell->x != prev_x && coverage != prev_coverage) { - int n = sweep->num_spans++; - int c = coverage >> (CAIRO_FIXED_FRAC_BITS * 2 - 8); - sweep->spans[n].x = prev_x; - sweep->spans[n].inverse = 0; - sweep->spans[n].coverage = c - (c >> 8); - prev_coverage = coverage; - } - - coverage += cell->covered; - if (coverage != prev_coverage) { - int n = sweep->num_spans++; - int c = coverage >> (CAIRO_FIXED_FRAC_BITS * 2 - 8); - sweep->spans[n].x = cell->x; - sweep->spans[n].inverse = 0; - sweep->spans[n].coverage = c - (c >> 8); - prev_coverage = coverage; - } - coverage += cell->uncovered; - prev_x = cell->x + 1; - } - _cairo_freepool_reset (&sweep->coverage.pool); - - if (sweep->num_spans) { - if (prev_x <= sweep->xmax) { - int n = sweep->num_spans++; - int c = coverage >> (CAIRO_FIXED_FRAC_BITS * 2 - 8); - sweep->spans[n].x = prev_x; - sweep->spans[n].inverse = 0; - sweep->spans[n].coverage = c - (c >> 8); - } - - if (coverage && prev_x < sweep->xmax) { - int n = sweep->num_spans++; - sweep->spans[n].x = sweep->xmax; - sweep->spans[n].inverse = 1; - sweep->spans[n].coverage = 0; - } - } -} - -static inline void -sweep_line_delete (sweep_line_t *sweep, - rectangle_t *rectangle) -{ - if (sweep->insert_cursor == rectangle) - sweep->insert_cursor = rectangle->next; - - rectangle->prev->next = rectangle->next; - rectangle->next->prev = rectangle->prev; - - pqueue_pop (&sweep->stop); -} - -static inline void -sweep_line_insert (sweep_line_t *sweep, - rectangle_t *rectangle) -{ - rectangle_t *pos; - - pos = sweep->insert_cursor; - if (pos->left != rectangle->left) { - if (pos->left > rectangle->left) { - do { - UNROLL3({ - if (pos->prev->left < rectangle->left) - break; - pos = pos->prev; - }) - } while (TRUE); - } else { - do { - UNROLL3({ - pos = pos->next; - if (pos->left >= rectangle->left) - break; - }); - } while (TRUE); - } - } - - pos->prev->next = rectangle; - rectangle->prev = pos->prev; - rectangle->next = pos; - pos->prev = rectangle; - sweep->insert_cursor = rectangle; - - pqueue_push (sweep, rectangle); -} - -static void -render_rows (sweep_line_t *sweep_line, - cairo_span_renderer_t *renderer, - int height) -{ - cairo_status_t status; - - _active_edges_to_spans (sweep_line); - - status = renderer->render_rows (renderer, - sweep_line->current_y, height, - sweep_line->spans, - sweep_line->num_spans); - if (unlikely (status)) - longjmp (sweep_line->jmpbuf, status); -} - -static cairo_status_t -generate (cairo_rectangular_scan_converter_t *self, - cairo_span_renderer_t *renderer, - rectangle_t **rectangles) -{ - sweep_line_t sweep_line; - rectangle_t *start, *stop; - cairo_status_t status; - - sweep_line_init (&sweep_line); - sweep_line.xmin = _cairo_fixed_integer_part (self->extents.p1.x); - sweep_line.xmax = _cairo_fixed_integer_part (self->extents.p2.x); - sweep_line.start = rectangles; - if ((status = setjmp (sweep_line.jmpbuf))) - goto out; - - sweep_line.current_y = _cairo_fixed_integer_part (self->extents.p1.y); - start = *sweep_line.start++; - do { - if (start->top_y != sweep_line.current_y) { - render_rows (&sweep_line, renderer, - start->top_y - sweep_line.current_y); - sweep_line.current_y = start->top_y; - } - - do { - sweep_line_insert (&sweep_line, start); - start = *sweep_line.start++; - if (start == NULL) - goto end; - if (start->top_y != sweep_line.current_y) - break; - } while (TRUE); - - render_rows (&sweep_line, renderer, 1); - - stop = peek_stop (&sweep_line); - while (stop->bottom_y == sweep_line.current_y) { - sweep_line_delete (&sweep_line, stop); - stop = peek_stop (&sweep_line); - if (stop == NULL) - break; - } - - sweep_line.current_y++; - - while (stop != NULL && stop->bottom_y < start->top_y) { - if (stop->bottom_y != sweep_line.current_y) { - render_rows (&sweep_line, renderer, - stop->bottom_y - sweep_line.current_y); - sweep_line.current_y = stop->bottom_y; - } - - render_rows (&sweep_line, renderer, 1); - - do { - sweep_line_delete (&sweep_line, stop); - stop = peek_stop (&sweep_line); - } while (stop != NULL && stop->bottom_y == sweep_line.current_y); - - sweep_line.current_y++; - } - } while (TRUE); - - end: - render_rows (&sweep_line, renderer, 1); - - stop = peek_stop (&sweep_line); - while (stop->bottom_y == sweep_line.current_y) { - sweep_line_delete (&sweep_line, stop); - stop = peek_stop (&sweep_line); - if (stop == NULL) - goto out; - } - - while (++sweep_line.current_y < _cairo_fixed_integer_part (self->extents.p2.y)) { - if (stop->bottom_y != sweep_line.current_y) { - render_rows (&sweep_line, renderer, - stop->bottom_y - sweep_line.current_y); - sweep_line.current_y = stop->bottom_y; - } - - render_rows (&sweep_line, renderer, 1); - - do { - sweep_line_delete (&sweep_line, stop); - stop = peek_stop (&sweep_line); - if (stop == NULL) - goto out; - } while (stop->bottom_y == sweep_line.current_y); - - } - - out: - sweep_line_fini (&sweep_line); - - return status; -} -static void generate_row(cairo_span_renderer_t *renderer, - const rectangle_t *r, - int y, int h, - uint16_t coverage) -{ - cairo_half_open_span_t spans[4]; - unsigned int num_spans = 0; - int x1 = _cairo_fixed_integer_part (r->left); - int x2 = _cairo_fixed_integer_part (r->right); - if (x2 > x1) { - if (! _cairo_fixed_is_integer (r->left)) { - spans[num_spans].x = x1; - spans[num_spans].coverage = - coverage * (256 - _cairo_fixed_fractional_part (r->left)) >> 8; - num_spans++; - x1++; - } - - if (x2 > x1) { - spans[num_spans].x = x1; - spans[num_spans].coverage = coverage - (coverage >> 8); - num_spans++; - } - - if (! _cairo_fixed_is_integer (r->right)) { - spans[num_spans].x = x2++; - spans[num_spans].coverage = - coverage * _cairo_fixed_fractional_part (r->right) >> 8; - num_spans++; - } - } else { - spans[num_spans].x = x2++; - spans[num_spans].coverage = coverage * (r->right - r->left) >> 8; - num_spans++; - } - - spans[num_spans].x = x2; - spans[num_spans].coverage = 0; - num_spans++; - - renderer->render_rows (renderer, y, h, spans, num_spans); -} - -static cairo_status_t -generate_box (cairo_rectangular_scan_converter_t *self, - cairo_span_renderer_t *renderer) -{ - const rectangle_t *r = self->chunks.base; - int y1 = _cairo_fixed_integer_part (r->top); - int y2 = _cairo_fixed_integer_part (r->bottom); - if (y2 > y1) { - if (! _cairo_fixed_is_integer (r->top)) { - generate_row(renderer, r, y1, 1, - 256 - _cairo_fixed_fractional_part (r->top)); - y1++; - } - - if (y2 > y1) - generate_row(renderer, r, y1, y2-y1, 256); - - if (! _cairo_fixed_is_integer (r->bottom)) - generate_row(renderer, r, y2, 1, - _cairo_fixed_fractional_part (r->bottom)); - } else - generate_row(renderer, r, y1, 1, r->bottom - r->top); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_rectangular_scan_converter_generate (void *converter, - cairo_span_renderer_t *renderer) -{ - cairo_rectangular_scan_converter_t *self = converter; - rectangle_t *rectangles_stack[CAIRO_STACK_ARRAY_LENGTH (rectangle_t *)]; - rectangle_t **rectangles; - struct _cairo_rectangular_scan_converter_chunk *chunk; - cairo_status_t status; - int i, j; - - if (unlikely (self->num_rectangles == 0)) { - return renderer->render_rows (renderer, - _cairo_fixed_integer_part (self->extents.p1.y), - _cairo_fixed_integer_part (self->extents.p2.y - self->extents.p1.y), - NULL, 0); - } - - if (self->num_rectangles == 1) - return generate_box (self, renderer); - - rectangles = rectangles_stack; - if (unlikely (self->num_rectangles >= ARRAY_LENGTH (rectangles_stack))) { - rectangles = _cairo_malloc_ab (self->num_rectangles + 1, - sizeof (rectangle_t *)); - if (unlikely (rectangles == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - j = 0; - for (chunk = &self->chunks; chunk != NULL; chunk = chunk->next) { - rectangle_t *rectangle; - - rectangle = chunk->base; - for (i = 0; i < chunk->count; i++) - rectangles[j++] = &rectangle[i]; - } - rectangle_sort (rectangles, j); - rectangles[j] = NULL; - - status = generate (self, renderer, rectangles); - - if (rectangles != rectangles_stack) - free (rectangles); - - return status; -} - -static rectangle_t * -_allocate_rectangle (cairo_rectangular_scan_converter_t *self) -{ - rectangle_t *rectangle; - struct _cairo_rectangular_scan_converter_chunk *chunk; - - chunk = self->tail; - if (chunk->count == chunk->size) { - int size; - - size = chunk->size * 2; - chunk->next = _cairo_malloc_ab_plus_c (size, - sizeof (rectangle_t), - sizeof (struct _cairo_rectangular_scan_converter_chunk)); - - if (unlikely (chunk->next == NULL)) - return NULL; - - chunk = chunk->next; - chunk->next = NULL; - chunk->count = 0; - chunk->size = size; - chunk->base = chunk + 1; - self->tail = chunk; - } - - rectangle = chunk->base; - return rectangle + chunk->count++; -} - -cairo_status_t -_cairo_rectangular_scan_converter_add_box (cairo_rectangular_scan_converter_t *self, - const cairo_box_t *box, - int dir) -{ - rectangle_t *rectangle; - - rectangle = _allocate_rectangle (self); - if (unlikely (rectangle == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - rectangle->dir = dir; - rectangle->left = MAX (box->p1.x, self->extents.p1.x); - rectangle->right = MIN (box->p2.x, self->extents.p2.x); - if (unlikely (rectangle->right <= rectangle->left)) { - self->tail->count--; - return CAIRO_STATUS_SUCCESS; - } - - rectangle->top = MAX (box->p1.y, self->extents.p1.y); - rectangle->top_y = _cairo_fixed_integer_floor (rectangle->top); - rectangle->bottom = MIN (box->p2.y, self->extents.p2.y); - rectangle->bottom_y = _cairo_fixed_integer_floor (rectangle->bottom); - if (likely (rectangle->bottom > rectangle->top)) - self->num_rectangles++; - else - self->tail->count--; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_rectangular_scan_converter_destroy (void *converter) -{ - cairo_rectangular_scan_converter_t *self = converter; - struct _cairo_rectangular_scan_converter_chunk *chunk, *next; - - for (chunk = self->chunks.next; chunk != NULL; chunk = next) { - next = chunk->next; - free (chunk); - } -} - -void -_cairo_rectangular_scan_converter_init (cairo_rectangular_scan_converter_t *self, - const cairo_rectangle_int_t *extents) -{ - self->base.destroy = _cairo_rectangular_scan_converter_destroy; - self->base.generate = _cairo_rectangular_scan_converter_generate; - - _cairo_box_from_rectangle (&self->extents, extents); - - self->chunks.base = self->buf; - self->chunks.next = NULL; - self->chunks.count = 0; - self->chunks.size = sizeof (self->buf) / sizeof (rectangle_t); - self->tail = &self->chunks; - - self->num_rectangles = 0; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-reference-count-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-reference-count-private.h deleted file mode 100644 index 75fdf3538f5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-reference-count-private.h +++ /dev/null @@ -1,62 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_REFRENCE_COUNT_PRIVATE_H -#define CAIRO_REFRENCE_COUNT_PRIVATE_H - -#include "cairo-atomic-private.h" - -/* Encapsulate operations on the object's reference count */ -typedef struct { - cairo_atomic_int_t ref_count; -} cairo_reference_count_t; - -#define _cairo_reference_count_inc(RC) _cairo_atomic_int_inc (&(RC)->ref_count) -#define _cairo_reference_count_dec(RC) _cairo_atomic_int_dec (&(RC)->ref_count) -#define _cairo_reference_count_dec_and_test(RC) _cairo_atomic_int_dec_and_test (&(RC)->ref_count) - -#define CAIRO_REFERENCE_COUNT_INIT(RC, VALUE) ((RC)->ref_count = (VALUE)) - -#define CAIRO_REFERENCE_COUNT_GET_VALUE(RC) _cairo_atomic_int_get (&(RC)->ref_count) - -#define CAIRO_REFERENCE_COUNT_INVALID_VALUE ((cairo_atomic_int_t) -1) -#define CAIRO_REFERENCE_COUNT_INVALID {CAIRO_REFERENCE_COUNT_INVALID_VALUE} - -#define CAIRO_REFERENCE_COUNT_IS_INVALID(RC) (CAIRO_REFERENCE_COUNT_GET_VALUE (RC) == CAIRO_REFERENCE_COUNT_INVALID_VALUE) - -#define CAIRO_REFERENCE_COUNT_HAS_REFERENCE(RC) (CAIRO_REFERENCE_COUNT_GET_VALUE (RC) > 0) - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-region-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-region-private.h deleted file mode 100644 index 549e5087898..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-region-private.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Owen Taylor - * Vladimir Vukicevic - * Søren Sandmann - */ - -#ifndef CAIRO_REGION_PRIVATE_H -#define CAIRO_REGION_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-reference-count-private.h" - -#include - -CAIRO_BEGIN_DECLS - -struct _cairo_region { - cairo_reference_count_t ref_count; - cairo_status_t status; - - pixman_region32_t rgn; -}; - -cairo_private cairo_region_t * -_cairo_region_create_in_error (cairo_status_t status); - -cairo_private void -_cairo_region_init (cairo_region_t *region); - -cairo_private void -_cairo_region_init_rectangle (cairo_region_t *region, - const cairo_rectangle_int_t *rectangle); - -cairo_private void -_cairo_region_fini (cairo_region_t *region); - -cairo_private cairo_region_t * -_cairo_region_create_from_boxes (const cairo_box_t *boxes, int count); - -cairo_private cairo_box_t * -_cairo_region_get_boxes (const cairo_region_t *region, int *nbox); - -CAIRO_END_DECLS - -#endif /* CAIRO_REGION_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-region.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-region.c deleted file mode 100644 index ccfb2200e14..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-region.c +++ /dev/null @@ -1,939 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Owen Taylor - * Vladimir Vukicevic - * Søren Sandmann - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-region-private.h" - -/* XXX need to update pixman headers to be const as appropriate */ -#define CONST_CAST (pixman_region32_t *) - -/** - * SECTION:cairo-region - * @Title: Regions - * @Short_Description: Representing a pixel-aligned area - * - * Regions are a simple graphical data type representing an area of - * integer-aligned rectangles. They are often used on raster surfaces - * to track areas of interest, such as change or clip areas. - **/ - -static const cairo_region_t _cairo_region_nil = { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_NO_MEMORY, /* status */ -}; - -cairo_region_t * -_cairo_region_create_in_error (cairo_status_t status) -{ - switch (status) { - case CAIRO_STATUS_NO_MEMORY: - return (cairo_region_t *) &_cairo_region_nil; - - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - /* fall-through */ - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_STATUS: - case CAIRO_STATUS_INVALID_CONTENT: - case CAIRO_STATUS_INVALID_FORMAT: - case CAIRO_STATUS_INVALID_VISUAL: - case CAIRO_STATUS_READ_ERROR: - case CAIRO_STATUS_WRITE_ERROR: - case CAIRO_STATUS_FILE_NOT_FOUND: - case CAIRO_STATUS_TEMP_FILE_ERROR: - case CAIRO_STATUS_INVALID_STRIDE: - case CAIRO_STATUS_INVALID_SIZE: - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - case CAIRO_STATUS_DEVICE_ERROR: - case CAIRO_STATUS_INVALID_RESTORE: - case CAIRO_STATUS_INVALID_POP_GROUP: - case CAIRO_STATUS_NO_CURRENT_POINT: - case CAIRO_STATUS_INVALID_MATRIX: - case CAIRO_STATUS_NULL_POINTER: - case CAIRO_STATUS_INVALID_STRING: - case CAIRO_STATUS_INVALID_PATH_DATA: - case CAIRO_STATUS_SURFACE_FINISHED: - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_DASH: - case CAIRO_STATUS_INVALID_DSC_COMMENT: - case CAIRO_STATUS_INVALID_INDEX: - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: - case CAIRO_STATUS_FONT_TYPE_MISMATCH: - case CAIRO_STATUS_USER_FONT_IMMUTABLE: - case CAIRO_STATUS_USER_FONT_ERROR: - case CAIRO_STATUS_NEGATIVE_COUNT: - case CAIRO_STATUS_INVALID_CLUSTERS: - case CAIRO_STATUS_INVALID_SLANT: - case CAIRO_STATUS_INVALID_WEIGHT: - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: - case CAIRO_STATUS_DEVICE_FINISHED: - case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: - default: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_region_t *) &_cairo_region_nil; - } -} - -/** - * _cairo_region_set_error: - * @region: a region - * @status: a status value indicating an error - * - * Atomically sets region->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS or any of the internal - * status values. - * - * All assignments of an error status to region->status should happen - * through _cairo_region_set_error(). Note that due to the nature of - * the atomic operation, it is not safe to call this function on the - * nil objects. - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - * - * Return value: the error status. - **/ -static cairo_status_t -_cairo_region_set_error (cairo_region_t *region, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return CAIRO_STATUS_SUCCESS; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (®ion->status, status); - - return _cairo_error (status); -} - -void -_cairo_region_init (cairo_region_t *region) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (region, sizeof (cairo_region_t))); - - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); - pixman_region32_init (®ion->rgn); -} - -void -_cairo_region_init_rectangle (cairo_region_t *region, - const cairo_rectangle_int_t *rectangle) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (region, sizeof (cairo_region_t))); - - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); - pixman_region32_init_rect (®ion->rgn, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); -} - -void -_cairo_region_fini (cairo_region_t *region) -{ - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); - pixman_region32_fini (®ion->rgn); - VG (VALGRIND_MAKE_MEM_NOACCESS (region, sizeof (cairo_region_t))); -} - -/** - * cairo_region_create: - * - * Allocates a new empty region object. - * - * Return value: A newly allocated #cairo_region_t. Free with - * cairo_region_destroy(). This function always returns a - * valid pointer; if memory cannot be allocated, then a special - * error object is returned where all operations on the object do nothing. - * You can check for this with cairo_region_status(). - * - * Since: 1.10 - **/ -cairo_region_t * -cairo_region_create (void) -{ - cairo_region_t *region; - - region = _cairo_malloc (sizeof (cairo_region_t)); - if (region == NULL) - return (cairo_region_t *) &_cairo_region_nil; - - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - - pixman_region32_init (®ion->rgn); - - return region; -} -slim_hidden_def (cairo_region_create); - -/** - * cairo_region_create_rectangles: - * @rects: an array of @count rectangles - * @count: number of rectangles - * - * Allocates a new region object containing the union of all given @rects. - * - * Return value: A newly allocated #cairo_region_t. Free with - * cairo_region_destroy(). This function always returns a - * valid pointer; if memory cannot be allocated, then a special - * error object is returned where all operations on the object do nothing. - * You can check for this with cairo_region_status(). - * - * Since: 1.10 - **/ -cairo_region_t * -cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, - int count) -{ - pixman_box32_t stack_pboxes[CAIRO_STACK_ARRAY_LENGTH (pixman_box32_t)]; - pixman_box32_t *pboxes = stack_pboxes; - cairo_region_t *region; - int i; - - region = _cairo_malloc (sizeof (cairo_region_t)); - if (unlikely (region == NULL)) - return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - region->status = CAIRO_STATUS_SUCCESS; - - if (count == 1) { - pixman_region32_init_rect (®ion->rgn, - rects->x, rects->y, - rects->width, rects->height); - - return region; - } - - if (count > ARRAY_LENGTH (stack_pboxes)) { - pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t)); - if (unlikely (pboxes == NULL)) { - free (region); - return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - } - - for (i = 0; i < count; i++) { - pboxes[i].x1 = rects[i].x; - pboxes[i].y1 = rects[i].y; - pboxes[i].x2 = rects[i].x + rects[i].width; - pboxes[i].y2 = rects[i].y + rects[i].height; - } - - i = pixman_region32_init_rects (®ion->rgn, pboxes, count); - - if (pboxes != stack_pboxes) - free (pboxes); - - if (unlikely (i == 0)) { - free (region); - return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - return region; -} -slim_hidden_def (cairo_region_create_rectangles); - -cairo_region_t * -_cairo_region_create_from_boxes (const cairo_box_t *boxes, int count) -{ - cairo_region_t *region; - - region = _cairo_malloc (sizeof (cairo_region_t)); - if (unlikely (region == NULL)) - return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - region->status = CAIRO_STATUS_SUCCESS; - - if (! pixman_region32_init_rects (®ion->rgn, - (pixman_box32_t *)boxes, count)) { - free (region); - return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - return region; -} - -cairo_box_t * -_cairo_region_get_boxes (const cairo_region_t *region, int *nbox) -{ - if (region->status) { - nbox = 0; - return NULL; - } - - return (cairo_box_t *) pixman_region32_rectangles (CONST_CAST ®ion->rgn, nbox); -} - -/** - * cairo_region_create_rectangle: - * @rectangle: a #cairo_rectangle_int_t - * - * Allocates a new region object containing @rectangle. - * - * Return value: A newly allocated #cairo_region_t. Free with - * cairo_region_destroy(). This function always returns a - * valid pointer; if memory cannot be allocated, then a special - * error object is returned where all operations on the object do nothing. - * You can check for this with cairo_region_status(). - * - * Since: 1.10 - **/ -cairo_region_t * -cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle) -{ - cairo_region_t *region; - - region = _cairo_malloc (sizeof (cairo_region_t)); - if (unlikely (region == NULL)) - return (cairo_region_t *) &_cairo_region_nil; - - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - - pixman_region32_init_rect (®ion->rgn, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); - - return region; -} -slim_hidden_def (cairo_region_create_rectangle); - -/** - * cairo_region_copy: - * @original: a #cairo_region_t - * - * Allocates a new region object copying the area from @original. - * - * Return value: A newly allocated #cairo_region_t. Free with - * cairo_region_destroy(). This function always returns a - * valid pointer; if memory cannot be allocated, then a special - * error object is returned where all operations on the object do nothing. - * You can check for this with cairo_region_status(). - * - * Since: 1.10 - **/ -cairo_region_t * -cairo_region_copy (const cairo_region_t *original) -{ - cairo_region_t *copy; - - if (original != NULL && original->status) - return (cairo_region_t *) &_cairo_region_nil; - - copy = cairo_region_create (); - if (unlikely (copy->status)) - return copy; - - if (original != NULL && - ! pixman_region32_copy (©->rgn, CONST_CAST &original->rgn)) - { - cairo_region_destroy (copy); - return (cairo_region_t *) &_cairo_region_nil; - } - - return copy; -} -slim_hidden_def (cairo_region_copy); - -/** - * cairo_region_reference: - * @region: a #cairo_region_t - * - * Increases the reference count on @region by one. This prevents - * @region from being destroyed until a matching call to - * cairo_region_destroy() is made. - * - * Return value: the referenced #cairo_region_t. - * - * Since: 1.10 - **/ -cairo_region_t * -cairo_region_reference (cairo_region_t *region) -{ - if (region == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (®ion->ref_count)) - return NULL; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); - - _cairo_reference_count_inc (®ion->ref_count); - return region; -} -slim_hidden_def (cairo_region_reference); - -/** - * cairo_region_destroy: - * @region: a #cairo_region_t - * - * Destroys a #cairo_region_t object created with - * cairo_region_create(), cairo_region_copy(), or - * or cairo_region_create_rectangle(). - * - * Since: 1.10 - **/ -void -cairo_region_destroy (cairo_region_t *region) -{ - if (region == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (®ion->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); - - if (! _cairo_reference_count_dec_and_test (®ion->ref_count)) - return; - - _cairo_region_fini (region); - free (region); -} -slim_hidden_def (cairo_region_destroy); - -/** - * cairo_region_num_rectangles: - * @region: a #cairo_region_t - * - * Returns the number of rectangles contained in @region. - * - * Return value: The number of rectangles contained in @region. - * - * Since: 1.10 - **/ -int -cairo_region_num_rectangles (const cairo_region_t *region) -{ - if (region->status) - return 0; - - return pixman_region32_n_rects (CONST_CAST ®ion->rgn); -} -slim_hidden_def (cairo_region_num_rectangles); - -/** - * cairo_region_get_rectangle: - * @region: a #cairo_region_t - * @nth: a number indicating which rectangle should be returned - * @rectangle: return location for a #cairo_rectangle_int_t - * - * Stores the @nth rectangle from the region in @rectangle. - * - * Since: 1.10 - **/ -void -cairo_region_get_rectangle (const cairo_region_t *region, - int nth, - cairo_rectangle_int_t *rectangle) -{ - pixman_box32_t *pbox; - - if (region->status) { - rectangle->x = rectangle->y = 0; - rectangle->width = rectangle->height = 0; - return; - } - - pbox = pixman_region32_rectangles (CONST_CAST ®ion->rgn, NULL) + nth; - - rectangle->x = pbox->x1; - rectangle->y = pbox->y1; - rectangle->width = pbox->x2 - pbox->x1; - rectangle->height = pbox->y2 - pbox->y1; -} -slim_hidden_def (cairo_region_get_rectangle); - -/** - * cairo_region_get_extents: - * @region: a #cairo_region_t - * @extents: rectangle into which to store the extents - * - * Gets the bounding rectangle of @region as a #cairo_rectangle_int_t - * - * Since: 1.10 - **/ -void -cairo_region_get_extents (const cairo_region_t *region, - cairo_rectangle_int_t *extents) -{ - pixman_box32_t *pextents; - - if (region->status) { - extents->x = extents->y = 0; - extents->width = extents->height = 0; - return; - } - - pextents = pixman_region32_extents (CONST_CAST ®ion->rgn); - - extents->x = pextents->x1; - extents->y = pextents->y1; - extents->width = pextents->x2 - pextents->x1; - extents->height = pextents->y2 - pextents->y1; -} -slim_hidden_def (cairo_region_get_extents); - -/** - * cairo_region_status: - * @region: a #cairo_region_t - * - * Checks whether an error has previous occurred for this - * region object. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_status (const cairo_region_t *region) -{ - return region->status; -} -slim_hidden_def (cairo_region_status); - -/** - * cairo_region_subtract: - * @dst: a #cairo_region_t - * @other: another #cairo_region_t - * - * Subtracts @other from @dst and places the result in @dst - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_subtract (cairo_region_t *dst, const cairo_region_t *other) -{ - if (dst->status) - return dst->status; - - if (other->status) - return _cairo_region_set_error (dst, other->status); - - if (! pixman_region32_subtract (&dst->rgn, - &dst->rgn, - CONST_CAST &other->rgn)) - { - return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - } - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_region_subtract); - -/** - * cairo_region_subtract_rectangle: - * @dst: a #cairo_region_t - * @rectangle: a #cairo_rectangle_int_t - * - * Subtracts @rectangle from @dst and places the result in @dst - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_subtract_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - pixman_region32_t region; - - if (dst->status) - return dst->status; - - pixman_region32_init_rect (®ion, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); - - if (! pixman_region32_subtract (&dst->rgn, &dst->rgn, ®ion)) - status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - pixman_region32_fini (®ion); - - return status; -} -slim_hidden_def (cairo_region_subtract_rectangle); - -/** - * cairo_region_intersect: - * @dst: a #cairo_region_t - * @other: another #cairo_region_t - * - * Computes the intersection of @dst with @other and places the result in @dst - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_intersect (cairo_region_t *dst, const cairo_region_t *other) -{ - if (dst->status) - return dst->status; - - if (other->status) - return _cairo_region_set_error (dst, other->status); - - if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn)) - return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_region_intersect); - -/** - * cairo_region_intersect_rectangle: - * @dst: a #cairo_region_t - * @rectangle: a #cairo_rectangle_int_t - * - * Computes the intersection of @dst with @rectangle and places the - * result in @dst - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_intersect_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - pixman_region32_t region; - - if (dst->status) - return dst->status; - - pixman_region32_init_rect (®ion, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); - - if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, ®ion)) - status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - pixman_region32_fini (®ion); - - return status; -} -slim_hidden_def (cairo_region_intersect_rectangle); - -/** - * cairo_region_union: - * @dst: a #cairo_region_t - * @other: another #cairo_region_t - * - * Computes the union of @dst with @other and places the result in @dst - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_union (cairo_region_t *dst, - const cairo_region_t *other) -{ - if (dst->status) - return dst->status; - - if (other->status) - return _cairo_region_set_error (dst, other->status); - - if (! pixman_region32_union (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn)) - return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_region_union); - -/** - * cairo_region_union_rectangle: - * @dst: a #cairo_region_t - * @rectangle: a #cairo_rectangle_int_t - * - * Computes the union of @dst with @rectangle and places the result in @dst. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_union_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - pixman_region32_t region; - - if (dst->status) - return dst->status; - - pixman_region32_init_rect (®ion, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); - - if (! pixman_region32_union (&dst->rgn, &dst->rgn, ®ion)) - status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - pixman_region32_fini (®ion); - - return status; -} -slim_hidden_def (cairo_region_union_rectangle); - -/** - * cairo_region_xor: - * @dst: a #cairo_region_t - * @other: another #cairo_region_t - * - * Computes the exclusive difference of @dst with @other and places the - * result in @dst. That is, @dst will be set to contain all areas that - * are either in @dst or in @other, but not in both. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - pixman_region32_t tmp; - - if (dst->status) - return dst->status; - - if (other->status) - return _cairo_region_set_error (dst, other->status); - - pixman_region32_init (&tmp); - - /* XXX: get an xor function into pixman */ - if (! pixman_region32_subtract (&tmp, CONST_CAST &other->rgn, &dst->rgn) || - ! pixman_region32_subtract (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn) || - ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp)) - status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - pixman_region32_fini (&tmp); - - return status; -} -slim_hidden_def (cairo_region_xor); - -/** - * cairo_region_xor_rectangle: - * @dst: a #cairo_region_t - * @rectangle: a #cairo_rectangle_int_t - * - * Computes the exclusive difference of @dst with @rectangle and places the - * result in @dst. That is, @dst will be set to contain all areas that are - * either in @dst or in @rectangle, but not in both. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY - * - * Since: 1.10 - **/ -cairo_status_t -cairo_region_xor_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - pixman_region32_t region, tmp; - - if (dst->status) - return dst->status; - - pixman_region32_init_rect (®ion, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); - pixman_region32_init (&tmp); - - /* XXX: get an xor function into pixman */ - if (! pixman_region32_subtract (&tmp, ®ion, &dst->rgn) || - ! pixman_region32_subtract (&dst->rgn, &dst->rgn, ®ion) || - ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp)) - status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); - - pixman_region32_fini (&tmp); - pixman_region32_fini (®ion); - - return status; -} -slim_hidden_def (cairo_region_xor_rectangle); - -/** - * cairo_region_is_empty: - * @region: a #cairo_region_t - * - * Checks whether @region is empty. - * - * Return value: %TRUE if @region is empty, %FALSE if it isn't. - * - * Since: 1.10 - **/ -cairo_bool_t -cairo_region_is_empty (const cairo_region_t *region) -{ - if (region->status) - return TRUE; - - return ! pixman_region32_not_empty (CONST_CAST ®ion->rgn); -} -slim_hidden_def (cairo_region_is_empty); - -/** - * cairo_region_translate: - * @region: a #cairo_region_t - * @dx: Amount to translate in the x direction - * @dy: Amount to translate in the y direction - * - * Translates @region by (@dx, @dy). - * - * Since: 1.10 - **/ -void -cairo_region_translate (cairo_region_t *region, - int dx, int dy) -{ - if (region->status) - return; - - pixman_region32_translate (®ion->rgn, dx, dy); -} -slim_hidden_def (cairo_region_translate); - -/** - * cairo_region_contains_rectangle: - * @region: a #cairo_region_t - * @rectangle: a #cairo_rectangle_int_t - * - * Checks whether @rectangle is inside, outside or partially contained - * in @region - * - * Return value: - * %CAIRO_REGION_OVERLAP_IN if @rectangle is entirely inside @region, - * %CAIRO_REGION_OVERLAP_OUT if @rectangle is entirely outside @region, or - * %CAIRO_REGION_OVERLAP_PART if @rectangle is partially inside and partially outside @region. - * - * Since: 1.10 - **/ -cairo_region_overlap_t -cairo_region_contains_rectangle (const cairo_region_t *region, - const cairo_rectangle_int_t *rectangle) -{ - pixman_box32_t pbox; - pixman_region_overlap_t poverlap; - - if (region->status) - return CAIRO_REGION_OVERLAP_OUT; - - pbox.x1 = rectangle->x; - pbox.y1 = rectangle->y; - pbox.x2 = rectangle->x + rectangle->width; - pbox.y2 = rectangle->y + rectangle->height; - - poverlap = pixman_region32_contains_rectangle (CONST_CAST ®ion->rgn, - &pbox); - switch (poverlap) { - default: - case PIXMAN_REGION_OUT: return CAIRO_REGION_OVERLAP_OUT; - case PIXMAN_REGION_IN: return CAIRO_REGION_OVERLAP_IN; - case PIXMAN_REGION_PART: return CAIRO_REGION_OVERLAP_PART; - } -} -slim_hidden_def (cairo_region_contains_rectangle); - -/** - * cairo_region_contains_point: - * @region: a #cairo_region_t - * @x: the x coordinate of a point - * @y: the y coordinate of a point - * - * Checks whether (@x, @y) is contained in @region. - * - * Return value: %TRUE if (@x, @y) is contained in @region, %FALSE if it is not. - * - * Since: 1.10 - **/ -cairo_bool_t -cairo_region_contains_point (const cairo_region_t *region, - int x, int y) -{ - pixman_box32_t box; - - if (region->status) - return FALSE; - - return pixman_region32_contains_point (CONST_CAST ®ion->rgn, x, y, &box); -} -slim_hidden_def (cairo_region_contains_point); - -/** - * cairo_region_equal: - * @a: a #cairo_region_t or %NULL - * @b: a #cairo_region_t or %NULL - * - * Compares whether region_a is equivalent to region_b. %NULL as an argument - * is equal to itself, but not to any non-%NULL region. - * - * Return value: %TRUE if both regions contained the same coverage, - * %FALSE if it is not or any region is in an error status. - * - * Since: 1.10 - **/ -cairo_bool_t -cairo_region_equal (const cairo_region_t *a, - const cairo_region_t *b) -{ - /* error objects are never equal */ - if ((a != NULL && a->status) || (b != NULL && b->status)) - return FALSE; - - if (a == b) - return TRUE; - - if (a == NULL || b == NULL) - return FALSE; - - return pixman_region32_equal (CONST_CAST &a->rgn, CONST_CAST &b->rgn); -} -slim_hidden_def (cairo_region_equal); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree-private.h deleted file mode 100644 index 27806cab603..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree-private.h +++ /dev/null @@ -1,142 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - * - */ - -#ifndef CAIRO_RTREE_PRIVATE_H -#define CAIRO_RTREE_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" -#include "cairo-types-private.h" - -#include "cairo-freelist-private.h" -#include "cairo-list-inline.h" - -enum { - CAIRO_RTREE_NODE_AVAILABLE, - CAIRO_RTREE_NODE_DIVIDED, - CAIRO_RTREE_NODE_OCCUPIED, -}; - -typedef struct _cairo_rtree_node { - struct _cairo_rtree_node *children[4], *parent; - cairo_list_t link; - uint16_t pinned; - uint16_t state; - uint16_t x, y; - uint16_t width, height; -} cairo_rtree_node_t; - -typedef struct _cairo_rtree { - cairo_rtree_node_t root; - int min_size; - cairo_list_t pinned; - cairo_list_t available; - cairo_list_t evictable; - void (*destroy) (cairo_rtree_node_t *); - cairo_freepool_t node_freepool; -} cairo_rtree_t; - -cairo_private cairo_rtree_node_t * -_cairo_rtree_node_create (cairo_rtree_t *rtree, - cairo_rtree_node_t *parent, - int x, - int y, - int width, - int height); - -cairo_private cairo_status_t -_cairo_rtree_node_insert (cairo_rtree_t *rtree, - cairo_rtree_node_t *node, - int width, - int height, - cairo_rtree_node_t **out); - -cairo_private void -_cairo_rtree_node_collapse (cairo_rtree_t *rtree, cairo_rtree_node_t *node); - -cairo_private void -_cairo_rtree_node_remove (cairo_rtree_t *rtree, cairo_rtree_node_t *node); - -cairo_private void -_cairo_rtree_node_destroy (cairo_rtree_t *rtree, cairo_rtree_node_t *node); - -cairo_private void -_cairo_rtree_init (cairo_rtree_t *rtree, - int width, - int height, - int min_size, - int node_size, - void (*destroy)(cairo_rtree_node_t *)); - -cairo_private cairo_int_status_t -_cairo_rtree_insert (cairo_rtree_t *rtree, - int width, - int height, - cairo_rtree_node_t **out); - -cairo_private cairo_int_status_t -_cairo_rtree_evict_random (cairo_rtree_t *rtree, - int width, - int height, - cairo_rtree_node_t **out); - -cairo_private void -_cairo_rtree_foreach (cairo_rtree_t *rtree, - void (*func)(cairo_rtree_node_t *, void *data), - void *data); - -static inline void * -_cairo_rtree_pin (cairo_rtree_t *rtree, cairo_rtree_node_t *node) -{ - assert (node->state == CAIRO_RTREE_NODE_OCCUPIED); - if (! node->pinned) { - cairo_list_move (&node->link, &rtree->pinned); - node->pinned = 1; - } - - return node; -} - -cairo_private void -_cairo_rtree_unpin (cairo_rtree_t *rtree); - -cairo_private void -_cairo_rtree_reset (cairo_rtree_t *rtree); - -cairo_private void -_cairo_rtree_fini (cairo_rtree_t *rtree); - -#endif /* CAIRO_RTREE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree.c deleted file mode 100644 index dbc040929af..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-rtree.c +++ /dev/null @@ -1,388 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - * - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-rtree-private.h" - -cairo_rtree_node_t * -_cairo_rtree_node_create (cairo_rtree_t *rtree, - cairo_rtree_node_t *parent, - int x, - int y, - int width, - int height) -{ - cairo_rtree_node_t *node; - - node = _cairo_freepool_alloc (&rtree->node_freepool); - if (node == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - node->children[0] = NULL; - node->parent = parent; - node->state = CAIRO_RTREE_NODE_AVAILABLE; - node->pinned = FALSE; - node->x = x; - node->y = y; - node->width = width; - node->height = height; - - cairo_list_add (&node->link, &rtree->available); - - return node; -} - -void -_cairo_rtree_node_destroy (cairo_rtree_t *rtree, cairo_rtree_node_t *node) -{ - int i; - - cairo_list_del (&node->link); - - if (node->state == CAIRO_RTREE_NODE_OCCUPIED) { - rtree->destroy (node); - } else { - for (i = 0; i < 4 && node->children[i] != NULL; i++) - _cairo_rtree_node_destroy (rtree, node->children[i]); - } - - _cairo_freepool_free (&rtree->node_freepool, node); -} - -void -_cairo_rtree_node_collapse (cairo_rtree_t *rtree, cairo_rtree_node_t *node) -{ - int i; - - do { - assert (node->state == CAIRO_RTREE_NODE_DIVIDED); - - for (i = 0; i < 4 && node->children[i] != NULL; i++) - if (node->children[i]->state != CAIRO_RTREE_NODE_AVAILABLE) - return; - - for (i = 0; i < 4 && node->children[i] != NULL; i++) - _cairo_rtree_node_destroy (rtree, node->children[i]); - - node->children[0] = NULL; - node->state = CAIRO_RTREE_NODE_AVAILABLE; - cairo_list_move (&node->link, &rtree->available); - } while ((node = node->parent) != NULL); -} - -cairo_status_t -_cairo_rtree_node_insert (cairo_rtree_t *rtree, - cairo_rtree_node_t *node, - int width, - int height, - cairo_rtree_node_t **out) -{ - int w, h, i; - - assert (node->state == CAIRO_RTREE_NODE_AVAILABLE); - assert (node->pinned == FALSE); - - if (node->width - width > rtree->min_size || - node->height - height > rtree->min_size) - { - w = node->width - width; - h = node->height - height; - - i = 0; - node->children[i] = _cairo_rtree_node_create (rtree, node, - node->x, node->y, - width, height); - if (unlikely (node->children[i] == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - i++; - - if (w > rtree->min_size) { - node->children[i] = _cairo_rtree_node_create (rtree, node, - node->x + width, - node->y, - w, height); - if (unlikely (node->children[i] == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - i++; - } - - if (h > rtree->min_size) { - node->children[i] = _cairo_rtree_node_create (rtree, node, - node->x, - node->y + height, - width, h); - if (unlikely (node->children[i] == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - i++; - - if (w > rtree->min_size) { - node->children[i] = _cairo_rtree_node_create (rtree, node, - node->x + width, - node->y + height, - w, h); - if (unlikely (node->children[i] == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - i++; - } - } - - if (i < 4) - node->children[i] = NULL; - - node->state = CAIRO_RTREE_NODE_DIVIDED; - cairo_list_move (&node->link, &rtree->evictable); - node = node->children[0]; - } - - node->state = CAIRO_RTREE_NODE_OCCUPIED; - cairo_list_move (&node->link, &rtree->evictable); - *out = node; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_rtree_node_remove (cairo_rtree_t *rtree, cairo_rtree_node_t *node) -{ - assert (node->state == CAIRO_RTREE_NODE_OCCUPIED); - assert (node->pinned == FALSE); - - rtree->destroy (node); - - node->state = CAIRO_RTREE_NODE_AVAILABLE; - cairo_list_move (&node->link, &rtree->available); - - _cairo_rtree_node_collapse (rtree, node->parent); -} - -cairo_int_status_t -_cairo_rtree_insert (cairo_rtree_t *rtree, - int width, - int height, - cairo_rtree_node_t **out) -{ - cairo_rtree_node_t *node; - - cairo_list_foreach_entry (node, cairo_rtree_node_t, - &rtree->available, link) - { - if (node->width >= width && node->height >= height) - return _cairo_rtree_node_insert (rtree, node, width, height, out); - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static uint32_t -hars_petruska_f54_1_random (void) -{ -#define rol(x,k) ((x << k) | (x >> (32-k))) - static uint32_t x; - return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; -#undef rol -} - -cairo_int_status_t -_cairo_rtree_evict_random (cairo_rtree_t *rtree, - int width, - int height, - cairo_rtree_node_t **out) -{ - cairo_int_status_t ret = CAIRO_INT_STATUS_UNSUPPORTED; - cairo_rtree_node_t *node, *next; - cairo_list_t tmp_pinned; - int i, cnt; - - cairo_list_init (&tmp_pinned); - - /* propagate pinned from children to root */ - cairo_list_foreach_entry_safe (node, next, - cairo_rtree_node_t, &rtree->pinned, link) { - node = node->parent; - while (node && ! node->pinned) { - node->pinned = 1; - cairo_list_move (&node->link, &tmp_pinned); - node = node->parent; - } - } - - cnt = 0; - cairo_list_foreach_entry (node, cairo_rtree_node_t, - &rtree->evictable, link) - { - if (node->width >= width && node->height >= height) - cnt++; - } - - if (cnt == 0) - goto out; - - cnt = hars_petruska_f54_1_random () % cnt; - cairo_list_foreach_entry (node, cairo_rtree_node_t, - &rtree->evictable, link) - { - if (node->width >= width && node->height >= height && cnt-- == 0) { - if (node->state == CAIRO_RTREE_NODE_OCCUPIED) { - rtree->destroy (node); - } else { - for (i = 0; i < 4 && node->children[i] != NULL; i++) - _cairo_rtree_node_destroy (rtree, node->children[i]); - node->children[0] = NULL; - } - - node->state = CAIRO_RTREE_NODE_AVAILABLE; - cairo_list_move (&node->link, &rtree->available); - - *out = node; - ret = CAIRO_STATUS_SUCCESS; - break; - } - } - -out: - while (! cairo_list_is_empty (&tmp_pinned)) { - node = cairo_list_first_entry (&tmp_pinned, cairo_rtree_node_t, link); - node->pinned = 0; - cairo_list_move (&node->link, &rtree->evictable); - } - return ret; -} - -void -_cairo_rtree_unpin (cairo_rtree_t *rtree) -{ - while (! cairo_list_is_empty (&rtree->pinned)) { - cairo_rtree_node_t *node = cairo_list_first_entry (&rtree->pinned, - cairo_rtree_node_t, - link); - node->pinned = 0; - cairo_list_move (&node->link, &rtree->evictable); - } -} - -void -_cairo_rtree_init (cairo_rtree_t *rtree, - int width, - int height, - int min_size, - int node_size, - void (*destroy) (cairo_rtree_node_t *)) -{ - assert (node_size >= (int) sizeof (cairo_rtree_node_t)); - _cairo_freepool_init (&rtree->node_freepool, node_size); - - cairo_list_init (&rtree->available); - cairo_list_init (&rtree->pinned); - cairo_list_init (&rtree->evictable); - - rtree->min_size = min_size; - rtree->destroy = destroy; - - memset (&rtree->root, 0, sizeof (rtree->root)); - rtree->root.width = width; - rtree->root.height = height; - rtree->root.state = CAIRO_RTREE_NODE_AVAILABLE; - cairo_list_add (&rtree->root.link, &rtree->available); -} - -void -_cairo_rtree_reset (cairo_rtree_t *rtree) -{ - int i; - - if (rtree->root.state == CAIRO_RTREE_NODE_OCCUPIED) { - rtree->destroy (&rtree->root); - } else { - for (i = 0; i < 4 && rtree->root.children[i] != NULL; i++) - _cairo_rtree_node_destroy (rtree, rtree->root.children[i]); - rtree->root.children[0] = NULL; - } - - cairo_list_init (&rtree->available); - cairo_list_init (&rtree->evictable); - cairo_list_init (&rtree->pinned); - - rtree->root.state = CAIRO_RTREE_NODE_AVAILABLE; - rtree->root.pinned = FALSE; - cairo_list_add (&rtree->root.link, &rtree->available); -} - -static void -_cairo_rtree_node_foreach (cairo_rtree_node_t *node, - void (*func)(cairo_rtree_node_t *, void *data), - void *data) -{ - int i; - - for (i = 0; i < 4 && node->children[i] != NULL; i++) - _cairo_rtree_node_foreach(node->children[i], func, data); - - func(node, data); -} - -void -_cairo_rtree_foreach (cairo_rtree_t *rtree, - void (*func)(cairo_rtree_node_t *, void *data), - void *data) -{ - int i; - - if (rtree->root.state == CAIRO_RTREE_NODE_OCCUPIED) { - func(&rtree->root, data); - } else { - for (i = 0; i < 4 && rtree->root.children[i] != NULL; i++) - _cairo_rtree_node_foreach (rtree->root.children[i], func, data); - } -} - -void -_cairo_rtree_fini (cairo_rtree_t *rtree) -{ - int i; - - if (rtree->root.state == CAIRO_RTREE_NODE_OCCUPIED) { - rtree->destroy (&rtree->root); - } else { - for (i = 0; i < 4 && rtree->root.children[i] != NULL; i++) - _cairo_rtree_node_destroy (rtree, rtree->root.children[i]); - } - - _cairo_freepool_fini (&rtree->node_freepool); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-private.h deleted file mode 100644 index da7b3469834..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-private.h +++ /dev/null @@ -1,183 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_SCALED_FONT_PRIVATE_H -#define CAIRO_SCALED_FONT_PRIVATE_H - -#include "cairo.h" - -#include "cairo-types-private.h" -#include "cairo-list-private.h" -#include "cairo-mutex-type-private.h" -#include "cairo-reference-count-private.h" - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_scaled_glyph_page cairo_scaled_glyph_page_t; - -struct _cairo_scaled_font { - /* For most cairo objects, the rule for multiple threads is that - * the user is responsible for any locking if the same object is - * manipulated from multiple threads simultaneously. - * - * However, with the caching that cairo does for scaled fonts, a - * user can easily end up with the same cairo_scaled_font object - * being manipulated from multiple threads without the user ever - * being aware of this, (and in fact, unable to control it). - * - * So, as a special exception, the cairo implementation takes care - * of all locking needed for cairo_scaled_font_t. Most of what is - * in the scaled font is immutable, (which is what allows for the - * sharing in the first place). The things that are modified and - * the locks protecting them are as follows: - * - * 1. The reference count (scaled_font->ref_count) - * - * Modifications to the reference count are protected by the - * _cairo_scaled_font_map_mutex. This is because the reference - * count of a scaled font is intimately related with the font - * map itself, (and the magic holdovers array). - * - * 2. The cache of glyphs (scaled_font->glyphs) - * 3. The backend private data (scaled_font->surface_backend, - * scaled_font->surface_private) - * - * Modifications to these fields are protected with locks on - * scaled_font->mutex in the generic scaled_font code. - */ - - cairo_hash_entry_t hash_entry; - - /* useful bits for _cairo_scaled_font_nil */ - cairo_status_t status; - cairo_reference_count_t ref_count; - cairo_user_data_array_t user_data; - - cairo_font_face_t *original_font_face; /* may be NULL */ - - /* hash key members */ - cairo_font_face_t *font_face; /* may be NULL */ - cairo_matrix_t font_matrix; /* font space => user space */ - cairo_matrix_t ctm; /* user space => device space */ - cairo_font_options_t options; - - unsigned int placeholder : 1; /* protected by fontmap mutex */ - unsigned int holdover : 1; - unsigned int finished : 1; - - /* "live" scaled_font members */ - cairo_matrix_t scale; /* font space => device space */ - cairo_matrix_t scale_inverse; /* device space => font space */ - double max_scale; /* maximum x/y expansion of scale */ - cairo_font_extents_t extents; /* user space */ - cairo_font_extents_t fs_extents; /* font space */ - - /* The mutex protects modification to all subsequent fields. */ - cairo_mutex_t mutex; - - cairo_hash_table_t *glyphs; - cairo_list_t glyph_pages; - cairo_bool_t cache_frozen; - cairo_bool_t global_cache_frozen; - - cairo_list_t dev_privates; - - /* font backend managing this scaled font */ - const cairo_scaled_font_backend_t *backend; - cairo_list_t link; -}; - -struct _cairo_scaled_font_private { - cairo_list_t link; - const void *key; - void (*destroy) (cairo_scaled_font_private_t *, - cairo_scaled_font_t *); -}; - -struct _cairo_scaled_glyph { - cairo_hash_entry_t hash_entry; - - cairo_text_extents_t metrics; /* user-space metrics */ - cairo_text_extents_t fs_metrics; /* font-space metrics */ - cairo_box_t bbox; /* device-space bounds */ - int16_t x_advance; /* device-space rounded X advance */ - int16_t y_advance; /* device-space rounded Y advance */ - - unsigned int has_info; - cairo_image_surface_t *surface; /* device-space image */ - cairo_path_fixed_t *path; /* device-space outline */ - cairo_surface_t *recording_surface; /* device-space recording-surface */ - - const void *dev_private_key; - void *dev_private; - cairo_list_t dev_privates; -}; - -struct _cairo_scaled_glyph_private { - cairo_list_t link; - const void *key; - void (*destroy) (cairo_scaled_glyph_private_t *, - cairo_scaled_glyph_t *, - cairo_scaled_font_t *); -}; - -cairo_private cairo_scaled_font_private_t * -_cairo_scaled_font_find_private (cairo_scaled_font_t *scaled_font, - const void *key); - -cairo_private void -_cairo_scaled_font_attach_private (cairo_scaled_font_t *scaled_font, - cairo_scaled_font_private_t *priv, - const void *key, - void (*destroy) (cairo_scaled_font_private_t *, - cairo_scaled_font_t *)); - -cairo_private cairo_scaled_glyph_private_t * -_cairo_scaled_glyph_find_private (cairo_scaled_glyph_t *scaled_glyph, - const void *key); - -cairo_private void -_cairo_scaled_glyph_attach_private (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_glyph_private_t *priv, - const void *key, - void (*destroy) (cairo_scaled_glyph_private_t *, - cairo_scaled_glyph_t *, - cairo_scaled_font_t *)); - -CAIRO_END_DECLS - -#endif /* CAIRO_SCALED_FONT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets-private.h deleted file mode 100644 index 866e63d7bca..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets-private.h +++ /dev/null @@ -1,735 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H -#define CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H - -#include "cairoint.h" - -#if CAIRO_HAS_FONT_SUBSET - -typedef struct _cairo_scaled_font_subsets_glyph { - unsigned int font_id; - unsigned int subset_id; - unsigned int subset_glyph_index; - cairo_bool_t is_scaled; - cairo_bool_t is_composite; - cairo_bool_t is_latin; - double x_advance; - double y_advance; - cairo_bool_t utf8_is_mapped; - uint32_t unicode; -} cairo_scaled_font_subsets_glyph_t; - -/** - * _cairo_scaled_font_subsets_create_scaled: - * - * Create a new #cairo_scaled_font_subsets_t object which can be used - * to create subsets of any number of #cairo_scaled_font_t - * objects. This allows the (arbitrarily large and sparse) glyph - * indices of a #cairo_scaled_font_t to be mapped to one or more font - * subsets with glyph indices packed into the range - * [0 .. max_glyphs_per_subset). - * - * Return value: a pointer to the newly creates font subsets. The - * caller owns this object and should call - * _cairo_scaled_font_subsets_destroy() when done with it. - **/ -cairo_private cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_scaled (void); - -/** - * _cairo_scaled_font_subsets_create_simple: - * - * Create a new #cairo_scaled_font_subsets_t object which can be used - * to create font subsets suitable for embedding as Postscript or PDF - * simple fonts. - * - * Glyphs with an outline path available will be mapped to one font - * subset for each font face. Glyphs from bitmap fonts will mapped to - * separate font subsets for each #cairo_scaled_font_t object. - * - * The maximum number of glyphs per subset is 256. Each subset - * reserves the first glyph for the .notdef glyph. - * - * Return value: a pointer to the newly creates font subsets. The - * caller owns this object and should call - * _cairo_scaled_font_subsets_destroy() when done with it. - **/ -cairo_private cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_simple (void); - -/** - * _cairo_scaled_font_subsets_create_composite: - * - * Create a new #cairo_scaled_font_subsets_t object which can be used - * to create font subsets suitable for embedding as Postscript or PDF - * composite fonts. - * - * Glyphs with an outline path available will be mapped to one font - * subset for each font face. Each unscaled subset has a maximum of - * 65536 glyphs except for Type1 fonts which have a maximum of 256 glyphs. - * - * Glyphs from bitmap fonts will mapped to separate font subsets for - * each #cairo_scaled_font_t object. Each unscaled subset has a maximum - * of 256 glyphs. - * - * Each subset reserves the first glyph for the .notdef glyph. - * - * Return value: a pointer to the newly creates font subsets. The - * caller owns this object and should call - * _cairo_scaled_font_subsets_destroy() when done with it. - **/ -cairo_private cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_composite (void); - -/** - * _cairo_scaled_font_subsets_destroy: - * @font_subsets: a #cairo_scaled_font_subsets_t object to be destroyed - * - * Destroys @font_subsets and all resources associated with it. - **/ -cairo_private void -_cairo_scaled_font_subsets_destroy (cairo_scaled_font_subsets_t *font_subsets); - -/** - * _cairo_scaled_font_subsets_enable_latin_subset: - * @font_subsets: a #cairo_scaled_font_subsets_t object to be destroyed - * @use_latin: a #cairo_bool_t indicating if a latin subset is to be used - * - * If enabled, all CP1252 characters will be placed in a separate - * 8-bit latin subset. - **/ -cairo_private void -_cairo_scaled_font_subsets_enable_latin_subset (cairo_scaled_font_subsets_t *font_subsets, - cairo_bool_t use_latin); - -/** - * _cairo_scaled_font_subsets_map_glyph: - * @font_subsets: a #cairo_scaled_font_subsets_t - * @scaled_font: the font of the glyph to be mapped - * @scaled_font_glyph_index: the index of the glyph to be mapped - * @utf8: a string of text encoded in UTF-8 - * @utf8_len: length of @utf8 in bytes - * @subset_glyph_ret: return structure containing subset font and glyph id - * - * Map a glyph from a #cairo_scaled_font to a new index within a - * subset of that font. The mapping performed is from the tuple: - * - * (scaled_font, scaled_font_glyph_index) - * - * to the tuple: - * - * (font_id, subset_id, subset_glyph_index) - * - * This mapping is 1:1. If the input tuple has previously mapped, the - * the output tuple previously returned will be returned again. - * - * Otherwise, the return tuple will be constructed as follows: - * - * 1) There is a 1:1 correspondence between the input scaled_font - * value and the output font_id value. If no mapping has been - * previously performed with the scaled_font value then the - * smallest unused font_id value will be returned. - * - * 2) Within the set of output tuples of the same font_id value the - * smallest value of subset_id will be returned such that - * subset_glyph_index does not exceed max_glyphs_per_subset (as - * passed to _cairo_scaled_font_subsets_create()) and that the - * resulting tuple is unique. - * - * 3) The smallest value of subset_glyph_index is returned such that - * the resulting tuple is unique. - * - * The net result is that any #cairo_scaled_font_t will be represented - * by one or more font subsets. Each subset is effectively a tuple of - * (scaled_font, font_id, subset_id) and within each subset there - * exists a mapping of scaled_glyph_font_index to subset_glyph_index. - * - * This final description of a font subset is the same representation - * used by #cairo_scaled_font_subset_t as provided by - * _cairo_scaled_font_subsets_foreach. - * - * @utf8 and @utf8_len specify a string of unicode characters that the - * glyph @scaled_font_glyph_index maps to. If @utf8_is_mapped in - * @subset_glyph_ret is %TRUE, the font subsetting will (where index to - * unicode mapping is supported) ensure that @scaled_font_glyph_index - * maps to @utf8. If @utf8_is_mapped is %FALSE, - * @scaled_font_glyph_index has already been mapped to a different - * unicode string. - * - * The returned values in the #cairo_scaled_font_subsets_glyph_t struct are: - * - * @font_id: The font ID of the mapped glyph - * @subset_id : The subset ID of the mapped glyph within the @font_id - * @subset_glyph_index: The index of the mapped glyph within the @subset_id subset - * @is_scaled: If true, the mapped glyph is from a bitmap font, and separate font - * subset is created for each font scale used. If false, the outline of the mapped glyph - * is available. One font subset for each font face is created. - * @x_advance, @y_advance: When @is_scaled is true, @x_advance and @y_advance contain - * the x and y advance for the mapped glyph in device space. - * When @is_scaled is false, @x_advance and @y_advance contain the x and y advance for - * the the mapped glyph from an unhinted 1 point font. - * @utf8_is_mapped: If true the utf8 string provided to _cairo_scaled_font_subsets_map_glyph() - * is (or already was) the utf8 string mapped to this glyph. If false the glyph is already - * mapped to a different utf8 string. - * @unicode: the unicode character mapped to this glyph by the font backend. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero - * value indicating an error. Possible errors include - * %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_t *scaled_font, - unsigned long scaled_font_glyph_index, - const char * utf8, - int utf8_len, - cairo_scaled_font_subsets_glyph_t *subset_glyph_ret); - -typedef cairo_int_status_t -(*cairo_scaled_font_subset_callback_func_t) (cairo_scaled_font_subset_t *font_subset, - void *closure); - -/** - * _cairo_scaled_font_subsets_foreach_scaled: - * @font_subsets: a #cairo_scaled_font_subsets_t - * @font_subset_callback: a function to be called for each font subset - * @closure: closure data for the callback function - * - * Iterate over each unique scaled font subset as created by calls to - * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by - * unique pairs of (font_id, subset_id) as returned by - * _cairo_scaled_font_subsets_map_glyph(). - * - * For each subset, @font_subset_callback will be called and will be - * provided with both a #cairo_scaled_font_subset_t object containing - * all the glyphs in the subset as well as the value of @closure. - * - * The #cairo_scaled_font_subset_t object contains the scaled_font, - * the font_id, and the subset_id corresponding to all glyphs - * belonging to the subset. In addition, it contains an array providing - * a mapping between subset glyph indices and the original scaled font - * glyph indices. - * - * The index of the array corresponds to subset_glyph_index values - * returned by _cairo_scaled_font_subsets_map_glyph() while the - * values of the array correspond to the scaled_font_glyph_index - * values passed as input to the same function. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero - * value indicating an error. Possible errors include - * %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_scaled_font_subsets_foreach_scaled (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure); - -/** - * _cairo_scaled_font_subsets_foreach_unscaled: - * @font_subsets: a #cairo_scaled_font_subsets_t - * @font_subset_callback: a function to be called for each font subset - * @closure: closure data for the callback function - * - * Iterate over each unique unscaled font subset as created by calls to - * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by - * unique pairs of (font_id, subset_id) as returned by - * _cairo_scaled_font_subsets_map_glyph(). - * - * For each subset, @font_subset_callback will be called and will be - * provided with both a #cairo_scaled_font_subset_t object containing - * all the glyphs in the subset as well as the value of @closure. - * - * The #cairo_scaled_font_subset_t object contains the scaled_font, - * the font_id, and the subset_id corresponding to all glyphs - * belonging to the subset. In addition, it contains an array providing - * a mapping between subset glyph indices and the original scaled font - * glyph indices. - * - * The index of the array corresponds to subset_glyph_index values - * returned by _cairo_scaled_font_subsets_map_glyph() while the - * values of the array correspond to the scaled_font_glyph_index - * values passed as input to the same function. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero - * value indicating an error. Possible errors include - * %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_scaled_font_subsets_foreach_unscaled (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure); - -/** - * _cairo_scaled_font_subsets_foreach_user: - * @font_subsets: a #cairo_scaled_font_subsets_t - * @font_subset_callback: a function to be called for each font subset - * @closure: closure data for the callback function - * - * Iterate over each unique scaled font subset as created by calls to - * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by - * unique pairs of (font_id, subset_id) as returned by - * _cairo_scaled_font_subsets_map_glyph(). - * - * For each subset, @font_subset_callback will be called and will be - * provided with both a #cairo_scaled_font_subset_t object containing - * all the glyphs in the subset as well as the value of @closure. - * - * The #cairo_scaled_font_subset_t object contains the scaled_font, - * the font_id, and the subset_id corresponding to all glyphs - * belonging to the subset. In addition, it contains an array providing - * a mapping between subset glyph indices and the original scaled font - * glyph indices. - * - * The index of the array corresponds to subset_glyph_index values - * returned by _cairo_scaled_font_subsets_map_glyph() while the - * values of the array correspond to the scaled_font_glyph_index - * values passed as input to the same function. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero - * value indicating an error. Possible errors include - * %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_scaled_font_subsets_foreach_user (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure); - -/** - * _cairo_scaled_font_subset_create_glyph_names: - * @font_subsets: a #cairo_scaled_font_subsets_t - * - * Create an array of strings containing the glyph name for each glyph - * in @font_subsets. The array as store in font_subsets->glyph_names. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font backend does not support - * mapping the glyph indices to unicode characters. Possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_int_status_t -_cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset); - -typedef struct _cairo_cff_subset { - char *family_name_utf8; - char *ps_name; - double *widths; - double x_min, y_min, x_max, y_max; - double ascent, descent; - char *data; - unsigned long data_length; -} cairo_cff_subset_t; - -/** - * _cairo_cff_subset_init: - * @cff_subset: a #cairo_cff_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a - * cff file corresponding to @font_subset and initialize - * @cff_subset with information about the subset and the cff - * data. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a - * cff file, or an non-zero value indicating an error. Possible - * errors include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_cff_subset_init (cairo_cff_subset_t *cff_subset, - const char *name, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_cff_subset_fini: - * @cff_subset: a #cairo_cff_subset_t - * - * Free all resources associated with @cff_subset. After this - * call, @cff_subset should not be used again without a - * subsequent call to _cairo_cff_subset_init() again first. - **/ -cairo_private void -_cairo_cff_subset_fini (cairo_cff_subset_t *cff_subset); - -/** - * _cairo_cff_scaled_font_is_cid_cff: - * @scaled_font: a #cairo_scaled_font_t - * - * Return %TRUE if @scaled_font is a CID CFF font, otherwise return %FALSE. - **/ -cairo_private cairo_bool_t -_cairo_cff_scaled_font_is_cid_cff (cairo_scaled_font_t *scaled_font); - -/** - * _cairo_cff_fallback_init: - * @cff_subset: a #cairo_cff_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a cff - * file corresponding to @font_subset and initialize @cff_subset - * with information about the subset and the cff data. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a - * cff file, or an non-zero value indicating an error. Possible - * errors include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_cff_fallback_init (cairo_cff_subset_t *cff_subset, - const char *name, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_cff_fallback_fini: - * @cff_subset: a #cairo_cff_subset_t - * - * Free all resources associated with @cff_subset. After this - * call, @cff_subset should not be used again without a - * subsequent call to _cairo_cff_subset_init() again first. - **/ -cairo_private void -_cairo_cff_fallback_fini (cairo_cff_subset_t *cff_subset); - -typedef struct _cairo_truetype_subset { - char *family_name_utf8; - char *ps_name; - double *widths; - double x_min, y_min, x_max, y_max; - double ascent, descent; - unsigned char *data; - unsigned long data_length; - unsigned long *string_offsets; - unsigned long num_string_offsets; -} cairo_truetype_subset_t; - -/** - * _cairo_truetype_subset_init_ps: - * @truetype_subset: a #cairo_truetype_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a - * truetype file corresponding to @font_subset and initialize - * @truetype_subset with information about the subset and the truetype - * data. The generated font will be suitable for embedding in - * PostScript. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a - * truetype file, or an non-zero value indicating an error. Possible - * errors include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_truetype_subset_init_ps (cairo_truetype_subset_t *truetype_subset, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_truetype_subset_init_pdf: - * @truetype_subset: a #cairo_truetype_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a - * truetype file corresponding to @font_subset and initialize - * @truetype_subset with information about the subset and the truetype - * data. The generated font will be suitable for embedding in - * PDF. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a - * truetype file, or an non-zero value indicating an error. Possible - * errors include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_truetype_subset_init_pdf (cairo_truetype_subset_t *truetype_subset, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_truetype_subset_fini: - * @truetype_subset: a #cairo_truetype_subset_t - * - * Free all resources associated with @truetype_subset. After this - * call, @truetype_subset should not be used again without a - * subsequent call to _cairo_truetype_subset_init() again first. - **/ -cairo_private void -_cairo_truetype_subset_fini (cairo_truetype_subset_t *truetype_subset); - -cairo_private const char * -_cairo_ps_standard_encoding_to_glyphname (int glyph); - -cairo_private int -_cairo_unicode_to_winansi (unsigned long unicode); - -cairo_private const char * -_cairo_winansi_to_glyphname (int glyph); - -typedef struct _cairo_type1_subset { - char *base_font; - double *widths; - double x_min, y_min, x_max, y_max; - double ascent, descent; - char *data; - unsigned long header_length; - unsigned long data_length; - unsigned long trailer_length; -} cairo_type1_subset_t; - - -/** - * _cairo_type1_subset_init: - * @type1_subset: a #cairo_type1_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * @hex_encode: if true the encrypted portion of the font is hex encoded - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a type1 - * file corresponding to @font_subset and initialize @type1_subset - * with information about the subset and the type1 data. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1 - * file, or an non-zero value indicating an error. Possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_type1_subset_init (cairo_type1_subset_t *type_subset, - const char *name, - cairo_scaled_font_subset_t *font_subset, - cairo_bool_t hex_encode); - -/** - * _cairo_type1_subset_fini: - * @type1_subset: a #cairo_type1_subset_t - * - * Free all resources associated with @type1_subset. After this call, - * @type1_subset should not be used again without a subsequent call to - * _cairo_truetype_type1_init() again first. - **/ -cairo_private void -_cairo_type1_subset_fini (cairo_type1_subset_t *subset); - -/** - * _cairo_type1_scaled_font_is_type1: - * @scaled_font: a #cairo_scaled_font_t - * - * Return %TRUE if @scaled_font is a Type 1 font, otherwise return %FALSE. - **/ -cairo_private cairo_bool_t -_cairo_type1_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font); - -/** - * _cairo_type1_fallback_init_binary: - * @type1_subset: a #cairo_type1_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a type1 - * file corresponding to @font_subset and initialize @type1_subset - * with information about the subset and the type1 data. The encrypted - * part of the font is binary encoded. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1 - * file, or an non-zero value indicating an error. Possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_type1_fallback_init_binary (cairo_type1_subset_t *type_subset, - const char *name, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_type1_fallback_init_hex: - * @type1_subset: a #cairo_type1_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate a type1 - * file corresponding to @font_subset and initialize @type1_subset - * with information about the subset and the type1 data. The encrypted - * part of the font is hex encoded. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1 - * file, or an non-zero value indicating an error. Possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_type1_fallback_init_hex (cairo_type1_subset_t *type_subset, - const char *name, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_type1_fallback_fini: - * @type1_subset: a #cairo_type1_subset_t - * - * Free all resources associated with @type1_subset. After this call, - * @type1_subset should not be used again without a subsequent call to - * _cairo_truetype_type1_init() again first. - **/ -cairo_private void -_cairo_type1_fallback_fini (cairo_type1_subset_t *subset); - -typedef struct _cairo_type2_charstrings { - int *widths; - long x_min, y_min, x_max, y_max; - long ascent, descent; - cairo_array_t charstrings; -} cairo_type2_charstrings_t; - -/** - * _cairo_type2_charstrings_init: - * @type2_subset: a #cairo_type2_subset_t to initialize - * @font_subset: the #cairo_scaled_font_subset_t to initialize from - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) generate type2 - * charstrings to @font_subset and initialize @type2_subset - * with information about the subset. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type2 - * charstrings, or an non-zero value indicating an error. Possible errors - * include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_status_t -_cairo_type2_charstrings_init (cairo_type2_charstrings_t *charstrings, - cairo_scaled_font_subset_t *font_subset); - -/** - * _cairo_type2_charstrings_fini: - * @subset: a #cairo_type2_charstrings_t - * - * Free all resources associated with @type2_charstring. After this call, - * @type2_charstring should not be used again without a subsequent call to - * _cairo_type2_charstring_init() again first. - **/ -cairo_private void -_cairo_type2_charstrings_fini (cairo_type2_charstrings_t *charstrings); - -/** - * _cairo_truetype_index_to_ucs4: - * @scaled_font: the #cairo_scaled_font_t - * @index: the glyph index - * @ucs4: return value for the unicode value of the glyph - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) assign - * the unicode character of the glyph to @ucs4. - * - * If mapping glyph indices to unicode is supported but the unicode - * value of the specified glyph is not available, @ucs4 is set to -1. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if mapping glyph indices to unicode - * is not supported. Possible errors include %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_int_status_t -_cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font, - unsigned long index, - uint32_t *ucs4); - -/** - * _cairo_truetype_read_font_name: - * @scaled_font: the #cairo_scaled_font_t - * @ps_name: returns the PostScript name of the font - * or %NULL if the name could not be found. - * @font_name: returns the font name or %NULL if the name could not be found. - * - * If possible (depending on the format of the underlying - * #cairo_scaled_font_t and the font backend in use) read the - * PostScript and Font names from a TrueType/OpenType font. - * - * The font name is the full name of the font eg "DejaVu Sans Bold". - * The PostScript name is a shortened name with spaces removed - * suitable for use as the font name in a PS or PDF file eg - * "DejaVuSans-Bold". - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font is not TrueType/OpenType - * or the name table is not present. Possible errors include - * %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_int_status_t -_cairo_truetype_read_font_name (cairo_scaled_font_t *scaled_font, - char **ps_name, - char **font_name); - -/** - * _cairo_truetype_get_style: - * @scaled_font: the #cairo_scaled_font_t - * @weight: returns the font weight from the OS/2 table - * @bold: returns true if font is bold - * @italic: returns true if font is italic - * - * If the font is a truetype/opentype font with an OS/2 table, get the - * weight, bold, and italic data from the OS/2 table. The weight - * values have the same meaning as the lfWeight field of the Windows - * LOGFONT structure. Refer to the TrueType Specification for - * definition of the weight values. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful, - * %CAIRO_INT_STATUS_UNSUPPORTED if the font is not TrueType/OpenType - * or the OS/2 table is not present. - **/ -cairo_private cairo_int_status_t -_cairo_truetype_get_style (cairo_scaled_font_t *scaled_font, - int *weight, - cairo_bool_t *bold, - cairo_bool_t *italic); - -/** - * _cairo_escape_ps_name: - * @ps_name: returns the PostScript name with all invalid characters escaped - * - * Ensure that PostSript name is a valid PDF/PostSript name object. - * In PDF names are treated as UTF8 and non ASCII bytes, ' ', - * and '#' are encoded as '#' followed by 2 hex digits that - * encode the byte. - * - * Return value: %CAIRO_STATUS_SUCCESS if successful. Possible errors include - * %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_private cairo_int_status_t -_cairo_escape_ps_name (char **ps_name); - -#endif /* CAIRO_HAS_FONT_SUBSET */ - -#endif /* CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets.c deleted file mode 100644 index 2121761839e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font-subsets.c +++ /dev/null @@ -1,1299 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2003 University of Southern California - * Copyright © 2005 Red Hat, Inc - * Copyright © 2006 Keith Packard - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Kristian Høgsberg - * Keith Packard - * Adrian Johnson - */ - -#define _BSD_SOURCE /* for snprintf(), strdup() */ -#include "cairoint.h" -#include "cairo-error-private.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-user-font-private.h" - -#define MAX_GLYPHS_PER_SIMPLE_FONT 256 -#define MAX_GLYPHS_PER_COMPOSITE_FONT 65536 - -typedef enum { - CAIRO_SUBSETS_SCALED, - CAIRO_SUBSETS_SIMPLE, - CAIRO_SUBSETS_COMPOSITE -} cairo_subsets_type_t; - -typedef enum { - CAIRO_SUBSETS_FOREACH_UNSCALED, - CAIRO_SUBSETS_FOREACH_SCALED, - CAIRO_SUBSETS_FOREACH_USER -} cairo_subsets_foreach_type_t; - -typedef struct _cairo_sub_font { - cairo_hash_entry_t base; - - cairo_bool_t is_scaled; - cairo_bool_t is_composite; - cairo_bool_t is_user; - cairo_bool_t use_latin_subset; - cairo_scaled_font_subsets_t *parent; - cairo_scaled_font_t *scaled_font; - unsigned int font_id; - - int current_subset; - int num_glyphs_in_current_subset; - int num_glyphs_in_latin_subset; - int max_glyphs_per_subset; - char latin_char_map[256]; - - cairo_hash_table_t *sub_font_glyphs; - struct _cairo_sub_font *next; -} cairo_sub_font_t; - -struct _cairo_scaled_font_subsets { - cairo_subsets_type_t type; - cairo_bool_t use_latin_subset; - - int max_glyphs_per_unscaled_subset_used; - cairo_hash_table_t *unscaled_sub_fonts; - cairo_sub_font_t *unscaled_sub_fonts_list; - cairo_sub_font_t *unscaled_sub_fonts_list_end; - - int max_glyphs_per_scaled_subset_used; - cairo_hash_table_t *scaled_sub_fonts; - cairo_sub_font_t *scaled_sub_fonts_list; - cairo_sub_font_t *scaled_sub_fonts_list_end; - - int num_sub_fonts; -}; - -typedef struct _cairo_sub_font_glyph { - cairo_hash_entry_t base; - - unsigned int subset_id; - unsigned int subset_glyph_index; - double x_advance; - double y_advance; - - cairo_bool_t is_latin; - int latin_character; - cairo_bool_t is_mapped; - uint32_t unicode; - char *utf8; - int utf8_len; -} cairo_sub_font_glyph_t; - -typedef struct _cairo_sub_font_collection { - unsigned long *glyphs; /* scaled_font_glyph_index */ - char **utf8; - unsigned int glyphs_size; - int *to_latin_char; - unsigned long *latin_to_subset_glyph_index; - unsigned int max_glyph; - unsigned int num_glyphs; - - unsigned int subset_id; - - cairo_status_t status; - cairo_scaled_font_subset_callback_func_t font_subset_callback; - void *font_subset_callback_closure; -} cairo_sub_font_collection_t; - -typedef struct _cairo_string_entry { - cairo_hash_entry_t base; - char *string; -} cairo_string_entry_t; - -static cairo_status_t -_cairo_sub_font_map_glyph (cairo_sub_font_t *sub_font, - unsigned long scaled_font_glyph_index, - const char * utf8, - int utf8_len, - cairo_scaled_font_subsets_glyph_t *subset_glyph); - -static void -_cairo_sub_font_glyph_init_key (cairo_sub_font_glyph_t *sub_font_glyph, - unsigned long scaled_font_glyph_index) -{ - sub_font_glyph->base.hash = scaled_font_glyph_index; -} - -static cairo_sub_font_glyph_t * -_cairo_sub_font_glyph_create (unsigned long scaled_font_glyph_index, - unsigned int subset_id, - unsigned int subset_glyph_index, - double x_advance, - double y_advance, - int latin_character, - uint32_t unicode, - char *utf8, - int utf8_len) -{ - cairo_sub_font_glyph_t *sub_font_glyph; - - sub_font_glyph = malloc (sizeof (cairo_sub_font_glyph_t)); - if (unlikely (sub_font_glyph == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - _cairo_sub_font_glyph_init_key (sub_font_glyph, scaled_font_glyph_index); - sub_font_glyph->subset_id = subset_id; - sub_font_glyph->subset_glyph_index = subset_glyph_index; - sub_font_glyph->x_advance = x_advance; - sub_font_glyph->y_advance = y_advance; - sub_font_glyph->is_latin = (latin_character >= 0); - sub_font_glyph->latin_character = latin_character; - sub_font_glyph->is_mapped = FALSE; - sub_font_glyph->unicode = unicode; - sub_font_glyph->utf8 = utf8; - sub_font_glyph->utf8_len = utf8_len; - - return sub_font_glyph; -} - -static void -_cairo_sub_font_glyph_destroy (cairo_sub_font_glyph_t *sub_font_glyph) -{ - free (sub_font_glyph->utf8); - - free (sub_font_glyph); -} - -static void -_cairo_sub_font_glyph_pluck (void *entry, void *closure) -{ - cairo_sub_font_glyph_t *sub_font_glyph = entry; - cairo_hash_table_t *sub_font_glyphs = closure; - - _cairo_hash_table_remove (sub_font_glyphs, &sub_font_glyph->base); - _cairo_sub_font_glyph_destroy (sub_font_glyph); -} - -static void -_cairo_sub_font_glyph_collect (void *entry, void *closure) -{ - cairo_sub_font_glyph_t *sub_font_glyph = entry; - cairo_sub_font_collection_t *collection = closure; - unsigned long scaled_font_glyph_index; - unsigned int subset_glyph_index; - - if (sub_font_glyph->subset_id != collection->subset_id) - return; - - scaled_font_glyph_index = sub_font_glyph->base.hash; - subset_glyph_index = sub_font_glyph->subset_glyph_index; - - /* Ensure we don't exceed the allocated bounds. */ - assert (subset_glyph_index < collection->glyphs_size); - - collection->glyphs[subset_glyph_index] = scaled_font_glyph_index; - collection->utf8[subset_glyph_index] = sub_font_glyph->utf8; - collection->to_latin_char[subset_glyph_index] = sub_font_glyph->latin_character; - if (sub_font_glyph->is_latin) - collection->latin_to_subset_glyph_index[sub_font_glyph->latin_character] = subset_glyph_index; - - if (subset_glyph_index > collection->max_glyph) - collection->max_glyph = subset_glyph_index; - - collection->num_glyphs++; -} - -static cairo_bool_t -_cairo_sub_fonts_equal (const void *key_a, const void *key_b) -{ - const cairo_sub_font_t *sub_font_a = key_a; - const cairo_sub_font_t *sub_font_b = key_b; - cairo_scaled_font_t *a = sub_font_a->scaled_font; - cairo_scaled_font_t *b = sub_font_b->scaled_font; - - if (sub_font_a->is_scaled) - return a == b; - else - return a->font_face == b->font_face || a->original_font_face == b->original_font_face; -} - -static void -_cairo_sub_font_init_key (cairo_sub_font_t *sub_font, - cairo_scaled_font_t *scaled_font) -{ - if (sub_font->is_scaled) - { - sub_font->base.hash = (unsigned long) scaled_font; - sub_font->scaled_font = scaled_font; - } - else - { - sub_font->base.hash = (unsigned long) scaled_font->font_face; - sub_font->scaled_font = scaled_font; - } -} - -static cairo_status_t -_cairo_sub_font_create (cairo_scaled_font_subsets_t *parent, - cairo_scaled_font_t *scaled_font, - unsigned int font_id, - int max_glyphs_per_subset, - cairo_bool_t is_scaled, - cairo_bool_t is_composite, - cairo_sub_font_t **sub_font_out) -{ - cairo_sub_font_t *sub_font; - int i; - - sub_font = malloc (sizeof (cairo_sub_font_t)); - if (unlikely (sub_font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - sub_font->is_scaled = is_scaled; - sub_font->is_composite = is_composite; - sub_font->is_user = _cairo_font_face_is_user (scaled_font->font_face); - _cairo_sub_font_init_key (sub_font, scaled_font); - - sub_font->parent = parent; - sub_font->scaled_font = scaled_font; - sub_font->font_id = font_id; - - sub_font->use_latin_subset = parent->use_latin_subset; - - /* latin subsets of Type 3 and CID CFF fonts are not supported */ - if (sub_font->is_user || sub_font->is_scaled || - _cairo_cff_scaled_font_is_cid_cff (scaled_font) ) - { - sub_font->use_latin_subset = FALSE; - } - - if (sub_font->use_latin_subset) - sub_font->current_subset = 1; /* reserve subset 0 for latin glyphs */ - else - sub_font->current_subset = 0; - - sub_font->num_glyphs_in_current_subset = 0; - sub_font->num_glyphs_in_latin_subset = 0; - sub_font->max_glyphs_per_subset = max_glyphs_per_subset; - for (i = 0; i < 256; i++) - sub_font->latin_char_map[i] = FALSE; - - sub_font->sub_font_glyphs = _cairo_hash_table_create (NULL); - if (unlikely (sub_font->sub_font_glyphs == NULL)) { - free (sub_font); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - sub_font->next = NULL; - *sub_font_out = sub_font; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_sub_font_destroy (cairo_sub_font_t *sub_font) -{ - _cairo_hash_table_foreach (sub_font->sub_font_glyphs, - _cairo_sub_font_glyph_pluck, - sub_font->sub_font_glyphs); - _cairo_hash_table_destroy (sub_font->sub_font_glyphs); - cairo_scaled_font_destroy (sub_font->scaled_font); - free (sub_font); -} - -static void -_cairo_sub_font_pluck (void *entry, void *closure) -{ - cairo_sub_font_t *sub_font = entry; - cairo_hash_table_t *sub_fonts = closure; - - _cairo_hash_table_remove (sub_fonts, &sub_font->base); - _cairo_sub_font_destroy (sub_font); -} - -/* Characters 0x80 to 0x9f in the winansi encoding. - * All other characters in the range 0x00 to 0xff map 1:1 to unicode */ -static unsigned int _winansi_0x80_to_0x9f[] = { - 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, - 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000, - 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, - 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178 -}; - -int -_cairo_unicode_to_winansi (unsigned long uni) -{ - int i; - - /* exclude the extra "hyphen" at 0xad to avoid duplicate glyphnames */ - if ((uni >= 0x20 && uni <= 0x7e) || - (uni >= 0xa1 && uni <= 0xff && uni != 0xad) || - uni == 0) - return uni; - - for (i = 0; i < 32; i++) - if (_winansi_0x80_to_0x9f[i] == uni) - return i + 0x80; - - return -1; -} - -static cairo_status_t -_cairo_sub_font_glyph_lookup_unicode (cairo_scaled_font_t *scaled_font, - unsigned long scaled_font_glyph_index, - uint32_t *unicode_out, - char **utf8_out, - int *utf8_len_out) -{ - uint32_t unicode; - char buf[8]; - int len; - cairo_status_t status; - - /* Do a reverse lookup on the glyph index. unicode is -1 if the - * index could not be mapped to a unicode character. */ - unicode = -1; - status = _cairo_truetype_index_to_ucs4 (scaled_font, - scaled_font_glyph_index, - &unicode); - if (_cairo_status_is_error (status)) - return status; - - if (unicode == (uint32_t)-1 && scaled_font->backend->index_to_ucs4) { - status = scaled_font->backend->index_to_ucs4 (scaled_font, - scaled_font_glyph_index, - &unicode); - if (unlikely (status)) - return status; - } - - *unicode_out = unicode; - *utf8_out = NULL; - *utf8_len_out = 0; - if (unicode != (uint32_t) -1) { - len = _cairo_ucs4_to_utf8 (unicode, buf); - if (len > 0) { - *utf8_out = malloc (len + 1); - if (unlikely (*utf8_out == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (*utf8_out, buf, len); - (*utf8_out)[len] = 0; - *utf8_len_out = len; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_sub_font_glyph_map_to_unicode (cairo_sub_font_glyph_t *sub_font_glyph, - const char *utf8, - int utf8_len, - cairo_bool_t *is_mapped) -{ - *is_mapped = FALSE; - - if (utf8_len < 0) - return CAIRO_STATUS_SUCCESS; - - if (utf8 != NULL && utf8_len != 0 && utf8[utf8_len - 1] == '\0') - utf8_len--; - - if (utf8 != NULL && utf8_len != 0) { - if (sub_font_glyph->utf8 != NULL) { - if (utf8_len == sub_font_glyph->utf8_len && - memcmp (utf8, sub_font_glyph->utf8, utf8_len) == 0) - { - /* Requested utf8 mapping matches the existing mapping */ - *is_mapped = TRUE; - } - } else { - /* No existing mapping. Use the requested mapping */ - sub_font_glyph->utf8 = malloc (utf8_len + 1); - if (unlikely (sub_font_glyph->utf8 == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (sub_font_glyph->utf8, utf8, utf8_len); - sub_font_glyph->utf8[utf8_len] = 0; - sub_font_glyph->utf8_len = utf8_len; - *is_mapped = TRUE; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_sub_font_lookup_glyph (cairo_sub_font_t *sub_font, - unsigned long scaled_font_glyph_index, - const char *utf8, - int utf8_len, - cairo_scaled_font_subsets_glyph_t *subset_glyph) -{ - cairo_sub_font_glyph_t key, *sub_font_glyph; - cairo_int_status_t status; - - _cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index); - sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs, - &key.base); - if (sub_font_glyph != NULL) { - subset_glyph->font_id = sub_font->font_id; - subset_glyph->subset_id = sub_font_glyph->subset_id; - if (sub_font_glyph->is_latin) - subset_glyph->subset_glyph_index = sub_font_glyph->latin_character; - else - subset_glyph->subset_glyph_index = sub_font_glyph->subset_glyph_index; - - subset_glyph->is_scaled = sub_font->is_scaled; - subset_glyph->is_composite = sub_font->is_composite; - subset_glyph->is_latin = sub_font_glyph->is_latin; - subset_glyph->x_advance = sub_font_glyph->x_advance; - subset_glyph->y_advance = sub_font_glyph->y_advance; - status = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph, - utf8, utf8_len, - &subset_glyph->utf8_is_mapped); - subset_glyph->unicode = sub_font_glyph->unicode; - - return status; - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_status_t -_cairo_sub_font_add_glyph (cairo_sub_font_t *sub_font, - unsigned long scaled_font_glyph_index, - cairo_bool_t is_latin, - int latin_character, - uint32_t unicode, - char *utf8, - int utf8_len, - cairo_sub_font_glyph_t **sub_font_glyph_out) -{ - cairo_scaled_glyph_t *scaled_glyph; - cairo_sub_font_glyph_t *sub_font_glyph; - int *num_glyphs_in_subset_ptr; - double x_advance; - double y_advance; - cairo_int_status_t status; - - _cairo_scaled_font_freeze_cache (sub_font->scaled_font); - status = _cairo_scaled_glyph_lookup (sub_font->scaled_font, - scaled_font_glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - assert (status != CAIRO_INT_STATUS_UNSUPPORTED); - if (unlikely (status)) { - _cairo_scaled_font_thaw_cache (sub_font->scaled_font); - return status; - } - - x_advance = scaled_glyph->metrics.x_advance; - y_advance = scaled_glyph->metrics.y_advance; - _cairo_scaled_font_thaw_cache (sub_font->scaled_font); - - if (!is_latin && sub_font->num_glyphs_in_current_subset == sub_font->max_glyphs_per_subset) - { - sub_font->current_subset++; - sub_font->num_glyphs_in_current_subset = 0; - } - - if (is_latin) - num_glyphs_in_subset_ptr = &sub_font->num_glyphs_in_latin_subset; - else - num_glyphs_in_subset_ptr = &sub_font->num_glyphs_in_current_subset; - - /* Reserve first glyph in subset for the .notdef glyph except for - * Type 3 fonts */ - if (*num_glyphs_in_subset_ptr == 0 && - scaled_font_glyph_index != 0 && - ! _cairo_font_face_is_user (sub_font->scaled_font->font_face)) - { - status = _cairo_sub_font_add_glyph (sub_font, - 0, - is_latin, - 0, - 0, - NULL, - -1, - &sub_font_glyph); - if (unlikely (status)) - return status; - } - - sub_font_glyph = _cairo_sub_font_glyph_create (scaled_font_glyph_index, - is_latin ? 0 : sub_font->current_subset, - *num_glyphs_in_subset_ptr, - x_advance, - y_advance, - is_latin ? latin_character : -1, - unicode, - utf8, - utf8_len); - - if (unlikely (sub_font_glyph == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_hash_table_insert (sub_font->sub_font_glyphs, &sub_font_glyph->base); - if (unlikely (status)) { - _cairo_sub_font_glyph_destroy (sub_font_glyph); - return status; - } - - (*num_glyphs_in_subset_ptr)++; - if (sub_font->is_scaled) { - if (*num_glyphs_in_subset_ptr > sub_font->parent->max_glyphs_per_scaled_subset_used) - sub_font->parent->max_glyphs_per_scaled_subset_used = *num_glyphs_in_subset_ptr; - } else { - if (*num_glyphs_in_subset_ptr > sub_font->parent->max_glyphs_per_unscaled_subset_used) - sub_font->parent->max_glyphs_per_unscaled_subset_used = *num_glyphs_in_subset_ptr; - } - - *sub_font_glyph_out = sub_font_glyph; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_sub_font_map_glyph (cairo_sub_font_t *sub_font, - unsigned long scaled_font_glyph_index, - const char *text_utf8, - int text_utf8_len, - cairo_scaled_font_subsets_glyph_t *subset_glyph) -{ - cairo_sub_font_glyph_t key, *sub_font_glyph; - cairo_status_t status; - - _cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index); - sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs, - &key.base); - if (sub_font_glyph == NULL) { - uint32_t font_unicode; - char *font_utf8; - int font_utf8_len; - cairo_bool_t is_latin; - int latin_character; - - status = _cairo_sub_font_glyph_lookup_unicode (sub_font->scaled_font, - scaled_font_glyph_index, - &font_unicode, - &font_utf8, - &font_utf8_len); - if (unlikely(status)) - return status; - - /* If the supplied utf8 is a valid single character, use it - * instead of the font lookup */ - if (text_utf8 != NULL && text_utf8_len > 0) { - uint32_t *ucs4; - int ucs4_len; - - status = _cairo_utf8_to_ucs4 (text_utf8, text_utf8_len, - &ucs4, &ucs4_len); - if (status == CAIRO_STATUS_SUCCESS) { - if (ucs4_len == 1) { - font_unicode = ucs4[0]; - free (font_utf8); - font_utf8 = malloc (text_utf8_len + 1); - if (font_utf8 == NULL) { - free (ucs4); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - memcpy (font_utf8, text_utf8, text_utf8_len); - font_utf8[text_utf8_len] = 0; - font_utf8_len = text_utf8_len; - } - free (ucs4); - } - } - - /* If glyph is in the winansi encoding and font is not a user - * font, put glyph in the latin subset. If glyph is .notdef - * the latin subset is preferred but only if the latin subset - * already contains at least one glyph. We don't want to - * create a separate subset just for the .notdef glyph. - */ - is_latin = FALSE; - latin_character = -1; - if (sub_font->use_latin_subset && - (! _cairo_font_face_is_user (sub_font->scaled_font->font_face))) - { - latin_character = _cairo_unicode_to_winansi (font_unicode); - if (latin_character > 0 || - (latin_character == 0 && sub_font->num_glyphs_in_latin_subset > 0)) - { - if (!sub_font->latin_char_map[latin_character]) { - sub_font->latin_char_map[latin_character] = TRUE; - is_latin = TRUE; - } - } - } - - status = _cairo_sub_font_add_glyph (sub_font, - scaled_font_glyph_index, - is_latin, - latin_character, - font_unicode, - font_utf8, - font_utf8_len, - &sub_font_glyph); - if (unlikely(status)) - return status; - } - - subset_glyph->font_id = sub_font->font_id; - subset_glyph->subset_id = sub_font_glyph->subset_id; - if (sub_font_glyph->is_latin) - subset_glyph->subset_glyph_index = sub_font_glyph->latin_character; - else - subset_glyph->subset_glyph_index = sub_font_glyph->subset_glyph_index; - - subset_glyph->is_scaled = sub_font->is_scaled; - subset_glyph->is_composite = sub_font->is_composite; - subset_glyph->is_latin = sub_font_glyph->is_latin; - subset_glyph->x_advance = sub_font_glyph->x_advance; - subset_glyph->y_advance = sub_font_glyph->y_advance; - status = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph, - text_utf8, text_utf8_len, - &subset_glyph->utf8_is_mapped); - subset_glyph->unicode = sub_font_glyph->unicode; - - return status; -} - -static void -_cairo_sub_font_collect (void *entry, void *closure) -{ - cairo_sub_font_t *sub_font = entry; - cairo_sub_font_collection_t *collection = closure; - cairo_scaled_font_subset_t subset; - int i; - unsigned int j; - - if (collection->status) - return; - - collection->status = sub_font->scaled_font->status; - if (collection->status) - return; - - for (i = 0; i <= sub_font->current_subset; i++) { - collection->subset_id = i; - collection->num_glyphs = 0; - collection->max_glyph = 0; - memset (collection->latin_to_subset_glyph_index, 0, 256*sizeof(unsigned long)); - - _cairo_hash_table_foreach (sub_font->sub_font_glyphs, - _cairo_sub_font_glyph_collect, collection); - if (collection->status) - break; - if (collection->num_glyphs == 0) - continue; - - /* Ensure the resulting array has no uninitialized holes */ - assert (collection->num_glyphs == collection->max_glyph + 1); - - subset.scaled_font = sub_font->scaled_font; - subset.is_composite = sub_font->is_composite; - subset.is_scaled = sub_font->is_scaled; - subset.font_id = sub_font->font_id; - subset.subset_id = i; - subset.glyphs = collection->glyphs; - subset.utf8 = collection->utf8; - subset.num_glyphs = collection->num_glyphs; - subset.glyph_names = NULL; - - subset.is_latin = FALSE; - if (sub_font->use_latin_subset && i == 0) { - subset.is_latin = TRUE; - subset.to_latin_char = collection->to_latin_char; - subset.latin_to_subset_glyph_index = collection->latin_to_subset_glyph_index; - } else { - subset.to_latin_char = NULL; - subset.latin_to_subset_glyph_index = NULL; - } - - collection->status = (collection->font_subset_callback) (&subset, - collection->font_subset_callback_closure); - - if (subset.glyph_names != NULL) { - for (j = 0; j < collection->num_glyphs; j++) - free (subset.glyph_names[j]); - free (subset.glyph_names); - } - - if (collection->status) - break; - } -} - -static cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_internal (cairo_subsets_type_t type) -{ - cairo_scaled_font_subsets_t *subsets; - - subsets = malloc (sizeof (cairo_scaled_font_subsets_t)); - if (unlikely (subsets == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; - } - - subsets->type = type; - subsets->use_latin_subset = FALSE; - subsets->max_glyphs_per_unscaled_subset_used = 0; - subsets->max_glyphs_per_scaled_subset_used = 0; - subsets->num_sub_fonts = 0; - - subsets->unscaled_sub_fonts = _cairo_hash_table_create (_cairo_sub_fonts_equal); - if (! subsets->unscaled_sub_fonts) { - free (subsets); - return NULL; - } - subsets->unscaled_sub_fonts_list = NULL; - subsets->unscaled_sub_fonts_list_end = NULL; - - subsets->scaled_sub_fonts = _cairo_hash_table_create (_cairo_sub_fonts_equal); - if (! subsets->scaled_sub_fonts) { - _cairo_hash_table_destroy (subsets->unscaled_sub_fonts); - free (subsets); - return NULL; - } - subsets->scaled_sub_fonts_list = NULL; - subsets->scaled_sub_fonts_list_end = NULL; - - return subsets; -} - -cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_scaled (void) -{ - return _cairo_scaled_font_subsets_create_internal (CAIRO_SUBSETS_SCALED); -} - -cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_simple (void) -{ - return _cairo_scaled_font_subsets_create_internal (CAIRO_SUBSETS_SIMPLE); -} - -cairo_scaled_font_subsets_t * -_cairo_scaled_font_subsets_create_composite (void) -{ - return _cairo_scaled_font_subsets_create_internal (CAIRO_SUBSETS_COMPOSITE); -} - -void -_cairo_scaled_font_subsets_destroy (cairo_scaled_font_subsets_t *subsets) -{ - _cairo_hash_table_foreach (subsets->scaled_sub_fonts, _cairo_sub_font_pluck, subsets->scaled_sub_fonts); - _cairo_hash_table_destroy (subsets->scaled_sub_fonts); - - _cairo_hash_table_foreach (subsets->unscaled_sub_fonts, _cairo_sub_font_pluck, subsets->unscaled_sub_fonts); - _cairo_hash_table_destroy (subsets->unscaled_sub_fonts); - - free (subsets); -} - -void -_cairo_scaled_font_subsets_enable_latin_subset (cairo_scaled_font_subsets_t *font_subsets, - cairo_bool_t use_latin) -{ - font_subsets->use_latin_subset = use_latin; -} - -cairo_status_t -_cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *subsets, - cairo_scaled_font_t *scaled_font, - unsigned long scaled_font_glyph_index, - const char * utf8, - int utf8_len, - cairo_scaled_font_subsets_glyph_t *subset_glyph) -{ - cairo_sub_font_t key, *sub_font; - cairo_scaled_glyph_t *scaled_glyph; - cairo_font_face_t *font_face; - cairo_matrix_t identity; - cairo_font_options_t font_options; - cairo_scaled_font_t *unscaled_font; - cairo_int_status_t status; - int max_glyphs; - cairo_bool_t type1_font; - - /* Lookup glyph in unscaled subsets */ - if (subsets->type != CAIRO_SUBSETS_SCALED) { - key.is_scaled = FALSE; - _cairo_sub_font_init_key (&key, scaled_font); - sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts, - &key.base); - if (sub_font != NULL) { - status = _cairo_sub_font_lookup_glyph (sub_font, - scaled_font_glyph_index, - utf8, utf8_len, - subset_glyph); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - } - - /* Lookup glyph in scaled subsets */ - key.is_scaled = TRUE; - _cairo_sub_font_init_key (&key, scaled_font); - sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts, - &key.base); - if (sub_font != NULL) { - status = _cairo_sub_font_lookup_glyph (sub_font, - scaled_font_glyph_index, - utf8, utf8_len, - subset_glyph); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - /* Glyph not found. Determine whether the glyph is outline or - * bitmap and add to the appropriate subset. - * - * glyph_index 0 (the .notdef glyph) is a special case. Some fonts - * will return CAIRO_INT_STATUS_UNSUPPORTED when doing a - * _scaled_glyph_lookup(_GLYPH_INFO_PATH). Type1-fallback creates - * empty glyphs in this case so we can put the glyph in a unscaled - * subset. */ - if (scaled_font_glyph_index == 0 || - _cairo_font_face_is_user (scaled_font->font_face)) { - status = CAIRO_STATUS_SUCCESS; - } else { - _cairo_scaled_font_freeze_cache (scaled_font); - status = _cairo_scaled_glyph_lookup (scaled_font, - scaled_font_glyph_index, - CAIRO_SCALED_GLYPH_INFO_PATH, - &scaled_glyph); - _cairo_scaled_font_thaw_cache (scaled_font); - } - if (_cairo_int_status_is_error (status)) - return status; - - if (status == CAIRO_INT_STATUS_SUCCESS && - subsets->type != CAIRO_SUBSETS_SCALED && - ! _cairo_font_face_is_user (scaled_font->font_face)) - { - /* Path available. Add to unscaled subset. */ - key.is_scaled = FALSE; - _cairo_sub_font_init_key (&key, scaled_font); - sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts, - &key.base); - if (sub_font == NULL) { - font_face = cairo_scaled_font_get_font_face (scaled_font); - cairo_matrix_init_identity (&identity); - _cairo_font_options_init_default (&font_options); - cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF); - unscaled_font = cairo_scaled_font_create (font_face, - &identity, - &identity, - &font_options); - if (unlikely (unscaled_font->status)) - return unscaled_font->status; - - subset_glyph->is_scaled = FALSE; - type1_font = _cairo_type1_scaled_font_is_type1 (unscaled_font); - if (subsets->type == CAIRO_SUBSETS_COMPOSITE && !type1_font) { - max_glyphs = MAX_GLYPHS_PER_COMPOSITE_FONT; - subset_glyph->is_composite = TRUE; - } else { - max_glyphs = MAX_GLYPHS_PER_SIMPLE_FONT; - subset_glyph->is_composite = FALSE; - } - - status = _cairo_sub_font_create (subsets, - unscaled_font, - subsets->num_sub_fonts, - max_glyphs, - subset_glyph->is_scaled, - subset_glyph->is_composite, - &sub_font); - - if (unlikely (status)) { - cairo_scaled_font_destroy (unscaled_font); - return status; - } - - status = _cairo_hash_table_insert (subsets->unscaled_sub_fonts, - &sub_font->base); - - if (unlikely (status)) { - _cairo_sub_font_destroy (sub_font); - return status; - } - if (!subsets->unscaled_sub_fonts_list) - subsets->unscaled_sub_fonts_list = sub_font; - else - subsets->unscaled_sub_fonts_list_end->next = sub_font; - subsets->unscaled_sub_fonts_list_end = sub_font; - subsets->num_sub_fonts++; - } - } else { - /* No path available. Add to scaled subset. */ - key.is_scaled = TRUE; - _cairo_sub_font_init_key (&key, scaled_font); - sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts, - &key.base); - if (sub_font == NULL) { - subset_glyph->is_scaled = TRUE; - subset_glyph->is_composite = FALSE; - if (subsets->type == CAIRO_SUBSETS_SCALED) - max_glyphs = INT_MAX; - else - max_glyphs = MAX_GLYPHS_PER_SIMPLE_FONT; - - status = _cairo_sub_font_create (subsets, - cairo_scaled_font_reference (scaled_font), - subsets->num_sub_fonts, - max_glyphs, - subset_glyph->is_scaled, - subset_glyph->is_composite, - &sub_font); - if (unlikely (status)) { - cairo_scaled_font_destroy (scaled_font); - return status; - } - - status = _cairo_hash_table_insert (subsets->scaled_sub_fonts, - &sub_font->base); - if (unlikely (status)) { - _cairo_sub_font_destroy (sub_font); - return status; - } - if (!subsets->scaled_sub_fonts_list) - subsets->scaled_sub_fonts_list = sub_font; - else - subsets->scaled_sub_fonts_list_end->next = sub_font; - subsets->scaled_sub_fonts_list_end = sub_font; - subsets->num_sub_fonts++; - } - } - - return _cairo_sub_font_map_glyph (sub_font, - scaled_font_glyph_index, - utf8, utf8_len, - subset_glyph); -} - -static cairo_status_t -_cairo_scaled_font_subsets_foreach_internal (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure, - cairo_subsets_foreach_type_t type) -{ - cairo_sub_font_collection_t collection; - cairo_sub_font_t *sub_font; - cairo_bool_t is_scaled, is_user; - - is_scaled = FALSE; - is_user = FALSE; - - if (type == CAIRO_SUBSETS_FOREACH_USER) - is_user = TRUE; - - if (type == CAIRO_SUBSETS_FOREACH_SCALED || - type == CAIRO_SUBSETS_FOREACH_USER) - { - is_scaled = TRUE; - } - - if (is_scaled) - collection.glyphs_size = font_subsets->max_glyphs_per_scaled_subset_used; - else - collection.glyphs_size = font_subsets->max_glyphs_per_unscaled_subset_used; - - if (! collection.glyphs_size) - return CAIRO_STATUS_SUCCESS; - - collection.glyphs = _cairo_malloc_ab (collection.glyphs_size, sizeof(unsigned long)); - collection.utf8 = _cairo_malloc_ab (collection.glyphs_size, sizeof(char *)); - collection.to_latin_char = _cairo_malloc_ab (collection.glyphs_size, sizeof(int)); - collection.latin_to_subset_glyph_index = _cairo_malloc_ab (256, sizeof(unsigned long)); - if (unlikely (collection.glyphs == NULL || - collection.utf8 == NULL || - collection.to_latin_char == NULL || - collection.latin_to_subset_glyph_index == NULL)) { - free (collection.glyphs); - free (collection.utf8); - free (collection.to_latin_char); - free (collection.latin_to_subset_glyph_index); - - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - collection.font_subset_callback = font_subset_callback; - collection.font_subset_callback_closure = closure; - collection.status = CAIRO_STATUS_SUCCESS; - - if (is_scaled) - sub_font = font_subsets->scaled_sub_fonts_list; - else - sub_font = font_subsets->unscaled_sub_fonts_list; - - while (sub_font) { - if (sub_font->is_user == is_user) - _cairo_sub_font_collect (sub_font, &collection); - - sub_font = sub_font->next; - } - free (collection.utf8); - free (collection.glyphs); - free (collection.to_latin_char); - free (collection.latin_to_subset_glyph_index); - - return collection.status; -} - -cairo_status_t -_cairo_scaled_font_subsets_foreach_scaled (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure) -{ - return _cairo_scaled_font_subsets_foreach_internal (font_subsets, - font_subset_callback, - closure, - CAIRO_SUBSETS_FOREACH_SCALED); -} - -cairo_status_t -_cairo_scaled_font_subsets_foreach_unscaled (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure) -{ - return _cairo_scaled_font_subsets_foreach_internal (font_subsets, - font_subset_callback, - closure, - CAIRO_SUBSETS_FOREACH_UNSCALED); -} - -cairo_status_t -_cairo_scaled_font_subsets_foreach_user (cairo_scaled_font_subsets_t *font_subsets, - cairo_scaled_font_subset_callback_func_t font_subset_callback, - void *closure) -{ - return _cairo_scaled_font_subsets_foreach_internal (font_subsets, - font_subset_callback, - closure, - CAIRO_SUBSETS_FOREACH_USER); -} - -static cairo_bool_t -_cairo_string_equal (const void *key_a, const void *key_b) -{ - const cairo_string_entry_t *a = key_a; - const cairo_string_entry_t *b = key_b; - - if (strcmp (a->string, b->string) == 0) - return TRUE; - else - return FALSE; -} - -static void -_cairo_string_init_key (cairo_string_entry_t *key, char *s) -{ - unsigned long sum = 0; - unsigned int i; - - for (i = 0; i < strlen(s); i++) - sum += s[i]; - key->base.hash = sum; - key->string = s; -} - -static cairo_status_t -create_string_entry (char *s, cairo_string_entry_t **entry) -{ - *entry = malloc (sizeof (cairo_string_entry_t)); - if (unlikely (*entry == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_string_init_key (*entry, s); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_pluck_entry (void *entry, void *closure) -{ - _cairo_hash_table_remove (closure, entry); - free (entry); -} - -cairo_int_status_t -_cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset) -{ - unsigned int i; - cairo_hash_table_t *names; - cairo_string_entry_t key, *entry; - char buf[30]; - char *utf8; - uint16_t *utf16; - int utf16_len; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - names = _cairo_hash_table_create (_cairo_string_equal); - if (unlikely (names == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - subset->glyph_names = calloc (subset->num_glyphs, sizeof (char *)); - if (unlikely (subset->glyph_names == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_HASH; - } - - i = 0; - if (! subset->is_scaled) { - subset->glyph_names[0] = strdup (".notdef"); - if (unlikely (subset->glyph_names[0] == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_HASH; - } - - status = create_string_entry (subset->glyph_names[0], &entry); - if (unlikely (status)) - goto CLEANUP_HASH; - - status = _cairo_hash_table_insert (names, &entry->base); - if (unlikely (status)) { - free (entry); - goto CLEANUP_HASH; - } - i++; - } - - for (; i < subset->num_glyphs; i++) { - utf8 = subset->utf8[i]; - utf16 = NULL; - utf16_len = 0; - if (utf8 && *utf8) { - status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len); - if (unlikely (status)) - goto CLEANUP_HASH; - } - - if (utf16_len == 1) { - int ch = _cairo_unicode_to_winansi (utf16[0]); - if (ch > 0 && _cairo_winansi_to_glyphname (ch)) - strncpy (buf, _cairo_winansi_to_glyphname (ch), sizeof (buf)); - else - snprintf (buf, sizeof (buf), "uni%04X", (int) utf16[0]); - - _cairo_string_init_key (&key, buf); - entry = _cairo_hash_table_lookup (names, &key.base); - if (entry != NULL) - snprintf (buf, sizeof (buf), "g%d", i); - } else { - snprintf (buf, sizeof (buf), "g%d", i); - } - free (utf16); - - subset->glyph_names[i] = strdup (buf); - if (unlikely (subset->glyph_names[i] == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_HASH; - } - - status = create_string_entry (subset->glyph_names[i], &entry); - if (unlikely (status)) - goto CLEANUP_HASH; - - status = _cairo_hash_table_insert (names, &entry->base); - if (unlikely (status)) { - free (entry); - goto CLEANUP_HASH; - } - } - -CLEANUP_HASH: - _cairo_hash_table_foreach (names, _pluck_entry, names); - _cairo_hash_table_destroy (names); - - if (likely (status == CAIRO_STATUS_SUCCESS)) - return CAIRO_STATUS_SUCCESS; - - if (subset->glyph_names != NULL) { - for (i = 0; i < subset->num_glyphs; i++) { - free (subset->glyph_names[i]); - } - - free (subset->glyph_names); - subset->glyph_names = NULL; - } - - return status; -} - -cairo_int_status_t -_cairo_escape_ps_name (char **ps_name) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - /* Ensure PS name is a valid PDF/PS name object. In PDF names are - * treated as UTF8 and non ASCII bytes, ' ', and '#' are encoded - * as '#' followed by 2 hex digits that encode the byte. By also - * encoding the characters in the reserved string we ensure the - * name is also PS compatible. */ - if (*ps_name) { - static const char *reserved = "()<>[]{}/%#\\"; - char buf[128]; /* max name length is 127 bytes */ - char *src = *ps_name; - char *dst = buf; - - while (*src && dst < buf + 127) { - unsigned char c = *src; - if (c < 0x21 || c > 0x7e || strchr (reserved, c)) { - if (dst + 4 > buf + 127) - break; - - snprintf (dst, 4, "#%02X", c); - src++; - dst += 3; - } else { - *dst++ = *src++; - } - } - *dst = 0; - free (*ps_name); - *ps_name = strdup (buf); - if (*ps_name == NULL) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - return status; -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font.c deleted file mode 100644 index ac80c97d1c5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-scaled-font.c +++ /dev/null @@ -1,3158 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* - * Copyright © 2005 Keith Packard - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith Packard - * Carl D. Worth - * Graydon Hoare - * Owen Taylor - * Behdad Esfahbod - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-pattern-private.h" -#include "cairo-scaled-font-private.h" -#include "cairo-surface-backend-private.h" - -#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE) -#define ISFINITE(x) isfinite (x) -#else -#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */ -#endif - -/** - * SECTION:cairo-scaled-font - * @Title: cairo_scaled_font_t - * @Short_Description: Font face at particular size and options - * @See_Also: #cairo_font_face_t, #cairo_matrix_t, #cairo_font_options_t - * - * #cairo_scaled_font_t represents a realization of a font face at a particular - * size and transformation and a certain set of font options. - **/ - -static uint32_t -_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font); - -/* Global Glyph Cache - * - * We maintain a global pool of glyphs split between all active fonts. This - * allows a heavily used individual font to cache more glyphs than we could - * manage if we used per-font glyph caches, but at the same time maintains - * fairness across all fonts and provides a cap on the maximum number of - * global glyphs. - * - * The glyphs are allocated in pages, which are capped in the global pool. - * Using pages means we can reduce the frequency at which we have to probe the - * global pool and ameliorates the memory allocation pressure. - */ - -/* XXX: This number is arbitrary---we've never done any measurement of this. */ -#define MAX_GLYPH_PAGES_CACHED 512 -static cairo_cache_t cairo_scaled_glyph_page_cache; - -#define CAIRO_SCALED_GLYPH_PAGE_SIZE 32 -struct _cairo_scaled_glyph_page { - cairo_cache_entry_t cache_entry; - - cairo_list_t link; - - unsigned int num_glyphs; - cairo_scaled_glyph_t glyphs[CAIRO_SCALED_GLYPH_PAGE_SIZE]; -}; - -/* - * Notes: - * - * To store rasterizations of glyphs, we use an image surface and the - * device offset to represent the glyph origin. - * - * A device_transform converts from device space (a conceptual space) to - * surface space. For simple cases of translation only, it's called a - * device_offset and is public API (cairo_surface_[gs]et_device_offset()). - * A possibly better name for those functions could have been - * cairo_surface_[gs]et_origin(). So, that's what they do: they set where - * the device-space origin (0,0) is in the surface. If the origin is inside - * the surface, device_offset values are positive. It may look like this: - * - * Device space: - * (-x,-y) <-- negative numbers - * +----------------+ - * | . | - * | . | - * |......(0,0) <---|-- device-space origin - * | | - * | | - * +----------------+ - * (width-x,height-y) - * - * Surface space: - * (0,0) <-- surface-space origin - * +---------------+ - * | . | - * | . | - * |......(x,y) <--|-- device_offset - * | | - * | | - * +---------------+ - * (width,height) - * - * In other words: device_offset is the coordinates of the device-space - * origin relative to the top-left of the surface. - * - * We use device offsets in a couple of places: - * - * - Public API: To let toolkits like Gtk+ give user a surface that - * only represents part of the final destination (say, the expose - * area), but has the same device space as the destination. In these - * cases device_offset is typically negative. Example: - * - * application window - * +---------------+ - * | . | - * | (x,y). | - * |......+---+ | - * | | | <--|-- expose area - * | +---+ | - * +---------------+ - * - * In this case, the user of cairo API can set the device_space on - * the expose area to (-x,-y) to move the device space origin to that - * of the application window, such that drawing in the expose area - * surface and painting it in the application window has the same - * effect as drawing in the application window directly. Gtk+ has - * been using this feature. - * - * - Glyph surfaces: In most font rendering systems, glyph surfaces - * have an origin at (0,0) and a bounding box that is typically - * represented as (x_bearing,y_bearing,width,height). Depending on - * which way y progresses in the system, y_bearing may typically be - * negative (for systems similar to cairo, with origin at top left), - * or be positive (in systems like PDF with origin at bottom left). - * No matter which is the case, it is important to note that - * (x_bearing,y_bearing) is the coordinates of top-left of the glyph - * relative to the glyph origin. That is, for example: - * - * Scaled-glyph space: - * - * (x_bearing,y_bearing) <-- negative numbers - * +----------------+ - * | . | - * | . | - * |......(0,0) <---|-- glyph origin - * | | - * | | - * +----------------+ - * (width+x_bearing,height+y_bearing) - * - * Note the similarity of the origin to the device space. That is - * exactly how we use the device_offset to represent scaled glyphs: - * to use the device-space origin as the glyph origin. - * - * Now compare the scaled-glyph space to device-space and surface-space - * and convince yourself that: - * - * (x_bearing,y_bearing) = (-x,-y) = - device_offset - * - * That's right. If you are not convinced yet, contrast the definition - * of the two: - * - * "(x_bearing,y_bearing) is the coordinates of top-left of the - * glyph relative to the glyph origin." - * - * "In other words: device_offset is the coordinates of the - * device-space origin relative to the top-left of the surface." - * - * and note that glyph origin = device-space origin. - */ - -static void -_cairo_scaled_font_fini_internal (cairo_scaled_font_t *scaled_font); - -static void -_cairo_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_t *scaled_glyph) -{ - while (! cairo_list_is_empty (&scaled_glyph->dev_privates)) { - cairo_scaled_glyph_private_t *private = - cairo_list_first_entry (&scaled_glyph->dev_privates, - cairo_scaled_glyph_private_t, - link); - private->destroy (private, scaled_glyph, scaled_font); - } - - _cairo_image_scaled_glyph_fini (scaled_font, scaled_glyph); - - if (scaled_glyph->surface != NULL) - cairo_surface_destroy (&scaled_glyph->surface->base); - - if (scaled_glyph->path != NULL) - _cairo_path_fixed_destroy (scaled_glyph->path); - - if (scaled_glyph->recording_surface != NULL) { - cairo_surface_finish (scaled_glyph->recording_surface); - cairo_surface_destroy (scaled_glyph->recording_surface); - } -} - -#define ZOMBIE 0 -static const cairo_scaled_font_t _cairo_scaled_font_nil = { - { ZOMBIE }, /* hash_entry */ - CAIRO_STATUS_NO_MEMORY, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL, /* original_font_face */ - NULL, /* font_face */ - { 1., 0., 0., 1., 0, 0}, /* font_matrix */ - { 1., 0., 0., 1., 0, 0}, /* ctm */ - { CAIRO_ANTIALIAS_DEFAULT, /* options */ - CAIRO_SUBPIXEL_ORDER_DEFAULT, - CAIRO_HINT_STYLE_DEFAULT, - CAIRO_HINT_METRICS_DEFAULT} , - FALSE, /* placeholder */ - FALSE, /* holdover */ - TRUE, /* finished */ - { 1., 0., 0., 1., 0, 0}, /* scale */ - { 1., 0., 0., 1., 0, 0}, /* scale_inverse */ - 1., /* max_scale */ - { 0., 0., 0., 0., 0. }, /* extents */ - { 0., 0., 0., 0., 0. }, /* fs_extents */ - CAIRO_MUTEX_NIL_INITIALIZER,/* mutex */ - NULL, /* glyphs */ - { NULL, NULL }, /* pages */ - FALSE, /* cache_frozen */ - FALSE, /* global_cache_frozen */ - { NULL, NULL }, /* privates */ - NULL /* backend */ -}; - -/** - * _cairo_scaled_font_set_error: - * @scaled_font: a scaled_font - * @status: a status value indicating an error - * - * Atomically sets scaled_font->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS. - * - * All assignments of an error status to scaled_font->status should happen - * through _cairo_scaled_font_set_error(). Note that due to the nature of - * the atomic operation, it is not safe to call this function on the nil - * objects. - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - * - * Return value: the error status. - **/ -cairo_status_t -_cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&scaled_font->status, status); - - return _cairo_error (status); -} - -/** - * cairo_scaled_font_get_type: - * @scaled_font: a #cairo_scaled_font_t - * - * This function returns the type of the backend used to create - * a scaled font. See #cairo_font_type_t for available types. - * However, this function never returns %CAIRO_FONT_TYPE_TOY. - * - * Return value: The type of @scaled_font. - * - * Since: 1.2 - **/ -cairo_font_type_t -cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) - return CAIRO_FONT_TYPE_TOY; - - return scaled_font->backend->type; -} - -/** - * cairo_scaled_font_status: - * @scaled_font: a #cairo_scaled_font_t - * - * Checks whether an error has previously occurred for this - * scaled_font. - * - * Return value: %CAIRO_STATUS_SUCCESS or another error such as - * %CAIRO_STATUS_NO_MEMORY. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_scaled_font_status (cairo_scaled_font_t *scaled_font) -{ - return scaled_font->status; -} -slim_hidden_def (cairo_scaled_font_status); - -/* Here we keep a unique mapping from - * font_face/matrix/ctm/font_options => #cairo_scaled_font_t. - * - * Here are the things that we want to map: - * - * a) All otherwise referenced #cairo_scaled_font_t's - * b) Some number of not otherwise referenced #cairo_scaled_font_t's - * - * The implementation uses a hash table which covers (a) - * completely. Then, for (b) we have an array of otherwise - * unreferenced fonts (holdovers) which are expired in - * least-recently-used order. - * - * The cairo_scaled_font_create() code gets to treat this like a regular - * hash table. All of the magic for the little holdover cache is in - * cairo_scaled_font_reference() and cairo_scaled_font_destroy(). - */ - -/* This defines the size of the holdover array ... that is, the number - * of scaled fonts we keep around even when not otherwise referenced - */ -#define CAIRO_SCALED_FONT_MAX_HOLDOVERS 256 - -typedef struct _cairo_scaled_font_map { - cairo_scaled_font_t *mru_scaled_font; - cairo_hash_table_t *hash_table; - cairo_scaled_font_t *holdovers[CAIRO_SCALED_FONT_MAX_HOLDOVERS]; - int num_holdovers; -} cairo_scaled_font_map_t; - -static cairo_scaled_font_map_t *cairo_scaled_font_map; - -static int -_cairo_scaled_font_keys_equal (const void *abstract_key_a, const void *abstract_key_b); - -static cairo_scaled_font_map_t * -_cairo_scaled_font_map_lock (void) -{ - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); - - if (cairo_scaled_font_map == NULL) { - cairo_scaled_font_map = malloc (sizeof (cairo_scaled_font_map_t)); - if (unlikely (cairo_scaled_font_map == NULL)) - goto CLEANUP_MUTEX_LOCK; - - cairo_scaled_font_map->mru_scaled_font = NULL; - cairo_scaled_font_map->hash_table = - _cairo_hash_table_create (_cairo_scaled_font_keys_equal); - - if (unlikely (cairo_scaled_font_map->hash_table == NULL)) - goto CLEANUP_SCALED_FONT_MAP; - - cairo_scaled_font_map->num_holdovers = 0; - } - - return cairo_scaled_font_map; - - CLEANUP_SCALED_FONT_MAP: - free (cairo_scaled_font_map); - cairo_scaled_font_map = NULL; - CLEANUP_MUTEX_LOCK: - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NULL; -} - -static void -_cairo_scaled_font_map_unlock (void) -{ - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); -} - -void -_cairo_scaled_font_map_destroy (void) -{ - cairo_scaled_font_map_t *font_map; - cairo_scaled_font_t *scaled_font; - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); - - font_map = cairo_scaled_font_map; - if (unlikely (font_map == NULL)) { - goto CLEANUP_MUTEX_LOCK; - } - - scaled_font = font_map->mru_scaled_font; - if (scaled_font != NULL) { - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); - cairo_scaled_font_destroy (scaled_font); - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); - } - - /* remove scaled_fonts starting from the end so that font_map->holdovers - * is always in a consistent state when we release the mutex. */ - while (font_map->num_holdovers) { - scaled_font = font_map->holdovers[font_map->num_holdovers-1]; - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); - _cairo_hash_table_remove (font_map->hash_table, - &scaled_font->hash_entry); - - font_map->num_holdovers--; - - /* This releases the font_map lock to avoid the possibility of a - * recursive deadlock when the scaled font destroy closure gets - * called - */ - _cairo_scaled_font_fini (scaled_font); - - free (scaled_font); - } - - _cairo_hash_table_destroy (font_map->hash_table); - - free (cairo_scaled_font_map); - cairo_scaled_font_map = NULL; - - CLEANUP_MUTEX_LOCK: - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); -} - -static void -_cairo_scaled_glyph_page_destroy (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_page_t *page) -{ - unsigned int n; - - assert (!scaled_font->cache_frozen); - assert (!scaled_font->global_cache_frozen); - - for (n = 0; n < page->num_glyphs; n++) { - _cairo_hash_table_remove (scaled_font->glyphs, - &page->glyphs[n].hash_entry); - _cairo_scaled_glyph_fini (scaled_font, &page->glyphs[n]); - } - - cairo_list_del (&page->link); - free (page); -} - -static void -_cairo_scaled_glyph_page_pluck (void *closure) -{ - cairo_scaled_glyph_page_t *page = closure; - cairo_scaled_font_t *scaled_font; - - assert (! cairo_list_is_empty (&page->link)); - - scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash; - - CAIRO_MUTEX_LOCK (scaled_font->mutex); - _cairo_scaled_glyph_page_destroy (scaled_font, page); - CAIRO_MUTEX_UNLOCK (scaled_font->mutex); -} - -/* If a scaled font wants to unlock the font map while still being - * created (needed for user-fonts), we need to take extra care not - * ending up with multiple identical scaled fonts being created. - * - * What we do is, we create a fake identical scaled font, and mark - * it as placeholder, lock its mutex, and insert that in the fontmap - * hash table. This makes other code trying to create an identical - * scaled font to just wait and retry. - * - * The reason we have to create a fake scaled font instead of just using - * scaled_font is for lifecycle management: we need to (or rather, - * other code needs to) reference the scaled_font in the hash table. - * We can't do that on the input scaled_font as it may be freed by - * font backend upon error. - */ - -cairo_status_t -_cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t *scaled_font) -{ - cairo_status_t status; - cairo_scaled_font_t *placeholder_scaled_font; - - assert (CAIRO_MUTEX_IS_LOCKED (_cairo_scaled_font_map_mutex)); - - status = scaled_font->status; - if (unlikely (status)) - return status; - - placeholder_scaled_font = malloc (sizeof (cairo_scaled_font_t)); - if (unlikely (placeholder_scaled_font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* full initialization is wasteful, but who cares... */ - status = _cairo_scaled_font_init (placeholder_scaled_font, - scaled_font->font_face, - &scaled_font->font_matrix, - &scaled_font->ctm, - &scaled_font->options, - NULL); - if (unlikely (status)) - goto FREE_PLACEHOLDER; - - placeholder_scaled_font->placeholder = TRUE; - - placeholder_scaled_font->hash_entry.hash - = _cairo_scaled_font_compute_hash (placeholder_scaled_font); - status = _cairo_hash_table_insert (cairo_scaled_font_map->hash_table, - &placeholder_scaled_font->hash_entry); - if (unlikely (status)) - goto FINI_PLACEHOLDER; - - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); - CAIRO_MUTEX_LOCK (placeholder_scaled_font->mutex); - - return CAIRO_STATUS_SUCCESS; - - FINI_PLACEHOLDER: - _cairo_scaled_font_fini_internal (placeholder_scaled_font); - FREE_PLACEHOLDER: - free (placeholder_scaled_font); - - return _cairo_scaled_font_set_error (scaled_font, status); -} - -void -_cairo_scaled_font_unregister_placeholder_and_lock_font_map (cairo_scaled_font_t *scaled_font) -{ - cairo_scaled_font_t *placeholder_scaled_font; - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); - - /* temporary hash value to match the placeholder */ - scaled_font->hash_entry.hash - = _cairo_scaled_font_compute_hash (scaled_font); - placeholder_scaled_font = - _cairo_hash_table_lookup (cairo_scaled_font_map->hash_table, - &scaled_font->hash_entry); - assert (placeholder_scaled_font != NULL); - assert (placeholder_scaled_font->placeholder); - assert (CAIRO_MUTEX_IS_LOCKED (placeholder_scaled_font->mutex)); - - _cairo_hash_table_remove (cairo_scaled_font_map->hash_table, - &placeholder_scaled_font->hash_entry); - - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); - - CAIRO_MUTEX_UNLOCK (placeholder_scaled_font->mutex); - cairo_scaled_font_destroy (placeholder_scaled_font); - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); -} - -static void -_cairo_scaled_font_placeholder_wait_for_creation_to_finish (cairo_scaled_font_t *placeholder_scaled_font) -{ - /* reference the place holder so it doesn't go away */ - cairo_scaled_font_reference (placeholder_scaled_font); - - /* now unlock the fontmap mutex so creation has a chance to finish */ - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); - - /* wait on placeholder mutex until we are awaken */ - CAIRO_MUTEX_LOCK (placeholder_scaled_font->mutex); - - /* ok, creation done. just clean up and back out */ - CAIRO_MUTEX_UNLOCK (placeholder_scaled_font->mutex); - cairo_scaled_font_destroy (placeholder_scaled_font); - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); -} - -/* Fowler / Noll / Vo (FNV) Hash (http://www.isthe.com/chongo/tech/comp/fnv/) - * - * Not necessarily better than a lot of other hashes, but should be OK, and - * well tested with binary data. - */ - -#define FNV_32_PRIME ((uint32_t)0x01000193) -#define FNV1_32_INIT ((uint32_t)0x811c9dc5) - -static uint32_t -_hash_matrix_fnv (const cairo_matrix_t *matrix, - uint32_t hval) -{ - const uint8_t *buffer = (const uint8_t *) matrix; - int len = sizeof (cairo_matrix_t); - do { - hval *= FNV_32_PRIME; - hval ^= *buffer++; - } while (--len); - - return hval; -} - -static uint32_t -_hash_mix_bits (uint32_t hash) -{ - hash += hash << 12; - hash ^= hash >> 7; - hash += hash << 3; - hash ^= hash >> 17; - hash += hash << 5; - return hash; -} - -static uint32_t -_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font) -{ - uint32_t hash = FNV1_32_INIT; - - /* We do a bytewise hash on the font matrices */ - hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash); - hash = _hash_matrix_fnv (&scaled_font->ctm, hash); - hash = _hash_mix_bits (hash); - - hash ^= (unsigned long) scaled_font->original_font_face; - hash ^= cairo_font_options_hash (&scaled_font->options); - - /* final mixing of bits */ - hash = _hash_mix_bits (hash); - assert (hash != ZOMBIE); - - return hash; -} - -static void -_cairo_scaled_font_init_key (cairo_scaled_font_t *scaled_font, - cairo_font_face_t *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options) -{ - scaled_font->status = CAIRO_STATUS_SUCCESS; - scaled_font->placeholder = FALSE; - scaled_font->font_face = font_face; - scaled_font->original_font_face = font_face; - scaled_font->font_matrix = *font_matrix; - scaled_font->ctm = *ctm; - /* ignore translation values in the ctm */ - scaled_font->ctm.x0 = 0.; - scaled_font->ctm.y0 = 0.; - _cairo_font_options_init_copy (&scaled_font->options, options); - - scaled_font->hash_entry.hash = - _cairo_scaled_font_compute_hash (scaled_font); -} - -static cairo_bool_t -_cairo_scaled_font_keys_equal (const void *abstract_key_a, - const void *abstract_key_b) -{ - const cairo_scaled_font_t *key_a = abstract_key_a; - const cairo_scaled_font_t *key_b = abstract_key_b; - - return key_a->original_font_face == key_b->original_font_face && - memcmp ((unsigned char *)(&key_a->font_matrix.xx), - (unsigned char *)(&key_b->font_matrix.xx), - sizeof(cairo_matrix_t)) == 0 && - memcmp ((unsigned char *)(&key_a->ctm.xx), - (unsigned char *)(&key_b->ctm.xx), - sizeof(cairo_matrix_t)) == 0 && - cairo_font_options_equal (&key_a->options, &key_b->options); -} - -static cairo_bool_t -_cairo_scaled_font_matches (const cairo_scaled_font_t *scaled_font, - const cairo_font_face_t *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options) -{ - return scaled_font->original_font_face == font_face && - memcmp ((unsigned char *)(&scaled_font->font_matrix.xx), - (unsigned char *)(&font_matrix->xx), - sizeof(cairo_matrix_t)) == 0 && - memcmp ((unsigned char *)(&scaled_font->ctm.xx), - (unsigned char *)(&ctm->xx), - sizeof(cairo_matrix_t)) == 0 && - cairo_font_options_equal (&scaled_font->options, options); -} - -/* - * Basic #cairo_scaled_font_t object management - */ - -cairo_status_t -_cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, - cairo_font_face_t *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - const cairo_scaled_font_backend_t *backend) -{ - cairo_status_t status; - - status = cairo_font_options_status ((cairo_font_options_t *) options); - if (unlikely (status)) - return status; - - scaled_font->status = CAIRO_STATUS_SUCCESS; - scaled_font->placeholder = FALSE; - scaled_font->font_face = font_face; - scaled_font->original_font_face = font_face; - scaled_font->font_matrix = *font_matrix; - scaled_font->ctm = *ctm; - /* ignore translation values in the ctm */ - scaled_font->ctm.x0 = 0.; - scaled_font->ctm.y0 = 0.; - _cairo_font_options_init_copy (&scaled_font->options, options); - - cairo_matrix_multiply (&scaled_font->scale, - &scaled_font->font_matrix, - &scaled_font->ctm); - - scaled_font->max_scale = MAX (fabs (scaled_font->scale.xx) + fabs (scaled_font->scale.xy), - fabs (scaled_font->scale.yx) + fabs (scaled_font->scale.yy)); - scaled_font->scale_inverse = scaled_font->scale; - status = cairo_matrix_invert (&scaled_font->scale_inverse); - if (unlikely (status)) { - /* If the font scale matrix is rank 0, just using an all-zero inverse matrix - * makes everything work correctly. This make font size 0 work without - * producing an error. - * - * FIXME: If the scale is rank 1, we still go into error mode. But then - * again, that's what we do everywhere in cairo. - * - * Also, the check for == 0. below may be too harsh... - */ - if (_cairo_matrix_is_scale_0 (&scaled_font->scale)) { - cairo_matrix_init (&scaled_font->scale_inverse, - 0, 0, 0, 0, - -scaled_font->scale.x0, - -scaled_font->scale.y0); - } else - return status; - } - - scaled_font->glyphs = _cairo_hash_table_create (NULL); - if (unlikely (scaled_font->glyphs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - cairo_list_init (&scaled_font->glyph_pages); - scaled_font->cache_frozen = FALSE; - scaled_font->global_cache_frozen = FALSE; - - scaled_font->holdover = FALSE; - scaled_font->finished = FALSE; - - CAIRO_REFERENCE_COUNT_INIT (&scaled_font->ref_count, 1); - - _cairo_user_data_array_init (&scaled_font->user_data); - - cairo_font_face_reference (font_face); - scaled_font->original_font_face = NULL; - - CAIRO_MUTEX_INIT (scaled_font->mutex); - - cairo_list_init (&scaled_font->dev_privates); - - scaled_font->backend = backend; - cairo_list_init (&scaled_font->link); - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_scaled_font_freeze_cache (cairo_scaled_font_t *scaled_font) -{ - /* ensure we do not modify an error object */ - assert (scaled_font->status == CAIRO_STATUS_SUCCESS); - - CAIRO_MUTEX_LOCK (scaled_font->mutex); - scaled_font->cache_frozen = TRUE; -} - -void -_cairo_scaled_font_thaw_cache (cairo_scaled_font_t *scaled_font) -{ - assert (scaled_font->cache_frozen); - - if (scaled_font->global_cache_frozen) { - CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); - _cairo_cache_thaw (&cairo_scaled_glyph_page_cache); - CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); - scaled_font->global_cache_frozen = FALSE; - } - - scaled_font->cache_frozen = FALSE; - CAIRO_MUTEX_UNLOCK (scaled_font->mutex); -} - -void -_cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font) -{ - CAIRO_MUTEX_LOCK (scaled_font->mutex); - assert (! scaled_font->cache_frozen); - assert (! scaled_font->global_cache_frozen); - CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); - while (! cairo_list_is_empty (&scaled_font->glyph_pages)) { - cairo_scaled_glyph_page_t *page = - cairo_list_first_entry (&scaled_font->glyph_pages, - cairo_scaled_glyph_page_t, - link); - - cairo_scaled_glyph_page_cache.size -= page->cache_entry.size; - _cairo_hash_table_remove (cairo_scaled_glyph_page_cache.hash_table, - (cairo_hash_entry_t *) &page->cache_entry); - - _cairo_scaled_glyph_page_destroy (scaled_font, page); - } - CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); - CAIRO_MUTEX_UNLOCK (scaled_font->mutex); -} - -cairo_status_t -_cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font, - cairo_font_extents_t *fs_metrics) -{ - cairo_status_t status; - double font_scale_x, font_scale_y; - - scaled_font->fs_extents = *fs_metrics; - - status = _cairo_matrix_compute_basis_scale_factors (&scaled_font->font_matrix, - &font_scale_x, &font_scale_y, - 1); - if (unlikely (status)) - return status; - - /* - * The font responded in unscaled units, scale by the font - * matrix scale factors to get to user space - */ - - scaled_font->extents.ascent = fs_metrics->ascent * font_scale_y; - scaled_font->extents.descent = fs_metrics->descent * font_scale_y; - scaled_font->extents.height = fs_metrics->height * font_scale_y; - scaled_font->extents.max_x_advance = fs_metrics->max_x_advance * font_scale_x; - scaled_font->extents.max_y_advance = fs_metrics->max_y_advance * font_scale_y; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_scaled_font_fini_internal (cairo_scaled_font_t *scaled_font) -{ - assert (! scaled_font->cache_frozen); - assert (! scaled_font->global_cache_frozen); - scaled_font->finished = TRUE; - - _cairo_scaled_font_reset_cache (scaled_font); - _cairo_hash_table_destroy (scaled_font->glyphs); - - cairo_font_face_destroy (scaled_font->font_face); - cairo_font_face_destroy (scaled_font->original_font_face); - - CAIRO_MUTEX_FINI (scaled_font->mutex); - - while (! cairo_list_is_empty (&scaled_font->dev_privates)) { - cairo_scaled_font_private_t *private = - cairo_list_first_entry (&scaled_font->dev_privates, - cairo_scaled_font_private_t, - link); - private->destroy (private, scaled_font); - } - - if (scaled_font->backend != NULL && scaled_font->backend->fini != NULL) - scaled_font->backend->fini (scaled_font); - - _cairo_user_data_array_fini (&scaled_font->user_data); -} - -void -_cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font) -{ - /* Release the lock to avoid the possibility of a recursive - * deadlock when the scaled font destroy closure gets called. */ - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); - _cairo_scaled_font_fini_internal (scaled_font); - CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); -} - -void -_cairo_scaled_font_attach_private (cairo_scaled_font_t *scaled_font, - cairo_scaled_font_private_t *private, - const void *key, - void (*destroy) (cairo_scaled_font_private_t *, - cairo_scaled_font_t *)) -{ - private->key = key; - private->destroy = destroy; - cairo_list_add (&private->link, &scaled_font->dev_privates); -} - -cairo_scaled_font_private_t * -_cairo_scaled_font_find_private (cairo_scaled_font_t *scaled_font, - const void *key) -{ - cairo_scaled_font_private_t *priv; - - cairo_list_foreach_entry (priv, cairo_scaled_font_private_t, - &scaled_font->dev_privates, link) - { - if (priv->key == key) { - if (priv->link.prev != &scaled_font->dev_privates) - cairo_list_move (&priv->link, &scaled_font->dev_privates); - return priv; - } - } - - return NULL; -} - -void -_cairo_scaled_glyph_attach_private (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_glyph_private_t *private, - const void *key, - void (*destroy) (cairo_scaled_glyph_private_t *, - cairo_scaled_glyph_t *, - cairo_scaled_font_t *)) -{ - private->key = key; - private->destroy = destroy; - cairo_list_add (&private->link, &scaled_glyph->dev_privates); -} - -cairo_scaled_glyph_private_t * -_cairo_scaled_glyph_find_private (cairo_scaled_glyph_t *scaled_glyph, - const void *key) -{ - cairo_scaled_glyph_private_t *priv; - - cairo_list_foreach_entry (priv, cairo_scaled_glyph_private_t, - &scaled_glyph->dev_privates, link) - { - if (priv->key == key) { - if (priv->link.prev != &scaled_glyph->dev_privates) - cairo_list_move (&priv->link, &scaled_glyph->dev_privates); - return priv; - } - } - - return NULL; -} - -/** - * cairo_scaled_font_create: - * @font_face: a #cairo_font_face_t - * @font_matrix: font space to user space transformation matrix for the - * font. In the simplest case of a N point font, this matrix is - * just a scale by N, but it can also be used to shear the font - * or stretch it unequally along the two axes. See - * cairo_set_font_matrix(). - * @ctm: user to device transformation matrix with which the font will - * be used. - * @options: options to use when getting metrics for the font and - * rendering with it. - * - * Creates a #cairo_scaled_font_t object from a font face and matrices that - * describe the size of the font and the environment in which it will - * be used. - * - * Return value: a newly created #cairo_scaled_font_t. Destroy with - * cairo_scaled_font_destroy() - * - * Since: 1.0 - **/ -cairo_scaled_font_t * -cairo_scaled_font_create (cairo_font_face_t *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options) -{ - cairo_status_t status; - cairo_scaled_font_map_t *font_map; - cairo_font_face_t *original_font_face = font_face; - cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL, *dead = NULL; - double det; - - status = font_face->status; - if (unlikely (status)) - return _cairo_scaled_font_create_in_error (status); - - det = _cairo_matrix_compute_determinant (font_matrix); - if (! ISFINITE (det)) - return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_MATRIX)); - - det = _cairo_matrix_compute_determinant (ctm); - if (! ISFINITE (det)) - return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_MATRIX)); - - status = cairo_font_options_status ((cairo_font_options_t *) options); - if (unlikely (status)) - return _cairo_scaled_font_create_in_error (status); - - /* Note that degenerate ctm or font_matrix *are* allowed. - * We want to support a font size of 0. */ - - font_map = _cairo_scaled_font_map_lock (); - if (unlikely (font_map == NULL)) - return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - scaled_font = font_map->mru_scaled_font; - if (scaled_font != NULL && - _cairo_scaled_font_matches (scaled_font, - font_face, font_matrix, ctm, options)) - { - assert (scaled_font->hash_entry.hash != ZOMBIE); - assert (! scaled_font->placeholder); - - if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) { - /* We increment the reference count manually here, (rather - * than calling into cairo_scaled_font_reference), since we - * must modify the reference count while our lock is still - * held. */ - _cairo_reference_count_inc (&scaled_font->ref_count); - _cairo_scaled_font_map_unlock (); - return scaled_font; - } - - /* the font has been put into an error status - abandon the cache */ - _cairo_hash_table_remove (font_map->hash_table, - &scaled_font->hash_entry); - scaled_font->hash_entry.hash = ZOMBIE; - dead = scaled_font; - font_map->mru_scaled_font = NULL; - } - - _cairo_scaled_font_init_key (&key, font_face, font_matrix, ctm, options); - - while ((scaled_font = _cairo_hash_table_lookup (font_map->hash_table, - &key.hash_entry))) - { - if (! scaled_font->placeholder) - break; - - /* If the scaled font is being created (happens for user-font), - * just wait until it's done, then retry */ - _cairo_scaled_font_placeholder_wait_for_creation_to_finish (scaled_font); - } - - if (scaled_font != NULL) { - /* If the original reference count is 0, then this font must have - * been found in font_map->holdovers, (which means this caching is - * actually working). So now we remove it from the holdovers - * array, unless we caught the font in the middle of destruction. - */ - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) { - if (scaled_font->holdover) { - int i; - - for (i = 0; i < font_map->num_holdovers; i++) { - if (font_map->holdovers[i] == scaled_font) { - font_map->num_holdovers--; - memmove (&font_map->holdovers[i], - &font_map->holdovers[i+1], - (font_map->num_holdovers - i) * sizeof (cairo_scaled_font_t*)); - break; - } - } - - scaled_font->holdover = FALSE; - } - - /* reset any error status */ - scaled_font->status = CAIRO_STATUS_SUCCESS; - } - - if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) { - /* We increment the reference count manually here, (rather - * than calling into cairo_scaled_font_reference), since we - * must modify the reference count while our lock is still - * held. */ - - old = font_map->mru_scaled_font; - font_map->mru_scaled_font = scaled_font; - /* increment reference count for the mru cache */ - _cairo_reference_count_inc (&scaled_font->ref_count); - /* and increment for the returned reference */ - _cairo_reference_count_inc (&scaled_font->ref_count); - _cairo_scaled_font_map_unlock (); - - cairo_scaled_font_destroy (old); - if (font_face != original_font_face) - cairo_font_face_destroy (font_face); - - return scaled_font; - } - - /* the font has been put into an error status - abandon the cache */ - _cairo_hash_table_remove (font_map->hash_table, - &scaled_font->hash_entry); - scaled_font->hash_entry.hash = ZOMBIE; - } - - - /* Otherwise create it and insert it into the hash table. */ - if (font_face->backend->get_implementation != NULL) { - font_face = font_face->backend->get_implementation (font_face, - font_matrix, - ctm, - options); - if (unlikely (font_face->status)) { - _cairo_scaled_font_map_unlock (); - return _cairo_scaled_font_create_in_error (font_face->status); - } - } - - status = font_face->backend->scaled_font_create (font_face, font_matrix, - ctm, options, &scaled_font); - /* Did we leave the backend in an error state? */ - if (unlikely (status)) { - _cairo_scaled_font_map_unlock (); - if (font_face != original_font_face) - cairo_font_face_destroy (font_face); - - if (dead != NULL) - cairo_scaled_font_destroy (dead); - - status = _cairo_font_face_set_error (font_face, status); - return _cairo_scaled_font_create_in_error (status); - } - /* Or did we encounter an error whilst constructing the scaled font? */ - if (unlikely (scaled_font->status)) { - _cairo_scaled_font_map_unlock (); - if (font_face != original_font_face) - cairo_font_face_destroy (font_face); - - if (dead != NULL) - cairo_scaled_font_destroy (dead); - - return scaled_font; - } - - /* Our caching above is defeated if the backend switches fonts on us - - * e.g. old incarnations of toy-font-face and lazily resolved - * ft-font-faces - */ - assert (scaled_font->font_face == font_face); - assert (! scaled_font->cache_frozen); - assert (! scaled_font->global_cache_frozen); - - scaled_font->original_font_face = - cairo_font_face_reference (original_font_face); - - scaled_font->hash_entry.hash = _cairo_scaled_font_compute_hash(scaled_font); - - status = _cairo_hash_table_insert (font_map->hash_table, - &scaled_font->hash_entry); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - old = font_map->mru_scaled_font; - font_map->mru_scaled_font = scaled_font; - _cairo_reference_count_inc (&scaled_font->ref_count); - } - - _cairo_scaled_font_map_unlock (); - - cairo_scaled_font_destroy (old); - if (font_face != original_font_face) - cairo_font_face_destroy (font_face); - - if (dead != NULL) - cairo_scaled_font_destroy (dead); - - if (unlikely (status)) { - /* We can't call _cairo_scaled_font_destroy here since it expects - * that the font has already been successfully inserted into the - * hash table. */ - _cairo_scaled_font_fini_internal (scaled_font); - free (scaled_font); - return _cairo_scaled_font_create_in_error (status); - } - - return scaled_font; -} -slim_hidden_def (cairo_scaled_font_create); - -static cairo_scaled_font_t *_cairo_scaled_font_nil_objects[CAIRO_STATUS_LAST_STATUS + 1]; - -/* XXX This should disappear in favour of a common pool of error objects. */ -cairo_scaled_font_t * -_cairo_scaled_font_create_in_error (cairo_status_t status) -{ - cairo_scaled_font_t *scaled_font; - - assert (status != CAIRO_STATUS_SUCCESS); - - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_scaled_font_t *) &_cairo_scaled_font_nil; - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex); - scaled_font = _cairo_scaled_font_nil_objects[status]; - if (unlikely (scaled_font == NULL)) { - scaled_font = malloc (sizeof (cairo_scaled_font_t)); - if (unlikely (scaled_font == NULL)) { - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_scaled_font_t *) &_cairo_scaled_font_nil; - } - - *scaled_font = _cairo_scaled_font_nil; - scaled_font->status = status; - _cairo_scaled_font_nil_objects[status] = scaled_font; - } - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); - - return scaled_font; -} - -void -_cairo_scaled_font_reset_static_data (void) -{ - int status; - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex); - for (status = CAIRO_STATUS_SUCCESS; - status <= CAIRO_STATUS_LAST_STATUS; - status++) - { - free (_cairo_scaled_font_nil_objects[status]); - _cairo_scaled_font_nil_objects[status] = NULL; - } - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); - - CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); - if (cairo_scaled_glyph_page_cache.hash_table != NULL) { - _cairo_cache_fini (&cairo_scaled_glyph_page_cache); - cairo_scaled_glyph_page_cache.hash_table = NULL; - } - CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); -} - -/** - * cairo_scaled_font_reference: - * @scaled_font: a #cairo_scaled_font_t, (may be %NULL in which case - * this function does nothing) - * - * Increases the reference count on @scaled_font by one. This prevents - * @scaled_font from being destroyed until a matching call to - * cairo_scaled_font_destroy() is made. - * - * The number of references to a #cairo_scaled_font_t can be get using - * cairo_scaled_font_get_reference_count(). - * - * Returns: the referenced #cairo_scaled_font_t - * - * Since: 1.0 - **/ -cairo_scaled_font_t * -cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font) -{ - if (scaled_font == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) - return scaled_font; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); - - _cairo_reference_count_inc (&scaled_font->ref_count); - - return scaled_font; -} -slim_hidden_def (cairo_scaled_font_reference); - -/** - * cairo_scaled_font_destroy: - * @scaled_font: a #cairo_scaled_font_t - * - * Decreases the reference count on @font by one. If the result - * is zero, then @font and all associated resources are freed. - * See cairo_scaled_font_reference(). - * - * Since: 1.0 - **/ -void -cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font) -{ - cairo_scaled_font_t *lru = NULL; - cairo_scaled_font_map_t *font_map; - - assert (CAIRO_MUTEX_IS_UNLOCKED (_cairo_scaled_font_map_mutex)); - - if (scaled_font == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&scaled_font->ref_count)) - return; - - assert (! scaled_font->cache_frozen); - assert (! scaled_font->global_cache_frozen); - - font_map = _cairo_scaled_font_map_lock (); - assert (font_map != NULL); - - /* Another thread may have resurrected the font whilst we waited */ - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) { - if (! scaled_font->placeholder && - scaled_font->hash_entry.hash != ZOMBIE) - { - /* Another thread may have already inserted us into the holdovers */ - if (scaled_font->holdover) - goto unlock; - - /* Rather than immediately destroying this object, we put it into - * the font_map->holdovers array in case it will get used again - * soon (and is why we must hold the lock over the atomic op on - * the reference count). To make room for it, we do actually - * destroy the least-recently-used holdover. - */ - - if (font_map->num_holdovers == CAIRO_SCALED_FONT_MAX_HOLDOVERS) { - lru = font_map->holdovers[0]; - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&lru->ref_count)); - - _cairo_hash_table_remove (font_map->hash_table, - &lru->hash_entry); - - font_map->num_holdovers--; - memmove (&font_map->holdovers[0], - &font_map->holdovers[1], - font_map->num_holdovers * sizeof (cairo_scaled_font_t*)); - } - - font_map->holdovers[font_map->num_holdovers++] = scaled_font; - scaled_font->holdover = TRUE; - } else - lru = scaled_font; - } - - unlock: - _cairo_scaled_font_map_unlock (); - - /* If we pulled an item from the holdovers array, (while the font - * map lock was held, of course), then there is no way that anyone - * else could have acquired a reference to it. So we can now - * safely call fini on it without any lock held. This is desirable - * as we never want to call into any backend function with a lock - * held. */ - if (lru != NULL) { - _cairo_scaled_font_fini_internal (lru); - free (lru); - } -} -slim_hidden_def (cairo_scaled_font_destroy); - -/** - * cairo_scaled_font_get_reference_count: - * @scaled_font: a #cairo_scaled_font_t - * - * Returns the current reference count of @scaled_font. - * - * Return value: the current reference count of @scaled_font. If the - * object is a nil object, 0 will be returned. - * - * Since: 1.4 - **/ -unsigned int -cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font) -{ - if (scaled_font == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&scaled_font->ref_count); -} - -/** - * cairo_scaled_font_get_user_data: - * @scaled_font: a #cairo_scaled_font_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Return user data previously attached to @scaled_font using the - * specified key. If no user data has been attached with the given - * key this function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - * - * Since: 1.4 - **/ -void * -cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font, - const cairo_user_data_key_t *key) -{ - return _cairo_user_data_array_get_data (&scaled_font->user_data, - key); -} -slim_hidden_def (cairo_scaled_font_get_user_data); - -/** - * cairo_scaled_font_set_user_data: - * @scaled_font: a #cairo_scaled_font_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach to the #cairo_scaled_font_t - * @destroy: a #cairo_destroy_func_t which will be called when the - * #cairo_t is destroyed or when new user data is attached using the - * same key. - * - * Attach user data to @scaled_font. To remove user data from a surface, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) - return scaled_font->status; - - return _cairo_user_data_array_set_data (&scaled_font->user_data, - key, user_data, destroy); -} -slim_hidden_def (cairo_scaled_font_set_user_data); - -/* Public font API follows. */ - -/** - * cairo_scaled_font_extents: - * @scaled_font: a #cairo_scaled_font_t - * @extents: a #cairo_font_extents_t which to store the retrieved extents. - * - * Gets the metrics for a #cairo_scaled_font_t. - * - * Since: 1.0 - **/ -void -cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, - cairo_font_extents_t *extents) -{ - if (scaled_font->status) { - extents->ascent = 0.0; - extents->descent = 0.0; - extents->height = 0.0; - extents->max_x_advance = 0.0; - extents->max_y_advance = 0.0; - return; - } - - *extents = scaled_font->extents; -} -slim_hidden_def (cairo_scaled_font_extents); - -/** - * cairo_scaled_font_text_extents: - * @scaled_font: a #cairo_scaled_font_t - * @utf8: a NUL-terminated string of text, encoded in UTF-8 - * @extents: a #cairo_text_extents_t which to store the retrieved extents. - * - * Gets the extents for a string of text. The extents describe a - * user-space rectangle that encloses the "inked" portion of the text - * drawn at the origin (0,0) (as it would be drawn by cairo_show_text() - * if the cairo graphics state were set to the same font_face, - * font_matrix, ctm, and font_options as @scaled_font). Additionally, - * the x_advance and y_advance values indicate the amount by which the - * current point would be advanced by cairo_show_text(). - * - * Note that whitespace characters do not directly contribute to the - * size of the rectangle (extents.width and extents.height). They do - * contribute indirectly by changing the position of non-whitespace - * characters. In particular, trailing whitespace characters are - * likely to not affect the size of the rectangle, though they will - * affect the x_advance and y_advance values. - * - * Since: 1.2 - **/ -void -cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, - const char *utf8, - cairo_text_extents_t *extents) -{ - cairo_status_t status; - cairo_glyph_t *glyphs = NULL; - int num_glyphs; - - if (scaled_font->status) - goto ZERO_EXTENTS; - - if (utf8 == NULL) - goto ZERO_EXTENTS; - - status = cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., - utf8, -1, - &glyphs, &num_glyphs, - NULL, NULL, - NULL); - if (unlikely (status)) { - status = _cairo_scaled_font_set_error (scaled_font, status); - goto ZERO_EXTENTS; - } - - cairo_scaled_font_glyph_extents (scaled_font, glyphs, num_glyphs, extents); - free (glyphs); - - return; - -ZERO_EXTENTS: - extents->x_bearing = 0.0; - extents->y_bearing = 0.0; - extents->width = 0.0; - extents->height = 0.0; - extents->x_advance = 0.0; - extents->y_advance = 0.0; -} - -/** - * cairo_scaled_font_glyph_extents: - * @scaled_font: a #cairo_scaled_font_t - * @glyphs: an array of glyph IDs with X and Y offsets. - * @num_glyphs: the number of glyphs in the @glyphs array - * @extents: a #cairo_text_extents_t which to store the retrieved extents. - * - * Gets the extents for an array of glyphs. The extents describe a - * user-space rectangle that encloses the "inked" portion of the - * glyphs, (as they would be drawn by cairo_show_glyphs() if the cairo - * graphics state were set to the same font_face, font_matrix, ctm, - * and font_options as @scaled_font). Additionally, the x_advance and - * y_advance values indicate the amount by which the current point - * would be advanced by cairo_show_glyphs(). - * - * Note that whitespace glyphs do not contribute to the size of the - * rectangle (extents.width and extents.height). - * - * Since: 1.0 - **/ -void -cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents) -{ - cairo_status_t status; - int i; - double min_x = 0.0, min_y = 0.0, max_x = 0.0, max_y = 0.0; - cairo_bool_t visible = FALSE; - cairo_scaled_glyph_t *scaled_glyph = NULL; - - extents->x_bearing = 0.0; - extents->y_bearing = 0.0; - extents->width = 0.0; - extents->height = 0.0; - extents->x_advance = 0.0; - extents->y_advance = 0.0; - - if (unlikely (scaled_font->status)) - goto ZERO_EXTENTS; - - if (num_glyphs == 0) - goto ZERO_EXTENTS; - - if (unlikely (num_glyphs < 0)) { - _cairo_error_throw (CAIRO_STATUS_NEGATIVE_COUNT); - /* XXX Can't propagate error */ - goto ZERO_EXTENTS; - } - - if (unlikely (glyphs == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NULL_POINTER); - /* XXX Can't propagate error */ - goto ZERO_EXTENTS; - } - - _cairo_scaled_font_freeze_cache (scaled_font); - - for (i = 0; i < num_glyphs; i++) { - double left, top, right, bottom; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) { - status = _cairo_scaled_font_set_error (scaled_font, status); - goto UNLOCK; - } - - /* "Ink" extents should skip "invisible" glyphs */ - if (scaled_glyph->metrics.width == 0 || scaled_glyph->metrics.height == 0) - continue; - - left = scaled_glyph->metrics.x_bearing + glyphs[i].x; - right = left + scaled_glyph->metrics.width; - top = scaled_glyph->metrics.y_bearing + glyphs[i].y; - bottom = top + scaled_glyph->metrics.height; - - if (!visible) { - visible = TRUE; - min_x = left; - max_x = right; - min_y = top; - max_y = bottom; - } else { - if (left < min_x) min_x = left; - if (right > max_x) max_x = right; - if (top < min_y) min_y = top; - if (bottom > max_y) max_y = bottom; - } - } - - if (visible) { - extents->x_bearing = min_x - glyphs[0].x; - extents->y_bearing = min_y - glyphs[0].y; - extents->width = max_x - min_x; - extents->height = max_y - min_y; - } else { - extents->x_bearing = 0.0; - extents->y_bearing = 0.0; - extents->width = 0.0; - extents->height = 0.0; - } - - if (num_glyphs) { - double x0, y0, x1, y1; - - x0 = glyphs[0].x; - y0 = glyphs[0].y; - - /* scaled_glyph contains the glyph for num_glyphs - 1 already. */ - x1 = glyphs[num_glyphs - 1].x + scaled_glyph->metrics.x_advance; - y1 = glyphs[num_glyphs - 1].y + scaled_glyph->metrics.y_advance; - - extents->x_advance = x1 - x0; - extents->y_advance = y1 - y0; - } else { - extents->x_advance = 0.0; - extents->y_advance = 0.0; - } - - UNLOCK: - _cairo_scaled_font_thaw_cache (scaled_font); - return; - -ZERO_EXTENTS: - extents->x_bearing = 0.0; - extents->y_bearing = 0.0; - extents->width = 0.0; - extents->height = 0.0; - extents->x_advance = 0.0; - extents->y_advance = 0.0; -} -slim_hidden_def (cairo_scaled_font_glyph_extents); - -#define GLYPH_LUT_SIZE 64 -static cairo_status_t -cairo_scaled_font_text_to_glyphs_internal_cached (cairo_scaled_font_t *scaled_font, - double x, - double y, - const char *utf8, - cairo_glyph_t *glyphs, - cairo_text_cluster_t **clusters, - int num_chars) -{ - struct glyph_lut_elt { - unsigned long index; - double x_advance; - double y_advance; - } glyph_lut[GLYPH_LUT_SIZE]; - uint32_t glyph_lut_unicode[GLYPH_LUT_SIZE]; - cairo_status_t status; - const char *p; - int i; - - for (i = 0; i < GLYPH_LUT_SIZE; i++) - glyph_lut_unicode[i] = ~0U; - - p = utf8; - for (i = 0; i < num_chars; i++) { - int idx, num_bytes; - uint32_t unicode; - cairo_scaled_glyph_t *scaled_glyph; - struct glyph_lut_elt *glyph_slot; - - num_bytes = _cairo_utf8_get_char_validated (p, &unicode); - p += num_bytes; - - glyphs[i].x = x; - glyphs[i].y = y; - - idx = unicode % ARRAY_LENGTH (glyph_lut); - glyph_slot = &glyph_lut[idx]; - if (glyph_lut_unicode[idx] == unicode) { - glyphs[i].index = glyph_slot->index; - x += glyph_slot->x_advance; - y += glyph_slot->y_advance; - } else { - unsigned long g; - - g = scaled_font->backend->ucs4_to_index (scaled_font, unicode); - status = _cairo_scaled_glyph_lookup (scaled_font, - g, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) - return status; - - x += scaled_glyph->metrics.x_advance; - y += scaled_glyph->metrics.y_advance; - - glyph_lut_unicode[idx] = unicode; - glyph_slot->index = g; - glyph_slot->x_advance = scaled_glyph->metrics.x_advance; - glyph_slot->y_advance = scaled_glyph->metrics.y_advance; - - glyphs[i].index = g; - } - - if (clusters) { - (*clusters)[i].num_bytes = num_bytes; - (*clusters)[i].num_glyphs = 1; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_scaled_font_text_to_glyphs_internal_uncached (cairo_scaled_font_t *scaled_font, - double x, - double y, - const char *utf8, - cairo_glyph_t *glyphs, - cairo_text_cluster_t **clusters, - int num_chars) -{ - const char *p; - int i; - - p = utf8; - for (i = 0; i < num_chars; i++) { - unsigned long g; - int num_bytes; - uint32_t unicode; - cairo_scaled_glyph_t *scaled_glyph; - cairo_status_t status; - - num_bytes = _cairo_utf8_get_char_validated (p, &unicode); - p += num_bytes; - - glyphs[i].x = x; - glyphs[i].y = y; - - g = scaled_font->backend->ucs4_to_index (scaled_font, unicode); - - /* - * No advance needed for a single character string. So, let's speed up - * one-character strings by skipping glyph lookup. - */ - if (num_chars > 1) { - status = _cairo_scaled_glyph_lookup (scaled_font, - g, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) - return status; - - x += scaled_glyph->metrics.x_advance; - y += scaled_glyph->metrics.y_advance; - } - - glyphs[i].index = g; - - if (clusters) { - (*clusters)[i].num_bytes = num_bytes; - (*clusters)[i].num_glyphs = 1; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -/** - * cairo_scaled_font_text_to_glyphs: - * @x: X position to place first glyph - * @y: Y position to place first glyph - * @scaled_font: a #cairo_scaled_font_t - * @utf8: a string of text encoded in UTF-8 - * @utf8_len: length of @utf8 in bytes, or -1 if it is NUL-terminated - * @glyphs: pointer to array of glyphs to fill - * @num_glyphs: pointer to number of glyphs - * @clusters: pointer to array of cluster mapping information to fill, or %NULL - * @num_clusters: pointer to number of clusters, or %NULL - * @cluster_flags: pointer to location to store cluster flags corresponding to the - * output @clusters, or %NULL - * - * Converts UTF-8 text to an array of glyphs, optionally with cluster - * mapping, that can be used to render later using @scaled_font. - * - * If @glyphs initially points to a non-%NULL value, that array is used - * as a glyph buffer, and @num_glyphs should point to the number of glyph - * entries available there. If the provided glyph array is too short for - * the conversion, a new glyph array is allocated using cairo_glyph_allocate() - * and placed in @glyphs. Upon return, @num_glyphs always contains the - * number of generated glyphs. If the value @glyphs points to has changed - * after the call, the user is responsible for freeing the allocated glyph - * array using cairo_glyph_free(). This may happen even if the provided - * array was large enough. - * - * If @clusters is not %NULL, @num_clusters and @cluster_flags should not be %NULL, - * and cluster mapping will be computed. - * The semantics of how cluster array allocation works is similar to the glyph - * array. That is, - * if @clusters initially points to a non-%NULL value, that array is used - * as a cluster buffer, and @num_clusters should point to the number of cluster - * entries available there. If the provided cluster array is too short for - * the conversion, a new cluster array is allocated using cairo_text_cluster_allocate() - * and placed in @clusters. Upon return, @num_clusters always contains the - * number of generated clusters. If the value @clusters points at has changed - * after the call, the user is responsible for freeing the allocated cluster - * array using cairo_text_cluster_free(). This may happen even if the provided - * array was large enough. - * - * In the simplest case, @glyphs and @clusters can point to %NULL initially - * and a suitable array will be allocated. In code: - * - * cairo_status_t status; - * - * cairo_glyph_t *glyphs = NULL; - * int num_glyphs; - * cairo_text_cluster_t *clusters = NULL; - * int num_clusters; - * cairo_text_cluster_flags_t cluster_flags; - * - * status = cairo_scaled_font_text_to_glyphs (scaled_font, - * x, y, - * utf8, utf8_len, - * &glyphs, &num_glyphs, - * &clusters, &num_clusters, &cluster_flags); - * - * if (status == CAIRO_STATUS_SUCCESS) { - * cairo_show_text_glyphs (cr, - * utf8, utf8_len, - * glyphs, num_glyphs, - * clusters, num_clusters, cluster_flags); - * - * cairo_glyph_free (glyphs); - * cairo_text_cluster_free (clusters); - * } - * - * - * If no cluster mapping is needed: - * - * cairo_status_t status; - * - * cairo_glyph_t *glyphs = NULL; - * int num_glyphs; - * - * status = cairo_scaled_font_text_to_glyphs (scaled_font, - * x, y, - * utf8, utf8_len, - * &glyphs, &num_glyphs, - * NULL, NULL, - * NULL); - * - * if (status == CAIRO_STATUS_SUCCESS) { - * cairo_show_glyphs (cr, glyphs, num_glyphs); - * cairo_glyph_free (glyphs); - * } - * - * - * If stack-based glyph and cluster arrays are to be used for small - * arrays: - * - * cairo_status_t status; - * - * cairo_glyph_t stack_glyphs[40]; - * cairo_glyph_t *glyphs = stack_glyphs; - * int num_glyphs = sizeof (stack_glyphs) / sizeof (stack_glyphs[0]); - * cairo_text_cluster_t stack_clusters[40]; - * cairo_text_cluster_t *clusters = stack_clusters; - * int num_clusters = sizeof (stack_clusters) / sizeof (stack_clusters[0]); - * cairo_text_cluster_flags_t cluster_flags; - * - * status = cairo_scaled_font_text_to_glyphs (scaled_font, - * x, y, - * utf8, utf8_len, - * &glyphs, &num_glyphs, - * &clusters, &num_clusters, &cluster_flags); - * - * if (status == CAIRO_STATUS_SUCCESS) { - * cairo_show_text_glyphs (cr, - * utf8, utf8_len, - * glyphs, num_glyphs, - * clusters, num_clusters, cluster_flags); - * - * if (glyphs != stack_glyphs) - * cairo_glyph_free (glyphs); - * if (clusters != stack_clusters) - * cairo_text_cluster_free (clusters); - * } - * - * - * For details of how @clusters, @num_clusters, and @cluster_flags map input - * UTF-8 text to the output glyphs see cairo_show_text_glyphs(). - * - * The output values can be readily passed to cairo_show_text_glyphs() - * cairo_show_glyphs(), or related functions, assuming that the exact - * same @scaled_font is used for the operation. - * - * Return value: %CAIRO_STATUS_SUCCESS upon success, or an error status - * if the input values are wrong or if conversion failed. If the input - * values are correct but the conversion failed, the error status is also - * set on @scaled_font. - * - * Since: 1.8 - **/ -#define CACHING_THRESHOLD 16 -cairo_status_t -cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font, - double x, - double y, - const char *utf8, - int utf8_len, - cairo_glyph_t **glyphs, - int *num_glyphs, - cairo_text_cluster_t **clusters, - int *num_clusters, - cairo_text_cluster_flags_t *cluster_flags) -{ - int num_chars = 0; - cairo_int_status_t status; - cairo_glyph_t *orig_glyphs; - cairo_text_cluster_t *orig_clusters; - - status = scaled_font->status; - if (unlikely (status)) - return status; - - /* A slew of sanity checks */ - - /* glyphs and num_glyphs can't be NULL */ - if (glyphs == NULL || - num_glyphs == NULL) { - status = _cairo_error (CAIRO_STATUS_NULL_POINTER); - goto BAIL; - } - - /* Special case for NULL and -1 */ - if (utf8 == NULL && utf8_len == -1) - utf8_len = 0; - - /* No NULLs for non-NULLs! */ - if ((utf8_len && utf8 == NULL) || - (clusters && num_clusters == NULL) || - (clusters && cluster_flags == NULL)) { - status = _cairo_error (CAIRO_STATUS_NULL_POINTER); - goto BAIL; - } - - /* A -1 for utf8_len means NUL-terminated */ - if (utf8_len == -1) - utf8_len = strlen (utf8); - - /* A NULL *glyphs means no prealloced glyphs array */ - if (glyphs && *glyphs == NULL) - *num_glyphs = 0; - - /* A NULL *clusters means no prealloced clusters array */ - if (clusters && *clusters == NULL) - *num_clusters = 0; - - if (!clusters && num_clusters) { - num_clusters = NULL; - } - - if (cluster_flags) { - *cluster_flags = FALSE; - } - - if (!clusters && cluster_flags) { - cluster_flags = NULL; - } - - /* Apart from that, no negatives */ - if (utf8_len < 0 || - *num_glyphs < 0 || - (num_clusters && *num_clusters < 0)) { - status = _cairo_error (CAIRO_STATUS_NEGATIVE_COUNT); - goto BAIL; - } - - if (utf8_len == 0) { - status = CAIRO_STATUS_SUCCESS; - goto BAIL; - } - - /* validate input so backend does not have to */ - status = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, &num_chars); - if (unlikely (status)) - goto BAIL; - - _cairo_scaled_font_freeze_cache (scaled_font); - - orig_glyphs = *glyphs; - orig_clusters = clusters ? *clusters : NULL; - - if (scaled_font->backend->text_to_glyphs) { - status = scaled_font->backend->text_to_glyphs (scaled_font, x, y, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) { - if (status == CAIRO_INT_STATUS_SUCCESS) { - /* The checks here are crude; we only should do them in - * user-font backend, but they don't hurt here. This stuff - * can be hard to get right. */ - - if (*num_glyphs < 0) { - status = _cairo_error (CAIRO_STATUS_NEGATIVE_COUNT); - goto DONE; - } - if (num_glyphs && *glyphs == NULL) { - status = _cairo_error (CAIRO_STATUS_NULL_POINTER); - goto DONE; - } - - if (clusters) { - if (*num_clusters < 0) { - status = _cairo_error (CAIRO_STATUS_NEGATIVE_COUNT); - goto DONE; - } - if (num_clusters && *clusters == NULL) { - status = _cairo_error (CAIRO_STATUS_NULL_POINTER); - goto DONE; - } - - /* Don't trust the backend, validate clusters! */ - status = - _cairo_validate_text_clusters (utf8, utf8_len, - *glyphs, *num_glyphs, - *clusters, *num_clusters, - *cluster_flags); - } - } - - goto DONE; - } - } - - if (*num_glyphs < num_chars) { - *glyphs = cairo_glyph_allocate (num_chars); - if (unlikely (*glyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto DONE; - } - } - *num_glyphs = num_chars; - - if (clusters) { - if (*num_clusters < num_chars) { - *clusters = cairo_text_cluster_allocate (num_chars); - if (unlikely (*clusters == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto DONE; - } - } - *num_clusters = num_chars; - } - - if (num_chars > CACHING_THRESHOLD) - status = cairo_scaled_font_text_to_glyphs_internal_cached (scaled_font, - x, y, - utf8, - *glyphs, - clusters, - num_chars); - else - status = cairo_scaled_font_text_to_glyphs_internal_uncached (scaled_font, - x, y, - utf8, - *glyphs, - clusters, - num_chars); - - DONE: /* error that should be logged on scaled_font happened */ - _cairo_scaled_font_thaw_cache (scaled_font); - - if (unlikely (status)) { - *num_glyphs = 0; - if (*glyphs != orig_glyphs) { - cairo_glyph_free (*glyphs); - *glyphs = orig_glyphs; - } - - if (clusters) { - *num_clusters = 0; - if (*clusters != orig_clusters) { - cairo_text_cluster_free (*clusters); - *clusters = orig_clusters; - } - } - } - - return _cairo_scaled_font_set_error (scaled_font, status); - - BAIL: /* error with input arguments */ - - if (num_glyphs) - *num_glyphs = 0; - - if (num_clusters) - *num_clusters = 0; - - return status; -} -slim_hidden_def (cairo_scaled_font_text_to_glyphs); - -static inline cairo_bool_t -_range_contains_glyph (const cairo_box_t *extents, - cairo_fixed_t left, - cairo_fixed_t top, - cairo_fixed_t right, - cairo_fixed_t bottom) -{ - if (left == right || top == bottom) - return FALSE; - - return right > extents->p1.x && - left < extents->p2.x && - bottom > extents->p1.y && - top < extents->p2.y; -} - -static cairo_status_t -_cairo_scaled_font_single_glyph_device_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyph, - cairo_rectangle_int_t *extents) -{ - cairo_scaled_glyph_t *scaled_glyph; - cairo_status_t status; - - _cairo_scaled_font_freeze_cache (scaled_font); - status = _cairo_scaled_glyph_lookup (scaled_font, - glyph->index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - cairo_bool_t round_xy = _cairo_font_options_get_round_glyph_positions (&scaled_font->options) == CAIRO_ROUND_GLYPH_POS_ON; - cairo_box_t box; - cairo_fixed_t v; - - if (round_xy) - v = _cairo_fixed_from_int (_cairo_lround (glyph->x)); - else - v = _cairo_fixed_from_double (glyph->x); - box.p1.x = v + scaled_glyph->bbox.p1.x; - box.p2.x = v + scaled_glyph->bbox.p2.x; - - if (round_xy) - v = _cairo_fixed_from_int (_cairo_lround (glyph->y)); - else - v = _cairo_fixed_from_double (glyph->y); - box.p1.y = v + scaled_glyph->bbox.p1.y; - box.p2.y = v + scaled_glyph->bbox.p2.y; - - _cairo_box_round_to_rectangle (&box, extents); - } - _cairo_scaled_font_thaw_cache (scaled_font); - return status; -} - -/* - * Compute a device-space bounding box for the glyphs. - */ -cairo_status_t -_cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_rectangle_int_t *extents, - cairo_bool_t *overlap_out) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_box_t box = { { INT_MAX, INT_MAX }, { INT_MIN, INT_MIN }}; - cairo_scaled_glyph_t *glyph_cache[64]; - cairo_bool_t overlap = overlap_out ? FALSE : TRUE; - cairo_round_glyph_positions_t round_glyph_positions = _cairo_font_options_get_round_glyph_positions (&scaled_font->options); - int i; - - if (unlikely (scaled_font->status)) - return scaled_font->status; - - if (num_glyphs == 1) { - if (overlap_out) - *overlap_out = FALSE; - return _cairo_scaled_font_single_glyph_device_extents (scaled_font, - glyphs, - extents); - } - - _cairo_scaled_font_freeze_cache (scaled_font); - - memset (glyph_cache, 0, sizeof (glyph_cache)); - - for (i = 0; i < num_glyphs; i++) { - cairo_scaled_glyph_t *scaled_glyph; - cairo_fixed_t x, y, x1, y1, x2, y2; - int cache_index = glyphs[i].index % ARRAY_LENGTH (glyph_cache); - - scaled_glyph = glyph_cache[cache_index]; - if (scaled_glyph == NULL || - _cairo_scaled_glyph_index (scaled_glyph) != glyphs[i].index) - { - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) - break; - - glyph_cache[cache_index] = scaled_glyph; - } - - if (round_glyph_positions == CAIRO_ROUND_GLYPH_POS_ON) - x = _cairo_fixed_from_int (_cairo_lround (glyphs[i].x)); - else - x = _cairo_fixed_from_double (glyphs[i].x); - x1 = x + scaled_glyph->bbox.p1.x; - x2 = x + scaled_glyph->bbox.p2.x; - - if (round_glyph_positions == CAIRO_ROUND_GLYPH_POS_ON) - y = _cairo_fixed_from_int (_cairo_lround (glyphs[i].y)); - else - y = _cairo_fixed_from_double (glyphs[i].y); - y1 = y + scaled_glyph->bbox.p1.y; - y2 = y + scaled_glyph->bbox.p2.y; - - if (overlap == FALSE) - overlap = _range_contains_glyph (&box, x1, y1, x2, y2); - - if (x1 < box.p1.x) box.p1.x = x1; - if (x2 > box.p2.x) box.p2.x = x2; - if (y1 < box.p1.y) box.p1.y = y1; - if (y2 > box.p2.y) box.p2.y = y2; - } - - _cairo_scaled_font_thaw_cache (scaled_font); - if (unlikely (status)) - return _cairo_scaled_font_set_error (scaled_font, status); - - if (box.p1.x < box.p2.x) { - _cairo_box_round_to_rectangle (&box, extents); - } else { - extents->x = extents->y = 0; - extents->width = extents->height = 0; - } - - if (overlap_out != NULL) - *overlap_out = overlap; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_bool_t -_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_rectangle_int_t *extents) -{ - double x0, x1, y0, y1, pad; - int i; - - /* If any of the factors are suspect (i.e. the font is broken), bail */ - if (scaled_font->fs_extents.max_x_advance == 0 || - scaled_font->fs_extents.height == 0 || - scaled_font->max_scale == 0) - { - return FALSE; - } - - assert (num_glyphs); - - x0 = x1 = glyphs[0].x; - y0 = y1 = glyphs[0].y; - for (i = 1; i < num_glyphs; i++) { - double g; - - g = glyphs[i].x; - if (g < x0) x0 = g; - if (g > x1) x1 = g; - - g = glyphs[i].y; - if (g < y0) y0 = g; - if (g > y1) y1 = g; - } - - pad = MAX(scaled_font->fs_extents.max_x_advance, - scaled_font->fs_extents.height); - pad *= scaled_font->max_scale; - - extents->x = floor (x0 - pad); - extents->width = ceil (x1 + pad) - extents->x; - extents->y = floor (y0 - pad); - extents->height = ceil (y1 + pad) - extents->y; - return TRUE; -} - -#if 0 -/* XXX win32 */ -cairo_status_t -_cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, - cairo_operator_t op, - const cairo_pattern_t *pattern, - cairo_surface_t *surface, - int source_x, - int source_y, - int dest_x, - int dest_y, - unsigned int width, - unsigned int height, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_region_t *clip_region) -{ - cairo_int_status_t status; - cairo_surface_t *mask = NULL; - cairo_format_t mask_format = CAIRO_FORMAT_A1; /* shut gcc up */ - cairo_surface_pattern_t mask_pattern; - int i; - - /* These operators aren't interpreted the same way by the backends; - * they are implemented in terms of other operators in cairo-gstate.c - */ - assert (op != CAIRO_OPERATOR_SOURCE && op != CAIRO_OPERATOR_CLEAR); - - if (scaled_font->status) - return scaled_font->status; - - if (!num_glyphs) - return CAIRO_STATUS_SUCCESS; - - if (scaled_font->backend->show_glyphs != NULL) { - int remaining_glyphs = num_glyphs; - status = scaled_font->backend->show_glyphs (scaled_font, - op, pattern, - surface, - source_x, source_y, - dest_x, dest_y, - width, height, - glyphs, num_glyphs, - clip_region, - &remaining_glyphs); - glyphs += num_glyphs - remaining_glyphs; - num_glyphs = remaining_glyphs; - if (remaining_glyphs == 0) - status = CAIRO_INT_STATUS_SUCCESS; - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return _cairo_scaled_font_set_error (scaled_font, status); - } - - /* Font display routine either does not exist or failed. */ - - _cairo_scaled_font_freeze_cache (scaled_font); - - for (i = 0; i < num_glyphs; i++) { - int x, y; - cairo_image_surface_t *glyph_surface; - cairo_scaled_glyph_t *scaled_glyph; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - - if (unlikely (status)) - goto CLEANUP_MASK; - - glyph_surface = scaled_glyph->surface; - - /* To start, create the mask using the format from the first - * glyph. Later we'll deal with different formats. */ - if (mask == NULL) { - mask_format = glyph_surface->format; - mask = cairo_image_surface_create (mask_format, width, height); - status = mask->status; - if (unlikely (status)) - goto CLEANUP_MASK; - } - - /* If we have glyphs of different formats, we "upgrade" the mask - * to the wider of the formats. */ - if (glyph_surface->format != mask_format && - _cairo_format_bits_per_pixel (mask_format) < - _cairo_format_bits_per_pixel (glyph_surface->format) ) - { - cairo_surface_t *new_mask; - - switch (glyph_surface->format) { - case CAIRO_FORMAT_ARGB32: - case CAIRO_FORMAT_A8: - case CAIRO_FORMAT_A1: - mask_format = glyph_surface->format; - break; - case CAIRO_FORMAT_RGB16_565: - case CAIRO_FORMAT_RGB24: - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_INVALID: - default: - ASSERT_NOT_REACHED; - mask_format = CAIRO_FORMAT_ARGB32; - break; - } - - new_mask = cairo_image_surface_create (mask_format, width, height); - status = new_mask->status; - if (unlikely (status)) { - cairo_surface_destroy (new_mask); - goto CLEANUP_MASK; - } - - _cairo_pattern_init_for_surface (&mask_pattern, mask); - /* Note that we only upgrade masks, i.e. A1 -> A8 -> ARGB32, so there is - * never any component alpha here. - */ - status = _cairo_surface_composite (CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - &mask_pattern.base, - new_mask, - 0, 0, - 0, 0, - 0, 0, - width, height, - NULL); - - _cairo_pattern_fini (&mask_pattern.base); - - if (unlikely (status)) { - cairo_surface_destroy (new_mask); - goto CLEANUP_MASK; - } - - cairo_surface_destroy (mask); - mask = new_mask; - } - - if (glyph_surface->width && glyph_surface->height) { - cairo_surface_pattern_t glyph_pattern; - - /* round glyph locations to the nearest pixel */ - /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ - x = _cairo_lround (glyphs[i].x - - glyph_surface->base.device_transform.x0); - y = _cairo_lround (glyphs[i].y - - glyph_surface->base.device_transform.y0); - - _cairo_pattern_init_for_surface (&glyph_pattern, - &glyph_surface->base); - if (mask_format == CAIRO_FORMAT_ARGB32) - glyph_pattern.base.has_component_alpha = TRUE; - - status = _cairo_surface_composite (CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - &glyph_pattern.base, - mask, - 0, 0, - 0, 0, - x - dest_x, y - dest_y, - glyph_surface->width, - glyph_surface->height, - NULL); - - _cairo_pattern_fini (&glyph_pattern.base); - - if (unlikely (status)) - goto CLEANUP_MASK; - } - } - - _cairo_pattern_init_for_surface (&mask_pattern, mask); - if (mask_format == CAIRO_FORMAT_ARGB32) - mask_pattern.base.has_component_alpha = TRUE; - - status = _cairo_surface_composite (op, pattern, &mask_pattern.base, - surface, - source_x, source_y, - 0, 0, - dest_x, dest_y, - width, height, - clip_region); - - _cairo_pattern_fini (&mask_pattern.base); - -CLEANUP_MASK: - _cairo_scaled_font_thaw_cache (scaled_font); - - if (mask != NULL) - cairo_surface_destroy (mask); - return _cairo_scaled_font_set_error (scaled_font, status); -} -#endif - -/* Add a single-device-unit rectangle to a path. */ -static cairo_status_t -_add_unit_rectangle_to_path (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y) -{ - cairo_status_t status; - - status = _cairo_path_fixed_move_to (path, x, y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_rel_line_to (path, - _cairo_fixed_from_int (1), - _cairo_fixed_from_int (0)); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_rel_line_to (path, - _cairo_fixed_from_int (0), - _cairo_fixed_from_int (1)); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_rel_line_to (path, - _cairo_fixed_from_int (-1), - _cairo_fixed_from_int (0)); - if (unlikely (status)) - return status; - - return _cairo_path_fixed_close_path (path); -} - -/** - * _trace_mask_to_path: - * @bitmap: An alpha mask (either %CAIRO_FORMAT_A1 or %CAIRO_FORMAT_A8) - * @path: An initialized path to hold the result - * - * Given a mask surface, (an alpha image), fill out the provided path - * so that when filled it would result in something that approximates - * the mask. - * - * Note: The current tracing code here is extremely primitive. It - * operates only on an A1 surface, (converting an A8 surface to A1 if - * necessary), and performs the tracing by drawing a little square - * around each pixel that is on in the mask. We do not pretend that - * this is a high-quality result. But we are leaving it up to someone - * who cares enough about getting a better result to implement - * something more sophisticated. - **/ -static cairo_status_t -_trace_mask_to_path (cairo_image_surface_t *mask, - cairo_path_fixed_t *path, - double tx, double ty) -{ - const uint8_t *row; - int rows, cols, bytes_per_row; - int x, y, bit; - double xoff, yoff; - cairo_fixed_t x0, y0; - cairo_fixed_t px, py; - cairo_status_t status; - - mask = _cairo_image_surface_coerce_to_format (mask, CAIRO_FORMAT_A1); - status = mask->base.status; - if (unlikely (status)) - return status; - - cairo_surface_get_device_offset (&mask->base, &xoff, &yoff); - x0 = _cairo_fixed_from_double (tx - xoff); - y0 = _cairo_fixed_from_double (ty - yoff); - - bytes_per_row = (mask->width + 7) / 8; - row = mask->data; - for (y = 0, rows = mask->height; rows--; row += mask->stride, y++) { - const uint8_t *byte_ptr = row; - x = 0; - py = _cairo_fixed_from_int (y); - for (cols = bytes_per_row; cols--; ) { - uint8_t byte = *byte_ptr++; - if (byte == 0) { - x += 8; - continue; - } - - byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (byte); - for (bit = 1 << 7; bit && x < mask->width; bit >>= 1, x++) { - if (byte & bit) { - px = _cairo_fixed_from_int (x); - status = _add_unit_rectangle_to_path (path, - px + x0, - py + y0); - if (unlikely (status)) - goto BAIL; - } - } - } - } - -BAIL: - cairo_surface_destroy (&mask->base); - - return status; -} - -cairo_status_t -_cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_path_fixed_t *path) -{ - cairo_int_status_t status; - int i; - - status = scaled_font->status; - if (unlikely (status)) - return status; - - _cairo_scaled_font_freeze_cache (scaled_font); - for (i = 0; i < num_glyphs; i++) { - cairo_scaled_glyph_t *scaled_glyph; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_PATH, - &scaled_glyph); - if (status == CAIRO_INT_STATUS_SUCCESS) { - status = _cairo_path_fixed_append (path, - scaled_glyph->path, - _cairo_fixed_from_double (glyphs[i].x), - _cairo_fixed_from_double (glyphs[i].y)); - - } else if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - /* If the font is incapable of providing a path, then we'll - * have to trace our own from a surface. - */ - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - if (unlikely (status)) - goto BAIL; - - status = _trace_mask_to_path (scaled_glyph->surface, path, - glyphs[i].x, glyphs[i].y); - } - - if (unlikely (status)) - goto BAIL; - } - BAIL: - _cairo_scaled_font_thaw_cache (scaled_font); - - return _cairo_scaled_font_set_error (scaled_font, status); -} - -/** - * _cairo_scaled_glyph_set_metrics: - * @scaled_glyph: a #cairo_scaled_glyph_t - * @scaled_font: a #cairo_scaled_font_t - * @fs_metrics: a #cairo_text_extents_t in font space - * - * _cairo_scaled_glyph_set_metrics() stores user space metrics - * for the specified glyph given font space metrics. It is - * called by the font backend when initializing a glyph with - * %CAIRO_SCALED_GLYPH_INFO_METRICS. - **/ -void -_cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_text_extents_t *fs_metrics) -{ - cairo_bool_t first = TRUE; - double hm, wm; - double min_user_x = 0.0, max_user_x = 0.0, min_user_y = 0.0, max_user_y = 0.0; - double min_device_x = 0.0, max_device_x = 0.0, min_device_y = 0.0, max_device_y = 0.0; - double device_x_advance, device_y_advance; - - scaled_glyph->fs_metrics = *fs_metrics; - - for (hm = 0.0; hm <= 1.0; hm += 1.0) - for (wm = 0.0; wm <= 1.0; wm += 1.0) { - double x, y; - - /* Transform this corner to user space */ - x = fs_metrics->x_bearing + fs_metrics->width * wm; - y = fs_metrics->y_bearing + fs_metrics->height * hm; - cairo_matrix_transform_point (&scaled_font->font_matrix, - &x, &y); - if (first) { - min_user_x = max_user_x = x; - min_user_y = max_user_y = y; - } else { - if (x < min_user_x) min_user_x = x; - if (x > max_user_x) max_user_x = x; - if (y < min_user_y) min_user_y = y; - if (y > max_user_y) max_user_y = y; - } - - /* Transform this corner to device space from glyph origin */ - x = fs_metrics->x_bearing + fs_metrics->width * wm; - y = fs_metrics->y_bearing + fs_metrics->height * hm; - cairo_matrix_transform_distance (&scaled_font->scale, - &x, &y); - - if (first) { - min_device_x = max_device_x = x; - min_device_y = max_device_y = y; - } else { - if (x < min_device_x) min_device_x = x; - if (x > max_device_x) max_device_x = x; - if (y < min_device_y) min_device_y = y; - if (y > max_device_y) max_device_y = y; - } - first = FALSE; - } - scaled_glyph->metrics.x_bearing = min_user_x; - scaled_glyph->metrics.y_bearing = min_user_y; - scaled_glyph->metrics.width = max_user_x - min_user_x; - scaled_glyph->metrics.height = max_user_y - min_user_y; - - scaled_glyph->metrics.x_advance = fs_metrics->x_advance; - scaled_glyph->metrics.y_advance = fs_metrics->y_advance; - cairo_matrix_transform_distance (&scaled_font->font_matrix, - &scaled_glyph->metrics.x_advance, - &scaled_glyph->metrics.y_advance); - - device_x_advance = fs_metrics->x_advance; - device_y_advance = fs_metrics->y_advance; - cairo_matrix_transform_distance (&scaled_font->scale, - &device_x_advance, - &device_y_advance); - - scaled_glyph->bbox.p1.x = _cairo_fixed_from_double (min_device_x); - scaled_glyph->bbox.p1.y = _cairo_fixed_from_double (min_device_y); - scaled_glyph->bbox.p2.x = _cairo_fixed_from_double (max_device_x); - scaled_glyph->bbox.p2.y = _cairo_fixed_from_double (max_device_y); - - scaled_glyph->x_advance = _cairo_lround (device_x_advance); - scaled_glyph->y_advance = _cairo_lround (device_y_advance); - - scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_METRICS; -} - -void -_cairo_scaled_glyph_set_surface (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_image_surface_t *surface) -{ - if (scaled_glyph->surface != NULL) - cairo_surface_destroy (&scaled_glyph->surface->base); - - /* sanity check the backend glyph contents */ - _cairo_debug_check_image_surface_is_defined (&surface->base); - scaled_glyph->surface = surface; - - if (surface != NULL) - scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_SURFACE; - else - scaled_glyph->has_info &= ~CAIRO_SCALED_GLYPH_INFO_SURFACE; -} - -void -_cairo_scaled_glyph_set_path (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_path_fixed_t *path) -{ - if (scaled_glyph->path != NULL) - _cairo_path_fixed_destroy (scaled_glyph->path); - - scaled_glyph->path = path; - - if (path != NULL) - scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_PATH; - else - scaled_glyph->has_info &= ~CAIRO_SCALED_GLYPH_INFO_PATH; -} - -void -_cairo_scaled_glyph_set_recording_surface (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_surface_t *recording_surface) -{ - if (scaled_glyph->recording_surface != NULL) { - cairo_surface_finish (scaled_glyph->recording_surface); - cairo_surface_destroy (scaled_glyph->recording_surface); - } - - scaled_glyph->recording_surface = recording_surface; - - if (recording_surface != NULL) - scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE; - else - scaled_glyph->has_info &= ~CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE; -} - -static cairo_bool_t -_cairo_scaled_glyph_page_can_remove (const void *closure) -{ - const cairo_scaled_glyph_page_t *page = closure; - const cairo_scaled_font_t *scaled_font; - - scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash; - return scaled_font->cache_frozen == 0; -} - -static cairo_status_t -_cairo_scaled_font_allocate_glyph (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_t **scaled_glyph) -{ - cairo_scaled_glyph_page_t *page; - cairo_status_t status; - - assert (scaled_font->cache_frozen); - - /* only the first page in the list may contain available slots */ - if (! cairo_list_is_empty (&scaled_font->glyph_pages)) { - page = cairo_list_last_entry (&scaled_font->glyph_pages, - cairo_scaled_glyph_page_t, - link); - if (page->num_glyphs < CAIRO_SCALED_GLYPH_PAGE_SIZE) { - *scaled_glyph = &page->glyphs[page->num_glyphs++]; - return CAIRO_STATUS_SUCCESS; - } - } - - page = malloc (sizeof (cairo_scaled_glyph_page_t)); - if (unlikely (page == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - page->cache_entry.hash = (unsigned long) scaled_font; - page->cache_entry.size = 1; /* XXX occupancy weighting? */ - page->num_glyphs = 0; - - CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); - if (scaled_font->global_cache_frozen == FALSE) { - if (unlikely (cairo_scaled_glyph_page_cache.hash_table == NULL)) { - status = _cairo_cache_init (&cairo_scaled_glyph_page_cache, - NULL, - _cairo_scaled_glyph_page_can_remove, - _cairo_scaled_glyph_page_pluck, - MAX_GLYPH_PAGES_CACHED); - if (unlikely (status)) { - CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); - free (page); - return status; - } - } - - _cairo_cache_freeze (&cairo_scaled_glyph_page_cache); - scaled_font->global_cache_frozen = TRUE; - } - - status = _cairo_cache_insert (&cairo_scaled_glyph_page_cache, - &page->cache_entry); - CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); - if (unlikely (status)) { - free (page); - return status; - } - - cairo_list_add_tail (&page->link, &scaled_font->glyph_pages); - - *scaled_glyph = &page->glyphs[page->num_glyphs++]; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_scaled_font_free_last_glyph (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_scaled_glyph_page_t *page; - - assert (! cairo_list_is_empty (&scaled_font->glyph_pages)); - page = cairo_list_last_entry (&scaled_font->glyph_pages, - cairo_scaled_glyph_page_t, - link); - assert (scaled_glyph == &page->glyphs[page->num_glyphs-1]); - - _cairo_scaled_glyph_fini (scaled_font, scaled_glyph); - - if (--page->num_glyphs == 0) { - CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); - /* Temporarily disconnect callback to avoid recursive locking */ - cairo_scaled_glyph_page_cache.entry_destroy = NULL; - _cairo_cache_remove (&cairo_scaled_glyph_page_cache, - &page->cache_entry); - _cairo_scaled_glyph_page_destroy (scaled_font, page); - cairo_scaled_glyph_page_cache.entry_destroy = _cairo_scaled_glyph_page_pluck; - CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); - } -} - -/** - * _cairo_scaled_glyph_lookup: - * @scaled_font: a #cairo_scaled_font_t - * @index: the glyph to create - * @info: a #cairo_scaled_glyph_info_t marking which portions of - * the glyph should be filled in. - * @scaled_glyph_ret: a #cairo_scaled_glyph_t where the glyph - * is returned. - * - * If the desired info is not available, (for example, when trying to - * get INFO_PATH with a bitmapped font), this function will return - * %CAIRO_INT_STATUS_UNSUPPORTED. - * - * Note: This function must be called with the scaled font frozen, and it must - * remain frozen for as long as the @scaled_glyph_ret is alive. (If the scaled - * font was not frozen, then there is no guarantee that the glyph would not be - * evicted before you tried to access it.) See - * _cairo_scaled_font_freeze_cache() and _cairo_scaled_font_thaw_cache(). - * - * Returns: a glyph with the requested portions filled in. Glyph - * lookup is cached and glyph will be automatically freed along - * with the scaled_font so no explicit free is required. - * @info can be one or more of: - * %CAIRO_SCALED_GLYPH_INFO_METRICS - glyph metrics and bounding box - * %CAIRO_SCALED_GLYPH_INFO_SURFACE - surface holding glyph image - * %CAIRO_SCALED_GLYPH_INFO_PATH - path holding glyph outline in device space - **/ -cairo_int_status_t -_cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font, - unsigned long index, - cairo_scaled_glyph_info_t info, - cairo_scaled_glyph_t **scaled_glyph_ret) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - cairo_scaled_glyph_t *scaled_glyph; - cairo_scaled_glyph_info_t need_info; - - *scaled_glyph_ret = NULL; - - if (unlikely (scaled_font->status)) - return scaled_font->status; - - assert (CAIRO_MUTEX_IS_LOCKED(scaled_font->mutex)); - assert (scaled_font->cache_frozen); - - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* - * Check cache for glyph - */ - scaled_glyph = _cairo_hash_table_lookup (scaled_font->glyphs, - (cairo_hash_entry_t *) &index); - if (scaled_glyph == NULL) { - status = _cairo_scaled_font_allocate_glyph (scaled_font, &scaled_glyph); - if (unlikely (status)) - goto err; - - memset (scaled_glyph, 0, sizeof (cairo_scaled_glyph_t)); - _cairo_scaled_glyph_set_index (scaled_glyph, index); - cairo_list_init (&scaled_glyph->dev_privates); - - /* ask backend to initialize metrics and shape fields */ - status = - scaled_font->backend->scaled_glyph_init (scaled_font, - scaled_glyph, - info | CAIRO_SCALED_GLYPH_INFO_METRICS); - if (unlikely (status)) { - _cairo_scaled_font_free_last_glyph (scaled_font, scaled_glyph); - goto err; - } - - status = _cairo_hash_table_insert (scaled_font->glyphs, - &scaled_glyph->hash_entry); - if (unlikely (status)) { - _cairo_scaled_font_free_last_glyph (scaled_font, scaled_glyph); - goto err; - } - } - - /* - * Check and see if the glyph, as provided, - * already has the requested data and amend it if not - */ - need_info = info & ~scaled_glyph->has_info; - if (need_info) { - status = scaled_font->backend->scaled_glyph_init (scaled_font, - scaled_glyph, - need_info); - if (unlikely (status)) - goto err; - - /* Don't trust the scaled_glyph_init() return value, the font - * backend may not even know about some of the info. For example, - * no backend other than the user-fonts knows about recording-surface - * glyph info. */ - if (info & ~scaled_glyph->has_info) - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - *scaled_glyph_ret = scaled_glyph; - return CAIRO_STATUS_SUCCESS; - -err: - /* It's not an error for the backend to not support the info we want. */ - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - status = _cairo_scaled_font_set_error (scaled_font, status); - return status; -} - -double -_cairo_scaled_font_get_max_scale (cairo_scaled_font_t *scaled_font) -{ - return scaled_font->max_scale; -} - - -/** - * cairo_scaled_font_get_font_face: - * @scaled_font: a #cairo_scaled_font_t - * - * Gets the font face that this scaled font uses. This might be the - * font face passed to cairo_scaled_font_create(), but this does not - * hold true for all possible cases. - * - * Return value: The #cairo_font_face_t with which @scaled_font was - * created. This object is owned by cairo. To keep a reference to it, - * you must call cairo_scaled_font_reference(). - * - * Since: 1.2 - **/ -cairo_font_face_t * -cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font) -{ - if (scaled_font->status) - return (cairo_font_face_t*) &_cairo_font_face_nil; - - if (scaled_font->original_font_face != NULL) - return scaled_font->original_font_face; - - return scaled_font->font_face; -} -slim_hidden_def (cairo_scaled_font_get_font_face); - -/** - * cairo_scaled_font_get_font_matrix: - * @scaled_font: a #cairo_scaled_font_t - * @font_matrix: return value for the matrix - * - * Stores the font matrix with which @scaled_font was created into - * @matrix. - * - * Since: 1.2 - **/ -void -cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *font_matrix) -{ - if (scaled_font->status) { - cairo_matrix_init_identity (font_matrix); - return; - } - - *font_matrix = scaled_font->font_matrix; -} -slim_hidden_def (cairo_scaled_font_get_font_matrix); - -/** - * cairo_scaled_font_get_ctm: - * @scaled_font: a #cairo_scaled_font_t - * @ctm: return value for the CTM - * - * Stores the CTM with which @scaled_font was created into @ctm. - * Note that the translation offsets (x0, y0) of the CTM are ignored - * by cairo_scaled_font_create(). So, the matrix this - * function returns always has 0,0 as x0,y0. - * - * Since: 1.2 - **/ -void -cairo_scaled_font_get_ctm (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *ctm) -{ - if (scaled_font->status) { - cairo_matrix_init_identity (ctm); - return; - } - - *ctm = scaled_font->ctm; -} -slim_hidden_def (cairo_scaled_font_get_ctm); - -/** - * cairo_scaled_font_get_scale_matrix: - * @scaled_font: a #cairo_scaled_font_t - * @scale_matrix: return value for the matrix - * - * Stores the scale matrix of @scaled_font into @matrix. - * The scale matrix is product of the font matrix and the ctm - * associated with the scaled font, and hence is the matrix mapping from - * font space to device space. - * - * Since: 1.8 - **/ -void -cairo_scaled_font_get_scale_matrix (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *scale_matrix) -{ - if (scaled_font->status) { - cairo_matrix_init_identity (scale_matrix); - return; - } - - *scale_matrix = scaled_font->scale; -} - -/** - * cairo_scaled_font_get_font_options: - * @scaled_font: a #cairo_scaled_font_t - * @options: return value for the font options - * - * Stores the font options with which @scaled_font was created into - * @options. - * - * Since: 1.2 - **/ -void -cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font, - cairo_font_options_t *options) -{ - if (cairo_font_options_status (options)) - return; - - if (scaled_font->status) { - _cairo_font_options_init_default (options); - return; - } - - _cairo_font_options_init_copy (options, &scaled_font->options); -} -slim_hidden_def (cairo_scaled_font_get_font_options); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-private.h deleted file mode 100644 index 5b506f500cd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-private.h +++ /dev/null @@ -1,59 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SCRIPT_PRIVATE_H -#define CAIRO_SCRIPT_PRIVATE_H - -#include "cairo.h" -#include "cairo-script.h" - -#include "cairo-compiler-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-types-private.h" - -CAIRO_BEGIN_DECLS - -cairo_private cairo_device_t * -_cairo_script_context_create_internal (cairo_output_stream_t *stream); - -cairo_private void -_cairo_script_context_attach_snapshots (cairo_device_t *device, - cairo_bool_t enable); - -slim_hidden_proto (cairo_script_surface_create); - -CAIRO_END_DECLS - -#endif /* CAIRO_SCRIPT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-surface.c deleted file mode 100644 index b84aed976f3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script-surface.c +++ /dev/null @@ -1,3999 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - */ - -/* The script surface is one that records all operations performed on - * it in the form of a procedural script, similar in fashion to - * PostScript but using Cairo's imaging model. In essence, this is - * equivalent to the recording-surface, but as there is no impedance mismatch - * between Cairo and CairoScript, we can generate output immediately - * without having to copy and hold the data in memory. - */ - -/** - * SECTION:cairo-script - * @Title: Script Surfaces - * @Short_Description: Rendering to replayable scripts - * @See_Also: #cairo_surface_t - * - * The script surface provides the ability to render to a native - * script that matches the cairo drawing model. The scripts can - * be replayed using tools under the util/cairo-script directoriy, - * or with cairo-perf-trace. - **/ - -/** - * CAIRO_HAS_SCRIPT_SURFACE: - * - * Defined if the script surface backend is available. - * The script surface backend is always built in since 1.12. - * - * Since: 1.12 - **/ - - -#include "cairoint.h" - -#include "cairo-script.h" -#include "cairo-script-private.h" - -#include "cairo-analysis-surface-private.h" -#include "cairo-default-context-private.h" -#include "cairo-device-private.h" -#include "cairo-error-private.h" -#include "cairo-list-inline.h" -#include "cairo-image-surface-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-pattern-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-scaled-font-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-private.h" -#include "cairo-surface-wrapper-private.h" - -#if CAIRO_HAS_FT_FONT -#include "cairo-ft-private.h" -#endif - -#include - -#ifdef WORDS_BIGENDIAN -#define to_be32(x) x -#else -#define to_be32(x) bswap_32(x) -#endif - -#define _cairo_output_stream_puts(S, STR) \ - _cairo_output_stream_write ((S), (STR), strlen (STR)) - -#define static cairo_warn static - -typedef struct _cairo_script_context cairo_script_context_t; -typedef struct _cairo_script_surface cairo_script_surface_t; -typedef struct _cairo_script_implicit_context cairo_script_implicit_context_t; -typedef struct _cairo_script_font cairo_script_font_t; - -typedef struct _operand { - enum { - SURFACE, - DEFERRED, - } type; - cairo_list_t link; -} operand_t; - - -struct deferred_finish { - cairo_list_t link; - operand_t operand; -}; - -struct _cairo_script_context { - cairo_device_t base; - - int active; - int attach_snapshots; - - cairo_bool_t owns_stream; - cairo_output_stream_t *stream; - cairo_script_mode_t mode; - - struct _bitmap { - unsigned long min; - unsigned long count; - unsigned int map[64]; - struct _bitmap *next; - } surface_id, font_id; - - cairo_list_t operands; - cairo_list_t deferred; - - cairo_list_t fonts; - cairo_list_t defines; -}; - -struct _cairo_script_font { - cairo_scaled_font_private_t base; - - cairo_bool_t has_sfnt; - unsigned long id; - unsigned long subset_glyph_index; - cairo_list_t link; - cairo_scaled_font_t *parent; -}; - -struct _cairo_script_implicit_context { - cairo_operator_t current_operator; - cairo_fill_rule_t current_fill_rule; - double current_tolerance; - cairo_antialias_t current_antialias; - cairo_stroke_style_t current_style; - cairo_pattern_union_t current_source; - cairo_matrix_t current_ctm; - cairo_matrix_t current_stroke_matrix; - cairo_matrix_t current_font_matrix; - cairo_font_options_t current_font_options; - cairo_scaled_font_t *current_scaled_font; - cairo_path_fixed_t current_path; - cairo_bool_t has_clip; -}; - -struct _cairo_script_surface { - cairo_surface_t base; - - cairo_surface_wrapper_t wrapper; - - cairo_surface_clipper_t clipper; - - operand_t operand; - cairo_bool_t emitted; - cairo_bool_t defined; - cairo_bool_t active; - - double width, height; - - /* implicit flattened context */ - cairo_script_implicit_context_t cr; -}; - -static const cairo_surface_backend_t _cairo_script_surface_backend; - -static cairo_script_surface_t * -_cairo_script_surface_create_internal (cairo_script_context_t *ctx, - cairo_content_t content, - cairo_rectangle_t *extents, - cairo_surface_t *passthrough); - -static void -_cairo_script_scaled_font_fini (cairo_scaled_font_private_t *abstract_private, - cairo_scaled_font_t *scaled_font); - -static void -_cairo_script_implicit_context_init (cairo_script_implicit_context_t *cr); - -static void -_cairo_script_implicit_context_reset (cairo_script_implicit_context_t *cr); - -static void -_bitmap_release_id (struct _bitmap *b, unsigned long token) -{ - struct _bitmap **prev = NULL; - - do { - if (token < b->min + sizeof (b->map) * CHAR_BIT) { - unsigned int bit, elem; - - token -= b->min; - elem = token / (sizeof (b->map[0]) * CHAR_BIT); - bit = token % (sizeof (b->map[0]) * CHAR_BIT); - b->map[elem] &= ~(1 << bit); - if (! --b->count && prev) { - *prev = b->next; - free (b); - } - return; - } - prev = &b->next; - b = b->next; - } while (b != NULL); -} - -static cairo_status_t -_bitmap_next_id (struct _bitmap *b, - unsigned long *id) -{ - struct _bitmap *bb, **prev = NULL; - unsigned long min = 0; - - do { - if (b->min != min) - break; - - if (b->count < sizeof (b->map) * CHAR_BIT) { - unsigned int n, m, bit; - for (n = 0; n < ARRAY_LENGTH (b->map); n++) { - if (b->map[n] == (unsigned int) -1) - continue; - - for (m=0, bit=1; mmap[0])*CHAR_BIT; m++, bit<<=1) { - if ((b->map[n] & bit) == 0) { - b->map[n] |= bit; - b->count++; - *id = n * sizeof (b->map[0])*CHAR_BIT + m + b->min; - return CAIRO_STATUS_SUCCESS; - } - } - } - } - min += sizeof (b->map) * CHAR_BIT; - - prev = &b->next; - b = b->next; - } while (b != NULL); - - bb = malloc (sizeof (struct _bitmap)); - if (unlikely (bb == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - *prev = bb; - bb->next = b; - bb->min = min; - bb->count = 1; - bb->map[0] = 0x1; - memset (bb->map + 1, 0, sizeof (bb->map) - sizeof (bb->map[0])); - *id = min; - - return CAIRO_STATUS_SUCCESS; -} - -static void -_bitmap_fini (struct _bitmap *b) -{ - while (b != NULL) { - struct _bitmap *next = b->next; - free (b); - b = next; - } -} - -static const char * -_direction_to_string (cairo_bool_t backward) -{ - static const char *names[] = { - "FORWARD", - "BACKWARD" - }; - assert (backward < ARRAY_LENGTH (names)); - return names[backward]; -} - -static const char * -_operator_to_string (cairo_operator_t op) -{ - static const char *names[] = { - "CLEAR", /* CAIRO_OPERATOR_CLEAR */ - - "SOURCE", /* CAIRO_OPERATOR_SOURCE */ - "OVER", /* CAIRO_OPERATOR_OVER */ - "IN", /* CAIRO_OPERATOR_IN */ - "OUT", /* CAIRO_OPERATOR_OUT */ - "ATOP", /* CAIRO_OPERATOR_ATOP */ - - "DEST", /* CAIRO_OPERATOR_DEST */ - "DEST_OVER", /* CAIRO_OPERATOR_DEST_OVER */ - "DEST_IN", /* CAIRO_OPERATOR_DEST_IN */ - "DEST_OUT", /* CAIRO_OPERATOR_DEST_OUT */ - "DEST_ATOP", /* CAIRO_OPERATOR_DEST_ATOP */ - - "XOR", /* CAIRO_OPERATOR_XOR */ - "ADD", /* CAIRO_OPERATOR_ADD */ - "SATURATE", /* CAIRO_OPERATOR_SATURATE */ - - "MULTIPLY", /* CAIRO_OPERATOR_MULTIPLY */ - "SCREEN", /* CAIRO_OPERATOR_SCREEN */ - "OVERLAY", /* CAIRO_OPERATOR_OVERLAY */ - "DARKEN", /* CAIRO_OPERATOR_DARKEN */ - "LIGHTEN", /* CAIRO_OPERATOR_LIGHTEN */ - "DODGE", /* CAIRO_OPERATOR_COLOR_DODGE */ - "BURN", /* CAIRO_OPERATOR_COLOR_BURN */ - "HARD_LIGHT", /* CAIRO_OPERATOR_HARD_LIGHT */ - "SOFT_LIGHT", /* CAIRO_OPERATOR_SOFT_LIGHT */ - "DIFFERENCE", /* CAIRO_OPERATOR_DIFFERENCE */ - "EXCLUSION", /* CAIRO_OPERATOR_EXCLUSION */ - "HSL_HUE", /* CAIRO_OPERATOR_HSL_HUE */ - "HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */ - "HSL_COLOR", /* CAIRO_OPERATOR_HSL_COLOR */ - "HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */ - }; - assert (op < ARRAY_LENGTH (names)); - return names[op]; -} - -static const char * -_extend_to_string (cairo_extend_t extend) -{ - static const char *names[] = { - "EXTEND_NONE", /* CAIRO_EXTEND_NONE */ - "EXTEND_REPEAT", /* CAIRO_EXTEND_REPEAT */ - "EXTEND_REFLECT", /* CAIRO_EXTEND_REFLECT */ - "EXTEND_PAD" /* CAIRO_EXTEND_PAD */ - }; - assert (extend < ARRAY_LENGTH (names)); - return names[extend]; -} - -static const char * -_filter_to_string (cairo_filter_t filter) -{ - static const char *names[] = { - "FILTER_FAST", /* CAIRO_FILTER_FAST */ - "FILTER_GOOD", /* CAIRO_FILTER_GOOD */ - "FILTER_BEST", /* CAIRO_FILTER_BEST */ - "FILTER_NEAREST", /* CAIRO_FILTER_NEAREST */ - "FILTER_BILINEAR", /* CAIRO_FILTER_BILINEAR */ - "FILTER_GAUSSIAN", /* CAIRO_FILTER_GAUSSIAN */ - }; - assert (filter < ARRAY_LENGTH (names)); - return names[filter]; -} - -static const char * -_fill_rule_to_string (cairo_fill_rule_t rule) -{ - static const char *names[] = { - "WINDING", /* CAIRO_FILL_RULE_WINDING */ - "EVEN_ODD" /* CAIRO_FILL_RILE_EVEN_ODD */ - }; - assert (rule < ARRAY_LENGTH (names)); - return names[rule]; -} - -static const char * -_antialias_to_string (cairo_antialias_t antialias) -{ - static const char *names[] = { - "ANTIALIAS_DEFAULT", /* CAIRO_ANTIALIAS_DEFAULT */ - "ANTIALIAS_NONE", /* CAIRO_ANTIALIAS_NONE */ - "ANTIALIAS_GRAY", /* CAIRO_ANTIALIAS_GRAY */ - "ANTIALIAS_SUBPIXEL", /* CAIRO_ANTIALIAS_SUBPIXEL */ - "ANTIALIAS_FAST", /* CAIRO_ANTIALIAS_FAST */ - "ANTIALIAS_GOOD", /* CAIRO_ANTIALIAS_GOOD */ - "ANTIALIAS_BEST" /* CAIRO_ANTIALIAS_BEST */ - }; - assert (antialias < ARRAY_LENGTH (names)); - return names[antialias]; -} - -static const char * -_line_cap_to_string (cairo_line_cap_t line_cap) -{ - static const char *names[] = { - "LINE_CAP_BUTT", /* CAIRO_LINE_CAP_BUTT */ - "LINE_CAP_ROUND", /* CAIRO_LINE_CAP_ROUND */ - "LINE_CAP_SQUARE" /* CAIRO_LINE_CAP_SQUARE */ - }; - assert (line_cap < ARRAY_LENGTH (names)); - return names[line_cap]; -} - -static const char * -_line_join_to_string (cairo_line_join_t line_join) -{ - static const char *names[] = { - "LINE_JOIN_MITER", /* CAIRO_LINE_JOIN_MITER */ - "LINE_JOIN_ROUND", /* CAIRO_LINE_JOIN_ROUND */ - "LINE_JOIN_BEVEL", /* CAIRO_LINE_JOIN_BEVEL */ - }; - assert (line_join < ARRAY_LENGTH (names)); - return names[line_join]; -} - -static inline cairo_script_context_t * -to_context (cairo_script_surface_t *surface) -{ - return (cairo_script_context_t *) surface->base.device; -} - -static cairo_bool_t -target_is_active (cairo_script_surface_t *surface) -{ - return cairo_list_is_first (&surface->operand.link, - &to_context (surface)->operands); -} - -static void -target_push (cairo_script_surface_t *surface) -{ - cairo_list_move (&surface->operand.link, &to_context (surface)->operands); -} - -static int -target_depth (cairo_script_surface_t *surface) -{ - cairo_list_t *link; - int depth = 0; - - cairo_list_foreach (link, &to_context (surface)->operands) { - if (link == &surface->operand.link) - break; - depth++; - } - - return depth; -} - -static void -_get_target (cairo_script_surface_t *surface) -{ - cairo_script_context_t *ctx = to_context (surface); - - if (target_is_active (surface)) { - _cairo_output_stream_puts (ctx->stream, "dup "); - return; - } - - if (surface->defined) { - _cairo_output_stream_printf (ctx->stream, "s%u ", - surface->base.unique_id); - } else { - int depth = target_depth (surface); - - assert (! cairo_list_is_empty (&surface->operand.link)); - assert (! target_is_active (surface)); - - if (ctx->active) { - _cairo_output_stream_printf (ctx->stream, "%d index ", depth); - _cairo_output_stream_puts (ctx->stream, "/target get exch pop "); - } else { - if (depth == 1) { - _cairo_output_stream_puts (ctx->stream, "exch "); - } else { - _cairo_output_stream_printf (ctx->stream, - "%d -1 roll ", depth); - } - target_push (surface); - _cairo_output_stream_puts (ctx->stream, "dup "); - } - } -} - -static const char * -_content_to_string (cairo_content_t content) -{ - switch (content) { - case CAIRO_CONTENT_ALPHA: return "ALPHA"; - case CAIRO_CONTENT_COLOR: return "COLOR"; - default: - case CAIRO_CONTENT_COLOR_ALPHA: return "COLOR_ALPHA"; - } -} - -static cairo_status_t -_emit_surface (cairo_script_surface_t *surface) -{ - cairo_script_context_t *ctx = to_context (surface); - - _cairo_output_stream_printf (ctx->stream, - "<< /content //%s", - _content_to_string (surface->base.content)); - if (surface->width != -1 && surface->height != -1) { - _cairo_output_stream_printf (ctx->stream, - " /width %f /height %f", - surface->width, - surface->height); - } - - if (surface->base.x_fallback_resolution != - CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT || - surface->base.y_fallback_resolution != - CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT) - { - _cairo_output_stream_printf (ctx->stream, - " /fallback-resolution [%f %f]", - surface->base.x_fallback_resolution, - surface->base.y_fallback_resolution); - } - - if (surface->base.device_transform.x0 != 0. || - surface->base.device_transform.y0 != 0.) - { - /* XXX device offset is encoded into the pattern matrices etc. */ - if (0) { - _cairo_output_stream_printf (ctx->stream, - " /device-offset [%f %f]", - surface->base.device_transform.x0, - surface->base.device_transform.y0); - } - } - - _cairo_output_stream_puts (ctx->stream, " >> surface context\n"); - surface->emitted = TRUE; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_context (cairo_script_surface_t *surface) -{ - cairo_script_context_t *ctx = to_context (surface); - - if (target_is_active (surface)) - return CAIRO_STATUS_SUCCESS; - - while (! cairo_list_is_empty (&ctx->operands)) { - operand_t *op; - cairo_script_surface_t *old; - - op = cairo_list_first_entry (&ctx->operands, - operand_t, - link); - if (op->type == DEFERRED) - break; - - old = cairo_container_of (op, cairo_script_surface_t, operand); - if (old == surface) - break; - if (old->active) - break; - - if (! old->defined) { - assert (old->emitted); - _cairo_output_stream_printf (ctx->stream, - "/target get /s%u exch def pop\n", - old->base.unique_id); - old->defined = TRUE; - } else { - _cairo_output_stream_puts (ctx->stream, "pop\n"); - } - - cairo_list_del (&old->operand.link); - } - - if (target_is_active (surface)) - return CAIRO_STATUS_SUCCESS; - - if (! surface->emitted) { - cairo_status_t status; - - status = _emit_surface (surface); - if (unlikely (status)) - return status; - } else if (cairo_list_is_empty (&surface->operand.link)) { - assert (surface->defined); - _cairo_output_stream_printf (ctx->stream, - "s%u context\n", - surface->base.unique_id); - _cairo_script_implicit_context_reset (&surface->cr); - _cairo_surface_clipper_reset (&surface->clipper); - } else { - int depth = target_depth (surface); - if (depth == 1) { - _cairo_output_stream_puts (ctx->stream, "exch\n"); - } else { - _cairo_output_stream_printf (ctx->stream, - "%d -1 roll\n", - depth); - } - } - target_push (surface); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_operator (cairo_script_surface_t *surface, - cairo_operator_t op) -{ - assert (target_is_active (surface)); - - if (surface->cr.current_operator == op) - return CAIRO_STATUS_SUCCESS; - - surface->cr.current_operator = op; - - _cairo_output_stream_printf (to_context (surface)->stream, - "//%s set-operator\n", - _operator_to_string (op)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_fill_rule (cairo_script_surface_t *surface, - cairo_fill_rule_t fill_rule) -{ - assert (target_is_active (surface)); - - if (surface->cr.current_fill_rule == fill_rule) - return CAIRO_STATUS_SUCCESS; - - surface->cr.current_fill_rule = fill_rule; - - _cairo_output_stream_printf (to_context (surface)->stream, - "//%s set-fill-rule\n", - _fill_rule_to_string (fill_rule)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_tolerance (cairo_script_surface_t *surface, - double tolerance, - cairo_bool_t force) -{ - assert (target_is_active (surface)); - - if ((! force || - fabs (tolerance - CAIRO_GSTATE_TOLERANCE_DEFAULT) < 1e-5) && - surface->cr.current_tolerance == tolerance) - { - return CAIRO_STATUS_SUCCESS; - } - - surface->cr.current_tolerance = tolerance; - - _cairo_output_stream_printf (to_context (surface)->stream, - "%f set-tolerance\n", - tolerance); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_antialias (cairo_script_surface_t *surface, - cairo_antialias_t antialias) -{ - assert (target_is_active (surface)); - - if (surface->cr.current_antialias == antialias) - return CAIRO_STATUS_SUCCESS; - - surface->cr.current_antialias = antialias; - - _cairo_output_stream_printf (to_context (surface)->stream, - "//%s set-antialias\n", - _antialias_to_string (antialias)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_line_width (cairo_script_surface_t *surface, - double line_width, - cairo_bool_t force) -{ - assert (target_is_active (surface)); - - if ((! force || - fabs (line_width - CAIRO_GSTATE_LINE_WIDTH_DEFAULT) < 1e-5) && - surface->cr.current_style.line_width == line_width) - { - return CAIRO_STATUS_SUCCESS; - } - - surface->cr.current_style.line_width = line_width; - - _cairo_output_stream_printf (to_context (surface)->stream, - "%f set-line-width\n", - line_width); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_line_cap (cairo_script_surface_t *surface, - cairo_line_cap_t line_cap) -{ - assert (target_is_active (surface)); - - if (surface->cr.current_style.line_cap == line_cap) - return CAIRO_STATUS_SUCCESS; - - surface->cr.current_style.line_cap = line_cap; - - _cairo_output_stream_printf (to_context (surface)->stream, - "//%s set-line-cap\n", - _line_cap_to_string (line_cap)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_line_join (cairo_script_surface_t *surface, - cairo_line_join_t line_join) -{ - assert (target_is_active (surface)); - - if (surface->cr.current_style.line_join == line_join) - return CAIRO_STATUS_SUCCESS; - - surface->cr.current_style.line_join = line_join; - - _cairo_output_stream_printf (to_context (surface)->stream, - "//%s set-line-join\n", - _line_join_to_string (line_join)); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_miter_limit (cairo_script_surface_t *surface, - double miter_limit, - cairo_bool_t force) -{ - assert (target_is_active (surface)); - - if ((! force || - fabs (miter_limit - CAIRO_GSTATE_MITER_LIMIT_DEFAULT) < 1e-5) && - surface->cr.current_style.miter_limit == miter_limit) - { - return CAIRO_STATUS_SUCCESS; - } - - surface->cr.current_style.miter_limit = miter_limit; - - _cairo_output_stream_printf (to_context (surface)->stream, - "%f set-miter-limit\n", - miter_limit); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_dashes_equal (const double *a, const double *b, int num_dashes) -{ - while (num_dashes--) { - if (fabs (*a - *b) > 1e-5) - return FALSE; - a++, b++; - } - - return TRUE; -} - -static cairo_status_t -_emit_dash (cairo_script_surface_t *surface, - const double *dash, - unsigned int num_dashes, - double offset, - cairo_bool_t force) -{ - unsigned int n; - - assert (target_is_active (surface)); - - if (force && - num_dashes == 0 && - surface->cr.current_style.num_dashes == 0) - { - return CAIRO_STATUS_SUCCESS; - } - - if (! force && - (surface->cr.current_style.num_dashes == num_dashes && - (num_dashes == 0 || - (fabs (surface->cr.current_style.dash_offset - offset) < 1e-5 && - _dashes_equal (surface->cr.current_style.dash, dash, num_dashes))))) - { - return CAIRO_STATUS_SUCCESS; - } - - - if (num_dashes) { - surface->cr.current_style.dash = _cairo_realloc_ab - (surface->cr.current_style.dash, num_dashes, sizeof (double)); - if (unlikely (surface->cr.current_style.dash == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (surface->cr.current_style.dash, dash, - sizeof (double) * num_dashes); - } else { - free (surface->cr.current_style.dash); - surface->cr.current_style.dash = NULL; - } - - surface->cr.current_style.num_dashes = num_dashes; - surface->cr.current_style.dash_offset = offset; - - _cairo_output_stream_puts (to_context (surface)->stream, "["); - for (n = 0; n < num_dashes; n++) { - _cairo_output_stream_printf (to_context (surface)->stream, "%f", dash[n]); - if (n < num_dashes-1) - _cairo_output_stream_puts (to_context (surface)->stream, " "); - } - _cairo_output_stream_printf (to_context (surface)->stream, - "] %f set-dash\n", - offset); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_stroke_style (cairo_script_surface_t *surface, - const cairo_stroke_style_t *style, - cairo_bool_t force) -{ - cairo_status_t status; - - assert (target_is_active (surface)); - - status = _emit_line_width (surface, style->line_width, force); - if (unlikely (status)) - return status; - - status = _emit_line_cap (surface, style->line_cap); - if (unlikely (status)) - return status; - - status = _emit_line_join (surface, style->line_join); - if (unlikely (status)) - return status; - - status = _emit_miter_limit (surface, style->miter_limit, force); - if (unlikely (status)) - return status; - - status = _emit_dash (surface, - style->dash, style->num_dashes, style->dash_offset, - force); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static const char * -_format_to_string (cairo_format_t format) -{ - switch (format) { - case CAIRO_FORMAT_ARGB32: return "ARGB32"; - case CAIRO_FORMAT_RGB30: return "RGB30"; - case CAIRO_FORMAT_RGB24: return "RGB24"; - case CAIRO_FORMAT_RGB16_565: return "RGB16_565"; - case CAIRO_FORMAT_A8: return "A8"; - case CAIRO_FORMAT_A1: return "A1"; - case CAIRO_FORMAT_INVALID: return "INVALID"; - } - ASSERT_NOT_REACHED; - return "INVALID"; -} - -static cairo_status_t -_emit_solid_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; - cairo_script_context_t *ctx = to_context (surface); - - if (! CAIRO_COLOR_IS_OPAQUE (&solid->color)) - { - if (! (surface->base.content & CAIRO_CONTENT_COLOR) || - ((solid->color.red_short == 0 || solid->color.red_short == 0xffff) && - (solid->color.green_short == 0 || solid->color.green_short == 0xffff) && - (solid->color.blue_short == 0 || solid->color.blue_short == 0xffff) )) - { - _cairo_output_stream_printf (ctx->stream, - "%f a", - solid->color.alpha); - } - else - { - _cairo_output_stream_printf (ctx->stream, - "%f %f %f %f rgba", - solid->color.red, - solid->color.green, - solid->color.blue, - solid->color.alpha); - } - } - else - { - if (solid->color.red_short == solid->color.green_short && - solid->color.red_short == solid->color.blue_short) - { - _cairo_output_stream_printf (ctx->stream, - "%f g", - solid->color.red); - } - else - { - _cairo_output_stream_printf (ctx->stream, - "%f %f %f rgb", - solid->color.red, - solid->color.green, - solid->color.blue); - } - } - - return CAIRO_STATUS_SUCCESS; -} - - -static cairo_status_t -_emit_gradient_color_stops (cairo_gradient_pattern_t *gradient, - cairo_output_stream_t *output) -{ - unsigned int n; - - for (n = 0; n < gradient->n_stops; n++) { - _cairo_output_stream_printf (output, - "\n %f %f %f %f %f add-color-stop", - gradient->stops[n].offset, - gradient->stops[n].color.red, - gradient->stops[n].color.green, - gradient->stops[n].color.blue, - gradient->stops[n].color.alpha); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_linear_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_linear_pattern_t *linear; - - linear = (cairo_linear_pattern_t *) pattern; - - _cairo_output_stream_printf (ctx->stream, - "%f %f %f %f linear", - linear->pd1.x, linear->pd1.y, - linear->pd2.x, linear->pd2.y); - return _emit_gradient_color_stops (&linear->base, ctx->stream); -} - -static cairo_status_t -_emit_radial_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_radial_pattern_t *radial; - - radial = (cairo_radial_pattern_t *) pattern; - - _cairo_output_stream_printf (ctx->stream, - "%f %f %f %f %f %f radial", - radial->cd1.center.x, - radial->cd1.center.y, - radial->cd1.radius, - radial->cd2.center.x, - radial->cd2.center.y, - radial->cd2.radius); - return _emit_gradient_color_stops (&radial->base, ctx->stream); -} - -static cairo_status_t -_emit_mesh_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_pattern_t *mesh; - cairo_status_t status; - unsigned int i, n; - - mesh = (cairo_pattern_t *) pattern; - status = cairo_mesh_pattern_get_patch_count (mesh, &n); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (ctx->stream, "mesh"); - for (i = 0; i < n; i++) { - cairo_path_t *path; - cairo_path_data_t *data; - int j; - - _cairo_output_stream_printf (ctx->stream, "\n begin-patch"); - - path = cairo_mesh_pattern_get_path (mesh, i); - if (unlikely (path->status)) - return path->status; - - for (j = 0; j < path->num_data; j+=data[0].header.length) { - data = &path->data[j]; - switch (data->header.type) { - case CAIRO_PATH_MOVE_TO: - _cairo_output_stream_printf (ctx->stream, - "\n %f %f m", - data[1].point.x, data[1].point.y); - break; - case CAIRO_PATH_LINE_TO: - _cairo_output_stream_printf (ctx->stream, - "\n %f %f l", - data[1].point.x, data[1].point.y); - break; - case CAIRO_PATH_CURVE_TO: - _cairo_output_stream_printf (ctx->stream, - "\n %f %f %f %f %f %f c", - data[1].point.x, data[1].point.y, - data[2].point.x, data[2].point.y, - data[3].point.x, data[3].point.y); - break; - case CAIRO_PATH_CLOSE_PATH: - break; - } - } - cairo_path_destroy (path); - - for (j = 0; j < 4; j++) { - double x, y; - - status = cairo_mesh_pattern_get_control_point (mesh, i, j, &x, &y); - if (unlikely (status)) - return status; - _cairo_output_stream_printf (ctx->stream, - "\n %d %f %f set-control-point", - j, x, y); - } - - for (j = 0; j < 4; j++) { - double r, g, b, a; - - status = cairo_mesh_pattern_get_corner_color_rgba (mesh, i, j, &r, &g, &b, &a); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (ctx->stream, - "\n %d %f %f %f %f set-corner-color", - j, r, g, b, a); - } - - _cairo_output_stream_printf (ctx->stream, "\n end-patch"); - } - - return CAIRO_STATUS_SUCCESS; -} - -struct script_snapshot { - cairo_surface_t base; -}; - -static cairo_status_t -script_snapshot_finish (void *abstract_surface) -{ - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t script_snapshot_backend = { - CAIRO_SURFACE_TYPE_SCRIPT, - script_snapshot_finish, -}; - -static void -detach_snapshot (cairo_surface_t *abstract_surface) -{ - cairo_script_surface_t *surface = (cairo_script_surface_t *)abstract_surface; - cairo_script_context_t *ctx = to_context (surface); - - _cairo_output_stream_printf (ctx->stream, - "/s%d undef\n", - surface->base.unique_id); -} - -static void -attach_snapshot (cairo_script_context_t *ctx, - cairo_surface_t *source) -{ - struct script_snapshot *surface; - - if (! ctx->attach_snapshots) - return; - - surface = malloc (sizeof (*surface)); - if (unlikely (surface == NULL)) - return; - - _cairo_surface_init (&surface->base, - &script_snapshot_backend, - &ctx->base, - source->content); - - _cairo_output_stream_printf (ctx->stream, - "dup /s%d exch def ", - surface->base.unique_id); - - _cairo_surface_attach_snapshot (source, &surface->base, detach_snapshot); - cairo_surface_destroy (&surface->base); -} - -static cairo_status_t -_emit_recording_surface_pattern (cairo_script_surface_t *surface, - cairo_recording_surface_t *source) -{ - cairo_script_implicit_context_t old_cr; - cairo_script_context_t *ctx = to_context (surface); - cairo_script_surface_t *similar; - cairo_surface_t *snapshot; - cairo_rectangle_t r, *extents; - cairo_status_t status; - - snapshot = _cairo_surface_has_snapshot (&source->base, &script_snapshot_backend); - if (snapshot) { - _cairo_output_stream_printf (ctx->stream, "s%d", snapshot->unique_id); - return CAIRO_INT_STATUS_SUCCESS; - } - - extents = NULL; - if (_cairo_recording_surface_get_bounds (&source->base, &r)) - extents = &r; - - similar = _cairo_script_surface_create_internal (ctx, - source->base.content, - extents, - NULL); - if (unlikely (similar->base.status)) - return similar->base.status; - - similar->base.is_clear = TRUE; - - _cairo_output_stream_printf (ctx->stream, "//%s ", - _content_to_string (source->base.content)); - if (extents) { - _cairo_output_stream_printf (ctx->stream, "[%f %f %f %f]", - extents->x, extents->y, - extents->width, extents->height); - } else - _cairo_output_stream_puts (ctx->stream, "[]"); - _cairo_output_stream_puts (ctx->stream, " record\n"); - - attach_snapshot (ctx, &source->base); - - _cairo_output_stream_puts (ctx->stream, "dup context\n"); - - target_push (similar); - similar->emitted = TRUE; - - - old_cr = surface->cr; - _cairo_script_implicit_context_init (&surface->cr); - status = _cairo_recording_surface_replay (&source->base, &similar->base); - surface->cr = old_cr; - - if (unlikely (status)) { - cairo_surface_destroy (&similar->base); - return status; - } - - cairo_list_del (&similar->operand.link); - assert (target_is_active (surface)); - - _cairo_output_stream_puts (ctx->stream, "pop "); - cairo_surface_destroy (&similar->base); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_script_surface_pattern (cairo_script_surface_t *surface, - cairo_script_surface_t *source) -{ - _get_target (source); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_write_image_surface (cairo_output_stream_t *output, - const cairo_image_surface_t *image) -{ - int stride, row, width; - uint8_t row_stack[CAIRO_STACK_BUFFER_SIZE]; - uint8_t *rowdata; - uint8_t *data; - - stride = image->stride; - width = image->width; - data = image->data; -#if WORDS_BIGENDIAN - switch (image->format) { - case CAIRO_FORMAT_A1: - for (row = image->height; row--; ) { - _cairo_output_stream_write (output, data, (width+7)/8); - data += stride; - } - break; - case CAIRO_FORMAT_A8: - for (row = image->height; row--; ) { - _cairo_output_stream_write (output, data, width); - data += stride; - } - break; - case CAIRO_FORMAT_RGB16_565: - for (row = image->height; row--; ) { - _cairo_output_stream_write (output, data, 2*width); - data += stride; - } - break; - case CAIRO_FORMAT_RGB24: - for (row = image->height; row--; ) { - int col; - rowdata = data; - for (col = width; col--; ) { - _cairo_output_stream_write (output, rowdata, 3); - rowdata+=4; - } - data += stride; - } - break; - case CAIRO_FORMAT_ARGB32: - for (row = image->height; row--; ) { - _cairo_output_stream_write (output, data, 4*width); - data += stride; - } - break; - case CAIRO_FORMAT_INVALID: - default: - ASSERT_NOT_REACHED; - break; - } -#else - if (stride > ARRAY_LENGTH (row_stack)) { - rowdata = malloc (stride); - if (unlikely (rowdata == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - rowdata = row_stack; - - switch (image->format) { - case CAIRO_FORMAT_A1: - for (row = image->height; row--; ) { - int col; - for (col = 0; col < (width + 7)/8; col++) - rowdata[col] = CAIRO_BITSWAP8 (data[col]); - _cairo_output_stream_write (output, rowdata, (width+7)/8); - data += stride; - } - break; - case CAIRO_FORMAT_A8: - for (row = image->height; row--; ) { - _cairo_output_stream_write (output, data, width); - data += stride; - } - break; - case CAIRO_FORMAT_RGB16_565: - for (row = image->height; row--; ) { - uint16_t *src = (uint16_t *) data; - uint16_t *dst = (uint16_t *) rowdata; - int col; - for (col = 0; col < width; col++) - dst[col] = bswap_16 (src[col]); - _cairo_output_stream_write (output, rowdata, 2*width); - data += stride; - } - break; - case CAIRO_FORMAT_RGB24: - for (row = image->height; row--; ) { - uint8_t *src = data; - int col; - for (col = 0; col < width; col++) { - rowdata[3*col+2] = *src++; - rowdata[3*col+1] = *src++; - rowdata[3*col+0] = *src++; - src++; - } - _cairo_output_stream_write (output, rowdata, 3*width); - data += stride; - } - break; - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_ARGB32: - for (row = image->height; row--; ) { - uint32_t *src = (uint32_t *) data; - uint32_t *dst = (uint32_t *) rowdata; - int col; - for (col = 0; col < width; col++) - dst[col] = bswap_32 (src[col]); - _cairo_output_stream_write (output, rowdata, 4*width); - data += stride; - } - break; - case CAIRO_FORMAT_INVALID: - default: - ASSERT_NOT_REACHED; - break; - } - if (rowdata != row_stack) - free (rowdata); -#endif - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_png_surface (cairo_script_surface_t *surface, - cairo_image_surface_t *image) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_output_stream_t *base85_stream; - cairo_status_t status; - const uint8_t *mime_data; - unsigned long mime_data_length; - - cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_PNG, - &mime_data, &mime_data_length); - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_output_stream_printf (ctx->stream, - "<< " - "/width %d " - "/height %d " - "/format //%s " - "/mime-type (image/png) " - "/source <~", - image->width, image->height, - _format_to_string (image->format)); - - base85_stream = _cairo_base85_stream_create (ctx->stream); - _cairo_output_stream_write (base85_stream, mime_data, mime_data_length); - status = _cairo_output_stream_destroy (base85_stream); - if (unlikely (status)) - return status; - - _cairo_output_stream_puts (ctx->stream, "~> >> image "); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_image_surface (cairo_script_surface_t *surface, - cairo_image_surface_t *image) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_output_stream_t *base85_stream; - cairo_output_stream_t *zlib_stream; - cairo_int_status_t status, status2; - cairo_surface_t *snapshot; - const uint8_t *mime_data; - unsigned long mime_data_length; - - snapshot = _cairo_surface_has_snapshot (&image->base, - &script_snapshot_backend); - if (snapshot) { - _cairo_output_stream_printf (ctx->stream, "s%u ", snapshot->unique_id); - return CAIRO_INT_STATUS_SUCCESS; - } - - status = _emit_png_surface (surface, image); - if (_cairo_int_status_is_error (status)) { - return status; - } else if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_image_surface_t *clone; - uint32_t len; - - if (image->format == CAIRO_FORMAT_INVALID) { - clone = _cairo_image_surface_coerce (image); - } else { - clone = (cairo_image_surface_t *) - cairo_surface_reference (&image->base); - } - - _cairo_output_stream_printf (ctx->stream, - "<< " - "/width %d " - "/height %d " - "/format //%s " - "/source ", - clone->width, clone->height, - _format_to_string (clone->format)); - - switch (clone->format) { - case CAIRO_FORMAT_A1: - len = (clone->width + 7)/8; - break; - case CAIRO_FORMAT_A8: - len = clone->width; - break; - case CAIRO_FORMAT_RGB16_565: - len = clone->width * 2; - break; - case CAIRO_FORMAT_RGB24: - len = clone->width * 3; - break; - case CAIRO_FORMAT_RGB30: - case CAIRO_FORMAT_ARGB32: - len = clone->width * 4; - break; - case CAIRO_FORMAT_INVALID: - default: - ASSERT_NOT_REACHED; - len = 0; - break; - } - len *= clone->height; - - if (len > 24) { - _cairo_output_stream_puts (ctx->stream, "<|"); - - base85_stream = _cairo_base85_stream_create (ctx->stream); - - len = to_be32 (len); - _cairo_output_stream_write (base85_stream, &len, sizeof (len)); - - zlib_stream = _cairo_deflate_stream_create (base85_stream); - status = _write_image_surface (zlib_stream, clone); - - status2 = _cairo_output_stream_destroy (zlib_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - status2 = _cairo_output_stream_destroy (base85_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - if (unlikely (status)) - return status; - } else { - _cairo_output_stream_puts (ctx->stream, "<~"); - - base85_stream = _cairo_base85_stream_create (ctx->stream); - status = _write_image_surface (base85_stream, clone); - status2 = _cairo_output_stream_destroy (base85_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - if (unlikely (status)) - return status; - } - _cairo_output_stream_puts (ctx->stream, "~> >> image "); - - cairo_surface_destroy (&clone->base); - } - - cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_JPEG, - &mime_data, &mime_data_length); - if (mime_data != NULL) { - _cairo_output_stream_printf (ctx->stream, - "\n (%s) <~", - CAIRO_MIME_TYPE_JPEG); - - base85_stream = _cairo_base85_stream_create (ctx->stream); - _cairo_output_stream_write (base85_stream, mime_data, mime_data_length); - status = _cairo_output_stream_destroy (base85_stream); - if (unlikely (status)) - return status; - - _cairo_output_stream_puts (ctx->stream, "~> set-mime-data\n"); - } - - cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_JP2, - &mime_data, &mime_data_length); - if (mime_data != NULL) { - _cairo_output_stream_printf (ctx->stream, - "\n (%s) <~", - CAIRO_MIME_TYPE_JP2); - - base85_stream = _cairo_base85_stream_create (ctx->stream); - _cairo_output_stream_write (base85_stream, mime_data, mime_data_length); - status = _cairo_output_stream_destroy (base85_stream); - if (unlikely (status)) - return status; - - _cairo_output_stream_puts (ctx->stream, "~> set-mime-data\n"); - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_image_surface_pattern (cairo_script_surface_t *surface, - cairo_surface_t *source) -{ - cairo_image_surface_t *image; - cairo_status_t status; - void *extra; - - status = _cairo_surface_acquire_source_image (source, &image, &extra); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - status = _emit_image_surface (surface, image); - _cairo_surface_release_source_image (source, image, extra); - } - - return status; -} - -static cairo_int_status_t -_emit_subsurface_pattern (cairo_script_surface_t *surface, - cairo_surface_subsurface_t *sub) -{ - cairo_surface_t *source = sub->target; - cairo_int_status_t status; - - switch ((int) source->backend->type) { - case CAIRO_SURFACE_TYPE_RECORDING: - status = _emit_recording_surface_pattern (surface, (cairo_recording_surface_t *) source); - break; - case CAIRO_SURFACE_TYPE_SCRIPT: - status = _emit_script_surface_pattern (surface, (cairo_script_surface_t *) source); - break; - default: - status = _emit_image_surface_pattern (surface, source); - break; - } - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (to_context (surface)->stream, - "%d %d %d %d subsurface ", - sub->extents.x, - sub->extents.y, - sub->extents.width, - sub->extents.height); - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_surface_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_surface_pattern_t *surface_pattern; - cairo_surface_t *source, *snapshot, *free_me = NULL; - cairo_surface_t *take_snapshot = NULL; - cairo_int_status_t status; - - surface_pattern = (cairo_surface_pattern_t *) pattern; - source = surface_pattern->surface; - - if (_cairo_surface_is_snapshot (source)) { - snapshot = _cairo_surface_has_snapshot (source, &script_snapshot_backend); - if (snapshot) { - _cairo_output_stream_printf (ctx->stream, - "s%d pattern ", - snapshot->unique_id); - return CAIRO_INT_STATUS_SUCCESS; - } - - if (_cairo_surface_snapshot_is_reused (source)) - take_snapshot = source; - - free_me = source = _cairo_surface_snapshot_get_target (source); - } - - switch ((int) source->backend->type) { - case CAIRO_SURFACE_TYPE_RECORDING: - status = _emit_recording_surface_pattern (surface, (cairo_recording_surface_t *) source); - break; - case CAIRO_SURFACE_TYPE_SCRIPT: - status = _emit_script_surface_pattern (surface, (cairo_script_surface_t *) source); - break; - case CAIRO_SURFACE_TYPE_SUBSURFACE: - status = _emit_subsurface_pattern (surface, (cairo_surface_subsurface_t *) source); - break; - default: - status = _emit_image_surface_pattern (surface, source); - break; - } - cairo_surface_destroy (free_me); - if (unlikely (status)) - return status; - - if (take_snapshot) - attach_snapshot (ctx, take_snapshot); - - _cairo_output_stream_puts (ctx->stream, "pattern"); - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_raster_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_surface_t *source; - cairo_int_status_t status; - - source = _cairo_raster_source_pattern_acquire (pattern, &surface->base, NULL); - if (unlikely (source == NULL)) { - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_UNSUPPORTED; - } - if (unlikely (source->status)) - return source->status; - - status = _emit_image_surface_pattern (surface, source); - _cairo_raster_source_pattern_release (pattern, source); - if (unlikely (status)) - return status; - - _cairo_output_stream_puts (to_context(surface)->stream, "pattern"); - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_pattern (cairo_script_surface_t *surface, - const cairo_pattern_t *pattern) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_int_status_t status; - cairo_bool_t is_default_extend; - cairo_bool_t need_newline = TRUE; - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - /* solid colors do not need filter/extend/matrix */ - return _emit_solid_pattern (surface, pattern); - - case CAIRO_PATTERN_TYPE_LINEAR: - status = _emit_linear_pattern (surface, pattern); - is_default_extend = pattern->extend == CAIRO_EXTEND_GRADIENT_DEFAULT; - break; - case CAIRO_PATTERN_TYPE_RADIAL: - status = _emit_radial_pattern (surface, pattern); - is_default_extend = pattern->extend == CAIRO_EXTEND_GRADIENT_DEFAULT; - break; - case CAIRO_PATTERN_TYPE_MESH: - status = _emit_mesh_pattern (surface, pattern); - is_default_extend = TRUE; - break; - case CAIRO_PATTERN_TYPE_SURFACE: - status = _emit_surface_pattern (surface, pattern); - is_default_extend = pattern->extend == CAIRO_EXTEND_SURFACE_DEFAULT; - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - status = _emit_raster_pattern (surface, pattern); - is_default_extend = pattern->extend == CAIRO_EXTEND_SURFACE_DEFAULT; - break; - - default: - ASSERT_NOT_REACHED; - status = CAIRO_INT_STATUS_UNSUPPORTED; - } - if (unlikely (status)) - return status; - - if (! _cairo_matrix_is_identity (&pattern->matrix)) { - if (need_newline) { - _cairo_output_stream_puts (ctx->stream, "\n "); - need_newline = FALSE; - } - - _cairo_output_stream_printf (ctx->stream, - " [%f %f %f %f %f %f] set-matrix\n ", - pattern->matrix.xx, pattern->matrix.yx, - pattern->matrix.xy, pattern->matrix.yy, - pattern->matrix.x0, pattern->matrix.y0); - } - - /* XXX need to discriminate the user explicitly setting the default */ - if (pattern->filter != CAIRO_FILTER_DEFAULT) { - if (need_newline) { - _cairo_output_stream_puts (ctx->stream, "\n "); - need_newline = FALSE; - } - - _cairo_output_stream_printf (ctx->stream, - " //%s set-filter\n ", - _filter_to_string (pattern->filter)); - } - if (! is_default_extend ){ - if (need_newline) { - _cairo_output_stream_puts (ctx->stream, "\n "); - need_newline = FALSE; - } - - _cairo_output_stream_printf (ctx->stream, - " //%s set-extend\n ", - _extend_to_string (pattern->extend)); - } - - if (need_newline) - _cairo_output_stream_puts (ctx->stream, "\n "); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_identity (cairo_script_surface_t *surface, - cairo_bool_t *matrix_updated) -{ - assert (target_is_active (surface)); - - if (_cairo_matrix_is_identity (&surface->cr.current_ctm)) - return CAIRO_INT_STATUS_SUCCESS; - - _cairo_output_stream_puts (to_context (surface)->stream, - "identity set-matrix\n"); - - *matrix_updated = TRUE; - cairo_matrix_init_identity (&surface->cr.current_ctm); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_emit_source (cairo_script_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source) -{ - cairo_bool_t matrix_updated = FALSE; - cairo_int_status_t status; - - assert (target_is_active (surface)); - - if (op == CAIRO_OPERATOR_CLEAR) { - /* the source is ignored, so don't change it */ - return CAIRO_INT_STATUS_SUCCESS; - } - - if (_cairo_pattern_equal (&surface->cr.current_source.base, source)) - return CAIRO_INT_STATUS_SUCCESS; - - _cairo_pattern_fini (&surface->cr.current_source.base); - status = _cairo_pattern_init_copy (&surface->cr.current_source.base, - source); - if (unlikely (status)) - return status; - - status = _emit_identity (surface, &matrix_updated); - if (unlikely (status)) - return status; - - status = _emit_pattern (surface, source); - if (unlikely (status)) - return status; - - assert (target_is_active (surface)); - _cairo_output_stream_puts (to_context (surface)->stream, - " set-source\n"); - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_status_t -_path_move_to (void *closure, - const cairo_point_t *point) -{ - _cairo_output_stream_printf (closure, - " %f %f m", - _cairo_fixed_to_double (point->x), - _cairo_fixed_to_double (point->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_path_line_to (void *closure, - const cairo_point_t *point) -{ - _cairo_output_stream_printf (closure, - " %f %f l", - _cairo_fixed_to_double (point->x), - _cairo_fixed_to_double (point->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_path_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - _cairo_output_stream_printf (closure, - " %f %f %f %f %f %f c", - _cairo_fixed_to_double (p1->x), - _cairo_fixed_to_double (p1->y), - _cairo_fixed_to_double (p2->x), - _cairo_fixed_to_double (p2->y), - _cairo_fixed_to_double (p3->x), - _cairo_fixed_to_double (p3->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_path_close (void *closure) -{ - _cairo_output_stream_printf (closure, - " h"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_path_boxes (cairo_script_surface_t *surface, - const cairo_path_fixed_t *path) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_path_fixed_iter_t iter; - cairo_status_t status; - struct _cairo_boxes_chunk *chunk; - cairo_boxes_t boxes; - cairo_box_t box; - int i; - - _cairo_boxes_init (&boxes); - _cairo_path_fixed_iter_init (&iter, path); - while (_cairo_path_fixed_iter_is_fill_box (&iter, &box)) { - if (box.p1.y == box.p2.y || box.p1.x == box.p2.x) - continue; - - status = _cairo_boxes_add (&boxes, CAIRO_ANTIALIAS_DEFAULT, &box); - if (unlikely (status)) { - _cairo_boxes_fini (&boxes); - return status; - } - } - - if (! _cairo_path_fixed_iter_at_end (&iter)) { - _cairo_boxes_fini (&boxes); - return FALSE; - } - - for (chunk = &boxes.chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - const cairo_box_t *b = &chunk->base[i]; - double x1 = _cairo_fixed_to_double (b->p1.x); - double y1 = _cairo_fixed_to_double (b->p1.y); - double x2 = _cairo_fixed_to_double (b->p2.x); - double y2 = _cairo_fixed_to_double (b->p2.y); - - _cairo_output_stream_printf (ctx->stream, - "\n %f %f %f %f rectangle", - x1, y1, x2 - x1, y2 - y1); - } - } - - _cairo_boxes_fini (&boxes); - return status; -} - -static cairo_status_t -_emit_path (cairo_script_surface_t *surface, - const cairo_path_fixed_t *path, - cairo_bool_t is_fill) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_box_t box; - cairo_int_status_t status; - - assert (target_is_active (surface)); - assert (_cairo_matrix_is_identity (&surface->cr.current_ctm)); - - if (_cairo_path_fixed_equal (&surface->cr.current_path, path)) - return CAIRO_STATUS_SUCCESS; - - _cairo_path_fixed_fini (&surface->cr.current_path); - - _cairo_output_stream_puts (ctx->stream, "n"); - - if (path == NULL) { - _cairo_path_fixed_init (&surface->cr.current_path); - _cairo_output_stream_puts (ctx->stream, "\n"); - return CAIRO_STATUS_SUCCESS; - } - - status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path); - if (unlikely (status)) - return status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_is_rectangle (path, &box)) { - double x1 = _cairo_fixed_to_double (box.p1.x); - double y1 = _cairo_fixed_to_double (box.p1.y); - double x2 = _cairo_fixed_to_double (box.p2.x); - double y2 = _cairo_fixed_to_double (box.p2.y); - - assert (x1 > -9999); - - _cairo_output_stream_printf (ctx->stream, - " %f %f %f %f rectangle", - x1, y1, x2 - x1, y2 - y1); - status = CAIRO_INT_STATUS_SUCCESS; - } else if (is_fill && _cairo_path_fixed_fill_is_rectilinear (path)) { - status = _emit_path_boxes (surface, path); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = _cairo_path_fixed_interpret (path, - _path_move_to, - _path_line_to, - _path_curve_to, - _path_close, - ctx->stream); - } - - _cairo_output_stream_puts (ctx->stream, "\n"); - - return status; -} -static cairo_bool_t -_scaling_matrix_equal (const cairo_matrix_t *a, - const cairo_matrix_t *b) -{ - return fabs (a->xx - b->xx) < 1e-5 && - fabs (a->xy - b->xy) < 1e-5 && - fabs (a->yx - b->yx) < 1e-5 && - fabs (a->yy - b->yy) < 1e-5; -} - -static cairo_status_t -_emit_scaling_matrix (cairo_script_surface_t *surface, - const cairo_matrix_t *ctm, - cairo_bool_t *matrix_updated) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_bool_t was_identity; - assert (target_is_active (surface)); - - if (_scaling_matrix_equal (&surface->cr.current_ctm, ctm)) - return CAIRO_STATUS_SUCCESS; - - was_identity = _cairo_matrix_is_identity (&surface->cr.current_ctm); - - *matrix_updated = TRUE; - surface->cr.current_ctm = *ctm; - surface->cr.current_ctm.x0 = 0.; - surface->cr.current_ctm.y0 = 0.; - - if (_cairo_matrix_is_identity (&surface->cr.current_ctm)) { - _cairo_output_stream_puts (ctx->stream, - "identity set-matrix\n"); - } else if (was_identity && fabs (ctm->yx) < 1e-5 && fabs (ctm->xy) < 1e-5) { - _cairo_output_stream_printf (ctx->stream, - "%f %f scale\n", - ctm->xx, ctm->yy); - } else { - _cairo_output_stream_printf (ctx->stream, - "[%f %f %f %f 0 0] set-matrix\n", - ctm->xx, ctm->yx, - ctm->xy, ctm->yy); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_font_matrix (cairo_script_surface_t *surface, - const cairo_matrix_t *font_matrix) -{ - cairo_script_context_t *ctx = to_context (surface); - assert (target_is_active (surface)); - - if (memcmp (&surface->cr.current_font_matrix, - font_matrix, - sizeof (cairo_matrix_t)) == 0) - { - return CAIRO_STATUS_SUCCESS; - } - - surface->cr.current_font_matrix = *font_matrix; - - if (_cairo_matrix_is_identity (font_matrix)) { - _cairo_output_stream_puts (ctx->stream, - "identity set-font-matrix\n"); - } else { - _cairo_output_stream_printf (ctx->stream, - "[%f %f %f %f %f %f] set-font-matrix\n", - font_matrix->xx, font_matrix->yx, - font_matrix->xy, font_matrix->yy, - font_matrix->x0, font_matrix->y0); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_script_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_script_surface_t *surface, *other = abstract_surface; - cairo_surface_t *passthrough = NULL; - cairo_script_context_t *ctx; - cairo_rectangle_t extents; - cairo_status_t status; - - ctx = to_context (other); - - status = cairo_device_acquire (&ctx->base); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (! other->emitted) { - status = _emit_surface (other); - if (unlikely (status)) { - cairo_device_release (&ctx->base); - return _cairo_surface_create_in_error (status); - } - - target_push (other); - } - - if (_cairo_surface_wrapper_is_active (&other->wrapper)) { - passthrough = - _cairo_surface_wrapper_create_similar (&other->wrapper, - content, width, height); - if (unlikely (passthrough->status)) { - cairo_device_release (&ctx->base); - return passthrough; - } - } - - extents.x = extents.y = 0; - extents.width = width; - extents.height = height; - surface = _cairo_script_surface_create_internal (ctx, content, - &extents, passthrough); - cairo_surface_destroy (passthrough); - - if (unlikely (surface->base.status)) { - cairo_device_release (&ctx->base); - return &surface->base; - } - - _get_target (other); - _cairo_output_stream_printf (ctx->stream, - "%u %u //%s similar dup /s%u exch def context\n", - width, height, - _content_to_string (content), - surface->base.unique_id); - - surface->emitted = TRUE; - surface->defined = TRUE; - surface->base.is_clear = TRUE; - target_push (surface); - - cairo_device_release (&ctx->base); - return &surface->base; -} - -static cairo_status_t -_device_flush (void *abstract_device) -{ - cairo_script_context_t *ctx = abstract_device; - - return _cairo_output_stream_flush (ctx->stream); -} - -static void -_device_destroy (void *abstract_device) -{ - cairo_script_context_t *ctx = abstract_device; - cairo_status_t status; - - while (! cairo_list_is_empty (&ctx->fonts)) { - cairo_script_font_t *font; - - font = cairo_list_first_entry (&ctx->fonts, cairo_script_font_t, link); - cairo_list_del (&font->base.link); - cairo_list_del (&font->link); - free (font); - } - - _bitmap_fini (ctx->surface_id.next); - _bitmap_fini (ctx->font_id.next); - - if (ctx->owns_stream) - status = _cairo_output_stream_destroy (ctx->stream); - - free (ctx); -} - -static cairo_surface_t * -_cairo_script_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_script_surface_t *surface = abstract_surface; - - if (extents) { - extents->x = extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - } - - return &surface->base; -} - -static cairo_status_t -_cairo_script_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_script_surface_t *surface = abstract_surface; - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { - return _cairo_surface_wrapper_acquire_source_image (&surface->wrapper, - image_out, - image_extra); - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static void -_cairo_script_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_script_surface_t *surface = abstract_surface; - - assert (_cairo_surface_wrapper_is_active (&surface->wrapper)); - _cairo_surface_wrapper_release_source_image (&surface->wrapper, - image, - image_extra); -} - -static cairo_status_t -_cairo_script_surface_finish (void *abstract_surface) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_script_context_t *ctx = to_context (surface); - cairo_status_t status = CAIRO_STATUS_SUCCESS, status2; - - _cairo_surface_wrapper_fini (&surface->wrapper); - - free (surface->cr.current_style.dash); - surface->cr.current_style.dash = NULL; - - _cairo_pattern_fini (&surface->cr.current_source.base); - _cairo_path_fixed_fini (&surface->cr.current_path); - _cairo_surface_clipper_reset (&surface->clipper); - - status = cairo_device_acquire (&ctx->base); - if (unlikely (status)) - return status; - - if (surface->emitted) { - assert (! surface->active); - - if (! cairo_list_is_empty (&surface->operand.link)) { - if (! ctx->active) { - if (target_is_active (surface)) { - _cairo_output_stream_printf (ctx->stream, - "pop\n"); - } else { - int depth = target_depth (surface); - if (depth == 1) { - _cairo_output_stream_printf (ctx->stream, - "exch pop\n"); - } else { - _cairo_output_stream_printf (ctx->stream, - "%d -1 roll pop\n", - depth); - } - } - cairo_list_del (&surface->operand.link); - } else { - struct deferred_finish *link = malloc (sizeof (*link)); - if (link == NULL) { - status2 = _cairo_error (CAIRO_STATUS_NO_MEMORY); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - cairo_list_del (&surface->operand.link); - } else { - link->operand.type = DEFERRED; - cairo_list_swap (&link->operand.link, - &surface->operand.link); - cairo_list_add (&link->link, &ctx->deferred); - } - } - } - - if (surface->defined) { - _cairo_output_stream_printf (ctx->stream, - "/s%u undef\n", - surface->base.unique_id); - } - } - - if (status == CAIRO_STATUS_SUCCESS) - status = _cairo_output_stream_flush (to_context (surface)->stream); - - cairo_device_release (&ctx->base); - - return status; -} - -static cairo_int_status_t -_cairo_script_surface_copy_page (void *abstract_surface) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_status_t status; - - status = cairo_device_acquire (surface->base.device); - if (unlikely (status)) - return status; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - _cairo_output_stream_puts (to_context (surface)->stream, "copy-page\n"); - -BAIL: - cairo_device_release (surface->base.device); - return status; -} - -static cairo_int_status_t -_cairo_script_surface_show_page (void *abstract_surface) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_status_t status; - - status = cairo_device_acquire (surface->base.device); - if (unlikely (status)) - return status; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - _cairo_output_stream_puts (to_context (surface)->stream, "show-page\n"); - -BAIL: - cairo_device_release (surface->base.device); - return status; -} - -static cairo_status_t -_cairo_script_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_script_surface_t *surface = cairo_container_of (clipper, - cairo_script_surface_t, - clipper); - cairo_script_context_t *ctx = to_context (surface); - cairo_bool_t matrix_updated = FALSE; - cairo_status_t status; - cairo_box_t box; - - status = _emit_context (surface); - if (unlikely (status)) - return status; - - if (path == NULL) { - if (surface->cr.has_clip) { - _cairo_output_stream_puts (ctx->stream, "reset-clip\n"); - surface->cr.has_clip = FALSE; - } - return CAIRO_STATUS_SUCCESS; - } - - /* skip the trivial clip covering the surface extents */ - if (surface->width >= 0 && surface->height >= 0 && - _cairo_path_fixed_is_box (path, &box)) - { - if (box.p1.x <= 0 && box.p1.y <= 0 && - box.p2.x >= _cairo_fixed_from_double (surface->width) && - box.p2.y >= _cairo_fixed_from_double (surface->height)) - { - return CAIRO_STATUS_SUCCESS; - } - } - - status = _emit_identity (surface, &matrix_updated); - if (unlikely (status)) - return status; - - status = _emit_fill_rule (surface, fill_rule); - if (unlikely (status)) - return status; - - if (path->has_curve_to) { - status = _emit_tolerance (surface, tolerance, matrix_updated); - if (unlikely (status)) - return status; - } - - if (! _cairo_path_fixed_fill_maybe_region (path)) { - status = _emit_antialias (surface, antialias); - if (unlikely (status)) - return status; - } - - status = _emit_path (surface, path, TRUE); - if (unlikely (status)) - return status; - - _cairo_output_stream_puts (ctx->stream, "clip+\n"); - surface->cr.has_clip = TRUE; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -active (cairo_script_surface_t *surface) -{ - cairo_status_t status; - - status = cairo_device_acquire (surface->base.device); - if (unlikely (status)) - return status; - - if (surface->active++ == 0) - to_context (surface)->active++; - - return CAIRO_STATUS_SUCCESS; -} - -static void -inactive (cairo_script_surface_t *surface) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_list_t sorted; - - assert (surface->active > 0); - if (--surface->active) - goto DONE; - - assert (ctx->active > 0); - if (--ctx->active) - goto DONE; - - cairo_list_init (&sorted); - while (! cairo_list_is_empty (&ctx->deferred)) { - struct deferred_finish *df; - cairo_list_t *operand; - int depth; - - df = cairo_list_first_entry (&ctx->deferred, - struct deferred_finish, - link); - - depth = 0; - cairo_list_foreach (operand, &ctx->operands) { - if (operand == &df->operand.link) - break; - depth++; - } - - df->operand.type = depth; - - if (cairo_list_is_empty (&sorted)) { - cairo_list_move (&df->link, &sorted); - } else { - struct deferred_finish *pos; - - cairo_list_foreach_entry (pos, struct deferred_finish, - &sorted, - link) - { - if (df->operand.type < pos->operand.type) - break; - } - cairo_list_move_tail (&df->link, &pos->link); - } - } - - while (! cairo_list_is_empty (&sorted)) { - struct deferred_finish *df; - cairo_list_t *operand; - int depth; - - df = cairo_list_first_entry (&sorted, - struct deferred_finish, - link); - - depth = 0; - cairo_list_foreach (operand, &ctx->operands) { - if (operand == &df->operand.link) - break; - depth++; - } - - if (depth == 0) { - _cairo_output_stream_printf (ctx->stream, - "pop\n"); - } else if (depth == 1) { - _cairo_output_stream_printf (ctx->stream, - "exch pop\n"); - } else { - _cairo_output_stream_printf (ctx->stream, - "%d -1 roll pop\n", - depth); - } - - cairo_list_del (&df->operand.link); - cairo_list_del (&df->link); - free (df); - } - -DONE: - cairo_device_release (surface->base.device); -} - -static cairo_int_status_t -_cairo_script_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_status_t status; - - status = active (surface); - if (unlikely (status)) - return status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - goto BAIL; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - status = _emit_source (surface, op, source); - if (unlikely (status)) - goto BAIL; - - status = _emit_operator (surface, op); - if (unlikely (status)) - goto BAIL; - - _cairo_output_stream_puts (to_context (surface)->stream, - "paint\n"); - - inactive (surface); - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { - return _cairo_surface_wrapper_paint (&surface->wrapper, - op, source, clip); - } - - return CAIRO_STATUS_SUCCESS; - -BAIL: - inactive (surface); - return status; -} - -static cairo_int_status_t -_cairo_script_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_status_t status; - - status = active (surface); - if (unlikely (status)) - return status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - goto BAIL; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - status = _emit_source (surface, op, source); - if (unlikely (status)) - goto BAIL; - - status = _emit_operator (surface, op); - if (unlikely (status)) - goto BAIL; - - if (_cairo_pattern_equal (source, mask)) { - _cairo_output_stream_puts (to_context (surface)->stream, "/source get"); - } else { - status = _emit_pattern (surface, mask); - if (unlikely (status)) - goto BAIL; - } - - assert (surface->cr.current_operator == op); - - _cairo_output_stream_puts (to_context (surface)->stream, - " mask\n"); - - inactive (surface); - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { - return _cairo_surface_wrapper_mask (&surface->wrapper, - op, source, mask, clip); - } - - return CAIRO_STATUS_SUCCESS; - -BAIL: - inactive (surface); - return status; -} - -static cairo_int_status_t -_cairo_script_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_bool_t matrix_updated = FALSE; - cairo_status_t status; - - status = active (surface); - if (unlikely (status)) - return status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - goto BAIL; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - status = _emit_identity (surface, &matrix_updated); - if (unlikely (status)) - goto BAIL; - - status = _emit_path (surface, path, FALSE); - if (unlikely (status)) - goto BAIL; - - status = _emit_source (surface, op, source); - if (unlikely (status)) - goto BAIL; - - status = _emit_scaling_matrix (surface, ctm, &matrix_updated); - if (unlikely (status)) - goto BAIL; - - status = _emit_operator (surface, op); - if (unlikely (status)) - goto BAIL; - - if (_scaling_matrix_equal (&surface->cr.current_ctm, - &surface->cr.current_stroke_matrix)) - { - matrix_updated = FALSE; - } - else - { - matrix_updated = TRUE; - surface->cr.current_stroke_matrix = surface->cr.current_ctm; - } - - status = _emit_stroke_style (surface, style, matrix_updated); - if (unlikely (status)) - goto BAIL; - - status = _emit_tolerance (surface, tolerance, matrix_updated); - if (unlikely (status)) - goto BAIL; - - status = _emit_antialias (surface, antialias); - if (unlikely (status)) - goto BAIL; - - _cairo_output_stream_puts (to_context (surface)->stream, "stroke+\n"); - - inactive (surface); - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { - return _cairo_surface_wrapper_stroke (&surface->wrapper, - op, source, path, - style, - ctm, ctm_inverse, - tolerance, antialias, - clip); - } - - return CAIRO_STATUS_SUCCESS; - -BAIL: - inactive (surface); - return status; -} - -static cairo_int_status_t -_cairo_script_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_bool_t matrix_updated = FALSE; - cairo_status_t status; - cairo_box_t box; - - status = active (surface); - if (unlikely (status)) - return status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - goto BAIL; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - status = _emit_identity (surface, &matrix_updated); - if (unlikely (status)) - goto BAIL; - - status = _emit_source (surface, op, source); - if (unlikely (status)) - goto BAIL; - - if (! _cairo_path_fixed_is_box (path, &box)) { - status = _emit_fill_rule (surface, fill_rule); - if (unlikely (status)) - goto BAIL; - } - - if (path->has_curve_to) { - status = _emit_tolerance (surface, tolerance, matrix_updated); - if (unlikely (status)) - goto BAIL; - } - - if (! _cairo_path_fixed_fill_maybe_region (path)) { - status = _emit_antialias (surface, antialias); - if (unlikely (status)) - goto BAIL; - } - - status = _emit_path (surface, path, TRUE); - if (unlikely (status)) - goto BAIL; - - status = _emit_operator (surface, op); - if (unlikely (status)) - goto BAIL; - - _cairo_output_stream_puts (to_context (surface)->stream, "fill+\n"); - - inactive (surface); - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { - return _cairo_surface_wrapper_fill (&surface->wrapper, - op, source, path, - fill_rule, - tolerance, - antialias, - clip); - } - - return CAIRO_STATUS_SUCCESS; - -BAIL: - inactive (surface); - return status; -} - -static cairo_surface_t * -_cairo_script_surface_snapshot (void *abstract_surface) -{ - cairo_script_surface_t *surface = abstract_surface; - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) - return _cairo_surface_wrapper_snapshot (&surface->wrapper); - - return NULL; -} - -static cairo_bool_t -_cairo_script_surface_has_show_text_glyphs (void *abstract_surface) -{ - return TRUE; -} - -static const char * -_subpixel_order_to_string (cairo_subpixel_order_t subpixel_order) -{ - static const char *names[] = { - "SUBPIXEL_ORDER_DEFAULT", /* CAIRO_SUBPIXEL_ORDER_DEFAULT */ - "SUBPIXEL_ORDER_RGB", /* CAIRO_SUBPIXEL_ORDER_RGB */ - "SUBPIXEL_ORDER_BGR", /* CAIRO_SUBPIXEL_ORDER_BGR */ - "SUBPIXEL_ORDER_VRGB", /* CAIRO_SUBPIXEL_ORDER_VRGB */ - "SUBPIXEL_ORDER_VBGR" /* CAIRO_SUBPIXEL_ORDER_VBGR */ - }; - return names[subpixel_order]; -} -static const char * -_hint_style_to_string (cairo_hint_style_t hint_style) -{ - static const char *names[] = { - "HINT_STYLE_DEFAULT", /* CAIRO_HINT_STYLE_DEFAULT */ - "HINT_STYLE_NONE", /* CAIRO_HINT_STYLE_NONE */ - "HINT_STYLE_SLIGHT", /* CAIRO_HINT_STYLE_SLIGHT */ - "HINT_STYLE_MEDIUM", /* CAIRO_HINT_STYLE_MEDIUM */ - "HINT_STYLE_FULL" /* CAIRO_HINT_STYLE_FULL */ - }; - return names[hint_style]; -} -static const char * -_hint_metrics_to_string (cairo_hint_metrics_t hint_metrics) -{ - static const char *names[] = { - "HINT_METRICS_DEFAULT", /* CAIRO_HINT_METRICS_DEFAULT */ - "HINT_METRICS_OFF", /* CAIRO_HINT_METRICS_OFF */ - "HINT_METRICS_ON" /* CAIRO_HINT_METRICS_ON */ - }; - return names[hint_metrics]; -} - -static cairo_status_t -_emit_font_options (cairo_script_surface_t *surface, - cairo_font_options_t *font_options) -{ - cairo_script_context_t *ctx = to_context (surface); - - if (cairo_font_options_equal (&surface->cr.current_font_options, - font_options)) - { - return CAIRO_STATUS_SUCCESS; - } - - _cairo_output_stream_printf (ctx->stream, "<<"); - - if (font_options->antialias != surface->cr.current_font_options.antialias) { - _cairo_output_stream_printf (ctx->stream, - " /antialias //%s", - _antialias_to_string (font_options->antialias)); - } - - if (font_options->subpixel_order != - surface->cr.current_font_options.subpixel_order) - { - _cairo_output_stream_printf (ctx->stream, - " /subpixel-order //%s", - _subpixel_order_to_string (font_options->subpixel_order)); - } - - if (font_options->hint_style != - surface->cr.current_font_options.hint_style) - { - _cairo_output_stream_printf (ctx->stream, - " /hint-style //%s", - _hint_style_to_string (font_options->hint_style)); - } - - if (font_options->hint_metrics != - surface->cr.current_font_options.hint_metrics) - { - _cairo_output_stream_printf (ctx->stream, - " /hint-metrics //%s", - _hint_metrics_to_string (font_options->hint_metrics)); - } - - _cairo_output_stream_printf (ctx->stream, - " >> set-font-options\n"); - - surface->cr.current_font_options = *font_options; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_script_scaled_font_fini (cairo_scaled_font_private_t *abstract_private, - cairo_scaled_font_t *scaled_font) -{ - cairo_script_font_t *priv = (cairo_script_font_t *)abstract_private; - cairo_script_context_t *ctx = (cairo_script_context_t *)abstract_private->key; - cairo_status_t status; - - status = cairo_device_acquire (&ctx->base); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - _cairo_output_stream_printf (ctx->stream, - "/f%lu undef /sf%lu undef\n", - priv->id, - priv->id); - - _bitmap_release_id (&ctx->font_id, priv->id); - cairo_device_release (&ctx->base); - } - - cairo_list_del (&priv->link); - cairo_list_del (&priv->base.link); - free (priv); -} - -static cairo_script_font_t * -_cairo_script_font_get (cairo_script_context_t *ctx, cairo_scaled_font_t *font) -{ - return (cairo_script_font_t *) _cairo_scaled_font_find_private (font, ctx); -} - -static long unsigned -_cairo_script_font_id (cairo_script_context_t *ctx, cairo_scaled_font_t *font) -{ - return _cairo_script_font_get (ctx, font)->id; -} - -static cairo_status_t -_emit_type42_font (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font) -{ - cairo_script_context_t *ctx = to_context (surface); - const cairo_scaled_font_backend_t *backend; - cairo_output_stream_t *base85_stream; - cairo_output_stream_t *zlib_stream; - cairo_status_t status, status2; - unsigned long size; - unsigned int load_flags; - uint32_t len; - uint8_t *buf; - - backend = scaled_font->backend; - if (backend->load_truetype_table == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = 0; - status = backend->load_truetype_table (scaled_font, 0, 0, NULL, &size); - if (unlikely (status)) - return status; - - buf = malloc (size); - if (unlikely (buf == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = backend->load_truetype_table (scaled_font, 0, 0, buf, &size); - if (unlikely (status)) { - free (buf); - return status; - } - -#if CAIRO_HAS_FT_FONT - load_flags = _cairo_ft_scaled_font_get_load_flags (scaled_font); -#else - load_flags = 0; -#endif - _cairo_output_stream_printf (ctx->stream, - "<< " - "/type 42 " - "/index 0 " - "/flags %d " - "/source <|", - load_flags); - - base85_stream = _cairo_base85_stream_create (ctx->stream); - len = to_be32 (size); - _cairo_output_stream_write (base85_stream, &len, sizeof (len)); - - zlib_stream = _cairo_deflate_stream_create (base85_stream); - - _cairo_output_stream_write (zlib_stream, buf, size); - free (buf); - - status2 = _cairo_output_stream_destroy (zlib_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - status2 = _cairo_output_stream_destroy (base85_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - _cairo_output_stream_printf (ctx->stream, - "~> >> font dup /f%lu exch def set-font-face", - _cairo_script_font_id (ctx, scaled_font)); - - return status; -} - -static cairo_status_t -_emit_scaled_font_init (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font, - cairo_script_font_t **font_out) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_script_font_t *font_private; - cairo_int_status_t status; - - font_private = malloc (sizeof (cairo_script_font_t)); - if (unlikely (font_private == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_scaled_font_attach_private (scaled_font, &font_private->base, ctx, - _cairo_script_scaled_font_fini); - - font_private->parent = scaled_font; - font_private->subset_glyph_index = 0; - font_private->has_sfnt = TRUE; - - cairo_list_add (&font_private->link, &ctx->fonts); - - status = _bitmap_next_id (&ctx->font_id, - &font_private->id); - if (unlikely (status)) { - free (font_private); - return status; - } - - status = _emit_context (surface); - if (unlikely (status)) { - free (font_private); - return status; - } - - status = _emit_type42_font (surface, scaled_font); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) { - *font_out = font_private; - return status; - } - - font_private->has_sfnt = FALSE; - _cairo_output_stream_printf (ctx->stream, - "dict\n" - " /type 3 set\n" - " /metrics [%f %f %f %f %f] set\n" - " /glyphs array set\n" - " font dup /f%lu exch def set-font-face", - scaled_font->fs_extents.ascent, - scaled_font->fs_extents.descent, - scaled_font->fs_extents.height, - scaled_font->fs_extents.max_x_advance, - scaled_font->fs_extents.max_y_advance, - font_private->id); - - *font_out = font_private; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_scaled_font (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_matrix_t matrix; - cairo_font_options_t options; - cairo_bool_t matrix_updated = FALSE; - cairo_status_t status; - cairo_script_font_t *font_private; - - cairo_scaled_font_get_ctm (scaled_font, &matrix); - status = _emit_scaling_matrix (surface, &matrix, &matrix_updated); - if (unlikely (status)) - return status; - - if (! matrix_updated && surface->cr.current_scaled_font == scaled_font) - return CAIRO_STATUS_SUCCESS; - - surface->cr.current_scaled_font = scaled_font; - - font_private = _cairo_script_font_get (ctx, scaled_font); - if (font_private == NULL) { - cairo_scaled_font_get_font_matrix (scaled_font, &matrix); - status = _emit_font_matrix (surface, &matrix); - if (unlikely (status)) - return status; - - cairo_scaled_font_get_font_options (scaled_font, &options); - status = _emit_font_options (surface, &options); - if (unlikely (status)) - return status; - - status = _emit_scaled_font_init (surface, scaled_font, &font_private); - if (unlikely (status)) - return status; - - assert (target_is_active (surface)); - _cairo_output_stream_printf (ctx->stream, - " /scaled-font get /sf%lu exch def\n", - font_private->id); - } else { - _cairo_output_stream_printf (ctx->stream, - "sf%lu set-scaled-font\n", - font_private->id); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_scaled_glyph_vector (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font, - cairo_script_font_t *font_private, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_script_implicit_context_t old_cr; - cairo_status_t status; - unsigned long index; - - index = ++font_private->subset_glyph_index; - scaled_glyph->dev_private_key = ctx; - scaled_glyph->dev_private = (void *) index; - - _cairo_output_stream_printf (ctx->stream, - "%lu <<\n" - " /metrics [%f %f %f %f %f %f]\n" - " /render {\n", - index, - scaled_glyph->fs_metrics.x_bearing, - scaled_glyph->fs_metrics.y_bearing, - scaled_glyph->fs_metrics.width, - scaled_glyph->fs_metrics.height, - scaled_glyph->fs_metrics.x_advance, - scaled_glyph->fs_metrics.y_advance); - - if (! _cairo_matrix_is_identity (&scaled_font->scale_inverse)) { - _cairo_output_stream_printf (ctx->stream, - "[%f %f %f %f %f %f] transform\n", - scaled_font->scale_inverse.xx, - scaled_font->scale_inverse.yx, - scaled_font->scale_inverse.xy, - scaled_font->scale_inverse.yy, - scaled_font->scale_inverse.x0, - scaled_font->scale_inverse.y0); - } - - old_cr = surface->cr; - _cairo_script_implicit_context_init (&surface->cr); - status = _cairo_recording_surface_replay (scaled_glyph->recording_surface, - &surface->base); - surface->cr = old_cr; - - _cairo_output_stream_puts (ctx->stream, "} >> set\n"); - - return status; -} - -static cairo_status_t -_emit_scaled_glyph_bitmap (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font, - cairo_script_font_t *font_private, - cairo_scaled_glyph_t *scaled_glyph) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_status_t status; - unsigned long index; - - index = ++font_private->subset_glyph_index; - scaled_glyph->dev_private_key = ctx; - scaled_glyph->dev_private = (void *) index; - - _cairo_output_stream_printf (ctx->stream, - "%lu <<\n" - " /metrics [%f %f %f %f %f %f]\n" - " /render {\n" - "%f %f translate\n", - index, - scaled_glyph->fs_metrics.x_bearing, - scaled_glyph->fs_metrics.y_bearing, - scaled_glyph->fs_metrics.width, - scaled_glyph->fs_metrics.height, - scaled_glyph->fs_metrics.x_advance, - scaled_glyph->fs_metrics.y_advance, - scaled_glyph->fs_metrics.x_bearing, - scaled_glyph->fs_metrics.y_bearing); - - status = _emit_image_surface (surface, scaled_glyph->surface); - if (unlikely (status)) - return status; - - _cairo_output_stream_puts (ctx->stream, "pattern "); - - if (! _cairo_matrix_is_identity (&scaled_font->font_matrix)) { - _cairo_output_stream_printf (ctx->stream, - "\n [%f %f %f %f %f %f] set-matrix\n", - scaled_font->font_matrix.xx, - scaled_font->font_matrix.yx, - scaled_font->font_matrix.xy, - scaled_font->font_matrix.yy, - scaled_font->font_matrix.x0, - scaled_font->font_matrix.y0); - } - _cairo_output_stream_puts (ctx->stream, - "mask\n} >> set\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_scaled_glyph_prologue (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font) -{ - cairo_script_context_t *ctx = to_context (surface); - - _cairo_output_stream_printf (ctx->stream, "f%lu /glyphs get\n", - _cairo_script_font_id (ctx, scaled_font)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_emit_scaled_glyphs (cairo_script_surface_t *surface, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - unsigned int num_glyphs) -{ - cairo_script_context_t *ctx = to_context (surface); - cairo_script_font_t *font_private; - cairo_status_t status; - unsigned int n; - cairo_bool_t have_glyph_prologue = FALSE; - - if (num_glyphs == 0) - return CAIRO_STATUS_SUCCESS; - - font_private = _cairo_script_font_get (ctx, scaled_font); - if (font_private->has_sfnt) - return CAIRO_STATUS_SUCCESS; - - _cairo_scaled_font_freeze_cache (scaled_font); - for (n = 0; n < num_glyphs; n++) { - cairo_scaled_glyph_t *scaled_glyph; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[n].index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) - break; - - if (scaled_glyph->dev_private_key == ctx) - continue; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[n].index, - CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE, - &scaled_glyph); - if (_cairo_status_is_error (status)) - break; - - if (status == CAIRO_STATUS_SUCCESS) { - if (! have_glyph_prologue) { - status = _emit_scaled_glyph_prologue (surface, scaled_font); - if (unlikely (status)) - break; - - have_glyph_prologue = TRUE; - } - - status = _emit_scaled_glyph_vector (surface, - scaled_font, font_private, - scaled_glyph); - if (unlikely (status)) - break; - - continue; - } - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[n].index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - if (_cairo_status_is_error (status)) - break; - - if (status == CAIRO_STATUS_SUCCESS) { - if (! have_glyph_prologue) { - status = _emit_scaled_glyph_prologue (surface, scaled_font); - if (unlikely (status)) - break; - - have_glyph_prologue = TRUE; - } - - status = _emit_scaled_glyph_bitmap (surface, - scaled_font, - font_private, - scaled_glyph); - if (unlikely (status)) - break; - - continue; - } - } - _cairo_scaled_font_thaw_cache (scaled_font); - - if (have_glyph_prologue) { - _cairo_output_stream_puts (to_context (surface)->stream, "pop pop\n"); - } - - return status; -} - -static void -to_octal (int value, char *buf, size_t size) -{ - do { - buf[--size] = '0' + (value & 7); - value >>= 3; - } while (size); -} - -static void -_emit_string_literal (cairo_script_surface_t *surface, - const char *utf8, int len) -{ - cairo_script_context_t *ctx = to_context (surface); - char c; - const char *end; - - _cairo_output_stream_puts (ctx->stream, "("); - - if (utf8 == NULL) { - end = utf8; - } else { - if (len < 0) - len = strlen (utf8); - end = utf8 + len; - } - - while (utf8 < end) { - switch ((c = *utf8++)) { - case '\n': - c = 'n'; - goto ESCAPED_CHAR; - case '\r': - c = 'r'; - goto ESCAPED_CHAR; - case '\t': - c = 't'; - goto ESCAPED_CHAR; - case '\b': - c = 'b'; - goto ESCAPED_CHAR; - case '\f': - c = 'f'; - goto ESCAPED_CHAR; - case '\\': - case '(': - case ')': -ESCAPED_CHAR: - _cairo_output_stream_printf (ctx->stream, "\\%c", c); - break; - default: - if (isprint (c) || isspace (c)) { - _cairo_output_stream_printf (ctx->stream, "%c", c); - } else { - char buf[4] = { '\\' }; - - to_octal (c, buf+1, 3); - _cairo_output_stream_write (ctx->stream, buf, 4); - } - break; - } - } - _cairo_output_stream_puts (ctx->stream, ")"); -} - -static cairo_int_status_t -_cairo_script_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t backward, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_script_surface_t *surface = abstract_surface; - cairo_script_context_t *ctx = to_context (surface); - cairo_script_font_t *font_private; - cairo_scaled_glyph_t *scaled_glyph; - cairo_matrix_t matrix; - cairo_status_t status; - double x, y, ix, iy; - int n; - cairo_output_stream_t *base85_stream = NULL; - - status = active (surface); - if (unlikely (status)) - return status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - goto BAIL; - - status = _emit_context (surface); - if (unlikely (status)) - goto BAIL; - - status = _emit_source (surface, op, source); - if (unlikely (status)) - goto BAIL; - - status = _emit_scaled_font (surface, scaled_font); - if (unlikely (status)) - goto BAIL; - - status = _emit_operator (surface, op); - if (unlikely (status)) - goto BAIL; - - status = _emit_scaled_glyphs (surface, scaled_font, glyphs, num_glyphs); - if (unlikely (status)) - goto BAIL; - - /* (utf8) [cx cy [glyphs]] [clusters] backward show_text_glyphs */ - /* [cx cy [glyphs]] show_glyphs */ - - if (utf8 != NULL && clusters != NULL) { - _emit_string_literal (surface, utf8, utf8_len); - _cairo_output_stream_puts (ctx->stream, " "); - } - - matrix = surface->cr.current_ctm; - status = cairo_matrix_invert (&matrix); - assert (status == CAIRO_STATUS_SUCCESS); - - ix = x = glyphs[0].x; - iy = y = glyphs[0].y; - cairo_matrix_transform_point (&matrix, &ix, &iy); - ix -= scaled_font->font_matrix.x0; - iy -= scaled_font->font_matrix.y0; - - _cairo_scaled_font_freeze_cache (scaled_font); - font_private = _cairo_script_font_get (ctx, scaled_font); - - _cairo_output_stream_printf (ctx->stream, - "[%f %f ", - ix, iy); - - for (n = 0; n < num_glyphs; n++) { - if (font_private->has_sfnt) { - if (glyphs[n].index > 256) - break; - } else { - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[n].index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) { - _cairo_scaled_font_thaw_cache (scaled_font); - goto BAIL; - } - - if ((long unsigned) scaled_glyph->dev_private > 256) - break; - } - } - - if (n == num_glyphs) { - _cairo_output_stream_puts (ctx->stream, "<~"); - base85_stream = _cairo_base85_stream_create (ctx->stream); - } else - _cairo_output_stream_puts (ctx->stream, "["); - - for (n = 0; n < num_glyphs; n++) { - double dx, dy; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs[n].index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (unlikely (status)) { - _cairo_scaled_font_thaw_cache (scaled_font); - goto BAIL; - } - - if (fabs (glyphs[n].x - x) > 1e-5 || fabs (glyphs[n].y - y) > 1e-5) { - if (fabs (glyphs[n].y - y) < 1e-5) { - if (base85_stream != NULL) { - status = _cairo_output_stream_destroy (base85_stream); - if (unlikely (status)) { - base85_stream = NULL; - break; - } - - _cairo_output_stream_printf (ctx->stream, - "~> %f <~", glyphs[n].x - x); - base85_stream = _cairo_base85_stream_create (ctx->stream); - } else { - _cairo_output_stream_printf (ctx->stream, - " ] %f [ ", glyphs[n].x - x); - } - - x = glyphs[n].x; - } else { - ix = x = glyphs[n].x; - iy = y = glyphs[n].y; - cairo_matrix_transform_point (&matrix, &ix, &iy); - ix -= scaled_font->font_matrix.x0; - iy -= scaled_font->font_matrix.y0; - if (base85_stream != NULL) { - status = _cairo_output_stream_destroy (base85_stream); - if (unlikely (status)) { - base85_stream = NULL; - break; - } - - _cairo_output_stream_printf (ctx->stream, - "~> %f %f <~", - ix, iy); - base85_stream = _cairo_base85_stream_create (ctx->stream); - } else { - _cairo_output_stream_printf (ctx->stream, - " ] %f %f [ ", - ix, iy); - } - } - } - if (base85_stream != NULL) { - uint8_t c; - - if (font_private->has_sfnt) - c = glyphs[n].index; - else - c = (uint8_t) (long unsigned) scaled_glyph->dev_private; - - _cairo_output_stream_write (base85_stream, &c, 1); - } else { - if (font_private->has_sfnt) - _cairo_output_stream_printf (ctx->stream, " %lu", - glyphs[n].index); - else - _cairo_output_stream_printf (ctx->stream, " %lu", - (long unsigned) scaled_glyph->dev_private); - } - - dx = scaled_glyph->metrics.x_advance; - dy = scaled_glyph->metrics.y_advance; - cairo_matrix_transform_distance (&scaled_font->ctm, &dx, &dy); - x += dx; - y += dy; - } - _cairo_scaled_font_thaw_cache (scaled_font); - - if (base85_stream != NULL) { - cairo_status_t status2; - - status2 = _cairo_output_stream_destroy (base85_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - _cairo_output_stream_printf (ctx->stream, "~>"); - } else { - _cairo_output_stream_puts (ctx->stream, " ]"); - } - if (unlikely (status)) - return status; - - if (utf8 != NULL && clusters != NULL) { - for (n = 0; n < num_clusters; n++) { - if (clusters[n].num_bytes > UCHAR_MAX || - clusters[n].num_glyphs > UCHAR_MAX) - { - break; - } - } - - if (n < num_clusters) { - _cairo_output_stream_puts (ctx->stream, "] [ "); - for (n = 0; n < num_clusters; n++) { - _cairo_output_stream_printf (ctx->stream, - "%d %d ", - clusters[n].num_bytes, - clusters[n].num_glyphs); - } - _cairo_output_stream_puts (ctx->stream, "]"); - } - else - { - _cairo_output_stream_puts (ctx->stream, "] <~"); - base85_stream = _cairo_base85_stream_create (ctx->stream); - for (n = 0; n < num_clusters; n++) { - uint8_t c[2]; - c[0] = clusters[n].num_bytes; - c[1] = clusters[n].num_glyphs; - _cairo_output_stream_write (base85_stream, c, 2); - } - status = _cairo_output_stream_destroy (base85_stream); - if (unlikely (status)) - goto BAIL; - - _cairo_output_stream_puts (ctx->stream, "~>"); - } - - _cairo_output_stream_printf (ctx->stream, - " //%s show-text-glyphs\n", - _direction_to_string (backward)); - } else { - _cairo_output_stream_puts (ctx->stream, - "] show-glyphs\n"); - } - - inactive (surface); - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)){ - return _cairo_surface_wrapper_show_text_glyphs (&surface->wrapper, - op, source, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - backward, - scaled_font, - clip); - } - - return CAIRO_STATUS_SUCCESS; - -BAIL: - inactive (surface); - return status; -} - -static cairo_bool_t -_cairo_script_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_script_surface_t *surface = abstract_surface; - - if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { - return _cairo_surface_wrapper_get_extents (&surface->wrapper, - rectangle); - } - - if (surface->width < 0 || surface->height < 0) - return FALSE; - - rectangle->x = 0; - rectangle->y = 0; - rectangle->width = surface->width; - rectangle->height = surface->height; - - return TRUE; -} - -static const cairo_surface_backend_t -_cairo_script_surface_backend = { - CAIRO_SURFACE_TYPE_SCRIPT, - _cairo_script_surface_finish, - - _cairo_default_context_create, - - _cairo_script_surface_create_similar, - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_script_surface_source, - _cairo_script_surface_acquire_source_image, - _cairo_script_surface_release_source_image, - _cairo_script_surface_snapshot, - - _cairo_script_surface_copy_page, - _cairo_script_surface_show_page, - - _cairo_script_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_script_surface_paint, - _cairo_script_surface_mask, - _cairo_script_surface_stroke, - _cairo_script_surface_fill, - NULL, /* fill/stroke */ - NULL, /* glyphs */ - _cairo_script_surface_has_show_text_glyphs, - _cairo_script_surface_show_text_glyphs -}; - -static void -_cairo_script_implicit_context_init (cairo_script_implicit_context_t *cr) -{ - cr->current_operator = CAIRO_GSTATE_OPERATOR_DEFAULT; - cr->current_fill_rule = CAIRO_GSTATE_FILL_RULE_DEFAULT; - cr->current_tolerance = CAIRO_GSTATE_TOLERANCE_DEFAULT; - cr->current_antialias = CAIRO_ANTIALIAS_DEFAULT; - _cairo_stroke_style_init (&cr->current_style); - _cairo_pattern_init_solid (&cr->current_source.solid, - CAIRO_COLOR_BLACK); - _cairo_path_fixed_init (&cr->current_path); - cairo_matrix_init_identity (&cr->current_ctm); - cairo_matrix_init_identity (&cr->current_stroke_matrix); - cairo_matrix_init_identity (&cr->current_font_matrix); - _cairo_font_options_init_default (&cr->current_font_options); - cr->current_scaled_font = NULL; - cr->has_clip = FALSE; -} - -static void -_cairo_script_implicit_context_reset (cairo_script_implicit_context_t *cr) -{ - free (cr->current_style.dash); - cr->current_style.dash = NULL; - - _cairo_pattern_fini (&cr->current_source.base); - _cairo_path_fixed_fini (&cr->current_path); - - _cairo_script_implicit_context_init (cr); -} - -static cairo_script_surface_t * -_cairo_script_surface_create_internal (cairo_script_context_t *ctx, - cairo_content_t content, - cairo_rectangle_t *extents, - cairo_surface_t *passthrough) -{ - cairo_script_surface_t *surface; - - if (unlikely (ctx == NULL)) - return (cairo_script_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); - - surface = malloc (sizeof (cairo_script_surface_t)); - if (unlikely (surface == NULL)) - return (cairo_script_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_script_surface_backend, - &ctx->base, - content); - - _cairo_surface_wrapper_init (&surface->wrapper, passthrough); - - _cairo_surface_clipper_init (&surface->clipper, - _cairo_script_surface_clipper_intersect_clip_path); - - surface->width = surface->height = -1; - if (extents) { - surface->width = extents->width; - surface->height = extents->height; - cairo_surface_set_device_offset (&surface->base, - -extents->x, -extents->y); - } - - surface->emitted = FALSE; - surface->defined = FALSE; - surface->active = FALSE; - surface->operand.type = SURFACE; - cairo_list_init (&surface->operand.link); - - _cairo_script_implicit_context_init (&surface->cr); - - return surface; -} - -static const cairo_device_backend_t _cairo_script_device_backend = { - CAIRO_DEVICE_TYPE_SCRIPT, - - NULL, NULL, /* lock, unlock */ - - _device_flush, /* flush */ - NULL, /* finish */ - _device_destroy -}; - -cairo_device_t * -_cairo_script_context_create_internal (cairo_output_stream_t *stream) -{ - cairo_script_context_t *ctx; - - ctx = malloc (sizeof (cairo_script_context_t)); - if (unlikely (ctx == NULL)) - return _cairo_device_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - memset (ctx, 0, sizeof (cairo_script_context_t)); - - _cairo_device_init (&ctx->base, &_cairo_script_device_backend); - - cairo_list_init (&ctx->operands); - cairo_list_init (&ctx->deferred); - ctx->stream = stream; - ctx->mode = CAIRO_SCRIPT_MODE_ASCII; - - cairo_list_init (&ctx->fonts); - cairo_list_init (&ctx->defines); - - ctx->attach_snapshots = TRUE; - - return &ctx->base; -} - -void -_cairo_script_context_attach_snapshots (cairo_device_t *device, - cairo_bool_t enable) -{ - cairo_script_context_t *ctx; - - ctx = (cairo_script_context_t *) device; - ctx->attach_snapshots = enable; -} - -static cairo_device_t * -_cairo_script_context_create (cairo_output_stream_t *stream) -{ - cairo_script_context_t *ctx; - - ctx = (cairo_script_context_t *) - _cairo_script_context_create_internal (stream); - if (unlikely (ctx->base.status)) - return &ctx->base; - - ctx->owns_stream = TRUE; - _cairo_output_stream_puts (ctx->stream, "%!CairoScript\n"); - return &ctx->base; -} - -/** - * cairo_script_create: - * @filename: the name (path) of the file to write the script to - * - * Creates a output device for emitting the script, used when - * creating the individual surfaces. - * - * Return value: a pointer to the newly created device. The caller - * owns the surface and should call cairo_device_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" device if an error such as out of memory - * occurs. You can use cairo_device_status() to check for this. - * - * Since: 1.12 - **/ -cairo_device_t * -cairo_script_create (const char *filename) -{ - cairo_output_stream_t *stream; - cairo_status_t status; - - stream = _cairo_output_stream_create_for_filename (filename); - if ((status = _cairo_output_stream_get_status (stream))) - return _cairo_device_create_in_error (status); - - return _cairo_script_context_create (stream); -} - -/** - * cairo_script_create_for_stream: - * @write_func: callback function passed the bytes written to the script - * @closure: user data to be passed to the callback - * - * Creates a output device for emitting the script, used when - * creating the individual surfaces. - * - * Return value: a pointer to the newly created device. The caller - * owns the surface and should call cairo_device_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" device if an error such as out of memory - * occurs. You can use cairo_device_status() to check for this. - * - * Since: 1.12 - **/ -cairo_device_t * -cairo_script_create_for_stream (cairo_write_func_t write_func, - void *closure) -{ - cairo_output_stream_t *stream; - cairo_status_t status; - - stream = _cairo_output_stream_create (write_func, NULL, closure); - if ((status = _cairo_output_stream_get_status (stream))) - return _cairo_device_create_in_error (status); - - return _cairo_script_context_create (stream); -} - -/** - * cairo_script_write_comment: - * @script: the script (output device) - * @comment: the string to emit - * @len:the length of the sting to write, or -1 to use strlen() - * - * Emit a string verbatim into the script. - * - * Since: 1.12 - **/ -void -cairo_script_write_comment (cairo_device_t *script, - const char *comment, - int len) -{ - cairo_script_context_t *context = (cairo_script_context_t *) script; - - if (len < 0) - len = strlen (comment); - - _cairo_output_stream_puts (context->stream, "% "); - _cairo_output_stream_write (context->stream, comment, len); - _cairo_output_stream_puts (context->stream, "\n"); -} - -/** - * cairo_script_set_mode: - * @script: The script (output device) - * @mode: the new mode - * - * Change the output mode of the script - * - * Since: 1.12 - **/ -void -cairo_script_set_mode (cairo_device_t *script, - cairo_script_mode_t mode) -{ - cairo_script_context_t *context = (cairo_script_context_t *) script; - - context->mode = mode; -} - -/** - * cairo_script_get_mode: - * @script: The script (output device) to query - * - * Queries the script for its current output mode. - * - * Return value: the current output mode of the script - * - * Since: 1.12 - **/ -cairo_script_mode_t -cairo_script_get_mode (cairo_device_t *script) -{ - cairo_script_context_t *context = (cairo_script_context_t *) script; - - return context->mode; -} - -/** - * cairo_script_surface_create: - * @script: the script (output device) - * @content: the content of the surface - * @width: width in pixels - * @height: height in pixels - * - * Create a new surface that will emit its rendering through @script - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_script_surface_create (cairo_device_t *script, - cairo_content_t content, - double width, - double height) -{ - cairo_rectangle_t *extents, r; - - if (unlikely (script->backend->type != CAIRO_DEVICE_TYPE_SCRIPT)) - return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - - if (unlikely (script->status)) - return _cairo_surface_create_in_error (script->status); - - extents = NULL; - if (width > 0 && height > 0) { - r.x = r.y = 0; - r.width = width; - r.height = height; - extents = &r; - } - return &_cairo_script_surface_create_internal ((cairo_script_context_t *) script, - content, extents, - NULL)->base; -} -slim_hidden_def (cairo_script_surface_create); - -/** - * cairo_script_surface_create_for_target: - * @script: the script (output device) - * @target: a target surface to wrap - * - * Create a pxoy surface that will render to @target and record - * the operations to @device. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_script_surface_create_for_target (cairo_device_t *script, - cairo_surface_t *target) -{ - cairo_rectangle_int_t extents; - cairo_rectangle_t rect, *r; - - if (unlikely (script->backend->type != CAIRO_DEVICE_TYPE_SCRIPT)) - return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - - if (unlikely (script->status)) - return _cairo_surface_create_in_error (script->status); - - if (unlikely (target->status)) - return _cairo_surface_create_in_error (target->status); - - r = NULL; - if (_cairo_surface_get_extents (target, &extents)) { - rect.x = rect.y = 0; - rect.width = extents.width; - rect.height = extents.height; - r= ▭ - } - return &_cairo_script_surface_create_internal ((cairo_script_context_t *) script, - target->content, r, - target)->base; -} - -/** - * cairo_script_from_recording_surface: - * @script: the script (output device) - * @recording_surface: the recording surface to replay - * - * Converts the record operations in @recording_surface into a script. - * - * Return value: #CAIRO_STATUS_SUCCESS on successful completion or an error code. - * - * Since: 1.12 - **/ -cairo_status_t -cairo_script_from_recording_surface (cairo_device_t *script, - cairo_surface_t *recording_surface) -{ - cairo_rectangle_t r, *extents; - cairo_surface_t *surface; - cairo_status_t status; - - if (unlikely (script->backend->type != CAIRO_DEVICE_TYPE_SCRIPT)) - return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - - if (unlikely (script->status)) - return _cairo_error (script->status); - - if (unlikely (recording_surface->status)) - return recording_surface->status; - - if (unlikely (! _cairo_surface_is_recording (recording_surface))) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - extents = NULL; - if (_cairo_recording_surface_get_bounds (recording_surface, &r)) - extents = &r; - - surface = &_cairo_script_surface_create_internal ((cairo_script_context_t *) script, - recording_surface->content, - extents, - NULL)->base; - if (unlikely (surface->status)) - return surface->status; - - status = _cairo_recording_surface_replay (recording_surface, surface); - cairo_surface_destroy (surface); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script.h deleted file mode 100644 index b5a8cf32d0b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-script.h +++ /dev/null @@ -1,98 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SCRIPT_H -#define CAIRO_SCRIPT_H - -#include "cairo.h" - -#if CAIRO_HAS_SCRIPT_SURFACE - -CAIRO_BEGIN_DECLS - -/** - * cairo_script_mode_t: - * @CAIRO_SCRIPT_MODE_ASCII: the output will be in readable text (default). (Since 1.12) - * @CAIRO_SCRIPT_MODE_BINARY: the output will use byte codes. (Since 1.12) - * - * A set of script output variants. - * - * Since: 1.12 - **/ -typedef enum { - CAIRO_SCRIPT_MODE_ASCII, - CAIRO_SCRIPT_MODE_BINARY -} cairo_script_mode_t; - -cairo_public cairo_device_t * -cairo_script_create (const char *filename); - -cairo_public cairo_device_t * -cairo_script_create_for_stream (cairo_write_func_t write_func, - void *closure); - -cairo_public void -cairo_script_write_comment (cairo_device_t *script, - const char *comment, - int len); - -cairo_public void -cairo_script_set_mode (cairo_device_t *script, - cairo_script_mode_t mode); - -cairo_public cairo_script_mode_t -cairo_script_get_mode (cairo_device_t *script); - -cairo_public cairo_surface_t * -cairo_script_surface_create (cairo_device_t *script, - cairo_content_t content, - double width, - double height); - -cairo_public cairo_surface_t * -cairo_script_surface_create_for_target (cairo_device_t *script, - cairo_surface_t *target); - -cairo_public cairo_status_t -cairo_script_from_recording_surface (cairo_device_t *script, - cairo_surface_t *recording_surface); - -CAIRO_END_DECLS - -#else /*CAIRO_HAS_SCRIPT_SURFACE*/ -# error Cairo was not compiled with support for the CairoScript backend -#endif /*CAIRO_HAS_SCRIPT_SURFACE*/ - -#endif /*CAIRO_SCRIPT_H*/ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-shape-mask-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-shape-mask-compositor.c deleted file mode 100644 index 3117267cccf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-shape-mask-compositor.c +++ /dev/null @@ -1,340 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2012 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-compositor-private.h" -#include "cairo-clip-private.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-private.h" -#include "cairo-surface-offset-private.h" - -static cairo_int_status_t -_cairo_shape_mask_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_surface_t *mask; - cairo_surface_pattern_t pattern; - cairo_int_status_t status; - cairo_clip_t *clip; - - if (! extents->is_bounded) - return CAIRO_INT_STATUS_UNSUPPORTED; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - mask = _cairo_surface_create_scratch (extents->surface, - CAIRO_CONTENT_ALPHA, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (mask->status)) - return mask->status; - - clip = extents->clip; - if (! _cairo_clip_is_region (clip)) - clip = _cairo_clip_copy_region (clip); - - if (! mask->is_clear) { - status = _cairo_surface_offset_paint (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - clip); - if (unlikely (status)) - goto error; - } - - status = _cairo_surface_offset_stroke (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - path, style, ctm, ctm_inverse, - tolerance, antialias, - clip); - if (unlikely (status)) - goto error; - - if (clip != extents->clip) { - status = _cairo_clip_combine_with_surface (extents->clip, mask, - extents->bounded.x, - extents->bounded.y); - if (unlikely (status)) - goto error; - } - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->bounded.x, - -extents->bounded.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - if (extents->op == CAIRO_OPERATOR_SOURCE) { - status = _cairo_surface_mask (extents->surface, - CAIRO_OPERATOR_DEST_OUT, - &_cairo_pattern_white.base, - &pattern.base, - clip); - if ((status == CAIRO_INT_STATUS_SUCCESS)) { - status = _cairo_surface_mask (extents->surface, - CAIRO_OPERATOR_ADD, - &extents->source_pattern.base, - &pattern.base, - clip); - } - } else { - status = _cairo_surface_mask (extents->surface, - extents->op, - &extents->source_pattern.base, - &pattern.base, - clip); - } - _cairo_pattern_fini (&pattern.base); - -error: - cairo_surface_destroy (mask); - if (clip != extents->clip) - _cairo_clip_destroy (clip); - return status; -} - -static cairo_int_status_t -_cairo_shape_mask_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_surface_t *mask; - cairo_surface_pattern_t pattern; - cairo_int_status_t status; - cairo_clip_t *clip; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (! extents->is_bounded) - return CAIRO_INT_STATUS_UNSUPPORTED; - - mask = _cairo_surface_create_scratch (extents->surface, - CAIRO_CONTENT_ALPHA, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (mask->status)) - return mask->status; - - clip = extents->clip; - if (! _cairo_clip_is_region (clip)) - clip = _cairo_clip_copy_region (clip); - - if (! mask->is_clear) { - status = _cairo_surface_offset_paint (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - clip); - if (unlikely (status)) - goto error; - } - - status = _cairo_surface_offset_fill (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - path, fill_rule, tolerance, antialias, - clip); - if (unlikely (status)) - goto error; - - if (clip != extents->clip) { - status = _cairo_clip_combine_with_surface (extents->clip, mask, - extents->bounded.x, - extents->bounded.y); - if (unlikely (status)) - goto error; - } - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->bounded.x, - -extents->bounded.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - if (extents->op == CAIRO_OPERATOR_SOURCE) { - status = _cairo_surface_mask (extents->surface, - CAIRO_OPERATOR_DEST_OUT, - &_cairo_pattern_white.base, - &pattern.base, - clip); - if ((status == CAIRO_INT_STATUS_SUCCESS)) { - status = _cairo_surface_mask (extents->surface, - CAIRO_OPERATOR_ADD, - &extents->source_pattern.base, - &pattern.base, - clip); - } - } else { - status = _cairo_surface_mask (extents->surface, - extents->op, - &extents->source_pattern.base, - &pattern.base, - clip); - } - _cairo_pattern_fini (&pattern.base); - -error: - if (clip != extents->clip) - _cairo_clip_destroy (clip); - cairo_surface_destroy (mask); - return status; -} - -static cairo_int_status_t -_cairo_shape_mask_compositor_glyphs (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_surface_t *mask; - cairo_surface_pattern_t pattern; - cairo_int_status_t status; - cairo_clip_t *clip; - - if (! extents->is_bounded) - return CAIRO_INT_STATUS_UNSUPPORTED; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - mask = _cairo_surface_create_scratch (extents->surface, - CAIRO_CONTENT_ALPHA, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (mask->status)) - return mask->status; - - clip = extents->clip; - if (! _cairo_clip_is_region (clip)) - clip = _cairo_clip_copy_region (clip); - - if (! mask->is_clear) { - status = _cairo_surface_offset_paint (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - clip); - if (unlikely (status)) - goto error; - } - - status = _cairo_surface_offset_glyphs (mask, - extents->bounded.x, - extents->bounded.y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - scaled_font, glyphs, num_glyphs, - clip); - if (unlikely (status)) - goto error; - - if (clip != extents->clip) { - status = _cairo_clip_combine_with_surface (extents->clip, mask, - extents->bounded.x, - extents->bounded.y); - if (unlikely (status)) - goto error; - } - - _cairo_pattern_init_for_surface (&pattern, mask); - cairo_matrix_init_translate (&pattern.base.matrix, - -extents->bounded.x, - -extents->bounded.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - pattern.base.extend = CAIRO_EXTEND_NONE; - if (extents->op == CAIRO_OPERATOR_SOURCE) { - status = _cairo_surface_mask (extents->surface, - CAIRO_OPERATOR_DEST_OUT, - &_cairo_pattern_white.base, - &pattern.base, - clip); - if ((status == CAIRO_INT_STATUS_SUCCESS)) { - status = _cairo_surface_mask (extents->surface, - CAIRO_OPERATOR_ADD, - &extents->source_pattern.base, - &pattern.base, - clip); - } - } else { - status = _cairo_surface_mask (extents->surface, - extents->op, - &extents->source_pattern.base, - &pattern.base, - clip); - } - _cairo_pattern_fini (&pattern.base); - -error: - if (clip != extents->clip) - _cairo_clip_destroy (clip); - cairo_surface_destroy (mask); - return status; -} - -void -_cairo_shape_mask_compositor_init (cairo_compositor_t *compositor, - const cairo_compositor_t *delegate) -{ - compositor->delegate = delegate; - - compositor->paint = NULL; - compositor->mask = NULL; - compositor->fill = _cairo_shape_mask_compositor_fill; - compositor->stroke = _cairo_shape_mask_compositor_stroke; - compositor->glyphs = _cairo_shape_mask_compositor_glyphs; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-skia.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-skia.h deleted file mode 100644 index 99b92865699..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-skia.h +++ /dev/null @@ -1,66 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_SKIA_H -#define CAIRO_SKIA_H - -#include "cairo.h" - -#if CAIRO_HAS_SKIA_SURFACE - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_skia_surface_create (cairo_format_t format, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_skia_surface_create_for_data (unsigned char *data, - cairo_format_t format, - int width, - int height, - int stride); - -CAIRO_END_DECLS - -#else - -# error Cairo was not compiled with support for the Skia backend - -#endif - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope-private.h deleted file mode 100644 index 6a58c9f456d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope-private.h +++ /dev/null @@ -1,72 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef _CAIRO_SLOPE_PRIVATE_H -#define _CAIRO_SLOPE_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-fixed-private.h" - -static inline void -_cairo_slope_init (cairo_slope_t *slope, - const cairo_point_t *a, - const cairo_point_t *b) -{ - slope->dx = b->x - a->x; - slope->dy = b->y - a->y; -} - -static inline cairo_bool_t -_cairo_slope_equal (const cairo_slope_t *a, const cairo_slope_t *b) -{ - return _cairo_int64_eq (_cairo_int32x32_64_mul (a->dy, b->dx), - _cairo_int32x32_64_mul (b->dy, a->dx)); -} - -static inline cairo_bool_t -_cairo_slope_backwards (const cairo_slope_t *a, const cairo_slope_t *b) -{ - return _cairo_int64_negative (_cairo_int64_add (_cairo_int32x32_64_mul (a->dx, b->dx), - _cairo_int32x32_64_mul (a->dy, b->dy))); -} - -cairo_private int -_cairo_slope_compare (const cairo_slope_t *a, - const cairo_slope_t *b) cairo_pure; - - -#endif /* _CAIRO_SLOPE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope.c deleted file mode 100644 index cc5f30cb0b3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-slope.c +++ /dev/null @@ -1,99 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-slope-private.h" - -/* Compare two slopes. Slope angles begin at 0 in the direction of the - positive X axis and increase in the direction of the positive Y - axis. - - This function always compares the slope vectors based on the - smaller angular difference between them, (that is based on an - angular difference that is strictly less than pi). To break ties - when comparing slope vectors with an angular difference of exactly - pi, the vector with a positive dx (or positive dy if dx's are zero) - is considered to be more positive than the other. - - Also, all slope vectors with both dx==0 and dy==0 are considered - equal and more positive than any non-zero vector. - - < 0 => a less positive than b - == 0 => a equal to b - > 0 => a more positive than b -*/ -int -_cairo_slope_compare (const cairo_slope_t *a, const cairo_slope_t *b) -{ - cairo_int64_t ady_bdx = _cairo_int32x32_64_mul (a->dy, b->dx); - cairo_int64_t bdy_adx = _cairo_int32x32_64_mul (b->dy, a->dx); - int cmp; - - cmp = _cairo_int64_cmp (ady_bdx, bdy_adx); - if (cmp) - return cmp; - - /* special-case zero vectors. the intended logic here is: - * zero vectors all compare equal, and more positive than any - * non-zero vector. - */ - if (a->dx == 0 && a->dy == 0 && b->dx == 0 && b->dy ==0) - return 0; - if (a->dx == 0 && a->dy == 0) - return 1; - if (b->dx == 0 && b->dy ==0) - return -1; - - /* Finally, we're looking at two vectors that are either equal or - * that differ by exactly pi. We can identify the "differ by pi" - * case by looking for a change in sign in either dx or dy between - * a and b. - * - * And in these cases, we eliminate the ambiguity by reducing the angle - * of b by an infinitesimally small amount, (that is, 'a' will - * always be considered less than 'b'). - */ - if ((a->dx ^ b->dx) < 0 || (a->dy ^ b->dy) < 0) { - if (a->dx > 0 || (a->dx == 0 && a->dy > 0)) - return -1; - else - return +1; - } - - /* Finally, for identical slopes, we obviously return 0. */ - return 0; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor-private.h deleted file mode 100644 index 0babebd26b5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor-private.h +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SPANS_COMPOSITOR_PRIVATE_H -#define CAIRO_SPANS_COMPOSITOR_PRIVATE_H - -#include "cairo-compositor-private.h" -#include "cairo-types-private.h" -#include "cairo-spans-private.h" - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_abstract_span_renderer { - cairo_span_renderer_t base; - char data[4096]; -} cairo_abstract_span_renderer_t; - -struct cairo_spans_compositor { - cairo_compositor_t base; - - unsigned int flags; -#define CAIRO_SPANS_COMPOSITOR_HAS_LERP 0x1 - - /* pixel-aligned fast paths */ - cairo_int_status_t (*fill_boxes) (void *surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes); - - cairo_int_status_t (*draw_image_boxes) (void *surface, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy); - - cairo_int_status_t (*copy_boxes) (void *surface, - cairo_surface_t *src, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents, - int dx, int dy); - - cairo_surface_t * (*pattern_to_surface) (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y); - - cairo_int_status_t (*composite_boxes) (void *surface, - cairo_operator_t op, - cairo_surface_t *source, - cairo_surface_t *mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents); - - /* general shape masks using a span renderer */ - cairo_int_status_t (*renderer_init) (cairo_abstract_span_renderer_t *renderer, - const cairo_composite_rectangles_t *extents, - cairo_antialias_t antialias, - cairo_bool_t needs_clip); - - void (*renderer_fini) (cairo_abstract_span_renderer_t *renderer, - cairo_int_status_t status); -}; - -cairo_private void -_cairo_spans_compositor_init (cairo_spans_compositor_t *compositor, - const cairo_compositor_t *delegate); - -CAIRO_END_DECLS - -#endif /* CAIRO_SPANS_COMPOSITOR_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor.c deleted file mode 100644 index efbae254bf4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-compositor.c +++ /dev/null @@ -1,1201 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-compositor-private.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-paginated-private.h" -#include "cairo-pattern-inline.h" -#include "cairo-region-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-spans-compositor-private.h" -#include "cairo-surface-subsurface-private.h" -#include "cairo-surface-snapshot-private.h" -#include "cairo-surface-observer-private.h" - -typedef struct { - cairo_polygon_t *polygon; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; -} composite_spans_info_t; - -static cairo_int_status_t -composite_polygon (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias); - -static cairo_int_status_t -composite_boxes (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes); - -static cairo_int_status_t -clip_and_composite_polygon (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias); -static cairo_surface_t * -get_clip_surface (const cairo_spans_compositor_t *compositor, - cairo_surface_t *dst, - const cairo_clip_t *clip, - const cairo_rectangle_int_t *extents) -{ - cairo_composite_rectangles_t composite; - cairo_surface_t *surface; - cairo_box_t box; - cairo_polygon_t polygon; - const cairo_clip_path_t *clip_path; - cairo_antialias_t antialias; - cairo_fill_rule_t fill_rule; - cairo_int_status_t status; - - assert (clip->path); - - surface = _cairo_surface_create_scratch (dst, - CAIRO_CONTENT_ALPHA, - extents->width, - extents->height, - CAIRO_COLOR_TRANSPARENT); - - _cairo_box_from_rectangle (&box, extents); - _cairo_polygon_init (&polygon, &box, 1); - - clip_path = clip->path; - status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, - clip_path->tolerance, - &polygon); - if (unlikely (status)) - goto cleanup_polygon; - - polygon.num_limits = 0; - - antialias = clip_path->antialias; - fill_rule = clip_path->fill_rule; - - if (clip->boxes) { - cairo_polygon_t intersect; - cairo_boxes_t tmp; - - _cairo_boxes_init_for_array (&tmp, clip->boxes, clip->num_boxes); - status= _cairo_polygon_init_boxes (&intersect, &tmp); - if (unlikely (status)) - goto cleanup_polygon; - - status = _cairo_polygon_intersect (&polygon, fill_rule, - &intersect, CAIRO_FILL_RULE_WINDING); - _cairo_polygon_fini (&intersect); - - if (unlikely (status)) - goto cleanup_polygon; - - fill_rule = CAIRO_FILL_RULE_WINDING; - } - - polygon.limits = NULL; - polygon.num_limits = 0; - - clip_path = clip_path->prev; - while (clip_path) { - if (clip_path->antialias == antialias) { - cairo_polygon_t next; - - _cairo_polygon_init (&next, NULL, 0); - status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, - clip_path->tolerance, - &next); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = _cairo_polygon_intersect (&polygon, fill_rule, - &next, clip_path->fill_rule); - _cairo_polygon_fini (&next); - if (unlikely (status)) - goto cleanup_polygon; - - fill_rule = CAIRO_FILL_RULE_WINDING; - } - - clip_path = clip_path->prev; - } - - _cairo_polygon_translate (&polygon, -extents->x, -extents->y); - status = _cairo_composite_rectangles_init_for_polygon (&composite, surface, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - &polygon, - NULL); - if (unlikely (status)) - goto cleanup_polygon; - - status = composite_polygon (compositor, &composite, - &polygon, fill_rule, antialias); - _cairo_composite_rectangles_fini (&composite); - _cairo_polygon_fini (&polygon); - if (unlikely (status)) - goto error; - - _cairo_polygon_init (&polygon, &box, 1); - - clip_path = clip->path; - antialias = clip_path->antialias == CAIRO_ANTIALIAS_DEFAULT ? CAIRO_ANTIALIAS_NONE : CAIRO_ANTIALIAS_DEFAULT; - clip_path = clip_path->prev; - while (clip_path) { - if (clip_path->antialias == antialias) { - if (polygon.num_edges == 0) { - status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, - clip_path->tolerance, - &polygon); - - fill_rule = clip_path->fill_rule; - polygon.limits = NULL; - polygon.num_limits = 0; - } else { - cairo_polygon_t next; - - _cairo_polygon_init (&next, NULL, 0); - status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, - clip_path->tolerance, - &next); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = _cairo_polygon_intersect (&polygon, fill_rule, - &next, clip_path->fill_rule); - _cairo_polygon_fini (&next); - fill_rule = CAIRO_FILL_RULE_WINDING; - } - if (unlikely (status)) - goto error; - } - - clip_path = clip_path->prev; - } - - if (polygon.num_edges) { - _cairo_polygon_translate (&polygon, -extents->x, -extents->y); - status = _cairo_composite_rectangles_init_for_polygon (&composite, surface, - CAIRO_OPERATOR_IN, - &_cairo_pattern_white.base, - &polygon, - NULL); - if (unlikely (status)) - goto cleanup_polygon; - - status = composite_polygon (compositor, &composite, - &polygon, fill_rule, antialias); - _cairo_composite_rectangles_fini (&composite); - _cairo_polygon_fini (&polygon); - if (unlikely (status)) - goto error; - } - - return surface; - -cleanup_polygon: - _cairo_polygon_fini (&polygon); -error: - cairo_surface_destroy (surface); - return _cairo_int_surface_create_in_error (status); -} - -static cairo_int_status_t -fixup_unbounded_mask (const cairo_spans_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_composite_rectangles_t composite; - cairo_surface_t *clip; - cairo_int_status_t status; - - TRACE((stderr, "%s\n", __FUNCTION__)); - - clip = get_clip_surface (compositor, extents->surface, extents->clip, - &extents->unbounded); - if (unlikely (clip->status)) { - if ((cairo_int_status_t)clip->status == CAIRO_INT_STATUS_NOTHING_TO_DO) - return CAIRO_STATUS_SUCCESS; - - return clip->status; - } - - status = _cairo_composite_rectangles_init_for_boxes (&composite, - extents->surface, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - boxes, - NULL); - if (unlikely (status)) - goto cleanup_clip; - - _cairo_pattern_init_for_surface (&composite.mask_pattern.surface, clip); - composite.mask_pattern.base.filter = CAIRO_FILTER_NEAREST; - composite.mask_pattern.base.extend = CAIRO_EXTEND_NONE; - - status = composite_boxes (compositor, &composite, boxes); - - _cairo_pattern_fini (&composite.mask_pattern.base); - _cairo_composite_rectangles_fini (&composite); - -cleanup_clip: - cairo_surface_destroy (clip); - return status; -} - -static cairo_int_status_t -fixup_unbounded_polygon (const cairo_spans_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_polygon_t polygon, intersect; - cairo_composite_rectangles_t composite; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - cairo_int_status_t status; - - TRACE((stderr, "%s\n", __FUNCTION__)); - - /* Can we treat the clip as a regular clear-polygon and use it to fill? */ - status = _cairo_clip_get_polygon (extents->clip, &polygon, - &fill_rule, &antialias); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status= _cairo_polygon_init_boxes (&intersect, boxes); - if (unlikely (status)) - goto cleanup_polygon; - - status = _cairo_polygon_intersect (&polygon, fill_rule, - &intersect, CAIRO_FILL_RULE_WINDING); - _cairo_polygon_fini (&intersect); - - if (unlikely (status)) - goto cleanup_polygon; - - status = _cairo_composite_rectangles_init_for_polygon (&composite, - extents->surface, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - &polygon, - NULL); - if (unlikely (status)) - goto cleanup_polygon; - - status = composite_polygon (compositor, &composite, - &polygon, fill_rule, antialias); - - _cairo_composite_rectangles_fini (&composite); -cleanup_polygon: - _cairo_polygon_fini (&polygon); - - return status; -} - -static cairo_int_status_t -fixup_unbounded_boxes (const cairo_spans_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_boxes_t tmp, clear; - cairo_box_t box; - cairo_int_status_t status; - - assert (boxes->is_pixel_aligned); - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (extents->bounded.width == extents->unbounded.width && - extents->bounded.height == extents->unbounded.height) - { - return CAIRO_STATUS_SUCCESS; - } - - /* subtract the drawn boxes from the unbounded area */ - _cairo_boxes_init (&clear); - - box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); - box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); - box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); - box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); - - if (boxes->num_boxes) { - _cairo_boxes_init (&tmp); - - status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - tmp.chunks.next = &boxes->chunks; - tmp.num_boxes += boxes->num_boxes; - - status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, - CAIRO_FILL_RULE_WINDING, - &clear); - tmp.chunks.next = NULL; - if (unlikely (status)) - goto error; - } else { - box.p1.x = _cairo_fixed_from_int (extents->unbounded.x); - box.p2.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); - - status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - /* If we have a clip polygon, we need to intersect with that as well */ - if (extents->clip->path) { - status = fixup_unbounded_polygon (compositor, extents, &clear); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - status = fixup_unbounded_mask (compositor, extents, &clear); - } else { - /* Otherwise just intersect with the clip boxes */ - if (extents->clip->num_boxes) { - _cairo_boxes_init_for_array (&tmp, - extents->clip->boxes, - extents->clip->num_boxes); - status = _cairo_boxes_intersect (&clear, &tmp, &clear); - if (unlikely (status)) - goto error; - } - - if (clear.is_pixel_aligned) { - status = compositor->fill_boxes (extents->surface, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - } else { - cairo_composite_rectangles_t composite; - - status = _cairo_composite_rectangles_init_for_boxes (&composite, - extents->surface, - CAIRO_OPERATOR_CLEAR, - &_cairo_pattern_clear.base, - &clear, - NULL); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - status = composite_boxes (compositor, &composite, &clear); - _cairo_composite_rectangles_fini (&composite); - } - } - } - -error: - _cairo_boxes_fini (&clear); - return status; -} - -static cairo_surface_t * -unwrap_source (const cairo_pattern_t *pattern) -{ - cairo_rectangle_int_t limit; - - return _cairo_pattern_get_source ((cairo_surface_pattern_t *)pattern, - &limit); -} - -static cairo_bool_t -is_recording_pattern (const cairo_pattern_t *pattern) -{ - cairo_surface_t *surface; - - if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) - return FALSE; - - surface = ((const cairo_surface_pattern_t *) pattern)->surface; - return _cairo_surface_is_recording (surface); -} - -static cairo_bool_t -recording_pattern_contains_sample (const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *sample) -{ - cairo_recording_surface_t *surface; - - if (! is_recording_pattern (pattern)) - return FALSE; - - if (pattern->extend == CAIRO_EXTEND_NONE) - return TRUE; - - surface = (cairo_recording_surface_t *) unwrap_source (pattern); - if (surface->unbounded) - return TRUE; - - return _cairo_rectangle_contains_rectangle (&surface->extents, sample); -} - -static cairo_bool_t -op_reduces_to_source (const cairo_composite_rectangles_t *extents, - cairo_bool_t no_mask) -{ - if (extents->op == CAIRO_OPERATOR_SOURCE) - return TRUE; - - if (extents->surface->is_clear) - return extents->op == CAIRO_OPERATOR_OVER || extents->op == CAIRO_OPERATOR_ADD; - - if (no_mask && extents->op == CAIRO_OPERATOR_OVER) - return _cairo_pattern_is_opaque (&extents->source_pattern.base, - &extents->source_sample_area); - - return FALSE; -} - -static cairo_status_t -upload_boxes (const cairo_spans_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - const cairo_surface_pattern_t *source = &extents->source_pattern.surface; - cairo_surface_t *src; - cairo_rectangle_int_t limit; - cairo_int_status_t status; - int tx, ty; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - src = _cairo_pattern_get_source(source, &limit); - if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_matrix_is_integer_translation (&source->base.matrix, &tx, &ty)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Check that the data is entirely within the image */ - if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width || - extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height) - return CAIRO_INT_STATUS_UNSUPPORTED; - - tx += limit.x; - ty += limit.y; - - if (src->type == CAIRO_SURFACE_TYPE_IMAGE) - status = compositor->draw_image_boxes (dst, - (cairo_image_surface_t *)src, - boxes, tx, ty); - else - status = compositor->copy_boxes (dst, src, boxes, &extents->bounded, - tx, ty); - - return status; -} - -static cairo_bool_t -_clip_is_region (const cairo_clip_t *clip) -{ - int i; - - if (clip->is_region) - return TRUE; - - if (clip->path) - return FALSE; - - for (i = 0; i < clip->num_boxes; i++) { - const cairo_box_t *b = &clip->boxes[i]; - if (!_cairo_fixed_is_integer (b->p1.x | b->p1.y | b->p2.x | b->p2.y)) - return FALSE; - } - - return TRUE; -} - -static cairo_int_status_t -composite_aligned_boxes (const cairo_spans_compositor_t *compositor, - const cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - cairo_operator_t op = extents->op; - const cairo_pattern_t *source = &extents->source_pattern.base; - cairo_int_status_t status; - cairo_bool_t need_clip_mask = ! _clip_is_region (extents->clip); - cairo_bool_t op_is_source; - cairo_bool_t no_mask; - cairo_bool_t inplace; - - TRACE ((stderr, "%s: need_clip_mask=%d, is-bounded=%d\n", - __FUNCTION__, need_clip_mask, extents->is_bounded)); - if (need_clip_mask && ! extents->is_bounded) { - TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - no_mask = extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && - CAIRO_COLOR_IS_OPAQUE (&extents->mask_pattern.solid.color); - op_is_source = op_reduces_to_source (extents, no_mask); - inplace = ! need_clip_mask && op_is_source && no_mask; - - TRACE ((stderr, "%s: op-is-source=%d [op=%d], no-mask=%d, inplace=%d\n", - __FUNCTION__, op_is_source, op, no_mask, inplace)); - - if (op == CAIRO_OPERATOR_SOURCE && (need_clip_mask || ! no_mask)) { - /* SOURCE with a mask is actually a LERP in cairo semantics */ - if ((compositor->flags & CAIRO_SPANS_COMPOSITOR_HAS_LERP) == 0) { - TRACE ((stderr, "%s: unsupported lerp\n", __FUNCTION__)); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - - /* Are we just copying a recording surface? */ - if (inplace && - recording_pattern_contains_sample (&extents->source_pattern.base, - &extents->source_sample_area)) - { - cairo_clip_t *recording_clip; - const cairo_pattern_t *source = &extents->source_pattern.base; - const cairo_matrix_t *m; - cairo_matrix_t matrix; - - /* XXX could also do tiling repeat modes... */ - - /* first clear the area about to be overwritten */ - if (! dst->is_clear) { - status = compositor->fill_boxes (dst, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - boxes); - if (unlikely (status)) - return status; - - dst->is_clear = TRUE; - } - - m = &source->matrix; - if (_cairo_surface_has_device_transform (dst)) { - cairo_matrix_multiply (&matrix, - &source->matrix, - &dst->device_transform); - m = &matrix; - } - - recording_clip = _cairo_clip_from_boxes (boxes); - status = _cairo_recording_surface_replay_with_clip (unwrap_source (source), - m, dst, recording_clip); - _cairo_clip_destroy (recording_clip); - - return status; - } - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (! need_clip_mask && no_mask && source->type == CAIRO_PATTERN_TYPE_SOLID) { - const cairo_color_t *color; - - color = &((cairo_solid_pattern_t *) source)->color; - if (op_is_source) - op = CAIRO_OPERATOR_SOURCE; - status = compositor->fill_boxes (dst, op, color, boxes); - } else if (inplace && source->type == CAIRO_PATTERN_TYPE_SURFACE) { - status = upload_boxes (compositor, extents, boxes); - } - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_surface_t *src; - cairo_surface_t *mask = NULL; - int src_x, src_y; - int mask_x = 0, mask_y = 0; - - /* All typical cases will have been resolved before now... */ - if (need_clip_mask) { - mask = get_clip_surface (compositor, dst, extents->clip, - &extents->bounded); - if (unlikely (mask->status)) - return mask->status; - - mask_x = -extents->bounded.x; - mask_y = -extents->bounded.y; - } - - /* XXX but this is still ugly */ - if (! no_mask) { - src = compositor->pattern_to_surface (dst, - &extents->mask_pattern.base, - TRUE, - &extents->bounded, - &extents->mask_sample_area, - &src_x, &src_y); - if (unlikely (src->status)) { - cairo_surface_destroy (mask); - return src->status; - } - - if (mask != NULL) { - status = compositor->composite_boxes (mask, CAIRO_OPERATOR_IN, - src, NULL, - src_x, src_y, - 0, 0, - mask_x, mask_y, - boxes, &extents->bounded); - - cairo_surface_destroy (src); - } else { - mask = src; - mask_x = src_x; - mask_y = src_y; - } - } - - src = compositor->pattern_to_surface (dst, source, FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (likely (src->status == CAIRO_STATUS_SUCCESS)) { - status = compositor->composite_boxes (dst, op, src, mask, - src_x, src_y, - mask_x, mask_y, - 0, 0, - boxes, &extents->bounded); - cairo_surface_destroy (src); - } else - status = src->status; - - cairo_surface_destroy (mask); - } - - if (status == CAIRO_INT_STATUS_SUCCESS && ! extents->is_bounded) - status = fixup_unbounded_boxes (compositor, extents, boxes); - - return status; -} - -static cairo_bool_t -composite_needs_clip (const cairo_composite_rectangles_t *composite, - const cairo_box_t *extents) -{ - return !_cairo_clip_contains_box (composite->clip, extents); -} - -static cairo_int_status_t -composite_boxes (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_abstract_span_renderer_t renderer; - cairo_rectangular_scan_converter_t converter; - const struct _cairo_boxes_chunk *chunk; - cairo_int_status_t status; - cairo_box_t box; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - _cairo_box_from_rectangle (&box, &extents->unbounded); - if (composite_needs_clip (extents, &box)) { - TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - _cairo_rectangular_scan_converter_init (&converter, &extents->unbounded); - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box = chunk->base; - int i; - - for (i = 0; i < chunk->count; i++) { - status = _cairo_rectangular_scan_converter_add_box (&converter, &box[i], 1); - if (unlikely (status)) - goto cleanup_converter; - } - } - - status = compositor->renderer_init (&renderer, extents, - CAIRO_ANTIALIAS_DEFAULT, FALSE); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = converter.base.generate (&converter.base, &renderer.base); - compositor->renderer_fini (&renderer, status); - -cleanup_converter: - converter.base.destroy (&converter.base); - return status; -} - -static cairo_int_status_t -composite_polygon (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias) -{ - cairo_abstract_span_renderer_t renderer; - cairo_scan_converter_t *converter; - cairo_bool_t needs_clip; - cairo_int_status_t status; - - if (extents->is_bounded) - needs_clip = extents->clip->path != NULL; - else - needs_clip = !_clip_is_region (extents->clip) || extents->clip->num_boxes > 1; - TRACE ((stderr, "%s - needs_clip=%d\n", __FUNCTION__, needs_clip)); - if (needs_clip) { - TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); - return CAIRO_INT_STATUS_UNSUPPORTED; - converter = _cairo_clip_tor_scan_converter_create (extents->clip, - polygon, - fill_rule, antialias); - } else { - const cairo_rectangle_int_t *r = &extents->unbounded; - - if (antialias == CAIRO_ANTIALIAS_FAST) { - converter = _cairo_tor22_scan_converter_create (r->x, r->y, - r->x + r->width, - r->y + r->height, - fill_rule, antialias); - status = _cairo_tor22_scan_converter_add_polygon (converter, polygon); - } else if (antialias == CAIRO_ANTIALIAS_NONE) { - converter = _cairo_mono_scan_converter_create (r->x, r->y, - r->x + r->width, - r->y + r->height, - fill_rule); - status = _cairo_mono_scan_converter_add_polygon (converter, polygon); - } else { - converter = _cairo_tor_scan_converter_create (r->x, r->y, - r->x + r->width, - r->y + r->height, - fill_rule, antialias); - status = _cairo_tor_scan_converter_add_polygon (converter, polygon); - } - } - if (unlikely (status)) - goto cleanup_converter; - - status = compositor->renderer_init (&renderer, extents, - antialias, needs_clip); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = converter->generate (converter, &renderer.base); - compositor->renderer_fini (&renderer, status); - -cleanup_converter: - converter->destroy (converter); - return status; -} - -static cairo_int_status_t -trim_extents_to_boxes (cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_box_t box; - - _cairo_boxes_extents (boxes, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_int_status_t -trim_extents_to_polygon (cairo_composite_rectangles_t *extents, - cairo_polygon_t *polygon) -{ - return _cairo_composite_rectangles_intersect_mask_extents (extents, - &polygon->extents); -} - -static cairo_int_status_t -clip_and_composite_boxes (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_int_status_t status; - cairo_polygon_t polygon; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - status = trim_extents_to_boxes (extents, boxes); - if (unlikely (status)) - return status; - - if (boxes->num_boxes == 0) { - if (extents->is_bounded) - return CAIRO_STATUS_SUCCESS; - - return fixup_unbounded_boxes (compositor, extents, boxes); - } - - /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ - if (extents->clip->path != NULL && extents->is_bounded) { - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - cairo_clip_t *clip; - - clip = _cairo_clip_copy (extents->clip); - clip = _cairo_clip_intersect_boxes (clip, boxes); - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - status = _cairo_clip_get_polygon (clip, &polygon, - &fill_rule, &antialias); - _cairo_clip_path_destroy (clip->path); - clip->path = NULL; - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t *saved_clip = extents->clip; - extents->clip = clip; - - status = clip_and_composite_polygon (compositor, extents, &polygon, - fill_rule, antialias); - - clip = extents->clip; - extents->clip = saved_clip; - - _cairo_polygon_fini (&polygon); - } - _cairo_clip_destroy (clip); - - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - if (boxes->is_pixel_aligned) { - status = composite_aligned_boxes (compositor, extents, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - status = composite_boxes (compositor, extents, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_polygon_init_boxes (&polygon, boxes); - if (unlikely (status)) - return status; - - status = composite_polygon (compositor, extents, &polygon, - CAIRO_FILL_RULE_WINDING, - CAIRO_ANTIALIAS_DEFAULT); - _cairo_polygon_fini (&polygon); - - return status; -} - -static cairo_int_status_t -clip_and_composite_polygon (const cairo_spans_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - /* XXX simply uses polygon limits.point extemities, tessellation? */ - status = trim_extents_to_polygon (extents, polygon); - if (unlikely (status)) - return status; - - if (_cairo_polygon_is_empty (polygon)) { - cairo_boxes_t boxes; - - if (extents->is_bounded) - return CAIRO_STATUS_SUCCESS; - - _cairo_boxes_init (&boxes); - extents->bounded.width = extents->bounded.height = 0; - return fixup_unbounded_boxes (compositor, extents, &boxes); - } - - if (extents->is_bounded && extents->clip->path) { - cairo_polygon_t clipper; - cairo_antialias_t clip_antialias; - cairo_fill_rule_t clip_fill_rule; - - TRACE((stderr, "%s - combining shape with clip polygon\n", - __FUNCTION__)); - - status = _cairo_clip_get_polygon (extents->clip, - &clipper, - &clip_fill_rule, - &clip_antialias); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t *old_clip; - - if (clip_antialias == antialias) { - status = _cairo_polygon_intersect (polygon, fill_rule, - &clipper, clip_fill_rule); - _cairo_polygon_fini (&clipper); - if (unlikely (status)) - return status; - - old_clip = extents->clip; - extents->clip = _cairo_clip_copy_region (extents->clip); - _cairo_clip_destroy (old_clip); - - status = trim_extents_to_polygon (extents, polygon); - if (unlikely (status)) - return status; - - fill_rule = CAIRO_FILL_RULE_WINDING; - } else { - _cairo_polygon_fini (&clipper); - } - } - } - - return composite_polygon (compositor, extents, - polygon, fill_rule, antialias); -} - -/* high-level compositor interface */ - -static cairo_int_status_t -_cairo_spans_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; - cairo_boxes_t boxes; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - _cairo_clip_steal_boxes (extents->clip, &boxes); - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_clip_unsteal_boxes (extents->clip, &boxes); - - return status; -} - -static cairo_int_status_t -_cairo_spans_compositor_mask (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; - cairo_int_status_t status; - cairo_boxes_t boxes; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - _cairo_clip_steal_boxes (extents->clip, &boxes); - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_clip_unsteal_boxes (extents->clip, &boxes); - - return status; -} - -static cairo_int_status_t -_cairo_spans_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - TRACE_ (_cairo_debug_print_path (stderr, path)); - TRACE_ (_cairo_debug_print_clip (stderr, extents->clip)); - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_stroke_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init (&boxes); - if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) - _cairo_boxes_limit (&boxes, - extents->clip->boxes, - extents->clip->num_boxes); - - status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, - style, - ctm, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule = CAIRO_FILL_RULE_WINDING; - - if (! _cairo_rectangle_contains_rectangle (&extents->unbounded, - &extents->mask)) - { - if (extents->clip->num_boxes == 1) { - _cairo_polygon_init (&polygon, extents->clip->boxes, 1); - } else { - cairo_box_t limits; - _cairo_box_from_rectangle (&limits, &extents->unbounded); - _cairo_polygon_init (&polygon, &limits, 1); - } - } - else - { - _cairo_polygon_init (&polygon, NULL, 0); - } - status = _cairo_path_fixed_stroke_to_polygon (path, - style, - ctm, ctm_inverse, - tolerance, - &polygon); - TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); - polygon.num_limits = 0; - - if (status == CAIRO_INT_STATUS_SUCCESS && extents->clip->num_boxes > 1) { - status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, - extents->clip->boxes, - extents->clip->num_boxes); - } - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t *saved_clip = extents->clip; - - if (extents->is_bounded) { - extents->clip = _cairo_clip_copy_path (extents->clip); - extents->clip = _cairo_clip_intersect_box(extents->clip, - &polygon.extents); - } - - status = clip_and_composite_polygon (compositor, extents, &polygon, - fill_rule, antialias); - - if (extents->is_bounded) { - _cairo_clip_destroy (extents->clip); - extents->clip = saved_clip; - } - } - _cairo_polygon_fini (&polygon); - } - - return status; -} - -static cairo_int_status_t -_cairo_spans_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; - cairo_int_status_t status; - - TRACE((stderr, "%s op=%d, antialias=%d\n", __FUNCTION__, extents->op, antialias)); - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_fill_is_rectilinear (path)) { - cairo_boxes_t boxes; - - TRACE((stderr, "%s - rectilinear\n", __FUNCTION__)); - - _cairo_boxes_init (&boxes); - if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) - _cairo_boxes_limit (&boxes, - extents->clip->boxes, - extents->clip->num_boxes); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - fill_rule, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_boxes_fini (&boxes); - } - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_polygon_t polygon; - - TRACE((stderr, "%s - polygon\n", __FUNCTION__)); - - if (! _cairo_rectangle_contains_rectangle (&extents->unbounded, - &extents->mask)) - { - TRACE((stderr, "%s - clipping to bounds\n", __FUNCTION__)); - if (extents->clip->num_boxes == 1) { - _cairo_polygon_init (&polygon, extents->clip->boxes, 1); - } else { - cairo_box_t limits; - _cairo_box_from_rectangle (&limits, &extents->unbounded); - _cairo_polygon_init (&polygon, &limits, 1); - } - } - else - { - _cairo_polygon_init (&polygon, NULL, 0); - } - - status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); - TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); - polygon.num_limits = 0; - - if (status == CAIRO_INT_STATUS_SUCCESS && extents->clip->num_boxes > 1) { - TRACE((stderr, "%s - polygon intersect with %d clip boxes\n", - __FUNCTION__, extents->clip->num_boxes)); - status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, - extents->clip->boxes, - extents->clip->num_boxes); - } - TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t *saved_clip = extents->clip; - - if (extents->is_bounded) { - TRACE((stderr, "%s - polygon discard clip boxes\n", - __FUNCTION__)); - extents->clip = _cairo_clip_copy_path (extents->clip); - extents->clip = _cairo_clip_intersect_box(extents->clip, - &polygon.extents); - } - - status = clip_and_composite_polygon (compositor, extents, &polygon, - fill_rule, antialias); - - if (extents->is_bounded) { - _cairo_clip_destroy (extents->clip); - extents->clip = saved_clip; - } - } - _cairo_polygon_fini (&polygon); - - TRACE((stderr, "%s - polygon status=%d\n", __FUNCTION__, status)); - } - - return status; -} - -void -_cairo_spans_compositor_init (cairo_spans_compositor_t *compositor, - const cairo_compositor_t *delegate) -{ - compositor->base.delegate = delegate; - - compositor->base.paint = _cairo_spans_compositor_paint; - compositor->base.mask = _cairo_spans_compositor_mask; - compositor->base.fill = _cairo_spans_compositor_fill; - compositor->base.stroke = _cairo_spans_compositor_stroke; - compositor->base.glyphs = NULL; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-private.h deleted file mode 100644 index b158f4d360a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans-private.h +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright (c) 2008 M Joonas Pihlaja - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef CAIRO_SPANS_PRIVATE_H -#define CAIRO_SPANS_PRIVATE_H -#include "cairo-types-private.h" -#include "cairo-compiler-private.h" - -/* Number of bits of precision used for alpha. */ -#define CAIRO_SPANS_UNIT_COVERAGE_BITS 8 -#define CAIRO_SPANS_UNIT_COVERAGE ((1 << CAIRO_SPANS_UNIT_COVERAGE_BITS)-1) - -/* A structure representing an open-ended horizontal span of constant - * pixel coverage. */ -typedef struct _cairo_half_open_span { - int32_t x; /* The inclusive x-coordinate of the start of the span. */ - uint8_t coverage; /* The pixel coverage for the pixels to the right. */ - uint8_t inverse; /* between regular mask and clip */ -} cairo_half_open_span_t; - -/* Span renderer interface. Instances of renderers are provided by - * surfaces if they want to composite spans instead of trapezoids. */ -typedef struct _cairo_span_renderer cairo_span_renderer_t; -struct _cairo_span_renderer { - /* Private status variable. */ - cairo_status_t status; - - /* Called to destroy the renderer. */ - cairo_destroy_func_t destroy; - - /* Render the spans on row y of the destination by whatever compositing - * method is required. */ - cairo_status_t - (*render_rows) (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *coverages, - unsigned num_coverages); - - /* Called after all rows have been rendered to perform whatever - * final rendering step is required. This function is called just - * once before the renderer is destroyed. */ - cairo_status_t (*finish) (void *abstract_renderer); -}; - -/* Scan converter interface. */ -typedef struct _cairo_scan_converter cairo_scan_converter_t; -struct _cairo_scan_converter { - /* Destroy this scan converter. */ - cairo_destroy_func_t destroy; - - /* Generates coverage spans for rows for the added edges and calls - * the renderer function for each row. After generating spans the - * only valid thing to do with the converter is to destroy it. */ - cairo_status_t (*generate) (void *abstract_converter, - cairo_span_renderer_t *renderer); - - /* Private status. Read with _cairo_scan_converter_status(). */ - cairo_status_t status; -}; - -/* Scan converter constructors. */ - -cairo_private cairo_scan_converter_t * -_cairo_tor_scan_converter_create (int xmin, - int ymin, - int xmax, - int ymax, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias); -cairo_private cairo_status_t -_cairo_tor_scan_converter_add_polygon (void *converter, - const cairo_polygon_t *polygon); - -cairo_private cairo_scan_converter_t * -_cairo_tor22_scan_converter_create (int xmin, - int ymin, - int xmax, - int ymax, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias); -cairo_private cairo_status_t -_cairo_tor22_scan_converter_add_polygon (void *converter, - const cairo_polygon_t *polygon); - -cairo_private cairo_scan_converter_t * -_cairo_mono_scan_converter_create (int xmin, - int ymin, - int xmax, - int ymax, - cairo_fill_rule_t fill_rule); -cairo_private cairo_status_t -_cairo_mono_scan_converter_add_polygon (void *converter, - const cairo_polygon_t *polygon); - -cairo_private cairo_scan_converter_t * -_cairo_clip_tor_scan_converter_create (cairo_clip_t *clip, - cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias); - -typedef struct _cairo_rectangular_scan_converter { - cairo_scan_converter_t base; - - cairo_box_t extents; - - struct _cairo_rectangular_scan_converter_chunk { - struct _cairo_rectangular_scan_converter_chunk *next; - void *base; - int count; - int size; - } chunks, *tail; - char buf[CAIRO_STACK_BUFFER_SIZE]; - int num_rectangles; -} cairo_rectangular_scan_converter_t; - -cairo_private void -_cairo_rectangular_scan_converter_init (cairo_rectangular_scan_converter_t *self, - const cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_rectangular_scan_converter_add_box (cairo_rectangular_scan_converter_t *self, - const cairo_box_t *box, - int dir); - -typedef struct _cairo_botor_scan_converter { - cairo_scan_converter_t base; - - cairo_box_t extents; - cairo_fill_rule_t fill_rule; - - int xmin, xmax; - - struct _cairo_botor_scan_converter_chunk { - struct _cairo_botor_scan_converter_chunk *next; - void *base; - int count; - int size; - } chunks, *tail; - char buf[CAIRO_STACK_BUFFER_SIZE]; - int num_edges; -} cairo_botor_scan_converter_t; - -cairo_private void -_cairo_botor_scan_converter_init (cairo_botor_scan_converter_t *self, - const cairo_box_t *extents, - cairo_fill_rule_t fill_rule); - -/* cairo-spans.c: */ - -cairo_private cairo_scan_converter_t * -_cairo_scan_converter_create_in_error (cairo_status_t error); - -cairo_private cairo_status_t -_cairo_scan_converter_status (void *abstract_converter); - -cairo_private cairo_status_t -_cairo_scan_converter_set_error (void *abstract_converter, - cairo_status_t error); - -cairo_private cairo_span_renderer_t * -_cairo_span_renderer_create_in_error (cairo_status_t error); - -cairo_private cairo_status_t -_cairo_span_renderer_status (void *abstract_renderer); - -/* Set the renderer into an error state. This sets all the method - * pointers except ->destroy() of the renderer to no-op - * implementations that just return the error status. */ -cairo_private cairo_status_t -_cairo_span_renderer_set_error (void *abstract_renderer, - cairo_status_t error); - -cairo_private cairo_status_t -_cairo_surface_composite_polygon (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias, - const cairo_composite_rectangles_t *rects, - cairo_polygon_t *polygon, - cairo_region_t *clip_region); - -#endif /* CAIRO_SPANS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans.c deleted file mode 100644 index 182390c205a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spans.c +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright (c) 2008 M Joonas Pihlaja - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -#include "cairoint.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-clip-private.h" -#include "cairo-error-private.h" -#include "cairo-fixed-private.h" -#include "cairo-types-private.h" - -static void -_cairo_nil_destroy (void *abstract) -{ - (void) abstract; -} - -static cairo_status_t -_cairo_nil_scan_converter_generate (void *abstract_converter, - cairo_span_renderer_t *renderer) -{ - (void) abstract_converter; - (void) renderer; - return _cairo_scan_converter_status (abstract_converter); -} - -cairo_status_t -_cairo_scan_converter_status (void *abstract_converter) -{ - cairo_scan_converter_t *converter = abstract_converter; - return converter->status; -} - -cairo_status_t -_cairo_scan_converter_set_error (void *abstract_converter, - cairo_status_t error) -{ - cairo_scan_converter_t *converter = abstract_converter; - if (error == CAIRO_STATUS_SUCCESS) - ASSERT_NOT_REACHED; - if (converter->status == CAIRO_STATUS_SUCCESS) { - converter->generate = _cairo_nil_scan_converter_generate; - converter->status = error; - } - return converter->status; -} - -static void -_cairo_nil_scan_converter_init (cairo_scan_converter_t *converter, - cairo_status_t status) -{ - converter->destroy = _cairo_nil_destroy; - converter->status = CAIRO_STATUS_SUCCESS; - status = _cairo_scan_converter_set_error (converter, status); -} - -cairo_scan_converter_t * -_cairo_scan_converter_create_in_error (cairo_status_t status) -{ -#define RETURN_NIL {\ - static cairo_scan_converter_t nil;\ - _cairo_nil_scan_converter_init (&nil, status);\ - return &nil;\ - } - switch (status) { - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - break; - case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL; - case CAIRO_STATUS_INVALID_POP_GROUP: RETURN_NIL; - case CAIRO_STATUS_NO_CURRENT_POINT: RETURN_NIL; - case CAIRO_STATUS_INVALID_MATRIX: RETURN_NIL; - case CAIRO_STATUS_INVALID_STATUS: RETURN_NIL; - case CAIRO_STATUS_NULL_POINTER: RETURN_NIL; - case CAIRO_STATUS_INVALID_STRING: RETURN_NIL; - case CAIRO_STATUS_INVALID_PATH_DATA: RETURN_NIL; - case CAIRO_STATUS_READ_ERROR: RETURN_NIL; - case CAIRO_STATUS_WRITE_ERROR: RETURN_NIL; - case CAIRO_STATUS_SURFACE_FINISHED: RETURN_NIL; - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_INVALID_CONTENT: RETURN_NIL; - case CAIRO_STATUS_INVALID_FORMAT: RETURN_NIL; - case CAIRO_STATUS_INVALID_VISUAL: RETURN_NIL; - case CAIRO_STATUS_FILE_NOT_FOUND: RETURN_NIL; - case CAIRO_STATUS_INVALID_DASH: RETURN_NIL; - case CAIRO_STATUS_INVALID_DSC_COMMENT: RETURN_NIL; - case CAIRO_STATUS_INVALID_INDEX: RETURN_NIL; - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: RETURN_NIL; - case CAIRO_STATUS_TEMP_FILE_ERROR: RETURN_NIL; - case CAIRO_STATUS_INVALID_STRIDE: RETURN_NIL; - case CAIRO_STATUS_FONT_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_USER_FONT_IMMUTABLE: RETURN_NIL; - case CAIRO_STATUS_USER_FONT_ERROR: RETURN_NIL; - case CAIRO_STATUS_NEGATIVE_COUNT: RETURN_NIL; - case CAIRO_STATUS_INVALID_CLUSTERS: RETURN_NIL; - case CAIRO_STATUS_INVALID_SLANT: RETURN_NIL; - case CAIRO_STATUS_INVALID_WEIGHT: RETURN_NIL; - case CAIRO_STATUS_NO_MEMORY: RETURN_NIL; - case CAIRO_STATUS_INVALID_SIZE: RETURN_NIL; - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: RETURN_NIL; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_DEVICE_ERROR: RETURN_NIL; - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: RETURN_NIL; - case CAIRO_STATUS_DEVICE_FINISHED: RETURN_NIL; - case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: - default: - break; - } - status = CAIRO_STATUS_NO_MEMORY; - RETURN_NIL; -#undef RETURN_NIL -} - -static cairo_status_t -_cairo_nil_span_renderer_render_rows ( - void *abstract_renderer, - int y, - int height, - const cairo_half_open_span_t *coverages, - unsigned num_coverages) -{ - (void) y; - (void) height; - (void) coverages; - (void) num_coverages; - return _cairo_span_renderer_status (abstract_renderer); -} - -static cairo_status_t -_cairo_nil_span_renderer_finish (void *abstract_renderer) -{ - return _cairo_span_renderer_status (abstract_renderer); -} - -cairo_status_t -_cairo_span_renderer_status (void *abstract_renderer) -{ - cairo_span_renderer_t *renderer = abstract_renderer; - return renderer->status; -} - -cairo_status_t -_cairo_span_renderer_set_error ( - void *abstract_renderer, - cairo_status_t error) -{ - cairo_span_renderer_t *renderer = abstract_renderer; - if (error == CAIRO_STATUS_SUCCESS) { - ASSERT_NOT_REACHED; - } - if (renderer->status == CAIRO_STATUS_SUCCESS) { - renderer->render_rows = _cairo_nil_span_renderer_render_rows; - renderer->finish = _cairo_nil_span_renderer_finish; - renderer->status = error; - } - return renderer->status; -} - -static void -_cairo_nil_span_renderer_init (cairo_span_renderer_t *renderer, - cairo_status_t status) -{ - renderer->destroy = _cairo_nil_destroy; - renderer->status = CAIRO_STATUS_SUCCESS; - status = _cairo_span_renderer_set_error (renderer, status); -} - -cairo_span_renderer_t * -_cairo_span_renderer_create_in_error (cairo_status_t status) -{ -#define RETURN_NIL {\ - static cairo_span_renderer_t nil;\ - _cairo_nil_span_renderer_init (&nil, status);\ - return &nil;\ - } - switch (status) { - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - break; - case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL; - case CAIRO_STATUS_INVALID_POP_GROUP: RETURN_NIL; - case CAIRO_STATUS_NO_CURRENT_POINT: RETURN_NIL; - case CAIRO_STATUS_INVALID_MATRIX: RETURN_NIL; - case CAIRO_STATUS_INVALID_STATUS: RETURN_NIL; - case CAIRO_STATUS_NULL_POINTER: RETURN_NIL; - case CAIRO_STATUS_INVALID_STRING: RETURN_NIL; - case CAIRO_STATUS_INVALID_PATH_DATA: RETURN_NIL; - case CAIRO_STATUS_READ_ERROR: RETURN_NIL; - case CAIRO_STATUS_WRITE_ERROR: RETURN_NIL; - case CAIRO_STATUS_SURFACE_FINISHED: RETURN_NIL; - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_INVALID_CONTENT: RETURN_NIL; - case CAIRO_STATUS_INVALID_FORMAT: RETURN_NIL; - case CAIRO_STATUS_INVALID_VISUAL: RETURN_NIL; - case CAIRO_STATUS_FILE_NOT_FOUND: RETURN_NIL; - case CAIRO_STATUS_INVALID_DASH: RETURN_NIL; - case CAIRO_STATUS_INVALID_DSC_COMMENT: RETURN_NIL; - case CAIRO_STATUS_INVALID_INDEX: RETURN_NIL; - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: RETURN_NIL; - case CAIRO_STATUS_TEMP_FILE_ERROR: RETURN_NIL; - case CAIRO_STATUS_INVALID_STRIDE: RETURN_NIL; - case CAIRO_STATUS_FONT_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_USER_FONT_IMMUTABLE: RETURN_NIL; - case CAIRO_STATUS_USER_FONT_ERROR: RETURN_NIL; - case CAIRO_STATUS_NEGATIVE_COUNT: RETURN_NIL; - case CAIRO_STATUS_INVALID_CLUSTERS: RETURN_NIL; - case CAIRO_STATUS_INVALID_SLANT: RETURN_NIL; - case CAIRO_STATUS_INVALID_WEIGHT: RETURN_NIL; - case CAIRO_STATUS_NO_MEMORY: RETURN_NIL; - case CAIRO_STATUS_INVALID_SIZE: RETURN_NIL; - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: RETURN_NIL; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: RETURN_NIL; - case CAIRO_STATUS_DEVICE_ERROR: RETURN_NIL; - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: RETURN_NIL; - case CAIRO_STATUS_DEVICE_FINISHED: RETURN_NIL; - case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: RETURN_NIL; - default: - break; - } - status = CAIRO_STATUS_NO_MEMORY; - RETURN_NIL; -#undef RETURN_NIL -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spline.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spline.c deleted file mode 100644 index 44634faec85..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-spline.c +++ /dev/null @@ -1,424 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-slope-private.h" - -cairo_bool_t -_cairo_spline_intersects (const cairo_point_t *a, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d, - const cairo_box_t *box) -{ - cairo_box_t bounds; - - if (_cairo_box_contains_point (box, a) || - _cairo_box_contains_point (box, b) || - _cairo_box_contains_point (box, c) || - _cairo_box_contains_point (box, d)) - { - return TRUE; - } - - bounds.p2 = bounds.p1 = *a; - _cairo_box_add_point (&bounds, b); - _cairo_box_add_point (&bounds, c); - _cairo_box_add_point (&bounds, d); - - if (bounds.p2.x <= box->p1.x || bounds.p1.x >= box->p2.x || - bounds.p2.y <= box->p1.y || bounds.p1.y >= box->p2.y) - { - return FALSE; - } - -#if 0 /* worth refining? */ - bounds.p2 = bounds.p1 = *a; - _cairo_box_add_curve_to (&bounds, b, c, d); - if (bounds.p2.x <= box->p1.x || bounds.p1.x >= box->p2.x || - bounds.p2.y <= box->p1.y || bounds.p1.y >= box->p2.y) - { - return FALSE; - } -#endif - - return TRUE; -} - -cairo_bool_t -_cairo_spline_init (cairo_spline_t *spline, - cairo_spline_add_point_func_t add_point_func, - void *closure, - const cairo_point_t *a, const cairo_point_t *b, - const cairo_point_t *c, const cairo_point_t *d) -{ - /* If both tangents are zero, this is just a straight line */ - if (a->x == b->x && a->y == b->y && c->x == d->x && c->y == d->y) - return FALSE; - - spline->add_point_func = add_point_func; - spline->closure = closure; - - spline->knots.a = *a; - spline->knots.b = *b; - spline->knots.c = *c; - spline->knots.d = *d; - - if (a->x != b->x || a->y != b->y) - _cairo_slope_init (&spline->initial_slope, &spline->knots.a, &spline->knots.b); - else if (a->x != c->x || a->y != c->y) - _cairo_slope_init (&spline->initial_slope, &spline->knots.a, &spline->knots.c); - else if (a->x != d->x || a->y != d->y) - _cairo_slope_init (&spline->initial_slope, &spline->knots.a, &spline->knots.d); - else - return FALSE; - - if (c->x != d->x || c->y != d->y) - _cairo_slope_init (&spline->final_slope, &spline->knots.c, &spline->knots.d); - else if (b->x != d->x || b->y != d->y) - _cairo_slope_init (&spline->final_slope, &spline->knots.b, &spline->knots.d); - else - return FALSE; /* just treat this as a straight-line from a -> d */ - - /* XXX if the initial, final and vector are all equal, this is just a line */ - - return TRUE; -} - -static cairo_status_t -_cairo_spline_add_point (cairo_spline_t *spline, - const cairo_point_t *point, - const cairo_point_t *knot) -{ - cairo_point_t *prev; - cairo_slope_t slope; - - prev = &spline->last_point; - if (prev->x == point->x && prev->y == point->y) - return CAIRO_STATUS_SUCCESS; - - _cairo_slope_init (&slope, point, knot); - - spline->last_point = *point; - return spline->add_point_func (spline->closure, point, &slope); -} - -static void -_lerp_half (const cairo_point_t *a, const cairo_point_t *b, cairo_point_t *result) -{ - result->x = a->x + ((b->x - a->x) >> 1); - result->y = a->y + ((b->y - a->y) >> 1); -} - -static void -_de_casteljau (cairo_spline_knots_t *s1, cairo_spline_knots_t *s2) -{ - cairo_point_t ab, bc, cd; - cairo_point_t abbc, bccd; - cairo_point_t final; - - _lerp_half (&s1->a, &s1->b, &ab); - _lerp_half (&s1->b, &s1->c, &bc); - _lerp_half (&s1->c, &s1->d, &cd); - _lerp_half (&ab, &bc, &abbc); - _lerp_half (&bc, &cd, &bccd); - _lerp_half (&abbc, &bccd, &final); - - s2->a = final; - s2->b = bccd; - s2->c = cd; - s2->d = s1->d; - - s1->b = ab; - s1->c = abbc; - s1->d = final; -} - -/* Return an upper bound on the error (squared) that could result from - * approximating a spline as a line segment connecting the two endpoints. */ -static double -_cairo_spline_error_squared (const cairo_spline_knots_t *knots) -{ - double bdx, bdy, berr; - double cdx, cdy, cerr; - - /* We are going to compute the distance (squared) between each of the the b - * and c control points and the segment a-b. The maximum of these two - * distances will be our approximation error. */ - - bdx = _cairo_fixed_to_double (knots->b.x - knots->a.x); - bdy = _cairo_fixed_to_double (knots->b.y - knots->a.y); - - cdx = _cairo_fixed_to_double (knots->c.x - knots->a.x); - cdy = _cairo_fixed_to_double (knots->c.y - knots->a.y); - - if (knots->a.x != knots->d.x || knots->a.y != knots->d.y) { - /* Intersection point (px): - * px = p1 + u(p2 - p1) - * (p - px) ∙ (p2 - p1) = 0 - * Thus: - * u = ((p - p1) ∙ (p2 - p1)) / ∥p2 - p1∥²; - */ - - double dx, dy, u, v; - - dx = _cairo_fixed_to_double (knots->d.x - knots->a.x); - dy = _cairo_fixed_to_double (knots->d.y - knots->a.y); - v = dx * dx + dy * dy; - - u = bdx * dx + bdy * dy; - if (u <= 0) { - /* bdx -= 0; - * bdy -= 0; - */ - } else if (u >= v) { - bdx -= dx; - bdy -= dy; - } else { - bdx -= u/v * dx; - bdy -= u/v * dy; - } - - u = cdx * dx + cdy * dy; - if (u <= 0) { - /* cdx -= 0; - * cdy -= 0; - */ - } else if (u >= v) { - cdx -= dx; - cdy -= dy; - } else { - cdx -= u/v * dx; - cdy -= u/v * dy; - } - } - - berr = bdx * bdx + bdy * bdy; - cerr = cdx * cdx + cdy * cdy; - if (berr > cerr) - return berr; - else - return cerr; -} - -static cairo_status_t -_cairo_spline_decompose_into (cairo_spline_knots_t *s1, - double tolerance_squared, - cairo_spline_t *result) -{ - cairo_spline_knots_t s2; - cairo_status_t status; - - if (_cairo_spline_error_squared (s1) < tolerance_squared) - return _cairo_spline_add_point (result, &s1->a, &s1->b); - - _de_casteljau (s1, &s2); - - status = _cairo_spline_decompose_into (s1, tolerance_squared, result); - if (unlikely (status)) - return status; - - return _cairo_spline_decompose_into (&s2, tolerance_squared, result); -} - -cairo_status_t -_cairo_spline_decompose (cairo_spline_t *spline, double tolerance) -{ - cairo_spline_knots_t s1; - cairo_status_t status; - - s1 = spline->knots; - spline->last_point = s1.a; - status = _cairo_spline_decompose_into (&s1, tolerance * tolerance, spline); - if (unlikely (status)) - return status; - - return spline->add_point_func (spline->closure, - &spline->knots.d, &spline->final_slope); -} - -/* Note: this function is only good for computing bounds in device space. */ -cairo_status_t -_cairo_spline_bound (cairo_spline_add_point_func_t add_point_func, - void *closure, - const cairo_point_t *p0, const cairo_point_t *p1, - const cairo_point_t *p2, const cairo_point_t *p3) -{ - double x0, x1, x2, x3; - double y0, y1, y2, y3; - double a, b, c; - double t[4]; - int t_num = 0, i; - cairo_status_t status; - - x0 = _cairo_fixed_to_double (p0->x); - y0 = _cairo_fixed_to_double (p0->y); - x1 = _cairo_fixed_to_double (p1->x); - y1 = _cairo_fixed_to_double (p1->y); - x2 = _cairo_fixed_to_double (p2->x); - y2 = _cairo_fixed_to_double (p2->y); - x3 = _cairo_fixed_to_double (p3->x); - y3 = _cairo_fixed_to_double (p3->y); - - /* The spline can be written as a polynomial of the four points: - * - * (1-t)³p0 + 3t(1-t)²p1 + 3t²(1-t)p2 + t³p3 - * - * for 0≤t≤1. Now, the X and Y components of the spline follow the - * same polynomial but with x and y replaced for p. To find the - * bounds of the spline, we just need to find the X and Y bounds. - * To find the bound, we take the derivative and equal it to zero, - * and solve to find the t's that give the extreme points. - * - * Here is the derivative of the curve, sorted on t: - * - * 3t²(-p0+3p1-3p2+p3) + 2t(3p0-6p1+3p2) -3p0+3p1 - * - * Let: - * - * a = -p0+3p1-3p2+p3 - * b = p0-2p1+p2 - * c = -p0+p1 - * - * Gives: - * - * a.t² + 2b.t + c = 0 - * - * With: - * - * delta = b*b - a*c - * - * the extreme points are at -c/2b if a is zero, at (-b±√delta)/a if - * delta is positive, and at -b/a if delta is zero. - */ - -#define ADD(t0) \ - { \ - double _t0 = (t0); \ - if (0 < _t0 && _t0 < 1) \ - t[t_num++] = _t0; \ - } - -#define FIND_EXTREMES(a,b,c) \ - { \ - if (a == 0) { \ - if (b != 0) \ - ADD (-c / (2*b)); \ - } else { \ - double b2 = b * b; \ - double delta = b2 - a * c; \ - if (delta > 0) { \ - cairo_bool_t feasible; \ - double _2ab = 2 * a * b; \ - /* We are only interested in solutions t that satisfy 0= 0) \ - feasible = delta > b2 && delta < a*a + b2 + _2ab; \ - else if (-b / a >= 1) \ - feasible = delta < b2 && delta > a*a + b2 + _2ab; \ - else \ - feasible = delta < b2 || delta < a*a + b2 + _2ab; \ - \ - if (unlikely (feasible)) { \ - double sqrt_delta = sqrt (delta); \ - ADD ((-b - sqrt_delta) / a); \ - ADD ((-b + sqrt_delta) / a); \ - } \ - } else if (delta == 0) { \ - ADD (-b / a); \ - } \ - } \ - } - - /* Find X extremes */ - a = -x0 + 3*x1 - 3*x2 + x3; - b = x0 - 2*x1 + x2; - c = -x0 + x1; - FIND_EXTREMES (a, b, c); - - /* Find Y extremes */ - a = -y0 + 3*y1 - 3*y2 + y3; - b = y0 - 2*y1 + y2; - c = -y0 + y1; - FIND_EXTREMES (a, b, c); - - status = add_point_func (closure, p0, NULL); - if (unlikely (status)) - return status; - - for (i = 0; i < t_num; i++) { - cairo_point_t p; - double x, y; - double t_1_0, t_0_1; - double t_2_0, t_0_2; - double t_3_0, t_2_1_3, t_1_2_3, t_0_3; - - t_1_0 = t[i]; /* t */ - t_0_1 = 1 - t_1_0; /* (1 - t) */ - - t_2_0 = t_1_0 * t_1_0; /* t * t */ - t_0_2 = t_0_1 * t_0_1; /* (1 - t) * (1 - t) */ - - t_3_0 = t_2_0 * t_1_0; /* t * t * t */ - t_2_1_3 = t_2_0 * t_0_1 * 3; /* t * t * (1 - t) * 3 */ - t_1_2_3 = t_1_0 * t_0_2 * 3; /* t * (1 - t) * (1 - t) * 3 */ - t_0_3 = t_0_1 * t_0_2; /* (1 - t) * (1 - t) * (1 - t) */ - - /* Bezier polynomial */ - x = x0 * t_0_3 - + x1 * t_1_2_3 - + x2 * t_2_1_3 - + x3 * t_3_0; - y = y0 * t_0_3 - + y1 * t_1_2_3 - + y2 * t_2_1_3 - + y3 * t_3_0; - - p.x = _cairo_fixed_from_double (x); - p.y = _cairo_fixed_from_double (y); - status = add_point_func (closure, &p, NULL); - if (unlikely (status)) - return status; - } - - return add_point_func (closure, p3, NULL); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash-private.h deleted file mode 100644 index 75c000cd73a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash-private.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#ifndef CAIRO_STROKE_DASH_PRIVATE_H -#define CAIRO_STROKE_DASH_PRIVATE_H - -#include "cairoint.h" - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_stroker_dash { - cairo_bool_t dashed; - unsigned int dash_index; - cairo_bool_t dash_on; - cairo_bool_t dash_starts_on; - double dash_remain; - - double dash_offset; - const double *dashes; - unsigned int num_dashes; -} cairo_stroker_dash_t; - -cairo_private void -_cairo_stroker_dash_init (cairo_stroker_dash_t *dash, - const cairo_stroke_style_t *style); - -cairo_private void -_cairo_stroker_dash_start (cairo_stroker_dash_t *dash); - -cairo_private void -_cairo_stroker_dash_step (cairo_stroker_dash_t *dash, double step); - -CAIRO_END_DECLS - -#endif /* CAIRO_STROKE_DASH_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash.c deleted file mode 100644 index 9494010f561..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-dash.c +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-stroke-dash-private.h" - -void -_cairo_stroker_dash_start (cairo_stroker_dash_t *dash) -{ - double offset; - cairo_bool_t on = TRUE; - unsigned int i = 0; - - if (! dash->dashed) - return; - - offset = dash->dash_offset; - - /* We stop searching for a starting point as soon as the - offset reaches zero. Otherwise when an initial dash - segment shrinks to zero it will be skipped over. */ - while (offset > 0.0 && offset >= dash->dashes[i]) { - offset -= dash->dashes[i]; - on = !on; - if (++i == dash->num_dashes) - i = 0; - } - - dash->dash_index = i; - dash->dash_on = dash->dash_starts_on = on; - dash->dash_remain = dash->dashes[i] - offset; -} - -void -_cairo_stroker_dash_step (cairo_stroker_dash_t *dash, double step) -{ - dash->dash_remain -= step; - if (dash->dash_remain < CAIRO_FIXED_ERROR_DOUBLE) { - if (++dash->dash_index == dash->num_dashes) - dash->dash_index = 0; - - dash->dash_on = ! dash->dash_on; - dash->dash_remain += dash->dashes[dash->dash_index]; - } -} - -void -_cairo_stroker_dash_init (cairo_stroker_dash_t *dash, - const cairo_stroke_style_t *style) -{ - dash->dashed = style->dash != NULL; - if (! dash->dashed) - return; - - dash->dashes = style->dash; - dash->num_dashes = style->num_dashes; - dash->dash_offset = style->dash_offset; - - _cairo_stroker_dash_start (dash); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-style.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-style.c deleted file mode 100644 index 51c9414c042..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-stroke-style.c +++ /dev/null @@ -1,354 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -void -_cairo_stroke_style_init (cairo_stroke_style_t *style) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (style, sizeof (cairo_stroke_style_t))); - - style->line_width = CAIRO_GSTATE_LINE_WIDTH_DEFAULT; - style->line_cap = CAIRO_GSTATE_LINE_CAP_DEFAULT; - style->line_join = CAIRO_GSTATE_LINE_JOIN_DEFAULT; - style->miter_limit = CAIRO_GSTATE_MITER_LIMIT_DEFAULT; - - style->dash = NULL; - style->num_dashes = 0; - style->dash_offset = 0.0; -} - -cairo_status_t -_cairo_stroke_style_init_copy (cairo_stroke_style_t *style, - const cairo_stroke_style_t *other) -{ - if (CAIRO_INJECT_FAULT ()) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - VG (VALGRIND_MAKE_MEM_UNDEFINED (style, sizeof (cairo_stroke_style_t))); - - style->line_width = other->line_width; - style->line_cap = other->line_cap; - style->line_join = other->line_join; - style->miter_limit = other->miter_limit; - - style->num_dashes = other->num_dashes; - - if (other->dash == NULL) { - style->dash = NULL; - } else { - style->dash = _cairo_malloc_ab (style->num_dashes, sizeof (double)); - if (unlikely (style->dash == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (style->dash, other->dash, - style->num_dashes * sizeof (double)); - } - - style->dash_offset = other->dash_offset; - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_stroke_style_fini (cairo_stroke_style_t *style) -{ - free (style->dash); - style->dash = NULL; - - style->num_dashes = 0; - - VG (VALGRIND_MAKE_MEM_NOACCESS (style, sizeof (cairo_stroke_style_t))); -} - -/* - * For a stroke in the given style, compute the maximum distance - * from the path that vertices could be generated. In the case - * of rotation in the ctm, the distance will not be exact. - */ -void -_cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm, - double *dx, double *dy) -{ - double style_expansion = 0.5; - - if (style->line_cap == CAIRO_LINE_CAP_SQUARE) - style_expansion = M_SQRT1_2; - - if (style->line_join == CAIRO_LINE_JOIN_MITER && - ! path->stroke_is_rectilinear && - style_expansion < M_SQRT2 * style->miter_limit) - { - style_expansion = M_SQRT2 * style->miter_limit; - } - - style_expansion *= style->line_width; - - if (_cairo_matrix_has_unity_scale (ctm)) { - *dx = *dy = style_expansion; - } else { - *dx = style_expansion * hypot (ctm->xx, ctm->xy); - *dy = style_expansion * hypot (ctm->yy, ctm->yx); - } -} - -void -_cairo_stroke_style_max_line_distance_from_path (const cairo_stroke_style_t *style, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm, - double *dx, double *dy) -{ - double style_expansion = 0.5 * style->line_width; - if (_cairo_matrix_has_unity_scale (ctm)) { - *dx = *dy = style_expansion; - } else { - *dx = style_expansion * hypot (ctm->xx, ctm->xy); - *dy = style_expansion * hypot (ctm->yy, ctm->yx); - } -} - -void -_cairo_stroke_style_max_join_distance_from_path (const cairo_stroke_style_t *style, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm, - double *dx, double *dy) -{ - double style_expansion = 0.5; - - if (style->line_join == CAIRO_LINE_JOIN_MITER && - ! path->stroke_is_rectilinear && - style_expansion < M_SQRT2 * style->miter_limit) - { - style_expansion = M_SQRT2 * style->miter_limit; - } - - style_expansion *= style->line_width; - - if (_cairo_matrix_has_unity_scale (ctm)) { - *dx = *dy = style_expansion; - } else { - *dx = style_expansion * hypot (ctm->xx, ctm->xy); - *dy = style_expansion * hypot (ctm->yy, ctm->yx); - } -} -/* - * Computes the period of a dashed stroke style. - * Returns 0 for non-dashed styles. - */ -double -_cairo_stroke_style_dash_period (const cairo_stroke_style_t *style) -{ - double period; - unsigned int i; - - period = 0.0; - for (i = 0; i < style->num_dashes; i++) - period += style->dash[i]; - - if (style->num_dashes & 1) - period *= 2.0; - - return period; -} - -/* - * Coefficient of the linear approximation (minimizing square difference) - * of the surface covered by round caps - * - * This can be computed in the following way: - * the area inside the circle with radius w/2 and the region -d/2 <= x <= d/2 is: - * f(w,d) = 2 * integrate (sqrt (w*w/4 - x*x), x, -d/2, d/2) - * The square difference to a generic linear approximation (c*d) in the range (0,w) would be: - * integrate ((f(w,d) - c*d)^2, d, 0, w) - * To minimize this difference it is sufficient to find a solution of the differential with - * respect to c: - * solve ( diff (integrate ((f(w,d) - c*d)^2, d, 0, w), c), c) - * Which leads to c = 9/32*pi*w - * Since we're not interested in the true area, but just in a coverage extimate, - * we always divide the real area by the line width (w). - * The same computation for square caps would be - * f(w,d) = 2 * integrate(w/2, x, -d/2, d/2) - * c = 1*w - * but in this case it would not be an approximation, since f is already linear in d. - */ -#define ROUND_MINSQ_APPROXIMATION (9*M_PI/32) - -/* - * Computes the length of the "on" part of a dashed stroke style, - * taking into account also line caps. - * Returns 0 for non-dashed styles. - */ -double -_cairo_stroke_style_dash_stroked (const cairo_stroke_style_t *style) -{ - double stroked, cap_scale; - unsigned int i; - - switch (style->line_cap) { - default: ASSERT_NOT_REACHED; - case CAIRO_LINE_CAP_BUTT: cap_scale = 0.0; break; - case CAIRO_LINE_CAP_ROUND: cap_scale = ROUND_MINSQ_APPROXIMATION; break; - case CAIRO_LINE_CAP_SQUARE: cap_scale = 1.0; break; - } - - stroked = 0.0; - if (style->num_dashes & 1) { - /* Each dash element is used both as on and as off. The order in which they are summed is - * irrelevant, so sum the coverage of one dash element, taken both on and off at each iteration */ - for (i = 0; i < style->num_dashes; i++) - stroked += style->dash[i] + cap_scale * MIN (style->dash[i], style->line_width); - } else { - /* Even (0, 2, ...) dashes are on and simply counted for the coverage, odd dashes are off, thus - * their coverage is approximated based on the area covered by the caps of adjacent on dases. */ - for (i = 0; i + 1 < style->num_dashes; i += 2) - stroked += style->dash[i] + cap_scale * MIN (style->dash[i+1], style->line_width); - } - - return stroked; -} - -/* - * Verifies if _cairo_stroke_style_dash_approximate should be used to generate - * an approximation of the dash pattern in the specified style, when used for - * stroking a path with the given CTM and tolerance. - * Always %FALSE for non-dashed styles. - */ -cairo_bool_t -_cairo_stroke_style_dash_can_approximate (const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - double tolerance) -{ - double period; - - if (! style->num_dashes) - return FALSE; - - period = _cairo_stroke_style_dash_period (style); - return _cairo_matrix_transformed_circle_major_axis (ctm, period) < tolerance; -} - -/* - * Create a 2-dashes approximation of a dashed style, by making the "on" and "off" - * parts respect the original ratio. - */ -void -_cairo_stroke_style_dash_approximate (const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - double tolerance, - double *dash_offset, - double *dashes, - unsigned int *num_dashes) -{ - double coverage, scale, offset; - cairo_bool_t on = TRUE; - unsigned int i = 0; - - coverage = _cairo_stroke_style_dash_stroked (style) / _cairo_stroke_style_dash_period (style); - coverage = MIN (coverage, 1.0); - scale = tolerance / _cairo_matrix_transformed_circle_major_axis (ctm, 1.0); - - /* We stop searching for a starting point as soon as the - * offset reaches zero. Otherwise when an initial dash - * segment shrinks to zero it will be skipped over. */ - offset = style->dash_offset; - while (offset > 0.0 && offset >= style->dash[i]) { - offset -= style->dash[i]; - on = !on; - if (++i == style->num_dashes) - i = 0; - } - - *num_dashes = 2; - - /* - * We want to create a new dash pattern with the same relative coverage, - * but composed of just 2 elements with total length equal to scale. - * Based on the formula in _cairo_stroke_style_dash_stroked: - * scale * coverage = dashes[0] + cap_scale * MIN (dashes[1], line_width) - * = MIN (dashes[0] + cap_scale * (scale - dashes[0]), - * dashes[0] + cap_scale * line_width) = - * = MIN (dashes[0] * (1 - cap_scale) + cap_scale * scale, - * dashes[0] + cap_scale * line_width) - * - * Solving both cases we get: - * dashes[0] = scale * (coverage - cap_scale) / (1 - cap_scale) - * when scale - dashes[0] <= line_width - * dashes[0] = scale * coverage - cap_scale * line_width - * when scale - dashes[0] > line_width. - * - * Comparing the two cases we get: - * second > first - * second > scale * (coverage - cap_scale) / (1 - cap_scale) - * second - cap_scale * second - scale * coverage + scale * cap_scale > 0 - * (scale * coverage - cap_scale * line_width) - cap_scale * second - scale * coverage + scale * cap_scale > 0 - * - line_width - second + scale > 0 - * scale - second > line_width - * which is the condition for the second solution to be the valid one. - * So when second > first, the second solution is the correct one (i.e. - * the solution is always MAX (first, second). - */ - switch (style->line_cap) { - default: - ASSERT_NOT_REACHED; - dashes[0] = 0.0; - break; - - case CAIRO_LINE_CAP_BUTT: - /* Simplified formula (substituting 0 for cap_scale): */ - dashes[0] = scale * coverage; - break; - - case CAIRO_LINE_CAP_ROUND: - dashes[0] = MAX(scale * (coverage - ROUND_MINSQ_APPROXIMATION) / (1.0 - ROUND_MINSQ_APPROXIMATION), - scale * coverage - ROUND_MINSQ_APPROXIMATION * style->line_width); - break; - - case CAIRO_LINE_CAP_SQUARE: - /* - * Special attention is needed to handle the case cap_scale == 1 (since the first solution - * is either indeterminate or -inf in this case). Since dash lengths are always >=0, using - * 0 as first solution always leads to the correct solution. - */ - dashes[0] = MAX(0.0, scale * coverage - style->line_width); - break; - } - - dashes[1] = scale - dashes[0]; - - *dash_offset = on ? 0.0 : dashes[0]; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-backend-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-backend-private.h deleted file mode 100644 index 955a79ff5c3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-backend-private.h +++ /dev/null @@ -1,221 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_SURFACE_BACKEND_PRIVATE_H -#define CAIRO_SURFACE_BACKEND_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" - -CAIRO_BEGIN_DECLS - -struct _cairo_surface_backend { - cairo_surface_type_t type; - - cairo_warn cairo_status_t - (*finish) (void *surface); - - cairo_t * - (*create_context) (void *surface); - - cairo_surface_t * - (*create_similar) (void *surface, - cairo_content_t content, - int width, - int height); - cairo_surface_t * - (*create_similar_image) (void *surface, - cairo_format_t format, - int width, - int height); - - cairo_image_surface_t * - (*map_to_image) (void *surface, - const cairo_rectangle_int_t *extents); - cairo_int_status_t - (*unmap_image) (void *surface, - cairo_image_surface_t *image); - - cairo_surface_t * - (*source) (void *abstract_surface, - cairo_rectangle_int_t *extents); - - cairo_warn cairo_status_t - (*acquire_source_image) (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra); - - cairo_warn void - (*release_source_image) (void *abstract_surface, - cairo_image_surface_t *image_out, - void *image_extra); - - cairo_surface_t * - (*snapshot) (void *surface); - - cairo_warn cairo_int_status_t - (*copy_page) (void *surface); - - cairo_warn cairo_int_status_t - (*show_page) (void *surface); - - /* Get the extents of the current surface. For many surface types - * this will be as simple as { x=0, y=0, width=surface->width, - * height=surface->height}. - * - * If this function is not implemented, or if it returns - * FALSE the surface is considered to be - * boundless and infinite bounds are used for it. - */ - cairo_bool_t - (*get_extents) (void *surface, - cairo_rectangle_int_t *extents); - - void - (*get_font_options) (void *surface, - cairo_font_options_t *options); - - cairo_warn cairo_status_t - (*flush) (void *surface, - unsigned flags); - - cairo_warn cairo_status_t - (*mark_dirty_rectangle) (void *surface, - int x, - int y, - int width, - int height); - - cairo_warn cairo_int_status_t - (*paint) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - - cairo_warn cairo_int_status_t - (*mask) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - - cairo_warn cairo_int_status_t - (*stroke) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - - cairo_warn cairo_int_status_t - (*fill) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - - cairo_warn cairo_int_status_t - (*fill_stroke) (void *surface, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - const cairo_path_fixed_t*path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip); - - cairo_warn cairo_int_status_t - (*show_glyphs) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - - cairo_bool_t - (*has_show_text_glyphs) (void *surface); - - cairo_warn cairo_int_status_t - (*show_text_glyphs) (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - - const char ** - (*get_supported_mime_types) (void *surface); -}; - -cairo_private cairo_status_t -_cairo_surface_default_acquire_source_image (void *surface, - cairo_image_surface_t **image_out, - void **image_extra); - -cairo_private void -_cairo_surface_default_release_source_image (void *surface, - cairo_image_surface_t *image, - void *image_extra); - -cairo_private cairo_surface_t * -_cairo_surface_default_source (void *surface, - cairo_rectangle_int_t *extents); - -CAIRO_END_DECLS - -#endif /* CAIRO_SURFACE_BACKEND_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper-private.h deleted file mode 100644 index e5b00af7c66..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper-private.h +++ /dev/null @@ -1,71 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_CLIPPER_PRIVATE_H -#define CAIRO_SURFACE_CLIPPER_PRIVATE_H - -#include "cairo-types-private.h" -#include "cairo-clip-private.h" - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_surface_clipper cairo_surface_clipper_t; - -typedef cairo_status_t -(*cairo_surface_clipper_intersect_clip_path_func_t) (cairo_surface_clipper_t *, - cairo_path_fixed_t *, - cairo_fill_rule_t, - double, - cairo_antialias_t); -struct _cairo_surface_clipper { - cairo_clip_t *clip; - cairo_surface_clipper_intersect_clip_path_func_t intersect_clip_path; -}; - -cairo_private cairo_status_t -_cairo_surface_clipper_set_clip (cairo_surface_clipper_t *clipper, - const cairo_clip_t *clip); - -cairo_private void -_cairo_surface_clipper_init (cairo_surface_clipper_t *clipper, - cairo_surface_clipper_intersect_clip_path_func_t intersect); - -cairo_private void -_cairo_surface_clipper_reset (cairo_surface_clipper_t *clipper); - -CAIRO_END_DECLS - -#endif /* CAIRO_SURFACE_CLIPPER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper.c deleted file mode 100644 index 5309362c68f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-clipper.c +++ /dev/null @@ -1,196 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-surface-clipper-private.h" - -/* A collection of routines to facilitate vector surface clipping */ - -/* XXX Eliminate repeated paths and nested clips */ - -static cairo_status_t -_cairo_path_fixed_add_box (cairo_path_fixed_t *path, - const cairo_box_t *box) -{ - cairo_status_t status; - - status = _cairo_path_fixed_move_to (path, box->p1.x, box->p1.y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p2.x, box->p1.y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p2.x, box->p2.y); - if (unlikely (status)) - return status; - - status = _cairo_path_fixed_line_to (path, box->p1.x, box->p2.y); - if (unlikely (status)) - return status; - - return _cairo_path_fixed_close_path (path); -} - -static cairo_status_t -_cairo_surface_clipper_intersect_clip_boxes (cairo_surface_clipper_t *clipper, - const cairo_clip_t *clip) -{ - cairo_path_fixed_t path; - cairo_status_t status; - int i; - - if (clip->num_boxes == 0) - return CAIRO_STATUS_SUCCESS; - - /* Reconstruct the path for the clip boxes. - * XXX maybe a new clipper callback? - */ - - _cairo_path_fixed_init (&path); - for (i = 0; i < clip->num_boxes; i++) { - status = _cairo_path_fixed_add_box (&path, &clip->boxes[i]); - if (unlikely (status)) { - _cairo_path_fixed_fini (&path); - return status; - } - } - - status = clipper->intersect_clip_path (clipper, &path, - CAIRO_FILL_RULE_WINDING, - 0., - CAIRO_ANTIALIAS_DEFAULT); - _cairo_path_fixed_fini (&path); - - return status; -} - -static cairo_status_t -_cairo_surface_clipper_intersect_clip_path_recursive (cairo_surface_clipper_t *clipper, - cairo_clip_path_t *clip_path, - cairo_clip_path_t *end) -{ - cairo_status_t status; - - if (clip_path->prev != end) { - status = - _cairo_surface_clipper_intersect_clip_path_recursive (clipper, - clip_path->prev, - end); - if (unlikely (status)) - return status; - } - - return clipper->intersect_clip_path (clipper, - &clip_path->path, - clip_path->fill_rule, - clip_path->tolerance, - clip_path->antialias); -} - -cairo_status_t -_cairo_surface_clipper_set_clip (cairo_surface_clipper_t *clipper, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_bool_t incremental = FALSE; - - if (_cairo_clip_equal (clip, clipper->clip)) - return CAIRO_STATUS_SUCCESS; - - /* all clipped out state should never propagate this far */ - assert (!_cairo_clip_is_all_clipped (clip)); - - /* XXX Is this an incremental clip? */ - if (clipper->clip && clip && - clip->num_boxes == clipper->clip->num_boxes && - memcmp (clip->boxes, clipper->clip->boxes, - sizeof (cairo_box_t) * clip->num_boxes) == 0) - { - cairo_clip_path_t *clip_path = clip->path; - while (clip_path != NULL && clip_path != clipper->clip->path) - clip_path = clip_path->prev; - - if (clip_path) { - incremental = TRUE; - status = _cairo_surface_clipper_intersect_clip_path_recursive (clipper, - clip->path, - clipper->clip->path); - } - } - - _cairo_clip_destroy (clipper->clip); - clipper->clip = _cairo_clip_copy (clip); - - if (incremental) - return status; - - status = clipper->intersect_clip_path (clipper, NULL, 0, 0, 0); - if (unlikely (status)) - return status; - - if (clip == NULL) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_clipper_intersect_clip_boxes (clipper, clip); - if (unlikely (status)) - return status; - - if (clip->path != NULL) { - status = _cairo_surface_clipper_intersect_clip_path_recursive (clipper, - clip->path, - NULL); - } - - return status; -} - -void -_cairo_surface_clipper_init (cairo_surface_clipper_t *clipper, - cairo_surface_clipper_intersect_clip_path_func_t func) -{ - clipper->clip = NULL; - clipper->intersect_clip_path = func; -} - -void -_cairo_surface_clipper_reset (cairo_surface_clipper_t *clipper) -{ - _cairo_clip_destroy (clipper->clip); - clipper->clip = NULL; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback-private.h deleted file mode 100644 index ecf7b0edf2b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback-private.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_FALLBACK_PRIVATE_H -#define CAIRO_SURFACE_FALLBACK_PRIVATE_H - -#include "cairoint.h" - -CAIRO_BEGIN_DECLS - -cairo_private cairo_int_status_t -_cairo_surface_fallback_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_surface_fallback_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_surface_fallback_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t*style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_surface_fallback_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_int_status_t -_cairo_surface_fallback_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - -CAIRO_END_DECLS - -#endif /* CAIRO_SURFACE_FALLBACK_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback.c deleted file mode 100644 index a0af1596921..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-fallback.c +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-compositor-private.h" -#include "cairo-surface-fallback-private.h" - -cairo_int_status_t -_cairo_surface_fallback_paint (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - return _cairo_compositor_paint (&_cairo_fallback_compositor, - surface, op, source, clip); -} - -cairo_int_status_t -_cairo_surface_fallback_mask (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - return _cairo_compositor_mask (&_cairo_fallback_compositor, - surface, op, source, mask, clip); -} - -cairo_int_status_t -_cairo_surface_fallback_stroke (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - const cairo_stroke_style_t*style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - return _cairo_compositor_stroke (&_cairo_fallback_compositor, - surface, op, source, path, - style, ctm,ctm_inverse, - tolerance, antialias, clip); -} - -cairo_int_status_t -_cairo_surface_fallback_fill (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - return _cairo_compositor_fill (&_cairo_fallback_compositor, - surface, op, source, path, - fill_rule, tolerance, antialias, - clip); -} - -cairo_int_status_t -_cairo_surface_fallback_glyphs (void *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - return _cairo_compositor_glyphs (&_cairo_fallback_compositor, - surface, op, source, - glyphs, num_glyphs, scaled_font, - clip); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-inline.h deleted file mode 100644 index 85fbc9192bd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-inline.h +++ /dev/null @@ -1,60 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_SURFACE_INLINE_H -#define CAIRO_SURFACE_INLINE_H - -#include "cairo-surface-private.h" - -static inline cairo_status_t -__cairo_surface_flush (cairo_surface_t *surface, unsigned flags) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - if (surface->backend->flush) - status = surface->backend->flush (surface, flags); - return status; -} - -static inline cairo_surface_t * -_cairo_surface_reference (cairo_surface_t *surface) -{ - if (!CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - _cairo_reference_count_inc (&surface->ref_count); - return surface; -} - -#endif /* CAIRO_SURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-inline.h deleted file mode 100644 index 07b94770d4b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-inline.h +++ /dev/null @@ -1,59 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_OBSERVER_INLINE_H -#define CAIRO_SURFACE_OBSERVER_INLINE_H - -#include "cairo-surface-observer-private.h" - -static inline cairo_surface_t * -_cairo_surface_observer_get_target (cairo_surface_t *surface) -{ - return ((cairo_surface_observer_t *) surface)->target; -} - -static inline cairo_bool_t -_cairo_surface_is_observer (cairo_surface_t *surface) -{ - return surface->backend->type == (cairo_surface_type_t)CAIRO_INTERNAL_SURFACE_TYPE_OBSERVER; -} - -static inline cairo_bool_t -_cairo_device_is_observer (cairo_device_t *device) -{ - return device->backend->type == (cairo_device_type_t)CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER; -} - -#endif /* CAIRO_SURFACE_OBSERVER_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-private.h deleted file mode 100644 index 70c87db8283..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer-private.h +++ /dev/null @@ -1,208 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_OBSERVER_PRIVATE_H -#define CAIRO_SURFACE_OBSERVER_PRIVATE_H - -#include "cairoint.h" - -#include "cairo-device-private.h" -#include "cairo-list-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-time-private.h" - -struct stat { - double min, max, sum, sum_sq; - unsigned count; -}; - -#define NUM_OPERATORS (CAIRO_OPERATOR_HSL_LUMINOSITY+1) -#define NUM_CAPS (CAIRO_LINE_CAP_SQUARE+1) -#define NUM_JOINS (CAIRO_LINE_JOIN_BEVEL+1) -#define NUM_ANTIALIAS (CAIRO_ANTIALIAS_BEST+1) -#define NUM_FILL_RULE (CAIRO_FILL_RULE_EVEN_ODD+1) - -struct extents { - struct stat area; - unsigned int bounded, unbounded; -}; - -struct pattern { - unsigned int type[7]; /* native/record/other surface/gradients */ -}; - -struct path { - unsigned int type[5]; /* empty/pixel/rectilinear/straight/curved */ -}; - -struct clip { - unsigned int type[6]; /* none, region, boxes, single path, polygon, general */ -}; - -typedef struct _cairo_observation cairo_observation_t; -typedef struct _cairo_observation_record cairo_observation_record_t; -typedef struct _cairo_device_observer cairo_device_observer_t; - -struct _cairo_observation_record { - cairo_content_t target_content; - int target_width; - int target_height; - - int index; - cairo_operator_t op; - int source; - int mask; - int num_glyphs; - int path; - int fill_rule; - double tolerance; - int antialias; - int clip; - cairo_time_t elapsed; -}; - -struct _cairo_observation { - int num_surfaces; - int num_contexts; - int num_sources_acquired; - - /* XXX put interesting stats here! */ - - struct paint { - cairo_time_t elapsed; - unsigned int count; - struct extents extents; - unsigned int operators[NUM_OPERATORS]; - struct pattern source; - struct clip clip; - unsigned int noop; - - cairo_observation_record_t slowest; - } paint; - - struct mask { - cairo_time_t elapsed; - unsigned int count; - struct extents extents; - unsigned int operators[NUM_OPERATORS]; - struct pattern source; - struct pattern mask; - struct clip clip; - unsigned int noop; - - cairo_observation_record_t slowest; - } mask; - - struct fill { - cairo_time_t elapsed; - unsigned int count; - struct extents extents; - unsigned int operators[NUM_OPERATORS]; - struct pattern source; - struct path path; - unsigned int antialias[NUM_ANTIALIAS]; - unsigned int fill_rule[NUM_FILL_RULE]; - struct clip clip; - unsigned int noop; - - cairo_observation_record_t slowest; - } fill; - - struct stroke { - cairo_time_t elapsed; - unsigned int count; - struct extents extents; - unsigned int operators[NUM_OPERATORS]; - unsigned int caps[NUM_CAPS]; - unsigned int joins[NUM_CAPS]; - unsigned int antialias[NUM_ANTIALIAS]; - struct pattern source; - struct path path; - struct stat line_width; - struct clip clip; - unsigned int noop; - - cairo_observation_record_t slowest; - } stroke; - - struct glyphs { - cairo_time_t elapsed; - unsigned int count; - struct extents extents; - unsigned int operators[NUM_OPERATORS]; - struct pattern source; - struct clip clip; - unsigned int noop; - - cairo_observation_record_t slowest; - } glyphs; - - cairo_array_t timings; - cairo_recording_surface_t *record; -}; - -struct _cairo_device_observer { - cairo_device_t base; - cairo_device_t *target; - - cairo_observation_t log; -}; - -struct callback_list { - cairo_list_t link; - - cairo_surface_observer_callback_t func; - void *data; -}; - -struct _cairo_surface_observer { - cairo_surface_t base; - cairo_surface_t *target; - - cairo_observation_t log; - - cairo_list_t paint_callbacks; - cairo_list_t mask_callbacks; - cairo_list_t fill_callbacks; - cairo_list_t stroke_callbacks; - cairo_list_t glyphs_callbacks; - - cairo_list_t flush_callbacks; - cairo_list_t finish_callbacks; -}; - -#endif /* CAIRO_SURFACE_OBSERVER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer.c deleted file mode 100644 index 52b013644db..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-observer.c +++ /dev/null @@ -1,2106 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-surface-observer-private.h" -#include "cairo-surface-observer-inline.h" - -#include "cairo-array-private.h" -#include "cairo-combsort-inline.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-pattern-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-subsurface-inline.h" -#include "cairo-reference-count-private.h" - -#if CAIRO_HAS_SCRIPT_SURFACE -#include "cairo-script-private.h" -#endif - -static const cairo_surface_backend_t _cairo_surface_observer_backend; - -/* observation/stats */ - -static void init_stats (struct stat *s) -{ - s->min = HUGE_VAL; - s->max = -HUGE_VAL; -} - -static void init_extents (struct extents *e) -{ - init_stats (&e->area); -} - -static void init_pattern (struct pattern *p) -{ -} - -static void init_path (struct path *p) -{ -} - -static void init_clip (struct clip *c) -{ -} - -static void init_paint (struct paint *p) -{ - init_extents (&p->extents); - init_pattern (&p->source); - init_clip (&p->clip); -} - -static void init_mask (struct mask *m) -{ - init_extents (&m->extents); - init_pattern (&m->source); - init_pattern (&m->mask); - init_clip (&m->clip); -} - -static void init_fill (struct fill *f) -{ - init_extents (&f->extents); - init_pattern (&f->source); - init_path (&f->path); - init_clip (&f->clip); -} - -static void init_stroke (struct stroke *s) -{ - init_extents (&s->extents); - init_pattern (&s->source); - init_path (&s->path); - init_clip (&s->clip); -} - -static void init_glyphs (struct glyphs *g) -{ - init_extents (&g->extents); - init_pattern (&g->source); - init_clip (&g->clip); -} - -static cairo_status_t -log_init (cairo_observation_t *log, - cairo_bool_t record) -{ - memset (log, 0, sizeof(*log)); - - init_paint (&log->paint); - init_mask (&log->mask); - init_fill (&log->fill); - init_stroke (&log->stroke); - init_glyphs (&log->glyphs); - - _cairo_array_init (&log->timings, sizeof (cairo_observation_record_t)); - - if (record) { - log->record = (cairo_recording_surface_t *) - cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL); - if (unlikely (log->record->base.status)) - return log->record->base.status; - - log->record->optimize_clears = FALSE; - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -log_fini (cairo_observation_t *log) -{ - _cairo_array_fini (&log->timings); - cairo_surface_destroy (&log->record->base); -} - -static cairo_surface_t* -get_pattern_surface (const cairo_pattern_t *pattern) -{ - return ((cairo_surface_pattern_t *)pattern)->surface; -} - -static int -classify_pattern (const cairo_pattern_t *pattern, - const cairo_surface_t *target) -{ - int classify; - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SURFACE: - if (get_pattern_surface (pattern)->type == target->type) - classify = 0; - else if (get_pattern_surface (pattern)->type == CAIRO_SURFACE_TYPE_RECORDING) - classify = 1; - else - classify = 2; - break; - default: - case CAIRO_PATTERN_TYPE_SOLID: - classify = 3; - break; - case CAIRO_PATTERN_TYPE_LINEAR: - classify = 4; - break; - case CAIRO_PATTERN_TYPE_RADIAL: - classify = 5; - break; - case CAIRO_PATTERN_TYPE_MESH: - classify = 6; - break; - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - classify = 7; - break; - } - return classify; -} - -static void -add_pattern (struct pattern *stats, - const cairo_pattern_t *pattern, - const cairo_surface_t *target) -{ - stats->type[classify_pattern(pattern, target)]++; -} - -static int -classify_path (const cairo_path_fixed_t *path, - cairo_bool_t is_fill) -{ - int classify; - - /* XXX improve for stroke */ - classify = -1; - if (is_fill) { - if (path->fill_is_empty) - classify = 0; - else if (_cairo_path_fixed_fill_is_rectilinear (path)) - classify = path->fill_maybe_region ? 1 : 2; - } else { - if (_cairo_path_fixed_stroke_is_rectilinear (path)) - classify = 2; - } - if (classify == -1) - classify = 3 + (path->has_curve_to != 0); - - return classify; -} - -static void -add_path (struct path *stats, - const cairo_path_fixed_t *path, - cairo_bool_t is_fill) -{ - stats->type[classify_path(path, is_fill)]++; -} - -static int -classify_clip (const cairo_clip_t *clip) -{ - int classify; - - if (clip == NULL) - classify = 0; - else if (_cairo_clip_is_region (clip)) - classify = 1; - else if (clip->path == NULL) - classify = 2; - else if (clip->path->prev == NULL) - classify = 3; - else if (_cairo_clip_is_polygon (clip)) - classify = 4; - else - classify = 5; - - return classify; -} - -static void -add_clip (struct clip *stats, - const cairo_clip_t *clip) -{ - stats->type[classify_clip (clip)]++; -} - -static void -stats_add (struct stat *s, double v) -{ - if (v < s->min) - s->min = v; - if (v > s->max) - s->max = v; - s->sum += v; - s->sum_sq += v*v; - s->count++; -} - -static void -add_extents (struct extents *stats, - const cairo_composite_rectangles_t *extents) -{ - const cairo_rectangle_int_t *r = extents->is_bounded ? &extents->bounded :&extents->unbounded; - stats_add (&stats->area, r->width * r->height); - stats->bounded += extents->is_bounded != 0; - stats->unbounded += extents->is_bounded == 0; -} - -/* device interface */ - -static void -_cairo_device_observer_lock (void *_device) -{ - cairo_device_observer_t *device = (cairo_device_observer_t *) _device; - cairo_status_t ignored; - - /* cairo_device_acquire() can fail for nil and finished - * devices. We don't care about observing them. */ - ignored = cairo_device_acquire (device->target); -} - -static void -_cairo_device_observer_unlock (void *_device) -{ - cairo_device_observer_t *device = (cairo_device_observer_t *) _device; - cairo_device_release (device->target); -} - -static cairo_status_t -_cairo_device_observer_flush (void *_device) -{ - cairo_device_observer_t *device = (cairo_device_observer_t *) _device; - - if (device->target == NULL) - return CAIRO_STATUS_SUCCESS; - - cairo_device_flush (device->target); - return device->target->status; -} - -static void -_cairo_device_observer_finish (void *_device) -{ - cairo_device_observer_t *device = (cairo_device_observer_t *) _device; - log_fini (&device->log); - cairo_device_finish (device->target); -} - -static void -_cairo_device_observer_destroy (void *_device) -{ - cairo_device_observer_t *device = (cairo_device_observer_t *) _device; - cairo_device_destroy (device->target); - free (device); -} - -static const cairo_device_backend_t _cairo_device_observer_backend = { - CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER, - - _cairo_device_observer_lock, - _cairo_device_observer_unlock, - - _cairo_device_observer_flush, - _cairo_device_observer_finish, - _cairo_device_observer_destroy, -}; - -static cairo_device_t * -_cairo_device_create_observer_internal (cairo_device_t *target, - cairo_bool_t record) -{ - cairo_device_observer_t *device; - cairo_status_t status; - - device = malloc (sizeof (cairo_device_observer_t)); - if (unlikely (device == NULL)) - return _cairo_device_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_device_init (&device->base, &_cairo_device_observer_backend); - status = log_init (&device->log, record); - if (unlikely (status)) { - free (device); - return _cairo_device_create_in_error (status); - } - - device->target = cairo_device_reference (target); - - return &device->base; -} - -/* surface interface */ - -static cairo_device_observer_t * -to_device (cairo_surface_observer_t *suface) -{ - return (cairo_device_observer_t *)suface->base.device; -} - -static cairo_surface_t * -_cairo_surface_create_observer_internal (cairo_device_t *device, - cairo_surface_t *target) -{ - cairo_surface_observer_t *surface; - cairo_status_t status; - - surface = malloc (sizeof (cairo_surface_observer_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_surface_observer_backend, device, - target->content); - - status = log_init (&surface->log, - ((cairo_device_observer_t *)device)->log.record != NULL); - if (unlikely (status)) { - free (surface); - return _cairo_surface_create_in_error (status); - } - - surface->target = cairo_surface_reference (target); - surface->base.type = surface->target->type; - surface->base.is_clear = surface->target->is_clear; - - cairo_list_init (&surface->paint_callbacks); - cairo_list_init (&surface->mask_callbacks); - cairo_list_init (&surface->fill_callbacks); - cairo_list_init (&surface->stroke_callbacks); - cairo_list_init (&surface->glyphs_callbacks); - - cairo_list_init (&surface->flush_callbacks); - cairo_list_init (&surface->finish_callbacks); - - surface->log.num_surfaces++; - to_device (surface)->log.num_surfaces++; - - return &surface->base; -} - -static inline void -do_callbacks (cairo_surface_observer_t *surface, cairo_list_t *head) -{ - struct callback_list *cb; - - cairo_list_foreach_entry (cb, struct callback_list, head, link) - cb->func (&surface->base, surface->target, cb->data); -} - - -static cairo_status_t -_cairo_surface_observer_finish (void *abstract_surface) -{ - cairo_surface_observer_t *surface = abstract_surface; - - do_callbacks (surface, &surface->finish_callbacks); - - cairo_surface_destroy (surface->target); - log_fini (&surface->log); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_surface_observer_create_similar (void *abstract_other, - cairo_content_t content, - int width, int height) -{ - cairo_surface_observer_t *other = abstract_other; - cairo_surface_t *target, *surface; - - target = NULL; - if (other->target->backend->create_similar) - target = other->target->backend->create_similar (other->target, content, - width, height); - if (target == NULL) - target = _cairo_image_surface_create_with_content (content, - width, height); - - surface = _cairo_surface_create_observer_internal (other->base.device, - target); - cairo_surface_destroy (target); - - return surface; -} - -static cairo_surface_t * -_cairo_surface_observer_create_similar_image (void *other, - cairo_format_t format, - int width, int height) -{ - cairo_surface_observer_t *surface = other; - - if (surface->target->backend->create_similar_image) - return surface->target->backend->create_similar_image (surface->target, - format, - width, height); - - return NULL; -} - -static cairo_image_surface_t * -_cairo_surface_observer_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_observer_t *surface = abstract_surface; - return _cairo_surface_map_to_image (surface->target, extents); -} - -static cairo_int_status_t -_cairo_surface_observer_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_surface_observer_t *surface = abstract_surface; - return _cairo_surface_unmap_image (surface->target, image); -} - -static void -record_target (cairo_observation_record_t *r, - cairo_surface_t *target) -{ - cairo_rectangle_int_t extents; - - r->target_content = target->content; - if (_cairo_surface_get_extents (target, &extents)) { - r->target_width = extents.width; - r->target_height = extents.height; - } else { - r->target_width = -1; - r->target_height = -1; - } -} - -static cairo_observation_record_t * -record_paint (cairo_observation_record_t *r, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - record_target (r, target); - - r->op = op; - r->source = classify_pattern (source, target); - r->mask = -1; - r->num_glyphs = -1; - r->path = -1; - r->fill_rule = -1; - r->tolerance = -1; - r->antialias = -1; - r->clip = classify_clip (clip); - r->elapsed = elapsed; - - return r; -} - -static cairo_observation_record_t * -record_mask (cairo_observation_record_t *r, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - record_target (r, target); - - r->op = op; - r->source = classify_pattern (source, target); - r->mask = classify_pattern (mask, target); - r->num_glyphs = -1; - r->path = -1; - r->fill_rule = -1; - r->tolerance = -1; - r->antialias = -1; - r->clip = classify_clip (clip); - r->elapsed = elapsed; - - return r; -} - -static cairo_observation_record_t * -record_fill (cairo_observation_record_t *r, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - record_target (r, target); - - r->op = op; - r->source = classify_pattern (source, target); - r->mask = -1; - r->num_glyphs = -1; - r->path = classify_path (path, TRUE); - r->fill_rule = fill_rule; - r->tolerance = tolerance; - r->antialias = antialias; - r->clip = classify_clip (clip); - r->elapsed = elapsed; - - return r; -} - -static cairo_observation_record_t * -record_stroke (cairo_observation_record_t *r, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - record_target (r, target); - - r->op = op; - r->source = classify_pattern (source, target); - r->mask = -1; - r->num_glyphs = -1; - r->path = classify_path (path, FALSE); - r->fill_rule = -1; - r->tolerance = tolerance; - r->antialias = antialias; - r->clip = classify_clip (clip); - r->elapsed = elapsed; - - return r; -} - -static cairo_observation_record_t * -record_glyphs (cairo_observation_record_t *r, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - record_target (r, target); - - r->op = op; - r->source = classify_pattern (source, target); - r->mask = -1; - r->path = -1; - r->num_glyphs = num_glyphs; - r->fill_rule = -1; - r->tolerance = -1; - r->antialias = -1; - r->clip = classify_clip (clip); - r->elapsed = elapsed; - - return r; -} - -static void -add_record (cairo_observation_t *log, - cairo_observation_record_t *r) -{ - cairo_int_status_t status; - - r->index = log->record ? log->record->commands.num_elements : 0; - - status = _cairo_array_append (&log->timings, r); - assert (status == CAIRO_INT_STATUS_SUCCESS); -} - -static void -_cairo_surface_sync (cairo_surface_t *target, int x, int y) -{ - cairo_rectangle_int_t extents; - - extents.x = x; - extents.y = y; - extents.width = 1; - extents.height = 1; - - _cairo_surface_unmap_image (target, - _cairo_surface_map_to_image (target, - &extents)); -} - -static void -midpt (const cairo_composite_rectangles_t *extents, int *x, int *y) -{ - *x = extents->bounded.x + extents->bounded.width / 2; - *y = extents->bounded.y + extents->bounded.height / 2; -} - -static void -add_record_paint (cairo_observation_t *log, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - cairo_observation_record_t record; - cairo_int_status_t status; - - add_record (log, - record_paint (&record, target, op, source, clip, elapsed)); - - /* We have to bypass the high-level surface layer in case it tries to be - * too smart and discard operations; we need to record exactly what just - * happened on the target. - */ - if (log->record) { - status = log->record->base.backend->paint (&log->record->base, - op, source, clip); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - if (_cairo_time_gt (elapsed, log->paint.slowest.elapsed)) - log->paint.slowest = record; - log->paint.elapsed = _cairo_time_add (log->paint.elapsed, elapsed); -} - -static cairo_int_status_t -_cairo_surface_observer_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_device_observer_t *device = to_device (surface); - cairo_composite_rectangles_t composite; - cairo_int_status_t status; - cairo_time_t t; - int x, y; - - /* XXX device locking */ - - surface->log.paint.count++; - surface->log.paint.operators[op]++; - add_pattern (&surface->log.paint.source, source, surface->target); - add_clip (&surface->log.paint.clip, clip); - - device->log.paint.count++; - device->log.paint.operators[op]++; - add_pattern (&device->log.paint.source, source, surface->target); - add_clip (&device->log.paint.clip, clip); - - status = _cairo_composite_rectangles_init_for_paint (&composite, - surface->target, - op, source, - clip); - if (unlikely (status)) { - surface->log.paint.noop++; - device->log.paint.noop++; - return status; - } - - midpt (&composite, &x, &y); - - add_extents (&surface->log.paint.extents, &composite); - add_extents (&device->log.paint.extents, &composite); - _cairo_composite_rectangles_fini (&composite); - - t = _cairo_time_get (); - status = _cairo_surface_paint (surface->target, - op, source, - clip); - if (unlikely (status)) - return status; - - _cairo_surface_sync (surface->target, x, y); - t = _cairo_time_get_delta (t); - - add_record_paint (&surface->log, surface->target, op, source, clip, t); - add_record_paint (&device->log, surface->target, op, source, clip, t); - - do_callbacks (surface, &surface->paint_callbacks); - - return CAIRO_STATUS_SUCCESS; -} - -static void -add_record_mask (cairo_observation_t *log, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - cairo_observation_record_t record; - cairo_int_status_t status; - - add_record (log, - record_mask (&record, target, op, source, mask, clip, elapsed)); - - if (log->record) { - status = log->record->base.backend->mask (&log->record->base, - op, source, mask, clip); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - if (_cairo_time_gt (elapsed, log->mask.slowest.elapsed)) - log->mask.slowest = record; - log->mask.elapsed = _cairo_time_add (log->mask.elapsed, elapsed); -} - -static cairo_int_status_t -_cairo_surface_observer_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_device_observer_t *device = to_device (surface); - cairo_composite_rectangles_t composite; - cairo_int_status_t status; - cairo_time_t t; - int x, y; - - surface->log.mask.count++; - surface->log.mask.operators[op]++; - add_pattern (&surface->log.mask.source, source, surface->target); - add_pattern (&surface->log.mask.mask, mask, surface->target); - add_clip (&surface->log.mask.clip, clip); - - device->log.mask.count++; - device->log.mask.operators[op]++; - add_pattern (&device->log.mask.source, source, surface->target); - add_pattern (&device->log.mask.mask, mask, surface->target); - add_clip (&device->log.mask.clip, clip); - - status = _cairo_composite_rectangles_init_for_mask (&composite, - surface->target, - op, source, mask, - clip); - if (unlikely (status)) { - surface->log.mask.noop++; - device->log.mask.noop++; - return status; - } - - midpt (&composite, &x, &y); - - add_extents (&surface->log.mask.extents, &composite); - add_extents (&device->log.mask.extents, &composite); - _cairo_composite_rectangles_fini (&composite); - - t = _cairo_time_get (); - status = _cairo_surface_mask (surface->target, - op, source, mask, - clip); - if (unlikely (status)) - return status; - - _cairo_surface_sync (surface->target, x, y); - t = _cairo_time_get_delta (t); - - add_record_mask (&surface->log, - surface->target, op, source, mask, clip, - t); - add_record_mask (&device->log, - surface->target, op, source, mask, clip, - t); - - do_callbacks (surface, &surface->mask_callbacks); - - return CAIRO_STATUS_SUCCESS; -} - -static void -add_record_fill (cairo_observation_t *log, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - cairo_observation_record_t record; - cairo_int_status_t status; - - add_record (log, - record_fill (&record, - target, op, source, - path, fill_rule, tolerance, antialias, - clip, elapsed)); - - if (log->record) { - status = log->record->base.backend->fill (&log->record->base, - op, source, - path, fill_rule, - tolerance, antialias, - clip); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - if (_cairo_time_gt (elapsed, log->fill.slowest.elapsed)) - log->fill.slowest = record; - log->fill.elapsed = _cairo_time_add (log->fill.elapsed, elapsed); -} - -static cairo_int_status_t -_cairo_surface_observer_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_device_observer_t *device = to_device (surface); - cairo_composite_rectangles_t composite; - cairo_int_status_t status; - cairo_time_t t; - int x, y; - - surface->log.fill.count++; - surface->log.fill.operators[op]++; - surface->log.fill.fill_rule[fill_rule]++; - surface->log.fill.antialias[antialias]++; - add_pattern (&surface->log.fill.source, source, surface->target); - add_path (&surface->log.fill.path, path, TRUE); - add_clip (&surface->log.fill.clip, clip); - - device->log.fill.count++; - device->log.fill.operators[op]++; - device->log.fill.fill_rule[fill_rule]++; - device->log.fill.antialias[antialias]++; - add_pattern (&device->log.fill.source, source, surface->target); - add_path (&device->log.fill.path, path, TRUE); - add_clip (&device->log.fill.clip, clip); - - status = _cairo_composite_rectangles_init_for_fill (&composite, - surface->target, - op, source, path, - clip); - if (unlikely (status)) { - surface->log.fill.noop++; - device->log.fill.noop++; - return status; - } - - midpt (&composite, &x, &y); - - add_extents (&surface->log.fill.extents, &composite); - add_extents (&device->log.fill.extents, &composite); - _cairo_composite_rectangles_fini (&composite); - - t = _cairo_time_get (); - status = _cairo_surface_fill (surface->target, - op, source, path, - fill_rule, tolerance, antialias, - clip); - if (unlikely (status)) - return status; - - _cairo_surface_sync (surface->target, x, y); - t = _cairo_time_get_delta (t); - - add_record_fill (&surface->log, - surface->target, op, source, path, - fill_rule, tolerance, antialias, - clip, t); - - add_record_fill (&device->log, - surface->target, op, source, path, - fill_rule, tolerance, antialias, - clip, t); - - do_callbacks (surface, &surface->fill_callbacks); - - return CAIRO_STATUS_SUCCESS; -} - -static void -add_record_stroke (cairo_observation_t *log, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - cairo_observation_record_t record; - cairo_int_status_t status; - - add_record (log, - record_stroke (&record, - target, op, source, - path, style, ctm,ctm_inverse, - tolerance, antialias, - clip, elapsed)); - - if (log->record) { - status = log->record->base.backend->stroke (&log->record->base, - op, source, - path, style, ctm,ctm_inverse, - tolerance, antialias, - clip); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - if (_cairo_time_gt (elapsed, log->stroke.slowest.elapsed)) - log->stroke.slowest = record; - log->stroke.elapsed = _cairo_time_add (log->stroke.elapsed, elapsed); -} - -static cairo_int_status_t -_cairo_surface_observer_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_device_observer_t *device = to_device (surface); - cairo_composite_rectangles_t composite; - cairo_int_status_t status; - cairo_time_t t; - int x, y; - - surface->log.stroke.count++; - surface->log.stroke.operators[op]++; - surface->log.stroke.antialias[antialias]++; - surface->log.stroke.caps[style->line_cap]++; - surface->log.stroke.joins[style->line_join]++; - add_pattern (&surface->log.stroke.source, source, surface->target); - add_path (&surface->log.stroke.path, path, FALSE); - add_clip (&surface->log.stroke.clip, clip); - - device->log.stroke.count++; - device->log.stroke.operators[op]++; - device->log.stroke.antialias[antialias]++; - device->log.stroke.caps[style->line_cap]++; - device->log.stroke.joins[style->line_join]++; - add_pattern (&device->log.stroke.source, source, surface->target); - add_path (&device->log.stroke.path, path, FALSE); - add_clip (&device->log.stroke.clip, clip); - - status = _cairo_composite_rectangles_init_for_stroke (&composite, - surface->target, - op, source, - path, style, ctm, - clip); - if (unlikely (status)) { - surface->log.stroke.noop++; - device->log.stroke.noop++; - return status; - } - - midpt (&composite, &x, &y); - - add_extents (&surface->log.stroke.extents, &composite); - add_extents (&device->log.stroke.extents, &composite); - _cairo_composite_rectangles_fini (&composite); - - t = _cairo_time_get (); - status = _cairo_surface_stroke (surface->target, - op, source, path, - style, ctm, ctm_inverse, - tolerance, antialias, - clip); - if (unlikely (status)) - return status; - - _cairo_surface_sync (surface->target, x, y); - t = _cairo_time_get_delta (t); - - add_record_stroke (&surface->log, - surface->target, op, source, path, - style, ctm,ctm_inverse, - tolerance, antialias, - clip, t); - - add_record_stroke (&device->log, - surface->target, op, source, path, - style, ctm,ctm_inverse, - tolerance, antialias, - clip, t); - - do_callbacks (surface, &surface->stroke_callbacks); - - return CAIRO_STATUS_SUCCESS; -} - -static void -add_record_glyphs (cairo_observation_t *log, - cairo_surface_t *target, - cairo_operator_t op, - const cairo_pattern_t*source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip, - cairo_time_t elapsed) -{ - cairo_observation_record_t record; - cairo_int_status_t status; - - add_record (log, - record_glyphs (&record, - target, op, source, - glyphs, num_glyphs, scaled_font, - clip, elapsed)); - - if (log->record) { - status = log->record->base.backend->show_text_glyphs (&log->record->base, - op, source, - NULL, 0, - glyphs, num_glyphs, - NULL, 0, 0, - scaled_font, - clip); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - if (_cairo_time_gt (elapsed, log->glyphs.slowest.elapsed)) - log->glyphs.slowest = record; - log->glyphs.elapsed = _cairo_time_add (log->glyphs.elapsed, elapsed); -} - -static cairo_int_status_t -_cairo_surface_observer_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_device_observer_t *device = to_device (surface); - cairo_composite_rectangles_t composite; - cairo_int_status_t status; - cairo_glyph_t *dev_glyphs; - cairo_time_t t; - int x, y; - - surface->log.glyphs.count++; - surface->log.glyphs.operators[op]++; - add_pattern (&surface->log.glyphs.source, source, surface->target); - add_clip (&surface->log.glyphs.clip, clip); - - device->log.glyphs.count++; - device->log.glyphs.operators[op]++; - add_pattern (&device->log.glyphs.source, source, surface->target); - add_clip (&device->log.glyphs.clip, clip); - - status = _cairo_composite_rectangles_init_for_glyphs (&composite, - surface->target, - op, source, - scaled_font, - glyphs, num_glyphs, - clip, - NULL); - if (unlikely (status)) { - surface->log.glyphs.noop++; - device->log.glyphs.noop++; - return status; - } - - midpt (&composite, &x, &y); - - add_extents (&surface->log.glyphs.extents, &composite); - add_extents (&device->log.glyphs.extents, &composite); - _cairo_composite_rectangles_fini (&composite); - - /* XXX We have to copy the glyphs, because the backend is allowed to - * modify! */ - dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); - if (unlikely (dev_glyphs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - memcpy (dev_glyphs, glyphs, num_glyphs * sizeof (cairo_glyph_t)); - - t = _cairo_time_get (); - status = _cairo_surface_show_text_glyphs (surface->target, op, source, - NULL, 0, - dev_glyphs, num_glyphs, - NULL, 0, 0, - scaled_font, - clip); - free (dev_glyphs); - if (unlikely (status)) - return status; - - _cairo_surface_sync (surface->target, x, y); - t = _cairo_time_get_delta (t); - - add_record_glyphs (&surface->log, - surface->target, op, source, - glyphs, num_glyphs, scaled_font, - clip, t); - - add_record_glyphs (&device->log, - surface->target, op, source, - glyphs, num_glyphs, scaled_font, - clip, t); - - do_callbacks (surface, &surface->glyphs_callbacks); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_surface_observer_flush (void *abstract_surface, unsigned flags) -{ - cairo_surface_observer_t *surface = abstract_surface; - - do_callbacks (surface, &surface->flush_callbacks); - return _cairo_surface_flush (surface->target, flags); -} - -static cairo_status_t -_cairo_surface_observer_mark_dirty (void *abstract_surface, - int x, int y, - int width, int height) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_status_t status; - - printf ("mark-dirty (%d, %d) x (%d, %d)\n", x, y, width, height); - - status = CAIRO_STATUS_SUCCESS; - if (surface->target->backend->mark_dirty_rectangle) - status = surface->target->backend->mark_dirty_rectangle (surface->target, - x,y, width,height); - - return status; -} - -static cairo_int_status_t -_cairo_surface_observer_copy_page (void *abstract_surface) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_status_t status; - - status = CAIRO_STATUS_SUCCESS; - if (surface->target->backend->copy_page) - status = surface->target->backend->copy_page (surface->target); - - return status; -} - -static cairo_int_status_t -_cairo_surface_observer_show_page (void *abstract_surface) -{ - cairo_surface_observer_t *surface = abstract_surface; - cairo_status_t status; - - status = CAIRO_STATUS_SUCCESS; - if (surface->target->backend->show_page) - status = surface->target->backend->show_page (surface->target); - - return status; -} - -static cairo_bool_t -_cairo_surface_observer_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_surface_observer_t *surface = abstract_surface; - return _cairo_surface_get_extents (surface->target, extents); -} - -static void -_cairo_surface_observer_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_surface_observer_t *surface = abstract_surface; - - if (surface->target->backend->get_font_options != NULL) - surface->target->backend->get_font_options (surface->target, options); -} - -static cairo_surface_t * -_cairo_surface_observer_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_surface_observer_t *surface = abstract_surface; - return _cairo_surface_get_source (surface->target, extents); -} - -static cairo_status_t -_cairo_surface_observer_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_surface_observer_t *surface = abstract_surface; - - surface->log.num_sources_acquired++; - to_device (surface)->log.num_sources_acquired++; - - return _cairo_surface_acquire_source_image (surface->target, - image_out, image_extra); -} - -static void -_cairo_surface_observer_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_observer_t *surface = abstract_surface; - - _cairo_surface_release_source_image (surface->target, image, image_extra); -} - -static cairo_surface_t * -_cairo_surface_observer_snapshot (void *abstract_surface) -{ - cairo_surface_observer_t *surface = abstract_surface; - - /* XXX hook onto the snapshot so that we measure number of reads */ - - if (surface->target->backend->snapshot) - return surface->target->backend->snapshot (surface->target); - - return NULL; -} - -static cairo_t * -_cairo_surface_observer_create_context(void *target) -{ - cairo_surface_observer_t *surface = target; - - if (_cairo_surface_is_subsurface (&surface->base)) - surface = (cairo_surface_observer_t *) - _cairo_surface_subsurface_get_target (&surface->base); - - surface->log.num_contexts++; - to_device (surface)->log.num_contexts++; - - return surface->target->backend->create_context (target); -} - -static const cairo_surface_backend_t _cairo_surface_observer_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_OBSERVER, - _cairo_surface_observer_finish, - - _cairo_surface_observer_create_context, - - _cairo_surface_observer_create_similar, - _cairo_surface_observer_create_similar_image, - _cairo_surface_observer_map_to_image, - _cairo_surface_observer_unmap_image, - - _cairo_surface_observer_source, - _cairo_surface_observer_acquire_source_image, - _cairo_surface_observer_release_source_image, - _cairo_surface_observer_snapshot, - - _cairo_surface_observer_copy_page, - _cairo_surface_observer_show_page, - - _cairo_surface_observer_get_extents, - _cairo_surface_observer_get_font_options, - - _cairo_surface_observer_flush, - _cairo_surface_observer_mark_dirty, - - _cairo_surface_observer_paint, - _cairo_surface_observer_mask, - _cairo_surface_observer_stroke, - _cairo_surface_observer_fill, - NULL, /* fill-stroke */ - _cairo_surface_observer_glyphs, -}; - -/** - * cairo_surface_create_observer: - * @target: an existing surface for which the observer will watch - * @mode: sets the mode of operation (normal vs. record) - * - * Create a new surface that exists solely to watch another is doing. In - * the process it will log operations and times, which are fast, which are - * slow, which are frequent, etc. - * - * The @mode parameter can be set to either CAIRO_SURFACE_OBSERVER_NORMAL - * or CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS, to control whether or not - * the internal observer should record operations. - * - * Return value: a pointer to the newly allocated surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if @other is already in an error state - * or any other error occurs. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_surface_create_observer (cairo_surface_t *target, - cairo_surface_observer_mode_t mode) -{ - cairo_device_t *device; - cairo_surface_t *surface; - cairo_bool_t record; - - if (unlikely (target->status)) - return _cairo_surface_create_in_error (target->status); - if (unlikely (target->finished)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - record = mode & CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS; - device = _cairo_device_create_observer_internal (target->device, record); - if (unlikely (device->status)) - return _cairo_surface_create_in_error (device->status); - - surface = _cairo_surface_create_observer_internal (device, target); - cairo_device_destroy (device); - - return surface; -} - -static cairo_status_t -_cairo_surface_observer_add_callback (cairo_list_t *head, - cairo_surface_observer_callback_t func, - void *data) -{ - struct callback_list *cb; - - cb = malloc (sizeof (*cb)); - if (unlikely (cb == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - cairo_list_add (&cb->link, head); - cb->func = func; - cb->data = data; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -cairo_surface_observer_add_paint_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->paint_callbacks, - func, data); -} - -cairo_status_t -cairo_surface_observer_add_mask_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->mask_callbacks, - func, data); -} - -cairo_status_t -cairo_surface_observer_add_fill_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->fill_callbacks, - func, data); -} - -cairo_status_t -cairo_surface_observer_add_stroke_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->stroke_callbacks, - func, data); -} - -cairo_status_t -cairo_surface_observer_add_glyphs_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->glyphs_callbacks, - func, data); -} - -cairo_status_t -cairo_surface_observer_add_flush_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->flush_callbacks, - func, data); -} - -cairo_status_t -cairo_surface_observer_add_finish_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return abstract_surface->status; - - if (! _cairo_surface_is_observer (abstract_surface)) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *)abstract_surface; - return _cairo_surface_observer_add_callback (&surface->finish_callbacks, - func, data); -} - -static void -print_extents (cairo_output_stream_t *stream, const struct extents *e) -{ - _cairo_output_stream_printf (stream, - " extents: total %g, avg %g [unbounded %d]\n", - e->area.sum, - e->area.sum / e->area.count, - e->unbounded); -} - -static inline int ordercmp (int a, int b, const unsigned int *array) -{ - /* high to low */ - return array[b] - array[a]; -} -CAIRO_COMBSORT_DECLARE_WITH_DATA (sort_order, int, ordercmp) - -static void -print_array (cairo_output_stream_t *stream, - const unsigned int *array, - const char **names, - int count) -{ - int order[64]; - int i, j; - - assert (count < ARRAY_LENGTH (order)); - for (i = j = 0; i < count; i++) { - if (array[i] != 0) - order[j++] = i; - } - - sort_order (order, j, (void *)array); - for (i = 0; i < j; i++) - _cairo_output_stream_printf (stream, " %d %s%s", - array[order[i]], names[order[i]], - i < j -1 ? "," : ""); -} - -static const char *operator_names[] = { - "CLEAR", /* CAIRO_OPERATOR_CLEAR */ - - "SOURCE", /* CAIRO_OPERATOR_SOURCE */ - "OVER", /* CAIRO_OPERATOR_OVER */ - "IN", /* CAIRO_OPERATOR_IN */ - "OUT", /* CAIRO_OPERATOR_OUT */ - "ATOP", /* CAIRO_OPERATOR_ATOP */ - - "DEST", /* CAIRO_OPERATOR_DEST */ - "DEST_OVER", /* CAIRO_OPERATOR_DEST_OVER */ - "DEST_IN", /* CAIRO_OPERATOR_DEST_IN */ - "DEST_OUT", /* CAIRO_OPERATOR_DEST_OUT */ - "DEST_ATOP", /* CAIRO_OPERATOR_DEST_ATOP */ - - "XOR", /* CAIRO_OPERATOR_XOR */ - "ADD", /* CAIRO_OPERATOR_ADD */ - "SATURATE", /* CAIRO_OPERATOR_SATURATE */ - - "MULTIPLY", /* CAIRO_OPERATOR_MULTIPLY */ - "SCREEN", /* CAIRO_OPERATOR_SCREEN */ - "OVERLAY", /* CAIRO_OPERATOR_OVERLAY */ - "DARKEN", /* CAIRO_OPERATOR_DARKEN */ - "LIGHTEN", /* CAIRO_OPERATOR_LIGHTEN */ - "DODGE", /* CAIRO_OPERATOR_COLOR_DODGE */ - "BURN", /* CAIRO_OPERATOR_COLOR_BURN */ - "HARD_LIGHT", /* CAIRO_OPERATOR_HARD_LIGHT */ - "SOFT_LIGHT", /* CAIRO_OPERATOR_SOFT_LIGHT */ - "DIFFERENCE", /* CAIRO_OPERATOR_DIFFERENCE */ - "EXCLUSION", /* CAIRO_OPERATOR_EXCLUSION */ - "HSL_HUE", /* CAIRO_OPERATOR_HSL_HUE */ - "HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */ - "HSL_COLOR", /* CAIRO_OPERATOR_HSL_COLOR */ - "HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */ -}; -static void -print_operators (cairo_output_stream_t *stream, unsigned int *array) -{ - _cairo_output_stream_printf (stream, " op:"); - print_array (stream, array, operator_names, NUM_OPERATORS); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *fill_rule_names[] = { - "non-zero", - "even-odd", -}; -static void -print_fill_rule (cairo_output_stream_t *stream, unsigned int *array) -{ - _cairo_output_stream_printf (stream, " fill rule:"); - print_array (stream, array, fill_rule_names, ARRAY_LENGTH(fill_rule_names)); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *cap_names[] = { - "butt", /* CAIRO_LINE_CAP_BUTT */ - "round", /* CAIRO_LINE_CAP_ROUND */ - "square" /* CAIRO_LINE_CAP_SQUARE */ -}; -static void -print_line_caps (cairo_output_stream_t *stream, unsigned int *array) -{ - _cairo_output_stream_printf (stream, " caps:"); - print_array (stream, array, cap_names, NUM_CAPS); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *join_names[] = { - "miter", /* CAIRO_LINE_JOIN_MITER */ - "round", /* CAIRO_LINE_JOIN_ROUND */ - "bevel", /* CAIRO_LINE_JOIN_BEVEL */ -}; -static void -print_line_joins (cairo_output_stream_t *stream, unsigned int *array) -{ - _cairo_output_stream_printf (stream, " joins:"); - print_array (stream, array, join_names, NUM_JOINS); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *antialias_names[] = { - "default", - "none", - "gray", - "subpixel", - "fast", - "good", - "best" -}; -static void -print_antialias (cairo_output_stream_t *stream, unsigned int *array) -{ - _cairo_output_stream_printf (stream, " antialias:"); - print_array (stream, array, antialias_names, NUM_ANTIALIAS); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *pattern_names[] = { - "native", - "record", - "other surface", - "solid", - "linear", - "radial", - "mesh", - "raster" -}; -static void -print_pattern (cairo_output_stream_t *stream, - const char *name, - const struct pattern *p) -{ - _cairo_output_stream_printf (stream, " %s:", name); - print_array (stream, p->type, pattern_names, ARRAY_LENGTH (pattern_names)); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *path_names[] = { - "empty", - "pixel-aligned", - "rectliinear", - "straight", - "curved", -}; -static void -print_path (cairo_output_stream_t *stream, - const struct path *p) -{ - _cairo_output_stream_printf (stream, " path:"); - print_array (stream, p->type, path_names, ARRAY_LENGTH (path_names)); - _cairo_output_stream_printf (stream, "\n"); -} - -static const char *clip_names[] = { - "none", - "region", - "boxes", - "single path", - "polygon", - "general", -}; -static void -print_clip (cairo_output_stream_t *stream, const struct clip *c) -{ - _cairo_output_stream_printf (stream, " clip:"); - print_array (stream, c->type, clip_names, ARRAY_LENGTH (clip_names)); - _cairo_output_stream_printf (stream, "\n"); -} - -static void -print_record (cairo_output_stream_t *stream, - cairo_observation_record_t *r) -{ - _cairo_output_stream_printf (stream, " op: %s\n", operator_names[r->op]); - _cairo_output_stream_printf (stream, " source: %s\n", - pattern_names[r->source]); - if (r->mask != -1) - _cairo_output_stream_printf (stream, " mask: %s\n", - pattern_names[r->mask]); - if (r->num_glyphs != -1) - _cairo_output_stream_printf (stream, " num_glyphs: %d\n", - r->num_glyphs); - if (r->path != -1) - _cairo_output_stream_printf (stream, " path: %s\n", - path_names[r->path]); - if (r->fill_rule != -1) - _cairo_output_stream_printf (stream, " fill rule: %s\n", - fill_rule_names[r->fill_rule]); - if (r->antialias != -1) - _cairo_output_stream_printf (stream, " antialias: %s\n", - antialias_names[r->antialias]); - _cairo_output_stream_printf (stream, " clip: %s\n", clip_names[r->clip]); - _cairo_output_stream_printf (stream, " elapsed: %f ns\n", - _cairo_time_to_ns (r->elapsed)); -} - -static double percent (cairo_time_t a, cairo_time_t b) -{ - /* Fake %.1f */ - return _cairo_round (_cairo_time_to_s (a) * 1000 / - _cairo_time_to_s (b)) / 10; -} - -static cairo_bool_t -replay_record (cairo_observation_t *log, - cairo_observation_record_t *r, - cairo_device_t *script) -{ -#if CAIRO_HAS_SCRIPT_SURFACE - cairo_surface_t *surface; - cairo_int_status_t status; - - if (log->record == NULL || script == NULL) - return FALSE; - - surface = cairo_script_surface_create (script, - r->target_content, - r->target_width, - r->target_height); - status = - _cairo_recording_surface_replay_one (log->record, r->index, surface); - cairo_surface_destroy (surface); - - assert (status == CAIRO_INT_STATUS_SUCCESS); - - return TRUE; -#else - return FALSE; -#endif -} - -static cairo_time_t -_cairo_observation_total_elapsed (cairo_observation_t *log) -{ - cairo_time_t total; - - total = log->paint.elapsed; - total = _cairo_time_add (total, log->mask.elapsed); - total = _cairo_time_add (total, log->fill.elapsed); - total = _cairo_time_add (total, log->stroke.elapsed); - total = _cairo_time_add (total, log->glyphs.elapsed); - - return total; -} - -static void -_cairo_observation_print (cairo_output_stream_t *stream, - cairo_observation_t *log) -{ - cairo_device_t *script; - cairo_time_t total; - -#if CAIRO_HAS_SCRIPT_SURFACE - script = _cairo_script_context_create_internal (stream); - _cairo_script_context_attach_snapshots (script, FALSE); -#else - script = NULL; -#endif - - total = _cairo_observation_total_elapsed (log); - - _cairo_output_stream_printf (stream, "elapsed: %f\n", - _cairo_time_to_ns (total)); - _cairo_output_stream_printf (stream, "surfaces: %d\n", - log->num_surfaces); - _cairo_output_stream_printf (stream, "contexts: %d\n", - log->num_contexts); - _cairo_output_stream_printf (stream, "sources acquired: %d\n", - log->num_sources_acquired); - - - _cairo_output_stream_printf (stream, "paint: count %d [no-op %d], elapsed %f [%f%%]\n", - log->paint.count, log->paint.noop, - _cairo_time_to_ns (log->paint.elapsed), - percent (log->paint.elapsed, total)); - if (log->paint.count) { - print_extents (stream, &log->paint.extents); - print_operators (stream, log->paint.operators); - print_pattern (stream, "source", &log->paint.source); - print_clip (stream, &log->paint.clip); - - _cairo_output_stream_printf (stream, "slowest paint: %f%%\n", - percent (log->paint.slowest.elapsed, - log->paint.elapsed)); - print_record (stream, &log->paint.slowest); - - _cairo_output_stream_printf (stream, "\n"); - if (replay_record (log, &log->paint.slowest, script)) - _cairo_output_stream_printf (stream, "\n\n"); - } - - _cairo_output_stream_printf (stream, "mask: count %d [no-op %d], elapsed %f [%f%%]\n", - log->mask.count, log->mask.noop, - _cairo_time_to_ns (log->mask.elapsed), - percent (log->mask.elapsed, total)); - if (log->mask.count) { - print_extents (stream, &log->mask.extents); - print_operators (stream, log->mask.operators); - print_pattern (stream, "source", &log->mask.source); - print_pattern (stream, "mask", &log->mask.mask); - print_clip (stream, &log->mask.clip); - - _cairo_output_stream_printf (stream, "slowest mask: %f%%\n", - percent (log->mask.slowest.elapsed, - log->mask.elapsed)); - print_record (stream, &log->mask.slowest); - - _cairo_output_stream_printf (stream, "\n"); - if (replay_record (log, &log->mask.slowest, script)) - _cairo_output_stream_printf (stream, "\n\n"); - } - - _cairo_output_stream_printf (stream, "fill: count %d [no-op %d], elaspsed %f [%f%%]\n", - log->fill.count, log->fill.noop, - _cairo_time_to_ns (log->fill.elapsed), - percent (log->fill.elapsed, total)); - if (log->fill.count) { - print_extents (stream, &log->fill.extents); - print_operators (stream, log->fill.operators); - print_pattern (stream, "source", &log->fill.source); - print_path (stream, &log->fill.path); - print_fill_rule (stream, log->fill.fill_rule); - print_antialias (stream, log->fill.antialias); - print_clip (stream, &log->fill.clip); - - _cairo_output_stream_printf (stream, "slowest fill: %f%%\n", - percent (log->fill.slowest.elapsed, - log->fill.elapsed)); - print_record (stream, &log->fill.slowest); - - _cairo_output_stream_printf (stream, "\n"); - if (replay_record (log, &log->fill.slowest, script)) - _cairo_output_stream_printf (stream, "\n\n"); - } - - _cairo_output_stream_printf (stream, "stroke: count %d [no-op %d], elapsed %f [%f%%]\n", - log->stroke.count, log->stroke.noop, - _cairo_time_to_ns (log->stroke.elapsed), - percent (log->stroke.elapsed, total)); - if (log->stroke.count) { - print_extents (stream, &log->stroke.extents); - print_operators (stream, log->stroke.operators); - print_pattern (stream, "source", &log->stroke.source); - print_path (stream, &log->stroke.path); - print_antialias (stream, log->stroke.antialias); - print_line_caps (stream, log->stroke.caps); - print_line_joins (stream, log->stroke.joins); - print_clip (stream, &log->stroke.clip); - - _cairo_output_stream_printf (stream, "slowest stroke: %f%%\n", - percent (log->stroke.slowest.elapsed, - log->stroke.elapsed)); - print_record (stream, &log->stroke.slowest); - - _cairo_output_stream_printf (stream, "\n"); - if (replay_record (log, &log->stroke.slowest, script)) - _cairo_output_stream_printf (stream, "\n\n"); - } - - _cairo_output_stream_printf (stream, "glyphs: count %d [no-op %d], elasped %f [%f%%]\n", - log->glyphs.count, log->glyphs.noop, - _cairo_time_to_ns (log->glyphs.elapsed), - percent (log->glyphs.elapsed, total)); - if (log->glyphs.count) { - print_extents (stream, &log->glyphs.extents); - print_operators (stream, log->glyphs.operators); - print_pattern (stream, "source", &log->glyphs.source); - print_clip (stream, &log->glyphs.clip); - - _cairo_output_stream_printf (stream, "slowest glyphs: %f%%\n", - percent (log->glyphs.slowest.elapsed, - log->glyphs.elapsed)); - print_record (stream, &log->glyphs.slowest); - - _cairo_output_stream_printf (stream, "\n"); - if (replay_record (log, &log->glyphs.slowest, script)) - _cairo_output_stream_printf (stream, "\n\n"); - } - - cairo_device_destroy (script); -} - -cairo_status_t -cairo_surface_observer_print (cairo_surface_t *abstract_surface, - cairo_write_func_t write_func, - void *closure) -{ - cairo_output_stream_t *stream; - cairo_surface_observer_t *surface; - - if (unlikely (abstract_surface->status)) - return abstract_surface->status; - - if (unlikely (! _cairo_surface_is_observer (abstract_surface))) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - surface = (cairo_surface_observer_t *) abstract_surface; - - stream = _cairo_output_stream_create (write_func, NULL, closure); - _cairo_observation_print (stream, &surface->log); - return _cairo_output_stream_destroy (stream); -} - -double -cairo_surface_observer_elapsed (cairo_surface_t *abstract_surface) -{ - cairo_surface_observer_t *surface; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) - return -1; - - if (! _cairo_surface_is_observer (abstract_surface)) - return -1; - - surface = (cairo_surface_observer_t *) abstract_surface; - return _cairo_time_to_ns (_cairo_observation_total_elapsed (&surface->log)); -} - -cairo_status_t -cairo_device_observer_print (cairo_device_t *abstract_device, - cairo_write_func_t write_func, - void *closure) -{ - cairo_output_stream_t *stream; - cairo_device_observer_t *device; - - if (unlikely (abstract_device->status)) - return abstract_device->status; - - if (unlikely (! _cairo_device_is_observer (abstract_device))) - return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - - device = (cairo_device_observer_t *) abstract_device; - - stream = _cairo_output_stream_create (write_func, NULL, closure); - _cairo_observation_print (stream, &device->log); - return _cairo_output_stream_destroy (stream); -} - -double -cairo_device_observer_elapsed (cairo_device_t *abstract_device) -{ - cairo_device_observer_t *device; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) - return -1; - - if (! _cairo_device_is_observer (abstract_device)) - return -1; - - device = (cairo_device_observer_t *) abstract_device; - return _cairo_time_to_ns (_cairo_observation_total_elapsed (&device->log)); -} - -double -cairo_device_observer_paint_elapsed (cairo_device_t *abstract_device) -{ - cairo_device_observer_t *device; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) - return -1; - - if (! _cairo_device_is_observer (abstract_device)) - return -1; - - device = (cairo_device_observer_t *) abstract_device; - return _cairo_time_to_ns (device->log.paint.elapsed); -} - -double -cairo_device_observer_mask_elapsed (cairo_device_t *abstract_device) -{ - cairo_device_observer_t *device; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) - return -1; - - if (! _cairo_device_is_observer (abstract_device)) - return -1; - - device = (cairo_device_observer_t *) abstract_device; - return _cairo_time_to_ns (device->log.mask.elapsed); -} - -double -cairo_device_observer_fill_elapsed (cairo_device_t *abstract_device) -{ - cairo_device_observer_t *device; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) - return -1; - - if (! _cairo_device_is_observer (abstract_device)) - return -1; - - device = (cairo_device_observer_t *) abstract_device; - return _cairo_time_to_ns (device->log.fill.elapsed); -} - -double -cairo_device_observer_stroke_elapsed (cairo_device_t *abstract_device) -{ - cairo_device_observer_t *device; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) - return -1; - - if (! _cairo_device_is_observer (abstract_device)) - return -1; - - device = (cairo_device_observer_t *) abstract_device; - return _cairo_time_to_ns (device->log.stroke.elapsed); -} - -double -cairo_device_observer_glyphs_elapsed (cairo_device_t *abstract_device) -{ - cairo_device_observer_t *device; - - if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) - return -1; - - if (! _cairo_device_is_observer (abstract_device)) - return -1; - - device = (cairo_device_observer_t *) abstract_device; - return _cairo_time_to_ns (device->log.glyphs.elapsed); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset-private.h deleted file mode 100644 index 310ba5691cd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset-private.h +++ /dev/null @@ -1,95 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_OFFSET_PRIVATE_H -#define CAIRO_SURFACE_OFFSET_PRIVATE_H - -#include "cairo-types-private.h" - -CAIRO_BEGIN_DECLS - -cairo_private cairo_status_t -_cairo_surface_offset_paint (cairo_surface_t *target, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_offset_mask (cairo_surface_t *target, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_offset_stroke (cairo_surface_t *surface, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_offset_fill (cairo_surface_t *surface, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t*source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_offset_glyphs (cairo_surface_t *surface, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_clip_t *clip); - -#endif /* CAIRO_SURFACE_OFFSET_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset.c deleted file mode 100644 index 98f57f29804..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-offset.c +++ /dev/null @@ -1,308 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * Copyright © 2007 Adrian Johnson - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-error-private.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-offset-private.h" - -/* A collection of routines to facilitate drawing to an alternate surface. */ - -static void -_copy_transformed_pattern (cairo_pattern_t *pattern, - const cairo_pattern_t *original, - const cairo_matrix_t *ctm_inverse) -{ - _cairo_pattern_init_static_copy (pattern, original); - - if (! _cairo_matrix_is_identity (ctm_inverse)) - _cairo_pattern_transform (pattern, ctm_inverse); -} - -cairo_status_t -_cairo_surface_offset_paint (cairo_surface_t *target, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_clip_t *dev_clip = (cairo_clip_t *) clip; - cairo_pattern_union_t source_copy; - - if (unlikely (target->status)) - return target->status; - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - if (x | y) { - cairo_matrix_t m; - - dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); - - cairo_matrix_init_translate (&m, x, y); - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - } - - status = _cairo_surface_paint (target, op, source, dev_clip); - - if (dev_clip != clip) - _cairo_clip_destroy (dev_clip); - - return status; -} - -cairo_status_t -_cairo_surface_offset_mask (cairo_surface_t *target, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_clip_t *dev_clip = (cairo_clip_t *) clip; - cairo_pattern_union_t source_copy; - cairo_pattern_union_t mask_copy; - - if (unlikely (target->status)) - return target->status; - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - if (x | y) { - cairo_matrix_t m; - - dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); - - cairo_matrix_init_translate (&m, x, y); - _copy_transformed_pattern (&source_copy.base, source, &m); - _copy_transformed_pattern (&mask_copy.base, mask, &m); - source = &source_copy.base; - mask = &mask_copy.base; - } - - status = _cairo_surface_mask (target, op, - source, mask, - dev_clip); - - if (dev_clip != clip) - _cairo_clip_destroy (dev_clip); - - return status; -} - -cairo_status_t -_cairo_surface_offset_stroke (cairo_surface_t *surface, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t*stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; - cairo_clip_t *dev_clip = (cairo_clip_t *) clip; - cairo_matrix_t dev_ctm = *ctm; - cairo_matrix_t dev_ctm_inverse = *ctm_inverse; - cairo_pattern_union_t source_copy; - cairo_status_t status; - - if (unlikely (surface->status)) - return surface->status; - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - if (x | y) { - cairo_matrix_t m; - - dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); - - status = _cairo_path_fixed_init_copy (&path_copy, dev_path); - if (unlikely (status)) - goto FINISH; - - _cairo_path_fixed_translate (&path_copy, - _cairo_fixed_from_int (-x), - _cairo_fixed_from_int (-y)); - dev_path = &path_copy; - - cairo_matrix_init_translate (&m, -x, -y); - cairo_matrix_multiply (&dev_ctm, &dev_ctm, &m); - - cairo_matrix_init_translate (&m, x, y); - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - cairo_matrix_multiply (&dev_ctm_inverse, &m, &dev_ctm_inverse); - } - - status = _cairo_surface_stroke (surface, op, source, - dev_path, stroke_style, - &dev_ctm, &dev_ctm_inverse, - tolerance, antialias, - dev_clip); - -FINISH: - if (dev_path != path) - _cairo_path_fixed_fini (dev_path); - if (dev_clip != clip) - _cairo_clip_destroy (dev_clip); - - return status; -} - -cairo_status_t -_cairo_surface_offset_fill (cairo_surface_t *surface, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t*source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; - cairo_clip_t *dev_clip = (cairo_clip_t *) clip; - cairo_pattern_union_t source_copy; - - if (unlikely (surface->status)) - return surface->status; - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - if (x | y) { - cairo_matrix_t m; - - dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); - - status = _cairo_path_fixed_init_copy (&path_copy, dev_path); - if (unlikely (status)) - goto FINISH; - - _cairo_path_fixed_translate (&path_copy, - _cairo_fixed_from_int (-x), - _cairo_fixed_from_int (-y)); - dev_path = &path_copy; - - cairo_matrix_init_translate (&m, x, y); - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - } - - status = _cairo_surface_fill (surface, op, source, - dev_path, fill_rule, - tolerance, antialias, - dev_clip); - -FINISH: - if (dev_path != path) - _cairo_path_fixed_fini (dev_path); - if (dev_clip != clip) - _cairo_clip_destroy (dev_clip); - - return status; -} - -cairo_status_t -_cairo_surface_offset_glyphs (cairo_surface_t *surface, - int x, int y, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_clip_t *dev_clip = (cairo_clip_t *) clip; - cairo_pattern_union_t source_copy; - cairo_glyph_t *dev_glyphs; - int i; - - if (unlikely (surface->status)) - return surface->status; - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); - if (dev_glyphs == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - memcpy (dev_glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); - - if (x | y) { - cairo_matrix_t m; - - dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); - - cairo_matrix_init_translate (&m, x, y); - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - - for (i = 0; i < num_glyphs; i++) { - dev_glyphs[i].x -= x; - dev_glyphs[i].y -= y; - } - } - - status = _cairo_surface_show_text_glyphs (surface, op, source, - NULL, 0, - dev_glyphs, num_glyphs, - NULL, 0, 0, - scaled_font, - dev_clip); - - if (dev_clip != clip) - _cairo_clip_destroy (dev_clip); - free (dev_glyphs); - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-private.h deleted file mode 100644 index f20ab073932..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-private.h +++ /dev/null @@ -1,121 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_SURFACE_PRIVATE_H -#define CAIRO_SURFACE_PRIVATE_H - -#include "cairo.h" - -#include "cairo-types-private.h" -#include "cairo-list-private.h" -#include "cairo-reference-count-private.h" -#include "cairo-clip-private.h" -#include "cairo-surface-backend-private.h" - -typedef void (*cairo_surface_func_t) (cairo_surface_t *); - -struct _cairo_surface { - const cairo_surface_backend_t *backend; - cairo_device_t *device; - - /* We allow surfaces to override the backend->type by shoving something - * else into surface->type. This is for "wrapper" surfaces that want to - * hide their internal type from the user-level API. */ - cairo_surface_type_t type; - - cairo_content_t content; - - cairo_reference_count_t ref_count; - cairo_status_t status; - unsigned int unique_id; - unsigned int serial; - cairo_damage_t *damage; - - unsigned _finishing : 1; - unsigned finished : 1; - unsigned is_clear : 1; - unsigned has_font_options : 1; - unsigned owns_device : 1; - - cairo_user_data_array_t user_data; - cairo_user_data_array_t mime_data; - - cairo_matrix_t device_transform; - cairo_matrix_t device_transform_inverse; - cairo_list_t device_transform_observers; - - /* The actual resolution of the device, in dots per inch. */ - double x_resolution; - double y_resolution; - - /* The resolution that should be used when generating image-based - * fallback; generally only used by the analysis/paginated - * surfaces - */ - double x_fallback_resolution; - double y_fallback_resolution; - - /* A "snapshot" surface is immutable. See _cairo_surface_snapshot. */ - cairo_surface_t *snapshot_of; - cairo_surface_func_t snapshot_detach; - /* current snapshots of this surface*/ - cairo_list_t snapshots; - /* place upon snapshot list */ - cairo_list_t snapshot; - - /* - * Surface font options, falling back to backend's default options, - * and set using _cairo_surface_set_font_options(), and propagated by - * cairo_surface_create_similar(). - */ - cairo_font_options_t font_options; -}; - -cairo_private cairo_surface_t * -_cairo_surface_create_in_error (cairo_status_t status); - -cairo_private cairo_surface_t * -_cairo_int_surface_create_in_error (cairo_int_status_t status); - -cairo_private cairo_surface_t * -_cairo_surface_get_source (cairo_surface_t *surface, - cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_surface_flush (cairo_surface_t *surface, unsigned flags); - -#endif /* CAIRO_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-inline.h deleted file mode 100644 index bf89c772b42..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-inline.h +++ /dev/null @@ -1,67 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_SNAPSHOT_INLINE_H -#define CAIRO_SURFACE_SNAPSHOT_INLINE_H - -#include "cairo-surface-snapshot-private.h" -#include "cairo-surface-inline.h" - -static inline cairo_bool_t -_cairo_surface_snapshot_is_reused (cairo_surface_t *surface) -{ - return CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count) > 2; -} - -static inline cairo_surface_t * -_cairo_surface_snapshot_get_target (cairo_surface_t *surface) -{ - cairo_surface_snapshot_t *snapshot = (cairo_surface_snapshot_t *) surface; - cairo_surface_t *target; - - CAIRO_MUTEX_LOCK (snapshot->mutex); - target = _cairo_surface_reference (snapshot->target); - CAIRO_MUTEX_UNLOCK (snapshot->mutex); - - return target; -} - -static inline cairo_bool_t -_cairo_surface_is_snapshot (cairo_surface_t *surface) -{ - return surface->backend->type == (cairo_surface_type_t)CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT; -} - -#endif /* CAIRO_SURFACE_SNAPSHOT_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-private.h deleted file mode 100644 index 58bee7b49dd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot-private.h +++ /dev/null @@ -1,51 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_SNAPSHOT_PRIVATE_H -#define CAIRO_SURFACE_SNAPSHOT_PRIVATE_H - -#include "cairo-mutex-private.h" -#include "cairo-surface-private.h" -#include "cairo-surface-backend-private.h" - -struct _cairo_surface_snapshot { - cairo_surface_t base; - - cairo_mutex_t mutex; - cairo_surface_t *target; - cairo_surface_t *clone; -}; - -#endif /* CAIRO_SURFACE_SNAPSHOT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot.c deleted file mode 100644 index 68bf9054ecd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-snapshot.c +++ /dev/null @@ -1,289 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-snapshot-inline.h" - -static cairo_status_t -_cairo_surface_snapshot_finish (void *abstract_surface) -{ - cairo_surface_snapshot_t *surface = abstract_surface; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (surface->clone != NULL) { - cairo_surface_finish (surface->clone); - status = surface->clone->status; - - cairo_surface_destroy (surface->clone); - } - - CAIRO_MUTEX_FINI (surface->mutex); - - return status; -} - -static cairo_status_t -_cairo_surface_snapshot_flush (void *abstract_surface, unsigned flags) -{ - cairo_surface_snapshot_t *surface = abstract_surface; - cairo_surface_t *target; - cairo_status_t status; - - target = _cairo_surface_snapshot_get_target (&surface->base); - status = _cairo_surface_flush (target, flags); - cairo_surface_destroy (target); - - return status; -} - -static cairo_surface_t * -_cairo_surface_snapshot_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_surface_snapshot_t *surface = abstract_surface; - return _cairo_surface_get_source (surface->target, extents); /* XXX racy */ -} - -struct snapshot_extra { - cairo_surface_t *target; - void *extra; -}; - -static cairo_status_t -_cairo_surface_snapshot_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **extra_out) -{ - cairo_surface_snapshot_t *surface = abstract_surface; - struct snapshot_extra *extra; - cairo_status_t status; - - extra = malloc (sizeof (*extra)); - if (unlikely (extra == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - extra->target = _cairo_surface_snapshot_get_target (&surface->base); - status = _cairo_surface_acquire_source_image (extra->target, image_out, &extra->extra); - if (unlikely (status)) { - cairo_surface_destroy (extra->target); - free (extra); - } - - *extra_out = extra; - return status; -} - -static void -_cairo_surface_snapshot_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *_extra) -{ - struct snapshot_extra *extra = _extra; - - _cairo_surface_release_source_image (extra->target, image, extra->extra); - cairo_surface_destroy (extra->target); - free (extra); -} - -static cairo_bool_t -_cairo_surface_snapshot_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_surface_snapshot_t *surface = abstract_surface; - cairo_surface_t *target; - cairo_bool_t bounded; - - target = _cairo_surface_snapshot_get_target (&surface->base); - bounded = _cairo_surface_get_extents (target, extents); - cairo_surface_destroy (target); - - return bounded; -} - -static const cairo_surface_backend_t _cairo_surface_snapshot_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT, - _cairo_surface_snapshot_finish, - NULL, - - NULL, /* create similar */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_snapshot_source, - _cairo_surface_snapshot_acquire_source_image, - _cairo_surface_snapshot_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_surface_snapshot_get_extents, - NULL, /* get-font-options */ - - _cairo_surface_snapshot_flush, -}; - -static void -_cairo_surface_snapshot_copy_on_write (cairo_surface_t *surface) -{ - cairo_surface_snapshot_t *snapshot = (cairo_surface_snapshot_t *) surface; - cairo_image_surface_t *image; - cairo_surface_t *clone; - void *extra; - cairo_status_t status; - - TRACE ((stderr, "%s: target=%d\n", - __FUNCTION__, snapshot->target->unique_id)); - - /* We need to make an image copy of the original surface since the - * snapshot may exceed the lifetime of the original device, i.e. - * when we later need to use the snapshot the data may have already - * been lost. - */ - - CAIRO_MUTEX_LOCK (snapshot->mutex); - - if (snapshot->target->backend->snapshot != NULL) { - clone = snapshot->target->backend->snapshot (snapshot->target); - if (clone != NULL) { - assert (clone->status || ! _cairo_surface_is_snapshot (clone)); - goto done; - } - } - - /* XXX copy to a similar surface, leave acquisition till later? - * We should probably leave such decisions to the backend in case we - * rely upon devices/connections like Xlib. - */ - status = _cairo_surface_acquire_source_image (snapshot->target, &image, &extra); - if (unlikely (status)) { - snapshot->target = _cairo_surface_create_in_error (status); - status = _cairo_surface_set_error (surface, status); - goto unlock; - } - clone = image->base.backend->snapshot (&image->base); - _cairo_surface_release_source_image (snapshot->target, image, extra); - -done: - status = _cairo_surface_set_error (surface, clone->status); - snapshot->target = snapshot->clone = clone; - snapshot->base.type = clone->type; -unlock: - CAIRO_MUTEX_UNLOCK (snapshot->mutex); -} - -/** - * _cairo_surface_snapshot: - * @surface: a #cairo_surface_t - * - * Make an immutable reference to @surface. It is an error to call a - * surface-modifying function on the result of this function. The - * resulting 'snapshot' is a lazily copied-on-write surface i.e. it - * remains a reference to the original surface until that surface is - * written to again, at which time a copy is made of the original surface - * and the snapshot then points to that instead. Multiple snapshots of the - * same unmodified surface point to the same copy. - * - * The caller owns the return value and should call - * cairo_surface_destroy() when finished with it. This function will not - * return %NULL, but will return a nil surface instead. - * - * Return value: The snapshot surface. Note that the return surface - * may not necessarily be of the same type as @surface. - **/ -cairo_surface_t * -_cairo_surface_snapshot (cairo_surface_t *surface) -{ - cairo_surface_snapshot_t *snapshot; - cairo_status_t status; - - TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, surface->unique_id)); - - if (unlikely (surface->status)) - return _cairo_surface_create_in_error (surface->status); - - if (unlikely (surface->finished)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (surface->snapshot_of != NULL) - return cairo_surface_reference (surface); - - if (_cairo_surface_is_snapshot (surface)) - return cairo_surface_reference (surface); - - snapshot = (cairo_surface_snapshot_t *) - _cairo_surface_has_snapshot (surface, &_cairo_surface_snapshot_backend); - if (snapshot != NULL) - return cairo_surface_reference (&snapshot->base); - - snapshot = malloc (sizeof (cairo_surface_snapshot_t)); - if (unlikely (snapshot == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - _cairo_surface_init (&snapshot->base, - &_cairo_surface_snapshot_backend, - NULL, /* device */ - surface->content); - snapshot->base.type = surface->type; - - CAIRO_MUTEX_INIT (snapshot->mutex); - snapshot->target = surface; - snapshot->clone = NULL; - - status = _cairo_surface_copy_mime_data (&snapshot->base, surface); - if (unlikely (status)) { - cairo_surface_destroy (&snapshot->base); - return _cairo_surface_create_in_error (status); - } - - snapshot->base.device_transform = surface->device_transform; - snapshot->base.device_transform_inverse = surface->device_transform_inverse; - - _cairo_surface_attach_snapshot (surface, - &snapshot->base, - _cairo_surface_snapshot_copy_on_write); - - return &snapshot->base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-inline.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-inline.h deleted file mode 100644 index 0cd09e63e70..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-inline.h +++ /dev/null @@ -1,72 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_SUBSURFACE_INLINE_H -#define CAIRO_SURFACE_SUBSURFACE_INLINE_H - -#include "cairo-surface-subsurface-private.h" - -static inline cairo_surface_t * -_cairo_surface_subsurface_get_target (cairo_surface_t *surface) -{ - return ((cairo_surface_subsurface_t *) surface)->target; -} - -static inline void -_cairo_surface_subsurface_offset (cairo_surface_t *surface, - int *x, int *y) -{ - cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; - *x += ss->extents.x; - *y += ss->extents.y; -} - -static inline cairo_surface_t * -_cairo_surface_subsurface_get_target_with_offset (cairo_surface_t *surface, - int *x, int *y) -{ - cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; - *x += ss->extents.x; - *y += ss->extents.y; - return ss->target; -} - -static inline cairo_bool_t -_cairo_surface_is_subsurface (cairo_surface_t *surface) -{ - return surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE; -} - -#endif /* CAIRO_SURFACE_SUBSURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-private.h deleted file mode 100644 index 89c5cc01b9d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface-private.h +++ /dev/null @@ -1,55 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_SUBSURFACE_PRIVATE_H -#define CAIRO_SURFACE_SUBSURFACE_PRIVATE_H - -#include "cairo-surface-private.h" -#include "cairo-surface-backend-private.h" - -struct _cairo_surface_subsurface { - cairo_surface_t base; - - cairo_rectangle_int_t extents; - - cairo_surface_t *target; - cairo_surface_t *snapshot; -}; - -cairo_private void -_cairo_surface_subsurface_set_snapshot (cairo_surface_t *surface, - cairo_surface_t *snapshot); - -#endif /* CAIRO_SURFACE_SUBSURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface.c deleted file mode 100644 index b7dfd9d9e0c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-subsurface.c +++ /dev/null @@ -1,587 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-offset-private.h" -#include "cairo-surface-snapshot-private.h" -#include "cairo-surface-subsurface-private.h" - -static const cairo_surface_backend_t _cairo_surface_subsurface_backend; - -static cairo_status_t -_cairo_surface_subsurface_finish (void *abstract_surface) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - - cairo_surface_destroy (surface->target); - cairo_surface_destroy (surface->snapshot); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_surface_subsurface_create_similar (void *other, - cairo_content_t content, - int width, int height) -{ - cairo_surface_subsurface_t *surface = other; - - if (surface->target->backend->create_similar == NULL) - return NULL; - - return surface->target->backend->create_similar (surface->target, content, width, height); -} - -static cairo_surface_t * -_cairo_surface_subsurface_create_similar_image (void *other, - cairo_format_t format, - int width, int height) -{ - cairo_surface_subsurface_t *surface = other; - - if (surface->target->backend->create_similar_image == NULL) - return NULL; - - return surface->target->backend->create_similar_image (surface->target, - format, - width, height); -} - -static cairo_image_surface_t * -_cairo_surface_subsurface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_rectangle_int_t target_extents; - - target_extents.x = extents->x + surface->extents.x; - target_extents.y = extents->y + surface->extents.y; - target_extents.width = extents->width; - target_extents.height = extents->height; - - return _cairo_surface_map_to_image (surface->target, &target_extents); -} - -static cairo_int_status_t -_cairo_surface_subsurface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - return _cairo_surface_unmap_image (surface->target, image); -} - -static cairo_int_status_t -_cairo_surface_subsurface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; - cairo_status_t status; - cairo_clip_t *target_clip; - - target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); - status = _cairo_surface_offset_paint (surface->target, - -surface->extents.x, -surface->extents.y, - op, source, target_clip); - _cairo_clip_destroy (target_clip); - return status; -} - -static cairo_int_status_t -_cairo_surface_subsurface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; - cairo_status_t status; - cairo_clip_t *target_clip; - - target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); - status = _cairo_surface_offset_mask (surface->target, - -surface->extents.x, -surface->extents.y, - op, source, mask, target_clip); - _cairo_clip_destroy (target_clip); - return status; -} - -static cairo_int_status_t -_cairo_surface_subsurface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; - cairo_status_t status; - cairo_clip_t *target_clip; - - target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); - status = _cairo_surface_offset_fill (surface->target, - -surface->extents.x, -surface->extents.y, - op, source, path, fill_rule, tolerance, antialias, - target_clip); - _cairo_clip_destroy (target_clip); - return status; -} - -static cairo_int_status_t -_cairo_surface_subsurface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; - cairo_status_t status; - cairo_clip_t *target_clip; - - target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); - status = _cairo_surface_offset_stroke (surface->target, - -surface->extents.x, -surface->extents.y, - op, source, path, stroke_style, ctm, ctm_inverse, - tolerance, antialias, - target_clip); - _cairo_clip_destroy (target_clip); - return status; -} - -static cairo_int_status_t -_cairo_surface_subsurface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; - cairo_status_t status; - cairo_clip_t *target_clip; - - target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); - status = _cairo_surface_offset_glyphs (surface->target, - -surface->extents.x, -surface->extents.y, - op, source, - scaled_font, glyphs, num_glyphs, - target_clip); - _cairo_clip_destroy (target_clip); - return status; -} - -static cairo_status_t -_cairo_surface_subsurface_flush (void *abstract_surface, unsigned flags) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - return _cairo_surface_flush (surface->target, flags); -} - -static cairo_status_t -_cairo_surface_subsurface_mark_dirty (void *abstract_surface, - int x, int y, - int width, int height) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_status_t status; - - status = CAIRO_STATUS_SUCCESS; - if (surface->target->backend->mark_dirty_rectangle != NULL) { - cairo_rectangle_int_t rect, extents; - - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - - extents.x = extents.y = 0; - extents.width = surface->extents.width; - extents.height = surface->extents.height; - - if (_cairo_rectangle_intersect (&rect, &extents)) { - status = surface->target->backend->mark_dirty_rectangle (surface->target, - rect.x + surface->extents.x, - rect.y + surface->extents.y, - rect.width, rect.height); - } - } - - return status; -} - -static cairo_bool_t -_cairo_surface_subsurface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - - extents->x = 0; - extents->y = 0; - extents->width = surface->extents.width; - extents->height = surface->extents.height; - - return TRUE; -} - -static void -_cairo_surface_subsurface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - - if (surface->target->backend->get_font_options != NULL) - surface->target->backend->get_font_options (surface->target, options); -} - -static cairo_surface_t * -_cairo_surface_subsurface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_surface_t *source; - - source = _cairo_surface_get_source (surface->target, extents); - if (extents) - *extents = surface->extents; - - return source; -} - -static cairo_status_t -_cairo_surface_subsurface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **extra_out) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_surface_pattern_t pattern; - cairo_surface_t *image; - cairo_status_t status; - - image = _cairo_image_surface_create_with_content (surface->base.content, - surface->extents.width, - surface->extents.height); - if (unlikely (image->status)) - return image->status; - - _cairo_pattern_init_for_surface (&pattern, surface->target); - cairo_matrix_init_translate (&pattern.base.matrix, - surface->extents.x, - surface->extents.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - status = _cairo_surface_paint (image, - CAIRO_OPERATOR_SOURCE, - &pattern.base, NULL); - _cairo_pattern_fini (&pattern.base); - if (unlikely (status)) { - cairo_surface_destroy (image); - return status; - } - - *image_out = (cairo_image_surface_t *)image; - *extra_out = NULL; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_surface_subsurface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *abstract_extra) -{ - cairo_surface_destroy (&image->base); -} - -static cairo_surface_t * -_cairo_surface_subsurface_snapshot (void *abstract_surface) -{ - cairo_surface_subsurface_t *surface = abstract_surface; - cairo_surface_pattern_t pattern; - cairo_surface_t *clone; - cairo_status_t status; - - TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, surface->target->unique_id)); - - clone = _cairo_surface_create_scratch (surface->target, - surface->target->content, - surface->extents.width, - surface->extents.height, - NULL); - if (unlikely (clone->status)) - return clone; - - _cairo_pattern_init_for_surface (&pattern, surface->target); - cairo_matrix_init_translate (&pattern.base.matrix, - surface->extents.x, surface->extents.y); - pattern.base.filter = CAIRO_FILTER_NEAREST; - status = _cairo_surface_paint (clone, - CAIRO_OPERATOR_SOURCE, - &pattern.base, NULL); - _cairo_pattern_fini (&pattern.base); - - if (unlikely (status)) { - cairo_surface_destroy (clone); - clone = _cairo_surface_create_in_error (status); - } - - return clone; -} - -static cairo_t * -_cairo_surface_subsurface_create_context(void *target) -{ - cairo_surface_subsurface_t *surface = target; - return surface->target->backend->create_context (&surface->base); -} - -static const cairo_surface_backend_t _cairo_surface_subsurface_backend = { - CAIRO_SURFACE_TYPE_SUBSURFACE, - _cairo_surface_subsurface_finish, - - _cairo_surface_subsurface_create_context, - - _cairo_surface_subsurface_create_similar, - _cairo_surface_subsurface_create_similar_image, - _cairo_surface_subsurface_map_to_image, - _cairo_surface_subsurface_unmap_image, - - _cairo_surface_subsurface_source, - _cairo_surface_subsurface_acquire_source_image, - _cairo_surface_subsurface_release_source_image, - _cairo_surface_subsurface_snapshot, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_surface_subsurface_get_extents, - _cairo_surface_subsurface_get_font_options, - - _cairo_surface_subsurface_flush, - _cairo_surface_subsurface_mark_dirty, - - _cairo_surface_subsurface_paint, - _cairo_surface_subsurface_mask, - _cairo_surface_subsurface_stroke, - _cairo_surface_subsurface_fill, - NULL, /* fill/stroke */ - _cairo_surface_subsurface_glyphs, -}; - -/** - * cairo_surface_create_for_rectangle: - * @target: an existing surface for which the sub-surface will point to - * @x: the x-origin of the sub-surface from the top-left of the target surface (in device-space units) - * @y: the y-origin of the sub-surface from the top-left of the target surface (in device-space units) - * @width: width of the sub-surface (in device-space units) - * @height: height of the sub-surface (in device-space units) - * - * Create a new surface that is a rectangle within the target surface. - * All operations drawn to this surface are then clipped and translated - * onto the target surface. Nothing drawn via this sub-surface outside of - * its bounds is drawn onto the target surface, making this a useful method - * for passing constrained child surfaces to library routines that draw - * directly onto the parent surface, i.e. with no further backend allocations, - * double buffering or copies. - * - * The semantics of subsurfaces have not been finalized yet - * unless the rectangle is in full device units, is contained within - * the extents of the target surface, and the target or subsurface's - * device transforms are not changed. - * - * Return value: a pointer to the newly allocated surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if @other is already in an error state - * or any other error occurs. - * - * Since: 1.10 - **/ -cairo_surface_t * -cairo_surface_create_for_rectangle (cairo_surface_t *target, - double x, double y, - double width, double height) -{ - cairo_surface_subsurface_t *surface; - - if (unlikely (width < 0 || height < 0)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - if (unlikely (target->status)) - return _cairo_surface_create_in_error (target->status); - if (unlikely (target->finished)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - surface = malloc (sizeof (cairo_surface_subsurface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - x *= target->device_transform.xx; - y *= target->device_transform.yy; - - width *= target->device_transform.xx; - height *= target->device_transform.yy; - - x += target->device_transform.x0; - y += target->device_transform.y0; - - _cairo_surface_init (&surface->base, - &_cairo_surface_subsurface_backend, - NULL, /* device */ - target->content); - - /* XXX forced integer alignment */ - surface->extents.x = ceil (x); - surface->extents.y = ceil (y); - surface->extents.width = floor (x + width) - surface->extents.x; - surface->extents.height = floor (y + height) - surface->extents.y; - if ((surface->extents.width | surface->extents.height) < 0) - surface->extents.width = surface->extents.height = 0; - - if (target->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - /* Maintain subsurfaces as 1-depth */ - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) target; - surface->extents.x += sub->extents.x; - surface->extents.y += sub->extents.y; - target = sub->target; - } - - surface->target = cairo_surface_reference (target); - surface->base.type = surface->target->type; - - surface->snapshot = NULL; - - cairo_surface_set_device_scale (&surface->base, - target->device_transform.xx, - target->device_transform.yy); - - return &surface->base; -} - -cairo_surface_t * -_cairo_surface_create_for_rectangle_int (cairo_surface_t *target, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_subsurface_t *surface; - - if (unlikely (target->status)) - return _cairo_surface_create_in_error (target->status); - if (unlikely (target->finished)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - assert (target->backend->type != CAIRO_SURFACE_TYPE_SUBSURFACE); - - surface = malloc (sizeof (cairo_surface_subsurface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_surface_subsurface_backend, - NULL, /* device */ - target->content); - - surface->extents = *extents; - surface->extents.x *= target->device_transform.xx; - surface->extents.y *= target->device_transform.yy; - surface->extents.width *= target->device_transform.xx; - surface->extents.height *= target->device_transform.yy; - surface->extents.x += target->device_transform.x0; - surface->extents.y += target->device_transform.y0; - - surface->target = cairo_surface_reference (target); - surface->base.type = surface->target->type; - - surface->snapshot = NULL; - - cairo_surface_set_device_scale (&surface->base, - target->device_transform.xx, - target->device_transform.yy); - - return &surface->base; -} -/* XXX observe mark-dirty */ - -static void -_cairo_surface_subsurface_detach_snapshot (cairo_surface_t *surface) -{ - cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; - - TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, ss->target->unique_id)); - - cairo_surface_destroy (ss->snapshot); - ss->snapshot = NULL; -} - -void -_cairo_surface_subsurface_set_snapshot (cairo_surface_t *surface, - cairo_surface_t *snapshot) -{ - cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; - - TRACE ((stderr, "%s: target=%d, snapshot=%d\n", __FUNCTION__, - ss->target->unique_id, snapshot->unique_id)); - - /* FIXME: attaching the subsurface as a snapshot to its target creates - * a reference cycle. Let's make this call as a no-op until that bug - * is fixed. - */ - return; - - if (ss->snapshot) - _cairo_surface_detach_snapshot (ss->snapshot); - - ss->snapshot = cairo_surface_reference (snapshot); - - _cairo_surface_attach_snapshot (ss->target, &ss->base, - _cairo_surface_subsurface_detach_snapshot); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper-private.h deleted file mode 100644 index 6529ebc1115..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper-private.h +++ /dev/null @@ -1,193 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_SURFACE_WRAPPER_PRIVATE_H -#define CAIRO_SURFACE_WRAPPER_PRIVATE_H - -#include "cairoint.h" -#include "cairo-types-private.h" -#include "cairo-surface-backend-private.h" - -CAIRO_BEGIN_DECLS - -struct _cairo_surface_wrapper { - cairo_surface_t *target; - - cairo_matrix_t transform; - - cairo_bool_t has_extents; - cairo_rectangle_int_t extents; - const cairo_clip_t *clip; - - cairo_bool_t needs_transform; -}; - -cairo_private void -_cairo_surface_wrapper_init (cairo_surface_wrapper_t *wrapper, - cairo_surface_t *target); - -cairo_private void -_cairo_surface_wrapper_intersect_extents (cairo_surface_wrapper_t *wrapper, - const cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_surface_wrapper_set_inverse_transform (cairo_surface_wrapper_t *wrapper, - const cairo_matrix_t *transform); - -cairo_private void -_cairo_surface_wrapper_set_clip (cairo_surface_wrapper_t *wrapper, - const cairo_clip_t *clip); - -cairo_private void -_cairo_surface_wrapper_fini (cairo_surface_wrapper_t *wrapper); - -static inline cairo_bool_t -_cairo_surface_wrapper_has_fill_stroke (cairo_surface_wrapper_t *wrapper) -{ - return wrapper->target->backend->fill_stroke != NULL; -} - -cairo_private cairo_status_t -_cairo_surface_wrapper_acquire_source_image (cairo_surface_wrapper_t *wrapper, - cairo_image_surface_t **image_out, - void **image_extra); - -cairo_private void -_cairo_surface_wrapper_release_source_image (cairo_surface_wrapper_t *wrapper, - cairo_image_surface_t *image, - void *image_extra); - - -cairo_private cairo_status_t -_cairo_surface_wrapper_paint (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_wrapper_mask (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_wrapper_stroke (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_wrapper_fill_stroke (cairo_surface_wrapper_t *wrapper, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - const cairo_path_fixed_t*path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_wrapper_fill (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_wrapper_show_text_glyphs (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - -cairo_private cairo_surface_t * -_cairo_surface_wrapper_create_similar (cairo_surface_wrapper_t *wrapper, - cairo_content_t content, - int width, - int height); -cairo_private cairo_bool_t -_cairo_surface_wrapper_get_extents (cairo_surface_wrapper_t *wrapper, - cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_surface_wrapper_get_font_options (cairo_surface_wrapper_t *wrapper, - cairo_font_options_t *options); - -cairo_private cairo_surface_t * -_cairo_surface_wrapper_snapshot (cairo_surface_wrapper_t *wrapper); - -cairo_private cairo_bool_t -_cairo_surface_wrapper_has_show_text_glyphs (cairo_surface_wrapper_t *wrapper); - -static inline cairo_bool_t -_cairo_surface_wrapper_is_active (cairo_surface_wrapper_t *wrapper) -{ - return wrapper->target != (cairo_surface_t *) 0; -} - -cairo_private cairo_bool_t -_cairo_surface_wrapper_get_target_extents (cairo_surface_wrapper_t *wrapper, - cairo_rectangle_int_t *extents); - -CAIRO_END_DECLS - -#endif /* CAIRO_SURFACE_WRAPPER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper.c deleted file mode 100644 index 9236c8bf42e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface-wrapper.c +++ /dev/null @@ -1,685 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * Copyright © 2007 Adrian Johnson - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-clip-inline.h" -#include "cairo-error-private.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-wrapper-private.h" - -/* A collection of routines to facilitate surface wrapping */ - -static void -_copy_transformed_pattern (cairo_pattern_t *pattern, - const cairo_pattern_t *original, - const cairo_matrix_t *ctm_inverse) -{ - _cairo_pattern_init_static_copy (pattern, original); - - if (! _cairo_matrix_is_identity (ctm_inverse)) - _cairo_pattern_transform (pattern, ctm_inverse); -} - -cairo_status_t -_cairo_surface_wrapper_acquire_source_image (cairo_surface_wrapper_t *wrapper, - cairo_image_surface_t **image_out, - void **image_extra) -{ - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - return _cairo_surface_acquire_source_image (wrapper->target, - image_out, image_extra); -} - -void -_cairo_surface_wrapper_release_source_image (cairo_surface_wrapper_t *wrapper, - cairo_image_surface_t *image, - void *image_extra) -{ - _cairo_surface_release_source_image (wrapper->target, image, image_extra); -} - -static void -_cairo_surface_wrapper_get_transform (cairo_surface_wrapper_t *wrapper, - cairo_matrix_t *m) -{ - cairo_matrix_init_identity (m); - - if (wrapper->has_extents && (wrapper->extents.x || wrapper->extents.y)) - cairo_matrix_translate (m, -wrapper->extents.x, -wrapper->extents.y); - - if (! _cairo_matrix_is_identity (&wrapper->transform)) - cairo_matrix_multiply (m, &wrapper->transform, m); - - if (! _cairo_matrix_is_identity (&wrapper->target->device_transform)) - cairo_matrix_multiply (m, &wrapper->target->device_transform, m); -} - -static void -_cairo_surface_wrapper_get_inverse_transform (cairo_surface_wrapper_t *wrapper, - cairo_matrix_t *m) -{ - cairo_matrix_init_identity (m); - - if (! _cairo_matrix_is_identity (&wrapper->target->device_transform_inverse)) - cairo_matrix_multiply (m, &wrapper->target->device_transform_inverse, m); - - if (! _cairo_matrix_is_identity (&wrapper->transform)) { - cairo_matrix_t inv; - cairo_status_t status; - - inv = wrapper->transform; - status = cairo_matrix_invert (&inv); - assert (status == CAIRO_STATUS_SUCCESS); - cairo_matrix_multiply (m, &inv, m); - } - - if (wrapper->has_extents && (wrapper->extents.x || wrapper->extents.y)) - cairo_matrix_translate (m, wrapper->extents.x, wrapper->extents.y); -} - -static cairo_clip_t * -_cairo_surface_wrapper_get_clip (cairo_surface_wrapper_t *wrapper, - const cairo_clip_t *clip) -{ - cairo_clip_t *copy; - - copy = _cairo_clip_copy (clip); - if (wrapper->has_extents) { - copy = _cairo_clip_intersect_rectangle (copy, &wrapper->extents); - } - copy = _cairo_clip_transform (copy, &wrapper->transform); - if (! _cairo_matrix_is_identity (&wrapper->target->device_transform)) - copy = _cairo_clip_transform (copy, &wrapper->target->device_transform); - if (wrapper->clip) - copy = _cairo_clip_intersect_clip (copy, wrapper->clip); - - return copy; -} - -cairo_status_t -_cairo_surface_wrapper_paint (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_clip_t *dev_clip; - cairo_pattern_union_t source_copy; - - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); - if (_cairo_clip_is_all_clipped (dev_clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (wrapper->needs_transform) { - cairo_matrix_t m; - - _cairo_surface_wrapper_get_transform (wrapper, &m); - - status = cairo_matrix_invert (&m); - assert (status == CAIRO_STATUS_SUCCESS); - - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - } - - status = _cairo_surface_paint (wrapper->target, op, source, dev_clip); - - _cairo_clip_destroy (dev_clip); - return status; -} - - -cairo_status_t -_cairo_surface_wrapper_mask (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_clip_t *dev_clip; - cairo_pattern_union_t source_copy; - cairo_pattern_union_t mask_copy; - - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); - if (_cairo_clip_is_all_clipped (dev_clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (wrapper->needs_transform) { - cairo_matrix_t m; - - _cairo_surface_wrapper_get_transform (wrapper, &m); - - status = cairo_matrix_invert (&m); - assert (status == CAIRO_STATUS_SUCCESS); - - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - - _copy_transformed_pattern (&mask_copy.base, mask, &m); - mask = &mask_copy.base; - } - - status = _cairo_surface_mask (wrapper->target, op, source, mask, dev_clip); - - _cairo_clip_destroy (dev_clip); - return status; -} - -cairo_status_t -_cairo_surface_wrapper_stroke (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; - cairo_clip_t *dev_clip; - cairo_matrix_t dev_ctm = *ctm; - cairo_matrix_t dev_ctm_inverse = *ctm_inverse; - cairo_pattern_union_t source_copy; - - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); - if (_cairo_clip_is_all_clipped (dev_clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (wrapper->needs_transform) { - cairo_matrix_t m; - - _cairo_surface_wrapper_get_transform (wrapper, &m); - - status = _cairo_path_fixed_init_copy (&path_copy, dev_path); - if (unlikely (status)) - goto FINISH; - - _cairo_path_fixed_transform (&path_copy, &m); - dev_path = &path_copy; - - cairo_matrix_multiply (&dev_ctm, &dev_ctm, &m); - - status = cairo_matrix_invert (&m); - assert (status == CAIRO_STATUS_SUCCESS); - - cairo_matrix_multiply (&dev_ctm_inverse, &m, &dev_ctm_inverse); - - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - } - - status = _cairo_surface_stroke (wrapper->target, op, source, - dev_path, stroke_style, - &dev_ctm, &dev_ctm_inverse, - tolerance, antialias, - dev_clip); - - FINISH: - if (dev_path != path) - _cairo_path_fixed_fini (dev_path); - _cairo_clip_destroy (dev_clip); - return status; -} - -cairo_status_t -_cairo_surface_wrapper_fill_stroke (cairo_surface_wrapper_t *wrapper, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - const cairo_path_fixed_t*path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *)path; - cairo_matrix_t dev_ctm = *stroke_ctm; - cairo_matrix_t dev_ctm_inverse = *stroke_ctm_inverse; - cairo_clip_t *dev_clip; - cairo_pattern_union_t stroke_source_copy; - cairo_pattern_union_t fill_source_copy; - - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); - if (_cairo_clip_is_all_clipped (dev_clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (wrapper->needs_transform) { - cairo_matrix_t m; - - _cairo_surface_wrapper_get_transform (wrapper, &m); - - status = _cairo_path_fixed_init_copy (&path_copy, dev_path); - if (unlikely (status)) - goto FINISH; - - _cairo_path_fixed_transform (&path_copy, &m); - dev_path = &path_copy; - - cairo_matrix_multiply (&dev_ctm, &dev_ctm, &m); - - status = cairo_matrix_invert (&m); - assert (status == CAIRO_STATUS_SUCCESS); - - cairo_matrix_multiply (&dev_ctm_inverse, &m, &dev_ctm_inverse); - - _copy_transformed_pattern (&stroke_source_copy.base, stroke_source, &m); - stroke_source = &stroke_source_copy.base; - - _copy_transformed_pattern (&fill_source_copy.base, fill_source, &m); - fill_source = &fill_source_copy.base; - } - - status = _cairo_surface_fill_stroke (wrapper->target, - fill_op, fill_source, fill_rule, - fill_tolerance, fill_antialias, - dev_path, - stroke_op, stroke_source, - stroke_style, - &dev_ctm, &dev_ctm_inverse, - stroke_tolerance, stroke_antialias, - dev_clip); - - FINISH: - if (dev_path != path) - _cairo_path_fixed_fini (dev_path); - _cairo_clip_destroy (dev_clip); - return status; -} - -cairo_status_t -_cairo_surface_wrapper_fill (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; - cairo_pattern_union_t source_copy; - cairo_clip_t *dev_clip; - - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); - if (_cairo_clip_is_all_clipped (dev_clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - if (wrapper->needs_transform) { - cairo_matrix_t m; - - _cairo_surface_wrapper_get_transform (wrapper, &m); - - status = _cairo_path_fixed_init_copy (&path_copy, dev_path); - if (unlikely (status)) - goto FINISH; - - _cairo_path_fixed_transform (&path_copy, &m); - dev_path = &path_copy; - - status = cairo_matrix_invert (&m); - assert (status == CAIRO_STATUS_SUCCESS); - - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - } - - status = _cairo_surface_fill (wrapper->target, op, source, - dev_path, fill_rule, - tolerance, antialias, - dev_clip); - - FINISH: - if (dev_path != path) - _cairo_path_fixed_fini (dev_path); - _cairo_clip_destroy (dev_clip); - return status; -} - -cairo_status_t -_cairo_surface_wrapper_show_text_glyphs (cairo_surface_wrapper_t *wrapper, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_clip_t *dev_clip; - cairo_glyph_t stack_glyphs [CAIRO_STACK_ARRAY_LENGTH(cairo_glyph_t)]; - cairo_glyph_t *dev_glyphs = stack_glyphs; - cairo_scaled_font_t *dev_scaled_font = scaled_font; - cairo_pattern_union_t source_copy; - cairo_font_options_t options; - - if (unlikely (wrapper->target->status)) - return wrapper->target->status; - - dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); - if (_cairo_clip_is_all_clipped (dev_clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - cairo_surface_get_font_options (wrapper->target, &options); - cairo_font_options_merge (&options, &scaled_font->options); - - if (wrapper->needs_transform) { - cairo_matrix_t m; - int i; - - _cairo_surface_wrapper_get_transform (wrapper, &m); - - if (! _cairo_matrix_is_translation (&m)) { - cairo_matrix_t ctm; - - _cairo_matrix_multiply (&ctm, - &m, - &scaled_font->ctm); - dev_scaled_font = cairo_scaled_font_create (scaled_font->font_face, - &scaled_font->font_matrix, - &ctm, &options); - } - - if (num_glyphs > ARRAY_LENGTH (stack_glyphs)) { - dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); - if (unlikely (dev_glyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FINISH; - } - } - - for (i = 0; i < num_glyphs; i++) { - dev_glyphs[i] = glyphs[i]; - cairo_matrix_transform_point (&m, - &dev_glyphs[i].x, - &dev_glyphs[i].y); - } - - status = cairo_matrix_invert (&m); - assert (status == CAIRO_STATUS_SUCCESS); - - _copy_transformed_pattern (&source_copy.base, source, &m); - source = &source_copy.base; - } else { - if (! cairo_font_options_equal (&options, &scaled_font->options)) { - dev_scaled_font = cairo_scaled_font_create (scaled_font->font_face, - &scaled_font->font_matrix, - &scaled_font->ctm, - &options); - } - - /* show_text_glyphs is special because _cairo_surface_show_text_glyphs is allowed - * to modify the glyph array that's passed in. We must always - * copy the array before handing it to the backend. - */ - if (num_glyphs > ARRAY_LENGTH (stack_glyphs)) { - dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); - if (unlikely (dev_glyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FINISH; - } - } - - memcpy (dev_glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); - } - - status = _cairo_surface_show_text_glyphs (wrapper->target, op, source, - utf8, utf8_len, - dev_glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags, - dev_scaled_font, - dev_clip); - FINISH: - _cairo_clip_destroy (dev_clip); - if (dev_glyphs != stack_glyphs) - free (dev_glyphs); - if (dev_scaled_font != scaled_font) - cairo_scaled_font_destroy (dev_scaled_font); - return status; -} - -cairo_surface_t * -_cairo_surface_wrapper_create_similar (cairo_surface_wrapper_t *wrapper, - cairo_content_t content, - int width, - int height) -{ - return _cairo_surface_create_scratch (wrapper->target, - content, width, height, NULL); -} - -cairo_bool_t -_cairo_surface_wrapper_get_extents (cairo_surface_wrapper_t *wrapper, - cairo_rectangle_int_t *extents) -{ - if (wrapper->has_extents) { - if (_cairo_surface_get_extents (wrapper->target, extents)) - _cairo_rectangle_intersect (extents, &wrapper->extents); - else - *extents = wrapper->extents; - - return TRUE; - } else { - return _cairo_surface_get_extents (wrapper->target, extents); - } -} - -static cairo_bool_t -_cairo_surface_wrapper_needs_device_transform (cairo_surface_wrapper_t *wrapper) -{ - return - (wrapper->has_extents && (wrapper->extents.x | wrapper->extents.y)) || - ! _cairo_matrix_is_identity (&wrapper->transform) || - ! _cairo_matrix_is_identity (&wrapper->target->device_transform); -} - -void -_cairo_surface_wrapper_intersect_extents (cairo_surface_wrapper_t *wrapper, - const cairo_rectangle_int_t *extents) -{ - if (! wrapper->has_extents) { - wrapper->extents = *extents; - wrapper->has_extents = TRUE; - } else - _cairo_rectangle_intersect (&wrapper->extents, extents); - - wrapper->needs_transform = - _cairo_surface_wrapper_needs_device_transform (wrapper); -} - -void -_cairo_surface_wrapper_set_inverse_transform (cairo_surface_wrapper_t *wrapper, - const cairo_matrix_t *transform) -{ - cairo_status_t status; - - if (transform == NULL || _cairo_matrix_is_identity (transform)) { - cairo_matrix_init_identity (&wrapper->transform); - - wrapper->needs_transform = - _cairo_surface_wrapper_needs_device_transform (wrapper); - } else { - wrapper->transform = *transform; - status = cairo_matrix_invert (&wrapper->transform); - /* should always be invertible unless given pathological input */ - assert (status == CAIRO_STATUS_SUCCESS); - - wrapper->needs_transform = TRUE; - } -} - -void -_cairo_surface_wrapper_set_clip (cairo_surface_wrapper_t *wrapper, - const cairo_clip_t *clip) -{ - wrapper->clip = clip; -} - -void -_cairo_surface_wrapper_get_font_options (cairo_surface_wrapper_t *wrapper, - cairo_font_options_t *options) -{ - cairo_surface_get_font_options (wrapper->target, options); -} - -cairo_surface_t * -_cairo_surface_wrapper_snapshot (cairo_surface_wrapper_t *wrapper) -{ - if (wrapper->target->backend->snapshot) - return wrapper->target->backend->snapshot (wrapper->target); - - return NULL; -} - -cairo_bool_t -_cairo_surface_wrapper_has_show_text_glyphs (cairo_surface_wrapper_t *wrapper) -{ - return cairo_surface_has_show_text_glyphs (wrapper->target); -} - -void -_cairo_surface_wrapper_init (cairo_surface_wrapper_t *wrapper, - cairo_surface_t *target) -{ - wrapper->target = cairo_surface_reference (target); - cairo_matrix_init_identity (&wrapper->transform); - wrapper->has_extents = FALSE; - wrapper->extents.x = wrapper->extents.y = 0; - wrapper->clip = NULL; - - wrapper->needs_transform = FALSE; - if (target) { - wrapper->needs_transform = - ! _cairo_matrix_is_identity (&target->device_transform); - } -} - -void -_cairo_surface_wrapper_fini (cairo_surface_wrapper_t *wrapper) -{ - cairo_surface_destroy (wrapper->target); -} - -cairo_bool_t -_cairo_surface_wrapper_get_target_extents (cairo_surface_wrapper_t *wrapper, - cairo_rectangle_int_t *extents) -{ - cairo_rectangle_int_t clip; - cairo_bool_t has_clip; - - has_clip = _cairo_surface_get_extents (wrapper->target, &clip); - if (wrapper->clip) { - if (has_clip) { - if (! _cairo_rectangle_intersect (&clip, - _cairo_clip_get_extents (wrapper->clip))) - return FALSE; - } else { - has_clip = TRUE; - clip = *_cairo_clip_get_extents (wrapper->clip); - } - } - - if (has_clip && wrapper->needs_transform) { - cairo_matrix_t m; - double x1, y1, x2, y2; - - _cairo_surface_wrapper_get_inverse_transform (wrapper, &m); - - x1 = clip.x; - y1 = clip.y; - x2 = clip.x + clip.width; - y2 = clip.y + clip.height; - - _cairo_matrix_transform_bounding_box (&m, &x1, &y1, &x2, &y2, NULL); - - clip.x = floor (x1); - clip.y = floor (y1); - clip.width = ceil (x2) - clip.x; - clip.height = ceil (y2) - clip.y; - } - - if (has_clip) { - if (wrapper->has_extents) { - *extents = wrapper->extents; - return _cairo_rectangle_intersect (extents, &clip); - } else { - *extents = clip; - return TRUE; - } - } else if (wrapper->has_extents) { - *extents = wrapper->extents; - return TRUE; - } else { - _cairo_unbounded_rectangle_init (extents); - return TRUE; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface.c deleted file mode 100644 index 89345f593d6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-surface.c +++ /dev/null @@ -1,2749 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-damage-private.h" -#include "cairo-device-private.h" -#include "cairo-error-private.h" -#include "cairo-list-inline.h" -#include "cairo-image-surface-inline.h" -#include "cairo-recording-surface-private.h" -#include "cairo-region-private.h" -#include "cairo-surface-inline.h" -#include "cairo-tee-surface-private.h" - -/** - * SECTION:cairo-surface - * @Title: cairo_surface_t - * @Short_Description: Base class for surfaces - * @See_Also: #cairo_t, #cairo_pattern_t - * - * #cairo_surface_t is the abstract type representing all different drawing - * targets that cairo can render to. The actual drawings are - * performed using a cairo context. - * - * A cairo surface is created by using backend-specific - * constructors, typically of the form - * cairo_backend_surface_create(). - * - * Most surface types allow accessing the surface without using Cairo - * functions. If you do this, keep in mind that it is mandatory that you call - * cairo_surface_flush() before reading from or writing to the surface and that - * you must use cairo_surface_mark_dirty() after modifying it. - * - * Directly modifying an image surface - * - * void - * modify_image_surface (cairo_surface_t *surface) - * { - * unsigned char *data; - * int width, height, stride; - * - * // flush to ensure all writing to the image was done - * cairo_surface_flush (surface); - * - * // modify the image - * data = cairo_image_surface_get_data (surface); - * width = cairo_image_surface_get_width (surface); - * height = cairo_image_surface_get_height (surface); - * stride = cairo_image_surface_get_stride (surface); - * modify_image_data (data, width, height, stride); - * - * // mark the image dirty so Cairo clears its caches. - * cairo_surface_mark_dirty (surface); - * } - * - * - * Note that for other surface types it might be necessary to acquire the - * surface's device first. See cairo_device_acquire() for a discussion of - * devices. - **/ - -#define DEFINE_NIL_SURFACE(status, name) \ -const cairo_surface_t name = { \ - NULL, /* backend */ \ - NULL, /* device */ \ - CAIRO_SURFACE_TYPE_IMAGE, /* type */ \ - CAIRO_CONTENT_COLOR, /* content */ \ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ - status, /* status */ \ - 0, /* unique id */ \ - 0, /* serial */ \ - NULL, /* damage */ \ - FALSE, /* _finishing */ \ - FALSE, /* finished */ \ - TRUE, /* is_clear */ \ - FALSE, /* has_font_options */ \ - FALSE, /* owns_device */ \ - { 0, 0, 0, NULL, }, /* user_data */ \ - { 0, 0, 0, NULL, }, /* mime_data */ \ - { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \ - { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform_inverse */ \ - { NULL, NULL }, /* device_transform_observers */ \ - 0.0, /* x_resolution */ \ - 0.0, /* y_resolution */ \ - 0.0, /* x_fallback_resolution */ \ - 0.0, /* y_fallback_resolution */ \ - NULL, /* snapshot_of */ \ - NULL, /* snapshot_detach */ \ - { NULL, NULL }, /* snapshots */ \ - { NULL, NULL }, /* snapshot */ \ - { CAIRO_ANTIALIAS_DEFAULT, /* antialias */ \ - CAIRO_SUBPIXEL_ORDER_DEFAULT, /* subpixel_order */ \ - CAIRO_LCD_FILTER_DEFAULT, /* lcd_filter */ \ - CAIRO_HINT_STYLE_DEFAULT, /* hint_style */ \ - CAIRO_HINT_METRICS_DEFAULT, /* hint_metrics */ \ - CAIRO_ROUND_GLYPH_POS_DEFAULT /* round_glyph_positions */ \ - } /* font_options */ \ -} - -/* XXX error object! */ - -static DEFINE_NIL_SURFACE(CAIRO_STATUS_NO_MEMORY, _cairo_surface_nil); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_SURFACE_TYPE_MISMATCH, _cairo_surface_nil_surface_type_mismatch); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STATUS, _cairo_surface_nil_invalid_status); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_CONTENT, _cairo_surface_nil_invalid_content); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_FORMAT, _cairo_surface_nil_invalid_format); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_VISUAL, _cairo_surface_nil_invalid_visual); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_FILE_NOT_FOUND, _cairo_surface_nil_file_not_found); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_TEMP_FILE_ERROR, _cairo_surface_nil_temp_file_error); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_READ_ERROR, _cairo_surface_nil_read_error); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_WRITE_ERROR, _cairo_surface_nil_write_error); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STRIDE, _cairo_surface_nil_invalid_stride); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_SIZE, _cairo_surface_nil_invalid_size); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_TYPE_MISMATCH, _cairo_surface_nil_device_type_mismatch); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_ERROR, _cairo_surface_nil_device_error); - -static DEFINE_NIL_SURFACE(CAIRO_INT_STATUS_UNSUPPORTED, _cairo_surface_nil_unsupported); -static DEFINE_NIL_SURFACE(CAIRO_INT_STATUS_NOTHING_TO_DO, _cairo_surface_nil_nothing_to_do); - -static void _cairo_surface_finish_snapshots (cairo_surface_t *surface); -static void _cairo_surface_finish (cairo_surface_t *surface); - -/** - * _cairo_surface_set_error: - * @surface: a surface - * @status: a status value indicating an error - * - * Atomically sets surface->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS or any of the internal - * status values. - * - * All assignments of an error status to surface->status should happen - * through _cairo_surface_set_error(). Note that due to the nature of - * the atomic operation, it is not safe to call this function on the - * nil objects. - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - * - * Return value: the error status. - **/ -cairo_int_status_t -_cairo_surface_set_error (cairo_surface_t *surface, - cairo_int_status_t status) -{ - /* NOTHING_TO_DO is magic. We use it to break out of the inner-most - * surface function, but anything higher just sees "success". - */ - if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) - status = CAIRO_INT_STATUS_SUCCESS; - - if (status == CAIRO_INT_STATUS_SUCCESS || - status >= (int)CAIRO_INT_STATUS_LAST_STATUS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&surface->status, (cairo_status_t)status); - - return _cairo_error (status); -} - -/** - * cairo_surface_get_type: - * @surface: a #cairo_surface_t - * - * This function returns the type of the backend used to create - * a surface. See #cairo_surface_type_t for available types. - * - * Return value: The type of @surface. - * - * Since: 1.2 - **/ -cairo_surface_type_t -cairo_surface_get_type (cairo_surface_t *surface) -{ - /* We don't use surface->backend->type here so that some of the - * special "wrapper" surfaces such as cairo_paginated_surface_t - * can override surface->type with the type of the "child" - * surface. */ - return surface->type; -} - -/** - * cairo_surface_get_content: - * @surface: a #cairo_surface_t - * - * This function returns the content type of @surface which indicates - * whether the surface contains color and/or alpha information. See - * #cairo_content_t. - * - * Return value: The content type of @surface. - * - * Since: 1.2 - **/ -cairo_content_t -cairo_surface_get_content (cairo_surface_t *surface) -{ - return surface->content; -} - -/** - * cairo_surface_status: - * @surface: a #cairo_surface_t - * - * Checks whether an error has previously occurred for this - * surface. - * - * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_STATUS_NULL_POINTER, - * %CAIRO_STATUS_NO_MEMORY, %CAIRO_STATUS_READ_ERROR, - * %CAIRO_STATUS_INVALID_CONTENT, %CAIRO_STATUS_INVALID_FORMAT, or - * %CAIRO_STATUS_INVALID_VISUAL. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_surface_status (cairo_surface_t *surface) -{ - return surface->status; -} -slim_hidden_def (cairo_surface_status); - -static unsigned int -_cairo_surface_allocate_unique_id (void) -{ - static cairo_atomic_int_t unique_id; - -#if CAIRO_NO_MUTEX - if (++unique_id == 0) - unique_id = 1; - return unique_id; -#else - cairo_atomic_int_t old, id; - - do { - old = _cairo_atomic_uint_get (&unique_id); - id = old + 1; - if (id == 0) - id = 1; - } while (! _cairo_atomic_uint_cmpxchg (&unique_id, old, id)); - - return id; -#endif -} - -/** - * cairo_surface_get_device: - * @surface: a #cairo_surface_t - * - * This function returns the device for a @surface. - * See #cairo_device_t. - * - * Return value: The device for @surface or %NULL if the surface does - * not have an associated device. - * - * Since: 1.10 - **/ -cairo_device_t * -cairo_surface_get_device (cairo_surface_t *surface) -{ - if (unlikely (surface->status)) - return _cairo_device_create_in_error (surface->status); - - return surface->device; -} - -static cairo_bool_t -_cairo_surface_has_snapshots (cairo_surface_t *surface) -{ - return ! cairo_list_is_empty (&surface->snapshots); -} - -static cairo_bool_t -_cairo_surface_has_mime_data (cairo_surface_t *surface) -{ - return surface->mime_data.num_elements != 0; -} - -static void -_cairo_surface_detach_mime_data (cairo_surface_t *surface) -{ - if (! _cairo_surface_has_mime_data (surface)) - return; - - _cairo_user_data_array_fini (&surface->mime_data); - _cairo_user_data_array_init (&surface->mime_data); -} - -static void -_cairo_surface_detach_snapshots (cairo_surface_t *surface) -{ - while (_cairo_surface_has_snapshots (surface)) { - _cairo_surface_detach_snapshot (cairo_list_first_entry (&surface->snapshots, - cairo_surface_t, - snapshot)); - } -} - -void -_cairo_surface_detach_snapshot (cairo_surface_t *snapshot) -{ - assert (snapshot->snapshot_of != NULL); - - snapshot->snapshot_of = NULL; - cairo_list_del (&snapshot->snapshot); - - if (snapshot->snapshot_detach != NULL) - snapshot->snapshot_detach (snapshot); - - cairo_surface_destroy (snapshot); -} - -void -_cairo_surface_attach_snapshot (cairo_surface_t *surface, - cairo_surface_t *snapshot, - cairo_surface_func_t detach_func) -{ - assert (surface != snapshot); - assert (snapshot->snapshot_of != surface); - - cairo_surface_reference (snapshot); - - if (snapshot->snapshot_of != NULL) - _cairo_surface_detach_snapshot (snapshot); - - snapshot->snapshot_of = surface; - snapshot->snapshot_detach = detach_func; - - cairo_list_add (&snapshot->snapshot, &surface->snapshots); - - assert (_cairo_surface_has_snapshot (surface, snapshot->backend) == snapshot); -} - -cairo_surface_t * -_cairo_surface_has_snapshot (cairo_surface_t *surface, - const cairo_surface_backend_t *backend) -{ - cairo_surface_t *snapshot; - - cairo_list_foreach_entry (snapshot, cairo_surface_t, - &surface->snapshots, snapshot) - { - if (snapshot->backend == backend) - return snapshot; - } - - return NULL; -} - -cairo_status_t -_cairo_surface_begin_modification (cairo_surface_t *surface) -{ - assert (surface->status == CAIRO_STATUS_SUCCESS); - assert (! surface->finished); - - return _cairo_surface_flush (surface, 1); -} - -void -_cairo_surface_init (cairo_surface_t *surface, - const cairo_surface_backend_t *backend, - cairo_device_t *device, - cairo_content_t content) -{ - CAIRO_MUTEX_INITIALIZE (); - - surface->backend = backend; - surface->device = cairo_device_reference (device); - surface->content = content; - surface->type = backend->type; - - CAIRO_REFERENCE_COUNT_INIT (&surface->ref_count, 1); - surface->status = CAIRO_STATUS_SUCCESS; - surface->unique_id = _cairo_surface_allocate_unique_id (); - surface->finished = FALSE; - surface->_finishing = FALSE; - surface->is_clear = FALSE; - surface->serial = 0; - surface->damage = NULL; - surface->owns_device = (device != NULL); - - _cairo_user_data_array_init (&surface->user_data); - _cairo_user_data_array_init (&surface->mime_data); - - cairo_matrix_init_identity (&surface->device_transform); - cairo_matrix_init_identity (&surface->device_transform_inverse); - cairo_list_init (&surface->device_transform_observers); - - surface->x_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT; - surface->y_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT; - - surface->x_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT; - surface->y_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT; - - cairo_list_init (&surface->snapshots); - surface->snapshot_of = NULL; - - surface->has_font_options = FALSE; -} - -static void -_cairo_surface_copy_similar_properties (cairo_surface_t *surface, - cairo_surface_t *other) -{ - if (other->has_font_options || other->backend != surface->backend) { - cairo_font_options_t options; - - cairo_surface_get_font_options (other, &options); - _cairo_surface_set_font_options (surface, &options); - } - - cairo_surface_set_fallback_resolution (surface, - other->x_fallback_resolution, - other->y_fallback_resolution); -} - -/** - * cairo_surface_create_similar: - * @other: an existing surface used to select the backend of the new surface - * @content: the content for the new surface - * @width: width of the new surface, (in device-space units) - * @height: height of the new surface (in device-space units) - * - * Create a new surface that is as compatible as possible with an - * existing surface. For example the new surface will have the same - * fallback resolution and font options as @other. Generally, the new - * surface will also use the same backend as @other, unless that is - * not possible for some reason. The type of the returned surface may - * be examined with cairo_surface_get_type(). - * - * Initially the surface contents are all 0 (transparent if contents - * have transparency, black otherwise.) - * - * Use cairo_surface_create_similar_image() if you need an image surface - * which can be painted quickly to the target surface. - * - * Return value: a pointer to the newly allocated surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if @other is already in an error state - * or any other error occurs. - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_surface_create_similar (cairo_surface_t *other, - cairo_content_t content, - int width, - int height) -{ - cairo_surface_t *surface; - cairo_status_t status; - cairo_solid_pattern_t pattern; - - if (unlikely (other->status)) - return _cairo_surface_create_in_error (other->status); - if (unlikely (other->finished)) - return _cairo_surface_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); - if (unlikely (width < 0 || height < 0)) - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); - - if (unlikely (! CAIRO_CONTENT_VALID (content))) - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_CONTENT); - - if (unlikely (other->status)) - return _cairo_surface_create_in_error (other->status); - - /* We inherit the device scale, so create a larger surface */ - width = width * other->device_transform.xx; - height = height * other->device_transform.yy; - - surface = NULL; - if (other->backend->create_similar) - surface = other->backend->create_similar (other, content, width, height); - if (surface == NULL) - surface = cairo_surface_create_similar_image (other, - _cairo_format_from_content (content), - width, height); - - if (unlikely (surface->status)) - return surface; - - _cairo_surface_copy_similar_properties (surface, other); - cairo_surface_set_device_scale (surface, - other->device_transform.xx, - other->device_transform.yy); - - if (unlikely (surface->status)) - return surface; - - _cairo_pattern_init_solid (&pattern, CAIRO_COLOR_TRANSPARENT); - status = _cairo_surface_paint (surface, - CAIRO_OPERATOR_CLEAR, - &pattern.base, NULL); - if (unlikely (status)) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - - assert (surface->is_clear); - - return surface; -} - -/** - * cairo_surface_create_similar_image: - * @other: an existing surface used to select the preference of the new surface - * @format: the format for the new surface - * @width: width of the new surface, (in device-space units) - * @height: height of the new surface (in device-space units) - * - * Create a new image surface that is as compatible as possible for uploading - * to and the use in conjunction with an existing surface. However, this surface - * can still be used like any normal image surface. - * - * Initially the surface contents are all 0 (transparent if contents - * have transparency, black otherwise.) - * - * Use cairo_surface_create_similar() if you don't need an image surface. - * - * Return value: a pointer to the newly allocated image surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if @other is already in an error state - * or any other error occurs. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_surface_create_similar_image (cairo_surface_t *other, - cairo_format_t format, - int width, - int height) -{ - cairo_surface_t *image; - - if (unlikely (other->status)) - return _cairo_surface_create_in_error (other->status); - if (unlikely (other->finished)) - return _cairo_surface_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); - - if (unlikely (width < 0 || height < 0)) - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); - if (unlikely (! CAIRO_FORMAT_VALID (format))) - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_FORMAT); - - image = NULL; - if (other->backend->create_similar_image) - image = other->backend->create_similar_image (other, - format, width, height); - if (image == NULL) - image = cairo_image_surface_create (format, width, height); - - assert (image->is_clear); - - return image; -} -slim_hidden_def (cairo_surface_create_similar_image); - -/** - * _cairo_surface_map_to_image: - * @surface: an existing surface used to extract the image from - * @extents: limit the extraction to an rectangular region - * - * Returns an image surface that is the most efficient mechanism for - * modifying the backing store of the target surface. The region - * retrieved is limited to @extents. - * - * Note, the use of the original surface as a target or source whilst - * it is mapped is undefined. The result of mapping the surface - * multiple times is undefined. Calling cairo_surface_destroy() or - * cairo_surface_finish() on the resulting image surface results in - * undefined behavior. Changing the device transform of the image - * surface or of @surface before the image surface is unmapped results - * in undefined behavior. - * - * Assumes that @surface is valid (CAIRO_STATUS_SUCCESS, - * non-finished). - * - * Return value: a pointer to the newly allocated image surface. The - * caller must use _cairo_surface_unmap_image() to destroy this image - * surface. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if @other is already in an error state - * or any other error occurs. - * - * The returned image might have a %CAIRO_FORMAT_INVALID format. - **/ -cairo_image_surface_t * -_cairo_surface_map_to_image (cairo_surface_t *surface, - const cairo_rectangle_int_t *extents) -{ - cairo_image_surface_t *image = NULL; - - assert (extents != NULL); - - /* TODO: require map_to_image != NULL */ - if (surface->backend->map_to_image) - image = surface->backend->map_to_image (surface, extents); - - if (image == NULL) - image = _cairo_image_surface_clone_subimage (surface, extents); - - return image; -} - -/** - * _cairo_surface_unmap_image: - * @surface: the surface passed to _cairo_surface_map_to_image(). - * @image: the currently mapped image - * - * Unmaps the image surface as returned from - * _cairo_surface_map_to_image(). - * - * The content of the image will be uploaded to the target surface. - * Afterwards, the image is destroyed. - * - * Using an image surface which wasn't returned by - * _cairo_surface_map_to_image() results in undefined behavior. - * - * An image surface in error status can be passed to - * _cairo_surface_unmap_image(). - * - * Return value: the unmap status. - * - * Even if the unmap status is not successful, @image is destroyed. - **/ -cairo_int_status_t -_cairo_surface_unmap_image (cairo_surface_t *surface, - cairo_image_surface_t *image) -{ - cairo_surface_pattern_t pattern; - cairo_rectangle_int_t extents; - cairo_clip_t *clip; - cairo_int_status_t status; - - /* map_to_image can return error surfaces */ - if (unlikely (image->base.status)) { - status = image->base.status; - goto destroy; - } - - /* If the image is untouched just skip the update */ - if (image->base.serial == 0) { - status = CAIRO_STATUS_SUCCESS; - goto destroy; - } - - /* TODO: require unmap_image != NULL */ - if (surface->backend->unmap_image && - ! _cairo_image_surface_is_clone (image)) - { - status = surface->backend->unmap_image (surface, image); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - _cairo_pattern_init_for_surface (&pattern, &image->base); - pattern.base.filter = CAIRO_FILTER_NEAREST; - - /* We have to apply the translate from map_to_image's extents.x and .y */ - cairo_matrix_init_translate (&pattern.base.matrix, - image->base.device_transform.x0, - image->base.device_transform.y0); - - /* And we also have to clip the operation to the image's extents */ - extents.x = image->base.device_transform_inverse.x0; - extents.y = image->base.device_transform_inverse.y0; - extents.width = image->width; - extents.height = image->height; - clip = _cairo_clip_intersect_rectangle (NULL, &extents); - - status = _cairo_surface_paint (surface, - CAIRO_OPERATOR_SOURCE, - &pattern.base, - clip); - - _cairo_pattern_fini (&pattern.base); - _cairo_clip_destroy (clip); - -destroy: - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return status; -} - -/** - * cairo_surface_map_to_image: - * @surface: an existing surface used to extract the image from - * @extents: limit the extraction to an rectangular region - * - * Returns an image surface that is the most efficient mechanism for - * modifying the backing store of the target surface. The region retrieved - * may be limited to the @extents or %NULL for the whole surface - * - * Note, the use of the original surface as a target or source whilst - * it is mapped is undefined. The result of mapping the surface - * multiple times is undefined. Calling cairo_surface_destroy() or - * cairo_surface_finish() on the resulting image surface results in - * undefined behavior. Changing the device transform of the image - * surface or of @surface before the image surface is unmapped results - * in undefined behavior. - * - * Return value: a pointer to the newly allocated image surface. The caller - * must use cairo_surface_unmap_image() to destroy this image surface. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if @other is already in an error state - * or any other error occurs. If the returned pointer does not have an - * error status, it is guaranteed to be an image surface whose format - * is not %CAIRO_FORMAT_INVALID. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_surface_map_to_image (cairo_surface_t *surface, - const cairo_rectangle_int_t *extents) -{ - cairo_rectangle_int_t rect; - cairo_image_surface_t *image; - cairo_status_t status; - - if (unlikely (surface->status)) - return _cairo_surface_create_in_error (surface->status); - if (unlikely (surface->finished)) - return _cairo_surface_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); - - if (extents == NULL) { - if (unlikely (! surface->backend->get_extents (surface, &rect))) - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); - - extents = ▭ - } else { - cairo_rectangle_int_t surface_extents; - - /* If this surface is bounded, we can't map parts - * that are outside of it. */ - if (likely (surface->backend->get_extents (surface, &surface_extents))) { - if (unlikely (! _cairo_rectangle_contains_rectangle (&surface_extents, extents))) - return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); - } - } - - image = _cairo_surface_map_to_image (surface, extents); - - status = image->base.status; - if (unlikely (status)) { - cairo_surface_destroy (&image->base); - return _cairo_surface_create_in_error (status); - } - - if (image->format == CAIRO_FORMAT_INVALID) { - cairo_surface_destroy (&image->base); - image = _cairo_image_surface_clone_subimage (surface, extents); - } - - return &image->base; -} - -/** - * cairo_surface_unmap_image: - * @surface: the surface passed to cairo_surface_map_to_image(). - * @image: the currently mapped image - * - * Unmaps the image surface as returned from #cairo_surface_map_to_image(). - * - * The content of the image will be uploaded to the target surface. - * Afterwards, the image is destroyed. - * - * Using an image surface which wasn't returned by cairo_surface_map_to_image() - * results in undefined behavior. - * - * Since: 1.12 - **/ -void -cairo_surface_unmap_image (cairo_surface_t *surface, - cairo_surface_t *image) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - - if (unlikely (surface->status)) { - status = surface->status; - goto error; - } - if (unlikely (surface->finished)) { - status = _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - goto error; - } - if (unlikely (image->status)) { - status = image->status; - goto error; - } - if (unlikely (image->finished)) { - status = _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - goto error; - } - if (unlikely (! _cairo_surface_is_image (image))) { - status = _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - goto error; - } - - status = _cairo_surface_unmap_image (surface, - (cairo_image_surface_t *) image); - if (unlikely (status)) - _cairo_surface_set_error (surface, status); - - return; - -error: - _cairo_surface_set_error (surface, status); - cairo_surface_finish (image); - cairo_surface_destroy (image); -} - -cairo_surface_t * -_cairo_surface_create_scratch (cairo_surface_t *other, - cairo_content_t content, - int width, - int height, - const cairo_color_t *color) -{ - cairo_surface_t *surface; - cairo_status_t status; - cairo_solid_pattern_t pattern; - - if (unlikely (other->status)) - return _cairo_surface_create_in_error (other->status); - - surface = NULL; - if (other->backend->create_similar) - surface = other->backend->create_similar (other, content, width, height); - if (surface == NULL) - surface = cairo_surface_create_similar_image (other, - _cairo_format_from_content (content), - width, height); - - if (unlikely (surface->status)) - return surface; - - _cairo_surface_copy_similar_properties (surface, other); - - if (unlikely (surface->status)) - return surface; - - if (color) { - _cairo_pattern_init_solid (&pattern, color); - status = _cairo_surface_paint (surface, - color == CAIRO_COLOR_TRANSPARENT ? - CAIRO_OPERATOR_CLEAR : CAIRO_OPERATOR_SOURCE, - &pattern.base, NULL); - if (unlikely (status)) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - } - - return surface; -} - -/** - * cairo_surface_reference: - * @surface: a #cairo_surface_t - * - * Increases the reference count on @surface by one. This prevents - * @surface from being destroyed until a matching call to - * cairo_surface_destroy() is made. - * - * The number of references to a #cairo_surface_t can be get using - * cairo_surface_get_reference_count(). - * - * Return value: the referenced #cairo_surface_t. - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_surface_reference (cairo_surface_t *surface) -{ - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return surface; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); - - _cairo_reference_count_inc (&surface->ref_count); - - return surface; -} -slim_hidden_def (cairo_surface_reference); - -/** - * cairo_surface_destroy: - * @surface: a #cairo_surface_t - * - * Decreases the reference count on @surface by one. If the result is - * zero, then @surface and all associated resources are freed. See - * cairo_surface_reference(). - * - * Since: 1.0 - **/ -void -cairo_surface_destroy (cairo_surface_t *surface) -{ - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&surface->ref_count)) - return; - - assert (surface->snapshot_of == NULL); - - if (! surface->finished) { - _cairo_surface_finish_snapshots (surface); - /* We may have been referenced by a snapshot prior to have - * detaching it with the copy-on-write. - */ - if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count)) - return; - - _cairo_surface_finish (surface); - } - - if (surface->damage) - _cairo_damage_destroy (surface->damage); - - _cairo_user_data_array_fini (&surface->user_data); - _cairo_user_data_array_fini (&surface->mime_data); - - if (surface->owns_device) - cairo_device_destroy (surface->device); - - assert (surface->snapshot_of == NULL); - assert (! _cairo_surface_has_snapshots (surface)); - /* paranoid check that nobody took a reference whilst finishing */ - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); - - free (surface); -} -slim_hidden_def(cairo_surface_destroy); - -/** - * cairo_surface_get_reference_count: - * @surface: a #cairo_surface_t - * - * Returns the current reference count of @surface. - * - * Return value: the current reference count of @surface. If the - * object is a nil object, 0 will be returned. - * - * Since: 1.4 - **/ -unsigned int -cairo_surface_get_reference_count (cairo_surface_t *surface) -{ - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count); -} - -static void -_cairo_surface_finish_snapshots (cairo_surface_t *surface) -{ - cairo_status_t status; - - /* update the snapshots *before* we declare the surface as finished */ - surface->_finishing = TRUE; - status = _cairo_surface_flush (surface, 0); - (void) status; -} - -static void -_cairo_surface_finish (cairo_surface_t *surface) -{ - cairo_status_t status; - - surface->finished = TRUE; - - /* call finish even if in error mode */ - if (surface->backend->finish) { - status = surface->backend->finish (surface); - if (unlikely (status)) - _cairo_surface_set_error (surface, status); - } - - assert (surface->snapshot_of == NULL); - assert (!_cairo_surface_has_snapshots (surface)); -} - -/** - * cairo_surface_finish: - * @surface: the #cairo_surface_t to finish - * - * This function finishes the surface and drops all references to - * external resources. For example, for the Xlib backend it means - * that cairo will no longer access the drawable, which can be freed. - * After calling cairo_surface_finish() the only valid operations on a - * surface are getting and setting user, referencing and - * destroying, and flushing and finishing it. - * Further drawing to the surface will not affect the - * surface but will instead trigger a %CAIRO_STATUS_SURFACE_FINISHED - * error. - * - * When the last call to cairo_surface_destroy() decreases the - * reference count to zero, cairo will call cairo_surface_finish() if - * it hasn't been called already, before freeing the resources - * associated with the surface. - * - * Since: 1.0 - **/ -void -cairo_surface_finish (cairo_surface_t *surface) -{ - if (surface == NULL) - return; - - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return; - - if (surface->finished) - return; - - /* We have to be careful when decoupling potential reference cycles */ - cairo_surface_reference (surface); - - _cairo_surface_finish_snapshots (surface); - /* XXX need to block and wait for snapshot references */ - _cairo_surface_finish (surface); - - cairo_surface_destroy (surface); -} -slim_hidden_def (cairo_surface_finish); - -/** - * _cairo_surface_release_device_reference: - * @surface: a #cairo_surface_t - * - * This function makes @surface release the reference to its device. The - * function is intended to be used for avoiding cycling references for - * surfaces that are owned by their device, for example cache surfaces. - * Note that the @surface will still assume that the device is available. - * So it is the caller's responsibility to ensure the device stays around - * until the @surface is destroyed. Just calling cairo_surface_finish() is - * not enough. - **/ -void -_cairo_surface_release_device_reference (cairo_surface_t *surface) -{ - assert (surface->owns_device); - - cairo_device_destroy (surface->device); - surface->owns_device = FALSE; -} - -/** - * cairo_surface_get_user_data: - * @surface: a #cairo_surface_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Return user data previously attached to @surface using the specified - * key. If no user data has been attached with the given key this - * function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - * - * Since: 1.0 - **/ -void * -cairo_surface_get_user_data (cairo_surface_t *surface, - const cairo_user_data_key_t *key) -{ - /* Prevent reads of the array during teardown */ - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) - return NULL; - - return _cairo_user_data_array_get_data (&surface->user_data, key); -} - -/** - * cairo_surface_set_user_data: - * @surface: a #cairo_surface_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach to the surface - * @destroy: a #cairo_destroy_func_t which will be called when the - * surface is destroyed or when new user data is attached using the - * same key. - * - * Attach user data to @surface. To remove user data from a surface, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.0 - **/ -cairo_status_t -cairo_surface_set_user_data (cairo_surface_t *surface, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return surface->status; - - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - return _cairo_user_data_array_set_data (&surface->user_data, - key, user_data, destroy); -} - -/** - * cairo_surface_get_mime_data: - * @surface: a #cairo_surface_t - * @mime_type: the mime type of the image data - * @data: the image data to attached to the surface - * @length: the length of the image data - * - * Return mime data previously attached to @surface using the - * specified mime type. If no data has been attached with the given - * mime type, @data is set %NULL. - * - * Since: 1.10 - **/ -void -cairo_surface_get_mime_data (cairo_surface_t *surface, - const char *mime_type, - const unsigned char **data, - unsigned long *length) -{ - cairo_user_data_slot_t *slots; - int i, num_slots; - - *data = NULL; - *length = 0; - - /* Prevent reads of the array during teardown */ - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) - return; - - /* The number of mime-types attached to a surface is usually small, - * typically zero. Therefore it is quicker to do a strcmp() against - * each key than it is to intern the string (i.e. compute a hash, - * search the hash table, and do a final strcmp). - */ - num_slots = surface->mime_data.num_elements; - slots = _cairo_array_index (&surface->mime_data, 0); - for (i = 0; i < num_slots; i++) { - if (slots[i].key != NULL && strcmp ((char *) slots[i].key, mime_type) == 0) { - cairo_mime_data_t *mime_data = slots[i].user_data; - - *data = mime_data->data; - *length = mime_data->length; - return; - } - } -} -slim_hidden_def (cairo_surface_get_mime_data); - -static void -_cairo_mime_data_destroy (void *ptr) -{ - cairo_mime_data_t *mime_data = ptr; - - if (! _cairo_reference_count_dec_and_test (&mime_data->ref_count)) - return; - - if (mime_data->destroy && mime_data->closure) - mime_data->destroy (mime_data->closure); - - free (mime_data); -} - -/** - * CAIRO_MIME_TYPE_JBIG2: - * - * Joint Bi-level Image Experts Group image coding standard (ISO/IEC 11544). - * - * Since: 1.14 - **/ - -/** - * CAIRO_MIME_TYPE_JBIG2_GLOBAL: - * - * Joint Bi-level Image Experts Group image coding standard (ISO/IEC 11544) global segment. - * - * Since: 1.14 - **/ - -/** - * CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID: - * - * An unique identifier shared by a JBIG2 global segment and all JBIG2 images - * that depend on the global segment. - * - * Since: 1.14 - **/ - -/** - * CAIRO_MIME_TYPE_JP2: - * - * The Joint Photographic Experts Group (JPEG) 2000 image coding standard (ISO/IEC 15444-1). - * - * Since: 1.10 - **/ - -/** - * CAIRO_MIME_TYPE_JPEG: - * - * The Joint Photographic Experts Group (JPEG) image coding standard (ISO/IEC 10918-1). - * - * Since: 1.10 - **/ - -/** - * CAIRO_MIME_TYPE_PNG: - * - * The Portable Network Graphics image file format (ISO/IEC 15948). - * - * Since: 1.10 - **/ - -/** - * CAIRO_MIME_TYPE_URI: - * - * URI for an image file (unofficial MIME type). - * - * Since: 1.10 - **/ - -/** - * CAIRO_MIME_TYPE_UNIQUE_ID: - * - * Unique identifier for a surface (cairo specific MIME type). All surfaces with - * the same unique identifier will only be embedded once. - * - * Since: 1.12 - **/ - -/** - * cairo_surface_set_mime_data: - * @surface: a #cairo_surface_t - * @mime_type: the MIME type of the image data - * @data: the image data to attach to the surface - * @length: the length of the image data - * @destroy: a #cairo_destroy_func_t which will be called when the - * surface is destroyed or when new image data is attached using the - * same mime type. - * @closure: the data to be passed to the @destroy notifier - * - * Attach an image in the format @mime_type to @surface. To remove - * the data from a surface, call this function with same mime type - * and %NULL for @data. - * - * The attached image (or filename) data can later be used by backends - * which support it (currently: PDF, PS, SVG and Win32 Printing - * surfaces) to emit this data instead of making a snapshot of the - * @surface. This approach tends to be faster and requires less - * memory and disk space. - * - * The recognized MIME types are the following: %CAIRO_MIME_TYPE_JPEG, - * %CAIRO_MIME_TYPE_PNG, %CAIRO_MIME_TYPE_JP2, %CAIRO_MIME_TYPE_URI, - * %CAIRO_MIME_TYPE_UNIQUE_ID, %CAIRO_MIME_TYPE_JBIG2, - * %CAIRO_MIME_TYPE_JBIG2_GLOBAL, %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID. - * - * See corresponding backend surface docs for details about which MIME - * types it can handle. Caution: the associated MIME data will be - * discarded if you draw on the surface afterwards. Use this function - * with care. - * - * Even if a backend supports a MIME type, that does not mean cairo - * will always be able to use the attached MIME data. For example, if - * the backend does not natively support the compositing operation used - * to apply the MIME data to the backend. In that case, the MIME data - * will be ignored. Therefore, to apply an image in all cases, it is best - * to create an image surface which contains the decoded image data and - * then attach the MIME data to that. This ensures the image will always - * be used while still allowing the MIME data to be used whenever - * possible. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.10 - **/ -cairo_status_t -cairo_surface_set_mime_data (cairo_surface_t *surface, - const char *mime_type, - const unsigned char *data, - unsigned long length, - cairo_destroy_func_t destroy, - void *closure) -{ - cairo_status_t status; - cairo_mime_data_t *mime_data; - - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return surface->status; - - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - status = _cairo_intern_string (&mime_type, -1); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); - - if (data != NULL) { - mime_data = malloc (sizeof (cairo_mime_data_t)); - if (unlikely (mime_data == NULL)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_NO_MEMORY)); - - CAIRO_REFERENCE_COUNT_INIT (&mime_data->ref_count, 1); - - mime_data->data = (unsigned char *) data; - mime_data->length = length; - mime_data->destroy = destroy; - mime_data->closure = closure; - } else - mime_data = NULL; - - status = _cairo_user_data_array_set_data (&surface->mime_data, - (cairo_user_data_key_t *) mime_type, - mime_data, - _cairo_mime_data_destroy); - if (unlikely (status)) { - free (mime_data); - - return _cairo_surface_set_error (surface, status); - } - - return CAIRO_STATUS_SUCCESS; -} -slim_hidden_def (cairo_surface_set_mime_data); - -/** - * cairo_surface_supports_mime_type: - * @surface: a #cairo_surface_t - * @mime_type: the mime type - * - * Return whether @surface supports @mime_type. - * - * Return value: %TRUE if @surface supports - * @mime_type, %FALSE otherwise - * - * Since: 1.12 - **/ -cairo_bool_t -cairo_surface_supports_mime_type (cairo_surface_t *surface, - const char *mime_type) -{ - const char **types; - - if (unlikely (surface->status)) - return FALSE; - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (surface->backend->get_supported_mime_types) { - types = surface->backend->get_supported_mime_types (surface); - if (types) { - while (*types) { - if (strcmp (*types, mime_type) == 0) - return TRUE; - types++; - } - } - } - - return FALSE; -} -slim_hidden_def (cairo_surface_supports_mime_type); - -static void -_cairo_mime_data_reference (const void *key, void *elt, void *closure) -{ - cairo_mime_data_t *mime_data = elt; - - _cairo_reference_count_inc (&mime_data->ref_count); -} - -cairo_status_t -_cairo_surface_copy_mime_data (cairo_surface_t *dst, - cairo_surface_t *src) -{ - cairo_status_t status; - - if (dst->status) - return dst->status; - - if (src->status) - return _cairo_surface_set_error (dst, src->status); - - /* first copy the mime-data, discarding any already set on dst */ - status = _cairo_user_data_array_copy (&dst->mime_data, &src->mime_data); - if (unlikely (status)) - return _cairo_surface_set_error (dst, status); - - /* now increment the reference counters for the copies */ - _cairo_user_data_array_foreach (&dst->mime_data, - _cairo_mime_data_reference, - NULL); - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_surface_set_font_options: - * @surface: a #cairo_surface_t - * @options: a #cairo_font_options_t object that contains the - * options to use for this surface instead of backend's default - * font options. - * - * Sets the default font rendering options for the surface. - * This is useful to correctly propagate default font options when - * falling back to an image surface in a backend implementation. - * This affects the options returned in cairo_surface_get_font_options(). - * - * If @options is %NULL the surface options are reset to those of - * the backend default. - **/ -void -_cairo_surface_set_font_options (cairo_surface_t *surface, - cairo_font_options_t *options) -{ - if (surface->status) - return; - - assert (surface->snapshot_of == NULL); - - if (surface->finished) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (options) { - surface->has_font_options = TRUE; - _cairo_font_options_init_copy (&surface->font_options, options); - } else { - surface->has_font_options = FALSE; - } -} - -/** - * cairo_surface_get_font_options: - * @surface: a #cairo_surface_t - * @options: a #cairo_font_options_t object into which to store - * the retrieved options. All existing values are overwritten - * - * Retrieves the default font rendering options for the surface. - * This allows display surfaces to report the correct subpixel order - * for rendering on them, print surfaces to disable hinting of - * metrics and so forth. The result can then be used with - * cairo_scaled_font_create(). - * - * Since: 1.0 - **/ -void -cairo_surface_get_font_options (cairo_surface_t *surface, - cairo_font_options_t *options) -{ - if (cairo_font_options_status (options)) - return; - - if (surface->status) { - _cairo_font_options_init_default (options); - return; - } - - if (! surface->has_font_options) { - surface->has_font_options = TRUE; - - _cairo_font_options_init_default (&surface->font_options); - - if (!surface->finished && surface->backend->get_font_options) { - surface->backend->get_font_options (surface, &surface->font_options); - } - } - - _cairo_font_options_init_copy (options, &surface->font_options); -} -slim_hidden_def (cairo_surface_get_font_options); - -cairo_status_t -_cairo_surface_flush (cairo_surface_t *surface, unsigned flags) -{ - /* update the current snapshots *before* the user updates the surface */ - _cairo_surface_detach_snapshots (surface); - if (surface->snapshot_of != NULL) - _cairo_surface_detach_snapshot (surface); - _cairo_surface_detach_mime_data (surface); - - return __cairo_surface_flush (surface, flags); -} - -/** - * cairo_surface_flush: - * @surface: a #cairo_surface_t - * - * Do any pending drawing for the surface and also restore any - * temporary modifications cairo has made to the surface's - * state. This function must be called before switching from - * drawing on the surface with cairo to drawing on it directly - * with native APIs. If the surface doesn't support direct access, - * then this function does nothing. - * - * Since: 1.0 - **/ -void -cairo_surface_flush (cairo_surface_t *surface) -{ - cairo_status_t status; - - if (surface->status) - return; - - if (surface->finished) - return; - - status = _cairo_surface_flush (surface, 0); - if (unlikely (status)) - _cairo_surface_set_error (surface, status); -} -slim_hidden_def (cairo_surface_flush); - -/** - * cairo_surface_mark_dirty: - * @surface: a #cairo_surface_t - * - * Tells cairo that drawing has been done to surface using means other - * than cairo, and that cairo should reread any cached areas. Note - * that you must call cairo_surface_flush() before doing such drawing. - * - * Since: 1.0 - **/ -void -cairo_surface_mark_dirty (cairo_surface_t *surface) -{ - cairo_rectangle_int_t extents; - - if (unlikely (surface->status)) - return; - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - _cairo_surface_get_extents (surface, &extents); - cairo_surface_mark_dirty_rectangle (surface, - extents.x, extents.y, - extents.width, extents.height); -} -slim_hidden_def (cairo_surface_mark_dirty); - -/** - * cairo_surface_mark_dirty_rectangle: - * @surface: a #cairo_surface_t - * @x: X coordinate of dirty rectangle - * @y: Y coordinate of dirty rectangle - * @width: width of dirty rectangle - * @height: height of dirty rectangle - * - * Like cairo_surface_mark_dirty(), but drawing has been done only to - * the specified rectangle, so that cairo can retain cached contents - * for other parts of the surface. - * - * Any cached clip set on the surface will be reset by this function, - * to make sure that future cairo calls have the clip set that they - * expect. - * - * Since: 1.0 - **/ -void -cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, - int x, - int y, - int width, - int height) -{ - cairo_status_t status; - - if (unlikely (surface->status)) - return; - - assert (surface->snapshot_of == NULL); - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - /* The application *should* have called cairo_surface_flush() before - * modifying the surface independently of cairo (and thus having to - * call mark_dirty()). */ - assert (! _cairo_surface_has_snapshots (surface)); - assert (! _cairo_surface_has_mime_data (surface)); - - surface->is_clear = FALSE; - surface->serial++; - - if (surface->damage) { - cairo_box_t box; - - box.p1.x = x; - box.p1.y = y; - box.p2.x = x + width; - box.p2.y = y + height; - - surface->damage = _cairo_damage_add_box (surface->damage, &box); - } - - if (surface->backend->mark_dirty_rectangle != NULL) { - /* XXX: FRAGILE: We're ignoring the scaling component of - * device_transform here. I don't know what the right thing to - * do would actually be if there were some scaling here, but - * we avoid this since device_transfom scaling is not exported - * publicly and mark_dirty is not used internally. */ - status = surface->backend->mark_dirty_rectangle (surface, - x + surface->device_transform.x0, - y + surface->device_transform.y0, - width, height); - - if (unlikely (status)) - _cairo_surface_set_error (surface, status); - } -} -slim_hidden_def (cairo_surface_mark_dirty_rectangle); - -/** - * cairo_surface_set_device_scale: - * @surface: a #cairo_surface_t - * @x_scale: a scale factor in the X direction - * @y_scale: a scale factor in the Y direction - * - * Sets a scale that is multiplied to the device coordinates determined - * by the CTM when drawing to @surface. One common use for this is to - * render to very high resolution display devices at a scale factor, so - * that code that assumes 1 pixel will be a certain size will still work. - * Setting a transformation via cairo_translate() isn't - * sufficient to do this, since functions like - * cairo_device_to_user() will expose the hidden scale. - * - * Note that the scale affects drawing to the surface as well as - * using the surface in a source pattern. - * - * Since: 1.14 - **/ -void -cairo_surface_set_device_scale (cairo_surface_t *surface, - double x_scale, - double y_scale) -{ - cairo_status_t status; - - if (unlikely (surface->status)) - return; - - assert (surface->snapshot_of == NULL); - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) { - _cairo_surface_set_error (surface, status); - return; - } - - surface->device_transform.xx = x_scale; - surface->device_transform.yy = y_scale; - surface->device_transform.xy = 0.0; - surface->device_transform.yx = 0.0; - - surface->device_transform_inverse = surface->device_transform; - status = cairo_matrix_invert (&surface->device_transform_inverse); - /* should always be invertible unless given pathological input */ - assert (status == CAIRO_STATUS_SUCCESS); - - _cairo_observers_notify (&surface->device_transform_observers, surface); -} -slim_hidden_def (cairo_surface_set_device_scale); - -/** - * cairo_surface_get_device_scale: - * @surface: a #cairo_surface_t - * @x_scale: the scale in the X direction, in device units - * @y_scale: the scale in the Y direction, in device units - * - * This function returns the previous device offset set by - * cairo_surface_set_device_scale(). - * - * Since: 1.14 - **/ -void -cairo_surface_get_device_scale (cairo_surface_t *surface, - double *x_scale, - double *y_scale) -{ - if (x_scale) - *x_scale = surface->device_transform.xx; - if (y_scale) - *y_scale = surface->device_transform.yy; -} -slim_hidden_def (cairo_surface_get_device_scale); - -/** - * cairo_surface_set_device_offset: - * @surface: a #cairo_surface_t - * @x_offset: the offset in the X direction, in device units - * @y_offset: the offset in the Y direction, in device units - * - * Sets an offset that is added to the device coordinates determined - * by the CTM when drawing to @surface. One use case for this function - * is when we want to create a #cairo_surface_t that redirects drawing - * for a portion of an onscreen surface to an offscreen surface in a - * way that is completely invisible to the user of the cairo - * API. Setting a transformation via cairo_translate() isn't - * sufficient to do this, since functions like - * cairo_device_to_user() will expose the hidden offset. - * - * Note that the offset affects drawing to the surface as well as - * using the surface in a source pattern. - * - * Since: 1.0 - **/ -void -cairo_surface_set_device_offset (cairo_surface_t *surface, - double x_offset, - double y_offset) -{ - cairo_status_t status; - - if (unlikely (surface->status)) - return; - - assert (surface->snapshot_of == NULL); - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) { - _cairo_surface_set_error (surface, status); - return; - } - - surface->device_transform.x0 = x_offset; - surface->device_transform.y0 = y_offset; - - surface->device_transform_inverse = surface->device_transform; - status = cairo_matrix_invert (&surface->device_transform_inverse); - /* should always be invertible unless given pathological input */ - assert (status == CAIRO_STATUS_SUCCESS); - - _cairo_observers_notify (&surface->device_transform_observers, surface); -} -slim_hidden_def (cairo_surface_set_device_offset); - -/** - * cairo_surface_get_device_offset: - * @surface: a #cairo_surface_t - * @x_offset: the offset in the X direction, in device units - * @y_offset: the offset in the Y direction, in device units - * - * This function returns the previous device offset set by - * cairo_surface_set_device_offset(). - * - * Since: 1.2 - **/ -void -cairo_surface_get_device_offset (cairo_surface_t *surface, - double *x_offset, - double *y_offset) -{ - if (x_offset) - *x_offset = surface->device_transform.x0; - if (y_offset) - *y_offset = surface->device_transform.y0; -} -slim_hidden_def (cairo_surface_get_device_offset); - -/** - * cairo_surface_set_fallback_resolution: - * @surface: a #cairo_surface_t - * @x_pixels_per_inch: horizontal setting for pixels per inch - * @y_pixels_per_inch: vertical setting for pixels per inch - * - * Set the horizontal and vertical resolution for image fallbacks. - * - * When certain operations aren't supported natively by a backend, - * cairo will fallback by rendering operations to an image and then - * overlaying that image onto the output. For backends that are - * natively vector-oriented, this function can be used to set the - * resolution used for these image fallbacks, (larger values will - * result in more detailed images, but also larger file sizes). - * - * Some examples of natively vector-oriented backends are the ps, pdf, - * and svg backends. - * - * For backends that are natively raster-oriented, image fallbacks are - * still possible, but they are always performed at the native - * device resolution. So this function has no effect on those - * backends. - * - * Note: The fallback resolution only takes effect at the time of - * completing a page (with cairo_show_page() or cairo_copy_page()) so - * there is currently no way to have more than one fallback resolution - * in effect on a single page. - * - * The default fallback resoultion is 300 pixels per inch in both - * dimensions. - * - * Since: 1.2 - **/ -void -cairo_surface_set_fallback_resolution (cairo_surface_t *surface, - double x_pixels_per_inch, - double y_pixels_per_inch) -{ - cairo_status_t status; - - if (unlikely (surface->status)) - return; - - assert (surface->snapshot_of == NULL); - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (x_pixels_per_inch <= 0 || y_pixels_per_inch <= 0) { - /* XXX Could delay raising the error until we fallback, but throwing - * the error here means that we can catch the real culprit. - */ - _cairo_surface_set_error (surface, CAIRO_STATUS_INVALID_MATRIX); - return; - } - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) { - _cairo_surface_set_error (surface, status); - return; - } - - surface->x_fallback_resolution = x_pixels_per_inch; - surface->y_fallback_resolution = y_pixels_per_inch; -} -slim_hidden_def (cairo_surface_set_fallback_resolution); - -/** - * cairo_surface_get_fallback_resolution: - * @surface: a #cairo_surface_t - * @x_pixels_per_inch: horizontal pixels per inch - * @y_pixels_per_inch: vertical pixels per inch - * - * This function returns the previous fallback resolution set by - * cairo_surface_set_fallback_resolution(), or default fallback - * resolution if never set. - * - * Since: 1.8 - **/ -void -cairo_surface_get_fallback_resolution (cairo_surface_t *surface, - double *x_pixels_per_inch, - double *y_pixels_per_inch) -{ - if (x_pixels_per_inch) - *x_pixels_per_inch = surface->x_fallback_resolution; - if (y_pixels_per_inch) - *y_pixels_per_inch = surface->y_fallback_resolution; -} - -cairo_bool_t -_cairo_surface_has_device_transform (cairo_surface_t *surface) -{ - return ! _cairo_matrix_is_identity (&surface->device_transform); -} - -/** - * _cairo_surface_acquire_source_image: - * @surface: a #cairo_surface_t - * @image_out: location to store a pointer to an image surface that - * has identical contents to @surface. This surface could be @surface - * itself, a surface held internal to @surface, or it could be a new - * surface with a copy of the relevant portion of @surface. - * @image_extra: location to store image specific backend data - * - * Gets an image surface to use when drawing as a fallback when drawing with - * @surface as a source. _cairo_surface_release_source_image() must be called - * when finished. - * - * Return value: %CAIRO_STATUS_SUCCESS if an image was stored in @image_out. - * %CAIRO_INT_STATUS_UNSUPPORTED if an image cannot be retrieved for the specified - * surface. Or %CAIRO_STATUS_NO_MEMORY. - **/ -cairo_status_t -_cairo_surface_acquire_source_image (cairo_surface_t *surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_status_t status; - - if (unlikely (surface->status)) - return surface->status; - - assert (!surface->finished); - - if (surface->backend->acquire_source_image == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = surface->backend->acquire_source_image (surface, - image_out, image_extra); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); - - _cairo_debug_check_image_surface_is_defined (&(*image_out)->base); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_surface_default_acquire_source_image (void *_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_surface_t *surface = _surface; - cairo_rectangle_int_t extents; - - if (unlikely (! surface->backend->get_extents (surface, &extents))) - return _cairo_error (CAIRO_STATUS_INVALID_SIZE); - - *image_out = _cairo_surface_map_to_image (surface, &extents); - *image_extra = NULL; - return (*image_out)->base.status; -} - -/** - * _cairo_surface_release_source_image: - * @surface: a #cairo_surface_t - * @image_extra: same as return from the matching _cairo_surface_acquire_source_image() - * - * Releases any resources obtained with _cairo_surface_acquire_source_image() - **/ -void -_cairo_surface_release_source_image (cairo_surface_t *surface, - cairo_image_surface_t *image, - void *image_extra) -{ - assert (!surface->finished); - - if (surface->backend->release_source_image) - surface->backend->release_source_image (surface, image, image_extra); -} - -void -_cairo_surface_default_release_source_image (void *surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_status_t ignored; - - ignored = _cairo_surface_unmap_image (surface, image); - (void)ignored; -} - - -cairo_surface_t * -_cairo_surface_get_source (cairo_surface_t *surface, - cairo_rectangle_int_t *extents) -{ - assert (surface->backend->source); - return surface->backend->source (surface, extents); -} - -cairo_surface_t * -_cairo_surface_default_source (void *surface, - cairo_rectangle_int_t *extents) -{ - if (extents) - _cairo_surface_get_extents(surface, extents); - return surface; -} - -static cairo_status_t -_pattern_has_error (const cairo_pattern_t *pattern) -{ - const cairo_surface_pattern_t *spattern; - - if (unlikely (pattern->status)) - return pattern->status; - - if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) - return CAIRO_STATUS_SUCCESS; - - spattern = (const cairo_surface_pattern_t *) pattern; - if (unlikely (spattern->surface->status)) - return spattern->surface->status; - - if (unlikely (spattern->surface->finished)) - return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -nothing_to_do (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source) -{ - if (_cairo_pattern_is_clear (source)) { - if (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD) - return TRUE; - - if (op == CAIRO_OPERATOR_SOURCE) - op = CAIRO_OPERATOR_CLEAR; - } - - if (op == CAIRO_OPERATOR_CLEAR && surface->is_clear) - return TRUE; - - if (op == CAIRO_OPERATOR_ATOP && (surface->content & CAIRO_CONTENT_COLOR) ==0) - return TRUE; - - return FALSE; -} - -cairo_status_t -_cairo_surface_paint (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - status = _pattern_has_error (source); - if (unlikely (status)) - return status; - - if (nothing_to_do (surface, op, source)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) - return status; - - status = surface->backend->paint (surface, op, source, clip); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - surface->is_clear = op == CAIRO_OPERATOR_CLEAR && clip == NULL; - surface->serial++; - } - - return _cairo_surface_set_error (surface, status); -} - -cairo_status_t -_cairo_surface_mask (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - /* If the mask is blank, this is just an expensive no-op */ - if (_cairo_pattern_is_clear (mask) && - _cairo_operator_bounded_by_mask (op)) - { - return CAIRO_STATUS_SUCCESS; - } - - status = _pattern_has_error (source); - if (unlikely (status)) - return status; - - status = _pattern_has_error (mask); - if (unlikely (status)) - return status; - - if (nothing_to_do (surface, op, source)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) - return status; - - status = surface->backend->mask (surface, op, source, mask, clip); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - surface->is_clear = FALSE; - surface->serial++; - } - - return _cairo_surface_set_error (surface, status); -} - -cairo_status_t -_cairo_surface_fill_stroke (cairo_surface_t *surface, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - cairo_path_fixed_t *path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - if (surface->is_clear && - fill_op == CAIRO_OPERATOR_CLEAR && - stroke_op == CAIRO_OPERATOR_CLEAR) - { - return CAIRO_STATUS_SUCCESS; - } - - status = _pattern_has_error (fill_source); - if (unlikely (status)) - return status; - - status = _pattern_has_error (stroke_source); - if (unlikely (status)) - return status; - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) - return status; - - if (surface->backend->fill_stroke) { - cairo_matrix_t dev_ctm = *stroke_ctm; - cairo_matrix_t dev_ctm_inverse = *stroke_ctm_inverse; - - status = surface->backend->fill_stroke (surface, - fill_op, fill_source, fill_rule, - fill_tolerance, fill_antialias, - path, - stroke_op, stroke_source, - stroke_style, - &dev_ctm, &dev_ctm_inverse, - stroke_tolerance, stroke_antialias, - clip); - - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - goto FINISH; - } - - status = _cairo_surface_fill (surface, fill_op, fill_source, path, - fill_rule, fill_tolerance, fill_antialias, - clip); - if (unlikely (status)) - goto FINISH; - - status = _cairo_surface_stroke (surface, stroke_op, stroke_source, path, - stroke_style, stroke_ctm, stroke_ctm_inverse, - stroke_tolerance, stroke_antialias, - clip); - if (unlikely (status)) - goto FINISH; - - FINISH: - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - surface->is_clear = FALSE; - surface->serial++; - } - - return _cairo_surface_set_error (surface, status); -} - -cairo_status_t -_cairo_surface_stroke (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - status = _pattern_has_error (source); - if (unlikely (status)) - return status; - - if (nothing_to_do (surface, op, source)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) - return status; - - status = surface->backend->stroke (surface, op, source, - path, stroke_style, - ctm, ctm_inverse, - tolerance, antialias, - clip); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - surface->is_clear = FALSE; - surface->serial++; - } - - return _cairo_surface_set_error (surface, status); -} - -cairo_status_t -_cairo_surface_fill (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - status = _pattern_has_error (source); - if (unlikely (status)) - return status; - - if (nothing_to_do (surface, op, source)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) - return status; - - status = surface->backend->fill (surface, op, source, - path, fill_rule, - tolerance, antialias, - clip); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - surface->is_clear = FALSE; - surface->serial++; - } - - return _cairo_surface_set_error (surface, status); -} - -/** - * cairo_surface_copy_page: - * @surface: a #cairo_surface_t - * - * Emits the current page for backends that support multiple pages, - * but doesn't clear it, so that the contents of the current page will - * be retained for the next page. Use cairo_surface_show_page() if you - * want to get an empty page after the emission. - * - * There is a convenience function for this that takes a #cairo_t, - * namely cairo_copy_page(). - * - * Since: 1.6 - **/ -void -cairo_surface_copy_page (cairo_surface_t *surface) -{ - if (unlikely (surface->status)) - return; - - assert (surface->snapshot_of == NULL); - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); - return; - } - - /* It's fine if some backends don't implement copy_page */ - if (surface->backend->copy_page == NULL) - return; - - _cairo_surface_set_error (surface, surface->backend->copy_page (surface)); -} -slim_hidden_def (cairo_surface_copy_page); - -/** - * cairo_surface_show_page: - * @surface: a #cairo_Surface_t - * - * Emits and clears the current page for backends that support multiple - * pages. Use cairo_surface_copy_page() if you don't want to clear the page. - * - * There is a convenience function for this that takes a #cairo_t, - * namely cairo_show_page(). - * - * Since: 1.6 - **/ -void -cairo_surface_show_page (cairo_surface_t *surface) -{ - cairo_status_t status; - - if (unlikely (surface->status)) - return; - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); - return; - } - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) { - _cairo_surface_set_error (surface, status); - return; - } - - /* It's fine if some backends don't implement show_page */ - if (surface->backend->show_page == NULL) - return; - - _cairo_surface_set_error (surface, surface->backend->show_page (surface)); -} -slim_hidden_def (cairo_surface_show_page); - -/** - * _cairo_surface_get_extents: - * @surface: the #cairo_surface_t to fetch extents for - * - * This function returns a bounding box for the surface. The surface - * bounds are defined as a region beyond which no rendering will - * possibly be recorded, in other words, it is the maximum extent of - * potentially usable coordinates. - * - * For vector surfaces, (PDF, PS, SVG and recording-surfaces), the surface - * might be conceived as unbounded, but we force the user to provide a - * maximum size at the time of surface_create. So get_extents uses - * that size. - * - * Note: The coordinates returned are in "backend" space rather than - * "surface" space. That is, they are relative to the true (0,0) - * origin rather than the device_transform origin. This might seem a - * bit inconsistent with other #cairo_surface_t interfaces, but all - * current callers are within the surface layer where backend space is - * desired. - * - * This behavior would have to be changed is we ever exported a public - * variant of this function. - **/ -cairo_bool_t -_cairo_surface_get_extents (cairo_surface_t *surface, - cairo_rectangle_int_t *extents) -{ - cairo_bool_t bounded; - - if (unlikely (surface->status)) - goto zero_extents; - if (unlikely (surface->finished)) { - _cairo_surface_set_error(surface, CAIRO_STATUS_SURFACE_FINISHED); - goto zero_extents; - } - - bounded = FALSE; - if (surface->backend->get_extents != NULL) - bounded = surface->backend->get_extents (surface, extents); - - if (! bounded) - _cairo_unbounded_rectangle_init (extents); - - return bounded; - -zero_extents: - extents->x = extents->y = 0; - extents->width = extents->height = 0; - return TRUE; -} - -/** - * cairo_surface_has_show_text_glyphs: - * @surface: a #cairo_surface_t - * - * Returns whether the surface supports - * sophisticated cairo_show_text_glyphs() operations. That is, - * whether it actually uses the provided text and cluster data - * to a cairo_show_text_glyphs() call. - * - * Note: Even if this function returns %FALSE, a - * cairo_show_text_glyphs() operation targeted at @surface will - * still succeed. It just will - * act like a cairo_show_glyphs() operation. Users can use this - * function to avoid computing UTF-8 text and cluster mapping if the - * target surface does not use it. - * - * Return value: %TRUE if @surface supports - * cairo_show_text_glyphs(), %FALSE otherwise - * - * Since: 1.8 - **/ -cairo_bool_t -cairo_surface_has_show_text_glyphs (cairo_surface_t *surface) -{ - if (unlikely (surface->status)) - return FALSE; - - if (unlikely (surface->finished)) { - _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); - return FALSE; - } - - if (surface->backend->has_show_text_glyphs) - return surface->backend->has_show_text_glyphs (surface); - else - return surface->backend->show_text_glyphs != NULL; -} -slim_hidden_def (cairo_surface_has_show_text_glyphs); - -/* Note: the backends may modify the contents of the glyph array as long as - * they do not return %CAIRO_INT_STATUS_UNSUPPORTED. This makes it possible to - * avoid copying the array again and again, and edit it in-place. - * Backends are in fact free to use the array as a generic buffer as they - * see fit. - * - * For show_glyphs backend method, and NOT for show_text_glyphs method, - * when they do return UNSUPPORTED, they may adjust remaining_glyphs to notify - * that they have successfully rendered some of the glyphs (from the beginning - * of the array), but not all. If they don't touch remaining_glyphs, it - * defaults to all glyphs. - * - * See commits 5a9642c5746fd677aed35ce620ce90b1029b1a0c and - * 1781e6018c17909311295a9cc74b70500c6b4d0a for the rationale. - */ -cairo_status_t -_cairo_surface_show_text_glyphs (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - if (unlikely (surface->status)) - return surface->status; - if (unlikely (surface->finished)) - return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (num_glyphs == 0 && utf8_len == 0) - return CAIRO_STATUS_SUCCESS; - - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_STATUS_SUCCESS; - - status = _pattern_has_error (source); - if (unlikely (status)) - return status; - - if (nothing_to_do (surface, op, source)) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_begin_modification (surface); - if (unlikely (status)) - return status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - - /* The logic here is duplicated in _cairo_analysis_surface show_glyphs and - * show_text_glyphs. Keep in synch. */ - if (clusters) { - /* A real show_text_glyphs call. Try show_text_glyphs backend - * method first */ - if (surface->backend->show_text_glyphs != NULL) { - status = surface->backend->show_text_glyphs (surface, op, - source, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, cluster_flags, - scaled_font, - clip); - } - if (status == CAIRO_INT_STATUS_UNSUPPORTED && - surface->backend->show_glyphs) - { - status = surface->backend->show_glyphs (surface, op, - source, - glyphs, num_glyphs, - scaled_font, - clip); - } - } else { - /* A mere show_glyphs call. Try show_glyphs backend method first */ - if (surface->backend->show_glyphs != NULL) { - status = surface->backend->show_glyphs (surface, op, - source, - glyphs, num_glyphs, - scaled_font, - clip); - } else if (surface->backend->show_text_glyphs != NULL) { - /* Intentionally only try show_text_glyphs method for show_glyphs - * calls if backend does not have show_glyphs. If backend has - * both methods implemented, we don't fallback from show_glyphs to - * show_text_glyphs, and hence the backend can assume in its - * show_text_glyphs call that clusters is not NULL (which also - * implies that UTF-8 is not NULL, unless the text is - * zero-length). - */ - status = surface->backend->show_text_glyphs (surface, op, - source, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, cluster_flags, - scaled_font, - clip); - } - } - - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - surface->is_clear = FALSE; - surface->serial++; - } - - return _cairo_surface_set_error (surface, status); -} - -/** - * _cairo_surface_set_resolution: - * @surface: the surface - * @x_res: x resolution, in dpi - * @y_res: y resolution, in dpi - * - * Set the actual surface resolution of @surface to the given x and y DPI. - * Mainly used for correctly computing the scale factor when fallback - * rendering needs to take place in the paginated surface. - **/ -void -_cairo_surface_set_resolution (cairo_surface_t *surface, - double x_res, - double y_res) -{ - if (surface->status) - return; - - surface->x_resolution = x_res; - surface->y_resolution = y_res; -} - -/** - * _cairo_surface_create_in_error: - * @status: the error status - * - * Return an appropriate static error surface for the error status. - * On error, surface creation functions should always return a surface - * created with _cairo_surface_create_in_error() instead of a new surface - * in an error state. This simplifies internal code as no refcounting has - * to be done. - **/ -cairo_surface_t * -_cairo_surface_create_in_error (cairo_status_t status) -{ - assert (status < CAIRO_STATUS_LAST_STATUS); - switch (status) { - case CAIRO_STATUS_NO_MEMORY: - return (cairo_surface_t *) &_cairo_surface_nil; - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - return (cairo_surface_t *) &_cairo_surface_nil_surface_type_mismatch; - case CAIRO_STATUS_INVALID_STATUS: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_status; - case CAIRO_STATUS_INVALID_CONTENT: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_content; - case CAIRO_STATUS_INVALID_FORMAT: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_format; - case CAIRO_STATUS_INVALID_VISUAL: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_visual; - case CAIRO_STATUS_READ_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_read_error; - case CAIRO_STATUS_WRITE_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_write_error; - case CAIRO_STATUS_FILE_NOT_FOUND: - return (cairo_surface_t *) &_cairo_surface_nil_file_not_found; - case CAIRO_STATUS_TEMP_FILE_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_temp_file_error; - case CAIRO_STATUS_INVALID_STRIDE: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_stride; - case CAIRO_STATUS_INVALID_SIZE: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_size; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - return (cairo_surface_t *) &_cairo_surface_nil_device_type_mismatch; - case CAIRO_STATUS_DEVICE_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_device_error; - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - /* fall-through */ - case CAIRO_STATUS_INVALID_RESTORE: - case CAIRO_STATUS_INVALID_POP_GROUP: - case CAIRO_STATUS_NO_CURRENT_POINT: - case CAIRO_STATUS_INVALID_MATRIX: - case CAIRO_STATUS_NULL_POINTER: - case CAIRO_STATUS_INVALID_STRING: - case CAIRO_STATUS_INVALID_PATH_DATA: - case CAIRO_STATUS_SURFACE_FINISHED: - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_DASH: - case CAIRO_STATUS_INVALID_DSC_COMMENT: - case CAIRO_STATUS_INVALID_INDEX: - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: - case CAIRO_STATUS_FONT_TYPE_MISMATCH: - case CAIRO_STATUS_USER_FONT_IMMUTABLE: - case CAIRO_STATUS_USER_FONT_ERROR: - case CAIRO_STATUS_NEGATIVE_COUNT: - case CAIRO_STATUS_INVALID_CLUSTERS: - case CAIRO_STATUS_INVALID_SLANT: - case CAIRO_STATUS_INVALID_WEIGHT: - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: - case CAIRO_STATUS_DEVICE_FINISHED: - case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: - default: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; - } -} - -cairo_surface_t * -_cairo_int_surface_create_in_error (cairo_int_status_t status) -{ - if (status < CAIRO_INT_STATUS_LAST_STATUS) - return _cairo_surface_create_in_error (status); - - switch ((int)status) { - case CAIRO_INT_STATUS_UNSUPPORTED: - return (cairo_surface_t *) &_cairo_surface_nil_unsupported; - case CAIRO_INT_STATUS_NOTHING_TO_DO: - return (cairo_surface_t *) &_cairo_surface_nil_nothing_to_do; - default: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; - } -} - -/* LocalWords: rasterized - */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface-private.h deleted file mode 100644 index ddbf464b1d2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface-private.h +++ /dev/null @@ -1,74 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * Copyright © 2005-2006 Emmanuel Pacaud - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Emmanuel Pacaud - * Carl Worth - */ - -#ifndef CAIRO_SVG_SURFACE_PRIVATE_H -#define CAIRO_SVG_SURFACE_PRIVATE_H - -#include "cairo-svg.h" - -#include "cairo-surface-private.h" -#include "cairo-surface-clipper-private.h" - -typedef struct cairo_svg_document cairo_svg_document_t; - -typedef struct cairo_svg_surface { - cairo_surface_t base; - - cairo_content_t content; - - double width; - double height; - - cairo_svg_document_t *document; - - cairo_output_stream_t *xml_node; - cairo_array_t page_set; - - cairo_surface_clipper_t clipper; - unsigned int clip_level; - unsigned int base_clip; - cairo_bool_t is_base_clip_emitted; - - cairo_paginated_mode_t paginated_mode; - - cairo_bool_t force_fallbacks; -} cairo_svg_surface_t; - -#endif /* CAIRO_SVG_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface.c deleted file mode 100644 index 372ef45b86e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg-surface.c +++ /dev/null @@ -1,2884 +0,0 @@ -/* vim: set sw=4 sts=4: -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * Copyright © 2005-2007 Emmanuel Pacaud - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Kristian Høgsberg - * Emmanuel Pacaud - * Carl Worth - */ - -#define _BSD_SOURCE /* for snprintf() */ -#include "cairoint.h" - -#include "cairo-svg.h" - -#include "cairo-array-private.h" -#include "cairo-analysis-surface-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-info-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-output-stream-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-paginated-private.h" -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-svg-surface-private.h" - -/** - * SECTION:cairo-svg - * @Title: SVG Surfaces - * @Short_Description: Rendering SVG documents - * @See_Also: #cairo_surface_t - * - * The SVG surface is used to render cairo graphics to - * SVG files and is a multi-page vector surface backend. - **/ - -/** - * CAIRO_HAS_SVG_SURFACE: - * - * Defined if the SVG surface backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.2 - **/ - -typedef struct cairo_svg_page cairo_svg_page_t; - -static const int invalid_pattern_id = -1; - -static const cairo_svg_version_t _cairo_svg_versions[] = -{ - CAIRO_SVG_VERSION_1_1, - CAIRO_SVG_VERSION_1_2 -}; - -#define CAIRO_SVG_VERSION_LAST ARRAY_LENGTH (_cairo_svg_versions) - -static const char *_cairo_svg_supported_mime_types[] = -{ - CAIRO_MIME_TYPE_JPEG, - CAIRO_MIME_TYPE_PNG, - CAIRO_MIME_TYPE_URI, - NULL -}; - -static void -_cairo_svg_surface_emit_path (cairo_output_stream_t *output, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm_inverse); - -static cairo_bool_t -_cairo_svg_version_has_page_set_support (cairo_svg_version_t version) -{ - return version > CAIRO_SVG_VERSION_1_1; -} - -static const char * _cairo_svg_version_strings[CAIRO_SVG_VERSION_LAST] = -{ - "SVG 1.1", - "SVG 1.2" -}; - -static const char * _cairo_svg_internal_version_strings[CAIRO_SVG_VERSION_LAST] = -{ - "1.1", - "1.2" -}; - -struct cairo_svg_page { - unsigned int surface_id; - unsigned int clip_level; - cairo_output_stream_t *xml_node; -}; - -struct cairo_svg_document { - cairo_output_stream_t *output_stream; - unsigned long refcount; - cairo_surface_t *owner; - cairo_bool_t finished; - - double width; - double height; - - cairo_output_stream_t *xml_node_defs; - cairo_output_stream_t *xml_node_glyphs; - - unsigned int linear_pattern_id; - unsigned int radial_pattern_id; - unsigned int pattern_id; - unsigned int filter_id; - unsigned int clip_id; - unsigned int mask_id; - - cairo_bool_t alpha_filter; - - cairo_svg_version_t svg_version; - - cairo_scaled_font_subsets_t *font_subsets; -}; - -static cairo_status_t -_cairo_svg_document_create (cairo_output_stream_t *stream, - double width, - double height, - cairo_svg_version_t version, - cairo_svg_document_t **document_out); - -static cairo_status_t -_cairo_svg_document_destroy (cairo_svg_document_t *document); - -static cairo_status_t -_cairo_svg_document_finish (cairo_svg_document_t *document); - -static cairo_svg_document_t * -_cairo_svg_document_reference (cairo_svg_document_t *document); - -static unsigned int -_cairo_svg_document_allocate_mask_id (cairo_svg_document_t *document); - -static cairo_surface_t * -_cairo_svg_surface_create_for_document (cairo_svg_document_t *document, - cairo_content_t content, - double width, - double height); -static cairo_surface_t * -_cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t *stream, - double width, - double height, - cairo_svg_version_t version); - -static const cairo_surface_backend_t cairo_svg_surface_backend; -static const cairo_paginated_surface_backend_t cairo_svg_surface_paginated_backend; - -/** - * cairo_svg_surface_create_for_stream: - * @write_func: a #cairo_write_func_t to accept the output data, may be %NULL - * to indicate a no-op @write_func. With a no-op @write_func, - * the surface may be queried or used as a source without - * generating any temporary files. - * @closure: the closure argument for @write_func - * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) - * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) - * - * Creates a SVG surface of the specified size in points to be written - * incrementally to the stream represented by @write_func and @closure. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, - void *closure, - double width, - double height) -{ - cairo_output_stream_t *stream; - - stream = _cairo_output_stream_create (write_func, NULL, closure); - if (_cairo_output_stream_get_status (stream)) - return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); - - return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1); -} - -/** - * cairo_svg_surface_create: - * @filename: a filename for the SVG output (must be writable), %NULL may be - * used to specify no output. This will generate a SVG surface that - * may be queried and used as a source, without generating a - * temporary file. - * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) - * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) - * - * Creates a SVG surface of the specified size in points to be written - * to @filename. - * - * The SVG surface backend recognizes the following MIME types for the - * data attached to a surface (see cairo_surface_set_mime_data()) when - * it is used as a source pattern for drawing on this surface: - * %CAIRO_MIME_TYPE_JPEG, %CAIRO_MIME_TYPE_PNG, - * %CAIRO_MIME_TYPE_URI. If any of them is specified, the SVG backend - * emits a href with the content of MIME data instead of a surface - * snapshot (PNG, Base64-encoded) in the corresponding image tag. - * - * The unofficial MIME type %CAIRO_MIME_TYPE_URI is examined - * first. If present, the URI is emitted as is: assuring the - * correctness of URI is left to the client code. - * - * If %CAIRO_MIME_TYPE_URI is not present, but %CAIRO_MIME_TYPE_JPEG - * or %CAIRO_MIME_TYPE_PNG is specified, the corresponding data is - * Base64-encoded and emitted. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_svg_surface_create (const char *filename, - double width, - double height) -{ - cairo_output_stream_t *stream; - - stream = _cairo_output_stream_create_for_filename (filename); - if (_cairo_output_stream_get_status (stream)) - return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); - - return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1); -} - -static cairo_bool_t -_cairo_surface_is_svg (cairo_surface_t *surface) -{ - return surface->backend == &cairo_svg_surface_backend; -} - -/* If the abstract_surface is a paginated surface, and that paginated - * surface's target is a svg_surface, then set svg_surface to that - * target. Otherwise return FALSE. - */ -static cairo_bool_t -_extract_svg_surface (cairo_surface_t *surface, - cairo_svg_surface_t **svg_surface) -{ - cairo_surface_t *target; - cairo_status_t status_ignored; - - if (surface->status) - return FALSE; - if (surface->finished) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (! _cairo_surface_is_paginated (surface)) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return FALSE; - } - - target = _cairo_paginated_surface_get_target (surface); - if (target->status) { - status_ignored = _cairo_surface_set_error (surface, - target->status); - return FALSE; - } - if (target->finished) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return FALSE; - } - - if (! _cairo_surface_is_svg (target)) { - status_ignored = _cairo_surface_set_error (surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return FALSE; - } - - *svg_surface = (cairo_svg_surface_t *) target; - return TRUE; -} - -/** - * cairo_svg_surface_restrict_to_version: - * @surface: a SVG #cairo_surface_t - * @version: SVG version - * - * Restricts the generated SVG file to @version. See cairo_svg_get_versions() - * for a list of available version values that can be used here. - * - * This function should only be called before any drawing operations - * have been performed on the given surface. The simplest way to do - * this is to call this function immediately after creating the - * surface. - * - * Since: 1.2 - **/ -void -cairo_svg_surface_restrict_to_version (cairo_surface_t *abstract_surface, - cairo_svg_version_t version) -{ - cairo_svg_surface_t *surface = NULL; /* hide compiler warning */ - - if (! _extract_svg_surface (abstract_surface, &surface)) - return; - - if (version < CAIRO_SVG_VERSION_LAST) - surface->document->svg_version = version; -} - -/** - * cairo_svg_get_versions: - * @versions: supported version list - * @num_versions: list length - * - * Used to retrieve the list of supported versions. See - * cairo_svg_surface_restrict_to_version(). - * - * Since: 1.2 - **/ -void -cairo_svg_get_versions (cairo_svg_version_t const **versions, - int *num_versions) -{ - if (versions != NULL) - *versions = _cairo_svg_versions; - - if (num_versions != NULL) - *num_versions = CAIRO_SVG_VERSION_LAST; -} - -/** - * cairo_svg_version_to_string: - * @version: a version id - * - * Get the string representation of the given @version id. This function - * will return %NULL if @version isn't valid. See cairo_svg_get_versions() - * for a way to get the list of valid version ids. - * - * Return value: the string associated to given version. - * - * Since: 1.2 - **/ -const char * -cairo_svg_version_to_string (cairo_svg_version_t version) -{ - if (version >= CAIRO_SVG_VERSION_LAST) - return NULL; - - return _cairo_svg_version_strings[version]; -} - -static cairo_bool_t -_cliprect_covers_surface (cairo_svg_surface_t *surface, - cairo_path_fixed_t *path) -{ - cairo_box_t box; - - if (_cairo_path_fixed_is_box (path, &box)) { - if (box.p1.x <= 0 && - box.p1.y <= 0 && - _cairo_fixed_to_double (box.p2.x) >= surface->width && - _cairo_fixed_to_double (box.p2.y) >= surface->height) - { - return TRUE; - } - } - - return FALSE; -} - -static cairo_status_t -_cairo_svg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_svg_surface_t *surface = cairo_container_of (clipper, - cairo_svg_surface_t, - clipper); - cairo_svg_document_t *document = surface->document; - unsigned int i; - - if (path == NULL) { - for (i = 0; i < surface->clip_level; i++) - _cairo_output_stream_printf (surface->xml_node, "\n"); - - surface->clip_level = 0; - return CAIRO_STATUS_SUCCESS; - } - - /* skip trivial whole-page clips */ - if (_cliprect_covers_surface (surface, path)) - return CAIRO_STATUS_SUCCESS; - - _cairo_output_stream_printf (document->xml_node_defs, - "\n" - " clip_id); - _cairo_svg_surface_emit_path (document->xml_node_defs, path, NULL); - - _cairo_output_stream_printf (document->xml_node_defs, - "/>\n" - "\n"); - - _cairo_output_stream_printf (surface->xml_node, - "\n", - document->clip_id, - fill_rule == CAIRO_FILL_RULE_EVEN_ODD ? - "evenodd" : "nonzero"); - - document->clip_id++; - surface->clip_level++; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_svg_surface_create_for_document (cairo_svg_document_t *document, - cairo_content_t content, - double width, - double height) -{ - cairo_svg_surface_t *surface; - cairo_surface_t *paginated; - cairo_status_t status, status_ignored; - - surface = malloc (sizeof (cairo_svg_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &cairo_svg_surface_backend, - NULL, /* device */ - content); - - surface->width = width; - surface->height = height; - - surface->document = _cairo_svg_document_reference (document); - - surface->clip_level = 0; - _cairo_surface_clipper_init (&surface->clipper, - _cairo_svg_surface_clipper_intersect_clip_path); - - surface->base_clip = document->clip_id++; - surface->is_base_clip_emitted = FALSE; - - surface->xml_node = _cairo_memory_stream_create (); - status = _cairo_output_stream_get_status (surface->xml_node); - if (unlikely (status)) - goto CLEANUP; - - _cairo_array_init (&surface->page_set, sizeof (cairo_svg_page_t)); - - if (content == CAIRO_CONTENT_COLOR) { - _cairo_output_stream_printf (surface->xml_node, - "\n", - width, height); - status = _cairo_output_stream_get_status (surface->xml_node); - if (unlikely (status)) - goto CLEANUP; - } - - surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE; - surface->force_fallbacks = FALSE; - surface->content = content; - - paginated = _cairo_paginated_surface_create (&surface->base, - surface->content, - &cairo_svg_surface_paginated_backend); - status = paginated->status; - if (status == CAIRO_STATUS_SUCCESS) { - /* paginated keeps the only reference to surface now, drop ours */ - cairo_surface_destroy (&surface->base); - return paginated; - } - - /* ignore status as we are on the error path */ -CLEANUP: - status_ignored = _cairo_output_stream_destroy (surface->xml_node); - status_ignored = _cairo_svg_document_destroy (document); - - free (surface); - - return _cairo_surface_create_in_error (status); -} - -static cairo_surface_t * -_cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t *stream, - double width, - double height, - cairo_svg_version_t version) -{ - cairo_svg_document_t *document = NULL; /* silence compiler */ - cairo_surface_t *surface; - cairo_status_t status; - - status = _cairo_svg_document_create (stream, - width, height, version, - &document); - if (unlikely (status)) { - surface = _cairo_surface_create_in_error (status); - /* consume the output stream on behalf of caller */ - status = _cairo_output_stream_destroy (stream); - return surface; - } - - surface = _cairo_svg_surface_create_for_document (document, CAIRO_CONTENT_COLOR_ALPHA, - width, height); - if (surface->status) { - status = _cairo_svg_document_destroy (document); - return surface; - } - - document->owner = surface; - status = _cairo_svg_document_destroy (document); - /* the ref count should be 2 at this point */ - assert (status == CAIRO_STATUS_SUCCESS); - - return surface; -} - -static cairo_svg_page_t * -_cairo_svg_surface_store_page (cairo_svg_surface_t *surface) -{ - cairo_svg_page_t page; - cairo_output_stream_t *stream; - cairo_int_status_t status; - unsigned int i; - - stream = _cairo_memory_stream_create (); - if (_cairo_output_stream_get_status (stream)) { - status = _cairo_output_stream_destroy (stream); - return NULL; - } - - page.surface_id = surface->base.unique_id; - page.clip_level = surface->clip_level; - page.xml_node = surface->xml_node; - - if (_cairo_array_append (&surface->page_set, &page)) { - status = _cairo_output_stream_destroy (stream); - return NULL; - } - - surface->xml_node = stream; - surface->clip_level = 0; - for (i = 0; i < page.clip_level; i++) - _cairo_output_stream_printf (page.xml_node, "\n"); - - _cairo_surface_clipper_reset (&surface->clipper); - - return _cairo_array_index (&surface->page_set, - surface->page_set.num_elements - 1); -} - -static cairo_int_status_t -_cairo_svg_surface_copy_page (void *abstract_surface) -{ - cairo_svg_surface_t *surface = abstract_surface; - cairo_svg_page_t *page; - - page = _cairo_svg_surface_store_page (surface); - if (unlikely (page == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_memory_stream_copy (page->xml_node, surface->xml_node); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_show_page (void *abstract_surface) -{ - cairo_svg_surface_t *surface = abstract_surface; - - if (unlikely (_cairo_svg_surface_store_page (surface) == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_svg_surface_emit_transform (cairo_output_stream_t *output, - char const *attribute_str, - const cairo_matrix_t *object_matrix, - const cairo_matrix_t *parent_matrix) -{ - cairo_matrix_t matrix = *object_matrix; - - if (parent_matrix != NULL) - cairo_matrix_multiply (&matrix, &matrix, parent_matrix); - - if (!_cairo_matrix_is_identity (&matrix)) - _cairo_output_stream_printf (output, - "%s=\"matrix(%f,%f,%f,%f,%f,%f)\"", - attribute_str, - matrix.xx, matrix.yx, - matrix.xy, matrix.yy, - matrix.x0, matrix.y0); -} - -typedef struct { - cairo_output_stream_t *output; - const cairo_matrix_t *ctm_inverse; -} svg_path_info_t; - -static cairo_status_t -_cairo_svg_path_move_to (void *closure, - const cairo_point_t *point) -{ - svg_path_info_t *info = closure; - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (info->ctm_inverse) - cairo_matrix_transform_point (info->ctm_inverse, &x, &y); - - _cairo_output_stream_printf (info->output, "M %f %f ", x, y); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_path_line_to (void *closure, - const cairo_point_t *point) -{ - svg_path_info_t *info = closure; - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (info->ctm_inverse) - cairo_matrix_transform_point (info->ctm_inverse, &x, &y); - - _cairo_output_stream_printf (info->output, "L %f %f ", x, y); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_path_curve_to (void *closure, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d) -{ - svg_path_info_t *info = closure; - double bx = _cairo_fixed_to_double (b->x); - double by = _cairo_fixed_to_double (b->y); - double cx = _cairo_fixed_to_double (c->x); - double cy = _cairo_fixed_to_double (c->y); - double dx = _cairo_fixed_to_double (d->x); - double dy = _cairo_fixed_to_double (d->y); - - if (info->ctm_inverse) { - cairo_matrix_transform_point (info->ctm_inverse, &bx, &by); - cairo_matrix_transform_point (info->ctm_inverse, &cx, &cy); - cairo_matrix_transform_point (info->ctm_inverse, &dx, &dy); - } - - _cairo_output_stream_printf (info->output, - "C %f %f %f %f %f %f ", - bx, by, cx, cy, dx, dy); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_path_close_path (void *closure) -{ - svg_path_info_t *info = closure; - - _cairo_output_stream_printf (info->output, "Z "); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_svg_surface_emit_path (cairo_output_stream_t *output, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm_inverse) -{ - cairo_status_t status; - svg_path_info_t info; - - _cairo_output_stream_printf (output, "d=\""); - - info.output = output; - info.ctm_inverse = ctm_inverse; - status = _cairo_path_fixed_interpret (path, - _cairo_svg_path_move_to, - _cairo_svg_path_line_to, - _cairo_svg_path_curve_to, - _cairo_svg_path_close_path, - &info); - assert (status == CAIRO_STATUS_SUCCESS); - - _cairo_output_stream_printf (output, "\""); -} - -static cairo_int_status_t -_cairo_svg_document_emit_outline_glyph_data (cairo_svg_document_t *document, - cairo_scaled_font_t *scaled_font, - unsigned long glyph_index) -{ - cairo_scaled_glyph_t *scaled_glyph; - cairo_int_status_t status; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS| - CAIRO_SCALED_GLYPH_INFO_PATH, - &scaled_glyph); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (document->xml_node_glyphs, - "xml_node_glyphs, - scaled_glyph->path, NULL); - - _cairo_output_stream_printf (document->xml_node_glyphs, - "/>\n"); - - return status; -} - -static cairo_int_status_t -_cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t *document, - cairo_scaled_font_t *scaled_font, - unsigned long glyph_index) -{ - cairo_scaled_glyph_t *scaled_glyph; - cairo_image_surface_t *image; - cairo_status_t status; - uint8_t *row, *byte; - int rows, cols; - int x, y, bit; - - status = _cairo_scaled_glyph_lookup (scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS | - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - if (unlikely (status)) - return status; - - image = _cairo_image_surface_coerce_to_format (scaled_glyph->surface, - CAIRO_FORMAT_A1); - status = image->base.status; - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (document->xml_node_glyphs, "xml_node_glyphs, " transform", - &image->base.device_transform_inverse, NULL); - _cairo_output_stream_printf (document->xml_node_glyphs, ">\n"); - - for (y = 0, row = image->data, rows = image->height; rows; row += image->stride, rows--, y++) { - for (x = 0, byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) { - uint8_t output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte); - for (bit = 7; bit >= 0 && x < image->width; bit--, x++) { - if (output_byte & (1 << bit)) { - _cairo_output_stream_printf (document->xml_node_glyphs, - "\n", - x, y); - } - } - } - } - _cairo_output_stream_printf (document->xml_node_glyphs, "\n"); - - cairo_surface_destroy (&image->base); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_document_emit_glyph (cairo_svg_document_t *document, - cairo_scaled_font_t *scaled_font, - unsigned long scaled_font_glyph_index, - unsigned int font_id, - unsigned int subset_glyph_index) -{ - cairo_int_status_t status; - - _cairo_output_stream_printf (document->xml_node_glyphs, - "\n", - font_id, - subset_glyph_index); - - status = _cairo_svg_document_emit_outline_glyph_data (document, - scaled_font, - scaled_font_glyph_index); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - status = _cairo_svg_document_emit_bitmap_glyph_data (document, - scaled_font, - scaled_font_glyph_index); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (document->xml_node_glyphs, "\n"); - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_document_emit_font_subset (cairo_scaled_font_subset_t *font_subset, - void *closure) -{ - cairo_svg_document_t *document = closure; - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - unsigned int i; - - _cairo_scaled_font_freeze_cache (font_subset->scaled_font); - for (i = 0; i < font_subset->num_glyphs; i++) { - status = _cairo_svg_document_emit_glyph (document, - font_subset->scaled_font, - font_subset->glyphs[i], - font_subset->font_id, i); - if (unlikely (status)) - break; - } - _cairo_scaled_font_thaw_cache (font_subset->scaled_font); - - return status; -} - -static cairo_status_t -_cairo_svg_document_emit_font_subsets (cairo_svg_document_t *document) -{ - cairo_status_t status; - - status = _cairo_scaled_font_subsets_foreach_scaled (document->font_subsets, - _cairo_svg_document_emit_font_subset, - document); - if (unlikely (status)) - goto FAIL; - - status = _cairo_scaled_font_subsets_foreach_user (document->font_subsets, - _cairo_svg_document_emit_font_subset, - document); - - FAIL: - _cairo_scaled_font_subsets_destroy (document->font_subsets); - document->font_subsets = NULL; - - return status; -} - -static char const * -_cairo_svg_surface_operators[] = { - "clear", - - "src", "src-over", "src-in", - "src-out", "src-atop", - - "dst", "dst-over", "dst-in", - "dst-out", "dst-atop", - - "xor", "plus", - "color-dodge", /* FIXME: saturate ? */ - - "multiply", "screen", "overlay", - "darken", "lighten", - "color-dodge", "color-burn", - "hard-light", "soft-light", - "difference", "exclusion" -}; - -static cairo_bool_t -_cairo_svg_surface_analyze_operator (cairo_svg_surface_t *surface, - cairo_operator_t op) -{ - /* guard against newly added operators */ - if (op >= ARRAY_LENGTH (_cairo_svg_surface_operators)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* allow operators being NULL if they are unsupported */ - if (_cairo_svg_surface_operators[op] == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_analyze_operation (cairo_svg_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern) -{ - cairo_svg_document_t *document = surface->document; - - if (surface->force_fallbacks && - surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (pattern->type == CAIRO_PATTERN_TYPE_MESH) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* SVG doesn't support extend reflect for image pattern */ - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE && - pattern->extend == CAIRO_EXTEND_REFLECT) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (document->svg_version >= CAIRO_SVG_VERSION_1_2) - return _cairo_svg_surface_analyze_operator (surface, op); - - if (op == CAIRO_OPERATOR_OVER) - return CAIRO_STATUS_SUCCESS; - - /* The SOURCE operator is only supported if there is nothing - * painted underneath. */ - if (op == CAIRO_OPERATOR_SOURCE) - return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_int_status_t -_cairo_svg_surface_operation_supported (cairo_svg_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *pattern) -{ - return _cairo_svg_surface_analyze_operation (surface, op, pattern) != CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_status_t -_cairo_svg_surface_finish (void *abstract_surface) -{ - cairo_status_t status, status2; - cairo_svg_surface_t *surface = abstract_surface; - cairo_svg_document_t *document = surface->document; - cairo_svg_page_t *page; - unsigned int i; - - if (_cairo_paginated_surface_get_target (document->owner) == &surface->base) - status = _cairo_svg_document_finish (document); - else - status = CAIRO_STATUS_SUCCESS; - - if (surface->xml_node != NULL) { - status2 = _cairo_output_stream_destroy (surface->xml_node); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - } - - for (i = 0; i < surface->page_set.num_elements; i++) { - page = _cairo_array_index (&surface->page_set, i); - status2 = _cairo_output_stream_destroy (page->xml_node); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - } - _cairo_array_fini (&surface->page_set); - - _cairo_surface_clipper_reset (&surface->clipper); - - status2 = _cairo_svg_document_destroy (document); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - return status; -} - - -static void -_cairo_svg_surface_emit_alpha_filter (cairo_svg_document_t *document) -{ - if (document->alpha_filter) - return; - - _cairo_output_stream_printf (document->xml_node_defs, - "\n" - " \n" - "\n"); - - document->alpha_filter = TRUE; -} - -typedef struct { - cairo_output_stream_t *output; - unsigned int in_mem; - unsigned int trailing; - unsigned char src[3]; -} base64_write_closure_t; - -static char const base64_table[64] = -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -static cairo_status_t -base64_write_func (void *closure, - const unsigned char *data, - unsigned int length) -{ - base64_write_closure_t *info = (base64_write_closure_t *) closure; - unsigned int i; - unsigned char *src; - - src = info->src; - - if (info->in_mem + length < 3) { - for (i = 0; i < length; i++) { - src[i + info->in_mem] = *data++; - } - info->in_mem += length; - return CAIRO_STATUS_SUCCESS; - } - - do { - unsigned char dst[4]; - - for (i = info->in_mem; i < 3; i++) { - src[i] = *data++; - length--; - } - info->in_mem = 0; - - dst[0] = base64_table[src[0] >> 2]; - dst[1] = base64_table[(src[0] & 0x03) << 4 | src[1] >> 4]; - dst[2] = base64_table[(src[1] & 0x0f) << 2 | src[2] >> 6]; - dst[3] = base64_table[src[2] & 0xfc >> 2]; - /* Special case for the last missing bits */ - switch (info->trailing) { - case 2: - dst[2] = '='; - case 1: - dst[3] = '='; - default: - break; - } - _cairo_output_stream_write (info->output, dst, 4); - } while (length >= 3); - - for (i = 0; i < length; i++) { - src[i] = *data++; - } - info->in_mem = length; - - return _cairo_output_stream_get_status (info->output); -} - -static cairo_int_status_t -_cairo_surface_base64_encode_jpeg (cairo_surface_t *surface, - cairo_output_stream_t *output) -{ - const unsigned char *mime_data; - unsigned long mime_data_length; - cairo_image_info_t image_info; - base64_write_closure_t info; - cairo_status_t status; - - cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_JPEG, - &mime_data, &mime_data_length); - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_image_info_get_jpeg_info (&image_info, mime_data, mime_data_length); - if (unlikely (status)) - return status; - - if (image_info.num_components == 4) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_output_stream_printf (output, "data:image/jpeg;base64,"); - - info.output = output; - info.in_mem = 0; - info.trailing = 0; - - status = base64_write_func (&info, mime_data, mime_data_length); - if (unlikely (status)) - return status; - - if (info.in_mem > 0) { - memset (info.src + info.in_mem, 0, 3 - info.in_mem); - info.trailing = 3 - info.in_mem; - info.in_mem = 3; - status = base64_write_func (&info, NULL, 0); - } - - return status; -} - -static cairo_int_status_t -_cairo_surface_base64_encode_png (cairo_surface_t *surface, - cairo_output_stream_t *output) -{ - const unsigned char *mime_data; - unsigned long mime_data_length; - base64_write_closure_t info; - cairo_status_t status; - - cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_PNG, - &mime_data, &mime_data_length); - if (unlikely (surface->status)) - return surface->status; - if (mime_data == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_output_stream_printf (output, "data:image/png;base64,"); - - info.output = output; - info.in_mem = 0; - info.trailing = 0; - - status = base64_write_func (&info, mime_data, mime_data_length); - if (unlikely (status)) - return status; - - if (info.in_mem > 0) { - memset (info.src + info.in_mem, 0, 3 - info.in_mem); - info.trailing = 3 - info.in_mem; - info.in_mem = 3; - status = base64_write_func (&info, NULL, 0); - } - - return status; -} - -static cairo_int_status_t -_cairo_surface_base64_encode (cairo_surface_t *surface, - cairo_output_stream_t *output) -{ - cairo_int_status_t status; - base64_write_closure_t info; - - status = _cairo_surface_base64_encode_jpeg (surface, output); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - status = _cairo_surface_base64_encode_png (surface, output); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - info.output = output; - info.in_mem = 0; - info.trailing = 0; - - _cairo_output_stream_printf (info.output, "data:image/png;base64,"); - - status = cairo_surface_write_to_png_stream (surface, base64_write_func, - (void *) &info); - - if (unlikely (status)) - return status; - - if (info.in_mem > 0) { - memset (info.src + info.in_mem, 0, 3 - info.in_mem); - info.trailing = 3 - info.in_mem; - info.in_mem = 3; - status = base64_write_func (&info, NULL, 0); - } - - return status; -} - -static void -_cairo_svg_surface_emit_operator (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op) -{ - if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2 && - op != CAIRO_OPERATOR_OVER) { - _cairo_output_stream_printf (output, " comp-op=\"%s\"", _cairo_svg_surface_operators[op]); - if (!_cairo_operator_bounded_by_source (op)) - _cairo_output_stream_printf (output, " clip-to-self=\"true\""); - } -} - -static void -_cairo_svg_surface_emit_operator_for_style (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op) -{ - if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2 && - op != CAIRO_OPERATOR_OVER) { - _cairo_output_stream_printf (output, "comp-op:%s;", _cairo_svg_surface_operators[op]); - if (!_cairo_operator_bounded_by_source (op)) - _cairo_output_stream_printf (output, "clip-to-self:true;"); - } -} - -/** - * _cairo_svg_surface_emit_attr_value: - * - * Write the value to output the stream as a sequence of characters, - * while escaping those which have special meaning in the XML - * attribute's value context: & and ". - **/ -static void -_cairo_svg_surface_emit_attr_value (cairo_output_stream_t *stream, - const unsigned char *value, - unsigned int length) -{ - const unsigned char *p; - const unsigned char *q; - unsigned int i; - - /* we'll accumulate non-special chars in [q, p) range */ - p = value; - q = p; - for (i = 0; i < length; i++, p++) { - if (*p == '&' || *p == '"') { - /* flush what's left before special char */ - if (p != q) { - _cairo_output_stream_write (stream, q, p - q); - q = p + 1; - } - - if (*p == '&') - _cairo_output_stream_printf (stream, "&"); - else // p == '"' - _cairo_output_stream_printf (stream, """); - } - } - - /* flush the trailing chars if any */ - if (p != q) - _cairo_output_stream_write (stream, q, p - q); -} - -static cairo_status_t -_cairo_svg_surface_emit_surface (cairo_svg_document_t *document, - cairo_surface_t *surface) -{ - cairo_rectangle_int_t extents; - cairo_bool_t is_bounded; - cairo_status_t status; - const unsigned char *uri; - unsigned long uri_len; - - if (_cairo_user_data_array_get_data (&surface->user_data, - (cairo_user_data_key_t *) document)) - { - return CAIRO_STATUS_SUCCESS; - } - - is_bounded = _cairo_surface_get_extents (surface, &extents); - assert (is_bounded); - - _cairo_output_stream_printf (document->xml_node_defs, - "unique_id, - extents.width, extents.height); - - _cairo_output_stream_printf (document->xml_node_defs, " xlink:href=\""); - - cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_URI, - &uri, &uri_len); - if (uri != NULL) { - _cairo_svg_surface_emit_attr_value (document->xml_node_defs, - uri, uri_len); - } else { - status = _cairo_surface_base64_encode (surface, - document->xml_node_defs); - if (unlikely (status)) - return status; - } - - _cairo_output_stream_printf (document->xml_node_defs, "\"/>\n"); - - /* and tag it */ - return _cairo_user_data_array_set_data (&surface->user_data, - (cairo_user_data_key_t *) document, - document, NULL); -} - -static cairo_status_t -_cairo_svg_surface_emit_composite_surface_pattern (cairo_output_stream_t *output, - cairo_svg_surface_t *svg_surface, - cairo_operator_t op, - cairo_surface_pattern_t *pattern, - int pattern_id, - const cairo_matrix_t *parent_matrix, - const char *extra_attributes) -{ - cairo_status_t status; - cairo_matrix_t p2u; - - p2u = pattern->base.matrix; - status = cairo_matrix_invert (&p2u); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - status = _cairo_svg_surface_emit_surface (svg_surface->document, - pattern->surface); - if (unlikely (status)) - return status; - - if (pattern_id != invalid_pattern_id) { - cairo_rectangle_int_t extents; - cairo_bool_t is_bounded; - - is_bounded = _cairo_surface_get_extents (pattern->surface, &extents); - assert (is_bounded); - - _cairo_output_stream_printf (output, - "\n "); - } - - _cairo_output_stream_printf (output, - "surface->unique_id); - if (extra_attributes) - _cairo_output_stream_printf (output, " %s", extra_attributes); - - if (pattern_id == invalid_pattern_id) { - _cairo_svg_surface_emit_operator (output, svg_surface, op); - _cairo_svg_surface_emit_transform (output, - " transform", - &p2u, parent_matrix); - } - _cairo_output_stream_printf (output, "/>\n"); - - - if (pattern_id != invalid_pattern_id) - _cairo_output_stream_printf (output, "\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_surface_emit_recording_surface (cairo_svg_document_t *document, - cairo_recording_surface_t *source) -{ - cairo_status_t status; - cairo_surface_t *paginated_surface; - cairo_svg_surface_t *svg_surface; - cairo_array_t *page_set; - - cairo_output_stream_t *contents; - - if (_cairo_user_data_array_get_data (&source->base.user_data, - (cairo_user_data_key_t *) document)) - { - return CAIRO_STATUS_SUCCESS; - } - - paginated_surface = _cairo_svg_surface_create_for_document (document, - source->base.content, - source->extents_pixels.width, - source->extents_pixels.height); - if (unlikely (paginated_surface->status)) - return paginated_surface->status; - - svg_surface = (cairo_svg_surface_t *) - _cairo_paginated_surface_get_target (paginated_surface); - cairo_surface_set_fallback_resolution (paginated_surface, - document->owner->x_fallback_resolution, - document->owner->y_fallback_resolution); - cairo_surface_set_device_offset (&svg_surface->base, - -source->extents_pixels.x, - -source->extents_pixels.y); - - status = _cairo_recording_surface_replay (&source->base, paginated_surface); - if (unlikely (status)) { - cairo_surface_destroy (paginated_surface); - return status; - } - - cairo_surface_show_page (paginated_surface); - status = cairo_surface_status (paginated_surface); - if (unlikely (status)) { - cairo_surface_destroy (paginated_surface); - return status; - } - - if (! svg_surface->is_base_clip_emitted) { - svg_surface->is_base_clip_emitted = TRUE; - _cairo_output_stream_printf (document->xml_node_defs, - "\n" - " \n" - "\n", - svg_surface->base_clip, - svg_surface->width, - svg_surface->height); - } - - if (source->base.content == CAIRO_CONTENT_ALPHA) { - _cairo_svg_surface_emit_alpha_filter (document); - _cairo_output_stream_printf (document->xml_node_defs, - "\n", - source->base.unique_id, - svg_surface->base_clip); - } else { - _cairo_output_stream_printf (document->xml_node_defs, - "\n", - source->base.unique_id, - svg_surface->base_clip); - } - - contents = svg_surface->xml_node; - page_set = &svg_surface->page_set; - - if (_cairo_memory_stream_length (contents) > 0) { - if (unlikely (_cairo_svg_surface_store_page (svg_surface) == NULL)) { - cairo_surface_destroy (paginated_surface); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - if (page_set->num_elements > 0) { - cairo_svg_page_t *page; - - page = _cairo_array_index (page_set, page_set->num_elements - 1); - _cairo_memory_stream_copy (page->xml_node, document->xml_node_defs); - } - - _cairo_output_stream_printf (document->xml_node_defs, "\n"); - - status = cairo_surface_status (paginated_surface); - cairo_surface_destroy (paginated_surface); - - if (unlikely (status)) - return status; - - /* and tag it */ - return _cairo_user_data_array_set_data (&source->base.user_data, - (cairo_user_data_key_t *) document, - document, NULL); -} - -static cairo_recording_surface_t * -to_recording_surface (const cairo_surface_pattern_t *pattern) -{ - cairo_surface_t *surface = pattern->surface; - if (_cairo_surface_is_paginated (surface)) - surface = _cairo_paginated_surface_get_recording (surface); - if (_cairo_surface_is_snapshot (surface)) - surface = _cairo_surface_snapshot_get_target (surface); - return (cairo_recording_surface_t *) surface; -} - -static cairo_status_t -_cairo_svg_surface_emit_composite_recording_pattern (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op, - cairo_surface_pattern_t *pattern, - int pattern_id, - const cairo_matrix_t *parent_matrix, - const char *extra_attributes) -{ - cairo_svg_document_t *document = surface->document; - cairo_recording_surface_t *recording_surface; - cairo_matrix_t p2u; - cairo_status_t status; - - p2u = pattern->base.matrix; - status = cairo_matrix_invert (&p2u); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - recording_surface = to_recording_surface (pattern); - status = _cairo_svg_surface_emit_recording_surface (document, recording_surface); - if (unlikely (status)) - return status; - - if (pattern_id != invalid_pattern_id) { - _cairo_output_stream_printf (output, - "extents.width, - recording_surface->extents.height); - _cairo_svg_surface_emit_transform (output, " patternTransform", &p2u, parent_matrix); - _cairo_output_stream_printf (output, ">\n"); - } - - _cairo_output_stream_printf (output, - "base.unique_id); - - if (pattern_id == invalid_pattern_id) { - _cairo_svg_surface_emit_operator (output, surface, op); - _cairo_svg_surface_emit_transform (output, " transform", &p2u, parent_matrix); - } - - if (extra_attributes) - _cairo_output_stream_printf (output, " %s", extra_attributes); - - _cairo_output_stream_printf (output, "/>\n"); - - if (pattern_id != invalid_pattern_id) - _cairo_output_stream_printf (output, "\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_surface_emit_composite_pattern (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op, - cairo_surface_pattern_t *pattern, - int pattern_id, - const cairo_matrix_t *parent_matrix, - const char *extra_attributes) -{ - - if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { - return _cairo_svg_surface_emit_composite_recording_pattern (output, surface, - op, pattern, - pattern_id, - parent_matrix, - extra_attributes); - } - - return _cairo_svg_surface_emit_composite_surface_pattern (output, surface, - op, pattern, - pattern_id, - parent_matrix, - extra_attributes); -} - -static cairo_status_t -_cairo_svg_surface_emit_solid_pattern (cairo_svg_surface_t *surface, - cairo_solid_pattern_t *pattern, - cairo_output_stream_t *style, - cairo_bool_t is_stroke) -{ - _cairo_output_stream_printf (style, is_stroke ? - "stroke:rgb(%f%%,%f%%,%f%%);stroke-opacity:%f;": - "fill:rgb(%f%%,%f%%,%f%%);fill-opacity:%f;", - pattern->color.red * 100.0, - pattern->color.green * 100.0, - pattern->color.blue * 100.0, - pattern->color.alpha); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_surface_emit_surface_pattern (cairo_svg_surface_t *surface, - cairo_surface_pattern_t *pattern, - cairo_output_stream_t *style, - cairo_bool_t is_stroke, - const cairo_matrix_t *parent_matrix) -{ - cairo_svg_document_t *document = surface->document; - cairo_status_t status; - int pattern_id; - - pattern_id = document->pattern_id++; - status = _cairo_svg_surface_emit_composite_pattern (document->xml_node_defs, - surface, CAIRO_OPERATOR_SOURCE, pattern, - pattern_id, parent_matrix, NULL); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (style, - "%s:url(#pattern%d);", - is_stroke ? "stroke" : "fill", - pattern_id); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_surface_emit_pattern_stops (cairo_output_stream_t *output, - cairo_gradient_pattern_t const *pattern, - double start_offset, - cairo_bool_t reverse_stops, - cairo_bool_t emulate_reflect) -{ - cairo_gradient_stop_t *stops; - double offset; - unsigned int n_stops; - unsigned int i; - - if (pattern->n_stops < 1) - return CAIRO_STATUS_SUCCESS; - - if (pattern->n_stops == 1) { - _cairo_output_stream_printf (output, - "\n", - pattern->stops[0].offset, - pattern->stops[0].color.red * 100.0, - pattern->stops[0].color.green * 100.0, - pattern->stops[0].color.blue * 100.0, - pattern->stops[0].color.alpha); - return CAIRO_STATUS_SUCCESS; - } - - if (emulate_reflect || reverse_stops) { - n_stops = emulate_reflect ? pattern->n_stops * 2 - 2: pattern->n_stops; - stops = _cairo_malloc_ab (n_stops, sizeof (cairo_gradient_stop_t)); - if (unlikely (stops == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - for (i = 0; i < pattern->n_stops; i++) { - if (reverse_stops) { - stops[i] = pattern->stops[pattern->n_stops - i - 1]; - stops[i].offset = 1.0 - stops[i].offset; - } else - stops[i] = pattern->stops[i]; - if (emulate_reflect) { - stops[i].offset /= 2; - if (i > 0 && i < (pattern->n_stops - 1)) { - if (reverse_stops) { - stops[i + pattern->n_stops - 1] = pattern->stops[i]; - stops[i + pattern->n_stops - 1].offset = - 0.5 + 0.5 * stops[i + pattern->n_stops - 1].offset; - } else { - stops[i + pattern->n_stops - 1] = pattern->stops[pattern->n_stops - i - 1]; - stops[i + pattern->n_stops - 1].offset = - 1 - 0.5 * stops[i + pattern->n_stops - 1].offset; - } - } - } - } - } else { - n_stops = pattern->n_stops; - stops = pattern->stops; - } - - if (start_offset >= 0.0) - for (i = 0; i < n_stops; i++) { - offset = start_offset + (1 - start_offset ) * stops[i].offset; - _cairo_output_stream_printf (output, - "\n", - offset, - stops[i].color.red * 100.0, - stops[i].color.green * 100.0, - stops[i].color.blue * 100.0, - stops[i].color.alpha); - } - else { - cairo_bool_t found = FALSE; - unsigned int offset_index; - cairo_color_stop_t offset_color_start, offset_color_stop; - - for (i = 0; i < n_stops; i++) { - if (stops[i].offset >= -start_offset) { - if (i > 0) { - if (stops[i].offset != stops[i-1].offset) { - double x0, x1; - cairo_color_stop_t *color0, *color1; - - x0 = stops[i-1].offset; - x1 = stops[i].offset; - color0 = &stops[i-1].color; - color1 = &stops[i].color; - offset_color_start.red = color0->red + (color1->red - color0->red) - * (-start_offset - x0) / (x1 - x0); - offset_color_start.green = color0->green + (color1->green - color0->green) - * (-start_offset - x0) / (x1 - x0); - offset_color_start.blue = color0->blue + (color1->blue - color0->blue) - * (-start_offset - x0) / (x1 - x0); - offset_color_start.alpha = color0->alpha + (color1->alpha - color0->alpha) - * (-start_offset - x0) / (x1 - x0); - offset_color_stop = offset_color_start; - } else { - offset_color_stop = stops[i-1].color; - offset_color_start = stops[i].color; - } - } else - offset_color_stop = offset_color_start = stops[i].color; - offset_index = i; - found = TRUE; - break; - } - } - - if (!found) { - offset_index = n_stops - 1; - offset_color_stop = offset_color_start = stops[offset_index].color; - } - - _cairo_output_stream_printf (output, - "\n", - offset_color_start.red * 100.0, - offset_color_start.green * 100.0, - offset_color_start.blue * 100.0, - offset_color_start.alpha); - for (i = offset_index; i < n_stops; i++) { - _cairo_output_stream_printf (output, - "\n", - stops[i].offset + start_offset, - stops[i].color.red * 100.0, - stops[i].color.green * 100.0, - stops[i].color.blue * 100.0, - stops[i].color.alpha); - } - for (i = 0; i < offset_index; i++) { - _cairo_output_stream_printf (output, - "\n", - 1.0 + stops[i].offset + start_offset, - stops[i].color.red * 100.0, - stops[i].color.green * 100.0, - stops[i].color.blue * 100.0, - stops[i].color.alpha); - } - - _cairo_output_stream_printf (output, - "\n", - offset_color_stop.red * 100.0, - offset_color_stop.green * 100.0, - offset_color_stop.blue * 100.0, - offset_color_stop.alpha); - - } - - if (reverse_stops || emulate_reflect) - free (stops); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_svg_surface_emit_pattern_extend (cairo_output_stream_t *output, - cairo_pattern_t *pattern) -{ - switch (pattern->extend) { - case CAIRO_EXTEND_REPEAT: - _cairo_output_stream_printf (output, "spreadMethod=\"repeat\" "); - break; - case CAIRO_EXTEND_REFLECT: - _cairo_output_stream_printf (output, "spreadMethod=\"reflect\" "); - break; - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_PAD: - break; - } -} - -static cairo_status_t -_cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface, - cairo_linear_pattern_t *pattern, - cairo_output_stream_t *style, - cairo_bool_t is_stroke, - const cairo_matrix_t *parent_matrix) -{ - cairo_svg_document_t *document = surface->document; - cairo_matrix_t p2u; - cairo_status_t status; - - p2u = pattern->base.base.matrix; - status = cairo_matrix_invert (&p2u); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - _cairo_output_stream_printf (document->xml_node_defs, - "linear_pattern_id, - pattern->pd1.x, pattern->pd1.y, - pattern->pd2.x, pattern->pd2.y); - - _cairo_svg_surface_emit_pattern_extend (document->xml_node_defs, &pattern->base.base), - _cairo_svg_surface_emit_transform (document->xml_node_defs, "gradientTransform", &p2u, parent_matrix); - _cairo_output_stream_printf (document->xml_node_defs, ">\n"); - - status = _cairo_svg_surface_emit_pattern_stops (document->xml_node_defs, - &pattern->base, 0.0, - FALSE, FALSE); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (document->xml_node_defs, - "\n"); - - _cairo_output_stream_printf (style, - "%s:url(#linear%d);", - is_stroke ? "stroke" : "fill", - document->linear_pattern_id); - - document->linear_pattern_id++; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface, - cairo_radial_pattern_t *pattern, - cairo_output_stream_t *style, - cairo_bool_t is_stroke, - const cairo_matrix_t *parent_matrix) -{ - cairo_svg_document_t *document = surface->document; - cairo_matrix_t p2u; - cairo_extend_t extend; - double x0, y0, x1, y1, r0, r1; - double fx, fy; - cairo_bool_t reverse_stops; - cairo_status_t status; - cairo_circle_double_t *c0, *c1; - - extend = pattern->base.base.extend; - - if (pattern->cd1.radius < pattern->cd2.radius) { - c0 = &pattern->cd1; - c1 = &pattern->cd2; - reverse_stops = FALSE; - } else { - c0 = &pattern->cd2; - c1 = &pattern->cd1; - reverse_stops = TRUE; - } - - x0 = c0->center.x; - y0 = c0->center.y; - r0 = c0->radius; - x1 = c1->center.x; - y1 = c1->center.y; - r1 = c1->radius; - - p2u = pattern->base.base.matrix; - status = cairo_matrix_invert (&p2u); - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - if (r0 == r1) { - unsigned int n_stops = pattern->base.n_stops; - - _cairo_output_stream_printf (document->xml_node_defs, - "radial_pattern_id, - x1, y1, - x1, y1, r1); - _cairo_svg_surface_emit_transform (document->xml_node_defs, - "gradientTransform", - &p2u, parent_matrix); - _cairo_output_stream_printf (document->xml_node_defs, ">\n"); - - if (extend == CAIRO_EXTEND_NONE || n_stops < 1) - _cairo_output_stream_printf (document->xml_node_defs, - "\n"); - else { - _cairo_output_stream_printf (document->xml_node_defs, - "\n", - pattern->base.stops[0].color.red * 100.0, - pattern->base.stops[0].color.green * 100.0, - pattern->base.stops[0].color.blue * 100.0, - pattern->base.stops[0].color.alpha); - if (n_stops > 1) - _cairo_output_stream_printf (document->xml_node_defs, - "\n", - pattern->base.stops[n_stops - 1].color.red * 100.0, - pattern->base.stops[n_stops - 1].color.green * 100.0, - pattern->base.stops[n_stops - 1].color.blue * 100.0, - pattern->base.stops[n_stops - 1].color.alpha); - } - - } else { - double offset, r, x, y; - cairo_bool_t emulate_reflect = FALSE; - - fx = (r1 * x0 - r0 * x1) / (r1 - r0); - fy = (r1 * y0 - r0 * y1) / (r1 - r0); - - /* SVG doesn't support the inner circle and use instead a gradient focal. - * That means we need to emulate the cairo behaviour by processing the - * cairo gradient stops. - * The CAIRO_EXTENT_NONE and CAIRO_EXTENT_PAD modes are quite easy to handle, - * it's just a matter of stop position translation and calculation of - * the corresponding SVG radial gradient focal. - * The CAIRO_EXTENT_REFLECT and CAIRO_EXTEND_REPEAT modes require to compute a new - * radial gradient, with an new outer circle, equal to r1 - r0 in the CAIRO_EXTEND_REPEAT - * case, and 2 * (r1 - r0) in the CAIRO_EXTENT_REFLECT case, and a new gradient stop - * list that maps to the original cairo stop list. - */ - if ((extend == CAIRO_EXTEND_REFLECT - || extend == CAIRO_EXTEND_REPEAT) - && r0 > 0.0) { - double r_org = r1; - - if (extend == CAIRO_EXTEND_REFLECT) { - r1 = 2 * r1 - r0; - emulate_reflect = TRUE; - } - - offset = fmod (r1, r1 - r0) / (r1 - r0) - 1.0; - r = r1 - r0; - - /* New position of outer circle. */ - x = r * (x1 - fx) / r_org + fx; - y = r * (y1 - fy) / r_org + fy; - - x1 = x; - y1 = y; - r1 = r; - r0 = 0.0; - } else { - offset = r0 / r1; - } - - _cairo_output_stream_printf (document->xml_node_defs, - "radial_pattern_id, - x1, y1, - fx, fy, r1); - - if (emulate_reflect) - _cairo_output_stream_printf (document->xml_node_defs, "spreadMethod=\"repeat\" "); - else - _cairo_svg_surface_emit_pattern_extend (document->xml_node_defs, &pattern->base.base); - _cairo_svg_surface_emit_transform (document->xml_node_defs, "gradientTransform", &p2u, parent_matrix); - _cairo_output_stream_printf (document->xml_node_defs, ">\n"); - - /* To support cairo's EXTEND_NONE, (for which SVG has no similar - * notion), we add transparent color stops on either end of the - * user-provided stops. */ - if (extend == CAIRO_EXTEND_NONE) { - _cairo_output_stream_printf (document->xml_node_defs, - "\n"); - if (r0 != 0.0) - _cairo_output_stream_printf (document->xml_node_defs, - "\n", - r0 / r1); - } - status = _cairo_svg_surface_emit_pattern_stops (document->xml_node_defs, - &pattern->base, offset, - reverse_stops, - emulate_reflect); - if (unlikely (status)) - return status; - - if (pattern->base.base.extend == CAIRO_EXTEND_NONE) - _cairo_output_stream_printf (document->xml_node_defs, - "\n"); - } - - _cairo_output_stream_printf (document->xml_node_defs, - "\n"); - - _cairo_output_stream_printf (style, - "%s:url(#radial%d);", - is_stroke ? "stroke" : "fill", - document->radial_pattern_id); - - document->radial_pattern_id++; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_svg_surface_emit_pattern (cairo_svg_surface_t *surface, - const cairo_pattern_t *pattern, - cairo_output_stream_t *output, - cairo_bool_t is_stroke, - const cairo_matrix_t *parent_matrix) -{ - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return _cairo_svg_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern, - output, is_stroke); - - case CAIRO_PATTERN_TYPE_SURFACE: - return _cairo_svg_surface_emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern, - output, is_stroke, parent_matrix); - - case CAIRO_PATTERN_TYPE_LINEAR: - return _cairo_svg_surface_emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern, - output, is_stroke, parent_matrix); - - case CAIRO_PATTERN_TYPE_RADIAL: - return _cairo_svg_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern, - output, is_stroke, parent_matrix); - - case CAIRO_PATTERN_TYPE_MESH: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - ASSERT_NOT_REACHED; - } - return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); -} - -static cairo_status_t -_cairo_svg_surface_emit_fill_style (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_fill_rule_t fill_rule, - const cairo_matrix_t *parent_matrix) -{ - _cairo_output_stream_printf (output, - "fill-rule:%s;", - fill_rule == CAIRO_FILL_RULE_EVEN_ODD ? - "evenodd" : "nonzero"); - _cairo_svg_surface_emit_operator_for_style (output, surface, op); - return _cairo_svg_surface_emit_pattern (surface, source, output, FALSE, parent_matrix); -} - -static cairo_status_t -_cairo_svg_surface_emit_stroke_style (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *parent_matrix) -{ - cairo_status_t status; - const char *line_cap, *line_join; - unsigned int i; - - switch (stroke_style->line_cap) { - case CAIRO_LINE_CAP_BUTT: - line_cap = "butt"; - break; - case CAIRO_LINE_CAP_ROUND: - line_cap = "round"; - break; - case CAIRO_LINE_CAP_SQUARE: - line_cap = "square"; - break; - default: - ASSERT_NOT_REACHED; - } - - switch (stroke_style->line_join) { - case CAIRO_LINE_JOIN_MITER: - line_join = "miter"; - break; - case CAIRO_LINE_JOIN_ROUND: - line_join = "round"; - break; - case CAIRO_LINE_JOIN_BEVEL: - line_join = "bevel"; - break; - default: - ASSERT_NOT_REACHED; - } - - _cairo_output_stream_printf (output, - "stroke-width:%f;" - "stroke-linecap:%s;" - "stroke-linejoin:%s;", - stroke_style->line_width, - line_cap, - line_join); - - status = _cairo_svg_surface_emit_pattern (surface, source, output, TRUE, parent_matrix); - if (unlikely (status)) - return status; - - _cairo_svg_surface_emit_operator_for_style (output, surface, op); - - if (stroke_style->num_dashes > 0) { - _cairo_output_stream_printf (output, "stroke-dasharray:"); - for (i = 0; i < stroke_style->num_dashes; i++) { - _cairo_output_stream_printf (output, "%f", - stroke_style->dash[i]); - if (i + 1 < stroke_style->num_dashes) - _cairo_output_stream_printf (output, ","); - else - _cairo_output_stream_printf (output, ";"); - } - if (stroke_style->dash_offset != 0.0) { - _cairo_output_stream_printf (output, - "stroke-dashoffset:%f;", - stroke_style->dash_offset); - } - } - - _cairo_output_stream_printf (output, - "stroke-miterlimit:%f;", - stroke_style->miter_limit); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_fill_stroke (void *abstract_surface, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - const cairo_path_fixed_t*path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip) -{ - cairo_svg_surface_t *surface = abstract_surface; - cairo_status_t status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, "xml_node, surface, fill_op, - fill_source, fill_rule, stroke_ctm_inverse); - if (unlikely (status)) - return status; - - status = _cairo_svg_surface_emit_stroke_style (surface->xml_node, surface, stroke_op, - stroke_source, stroke_style, stroke_ctm_inverse); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, "\" "); - - _cairo_svg_surface_emit_path (surface->xml_node, path, stroke_ctm_inverse); - - _cairo_svg_surface_emit_transform (surface->xml_node, " transform", stroke_ctm, NULL); - _cairo_output_stream_printf (surface->xml_node, "/>\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_svg_surface_t *surface = abstract_surface; - cairo_status_t status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return _cairo_svg_surface_analyze_operation (surface, op, source); - - assert (_cairo_svg_surface_operation_supported (surface, op, source)); - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, "xml_node, surface, op, source, fill_rule, NULL); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, "\" "); - - _cairo_svg_surface_emit_path (surface->xml_node, path, NULL); - - _cairo_output_stream_printf (surface->xml_node, "/>\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_svg_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_svg_surface_t *surface = abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - - /* XXX: The conversion to integers here is pretty bogus, (not to - * mention the arbitrary limitation of width to a short(!). We - * may need to come up with a better interface for get_size. - */ - rectangle->width = ceil (surface->width); - rectangle->height = ceil (surface->height); - - return TRUE; -} - -static cairo_status_t -_cairo_svg_surface_emit_paint (cairo_output_stream_t *output, - cairo_svg_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask_source, - const char *extra_attributes) -{ - cairo_status_t status; - - if (source->type == CAIRO_PATTERN_TYPE_SURFACE && - source->extend == CAIRO_EXTEND_NONE) - return _cairo_svg_surface_emit_composite_pattern (output, - surface, - op, - (cairo_surface_pattern_t *) source, - invalid_pattern_id, - mask_source ? &mask_source->matrix :NULL, - extra_attributes); - - _cairo_output_stream_printf (output, - "width, surface->height); - _cairo_svg_surface_emit_operator_for_style (output, surface, op); - status = _cairo_svg_surface_emit_pattern (surface, source, output, FALSE, NULL); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (output, "stroke:none;\""); - - if (extra_attributes) - _cairo_output_stream_printf (output, " %s", extra_attributes); - - _cairo_output_stream_printf (output, "/>\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_svg_surface_t *surface = abstract_surface; - - /* Emulation of clear and source operators, when no clipping region - * is defined. We just delete existing content of surface root node, - * and exit early if operator is clear. - */ - if ((op == CAIRO_OPERATOR_CLEAR || op == CAIRO_OPERATOR_SOURCE) && - clip == NULL) - { - switch (surface->paginated_mode) { - case CAIRO_PAGINATED_MODE_FALLBACK: - ASSERT_NOT_REACHED; - case CAIRO_PAGINATED_MODE_ANALYZE: - return CAIRO_STATUS_SUCCESS; - - case CAIRO_PAGINATED_MODE_RENDER: - status = _cairo_output_stream_destroy (surface->xml_node); - if (unlikely (status)) { - surface->xml_node = NULL; - return status; - } - - surface->xml_node = _cairo_memory_stream_create (); - if (_cairo_output_stream_get_status (surface->xml_node)) { - status = _cairo_output_stream_destroy (surface->xml_node); - surface->xml_node = NULL; - return status; - } - - if (op == CAIRO_OPERATOR_CLEAR) { - if (surface->content == CAIRO_CONTENT_COLOR) { - _cairo_output_stream_printf (surface->xml_node, - "\n", - surface->width, surface->height); - } - return CAIRO_STATUS_SUCCESS; - } - break; - } - } else { - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return _cairo_svg_surface_analyze_operation (surface, op, source); - - assert (_cairo_svg_surface_operation_supported (surface, op, source)); - } - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - return _cairo_svg_surface_emit_paint (surface->xml_node, - surface, op, source, 0, NULL); -} - -static cairo_int_status_t -_cairo_svg_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_status_t status; - cairo_svg_surface_t *surface = abstract_surface; - cairo_svg_document_t *document = surface->document; - cairo_output_stream_t *mask_stream; - char buffer[64]; - cairo_bool_t discard_filter = FALSE; - unsigned int mask_id; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { - cairo_status_t source_status, mask_status; - - source_status = _cairo_svg_surface_analyze_operation (surface, op, source); - if (_cairo_status_is_error (source_status)) - return source_status; - - if (mask->has_component_alpha) { - mask_status = CAIRO_INT_STATUS_UNSUPPORTED; - } else { - mask_status = _cairo_svg_surface_analyze_operation (surface, op, mask); - if (_cairo_status_is_error (mask_status)) - return mask_status; - } - - return _cairo_analysis_surface_merge_status (source_status, - mask_status); - } - - assert (_cairo_svg_surface_operation_supported (surface, op, source)); - assert (_cairo_svg_surface_operation_supported (surface, CAIRO_OPERATOR_OVER, mask)); - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - if (mask->type == CAIRO_PATTERN_TYPE_SURFACE) { - const cairo_surface_pattern_t *surface_pattern = (const cairo_surface_pattern_t*) mask; - cairo_content_t content = surface_pattern->surface->content; - if (content == CAIRO_CONTENT_ALPHA) - discard_filter = TRUE; - } - - if (!discard_filter) - _cairo_svg_surface_emit_alpha_filter (document); - - /* _cairo_svg_surface_emit_paint() will output a pattern definition to - * document->xml_node_defs so we need to write the mask element to - * a temporary stream and then copy that to xml_node_defs. */ - mask_stream = _cairo_memory_stream_create (); - if (_cairo_output_stream_get_status (mask_stream)) - return _cairo_output_stream_destroy (mask_stream); - - mask_id = _cairo_svg_document_allocate_mask_id (document); - - _cairo_output_stream_printf (mask_stream, - "\n" - "%s", - mask_id, - discard_filter ? "" : " \n"); - status = _cairo_svg_surface_emit_paint (mask_stream, surface, CAIRO_OPERATOR_OVER, mask, source, NULL); - if (unlikely (status)) { - cairo_status_t ignore = _cairo_output_stream_destroy (mask_stream); - return status; - (void) ignore; - } - - _cairo_output_stream_printf (mask_stream, - "%s" - "\n", - discard_filter ? "" : " \n"); - _cairo_memory_stream_copy (mask_stream, document->xml_node_defs); - - status = _cairo_output_stream_destroy (mask_stream); - if (unlikely (status)) - return status; - - snprintf (buffer, sizeof buffer, "mask=\"url(#mask%d)\"", - mask_id); - status = _cairo_svg_surface_emit_paint (surface->xml_node, surface, op, source, 0, buffer); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_stroke (void *abstract_dst, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_svg_surface_t *surface = abstract_dst; - cairo_status_t status; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return _cairo_svg_surface_analyze_operation (surface, op, source); - - assert (_cairo_svg_surface_operation_supported (surface, op, source)); - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, "xml_node, surface, op, - source, stroke_style, ctm_inverse); - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, "\" "); - - _cairo_svg_surface_emit_path (surface->xml_node, path, ctm_inverse); - - _cairo_svg_surface_emit_transform (surface->xml_node, " transform", ctm, NULL); - _cairo_output_stream_printf (surface->xml_node, "/>\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_svg_surface_show_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *pattern, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_svg_surface_t *surface = abstract_surface; - cairo_svg_document_t *document = surface->document; - cairo_path_fixed_t path; - cairo_int_status_t status; - cairo_scaled_font_subsets_glyph_t subset_glyph; - int i; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return _cairo_svg_surface_analyze_operation (surface, op, pattern); - - assert (_cairo_svg_surface_operation_supported (surface, op, pattern)); - - if (num_glyphs <= 0) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - /* FIXME it's probably possible to apply a pattern of a gradient to - * a group of symbols, but I don't know how yet. Gradients or patterns - * are translated by x and y properties of use element. */ - if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) - goto FALLBACK; - - _cairo_output_stream_printf (surface->xml_node, "xml_node, FALSE, NULL); - if (unlikely (status)) - return status; - - _cairo_svg_surface_emit_operator_for_style (surface->xml_node, surface, op); - - _cairo_output_stream_printf (surface->xml_node, "\">\n"); - - for (i = 0; i < num_glyphs; i++) { - status = _cairo_scaled_font_subsets_map_glyph (document->font_subsets, - scaled_font, glyphs[i].index, - NULL, 0, - &subset_glyph); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - _cairo_output_stream_printf (surface->xml_node, "\n"); - - glyphs += i; - num_glyphs -= i; - goto FALLBACK; - } - - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->xml_node, - " \n", - subset_glyph.font_id, - subset_glyph.subset_glyph_index, - glyphs[i].x, glyphs[i].y); - } - - _cairo_output_stream_printf (surface->xml_node, "\n"); - - return CAIRO_STATUS_SUCCESS; - -FALLBACK: - _cairo_path_fixed_init (&path); - - status = _cairo_scaled_font_glyph_path (scaled_font, - (cairo_glyph_t *) glyphs, - num_glyphs, &path); - - if (unlikely (status)) { - _cairo_path_fixed_fini (&path); - return status; - } - - status = _cairo_svg_surface_fill (abstract_surface, op, pattern, - &path, CAIRO_FILL_RULE_WINDING, - 0.0, CAIRO_ANTIALIAS_SUBPIXEL, - clip); - - _cairo_path_fixed_fini (&path); - - return status; -} - -static void -_cairo_svg_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - _cairo_font_options_init_default (options); - - cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); - cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); - _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); -} - - -static const char ** -_cairo_svg_surface_get_supported_mime_types (void *abstract_surface) -{ - return _cairo_svg_supported_mime_types; -} - -static const cairo_surface_backend_t cairo_svg_surface_backend = { - CAIRO_SURFACE_TYPE_SVG, - _cairo_svg_surface_finish, - - _cairo_default_context_create, - - NULL, /* create_similar: handled by wrapper */ - NULL, /* create_similar_image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - _cairo_svg_surface_copy_page, - _cairo_svg_surface_show_page, - - _cairo_svg_surface_get_extents, - _cairo_svg_surface_get_font_options, - - NULL, /* flush */ - NULL, /* mark dirty rectangle */ - - _cairo_svg_surface_paint, - _cairo_svg_surface_mask, - _cairo_svg_surface_stroke, - _cairo_svg_surface_fill, - _cairo_svg_surface_fill_stroke, - _cairo_svg_surface_show_glyphs, - NULL, /* has_show_text_glyphs */ - NULL, /* show_text_glyphs */ - _cairo_svg_surface_get_supported_mime_types, -}; - -static cairo_status_t -_cairo_svg_document_create (cairo_output_stream_t *output_stream, - double width, - double height, - cairo_svg_version_t version, - cairo_svg_document_t **document_out) -{ - cairo_svg_document_t *document; - cairo_status_t status, status_ignored; - - if (output_stream->status) - return output_stream->status; - - document = malloc (sizeof (cairo_svg_document_t)); - if (unlikely (document == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* The use of defs for font glyphs imposes no per-subset limit. */ - document->font_subsets = _cairo_scaled_font_subsets_create_scaled (); - if (unlikely (document->font_subsets == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_DOCUMENT; - } - - document->output_stream = output_stream; - document->refcount = 1; - document->owner = NULL; - document->finished = FALSE; - document->width = width; - document->height = height; - - document->linear_pattern_id = 0; - document->radial_pattern_id = 0; - document->pattern_id = 0; - document->filter_id = 0; - document->clip_id = 0; - document->mask_id = 0; - - document->xml_node_defs = _cairo_memory_stream_create (); - status = _cairo_output_stream_get_status (document->xml_node_defs); - if (unlikely (status)) - goto CLEANUP_NODE_DEFS; - - document->xml_node_glyphs = _cairo_memory_stream_create (); - status = _cairo_output_stream_get_status (document->xml_node_glyphs); - if (unlikely (status)) - goto CLEANUP_NODE_GLYPHS; - - document->alpha_filter = FALSE; - - document->svg_version = version; - - *document_out = document; - return CAIRO_STATUS_SUCCESS; - - CLEANUP_NODE_GLYPHS: - status_ignored = _cairo_output_stream_destroy (document->xml_node_glyphs); - CLEANUP_NODE_DEFS: - status_ignored = _cairo_output_stream_destroy (document->xml_node_defs); - _cairo_scaled_font_subsets_destroy (document->font_subsets); - CLEANUP_DOCUMENT: - free (document); - return status; -} - -static cairo_svg_document_t * -_cairo_svg_document_reference (cairo_svg_document_t *document) -{ - document->refcount++; - - return document; -} - -static unsigned int -_cairo_svg_document_allocate_mask_id (cairo_svg_document_t *document) -{ - return document->mask_id++; -} - -static cairo_status_t -_cairo_svg_document_destroy (cairo_svg_document_t *document) -{ - cairo_status_t status; - - document->refcount--; - if (document->refcount > 0) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_svg_document_finish (document); - - free (document); - - return status; -} - -static cairo_status_t -_cairo_svg_document_finish (cairo_svg_document_t *document) -{ - cairo_status_t status, status2; - cairo_output_stream_t *output = document->output_stream; - cairo_svg_page_t *page; - unsigned int i; - - if (document->finished) - return CAIRO_STATUS_SUCCESS; - - /* - * Should we add DOCTYPE? - * - * Google says no. - * - * http://tech.groups.yahoo.com/group/svg-developers/message/48562: - * There's a bunch of issues, but just to pick a few: - * - they'll give false positives. - * - they'll give false negatives. - * - they're namespace-unaware. - * - they don't wildcard. - * So when they say OK they really haven't checked anything, when - * they say NOT OK they might be on crack, and like all - * namespace-unaware things they're a dead branch of the XML tree. - * - * http://jwatt.org/svg/authoring/: - * Unfortunately the SVG DTDs are a source of so many issues that the - * SVG WG has decided not to write one for the upcoming SVG 1.2 - * standard. In fact SVG WG members are even telling people not to use - * a DOCTYPE declaration in SVG 1.0 and 1.1 documents. - */ - - _cairo_output_stream_printf (output, - "\n" - "\n", - document->width, document->height, - document->width, document->height, - _cairo_svg_internal_version_strings [document->svg_version]); - - status = _cairo_svg_document_emit_font_subsets (document); - - if (_cairo_memory_stream_length (document->xml_node_glyphs) > 0 || - _cairo_memory_stream_length (document->xml_node_defs) > 0) { - _cairo_output_stream_printf (output, "\n"); - if (_cairo_memory_stream_length (document->xml_node_glyphs) > 0) { - _cairo_output_stream_printf (output, "\n"); - _cairo_memory_stream_copy (document->xml_node_glyphs, output); - _cairo_output_stream_printf (output, "\n"); - } - _cairo_memory_stream_copy (document->xml_node_defs, output); - _cairo_output_stream_printf (output, "\n"); - } - - if (document->owner != NULL) { - cairo_svg_surface_t *surface; - - surface = (cairo_svg_surface_t *) _cairo_paginated_surface_get_target (document->owner); - if (surface->xml_node != NULL && - _cairo_memory_stream_length (surface->xml_node) > 0) { - if (unlikely (_cairo_svg_surface_store_page (surface) == NULL)) { - if (status == CAIRO_STATUS_SUCCESS) - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - if (surface->page_set.num_elements > 1 && - _cairo_svg_version_has_page_set_support (document->svg_version)) { - _cairo_output_stream_printf (output, "\n"); - for (i = 0; i < surface->page_set.num_elements; i++) { - page = _cairo_array_index (&surface->page_set, i); - _cairo_output_stream_printf (output, "\n"); - _cairo_output_stream_printf (output, - "\n", - page->surface_id); - _cairo_memory_stream_copy (page->xml_node, output); - _cairo_output_stream_printf (output, "\n\n"); - } - _cairo_output_stream_printf (output, "\n"); - } else if (surface->page_set.num_elements > 0) { - page = _cairo_array_index (&surface->page_set, surface->page_set.num_elements - 1); - _cairo_output_stream_printf (output, - "\n", - page->surface_id); - _cairo_memory_stream_copy (page->xml_node, output); - _cairo_output_stream_printf (output, "\n"); - } - } - - _cairo_output_stream_printf (output, "\n"); - - status2 = _cairo_output_stream_destroy (document->xml_node_glyphs); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - status2 = _cairo_output_stream_destroy (document->xml_node_defs); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - status2 = _cairo_output_stream_destroy (output); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - document->finished = TRUE; - - return status; -} - -static void -_cairo_svg_surface_set_paginated_mode (void *abstract_surface, - cairo_paginated_mode_t paginated_mode) -{ - cairo_svg_surface_t *surface = abstract_surface; - - surface->paginated_mode = paginated_mode; -} - -static cairo_bool_t -_cairo_svg_surface_supports_fine_grained_fallbacks (void *abstract_surface) -{ - cairo_svg_surface_t *surface = abstract_surface; - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2) { - status = _cairo_svg_surface_analyze_operator (surface, - CAIRO_OPERATOR_SOURCE); - } - - return status == CAIRO_INT_STATUS_SUCCESS; -} - -static const cairo_paginated_surface_backend_t cairo_svg_surface_paginated_backend = { - NULL /*_cairo_svg_surface_start_page*/, - _cairo_svg_surface_set_paginated_mode, - NULL, /* _cairo_svg_surface_set_bounding_box */ - NULL, /* _cairo_svg_surface_set_fallback_images_required */ - _cairo_svg_surface_supports_fine_grained_fallbacks, - -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg.h deleted file mode 100644 index 592c645f627..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-svg.h +++ /dev/null @@ -1,84 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * cairo-svg.h - * - * Copyright © 2005 Emmanuel Pacaud - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - */ - -#ifndef CAIRO_SVG_H -#define CAIRO_SVG_H - -#include "cairo.h" - -#if CAIRO_HAS_SVG_SURFACE - -CAIRO_BEGIN_DECLS - -/** - * cairo_svg_version_t: - * @CAIRO_SVG_VERSION_1_1: The version 1.1 of the SVG specification. (Since 1.2) - * @CAIRO_SVG_VERSION_1_2: The version 1.2 of the SVG specification. (Since 1.2) - * - * #cairo_svg_version_t is used to describe the version number of the SVG - * specification that a generated SVG file will conform to. - * - * Since: 1.2 - **/ -typedef enum _cairo_svg_version { - CAIRO_SVG_VERSION_1_1, - CAIRO_SVG_VERSION_1_2 -} cairo_svg_version_t; - -cairo_public cairo_surface_t * -cairo_svg_surface_create (const char *filename, - double width_in_points, - double height_in_points); - -cairo_public cairo_surface_t * -cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, - void *closure, - double width_in_points, - double height_in_points); - -cairo_public void -cairo_svg_surface_restrict_to_version (cairo_surface_t *surface, - cairo_svg_version_t version); - -cairo_public void -cairo_svg_get_versions (cairo_svg_version_t const **versions, - int *num_versions); - -cairo_public const char * -cairo_svg_version_to_string (cairo_svg_version_t version); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_SVG_SURFACE */ -# error Cairo was not compiled with support for the svg backend -#endif /* CAIRO_HAS_SVG_SURFACE */ - -#endif /* CAIRO_SVG_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface-private.h deleted file mode 100644 index a83cfc959db..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface-private.h +++ /dev/null @@ -1,47 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_TEE_SURFACE_PRIVATE_H -#define CAIRO_TEE_SURFACE_PRIVATE_H - -#include "cairoint.h" - -cairo_private cairo_surface_t * -_cairo_tee_surface_find_match (void *abstract_surface, - const cairo_surface_backend_t *backend, - cairo_content_t content); - -#endif /* CAIRO_TEE_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface.c deleted file mode 100644 index 294e5f162e2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee-surface.c +++ /dev/null @@ -1,602 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - * Chris Wilson - */ - -/* This surface supports redirecting all its input to multiple surfaces. - */ - -#include "cairoint.h" - -#include "cairo-tee.h" - -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-tee-surface-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-surface-wrapper-private.h" -#include "cairo-array-private.h" -#include "cairo-image-surface-inline.h" - -typedef struct _cairo_tee_surface { - cairo_surface_t base; - - cairo_surface_wrapper_t master; - cairo_array_t slaves; -} cairo_tee_surface_t; - -slim_hidden_proto (cairo_tee_surface_create); -slim_hidden_proto (cairo_tee_surface_add); - -static cairo_surface_t * -_cairo_tee_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - - cairo_tee_surface_t *other = abstract_surface; - cairo_surface_t *similar; - cairo_surface_t *surface; - cairo_surface_wrapper_t *slaves; - int n, num_slaves; - - similar = _cairo_surface_wrapper_create_similar (&other->master, - content, width, height); - surface = cairo_tee_surface_create (similar); - cairo_surface_destroy (similar); - if (unlikely (surface->status)) - return surface; - - num_slaves = _cairo_array_num_elements (&other->slaves); - slaves = _cairo_array_index (&other->slaves, 0); - for (n = 0; n < num_slaves; n++) { - - similar = _cairo_surface_wrapper_create_similar (&slaves[n], - content, - width, height); - cairo_tee_surface_add (surface, similar); - cairo_surface_destroy (similar); - } - - if (unlikely (surface->status)) { - cairo_status_t status = surface->status; - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - - return surface; -} - -static cairo_status_t -_cairo_tee_surface_finish (void *abstract_surface) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - int n, num_slaves; - - _cairo_surface_wrapper_fini (&surface->master); - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) - _cairo_surface_wrapper_fini (&slaves[n]); - - _cairo_array_fini (&surface->slaves); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_tee_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_tee_surface_t *surface = abstract_surface; - return _cairo_surface_get_source (surface->master.target, extents); -} - -static cairo_status_t -_cairo_tee_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - int num_slaves, n; - - /* we prefer to use a real image surface if available */ - if (_cairo_surface_is_image (surface->master.target)) { - return _cairo_surface_wrapper_acquire_source_image (&surface->master, - image_out, image_extra); - } - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - if (_cairo_surface_is_image (slaves[n].target)) { - return _cairo_surface_wrapper_acquire_source_image (&slaves[n], - image_out, - image_extra); - } - } - - return _cairo_surface_wrapper_acquire_source_image (&surface->master, - image_out, image_extra); -} - -static void -_cairo_tee_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_tee_surface_t *surface = abstract_surface; - - _cairo_surface_wrapper_release_source_image (&surface->master, - image, image_extra); -} - -static cairo_surface_t * -_cairo_tee_surface_snapshot (void *abstract_surface) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - int num_slaves, n; - - /* we prefer to use a recording surface for our snapshots */ - if (_cairo_surface_is_recording (surface->master.target)) - return _cairo_surface_wrapper_snapshot (&surface->master); - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - if (_cairo_surface_is_recording (slaves[n].target)) - return _cairo_surface_wrapper_snapshot (&slaves[n]); - } - - return _cairo_surface_wrapper_snapshot (&surface->master); -} - -static cairo_bool_t -_cairo_tee_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_tee_surface_t *surface = abstract_surface; - - return _cairo_surface_wrapper_get_extents (&surface->master, rectangle); -} - -static void -_cairo_tee_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_tee_surface_t *surface = abstract_surface; - - _cairo_surface_wrapper_get_font_options (&surface->master, options); -} - -static cairo_int_status_t -_cairo_tee_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - int n, num_slaves; - cairo_int_status_t status; - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - status = _cairo_surface_wrapper_paint (&slaves[n], op, source, clip); - if (unlikely (status)) - return status; - } - - return _cairo_surface_wrapper_paint (&surface->master, op, source, clip); -} - -static cairo_int_status_t -_cairo_tee_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - cairo_int_status_t status; - int n, num_slaves; - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - status = _cairo_surface_wrapper_mask (&slaves[n], - op, source, mask, clip); - if (unlikely (status)) - return status; - } - - return _cairo_surface_wrapper_mask (&surface->master, - op, source, mask, clip); -} - -static cairo_int_status_t -_cairo_tee_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - cairo_int_status_t status; - int n, num_slaves; - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - status = _cairo_surface_wrapper_stroke (&slaves[n], - op, source, - path, style, - ctm, ctm_inverse, - tolerance, antialias, - clip); - if (unlikely (status)) - return status; - } - - return _cairo_surface_wrapper_stroke (&surface->master, - op, source, - path, style, - ctm, ctm_inverse, - tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_tee_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - cairo_int_status_t status; - int n, num_slaves; - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - status = _cairo_surface_wrapper_fill (&slaves[n], - op, source, - path, fill_rule, - tolerance, antialias, - clip); - if (unlikely (status)) - return status; - } - - return _cairo_surface_wrapper_fill (&surface->master, - op, source, - path, fill_rule, - tolerance, antialias, - clip); -} - -static cairo_bool_t -_cairo_tee_surface_has_show_text_glyphs (void *abstract_surface) -{ - return TRUE; -} - -static cairo_int_status_t -_cairo_tee_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - cairo_int_status_t status; - int n, num_slaves; - cairo_glyph_t *glyphs_copy; - - /* XXX: This copying is ugly. */ - glyphs_copy = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); - if (unlikely (glyphs_copy == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - memcpy (glyphs_copy, glyphs, sizeof (cairo_glyph_t) * num_glyphs); - status = _cairo_surface_wrapper_show_text_glyphs (&slaves[n], op, - source, - utf8, utf8_len, - glyphs_copy, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font, - clip); - if (unlikely (status)) - goto CLEANUP; - } - - memcpy (glyphs_copy, glyphs, sizeof (cairo_glyph_t) * num_glyphs); - status = _cairo_surface_wrapper_show_text_glyphs (&surface->master, op, - source, - utf8, utf8_len, - glyphs_copy, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font, - clip); -CLEANUP: - free (glyphs_copy); - return status; -} - -static const cairo_surface_backend_t cairo_tee_surface_backend = { - CAIRO_SURFACE_TYPE_TEE, - _cairo_tee_surface_finish, - - _cairo_default_context_create, /* XXX */ - - _cairo_tee_surface_create_similar, - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_tee_surface_source, - _cairo_tee_surface_acquire_source_image, - _cairo_tee_surface_release_source_image, - _cairo_tee_surface_snapshot, - NULL, /* copy_page */ - NULL, /* show_page */ - _cairo_tee_surface_get_extents, - _cairo_tee_surface_get_font_options, - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_tee_surface_paint, - _cairo_tee_surface_mask, - _cairo_tee_surface_stroke, - _cairo_tee_surface_fill, - NULL, /* fill_stroke */ - - NULL, /* show_glyphs */ - - _cairo_tee_surface_has_show_text_glyphs, - _cairo_tee_surface_show_text_glyphs -}; - -cairo_surface_t * -cairo_tee_surface_create (cairo_surface_t *master) -{ - cairo_tee_surface_t *surface; - - if (unlikely (master->status)) - return _cairo_surface_create_in_error (master->status); - - surface = malloc (sizeof (cairo_tee_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &cairo_tee_surface_backend, - master->device, - master->content); - - _cairo_surface_wrapper_init (&surface->master, master); - - _cairo_array_init (&surface->slaves, sizeof (cairo_surface_wrapper_t)); - - return &surface->base; -} -slim_hidden_def (cairo_tee_surface_create); - -void -cairo_tee_surface_add (cairo_surface_t *abstract_surface, - cairo_surface_t *target) -{ - cairo_tee_surface_t *surface; - cairo_surface_wrapper_t slave; - cairo_status_t status; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (abstract_surface->backend != &cairo_tee_surface_backend) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - if (unlikely (target->status)) { - status = _cairo_surface_set_error (abstract_surface, target->status); - return; - } - - surface = (cairo_tee_surface_t *) abstract_surface; - - _cairo_surface_wrapper_init (&slave, target); - status = _cairo_array_append (&surface->slaves, &slave); - if (unlikely (status)) { - _cairo_surface_wrapper_fini (&slave); - status = _cairo_surface_set_error (&surface->base, status); - } -} -slim_hidden_def (cairo_tee_surface_add); - -void -cairo_tee_surface_remove (cairo_surface_t *abstract_surface, - cairo_surface_t *target) -{ - cairo_tee_surface_t *surface; - cairo_surface_wrapper_t *slaves; - int n, num_slaves; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (abstract_surface->backend != &cairo_tee_surface_backend) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - surface = (cairo_tee_surface_t *) abstract_surface; - if (target == surface->master.target) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_INVALID_INDEX)); - return; - } - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - if (slaves[n].target == target) - break; - } - - if (n == num_slaves) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_INVALID_INDEX)); - return; - } - - _cairo_surface_wrapper_fini (&slaves[n]); - for (n++; n < num_slaves; n++) - slaves[n-1] = slaves[n]; - surface->slaves.num_elements--; /* XXX: cairo_array_remove()? */ -} - -cairo_surface_t * -cairo_tee_surface_index (cairo_surface_t *abstract_surface, - unsigned int index) -{ - cairo_tee_surface_t *surface; - - if (unlikely (abstract_surface->status)) - return _cairo_surface_create_in_error (abstract_surface->status); - if (unlikely (abstract_surface->finished)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (abstract_surface->backend != &cairo_tee_surface_backend) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - - surface = (cairo_tee_surface_t *) abstract_surface; - if (index == 0) { - return surface->master.target; - } else { - cairo_surface_wrapper_t *slave; - - index--; - - if (index >= _cairo_array_num_elements (&surface->slaves)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_INDEX)); - - slave = _cairo_array_index (&surface->slaves, index); - return slave->target; - } -} - -cairo_surface_t * -_cairo_tee_surface_find_match (void *abstract_surface, - const cairo_surface_backend_t *backend, - cairo_content_t content) -{ - cairo_tee_surface_t *surface = abstract_surface; - cairo_surface_wrapper_t *slaves; - int num_slaves, n; - - /* exact match first */ - if (surface->master.target->backend == backend && - surface->master.target->content == content) - { - return surface->master.target; - } - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - if (slaves[n].target->backend == backend && - slaves[n].target->content == content) - { - return slaves[n].target; - } - } - - /* matching backend? */ - if (surface->master.target->backend == backend) - return surface->master.target; - - num_slaves = _cairo_array_num_elements (&surface->slaves); - slaves = _cairo_array_index (&surface->slaves, 0); - for (n = 0; n < num_slaves; n++) { - if (slaves[n].target->backend == backend) - return slaves[n].target; - } - - return NULL; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee.h deleted file mode 100644 index 9125a3a4a2b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tee.h +++ /dev/null @@ -1,66 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_TEE_H -#define CAIRO_TEE_H - -#include "cairo.h" - -#if CAIRO_HAS_TEE_SURFACE - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_tee_surface_create (cairo_surface_t *master); - -cairo_public void -cairo_tee_surface_add (cairo_surface_t *surface, - cairo_surface_t *target); - -cairo_public void -cairo_tee_surface_remove (cairo_surface_t *surface, - cairo_surface_t *target); - -cairo_public cairo_surface_t * -cairo_tee_surface_index (cairo_surface_t *surface, - unsigned int index); - -CAIRO_END_DECLS - -#else /*CAIRO_HAS_TEE_SURFACE*/ -# error Cairo was not compiled with support for the TEE backend -#endif /*CAIRO_HAS_TEE_SURFACE*/ - -#endif /*CAIRO_TEE_H*/ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-time-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-time-private.h deleted file mode 100644 index 06dc912b431..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-time-private.h +++ /dev/null @@ -1,94 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright (C) 2011 Andrea Canciani - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of the - * copyright holders not be used in advertising or publicity - * pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied - * warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * Authors: Andrea Canciani - * - */ - -#ifndef CAIRO_TIME_PRIVATE_H -#define CAIRO_TIME_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-wideint-private.h" - -/* Make the base type signed for easier arithmetic */ -typedef cairo_int64_t cairo_time_t; - -#define _cairo_time_add _cairo_int64_add -#define _cairo_time_sub _cairo_int64_sub -#define _cairo_time_gt _cairo_int64_gt -#define _cairo_time_lt _cairo_int64_lt - -#define _cairo_time_to_double _cairo_int64_to_double -#define _cairo_time_from_double _cairo_double_to_int64 - -cairo_private int -_cairo_time_cmp (const void *a, - const void *b); - -cairo_private double -_cairo_time_to_s (cairo_time_t t); - -cairo_private cairo_time_t -_cairo_time_from_s (double t); - -cairo_private cairo_time_t -_cairo_time_get (void); - -static cairo_always_inline cairo_time_t -_cairo_time_get_delta (cairo_time_t t) -{ - cairo_time_t now; - - now = _cairo_time_get (); - - return _cairo_time_sub (now, t); -} - -static cairo_always_inline double -_cairo_time_to_ns (cairo_time_t t) -{ - return 1.e9 * _cairo_time_to_s (t); -} - -static cairo_always_inline cairo_time_t -_cairo_time_max (cairo_time_t a, cairo_time_t b) -{ - if (_cairo_int64_gt (a, b)) - return a; - else - return b; -} - -static cairo_always_inline cairo_time_t -_cairo_time_min (cairo_time_t a, cairo_time_t b) -{ - if (_cairo_int64_lt (a, b)) - return a; - else - return b; -} - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-time.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-time.c deleted file mode 100644 index a0003fbfc2c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-time.c +++ /dev/null @@ -1,225 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright (c) 2007 Netlabs - * Copyright (c) 2006 Mozilla Corporation - * Copyright (c) 2006 Red Hat, Inc. - * Copyright (c) 2011 Andrea Canciani - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of - * the authors not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. The authors make no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR - * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Authors: Peter Weilbacher - * Vladimir Vukicevic - * Carl Worth - * Andrea Canciani - */ - -#include "cairoint.h" - -#include "cairo-time-private.h" - -#if HAVE_CLOCK_GETTIME -#if defined(CLOCK_MONOTONIC_RAW) -#define CAIRO_CLOCK CLOCK_MONOTONIC_RAW -#elif defined(CLOCK_MONOTONIC) -#define CAIRO_CLOCK CLOCK_MONOTONIC -#endif -#endif - -#if defined(__APPLE__) -#include - -static cairo_always_inline double -_cairo_time_1s (void) -{ - mach_timebase_info_data_t freq; - - mach_timebase_info (&freq); - - return 1000000000. * freq.denom / freq.numer; -} - -cairo_time_t -_cairo_time_get (void) -{ - return mach_absolute_time (); -} - -#elif defined(__OS2__) -#define INCL_BASE -#include - -static cairo_always_inline double -_cairo_time_1s (void) -{ - ULONG freq; - - DosTmrQueryFreq (&freq); - - return freq; -} - -cairo_time_t -_cairo_time_get (void) -{ - QWORD t; - cairo_int64_t r; - - DosTmrQueryTime (&t); - - r = _cairo_int64_lsl (_cairo_int32_to_int64 (t.ulHi), 32); - r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.ulLo)); - - return r; -} - -#elif _WIN32 -#define WIN32_LEAN_AND_MEAN -#include - -static cairo_always_inline double -_cairo_time_1s (void) -{ - LARGE_INTEGER freq; - - QueryPerformanceFrequency (&freq); - - return freq.QuadPart; -} - -#ifndef HAVE_UINT64_T -static cairo_always_inline cairo_time_t -_cairo_time_from_large_integer (LARGE_INTEGER t) -{ - cairo_int64_t r; - - r = _cairo_int64_lsl (_cairo_int32_to_int64 (t.HighPart), 32); - r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.LowPart)); - - return r; -} -#else -static cairo_always_inline cairo_time_t -_cairo_time_from_large_integer (LARGE_INTEGER t) -{ - return t.QuadPart; -} -#endif - -cairo_time_t -_cairo_time_get (void) -{ - LARGE_INTEGER t; - - QueryPerformanceCounter (&t); - - return _cairo_time_from_large_integer(t); -} - -#elif defined(CAIRO_CLOCK) -#include - -static cairo_always_inline double -_cairo_time_1s (void) -{ - return 1000000000; -} - -cairo_time_t -_cairo_time_get (void) -{ - struct timespec t; - cairo_time_t r; - - clock_gettime (CAIRO_CLOCK, &t); - - r = _cairo_double_to_int64 (_cairo_time_1s ()); - r = _cairo_int64_mul (r, _cairo_int32_to_int64 (t.tv_sec)); - r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.tv_nsec)); - - return r; -} - -#else -#include - -static cairo_always_inline double -_cairo_time_1s (void) -{ - return 1000000; -} - -cairo_time_t -_cairo_time_get (void) -{ - struct timeval t; - cairo_time_t r; - - gettimeofday (&t, NULL); - - r = _cairo_double_to_int64 (_cairo_time_1s ()); - r = _cairo_int64_mul (r, _cairo_int32_to_int64 (t.tv_sec)); - r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.tv_usec)); - - return r; -} - -#endif - -int -_cairo_time_cmp (const void *a, - const void *b) -{ - const cairo_time_t *ta = a, *tb = b; - return _cairo_int64_cmp (*ta, *tb); -} - -static double -_cairo_time_ticks_per_sec (void) -{ - static double ticks = 0; - - if (unlikely (ticks == 0)) - ticks = _cairo_time_1s (); - - return ticks; -} - -static double -_cairo_time_s_per_tick (void) -{ - static double s = 0; - - if (unlikely (s == 0)) - s = 1. / _cairo_time_ticks_per_sec (); - - return s; -} - -double -_cairo_time_to_s (cairo_time_t t) -{ - return _cairo_int64_to_double (t) * _cairo_time_s_per_tick (); -} - -cairo_time_t -_cairo_time_from_s (double t) -{ - return _cairo_double_to_int64 (t * _cairo_time_ticks_per_sec ()); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor-scan-converter.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor-scan-converter.c deleted file mode 100644 index b1b51872b19..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor-scan-converter.c +++ /dev/null @@ -1,1899 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* glitter-paths - polygon scan converter - * - * Copyright (c) 2008 M Joonas Pihlaja - * Copyright (c) 2007 David Turner - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -/* This is the Glitter paths scan converter incorporated into cairo. - * The source is from commit 734c53237a867a773640bd5b64816249fa1730f8 - * of - * - * http://gitweb.freedesktop.org/?p=users/joonas/glitter-paths - */ -/* Glitter-paths is a stand alone polygon rasteriser derived from - * David Turner's reimplementation of Tor Anderssons's 15x17 - * supersampling rasteriser from the Apparition graphics library. The - * main new feature here is cheaply choosing per-scan line between - * doing fully analytical coverage computation for an entire row at a - * time vs. using a supersampling approach. - * - * David Turner's code can be found at - * - * http://david.freetype.org/rasterizer-shootout/raster-comparison-20070813.tar.bz2 - * - * In particular this file incorporates large parts of ftgrays_tor10.h - * from raster-comparison-20070813.tar.bz2 - */ -/* Overview - * - * A scan converter's basic purpose to take polygon edges and convert - * them into an RLE compressed A8 mask. This one works in two phases: - * gathering edges and generating spans. - * - * 1) As the user feeds the scan converter edges they are vertically - * clipped and bucketted into a _polygon_ data structure. The edges - * are also snapped from the user's coordinates to the subpixel grid - * coordinates used during scan conversion. - * - * user - * | - * | edges - * V - * polygon buckets - * - * 2) Generating spans works by performing a vertical sweep of pixel - * rows from top to bottom and maintaining an _active_list_ of edges - * that intersect the row. From the active list the fill rule - * determines which edges are the left and right edges of the start of - * each span, and their contribution is then accumulated into a pixel - * coverage list (_cell_list_) as coverage deltas. Once the coverage - * deltas of all edges are known we can form spans of constant pixel - * coverage by summing the deltas during a traversal of the cell list. - * At the end of a pixel row the cell list is sent to a coverage - * blitter for rendering to some target surface. - * - * The pixel coverages are computed by either supersampling the row - * and box filtering a mono rasterisation, or by computing the exact - * coverages of edges in the active list. The supersampling method is - * used whenever some edge starts or stops within the row or there are - * edge intersections in the row. - * - * polygon bucket for \ - * current pixel row | - * | | - * | activate new edges | Repeat GRID_Y times if we - * V \ are supersampling this row, - * active list / or just once if we're computing - * | | analytical coverage. - * | coverage deltas | - * V | - * pixel coverage list / - * | - * V - * coverage blitter - */ -#include "cairoint.h" -#include "cairo-spans-private.h" -#include "cairo-error-private.h" - -#include -#include -#include -#include - -/*------------------------------------------------------------------------- - * cairo specific config - */ -#define I static - -/* Prefer cairo's status type. */ -#define GLITTER_HAVE_STATUS_T 1 -#define GLITTER_STATUS_SUCCESS CAIRO_STATUS_SUCCESS -#define GLITTER_STATUS_NO_MEMORY CAIRO_STATUS_NO_MEMORY -typedef cairo_status_t glitter_status_t; - -/* The input coordinate scale and the rasterisation grid scales. */ -#define GLITTER_INPUT_BITS CAIRO_FIXED_FRAC_BITS -#define GRID_X_BITS CAIRO_FIXED_FRAC_BITS -#define GRID_Y 15 - -/* Set glitter up to use a cairo span renderer to do the coverage - * blitting. */ -struct pool; -struct cell_list; - -/*------------------------------------------------------------------------- - * glitter-paths.h - */ - -/* "Input scaled" numbers are fixed precision reals with multiplier - * 2**GLITTER_INPUT_BITS. Input coordinates are given to glitter as - * pixel scaled numbers. These get converted to the internal grid - * scaled numbers as soon as possible. Internal overflow is possible - * if GRID_X/Y inside glitter-paths.c is larger than - * 1< -#include -#include - -/* All polygon coordinates are snapped onto a subsample grid. "Grid - * scaled" numbers are fixed precision reals with multiplier GRID_X or - * GRID_Y. */ -typedef int grid_scaled_t; -typedef int grid_scaled_x_t; -typedef int grid_scaled_y_t; - -/* Default x/y scale factors. - * You can either define GRID_X/Y_BITS to get a power-of-two scale - * or define GRID_X/Y separately. */ -#if !defined(GRID_X) && !defined(GRID_X_BITS) -# define GRID_X_BITS 8 -#endif -#if !defined(GRID_Y) && !defined(GRID_Y_BITS) -# define GRID_Y 15 -#endif - -/* Use GRID_X/Y_BITS to define GRID_X/Y if they're available. */ -#ifdef GRID_X_BITS -# define GRID_X (1 << GRID_X_BITS) -#endif -#ifdef GRID_Y_BITS -# define GRID_Y (1 << GRID_Y_BITS) -#endif - -/* The GRID_X_TO_INT_FRAC macro splits a grid scaled coordinate into - * integer and fractional parts. The integer part is floored. */ -#if defined(GRID_X_TO_INT_FRAC) - /* do nothing */ -#elif defined(GRID_X_BITS) -# define GRID_X_TO_INT_FRAC(x, i, f) \ - _GRID_TO_INT_FRAC_shift(x, i, f, GRID_X_BITS) -#else -# define GRID_X_TO_INT_FRAC(x, i, f) \ - _GRID_TO_INT_FRAC_general(x, i, f, GRID_X) -#endif - -#define _GRID_TO_INT_FRAC_general(t, i, f, m) do { \ - (i) = (t) / (m); \ - (f) = (t) % (m); \ - if ((f) < 0) { \ - --(i); \ - (f) += (m); \ - } \ -} while (0) - -#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do { \ - (f) = (t) & ((1 << (b)) - 1); \ - (i) = (t) >> (b); \ -} while (0) - -/* A grid area is a real in [0,1] scaled by 2*GRID_X*GRID_Y. We want - * to be able to represent exactly areas of subpixel trapezoids whose - * vertices are given in grid scaled coordinates. The scale factor - * comes from needing to accurately represent the area 0.5*dx*dy of a - * triangle with base dx and height dy in grid scaled numbers. */ -#define GRID_XY (2*GRID_X*GRID_Y) /* Unit area on the grid. */ - -/* GRID_AREA_TO_ALPHA(area): map [0,GRID_XY] to [0,255]. */ -#if GRID_XY == 510 -# define GRID_AREA_TO_ALPHA(c) (((c)+1) >> 1) -#elif GRID_XY == 255 -# define GRID_AREA_TO_ALPHA(c) (c) -#elif GRID_XY == 64 -# define GRID_AREA_TO_ALPHA(c) (((c) << 2) | -(((c) & 0x40) >> 6)) -#elif GRID_XY == 128 -# define GRID_AREA_TO_ALPHA(c) ((((c) << 1) | -((c) >> 7)) & 255) -#elif GRID_XY == 256 -# define GRID_AREA_TO_ALPHA(c) (((c) | -((c) >> 8)) & 255) -#elif GRID_XY == 15 -# define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) -#elif GRID_XY == 2*256*15 -# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) -#else -# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) -#endif - -#define UNROLL3(x) x x x - -struct quorem { - int32_t quo; - int64_t rem; -}; - -/* Header for a chunk of memory in a memory pool. */ -struct _pool_chunk { - /* # bytes used in this chunk. */ - size_t size; - - /* # bytes total in this chunk */ - size_t capacity; - - /* Pointer to the previous chunk or %NULL if this is the sentinel - * chunk in the pool header. */ - struct _pool_chunk *prev_chunk; - - /* Actual data starts here. Well aligned even for 64 bit types. */ - int64_t data; -}; - -/* The int64_t data member of _pool_chunk just exists to enforce alignment, - * it shouldn't be included in the allocated size for the struct. */ -#define SIZEOF_POOL_CHUNK (sizeof(struct _pool_chunk) - sizeof(int64_t)) - -/* A memory pool. This is supposed to be embedded on the stack or - * within some other structure. It may optionally be followed by an - * embedded array from which requests are fulfilled until - * malloc needs to be called to allocate a first real chunk. */ -struct pool { - /* Chunk we're allocating from. */ - struct _pool_chunk *current; - - jmp_buf *jmp; - - /* Free list of previously allocated chunks. All have >= default - * capacity. */ - struct _pool_chunk *first_free; - - /* The default capacity of a chunk. */ - size_t default_capacity; - - /* Header for the sentinel chunk. Directly following the pool - * struct should be some space for embedded elements from which - * the sentinel chunk allocates from. This is expressed as a char - * array so that the 'int64_t data' member of _pool_chunk isn't - * included. This way embedding struct pool in other structs works - * without wasting space. */ - char sentinel[SIZEOF_POOL_CHUNK]; -}; - -/* A polygon edge. */ -struct edge { - /* Next in y-bucket or active list. */ - struct edge *next, *prev; - - /* The clipped y of the top of the edge. */ - grid_scaled_y_t ytop; - - /* Number of subsample rows remaining to scan convert of this - * edge. */ - grid_scaled_y_t height_left; - - /* Original sign of the edge: +1 for downwards, -1 for upwards - * edges. */ - int dir; - int cell; - - /* Current x coordinate while the edge is on the active - * list. Initialised to the x coordinate of the top of the - * edge. The quotient is in grid_scaled_x_t units and the - * remainder is mod dy in grid_scaled_y_t units.*/ - struct quorem x; - - /* Advance of the current x when moving down a subsample line. */ - struct quorem dxdy; - - /* Advance of the current x when moving down a full pixel - * row. Only initialised when the height of the edge is large - * enough that there's a chance the edge could be stepped by a - * full row's worth of subsample rows at a time. */ - struct quorem dxdy_full; - - /* y2-y1 after orienting the edge downwards. */ - int64_t dy; -}; - -#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/GRID_Y) - -/* A collection of sorted and vertically clipped edges of the polygon. - * Edges are moved from the polygon to an active list while scan - * converting. */ -struct polygon { - /* The vertical clip extents. */ - grid_scaled_y_t ymin, ymax; - - /* Array of edges all starting in the same bucket. An edge is put - * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when - * it is added to the polygon. */ - struct edge **y_buckets; - struct edge *y_buckets_embedded[64]; - - struct { - struct pool base[1]; - struct edge embedded[32]; - } edge_pool; -}; - -/* A cell records the effect on pixel coverage of polygon edges - * passing through a pixel. It contains two accumulators of pixel - * coverage. - * - * Consider the effects of a polygon edge on the coverage of a pixel - * it intersects and that of the following one. The coverage of the - * following pixel is the height of the edge multiplied by the width - * of the pixel, and the coverage of the pixel itself is the area of - * the trapezoid formed by the edge and the right side of the pixel. - * - * +-----------------------+-----------------------+ - * | | | - * | | | - * |_______________________|_______________________| - * | \...................|.......................|\ - * | \..................|.......................| | - * | \.................|.......................| | - * | \....covered.....|.......................| | - * | \....area.......|.......................| } covered height - * | \..............|.......................| | - * |uncovered\.............|.......................| | - * | area \............|.......................| | - * |___________\...........|.......................|/ - * | | | - * | | | - * | | | - * +-----------------------+-----------------------+ - * - * Since the coverage of the following pixel will always be a multiple - * of the width of the pixel, we can store the height of the covered - * area instead. The coverage of the pixel itself is the total - * coverage minus the area of the uncovered area to the left of the - * edge. As it's faster to compute the uncovered area we only store - * that and subtract it from the total coverage later when forming - * spans to blit. - * - * The heights and areas are signed, with left edges of the polygon - * having positive sign and right edges having negative sign. When - * two edges intersect they swap their left/rightness so their - * contribution above and below the intersection point must be - * computed separately. */ -struct cell { - struct cell *next; - int x; - int16_t uncovered_area; - int16_t covered_height; -}; - -/* A cell list represents the scan line sparsely as cells ordered by - * ascending x. It is geared towards scanning the cells in order - * using an internal cursor. */ -struct cell_list { - /* Sentinel nodes */ - struct cell head, tail; - - /* Cursor state for iterating through the cell list. */ - struct cell *cursor, *rewind; - - /* Cells in the cell list are owned by the cell list and are - * allocated from this pool. */ - struct { - struct pool base[1]; - struct cell embedded[32]; - } cell_pool; -}; - -struct cell_pair { - struct cell *cell1; - struct cell *cell2; -}; - -/* The active list contains edges in the current scan line ordered by - * the x-coordinate of the intercept of the edge and the scan line. */ -struct active_list { - /* Leftmost edge on the current scan line. */ - struct edge head, tail; - - /* A lower bound on the height of the active edges is used to - * estimate how soon some active edge ends. We can't advance the - * scan conversion by a full pixel row if an edge ends somewhere - * within it. */ - grid_scaled_y_t min_height; - int is_vertical; -}; - -struct glitter_scan_converter { - struct polygon polygon[1]; - struct active_list active[1]; - struct cell_list coverages[1]; - - cairo_half_open_span_t *spans; - cairo_half_open_span_t spans_embedded[64]; - - /* Clip box. */ - grid_scaled_x_t xmin, xmax; - grid_scaled_y_t ymin, ymax; -}; - -static struct _pool_chunk * -_pool_chunk_init( - struct _pool_chunk *p, - struct _pool_chunk *prev_chunk, - size_t capacity) -{ - p->prev_chunk = prev_chunk; - p->size = 0; - p->capacity = capacity; - return p; -} - -static struct _pool_chunk * -_pool_chunk_create(struct pool *pool, size_t size) -{ - struct _pool_chunk *p; - - p = malloc(SIZEOF_POOL_CHUNK + size); - if (unlikely (NULL == p)) - longjmp (*pool->jmp, _cairo_error (CAIRO_STATUS_NO_MEMORY)); - - return _pool_chunk_init(p, pool->current, size); -} - -static void -pool_init(struct pool *pool, - jmp_buf *jmp, - size_t default_capacity, - size_t embedded_capacity) -{ - pool->jmp = jmp; - pool->current = (void*) pool->sentinel; - pool->first_free = NULL; - pool->default_capacity = default_capacity; - _pool_chunk_init(pool->current, NULL, embedded_capacity); -} - -static void -pool_fini(struct pool *pool) -{ - struct _pool_chunk *p = pool->current; - do { - while (NULL != p) { - struct _pool_chunk *prev = p->prev_chunk; - if (p != (void *) pool->sentinel) - free(p); - p = prev; - } - p = pool->first_free; - pool->first_free = NULL; - } while (NULL != p); -} - -/* Satisfy an allocation by first allocating a new large enough chunk - * and adding it to the head of the pool's chunk list. This function - * is called as a fallback if pool_alloc() couldn't do a quick - * allocation from the current chunk in the pool. */ -static void * -_pool_alloc_from_new_chunk( - struct pool *pool, - size_t size) -{ - struct _pool_chunk *chunk; - void *obj; - size_t capacity; - - /* If the allocation is smaller than the default chunk size then - * try getting a chunk off the free list. Force alloc of a new - * chunk for large requests. */ - capacity = size; - chunk = NULL; - if (size < pool->default_capacity) { - capacity = pool->default_capacity; - chunk = pool->first_free; - if (chunk) { - pool->first_free = chunk->prev_chunk; - _pool_chunk_init(chunk, pool->current, chunk->capacity); - } - } - - if (NULL == chunk) - chunk = _pool_chunk_create (pool, capacity); - pool->current = chunk; - - obj = ((unsigned char*)&chunk->data + chunk->size); - chunk->size += size; - return obj; -} - -/* Allocate size bytes from the pool. The first allocated address - * returned from a pool is aligned to 8 bytes. Subsequent - * addresses will maintain alignment as long as multiples of 8 are - * allocated. Returns the address of a new memory area or %NULL on - * allocation failures. The pool retains ownership of the returned - * memory. */ -inline static void * -pool_alloc (struct pool *pool, size_t size) -{ - struct _pool_chunk *chunk = pool->current; - - if (size <= chunk->capacity - chunk->size) { - void *obj = ((unsigned char*)&chunk->data + chunk->size); - chunk->size += size; - return obj; - } else { - return _pool_alloc_from_new_chunk(pool, size); - } -} - -/* Relinquish all pool_alloced memory back to the pool. */ -static void -pool_reset (struct pool *pool) -{ - /* Transfer all used chunks to the chunk free list. */ - struct _pool_chunk *chunk = pool->current; - if (chunk != (void *) pool->sentinel) { - while (chunk->prev_chunk != (void *) pool->sentinel) { - chunk = chunk->prev_chunk; - } - chunk->prev_chunk = pool->first_free; - pool->first_free = pool->current; - } - /* Reset the sentinel as the current chunk. */ - pool->current = (void *) pool->sentinel; - pool->current->size = 0; -} - -/* Rewinds the cell list's cursor to the beginning. After rewinding - * we're good to cell_list_find() the cell any x coordinate. */ -inline static void -cell_list_rewind (struct cell_list *cells) -{ - cells->cursor = &cells->head; -} - -inline static void -cell_list_maybe_rewind (struct cell_list *cells, int x) -{ - if (x < cells->cursor->x) { - cells->cursor = cells->rewind; - if (x < cells->cursor->x) - cells->cursor = &cells->head; - } -} - -inline static void -cell_list_set_rewind (struct cell_list *cells) -{ - cells->rewind = cells->cursor; -} - -static void -cell_list_init(struct cell_list *cells, jmp_buf *jmp) -{ - pool_init(cells->cell_pool.base, jmp, - 256*sizeof(struct cell), - sizeof(cells->cell_pool.embedded)); - cells->tail.next = NULL; - cells->tail.x = INT_MAX; - cells->head.x = INT_MIN; - cells->head.next = &cells->tail; - cell_list_rewind (cells); -} - -static void -cell_list_fini(struct cell_list *cells) -{ - pool_fini (cells->cell_pool.base); -} - -/* Empty the cell list. This is called at the start of every pixel - * row. */ -inline static void -cell_list_reset (struct cell_list *cells) -{ - cell_list_rewind (cells); - cells->head.next = &cells->tail; - pool_reset (cells->cell_pool.base); -} - -inline static struct cell * -cell_list_alloc (struct cell_list *cells, - struct cell *tail, - int x) -{ - struct cell *cell; - - cell = pool_alloc (cells->cell_pool.base, sizeof (struct cell)); - cell->next = tail->next; - tail->next = cell; - cell->x = x; - *(uint32_t *)&cell->uncovered_area = 0; - - return cell; -} - -/* Find a cell at the given x-coordinate. Returns %NULL if a new cell - * needed to be allocated but couldn't be. Cells must be found with - * non-decreasing x-coordinate until the cell list is rewound using - * cell_list_rewind(). Ownership of the returned cell is retained by - * the cell list. */ -inline static struct cell * -cell_list_find (struct cell_list *cells, int x) -{ - struct cell *tail = cells->cursor; - - if (tail->x == x) - return tail; - - while (1) { - UNROLL3({ - if (tail->next->x > x) - break; - tail = tail->next; - }); - } - - if (tail->x != x) - tail = cell_list_alloc (cells, tail, x); - return cells->cursor = tail; - -} - -/* Find two cells at x1 and x2. This is exactly equivalent - * to - * - * pair.cell1 = cell_list_find(cells, x1); - * pair.cell2 = cell_list_find(cells, x2); - * - * except with less function call overhead. */ -inline static struct cell_pair -cell_list_find_pair(struct cell_list *cells, int x1, int x2) -{ - struct cell_pair pair; - - pair.cell1 = cells->cursor; - while (1) { - UNROLL3({ - if (pair.cell1->next->x > x1) - break; - pair.cell1 = pair.cell1->next; - }); - } - if (pair.cell1->x != x1) - pair.cell1 = cell_list_alloc (cells, pair.cell1, x1); - - pair.cell2 = pair.cell1; - while (1) { - UNROLL3({ - if (pair.cell2->next->x > x2) - break; - pair.cell2 = pair.cell2->next; - }); - } - if (pair.cell2->x != x2) - pair.cell2 = cell_list_alloc (cells, pair.cell2, x2); - - cells->cursor = pair.cell2; - return pair; -} - -/* Add a subpixel span covering [x1, x2) to the coverage cells. */ -inline static void -cell_list_add_subspan(struct cell_list *cells, - grid_scaled_x_t x1, - grid_scaled_x_t x2) -{ - int ix1, fx1; - int ix2, fx2; - - if (x1 == x2) - return; - - GRID_X_TO_INT_FRAC(x1, ix1, fx1); - GRID_X_TO_INT_FRAC(x2, ix2, fx2); - - if (ix1 != ix2) { - struct cell_pair p; - p = cell_list_find_pair(cells, ix1, ix2); - p.cell1->uncovered_area += 2*fx1; - ++p.cell1->covered_height; - p.cell2->uncovered_area -= 2*fx2; - --p.cell2->covered_height; - } else { - struct cell *cell = cell_list_find(cells, ix1); - cell->uncovered_area += 2*(fx1-fx2); - } -} - -inline static void full_step (struct edge *e) -{ - if (e->dy == 0) - return; - - e->x.quo += e->dxdy_full.quo; - e->x.rem += e->dxdy_full.rem; - if (e->x.rem < 0) { - e->x.quo--; - e->x.rem += e->dy; - } else if (e->x.rem >= e->dy) { - ++e->x.quo; - e->x.rem -= e->dy; - } - - e->cell = e->x.quo + (e->x.rem >= e->dy/2); -} - - -/* Adds the analytical coverage of an edge crossing the current pixel - * row to the coverage cells and advances the edge's x position to the - * following row. - * - * This function is only called when we know that during this pixel row: - * - * 1) The relative order of all edges on the active list doesn't - * change. In particular, no edges intersect within this row to pixel - * precision. - * - * 2) No new edges start in this row. - * - * 3) No existing edges end mid-row. - * - * This function depends on being called with all edges from the - * active list in the order they appear on the list (i.e. with - * non-decreasing x-coordinate.) */ -static void -cell_list_render_edge(struct cell_list *cells, - struct edge *edge, - int sign) -{ - struct quorem x1, x2; - grid_scaled_x_t fx1, fx2; - int ix1, ix2; - - x1 = edge->x; - full_step (edge); - x2 = edge->x; - - /* Step back from the sample location (half-subrow) to the pixel origin */ - if (edge->dy) { - x1.quo -= edge->dxdy.quo / 2; - x1.rem -= edge->dxdy.rem / 2; - if (x1.rem < 0) { - --x1.quo; - x1.rem += edge->dy; - } else if (x1.rem >= edge->dy) { - ++x1.quo; - x1.rem -= edge->dy; - } - - x2.quo -= edge->dxdy.quo / 2; - x2.rem -= edge->dxdy.rem / 2; - if (x2.rem < 0) { - --x2.quo; - x2.rem += edge->dy; - } else if (x2.rem >= edge->dy) { - ++x2.quo; - x2.rem -= edge->dy; - } - } - - GRID_X_TO_INT_FRAC(x1.quo, ix1, fx1); - GRID_X_TO_INT_FRAC(x2.quo, ix2, fx2); - - cell_list_maybe_rewind(cells, MIN(ix1, ix2)); - - /* Edge is entirely within a column? */ - if (ix1 == ix2) { - /* We always know that ix1 is >= the cell list cursor in this - * case due to the no-intersections precondition. */ - struct cell *cell = cell_list_find(cells, ix1); - cell->covered_height += sign*GRID_Y; - cell->uncovered_area += sign*(fx1 + fx2)*GRID_Y; - return; - } - - /* Orient the edge left-to-right. */ - if (ix2 < ix1) { - struct quorem tx; - int t; - - t = ix1; - ix1 = ix2; - ix2 = t; - - t = fx1; - fx1 = fx2; - fx2 = t; - - tx = x1; - x1 = x2; - x2 = tx; - } - - /* Add coverage for all pixels [ix1,ix2] on this row crossed - * by the edge. */ - { - struct cell_pair pair; - struct quorem y; - int64_t tmp, dx; - int y_last; - - dx = (x2.quo - x1.quo) * edge->dy + (x2.rem - x1.rem); - - tmp = (ix1 + 1) * GRID_X * edge->dy; - tmp -= x1.quo * edge->dy + x1.rem; - tmp *= GRID_Y; - - y.quo = tmp / dx; - y.rem = tmp % dx; - - /* When rendering a previous edge on the active list we may - * advance the cell list cursor past the leftmost pixel of the - * current edge even though the two edges don't intersect. - * e.g. consider two edges going down and rightwards: - * - * --\_+---\_+-----+-----+---- - * \_ \_ | | - * | \_ | \_ | | - * | \_| \_| | - * | \_ \_ | - * ----+-----+-\---+-\---+---- - * - * The left edge touches cells past the starting cell of the - * right edge. Fortunately such cases are rare. - */ - - pair = cell_list_find_pair(cells, ix1, ix1+1); - pair.cell1->uncovered_area += sign*y.quo*(GRID_X + fx1); - pair.cell1->covered_height += sign*y.quo; - y_last = y.quo; - - if (ix1+1 < ix2) { - struct cell *cell = pair.cell2; - struct quorem dydx_full; - - dydx_full.quo = GRID_Y * GRID_X * edge->dy / dx; - dydx_full.rem = GRID_Y * GRID_X * edge->dy % dx; - - ++ix1; - do { - y.quo += dydx_full.quo; - y.rem += dydx_full.rem; - if (y.rem >= dx) { - y.quo++; - y.rem -= dx; - } - - cell->uncovered_area += sign*(y.quo - y_last)*GRID_X; - cell->covered_height += sign*(y.quo - y_last); - y_last = y.quo; - - ++ix1; - cell = cell_list_find(cells, ix1); - } while (ix1 != ix2); - - pair.cell2 = cell; - } - pair.cell2->uncovered_area += sign*(GRID_Y - y_last)*fx2; - pair.cell2->covered_height += sign*(GRID_Y - y_last); - } -} - -static void -polygon_init (struct polygon *polygon, jmp_buf *jmp) -{ - polygon->ymin = polygon->ymax = 0; - polygon->y_buckets = polygon->y_buckets_embedded; - pool_init (polygon->edge_pool.base, jmp, - 8192 - sizeof (struct _pool_chunk), - sizeof (polygon->edge_pool.embedded)); -} - -static void -polygon_fini (struct polygon *polygon) -{ - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - pool_fini (polygon->edge_pool.base); -} - -/* Empties the polygon of all edges. The polygon is then prepared to - * receive new edges and clip them to the vertical range - * [ymin,ymax). */ -static glitter_status_t -polygon_reset (struct polygon *polygon, - grid_scaled_y_t ymin, - grid_scaled_y_t ymax) -{ - unsigned h = ymax - ymin; - unsigned num_buckets = EDGE_Y_BUCKET_INDEX(ymax + GRID_Y-1, ymin); - - pool_reset(polygon->edge_pool.base); - - if (unlikely (h > 0x7FFFFFFFU - GRID_Y)) - goto bail_no_mem; /* even if you could, you wouldn't want to. */ - - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - polygon->y_buckets = polygon->y_buckets_embedded; - if (num_buckets > ARRAY_LENGTH (polygon->y_buckets_embedded)) { - polygon->y_buckets = _cairo_malloc_ab (num_buckets, - sizeof (struct edge *)); - if (unlikely (NULL == polygon->y_buckets)) - goto bail_no_mem; - } - memset (polygon->y_buckets, 0, num_buckets * sizeof (struct edge *)); - - polygon->ymin = ymin; - polygon->ymax = ymax; - return GLITTER_STATUS_SUCCESS; - -bail_no_mem: - polygon->ymin = 0; - polygon->ymax = 0; - return GLITTER_STATUS_NO_MEMORY; -} - -static void -_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, - struct edge *e) -{ - unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin); - struct edge **ptail = &polygon->y_buckets[ix]; - e->next = *ptail; - *ptail = e; -} - -static void -active_list_reset (struct active_list *active) -{ - active->head.height_left = INT_MAX; - active->head.dy = 0; - active->head.cell = INT_MIN; - active->head.prev = NULL; - active->head.next = &active->tail; - active->tail.prev = &active->head; - active->tail.next = NULL; - active->tail.cell = INT_MAX; - active->tail.height_left = INT_MAX; - active->tail.dy = 0; - active->min_height = 0; - active->is_vertical = 1; -} - -static void -active_list_init(struct active_list *active) -{ - active_list_reset(active); -} - -/* - * Merge two sorted edge lists. - * Input: - * - head_a: The head of the first list. - * - head_b: The head of the second list; head_b cannot be NULL. - * Output: - * Returns the head of the merged list. - * - * Implementation notes: - * To make it fast (in particular, to reduce to an insertion sort whenever - * one of the two input lists only has a single element) we iterate through - * a list until its head becomes greater than the head of the other list, - * then we switch their roles. As soon as one of the two lists is empty, we - * just attach the other one to the current list and exit. - * Writes to memory are only needed to "switch" lists (as it also requires - * attaching to the output list the list which we will be iterating next) and - * to attach the last non-empty list. - */ -static struct edge * -merge_sorted_edges (struct edge *head_a, struct edge *head_b) -{ - struct edge *head, **next, *prev; - int32_t x; - - prev = head_a->prev; - next = &head; - if (head_a->cell <= head_b->cell) { - head = head_a; - } else { - head = head_b; - head_b->prev = prev; - goto start_with_b; - } - - do { - x = head_b->cell; - while (head_a != NULL && head_a->cell <= x) { - prev = head_a; - next = &head_a->next; - head_a = head_a->next; - } - - head_b->prev = prev; - *next = head_b; - if (head_a == NULL) - return head; - -start_with_b: - x = head_a->cell; - while (head_b != NULL && head_b->cell <= x) { - prev = head_b; - next = &head_b->next; - head_b = head_b->next; - } - - head_a->prev = prev; - *next = head_a; - if (head_b == NULL) - return head; - } while (1); -} - -/* - * Sort (part of) a list. - * Input: - * - list: The list to be sorted; list cannot be NULL. - * - limit: Recursion limit. - * Output: - * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the - * input list; if the input list has fewer elements, head_out be a sorted list - * containing all the elements of the input list. - * Returns the head of the list of unprocessed elements (NULL if the sorted list contains - * all the elements of the input list). - * - * Implementation notes: - * Special case single element list, unroll/inline the sorting of the first two elements. - * Some tail recursion is used since we iterate on the bottom-up solution of the problem - * (we start with a small sorted list and keep merging other lists of the same size to it). - */ -static struct edge * -sort_edges (struct edge *list, - unsigned int level, - struct edge **head_out) -{ - struct edge *head_other, *remaining; - unsigned int i; - - head_other = list->next; - - if (head_other == NULL) { - *head_out = list; - return NULL; - } - - remaining = head_other->next; - if (list->cell <= head_other->cell) { - *head_out = list; - head_other->next = NULL; - } else { - *head_out = head_other; - head_other->prev = list->prev; - head_other->next = list; - list->prev = head_other; - list->next = NULL; - } - - for (i = 0; i < level && remaining; i++) { - remaining = sort_edges (remaining, i, &head_other); - *head_out = merge_sorted_edges (*head_out, head_other); - } - - return remaining; -} - - static struct edge * -merge_unsorted_edges (struct edge *head, struct edge *unsorted) -{ - sort_edges (unsorted, UINT_MAX, &unsorted); - return merge_sorted_edges (head, unsorted); -} - -/* Test if the edges on the active list can be safely advanced by a - * full row without intersections or any edges ending. */ -inline static int -can_do_full_row (struct active_list *active) -{ - const struct edge *e; - int prev_x = INT_MIN; - - /* Recomputes the minimum height of all edges on the active - * list if we have been dropping edges. */ - if (active->min_height <= 0) { - int min_height = INT_MAX; - int is_vertical = 1; - - e = active->head.next; - while (NULL != e) { - if (e->height_left < min_height) - min_height = e->height_left; - is_vertical &= e->dy == 0; - e = e->next; - } - - active->is_vertical = is_vertical; - active->min_height = min_height; - } - - if (active->min_height < GRID_Y) - return 0; - - /* Check for intersections as no edges end during the next row. */ - for (e = active->head.next; e != &active->tail; e = e->next) { - int cell; - - if (e->dy) { - struct quorem x = e->x; - x.quo += e->dxdy_full.quo; - x.rem += e->dxdy_full.rem; - if (x.rem < 0) { - x.quo--; - x.rem += e->dy; - } else if (x.rem >= e->dy) { - x.quo++; - x.rem -= e->dy; - } - cell = x.quo + (x.rem >= e->dy/2); - } else - cell = e->cell; - - if (cell < prev_x) - return 0; - - prev_x = cell; - } - - return 1; -} - -/* Merges edges on the given subpixel row from the polygon to the - * active_list. */ -inline static void -active_list_merge_edges_from_bucket(struct active_list *active, - struct edge *edges) -{ - active->head.next = merge_unsorted_edges (active->head.next, edges); -} - -inline static int -polygon_fill_buckets (struct active_list *active, - struct edge *edge, - int y, - struct edge **buckets) -{ - grid_scaled_y_t min_height = active->min_height; - int is_vertical = active->is_vertical; - int max_suby = 0; - - while (edge) { - struct edge *next = edge->next; - int suby = edge->ytop - y; - if (buckets[suby]) - buckets[suby]->prev = edge; - edge->next = buckets[suby]; - edge->prev = NULL; - buckets[suby] = edge; - if (edge->height_left < min_height) - min_height = edge->height_left; - is_vertical &= edge->dy == 0; - edge = next; - if (suby > max_suby) - max_suby = suby; - } - - active->is_vertical = is_vertical; - active->min_height = min_height; - - return max_suby; -} - -static void step (struct edge *edge) -{ - if (edge->dy == 0) - return; - - edge->x.quo += edge->dxdy.quo; - edge->x.rem += edge->dxdy.rem; - if (edge->x.rem < 0) { - --edge->x.quo; - edge->x.rem += edge->dy; - } else if (edge->x.rem >= edge->dy) { - ++edge->x.quo; - edge->x.rem -= edge->dy; - } - - edge->cell = edge->x.quo + (edge->x.rem >= edge->dy/2); -} - -inline static void -sub_row (struct active_list *active, - struct cell_list *coverages, - unsigned int mask) -{ - struct edge *edge = active->head.next; - int xstart = INT_MIN, prev_x = INT_MIN; - int winding = 0; - - cell_list_rewind (coverages); - - while (&active->tail != edge) { - struct edge *next = edge->next; - int xend = edge->cell; - - if (--edge->height_left) { - step (edge); - - if (edge->cell < prev_x) { - struct edge *pos = edge->prev; - pos->next = next; - next->prev = pos; - do { - pos = pos->prev; - } while (edge->cell < pos->cell); - pos->next->prev = edge; - edge->next = pos->next; - edge->prev = pos; - pos->next = edge; - } else - prev_x = edge->cell; - active->min_height = -1; - } else { - edge->prev->next = next; - next->prev = edge->prev; - } - - winding += edge->dir; - if ((winding & mask) == 0) { - if (next->cell != xend) { - cell_list_add_subspan (coverages, xstart, xend); - xstart = INT_MIN; - } - } else if (xstart == INT_MIN) - xstart = xend; - - edge = next; - } -} - -inline static void dec (struct active_list *a, struct edge *e, int h) -{ - e->height_left -= h; - if (e->height_left == 0) { - e->prev->next = e->next; - e->next->prev = e->prev; - a->min_height = -1; - } -} - -static void -full_row (struct active_list *active, - struct cell_list *coverages, - unsigned int mask) -{ - struct edge *left = active->head.next; - - while (&active->tail != left) { - struct edge *right; - int winding; - - dec (active, left, GRID_Y); - - winding = left->dir; - right = left->next; - do { - dec (active, right, GRID_Y); - - winding += right->dir; - if ((winding & mask) == 0 && right->next->cell != right->cell) - break; - - full_step (right); - - right = right->next; - } while (1); - - cell_list_set_rewind (coverages); - cell_list_render_edge (coverages, left, +1); - cell_list_render_edge (coverages, right, -1); - - left = right->next; - } -} - -static void -_glitter_scan_converter_init(glitter_scan_converter_t *converter, jmp_buf *jmp) -{ - polygon_init(converter->polygon, jmp); - active_list_init(converter->active); - cell_list_init(converter->coverages, jmp); - converter->xmin=0; - converter->ymin=0; - converter->xmax=0; - converter->ymax=0; -} - -static void -_glitter_scan_converter_fini(glitter_scan_converter_t *self) -{ - if (self->spans != self->spans_embedded) - free (self->spans); - - polygon_fini(self->polygon); - cell_list_fini(self->coverages); - - self->xmin=0; - self->ymin=0; - self->xmax=0; - self->ymax=0; -} - -static grid_scaled_t -int_to_grid_scaled(int i, int scale) -{ - /* Clamp to max/min representable scaled number. */ - if (i >= 0) { - if (i >= INT_MAX/scale) - i = INT_MAX/scale; - } - else { - if (i <= INT_MIN/scale) - i = INT_MIN/scale; - } - return i*scale; -} - -#define int_to_grid_scaled_x(x) int_to_grid_scaled((x), GRID_X) -#define int_to_grid_scaled_y(x) int_to_grid_scaled((x), GRID_Y) - -I glitter_status_t -glitter_scan_converter_reset( - glitter_scan_converter_t *converter, - int xmin, int ymin, - int xmax, int ymax) -{ - glitter_status_t status; - int max_num_spans; - - converter->xmin = 0; converter->xmax = 0; - converter->ymin = 0; converter->ymax = 0; - - max_num_spans = xmax - xmin + 1; - - if (max_num_spans > ARRAY_LENGTH(converter->spans_embedded)) { - converter->spans = _cairo_malloc_ab (max_num_spans, - sizeof (cairo_half_open_span_t)); - if (unlikely (converter->spans == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - converter->spans = converter->spans_embedded; - - xmin = int_to_grid_scaled_x(xmin); - ymin = int_to_grid_scaled_y(ymin); - xmax = int_to_grid_scaled_x(xmax); - ymax = int_to_grid_scaled_y(ymax); - - active_list_reset(converter->active); - cell_list_reset(converter->coverages); - status = polygon_reset(converter->polygon, ymin, ymax); - if (status) - return status; - - converter->xmin = xmin; - converter->xmax = xmax; - converter->ymin = ymin; - converter->ymax = ymax; - return GLITTER_STATUS_SUCCESS; -} - -/* INPUT_TO_GRID_X/Y (in_coord, out_grid_scaled, grid_scale) - * These macros convert an input coordinate in the client's - * device space to the rasterisation grid. - */ -/* Gah.. this bit of ugly defines INPUT_TO_GRID_X/Y so as to use - * shifts if possible, and something saneish if not. - */ -#if !defined(INPUT_TO_GRID_Y) && defined(GRID_Y_BITS) && GRID_Y_BITS <= GLITTER_INPUT_BITS -# define INPUT_TO_GRID_Y(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_Y_BITS) -#else -# define INPUT_TO_GRID_Y(in, out) INPUT_TO_GRID_general(in, out, GRID_Y) -#endif - -#if !defined(INPUT_TO_GRID_X) && defined(GRID_X_BITS) && GRID_X_BITS <= GLITTER_INPUT_BITS -# define INPUT_TO_GRID_X(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_X_BITS) -#else -# define INPUT_TO_GRID_X(in, out) INPUT_TO_GRID_general(in, out, GRID_X) -#endif - -#define INPUT_TO_GRID_general(in, out, grid_scale) do { \ - long long tmp__ = (long long)(grid_scale) * (in); \ - tmp__ += 1 << (GLITTER_INPUT_BITS-1); \ - tmp__ >>= GLITTER_INPUT_BITS; \ - (out) = tmp__; \ -} while (0) - -inline static void -polygon_add_edge (struct polygon *polygon, - const cairo_edge_t *edge) -{ - struct edge *e; - grid_scaled_y_t ytop, ybot; - const cairo_point_t *p1, *p2; - - INPUT_TO_GRID_Y (edge->top, ytop); - if (ytop < polygon->ymin) - ytop = polygon->ymin; - - INPUT_TO_GRID_Y (edge->bottom, ybot); - if (ybot > polygon->ymax) - ybot = polygon->ymax; - - if (ybot <= ytop) - return; - - e = pool_alloc (polygon->edge_pool.base, sizeof (struct edge)); - - e->ytop = ytop; - e->height_left = ybot - ytop; - if (edge->line.p2.y > edge->line.p1.y) { - e->dir = edge->dir; - p1 = &edge->line.p1; - p2 = &edge->line.p2; - } else { - e->dir = -edge->dir; - p1 = &edge->line.p2; - p2 = &edge->line.p1; - } - - if (p2->x == p1->x) { - e->cell = p1->x; - e->x.quo = p1->x; - e->x.rem = 0; - e->dxdy.quo = e->dxdy.rem = 0; - e->dxdy_full.quo = e->dxdy_full.rem = 0; - e->dy = 0; - } else { - int64_t Ex, Ey, tmp; - - Ex = (int64_t)(p2->x - p1->x) * GRID_X; - Ey = (int64_t)(p2->y - p1->y) * GRID_Y * (2 << GLITTER_INPUT_BITS); - - e->dxdy.quo = Ex * (2 << GLITTER_INPUT_BITS) / Ey; - e->dxdy.rem = Ex * (2 << GLITTER_INPUT_BITS) % Ey; - - tmp = (int64_t)(2*ytop + 1) << GLITTER_INPUT_BITS; - tmp -= (int64_t)p1->y * GRID_Y * 2; - tmp *= Ex; - e->x.quo = tmp / Ey; - e->x.rem = tmp % Ey; - -#if GRID_X_BITS == GLITTER_INPUT_BITS - e->x.quo += p1->x; -#else - tmp = (int64_t)p1->x * GRID_X; - e->x.quo += tmp >> GLITTER_INPUT_BITS; - e->x.rem += ((tmp & ((1 << GLITTER_INPUT_BITS) - 1)) * Ey) / (1 << GLITTER_INPUT_BITS); -#endif - - if (e->x.rem < 0) { - e->x.quo--; - e->x.rem += Ey; - } else if (e->x.rem >= Ey) { - e->x.quo++; - e->x.rem -= Ey; - } - - if (e->height_left >= GRID_Y) { - tmp = Ex * (2 * GRID_Y << GLITTER_INPUT_BITS); - e->dxdy_full.quo = tmp / Ey; - e->dxdy_full.rem = tmp % Ey; - } else - e->dxdy_full.quo = e->dxdy_full.rem = 0; - - e->cell = e->x.quo + (e->x.rem >= Ey/2); - e->dy = Ey; - } - - _polygon_insert_edge_into_its_y_bucket (polygon, e); -} - -/* Add a new polygon edge from pixel (x1,y1) to (x2,y2) to the scan - * converter. The coordinates represent pixel positions scaled by - * 2**GLITTER_PIXEL_BITS. If this function fails then the scan - * converter should be reset or destroyed. Dir must be +1 or -1, - * with the latter reversing the orientation of the edge. */ -I void -glitter_scan_converter_add_edge (glitter_scan_converter_t *converter, - const cairo_edge_t *edge) -{ - polygon_add_edge (converter->polygon, edge); -} - -static void -step_edges (struct active_list *active, int count) -{ - struct edge *edge; - - count *= GRID_Y; - for (edge = active->head.next; edge != &active->tail; edge = edge->next) { - edge->height_left -= count; - if (! edge->height_left) { - edge->prev->next = edge->next; - edge->next->prev = edge->prev; - active->min_height = -1; - } - } -} - -static glitter_status_t -blit_a8 (struct cell_list *cells, - cairo_span_renderer_t *renderer, - cairo_half_open_span_t *spans, - int y, int height, - int xmin, int xmax) -{ - struct cell *cell = cells->head.next; - int prev_x = xmin, last_x = -1; - int16_t cover = 0, last_cover = 0; - unsigned num_spans; - - if (cell == &cells->tail) - return CAIRO_STATUS_SUCCESS; - - /* Skip cells to the left of the clip region. */ - while (cell->x < xmin) { - cover += cell->covered_height; - cell = cell->next; - } - cover *= GRID_X*2; - - /* Form the spans from the coverages and areas. */ - num_spans = 0; - for (; cell->x < xmax; cell = cell->next) { - int x = cell->x; - int16_t area; - - if (x > prev_x && cover != last_cover) { - spans[num_spans].x = prev_x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); - last_cover = cover; - last_x = prev_x; - ++num_spans; - } - - cover += cell->covered_height*GRID_X*2; - area = cover - cell->uncovered_area; - - if (area != last_cover) { - spans[num_spans].x = x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (area); - last_cover = area; - last_x = x; - ++num_spans; - } - - prev_x = x+1; - } - - if (prev_x <= xmax && cover != last_cover) { - spans[num_spans].x = prev_x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); - last_cover = cover; - last_x = prev_x; - ++num_spans; - } - - if (last_x < xmax && last_cover) { - spans[num_spans].x = xmax; - spans[num_spans].coverage = 0; - ++num_spans; - } - - /* Dump them into the renderer. */ - return renderer->render_rows (renderer, y, height, spans, num_spans); -} - -#define GRID_AREA_TO_A1(A) ((GRID_AREA_TO_ALPHA (A) > 127) ? 255 : 0) -static glitter_status_t -blit_a1 (struct cell_list *cells, - cairo_span_renderer_t *renderer, - cairo_half_open_span_t *spans, - int y, int height, - int xmin, int xmax) -{ - struct cell *cell = cells->head.next; - int prev_x = xmin, last_x = -1; - int16_t cover = 0; - uint8_t coverage, last_cover = 0; - unsigned num_spans; - - if (cell == &cells->tail) - return CAIRO_STATUS_SUCCESS; - - /* Skip cells to the left of the clip region. */ - while (cell->x < xmin) { - cover += cell->covered_height; - cell = cell->next; - } - cover *= GRID_X*2; - - /* Form the spans from the coverages and areas. */ - num_spans = 0; - for (; cell->x < xmax; cell = cell->next) { - int x = cell->x; - int16_t area; - - coverage = GRID_AREA_TO_A1 (cover); - if (x > prev_x && coverage != last_cover) { - last_x = spans[num_spans].x = prev_x; - last_cover = spans[num_spans].coverage = coverage; - ++num_spans; - } - - cover += cell->covered_height*GRID_X*2; - area = cover - cell->uncovered_area; - - coverage = GRID_AREA_TO_A1 (area); - if (coverage != last_cover) { - last_x = spans[num_spans].x = x; - last_cover = spans[num_spans].coverage = coverage; - ++num_spans; - } - - prev_x = x+1; - } - - coverage = GRID_AREA_TO_A1 (cover); - if (prev_x <= xmax && coverage != last_cover) { - last_x = spans[num_spans].x = prev_x; - last_cover = spans[num_spans].coverage = coverage; - ++num_spans; - } - - if (last_x < xmax && last_cover) { - spans[num_spans].x = xmax; - spans[num_spans].coverage = 0; - ++num_spans; - } - if (num_spans == 1) - return CAIRO_STATUS_SUCCESS; - - /* Dump them into the renderer. */ - return renderer->render_rows (renderer, y, height, spans, num_spans); -} - - -I void -glitter_scan_converter_render(glitter_scan_converter_t *converter, - unsigned int winding_mask, - int antialias, - cairo_span_renderer_t *renderer) -{ - int i, j; - int ymax_i = converter->ymax / GRID_Y; - int ymin_i = converter->ymin / GRID_Y; - int xmin_i, xmax_i; - int h = ymax_i - ymin_i; - struct polygon *polygon = converter->polygon; - struct cell_list *coverages = converter->coverages; - struct active_list *active = converter->active; - struct edge *buckets[GRID_Y] = { 0 }; - - xmin_i = converter->xmin / GRID_X; - xmax_i = converter->xmax / GRID_X; - if (xmin_i >= xmax_i) - return; - - /* Render each pixel row. */ - for (i = 0; i < h; i = j) { - int do_full_row = 0; - - j = i + 1; - - /* Determine if we can ignore this row or use the full pixel - * stepper. */ - if (polygon_fill_buckets (active, - polygon->y_buckets[i], - (i+ymin_i)*GRID_Y, - buckets) == 0) { - if (buckets[0]) { - active_list_merge_edges_from_bucket (active, buckets[0]); - buckets[0] = NULL; - } - - if (active->head.next == &active->tail) { - active->min_height = INT_MAX; - active->is_vertical = 1; - for (; j < h && ! polygon->y_buckets[j]; j++) - ; - continue; - } - - do_full_row = can_do_full_row (active); - } - - if (do_full_row) { - /* Step by a full pixel row's worth. */ - full_row (active, coverages, winding_mask); - - if (active->is_vertical) { - while (j < h && - polygon->y_buckets[j] == NULL && - active->min_height >= 2*GRID_Y) - { - active->min_height -= GRID_Y; - j++; - } - if (j != i + 1) - step_edges (active, j - (i + 1)); - } - } else { - int sub; - - /* Subsample this row. */ - for (sub = 0; sub < GRID_Y; sub++) { - if (buckets[sub]) { - active_list_merge_edges_from_bucket (active, buckets[sub]); - buckets[sub] = NULL; - } - sub_row (active, coverages, winding_mask); - } - } - - if (antialias) - blit_a8 (coverages, renderer, converter->spans, - i+ymin_i, j-i, xmin_i, xmax_i); - else - blit_a1 (coverages, renderer, converter->spans, - i+ymin_i, j-i, xmin_i, xmax_i); - cell_list_reset (coverages); - - active->min_height -= GRID_Y; - } -} - -struct _cairo_tor_scan_converter { - cairo_scan_converter_t base; - - glitter_scan_converter_t converter[1]; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - - jmp_buf jmp; -}; - -typedef struct _cairo_tor_scan_converter cairo_tor_scan_converter_t; - -static void -_cairo_tor_scan_converter_destroy (void *converter) -{ - cairo_tor_scan_converter_t *self = converter; - if (self == NULL) { - return; - } - _glitter_scan_converter_fini (self->converter); - free(self); -} - -cairo_status_t -_cairo_tor_scan_converter_add_polygon (void *converter, - const cairo_polygon_t *polygon) -{ - cairo_tor_scan_converter_t *self = converter; - int i; - -#if 0 - FILE *file = fopen ("polygon.txt", "w"); - _cairo_debug_print_polygon (file, polygon); - fclose (file); -#endif - - for (i = 0; i < polygon->num_edges; i++) - glitter_scan_converter_add_edge (self->converter, &polygon->edges[i]); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_tor_scan_converter_generate (void *converter, - cairo_span_renderer_t *renderer) -{ - cairo_tor_scan_converter_t *self = converter; - cairo_status_t status; - - if ((status = setjmp (self->jmp))) - return _cairo_scan_converter_set_error (self, _cairo_error (status)); - - glitter_scan_converter_render (self->converter, - self->fill_rule == CAIRO_FILL_RULE_WINDING ? ~0 : 1, - self->antialias != CAIRO_ANTIALIAS_NONE, - renderer); - return CAIRO_STATUS_SUCCESS; -} - -cairo_scan_converter_t * -_cairo_tor_scan_converter_create (int xmin, - int ymin, - int xmax, - int ymax, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias) -{ - cairo_tor_scan_converter_t *self; - cairo_status_t status; - - self = malloc (sizeof(struct _cairo_tor_scan_converter)); - if (unlikely (self == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto bail_nomem; - } - - self->base.destroy = _cairo_tor_scan_converter_destroy; - self->base.generate = _cairo_tor_scan_converter_generate; - - _glitter_scan_converter_init (self->converter, &self->jmp); - status = glitter_scan_converter_reset (self->converter, - xmin, ymin, xmax, ymax); - if (unlikely (status)) - goto bail; - - self->fill_rule = fill_rule; - self->antialias = antialias; - - return &self->base; - - bail: - self->base.destroy(&self->base); - bail_nomem: - return _cairo_scan_converter_create_in_error (status); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor22-scan-converter.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor22-scan-converter.c deleted file mode 100644 index 4cec5ee4f37..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tor22-scan-converter.c +++ /dev/null @@ -1,1709 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* glitter-paths - polygon scan converter - * - * Copyright (c) 2008 M Joonas Pihlaja - * Copyright (c) 2007 David Turner - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -/* This is the Glitter paths scan converter incorporated into cairo. - * The source is from commit 734c53237a867a773640bd5b64816249fa1730f8 - * of - * - * http://gitweb.freedesktop.org/?p=users/joonas/glitter-paths - */ -/* Glitter-paths is a stand alone polygon rasteriser derived from - * David Turner's reimplementation of Tor Anderssons's 15x17 - * supersampling rasteriser from the Apparition graphics library. The - * main new feature here is cheaply choosing per-scan line between - * doing fully analytical coverage computation for an entire row at a - * time vs. using a supersampling approach. - * - * David Turner's code can be found at - * - * http://david.freetype.org/rasterizer-shootout/raster-comparison-20070813.tar.bz2 - * - * In particular this file incorporates large parts of ftgrays_tor10.h - * from raster-comparison-20070813.tar.bz2 - */ -/* Overview - * - * A scan converter's basic purpose to take polygon edges and convert - * them into an RLE compressed A8 mask. This one works in two phases: - * gathering edges and generating spans. - * - * 1) As the user feeds the scan converter edges they are vertically - * clipped and bucketted into a _polygon_ data structure. The edges - * are also snapped from the user's coordinates to the subpixel grid - * coordinates used during scan conversion. - * - * user - * | - * | edges - * V - * polygon buckets - * - * 2) Generating spans works by performing a vertical sweep of pixel - * rows from top to bottom and maintaining an _active_list_ of edges - * that intersect the row. From the active list the fill rule - * determines which edges are the left and right edges of the start of - * each span, and their contribution is then accumulated into a pixel - * coverage list (_cell_list_) as coverage deltas. Once the coverage - * deltas of all edges are known we can form spans of constant pixel - * coverage by summing the deltas during a traversal of the cell list. - * At the end of a pixel row the cell list is sent to a coverage - * blitter for rendering to some target surface. - * - * The pixel coverages are computed by either supersampling the row - * and box filtering a mono rasterisation, or by computing the exact - * coverages of edges in the active list. The supersampling method is - * used whenever some edge starts or stops within the row or there are - * edge intersections in the row. - * - * polygon bucket for \ - * current pixel row | - * | | - * | activate new edges | Repeat GRID_Y times if we - * V \ are supersampling this row, - * active list / or just once if we're computing - * | | analytical coverage. - * | coverage deltas | - * V | - * pixel coverage list / - * | - * V - * coverage blitter - */ -#include "cairoint.h" -#include "cairo-spans-private.h" -#include "cairo-error-private.h" - -#include -#include -#include -#include - -/*------------------------------------------------------------------------- - * cairo specific config - */ -#define I static - -/* Prefer cairo's status type. */ -#define GLITTER_HAVE_STATUS_T 1 -#define GLITTER_STATUS_SUCCESS CAIRO_STATUS_SUCCESS -#define GLITTER_STATUS_NO_MEMORY CAIRO_STATUS_NO_MEMORY -typedef cairo_status_t glitter_status_t; - -/* The input coordinate scale and the rasterisation grid scales. */ -#define GLITTER_INPUT_BITS CAIRO_FIXED_FRAC_BITS -//#define GRID_X_BITS CAIRO_FIXED_FRAC_BITS -//#define GRID_Y 15 -#define GRID_X_BITS 2 -#define GRID_Y_BITS 2 - -/* Set glitter up to use a cairo span renderer to do the coverage - * blitting. */ -struct pool; -struct cell_list; - -/*------------------------------------------------------------------------- - * glitter-paths.h - */ - -/* "Input scaled" numbers are fixed precision reals with multiplier - * 2**GLITTER_INPUT_BITS. Input coordinates are given to glitter as - * pixel scaled numbers. These get converted to the internal grid - * scaled numbers as soon as possible. Internal overflow is possible - * if GRID_X/Y inside glitter-paths.c is larger than - * 1< -#include -#include - -/* All polygon coordinates are snapped onto a subsample grid. "Grid - * scaled" numbers are fixed precision reals with multiplier GRID_X or - * GRID_Y. */ -typedef int grid_scaled_t; -typedef int grid_scaled_x_t; -typedef int grid_scaled_y_t; - -/* Default x/y scale factors. - * You can either define GRID_X/Y_BITS to get a power-of-two scale - * or define GRID_X/Y separately. */ -#if !defined(GRID_X) && !defined(GRID_X_BITS) -# define GRID_X_BITS 8 -#endif -#if !defined(GRID_Y) && !defined(GRID_Y_BITS) -# define GRID_Y 15 -#endif - -/* Use GRID_X/Y_BITS to define GRID_X/Y if they're available. */ -#ifdef GRID_X_BITS -# define GRID_X (1 << GRID_X_BITS) -#endif -#ifdef GRID_Y_BITS -# define GRID_Y (1 << GRID_Y_BITS) -#endif - -/* The GRID_X_TO_INT_FRAC macro splits a grid scaled coordinate into - * integer and fractional parts. The integer part is floored. */ -#if defined(GRID_X_TO_INT_FRAC) - /* do nothing */ -#elif defined(GRID_X_BITS) -# define GRID_X_TO_INT_FRAC(x, i, f) \ - _GRID_TO_INT_FRAC_shift(x, i, f, GRID_X_BITS) -#else -# define GRID_X_TO_INT_FRAC(x, i, f) \ - _GRID_TO_INT_FRAC_general(x, i, f, GRID_X) -#endif - -#define _GRID_TO_INT_FRAC_general(t, i, f, m) do { \ - (i) = (t) / (m); \ - (f) = (t) % (m); \ - if ((f) < 0) { \ - --(i); \ - (f) += (m); \ - } \ -} while (0) - -#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do { \ - (f) = (t) & ((1 << (b)) - 1); \ - (i) = (t) >> (b); \ -} while (0) - -/* A grid area is a real in [0,1] scaled by 2*GRID_X*GRID_Y. We want - * to be able to represent exactly areas of subpixel trapezoids whose - * vertices are given in grid scaled coordinates. The scale factor - * comes from needing to accurately represent the area 0.5*dx*dy of a - * triangle with base dx and height dy in grid scaled numbers. */ -#define GRID_XY (2*GRID_X*GRID_Y) /* Unit area on the grid. */ - -/* GRID_AREA_TO_ALPHA(area): map [0,GRID_XY] to [0,255]. */ -#if GRID_XY == 510 -# define GRID_AREA_TO_ALPHA(c) (((c)+1) >> 1) -#elif GRID_XY == 255 -# define GRID_AREA_TO_ALPHA(c) (c) -#elif GRID_XY == 64 -# define GRID_AREA_TO_ALPHA(c) (((c) << 2) | -(((c) & 0x40) >> 6)) -#elif GRID_XY == 32 -# define GRID_AREA_TO_ALPHA(c) (((c) << 3) | -(((c) & 0x20) >> 5)) -#elif GRID_XY == 128 -# define GRID_AREA_TO_ALPHA(c) ((((c) << 1) | -((c) >> 7)) & 255) -#elif GRID_XY == 256 -# define GRID_AREA_TO_ALPHA(c) (((c) | -((c) >> 8)) & 255) -#elif GRID_XY == 15 -# define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) -#elif GRID_XY == 2*256*15 -# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) -#else -# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) -#endif - -#define UNROLL3(x) x x x - -struct quorem { - int32_t quo; - int32_t rem; -}; - -/* Header for a chunk of memory in a memory pool. */ -struct _pool_chunk { - /* # bytes used in this chunk. */ - size_t size; - - /* # bytes total in this chunk */ - size_t capacity; - - /* Pointer to the previous chunk or %NULL if this is the sentinel - * chunk in the pool header. */ - struct _pool_chunk *prev_chunk; - - /* Actual data starts here. Well aligned for pointers. */ -}; - -/* A memory pool. This is supposed to be embedded on the stack or - * within some other structure. It may optionally be followed by an - * embedded array from which requests are fulfilled until - * malloc needs to be called to allocate a first real chunk. */ -struct pool { - /* Chunk we're allocating from. */ - struct _pool_chunk *current; - - jmp_buf *jmp; - - /* Free list of previously allocated chunks. All have >= default - * capacity. */ - struct _pool_chunk *first_free; - - /* The default capacity of a chunk. */ - size_t default_capacity; - - /* Header for the sentinel chunk. Directly following the pool - * struct should be some space for embedded elements from which - * the sentinel chunk allocates from. */ - struct _pool_chunk sentinel[1]; -}; - -/* A polygon edge. */ -struct edge { - /* Next in y-bucket or active list. */ - struct edge *next, *prev; - - /* Number of subsample rows remaining to scan convert of this - * edge. */ - grid_scaled_y_t height_left; - - /* Original sign of the edge: +1 for downwards, -1 for upwards - * edges. */ - int dir; - int vertical; - - /* Current x coordinate while the edge is on the active - * list. Initialised to the x coordinate of the top of the - * edge. The quotient is in grid_scaled_x_t units and the - * remainder is mod dy in grid_scaled_y_t units.*/ - struct quorem x; - - /* Advance of the current x when moving down a subsample line. */ - struct quorem dxdy; - - /* The clipped y of the top of the edge. */ - grid_scaled_y_t ytop; - - /* y2-y1 after orienting the edge downwards. */ - grid_scaled_y_t dy; -}; - -#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/GRID_Y) - -/* A collection of sorted and vertically clipped edges of the polygon. - * Edges are moved from the polygon to an active list while scan - * converting. */ -struct polygon { - /* The vertical clip extents. */ - grid_scaled_y_t ymin, ymax; - - /* Array of edges all starting in the same bucket. An edge is put - * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when - * it is added to the polygon. */ - struct edge **y_buckets; - struct edge *y_buckets_embedded[64]; - - struct { - struct pool base[1]; - struct edge embedded[32]; - } edge_pool; -}; - -/* A cell records the effect on pixel coverage of polygon edges - * passing through a pixel. It contains two accumulators of pixel - * coverage. - * - * Consider the effects of a polygon edge on the coverage of a pixel - * it intersects and that of the following one. The coverage of the - * following pixel is the height of the edge multiplied by the width - * of the pixel, and the coverage of the pixel itself is the area of - * the trapezoid formed by the edge and the right side of the pixel. - * - * +-----------------------+-----------------------+ - * | | | - * | | | - * |_______________________|_______________________| - * | \...................|.......................|\ - * | \..................|.......................| | - * | \.................|.......................| | - * | \....covered.....|.......................| | - * | \....area.......|.......................| } covered height - * | \..............|.......................| | - * |uncovered\.............|.......................| | - * | area \............|.......................| | - * |___________\...........|.......................|/ - * | | | - * | | | - * | | | - * +-----------------------+-----------------------+ - * - * Since the coverage of the following pixel will always be a multiple - * of the width of the pixel, we can store the height of the covered - * area instead. The coverage of the pixel itself is the total - * coverage minus the area of the uncovered area to the left of the - * edge. As it's faster to compute the uncovered area we only store - * that and subtract it from the total coverage later when forming - * spans to blit. - * - * The heights and areas are signed, with left edges of the polygon - * having positive sign and right edges having negative sign. When - * two edges intersect they swap their left/rightness so their - * contribution above and below the intersection point must be - * computed separately. */ -struct cell { - struct cell *next; - int x; - int16_t uncovered_area; - int16_t covered_height; -}; - -/* A cell list represents the scan line sparsely as cells ordered by - * ascending x. It is geared towards scanning the cells in order - * using an internal cursor. */ -struct cell_list { - /* Sentinel nodes */ - struct cell head, tail; - - /* Cursor state for iterating through the cell list. */ - struct cell *cursor, *rewind; - - /* Cells in the cell list are owned by the cell list and are - * allocated from this pool. */ - struct { - struct pool base[1]; - struct cell embedded[32]; - } cell_pool; -}; - -struct cell_pair { - struct cell *cell1; - struct cell *cell2; -}; - -/* The active list contains edges in the current scan line ordered by - * the x-coordinate of the intercept of the edge and the scan line. */ -struct active_list { - /* Leftmost edge on the current scan line. */ - struct edge head, tail; - - /* A lower bound on the height of the active edges is used to - * estimate how soon some active edge ends. We can't advance the - * scan conversion by a full pixel row if an edge ends somewhere - * within it. */ - grid_scaled_y_t min_height; - int is_vertical; -}; - -struct glitter_scan_converter { - struct polygon polygon[1]; - struct active_list active[1]; - struct cell_list coverages[1]; - - cairo_half_open_span_t *spans; - cairo_half_open_span_t spans_embedded[64]; - - /* Clip box. */ - grid_scaled_x_t xmin, xmax; - grid_scaled_y_t ymin, ymax; -}; - -/* Compute the floored division a/b. Assumes / and % perform symmetric - * division. */ -inline static struct quorem -floored_divrem(int a, int b) -{ - struct quorem qr; - qr.quo = a/b; - qr.rem = a%b; - if ((a^b)<0 && qr.rem) { - qr.quo -= 1; - qr.rem += b; - } - return qr; -} - -/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric - * division. */ -static struct quorem -floored_muldivrem(int x, int a, int b) -{ - struct quorem qr; - long long xa = (long long)x*a; - qr.quo = xa/b; - qr.rem = xa%b; - if ((xa>=0) != (b>=0) && qr.rem) { - qr.quo -= 1; - qr.rem += b; - } - return qr; -} - -static struct _pool_chunk * -_pool_chunk_init( - struct _pool_chunk *p, - struct _pool_chunk *prev_chunk, - size_t capacity) -{ - p->prev_chunk = prev_chunk; - p->size = 0; - p->capacity = capacity; - return p; -} - -static struct _pool_chunk * -_pool_chunk_create(struct pool *pool, size_t size) -{ - struct _pool_chunk *p; - - p = malloc(size + sizeof(struct _pool_chunk)); - if (unlikely (NULL == p)) - longjmp (*pool->jmp, _cairo_error (CAIRO_STATUS_NO_MEMORY)); - - return _pool_chunk_init(p, pool->current, size); -} - -static void -pool_init(struct pool *pool, - jmp_buf *jmp, - size_t default_capacity, - size_t embedded_capacity) -{ - pool->jmp = jmp; - pool->current = pool->sentinel; - pool->first_free = NULL; - pool->default_capacity = default_capacity; - _pool_chunk_init(pool->sentinel, NULL, embedded_capacity); -} - -static void -pool_fini(struct pool *pool) -{ - struct _pool_chunk *p = pool->current; - do { - while (NULL != p) { - struct _pool_chunk *prev = p->prev_chunk; - if (p != pool->sentinel) - free(p); - p = prev; - } - p = pool->first_free; - pool->first_free = NULL; - } while (NULL != p); -} - -/* Satisfy an allocation by first allocating a new large enough chunk - * and adding it to the head of the pool's chunk list. This function - * is called as a fallback if pool_alloc() couldn't do a quick - * allocation from the current chunk in the pool. */ -static void * -_pool_alloc_from_new_chunk( - struct pool *pool, - size_t size) -{ - struct _pool_chunk *chunk; - void *obj; - size_t capacity; - - /* If the allocation is smaller than the default chunk size then - * try getting a chunk off the free list. Force alloc of a new - * chunk for large requests. */ - capacity = size; - chunk = NULL; - if (size < pool->default_capacity) { - capacity = pool->default_capacity; - chunk = pool->first_free; - if (chunk) { - pool->first_free = chunk->prev_chunk; - _pool_chunk_init(chunk, pool->current, chunk->capacity); - } - } - - if (NULL == chunk) - chunk = _pool_chunk_create (pool, capacity); - pool->current = chunk; - - obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); - chunk->size += size; - return obj; -} - -/* Allocate size bytes from the pool. The first allocated address - * returned from a pool is aligned to sizeof(void*). Subsequent - * addresses will maintain alignment as long as multiples of void* are - * allocated. Returns the address of a new memory area or %NULL on - * allocation failures. The pool retains ownership of the returned - * memory. */ -inline static void * -pool_alloc (struct pool *pool, size_t size) -{ - struct _pool_chunk *chunk = pool->current; - - if (size <= chunk->capacity - chunk->size) { - void *obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); - chunk->size += size; - return obj; - } else { - return _pool_alloc_from_new_chunk(pool, size); - } -} - -/* Relinquish all pool_alloced memory back to the pool. */ -static void -pool_reset (struct pool *pool) -{ - /* Transfer all used chunks to the chunk free list. */ - struct _pool_chunk *chunk = pool->current; - if (chunk != pool->sentinel) { - while (chunk->prev_chunk != pool->sentinel) { - chunk = chunk->prev_chunk; - } - chunk->prev_chunk = pool->first_free; - pool->first_free = pool->current; - } - /* Reset the sentinel as the current chunk. */ - pool->current = pool->sentinel; - pool->sentinel->size = 0; -} - -/* Rewinds the cell list's cursor to the beginning. After rewinding - * we're good to cell_list_find() the cell any x coordinate. */ -inline static void -cell_list_rewind (struct cell_list *cells) -{ - cells->cursor = &cells->head; -} - -inline static void -cell_list_maybe_rewind (struct cell_list *cells, int x) -{ - if (x < cells->cursor->x) { - cells->cursor = cells->rewind; - if (x < cells->cursor->x) - cells->cursor = &cells->head; - } -} - -inline static void -cell_list_set_rewind (struct cell_list *cells) -{ - cells->rewind = cells->cursor; -} - -static void -cell_list_init(struct cell_list *cells, jmp_buf *jmp) -{ - pool_init(cells->cell_pool.base, jmp, - 256*sizeof(struct cell), - sizeof(cells->cell_pool.embedded)); - cells->tail.next = NULL; - cells->tail.x = INT_MAX; - cells->head.x = INT_MIN; - cells->head.next = &cells->tail; - cell_list_rewind (cells); -} - -static void -cell_list_fini(struct cell_list *cells) -{ - pool_fini (cells->cell_pool.base); -} - -/* Empty the cell list. This is called at the start of every pixel - * row. */ -inline static void -cell_list_reset (struct cell_list *cells) -{ - cell_list_rewind (cells); - cells->head.next = &cells->tail; - pool_reset (cells->cell_pool.base); -} - -inline static struct cell * -cell_list_alloc (struct cell_list *cells, - struct cell *tail, - int x) -{ - struct cell *cell; - - cell = pool_alloc (cells->cell_pool.base, sizeof (struct cell)); - cell->next = tail->next; - tail->next = cell; - cell->x = x; - *(uint32_t *)&cell->uncovered_area = 0; - - return cell; -} - -/* Find a cell at the given x-coordinate. Returns %NULL if a new cell - * needed to be allocated but couldn't be. Cells must be found with - * non-decreasing x-coordinate until the cell list is rewound using - * cell_list_rewind(). Ownership of the returned cell is retained by - * the cell list. */ -inline static struct cell * -cell_list_find (struct cell_list *cells, int x) -{ - struct cell *tail = cells->cursor; - - if (tail->x == x) - return tail; - - while (1) { - UNROLL3({ - if (tail->next->x > x) - break; - tail = tail->next; - }); - } - - if (tail->x != x) - tail = cell_list_alloc (cells, tail, x); - return cells->cursor = tail; - -} - -/* Find two cells at x1 and x2. This is exactly equivalent - * to - * - * pair.cell1 = cell_list_find(cells, x1); - * pair.cell2 = cell_list_find(cells, x2); - * - * except with less function call overhead. */ -inline static struct cell_pair -cell_list_find_pair(struct cell_list *cells, int x1, int x2) -{ - struct cell_pair pair; - - pair.cell1 = cells->cursor; - while (1) { - UNROLL3({ - if (pair.cell1->next->x > x1) - break; - pair.cell1 = pair.cell1->next; - }); - } - if (pair.cell1->x != x1) - pair.cell1 = cell_list_alloc (cells, pair.cell1, x1); - - pair.cell2 = pair.cell1; - while (1) { - UNROLL3({ - if (pair.cell2->next->x > x2) - break; - pair.cell2 = pair.cell2->next; - }); - } - if (pair.cell2->x != x2) - pair.cell2 = cell_list_alloc (cells, pair.cell2, x2); - - cells->cursor = pair.cell2; - return pair; -} - -/* Add a subpixel span covering [x1, x2) to the coverage cells. */ -inline static void -cell_list_add_subspan(struct cell_list *cells, - grid_scaled_x_t x1, - grid_scaled_x_t x2) -{ - int ix1, fx1; - int ix2, fx2; - - if (x1 == x2) - return; - - GRID_X_TO_INT_FRAC(x1, ix1, fx1); - GRID_X_TO_INT_FRAC(x2, ix2, fx2); - - if (ix1 != ix2) { - struct cell_pair p; - p = cell_list_find_pair(cells, ix1, ix2); - p.cell1->uncovered_area += 2*fx1; - ++p.cell1->covered_height; - p.cell2->uncovered_area -= 2*fx2; - --p.cell2->covered_height; - } else { - struct cell *cell = cell_list_find(cells, ix1); - cell->uncovered_area += 2*(fx1-fx2); - } -} - -/* Adds the analytical coverage of an edge crossing the current pixel - * row to the coverage cells and advances the edge's x position to the - * following row. - * - * This function is only called when we know that during this pixel row: - * - * 1) The relative order of all edges on the active list doesn't - * change. In particular, no edges intersect within this row to pixel - * precision. - * - * 2) No new edges start in this row. - * - * 3) No existing edges end mid-row. - * - * This function depends on being called with all edges from the - * active list in the order they appear on the list (i.e. with - * non-decreasing x-coordinate.) */ -static void -cell_list_render_edge(struct cell_list *cells, - struct edge *edge, - int sign) -{ - grid_scaled_x_t fx; - struct cell *cell; - int ix; - - GRID_X_TO_INT_FRAC(edge->x.quo, ix, fx); - - /* We always know that ix1 is >= the cell list cursor in this - * case due to the no-intersections precondition. */ - cell = cell_list_find(cells, ix); - cell->covered_height += sign*GRID_Y; - cell->uncovered_area += sign*2*fx*GRID_Y; -} - -static void -polygon_init (struct polygon *polygon, jmp_buf *jmp) -{ - polygon->ymin = polygon->ymax = 0; - polygon->y_buckets = polygon->y_buckets_embedded; - pool_init (polygon->edge_pool.base, jmp, - 8192 - sizeof (struct _pool_chunk), - sizeof (polygon->edge_pool.embedded)); -} - -static void -polygon_fini (struct polygon *polygon) -{ - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - pool_fini (polygon->edge_pool.base); -} - -/* Empties the polygon of all edges. The polygon is then prepared to - * receive new edges and clip them to the vertical range - * [ymin,ymax). */ -static glitter_status_t -polygon_reset (struct polygon *polygon, - grid_scaled_y_t ymin, - grid_scaled_y_t ymax) -{ - unsigned h = ymax - ymin; - unsigned num_buckets = EDGE_Y_BUCKET_INDEX(ymax + GRID_Y-1, ymin); - - pool_reset(polygon->edge_pool.base); - - if (unlikely (h > 0x7FFFFFFFU - GRID_Y)) - goto bail_no_mem; /* even if you could, you wouldn't want to. */ - - if (polygon->y_buckets != polygon->y_buckets_embedded) - free (polygon->y_buckets); - - polygon->y_buckets = polygon->y_buckets_embedded; - if (num_buckets > ARRAY_LENGTH (polygon->y_buckets_embedded)) { - polygon->y_buckets = _cairo_malloc_ab (num_buckets, - sizeof (struct edge *)); - if (unlikely (NULL == polygon->y_buckets)) - goto bail_no_mem; - } - memset (polygon->y_buckets, 0, num_buckets * sizeof (struct edge *)); - - polygon->ymin = ymin; - polygon->ymax = ymax; - return GLITTER_STATUS_SUCCESS; - -bail_no_mem: - polygon->ymin = 0; - polygon->ymax = 0; - return GLITTER_STATUS_NO_MEMORY; -} - -static void -_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, - struct edge *e) -{ - unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin); - struct edge **ptail = &polygon->y_buckets[ix]; - e->next = *ptail; - *ptail = e; -} - -inline static void -polygon_add_edge (struct polygon *polygon, - const cairo_edge_t *edge) -{ - struct edge *e; - grid_scaled_x_t dx; - grid_scaled_y_t dy; - grid_scaled_y_t ytop, ybot; - grid_scaled_y_t ymin = polygon->ymin; - grid_scaled_y_t ymax = polygon->ymax; - - if (unlikely (edge->top >= ymax || edge->bottom <= ymin)) - return; - - e = pool_alloc (polygon->edge_pool.base, sizeof (struct edge)); - - dx = edge->line.p2.x - edge->line.p1.x; - dy = edge->line.p2.y - edge->line.p1.y; - e->dy = dy; - e->dir = edge->dir; - - ytop = edge->top >= ymin ? edge->top : ymin; - ybot = edge->bottom <= ymax ? edge->bottom : ymax; - e->ytop = ytop; - e->height_left = ybot - ytop; - - if (dx == 0) { - e->vertical = TRUE; - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - e->dxdy.quo = 0; - e->dxdy.rem = 0; - } else { - e->vertical = FALSE; - e->dxdy = floored_divrem (dx, dy); - if (ytop == edge->line.p1.y) { - e->x.quo = edge->line.p1.x; - e->x.rem = 0; - } else { - e->x = floored_muldivrem (ytop - edge->line.p1.y, dx, dy); - e->x.quo += edge->line.p1.x; - } - } - - _polygon_insert_edge_into_its_y_bucket (polygon, e); - - e->x.rem -= dy; /* Bias the remainder for faster - * edge advancement. */ -} - -static void -active_list_reset (struct active_list *active) -{ - active->head.vertical = 1; - active->head.height_left = INT_MAX; - active->head.x.quo = INT_MIN; - active->head.prev = NULL; - active->head.next = &active->tail; - active->tail.prev = &active->head; - active->tail.next = NULL; - active->tail.x.quo = INT_MAX; - active->tail.height_left = INT_MAX; - active->tail.vertical = 1; - active->min_height = 0; - active->is_vertical = 1; -} - -static void -active_list_init(struct active_list *active) -{ - active_list_reset(active); -} - -/* - * Merge two sorted edge lists. - * Input: - * - head_a: The head of the first list. - * - head_b: The head of the second list; head_b cannot be NULL. - * Output: - * Returns the head of the merged list. - * - * Implementation notes: - * To make it fast (in particular, to reduce to an insertion sort whenever - * one of the two input lists only has a single element) we iterate through - * a list until its head becomes greater than the head of the other list, - * then we switch their roles. As soon as one of the two lists is empty, we - * just attach the other one to the current list and exit. - * Writes to memory are only needed to "switch" lists (as it also requires - * attaching to the output list the list which we will be iterating next) and - * to attach the last non-empty list. - */ -static struct edge * -merge_sorted_edges (struct edge *head_a, struct edge *head_b) -{ - struct edge *head, **next, *prev; - int32_t x; - - prev = head_a->prev; - next = &head; - if (head_a->x.quo <= head_b->x.quo) { - head = head_a; - } else { - head = head_b; - head_b->prev = prev; - goto start_with_b; - } - - do { - x = head_b->x.quo; - while (head_a != NULL && head_a->x.quo <= x) { - prev = head_a; - next = &head_a->next; - head_a = head_a->next; - } - - head_b->prev = prev; - *next = head_b; - if (head_a == NULL) - return head; - -start_with_b: - x = head_a->x.quo; - while (head_b != NULL && head_b->x.quo <= x) { - prev = head_b; - next = &head_b->next; - head_b = head_b->next; - } - - head_a->prev = prev; - *next = head_a; - if (head_b == NULL) - return head; - } while (1); -} - -/* - * Sort (part of) a list. - * Input: - * - list: The list to be sorted; list cannot be NULL. - * - limit: Recursion limit. - * Output: - * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the - * input list; if the input list has fewer elements, head_out be a sorted list - * containing all the elements of the input list. - * Returns the head of the list of unprocessed elements (NULL if the sorted list contains - * all the elements of the input list). - * - * Implementation notes: - * Special case single element list, unroll/inline the sorting of the first two elements. - * Some tail recursion is used since we iterate on the bottom-up solution of the problem - * (we start with a small sorted list and keep merging other lists of the same size to it). - */ -static struct edge * -sort_edges (struct edge *list, - unsigned int level, - struct edge **head_out) -{ - struct edge *head_other, *remaining; - unsigned int i; - - head_other = list->next; - - if (head_other == NULL) { - *head_out = list; - return NULL; - } - - remaining = head_other->next; - if (list->x.quo <= head_other->x.quo) { - *head_out = list; - head_other->next = NULL; - } else { - *head_out = head_other; - head_other->prev = list->prev; - head_other->next = list; - list->prev = head_other; - list->next = NULL; - } - - for (i = 0; i < level && remaining; i++) { - remaining = sort_edges (remaining, i, &head_other); - *head_out = merge_sorted_edges (*head_out, head_other); - } - - return remaining; -} - -static struct edge * -merge_unsorted_edges (struct edge *head, struct edge *unsorted) -{ - sort_edges (unsorted, UINT_MAX, &unsorted); - return merge_sorted_edges (head, unsorted); -} - -/* Test if the edges on the active list can be safely advanced by a - * full row without intersections or any edges ending. */ -inline static int -can_do_full_row (struct active_list *active) -{ - const struct edge *e; - - /* Recomputes the minimum height of all edges on the active - * list if we have been dropping edges. */ - if (active->min_height <= 0) { - int min_height = INT_MAX; - int is_vertical = 1; - - e = active->head.next; - while (NULL != e) { - if (e->height_left < min_height) - min_height = e->height_left; - is_vertical &= e->vertical; - e = e->next; - } - - active->is_vertical = is_vertical; - active->min_height = min_height; - } - - if (active->min_height < GRID_Y) - return 0; - - return active->is_vertical; -} - -/* Merges edges on the given subpixel row from the polygon to the - * active_list. */ -inline static void -active_list_merge_edges_from_bucket(struct active_list *active, - struct edge *edges) -{ - active->head.next = merge_unsorted_edges (active->head.next, edges); -} - -inline static void -polygon_fill_buckets (struct active_list *active, - struct edge *edge, - int y, - struct edge **buckets) -{ - grid_scaled_y_t min_height = active->min_height; - int is_vertical = active->is_vertical; - - while (edge) { - struct edge *next = edge->next; - int suby = edge->ytop - y; - if (buckets[suby]) - buckets[suby]->prev = edge; - edge->next = buckets[suby]; - edge->prev = NULL; - buckets[suby] = edge; - if (edge->height_left < min_height) - min_height = edge->height_left; - is_vertical &= edge->vertical; - edge = next; - } - - active->is_vertical = is_vertical; - active->min_height = min_height; -} - -inline static void -sub_row (struct active_list *active, - struct cell_list *coverages, - unsigned int mask) -{ - struct edge *edge = active->head.next; - int xstart = INT_MIN, prev_x = INT_MIN; - int winding = 0; - - cell_list_rewind (coverages); - - while (&active->tail != edge) { - struct edge *next = edge->next; - int xend = edge->x.quo; - - if (--edge->height_left) { - edge->x.quo += edge->dxdy.quo; - edge->x.rem += edge->dxdy.rem; - if (edge->x.rem >= 0) { - ++edge->x.quo; - edge->x.rem -= edge->dy; - } - - if (edge->x.quo < prev_x) { - struct edge *pos = edge->prev; - pos->next = next; - next->prev = pos; - do { - pos = pos->prev; - } while (edge->x.quo < pos->x.quo); - pos->next->prev = edge; - edge->next = pos->next; - edge->prev = pos; - pos->next = edge; - } else - prev_x = edge->x.quo; - } else { - edge->prev->next = next; - next->prev = edge->prev; - } - - winding += edge->dir; - if ((winding & mask) == 0) { - if (next->x.quo != xend) { - cell_list_add_subspan (coverages, xstart, xend); - xstart = INT_MIN; - } - } else if (xstart == INT_MIN) - xstart = xend; - - edge = next; - } -} - -inline static void dec (struct edge *e, int h) -{ - e->height_left -= h; - if (e->height_left == 0) { - e->prev->next = e->next; - e->next->prev = e->prev; - } -} - -static void -full_row (struct active_list *active, - struct cell_list *coverages, - unsigned int mask) -{ - struct edge *left = active->head.next; - - while (&active->tail != left) { - struct edge *right; - int winding; - - dec (left, GRID_Y); - - winding = left->dir; - right = left->next; - do { - dec (right, GRID_Y); - - winding += right->dir; - if ((winding & mask) == 0 && right->next->x.quo != right->x.quo) - break; - - right = right->next; - } while (1); - - cell_list_set_rewind (coverages); - cell_list_render_edge (coverages, left, +1); - cell_list_render_edge (coverages, right, -1); - - left = right->next; - } -} - -static void -_glitter_scan_converter_init(glitter_scan_converter_t *converter, jmp_buf *jmp) -{ - polygon_init(converter->polygon, jmp); - active_list_init(converter->active); - cell_list_init(converter->coverages, jmp); - converter->xmin=0; - converter->ymin=0; - converter->xmax=0; - converter->ymax=0; -} - -static void -_glitter_scan_converter_fini(glitter_scan_converter_t *self) -{ - if (self->spans != self->spans_embedded) - free (self->spans); - - polygon_fini(self->polygon); - cell_list_fini(self->coverages); - - self->xmin=0; - self->ymin=0; - self->xmax=0; - self->ymax=0; -} - -static grid_scaled_t -int_to_grid_scaled(int i, int scale) -{ - /* Clamp to max/min representable scaled number. */ - if (i >= 0) { - if (i >= INT_MAX/scale) - i = INT_MAX/scale; - } - else { - if (i <= INT_MIN/scale) - i = INT_MIN/scale; - } - return i*scale; -} - -#define int_to_grid_scaled_x(x) int_to_grid_scaled((x), GRID_X) -#define int_to_grid_scaled_y(x) int_to_grid_scaled((x), GRID_Y) - -I glitter_status_t -glitter_scan_converter_reset( - glitter_scan_converter_t *converter, - int xmin, int ymin, - int xmax, int ymax) -{ - glitter_status_t status; - - converter->xmin = 0; converter->xmax = 0; - converter->ymin = 0; converter->ymax = 0; - - if (xmax - xmin > ARRAY_LENGTH(converter->spans_embedded)) { - converter->spans = _cairo_malloc_ab (xmax - xmin, - sizeof (cairo_half_open_span_t)); - if (unlikely (converter->spans == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } else - converter->spans = converter->spans_embedded; - - xmin = int_to_grid_scaled_x(xmin); - ymin = int_to_grid_scaled_y(ymin); - xmax = int_to_grid_scaled_x(xmax); - ymax = int_to_grid_scaled_y(ymax); - - active_list_reset(converter->active); - cell_list_reset(converter->coverages); - status = polygon_reset(converter->polygon, ymin, ymax); - if (status) - return status; - - converter->xmin = xmin; - converter->xmax = xmax; - converter->ymin = ymin; - converter->ymax = ymax; - return GLITTER_STATUS_SUCCESS; -} - -/* INPUT_TO_GRID_X/Y (in_coord, out_grid_scaled, grid_scale) - * These macros convert an input coordinate in the client's - * device space to the rasterisation grid. - */ -/* Gah.. this bit of ugly defines INPUT_TO_GRID_X/Y so as to use - * shifts if possible, and something saneish if not. - */ -#if !defined(INPUT_TO_GRID_Y) && defined(GRID_Y_BITS) && GRID_Y_BITS <= GLITTER_INPUT_BITS -# define INPUT_TO_GRID_Y(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_Y_BITS) -#else -# define INPUT_TO_GRID_Y(in, out) INPUT_TO_GRID_general(in, out, GRID_Y) -#endif - -#if !defined(INPUT_TO_GRID_X) && defined(GRID_X_BITS) && GRID_X_BITS <= GLITTER_INPUT_BITS -# define INPUT_TO_GRID_X(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_X_BITS) -#else -# define INPUT_TO_GRID_X(in, out) INPUT_TO_GRID_general(in, out, GRID_X) -#endif - -#define INPUT_TO_GRID_general(in, out, grid_scale) do { \ - long long tmp__ = (long long)(grid_scale) * (in); \ - tmp__ >>= GLITTER_INPUT_BITS; \ - (out) = tmp__; \ -} while (0) - -/* Add a new polygon edge from pixel (x1,y1) to (x2,y2) to the scan - * converter. The coordinates represent pixel positions scaled by - * 2**GLITTER_PIXEL_BITS. If this function fails then the scan - * converter should be reset or destroyed. Dir must be +1 or -1, - * with the latter reversing the orientation of the edge. */ -I void -glitter_scan_converter_add_edge (glitter_scan_converter_t *converter, - const cairo_edge_t *edge) -{ - cairo_edge_t e; - - INPUT_TO_GRID_Y (edge->top, e.top); - INPUT_TO_GRID_Y (edge->bottom, e.bottom); - if (e.top >= e.bottom) - return; - - /* XXX: possible overflows if GRID_X/Y > 2**GLITTER_INPUT_BITS */ - INPUT_TO_GRID_Y (edge->line.p1.y, e.line.p1.y); - INPUT_TO_GRID_Y (edge->line.p2.y, e.line.p2.y); - if (e.line.p1.y == e.line.p2.y) - e.line.p2.y++; /* Fudge to prevent div-by-zero */ - - INPUT_TO_GRID_X (edge->line.p1.x, e.line.p1.x); - INPUT_TO_GRID_X (edge->line.p2.x, e.line.p2.x); - - e.dir = edge->dir; - - polygon_add_edge (converter->polygon, &e); -} - -static void -step_edges (struct active_list *active, int count) -{ - struct edge *edge; - - count *= GRID_Y; - for (edge = active->head.next; edge != &active->tail; edge = edge->next) { - edge->height_left -= count; - if (! edge->height_left) { - edge->prev->next = edge->next; - edge->next->prev = edge->prev; - } - } -} - -static glitter_status_t -blit_a8 (struct cell_list *cells, - cairo_span_renderer_t *renderer, - cairo_half_open_span_t *spans, - int y, int height, - int xmin, int xmax) -{ - struct cell *cell = cells->head.next; - int prev_x = xmin, last_x = -1; - int16_t cover = 0, last_cover = 0; - unsigned num_spans; - - if (cell == &cells->tail) - return CAIRO_STATUS_SUCCESS; - - /* Skip cells to the left of the clip region. */ - while (cell->x < xmin) { - cover += cell->covered_height; - cell = cell->next; - } - cover *= GRID_X*2; - - /* Form the spans from the coverages and areas. */ - num_spans = 0; - for (; cell->x < xmax; cell = cell->next) { - int x = cell->x; - int16_t area; - - if (x > prev_x && cover != last_cover) { - spans[num_spans].x = prev_x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); - last_cover = cover; - last_x = prev_x; - ++num_spans; - } - - cover += cell->covered_height*GRID_X*2; - area = cover - cell->uncovered_area; - - if (area != last_cover) { - spans[num_spans].x = x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (area); - last_cover = area; - last_x = x; - ++num_spans; - } - - prev_x = x+1; - } - - if (prev_x <= xmax && cover != last_cover) { - spans[num_spans].x = prev_x; - spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); - last_cover = cover; - last_x = prev_x; - ++num_spans; - } - - if (last_x < xmax && last_cover) { - spans[num_spans].x = xmax; - spans[num_spans].coverage = 0; - ++num_spans; - } - - /* Dump them into the renderer. */ - return renderer->render_rows (renderer, y, height, spans, num_spans); -} - -#define GRID_AREA_TO_A1(A) ((GRID_AREA_TO_ALPHA (A) > 127) ? 255 : 0) -static glitter_status_t -blit_a1 (struct cell_list *cells, - cairo_span_renderer_t *renderer, - cairo_half_open_span_t *spans, - int y, int height, - int xmin, int xmax) -{ - struct cell *cell = cells->head.next; - int prev_x = xmin, last_x = -1; - int16_t cover = 0; - uint8_t coverage, last_cover = 0; - unsigned num_spans; - - if (cell == &cells->tail) - return CAIRO_STATUS_SUCCESS; - - /* Skip cells to the left of the clip region. */ - while (cell->x < xmin) { - cover += cell->covered_height; - cell = cell->next; - } - cover *= GRID_X*2; - - /* Form the spans from the coverages and areas. */ - num_spans = 0; - for (; cell->x < xmax; cell = cell->next) { - int x = cell->x; - int16_t area; - - coverage = GRID_AREA_TO_A1 (cover); - if (x > prev_x && coverage != last_cover) { - last_x = spans[num_spans].x = prev_x; - last_cover = spans[num_spans].coverage = coverage; - ++num_spans; - } - - cover += cell->covered_height*GRID_X*2; - area = cover - cell->uncovered_area; - - coverage = GRID_AREA_TO_A1 (area); - if (coverage != last_cover) { - last_x = spans[num_spans].x = x; - last_cover = spans[num_spans].coverage = coverage; - ++num_spans; - } - - prev_x = x+1; - } - - coverage = GRID_AREA_TO_A1 (cover); - if (prev_x <= xmax && coverage != last_cover) { - last_x = spans[num_spans].x = prev_x; - last_cover = spans[num_spans].coverage = coverage; - ++num_spans; - } - - if (last_x < xmax && last_cover) { - spans[num_spans].x = xmax; - spans[num_spans].coverage = 0; - ++num_spans; - } - if (num_spans == 1) - return CAIRO_STATUS_SUCCESS; - - /* Dump them into the renderer. */ - return renderer->render_rows (renderer, y, height, spans, num_spans); -} - - -I void -glitter_scan_converter_render(glitter_scan_converter_t *converter, - unsigned int winding_mask, - int antialias, - cairo_span_renderer_t *renderer) -{ - int i, j; - int ymax_i = converter->ymax / GRID_Y; - int ymin_i = converter->ymin / GRID_Y; - int xmin_i, xmax_i; - int h = ymax_i - ymin_i; - struct polygon *polygon = converter->polygon; - struct cell_list *coverages = converter->coverages; - struct active_list *active = converter->active; - struct edge *buckets[GRID_Y] = { 0 }; - - xmin_i = converter->xmin / GRID_X; - xmax_i = converter->xmax / GRID_X; - if (xmin_i >= xmax_i) - return; - - /* Render each pixel row. */ - for (i = 0; i < h; i = j) { - int do_full_row = 0; - - j = i + 1; - - /* Determine if we can ignore this row or use the full pixel - * stepper. */ - if (! polygon->y_buckets[i]) { - if (active->head.next == &active->tail) { - active->min_height = INT_MAX; - active->is_vertical = 1; - for (; j < h && ! polygon->y_buckets[j]; j++) - ; - continue; - } - - do_full_row = can_do_full_row (active); - } - - if (do_full_row) { - /* Step by a full pixel row's worth. */ - full_row (active, coverages, winding_mask); - - if (active->is_vertical) { - while (j < h && - polygon->y_buckets[j] == NULL && - active->min_height >= 2*GRID_Y) - { - active->min_height -= GRID_Y; - j++; - } - if (j != i + 1) - step_edges (active, j - (i + 1)); - } - } else { - int sub; - - polygon_fill_buckets (active, - polygon->y_buckets[i], - (i+ymin_i)*GRID_Y, - buckets); - - /* Subsample this row. */ - for (sub = 0; sub < GRID_Y; sub++) { - if (buckets[sub]) { - active_list_merge_edges_from_bucket (active, buckets[sub]); - buckets[sub] = NULL; - } - - sub_row (active, coverages, winding_mask); - } - } - - if (antialias) - blit_a8 (coverages, renderer, converter->spans, - i+ymin_i, j-i, xmin_i, xmax_i); - else - blit_a1 (coverages, renderer, converter->spans, - i+ymin_i, j-i, xmin_i, xmax_i); - cell_list_reset (coverages); - - active->min_height -= GRID_Y; - } -} - -struct _cairo_tor22_scan_converter { - cairo_scan_converter_t base; - - glitter_scan_converter_t converter[1]; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - - jmp_buf jmp; -}; - -typedef struct _cairo_tor22_scan_converter cairo_tor22_scan_converter_t; - -static void -_cairo_tor22_scan_converter_destroy (void *converter) -{ - cairo_tor22_scan_converter_t *self = converter; - if (self == NULL) { - return; - } - _glitter_scan_converter_fini (self->converter); - free(self); -} - -cairo_status_t -_cairo_tor22_scan_converter_add_polygon (void *converter, - const cairo_polygon_t *polygon) -{ - cairo_tor22_scan_converter_t *self = converter; - int i; - -#if 0 - FILE *file = fopen ("polygon.txt", "w"); - _cairo_debug_print_polygon (file, polygon); - fclose (file); -#endif - - for (i = 0; i < polygon->num_edges; i++) - glitter_scan_converter_add_edge (self->converter, &polygon->edges[i]); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_tor22_scan_converter_generate (void *converter, - cairo_span_renderer_t *renderer) -{ - cairo_tor22_scan_converter_t *self = converter; - cairo_status_t status; - - if ((status = setjmp (self->jmp))) - return _cairo_scan_converter_set_error (self, _cairo_error (status)); - - glitter_scan_converter_render (self->converter, - self->fill_rule == CAIRO_FILL_RULE_WINDING ? ~0 : 1, - self->antialias != CAIRO_ANTIALIAS_NONE, - renderer); - return CAIRO_STATUS_SUCCESS; -} - -cairo_scan_converter_t * -_cairo_tor22_scan_converter_create (int xmin, - int ymin, - int xmax, - int ymax, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias) -{ - cairo_tor22_scan_converter_t *self; - cairo_status_t status; - - self = malloc (sizeof(struct _cairo_tor22_scan_converter)); - if (unlikely (self == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto bail_nomem; - } - - self->base.destroy = _cairo_tor22_scan_converter_destroy; - self->base.generate = _cairo_tor22_scan_converter_generate; - - _glitter_scan_converter_init (self->converter, &self->jmp); - status = glitter_scan_converter_reset (self->converter, - xmin, ymin, xmax, ymax); - if (unlikely (status)) - goto bail; - - self->fill_rule = fill_rule; - self->antialias = antialias; - - return &self->base; - - bail: - self->base.destroy(&self->base); - bail_nomem: - return _cairo_scan_converter_create_in_error (status); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-toy-font-face.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-toy-font-face.c deleted file mode 100644 index 4fe94ab0919..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-toy-font-face.c +++ /dev/null @@ -1,524 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005,2008 Red Hat Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Graydon Hoare - * Owen Taylor - * Behdad Esfahbod - */ - -#define _BSD_SOURCE /* for strdup() */ -#include "cairoint.h" -#include "cairo-error-private.h" - - -static const cairo_font_face_t _cairo_font_face_null_pointer = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_NULL_POINTER, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_invalid_string = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_INVALID_STRING, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_invalid_slant = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_INVALID_SLANT, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_invalid_weight = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_INVALID_WEIGHT, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - - -static const cairo_font_face_backend_t _cairo_toy_font_face_backend; - -static int -_cairo_toy_font_face_keys_equal (const void *key_a, - const void *key_b); - -/* We maintain a hash table from family/weight/slant => - * #cairo_font_face_t for #cairo_toy_font_t. The primary purpose of - * this mapping is to provide unique #cairo_font_face_t values so that - * our cache and mapping from #cairo_font_face_t => #cairo_scaled_font_t - * works. Once the corresponding #cairo_font_face_t objects fall out of - * downstream caches, we don't need them in this hash table anymore. - * - * Modifications to this hash table are protected by - * _cairo_toy_font_face_mutex. - */ -static cairo_hash_table_t *cairo_toy_font_face_hash_table = NULL; - -static cairo_hash_table_t * -_cairo_toy_font_face_hash_table_lock (void) -{ - CAIRO_MUTEX_LOCK (_cairo_toy_font_face_mutex); - - if (cairo_toy_font_face_hash_table == NULL) - { - cairo_toy_font_face_hash_table = - _cairo_hash_table_create (_cairo_toy_font_face_keys_equal); - - if (cairo_toy_font_face_hash_table == NULL) { - CAIRO_MUTEX_UNLOCK (_cairo_toy_font_face_mutex); - return NULL; - } - } - - return cairo_toy_font_face_hash_table; -} - -static void -_cairo_toy_font_face_hash_table_unlock (void) -{ - CAIRO_MUTEX_UNLOCK (_cairo_toy_font_face_mutex); -} - -/** - * _cairo_toy_font_face_init_key: - * - * Initialize those portions of #cairo_toy_font_face_t needed to use - * it as a hash table key, including the hash code buried away in - * font_face->base.hash_entry. No memory allocation is performed here - * so that no fini call is needed. We do this to make it easier to use - * an automatic #cairo_toy_font_face_t variable as a key. - **/ -static void -_cairo_toy_font_face_init_key (cairo_toy_font_face_t *key, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) -{ - unsigned long hash; - - key->family = family; - key->owns_family = FALSE; - - key->slant = slant; - key->weight = weight; - - /* 1607 and 1451 are just a couple of arbitrary primes. */ - hash = _cairo_hash_string (family); - hash += ((unsigned long) slant) * 1607; - hash += ((unsigned long) weight) * 1451; - - key->base.hash_entry.hash = hash; -} - -static cairo_status_t -_cairo_toy_font_face_create_impl_face (cairo_toy_font_face_t *font_face, - cairo_font_face_t **impl_font_face) -{ - const cairo_font_face_backend_t * backend = CAIRO_FONT_FACE_BACKEND_DEFAULT; - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - if (unlikely (font_face->base.status)) - return font_face->base.status; - - if (backend->create_for_toy != NULL && - 0 != strncmp (font_face->family, CAIRO_USER_FONT_FAMILY_DEFAULT, - strlen (CAIRO_USER_FONT_FAMILY_DEFAULT))) - { - status = backend->create_for_toy (font_face, impl_font_face); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - backend = &_cairo_user_font_face_backend; - status = backend->create_for_toy (font_face, impl_font_face); - } - - return status; -} - -static cairo_status_t -_cairo_toy_font_face_init (cairo_toy_font_face_t *font_face, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) -{ - char *family_copy; - cairo_status_t status; - - family_copy = strdup (family); - if (unlikely (family_copy == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_toy_font_face_init_key (font_face, family_copy, slant, weight); - font_face->owns_family = TRUE; - - _cairo_font_face_init (&font_face->base, &_cairo_toy_font_face_backend); - - status = _cairo_toy_font_face_create_impl_face (font_face, - &font_face->impl_face); - if (unlikely (status)) { - free (family_copy); - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_toy_font_face_fini (cairo_toy_font_face_t *font_face) -{ - /* We assert here that we own font_face->family before casting - * away the const qualifer. */ - assert (font_face->owns_family); - free ((char*) font_face->family); - - if (font_face->impl_face) - cairo_font_face_destroy (font_face->impl_face); -} - -static int -_cairo_toy_font_face_keys_equal (const void *key_a, - const void *key_b) -{ - const cairo_toy_font_face_t *face_a = key_a; - const cairo_toy_font_face_t *face_b = key_b; - - return (strcmp (face_a->family, face_b->family) == 0 && - face_a->slant == face_b->slant && - face_a->weight == face_b->weight); -} - -/** - * cairo_toy_font_face_create: - * @family: a font family name, encoded in UTF-8 - * @slant: the slant for the font - * @weight: the weight for the font - * - * Creates a font face from a triplet of family, slant, and weight. - * These font faces are used in implementation of the the #cairo_t "toy" - * font API. - * - * If @family is the zero-length string "", the platform-specific default - * family is assumed. The default family then can be queried using - * cairo_toy_font_face_get_family(). - * - * The cairo_select_font_face() function uses this to create font faces. - * See that function for limitations and other details of toy font faces. - * - * Return value: a newly created #cairo_font_face_t. Free with - * cairo_font_face_destroy() when you are done using it. - * - * Since: 1.8 - **/ -cairo_font_face_t * -cairo_toy_font_face_create (const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) -{ - cairo_status_t status; - cairo_toy_font_face_t key, *font_face; - cairo_hash_table_t *hash_table; - - if (family == NULL) - return (cairo_font_face_t*) &_cairo_font_face_null_pointer; - - /* Make sure we've got valid UTF-8 for the family */ - status = _cairo_utf8_to_ucs4 (family, -1, NULL, NULL); - if (unlikely (status)) { - if (status == CAIRO_STATUS_INVALID_STRING) - return (cairo_font_face_t*) &_cairo_font_face_invalid_string; - - return (cairo_font_face_t*) &_cairo_font_face_nil; - } - - switch (slant) { - case CAIRO_FONT_SLANT_NORMAL: - case CAIRO_FONT_SLANT_ITALIC: - case CAIRO_FONT_SLANT_OBLIQUE: - break; - default: - return (cairo_font_face_t*) &_cairo_font_face_invalid_slant; - } - - switch (weight) { - case CAIRO_FONT_WEIGHT_NORMAL: - case CAIRO_FONT_WEIGHT_BOLD: - break; - default: - return (cairo_font_face_t*) &_cairo_font_face_invalid_weight; - } - - if (*family == '\0') - family = CAIRO_FONT_FAMILY_DEFAULT; - - hash_table = _cairo_toy_font_face_hash_table_lock (); - if (unlikely (hash_table == NULL)) - goto UNWIND; - - _cairo_toy_font_face_init_key (&key, family, slant, weight); - - /* Return existing font_face if it exists in the hash table. */ - font_face = _cairo_hash_table_lookup (hash_table, - &key.base.hash_entry); - if (font_face != NULL) { - if (font_face->base.status == CAIRO_STATUS_SUCCESS) { - cairo_font_face_reference (&font_face->base); - _cairo_toy_font_face_hash_table_unlock (); - return &font_face->base; - } - - /* remove the bad font from the hash table */ - _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); - } - - /* Otherwise create it and insert into hash table. */ - font_face = malloc (sizeof (cairo_toy_font_face_t)); - if (unlikely (font_face == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto UNWIND_HASH_TABLE_LOCK; - } - - status = _cairo_toy_font_face_init (font_face, family, slant, weight); - if (unlikely (status)) - goto UNWIND_FONT_FACE_MALLOC; - - assert (font_face->base.hash_entry.hash == key.base.hash_entry.hash); - status = _cairo_hash_table_insert (hash_table, &font_face->base.hash_entry); - if (unlikely (status)) - goto UNWIND_FONT_FACE_INIT; - - _cairo_toy_font_face_hash_table_unlock (); - - return &font_face->base; - - UNWIND_FONT_FACE_INIT: - _cairo_toy_font_face_fini (font_face); - UNWIND_FONT_FACE_MALLOC: - free (font_face); - UNWIND_HASH_TABLE_LOCK: - _cairo_toy_font_face_hash_table_unlock (); - UNWIND: - return (cairo_font_face_t*) &_cairo_font_face_nil; -} -slim_hidden_def (cairo_toy_font_face_create); - -static cairo_bool_t -_cairo_toy_font_face_destroy (void *abstract_face) -{ - cairo_toy_font_face_t *font_face = abstract_face; - cairo_hash_table_t *hash_table; - - hash_table = _cairo_toy_font_face_hash_table_lock (); - /* All created objects must have been mapped in the hash table. */ - assert (hash_table != NULL); - - if (! _cairo_reference_count_dec_and_test (&font_face->base.ref_count)) { - /* somebody recreated the font whilst we waited for the lock */ - _cairo_toy_font_face_hash_table_unlock (); - return FALSE; - } - - /* Font faces in SUCCESS status are guaranteed to be in the - * hashtable. Font faces in an error status are removed from the - * hashtable if they are found during a lookup, thus they should - * only be removed if they are in the hashtable. */ - if (likely (font_face->base.status == CAIRO_STATUS_SUCCESS) || - _cairo_hash_table_lookup (hash_table, &font_face->base.hash_entry) == font_face) - _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); - - _cairo_toy_font_face_hash_table_unlock (); - - _cairo_toy_font_face_fini (font_face); - return TRUE; -} - -static cairo_status_t -_cairo_toy_font_face_scaled_font_create (void *abstract_font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - cairo_scaled_font_t **scaled_font) -{ - cairo_toy_font_face_t *font_face = (cairo_toy_font_face_t *) abstract_font_face; - - ASSERT_NOT_REACHED; - - return _cairo_font_face_set_error (&font_face->base, CAIRO_STATUS_FONT_TYPE_MISMATCH); -} - -static cairo_font_face_t * -_cairo_toy_font_face_get_implementation (void *abstract_font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options) -{ - cairo_toy_font_face_t *font_face = abstract_font_face; - - if (font_face->impl_face) { - cairo_font_face_t *impl = font_face->impl_face; - - if (impl->backend->get_implementation != NULL) { - return impl->backend->get_implementation (impl, - font_matrix, - ctm, - options); - } - - return cairo_font_face_reference (impl); - } - - return abstract_font_face; -} - -static cairo_bool_t -_cairo_font_face_is_toy (cairo_font_face_t *font_face) -{ - return font_face->backend == &_cairo_toy_font_face_backend; -} - -/** - * cairo_toy_font_face_get_family: - * @font_face: A toy font face - * - * Gets the familly name of a toy font. - * - * Return value: The family name. This string is owned by the font face - * and remains valid as long as the font face is alive (referenced). - * - * Since: 1.8 - **/ -const char * -cairo_toy_font_face_get_family (cairo_font_face_t *font_face) -{ - cairo_toy_font_face_t *toy_font_face; - - if (font_face->status) - return CAIRO_FONT_FAMILY_DEFAULT; - - toy_font_face = (cairo_toy_font_face_t *) font_face; - if (! _cairo_font_face_is_toy (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return CAIRO_FONT_FAMILY_DEFAULT; - } - assert (toy_font_face->owns_family); - return toy_font_face->family; -} - -/** - * cairo_toy_font_face_get_slant: - * @font_face: A toy font face - * - * Gets the slant a toy font. - * - * Return value: The slant value - * - * Since: 1.8 - **/ -cairo_font_slant_t -cairo_toy_font_face_get_slant (cairo_font_face_t *font_face) -{ - cairo_toy_font_face_t *toy_font_face; - - if (font_face->status) - return CAIRO_FONT_SLANT_DEFAULT; - - toy_font_face = (cairo_toy_font_face_t *) font_face; - if (! _cairo_font_face_is_toy (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return CAIRO_FONT_SLANT_DEFAULT; - } - return toy_font_face->slant; -} -slim_hidden_def (cairo_toy_font_face_get_slant); - -/** - * cairo_toy_font_face_get_weight: - * @font_face: A toy font face - * - * Gets the weight a toy font. - * - * Return value: The weight value - * - * Since: 1.8 - **/ -cairo_font_weight_t -cairo_toy_font_face_get_weight (cairo_font_face_t *font_face) -{ - cairo_toy_font_face_t *toy_font_face; - - if (font_face->status) - return CAIRO_FONT_WEIGHT_DEFAULT; - - toy_font_face = (cairo_toy_font_face_t *) font_face; - if (! _cairo_font_face_is_toy (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return CAIRO_FONT_WEIGHT_DEFAULT; - } - return toy_font_face->weight; -} -slim_hidden_def (cairo_toy_font_face_get_weight); - -static const cairo_font_face_backend_t _cairo_toy_font_face_backend = { - CAIRO_FONT_TYPE_TOY, - NULL, /* create_for_toy */ - _cairo_toy_font_face_destroy, - _cairo_toy_font_face_scaled_font_create, - _cairo_toy_font_face_get_implementation -}; - -void -_cairo_toy_font_face_reset_static_data (void) -{ - cairo_hash_table_t *hash_table; - - /* We manually acquire the lock rather than calling - * cairo_toy_font_face_hash_table_lock simply to avoid - * creating the table only to destroy it again. */ - CAIRO_MUTEX_LOCK (_cairo_toy_font_face_mutex); - hash_table = cairo_toy_font_face_hash_table; - cairo_toy_font_face_hash_table = NULL; - CAIRO_MUTEX_UNLOCK (_cairo_toy_font_face_mutex); - - if (hash_table != NULL) - _cairo_hash_table_destroy (hash_table); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-compositor.c deleted file mode 100644 index 3414fc2684a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-compositor.c +++ /dev/null @@ -1,2351 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-pattern-inline.h" -#include "cairo-paginated-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-surface-subsurface-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-observer-private.h" -#include "cairo-region-private.h" -#include "cairo-spans-private.h" -#include "cairo-traps-private.h" -#include "cairo-tristrip-private.h" - -typedef cairo_int_status_t -(*draw_func_t) (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip); - -static void do_unaligned_row(void (*blt)(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage), - void *closure, - const cairo_box_t *b, - int tx, int y, int h, - uint16_t coverage) -{ - int x1 = _cairo_fixed_integer_part (b->p1.x) - tx; - int x2 = _cairo_fixed_integer_part (b->p2.x) - tx; - if (x2 > x1) { - if (! _cairo_fixed_is_integer (b->p1.x)) { - blt(closure, x1, y, 1, h, - coverage * (256 - _cairo_fixed_fractional_part (b->p1.x))); - x1++; - } - - if (x2 > x1) - blt(closure, x1, y, x2-x1, h, (coverage << 8) - (coverage >> 8)); - - if (! _cairo_fixed_is_integer (b->p2.x)) - blt(closure, x2, y, 1, h, - coverage * _cairo_fixed_fractional_part (b->p2.x)); - } else - blt(closure, x1, y, 1, h, - coverage * (b->p2.x - b->p1.x)); -} - -static void do_unaligned_box(void (*blt)(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage), - void *closure, - const cairo_box_t *b, int tx, int ty) -{ - int y1 = _cairo_fixed_integer_part (b->p1.y) - ty; - int y2 = _cairo_fixed_integer_part (b->p2.y) - ty; - if (y2 > y1) { - if (! _cairo_fixed_is_integer (b->p1.y)) { - do_unaligned_row(blt, closure, b, tx, y1, 1, - 256 - _cairo_fixed_fractional_part (b->p1.y)); - y1++; - } - - if (y2 > y1) - do_unaligned_row(blt, closure, b, tx, y1, y2-y1, 256); - - if (! _cairo_fixed_is_integer (b->p2.y)) - do_unaligned_row(blt, closure, b, tx, y2, 1, - _cairo_fixed_fractional_part (b->p2.y)); - } else - do_unaligned_row(blt, closure, b, tx, y1, 1, - b->p2.y - b->p1.y); -} - -struct blt_in { - const cairo_traps_compositor_t *compositor; - cairo_surface_t *dst; - cairo_boxes_t boxes; -}; - -static void blt_in(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct blt_in *info = closure; - cairo_color_t color; - - if (CAIRO_ALPHA_SHORT_IS_OPAQUE (coverage)) - return; - - _cairo_box_from_integers (&info->boxes.chunks.base[0], x, y, w, h); - - _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double) 0xffff); - info->compositor->fill_boxes (info->dst, - CAIRO_OPERATOR_IN, &color, - &info->boxes); -} - -static void -add_rect_with_offset (cairo_boxes_t *boxes, int x1, int y1, int x2, int y2, int dx, int dy) -{ - cairo_box_t box; - cairo_int_status_t status; - - box.p1.x = _cairo_fixed_from_int (x1 - dx); - box.p1.y = _cairo_fixed_from_int (y1 - dy); - box.p2.x = _cairo_fixed_from_int (x2 - dx); - box.p2.y = _cairo_fixed_from_int (y2 - dy); - - status = _cairo_boxes_add (boxes, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_INT_STATUS_SUCCESS); -} - -static cairo_int_status_t -combine_clip_as_traps (const cairo_traps_compositor_t *compositor, - cairo_surface_t *mask, - const cairo_clip_t *clip, - const cairo_rectangle_int_t *extents) -{ - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - cairo_traps_t traps; - cairo_surface_t *src; - cairo_box_t box; - cairo_rectangle_int_t fixup; - int src_x, src_y; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = _cairo_clip_get_polygon (clip, &polygon, - &fill_rule, &antialias); - if (status) - return status; - - _cairo_traps_init (&traps); - status = _cairo_bentley_ottmann_tessellate_polygon (&traps, - &polygon, - fill_rule); - _cairo_polygon_fini (&polygon); - if (unlikely (status)) - return status; - - src = compositor->pattern_to_surface (mask, NULL, FALSE, - extents, NULL, - &src_x, &src_y); - if (unlikely (src->status)) { - _cairo_traps_fini (&traps); - return src->status; - } - - status = compositor->composite_traps (mask, CAIRO_OPERATOR_IN, src, - src_x, src_y, - extents->x, extents->y, - extents, - antialias, &traps); - - _cairo_traps_extents (&traps, &box); - _cairo_box_round_to_rectangle (&box, &fixup); - _cairo_traps_fini (&traps); - cairo_surface_destroy (src); - - if (unlikely (status)) - return status; - - if (! _cairo_rectangle_intersect (&fixup, extents)) - return CAIRO_STATUS_SUCCESS; - - if (fixup.width < extents->width || fixup.height < extents->height) { - cairo_boxes_t clear; - - _cairo_boxes_init (&clear); - - /* top */ - if (fixup.y != extents->y) { - add_rect_with_offset (&clear, - extents->x, extents->y, - extents->x + extents->width, - fixup.y, - extents->x, extents->y); - } - /* left */ - if (fixup.x != extents->x) { - add_rect_with_offset (&clear, - extents->x, fixup.y, - fixup.x, - fixup.y + fixup.height, - extents->x, extents->y); - } - /* right */ - if (fixup.x + fixup.width != extents->x + extents->width) { - add_rect_with_offset (&clear, - fixup.x + fixup.width, - fixup.y, - extents->x + extents->width, - fixup.y + fixup.height, - extents->x, extents->y); - } - /* bottom */ - if (fixup.y + fixup.height != extents->y + extents->height) { - add_rect_with_offset (&clear, - extents->x, - fixup.y + fixup.height, - extents->x + extents->width, - extents->y + extents->height, - extents->x, extents->y); - } - - status = compositor->fill_boxes (mask, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - - _cairo_boxes_fini (&clear); - } - - return status; -} - -static cairo_status_t -__clip_to_surface (const cairo_traps_compositor_t *compositor, - const cairo_composite_rectangles_t *composite, - const cairo_rectangle_int_t *extents, - cairo_surface_t **surface) -{ - cairo_surface_t *mask; - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - cairo_traps_t traps; - cairo_boxes_t clear; - cairo_surface_t *src; - int src_x, src_y; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = _cairo_clip_get_polygon (composite->clip, &polygon, - &fill_rule, &antialias); - if (status) - return status; - - _cairo_traps_init (&traps); - status = _cairo_bentley_ottmann_tessellate_polygon (&traps, - &polygon, - fill_rule); - _cairo_polygon_fini (&polygon); - if (unlikely (status)) - return status; - - mask = _cairo_surface_create_scratch (composite->surface, - CAIRO_CONTENT_ALPHA, - extents->width, - extents->height, - NULL); - if (unlikely (mask->status)) { - _cairo_traps_fini (&traps); - return status; - } - - src = compositor->pattern_to_surface (mask, NULL, FALSE, - extents, NULL, - &src_x, &src_y); - if (unlikely (status = src->status)) - goto error; - - status = compositor->acquire (mask); - if (unlikely (status)) - goto error; - - _cairo_boxes_init_from_rectangle (&clear, - 0, 0, - extents->width, - extents->height); - status = compositor->fill_boxes (mask, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - if (unlikely (status)) - goto error_release; - - status = compositor->composite_traps (mask, CAIRO_OPERATOR_ADD, src, - src_x, src_y, - extents->x, extents->y, - extents, - antialias, &traps); - if (unlikely (status)) - goto error_release; - - compositor->release (mask); - *surface = mask; -out: - cairo_surface_destroy (src); - _cairo_traps_fini (&traps); - return status; - -error_release: - compositor->release (mask); -error: - cairo_surface_destroy (mask); - goto out; -} - -static cairo_surface_t * -traps_get_clip_surface (const cairo_traps_compositor_t *compositor, - const cairo_composite_rectangles_t *composite, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_t *surface = NULL; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = __clip_to_surface (compositor, composite, extents, &surface); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - surface = _cairo_surface_create_scratch (composite->surface, - CAIRO_CONTENT_ALPHA, - extents->width, - extents->height, - CAIRO_COLOR_WHITE); - if (unlikely (surface->status)) - return surface; - - status = _cairo_clip_combine_with_surface (composite->clip, surface, - extents->x, extents->y); - } - if (unlikely (status)) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - - return surface; -} - -static void blt_unaligned_boxes(const cairo_traps_compositor_t *compositor, - cairo_surface_t *surface, - int dx, int dy, - cairo_box_t *boxes, - int num_boxes) -{ - struct blt_in info; - int i; - - info.compositor = compositor; - info.dst = surface; - _cairo_boxes_init (&info.boxes); - info.boxes.num_boxes = 1; - for (i = 0; i < num_boxes; i++) { - cairo_box_t *b = &boxes[i]; - - if (! _cairo_fixed_is_integer (b->p1.x) || - ! _cairo_fixed_is_integer (b->p1.y) || - ! _cairo_fixed_is_integer (b->p2.x) || - ! _cairo_fixed_is_integer (b->p2.y)) - { - do_unaligned_box(blt_in, &info, b, dx, dy); - } - } -} - -static cairo_surface_t * -create_composite_mask (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *draw_closure, - draw_func_t draw_func, - draw_func_t mask_func, - const cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *surface, *src; - cairo_int_status_t status; - int src_x, src_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - surface = _cairo_surface_create_scratch (dst, CAIRO_CONTENT_ALPHA, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (surface->status)) - return surface; - - src = compositor->pattern_to_surface (surface, - &_cairo_pattern_white.base, - FALSE, - &extents->bounded, - &extents->bounded, - &src_x, &src_y); - if (unlikely (src->status)) { - cairo_surface_destroy (surface); - return src; - } - - status = compositor->acquire (surface); - if (unlikely (status)) { - cairo_surface_destroy (src); - cairo_surface_destroy (surface); - return _cairo_surface_create_in_error (status); - } - - if (!surface->is_clear) { - cairo_boxes_t clear; - - _cairo_boxes_init_from_rectangle (&clear, - 0, 0, - extents->bounded.width, - extents->bounded.height); - status = compositor->fill_boxes (surface, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - if (unlikely (status)) - goto error; - - surface->is_clear = TRUE; - } - - if (mask_func) { - status = mask_func (compositor, surface, draw_closure, - CAIRO_OPERATOR_SOURCE, src, src_x, src_y, - extents->bounded.x, extents->bounded.y, - &extents->bounded, extents->clip); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - surface->is_clear = FALSE; - goto out; - } - if (unlikely (status != CAIRO_INT_STATUS_UNSUPPORTED)) - goto error; - } - - /* Is it worth setting the clip region here? */ - status = draw_func (compositor, surface, draw_closure, - CAIRO_OPERATOR_ADD, src, src_x, src_y, - extents->bounded.x, extents->bounded.y, - &extents->bounded, NULL); - if (unlikely (status)) - goto error; - - surface->is_clear = FALSE; - if (extents->clip->path != NULL) { - status = combine_clip_as_traps (compositor, surface, - extents->clip, &extents->bounded); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = _cairo_clip_combine_with_surface (extents->clip, surface, - extents->bounded.x, - extents->bounded.y); - } - if (unlikely (status)) - goto error; - } else if (extents->clip->boxes) { - blt_unaligned_boxes(compositor, surface, - extents->bounded.x, extents->bounded.y, - extents->clip->boxes, extents->clip->num_boxes); - - } - -out: - compositor->release (surface); - cairo_surface_destroy (src); - return surface; - -error: - compositor->release (surface); - if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - cairo_surface_destroy (src); - return surface; -} - -/* Handles compositing with a clip surface when the operator allows - * us to combine the clip with the mask - */ -static cairo_status_t -clip_and_composite_with_mask (const cairo_traps_compositor_t *compositor, - const cairo_composite_rectangles_t*extents, - draw_func_t draw_func, - draw_func_t mask_func, - void *draw_closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, int src_y) -{ - cairo_surface_t *dst = extents->surface; - cairo_surface_t *mask; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - mask = create_composite_mask (compositor, dst, draw_closure, - draw_func, mask_func, - extents); - if (unlikely (mask->status)) - return mask->status; - - if (mask->is_clear) - goto skip; - - if (src != NULL || dst->content != CAIRO_CONTENT_ALPHA) { - compositor->composite (dst, op, src, mask, - extents->bounded.x + src_x, - extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } else { - compositor->composite (dst, op, mask, NULL, - 0, 0, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } - -skip: - cairo_surface_destroy (mask); - return CAIRO_STATUS_SUCCESS; -} - -/* Handles compositing with a clip surface when we have to do the operation - * in two pieces and combine them together. - */ -static cairo_status_t -clip_and_composite_combine (const cairo_traps_compositor_t *compositor, - const cairo_composite_rectangles_t*extents, - draw_func_t draw_func, - void *draw_closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, int src_y) -{ - cairo_surface_t *dst = extents->surface; - cairo_surface_t *tmp, *clip; - cairo_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - tmp = _cairo_surface_create_scratch (dst, dst->content, - extents->bounded.width, - extents->bounded.height, - NULL); - if (unlikely (tmp->status)) - return tmp->status; - - status = compositor->acquire (tmp); - if (unlikely (status)) { - cairo_surface_destroy (tmp); - return status; - } - - compositor->composite (tmp, - dst->is_clear ? CAIRO_OPERATOR_CLEAR : CAIRO_OPERATOR_SOURCE, - dst, NULL, - extents->bounded.x, extents->bounded.y, - 0, 0, - 0, 0, - extents->bounded.width, extents->bounded.height); - - status = draw_func (compositor, tmp, draw_closure, op, - src, src_x, src_y, - extents->bounded.x, extents->bounded.y, - &extents->bounded, NULL); - - if (unlikely (status)) - goto cleanup; - - clip = traps_get_clip_surface (compositor, extents, &extents->bounded); - if (unlikely ((status = clip->status))) - goto cleanup; - - if (dst->is_clear) { - compositor->composite (dst, CAIRO_OPERATOR_SOURCE, tmp, clip, - 0, 0, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } else { - compositor->lerp (dst, tmp, clip, - 0, 0, - 0,0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } - cairo_surface_destroy (clip); - -cleanup: - compositor->release (tmp); - cairo_surface_destroy (tmp); - - return status; -} - -/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's - * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) - */ -static cairo_status_t -clip_and_composite_source (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - draw_func_t draw_func, - draw_func_t mask_func, - void *draw_closure, - cairo_surface_t *src, - int src_x, - int src_y, - const cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *mask; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - /* Create a surface that is mask IN clip */ - mask = create_composite_mask (compositor, dst, draw_closure, - draw_func, mask_func, - extents); - if (unlikely (mask->status)) - return mask->status; - - if (mask->is_clear) - goto skip; - - if (dst->is_clear) { - compositor->composite (dst, CAIRO_OPERATOR_SOURCE, src, mask, - extents->bounded.x + src_x, extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } else { - compositor->lerp (dst, src, mask, - extents->bounded.x + src_x, extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - } - -skip: - cairo_surface_destroy (mask); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -can_reduce_alpha_op (cairo_operator_t op) -{ - int iop = op; - switch (iop) { - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_ADD: - return TRUE; - default: - return FALSE; - } -} - -static cairo_bool_t -reduce_alpha_op (cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *dst = extents->surface; - cairo_operator_t op = extents->op; - const cairo_pattern_t *pattern = &extents->source_pattern.base; - return dst->is_clear && - dst->content == CAIRO_CONTENT_ALPHA && - _cairo_pattern_is_opaque_solid (pattern) && - can_reduce_alpha_op (op); -} - -static cairo_status_t -fixup_unbounded_with_mask (const cairo_traps_compositor_t *compositor, - const cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *dst = extents->surface; - cairo_surface_t *mask; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - /* XXX can we avoid querying the clip surface again? */ - mask = traps_get_clip_surface (compositor, extents, &extents->unbounded); - if (unlikely (mask->status)) - return mask->status; - - /* top */ - if (extents->bounded.y != extents->unbounded.y) { - int x = extents->unbounded.x; - int y = extents->unbounded.y; - int width = extents->unbounded.width; - int height = extents->bounded.y - y; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - 0, 0, - 0, 0, - x, y, - width, height); - } - - /* left */ - if (extents->bounded.x != extents->unbounded.x) { - int x = extents->unbounded.x; - int y = extents->bounded.y; - int width = extents->bounded.x - x; - int height = extents->bounded.height; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - 0, y - extents->unbounded.y, - 0, 0, - x, y, - width, height); - } - - /* right */ - if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { - int x = extents->bounded.x + extents->bounded.width; - int y = extents->bounded.y; - int width = extents->unbounded.x + extents->unbounded.width - x; - int height = extents->bounded.height; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - x - extents->unbounded.x, y - extents->unbounded.y, - 0, 0, - x, y, - width, height); - } - - /* bottom */ - if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { - int x = extents->unbounded.x; - int y = extents->bounded.y + extents->bounded.height; - int width = extents->unbounded.width; - int height = extents->unbounded.y + extents->unbounded.height - y; - - compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, - 0, y - extents->unbounded.y, - 0, 0, - x, y, - width, height); - } - - cairo_surface_destroy (mask); - - return CAIRO_STATUS_SUCCESS; -} - -static void -add_rect (cairo_boxes_t *boxes, int x1, int y1, int x2, int y2) -{ - cairo_box_t box; - cairo_int_status_t status; - - box.p1.x = _cairo_fixed_from_int (x1); - box.p1.y = _cairo_fixed_from_int (y1); - box.p2.x = _cairo_fixed_from_int (x2); - box.p2.y = _cairo_fixed_from_int (y2); - - status = _cairo_boxes_add (boxes, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_INT_STATUS_SUCCESS); -} - -static cairo_status_t -fixup_unbounded (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - cairo_boxes_t clear, tmp; - cairo_box_t box; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (extents->bounded.width == extents->unbounded.width && - extents->bounded.height == extents->unbounded.height) - { - return CAIRO_STATUS_SUCCESS; - } - - assert (extents->clip->path == NULL); - - /* subtract the drawn boxes from the unbounded area */ - _cairo_boxes_init (&clear); - - box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); - box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); - box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); - box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); - - if (boxes == NULL) { - if (extents->bounded.width == 0 || extents->bounded.height == 0) { - goto empty; - } else { - /* top */ - if (extents->bounded.y != extents->unbounded.y) { - add_rect (&clear, - extents->unbounded.x, extents->unbounded.y, - extents->unbounded.x + extents->unbounded.width, - extents->bounded.y); - } - /* left */ - if (extents->bounded.x != extents->unbounded.x) { - add_rect (&clear, - extents->unbounded.x, extents->bounded.y, - extents->bounded.x, - extents->bounded.y + extents->bounded.height); - } - /* right */ - if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { - add_rect (&clear, - extents->bounded.x + extents->bounded.width, - extents->bounded.y, - extents->unbounded.x + extents->unbounded.width, - extents->bounded.y + extents->bounded.height); - } - /* bottom */ - if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { - add_rect (&clear, - extents->unbounded.x, - extents->bounded.y + extents->bounded.height, - extents->unbounded.x + extents->unbounded.width, - extents->unbounded.y + extents->unbounded.height); - } - } - } else if (boxes->num_boxes) { - _cairo_boxes_init (&tmp); - - assert (boxes->is_pixel_aligned); - - status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_INT_STATUS_SUCCESS); - - tmp.chunks.next = &boxes->chunks; - tmp.num_boxes += boxes->num_boxes; - - status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, - CAIRO_FILL_RULE_WINDING, - &clear); - tmp.chunks.next = NULL; - if (unlikely (status)) - goto error; - } else { -empty: - box.p1.x = _cairo_fixed_from_int (extents->unbounded.x); - box.p2.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); - - status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_INT_STATUS_SUCCESS); - } - - /* Now intersect with the clip boxes */ - if (extents->clip->num_boxes) { - _cairo_boxes_init_for_array (&tmp, - extents->clip->boxes, - extents->clip->num_boxes); - status = _cairo_boxes_intersect (&clear, &tmp, &clear); - if (unlikely (status)) - goto error; - } - - status = compositor->fill_boxes (dst, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - -error: - _cairo_boxes_fini (&clear); - return status; -} - -enum { - NEED_CLIP_REGION = 0x1, - NEED_CLIP_SURFACE = 0x2, - FORCE_CLIP_REGION = 0x4, -}; - -static cairo_bool_t -need_bounded_clip (cairo_composite_rectangles_t *extents) -{ - unsigned int flags = 0; - - if (extents->clip->num_boxes > 1 || - extents->mask.width > extents->unbounded.width || - extents->mask.height > extents->unbounded.height) - { - flags |= NEED_CLIP_REGION; - } - - if (extents->clip->num_boxes > 1 || - extents->mask.width > extents->bounded.width || - extents->mask.height > extents->bounded.height) - { - flags |= FORCE_CLIP_REGION; - } - - if (! _cairo_clip_is_region (extents->clip)) - flags |= NEED_CLIP_SURFACE; - - return flags; -} - -static cairo_bool_t -need_unbounded_clip (cairo_composite_rectangles_t *extents) -{ - unsigned int flags = 0; - if (! extents->is_bounded) { - flags |= NEED_CLIP_REGION; - if (! _cairo_clip_is_region (extents->clip)) - flags |= NEED_CLIP_SURFACE; - } - if (extents->clip->path != NULL) - flags |= NEED_CLIP_SURFACE; - return flags; -} - -static cairo_status_t -clip_and_composite (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - draw_func_t draw_func, - draw_func_t mask_func, - void *draw_closure, - unsigned int need_clip) -{ - cairo_surface_t *dst = extents->surface; - cairo_operator_t op = extents->op; - cairo_pattern_t *source = &extents->source_pattern.base; - cairo_surface_t *src; - int src_x, src_y; - cairo_region_t *clip_region = NULL; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (reduce_alpha_op (extents)) { - op = CAIRO_OPERATOR_ADD; - source = NULL; - } - - if (op == CAIRO_OPERATOR_CLEAR) { - op = CAIRO_OPERATOR_DEST_OUT; - source = NULL; - } - - compositor->acquire (dst); - - if (need_clip & NEED_CLIP_REGION) { - const cairo_rectangle_int_t *limit; - - if ((need_clip & FORCE_CLIP_REGION) == 0) - limit = &extents->unbounded; - else - limit = &extents->destination; - - clip_region = _cairo_clip_get_region (extents->clip); - if (clip_region != NULL && - cairo_region_contains_rectangle (clip_region, - limit) == CAIRO_REGION_OVERLAP_IN) - clip_region = NULL; - - if (clip_region != NULL) { - status = compositor->set_clip_region (dst, clip_region); - if (unlikely (status)) { - compositor->release (dst); - return status; - } - } - } - - if (extents->bounded.width == 0 || extents->bounded.height == 0) - goto skip; - - src = compositor->pattern_to_surface (dst, source, FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (unlikely (status = src->status)) - goto error; - - if (op == CAIRO_OPERATOR_SOURCE) { - status = clip_and_composite_source (compositor, dst, - draw_func, mask_func, draw_closure, - src, src_x, src_y, - extents); - } else { - if (need_clip & NEED_CLIP_SURFACE) { - if (extents->is_bounded) { - status = clip_and_composite_with_mask (compositor, extents, - draw_func, mask_func, - draw_closure, - op, src, src_x, src_y); - } else { - status = clip_and_composite_combine (compositor, extents, - draw_func, draw_closure, - op, src, src_x, src_y); - } - } else { - status = draw_func (compositor, - dst, draw_closure, - op, src, src_x, src_y, - 0, 0, - &extents->bounded, - extents->clip); - } - } - cairo_surface_destroy (src); - -skip: - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { - if (need_clip & NEED_CLIP_SURFACE) - status = fixup_unbounded_with_mask (compositor, extents); - else - status = fixup_unbounded (compositor, extents, NULL); - } - -error: - if (clip_region) - compositor->set_clip_region (dst, NULL); - - compositor->release (dst); - - return status; -} - -/* meta-ops */ - -typedef struct { - cairo_traps_t traps; - cairo_antialias_t antialias; -} composite_traps_info_t; - -static cairo_int_status_t -composite_traps (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, int src_y, - int dst_x, int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - composite_traps_info_t *info = closure; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - return compositor->composite_traps (dst, op, src, - src_x - dst_x, src_y - dst_y, - dst_x, dst_y, - extents, - info->antialias, &info->traps); -} - -typedef struct { - cairo_tristrip_t strip; - cairo_antialias_t antialias; -} composite_tristrip_info_t; - -static cairo_int_status_t -composite_tristrip (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, int src_y, - int dst_x, int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - composite_tristrip_info_t *info = closure; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - return compositor->composite_tristrip (dst, op, src, - src_x - dst_x, src_y - dst_y, - dst_x, dst_y, - extents, - info->antialias, &info->strip); -} - -static cairo_bool_t -is_recording_pattern (const cairo_pattern_t *pattern) -{ - cairo_surface_t *surface; - - if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) - return FALSE; - - surface = ((const cairo_surface_pattern_t *) pattern)->surface; - surface = _cairo_surface_get_source (surface, NULL); - return _cairo_surface_is_recording (surface); -} - -static cairo_surface_t * -recording_pattern_get_surface (const cairo_pattern_t *pattern) -{ - cairo_surface_t *surface; - - surface = ((const cairo_surface_pattern_t *) pattern)->surface; - return _cairo_surface_get_source (surface, NULL); -} - -static cairo_bool_t -recording_pattern_contains_sample (const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *sample) -{ - cairo_recording_surface_t *surface; - - if (! is_recording_pattern (pattern)) - return FALSE; - - if (pattern->extend == CAIRO_EXTEND_NONE) - return TRUE; - - surface = (cairo_recording_surface_t *) recording_pattern_get_surface (pattern); - if (surface->unbounded) - return TRUE; - - return _cairo_rectangle_contains_rectangle (&surface->extents, sample); -} - -static cairo_bool_t -op_reduces_to_source (cairo_composite_rectangles_t *extents) -{ - if (extents->op == CAIRO_OPERATOR_SOURCE) - return TRUE; - - if (extents->surface->is_clear) - return extents->op == CAIRO_OPERATOR_OVER || extents->op == CAIRO_OPERATOR_ADD; - - return FALSE; -} - -static cairo_status_t -composite_aligned_boxes (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - cairo_operator_t op = extents->op; - cairo_bool_t need_clip_mask = ! _cairo_clip_is_region (extents->clip); - cairo_bool_t op_is_source; - cairo_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (need_clip_mask && - (! extents->is_bounded || extents->op == CAIRO_OPERATOR_SOURCE)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - op_is_source = op_reduces_to_source (extents); - - /* Are we just copying a recording surface? */ - if (! need_clip_mask && op_is_source && - recording_pattern_contains_sample (&extents->source_pattern.base, - &extents->source_sample_area)) - { - cairo_clip_t *recording_clip; - const cairo_pattern_t *source = &extents->source_pattern.base; - const cairo_matrix_t *m; - cairo_matrix_t matrix; - - /* XXX could also do tiling repeat modes... */ - - /* first clear the area about to be overwritten */ - if (! dst->is_clear) { - status = compositor->acquire (dst); - if (unlikely (status)) - return status; - - status = compositor->fill_boxes (dst, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - boxes); - compositor->release (dst); - if (unlikely (status)) - return status; - } - - m = &source->matrix; - if (_cairo_surface_has_device_transform (dst)) { - cairo_matrix_multiply (&matrix, - &source->matrix, - &dst->device_transform); - m = &matrix; - } - - recording_clip = _cairo_clip_from_boxes (boxes); - status = _cairo_recording_surface_replay_with_clip (recording_pattern_get_surface (source), - m, dst, recording_clip); - _cairo_clip_destroy (recording_clip); - - return status; - } - - status = compositor->acquire (dst); - if (unlikely (status)) - return status; - - if (! need_clip_mask && - (op == CAIRO_OPERATOR_CLEAR || - extents->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID)) - { - const cairo_color_t *color; - - if (op == CAIRO_OPERATOR_CLEAR) { - color = CAIRO_COLOR_TRANSPARENT; - } else { - color = &((cairo_solid_pattern_t *) &extents->source_pattern)->color; - if (op_is_source) - op = CAIRO_OPERATOR_SOURCE; - } - - status = compositor->fill_boxes (dst, op, color, boxes); - } - else - { - cairo_surface_t *src, *mask = NULL; - cairo_pattern_t *source = &extents->source_pattern.base; - int src_x, src_y; - int mask_x = 0, mask_y = 0; - - if (need_clip_mask) { - mask = traps_get_clip_surface (compositor, - extents, &extents->bounded); - if (unlikely (mask->status)) - return mask->status; - - mask_x = -extents->bounded.x; - mask_y = -extents->bounded.y; - - if (op == CAIRO_OPERATOR_CLEAR) { - source = NULL; - op = CAIRO_OPERATOR_DEST_OUT; - } - } else if (op_is_source) - op = CAIRO_OPERATOR_SOURCE; - - src = compositor->pattern_to_surface (dst, source, FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (likely (src->status == CAIRO_STATUS_SUCCESS)) { - status = compositor->composite_boxes (dst, op, src, mask, - src_x, src_y, - mask_x, mask_y, - 0, 0, - boxes, &extents->bounded); - cairo_surface_destroy (src); - } else - status = src->status; - - cairo_surface_destroy (mask); - } - - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) - status = fixup_unbounded (compositor, extents, boxes); - - compositor->release (dst); - - return status; -} - -static cairo_status_t -upload_boxes (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_surface_t *dst = extents->surface; - const cairo_pattern_t *source = &extents->source_pattern.base; - cairo_surface_t *src; - cairo_rectangle_int_t limit; - cairo_int_status_t status; - int tx, ty; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - src = _cairo_pattern_get_source((cairo_surface_pattern_t *)source, - &limit); - if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Check that the data is entirely within the image */ - if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width || - extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height) - return CAIRO_INT_STATUS_UNSUPPORTED; - - tx += limit.x; - ty += limit.y; - - if (src->type == CAIRO_SURFACE_TYPE_IMAGE) - status = compositor->draw_image_boxes (dst, - (cairo_image_surface_t *)src, - boxes, tx, ty); - else - status = compositor->copy_boxes (dst, src, boxes, &extents->bounded, - tx, ty); - - return status; -} - -static cairo_int_status_t -trim_extents_to_traps (cairo_composite_rectangles_t *extents, - cairo_traps_t *traps) -{ - cairo_box_t box; - - _cairo_traps_extents (traps, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_int_status_t -trim_extents_to_tristrip (cairo_composite_rectangles_t *extents, - cairo_tristrip_t *strip) -{ - cairo_box_t box; - - _cairo_tristrip_extents (strip, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_int_status_t -trim_extents_to_boxes (cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_box_t box; - - _cairo_boxes_extents (boxes, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_int_status_t -boxes_for_traps (cairo_boxes_t *boxes, - cairo_traps_t *traps, - cairo_antialias_t antialias) -{ - int i, j; - - /* first check that the traps are rectilinear */ - if (antialias == CAIRO_ANTIALIAS_NONE) { - for (i = 0; i < traps->num_traps; i++) { - const cairo_trapezoid_t *t = &traps->traps[i]; - if (_cairo_fixed_integer_round_down (t->left.p1.x) != - _cairo_fixed_integer_round_down (t->left.p2.x) || - _cairo_fixed_integer_round_down (t->right.p1.x) != - _cairo_fixed_integer_round_down (t->right.p2.x)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - } else { - for (i = 0; i < traps->num_traps; i++) { - const cairo_trapezoid_t *t = &traps->traps[i]; - if (t->left.p1.x != t->left.p2.x || t->right.p1.x != t->right.p2.x) - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - - _cairo_boxes_init (boxes); - - boxes->chunks.base = (cairo_box_t *) traps->traps; - boxes->chunks.size = traps->num_traps; - - if (antialias != CAIRO_ANTIALIAS_NONE) { - for (i = j = 0; i < traps->num_traps; i++) { - /* Note the traps and boxes alias so we need to take the local copies first. */ - cairo_fixed_t x1 = traps->traps[i].left.p1.x; - cairo_fixed_t x2 = traps->traps[i].right.p1.x; - cairo_fixed_t y1 = traps->traps[i].top; - cairo_fixed_t y2 = traps->traps[i].bottom; - - if (x1 == x2 || y1 == y2) - continue; - - boxes->chunks.base[j].p1.x = x1; - boxes->chunks.base[j].p1.y = y1; - boxes->chunks.base[j].p2.x = x2; - boxes->chunks.base[j].p2.y = y2; - j++; - - if (boxes->is_pixel_aligned) { - boxes->is_pixel_aligned = - _cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) && - _cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2); - } - } - } else { - boxes->is_pixel_aligned = TRUE; - - for (i = j = 0; i < traps->num_traps; i++) { - /* Note the traps and boxes alias so we need to take the local copies first. */ - cairo_fixed_t x1 = traps->traps[i].left.p1.x; - cairo_fixed_t x2 = traps->traps[i].right.p1.x; - cairo_fixed_t y1 = traps->traps[i].top; - cairo_fixed_t y2 = traps->traps[i].bottom; - - /* round down here to match Pixman's behavior when using traps. */ - boxes->chunks.base[j].p1.x = _cairo_fixed_round_down (x1); - boxes->chunks.base[j].p1.y = _cairo_fixed_round_down (y1); - boxes->chunks.base[j].p2.x = _cairo_fixed_round_down (x2); - boxes->chunks.base[j].p2.y = _cairo_fixed_round_down (y2); - j += (boxes->chunks.base[j].p1.x != boxes->chunks.base[j].p2.x && - boxes->chunks.base[j].p1.y != boxes->chunks.base[j].p2.y); - } - } - boxes->chunks.count = j; - boxes->num_boxes = j; - - return CAIRO_INT_STATUS_SUCCESS; -} - -static cairo_status_t -clip_and_composite_boxes (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes); - -static cairo_status_t -clip_and_composite_polygon (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_polygon_t *polygon, - cairo_antialias_t antialias, - cairo_fill_rule_t fill_rule, - cairo_bool_t curvy) -{ - composite_traps_info_t traps; - cairo_surface_t *dst = extents->surface; - cairo_bool_t clip_surface = ! _cairo_clip_is_region (extents->clip); - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (polygon->num_edges == 0) { - status = CAIRO_INT_STATUS_SUCCESS; - - if (! extents->is_bounded) { - cairo_region_t *clip_region = _cairo_clip_get_region (extents->clip); - - if (clip_region && - cairo_region_contains_rectangle (clip_region, - &extents->unbounded) == CAIRO_REGION_OVERLAP_IN) - clip_region = NULL; - - if (clip_region != NULL) { - status = compositor->set_clip_region (dst, clip_region); - if (unlikely (status)) - return status; - } - - if (clip_surface) - status = fixup_unbounded_with_mask (compositor, extents); - else - status = fixup_unbounded (compositor, extents, NULL); - - if (clip_region != NULL) - compositor->set_clip_region (dst, NULL); - } - - return status; - } - - if (extents->clip->path != NULL && extents->is_bounded) { - cairo_polygon_t clipper; - cairo_fill_rule_t clipper_fill_rule; - cairo_antialias_t clipper_antialias; - - status = _cairo_clip_get_polygon (extents->clip, - &clipper, - &clipper_fill_rule, - &clipper_antialias); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - if (clipper_antialias == antialias) { - status = _cairo_polygon_intersect (polygon, fill_rule, - &clipper, clipper_fill_rule); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t * clip = _cairo_clip_copy_region (extents->clip); - _cairo_clip_destroy (extents->clip); - extents->clip = clip; - - fill_rule = CAIRO_FILL_RULE_WINDING; - } - _cairo_polygon_fini (&clipper); - } - } - } - - if (antialias == CAIRO_ANTIALIAS_NONE && curvy) { - cairo_boxes_t boxes; - - _cairo_boxes_init (&boxes); - status = _cairo_rasterise_polygon_to_boxes (polygon, fill_rule, &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - assert (boxes.is_pixel_aligned); - status = clip_and_composite_boxes (compositor, extents, &boxes); - } - _cairo_boxes_fini (&boxes); - if ((status != CAIRO_INT_STATUS_UNSUPPORTED)) - return status; - } - - _cairo_traps_init (&traps.traps); - - if (antialias == CAIRO_ANTIALIAS_NONE && curvy) { - status = _cairo_rasterise_polygon_to_traps (polygon, fill_rule, antialias, &traps.traps); - } else { - status = _cairo_bentley_ottmann_tessellate_polygon (&traps.traps, polygon, fill_rule); - } - if (unlikely (status)) - goto CLEANUP_TRAPS; - - status = trim_extents_to_traps (extents, &traps.traps); - if (unlikely (status)) - goto CLEANUP_TRAPS; - - /* Use a fast path if the trapezoids consist of a set of boxes. */ - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (1) { - cairo_boxes_t boxes; - - status = boxes_for_traps (&boxes, &traps.traps, antialias); - if (status == CAIRO_INT_STATUS_SUCCESS) { - status = clip_and_composite_boxes (compositor, extents, &boxes); - /* XXX need to reconstruct the traps! */ - assert (status != CAIRO_INT_STATUS_UNSUPPORTED); - } - } - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - /* Otherwise render the trapezoids to a mask and composite in the usual - * fashion. - */ - unsigned int flags = 0; - - /* For unbounded operations, the X11 server will estimate the - * affected rectangle and apply the operation to that. However, - * there are cases where this is an overestimate (e.g. the - * clip-fill-{eo,nz}-unbounded test). - * - * The clip will trim that overestimate to our expectations. - */ - if (! extents->is_bounded) - flags |= FORCE_CLIP_REGION; - - traps.antialias = antialias; - status = clip_and_composite (compositor, extents, - composite_traps, NULL, &traps, - need_unbounded_clip (extents) | flags); - } - -CLEANUP_TRAPS: - _cairo_traps_fini (&traps.traps); - - return status; -} - -struct composite_opacity_info { - const cairo_traps_compositor_t *compositor; - uint8_t op; - cairo_surface_t *dst; - cairo_surface_t *src; - int src_x, src_y; - double opacity; -}; - -static void composite_opacity(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct composite_opacity_info *info = closure; - const cairo_traps_compositor_t *compositor = info->compositor; - cairo_surface_t *mask; - int mask_x, mask_y; - cairo_color_t color; - cairo_solid_pattern_t solid; - - _cairo_color_init_rgba (&color, 0, 0, 0, info->opacity * coverage); - _cairo_pattern_init_solid (&solid, &color); - mask = compositor->pattern_to_surface (info->dst, &solid.base, TRUE, - &_cairo_unbounded_rectangle, - &_cairo_unbounded_rectangle, - &mask_x, &mask_y); - if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { - if (info->src) { - compositor->composite (info->dst, info->op, info->src, mask, - x + info->src_x, y + info->src_y, - mask_x, mask_y, - x, y, - w, h); - } else { - compositor->composite (info->dst, info->op, mask, NULL, - mask_x, mask_y, - 0, 0, - x, y, - w, h); - } - } - - cairo_surface_destroy (mask); -} - - -static cairo_int_status_t -composite_opacity_boxes (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - const cairo_solid_pattern_t *mask = closure; - struct composite_opacity_info info; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - info.compositor = compositor; - info.op = op; - info.dst = dst; - - info.src = src; - info.src_x = src_x; - info.src_y = src_y; - - info.opacity = mask->color.alpha / (double) 0xffff; - - /* XXX for lots of boxes create a clip region for the fully opaque areas */ - for (i = 0; i < clip->num_boxes; i++) - do_unaligned_box(composite_opacity, &info, - &clip->boxes[i], dst_x, dst_y); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_boxes (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - cairo_traps_t traps; - cairo_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = _cairo_traps_init_boxes (&traps, closure); - if (unlikely (status)) - return status; - - status = compositor->composite_traps (dst, op, src, - src_x - dst_x, src_y - dst_y, - dst_x, dst_y, - extents, - CAIRO_ANTIALIAS_DEFAULT, &traps); - _cairo_traps_fini (&traps); - - return status; -} - -static cairo_status_t -clip_and_composite_boxes (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (boxes->num_boxes == 0 && extents->is_bounded) - return CAIRO_STATUS_SUCCESS; - - status = trim_extents_to_boxes (extents, boxes); - if (unlikely (status)) - return status; - - if (boxes->is_pixel_aligned && extents->clip->path == NULL && - extents->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && - (op_reduces_to_source (extents) || - (extents->op == CAIRO_OPERATOR_OVER && - (extents->source_pattern.surface.surface->content & CAIRO_CONTENT_ALPHA) == 0))) - { - status = upload_boxes (compositor, extents, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ - if (extents->clip->path != NULL && extents->is_bounded) { - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - cairo_clip_t *clip; - - clip = _cairo_clip_copy (extents->clip); - clip = _cairo_clip_intersect_boxes (clip, boxes); - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - status = _cairo_clip_get_polygon (clip, &polygon, - &fill_rule, &antialias); - _cairo_clip_path_destroy (clip->path); - clip->path = NULL; - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t *saved_clip = extents->clip; - extents->clip = clip; - - status = clip_and_composite_polygon (compositor, extents, &polygon, - antialias, fill_rule, FALSE); - - clip = extents->clip; - extents->clip = saved_clip; - - _cairo_polygon_fini (&polygon); - } - _cairo_clip_destroy (clip); - - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - /* Use a fast path if the boxes are pixel aligned (or nearly aligned!) */ - if (boxes->is_pixel_aligned) { - status = composite_aligned_boxes (compositor, extents, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - return clip_and_composite (compositor, extents, - composite_boxes, NULL, boxes, - need_unbounded_clip (extents)); -} - -static cairo_int_status_t -composite_traps_as_boxes (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - composite_traps_info_t *info) -{ - cairo_boxes_t boxes; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (! _cairo_traps_to_boxes (&info->traps, info->antialias, &boxes)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return clip_and_composite_boxes (compositor, extents, &boxes); -} - -static cairo_int_status_t -clip_and_composite_traps (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - composite_traps_info_t *info, - unsigned flags) -{ - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = trim_extents_to_traps (extents, &info->traps); - if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) - return status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if ((flags & FORCE_CLIP_REGION) == 0) - status = composite_traps_as_boxes (compositor, extents, info); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - /* For unbounded operations, the X11 server will estimate the - * affected rectangle and apply the operation to that. However, - * there are cases where this is an overestimate (e.g. the - * clip-fill-{eo,nz}-unbounded test). - * - * The clip will trim that overestimate to our expectations. - */ - if (! extents->is_bounded) - flags |= FORCE_CLIP_REGION; - - status = clip_and_composite (compositor, extents, - composite_traps, NULL, info, - need_unbounded_clip (extents) | flags); - } - - return status; -} - -static cairo_int_status_t -clip_and_composite_tristrip (const cairo_traps_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - composite_tristrip_info_t *info) -{ - cairo_int_status_t status; - unsigned int flags = 0; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = trim_extents_to_tristrip (extents, &info->strip); - if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) - return status; - - if (! extents->is_bounded) - flags |= FORCE_CLIP_REGION; - - status = clip_and_composite (compositor, extents, - composite_tristrip, NULL, info, - need_unbounded_clip (extents) | flags); - - return status; -} - -struct composite_mask { - cairo_surface_t *mask; - int mask_x, mask_y; -}; - -static cairo_int_status_t -composite_mask (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - struct composite_mask *data = closure; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (src != NULL) { - compositor->composite (dst, op, src, data->mask, - extents->x + src_x, extents->y + src_y, - extents->x + data->mask_x, extents->y + data->mask_y, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - } else { - compositor->composite (dst, op, data->mask, NULL, - extents->x + data->mask_x, extents->y + data->mask_y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - } - - return CAIRO_STATUS_SUCCESS; -} - -struct composite_box_info { - const cairo_traps_compositor_t *compositor; - cairo_surface_t *dst; - cairo_surface_t *src; - int src_x, src_y; - uint8_t op; -}; - -static void composite_box(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct composite_box_info *info = closure; - const cairo_traps_compositor_t *compositor = info->compositor; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (! CAIRO_ALPHA_SHORT_IS_OPAQUE (coverage)) { - cairo_surface_t *mask; - cairo_color_t color; - cairo_solid_pattern_t solid; - int mask_x, mask_y; - - _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double)0xffff); - _cairo_pattern_init_solid (&solid, &color); - - mask = compositor->pattern_to_surface (info->dst, &solid.base, FALSE, - &_cairo_unbounded_rectangle, - &_cairo_unbounded_rectangle, - &mask_x, &mask_y); - - if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { - compositor->composite (info->dst, info->op, info->src, mask, - x + info->src_x, y + info->src_y, - mask_x, mask_y, - x, y, - w, h); - } - - cairo_surface_destroy (mask); - } else { - compositor->composite (info->dst, info->op, info->src, NULL, - x + info->src_x, y + info->src_y, - 0, 0, - x, y, - w, h); - } -} - -static cairo_int_status_t -composite_mask_clip_boxes (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - struct composite_mask *data = closure; - struct composite_box_info info; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - info.compositor = compositor; - info.op = CAIRO_OPERATOR_SOURCE; - info.dst = dst; - info.src = data->mask; - info.src_x = data->mask_x; - info.src_y = data->mask_y; - - info.src_x += dst_x; - info.src_y += dst_y; - - for (i = 0; i < clip->num_boxes; i++) - do_unaligned_box(composite_box, &info, &clip->boxes[i], dst_x, dst_y); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_mask_clip (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - struct composite_mask *data = closure; - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - composite_traps_info_t info; - cairo_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = _cairo_clip_get_polygon (clip, &polygon, - &fill_rule, &info.antialias); - if (unlikely (status)) - return status; - - _cairo_traps_init (&info.traps); - status = _cairo_bentley_ottmann_tessellate_polygon (&info.traps, - &polygon, - fill_rule); - _cairo_polygon_fini (&polygon); - if (unlikely (status)) - return status; - - status = composite_traps (compositor, dst, &info, - CAIRO_OPERATOR_SOURCE, - data->mask, - data->mask_x + dst_x, data->mask_y + dst_y, - dst_x, dst_y, - extents, NULL); - _cairo_traps_fini (&info.traps); - - return status; -} - -/* high-level compositor interface */ - -static cairo_int_status_t -_cairo_traps_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t*)_compositor; - cairo_boxes_t boxes; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - _cairo_clip_steal_boxes (extents->clip, &boxes); - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_clip_unsteal_boxes (extents->clip, &boxes); - - return status; -} - -static cairo_int_status_t -_cairo_traps_compositor_mask (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t*)_compositor; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - if (extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && - extents->clip->path == NULL) { - status = clip_and_composite (compositor, extents, - composite_opacity_boxes, - composite_opacity_boxes, - &extents->mask_pattern, - need_unbounded_clip (extents)); - } else { - struct composite_mask data; - - data.mask = compositor->pattern_to_surface (extents->surface, - &extents->mask_pattern.base, - TRUE, - &extents->bounded, - &extents->mask_sample_area, - &data.mask_x, - &data.mask_y); - if (unlikely (data.mask->status)) - return data.mask->status; - - status = clip_and_composite (compositor, extents, - composite_mask, - extents->clip->path ? composite_mask_clip : composite_mask_clip_boxes, - &data, need_bounded_clip (extents)); - - cairo_surface_destroy (data.mask); - } - - return status; -} - -static cairo_int_status_t -_cairo_traps_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t *)_compositor; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_stroke_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, extents->clip); - status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, - style, - ctm, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED && 0 && - _cairo_clip_is_region (extents->clip)) /* XXX */ - { - composite_tristrip_info_t info; - - info.antialias = antialias; - _cairo_tristrip_init_with_clip (&info.strip, extents->clip); - status = _cairo_path_fixed_stroke_to_tristrip (path, style, - ctm, ctm_inverse, - tolerance, - &info.strip); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_tristrip (compositor, extents, &info); - _cairo_tristrip_fini (&info.strip); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED && - path->has_curve_to && antialias == CAIRO_ANTIALIAS_NONE) { - cairo_polygon_t polygon; - - _cairo_polygon_init_with_clip (&polygon, extents->clip); - status = _cairo_path_fixed_stroke_to_polygon (path, style, - ctm, ctm_inverse, - tolerance, - &polygon); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_polygon (compositor, - extents, &polygon, - CAIRO_ANTIALIAS_NONE, - CAIRO_FILL_RULE_WINDING, - TRUE); - _cairo_polygon_fini (&polygon); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_int_status_t (*func) (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_traps_t *traps); - composite_traps_info_t info; - unsigned flags; - - if (antialias == CAIRO_ANTIALIAS_BEST || antialias == CAIRO_ANTIALIAS_GOOD) { - func = _cairo_path_fixed_stroke_polygon_to_traps; - flags = 0; - } else { - func = _cairo_path_fixed_stroke_to_traps; - flags = need_bounded_clip (extents) & ~NEED_CLIP_SURFACE; - } - - info.antialias = antialias; - _cairo_traps_init_with_clip (&info.traps, extents->clip); - status = func (path, style, ctm, ctm_inverse, tolerance, &info.traps); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_traps (compositor, extents, &info, flags); - _cairo_traps_fini (&info.traps); - } - - return status; -} - -static cairo_int_status_t -_cairo_traps_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t *)_compositor; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_fill_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, extents->clip); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - fill_rule, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite_boxes (compositor, extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - cairo_polygon_t polygon; - -#if 0 - if (extents->mask.width > extents->unbounded.width || - extents->mask.height > extents->unbounded.height) - { - cairo_box_t limits; - _cairo_box_from_rectangle (&limits, &extents->unbounded); - _cairo_polygon_init (&polygon, &limits, 1); - } - else - { - _cairo_polygon_init (&polygon, NULL, 0); - } - - status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, - extents->clip->boxes, - extents->clip->num_boxes); - } -#else - _cairo_polygon_init_with_clip (&polygon, extents->clip); - status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); -#endif - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - status = clip_and_composite_polygon (compositor, extents, &polygon, - antialias, fill_rule, path->has_curve_to); - } - _cairo_polygon_fini (&polygon); - } - - return status; -} - -static cairo_int_status_t -composite_glyphs (const cairo_traps_compositor_t *compositor, - cairo_surface_t *dst, - void *closure, - cairo_operator_t op, - cairo_surface_t *src, - int src_x, int src_y, - int dst_x, int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - cairo_composite_glyphs_info_t *info = closure; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (op == CAIRO_OPERATOR_ADD && (dst->content & CAIRO_CONTENT_COLOR) == 0) - info->use_mask = 0; - - return compositor->composite_glyphs (dst, op, src, - src_x, src_y, - dst_x, dst_y, - info); -} - -static cairo_int_status_t -_cairo_traps_compositor_glyphs (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t *)_compositor; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - status = compositor->check_composite (extents); - if (unlikely (status)) - return status; - - _cairo_scaled_font_freeze_cache (scaled_font); - status = compositor->check_composite_glyphs (extents, - scaled_font, glyphs, - &num_glyphs); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_composite_glyphs_info_t info; - - info.font = scaled_font; - info.glyphs = glyphs; - info.num_glyphs = num_glyphs; - info.use_mask = overlap || ! extents->is_bounded; - info.extents = extents->bounded; - - status = clip_and_composite (compositor, extents, - composite_glyphs, NULL, &info, - need_bounded_clip (extents) | FORCE_CLIP_REGION); - } - _cairo_scaled_font_thaw_cache (scaled_font); - - return status; -} - -void -_cairo_traps_compositor_init (cairo_traps_compositor_t *compositor, - const cairo_compositor_t *delegate) -{ - compositor->base.delegate = delegate; - - compositor->base.paint = _cairo_traps_compositor_paint; - compositor->base.mask = _cairo_traps_compositor_mask; - compositor->base.fill = _cairo_traps_compositor_fill; - compositor->base.stroke = _cairo_traps_compositor_stroke; - compositor->base.glyphs = _cairo_traps_compositor_glyphs; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-private.h deleted file mode 100644 index dcaf40d1863..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps-private.h +++ /dev/null @@ -1,143 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_TRAPS_PRIVATE_H -#define CAIRO_TRAPS_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" -#include "cairo-types-private.h" - -CAIRO_BEGIN_DECLS - -struct _cairo_traps { - cairo_status_t status; - - cairo_box_t bounds; - const cairo_box_t *limits; - int num_limits; - - unsigned int maybe_region : 1; /* hint: 0 implies that it cannot be */ - unsigned int has_intersections : 1; - unsigned int is_rectilinear : 1; - unsigned int is_rectangular : 1; - - int num_traps; - int traps_size; - cairo_trapezoid_t *traps; - cairo_trapezoid_t traps_embedded[16]; -}; - -/* cairo-traps.c */ -cairo_private void -_cairo_traps_init (cairo_traps_t *traps); - -cairo_private void -_cairo_traps_init_with_clip (cairo_traps_t *traps, - const cairo_clip_t *clip); - -cairo_private void -_cairo_traps_limit (cairo_traps_t *traps, - const cairo_box_t *boxes, - int num_boxes); - -cairo_private cairo_status_t -_cairo_traps_init_boxes (cairo_traps_t *traps, - const cairo_boxes_t *boxes); - -cairo_private void -_cairo_traps_clear (cairo_traps_t *traps); - -cairo_private void -_cairo_traps_fini (cairo_traps_t *traps); - -#define _cairo_traps_status(T) (T)->status - -cairo_private void -_cairo_traps_translate (cairo_traps_t *traps, int x, int y); - -cairo_private void -_cairo_traps_tessellate_triangle_with_edges (cairo_traps_t *traps, - const cairo_point_t t[3], - const cairo_point_t edges[4]); - -cairo_private void -_cairo_traps_tessellate_convex_quad (cairo_traps_t *traps, - const cairo_point_t q[4]); - -cairo_private cairo_status_t -_cairo_traps_tessellate_rectangle (cairo_traps_t *traps, - const cairo_point_t *top_left, - const cairo_point_t *bottom_right); - -cairo_private void -_cairo_traps_add_trap (cairo_traps_t *traps, - cairo_fixed_t top, cairo_fixed_t bottom, - const cairo_line_t *left, - const cairo_line_t *right); - -cairo_private int -_cairo_traps_contain (const cairo_traps_t *traps, - double x, double y); - -cairo_private void -_cairo_traps_extents (const cairo_traps_t *traps, - cairo_box_t *extents); - -cairo_private cairo_int_status_t -_cairo_traps_extract_region (cairo_traps_t *traps, - cairo_antialias_t antialias, - cairo_region_t **region); - -cairo_private cairo_bool_t -_cairo_traps_to_boxes (cairo_traps_t *traps, - cairo_antialias_t antialias, - cairo_boxes_t *boxes); - -cairo_private cairo_status_t -_cairo_traps_path (const cairo_traps_t *traps, - cairo_path_fixed_t *path); - -cairo_private cairo_int_status_t -_cairo_rasterise_polygon_to_traps (cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias, - cairo_traps_t *traps); - -CAIRO_END_DECLS - -#endif /* CAIRO_TRAPS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps.c deleted file mode 100644 index 3aa0052f91f..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-traps.c +++ /dev/null @@ -1,1123 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* - * Copyright © 2002 Keith Packard - * Copyright © 2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith R. Packard - * Carl D. Worth - * - * 2002-07-15: Converted from XRenderCompositeDoublePoly to #cairo_trap_t. Carl D. Worth - */ - -#include "cairoint.h" - -#include "cairo-box-inline.h" -#include "cairo-boxes-private.h" -#include "cairo-error-private.h" -#include "cairo-line-private.h" -#include "cairo-region-private.h" -#include "cairo-slope-private.h" -#include "cairo-traps-private.h" -#include "cairo-spans-private.h" - -/* private functions */ - -void -_cairo_traps_init (cairo_traps_t *traps) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (traps, sizeof (cairo_traps_t))); - - traps->status = CAIRO_STATUS_SUCCESS; - - traps->maybe_region = 1; - traps->is_rectilinear = 0; - traps->is_rectangular = 0; - - traps->num_traps = 0; - - traps->traps_size = ARRAY_LENGTH (traps->traps_embedded); - traps->traps = traps->traps_embedded; - - traps->num_limits = 0; - traps->has_intersections = FALSE; -} - -void -_cairo_traps_limit (cairo_traps_t *traps, - const cairo_box_t *limits, - int num_limits) -{ - int i; - - traps->limits = limits; - traps->num_limits = num_limits; - - traps->bounds = limits[0]; - for (i = 1; i < num_limits; i++) - _cairo_box_add_box (&traps->bounds, &limits[i]); -} - -void -_cairo_traps_init_with_clip (cairo_traps_t *traps, - const cairo_clip_t *clip) -{ - _cairo_traps_init (traps); - if (clip) - _cairo_traps_limit (traps, clip->boxes, clip->num_boxes); -} - -void -_cairo_traps_clear (cairo_traps_t *traps) -{ - traps->status = CAIRO_STATUS_SUCCESS; - - traps->maybe_region = 1; - traps->is_rectilinear = 0; - traps->is_rectangular = 0; - - traps->num_traps = 0; - traps->has_intersections = FALSE; -} - -void -_cairo_traps_fini (cairo_traps_t *traps) -{ - if (traps->traps != traps->traps_embedded) - free (traps->traps); - - VG (VALGRIND_MAKE_MEM_NOACCESS (traps, sizeof (cairo_traps_t))); -} - -/* make room for at least one more trap */ -static cairo_bool_t -_cairo_traps_grow (cairo_traps_t *traps) -{ - cairo_trapezoid_t *new_traps; - int new_size = 4 * traps->traps_size; - - if (CAIRO_INJECT_FAULT ()) { - traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - if (traps->traps == traps->traps_embedded) { - new_traps = _cairo_malloc_ab (new_size, sizeof (cairo_trapezoid_t)); - if (new_traps != NULL) - memcpy (new_traps, traps->traps, sizeof (traps->traps_embedded)); - } else { - new_traps = _cairo_realloc_ab (traps->traps, - new_size, sizeof (cairo_trapezoid_t)); - } - - if (unlikely (new_traps == NULL)) { - traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - traps->traps = new_traps; - traps->traps_size = new_size; - return TRUE; -} - -void -_cairo_traps_add_trap (cairo_traps_t *traps, - cairo_fixed_t top, cairo_fixed_t bottom, - const cairo_line_t *left, - const cairo_line_t *right) -{ - cairo_trapezoid_t *trap; - - assert (left->p1.y != left->p2.y); - assert (right->p1.y != right->p2.y); - assert (bottom > top); - - if (unlikely (traps->num_traps == traps->traps_size)) { - if (unlikely (! _cairo_traps_grow (traps))) - return; - } - - trap = &traps->traps[traps->num_traps++]; - trap->top = top; - trap->bottom = bottom; - trap->left = *left; - trap->right = *right; -} - -static void -_cairo_traps_add_clipped_trap (cairo_traps_t *traps, - cairo_fixed_t _top, cairo_fixed_t _bottom, - const cairo_line_t *_left, - const cairo_line_t *_right) -{ - /* Note: With the goofy trapezoid specification, (where an - * arbitrary two points on the lines can specified for the left - * and right edges), these limit checks would not work in - * general. For example, one can imagine a trapezoid entirely - * within the limits, but with two points used to specify the left - * edge entirely to the right of the limits. Fortunately, for our - * purposes, cairo will never generate such a crazy - * trapezoid. Instead, cairo always uses for its points the - * extreme positions of the edge that are visible on at least some - * trapezoid. With this constraint, it's impossible for both - * points to be outside the limits while the relevant edge is - * entirely inside the limits. - */ - if (traps->num_limits) { - const cairo_box_t *b = &traps->bounds; - cairo_fixed_t top = _top, bottom = _bottom; - cairo_line_t left = *_left, right = *_right; - - /* Trivially reject if trapezoid is entirely to the right or - * to the left of the limits. */ - if (left.p1.x >= b->p2.x && left.p2.x >= b->p2.x) - return; - - if (right.p1.x <= b->p1.x && right.p2.x <= b->p1.x) - return; - - /* And reject if the trapezoid is entirely above or below */ - if (top >= b->p2.y || bottom <= b->p1.y) - return; - - /* Otherwise, clip the trapezoid to the limits. We only clip - * where an edge is entirely outside the limits. If we wanted - * to be more clever, we could handle cases where a trapezoid - * edge intersects the edge of the limits, but that would - * require slicing this trapezoid into multiple trapezoids, - * and I'm not sure the effort would be worth it. */ - if (top < b->p1.y) - top = b->p1.y; - - if (bottom > b->p2.y) - bottom = b->p2.y; - - if (left.p1.x <= b->p1.x && left.p2.x <= b->p1.x) - left.p1.x = left.p2.x = b->p1.x; - - if (right.p1.x >= b->p2.x && right.p2.x >= b->p2.x) - right.p1.x = right.p2.x = b->p2.x; - - /* Trivial discards for empty trapezoids that are likely to - * be produced by our tessellators (most notably convex_quad - * when given a simple rectangle). - */ - if (top >= bottom) - return; - - /* cheap colinearity check */ - if (right.p1.x <= left.p1.x && right.p1.y == left.p1.y && - right.p2.x <= left.p2.x && right.p2.y == left.p2.y) - return; - - _cairo_traps_add_trap (traps, top, bottom, &left, &right); - } else - _cairo_traps_add_trap (traps, _top, _bottom, _left, _right); -} - -static int -_compare_point_fixed_by_y (const void *av, const void *bv) -{ - const cairo_point_t *a = av, *b = bv; - int ret = a->y - b->y; - if (ret == 0) - ret = a->x - b->x; - return ret; -} - -void -_cairo_traps_tessellate_convex_quad (cairo_traps_t *traps, - const cairo_point_t q[4]) -{ - int a, b, c, d; - int i; - cairo_slope_t ab, ad; - cairo_bool_t b_left_of_d; - cairo_line_t left; - cairo_line_t right; - - /* Choose a as a point with minimal y */ - a = 0; - for (i = 1; i < 4; i++) - if (_compare_point_fixed_by_y (&q[i], &q[a]) < 0) - a = i; - - /* b and d are adjacent to a, while c is opposite */ - b = (a + 1) % 4; - c = (a + 2) % 4; - d = (a + 3) % 4; - - /* Choose between b and d so that b.y is less than d.y */ - if (_compare_point_fixed_by_y (&q[d], &q[b]) < 0) { - b = (a + 3) % 4; - d = (a + 1) % 4; - } - - /* Without freedom left to choose anything else, we have four - * cases to tessellate. - * - * First, we have to determine the Y-axis sort of the four - * vertices, (either abcd or abdc). After that we need to detemine - * which edges will be "left" and which will be "right" in the - * resulting trapezoids. This can be determined by computing a - * slope comparison of ab and ad to determine if b is left of d or - * not. - * - * Note that "left of" here is in the sense of which edges should - * be the left vs. right edges of the trapezoid. In particular, b - * left of d does *not* mean that b.x is less than d.x. - * - * This should hopefully be made clear in the lame ASCII art - * below. Since the same slope comparison is used in all cases, we - * compute it before testing for the Y-value sort. */ - - /* Note: If a == b then the ab slope doesn't give us any - * information. In that case, we can replace it with the ac (or - * equivalenly the bc) slope which gives us exactly the same - * information we need. At worst the names of the identifiers ab - * and b_left_of_d are inaccurate in this case, (would be ac, and - * c_left_of_d). */ - if (q[a].x == q[b].x && q[a].y == q[b].y) - _cairo_slope_init (&ab, &q[a], &q[c]); - else - _cairo_slope_init (&ab, &q[a], &q[b]); - - _cairo_slope_init (&ad, &q[a], &q[d]); - - b_left_of_d = _cairo_slope_compare (&ab, &ad) > 0; - - if (q[c].y <= q[d].y) { - if (b_left_of_d) { - /* Y-sort is abcd and b is left of d, (slope(ab) > slope (ad)) - * - * top bot left right - * _a a a - * / / /| |\ a.y b.y ab ad - * b / b | b \ - * / / | | \ \ b.y c.y bc ad - * c / c | c \ - * | / \| \ \ c.y d.y cd ad - * d d d - */ - left.p1 = q[a]; left.p2 = q[b]; - right.p1 = q[a]; right.p2 = q[d]; - _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); - left.p1 = q[b]; left.p2 = q[c]; - _cairo_traps_add_clipped_trap (traps, q[b].y, q[c].y, &left, &right); - left.p1 = q[c]; left.p2 = q[d]; - _cairo_traps_add_clipped_trap (traps, q[c].y, q[d].y, &left, &right); - } else { - /* Y-sort is abcd and b is right of d, (slope(ab) <= slope (ad)) - * - * a a a_ - * /| |\ \ \ a.y b.y ad ab - * / b | b \ b - * / / | | \ \ b.y c.y ad bc - * / c | c \ c - * / / |/ \ | c.y d.y ad cd - * d d d - */ - left.p1 = q[a]; left.p2 = q[d]; - right.p1 = q[a]; right.p2 = q[b]; - _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); - right.p1 = q[b]; right.p2 = q[c]; - _cairo_traps_add_clipped_trap (traps, q[b].y, q[c].y, &left, &right); - right.p1 = q[c]; right.p2 = q[d]; - _cairo_traps_add_clipped_trap (traps, q[c].y, q[d].y, &left, &right); - } - } else { - if (b_left_of_d) { - /* Y-sort is abdc and b is left of d, (slope (ab) > slope (ad)) - * - * a a a - * // / \ |\ a.y b.y ab ad - * /b/ b \ b \ - * / / \ \ \ \ b.y d.y bc ad - * /d/ \ d \ d - * // \ / \| d.y c.y bc dc - * c c c - */ - left.p1 = q[a]; left.p2 = q[b]; - right.p1 = q[a]; right.p2 = q[d]; - _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); - left.p1 = q[b]; left.p2 = q[c]; - _cairo_traps_add_clipped_trap (traps, q[b].y, q[d].y, &left, &right); - right.p1 = q[d]; right.p2 = q[c]; - _cairo_traps_add_clipped_trap (traps, q[d].y, q[c].y, &left, &right); - } else { - /* Y-sort is abdc and b is right of d, (slope (ab) <= slope (ad)) - * - * a a a - * /| / \ \\ a.y b.y ad ab - * / b / b \b\ - * / / / / \ \ b.y d.y ad bc - * d / d / \d\ - * |/ \ / \\ d.y c.y dc bc - * c c c - */ - left.p1 = q[a]; left.p2 = q[d]; - right.p1 = q[a]; right.p2 = q[b]; - _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); - right.p1 = q[b]; right.p2 = q[c]; - _cairo_traps_add_clipped_trap (traps, q[b].y, q[d].y, &left, &right); - left.p1 = q[d]; left.p2 = q[c]; - _cairo_traps_add_clipped_trap (traps, q[d].y, q[c].y, &left, &right); - } - } -} - -static void add_tri (cairo_traps_t *traps, - int y1, int y2, - const cairo_line_t *left, - const cairo_line_t *right) -{ - if (y2 < y1) { - int tmp = y1; - y1 = y2; - y2 = tmp; - } - - if (cairo_lines_compare_at_y (left, right, y1) > 0) { - const cairo_line_t *tmp = left; - left = right; - right = tmp; - } - - _cairo_traps_add_clipped_trap (traps, y1, y2, left, right); -} - -void -_cairo_traps_tessellate_triangle_with_edges (cairo_traps_t *traps, - const cairo_point_t t[3], - const cairo_point_t edges[4]) -{ - cairo_line_t lines[3]; - - if (edges[0].y <= edges[1].y) { - lines[0].p1 = edges[0]; - lines[0].p2 = edges[1]; - } else { - lines[0].p1 = edges[1]; - lines[0].p2 = edges[0]; - } - - if (edges[2].y <= edges[3].y) { - lines[1].p1 = edges[2]; - lines[1].p2 = edges[3]; - } else { - lines[1].p1 = edges[3]; - lines[1].p2 = edges[2]; - } - - if (t[1].y == t[2].y) { - add_tri (traps, t[0].y, t[1].y, &lines[0], &lines[1]); - return; - } - - if (t[1].y <= t[2].y) { - lines[2].p1 = t[1]; - lines[2].p2 = t[2]; - } else { - lines[2].p1 = t[2]; - lines[2].p2 = t[1]; - } - - if (((t[1].y - t[0].y) < 0) ^ ((t[2].y - t[0].y) < 0)) { - add_tri (traps, t[0].y, t[1].y, &lines[0], &lines[2]); - add_tri (traps, t[0].y, t[2].y, &lines[1], &lines[2]); - } else if (abs(t[1].y - t[0].y) < abs(t[2].y - t[0].y)) { - add_tri (traps, t[0].y, t[1].y, &lines[0], &lines[1]); - add_tri (traps, t[1].y, t[2].y, &lines[2], &lines[1]); - } else { - add_tri (traps, t[0].y, t[2].y, &lines[1], &lines[0]); - add_tri (traps, t[1].y, t[2].y, &lines[2], &lines[0]); - } -} - -/** - * _cairo_traps_init_boxes: - * @traps: a #cairo_traps_t - * @box: an array box that will each be converted to a single trapezoid - * to store in @traps. - * - * Initializes a #cairo_traps_t to contain an array of rectangular - * trapezoids. - **/ -cairo_status_t -_cairo_traps_init_boxes (cairo_traps_t *traps, - const cairo_boxes_t *boxes) -{ - cairo_trapezoid_t *trap; - const struct _cairo_boxes_chunk *chunk; - - _cairo_traps_init (traps); - - while (traps->traps_size < boxes->num_boxes) { - if (unlikely (! _cairo_traps_grow (traps))) { - _cairo_traps_fini (traps); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - traps->num_traps = boxes->num_boxes; - traps->is_rectilinear = TRUE; - traps->is_rectangular = TRUE; - traps->maybe_region = boxes->is_pixel_aligned; - - trap = &traps->traps[0]; - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box; - int i; - - box = chunk->base; - for (i = 0; i < chunk->count; i++) { - trap->top = box->p1.y; - trap->bottom = box->p2.y; - - trap->left.p1 = box->p1; - trap->left.p2.x = box->p1.x; - trap->left.p2.y = box->p2.y; - - trap->right.p1.x = box->p2.x; - trap->right.p1.y = box->p1.y; - trap->right.p2 = box->p2; - - box++, trap++; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t -_cairo_traps_tessellate_rectangle (cairo_traps_t *traps, - const cairo_point_t *top_left, - const cairo_point_t *bottom_right) -{ - cairo_line_t left; - cairo_line_t right; - cairo_fixed_t top, bottom; - - if (top_left->y == bottom_right->y) - return CAIRO_STATUS_SUCCESS; - - if (top_left->x == bottom_right->x) - return CAIRO_STATUS_SUCCESS; - - left.p1.x = left.p2.x = top_left->x; - left.p1.y = right.p1.y = top_left->y; - right.p1.x = right.p2.x = bottom_right->x; - left.p2.y = right.p2.y = bottom_right->y; - - top = top_left->y; - bottom = bottom_right->y; - - if (traps->num_limits) { - cairo_bool_t reversed; - int n; - - if (top >= traps->bounds.p2.y || bottom <= traps->bounds.p1.y) - return CAIRO_STATUS_SUCCESS; - - /* support counter-clockwise winding for rectangular tessellation */ - reversed = top_left->x > bottom_right->x; - if (reversed) { - right.p1.x = right.p2.x = top_left->x; - left.p1.x = left.p2.x = bottom_right->x; - } - - if (left.p1.x >= traps->bounds.p2.x || right.p1.x <= traps->bounds.p1.x) - return CAIRO_STATUS_SUCCESS; - - for (n = 0; n < traps->num_limits; n++) { - const cairo_box_t *limits = &traps->limits[n]; - cairo_line_t _left, _right; - cairo_fixed_t _top, _bottom; - - if (top >= limits->p2.y) - continue; - if (bottom <= limits->p1.y) - continue; - - /* Trivially reject if trapezoid is entirely to the right or - * to the left of the limits. */ - if (left.p1.x >= limits->p2.x) - continue; - if (right.p1.x <= limits->p1.x) - continue; - - /* Otherwise, clip the trapezoid to the limits. */ - _top = top; - if (_top < limits->p1.y) - _top = limits->p1.y; - - _bottom = bottom; - if (_bottom > limits->p2.y) - _bottom = limits->p2.y; - - if (_bottom <= _top) - continue; - - _left = left; - if (_left.p1.x < limits->p1.x) { - _left.p1.x = limits->p1.x; - _left.p1.y = limits->p1.y; - _left.p2.x = limits->p1.x; - _left.p2.y = limits->p2.y; - } - - _right = right; - if (_right.p1.x > limits->p2.x) { - _right.p1.x = limits->p2.x; - _right.p1.y = limits->p1.y; - _right.p2.x = limits->p2.x; - _right.p2.y = limits->p2.y; - } - - if (left.p1.x >= right.p1.x) - continue; - - if (reversed) - _cairo_traps_add_trap (traps, _top, _bottom, &_right, &_left); - else - _cairo_traps_add_trap (traps, _top, _bottom, &_left, &_right); - } - } else { - _cairo_traps_add_trap (traps, top, bottom, &left, &right); - } - - return traps->status; -} - -void -_cairo_traps_translate (cairo_traps_t *traps, int x, int y) -{ - cairo_fixed_t xoff, yoff; - cairo_trapezoid_t *t; - int i; - - /* Ugh. The cairo_composite/(Render) interface doesn't allow - an offset for the trapezoids. Need to manually shift all - the coordinates to align with the offset origin of the - intermediate surface. */ - - xoff = _cairo_fixed_from_int (x); - yoff = _cairo_fixed_from_int (y); - - for (i = 0, t = traps->traps; i < traps->num_traps; i++, t++) { - t->top += yoff; - t->bottom += yoff; - t->left.p1.x += xoff; - t->left.p1.y += yoff; - t->left.p2.x += xoff; - t->left.p2.y += yoff; - t->right.p1.x += xoff; - t->right.p1.y += yoff; - t->right.p2.x += xoff; - t->right.p2.y += yoff; - } -} - -void -_cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps, - cairo_trapezoid_t *src_traps, - int num_traps, - double tx, double ty, - double sx, double sy) -{ - int i; - cairo_fixed_t xoff = _cairo_fixed_from_double (tx); - cairo_fixed_t yoff = _cairo_fixed_from_double (ty); - - if (sx == 1.0 && sy == 1.0) { - for (i = 0; i < num_traps; i++) { - offset_traps[i].top = src_traps[i].top + yoff; - offset_traps[i].bottom = src_traps[i].bottom + yoff; - offset_traps[i].left.p1.x = src_traps[i].left.p1.x + xoff; - offset_traps[i].left.p1.y = src_traps[i].left.p1.y + yoff; - offset_traps[i].left.p2.x = src_traps[i].left.p2.x + xoff; - offset_traps[i].left.p2.y = src_traps[i].left.p2.y + yoff; - offset_traps[i].right.p1.x = src_traps[i].right.p1.x + xoff; - offset_traps[i].right.p1.y = src_traps[i].right.p1.y + yoff; - offset_traps[i].right.p2.x = src_traps[i].right.p2.x + xoff; - offset_traps[i].right.p2.y = src_traps[i].right.p2.y + yoff; - } - } else { - cairo_fixed_t xsc = _cairo_fixed_from_double (sx); - cairo_fixed_t ysc = _cairo_fixed_from_double (sy); - - for (i = 0; i < num_traps; i++) { - offset_traps[i].top = _cairo_fixed_mul (src_traps[i].top + yoff, ysc); - offset_traps[i].bottom = _cairo_fixed_mul (src_traps[i].bottom + yoff, ysc); - offset_traps[i].left.p1.x = _cairo_fixed_mul (src_traps[i].left.p1.x + xoff, xsc); - offset_traps[i].left.p1.y = _cairo_fixed_mul (src_traps[i].left.p1.y + yoff, ysc); - offset_traps[i].left.p2.x = _cairo_fixed_mul (src_traps[i].left.p2.x + xoff, xsc); - offset_traps[i].left.p2.y = _cairo_fixed_mul (src_traps[i].left.p2.y + yoff, ysc); - offset_traps[i].right.p1.x = _cairo_fixed_mul (src_traps[i].right.p1.x + xoff, xsc); - offset_traps[i].right.p1.y = _cairo_fixed_mul (src_traps[i].right.p1.y + yoff, ysc); - offset_traps[i].right.p2.x = _cairo_fixed_mul (src_traps[i].right.p2.x + xoff, xsc); - offset_traps[i].right.p2.y = _cairo_fixed_mul (src_traps[i].right.p2.y + yoff, ysc); - } - } -} - -static cairo_bool_t -_cairo_trap_contains (cairo_trapezoid_t *t, cairo_point_t *pt) -{ - cairo_slope_t slope_left, slope_pt, slope_right; - - if (t->top > pt->y) - return FALSE; - if (t->bottom < pt->y) - return FALSE; - - _cairo_slope_init (&slope_left, &t->left.p1, &t->left.p2); - _cairo_slope_init (&slope_pt, &t->left.p1, pt); - - if (_cairo_slope_compare (&slope_left, &slope_pt) < 0) - return FALSE; - - _cairo_slope_init (&slope_right, &t->right.p1, &t->right.p2); - _cairo_slope_init (&slope_pt, &t->right.p1, pt); - - if (_cairo_slope_compare (&slope_pt, &slope_right) < 0) - return FALSE; - - return TRUE; -} - -cairo_bool_t -_cairo_traps_contain (const cairo_traps_t *traps, - double x, double y) -{ - int i; - cairo_point_t point; - - point.x = _cairo_fixed_from_double (x); - point.y = _cairo_fixed_from_double (y); - - for (i = 0; i < traps->num_traps; i++) { - if (_cairo_trap_contains (&traps->traps[i], &point)) - return TRUE; - } - - return FALSE; -} - -static cairo_fixed_t -_line_compute_intersection_x_for_y (const cairo_line_t *line, - cairo_fixed_t y) -{ - return _cairo_edge_compute_intersection_x_for_y (&line->p1, &line->p2, y); -} - -void -_cairo_traps_extents (const cairo_traps_t *traps, - cairo_box_t *extents) -{ - int i; - - if (traps->num_traps == 0) { - extents->p1.x = extents->p1.y = 0; - extents->p2.x = extents->p2.y = 0; - return; - } - - extents->p1.x = extents->p1.y = INT32_MAX; - extents->p2.x = extents->p2.y = INT32_MIN; - - for (i = 0; i < traps->num_traps; i++) { - const cairo_trapezoid_t *trap = &traps->traps[i]; - - if (trap->top < extents->p1.y) - extents->p1.y = trap->top; - if (trap->bottom > extents->p2.y) - extents->p2.y = trap->bottom; - - if (trap->left.p1.x < extents->p1.x) { - cairo_fixed_t x = trap->left.p1.x; - if (trap->top != trap->left.p1.y) { - x = _line_compute_intersection_x_for_y (&trap->left, - trap->top); - if (x < extents->p1.x) - extents->p1.x = x; - } else - extents->p1.x = x; - } - if (trap->left.p2.x < extents->p1.x) { - cairo_fixed_t x = trap->left.p2.x; - if (trap->bottom != trap->left.p2.y) { - x = _line_compute_intersection_x_for_y (&trap->left, - trap->bottom); - if (x < extents->p1.x) - extents->p1.x = x; - } else - extents->p1.x = x; - } - - if (trap->right.p1.x > extents->p2.x) { - cairo_fixed_t x = trap->right.p1.x; - if (trap->top != trap->right.p1.y) { - x = _line_compute_intersection_x_for_y (&trap->right, - trap->top); - if (x > extents->p2.x) - extents->p2.x = x; - } else - extents->p2.x = x; - } - if (trap->right.p2.x > extents->p2.x) { - cairo_fixed_t x = trap->right.p2.x; - if (trap->bottom != trap->right.p2.y) { - x = _line_compute_intersection_x_for_y (&trap->right, - trap->bottom); - if (x > extents->p2.x) - extents->p2.x = x; - } else - extents->p2.x = x; - } - } -} - -static cairo_bool_t -_mono_edge_is_vertical (const cairo_line_t *line) -{ - return _cairo_fixed_integer_round_down (line->p1.x) == _cairo_fixed_integer_round_down (line->p2.x); -} - -static cairo_bool_t -_traps_are_pixel_aligned (cairo_traps_t *traps, - cairo_antialias_t antialias) -{ - int i; - - if (antialias == CAIRO_ANTIALIAS_NONE) { - for (i = 0; i < traps->num_traps; i++) { - if (! _mono_edge_is_vertical (&traps->traps[i].left) || - ! _mono_edge_is_vertical (&traps->traps[i].right)) - { - traps->maybe_region = FALSE; - return FALSE; - } - } - } else { - for (i = 0; i < traps->num_traps; i++) { - if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x || - traps->traps[i].right.p1.x != traps->traps[i].right.p2.x || - ! _cairo_fixed_is_integer (traps->traps[i].top) || - ! _cairo_fixed_is_integer (traps->traps[i].bottom) || - ! _cairo_fixed_is_integer (traps->traps[i].left.p1.x) || - ! _cairo_fixed_is_integer (traps->traps[i].right.p1.x)) - { - traps->maybe_region = FALSE; - return FALSE; - } - } - } - - return TRUE; -} - -/** - * _cairo_traps_extract_region: - * @traps: a #cairo_traps_t - * @region: a #cairo_region_t - * - * Determines if a set of trapezoids are exactly representable as a - * cairo region. If so, the passed-in region is initialized to - * the area representing the given traps. It should be finalized - * with cairo_region_fini(). If not, %CAIRO_INT_STATUS_UNSUPPORTED - * is returned. - * - * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_INT_STATUS_UNSUPPORTED - * or %CAIRO_STATUS_NO_MEMORY - **/ -cairo_int_status_t -_cairo_traps_extract_region (cairo_traps_t *traps, - cairo_antialias_t antialias, - cairo_region_t **region) -{ - cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)]; - cairo_rectangle_int_t *rects = stack_rects; - cairo_int_status_t status; - int i, rect_count; - - /* we only treat this a hint... */ - if (antialias != CAIRO_ANTIALIAS_NONE && ! traps->maybe_region) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _traps_are_pixel_aligned (traps, antialias)) { - traps->maybe_region = FALSE; - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (traps->num_traps > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (traps->num_traps, sizeof (cairo_rectangle_int_t)); - - if (unlikely (rects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - rect_count = 0; - for (i = 0; i < traps->num_traps; i++) { - int x1, y1, x2, y2; - - if (antialias == CAIRO_ANTIALIAS_NONE) { - x1 = _cairo_fixed_integer_round_down (traps->traps[i].left.p1.x); - y1 = _cairo_fixed_integer_round_down (traps->traps[i].top); - x2 = _cairo_fixed_integer_round_down (traps->traps[i].right.p1.x); - y2 = _cairo_fixed_integer_round_down (traps->traps[i].bottom); - } else { - x1 = _cairo_fixed_integer_part (traps->traps[i].left.p1.x); - y1 = _cairo_fixed_integer_part (traps->traps[i].top); - x2 = _cairo_fixed_integer_part (traps->traps[i].right.p1.x); - y2 = _cairo_fixed_integer_part (traps->traps[i].bottom); - } - - if (x2 > x1 && y2 > y1) { - rects[rect_count].x = x1; - rects[rect_count].y = y1; - rects[rect_count].width = x2 - x1; - rects[rect_count].height = y2 - y1; - rect_count++; - } - } - - - *region = cairo_region_create_rectangles (rects, rect_count); - status = (*region)->status; - - if (rects != stack_rects) - free (rects); - - return status; -} - -cairo_bool_t -_cairo_traps_to_boxes (cairo_traps_t *traps, - cairo_antialias_t antialias, - cairo_boxes_t *boxes) -{ - int i; - - for (i = 0; i < traps->num_traps; i++) { - if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x || - traps->traps[i].right.p1.x != traps->traps[i].right.p2.x) - return FALSE; - } - - _cairo_boxes_init (boxes); - - boxes->num_boxes = traps->num_traps; - boxes->chunks.base = (cairo_box_t *) traps->traps; - boxes->chunks.count = traps->num_traps; - boxes->chunks.size = traps->num_traps; - - if (antialias != CAIRO_ANTIALIAS_NONE) { - for (i = 0; i < traps->num_traps; i++) { - /* Note the traps and boxes alias so we need to take the local copies first. */ - cairo_fixed_t x1 = traps->traps[i].left.p1.x; - cairo_fixed_t x2 = traps->traps[i].right.p1.x; - cairo_fixed_t y1 = traps->traps[i].top; - cairo_fixed_t y2 = traps->traps[i].bottom; - - boxes->chunks.base[i].p1.x = x1; - boxes->chunks.base[i].p1.y = y1; - boxes->chunks.base[i].p2.x = x2; - boxes->chunks.base[i].p2.y = y2; - - if (boxes->is_pixel_aligned) { - boxes->is_pixel_aligned = - _cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) && - _cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2); - } - } - } else { - boxes->is_pixel_aligned = TRUE; - - for (i = 0; i < traps->num_traps; i++) { - /* Note the traps and boxes alias so we need to take the local copies first. */ - cairo_fixed_t x1 = traps->traps[i].left.p1.x; - cairo_fixed_t x2 = traps->traps[i].right.p1.x; - cairo_fixed_t y1 = traps->traps[i].top; - cairo_fixed_t y2 = traps->traps[i].bottom; - - /* round down here to match Pixman's behavior when using traps. */ - boxes->chunks.base[i].p1.x = _cairo_fixed_round_down (x1); - boxes->chunks.base[i].p1.y = _cairo_fixed_round_down (y1); - boxes->chunks.base[i].p2.x = _cairo_fixed_round_down (x2); - boxes->chunks.base[i].p2.y = _cairo_fixed_round_down (y2); - } - } - - return TRUE; -} - -/* moves trap points such that they become the actual corners of the trapezoid */ -static void -_sanitize_trap (cairo_trapezoid_t *t) -{ - cairo_trapezoid_t s = *t; - -#define FIX(lr, tb, p) \ - if (t->lr.p.y != t->tb) { \ - t->lr.p.x = s.lr.p2.x + _cairo_fixed_mul_div_floor (s.lr.p1.x - s.lr.p2.x, s.tb - s.lr.p2.y, s.lr.p1.y - s.lr.p2.y); \ - t->lr.p.y = s.tb; \ - } - FIX (left, top, p1); - FIX (left, bottom, p2); - FIX (right, top, p1); - FIX (right, bottom, p2); -} - -cairo_private cairo_status_t -_cairo_traps_path (const cairo_traps_t *traps, - cairo_path_fixed_t *path) -{ - int i; - - for (i = 0; i < traps->num_traps; i++) { - cairo_status_t status; - cairo_trapezoid_t trap = traps->traps[i]; - - if (trap.top == trap.bottom) - continue; - - _sanitize_trap (&trap); - - status = _cairo_path_fixed_move_to (path, trap.left.p1.x, trap.top); - if (unlikely (status)) return status; - status = _cairo_path_fixed_line_to (path, trap.right.p1.x, trap.top); - if (unlikely (status)) return status; - status = _cairo_path_fixed_line_to (path, trap.right.p2.x, trap.bottom); - if (unlikely (status)) return status; - status = _cairo_path_fixed_line_to (path, trap.left.p2.x, trap.bottom); - if (unlikely (status)) return status; - status = _cairo_path_fixed_close_path (path); - if (unlikely (status)) return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_debug_print_traps (FILE *file, const cairo_traps_t *traps) -{ - cairo_box_t extents; - int n; - -#if 0 - if (traps->has_limits) { - printf ("%s: limits=(%d, %d, %d, %d)\n", - filename, - traps->limits.p1.x, traps->limits.p1.y, - traps->limits.p2.x, traps->limits.p2.y); - } -#endif - - _cairo_traps_extents (traps, &extents); - fprintf (file, "extents=(%d, %d, %d, %d)\n", - extents.p1.x, extents.p1.y, - extents.p2.x, extents.p2.y); - - for (n = 0; n < traps->num_traps; n++) { - fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", - traps->traps[n].top, - traps->traps[n].bottom, - traps->traps[n].left.p1.x, - traps->traps[n].left.p1.y, - traps->traps[n].left.p2.x, - traps->traps[n].left.p2.y, - traps->traps[n].right.p1.x, - traps->traps[n].right.p1.y, - traps->traps[n].right.p2.x, - traps->traps[n].right.p2.y); - } -} - -struct cairo_trap_renderer { - cairo_span_renderer_t base; - cairo_traps_t *traps; -}; - -static cairo_status_t -span_to_traps (void *abstract_renderer, int y, int h, - const cairo_half_open_span_t *spans, unsigned num_spans) -{ - struct cairo_trap_renderer *r = abstract_renderer; - cairo_fixed_t top, bot; - - if (num_spans == 0) - return CAIRO_STATUS_SUCCESS; - - top = _cairo_fixed_from_int (y); - bot = _cairo_fixed_from_int (y + h); - do { - if (spans[0].coverage) { - cairo_fixed_t x0 = _cairo_fixed_from_int(spans[0].x); - cairo_fixed_t x1 = _cairo_fixed_from_int(spans[1].x); - cairo_line_t left = { { x0, top }, { x0, bot } }, - right = { { x1, top }, { x1, bot } }; - _cairo_traps_add_trap (r->traps, top, bot, &left, &right); - } - spans++; - } while (--num_spans > 1); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_rasterise_polygon_to_traps (cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias, - cairo_traps_t *traps) -{ - struct cairo_trap_renderer renderer; - cairo_scan_converter_t *converter; - cairo_int_status_t status; - cairo_rectangle_int_t r; - - TRACE ((stderr, "%s: fill_rule=%d, antialias=%d\n", - __FUNCTION__, fill_rule, antialias)); - assert(antialias == CAIRO_ANTIALIAS_NONE); - - renderer.traps = traps; - renderer.base.render_rows = span_to_traps; - - _cairo_box_round_to_rectangle (&polygon->extents, &r); - converter = _cairo_mono_scan_converter_create (r.x, r.y, - r.x + r.width, - r.y + r.height, - fill_rule); - status = _cairo_mono_scan_converter_add_polygon (converter, polygon); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = converter->generate (converter, &renderer.base); - converter->destroy (converter); - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip-private.h deleted file mode 100644 index ccd28799e82..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip-private.h +++ /dev/null @@ -1,94 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_TRISTRIP_PRIVATE_H -#define CAIRO_TRISTRIP_PRIVATE_H - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" -#include "cairo-types-private.h" - -CAIRO_BEGIN_DECLS - -struct _cairo_tristrip { - cairo_status_t status; - - /* XXX clipping */ - - const cairo_box_t *limits; - int num_limits; - - int num_points; - int size_points; - cairo_point_t *points; - cairo_point_t points_embedded[64]; -}; - -cairo_private void -_cairo_tristrip_init (cairo_tristrip_t *strip); - -cairo_private void -_cairo_tristrip_limit (cairo_tristrip_t *strip, - const cairo_box_t *limits, - int num_limits); - -cairo_private void -_cairo_tristrip_init_with_clip (cairo_tristrip_t *strip, - const cairo_clip_t *clip); - -cairo_private void -_cairo_tristrip_translate (cairo_tristrip_t *strip, int x, int y); - -cairo_private void -_cairo_tristrip_move_to (cairo_tristrip_t *strip, - const cairo_point_t *point); - -cairo_private void -_cairo_tristrip_add_point (cairo_tristrip_t *strip, - const cairo_point_t *point); - -cairo_private void -_cairo_tristrip_extents (const cairo_tristrip_t *strip, - cairo_box_t *extents); - -cairo_private void -_cairo_tristrip_fini (cairo_tristrip_t *strip); - -#define _cairo_tristrip_status(T) ((T)->status) - -CAIRO_END_DECLS - -#endif /* CAIRO_TRISTRIP_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip.c deleted file mode 100644 index bb4972f5003..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-tristrip.c +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-error-private.h" -#include "cairo-tristrip-private.h" - -void -_cairo_tristrip_init (cairo_tristrip_t *strip) -{ - VG (VALGRIND_MAKE_MEM_UNDEFINED (strip, sizeof (cairo_tristrip_t))); - - strip->status = CAIRO_STATUS_SUCCESS; - - strip->num_limits = 0; - strip->num_points = 0; - - strip->size_points = ARRAY_LENGTH (strip->points_embedded); - strip->points = strip->points_embedded; -} - -void -_cairo_tristrip_fini (cairo_tristrip_t *strip) -{ - if (strip->points != strip->points_embedded) - free (strip->points); - - VG (VALGRIND_MAKE_MEM_NOACCESS (strip, sizeof (cairo_tristrip_t))); -} - - -void -_cairo_tristrip_limit (cairo_tristrip_t *strip, - const cairo_box_t *limits, - int num_limits) -{ - strip->limits = limits; - strip->num_limits = num_limits; -} - -void -_cairo_tristrip_init_with_clip (cairo_tristrip_t *strip, - const cairo_clip_t *clip) -{ - _cairo_tristrip_init (strip); - if (clip) - _cairo_tristrip_limit (strip, clip->boxes, clip->num_boxes); -} - -/* make room for at least one more trap */ -static cairo_bool_t -_cairo_tristrip_grow (cairo_tristrip_t *strip) -{ - cairo_point_t *points; - int new_size = 4 * strip->size_points; - - if (CAIRO_INJECT_FAULT ()) { - strip->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - if (strip->points == strip->points_embedded) { - points = _cairo_malloc_ab (new_size, sizeof (cairo_point_t)); - if (points != NULL) - memcpy (points, strip->points, sizeof (strip->points_embedded)); - } else { - points = _cairo_realloc_ab (strip->points, - new_size, sizeof (cairo_trapezoid_t)); - } - - if (unlikely (points == NULL)) { - strip->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - return FALSE; - } - - strip->points = points; - strip->size_points = new_size; - return TRUE; -} - -void -_cairo_tristrip_add_point (cairo_tristrip_t *strip, - const cairo_point_t *p) -{ - if (unlikely (strip->num_points == strip->size_points)) { - if (unlikely (! _cairo_tristrip_grow (strip))) - return; - } - - strip->points[strip->num_points++] = *p; -} - -/* Insert degenerate triangles to advance to the given point. The - * next point inserted must also be @p. */ -void -_cairo_tristrip_move_to (cairo_tristrip_t *strip, - const cairo_point_t *p) -{ - if (strip->num_points == 0) - return; - - _cairo_tristrip_add_point (strip, &strip->points[strip->num_points-1]); - _cairo_tristrip_add_point (strip, p); -#if 0 - /* and one more for luck! (to preserve cw/ccw ordering) */ - _cairo_tristrip_add_point (strip, p); -#endif -} - -void -_cairo_tristrip_translate (cairo_tristrip_t *strip, int x, int y) -{ - cairo_fixed_t xoff, yoff; - cairo_point_t *p; - int i; - - xoff = _cairo_fixed_from_int (x); - yoff = _cairo_fixed_from_int (y); - - for (i = 0, p = strip->points; i < strip->num_points; i++, p++) { - p->x += xoff; - p->y += yoff; - } -} - -void -_cairo_tristrip_extents (const cairo_tristrip_t *strip, - cairo_box_t *extents) -{ - int i; - - if (strip->num_points == 0) { - extents->p1.x = extents->p1.y = 0; - extents->p2.x = extents->p2.y = 0; - return; - } - - extents->p2 = extents->p1 = strip->points[0]; - for (i = 1; i < strip->num_points; i++) { - const cairo_point_t *p = &strip->points[i]; - - if (p->x < extents->p1.x) - extents->p1.x = p->x; - else if (p->x > extents->p2.x) - extents->p2.x = p->x; - - if (p->y < extents->p1.y) - extents->p1.y = p->y; - else if (p->y > extents->p2.y) - extents->p2.y = p->y; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset-private.h deleted file mode 100644 index dc9573216f3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset-private.h +++ /dev/null @@ -1,212 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Adrian Johnson - */ - -#ifndef CAIRO_TRUETYPE_SUBSET_PRIVATE_H -#define CAIRO_TRUETYPE_SUBSET_PRIVATE_H - -#include "cairoint.h" - -#if CAIRO_HAS_FONT_SUBSET - -/* The structs defined here should strictly follow the TrueType - * specification and not be padded. We use only 16-bit integer - * in their definition to guarantee that. The fields of type - * "FIXED" in the TT spec are broken into two *_1 and *_2 16-bit - * parts, and 64-bit members are broken into four. - * - * The test truetype-tables in the test suite makes sure that - * these tables have the right size. Please update that test - * if you add new tables/structs that should be packed. - */ - -#define MAKE_TT_TAG(a, b, c, d) (a<<24 | b<<16 | c<<8 | d) -#define TT_TAG_CFF MAKE_TT_TAG('C','F','F',' ') -#define TT_TAG_cmap MAKE_TT_TAG('c','m','a','p') -#define TT_TAG_cvt MAKE_TT_TAG('c','v','t',' ') -#define TT_TAG_fpgm MAKE_TT_TAG('f','p','g','m') -#define TT_TAG_glyf MAKE_TT_TAG('g','l','y','f') -#define TT_TAG_head MAKE_TT_TAG('h','e','a','d') -#define TT_TAG_hhea MAKE_TT_TAG('h','h','e','a') -#define TT_TAG_hmtx MAKE_TT_TAG('h','m','t','x') -#define TT_TAG_loca MAKE_TT_TAG('l','o','c','a') -#define TT_TAG_maxp MAKE_TT_TAG('m','a','x','p') -#define TT_TAG_name MAKE_TT_TAG('n','a','m','e') -#define TT_TAG_OS2 MAKE_TT_TAG('O','S','/','2') -#define TT_TAG_post MAKE_TT_TAG('p','o','s','t') -#define TT_TAG_prep MAKE_TT_TAG('p','r','e','p') - -/* All tt_* structs are big-endian */ -typedef struct _tt_cmap_index { - uint16_t platform; - uint16_t encoding; - uint32_t offset; -} tt_cmap_index_t; - -typedef struct _tt_cmap { - uint16_t version; - uint16_t num_tables; - tt_cmap_index_t index[1]; -} tt_cmap_t; - -typedef struct _segment_map { - uint16_t format; - uint16_t length; - uint16_t version; - uint16_t segCountX2; - uint16_t searchRange; - uint16_t entrySelector; - uint16_t rangeShift; - uint16_t endCount[1]; -} tt_segment_map_t; - -typedef struct _tt_head { - int16_t version_1; - int16_t version_2; - int16_t revision_1; - int16_t revision_2; - uint16_t checksum_1; - uint16_t checksum_2; - uint16_t magic_1; - uint16_t magic_2; - uint16_t flags; - uint16_t units_per_em; - int16_t created_1; - int16_t created_2; - int16_t created_3; - int16_t created_4; - int16_t modified_1; - int16_t modified_2; - int16_t modified_3; - int16_t modified_4; - int16_t x_min; /* FWORD */ - int16_t y_min; /* FWORD */ - int16_t x_max; /* FWORD */ - int16_t y_max; /* FWORD */ - uint16_t mac_style; - uint16_t lowest_rec_pppem; - int16_t font_direction_hint; - int16_t index_to_loc_format; - int16_t glyph_data_format; -} tt_head_t; - -typedef struct _tt_hhea { - int16_t version_1; - int16_t version_2; - int16_t ascender; /* FWORD */ - int16_t descender; /* FWORD */ - int16_t line_gap; /* FWORD */ - uint16_t advance_max_width; /* UFWORD */ - int16_t min_left_side_bearing; /* FWORD */ - int16_t min_right_side_bearing; /* FWORD */ - int16_t x_max_extent; /* FWORD */ - int16_t caret_slope_rise; - int16_t caret_slope_run; - int16_t reserved[5]; - int16_t metric_data_format; - uint16_t num_hmetrics; -} tt_hhea_t; - -typedef struct _tt_maxp { - int16_t version_1; - int16_t version_2; - uint16_t num_glyphs; - uint16_t max_points; - uint16_t max_contours; - uint16_t max_composite_points; - uint16_t max_composite_contours; - uint16_t max_zones; - uint16_t max_twilight_points; - uint16_t max_storage; - uint16_t max_function_defs; - uint16_t max_instruction_defs; - uint16_t max_stack_elements; - uint16_t max_size_of_instructions; - uint16_t max_component_elements; - uint16_t max_component_depth; -} tt_maxp_t; - -typedef struct _tt_name_record { - uint16_t platform; - uint16_t encoding; - uint16_t language; - uint16_t name; - uint16_t length; - uint16_t offset; -} tt_name_record_t; - -typedef struct _tt_name { - uint16_t format; - uint16_t num_records; - uint16_t strings_offset; - tt_name_record_t records[1]; -} tt_name_t; - - -/* bitmask for fsSelection field */ -#define TT_FS_SELECTION_ITALIC 1 -#define TT_FS_SELECTION_BOLD 32 - -/* _unused fields are defined in TT spec but not used by cairo */ -typedef struct _tt_os2 { - uint16_t _unused1[2]; - uint16_t usWeightClass; - uint16_t _unused2[28]; - uint16_t fsSelection; - uint16_t _unused3[11]; -} tt_os2_t; - -/* composite_glyph_t flags */ -#define TT_ARG_1_AND_2_ARE_WORDS 0x0001 -#define TT_WE_HAVE_A_SCALE 0x0008 -#define TT_MORE_COMPONENTS 0x0020 -#define TT_WE_HAVE_AN_X_AND_Y_SCALE 0x0040 -#define TT_WE_HAVE_A_TWO_BY_TWO 0x0080 - -typedef struct _tt_composite_glyph { - uint16_t flags; - uint16_t index; - uint16_t args[6]; /* 1 to 6 arguments depending on value of flags */ -} tt_composite_glyph_t; - -typedef struct _tt_glyph_data { - int16_t num_contours; - int8_t data[8]; - tt_composite_glyph_t glyph; -} tt_glyph_data_t; - -#endif /* CAIRO_HAS_FONT_SUBSET */ - -#endif /* CAIRO_TRUETYPE_SUBSET_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset.c deleted file mode 100644 index 645a89abf21..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-truetype-subset.c +++ /dev/null @@ -1,1631 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Adrian Johnson - */ - -/* - * Useful links: - * http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html - * http://www.microsoft.com/typography/specs/default.htm - */ - -#define _BSD_SOURCE /* for snprintf(), strdup() */ -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-truetype-subset-private.h" - - -typedef struct subset_glyph subset_glyph_t; -struct subset_glyph { - int parent_index; - unsigned long location; -}; - -typedef struct _cairo_truetype_font cairo_truetype_font_t; - -typedef struct table table_t; -struct table { - unsigned long tag; - cairo_status_t (*write) (cairo_truetype_font_t *font, unsigned long tag); - int pos; /* position in the font directory */ -}; - -struct _cairo_truetype_font { - - cairo_scaled_font_subset_t *scaled_font_subset; - - table_t truetype_tables[10]; - int num_tables; - - struct { - char *font_name; - char *ps_name; - unsigned int num_glyphs; - int *widths; - long x_min, y_min, x_max, y_max; - long ascent, descent; - int units_per_em; - } base; - - subset_glyph_t *glyphs; - const cairo_scaled_font_backend_t *backend; - int num_glyphs_in_face; - int checksum_index; - cairo_array_t output; - cairo_array_t string_offsets; - unsigned long last_offset; - unsigned long last_boundary; - int *parent_to_subset; - cairo_status_t status; - cairo_bool_t is_pdf; -}; - -/* - * Test that the structs we define for TrueType tables have the - * correct size, ie. they are not padded. - */ -#define check(T, S) COMPILE_TIME_ASSERT (sizeof (T) == (S)) -check (tt_head_t, 54); -check (tt_hhea_t, 36); -check (tt_maxp_t, 32); -check (tt_name_record_t, 12); -check (tt_name_t, 18); -check (tt_name_t, 18); -check (tt_composite_glyph_t, 16); -check (tt_glyph_data_t, 26); -#undef check - -static cairo_status_t -cairo_truetype_font_use_glyph (cairo_truetype_font_t *font, - unsigned short glyph, - unsigned short *out); - -#define SFNT_VERSION 0x00010000 -#define SFNT_STRING_MAX_LENGTH 65535 - -static cairo_status_t -_cairo_truetype_font_set_error (cairo_truetype_font_t *font, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS || - status == (int)CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - _cairo_status_set_error (&font->status, status); - - return _cairo_error (status); -} - -static cairo_status_t -_cairo_truetype_font_create (cairo_scaled_font_subset_t *scaled_font_subset, - cairo_bool_t is_pdf, - cairo_truetype_font_t **font_return) -{ - cairo_status_t status; - cairo_truetype_font_t *font; - const cairo_scaled_font_backend_t *backend; - tt_head_t head; - tt_hhea_t hhea; - tt_maxp_t maxp; - unsigned long size; - - backend = scaled_font_subset->scaled_font->backend; - if (!backend->load_truetype_table) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* FIXME: We should either support subsetting vertical fonts, or fail on - * vertical. Currently font_options_t doesn't have vertical flag, but - * it should be added in the future. For now, the freetype backend - * returns UNSUPPORTED in load_truetype_table if the font is vertical. - * - * if (cairo_font_options_get_vertical_layout (scaled_font_subset->scaled_font)) - * return CAIRO_INT_STATUS_UNSUPPORTED; - */ - - /* We need to use a fallback font generated from the synthesized outlines. */ - if (backend->is_synthetic && backend->is_synthetic (scaled_font_subset->scaled_font)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = sizeof (tt_head_t); - status = backend->load_truetype_table (scaled_font_subset->scaled_font, - TT_TAG_head, 0, - (unsigned char *) &head, - &size); - if (unlikely (status)) - return status; - - size = sizeof (tt_maxp_t); - status = backend->load_truetype_table (scaled_font_subset->scaled_font, - TT_TAG_maxp, 0, - (unsigned char *) &maxp, - &size); - if (unlikely (status)) - return status; - - size = sizeof (tt_hhea_t); - status = backend->load_truetype_table (scaled_font_subset->scaled_font, - TT_TAG_hhea, 0, - (unsigned char *) &hhea, - &size); - if (unlikely (status)) - return status; - - font = malloc (sizeof (cairo_truetype_font_t)); - if (unlikely (font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->backend = backend; - font->num_glyphs_in_face = be16_to_cpu (maxp.num_glyphs); - font->scaled_font_subset = scaled_font_subset; - - font->last_offset = 0; - font->last_boundary = 0; - _cairo_array_init (&font->output, sizeof (char)); - status = _cairo_array_grow_by (&font->output, 4096); - if (unlikely (status)) - goto fail1; - - font->glyphs = calloc (font->num_glyphs_in_face + 1, sizeof (subset_glyph_t)); - if (unlikely (font->glyphs == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - font->parent_to_subset = calloc (font->num_glyphs_in_face, sizeof (int)); - if (unlikely (font->parent_to_subset == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - - font->is_pdf = is_pdf; - font->base.num_glyphs = 0; - font->base.x_min = (int16_t) be16_to_cpu (head.x_min); - font->base.y_min = (int16_t) be16_to_cpu (head.y_min); - font->base.x_max = (int16_t) be16_to_cpu (head.x_max); - font->base.y_max = (int16_t) be16_to_cpu (head.y_max); - font->base.ascent = (int16_t) be16_to_cpu (hhea.ascender); - font->base.descent = (int16_t) be16_to_cpu (hhea.descender); - font->base.units_per_em = (int16_t) be16_to_cpu (head.units_per_em); - if (font->base.units_per_em == 0) - font->base.units_per_em = 2048; - - font->base.ps_name = NULL; - font->base.font_name = NULL; - status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font, - &font->base.ps_name, - &font->base.font_name); - if (_cairo_status_is_error (status)) - goto fail3; - - /* If the PS name is not found, create a CairoFont-x-y name. */ - if (font->base.ps_name == NULL) { - font->base.ps_name = malloc (30); - if (unlikely (font->base.ps_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - - snprintf(font->base.ps_name, 30, "CairoFont-%u-%u", - scaled_font_subset->font_id, - scaled_font_subset->subset_id); - } - - font->base.widths = calloc (font->num_glyphs_in_face, sizeof (int)); - if (unlikely (font->base.widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail4; - } - - _cairo_array_init (&font->string_offsets, sizeof (unsigned long)); - status = _cairo_array_grow_by (&font->string_offsets, 10); - if (unlikely (status)) - goto fail5; - - font->status = CAIRO_STATUS_SUCCESS; - - *font_return = font; - - return CAIRO_STATUS_SUCCESS; - - fail5: - _cairo_array_fini (&font->string_offsets); - free (font->base.widths); - fail4: - free (font->base.ps_name); - fail3: - free (font->parent_to_subset); - free (font->base.font_name); - fail2: - free (font->glyphs); - fail1: - _cairo_array_fini (&font->output); - free (font); - - return status; -} - -static void -cairo_truetype_font_destroy (cairo_truetype_font_t *font) -{ - _cairo_array_fini (&font->string_offsets); - free (font->base.widths); - free (font->base.ps_name); - free (font->base.font_name); - free (font->parent_to_subset); - free (font->glyphs); - _cairo_array_fini (&font->output); - free (font); -} - -static cairo_status_t -cairo_truetype_font_allocate_write_buffer (cairo_truetype_font_t *font, - size_t length, - unsigned char **buffer) -{ - cairo_status_t status; - - if (font->status) - return font->status; - - status = _cairo_array_allocate (&font->output, length, (void **) buffer); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - return CAIRO_STATUS_SUCCESS; -} - -static void -cairo_truetype_font_write (cairo_truetype_font_t *font, - const void *data, - size_t length) -{ - cairo_status_t status; - - if (font->status) - return; - - status = _cairo_array_append_multiple (&font->output, data, length); - if (unlikely (status)) - status = _cairo_truetype_font_set_error (font, status); -} - -static void -cairo_truetype_font_write_be16 (cairo_truetype_font_t *font, - uint16_t value) -{ - uint16_t be16_value; - - if (font->status) - return; - - be16_value = cpu_to_be16 (value); - cairo_truetype_font_write (font, &be16_value, sizeof be16_value); -} - -static void -cairo_truetype_font_write_be32 (cairo_truetype_font_t *font, - uint32_t value) -{ - uint32_t be32_value; - - if (font->status) - return; - - be32_value = cpu_to_be32 (value); - cairo_truetype_font_write (font, &be32_value, sizeof be32_value); -} - -static cairo_status_t -cairo_truetype_font_align_output (cairo_truetype_font_t *font, - unsigned long *aligned) -{ - int length, pad; - unsigned char *padding; - - length = _cairo_array_num_elements (&font->output); - *aligned = (length + 3) & ~3; - pad = *aligned - length; - - if (pad) { - cairo_status_t status; - - status = cairo_truetype_font_allocate_write_buffer (font, pad, - &padding); - if (unlikely (status)) - return status; - - memset (padding, 0, pad); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_check_boundary (cairo_truetype_font_t *font, - unsigned long boundary) -{ - cairo_status_t status; - - if (font->status) - return font->status; - - if (boundary - font->last_offset > SFNT_STRING_MAX_LENGTH) - { - status = _cairo_array_append (&font->string_offsets, - &font->last_boundary); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - font->last_offset = font->last_boundary; - } - font->last_boundary = boundary; - - return CAIRO_STATUS_SUCCESS; -} - -typedef struct _cmap_unicode_range { - unsigned int start; - unsigned int end; -} cmap_unicode_range_t; - -static cmap_unicode_range_t winansi_unicode_ranges[] = { - { 0x0020, 0x007f }, - { 0x00a0, 0x00ff }, - { 0x0152, 0x0153 }, - { 0x0160, 0x0161 }, - { 0x0178, 0x0178 }, - { 0x017d, 0x017e }, - { 0x0192, 0x0192 }, - { 0x02c6, 0x02c6 }, - { 0x02dc, 0x02dc }, - { 0x2013, 0x2026 }, - { 0x2030, 0x2030 }, - { 0x2039, 0x203a }, - { 0x20ac, 0x20ac }, - { 0x2122, 0x2122 }, -}; - -static cairo_status_t -cairo_truetype_font_write_cmap_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - int i; - unsigned int j; - int range_offset; - int num_ranges; - int entry_selector; - int length; - - num_ranges = ARRAY_LENGTH (winansi_unicode_ranges); - - length = 16 + (num_ranges + 1)*8; - for (i = 0; i < num_ranges; i++) - length += (winansi_unicode_ranges[i].end - winansi_unicode_ranges[i].start + 1)*2; - - entry_selector = 0; - while ((1 << entry_selector) <= (num_ranges + 1)) - entry_selector++; - - entry_selector--; - - cairo_truetype_font_write_be16 (font, 0); /* Table version */ - cairo_truetype_font_write_be16 (font, 1); /* Num tables */ - - cairo_truetype_font_write_be16 (font, 3); /* Platform */ - cairo_truetype_font_write_be16 (font, 1); /* Encoding */ - cairo_truetype_font_write_be32 (font, 12); /* Offset to start of table */ - - /* Output a format 4 encoding table for the winansi encoding */ - - cairo_truetype_font_write_be16 (font, 4); /* Format */ - cairo_truetype_font_write_be16 (font, length); /* Length */ - cairo_truetype_font_write_be16 (font, 0); /* Version */ - cairo_truetype_font_write_be16 (font, num_ranges*2 + 2); /* 2*segcount */ - cairo_truetype_font_write_be16 (font, (1 << (entry_selector + 1))); /* searchrange */ - cairo_truetype_font_write_be16 (font, entry_selector); /* entry selector */ - cairo_truetype_font_write_be16 (font, num_ranges*2 + 2 - (1 << (entry_selector + 1))); /* rangeshift */ - for (i = 0; i < num_ranges; i++) - cairo_truetype_font_write_be16 (font, winansi_unicode_ranges[i].end); /* end count[] */ - cairo_truetype_font_write_be16 (font, 0xffff); /* end count[] */ - - cairo_truetype_font_write_be16 (font, 0); /* reserved */ - - for (i = 0; i < num_ranges; i++) - cairo_truetype_font_write_be16 (font, winansi_unicode_ranges[i].start); /* startCode[] */ - cairo_truetype_font_write_be16 (font, 0xffff); /* startCode[] */ - - for (i = 0; i < num_ranges; i++) - cairo_truetype_font_write_be16 (font, 0x0000); /* delta[] */ - cairo_truetype_font_write_be16 (font, 1); /* delta[] */ - - range_offset = num_ranges*2 + 2; - for (i = 0; i < num_ranges; i++) { - cairo_truetype_font_write_be16 (font, range_offset); /* rangeOffset[] */ - range_offset += (winansi_unicode_ranges[i].end - winansi_unicode_ranges[i].start + 1)*2 - 2; - } - cairo_truetype_font_write_be16 (font, 0); /* rangeOffset[] */ - - for (i = 0; i < num_ranges; i++) { - for (j = winansi_unicode_ranges[i].start; j < winansi_unicode_ranges[i].end + 1; j++) { - int ch = _cairo_unicode_to_winansi (j); - int glyph; - - if (ch > 0) - glyph = font->scaled_font_subset->latin_to_subset_glyph_index[ch]; - else - glyph = 0; - cairo_truetype_font_write_be16 (font, glyph); - } - } - - return font->status; -} - -static cairo_status_t -cairo_truetype_font_write_generic_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - cairo_status_t status; - unsigned char *buffer; - unsigned long size; - - if (font->status) - return font->status; - - size = 0; - status = font->backend->load_truetype_table(font->scaled_font_subset->scaled_font, - tag, 0, NULL, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - tag, 0, buffer, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_remap_composite_glyph (cairo_truetype_font_t *font, - unsigned char *buffer, - unsigned long size) -{ - tt_glyph_data_t *glyph_data; - tt_composite_glyph_t *composite_glyph; - int num_args; - int has_more_components; - unsigned short flags; - unsigned short index; - cairo_status_t status; - unsigned char *end = buffer + size; - - if (font->status) - return font->status; - - glyph_data = (tt_glyph_data_t *) buffer; - if ((unsigned char *)(&glyph_data->data) >= end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((int16_t)be16_to_cpu (glyph_data->num_contours) >= 0) - return CAIRO_STATUS_SUCCESS; - - composite_glyph = &glyph_data->glyph; - do { - if ((unsigned char *)(&composite_glyph->args[1]) > end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - flags = be16_to_cpu (composite_glyph->flags); - has_more_components = flags & TT_MORE_COMPONENTS; - status = cairo_truetype_font_use_glyph (font, be16_to_cpu (composite_glyph->index), &index); - if (unlikely (status)) - return status; - - composite_glyph->index = cpu_to_be16 (index); - num_args = 1; - if (flags & TT_ARG_1_AND_2_ARE_WORDS) - num_args += 1; - - if (flags & TT_WE_HAVE_A_SCALE) - num_args += 1; - else if (flags & TT_WE_HAVE_AN_X_AND_Y_SCALE) - num_args += 2; - else if (flags & TT_WE_HAVE_A_TWO_BY_TWO) - num_args += 4; - - composite_glyph = (tt_composite_glyph_t *) &(composite_glyph->args[num_args]); - } while (has_more_components); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - unsigned long start_offset, index, size, next; - tt_head_t header; - unsigned long begin, end; - unsigned char *buffer; - unsigned int i; - union { - unsigned char *bytes; - uint16_t *short_offsets; - uint32_t *long_offsets; - } u; - cairo_status_t status; - - if (font->status) - return font->status; - - size = sizeof (tt_head_t); - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_head, 0, - (unsigned char*) &header, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - if (be16_to_cpu (header.index_to_loc_format) == 0) - size = sizeof (int16_t) * (font->num_glyphs_in_face + 1); - else - size = sizeof (int32_t) * (font->num_glyphs_in_face + 1); - - u.bytes = malloc (size); - if (unlikely (u.bytes == NULL)) - return _cairo_truetype_font_set_error (font, CAIRO_STATUS_NO_MEMORY); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_loca, 0, u.bytes, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - start_offset = _cairo_array_num_elements (&font->output); - for (i = 0; i < font->base.num_glyphs; i++) { - index = font->glyphs[i].parent_index; - if (be16_to_cpu (header.index_to_loc_format) == 0) { - begin = be16_to_cpu (u.short_offsets[index]) * 2; - end = be16_to_cpu (u.short_offsets[index + 1]) * 2; - } - else { - begin = be32_to_cpu (u.long_offsets[index]); - end = be32_to_cpu (u.long_offsets[index + 1]); - } - - /* quick sanity check... */ - if (end < begin) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto FAIL; - } - - size = end - begin; - status = cairo_truetype_font_align_output (font, &next); - if (unlikely (status)) - goto FAIL; - - status = cairo_truetype_font_check_boundary (font, next); - if (unlikely (status)) - goto FAIL; - - font->glyphs[i].location = next - start_offset; - - status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); - if (unlikely (status)) - goto FAIL; - - if (size != 0) { - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_glyf, begin, buffer, &size); - if (unlikely (status)) - goto FAIL; - - status = cairo_truetype_font_remap_composite_glyph (font, buffer, size); - if (unlikely (status)) - goto FAIL; - } - } - - status = cairo_truetype_font_align_output (font, &next); - if (unlikely (status)) - goto FAIL; - - font->glyphs[i].location = next - start_offset; - - status = font->status; -FAIL: - free (u.bytes); - - return _cairo_truetype_font_set_error (font, status); -} - -static cairo_status_t -cairo_truetype_font_write_head_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - unsigned char *buffer; - unsigned long size; - cairo_status_t status; - - if (font->status) - return font->status; - - size = 0; - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - tag, 0, NULL, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - font->checksum_index = _cairo_array_num_elements (&font->output) + 8; - status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - tag, 0, buffer, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - /* set checkSumAdjustment to 0 for table checksum calculation */ - *(uint32_t *)(buffer + 8) = 0; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_write_hhea_table (cairo_truetype_font_t *font, unsigned long tag) -{ - tt_hhea_t *hhea; - unsigned long size; - cairo_status_t status; - - if (font->status) - return font->status; - - size = sizeof (tt_hhea_t); - status = cairo_truetype_font_allocate_write_buffer (font, size, (unsigned char **) &hhea); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - tag, 0, (unsigned char *) hhea, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - hhea->num_hmetrics = cpu_to_be16 ((uint16_t)(font->base.num_glyphs)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - unsigned long size; - unsigned long long_entry_size; - unsigned long short_entry_size; - short *p; - unsigned int i; - tt_hhea_t hhea; - int num_hmetrics; - cairo_status_t status; - - if (font->status) - return font->status; - - size = sizeof (tt_hhea_t); - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hhea, 0, - (unsigned char*) &hhea, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - num_hmetrics = be16_to_cpu(hhea.num_hmetrics); - - for (i = 0; i < font->base.num_glyphs; i++) { - long_entry_size = 2 * sizeof (int16_t); - short_entry_size = sizeof (int16_t); - status = cairo_truetype_font_allocate_write_buffer (font, - long_entry_size, - (unsigned char **) &p); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - if (font->glyphs[i].parent_index < num_hmetrics) { - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hmtx, - font->glyphs[i].parent_index * long_entry_size, - (unsigned char *) p, &long_entry_size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - } - else - { - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hmtx, - (num_hmetrics - 1) * long_entry_size, - (unsigned char *) p, &short_entry_size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_hmtx, - num_hmetrics * long_entry_size + - (font->glyphs[i].parent_index - num_hmetrics) * short_entry_size, - (unsigned char *) (p + 1), &short_entry_size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - } - font->base.widths[i] = be16_to_cpu (p[0]); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_write_loca_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - unsigned int i; - tt_head_t header; - unsigned long size; - cairo_status_t status; - - if (font->status) - return font->status; - - size = sizeof(tt_head_t); - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_head, 0, - (unsigned char*) &header, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - if (be16_to_cpu (header.index_to_loc_format) == 0) - { - for (i = 0; i < font->base.num_glyphs + 1; i++) - cairo_truetype_font_write_be16 (font, font->glyphs[i].location / 2); - } else { - for (i = 0; i < font->base.num_glyphs + 1; i++) - cairo_truetype_font_write_be32 (font, font->glyphs[i].location); - } - - return font->status; -} - -static cairo_status_t -cairo_truetype_font_write_maxp_table (cairo_truetype_font_t *font, - unsigned long tag) -{ - tt_maxp_t *maxp; - unsigned long size; - cairo_status_t status; - - if (font->status) - return font->status; - - size = sizeof (tt_maxp_t); - status = cairo_truetype_font_allocate_write_buffer (font, size, (unsigned char **) &maxp); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - tag, 0, (unsigned char *) maxp, &size); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - maxp->num_glyphs = cpu_to_be16 (font->base.num_glyphs); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_truetype_font_write_offset_table (cairo_truetype_font_t *font) -{ - cairo_status_t status; - unsigned char *table_buffer; - size_t table_buffer_length; - unsigned short search_range, entry_selector, range_shift; - - if (font->status) - return font->status; - - search_range = 1; - entry_selector = 0; - while (search_range * 2 <= font->num_tables) { - search_range *= 2; - entry_selector++; - } - search_range *= 16; - range_shift = font->num_tables * 16 - search_range; - - cairo_truetype_font_write_be32 (font, SFNT_VERSION); - cairo_truetype_font_write_be16 (font, font->num_tables); - cairo_truetype_font_write_be16 (font, search_range); - cairo_truetype_font_write_be16 (font, entry_selector); - cairo_truetype_font_write_be16 (font, range_shift); - - /* Allocate space for the table directory. Each directory entry - * will be filled in by cairo_truetype_font_update_entry() after - * the table is written. */ - table_buffer_length = font->num_tables * 16; - status = cairo_truetype_font_allocate_write_buffer (font, table_buffer_length, - &table_buffer); - if (unlikely (status)) - return _cairo_truetype_font_set_error (font, status); - - return CAIRO_STATUS_SUCCESS; -} - -static uint32_t -cairo_truetype_font_calculate_checksum (cairo_truetype_font_t *font, - unsigned long start, - unsigned long end) -{ - uint32_t *padded_end; - uint32_t *p; - uint32_t checksum; - char *data; - - checksum = 0; - data = _cairo_array_index (&font->output, 0); - p = (uint32_t *) (data + start); - padded_end = (uint32_t *) (data + ((end + 3) & ~3)); - while (p < padded_end) - checksum += be32_to_cpu(*p++); - - return checksum; -} - -static void -cairo_truetype_font_update_entry (cairo_truetype_font_t *font, - int index, - unsigned long tag, - unsigned long start, - unsigned long end) -{ - uint32_t *entry; - - entry = _cairo_array_index (&font->output, 12 + 16 * index); - entry[0] = cpu_to_be32 ((uint32_t)tag); - entry[1] = cpu_to_be32 (cairo_truetype_font_calculate_checksum (font, start, end)); - entry[2] = cpu_to_be32 ((uint32_t)start); - entry[3] = cpu_to_be32 ((uint32_t)(end - start)); -} - -static cairo_status_t -cairo_truetype_font_generate (cairo_truetype_font_t *font, - const char **data, - unsigned long *length, - const unsigned long **string_offsets, - unsigned long *num_strings) -{ - cairo_status_t status; - unsigned long start, end, next; - uint32_t checksum, *checksum_location; - int i; - - if (font->status) - return font->status; - - status = cairo_truetype_font_write_offset_table (font); - if (unlikely (status)) - goto FAIL; - - status = cairo_truetype_font_align_output (font, &start); - if (unlikely (status)) - goto FAIL; - - end = 0; - for (i = 0; i < font->num_tables; i++) { - status = font->truetype_tables[i].write (font, font->truetype_tables[i].tag); - if (unlikely (status)) - goto FAIL; - - end = _cairo_array_num_elements (&font->output); - status = cairo_truetype_font_align_output (font, &next); - if (unlikely (status)) - goto FAIL; - - cairo_truetype_font_update_entry (font, font->truetype_tables[i].pos, - font->truetype_tables[i].tag, start, end); - status = cairo_truetype_font_check_boundary (font, next); - if (unlikely (status)) - goto FAIL; - - start = next; - } - - checksum = - 0xb1b0afba - cairo_truetype_font_calculate_checksum (font, 0, end); - checksum_location = _cairo_array_index (&font->output, font->checksum_index); - *checksum_location = cpu_to_be32 (checksum); - - *data = _cairo_array_index (&font->output, 0); - *length = _cairo_array_num_elements (&font->output); - *num_strings = _cairo_array_num_elements (&font->string_offsets); - if (*num_strings != 0) - *string_offsets = _cairo_array_index (&font->string_offsets, 0); - else - *string_offsets = NULL; - - FAIL: - return _cairo_truetype_font_set_error (font, status); -} - -static cairo_status_t -cairo_truetype_font_use_glyph (cairo_truetype_font_t *font, - unsigned short glyph, - unsigned short *out) -{ - if (glyph >= font->num_glyphs_in_face) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (font->parent_to_subset[glyph] == 0) { - font->parent_to_subset[glyph] = font->base.num_glyphs; - font->glyphs[font->base.num_glyphs].parent_index = glyph; - font->base.num_glyphs++; - } - - *out = font->parent_to_subset[glyph]; - return CAIRO_STATUS_SUCCESS; -} - -static void -cairo_truetype_font_add_truetype_table (cairo_truetype_font_t *font, - unsigned long tag, - cairo_status_t (*write) (cairo_truetype_font_t *font, unsigned long tag), - int pos) -{ - font->truetype_tables[font->num_tables].tag = tag; - font->truetype_tables[font->num_tables].write = write; - font->truetype_tables[font->num_tables].pos = pos; - font->num_tables++; -} - -/* cairo_truetype_font_create_truetype_table_list() builds the list of - * truetype tables to be embedded in the subsetted font. Each call to - * cairo_truetype_font_add_truetype_table() adds a table, the callback - * for generating the table, and the position in the table directory - * to the truetype_tables array. - * - * As we write out the glyf table we remap composite glyphs. - * Remapping composite glyphs will reference the sub glyphs the - * composite glyph is made up of. The "glyf" table callback needs to - * be called first so we have all the glyphs in the subset before - * going further. - * - * The order in which tables are added to the truetype_table array - * using cairo_truetype_font_add_truetype_table() specifies the order - * in which the callback functions will be called. - * - * The tables in the table directory must be listed in alphabetical - * order. The "cvt", "fpgm", and "prep" are optional tables. They - * will only be embedded in the subset if they exist in the source - * font. "cmap" is only embedded for latin fonts. The pos parameter of - * cairo_truetype_font_add_truetype_table() specifies the position of - * the table in the table directory. - */ -static void -cairo_truetype_font_create_truetype_table_list (cairo_truetype_font_t *font) -{ - cairo_bool_t has_cvt = FALSE; - cairo_bool_t has_fpgm = FALSE; - cairo_bool_t has_prep = FALSE; - unsigned long size; - int pos; - - size = 0; - if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_cvt, 0, NULL, - &size) == CAIRO_INT_STATUS_SUCCESS) - has_cvt = TRUE; - - size = 0; - if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_fpgm, 0, NULL, - &size) == CAIRO_INT_STATUS_SUCCESS) - has_fpgm = TRUE; - - size = 0; - if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, - TT_TAG_prep, 0, NULL, - &size) == CAIRO_INT_STATUS_SUCCESS) - has_prep = TRUE; - - font->num_tables = 0; - pos = 0; - if (font->is_pdf && font->scaled_font_subset->is_latin) - pos++; - if (has_cvt) - pos++; - if (has_fpgm) - pos++; - cairo_truetype_font_add_truetype_table (font, TT_TAG_glyf, cairo_truetype_font_write_glyf_table, pos); - - pos = 0; - if (font->is_pdf && font->scaled_font_subset->is_latin) - cairo_truetype_font_add_truetype_table (font, TT_TAG_cmap, cairo_truetype_font_write_cmap_table, pos++); - if (has_cvt) - cairo_truetype_font_add_truetype_table (font, TT_TAG_cvt, cairo_truetype_font_write_generic_table, pos++); - if (has_fpgm) - cairo_truetype_font_add_truetype_table (font, TT_TAG_fpgm, cairo_truetype_font_write_generic_table, pos++); - pos++; - cairo_truetype_font_add_truetype_table (font, TT_TAG_head, cairo_truetype_font_write_head_table, pos++); - cairo_truetype_font_add_truetype_table (font, TT_TAG_hhea, cairo_truetype_font_write_hhea_table, pos++); - cairo_truetype_font_add_truetype_table (font, TT_TAG_hmtx, cairo_truetype_font_write_hmtx_table, pos++); - cairo_truetype_font_add_truetype_table (font, TT_TAG_loca, cairo_truetype_font_write_loca_table, pos++); - cairo_truetype_font_add_truetype_table (font, TT_TAG_maxp, cairo_truetype_font_write_maxp_table, pos++); - if (has_prep) - cairo_truetype_font_add_truetype_table (font, TT_TAG_prep, cairo_truetype_font_write_generic_table, pos); -} - -static cairo_status_t -cairo_truetype_subset_init_internal (cairo_truetype_subset_t *truetype_subset, - cairo_scaled_font_subset_t *font_subset, - cairo_bool_t is_pdf) -{ - cairo_truetype_font_t *font = NULL; - cairo_status_t status; - const char *data = NULL; /* squelch bogus compiler warning */ - unsigned long length = 0; /* squelch bogus compiler warning */ - unsigned long offsets_length; - unsigned int i; - const unsigned long *string_offsets = NULL; - unsigned long num_strings = 0; - - status = _cairo_truetype_font_create (font_subset, is_pdf, &font); - if (unlikely (status)) - return status; - - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - unsigned short parent_glyph = font->scaled_font_subset->glyphs[i]; - status = cairo_truetype_font_use_glyph (font, parent_glyph, &parent_glyph); - if (unlikely (status)) - goto fail1; - } - - cairo_truetype_font_create_truetype_table_list (font); - status = cairo_truetype_font_generate (font, &data, &length, - &string_offsets, &num_strings); - if (unlikely (status)) - goto fail1; - - truetype_subset->ps_name = strdup (font->base.ps_name); - if (unlikely (truetype_subset->ps_name == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - if (font->base.font_name != NULL) { - truetype_subset->family_name_utf8 = strdup (font->base.font_name); - if (unlikely (truetype_subset->family_name_utf8 == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - } else { - truetype_subset->family_name_utf8 = NULL; - } - - /* The widths array returned must contain only widths for the - * glyphs in font_subset. Any subglyphs appended after - * font_subset->num_glyphs are omitted. */ - truetype_subset->widths = calloc (sizeof (double), - font->scaled_font_subset->num_glyphs); - if (unlikely (truetype_subset->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) - truetype_subset->widths[i] = (double)font->base.widths[i]/font->base.units_per_em; - - truetype_subset->x_min = (double)font->base.x_min/font->base.units_per_em; - truetype_subset->y_min = (double)font->base.y_min/font->base.units_per_em; - truetype_subset->x_max = (double)font->base.x_max/font->base.units_per_em; - truetype_subset->y_max = (double)font->base.y_max/font->base.units_per_em; - truetype_subset->ascent = (double)font->base.ascent/font->base.units_per_em; - truetype_subset->descent = (double)font->base.descent/font->base.units_per_em; - - if (length) { - truetype_subset->data = malloc (length); - if (unlikely (truetype_subset->data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail4; - } - - memcpy (truetype_subset->data, data, length); - } else - truetype_subset->data = NULL; - truetype_subset->data_length = length; - - if (num_strings) { - offsets_length = num_strings * sizeof (unsigned long); - truetype_subset->string_offsets = malloc (offsets_length); - if (unlikely (truetype_subset->string_offsets == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail5; - } - - memcpy (truetype_subset->string_offsets, string_offsets, offsets_length); - truetype_subset->num_string_offsets = num_strings; - } else { - truetype_subset->string_offsets = NULL; - truetype_subset->num_string_offsets = 0; - } - - cairo_truetype_font_destroy (font); - - return CAIRO_STATUS_SUCCESS; - - fail5: - free (truetype_subset->data); - fail4: - free (truetype_subset->widths); - fail3: - free (truetype_subset->family_name_utf8); - fail2: - free (truetype_subset->ps_name); - fail1: - cairo_truetype_font_destroy (font); - - return status; -} - -cairo_status_t -_cairo_truetype_subset_init_ps (cairo_truetype_subset_t *truetype_subset, - cairo_scaled_font_subset_t *font_subset) -{ - return cairo_truetype_subset_init_internal (truetype_subset, font_subset, FALSE); -} - -cairo_status_t -_cairo_truetype_subset_init_pdf (cairo_truetype_subset_t *truetype_subset, - cairo_scaled_font_subset_t *font_subset) -{ - return cairo_truetype_subset_init_internal (truetype_subset, font_subset, TRUE); -} - -void -_cairo_truetype_subset_fini (cairo_truetype_subset_t *subset) -{ - free (subset->ps_name); - free (subset->family_name_utf8); - free (subset->widths); - free (subset->data); - free (subset->string_offsets); -} - -static cairo_int_status_t -_cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font, - unsigned long table_offset, - unsigned long index, - uint32_t *ucs4) -{ - cairo_status_t status; - const cairo_scaled_font_backend_t *backend; - tt_segment_map_t *map; - char buf[4]; - unsigned int num_segments, i; - unsigned long size; - uint16_t *start_code; - uint16_t *end_code; - uint16_t *delta; - uint16_t *range_offset; - uint16_t c; - - backend = scaled_font->backend; - size = 4; - status = backend->load_truetype_table (scaled_font, - TT_TAG_cmap, table_offset, - (unsigned char *) &buf, - &size); - if (unlikely (status)) - return status; - - /* All table formats have the same first two words */ - map = (tt_segment_map_t *) buf; - if (be16_to_cpu (map->format) != 4) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = be16_to_cpu (map->length); - map = malloc (size); - if (unlikely (map == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = backend->load_truetype_table (scaled_font, - TT_TAG_cmap, table_offset, - (unsigned char *) map, - &size); - if (unlikely (status)) - goto fail; - - num_segments = be16_to_cpu (map->segCountX2)/2; - - /* A Format 4 cmap contains 8 uint16_t numbers and 4 arrays of - * uint16_t each num_segments long. */ - if (size < (8 + 4*num_segments)*sizeof(uint16_t)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - end_code = map->endCount; - start_code = &(end_code[num_segments + 1]); - delta = &(start_code[num_segments]); - range_offset = &(delta[num_segments]); - - /* search for glyph in segments with rangeOffset=0 */ - for (i = 0; i < num_segments; i++) { - c = index - be16_to_cpu (delta[i]); - if (range_offset[i] == 0 && - c >= be16_to_cpu (start_code[i]) && - c <= be16_to_cpu (end_code[i])) - { - *ucs4 = c; - goto found; - } - } - - /* search for glyph in segments with rangeOffset=1 */ - for (i = 0; i < num_segments; i++) { - if (range_offset[i] != 0) { - uint16_t *glyph_ids = &range_offset[i] + be16_to_cpu (range_offset[i])/2; - int range_size = be16_to_cpu (end_code[i]) - be16_to_cpu (start_code[i]) + 1; - uint16_t g_id_be = cpu_to_be16 (index); - int j; - - if (range_size > 0) { - if ((char*)glyph_ids + 2*range_size > (char*)map + size) - return CAIRO_INT_STATUS_UNSUPPORTED; - - for (j = 0; j < range_size; j++) { - if (glyph_ids[j] == g_id_be) { - *ucs4 = be16_to_cpu (start_code[i]) + j; - goto found; - } - } - } - } - } - - /* glyph not found */ - *ucs4 = -1; - -found: - status = CAIRO_STATUS_SUCCESS; - -fail: - free (map); - - return status; -} - -cairo_int_status_t -_cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font, - unsigned long index, - uint32_t *ucs4) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - const cairo_scaled_font_backend_t *backend; - tt_cmap_t *cmap; - char buf[4]; - int num_tables, i; - unsigned long size; - - backend = scaled_font->backend; - if (!backend->load_truetype_table) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = 4; - status = backend->load_truetype_table (scaled_font, - TT_TAG_cmap, 0, - (unsigned char *) &buf, - &size); - if (unlikely (status)) - return status; - - cmap = (tt_cmap_t *) buf; - num_tables = be16_to_cpu (cmap->num_tables); - size = 4 + num_tables*sizeof(tt_cmap_index_t); - cmap = _cairo_malloc_ab_plus_c (num_tables, sizeof (tt_cmap_index_t), 4); - if (unlikely (cmap == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = backend->load_truetype_table (scaled_font, - TT_TAG_cmap, 0, - (unsigned char *) cmap, - &size); - if (unlikely (status)) - goto cleanup; - - /* Find a table with Unicode mapping */ - for (i = 0; i < num_tables; i++) { - if (be16_to_cpu (cmap->index[i].platform) == 3 && - be16_to_cpu (cmap->index[i].encoding) == 1) { - status = _cairo_truetype_reverse_cmap (scaled_font, - be32_to_cpu (cmap->index[i].offset), - index, - ucs4); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - break; - } - } - -cleanup: - free (cmap); - - return status; -} - -static cairo_status_t -find_name (tt_name_t *name, int name_id, int platform, int encoding, int language, char **str_out) -{ - tt_name_record_t *record; - int i, len; - char *str; - char *p; - cairo_bool_t has_tag; - cairo_status_t status; - - str = NULL; - for (i = 0; i < be16_to_cpu (name->num_records); i++) { - record = &(name->records[i]); - if (be16_to_cpu (record->name) == name_id && - be16_to_cpu (record->platform) == platform && - be16_to_cpu (record->encoding) == encoding && - (language == -1 || be16_to_cpu (record->language) == language)) { - - str = malloc (be16_to_cpu (record->length) + 1); - if (str == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - len = be16_to_cpu (record->length); - memcpy (str, - ((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset), - len); - str[be16_to_cpu (record->length)] = 0; - break; - } - } - if (str == NULL) { - *str_out = NULL; - return CAIRO_STATUS_SUCCESS; - } - - if (platform == 3) { /* Win platform, unicode encoding */ - /* convert to utf8 */ - int size = 0; - char *utf8; - uint16_t *u = (uint16_t *) str; - int u_len = len/2; - - for (i = 0; i < u_len; i++) - size += _cairo_ucs4_to_utf8 (be16_to_cpu(u[i]), NULL); - - utf8 = malloc (size + 1); - if (utf8 == NULL) { - status =_cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - p = utf8; - for (i = 0; i < u_len; i++) - p += _cairo_ucs4_to_utf8 (be16_to_cpu(u[i]), p); - *p = 0; - free (str); - str = utf8; - } else if (platform == 1) { /* Mac platform, Mac Roman encoding */ - /* Replace characters above 127 with underscores. We could use - * a lookup table to convert to unicode but since most fonts - * include a unicode name this is just a rarely used fallback. */ - for (i = 0; i < len; i++) { - if ((unsigned char)str[i] > 127) - str[i] = '_'; - } - } - - /* If font name is prefixed with a PDF subset tag, strip it off. */ - p = str; - len = strlen (str); - has_tag = FALSE; - if (len > 7 && p[6] == '+') { - has_tag = TRUE; - for (i = 0; i < 6; i++) { - if (p[i] < 'A' || p[i] > 'Z') { - has_tag = FALSE; - break; - } - } - } - if (has_tag) { - p = malloc (len - 6); - if (unlikely (p == NULL)) { - status =_cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail; - } - memcpy (p, str + 7, len - 7); - p[len-7] = 0; - free (str); - str = p; - } - - *str_out = str; - - return CAIRO_STATUS_SUCCESS; - - fail: - free (str); - - return status; -} - -cairo_int_status_t -_cairo_truetype_read_font_name (cairo_scaled_font_t *scaled_font, - char **ps_name_out, - char **font_name_out) -{ - cairo_status_t status; - const cairo_scaled_font_backend_t *backend; - tt_name_t *name; - unsigned long size; - char *ps_name = NULL; - char *family_name = NULL; - - backend = scaled_font->backend; - if (!backend->load_truetype_table) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = 0; - status = backend->load_truetype_table (scaled_font, - TT_TAG_name, 0, - NULL, - &size); - if (status) - return status; - - name = malloc (size); - if (name == NULL) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = backend->load_truetype_table (scaled_font, - TT_TAG_name, 0, - (unsigned char *) name, - &size); - if (status) - goto fail; - - /* Find PS Name (name_id = 6). OT spec says PS name must be one of - * the following two encodings */ - status = find_name (name, 6, 3, 1, 0x409, &ps_name); /* win, unicode, english-us */ - if (unlikely(status)) - goto fail; - - if (!ps_name) { - status = find_name (name, 6, 1, 0, 0, &ps_name); /* mac, roman, english */ - if (unlikely(status)) - goto fail; - } - - /* Find Family name (name_id = 1) */ - status = find_name (name, 1, 3, 1, 0x409, &family_name); /* win, unicode, english-us */ - if (unlikely(status)) - goto fail; - - if (!family_name) { - status = find_name (name, 1, 3, 0, 0x409, &family_name); /* win, symbol, english-us */ - if (unlikely(status)) - goto fail; - } - - if (!family_name) { - status = find_name (name, 1, 1, 0, 0, &family_name); /* mac, roman, english */ - if (unlikely(status)) - goto fail; - } - - if (!family_name) { - status = find_name (name, 1, 3, 1, -1, &family_name); /* win, unicode, any language */ - if (unlikely(status)) - goto fail; - } - - status = _cairo_escape_ps_name (&ps_name); - if (unlikely(status)) - goto fail; - - free (name); - - *ps_name_out = ps_name; - *font_name_out = family_name; - - return CAIRO_STATUS_SUCCESS; - -fail: - free (name); - free (ps_name); - free (family_name); - *ps_name_out = NULL; - *font_name_out = NULL; - - return status; -} - -cairo_int_status_t -_cairo_truetype_get_style (cairo_scaled_font_t *scaled_font, - int *weight, - cairo_bool_t *bold, - cairo_bool_t *italic) -{ - cairo_status_t status; - const cairo_scaled_font_backend_t *backend; - tt_os2_t os2; - unsigned long size; - uint16_t selection; - - backend = scaled_font->backend; - if (!backend->load_truetype_table) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = 0; - status = backend->load_truetype_table (scaled_font, - TT_TAG_OS2, 0, - NULL, - &size); - if (status) - return status; - - if (size < sizeof(os2)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = sizeof (os2); - status = backend->load_truetype_table (scaled_font, - TT_TAG_OS2, 0, - (unsigned char *) &os2, - &size); - if (status) - return status; - - *weight = be16_to_cpu (os2.usWeightClass); - selection = be16_to_cpu (os2.fsSelection); - *bold = (selection & TT_FS_SELECTION_BOLD) ? TRUE : FALSE; - *italic = (selection & TT_FS_SELECTION_ITALIC) ? TRUE : FALSE; - - return CAIRO_STATUS_SUCCESS; -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-fallback.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-fallback.c deleted file mode 100644 index 4a657413e48..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-fallback.c +++ /dev/null @@ -1,903 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Adrian Johnson - */ - -#define _BSD_SOURCE /* for snprintf(), strdup() */ -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-type1-private.h" -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-output-stream-private.h" - -typedef enum { - CAIRO_CHARSTRING_TYPE1, - CAIRO_CHARSTRING_TYPE2 -} cairo_charstring_type_t; - -typedef struct _cairo_type1_font { - int *widths; - - cairo_scaled_font_subset_t *scaled_font_subset; - cairo_scaled_font_t *type1_scaled_font; - - cairo_array_t contents; - - double x_min, y_min, x_max, y_max; - - const char *data; - unsigned long header_size; - unsigned long data_size; - unsigned long trailer_size; - int bbox_position; - int bbox_max_chars; - - cairo_output_stream_t *output; - - unsigned short eexec_key; - cairo_bool_t hex_encode; - int hex_column; -} cairo_type1_font_t; - -static cairo_status_t -cairo_type1_font_create (cairo_scaled_font_subset_t *scaled_font_subset, - cairo_type1_font_t **subset_return, - cairo_bool_t hex_encode) -{ - cairo_type1_font_t *font; - cairo_font_face_t *font_face; - cairo_matrix_t font_matrix; - cairo_matrix_t ctm; - cairo_font_options_t font_options; - cairo_status_t status; - - font = calloc (1, sizeof (cairo_type1_font_t)); - if (unlikely (font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - font->widths = calloc (scaled_font_subset->num_glyphs, sizeof (int)); - if (unlikely (font->widths == NULL)) { - free (font); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - font->scaled_font_subset = scaled_font_subset; - font->hex_encode = hex_encode; - - font_face = cairo_scaled_font_get_font_face (scaled_font_subset->scaled_font); - - cairo_matrix_init_scale (&font_matrix, 1000, -1000); - cairo_matrix_init_identity (&ctm); - - _cairo_font_options_init_default (&font_options); - cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE); - cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF); - - font->type1_scaled_font = cairo_scaled_font_create (font_face, - &font_matrix, - &ctm, - &font_options); - status = font->type1_scaled_font->status; - if (unlikely (status)) - goto fail; - - _cairo_array_init (&font->contents, sizeof (unsigned char)); - font->output = NULL; - - *subset_return = font; - - return CAIRO_STATUS_SUCCESS; - -fail: - free (font->widths); - free (font); - - return status; -} - -/* Charstring commands. If the high byte is 0 the command is encoded - * with a single byte. */ -#define CHARSTRING_sbw 0x0c07 -#define CHARSTRING_rmoveto 0x0015 -#define CHARSTRING_rlineto 0x0005 -#define CHARSTRING_rcurveto 0x0008 -#define CHARSTRING_closepath 0x0009 -#define CHARSTRING_endchar 0x000e - -/* Before calling this function, the caller must allocate sufficient - * space in data (see _cairo_array_grow_by). The maximum number of - * bytes that will be used is 2. - */ -static void -charstring_encode_command (cairo_array_t *data, int command) -{ - cairo_status_t status; - unsigned int orig_size; - unsigned char buf[5]; - unsigned char *p = buf; - - if (command & 0xff00) - *p++ = command >> 8; - *p++ = command & 0x00ff; - - /* Ensure the array doesn't grow, which allows this function to - * have no possibility of failure. */ - orig_size = _cairo_array_size (data); - status = _cairo_array_append_multiple (data, buf, p - buf); - - assert (status == CAIRO_STATUS_SUCCESS); - assert (_cairo_array_size (data) == orig_size); -} - -/* Before calling this function, the caller must allocate sufficient - * space in data (see _cairo_array_grow_by). The maximum number of - * bytes that will be used is 5. - */ -static void -charstring_encode_integer (cairo_array_t *data, - int i, - cairo_charstring_type_t type) -{ - cairo_status_t status; - unsigned int orig_size; - unsigned char buf[10]; - unsigned char *p = buf; - - if (i >= -107 && i <= 107) { - *p++ = i + 139; - } else if (i >= 108 && i <= 1131) { - i -= 108; - *p++ = (i >> 8)+ 247; - *p++ = i & 0xff; - } else if (i >= -1131 && i <= -108) { - i = -i - 108; - *p++ = (i >> 8)+ 251; - *p++ = i & 0xff; - } else { - if (type == CAIRO_CHARSTRING_TYPE1) { - *p++ = 0xff; - *p++ = i >> 24; - *p++ = (i >> 16) & 0xff; - *p++ = (i >> 8) & 0xff; - *p++ = i & 0xff; - } else { - *p++ = 0xff; - *p++ = (i >> 8) & 0xff; - *p++ = i & 0xff; - *p++ = 0; - *p++ = 0; - } - } - - /* Ensure the array doesn't grow, which allows this function to - * have no possibility of failure. */ - orig_size = _cairo_array_size (data); - status = _cairo_array_append_multiple (data, buf, p - buf); - - assert (status == CAIRO_STATUS_SUCCESS); - assert (_cairo_array_size (data) == orig_size); -} - -typedef struct _ps_path_info { - cairo_array_t *data; - int current_x, current_y; - cairo_charstring_type_t type; -} t1_path_info_t; - -static cairo_status_t -_charstring_move_to (void *closure, - const cairo_point_t *point) -{ - t1_path_info_t *path_info = (t1_path_info_t *) closure; - int dx, dy; - cairo_status_t status; - - status = _cairo_array_grow_by (path_info->data, 12); - if (unlikely (status)) - return status; - - dx = _cairo_fixed_integer_part (point->x) - path_info->current_x; - dy = _cairo_fixed_integer_part (point->y) - path_info->current_y; - charstring_encode_integer (path_info->data, dx, path_info->type); - charstring_encode_integer (path_info->data, dy, path_info->type); - path_info->current_x += dx; - path_info->current_y += dy; - - charstring_encode_command (path_info->data, CHARSTRING_rmoveto); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_charstring_line_to (void *closure, - const cairo_point_t *point) -{ - t1_path_info_t *path_info = (t1_path_info_t *) closure; - int dx, dy; - cairo_status_t status; - - status = _cairo_array_grow_by (path_info->data, 12); - if (unlikely (status)) - return status; - - dx = _cairo_fixed_integer_part (point->x) - path_info->current_x; - dy = _cairo_fixed_integer_part (point->y) - path_info->current_y; - charstring_encode_integer (path_info->data, dx, path_info->type); - charstring_encode_integer (path_info->data, dy, path_info->type); - path_info->current_x += dx; - path_info->current_y += dy; - - charstring_encode_command (path_info->data, CHARSTRING_rlineto); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_charstring_curve_to (void *closure, - const cairo_point_t *point1, - const cairo_point_t *point2, - const cairo_point_t *point3) -{ - t1_path_info_t *path_info = (t1_path_info_t *) closure; - int dx1, dy1, dx2, dy2, dx3, dy3; - cairo_status_t status; - - status = _cairo_array_grow_by (path_info->data, 32); - if (unlikely (status)) - return status; - - dx1 = _cairo_fixed_integer_part (point1->x) - path_info->current_x; - dy1 = _cairo_fixed_integer_part (point1->y) - path_info->current_y; - dx2 = _cairo_fixed_integer_part (point2->x) - path_info->current_x - dx1; - dy2 = _cairo_fixed_integer_part (point2->y) - path_info->current_y - dy1; - dx3 = _cairo_fixed_integer_part (point3->x) - path_info->current_x - dx1 - dx2; - dy3 = _cairo_fixed_integer_part (point3->y) - path_info->current_y - dy1 - dy2; - charstring_encode_integer (path_info->data, dx1, path_info->type); - charstring_encode_integer (path_info->data, dy1, path_info->type); - charstring_encode_integer (path_info->data, dx2, path_info->type); - charstring_encode_integer (path_info->data, dy2, path_info->type); - charstring_encode_integer (path_info->data, dx3, path_info->type); - charstring_encode_integer (path_info->data, dy3, path_info->type); - path_info->current_x += dx1 + dx2 + dx3; - path_info->current_y += dy1 + dy2 + dy3; - charstring_encode_command (path_info->data, CHARSTRING_rcurveto); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_charstring_close_path (void *closure) -{ - cairo_status_t status; - t1_path_info_t *path_info = (t1_path_info_t *) closure; - - if (path_info->type == CAIRO_CHARSTRING_TYPE2) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_array_grow_by (path_info->data, 2); - if (unlikely (status)) - return status; - - charstring_encode_command (path_info->data, CHARSTRING_closepath); - - return CAIRO_STATUS_SUCCESS; -} - -static void -charstring_encrypt (cairo_array_t *data) -{ - unsigned char *d, *end; - uint16_t c, p, r; - - r = CAIRO_TYPE1_CHARSTRING_KEY; - d = (unsigned char *) _cairo_array_index (data, 0); - end = d + _cairo_array_num_elements (data); - while (d < end) { - p = *d; - c = p ^ (r >> 8); - r = (c + r) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; - *d++ = c; - } -} - -static cairo_int_status_t -cairo_type1_font_create_charstring (cairo_type1_font_t *font, - int subset_index, - int glyph_index, - cairo_charstring_type_t type, - cairo_array_t *data) -{ - cairo_int_status_t status; - cairo_scaled_glyph_t *scaled_glyph; - t1_path_info_t path_info; - cairo_text_extents_t *metrics; - cairo_bool_t emit_path = TRUE; - - /* This call may return CAIRO_INT_STATUS_UNSUPPORTED for bitmap fonts. */ - status = _cairo_scaled_glyph_lookup (font->type1_scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS| - CAIRO_SCALED_GLYPH_INFO_PATH, - &scaled_glyph); - - /* It is ok for the .notdef glyph to not have a path available. We - * just need the metrics to emit an empty glyph. */ - if (glyph_index == 0 && status == CAIRO_INT_STATUS_UNSUPPORTED) { - emit_path = FALSE; - status = _cairo_scaled_glyph_lookup (font->type1_scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - } - if (unlikely (status)) - return status; - - metrics = &scaled_glyph->metrics; - if (subset_index == 0) { - font->x_min = metrics->x_bearing; - font->y_min = metrics->y_bearing; - font->x_max = metrics->x_bearing + metrics->width; - font->y_max = metrics->y_bearing + metrics->height; - } else { - if (metrics->x_bearing < font->x_min) - font->x_min = metrics->x_bearing; - if (metrics->y_bearing < font->y_min) - font->y_min = metrics->y_bearing; - if (metrics->x_bearing + metrics->width > font->x_max) - font->x_max = metrics->x_bearing + metrics->width; - if (metrics->y_bearing + metrics->height > font->y_max) - font->y_max = metrics->y_bearing + metrics->height; - } - font->widths[subset_index] = metrics->x_advance; - - status = _cairo_array_grow_by (data, 30); - if (unlikely (status)) - return status; - - if (type == CAIRO_CHARSTRING_TYPE1) { - charstring_encode_integer (data, (int) scaled_glyph->metrics.x_bearing, type); - charstring_encode_integer (data, (int) scaled_glyph->metrics.y_bearing, type); - charstring_encode_integer (data, (int) scaled_glyph->metrics.x_advance, type); - charstring_encode_integer (data, (int) scaled_glyph->metrics.y_advance, type); - charstring_encode_command (data, CHARSTRING_sbw); - - path_info.current_x = (int) scaled_glyph->metrics.x_bearing; - path_info.current_y = (int) scaled_glyph->metrics.y_bearing; - } else { - charstring_encode_integer (data, (int) scaled_glyph->metrics.x_advance, type); - - path_info.current_x = 0; - path_info.current_y = 0; - } - path_info.data = data; - path_info.type = type; - if (emit_path) { - status = _cairo_path_fixed_interpret (scaled_glyph->path, - _charstring_move_to, - _charstring_line_to, - _charstring_curve_to, - _charstring_close_path, - &path_info); - if (unlikely (status)) - return status; - } - - status = _cairo_array_grow_by (data, 1); - if (unlikely (status)) - return status; - charstring_encode_command (path_info.data, CHARSTRING_endchar); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_type1_font_write_charstrings (cairo_type1_font_t *font, - cairo_output_stream_t *encrypted_output) -{ - cairo_status_t status; - unsigned char zeros[] = { 0, 0, 0, 0 }; - cairo_array_t data; - unsigned int i; - int length; - - _cairo_array_init (&data, sizeof (unsigned char)); - status = _cairo_array_grow_by (&data, 1024); - if (unlikely (status)) - goto fail; - - _cairo_output_stream_printf (encrypted_output, - "2 index /CharStrings %d dict dup begin\n", - font->scaled_font_subset->num_glyphs + 1); - - _cairo_scaled_font_freeze_cache (font->type1_scaled_font); - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - _cairo_array_truncate (&data, 0); - /* four "random" bytes required by encryption algorithm */ - status = _cairo_array_append_multiple (&data, zeros, 4); - if (unlikely (status)) - break; - - status = cairo_type1_font_create_charstring (font, i, - font->scaled_font_subset->glyphs[i], - CAIRO_CHARSTRING_TYPE1, - &data); - if (unlikely (status)) - break; - - charstring_encrypt (&data); - length = _cairo_array_num_elements (&data); - if (font->scaled_font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (encrypted_output, "/%s %d RD ", - font->scaled_font_subset->glyph_names[i], - length); - } else if (i == 0) { - _cairo_output_stream_printf (encrypted_output, "/.notdef %d RD ", length); - } else { - _cairo_output_stream_printf (encrypted_output, "/g%d %d RD ", i, length); - } - _cairo_output_stream_write (encrypted_output, - _cairo_array_index (&data, 0), - length); - _cairo_output_stream_printf (encrypted_output, " ND\n"); - } - _cairo_scaled_font_thaw_cache (font->type1_scaled_font); - -fail: - _cairo_array_fini (&data); - return status; -} - -static void -cairo_type1_font_write_header (cairo_type1_font_t *font, - const char *name) -{ - unsigned int i; - const char spaces[50] = " "; - - _cairo_output_stream_printf (font->output, - "%%!FontType1-1.1 %s 1.0\n" - "11 dict begin\n" - "/FontName /%s def\n" - "/PaintType 0 def\n" - "/FontType 1 def\n" - "/FontMatrix [0.001 0 0 0.001 0 0] readonly def\n", - name, - name); - - /* We don't know the bbox values until after the charstrings have - * been generated. Reserve some space and fill in the bbox - * later. */ - - /* Worst case for four signed ints with spaces between each number */ - font->bbox_max_chars = 50; - - _cairo_output_stream_printf (font->output, "/FontBBox {"); - font->bbox_position = _cairo_output_stream_get_position (font->output); - _cairo_output_stream_write (font->output, spaces, font->bbox_max_chars); - - _cairo_output_stream_printf (font->output, - "} readonly def\n" - "/Encoding 256 array\n" - "0 1 255 {1 index exch /.notdef put} for\n"); - if (font->scaled_font_subset->is_latin) { - for (i = 1; i < 256; i++) { - int subset_glyph = font->scaled_font_subset->latin_to_subset_glyph_index[i]; - - if (subset_glyph > 0) { - if (font->scaled_font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (font->output, "dup %d /%s put\n", - i, font->scaled_font_subset->glyph_names[subset_glyph]); - } else { - _cairo_output_stream_printf (font->output, "dup %d /g%d put\n", i, subset_glyph); - } - } - } - } else { - for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { - if (font->scaled_font_subset->glyph_names != NULL) { - _cairo_output_stream_printf (font->output, "dup %d /%s put\n", - i, font->scaled_font_subset->glyph_names[i]); - } else { - _cairo_output_stream_printf (font->output, "dup %d /g%d put\n", i, i); - } - } - } - _cairo_output_stream_printf (font->output, - "readonly def\n" - "currentdict end\n" - "currentfile eexec\n"); -} - -static cairo_status_t -cairo_type1_write_stream_encrypted (void *closure, - const unsigned char *data, - unsigned int length) -{ - const unsigned char *in, *end; - uint16_t c, p; - static const char hex_digits[16] = "0123456789abcdef"; - char digits[3]; - cairo_type1_font_t *font = closure; - - in = (const unsigned char *) data; - end = (const unsigned char *) data + length; - while (in < end) { - p = *in++; - c = p ^ (font->eexec_key >> 8); - font->eexec_key = (c + font->eexec_key) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; - - if (font->hex_encode) { - digits[0] = hex_digits[c >> 4]; - digits[1] = hex_digits[c & 0x0f]; - digits[2] = '\n'; - font->hex_column += 2; - - if (font->hex_column == 78) { - _cairo_output_stream_write (font->output, digits, 3); - font->hex_column = 0; - } else { - _cairo_output_stream_write (font->output, digits, 2); - } - } else { - digits[0] = c; - _cairo_output_stream_write (font->output, digits, 1); - } - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_type1_font_write_private_dict (cairo_type1_font_t *font, - const char *name) -{ - cairo_int_status_t status; - cairo_status_t status2; - cairo_output_stream_t *encrypted_output; - - font->eexec_key = CAIRO_TYPE1_PRIVATE_DICT_KEY; - font->hex_column = 0; - encrypted_output = _cairo_output_stream_create ( - cairo_type1_write_stream_encrypted, - NULL, - font); - if (_cairo_output_stream_get_status (encrypted_output)) - return _cairo_output_stream_destroy (encrypted_output); - - /* Note: the first four spaces at the start of this private dict - * are the four "random" bytes of plaintext required by the - * encryption algorithm */ - _cairo_output_stream_printf (encrypted_output, - " dup /Private 9 dict dup begin\n" - "/RD {string currentfile exch readstring pop}" - " bind executeonly def\n" - "/ND {noaccess def} executeonly def\n" - "/NP {noaccess put} executeonly def\n" - "/BlueValues [] def\n" - "/MinFeature {16 16} def\n" - "/lenIV 4 def\n" - "/password 5839 def\n"); - - status = cairo_type1_font_write_charstrings (font, encrypted_output); - if (unlikely (status)) - goto fail; - - _cairo_output_stream_printf (encrypted_output, - "end\n" - "end\n" - "readonly put\n" - "noaccess put\n" - "dup /FontName get exch definefont pop\n" - "mark currentfile closefile\n"); - - fail: - status2 = _cairo_output_stream_destroy (encrypted_output); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - - return status; -} - -static void -cairo_type1_font_write_trailer(cairo_type1_font_t *font) -{ - int i; - static const char zeros[65] = - "0000000000000000000000000000000000000000000000000000000000000000\n"; - - for (i = 0; i < 8; i++) - _cairo_output_stream_write (font->output, zeros, sizeof zeros); - - _cairo_output_stream_printf (font->output, "cleartomark\n"); -} - -static cairo_status_t -cairo_type1_write_stream (void *closure, - const unsigned char *data, - unsigned int length) -{ - cairo_type1_font_t *font = closure; - - return _cairo_array_append_multiple (&font->contents, data, length); -} - -static cairo_int_status_t -cairo_type1_font_write (cairo_type1_font_t *font, - const char *name) -{ - cairo_int_status_t status; - - cairo_type1_font_write_header (font, name); - font->header_size = _cairo_output_stream_get_position (font->output); - - status = cairo_type1_font_write_private_dict (font, name); - if (unlikely (status)) - return status; - - font->data_size = _cairo_output_stream_get_position (font->output) - - font->header_size; - - cairo_type1_font_write_trailer (font); - font->trailer_size = - _cairo_output_stream_get_position (font->output) - - font->header_size - font->data_size; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -cairo_type1_font_generate (cairo_type1_font_t *font, const char *name) -{ - cairo_int_status_t status; - - status = _cairo_array_grow_by (&font->contents, 4096); - if (unlikely (status)) - return status; - - font->output = _cairo_output_stream_create (cairo_type1_write_stream, NULL, font); - if (_cairo_output_stream_get_status (font->output)) - return _cairo_output_stream_destroy (font->output); - - status = cairo_type1_font_write (font, name); - if (unlikely (status)) - return status; - - font->data = _cairo_array_index (&font->contents, 0); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_type1_font_destroy (cairo_type1_font_t *font) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - free (font->widths); - cairo_scaled_font_destroy (font->type1_scaled_font); - _cairo_array_fini (&font->contents); - if (font->output) - status = _cairo_output_stream_destroy (font->output); - free (font); - - return status; -} - -static cairo_status_t -_cairo_type1_fallback_init_internal (cairo_type1_subset_t *type1_subset, - const char *name, - cairo_scaled_font_subset_t *scaled_font_subset, - cairo_bool_t hex_encode) -{ - cairo_type1_font_t *font; - cairo_status_t status; - unsigned long length; - unsigned int i, len; - - status = cairo_type1_font_create (scaled_font_subset, &font, hex_encode); - if (unlikely (status)) - return status; - - status = cairo_type1_font_generate (font, name); - if (unlikely (status)) - goto fail1; - - type1_subset->base_font = strdup (name); - if (unlikely (type1_subset->base_font == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - type1_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); - if (unlikely (type1_subset->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail2; - } - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) - type1_subset->widths[i] = (double)font->widths[i]/1000; - - type1_subset->x_min = (double)font->x_min/1000; - type1_subset->y_min = (double)font->y_min/1000; - type1_subset->x_max = (double)font->x_max/1000; - type1_subset->y_max = (double)font->y_max/1000; - type1_subset->ascent = (double)font->y_max/1000; - type1_subset->descent = (double)font->y_min/1000; - - length = font->header_size + font->data_size + - font->trailer_size; - type1_subset->data = malloc (length); - if (unlikely (type1_subset->data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail3; - } - memcpy (type1_subset->data, - _cairo_array_index (&font->contents, 0), length); - - len = snprintf(type1_subset->data + font->bbox_position, - font->bbox_max_chars, - "%d %d %d %d", - (int)font->x_min, - (int)font->y_min, - (int)font->x_max, - (int)font->y_max); - type1_subset->data[font->bbox_position + len] = ' '; - - type1_subset->header_length = font->header_size; - type1_subset->data_length = font->data_size; - type1_subset->trailer_length = font->trailer_size; - - return cairo_type1_font_destroy (font); - - fail3: - free (type1_subset->widths); - fail2: - free (type1_subset->base_font); - fail1: - /* status is already set, ignore further errors */ - cairo_type1_font_destroy (font); - - return status; -} - -cairo_status_t -_cairo_type1_fallback_init_binary (cairo_type1_subset_t *type1_subset, - const char *name, - cairo_scaled_font_subset_t *scaled_font_subset) -{ - return _cairo_type1_fallback_init_internal (type1_subset, - name, - scaled_font_subset, FALSE); -} - -cairo_status_t -_cairo_type1_fallback_init_hex (cairo_type1_subset_t *type1_subset, - const char *name, - cairo_scaled_font_subset_t *scaled_font_subset) -{ - return _cairo_type1_fallback_init_internal (type1_subset, - name, - scaled_font_subset, TRUE); -} - -void -_cairo_type1_fallback_fini (cairo_type1_subset_t *subset) -{ - free (subset->base_font); - free (subset->widths); - free (subset->data); -} - -cairo_status_t -_cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset, - cairo_scaled_font_subset_t *scaled_font_subset) -{ - cairo_type1_font_t *font; - cairo_status_t status; - unsigned int i; - cairo_array_t charstring; - - status = cairo_type1_font_create (scaled_font_subset, &font, FALSE); - if (unlikely (status)) - return status; - - _cairo_array_init (&type2_subset->charstrings, sizeof (cairo_array_t)); - - type2_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs); - if (unlikely (type2_subset->widths == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto fail1; - } - - _cairo_scaled_font_freeze_cache (font->type1_scaled_font); - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - _cairo_array_init (&charstring, sizeof (unsigned char)); - status = _cairo_array_grow_by (&charstring, 32); - if (unlikely (status)) - goto fail2; - - status = cairo_type1_font_create_charstring (font, i, - font->scaled_font_subset->glyphs[i], - CAIRO_CHARSTRING_TYPE2, - &charstring); - if (unlikely (status)) - goto fail2; - - status = _cairo_array_append (&type2_subset->charstrings, &charstring); - if (unlikely (status)) - goto fail2; - } - _cairo_scaled_font_thaw_cache (font->type1_scaled_font); - - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) - type2_subset->widths[i] = font->widths[i]; - - type2_subset->x_min = (int) font->x_min; - type2_subset->y_min = (int) font->y_min; - type2_subset->x_max = (int) font->x_max; - type2_subset->y_max = (int) font->y_max; - type2_subset->ascent = (int) font->y_max; - type2_subset->descent = (int) font->y_min; - - return cairo_type1_font_destroy (font); - -fail2: - _cairo_scaled_font_thaw_cache (font->type1_scaled_font); - _cairo_array_fini (&charstring); - _cairo_type2_charstrings_fini (type2_subset); -fail1: - cairo_type1_font_destroy (font); - return status; -} - -void -_cairo_type2_charstrings_fini (cairo_type2_charstrings_t *type2_subset) -{ - unsigned int i, num_charstrings; - cairo_array_t *charstring; - - num_charstrings = _cairo_array_num_elements (&type2_subset->charstrings); - for (i = 0; i < num_charstrings; i++) { - charstring = _cairo_array_index (&type2_subset->charstrings, i); - _cairo_array_fini (charstring); - } - _cairo_array_fini (&type2_subset->charstrings); - - free (type2_subset->widths); -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-glyph-names.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-glyph-names.c deleted file mode 100644 index 80ccb96269e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-glyph-names.c +++ /dev/null @@ -1,410 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - */ - -#include "cairoint.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-type1-private.h" -#include "cairo-scaled-font-subsets-private.h" - -#if 0 -/* - * The three tables that follow are generated using this perl code: - */ - -@ps_standard_encoding = ( - # 0 - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 16 - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 32 - "space", "exclam", "quotedbl", "numbersign", - "dollar", "percent", "ampersand", "quoteright", - "parenleft", "parenright", "asterisk", "plus", - "comma", "hyphen", "period", "slash", - # 48 - "zero", "one", "two", "three", - "four", "five", "six", "seven", - "eight", "nine", "colon", "semicolon", - "less", "equal", "greater", "question", - # 64 - "at", "A", "B", "C", - "D", "E", "F", "G", - "H", "I", "J", "K", - "L", "M", "N", "O", - # 80 - "P", "Q", "R", "S", - "T", "U", "V", "W", - "X", "Y", "Z", "bracketleft", - "backslash", "bracketright", "asciicircum", "underscore", - # 96 - "quoteleft", "a", "b", "c", - "d", "e", "f", "g", - "h", "i", "j", "k", - "l", "m", "n", "o", - # 112 - "p", "q", "r", "s", - "t", "u", "v", "w", - "x", "y", "z", "braceleft", - "bar", "braceright", "asciitilde", NULL, - # 128 - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 144 - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 160 - NULL, "exclamdown", "cent", "sterling", - "fraction", "yen", "florin", "section", - "currency", "quotesingle", "quotedblleft", "guillemotleft", - "guilsinglleft","guilsinglright","fi", "fl", - # 176 - NULL, "endash", "dagger", "daggerdbl", - "periodcentered",NULL, "paragraph", "bullet", - "quotesinglbase","quotedblbase","quotedblright","guillemotright", - "ellipsis", "perthousand", NULL, "questiondown", - # 192 - NULL, "grave", "acute", "circumflex", - "tilde", "macron", "breve", "dotaccent", - "dieresis", NULL, "ring", "cedilla", - NULL, "hungarumlaut", "ogonek", "caron", - # 208 - "emdash", NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 224 - NULL, "AE", NULL, "ordfeminine", - NULL, NULL, NULL, NULL, - "Lslash", "Oslash", "OE", "ordmasculine", - NULL, NULL, NULL, NULL, - # 240 - NULL, "ae", NULL, NULL, - NULL, "dotlessi", NULL, NULL, - "lslash", "oslash", "oe", "germandbls", - NULL, NULL, NULL, NULL - ); - -@winansi_encoding = ( - # 0 - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 16 - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - # 32 - "space", "exclam", "quotedbl", "numbersign", - "dollar", "percent", "ampersand", "quotesingle", - "parenleft", "parenright", "asterisk", "plus", - "comma", "hyphen", "period", "slash", - # 48 - "zero", "one", "two", "three", - "four", "five", "six", "seven", - "eight", "nine", "colon", "semicolon", - "less", "equal", "greater", "question", - # 64 - "at", "A", "B", "C", - "D", "E", "F", "G", - "H", "I", "J", "K", - "L", "M", "N", "O", - # 80 - "P", "Q", "R", "S", - "T", "U", "V", "W", - "X", "Y", "Z", "bracketleft", - "backslash", "bracketright", "asciicircum", "underscore", - # 96 - "grave", "a", "b", "c", - "d", "e", "f", "g", - "h", "i", "j", "k", - "l", "m", "n", "o", - # 112 - "p", "q", "r", "s", - "t", "u", "v", "w", - "x", "y", "z", "braceleft", - "bar", "braceright", "asciitilde", NULL, - # 128 - "Euro", NULL, "quotesinglbase","florin", - "quotedblbase", "ellipsis", "dagger", "daggerdbl", - "circumflex", "perthousand", "Scaron", "guilsinglleft", - "OE", NULL, "Zcaron", NULL, - # 144 - NULL, "quoteleft", "quoteright", "quotedblleft", - "quotedblright","bullet", "endash", "emdash", - "tilde", "trademark", "scaron", "guilsinglright", - "oe", NULL, "zcaron", "Ydieresis", - # 160 - NULL, "exclamdown", "cent", "sterling", - "currency", "yen", "brokenbar", "section", - "dieresis", "copyright", "ordfeminine", "guillemotleft", - # 173 is also "hyphen" but we leave this NULL to avoid duplicate names - "logicalnot", NULL, "registered", "macron", - # 176 - "degree", "plusminus", "twosuperior", "threesuperior", - "acute", "mu", "paragraph", "periodcentered", - "cedilla", "onesuperior", "ordmasculine", "guillemotright", - "onequarter", "onehalf", "threequarters","questiondown", - # 192 - "Agrave", "Aacute", "Acircumflex", "Atilde", - "Adieresis", "Aring", "AE", "Ccedilla", - "Egrave", "Eacute", "Ecircumflex", "Edieresis", - "Igrave", "Iacute", "Icircumflex", "Idieresis", - # 208 - "Eth", "Ntilde", "Ograve", "Oacute", - "Ocircumflex", "Otilde", "Odieresis", "multiply", - "Oslash", "Ugrave", "Uacute", "Ucircumflex", - "Udieresis", "Yacute", "Thorn", "germandbls", - # 224 - "agrave", "aacute", "acircumflex", "atilde", - "adieresis", "aring", "ae", "ccedilla", - "egrave", "eacute", "ecircumflex", "edieresis", - "igrave", "iacute", "icircumflex", "idieresis", - # 240 - "eth", "ntilde", "ograve", "oacute", - "ocircumflex", "otilde", "odieresis", "divide", - "oslash", "ugrave", "uacute", "ucircumflex", - "udieresis", "yacute", "thorn", "ydieresis" -); - -sub print_offsets { - $s = qq(); - for $sym (@_) { - if (! ($sym eq NULL)) { - $ss = qq( $hash{$sym}/*$sym*/,); - } else { - $ss = qq( 0,); - } - if (length($s) + length($ss) > 78) { - print qq( $s\n); - $s = ""; - } - $s .= $ss; - } - print qq( $s\n); -} - -@combined = (@ps_standard_encoding, @winansi_encoding); -print "static const char glyph_name_symbol[] = {\n"; -%hash = (); -$s = qq( "\\0"); -$offset = 1; -for $sym (@combined) { - if (! ($sym eq NULL)) { - if (! exists $hash{$sym}) { - $hash{$sym} = $offset; - $offset += length($sym) + 1; - $ss = qq( "$sym\\0"); - if (length($s) + length($ss) > 78) { - print qq( $s\n); - $s = ""; - } - $s .= $ss; - } - } -} -print qq( $s\n); -print "};\n\n"; - -print "static const int16_t ps_standard_encoding_offset[256] = {\n"; -print_offsets(@ps_standard_encoding); -print "};\n"; - -print "static const int16_t winansi_encoding_offset[256] = {\n"; -print_offsets(@winansi_encoding); -print "};\n"; - -exit; -#endif - -static const char glyph_name_symbol[] = { - "\0" "space\0" "exclam\0" "quotedbl\0" "numbersign\0" "dollar\0" "percent\0" - "ampersand\0" "quoteright\0" "parenleft\0" "parenright\0" "asterisk\0" - "plus\0" "comma\0" "hyphen\0" "period\0" "slash\0" "zero\0" "one\0" "two\0" - "three\0" "four\0" "five\0" "six\0" "seven\0" "eight\0" "nine\0" "colon\0" - "semicolon\0" "less\0" "equal\0" "greater\0" "question\0" "at\0" "A\0" "B\0" - "C\0" "D\0" "E\0" "F\0" "G\0" "H\0" "I\0" "J\0" "K\0" "L\0" "M\0" "N\0" "O\0" - "P\0" "Q\0" "R\0" "S\0" "T\0" "U\0" "V\0" "W\0" "X\0" "Y\0" "Z\0" - "bracketleft\0" "backslash\0" "bracketright\0" "asciicircum\0" "underscore\0" - "quoteleft\0" "a\0" "b\0" "c\0" "d\0" "e\0" "f\0" "g\0" "h\0" "i\0" "j\0" - "k\0" "l\0" "m\0" "n\0" "o\0" "p\0" "q\0" "r\0" "s\0" "t\0" "u\0" "v\0" "w\0" - "x\0" "y\0" "z\0" "braceleft\0" "bar\0" "braceright\0" "asciitilde\0" - "exclamdown\0" "cent\0" "sterling\0" "fraction\0" "yen\0" "florin\0" - "section\0" "currency\0" "quotesingle\0" "quotedblleft\0" "guillemotleft\0" - "guilsinglleft\0" "guilsinglright\0" "fi\0" "fl\0" "endash\0" "dagger\0" - "daggerdbl\0" "periodcentered\0" "paragraph\0" "bullet\0" "quotesinglbase\0" - "quotedblbase\0" "quotedblright\0" "guillemotright\0" "ellipsis\0" - "perthousand\0" "questiondown\0" "grave\0" "acute\0" "circumflex\0" "tilde\0" - "macron\0" "breve\0" "dotaccent\0" "dieresis\0" "ring\0" "cedilla\0" - "hungarumlaut\0" "ogonek\0" "caron\0" "emdash\0" "AE\0" "ordfeminine\0" - "Lslash\0" "Oslash\0" "OE\0" "ordmasculine\0" "ae\0" "dotlessi\0" "lslash\0" - "oslash\0" "oe\0" "germandbls\0" "Euro\0" "Scaron\0" "Zcaron\0" "trademark\0" - "scaron\0" "zcaron\0" "Ydieresis\0" "brokenbar\0" "copyright\0" - "logicalnot\0" "registered\0" "degree\0" "plusminus\0" "twosuperior\0" - "threesuperior\0" "mu\0" "onesuperior\0" "onequarter\0" "onehalf\0" - "threequarters\0" "Agrave\0" "Aacute\0" "Acircumflex\0" "Atilde\0" - "Adieresis\0" "Aring\0" "Ccedilla\0" "Egrave\0" "Eacute\0" "Ecircumflex\0" - "Edieresis\0" "Igrave\0" "Iacute\0" "Icircumflex\0" "Idieresis\0" "Eth\0" - "Ntilde\0" "Ograve\0" "Oacute\0" "Ocircumflex\0" "Otilde\0" "Odieresis\0" - "multiply\0" "Ugrave\0" "Uacute\0" "Ucircumflex\0" "Udieresis\0" "Yacute\0" - "Thorn\0" "agrave\0" "aacute\0" "acircumflex\0" "atilde\0" "adieresis\0" - "aring\0" "ccedilla\0" "egrave\0" "eacute\0" "ecircumflex\0" "edieresis\0" - "igrave\0" "iacute\0" "icircumflex\0" "idieresis\0" "eth\0" "ntilde\0" - "ograve\0" "oacute\0" "ocircumflex\0" "otilde\0" "odieresis\0" "divide\0" - "ugrave\0" "uacute\0" "ucircumflex\0" "udieresis\0" "yacute\0" "thorn\0" - "ydieresis\0" -}; - -static const int16_t ps_standard_encoding_offset[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1/*space*/, 7/*exclam*/, 14/*quotedbl*/, 23/*numbersign*/, - 34/*dollar*/, 41/*percent*/, 49/*ampersand*/, 59/*quoteright*/, - 70/*parenleft*/, 80/*parenright*/, 91/*asterisk*/, 100/*plus*/, 105/*comma*/, - 111/*hyphen*/, 118/*period*/, 125/*slash*/, 131/*zero*/, 136/*one*/, - 140/*two*/, 144/*three*/, 150/*four*/, 155/*five*/, 160/*six*/, 164/*seven*/, - 170/*eight*/, 176/*nine*/, 181/*colon*/, 187/*semicolon*/, 197/*less*/, - 202/*equal*/, 208/*greater*/, 216/*question*/, 225/*at*/, 228/*A*/, 230/*B*/, - 232/*C*/, 234/*D*/, 236/*E*/, 238/*F*/, 240/*G*/, 242/*H*/, 244/*I*/, - 246/*J*/, 248/*K*/, 250/*L*/, 252/*M*/, 254/*N*/, 256/*O*/, 258/*P*/, - 260/*Q*/, 262/*R*/, 264/*S*/, 266/*T*/, 268/*U*/, 270/*V*/, 272/*W*/, - 274/*X*/, 276/*Y*/, 278/*Z*/, 280/*bracketleft*/, 292/*backslash*/, - 302/*bracketright*/, 315/*asciicircum*/, 327/*underscore*/, 338/*quoteleft*/, - 348/*a*/, 350/*b*/, 352/*c*/, 354/*d*/, 356/*e*/, 358/*f*/, 360/*g*/, - 362/*h*/, 364/*i*/, 366/*j*/, 368/*k*/, 370/*l*/, 372/*m*/, 374/*n*/, - 376/*o*/, 378/*p*/, 380/*q*/, 382/*r*/, 384/*s*/, 386/*t*/, 388/*u*/, - 390/*v*/, 392/*w*/, 394/*x*/, 396/*y*/, 398/*z*/, 400/*braceleft*/, - 410/*bar*/, 414/*braceright*/, 425/*asciitilde*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 436/*exclamdown*/, 447/*cent*/, 452/*sterling*/, 461/*fraction*/, 470/*yen*/, - 474/*florin*/, 481/*section*/, 489/*currency*/, 498/*quotesingle*/, - 510/*quotedblleft*/, 523/*guillemotleft*/, 537/*guilsinglleft*/, - 551/*guilsinglright*/, 566/*fi*/, 569/*fl*/, 0, 572/*endash*/, 579/*dagger*/, - 586/*daggerdbl*/, 596/*periodcentered*/, 0, 611/*paragraph*/, 621/*bullet*/, - 628/*quotesinglbase*/, 643/*quotedblbase*/, 656/*quotedblright*/, - 670/*guillemotright*/, 685/*ellipsis*/, 694/*perthousand*/, 0, - 706/*questiondown*/, 0, 719/*grave*/, 725/*acute*/, 731/*circumflex*/, - 742/*tilde*/, 748/*macron*/, 755/*breve*/, 761/*dotaccent*/, 771/*dieresis*/, - 0, 780/*ring*/, 785/*cedilla*/, 0, 793/*hungarumlaut*/, 806/*ogonek*/, - 813/*caron*/, 819/*emdash*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 826/*AE*/, 0, 829/*ordfeminine*/, 0, 0, 0, 0, 841/*Lslash*/, 848/*Oslash*/, - 855/*OE*/, 858/*ordmasculine*/, 0, 0, 0, 0, 0, 871/*ae*/, 0, 0, 0, - 874/*dotlessi*/, 0, 0, 883/*lslash*/, 890/*oslash*/, 897/*oe*/, - 900/*germandbls*/, 0, 0, 0, 0, -}; - -static const int16_t winansi_encoding_offset[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1/*space*/, 7/*exclam*/, 14/*quotedbl*/, 23/*numbersign*/, - 34/*dollar*/, 41/*percent*/, 49/*ampersand*/, 498/*quotesingle*/, - 70/*parenleft*/, 80/*parenright*/, 91/*asterisk*/, 100/*plus*/, 105/*comma*/, - 111/*hyphen*/, 118/*period*/, 125/*slash*/, 131/*zero*/, 136/*one*/, - 140/*two*/, 144/*three*/, 150/*four*/, 155/*five*/, 160/*six*/, 164/*seven*/, - 170/*eight*/, 176/*nine*/, 181/*colon*/, 187/*semicolon*/, 197/*less*/, - 202/*equal*/, 208/*greater*/, 216/*question*/, 225/*at*/, 228/*A*/, 230/*B*/, - 232/*C*/, 234/*D*/, 236/*E*/, 238/*F*/, 240/*G*/, 242/*H*/, 244/*I*/, - 246/*J*/, 248/*K*/, 250/*L*/, 252/*M*/, 254/*N*/, 256/*O*/, 258/*P*/, - 260/*Q*/, 262/*R*/, 264/*S*/, 266/*T*/, 268/*U*/, 270/*V*/, 272/*W*/, - 274/*X*/, 276/*Y*/, 278/*Z*/, 280/*bracketleft*/, 292/*backslash*/, - 302/*bracketright*/, 315/*asciicircum*/, 327/*underscore*/, 719/*grave*/, - 348/*a*/, 350/*b*/, 352/*c*/, 354/*d*/, 356/*e*/, 358/*f*/, 360/*g*/, - 362/*h*/, 364/*i*/, 366/*j*/, 368/*k*/, 370/*l*/, 372/*m*/, 374/*n*/, - 376/*o*/, 378/*p*/, 380/*q*/, 382/*r*/, 384/*s*/, 386/*t*/, 388/*u*/, - 390/*v*/, 392/*w*/, 394/*x*/, 396/*y*/, 398/*z*/, 400/*braceleft*/, - 410/*bar*/, 414/*braceright*/, 425/*asciitilde*/, 0, 911/*Euro*/, 0, - 628/*quotesinglbase*/, 474/*florin*/, 643/*quotedblbase*/, 685/*ellipsis*/, - 579/*dagger*/, 586/*daggerdbl*/, 731/*circumflex*/, 694/*perthousand*/, - 916/*Scaron*/, 537/*guilsinglleft*/, 855/*OE*/, 0, 923/*Zcaron*/, 0, 0, - 338/*quoteleft*/, 59/*quoteright*/, 510/*quotedblleft*/, - 656/*quotedblright*/, 621/*bullet*/, 572/*endash*/, 819/*emdash*/, - 742/*tilde*/, 930/*trademark*/, 940/*scaron*/, 551/*guilsinglright*/, - 897/*oe*/, 0, 947/*zcaron*/, 954/*Ydieresis*/, 0, 436/*exclamdown*/, - 447/*cent*/, 452/*sterling*/, 489/*currency*/, 470/*yen*/, 964/*brokenbar*/, - 481/*section*/, 771/*dieresis*/, 974/*copyright*/, 829/*ordfeminine*/, - 523/*guillemotleft*/, 984/*logicalnot*/, 0, 995/*registered*/, 748/*macron*/, - 1006/*degree*/, 1013/*plusminus*/, 1023/*twosuperior*/, - 1035/*threesuperior*/, 725/*acute*/, 1049/*mu*/, 611/*paragraph*/, - 596/*periodcentered*/, 785/*cedilla*/, 1052/*onesuperior*/, - 858/*ordmasculine*/, 670/*guillemotright*/, 1064/*onequarter*/, - 1075/*onehalf*/, 1083/*threequarters*/, 706/*questiondown*/, 1097/*Agrave*/, - 1104/*Aacute*/, 1111/*Acircumflex*/, 1123/*Atilde*/, 1130/*Adieresis*/, - 1140/*Aring*/, 826/*AE*/, 1146/*Ccedilla*/, 1155/*Egrave*/, 1162/*Eacute*/, - 1169/*Ecircumflex*/, 1181/*Edieresis*/, 1191/*Igrave*/, 1198/*Iacute*/, - 1205/*Icircumflex*/, 1217/*Idieresis*/, 1227/*Eth*/, 1231/*Ntilde*/, - 1238/*Ograve*/, 1245/*Oacute*/, 1252/*Ocircumflex*/, 1264/*Otilde*/, - 1271/*Odieresis*/, 1281/*multiply*/, 848/*Oslash*/, 1290/*Ugrave*/, - 1297/*Uacute*/, 1304/*Ucircumflex*/, 1316/*Udieresis*/, 1326/*Yacute*/, - 1333/*Thorn*/, 900/*germandbls*/, 1339/*agrave*/, 1346/*aacute*/, - 1353/*acircumflex*/, 1365/*atilde*/, 1372/*adieresis*/, 1382/*aring*/, - 871/*ae*/, 1388/*ccedilla*/, 1397/*egrave*/, 1404/*eacute*/, - 1411/*ecircumflex*/, 1423/*edieresis*/, 1433/*igrave*/, 1440/*iacute*/, - 1447/*icircumflex*/, 1459/*idieresis*/, 1469/*eth*/, 1473/*ntilde*/, - 1480/*ograve*/, 1487/*oacute*/, 1494/*ocircumflex*/, 1506/*otilde*/, - 1513/*odieresis*/, 1523/*divide*/, 890/*oslash*/, 1530/*ugrave*/, - 1537/*uacute*/, 1544/*ucircumflex*/, 1556/*udieresis*/, 1566/*yacute*/, - 1573/*thorn*/, 1579/*ydieresis*/, -}; - -const char * -_cairo_ps_standard_encoding_to_glyphname (int glyph) -{ - if (ps_standard_encoding_offset[glyph]) - return glyph_name_symbol + ps_standard_encoding_offset[glyph]; - else - return NULL; -} - -const char * -_cairo_winansi_to_glyphname (int glyph) -{ - if (winansi_encoding_offset[glyph]) - return glyph_name_symbol + winansi_encoding_offset[glyph]; - else - return NULL; -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-private.h deleted file mode 100644 index 1630397bca6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-private.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Adrian Johnson - */ - -#ifndef CAIRO_TYPE1_PRIVATE_H -#define CAIRO_TYPE1_PRIVATE_H - -#include "cairoint.h" - -#if CAIRO_HAS_FONT_SUBSET - -/* Magic constants for the type1 eexec encryption */ -#define CAIRO_TYPE1_ENCRYPT_C1 ((unsigned short) 52845) -#define CAIRO_TYPE1_ENCRYPT_C2 ((unsigned short) 22719) -#define CAIRO_TYPE1_PRIVATE_DICT_KEY ((unsigned short) 55665) -#define CAIRO_TYPE1_CHARSTRING_KEY ((unsigned short) 4330) - -#endif /* CAIRO_HAS_FONT_SUBSET */ - -#endif /* CAIRO_TYPE1_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-subset.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-subset.c deleted file mode 100644 index b15663509d3..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type1-subset.c +++ /dev/null @@ -1,1821 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - */ - -/* - * Useful links: - * http://partners.adobe.com/public/developer/en/font/T1_SPEC.PDF - */ - - -#define _BSD_SOURCE /* for snprintf(), strdup() */ -#include "cairoint.h" - -#include "cairo-array-private.h" -#include "cairo-error-private.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-type1-private.h" -#include "cairo-scaled-font-subsets-private.h" -#include "cairo-output-stream-private.h" - -#include - -#define TYPE1_STACKSIZE 24 /* Defined in Type 1 Font Format */ - - -typedef struct { - int subset_index; - double width; - const char *encrypted_charstring; - int encrypted_charstring_length; -} glyph_data_t; - -typedef struct _cairo_type1_font_subset { - cairo_scaled_font_subset_t *scaled_font_subset; - - struct { - unsigned int font_id; - char *base_font; - unsigned int num_glyphs; - double x_min, y_min, x_max, y_max; - double ascent, descent; - double units_per_em; - - const char *data; - unsigned long header_size; - unsigned long data_size; - unsigned long trailer_size; - } base; - - int num_glyphs; - - /* The glyphs and glyph_names arrays are indexed by the order of - * the Charstrings in the font. This is not necessarily the same - * order as the glyph index. The index_to_glyph_name() font backend - * function is used to map the glyph index to the glyph order in - * the Charstrings. */ - - glyph_data_t *glyphs; - char **glyph_names; - cairo_array_t glyphs_array; - cairo_array_t glyph_names_array; - - int num_subrs; - cairo_bool_t subset_subrs; - struct { - const char *subr_string; - int subr_length; - const char *np; - int np_length; - cairo_bool_t used; - } *subrs; - - /* Indexed by subset_index this maps to the glyph order in the - * glyph_names and glyphs arrays. Has font->num_golyphs - * elements. */ - int *subset_index_to_glyphs; - - cairo_output_stream_t *output; - cairo_array_t contents; - - const char *rd, *nd, *np; - - int lenIV; - - char *type1_data; - unsigned int type1_length; - char *type1_end; - - char *header_segment; - int header_segment_size; - char *eexec_segment; - int eexec_segment_size; - cairo_bool_t eexec_segment_is_ascii; - - char *cleartext; - char *cleartext_end; - - int header_size; - - unsigned short eexec_key; - cairo_bool_t hex_encode; - int hex_column; - - struct { - double stack[TYPE1_STACKSIZE]; - int sp; - } build_stack; - - struct { - int stack[TYPE1_STACKSIZE]; - int sp; - } ps_stack; - - -} cairo_type1_font_subset_t; - - -static cairo_status_t -_cairo_type1_font_subset_init (cairo_type1_font_subset_t *font, - cairo_scaled_font_subset_t *scaled_font_subset, - cairo_bool_t hex_encode) -{ - memset (font, 0, sizeof (*font)); - font->scaled_font_subset = scaled_font_subset; - - _cairo_array_init (&font->glyphs_array, sizeof (glyph_data_t)); - _cairo_array_init (&font->glyph_names_array, sizeof (char *)); - font->subset_index_to_glyphs = NULL; - font->base.num_glyphs = 0; - font->num_subrs = 0; - font->subset_subrs = TRUE; - font->subrs = NULL; - - font->hex_encode = hex_encode; - font->num_glyphs = 0; - - _cairo_array_init (&font->contents, sizeof (char)); - - return CAIRO_STATUS_SUCCESS; -} - -static void -cairo_type1_font_subset_use_glyph (cairo_type1_font_subset_t *font, int glyph) -{ - if (font->glyphs[glyph].subset_index >= 0) - return; - - font->glyphs[glyph].subset_index = font->num_glyphs; - font->subset_index_to_glyphs[font->num_glyphs] = glyph; - font->num_glyphs++; -} - -static cairo_bool_t -is_ps_delimiter(int c) -{ - static const char delimiters[] = "()[]{}<>/% \t\r\n"; - - return strchr (delimiters, c) != NULL; -} - -static const char * -find_token (const char *buffer, const char *end, const char *token) -{ - int i, length; - /* FIXME: find substring really must be find_token */ - - if (buffer == NULL) - return NULL; - - length = strlen (token); - for (i = 0; buffer + i < end - length + 1; i++) - if (memcmp (buffer + i, token, length) == 0) - if ((i == 0 || token[0] == '/' || is_ps_delimiter(buffer[i - 1])) && - (buffer + i == end - length || is_ps_delimiter(buffer[i + length]))) - return buffer + i; - - return NULL; -} - -static cairo_status_t -cairo_type1_font_subset_find_segments (cairo_type1_font_subset_t *font) -{ - unsigned char *p; - const char *eexec_token; - int size, i; - - p = (unsigned char *) font->type1_data; - font->type1_end = font->type1_data + font->type1_length; - if (p[0] == 0x80 && p[1] == 0x01) { - font->header_segment_size = - p[2] | (p[3] << 8) | (p[4] << 16) | (p[5] << 24); - font->header_segment = (char *) p + 6; - - p += 6 + font->header_segment_size; - font->eexec_segment_size = - p[2] | (p[3] << 8) | (p[4] << 16) | (p[5] << 24); - font->eexec_segment = (char *) p + 6; - font->eexec_segment_is_ascii = (p[1] == 1); - - p += 6 + font->eexec_segment_size; - while (p < (unsigned char *) (font->type1_end) && p[1] != 0x03) { - size = p[2] | (p[3] << 8) | (p[4] << 16) | (p[5] << 24); - p += 6 + size; - } - font->type1_end = (char *) p; - } else { - eexec_token = find_token ((char *) p, font->type1_end, "eexec"); - if (eexec_token == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - font->header_segment_size = eexec_token - (char *) p + strlen ("eexec\n"); - font->header_segment = (char *) p; - font->eexec_segment_size = font->type1_length - font->header_segment_size; - font->eexec_segment = (char *) p + font->header_segment_size; - font->eexec_segment_is_ascii = TRUE; - for (i = 0; i < 4; i++) { - if (!isxdigit(font->eexec_segment[i])) - font->eexec_segment_is_ascii = FALSE; - } - } - - return CAIRO_STATUS_SUCCESS; -} - -/* Search for the definition of key and erase it by overwriting with spaces. - * This function is looks for definitions of the form: - * - * /key1 1234 def - * /key2 [12 34 56] def - * - * ie a key defined as an integer or array of integers. - * - */ -static void -cairo_type1_font_erase_dict_key (cairo_type1_font_subset_t *font, - const char *key) -{ - const char *start, *p, *segment_end; - - segment_end = font->header_segment + font->header_segment_size; - - start = font->header_segment; - do { - start = find_token (start, segment_end, key); - if (start) { - p = start + strlen(key); - /* skip integers or array of integers */ - while (p < segment_end && - (_cairo_isspace(*p) || - _cairo_isdigit(*p) || - *p == '[' || - *p == ']')) - { - p++; - } - - if (p + 3 < segment_end && memcmp(p, "def", 3) == 0) { - /* erase definition of the key */ - memset((char *) start, ' ', p + 3 - start); - } - start += strlen(key); - } - } while (start); -} - -static cairo_status_t -cairo_type1_font_subset_get_matrix (cairo_type1_font_subset_t *font, - const char *name, - double *a, - double *b, - double *c, - double *d) -{ - const char *start, *end, *segment_end; - int ret, s_max, i, j; - char *s; - const char *decimal_point; - int decimal_point_len; - - decimal_point = cairo_get_locale_decimal_point (); - decimal_point_len = strlen (decimal_point); - - assert (decimal_point_len != 0); - - segment_end = font->header_segment + font->header_segment_size; - start = find_token (font->header_segment, segment_end, name); - if (start == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - end = find_token (start, segment_end, "def"); - if (end == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - s_max = end - start + 5*decimal_point_len + 1; - s = malloc (s_max); - if (unlikely (s == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - i = 0; - j = 0; - while (i < end - start && j < s_max - decimal_point_len) { - if (start[i] == '.') { - strncpy(s + j, decimal_point, decimal_point_len); - i++; - j += decimal_point_len; - } else { - s[j++] = start[i++]; - } - } - s[j] = 0; - - start = strpbrk (s, "{["); - if (!start) { - free (s); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - start++; - ret = 0; - if (*start) - ret = sscanf(start, "%lf %lf %lf %lf", a, b, c, d); - - free (s); - - if (ret != 4) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_type1_font_subset_get_bbox (cairo_type1_font_subset_t *font) -{ - cairo_status_t status; - double x_min, y_min, x_max, y_max; - double xx, yx, xy, yy; - - status = cairo_type1_font_subset_get_matrix (font, "/FontBBox", - &x_min, - &y_min, - &x_max, - &y_max); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_get_matrix (font, "/FontMatrix", - &xx, &yx, &xy, &yy); - if (unlikely (status)) - return status; - - if (yy == 0.0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Freetype uses 1/yy to get units per EM */ - font->base.units_per_em = 1.0/yy; - - font->base.x_min = x_min / font->base.units_per_em; - font->base.y_min = y_min / font->base.units_per_em; - font->base.x_max = x_max / font->base.units_per_em; - font->base.y_max = y_max / font->base.units_per_em; - font->base.ascent = font->base.y_max; - font->base.descent = font->base.y_min; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_type1_font_subset_get_fontname (cairo_type1_font_subset_t *font) -{ - const char *start, *end, *segment_end; - char *s; - int i; - cairo_status_t status; - - segment_end = font->header_segment + font->header_segment_size; - start = find_token (font->header_segment, segment_end, "/FontName"); - if (start == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - start += strlen ("/FontName"); - - end = find_token (start, segment_end, "def"); - if (end == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - while (end > start && _cairo_isspace(end[-1])) - end--; - - s = malloc (end - start + 1); - if (unlikely (s == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - strncpy (s, start, end - start); - s[end - start] = 0; - - start = strchr (s, '/'); - if (!start++ || !start) { - free (s); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* If font name is prefixed with a subset tag, strip it off. */ - if (strlen(start) > 7 && start[6] == '+') { - for (i = 0; i < 6; i++) { - if (start[i] < 'A' || start[i] > 'Z') - break; - } - if (i == 6) - start += 7; - } - - font->base.base_font = strdup (start); - free (s); - if (unlikely (font->base.base_font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_escape_ps_name (&font->base.base_font); - - return status; -} - -static cairo_status_t -cairo_type1_font_subset_write_header (cairo_type1_font_subset_t *font, - const char *name) -{ - const char *start, *end, *segment_end; - unsigned int i; - - /* FIXME: - * This function assumes that /FontName always appears - * before /Encoding. This appears to always be the case with Type1 - * fonts. - * - * The more recently added code for removing the UniqueID and XUID - * keys can not make any assumptions about the position of the - * keys in the dictionary so it is implemented by overwriting the - * key definition with spaces before we start copying the font to - * the output. - * - * This code should be rewritten to not make any assumptions about - * the order of dictionary keys. This will allow UniqueID to be - * stripped out instead of leaving a bunch of spaces in the - * output. - */ - cairo_type1_font_erase_dict_key (font, "/UniqueID"); - cairo_type1_font_erase_dict_key (font, "/XUID"); - - segment_end = font->header_segment + font->header_segment_size; - - /* Type 1 fonts created by Fontforge have some PostScript code at - * the start of the font that skips the font if the printer has a - * cached copy of the font with the same unique id. This breaks - * our subsetted font so we disable it by searching for the - * PostScript operator "known" when used to check for the - * "/UniqueID" dictionary key. We append " pop false " after it to - * pop the result of this check off the stack and replace it with - * "false" to make the PostScript code think "/UniqueID" does not - * exist. - */ - end = font->header_segment; - start = find_token (font->header_segment, segment_end, "/UniqueID"); - if (start) { - start += 9; - while (start < segment_end && _cairo_isspace (*start)) - start++; - if (start + 5 < segment_end && memcmp(start, "known", 5) == 0) { - _cairo_output_stream_write (font->output, font->header_segment, - start + 5 - font->header_segment); - _cairo_output_stream_printf (font->output, " pop false "); - end = start + 5; - } - } - - start = find_token (end, segment_end, "/FontName"); - if (start == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_output_stream_write (font->output, end, - start - end); - - _cairo_output_stream_printf (font->output, "/FontName /%s def", name); - - end = find_token (start, segment_end, "def"); - if (end == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - end += 3; - - start = find_token (end, segment_end, "/Encoding"); - if (start == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - _cairo_output_stream_write (font->output, end, start - end); - - _cairo_output_stream_printf (font->output, - "/Encoding 256 array\n" - "0 1 255 {1 index exch /.notdef put} for\n"); - if (font->scaled_font_subset->is_latin) { - for (i = 1; i < 256; i++) { - int subset_glyph = font->scaled_font_subset->latin_to_subset_glyph_index[i]; - - if (subset_glyph > 0) { - _cairo_output_stream_printf (font->output, - "dup %d /%s put\n", - i, - _cairo_winansi_to_glyphname (i)); - } - } - } else { - for (i = 0; i < font->base.num_glyphs; i++) { - if (font->glyphs[i].subset_index <= 0) - continue; - _cairo_output_stream_printf (font->output, - "dup %d /%s put\n", - font->glyphs[i].subset_index, - font->glyph_names[i]); - } - } - _cairo_output_stream_printf (font->output, "readonly def"); - - end = find_token (start, segment_end, "def"); - if (end == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - end += 3; - - /* There are some buggy fonts that contain more than one /Encoding */ - if (find_token (end, segment_end, "/Encoding")) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_output_stream_write (font->output, end, segment_end - end); - - return font->output->status; -} - -static int -hex_to_int (int ch) -{ - if (ch <= '9') - return ch - '0'; - else if (ch <= 'F') - return ch - 'A' + 10; - else - return ch - 'a' + 10; -} - -static cairo_status_t -cairo_type1_font_subset_write_encrypted (cairo_type1_font_subset_t *font, - const char *data, unsigned int length) -{ - const unsigned char *in, *end; - int c, p; - static const char hex_digits[16] = "0123456789abcdef"; - char digits[3]; - - in = (const unsigned char *) data; - end = (const unsigned char *) data + length; - while (in < end) { - p = *in++; - c = p ^ (font->eexec_key >> 8); - font->eexec_key = (c + font->eexec_key) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; - - if (font->hex_encode) { - digits[0] = hex_digits[c >> 4]; - digits[1] = hex_digits[c & 0x0f]; - digits[2] = '\n'; - font->hex_column += 2; - - if (font->hex_column == 78) { - _cairo_output_stream_write (font->output, digits, 3); - font->hex_column = 0; - } else { - _cairo_output_stream_write (font->output, digits, 2); - } - } else { - digits[0] = c; - _cairo_output_stream_write (font->output, digits, 1); - } - } - - return font->output->status; -} - -static cairo_status_t -cairo_type1_font_subset_decrypt_eexec_segment (cairo_type1_font_subset_t *font) -{ - unsigned short r = CAIRO_TYPE1_PRIVATE_DICT_KEY; - unsigned char *in, *end; - char *out; - int c, p; - int i; - - in = (unsigned char *) font->eexec_segment; - end = (unsigned char *) in + font->eexec_segment_size; - - font->cleartext = malloc (font->eexec_segment_size + 1); - if (unlikely (font->cleartext == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - out = font->cleartext; - while (in < end) { - if (font->eexec_segment_is_ascii) { - c = *in++; - if (_cairo_isspace (c)) - continue; - c = (hex_to_int (c) << 4) | hex_to_int (*in++); - } else { - c = *in++; - } - p = c ^ (r >> 8); - r = (c + r) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; - - *out++ = p; - } - font->cleartext_end = out; - - /* Overwrite random bytes with spaces. - * - * The first 4 bytes of the cleartext are the random bytes - * required by the encryption algorithm. When encrypting the - * cleartext, the first ciphertext byte must not be a white space - * character and the first 4 bytes must not be an ASCII Hex - * character. Some fonts do not check that their randomly chosen - * bytes results in ciphertext that complies with this - * restriction. This may cause problems for some PDF consumers. By - * replacing the random bytes with spaces, the first four bytes of - * ciphertext will always be 0xf9, 0x83, 0xef, 0x00 which complies - * with this restriction. Using spaces also means we don't have to - * skip over the random bytes when parsing the cleartext. - */ - for (i = 0; i < 4 && i < font->eexec_segment_size; i++) - font->cleartext[i] = ' '; - - /* Ensure strtol() can not scan past the end of the cleartext */ - font->cleartext[font->eexec_segment_size] = 0; - - return CAIRO_STATUS_SUCCESS; -} - -static const char * -skip_token (const char *p, const char *end) -{ - while (p < end && _cairo_isspace(*p)) - p++; - - while (p < end && !_cairo_isspace(*p)) - p++; - - if (p == end) - return NULL; - - return p; -} - -static void -cairo_type1_font_subset_decrypt_charstring (const unsigned char *in, int size, unsigned char *out) -{ - unsigned short r = CAIRO_TYPE1_CHARSTRING_KEY; - int c, p, i; - - for (i = 0; i < size; i++) { - c = *in++; - p = c ^ (r >> 8); - r = (c + r) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; - *out++ = p; - } -} - -static const unsigned char * -cairo_type1_font_subset_decode_integer (const unsigned char *p, int *integer) -{ - if (*p <= 246) { - *integer = *p++ - 139; - } else if (*p <= 250) { - *integer = (p[0] - 247) * 256 + p[1] + 108; - p += 2; - } else if (*p <= 254) { - *integer = -(p[0] - 251) * 256 - p[1] - 108; - p += 2; - } else { - *integer = (p[1] << 24) | (p[2] << 16) | (p[3] << 8) | p[4]; - p += 5; - } - - return p; -} - -static cairo_status_t -use_standard_encoding_glyph (cairo_type1_font_subset_t *font, int index) -{ - const char *glyph_name; - unsigned int i; - - if (index < 0 || index > 255) - return CAIRO_STATUS_SUCCESS; - - glyph_name = _cairo_ps_standard_encoding_to_glyphname (index); - if (glyph_name == NULL) - return CAIRO_STATUS_SUCCESS; - - for (i = 0; i < font->base.num_glyphs; i++) { - if (font->glyph_names[i] && strcmp (font->glyph_names[i], glyph_name) == 0) { - cairo_type1_font_subset_use_glyph (font, i); - - return CAIRO_STATUS_SUCCESS; - } - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - - -#define TYPE1_CHARSTRING_COMMAND_HSTEM 0x01 -#define TYPE1_CHARSTRING_COMMAND_VSTEM 0x03 -#define TYPE1_CHARSTRING_COMMAND_VMOVETO 0x04 -#define TYPE1_CHARSTRING_COMMAND_RLINETO 0x05 -#define TYPE1_CHARSTRING_COMMAND_HLINETO 0x06 -#define TYPE1_CHARSTRING_COMMAND_VLINETO 0x07 -#define TYPE1_CHARSTRING_COMMAND_RRCURVETO 0x08 -#define TYPE1_CHARSTRING_COMMAND_CLOSEPATH 0x09 -#define TYPE1_CHARSTRING_COMMAND_CALLSUBR 0x0a -#define TYPE1_CHARSTRING_COMMAND_RETURN 0x0b -#define TYPE1_CHARSTRING_COMMAND_ESCAPE 0x0c -#define TYPE1_CHARSTRING_COMMAND_HSBW 0x0d -#define TYPE1_CHARSTRING_COMMAND_ENDCHAR 0x0e -#define TYPE1_CHARSTRING_COMMAND_RMOVETO 0x15 -#define TYPE1_CHARSTRING_COMMAND_HMOVETO 0x16 -#define TYPE1_CHARSTRING_COMMAND_VHCURVETO 0x1e -#define TYPE1_CHARSTRING_COMMAND_HVCURVETO 0x1f -#define TYPE1_CHARSTRING_COMMAND_DOTSECTION 0x0c00 -#define TYPE1_CHARSTRING_COMMAND_VSTEM3 0x0c01 -#define TYPE1_CHARSTRING_COMMAND_HSTEM3 0x0c02 -#define TYPE1_CHARSTRING_COMMAND_SEAC 0x0c06 -#define TYPE1_CHARSTRING_COMMAND_SBW 0x0c07 -#define TYPE1_CHARSTRING_COMMAND_DIV 0x0c0c -#define TYPE1_CHARSTRING_COMMAND_CALLOTHERSUBR 0x0c10 -#define TYPE1_CHARSTRING_COMMAND_POP 0x0c11 -#define TYPE1_CHARSTRING_COMMAND_SETCURRENTPOINT 0x0c21 - -/* Parse the charstring, including recursing into subroutines. Find - * the glyph width, subroutines called, and glyphs required by the - * SEAC operator. */ -static cairo_status_t -cairo_type1_font_subset_parse_charstring (cairo_type1_font_subset_t *font, - int glyph, - const char *encrypted_charstring, - int encrypted_charstring_length) -{ - cairo_status_t status; - unsigned char *charstring; - const unsigned char *end; - const unsigned char *p; - int command; - - charstring = malloc (encrypted_charstring_length); - if (unlikely (charstring == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - cairo_type1_font_subset_decrypt_charstring ((const unsigned char *) - encrypted_charstring, - encrypted_charstring_length, - charstring); - end = charstring + encrypted_charstring_length; - p = charstring + font->lenIV; - status = CAIRO_STATUS_SUCCESS; - while (p < end) { - if (*p < 32) { - command = *p++; - switch (command) { - case TYPE1_CHARSTRING_COMMAND_HSTEM: - case TYPE1_CHARSTRING_COMMAND_VSTEM: - case TYPE1_CHARSTRING_COMMAND_VMOVETO: - case TYPE1_CHARSTRING_COMMAND_RLINETO: - case TYPE1_CHARSTRING_COMMAND_HLINETO: - case TYPE1_CHARSTRING_COMMAND_VLINETO: - case TYPE1_CHARSTRING_COMMAND_RRCURVETO: - case TYPE1_CHARSTRING_COMMAND_CLOSEPATH: - case TYPE1_CHARSTRING_COMMAND_RMOVETO: - case TYPE1_CHARSTRING_COMMAND_HMOVETO: - case TYPE1_CHARSTRING_COMMAND_VHCURVETO: - case TYPE1_CHARSTRING_COMMAND_HVCURVETO: - case TYPE1_CHARSTRING_COMMAND_RETURN: - case TYPE1_CHARSTRING_COMMAND_ENDCHAR: - default: - /* stack clearing operator */ - font->build_stack.sp = 0; - break; - - case TYPE1_CHARSTRING_COMMAND_CALLSUBR: - if (font->subset_subrs && font->build_stack.sp > 0) { - double int_val; - if (modf(font->build_stack.stack[--font->build_stack.sp], &int_val) == 0.0) { - int subr_num = int_val; - if (subr_num >= 0 && subr_num < font->num_subrs) { - font->subrs[subr_num].used = TRUE; - status = cairo_type1_font_subset_parse_charstring ( - font, - glyph, - font->subrs[subr_num].subr_string, - font->subrs[subr_num].subr_length); - break; - } - } - } - font->subset_subrs = FALSE; - break; - - case TYPE1_CHARSTRING_COMMAND_HSBW: - if (font->build_stack.sp < 2) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - - font->glyphs[glyph].width = font->build_stack.stack[1]/font->base.units_per_em; - font->build_stack.sp = 0; - break; - - case TYPE1_CHARSTRING_COMMAND_ESCAPE: - command = command << 8 | *p++; - switch (command) { - case TYPE1_CHARSTRING_COMMAND_DOTSECTION: - case TYPE1_CHARSTRING_COMMAND_VSTEM3: - case TYPE1_CHARSTRING_COMMAND_HSTEM3: - case TYPE1_CHARSTRING_COMMAND_SETCURRENTPOINT: - default: - /* stack clearing operator */ - font->build_stack.sp = 0; - break; - - case TYPE1_CHARSTRING_COMMAND_SEAC: - /* The seac command takes five integer arguments. The - * last two are glyph indices into the PS standard - * encoding give the names of the glyphs that this - * glyph is composed from. All we need to do is to - * make sure those glyphs are present in the subset - * under their standard names. */ - if (font->build_stack.sp < 5) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - - status = use_standard_encoding_glyph (font, font->build_stack.stack[3]); - if (unlikely (status)) - goto cleanup; - - status = use_standard_encoding_glyph (font, font->build_stack.stack[4]); - if (unlikely (status)) - goto cleanup; - - font->build_stack.sp = 0; - break; - - case TYPE1_CHARSTRING_COMMAND_SBW: - if (font->build_stack.sp < 4) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - - font->glyphs[glyph].width = font->build_stack.stack[2]/font->base.units_per_em; - font->build_stack.sp = 0; - break; - - case TYPE1_CHARSTRING_COMMAND_DIV: - if (font->build_stack.sp < 2) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } else { - double num1 = font->build_stack.stack[font->build_stack.sp - 2]; - double num2 = font->build_stack.stack[font->build_stack.sp - 1]; - font->build_stack.sp--; - if (num2 == 0.0) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - font->build_stack.stack[font->build_stack.sp - 1] = num1/num2; - } - break; - - case TYPE1_CHARSTRING_COMMAND_CALLOTHERSUBR: - if (font->build_stack.sp < 1) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - - font->build_stack.sp--; - font->ps_stack.sp = 0; - while (font->build_stack.sp) - font->ps_stack.stack[font->ps_stack.sp++] = font->build_stack.stack[--font->build_stack.sp]; - - break; - - case TYPE1_CHARSTRING_COMMAND_POP: - if (font->ps_stack.sp < 1) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - - /* T1 spec states that if the interpreter does not - * support executing the callothersub, the results - * must be taken from the callothersub arguments. */ - font->build_stack.stack[font->build_stack.sp++] = font->ps_stack.stack[--font->ps_stack.sp]; - break; - } - break; - } - } else { - /* integer argument */ - if (font->build_stack.sp < TYPE1_STACKSIZE) { - int val; - p = cairo_type1_font_subset_decode_integer (p, &val); - font->build_stack.stack[font->build_stack.sp++] = val; - } else { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto cleanup; - } - } - } - -cleanup: - free (charstring); - - return status; -} - -static cairo_status_t -cairo_type1_font_subset_build_subr_list (cairo_type1_font_subset_t *font, - int subr_number, - const char *encrypted_charstring, int encrypted_charstring_length, - const char *np, int np_length) -{ - - font->subrs[subr_number].subr_string = encrypted_charstring; - font->subrs[subr_number].subr_length = encrypted_charstring_length; - font->subrs[subr_number].np = np; - font->subrs[subr_number].np_length = np_length; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -write_used_subrs (cairo_type1_font_subset_t *font, - int subr_number, - const char *subr_string, int subr_string_length, - const char *np, int np_length) -{ - cairo_status_t status; - char buffer[256]; - int length; - - if (!font->subrs[subr_number].used) - return CAIRO_STATUS_SUCCESS; - - length = snprintf (buffer, sizeof buffer, - "dup %d %d %s ", - subr_number, subr_string_length, font->rd); - status = cairo_type1_font_subset_write_encrypted (font, buffer, length); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_write_encrypted (font, - subr_string, - subr_string_length); - if (unlikely (status)) - return status; - - if (np) { - status = cairo_type1_font_subset_write_encrypted (font, np, np_length); - } else { - length = snprintf (buffer, sizeof buffer, "%s\n", font->np); - status = cairo_type1_font_subset_write_encrypted (font, buffer, length); - } - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -typedef cairo_status_t (*subr_func_t) (cairo_type1_font_subset_t *font, - int subr_number, - const char *subr_string, int subr_string_length, - const char *np, int np_length); - -static cairo_status_t -cairo_type1_font_for_each_subr (cairo_type1_font_subset_t *font, - const char *array_start, - const char *cleartext_end, - subr_func_t func, - const char **array_end) -{ - const char *p, *subr_string; - char *end; - int subr_num, subr_length; - const char *np; - int np_length; - cairo_status_t status; - - /* We're looking at "dup" at the start of the first subroutine. The subroutines - * definitions are on the form: - * - * dup 5 23 RD <23 binary bytes> NP - * - * or alternatively using -| and |- instead of RD and ND. - * The first number is the subroutine number. - */ - - p = array_start; - while (p + 3 < cleartext_end && strncmp (p, "dup", 3) == 0) { - p = skip_token (p, cleartext_end); - - /* get subr number */ - subr_num = strtol (p, &end, 10); - if (p == end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (subr_num < 0 || subr_num >= font->num_subrs) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* get subr length */ - p = end; - subr_length = strtol (p, &end, 10); - if (p == end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Skip past -| or RD to binary data. There is exactly one space - * between the -| or RD token and the encrypted data, thus '+ 1'. */ - subr_string = skip_token (end, cleartext_end) + 1; - - np = NULL; - np_length = 0; - - /* Skip binary data and | or NP token. */ - p = skip_token (subr_string + subr_length, cleartext_end); - while (p < cleartext_end && _cairo_isspace(*p)) - p++; - - /* Some fonts have "noaccess put" instead of "NP" */ - if (p + 3 < cleartext_end && strncmp (p, "put", 3) == 0) { - p = skip_token (p, cleartext_end); - while (p < cleartext_end && _cairo_isspace(*p)) - p++; - - np = subr_string + subr_length; - np_length = p - np; - } - - status = func (font, subr_num, - subr_string, subr_length, np, np_length); - if (unlikely (status)) - return status; - - } - - *array_end = (char *) p; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_type1_font_subset_build_glyph_list (cairo_type1_font_subset_t *font, - int glyph_number, - const char *name, int name_length, - const char *encrypted_charstring, int encrypted_charstring_length) -{ - char *s; - glyph_data_t glyph; - cairo_status_t status; - - s = malloc (name_length + 1); - if (unlikely (s == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - strncpy (s, name, name_length); - s[name_length] = 0; - - status = _cairo_array_append (&font->glyph_names_array, &s); - if (unlikely (status)) - return status; - - glyph.subset_index = -1; - glyph.width = 0; - glyph.encrypted_charstring = encrypted_charstring; - glyph.encrypted_charstring_length = encrypted_charstring_length; - status = _cairo_array_append (&font->glyphs_array, &glyph); - - return status; -} - -static cairo_status_t -write_used_glyphs (cairo_type1_font_subset_t *font, - int glyph_number, - const char *name, int name_length, - const char *charstring, int charstring_length) -{ - cairo_status_t status; - char buffer[256]; - int length; - unsigned int subset_id; - int ch; - const char *wa_name; - - if (font->glyphs[glyph_number].subset_index < 0) - return CAIRO_STATUS_SUCCESS; - - if (font->scaled_font_subset->is_latin) { - /* When using the WinAnsi encoding in PDF, the /Encoding array - * is ignored and instead glyphs are keyed by glyph names. To - * ensure correct rendering we replace the glyph name in the - * font with the standard name. - **/ - subset_id = font->glyphs[glyph_number].subset_index; - /* Any additional glyph included for use by the seac operator - * will either have subset_id >= font->scaled_font_subset->num_glyphs - * or will not map to a winansi name (wa_name = NULL). In this - * case the original name is used. - */ - if (subset_id > 0 && subset_id < font->scaled_font_subset->num_glyphs) { - ch = font->scaled_font_subset->to_latin_char[subset_id]; - wa_name = _cairo_winansi_to_glyphname (ch); - if (wa_name) { - name = wa_name; - name_length = strlen(name); - } - } - } - - length = snprintf (buffer, sizeof buffer, - "/%.*s %d %s ", - name_length, name, charstring_length, font->rd); - status = cairo_type1_font_subset_write_encrypted (font, buffer, length); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_write_encrypted (font, - charstring, - charstring_length); - if (unlikely (status)) - return status; - - length = snprintf (buffer, sizeof buffer, "%s\n", font->nd); - status = cairo_type1_font_subset_write_encrypted (font, buffer, length); - if (unlikely (status)) - return status; - - return CAIRO_STATUS_SUCCESS; -} - -typedef cairo_status_t (*glyph_func_t) (cairo_type1_font_subset_t *font, - int glyph_number, - const char *name, int name_length, - const char *charstring, int charstring_length); - -static cairo_status_t -cairo_type1_font_subset_for_each_glyph (cairo_type1_font_subset_t *font, - const char *dict_start, - const char *dict_end, - glyph_func_t func, - const char **dict_out) -{ - int charstring_length, name_length; - const char *p, *charstring, *name; - char *end; - cairo_status_t status; - int glyph_count; - - /* We're looking at '/' in the name of the first glyph. The glyph - * definitions are on the form: - * - * /name 23 RD <23 binary bytes> ND - * - * or alternatively using -| and |- instead of RD and ND. - * - * We parse the glyph name and see if it is in the subset. If it - * is, we call the specified callback with the glyph name and - * glyph data, otherwise we just skip it. We need to parse - * through a glyph definition; we can't just find the next '/', - * since the binary data could contain a '/'. - */ - - p = dict_start; - glyph_count = 0; - while (*p == '/') { - name = p + 1; - p = skip_token (p, dict_end); - name_length = p - name; - - charstring_length = strtol (p, &end, 10); - if (p == end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Skip past -| or RD to binary data. There is exactly one space - * between the -| or RD token and the encrypted data, thus '+ 1'. */ - charstring = skip_token (end, dict_end) + 1; - - /* Skip binary data and |- or ND token. */ - p = skip_token (charstring + charstring_length, dict_end); - while (p < dict_end && _cairo_isspace(*p)) - p++; - - /* In case any of the skip_token() calls above reached EOF, p will - * be equal to dict_end. */ - if (p == dict_end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = func (font, glyph_count++, - name, name_length, - charstring, charstring_length); - if (unlikely (status)) - return status; - } - - *dict_out = p; - - return CAIRO_STATUS_SUCCESS; -} - - -static cairo_status_t -cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font, - const char *name) -{ - cairo_status_t status; - const char *p, *subrs, *charstrings, *array_start, *array_end, *dict_start, *dict_end; - const char *lenIV_start, *lenIV_end, *closefile_token; - char buffer[32], *lenIV_str, *subr_count_end, *glyph_count_end; - int ret, lenIV, length; - const cairo_scaled_font_backend_t *backend; - unsigned int i; - int glyph, j; - - /* The private dict holds hint information, common subroutines and - * the actual glyph definitions (charstrings). - * - * What we do here is scan directly to the /Subrs token, which - * marks the beginning of the subroutines. We read in all the - * subroutines, then move on to the /CharString token, which marks - * the beginning of the glyph definitions, and read in the charstrings. - * - * The charstrings are parsed to extract glyph widths, work out - * which subroutines are called, and to see if any extra glyphs - * need to be included due to the use of the seac glyph combining - * operator. - * - * Finally, the private dict is copied to the subset font minus the - * subroutines and charstrings not required. - */ - - /* Determine lenIV, the number of random characters at the start of - each encrypted charstring. The default is 4, but this can be - overridden in the private dict. */ - font->lenIV = 4; - if ((lenIV_start = find_token (font->cleartext, font->cleartext_end, "/lenIV")) != NULL) { - lenIV_start += 6; - lenIV_end = find_token (lenIV_start, font->cleartext_end, "def"); - if (lenIV_end == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - lenIV_str = malloc (lenIV_end - lenIV_start + 1); - if (unlikely (lenIV_str == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - strncpy (lenIV_str, lenIV_start, lenIV_end - lenIV_start); - lenIV_str[lenIV_end - lenIV_start] = 0; - - ret = sscanf(lenIV_str, "%d", &lenIV); - free(lenIV_str); - - if (unlikely (ret <= 0)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Apparently some fonts signal unencrypted charstrings with a negative lenIV, - though this is not part of the Type 1 Font Format specification. See, e.g. - http://lists.gnu.org/archive/html/freetype-devel/2000-06/msg00064.html. */ - if (unlikely (lenIV < 0)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - font->lenIV = lenIV; - } - - /* Find start of Subrs */ - subrs = find_token (font->cleartext, font->cleartext_end, "/Subrs"); - if (subrs == NULL) { - font->subset_subrs = FALSE; - p = font->cleartext; - array_start = NULL; - goto skip_subrs; - } - - /* Scan past /Subrs and get the array size. */ - p = subrs + strlen ("/Subrs"); - font->num_subrs = strtol (p, &subr_count_end, 10); - if (subr_count_end == p) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (font->num_subrs <= 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - font->subrs = calloc (font->num_subrs, sizeof (font->subrs[0])); - if (unlikely (font->subrs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - /* look for "dup" which marks the beginning of the first subr */ - array_start = find_token (subr_count_end, font->cleartext_end, "dup"); - if (subrs == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Read in the subroutines */ - status = cairo_type1_font_for_each_subr (font, - array_start, - font->cleartext_end, - cairo_type1_font_subset_build_subr_list, - &array_end); - if (unlikely(status)) - return status; - - p = array_end; -skip_subrs: - - /* Find start of CharStrings */ - charstrings = find_token (p, font->cleartext_end, "/CharStrings"); - if (charstrings == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Scan past /CharStrings and the integer following it. */ - p = charstrings + strlen ("/CharStrings"); - strtol (p, &glyph_count_end, 10); - if (p == glyph_count_end) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Look for a '/' which marks the beginning of the first glyph - * definition. */ - for (p = glyph_count_end; p < font->cleartext_end; p++) - if (*p == '/') - break; - if (p == font->cleartext_end) - return CAIRO_INT_STATUS_UNSUPPORTED; - dict_start = p; - - /* Now that we have the private dictionary broken down in - * sections, do the first pass through the glyph definitions to - * build a list of glyph names and charstrings. */ - status = cairo_type1_font_subset_for_each_glyph (font, - dict_start, - font->cleartext_end, - cairo_type1_font_subset_build_glyph_list, - &dict_end); - if (unlikely(status)) - return status; - - font->glyphs = _cairo_array_index (&font->glyphs_array, 0); - font->glyph_names = _cairo_array_index (&font->glyph_names_array, 0); - font->base.num_glyphs = _cairo_array_num_elements (&font->glyphs_array); - font->subset_index_to_glyphs = calloc (font->base.num_glyphs, sizeof font->subset_index_to_glyphs[0]); - if (unlikely (font->subset_index_to_glyphs == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - backend = font->scaled_font_subset->scaled_font->backend; - if (!backend->index_to_glyph_name) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Find the glyph number corresponding to each glyph in the subset - * and mark it as in use */ - - for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { - unsigned long index; - - status = backend->index_to_glyph_name (font->scaled_font_subset->scaled_font, - font->glyph_names, - font->base.num_glyphs, - font->scaled_font_subset->glyphs[i], - &index); - if (unlikely(status)) - return status; - - cairo_type1_font_subset_use_glyph (font, index); - } - - /* Go through the charstring of each glyph in use, get the glyph - * width and figure out which extra glyphs may be required by the - * seac operator (which may cause font->num_glyphs to increase - * while this loop is executing). Also subset the Subrs. */ - for (j = 0; j < font->num_glyphs; j++) { - glyph = font->subset_index_to_glyphs[j]; - font->build_stack.sp = 0; - font->ps_stack.sp = 0; - status = cairo_type1_font_subset_parse_charstring (font, - glyph, - font->glyphs[glyph].encrypted_charstring, - font->glyphs[glyph].encrypted_charstring_length); - if (unlikely (status)) - return status; - } - - /* Always include the first five subroutines in case the Flex/hint mechanism is - * being used. */ - for (j = 0; j < MIN (font->num_subrs, 5); j++) { - font->subrs[j].used = TRUE; - } - - closefile_token = find_token (dict_end, font->cleartext_end, "closefile"); - if (closefile_token == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* We're ready to start outputting. First write the header, - * i.e. the public part of the font dict.*/ - status = cairo_type1_font_subset_write_header (font, name); - if (unlikely (status)) - return status; - - font->base.header_size = _cairo_output_stream_get_position (font->output); - - /* Start outputting the private dict */ - if (font->subset_subrs) { - /* First output everything up to the start of the Subrs array. */ - status = cairo_type1_font_subset_write_encrypted (font, font->cleartext, - array_start - font->cleartext); - if (unlikely (status)) - return status; - - /* Write out the subr definitions for each of the glyphs in - * the subset. */ - status = cairo_type1_font_for_each_subr (font, - array_start, - font->cleartext_end, - write_used_subrs, - &p); - if (unlikely (status)) - return status; - } else { - p = font->cleartext; - } - - /* If subr subsetting, output everything from end of subrs to - * start of /CharStrings token. If not subr subsetting, output - * everything start of private dict to start of /CharStrings - * token. */ - status = cairo_type1_font_subset_write_encrypted (font, p, charstrings - p); - if (unlikely (status)) - return status; - - /* Write out new charstring count */ - length = snprintf (buffer, sizeof buffer, - "/CharStrings %d", font->num_glyphs); - status = cairo_type1_font_subset_write_encrypted (font, buffer, length); - if (unlikely (status)) - return status; - - /* Write out text between the charstring count and the first - * charstring definition */ - status = cairo_type1_font_subset_write_encrypted (font, glyph_count_end, - dict_start - glyph_count_end); - if (unlikely (status)) - return status; - - /* Write out the charstring definitions for each of the glyphs in - * the subset. */ - status = cairo_type1_font_subset_for_each_glyph (font, - dict_start, - font->cleartext_end, - write_used_glyphs, - &p); - if (unlikely (status)) - return status; - - /* Output what's left between the end of the glyph definitions and - * the end of the private dict to the output. */ - status = cairo_type1_font_subset_write_encrypted (font, p, - closefile_token - p + strlen ("closefile") + 1); - if (unlikely (status)) - return status; - - if (font->hex_encode) - _cairo_output_stream_write (font->output, "\n", 1); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -cairo_type1_font_subset_write_trailer(cairo_type1_font_subset_t *font) -{ - const char *cleartomark_token; - int i; - static const char zeros[65] = - "0000000000000000000000000000000000000000000000000000000000000000\n"; - - - for (i = 0; i < 8; i++) - _cairo_output_stream_write (font->output, zeros, sizeof zeros); - - cleartomark_token = find_token (font->type1_data, font->type1_end, "cleartomark"); - if (cleartomark_token) { - /* Some fonts have conditional save/restore around the entire - * font dict, so we need to retain whatever postscript code - * that may come after 'cleartomark'. */ - - _cairo_output_stream_write (font->output, cleartomark_token, - font->type1_end - cleartomark_token); - if (*(font->type1_end - 1) != '\n') - _cairo_output_stream_printf (font->output, "\n"); - - } else if (!font->eexec_segment_is_ascii) { - /* Fonts embedded in PDF may omit the fixed-content portion - * that includes the 'cleartomark' operator. Type 1 in PDF is - * always binary. */ - - _cairo_output_stream_printf (font->output, "cleartomark\n"); - } else { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* some fonts do not have a newline at the end of the last line */ - _cairo_output_stream_printf (font->output, "\n"); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -type1_font_write (void *closure, const unsigned char *data, unsigned int length) -{ - cairo_type1_font_subset_t *font = closure; - - return _cairo_array_append_multiple (&font->contents, data, length); -} - -static cairo_status_t -cairo_type1_font_subset_write (cairo_type1_font_subset_t *font, - const char *name) -{ - cairo_status_t status; - - status = cairo_type1_font_subset_find_segments (font); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_decrypt_eexec_segment (font); - if (unlikely (status)) - return status; - - /* Determine which glyph definition delimiters to use. */ - if (find_token (font->cleartext, font->cleartext_end, "/-|") != NULL) { - font->rd = "-|"; - font->nd = "|-"; - font->np = "|"; - } else if (find_token (font->cleartext, font->cleartext_end, "/RD") != NULL) { - font->rd = "RD"; - font->nd = "ND"; - font->np = "NP"; - } else { - /* Don't know *what* kind of font this is... */ - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - font->eexec_key = CAIRO_TYPE1_PRIVATE_DICT_KEY; - font->hex_column = 0; - - status = cairo_type1_font_subset_get_bbox (font); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_get_fontname (font); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_write_private_dict (font, name); - if (unlikely (status)) - return status; - - font->base.data_size = _cairo_output_stream_get_position (font->output) - - font->base.header_size; - - status = cairo_type1_font_subset_write_trailer (font); - if (unlikely (status)) - return status; - - font->base.trailer_size = - _cairo_output_stream_get_position (font->output) - - font->base.header_size - font->base.data_size; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -check_fontdata_is_type1 (const unsigned char *data, long length) -{ - /* Test for Type 1 Binary (PFB) */ - if (length > 2 && data[0] == 0x80 && data[1] == 0x01) - return TRUE; - - /* Test for Type 1 1 ASCII (PFA) */ - if (length > 2 && data[0] == '%' && data[1] == '!') - return TRUE; - - return FALSE; -} - -static cairo_status_t -cairo_type1_font_subset_generate (void *abstract_font, - const char *name) - -{ - cairo_type1_font_subset_t *font = abstract_font; - cairo_scaled_font_t *scaled_font; - cairo_status_t status; - unsigned long data_length; - - scaled_font = font->scaled_font_subset->scaled_font; - if (!scaled_font->backend->load_type1_data) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = scaled_font->backend->load_type1_data (scaled_font, 0, NULL, &data_length); - if (status) - return CAIRO_INT_STATUS_UNSUPPORTED; - - font->type1_length = data_length; - font->type1_data = malloc (font->type1_length); - if (unlikely (font->type1_data == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = scaled_font->backend->load_type1_data (scaled_font, 0, - (unsigned char *) font->type1_data, - &data_length); - if (unlikely (status)) - return status; - - if (!check_fontdata_is_type1 ((unsigned char *)font->type1_data, data_length)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_array_grow_by (&font->contents, 4096); - if (unlikely (status)) - return status; - - font->output = _cairo_output_stream_create (type1_font_write, NULL, font); - if (unlikely ((status = font->output->status))) - return status; - - status = cairo_type1_font_subset_write (font, name); - if (unlikely (status)) - return status; - - font->base.data = _cairo_array_index (&font->contents, 0); - - return status; -} - -static cairo_status_t -_cairo_type1_font_subset_fini (cairo_type1_font_subset_t *font) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - unsigned int i; - - /* If the subset generation failed, some of the pointers below may - * be NULL depending on at which point the error occurred. */ - - _cairo_array_fini (&font->contents); - - free (font->type1_data); - for (i = 0; i < _cairo_array_num_elements (&font->glyph_names_array); i++) { - char **s; - - s = _cairo_array_index (&font->glyph_names_array, i); - free (*s); - } - _cairo_array_fini (&font->glyph_names_array); - _cairo_array_fini (&font->glyphs_array); - - free (font->subrs); - - if (font->output != NULL) - status = _cairo_output_stream_destroy (font->output); - - free (font->base.base_font); - - free (font->subset_index_to_glyphs); - - free (font->cleartext); - - return status; -} - -cairo_status_t -_cairo_type1_subset_init (cairo_type1_subset_t *type1_subset, - const char *name, - cairo_scaled_font_subset_t *scaled_font_subset, - cairo_bool_t hex_encode) -{ - cairo_type1_font_subset_t font; - cairo_status_t status; - unsigned long length; - unsigned int i; - char buf[30]; - - /* We need to use a fallback font generated from the synthesized outlines. */ - if (scaled_font_subset->scaled_font->backend->is_synthetic && - scaled_font_subset->scaled_font->backend->is_synthetic (scaled_font_subset->scaled_font)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_type1_font_subset_init (&font, scaled_font_subset, hex_encode); - if (unlikely (status)) - return status; - - status = cairo_type1_font_subset_generate (&font, name); - if (unlikely (status)) - goto fail1; - - if (font.base.base_font) { - type1_subset->base_font = strdup (font.base.base_font); - } else { - snprintf(buf, sizeof (buf), "CairoFont-%u-%u", - scaled_font_subset->font_id, scaled_font_subset->subset_id); - type1_subset->base_font = strdup (buf); - } - if (unlikely (type1_subset->base_font == NULL)) - goto fail1; - - type1_subset->widths = calloc (sizeof (double), font.num_glyphs); - if (unlikely (type1_subset->widths == NULL)) - goto fail2; - for (i = 0; i < font.base.num_glyphs; i++) { - if (font.glyphs[i].subset_index < 0) - continue; - type1_subset->widths[font.glyphs[i].subset_index] = - font.glyphs[i].width; - } - - type1_subset->x_min = font.base.x_min; - type1_subset->y_min = font.base.y_min; - type1_subset->x_max = font.base.x_max; - type1_subset->y_max = font.base.y_max; - type1_subset->ascent = font.base.ascent; - type1_subset->descent = font.base.descent; - - length = font.base.header_size + - font.base.data_size + - font.base.trailer_size; - type1_subset->data = malloc (length); - if (unlikely (type1_subset->data == NULL)) - goto fail3; - - memcpy (type1_subset->data, - _cairo_array_index (&font.contents, 0), length); - - type1_subset->header_length = font.base.header_size; - type1_subset->data_length = font.base.data_size; - type1_subset->trailer_length = font.base.trailer_size; - - return _cairo_type1_font_subset_fini (&font); - - fail3: - free (type1_subset->widths); - fail2: - free (type1_subset->base_font); - fail1: - _cairo_type1_font_subset_fini (&font); - - return status; -} - -void -_cairo_type1_subset_fini (cairo_type1_subset_t *subset) -{ - free (subset->base_font); - free (subset->widths); - free (subset->data); -} - -cairo_bool_t -_cairo_type1_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font) -{ - cairo_status_t status; - unsigned long length; - unsigned char buf[64]; - - if (!scaled_font->backend->load_type1_data) - return FALSE; - - status = scaled_font->backend->load_type1_data (scaled_font, 0, NULL, &length); - if (status) - return FALSE; - - /* We only need a few bytes to test for Type 1 */ - if (length > sizeof (buf)) - length = sizeof (buf); - - status = scaled_font->backend->load_type1_data (scaled_font, 0, buf, &length); - if (status) - return FALSE; - - return check_fontdata_is_type1 (buf, length); -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface-private.h deleted file mode 100644 index 6f40f1c25b4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface-private.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - */ - -#ifndef CAIRO_TYPE3_GLYPH_SURFACE_PRIVATE_H -#define CAIRO_TYPE3_GLYPH_SURFACE_PRIVATE_H - -#include "cairoint.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-surface-private.h" -#include "cairo-surface-clipper-private.h" -#include "cairo-pdf-operators-private.h" - -typedef cairo_int_status_t -(*cairo_type3_glyph_surface_emit_image_t) (cairo_image_surface_t *image, - cairo_output_stream_t *stream); - -typedef struct cairo_type3_glyph_surface { - cairo_surface_t base; - - cairo_scaled_font_t *scaled_font; - cairo_output_stream_t *stream; - cairo_pdf_operators_t pdf_operators; - cairo_matrix_t cairo_to_pdf; - cairo_type3_glyph_surface_emit_image_t emit_image; - - cairo_surface_clipper_t clipper; -} cairo_type3_glyph_surface_t; - -cairo_private cairo_surface_t * -_cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, - cairo_output_stream_t *stream, - cairo_type3_glyph_surface_emit_image_t emit_image, - cairo_scaled_font_subsets_t *font_subsets, - cairo_bool_t ps_output); - -cairo_private void -_cairo_type3_glyph_surface_set_font_subsets_callback (void *abstract_surface, - cairo_pdf_operators_use_font_subset_t use_font_subset, - void *closure); - -cairo_private cairo_status_t -_cairo_type3_glyph_surface_analyze_glyph (void *abstract_surface, - unsigned long glyph_index); - -cairo_private cairo_status_t -_cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, - cairo_output_stream_t *stream, - unsigned long glyph_index, - cairo_box_t *bbox, - double *width); - -#endif /* CAIRO_HAS_FONT_SUBSET */ - -#endif /* CAIRO_TYPE3_GLYPH_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface.c deleted file mode 100644 index c99d461066c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-type3-glyph-surface.c +++ /dev/null @@ -1,568 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Adrian Johnson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Adrian Johnson. - * - * Contributor(s): - * Adrian Johnson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_FONT_SUBSET - -#include "cairo-type3-glyph-surface-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-analysis-surface-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-clipper-private.h" - -static const cairo_surface_backend_t cairo_type3_glyph_surface_backend; - -static cairo_status_t -_cairo_type3_glyph_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_type3_glyph_surface_t *surface = cairo_container_of (clipper, - cairo_type3_glyph_surface_t, - clipper); - - if (path == NULL) { - _cairo_output_stream_printf (surface->stream, "Q q\n"); - return CAIRO_STATUS_SUCCESS; - } - - return _cairo_pdf_operators_clip (&surface->pdf_operators, - path, - fill_rule); -} - -cairo_surface_t * -_cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, - cairo_output_stream_t *stream, - cairo_type3_glyph_surface_emit_image_t emit_image, - cairo_scaled_font_subsets_t *font_subsets, - cairo_bool_t ps) -{ - cairo_type3_glyph_surface_t *surface; - cairo_matrix_t invert_y_axis; - - if (unlikely (stream != NULL && stream->status)) - return _cairo_surface_create_in_error (stream->status); - - surface = malloc (sizeof (cairo_type3_glyph_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &cairo_type3_glyph_surface_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - surface->scaled_font = scaled_font; - surface->stream = stream; - surface->emit_image = emit_image; - - /* Setup the transform from the user-font device space to Type 3 - * font space. The Type 3 font space is defined by the FontMatrix - * entry in the Type 3 dictionary. In the PDF backend this is an - * identity matrix. */ - surface->cairo_to_pdf = scaled_font->scale_inverse; - cairo_matrix_init_scale (&invert_y_axis, 1, -1); - cairo_matrix_multiply (&surface->cairo_to_pdf, &surface->cairo_to_pdf, &invert_y_axis); - - _cairo_pdf_operators_init (&surface->pdf_operators, - surface->stream, - &surface->cairo_to_pdf, - font_subsets, - ps); - - _cairo_surface_clipper_init (&surface->clipper, - _cairo_type3_glyph_surface_clipper_intersect_clip_path); - - return &surface->base; -} - -static cairo_status_t -_cairo_type3_glyph_surface_emit_image (cairo_type3_glyph_surface_t *surface, - cairo_image_surface_t *image, - cairo_matrix_t *image_matrix) -{ - cairo_status_t status; - - /* The only image type supported by Type 3 fonts are 1-bit masks */ - image = _cairo_image_surface_coerce_to_format (image, CAIRO_FORMAT_A1); - status = image->base.status; - if (unlikely (status)) - return status; - - _cairo_output_stream_printf (surface->stream, - "q %f %f %f %f %f %f cm\n", - image_matrix->xx, - image_matrix->xy, - image_matrix->yx, - image_matrix->yy, - image_matrix->x0, - image_matrix->y0); - - status = surface->emit_image (image, surface->stream); - cairo_surface_destroy (&image->base); - - _cairo_output_stream_printf (surface->stream, - "Q\n"); - - return status; -} - -static cairo_status_t -_cairo_type3_glyph_surface_emit_image_pattern (cairo_type3_glyph_surface_t *surface, - cairo_image_surface_t *image, - const cairo_matrix_t *pattern_matrix) -{ - cairo_matrix_t mat, upside_down; - cairo_status_t status; - - if (image->width == 0 || image->height == 0) - return CAIRO_STATUS_SUCCESS; - - mat = *pattern_matrix; - - /* Get the pattern space to user space matrix */ - status = cairo_matrix_invert (&mat); - - /* cairo_pattern_set_matrix ensures the matrix is invertible */ - assert (status == CAIRO_STATUS_SUCCESS); - - /* Make this a pattern space to Type 3 font space matrix */ - cairo_matrix_multiply (&mat, &mat, &surface->cairo_to_pdf); - - /* PDF images are in a 1 unit by 1 unit image space. Turn the 1 by - * 1 image upside down to convert to flip the Y-axis going from - * cairo to PDF. Then scale the image up to the required size. */ - cairo_matrix_scale (&mat, image->width, image->height); - cairo_matrix_init (&upside_down, 1, 0, 0, -1, 0, 1); - cairo_matrix_multiply (&mat, &upside_down, &mat); - - return _cairo_type3_glyph_surface_emit_image (surface, image, &mat); -} - -static cairo_status_t -_cairo_type3_glyph_surface_finish (void *abstract_surface) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - - return _cairo_pdf_operators_fini (&surface->pdf_operators); -} - -static cairo_int_status_t -_cairo_type3_glyph_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - const cairo_surface_pattern_t *pattern; - cairo_image_surface_t *image; - void *image_extra; - cairo_status_t status; - - if (source->type != CAIRO_PATTERN_TYPE_SURFACE) - return CAIRO_INT_STATUS_IMAGE_FALLBACK; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - pattern = (const cairo_surface_pattern_t *) source; - status = _cairo_surface_acquire_source_image (pattern->surface, - &image, &image_extra); - if (unlikely (status)) - goto fail; - - status = _cairo_type3_glyph_surface_emit_image_pattern (surface, - image, - &pattern->base.matrix); - -fail: - _cairo_surface_release_source_image (pattern->surface, image, image_extra); - - return status; -} - -static cairo_int_status_t -_cairo_type3_glyph_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - return _cairo_type3_glyph_surface_paint (abstract_surface, - op, mask, - clip); -} - -static cairo_int_status_t -_cairo_type3_glyph_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - return _cairo_pdf_operators_stroke (&surface->pdf_operators, - path, - style, - ctm, - ctm_inverse); -} - -static cairo_int_status_t -_cairo_type3_glyph_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - return _cairo_pdf_operators_fill (&surface->pdf_operators, - path, - fill_rule); -} - -static cairo_int_status_t -_cairo_type3_glyph_surface_show_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - cairo_int_status_t status; - cairo_scaled_font_t *font; - cairo_matrix_t new_ctm, invert_y_axis; - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) - return status; - - cairo_matrix_init_scale (&invert_y_axis, 1, -1); - cairo_matrix_multiply (&new_ctm, &invert_y_axis, &scaled_font->ctm); - cairo_matrix_multiply (&new_ctm, &surface->cairo_to_pdf, &new_ctm); - font = cairo_scaled_font_create (scaled_font->font_face, - &scaled_font->font_matrix, - &new_ctm, - &scaled_font->options); - if (unlikely (font->status)) - return font->status; - - status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, - NULL, 0, - glyphs, num_glyphs, - NULL, 0, - FALSE, - font); - - cairo_scaled_font_destroy (font); - - return status; -} - -static const cairo_surface_backend_t cairo_type3_glyph_surface_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_TYPE3_GLYPH, - _cairo_type3_glyph_surface_finish, - - _cairo_default_context_create, /* XXX usable through a context? */ - - NULL, /* create similar */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - NULL, /* source */ - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* copy page */ - NULL, /* show page */ - - NULL, /* _cairo_type3_glyph_surface_get_extents */ - NULL, /* _cairo_type3_glyph_surface_get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_type3_glyph_surface_paint, - _cairo_type3_glyph_surface_mask, - _cairo_type3_glyph_surface_stroke, - _cairo_type3_glyph_surface_fill, - NULL, /* fill-stroke */ - _cairo_type3_glyph_surface_show_glyphs, -}; - -static void -_cairo_type3_glyph_surface_set_stream (cairo_type3_glyph_surface_t *surface, - cairo_output_stream_t *stream) -{ - surface->stream = stream; - _cairo_pdf_operators_set_stream (&surface->pdf_operators, stream); -} - -static cairo_status_t -_cairo_type3_glyph_surface_emit_fallback_image (cairo_type3_glyph_surface_t *surface, - unsigned long glyph_index) -{ - cairo_scaled_glyph_t *scaled_glyph; - cairo_status_t status; - cairo_image_surface_t *image; - cairo_matrix_t mat; - double x, y; - - status = _cairo_scaled_glyph_lookup (surface->scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS | - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - if (unlikely (status)) - return status; - - image = scaled_glyph->surface; - if (image->width == 0 || image->height == 0) - return CAIRO_STATUS_SUCCESS; - - x = _cairo_fixed_to_double (scaled_glyph->bbox.p1.x); - y = _cairo_fixed_to_double (scaled_glyph->bbox.p2.y); - mat.xx = image->width; - mat.xy = 0; - mat.yx = 0; - mat.yy = image->height; - mat.x0 = x; - mat.y0 = y; - cairo_matrix_multiply (&mat, &mat, &surface->scaled_font->scale_inverse); - mat.y0 *= -1; - - return _cairo_type3_glyph_surface_emit_image (surface, image, &mat); -} - -void -_cairo_type3_glyph_surface_set_font_subsets_callback (void *abstract_surface, - cairo_pdf_operators_use_font_subset_t use_font_subset, - void *closure) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - - if (unlikely (surface->base.status)) - return; - - _cairo_pdf_operators_set_font_subsets_callback (&surface->pdf_operators, - use_font_subset, - closure); -} - -cairo_status_t -_cairo_type3_glyph_surface_analyze_glyph (void *abstract_surface, - unsigned long glyph_index) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - cairo_scaled_glyph_t *scaled_glyph; - cairo_int_status_t status, status2; - cairo_output_stream_t *null_stream; - - if (unlikely (surface->base.status)) - return surface->base.status; - - null_stream = _cairo_null_stream_create (); - if (unlikely (null_stream->status)) - return null_stream->status; - - _cairo_type3_glyph_surface_set_stream (surface, null_stream); - - _cairo_scaled_font_freeze_cache (surface->scaled_font); - status = _cairo_scaled_glyph_lookup (surface->scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE, - &scaled_glyph); - - if (_cairo_int_status_is_error (status)) - goto cleanup; - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = CAIRO_INT_STATUS_SUCCESS; - goto cleanup; - } - - status = _cairo_recording_surface_replay (scaled_glyph->recording_surface, - &surface->base); - if (unlikely (status)) - goto cleanup; - - status = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) - status = CAIRO_INT_STATUS_SUCCESS; - -cleanup: - _cairo_scaled_font_thaw_cache (surface->scaled_font); - - status2 = _cairo_output_stream_destroy (null_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - - return status; -} - -cairo_status_t -_cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, - cairo_output_stream_t *stream, - unsigned long glyph_index, - cairo_box_t *bbox, - double *width) -{ - cairo_type3_glyph_surface_t *surface = abstract_surface; - cairo_scaled_glyph_t *scaled_glyph; - cairo_int_status_t status, status2; - double x_advance, y_advance; - cairo_matrix_t font_matrix_inverse; - - if (unlikely (surface->base.status)) - return surface->base.status; - - _cairo_type3_glyph_surface_set_stream (surface, stream); - - _cairo_scaled_font_freeze_cache (surface->scaled_font); - status = _cairo_scaled_glyph_lookup (surface->scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS | - CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE, - &scaled_glyph); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = _cairo_scaled_glyph_lookup (surface->scaled_font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &scaled_glyph); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = CAIRO_INT_STATUS_IMAGE_FALLBACK; - } - if (_cairo_int_status_is_error (status)) { - _cairo_scaled_font_thaw_cache (surface->scaled_font); - return status; - } - - x_advance = scaled_glyph->metrics.x_advance; - y_advance = scaled_glyph->metrics.y_advance; - font_matrix_inverse = surface->scaled_font->font_matrix; - status2 = cairo_matrix_invert (&font_matrix_inverse); - - /* The invertability of font_matrix is tested in - * pdf_operators_show_glyphs before any glyphs are mapped to the - * subset. */ - assert (status2 == CAIRO_INT_STATUS_SUCCESS); - - cairo_matrix_transform_distance (&font_matrix_inverse, &x_advance, &y_advance); - *width = x_advance; - - *bbox = scaled_glyph->bbox; - _cairo_matrix_transform_bounding_box_fixed (&surface->scaled_font->scale_inverse, - bbox, NULL); - - _cairo_output_stream_printf (surface->stream, - "%f 0 %f %f %f %f d1\n", - x_advance, - _cairo_fixed_to_double (bbox->p1.x), - - _cairo_fixed_to_double (bbox->p2.y), - _cairo_fixed_to_double (bbox->p2.x), - - _cairo_fixed_to_double (bbox->p1.y)); - - if (status == CAIRO_INT_STATUS_SUCCESS) { - cairo_output_stream_t *mem_stream; - - mem_stream = _cairo_memory_stream_create (); - status = mem_stream->status; - if (unlikely (status)) - goto FAIL; - - _cairo_type3_glyph_surface_set_stream (surface, mem_stream); - - _cairo_output_stream_printf (surface->stream, "q\n"); - status = _cairo_recording_surface_replay (scaled_glyph->recording_surface, - &surface->base); - - status2 = _cairo_pdf_operators_flush (&surface->pdf_operators); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - - _cairo_output_stream_printf (surface->stream, "Q\n"); - - _cairo_type3_glyph_surface_set_stream (surface, stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - _cairo_memory_stream_copy (mem_stream, stream); - - status2 = _cairo_output_stream_destroy (mem_stream); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = status2; - } - - if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) - status = _cairo_type3_glyph_surface_emit_fallback_image (surface, glyph_index); - - FAIL: - _cairo_scaled_font_thaw_cache (surface->scaled_font); - - return status; -} - -#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-types-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-types-private.h deleted file mode 100644 index 3d15d968e4b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-types-private.h +++ /dev/null @@ -1,429 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_TYPES_PRIVATE_H -#define CAIRO_TYPES_PRIVATE_H - -#include "cairo.h" -#include "cairo-fixed-type-private.h" -#include "cairo-list-private.h" -#include "cairo-reference-count-private.h" - -CAIRO_BEGIN_DECLS - -/** - * SECTION:cairo-types - * @Title: Types - * @Short_Description: Generic data types - * - * This section lists generic data types used in the cairo API. - **/ - -typedef struct _cairo_array cairo_array_t; -typedef struct _cairo_backend cairo_backend_t; -typedef struct _cairo_boxes_t cairo_boxes_t; -typedef struct _cairo_cache cairo_cache_t; -typedef struct _cairo_composite_rectangles cairo_composite_rectangles_t; -typedef struct _cairo_clip cairo_clip_t; -typedef struct _cairo_clip_path cairo_clip_path_t; -typedef struct _cairo_color cairo_color_t; -typedef struct _cairo_color_stop cairo_color_stop_t; -typedef struct _cairo_contour cairo_contour_t; -typedef struct _cairo_contour_chain cairo_contour_chain_t; -typedef struct _cairo_contour_iter cairo_contour_iter_t; -typedef struct _cairo_damage cairo_damage_t; -typedef struct _cairo_device_backend cairo_device_backend_t; -typedef struct _cairo_font_face_backend cairo_font_face_backend_t; -typedef struct _cairo_gstate cairo_gstate_t; -typedef struct _cairo_gstate_backend cairo_gstate_backend_t; -typedef struct _cairo_glyph_text_info cairo_glyph_text_info_t; -typedef struct _cairo_hash_entry cairo_hash_entry_t; -typedef struct _cairo_hash_table cairo_hash_table_t; -typedef struct _cairo_image_surface cairo_image_surface_t; -typedef struct _cairo_mime_data cairo_mime_data_t; -typedef struct _cairo_observer cairo_observer_t; -typedef struct _cairo_output_stream cairo_output_stream_t; -typedef struct _cairo_paginated_surface_backend cairo_paginated_surface_backend_t; -typedef struct _cairo_path_fixed cairo_path_fixed_t; -typedef struct _cairo_rectangle_int16 cairo_glyph_size_t; -typedef struct _cairo_scaled_font_subsets cairo_scaled_font_subsets_t; -typedef struct _cairo_solid_pattern cairo_solid_pattern_t; -typedef struct _cairo_surface_attributes cairo_surface_attributes_t; -typedef struct _cairo_surface_backend cairo_surface_backend_t; -typedef struct _cairo_surface_observer cairo_surface_observer_t; -typedef struct _cairo_surface_snapshot cairo_surface_snapshot_t; -typedef struct _cairo_surface_subsurface cairo_surface_subsurface_t; -typedef struct _cairo_surface_wrapper cairo_surface_wrapper_t; -typedef struct _cairo_traps cairo_traps_t; -typedef struct _cairo_tristrip cairo_tristrip_t; -typedef struct _cairo_unscaled_font_backend cairo_unscaled_font_backend_t; -typedef struct _cairo_xlib_screen_info cairo_xlib_screen_info_t; - -typedef cairo_array_t cairo_user_data_array_t; - -typedef struct _cairo_scaled_font_private cairo_scaled_font_private_t; -typedef struct _cairo_scaled_font_backend cairo_scaled_font_backend_t; -typedef struct _cairo_scaled_glyph cairo_scaled_glyph_t; -typedef struct _cairo_scaled_glyph_private cairo_scaled_glyph_private_t; - -typedef struct cairo_compositor cairo_compositor_t; -typedef struct cairo_fallback_compositor cairo_fallback_compositor_t; -typedef struct cairo_mask_compositor cairo_mask_compositor_t; -typedef struct cairo_traps_compositor cairo_traps_compositor_t; -typedef struct cairo_spans_compositor cairo_spans_compositor_t; - -struct _cairo_observer { - cairo_list_t link; - void (*callback) (cairo_observer_t *self, void *arg); -}; - -/** - * _cairo_hash_entry: - * - * A #cairo_hash_entry_t contains both a key and a value for - * #cairo_hash_table_t. User-derived types for #cairo_hash_entry_t must - * be type-compatible with this structure (eg. they must have an - * unsigned long as the first parameter. The easiest way to get this - * is to use: - * - * typedef _my_entry { - * cairo_hash_entry_t base; - * ... Remainder of key and value fields here .. - * } my_entry_t; - * - * which then allows a pointer to my_entry_t to be passed to any of - * the #cairo_hash_table_t functions as follows without requiring a cast: - * - * _cairo_hash_table_insert (hash_table, &my_entry->base); - * - * IMPORTANT: The caller is responsible for initializing - * my_entry->base.hash with a hash code derived from the key. The - * essential property of the hash code is that keys_equal must never - * return %TRUE for two keys that have different hashes. The best hash - * code will reduce the frequency of two keys with the same code for - * which keys_equal returns %FALSE. - * - * Which parts of the entry make up the "key" and which part make up - * the value are entirely up to the caller, (as determined by the - * computation going into base.hash as well as the keys_equal - * function). A few of the #cairo_hash_table_t functions accept an entry - * which will be used exclusively as a "key", (indicated by a - * parameter name of key). In these cases, the value-related fields of - * the entry need not be initialized if so desired. - **/ -struct _cairo_hash_entry { - unsigned long hash; -}; - -struct _cairo_array { - unsigned int size; - unsigned int num_elements; - unsigned int element_size; - char *elements; -}; - -/** - * _cairo_lcd_filter: - * @CAIRO_LCD_FILTER_DEFAULT: Use the default LCD filter for - * font backend and target device - * @CAIRO_LCD_FILTER_NONE: Do not perform LCD filtering - * @CAIRO_LCD_FILTER_INTRA_PIXEL: Intra-pixel filter - * @CAIRO_LCD_FILTER_FIR3: FIR filter with a 3x3 kernel - * @CAIRO_LCD_FILTER_FIR5: FIR filter with a 5x5 kernel - * - * The LCD filter specifies the low-pass filter applied to LCD-optimized - * bitmaps generated with an antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL. - * - * Note: This API was temporarily made available in the public - * interface during the 1.7.x development series, but was made private - * before 1.8. - **/ -typedef enum _cairo_lcd_filter { - CAIRO_LCD_FILTER_DEFAULT, - CAIRO_LCD_FILTER_NONE, - CAIRO_LCD_FILTER_INTRA_PIXEL, - CAIRO_LCD_FILTER_FIR3, - CAIRO_LCD_FILTER_FIR5 -} cairo_lcd_filter_t; - -typedef enum _cairo_round_glyph_positions { - CAIRO_ROUND_GLYPH_POS_DEFAULT, - CAIRO_ROUND_GLYPH_POS_ON, - CAIRO_ROUND_GLYPH_POS_OFF -} cairo_round_glyph_positions_t; - -struct _cairo_font_options { - cairo_antialias_t antialias; - cairo_subpixel_order_t subpixel_order; - cairo_lcd_filter_t lcd_filter; - cairo_hint_style_t hint_style; - cairo_hint_metrics_t hint_metrics; - cairo_round_glyph_positions_t round_glyph_positions; -}; - -struct _cairo_glyph_text_info { - const char *utf8; - int utf8_len; - - const cairo_text_cluster_t *clusters; - int num_clusters; - cairo_text_cluster_flags_t cluster_flags; -}; - - -/* XXX: Right now, the _cairo_color structure puts unpremultiplied - color in the doubles and premultiplied color in the shorts. Yes, - this is crazy insane, (but at least we don't export this - madness). I'm still working on a cleaner API, but in the meantime, - at least this does prevent precision loss in color when changing - alpha. */ -struct _cairo_color { - double red; - double green; - double blue; - double alpha; - - unsigned short red_short; - unsigned short green_short; - unsigned short blue_short; - unsigned short alpha_short; -}; - -struct _cairo_color_stop { - /* unpremultiplied */ - double red; - double green; - double blue; - double alpha; - - /* unpremultipled, for convenience */ - uint16_t red_short; - uint16_t green_short; - uint16_t blue_short; - uint16_t alpha_short; -}; - -typedef enum _cairo_paginated_mode { - CAIRO_PAGINATED_MODE_ANALYZE, /* analyze page regions */ - CAIRO_PAGINATED_MODE_RENDER, /* render page contents */ - CAIRO_PAGINATED_MODE_FALLBACK /* paint fallback images */ -} cairo_paginated_mode_t; - -typedef enum _cairo_internal_surface_type { - CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT = 0x1000, - CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, - CAIRO_INTERNAL_SURFACE_TYPE_ANALYSIS, - CAIRO_INTERNAL_SURFACE_TYPE_OBSERVER, - CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, - CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED, - CAIRO_INTERNAL_SURFACE_TYPE_TEST_WRAPPING, - CAIRO_INTERNAL_SURFACE_TYPE_NULL, - CAIRO_INTERNAL_SURFACE_TYPE_TYPE3_GLYPH -} cairo_internal_surface_type_t; - -typedef enum _cairo_internal_device_type { - CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER = 0x1000, -} cairo_device_surface_type_t; - -#define CAIRO_HAS_TEST_PAGINATED_SURFACE 1 - -typedef struct _cairo_slope { - cairo_fixed_t dx; - cairo_fixed_t dy; -} cairo_slope_t, cairo_distance_t; - -typedef struct _cairo_point_double { - double x; - double y; -} cairo_point_double_t; - -typedef struct _cairo_circle_double { - cairo_point_double_t center; - double radius; -} cairo_circle_double_t; - -typedef struct _cairo_distance_double { - double dx; - double dy; -} cairo_distance_double_t; - -typedef struct _cairo_box_double { - cairo_point_double_t p1; - cairo_point_double_t p2; -} cairo_box_double_t; - -typedef struct _cairo_line { - cairo_point_t p1; - cairo_point_t p2; -} cairo_line_t, cairo_box_t; - -typedef struct _cairo_trapezoid { - cairo_fixed_t top, bottom; - cairo_line_t left, right; -} cairo_trapezoid_t; - -typedef struct _cairo_point_int { - int x, y; -} cairo_point_int_t; - -#define CAIRO_RECT_INT_MIN (INT_MIN >> CAIRO_FIXED_FRAC_BITS) -#define CAIRO_RECT_INT_MAX (INT_MAX >> CAIRO_FIXED_FRAC_BITS) - -typedef enum _cairo_direction { - CAIRO_DIRECTION_FORWARD, - CAIRO_DIRECTION_REVERSE -} cairo_direction_t; - -typedef struct _cairo_edge { - cairo_line_t line; - int top, bottom; - int dir; -} cairo_edge_t; - -typedef struct _cairo_polygon { - cairo_status_t status; - - cairo_box_t extents; - cairo_box_t limit; - const cairo_box_t *limits; - int num_limits; - - int num_edges; - int edges_size; - cairo_edge_t *edges; - cairo_edge_t edges_embedded[32]; -} cairo_polygon_t; - -typedef cairo_warn cairo_status_t -(*cairo_spline_add_point_func_t) (void *closure, - const cairo_point_t *point, - const cairo_slope_t *tangent); - -typedef struct _cairo_spline_knots { - cairo_point_t a, b, c, d; -} cairo_spline_knots_t; - -typedef struct _cairo_spline { - cairo_spline_add_point_func_t add_point_func; - void *closure; - - cairo_spline_knots_t knots; - - cairo_slope_t initial_slope; - cairo_slope_t final_slope; - - cairo_bool_t has_point; - cairo_point_t last_point; -} cairo_spline_t; - -typedef struct _cairo_pen_vertex { - cairo_point_t point; - - cairo_slope_t slope_ccw; - cairo_slope_t slope_cw; -} cairo_pen_vertex_t; - -typedef struct _cairo_pen { - double radius; - double tolerance; - - int num_vertices; - cairo_pen_vertex_t *vertices; - cairo_pen_vertex_t vertices_embedded[32]; -} cairo_pen_t; - -typedef struct _cairo_stroke_style { - double line_width; - cairo_line_cap_t line_cap; - cairo_line_join_t line_join; - double miter_limit; - double *dash; - unsigned int num_dashes; - double dash_offset; -} cairo_stroke_style_t; - -typedef struct _cairo_format_masks { - int bpp; - unsigned long alpha_mask; - unsigned long red_mask; - unsigned long green_mask; - unsigned long blue_mask; -} cairo_format_masks_t; - -typedef enum { - CAIRO_STOCK_WHITE, - CAIRO_STOCK_BLACK, - CAIRO_STOCK_TRANSPARENT, - CAIRO_STOCK_NUM_COLORS, -} cairo_stock_t; - -typedef enum _cairo_image_transparency { - CAIRO_IMAGE_IS_OPAQUE, - CAIRO_IMAGE_HAS_BILEVEL_ALPHA, - CAIRO_IMAGE_HAS_ALPHA, - CAIRO_IMAGE_UNKNOWN -} cairo_image_transparency_t; - -typedef enum _cairo_image_color { - CAIRO_IMAGE_IS_COLOR, - CAIRO_IMAGE_IS_GRAYSCALE, - CAIRO_IMAGE_IS_MONOCHROME, - CAIRO_IMAGE_UNKNOWN_COLOR -} cairo_image_color_t; - - -struct _cairo_mime_data { - cairo_reference_count_t ref_count; - unsigned char *data; - unsigned long length; - cairo_destroy_func_t destroy; - void *closure; -}; - -/* - * A #cairo_unscaled_font_t is just an opaque handle we use in the - * glyph cache. - */ -typedef struct _cairo_unscaled_font { - cairo_hash_entry_t hash_entry; - cairo_reference_count_t ref_count; - const cairo_unscaled_font_backend_t *backend; -} cairo_unscaled_font_t; -CAIRO_END_DECLS - -#endif /* CAIRO_TYPES_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-unicode.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-unicode.c deleted file mode 100644 index 88de39516b6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-unicode.c +++ /dev/null @@ -1,422 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * The code in this file is derived from GLib's gutf8.c and - * ultimately from libunicode. It is relicensed under the - * dual LGPL/MPL with permission of the original authors. - * - * Copyright © 1999 Tom Tromey - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Tom Tromey. - * and Red Hat, Inc. - * - * Contributor(s): - * Owen Taylor - */ - -#include "cairoint.h" -#include "cairo-error-private.h" - -#define UTF8_COMPUTE(Char, Mask, Len) \ - if (Char < 128) \ - { \ - Len = 1; \ - Mask = 0x7f; \ - } \ - else if ((Char & 0xe0) == 0xc0) \ - { \ - Len = 2; \ - Mask = 0x1f; \ - } \ - else if ((Char & 0xf0) == 0xe0) \ - { \ - Len = 3; \ - Mask = 0x0f; \ - } \ - else if ((Char & 0xf8) == 0xf0) \ - { \ - Len = 4; \ - Mask = 0x07; \ - } \ - else if ((Char & 0xfc) == 0xf8) \ - { \ - Len = 5; \ - Mask = 0x03; \ - } \ - else if ((Char & 0xfe) == 0xfc) \ - { \ - Len = 6; \ - Mask = 0x01; \ - } \ - else \ - Len = -1; - -#define UTF8_LENGTH(Char) \ - ((Char) < 0x80 ? 1 : \ - ((Char) < 0x800 ? 2 : \ - ((Char) < 0x10000 ? 3 : \ - ((Char) < 0x200000 ? 4 : \ - ((Char) < 0x4000000 ? 5 : 6))))) - -#define UTF8_GET(Result, Chars, Count, Mask, Len) \ - (Result) = (Chars)[0] & (Mask); \ - for ((Count) = 1; (Count) < (Len); ++(Count)) \ - { \ - if (((Chars)[(Count)] & 0xc0) != 0x80) \ - { \ - (Result) = -1; \ - break; \ - } \ - (Result) <<= 6; \ - (Result) |= ((Chars)[(Count)] & 0x3f); \ - } - -#define UNICODE_VALID(Char) \ - ((Char) < 0x110000 && \ - (((Char) & 0xFFFFF800) != 0xD800) && \ - ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \ - ((Char) & 0xFFFE) != 0xFFFE) - -static const char utf8_skip_data[256] = { - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1 -}; - -#define UTF8_NEXT_CHAR(p) ((p) + utf8_skip_data[*(unsigned char *)(p)]) - -/* Converts a sequence of bytes encoded as UTF-8 to a Unicode character. - * If @p does not point to a valid UTF-8 encoded character, results are - * undefined. - **/ -static uint32_t -_utf8_get_char (const unsigned char *p) -{ - int i, mask = 0, len; - uint32_t result; - unsigned char c = (unsigned char) *p; - - UTF8_COMPUTE (c, mask, len); - if (len == -1) - return (uint32_t)-1; - UTF8_GET (result, p, i, mask, len); - - return result; -} - -/* Like _utf8_get_char, but take a maximum length - * and return (uint32_t)-2 on incomplete trailing character - */ -static uint32_t -_utf8_get_char_extended (const unsigned char *p, - long max_len) -{ - int i, len; - uint32_t wc = (unsigned char) *p; - - if (wc < 0x80) { - return wc; - } else if (wc < 0xc0) { - return (uint32_t)-1; - } else if (wc < 0xe0) { - len = 2; - wc &= 0x1f; - } else if (wc < 0xf0) { - len = 3; - wc &= 0x0f; - } else if (wc < 0xf8) { - len = 4; - wc &= 0x07; - } else if (wc < 0xfc) { - len = 5; - wc &= 0x03; - } else if (wc < 0xfe) { - len = 6; - wc &= 0x01; - } else { - return (uint32_t)-1; - } - - if (max_len >= 0 && len > max_len) { - for (i = 1; i < max_len; i++) { - if ((((unsigned char *)p)[i] & 0xc0) != 0x80) - return (uint32_t)-1; - } - return (uint32_t)-2; - } - - for (i = 1; i < len; ++i) { - uint32_t ch = ((unsigned char *)p)[i]; - - if ((ch & 0xc0) != 0x80) { - if (ch) - return (uint32_t)-1; - else - return (uint32_t)-2; - } - - wc <<= 6; - wc |= (ch & 0x3f); - } - - if (UTF8_LENGTH(wc) != len) - return (uint32_t)-1; - - return wc; -} - -/** - * _cairo_utf8_get_char_validated: - * @p: a UTF-8 string - * @unicode: location to store one Unicode character - * - * Decodes the first character of a valid UTF-8 string, and returns - * the number of bytes consumed. - * - * Note that the string should be valid. Do not use this without - * validating the string first. - * - * Returns: the number of bytes forming the character returned. - **/ -int -_cairo_utf8_get_char_validated (const char *p, - uint32_t *unicode) -{ - int i, mask = 0, len; - uint32_t result; - unsigned char c = (unsigned char) *p; - - UTF8_COMPUTE (c, mask, len); - if (len == -1) { - if (unicode) - *unicode = (uint32_t)-1; - return 1; - } - UTF8_GET (result, p, i, mask, len); - - if (unicode) - *unicode = result; - return len; -} - -/** - * _cairo_utf8_to_ucs4: - * @str: an UTF-8 string - * @len: length of @str in bytes, or -1 if it is nul-terminated. - * If @len is supplied and the string has an embedded nul - * byte, only the portion before the nul byte is converted. - * @result: location to store a pointer to a newly allocated UTF-32 - * string (always native endian), or %NULL. Free with free(). A 0 - * word will be written after the last character. - * @items_written: location to store number of 32-bit words - * written. (Not including the trailing 0) - * - * Converts a UTF-8 string to UCS-4. UCS-4 is an encoding of Unicode - * with 1 32-bit word per character. The string is validated to - * consist entirely of valid Unicode characters. - * - * Return value: %CAIRO_STATUS_SUCCESS if the entire string was - * successfully converted. %CAIRO_STATUS_INVALID_STRING if an - * invalid sequence was found. - **/ -cairo_status_t -_cairo_utf8_to_ucs4 (const char *str, - int len, - uint32_t **result, - int *items_written) -{ - uint32_t *str32 = NULL; - int n_chars, i; - const unsigned char *in; - const unsigned char * const ustr = (const unsigned char *) str; - - in = ustr; - n_chars = 0; - while ((len < 0 || ustr + len - in > 0) && *in) - { - uint32_t wc = _utf8_get_char_extended (in, ustr + len - in); - if (wc & 0x80000000 || !UNICODE_VALID (wc)) - return _cairo_error (CAIRO_STATUS_INVALID_STRING); - - n_chars++; - if (n_chars == INT_MAX) - return _cairo_error (CAIRO_STATUS_INVALID_STRING); - - in = UTF8_NEXT_CHAR (in); - } - - if (result) { - str32 = _cairo_malloc_ab (n_chars + 1, sizeof (uint32_t)); - if (!str32) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - in = ustr; - for (i=0; i < n_chars; i++) { - str32[i] = _utf8_get_char (in); - in = UTF8_NEXT_CHAR (in); - } - str32[i] = 0; - - *result = str32; - } - - if (items_written) - *items_written = n_chars; - - return CAIRO_STATUS_SUCCESS; -} - -/** - * _cairo_ucs4_to_utf8: - * @unicode: a UCS-4 character - * @utf8: buffer to write utf8 string into. Must have at least 4 bytes - * space available. Or %NULL. - * - * This space left intentionally blank. - * - * Return value: Number of bytes in the utf8 string or 0 if an invalid - * unicode character - **/ -int -_cairo_ucs4_to_utf8 (uint32_t unicode, - char *utf8) -{ - int bytes; - char *p; - - if (unicode < 0x80) { - if (utf8) - *utf8 = unicode; - return 1; - } else if (unicode < 0x800) { - bytes = 2; - } else if (unicode < 0x10000) { - bytes = 3; - } else if (unicode < 0x200000) { - bytes = 4; - } else { - return 0; - } - - if (!utf8) - return bytes; - - p = utf8 + bytes; - while (p > utf8) { - *--p = 0x80 | (unicode & 0x3f); - unicode >>= 6; - } - *p |= 0xf0 << (4 - bytes); - - return bytes; -} - -#if CAIRO_HAS_UTF8_TO_UTF16 -/** - * _cairo_utf8_to_utf16: - * @str: an UTF-8 string - * @len: length of @str in bytes, or -1 if it is nul-terminated. - * If @len is supplied and the string has an embedded nul - * byte, only the portion before the nul byte is converted. - * @result: location to store a pointer to a newly allocated UTF-16 - * string (always native endian). Free with free(). A 0 - * word will be written after the last character. - * @items_written: location to store number of 16-bit words - * written. (Not including the trailing 0) - * - * Converts a UTF-8 string to UTF-16. UTF-16 is an encoding of Unicode - * where characters are represented either as a single 16-bit word, or - * as a pair of 16-bit "surrogates". The string is validated to - * consist entirely of valid Unicode characters. - * - * Return value: %CAIRO_STATUS_SUCCESS if the entire string was - * successfully converted. %CAIRO_STATUS_INVALID_STRING if an - * an invalid sequence was found. - **/ -cairo_status_t -_cairo_utf8_to_utf16 (const char *str, - int len, - uint16_t **result, - int *items_written) -{ - uint16_t *str16 = NULL; - int n16, i; - const unsigned char *in; - const unsigned char * const ustr = (const unsigned char *) str; - - in = ustr; - n16 = 0; - while ((len < 0 || ustr + len - in > 0) && *in) { - uint32_t wc = _utf8_get_char_extended (in, ustr + len - in); - if (wc & 0x80000000 || !UNICODE_VALID (wc)) - return _cairo_error (CAIRO_STATUS_INVALID_STRING); - - if (wc < 0x10000) - n16 += 1; - else - n16 += 2; - - if (n16 == INT_MAX - 1 || n16 == INT_MAX) - return _cairo_error (CAIRO_STATUS_INVALID_STRING); - - in = UTF8_NEXT_CHAR (in); - } - - str16 = _cairo_malloc_ab (n16 + 1, sizeof (uint16_t)); - if (!str16) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - in = ustr; - for (i = 0; i < n16;) { - uint32_t wc = _utf8_get_char (in); - - if (wc < 0x10000) { - str16[i++] = wc; - } else { - str16[i++] = (wc - 0x10000) / 0x400 + 0xd800; - str16[i++] = (wc - 0x10000) % 0x400 + 0xdc00; - } - - in = UTF8_NEXT_CHAR (in); - } - - str16[i] = 0; - - *result = str16; - if (items_written) - *items_written = n16; - - return CAIRO_STATUS_SUCCESS; -} -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-uninstalled.pc.in b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-uninstalled.pc.in deleted file mode 100644 index 9dc3231ae45..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-uninstalled.pc.in +++ /dev/null @@ -1,8 +0,0 @@ -Name: cairo -Description: Multi-platform 2D graphics library -Version: @VERSION@ - -@PKGCONFIG_REQUIRES@: @CAIRO_REQUIRES@ -Libs: ${pc_top_builddir}/${pcfiledir}/src/libcairo.la -Libs.private: @CAIRO_NONPKGCONFIG_LIBS@ -Cflags: -I${pc_top_builddir}/${pcfiledir}/@srcdir@/src diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font-private.h deleted file mode 100644 index d54ef78b44e..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font-private.h +++ /dev/null @@ -1,46 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006, 2008 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Behdad Esfahbod - */ - -#ifndef CAIRO_USER_FONT_PRIVATE_H -#define CAIRO_USER_FONT_PRIVATE_H - -#include "cairo.h" -#include "cairo-compiler-private.h" - -cairo_private cairo_bool_t -_cairo_font_face_is_user (cairo_font_face_t *font_face); - -#endif /* CAIRO_USER_FONT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font.c deleted file mode 100644 index 6d2de2097d5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-user-font.c +++ /dev/null @@ -1,831 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2006, 2008 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Kristian Høgsberg - * Behdad Esfahbod - */ - -#include "cairoint.h" -#include "cairo-user-font-private.h" -#include "cairo-recording-surface-private.h" -#include "cairo-analysis-surface-private.h" -#include "cairo-error-private.h" - -/** - * SECTION:cairo-user-fonts - * @Title:User Fonts - * @Short_Description: Font support with font data provided by the user - * - * The user-font feature allows the cairo user to provide drawings for glyphs - * in a font. This is most useful in implementing fonts in non-standard - * formats, like SVG fonts and Flash fonts, but can also be used by games and - * other application to draw "funky" fonts. - **/ - -/** - * CAIRO_HAS_USER_FONT: - * - * Defined if the user font backend is available. - * This macro can be used to conditionally compile backend-specific code. - * The user font backend is always built in versions of cairo that support - * this feature (1.8 and later). - * - * Since: 1.8 - **/ - -typedef struct _cairo_user_scaled_font_methods { - cairo_user_scaled_font_init_func_t init; - cairo_user_scaled_font_render_glyph_func_t render_glyph; - cairo_user_scaled_font_unicode_to_glyph_func_t unicode_to_glyph; - cairo_user_scaled_font_text_to_glyphs_func_t text_to_glyphs; -} cairo_user_scaled_font_methods_t; - -typedef struct _cairo_user_font_face { - cairo_font_face_t base; - - /* Set to true after first scaled font is created. At that point, - * the scaled_font_methods cannot change anymore. */ - cairo_bool_t immutable; - - cairo_user_scaled_font_methods_t scaled_font_methods; -} cairo_user_font_face_t; - -typedef struct _cairo_user_scaled_font { - cairo_scaled_font_t base; - - cairo_text_extents_t default_glyph_extents; - - /* space to compute extents in, and factors to convert back to user space */ - cairo_matrix_t extent_scale; - double extent_x_scale; - double extent_y_scale; - - /* multiplier for metrics hinting */ - double snap_x_scale; - double snap_y_scale; - -} cairo_user_scaled_font_t; - -/* #cairo_user_scaled_font_t */ - -static cairo_surface_t * -_cairo_user_scaled_font_create_recording_surface (const cairo_user_scaled_font_t *scaled_font) -{ - cairo_content_t content; - - content = scaled_font->base.options.antialias == CAIRO_ANTIALIAS_SUBPIXEL ? - CAIRO_CONTENT_COLOR_ALPHA : - CAIRO_CONTENT_ALPHA; - - return cairo_recording_surface_create (content, NULL); -} - - -static cairo_t * -_cairo_user_scaled_font_create_recording_context (const cairo_user_scaled_font_t *scaled_font, - cairo_surface_t *recording_surface) -{ - cairo_t *cr; - - cr = cairo_create (recording_surface); - - if (!_cairo_matrix_is_scale_0 (&scaled_font->base.scale)) { - cairo_matrix_t scale; - scale = scaled_font->base.scale; - scale.x0 = scale.y0 = 0.; - cairo_set_matrix (cr, &scale); - } - - cairo_set_font_size (cr, 1.0); - cairo_set_font_options (cr, &scaled_font->base.options); - cairo_set_source_rgb (cr, 1., 1., 1.); - - return cr; -} - -static cairo_int_status_t -_cairo_user_scaled_glyph_init (void *abstract_font, - cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_glyph_info_t info) -{ - cairo_int_status_t status = CAIRO_STATUS_SUCCESS; - cairo_user_scaled_font_t *scaled_font = abstract_font; - cairo_surface_t *recording_surface = scaled_glyph->recording_surface; - - if (!scaled_glyph->recording_surface) { - cairo_user_font_face_t *face = - (cairo_user_font_face_t *) scaled_font->base.font_face; - cairo_text_extents_t extents = scaled_font->default_glyph_extents; - cairo_t *cr; - - if (!face->scaled_font_methods.render_glyph) - return CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED; - - recording_surface = _cairo_user_scaled_font_create_recording_surface (scaled_font); - - /* special case for 0 rank matrix (as in _cairo_scaled_font_init): empty surface */ - if (!_cairo_matrix_is_scale_0 (&scaled_font->base.scale)) { - cr = _cairo_user_scaled_font_create_recording_context (scaled_font, recording_surface); - status = face->scaled_font_methods.render_glyph ((cairo_scaled_font_t *)scaled_font, - _cairo_scaled_glyph_index(scaled_glyph), - cr, &extents); - if (status == CAIRO_INT_STATUS_SUCCESS) - status = cairo_status (cr); - - cairo_destroy (cr); - - if (unlikely (status)) { - cairo_surface_destroy (recording_surface); - return status; - } - } - - _cairo_scaled_glyph_set_recording_surface (scaled_glyph, - &scaled_font->base, - recording_surface); - - - /* set metrics */ - - if (extents.width == 0.) { - cairo_box_t bbox; - double x1, y1, x2, y2; - double x_scale, y_scale; - - /* Compute extents.x/y/width/height from recording_surface, - * in font space. - */ - status = _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface, - &bbox, - &scaled_font->extent_scale); - if (unlikely (status)) - return status; - - _cairo_box_to_doubles (&bbox, &x1, &y1, &x2, &y2); - - x_scale = scaled_font->extent_x_scale; - y_scale = scaled_font->extent_y_scale; - extents.x_bearing = x1 * x_scale; - extents.y_bearing = y1 * y_scale; - extents.width = (x2 - x1) * x_scale; - extents.height = (y2 - y1) * y_scale; - } - - if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF) { - extents.x_advance = _cairo_lround (extents.x_advance / scaled_font->snap_x_scale) * scaled_font->snap_x_scale; - extents.y_advance = _cairo_lround (extents.y_advance / scaled_font->snap_y_scale) * scaled_font->snap_y_scale; - } - - _cairo_scaled_glyph_set_metrics (scaled_glyph, - &scaled_font->base, - &extents); - } - - if (info & CAIRO_SCALED_GLYPH_INFO_SURFACE) { - cairo_surface_t *surface; - cairo_format_t format; - int width, height; - - /* TODO - * extend the glyph cache to support argb glyphs. - * need to figure out the semantics and interaction with subpixel - * rendering first. - */ - - width = _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.x) - - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x); - height = _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.y) - - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y); - - switch (scaled_font->base.options.antialias) { - default: - case CAIRO_ANTIALIAS_DEFAULT: - case CAIRO_ANTIALIAS_FAST: - case CAIRO_ANTIALIAS_GOOD: - case CAIRO_ANTIALIAS_GRAY: format = CAIRO_FORMAT_A8; break; - case CAIRO_ANTIALIAS_NONE: format = CAIRO_FORMAT_A1; break; - case CAIRO_ANTIALIAS_BEST: - case CAIRO_ANTIALIAS_SUBPIXEL: format = CAIRO_FORMAT_ARGB32; break; - } - surface = cairo_image_surface_create (format, width, height); - - cairo_surface_set_device_offset (surface, - - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x), - - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y)); - status = _cairo_recording_surface_replay (recording_surface, surface); - - if (unlikely (status)) { - cairo_surface_destroy(surface); - return status; - } - - _cairo_scaled_glyph_set_surface (scaled_glyph, - &scaled_font->base, - (cairo_image_surface_t *) surface); - } - - if (info & CAIRO_SCALED_GLYPH_INFO_PATH) { - cairo_path_fixed_t *path = _cairo_path_fixed_create (); - if (!path) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_recording_surface_get_path (recording_surface, path); - if (unlikely (status)) { - _cairo_path_fixed_destroy (path); - return status; - } - - _cairo_scaled_glyph_set_path (scaled_glyph, - &scaled_font->base, - path); - } - - return status; -} - -static unsigned long -_cairo_user_ucs4_to_index (void *abstract_font, - uint32_t ucs4) -{ - cairo_user_scaled_font_t *scaled_font = abstract_font; - cairo_user_font_face_t *face = - (cairo_user_font_face_t *) scaled_font->base.font_face; - unsigned long glyph = 0; - - if (face->scaled_font_methods.unicode_to_glyph) { - cairo_status_t status; - - status = face->scaled_font_methods.unicode_to_glyph (&scaled_font->base, - ucs4, &glyph); - - if (status == CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED) - goto not_implemented; - - if (status != CAIRO_STATUS_SUCCESS) { - status = _cairo_scaled_font_set_error (&scaled_font->base, status); - glyph = 0; - } - - } else { -not_implemented: - glyph = ucs4; - } - - return glyph; -} - -static cairo_int_status_t -_cairo_user_text_to_glyphs (void *abstract_font, - double x, - double y, - const char *utf8, - int utf8_len, - cairo_glyph_t **glyphs, - int *num_glyphs, - cairo_text_cluster_t **clusters, - int *num_clusters, - cairo_text_cluster_flags_t *cluster_flags) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; - - cairo_user_scaled_font_t *scaled_font = abstract_font; - cairo_user_font_face_t *face = - (cairo_user_font_face_t *) scaled_font->base.font_face; - - if (face->scaled_font_methods.text_to_glyphs) { - int i; - cairo_glyph_t *orig_glyphs = *glyphs; - int orig_num_glyphs = *num_glyphs; - - status = face->scaled_font_methods.text_to_glyphs (&scaled_font->base, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, cluster_flags); - - if (status != CAIRO_INT_STATUS_SUCCESS && - status != CAIRO_INT_STATUS_USER_FONT_NOT_IMPLEMENTED) - return status; - - if (status == CAIRO_INT_STATUS_USER_FONT_NOT_IMPLEMENTED || - *num_glyphs < 0) { - if (orig_glyphs != *glyphs) { - cairo_glyph_free (*glyphs); - *glyphs = orig_glyphs; - } - *num_glyphs = orig_num_glyphs; - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* Convert from font space to user space and add x,y */ - for (i = 0; i < *num_glyphs; i++) { - double gx = (*glyphs)[i].x; - double gy = (*glyphs)[i].y; - - cairo_matrix_transform_point (&scaled_font->base.font_matrix, - &gx, &gy); - - (*glyphs)[i].x = gx + x; - (*glyphs)[i].y = gy + y; - } - } - - return status; -} - -static cairo_status_t -_cairo_user_font_face_scaled_font_create (void *abstract_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - cairo_scaled_font_t **scaled_font); - -static cairo_status_t -_cairo_user_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, - cairo_font_face_t **font_face) -{ - return _cairo_font_face_twin_create_for_toy (toy_face, font_face); -} - -static const cairo_scaled_font_backend_t _cairo_user_scaled_font_backend = { - CAIRO_FONT_TYPE_USER, - NULL, /* scaled_font_fini */ - _cairo_user_scaled_glyph_init, - _cairo_user_text_to_glyphs, - _cairo_user_ucs4_to_index, - NULL, /* show_glyphs */ - NULL, /* load_truetype_table */ - NULL /* index_to_ucs4 */ -}; - -/* #cairo_user_font_face_t */ - -static cairo_status_t -_cairo_user_font_face_scaled_font_create (void *abstract_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - cairo_scaled_font_t **scaled_font) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_user_font_face_t *font_face = abstract_face; - cairo_user_scaled_font_t *user_scaled_font = NULL; - cairo_font_extents_t font_extents = {1., 0., 1., 1., 0.}; - - font_face->immutable = TRUE; - - user_scaled_font = malloc (sizeof (cairo_user_scaled_font_t)); - if (unlikely (user_scaled_font == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = _cairo_scaled_font_init (&user_scaled_font->base, - &font_face->base, - font_matrix, ctm, options, - &_cairo_user_scaled_font_backend); - - if (unlikely (status)) { - free (user_scaled_font); - return status; - } - - /* XXX metrics hinting? */ - - /* compute a normalized version of font scale matrix to compute - * extents in. This is to minimize error caused by the cairo_fixed_t - * representation. */ - { - double fixed_scale, x_scale, y_scale; - - user_scaled_font->extent_scale = user_scaled_font->base.scale_inverse; - status = _cairo_matrix_compute_basis_scale_factors (&user_scaled_font->extent_scale, - &x_scale, &y_scale, - 1); - if (status == CAIRO_STATUS_SUCCESS) { - - if (x_scale == 0) x_scale = 1.; - if (y_scale == 0) y_scale = 1.; - - user_scaled_font->snap_x_scale = x_scale; - user_scaled_font->snap_y_scale = y_scale; - - /* since glyphs are pretty much 1.0x1.0, we can reduce error by - * scaling to a larger square. say, 1024.x1024. */ - fixed_scale = 1024.; - x_scale /= fixed_scale; - y_scale /= fixed_scale; - - cairo_matrix_scale (&user_scaled_font->extent_scale, 1. / x_scale, 1. / y_scale); - - user_scaled_font->extent_x_scale = x_scale; - user_scaled_font->extent_y_scale = y_scale; - } - } - - if (status == CAIRO_STATUS_SUCCESS && - font_face->scaled_font_methods.init != NULL) - { - /* Lock the scaled_font mutex such that user doesn't accidentally try - * to use it just yet. */ - CAIRO_MUTEX_LOCK (user_scaled_font->base.mutex); - - /* Give away fontmap lock such that user-font can use other fonts */ - status = _cairo_scaled_font_register_placeholder_and_unlock_font_map (&user_scaled_font->base); - if (status == CAIRO_STATUS_SUCCESS) { - cairo_surface_t *recording_surface; - cairo_t *cr; - - recording_surface = _cairo_user_scaled_font_create_recording_surface (user_scaled_font); - cr = _cairo_user_scaled_font_create_recording_context (user_scaled_font, recording_surface); - cairo_surface_destroy (recording_surface); - - status = font_face->scaled_font_methods.init (&user_scaled_font->base, - cr, - &font_extents); - - if (status == CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED) - status = CAIRO_STATUS_SUCCESS; - - if (status == CAIRO_STATUS_SUCCESS) - status = cairo_status (cr); - - cairo_destroy (cr); - - _cairo_scaled_font_unregister_placeholder_and_lock_font_map (&user_scaled_font->base); - } - - CAIRO_MUTEX_UNLOCK (user_scaled_font->base.mutex); - } - - if (status == CAIRO_STATUS_SUCCESS) - status = _cairo_scaled_font_set_metrics (&user_scaled_font->base, &font_extents); - - if (status != CAIRO_STATUS_SUCCESS) { - _cairo_scaled_font_fini (&user_scaled_font->base); - free (user_scaled_font); - } else { - user_scaled_font->default_glyph_extents.x_bearing = 0.; - user_scaled_font->default_glyph_extents.y_bearing = -font_extents.ascent; - user_scaled_font->default_glyph_extents.width = 0.; - user_scaled_font->default_glyph_extents.height = font_extents.ascent + font_extents.descent; - user_scaled_font->default_glyph_extents.x_advance = font_extents.max_x_advance; - user_scaled_font->default_glyph_extents.y_advance = 0.; - - *scaled_font = &user_scaled_font->base; - } - - return status; -} - -const cairo_font_face_backend_t _cairo_user_font_face_backend = { - CAIRO_FONT_TYPE_USER, - _cairo_user_font_face_create_for_toy, - _cairo_font_face_destroy, - _cairo_user_font_face_scaled_font_create -}; - - -cairo_bool_t -_cairo_font_face_is_user (cairo_font_face_t *font_face) -{ - return font_face->backend == &_cairo_user_font_face_backend; -} - -/* Implement the public interface */ - -/** - * cairo_user_font_face_create: - * - * Creates a new user font-face. - * - * Use the setter functions to associate callbacks with the returned - * user font. The only mandatory callback is render_glyph. - * - * After the font-face is created, the user can attach arbitrary data - * (the actual font data) to it using cairo_font_face_set_user_data() - * and access it from the user-font callbacks by using - * cairo_scaled_font_get_font_face() followed by - * cairo_font_face_get_user_data(). - * - * Return value: a newly created #cairo_font_face_t. Free with - * cairo_font_face_destroy() when you are done using it. - * - * Since: 1.8 - **/ -cairo_font_face_t * -cairo_user_font_face_create (void) -{ - cairo_user_font_face_t *font_face; - - font_face = malloc (sizeof (cairo_user_font_face_t)); - if (!font_face) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_font_face_t *)&_cairo_font_face_nil; - } - - _cairo_font_face_init (&font_face->base, &_cairo_user_font_face_backend); - - font_face->immutable = FALSE; - memset (&font_face->scaled_font_methods, 0, sizeof (font_face->scaled_font_methods)); - - return &font_face->base; -} -slim_hidden_def(cairo_user_font_face_create); - -/* User-font method setters */ - - -/** - * cairo_user_font_face_set_init_func: - * @font_face: A user font face - * @init_func: The init callback, or %NULL - * - * Sets the scaled-font initialization function of a user-font. - * See #cairo_user_scaled_font_init_func_t for details of how the callback - * works. - * - * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE - * error will occur. A user font-face is immutable as soon as a scaled-font - * is created from it. - * - * Since: 1.8 - **/ -void -cairo_user_font_face_set_init_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_init_func_t init_func) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - if (user_font_face->immutable) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) - return; - } - user_font_face->scaled_font_methods.init = init_func; -} -slim_hidden_def(cairo_user_font_face_set_init_func); - -/** - * cairo_user_font_face_set_render_glyph_func: - * @font_face: A user font face - * @render_glyph_func: The render_glyph callback, or %NULL - * - * Sets the glyph rendering function of a user-font. - * See #cairo_user_scaled_font_render_glyph_func_t for details of how the callback - * works. - * - * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE - * error will occur. A user font-face is immutable as soon as a scaled-font - * is created from it. - * - * The render_glyph callback is the only mandatory callback of a user-font. - * If the callback is %NULL and a glyph is tried to be rendered using - * @font_face, a %CAIRO_STATUS_USER_FONT_ERROR will occur. - * - * Since: 1.8 - **/ -void -cairo_user_font_face_set_render_glyph_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_render_glyph_func_t render_glyph_func) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - if (user_font_face->immutable) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) - return; - } - user_font_face->scaled_font_methods.render_glyph = render_glyph_func; -} -slim_hidden_def(cairo_user_font_face_set_render_glyph_func); - -/** - * cairo_user_font_face_set_text_to_glyphs_func: - * @font_face: A user font face - * @text_to_glyphs_func: The text_to_glyphs callback, or %NULL - * - * Sets th text-to-glyphs conversion function of a user-font. - * See #cairo_user_scaled_font_text_to_glyphs_func_t for details of how the callback - * works. - * - * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE - * error will occur. A user font-face is immutable as soon as a scaled-font - * is created from it. - * - * Since: 1.8 - **/ -void -cairo_user_font_face_set_text_to_glyphs_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_text_to_glyphs_func_t text_to_glyphs_func) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - if (user_font_face->immutable) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) - return; - } - user_font_face->scaled_font_methods.text_to_glyphs = text_to_glyphs_func; -} - -/** - * cairo_user_font_face_set_unicode_to_glyph_func: - * @font_face: A user font face - * @unicode_to_glyph_func: The unicode_to_glyph callback, or %NULL - * - * Sets the unicode-to-glyph conversion function of a user-font. - * See #cairo_user_scaled_font_unicode_to_glyph_func_t for details of how the callback - * works. - * - * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE - * error will occur. A user font-face is immutable as soon as a scaled-font - * is created from it. - * - * Since: 1.8 - **/ -void -cairo_user_font_face_set_unicode_to_glyph_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_unicode_to_glyph_func_t unicode_to_glyph_func) -{ - cairo_user_font_face_t *user_font_face; - if (font_face->status) - return; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - if (user_font_face->immutable) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) - return; - } - user_font_face->scaled_font_methods.unicode_to_glyph = unicode_to_glyph_func; -} -slim_hidden_def(cairo_user_font_face_set_unicode_to_glyph_func); - -/* User-font method getters */ - -/** - * cairo_user_font_face_get_init_func: - * @font_face: A user font face - * - * Gets the scaled-font initialization function of a user-font. - * - * Return value: The init callback of @font_face - * or %NULL if none set or an error has occurred. - * - * Since: 1.8 - **/ -cairo_user_scaled_font_init_func_t -cairo_user_font_face_get_init_func (cairo_font_face_t *font_face) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return NULL; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return NULL; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - return user_font_face->scaled_font_methods.init; -} - -/** - * cairo_user_font_face_get_render_glyph_func: - * @font_face: A user font face - * - * Gets the glyph rendering function of a user-font. - * - * Return value: The render_glyph callback of @font_face - * or %NULL if none set or an error has occurred. - * - * Since: 1.8 - **/ -cairo_user_scaled_font_render_glyph_func_t -cairo_user_font_face_get_render_glyph_func (cairo_font_face_t *font_face) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return NULL; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return NULL; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - return user_font_face->scaled_font_methods.render_glyph; -} - -/** - * cairo_user_font_face_get_text_to_glyphs_func: - * @font_face: A user font face - * - * Gets the text-to-glyphs conversion function of a user-font. - * - * Return value: The text_to_glyphs callback of @font_face - * or %NULL if none set or an error occurred. - * - * Since: 1.8 - **/ -cairo_user_scaled_font_text_to_glyphs_func_t -cairo_user_font_face_get_text_to_glyphs_func (cairo_font_face_t *font_face) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return NULL; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return NULL; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - return user_font_face->scaled_font_methods.text_to_glyphs; -} - -/** - * cairo_user_font_face_get_unicode_to_glyph_func: - * @font_face: A user font face - * - * Gets the unicode-to-glyph conversion function of a user-font. - * - * Return value: The unicode_to_glyph callback of @font_face - * or %NULL if none set or an error occurred. - * - * Since: 1.8 - **/ -cairo_user_scaled_font_unicode_to_glyph_func_t -cairo_user_font_face_get_unicode_to_glyph_func (cairo_font_face_t *font_face) -{ - cairo_user_font_face_t *user_font_face; - - if (font_face->status) - return NULL; - - if (! _cairo_font_face_is_user (font_face)) { - if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) - return NULL; - } - - user_font_face = (cairo_user_font_face_t *) font_face; - return user_font_face->scaled_font_methods.unicode_to_glyph; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.c deleted file mode 100644 index a94cef6819d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.c +++ /dev/null @@ -1,261 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#define CAIRO_VERSION_H 1 - -#include "cairoint.h" - -/* get the "real" version info instead of dummy cairo-version.h */ -#undef CAIRO_VERSION_H -#include "../cairo-version.h" - -/** - * SECTION:cairo-version - * @Title: Version Information - * @Short_Description: Compile-time and run-time version checks. - * - * Cairo has a three-part version number scheme. In this scheme, we use - * even vs. odd numbers to distinguish fixed points in the software - * vs. in-progress development, (such as from git instead of a tar file, - * or as a "snapshot" tar file as opposed to a "release" tar file). - * - * - * _____ Major. Always 1, until we invent a new scheme. - * / ___ Minor. Even/Odd = Release/Snapshot (tar files) or Branch/Head (git) - * | / _ Micro. Even/Odd = Tar-file/git - * | | / - * 1.0.0 - * - * - * Here are a few examples of versions that one might see. - * - * Releases - * -------- - * 1.0.0 - A major release - * 1.0.2 - A subsequent maintenance release - * 1.2.0 - Another major release - *   - * Snapshots - * --------- - * 1.1.2 - A snapshot (working toward the 1.2.0 release) - *   - * In-progress development (eg. from git) - * -------------------------------------- - * 1.0.1 - Development on a maintenance branch (toward 1.0.2 release) - * 1.1.1 - Development on head (toward 1.1.2 snapshot and 1.2.0 release) - * - * - * - * Compatibility - * - * The API/ABI compatibility guarantees for various versions are as - * follows. First, let's assume some cairo-using application code that is - * successfully using the API/ABI "from" one version of cairo. Then let's - * ask the question whether this same code can be moved "to" the API/ABI - * of another version of cairo. - * - * Moving from a release to any later version (release, snapshot, - * development) is always guaranteed to provide compatibility. - * - * Moving from a snapshot to any later version is not guaranteed to - * provide compatibility, since snapshots may introduce new API that ends - * up being removed before the next release. - * - * Moving from an in-development version (odd micro component) to any - * later version is not guaranteed to provide compatibility. In fact, - * there's not even a guarantee that the code will even continue to work - * with the same in-development version number. This is because these - * numbers don't correspond to any fixed state of the software, but - * rather the many states between snapshots and releases. - * - * - * - * Examining the version - * - * Cairo provides the ability to examine the version at either - * compile-time or run-time and in both a human-readable form as well as - * an encoded form suitable for direct comparison. Cairo also provides the - * macro CAIRO_VERSION_ENCODE() to perform the encoding. - * - * - * Compile-time - * ------------ - * CAIRO_VERSION_STRING Human-readable - * CAIRO_VERSION Encoded, suitable for comparison - *   - * Run-time - * -------- - * cairo_version_string() Human-readable - * cairo_version() Encoded, suitable for comparison - * - * - * For example, checking that the cairo version is greater than or equal - * to 1.0.0 could be achieved at compile-time or run-time as follows: - * - * - * ##if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 0, 0) - * printf ("Compiling with suitable cairo version: %s\n", %CAIRO_VERSION_STRING); - * ##endif - * - * if (cairo_version() >= CAIRO_VERSION_ENCODE(1, 0, 0)) - * printf ("Running with suitable cairo version: %s\n", cairo_version_string ()); - * - * - * - * - **/ - -/** - * CAIRO_VERSION: - * - * The version of cairo available at compile-time, encoded using - * CAIRO_VERSION_ENCODE(). - * - * Since: 1.0 - **/ - -/** - * CAIRO_VERSION_MAJOR: - * - * The major component of the version of cairo available at compile-time. - * - * Since: 1.0 - **/ - -/** - * CAIRO_VERSION_MINOR: - * - * The minor component of the version of cairo available at compile-time. - * - * Since: 1.0 - **/ - -/** - * CAIRO_VERSION_MICRO: - * - * The micro component of the version of cairo available at compile-time. - * - * Since: 1.0 - **/ - -/** - * CAIRO_VERSION_STRING: - * - * A human-readable string literal containing the version of cairo available - * at compile-time, in the form of "X.Y.Z". - * - * Since: 1.8 - **/ - -/** - * CAIRO_VERSION_ENCODE: - * @major: the major component of the version number - * @minor: the minor component of the version number - * @micro: the micro component of the version number - * - * This macro encodes the given cairo version into an integer. The numbers - * returned by %CAIRO_VERSION and cairo_version() are encoded using this macro. - * Two encoded version numbers can be compared as integers. The encoding ensures - * that later versions compare greater than earlier versions. - * - * Returns: the encoded version. - * - * Since: 1.0 - **/ - -/** - * CAIRO_VERSION_STRINGIZE: - * @major: the major component of the version number - * @minor: the minor component of the version number - * @micro: the micro component of the version number - * - * This macro encodes the given cairo version into an string. The numbers - * returned by %CAIRO_VERSION_STRING and cairo_version_string() are encoded using this macro. - * The parameters to this macro must expand to numerical literals. - * - * Returns: a string literal containing the version. - * - * Since: 1.8 - **/ - -/** - * cairo_version: - * - * Returns the version of the cairo library encoded in a single - * integer as per %CAIRO_VERSION_ENCODE. The encoding ensures that - * later versions compare greater than earlier versions. - * - * A run-time comparison to check that cairo's version is greater than - * or equal to version X.Y.Z could be performed as follows: - * - * - * if (cairo_version() >= CAIRO_VERSION_ENCODE(X,Y,Z)) {...} - * - * - * See also cairo_version_string() as well as the compile-time - * equivalents %CAIRO_VERSION and %CAIRO_VERSION_STRING. - * - * Return value: the encoded version. - * - * Since: 1.0 - **/ -int -cairo_version (void) -{ - return CAIRO_VERSION; -} - -/** - * cairo_version_string: - * - * Returns the version of the cairo library as a human-readable string - * of the form "X.Y.Z". - * - * See also cairo_version() as well as the compile-time equivalents - * %CAIRO_VERSION_STRING and %CAIRO_VERSION. - * - * Return value: a string containing the version. - * - * Since: 1.0 - **/ -const char* -cairo_version_string (void) -{ - return CAIRO_VERSION_STRING; -} -slim_hidden_def (cairo_version_string); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.h deleted file mode 100644 index 51008003f98..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-version.h +++ /dev/null @@ -1,14 +0,0 @@ -/* This is a dummy file. - * The actual version info is in toplevel cairo-version.h. - * The purpose of this file is to make most of the source files NOT depend - * on the real cairo-version.h, and as a result, changing library version - * would not cause a complete rebuild of all object files (just a relink). - * This is useful when bisecting. */ -#ifndef CAIRO_VERSION_H -#define CAIRO_VERSION_H - -#define CAIRO_VERSION_MAJOR USE_cairo_version_OR_cairo_version_string_INSTEAD -#define CAIRO_VERSION_MINOR USE_cairo_version_OR_cairo_version_string_INSTEAD -#define CAIRO_VERSION_MICRO USE_cairo_version_OR_cairo_version_string_INSTEAD - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg-surface.c deleted file mode 100644 index 6e0d9a0ed69..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg-surface.c +++ /dev/null @@ -1,1853 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Opened Hand Ltd. - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.og/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Pierre Tardy - * Øyvind Kolås - * Vladimi Vukicevic (stubbed out base backend) - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-vg.h" - -#include "cairo-cache-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-path-fixed-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-surface-clipper-private.h" - -#include -#include - -//#define OPENVG_DEBUG - -/* - * Work that needs to be done: - * - Glyph cache / proper font support - * - * - First-class paths - * Paths are expensive for OpenVG, reuse paths whenever possible. - * So add a path cache, and first class paths! - */ - -typedef struct _cairo_vg_surface cairo_vg_surface_t; - -/* XXX need GL specific context control. :( */ -struct _cairo_vg_context { - cairo_status_t status; - cairo_reference_count_t ref_count; - - unsigned long target_id; - - VGPaint paint; - cairo_vg_surface_t *source; - double alpha; - - cairo_cache_t snapshot_cache; - - void *display; - void *context; - - cairo_status_t (*create_target) (cairo_vg_context_t *, - cairo_vg_surface_t *); - cairo_status_t (*set_target) (cairo_vg_context_t *, - cairo_vg_surface_t *); - void (*destroy_target) (cairo_vg_context_t *, cairo_vg_surface_t *); -}; - -struct _cairo_vg_surface { - cairo_surface_t base; - - cairo_vg_context_t *context; - - VGImage image; - VGImageFormat format; - int width; - int height; - cairo_bool_t own_image; - - cairo_cache_entry_t snapshot_cache_entry; - - cairo_surface_clipper_t clipper; - - unsigned long target_id; -}; - -static const cairo_surface_backend_t cairo_vg_surface_backend; - -slim_hidden_proto (cairo_vg_surface_create); - -static cairo_surface_t * -_vg_surface_create_internal (cairo_vg_context_t *context, - VGImage image, - VGImageFormat format, - int width, int height); - -static cairo_vg_context_t * -_vg_context_reference (cairo_vg_context_t *context) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&context->ref_count)); - - _cairo_reference_count_inc (&context->ref_count); - - return context; -} - -static cairo_vg_context_t * -_vg_context_lock (cairo_vg_context_t *context) -{ - /* XXX if we need to add locking, then it has to be recursive */ - return context; -} - -static cairo_int_status_t -_vg_context_set_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ - cairo_status_t status; - - if (surface->target_id == 0) { - status = context->create_target (context, surface); - if (unlikely (status)) - return status; - } - - if (context->target_id == surface->target_id) - return CAIRO_STATUS_SUCCESS; - - context->target_id = surface->target_id; - - return context->set_target (context, surface); -} - -static void -_vg_context_destroy_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ - if (surface->target_id == 0) - return; - - if (context->target_id == surface->target_id) - context->set_target (context, NULL); - - context->destroy_target (context, surface); -} - -static cairo_bool_t -_vg_snapshot_cache_can_remove (const void *entry) -{ - return TRUE; -} - -static void -_vg_snapshot_cache_remove (void *cache_entry) -{ - cairo_vg_surface_t *surface = cairo_container_of (cache_entry, - cairo_vg_surface_t, - snapshot_cache_entry); - surface->snapshot_cache_entry.hash = 0; - cairo_surface_destroy (&surface->base); -} - -static cairo_status_t -_vg_context_init (cairo_vg_context_t *context) -{ - cairo_status_t status; - - context->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (&context->ref_count, 1); - - status = _cairo_cache_init (&context->snapshot_cache, - NULL, - _vg_snapshot_cache_can_remove, - _vg_snapshot_cache_remove, - 16*1024*1024); - if (unlikely (status)) - return status; - - context->target_id = 0; - context->source = NULL; - context->alpha = 1.0; - - context->paint = vgCreatePaint (); - vgLoadIdentity (); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_vg_context_destroy (cairo_vg_context_t *context) -{ - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&context->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&context->ref_count)) - return; - - if (context->paint != VG_INVALID_HANDLE) - vgDestroyPaint (context->paint); - - _cairo_cache_fini (&context->snapshot_cache); - free (context); -} - -static void -_vg_context_unlock (cairo_vg_context_t *context) -{ -} - -#ifdef OPENVG_DEBUG -static void check_vg_errors(const char*function,int line) -{ - int err = vgGetError(); - if (err != VG_NO_ERROR){ - printf("%s+%d:vgError detected: 0x%08x.\n",function, line,err); - assert(err == VG_NO_ERROR); - } - -} -#define CHECK_VG_ERRORS() check_vg_errors(__FILE__,__LINE__) -#else -#define CHECK_VG_ERRORS() do{}while(0) -#endif //OPENVG_DEBUG - -static pixman_format_code_t -_vg_format_to_pixman (VGImageFormat format, - cairo_bool_t *needs_premult_fixup) -{ - *needs_premult_fixup = FALSE; - switch (format) { - /* RGB{A,X} channel ordering */ - case VG_sRGBX_8888: return PIXMAN_r8g8b8x8; - case VG_sRGBA_8888: *needs_premult_fixup = TRUE; return PIXMAN_r8g8b8a8; - case VG_sRGBA_8888_PRE: return PIXMAN_r8g8b8a8; - case VG_sRGB_565: return PIXMAN_r5g6b5; - case VG_sRGBA_5551: return 0; - case VG_sRGBA_4444: return 0; - case VG_sL_8: return PIXMAN_g8; - case VG_lRGBX_8888: return 0; - case VG_lRGBA_8888: return 0; - case VG_lRGBA_8888_PRE: return 0; - case VG_lL_8: return 0; - case VG_A_8: return PIXMAN_a8; - case VG_BW_1: return PIXMAN_a1; - case VG_A_1: return PIXMAN_a1; - case VG_A_4: return PIXMAN_a4; - - /* {A,X}RGB channel ordering */ - case VG_sXRGB_8888: return PIXMAN_x8r8g8b8; - case VG_sARGB_8888: *needs_premult_fixup = TRUE; return PIXMAN_a8r8g8b8; - case VG_sARGB_8888_PRE: return PIXMAN_a8r8g8b8; - case VG_sARGB_1555: return 0; - case VG_sARGB_4444: return 0; - case VG_lXRGB_8888: return 0; - case VG_lARGB_8888: return 0; - case VG_lARGB_8888_PRE: return 0; - - /* BGR{A,X} channel ordering */ - case VG_sBGRX_8888: return PIXMAN_b8g8r8x8; - case VG_sBGRA_8888: *needs_premult_fixup = TRUE; return PIXMAN_b8g8r8a8; - case VG_sBGRA_8888_PRE: return PIXMAN_b8g8r8a8; - case VG_sBGR_565: return PIXMAN_b5g6r5; - case VG_sBGRA_5551: return 0; - case VG_sBGRA_4444: return 0; - case VG_lBGRX_8888: return 0; - case VG_lBGRA_8888: return 0; - case VG_lBGRA_8888_PRE: return 0; - - /* {A,X}BGR channel ordering */ - case VG_sXBGR_8888: return PIXMAN_x8b8g8r8; - case VG_sABGR_8888: *needs_premult_fixup = TRUE; return PIXMAN_a8b8g8r8; - case VG_sABGR_8888_PRE: return PIXMAN_a8b8g8r8; - case VG_sABGR_1555: return 0; - case VG_sABGR_4444: return 0; - case VG_lXBGR_8888: return 0; - case VG_lABGR_8888: return 0; - case VG_lABGR_8888_PRE: return 0; - default: return 0; - } -} - -static pixman_format_code_t -_vg_format_to_content (VGImageFormat format) -{ - /* XXX could use more simple bit tests */ - switch (format) { - /* RGB{A,X} channel ordering */ - case VG_sRGBX_8888: return CAIRO_CONTENT_COLOR; - case VG_sRGBA_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sRGBA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sRGB_565: return CAIRO_CONTENT_COLOR; - case VG_sRGBA_5551: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sRGBA_4444: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sL_8: return CAIRO_CONTENT_ALPHA; - case VG_lRGBX_8888: return CAIRO_CONTENT_COLOR; - case VG_lRGBA_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lRGBA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lL_8: return CAIRO_CONTENT_ALPHA; - case VG_A_8: return CAIRO_CONTENT_ALPHA; - case VG_A_4: return CAIRO_CONTENT_ALPHA; - case VG_A_1: return CAIRO_CONTENT_ALPHA; - case VG_BW_1: return CAIRO_CONTENT_ALPHA; - - /* {A,X}RGB channel ordering */ - case VG_sXRGB_8888: return CAIRO_CONTENT_COLOR; - case VG_sARGB_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sARGB_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sARGB_1555: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sARGB_4444: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lXRGB_8888: return CAIRO_CONTENT_COLOR; - case VG_lARGB_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lARGB_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - - /* BGR{A,X} channel ordering */ - case VG_sBGRX_8888: return CAIRO_CONTENT_COLOR; - case VG_sBGRA_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sBGRA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sBGR_565: return CAIRO_CONTENT_COLOR; - case VG_sBGRA_5551: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sBGRA_4444: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lBGRX_8888: return CAIRO_CONTENT_COLOR; - case VG_lBGRA_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lBGRA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - - /* {A,X}BGR channel ordering */ - case VG_sXBGR_8888: return CAIRO_CONTENT_COLOR; - case VG_sABGR_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sABGR_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sABGR_1555: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_sABGR_4444: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lXBGR_8888: return CAIRO_CONTENT_COLOR; - case VG_lABGR_8888: return CAIRO_CONTENT_COLOR_ALPHA; - case VG_lABGR_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; - default: return 0; - } -} - -static VGImageFormat -_vg_format_from_pixman (pixman_format_code_t format) -{ - /* XXX _PRE needs fixup */ - switch ((int) format) { - case PIXMAN_r5g6b5: return VG_sRGB_565; - case PIXMAN_g8: return VG_sL_8; - case PIXMAN_a8: return VG_A_8; - case PIXMAN_a1: return VG_BW_1; - case PIXMAN_x8r8g8b8: return VG_sXRGB_8888; - case PIXMAN_a8r8g8b8: return VG_sARGB_8888; // _PRE - case PIXMAN_b8g8r8x8: return VG_sBGRX_8888; - case PIXMAN_b8g8r8a8: return VG_sBGRA_8888; // _PRE - case PIXMAN_b5g6r5: return VG_sBGR_565; - case PIXMAN_x8b8g8r8: return VG_sXBGR_8888; - case PIXMAN_a8b8g8r8: return VG_sABGR_8888; // _PRE - default: return 0; - } -} - -static VGImageFormat -_vg_format_for_content (cairo_content_t content) -{ - switch (content) { - case CAIRO_CONTENT_ALPHA: return VG_A_8; - case CAIRO_CONTENT_COLOR: return VG_sXRGB_8888; - default: ASSERT_NOT_REACHED; - case CAIRO_CONTENT_COLOR_ALPHA: return VG_sARGB_8888; // _PRE - } -} - -static cairo_surface_t * -_vg_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_vg_surface_t *surface = abstract_surface; - - if (width > vgGeti (VG_MAX_IMAGE_WIDTH) || - height > vgGeti (VG_MAX_IMAGE_HEIGHT)) - { - return NULL; - } - - return cairo_vg_surface_create (surface->context, content, width, height); -} - -static cairo_status_t -_vg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, - cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_vg_surface_t *surface = cairo_container_of (clipper, - cairo_vg_surface_t, - clipper); - cairo_vg_surface_t *mask; - cairo_status_t status; - - if (path == NULL) { - vgMask (VG_INVALID_HANDLE, - VG_FILL_MASK, 0, 0, surface->width, surface->height); - vgSeti (VG_MASKING, VG_FALSE); - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; - } - - mask = (cairo_vg_surface_t *) - _vg_surface_create_similar (surface, CAIRO_CONTENT_ALPHA, - surface->width, surface->height); - if (unlikely (mask == NULL)) - return CAIRO_INT_STATUS_UNSUPPORTED; - if (unlikely (mask->base.status)) - return mask->base.status; - - status = _cairo_surface_fill (&mask->base, - CAIRO_OPERATOR_SOURCE, - &_cairo_pattern_white.base, - path, fill_rule, tolerance, antialias, - NULL); - if (status) { - cairo_surface_destroy (&mask->base); - return status; - } - - vgSeti (VG_MASKING, VG_TRUE); - vgMask (mask->image, VG_INTERSECT_MASK, 0, 0, mask->width, mask->height); - - cairo_surface_destroy (&mask->base); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_vg_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_vg_surface_t *surface = abstract_surface; - - extents->x = 0; - extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - - return TRUE; -} - -#define MAX_SEG 16 /* max number of knots to upload in a batch */ - -typedef struct _vg_path { - VGPath path; - const cairo_matrix_t *ctm_inverse; - - VGubyte gseg[MAX_SEG]; - VGfloat gdata[MAX_SEG*3*2]; - int dcount; - int scount; -} vg_path_t; - -static cairo_status_t -_vg_move_to (void *closure, - const cairo_point_t *point) -{ - vg_path_t *path = closure; - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (path->ctm_inverse) - cairo_matrix_transform_point (path->ctm_inverse, &x, &y); - - path->gseg[path->scount++] = VG_MOVE_TO; - path->gdata[path->dcount++] = x; - path->gdata[path->dcount++] = y; - - if (path->scount >= MAX_SEG-1) { - vgAppendPathData (path->path, path->scount, path->gseg, path->gdata); - path->scount = 0; - path->dcount = 0; - } - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_vg_line_to (void *closure, - const cairo_point_t *point) -{ - vg_path_t *path = closure; - double x = _cairo_fixed_to_double (point->x); - double y = _cairo_fixed_to_double (point->y); - - if (path->ctm_inverse) - cairo_matrix_transform_point (path->ctm_inverse, &x, &y); - - path->gseg[path->scount++] = VG_LINE_TO; - path->gdata[path->dcount++] = x; - path->gdata[path->dcount++] = y; - - if (path->scount >= MAX_SEG-1) { - vgAppendPathData (path->path, path->scount, path->gseg, path->gdata); - path->scount = 0; - path->dcount = 0; - } - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_vg_curve_to (void *closure, - const cairo_point_t *p0, - const cairo_point_t *p1, - const cairo_point_t *p2) -{ - vg_path_t *path = closure; - double x0 = _cairo_fixed_to_double (p0->x); - double y0 = _cairo_fixed_to_double (p0->y); - double x1 = _cairo_fixed_to_double (p1->x); - double y1 = _cairo_fixed_to_double (p1->y); - double x2 = _cairo_fixed_to_double (p2->x); - double y2 = _cairo_fixed_to_double (p2->y); - - if (path->ctm_inverse) { - cairo_matrix_transform_point (path->ctm_inverse, &x0, &y0); - cairo_matrix_transform_point (path->ctm_inverse, &x1, &y1); - cairo_matrix_transform_point (path->ctm_inverse, &x2, &y2); - } - - path->gseg[path->scount++] = VG_CUBIC_TO; - path->gdata[path->dcount++] = x0; - path->gdata[path->dcount++] = y0; - path->gdata[path->dcount++] = x1; - path->gdata[path->dcount++] = y1; - path->gdata[path->dcount++] = x2; - path->gdata[path->dcount++] = y2; - - if (path->scount >= MAX_SEG-1) { - vgAppendPathData(path->path, path->scount, path->gseg, path->gdata); - path->scount = 0; - path->dcount = 0; - } - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_vg_close_path (void *closure) -{ - vg_path_t *path = closure; - - path->gseg[path->scount++] = VG_CLOSE_PATH; - - if (path->scount >= MAX_SEG-1) { - vgAppendPathData (path->path, path->scount, path->gseg, path->gdata); - path->scount = 0; - path->dcount = 0; - } - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static void -_vg_path_from_cairo (vg_path_t *vg_path, - const cairo_path_fixed_t *path) -{ - cairo_status_t status; - - vg_path->scount = 0; - vg_path->dcount = 0; - - status = _cairo_path_fixed_interpret (path, - _vg_move_to, - _vg_line_to, - _vg_curve_to, - _vg_close_path, - vg_path); - assert (status == CAIRO_STATUS_SUCCESS); - - vgAppendPathData (vg_path->path, - vg_path->scount, vg_path->gseg, vg_path->gdata); - CHECK_VG_ERRORS(); -} - -static cairo_bool_t -_vg_is_supported_operator (cairo_operator_t op) -{ - switch ((int) op) { - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_IN: - case CAIRO_OPERATOR_DEST_OVER: - case CAIRO_OPERATOR_DEST_IN: - case CAIRO_OPERATOR_ADD: - return TRUE; - - default: - return FALSE; - } -} - -static VGBlendMode -_vg_operator (cairo_operator_t op) -{ - switch ((int) op) { - case CAIRO_OPERATOR_SOURCE: - return VG_BLEND_SRC; - case CAIRO_OPERATOR_OVER: - return VG_BLEND_SRC_OVER; - case CAIRO_OPERATOR_IN: - return VG_BLEND_SRC_IN; - case CAIRO_OPERATOR_DEST_OVER: - return VG_BLEND_DST_OVER; - case CAIRO_OPERATOR_DEST_IN: - return VG_BLEND_DST_IN; - case CAIRO_OPERATOR_ADD: - return VG_BLEND_ADDITIVE; - default: - ASSERT_NOT_REACHED; - return VG_BLEND_SRC_OVER; - } -} - -static VGFillRule -_vg_fill_rule_from_cairo (cairo_fill_rule_t rule) -{ - switch (rule) { - case CAIRO_FILL_RULE_EVEN_ODD: return VG_EVEN_ODD; - case CAIRO_FILL_RULE_WINDING: return VG_NON_ZERO; - } - - ASSERT_NOT_REACHED; - return VG_NON_ZERO; -} - -static VGRenderingQuality -_vg_rendering_quality_from_cairo (cairo_antialias_t aa) -{ - switch (aa) { - case CAIRO_ANTIALIAS_DEFAULT: - case CAIRO_ANTIALIAS_SUBPIXEL: - case CAIRO_ANTIALIAS_GOOD: - case CAIRO_ANTIALIAS_BEST: - return VG_RENDERING_QUALITY_BETTER; - - case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_FAST: - return VG_RENDERING_QUALITY_FASTER; - - case CAIRO_ANTIALIAS_NONE: - return VG_RENDERING_QUALITY_NONANTIALIASED; - } - - ASSERT_NOT_REACHED; - return VG_RENDERING_QUALITY_BETTER; -} - -static VGCapStyle -_vg_line_cap_from_cairo (cairo_line_cap_t cap) -{ - switch (cap) { - case CAIRO_LINE_CAP_BUTT: return VG_CAP_BUTT; - case CAIRO_LINE_CAP_ROUND: return VG_CAP_ROUND; - case CAIRO_LINE_CAP_SQUARE: return VG_CAP_SQUARE; - } - - ASSERT_NOT_REACHED; - return VG_CAP_BUTT; -} - -static VGJoinStyle -_vg_line_join_from_cairo (cairo_line_join_t join) -{ - switch (join) { - case CAIRO_LINE_JOIN_MITER: return VG_JOIN_MITER; - case CAIRO_LINE_JOIN_ROUND: return VG_JOIN_ROUND; - case CAIRO_LINE_JOIN_BEVEL: return VG_JOIN_BEVEL; - } - - ASSERT_NOT_REACHED; - return VG_JOIN_MITER; -} - -static void -_vg_matrix_from_cairo (VGfloat *dst, const cairo_matrix_t *src) -{ - dst[0] = /* sx */ src->xx; - dst[1] = /* shy */ src->yx; - dst[2] = /* w0 */ 0; - dst[3] = /* shx */ src->xy; - dst[4] = /* sy */ src->yy; - dst[5] = /* w1 */ 0; - dst[6] = /* tx */ src->x0; - dst[7] = /* ty */ src->y0; - dst[8] = /* w2 */ 0; -} - -static cairo_status_t -_vg_setup_gradient_stops (cairo_vg_context_t *context, - const cairo_gradient_pattern_t *pattern) -{ - VGint numstops = pattern->n_stops; - VGfloat *stops, stack_stops[CAIRO_STACK_ARRAY_LENGTH (VGfloat)]; - int i; - - if (numstops*5 < ARRAY_LENGTH (stack_stops)) { - stops = stack_stops; - } else { - stops = _cairo_malloc_ab (numstops, 5*sizeof (VGfloat)); - if (unlikely (stops == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - for (i = 0; i < numstops; i++) { - stops[i*5 + 0] = pattern->stops[i].offset; - stops[i*5 + 1] = pattern->stops[i].color.red; - stops[i*5 + 2] = pattern->stops[i].color.green; - stops[i*5 + 3] = pattern->stops[i].color.blue; - stops[i*5 + 4] = pattern->stops[i].color.alpha * context->alpha; - } - - vgSetParameterfv (context->paint, - VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops); - - if (stops != stack_stops) - free (stops); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static void -_vg_set_source_matrix (const cairo_pattern_t *pat) -{ - cairo_matrix_t mat; - cairo_status_t status; - VGfloat vmat[9]; - - mat = pat->matrix; - status = cairo_matrix_invert (&mat); - assert (status == CAIRO_STATUS_SUCCESS); - - _vg_matrix_from_cairo (vmat, &mat); - - vgSeti (VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); - vgLoadMatrix (vmat); - vgSeti (VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER); - vgLoadMatrix (vmat); - vgSeti (VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); - - CHECK_VG_ERRORS(); -} - -static cairo_status_t -_vg_setup_linear_source (cairo_vg_context_t *context, - const cairo_linear_pattern_t *lpat) -{ - VGfloat linear[4]; - - linear[0] = lpat->pd1.x; - linear[1] = lpat->pd1.y; - linear[2] = lpat->pd2.x; - linear[3] = lpat->pd2.y; - - vgSetParameteri (context->paint, - VG_PAINT_COLOR_RAMP_SPREAD_MODE, - VG_COLOR_RAMP_SPREAD_PAD); - vgSetParameteri (context->paint, - VG_PAINT_TYPE, - VG_PAINT_TYPE_LINEAR_GRADIENT); - vgSetParameterfv (context->paint, - VG_PAINT_LINEAR_GRADIENT, 4, linear); - - _vg_set_source_matrix (&lpat->base.base); - - CHECK_VG_ERRORS(); - return _vg_setup_gradient_stops (context, &lpat->base); - -} - -static cairo_status_t -_vg_setup_radial_source (cairo_vg_context_t *context, - const cairo_radial_pattern_t *rpat) -{ - VGfloat radial[5]; - - radial[0] = rpat->cd1.center.x; - radial[1] = rpat->cd1.center.y; - radial[2] = rpat->cd2.center.x; - radial[3] = rpat->cd2.center.y; - radial[4] = rpat->cd2.radius; - - vgSetParameteri (context->paint, - VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD); - vgSetParameteri (context->paint, - VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT); - vgSetParameterfv (context->paint, - VG_PAINT_RADIAL_GRADIENT, 5, radial); - - _vg_set_source_matrix (&rpat->base.base); - - /* FIXME: copy/adapt fixes from SVG backend to add inner radius */ - - CHECK_VG_ERRORS(); - return _vg_setup_gradient_stops (context, &rpat->base); -} - -static cairo_status_t -_vg_setup_solid_source (cairo_vg_context_t *context, - const cairo_solid_pattern_t *spat) -{ - VGfloat color[] = { - spat->color.red, - spat->color.green, - spat->color.blue, - spat->color.alpha * context->alpha - }; - - vgSetParameteri (context->paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); - vgSetParameterfv (context->paint, VG_PAINT_COLOR, 4, color); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_vg_surface_t * -_vg_clone_recording_surface (cairo_vg_context_t *context, - cairo_surface_t *surface) -{ - VGImage vg_image; - VGImageFormat format; - cairo_status_t status; - cairo_rectangle_int_t extents; - cairo_vg_surface_t *clone; - - status = _cairo_surface_get_extents (surface, &extents); - if (status) - return NULL; - - if (extents.width > vgGeti (VG_MAX_IMAGE_WIDTH) || - extents.height > vgGeti (VG_MAX_IMAGE_HEIGHT)) - { - return NULL; - } - - format = _vg_format_for_content (surface->content); - - /* NONALIASED, FASTER, BETTER */ - vg_image = vgCreateImage (format, - extents.width, extents.height, - VG_IMAGE_QUALITY_FASTER); - clone = (cairo_vg_surface_t *) - _vg_surface_create_internal (context, vg_image, format, - extents.width, extents.height); - cairo_surface_set_device_offset (&clone->base, -extents.x, -extents.y); - - status = _cairo_recording_surface_replay (surface, &clone->base); - if (unlikely (status)) { - cairo_surface_destroy (&clone->base); - return (cairo_vg_surface_t *) _cairo_surface_create_in_error (status); - } - - return clone; -} - -static cairo_vg_surface_t * -_vg_clone_image_surface (cairo_vg_context_t *context, - cairo_surface_t *surface) -{ - cairo_image_surface_t *image; - void *image_extra; - cairo_status_t status; - VGImage vg_image; - VGImageFormat format; - cairo_rectangle_int_t extents; - cairo_vg_surface_t *clone; - - if (surface->backend->acquire_source_image == NULL) - return NULL; - - status = _cairo_surface_get_extents (surface, &extents); - if (status) - return NULL; - - if (extents.width > vgGeti (VG_MAX_IMAGE_WIDTH) || - extents.height > vgGeti (VG_MAX_IMAGE_HEIGHT)) - { - return NULL; - } - - status = _cairo_surface_acquire_source_image (surface, - &image, &image_extra); - if (unlikely (status)) - return (cairo_vg_surface_t *) _cairo_surface_create_in_error (status); - - format = _vg_format_from_pixman (image->pixman_format); - if (format == 0) - format = _vg_format_for_content (image->base.content); - - /* NONALIASED, FASTER, BETTER */ - vg_image = vgCreateImage (format, - image->width, image->height, - VG_IMAGE_QUALITY_FASTER); - clone = (cairo_vg_surface_t *) - _vg_surface_create_internal (context, vg_image, format, - image->width, image->height); - if (unlikely (clone->base.status)) - return clone; - - vgImageSubData (clone->image, - image->data, image->stride, - format, 0, 0, image->width, image->height); - - _cairo_surface_release_source_image (surface, image, image_extra); - - return clone; -} - -static void -_vg_surface_remove_from_cache (cairo_surface_t *abstract_surface) -{ - cairo_vg_surface_t *surface = (cairo_vg_surface_t *) abstract_surface; - - if (surface->snapshot_cache_entry.hash) { - cairo_vg_context_t *context; - - context = _vg_context_lock (surface->context); - _cairo_cache_remove (&context->snapshot_cache, - &surface->snapshot_cache_entry); - _vg_context_unlock (context); - - surface->snapshot_cache_entry.hash = 0; - } -} - -static cairo_status_t -_vg_setup_surface_source (cairo_vg_context_t *context, - const cairo_surface_pattern_t *spat) -{ - cairo_surface_t *snapshot; - cairo_vg_surface_t *clone; - cairo_status_t status; - - snapshot = _cairo_surface_has_snapshot (spat->surface, - &cairo_vg_surface_backend); - if (snapshot != NULL) { - clone = (cairo_vg_surface_t *) cairo_surface_reference (snapshot); - goto DONE; - } - - if (_cairo_surface_is_recording (spat->surface)) - clone = _vg_clone_recording_surface (context, spat->surface); - else - clone = _vg_clone_image_surface (context, spat->surface); - if (clone == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - if (unlikely (clone->base.status)) - return clone->base.status; - - clone->snapshot_cache_entry.hash = clone->base.unique_id; - status = _cairo_cache_insert (&context->snapshot_cache, - &clone->snapshot_cache_entry); - if (unlikely (status)) { - clone->snapshot_cache_entry.hash = 0; - cairo_surface_destroy (&clone->base); - return status; - } - - _cairo_surface_attach_snapshot (spat->surface, &clone->base, - _vg_surface_remove_from_cache); - -DONE: - cairo_surface_destroy (&context->source->base); - context->source = clone; - - vgSetParameteri (context->paint, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN); - - switch (spat->base.extend) { - case CAIRO_EXTEND_PAD: - vgSetParameteri (context->paint, - VG_PAINT_PATTERN_TILING_MODE, - VG_TILE_PAD); - break; - - case CAIRO_EXTEND_NONE: - vgSetParameteri (context->paint, - VG_PAINT_PATTERN_TILING_MODE, - VG_TILE_FILL); - { - VGfloat color[] = {0,0,0,0}; - vgSetfv (VG_TILE_FILL_COLOR, 4, color); - } - break; - - case CAIRO_EXTEND_REPEAT: - vgSetParameteri (context->paint, - VG_PAINT_PATTERN_TILING_MODE, - VG_TILE_REPEAT); - break; - - default: - ASSERT_NOT_REACHED; - case CAIRO_EXTEND_REFLECT: - vgSetParameteri (context->paint, - VG_PAINT_PATTERN_TILING_MODE, - VG_TILE_REFLECT); - break; - } - vgPaintPattern (context->paint, context->source->image); - - _vg_set_source_matrix (&spat->base); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -setup_source (cairo_vg_context_t *context, - const cairo_pattern_t *source) -{ - switch (source->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return _vg_setup_solid_source (context, - (cairo_solid_pattern_t *) source); - case CAIRO_PATTERN_TYPE_LINEAR: - return _vg_setup_linear_source (context, - (cairo_linear_pattern_t *) source); - case CAIRO_PATTERN_TYPE_RADIAL: - return _vg_setup_radial_source (context, - (cairo_radial_pattern_t *) source); - case CAIRO_PATTERN_TYPE_SURFACE: - return _vg_setup_surface_source (context, - (cairo_surface_pattern_t *) source); - default: - ASSERT_NOT_REACHED; - return CAIRO_INT_STATUS_UNSUPPORTED; - } -} - -static cairo_int_status_t -_vg_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_vg_surface_t *surface = abstract_surface; - cairo_vg_context_t *context; - cairo_status_t status; - VGfloat state[9]; - VGfloat strokeTransform[9]; - vg_path_t vg_path; - - if (! _vg_is_supported_operator (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - context = _vg_context_lock (surface->context); - status = _vg_context_set_target (context, surface); - if (status) { - _vg_context_unlock (context); - return status; - } - - status = setup_source (context, source); - if (status) { - _vg_context_unlock (context); - return status; - } - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) { - _vg_context_unlock (context); - return status; - } - - vg_path.path = vgCreatePath (VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1, 0, 0, 0, - VG_PATH_CAPABILITY_ALL); - - vgGetMatrix (state); - _vg_matrix_from_cairo (strokeTransform, ctm); - vgMultMatrix (strokeTransform); - - vg_path.ctm_inverse = ctm_inverse; - - _vg_path_from_cairo (&vg_path, path); - - /* XXX DASH_PATTERN, DASH_PHASE */ - vgSetf (VG_STROKE_LINE_WIDTH, style->line_width); - vgSetf (VG_STROKE_MITER_LIMIT, style->miter_limit); - vgSetf (VG_STROKE_JOIN_STYLE, _vg_line_join_from_cairo (style->line_join)); - vgSetf (VG_STROKE_CAP_STYLE, _vg_line_cap_from_cairo (style->line_cap)); - - vgSeti (VG_BLEND_MODE, _vg_operator (op)); - - vgSetPaint (context->paint, VG_STROKE_PATH); - - vgDrawPath (vg_path.path, VG_STROKE_PATH); - - vgDestroyPath (vg_path.path); - - vgLoadMatrix (state); - - CHECK_VG_ERRORS(); - _vg_context_unlock (context); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_vg_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_vg_surface_t *surface = abstract_surface; - cairo_vg_context_t *context; - cairo_status_t status; - vg_path_t vg_path; - - if (op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (! _vg_is_supported_operator (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - context = _vg_context_lock (surface->context); - status = _vg_context_set_target (context, surface); - if (status) { - _vg_context_unlock (context); - return status; - } - - status = setup_source (context, source); - if (status) { - _vg_context_unlock (context); - return status; - } - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) { - _vg_context_unlock (context); - return status; - } - - vg_path.path = vgCreatePath (VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1, 0, - 0, 0, - VG_PATH_CAPABILITY_ALL); - vg_path.ctm_inverse = NULL; - - _vg_path_from_cairo (&vg_path, path); - - /* XXX tolerance */ - - vgSeti (VG_BLEND_MODE, _vg_operator (op)); - vgSetf (VG_FILL_RULE, _vg_fill_rule_from_cairo (fill_rule)); - vgSetf (VG_RENDERING_QUALITY, _vg_rendering_quality_from_cairo (antialias)); - - vgSetPaint (context->paint, VG_FILL_PATH); - - vgDrawPath (vg_path.path, VG_FILL_PATH); - - vgDestroyPath (vg_path.path); - - _vg_context_unlock (context); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_vg_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_vg_surface_t *surface = abstract_surface; - cairo_vg_context_t *context; - cairo_status_t status; - - if (op == CAIRO_OPERATOR_DEST) - return CAIRO_STATUS_SUCCESS; - - if (! _vg_is_supported_operator (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - context = _vg_context_lock (surface->context); - status = _vg_context_set_target (context, surface); - if (status) { - _vg_context_unlock (context); - return status; - } - - status = setup_source (context, source); - if (status) { - _vg_context_unlock (context); - return status; - } - - status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); - if (unlikely (status)) { - _vg_context_unlock (context); - return status; - } - - vgSeti (VG_BLEND_MODE, _vg_operator (op)); - vgSetPaint (context->paint, VG_FILL_PATH); - - { /* creating a rectangular path that should cover the extent */ - VGubyte segs[] = { - VG_MOVE_TO_ABS, VG_LINE_TO_ABS, - VG_LINE_TO_ABS, VG_LINE_TO_ABS, - VG_CLOSE_PATH - }; - VGfloat data[] = { - 0, 0, - surface->width, 0, - surface->width, surface->height, - 0, surface->height - }; - VGPath fullext; - - fullext = vgCreatePath (VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, - 1,0,0,0, VG_PATH_CAPABILITY_ALL); - vgAppendPathData (fullext, sizeof(segs), segs, data); - - vgDrawPath (fullext, VG_FILL_PATH); - - vgDestroyPath (fullext); - } - - _vg_context_unlock (context); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_vg_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_vg_surface_t *surface = abstract_surface; - cairo_status_t status; - - if (! _vg_is_supported_operator (op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Handle paint-with-alpha to do fades cheaply */ - if (mask->type == CAIRO_PATTERN_TYPE_SOLID) { - cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) mask; - cairo_vg_context_t *context = _vg_context_lock (surface->context); - double alpha = context->alpha; - - context->alpha = solid->color.alpha; - status = _vg_surface_paint (abstract_surface, op, source, clip); - context->alpha = alpha; - - _vg_context_unlock (context); - - return status; - } - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static void -_vg_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - _cairo_font_options_init_default (options); - - cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON); - _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); -} - -static cairo_int_status_t -_vg_surface_show_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_path_fixed_t path; - - if (num_glyphs <= 0) - return CAIRO_STATUS_SUCCESS; - - _cairo_path_fixed_init (&path); - - /* XXX Glyph cache! OpenVG font support in 1.1? */ - - status = _cairo_scaled_font_glyph_path (scaled_font, - glyphs, num_glyphs, - &path); - if (unlikely (status)) - goto BAIL; - - status = _vg_surface_fill (abstract_surface, - op, source, &path, - CAIRO_FILL_RULE_WINDING, - CAIRO_GSTATE_TOLERANCE_DEFAULT, - CAIRO_ANTIALIAS_DEFAULT, - clip); -BAIL: - _cairo_path_fixed_fini (&path); - return status; -} - -static inline int -multiply_alpha (int alpha, int color) -{ - int temp = alpha * color + 0x80; - return (temp + (temp >> 8)) >> 8; -} - -static void -premultiply_argb (uint8_t *data, - int width, - int height, - int stride) -{ - int i; - - while (height --) { - uint32_t *row = (uint32_t *) data; - - for (i = 0; i < width; i++) { - uint32_t p = row[i]; - uint8_t alpha; - - alpha = p >> 24; - if (alpha == 0) { - row[i] = 0; - } else if (alpha != 0xff) { - uint8_t r = multiply_alpha (alpha, (p >> 16) & 0xff); - uint8_t g = multiply_alpha (alpha, (p >> 8) & 0xff); - uint8_t b = multiply_alpha (alpha, (p >> 0) & 0xff); - row[i] = (alpha << 24) | (r << 16) | (g << 8) | (b << 0); - } - } - - data += stride; - } -} - -static cairo_int_status_t -_vg_get_image (cairo_vg_surface_t *surface, - int x, int y, - int width, int height, - cairo_image_surface_t **image_out) -{ - cairo_image_surface_t *image; - pixman_image_t *pixman_image; - pixman_format_code_t pixman_format; - cairo_bool_t needs_premultiply; - - pixman_format = _vg_format_to_pixman (surface->format, - &needs_premultiply); - if (pixman_format == 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - pixman_image = pixman_image_create_bits (pixman_format, - width, height, - NULL, 0); - if (unlikely (pixman_image == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - vgFinish (); - CHECK_VG_ERRORS(); - - vgGetImageSubData (surface->image, - pixman_image_get_data (pixman_image), - pixman_image_get_stride (pixman_image), - surface->format, - x, y, width, height); - - image = (cairo_image_surface_t *) - _cairo_image_surface_create_for_pixman_image (pixman_image, - pixman_format); - if (unlikely (image->base.status)) { - pixman_image_unref (pixman_image); - return image->base.status; - } - - if (needs_premultiply) - premultiply_argb (image->data, width, height, image->stride); - - *image_out = image; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_vg_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_vg_surface_t *surface = abstract_surface; - - CHECK_VG_ERRORS(); - *image_extra = NULL; - return _vg_get_image (surface, - 0, 0, surface->width, surface->height, - image_out); -} - -static void -_vg_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); -} - -static cairo_status_t -_vg_surface_finish (void *abstract_surface) -{ - cairo_vg_surface_t *surface = abstract_surface; - cairo_vg_context_t *context = _vg_context_lock (surface->context); - - if (surface->snapshot_cache_entry.hash) { - _cairo_cache_remove (&context->snapshot_cache, - &surface->snapshot_cache_entry); - - surface->snapshot_cache_entry.hash = 0; - } - - _cairo_surface_clipper_reset (&surface->clipper); - - if (surface->own_image) - vgDestroyImage (surface->image); - - _vg_context_destroy_target (context, surface); - - _vg_context_unlock (context); - _vg_context_destroy (context); - - CHECK_VG_ERRORS(); - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t cairo_vg_surface_backend = { - CAIRO_SURFACE_TYPE_VG, - _vg_surface_finish, - - _cairo_default_context_create, /* XXX */ - - _vg_surface_create_similar, - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - _vg_surface_acquire_source_image, - _vg_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _vg_surface_get_extents, - _vg_surface_get_font_options, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark dirty */ - - _vg_surface_paint, - _vg_surface_mask, - _vg_surface_stroke, - _vg_surface_fill, - NULL, /* fill-stroke */ - _vg_surface_show_glyphs, -}; - -static cairo_surface_t * -_vg_surface_create_internal (cairo_vg_context_t *context, - VGImage image, - VGImageFormat format, - int width, int height) -{ - cairo_vg_surface_t *surface; - - surface = malloc (sizeof (cairo_vg_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface->context = _vg_context_reference (context); - - surface->image = image; - surface->format = format; - - _cairo_surface_init (&surface->base, - &cairo_vg_surface_backend, - NULL, /* device */ - _vg_format_to_content (format)); - - surface->width = width; - surface->height = height; - - _cairo_surface_clipper_init (&surface->clipper, - _vg_surface_clipper_intersect_clip_path); - - surface->snapshot_cache_entry.hash = 0; - - surface->target_id = 0; - - CHECK_VG_ERRORS(); - return &surface->base; -} - -cairo_surface_t * -cairo_vg_surface_create_for_image (cairo_vg_context_t *context, - VGImage image, - VGImageFormat format, - int width, int height) -{ - cairo_bool_t premult; - - if (context->status) - return _cairo_surface_create_in_error (context->status); - - if (image == VG_INVALID_HANDLE) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - if (_vg_format_to_pixman (format, &premult) == 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - - return _vg_surface_create_internal (context, image, format, width, height); -} - -cairo_surface_t * -cairo_vg_surface_create (cairo_vg_context_t *context, - cairo_content_t content, - int width, - int height) -{ - VGImage image; - VGImageFormat format; - cairo_surface_t *surface; - - if (context->status) - return _cairo_surface_create_in_error (context->status); - - if (! CAIRO_CONTENT_VALID (content)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); - - if (width > vgGeti (VG_MAX_IMAGE_WIDTH) || - height > vgGeti (VG_MAX_IMAGE_HEIGHT)) - { - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - } - - - format = _vg_format_for_content (content); - image = vgCreateImage (format, width, height, VG_IMAGE_QUALITY_BETTER); - if (image == VG_INVALID_HANDLE) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface = _vg_surface_create_internal (context, - image, format, width, height); - if (unlikely (surface->status)) - return surface; - - ((cairo_vg_surface_t *) surface)->own_image = TRUE; - return surface; -} -slim_hidden_def (cairo_vg_surface_create); - -VGImage -cairo_vg_surface_get_image (cairo_surface_t *abstract_surface) -{ - cairo_vg_surface_t *surface; - - if (abstract_surface->backend != &cairo_vg_surface_backend) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return VG_INVALID_HANDLE; - } - - surface = (cairo_vg_surface_t *) abstract_surface; - return surface->image; -} - -int -cairo_vg_surface_get_width (cairo_surface_t *abstract_surface) -{ - cairo_vg_surface_t *surface; - - if (abstract_surface->backend != &cairo_vg_surface_backend) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - surface = (cairo_vg_surface_t *) abstract_surface; - return surface->width; -} - -int -cairo_vg_surface_get_height (cairo_surface_t *abstract_surface) -{ - cairo_vg_surface_t *surface; - - if (abstract_surface->backend != &cairo_vg_surface_backend) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - surface = (cairo_vg_surface_t *) abstract_surface; - return surface->height; -} - -VGImageFormat -cairo_vg_surface_get_format (cairo_surface_t *abstract_surface) -{ - cairo_vg_surface_t *surface; - - if (abstract_surface->backend != &cairo_vg_surface_backend) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - surface = (cairo_vg_surface_t *) abstract_surface; - return surface->format; -} - -/* GL specific context support :-( - * - * OpenVG like cairo defers creation of surface (and the necessary - * paraphernalia to the application. - */ - -static const cairo_vg_context_t _vg_context_nil = { - CAIRO_STATUS_NO_MEMORY, - CAIRO_REFERENCE_COUNT_INVALID -}; - -static const cairo_vg_context_t _vg_context_nil_invalid_visual = { - CAIRO_STATUS_INVALID_VISUAL, - CAIRO_REFERENCE_COUNT_INVALID -}; - -#if CAIRO_HAS_GLX_FUNCTIONS -#include - -static cairo_status_t -glx_create_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ - /* XXX hmm, magic required for creating an FBO points to VGImage! */ - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_status_t -glx_set_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ -#if 0 - glXMakeContextCurrent (context->display, - (GLXDrawable) surface->target_id, - (GLXDrawable) surface->target_id, - context->context); -#else - return CAIRO_INT_STATUS_UNSUPPORTED; -#endif -} - -static void -glx_destroy_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ -} - -cairo_vg_context_t * -cairo_vg_context_create_for_glx (Display *dpy, GLXContext ctx) -{ - cairo_vg_context_t *context; - cairo_status_t status; - - context = malloc (sizeof (*context)); - if (unlikely (context == NULL)) - return (cairo_vg_context_t *) &_vg_context_nil; - - context->display = dpy; - context->context = ctx; - - context->create_target = glx_create_target; - context->set_target = glx_set_target; - context->destroy_target = glx_destroy_target; - - status = _vg_context_init (context); - if (unlikely (status)) { - free (context); - return (cairo_vg_context_t *) &_vg_context_nil; - } - - return context; -} -#endif - -#if CAIRO_HAS_EGL_FUNCTIONS -static cairo_status_t -egl_create_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ - EGLSurface *egl_surface; -#define RED 1 -#define GREEN 3 -#define BLUE 5 -#define ALPHA 7 - int attribs[] = { - EGL_RED_SIZE, 0, - EGL_GREEN_SIZE, 0, - EGL_BLUE_SIZE, 0, - EGL_ALPHA_SIZE, 0, - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, - EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, - EGL_NONE - }; - pixman_format_code_t pixman_format; - EGLConfig config; - int num_configs = 0; - cairo_bool_t needs_premultiply; - - pixman_format = _vg_format_to_pixman (surface->format, &needs_premultiply); - if (pixman_format == 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* XXX no control over pixel ordering! */ - attribs[RED] = PIXMAN_FORMAT_R (pixman_format); - attribs[GREEN] = PIXMAN_FORMAT_G (pixman_format); - attribs[BLUE] = PIXMAN_FORMAT_B (pixman_format); - attribs[ALPHA] = PIXMAN_FORMAT_A (pixman_format); - - if (! eglChooseConfig (context->display, - attribs, - &config, 1, &num_configs) || - num_configs != 1) - { - fprintf(stderr, "Error: eglChooseConfig() failed.\n"); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - egl_surface = - eglCreatePbufferFromClientBuffer (context->display, - EGL_OPENVG_IMAGE, - (EGLClientBuffer) surface->image, - config, - NULL); - surface->target_id = (unsigned long) egl_surface; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -egl_set_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ - if (! eglMakeCurrent (context->display, - (EGLSurface *) surface->target_id, - (EGLSurface *) surface->target_id, - context->context)) - { - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - return CAIRO_STATUS_SUCCESS; -} - -static void -egl_destroy_target (cairo_vg_context_t *context, - cairo_vg_surface_t *surface) -{ - eglDestroySurface (context->display, - (EGLSurface *) surface->target_id); -} - -cairo_vg_context_t * -cairo_vg_context_create_for_egl (EGLDisplay egl_display, - EGLContext egl_context) -{ - cairo_vg_context_t *context; - cairo_status_t status; - - context = malloc (sizeof (*context)); - if (unlikely (context == NULL)) - return (cairo_vg_context_t *) &_vg_context_nil; - - status = _vg_context_init (context); - if (unlikely (status)) { - free (context); - return (cairo_vg_context_t *) &_vg_context_nil; - } - - context->display = egl_display; - context->context = egl_context; - - context->create_target = egl_create_target; - context->set_target = egl_set_target; - context->destroy_target = egl_destroy_target; - - return context; -} -#endif - -cairo_status_t -cairo_vg_context_status (cairo_vg_context_t *context) -{ - return context->status; -} - -void -cairo_vg_context_destroy (cairo_vg_context_t *context) -{ - if (context == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&context->ref_count)) - return; - - _vg_context_destroy (context); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg.h deleted file mode 100644 index f9a62e51c69..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-vg.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright 2007 * Mozilla Corporation - * Copyright 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Mozilla Corporation. - * - * Contributor(s): - * Vladimir Vukicevic - * Chris Wilson - */ - -#ifndef CAIRO_VG_H -#define CAIRO_VG_H - -#include "cairo.h" - -#if CAIRO_HAS_VG_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -typedef struct _cairo_vg_context cairo_vg_context_t; - -#if CAIRO_HAS_GLX_FUNCTIONS -typedef struct __GLXcontextRec *GLXContext; -typedef struct _XDisplay Display; - -cairo_public cairo_vg_context_t * -cairo_vg_context_create_for_glx (Display *dpy, - GLXContext ctx); -#endif - -#if CAIRO_HAS_EGL_FUNCTIONS -#include - -cairo_public cairo_vg_context_t * -cairo_vg_context_create_for_egl (EGLDisplay egl_display, - EGLContext egl_context); -#endif - -cairo_public cairo_status_t -cairo_vg_context_status (cairo_vg_context_t *context); - -cairo_public void -cairo_vg_context_destroy (cairo_vg_context_t *context); - -cairo_public cairo_surface_t * -cairo_vg_surface_create (cairo_vg_context_t *context, - cairo_content_t content, int width, int height); - -cairo_public cairo_surface_t * -cairo_vg_surface_create_for_image (cairo_vg_context_t *context, - VGImage image, - VGImageFormat format, - int width, int height); - -cairo_public VGImage -cairo_vg_surface_get_image (cairo_surface_t *abstract_surface); - -cairo_public VGImageFormat -cairo_vg_surface_get_format (cairo_surface_t *abstract_surface); - -cairo_public int -cairo_vg_surface_get_height (cairo_surface_t *abstract_surface); - -cairo_public int -cairo_vg_surface_get_width (cairo_surface_t *abstract_surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_VG_SURFACE*/ -# error Cairo was not compiled with support for the OpenVG backend -#endif /* CAIRO_HAS_VG_SURFACE*/ - -#endif /* CAIRO_VG_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wgl-context.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wgl-context.c deleted file mode 100644 index 48723744648..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wgl-context.c +++ /dev/null @@ -1,261 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Eric Anholt - * Copyright © 2009 Chris Wilson - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - * Chris Wilson - * Zoxc - */ - -#include "cairoint.h" - -#include "cairo-gl-private.h" - -#include "cairo-error-private.h" - -#define WIN32_LEAN_AND_MEAN -#include - -typedef struct _cairo_wgl_context { - cairo_gl_context_t base; - - HDC dummy_dc; - HWND dummy_wnd; - HGLRC rc; - - HDC prev_dc; - HGLRC prev_rc; -} cairo_wgl_context_t; - -typedef struct _cairo_wgl_surface { - cairo_gl_surface_t base; - - HDC dc; -} cairo_wgl_surface_t; - -static void -_wgl_acquire (void *abstract_ctx) -{ - cairo_wgl_context_t *ctx = abstract_ctx; - - HDC current_dc; - - ctx->prev_dc = wglGetCurrentDC (); - ctx->prev_rc = wglGetCurrentContext (); - - if (ctx->base.current_target == NULL || - _cairo_gl_surface_is_texture (ctx->base.current_target)) - { - current_dc = ctx->dummy_dc; - } - else - { - cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) ctx->base.current_target; - current_dc = surface->dc; - } - - if (ctx->prev_dc != current_dc || - (ctx->prev_rc != ctx->rc && - current_dc != ctx->dummy_dc)) - { - wglMakeCurrent (current_dc, ctx->rc); - } -} - -static void -_wgl_make_current (void *abstract_ctx, cairo_gl_surface_t *abstract_surface) -{ - cairo_wgl_context_t *ctx = abstract_ctx; - cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) abstract_surface; - - /* Set the window as the target of our context. */ - wglMakeCurrent (surface->dc, ctx->rc); -} - -static void -_wgl_release (void *abstract_ctx) -{ - cairo_wgl_context_t *ctx = abstract_ctx; - - if (ctx->prev_dc != wglGetCurrentDC () || - ctx->prev_rc != wglGetCurrentContext ()) - { - wglMakeCurrent (ctx->prev_dc, - ctx->prev_rc); - } -} - -static void -_wgl_swap_buffers (void *abstract_ctx, - cairo_gl_surface_t *abstract_surface) -{ - cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) abstract_surface; - - SwapBuffers (surface->dc); -} - -static void -_wgl_destroy (void *abstract_ctx) -{ - cairo_wgl_context_t *ctx = abstract_ctx; - - if (ctx->dummy_dc != 0) { - wglMakeCurrent (ctx->dummy_dc, 0); - ReleaseDC (ctx->dummy_wnd, ctx->dummy_dc); - DestroyWindow (ctx->dummy_wnd); - } -} - -static cairo_status_t -_wgl_dummy_ctx (cairo_wgl_context_t *ctx) -{ - WNDCLASSEXA wincl; - PIXELFORMATDESCRIPTOR pfd; - int format; - HDC dc; - - ZeroMemory (&wincl, sizeof (WNDCLASSEXA)); - wincl.cbSize = sizeof (WNDCLASSEXA); - wincl.hInstance = GetModuleHandle (0); - wincl.lpszClassName = "cairo_wgl_context_dummy"; - wincl.lpfnWndProc = DefWindowProcA; - wincl.style = CS_OWNDC; - - RegisterClassExA (&wincl); - - ctx->dummy_wnd = CreateWindowA ("cairo_wgl_context_dummy", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - ctx->dummy_dc = GetDC (ctx->dummy_wnd); - - ZeroMemory (&pfd, sizeof (PIXELFORMATDESCRIPTOR)); - pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cDepthBits = 16; - pfd.iLayerType = PFD_MAIN_PLANE; - - format = ChoosePixelFormat (ctx->dummy_dc, &pfd); - SetPixelFormat (ctx->dummy_dc, format, &pfd); - - wglMakeCurrent(ctx->dummy_dc, ctx->rc); - - return CAIRO_STATUS_SUCCESS; -} - -cairo_device_t * -cairo_wgl_device_create (HGLRC rc) -{ - cairo_wgl_context_t *ctx; - cairo_status_t status; - - ctx = calloc (1, sizeof (cairo_wgl_context_t)); - if (unlikely (ctx == NULL)) - return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); - - ctx->rc = rc; - ctx->prev_dc = 0; - ctx->prev_rc = 0; - - status = _wgl_dummy_ctx (ctx); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - ctx->base.acquire = _wgl_acquire; - ctx->base.release = _wgl_release; - ctx->base.make_current = _wgl_make_current; - ctx->base.swap_buffers = _wgl_swap_buffers; - ctx->base.destroy = _wgl_destroy; - - status = _cairo_gl_dispatch_init (&ctx->base.dispatch, - (cairo_gl_get_proc_addr_func_t) wglGetProcAddress); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - status = _cairo_gl_context_init (&ctx->base); - if (unlikely (status)) { - free (ctx); - return _cairo_gl_context_create_in_error (status); - } - - ctx->base.release (ctx); - - return &ctx->base.base; -} - -HGLRC -cairo_wgl_device_get_context (cairo_device_t *device) -{ - cairo_wgl_context_t *ctx; - - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { - _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - return NULL; - } - - ctx = (cairo_wgl_context_t *) device; - - return ctx->rc; -} - -cairo_surface_t * -cairo_gl_surface_create_for_dc (cairo_device_t *device, - HDC dc, - int width, - int height) -{ - cairo_wgl_surface_t *surface; - - if (unlikely (device->status)) - return _cairo_surface_create_in_error (device->status); - - if (device->backend->type != CAIRO_DEVICE_TYPE_GL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - - if (width <= 0 || height <= 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - surface = calloc (1, sizeof (cairo_wgl_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_gl_surface_init (device, &surface->base, - CAIRO_CONTENT_COLOR_ALPHA, width, height); - surface->dc = dc; - - return &surface->base.base; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-private.h deleted file mode 100644 index 3f5491bb1c0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-private.h +++ /dev/null @@ -1,338 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Keith Packard - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith R. Packard - * - */ - -#ifndef CAIRO_WIDEINT_H -#define CAIRO_WIDEINT_H - -#include "cairo-wideint-type-private.h" - -#include "cairo-compiler-private.h" - -/* - * 64-bit datatypes. Two separate implementations, one using - * built-in 64-bit signed/unsigned types another implemented - * as a pair of 32-bit ints - */ - -#define I cairo_private cairo_const - -#if !HAVE_UINT64_T - -cairo_uquorem64_t I -_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den); - -cairo_uint64_t I _cairo_double_to_uint64 (double i); -double I _cairo_uint64_to_double (cairo_uint64_t i); -cairo_int64_t I _cairo_double_to_int64 (double i); -double I _cairo_int64_to_double (cairo_uint64_t i); - -cairo_uint64_t I _cairo_uint32_to_uint64 (uint32_t i); -#define _cairo_uint64_to_uint32(a) ((a).lo) -cairo_uint64_t I _cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b); -cairo_uint64_t I _cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b); -cairo_uint64_t I _cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b); -cairo_uint64_t I _cairo_uint32x32_64_mul (uint32_t a, uint32_t b); -cairo_uint64_t I _cairo_uint64_lsl (cairo_uint64_t a, int shift); -cairo_uint64_t I _cairo_uint64_rsl (cairo_uint64_t a, int shift); -cairo_uint64_t I _cairo_uint64_rsa (cairo_uint64_t a, int shift); -int I _cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b); -int I _cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b); -int I _cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b); -cairo_uint64_t I _cairo_uint64_negate (cairo_uint64_t a); -#define _cairo_uint64_is_zero(a) ((a).hi == 0 && (a).lo == 0) -#define _cairo_uint64_negative(a) (((int32_t) ((a).hi)) < 0) -cairo_uint64_t I _cairo_uint64_not (cairo_uint64_t a); - -#define _cairo_uint64_to_int64(i) (i) -#define _cairo_int64_to_uint64(i) (i) - -cairo_int64_t I _cairo_int32_to_int64(int32_t i); -#define _cairo_int64_to_int32(a) ((int32_t) _cairo_uint64_to_uint32(a)) -#define _cairo_int64_add(a,b) _cairo_uint64_add (a,b) -#define _cairo_int64_sub(a,b) _cairo_uint64_sub (a,b) -#define _cairo_int64_mul(a,b) _cairo_uint64_mul (a,b) -cairo_int64_t I _cairo_int32x32_64_mul (int32_t a, int32_t b); -int I _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b); -int I _cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b); -#define _cairo_int64_is_zero(a) _cairo_uint64_is_zero (a) -#define _cairo_int64_eq(a,b) _cairo_uint64_eq (a,b) -#define _cairo_int64_lsl(a,b) _cairo_uint64_lsl (a,b) -#define _cairo_int64_rsl(a,b) _cairo_uint64_rsl (a,b) -#define _cairo_int64_rsa(a,b) _cairo_uint64_rsa (a,b) -#define _cairo_int64_negate(a) _cairo_uint64_negate(a) -#define _cairo_int64_negative(a) (((int32_t) ((a).hi)) < 0) -#define _cairo_int64_not(a) _cairo_uint64_not(a) - -#else - -static inline cairo_uquorem64_t -_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den) -{ - cairo_uquorem64_t qr; - - qr.quo = num / den; - qr.rem = num % den; - return qr; -} - -/* - * These need to be functions or gcc will complain when used on the - * result of a function: - * - * warning: cast from function call of type ‘#cairo_uint64_t’ to - * non-matching type ‘double’ - */ -static cairo_always_inline cairo_const cairo_uint64_t _cairo_double_to_uint64 (double i) { return i; } -static cairo_always_inline cairo_const double _cairo_uint64_to_double (cairo_uint64_t i) { return i; } - -static cairo_always_inline cairo_int64_t I _cairo_double_to_int64 (double i) { return i; } -static cairo_always_inline double I _cairo_int64_to_double (cairo_int64_t i) { return i; } - -#define _cairo_uint32_to_uint64(i) ((uint64_t) (i)) -#define _cairo_uint64_to_uint32(i) ((uint32_t) (i)) -#define _cairo_uint64_add(a,b) ((a) + (b)) -#define _cairo_uint64_sub(a,b) ((a) - (b)) -#define _cairo_uint64_mul(a,b) ((a) * (b)) -#define _cairo_uint32x32_64_mul(a,b) ((uint64_t) (a) * (b)) -#define _cairo_uint64_lsl(a,b) ((a) << (b)) -#define _cairo_uint64_rsl(a,b) ((uint64_t) (a) >> (b)) -#define _cairo_uint64_rsa(a,b) ((uint64_t) ((int64_t) (a) >> (b))) -#define _cairo_uint64_lt(a,b) ((a) < (b)) -#define _cairo_uint64_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) -#define _cairo_uint64_is_zero(a) ((a) == 0) -#define _cairo_uint64_eq(a,b) ((a) == (b)) -#define _cairo_uint64_negate(a) ((uint64_t) -((int64_t) (a))) -#define _cairo_uint64_negative(a) ((int64_t) (a) < 0) -#define _cairo_uint64_not(a) (~(a)) - -#define _cairo_uint64_to_int64(i) ((int64_t) (i)) -#define _cairo_int64_to_uint64(i) ((uint64_t) (i)) - -#define _cairo_int32_to_int64(i) ((int64_t) (i)) -#define _cairo_int64_to_int32(i) ((int32_t) (i)) -#define _cairo_int64_add(a,b) ((a) + (b)) -#define _cairo_int64_sub(a,b) ((a) - (b)) -#define _cairo_int64_mul(a,b) ((a) * (b)) -#define _cairo_int32x32_64_mul(a,b) ((int64_t) (a) * (b)) -#define _cairo_int64_lt(a,b) ((a) < (b)) -#define _cairo_int64_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) -#define _cairo_int64_is_zero(a) ((a) == 0) -#define _cairo_int64_eq(a,b) ((a) == (b)) -#define _cairo_int64_lsl(a,b) ((a) << (b)) -#define _cairo_int64_rsl(a,b) ((int64_t) ((uint64_t) (a) >> (b))) -#define _cairo_int64_rsa(a,b) ((int64_t) (a) >> (b)) -#define _cairo_int64_negate(a) (-(a)) -#define _cairo_int64_negative(a) ((a) < 0) -#define _cairo_int64_not(a) (~(a)) - -#endif - -/* - * 64-bit comparisons derived from lt or eq - */ -#define _cairo_uint64_le(a,b) (!_cairo_uint64_gt(a,b)) -#define _cairo_uint64_ne(a,b) (!_cairo_uint64_eq(a,b)) -#define _cairo_uint64_ge(a,b) (!_cairo_uint64_lt(a,b)) -#define _cairo_uint64_gt(a,b) _cairo_uint64_lt(b,a) - -#define _cairo_int64_le(a,b) (!_cairo_int64_gt(a,b)) -#define _cairo_int64_ne(a,b) (!_cairo_int64_eq(a,b)) -#define _cairo_int64_ge(a,b) (!_cairo_int64_lt(a,b)) -#define _cairo_int64_gt(a,b) _cairo_int64_lt(b,a) - -/* - * As the C implementation always computes both, create - * a function which returns both for the 'native' type as well - */ - -static inline cairo_quorem64_t -_cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den) -{ - int num_neg = _cairo_int64_negative (num); - int den_neg = _cairo_int64_negative (den); - cairo_uquorem64_t uqr; - cairo_quorem64_t qr; - - if (num_neg) - num = _cairo_int64_negate (num); - if (den_neg) - den = _cairo_int64_negate (den); - uqr = _cairo_uint64_divrem (num, den); - if (num_neg) - qr.rem = _cairo_int64_negate (uqr.rem); - else - qr.rem = uqr.rem; - if (num_neg != den_neg) - qr.quo = (cairo_int64_t) _cairo_int64_negate (uqr.quo); - else - qr.quo = (cairo_int64_t) uqr.quo; - return qr; -} - -static inline int32_t -_cairo_int64_32_div (cairo_int64_t num, int32_t den) -{ -#if !HAVE_UINT64_T - return _cairo_int64_to_int32 - (_cairo_int64_divrem (num, _cairo_int32_to_int64 (den)).quo); -#else - return num / den; -#endif -} - -/* - * 128-bit datatypes. Again, provide two implementations in - * case the machine has a native 128-bit datatype. GCC supports int128_t - * on ia64 - */ - -#if !HAVE_UINT128_T - -cairo_uint128_t I _cairo_uint32_to_uint128 (uint32_t i); -cairo_uint128_t I _cairo_uint64_to_uint128 (cairo_uint64_t i); -#define _cairo_uint128_to_uint64(a) ((a).lo) -#define _cairo_uint128_to_uint32(a) _cairo_uint64_to_uint32(_cairo_uint128_to_uint64(a)) -cairo_uint128_t I _cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b); -cairo_uint128_t I _cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b); -cairo_uint128_t I _cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b); -cairo_uint128_t I _cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b); -cairo_uint128_t I _cairo_uint128_lsl (cairo_uint128_t a, int shift); -cairo_uint128_t I _cairo_uint128_rsl (cairo_uint128_t a, int shift); -cairo_uint128_t I _cairo_uint128_rsa (cairo_uint128_t a, int shift); -int I _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b); -int I _cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b); -int I _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b); -#define _cairo_uint128_is_zero(a) (_cairo_uint64_is_zero ((a).hi) && _cairo_uint64_is_zero ((a).lo)) -cairo_uint128_t I _cairo_uint128_negate (cairo_uint128_t a); -#define _cairo_uint128_negative(a) (_cairo_uint64_negative(a.hi)) -cairo_uint128_t I _cairo_uint128_not (cairo_uint128_t a); - -#define _cairo_uint128_to_int128(i) (i) -#define _cairo_int128_to_uint128(i) (i) - -cairo_int128_t I _cairo_int32_to_int128 (int32_t i); -cairo_int128_t I _cairo_int64_to_int128 (cairo_int64_t i); -#define _cairo_int128_to_int64(a) ((cairo_int64_t) (a).lo) -#define _cairo_int128_to_int32(a) _cairo_int64_to_int32(_cairo_int128_to_int64(a)) -#define _cairo_int128_add(a,b) _cairo_uint128_add(a,b) -#define _cairo_int128_sub(a,b) _cairo_uint128_sub(a,b) -#define _cairo_int128_mul(a,b) _cairo_uint128_mul(a,b) -cairo_int128_t I _cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b); -#define _cairo_int64x32_128_mul(a, b) _cairo_int64x64_128_mul(a, _cairo_int32_to_int64(b)) -#define _cairo_int128_lsl(a,b) _cairo_uint128_lsl(a,b) -#define _cairo_int128_rsl(a,b) _cairo_uint128_rsl(a,b) -#define _cairo_int128_rsa(a,b) _cairo_uint128_rsa(a,b) -int I _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b); -int I _cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b); -#define _cairo_int128_is_zero(a) _cairo_uint128_is_zero (a) -#define _cairo_int128_eq(a,b) _cairo_uint128_eq (a,b) -#define _cairo_int128_negate(a) _cairo_uint128_negate(a) -#define _cairo_int128_negative(a) (_cairo_uint128_negative(a)) -#define _cairo_int128_not(a) _cairo_uint128_not(a) - -#else /* !HAVE_UINT128_T */ - -#define _cairo_uint32_to_uint128(i) ((uint128_t) (i)) -#define _cairo_uint64_to_uint128(i) ((uint128_t) (i)) -#define _cairo_uint128_to_uint64(i) ((uint64_t) (i)) -#define _cairo_uint128_to_uint32(i) ((uint32_t) (i)) -#define _cairo_uint128_add(a,b) ((a) + (b)) -#define _cairo_uint128_sub(a,b) ((a) - (b)) -#define _cairo_uint128_mul(a,b) ((a) * (b)) -#define _cairo_uint64x64_128_mul(a,b) ((uint128_t) (a) * (b)) -#define _cairo_uint128_lsl(a,b) ((a) << (b)) -#define _cairo_uint128_rsl(a,b) ((uint128_t) (a) >> (b)) -#define _cairo_uint128_rsa(a,b) ((uint128_t) ((int128_t) (a) >> (b))) -#define _cairo_uint128_lt(a,b) ((a) < (b)) -#define _cairo_uint128_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) -#define _cairo_uint128_is_zero(a) ((a) == 0) -#define _cairo_uint128_eq(a,b) ((a) == (b)) -#define _cairo_uint128_negate(a) ((uint128_t) -((int128_t) (a))) -#define _cairo_uint128_negative(a) ((int128_t) (a) < 0) -#define _cairo_uint128_not(a) (~(a)) - -#define _cairo_uint128_to_int128(i) ((int128_t) (i)) -#define _cairo_int128_to_uint128(i) ((uint128_t) (i)) - -#define _cairo_int32_to_int128(i) ((int128_t) (i)) -#define _cairo_int64_to_int128(i) ((int128_t) (i)) -#define _cairo_int128_to_int64(i) ((int64_t) (i)) -#define _cairo_int128_to_int32(i) ((int32_t) (i)) -#define _cairo_int128_add(a,b) ((a) + (b)) -#define _cairo_int128_sub(a,b) ((a) - (b)) -#define _cairo_int128_mul(a,b) ((a) * (b)) -#define _cairo_int64x64_128_mul(a,b) ((int128_t) (a) * (b)) -#define _cairo_int64x32_128_mul(a, b) _cairo_int64x64_128_mul(a, _cairo_int32_to_int64(b)) -#define _cairo_int128_lt(a,b) ((a) < (b)) -#define _cairo_int128_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) -#define _cairo_int128_is_zero(a) ((a) == 0) -#define _cairo_int128_eq(a,b) ((a) == (b)) -#define _cairo_int128_lsl(a,b) ((a) << (b)) -#define _cairo_int128_rsl(a,b) ((int128_t) ((uint128_t) (a) >> (b))) -#define _cairo_int128_rsa(a,b) ((int128_t) (a) >> (b)) -#define _cairo_int128_negate(a) (-(a)) -#define _cairo_int128_negative(a) ((a) < 0) -#define _cairo_int128_not(a) (~(a)) - -#endif /* HAVE_UINT128_T */ - -cairo_uquorem128_t I -_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den); - -cairo_quorem128_t I -_cairo_int128_divrem (cairo_int128_t num, cairo_int128_t den); - -cairo_uquorem64_t I -_cairo_uint_96by64_32x64_divrem (cairo_uint128_t num, - cairo_uint64_t den); - -cairo_quorem64_t I -_cairo_int_96by64_32x64_divrem (cairo_int128_t num, - cairo_int64_t den); - -#define _cairo_uint128_le(a,b) (!_cairo_uint128_gt(a,b)) -#define _cairo_uint128_ne(a,b) (!_cairo_uint128_eq(a,b)) -#define _cairo_uint128_ge(a,b) (!_cairo_uint128_lt(a,b)) -#define _cairo_uint128_gt(a,b) _cairo_uint128_lt(b,a) - -#define _cairo_int128_le(a,b) (!_cairo_int128_gt(a,b)) -#define _cairo_int128_ne(a,b) (!_cairo_int128_eq(a,b)) -#define _cairo_int128_ge(a,b) (!_cairo_int128_lt(a,b)) -#define _cairo_int128_gt(a,b) _cairo_int128_lt(b,a) - -#undef I - -#endif /* CAIRO_WIDEINT_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-type-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-type-private.h deleted file mode 100644 index 84a3cbab0d2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint-type-private.h +++ /dev/null @@ -1,158 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Keith Packard - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith R. Packard - * - */ - -#ifndef CAIRO_WIDEINT_TYPE_H -#define CAIRO_WIDEINT_TYPE_H - -#include "cairo.h" - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#if HAVE_STDINT_H -# include -#elif HAVE_INTTYPES_H -# include -#elif HAVE_SYS_INT_TYPES_H -# include -#elif defined(_MSC_VER) - typedef __int8 int8_t; - typedef unsigned __int8 uint8_t; - typedef __int16 int16_t; - typedef unsigned __int16 uint16_t; - typedef __int32 int32_t; - typedef unsigned __int32 uint32_t; - typedef __int64 int64_t; - typedef unsigned __int64 uint64_t; -# ifndef HAVE_UINT64_T -# define HAVE_UINT64_T 1 -# endif -#else -#error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.) -#endif - -#ifndef INT16_MIN -# define INT16_MIN (-32767-1) -#endif -#ifndef INT16_MAX -# define INT16_MAX (32767) -#endif -#ifndef UINT16_MAX -# define UINT16_MAX (65535) -#endif -#ifndef INT32_MIN -# define INT32_MIN (-2147483647-1) -#endif -#ifndef INT32_MAX -# define INT32_MAX (2147483647) -#endif -#ifndef UINT32_MAX -# define UINT32_MAX (4294967295U) -#endif - -#if HAVE_BYTESWAP_H -# include -#endif -#ifndef bswap_16 -# define bswap_16(p) \ - (((((uint16_t)(p)) & 0x00ff) << 8) | \ - (((uint16_t)(p)) >> 8)); -#endif -#ifndef bswap_32 -# define bswap_32(p) \ - (((((uint32_t)(p)) & 0x000000ff) << 24) | \ - ((((uint32_t)(p)) & 0x0000ff00) << 8) | \ - ((((uint32_t)(p)) & 0x00ff0000) >> 8) | \ - ((((uint32_t)(p))) >> 24)); -#endif - - -#if !HAVE_UINT64_T - -typedef struct _cairo_uint64 { - uint32_t lo, hi; -} cairo_uint64_t, cairo_int64_t; - -#else - -typedef uint64_t cairo_uint64_t; -typedef int64_t cairo_int64_t; - -#endif - -typedef struct _cairo_uquorem64 { - cairo_uint64_t quo; - cairo_uint64_t rem; -} cairo_uquorem64_t; - -typedef struct _cairo_quorem64 { - cairo_int64_t quo; - cairo_int64_t rem; -} cairo_quorem64_t; - -/* gcc has a non-standard name. */ -#if HAVE___UINT128_T && !HAVE_UINT128_T -typedef __uint128_t uint128_t; -typedef __int128_t int128_t; -#define HAVE_UINT128_T 1 -#endif - -#if !HAVE_UINT128_T - -typedef struct cairo_uint128 { - cairo_uint64_t lo, hi; -} cairo_uint128_t, cairo_int128_t; - -#else - -typedef uint128_t cairo_uint128_t; -typedef int128_t cairo_int128_t; - -#endif - -typedef struct _cairo_uquorem128 { - cairo_uint128_t quo; - cairo_uint128_t rem; -} cairo_uquorem128_t; - -typedef struct _cairo_quorem128 { - cairo_int128_t quo; - cairo_int128_t rem; -} cairo_quorem128_t; - - -#endif /* CAIRO_WIDEINT_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint.c deleted file mode 100644 index 2e056fa36a2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-wideint.c +++ /dev/null @@ -1,852 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2004 Keith Packard - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Keith Packard - * - * Contributor(s): - * Keith R. Packard - */ - -#include "cairoint.h" - -#if HAVE_UINT64_T - -#define uint64_lo32(i) ((i) & 0xffffffff) -#define uint64_hi32(i) ((i) >> 32) -#define uint64_lo(i) ((i) & 0xffffffff) -#define uint64_hi(i) ((i) >> 32) -#define uint64_shift32(i) ((i) << 32) -#define uint64_carry32 (((uint64_t) 1) << 32) - -#define _cairo_uint32s_to_uint64(h,l) ((uint64_t) (h) << 32 | (l)) - -#else - -#define uint64_lo32(i) ((i).lo) -#define uint64_hi32(i) ((i).hi) - -static cairo_uint64_t -uint64_lo (cairo_uint64_t i) -{ - cairo_uint64_t s; - - s.lo = i.lo; - s.hi = 0; - return s; -} - -static cairo_uint64_t -uint64_hi (cairo_uint64_t i) -{ - cairo_uint64_t s; - - s.lo = i.hi; - s.hi = 0; - return s; -} - -static cairo_uint64_t -uint64_shift32 (cairo_uint64_t i) -{ - cairo_uint64_t s; - - s.lo = 0; - s.hi = i.lo; - return s; -} - -static const cairo_uint64_t uint64_carry32 = { 0, 1 }; - -cairo_uint64_t -_cairo_double_to_uint64 (double i) -{ - cairo_uint64_t q; - - q.hi = i * (1. / 4294967296.); - q.lo = i - q.hi * 4294967296.; - return q; -} - -double -_cairo_uint64_to_double (cairo_uint64_t i) -{ - return i.hi * 4294967296. + i.lo; -} - -cairo_int64_t -_cairo_double_to_int64 (double i) -{ - cairo_uint64_t q; - - q.hi = i * (1. / INT32_MAX); - q.lo = i - q.hi * (double)INT32_MAX; - return q; -} - -double -_cairo_int64_to_double (cairo_int64_t i) -{ - return i.hi * INT32_MAX + i.lo; -} - -cairo_uint64_t -_cairo_uint32_to_uint64 (uint32_t i) -{ - cairo_uint64_t q; - - q.lo = i; - q.hi = 0; - return q; -} - -cairo_int64_t -_cairo_int32_to_int64 (int32_t i) -{ - cairo_uint64_t q; - - q.lo = i; - q.hi = i < 0 ? -1 : 0; - return q; -} - -static cairo_uint64_t -_cairo_uint32s_to_uint64 (uint32_t h, uint32_t l) -{ - cairo_uint64_t q; - - q.lo = l; - q.hi = h; - return q; -} - -cairo_uint64_t -_cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b) -{ - cairo_uint64_t s; - - s.hi = a.hi + b.hi; - s.lo = a.lo + b.lo; - if (s.lo < a.lo) - s.hi++; - return s; -} - -cairo_uint64_t -_cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b) -{ - cairo_uint64_t s; - - s.hi = a.hi - b.hi; - s.lo = a.lo - b.lo; - if (s.lo > a.lo) - s.hi--; - return s; -} - -#define uint32_lo(i) ((i) & 0xffff) -#define uint32_hi(i) ((i) >> 16) -#define uint32_carry16 ((1) << 16) - -cairo_uint64_t -_cairo_uint32x32_64_mul (uint32_t a, uint32_t b) -{ - cairo_uint64_t s; - - uint16_t ah, al, bh, bl; - uint32_t r0, r1, r2, r3; - - al = uint32_lo (a); - ah = uint32_hi (a); - bl = uint32_lo (b); - bh = uint32_hi (b); - - r0 = (uint32_t) al * bl; - r1 = (uint32_t) al * bh; - r2 = (uint32_t) ah * bl; - r3 = (uint32_t) ah * bh; - - r1 += uint32_hi(r0); /* no carry possible */ - r1 += r2; /* but this can carry */ - if (r1 < r2) /* check */ - r3 += uint32_carry16; - - s.hi = r3 + uint32_hi(r1); - s.lo = (uint32_lo (r1) << 16) + uint32_lo (r0); - return s; -} - -cairo_int64_t -_cairo_int32x32_64_mul (int32_t a, int32_t b) -{ - cairo_int64_t s; - s = _cairo_uint32x32_64_mul ((uint32_t) a, (uint32_t) b); - if (a < 0) - s.hi -= b; - if (b < 0) - s.hi -= a; - return s; -} - -cairo_uint64_t -_cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b) -{ - cairo_uint64_t s; - - s = _cairo_uint32x32_64_mul (a.lo, b.lo); - s.hi += a.lo * b.hi + a.hi * b.lo; - return s; -} - -cairo_uint64_t -_cairo_uint64_lsl (cairo_uint64_t a, int shift) -{ - if (shift >= 32) - { - a.hi = a.lo; - a.lo = 0; - shift -= 32; - } - if (shift) - { - a.hi = a.hi << shift | a.lo >> (32 - shift); - a.lo = a.lo << shift; - } - return a; -} - -cairo_uint64_t -_cairo_uint64_rsl (cairo_uint64_t a, int shift) -{ - if (shift >= 32) - { - a.lo = a.hi; - a.hi = 0; - shift -= 32; - } - if (shift) - { - a.lo = a.lo >> shift | a.hi << (32 - shift); - a.hi = a.hi >> shift; - } - return a; -} - -#define _cairo_uint32_rsa(a,n) ((uint32_t) (((int32_t) (a)) >> (n))) - -cairo_int64_t -_cairo_uint64_rsa (cairo_int64_t a, int shift) -{ - if (shift >= 32) - { - a.lo = a.hi; - a.hi = _cairo_uint32_rsa (a.hi, 31); - shift -= 32; - } - if (shift) - { - a.lo = a.lo >> shift | a.hi << (32 - shift); - a.hi = _cairo_uint32_rsa (a.hi, shift); - } - return a; -} - -int -_cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b) -{ - return (a.hi < b.hi || - (a.hi == b.hi && a.lo < b.lo)); -} - -int -_cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b) -{ - return a.hi == b.hi && a.lo == b.lo; -} - -int -_cairo_int64_lt (cairo_int64_t a, cairo_int64_t b) -{ - if (_cairo_int64_negative (a) && !_cairo_int64_negative (b)) - return 1; - if (!_cairo_int64_negative (a) && _cairo_int64_negative (b)) - return 0; - return _cairo_uint64_lt (a, b); -} - -int -_cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b) -{ - if (a.hi < b.hi) - return -1; - else if (a.hi > b.hi) - return 1; - else if (a.lo < b.lo) - return -1; - else if (a.lo > b.lo) - return 1; - else - return 0; -} - -int -_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b) -{ - if (_cairo_int64_negative (a) && !_cairo_int64_negative (b)) - return -1; - if (!_cairo_int64_negative (a) && _cairo_int64_negative (b)) - return 1; - - return _cairo_uint64_cmp (a, b); -} - -cairo_uint64_t -_cairo_uint64_not (cairo_uint64_t a) -{ - a.lo = ~a.lo; - a.hi = ~a.hi; - return a; -} - -cairo_uint64_t -_cairo_uint64_negate (cairo_uint64_t a) -{ - a.lo = ~a.lo; - a.hi = ~a.hi; - if (++a.lo == 0) - ++a.hi; - return a; -} - -/* - * Simple bit-at-a-time divide. - */ -cairo_uquorem64_t -_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den) -{ - cairo_uquorem64_t qr; - cairo_uint64_t bit; - cairo_uint64_t quo; - - bit = _cairo_uint32_to_uint64 (1); - - /* normalize to make den >= num, but not overflow */ - while (_cairo_uint64_lt (den, num) && (den.hi & 0x80000000) == 0) - { - bit = _cairo_uint64_lsl (bit, 1); - den = _cairo_uint64_lsl (den, 1); - } - quo = _cairo_uint32_to_uint64 (0); - - /* generate quotient, one bit at a time */ - while (bit.hi | bit.lo) - { - if (_cairo_uint64_le (den, num)) - { - num = _cairo_uint64_sub (num, den); - quo = _cairo_uint64_add (quo, bit); - } - bit = _cairo_uint64_rsl (bit, 1); - den = _cairo_uint64_rsl (den, 1); - } - qr.quo = quo; - qr.rem = num; - return qr; -} - -#endif /* !HAVE_UINT64_T */ - -#if HAVE_UINT128_T -cairo_uquorem128_t -_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den) -{ - cairo_uquorem128_t qr; - - qr.quo = num / den; - qr.rem = num % den; - return qr; -} - -#else - -cairo_uint128_t -_cairo_uint32_to_uint128 (uint32_t i) -{ - cairo_uint128_t q; - - q.lo = _cairo_uint32_to_uint64 (i); - q.hi = _cairo_uint32_to_uint64 (0); - return q; -} - -cairo_int128_t -_cairo_int32_to_int128 (int32_t i) -{ - cairo_int128_t q; - - q.lo = _cairo_int32_to_int64 (i); - q.hi = _cairo_int32_to_int64 (i < 0 ? -1 : 0); - return q; -} - -cairo_uint128_t -_cairo_uint64_to_uint128 (cairo_uint64_t i) -{ - cairo_uint128_t q; - - q.lo = i; - q.hi = _cairo_uint32_to_uint64 (0); - return q; -} - -cairo_int128_t -_cairo_int64_to_int128 (cairo_int64_t i) -{ - cairo_int128_t q; - - q.lo = i; - q.hi = _cairo_int32_to_int64 (_cairo_int64_negative(i) ? -1 : 0); - return q; -} - -cairo_uint128_t -_cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b) -{ - cairo_uint128_t s; - - s.hi = _cairo_uint64_add (a.hi, b.hi); - s.lo = _cairo_uint64_add (a.lo, b.lo); - if (_cairo_uint64_lt (s.lo, a.lo)) - s.hi = _cairo_uint64_add (s.hi, _cairo_uint32_to_uint64 (1)); - return s; -} - -cairo_uint128_t -_cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b) -{ - cairo_uint128_t s; - - s.hi = _cairo_uint64_sub (a.hi, b.hi); - s.lo = _cairo_uint64_sub (a.lo, b.lo); - if (_cairo_uint64_gt (s.lo, a.lo)) - s.hi = _cairo_uint64_sub (s.hi, _cairo_uint32_to_uint64(1)); - return s; -} - -cairo_uint128_t -_cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b) -{ - cairo_uint128_t s; - uint32_t ah, al, bh, bl; - cairo_uint64_t r0, r1, r2, r3; - - al = uint64_lo32 (a); - ah = uint64_hi32 (a); - bl = uint64_lo32 (b); - bh = uint64_hi32 (b); - - r0 = _cairo_uint32x32_64_mul (al, bl); - r1 = _cairo_uint32x32_64_mul (al, bh); - r2 = _cairo_uint32x32_64_mul (ah, bl); - r3 = _cairo_uint32x32_64_mul (ah, bh); - - r1 = _cairo_uint64_add (r1, uint64_hi (r0)); /* no carry possible */ - r1 = _cairo_uint64_add (r1, r2); /* but this can carry */ - if (_cairo_uint64_lt (r1, r2)) /* check */ - r3 = _cairo_uint64_add (r3, uint64_carry32); - - s.hi = _cairo_uint64_add (r3, uint64_hi(r1)); - s.lo = _cairo_uint64_add (uint64_shift32 (r1), - uint64_lo (r0)); - return s; -} - -cairo_int128_t -_cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b) -{ - cairo_int128_t s; - s = _cairo_uint64x64_128_mul (_cairo_int64_to_uint64(a), - _cairo_int64_to_uint64(b)); - if (_cairo_int64_negative (a)) - s.hi = _cairo_uint64_sub (s.hi, - _cairo_int64_to_uint64 (b)); - if (_cairo_int64_negative (b)) - s.hi = _cairo_uint64_sub (s.hi, - _cairo_int64_to_uint64 (a)); - return s; -} - -cairo_uint128_t -_cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b) -{ - cairo_uint128_t s; - - s = _cairo_uint64x64_128_mul (a.lo, b.lo); - s.hi = _cairo_uint64_add (s.hi, - _cairo_uint64_mul (a.lo, b.hi)); - s.hi = _cairo_uint64_add (s.hi, - _cairo_uint64_mul (a.hi, b.lo)); - return s; -} - -cairo_uint128_t -_cairo_uint128_lsl (cairo_uint128_t a, int shift) -{ - if (shift >= 64) - { - a.hi = a.lo; - a.lo = _cairo_uint32_to_uint64 (0); - shift -= 64; - } - if (shift) - { - a.hi = _cairo_uint64_add (_cairo_uint64_lsl (a.hi, shift), - _cairo_uint64_rsl (a.lo, (64 - shift))); - a.lo = _cairo_uint64_lsl (a.lo, shift); - } - return a; -} - -cairo_uint128_t -_cairo_uint128_rsl (cairo_uint128_t a, int shift) -{ - if (shift >= 64) - { - a.lo = a.hi; - a.hi = _cairo_uint32_to_uint64 (0); - shift -= 64; - } - if (shift) - { - a.lo = _cairo_uint64_add (_cairo_uint64_rsl (a.lo, shift), - _cairo_uint64_lsl (a.hi, (64 - shift))); - a.hi = _cairo_uint64_rsl (a.hi, shift); - } - return a; -} - -cairo_uint128_t -_cairo_uint128_rsa (cairo_int128_t a, int shift) -{ - if (shift >= 64) - { - a.lo = a.hi; - a.hi = _cairo_uint64_rsa (a.hi, 64-1); - shift -= 64; - } - if (shift) - { - a.lo = _cairo_uint64_add (_cairo_uint64_rsl (a.lo, shift), - _cairo_uint64_lsl (a.hi, (64 - shift))); - a.hi = _cairo_uint64_rsa (a.hi, shift); - } - return a; -} - -int -_cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b) -{ - return (_cairo_uint64_lt (a.hi, b.hi) || - (_cairo_uint64_eq (a.hi, b.hi) && - _cairo_uint64_lt (a.lo, b.lo))); -} - -int -_cairo_int128_lt (cairo_int128_t a, cairo_int128_t b) -{ - if (_cairo_int128_negative (a) && !_cairo_int128_negative (b)) - return 1; - if (!_cairo_int128_negative (a) && _cairo_int128_negative (b)) - return 0; - return _cairo_uint128_lt (a, b); -} - -int -_cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b) -{ - int cmp; - - cmp = _cairo_uint64_cmp (a.hi, b.hi); - if (cmp) - return cmp; - return _cairo_uint64_cmp (a.lo, b.lo); -} - -int -_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b) -{ - if (_cairo_int128_negative (a) && !_cairo_int128_negative (b)) - return -1; - if (!_cairo_int128_negative (a) && _cairo_int128_negative (b)) - return 1; - - return _cairo_uint128_cmp (a, b); -} - -int -_cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b) -{ - return (_cairo_uint64_eq (a.hi, b.hi) && - _cairo_uint64_eq (a.lo, b.lo)); -} - -#if HAVE_UINT64_T -#define _cairo_msbset64(q) (q & ((uint64_t) 1 << 63)) -#else -#define _cairo_msbset64(q) (q.hi & ((uint32_t) 1 << 31)) -#endif - -cairo_uquorem128_t -_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den) -{ - cairo_uquorem128_t qr; - cairo_uint128_t bit; - cairo_uint128_t quo; - - bit = _cairo_uint32_to_uint128 (1); - - /* normalize to make den >= num, but not overflow */ - while (_cairo_uint128_lt (den, num) && !_cairo_msbset64(den.hi)) - { - bit = _cairo_uint128_lsl (bit, 1); - den = _cairo_uint128_lsl (den, 1); - } - quo = _cairo_uint32_to_uint128 (0); - - /* generate quotient, one bit at a time */ - while (_cairo_uint128_ne (bit, _cairo_uint32_to_uint128(0))) - { - if (_cairo_uint128_le (den, num)) - { - num = _cairo_uint128_sub (num, den); - quo = _cairo_uint128_add (quo, bit); - } - bit = _cairo_uint128_rsl (bit, 1); - den = _cairo_uint128_rsl (den, 1); - } - qr.quo = quo; - qr.rem = num; - return qr; -} - -cairo_uint128_t -_cairo_uint128_negate (cairo_uint128_t a) -{ - a.lo = _cairo_uint64_not (a.lo); - a.hi = _cairo_uint64_not (a.hi); - return _cairo_uint128_add (a, _cairo_uint32_to_uint128 (1)); -} - -cairo_uint128_t -_cairo_uint128_not (cairo_uint128_t a) -{ - a.lo = _cairo_uint64_not (a.lo); - a.hi = _cairo_uint64_not (a.hi); - return a; -} - -#endif /* !HAVE_UINT128_T */ - -cairo_quorem128_t -_cairo_int128_divrem (cairo_int128_t num, cairo_int128_t den) -{ - int num_neg = _cairo_int128_negative (num); - int den_neg = _cairo_int128_negative (den); - cairo_uquorem128_t uqr; - cairo_quorem128_t qr; - - if (num_neg) - num = _cairo_int128_negate (num); - if (den_neg) - den = _cairo_int128_negate (den); - uqr = _cairo_uint128_divrem (num, den); - if (num_neg) - qr.rem = _cairo_int128_negate (uqr.rem); - else - qr.rem = uqr.rem; - if (num_neg != den_neg) - qr.quo = _cairo_int128_negate (uqr.quo); - else - qr.quo = uqr.quo; - return qr; -} - -/** - * _cairo_uint_96by64_32x64_divrem: - * - * Compute a 32 bit quotient and 64 bit remainder of a 96 bit unsigned - * dividend and 64 bit divisor. If the quotient doesn't fit into 32 - * bits then the returned remainder is equal to the divisor, and the - * quotient is the largest representable 64 bit integer. It is an - * error to call this function with the high 32 bits of @num being - * non-zero. - **/ -cairo_uquorem64_t -_cairo_uint_96by64_32x64_divrem (cairo_uint128_t num, - cairo_uint64_t den) -{ - cairo_uquorem64_t result; - cairo_uint64_t B = _cairo_uint32s_to_uint64 (1, 0); - - /* These are the high 64 bits of the *96* bit numerator. We're - * going to represent the numerator as xB + y, where x is a 64, - * and y is a 32 bit number. */ - cairo_uint64_t x = _cairo_uint128_to_uint64 (_cairo_uint128_rsl(num, 32)); - - /* Initialise the result to indicate overflow. */ - result.quo = _cairo_uint32s_to_uint64 (-1U, -1U); - result.rem = den; - - /* Don't bother if the quotient is going to overflow. */ - if (_cairo_uint64_ge (x, den)) { - return /* overflow */ result; - } - - if (_cairo_uint64_lt (x, B)) { - /* When the final quotient is known to fit in 32 bits, then - * num < 2^64 if and only if den < 2^32. */ - return _cairo_uint64_divrem (_cairo_uint128_to_uint64 (num), den); - } - else { - /* Denominator is >= 2^32. the numerator is >= 2^64, and the - * division won't overflow: need two divrems. Write the - * numerator and denominator as - * - * num = xB + y x : 64 bits, y : 32 bits - * den = uB + v u, v : 32 bits - */ - uint32_t y = _cairo_uint128_to_uint32 (num); - uint32_t u = uint64_hi32 (den); - uint32_t v = _cairo_uint64_to_uint32 (den); - - /* Compute a lower bound approximate quotient of num/den - * from x/(u+1). Then we have - * - * x = q(u+1) + r ; q : 32 bits, r <= u : 32 bits. - * - * xB + y = q(u+1)B + (rB+y) - * = q(uB + B + v - v) + (rB+y) - * = q(uB + v) + qB - qv + (rB+y) - * = q(uB + v) + q(B-v) + (rB+y) - * - * The true quotient of num/den then is q plus the - * contribution of q(B-v) + (rB+y). The main contribution - * comes from the term q(B-v), with the term (rB+y) only - * contributing at most one part. - * - * The term q(B-v) must fit into 64 bits, since q fits into 32 - * bits on account of being a lower bound to the true - * quotient, and as B-v <= 2^32, we may safely use a single - * 64/64 bit division to find its contribution. */ - - cairo_uquorem64_t quorem; - cairo_uint64_t remainder; /* will contain final remainder */ - uint32_t quotient; /* will contain final quotient. */ - uint32_t q; - uint32_t r; - - /* Approximate quotient by dividing the high 64 bits of num by - * u+1. Watch out for overflow of u+1. */ - if (u+1) { - quorem = _cairo_uint64_divrem (x, _cairo_uint32_to_uint64 (u+1)); - q = _cairo_uint64_to_uint32 (quorem.quo); - r = _cairo_uint64_to_uint32 (quorem.rem); - } - else { - q = uint64_hi32 (x); - r = _cairo_uint64_to_uint32 (x); - } - quotient = q; - - /* Add the main term's contribution to quotient. Note B-v = - * -v as an uint32 (unless v = 0) */ - if (v) - quorem = _cairo_uint64_divrem (_cairo_uint32x32_64_mul (q, -v), den); - else - quorem = _cairo_uint64_divrem (_cairo_uint32s_to_uint64 (q, 0), den); - quotient += _cairo_uint64_to_uint32 (quorem.quo); - - /* Add the contribution of the subterm and start computing the - * true remainder. */ - remainder = _cairo_uint32s_to_uint64 (r, y); - if (_cairo_uint64_ge (remainder, den)) { - remainder = _cairo_uint64_sub (remainder, den); - quotient++; - } - - /* Add the contribution of the main term's remainder. The - * funky test here checks that remainder + main_rem >= den, - * taking into account overflow of the addition. */ - remainder = _cairo_uint64_add (remainder, quorem.rem); - if (_cairo_uint64_ge (remainder, den) || - _cairo_uint64_lt (remainder, quorem.rem)) - { - remainder = _cairo_uint64_sub (remainder, den); - quotient++; - } - - result.quo = _cairo_uint32_to_uint64 (quotient); - result.rem = remainder; - } - return result; -} - -cairo_quorem64_t -_cairo_int_96by64_32x64_divrem (cairo_int128_t num, cairo_int64_t den) -{ - int num_neg = _cairo_int128_negative (num); - int den_neg = _cairo_int64_negative (den); - cairo_uint64_t nonneg_den; - cairo_uquorem64_t uqr; - cairo_quorem64_t qr; - - if (num_neg) - num = _cairo_int128_negate (num); - if (den_neg) - nonneg_den = _cairo_int64_negate (den); - else - nonneg_den = den; - - uqr = _cairo_uint_96by64_32x64_divrem (num, nonneg_den); - if (_cairo_uint64_eq (uqr.rem, nonneg_den)) { - /* bail on overflow. */ - qr.quo = _cairo_uint32s_to_uint64 (0x7FFFFFFF, -1U); - qr.rem = den; - return qr; - } - - if (num_neg) - qr.rem = _cairo_int64_negate (uqr.rem); - else - qr.rem = uqr.rem; - if (num_neg != den_neg) - qr.quo = _cairo_int64_negate (uqr.quo); - else - qr.quo = uqr.quo; - return qr; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-win32.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-win32.h deleted file mode 100644 index 3d2e1c60169..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-win32.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Owen Taylor - */ - -#ifndef _CAIRO_WIN32_H_ -#define _CAIRO_WIN32_H_ - -#include "cairo.h" - -#if CAIRO_HAS_WIN32_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_win32_surface_create (HDC hdc); - -cairo_public cairo_surface_t * -cairo_win32_printing_surface_create (HDC hdc); - -cairo_public cairo_surface_t * -cairo_win32_surface_create_with_ddb (HDC hdc, - cairo_format_t format, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_win32_surface_create_with_dib (cairo_format_t format, - int width, - int height); - -cairo_public HDC -cairo_win32_surface_get_dc (cairo_surface_t *surface); - -cairo_public cairo_surface_t * -cairo_win32_surface_get_image (cairo_surface_t *surface); - -#if CAIRO_HAS_WIN32_FONT - -/* - * Win32 font support - */ - -cairo_public cairo_font_face_t * -cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont); - -cairo_public cairo_font_face_t * -cairo_win32_font_face_create_for_hfont (HFONT font); - -cairo_public cairo_font_face_t * -cairo_win32_font_face_create_for_logfontw_hfont (LOGFONTW *logfont, HFONT font); - -cairo_public cairo_status_t -cairo_win32_scaled_font_select_font (cairo_scaled_font_t *scaled_font, - HDC hdc); - -cairo_public void -cairo_win32_scaled_font_done_font (cairo_scaled_font_t *scaled_font); - -cairo_public double -cairo_win32_scaled_font_get_metrics_factor (cairo_scaled_font_t *scaled_font); - -cairo_public void -cairo_win32_scaled_font_get_logical_to_device (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *logical_to_device); - -cairo_public void -cairo_win32_scaled_font_get_device_to_logical (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *device_to_logical); - -#endif /* CAIRO_HAS_WIN32_FONT */ - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_WIN32_SURFACE */ -# error Cairo was not compiled with support for the win32 backend -#endif /* CAIRO_HAS_WIN32_SURFACE */ - -#endif /* _CAIRO_WIN32_H_ */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-core.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-core.c deleted file mode 100644 index e01dc1a8361..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-core.c +++ /dev/null @@ -1,300 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-xcb-private.h" - -#include - -xcb_pixmap_t -_cairo_xcb_connection_create_pixmap (cairo_xcb_connection_t *connection, - uint8_t depth, - xcb_drawable_t drawable, - uint16_t width, - uint16_t height) -{ - xcb_pixmap_t pixmap = _cairo_xcb_connection_get_xid (connection); - - assert (width > 0); - assert (height > 0); - xcb_create_pixmap (connection->xcb_connection, - depth, pixmap, drawable, - width, height); - return pixmap; -} - -void -_cairo_xcb_connection_free_pixmap (cairo_xcb_connection_t *connection, - xcb_pixmap_t pixmap) -{ - xcb_free_pixmap (connection->xcb_connection, pixmap); - _cairo_xcb_connection_put_xid (connection, pixmap); -} - -xcb_gcontext_t -_cairo_xcb_connection_create_gc (cairo_xcb_connection_t *connection, - xcb_drawable_t drawable, - uint32_t value_mask, - uint32_t *values) -{ - xcb_gcontext_t gc = _cairo_xcb_connection_get_xid (connection); - xcb_create_gc (connection->xcb_connection, gc, drawable, - value_mask, values); - return gc; -} - -void -_cairo_xcb_connection_free_gc (cairo_xcb_connection_t *connection, - xcb_gcontext_t gc) -{ - xcb_free_gc (connection->xcb_connection, gc); - _cairo_xcb_connection_put_xid (connection, gc); -} - -void -_cairo_xcb_connection_change_gc (cairo_xcb_connection_t *connection, - xcb_gcontext_t gc, - uint32_t value_mask, - uint32_t *values) -{ - xcb_change_gc (connection->xcb_connection, gc, - value_mask, values); -} - -void -_cairo_xcb_connection_copy_area (cairo_xcb_connection_t *connection, - xcb_drawable_t src, - xcb_drawable_t dst, - xcb_gcontext_t gc, - int16_t src_x, - int16_t src_y, - int16_t dst_x, - int16_t dst_y, - uint16_t width, - uint16_t height) -{ - xcb_copy_area (connection->xcb_connection, src, dst, gc, - src_x, src_y, dst_x, dst_y, width, height); -} - -void -_cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint32_t num_rectangles, - xcb_rectangle_t *rectangles) -{ - xcb_poly_fill_rectangle (connection->xcb_connection, dst, gc, - num_rectangles, rectangles); -} - -void -_cairo_xcb_connection_put_image (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint16_t width, - uint16_t height, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - uint32_t stride, - void *data) -{ - const uint32_t req_size = 18; - uint32_t length = height * stride; - uint32_t len = (req_size + length) >> 2; - - if (len < connection->maximum_request_length) { - xcb_put_image (connection->xcb_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, - dst, gc, width, height, dst_x, dst_y, 0, depth, - length, data); - } else { - int rows = (connection->maximum_request_length - req_size - 4) / stride; - if (rows > 0) { - do { - if (rows > height) - rows = height; - - length = rows * stride; - - xcb_put_image (connection->xcb_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, - dst, gc, width, rows, dst_x, dst_y, 0, depth, length, data); - - height -= rows; - dst_y += rows; - data = (char *) data + length; - } while (height); - } else { - ASSERT_NOT_REACHED; - } - } -} - -static void -_cairo_xcb_connection_do_put_subimage (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - uint16_t cpp, - int stride, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - void *_data) -{ - xcb_protocol_request_t xcb_req = { - 0 /* count */, - 0 /* ext */, - XCB_PUT_IMAGE /* opcode */, - 1 /* isvoid (doesn't cause a reply) */ - }; - xcb_put_image_request_t req; - struct iovec vec_stack[CAIRO_STACK_ARRAY_LENGTH (struct iovec)]; - struct iovec *vec = vec_stack; - uint32_t len = 0; - uint8_t *data = _data; - int n = 3; - /* Two extra entries are needed for xcb, two for us */ - int entries_needed = height + 2 + 2; - - req.format = XCB_IMAGE_FORMAT_Z_PIXMAP; - req.drawable = dst; - req.gc = gc; - req.width = width; - req.height = height; - req.dst_x = dst_x; - req.dst_y = dst_y; - req.left_pad = 0; - req.depth = depth; - req.pad0[0] = 0; - req.pad0[1] = 0; - - if (entries_needed > ARRAY_LENGTH (vec_stack)) { - vec = _cairo_malloc_ab (entries_needed, sizeof (struct iovec)); - if (unlikely (vec == NULL)) { - /* XXX loop over ARRAY_LENGTH (vec_stack) */ - return; - } - } - - data += src_y * stride + src_x * cpp; - /* vec[1] will be used in XCB if it has to use BigRequests or insert a sync, - * vec[0] is used if the internal queue needs to be flushed. */ - vec[2].iov_base = (char *) &req; - vec[2].iov_len = sizeof (req); - - /* Now comes the actual data */ - while (height--) { - vec[n].iov_base = data; - vec[n].iov_len = cpp * width; - len += cpp * width; - data += stride; - n++; - } - - /* And again some padding */ - vec[n].iov_base = 0; - vec[n].iov_len = -len & 3; - n++; - - /* For efficiency reasons, this functions writes the request "directly" to - * the xcb connection to avoid having to copy the data around. */ - assert (n == entries_needed); - xcb_req.count = n - 2; - xcb_send_request (connection->xcb_connection, 0, &vec[2], &xcb_req); - - if (vec != vec_stack) - free (vec); -} - -void -_cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - uint16_t cpp, - int stride, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - void *_data) -{ - const uint32_t req_size = sizeof(xcb_put_image_request_t); - uint32_t length = height * cpp * width; - uint32_t len = (req_size + length) >> 2; - - if (len < connection->maximum_request_length) { - _cairo_xcb_connection_do_put_subimage (connection, dst, gc, src_x, src_y, - width, height, cpp, stride, dst_x, dst_y, depth, _data); - } else { - int rows = (connection->maximum_request_length - req_size - 4) / (cpp * width); - if (rows > 0) { - do { - if (rows > height) - rows = height; - - _cairo_xcb_connection_do_put_subimage (connection, dst, gc, src_x, src_y, - width, rows, cpp, stride, dst_x, dst_y, depth, _data); - - height -= rows; - dst_y += rows; - _data = (char *) _data + stride * rows; - } while (height); - } else { - ASSERT_NOT_REACHED; - } - } -} - -xcb_get_image_reply_t * -_cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection, - xcb_drawable_t src, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height) -{ - return xcb_get_image_reply (connection->xcb_connection, - xcb_get_image (connection->xcb_connection, - XCB_IMAGE_FORMAT_Z_PIXMAP, - src, - src_x, src_y, - width, height, - (uint32_t) -1), - NULL); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-render.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-render.c deleted file mode 100644 index 61119653e9a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-render.c +++ /dev/null @@ -1,299 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-xcb-private.h" - -#include - -void -_cairo_xcb_connection_render_create_picture (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_drawable_t drawable, - xcb_render_pictformat_t format, - uint32_t value_mask, - uint32_t *value_list) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_create_picture (connection->xcb_connection, picture, drawable, - format, value_mask, value_list); -} - -void -_cairo_xcb_connection_render_change_picture (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - uint32_t value_mask, - uint32_t *value_list) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_change_picture (connection->xcb_connection, picture, - value_mask, value_list); -} - -void -_cairo_xcb_connection_render_set_picture_clip_rectangles (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - int16_t clip_x_origin, - int16_t clip_y_origin, - uint32_t rectangles_len, - xcb_rectangle_t *rectangles) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_set_picture_clip_rectangles (connection->xcb_connection, picture, - clip_x_origin, clip_y_origin, - rectangles_len, rectangles); -} - -void -_cairo_xcb_connection_render_free_picture (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_free_picture (connection->xcb_connection, picture); - _cairo_xcb_connection_put_xid (connection, picture); -} - -void -_cairo_xcb_connection_render_composite (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t mask, - xcb_render_picture_t dst, - int16_t src_x, - int16_t src_y, - int16_t mask_x, - int16_t mask_y, - int16_t dst_x, - int16_t dst_y, - uint16_t width, - uint16_t height) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE); - xcb_render_composite (connection->xcb_connection, op, src, mask, dst, - src_x, src_y, mask_x, mask_y, dst_x, dst_y, width, height); -} - -void -_cairo_xcb_connection_render_trapezoids (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - int16_t src_x, - int16_t src_y, - uint32_t traps_len, - xcb_render_trapezoid_t *traps) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS); - xcb_render_trapezoids (connection->xcb_connection, op, src, dst, - mask_format, src_x, src_y, traps_len, traps); -} - -void -_cairo_xcb_connection_render_create_glyph_set (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t id, - xcb_render_pictformat_t format) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_create_glyph_set (connection->xcb_connection, id, format); -} - -void -_cairo_xcb_connection_render_free_glyph_set (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t glyphset) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_free_glyph_set (connection->xcb_connection, glyphset); - _cairo_xcb_connection_put_xid (connection, glyphset); -} - -void -_cairo_xcb_connection_render_add_glyphs (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t glyphset, - uint32_t num_glyphs, - uint32_t *glyphs_id, - xcb_render_glyphinfo_t *glyphs, - uint32_t data_len, - uint8_t *data) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_add_glyphs (connection->xcb_connection, glyphset, num_glyphs, - glyphs_id, glyphs, data_len, data); -} - -void -_cairo_xcb_connection_render_free_glyphs (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t glyphset, - uint32_t num_glyphs, - xcb_render_glyph_t *glyphs) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_free_glyphs (connection->xcb_connection, glyphset, num_glyphs, glyphs); -} - -void -_cairo_xcb_connection_render_composite_glyphs_8 (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t glyphcmds_len, - uint8_t *glyphcmds) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_composite_glyphs_8 (connection->xcb_connection, op, src, dst, mask_format, - glyphset, src_x, src_y, glyphcmds_len, glyphcmds); -} - -void -_cairo_xcb_connection_render_composite_glyphs_16 (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t glyphcmds_len, - uint8_t *glyphcmds) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_composite_glyphs_16 (connection->xcb_connection, op, src, dst, mask_format, - glyphset, src_x, src_y, glyphcmds_len, glyphcmds); -} - -void -_cairo_xcb_connection_render_composite_glyphs_32 (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t glyphcmds_len, - uint8_t *glyphcmds) -{ - assert (connection->flags & CAIRO_XCB_HAS_RENDER); - xcb_render_composite_glyphs_32 (connection->xcb_connection, op, src, dst, mask_format, - glyphset, src_x, src_y, glyphcmds_len, glyphcmds); -} - -void -_cairo_xcb_connection_render_fill_rectangles (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t dst, - xcb_render_color_t color, - uint32_t num_rects, - xcb_rectangle_t *rects) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES); - xcb_render_fill_rectangles (connection->xcb_connection, op, dst, color, - num_rects, rects); -} - -void -_cairo_xcb_connection_render_set_picture_transform (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_transform_t *transform) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM); - xcb_render_set_picture_transform (connection->xcb_connection, picture, *transform); -} - -void -_cairo_xcb_connection_render_set_picture_filter (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - uint16_t filter_len, - char *filter) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_FILTERS); - xcb_render_set_picture_filter (connection->xcb_connection, picture, - filter_len, filter, 0, NULL); -} - -void -_cairo_xcb_connection_render_create_solid_fill (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_color_t color) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); - xcb_render_create_solid_fill (connection->xcb_connection, picture, color); -} - -void -_cairo_xcb_connection_render_create_linear_gradient (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_pointfix_t p1, - xcb_render_pointfix_t p2, - uint32_t num_stops, - xcb_render_fixed_t *stops, - xcb_render_color_t *colors) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); - xcb_render_create_linear_gradient (connection->xcb_connection, picture, - p1, p2, num_stops, stops, colors); -} - -void -_cairo_xcb_connection_render_create_radial_gradient (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_pointfix_t inner, - xcb_render_pointfix_t outer, - xcb_render_fixed_t inner_radius, - xcb_render_fixed_t outer_radius, - uint32_t num_stops, - xcb_render_fixed_t *stops, - xcb_render_color_t *colors) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); - xcb_render_create_radial_gradient (connection->xcb_connection, picture, - inner, outer, inner_radius, outer_radius, - num_stops, stops, colors); -} - -void -_cairo_xcb_connection_render_create_conical_gradient (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_pointfix_t center, - xcb_render_fixed_t angle, - uint32_t num_stops, - xcb_render_fixed_t *stops, - xcb_render_color_t *colors) -{ - assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); - xcb_render_create_conical_gradient (connection->xcb_connection, picture, - center, angle, num_stops, stops, colors); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-shm.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-shm.c deleted file mode 100644 index 7720bbbd25b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection-shm.c +++ /dev/null @@ -1,115 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - -#include "cairo-xcb-private.h" - -#include -#include - -uint32_t -_cairo_xcb_connection_shm_attach (cairo_xcb_connection_t *connection, - uint32_t id, - cairo_bool_t readonly) -{ - uint32_t segment = _cairo_xcb_connection_get_xid (connection); - assert (connection->flags & CAIRO_XCB_HAS_SHM); - xcb_shm_attach (connection->xcb_connection, segment, id, readonly); - return segment; -} - -void -_cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint16_t total_width, - uint16_t total_height, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - uint32_t shm, - uint32_t offset) -{ - assert (connection->flags & CAIRO_XCB_HAS_SHM); - xcb_shm_put_image (connection->xcb_connection, dst, gc, total_width, total_height, - src_x, src_y, width, height, dst_x, dst_y, depth, - XCB_IMAGE_FORMAT_Z_PIXMAP, 0, shm, offset); -} - -cairo_status_t -_cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection, - xcb_drawable_t src, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - uint32_t shmseg, - uint32_t offset) -{ - xcb_shm_get_image_reply_t *reply; - - assert (connection->flags & CAIRO_XCB_HAS_SHM); - reply = xcb_shm_get_image_reply (connection->xcb_connection, - xcb_shm_get_image (connection->xcb_connection, - src, - src_x, src_y, - width, height, - (uint32_t) -1, - XCB_IMAGE_FORMAT_Z_PIXMAP, - shmseg, offset), - NULL); - free (reply); - - if (!reply) { - /* an error here should be impossible */ - return _cairo_error (CAIRO_STATUS_READ_ERROR); - } - - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_xcb_connection_shm_detach (cairo_xcb_connection_t *connection, - uint32_t segment) -{ - assert (connection->flags & CAIRO_XCB_HAS_SHM); - xcb_shm_detach (connection->xcb_connection, segment); - _cairo_xcb_connection_put_xid (connection, segment); -} - -#endif /* CAIRO_HAS_XCB_SHM_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection.c deleted file mode 100644 index 67897fa4ecc..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-connection.c +++ /dev/null @@ -1,1006 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Authors: - * Chris Wilson - */ - - -#include "cairoint.h" - -#include "cairo-xcb-private.h" -#include "cairo-hash-private.h" -#include "cairo-freelist-private.h" -#include "cairo-list-inline.h" - -#include -#include -#include - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS -#include -#include -#include -#endif - -typedef struct _cairo_xcb_xrender_format { - cairo_hash_entry_t key; - xcb_render_pictformat_t xrender_format; -} cairo_xcb_xrender_format_t; - -typedef struct _cairo_xcb_xid { - cairo_list_t link; - uint32_t xid; -} cairo_xcb_xid_t; - -#define XCB_RENDER_AT_LEAST(V, major, minor) \ - (((V)->major_version > major) || \ - (((V)->major_version == major) && ((V)->minor_version >= minor))) - -#define XCB_RENDER_HAS_CREATE_PICTURE(surface) XCB_RENDER_AT_LEAST((surface), 0, 0) -#define XCB_RENDER_HAS_COMPOSITE(surface) XCB_RENDER_AT_LEAST((surface), 0, 0) -#define XCB_RENDER_HAS_COMPOSITE_TEXT(surface) XCB_RENDER_AT_LEAST((surface), 0, 0) - -#define XCB_RENDER_HAS_FILL_RECTANGLES(surface) XCB_RENDER_AT_LEAST((surface), 0, 1) - -#define XCB_RENDER_HAS_DISJOINT(surface) XCB_RENDER_AT_LEAST((surface), 0, 2) -#define XCB_RENDER_HAS_CONJOINT(surface) XCB_RENDER_AT_LEAST((surface), 0, 2) - -#define XCB_RENDER_HAS_TRAPEZOIDS(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) -#define XCB_RENDER_HAS_TRIANGLES(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) -#define XCB_RENDER_HAS_TRISTRIP(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) -#define XCB_RENDER_HAS_TRIFAN(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) - -#define XCB_RENDER_HAS_PICTURE_TRANSFORM(surface) XCB_RENDER_AT_LEAST((surface), 0, 6) -#define XCB_RENDER_HAS_FILTERS(surface) XCB_RENDER_AT_LEAST((surface), 0, 6) -#define XCB_RENDER_HAS_FILTER_GOOD(surface) FALSE -#define XCB_RENDER_HAS_FILTER_BEST(surface) FALSE -#define XCB_RENDER_HAS_SUBPIXEL_ORDER(surface) XCB_RENDER_AT_LEAST((surface), 0, 6) - -#define XCB_RENDER_HAS_EXTENDED_REPEAT(surface) XCB_RENDER_AT_LEAST((surface), 0, 10) -#define XCB_RENDER_HAS_GRADIENTS(surface) XCB_RENDER_AT_LEAST((surface), 0, 10) - -#define XCB_RENDER_HAS_PDF_OPERATORS(surface) XCB_RENDER_AT_LEAST((surface), 0, 11) - -static cairo_list_t connections; - -static cairo_status_t -_cairo_xcb_connection_find_visual_formats (cairo_xcb_connection_t *connection, - const xcb_render_query_pict_formats_reply_t *formats) -{ - xcb_render_pictscreen_iterator_t screens; - xcb_render_pictdepth_iterator_t depths; - xcb_render_pictvisual_iterator_t visuals; - - for (screens = xcb_render_query_pict_formats_screens_iterator (formats); - screens.rem; - xcb_render_pictscreen_next (&screens)) - { - for (depths = xcb_render_pictscreen_depths_iterator (screens.data); - depths.rem; - xcb_render_pictdepth_next (&depths)) - { - for (visuals = xcb_render_pictdepth_visuals_iterator (depths.data); - visuals.rem; - xcb_render_pictvisual_next (&visuals)) - { - cairo_xcb_xrender_format_t *f; - cairo_status_t status; - - f = malloc (sizeof (cairo_xcb_xrender_format_t)); - if (unlikely (f == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - f->key.hash = visuals.data->visual; - f->xrender_format = visuals.data->format; - status = _cairo_hash_table_insert (connection->visual_to_xrender_format, - &f->key); - if (unlikely (status)) - return status; - } - } - } - - return CAIRO_STATUS_SUCCESS; -} - -#if 0 -static xcb_format_t * -find_format_for_depth (const xcb_setup_t *setup, uint8_t depth) -{ - xcb_format_t *fmt = xcb_setup_pixmap_formats (setup); - xcb_format_t *fmtend = fmt + xcb_setup_pixmap_formats_length (setup); - - for (; fmt != fmtend; ++fmt) - if (fmt->depth == depth) - return fmt; - - return 0; -} -#endif - -static cairo_status_t -_cairo_xcb_connection_parse_xrender_formats (cairo_xcb_connection_t *connection, - const xcb_render_query_pict_formats_reply_t *formats) -{ - xcb_render_pictforminfo_iterator_t i; - cairo_status_t status; - - for (i = xcb_render_query_pict_formats_formats_iterator (formats); - i.rem; - xcb_render_pictforminfo_next (&i)) - { - cairo_format_masks_t masks; - pixman_format_code_t pixman_format; - - if (i.data->type != XCB_RENDER_PICT_TYPE_DIRECT) - continue; - - masks.alpha_mask = - (unsigned long) i.data->direct.alpha_mask << i.data->direct.alpha_shift; - masks.red_mask = - (unsigned long) i.data->direct.red_mask << i.data->direct.red_shift; - masks.green_mask = - (unsigned long) i.data->direct.green_mask << i.data->direct.green_shift; - masks.blue_mask = - (unsigned long) i.data->direct.blue_mask << i.data->direct.blue_shift; - masks.bpp = i.data->depth; - - if (_pixman_format_from_masks (&masks, &pixman_format)) { - cairo_hash_entry_t key; - - key.hash = pixman_format; - if (! _cairo_hash_table_lookup (connection->xrender_formats, &key)) { - cairo_xcb_xrender_format_t *f; - - f = malloc (sizeof (cairo_xcb_xrender_format_t)); - if (unlikely (f == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - f->key.hash = pixman_format; - f->xrender_format = i.data->id; - status = _cairo_hash_table_insert (connection->xrender_formats, - &f->key); - if (unlikely (status)) - return status; - -#if 0 - printf ("xrender %x -> (%lx, %lx, %lx, %lx, %d) %x [%d, %d]\n", - i.data->id, - masks.alpha_mask, - masks.red_mask, - masks.green_mask, - masks.blue_mask, - masks.bpp, - pixman_format, - PIXMAN_FORMAT_DEPTH(pixman_format), - PIXMAN_FORMAT_BPP(pixman_format)); -#endif - } - } - } - - status = _cairo_xcb_connection_find_visual_formats (connection, formats); - if (unlikely (status)) - return status; - - connection->standard_formats[CAIRO_FORMAT_A1] = - _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a1); - - connection->standard_formats[CAIRO_FORMAT_A8] = - _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a8); - - connection->standard_formats[CAIRO_FORMAT_RGB24] = - _cairo_xcb_connection_get_xrender_format (connection, - PIXMAN_FORMAT (24, - PIXMAN_TYPE_ARGB, - 0, 8, 8, 8)); - if (connection->standard_formats[CAIRO_FORMAT_RGB24] == XCB_NONE) { - connection->standard_formats[CAIRO_FORMAT_RGB24] = - _cairo_xcb_connection_get_xrender_format (connection, - PIXMAN_FORMAT (24, PIXMAN_TYPE_ABGR, - 0, 8, 8, 8)); - } - - connection->standard_formats[CAIRO_FORMAT_ARGB32] = - _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a8r8g8b8); - if (connection->standard_formats[CAIRO_FORMAT_ARGB32] == XCB_NONE) { - connection->standard_formats[CAIRO_FORMAT_ARGB32] = - _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a8b8g8r8); - } - - return CAIRO_STATUS_SUCCESS; -} - -/* - * We require support for depth 1, 8, 24 and 32 pixmaps - */ -#define DEPTH_MASK(d) (1 << ((d) - 1)) -#define REQUIRED_DEPTHS (DEPTH_MASK(1) | \ - DEPTH_MASK(8) | \ - DEPTH_MASK(24) | \ - DEPTH_MASK(32)) -static cairo_bool_t -pixmap_depths_usable (cairo_xcb_connection_t *connection, - uint32_t missing, - xcb_drawable_t root) -{ - xcb_connection_t *c = connection->xcb_connection; - xcb_void_cookie_t create_cookie[32]; - xcb_pixmap_t pixmap; - cairo_bool_t success = TRUE; - int depth, i, j; - - pixmap = _cairo_xcb_connection_get_xid (connection); - - for (depth = 1, i = 0; depth <= 32; depth++) { - if (missing & DEPTH_MASK(depth)) { - create_cookie[i] = xcb_create_pixmap_checked (c, depth, pixmap, root, 1, 1); - xcb_free_pixmap (c, pixmap); - if (!create_cookie[i].sequence) { - success = FALSE; - break; - } - i++; - } - } - - for (j = 0; j < i; j++) { - xcb_generic_error_t *create_error = xcb_request_check (c, create_cookie[j]); - success &= create_error == NULL; - free (create_error); - } - - _cairo_xcb_connection_put_xid (connection, pixmap); - - return success; -} - -static cairo_bool_t -has_required_depths (cairo_xcb_connection_t *connection) -{ - xcb_screen_iterator_t screens; - - for (screens = xcb_setup_roots_iterator (connection->root); - screens.rem; - xcb_screen_next (&screens)) - { - xcb_depth_iterator_t depths; - uint32_t missing = REQUIRED_DEPTHS; - - for (depths = xcb_screen_allowed_depths_iterator (screens.data); - depths.rem; - xcb_depth_next (&depths)) - { - missing &= ~DEPTH_MASK (depths.data->depth); - } - if (missing == 0) - continue; - - /* - * Ok, this is ugly. It should be sufficient at this - * point to just return false, but Xinerama is broken at - * this point and only advertises depths which have an - * associated visual. Of course, the other depths still - * work, but the only way to find out is to try them. - */ - if (! pixmap_depths_usable (connection, missing, screens.data->root)) - return FALSE; - } - - return TRUE; -} - -static xcb_render_query_version_reply_t * -_render_restrict_env(xcb_render_query_version_reply_t *version) -{ - const char *env; - - if (version == NULL) - return NULL; - - env = getenv ("CAIRO_DEBUG"); - if (env != NULL) - env = strstr (env, "xrender-version="); - if (env != NULL) { - int max_render_major, max_render_minor; - - env += sizeof ("xrender-version=") - 1; - if (sscanf (env, "%d.%d", &max_render_major, &max_render_minor) != 2) - max_render_major = max_render_minor = -1; - - if (max_render_major < 0 || max_render_minor < 0) { - free (version); - return NULL; - } - - if (max_render_major < (int) version->major_version || - (max_render_major == (int) version->major_version && - max_render_minor < (int) version->minor_version)) - { - version->major_version = max_render_major; - version->minor_version = max_render_minor; - } - } - - return version; -} - -static cairo_status_t -_cairo_xcb_connection_query_render (cairo_xcb_connection_t *connection) -{ - xcb_connection_t *c = connection->xcb_connection; - xcb_render_query_version_cookie_t version_cookie; - xcb_render_query_pict_formats_cookie_t formats_cookie; - xcb_render_query_version_reply_t *version; - xcb_render_query_pict_formats_reply_t *formats; - cairo_status_t status; - cairo_bool_t present; - - version_cookie = xcb_render_query_version (c, XCB_RENDER_MAJOR_VERSION, XCB_RENDER_MINOR_VERSION); - formats_cookie = xcb_render_query_pict_formats (c); - - present = has_required_depths (connection); - version = xcb_render_query_version_reply (c, version_cookie, 0); - formats = xcb_render_query_pict_formats_reply (c, formats_cookie, 0); - - version = _render_restrict_env (version); - - if (! present || version == NULL || formats == NULL) { - free (version); - free (formats); - return CAIRO_STATUS_SUCCESS; - } - - /* always true if the extension is present (i.e. >= 0.0) */ - connection->flags |= CAIRO_XCB_HAS_RENDER; - connection->flags |= CAIRO_XCB_RENDER_HAS_COMPOSITE; - connection->flags |= CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS; - - if (XCB_RENDER_HAS_FILL_RECTANGLES (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES; - - if (XCB_RENDER_HAS_TRAPEZOIDS (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS; - - if (XCB_RENDER_HAS_PICTURE_TRANSFORM (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM; - - if (XCB_RENDER_HAS_FILTERS (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_FILTERS; - - if (XCB_RENDER_HAS_FILTER_GOOD (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_FILTER_GOOD; - - if (XCB_RENDER_HAS_FILTER_BEST (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_FILTER_BEST; - - if (XCB_RENDER_HAS_PDF_OPERATORS (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_PDF_OPERATORS; - - if (XCB_RENDER_HAS_EXTENDED_REPEAT (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT; - - if (XCB_RENDER_HAS_GRADIENTS (version)) - connection->flags |= CAIRO_XCB_RENDER_HAS_GRADIENTS; - - if (XCB_RENDER_HAS_SUBPIXEL_ORDER (version)) { - uint32_t screen; - uint32_t *subpixel = xcb_render_query_pict_formats_subpixels(formats); - - /* The spec explicitly allows to have too few entries in the reply... */ - for (screen = 0; screen < formats->num_subpixel && screen < connection->root->roots_len; screen++) - connection->subpixel_orders[screen] = subpixel[screen]; - } - - free (version); - - status = _cairo_xcb_connection_parse_xrender_formats (connection, formats); - free (formats); - - return status; -} - -#if 0 -static void -_cairo_xcb_connection_query_cairo (cairo_xcb_connection_t *connection) -{ - xcb_connection_t *c = connection->xcb_connection; - xcb_cairo_query_version_reply_t *version; - - version = xcb_cairo_query_version_reply (c, - xcb_cairo_query_version (c, 0, 0), - 0); - - free (version); -} -#endif - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS -static cairo_bool_t -can_use_shm (cairo_xcb_connection_t *connection) -{ - cairo_bool_t success = TRUE; - xcb_connection_t *c = connection->xcb_connection; - xcb_void_cookie_t cookie[2]; - xcb_generic_error_t *error; - int shmid; - uint32_t shmseg; - void *ptr; - - shmid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | 0600); - if (shmid == -1) - return FALSE; - - ptr = shmat (shmid, NULL, 0); - if (ptr == (char *) -1) { - shmctl (shmid, IPC_RMID, NULL); - return FALSE; - } - - shmseg = _cairo_xcb_connection_get_xid (connection); - cookie[0] = xcb_shm_attach_checked (c, shmseg, shmid, FALSE); - cookie[1] = xcb_shm_detach_checked (c, shmseg); - _cairo_xcb_connection_put_xid (connection, shmseg); - - error = xcb_request_check (c, cookie[0]); - if (error != NULL) - success = FALSE; - - error = xcb_request_check (c, cookie[1]); - if (error != NULL) - success = FALSE; - - shmctl (shmid, IPC_RMID, NULL); - shmdt (ptr); - - return success; -} - -static void -_cairo_xcb_connection_query_shm (cairo_xcb_connection_t *connection) -{ - xcb_connection_t *c = connection->xcb_connection; - xcb_shm_query_version_reply_t *version; - - version = xcb_shm_query_version_reply (c, xcb_shm_query_version (c), 0); - if (version == NULL) - return; - - free (version); - - if (can_use_shm (connection)) - connection->flags |= CAIRO_XCB_HAS_SHM; -} -#endif - -static cairo_status_t -_device_flush (void *device) -{ - cairo_xcb_connection_t *connection = device; - cairo_status_t status; - - status = cairo_device_acquire (&connection->device); - if (unlikely (status)) - return status; - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - _cairo_xcb_connection_shm_mem_pools_flush (connection); -#endif - - xcb_flush (connection->xcb_connection); - - cairo_device_release (&connection->device); - return CAIRO_STATUS_SUCCESS; -} - -static void -_pluck_xrender_format (void *entry, - void *closure) -{ - _cairo_hash_table_remove (closure, entry); - free (entry); -} - -static void -_device_finish (void *device) -{ - cairo_xcb_connection_t *connection = device; - cairo_bool_t was_cached = FALSE; - - if (! cairo_list_is_empty (&connection->link)) { - CAIRO_MUTEX_LOCK (_cairo_xcb_connections_mutex); - cairo_list_del (&connection->link); - CAIRO_MUTEX_UNLOCK (_cairo_xcb_connections_mutex); - was_cached = TRUE; - } - - while (! cairo_list_is_empty (&connection->fonts)) { - cairo_xcb_font_t *font; - - font = cairo_list_first_entry (&connection->fonts, - cairo_xcb_font_t, - link); - _cairo_xcb_font_close (font); - } - - while (! cairo_list_is_empty (&connection->screens)) { - cairo_xcb_screen_t *screen; - - screen = cairo_list_first_entry (&connection->screens, - cairo_xcb_screen_t, - link); - _cairo_xcb_screen_finish (screen); - } - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - /* _cairo_xcb_screen_finish finishes surfaces. If any of those surfaces had - * a fallback image, we might have done a SHM PutImage. */ - _cairo_xcb_connection_shm_mem_pools_flush (connection); -#endif - - if (was_cached) - cairo_device_destroy (device); -} - -static void -_device_destroy (void *device) -{ - cairo_xcb_connection_t *connection = device; - - _cairo_hash_table_foreach (connection->xrender_formats, - _pluck_xrender_format, connection->xrender_formats); - _cairo_hash_table_destroy (connection->xrender_formats); - - _cairo_hash_table_foreach (connection->visual_to_xrender_format, - _pluck_xrender_format, - connection->visual_to_xrender_format); - _cairo_hash_table_destroy (connection->visual_to_xrender_format); - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - _cairo_xcb_connection_shm_mem_pools_fini (connection); -#endif - _cairo_freepool_fini (&connection->shm_info_freelist); - - _cairo_freepool_fini (&connection->xid_pool); - - CAIRO_MUTEX_FINI (connection->shm_mutex); - CAIRO_MUTEX_FINI (connection->screens_mutex); - - free (connection->subpixel_orders); - free (connection); -} - -static const cairo_device_backend_t _cairo_xcb_device_backend = { - CAIRO_DEVICE_TYPE_XCB, - - NULL, NULL, /* lock, unlock */ - - _device_flush, - _device_finish, - _device_destroy, -}; - -cairo_xcb_connection_t * -_cairo_xcb_connection_get (xcb_connection_t *xcb_connection) -{ - cairo_xcb_connection_t *connection; - const xcb_query_extension_reply_t *ext; - cairo_status_t status; - - CAIRO_MUTEX_INITIALIZE (); - - CAIRO_MUTEX_LOCK (_cairo_xcb_connections_mutex); - if (connections.next == NULL) { - /* XXX _cairo_init () */ - cairo_list_init (&connections); - } - - cairo_list_foreach_entry (connection, - cairo_xcb_connection_t, - &connections, - link) - { - if (connection->xcb_connection == xcb_connection) { - /* Maintain MRU order. */ - if (connections.next != &connection->link) - cairo_list_move (&connection->link, &connections); - - goto unlock; - } - } - - connection = malloc (sizeof (cairo_xcb_connection_t)); - if (unlikely (connection == NULL)) - goto unlock; - - _cairo_device_init (&connection->device, &_cairo_xcb_device_backend); - - connection->xcb_connection = xcb_connection; - - cairo_list_init (&connection->fonts); - cairo_list_init (&connection->screens); - cairo_list_init (&connection->link); - connection->xrender_formats = _cairo_hash_table_create (NULL); - if (connection->xrender_formats == NULL) { - CAIRO_MUTEX_FINI (connection->device.mutex); - free (connection); - connection = NULL; - goto unlock; - } - - connection->visual_to_xrender_format = _cairo_hash_table_create (NULL); - if (connection->visual_to_xrender_format == NULL) { - _cairo_hash_table_destroy (connection->xrender_formats); - CAIRO_MUTEX_FINI (connection->device.mutex); - free (connection); - connection = NULL; - goto unlock; - } - - cairo_list_init (&connection->free_xids); - _cairo_freepool_init (&connection->xid_pool, - sizeof (cairo_xcb_xid_t)); - - cairo_list_init (&connection->shm_pools); - cairo_list_init (&connection->shm_pending); - _cairo_freepool_init (&connection->shm_info_freelist, - sizeof (cairo_xcb_shm_info_t)); - - connection->maximum_request_length = - xcb_get_maximum_request_length (xcb_connection); - - CAIRO_MUTEX_INIT (connection->shm_mutex); - CAIRO_MUTEX_INIT (connection->screens_mutex); - - CAIRO_MUTEX_LOCK (connection->device.mutex); - - connection->flags = 0; - connection->force_precision = -1; - - xcb_prefetch_extension_data (xcb_connection, &xcb_big_requests_id); - xcb_prefetch_extension_data (xcb_connection, &xcb_render_id); -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - xcb_prefetch_extension_data (xcb_connection, &xcb_shm_id); -#endif -#if 0 - xcb_prefetch_extension_data (xcb_connection, &xcb_cairo_id); -#endif - - xcb_prefetch_maximum_request_length (xcb_connection); - - connection->root = xcb_get_setup (xcb_connection); - connection->render = NULL; - connection->subpixel_orders = calloc (connection->root->roots_len, sizeof(*connection->subpixel_orders)); - if (unlikely (connection->subpixel_orders == NULL)) { - CAIRO_MUTEX_UNLOCK (connection->device.mutex); - _cairo_xcb_connection_destroy (connection); - connection = NULL; - goto unlock; - } - - ext = xcb_get_extension_data (xcb_connection, &xcb_render_id); - if (ext != NULL && ext->present) { - status = _cairo_xcb_connection_query_render (connection); - if (unlikely (status)) { - CAIRO_MUTEX_UNLOCK (connection->device.mutex); - _cairo_xcb_connection_destroy (connection); - connection = NULL; - goto unlock; - } - - connection->render = ext; - } - -#if 0 - ext = xcb_get_extension_data (connection, &xcb_cairo_id); - if (ext != NULL && ext->present) - _cairo_xcb_connection_query_cairo (connection); -#endif - - connection->shm = NULL; -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - ext = xcb_get_extension_data (xcb_connection, &xcb_shm_id); - if (ext != NULL && ext->present) { - _cairo_xcb_connection_query_shm (connection); - connection->shm = ext; - } -#endif - - connection->original_flags = connection->flags; - - CAIRO_MUTEX_UNLOCK (connection->device.mutex); - - cairo_list_add (&connection->link, &connections); -unlock: - CAIRO_MUTEX_UNLOCK (_cairo_xcb_connections_mutex); - - return connection; -} - -xcb_render_pictformat_t -_cairo_xcb_connection_get_xrender_format (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format) -{ - cairo_hash_entry_t key; - cairo_xcb_xrender_format_t *format; - - key.hash = pixman_format; - format = _cairo_hash_table_lookup (connection->xrender_formats, &key); - return format ? format->xrender_format : XCB_NONE; -} - -xcb_render_pictformat_t -_cairo_xcb_connection_get_xrender_format_for_visual (cairo_xcb_connection_t *connection, - const xcb_visualid_t visual) -{ - cairo_hash_entry_t key; - cairo_xcb_xrender_format_t *format; - - key.hash = visual; - format = _cairo_hash_table_lookup (connection->visual_to_xrender_format, &key); - return format ? format->xrender_format : XCB_NONE; -} - -void -_cairo_xcb_connection_put_xid (cairo_xcb_connection_t *connection, - uint32_t xid) -{ - cairo_xcb_xid_t *cache; - - assert (CAIRO_MUTEX_IS_LOCKED (connection->device.mutex)); - cache = _cairo_freepool_alloc (&connection->xid_pool); - if (likely (cache != NULL)) { - cache->xid = xid; - cairo_list_add (&cache->link, &connection->free_xids); - } -} - -uint32_t -_cairo_xcb_connection_get_xid (cairo_xcb_connection_t *connection) -{ - uint32_t xid; - - assert (CAIRO_MUTEX_IS_LOCKED (connection->device.mutex)); - if (! cairo_list_is_empty (&connection->free_xids)) { - cairo_xcb_xid_t *cache; - - cache = cairo_list_first_entry (&connection->free_xids, - cairo_xcb_xid_t, - link); - xid = cache->xid; - - cairo_list_del (&cache->link); - _cairo_freepool_free (&connection->xid_pool, cache); - } else { - xid = xcb_generate_id (connection->xcb_connection); - } - - return xid; -} - -/** - * cairo_xcb_device_get_connection: - * @device: a #cairo_device_t for the XCB backend - * - * Get the connection for the XCB device. - * - * Returns: the #xcb_connection_t for the connection - * - * Since: 1.12 - **/ -xcb_connection_t * -cairo_xcb_device_get_connection (cairo_device_t *device) -{ - if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) - return NULL; - - return ((cairo_xcb_connection_t *)device)->xcb_connection; -} - -/* public (debug) interface */ - -/** - * cairo_xcb_device_debug_cap_xshm_version: - * @device: a #cairo_device_t for the XCB backend - * @major_version: major version to restrict to - * @minor_version: minor version to restrict to - * - * Restricts all future XCB surfaces for this devices to the specified version - * of the SHM extension. This function exists solely for debugging purpose. - * It let's you find out how cairo would behave with an older version of - * the SHM extension. - * - * Use the special values -1 and -1 for disabling the SHM extension. - * - * Since: 1.12 - **/ -void -cairo_xcb_device_debug_cap_xshm_version (cairo_device_t *device, - int major_version, - int minor_version) -{ - cairo_xcb_connection_t *connection = (cairo_xcb_connection_t *) device; - - if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return; - } - - /* First reset all the SHM flags to their original value. This works - * because we only ever clear bits after the connection was created. - */ - connection->flags |= (connection->original_flags & CAIRO_XCB_SHM_MASK); - - /* clear any flags that are inappropriate for the desired version */ - if (major_version < 0 && minor_version < 0) { - connection->flags &= ~(CAIRO_XCB_HAS_SHM); - } -} - -/** - * cairo_xcb_device_debug_cap_xrender_version: - * @device: a #cairo_device_t for the XCB backend - * @major_version: major version to restrict to - * @minor_version: minor version to restrict to - * - * Restricts all future XCB surfaces for this devices to the specified version - * of the RENDER extension. This function exists solely for debugging purpose. - * It let's you find out how cairo would behave with an older version of - * the RENDER extension. - * - * Use the special values -1 and -1 for disabling the RENDER extension. - * - * Since: 1.12 - **/ -void -cairo_xcb_device_debug_cap_xrender_version (cairo_device_t *device, - int major_version, - int minor_version) -{ - cairo_xcb_connection_t *connection = (cairo_xcb_connection_t *) device; - - if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return; - } - - /* First reset all the RENDER flags to their original value. This works - * because we only ever clear bits after the connection was created. - */ - connection->flags |= (connection->original_flags & CAIRO_XCB_RENDER_MASK); - - /* clear any flags that are inappropriate for the desired version */ - if (major_version < 0 && minor_version < 0) { - connection->flags &= ~(CAIRO_XCB_HAS_RENDER | - CAIRO_XCB_RENDER_HAS_COMPOSITE | - CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS | - CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES | - CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | - CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM | - CAIRO_XCB_RENDER_HAS_FILTERS | - CAIRO_XCB_RENDER_HAS_FILTER_GOOD | - CAIRO_XCB_RENDER_HAS_FILTER_BEST | - CAIRO_XCB_RENDER_HAS_PDF_OPERATORS | - CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT | - CAIRO_XCB_RENDER_HAS_GRADIENTS); - } else { - xcb_render_query_version_reply_t version; - - version.major_version = major_version; - version.minor_version = minor_version; - - if (! XCB_RENDER_HAS_FILL_RECTANGLES (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES; - - if (! XCB_RENDER_HAS_TRAPEZOIDS (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS; - - if (! XCB_RENDER_HAS_PICTURE_TRANSFORM (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM; - - if (! XCB_RENDER_HAS_FILTERS (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_FILTERS; - - if (! XCB_RENDER_HAS_PDF_OPERATORS (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_PDF_OPERATORS; - - if (! XCB_RENDER_HAS_EXTENDED_REPEAT (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT; - - if (! XCB_RENDER_HAS_GRADIENTS (&version)) - connection->flags &= ~CAIRO_XCB_RENDER_HAS_GRADIENTS; - } -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_device_debug_cap_xrender_version); -#endif - -/** - * cairo_xcb_device_debug_set_precision: - * @device: a #cairo_device_t for the XCB backend - * @precision: the precision to use - * - * Render supports two modes of precision when rendering trapezoids. Set - * the precision to the desired mode. - * - * Since: 1.12 - **/ -void -cairo_xcb_device_debug_set_precision (cairo_device_t *device, - int precision) -{ - if (device == NULL || device->status) - return; - if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return; - } - - ((cairo_xcb_connection_t *) device)->force_precision = precision; -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_device_debug_set_precision); -#endif - -/** - * cairo_xcb_device_debug_get_precision: - * @device: a #cairo_device_t for the XCB backend - * - * Get the Xrender precision mode. - * - * Returns: the render precision mode - * - * Since: 1.12 - **/ -int -cairo_xcb_device_debug_get_precision (cairo_device_t *device) -{ - if (device == NULL || device->status) - return -1; - if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return -1; - } - - return ((cairo_xcb_connection_t *) device)->force_precision; -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_device_debug_get_precision); -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-private.h deleted file mode 100644 index f5d5a4c81c7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-private.h +++ /dev/null @@ -1,801 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributors(s): - * Chris Wilson - */ - -#ifndef CAIRO_XCB_PRIVATE_H -#define CAIRO_XCB_PRIVATE_H - -#include "cairoint.h" - -#include "cairo-xcb.h" - -#include "cairo-cache-private.h" -#include "cairo-compiler-private.h" -#include "cairo-device-private.h" -#include "cairo-error-private.h" -#include "cairo-freelist-private.h" -#include "cairo-list-private.h" -#include "cairo-mutex-private.h" -#include "cairo-pattern-private.h" -#include "cairo-reference-count-private.h" -#include "cairo-scaled-font-private.h" -#include "cairo-spans-private.h" -#include "cairo-surface-private.h" - -#include -#include -#include -#include - -#define XLIB_COORD_MAX 32767 - -/* maximum number of cached GC's */ -#define GC_CACHE_SIZE 4 - -#define CAIRO_XCB_RENDER_AT_LEAST(major, minor) \ - ((XCB_RENDER_MAJOR_VERSION > major) || \ - ((XCB_RENDER_MAJOR_VERSION == major) && (XCB_RENDER_MINOR_VERSION >= minor))) - -typedef struct _cairo_xcb_connection cairo_xcb_connection_t; -typedef struct _cairo_xcb_font cairo_xcb_font_t; -typedef struct _cairo_xcb_screen cairo_xcb_screen_t; -typedef struct _cairo_xcb_surface cairo_xcb_surface_t; -typedef struct _cairo_xcb_picture cairo_xcb_picture_t; -typedef struct _cairo_xcb_shm_mem_pool cairo_xcb_shm_mem_pool_t; -typedef struct _cairo_xcb_shm_info cairo_xcb_shm_info_t; -typedef struct _cairo_xcb_resources cairo_xcb_resources_t; - -struct _cairo_xcb_shm_info { - cairo_xcb_connection_t *connection; - uint32_t shm; - uint32_t offset; - size_t size; - void *mem; - cairo_xcb_shm_mem_pool_t *pool; - xcb_get_input_focus_cookie_t sync; - cairo_list_t pending; -}; - -struct _cairo_xcb_surface { - cairo_surface_t base; - cairo_image_surface_t *fallback; - cairo_boxes_t fallback_damage; - - cairo_xcb_connection_t *connection; - cairo_xcb_screen_t *screen; - - xcb_drawable_t drawable; - cairo_bool_t owns_pixmap; - - cairo_bool_t deferred_clear; - cairo_color_t deferred_clear_color; - - int width; - int height; - int depth; - - xcb_render_picture_t picture; - xcb_render_pictformat_t xrender_format; - pixman_format_code_t pixman_format; - uint32_t precision; - - cairo_list_t link; -}; - -struct _cairo_xcb_picture { - cairo_surface_t base; - - cairo_xcb_screen_t *screen; - xcb_render_picture_t picture; - xcb_render_pictformat_t xrender_format; - pixman_format_code_t pixman_format; - - int width, height; - - cairo_extend_t extend; - cairo_filter_t filter; - cairo_bool_t has_component_alpha; - xcb_render_transform_t transform; - - int x0, y0; - int x, y; - - cairo_list_t link; -}; - -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -typedef struct _cairo_xlib_xcb_surface { - cairo_surface_t base; - - cairo_xcb_surface_t *xcb; - - /* original settings for query */ - void *display; - void *screen; - void *visual; - void *format; -} cairo_xlib_xcb_surface_t; -#endif - - -enum { - GLYPHSET_INDEX_ARGB32, - GLYPHSET_INDEX_A8, - GLYPHSET_INDEX_A1, - NUM_GLYPHSETS -}; - -typedef struct _cairo_xcb_font_glyphset_free_glyphs { - xcb_render_glyphset_t glyphset; - int glyph_count; - xcb_render_glyph_t glyph_indices[128]; -} cairo_xcb_font_glyphset_free_glyphs_t; - -typedef struct _cairo_xcb_font_glyphset_info { - xcb_render_glyphset_t glyphset; - cairo_format_t format; - xcb_render_pictformat_t xrender_format; - cairo_xcb_font_glyphset_free_glyphs_t *pending_free_glyphs; -} cairo_xcb_font_glyphset_info_t; - -struct _cairo_xcb_font { - cairo_scaled_font_private_t base; - cairo_scaled_font_t *scaled_font; - cairo_xcb_connection_t *connection; - cairo_xcb_font_glyphset_info_t glyphset_info[NUM_GLYPHSETS]; - cairo_list_t link; -}; - -struct _cairo_xcb_screen { - cairo_xcb_connection_t *connection; - - xcb_screen_t *xcb_screen; - xcb_render_sub_pixel_t subpixel_order; - - xcb_gcontext_t gc[GC_CACHE_SIZE]; - uint8_t gc_depths[GC_CACHE_SIZE]; - - cairo_surface_t *stock_colors[CAIRO_STOCK_NUM_COLORS]; - struct { - cairo_surface_t *picture; - cairo_color_t color; - } solid_cache[16]; - int solid_cache_size; - - cairo_cache_t linear_pattern_cache; - cairo_cache_t radial_pattern_cache; - cairo_freelist_t pattern_cache_entry_freelist; - - cairo_list_t link; - cairo_list_t surfaces; - cairo_list_t pictures; - - cairo_bool_t has_font_options; - cairo_font_options_t font_options; -}; - -struct _cairo_xcb_connection { - cairo_device_t device; - - xcb_connection_t *xcb_connection; - - xcb_render_pictformat_t standard_formats[5]; - cairo_hash_table_t *xrender_formats; - cairo_hash_table_t *visual_to_xrender_format; - - unsigned int maximum_request_length; - unsigned int flags; - unsigned int original_flags; - - int force_precision; - - const xcb_setup_t *root; - const xcb_query_extension_reply_t *render; - const xcb_query_extension_reply_t *shm; - xcb_render_sub_pixel_t *subpixel_orders; - - cairo_list_t free_xids; - cairo_freepool_t xid_pool; - - cairo_mutex_t shm_mutex; - cairo_list_t shm_pools; - cairo_list_t shm_pending; - cairo_freepool_t shm_info_freelist; - - cairo_mutex_t screens_mutex; - cairo_list_t screens; - - cairo_list_t fonts; - - cairo_list_t link; -}; - -struct _cairo_xcb_resources { - cairo_bool_t xft_antialias; - int xft_lcdfilter; - cairo_bool_t xft_hinting; - int xft_hintstyle; - int xft_rgba; -}; - -enum { - CAIRO_XCB_HAS_RENDER = 0x0001, - CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES = 0x0002, - CAIRO_XCB_RENDER_HAS_COMPOSITE = 0x0004, - CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS = 0x0008, - CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS = 0x0010, - CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM = 0x0020, - CAIRO_XCB_RENDER_HAS_FILTERS = 0x0040, - CAIRO_XCB_RENDER_HAS_PDF_OPERATORS = 0x0080, - CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT = 0x0100, - CAIRO_XCB_RENDER_HAS_GRADIENTS = 0x0200, - CAIRO_XCB_RENDER_HAS_FILTER_GOOD = 0x0400, - CAIRO_XCB_RENDER_HAS_FILTER_BEST = 0x0800, - - CAIRO_XCB_HAS_SHM = 0x80000000, - - CAIRO_XCB_RENDER_MASK = CAIRO_XCB_HAS_RENDER | - CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES | - CAIRO_XCB_RENDER_HAS_COMPOSITE | - CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | - CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS | - CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM | - CAIRO_XCB_RENDER_HAS_FILTERS | - CAIRO_XCB_RENDER_HAS_PDF_OPERATORS | - CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT | - CAIRO_XCB_RENDER_HAS_GRADIENTS | - CAIRO_XCB_RENDER_HAS_FILTER_GOOD | - CAIRO_XCB_RENDER_HAS_FILTER_BEST, - CAIRO_XCB_SHM_MASK = CAIRO_XCB_HAS_SHM -}; - -#define CAIRO_XCB_SHM_SMALL_IMAGE 8192 - -cairo_private extern const cairo_surface_backend_t _cairo_xcb_surface_backend; - -/** - * _cairo_surface_is_xcb: - * @surface: a #cairo_surface_t - * - * Checks if a surface is an #cairo_xcb_surface_t - * - * Return value: %TRUE if the surface is an xcb surface - **/ -static inline cairo_bool_t -_cairo_surface_is_xcb (const cairo_surface_t *surface) -{ - /* _cairo_surface_nil sets a NULL backend so be safe */ - return surface->backend && surface->backend->type == CAIRO_SURFACE_TYPE_XCB; -} - -cairo_private cairo_xcb_connection_t * -_cairo_xcb_connection_get (xcb_connection_t *connection); - -static inline cairo_xcb_connection_t * -_cairo_xcb_connection_reference (cairo_xcb_connection_t *connection) -{ - return (cairo_xcb_connection_t *) cairo_device_reference (&connection->device); -} - -cairo_private xcb_render_pictformat_t -_cairo_xcb_connection_get_xrender_format (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format); - -cairo_private xcb_render_pictformat_t -_cairo_xcb_connection_get_xrender_format_for_visual (cairo_xcb_connection_t *connection, - const xcb_visualid_t visual); - -static inline cairo_status_t cairo_warn -_cairo_xcb_connection_acquire (cairo_xcb_connection_t *connection) -{ - return cairo_device_acquire (&connection->device); -} - -cairo_private uint32_t -_cairo_xcb_connection_get_xid (cairo_xcb_connection_t *connection); - -cairo_private void -_cairo_xcb_connection_put_xid (cairo_xcb_connection_t *connection, - uint32_t xid); - -static inline void -_cairo_xcb_connection_release (cairo_xcb_connection_t *connection) -{ - cairo_device_release (&connection->device); -} - -static inline void -_cairo_xcb_connection_destroy (cairo_xcb_connection_t *connection) -{ - cairo_device_destroy (&connection->device); -} - -cairo_private cairo_int_status_t -_cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *display, - size_t size, - cairo_bool_t might_reuse, - cairo_xcb_shm_info_t **shm_info_out); - -cairo_private void -_cairo_xcb_shm_info_destroy (cairo_xcb_shm_info_t *shm_info); - -cairo_private void -_cairo_xcb_connection_shm_mem_pools_flush (cairo_xcb_connection_t *connection); - -cairo_private void -_cairo_xcb_connection_shm_mem_pools_fini (cairo_xcb_connection_t *connection); - -cairo_private void -_cairo_xcb_font_close (cairo_xcb_font_t *font); - -cairo_private cairo_xcb_screen_t * -_cairo_xcb_screen_get (xcb_connection_t *connection, - xcb_screen_t *screen); - -cairo_private void -_cairo_xcb_screen_finish (cairo_xcb_screen_t *screen); - -cairo_private xcb_gcontext_t -_cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen, - xcb_drawable_t drawable, - int depth); - -cairo_private void -_cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t gc); - -cairo_private cairo_font_options_t * -_cairo_xcb_screen_get_font_options (cairo_xcb_screen_t *screen); - -cairo_private cairo_status_t -_cairo_xcb_screen_store_linear_picture (cairo_xcb_screen_t *screen, - const cairo_linear_pattern_t *linear, - cairo_surface_t *picture); - -cairo_private cairo_surface_t * -_cairo_xcb_screen_lookup_linear_picture (cairo_xcb_screen_t *screen, - const cairo_linear_pattern_t *linear); - -cairo_private cairo_status_t -_cairo_xcb_screen_store_radial_picture (cairo_xcb_screen_t *screen, - const cairo_radial_pattern_t *radial, - cairo_surface_t *picture); - -cairo_private cairo_surface_t * -_cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen, - const cairo_radial_pattern_t *radial); - -cairo_private cairo_surface_t * -_cairo_xcb_surface_create_similar_image (void *abstrct_other, - cairo_format_t format, - int width, - int height); - -cairo_private cairo_surface_t * -_cairo_xcb_surface_create_similar (void *abstract_other, - cairo_content_t content, - int width, - int height); - -cairo_private cairo_surface_t * -_cairo_xcb_surface_create_internal (cairo_xcb_screen_t *screen, - xcb_drawable_t drawable, - cairo_bool_t owns_pixmap, - pixman_format_code_t pixman_format, - xcb_render_pictformat_t xrender_format, - int width, - int height); - -cairo_private_no_warn cairo_bool_t -_cairo_xcb_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents); - -cairo_private cairo_int_status_t -_cairo_xcb_render_compositor_paint (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents); - -cairo_private cairo_int_status_t -_cairo_xcb_render_compositor_mask (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents); - -cairo_private cairo_int_status_t -_cairo_xcb_render_compositor_stroke (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias); - -cairo_private cairo_int_status_t -_cairo_xcb_render_compositor_fill (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias); - -cairo_private cairo_int_status_t -_cairo_xcb_render_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap); -cairo_private void -_cairo_xcb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font); - -cairo_private void -_cairo_xcb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font); - -cairo_private cairo_status_t -_cairo_xcb_surface_clear (cairo_xcb_surface_t *dst); - -cairo_private cairo_status_t -_cairo_xcb_surface_core_copy_boxes (cairo_xcb_surface_t *dst, - const cairo_pattern_t *src_pattern, - const cairo_rectangle_int_t *extents, - const cairo_boxes_t *boxes); - -cairo_private cairo_status_t -_cairo_xcb_surface_core_fill_boxes (cairo_xcb_surface_t *dst, - const cairo_color_t *color, - cairo_boxes_t *boxes); - -cairo_private xcb_pixmap_t -_cairo_xcb_connection_create_pixmap (cairo_xcb_connection_t *connection, - uint8_t depth, - xcb_drawable_t drawable, - uint16_t width, - uint16_t height); - -cairo_private void -_cairo_xcb_connection_free_pixmap (cairo_xcb_connection_t *connection, - xcb_pixmap_t pixmap); - -cairo_private xcb_gcontext_t -_cairo_xcb_connection_create_gc (cairo_xcb_connection_t *connection, - xcb_drawable_t drawable, - uint32_t value_mask, - uint32_t *values); - -cairo_private void -_cairo_xcb_connection_free_gc (cairo_xcb_connection_t *connection, - xcb_gcontext_t gc); - -cairo_private void -_cairo_xcb_connection_change_gc (cairo_xcb_connection_t *connection, - xcb_gcontext_t gc, - uint32_t value_mask, - uint32_t *values); - -cairo_private void -_cairo_xcb_connection_copy_area (cairo_xcb_connection_t *connection, - xcb_drawable_t src, - xcb_drawable_t dst, - xcb_gcontext_t gc, - int16_t src_x, - int16_t src_y, - int16_t dst_x, - int16_t dst_y, - uint16_t width, - uint16_t height); - -cairo_private void -_cairo_xcb_connection_put_image (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint16_t width, - uint16_t height, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - uint32_t length, - void *data); - -cairo_private void -_cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - uint16_t cpp, - int stride, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - void *data); - -cairo_private xcb_get_image_reply_t * -_cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection, - xcb_drawable_t src, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height); - -cairo_private void -_cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint32_t num_rectangles, - xcb_rectangle_t *rectangles); - -cairo_private cairo_status_t -_cairo_xcb_shm_image_create (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format, - int width, int height, - cairo_image_surface_t **image_out, - cairo_xcb_shm_info_t **shm_info_out); - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS -cairo_private uint32_t -_cairo_xcb_connection_shm_attach (cairo_xcb_connection_t *connection, - uint32_t id, - cairo_bool_t readonly); - -cairo_private void -_cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint16_t total_width, - uint16_t total_height, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - uint32_t shm, - uint32_t offset); - -cairo_private cairo_status_t -_cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection, - xcb_drawable_t src, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - uint32_t shmseg, - uint32_t offset); - -cairo_private void -_cairo_xcb_connection_shm_detach (cairo_xcb_connection_t *connection, - uint32_t segment); -#else -static inline void -_cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection, - xcb_drawable_t dst, - xcb_gcontext_t gc, - uint16_t total_width, - uint16_t total_height, - int16_t src_x, - int16_t src_y, - uint16_t width, - uint16_t height, - int16_t dst_x, - int16_t dst_y, - uint8_t depth, - uint32_t shm, - uint32_t offset) -{ - ASSERT_NOT_REACHED; -} -#endif - -cairo_private void -_cairo_xcb_connection_render_create_picture (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_drawable_t drawable, - xcb_render_pictformat_t format, - uint32_t value_mask, - uint32_t *value_list); - -cairo_private void -_cairo_xcb_connection_render_change_picture (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - uint32_t value_mask, - uint32_t *value_list); - -cairo_private void -_cairo_xcb_connection_render_set_picture_clip_rectangles (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - int16_t clip_x_origin, - int16_t clip_y_origin, - uint32_t rectangles_len, - xcb_rectangle_t *rectangles); - -cairo_private void -_cairo_xcb_connection_render_free_picture (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture); - -cairo_private void -_cairo_xcb_connection_render_composite (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t mask, - xcb_render_picture_t dst, - int16_t src_x, - int16_t src_y, - int16_t mask_x, - int16_t mask_y, - int16_t dst_x, - int16_t dst_y, - uint16_t width, - uint16_t height); - -cairo_private void -_cairo_xcb_connection_render_trapezoids (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - int16_t src_x, - int16_t src_y, - uint32_t traps_len, - xcb_render_trapezoid_t *traps); - -cairo_private void -_cairo_xcb_connection_render_create_glyph_set (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t id, - xcb_render_pictformat_t format); - -cairo_private void -_cairo_xcb_connection_render_free_glyph_set (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t glyphset); - -cairo_private void -_cairo_xcb_connection_render_add_glyphs (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t glyphset, - uint32_t num_glyphs, - uint32_t *glyphs_id, - xcb_render_glyphinfo_t *glyphs, - uint32_t data_len, - uint8_t *data); - -cairo_private void -_cairo_xcb_connection_render_free_glyphs (cairo_xcb_connection_t *connection, - xcb_render_glyphset_t glyphset, - uint32_t num_glyphs, - xcb_render_glyph_t *glyphs); - -cairo_private void -_cairo_xcb_connection_render_composite_glyphs_8 (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t glyphcmds_len, - uint8_t *glyphcmds); - -cairo_private void -_cairo_xcb_connection_render_composite_glyphs_16 (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t glyphcmds_len, - uint8_t *glyphcmds); - -cairo_private void -_cairo_xcb_connection_render_composite_glyphs_32 (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t glyphcmds_len, - uint8_t *glyphcmds); - -cairo_private void -_cairo_xcb_connection_render_fill_rectangles (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t dst, - xcb_render_color_t color, - uint32_t num_rects, - xcb_rectangle_t *rects); - -cairo_private void -_cairo_xcb_connection_render_set_picture_transform (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_transform_t *transform); - -cairo_private void -_cairo_xcb_connection_render_set_picture_filter (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - uint16_t filter_len, - char *filter); - -cairo_private void -_cairo_xcb_connection_render_create_solid_fill (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_color_t color); - -cairo_private void -_cairo_xcb_connection_render_create_linear_gradient (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_pointfix_t p1, - xcb_render_pointfix_t p2, - uint32_t num_stops, - xcb_render_fixed_t *stops, - xcb_render_color_t *colors); - -cairo_private void -_cairo_xcb_connection_render_create_radial_gradient (cairo_xcb_connection_t *connection, - xcb_render_picture_t picture, - xcb_render_pointfix_t inner, - xcb_render_pointfix_t outer, - xcb_render_fixed_t inner_radius, - xcb_render_fixed_t outer_radius, - uint32_t num_stops, - xcb_render_fixed_t *stops, - xcb_render_color_t *colors); - -cairo_private void -_cairo_xcb_connection_render_create_conical_gradient (cairo_xcb_connection_t *c, - xcb_render_picture_t picture, - xcb_render_pointfix_t center, - xcb_render_fixed_t angle, - uint32_t num_stops, - xcb_render_fixed_t *stops, - xcb_render_color_t *colors); -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_proto (cairo_xcb_surface_create); -slim_hidden_proto (cairo_xcb_surface_create_for_bitmap); -slim_hidden_proto (cairo_xcb_surface_create_with_xrender_format); -slim_hidden_proto (cairo_xcb_surface_set_size); -slim_hidden_proto (cairo_xcb_surface_set_drawable); -slim_hidden_proto (cairo_xcb_device_debug_get_precision); -slim_hidden_proto_no_warn (cairo_xcb_device_debug_set_precision); -slim_hidden_proto_no_warn (cairo_xcb_device_debug_cap_xrender_version); -#endif - -cairo_private void -_cairo_xcb_resources_get (cairo_xcb_screen_t *screen, - cairo_xcb_resources_t *resources); - -#endif /* CAIRO_XCB_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-resources.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-resources.c deleted file mode 100644 index 1877758c25a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-resources.c +++ /dev/null @@ -1,281 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2014 Lukas Lalinsky - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Authors: - * Lukas Lalinsky - * - * Partially on code from xftdpy.c - * - * Copyright © 2000 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include "cairoint.h" - -#include "cairo-xcb-private.h" - -#include "cairo-fontconfig-private.h" - -static void -parse_boolean (const char *v, cairo_bool_t *out) -{ - char c0, c1; - - c0 = *v; - if (c0 == 't' || c0 == 'T' || c0 == 'y' || c0 == 'Y' || c0 == '1') - *out = TRUE; - if (c0 == 'f' || c0 == 'F' || c0 == 'n' || c0 == 'N' || c0 == '0') - *out = FALSE; - if (c0 == 'o') { - c1 = v[1]; - if (c1 == 'n' || c1 == 'N') - *out = TRUE; - if (c1 == 'f' || c1 == 'F') - *out = FALSE; - } -} - -static void -parse_integer (const char *v, int *out) -{ - char *e; - int value; - -#if CAIRO_HAS_FC_FONT - if (FcNameConstant ((FcChar8 *) v, out)) - return; -#endif - - value = strtol (v, &e, 0); - if (e != v) - *out = value; -} - -static char * -skip_spaces(char *str) -{ - while (*str == ' ' || *str == '\t' || *str == '\n') - str++; - return str; -} - -struct resource_parser { - int buffer_size; - int bytes_in_buffer; - char* buffer; - cairo_xcb_resources_t *resources; -}; - -static cairo_bool_t -resource_parse_line (char *name, cairo_xcb_resources_t *resources) -{ - char *value; - - value = strchr (name, ':'); - if (value == NULL) - return FALSE; - - *value++ = 0; - - name = skip_spaces (name); - value = skip_spaces (value); - - if (strcmp (name, "Xft.antialias") == 0) - parse_boolean (value, &(resources->xft_antialias)); - else if (strcmp (name, "Xft.lcdfilter") == 0) - parse_integer (value, &(resources->xft_lcdfilter)); - else if (strcmp (name, "Xft.rgba") == 0) - parse_integer (value, &(resources->xft_rgba)); - else if (strcmp (name, "Xft.hinting") == 0) - parse_boolean (value, &(resources->xft_hinting)); - else if (strcmp (name, "Xft.hintstyle") == 0) - parse_integer (value, &(resources->xft_hintstyle)); - - return TRUE; -} - -static int -resource_parse_lines (struct resource_parser *parser) -{ - char *line, *newline; - - line = parser->buffer; - while (1) { - newline = strchr (line, '\n'); - if (newline == NULL) - break; - - *newline++ = 0; - - if (! resource_parse_line (line, parser->resources)) - break; - - line = newline; - } - - return line - parser->buffer; -} - -static void -resource_parser_init (struct resource_parser *parser, cairo_xcb_resources_t *resources) -{ - parser->buffer_size = 0; - parser->bytes_in_buffer = 0; - parser->buffer = NULL; - parser->resources = resources; -} - -static cairo_bool_t -resource_parser_update (struct resource_parser *parser, const char *data, int length) -{ - int bytes_parsed; - - if (parser->bytes_in_buffer + length + 1 > parser->buffer_size) { - parser->buffer_size = parser->bytes_in_buffer + length + 1; - parser->buffer = realloc(parser->buffer, parser->buffer_size); - if (! parser->buffer) { - parser->buffer_size = 0; - parser->bytes_in_buffer = 0; - return FALSE; - } - } - - memmove (parser->buffer + parser->bytes_in_buffer, data, length); - parser->bytes_in_buffer += length; - parser->buffer[parser->bytes_in_buffer] = 0; - - bytes_parsed = resource_parse_lines (parser); - - if (parser->bytes_in_buffer > bytes_parsed) { - memmove (parser->buffer, parser->buffer + bytes_parsed, parser->bytes_in_buffer - bytes_parsed); - parser->bytes_in_buffer -= bytes_parsed; - } else { - parser->bytes_in_buffer = 0; - } - - return TRUE; -} - -static void -resource_parser_done (struct resource_parser *parser) -{ - if (parser->bytes_in_buffer > 0) { - parser->buffer[parser->bytes_in_buffer] = 0; - resource_parse_line (parser->buffer, parser->resources); - } - - free (parser->buffer); -} - -static void -get_resources(xcb_connection_t *connection, xcb_screen_t *screen, cairo_xcb_resources_t *resources) -{ - xcb_get_property_cookie_t cookie; - xcb_get_property_reply_t *reply; - struct resource_parser parser; - int offset; - cairo_bool_t has_more_data; - - resources->xft_antialias = TRUE; - resources->xft_lcdfilter = -1; - resources->xft_hinting = TRUE; - resources->xft_hintstyle = FC_HINT_FULL; - resources->xft_rgba = FC_RGBA_UNKNOWN; - - resource_parser_init (&parser, resources); - - offset = 0; - has_more_data = FALSE; - do { - cookie = xcb_get_property (connection, 0, screen->root, XCB_ATOM_RESOURCE_MANAGER, XCB_ATOM_STRING, offset, 1024); - reply = xcb_get_property_reply (connection, cookie, NULL); - - if (reply) { - if (reply->format == 8 && reply->type == XCB_ATOM_STRING) { - char *value = (char *) xcb_get_property_value (reply); - int length = xcb_get_property_value_length (reply); - - offset += length / 4; /* X needs the offset in 'long' units */ - has_more_data = reply->bytes_after > 0; - - if (! resource_parser_update (&parser, value, length)) - has_more_data = FALSE; /* early exit on error */ - } - - free (reply); - } - } while (has_more_data); - - resource_parser_done (&parser); -} - -void -_cairo_xcb_resources_get (cairo_xcb_screen_t *screen, cairo_xcb_resources_t *resources) -{ - get_resources (screen->connection->xcb_connection, screen->xcb_screen, resources); - - if (resources->xft_rgba == FC_RGBA_UNKNOWN) { - switch (screen->subpixel_order) { - case XCB_RENDER_SUB_PIXEL_UNKNOWN: - resources->xft_rgba = FC_RGBA_UNKNOWN; - break; - case XCB_RENDER_SUB_PIXEL_HORIZONTAL_RGB: - resources->xft_rgba = FC_RGBA_RGB; - break; - case XCB_RENDER_SUB_PIXEL_HORIZONTAL_BGR: - resources->xft_rgba = FC_RGBA_BGR; - break; - case XCB_RENDER_SUB_PIXEL_VERTICAL_RGB: - resources->xft_rgba = FC_RGBA_VRGB; - break; - case XCB_RENDER_SUB_PIXEL_VERTICAL_BGR: - resources->xft_rgba = FC_RGBA_VBGR; - break; - case XCB_RENDER_SUB_PIXEL_NONE: - resources->xft_rgba = FC_RGBA_NONE; - break; - } - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-screen.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-screen.c deleted file mode 100644 index d0019f9cdff..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-screen.c +++ /dev/null @@ -1,494 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Chris Wilson - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Authors: - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-xcb-private.h" -#include "cairo-list-inline.h" - -#include "cairo-fontconfig-private.h" - -static void -_cairo_xcb_init_screen_font_options (cairo_xcb_screen_t *screen) -{ - cairo_xcb_resources_t res; - cairo_antialias_t antialias; - cairo_subpixel_order_t subpixel_order; - cairo_lcd_filter_t lcd_filter; - cairo_hint_style_t hint_style; - - _cairo_xcb_resources_get (screen, &res); - - /* the rest of the code in this function is copied from - _cairo_xlib_init_screen_font_options in cairo-xlib-screen.c */ - - if (res.xft_hinting) { - switch (res.xft_hintstyle) { - case FC_HINT_NONE: - hint_style = CAIRO_HINT_STYLE_NONE; - break; - case FC_HINT_SLIGHT: - hint_style = CAIRO_HINT_STYLE_SLIGHT; - break; - case FC_HINT_MEDIUM: - hint_style = CAIRO_HINT_STYLE_MEDIUM; - break; - case FC_HINT_FULL: - hint_style = CAIRO_HINT_STYLE_FULL; - break; - default: - hint_style = CAIRO_HINT_STYLE_DEFAULT; - } - } else { - hint_style = CAIRO_HINT_STYLE_NONE; - } - - switch (res.xft_rgba) { - case FC_RGBA_RGB: - subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; - break; - case FC_RGBA_BGR: - subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; - break; - case FC_RGBA_VRGB: - subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; - break; - case FC_RGBA_VBGR: - subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; - break; - case FC_RGBA_UNKNOWN: - case FC_RGBA_NONE: - default: - subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; - } - - switch (res.xft_lcdfilter) { - case FC_LCD_NONE: - lcd_filter = CAIRO_LCD_FILTER_NONE; - break; - case FC_LCD_DEFAULT: - lcd_filter = CAIRO_LCD_FILTER_FIR5; - break; - case FC_LCD_LIGHT: - lcd_filter = CAIRO_LCD_FILTER_FIR3; - break; - case FC_LCD_LEGACY: - lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL; - break; - default: - lcd_filter = CAIRO_LCD_FILTER_DEFAULT; - break; - } - - if (res.xft_antialias) { - if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT) - antialias = CAIRO_ANTIALIAS_GRAY; - else - antialias = CAIRO_ANTIALIAS_SUBPIXEL; - } else { - antialias = CAIRO_ANTIALIAS_NONE; - } - - cairo_font_options_set_hint_style (&screen->font_options, hint_style); - cairo_font_options_set_antialias (&screen->font_options, antialias); - cairo_font_options_set_subpixel_order (&screen->font_options, subpixel_order); - _cairo_font_options_set_lcd_filter (&screen->font_options, lcd_filter); - cairo_font_options_set_hint_metrics (&screen->font_options, CAIRO_HINT_METRICS_ON); -} - -struct pattern_cache_entry { - cairo_cache_entry_t key; - cairo_xcb_screen_t *screen; - cairo_pattern_union_t pattern; - cairo_surface_t *picture; -}; - -void -_cairo_xcb_screen_finish (cairo_xcb_screen_t *screen) -{ - int i; - - CAIRO_MUTEX_LOCK (screen->connection->screens_mutex); - cairo_list_del (&screen->link); - CAIRO_MUTEX_UNLOCK (screen->connection->screens_mutex); - - while (! cairo_list_is_empty (&screen->surfaces)) { - cairo_surface_t *surface; - - surface = &cairo_list_first_entry (&screen->surfaces, - cairo_xcb_surface_t, - link)->base; - - cairo_surface_finish (surface); - } - - while (! cairo_list_is_empty (&screen->pictures)) { - cairo_surface_t *surface; - - surface = &cairo_list_first_entry (&screen->pictures, - cairo_xcb_picture_t, - link)->base; - - cairo_surface_finish (surface); - } - - for (i = 0; i < screen->solid_cache_size; i++) - cairo_surface_destroy (screen->solid_cache[i].picture); - - for (i = 0; i < ARRAY_LENGTH (screen->stock_colors); i++) - cairo_surface_destroy (screen->stock_colors[i]); - - for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) { - if (screen->gc_depths[i] != 0) - _cairo_xcb_connection_free_gc (screen->connection, screen->gc[i]); - } - - _cairo_cache_fini (&screen->linear_pattern_cache); - _cairo_cache_fini (&screen->radial_pattern_cache); - _cairo_freelist_fini (&screen->pattern_cache_entry_freelist); - - free (screen); -} - -static cairo_bool_t -_linear_pattern_cache_entry_equal (const void *A, const void *B) -{ - const struct pattern_cache_entry *a = A, *b = B; - - return _cairo_linear_pattern_equal (&a->pattern.gradient.linear, - &b->pattern.gradient.linear); -} - -static cairo_bool_t -_radial_pattern_cache_entry_equal (const void *A, const void *B) -{ - const struct pattern_cache_entry *a = A, *b = B; - - return _cairo_radial_pattern_equal (&a->pattern.gradient.radial, - &b->pattern.gradient.radial); -} - -static void -_pattern_cache_entry_destroy (void *closure) -{ - struct pattern_cache_entry *entry = closure; - - _cairo_pattern_fini (&entry->pattern.base); - cairo_surface_destroy (entry->picture); - _cairo_freelist_free (&entry->screen->pattern_cache_entry_freelist, entry); -} - -static int _get_screen_index(cairo_xcb_connection_t *xcb_connection, - xcb_screen_t *xcb_screen) -{ - int idx = 0; - xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_connection->root); - for (; iter.rem; xcb_screen_next(&iter), idx++) - if (iter.data->root == xcb_screen->root) - return idx; - - ASSERT_NOT_REACHED; -} - -cairo_xcb_screen_t * -_cairo_xcb_screen_get (xcb_connection_t *xcb_connection, - xcb_screen_t *xcb_screen) -{ - cairo_xcb_connection_t *connection; - cairo_xcb_screen_t *screen; - cairo_status_t status; - int screen_idx; - int i; - - connection = _cairo_xcb_connection_get (xcb_connection); - if (unlikely (connection == NULL)) - return NULL; - - CAIRO_MUTEX_LOCK (connection->screens_mutex); - - cairo_list_foreach_entry (screen, - cairo_xcb_screen_t, - &connection->screens, - link) - { - if (screen->xcb_screen == xcb_screen) { - /* Maintain list in MRU order */ - if (&screen->link != connection->screens.next) - cairo_list_move (&screen->link, &connection->screens); - - goto unlock; - } - } - - screen = malloc (sizeof (cairo_xcb_screen_t)); - if (unlikely (screen == NULL)) - goto unlock; - - screen_idx = _get_screen_index(connection, xcb_screen); - - screen->connection = connection; - screen->xcb_screen = xcb_screen; - screen->has_font_options = FALSE; - screen->subpixel_order = connection->subpixel_orders[screen_idx]; - - _cairo_freelist_init (&screen->pattern_cache_entry_freelist, - sizeof (struct pattern_cache_entry)); - cairo_list_init (&screen->link); - cairo_list_init (&screen->surfaces); - cairo_list_init (&screen->pictures); - - memset (screen->gc_depths, 0, sizeof (screen->gc_depths)); - memset (screen->gc, 0, sizeof (screen->gc)); - - screen->solid_cache_size = 0; - for (i = 0; i < ARRAY_LENGTH (screen->stock_colors); i++) - screen->stock_colors[i] = NULL; - - status = _cairo_cache_init (&screen->linear_pattern_cache, - _linear_pattern_cache_entry_equal, - NULL, - _pattern_cache_entry_destroy, - 16); - if (unlikely (status)) - goto error_screen; - - status = _cairo_cache_init (&screen->radial_pattern_cache, - _radial_pattern_cache_entry_equal, - NULL, - _pattern_cache_entry_destroy, - 4); - if (unlikely (status)) - goto error_linear; - - cairo_list_add (&screen->link, &connection->screens); - -unlock: - CAIRO_MUTEX_UNLOCK (connection->screens_mutex); - - return screen; - -error_linear: - _cairo_cache_fini (&screen->linear_pattern_cache); -error_screen: - CAIRO_MUTEX_UNLOCK (connection->screens_mutex); - free (screen); - - return NULL; -} - -static xcb_gcontext_t -_create_gc (cairo_xcb_screen_t *screen, - xcb_drawable_t drawable) -{ - uint32_t values[] = { 0 }; - - return _cairo_xcb_connection_create_gc (screen->connection, drawable, - XCB_GC_GRAPHICS_EXPOSURES, - values); -} - -xcb_gcontext_t -_cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen, - xcb_drawable_t drawable, - int depth) -{ - int i; - - assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); - - for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) { - if (screen->gc_depths[i] == depth) { - screen->gc_depths[i] = 0; - return screen->gc[i]; - } - } - - return _create_gc (screen, drawable); -} - -void -_cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t gc) -{ - int i; - - assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); - - for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) { - if (screen->gc_depths[i] == 0) - break; - } - - if (i == ARRAY_LENGTH (screen->gc)) { - /* perform random substitution to ensure fair caching over depths */ - i = rand () % ARRAY_LENGTH (screen->gc); - _cairo_xcb_connection_free_gc (screen->connection, screen->gc[i]); - } - - screen->gc[i] = gc; - screen->gc_depths[i] = depth; -} - -cairo_status_t -_cairo_xcb_screen_store_linear_picture (cairo_xcb_screen_t *screen, - const cairo_linear_pattern_t *linear, - cairo_surface_t *picture) -{ - struct pattern_cache_entry *entry; - cairo_status_t status; - - assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); - - entry = _cairo_freelist_alloc (&screen->pattern_cache_entry_freelist); - if (unlikely (entry == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - entry->key.hash = _cairo_linear_pattern_hash (_CAIRO_HASH_INIT_VALUE, linear); - entry->key.size = 1; - - status = _cairo_pattern_init_copy (&entry->pattern.base, &linear->base.base); - if (unlikely (status)) { - _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); - return status; - } - - entry->picture = cairo_surface_reference (picture); - entry->screen = screen; - - status = _cairo_cache_insert (&screen->linear_pattern_cache, - &entry->key); - if (unlikely (status)) { - cairo_surface_destroy (picture); - _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_surface_t * -_cairo_xcb_screen_lookup_linear_picture (cairo_xcb_screen_t *screen, - const cairo_linear_pattern_t *linear) -{ - cairo_surface_t *picture = NULL; - struct pattern_cache_entry tmpl; - struct pattern_cache_entry *entry; - - assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); - - tmpl.key.hash = _cairo_linear_pattern_hash (_CAIRO_HASH_INIT_VALUE, linear); - _cairo_pattern_init_static_copy (&tmpl.pattern.base, &linear->base.base); - - entry = _cairo_cache_lookup (&screen->linear_pattern_cache, &tmpl.key); - if (entry != NULL) - picture = cairo_surface_reference (entry->picture); - - return picture; -} - -cairo_status_t -_cairo_xcb_screen_store_radial_picture (cairo_xcb_screen_t *screen, - const cairo_radial_pattern_t *radial, - cairo_surface_t *picture) -{ - struct pattern_cache_entry *entry; - cairo_status_t status; - - assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); - - entry = _cairo_freelist_alloc (&screen->pattern_cache_entry_freelist); - if (unlikely (entry == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - entry->key.hash = _cairo_radial_pattern_hash (_CAIRO_HASH_INIT_VALUE, radial); - entry->key.size = 1; - - status = _cairo_pattern_init_copy (&entry->pattern.base, &radial->base.base); - if (unlikely (status)) { - _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); - return status; - } - - entry->picture = cairo_surface_reference (picture); - entry->screen = screen; - - status = _cairo_cache_insert (&screen->radial_pattern_cache, &entry->key); - if (unlikely (status)) { - cairo_surface_destroy (picture); - _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); - return status; - } - - return CAIRO_STATUS_SUCCESS; -} - -cairo_surface_t * -_cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen, - const cairo_radial_pattern_t *radial) -{ - cairo_surface_t *picture = NULL; - struct pattern_cache_entry tmpl; - struct pattern_cache_entry *entry; - - assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); - - tmpl.key.hash = _cairo_radial_pattern_hash (_CAIRO_HASH_INIT_VALUE, radial); - _cairo_pattern_init_static_copy (&tmpl.pattern.base, &radial->base.base); - - entry = _cairo_cache_lookup (&screen->radial_pattern_cache, &tmpl.key); - if (entry != NULL) - picture = cairo_surface_reference (entry->picture); - - return picture; -} - -cairo_font_options_t * -_cairo_xcb_screen_get_font_options (cairo_xcb_screen_t *screen) -{ - if (! screen->has_font_options) { - _cairo_font_options_init_default (&screen->font_options); - _cairo_font_options_set_round_glyph_positions (&screen->font_options, CAIRO_ROUND_GLYPH_POS_ON); - - /* XXX: This is disabled because something seems to be merging - font options incorrectly for xcb. This effectively reverts - the changes brought in git e691d242, and restores ~150 tests - to resume passing. See mailing list archives for Sep 17, - 2014 for more discussion. */ - if (0 && ! _cairo_xcb_connection_acquire (screen->connection)) { - _cairo_xcb_init_screen_font_options (screen); - _cairo_xcb_connection_release (screen->connection); - } - - screen->has_font_options = TRUE; - } - - return &screen->font_options; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-shm.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-shm.c deleted file mode 100644 index 2be2dac5bf9..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-shm.c +++ /dev/null @@ -1,337 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributors(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - -#include "cairo-xcb-private.h" -#include "cairo-list-inline.h" -#include "cairo-mempool-private.h" - -#include -#include -#include -#include - -#define CAIRO_MAX_SHM_MEMORY (16*1024*1024) - -/* a simple buddy allocator for memory pools - * XXX fragmentation? use Doug Lea's malloc? - */ - -typedef struct _cairo_xcb_shm_mem_block cairo_xcb_shm_mem_block_t; - -typedef enum { - PENDING_WAIT, - PENDING_POLL -} shm_wait_type_t; - -struct _cairo_xcb_shm_mem_pool { - int shmid; - uint32_t shmseg; - void *shm; - - cairo_mempool_t mem; - - cairo_list_t link; -}; - -static void -_cairo_xcb_shm_mem_pool_destroy (cairo_xcb_shm_mem_pool_t *pool) -{ - cairo_list_del (&pool->link); - - shmdt (pool->shm); - _cairo_mempool_fini (&pool->mem); - - free (pool); -} - -static void -_cairo_xcb_shm_info_finalize (cairo_xcb_shm_info_t *shm_info) -{ - cairo_xcb_connection_t *connection = shm_info->connection; - - assert (CAIRO_MUTEX_IS_LOCKED (connection->shm_mutex)); - - _cairo_mempool_free (&shm_info->pool->mem, shm_info->mem); - _cairo_freepool_free (&connection->shm_info_freelist, shm_info); - - /* scan for old, unused pools - hold at least one in reserve */ - if (! cairo_list_is_singular (&connection->shm_pools)) - { - cairo_xcb_shm_mem_pool_t *pool, *next; - cairo_list_t head; - - cairo_list_init (&head); - cairo_list_move (connection->shm_pools.next, &head); - - cairo_list_foreach_entry_safe (pool, next, cairo_xcb_shm_mem_pool_t, - &connection->shm_pools, link) - { - if (pool->mem.free_bytes == pool->mem.max_bytes) { - _cairo_xcb_connection_shm_detach (connection, pool->shmseg); - _cairo_xcb_shm_mem_pool_destroy (pool); - } - } - - cairo_list_move (head.next, &connection->shm_pools); - } -} - -static void -_cairo_xcb_shm_process_pending (cairo_xcb_connection_t *connection, shm_wait_type_t wait) -{ - cairo_xcb_shm_info_t *info, *next; - xcb_get_input_focus_reply_t *reply; - - assert (CAIRO_MUTEX_IS_LOCKED (connection->shm_mutex)); - cairo_list_foreach_entry_safe (info, next, cairo_xcb_shm_info_t, - &connection->shm_pending, pending) - { - switch (wait) { - case PENDING_WAIT: - reply = xcb_wait_for_reply (connection->xcb_connection, - info->sync.sequence, NULL); - break; - case PENDING_POLL: - if (! xcb_poll_for_reply (connection->xcb_connection, - info->sync.sequence, - (void **) &reply, NULL)) - /* We cannot be sure the server finished with this image yet, so - * try again later. All other shm info are guaranteed to have a - * larger sequence number and thus don't have to be checked. */ - return; - break; - default: - /* silence Clang static analyzer warning */ - ASSERT_NOT_REACHED; - reply = NULL; - } - - free (reply); - cairo_list_del (&info->pending); - _cairo_xcb_shm_info_finalize (info); - } -} - -cairo_int_status_t -_cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection, - size_t size, - cairo_bool_t might_reuse, - cairo_xcb_shm_info_t **shm_info_out) -{ - cairo_xcb_shm_info_t *shm_info; - cairo_xcb_shm_mem_pool_t *pool, *next; - size_t bytes, maxbits = 16, minbits = 8; - size_t shm_allocated = 0; - void *mem = NULL; - cairo_status_t status; - - assert (connection->flags & CAIRO_XCB_HAS_SHM); - - CAIRO_MUTEX_LOCK (connection->shm_mutex); - _cairo_xcb_shm_process_pending (connection, PENDING_POLL); - - if (might_reuse) { - cairo_list_foreach_entry (shm_info, cairo_xcb_shm_info_t, - &connection->shm_pending, pending) { - if (shm_info->size >= size) { - cairo_list_del (&shm_info->pending); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - - xcb_discard_reply (connection->xcb_connection, shm_info->sync.sequence); - shm_info->sync.sequence = XCB_NONE; - - *shm_info_out = shm_info; - return CAIRO_STATUS_SUCCESS; - } - } - } - - cairo_list_foreach_entry_safe (pool, next, cairo_xcb_shm_mem_pool_t, - &connection->shm_pools, link) - { - if (pool->mem.free_bytes > size) { - mem = _cairo_mempool_alloc (&pool->mem, size); - if (mem != NULL) { - /* keep the active pools towards the front */ - cairo_list_move (&pool->link, &connection->shm_pools); - goto allocate_shm_info; - } - } - /* scan for old, unused pools */ - if (pool->mem.free_bytes == pool->mem.max_bytes) { - _cairo_xcb_connection_shm_detach (connection, - pool->shmseg); - _cairo_xcb_shm_mem_pool_destroy (pool); - } else { - shm_allocated += pool->mem.max_bytes; - } - } - - if (unlikely (shm_allocated >= CAIRO_MAX_SHM_MEMORY)) { - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pool = malloc (sizeof (cairo_xcb_shm_mem_pool_t)); - if (unlikely (pool == NULL)) { - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - bytes = 1 << maxbits; - while (bytes <= size) - bytes <<= 1, maxbits++; - bytes <<= 3; - - do { - pool->shmid = shmget (IPC_PRIVATE, bytes, IPC_CREAT | 0600); - if (pool->shmid != -1) - break; - - /* If the allocation failed because we asked for too much memory, we try - * again with a smaller request, as long as our allocation still fits. */ - bytes >>= 1; - if (errno != EINVAL || bytes < size) - break; - } while (TRUE); - if (pool->shmid == -1) { - int err = errno; - if (! (err == EINVAL || err == ENOMEM)) - connection->flags &= ~CAIRO_XCB_HAS_SHM; - free (pool); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - pool->shm = shmat (pool->shmid, NULL, 0); - if (unlikely (pool->shm == (char *) -1)) { - shmctl (pool->shmid, IPC_RMID, NULL); - free (pool); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - status = _cairo_mempool_init (&pool->mem, pool->shm, bytes, - minbits, maxbits - minbits + 1); - if (unlikely (status)) { - shmdt (pool->shm); - free (pool); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - return status; - } - - pool->shmseg = _cairo_xcb_connection_shm_attach (connection, pool->shmid, FALSE); - shmctl (pool->shmid, IPC_RMID, NULL); - - cairo_list_add (&pool->link, &connection->shm_pools); - mem = _cairo_mempool_alloc (&pool->mem, size); - - allocate_shm_info: - shm_info = _cairo_freepool_alloc (&connection->shm_info_freelist); - if (unlikely (shm_info == NULL)) { - _cairo_mempool_free (&pool->mem, mem); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - shm_info->connection = connection; - shm_info->pool = pool; - shm_info->shm = pool->shmseg; - shm_info->size = size; - shm_info->offset = (char *) mem - (char *) pool->shm; - shm_info->mem = mem; - shm_info->sync.sequence = XCB_NONE; - - /* scan for old, unused pools */ - cairo_list_foreach_entry_safe (pool, next, cairo_xcb_shm_mem_pool_t, - &connection->shm_pools, link) - { - if (pool->mem.free_bytes == pool->mem.max_bytes) { - _cairo_xcb_connection_shm_detach (connection, - pool->shmseg); - _cairo_xcb_shm_mem_pool_destroy (pool); - } - } - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); - - *shm_info_out = shm_info; - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_xcb_shm_info_destroy (cairo_xcb_shm_info_t *shm_info) -{ - cairo_xcb_connection_t *connection = shm_info->connection; - - /* We can only return shm_info->mem to the allocator when we can be sure - * that the X server no longer reads from it. Since the X server processes - * requests in order, we send a GetInputFocus here. - * _cairo_xcb_shm_process_pending () will later check if the reply for that - * request was received and then actually mark this memory area as free. */ - - CAIRO_MUTEX_LOCK (connection->shm_mutex); - assert (shm_info->sync.sequence == XCB_NONE); - shm_info->sync = xcb_get_input_focus (connection->xcb_connection); - - cairo_list_init (&shm_info->pending); - cairo_list_add_tail (&shm_info->pending, &connection->shm_pending); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); -} - -void -_cairo_xcb_connection_shm_mem_pools_flush (cairo_xcb_connection_t *connection) -{ - CAIRO_MUTEX_LOCK (connection->shm_mutex); - _cairo_xcb_shm_process_pending (connection, PENDING_WAIT); - CAIRO_MUTEX_UNLOCK (connection->shm_mutex); -} - -void -_cairo_xcb_connection_shm_mem_pools_fini (cairo_xcb_connection_t *connection) -{ - assert (cairo_list_is_empty (&connection->shm_pending)); - while (! cairo_list_is_empty (&connection->shm_pools)) { - _cairo_xcb_shm_mem_pool_destroy (cairo_list_first_entry (&connection->shm_pools, - cairo_xcb_shm_mem_pool_t, - link)); - } -} - -#endif /* CAIRO_HAS_XCB_SHM_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-core.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-core.c deleted file mode 100644 index 9c0c0a0957d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-core.c +++ /dev/null @@ -1,639 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-boxes-private.h" -#include "cairo-xcb-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-backend-private.h" - -/* XXX dithering */ - -typedef struct _cairo_xcb_pixmap { - cairo_surface_t base; - - cairo_xcb_connection_t *connection; - cairo_xcb_screen_t *screen; - - cairo_surface_t *owner; - xcb_pixmap_t pixmap; - int width; - int height; - int depth; - int x0, y0; - cairo_bool_t repeat; -} cairo_xcb_pixmap_t; - -static cairo_status_t -_cairo_xcb_pixmap_finish (void *abstract_surface) -{ - cairo_xcb_pixmap_t *surface = abstract_surface; - cairo_status_t status; - - if (surface->owner != NULL) { - cairo_surface_destroy (surface->owner); - } else { - status = _cairo_xcb_connection_acquire (surface->connection); - if (unlikely (status)) - return status; - - _cairo_xcb_connection_free_pixmap (surface->connection, - surface->pixmap); - _cairo_xcb_connection_release (surface->connection); - } - - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t _cairo_xcb_pixmap_backend = { - CAIRO_SURFACE_TYPE_XCB, - _cairo_xcb_pixmap_finish, -}; - -static cairo_xcb_pixmap_t * -_cairo_xcb_pixmap_create (cairo_xcb_surface_t *target, - int width, int height) -{ - cairo_xcb_pixmap_t *surface; - - surface = malloc (sizeof (cairo_xcb_pixmap_t)); - if (unlikely (surface == NULL)) - return (cairo_xcb_pixmap_t *) - _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_xcb_pixmap_backend, - NULL, - target->base.content); - - surface->connection = target->connection; - surface->screen = target->screen; - surface->owner = NULL; - surface->width = width; - surface->height = height; - surface->depth = target->depth; - surface->x0 = surface->y0 = 0; - surface->repeat = FALSE; - - surface->pixmap = - _cairo_xcb_connection_create_pixmap (surface->connection, - surface->depth, - target->drawable, - width, height); - - return surface; -} - -static cairo_xcb_pixmap_t * -_cairo_xcb_pixmap_copy (cairo_xcb_surface_t *target) -{ - cairo_xcb_pixmap_t *surface; - - surface = malloc (sizeof (cairo_xcb_pixmap_t)); - if (unlikely (surface == NULL)) - return (cairo_xcb_pixmap_t *) - _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_xcb_pixmap_backend, - NULL, - target->base.content); - - surface->connection = target->connection; - surface->screen = target->screen; - surface->pixmap = target->drawable; - surface->owner = cairo_surface_reference (&target->base); - surface->width = target->width; - surface->height = target->height; - surface->depth = target->depth; - surface->x0 = surface->y0 = 0; - surface->repeat = FALSE; - - return surface; -} - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS -static cairo_status_t -_cairo_xcb_shm_image_create_shm (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format, - int width, int height, - cairo_image_surface_t **image_out, - cairo_xcb_shm_info_t **shm_info_out) -{ - cairo_surface_t *image = NULL; - cairo_xcb_shm_info_t *shm_info = NULL; - cairo_status_t status; - size_t size, stride; - - if (! (connection->flags & CAIRO_XCB_HAS_SHM)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, PIXMAN_FORMAT_BPP (pixman_format)); - size = stride * height; - if (size <= CAIRO_XCB_SHM_SMALL_IMAGE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_xcb_connection_allocate_shm_info (connection, size, - FALSE, &shm_info); - if (unlikely (status)) - return status; - - image = _cairo_image_surface_create_with_pixman_format (shm_info->mem, - pixman_format, - width, height, - stride); - status = image->status; - if (unlikely (status)) { - _cairo_xcb_shm_info_destroy (shm_info); - return status; - } - - status = _cairo_user_data_array_set_data (&image->user_data, - (const cairo_user_data_key_t *) connection, - shm_info, - (cairo_destroy_func_t) _cairo_xcb_shm_info_destroy); - - if (unlikely (status)) { - cairo_surface_destroy (image); - _cairo_xcb_shm_info_destroy (shm_info); - return status; - } - - *image_out = (cairo_image_surface_t *) image; - *shm_info_out = shm_info; - return CAIRO_STATUS_SUCCESS; -} -#else -static cairo_status_t -_cairo_xcb_shm_image_create_shm (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format, - int width, int height, - cairo_image_surface_t **image_out, - cairo_xcb_shm_info_t **shm_info_out) -{ - return CAIRO_INT_STATUS_UNSUPPORTED; -} -#endif - -cairo_status_t -_cairo_xcb_shm_image_create (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format, - int width, int height, - cairo_image_surface_t **image_out, - cairo_xcb_shm_info_t **shm_info_out) -{ - cairo_surface_t *image = NULL; - cairo_xcb_shm_info_t *shm_info = NULL; - cairo_status_t status; - - status = _cairo_xcb_shm_image_create_shm (connection, - pixman_format, - width, - height, - image_out, - shm_info_out); - - if (status != CAIRO_STATUS_SUCCESS) { - image = _cairo_image_surface_create_with_pixman_format (NULL, - pixman_format, - width, height, - 0); - status = image->status; - if (unlikely (status)) - return status; - - *image_out = (cairo_image_surface_t *) image; - *shm_info_out = shm_info; - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_xcb_pixmap_t * -_pixmap_from_image (cairo_xcb_surface_t *target, - xcb_render_pictformat_t format, - cairo_image_surface_t *image, - cairo_xcb_shm_info_t *shm_info) -{ - xcb_gcontext_t gc; - cairo_xcb_pixmap_t *pixmap; - - pixmap = _cairo_xcb_pixmap_create (target, - image->width, - image->height); - if (unlikely (pixmap->base.status)) - return pixmap; - - gc = _cairo_xcb_screen_get_gc (target->screen, pixmap->pixmap, image->depth); - - if (shm_info != NULL) { - _cairo_xcb_connection_shm_put_image (target->connection, - pixmap->pixmap, gc, - image->width, image->height, - 0, 0, - image->width, image->height, - 0, 0, - image->depth, - shm_info->shm, - shm_info->offset); - } else { - int len; - - /* Do we need to trim the image? */ - len = CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, - PIXMAN_FORMAT_BPP (image->pixman_format)); - if (len == image->stride) { - _cairo_xcb_connection_put_image (target->connection, - pixmap->pixmap, gc, - image->width, image->height, - 0, 0, - image->depth, - image->stride, - image->data); - } else { - _cairo_xcb_connection_put_subimage (target->connection, - pixmap->pixmap, gc, - 0, 0, - image->width, image->height, - PIXMAN_FORMAT_BPP (image->pixman_format) / 8, - image->stride, - 0, 0, - image->depth, - image->data); - - } - } - - _cairo_xcb_screen_put_gc (target->screen, image->depth, gc); - - return pixmap; -} - -static cairo_xcb_pixmap_t * -_render_to_pixmap (cairo_xcb_surface_t *target, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - cairo_image_surface_t *image; - cairo_xcb_shm_info_t *shm_info; - cairo_pattern_union_t copy; - cairo_status_t status; - cairo_xcb_pixmap_t *pixmap; - - status = _cairo_xcb_shm_image_create (target->screen->connection, - target->pixman_format, - extents->width, extents->height, - &image, &shm_info); - if (unlikely (status)) - return (cairo_xcb_pixmap_t *) _cairo_surface_create_in_error (status); - - _cairo_pattern_init_static_copy (©.base, pattern); - cairo_matrix_translate (©.base.matrix, -extents->x, -extents->y); - status = _cairo_surface_paint (&image->base, - CAIRO_OPERATOR_SOURCE, - ©.base, - NULL); - if (unlikely (status)) { - cairo_surface_destroy (&image->base); - return (cairo_xcb_pixmap_t *) _cairo_surface_create_in_error (status); - } - - pixmap = _pixmap_from_image (target, target->xrender_format, image, shm_info); - cairo_surface_destroy (&image->base); - - if (unlikely (pixmap->base.status)) - return pixmap; - - pixmap->x0 = -extents->x; - pixmap->y0 = -extents->y; - return pixmap; -} - -static cairo_xcb_pixmap_t * -_copy_to_pixmap (cairo_xcb_surface_t *source) -{ - cairo_xcb_pixmap_t *pixmap; - - /* If the source may be a window, we need to copy it and its children - * via a temporary pixmap so that we can IncludeInferiors on the source - * and use ClipByChildren on the destination. - */ - if (source->owns_pixmap) { - pixmap = _cairo_xcb_pixmap_copy (source); - if (unlikely (pixmap->base.status)) - return pixmap; - } else { - uint32_t values[1]; - xcb_gcontext_t gc; - - pixmap = _cairo_xcb_pixmap_create (source, - source->width, - source->height); - if (unlikely (pixmap->base.status)) - return pixmap; - - gc = _cairo_xcb_screen_get_gc (source->screen, - pixmap->pixmap, - pixmap->depth); - - values[0] = TRUE; - _cairo_xcb_connection_change_gc (pixmap->connection, gc, - XCB_GC_SUBWINDOW_MODE, values); - - _cairo_xcb_connection_copy_area (pixmap->connection, - source->drawable, - pixmap->pixmap, gc, - 0, 0, - 0, 0, - source->width, - source->height); - - values[0] = FALSE; - _cairo_xcb_connection_change_gc (pixmap->connection, gc, - XCB_GC_SUBWINDOW_MODE, values); - - _cairo_xcb_screen_put_gc (source->screen, - pixmap->depth, - gc); - } - - return pixmap; -} -static cairo_xcb_pixmap_t * -_cairo_xcb_surface_pixmap (cairo_xcb_surface_t *target, - const cairo_surface_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - int tx, int ty) -{ - cairo_surface_t *source; - cairo_xcb_pixmap_t *pixmap; - - source = pattern->surface; - pixmap = (cairo_xcb_pixmap_t *) - _cairo_surface_has_snapshot (source, &_cairo_xcb_pixmap_backend); - if (pixmap != NULL && pixmap->screen == target->screen) - return (cairo_xcb_pixmap_t *) cairo_surface_reference (&pixmap->base); - - if (_cairo_surface_is_xcb(source) && - ((cairo_xcb_surface_t *) source)->screen == target->screen) - { - cairo_xcb_surface_t *xcb_source = (cairo_xcb_surface_t *) source; - - if (xcb_source->depth == target->depth) - pixmap = _copy_to_pixmap (xcb_source); - } -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS - else if (source->type == CAIRO_SURFACE_TYPE_XLIB && - ((cairo_xlib_xcb_surface_t *) source)->xcb->screen == target->screen) - { - cairo_xcb_surface_t *xcb_source = ((cairo_xlib_xcb_surface_t *) source)->xcb; - - if (xcb_source->depth == target->depth) - pixmap = _copy_to_pixmap (xcb_source); - } -#endif - - if (pixmap == NULL) { - cairo_rectangle_int_t rect; - - if (! _cairo_surface_get_extents (source, &rect)) { - rect.x = rect.y = 0; - rect.width = target->width; - rect.height = target->height; - } - - pixmap = _render_to_pixmap (target, &pattern->base, &rect); - } - - if (unlikely (pixmap->base.status)) - return pixmap; - - _cairo_surface_attach_snapshot (source, &pixmap->base, NULL); - - if (pattern->base.extend != CAIRO_EXTEND_NONE) { - if (extents->x < 0 || extents->y < 0 || - extents->x + extents->width > pixmap->width || - extents->y + extents->height > pixmap->height) - { - pixmap->repeat = TRUE; - } - } - - pixmap->x0 += tx; - pixmap->y0 += ty; - - return pixmap; -} - -static cairo_xcb_pixmap_t * -_cairo_xcb_pixmap_for_pattern (cairo_xcb_surface_t *target, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - int tx, ty; - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SURFACE: - /* Core can only perform a native, unscaled blit, but can handle tiles */ - if (_cairo_matrix_is_integer_translation (&pattern->matrix, &tx, &ty)) { - switch (pattern->extend) { - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_REPEAT: - return _cairo_xcb_surface_pixmap (target, - (cairo_surface_pattern_t *) pattern, - extents, tx, ty); - - default: - case CAIRO_EXTEND_PAD: - case CAIRO_EXTEND_REFLECT: - break; - } - } - /* fallthrough */ - case CAIRO_PATTERN_TYPE_LINEAR: - case CAIRO_PATTERN_TYPE_RADIAL: - case CAIRO_PATTERN_TYPE_MESH: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _render_to_pixmap (target, pattern, extents); - - default: - case CAIRO_PATTERN_TYPE_SOLID: - ASSERT_NOT_REACHED; - return NULL; - } -} - -cairo_status_t -_cairo_xcb_surface_core_copy_boxes (cairo_xcb_surface_t *dst, - const cairo_pattern_t *src_pattern, - const cairo_rectangle_int_t *extents, - const cairo_boxes_t *boxes) -{ - cairo_xcb_pixmap_t *src; - const struct _cairo_boxes_chunk *chunk; - xcb_gcontext_t gc; - cairo_status_t status; - - status = _cairo_xcb_connection_acquire (dst->connection); - if (unlikely (status)) - return status; - - src = _cairo_xcb_pixmap_for_pattern (dst, src_pattern, extents); - status = src->base.status; - if (unlikely (status)) - goto CLEANUP_CONNECTION; - - assert (src->depth == dst->depth); - - gc = _cairo_xcb_screen_get_gc (dst->screen, src->pixmap, src->depth); - - if (src->repeat) { - uint32_t mask = - XCB_GC_FILL_STYLE | - XCB_GC_TILE | - XCB_GC_TILE_STIPPLE_ORIGIN_X | - XCB_GC_TILE_STIPPLE_ORIGIN_Y; - uint32_t values[] = { - XCB_FILL_STYLE_TILED, - src->pixmap, - - src->x0, - src->y0, - }; - xcb_rectangle_t *xcb_rects; - - _cairo_xcb_connection_change_gc (dst->connection, gc, mask, values); - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - int i; - - xcb_rects = (xcb_rectangle_t *) chunk->base; - - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_round (chunk->base[i].p1.x); - int x2 = _cairo_fixed_integer_round (chunk->base[i].p2.x); - int y1 = _cairo_fixed_integer_round (chunk->base[i].p1.y); - int y2 = _cairo_fixed_integer_round (chunk->base[i].p2.y); - - xcb_rects[i].x = x1; - xcb_rects[i].y = y1; - xcb_rects[i].width = x2 - x1; - xcb_rects[i].height = y2 - y1; - } - _cairo_xcb_connection_poly_fill_rectangle (dst->connection, - dst->drawable, - gc, chunk->count, xcb_rects); - } - - values[0] = 0; - _cairo_xcb_connection_change_gc (dst->connection, gc, XCB_GC_FILL_STYLE, values); - } else { - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - int i; - - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_round (chunk->base[i].p1.x); - int x2 = _cairo_fixed_integer_round (chunk->base[i].p2.x); - int y1 = _cairo_fixed_integer_round (chunk->base[i].p1.y); - int y2 = _cairo_fixed_integer_round (chunk->base[i].p2.y); - - _cairo_xcb_connection_copy_area (dst->connection, - src->pixmap, - dst->drawable, gc, - src->x0 + x1, - src->y0 + y1, - x1, y1, - x2 - x1, y2 - y1); - } - } - } - - _cairo_xcb_screen_put_gc (dst->screen, src->depth, gc); - cairo_surface_destroy (&src->base); - - CLEANUP_CONNECTION: - _cairo_xcb_connection_release (dst->connection); - - return status; -} - -cairo_status_t -_cairo_xcb_surface_core_fill_boxes (cairo_xcb_surface_t *dst, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - struct _cairo_boxes_chunk *chunk; - xcb_gcontext_t gc; - cairo_status_t status; - - status = _cairo_xcb_connection_acquire (dst->connection); - if (unlikely (status)) - return status; - - gc = _cairo_xcb_screen_get_gc (dst->screen, dst->drawable, dst->depth); - -#if 0 - xcb_pixmap_t source; - - source = _dither_source (dst, color); - XSetTSOrigin (surface->dpy, gc, 0, 0); - XSetTile (surface->dpy, gc, source); -#endif - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - xcb_rectangle_t *xcb_rects; - int i; - - xcb_rects = (xcb_rectangle_t *) chunk->base; - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_round (chunk->base[i].p1.x); - int x2 = _cairo_fixed_integer_round (chunk->base[i].p2.x); - int y1 = _cairo_fixed_integer_round (chunk->base[i].p1.y); - int y2 = _cairo_fixed_integer_round (chunk->base[i].p2.y); - - xcb_rects[i].x = x1; - xcb_rects[i].y = y1; - xcb_rects[i].width = x2 - x1; - xcb_rects[i].height = y2 - y1; - } - - _cairo_xcb_connection_poly_fill_rectangle (dst->connection, - dst->drawable, gc, - chunk->count, xcb_rects); - } - - _cairo_xcb_screen_put_gc (dst->screen, dst->depth, gc); - _cairo_xcb_connection_release (dst->connection); - - return CAIRO_STATUS_SUCCESS; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-render.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-render.c deleted file mode 100644 index 1a086a24fa1..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface-render.c +++ /dev/null @@ -1,4878 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "cairo-xcb-private.h" - -#include "cairo-boxes-private.h" -#include "cairo-clip-inline.h" -#include "cairo-clip-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-region-private.h" -#include "cairo-surface-offset-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-private.h" -#include "cairo-traps-private.h" -#include "cairo-recording-surface-inline.h" -#include "cairo-paginated-private.h" -#include "cairo-pattern-inline.h" - -#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ - -static cairo_status_t -_clip_and_composite_boxes (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src, - cairo_boxes_t *boxes, - cairo_composite_rectangles_t *extents); - -static inline cairo_xcb_connection_t * -_picture_to_connection (cairo_xcb_picture_t *picture) -{ - return (cairo_xcb_connection_t *) picture->base.device; -} - -static void -_cairo_xcb_surface_ensure_picture (cairo_xcb_surface_t *surface); - -static uint32_t -hars_petruska_f54_1_random (void) -{ -#define rol(x,k) ((x << k) | (x >> (32-k))) - static uint32_t x; - return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; -#undef rol -} - -static cairo_status_t -_cairo_xcb_picture_finish (void *abstract_surface) -{ - cairo_xcb_picture_t *surface = abstract_surface; - cairo_xcb_connection_t *connection = _picture_to_connection (surface); - cairo_status_t status; - - status = _cairo_xcb_connection_acquire (connection); - cairo_list_del (&surface->link); - if (unlikely (status)) - return status; - - _cairo_xcb_connection_render_free_picture (connection, surface->picture); - - _cairo_xcb_connection_release (connection); - - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t _cairo_xcb_picture_backend = { - CAIRO_SURFACE_TYPE_XCB, - _cairo_xcb_picture_finish, -}; - -static const struct xcb_render_transform_t identity_transform = { - 1 << 16, 0, 0, - 0, 1 << 16, 0, - 0, 0, 1 << 16, -}; - -static cairo_xcb_picture_t * -_cairo_xcb_picture_create (cairo_xcb_screen_t *screen, - pixman_format_code_t pixman_format, - xcb_render_pictformat_t xrender_format, - int width, int height) -{ - cairo_xcb_picture_t *surface; - - surface = malloc (sizeof (cairo_xcb_picture_t)); - if (unlikely (surface == NULL)) - return (cairo_xcb_picture_t *) - _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_xcb_picture_backend, - &screen->connection->device, - _cairo_content_from_pixman_format (pixman_format)); - - cairo_list_add (&surface->link, &screen->pictures); - - surface->screen = screen; - surface->picture = _cairo_xcb_connection_get_xid (screen->connection); - surface->pixman_format = pixman_format; - surface->xrender_format = xrender_format; - - surface->x0 = surface->y0 = 0; - surface->x = surface->y = 0; - surface->width = width; - surface->height = height; - - surface->transform = identity_transform; - surface->extend = CAIRO_EXTEND_NONE; - surface->filter = CAIRO_FILTER_NEAREST; - surface->has_component_alpha = FALSE; - - return surface; -} - -static inline cairo_bool_t -_operator_is_supported (uint32_t flags, cairo_operator_t op) -{ - if (op <= CAIRO_OPERATOR_SATURATE) - return TRUE; - - /* Can we use PDF operators? */ -#if CAIRO_XCB_RENDER_AT_LEAST(0, 11) - if (op <= CAIRO_OPERATOR_HSL_LUMINOSITY) - return flags & CAIRO_XCB_RENDER_HAS_PDF_OPERATORS; -#endif - - return FALSE; -} - -static int -_render_operator (cairo_operator_t op) -{ -#define C(x,y) case CAIRO_OPERATOR_##x: return XCB_RENDER_PICT_OP_##y - switch (op) { - C(CLEAR, CLEAR); - C(SOURCE, SRC); - - C(OVER, OVER); - C(IN, IN); - C(OUT, OUT); - C(ATOP, ATOP); - - C(DEST, DST); - C(DEST_OVER, OVER_REVERSE); - C(DEST_IN, IN_REVERSE); - C(DEST_OUT, OUT_REVERSE); - C(DEST_ATOP, ATOP_REVERSE); - - C(XOR, XOR); - C(ADD, ADD); - C(SATURATE, SATURATE); - - /* PDF operators were added in RENDER 0.11, check if the xcb headers have - * the defines, else fall through to the default case. */ -#if CAIRO_XCB_RENDER_AT_LEAST(0, 11) -#define BLEND(x,y) C(x,y) -#else -#define BLEND(x,y) case CAIRO_OPERATOR_##x: -#endif - BLEND(MULTIPLY, MULTIPLY); - BLEND(SCREEN, SCREEN); - BLEND(OVERLAY, OVERLAY); - BLEND(DARKEN, DARKEN); - BLEND(LIGHTEN, LIGHTEN); - BLEND(COLOR_DODGE, COLOR_DODGE); - BLEND(COLOR_BURN, COLOR_BURN); - BLEND(HARD_LIGHT, HARD_LIGHT); - BLEND(SOFT_LIGHT, SOFT_LIGHT); - BLEND(DIFFERENCE, DIFFERENCE); - BLEND(EXCLUSION, EXCLUSION); - BLEND(HSL_HUE, HSL_HUE); - BLEND(HSL_SATURATION, HSL_SATURATION); - BLEND(HSL_COLOR, HSL_COLOR); - BLEND(HSL_LUMINOSITY, HSL_LUMINOSITY); - - default: - ASSERT_NOT_REACHED; - return XCB_RENDER_PICT_OP_OVER; - } -} - -static cairo_status_t -_cairo_xcb_surface_set_clip_region (cairo_xcb_surface_t *surface, - cairo_region_t *region) -{ - xcb_rectangle_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (xcb_rectangle_t)]; - xcb_rectangle_t *rects = stack_rects; - int i, num_rects; - - num_rects = cairo_region_num_rectangles (region); - - if (num_rects > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (num_rects, sizeof (xcb_rectangle_t)); - if (unlikely (rects == NULL)) { - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - } - - for (i = 0; i < num_rects; i++) { - cairo_rectangle_int_t rect; - - cairo_region_get_rectangle (region, i, &rect); - - rects[i].x = rect.x; - rects[i].y = rect.y; - rects[i].width = rect.width; - rects[i].height = rect.height; - } - - _cairo_xcb_connection_render_set_picture_clip_rectangles (surface->connection, - surface->picture, - 0, 0, - num_rects, rects); - - if (rects != stack_rects) - free (rects); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_xcb_surface_clear_clip_region (cairo_xcb_surface_t *surface) -{ - uint32_t values[] = { XCB_NONE }; - _cairo_xcb_connection_render_change_picture (surface->connection, - surface->picture, - XCB_RENDER_CP_CLIP_MASK, - values); -} - -static void -_cairo_xcb_surface_set_precision (cairo_xcb_surface_t *surface, - cairo_antialias_t antialias) -{ - cairo_xcb_connection_t *connection = surface->connection; - uint32_t precision; - - if (connection->force_precision != -1) - precision = connection->force_precision; - else switch (antialias) { - default: - case CAIRO_ANTIALIAS_DEFAULT: - case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_NONE: - case CAIRO_ANTIALIAS_FAST: - case CAIRO_ANTIALIAS_GOOD: - precision = XCB_RENDER_POLY_MODE_IMPRECISE; - break; - case CAIRO_ANTIALIAS_SUBPIXEL: - case CAIRO_ANTIALIAS_BEST: - precision = XCB_RENDER_POLY_MODE_PRECISE; - break; - } - - if (surface->precision != precision) { - _cairo_xcb_connection_render_change_picture (connection, - surface->picture, - XCB_RENDER_CP_POLY_MODE, - &precision); - surface->precision = precision; - } -} - - -static void -_cairo_xcb_surface_ensure_picture (cairo_xcb_surface_t *surface) -{ - assert (surface->fallback == NULL); - if (surface->picture == XCB_NONE) { - uint32_t values[1]; - uint32_t flags = 0; - - if (surface->precision != XCB_RENDER_POLY_MODE_PRECISE) { - flags |= XCB_RENDER_CP_POLY_MODE; - values[0] = surface->precision; - } - - surface->picture = _cairo_xcb_connection_get_xid (surface->connection); - _cairo_xcb_connection_render_create_picture (surface->connection, - surface->picture, - surface->drawable, - surface->xrender_format, - flags, values); - } -} - -static cairo_xcb_picture_t * -_picture_from_image (cairo_xcb_surface_t *target, - xcb_render_pictformat_t format, - cairo_image_surface_t *image, - cairo_xcb_shm_info_t *shm_info) -{ - xcb_pixmap_t pixmap; - xcb_gcontext_t gc; - cairo_xcb_picture_t *picture; - - pixmap = _cairo_xcb_connection_create_pixmap (target->connection, - image->depth, - target->drawable, - image->width, image->height); - - gc = _cairo_xcb_screen_get_gc (target->screen, pixmap, image->depth); - - if (shm_info != NULL) { - _cairo_xcb_connection_shm_put_image (target->connection, - pixmap, gc, - image->width, image->height, - 0, 0, - image->width, image->height, - 0, 0, - image->depth, - shm_info->shm, - shm_info->offset); - } else { - int len; - - /* Do we need to trim the image? */ - len = CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, PIXMAN_FORMAT_BPP (image->pixman_format)); - if (len == image->stride) { - _cairo_xcb_connection_put_image (target->connection, - pixmap, gc, - image->width, image->height, - 0, 0, - image->depth, - image->stride, - image->data); - } else { - _cairo_xcb_connection_put_subimage (target->connection, - pixmap, gc, - 0, 0, - image->width, image->height, - PIXMAN_FORMAT_BPP (image->pixman_format) / 8, - image->stride, - 0, 0, - image->depth, - image->data); - - } - } - - _cairo_xcb_screen_put_gc (target->screen, image->depth, gc); - - picture = _cairo_xcb_picture_create (target->screen, - image->pixman_format, format, - image->width, image->height); - if (likely (picture->base.status == CAIRO_STATUS_SUCCESS)) { - _cairo_xcb_connection_render_create_picture (target->connection, - picture->picture, pixmap, format, - 0, 0); - } - - _cairo_xcb_connection_free_pixmap (target->connection, pixmap); - - return picture; -} - -static cairo_bool_t -_pattern_is_supported (uint32_t flags, - const cairo_pattern_t *pattern) - -{ - if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) - return TRUE; - - switch (pattern->extend) { - default: - ASSERT_NOT_REACHED; - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_REPEAT: - break; - case CAIRO_EXTEND_PAD: - case CAIRO_EXTEND_REFLECT: - if ((flags & CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT) == 0) - return FALSE; - } - - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - switch (pattern->filter) { - case CAIRO_FILTER_FAST: - case CAIRO_FILTER_NEAREST: - return (flags & CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM) || - _cairo_matrix_is_integer_translation (&pattern->matrix, NULL, NULL); - case CAIRO_FILTER_GOOD: - return flags & CAIRO_XCB_RENDER_HAS_FILTER_GOOD; - case CAIRO_FILTER_BEST: - return flags & CAIRO_XCB_RENDER_HAS_FILTER_BEST; - case CAIRO_FILTER_BILINEAR: - case CAIRO_FILTER_GAUSSIAN: - default: - return flags & CAIRO_XCB_RENDER_HAS_FILTERS; - } - } else if (pattern->type == CAIRO_PATTERN_TYPE_MESH) { - return FALSE; - } else { /* gradient */ - if ((flags & CAIRO_XCB_RENDER_HAS_GRADIENTS) == 0) - return FALSE; - - /* The RENDER specification says that the inner circle has to be - * completely contained inside the outer one. */ - if (pattern->type == CAIRO_PATTERN_TYPE_RADIAL && - ! _cairo_radial_pattern_focus_is_inside ((cairo_radial_pattern_t *) pattern)) - { - return FALSE; - } - return TRUE; - } -} - -static void -_cairo_xcb_picture_set_matrix (cairo_xcb_picture_t *picture, - const cairo_matrix_t *matrix, - cairo_filter_t filter, - double xc, double yc) -{ - xcb_render_transform_t transform; - pixman_transform_t *pixman_transform; - cairo_int_status_t ignored; - - /* Casting between pixman_transform_t and xcb_render_transform_t is safe - * because they happen to be the exact same type. - */ - pixman_transform = (pixman_transform_t *) &transform; - - picture->x = picture->x0; - picture->y = picture->y0; - ignored = _cairo_matrix_to_pixman_matrix_offset (matrix, filter, xc, yc, - pixman_transform, - &picture->x, &picture->y); - (void) ignored; - - if (memcmp (&picture->transform, &transform, sizeof (xcb_render_transform_t))) { - _cairo_xcb_connection_render_set_picture_transform (_picture_to_connection (picture), - picture->picture, - &transform); - - picture->transform = transform; - } -} - -static void -_cairo_xcb_picture_set_filter (cairo_xcb_picture_t *picture, - cairo_filter_t filter) -{ - const char *render_filter; - int len; - - if (picture->filter == filter) - return; - - switch (filter) { - case CAIRO_FILTER_FAST: - render_filter = "fast"; - len = strlen ("fast"); - break; - - case CAIRO_FILTER_GOOD: - render_filter = "good"; - len = strlen ("good"); - break; - - case CAIRO_FILTER_BEST: - render_filter = "best"; - len = strlen ("best"); - break; - - case CAIRO_FILTER_NEAREST: - render_filter = "nearest"; - len = strlen ("nearest"); - break; - - case CAIRO_FILTER_BILINEAR: - render_filter = "bilinear"; - len = strlen ("bilinear"); - break; - - default: - ASSERT_NOT_REACHED; - case CAIRO_FILTER_GAUSSIAN: - render_filter = "best"; - len = strlen ("best"); - break; - } - - _cairo_xcb_connection_render_set_picture_filter (_picture_to_connection (picture), - picture->picture, - len, (char *) render_filter); - picture->filter = filter; -} - -static void -_cairo_xcb_picture_set_extend (cairo_xcb_picture_t *picture, - cairo_extend_t extend) -{ - uint32_t pa[1]; - - if (picture->extend == extend) - return; - - switch (extend) { - default: - ASSERT_NOT_REACHED; - case CAIRO_EXTEND_NONE: - pa[0] = XCB_RENDER_REPEAT_NONE; - break; - - case CAIRO_EXTEND_REPEAT: - pa[0] = XCB_RENDER_REPEAT_NORMAL; - break; - - case CAIRO_EXTEND_REFLECT: - pa[0] = XCB_RENDER_REPEAT_REFLECT; - break; - - case CAIRO_EXTEND_PAD: - pa[0] = XCB_RENDER_REPEAT_PAD; - break; - } - - _cairo_xcb_connection_render_change_picture (_picture_to_connection (picture), - picture->picture, - XCB_RENDER_CP_REPEAT, pa); - picture->extend = extend; -} - -static void -_cairo_xcb_picture_set_component_alpha (cairo_xcb_picture_t *picture, - cairo_bool_t ca) -{ - uint32_t pa[1]; - - if (picture->has_component_alpha == ca) - return; - - pa[0] = ca; - - _cairo_xcb_connection_render_change_picture (_picture_to_connection (picture), - picture->picture, - XCB_RENDER_CP_COMPONENT_ALPHA, - pa); - picture->has_component_alpha = ca; -} - -static cairo_xcb_picture_t * -_solid_picture (cairo_xcb_surface_t *target, - const cairo_color_t *color) -{ - xcb_render_color_t xcb_color; - xcb_render_pictformat_t xrender_format; - cairo_xcb_picture_t *picture; - - xcb_color.red = color->red_short; - xcb_color.green = color->green_short; - xcb_color.blue = color->blue_short; - xcb_color.alpha = color->alpha_short; - - xrender_format = target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32]; - picture = _cairo_xcb_picture_create (target->screen, - PIXMAN_a8r8g8b8, - xrender_format, - -1, -1); - if (unlikely (picture->base.status)) - return picture; - - if (target->connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS) { - _cairo_xcb_connection_render_create_solid_fill (target->connection, - picture->picture, - xcb_color); - } else { - xcb_pixmap_t pixmap; - uint32_t values[] = { XCB_RENDER_REPEAT_NORMAL }; - - pixmap = _cairo_xcb_connection_create_pixmap (target->connection, - 32, target->drawable, 1, 1); - _cairo_xcb_connection_render_create_picture (target->connection, - picture->picture, - pixmap, - xrender_format, - XCB_RENDER_CP_REPEAT, - values); - if (target->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { - xcb_rectangle_t rect; - - rect.x = rect.y = 0; - rect.width = rect.height = 1; - - _cairo_xcb_connection_render_fill_rectangles (_picture_to_connection (picture), - XCB_RENDER_PICT_OP_SRC, - picture->picture, - xcb_color, 1, &rect); - } else { - xcb_gcontext_t gc; - uint32_t pixel; - - gc = _cairo_xcb_screen_get_gc (target->screen, pixmap, 32); - - /* XXX byte ordering? */ - pixel = ((color->alpha_short >> 8) << 24) | - ((color->red_short >> 8) << 16) | - ((color->green_short >> 8) << 8) | - ((color->blue_short >> 8) << 0); - - _cairo_xcb_connection_put_image (target->connection, - pixmap, gc, - 1, 1, 0, 0, - 32, 4, &pixel); - - _cairo_xcb_screen_put_gc (target->screen, 32, gc); - } - - _cairo_xcb_connection_free_pixmap (target->connection, pixmap); - } - - return picture; -} - -static cairo_xcb_picture_t * -_cairo_xcb_transparent_picture (cairo_xcb_surface_t *target) -{ - cairo_xcb_picture_t *picture; - - picture = (cairo_xcb_picture_t *) target->screen->stock_colors[CAIRO_STOCK_TRANSPARENT]; - if (picture == NULL) { - picture = _solid_picture (target, CAIRO_COLOR_TRANSPARENT); - target->screen->stock_colors[CAIRO_STOCK_TRANSPARENT] = &picture->base; - } - - return (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); -} - -static cairo_xcb_picture_t * -_cairo_xcb_black_picture (cairo_xcb_surface_t *target) -{ - cairo_xcb_picture_t *picture; - - picture = (cairo_xcb_picture_t *) target->screen->stock_colors[CAIRO_STOCK_BLACK]; - if (picture == NULL) { - picture = _solid_picture (target, CAIRO_COLOR_BLACK); - target->screen->stock_colors[CAIRO_STOCK_BLACK] = &picture->base; - } - - return (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); -} - -static cairo_xcb_picture_t * -_cairo_xcb_white_picture (cairo_xcb_surface_t *target) -{ - cairo_xcb_picture_t *picture; - - picture = (cairo_xcb_picture_t *) target->screen->stock_colors[CAIRO_STOCK_WHITE]; - if (picture == NULL) { - picture = _solid_picture (target, CAIRO_COLOR_WHITE); - target->screen->stock_colors[CAIRO_STOCK_WHITE] = &picture->base; - } - - return (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); -} - -static cairo_xcb_picture_t * -_cairo_xcb_solid_picture (cairo_xcb_surface_t *target, - const cairo_solid_pattern_t *pattern) -{ - cairo_xcb_picture_t *picture; - cairo_xcb_screen_t *screen; - int i, n_cached; - - if (pattern->color.alpha_short <= 0x00ff) - return _cairo_xcb_transparent_picture (target); - - if (pattern->color.alpha_short >= 0xff00) { - if (pattern->color.red_short <= 0x00ff && - pattern->color.green_short <= 0x00ff && - pattern->color.blue_short <= 0x00ff) - { - return _cairo_xcb_black_picture (target); - } - - if (pattern->color.red_short >= 0xff00 && - pattern->color.green_short >= 0xff00 && - pattern->color.blue_short >= 0xff00) - { - return _cairo_xcb_white_picture (target); - } - } - - screen = target->screen; - n_cached = screen->solid_cache_size; - for (i = 0; i < n_cached; i++) { - if (_cairo_color_equal (&screen->solid_cache[i].color, &pattern->color)) { - return (cairo_xcb_picture_t *) cairo_surface_reference (screen->solid_cache[i].picture); - } - } - - picture = _solid_picture (target, &pattern->color); - if (unlikely (picture->base.status)) - return picture; - - if (screen->solid_cache_size < ARRAY_LENGTH (screen->solid_cache)) { - i = screen->solid_cache_size++; - } else { - i = hars_petruska_f54_1_random () % ARRAY_LENGTH (screen->solid_cache); - cairo_surface_destroy (screen->solid_cache[i].picture); - } - screen->solid_cache[i].picture = cairo_surface_reference (&picture->base); - screen->solid_cache[i].color = pattern->color; - - return picture; -} - -static cairo_xcb_picture_t * -_render_to_picture (cairo_xcb_surface_t *target, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - cairo_image_surface_t *image; - cairo_xcb_shm_info_t *shm_info; - cairo_pattern_union_t copy; - cairo_status_t status; - cairo_xcb_picture_t *picture; - pixman_format_code_t pixman_format; - xcb_render_pictformat_t xrender_format; - - /* XXX handle extend modes via tiling? */ - /* XXX alpha-only masks? */ - - pixman_format = PIXMAN_a8r8g8b8; - xrender_format = target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32]; - - status = _cairo_xcb_shm_image_create (target->screen->connection, - pixman_format, - extents->width, extents->height, - &image, &shm_info); - if (unlikely (status)) - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - - _cairo_pattern_init_static_copy (©.base, pattern); - cairo_matrix_translate (©.base.matrix, extents->x, extents->y); - status = _cairo_surface_paint (&image->base, - CAIRO_OPERATOR_SOURCE, - ©.base, - NULL); - if (unlikely (status)) { - cairo_surface_destroy (&image->base); - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - } - - picture = _picture_from_image (target, xrender_format, image, shm_info); - cairo_surface_destroy (&image->base); - - if (unlikely (picture->base.status)) - return picture; - - _cairo_xcb_picture_set_component_alpha (picture, pattern->has_component_alpha); - picture->x = -extents->x; - picture->y = -extents->y; - - return picture; -} - -static xcb_render_fixed_t * -_gradient_to_xcb (const cairo_gradient_pattern_t *gradient, - unsigned int *n_stops, - char *buf, unsigned int buflen) -{ - xcb_render_fixed_t *stops; - xcb_render_color_t *colors; - unsigned int i; - - assert (gradient->n_stops > 0); - *n_stops = MAX (gradient->n_stops, 2); - - if (*n_stops * (sizeof (xcb_render_fixed_t) + sizeof (xcb_render_color_t)) < buflen) - { - stops = (xcb_render_fixed_t *) buf; - } - else - { - stops = - _cairo_malloc_ab (*n_stops, - sizeof (xcb_render_fixed_t) + sizeof (xcb_render_color_t)); - if (unlikely (stops == NULL)) - return NULL; - } - - colors = (xcb_render_color_t *) (stops + *n_stops); - for (i = 0; i < gradient->n_stops; i++) { - stops[i] = - _cairo_fixed_16_16_from_double (gradient->stops[i].offset); - - colors[i].red = gradient->stops[i].color.red_short; - colors[i].green = gradient->stops[i].color.green_short; - colors[i].blue = gradient->stops[i].color.blue_short; - colors[i].alpha = gradient->stops[i].color.alpha_short; - } - - /* RENDER does not support gradients with less than 2 stops. If a - * gradient has only a single stop, duplicate it to make RENDER - * happy. */ - if (gradient->n_stops == 1) { - stops[1] = _cairo_fixed_16_16_from_double (gradient->stops[0].offset); - - colors[1].red = gradient->stops[0].color.red_short; - colors[1].green = gradient->stops[0].color.green_short; - colors[1].blue = gradient->stops[0].color.blue_short; - colors[1].alpha = gradient->stops[0].color.alpha_short; - } - - return stops; -} - -static cairo_xcb_picture_t * -_cairo_xcb_linear_picture (cairo_xcb_surface_t *target, - const cairo_linear_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - char buf[CAIRO_STACK_BUFFER_SIZE]; - xcb_render_fixed_t *stops; - xcb_render_color_t *colors; - xcb_render_pointfix_t p1, p2; - cairo_matrix_t matrix; - cairo_circle_double_t extremes[2]; - cairo_xcb_picture_t *picture; - cairo_status_t status; - unsigned int n_stops; - - _cairo_gradient_pattern_fit_to_range (&pattern->base, PIXMAN_MAX_INT >> 1, &matrix, extremes); - - picture = (cairo_xcb_picture_t *) - _cairo_xcb_screen_lookup_linear_picture (target->screen, pattern); - if (picture != NULL) - goto setup_picture; - - stops = _gradient_to_xcb (&pattern->base, &n_stops, buf, sizeof (buf)); - if (unlikely (stops == NULL)) - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - picture = _cairo_xcb_picture_create (target->screen, - target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32], - PIXMAN_a8r8g8b8, - -1, -1); - if (unlikely (picture->base.status)) { - if (stops != (xcb_render_fixed_t *) buf) - free (stops); - return picture; - } - picture->filter = CAIRO_FILTER_DEFAULT; - - colors = (xcb_render_color_t *) (stops + n_stops); - - p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); - p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); - p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); - p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); - - _cairo_xcb_connection_render_create_linear_gradient (target->connection, - picture->picture, - p1, p2, - n_stops, - stops, colors); - - if (stops != (xcb_render_fixed_t *) buf) - free (stops); - - status = _cairo_xcb_screen_store_linear_picture (target->screen, - pattern, - &picture->base); - if (unlikely (status)) { - cairo_surface_destroy (&picture->base); - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - } - -setup_picture: - _cairo_xcb_picture_set_matrix (picture, &matrix, - pattern->base.base.filter, - extents->x + extents->width/2., - extents->y + extents->height/2.); - _cairo_xcb_picture_set_filter (picture, pattern->base.base.filter); - _cairo_xcb_picture_set_extend (picture, pattern->base.base.extend); - _cairo_xcb_picture_set_component_alpha (picture, - pattern->base.base.has_component_alpha); - - return picture; -} - -static cairo_xcb_picture_t * -_cairo_xcb_radial_picture (cairo_xcb_surface_t *target, - const cairo_radial_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - char buf[CAIRO_STACK_BUFFER_SIZE]; - xcb_render_fixed_t *stops; - xcb_render_color_t *colors; - xcb_render_pointfix_t p1, p2; - xcb_render_fixed_t r1, r2; - cairo_matrix_t matrix; - cairo_circle_double_t extremes[2]; - cairo_xcb_picture_t *picture; - cairo_status_t status; - unsigned int n_stops; - - _cairo_gradient_pattern_fit_to_range (&pattern->base, PIXMAN_MAX_INT >> 1, &matrix, extremes); - - picture = (cairo_xcb_picture_t *) - _cairo_xcb_screen_lookup_radial_picture (target->screen, pattern); - if (picture != NULL) - goto setup_picture; - - stops = _gradient_to_xcb (&pattern->base, &n_stops, buf, sizeof (buf)); - if (unlikely (stops == NULL)) - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - picture = _cairo_xcb_picture_create (target->screen, - target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32], - PIXMAN_a8r8g8b8, - -1, -1); - if (unlikely (picture->base.status)) { - if (stops != (xcb_render_fixed_t *) buf) - free (stops); - return picture; - } - picture->filter = CAIRO_FILTER_DEFAULT; - - colors = (xcb_render_color_t *) (stops + n_stops); - - p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); - p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); - p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); - p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); - - r1 = _cairo_fixed_16_16_from_double (extremes[0].radius); - r2 = _cairo_fixed_16_16_from_double (extremes[1].radius); - - _cairo_xcb_connection_render_create_radial_gradient (target->connection, - picture->picture, - p1, p2, r1, r2, - n_stops, - stops, colors); - - if (stops != (xcb_render_fixed_t *) buf) - free (stops); - - status = _cairo_xcb_screen_store_radial_picture (target->screen, - pattern, - &picture->base); - if (unlikely (status)) { - cairo_surface_destroy (&picture->base); - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - } - -setup_picture: - _cairo_xcb_picture_set_matrix (picture, &matrix, - pattern->base.base.filter, - extents->x + extents->width/2., - extents->y + extents->height/2.); - _cairo_xcb_picture_set_filter (picture, pattern->base.base.filter); - _cairo_xcb_picture_set_extend (picture, pattern->base.base.extend); - _cairo_xcb_picture_set_component_alpha (picture, - pattern->base.base.has_component_alpha); - - return picture; -} - -static cairo_xcb_picture_t * -_copy_to_picture (cairo_xcb_surface_t *source) -{ - cairo_xcb_picture_t *picture; - uint32_t values[] = { 0, 1 }; - - if (source->deferred_clear) { - cairo_status_t status = _cairo_xcb_surface_clear (source); - if (unlikely (status)) - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - } - - picture = _cairo_xcb_picture_create (source->screen, - source->xrender_format, - source->pixman_format, - source->width, - source->height); - if (unlikely (picture->base.status)) - return picture; - - _cairo_xcb_connection_render_create_picture (source->connection, - picture->picture, - source->drawable, - source->xrender_format, - XCB_RENDER_CP_GRAPHICS_EXPOSURE | - XCB_RENDER_CP_SUBWINDOW_MODE, - values); - - return picture; -} - -static void -_cairo_xcb_surface_setup_surface_picture(cairo_xcb_picture_t *picture, - const cairo_surface_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - cairo_filter_t filter; - - filter = pattern->base.filter; - if (filter != CAIRO_FILTER_NEAREST && - _cairo_matrix_is_pixel_exact (&pattern->base.matrix)) - { - filter = CAIRO_FILTER_NEAREST; - } - _cairo_xcb_picture_set_filter (picture, filter); - - _cairo_xcb_picture_set_matrix (picture, - &pattern->base.matrix, filter, - extents->x + extents->width/2., - extents->y + extents->height/2.); - - - _cairo_xcb_picture_set_extend (picture, pattern->base.extend); - _cairo_xcb_picture_set_component_alpha (picture, pattern->base.has_component_alpha); -} - -static cairo_xcb_picture_t * -record_to_picture (cairo_surface_t *target, - const cairo_surface_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_pattern_t tmp_pattern; - cairo_xcb_picture_t *picture; - cairo_status_t status; - cairo_matrix_t matrix; - cairo_surface_t *tmp; - cairo_surface_t *source; - cairo_rectangle_int_t limit; - cairo_extend_t extend; - - /* XXX: The following was once more or less copied from cairo-xlibs-ource.c, - * record_source() and recording_pattern_get_surface(), can we share a - * single version? - */ - - /* First get the 'real' recording surface and figure out the size for tmp */ - source = _cairo_pattern_get_source (pattern, &limit); - assert (_cairo_surface_is_recording (source)); - - if (! _cairo_matrix_is_identity (&pattern->base.matrix)) { - double x1, y1, x2, y2; - - matrix = pattern->base.matrix; - status = cairo_matrix_invert (&matrix); - assert (status == CAIRO_STATUS_SUCCESS); - - x1 = limit.x; - y1 = limit.y; - x2 = limit.x + limit.width; - y2 = limit.y + limit.height; - - _cairo_matrix_transform_bounding_box (&matrix, - &x1, &y1, &x2, &y2, NULL); - - limit.x = floor (x1); - limit.y = floor (y1); - limit.width = ceil (x2) - limit.x; - limit.height = ceil (y2) - limit.y; - } - extend = pattern->base.extend; - if (_cairo_rectangle_contains_rectangle (&limit, extents)) - extend = CAIRO_EXTEND_NONE; - if (extend == CAIRO_EXTEND_NONE && ! _cairo_rectangle_intersect (&limit, extents)) - return _cairo_xcb_transparent_picture ((cairo_xcb_surface_t *) target); - - /* Now draw the recording surface to an xcb surface */ - tmp = _cairo_surface_create_scratch (target, - source->content, - limit.width, - limit.height, - CAIRO_COLOR_TRANSPARENT); - if (tmp->status != CAIRO_STATUS_SUCCESS) { - return (cairo_xcb_picture_t *) tmp; - } - - cairo_matrix_init_translate (&matrix, limit.x, limit.y); - cairo_matrix_multiply (&matrix, &matrix, &pattern->base.matrix); - - status = _cairo_recording_surface_replay_with_clip (source, - &matrix, tmp, - NULL); - if (unlikely (status)) { - cairo_surface_destroy (tmp); - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - } - - /* Now that we have drawn this to an xcb surface, try again with that */ - _cairo_pattern_init_static_copy (&tmp_pattern.base, &pattern->base); - tmp_pattern.surface = tmp; - cairo_matrix_init_translate (&tmp_pattern.base.matrix, -limit.x, -limit.y); - - picture = _copy_to_picture ((cairo_xcb_surface_t *) tmp); - if (picture->base.status == CAIRO_STATUS_SUCCESS) - _cairo_xcb_surface_setup_surface_picture (picture, &tmp_pattern, extents); - cairo_surface_destroy (tmp); - return picture; -} - -static cairo_xcb_picture_t * -_cairo_xcb_surface_picture (cairo_xcb_surface_t *target, - const cairo_surface_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - cairo_surface_t *source = pattern->surface; - cairo_xcb_picture_t *picture; - - picture = (cairo_xcb_picture_t *) - _cairo_surface_has_snapshot (source, &_cairo_xcb_picture_backend); - if (picture != NULL) { - if (picture->screen == target->screen) { - picture = (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); - _cairo_xcb_surface_setup_surface_picture (picture, pattern, extents); - return picture; - } - picture = NULL; - } - - if (source->type == CAIRO_SURFACE_TYPE_XCB) - { - if (_cairo_surface_is_xcb(source)) { - cairo_xcb_surface_t *xcb = (cairo_xcb_surface_t *) source; - if (xcb->screen == target->screen && xcb->fallback == NULL) { - picture = _copy_to_picture ((cairo_xcb_surface_t *) source); - if (unlikely (picture->base.status)) - return picture; - } - } else if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; - cairo_xcb_surface_t *xcb = (cairo_xcb_surface_t *) sub->target; - - /* XXX repeat interval with source clipping? */ - if (FALSE && xcb->screen == target->screen && xcb->fallback == NULL) { - xcb_rectangle_t rect; - - picture = _copy_to_picture (xcb); - if (unlikely (picture->base.status)) - return picture; - - rect.x = sub->extents.x; - rect.y = sub->extents.y; - rect.width = sub->extents.width; - rect.height = sub->extents.height; - - _cairo_xcb_connection_render_set_picture_clip_rectangles (xcb->connection, - picture->picture, - 0, 0, - 1, &rect); - picture->x0 = rect.x; - picture->y0 = rect.y; - picture->width = rect.width; - picture->height = rect.height; - } - } else if (_cairo_surface_is_snapshot (source)) { - cairo_surface_snapshot_t *snap = (cairo_surface_snapshot_t *) source; - cairo_xcb_surface_t *xcb = (cairo_xcb_surface_t *) snap->target; - - if (xcb->screen == target->screen && xcb->fallback == NULL) { - picture = _copy_to_picture (xcb); - if (unlikely (picture->base.status)) - return picture; - } - } - } -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS - else if (source->type == CAIRO_SURFACE_TYPE_XLIB) - { - if (source->backend->type == CAIRO_SURFACE_TYPE_XLIB) { - cairo_xcb_surface_t *xcb = ((cairo_xlib_xcb_surface_t *) source)->xcb; - if (xcb->screen == target->screen && xcb->fallback == NULL) { - picture = _copy_to_picture (xcb); - if (unlikely (picture->base.status)) - return picture; - } - } else if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { - cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; - cairo_xcb_surface_t *xcb = ((cairo_xlib_xcb_surface_t *) sub->target)->xcb; - - if (FALSE && xcb->screen == target->screen && xcb->fallback == NULL) { - xcb_rectangle_t rect; - - picture = _copy_to_picture (xcb); - if (unlikely (picture->base.status)) - return picture; - - rect.x = sub->extents.x; - rect.y = sub->extents.y; - rect.width = sub->extents.width; - rect.height = sub->extents.height; - - _cairo_xcb_connection_render_set_picture_clip_rectangles (xcb->connection, - picture->picture, - 0, 0, - 1, &rect); - picture->x0 = rect.x; - picture->y0 = rect.y; - picture->width = rect.width; - picture->height = rect.height; - } - } else if (_cairo_surface_is_snapshot (source)) { - cairo_surface_snapshot_t *snap = (cairo_surface_snapshot_t *) source; - cairo_xcb_surface_t *xcb = ((cairo_xlib_xcb_surface_t *) snap->target)->xcb; - - if (xcb->screen == target->screen && xcb->fallback == NULL) { - picture = _copy_to_picture (xcb); - if (unlikely (picture->base.status)) - return picture; - } - } - } -#endif -#if CAIRO_HAS_GL_FUNCTIONS - else if (source->type == CAIRO_SURFACE_TYPE_GL) - { - /* pixmap from texture */ - } -#endif - else if (source->type == CAIRO_SURFACE_TYPE_RECORDING) - { - /* We have to skip the call to attach_snapshot() because we possibly - * only drew part of the recording surface. - * TODO: When can we safely attach a snapshot? - */ - return record_to_picture(&target->base, pattern, extents); - } - - if (picture == NULL) { - cairo_image_surface_t *image; - void *image_extra; - cairo_status_t status; - - status = _cairo_surface_acquire_source_image (source, &image, &image_extra); - if (unlikely (status)) - return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); - - if (image->format != CAIRO_FORMAT_INVALID) { - xcb_render_pictformat_t format; - - format = target->screen->connection->standard_formats[image->format]; - - picture = _picture_from_image (target, format, image, NULL); - _cairo_surface_release_source_image (source, image, image_extra); - } else { - cairo_image_surface_t *conv; - xcb_render_pictformat_t render_format; - - /* XXX XRenderPutImage! */ - - conv = _cairo_image_surface_coerce (image); - _cairo_surface_release_source_image (source, image, image_extra); - if (unlikely (conv->base.status)) - return (cairo_xcb_picture_t *) conv; - - render_format = target->screen->connection->standard_formats[conv->format]; - picture = _picture_from_image (target, render_format, conv, NULL); - cairo_surface_destroy (&conv->base); - } - - if (unlikely (picture->base.status)) - return picture; - } - - _cairo_surface_attach_snapshot (source, - &picture->base, - NULL); - - _cairo_xcb_surface_setup_surface_picture (picture, pattern, extents); - return picture; -} - -static cairo_xcb_picture_t * -_cairo_xcb_picture_for_pattern (cairo_xcb_surface_t *target, - const cairo_pattern_t *pattern, - const cairo_rectangle_int_t *extents) -{ - if (pattern == NULL) - return _cairo_xcb_white_picture (target); - - if (! _pattern_is_supported (target->connection->flags, pattern)) - return _render_to_picture (target, pattern, extents); - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - return _cairo_xcb_solid_picture (target, (cairo_solid_pattern_t *) pattern); - - case CAIRO_PATTERN_TYPE_LINEAR: - return _cairo_xcb_linear_picture (target, - (cairo_linear_pattern_t *) pattern, - extents); - - case CAIRO_PATTERN_TYPE_RADIAL: - return _cairo_xcb_radial_picture (target, - (cairo_radial_pattern_t *) pattern, - extents); - - case CAIRO_PATTERN_TYPE_SURFACE: - return _cairo_xcb_surface_picture (target, - (cairo_surface_pattern_t *) pattern, - extents); - default: - ASSERT_NOT_REACHED; - case CAIRO_PATTERN_TYPE_MESH: - case CAIRO_PATTERN_TYPE_RASTER_SOURCE: - return _render_to_picture (target, pattern, extents); - } -} - -COMPILE_TIME_ASSERT (sizeof (xcb_rectangle_t) <= sizeof (cairo_box_t)); - -static cairo_status_t -_render_fill_boxes (void *abstract_dst, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - cairo_xcb_surface_t *dst = abstract_dst; - xcb_rectangle_t stack_xrects[CAIRO_STACK_ARRAY_LENGTH (xcb_rectangle_t)]; - xcb_rectangle_t *xrects = stack_xrects; - xcb_render_color_t render_color; - int render_op = _render_operator (op); - struct _cairo_boxes_chunk *chunk; - int max_count; - - render_color.red = color->red_short; - render_color.green = color->green_short; - render_color.blue = color->blue_short; - render_color.alpha = color->alpha_short; - - max_count = 0; - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - if (chunk->count > max_count) - max_count = chunk->count; - } - if (max_count > ARRAY_LENGTH (stack_xrects)) { - xrects = _cairo_malloc_ab (max_count, sizeof (xcb_rectangle_t)); - if (unlikely (xrects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - int i, j; - - for (i = j = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_round_down (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_round_down (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_round_down (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_round_down (chunk->base[i].p2.y); - - if (x2 > x1 && y2 > y1) { - xrects[j].x = x1; - xrects[j].y = y1; - xrects[j].width = x2 - x1; - xrects[j].height = y2 - y1; - j++; - } - } - - if (j) { - _cairo_xcb_connection_render_fill_rectangles - (dst->connection, - render_op, dst->picture, - render_color, j, xrects); - } - } - - if (xrects != stack_xrects) - free (xrects); - - return CAIRO_STATUS_SUCCESS; -} - -/* pixel aligned, non-overlapping boxes */ -static cairo_int_status_t -_render_composite_boxes (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - const cairo_pattern_t *mask_pattern, - const cairo_rectangle_int_t *extents, - const cairo_boxes_t *boxes) -{ - cairo_xcb_picture_t *src, *mask; - const struct _cairo_boxes_chunk *chunk; - xcb_rectangle_t stack_boxes[CAIRO_STACK_ARRAY_LENGTH (xcb_rectangle_t)]; - xcb_rectangle_t *clip_boxes; - cairo_rectangle_int_t stack_extents; - cairo_status_t status; - int num_boxes; - int render_op; - - render_op = _render_operator (op); - - if (src_pattern == NULL) { - src_pattern = mask_pattern; - mask_pattern = NULL; - } - - /* amalgamate into a single Composite call by setting a clip region */ - clip_boxes = stack_boxes; - if (boxes->num_boxes > ARRAY_LENGTH (stack_boxes)) { - clip_boxes = _cairo_malloc_ab (boxes->num_boxes, sizeof (xcb_rectangle_t)); - if (unlikely (clip_boxes == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - src = _cairo_xcb_picture_for_pattern (dst, src_pattern, extents); - status = src->base.status; - if (unlikely (status)) - goto cleanup_boxes; - - num_boxes = 0; - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - const cairo_box_t *box = chunk->base; - int i; - - for (i = 0; i < chunk->count; i++) { - int x = _cairo_fixed_integer_round_down (box[i].p1.x); - int y = _cairo_fixed_integer_round_down (box[i].p1.y); - int width = _cairo_fixed_integer_round_down (box[i].p2.x) - x; - int height = _cairo_fixed_integer_round_down (box[i].p2.y) - y; - - if (width && height) { - clip_boxes[num_boxes].x = x; - clip_boxes[num_boxes].y = y; - clip_boxes[num_boxes].width = width; - clip_boxes[num_boxes].height = height; - num_boxes++; - } - } - } - - if (num_boxes) { - if (num_boxes > 1) { - _cairo_xcb_connection_render_set_picture_clip_rectangles (dst->connection, - dst->picture, - 0, 0, - num_boxes, - clip_boxes); - } else { - stack_extents.x = clip_boxes[0].x; - stack_extents.y = clip_boxes[0].y; - stack_extents.width = clip_boxes[0].width; - stack_extents.height = clip_boxes[0].height; - extents = &stack_extents; - } - - if (mask_pattern != NULL) { - mask = _cairo_xcb_picture_for_pattern (dst, mask_pattern, extents); - status = mask->base.status; - if (unlikely (status)) - goto cleanup_clip; - - _cairo_xcb_connection_render_composite (dst->connection, - render_op, - src->picture, - mask->picture, - dst->picture, - src->x + extents->x, src->y + extents->y, - mask->x + extents->x, mask->y + extents->y, - extents->x, extents->y, - extents->width, extents->height); - - cairo_surface_destroy (&mask->base); - } else { - _cairo_xcb_connection_render_composite (dst->connection, - render_op, - src->picture, - XCB_NONE, - dst->picture, - src->x + extents->x, src->y + extents->y, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - } - -cleanup_clip: - - if (num_boxes > 1) - _cairo_xcb_surface_clear_clip_region (dst); - } - - cairo_surface_destroy (&src->base); - -cleanup_boxes: - - if (clip_boxes != stack_boxes) - free (clip_boxes); - - return status; -} - - -#define CAIRO_FIXED_16_16_MIN _cairo_fixed_from_int (-32768) -#define CAIRO_FIXED_16_16_MAX _cairo_fixed_from_int (32767) - -static cairo_bool_t -_line_exceeds_16_16 (const cairo_line_t *line) -{ - return - line->p1.x <= CAIRO_FIXED_16_16_MIN || - line->p1.x >= CAIRO_FIXED_16_16_MAX || - - line->p2.x <= CAIRO_FIXED_16_16_MIN || - line->p2.x >= CAIRO_FIXED_16_16_MAX || - - line->p1.y <= CAIRO_FIXED_16_16_MIN || - line->p1.y >= CAIRO_FIXED_16_16_MAX || - - line->p2.y <= CAIRO_FIXED_16_16_MIN || - line->p2.y >= CAIRO_FIXED_16_16_MAX; -} - -static void -_project_line_x_onto_16_16 (const cairo_line_t *line, - cairo_fixed_t top, - cairo_fixed_t bottom, - xcb_render_linefix_t *out) -{ - cairo_point_double_t p1, p2; - double m; - - p1.x = _cairo_fixed_to_double (line->p1.x); - p1.y = _cairo_fixed_to_double (line->p1.y); - - p2.x = _cairo_fixed_to_double (line->p2.x); - p2.y = _cairo_fixed_to_double (line->p2.y); - - m = (p2.x - p1.x) / (p2.y - p1.y); - out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); - out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); -} - -typedef struct { - cairo_traps_t traps; - cairo_antialias_t antialias; -} composite_traps_info_t; - -COMPILE_TIME_ASSERT (sizeof (xcb_render_trapezoid_t) <= sizeof (cairo_trapezoid_t)); - -static cairo_int_status_t -_composite_traps (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - composite_traps_info_t *info = closure; - const cairo_traps_t *traps = &info->traps; - cairo_xcb_picture_t *src; - cairo_format_t format; - xcb_render_pictformat_t xrender_format; - xcb_render_trapezoid_t *xtraps; - int render_reference_x, render_reference_y; - cairo_status_t status; - int i; - - if (dst->deferred_clear) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) - return status; - } - - src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); - if (unlikely (src->base.status)) - return src->base.status; - - if (info->antialias == CAIRO_ANTIALIAS_NONE) - format = CAIRO_FORMAT_A1; - else - format = CAIRO_FORMAT_A8; - xrender_format = dst->screen->connection->standard_formats[format]; - - xtraps = (xcb_render_trapezoid_t *) traps->traps; - for (i = 0; i < traps->num_traps; i++) { - cairo_trapezoid_t t = traps->traps[i]; - - /* top/bottom will be clamped to surface bounds */ - xtraps[i].top = _cairo_fixed_to_16_16 (t.top); - xtraps[i].top -= dst_y << 16; - xtraps[i].bottom = _cairo_fixed_to_16_16 (t.bottom); - xtraps[i].bottom -= dst_y << 16; - - /* However, all the other coordinates will have been left untouched so - * as not to introduce numerical error. Recompute them if they - * exceed the 16.16 limits. - */ - if (unlikely (_line_exceeds_16_16 (&t.left))) { - _project_line_x_onto_16_16 (&t.left, - t.top, - t.bottom, - &xtraps[i].left); - xtraps[i].left.p1.y = xtraps[i].top; - xtraps[i].left.p2.y = xtraps[i].bottom; - } else { - xtraps[i].left.p1.x = _cairo_fixed_to_16_16 (t.left.p1.x); - xtraps[i].left.p1.y = _cairo_fixed_to_16_16 (t.left.p1.y); - xtraps[i].left.p2.x = _cairo_fixed_to_16_16 (t.left.p2.x); - xtraps[i].left.p2.y = _cairo_fixed_to_16_16 (t.left.p2.y); - } - xtraps[i].left.p1.x -= dst_x << 16; - xtraps[i].left.p1.y -= dst_y << 16; - xtraps[i].left.p2.x -= dst_x << 16; - xtraps[i].left.p2.y -= dst_y << 16; - - if (unlikely (_line_exceeds_16_16 (&t.right))) { - _project_line_x_onto_16_16 (&t.right, - t.top, - t.bottom, - &xtraps[i].right); - xtraps[i].right.p1.y = xtraps[i].top; - xtraps[i].right.p2.y = xtraps[i].bottom; - } else { - xtraps[i].right.p1.x = _cairo_fixed_to_16_16 (t.right.p1.x); - xtraps[i].right.p1.y = _cairo_fixed_to_16_16 (t.right.p1.y); - xtraps[i].right.p2.x = _cairo_fixed_to_16_16 (t.right.p2.x); - xtraps[i].right.p2.y = _cairo_fixed_to_16_16 (t.right.p2.y); - } - xtraps[i].right.p1.x -= dst_x << 16; - xtraps[i].right.p1.y -= dst_y << 16; - xtraps[i].right.p2.x -= dst_x << 16; - xtraps[i].right.p2.y -= dst_y << 16; - } - - if (xtraps[0].left.p1.y < xtraps[0].left.p2.y) { - render_reference_x = xtraps[0].left.p1.x >> 16; - render_reference_y = xtraps[0].left.p1.y >> 16; - } else { - render_reference_x = xtraps[0].left.p2.x >> 16; - render_reference_y = xtraps[0].left.p2.y >> 16; - } - render_reference_x += src->x + dst_x; - render_reference_y += src->y + dst_y; - - _cairo_xcb_surface_set_precision (dst, info->antialias); - _cairo_xcb_connection_render_trapezoids (dst->connection, - _render_operator (op), - src->picture, - dst->picture, - xrender_format, - render_reference_x, - render_reference_y, - traps->num_traps, xtraps); - - cairo_surface_destroy (&src->base); - - return CAIRO_STATUS_SUCCESS; -} - -/* low-level composite driver */ - -static cairo_xcb_surface_t * -get_clip_surface (const cairo_clip_t *clip, - cairo_xcb_surface_t *target, - int *tx, int *ty) -{ - cairo_surface_t *surface; - cairo_status_t status; - - surface = _cairo_surface_create_scratch (&target->base, - CAIRO_CONTENT_ALPHA, - clip->extents.width, - clip->extents.height, - CAIRO_COLOR_WHITE); - if (unlikely (surface->status)) - return (cairo_xcb_surface_t *) surface; - - assert (surface->backend == &_cairo_xcb_surface_backend); - status = _cairo_clip_combine_with_surface (clip, surface, - clip->extents.x, clip->extents.y); - if (unlikely (status)) { - cairo_surface_destroy (surface); - surface = _cairo_surface_create_in_error (status); - } - - *tx = clip->extents.x; - *ty = clip->extents.y; - - return (cairo_xcb_surface_t *) surface; -} - -typedef cairo_int_status_t -(*xcb_draw_func_t) (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip); - -static void do_unaligned_row(void (*blt)(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage), - void *closure, - const cairo_box_t *b, - int tx, int y, int h, - uint16_t coverage) -{ - int x1 = _cairo_fixed_integer_part (b->p1.x) - tx; - int x2 = _cairo_fixed_integer_part (b->p2.x) - tx; - if (x2 > x1) { - if (! _cairo_fixed_is_integer (b->p1.x)) { - blt(closure, x1, y, 1, h, - coverage * (256 - _cairo_fixed_fractional_part (b->p1.x))); - x1++; - } - - if (x2 > x1) - blt(closure, x1, y, x2-x1, h, (coverage << 8) - (coverage >> 8)); - - if (! _cairo_fixed_is_integer (b->p2.x)) - blt(closure, x2, y, 1, h, - coverage * _cairo_fixed_fractional_part (b->p2.x)); - } else - blt(closure, x1, y, 1, h, - coverage * (b->p2.x - b->p1.x)); -} - -static void do_unaligned_box(void (*blt)(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage), - void *closure, - const cairo_box_t *b, int tx, int ty) -{ - int y1 = _cairo_fixed_integer_part (b->p1.y) - ty; - int y2 = _cairo_fixed_integer_part (b->p2.y) - ty; - if (y2 > y1) { - if (! _cairo_fixed_is_integer (b->p1.y)) { - do_unaligned_row(blt, closure, b, tx, y1, 1, - 256 - _cairo_fixed_fractional_part (b->p1.y)); - y1++; - } - - if (y2 > y1) - do_unaligned_row(blt, closure, b, tx, y1, y2-y1, 256); - - if (! _cairo_fixed_is_integer (b->p2.y)) - do_unaligned_row(blt, closure, b, tx, y2, 1, - _cairo_fixed_fractional_part (b->p2.y)); - } else - do_unaligned_row(blt, closure, b, tx, y1, 1, - b->p2.y - b->p1.y); -} - - -static void blt_in(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - cairo_xcb_surface_t *mask = closure; - xcb_render_color_t color; - xcb_rectangle_t rect; - - if (coverage == 0xffff) - return; - - color.red = color.green = color.blue = 0; - color.alpha = coverage; - - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - - _cairo_xcb_connection_render_fill_rectangles (mask->connection, - XCB_RENDER_PICT_OP_IN, - mask->picture, - color, 1, &rect); -} - -static cairo_xcb_surface_t * -_create_composite_mask (cairo_clip_t *clip, - xcb_draw_func_t draw_func, - xcb_draw_func_t mask_func, - void *draw_closure, - cairo_xcb_surface_t *dst, - const cairo_rectangle_int_t*extents) -{ - cairo_xcb_surface_t *surface; - cairo_bool_t need_clip_combine; - cairo_int_status_t status; - - surface = (cairo_xcb_surface_t *) - _cairo_xcb_surface_create_similar (dst, CAIRO_CONTENT_ALPHA, - extents->width, extents->height); - if (unlikely (surface->base.status)) - return surface; - - _cairo_xcb_surface_ensure_picture (surface); - - surface->deferred_clear_color = *CAIRO_COLOR_TRANSPARENT; - surface->deferred_clear = TRUE; - surface->base.is_clear = TRUE; - - if (mask_func) { - status = mask_func (draw_closure, surface, - CAIRO_OPERATOR_ADD, NULL, - extents->x, extents->y, - extents, clip); - if (likely (status != CAIRO_INT_STATUS_UNSUPPORTED)) - return surface; - } - - /* Is it worth setting the clip region here? */ - status = draw_func (draw_closure, surface, - CAIRO_OPERATOR_ADD, NULL, - extents->x, extents->y, - extents, NULL); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return (cairo_xcb_surface_t *) _cairo_surface_create_in_error (status); - } - - if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { - int i; - - for (i = 0; i < clip->num_boxes; i++) { - cairo_box_t *b = &clip->boxes[i]; - - if (! _cairo_fixed_is_integer (b->p1.x) || - ! _cairo_fixed_is_integer (b->p1.y) || - ! _cairo_fixed_is_integer (b->p2.x) || - ! _cairo_fixed_is_integer (b->p2.y)) - { - do_unaligned_box(blt_in, surface, b, extents->x, extents->y); - } - } - - need_clip_combine = clip->path != NULL; - } else - need_clip_combine = ! _cairo_clip_is_region (clip); - - if (need_clip_combine) { - status = _cairo_clip_combine_with_surface (clip, &surface->base, - extents->x, extents->y); - if (unlikely (status)) { - cairo_surface_destroy (&surface->base); - return (cairo_xcb_surface_t *) _cairo_surface_create_in_error (status); - } - } - - return surface; -} - -/* Handles compositing with a clip surface when the operator allows - * us to combine the clip with the mask - */ -static cairo_status_t -_clip_and_composite_with_mask (cairo_clip_t *clip, - cairo_operator_t op, - const cairo_pattern_t *pattern, - xcb_draw_func_t draw_func, - xcb_draw_func_t mask_func, - void *draw_closure, - cairo_xcb_surface_t *dst, - const cairo_rectangle_int_t*extents) -{ - cairo_xcb_surface_t *mask; - cairo_xcb_picture_t *src; - - mask = _create_composite_mask (clip, - draw_func, mask_func, draw_closure, - dst, extents); - if (unlikely (mask->base.status)) - return mask->base.status; - - if (pattern != NULL || dst->base.content != CAIRO_CONTENT_ALPHA) { - src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); - if (unlikely (src->base.status)) { - cairo_surface_destroy (&mask->base); - return src->base.status; - } - - _cairo_xcb_connection_render_composite (dst->connection, - _render_operator (op), - src->picture, - mask->picture, - dst->picture, - extents->x + src->x, extents->y + src->y, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - - cairo_surface_destroy (&src->base); - } else { - _cairo_xcb_connection_render_composite (dst->connection, - _render_operator (op), - mask->picture, - XCB_NONE, - dst->picture, - 0, 0, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - } - cairo_surface_destroy (&mask->base); - - return CAIRO_STATUS_SUCCESS; -} - -/* Handles compositing with a clip surface when we have to do the operation - * in two pieces and combine them together. - */ -static cairo_status_t -_clip_and_composite_combine (cairo_clip_t *clip, - cairo_operator_t op, - const cairo_pattern_t *pattern, - xcb_draw_func_t draw_func, - void *draw_closure, - cairo_xcb_surface_t *dst, - const cairo_rectangle_int_t*extents) -{ - cairo_xcb_surface_t *tmp; - cairo_xcb_surface_t *clip_surface; - int clip_x = 0, clip_y = 0; - xcb_render_picture_t clip_picture; - cairo_status_t status; - - tmp = (cairo_xcb_surface_t *) - _cairo_xcb_surface_create_similar (dst, dst->base.content, - extents->width, extents->height); - if (unlikely (tmp->base.status)) - return tmp->base.status; - - /* create_similar() could have done a fallback to an image surface */ - assert (tmp->base.backend == &_cairo_xcb_surface_backend); - - _cairo_xcb_surface_ensure_picture (tmp); - - if (pattern == NULL) { - status = (*draw_func) (draw_closure, tmp, - CAIRO_OPERATOR_ADD, NULL, - extents->x, extents->y, - extents, NULL); - } else { - /* Initialize the temporary surface from the destination surface */ - if (! dst->base.is_clear || - (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) == 0) - { - /* XCopyArea may actually be quicker here. - * A good driver should translate if appropriate. - */ - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_SRC, - dst->picture, - XCB_NONE, - tmp->picture, - extents->x, extents->y, - 0, 0, - 0, 0, - extents->width, extents->height); - } - else - { - xcb_render_color_t clear; - xcb_rectangle_t xrect; - - clear.red = clear.green = clear.blue = clear.alpha = 0; - - xrect.x = xrect.y = 0; - xrect.width = extents->width; - xrect.height = extents->height; - - _cairo_xcb_connection_render_fill_rectangles (dst->connection, - XCB_RENDER_PICT_OP_CLEAR, - dst->picture, - clear, 1, &xrect); - } - - status = (*draw_func) (draw_closure, tmp, op, pattern, - extents->x, extents->y, - extents, NULL); - } - if (unlikely (status)) - goto CLEANUP_SURFACE; - - clip_surface = get_clip_surface (clip, dst, &clip_x, &clip_y); - status = clip_surface->base.status; - if (unlikely (status)) - goto CLEANUP_SURFACE; - - assert (clip_surface->base.backend == &_cairo_xcb_surface_backend); - clip_picture = clip_surface->picture; - assert (clip_picture != XCB_NONE); - - if (dst->base.is_clear) { - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_SRC, - tmp->picture, clip_picture, dst->picture, - 0, 0, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - } else { - /* Punch the clip out of the destination */ - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_OUT_REVERSE, - clip_picture, XCB_NONE, dst->picture, - extents->x - clip_x, - extents->y - clip_y, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - - /* Now add the two results together */ - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_ADD, - tmp->picture, clip_picture, dst->picture, - 0, 0, - extents->x - clip_x, - extents->y - clip_y, - extents->x, extents->y, - extents->width, extents->height); - } - cairo_surface_destroy (&clip_surface->base); - - CLEANUP_SURFACE: - cairo_surface_destroy (&tmp->base); - - return status; -} - -/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's - * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) - */ -static cairo_status_t -_clip_and_composite_source (cairo_clip_t *clip, - const cairo_pattern_t *pattern, - xcb_draw_func_t draw_func, - xcb_draw_func_t mask_func, - void *draw_closure, - cairo_xcb_surface_t *dst, - const cairo_rectangle_int_t *extents) -{ - cairo_xcb_surface_t *mask; - cairo_xcb_picture_t *src; - - /* Create a surface that is mask IN clip */ - mask = _create_composite_mask (clip, - draw_func, mask_func, draw_closure, - dst, extents); - if (unlikely (mask->base.status)) - return mask->base.status; - - src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); - if (unlikely (src->base.status)) { - cairo_surface_destroy (&mask->base); - return src->base.status; - } - - if (dst->base.is_clear) { - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_SRC, - src->picture, - mask->picture, - dst->picture, - extents->x + src->x, extents->y + src->y, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - } else { - /* Compute dest' = dest OUT (mask IN clip) */ - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_OUT_REVERSE, - mask->picture, - XCB_NONE, - dst->picture, - 0, 0, 0, 0, - extents->x, extents->y, - extents->width, extents->height); - - /* Now compute (src IN (mask IN clip)) ADD dest' */ - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_ADD, - src->picture, - mask->picture, - dst->picture, - extents->x + src->x, extents->y + src->y, - 0, 0, - extents->x, extents->y, - extents->width, extents->height); - } - - cairo_surface_destroy (&src->base); - cairo_surface_destroy (&mask->base); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -can_reduce_alpha_op (cairo_operator_t op) -{ - int iop = op; - switch (iop) { - case CAIRO_OPERATOR_OVER: - case CAIRO_OPERATOR_SOURCE: - case CAIRO_OPERATOR_ADD: - return TRUE; - default: - return FALSE; - } -} - -static cairo_bool_t -reduce_alpha_op (cairo_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *pattern) -{ - return dst->is_clear && - dst->content == CAIRO_CONTENT_ALPHA && - _cairo_pattern_is_opaque_solid (pattern) && - can_reduce_alpha_op (op); -} - -static cairo_status_t -_cairo_xcb_surface_fixup_unbounded (cairo_xcb_surface_t *dst, - const cairo_composite_rectangles_t *rects) -{ - xcb_rectangle_t xrects[4]; - int n; - - if (rects->bounded.width == rects->unbounded.width && - rects->bounded.height == rects->unbounded.height) - { - return CAIRO_STATUS_SUCCESS; - } - - n = 0; - if (rects->bounded.width == 0 || rects->bounded.height == 0) { - xrects[n].x = rects->unbounded.x; - xrects[n].width = rects->unbounded.width; - xrects[n].y = rects->unbounded.y; - xrects[n].height = rects->unbounded.height; - n++; - } else { - /* top */ - if (rects->bounded.y != rects->unbounded.y) { - xrects[n].x = rects->unbounded.x; - xrects[n].width = rects->unbounded.width; - xrects[n].y = rects->unbounded.y; - xrects[n].height = rects->bounded.y - rects->unbounded.y; - n++; - } - /* left */ - if (rects->bounded.x != rects->unbounded.x) { - xrects[n].x = rects->unbounded.x; - xrects[n].width = rects->bounded.x - rects->unbounded.x; - xrects[n].y = rects->bounded.y; - xrects[n].height = rects->bounded.height; - n++; - } - /* right */ - if (rects->bounded.x + rects->bounded.width != rects->unbounded.x + rects->unbounded.width) { - xrects[n].x = rects->bounded.x + rects->bounded.width; - xrects[n].width = rects->unbounded.x + rects->unbounded.width - xrects[n].x; - xrects[n].y = rects->bounded.y; - xrects[n].height = rects->bounded.height; - n++; - } - /* bottom */ - if (rects->bounded.y + rects->bounded.height != rects->unbounded.y + rects->unbounded.height) { - xrects[n].x = rects->unbounded.x; - xrects[n].width = rects->unbounded.width; - xrects[n].y = rects->bounded.y + rects->bounded.height; - xrects[n].height = rects->unbounded.y + rects->unbounded.height - xrects[n].y; - n++; - } - } - - if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { - xcb_render_color_t color; - - color.red = 0; - color.green = 0; - color.blue = 0; - color.alpha = 0; - - _cairo_xcb_connection_render_fill_rectangles (dst->connection, - XCB_RENDER_PICT_OP_CLEAR, - dst->picture, - color, n, xrects); - } else { - int i; - cairo_xcb_picture_t *src; - - src = _cairo_xcb_transparent_picture (dst); - if (unlikely (src->base.status)) - return src->base.status; - - for (i = 0; i < n; i++) { - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_CLEAR, - src->picture, XCB_NONE, dst->picture, - 0, 0, - 0, 0, - xrects[i].x, xrects[i].y, - xrects[i].width, xrects[i].height); - } - cairo_surface_destroy (&src->base); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xcb_surface_fixup_unbounded_with_mask (cairo_xcb_surface_t *dst, - const cairo_composite_rectangles_t *rects, - cairo_clip_t *clip) -{ - cairo_xcb_surface_t *mask; - int mask_x = 0, mask_y = 0; - - mask = get_clip_surface (clip, dst, &mask_x, &mask_y); - if (unlikely (mask->base.status)) - return mask->base.status; - - /* top */ - if (rects->bounded.y != rects->unbounded.y) { - int x = rects->unbounded.x; - int y = rects->unbounded.y; - int width = rects->unbounded.width; - int height = rects->bounded.y - y; - - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_OUT_REVERSE, - mask->picture, XCB_NONE, dst->picture, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - /* left */ - if (rects->bounded.x != rects->unbounded.x) { - int x = rects->unbounded.x; - int y = rects->bounded.y; - int width = rects->bounded.x - x; - int height = rects->bounded.height; - - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_OUT_REVERSE, - mask->picture, XCB_NONE, dst->picture, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - /* right */ - if (rects->bounded.x + rects->bounded.width != rects->unbounded.x + rects->unbounded.width) { - int x = rects->bounded.x + rects->bounded.width; - int y = rects->bounded.y; - int width = rects->unbounded.x + rects->unbounded.width - x; - int height = rects->bounded.height; - - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_OUT_REVERSE, - mask->picture, XCB_NONE, dst->picture, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - /* bottom */ - if (rects->bounded.y + rects->bounded.height != rects->unbounded.y + rects->unbounded.height) { - int x = rects->unbounded.x; - int y = rects->bounded.y + rects->bounded.height; - int width = rects->unbounded.width; - int height = rects->unbounded.y + rects->unbounded.height - y; - - _cairo_xcb_connection_render_composite (dst->connection, - XCB_RENDER_PICT_OP_OUT_REVERSE, - mask->picture, XCB_NONE, dst->picture, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - cairo_surface_destroy (&mask->base); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xcb_surface_fixup_unbounded_boxes (cairo_xcb_surface_t *dst, - const cairo_composite_rectangles_t *extents, - cairo_clip_t *clip, - cairo_boxes_t *boxes) -{ - cairo_boxes_t clear; - cairo_box_t box; - cairo_status_t status; - struct _cairo_boxes_chunk *chunk; - int i; - - if (boxes->num_boxes <= 1 && clip == NULL) - return _cairo_xcb_surface_fixup_unbounded (dst, extents); - - _cairo_boxes_init (&clear); - - box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); - box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); - box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); - box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); - - if (clip == NULL) { - cairo_boxes_t tmp; - - _cairo_boxes_init (&tmp); - - status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_STATUS_SUCCESS); - - tmp.chunks.next = &boxes->chunks; - tmp.num_boxes += boxes->num_boxes; - - status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, - CAIRO_FILL_RULE_WINDING, - &clear); - - tmp.chunks.next = NULL; - } else { - _cairo_boxes_init_with_clip (&clear, clip); - - status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); - assert (status == CAIRO_STATUS_SUCCESS); - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - status = _cairo_boxes_add (&clear, - CAIRO_ANTIALIAS_DEFAULT, - &chunk->base[i]); - if (unlikely (status)) { - _cairo_boxes_fini (&clear); - return status; - } - } - } - - status = _cairo_bentley_ottmann_tessellate_boxes (&clear, - CAIRO_FILL_RULE_WINDING, - &clear); - } - - if (likely (status == CAIRO_STATUS_SUCCESS)) { - if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) - status = _render_fill_boxes (dst, - CAIRO_OPERATOR_CLEAR, - CAIRO_COLOR_TRANSPARENT, - &clear); - else - status = _cairo_xcb_surface_core_fill_boxes (dst, - CAIRO_COLOR_TRANSPARENT, - &clear); - } - - _cairo_boxes_fini (&clear); - - return status; -} - -cairo_status_t -_cairo_xcb_surface_clear (cairo_xcb_surface_t *dst) -{ - xcb_gcontext_t gc; - xcb_rectangle_t rect; - cairo_status_t status; - - status = _cairo_xcb_connection_acquire (dst->connection); - if (unlikely (status)) - return status; - - rect.x = rect.y = 0; - rect.width = dst->width; - rect.height = dst->height; - - if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { - xcb_render_color_t color; - uint8_t op; - - color.red = dst->deferred_clear_color.red_short; - color.green = dst->deferred_clear_color.green_short; - color.blue = dst->deferred_clear_color.blue_short; - color.alpha = dst->deferred_clear_color.alpha_short; - - if (color.alpha == 0) - op = XCB_RENDER_PICT_OP_CLEAR; - else - op = XCB_RENDER_PICT_OP_SRC; - - _cairo_xcb_surface_ensure_picture (dst); - _cairo_xcb_connection_render_fill_rectangles (dst->connection, - op, dst->picture, color, - 1, &rect); - } else { - gc = _cairo_xcb_screen_get_gc (dst->screen, dst->drawable, dst->depth); - - /* XXX color */ - _cairo_xcb_connection_poly_fill_rectangle (dst->connection, - dst->drawable, gc, - 1, &rect); - - _cairo_xcb_screen_put_gc (dst->screen, dst->depth, gc); - } - - _cairo_xcb_connection_release (dst->connection); - - dst->deferred_clear = FALSE; - return CAIRO_STATUS_SUCCESS; -} - -enum { - NEED_CLIP_REGION = 0x1, - NEED_CLIP_SURFACE = 0x2, - FORCE_CLIP_REGION = 0x4, -}; - -static cairo_bool_t -need_bounded_clip (cairo_composite_rectangles_t *extents) -{ - unsigned int flags = NEED_CLIP_REGION; - if (! _cairo_clip_is_region (extents->clip)) - flags |= NEED_CLIP_SURFACE; - return flags; -} - -static cairo_bool_t -need_unbounded_clip (cairo_composite_rectangles_t *extents) -{ - unsigned int flags = 0; - if (! extents->is_bounded) { - flags |= NEED_CLIP_REGION; - if (! _cairo_clip_is_region (extents->clip)) - flags |= NEED_CLIP_SURFACE; - } - if (extents->clip->path != NULL) - flags |= NEED_CLIP_SURFACE; - return flags; -} - -static cairo_status_t -_clip_and_composite (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src, - xcb_draw_func_t draw_func, - xcb_draw_func_t mask_func, - void *draw_closure, - cairo_composite_rectangles_t*extents, - unsigned int need_clip) -{ - cairo_region_t *clip_region = NULL; - cairo_status_t status; - - status = _cairo_xcb_connection_acquire (dst->connection); - if (unlikely (status)) - return status; - - if (dst->deferred_clear) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) { - _cairo_xcb_connection_release (dst->connection); - return status; - } - } - - _cairo_xcb_surface_ensure_picture (dst); - - if (need_clip & NEED_CLIP_REGION) { - clip_region = _cairo_clip_get_region (extents->clip); - if ((need_clip & FORCE_CLIP_REGION) == 0 && clip_region != NULL && - cairo_region_contains_rectangle (clip_region, - &extents->unbounded) == CAIRO_REGION_OVERLAP_IN) - clip_region = NULL; - if (clip_region != NULL) { - status = _cairo_xcb_surface_set_clip_region (dst, clip_region); - if (unlikely (status)) { - _cairo_xcb_connection_release (dst->connection); - return status; - } - } - } - - if (reduce_alpha_op (&dst->base, op, src)) { - op = CAIRO_OPERATOR_ADD; - src = NULL; - } - - if (extents->bounded.width != 0 && extents->bounded.height != 0) { - if (op == CAIRO_OPERATOR_SOURCE) { - status = _clip_and_composite_source (extents->clip, src, - draw_func, mask_func, draw_closure, - dst, &extents->bounded); - } else { - if (op == CAIRO_OPERATOR_CLEAR) { - op = CAIRO_OPERATOR_DEST_OUT; - src = NULL; - } - - if (need_clip & NEED_CLIP_SURFACE) { - if (extents->is_bounded) { - status = _clip_and_composite_with_mask (extents->clip, op, src, - draw_func, - mask_func, - draw_closure, - dst, &extents->bounded); - } else { - status = _clip_and_composite_combine (extents->clip, op, src, - draw_func, draw_closure, - dst, &extents->bounded); - } - } else { - status = draw_func (draw_closure, - dst, op, src, - 0, 0, - &extents->bounded, - extents->clip); - } - } - } - - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { - if (need_clip & NEED_CLIP_SURFACE) - status = _cairo_xcb_surface_fixup_unbounded_with_mask (dst, extents, extents->clip); - else - status = _cairo_xcb_surface_fixup_unbounded (dst, extents); - } - - if (clip_region) - _cairo_xcb_surface_clear_clip_region (dst); - - _cairo_xcb_connection_release (dst->connection); - - return status; -} - -static cairo_status_t -_core_boxes (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src, - cairo_boxes_t *boxes, - const cairo_composite_rectangles_t *extents) -{ - if (! boxes->is_pixel_aligned) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_clip_is_region (extents->clip)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (op == CAIRO_OPERATOR_CLEAR) - return _cairo_xcb_surface_core_fill_boxes (dst, CAIRO_COLOR_TRANSPARENT, boxes); - - if (op == CAIRO_OPERATOR_OVER) { - if (dst->base.is_clear || _cairo_pattern_is_opaque (src, &extents->bounded)) - op = CAIRO_OPERATOR_SOURCE; - } - if (op != CAIRO_OPERATOR_SOURCE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (src->type == CAIRO_PATTERN_TYPE_SOLID) { - return _cairo_xcb_surface_core_fill_boxes (dst, - &((cairo_solid_pattern_t *) src)->color, - boxes); - } - - return _cairo_xcb_surface_core_copy_boxes (dst, src, &extents->bounded, boxes); -} - -static cairo_status_t -_composite_boxes (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src, - cairo_boxes_t *boxes, - const cairo_composite_rectangles_t *extents) -{ - cairo_clip_t *clip = extents->clip; - cairo_bool_t need_clip_mask = ! _cairo_clip_is_region (clip); - cairo_status_t status; - - /* If the boxes are not pixel-aligned, we will need to compute a real mask */ - if (! boxes->is_pixel_aligned) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (need_clip_mask && - (! extents->is_bounded || op == CAIRO_OPERATOR_SOURCE)) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = _cairo_xcb_connection_acquire (dst->connection); - if (unlikely (status)) - return status; - - _cairo_xcb_surface_ensure_picture (dst); - if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES && ! need_clip_mask && - (op == CAIRO_OPERATOR_CLEAR || src->type == CAIRO_PATTERN_TYPE_SOLID)) - { - const cairo_color_t *color; - - if (op == CAIRO_OPERATOR_CLEAR) - color = CAIRO_COLOR_TRANSPARENT; - else - color = &((cairo_solid_pattern_t *) src)->color; - - status = _render_fill_boxes (dst, op, color, boxes); - } - else - { - cairo_surface_pattern_t mask; - - if (need_clip_mask) { - cairo_xcb_surface_t *clip_surface; - int clip_x = 0, clip_y = 0; - - clip_surface = get_clip_surface (extents->clip, dst, - &clip_x, &clip_y); - if (unlikely (clip_surface->base.status)) - return clip_surface->base.status; - - _cairo_pattern_init_for_surface (&mask, &clip_surface->base); - mask.base.filter = CAIRO_FILTER_NEAREST; - cairo_matrix_init_translate (&mask.base.matrix, - -clip_x, - -clip_y); - cairo_surface_destroy (&clip_surface->base); - - if (op == CAIRO_OPERATOR_CLEAR) { - src = NULL; - op = CAIRO_OPERATOR_DEST_OUT; - } - } - - status = _render_composite_boxes (dst, op, src, - need_clip_mask ? &mask.base : NULL, - &extents->bounded, boxes); - - if (need_clip_mask) - _cairo_pattern_fini (&mask.base); - } - - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { - status = - _cairo_xcb_surface_fixup_unbounded_boxes (dst, extents, - clip, boxes); - } - - _cairo_xcb_connection_release (dst->connection); - - return status; -} - -static cairo_bool_t -cairo_boxes_for_each_box (cairo_boxes_t *boxes, - cairo_bool_t (*func) (cairo_box_t *box, - void *data), - void *data) -{ - struct _cairo_boxes_chunk *chunk; - int i; - - for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) - if (! func (&chunk->base[i], data)) - return FALSE; - } - - return TRUE; -} - -struct _image_contains_box { - int width, height; - int tx, ty; -}; - -static cairo_bool_t image_contains_box (cairo_box_t *box, void *closure) -{ - struct _image_contains_box *data = closure; - - /* The box is pixel-aligned so the truncation is safe. */ - return - _cairo_fixed_integer_part (box->p1.x) + data->tx >= 0 && - _cairo_fixed_integer_part (box->p1.y) + data->ty >= 0 && - _cairo_fixed_integer_part (box->p2.x) + data->tx <= data->width && - _cairo_fixed_integer_part (box->p2.y) + data->ty <= data->height; -} - -struct _image_upload_box { - cairo_xcb_surface_t *surface; - cairo_image_surface_t *image; - xcb_gcontext_t gc; - int tx, ty; -}; - -static cairo_bool_t image_upload_box (cairo_box_t *box, void *closure) -{ - const struct _image_upload_box *iub = closure; - /* The box is pixel-aligned so the truncation is safe. */ - int x = _cairo_fixed_integer_part (box->p1.x); - int y = _cairo_fixed_integer_part (box->p1.y); - int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); - int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); - int bpp = PIXMAN_FORMAT_BPP (iub->image->pixman_format); - int len = CAIRO_STRIDE_FOR_WIDTH_BPP (width, bpp); - if (len == iub->image->stride) { - _cairo_xcb_connection_put_image (iub->surface->connection, - iub->surface->drawable, - iub->gc, - width, height, - x, y, - iub->image->depth, - iub->image->stride, - iub->image->data + - (y + iub->ty) * iub->image->stride + - (x + iub->tx) * bpp/8); - } else { - _cairo_xcb_connection_put_subimage (iub->surface->connection, - iub->surface->drawable, - iub->gc, - x + iub->tx, - y + iub->ty, - width, height, - bpp / 8, - iub->image->stride, - x, y, - iub->image->depth, - iub->image->data); - } - - return TRUE; -} - -static cairo_status_t -_upload_image_inplace (cairo_xcb_surface_t *surface, - const cairo_pattern_t *source, - cairo_boxes_t *boxes) -{ - const cairo_surface_pattern_t *pattern; - struct _image_contains_box icb; - struct _image_upload_box iub; - cairo_image_surface_t *image; - cairo_status_t status; - int tx, ty; - - if (! boxes->is_pixel_aligned) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (source->type != CAIRO_PATTERN_TYPE_SURFACE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - pattern = (const cairo_surface_pattern_t *) source; - if (! _cairo_surface_is_image (pattern->surface)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Have we already upload this image to a pixmap? */ - { - cairo_xcb_picture_t *snapshot; - - snapshot = (cairo_xcb_picture_t *) - _cairo_surface_has_snapshot (pattern->surface, &_cairo_xcb_picture_backend); - if (snapshot != NULL) { - if (snapshot->screen == surface->screen) - return CAIRO_INT_STATUS_UNSUPPORTED; - } - } - - image = (cairo_image_surface_t *) pattern->surface; - if (image->format == CAIRO_FORMAT_INVALID) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (image->depth != surface->depth) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Check that the data is entirely within the image */ - icb.width = image->width; - icb.height = image->height; - icb.tx = tx; - icb.ty = ty; - if (! cairo_boxes_for_each_box (boxes, image_contains_box, &icb)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (surface->deferred_clear) { - status = _cairo_xcb_surface_clear (surface); - if (unlikely (status)) - return status; - } - - status = _cairo_xcb_connection_acquire (surface->connection); - if (unlikely (status)) - return status; - - iub.surface = surface; - iub.image = image; - iub.gc = _cairo_xcb_screen_get_gc (surface->screen, - surface->drawable, - image->depth); - iub.tx = tx; - iub.ty = ty; - cairo_boxes_for_each_box (boxes, image_upload_box, &iub); - - _cairo_xcb_screen_put_gc (surface->screen, image->depth, iub.gc); - _cairo_xcb_connection_release (surface->connection); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -trim_extents_to_traps (cairo_composite_rectangles_t *extents, - cairo_traps_t *traps) -{ - cairo_box_t box; - - /* X trims the affected area to the extents of the trapezoids, so - * we need to compensate when fixing up the unbounded area. - */ - _cairo_traps_extents (traps, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_bool_t -_mono_edge_is_vertical (const cairo_line_t *line) -{ - return _cairo_fixed_integer_round_down (line->p1.x) == _cairo_fixed_integer_round_down (line->p2.x); -} - -static cairo_bool_t -_traps_are_pixel_aligned (cairo_traps_t *traps, - cairo_antialias_t antialias) -{ - int i; - - if (antialias == CAIRO_ANTIALIAS_NONE) { - for (i = 0; i < traps->num_traps; i++) { - if (! _mono_edge_is_vertical (&traps->traps[i].left) || - ! _mono_edge_is_vertical (&traps->traps[i].right)) - { - traps->maybe_region = FALSE; - return FALSE; - } - } - } else { - for (i = 0; i < traps->num_traps; i++) { - if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x || - traps->traps[i].right.p1.x != traps->traps[i].right.p2.x || - ! _cairo_fixed_is_integer (traps->traps[i].top) || - ! _cairo_fixed_is_integer (traps->traps[i].bottom) || - ! _cairo_fixed_is_integer (traps->traps[i].left.p1.x) || - ! _cairo_fixed_is_integer (traps->traps[i].right.p1.x)) - { - traps->maybe_region = FALSE; - return FALSE; - } - } - } - - return TRUE; -} - -static void -_boxes_for_traps (cairo_boxes_t *boxes, - cairo_traps_t *traps, - cairo_antialias_t antialias) -{ - int i, j; - - _cairo_boxes_init (boxes); - - boxes->chunks.base = (cairo_box_t *) traps->traps; - boxes->chunks.size = traps->num_traps; - - if (antialias != CAIRO_ANTIALIAS_NONE) { - for (i = j = 0; i < traps->num_traps; i++) { - /* Note the traps and boxes alias so we need to take the local copies first. */ - cairo_fixed_t x1 = traps->traps[i].left.p1.x; - cairo_fixed_t x2 = traps->traps[i].right.p1.x; - cairo_fixed_t y1 = traps->traps[i].top; - cairo_fixed_t y2 = traps->traps[i].bottom; - - if (x1 == x2 || y1 == y2) - continue; - - boxes->chunks.base[j].p1.x = x1; - boxes->chunks.base[j].p1.y = y1; - boxes->chunks.base[j].p2.x = x2; - boxes->chunks.base[j].p2.y = y2; - j++; - - if (boxes->is_pixel_aligned) { - boxes->is_pixel_aligned = - _cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) && - _cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2); - } - } - } else { - boxes->is_pixel_aligned = TRUE; - - for (i = j = 0; i < traps->num_traps; i++) { - /* Note the traps and boxes alias so we need to take the local copies first. */ - cairo_fixed_t x1 = traps->traps[i].left.p1.x; - cairo_fixed_t x2 = traps->traps[i].right.p1.x; - cairo_fixed_t y1 = traps->traps[i].top; - cairo_fixed_t y2 = traps->traps[i].bottom; - - /* round down here to match Pixman's behavior when using traps. */ - boxes->chunks.base[j].p1.x = _cairo_fixed_round_down (x1); - boxes->chunks.base[j].p1.y = _cairo_fixed_round_down (y1); - boxes->chunks.base[j].p2.x = _cairo_fixed_round_down (x2); - boxes->chunks.base[j].p2.y = _cairo_fixed_round_down (y2); - - j += (boxes->chunks.base[j].p1.x != boxes->chunks.base[j].p2.x && - boxes->chunks.base[j].p1.y != boxes->chunks.base[j].p2.y); - } - } - - boxes->num_boxes = j; - boxes->chunks.count = j; -} - -static cairo_status_t -_composite_polygon (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_polygon_t *polygon, - cairo_antialias_t antialias, - cairo_fill_rule_t fill_rule, - cairo_composite_rectangles_t *extents) -{ - composite_traps_info_t traps; - cairo_bool_t clip_surface = ! _cairo_clip_is_region (extents->clip); - cairo_region_t *clip_region = _cairo_clip_get_region (extents->clip); - cairo_status_t status; - - if (polygon->num_edges == 0) { - status = CAIRO_STATUS_SUCCESS; - - if (! extents->is_bounded) { - if (cairo_region_contains_rectangle (clip_region, &extents->unbounded) == CAIRO_REGION_OVERLAP_IN) - clip_region = NULL; - - if (clip_surface == FALSE) { - if (clip_region != NULL) { - status = _cairo_xcb_surface_set_clip_region (dst, clip_region); - if (unlikely (status)) - return status; - } - - status = _cairo_xcb_surface_fixup_unbounded (dst, extents); - - if (clip_region != NULL) - _cairo_xcb_surface_clear_clip_region (dst); - } else { - status = _cairo_xcb_surface_fixup_unbounded_with_mask (dst, - extents, - extents->clip); - } - } - - return status; - } - - if (extents->clip->path != NULL && extents->is_bounded) { - cairo_polygon_t clipper; - cairo_fill_rule_t clipper_fill_rule; - cairo_antialias_t clipper_antialias; - - status = _cairo_clip_get_polygon (extents->clip, - &clipper, - &clipper_fill_rule, - &clipper_antialias); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - if (clipper_antialias == antialias) { - status = _cairo_polygon_intersect (polygon, fill_rule, - &clipper, clipper_fill_rule); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - cairo_clip_t * clip = _cairo_clip_copy_region (extents->clip); - _cairo_clip_destroy (extents->clip); - extents->clip = clip; - - fill_rule = CAIRO_FILL_RULE_WINDING; - } - _cairo_polygon_fini (&clipper); - } - } - } - - _cairo_traps_init (&traps.traps); - - status = _cairo_bentley_ottmann_tessellate_polygon (&traps.traps, polygon, fill_rule); - if (unlikely (status)) - goto CLEANUP_TRAPS; - - if (traps.traps.has_intersections) { - if (traps.traps.is_rectangular) - status = _cairo_bentley_ottmann_tessellate_rectangular_traps (&traps.traps, CAIRO_FILL_RULE_WINDING); - else if (traps.traps.is_rectilinear) - status = _cairo_bentley_ottmann_tessellate_rectilinear_traps (&traps.traps, CAIRO_FILL_RULE_WINDING); - else - status = _cairo_bentley_ottmann_tessellate_traps (&traps.traps, CAIRO_FILL_RULE_WINDING); - if (unlikely (status)) - goto CLEANUP_TRAPS; - } - - /* Use a fast path if the trapezoids consist of a simple region, - * but we can only do this if we do not have a clip surface, or can - * substitute the mask with the clip. - */ - if (traps.traps.maybe_region && - _traps_are_pixel_aligned (&traps.traps, antialias) && - (! clip_surface || - (extents->is_bounded && op != CAIRO_OPERATOR_SOURCE))) - { - cairo_boxes_t boxes; - - _boxes_for_traps (&boxes, &traps.traps, antialias); - status = _clip_and_composite_boxes (dst, op, source, &boxes, extents); - } - else - { - /* Otherwise render the trapezoids to a mask and composite in the usual - * fashion. - */ - traps.antialias = antialias; - status = trim_extents_to_traps (extents, &traps.traps); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - unsigned int flags = 0; - - /* For unbounded operations, the X11 server will estimate the - * affected rectangle and apply the operation to that. However, - * there are cases where this is an overestimate (e.g. the - * clip-fill-{eo,nz}-unbounded test). - * - * The clip will trim that overestimate to our expectations. - */ - if (! extents->is_bounded) - flags |= FORCE_CLIP_REGION; - - status = _clip_and_composite (dst, op, source, _composite_traps, - NULL, &traps, extents, - need_unbounded_clip (extents) | flags); - } - } - -CLEANUP_TRAPS: - _cairo_traps_fini (&traps.traps); - - return status; -} - -static cairo_status_t -_clip_and_composite_boxes (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src, - cairo_boxes_t *boxes, - cairo_composite_rectangles_t *extents) -{ - composite_traps_info_t info; - cairo_int_status_t status; - - if (boxes->num_boxes == 0 && extents->is_bounded) - return CAIRO_STATUS_SUCCESS; - - if (boxes->is_pixel_aligned && _cairo_clip_is_region (extents->clip) && - (op == CAIRO_OPERATOR_SOURCE || - (dst->base.is_clear && (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD)))) - { - if (boxes->num_boxes == 1 && - extents->bounded.width == dst->width && - extents->bounded.height == dst->height) - { - op = CAIRO_OPERATOR_SOURCE; - dst->deferred_clear = FALSE; - } - - status = _upload_image_inplace (dst, src, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ - if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS && - extents->clip->path != NULL && extents->is_bounded) { - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - cairo_antialias_t antialias; - cairo_clip_t *clip; - - clip = _cairo_clip_copy (extents->clip); - clip = _cairo_clip_intersect_boxes (clip, boxes); - if (_cairo_clip_is_all_clipped (clip)) - return CAIRO_INT_STATUS_NOTHING_TO_DO; - - status = _cairo_clip_get_polygon (clip, &polygon, - &fill_rule, &antialias); - _cairo_clip_path_destroy (clip->path); - clip->path = NULL; - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - cairo_clip_t *saved_clip = extents->clip; - extents->clip = clip; - status = _composite_polygon (dst, op, src, - &polygon, - antialias, - fill_rule, - extents); - if (extents->clip != clip) - clip = NULL; - extents->clip = saved_clip; - _cairo_polygon_fini (&polygon); - } - if (clip) - _cairo_clip_destroy (clip); - - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - if (dst->deferred_clear) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) - return status; - } - - if (boxes->is_pixel_aligned && - _cairo_clip_is_region (extents->clip) && - op == CAIRO_OPERATOR_SOURCE) { - status = _upload_image_inplace (dst, src, boxes); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - } - - if ((dst->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) == 0) - return _core_boxes (dst, op, src, boxes, extents); - - /* Use a fast path if the boxes are pixel aligned */ - status = _composite_boxes (dst, op, src, boxes, extents); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return status; - - if ((dst->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) == 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* Otherwise render via a mask and composite in the usual fashion. */ - status = _cairo_traps_init_boxes (&info.traps, boxes); - if (unlikely (status)) - return status; - - info.antialias = CAIRO_ANTIALIAS_DEFAULT; - status = trim_extents_to_traps (extents, &info.traps); - if (status == CAIRO_INT_STATUS_SUCCESS) { - status = _clip_and_composite (dst, op, src, - _composite_traps, NULL, &info, - extents, need_unbounded_clip (extents)); - } - - _cairo_traps_fini (&info.traps); - return status; -} - -static cairo_int_status_t -_composite_mask (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - const cairo_pattern_t *mask_pattern = closure; - cairo_xcb_picture_t *src, *mask = NULL; - cairo_status_t status; - - if (dst->base.is_clear) { - if (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD) - op = CAIRO_OPERATOR_SOURCE; - } - - if (op == CAIRO_OPERATOR_SOURCE && clip == NULL) - dst->deferred_clear = FALSE; - - if (dst->deferred_clear) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) - return status; - } - - if (src_pattern != NULL) { - src = _cairo_xcb_picture_for_pattern (dst, src_pattern, extents); - if (unlikely (src->base.status)) - return src->base.status; - - mask = _cairo_xcb_picture_for_pattern (dst, mask_pattern, extents); - if (unlikely (mask->base.status)) { - cairo_surface_destroy (&src->base); - return mask->base.status; - } - - _cairo_xcb_connection_render_composite (dst->connection, - _render_operator (op), - src->picture, - mask->picture, - dst->picture, - extents->x + src->x, extents->y + src->y, - extents->x + mask->x, extents->y + mask->y, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - cairo_surface_destroy (&mask->base); - cairo_surface_destroy (&src->base); - } else { - src = _cairo_xcb_picture_for_pattern (dst, mask_pattern, extents); - if (unlikely (src->base.status)) - return src->base.status; - - _cairo_xcb_connection_render_composite (dst->connection, - _render_operator (op), - src->picture, - XCB_NONE, - dst->picture, - extents->x + src->x, extents->y + src->y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - cairo_surface_destroy (&src->base); - } - - return CAIRO_STATUS_SUCCESS; -} - -struct composite_box_info { - cairo_xcb_surface_t *dst; - cairo_xcb_picture_t *src; - uint8_t op; -}; - -static void composite_box(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct composite_box_info *info = closure; - - if (coverage < 0xff00) { - cairo_xcb_picture_t *mask; - cairo_color_t color; - - color.red_short = color.green_short = color.blue_short = 0; - color.alpha_short = coverage; - - mask = _solid_picture (info->dst, &color); - if (likely (mask->base.status == CAIRO_STATUS_SUCCESS)) { - _cairo_xcb_connection_render_composite (info->dst->connection, - info->op, - info->src->picture, - mask->picture, - info->dst->picture, - x + info->src->x, y + info->src->y, - 0, 0, - x, y, - w, h); - } - cairo_surface_destroy (&mask->base); - } else { - _cairo_xcb_connection_render_composite (info->dst->connection, - info->op, - info->src->picture, - XCB_NONE, - info->dst->picture, - x + info->src->x, y + info->src->y, - 0, 0, - x, y, - w, h); - } -} - -static cairo_int_status_t -_composite_mask_clip_boxes (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - struct composite_box_info info; - cairo_status_t status; - int i; - - assert (src_pattern == NULL); - assert (op == CAIRO_OPERATOR_ADD); - assert (dst->base.is_clear); - - if (clip->num_boxes > 1) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) - return status; - } - - info.op = XCB_RENDER_PICT_OP_SRC; - info.dst = dst; - info.src = _cairo_xcb_picture_for_pattern (dst, closure, extents); - if (unlikely (info.src->base.status)) - return info.src->base.status; - - info.src->x += dst_x; - info.src->y += dst_y; - - for (i = 0; i < clip->num_boxes; i++) - do_unaligned_box(composite_box, &info, &clip->boxes[i], dst_x, dst_y); - cairo_surface_destroy (&info.src->base); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_composite_mask_clip (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - const cairo_pattern_t *mask_pattern = closure; - cairo_polygon_t polygon; - cairo_fill_rule_t fill_rule; - composite_traps_info_t info; - cairo_status_t status; - - assert (src_pattern == NULL); - assert (op == CAIRO_OPERATOR_ADD); - assert (dst->base.is_clear); - - status = _cairo_clip_get_polygon (clip, &polygon, - &fill_rule, &info.antialias); - if (unlikely (status)) - return status; - - _cairo_traps_init (&info.traps); - status = _cairo_bentley_ottmann_tessellate_polygon (&info.traps, - &polygon, - fill_rule); - _cairo_polygon_fini (&polygon); - if (unlikely (status)) - return status; - - if (info.traps.has_intersections) { - if (info.traps.is_rectangular) - status = _cairo_bentley_ottmann_tessellate_rectangular_traps (&info.traps, CAIRO_FILL_RULE_WINDING); - else if (info.traps.is_rectilinear) - status = _cairo_bentley_ottmann_tessellate_rectilinear_traps (&info.traps, CAIRO_FILL_RULE_WINDING); - else - status = _cairo_bentley_ottmann_tessellate_traps (&info.traps, CAIRO_FILL_RULE_WINDING); - if (unlikely (status)) { - _cairo_traps_fini (&info.traps); - return status; - } - } - - dst->deferred_clear = FALSE; /* assert(trap extents == extents); */ - - status = _composite_traps (&info, - dst, CAIRO_OPERATOR_SOURCE, mask_pattern, - dst_x, dst_y, - extents, NULL); - _cairo_traps_fini (&info.traps); - - return status; -} - -struct composite_opacity_info { - uint8_t op; - cairo_xcb_surface_t *dst; - cairo_xcb_picture_t *src; - double opacity; -}; - -static void composite_opacity(void *closure, - int16_t x, int16_t y, - int16_t w, int16_t h, - uint16_t coverage) -{ - struct composite_opacity_info *info = closure; - cairo_xcb_picture_t *mask; - cairo_color_t color; - - color.red_short = color.green_short = color.blue_short = 0; - color.alpha_short = info->opacity * coverage; - - mask = _solid_picture (info->dst, &color); - if (likely (mask->base.status == CAIRO_STATUS_SUCCESS)) { - if (info->src) { - _cairo_xcb_connection_render_composite (info->dst->connection, - info->op, - info->src->picture, - mask->picture, - info->dst->picture, - x + info->src->x, y + info->src->y, - 0, 0, - x, y, - w, h); - } else { - _cairo_xcb_connection_render_composite (info->dst->connection, - info->op, - mask->picture, - XCB_NONE, - info->dst->picture, - 0, 0, - 0, 0, - x, y, - w, h); - } - } - - cairo_surface_destroy (&mask->base); -} - -static cairo_int_status_t -_composite_opacity_boxes (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *src_pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - const cairo_solid_pattern_t *mask_pattern = closure; - struct composite_opacity_info info; - cairo_status_t status; - int i; - - if (dst->base.is_clear) { - if (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD) - op = CAIRO_OPERATOR_SOURCE; - } - - if (op == CAIRO_OPERATOR_SOURCE && - (clip == NULL || - (clip->extents.width >= extents->width && - clip->extents.height >= extents->height))) - dst->deferred_clear = FALSE; - - if (dst->deferred_clear) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) - return status; - } - - info.op = _render_operator (op); - info.dst = dst; - - if (src_pattern != NULL) { - info.src = _cairo_xcb_picture_for_pattern (dst, src_pattern, extents); - if (unlikely (info.src->base.status)) - return info.src->base.status; - } else - info.src = NULL; - - info.opacity = mask_pattern->color.alpha; - - /* XXX for lots of boxes create a clip region for the fully opaque areas */ - if (clip) { - for (i = 0; i < clip->num_boxes; i++) - do_unaligned_box(composite_opacity, &info, - &clip->boxes[i], dst_x, dst_y); - } else { - composite_opacity(&info, - extents->x - dst_x, - extents->y - dst_y, - extents->width, - extents->height, - 0xffff); - } - cairo_surface_destroy (&info.src->base); - - return CAIRO_STATUS_SUCCESS; -} - -/* high level rasteriser -> compositor */ - -cairo_int_status_t -_cairo_xcb_render_compositor_paint (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; - cairo_operator_t op = composite->op; - cairo_pattern_t *source = &composite->source_pattern.base; - cairo_boxes_t boxes; - cairo_status_t status; - - if (unlikely (! _operator_is_supported (surface->connection->flags, op))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | - CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - if (composite->clip == NULL && - source->type == CAIRO_PATTERN_TYPE_SOLID && - (op == CAIRO_OPERATOR_SOURCE || - op == CAIRO_OPERATOR_CLEAR || - (surface->base.is_clear && - (op == CAIRO_OPERATOR_ADD || op == CAIRO_OPERATOR_OVER)))) - { - surface->deferred_clear = TRUE; - surface->deferred_clear_color = composite->source_pattern.solid.color; - return CAIRO_STATUS_SUCCESS; - } - - _cairo_clip_steal_boxes(composite->clip, &boxes); - status = _clip_and_composite_boxes (surface, op, source, &boxes, composite); - _cairo_clip_unsteal_boxes (composite->clip, &boxes); - - return status; -} - -cairo_int_status_t -_cairo_xcb_render_compositor_mask (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; - cairo_operator_t op = composite->op; - cairo_pattern_t *source = &composite->source_pattern.base; - cairo_pattern_t *mask = &composite->mask_pattern.base; - cairo_status_t status; - - if (unlikely (! _operator_is_supported (surface->connection->flags, op))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) == 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (mask->type == CAIRO_PATTERN_TYPE_SOLID && - composite->clip->path == NULL && - ! _cairo_clip_is_region (composite->clip)) { - status = _clip_and_composite (surface, op, source, - _composite_opacity_boxes, - _composite_opacity_boxes, - (void *) mask, - composite, need_unbounded_clip (composite)); - } else { - xcb_draw_func_t mask_func = NULL; - if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) - mask_func = composite->clip->path ? _composite_mask_clip : _composite_mask_clip_boxes; - status = _clip_and_composite (surface, op, source, - _composite_mask, mask_func, - (void *) mask, - composite, need_bounded_clip (composite)); - } - - return status; -} - -static cairo_int_status_t -_cairo_xcb_surface_render_stroke_as_polygon (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - cairo_composite_rectangles_t *extents) -{ - cairo_polygon_t polygon; - cairo_status_t status; - - _cairo_polygon_init_with_clip (&polygon, extents->clip); - status = _cairo_path_fixed_stroke_to_polygon (path, - stroke_style, - ctm, ctm_inverse, - tolerance, - &polygon); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - status = _composite_polygon (dst, op, source, - &polygon, antialias, - CAIRO_FILL_RULE_WINDING, - extents); - } - _cairo_polygon_fini (&polygon); - - return status; -} - -static cairo_status_t -_cairo_xcb_surface_render_stroke_via_mask (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *image; - cairo_status_t status; - cairo_clip_t *clip; - int x, y; - - x = extents->bounded.x; - y = extents->bounded.y; - image = _cairo_xcb_surface_create_similar_image (dst, CAIRO_FORMAT_A8, - extents->bounded.width, - extents->bounded.height); - if (unlikely (image->status)) - return image->status; - - clip = _cairo_clip_copy_region (extents->clip); - status = _cairo_surface_offset_stroke (image, x, y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - path, stroke_style, - ctm, ctm_inverse, - tolerance, antialias, - clip); - _cairo_clip_destroy (clip); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - cairo_surface_pattern_t mask; - - _cairo_pattern_init_for_surface (&mask, image); - mask.base.filter = CAIRO_FILTER_NEAREST; - - cairo_matrix_init_translate (&mask.base.matrix, -x, -y); - status = _clip_and_composite (dst, op, source, - _composite_mask, NULL, &mask.base, - extents, need_bounded_clip (extents)); - _cairo_pattern_fini (&mask.base); - } - - cairo_surface_finish (image); - cairo_surface_destroy (image); - - return status; -} - -cairo_int_status_t -_cairo_xcb_render_compositor_stroke (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; - cairo_operator_t op = composite->op; - cairo_pattern_t *source = &composite->source_pattern.base; - cairo_int_status_t status; - - if (unlikely (! _operator_is_supported (surface->connection->flags, op))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | - CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_stroke_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, composite->clip); - status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, - style, - ctm, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - status = _clip_and_composite_boxes (surface, op, source, - &boxes, composite); - } - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) { - status = _cairo_xcb_surface_render_stroke_as_polygon (surface, op, source, - path, style, - ctm, ctm_inverse, - tolerance, antialias, - composite); - } else if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) { - status = _cairo_xcb_surface_render_stroke_via_mask (surface, op, source, - path, style, - ctm, ctm_inverse, - tolerance, antialias, - composite); - } else { - ASSERT_NOT_REACHED; - } - } - - return status; -} - -static cairo_status_t -_cairo_xcb_surface_render_fill_as_polygon (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t*source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - cairo_composite_rectangles_t *extents) -{ - cairo_polygon_t polygon; - cairo_status_t status; - - _cairo_polygon_init_with_clip (&polygon, extents->clip); - status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - status = _composite_polygon (dst, op, source, - &polygon, - antialias, - fill_rule, - extents); - } - _cairo_polygon_fini (&polygon); - - return status; -} - -static cairo_status_t -_cairo_xcb_surface_render_fill_via_mask (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *image; - cairo_status_t status; - cairo_clip_t *clip; - int x, y; - - x = extents->bounded.x; - y = extents->bounded.y; - image = _cairo_xcb_surface_create_similar_image (dst, CAIRO_FORMAT_A8, - extents->bounded.width, - extents->bounded.height); - if (unlikely (image->status)) - return image->status; - - clip = _cairo_clip_copy_region (extents->clip); - status = _cairo_surface_offset_fill (image, x, y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - path, fill_rule, tolerance, antialias, - clip); - _cairo_clip_destroy (clip); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - cairo_surface_pattern_t mask; - - _cairo_pattern_init_for_surface (&mask, image); - mask.base.filter = CAIRO_FILTER_NEAREST; - - cairo_matrix_init_translate (&mask.base.matrix, -x, -y); - status = _clip_and_composite (dst, op, source, - _composite_mask, NULL, &mask.base, - extents, need_bounded_clip (extents)); - - _cairo_pattern_fini (&mask.base); - } - - cairo_surface_finish (image); - cairo_surface_destroy (image); - - return status; -} - -cairo_int_status_t -_cairo_xcb_render_compositor_fill (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; - cairo_operator_t op = composite->op; - cairo_pattern_t *source = &composite->source_pattern.base; - cairo_int_status_t status; - - if (unlikely (! _operator_is_supported (surface->connection->flags, op))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | - CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_path_fixed_fill_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, composite->clip); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - fill_rule, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - status = _clip_and_composite_boxes (surface, op, source, - &boxes, composite); - } - _cairo_boxes_fini (&boxes); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) { - status = _cairo_xcb_surface_render_fill_as_polygon (surface, op, source, path, - fill_rule, tolerance, antialias, - composite); - } else if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) { - status = _cairo_xcb_surface_render_fill_via_mask (surface, op, source, path, - fill_rule, tolerance, antialias, - composite); - } else { - ASSERT_NOT_REACHED; - } - } - - return status; -} - -static cairo_status_t -_cairo_xcb_surface_render_glyphs_via_mask (cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_composite_rectangles_t *extents) -{ - cairo_surface_t *image; - cairo_content_t content; - cairo_status_t status; - cairo_clip_t *clip; - int x, y; - - content = CAIRO_CONTENT_ALPHA; - if (scaled_font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL) - content = CAIRO_CONTENT_COLOR_ALPHA; - - x = extents->bounded.x; - y = extents->bounded.y; - image = _cairo_xcb_surface_create_similar_image (dst, - _cairo_format_from_content (content), - extents->bounded.width, - extents->bounded.height); - if (unlikely (image->status)) - return image->status; - - clip = _cairo_clip_copy_region (extents->clip); - status = _cairo_surface_offset_glyphs (image, x, y, - CAIRO_OPERATOR_ADD, - &_cairo_pattern_white.base, - scaled_font, glyphs, num_glyphs, - clip); - _cairo_clip_destroy (clip); - if (likely (status == CAIRO_STATUS_SUCCESS)) { - cairo_surface_pattern_t mask; - - _cairo_pattern_init_for_surface (&mask, image); - mask.base.filter = CAIRO_FILTER_NEAREST; - if (content & CAIRO_CONTENT_COLOR) - mask.base.has_component_alpha = TRUE; - - cairo_matrix_init_translate (&mask.base.matrix, -x, -y); - status = _clip_and_composite (dst, op, source, - _composite_mask, NULL, &mask.base, - extents, need_bounded_clip (extents)); - - _cairo_pattern_fini (&mask.base); - } - - cairo_surface_finish (image); - cairo_surface_destroy (image); - - return status; -} - -/* Build a struct of the same size of #cairo_glyph_t that can be used both as - * an input glyph with double coordinates, and as "working" glyph with - * integer from-current-point offsets. */ -typedef union { - cairo_glyph_t d; - unsigned long index; - struct { - unsigned long index; - int x; - int y; - } i; -} cairo_xcb_glyph_t; - -/* compile-time assert that #cairo_xcb_glyph_t is the same size as #cairo_glyph_t */ -COMPILE_TIME_ASSERT (sizeof (cairo_xcb_glyph_t) == sizeof (cairo_glyph_t)); - -typedef struct { - cairo_scaled_font_t *font; - cairo_xcb_glyph_t *glyphs; - int num_glyphs; - cairo_bool_t use_mask; -} composite_glyphs_info_t; - -static cairo_status_t -_can_composite_glyphs (cairo_xcb_surface_t *dst, - cairo_rectangle_int_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs) -{ -#define GLYPH_CACHE_SIZE 64 - cairo_box_t bbox_cache[GLYPH_CACHE_SIZE]; - unsigned long glyph_cache[GLYPH_CACHE_SIZE]; -#undef GLYPH_CACHE_SIZE - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_glyph_t *glyphs_end, *valid_glyphs; - const int max_glyph_size = dst->connection->maximum_request_length - 64; - - /* We must initialize the cache with values that cannot match the - * "hash" to guarantee that when compared for the first time they - * will result in a mismatch. The hash function is simply modulus, - * so we cannot use 0 in glyph_cache[0], but we can use it in all - * other array cells. - */ - memset (glyph_cache, 0, sizeof (glyph_cache)); - glyph_cache[0] = 1; - - /* Scan for oversized glyphs or glyphs outside the representable - * range and fallback in that case, discard glyphs outside of the - * image. - */ - valid_glyphs = glyphs; - for (glyphs_end = glyphs + *num_glyphs; glyphs != glyphs_end; glyphs++) { - double x1, y1, x2, y2; - cairo_scaled_glyph_t *glyph; - cairo_box_t *bbox; - int width, height, len; - int g; - - g = glyphs->index % ARRAY_LENGTH (glyph_cache); - if (glyph_cache[g] != glyphs->index) { - status = _cairo_scaled_glyph_lookup (scaled_font, - glyphs->index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &glyph); - if (unlikely (status)) - break; - - glyph_cache[g] = glyphs->index; - bbox_cache[g] = glyph->bbox; - } - bbox = &bbox_cache[g]; - - /* Drop glyphs outside the clipping */ - x1 = _cairo_fixed_to_double (bbox->p1.x); - y1 = _cairo_fixed_to_double (bbox->p1.y); - y2 = _cairo_fixed_to_double (bbox->p2.y); - x2 = _cairo_fixed_to_double (bbox->p2.x); - if (unlikely (glyphs->x + x2 <= extents->x || - glyphs->y + y2 <= extents->y || - glyphs->x + x1 >= extents->x + extents->width || - glyphs->y + y1 >= extents->y + extents->height)) - { - (*num_glyphs)--; - continue; - } - - /* XRenderAddGlyph does not handle a glyph surface larger than - * the extended maximum XRequest size. - */ - width = _cairo_fixed_integer_ceil (bbox->p2.x - bbox->p1.x); - height = _cairo_fixed_integer_ceil (bbox->p2.y - bbox->p1.y); - len = CAIRO_STRIDE_FOR_WIDTH_BPP (width, 32) * height; - if (unlikely (len >= max_glyph_size)) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - break; - } - - /* The glyph coordinates must be representable in an int16_t. - * When possible, they will be expressed as an offset from the - * previous glyph, otherwise they will be an offset from the - * operation extents or from the surface origin. If the last - * two options are not valid, fallback. - */ - if (unlikely (glyphs->x > INT16_MAX || - glyphs->y > INT16_MAX || - glyphs->x - extents->x < INT16_MIN || - glyphs->y - extents->y < INT16_MIN)) - { - status = CAIRO_INT_STATUS_UNSUPPORTED; - break; - } - - - if (unlikely (valid_glyphs != glyphs)) - *valid_glyphs = *glyphs; - valid_glyphs++; - } - - if (unlikely (valid_glyphs != glyphs)) { - for (; glyphs != glyphs_end; glyphs++) { - *valid_glyphs = *glyphs; - valid_glyphs++; - } - } - - return status; -} - -/* Start a new element for the first glyph, - * or for any glyph that has unexpected position, - * or if current element has too many glyphs - * (Xrender limits each element to 252 glyphs, we limit them to 128) - * - * These same conditions need to be mirrored between - * _cairo_xcb_surface_emit_glyphs and _emit_glyph_chunks - */ -#define _start_new_glyph_elt(count, glyph) \ - (((count) & 127) == 0 || (glyph)->i.x || (glyph)->i.y) - -/* sz_xGlyphtElt required alignment to a 32-bit boundary, so ensure we have - * enough room for padding */ -typedef struct { - uint8_t len; - uint8_t pad1; - uint16_t pad2; - int16_t deltax; - int16_t deltay; -} x_glyph_elt_t; -#define _cairo_sz_x_glyph_elt_t (sizeof (x_glyph_elt_t) + 4) - -static void -_cairo_xcb_font_destroy (cairo_xcb_font_t *font) -{ - int i; - - for (i = 0; i < NUM_GLYPHSETS; i++) { - cairo_xcb_font_glyphset_info_t *info; - - info = &font->glyphset_info[i]; - free (info->pending_free_glyphs); - } - - cairo_list_del (&font->base.link); - cairo_list_del (&font->link); - - _cairo_xcb_connection_destroy (font->connection); - - free (font); -} - -static void -_cairo_xcb_font_fini (cairo_scaled_font_private_t *abstract_private, - cairo_scaled_font_t *scaled_font) -{ - cairo_xcb_font_t *font_private = (cairo_xcb_font_t *)abstract_private; - cairo_xcb_connection_t *connection; - cairo_bool_t have_connection; - cairo_status_t status; - int i; - - connection = font_private->connection; - - status = _cairo_xcb_connection_acquire (connection); - have_connection = status == CAIRO_STATUS_SUCCESS; - - for (i = 0; i < NUM_GLYPHSETS; i++) { - cairo_xcb_font_glyphset_info_t *info; - - info = &font_private->glyphset_info[i]; - if (info->glyphset && status == CAIRO_STATUS_SUCCESS) { - _cairo_xcb_connection_render_free_glyph_set (connection, - info->glyphset); - } - } - - if (have_connection) - _cairo_xcb_connection_release (connection); - - _cairo_xcb_font_destroy (font_private); -} - - -static cairo_xcb_font_t * -_cairo_xcb_font_create (cairo_xcb_connection_t *connection, - cairo_scaled_font_t *font) -{ - cairo_xcb_font_t *priv; - int i; - - priv = malloc (sizeof (cairo_xcb_font_t)); - if (unlikely (priv == NULL)) - return NULL; - - _cairo_scaled_font_attach_private (font, &priv->base, connection, - _cairo_xcb_font_fini); - - priv->scaled_font = font; - priv->connection = _cairo_xcb_connection_reference (connection); - cairo_list_add (&priv->link, &connection->fonts); - - for (i = 0; i < NUM_GLYPHSETS; i++) { - cairo_xcb_font_glyphset_info_t *info = &priv->glyphset_info[i]; - switch (i) { - case GLYPHSET_INDEX_ARGB32: info->format = CAIRO_FORMAT_ARGB32; break; - case GLYPHSET_INDEX_A8: info->format = CAIRO_FORMAT_A8; break; - case GLYPHSET_INDEX_A1: info->format = CAIRO_FORMAT_A1; break; - default: ASSERT_NOT_REACHED; break; - } - info->xrender_format = 0; - info->glyphset = XCB_NONE; - info->pending_free_glyphs = NULL; - } - - return priv; -} - -void -_cairo_xcb_font_close (cairo_xcb_font_t *font) -{ - cairo_scaled_font_t *scaled_font; - - scaled_font = font->scaled_font; - - //scaled_font->surface_private = NULL; - _cairo_scaled_font_reset_cache (scaled_font); - - _cairo_xcb_font_destroy (font); -} - -static void -_cairo_xcb_render_free_glyphs (cairo_xcb_connection_t *connection, - cairo_xcb_font_glyphset_free_glyphs_t *to_free) -{ - _cairo_xcb_connection_render_free_glyphs (connection, - to_free->glyphset, - to_free->glyph_count, - to_free->glyph_indices); -} - -static int -_cairo_xcb_get_glyphset_index_for_format (cairo_format_t format) -{ - if (format == CAIRO_FORMAT_A8) - return GLYPHSET_INDEX_A8; - if (format == CAIRO_FORMAT_A1) - return GLYPHSET_INDEX_A1; - - assert (format == CAIRO_FORMAT_ARGB32); - return GLYPHSET_INDEX_ARGB32; -} - - - -static inline cairo_xcb_font_t * -_cairo_xcb_font_get (const cairo_xcb_connection_t *c, - cairo_scaled_font_t *font) -{ - return (cairo_xcb_font_t *)_cairo_scaled_font_find_private (font, c); -} - - -static cairo_xcb_font_glyphset_info_t * -_cairo_xcb_scaled_font_get_glyphset_info_for_format (cairo_xcb_connection_t *c, - cairo_scaled_font_t *font, - cairo_format_t format) -{ - cairo_xcb_font_t *priv; - cairo_xcb_font_glyphset_info_t *info; - int glyphset_index; - - glyphset_index = _cairo_xcb_get_glyphset_index_for_format (format); - - priv = _cairo_xcb_font_get (c, font); - if (priv == NULL) { - priv = _cairo_xcb_font_create (c, font); - if (priv == NULL) - return NULL; - } - - info = &priv->glyphset_info[glyphset_index]; - if (info->glyphset == XCB_NONE) { - info->glyphset = _cairo_xcb_connection_get_xid (c); - info->xrender_format = c->standard_formats[info->format]; - - _cairo_xcb_connection_render_create_glyph_set (c, - info->glyphset, - info->xrender_format); - } - - return info; -} - -static cairo_bool_t -_cairo_xcb_glyphset_info_has_pending_free_glyph ( - cairo_xcb_font_glyphset_info_t *info, - unsigned long glyph_index) -{ - if (info->pending_free_glyphs != NULL) { - cairo_xcb_font_glyphset_free_glyphs_t *to_free; - int i; - - to_free = info->pending_free_glyphs; - for (i = 0; i < to_free->glyph_count; i++) { - if (to_free->glyph_indices[i] == glyph_index) { - to_free->glyph_count--; - memmove (&to_free->glyph_indices[i], - &to_free->glyph_indices[i+1], - (to_free->glyph_count - i) * sizeof (to_free->glyph_indices[0])); - return TRUE; - } - } - } - - return FALSE; -} - -typedef struct { - cairo_scaled_glyph_private_t base; - - cairo_xcb_font_glyphset_info_t *glyphset; -} cairo_xcb_glyph_private_t; - -static cairo_xcb_font_glyphset_info_t * -_cairo_xcb_scaled_font_get_glyphset_info_for_pending_free_glyph (cairo_xcb_connection_t *c, - cairo_scaled_font_t *font, - unsigned long glyph_index, - cairo_image_surface_t *surface) -{ - cairo_xcb_font_t *priv; - int i; - - priv = _cairo_xcb_font_get (c, font); - if (priv == NULL) - return NULL; - - if (surface != NULL) { - i = _cairo_xcb_get_glyphset_index_for_format (surface->format); - - if (_cairo_xcb_glyphset_info_has_pending_free_glyph ( - &priv->glyphset_info[i], - glyph_index)) - { - return &priv->glyphset_info[i]; - } - } else { - for (i = 0; i < NUM_GLYPHSETS; i++) { - if (_cairo_xcb_glyphset_info_has_pending_free_glyph ( - &priv->glyphset_info[i], - glyph_index)) - { - return &priv->glyphset_info[i]; - } - } - } - - return NULL; -} - -static void -_cairo_xcb_glyph_fini (cairo_scaled_glyph_private_t *glyph_private, - cairo_scaled_glyph_t *glyph, - cairo_scaled_font_t *font) -{ - cairo_xcb_glyph_private_t *priv = (cairo_xcb_glyph_private_t *)glyph_private; - - if (! font->finished) { - cairo_xcb_font_glyphset_info_t *info = priv->glyphset; - cairo_xcb_font_glyphset_free_glyphs_t *to_free; - cairo_xcb_font_t *font_private; - - font_private = _cairo_xcb_font_get (glyph_private->key, font); - assert (font_private); - - to_free = info->pending_free_glyphs; - if (to_free != NULL && - to_free->glyph_count == ARRAY_LENGTH (to_free->glyph_indices)) - { - _cairo_xcb_render_free_glyphs (font_private->connection, to_free); - to_free = info->pending_free_glyphs = NULL; - } - - if (to_free == NULL) { - to_free = malloc (sizeof (cairo_xcb_font_glyphset_free_glyphs_t)); - if (unlikely (to_free == NULL)) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return; /* XXX cannot propagate failure */ - } - - to_free->glyphset = info->glyphset; - to_free->glyph_count = 0; - info->pending_free_glyphs = to_free; - } - - to_free->glyph_indices[to_free->glyph_count++] = - _cairo_scaled_glyph_index (glyph); - } - - cairo_list_del (&glyph_private->link); - free (glyph_private); -} - - -static cairo_status_t -_cairo_xcb_glyph_attach (cairo_xcb_connection_t *c, - cairo_scaled_glyph_t *glyph, - cairo_xcb_font_glyphset_info_t *info) -{ - cairo_xcb_glyph_private_t *priv; - - priv = malloc (sizeof (*priv)); - if (unlikely (priv == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_scaled_glyph_attach_private (glyph, &priv->base, c, - _cairo_xcb_glyph_fini); - priv->glyphset = info; - - glyph->dev_private = info; - glyph->dev_private_key = c; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xcb_surface_add_glyph (cairo_xcb_connection_t *connection, - cairo_scaled_font_t *font, - cairo_scaled_glyph_t **scaled_glyph_out) -{ - xcb_render_glyphinfo_t glyph_info; - uint32_t glyph_index; - uint8_t *data; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_scaled_glyph_t *scaled_glyph = *scaled_glyph_out; - cairo_image_surface_t *glyph_surface = scaled_glyph->surface; - cairo_bool_t already_had_glyph_surface; - cairo_xcb_font_glyphset_info_t *info; - - glyph_index = _cairo_scaled_glyph_index (scaled_glyph); - - /* check to see if we have a pending XRenderFreeGlyph for this glyph */ - info = _cairo_xcb_scaled_font_get_glyphset_info_for_pending_free_glyph (connection, font, glyph_index, glyph_surface); - if (info != NULL) - return _cairo_xcb_glyph_attach (connection, scaled_glyph, info); - - if (glyph_surface == NULL) { - status = _cairo_scaled_glyph_lookup (font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS | - CAIRO_SCALED_GLYPH_INFO_SURFACE, - scaled_glyph_out); - if (unlikely (status)) - return status; - - scaled_glyph = *scaled_glyph_out; - glyph_surface = scaled_glyph->surface; - already_had_glyph_surface = FALSE; - } else { - already_had_glyph_surface = TRUE; - } - - info = _cairo_xcb_scaled_font_get_glyphset_info_for_format (connection, - font, - glyph_surface->format); - if (unlikely (info == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - -#if 0 - /* If the glyph surface has zero height or width, we create - * a clear 1x1 surface, to avoid various X server bugs. - */ - if (glyph_surface->width == 0 || glyph_surface->height == 0) { - cairo_surface_t *tmp_surface; - - tmp_surface = cairo_image_surface_create (info->format, 1, 1); - status = tmp_surface->status; - if (unlikely (status)) - goto BAIL; - - tmp_surface->device_transform = glyph_surface->base.device_transform; - tmp_surface->device_transform_inverse = glyph_surface->base.device_transform_inverse; - - glyph_surface = (cairo_image_surface_t *) tmp_surface; - } -#endif - - /* If the glyph format does not match the font format, then we - * create a temporary surface for the glyph image with the font's - * format. - */ - if (glyph_surface->format != info->format) { - glyph_surface = _cairo_image_surface_coerce_to_format (glyph_surface, - info->format); - status = glyph_surface->base.status; - if (unlikely (status)) - goto BAIL; - } - - /* XXX: FRAGILE: We're ignore device_transform scaling here. A bug? */ - glyph_info.x = _cairo_lround (glyph_surface->base.device_transform.x0); - glyph_info.y = _cairo_lround (glyph_surface->base.device_transform.y0); - glyph_info.width = glyph_surface->width; - glyph_info.height = glyph_surface->height; - glyph_info.x_off = scaled_glyph->x_advance; - glyph_info.y_off = scaled_glyph->y_advance; - - data = glyph_surface->data; - - /* flip formats around */ - switch (_cairo_xcb_get_glyphset_index_for_format (scaled_glyph->surface->format)) { - case GLYPHSET_INDEX_A1: - /* local bitmaps are always stored with bit == byte */ - if (_cairo_is_little_endian() != (connection->root->bitmap_format_bit_order == XCB_IMAGE_ORDER_LSB_FIRST)) { - int c = glyph_surface->stride * glyph_surface->height; - const uint8_t *d; - uint8_t *new, *n; - - if (c == 0) - break; - - new = malloc (c); - if (unlikely (new == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - - n = new; - d = data; - do { - uint8_t b = *d++; - b = ((b << 1) & 0xaa) | ((b >> 1) & 0x55); - b = ((b << 2) & 0xcc) | ((b >> 2) & 0x33); - b = ((b << 4) & 0xf0) | ((b >> 4) & 0x0f); - *n++ = b; - } while (--c); - data = new; - } - break; - - case GLYPHSET_INDEX_A8: - break; - - case GLYPHSET_INDEX_ARGB32: - if (_cairo_is_little_endian() != (connection->root->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST)) { - unsigned int c = glyph_surface->stride * glyph_surface->height / 4; - const uint32_t *d; - uint32_t *new, *n; - - if (c == 0) - break; - - new = malloc (4 * c); - if (unlikely (new == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - - n = new; - d = (uint32_t *) data; - do { - *n++ = bswap_32 (*d); - d++; - } while (--c); - data = (uint8_t *) new; - } - break; - - default: - ASSERT_NOT_REACHED; - break; - } - /* XXX assume X server wants pixman padding. Xft assumes this as well */ - - _cairo_xcb_connection_render_add_glyphs (connection, - info->glyphset, - 1, &glyph_index, &glyph_info, - glyph_surface->stride * glyph_surface->height, - data); - - if (data != glyph_surface->data) - free (data); - - status = _cairo_xcb_glyph_attach (connection, scaled_glyph, info); - - BAIL: - if (glyph_surface != scaled_glyph->surface) - cairo_surface_destroy (&glyph_surface->base); - - /* If the scaled glyph didn't already have a surface attached - * to it, release the created surface now that we have it - * uploaded to the X server. If the surface has already been - * there (e.g. because image backend requested it), leave it in - * the cache - */ - if (! already_had_glyph_surface) - _cairo_scaled_glyph_set_surface (scaled_glyph, font, NULL); - - return status; -} - -typedef void (*cairo_xcb_render_composite_text_func_t) - (cairo_xcb_connection_t *connection, - uint8_t op, - xcb_render_picture_t src, - xcb_render_picture_t dst, - xcb_render_pictformat_t mask_format, - xcb_render_glyphset_t glyphset, - int16_t src_x, - int16_t src_y, - uint32_t len, - uint8_t *cmd); - - -static cairo_status_t -_emit_glyphs_chunk (cairo_xcb_surface_t *dst, - cairo_operator_t op, - cairo_xcb_picture_t *src, - /* info for this chunk */ - cairo_xcb_glyph_t *glyphs, - int num_glyphs, - int width, - int estimated_req_size, - cairo_xcb_font_glyphset_info_t *info, - xcb_render_pictformat_t mask_format) -{ - cairo_xcb_render_composite_text_func_t composite_text_func; - uint8_t stack_buf[CAIRO_STACK_BUFFER_SIZE]; - uint8_t *buf = stack_buf; - x_glyph_elt_t *elt = NULL; /* silence compiler */ - uint32_t len; - int i; - - if (estimated_req_size > ARRAY_LENGTH (stack_buf)) { - buf = malloc (estimated_req_size); - if (unlikely (buf == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - len = 0; - for (i = 0; i < num_glyphs; i++) { - if (_start_new_glyph_elt (i, &glyphs[i])) { - if (len & 3) - len += 4 - (len & 3); - - elt = (x_glyph_elt_t *) (buf + len); - elt->len = 0; - elt->deltax = glyphs[i].i.x; - elt->deltay = glyphs[i].i.y; - len += sizeof (x_glyph_elt_t); - } - - switch (width) { - case 1: *(uint8_t *) (buf + len) = glyphs[i].index; break; - case 2: *(uint16_t *) (buf + len) = glyphs[i].index; break; - default: - case 4: *(uint32_t *) (buf + len) = glyphs[i].index; break; - } - len += width; - elt->len++; - } - if (len & 3) - len += 4 - (len & 3); - - switch (width) { - case 1: - composite_text_func = _cairo_xcb_connection_render_composite_glyphs_8; - break; - case 2: - composite_text_func = _cairo_xcb_connection_render_composite_glyphs_16; - break; - default: - case 4: - composite_text_func = _cairo_xcb_connection_render_composite_glyphs_32; - break; - } - composite_text_func (dst->connection, - _render_operator (op), - src->picture, - dst->picture, - mask_format, - info->glyphset, - src->x + glyphs[0].i.x, - src->y + glyphs[0].i.y, - len, buf); - - if (buf != stack_buf) - free (buf); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_composite_glyphs (void *closure, - cairo_xcb_surface_t *dst, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_clip_t *clip) -{ - composite_glyphs_info_t *info = closure; - cairo_scaled_glyph_t *glyph_cache[64]; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_fixed_t x = 0, y = 0; - cairo_xcb_font_glyphset_info_t *glyphset_info = NULL, *this_glyphset_info; - const unsigned int max_request_size = dst->connection->maximum_request_length - 64; - cairo_xcb_picture_t *src; - - unsigned long max_index = 0; - int width = 1; - - unsigned int request_size = 0; - int i; - - if (dst->deferred_clear) { - status = _cairo_xcb_surface_clear (dst); - if (unlikely (status)) - return status; - } - - src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); - if (unlikely (src->base.status)) - return src->base.status; - - memset (glyph_cache, 0, sizeof (glyph_cache)); - - for (i = 0; i < info->num_glyphs; i++) { - cairo_scaled_glyph_t *glyph; - unsigned long glyph_index = info->glyphs[i].index; - int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); - int old_width = width; - int this_x, this_y; - - glyph = glyph_cache[cache_index]; - if (glyph == NULL || - _cairo_scaled_glyph_index (glyph) != glyph_index) - { - status = _cairo_scaled_glyph_lookup (info->font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &glyph); - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return status; - } - - /* Send unseen glyphs to the server */ - if (glyph->dev_private_key != dst->connection) { - status = _cairo_xcb_surface_add_glyph (dst->connection, - info->font, - &glyph); - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return status; - } - } - - glyph_cache[cache_index] = glyph; - } - - this_x = _cairo_lround (info->glyphs[i].d.x) - dst_x; - this_y = _cairo_lround (info->glyphs[i].d.y) - dst_y; - - this_glyphset_info = glyph->dev_private; - if (glyphset_info == NULL) - glyphset_info = this_glyphset_info; - - /* Update max glyph index */ - if (glyph_index > max_index) { - max_index = glyph_index; - if (max_index >= 65536) - width = 4; - else if (max_index >= 256) - width = 2; - if (width != old_width) - request_size += (width - old_width) * i; - } - - /* If we will pass the max request size by adding this glyph, - * flush current glyphs. Note that we account for a - * possible element being added below. - * - * Also flush if changing glyphsets, as Xrender limits one mask - * format per request, so we can either break up, or use a - * wide-enough mask format. We do the former. One reason to - * prefer the latter is the fact that Xserver ADDs all glyphs - * to the mask first, and then composes that to final surface, - * though it's not a big deal. - * - * If the glyph has a coordinate which cannot be represented - * as a 16-bit offset from the previous glyph, flush the - * current chunk. The current glyph will be the first one in - * the next chunk, thus its coordinates will be an offset from - * the destination origin. This offset is guaranteed to be - * representable as 16-bit offset in _can_composite_glyphs(). - */ - if (request_size + width > max_request_size - _cairo_sz_x_glyph_elt_t || - this_x - x > INT16_MAX || this_x - x < INT16_MIN || - this_y - y > INT16_MAX || this_y - y < INT16_MIN || - this_glyphset_info != glyphset_info) - { - status = _emit_glyphs_chunk (dst, op, src, - info->glyphs, i, - old_width, request_size, - glyphset_info, - info->use_mask ? glyphset_info->xrender_format : 0); - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return status; - } - - info->glyphs += i; - info->num_glyphs -= i; - i = 0; - - max_index = info->glyphs[0].index; - width = max_index < 256 ? 1 : max_index < 65536 ? 2 : 4; - - request_size = 0; - - x = y = 0; - glyphset_info = this_glyphset_info; - } - - /* Convert absolute glyph position to relative-to-current-point - * position */ - info->glyphs[i].i.x = this_x - x; - info->glyphs[i].i.y = this_y - y; - - /* Start a new element for the first glyph, - * or for any glyph that has unexpected position, - * or if current element has too many glyphs. - * - * These same conditions are mirrored in _emit_glyphs_chunk(). - */ - if (_start_new_glyph_elt (i, &info->glyphs[i])) - request_size += _cairo_sz_x_glyph_elt_t; - - /* adjust current-position */ - x = this_x + glyph->x_advance; - y = this_y + glyph->y_advance; - - request_size += width; - } - - if (i) { - status = _emit_glyphs_chunk (dst, op, src, - info->glyphs, i, - width, request_size, - glyphset_info, - info->use_mask ? glyphset_info->xrender_format : 0); - } - - cairo_surface_destroy (&src->base); - - return status; -} - -cairo_int_status_t -_cairo_xcb_render_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *composite, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; - cairo_operator_t op = composite->op; - cairo_pattern_t *source = &composite->source_pattern.base; - cairo_int_status_t status; - - if (unlikely (! _operator_is_supported (surface->connection->flags, op))) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS | CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS) { - _cairo_scaled_font_freeze_cache (scaled_font); - - status = _can_composite_glyphs (surface, &composite->bounded, - scaled_font, glyphs, &num_glyphs); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { - composite_glyphs_info_t info; - unsigned flags = 0; - - info.font = scaled_font; - info.glyphs = (cairo_xcb_glyph_t *) glyphs; - info.num_glyphs = num_glyphs; - info.use_mask = - overlap || - ! composite->is_bounded || - ! _cairo_clip_is_region(composite->clip); - - if (composite->mask.width > composite->unbounded.width || - composite->mask.height > composite->unbounded.height) - { - /* Glyphs are tricky since we do not directly control the - * geometry and their inked extents depend on the - * individual glyph-surface size. We must set a clip region - * so that the X server can trim the glyphs appropriately. - */ - flags |= FORCE_CLIP_REGION; - } - status = _clip_and_composite (surface, op, source, - _composite_glyphs, NULL, - &info, composite, - need_bounded_clip (composite) | - flags); - } - - _cairo_scaled_font_thaw_cache (scaled_font); - } - - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - assert (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE); - status = - _cairo_xcb_surface_render_glyphs_via_mask (surface, op, source, - scaled_font, glyphs, num_glyphs, - composite); - } - - return status; -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface.c deleted file mode 100644 index d7e0d734ea5..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb-surface.c +++ /dev/null @@ -1,1530 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Behdad Esfahbod - * Carl D. Worth - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ - -#include "cairoint.h" - -#include "cairo-xcb.h" -#include "cairo-xcb-private.h" - -#include "cairo-composite-rectangles-private.h" -#include "cairo-default-context-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-list-inline.h" -#include "cairo-surface-backend-private.h" -#include "cairo-compositor-private.h" - -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_proto (cairo_xcb_surface_create); -slim_hidden_proto (cairo_xcb_surface_create_for_bitmap); -slim_hidden_proto (cairo_xcb_surface_create_with_xrender_format); -#endif - -/** - * SECTION:cairo-xcb - * @Title: XCB Surfaces - * @Short_Description: X Window System rendering using the XCB library - * @See_Also: #cairo_surface_t - * - * The XCB surface is used to render cairo graphics to X Window System - * windows and pixmaps using the XCB library. - * - * Note that the XCB surface automatically takes advantage of the X render - * extension if it is available. - **/ - -/** - * CAIRO_HAS_XCB_SURFACE: - * - * Defined if the xcb surface backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.12 - **/ - -cairo_surface_t * -_cairo_xcb_surface_create_similar (void *abstract_other, - cairo_content_t content, - int width, - int height) -{ - cairo_xcb_surface_t *other = abstract_other; - cairo_xcb_surface_t *surface; - cairo_xcb_connection_t *connection; - xcb_pixmap_t pixmap; - cairo_status_t status; - - if (unlikely(width > XLIB_COORD_MAX || - height > XLIB_COORD_MAX || - width <= 0 || - height <= 0)) - return cairo_image_surface_create (_cairo_format_from_content (content), - width, height); - - if ((other->connection->flags & CAIRO_XCB_HAS_RENDER) == 0) - return _cairo_xcb_surface_create_similar_image (other, - _cairo_format_from_content (content), - width, height); - - connection = other->connection; - status = _cairo_xcb_connection_acquire (connection); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (content == other->base.content) { - pixmap = _cairo_xcb_connection_create_pixmap (connection, - other->depth, - other->drawable, - width, height); - - surface = (cairo_xcb_surface_t *) - _cairo_xcb_surface_create_internal (other->screen, - pixmap, TRUE, - other->pixman_format, - other->xrender_format, - width, height); - } else { - cairo_format_t format; - pixman_format_code_t pixman_format; - - /* XXX find a compatible xrender format */ - switch (content) { - case CAIRO_CONTENT_ALPHA: - pixman_format = PIXMAN_a8; - format = CAIRO_FORMAT_A8; - break; - case CAIRO_CONTENT_COLOR: - pixman_format = PIXMAN_x8r8g8b8; - format = CAIRO_FORMAT_RGB24; - break; - default: - ASSERT_NOT_REACHED; - case CAIRO_CONTENT_COLOR_ALPHA: - pixman_format = PIXMAN_a8r8g8b8; - format = CAIRO_FORMAT_ARGB32; - break; - } - - pixmap = _cairo_xcb_connection_create_pixmap (connection, - PIXMAN_FORMAT_DEPTH (pixman_format), - other->drawable, - width, height); - - surface = (cairo_xcb_surface_t *) - _cairo_xcb_surface_create_internal (other->screen, - pixmap, TRUE, - pixman_format, - connection->standard_formats[format], - width, height); - } - - if (unlikely (surface->base.status)) - _cairo_xcb_connection_free_pixmap (connection, pixmap); - - _cairo_xcb_connection_release (connection); - - return &surface->base; -} - -cairo_surface_t * -_cairo_xcb_surface_create_similar_image (void *abstract_other, - cairo_format_t format, - int width, - int height) -{ - cairo_xcb_surface_t *other = abstract_other; - cairo_xcb_connection_t *connection = other->connection; - - cairo_xcb_shm_info_t *shm_info; - cairo_image_surface_t *image; - cairo_status_t status; - pixman_format_code_t pixman_format; - - if (unlikely(width > XLIB_COORD_MAX || - height > XLIB_COORD_MAX || - width <= 0 || - height <= 0)) - return NULL; - - pixman_format = _cairo_format_to_pixman_format_code (format); - - status = _cairo_xcb_shm_image_create (connection, pixman_format, - width, height, &image, - &shm_info); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (! image->base.is_clear) { - memset (image->data, 0, image->stride * image->height); - image->base.is_clear = TRUE; - } - - return &image->base; -} - -static cairo_status_t -_cairo_xcb_surface_finish (void *abstract_surface) -{ - cairo_xcb_surface_t *surface = abstract_surface; - cairo_status_t status; - - if (surface->fallback != NULL) { - cairo_surface_finish (&surface->fallback->base); - cairo_surface_destroy (&surface->fallback->base); - } - _cairo_boxes_fini (&surface->fallback_damage); - - cairo_list_del (&surface->link); - - status = _cairo_xcb_connection_acquire (surface->connection); - if (status == CAIRO_STATUS_SUCCESS) { - if (surface->picture != XCB_NONE) { - _cairo_xcb_connection_render_free_picture (surface->connection, - surface->picture); - } - - if (surface->owns_pixmap) - _cairo_xcb_connection_free_pixmap (surface->connection, surface->drawable); - _cairo_xcb_connection_release (surface->connection); - } - - _cairo_xcb_connection_destroy (surface->connection); - - return status; -} - -static void -_destroy_image (pixman_image_t *image, void *data) -{ - free (data); -} - -#if CAIRO_HAS_XCB_SHM_FUNCTIONS -static cairo_surface_t * -_cairo_xcb_surface_create_shm_image (cairo_xcb_connection_t *connection, - pixman_format_code_t pixman_format, - int width, int height, - cairo_bool_t might_reuse, - cairo_xcb_shm_info_t **shm_info_out) -{ - cairo_surface_t *image; - cairo_xcb_shm_info_t *shm_info; - cairo_int_status_t status; - size_t stride; - - *shm_info_out = NULL; - - stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, - PIXMAN_FORMAT_BPP (pixman_format)); - status = _cairo_xcb_connection_allocate_shm_info (connection, - stride * height, - might_reuse, - &shm_info); - if (unlikely (status)) { - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - return NULL; - - return _cairo_surface_create_in_error (status); - } - - image = _cairo_image_surface_create_with_pixman_format (shm_info->mem, - pixman_format, - width, height, - stride); - if (unlikely (image->status)) { - _cairo_xcb_shm_info_destroy (shm_info); - return image; - } - - status = _cairo_user_data_array_set_data (&image->user_data, - (const cairo_user_data_key_t *) connection, - shm_info, - (cairo_destroy_func_t) _cairo_xcb_shm_info_destroy); - if (unlikely (status)) { - cairo_surface_destroy (image); - _cairo_xcb_shm_info_destroy (shm_info); - return _cairo_surface_create_in_error (status); - } - - *shm_info_out = shm_info; - return image; -} -#endif - -static cairo_surface_t * -_get_shm_image (cairo_xcb_surface_t *surface, - int x, int y, - int width, int height) -{ -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - cairo_xcb_shm_info_t *shm_info; - cairo_surface_t *image; - cairo_status_t status; - - if ((surface->connection->flags & CAIRO_XCB_HAS_SHM) == 0) - return NULL; - - image = _cairo_xcb_surface_create_shm_image (surface->connection, - surface->pixman_format, - width, height, - TRUE, - &shm_info); - if (unlikely (image == NULL || image->status)) - goto done; - - status = _cairo_xcb_connection_shm_get_image (surface->connection, - surface->drawable, - x, y, - width, height, - shm_info->shm, - shm_info->offset); - if (unlikely (status)) { - cairo_surface_destroy (image); - image = _cairo_surface_create_in_error (status); - } - -done: - return image; -#else - return NULL; -#endif -} - -static cairo_surface_t * -_get_image (cairo_xcb_surface_t *surface, - cairo_bool_t use_shm, - int x, int y, - int width, int height) -{ - cairo_surface_t *image; - cairo_xcb_connection_t *connection; - xcb_get_image_reply_t *reply; - cairo_int_status_t status; - - assert (surface->fallback == NULL); - assert (x >= 0); - assert (y >= 0); - assert (x + width <= surface->width); - assert (y + height <= surface->height); - - if (surface->deferred_clear) { - image = - _cairo_image_surface_create_with_pixman_format (NULL, - surface->pixman_format, - width, height, - 0); - if (surface->deferred_clear_color.alpha_short > 0x00ff) { - cairo_solid_pattern_t solid; - - _cairo_pattern_init_solid (&solid, &surface->deferred_clear_color); - status = _cairo_surface_paint (image, - CAIRO_OPERATOR_SOURCE, - &solid.base, - NULL); - if (unlikely (status)) { - cairo_surface_destroy (image); - image = _cairo_surface_create_in_error (status); - } - } - return image; - } - - connection = surface->connection; - - status = _cairo_xcb_connection_acquire (connection); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (use_shm) { - image = _get_shm_image (surface, x, y, width, height); - if (image) { - if (image->status == CAIRO_STATUS_SUCCESS) { - _cairo_xcb_connection_release (connection); - return image; - } - cairo_surface_destroy (image); - } - } - - reply =_cairo_xcb_connection_get_image (connection, - surface->drawable, - x, y, - width, height); - - if (reply == NULL && ! surface->owns_pixmap) { - /* xcb_get_image_t from a window is dangerous because it can - * produce errors if the window is unmapped or partially - * outside the screen. We could check for errors and - * retry, but to keep things simple, we just create a - * temporary pixmap - * - * If we hit this fallback too often, we should remember so and - * skip the round-trip from the above GetImage request, - * similar to what cairo-xlib does. - */ - xcb_pixmap_t pixmap; - xcb_gcontext_t gc; - - gc = _cairo_xcb_screen_get_gc (surface->screen, - surface->drawable, - surface->depth); - pixmap = _cairo_xcb_connection_create_pixmap (connection, - surface->depth, - surface->drawable, - width, height); - - /* XXX IncludeInferiors? */ - _cairo_xcb_connection_copy_area (connection, - surface->drawable, - pixmap, gc, - x, y, - 0, 0, - width, height); - - _cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc); - - reply = _cairo_xcb_connection_get_image (connection, - pixmap, - 0, 0, - width, height); - _cairo_xcb_connection_free_pixmap (connection, pixmap); - } - - if (unlikely (reply == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto FAIL; - } - - /* XXX byte swap */ - /* XXX format conversion */ - assert (reply->depth == surface->depth); - - image = _cairo_image_surface_create_with_pixman_format - (xcb_get_image_data (reply), - surface->pixman_format, - width, height, - CAIRO_STRIDE_FOR_WIDTH_BPP (width, - PIXMAN_FORMAT_BPP (surface->pixman_format))); - status = image->status; - if (unlikely (status)) { - free (reply); - goto FAIL; - } - - /* XXX */ - pixman_image_set_destroy_function (((cairo_image_surface_t *)image)->pixman_image, _destroy_image, reply); - - _cairo_xcb_connection_release (connection); - - return image; - -FAIL: - _cairo_xcb_connection_release (connection); - return _cairo_surface_create_in_error (status); -} - -static cairo_surface_t * -_cairo_xcb_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_xcb_surface_t *surface = abstract_surface; - - if (extents) { - extents->x = extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - } - - return &surface->base; -} - -static cairo_status_t -_cairo_xcb_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_xcb_surface_t *surface = abstract_surface; - cairo_surface_t *image; - - if (surface->fallback != NULL) { - image = cairo_surface_reference (&surface->fallback->base); - goto DONE; - } - - image = _cairo_surface_has_snapshot (&surface->base, - &_cairo_image_surface_backend); - if (image != NULL) { - image = cairo_surface_reference (image); - goto DONE; - } - - image = _get_image (surface, FALSE, 0, 0, surface->width, surface->height); - if (unlikely (image->status)) - return image->status; - - _cairo_surface_attach_snapshot (&surface->base, image, NULL); - -DONE: - *image_out = (cairo_image_surface_t *) image; - *image_extra = NULL; - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_xcb_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_surface_destroy (&image->base); -} - -cairo_bool_t -_cairo_xcb_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_xcb_surface_t *surface = abstract_surface; - - extents->x = extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - return TRUE; -} - -static void -_cairo_xcb_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_xcb_surface_t *surface = abstract_surface; - - *options = *_cairo_xcb_screen_get_font_options (surface->screen); -} - -static cairo_status_t -_put_shm_image (cairo_xcb_surface_t *surface, - xcb_gcontext_t gc, - cairo_image_surface_t *image) -{ -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - cairo_xcb_shm_info_t *shm_info; - - shm_info = _cairo_user_data_array_get_data (&image->base.user_data, - (const cairo_user_data_key_t *) surface->connection); - if (shm_info == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - _cairo_xcb_connection_shm_put_image (surface->connection, - surface->drawable, - gc, - surface->width, surface->height, - 0, 0, - image->width, image->height, - image->base.device_transform_inverse.x0, - image->base.device_transform_inverse.y0, - image->depth, - shm_info->shm, - shm_info->offset); - - return CAIRO_STATUS_SUCCESS; -#else - return CAIRO_INT_STATUS_UNSUPPORTED; -#endif -} - -static cairo_status_t -_put_image (cairo_xcb_surface_t *surface, - cairo_image_surface_t *image) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - - /* XXX track damaged region? */ - - status = _cairo_xcb_connection_acquire (surface->connection); - if (unlikely (status)) - return status; - - if (image->pixman_format == surface->pixman_format) { - xcb_gcontext_t gc; - - assert (image->depth == surface->depth); - assert (image->stride == (int) CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, PIXMAN_FORMAT_BPP (image->pixman_format))); - - gc = _cairo_xcb_screen_get_gc (surface->screen, - surface->drawable, - surface->depth); - - status = _put_shm_image (surface, gc, image); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - _cairo_xcb_connection_put_image (surface->connection, - surface->drawable, gc, - image->width, image->height, - image->base.device_transform_inverse.x0, - image->base.device_transform_inverse.y0, - image->depth, - image->stride, - image->data); - status = CAIRO_STATUS_SUCCESS; - } - - _cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc); - } else { - ASSERT_NOT_REACHED; - } - - _cairo_xcb_connection_release (surface->connection); - return status; -} - -static cairo_int_status_t -_put_shm_image_boxes (cairo_xcb_surface_t *surface, - cairo_image_surface_t *image, - xcb_gcontext_t gc, - cairo_boxes_t *boxes) -{ -#if CAIRO_HAS_XCB_SHM_FUNCTIONS - cairo_xcb_shm_info_t *shm_info; - - shm_info = _cairo_user_data_array_get_data (&image->base.user_data, - (const cairo_user_data_key_t *) surface->connection); - if (shm_info != NULL) { - struct _cairo_boxes_chunk *chunk; - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - int i; - - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - int x = _cairo_fixed_integer_part (b->p1.x); - int y = _cairo_fixed_integer_part (b->p1.y); - int width = _cairo_fixed_integer_part (b->p2.x - b->p1.x); - int height = _cairo_fixed_integer_part (b->p2.y - b->p1.y); - - _cairo_xcb_connection_shm_put_image (surface->connection, - surface->drawable, - gc, - surface->width, surface->height, - x, y, - width, height, - x, y, - image->depth, - shm_info->shm, - shm_info->offset); - } - } - } - - return CAIRO_INT_STATUS_SUCCESS; -#endif - - return CAIRO_INT_STATUS_UNSUPPORTED; -} - -static cairo_status_t -_put_image_boxes (cairo_xcb_surface_t *surface, - cairo_image_surface_t *image, - cairo_boxes_t *boxes) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - xcb_gcontext_t gc; - - if (boxes->num_boxes == 0) - return CAIRO_STATUS_SUCCESS; - - /* XXX track damaged region? */ - - status = _cairo_xcb_connection_acquire (surface->connection); - if (unlikely (status)) - return status; - - assert (image->pixman_format == surface->pixman_format); - assert (image->depth == surface->depth); - assert (image->stride == (int) CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, PIXMAN_FORMAT_BPP (image->pixman_format))); - - gc = _cairo_xcb_screen_get_gc (surface->screen, - surface->drawable, - surface->depth); - - status = _put_shm_image_boxes (surface, image, gc, boxes); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - struct _cairo_boxes_chunk *chunk; - - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - int i; - - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - int x = _cairo_fixed_integer_part (b->p1.x); - int y = _cairo_fixed_integer_part (b->p1.y); - int width = _cairo_fixed_integer_part (b->p2.x - b->p1.x); - int height = _cairo_fixed_integer_part (b->p2.y - b->p1.y); - _cairo_xcb_connection_put_image (surface->connection, - surface->drawable, gc, - width, height, - x, y, - image->depth, - image->stride, - image->data + - x * PIXMAN_FORMAT_BPP (image->pixman_format) / 8 + - y * image->stride); - - } - } - status = CAIRO_STATUS_SUCCESS; - } - - _cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc); - _cairo_xcb_connection_release (surface->connection); - return status; -} - -static cairo_status_t -_cairo_xcb_surface_flush (void *abstract_surface, - unsigned flags) -{ - cairo_xcb_surface_t *surface = abstract_surface; - cairo_status_t status; - - if (flags) - return CAIRO_STATUS_SUCCESS; - - if (likely (surface->fallback == NULL)) { - status = CAIRO_STATUS_SUCCESS; - if (! surface->base.finished && surface->deferred_clear) - status = _cairo_xcb_surface_clear (surface); - - return status; - } - - status = surface->base.status; - if (status == CAIRO_STATUS_SUCCESS && - (! surface->base._finishing || ! surface->owns_pixmap)) { - status = cairo_surface_status (&surface->fallback->base); - - if (status == CAIRO_STATUS_SUCCESS) - status = _cairo_bentley_ottmann_tessellate_boxes (&surface->fallback_damage, - CAIRO_FILL_RULE_WINDING, - &surface->fallback_damage); - - if (status == CAIRO_STATUS_SUCCESS) - status = _put_image_boxes (surface, - surface->fallback, - &surface->fallback_damage); - - if (status == CAIRO_STATUS_SUCCESS && ! surface->base._finishing) { - _cairo_surface_attach_snapshot (&surface->base, - &surface->fallback->base, - cairo_surface_finish); - } - } - - _cairo_boxes_clear (&surface->fallback_damage); - cairo_surface_destroy (&surface->fallback->base); - surface->fallback = NULL; - - return status; -} - -static cairo_image_surface_t * -_cairo_xcb_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_xcb_surface_t *surface = abstract_surface; - cairo_surface_t *image; - cairo_status_t status; - - if (surface->fallback) - return _cairo_surface_map_to_image (&surface->fallback->base, extents); - - image = _get_image (surface, TRUE, - extents->x, extents->y, - extents->width, extents->height); - status = cairo_surface_status (image); - if (unlikely (status)) { - cairo_surface_destroy(image); - return _cairo_image_surface_create_in_error (status); - } - - /* Do we have a deferred clear and this image surface does NOT cover the - * whole xcb surface? Have to apply the clear in that case, else - * uploading the image will handle the problem for us. - */ - if (surface->deferred_clear && - ! (extents->width == surface->width && - extents->height == surface->height)) { - status = _cairo_xcb_surface_clear (surface); - if (unlikely (status)) { - cairo_surface_destroy(image); - return _cairo_image_surface_create_in_error (status); - } - } - surface->deferred_clear = FALSE; - - cairo_surface_set_device_offset (image, -extents->x, -extents->y); - return (cairo_image_surface_t *) image; -} - -static cairo_int_status_t -_cairo_xcb_surface_unmap (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_xcb_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - if (surface->fallback) - return _cairo_surface_unmap_image (&surface->fallback->base, image); - - status = _put_image (abstract_surface, image); - - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return status; -} - -static cairo_surface_t * -_cairo_xcb_surface_fallback (cairo_xcb_surface_t *surface, - cairo_composite_rectangles_t *composite) -{ - cairo_image_surface_t *image; - cairo_status_t status; - - status = _cairo_composite_rectangles_add_to_damage (composite, - &surface->fallback_damage); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (surface->fallback) - return &surface->fallback->base; - - image = (cairo_image_surface_t *) - _get_image (surface, TRUE, 0, 0, surface->width, surface->height); - - /* If there was a deferred clear, _get_image applied it */ - if (image->base.status == CAIRO_STATUS_SUCCESS) { - surface->deferred_clear = FALSE; - - surface->fallback = image; - } - - return &surface->fallback->base; -} - -static cairo_int_status_t -_cairo_xcb_fallback_compositor_paint (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; - cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); - - return _cairo_surface_paint (fallback, extents->op, - &extents->source_pattern.base, - extents->clip); -} - -static cairo_int_status_t -_cairo_xcb_fallback_compositor_mask (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; - cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); - - return _cairo_surface_mask (fallback, extents->op, - &extents->source_pattern.base, - &extents->mask_pattern.base, - extents->clip); -} - -static cairo_int_status_t -_cairo_xcb_fallback_compositor_stroke (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; - cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); - - return _cairo_surface_stroke (fallback, extents->op, - &extents->source_pattern.base, - path, style, ctm, ctm_inverse, - tolerance, antialias, - extents->clip); -} - -static cairo_int_status_t -_cairo_xcb_fallback_compositor_fill (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; - cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); - - return _cairo_surface_fill (fallback, extents->op, - &extents->source_pattern.base, - path, fill_rule, tolerance, - antialias, extents->clip); -} - -static cairo_int_status_t -_cairo_xcb_fallback_compositor_glyphs (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; - cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); - - return _cairo_surface_show_text_glyphs (fallback, extents->op, - &extents->source_pattern.base, - NULL, 0, glyphs, num_glyphs, - NULL, 0, 0, - scaled_font, extents->clip); -} - -static const cairo_compositor_t _cairo_xcb_fallback_compositor = { - &__cairo_no_compositor, - - _cairo_xcb_fallback_compositor_paint, - _cairo_xcb_fallback_compositor_mask, - _cairo_xcb_fallback_compositor_stroke, - _cairo_xcb_fallback_compositor_fill, - _cairo_xcb_fallback_compositor_glyphs, -}; - -static const cairo_compositor_t _cairo_xcb_render_compositor = { - &_cairo_xcb_fallback_compositor, - - _cairo_xcb_render_compositor_paint, - _cairo_xcb_render_compositor_mask, - _cairo_xcb_render_compositor_stroke, - _cairo_xcb_render_compositor_fill, - _cairo_xcb_render_compositor_glyphs, -}; - -static inline const cairo_compositor_t * -get_compositor (cairo_surface_t **s) -{ - cairo_xcb_surface_t *surface = (cairo_xcb_surface_t * )*s; - if (surface->fallback) { - *s = &surface->fallback->base; - return ((cairo_image_surface_t *) *s)->compositor; - } - - return &_cairo_xcb_render_compositor; -} - -static cairo_int_status_t -_cairo_xcb_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_surface_t *surface = abstract_surface; - const cairo_compositor_t *compositor = get_compositor (&surface); - return _cairo_compositor_paint (compositor, surface, op, source, clip); -} - -static cairo_int_status_t -_cairo_xcb_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_surface_t *surface = abstract_surface; - const cairo_compositor_t *compositor = get_compositor (&surface); - return _cairo_compositor_mask (compositor, surface, op, source, mask, clip); -} - -static cairo_int_status_t -_cairo_xcb_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_surface_t *surface = abstract_surface; - const cairo_compositor_t *compositor = get_compositor (&surface); - return _cairo_compositor_stroke (compositor, surface, op, source, - path, style, ctm, ctm_inverse, - tolerance, antialias, clip); -} - -static cairo_int_status_t -_cairo_xcb_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_surface_t *surface = abstract_surface; - const cairo_compositor_t *compositor = get_compositor (&surface); - return _cairo_compositor_fill (compositor, surface, op, - source, path, fill_rule, - tolerance, antialias, clip); -} - -static cairo_int_status_t -_cairo_xcb_surface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_surface_t *surface = abstract_surface; - const cairo_compositor_t *compositor = get_compositor (&surface); - return _cairo_compositor_glyphs (compositor, surface, op, - source, glyphs, num_glyphs, - scaled_font, clip); -} - -const cairo_surface_backend_t _cairo_xcb_surface_backend = { - CAIRO_SURFACE_TYPE_XCB, - _cairo_xcb_surface_finish, - _cairo_default_context_create, - - _cairo_xcb_surface_create_similar, - _cairo_xcb_surface_create_similar_image, - _cairo_xcb_surface_map_to_image, - _cairo_xcb_surface_unmap, - - _cairo_xcb_surface_source, - _cairo_xcb_surface_acquire_source_image, - _cairo_xcb_surface_release_source_image, - NULL, /* snapshot */ - - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_xcb_surface_get_extents, - _cairo_xcb_surface_get_font_options, - - _cairo_xcb_surface_flush, - NULL, - - _cairo_xcb_surface_paint, - _cairo_xcb_surface_mask, - _cairo_xcb_surface_stroke, - _cairo_xcb_surface_fill, - NULL, /* fill-stroke */ - _cairo_xcb_surface_glyphs, -}; - -cairo_surface_t * -_cairo_xcb_surface_create_internal (cairo_xcb_screen_t *screen, - xcb_drawable_t drawable, - cairo_bool_t owns_pixmap, - pixman_format_code_t pixman_format, - xcb_render_pictformat_t xrender_format, - int width, - int height) -{ - cairo_xcb_surface_t *surface; - - surface = malloc (sizeof (cairo_xcb_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_xcb_surface_backend, - &screen->connection->device, - _cairo_content_from_pixman_format (pixman_format)); - - surface->connection = _cairo_xcb_connection_reference (screen->connection); - surface->screen = screen; - cairo_list_add (&surface->link, &screen->surfaces); - - surface->drawable = drawable; - surface->owns_pixmap = owns_pixmap; - - surface->deferred_clear = FALSE; - surface->deferred_clear_color = *CAIRO_COLOR_TRANSPARENT; - - surface->width = width; - surface->height = height; - surface->depth = PIXMAN_FORMAT_DEPTH (pixman_format); - - surface->picture = XCB_NONE; - if (screen->connection->force_precision != -1) - surface->precision = screen->connection->force_precision; - else - surface->precision = XCB_RENDER_POLY_MODE_IMPRECISE; - - surface->pixman_format = pixman_format; - surface->xrender_format = xrender_format; - - surface->fallback = NULL; - _cairo_boxes_init (&surface->fallback_damage); - - return &surface->base; -} - -static xcb_screen_t * -_cairo_xcb_screen_from_visual (xcb_connection_t *connection, - xcb_visualtype_t *visual, - int *depth) -{ - xcb_depth_iterator_t d; - xcb_screen_iterator_t s; - - s = xcb_setup_roots_iterator (xcb_get_setup (connection)); - for (; s.rem; xcb_screen_next (&s)) { - if (s.data->root_visual == visual->visual_id) { - *depth = s.data->root_depth; - return s.data; - } - - d = xcb_screen_allowed_depths_iterator(s.data); - for (; d.rem; xcb_depth_next (&d)) { - xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator (d.data); - - for (; v.rem; xcb_visualtype_next (&v)) { - if (v.data->visual_id == visual->visual_id) { - *depth = d.data->depth; - return s.data; - } - } - } - } - - return NULL; -} - -/** - * cairo_xcb_surface_create: - * @connection: an XCB connection - * @drawable: an XCB drawable - * @visual: the visual to use for drawing to @drawable. The depth - * of the visual must match the depth of the drawable. - * Currently, only TrueColor visuals are fully supported. - * @width: the current width of @drawable - * @height: the current height of @drawable - * - * Creates an XCB surface that draws to the given drawable. - * The way that colors are represented in the drawable is specified - * by the provided visual. - * - * Note: If @drawable is a Window, then the function - * cairo_xcb_surface_set_size() must be called whenever the size of the - * window changes. - * - * When @drawable is a Window containing child windows then drawing to - * the created surface will be clipped by those child windows. When - * the created surface is used as a source, the contents of the - * children will be included. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_xcb_surface_create (xcb_connection_t *connection, - xcb_drawable_t drawable, - xcb_visualtype_t *visual, - int width, - int height) -{ - cairo_xcb_screen_t *screen; - xcb_screen_t *xcb_screen; - cairo_format_masks_t image_masks; - pixman_format_code_t pixman_format; - xcb_render_pictformat_t xrender_format; - int depth; - - if (xcb_connection_has_error (connection)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); - - if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - if (unlikely (width <= 0 || height <= 0)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - xcb_screen = _cairo_xcb_screen_from_visual (connection, visual, &depth); - if (unlikely (xcb_screen == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); - - image_masks.alpha_mask = 0; - image_masks.red_mask = visual->red_mask; - image_masks.green_mask = visual->green_mask; - image_masks.blue_mask = visual->blue_mask; - if (depth == 32) /* XXX visuals have no alpha! */ - image_masks.alpha_mask = - 0xffffffff & ~(visual->red_mask | visual->green_mask | visual->blue_mask); - if (depth > 16) - image_masks.bpp = 32; - else if (depth > 8) - image_masks.bpp = 16; - else if (depth > 1) - image_masks.bpp = 8; - else - image_masks.bpp = 1; - - if (! _pixman_format_from_masks (&image_masks, &pixman_format)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - - screen = _cairo_xcb_screen_get (connection, xcb_screen); - if (unlikely (screen == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - xrender_format = - _cairo_xcb_connection_get_xrender_format_for_visual (screen->connection, - visual->visual_id); - - return _cairo_xcb_surface_create_internal (screen, drawable, FALSE, - pixman_format, - xrender_format, - width, height); -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_surface_create); -#endif - -/** - * cairo_xcb_surface_create_for_bitmap: - * @connection: an XCB connection - * @screen: the XCB screen associated with @bitmap - * @bitmap: an XCB drawable (a Pixmap with depth 1) - * @width: the current width of @bitmap - * @height: the current height of @bitmap - * - * Creates an XCB surface that draws to the given bitmap. - * This will be drawn to as a %CAIRO_FORMAT_A1 object. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_xcb_surface_create_for_bitmap (xcb_connection_t *connection, - xcb_screen_t *screen, - xcb_pixmap_t bitmap, - int width, - int height) -{ - cairo_xcb_screen_t *cairo_xcb_screen; - - if (xcb_connection_has_error (connection)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); - - if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - if (unlikely (width <= 0 || height <= 0)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - cairo_xcb_screen = _cairo_xcb_screen_get (connection, screen); - if (unlikely (cairo_xcb_screen == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - return _cairo_xcb_surface_create_internal (cairo_xcb_screen, bitmap, FALSE, - PIXMAN_a1, - cairo_xcb_screen->connection->standard_formats[CAIRO_FORMAT_A1], - width, height); -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_surface_create_for_bitmap); -#endif - -/** - * cairo_xcb_surface_create_with_xrender_format: - * @connection: an XCB connection - * @drawable: an XCB drawable - * @screen: the XCB screen associated with @drawable - * @format: the picture format to use for drawing to @drawable. The - * depth of @format mush match the depth of the drawable. - * @width: the current width of @drawable - * @height: the current height of @drawable - * - * Creates an XCB surface that draws to the given drawable. - * The way that colors are represented in the drawable is specified - * by the provided picture format. - * - * Note: If @drawable is a Window, then the function - * cairo_xcb_surface_set_size() must be called whenever the size of the - * window changes. - * - * When @drawable is a Window containing child windows then drawing to - * the created surface will be clipped by those child windows. When - * the created surface is used as a source, the contents of the - * children will be included. - * - * Return value: a pointer to the newly created surface. The caller - * owns the surface and should call cairo_surface_destroy() when done - * with it. - * - * This function always returns a valid pointer, but it will return a - * pointer to a "nil" surface if an error such as out of memory - * occurs. You can use cairo_surface_status() to check for this. - * - * Since: 1.12 - **/ -cairo_surface_t * -cairo_xcb_surface_create_with_xrender_format (xcb_connection_t *connection, - xcb_screen_t *screen, - xcb_drawable_t drawable, - xcb_render_pictforminfo_t *format, - int width, - int height) -{ - cairo_xcb_screen_t *cairo_xcb_screen; - cairo_format_masks_t image_masks; - pixman_format_code_t pixman_format; - - if (xcb_connection_has_error (connection)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); - - if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - if (unlikely (width <= 0 || height <= 0)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - image_masks.alpha_mask = - (unsigned long) format->direct.alpha_mask << format->direct.alpha_shift; - image_masks.red_mask = - (unsigned long) format->direct.red_mask << format->direct.red_shift; - image_masks.green_mask = - (unsigned long) format->direct.green_mask << format->direct.green_shift; - image_masks.blue_mask = - (unsigned long) format->direct.blue_mask << format->direct.blue_shift; -#if 0 - image_masks.bpp = format->depth; -#else - if (format->depth > 16) - image_masks.bpp = 32; - else if (format->depth > 8) - image_masks.bpp = 16; - else if (format->depth > 1) - image_masks.bpp = 8; - else - image_masks.bpp = 1; -#endif - - if (! _pixman_format_from_masks (&image_masks, &pixman_format)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); - - cairo_xcb_screen = _cairo_xcb_screen_get (connection, screen); - if (unlikely (cairo_xcb_screen == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - return _cairo_xcb_surface_create_internal (cairo_xcb_screen, - drawable, - FALSE, - pixman_format, - format->id, - width, height); -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_surface_create_with_xrender_format); -#endif - -/* This does the necessary fixup when a surface's drawable or size changed. */ -static void -_drawable_changed (cairo_xcb_surface_t *surface) -{ - _cairo_surface_set_error (&surface->base, - _cairo_surface_begin_modification (&surface->base)); - _cairo_boxes_clear (&surface->fallback_damage); - cairo_surface_destroy (&surface->fallback->base); - - surface->deferred_clear = FALSE; - surface->fallback = NULL; -} - -/** - * cairo_xcb_surface_set_size: - * @surface: a #cairo_surface_t for the XCB backend - * @width: the new width of the surface - * @height: the new height of the surface - * - * Informs cairo of the new size of the XCB drawable underlying the - * surface. For a surface created for a window (rather than a pixmap), - * this function must be called each time the size of the window - * changes. (For a subwindow, you are normally resizing the window - * yourself, but for a toplevel window, it is necessary to listen for - * ConfigureNotify events.) - * - * A pixmap can never change size, so it is never necessary to call - * this function on a surface created for a pixmap. - * - * If cairo_surface_flush() wasn't called, some pending operations - * might be discarded. - * - * Since: 1.12 - **/ -void -cairo_xcb_surface_set_size (cairo_surface_t *abstract_surface, - int width, - int height) -{ - cairo_xcb_surface_t *surface; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - - if ( !_cairo_surface_is_xcb(abstract_surface)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX || width <= 0 || height <= 0) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_INVALID_SIZE)); - return; - } - - surface = (cairo_xcb_surface_t *) abstract_surface; - - _drawable_changed(surface); - surface->width = width; - surface->height = height; -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_surface_set_size); -#endif - -/** - * cairo_xcb_surface_set_drawable: - * @surface: a #cairo_surface_t for the XCB backend - * @drawable: the new drawable of the surface - * @width: the new width of the surface - * @height: the new height of the surface - * - * Informs cairo of the new drawable and size of the XCB drawable underlying the - * surface. - * - * If cairo_surface_flush() wasn't called, some pending operations - * might be discarded. - * - * Since: 1.12 - **/ -void -cairo_xcb_surface_set_drawable (cairo_surface_t *abstract_surface, - xcb_drawable_t drawable, - int width, - int height) -{ - cairo_xcb_surface_t *surface; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - - if ( !_cairo_surface_is_xcb(abstract_surface)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX || width <= 0 || height <= 0) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_INVALID_SIZE)); - return; - } - - surface = (cairo_xcb_surface_t *) abstract_surface; - - /* XXX: and what about this case? */ - if (surface->owns_pixmap) - return; - - _drawable_changed (surface); - - if (surface->drawable != drawable) { - cairo_status_t status; - status = _cairo_xcb_connection_acquire (surface->connection); - if (unlikely (status)) - return; - - if (surface->picture != XCB_NONE) { - _cairo_xcb_connection_render_free_picture (surface->connection, - surface->picture); - surface->picture = XCB_NONE; - } - - _cairo_xcb_connection_release (surface->connection); - - surface->drawable = drawable; - } - surface->width = width; - surface->height = height; -} -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS -slim_hidden_def (cairo_xcb_surface_set_drawable); -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb.h deleted file mode 100644 index e321d8482c2..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xcb.h +++ /dev/null @@ -1,116 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#ifndef CAIRO_XCB_H -#define CAIRO_XCB_H - -#include "cairo.h" - -#if CAIRO_HAS_XCB_SURFACE - -#include -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_xcb_surface_create (xcb_connection_t *connection, - xcb_drawable_t drawable, - xcb_visualtype_t *visual, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_xcb_surface_create_for_bitmap (xcb_connection_t *connection, - xcb_screen_t *screen, - xcb_pixmap_t bitmap, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_xcb_surface_create_with_xrender_format (xcb_connection_t *connection, - xcb_screen_t *screen, - xcb_drawable_t drawable, - xcb_render_pictforminfo_t *format, - int width, - int height); - -cairo_public void -cairo_xcb_surface_set_size (cairo_surface_t *surface, - int width, - int height); - -cairo_public void -cairo_xcb_surface_set_drawable (cairo_surface_t *surface, - xcb_drawable_t drawable, - int width, - int height); - -cairo_public xcb_connection_t * -cairo_xcb_device_get_connection (cairo_device_t *device); - -/* debug interface */ - -cairo_public void -cairo_xcb_device_debug_cap_xshm_version (cairo_device_t *device, - int major_version, - int minor_version); - -cairo_public void -cairo_xcb_device_debug_cap_xrender_version (cairo_device_t *device, - int major_version, - int minor_version); - -/* - * @precision: -1 implies automatically choose based on antialiasing mode, - * any other value overrides and sets the corresponding PolyMode. - */ -cairo_public void -cairo_xcb_device_debug_set_precision (cairo_device_t *device, - int precision); - -cairo_public int -cairo_xcb_device_debug_get_precision (cairo_device_t *device); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_XCB_SURFACE */ -# error Cairo was not compiled with support for the xcb backend -#endif /* CAIRO_HAS_XCB_SURFACE */ - -#endif /* CAIRO_XCB_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-core-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-core-compositor.c deleted file mode 100644 index 5babcc81bed..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-core-compositor.c +++ /dev/null @@ -1,650 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Behdad Esfahbod - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ - -/* The original X drawing API was very restrictive in what it could handle, - * pixel-aligned fill/blits are all that map into Cairo's drawing model. - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" -#include "cairo-xlib-surface-private.h" - -#include "cairo-boxes-private.h" -#include "cairo-clip-inline.h" -#include "cairo-compositor-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-pattern-private.h" -#include "cairo-region-private.h" -#include "cairo-surface-offset-private.h" - -/* the low-level interface */ - -static cairo_int_status_t -acquire (void *abstract_dst) -{ - cairo_xlib_surface_t *dst = abstract_dst; - return _cairo_xlib_display_acquire (dst->base.device, &dst->display); -} - -static cairo_int_status_t -release (void *abstract_dst) -{ - cairo_xlib_surface_t *dst = abstract_dst; - - cairo_device_release (&dst->display->base); - dst->display = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -struct _fill_box { - Display *dpy; - Drawable drawable; - GC gc; - //cairo_surface_t *dither = NULL; -}; - -static cairo_bool_t fill_box (cairo_box_t *box, void *closure) -{ - struct _fill_box *data = closure; - int x = _cairo_fixed_integer_part (box->p1.x); - int y = _cairo_fixed_integer_part (box->p1.y); - int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); - int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); - - XFillRectangle (data->dpy, data->drawable, data->gc, x, y, width, height); - return TRUE; -} - -static void -_characterize_field (uint32_t mask, int *width, int *shift) -{ - *width = _cairo_popcount (mask); - /* The final '& 31' is to force a 0 mask to result in 0 shift. */ - *shift = _cairo_popcount ((mask - 1) & ~mask) & 31; -} - -static uint32_t -color_to_pixel (cairo_xlib_surface_t *dst, - const cairo_color_t *color) -{ - uint32_t rgba = 0; - int width, shift; - - _characterize_field (dst->a_mask, &width, &shift); - rgba |= color->alpha_short >> (16 - width) << shift; - - _characterize_field (dst->r_mask, &width, &shift); - rgba |= color->red_short >> (16 - width) << shift; - - _characterize_field (dst->g_mask, &width, &shift); - rgba |= color->green_short >> (16 - width) << shift; - - _characterize_field (dst->b_mask, &width, &shift); - rgba |= color->blue_short >> (16 - width) << shift; - - return rgba; -} - -static cairo_int_status_t -_fill_box_init (struct _fill_box *fb, - cairo_xlib_surface_t *dst, - const cairo_color_t *color) -{ - cairo_int_status_t status; - - status = _cairo_xlib_surface_get_gc (dst->display, dst, &fb->gc); - if (unlikely (status)) - return status; - - fb->dpy = dst->display->display; - fb->drawable = dst->drawable; - - if (dst->visual && dst->visual->class != TrueColor && 0) { -#if 0 - cairo_solid_pattern_t solid; - cairo_surface_attributes_t attrs; - - _cairo_pattern_init_solid (&solid, color); - status = _cairo_pattern_acquire_surface (&solid.base, &dst->base, - 0, 0, - ARRAY_LENGTH (dither_pattern[0]), - ARRAY_LENGTH (dither_pattern), - CAIRO_PATTERN_ACQUIRE_NONE, - &dither, - &attrs); - if (unlikely (status)) { - _cairo_xlib_surface_put_gc (dst->display, dst, fb.gc); - return status; - } - - XSetTSOrigin (fb->dpy, fb->gc, - - (dst->base.device_transform.x0 + attrs.x_offset), - - (dst->base.device_transform.y0 + attrs.y_offset)); - XSetTile (fb->dpy, fb->gc, ((cairo_xlib_surface_t *) dither)->drawable); -#endif - } else { - XGCValues gcv; - - gcv.foreground = color_to_pixel (dst, color); - gcv.fill_style = FillSolid; - - XChangeGC (fb->dpy, fb->gc, GCFillStyle | GCForeground, &gcv); - } - - return CAIRO_INT_STATUS_SUCCESS; -} - -static void -_fill_box_fini (struct _fill_box *fb, - cairo_xlib_surface_t *dst) -{ - _cairo_xlib_surface_put_gc (dst->display, dst, fb->gc); - //cairo_surface_destroy (fb->dither); -} - -cairo_int_status_t -_cairo_xlib_core_fill_boxes (cairo_xlib_surface_t *dst, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - cairo_int_status_t status; - struct _fill_box fb; - - status = _fill_box_init (&fb, dst, color); - if (unlikely (status)) - return status; - - _cairo_boxes_for_each_box (boxes, fill_box, &fb); - - _fill_box_fini (&fb, dst); - return CAIRO_STATUS_SUCCESS; -} - -cairo_int_status_t -_cairo_xlib_core_fill_rectangles (cairo_xlib_surface_t *dst, - const cairo_color_t *color, - int num_rects, - cairo_rectangle_int_t *rects) -{ - cairo_int_status_t status; - struct _fill_box fb; - int i; - - status = _fill_box_init (&fb, dst, color); - if (unlikely (status)) - return status; - - for (i = 0; i < num_rects; i++) - XFillRectangle (fb.dpy, fb.drawable, fb.gc, - rects[i].x, rects[i].y, - rects[i].width, rects[i].height); - - _fill_box_fini (&fb, dst); - return CAIRO_STATUS_SUCCESS; -} - -struct _fallback_box { - cairo_xlib_surface_t *dst; - cairo_format_t format; - const cairo_pattern_t *pattern; -}; - -static cairo_bool_t fallback_box (cairo_box_t *box, void *closure) -{ - struct _fallback_box *data = closure; - int x = _cairo_fixed_integer_part (box->p1.x); - int y = _cairo_fixed_integer_part (box->p1.y); - int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); - int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); - cairo_surface_t *image; - cairo_status_t status; - - /* XXX for EXTEND_NONE and if the box is wholly outside we can just fill */ - - image = cairo_surface_create_similar_image (&data->dst->base, data->format, - width, height); - status = _cairo_surface_offset_paint (image, x, y, - CAIRO_OPERATOR_SOURCE, - data->pattern, NULL); - if (status == CAIRO_STATUS_SUCCESS) { - status = _cairo_xlib_surface_draw_image (data->dst, - (cairo_image_surface_t *)image, - 0, 0, - width, height, - x, y); - } - cairo_surface_destroy (image); - - return status == CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -fallback_boxes (cairo_xlib_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_boxes_t *boxes) -{ - struct _fallback_box fb; - - /* XXX create_similar_image using pixman_format? */ - switch (dst->depth) { - case 8: fb.format = CAIRO_FORMAT_A8; break; - case 16: fb.format = CAIRO_FORMAT_RGB16_565; break; - case 24: fb.format = CAIRO_FORMAT_RGB24; break; - case 30: fb.format = CAIRO_FORMAT_RGB30; break; - case 32: fb.format = CAIRO_FORMAT_ARGB32; break; - default: return CAIRO_INT_STATUS_UNSUPPORTED; - } - - fb.dst = dst; - fb.pattern = pattern; - - if (! _cairo_boxes_for_each_box (boxes, fallback_box, &fb)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -render_boxes (cairo_xlib_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_boxes_t *boxes) -{ - if (pattern->filter != CAIRO_FILTER_NEAREST) - return fallback_boxes (dst, pattern, boxes); - - switch (pattern->extend) { - default: - case CAIRO_EXTEND_NONE: - case CAIRO_EXTEND_REFLECT: - case CAIRO_EXTEND_PAD: - return fallback_boxes (dst, pattern, boxes); - - case CAIRO_EXTEND_REPEAT: /* XXX Use tiling */ - return fallback_boxes (dst, pattern, boxes); - } -} - -/* the mid-level: converts boxes into drawing operations */ - -struct _box_data { - Display *dpy; - cairo_xlib_surface_t *dst; - cairo_surface_t *src; - GC gc; - int tx, ty; - int width, height; -}; - -static cairo_bool_t source_contains_box (cairo_box_t *box, void *closure) -{ - struct _box_data *data = closure; - - /* The box is pixel-aligned so the truncation is safe. */ - return - _cairo_fixed_integer_part (box->p1.x) + data->tx >= 0 && - _cairo_fixed_integer_part (box->p1.y) + data->ty >= 0 && - _cairo_fixed_integer_part (box->p2.x) + data->tx <= data->width && - _cairo_fixed_integer_part (box->p2.y) + data->ty <= data->height; -} - -static cairo_bool_t image_upload_box (cairo_box_t *box, void *closure) -{ - const struct _box_data *iub = closure; - int x = _cairo_fixed_integer_part (box->p1.x); - int y = _cairo_fixed_integer_part (box->p1.y); - int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); - int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); - - return _cairo_xlib_surface_draw_image (iub->dst, - (cairo_image_surface_t *)iub->src, - x + iub->tx, y + iub->ty, - width, height, - x, y) == CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -surface_matches_image_format (cairo_xlib_surface_t *surface, - cairo_image_surface_t *image) -{ - cairo_format_masks_t format; - - return (_pixman_format_to_masks (image->pixman_format, &format) && - (format.alpha_mask == surface->a_mask || surface->a_mask == 0) && - (format.red_mask == surface->r_mask || surface->r_mask == 0) && - (format.green_mask == surface->g_mask || surface->g_mask == 0) && - (format.blue_mask == surface->b_mask || surface->b_mask == 0)); -} - -static cairo_status_t -upload_image_inplace (cairo_xlib_surface_t *dst, - const cairo_pattern_t *source, - cairo_boxes_t *boxes) -{ - const cairo_surface_pattern_t *pattern; - struct _box_data iub; - cairo_image_surface_t *image; - - if (source->type != CAIRO_PATTERN_TYPE_SURFACE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - pattern = (const cairo_surface_pattern_t *) source; - if (pattern->surface->type != CAIRO_SURFACE_TYPE_IMAGE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - image = (cairo_image_surface_t *) pattern->surface; - if (image->format == CAIRO_FORMAT_INVALID) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (image->depth != dst->depth) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! surface_matches_image_format (dst, image)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* XXX subsurface */ - - if (! _cairo_matrix_is_integer_translation (&source->matrix, - &iub.tx, &iub.ty)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - iub.dst = dst; - iub.src = &image->base; - iub.width = image->width; - iub.height = image->height; - - /* First check that the data is entirely within the image */ - if (! _cairo_boxes_for_each_box (boxes, source_contains_box, &iub)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_boxes_for_each_box (boxes, image_upload_box, &iub)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t copy_box (cairo_box_t *box, void *closure) -{ - const struct _box_data *cb = closure; - int x = _cairo_fixed_integer_part (box->p1.x); - int y = _cairo_fixed_integer_part (box->p1.y); - int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); - int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); - - XCopyArea (cb->dpy, - ((cairo_xlib_surface_t *)cb->src)->drawable, - cb->dst->drawable, - cb->gc, - x + cb->tx, y + cb->ty, - width, height, - x, y); - return TRUE; -} - -static cairo_status_t -copy_boxes (cairo_xlib_surface_t *dst, - const cairo_pattern_t *source, - cairo_boxes_t *boxes) -{ - const cairo_surface_pattern_t *pattern; - struct _box_data cb; - cairo_xlib_surface_t *src; - cairo_status_t status; - - if (source->type != CAIRO_PATTERN_TYPE_SURFACE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* XXX subsurface */ - - pattern = (const cairo_surface_pattern_t *) source; - if (pattern->surface->backend->type != CAIRO_SURFACE_TYPE_XLIB) - return CAIRO_INT_STATUS_UNSUPPORTED; - - src = (cairo_xlib_surface_t *) pattern->surface; - if (src->depth != dst->depth) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* We can only have a single control for subwindow_mode on the - * GC. If we have a Window destination, we need to set ClipByChildren, - * but if we have a Window source, we need IncludeInferiors. If we have - * both a Window destination and source, we must fallback. There is - * no convenient way to detect if a drawable is a Pixmap or Window, - * therefore we can only rely on those surfaces that we created - * ourselves to be Pixmaps, and treat everything else as a potential - * Window. - */ - if (! src->owns_pixmap && ! dst->owns_pixmap) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_xlib_surface_same_screen (dst, src)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (! _cairo_matrix_is_integer_translation (&source->matrix, - &cb.tx, &cb.ty)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - cb.dpy = dst->display->display; - cb.dst = dst; - cb.src = &src->base; - cb.width = src->width; - cb.height = src->height; - - /* First check that the data is entirely within the image */ - if (! _cairo_boxes_for_each_box (boxes, source_contains_box, &cb)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_xlib_surface_get_gc (dst->display, dst, &cb.gc); - if (unlikely (status)) - return status; - - if (! src->owns_pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = IncludeInferiors; - XChangeGC (dst->display->display, cb.gc, GCSubwindowMode, &gcv); - } - - status = CAIRO_STATUS_SUCCESS; - if (! _cairo_boxes_for_each_box (boxes, copy_box, &cb)) - status = CAIRO_INT_STATUS_UNSUPPORTED; - - if (! src->owns_pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = ClipByChildren; - XChangeGC (dst->display->display, cb.gc, GCSubwindowMode, &gcv); - } - - _cairo_xlib_surface_put_gc (dst->display, dst, cb.gc); - - return status; -} - -static cairo_status_t -draw_boxes (cairo_composite_rectangles_t *extents, - cairo_boxes_t *boxes) -{ - cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)extents->surface; - cairo_operator_t op = extents->op; - const cairo_pattern_t *src = &extents->source_pattern.base; - cairo_int_status_t status; - - if (boxes->num_boxes == 0 && extents->is_bounded) - return CAIRO_STATUS_SUCCESS; - - if (! boxes->is_pixel_aligned) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (op == CAIRO_OPERATOR_CLEAR) - op = CAIRO_OPERATOR_SOURCE; - - if (op == CAIRO_OPERATOR_OVER && - _cairo_pattern_is_opaque (src, &extents->bounded)) - op = CAIRO_OPERATOR_SOURCE; - - if (dst->base.is_clear && op == CAIRO_OPERATOR_OVER) - op = CAIRO_OPERATOR_SOURCE; - - if (op != CAIRO_OPERATOR_SOURCE) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = acquire (dst); - if (unlikely (status)) - return status; - - if (src->type == CAIRO_PATTERN_TYPE_SOLID) { - status = _cairo_xlib_core_fill_boxes - (dst, &((cairo_solid_pattern_t *) src)->color, boxes); - } else { - status = upload_image_inplace (dst, src, boxes); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - status = copy_boxes (dst, src, boxes); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) - status = render_boxes (dst, src, boxes); - } - - release (dst); - - return status; -} - -/* high-level compositor interface */ - -static cairo_int_status_t -_cairo_xlib_core_compositor_paint (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_int_status_t status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (_cairo_clip_is_region (extents->clip)) { - cairo_boxes_t boxes; - - _cairo_clip_steal_boxes (extents->clip, &boxes); - status = draw_boxes (extents, &boxes); - _cairo_clip_unsteal_boxes (extents->clip, &boxes); - } - - return status; -} - -static cairo_int_status_t -_cairo_xlib_core_compositor_stroke (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_int_status_t status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (extents->clip->path == NULL && - _cairo_path_fixed_stroke_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, extents->clip); - status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, - style, - ctm, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = draw_boxes (extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - return status; -} - -static cairo_int_status_t -_cairo_xlib_core_compositor_fill (const cairo_compositor_t *compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_int_status_t status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (extents->clip->path == NULL && - _cairo_path_fixed_fill_is_rectilinear (path)) { - cairo_boxes_t boxes; - - _cairo_boxes_init_with_clip (&boxes, extents->clip); - status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, - fill_rule, - antialias, - &boxes); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = draw_boxes (extents, &boxes); - _cairo_boxes_fini (&boxes); - } - - return status; -} - -const cairo_compositor_t * -_cairo_xlib_core_compositor_get (void) -{ - static cairo_compositor_t compositor; - - if (compositor.delegate == NULL) { - compositor.delegate = _cairo_xlib_fallback_compositor_get (); - - compositor.paint = _cairo_xlib_core_compositor_paint; - compositor.mask = NULL; - compositor.fill = _cairo_xlib_core_compositor_fill; - compositor.stroke = _cairo_xlib_core_compositor_stroke; - compositor.glyphs = NULL; /* XXX PolyGlyph? */ - } - - return &compositor; -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-display.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-display.c deleted file mode 100644 index a2a3bc7924b..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-display.c +++ /dev/null @@ -1,655 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Karl Tomlinson , Mozilla Corporation - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" -#include "cairo-xlib-xrender-private.h" -#include "cairo-freelist-private.h" -#include "cairo-error-private.h" -#include "cairo-list-inline.h" - -#include /* For XESetCloseDisplay */ - -typedef int (*cairo_xlib_error_func_t) (Display *display, - XErrorEvent *event); - -static cairo_xlib_display_t *_cairo_xlib_display_list; - -static int -_noop_error_handler (Display *display, - XErrorEvent *event) -{ - return False; /* return value is ignored */ -} - -static void -_cairo_xlib_display_finish (void *abstract_display) -{ - cairo_xlib_display_t *display = abstract_display; - Display *dpy = display->display; - - _cairo_xlib_display_fini_shm (display); - - if (! cairo_device_acquire (&display->base)) { - cairo_xlib_error_func_t old_handler; - - /* protect the notifies from triggering XErrors */ - XSync (dpy, False); - old_handler = XSetErrorHandler (_noop_error_handler); - - while (! cairo_list_is_empty (&display->fonts)) { - _cairo_xlib_font_close (cairo_list_first_entry (&display->fonts, - cairo_xlib_font_t, - link)); - } - - while (! cairo_list_is_empty (&display->screens)) { - _cairo_xlib_screen_destroy (display, - cairo_list_first_entry (&display->screens, - cairo_xlib_screen_t, - link)); - } - - XSync (dpy, False); - XSetErrorHandler (old_handler); - - cairo_device_release (&display->base); - } -} - -static void -_cairo_xlib_display_destroy (void *abstract_display) -{ - cairo_xlib_display_t *display = abstract_display; - - free (display); -} - -static int -_cairo_xlib_close_display (Display *dpy, XExtCodes *codes) -{ - cairo_xlib_display_t *display, **prev, *next; - - CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); - for (display = _cairo_xlib_display_list; display; display = display->next) - if (display->display == dpy) - break; - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - if (display == NULL) - return 0; - - cairo_device_finish (&display->base); - - /* - * Unhook from the global list - */ - CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); - prev = &_cairo_xlib_display_list; - for (display = _cairo_xlib_display_list; display; display = next) { - next = display->next; - if (display->display == dpy) { - *prev = next; - break; - } else - prev = &display->next; - } - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - - display->display = NULL; /* catch any later invalid access */ - cairo_device_destroy (&display->base); - - /* Return value in accordance with requirements of - * XESetCloseDisplay */ - return 0; -} - -static const cairo_device_backend_t _cairo_xlib_device_backend = { - CAIRO_DEVICE_TYPE_XLIB, - - NULL, - NULL, - - NULL, /* flush */ - _cairo_xlib_display_finish, - _cairo_xlib_display_destroy, -}; - -static void _cairo_xlib_display_select_compositor (cairo_xlib_display_t *display) -{ -#if 1 - if (display->render_major > 0 || display->render_minor >= 4) - display->compositor = _cairo_xlib_traps_compositor_get (); - else if (display->render_major > 0 || display->render_minor >= 0) - display->compositor = _cairo_xlib_mask_compositor_get (); - else - display->compositor = _cairo_xlib_core_compositor_get (); -#else - display->compositor = _cairo_xlib_fallback_compositor_get (); -#endif -} - -/** - * _cairo_xlib_device_create: - * @dpy: the display to create the device for - * - * Gets the device belonging to @dpy, or creates it if it doesn't exist yet. - * - * Returns: the device belonging to @dpy - **/ -cairo_device_t * -_cairo_xlib_device_create (Display *dpy) -{ - cairo_xlib_display_t *display; - cairo_xlib_display_t **prev; - cairo_device_t *device; - XExtCodes *codes; - const char *env; - - CAIRO_MUTEX_INITIALIZE (); - - /* There is an apparent deadlock between this mutex and the - * mutex for the display, but it's actually safe. For the - * app to call XCloseDisplay() while any other thread is - * inside this function would be an error in the logic - * app, and the CloseDisplay hook is the only other place we - * acquire this mutex. - */ - CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); - - for (prev = &_cairo_xlib_display_list; (display = *prev); prev = &(*prev)->next) - { - if (display->display == dpy) { - /* - * MRU the list - */ - if (prev != &_cairo_xlib_display_list) { - *prev = display->next; - display->next = _cairo_xlib_display_list; - _cairo_xlib_display_list = display; - } - device = cairo_device_reference (&display->base); - goto UNLOCK; - } - } - - display = malloc (sizeof (cairo_xlib_display_t)); - if (unlikely (display == NULL)) { - device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); - goto UNLOCK; - } - - _cairo_device_init (&display->base, &_cairo_xlib_device_backend); - - display->display = dpy; - cairo_list_init (&display->screens); - cairo_list_init (&display->fonts); - display->closed = FALSE; - - /* Xlib calls out to the extension close_display hooks in LIFO - * order. So we have to ensure that all extensions that we depend - * on in our close_display hook are properly initialized before we - * add our hook. For now, that means Render, so we call into its - * QueryVersion function to ensure it gets initialized. - */ - display->render_major = display->render_minor = -1; - XRenderQueryVersion (dpy, &display->render_major, &display->render_minor); - env = getenv ("CAIRO_DEBUG"); - if (env != NULL && (env = strstr (env, "xrender-version=")) != NULL) { - int max_render_major, max_render_minor; - - env += sizeof ("xrender-version=") - 1; - if (sscanf (env, "%d.%d", &max_render_major, &max_render_minor) != 2) - max_render_major = max_render_minor = -1; - - if (max_render_major < display->render_major || - (max_render_major == display->render_major && - max_render_minor < display->render_minor)) - { - display->render_major = max_render_major; - display->render_minor = max_render_minor; - } - } - - _cairo_xlib_display_select_compositor (display); - - display->white = NULL; - memset (display->alpha, 0, sizeof (display->alpha)); - memset (display->solid, 0, sizeof (display->solid)); - memset (display->solid_cache, 0, sizeof (display->solid_cache)); - memset (display->last_solid_cache, 0, sizeof (display->last_solid_cache)); - - memset (display->cached_xrender_formats, 0, - sizeof (display->cached_xrender_formats)); - - display->force_precision = -1; - - _cairo_xlib_display_init_shm (display); - - /* Prior to Render 0.10, there is no protocol support for gradients and - * we call function stubs instead, which would silently consume the drawing. - */ -#if RENDER_MAJOR == 0 && RENDER_MINOR < 10 - display->buggy_gradients = TRUE; -#else - display->buggy_gradients = FALSE; -#endif - display->buggy_pad_reflect = FALSE; - display->buggy_repeat = FALSE; - - /* This buggy_repeat condition is very complicated because there - * are multiple X server code bases (with multiple versioning - * schemes within a code base), and multiple bugs. - * - * The X servers: - * - * 1. The Vendor=="XFree86" code base with release numbers such - * as 4.7.0 (VendorRelease==40700000). - * - * 2. The Vendor=="X.Org" code base (a descendant of the - * XFree86 code base). It originally had things like - * VendorRelease==60700000 for release 6.7.0 but then changed - * its versioning scheme so that, for example, - * VendorRelease==10400000 for the 1.4.0 X server within the - * X.Org 7.3 release. - * - * The bugs: - * - * 1. The original bug that led to the buggy_repeat - * workaround. This was a bug that Owen Taylor investigated, - * understood well, and characterized against various X - * servers. Confirmed X servers with this bug include: - * - * "XFree86" <= 40500000 - * "X.Org" <= 60802000 (only with old numbering >= 60700000) - * - * 2. A separate bug resulting in a crash of the X server when - * using cairo's extend-reflect test case, (which, surprisingly - * enough was not passing RepeatReflect to the X server, but - * instead using RepeatNormal in a workaround). Nobody to date - * has understood the bug well, but it appears to be gone as of - * the X.Org 1.4.0 server. This bug is coincidentally avoided - * by using the same buggy_repeat workaround. Confirmed X - * servers with this bug include: - * - * "X.org" == 60900000 (old versioning scheme) - * "X.org" < 10400000 (new numbering scheme) - * - * For the old-versioning-scheme X servers we don't know - * exactly when second the bug started, but since bug 1 is - * present through 6.8.2 and bug 2 is present in 6.9.0 it seems - * safest to just blacklist all old-versioning-scheme X servers, - * (just using VendorRelease < 70000000), as buggy_repeat=TRUE. - */ - if (_cairo_xlib_vendor_is_xorg (dpy)) { - if (VendorRelease (dpy) >= 60700000) { - if (VendorRelease (dpy) < 70000000) - display->buggy_repeat = TRUE; - - /* We know that gradients simply do not work in early Xorg servers */ - if (VendorRelease (dpy) < 70200000) - display->buggy_gradients = TRUE; - - /* And the extended repeat modes were not fixed until much later */ - display->buggy_pad_reflect = TRUE; - } else { - if (VendorRelease (dpy) < 10400000) - display->buggy_repeat = TRUE; - - /* Too many bugs in the early drivers */ - if (VendorRelease (dpy) < 10699000) - display->buggy_pad_reflect = TRUE; - } - } else if (strstr (ServerVendor (dpy), "XFree86") != NULL) { - if (VendorRelease (dpy) <= 40500000) - display->buggy_repeat = TRUE; - - display->buggy_gradients = TRUE; - display->buggy_pad_reflect = TRUE; - } - - codes = XAddExtension (dpy); - if (unlikely (codes == NULL)) { - device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); - free (display); - goto UNLOCK; - } - - XESetCloseDisplay (dpy, codes->extension, _cairo_xlib_close_display); - cairo_device_reference (&display->base); /* add one for the CloseDisplay */ - - display->next = _cairo_xlib_display_list; - _cairo_xlib_display_list = display; - - device = &display->base; - -UNLOCK: - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - return device; -} - -cairo_status_t -_cairo_xlib_display_acquire (cairo_device_t *device, cairo_xlib_display_t **display) -{ - cairo_status_t status; - - status = cairo_device_acquire (device); - if (status) - return status; - - *display = (cairo_xlib_display_t *) device; - return CAIRO_STATUS_SUCCESS; -} - -XRenderPictFormat * -_cairo_xlib_display_get_xrender_format_for_pixman(cairo_xlib_display_t *display, - pixman_format_code_t format) -{ - Display *dpy = display->display; - XRenderPictFormat tmpl; - int mask; - -#define MASK(x) ((1<<(x))-1) - - tmpl.depth = PIXMAN_FORMAT_DEPTH(format); - mask = PictFormatType | PictFormatDepth; - - switch (PIXMAN_FORMAT_TYPE(format)) { - case PIXMAN_TYPE_ARGB: - tmpl.type = PictTypeDirect; - - tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); - if (PIXMAN_FORMAT_A(format)) - tmpl.direct.alpha = (PIXMAN_FORMAT_R(format) + - PIXMAN_FORMAT_G(format) + - PIXMAN_FORMAT_B(format)); - - tmpl.direct.redMask = MASK(PIXMAN_FORMAT_R(format)); - tmpl.direct.red = (PIXMAN_FORMAT_G(format) + - PIXMAN_FORMAT_B(format)); - - tmpl.direct.greenMask = MASK(PIXMAN_FORMAT_G(format)); - tmpl.direct.green = PIXMAN_FORMAT_B(format); - - tmpl.direct.blueMask = MASK(PIXMAN_FORMAT_B(format)); - tmpl.direct.blue = 0; - - mask |= PictFormatRed | PictFormatRedMask; - mask |= PictFormatGreen | PictFormatGreenMask; - mask |= PictFormatBlue | PictFormatBlueMask; - mask |= PictFormatAlpha | PictFormatAlphaMask; - break; - - case PIXMAN_TYPE_ABGR: - tmpl.type = PictTypeDirect; - - tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); - if (tmpl.direct.alphaMask) - tmpl.direct.alpha = (PIXMAN_FORMAT_B(format) + - PIXMAN_FORMAT_G(format) + - PIXMAN_FORMAT_R(format)); - - tmpl.direct.blueMask = MASK(PIXMAN_FORMAT_B(format)); - tmpl.direct.blue = (PIXMAN_FORMAT_G(format) + - PIXMAN_FORMAT_R(format)); - - tmpl.direct.greenMask = MASK(PIXMAN_FORMAT_G(format)); - tmpl.direct.green = PIXMAN_FORMAT_R(format); - - tmpl.direct.redMask = MASK(PIXMAN_FORMAT_R(format)); - tmpl.direct.red = 0; - - mask |= PictFormatRed | PictFormatRedMask; - mask |= PictFormatGreen | PictFormatGreenMask; - mask |= PictFormatBlue | PictFormatBlueMask; - mask |= PictFormatAlpha | PictFormatAlphaMask; - break; - - case PIXMAN_TYPE_BGRA: - tmpl.type = PictTypeDirect; - - tmpl.direct.blueMask = MASK(PIXMAN_FORMAT_B(format)); - tmpl.direct.blue = (PIXMAN_FORMAT_BPP(format) - PIXMAN_FORMAT_B(format)); - - tmpl.direct.greenMask = MASK(PIXMAN_FORMAT_G(format)); - tmpl.direct.green = (PIXMAN_FORMAT_BPP(format) - PIXMAN_FORMAT_B(format) - - PIXMAN_FORMAT_G(format)); - - tmpl.direct.redMask = MASK(PIXMAN_FORMAT_R(format)); - tmpl.direct.red = (PIXMAN_FORMAT_BPP(format) - PIXMAN_FORMAT_B(format) - - PIXMAN_FORMAT_G(format) - PIXMAN_FORMAT_R(format)); - - tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); - tmpl.direct.alpha = 0; - - mask |= PictFormatRed | PictFormatRedMask; - mask |= PictFormatGreen | PictFormatGreenMask; - mask |= PictFormatBlue | PictFormatBlueMask; - mask |= PictFormatAlpha | PictFormatAlphaMask; - break; - - case PIXMAN_TYPE_A: - tmpl.type = PictTypeDirect; - - tmpl.direct.alpha = 0; - tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); - - mask |= PictFormatAlpha | PictFormatAlphaMask; - break; - - case PIXMAN_TYPE_COLOR: - case PIXMAN_TYPE_GRAY: - /* XXX Find matching visual/colormap */ - tmpl.type = PictTypeIndexed; - //tmpl.colormap = screen->visuals[PIXMAN_FORMAT_VIS(format)].vid; - //mask |= PictFormatColormap; - return NULL; - } -#undef MASK - - /* XXX caching? */ - return XRenderFindFormat(dpy, mask, &tmpl, 0); -} - -XRenderPictFormat * -_cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display, - cairo_format_t format) -{ - XRenderPictFormat *xrender_format; - - xrender_format = display->cached_xrender_formats[format]; - if (xrender_format == NULL) { - int pict_format = PictStandardNUM; - - switch (format) { - case CAIRO_FORMAT_A1: - pict_format = PictStandardA1; break; - case CAIRO_FORMAT_A8: - pict_format = PictStandardA8; break; - case CAIRO_FORMAT_RGB24: - pict_format = PictStandardRGB24; break; - case CAIRO_FORMAT_RGB16_565: - xrender_format = _cairo_xlib_display_get_xrender_format_for_pixman(display, - PIXMAN_r5g6b5); - break; - case CAIRO_FORMAT_RGB30: - xrender_format = _cairo_xlib_display_get_xrender_format_for_pixman(display, - PIXMAN_x2r10g10b10); - break; - case CAIRO_FORMAT_INVALID: - default: - ASSERT_NOT_REACHED; - case CAIRO_FORMAT_ARGB32: - pict_format = PictStandardARGB32; break; - } - if (pict_format != PictStandardNUM) - xrender_format = - XRenderFindStandardFormat (display->display, pict_format); - display->cached_xrender_formats[format] = xrender_format; - } - - return xrender_format; -} - -cairo_xlib_screen_t * -_cairo_xlib_display_get_screen (cairo_xlib_display_t *display, - Screen *screen) -{ - cairo_xlib_screen_t *info; - - cairo_list_foreach_entry (info, cairo_xlib_screen_t, &display->screens, link) { - if (info->screen == screen) { - if (display->screens.next != &info->link) - cairo_list_move (&info->link, &display->screens); - return info; - } - } - - return NULL; -} - -cairo_bool_t -_cairo_xlib_display_has_repeat (cairo_device_t *device) -{ - return ! ((cairo_xlib_display_t *) device)->buggy_repeat; -} - -cairo_bool_t -_cairo_xlib_display_has_reflect (cairo_device_t *device) -{ - return ! ((cairo_xlib_display_t *) device)->buggy_pad_reflect; -} - -cairo_bool_t -_cairo_xlib_display_has_gradients (cairo_device_t *device) -{ - return ! ((cairo_xlib_display_t *) device)->buggy_gradients; -} - -/** - * cairo_xlib_device_debug_cap_xrender_version: - * @device: a #cairo_device_t for the Xlib backend - * @major_version: major version to restrict to - * @minor_version: minor version to restrict to - * - * Restricts all future Xlib surfaces for this devices to the specified version - * of the RENDER extension. This function exists solely for debugging purpose. - * It lets you find out how cairo would behave with an older version of - * the RENDER extension. - * - * Use the special values -1 and -1 for disabling the RENDER extension. - * - * Since: 1.12 - **/ -void -cairo_xlib_device_debug_cap_xrender_version (cairo_device_t *device, - int major_version, - int minor_version) -{ - cairo_xlib_display_t *display = (cairo_xlib_display_t *) device; - - if (device == NULL || device->status) - return; - - if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) - return; - - if (major_version < display->render_major || - (major_version == display->render_major && - minor_version < display->render_minor)) - { - display->render_major = major_version; - display->render_minor = minor_version; - } - - _cairo_xlib_display_select_compositor (display); -} - -/** - * cairo_xlib_device_debug_set_precision: - * @device: a #cairo_device_t for the Xlib backend - * @precision: the precision to use - * - * Render supports two modes of precision when rendering trapezoids. Set - * the precision to the desired mode. - * - * Since: 1.12 - **/ -void -cairo_xlib_device_debug_set_precision (cairo_device_t *device, - int precision) -{ - if (device == NULL || device->status) - return; - if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return; - } - - ((cairo_xlib_display_t *) device)->force_precision = precision; -} - -/** - * cairo_xlib_device_debug_get_precision: - * @device: a #cairo_device_t for the Xlib backend - * - * Get the Xrender precision mode. - * - * Returns: the render precision mode - * - * Since: 1.12 - **/ -int -cairo_xlib_device_debug_get_precision (cairo_device_t *device) -{ - if (device == NULL || device->status) - return -1; - if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return -1; - } - - return ((cairo_xlib_display_t *) device)->force_precision; -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-fallback-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-fallback-compositor.c deleted file mode 100644 index ed2845db57d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-fallback-compositor.c +++ /dev/null @@ -1,248 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Behdad Esfahbod - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-offset-private.h" - -static const cairo_compositor_t * -_get_compositor (cairo_surface_t *surface) -{ - return ((cairo_image_surface_t *)surface)->compositor; -} - -static cairo_bool_t -unclipped (cairo_xlib_surface_t *xlib, cairo_clip_t *clip) -{ - cairo_rectangle_int_t r; - - r.x = r.y = 0; - r.width = xlib->width; - r.height = xlib->height; - return _cairo_clip_contains_rectangle (clip, &r); -} - -static cairo_int_status_t -_cairo_xlib_shm_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; - cairo_int_status_t status; - cairo_surface_t *shm; - cairo_bool_t overwrite; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - overwrite = - extents->op <= CAIRO_OPERATOR_SOURCE && unclipped (xlib, extents->clip); - - shm = _cairo_xlib_surface_get_shm (xlib, overwrite); - if (shm == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_paint (_get_compositor (shm), shm, - extents->op, - &extents->source_pattern.base, - extents->clip); - if (unlikely (status)) - return status; - - xlib->base.is_clear = - extents->op == CAIRO_OPERATOR_CLEAR && unclipped (xlib, extents->clip); - xlib->base.serial++; - xlib->fallback++; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_xlib_shm_compositor_mask (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; - cairo_int_status_t status; - cairo_surface_t *shm; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - shm = _cairo_xlib_surface_get_shm (xlib, FALSE); - if (shm == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_mask (_get_compositor (shm), shm, - extents->op, - &extents->source_pattern.base, - &extents->mask_pattern.base, - extents->clip); - if (unlikely (status)) - return status; - - xlib->base.is_clear = FALSE; - xlib->base.serial++; - xlib->fallback++; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_xlib_shm_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; - cairo_int_status_t status; - cairo_surface_t *shm; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - shm = _cairo_xlib_surface_get_shm (xlib, FALSE); - if (shm == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_stroke (_get_compositor (shm), shm, - extents->op, - &extents->source_pattern.base, - path, style, - ctm, ctm_inverse, - tolerance, - antialias, - extents->clip); - if (unlikely (status)) - return status; - - xlib->base.is_clear = FALSE; - xlib->base.serial++; - xlib->fallback++; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_xlib_shm_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; - cairo_int_status_t status; - cairo_surface_t *shm; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - shm = _cairo_xlib_surface_get_shm (xlib, FALSE); - if (shm == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_fill (_get_compositor (shm), shm, - extents->op, - &extents->source_pattern.base, - path, - fill_rule, tolerance, antialias, - extents->clip); - if (unlikely (status)) - return status; - - xlib->base.is_clear = FALSE; - xlib->base.serial++; - xlib->fallback++; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static cairo_int_status_t -_cairo_xlib_shm_compositor_glyphs (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; - cairo_int_status_t status; - cairo_surface_t *shm; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - shm = _cairo_xlib_surface_get_shm (xlib, FALSE); - if (shm == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = _cairo_compositor_glyphs (_get_compositor (shm), shm, - extents->op, - &extents->source_pattern.base, - glyphs, num_glyphs, scaled_font, - extents->clip); - if (unlikely (status)) - return status; - - xlib->base.is_clear = FALSE; - xlib->base.serial++; - xlib->fallback++; - return CAIRO_INT_STATUS_NOTHING_TO_DO; -} - -static const cairo_compositor_t _cairo_xlib_shm_compositor = { - &_cairo_fallback_compositor, - - _cairo_xlib_shm_compositor_paint, - _cairo_xlib_shm_compositor_mask, - _cairo_xlib_shm_compositor_stroke, - _cairo_xlib_shm_compositor_fill, - _cairo_xlib_shm_compositor_glyphs, -}; - -const cairo_compositor_t * -_cairo_xlib_fallback_compositor_get (void) -{ - return &_cairo_xlib_shm_compositor; -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-private.h deleted file mode 100644 index 0f2f2e1faa0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-private.h +++ /dev/null @@ -1,470 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributors(s): - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ - -#ifndef CAIRO_XLIB_PRIVATE_H -#define CAIRO_XLIB_PRIVATE_H - -#include "cairo-xlib-xrender-private.h" -#include "cairo-xlib.h" - -#include "cairo-compiler-private.h" -#include "cairo-device-private.h" -#include "cairo-freelist-type-private.h" -#include "cairo-list-private.h" -#include "cairo-reference-count-private.h" -#include "cairo-types-private.h" -#include "cairo-scaled-font-private.h" -#include "cairo-surface-private.h" - -#include -#include - -typedef struct _cairo_xlib_display cairo_xlib_display_t; -typedef struct _cairo_xlib_shm_display cairo_xlib_shm_display_t; -typedef struct _cairo_xlib_screen cairo_xlib_screen_t; -typedef struct _cairo_xlib_source cairo_xlib_source_t; -typedef struct _cairo_xlib_proxy cairo_xlib_proxy_t; -typedef struct _cairo_xlib_surface cairo_xlib_surface_t; - -/* size of color cube */ -#define CUBE_SIZE 6 -/* size of gray ramp */ -#define RAMP_SIZE 16 -/* maximum number of cached GC's */ -#define GC_CACHE_SIZE 4 - -struct _cairo_xlib_display { - cairo_device_t base; - - cairo_xlib_display_t *next; - - Display *display; - cairo_list_t screens; - cairo_list_t fonts; - - cairo_xlib_shm_display_t *shm; - - const cairo_compositor_t *compositor; - - int render_major; - int render_minor; - XRenderPictFormat *cached_xrender_formats[CAIRO_FORMAT_RGB30 + 1]; - - int force_precision; - - cairo_surface_t *white; - cairo_surface_t *alpha[256]; - cairo_surface_t *solid[32]; - uint32_t solid_cache[32]; /* low 16 are opaque, high 16 transparent */ - struct { - uint32_t color; - int index; - } last_solid_cache[2]; - - /* TRUE if the server has a bug with repeating pictures - * - * https://bugs.freedesktop.org/show_bug.cgi?id=3566 - * - * We can't test for this because it depends on whether the - * picture is in video memory or not. - * - * We also use this variable as a guard against a second - * independent bug with transformed repeating pictures: - * - * http://lists.freedesktop.org/archives/cairo/2004-September/001839.html - * - * Both are fixed in xorg >= 6.9 and hopefully in > 6.8.2, so - * we can reuse the test for now. - */ - unsigned int buggy_gradients : 1; - unsigned int buggy_pad_reflect : 1; - unsigned int buggy_repeat : 1; - unsigned int closed :1; -}; - -typedef struct _cairo_xlib_visual_info { - cairo_list_t link; - VisualID visualid; - struct { uint8_t a, r, g, b; } colors[256]; - uint8_t cube_to_pseudocolor[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE]; - uint8_t field8_to_cube[256]; - int8_t dither8_to_cube[256]; - uint8_t gray8_to_pseudocolor[256]; -} cairo_xlib_visual_info_t; - -struct _cairo_xlib_screen { - cairo_list_t link; - - cairo_device_t *device; - Screen *screen; - - cairo_list_t surfaces; - - cairo_bool_t has_font_options; - cairo_font_options_t font_options; - - GC gc[GC_CACHE_SIZE]; - uint8_t gc_depths[GC_CACHE_SIZE]; - - cairo_list_t visuals; -}; - -enum { - GLYPHSET_INDEX_ARGB32, - GLYPHSET_INDEX_A8, - GLYPHSET_INDEX_A1, - NUM_GLYPHSETS -}; - -typedef struct _cairo_xlib_font_glyphset { - GlyphSet glyphset; - cairo_format_t format; - XRenderPictFormat *xrender_format; - struct _cairo_xlib_font_glyphset_free_glyphs { - int count; - unsigned long indices[128]; - } to_free; -} cairo_xlib_font_glyphset_t; - -typedef struct _cairo_xlib_font { - cairo_scaled_font_private_t base; - cairo_scaled_font_t *font; - cairo_device_t *device; - cairo_list_t link; - cairo_xlib_font_glyphset_t glyphset[NUM_GLYPHSETS]; -} cairo_xlib_font_t; - -struct _cairo_xlib_surface { - cairo_surface_t base; - - Picture picture; - Drawable drawable; - - const cairo_compositor_t *compositor; - cairo_surface_t *shm; - int fallback; - - cairo_xlib_display_t *display; - cairo_xlib_screen_t *screen; - cairo_list_t link; - - Display *dpy; /* only valid between acquire/release */ - cairo_bool_t owns_pixmap; - Visual *visual; - - int use_pixmap; - - int width; - int height; - int depth; - - int precision; - XRenderPictFormat *xrender_format; - /* XXX pixman_format instead of masks? */ - uint32_t a_mask; - uint32_t r_mask; - uint32_t g_mask; - uint32_t b_mask; - - struct _cairo_xlib_source { - cairo_surface_t base; - - Picture picture; - Pixmap pixmap; - Display *dpy; - - unsigned int filter:3; - unsigned int extend:3; - unsigned int has_matrix:1; - unsigned int has_component_alpha:1; - } embedded_source; -}; - -struct _cairo_xlib_proxy { - struct _cairo_xlib_source source; - cairo_surface_t *owner; -}; - -inline static cairo_bool_t -_cairo_xlib_vendor_is_xorg (Display *dpy) -{ - const char *const vendor = ServerVendor (dpy); - return strstr (vendor, "X.Org") || strstr (vendor, "Xorg"); -} - -cairo_private cairo_status_t -_cairo_xlib_surface_get_gc (cairo_xlib_display_t *display, - cairo_xlib_surface_t *surface, - GC *gc); - -cairo_private cairo_device_t * -_cairo_xlib_device_create (Display *display); - -cairo_private void -_cairo_xlib_display_init_shm (cairo_xlib_display_t *display); - -cairo_private void -_cairo_xlib_display_fini_shm (cairo_xlib_display_t *display); - -cairo_private cairo_xlib_screen_t * -_cairo_xlib_display_get_screen (cairo_xlib_display_t *display, - Screen *screen); - -cairo_private cairo_status_t -_cairo_xlib_display_acquire (cairo_device_t *device, - cairo_xlib_display_t **display); - -cairo_private cairo_bool_t -_cairo_xlib_display_has_repeat (cairo_device_t *device); - -cairo_private cairo_bool_t -_cairo_xlib_display_has_reflect (cairo_device_t *device); - -cairo_private cairo_bool_t -_cairo_xlib_display_has_gradients (cairo_device_t *device); - -cairo_private void -_cairo_xlib_display_set_precision(cairo_device_t *device, - int precision); - -cairo_private XRenderPictFormat * -_cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display, - cairo_format_t format); - -cairo_private XRenderPictFormat * -_cairo_xlib_display_get_xrender_format_for_pixman (cairo_xlib_display_t *display, - pixman_format_code_t format); - -cairo_private cairo_status_t -_cairo_xlib_screen_get (Display *dpy, - Screen *screen, - cairo_xlib_screen_t **out); - -cairo_private void -_cairo_xlib_screen_destroy (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info); - -cairo_private GC -_cairo_xlib_screen_get_gc (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info, - int depth, - Drawable drawable); -cairo_private void -_cairo_xlib_screen_put_gc (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info, - int depth, - GC gc); - -cairo_private cairo_font_options_t * -_cairo_xlib_screen_get_font_options (cairo_xlib_screen_t *info); - -cairo_private cairo_status_t -_cairo_xlib_screen_get_visual_info (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info, - Visual *visual, - cairo_xlib_visual_info_t **out); - -cairo_private cairo_status_t -_cairo_xlib_visual_info_create (Display *dpy, - int screen, - VisualID visualid, - cairo_xlib_visual_info_t **out); - -cairo_private void -_cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info); - -cairo_private const cairo_compositor_t * -_cairo_xlib_core_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_xlib_fallback_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_xlib_mask_compositor_get (void); - -cairo_private const cairo_compositor_t * -_cairo_xlib_traps_compositor_get (void); - -cairo_private void -_cairo_xlib_surface_ensure_picture (cairo_xlib_surface_t *surface); - -cairo_private void -_cairo_xlib_surface_set_precision (cairo_xlib_surface_t *surface, - cairo_antialias_t antialias); - -cairo_private cairo_int_status_t -_cairo_xlib_surface_set_attributes (cairo_xlib_display_t *display, - cairo_xlib_surface_t *surface, - cairo_surface_attributes_t *attributes, - double xc, - double yc); - -cairo_private cairo_status_t -_cairo_xlib_surface_draw_image (cairo_xlib_surface_t *surface, - cairo_image_surface_t *image, - int src_x, - int src_y, - int width, - int height, - int dst_x, - int dst_y); - -cairo_private cairo_surface_t * -_cairo_xlib_source_create_for_pattern (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y); - -cairo_private void -_cairo_xlib_font_close (cairo_xlib_font_t *font); - -#define CAIRO_RENDER_AT_LEAST(surface, major, minor) \ - (((surface)->render_major > major) || \ - (((surface)->render_major == major) && ((surface)->render_minor >= minor))) - -#define CAIRO_RENDER_HAS_CREATE_PICTURE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0) -#define CAIRO_RENDER_HAS_COMPOSITE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0) -#define CAIRO_RENDER_HAS_COMPOSITE_TEXT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0) - -#define CAIRO_RENDER_HAS_FILL_RECTANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 1) - -#define CAIRO_RENDER_HAS_DISJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2) -#define CAIRO_RENDER_HAS_CONJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2) - -#define CAIRO_RENDER_HAS_TRAPEZOIDS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) -#define CAIRO_RENDER_HAS_TRIANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) -#define CAIRO_RENDER_HAS_TRISTRIP(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) -#define CAIRO_RENDER_HAS_TRIFAN(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) - -#define CAIRO_RENDER_HAS_PICTURE_TRANSFORM(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6) -#define CAIRO_RENDER_HAS_FILTERS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6) -#define CAIRO_RENDER_HAS_FILTER_GOOD(surface) FALSE -#define CAIRO_RENDER_HAS_FILTER_BEST(surface) FALSE - -#define CAIRO_RENDER_HAS_EXTENDED_REPEAT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10) -#define CAIRO_RENDER_HAS_GRADIENTS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10) - -#define CAIRO_RENDER_HAS_PDF_OPERATORS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 11) - -#define CAIRO_RENDER_SUPPORTS_OPERATOR(surface, op) \ - ((op) <= CAIRO_OPERATOR_SATURATE || \ - (CAIRO_RENDER_HAS_PDF_OPERATORS(surface) && \ - (op) <= CAIRO_OPERATOR_HSL_LUMINOSITY)) - -/* - * Return whether two xlib surfaces share the same - * screen. Both core and Render drawing require this - * when using multiple drawables in an operation. - */ -static inline cairo_bool_t -_cairo_xlib_surface_same_screen (cairo_xlib_surface_t *dst, - cairo_xlib_surface_t *src) -{ - return dst->screen == src->screen; -} - -cairo_private cairo_int_status_t -_cairo_xlib_core_fill_boxes (cairo_xlib_surface_t *dst, - const cairo_color_t *color, - cairo_boxes_t *boxes); - -cairo_private cairo_int_status_t -_cairo_xlib_core_fill_rectangles (cairo_xlib_surface_t *dst, - const cairo_color_t *color, - int num_rects, - cairo_rectangle_int_t *rects); - -static inline void -_cairo_xlib_surface_put_gc (cairo_xlib_display_t *display, - cairo_xlib_surface_t *surface, - GC gc) -{ - _cairo_xlib_screen_put_gc (display, - surface->screen, - surface->depth, - gc); -} - -cairo_private cairo_surface_t * -_cairo_xlib_surface_create_similar_shm (void *surface, - cairo_format_t format, - int width, int height); - -cairo_private cairo_surface_t * -_cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface, - cairo_bool_t overwrite); - -cairo_private cairo_int_status_t -_cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface); - -cairo_private cairo_surface_t * -_cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other, - pixman_format_code_t format, - int width, int height); - -cairo_private cairo_surface_t * -_cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface, - pixman_format_code_t format, - int width, int height); - -cairo_private void -_cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface, - XImage *ximage); - -cairo_private void * -_cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface); - -cairo_private void -_cairo_xlib_shm_surface_mark_active (cairo_surface_t *shm); - -cairo_private cairo_bool_t -_cairo_xlib_shm_surface_is_active (cairo_surface_t *surface); - -cairo_private cairo_bool_t -_cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface); - -cairo_private Pixmap -_cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface); - -cairo_private XRenderPictFormat * -_cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface); - -cairo_private pixman_format_code_t -_pixman_format_for_xlib_surface (cairo_xlib_surface_t *surface); - -#endif /* CAIRO_XLIB_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-render-compositor.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-render-compositor.c deleted file mode 100644 index 8a1ec7bd731..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-render-compositor.c +++ /dev/null @@ -1,2005 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Behdad Esfahbod - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-damage-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-pattern-private.h" -#include "cairo-pixman-private.h" -#include "cairo-traps-private.h" -#include "cairo-tristrip-private.h" - -static cairo_int_status_t -check_composite (const cairo_composite_rectangles_t *extents) -{ - cairo_xlib_display_t *display = ((cairo_xlib_surface_t *)extents->surface)->display; - - if (! CAIRO_RENDER_SUPPORTS_OPERATOR (display, extents->op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -acquire (void *abstract_dst) -{ - cairo_xlib_surface_t *dst = abstract_dst; - cairo_int_status_t status; - - status = _cairo_xlib_display_acquire (dst->base.device, &dst->display); - if (unlikely (status)) - return status; - - dst->dpy = dst->display->display; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -release (void *abstract_dst) -{ - cairo_xlib_surface_t *dst = abstract_dst; - - cairo_device_release (&dst->display->base); - dst->dpy = NULL; - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -set_clip_region (void *_surface, - cairo_region_t *region) -{ - cairo_xlib_surface_t *surface = _surface; - - _cairo_xlib_surface_ensure_picture (surface); - - if (region != NULL) { - XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *rects = stack_rects; - int n_rects, i; - - n_rects = cairo_region_num_rectangles (region); - if (n_rects > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle)); - if (unlikely (rects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - for (i = 0; i < n_rects; i++) { - cairo_rectangle_int_t rect; - - cairo_region_get_rectangle (region, i, &rect); - - rects[i].x = rect.x; - rects[i].y = rect.y; - rects[i].width = rect.width; - rects[i].height = rect.height; - } - XRenderSetPictureClipRectangles (surface->dpy, - surface->picture, - 0, 0, - rects, n_rects); - if (rects != stack_rects) - free (rects); - } else { - XRenderPictureAttributes pa; - pa.clip_mask = None; - XRenderChangePicture (surface->dpy, - surface->picture, - CPClipMask, &pa); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -copy_image_boxes (void *_dst, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy) -{ - cairo_xlib_surface_t *dst = _dst; - struct _cairo_boxes_chunk *chunk; - cairo_int_status_t status; - Pixmap src; - GC gc; - int i, j; - - assert (image->depth == dst->depth); - - status = acquire (dst); - if (unlikely (status)) - return status; - - status = _cairo_xlib_surface_get_gc (dst->display, dst, &gc); - if (unlikely (status)) { - release (dst); - return status; - } - - src = _cairo_xlib_shm_surface_get_pixmap (&image->base); - if (boxes->num_boxes == 1) { - int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); - int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); - int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); - int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); - - _cairo_xlib_shm_surface_mark_active (&image->base); - XCopyArea (dst->dpy, src, dst->drawable, gc, - x1 + dx, y1 + dy, - x2 - x1, y2 - y1, - x1, y1); - } else { - XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *rects = stack_rects; - - if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); - if (unlikely (rects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - j = 0; - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - - if (x2 > x1 && y2 > y1) { - rects[j].x = x1; - rects[j].y = y1; - rects[j].width = x2 - x1; - rects[j].height = y2 - y1; - j++; - } - } - } - - XSetClipRectangles (dst->dpy, gc, 0, 0, rects, j, Unsorted); - _cairo_xlib_shm_surface_mark_active (&image->base); - XCopyArea (dst->dpy, src, dst->drawable, gc, - 0, 0, image->width, image->height, -dx, -dy); - XSetClipMask (dst->dpy, gc, None); - - if (rects != stack_rects) - free (rects); - } - - _cairo_xlib_surface_put_gc (dst->display, dst, gc); - release (dst); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -boxes_cover_surface (cairo_boxes_t *boxes, - cairo_xlib_surface_t *surface) -{ - cairo_box_t *b; - - if (boxes->num_boxes != 1) - return FALSE; - - b = &boxes->chunks.base[0]; - - if (_cairo_fixed_integer_part (b->p1.x) > 0 || - _cairo_fixed_integer_part (b->p1.y) > 0) - return FALSE; - - if (_cairo_fixed_integer_part (b->p2.x) < surface->width || - _cairo_fixed_integer_part (b->p2.y) < surface->height) - return FALSE; - - return TRUE; -} - -static cairo_int_status_t -draw_image_boxes (void *_dst, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy) -{ - cairo_xlib_surface_t *dst = _dst; - struct _cairo_boxes_chunk *chunk; - cairo_image_surface_t *shm = NULL; - cairo_int_status_t status; - int i; - - if (image->base.device == dst->base.device) { - if (image->depth != dst->depth) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (_cairo_xlib_shm_surface_get_pixmap (&image->base)) - return copy_image_boxes (dst, image, boxes, dx, dy); - - goto draw_image_boxes; - } - - if (boxes_cover_surface (boxes, dst)) - shm = (cairo_image_surface_t *) _cairo_xlib_surface_get_shm (dst, TRUE); - if (shm) { - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - cairo_rectangle_int_t r; - - r.x = _cairo_fixed_integer_part (b->p1.x); - r.y = _cairo_fixed_integer_part (b->p1.y); - r.width = _cairo_fixed_integer_part (b->p2.x) - r.x; - r.height = _cairo_fixed_integer_part (b->p2.y) - r.y; - - if (shm->pixman_format != image->pixman_format || - ! pixman_blt ((uint32_t *)image->data, (uint32_t *)shm->data, - image->stride / sizeof (uint32_t), - shm->stride / sizeof (uint32_t), - PIXMAN_FORMAT_BPP (image->pixman_format), - PIXMAN_FORMAT_BPP (shm->pixman_format), - r.x + dx, r.y + dy, - r.x, r.y, - r.width, r.height)) - { - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, NULL, shm->pixman_image, - r.x + dx, r.y + dy, - 0, 0, - r.x, r.y, - r.width, r.height); - } - - shm->base.damage = - _cairo_damage_add_rectangle (shm->base.damage, &r); - } - } - dst->base.is_clear = FALSE; - dst->fallback++; - dst->base.serial++; - return CAIRO_INT_STATUS_NOTHING_TO_DO; - } - - if (image->depth == dst->depth && - ((cairo_xlib_display_t *)dst->display)->shm) { - cairo_box_t extents; - cairo_rectangle_int_t r; - - _cairo_boxes_extents (boxes, &extents); - _cairo_box_round_to_rectangle (&extents, &r); - - shm = (cairo_image_surface_t *) - _cairo_xlib_surface_create_shm (dst, image->pixman_format, - r.width, r.height); - if (shm) { - int tx = -r.x, ty = -r.y; - - assert (shm->pixman_format == image->pixman_format); - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - - r.x = _cairo_fixed_integer_part (b->p1.x); - r.y = _cairo_fixed_integer_part (b->p1.y); - r.width = _cairo_fixed_integer_part (b->p2.x) - r.x; - r.height = _cairo_fixed_integer_part (b->p2.y) - r.y; - - if (! pixman_blt ((uint32_t *)image->data, (uint32_t *)shm->data, - image->stride / sizeof (uint32_t), - shm->stride / sizeof (uint32_t), - PIXMAN_FORMAT_BPP (image->pixman_format), - PIXMAN_FORMAT_BPP (shm->pixman_format), - r.x + dx, r.y + dy, - r.x + tx, r.y + ty, - r.width, r.height)) - { - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, NULL, shm->pixman_image, - r.x + dx, r.y + dy, - 0, 0, - r.x + tx, r.y + ty, - r.width, r.height); - } - } - } - - dx = tx; - dy = ty; - image = shm; - - if (_cairo_xlib_shm_surface_get_pixmap (&image->base)) { - status = copy_image_boxes (dst, image, boxes, dx, dy); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - goto out; - } - } - } - -draw_image_boxes: - status = CAIRO_STATUS_SUCCESS; - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - cairo_box_t *b = &chunk->base[i]; - int x1 = _cairo_fixed_integer_part (b->p1.x); - int y1 = _cairo_fixed_integer_part (b->p1.y); - int x2 = _cairo_fixed_integer_part (b->p2.x); - int y2 = _cairo_fixed_integer_part (b->p2.y); - if (_cairo_xlib_surface_draw_image (dst, image, - x1 + dx, y1 + dy, - x2 - x1, y2 - y1, - x1, y1)) { - status = CAIRO_INT_STATUS_UNSUPPORTED; - goto out; - } - } - } - -out: - cairo_surface_destroy (&shm->base); - return status; -} - -static cairo_int_status_t -copy_boxes (void *_dst, - cairo_surface_t *_src, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents, - int dx, int dy) -{ - cairo_xlib_surface_t *dst = _dst; - cairo_xlib_surface_t *src = (cairo_xlib_surface_t *)_src; - struct _cairo_boxes_chunk *chunk; - cairo_int_status_t status; - GC gc; - Drawable d; - int i, j; - - if (! _cairo_xlib_surface_same_screen (dst, src)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - if (dst->depth != src->depth) - return CAIRO_INT_STATUS_UNSUPPORTED; - - status = acquire (dst); - if (unlikely (status)) - return status; - - status = _cairo_xlib_surface_get_gc (dst->display, dst, &gc); - if (unlikely (status)) { - release (dst); - return status; - } - - if (src->fallback && src->shm->damage->dirty) { - assert (src != dst); - d = _cairo_xlib_shm_surface_get_pixmap (src->shm); - assert (d != 0); - } else { - if (! src->owns_pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = IncludeInferiors; - XChangeGC (dst->display->display, gc, GCSubwindowMode, &gcv); - } - d = src->drawable; - } - - if (boxes->num_boxes == 1) { - int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); - int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); - int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); - int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); - - XCopyArea (dst->dpy, d, dst->drawable, gc, - x1 + dx, y1 + dy, - x2 - x1, y2 - y1, - x1, y1); - } else { - /* We can only have a single control for subwindow_mode on the - * GC. If we have a Window destination, we need to set ClipByChildren, - * but if we have a Window source, we need IncludeInferiors. If we have - * both a Window destination and source, we must fallback. There is - * no convenient way to detect if a drawable is a Pixmap or Window, - * therefore we can only rely on those surfaces that we created - * ourselves to be Pixmaps, and treat everything else as a potential - * Window. - */ - if (src == dst || (!src->owns_pixmap && !dst->owns_pixmap)) { - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - XCopyArea (dst->dpy, d, dst->drawable, gc, - x1 + dx, y1 + dy, - x2 - x1, y2 - y1, - x1, y1); - } - } - } else { - XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *rects = stack_rects; - - if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); - if (unlikely (rects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - j = 0; - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - - rects[j].x = x1; - rects[j].y = y1; - rects[j].width = x2 - x1; - rects[j].height = y2 - y1; - j++; - } - } - assert (j == boxes->num_boxes); - - XSetClipRectangles (dst->dpy, gc, 0, 0, rects, j, Unsorted); - - XCopyArea (dst->dpy, d, dst->drawable, gc, - extents->x + dx, extents->y + dy, - extents->width, extents->height, - extents->x, extents->y); - - XSetClipMask (dst->dpy, gc, None); - - if (rects != stack_rects) - free (rects); - } - } - - if (src->fallback && src->shm->damage->dirty) { - _cairo_xlib_shm_surface_mark_active (src->shm); - } else if (! src->owns_pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = ClipByChildren; - XChangeGC (dst->display->display, gc, GCSubwindowMode, &gcv); - } - - _cairo_xlib_surface_put_gc (dst->display, dst, gc); - release (dst); - return CAIRO_STATUS_SUCCESS; -} - -static int -_render_operator (cairo_operator_t op) -{ - switch (op) { - case CAIRO_OPERATOR_CLEAR: - return PictOpClear; - - case CAIRO_OPERATOR_SOURCE: - return PictOpSrc; - case CAIRO_OPERATOR_OVER: - return PictOpOver; - case CAIRO_OPERATOR_IN: - return PictOpIn; - case CAIRO_OPERATOR_OUT: - return PictOpOut; - case CAIRO_OPERATOR_ATOP: - return PictOpAtop; - - case CAIRO_OPERATOR_DEST: - return PictOpDst; - case CAIRO_OPERATOR_DEST_OVER: - return PictOpOverReverse; - case CAIRO_OPERATOR_DEST_IN: - return PictOpInReverse; - case CAIRO_OPERATOR_DEST_OUT: - return PictOpOutReverse; - case CAIRO_OPERATOR_DEST_ATOP: - return PictOpAtopReverse; - - case CAIRO_OPERATOR_XOR: - return PictOpXor; - case CAIRO_OPERATOR_ADD: - return PictOpAdd; - case CAIRO_OPERATOR_SATURATE: - return PictOpSaturate; - - case CAIRO_OPERATOR_MULTIPLY: - return PictOpMultiply; - case CAIRO_OPERATOR_SCREEN: - return PictOpScreen; - case CAIRO_OPERATOR_OVERLAY: - return PictOpOverlay; - case CAIRO_OPERATOR_DARKEN: - return PictOpDarken; - case CAIRO_OPERATOR_LIGHTEN: - return PictOpLighten; - case CAIRO_OPERATOR_COLOR_DODGE: - return PictOpColorDodge; - case CAIRO_OPERATOR_COLOR_BURN: - return PictOpColorBurn; - case CAIRO_OPERATOR_HARD_LIGHT: - return PictOpHardLight; - case CAIRO_OPERATOR_SOFT_LIGHT: - return PictOpSoftLight; - case CAIRO_OPERATOR_DIFFERENCE: - return PictOpDifference; - case CAIRO_OPERATOR_EXCLUSION: - return PictOpExclusion; - case CAIRO_OPERATOR_HSL_HUE: - return PictOpHSLHue; - case CAIRO_OPERATOR_HSL_SATURATION: - return PictOpHSLSaturation; - case CAIRO_OPERATOR_HSL_COLOR: - return PictOpHSLColor; - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return PictOpHSLLuminosity; - - default: - ASSERT_NOT_REACHED; - return PictOpOver; - } -} - -static cairo_bool_t -fill_reduces_to_source (cairo_operator_t op, - const cairo_color_t *color, - cairo_xlib_surface_t *dst) -{ - if (dst->base.is_clear || CAIRO_COLOR_IS_OPAQUE (color)) { - if (op == CAIRO_OPERATOR_OVER) - return TRUE; - if (op == CAIRO_OPERATOR_ADD) - return (dst->base.content & CAIRO_CONTENT_COLOR) == 0; - } - - return FALSE; -} - -static cairo_int_status_t -fill_rectangles (void *abstract_surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_rectangle_int_t *rects, - int num_rects) -{ - cairo_xlib_surface_t *dst = abstract_surface; - XRenderColor render_color; - int i; - - //X_DEBUG ((display->display, "fill_rectangles (dst=%x)", (unsigned int) surface->drawable)); - - if (fill_reduces_to_source (op, color, dst)) - op = CAIRO_OPERATOR_SOURCE; - - if (!CAIRO_RENDER_HAS_FILL_RECTANGLES(dst->display)) { - cairo_int_status_t status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (op == CAIRO_OPERATOR_SOURCE) - status = _cairo_xlib_core_fill_rectangles (dst, color, num_rects, rects); - return status; - } - - render_color.red = color->red_short; - render_color.green = color->green_short; - render_color.blue = color->blue_short; - render_color.alpha = color->alpha_short; - - _cairo_xlib_surface_ensure_picture (dst); - if (num_rects == 1) { - /* Take advantage of the protocol compaction that libXrender performs - * to amalgamate sequences of XRenderFillRectangle(). - */ - XRenderFillRectangle (dst->dpy, - _render_operator (op), - dst->picture, - &render_color, - rects->x, rects->y, - rects->width, rects->height); - } else { - XRectangle stack_xrects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *xrects = stack_xrects; - - if (num_rects > ARRAY_LENGTH (stack_xrects)) { - xrects = _cairo_malloc_ab (num_rects, sizeof (XRectangle)); - if (unlikely (xrects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - for (i = 0; i < num_rects; i++) { - xrects[i].x = rects[i].x; - xrects[i].y = rects[i].y; - xrects[i].width = rects[i].width; - xrects[i].height = rects[i].height; - } - - XRenderFillRectangles (dst->dpy, - _render_operator (op), - dst->picture, - &render_color, xrects, num_rects); - - if (xrects != stack_xrects) - free (xrects); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -fill_boxes (void *abstract_surface, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - cairo_xlib_surface_t *dst = abstract_surface; - XRenderColor render_color; - - if (fill_reduces_to_source (op, color, dst)) - op = CAIRO_OPERATOR_SOURCE; - - if (!CAIRO_RENDER_HAS_FILL_RECTANGLES(dst->display)) { - cairo_int_status_t status; - - status = CAIRO_INT_STATUS_UNSUPPORTED; - if (op == CAIRO_OPERATOR_SOURCE) - status = _cairo_xlib_core_fill_boxes (dst, color, boxes); - return status; - } - - render_color.red = color->red_short; - render_color.green = color->green_short; - render_color.blue = color->blue_short; - render_color.alpha = color->alpha_short; - - _cairo_xlib_surface_ensure_picture (dst); - if (boxes->num_boxes == 1) { - int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); - int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); - int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); - int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); - - /* Take advantage of the protocol compaction that libXrender performs - * to amalgamate sequences of XRenderFillRectangle(). - */ - XRenderFillRectangle (dst->dpy, - _render_operator (op), - dst->picture, - &render_color, - x1, y1, - x2 - x1, y2 - y1); - } else { - XRectangle stack_xrects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *xrects = stack_xrects; - struct _cairo_boxes_chunk *chunk; - int i, j; - - if (boxes->num_boxes > ARRAY_LENGTH (stack_xrects)) { - xrects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); - if (unlikely (xrects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - j = 0; - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - - xrects[j].x = x1; - xrects[j].y = y1; - xrects[j].width = x2 - x1; - xrects[j].height = y2 - y1; - j++; - } - } - - XRenderFillRectangles (dst->dpy, - _render_operator (op), - dst->picture, - &render_color, xrects, j); - - if (xrects != stack_xrects) - free (xrects); - } - - return CAIRO_STATUS_SUCCESS; -} - -#if 0 -check_composite () - operation = _categorize_composite_operation (dst, op, src_pattern, - mask_pattern != NULL); - if (operation == DO_UNSUPPORTED) - return UNSUPPORTED ("unsupported operation"); - - //X_DEBUG ((display->display, "composite (dst=%x)", (unsigned int) dst->drawable)); - - operation = _recategorize_composite_operation (dst, op, src, &src_attr, - mask_pattern != NULL); - if (operation == DO_UNSUPPORTED) { - status = UNSUPPORTED ("unsupported operation"); - goto BAIL; - } -#endif - -static cairo_int_status_t -composite (void *abstract_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - cairo_xlib_surface_t *dst = abstract_dst; - cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; - - op = _render_operator (op); - - _cairo_xlib_surface_ensure_picture (dst); - if (abstract_mask) { - cairo_xlib_source_t *mask = (cairo_xlib_source_t *)abstract_mask; - - XRenderComposite (dst->dpy, op, - src->picture, mask->picture, dst->picture, - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height); - } else { - XRenderComposite (dst->dpy, op, - src->picture, 0, dst->picture, - src_x, src_y, - 0, 0, - dst_x, dst_y, - width, height); - } - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -lerp (void *abstract_dst, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - cairo_xlib_surface_t *dst = abstract_dst; - cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; - cairo_xlib_source_t *mask = (cairo_xlib_source_t *)abstract_mask; - - _cairo_xlib_surface_ensure_picture (dst); - XRenderComposite (dst->dpy, PictOpOutReverse, - mask->picture, None, dst->picture, - mask_x, mask_y, - 0, 0, - dst_x, dst_y, - width, height); - XRenderComposite (dst->dpy, PictOpAdd, - src->picture, mask->picture, dst->picture, - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_boxes (void *abstract_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents) -{ - cairo_xlib_surface_t *dst = abstract_dst; - Picture src = ((cairo_xlib_source_t *)abstract_src)->picture; - Picture mask = abstract_mask ? ((cairo_xlib_source_t *)abstract_mask)->picture : 0; - XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *rects = stack_rects; - struct _cairo_boxes_chunk *chunk; - int i, j; - - op = _render_operator (op); - _cairo_xlib_surface_ensure_picture (dst); - if (boxes->num_boxes == 1) { - int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); - int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); - int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); - int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); - - XRenderComposite (dst->dpy, op, - src, mask, dst->picture, - x1 + src_x, y1 + src_y, - x1 + mask_x, y1 + mask_y, - x1 - dst_x, y1 - dst_y, - x2 - x1, y2 - y1); - return CAIRO_STATUS_SUCCESS; - } - - if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); - if (unlikely (rects == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - j = 0; - for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { - for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); - int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); - int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); - int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); - - rects[j].x = x1 - dst_x; - rects[j].y = y1 - dst_y; - rects[j].width = x2 - x1; - rects[j].height = y2 - y1; - j++; - } - } - assert (j == boxes->num_boxes); - - XRenderSetPictureClipRectangles (dst->dpy, - dst->picture, - 0, 0, - rects, j); - if (rects != stack_rects) - free (rects); - - XRenderComposite (dst->dpy, op, - src, mask, dst->picture, - extents->x + src_x, extents->y + src_y, - extents->x + mask_x, extents->y + mask_y, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - set_clip_region (dst, NULL); - - return CAIRO_STATUS_SUCCESS; -} - -/* font rendering */ - -void -_cairo_xlib_font_close (cairo_xlib_font_t *priv) -{ - cairo_xlib_display_t *display = (cairo_xlib_display_t *)priv->base.key; - int i; - - /* XXX All I really want is to do is zap my glyphs... */ - _cairo_scaled_font_reset_cache (priv->font); - - for (i = 0; i < NUM_GLYPHSETS; i++) { - cairo_xlib_font_glyphset_t *info; - - info = &priv->glyphset[i]; - if (info->glyphset) - XRenderFreeGlyphSet (display->display, info->glyphset); - } - - /* XXX locking */ - cairo_list_del (&priv->link); - cairo_list_del (&priv->base.link); - free (priv); -} - -static void -_cairo_xlib_font_fini (cairo_scaled_font_private_t *abstract_private, - cairo_scaled_font_t *font) -{ - cairo_xlib_font_t *priv = (cairo_xlib_font_t *) abstract_private; - cairo_status_t status; - cairo_xlib_display_t *display; - int i; - - cairo_list_del (&priv->base.link); - cairo_list_del (&priv->link); - - status = _cairo_xlib_display_acquire (priv->device, &display); - if (status) - goto BAIL; - - for (i = 0; i < NUM_GLYPHSETS; i++) { - cairo_xlib_font_glyphset_t *info; - - info = &priv->glyphset[i]; - if (info->glyphset) - XRenderFreeGlyphSet (display->display, info->glyphset); - } - - cairo_device_release (&display->base); -BAIL: - cairo_device_destroy (&display->base); - free (priv); -} - -static cairo_xlib_font_t * -_cairo_xlib_font_create (cairo_xlib_display_t *display, - cairo_scaled_font_t *font) -{ - cairo_xlib_font_t *priv; - int i; - - priv = malloc (sizeof (cairo_xlib_font_t)); - if (unlikely (priv == NULL)) - return NULL; - - _cairo_scaled_font_attach_private (font, &priv->base, display, - _cairo_xlib_font_fini); - - priv->device = cairo_device_reference (&display->base); - priv->font = font; - cairo_list_add (&priv->link, &display->fonts); - - for (i = 0; i < NUM_GLYPHSETS; i++) { - cairo_xlib_font_glyphset_t *info = &priv->glyphset[i]; - switch (i) { - case GLYPHSET_INDEX_ARGB32: info->format = CAIRO_FORMAT_ARGB32; break; - case GLYPHSET_INDEX_A8: info->format = CAIRO_FORMAT_A8; break; - case GLYPHSET_INDEX_A1: info->format = CAIRO_FORMAT_A1; break; - default: ASSERT_NOT_REACHED; break; - } - info->xrender_format = NULL; - info->glyphset = None; - info->to_free.count = 0; - } - - return priv; -} - -static int -_cairo_xlib_get_glyphset_index_for_format (cairo_format_t format) -{ - if (format == CAIRO_FORMAT_A8) - return GLYPHSET_INDEX_A8; - if (format == CAIRO_FORMAT_A1) - return GLYPHSET_INDEX_A1; - - assert (format == CAIRO_FORMAT_ARGB32); - return GLYPHSET_INDEX_ARGB32; -} - -static inline cairo_xlib_font_t * -_cairo_xlib_font_get (const cairo_xlib_display_t *display, - cairo_scaled_font_t *font) -{ - return (cairo_xlib_font_t *)_cairo_scaled_font_find_private (font, display); -} - -typedef struct { - cairo_scaled_glyph_private_t base; - - - cairo_xlib_font_glyphset_t *glyphset; -} cairo_xlib_glyph_private_t; - -static void -_cairo_xlib_glyph_fini (cairo_scaled_glyph_private_t *glyph_private, - cairo_scaled_glyph_t *glyph, - cairo_scaled_font_t *font) -{ - cairo_xlib_glyph_private_t *priv = (cairo_xlib_glyph_private_t *)glyph_private; - - if (! font->finished) { - cairo_xlib_font_t *font_private; - struct _cairo_xlib_font_glyphset_free_glyphs *to_free; - cairo_xlib_font_glyphset_t *info; - - font_private = _cairo_xlib_font_get (glyph_private->key, font); - assert (font_private); - - info = priv->glyphset; - to_free = &info->to_free; - if (to_free->count == ARRAY_LENGTH (to_free->indices)) { - cairo_xlib_display_t *display; - - if (_cairo_xlib_display_acquire (font_private->device, - &display) == CAIRO_STATUS_SUCCESS) { - XRenderFreeGlyphs (display->display, - info->glyphset, - to_free->indices, - to_free->count); - cairo_device_release (&display->base); - } - - to_free->count = 0; - } - - to_free->indices[to_free->count++] = - _cairo_scaled_glyph_index (glyph); - } - - cairo_list_del (&glyph_private->link); - free (glyph_private); -} - -static cairo_status_t -_cairo_xlib_glyph_attach (cairo_xlib_display_t *display, - cairo_scaled_glyph_t *glyph, - cairo_xlib_font_glyphset_t *info) -{ - cairo_xlib_glyph_private_t *priv; - - priv = malloc (sizeof (*priv)); - if (unlikely (priv == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_scaled_glyph_attach_private (glyph, &priv->base, display, - _cairo_xlib_glyph_fini); - priv->glyphset = info; - - glyph->dev_private = info; - glyph->dev_private_key = display; - return CAIRO_STATUS_SUCCESS; -} - -static cairo_xlib_font_glyphset_t * -_cairo_xlib_font_get_glyphset_info_for_format (cairo_xlib_display_t *display, - cairo_scaled_font_t *font, - cairo_format_t format) -{ - cairo_xlib_font_t *priv; - cairo_xlib_font_glyphset_t *info; - int glyphset_index; - - glyphset_index = _cairo_xlib_get_glyphset_index_for_format (format); - - priv = _cairo_xlib_font_get (display, font); - if (priv == NULL) { - priv = _cairo_xlib_font_create (display, font); - if (priv == NULL) - return NULL; - } - - info = &priv->glyphset[glyphset_index]; - if (info->glyphset == None) { - info->xrender_format = - _cairo_xlib_display_get_xrender_format (display, info->format); - info->glyphset = XRenderCreateGlyphSet (display->display, - info->xrender_format); - } - - return info; -} - -static cairo_bool_t -has_pending_free_glyph (cairo_xlib_font_glyphset_t *info, - unsigned long glyph_index) -{ - struct _cairo_xlib_font_glyphset_free_glyphs *to_free; - int i; - - to_free = &info->to_free; - for (i = 0; i < to_free->count; i++) { - if (to_free->indices[i] == glyph_index) { - to_free->count--; - memmove (&to_free->indices[i], - &to_free->indices[i+1], - (to_free->count - i) * sizeof (to_free->indices[0])); - return TRUE; - } - } - - return FALSE; -} - -static cairo_xlib_font_glyphset_t * -find_pending_free_glyph (cairo_xlib_display_t *display, - cairo_scaled_font_t *font, - unsigned long glyph_index, - cairo_image_surface_t *surface) -{ - cairo_xlib_font_t *priv; - int i; - - priv = _cairo_xlib_font_get (display, font); - if (priv == NULL) - return NULL; - - if (surface != NULL) { - i = _cairo_xlib_get_glyphset_index_for_format (surface->format); - if (has_pending_free_glyph (&priv->glyphset[i], glyph_index)) - return &priv->glyphset[i]; - } else { - for (i = 0; i < NUM_GLYPHSETS; i++) { - if (has_pending_free_glyph (&priv->glyphset[i], glyph_index)) - return &priv->glyphset[i]; - } - } - - return NULL; -} - -static cairo_status_t -_cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display, - cairo_scaled_font_t *font, - cairo_scaled_glyph_t **pscaled_glyph) -{ - XGlyphInfo glyph_info; - unsigned long glyph_index; - unsigned char *data; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - cairo_scaled_glyph_t *glyph = *pscaled_glyph; - cairo_image_surface_t *glyph_surface = glyph->surface; - cairo_bool_t already_had_glyph_surface; - cairo_xlib_font_glyphset_t *info; - - glyph_index = _cairo_scaled_glyph_index (glyph); - - /* check to see if we have a pending XRenderFreeGlyph for this glyph */ - info = find_pending_free_glyph (display, font, glyph_index, glyph_surface); - if (info != NULL) - return _cairo_xlib_glyph_attach (display, glyph, info); - - if (glyph_surface == NULL) { - status = _cairo_scaled_glyph_lookup (font, - glyph_index, - CAIRO_SCALED_GLYPH_INFO_METRICS | - CAIRO_SCALED_GLYPH_INFO_SURFACE, - pscaled_glyph); - if (unlikely (status)) - return status; - - glyph = *pscaled_glyph; - glyph_surface = glyph->surface; - already_had_glyph_surface = FALSE; - } else { - already_had_glyph_surface = TRUE; - } - - info = _cairo_xlib_font_get_glyphset_info_for_format (display, font, - glyph_surface->format); - -#if 0 - /* If the glyph surface has zero height or width, we create - * a clear 1x1 surface, to avoid various X server bugs. - */ - if (glyph_surface->width == 0 || glyph_surface->height == 0) { - cairo_surface_t *tmp_surface; - - tmp_surface = cairo_image_surface_create (info->format, 1, 1); - status = tmp_surface->status; - if (unlikely (status)) - goto BAIL; - - tmp_surface->device_transform = glyph_surface->base.device_transform; - tmp_surface->device_transform_inverse = glyph_surface->base.device_transform_inverse; - - glyph_surface = (cairo_image_surface_t *) tmp_surface; - } -#endif - - /* If the glyph format does not match the font format, then we - * create a temporary surface for the glyph image with the font's - * format. - */ - if (glyph_surface->format != info->format) { - cairo_surface_pattern_t pattern; - cairo_surface_t *tmp_surface; - - tmp_surface = cairo_image_surface_create (info->format, - glyph_surface->width, - glyph_surface->height); - status = tmp_surface->status; - if (unlikely (status)) - goto BAIL; - - tmp_surface->device_transform = glyph_surface->base.device_transform; - tmp_surface->device_transform_inverse = glyph_surface->base.device_transform_inverse; - - _cairo_pattern_init_for_surface (&pattern, &glyph_surface->base); - status = _cairo_surface_paint (tmp_surface, - CAIRO_OPERATOR_SOURCE, &pattern.base, - NULL); - _cairo_pattern_fini (&pattern.base); - - glyph_surface = (cairo_image_surface_t *) tmp_surface; - - if (unlikely (status)) - goto BAIL; - } - - /* XXX: FRAGILE: We're ignore device_transform scaling here. A bug? */ - glyph_info.x = _cairo_lround (glyph_surface->base.device_transform.x0); - glyph_info.y = _cairo_lround (glyph_surface->base.device_transform.y0); - glyph_info.width = glyph_surface->width; - glyph_info.height = glyph_surface->height; - glyph_info.xOff = glyph->x_advance; - glyph_info.yOff = glyph->y_advance; - - data = glyph_surface->data; - - /* flip formats around */ - switch (_cairo_xlib_get_glyphset_index_for_format (glyph->surface->format)) { - case GLYPHSET_INDEX_A1: - /* local bitmaps are always stored with bit == byte */ - if (_cairo_is_little_endian() != (BitmapBitOrder (display->display) == LSBFirst)) { - int c = glyph_surface->stride * glyph_surface->height; - unsigned char *d; - unsigned char *new, *n; - - if (c == 0) - break; - - new = malloc (c); - if (!new) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - n = new; - d = data; - do { - char b = *d++; - b = ((b << 1) & 0xaa) | ((b >> 1) & 0x55); - b = ((b << 2) & 0xcc) | ((b >> 2) & 0x33); - b = ((b << 4) & 0xf0) | ((b >> 4) & 0x0f); - *n++ = b; - } while (--c); - data = new; - } - break; - case GLYPHSET_INDEX_A8: - break; - case GLYPHSET_INDEX_ARGB32: - if (_cairo_is_little_endian() != (ImageByteOrder (display->display) == LSBFirst)) { - unsigned int c = glyph_surface->stride * glyph_surface->height / 4; - const uint32_t *d; - uint32_t *new, *n; - - if (c == 0) - break; - - new = malloc (4 * c); - if (unlikely (new == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - n = new; - d = (uint32_t *) data; - do { - *n++ = bswap_32 (*d); - d++; - } while (--c); - data = (uint8_t *) new; - } - break; - default: - ASSERT_NOT_REACHED; - break; - } - /* XXX assume X server wants pixman padding. Xft assumes this as well */ - - XRenderAddGlyphs (display->display, info->glyphset, - &glyph_index, &glyph_info, 1, - (char *) data, - glyph_surface->stride * glyph_surface->height); - - if (data != glyph_surface->data) - free (data); - - status = _cairo_xlib_glyph_attach (display, glyph, info); - - BAIL: - if (glyph_surface != glyph->surface) - cairo_surface_destroy (&glyph_surface->base); - - /* if the scaled glyph didn't already have a surface attached - * to it, release the created surface now that we have it - * uploaded to the X server. If the surface has already been - * there (eg. because image backend requested it), leave it in - * the cache - */ - if (!already_had_glyph_surface) - _cairo_scaled_glyph_set_surface (glyph, font, NULL); - - return status; -} - -typedef void (*cairo_xrender_composite_text_func_t) - (Display *dpy, - int op, - Picture src, - Picture dst, - _Xconst XRenderPictFormat *maskFormat, - int xSrc, - int ySrc, - int xDst, - int yDst, - _Xconst XGlyphElt8 *elts, - int nelt); - -/* Build a struct of the same size of #cairo_glyph_t that can be used both as - * an input glyph with double coordinates, and as "working" glyph with - * integer from-current-point offsets. */ -typedef union { - cairo_glyph_t d; - unsigned long index; - struct { - unsigned long index; - int x; - int y; - } i; -} cairo_xlib_glyph_t; - -/* compile-time assert that #cairo_xlib_glyph_t is the same size as #cairo_glyph_t */ -COMPILE_TIME_ASSERT (sizeof (cairo_xlib_glyph_t) == sizeof (cairo_glyph_t)); - -/* Start a new element for the first glyph, - * or for any glyph that has unexpected position, - * or if current element has too many glyphs - * (Xrender limits each element to 252 glyphs, we limit them to 128) - * - * These same conditions need to be mirrored between - * _cairo_xlib_surface_emit_glyphs and _emit_glyph_chunks - */ -#define _start_new_glyph_elt(count, glyph) \ - (((count) & 127) == 0 || (glyph)->i.x || (glyph)->i.y) - -static cairo_status_t -_emit_glyphs_chunk (cairo_xlib_display_t *display, - cairo_xlib_surface_t *dst, - int dst_x, int dst_y, - cairo_xlib_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *font, - cairo_bool_t use_mask, - cairo_operator_t op, - cairo_xlib_source_t *src, - int src_x, int src_y, - /* info for this chunk */ - int num_elts, - int width, - cairo_xlib_font_glyphset_t *info) -{ - /* Which XRenderCompositeText function to use */ - cairo_xrender_composite_text_func_t composite_text_func; - int size; - - /* Element buffer stuff */ - XGlyphElt8 *elts; - XGlyphElt8 stack_elts[CAIRO_STACK_ARRAY_LENGTH (XGlyphElt8)]; - - /* Reuse the input glyph array for output char generation */ - char *char8 = (char *) glyphs; - unsigned short *char16 = (unsigned short *) glyphs; - unsigned int *char32 = (unsigned int *) glyphs; - - int i; - int nelt; /* Element index */ - int n; /* Num output glyphs in current element */ - int j; /* Num output glyphs so far */ - - switch (width) { - case 1: - /* don't cast the 8-variant, to catch possible mismatches */ - composite_text_func = XRenderCompositeText8; - size = sizeof (char); - break; - case 2: - composite_text_func = (cairo_xrender_composite_text_func_t) XRenderCompositeText16; - size = sizeof (unsigned short); - break; - default: - case 4: - composite_text_func = (cairo_xrender_composite_text_func_t) XRenderCompositeText32; - size = sizeof (unsigned int); - } - - /* Allocate element array */ - if (num_elts <= ARRAY_LENGTH (stack_elts)) { - elts = stack_elts; - } else { - elts = _cairo_malloc_ab (num_elts, sizeof (XGlyphElt8)); - if (unlikely (elts == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* Fill them in */ - nelt = 0; - n = 0; - j = 0; - for (i = 0; i < num_glyphs; i++) { - /* Start a new element for first output glyph, - * or for any glyph that has unexpected position, - * or if current element has too many glyphs. - * - * These same conditions are mirrored in _cairo_xlib_surface_emit_glyphs() - */ - if (_start_new_glyph_elt (j, &glyphs[i])) { - if (j) { - elts[nelt].nchars = n; - nelt++; - n = 0; - } - elts[nelt].chars = char8 + size * j; - elts[nelt].glyphset = info->glyphset; - elts[nelt].xOff = glyphs[i].i.x; - elts[nelt].yOff = glyphs[i].i.y; - } - - switch (width) { - case 1: char8 [j] = (char) glyphs[i].index; break; - case 2: char16[j] = (unsigned short) glyphs[i].index; break; - default: - case 4: char32[j] = (unsigned int) glyphs[i].index; break; - } - - n++; - j++; - } - - if (n) { - elts[nelt].nchars = n; - nelt++; - } - - /* Check that we agree with _cairo_xlib_surface_emit_glyphs() on the - * expected number of xGlyphElts. */ - assert (nelt == num_elts); - - composite_text_func (display->display, op, - src->picture, - dst->picture, - use_mask ? info->xrender_format : NULL, - src_x + elts[0].xOff + dst_x, - src_y + elts[0].yOff + dst_y, - elts[0].xOff, elts[0].yOff, - (XGlyphElt8 *) elts, nelt); - - if (elts != stack_elts) - free (elts); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -check_composite_glyphs (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *font, - cairo_glyph_t *glyphs, - int *num_glyphs) -{ - cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)extents->surface; - cairo_xlib_display_t *display = dst->display; - int max_request_size, size; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (! CAIRO_RENDER_SUPPORTS_OPERATOR (display, extents->op)) - return CAIRO_INT_STATUS_UNSUPPORTED; - - /* The glyph coordinates must be representable in an int16_t. - * When possible, they will be expressed as an offset from the - * previous glyph, otherwise they will be an offset from the - * surface origin. If we can't guarantee this to be possible, - * fallback. - */ - if (extents->bounded.x + extents->bounded.width > INT16_MAX || - extents->bounded.y + extents->bounded.height> INT16_MAX || - extents->bounded.x < INT16_MIN || - extents->bounded.y < INT16_MIN) - { - return CAIRO_INT_STATUS_UNSUPPORTED; - } - - /* Approximate the size of the largest glyph and fallback if we can not - * upload it to the xserver. - */ - size = ceil (font->max_scale); - size = 4 * size * size; - max_request_size = (XExtendedMaxRequestSize (display->display) ? XExtendedMaxRequestSize (display->display) - : XMaxRequestSize (display->display)) * 4 - - sz_xRenderAddGlyphsReq - - sz_xGlyphInfo - - 8; - if (size >= max_request_size) - return CAIRO_INT_STATUS_UNSUPPORTED; - - return CAIRO_STATUS_SUCCESS; -} - -/* sz_xGlyphtElt required alignment to a 32-bit boundary, so ensure we have - * enough room for padding */ -#define _cairo_sz_xGlyphElt (sz_xGlyphElt + 4) - -static cairo_int_status_t -composite_glyphs (void *surface, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - cairo_xlib_surface_t *dst = surface; - cairo_xlib_glyph_t *glyphs = (cairo_xlib_glyph_t *)info->glyphs; - cairo_xlib_source_t *src = (cairo_xlib_source_t *)_src; - cairo_xlib_display_t *display = dst->display; - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - cairo_scaled_glyph_t *glyph; - cairo_fixed_t x = dst_x, y = dst_y; - cairo_xlib_font_glyphset_t *glyphset = NULL, *this_glyphset_info; - - unsigned long max_index = 0; - int width = 1; - int num_elts = 0; - int num_out_glyphs = 0; - int num_glyphs = info->num_glyphs; - - int max_request_size = XMaxRequestSize (display->display) * 4 - - MAX (sz_xRenderCompositeGlyphs8Req, - MAX(sz_xRenderCompositeGlyphs16Req, - sz_xRenderCompositeGlyphs32Req)); - int request_size = 0; - int i; - - op = _render_operator (op), - _cairo_xlib_surface_ensure_picture (dst); - for (i = 0; i < num_glyphs; i++) { - int this_x, this_y; - int old_width; - - status = _cairo_scaled_glyph_lookup (info->font, - glyphs[i].index, - CAIRO_SCALED_GLYPH_INFO_METRICS, - &glyph); - if (unlikely (status)) - return status; - - this_x = _cairo_lround (glyphs[i].d.x); - this_y = _cairo_lround (glyphs[i].d.y); - - /* Send unsent glyphs to the server */ - if (glyph->dev_private_key != display) { - status = _cairo_xlib_surface_add_glyph (display, info->font, &glyph); - if (unlikely (status)) - return status; - } - - this_glyphset_info = glyph->dev_private; - if (!glyphset) - glyphset = this_glyphset_info; - - /* The invariant here is that we can always flush the glyphs - * accumulated before this one, using old_width, and they - * would fit in the request. - */ - old_width = width; - - /* Update max glyph index */ - if (glyphs[i].index > max_index) { - max_index = glyphs[i].index; - if (max_index >= 65536) - width = 4; - else if (max_index >= 256) - width = 2; - if (width != old_width) - request_size += (width - old_width) * num_out_glyphs; - } - - /* If we will pass the max request size by adding this glyph, - * flush current glyphs. Note that we account for a - * possible element being added below. - * - * Also flush if changing glyphsets, as Xrender limits one mask - * format per request, so we can either break up, or use a - * wide-enough mask format. We do the former. One reason to - * prefer the latter is the fact that Xserver ADDs all glyphs - * to the mask first, and then composes that to final surface, - * though it's not a big deal. - * - * If the glyph has a coordinate which cannot be represented - * as a 16-bit offset from the previous glyph, flush the - * current chunk. The current glyph will be the first one in - * the next chunk, thus its coordinates will be an offset from - * the destination origin. This offset is guaranteed to be - * representable as 16-bit offset (otherwise we would have - * fallen back). - */ - if (request_size + width > max_request_size - _cairo_sz_xGlyphElt || - this_x - x > INT16_MAX || this_x - x < INT16_MIN || - this_y - y > INT16_MAX || this_y - y < INT16_MIN || - (this_glyphset_info != glyphset)) { - status = _emit_glyphs_chunk (display, dst, dst_x, dst_y, - glyphs, i, info->font, info->use_mask, - op, src, src_x, src_y, - num_elts, old_width, glyphset); - if (unlikely (status)) - return status; - - glyphs += i; - num_glyphs -= i; - i = 0; - max_index = glyphs[i].index; - width = max_index < 256 ? 1 : max_index < 65536 ? 2 : 4; - request_size = 0; - num_elts = 0; - num_out_glyphs = 0; - x = y = 0; - glyphset = this_glyphset_info; - } - - /* Convert absolute glyph position to relative-to-current-point - * position */ - glyphs[i].i.x = this_x - x; - glyphs[i].i.y = this_y - y; - - /* Start a new element for the first glyph, - * or for any glyph that has unexpected position, - * or if current element has too many glyphs. - * - * These same conditions are mirrored in _emit_glyphs_chunk(). - */ - if (_start_new_glyph_elt (num_out_glyphs, &glyphs[i])) { - num_elts++; - request_size += _cairo_sz_xGlyphElt; - } - - /* adjust current-position */ - x = this_x + glyph->x_advance; - y = this_y + glyph->y_advance; - - num_out_glyphs++; - request_size += width; - } - - if (num_elts) { - status = _emit_glyphs_chunk (display, dst, dst_x, dst_y, - glyphs, i, info->font, info->use_mask, - op, src, src_x, src_y, - num_elts, width, glyphset); - } - - return status; -} - -const cairo_compositor_t * -_cairo_xlib_mask_compositor_get (void) -{ - static cairo_mask_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_mask_compositor_init (&compositor, - _cairo_xlib_fallback_compositor_get ()); - - compositor.acquire = acquire; - compositor.release = release; - compositor.set_clip_region = set_clip_region; - compositor.pattern_to_surface = _cairo_xlib_source_create_for_pattern; - compositor.draw_image_boxes = draw_image_boxes; - compositor.fill_rectangles = fill_rectangles; - compositor.fill_boxes = fill_boxes; - compositor.copy_boxes = copy_boxes; - compositor.check_composite = check_composite; - compositor.composite = composite; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - compositor.check_composite_glyphs = check_composite_glyphs; - compositor.composite_glyphs = composite_glyphs; - } - - return &compositor.base; -} - -#define CAIRO_FIXED_16_16_MIN -32768 -#define CAIRO_FIXED_16_16_MAX 32767 - -static cairo_bool_t -line_exceeds_16_16 (const cairo_line_t *line) -{ - return - line->p1.x < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || - line->p1.x > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX) || - line->p2.x < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || - line->p2.x > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX) || - line->p1.y < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || - line->p1.y > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX) || - line->p2.y < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || - line->p2.y > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX); -} - -static void -project_line_x_onto_16_16 (const cairo_line_t *line, - cairo_fixed_t top, - cairo_fixed_t bottom, - XLineFixed *out) -{ - cairo_point_double_t p1, p2; - double m; - - p1.x = _cairo_fixed_to_double (line->p1.x); - p1.y = _cairo_fixed_to_double (line->p1.y); - - p2.x = _cairo_fixed_to_double (line->p2.x); - p2.y = _cairo_fixed_to_double (line->p2.y); - - m = (p2.x - p1.x) / (p2.y - p1.y); - out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); - out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); -} -#if 0 -static cairo_int_status_T -check_composite_trapezoids () -{ - operation = _categorize_composite_operation (dst, op, pattern, TRUE); - if (operation == DO_UNSUPPORTED) - return UNSUPPORTED ("unsupported operation"); - - operation = _recategorize_composite_operation (dst, op, src, - &attributes, TRUE); - if (operation == DO_UNSUPPORTED) { - status = UNSUPPORTED ("unsupported operation"); - goto BAIL; - } - -} -#endif - -static cairo_int_status_t -composite_traps (void *abstract_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_traps_t *traps) -{ - cairo_xlib_surface_t *dst = abstract_dst; - cairo_xlib_display_t *display = dst->display; - cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; - XRenderPictFormat *pict_format; - XTrapezoid xtraps_stack[CAIRO_STACK_ARRAY_LENGTH (XTrapezoid)]; - XTrapezoid *xtraps = xtraps_stack; - int dx, dy; - int i; - - //X_DEBUG ((display->display, "composite_trapezoids (dst=%x)", (unsigned int) dst->drawable)); - - if (dst->base.is_clear && - (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD)) - { - op = CAIRO_OPERATOR_SOURCE; - } - - pict_format = - _cairo_xlib_display_get_xrender_format (display, - antialias == CAIRO_ANTIALIAS_NONE ? CAIRO_FORMAT_A1 : CAIRO_FORMAT_A8); - - if (traps->num_traps > ARRAY_LENGTH (xtraps_stack)) { - xtraps = _cairo_malloc_ab (traps->num_traps, sizeof (XTrapezoid)); - if (unlikely (xtraps == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - dx = -dst_x << 16; - dy = -dst_y << 16; - for (i = 0; i < traps->num_traps; i++) { - cairo_trapezoid_t *t = &traps->traps[i]; - - /* top/bottom will be clamped to surface bounds */ - xtraps[i].top = _cairo_fixed_to_16_16(t->top) + dy; - xtraps[i].bottom = _cairo_fixed_to_16_16(t->bottom) + dy; - - /* However, all the other coordinates will have been left untouched so - * as not to introduce numerical error. Recompute them if they - * exceed the 16.16 limits. - */ - if (unlikely (line_exceeds_16_16 (&t->left))) { - project_line_x_onto_16_16 (&t->left, t->top, t->bottom, - &xtraps[i].left); - xtraps[i].left.p1.x += dx; - xtraps[i].left.p2.x += dx; - xtraps[i].left.p1.y = xtraps[i].top; - xtraps[i].left.p2.y = xtraps[i].bottom; - } else { - xtraps[i].left.p1.x = _cairo_fixed_to_16_16(t->left.p1.x) + dx; - xtraps[i].left.p1.y = _cairo_fixed_to_16_16(t->left.p1.y) + dy; - xtraps[i].left.p2.x = _cairo_fixed_to_16_16(t->left.p2.x) + dx; - xtraps[i].left.p2.y = _cairo_fixed_to_16_16(t->left.p2.y) + dy; - } - - if (unlikely (line_exceeds_16_16 (&t->right))) { - project_line_x_onto_16_16 (&t->right, t->top, t->bottom, - &xtraps[i].right); - xtraps[i].right.p1.x += dx; - xtraps[i].right.p2.x += dx; - xtraps[i].right.p1.y = xtraps[i].top; - xtraps[i].right.p2.y = xtraps[i].bottom; - } else { - xtraps[i].right.p1.x = _cairo_fixed_to_16_16(t->right.p1.x) + dx; - xtraps[i].right.p1.y = _cairo_fixed_to_16_16(t->right.p1.y) + dy; - xtraps[i].right.p2.x = _cairo_fixed_to_16_16(t->right.p2.x) + dx; - xtraps[i].right.p2.y = _cairo_fixed_to_16_16(t->right.p2.y) + dy; - } - } - - if (xtraps[0].left.p1.y < xtraps[0].left.p2.y) { - src_x += _cairo_fixed_16_16_floor (xtraps[0].left.p1.x); - src_y += _cairo_fixed_16_16_floor (xtraps[0].left.p1.y); - } else { - src_x += _cairo_fixed_16_16_floor (xtraps[0].left.p2.x); - src_y += _cairo_fixed_16_16_floor (xtraps[0].left.p2.y); - } - src_x += dst_x; - src_y += dst_y; - - _cairo_xlib_surface_ensure_picture (dst); - _cairo_xlib_surface_set_precision (dst, antialias); - XRenderCompositeTrapezoids (dst->dpy, - _render_operator (op), - src->picture, dst->picture, - pict_format, - src_x, src_y, - xtraps, traps->num_traps); - - if (xtraps != xtraps_stack) - free (xtraps); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_tristrip (void *abstract_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_tristrip_t *strip) -{ - cairo_xlib_surface_t *dst = abstract_dst; - cairo_xlib_display_t *display = dst->display; - cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; - XRenderPictFormat *pict_format; - XPointFixed points_stack[CAIRO_STACK_ARRAY_LENGTH (XPointFixed)]; - XPointFixed *points = points_stack; - int dx, dy; - int i; - - //X_DEBUG ((display->display, "composite_trapezoids (dst=%x)", (unsigned int) dst->drawable)); - - pict_format = - _cairo_xlib_display_get_xrender_format (display, - antialias == CAIRO_ANTIALIAS_NONE ? CAIRO_FORMAT_A1 : CAIRO_FORMAT_A8); - - if (strip->num_points > ARRAY_LENGTH (points_stack)) { - points = _cairo_malloc_ab (strip->num_points, sizeof (XPointFixed)); - if (unlikely (points == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - dx = -dst_x << 16; - dy = -dst_y << 16; - for (i = 0; i < strip->num_points; i++) { - cairo_point_t *p = &strip->points[i]; - - points[i].x = _cairo_fixed_to_16_16(p->x) + dx; - points[i].y = _cairo_fixed_to_16_16(p->y) + dy; - } - - src_x += _cairo_fixed_16_16_floor (points[0].x) + dst_x; - src_y += _cairo_fixed_16_16_floor (points[0].y) + dst_y; - - _cairo_xlib_surface_ensure_picture (dst); - _cairo_xlib_surface_set_precision (dst, antialias); - XRenderCompositeTriStrip (dst->dpy, - _render_operator (op), - src->picture, dst->picture, - pict_format, - src_x, src_y, - points, strip->num_points); - - if (points != points_stack) - free (points); - - return CAIRO_STATUS_SUCCESS; -} - -const cairo_compositor_t * -_cairo_xlib_traps_compositor_get (void) -{ - static cairo_traps_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_traps_compositor_init (&compositor, - _cairo_xlib_mask_compositor_get ()); - - compositor.acquire = acquire; - compositor.release = release; - compositor.set_clip_region = set_clip_region; - compositor.pattern_to_surface = _cairo_xlib_source_create_for_pattern; - compositor.draw_image_boxes = draw_image_boxes; - compositor.copy_boxes = copy_boxes; - compositor.fill_boxes = fill_boxes; - compositor.check_composite = check_composite; - compositor.composite = composite; - compositor.lerp = lerp; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - //compositor.check_composite_traps = check_composite_traps; - compositor.composite_traps = composite_traps; - //compositor.check_composite_tristrip = check_composite_tristrip; - compositor.composite_tristrip = composite_tristrip; - compositor.check_composite_glyphs = check_composite_glyphs; - compositor.composite_glyphs = composite_glyphs; - } - - return &compositor.base; -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-screen.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-screen.c deleted file mode 100644 index 57beeaab426..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-screen.c +++ /dev/null @@ -1,467 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Partially on code from xftdpy.c - * - * Copyright © 2000 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" -#include "cairo-xlib-xrender-private.h" - -#include "cairo-xlib-surface-private.h" -#include "cairo-error-private.h" -#include "cairo-list-inline.h" - -#include "cairo-fontconfig-private.h" - -static int -parse_boolean (const char *v) -{ - char c0, c1; - - c0 = *v; - if (c0 == 't' || c0 == 'T' || c0 == 'y' || c0 == 'Y' || c0 == '1') - return 1; - if (c0 == 'f' || c0 == 'F' || c0 == 'n' || c0 == 'N' || c0 == '0') - return 0; - if (c0 == 'o') - { - c1 = v[1]; - if (c1 == 'n' || c1 == 'N') - return 1; - if (c1 == 'f' || c1 == 'F') - return 0; - } - - return -1; -} - -static cairo_bool_t -get_boolean_default (Display *dpy, - const char *option, - cairo_bool_t *value) -{ - char *v; - int i; - - v = XGetDefault (dpy, "Xft", option); - if (v) { - i = parse_boolean (v); - if (i >= 0) { - *value = i; - return TRUE; - } - } - - return FALSE; -} - -static cairo_bool_t -get_integer_default (Display *dpy, - const char *option, - int *value) -{ - char *v, *e; - - v = XGetDefault (dpy, "Xft", option); - if (v) { -#if CAIRO_HAS_FC_FONT - if (FcNameConstant ((FcChar8 *) v, value)) - return TRUE; -#endif - - *value = strtol (v, &e, 0); - if (e != v) - return TRUE; - } - - return FALSE; -} - -static void -_cairo_xlib_init_screen_font_options (Display *dpy, - cairo_xlib_screen_t *info) -{ - cairo_bool_t xft_hinting; - cairo_bool_t xft_antialias; - int xft_hintstyle; - int xft_rgba; - int xft_lcdfilter; - cairo_antialias_t antialias; - cairo_subpixel_order_t subpixel_order; - cairo_lcd_filter_t lcd_filter; - cairo_hint_style_t hint_style; - - if (!get_boolean_default (dpy, "antialias", &xft_antialias)) - xft_antialias = TRUE; - - if (!get_integer_default (dpy, "lcdfilter", &xft_lcdfilter)) { - /* -1 is an non-existant Fontconfig constant used to differentiate - * the case when no lcdfilter property is available. - */ - xft_lcdfilter = -1; - } - - if (!get_boolean_default (dpy, "hinting", &xft_hinting)) - xft_hinting = TRUE; - - if (!get_integer_default (dpy, "hintstyle", &xft_hintstyle)) - xft_hintstyle = FC_HINT_FULL; - - if (!get_integer_default (dpy, "rgba", &xft_rgba)) - { - cairo_xlib_display_t *display = (cairo_xlib_display_t *) info->device; - - xft_rgba = FC_RGBA_UNKNOWN; - -#if RENDER_MAJOR > 0 || RENDER_MINOR >= 6 - if (display->render_major > 0 || display->render_minor >= 6) { - int render_order = XRenderQuerySubpixelOrder (dpy, - XScreenNumberOfScreen (info->screen)); - - switch (render_order) { - default: - case SubPixelUnknown: - xft_rgba = FC_RGBA_UNKNOWN; - break; - case SubPixelHorizontalRGB: - xft_rgba = FC_RGBA_RGB; - break; - case SubPixelHorizontalBGR: - xft_rgba = FC_RGBA_BGR; - break; - case SubPixelVerticalRGB: - xft_rgba = FC_RGBA_VRGB; - break; - case SubPixelVerticalBGR: - xft_rgba = FC_RGBA_VBGR; - break; - case SubPixelNone: - xft_rgba = FC_RGBA_NONE; - break; - } - } -#endif - } - - if (xft_hinting) { - switch (xft_hintstyle) { - case FC_HINT_NONE: - hint_style = CAIRO_HINT_STYLE_NONE; - break; - case FC_HINT_SLIGHT: - hint_style = CAIRO_HINT_STYLE_SLIGHT; - break; - case FC_HINT_MEDIUM: - hint_style = CAIRO_HINT_STYLE_MEDIUM; - break; - case FC_HINT_FULL: - hint_style = CAIRO_HINT_STYLE_FULL; - break; - default: - hint_style = CAIRO_HINT_STYLE_DEFAULT; - } - } else { - hint_style = CAIRO_HINT_STYLE_NONE; - } - - switch (xft_rgba) { - case FC_RGBA_RGB: - subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; - break; - case FC_RGBA_BGR: - subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; - break; - case FC_RGBA_VRGB: - subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; - break; - case FC_RGBA_VBGR: - subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; - break; - case FC_RGBA_UNKNOWN: - case FC_RGBA_NONE: - default: - subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; - } - - switch (xft_lcdfilter) { - case FC_LCD_NONE: - lcd_filter = CAIRO_LCD_FILTER_NONE; - break; - case FC_LCD_DEFAULT: - lcd_filter = CAIRO_LCD_FILTER_FIR5; - break; - case FC_LCD_LIGHT: - lcd_filter = CAIRO_LCD_FILTER_FIR3; - break; - case FC_LCD_LEGACY: - lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL; - break; - default: - lcd_filter = CAIRO_LCD_FILTER_DEFAULT; - break; - } - - if (xft_antialias) { - if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT) - antialias = CAIRO_ANTIALIAS_GRAY; - else - antialias = CAIRO_ANTIALIAS_SUBPIXEL; - } else { - antialias = CAIRO_ANTIALIAS_NONE; - } - - cairo_font_options_set_hint_style (&info->font_options, hint_style); - cairo_font_options_set_antialias (&info->font_options, antialias); - cairo_font_options_set_subpixel_order (&info->font_options, subpixel_order); - _cairo_font_options_set_lcd_filter (&info->font_options, lcd_filter); - cairo_font_options_set_hint_metrics (&info->font_options, CAIRO_HINT_METRICS_ON); -} - -void -_cairo_xlib_screen_destroy (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info) -{ - Display *dpy; - int i; - - dpy = display->display; - - while (! cairo_list_is_empty (&info->surfaces)) { - cairo_xlib_surface_t *surface; - - surface = cairo_list_first_entry (&info->surfaces, - cairo_xlib_surface_t, - link); - cairo_surface_finish (&surface->base); - } - - for (i = 0; i < ARRAY_LENGTH (info->gc); i++) { - if (info->gc_depths[i] != 0) { - XFreeGC (dpy, info->gc[i]); - info->gc_depths[i] = 0; - } - } - - while (! cairo_list_is_empty (&info->visuals)) { - _cairo_xlib_visual_info_destroy (cairo_list_first_entry (&info->visuals, - cairo_xlib_visual_info_t, - link)); - } - - cairo_list_del (&info->link); - - free (info); -} - -cairo_status_t -_cairo_xlib_screen_get (Display *dpy, - Screen *screen, - cairo_xlib_screen_t **out) -{ - cairo_xlib_display_t *display; - cairo_device_t *device; - cairo_xlib_screen_t *info; - cairo_status_t status; - - device = _cairo_xlib_device_create (dpy); - status = device->status; - if (unlikely (status)) - goto CLEANUP_DEVICE; - - status = _cairo_xlib_display_acquire (device, &display); - if (unlikely (status)) - goto CLEANUP_DEVICE; - - info = _cairo_xlib_display_get_screen (display, screen); - if (info != NULL) { - *out = info; - goto CLEANUP_DISPLAY; - } - - info = malloc (sizeof (cairo_xlib_screen_t)); - if (unlikely (info == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto CLEANUP_DISPLAY; - } - - info->device = device; - info->screen = screen; - info->has_font_options = FALSE; - memset (info->gc_depths, 0, sizeof (info->gc_depths)); - memset (info->gc, 0, sizeof (info->gc)); - - cairo_list_init (&info->surfaces); - cairo_list_init (&info->visuals); - cairo_list_add (&info->link, &display->screens); - - *out = info; - - CLEANUP_DISPLAY: - cairo_device_release (&display->base); - - CLEANUP_DEVICE: - cairo_device_destroy (device); - return status; -} - -GC -_cairo_xlib_screen_get_gc (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info, - int depth, - Drawable drawable) -{ - GC gc = NULL; - int i; - - for (i = 0; i < ARRAY_LENGTH (info->gc); i++) { - if (info->gc_depths[i] == depth) { - info->gc_depths[i] = 0; - gc = info->gc[i]; - break; - } - } - - if (gc == NULL) { - XGCValues gcv; - - gcv.graphics_exposures = False; - gcv.fill_style = FillTiled; - gc = XCreateGC (display->display, - drawable, - GCGraphicsExposures | GCFillStyle, &gcv); - } - - return gc; -} - -void -_cairo_xlib_screen_put_gc (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info, - int depth, - GC gc) -{ - int i; - - for (i = 0; i < ARRAY_LENGTH (info->gc); i++) { - if (info->gc_depths[i] == 0) - break; - } - - if (i == ARRAY_LENGTH (info->gc)) { - /* perform random substitution to ensure fair caching over depths */ - i = rand () % ARRAY_LENGTH (info->gc); - XFreeGC(display->display, info->gc[i]); - } - - info->gc[i] = gc; - info->gc_depths[i] = depth; -} - -cairo_status_t -_cairo_xlib_screen_get_visual_info (cairo_xlib_display_t *display, - cairo_xlib_screen_t *info, - Visual *v, - cairo_xlib_visual_info_t **out) -{ - cairo_xlib_visual_info_t *visual; - cairo_status_t status; - - cairo_list_foreach_entry (visual, - cairo_xlib_visual_info_t, - &info->visuals, - link) - { - if (visual->visualid == v->visualid) { - *out = visual; - return CAIRO_STATUS_SUCCESS; - } - } - - status = _cairo_xlib_visual_info_create (display->display, - XScreenNumberOfScreen (info->screen), - v->visualid, - &visual); - if (unlikely (status)) - return status; - - cairo_list_add (&visual->link, &info->visuals); - *out = visual; - return CAIRO_STATUS_SUCCESS; -} - -cairo_font_options_t * -_cairo_xlib_screen_get_font_options (cairo_xlib_screen_t *info) -{ - if (! info->has_font_options) { - _cairo_font_options_init_default (&info->font_options); - _cairo_font_options_set_round_glyph_positions (&info->font_options, CAIRO_ROUND_GLYPH_POS_ON); - - if (info->screen != NULL) { - cairo_xlib_display_t *display; - - if (! _cairo_xlib_display_acquire (info->device, &display)) { - _cairo_xlib_init_screen_font_options (display->display, - info); - cairo_device_release (&display->base); - } - } - - info->has_font_options = TRUE; - } - - return &info->font_options; -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-source.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-source.c deleted file mode 100644 index 1591f5874f6..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-source.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Behdad Esfahbod - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" -#include "cairo-xlib-surface-private.h" - -#include "cairo-error-private.h" -#include "cairo-image-surface-inline.h" -#include "cairo-paginated-private.h" -#include "cairo-pattern-inline.h" -#include "cairo-recording-surface-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-surface-offset-private.h" -#include "cairo-surface-observer-private.h" -#include "cairo-surface-snapshot-inline.h" -#include "cairo-surface-subsurface-inline.h" - -#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ - -static cairo_xlib_surface_t * -unwrap_source (const cairo_surface_pattern_t *pattern) -{ - cairo_rectangle_int_t limits; - return (cairo_xlib_surface_t *)_cairo_pattern_get_source (pattern, &limits); -} - -static cairo_status_t -_cairo_xlib_source_finish (void *abstract_surface) -{ - cairo_xlib_source_t *source = abstract_surface; - - XRenderFreePicture (source->dpy, source->picture); - if (source->pixmap) - XFreePixmap (source->dpy, source->pixmap); - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t cairo_xlib_source_backend = { - CAIRO_SURFACE_TYPE_XLIB, - _cairo_xlib_source_finish, - NULL, /* read-only wrapper */ -}; - -static cairo_status_t -_cairo_xlib_proxy_finish (void *abstract_surface) -{ - cairo_xlib_proxy_t *proxy = abstract_surface; - - _cairo_xlib_shm_surface_mark_active (proxy->owner); - XRenderFreePicture (proxy->source.dpy, proxy->source.picture); - if (proxy->source.pixmap) - XFreePixmap (proxy->source.dpy, proxy->source.pixmap); - cairo_surface_destroy (proxy->owner); - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t cairo_xlib_proxy_backend = { - CAIRO_SURFACE_TYPE_XLIB, - _cairo_xlib_proxy_finish, - NULL, /* read-only wrapper */ -}; - -static cairo_surface_t * -source (cairo_xlib_surface_t *dst, Picture picture, Pixmap pixmap) -{ - cairo_xlib_source_t *source; - - if (picture == None) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - source = malloc (sizeof (*source)); - if (unlikely (source == NULL)) { - XRenderFreePicture (dst->display->display, picture); - if (pixmap) - XFreePixmap (dst->display->display, pixmap); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - _cairo_surface_init (&source->base, - &cairo_xlib_source_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - /* The source exists only within an operation */ - source->picture = picture; - source->pixmap = pixmap; - source->dpy = dst->display->display; - - return &source->base; -} - -static uint32_t -hars_petruska_f54_1_random (void) -{ -#define rol(x,k) ((x << k) | (x >> (32-k))) - static uint32_t x; - return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; -#undef rol -} - -static const XTransform identity = { - { - { 1 << 16, 0x00000, 0x00000 }, - { 0x00000, 1 << 16, 0x00000 }, - { 0x00000, 0x00000, 1 << 16 }, - } -}; - -static cairo_bool_t -picture_set_matrix (cairo_xlib_display_t *display, - Picture picture, - const cairo_matrix_t *matrix, - cairo_filter_t filter, - double xc, - double yc, - int *x_offset, - int *y_offset) -{ - XTransform xtransform; - pixman_transform_t *pixman_transform; - cairo_int_status_t status; - - /* Casting between pixman_transform_t and XTransform is safe because - * they happen to be the exact same type. - */ - pixman_transform = (pixman_transform_t *) &xtransform; - status = _cairo_matrix_to_pixman_matrix_offset (matrix, filter, xc, yc, - pixman_transform, - x_offset, y_offset); - if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) - return TRUE; - if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) - return FALSE; - - if (memcmp (&xtransform, &identity, sizeof (XTransform)) == 0) - return TRUE; - - /* a late check in case we perturb the matrix too far */ - if (! CAIRO_RENDER_HAS_PICTURE_TRANSFORM (display)) - return FALSE; - - XRenderSetPictureTransform (display->display, picture, &xtransform); - return TRUE; -} - -static cairo_status_t -picture_set_filter (Display *dpy, - Picture picture, - cairo_filter_t filter) -{ - const char *render_filter; - - switch (filter) { - case CAIRO_FILTER_FAST: - render_filter = FilterFast; - break; - case CAIRO_FILTER_GOOD: - render_filter = FilterGood; - break; - case CAIRO_FILTER_BEST: - render_filter = FilterBest; - break; - case CAIRO_FILTER_NEAREST: - render_filter = FilterNearest; - break; - case CAIRO_FILTER_BILINEAR: - render_filter = FilterBilinear; - break; - case CAIRO_FILTER_GAUSSIAN: - /* XXX: The GAUSSIAN value has no implementation in cairo - * whatsoever, so it was really a mistake to have it in the - * API. We could fix this by officially deprecating it, or - * else inventing semantics and providing an actual - * implementation for it. */ - default: - render_filter = FilterBest; - break; - } - - XRenderSetPictureFilter (dpy, picture, (char *) render_filter, NULL, 0); - return CAIRO_STATUS_SUCCESS; -} - -static int -extend_to_repeat (cairo_extend_t extend) -{ - switch (extend) { - default: - ASSERT_NOT_REACHED; - case CAIRO_EXTEND_NONE: - return RepeatNone; - case CAIRO_EXTEND_REPEAT: - return RepeatNormal; - case CAIRO_EXTEND_REFLECT: - return RepeatReflect; - case CAIRO_EXTEND_PAD: - return RepeatPad; - } -} - -static cairo_bool_t -picture_set_properties (cairo_xlib_display_t *display, - Picture picture, - const cairo_pattern_t *pattern, - const cairo_matrix_t *matrix, - const cairo_rectangle_int_t *extents, - int *x_off, int *y_off) -{ - XRenderPictureAttributes pa; - int mask = 0; - - if (! picture_set_matrix (display, picture, matrix, pattern->filter, - extents->x + extents->width / 2, - extents->y + extents->height / 2, - x_off, y_off)) - return FALSE; - - picture_set_filter (display->display, picture, pattern->filter); - - if (pattern->has_component_alpha) { - pa.component_alpha = 1; - mask |= CPComponentAlpha; - } - - if (pattern->extend != CAIRO_EXTEND_NONE) { - pa.repeat = extend_to_repeat (pattern->extend); - mask |= CPRepeat; - } - - if (mask) - XRenderChangePicture (display->display, picture, mask, &pa); - - return TRUE; -} - -static cairo_surface_t * -render_pattern (cairo_xlib_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - int *src_x, int *src_y) -{ - Display *dpy = dst->display->display; - cairo_xlib_surface_t *src; - cairo_image_surface_t *image; - cairo_status_t status; - cairo_rectangle_int_t map_extents; - - src = (cairo_xlib_surface_t *) - _cairo_surface_create_scratch (&dst->base, - is_mask ? CAIRO_CONTENT_ALPHA : CAIRO_CONTENT_COLOR_ALPHA, - extents->width, - extents->height, - NULL); - if (src->base.type != CAIRO_SURFACE_TYPE_XLIB) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - map_extents = *extents; - map_extents.x = map_extents.y = 0; - - image = _cairo_surface_map_to_image (&src->base, &map_extents); - status = _cairo_surface_offset_paint (&image->base, extents->x, extents->y, - CAIRO_OPERATOR_SOURCE, pattern, - NULL); - status = _cairo_surface_unmap_image (&src->base, image); - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (status); - } - - status = _cairo_xlib_surface_put_shm (src); - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (status); - } - - src->picture = XRenderCreatePicture (dpy, - src->drawable, src->xrender_format, - 0, NULL); - - *src_x = -extents->x; - *src_y = -extents->y; - return &src->base; -} - -static cairo_surface_t * -gradient_source (cairo_xlib_surface_t *dst, - const cairo_gradient_pattern_t *gradient, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - int *src_x, int *src_y) -{ - cairo_xlib_display_t *display = dst->display; - cairo_matrix_t matrix = gradient->base.matrix; - char buf[CAIRO_STACK_BUFFER_SIZE]; - cairo_circle_double_t extremes[2]; - XFixed *stops; - XRenderColor *colors; - Picture picture; - unsigned int i, n_stops; - - /* The RENDER specification says that the inner circle has - * to be completely contained inside the outer one. */ - if (gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL && - ! _cairo_radial_pattern_focus_is_inside ((cairo_radial_pattern_t *) gradient)) - return render_pattern (dst, &gradient->base, is_mask, extents, src_x, src_y); - - assert (gradient->n_stops > 0); - n_stops = MAX (gradient->n_stops, 2); - - if (n_stops < sizeof (buf) / (sizeof (XFixed) + sizeof (XRenderColor))) - { - stops = (XFixed *) buf; - } - else - { - stops = - _cairo_malloc_ab (n_stops, - sizeof (XFixed) + sizeof (XRenderColor)); - if (unlikely (stops == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - colors = (XRenderColor *) (stops + n_stops); - for (i = 0; i < gradient->n_stops; i++) { - stops[i] = - _cairo_fixed_16_16_from_double (gradient->stops[i].offset); - - colors[i].red = gradient->stops[i].color.red_short; - colors[i].green = gradient->stops[i].color.green_short; - colors[i].blue = gradient->stops[i].color.blue_short; - colors[i].alpha = gradient->stops[i].color.alpha_short; - } - - /* RENDER does not support gradients with less than 2 - * stops. If a gradient has only a single stop, duplicate - * it to make RENDER happy. */ - if (gradient->n_stops == 1) { - stops[1] = - _cairo_fixed_16_16_from_double (gradient->stops[0].offset); - - colors[1].red = gradient->stops[0].color.red_short; - colors[1].green = gradient->stops[0].color.green_short; - colors[1].blue = gradient->stops[0].color.blue_short; - colors[1].alpha = gradient->stops[0].color.alpha_short; - } - -#if 0 - /* For some weird reason the X server is sometimes getting - * CreateGradient requests with bad length. So far I've only seen - * XRenderCreateLinearGradient request with 4 stops sometime end up - * with length field matching 0 stops at the server side. I've - * looked at the libXrender code and I can't see anything that - * could cause this behavior. However, for some reason having a - * XSync call here seems to avoid the issue so I'll keep it here - * until it's solved. - */ - XSync (display->display, False); -#endif - - _cairo_gradient_pattern_fit_to_range (gradient, PIXMAN_MAX_INT >> 1, &matrix, extremes); - - if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { - XLinearGradient grad; - - grad.p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); - grad.p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); - grad.p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); - grad.p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); - - picture = XRenderCreateLinearGradient (display->display, &grad, - stops, colors, - n_stops); - } else { - XRadialGradient grad; - - grad.inner.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); - grad.inner.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); - grad.inner.radius = _cairo_fixed_16_16_from_double (extremes[0].radius); - grad.outer.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); - grad.outer.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); - grad.outer.radius = _cairo_fixed_16_16_from_double (extremes[1].radius); - - picture = XRenderCreateRadialGradient (display->display, &grad, - stops, colors, - n_stops); - } - - if (stops != (XFixed *) buf) - free (stops); - - *src_x = *src_y = 0; - if (! picture_set_properties (display, picture, - &gradient->base, &gradient->base.matrix, - extents, - src_x, src_y)) { - XRenderFreePicture (display->display, picture); - return render_pattern (dst, &gradient->base, is_mask, extents, src_x, src_y); - } - - return source (dst, picture, None); -} - -static cairo_surface_t * -color_source (cairo_xlib_surface_t *dst, const cairo_color_t *color) -{ - Display *dpy = dst->display->display; - XRenderColor xcolor; - Picture picture; - Pixmap pixmap = None; - - xcolor.red = color->red_short; - xcolor.green = color->green_short; - xcolor.blue = color->blue_short; - xcolor.alpha = color->alpha_short; - - if (CAIRO_RENDER_HAS_GRADIENTS(dst->display)) { - picture = XRenderCreateSolidFill (dpy, &xcolor); - } else { - XRenderPictureAttributes pa; - int mask = 0; - - pa.repeat = RepeatNormal; - mask |= CPRepeat; - - pixmap = XCreatePixmap (dpy, dst->drawable, 1, 1, 32); - picture = XRenderCreatePicture (dpy, pixmap, - _cairo_xlib_display_get_xrender_format (dst->display, CAIRO_FORMAT_ARGB32), - mask, &pa); - - if (CAIRO_RENDER_HAS_FILL_RECTANGLES(dst->display)) { - XRectangle r = { 0, 0, 1, 1}; - XRenderFillRectangles (dpy, PictOpSrc, picture, &xcolor, &r, 1); - } else { - XGCValues gcv; - GC gc; - - gc = _cairo_xlib_screen_get_gc (dst->display, dst->screen, - 32, pixmap); - if (unlikely (gc == NULL)) { - XFreePixmap (dpy, pixmap); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - gcv.foreground = 0; - gcv.foreground |= color->alpha_short >> 8 << 24; - gcv.foreground |= color->red_short >> 8 << 16; - gcv.foreground |= color->green_short >> 8 << 8; - gcv.foreground |= color->blue_short >> 8 << 0; - gcv.fill_style = FillSolid; - - XChangeGC (dpy, gc, GCFillStyle | GCForeground, &gcv); - XFillRectangle (dpy, pixmap, gc, 0, 0, 1, 1); - - _cairo_xlib_screen_put_gc (dst->display, dst->screen, 32, gc); - } - } - - return source (dst, picture, pixmap); -} - -static cairo_surface_t * -alpha_source (cairo_xlib_surface_t *dst, uint8_t alpha) -{ - cairo_xlib_display_t *display = dst->display; - - if (display->alpha[alpha] == NULL) { - cairo_color_t color; - - color.red_short = color.green_short = color.blue_short = 0; - color.alpha_short = alpha << 8 | alpha; - - display->alpha[alpha] = color_source (dst, &color); - } - - return cairo_surface_reference (display->alpha[alpha]); -} - -static cairo_surface_t * -white_source (cairo_xlib_surface_t *dst) -{ - cairo_xlib_display_t *display = dst->display; - - if (display->white == NULL) - display->white = color_source (dst, CAIRO_COLOR_WHITE); - - return cairo_surface_reference (display->white); -} - -static cairo_surface_t * -opaque_source (cairo_xlib_surface_t *dst, const cairo_color_t *color) -{ - cairo_xlib_display_t *display = dst->display; - uint32_t pixel = - 0xff000000 | - color->red_short >> 8 << 16 | - color->green_short >> 8 << 8 | - color->blue_short >> 8 << 0; - int i; - - if (display->last_solid_cache[0].color == pixel) - return cairo_surface_reference (display->solid[display->last_solid_cache[0].index]); - - for (i = 0; i < 16; i++) { - if (display->solid_cache[i] == pixel) - goto done; - } - - i = hars_petruska_f54_1_random () % 16; - cairo_surface_destroy (display->solid[i]); - - display->solid[i] = color_source (dst, color); - display->solid_cache[i] = pixel; - -done: - display->last_solid_cache[0].color = pixel; - display->last_solid_cache[0].index = i; - return cairo_surface_reference (display->solid[i]); -} - -static cairo_surface_t * -transparent_source (cairo_xlib_surface_t *dst, const cairo_color_t *color) -{ - cairo_xlib_display_t *display = dst->display; - uint32_t pixel = - color->alpha_short >> 8 << 24 | - color->red_short >> 8 << 16 | - color->green_short >> 8 << 8 | - color->blue_short >> 8 << 0; - int i; - - if (display->last_solid_cache[1].color == pixel) { - assert (display->solid[display->last_solid_cache[1].index]); - return cairo_surface_reference (display->solid[display->last_solid_cache[1].index]); - } - - for (i = 16; i < 32; i++) { - if (display->solid_cache[i] == pixel) - goto done; - } - - i = 16 + (hars_petruska_f54_1_random () % 16); - cairo_surface_destroy (display->solid[i]); - - display->solid[i] = color_source (dst, color); - display->solid_cache[i] = pixel; - -done: - display->last_solid_cache[1].color = pixel; - display->last_solid_cache[1].index = i; - assert (display->solid[i]); - return cairo_surface_reference (display->solid[i]); -} - -static cairo_surface_t * -solid_source (cairo_xlib_surface_t *dst, - const cairo_color_t *color) -{ - if ((color->red_short | color->green_short | color->blue_short) <= 0xff) - return alpha_source (dst, color->alpha_short >> 8); - - if (CAIRO_ALPHA_SHORT_IS_OPAQUE (color->alpha_short)) { - if (color->red_short >= 0xff00 && color->green_short >= 0xff00 && color->blue_short >= 0xff00) - return white_source (dst); - - return opaque_source (dst, color); - } else - return transparent_source (dst, color); -} - -static cairo_xlib_source_t *init_source (cairo_xlib_surface_t *dst, - cairo_xlib_surface_t *src) -{ - Display *dpy = dst->display->display; - cairo_xlib_source_t *source = &src->embedded_source; - - /* As these are frequent and meant to be fast, we track pictures for - * native surface and minimise update requests. - */ - if (source->picture == None) { - XRenderPictureAttributes pa; - - _cairo_surface_init (&source->base, - &cairo_xlib_source_backend, - NULL, /* device */ - CAIRO_CONTENT_COLOR_ALPHA); - - pa.subwindow_mode = IncludeInferiors; - source->picture = XRenderCreatePicture (dpy, - src->drawable, - src->xrender_format, - CPSubwindowMode, &pa); - - source->has_component_alpha = 0; - source->has_matrix = 0; - source->filter = CAIRO_FILTER_NEAREST; - source->extend = CAIRO_EXTEND_NONE; - } - - return (cairo_xlib_source_t *) cairo_surface_reference (&source->base); -} - -static cairo_surface_t * -embedded_source (cairo_xlib_surface_t *dst, - const cairo_surface_pattern_t *pattern, - const cairo_rectangle_int_t *extents, - int *src_x, int *src_y, - cairo_xlib_source_t *source) -{ - Display *dpy = dst->display->display; - cairo_int_status_t status; - XTransform xtransform; - XRenderPictureAttributes pa; - unsigned mask = 0; - - status = _cairo_matrix_to_pixman_matrix_offset (&pattern->base.matrix, - pattern->base.filter, - extents->x + extents->width / 2, - extents->y + extents->height / 2, - (pixman_transform_t *)&xtransform, - src_x, src_y); - - if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) { - if (source->has_matrix) { - source->has_matrix = 0; - memcpy (&xtransform, &identity, sizeof (identity)); - status = CAIRO_INT_STATUS_SUCCESS; - } - } else - source->has_matrix = 1; - if (status == CAIRO_INT_STATUS_SUCCESS) - XRenderSetPictureTransform (dpy, source->picture, &xtransform); - - if (source->filter != pattern->base.filter) { - picture_set_filter (dpy, source->picture, pattern->base.filter); - source->filter = pattern->base.filter; - } - - if (source->has_component_alpha != pattern->base.has_component_alpha) { - pa.component_alpha = pattern->base.has_component_alpha; - mask |= CPComponentAlpha; - source->has_component_alpha = pattern->base.has_component_alpha; - } - - if (source->extend != pattern->base.extend) { - pa.repeat = extend_to_repeat (pattern->base.extend); - mask |= CPRepeat; - source->extend = pattern->base.extend; - } - - if (mask) - XRenderChangePicture (dpy, source->picture, mask, &pa); - - return &source->base; -} - -static cairo_surface_t * -subsurface_source (cairo_xlib_surface_t *dst, - const cairo_surface_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_surface_subsurface_t *sub; - cairo_xlib_surface_t *src; - cairo_xlib_source_t *source; - Display *dpy = dst->display->display; - cairo_int_status_t status; - cairo_surface_pattern_t local_pattern; - XTransform xtransform; - XRenderPictureAttributes pa; - unsigned mask = 0; - - sub = (cairo_surface_subsurface_t *) pattern->surface; - - if (sample->x >= 0 && sample->y >= 0 && - sample->x + sample->width <= sub->extents.width && - sample->y + sample->height <= sub->extents.height) - { - src = (cairo_xlib_surface_t *) sub->target; - status = _cairo_surface_flush (&src->base, 0); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (pattern->base.filter == CAIRO_FILTER_NEAREST && - _cairo_matrix_is_translation (&pattern->base.matrix)) - { - *src_x += pattern->base.matrix.x0 + sub->extents.x; - *src_y += pattern->base.matrix.y0 + sub->extents.y; - - _cairo_xlib_surface_ensure_picture (src); - return cairo_surface_reference (&src->base); - } - else - { - cairo_surface_pattern_t local_pattern = *pattern; - local_pattern.base.matrix.x0 += sub->extents.x; - local_pattern.base.matrix.y0 += sub->extents.y; - local_pattern.base.extend = CAIRO_EXTEND_NONE; - return embedded_source (dst, &local_pattern, extents, - src_x, src_y, init_source (dst, src)); - } - } - - if (sub->snapshot && sub->snapshot->type == CAIRO_SURFACE_TYPE_XLIB) { - src = (cairo_xlib_surface_t *) cairo_surface_reference (sub->snapshot); - source = &src->embedded_source; - } else { - src = (cairo_xlib_surface_t *) - _cairo_surface_create_scratch (&dst->base, - sub->base.content, - sub->extents.width, - sub->extents.height, - NULL); - if (src->base.type != CAIRO_SURFACE_TYPE_XLIB) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_pattern_init_for_surface (&local_pattern, sub->target); - cairo_matrix_init_translate (&local_pattern.base.matrix, - sub->extents.x, sub->extents.y); - local_pattern.base.filter = CAIRO_FILTER_NEAREST; - status = _cairo_surface_paint (&src->base, - CAIRO_OPERATOR_SOURCE, - &local_pattern.base, - NULL); - _cairo_pattern_fini (&local_pattern.base); - - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (status); - } - - _cairo_xlib_surface_ensure_picture (src); - _cairo_surface_subsurface_set_snapshot (&sub->base, &src->base); - - source = &src->embedded_source; - source->has_component_alpha = 0; - source->has_matrix = 0; - source->filter = CAIRO_FILTER_NEAREST; - source->extend = CAIRO_EXTEND_NONE; - } - - status = _cairo_matrix_to_pixman_matrix_offset (&pattern->base.matrix, - pattern->base.filter, - extents->x + extents->width / 2, - extents->y + extents->height / 2, - (pixman_transform_t *)&xtransform, - src_x, src_y); - if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) { - if (source->has_matrix) { - source->has_matrix = 0; - memcpy (&xtransform, &identity, sizeof (identity)); - status = CAIRO_INT_STATUS_SUCCESS; - } - } else - source->has_matrix = 1; - if (status == CAIRO_INT_STATUS_SUCCESS) - XRenderSetPictureTransform (dpy, src->picture, &xtransform); - - if (source->filter != pattern->base.filter) { - picture_set_filter (dpy, src->picture, pattern->base.filter); - source->filter = pattern->base.filter; - } - - if (source->has_component_alpha != pattern->base.has_component_alpha) { - pa.component_alpha = pattern->base.has_component_alpha; - mask |= CPComponentAlpha; - source->has_component_alpha = pattern->base.has_component_alpha; - } - - if (source->extend != pattern->base.extend) { - pa.repeat = extend_to_repeat (pattern->base.extend); - mask |= CPRepeat; - source->extend = pattern->base.extend; - } - - if (mask) - XRenderChangePicture (dpy, src->picture, mask, &pa); - - return &src->base; -} - -static cairo_surface_t * -native_source (cairo_xlib_surface_t *dst, - const cairo_surface_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_xlib_surface_t *src; - cairo_int_status_t status; - - if (_cairo_surface_is_subsurface (pattern->surface)) - return subsurface_source (dst, pattern, is_mask, - extents, sample, - src_x, src_y); - - src = unwrap_source (pattern); - status = _cairo_surface_flush (&src->base, 0); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - if (pattern->base.filter == CAIRO_FILTER_NEAREST && - sample->x >= 0 && sample->y >= 0 && - sample->x + sample->width <= src->width && - sample->y + sample->height <= src->height && - _cairo_matrix_is_translation (&pattern->base.matrix)) - { - *src_x += pattern->base.matrix.x0; - *src_y += pattern->base.matrix.y0; - _cairo_xlib_surface_ensure_picture (src); - return cairo_surface_reference (&src->base); - } - - return embedded_source (dst, pattern, extents, src_x, src_y, - init_source (dst, src)); -} - -static cairo_surface_t * -recording_pattern_get_surface (const cairo_pattern_t *pattern) -{ - cairo_surface_t *surface; - - surface = ((const cairo_surface_pattern_t *) pattern)->surface; - - if (_cairo_surface_is_paginated (surface)) - return cairo_surface_reference (_cairo_paginated_surface_get_recording (surface)); - - if (_cairo_surface_is_snapshot (surface)) - return _cairo_surface_snapshot_get_target (surface); - - return cairo_surface_reference (surface); -} - -static cairo_surface_t * -record_source (cairo_xlib_surface_t *dst, - const cairo_surface_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_xlib_surface_t *src; - cairo_surface_t *recording; - cairo_matrix_t matrix, m; - cairo_status_t status; - cairo_rectangle_int_t upload, limit; - - upload = *sample; - if (_cairo_surface_get_extents (pattern->surface, &limit) && - ! _cairo_rectangle_intersect (&upload, &limit)) - { - if (pattern->base.extend == CAIRO_EXTEND_NONE) - return alpha_source (dst, 0); - - upload = limit; - } - - src = (cairo_xlib_surface_t *) - _cairo_surface_create_scratch (&dst->base, - pattern->surface->content, - upload.width, - upload.height, - NULL); - if (src->base.type != CAIRO_SURFACE_TYPE_XLIB) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - cairo_matrix_init_translate (&matrix, upload.x, upload.y); - recording = recording_pattern_get_surface (&pattern->base), - status = _cairo_recording_surface_replay_with_clip (recording, - &matrix, &src->base, - NULL); - cairo_surface_destroy (recording); - if (unlikely (status)) { - cairo_surface_destroy (&src->base); - return _cairo_surface_create_in_error (status); - } - - matrix = pattern->base.matrix; - if (upload.x | upload.y) { - cairo_matrix_init_translate (&m, -upload.x, -upload.y); - cairo_matrix_multiply (&matrix, &matrix, &m); - } - - _cairo_xlib_surface_ensure_picture (src); - if (! picture_set_properties (src->display, src->picture, - &pattern->base, &matrix, extents, - src_x, src_y)) - { - cairo_surface_destroy (&src->base); - return render_pattern (dst, &pattern->base, is_mask, - extents, src_x, src_y); - } - - return &src->base; -} - -static cairo_surface_t * -surface_source (cairo_xlib_surface_t *dst, - const cairo_surface_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_surface_t *src; - cairo_xlib_surface_t *xsrc; - cairo_surface_pattern_t local_pattern; - cairo_status_t status; - cairo_rectangle_int_t upload, limit; - - src = pattern->surface; - if (src->type == CAIRO_SURFACE_TYPE_IMAGE && - src->device == dst->base.device && - _cairo_xlib_shm_surface_get_pixmap (src)) { - cairo_xlib_proxy_t *proxy; - - proxy = malloc (sizeof(*proxy)); - if (unlikely (proxy == NULL)) - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_surface_init (&proxy->source.base, - &cairo_xlib_proxy_backend, - dst->base.device, - src->content); - - proxy->source.dpy = dst->display->display; - proxy->source.picture = XRenderCreatePicture (proxy->source.dpy, - _cairo_xlib_shm_surface_get_pixmap (src), - _cairo_xlib_shm_surface_get_xrender_format (src), - 0, NULL); - proxy->source.pixmap = None; - - proxy->source.has_component_alpha = 0; - proxy->source.has_matrix = 0; - proxy->source.filter = CAIRO_FILTER_NEAREST; - proxy->source.extend = CAIRO_EXTEND_NONE; - proxy->owner = cairo_surface_reference (src); - - return embedded_source (dst, pattern, extents, src_x, src_y, - &proxy->source); - } - - upload = *sample; - if (_cairo_surface_get_extents (pattern->surface, &limit)) { - if (pattern->base.extend == CAIRO_EXTEND_NONE) { - if (! _cairo_rectangle_intersect (&upload, &limit)) - return alpha_source (dst, 0); - } else if (pattern->base.extend == CAIRO_EXTEND_PAD) { - if (! _cairo_rectangle_intersect (&upload, &limit)) - upload = limit; - } else { - if (upload.x < limit.x || - upload.x + upload.width > limit.x + limit.width || - upload.y < limit.y || - upload.y + upload.height > limit.y + limit.height) - { - upload = limit; - } - } - } - - xsrc = (cairo_xlib_surface_t *) - _cairo_surface_create_scratch (&dst->base, - src->content, - upload.width, - upload.height, - NULL); - if (xsrc->base.type != CAIRO_SURFACE_TYPE_XLIB) { - cairo_surface_destroy (src); - cairo_surface_destroy (&xsrc->base); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - if (_cairo_surface_is_image (src)) { - status = _cairo_xlib_surface_draw_image (xsrc, (cairo_image_surface_t *)src, - upload.x, upload.y, - upload.width, upload.height, - 0, 0); - } else { - cairo_image_surface_t *image; - cairo_rectangle_int_t map_extents = { 0,0, upload.width,upload.height }; - - image = _cairo_surface_map_to_image (&xsrc->base, &map_extents); - - _cairo_pattern_init_for_surface (&local_pattern, pattern->surface); - cairo_matrix_init_translate (&local_pattern.base.matrix, - upload.x, upload.y); - - status = _cairo_surface_paint (&image->base, - CAIRO_OPERATOR_SOURCE, - &local_pattern.base, - NULL); - _cairo_pattern_fini (&local_pattern.base); - - status = _cairo_surface_unmap_image (&xsrc->base, image); - if (unlikely (status)) { - cairo_surface_destroy (&xsrc->base); - return _cairo_surface_create_in_error (status); - } - - status = _cairo_xlib_surface_put_shm (xsrc); - if (unlikely (status)) { - cairo_surface_destroy (&xsrc->base); - return _cairo_surface_create_in_error (status); - } - } - - _cairo_pattern_init_static_copy (&local_pattern.base, &pattern->base); - if (upload.x | upload.y) { - cairo_matrix_t m; - cairo_matrix_init_translate (&m, -upload.x, -upload.y); - cairo_matrix_multiply (&local_pattern.base.matrix, - &local_pattern.base.matrix, - &m); - } - - *src_x = *src_y = 0; - _cairo_xlib_surface_ensure_picture (xsrc); - if (! picture_set_properties (xsrc->display, - xsrc->picture, - &local_pattern.base, - &local_pattern.base.matrix, - extents, - src_x, src_y)) - { - cairo_surface_destroy (&xsrc->base); - return render_pattern (dst, &pattern->base, - is_mask, extents, - src_x, src_y); - } - - return &xsrc->base; -} - -static cairo_bool_t -pattern_is_supported (cairo_xlib_display_t *display, - const cairo_pattern_t *pattern) -{ - if (pattern->type == CAIRO_PATTERN_TYPE_MESH) - return FALSE; - - if (display->buggy_pad_reflect) { - if (pattern->extend == CAIRO_EXTEND_REPEAT || pattern->extend == CAIRO_EXTEND_PAD) - return FALSE; - } - - if (display->buggy_gradients) { - if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || pattern->type == CAIRO_PATTERN_TYPE_RADIAL) - return FALSE; - } - - switch (pattern->filter) { - case CAIRO_FILTER_FAST: - case CAIRO_FILTER_NEAREST: - return CAIRO_RENDER_HAS_PICTURE_TRANSFORM (display) || - _cairo_matrix_is_integer_translation (&pattern->matrix, NULL, NULL); - case CAIRO_FILTER_GOOD: - return CAIRO_RENDER_HAS_FILTER_GOOD (display); - case CAIRO_FILTER_BEST: - return CAIRO_RENDER_HAS_FILTER_BEST (display); - case CAIRO_FILTER_BILINEAR: - case CAIRO_FILTER_GAUSSIAN: - default: - return CAIRO_RENDER_HAS_FILTERS (display); - } -} - -cairo_surface_t * -_cairo_xlib_source_create_for_pattern (cairo_surface_t *_dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)_dst; - - *src_x = *src_y = 0; - - if (pattern == NULL || pattern->type == CAIRO_PATTERN_TYPE_SOLID) { - if (pattern == NULL) - pattern = &_cairo_pattern_white.base; - - return solid_source (dst, &((cairo_solid_pattern_t *)pattern)->color); - } - - if (pattern_is_supported (dst->display, pattern)) { - if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { - cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t *)pattern; - if (spattern->surface->type == CAIRO_SURFACE_TYPE_XLIB && - _cairo_xlib_surface_same_screen (dst, - unwrap_source (spattern))) - return native_source (dst, spattern, is_mask, - extents, sample, - src_x, src_y); - - if (spattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) - return record_source (dst, spattern, is_mask, - extents, sample, - src_x, src_y); - - return surface_source (dst, spattern, is_mask, - extents, sample, - src_x, src_y); - } - - if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || - pattern->type == CAIRO_PATTERN_TYPE_RADIAL) - { - cairo_gradient_pattern_t *gpattern = (cairo_gradient_pattern_t *)pattern; - return gradient_source (dst, gpattern, is_mask, extents, src_x, src_y); - } - } - - return render_pattern (dst, pattern, is_mask, extents, src_x, src_y); -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-private.h deleted file mode 100644 index 83d9b63cc4c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-private.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - */ - -#ifndef CAIRO_XLIB_SURFACE_PRIVATE_H -#define CAIRO_XLIB_SURFACE_PRIVATE_H - -#include "cairo-xlib-xrender-private.h" -#include "cairo-xlib.h" -#include "cairo-xlib-private.h" - -#include "cairo-surface-private.h" -#include "cairo-surface-backend-private.h" - - -#endif /* CAIRO_XLIB_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-shm.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-shm.c deleted file mode 100644 index fb40699dc1d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface-shm.c +++ /dev/null @@ -1,1459 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2012 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" -#include "cairo-xlib-surface-private.h" - -#if !HAVE_X11_EXTENSIONS_XSHM_H || !(HAVE_X11_EXTENSIONS_SHMPROTO_H || HAVE_X11_EXTENSIONS_SHMSTR_H) -void _cairo_xlib_display_init_shm (cairo_xlib_display_t *display) {} - -cairo_surface_t * -_cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface, - cairo_bool_t overwrite) -{ - return NULL; -} - -cairo_int_status_t -_cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface) -{ - assert (!surface->fallback); - return CAIRO_INT_STATUS_SUCCESS; -} - -cairo_surface_t * -_cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other, - pixman_format_code_t format, - int width, int height) -{ - return NULL; -} - -cairo_surface_t * -_cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface, - pixman_format_code_t format, - int width, int height) -{ - return NULL; -} - -cairo_surface_t * -_cairo_xlib_surface_create_similar_shm (void *other, - cairo_format_t format, - int width, int height) -{ - return cairo_image_surface_create (format, width, height); -} - -void -_cairo_xlib_shm_surface_mark_active (cairo_surface_t *_shm) -{ - ASSERT_NOT_REACHED; -} - -void -_cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface, - XImage *ximage) -{ - ASSERT_NOT_REACHED; -} - -void * -_cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface) -{ - ASSERT_NOT_REACHED; - return NULL; -} - -Pixmap -_cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface) -{ - ASSERT_NOT_REACHED; - return 0; -} - -XRenderPictFormat * -_cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface) -{ - ASSERT_NOT_REACHED; - return NULL; -} - -cairo_bool_t -_cairo_xlib_shm_surface_is_active (cairo_surface_t *surface) -{ - ASSERT_NOT_REACHED; - return FALSE; -} - -cairo_bool_t -_cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface) -{ - ASSERT_NOT_REACHED; - return TRUE; -} - -void _cairo_xlib_display_fini_shm (cairo_xlib_display_t *display) {} - -#else - -#include "cairo-damage-private.h" -#include "cairo-default-context-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-mempool-private.h" - -#include -#include -#include -#if HAVE_X11_EXTENSIONS_SHMPROTO_H -#include -#elif HAVE_X11_EXTENSIONS_SHMSTR_H -#include -#endif -#include -#include - -#define MIN_PIXMAP_SIZE 4096 - -#define MIN_BITS 8 -#define MIN_SIZE (1<<(MIN_BITS-1)) - -typedef struct _cairo_xlib_shm cairo_xlib_shm_t; -typedef struct _cairo_xlib_shm_info cairo_xlib_shm_info_t; -typedef struct _cairo_xlib_shm_surface cairo_xlib_shm_surface_t; - -struct _cairo_xlib_shm { - cairo_mempool_t mem; - - XShmSegmentInfo shm; - unsigned long attached; - cairo_list_t link; -}; - -struct _cairo_xlib_shm_info { - unsigned long last_request; - void *mem; - size_t size; - cairo_xlib_shm_t *pool; -}; - -struct _cairo_xlib_shm_surface { - cairo_image_surface_t image; - - cairo_list_t link; - cairo_xlib_shm_info_t *info; - Pixmap pixmap; - unsigned long active; - int idle; -}; - -/* the parent is always given by index/2 */ -#define PQ_PARENT_INDEX(i) ((i) >> 1) -#define PQ_FIRST_ENTRY 1 - -/* left and right children are index * 2 and (index * 2) +1 respectively */ -#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) - -#define PQ_TOP(pq) ((pq)->elements[PQ_FIRST_ENTRY]) - -struct pqueue { - int size, max_size; - cairo_xlib_shm_info_t **elements; -}; - -struct _cairo_xlib_shm_display { - int has_pixmaps; - int opcode; - int event; - - Window window; - unsigned long last_request; - unsigned long last_event; - - cairo_list_t surfaces; - - cairo_list_t pool; - struct pqueue info; -}; - -static inline cairo_bool_t -seqno_passed (unsigned long a, unsigned long b) -{ - return (long)(b - a) >= 0; -} - -static inline cairo_bool_t -seqno_before (unsigned long a, unsigned long b) -{ - return (long)(b - a) > 0; -} - -static inline cairo_bool_t -seqno_after (unsigned long a, unsigned long b) -{ - return (long)(a - b) > 0; -} - -static inline cairo_status_t -_pqueue_init (struct pqueue *pq) -{ - pq->max_size = 32; - pq->size = 0; - - pq->elements = _cairo_malloc_ab (pq->max_size, - sizeof (cairo_xlib_shm_info_t *)); - if (unlikely (pq->elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - PQ_TOP(pq) = NULL; - return CAIRO_STATUS_SUCCESS; -} - -static inline void -_pqueue_fini (struct pqueue *pq) -{ - free (pq->elements); -} - -static cairo_status_t -_pqueue_grow (struct pqueue *pq) -{ - cairo_xlib_shm_info_t **new_elements; - - new_elements = _cairo_realloc_ab (pq->elements, - 2 * pq->max_size, - sizeof (cairo_xlib_shm_info_t *)); - if (unlikely (new_elements == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - pq->elements = new_elements; - pq->max_size *= 2; - return CAIRO_STATUS_SUCCESS; -} - -static void -_pqueue_shrink (struct pqueue *pq, int min_size) -{ - cairo_xlib_shm_info_t **new_elements; - - if (min_size > pq->max_size) - return; - - new_elements = _cairo_realloc_ab (pq->elements, - min_size, - sizeof (cairo_xlib_shm_info_t *)); - if (unlikely (new_elements == NULL)) - return; - - pq->elements = new_elements; - pq->max_size = min_size; -} - -static inline cairo_status_t -_pqueue_push (struct pqueue *pq, cairo_xlib_shm_info_t *info) -{ - cairo_xlib_shm_info_t **elements; - int i, parent; - - if (unlikely (pq->size + 1 == pq->max_size)) { - cairo_status_t status; - - status = _pqueue_grow (pq); - if (unlikely (status)) - return status; - } - - elements = pq->elements; - - for (i = ++pq->size; - i != PQ_FIRST_ENTRY && - info->last_request < elements[parent = PQ_PARENT_INDEX (i)]->last_request; - i = parent) - { - elements[i] = elements[parent]; - } - - elements[i] = info; - - return CAIRO_STATUS_SUCCESS; -} - -static inline void -_pqueue_pop (struct pqueue *pq) -{ - cairo_xlib_shm_info_t **elements = pq->elements; - cairo_xlib_shm_info_t *tail; - int child, i; - - tail = elements[pq->size--]; - if (pq->size == 0) { - elements[PQ_FIRST_ENTRY] = NULL; - _pqueue_shrink (pq, 32); - return; - } - - for (i = PQ_FIRST_ENTRY; - (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; - i = child) - { - if (child != pq->size && - elements[child+1]->last_request < elements[child]->last_request) - { - child++; - } - - if (elements[child]->last_request >= tail->last_request) - break; - - elements[i] = elements[child]; - } - elements[i] = tail; -} - -static cairo_bool_t _x_error_occurred; - -static int -_check_error_handler (Display *display, - XErrorEvent *event) -{ - _x_error_occurred = TRUE; - return False; /* ignored */ -} - -static cairo_bool_t -can_use_shm (Display *dpy, int *has_pixmap) -{ - XShmSegmentInfo shm; - int (*old_handler) (Display *display, XErrorEvent *event); - Status success; - int major, minor; - - if (! XShmQueryExtension (dpy)) - return FALSE; - - XShmQueryVersion (dpy, &major, &minor, has_pixmap); - - shm.shmid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | 0600); - if (shm.shmid == -1) - return FALSE; - - shm.readOnly = FALSE; - shm.shmaddr = shmat (shm.shmid, NULL, 0); - if (shm.shmaddr == (char *) -1) { - shmctl (shm.shmid, IPC_RMID, NULL); - return FALSE; - } - - assert (CAIRO_MUTEX_IS_LOCKED (_cairo_xlib_display_mutex)); - _x_error_occurred = FALSE; - - XLockDisplay (dpy); - XSync (dpy, False); - old_handler = XSetErrorHandler (_check_error_handler); - - success = XShmAttach (dpy, &shm); - if (success) - XShmDetach (dpy, &shm); - - XSync (dpy, False); - XSetErrorHandler (old_handler); - XUnlockDisplay (dpy); - - shmctl (shm.shmid, IPC_RMID, NULL); - shmdt (shm.shmaddr); - - return success && ! _x_error_occurred; -} - -static inline Display * -peek_display (cairo_device_t *device) -{ - return ((cairo_xlib_display_t *)device)->display; -} - -static inline unsigned long -peek_processed (cairo_device_t *device) -{ - return LastKnownRequestProcessed (peek_display(device)); -} - -static void -_cairo_xlib_display_shm_pool_destroy (cairo_xlib_display_t *display, - cairo_xlib_shm_t *pool) -{ - shmdt (pool->shm.shmaddr); - if (display->display) /* may be called after CloseDisplay */ - XShmDetach (display->display, &pool->shm); - - _cairo_mempool_fini (&pool->mem); - - cairo_list_del (&pool->link); - free (pool); -} - -static void send_event(cairo_xlib_display_t *display, - cairo_xlib_shm_info_t *info, - unsigned long seqno) -{ - XShmCompletionEvent ev; - - if (! seqno_after (seqno, display->shm->last_event)) - return; - - ev.type = display->shm->event; - ev.send_event = 1; /* XXX or lie? */ - ev.serial = NextRequest (display->display); - ev.drawable = display->shm->window; - ev.major_code = display->shm->opcode; - ev.minor_code = X_ShmPutImage; - ev.shmseg = info->pool->shm.shmid; - ev.offset = (char *)info->mem - (char *)info->pool->shm.shmaddr; - - XSendEvent (display->display, ev.drawable, False, 0, (XEvent *)&ev); - - display->shm->last_event = ev.serial; -} - -static void _cairo_xlib_display_sync (cairo_xlib_display_t *display) -{ - cairo_xlib_shm_info_t *info; - struct pqueue *pq = &display->shm->info; - - XSync (display->display, False); - - while ((info = PQ_TOP(pq))) { - _cairo_mempool_free (&info->pool->mem, info->mem); - _pqueue_pop (&display->shm->info); - free (info); - } -} - -static void -_cairo_xlib_shm_info_cleanup (cairo_xlib_display_t *display) -{ - cairo_xlib_shm_info_t *info; - Display *dpy = display->display; - struct pqueue *pq = &display->shm->info; - unsigned long processed; - - if (PQ_TOP(pq) == NULL) - return; - - XEventsQueued (dpy, QueuedAfterReading); - processed = LastKnownRequestProcessed (dpy); - - info = PQ_TOP(pq); - do { - if (! seqno_passed (info->last_request, processed)) { - send_event (display, info, display->shm->last_request); - return; - } - - _cairo_mempool_free (&info->pool->mem, info->mem); - _pqueue_pop (&display->shm->info); - free (info); - } while ((info = PQ_TOP(pq))); -} - -static cairo_xlib_shm_t * -_cairo_xlib_shm_info_find (cairo_xlib_display_t *display, size_t size, - void **ptr, unsigned long *last_request) -{ - cairo_xlib_shm_info_t *info; - struct pqueue *pq = &display->shm->info; - - if (PQ_TOP(pq) == NULL) - return NULL; - - info = PQ_TOP(pq); - do { - cairo_xlib_shm_t *pool = info->pool; - - *last_request = info->last_request; - - _pqueue_pop (&display->shm->info); - _cairo_mempool_free (&pool->mem, info->mem); - free (info); - - if (pool->mem.free_bytes >= size) { - void *mem = _cairo_mempool_alloc (&pool->mem, size); - if (mem != NULL) { - *ptr = mem; - return pool; - } - } - } while ((info = PQ_TOP(pq))); - - return NULL; -} - -static cairo_xlib_shm_t * -_cairo_xlib_shm_pool_find (cairo_xlib_display_t *display, - size_t size, - void **ptr) -{ - cairo_xlib_shm_t *pool; - - cairo_list_foreach_entry (pool, cairo_xlib_shm_t, &display->shm->pool, link) { - if (pool->mem.free_bytes >= size) { - void *mem = _cairo_mempool_alloc (&pool->mem, size); - if (mem != NULL) { - *ptr = mem; - return pool; - } - } - } - - return NULL; -} - -static void -_cairo_xlib_shm_pool_cleanup (cairo_xlib_display_t *display) -{ - cairo_xlib_shm_t *pool, *next; - unsigned long processed; - - processed = LastKnownRequestProcessed (display->display); - - cairo_list_foreach_entry_safe (pool, next, cairo_xlib_shm_t, - &display->shm->pool, link) { - if (! seqno_passed (pool->attached, processed)) - break; - - if (pool->mem.free_bytes == pool->mem.max_bytes) - _cairo_xlib_display_shm_pool_destroy (display, pool); - } -} - -static cairo_xlib_shm_t * -_cairo_xlib_shm_pool_create(cairo_xlib_display_t *display, - size_t size, void **ptr) -{ - Display *dpy = display->display; - cairo_xlib_shm_t *pool; - size_t bytes, maxbits = 16, minbits = MIN_BITS; - Status success; - - pool = malloc (sizeof (cairo_xlib_shm_t)); - if (pool == NULL) - return NULL; - - bytes = 1 << maxbits; - while (bytes <= size) - bytes <<= 1, maxbits++; - bytes <<= 3; - - minbits += (maxbits - 16) / 2; - - pool->shm.shmid = shmget (IPC_PRIVATE, bytes, IPC_CREAT | 0600); - while (pool->shm.shmid == -1 && bytes >= 2*size) { - bytes >>= 1; - pool->shm.shmid = shmget (IPC_PRIVATE, bytes, IPC_CREAT | 0600); - } - if (pool->shm.shmid == -1) - goto cleanup; - - pool->shm.readOnly = FALSE; - pool->shm.shmaddr = shmat (pool->shm.shmid, NULL, 0); - if (pool->shm.shmaddr == (char *) -1) { - shmctl (pool->shm.shmid, IPC_RMID, NULL); - goto cleanup; - } - - pool->attached = NextRequest (dpy); - success = XShmAttach (dpy, &pool->shm); -#if !IPC_RMID_DEFERRED_RELEASE - XSync (dpy, FALSE); -#endif - shmctl (pool->shm.shmid, IPC_RMID, NULL); - - if (! success) - goto cleanup_shm; - - if (_cairo_mempool_init (&pool->mem, pool->shm.shmaddr, bytes, - minbits, maxbits - minbits + 1)) - goto cleanup_detach; - - cairo_list_add (&pool->link, &display->shm->pool); - - *ptr = _cairo_mempool_alloc (&pool->mem, size); - assert (*ptr != NULL); - return pool; - -cleanup_detach: - XShmDetach (dpy, &pool->shm); -cleanup_shm: - shmdt (pool->shm.shmaddr); -cleanup: - free (pool); - return NULL; -} - -static cairo_xlib_shm_info_t * -_cairo_xlib_shm_info_create (cairo_xlib_display_t *display, - size_t size, cairo_bool_t will_sync) -{ - cairo_xlib_shm_info_t *info; - cairo_xlib_shm_t *pool; - unsigned long last_request = 0; - void *mem = NULL; - - _cairo_xlib_shm_info_cleanup (display); - pool = _cairo_xlib_shm_pool_find (display, size, &mem); - _cairo_xlib_shm_pool_cleanup (display); - - if (pool == NULL && will_sync) - pool = _cairo_xlib_shm_info_find (display, size, &mem, &last_request); - if (pool == NULL) - pool = _cairo_xlib_shm_pool_create (display, size, &mem); - if (pool == NULL) - return NULL; - - assert (mem != NULL); - - info = malloc (sizeof (*info)); - if (info == NULL) { - _cairo_mempool_free (&pool->mem, mem); - return NULL; - } - - info->pool = pool; - info->mem = mem; - info->size = size; - info->last_request = last_request; - - return info; -} - -static cairo_status_t -_cairo_xlib_shm_surface_flush (void *abstract_surface, unsigned flags) -{ - cairo_xlib_shm_surface_t *shm = abstract_surface; - cairo_xlib_display_t *display; - Display *dpy; - cairo_status_t status; - - if (shm->active == 0) - return CAIRO_STATUS_SUCCESS; - - if (shm->image.base._finishing) - return CAIRO_STATUS_SUCCESS; - - if (seqno_passed (shm->active, peek_processed (shm->image.base.device))) { - shm->active = 0; - return CAIRO_STATUS_SUCCESS; - } - - status = _cairo_xlib_display_acquire (shm->image.base.device, &display); - if (unlikely (status)) - return status; - - send_event (display, shm->info, shm->active); - - dpy = display->display; - XEventsQueued (dpy, QueuedAfterReading); - while (! seqno_passed (shm->active, LastKnownRequestProcessed (dpy))) { - LockDisplay(dpy); - _XReadEvents(dpy); - UnlockDisplay(dpy); - } - - cairo_device_release (&display->base); - shm->active = 0; - - return CAIRO_STATUS_SUCCESS; -} - -static inline cairo_bool_t -active (cairo_xlib_shm_surface_t *shm, Display *dpy) -{ - return (shm->active && - ! seqno_passed (shm->active, LastKnownRequestProcessed (dpy))); -} - -static cairo_status_t -_cairo_xlib_shm_surface_finish (void *abstract_surface) -{ - cairo_xlib_shm_surface_t *shm = abstract_surface; - cairo_xlib_display_t *display; - cairo_status_t status; - - if (shm->image.base.damage) { - _cairo_damage_destroy (shm->image.base.damage); - shm->image.base.damage = _cairo_damage_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); - } - - status = _cairo_xlib_display_acquire (shm->image.base.device, &display); - if (unlikely (status)) - return status; - - if (shm->pixmap) - XFreePixmap (display->display, shm->pixmap); - - if (active (shm, display->display)) { - shm->info->last_request = shm->active; - _pqueue_push (&display->shm->info, shm->info); - if (seqno_before (display->shm->last_request, shm->active)) - display->shm->last_request = shm->active; - } else { - _cairo_mempool_free (&shm->info->pool->mem, shm->info->mem); - free (shm->info); - - _cairo_xlib_shm_pool_cleanup (display); - } - - cairo_list_del (&shm->link); - - cairo_device_release (&display->base); - return _cairo_image_surface_finish (abstract_surface); -} - -static const cairo_surface_backend_t cairo_xlib_shm_surface_backend = { - CAIRO_SURFACE_TYPE_IMAGE, - _cairo_xlib_shm_surface_finish, - - _cairo_default_context_create, - - _cairo_image_surface_create_similar, - NULL, /* create similar image */ - _cairo_image_surface_map_to_image, - _cairo_image_surface_unmap_image, - - _cairo_image_surface_source, - _cairo_image_surface_acquire_source_image, - _cairo_image_surface_release_source_image, - _cairo_image_surface_snapshot, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_image_surface_get_extents, - _cairo_image_surface_get_font_options, - - _cairo_xlib_shm_surface_flush, - NULL, - - _cairo_image_surface_paint, - _cairo_image_surface_mask, - _cairo_image_surface_stroke, - _cairo_image_surface_fill, - NULL, /* fill-stroke */ - _cairo_image_surface_glyphs, -}; - -static cairo_bool_t -has_shm (cairo_xlib_surface_t *surface) -{ - cairo_xlib_display_t *display = (cairo_xlib_display_t *)surface->base.device; - return display->shm != NULL; -} - -static int -has_shm_pixmaps (cairo_xlib_surface_t *surface) -{ - cairo_xlib_display_t *display = (cairo_xlib_display_t *)surface->base.device; - if (!display->shm) - return 0; - - return display->shm->has_pixmaps; -} - -static cairo_xlib_shm_surface_t * -_cairo_xlib_shm_surface_create (cairo_xlib_surface_t *other, - pixman_format_code_t format, - int width, int height, - cairo_bool_t will_sync, - int create_pixmap) -{ - cairo_xlib_shm_surface_t *shm; - cairo_xlib_display_t *display; - pixman_image_t *image; - int stride, size; - - stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, PIXMAN_FORMAT_BPP(format)); - size = stride * height; - if (size < MIN_SIZE) - return NULL; - - shm = malloc (sizeof (*shm)); - if (unlikely (shm == NULL)) - return (cairo_xlib_shm_surface_t *)_cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_surface_init (&shm->image.base, - &cairo_xlib_shm_surface_backend, - other->base.device, - _cairo_content_from_pixman_format (format)); - - if (_cairo_xlib_display_acquire (other->base.device, &display)) - goto cleanup_shm; - - shm->info = _cairo_xlib_shm_info_create (display, size, will_sync); - if (shm->info == NULL) - goto cleanup_display; - - image = pixman_image_create_bits (format, width, height, - (uint32_t *) shm->info->mem, stride); - if (image == NULL) - goto cleanup_info; - - _cairo_image_surface_init (&shm->image, image, format); - - shm->pixmap = 0; - if (create_pixmap && size >= create_pixmap) { - shm->pixmap = XShmCreatePixmap (display->display, - other->drawable, - shm->info->mem, - &shm->info->pool->shm, - shm->image.width, - shm->image.height, - shm->image.depth); - } - shm->active = shm->info->last_request; - shm->idle = -5; - - assert (shm->active == 0 || will_sync); - - cairo_list_add (&shm->link, &display->shm->surfaces); - - cairo_device_release (&display->base); - - return shm; - -cleanup_info: - _cairo_mempool_free (&shm->info->pool->mem, shm->info->mem); - free(shm->info); -cleanup_display: - cairo_device_release (&display->base); -cleanup_shm: - free (shm); - return NULL; -} - -static void -_cairo_xlib_surface_update_shm (cairo_xlib_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface->shm; - cairo_xlib_display_t *display; - cairo_damage_t *damage; - GC gc; - - damage = _cairo_damage_reduce (surface->base.damage); - surface->base.damage = _cairo_damage_create(); - - if (_cairo_xlib_display_acquire (surface->base.device, &display)) - goto cleanup_damage; - - if (_cairo_xlib_surface_get_gc (display, surface, &gc)) - goto cleanup_display; - - if (! surface->owns_pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = IncludeInferiors; - XChangeGC (display->display, gc, GCSubwindowMode, &gcv); - } - - if (damage->region) { - XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *rects = stack_rects; - cairo_rectangle_int_t r; - int n_rects, i; - - n_rects = cairo_region_num_rectangles (damage->region); - if (n_rects == 0) { - } else if (n_rects == 1) { - cairo_region_get_rectangle (damage->region, 0, &r); - XCopyArea (display->display, - surface->drawable, shm->pixmap, gc, - r.x, r.y, - r.width, r.height, - r.x, r.y); - } else { - if (n_rects > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle)); - if (unlikely (rects == NULL)) { - rects = stack_rects; - n_rects = ARRAY_LENGTH (stack_rects); - } - } - for (i = 0; i < n_rects; i++) { - cairo_region_get_rectangle (damage->region, i, &r); - - rects[i].x = r.x; - rects[i].y = r.y; - rects[i].width = r.width; - rects[i].height = r.height; - } - XSetClipRectangles (display->display, gc, 0, 0, rects, i, YXBanded); - - XCopyArea (display->display, - surface->drawable, shm->pixmap, gc, - 0, 0, - shm->image.width, shm->image.height, - 0, 0); - - if (damage->status == CAIRO_STATUS_SUCCESS && damage->region) - XSetClipMask (display->display, gc, None); - } - } else { - XCopyArea (display->display, - surface->drawable, shm->pixmap, gc, - 0, 0, - shm->image.width, shm->image.height, - 0, 0); - } - - if (! surface->owns_pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = ClipByChildren; - XChangeGC (display->display, gc, GCSubwindowMode, &gcv); - } - - _cairo_xlib_display_sync (display); - shm->active = 0; - shm->idle--; - - _cairo_xlib_surface_put_gc (display, surface, gc); -cleanup_display: - cairo_device_release (&display->base); -cleanup_damage: - _cairo_damage_destroy (damage); -} - -static void -_cairo_xlib_surface_clear_shm (cairo_xlib_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface->shm; - - assert (shm->active == 0); - - _cairo_damage_destroy (surface->base.damage); - surface->base.damage = _cairo_damage_create(); - - memset (shm->image.data, 0, shm->image.stride * shm->image.height); - shm->image.base.is_clear = TRUE; -} - -static void inc_idle (cairo_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface; - shm->idle++; -} - -static void dec_idle (cairo_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface; - shm->idle--; -} - -cairo_surface_t * -_cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface, - cairo_bool_t overwrite) -{ - if (surface->fallback) { - assert (surface->base.damage); - assert (surface->shm); - assert (surface->shm->damage); - goto done; - } - - if (surface->shm == NULL) { - pixman_format_code_t pixman_format; - cairo_bool_t will_sync; - - if (! has_shm_pixmaps (surface)) - return NULL; - - if ((surface->width | surface->height) < 32) - return NULL; - - pixman_format = _pixman_format_for_xlib_surface (surface); - if (pixman_format == 0) - return NULL; - - will_sync = !surface->base.is_clear && !overwrite; - - surface->shm = - &_cairo_xlib_shm_surface_create (surface, pixman_format, - surface->width, surface->height, - will_sync, 1)->image.base; - if (surface->shm == NULL) - return NULL; - - assert (surface->base.damage == NULL); - if (surface->base.serial || !surface->owns_pixmap) { - cairo_rectangle_int_t rect; - - rect.x = rect.y = 0; - rect.width = surface->width; - rect.height = surface->height; - - surface->base.damage = - _cairo_damage_add_rectangle (NULL, &rect); - } else - surface->base.damage = _cairo_damage_create (); - - surface->shm->damage = _cairo_damage_create (); - } - - if (overwrite) { - _cairo_damage_destroy (surface->base.damage); - surface->base.damage = _cairo_damage_create (); - } - - if (!surface->base.is_clear && surface->base.damage->dirty) - _cairo_xlib_surface_update_shm (surface); - - _cairo_xlib_shm_surface_flush (surface->shm, 1); - - if (surface->base.is_clear && surface->base.damage->dirty) - _cairo_xlib_surface_clear_shm (surface); - -done: - dec_idle(surface->shm); - return surface->shm; -} - -cairo_int_status_t -_cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface) -{ - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; - - if (!surface->fallback) { - if (surface->shm) - inc_idle (surface->shm); - return CAIRO_INT_STATUS_SUCCESS; - } - - if (surface->shm->damage->dirty) { - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface->shm; - cairo_xlib_display_t *display; - cairo_damage_t *damage; - GC gc; - - status = _cairo_xlib_display_acquire (surface->base.device, &display); - if (unlikely (status)) - return status; - - damage = _cairo_damage_reduce (shm->image.base.damage); - shm->image.base.damage = _cairo_damage_create (); - - TRACE ((stderr, "%s: flushing damage x %d\n", __FUNCTION__, - damage->region ? cairo_region_num_rectangles (damage->region) : 0)); - if (damage->status == CAIRO_STATUS_SUCCESS && damage->region) { - XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; - XRectangle *rects = stack_rects; - cairo_rectangle_int_t r; - int n_rects, i; - - n_rects = cairo_region_num_rectangles (damage->region); - if (n_rects == 0) - goto out; - - status = _cairo_xlib_surface_get_gc (display, surface, &gc); - if (unlikely (status)) - goto out; - - if (n_rects == 1) { - cairo_region_get_rectangle (damage->region, 0, &r); - _cairo_xlib_shm_surface_mark_active (surface->shm); - XCopyArea (display->display, - shm->pixmap, surface->drawable, gc, - r.x, r.y, - r.width, r.height, - r.x, r.y); - } else { - if (n_rects > ARRAY_LENGTH (stack_rects)) { - rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle)); - if (unlikely (rects == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - _cairo_xlib_surface_put_gc (display, surface, gc); - goto out; - } - } - for (i = 0; i < n_rects; i++) { - cairo_region_get_rectangle (damage->region, i, &r); - - rects[i].x = r.x; - rects[i].y = r.y; - rects[i].width = r.width; - rects[i].height = r.height; - } - XSetClipRectangles (display->display, gc, 0, 0, rects, i, YXBanded); - - _cairo_xlib_shm_surface_mark_active (surface->shm); - XCopyArea (display->display, - shm->pixmap, surface->drawable, gc, - 0, 0, - shm->image.width, shm->image.height, - 0, 0); - - if (damage->status == CAIRO_STATUS_SUCCESS && damage->region) - XSetClipMask (display->display, gc, None); - } - - _cairo_xlib_surface_put_gc (display, surface, gc); - } - -out: - _cairo_damage_destroy (damage); - cairo_device_release (&display->base); - } - - return status; -} - -cairo_surface_t * -_cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other, - pixman_format_code_t format, - int width, int height) -{ - cairo_surface_t *surface; - - surface = NULL; - if (has_shm (other)) - surface = &_cairo_xlib_shm_surface_create (other, format, width, height, - FALSE, has_shm_pixmaps (other))->image.base; - - return surface; -} - -cairo_surface_t * -_cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface, - pixman_format_code_t format, - int width, int height) -{ - if (! has_shm(surface)) - return NULL; - - return &_cairo_xlib_shm_surface_create (surface, format, width, height, - FALSE, 0)->image.base; -} - -cairo_surface_t * -_cairo_xlib_surface_create_similar_shm (void *other, - cairo_format_t format, - int width, int height) -{ - cairo_surface_t *surface; - - surface = _cairo_xlib_surface_create_shm (other, - _cairo_format_to_pixman_format_code (format), - width, height); - if (surface) { - if (! surface->is_clear) { - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface; - assert (shm->active == 0); - memset (shm->image.data, 0, shm->image.stride * shm->image.height); - shm->image.base.is_clear = TRUE; - } - } else - surface = cairo_image_surface_create (format, width, height); - - return surface; -} - -void -_cairo_xlib_shm_surface_mark_active (cairo_surface_t *_shm) -{ - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) _shm; - cairo_xlib_display_t *display = (cairo_xlib_display_t *) _shm->device; - - shm->active = NextRequest (display->display); -} - -void -_cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface, - XImage *ximage) -{ - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface; - int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; - cairo_format_masks_t image_masks; - int ret; - - ret = _pixman_format_to_masks (shm->image.pixman_format, &image_masks); - assert (ret); - - ximage->width = shm->image.width; - ximage->height = shm->image.height; - ximage->format = ZPixmap; - ximage->data = (char *) shm->image.data; - ximage->obdata = (char *)&shm->info->pool->shm; - ximage->byte_order = native_byte_order; - ximage->bitmap_unit = 32; /* always for libpixman */ - ximage->bitmap_bit_order = native_byte_order; - ximage->bitmap_pad = 32; /* always for libpixman */ - ximage->depth = shm->image.depth; - ximage->bytes_per_line = shm->image.stride; - ximage->bits_per_pixel = image_masks.bpp; - ximage->red_mask = image_masks.red_mask; - ximage->green_mask = image_masks.green_mask; - ximage->blue_mask = image_masks.blue_mask; - ximage->xoffset = 0; - - ret = XInitImage (ximage); - assert (ret != 0); -} - -void * -_cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface) -{ - cairo_xlib_display_t *display = (cairo_xlib_display_t *) surface->device; - cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface; - - display->shm->last_event = shm->active = NextRequest (display->display); - return &shm->info->pool->shm; -} - -Pixmap -_cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm; - - shm = (cairo_xlib_shm_surface_t *) surface; - return shm->pixmap; -} - -XRenderPictFormat * -_cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm; - - shm = (cairo_xlib_shm_surface_t *) surface; - if (shm->image.format != CAIRO_FORMAT_INVALID) - return _cairo_xlib_display_get_xrender_format ((cairo_xlib_display_t *)surface->device, - shm->image.format); - - return _cairo_xlib_display_get_xrender_format_for_pixman((cairo_xlib_display_t *)surface->device, - shm->image.pixman_format); -} - -cairo_bool_t -_cairo_xlib_shm_surface_is_active (cairo_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm; - - shm = (cairo_xlib_shm_surface_t *) surface; - if (shm->active == 0) - return FALSE; - - if (seqno_passed (shm->active, peek_processed (shm->image.base.device))) { - shm->active = 0; - return FALSE; - } - - return TRUE; -} - -cairo_bool_t -_cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface) -{ - cairo_xlib_shm_surface_t *shm; - - shm = (cairo_xlib_shm_surface_t *) surface; - return shm->idle > 0; -} - -#define XORG_VERSION_ENCODE(major,minor,patch,snap) \ - (((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap) - -static cairo_bool_t -has_broken_send_shm_event (cairo_xlib_display_t *display, - cairo_xlib_shm_display_t *shm) -{ - Display *dpy = display->display; - int (*old_handler) (Display *display, XErrorEvent *event); - XShmCompletionEvent ev; - XShmSegmentInfo info; - - info.shmid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | 0600); - if (info.shmid == -1) - return TRUE; - - info.readOnly = FALSE; - info.shmaddr = shmat (info.shmid, NULL, 0); - if (info.shmaddr == (char *) -1) { - shmctl (info.shmid, IPC_RMID, NULL); - return TRUE; - } - - ev.type = shm->event; - ev.send_event = 1; - ev.serial = 1; - ev.drawable = shm->window; - ev.major_code = shm->opcode; - ev.minor_code = X_ShmPutImage; - - ev.shmseg = info.shmid; - ev.offset = 0; - - assert (CAIRO_MUTEX_IS_LOCKED (_cairo_xlib_display_mutex)); - _x_error_occurred = FALSE; - - XLockDisplay (dpy); - XSync (dpy, False); - old_handler = XSetErrorHandler (_check_error_handler); - - XShmAttach (dpy, &info); - XSendEvent (dpy, ev.drawable, False, 0, (XEvent *)&ev); - XShmDetach (dpy, &info); - - XSync (dpy, False); - XSetErrorHandler (old_handler); - XUnlockDisplay (dpy); - - shmctl (info.shmid, IPC_RMID, NULL); - shmdt (info.shmaddr); - - return _x_error_occurred; -} - -static cairo_bool_t -xorg_has_buggy_send_shm_completion_event(cairo_xlib_display_t *display, - cairo_xlib_shm_display_t *shm) -{ - Display *dpy = display->display; - - /* As libXext sets the SEND_EVENT bit in the ShmCompletionEvent, - * the Xserver may crash if it does not take care when processing - * the event type. For instance versions of Xorg prior to 1.11.1 - * exhibited this bug, and was fixed by: - * - * commit 2d2dce558d24eeea0eb011ec9ebaa6c5c2273c39 - * Author: Sam Spilsbury - * Date: Wed Sep 14 09:58:34 2011 +0800 - * - * Remove the SendEvent bit (0x80) before doing range checks on event type. - */ - if (_cairo_xlib_vendor_is_xorg (dpy) && - VendorRelease (dpy) < XORG_VERSION_ENCODE(1,11,0,1)) - return TRUE; - - /* For everyone else check that no error is generated */ - return has_broken_send_shm_event (display, shm); -} - -void -_cairo_xlib_display_init_shm (cairo_xlib_display_t *display) -{ - cairo_xlib_shm_display_t *shm; - XSetWindowAttributes attr; - XExtCodes *codes; - int has_pixmap, scr; - - display->shm = NULL; - - if (!can_use_shm (display->display, &has_pixmap)) - return; - - shm = malloc (sizeof (*shm)); - if (unlikely (shm == NULL)) - return; - - codes = XInitExtension (display->display, SHMNAME); - if (codes == NULL) { - free (shm); - return; - } - - shm->opcode = codes ->major_opcode; - shm->event = codes->first_event; - - if (unlikely (_pqueue_init (&shm->info))) { - free (shm); - return; - } - - scr = DefaultScreen (display->display); - attr.override_redirect = 1; - shm->window = XCreateWindow (display->display, - DefaultRootWindow (display->display), -1, -1, - 1, 1, 0, - DefaultDepth (display->display, scr), - InputOutput, - DefaultVisual (display->display, scr), - CWOverrideRedirect, &attr); - shm->last_event = 0; - shm->last_request = 0; - - if (xorg_has_buggy_send_shm_completion_event(display, shm)) - has_pixmap = 0; - - shm->has_pixmaps = has_pixmap ? MIN_PIXMAP_SIZE : 0; - cairo_list_init (&shm->pool); - - cairo_list_init (&shm->surfaces); - - display->shm = shm; -} - -void -_cairo_xlib_display_fini_shm (cairo_xlib_display_t *display) -{ - cairo_xlib_shm_display_t *shm = display->shm; - - if (shm == NULL) - return; - - while (!cairo_list_is_empty (&shm->surfaces)) - cairo_surface_finish (&cairo_list_first_entry (&shm->surfaces, - cairo_xlib_shm_surface_t, - link)->image.base); - - _pqueue_fini (&shm->info); - - while (!cairo_list_is_empty (&shm->pool)) { - cairo_xlib_shm_t *pool; - - pool = cairo_list_first_entry (&shm->pool, cairo_xlib_shm_t, link); - _cairo_xlib_display_shm_pool_destroy (display, pool); - } - - if (display->display) - XDestroyWindow (display->display, shm->window); - - free (shm); - display->shm = NULL; -} -#endif -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface.c deleted file mode 100644 index 029a542b946..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-surface.c +++ /dev/null @@ -1,2383 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Behdad Esfahbod - * Chris Wilson - * Karl Tomlinson , Mozilla Corporation - */ - -/* Heed well the words of Owen Taylor: - * "Any patch that works around a render bug, or claims to, without a - * specific reference to the bug filed in bugzilla.freedesktop.org will - * never pass approval." - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" -#include "cairo-xlib-surface-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-clip-private.h" -#include "cairo-damage-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-list-inline.h" -#include "cairo-pattern-private.h" -#include "cairo-pixman-private.h" -#include "cairo-region-private.h" -#include "cairo-scaled-font-private.h" -#include "cairo-surface-snapshot-private.h" -#include "cairo-surface-subsurface-private.h" - -#include /* for XDestroyImage */ - -#include -#include -#include - -#define XLIB_COORD_MAX 32767 - -#define DEBUG 0 - -#if DEBUG -#define UNSUPPORTED(reason) \ - fprintf (stderr, \ - "cairo-xlib: hit unsupported operation %s(), line %d: %s\n", \ - __FUNCTION__, __LINE__, reason), \ - CAIRO_INT_STATUS_UNSUPPORTED -#else -#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED -#endif - -#if DEBUG -#include -static void CAIRO_PRINTF_FORMAT (2, 3) -_x_bread_crumb (Display *dpy, - const char *fmt, - ...) -{ - xReq *req; - char buf[2048]; - unsigned int len, len_dwords; - va_list ap; - - va_start (ap, fmt); - len = vsnprintf (buf, sizeof (buf), fmt, ap); - va_end (ap); - - buf[len++] = '\0'; - while (len & 3) - buf[len++] = '\0'; - - LockDisplay (dpy); - GetEmptyReq (NoOperation, req); - - len_dwords = len >> 2; - SetReqLen (req, len_dwords, len_dwords); - Data (dpy, buf, len); - - UnlockDisplay (dpy); - SyncHandle (); -} -#define X_DEBUG(x) _x_bread_crumb x -#else -#define X_DEBUG(x) -#endif - -/** - * SECTION:cairo-xlib - * @Title: XLib Surfaces - * @Short_Description: X Window System rendering using XLib - * @See_Also: #cairo_surface_t - * - * The XLib surface is used to render cairo graphics to X Window System - * windows and pixmaps using the XLib library. - * - * Note that the XLib surface automatically takes advantage of X render extension - * if it is available. - **/ - -/** - * CAIRO_HAS_XLIB_SURFACE: - * - * Defined if the Xlib surface backend is available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.0 - **/ - -/** - * SECTION:cairo-xlib-xrender - * @Title: XLib-XRender Backend - * @Short_Description: X Window System rendering using XLib and the X Render extension - * @See_Also: #cairo_surface_t - * - * The XLib surface is used to render cairo graphics to X Window System - * windows and pixmaps using the XLib and Xrender libraries. - * - * Note that the XLib surface automatically takes advantage of X Render extension - * if it is available. - **/ - -/** - * CAIRO_HAS_XLIB_XRENDER_SURFACE: - * - * Defined if the XLib/XRender surface functions are available. - * This macro can be used to conditionally compile backend-specific code. - * - * Since: 1.6 - **/ - -/* Xlib doesn't define a typedef, so define one ourselves */ -typedef int (*cairo_xlib_error_func_t) (Display *display, - XErrorEvent *event); - -static cairo_surface_t * -_cairo_xlib_surface_create_internal (cairo_xlib_screen_t *screen, - Drawable drawable, - Visual *visual, - XRenderPictFormat *xrender_format, - int width, - int height, - int depth); - -static cairo_bool_t -_cairo_surface_is_xlib (cairo_surface_t *surface); - -/* - * Instead of taking two round trips for each blending request, - * assume that if a particular drawable fails GetImage that it will - * fail for a "while"; use temporary pixmaps to avoid the errors - */ - -#define CAIRO_ASSUME_PIXMAP 20 - -static const XTransform identity = { { - { 1 << 16, 0x00000, 0x00000 }, - { 0x00000, 1 << 16, 0x00000 }, - { 0x00000, 0x00000, 1 << 16 }, -} }; - -static Visual * -_visual_for_xrender_format(Screen *screen, - XRenderPictFormat *xrender_format) -{ - int d, v; - - /* XXX Consider searching through the list of known cairo_visual_t for - * the reverse mapping. - */ - - for (d = 0; d < screen->ndepths; d++) { - Depth *d_info = &screen->depths[d]; - - if (d_info->depth != xrender_format->depth) - continue; - - for (v = 0; v < d_info->nvisuals; v++) { - Visual *visual = &d_info->visuals[v]; - - switch (visual->class) { - case TrueColor: - if (xrender_format->type != PictTypeDirect) - continue; - break; - - case DirectColor: - /* Prefer TrueColor to DirectColor. - * (XRenderFindVisualFormat considers both TrueColor and DirectColor - * Visuals to match the same PictFormat.) - */ - continue; - - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - if (xrender_format->type != PictTypeIndexed) - continue; - break; - } - - if (xrender_format == - XRenderFindVisualFormat (DisplayOfScreen(screen), visual)) - return visual; - } - } - - return NULL; -} - -static cairo_content_t -_xrender_format_to_content (XRenderPictFormat *xrender_format) -{ - cairo_content_t content; - - /* This only happens when using a non-Render server. Let's punt - * and say there's no alpha here. */ - if (xrender_format == NULL) - return CAIRO_CONTENT_COLOR; - - content = 0; - if (xrender_format->direct.alphaMask) - content |= CAIRO_CONTENT_ALPHA; - if (xrender_format->direct.redMask | - xrender_format->direct.greenMask | - xrender_format->direct.blueMask) - content |= CAIRO_CONTENT_COLOR; - - return content; -} - -static cairo_surface_t * -_cairo_xlib_surface_create_similar (void *abstract_src, - cairo_content_t content, - int width, - int height) -{ - cairo_xlib_surface_t *src = abstract_src; - XRenderPictFormat *xrender_format; - cairo_xlib_surface_t *surface; - cairo_xlib_display_t *display; - Pixmap pix; - - if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX) - return NULL; - - if (width == 0 || height == 0) - return NULL; - - if (_cairo_xlib_display_acquire (src->base.device, &display)) - return NULL; - - /* If we never found an XRenderFormat or if it isn't compatible - * with the content being requested, then we fallback to just - * constructing a cairo_format_t instead, (which will fairly - * arbitrarily pick a visual/depth for the similar surface. - */ - xrender_format = NULL; - if (src->xrender_format && - _xrender_format_to_content (src->xrender_format) == content) - { - xrender_format = src->xrender_format; - } - if (xrender_format == NULL) { - xrender_format = - _cairo_xlib_display_get_xrender_format (display, - _cairo_format_from_content (content)); - } - if (xrender_format) { - Visual *visual; - - /* We've got a compatible XRenderFormat now, which means the - * similar surface will match the existing surface as closely in - * visual/depth etc. as possible. */ - pix = XCreatePixmap (display->display, src->drawable, - width, height, xrender_format->depth); - - if (xrender_format == src->xrender_format) - visual = src->visual; - else - visual = _visual_for_xrender_format(src->screen->screen, - xrender_format); - - surface = (cairo_xlib_surface_t *) - _cairo_xlib_surface_create_internal (src->screen, pix, visual, - xrender_format, - width, height, - xrender_format->depth); - } - else - { - Screen *screen = src->screen->screen; - int depth; - - /* No compatible XRenderFormat, see if we can make an ordinary pixmap, - * so that we can still accelerate blits with XCopyArea(). */ - if (content != CAIRO_CONTENT_COLOR) { - cairo_device_release (&display->base); - return NULL; - } - - depth = DefaultDepthOfScreen (screen); - - pix = XCreatePixmap (display->display, RootWindowOfScreen (screen), - width <= 0 ? 1 : width, height <= 0 ? 1 : height, - depth); - - surface = (cairo_xlib_surface_t *) - _cairo_xlib_surface_create_internal (src->screen, pix, - DefaultVisualOfScreen (screen), - NULL, - width, height, depth); - } - - if (likely (surface->base.status == CAIRO_STATUS_SUCCESS)) - surface->owns_pixmap = TRUE; - else - XFreePixmap (display->display, pix); - - cairo_device_release (&display->base); - - return &surface->base; -} - -static void -_cairo_xlib_surface_discard_shm (cairo_xlib_surface_t *surface) -{ - if (surface->shm == NULL) - return; - - /* Force the flush for an external surface */ - if (!surface->owns_pixmap) - cairo_surface_flush (surface->shm); - - cairo_surface_finish (surface->shm); - cairo_surface_destroy (surface->shm); - surface->shm = NULL; - - _cairo_damage_destroy (surface->base.damage); - surface->base.damage = NULL; - - surface->fallback = 0; -} - -static cairo_status_t -_cairo_xlib_surface_finish (void *abstract_surface) -{ - cairo_xlib_surface_t *surface = abstract_surface; - cairo_status_t status; - cairo_xlib_display_t *display; - - cairo_list_del (&surface->link); - - status = _cairo_xlib_display_acquire (surface->base.device, &display); - if (unlikely (status)) - return status; - - X_DEBUG ((display->display, "finish (drawable=%x)", (unsigned int) surface->drawable)); - - if (surface->embedded_source.picture) - XRenderFreePicture (display->display, surface->embedded_source.picture); - if (surface->picture) - XRenderFreePicture (display->display, surface->picture); - - _cairo_xlib_surface_discard_shm (surface); - - if (surface->owns_pixmap) - XFreePixmap (display->display, surface->drawable); - - cairo_device_release (&display->base); - - return status; -} - -cairo_status_t -_cairo_xlib_surface_get_gc (cairo_xlib_display_t *display, - cairo_xlib_surface_t *surface, - GC *gc) -{ - *gc = _cairo_xlib_screen_get_gc (display, - surface->screen, - surface->depth, - surface->drawable); - if (unlikely (*gc == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} - -static int -_noop_error_handler (Display *display, - XErrorEvent *event) -{ - return False; /* return value is ignored */ -} - -static void -_swap_ximage_2bytes (XImage *ximage) -{ - int i, j; - char *line = ximage->data; - - for (j = ximage->height; j; j--) { - uint16_t *p = (uint16_t *) line; - for (i = ximage->width; i; i--) { - *p = bswap_16 (*p); - p++; - } - - line += ximage->bytes_per_line; - } -} - -static void -_swap_ximage_3bytes (XImage *ximage) -{ - int i, j; - char *line = ximage->data; - - for (j = ximage->height; j; j--) { - uint8_t *p = (uint8_t *) line; - for (i = ximage->width; i; i--) { - uint8_t tmp; - tmp = p[2]; - p[2] = p[0]; - p[0] = tmp; - p += 3; - } - - line += ximage->bytes_per_line; - } -} - -static void -_swap_ximage_4bytes (XImage *ximage) -{ - int i, j; - char *line = ximage->data; - - for (j = ximage->height; j; j--) { - uint32_t *p = (uint32_t *) line; - for (i = ximage->width; i; i--) { - *p = bswap_32 (*p); - p++; - } - - line += ximage->bytes_per_line; - } -} - -static void -_swap_ximage_nibbles (XImage *ximage) -{ - int i, j; - char *line = ximage->data; - - for (j = ximage->height; j; j--) { - uint8_t *p = (uint8_t *) line; - for (i = (ximage->width + 1) / 2; i; i--) { - *p = ((*p >> 4) & 0xf) | ((*p << 4) & ~0xf); - p++; - } - - line += ximage->bytes_per_line; - } -} - -static void -_swap_ximage_bits (XImage *ximage) -{ - int i, j; - char *line = ximage->data; - int unit = ximage->bitmap_unit; - int line_bytes = ((ximage->width + unit - 1) & ~(unit - 1)) / 8; - - for (j = ximage->height; j; j--) { - char *p = line; - - for (i = line_bytes; i; i--) { - char b = *p; - b = ((b << 1) & 0xaa) | ((b >> 1) & 0x55); - b = ((b << 2) & 0xcc) | ((b >> 2) & 0x33); - b = ((b << 4) & 0xf0) | ((b >> 4) & 0x0f); - *p = b; - - p++; - } - - line += ximage->bytes_per_line; - } -} - -static void -_swap_ximage_to_native (XImage *ximage) -{ - int unit_bytes = 0; - int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; - - if (ximage->bits_per_pixel == 1 && - ximage->bitmap_bit_order != native_byte_order) - { - _swap_ximage_bits (ximage); - if (ximage->bitmap_bit_order == ximage->byte_order) - return; - } - - if (ximage->byte_order == native_byte_order) - return; - - switch (ximage->bits_per_pixel) { - case 1: - unit_bytes = ximage->bitmap_unit / 8; - break; - case 4: - _swap_ximage_nibbles (ximage); - /* fall-through */ - case 8: - case 16: - case 20: - case 24: - case 28: - case 30: - case 32: - unit_bytes = (ximage->bits_per_pixel + 7) / 8; - break; - default: - /* This could be hit on some rare but possible cases. */ - ASSERT_NOT_REACHED; - } - - switch (unit_bytes) { - case 1: - break; - case 2: - _swap_ximage_2bytes (ximage); - break; - case 3: - _swap_ximage_3bytes (ximage); - break; - case 4: - _swap_ximage_4bytes (ximage); - break; - default: - ASSERT_NOT_REACHED; - } -} - - -/* Given a mask, (with a single sequence of contiguous 1 bits), return - * the number of 1 bits in 'width' and the number of 0 bits to its - * right in 'shift'. */ -static void -_characterize_field (uint32_t mask, int *width, int *shift) -{ - *width = _cairo_popcount (mask); - /* The final '& 31' is to force a 0 mask to result in 0 shift. */ - *shift = _cairo_popcount ((mask - 1) & ~mask) & 31; -} - -/* Convert a field of 'width' bits to 'new_width' bits with correct - * rounding. */ -static inline uint32_t -_resize_field (uint32_t field, int width, int new_width) -{ - if (width == 0) - return 0; - - if (width >= new_width) { - return field >> (width - new_width); - } else { - uint32_t result = field << (new_width - width); - - while (width < new_width) { - result |= result >> width; - width <<= 1; - } - return result; - } -} - -static inline uint32_t -_adjust_field (uint32_t field, int adjustment) -{ - return MIN (255, MAX(0, (int)field + adjustment)); -} - -/* Given a shifted field value, (described by 'width' and 'shift), - * resize it 8-bits and return that value. - * - * Note that the original field value must not have any non-field bits - * set. - */ -static inline uint32_t -_field_to_8 (uint32_t field, int width, int shift) -{ - return _resize_field (field >> shift, width, 8); -} - -static inline uint32_t -_field_to_8_undither (uint32_t field, int width, int shift, - int dither_adjustment) -{ - return _adjust_field (_field_to_8 (field, width, shift), - dither_adjustment>>width); -} - -/* Given an 8-bit value, convert it to a field of 'width', shift it up - * to 'shift, and return it. */ -static inline uint32_t -_field_from_8 (uint32_t field, int width, int shift) -{ - return _resize_field (field, 8, width) << shift; -} - -static inline uint32_t -_field_from_8_dither (uint32_t field, int width, int shift, - int8_t dither_adjustment) -{ - return _field_from_8 (_adjust_field (field, dither_adjustment>>width), width, shift); -} - -static inline uint32_t -_pseudocolor_from_rgb888_dither (cairo_xlib_visual_info_t *visual_info, - uint32_t r, uint32_t g, uint32_t b, - int8_t dither_adjustment) -{ - if (r == g && g == b) { - dither_adjustment /= RAMP_SIZE; - return visual_info->gray8_to_pseudocolor[_adjust_field (r, dither_adjustment)]; - } else { - dither_adjustment = visual_info->dither8_to_cube[dither_adjustment+128]; - return visual_info->cube_to_pseudocolor[visual_info->field8_to_cube[_adjust_field (r, dither_adjustment)]] - [visual_info->field8_to_cube[_adjust_field (g, dither_adjustment)]] - [visual_info->field8_to_cube[_adjust_field (b, dither_adjustment)]]; - } -} - -static inline uint32_t -_pseudocolor_to_rgb888 (cairo_xlib_visual_info_t *visual_info, - uint32_t pixel) -{ - uint32_t r, g, b; - pixel &= 0xff; - r = visual_info->colors[pixel].r; - g = visual_info->colors[pixel].g; - b = visual_info->colors[pixel].b; - return (r << 16) | - (g << 8) | - (b ); -} - -/* should range from -128 to 127 */ -#define X 16 -static const int8_t dither_pattern[4][4] = { - {-8*X, +0*X, -6*X, +2*X}, - {+4*X, -4*X, +6*X, -2*X}, - {-5*X, +4*X, -7*X, +1*X}, - {+7*X, -1*X, +5*X, -3*X} -}; -#undef X - -static int bits_per_pixel(cairo_xlib_surface_t *surface) -{ - if (surface->depth > 16) - return 32; - else if (surface->depth > 8) - return 16; - else if (surface->depth > 1) - return 8; - else - return 1; -} - -pixman_format_code_t -_pixman_format_for_xlib_surface (cairo_xlib_surface_t *surface) -{ - cairo_format_masks_t masks; - pixman_format_code_t format; - - masks.bpp = bits_per_pixel (surface); - masks.alpha_mask = surface->a_mask; - masks.red_mask = surface->r_mask; - masks.green_mask = surface->g_mask; - masks.blue_mask = surface->b_mask; - if (! _pixman_format_from_masks (&masks, &format)) - return 0; - - return format; -} - -static cairo_surface_t * -_get_image_surface (cairo_xlib_surface_t *surface, - const cairo_rectangle_int_t *extents, - int try_shm) -{ - cairo_int_status_t status; - cairo_image_surface_t *image = NULL; - XImage *ximage; - pixman_format_code_t pixman_format; - cairo_xlib_display_t *display; - - assert (extents->x >= 0); - assert (extents->y >= 0); - assert (extents->x + extents->width <= surface->width); - assert (extents->y + extents->height <= surface->height); - - if (surface->base.is_clear || - (surface->base.serial == 0 && surface->owns_pixmap)) - { - pixman_format = _pixman_format_for_xlib_surface (surface); - if (pixman_format) - { - return _cairo_image_surface_create_with_pixman_format (NULL, - pixman_format, - extents->width, - extents->height, - 0); - } - } - - if (surface->shm) { - cairo_image_surface_t *src = (cairo_image_surface_t *) surface->shm; - cairo_surface_t *dst; - cairo_surface_pattern_t pattern; - - dst = cairo_image_surface_create (src->format, - extents->width, extents->height); - if (unlikely (dst->status)) - return dst; - - _cairo_pattern_init_for_surface (&pattern, &src->base); - cairo_matrix_init_translate (&pattern.base.matrix, - extents->x, extents->y); - status = _cairo_surface_paint (dst, CAIRO_OPERATOR_SOURCE, &pattern.base, NULL); - _cairo_pattern_fini (&pattern.base); - if (unlikely (status)) { - cairo_surface_destroy (dst); - dst = _cairo_surface_create_in_error (status); - } - - return dst; - } - - status = _cairo_xlib_display_acquire (surface->base.device, &display); - if (status) - return _cairo_surface_create_in_error (status); - - pixman_format = _pixman_format_for_xlib_surface (surface); - if (try_shm && pixman_format) { - image = (cairo_image_surface_t *) - _cairo_xlib_surface_create_shm__image (surface, pixman_format, - extents->width, extents->height); - if (image && image->base.status == CAIRO_STATUS_SUCCESS) { - cairo_xlib_error_func_t old_handler; - XImage shm_image; - Bool success; - - _cairo_xlib_shm_surface_get_ximage (&image->base, &shm_image); - - old_handler = XSetErrorHandler (_noop_error_handler); - success = XShmGetImage (display->display, - surface->drawable, - &shm_image, - extents->x, extents->y, - AllPlanes); - XSetErrorHandler (old_handler); - - if (success) { - cairo_device_release (&display->base); - return &image->base; - } - - cairo_surface_destroy (&image->base); - } - } - - if (surface->use_pixmap == 0) { - cairo_xlib_error_func_t old_handler; - - old_handler = XSetErrorHandler (_noop_error_handler); - - ximage = XGetImage (display->display, - surface->drawable, - extents->x, extents->y, - extents->width, extents->height, - AllPlanes, ZPixmap); - - XSetErrorHandler (old_handler); - - /* If we get an error, the surface must have been a window, - * so retry with the safe code path. - */ - if (!ximage) - surface->use_pixmap = CAIRO_ASSUME_PIXMAP; - } else { - surface->use_pixmap--; - ximage = NULL; - } - - if (ximage == NULL) { - /* XGetImage from a window is dangerous because it can - * produce errors if the window is unmapped or partially - * outside the screen. We could check for errors and - * retry, but to keep things simple, we just create a - * temporary pixmap - */ - Pixmap pixmap; - GC gc; - - status = _cairo_xlib_surface_get_gc (display, surface, &gc); - if (unlikely (status)) - goto BAIL; - - pixmap = XCreatePixmap (display->display, - surface->drawable, - extents->width, extents->height, - surface->depth); - if (pixmap) { - XGCValues gcv; - - gcv.subwindow_mode = IncludeInferiors; - XChangeGC (display->display, gc, GCSubwindowMode, &gcv); - - XCopyArea (display->display, surface->drawable, pixmap, gc, - extents->x, extents->y, - extents->width, extents->height, - 0, 0); - - gcv.subwindow_mode = ClipByChildren; - XChangeGC (display->display, gc, GCSubwindowMode, &gcv); - - ximage = XGetImage (display->display, - pixmap, - 0, 0, - extents->width, extents->height, - AllPlanes, ZPixmap); - - XFreePixmap (display->display, pixmap); - } - - _cairo_xlib_surface_put_gc (display, surface, gc); - - if (ximage == NULL) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - } - - _swap_ximage_to_native (ximage); - - /* We can't use pixman to simply write to image if: - * (a) the pixels are not appropriately aligned, - * (b) pixman does not the pixel format, or - * (c) if the image is palettized and we need to convert. - */ - if (pixman_format && - ximage->bitmap_unit == 32 && ximage->bitmap_pad == 32 && - (surface->visual == NULL || surface->visual->class == TrueColor)) - { - image = (cairo_image_surface_t*) - _cairo_image_surface_create_with_pixman_format ((unsigned char *) ximage->data, - pixman_format, - ximage->width, - ximage->height, - ximage->bytes_per_line); - status = image->base.status; - if (unlikely (status)) - goto BAIL; - - /* Let the surface take ownership of the data */ - _cairo_image_surface_assume_ownership_of_data (image); - ximage->data = NULL; - } else { - /* The visual we are dealing with is not supported by the - * standard pixman formats. So we must first convert the data - * to a supported format. */ - - cairo_format_t format; - unsigned char *data; - uint32_t *row; - uint32_t in_pixel, out_pixel; - unsigned int rowstride; - uint32_t a_mask=0, r_mask=0, g_mask=0, b_mask=0; - int a_width=0, r_width=0, g_width=0, b_width=0; - int a_shift=0, r_shift=0, g_shift=0, b_shift=0; - int x, y, x0, y0, x_off, y_off; - cairo_xlib_visual_info_t *visual_info = NULL; - - if (surface->visual == NULL || surface->visual->class == TrueColor) { - cairo_bool_t has_alpha; - cairo_bool_t has_color; - - has_alpha = surface->a_mask; - has_color = (surface->r_mask || - surface->g_mask || - surface->b_mask); - - if (has_color) { - if (has_alpha) { - format = CAIRO_FORMAT_ARGB32; - } else { - format = CAIRO_FORMAT_RGB24; - } - } else { - /* XXX: Using CAIRO_FORMAT_A8 here would be more - * efficient, but would require slightly different code in - * the image conversion to put the alpha channel values - * into the right place. */ - format = CAIRO_FORMAT_ARGB32; - } - - a_mask = surface->a_mask; - r_mask = surface->r_mask; - g_mask = surface->g_mask; - b_mask = surface->b_mask; - - _characterize_field (a_mask, &a_width, &a_shift); - _characterize_field (r_mask, &r_width, &r_shift); - _characterize_field (g_mask, &g_width, &g_shift); - _characterize_field (b_mask, &b_width, &b_shift); - - } else { - format = CAIRO_FORMAT_RGB24; - - status = _cairo_xlib_screen_get_visual_info (display, - surface->screen, - surface->visual, - &visual_info); - if (unlikely (status)) - goto BAIL; - } - - image = (cairo_image_surface_t *) cairo_image_surface_create - (format, ximage->width, ximage->height); - status = image->base.status; - if (unlikely (status)) - goto BAIL; - - data = cairo_image_surface_get_data (&image->base); - rowstride = cairo_image_surface_get_stride (&image->base) >> 2; - row = (uint32_t *) data; - x0 = extents->x + surface->base.device_transform.x0; - y0 = extents->y + surface->base.device_transform.y0; - for (y = 0, y_off = y0 % ARRAY_LENGTH (dither_pattern); - y < ximage->height; - y++, y_off = (y_off+1) % ARRAY_LENGTH (dither_pattern)) { - const int8_t *dither_row = dither_pattern[y_off]; - for (x = 0, x_off = x0 % ARRAY_LENGTH (dither_pattern[0]); - x < ximage->width; - x++, x_off = (x_off+1) % ARRAY_LENGTH (dither_pattern[0])) { - int dither_adjustment = dither_row[x_off]; - - in_pixel = XGetPixel (ximage, x, y); - if (visual_info == NULL) { - out_pixel = ( - _field_to_8 (in_pixel & a_mask, a_width, a_shift) << 24 | - _field_to_8_undither (in_pixel & r_mask, r_width, r_shift, dither_adjustment) << 16 | - _field_to_8_undither (in_pixel & g_mask, g_width, g_shift, dither_adjustment) << 8 | - _field_to_8_undither (in_pixel & b_mask, b_width, b_shift, dither_adjustment)); - } else { - /* Undithering pseudocolor does not look better */ - out_pixel = _pseudocolor_to_rgb888 (visual_info, in_pixel); - } - row[x] = out_pixel; - } - row += rowstride; - } - cairo_surface_mark_dirty (&image->base); - } - - BAIL: - if (ximage) - XDestroyImage (ximage); - - cairo_device_release (&display->base); - - if (unlikely (status)) { - cairo_surface_destroy (&image->base); - return _cairo_surface_create_in_error (status); - } - - return &image->base; -} - -void -_cairo_xlib_surface_set_precision (cairo_xlib_surface_t *surface, - cairo_antialias_t antialias) -{ - cairo_xlib_display_t *display = surface->display; - int precision; - - if (display->force_precision != -1) - precision = display->force_precision; - else switch (antialias) { - default: - case CAIRO_ANTIALIAS_DEFAULT: - case CAIRO_ANTIALIAS_GRAY: - case CAIRO_ANTIALIAS_NONE: - case CAIRO_ANTIALIAS_FAST: - case CAIRO_ANTIALIAS_GOOD: - precision = PolyModeImprecise; - break; - case CAIRO_ANTIALIAS_BEST: - case CAIRO_ANTIALIAS_SUBPIXEL: - precision = PolyModePrecise; - break; - } - - if (surface->precision != precision) { - XRenderPictureAttributes pa; - - pa.poly_mode = precision; - XRenderChangePicture (display->display, surface->picture, - CPPolyMode, &pa); - - surface->precision = precision; - } -} - -void -_cairo_xlib_surface_ensure_picture (cairo_xlib_surface_t *surface) -{ - cairo_xlib_display_t *display = surface->display; - XRenderPictureAttributes pa; - int mask = 0; - - if (surface->picture) - return; - - if (display->force_precision != -1) - pa.poly_mode = display->force_precision; - else - pa.poly_mode = PolyModeImprecise; - if (pa.poly_mode) - mask |= CPPolyMode; - - surface->precision = pa.poly_mode; - surface->picture = XRenderCreatePicture (display->display, - surface->drawable, - surface->xrender_format, - mask, &pa); -} - -cairo_status_t -_cairo_xlib_surface_draw_image (cairo_xlib_surface_t *surface, - cairo_image_surface_t *image, - int src_x, - int src_y, - int width, - int height, - int dst_x, - int dst_y) -{ - cairo_xlib_display_t *display; - XImage ximage; - cairo_format_masks_t image_masks; - int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; - cairo_surface_t *shm_image = NULL; - pixman_image_t *pixman_image = NULL; - cairo_status_t status; - cairo_bool_t own_data = FALSE; - cairo_bool_t is_rgb_image; - GC gc; - - ximage.width = image->width; - ximage.height = image->height; - ximage.format = ZPixmap; - ximage.byte_order = native_byte_order; - ximage.bitmap_unit = 32; /* always for libpixman */ - ximage.bitmap_bit_order = native_byte_order; - ximage.bitmap_pad = 32; /* always for libpixman */ - ximage.depth = surface->depth; - ximage.red_mask = surface->r_mask; - ximage.green_mask = surface->g_mask; - ximage.blue_mask = surface->b_mask; - ximage.xoffset = 0; - ximage.obdata = NULL; - - status = _cairo_xlib_display_acquire (surface->base.device, &display); - if (unlikely (status)) - return status; - - is_rgb_image = _pixman_format_to_masks (image->pixman_format, &image_masks); - - if (is_rgb_image && - (image_masks.alpha_mask == surface->a_mask || surface->a_mask == 0) && - (image_masks.red_mask == surface->r_mask || surface->r_mask == 0) && - (image_masks.green_mask == surface->g_mask || surface->g_mask == 0) && - (image_masks.blue_mask == surface->b_mask || surface->b_mask == 0)) - { - int ret; - - ximage.bits_per_pixel = image_masks.bpp; - ximage.bytes_per_line = image->stride; - ximage.data = (char *)image->data; - if (image->base.device != surface->base.device) { - /* If PutImage will break the image up into chunks, prefer to - * send it all in one pass with ShmPutImage. For larger images, - * it is further advantageous to reduce the number of copies, - * albeit at the expense of more SHM bookkeeping. - */ - int max_request_size = XExtendedMaxRequestSize (display->display); - if (max_request_size == 0) - max_request_size = XMaxRequestSize (display->display); - if (max_request_size > 8192) - max_request_size = 8192; - if (width * height * 4 > max_request_size) { - shm_image = _cairo_xlib_surface_create_shm__image (surface, - image->pixman_format, - width, height); - if (shm_image && shm_image->status == CAIRO_STATUS_SUCCESS) { - cairo_image_surface_t *clone = (cairo_image_surface_t *) shm_image; - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, NULL, clone->pixman_image, - src_x, src_y, - 0, 0, - 0, 0, - width, height); - ximage.obdata = _cairo_xlib_shm_surface_get_obdata (shm_image); - ximage.data = (char *)clone->data; - ximage.bytes_per_line = clone->stride; - ximage.width = width; - ximage.height = height; - src_x = src_y = 0; - } - } - } else - ximage.obdata = _cairo_xlib_shm_surface_get_obdata (&image->base); - - ret = XInitImage (&ximage); - assert (ret != 0); - } - else if (surface->visual == NULL || surface->visual->class == TrueColor) - { - pixman_format_code_t intermediate_format; - int ret; - - image_masks.alpha_mask = surface->a_mask; - image_masks.red_mask = surface->r_mask; - image_masks.green_mask = surface->g_mask; - image_masks.blue_mask = surface->b_mask; - image_masks.bpp = bits_per_pixel (surface); - ret = _pixman_format_from_masks (&image_masks, &intermediate_format); - assert (ret); - - shm_image = _cairo_xlib_surface_create_shm__image (surface, - intermediate_format, - width, height); - if (shm_image && shm_image->status == CAIRO_STATUS_SUCCESS) { - cairo_image_surface_t *clone = (cairo_image_surface_t *) shm_image; - - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, - NULL, - clone->pixman_image, - src_x, src_y, - 0, 0, - 0, 0, - width, height); - - ximage.data = (char *) clone->data; - ximage.obdata = _cairo_xlib_shm_surface_get_obdata (&clone->base); - ximage.bytes_per_line = clone->stride; - } else { - pixman_image = pixman_image_create_bits (intermediate_format, - width, height, NULL, 0); - if (pixman_image == NULL) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - - pixman_image_composite32 (PIXMAN_OP_SRC, - image->pixman_image, - NULL, - pixman_image, - src_x, src_y, - 0, 0, - 0, 0, - width, height); - - ximage.data = (char *) pixman_image_get_data (pixman_image); - ximage.bytes_per_line = pixman_image_get_stride (pixman_image); - } - - ximage.width = width; - ximage.height = height; - ximage.bits_per_pixel = image_masks.bpp; - - ret = XInitImage (&ximage); - assert (ret != 0); - - src_x = src_y = 0; - } - else - { - unsigned int stride, rowstride; - int x, y, x0, y0, x_off, y_off; - uint32_t in_pixel, out_pixel, *row; - int i_a_width=0, i_r_width=0, i_g_width=0, i_b_width=0; - int i_a_shift=0, i_r_shift=0, i_g_shift=0, i_b_shift=0; - int o_a_width=0, o_r_width=0, o_g_width=0, o_b_width=0; - int o_a_shift=0, o_r_shift=0, o_g_shift=0, o_b_shift=0; - cairo_xlib_visual_info_t *visual_info = NULL; - cairo_bool_t true_color; - int ret; - - ximage.bits_per_pixel = bits_per_pixel(surface); - stride = CAIRO_STRIDE_FOR_WIDTH_BPP (ximage.width, - ximage.bits_per_pixel); - ximage.bytes_per_line = stride; - ximage.data = _cairo_malloc_ab (stride, ximage.height); - if (unlikely (ximage.data == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; - } - - own_data = TRUE; - - ret = XInitImage (&ximage); - assert (ret != 0); - - _characterize_field (image_masks.alpha_mask, &i_a_width, &i_a_shift); - _characterize_field (image_masks.red_mask , &i_r_width, &i_r_shift); - _characterize_field (image_masks.green_mask, &i_g_width, &i_g_shift); - _characterize_field (image_masks.blue_mask , &i_b_width, &i_b_shift); - - true_color = surface->visual == NULL || - surface->visual->class == TrueColor; - if (true_color) { - _characterize_field (surface->a_mask, &o_a_width, &o_a_shift); - _characterize_field (surface->r_mask, &o_r_width, &o_r_shift); - _characterize_field (surface->g_mask, &o_g_width, &o_g_shift); - _characterize_field (surface->b_mask, &o_b_width, &o_b_shift); - } else { - status = _cairo_xlib_screen_get_visual_info (display, - surface->screen, - surface->visual, - &visual_info); - if (unlikely (status)) - goto BAIL; - } - - rowstride = image->stride >> 2; - row = (uint32_t *) image->data; - x0 = dst_x + surface->base.device_transform.x0; - y0 = dst_y + surface->base.device_transform.y0; - for (y = 0, y_off = y0 % ARRAY_LENGTH (dither_pattern); - y < ximage.height; - y++, y_off = (y_off+1) % ARRAY_LENGTH (dither_pattern)) - { - const int8_t *dither_row = dither_pattern[y_off]; - - for (x = 0, x_off = x0 % ARRAY_LENGTH (dither_pattern[0]); - x < ximage.width; - x++, x_off = (x_off+1) % ARRAY_LENGTH (dither_pattern[0])) - { - int dither_adjustment = dither_row[x_off]; - int a, r, g, b; - - if (image_masks.bpp == 1) - in_pixel = !! (((uint8_t*)row)[x/8] & (1 << (x & 7))); - else if (image_masks.bpp <= 8) - in_pixel = ((uint8_t*)row)[x]; - else if (image_masks.bpp <= 16) - in_pixel = ((uint16_t*)row)[x]; - else if (image_masks.bpp <= 24) -#ifdef WORDS_BIGENDIAN - in_pixel = ((uint8_t*)row)[3 * x] << 16 | - ((uint8_t*)row)[3 * x + 1] << 8 | - ((uint8_t*)row)[3 * x + 2]; -#else - in_pixel = ((uint8_t*)row)[3 * x] | - ((uint8_t*)row)[3 * x + 1] << 8 | - ((uint8_t*)row)[3 * x + 2] << 16; -#endif - else - in_pixel = row[x]; - - /* If the incoming image has no alpha channel, then the input - * is opaque and the output should have the maximum alpha value. - * For all other channels, their absence implies 0. - */ - if (image_masks.alpha_mask == 0x0) - a = 0xff; - else - a = _field_to_8 (in_pixel & image_masks.alpha_mask, i_a_width, i_a_shift); - r = _field_to_8 (in_pixel & image_masks.red_mask , i_r_width, i_r_shift); - g = _field_to_8 (in_pixel & image_masks.green_mask, i_g_width, i_g_shift); - b = _field_to_8 (in_pixel & image_masks.blue_mask , i_b_width, i_b_shift); - - if (true_color) { - out_pixel = _field_from_8 (a, o_a_width, o_a_shift) | - _field_from_8_dither (r, o_r_width, o_r_shift, dither_adjustment) | - _field_from_8_dither (g, o_g_width, o_g_shift, dither_adjustment) | - _field_from_8_dither (b, o_b_width, o_b_shift, dither_adjustment); - } else { - out_pixel = _pseudocolor_from_rgb888_dither (visual_info, r, g, b, dither_adjustment); - } - - XPutPixel (&ximage, x, y, out_pixel); - } - - row += rowstride; - } - } - - status = _cairo_xlib_surface_get_gc (display, surface, &gc); - if (unlikely (status)) - goto BAIL; - - if (ximage.obdata) - XShmPutImage (display->display, surface->drawable, gc, &ximage, - src_x, src_y, dst_x, dst_y, width, height, True); - else - XPutImage (display->display, surface->drawable, gc, &ximage, - src_x, src_y, dst_x, dst_y, width, height); - - _cairo_xlib_surface_put_gc (display, surface, gc); - - BAIL: - cairo_device_release (&display->base); - - if (own_data) - free (ximage.data); - if (shm_image) - cairo_surface_destroy (shm_image); - if (pixman_image) - pixman_image_unref (pixman_image); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -_cairo_xlib_surface_source(void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_xlib_surface_t *surface = abstract_surface; - - if (extents) { - extents->x = extents->y = 0; - extents->width = surface->width; - extents->height = surface->height; - } - - return &surface->base; -} - -static cairo_status_t -_cairo_xlib_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_xlib_surface_t *surface = abstract_surface; - cairo_rectangle_int_t extents; - - *image_extra = NULL; - *image_out = (cairo_image_surface_t *) - _cairo_xlib_surface_get_shm (abstract_surface, FALSE); - if (*image_out) - return (*image_out)->base.status; - - extents.x = extents.y = 0; - extents.width = surface->width; - extents.height = surface->height; - - *image_out = (cairo_image_surface_t*) - _get_image_surface (surface, &extents, TRUE); - return (*image_out)->base.status; -} - -static cairo_surface_t * -_cairo_xlib_surface_snapshot (void *abstract_surface) -{ - cairo_xlib_surface_t *surface = abstract_surface; - cairo_rectangle_int_t extents; - - extents.x = extents.y = 0; - extents.width = surface->width; - extents.height = surface->height; - - return _get_image_surface (surface, &extents, FALSE); -} - -static void -_cairo_xlib_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image, - void *image_extra) -{ - cairo_xlib_surface_t *surface = abstract_surface; - - if (&image->base == surface->shm) - return; - - cairo_surface_destroy (&image->base); -} - -static cairo_image_surface_t * -_cairo_xlib_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_xlib_surface_t *surface = abstract_surface; - cairo_surface_t *image; - - image = _cairo_xlib_surface_get_shm (abstract_surface, FALSE); - if (image) { - assert (surface->base.damage); - surface->fallback++; - return _cairo_image_surface_map_to_image (image, extents); - } - - image = _get_image_surface (abstract_surface, extents, TRUE); - cairo_surface_set_device_offset (image, -extents->x, -extents->y); - - return (cairo_image_surface_t *) image; -} - -static cairo_int_status_t -_cairo_xlib_surface_unmap_image (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_xlib_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - if (surface->shm) { - cairo_rectangle_int_t r; - - assert (surface->fallback); - assert (surface->base.damage); - - r.x = image->base.device_transform_inverse.x0; - r.y = image->base.device_transform_inverse.y0; - r.width = image->width; - r.height = image->height; - - TRACE ((stderr, "%s: adding damage (%d,%d)x(%d,%d)\n", - __FUNCTION__, r.x, r.y, r.width, r.height)); - surface->shm->damage = - _cairo_damage_add_rectangle (surface->shm->damage, &r); - - return _cairo_image_surface_unmap_image (surface->shm, image); - } - - status = _cairo_xlib_surface_draw_image (abstract_surface, image, - 0, 0, - image->width, image->height, - image->base.device_transform_inverse.x0, - image->base.device_transform_inverse.y0); - - cairo_surface_finish (&image->base); - cairo_surface_destroy (&image->base); - - return status; -} - -static cairo_status_t -_cairo_xlib_surface_flush (void *abstract_surface, - unsigned flags) -{ - cairo_xlib_surface_t *surface = abstract_surface; - cairo_int_status_t status; - - if (flags) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_xlib_surface_put_shm (surface); - if (unlikely (status)) - return status; - - surface->fallback >>= 1; - if (surface->shm && _cairo_xlib_shm_surface_is_idle (surface->shm)) - _cairo_xlib_surface_discard_shm (surface); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_cairo_xlib_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_xlib_surface_t *surface = abstract_surface; - - rectangle->x = 0; - rectangle->y = 0; - - rectangle->width = surface->width; - rectangle->height = surface->height; - - return TRUE; -} - -static void -_cairo_xlib_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_xlib_surface_t *surface = abstract_surface; - - *options = *_cairo_xlib_screen_get_font_options (surface->screen); -} - -static inline cairo_int_status_t -get_compositor (cairo_xlib_surface_t **surface, - const cairo_compositor_t **compositor) -{ - cairo_xlib_surface_t *s = *surface; - cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS;; - - if (s->fallback) { - assert (s->base.damage != NULL); - assert (s->shm != NULL); - assert (s->shm->damage != NULL); - if (! _cairo_xlib_shm_surface_is_active (s->shm)) { - *surface = (cairo_xlib_surface_t *) s->shm; - *compositor = ((cairo_image_surface_t *) s->shm)->compositor; - s->fallback++; - } else { - status = _cairo_xlib_surface_put_shm (s); - s->fallback = 0; - *compositor = s->compositor; - } - } else - *compositor = s->compositor; - - return status; -} - -static cairo_int_status_t -_cairo_xlib_surface_paint (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_xlib_surface_t *surface = _surface; - const cairo_compositor_t *compositor; - cairo_int_status_t status; - - status = get_compositor (&surface, &compositor); - if (unlikely (status)) - return status; - - return _cairo_compositor_paint (compositor, &surface->base, - op, source, - clip); -} - -static cairo_int_status_t -_cairo_xlib_surface_mask (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_xlib_surface_t *surface = _surface; - const cairo_compositor_t *compositor; - cairo_int_status_t status; - - status = get_compositor (&surface, &compositor); - if (unlikely (status)) - return status; - - return _cairo_compositor_mask (compositor, &surface->base, - op, source, mask, - clip); -} - -static cairo_int_status_t -_cairo_xlib_surface_stroke (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_xlib_surface_t *surface = _surface; - const cairo_compositor_t *compositor; - cairo_int_status_t status; - - status = get_compositor (&surface, &compositor); - if (unlikely (status)) - return status; - - return _cairo_compositor_stroke (compositor, &surface->base, - op, source, - path, style, ctm, ctm_inverse, - tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_xlib_surface_fill (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_xlib_surface_t *surface = _surface; - const cairo_compositor_t *compositor; - cairo_int_status_t status; - - status = get_compositor (&surface, &compositor); - if (unlikely (status)) - return status; - - return _cairo_compositor_fill (compositor, &surface->base, - op, source, - path, fill_rule, tolerance, antialias, - clip); -} - -static cairo_int_status_t -_cairo_xlib_surface_glyphs (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_xlib_surface_t *surface = _surface; - const cairo_compositor_t *compositor; - cairo_int_status_t status; - - status = get_compositor (&surface, &compositor); - if (unlikely (status)) - return status; - - return _cairo_compositor_glyphs (compositor, &surface->base, - op, source, - glyphs, num_glyphs, scaled_font, - clip); -} - -static const cairo_surface_backend_t cairo_xlib_surface_backend = { - CAIRO_SURFACE_TYPE_XLIB, - _cairo_xlib_surface_finish, - - _cairo_default_context_create, - - _cairo_xlib_surface_create_similar, - _cairo_xlib_surface_create_similar_shm, - _cairo_xlib_surface_map_to_image, - _cairo_xlib_surface_unmap_image, - - _cairo_xlib_surface_source, - _cairo_xlib_surface_acquire_source_image, - _cairo_xlib_surface_release_source_image, - _cairo_xlib_surface_snapshot, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_xlib_surface_get_extents, - _cairo_xlib_surface_get_font_options, - - _cairo_xlib_surface_flush, - NULL, /* mark_dirty_rectangle */ - - _cairo_xlib_surface_paint, - _cairo_xlib_surface_mask, - _cairo_xlib_surface_stroke, - _cairo_xlib_surface_fill, - NULL, /* fill-stroke */ - _cairo_xlib_surface_glyphs, -}; - -/** - * _cairo_surface_is_xlib: - * @surface: a #cairo_surface_t - * - * Checks if a surface is a #cairo_xlib_surface_t - * - * Return value: True if the surface is an xlib surface - **/ -static cairo_bool_t -_cairo_surface_is_xlib (cairo_surface_t *surface) -{ - return surface->backend == &cairo_xlib_surface_backend; -} - -static cairo_surface_t * -_cairo_xlib_surface_create_internal (cairo_xlib_screen_t *screen, - Drawable drawable, - Visual *visual, - XRenderPictFormat *xrender_format, - int width, - int height, - int depth) -{ - cairo_xlib_surface_t *surface; - cairo_xlib_display_t *display; - cairo_status_t status; - - if (depth == 0) { - if (xrender_format) { - depth = xrender_format->depth; - - /* XXX find matching visual for core/dithering fallbacks? */ - } else if (visual) { - Screen *scr = screen->screen; - - if (visual == DefaultVisualOfScreen (scr)) { - depth = DefaultDepthOfScreen (scr); - } else { - int j, k; - - /* This is ugly, but we have to walk over all visuals - * for the display to find the correct depth. - */ - depth = 0; - for (j = 0; j < scr->ndepths; j++) { - Depth *d = &scr->depths[j]; - for (k = 0; k < d->nvisuals; k++) { - if (&d->visuals[k] == visual) { - depth = d->depth; - goto found; - } - } - } - } - } - - if (depth == 0) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); - -found: - ; - } - - surface = malloc (sizeof (cairo_xlib_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - status = _cairo_xlib_display_acquire (screen->device, &display); - if (unlikely (status)) { - free (surface); - return _cairo_surface_create_in_error (_cairo_error (status)); - } - - surface->display = display; - if (CAIRO_RENDER_HAS_CREATE_PICTURE (display)) { - if (!xrender_format) { - if (visual) { - xrender_format = XRenderFindVisualFormat (display->display, visual); - } else if (depth == 1) { - xrender_format = - _cairo_xlib_display_get_xrender_format (display, - CAIRO_FORMAT_A1); - } - } - } - - cairo_device_release (&display->base); - - _cairo_surface_init (&surface->base, - &cairo_xlib_surface_backend, - screen->device, - _xrender_format_to_content (xrender_format)); - - surface->screen = screen; - surface->compositor = display->compositor; - surface->shm = NULL; - surface->fallback = 0; - - surface->drawable = drawable; - surface->owns_pixmap = FALSE; - surface->use_pixmap = 0; - surface->width = width; - surface->height = height; - - surface->picture = None; - surface->precision = PolyModePrecise; - - surface->embedded_source.picture = None; - - surface->visual = visual; - surface->xrender_format = xrender_format; - surface->depth = depth; - - /* - * Compute the pixel format masks from either a XrenderFormat or - * else from a visual; failing that we assume the drawable is an - * alpha-only pixmap as it could only have been created that way - * through the cairo_xlib_surface_create_for_bitmap function. - */ - if (xrender_format) { - surface->a_mask = (unsigned long) - surface->xrender_format->direct.alphaMask - << surface->xrender_format->direct.alpha; - surface->r_mask = (unsigned long) - surface->xrender_format->direct.redMask - << surface->xrender_format->direct.red; - surface->g_mask = (unsigned long) - surface->xrender_format->direct.greenMask - << surface->xrender_format->direct.green; - surface->b_mask = (unsigned long) - surface->xrender_format->direct.blueMask - << surface->xrender_format->direct.blue; - } else if (visual) { - surface->a_mask = 0; - surface->r_mask = visual->red_mask; - surface->g_mask = visual->green_mask; - surface->b_mask = visual->blue_mask; - } else { - if (depth < 32) - surface->a_mask = (1 << depth) - 1; - else - surface->a_mask = 0xffffffff; - surface->r_mask = 0; - surface->g_mask = 0; - surface->b_mask = 0; - } - - cairo_list_add (&surface->link, &screen->surfaces); - - return &surface->base; -} - -static Screen * -_cairo_xlib_screen_from_visual (Display *dpy, Visual *visual) -{ - int s, d, v; - - for (s = 0; s < ScreenCount (dpy); s++) { - Screen *screen; - - screen = ScreenOfDisplay (dpy, s); - if (visual == DefaultVisualOfScreen (screen)) - return screen; - - for (d = 0; d < screen->ndepths; d++) { - Depth *depth; - - depth = &screen->depths[d]; - for (v = 0; v < depth->nvisuals; v++) - if (visual == &depth->visuals[v]) - return screen; - } - } - - return NULL; -} - -static cairo_bool_t valid_size (int width, int height) -{ - /* Note: the minimum surface size allowed in the X protocol is 1x1. - * However, as we historically did not check the minimum size we - * allowed applications to lie and set the correct size later (one hopes). - * To preserve compatability we must allow applications to use - * 0x0 surfaces. - */ - return (width >= 0 && width <= XLIB_COORD_MAX && - height >= 0 && height <= XLIB_COORD_MAX); -} - -/** - * cairo_xlib_surface_create: - * @dpy: an X Display - * @drawable: an X Drawable, (a Pixmap or a Window) - * @visual: the visual to use for drawing to @drawable. The depth - * of the visual must match the depth of the drawable. - * Currently, only TrueColor visuals are fully supported. - * @width: the current width of @drawable. - * @height: the current height of @drawable. - * - * Creates an Xlib surface that draws to the given drawable. - * The way that colors are represented in the drawable is specified - * by the provided visual. - * - * Note: If @drawable is a Window, then the function - * cairo_xlib_surface_set_size() must be called whenever the size of the - * window changes. - * - * When @drawable is a Window containing child windows then drawing to - * the created surface will be clipped by those child windows. When - * the created surface is used as a source, the contents of the - * children will be included. - * - * Return value: the newly created surface - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_xlib_surface_create (Display *dpy, - Drawable drawable, - Visual *visual, - int width, - int height) -{ - Screen *scr; - cairo_xlib_screen_t *screen; - cairo_status_t status; - - if (! valid_size (width, height)) { - /* you're lying, and you know it! */ - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - } - - scr = _cairo_xlib_screen_from_visual (dpy, visual); - if (scr == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); - - status = _cairo_xlib_screen_get (dpy, scr, &screen); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - X_DEBUG ((dpy, "create (drawable=%x)", (unsigned int) drawable)); - - return _cairo_xlib_surface_create_internal (screen, drawable, - visual, NULL, - width, height, 0); -} - -/** - * cairo_xlib_surface_create_for_bitmap: - * @dpy: an X Display - * @bitmap: an X Drawable, (a depth-1 Pixmap) - * @screen: the X Screen associated with @bitmap - * @width: the current width of @bitmap. - * @height: the current height of @bitmap. - * - * Creates an Xlib surface that draws to the given bitmap. - * This will be drawn to as a %CAIRO_FORMAT_A1 object. - * - * Return value: the newly created surface - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_xlib_surface_create_for_bitmap (Display *dpy, - Pixmap bitmap, - Screen *scr, - int width, - int height) -{ - cairo_xlib_screen_t *screen; - cairo_status_t status; - - if (! valid_size (width, height)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - status = _cairo_xlib_screen_get (dpy, scr, &screen); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - X_DEBUG ((dpy, "create_for_bitmap (drawable=%x)", (unsigned int) bitmap)); - - return _cairo_xlib_surface_create_internal (screen, bitmap, - NULL, NULL, - width, height, 1); -} - -#if CAIRO_HAS_XLIB_XRENDER_SURFACE -/** - * cairo_xlib_surface_create_with_xrender_format: - * @dpy: an X Display - * @drawable: an X Drawable, (a Pixmap or a Window) - * @screen: the X Screen associated with @drawable - * @format: the picture format to use for drawing to @drawable. The depth - * of @format must match the depth of the drawable. - * @width: the current width of @drawable. - * @height: the current height of @drawable. - * - * Creates an Xlib surface that draws to the given drawable. - * The way that colors are represented in the drawable is specified - * by the provided picture format. - * - * Note: If @drawable is a Window, then the function - * cairo_xlib_surface_set_size() must be called whenever the size of the - * window changes. - * - * Return value: the newly created surface - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_xlib_surface_create_with_xrender_format (Display *dpy, - Drawable drawable, - Screen *scr, - XRenderPictFormat *format, - int width, - int height) -{ - cairo_xlib_screen_t *screen; - cairo_status_t status; - - if (! valid_size (width, height)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); - - status = _cairo_xlib_screen_get (dpy, scr, &screen); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - X_DEBUG ((dpy, "create_with_xrender_format (drawable=%x)", (unsigned int) drawable)); - - return _cairo_xlib_surface_create_internal (screen, drawable, - _visual_for_xrender_format (scr, format), - format, width, height, 0); -} - -/** - * cairo_xlib_surface_get_xrender_format: - * @surface: an xlib surface - * - * Gets the X Render picture format that @surface uses for rendering with the - * X Render extension. If the surface was created by - * cairo_xlib_surface_create_with_xrender_format() originally, the return - * value is the format passed to that constructor. - * - * Return value: the XRenderPictFormat* associated with @surface, - * or %NULL if the surface is not an xlib surface - * or if the X Render extension is not available. - * - * Since: 1.6 - **/ -XRenderPictFormat * -cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface) -{ - cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *) surface; - - /* Throw an error for a non-xlib surface */ - if (! _cairo_surface_is_xlib (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return xlib_surface->xrender_format; -} -#endif - -/** - * cairo_xlib_surface_set_size: - * @surface: a #cairo_surface_t for the XLib backend - * @width: the new width of the surface - * @height: the new height of the surface - * - * Informs cairo of the new size of the X Drawable underlying the - * surface. For a surface created for a Window (rather than a Pixmap), - * this function must be called each time the size of the window - * changes. (For a subwindow, you are normally resizing the window - * yourself, but for a toplevel window, it is necessary to listen for - * ConfigureNotify events.) - * - * A Pixmap can never change size, so it is never necessary to call - * this function on a surface created for a Pixmap. - * - * Since: 1.0 - **/ -void -cairo_xlib_surface_set_size (cairo_surface_t *abstract_surface, - int width, - int height) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; - cairo_status_t status; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - if (surface->width == width && surface->height == height) - return; - - if (! valid_size (width, height)) { - _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_INVALID_SIZE)); - return; - } - - status = _cairo_surface_flush (abstract_surface, 0); - if (unlikely (status)) { - _cairo_surface_set_error (abstract_surface, status); - return; - } - - _cairo_xlib_surface_discard_shm (surface); - - surface->width = width; - surface->height = height; -} - -/** - * cairo_xlib_surface_set_drawable: - * @surface: a #cairo_surface_t for the XLib backend - * @drawable: the new drawable for the surface - * @width: the width of the new drawable - * @height: the height of the new drawable - * - * Informs cairo of a new X Drawable underlying the - * surface. The drawable must match the display, screen - * and format of the existing drawable or the application - * will get X protocol errors and will probably terminate. - * No checks are done by this function to ensure this - * compatibility. - * - * Since: 1.0 - **/ -void -cairo_xlib_surface_set_drawable (cairo_surface_t *abstract_surface, - Drawable drawable, - int width, - int height) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *)abstract_surface; - cairo_status_t status; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (! _cairo_surface_is_xlib (abstract_surface)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); - return; - } - - if (! valid_size (width, height)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_INVALID_SIZE)); - return; - } - - /* XXX: and what about this case? */ - if (surface->owns_pixmap) - return; - - status = _cairo_surface_flush (abstract_surface, 0); - if (unlikely (status)) { - _cairo_surface_set_error (abstract_surface, status); - return; - } - - if (surface->drawable != drawable) { - cairo_xlib_display_t *display; - - status = _cairo_xlib_display_acquire (surface->base.device, &display); - if (unlikely (status)) - return; - - X_DEBUG ((display->display, "set_drawable (drawable=%x)", (unsigned int) drawable)); - - if (surface->picture != None) { - XRenderFreePicture (display->display, surface->picture); - if (unlikely (status)) { - status = _cairo_surface_set_error (&surface->base, status); - return; - } - - surface->picture = None; - } - - cairo_device_release (&display->base); - - surface->drawable = drawable; - } - - if (surface->width != width || surface->height != height) { - _cairo_xlib_surface_discard_shm (surface); - - surface->width = width; - surface->height = height; - } -} - -/** - * cairo_xlib_surface_get_display: - * @surface: a #cairo_xlib_surface_t - * - * Get the X Display for the underlying X Drawable. - * - * Return value: the display. - * - * Since: 1.2 - **/ -Display * -cairo_xlib_surface_get_display (cairo_surface_t *abstract_surface) -{ - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return ((cairo_xlib_display_t *) abstract_surface->device)->display; -} - -/** - * cairo_xlib_surface_get_drawable: - * @surface: a #cairo_xlib_surface_t - * - * Get the underlying X Drawable used for the surface. - * - * Return value: the drawable. - * - * Since: 1.2 - **/ -Drawable -cairo_xlib_surface_get_drawable (cairo_surface_t *abstract_surface) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; - - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->drawable; -} - -/** - * cairo_xlib_surface_get_screen: - * @surface: a #cairo_xlib_surface_t - * - * Get the X Screen for the underlying X Drawable. - * - * Return value: the screen. - * - * Since: 1.2 - **/ -Screen * -cairo_xlib_surface_get_screen (cairo_surface_t *abstract_surface) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; - - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return surface->screen->screen; -} - -/** - * cairo_xlib_surface_get_visual: - * @surface: a #cairo_xlib_surface_t - * - * Gets the X Visual associated with @surface, suitable for use with the - * underlying X Drawable. If @surface was created by - * cairo_xlib_surface_create(), the return value is the Visual passed to that - * constructor. - * - * Return value: the Visual or %NULL if there is no appropriate Visual for - * @surface. - * - * Since: 1.2 - **/ -Visual * -cairo_xlib_surface_get_visual (cairo_surface_t *surface) -{ - cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *) surface; - - if (! _cairo_surface_is_xlib (surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return xlib_surface->visual; -} - -/** - * cairo_xlib_surface_get_depth: - * @surface: a #cairo_xlib_surface_t - * - * Get the number of bits used to represent each pixel value. - * - * Return value: the depth of the surface in bits. - * - * Since: 1.2 - **/ -int -cairo_xlib_surface_get_depth (cairo_surface_t *abstract_surface) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; - - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->depth; -} - -/** - * cairo_xlib_surface_get_width: - * @surface: a #cairo_xlib_surface_t - * - * Get the width of the X Drawable underlying the surface in pixels. - * - * Return value: the width of the surface in pixels. - * - * Since: 1.2 - **/ -int -cairo_xlib_surface_get_width (cairo_surface_t *abstract_surface) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; - - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->width; -} - -/** - * cairo_xlib_surface_get_height: - * @surface: a #cairo_xlib_surface_t - * - * Get the height of the X Drawable underlying the surface in pixels. - * - * Return value: the height of the surface in pixels. - * - * Since: 1.2 - **/ -int -cairo_xlib_surface_get_height (cairo_surface_t *abstract_surface) -{ - cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; - - if (! _cairo_surface_is_xlib (abstract_surface)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->height; -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-visual.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-visual.c deleted file mode 100644 index 863822eebbd..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-visual.c +++ /dev/null @@ -1,194 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl D. Worth - */ - -#include "cairoint.h" - -#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib-private.h" - -#include "cairo-error-private.h" -#include "cairo-list-inline.h" - -/* A perceptual distance metric between two colors. No sqrt needed - * since the square of the distance is still a valid metric. */ - -/* XXX: This is currently using linear distance in RGB space which is - * decidedly not perceptually linear. If someone cared a lot about the - * quality, they might choose something else here. Then again, they - * might also choose not to use a PseudoColor visual... */ -static inline int -_color_distance (unsigned short r1, unsigned short g1, unsigned short b1, - unsigned short r2, unsigned short g2, unsigned short b2) -{ - r1 >>= 8; g1 >>= 8; b1 >>= 8; - r2 >>= 8; g2 >>= 8; b2 >>= 8; - - return ((r2 - r1) * (r2 - r1) + - (g2 - g1) * (g2 - g1) + - (b2 - b1) * (b2 - b1)); -} - -cairo_status_t -_cairo_xlib_visual_info_create (Display *dpy, - int screen, - VisualID visualid, - cairo_xlib_visual_info_t **out) -{ - cairo_xlib_visual_info_t *info; - Colormap colormap = DefaultColormap (dpy, screen); - XColor color; - int gray, red, green, blue; - int i, j, distance, min_distance = 0; - XColor colors[256]; - unsigned short cube_index_to_short[CUBE_SIZE]; - unsigned short ramp_index_to_short[RAMP_SIZE]; - unsigned char gray_to_pseudocolor[RAMP_SIZE]; - - for (i = 0; i < CUBE_SIZE; i++) - cube_index_to_short[i] = (0xffff * i + ((CUBE_SIZE-1)>>1)) / (CUBE_SIZE-1); - for (i = 0; i < RAMP_SIZE; i++) - ramp_index_to_short[i] = (0xffff * i + ((RAMP_SIZE-1)>>1)) / (RAMP_SIZE-1); - - info = malloc (sizeof (cairo_xlib_visual_info_t)); - if (unlikely (info == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - cairo_list_init (&info->link); - info->visualid = visualid; - - /* Allocate a gray ramp and a color cube. - * Give up as soon as failures start. */ - - for (gray = 0; gray < RAMP_SIZE; gray++) { - color.red = color.green = color.blue = ramp_index_to_short[gray]; - if (! XAllocColor (dpy, colormap, &color)) - goto DONE_ALLOCATE; - } - - /* XXX: Could do this in a more clever order to have the best - * possible results from early failure. Could also choose a cube - * uniformly distributed in a better space than RGB. */ - for (red = 0; red < CUBE_SIZE; red++) { - for (green = 0; green < CUBE_SIZE; green++) { - for (blue = 0; blue < CUBE_SIZE; blue++) { - color.red = cube_index_to_short[red]; - color.green = cube_index_to_short[green]; - color.blue = cube_index_to_short[blue]; - color.pixel = 0; - color.flags = 0; - color.pad = 0; - if (! XAllocColor (dpy, colormap, &color)) - goto DONE_ALLOCATE; - } - } - } - DONE_ALLOCATE: - - for (i = 0; i < ARRAY_LENGTH (colors); i++) - colors[i].pixel = i; - XQueryColors (dpy, colormap, colors, ARRAY_LENGTH (colors)); - - /* Search for nearest colors within allocated colormap. */ - for (gray = 0; gray < RAMP_SIZE; gray++) { - for (i = 0; i < 256; i++) { - distance = _color_distance (ramp_index_to_short[gray], - ramp_index_to_short[gray], - ramp_index_to_short[gray], - colors[i].red, - colors[i].green, - colors[i].blue); - if (i == 0 || distance < min_distance) { - gray_to_pseudocolor[gray] = colors[i].pixel; - min_distance = distance; - if (!min_distance) - break; - } - } - } - for (red = 0; red < CUBE_SIZE; red++) { - for (green = 0; green < CUBE_SIZE; green++) { - for (blue = 0; blue < CUBE_SIZE; blue++) { - for (i = 0; i < 256; i++) { - distance = _color_distance (cube_index_to_short[red], - cube_index_to_short[green], - cube_index_to_short[blue], - colors[i].red, - colors[i].green, - colors[i].blue); - if (i == 0 || distance < min_distance) { - info->cube_to_pseudocolor[red][green][blue] = colors[i].pixel; - min_distance = distance; - if (!min_distance) - break; - } - } - } - } - } - - for (i = 0, j = 0; i < 256; i++) { - if (j < CUBE_SIZE - 1 && (((i<<8)+i) - (int)cube_index_to_short[j]) > ((int)cube_index_to_short[j+1] - ((i<<8)+i))) - j++; - info->field8_to_cube[i] = j; - - info->dither8_to_cube[i] = ((int)i - 128) / (CUBE_SIZE - 1); - } - for (i = 0, j = 0; i < 256; i++) { - if (j < RAMP_SIZE - 1 && (((i<<8)+i) - (int)ramp_index_to_short[j]) > ((int)ramp_index_to_short[j+1] - ((i<<8)+i))) - j++; - info->gray8_to_pseudocolor[i] = gray_to_pseudocolor[j]; - } - - for (i = 0; i < 256; i++) { - info->colors[i].a = 0xff; - info->colors[i].r = colors[i].red >> 8; - info->colors[i].g = colors[i].green >> 8; - info->colors[i].b = colors[i].blue >> 8; - } - - *out = info; - return CAIRO_STATUS_SUCCESS; -} - -void -_cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info) -{ - /* No need for XFreeColors() whilst using DefaultColormap */ - _cairo_list_del (&info->link); - free (info); -} - -#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xcb-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xcb-surface.c deleted file mode 100644 index af3e1557899..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xcb-surface.c +++ /dev/null @@ -1,847 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2009 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" - -#if CAIRO_HAS_XLIB_XCB_FUNCTIONS - -#include "cairo-xlib.h" -#include "cairo-xcb.h" - -#include "cairo-xcb-private.h" -#include "cairo-xlib-xrender-private.h" - -#include "cairo-default-context-private.h" -#include "cairo-list-inline.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-backend-private.h" - -#include -#include /* For XESetCloseDisplay */ - -struct cairo_xlib_xcb_display_t { - cairo_device_t base; - - Display *dpy; - cairo_device_t *xcb_device; - XExtCodes *codes; - - cairo_list_t link; -}; -typedef struct cairo_xlib_xcb_display_t cairo_xlib_xcb_display_t; - -/* List of all #cairo_xlib_xcb_display_t alive, - * protected by _cairo_xlib_display_mutex */ -static cairo_list_t displays; - -static cairo_surface_t * -_cairo_xlib_xcb_surface_create (void *dpy, - void *scr, - void *visual, - void *format, - cairo_surface_t *xcb); - -static cairo_surface_t * -_cairo_xlib_xcb_surface_create_similar (void *abstract_other, - cairo_content_t content, - int width, - int height) -{ - cairo_xlib_xcb_surface_t *other = abstract_other; - cairo_surface_t *xcb; - - xcb = other->xcb->base.backend->create_similar (other->xcb, content, width, height); - if (unlikely (xcb == NULL || xcb->status)) - return xcb; - - return _cairo_xlib_xcb_surface_create (other->display, other->screen, NULL, NULL, xcb); -} - -static cairo_status_t -_cairo_xlib_xcb_surface_finish (void *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - cairo_status_t status; - - cairo_surface_finish (&surface->xcb->base); - status = surface->xcb->base.status; - cairo_surface_destroy (&surface->xcb->base); - surface->xcb = NULL; - - return status; -} - -static cairo_surface_t * -_cairo_xlib_xcb_surface_create_similar_image (void *abstract_other, - cairo_format_t format, - int width, - int height) -{ - cairo_xlib_xcb_surface_t *surface = abstract_other; - return cairo_surface_create_similar_image (&surface->xcb->base, format, width, height); -} - -static cairo_image_surface_t * -_cairo_xlib_xcb_surface_map_to_image (void *abstract_surface, - const cairo_rectangle_int_t *extents) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_map_to_image (&surface->xcb->base, extents); -} - -static cairo_int_status_t -_cairo_xlib_xcb_surface_unmap (void *abstract_surface, - cairo_image_surface_t *image) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_unmap_image (&surface->xcb->base, image); -} - -static cairo_surface_t * -_cairo_xlib_xcb_surface_source (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_get_source (&surface->xcb->base, extents); -} - -static cairo_status_t -_cairo_xlib_xcb_surface_acquire_source_image (void *abstract_surface, - cairo_image_surface_t **image_out, - void **image_extra) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_acquire_source_image (&surface->xcb->base, - image_out, image_extra); -} - -static void -_cairo_xlib_xcb_surface_release_source_image (void *abstract_surface, - cairo_image_surface_t *image_out, - void *image_extra) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - _cairo_surface_release_source_image (&surface->xcb->base, image_out, image_extra); -} - -static cairo_bool_t -_cairo_xlib_xcb_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *extents) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_get_extents (&surface->xcb->base, extents); -} - -static void -_cairo_xlib_xcb_surface_get_font_options (void *abstract_surface, - cairo_font_options_t *options) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - cairo_surface_get_font_options (&surface->xcb->base, options); -} - -static cairo_int_status_t -_cairo_xlib_xcb_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_paint (&surface->xcb->base, op, source, clip); -} - -static cairo_int_status_t -_cairo_xlib_xcb_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_mask (&surface->xcb->base, op, source, mask, clip); -} - -static cairo_int_status_t -_cairo_xlib_xcb_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_stroke (&surface->xcb->base, - op, source, path, style, ctm, ctm_inverse, - tolerance, antialias, clip); -} - -static cairo_int_status_t -_cairo_xlib_xcb_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_fill (&surface->xcb->base, - op, source, path, - fill_rule, tolerance, - antialias, clip); -} - -static cairo_int_status_t -_cairo_xlib_xcb_surface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - return _cairo_surface_show_text_glyphs (&surface->xcb->base, op, source, - NULL, 0, - glyphs, num_glyphs, - NULL, 0, 0, - scaled_font, clip); -} - -static cairo_status_t -_cairo_xlib_xcb_surface_flush (void *abstract_surface, unsigned flags) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - /* We have to call cairo_surface_flush() to make sure snapshots are detached */ - return _cairo_surface_flush (&surface->xcb->base, flags); -} - -static cairo_status_t -_cairo_xlib_xcb_surface_mark_dirty (void *abstract_surface, - int x, int y, - int width, int height) -{ - cairo_xlib_xcb_surface_t *surface = abstract_surface; - cairo_surface_mark_dirty_rectangle (&surface->xcb->base, x, y, width, height); - return cairo_surface_status (&surface->xcb->base); -} - -static const cairo_surface_backend_t _cairo_xlib_xcb_surface_backend = { - CAIRO_SURFACE_TYPE_XLIB, - _cairo_xlib_xcb_surface_finish, - - _cairo_default_context_create, /* XXX */ - - _cairo_xlib_xcb_surface_create_similar, - _cairo_xlib_xcb_surface_create_similar_image, - _cairo_xlib_xcb_surface_map_to_image, - _cairo_xlib_xcb_surface_unmap, - - _cairo_xlib_xcb_surface_source, - _cairo_xlib_xcb_surface_acquire_source_image, - _cairo_xlib_xcb_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_xlib_xcb_surface_get_extents, - _cairo_xlib_xcb_surface_get_font_options, - - _cairo_xlib_xcb_surface_flush, - _cairo_xlib_xcb_surface_mark_dirty, - - _cairo_xlib_xcb_surface_paint, - _cairo_xlib_xcb_surface_mask, - _cairo_xlib_xcb_surface_stroke, - _cairo_xlib_xcb_surface_fill, - NULL, /* fill_stroke */ - _cairo_xlib_xcb_surface_glyphs, -}; - -static void -_cairo_xlib_xcb_display_finish (void *abstract_display) -{ - cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) abstract_display; - - CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); - cairo_list_del (&display->link); - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - - cairo_device_destroy (display->xcb_device); - display->xcb_device = NULL; - - XESetCloseDisplay (display->dpy, display->codes->extension, NULL); - /* Drop the reference from _cairo_xlib_xcb_device_create */ - cairo_device_destroy (&display->base); -} - -static int -_cairo_xlib_xcb_close_display(Display *dpy, XExtCodes *codes) -{ - cairo_xlib_xcb_display_t *display; - - CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); - cairo_list_foreach_entry (display, - cairo_xlib_xcb_display_t, - &displays, - link) - { - if (display->dpy == dpy) - { - /* _cairo_xlib_xcb_display_finish will lock the mutex again - * -> deadlock (This mutex isn't recursive) */ - cairo_device_reference (&display->base); - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - - /* Make sure the xcb and xlib-xcb devices are finished */ - cairo_device_finish (display->xcb_device); - cairo_device_finish (&display->base); - - cairo_device_destroy (&display->base); - return 0; - } - } - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - - return 0; -} - -static const cairo_device_backend_t _cairo_xlib_xcb_device_backend = { - CAIRO_DEVICE_TYPE_XLIB, - - NULL, - NULL, - - NULL, /* flush */ - _cairo_xlib_xcb_display_finish, - free, /* destroy */ -}; - -static cairo_device_t * -_cairo_xlib_xcb_device_create (Display *dpy, cairo_device_t *xcb_device) -{ - cairo_xlib_xcb_display_t *display = NULL; - cairo_device_t *device; - - if (xcb_device == NULL) - return NULL; - - CAIRO_MUTEX_INITIALIZE (); - - CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); - if (displays.next == NULL) { - cairo_list_init (&displays); - } - - cairo_list_foreach_entry (display, - cairo_xlib_xcb_display_t, - &displays, - link) - { - if (display->dpy == dpy) { - /* Maintain MRU order. */ - if (displays.next != &display->link) - cairo_list_move (&display->link, &displays); - - /* Grab a reference for our caller */ - device = cairo_device_reference (&display->base); - assert (display->xcb_device == xcb_device); - goto unlock; - } - } - - display = malloc (sizeof (cairo_xlib_xcb_display_t)); - if (unlikely (display == NULL)) { - device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); - goto unlock; - } - - display->codes = XAddExtension (dpy); - if (unlikely (display->codes == NULL)) { - device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); - free (display); - goto unlock; - } - - _cairo_device_init (&display->base, &_cairo_xlib_xcb_device_backend); - - XESetCloseDisplay (dpy, display->codes->extension, _cairo_xlib_xcb_close_display); - /* Add a reference for _cairo_xlib_xcb_display_finish. This basically means - * that the device's reference count never drops to zero - * as long as our Display* is alive. We need this because there is no - * "XDelExtension" to undo XAddExtension and having lots of registered - * extensions slows down libX11. */ - cairo_device_reference (&display->base); - - display->dpy = dpy; - display->xcb_device = cairo_device_reference(xcb_device); - - cairo_list_add (&display->link, &displays); - device = &display->base; - -unlock: - CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); - - return device; -} - -static cairo_surface_t * -_cairo_xlib_xcb_surface_create (void *dpy, - void *scr, - void *visual, - void *format, - cairo_surface_t *xcb) -{ - cairo_xlib_xcb_surface_t *surface; - - if (unlikely (xcb->status)) - return xcb; - - surface = malloc (sizeof (*surface)); - if (unlikely (surface == NULL)) { - cairo_surface_destroy (xcb); - return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); - } - - _cairo_surface_init (&surface->base, - &_cairo_xlib_xcb_surface_backend, - _cairo_xlib_xcb_device_create (dpy, xcb->device), - xcb->content); - - /* _cairo_surface_init() got another reference to the device, drop ours */ - cairo_device_destroy (surface->base.device); - - surface->display = dpy; - surface->screen = scr; - surface->visual = visual; - surface->format = format; - surface->xcb = (cairo_xcb_surface_t *) xcb; - - return &surface->base; -} - -static Screen * -_cairo_xlib_screen_from_visual (Display *dpy, Visual *visual) -{ - int s, d, v; - - for (s = 0; s < ScreenCount (dpy); s++) { - Screen *screen; - - screen = ScreenOfDisplay (dpy, s); - if (visual == DefaultVisualOfScreen (screen)) - return screen; - - for (d = 0; d < screen->ndepths; d++) { - Depth *depth; - - depth = &screen->depths[d]; - for (v = 0; v < depth->nvisuals; v++) - if (visual == &depth->visuals[v]) - return screen; - } - } - - return NULL; -} - -cairo_surface_t * -cairo_xlib_surface_create (Display *dpy, - Drawable drawable, - Visual *visual, - int width, - int height) -{ - Screen *scr; - xcb_visualtype_t xcb_visual; - - scr = _cairo_xlib_screen_from_visual (dpy, visual); - if (scr == NULL) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); - - xcb_visual.visual_id = visual->visualid; -#if defined(__cplusplus) || defined(c_plusplus) - xcb_visual._class = visual->c_class; -#else - xcb_visual._class = visual->class; -#endif - xcb_visual.bits_per_rgb_value = visual->bits_per_rgb; - xcb_visual.colormap_entries = visual->map_entries; - xcb_visual.red_mask = visual->red_mask; - xcb_visual.green_mask = visual->green_mask; - xcb_visual.blue_mask = visual->blue_mask; - - return _cairo_xlib_xcb_surface_create (dpy, scr, visual, NULL, - cairo_xcb_surface_create (XGetXCBConnection (dpy), - drawable, - &xcb_visual, - width, height)); -} - -static xcb_screen_t * -_cairo_xcb_screen_from_root (xcb_connection_t *connection, - xcb_window_t id) -{ - xcb_screen_iterator_t s; - - s = xcb_setup_roots_iterator (xcb_get_setup (connection)); - for (; s.rem; xcb_screen_next (&s)) { - if (s.data->root == id) - return s.data; - } - - return NULL; -} - -cairo_surface_t * -cairo_xlib_surface_create_for_bitmap (Display *dpy, - Pixmap bitmap, - Screen *scr, - int width, - int height) -{ - xcb_connection_t *connection = XGetXCBConnection (dpy); - xcb_screen_t *screen = _cairo_xcb_screen_from_root (connection, (xcb_window_t) scr->root); - return _cairo_xlib_xcb_surface_create (dpy, scr, NULL, NULL, - cairo_xcb_surface_create_for_bitmap (connection, - screen, - bitmap, - width, height)); -} - -#if CAIRO_HAS_XLIB_XRENDER_SURFACE -cairo_surface_t * -cairo_xlib_surface_create_with_xrender_format (Display *dpy, - Drawable drawable, - Screen *scr, - XRenderPictFormat *format, - int width, - int height) -{ - xcb_render_pictforminfo_t xcb_format; - xcb_connection_t *connection; - xcb_screen_t *screen; - - xcb_format.id = format->id; - xcb_format.type = format->type; - xcb_format.depth = format->depth; - xcb_format.direct.red_shift = format->direct.red; - xcb_format.direct.red_mask = format->direct.redMask; - xcb_format.direct.green_shift = format->direct.green; - xcb_format.direct.green_mask = format->direct.greenMask; - xcb_format.direct.blue_shift = format->direct.blue; - xcb_format.direct.blue_mask = format->direct.blueMask; - xcb_format.direct.alpha_shift = format->direct.alpha; - xcb_format.direct.alpha_mask = format->direct.alphaMask; - xcb_format.colormap = format->colormap; - - connection = XGetXCBConnection (dpy); - screen = _cairo_xcb_screen_from_root (connection, (xcb_window_t) scr->root); - - return _cairo_xlib_xcb_surface_create (dpy, scr, NULL, format, - cairo_xcb_surface_create_with_xrender_format (connection, screen, - drawable, - &xcb_format, - width, height)); -} - -XRenderPictFormat * -cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface) -{ - cairo_xlib_xcb_surface_t *xlib_surface = (cairo_xlib_xcb_surface_t *) surface; - - /* Throw an error for a non-xlib surface */ - if (surface->type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return xlib_surface->format; -} -#endif - -void -cairo_xlib_surface_set_size (cairo_surface_t *abstract_surface, - int width, - int height) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - cairo_status_t status; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - status = _cairo_surface_set_error (abstract_surface, - CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return; - } - - cairo_xcb_surface_set_size (&surface->xcb->base, width, height); - if (unlikely (surface->xcb->base.status)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (surface->xcb->base.status)); - } -} - -void -cairo_xlib_surface_set_drawable (cairo_surface_t *abstract_surface, - Drawable drawable, - int width, - int height) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *)abstract_surface; - cairo_status_t status; - - if (unlikely (abstract_surface->status)) - return; - if (unlikely (abstract_surface->finished)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - return; - } - - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - status = _cairo_surface_set_error (abstract_surface, - CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return; - } - - cairo_xcb_surface_set_drawable (&surface->xcb->base, drawable, width, height); - if (unlikely (surface->xcb->base.status)) { - status = _cairo_surface_set_error (abstract_surface, - _cairo_error (surface->xcb->base.status)); - } -} - -Display * -cairo_xlib_surface_get_display (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return surface->display; -} - -Drawable -cairo_xlib_surface_get_drawable (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (unlikely (abstract_surface->finished)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); - return 0; - } - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - /* This can happen when e.g. create_similar falls back to an image surface - * because we don't have the RENDER extension. */ - if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->xcb->drawable; -} - -Screen * -cairo_xlib_surface_get_screen (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return surface->screen; -} - -Visual * -cairo_xlib_surface_get_visual (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return NULL; - } - - return surface->visual; -} - -int -cairo_xlib_surface_get_depth (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (unlikely (abstract_surface->finished)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); - return 0; - } - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - /* This can happen when e.g. create_similar falls back to an image surface - * because we don't have the RENDER extension. */ - if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->xcb->depth; -} - -int -cairo_xlib_surface_get_width (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (unlikely (abstract_surface->finished)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); - return 0; - } - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - /* This can happen when e.g. create_similar falls back to an image surface - * because we don't have the RENDER extension. */ - if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->xcb->width; -} - -int -cairo_xlib_surface_get_height (cairo_surface_t *abstract_surface) -{ - cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; - - if (unlikely (abstract_surface->finished)) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); - return 0; - } - if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - /* This can happen when e.g. create_similar falls back to an image surface - * because we don't have the RENDER extension. */ - if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { - _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - return 0; - } - - return surface->xcb->height; -} - -void -cairo_xlib_device_debug_cap_xrender_version (cairo_device_t *device, - int major, int minor) -{ - cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) device; - - if (device == NULL || device->status) - return; - - if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) - return; - - cairo_xcb_device_debug_cap_xrender_version (display->xcb_device, - major, minor); -} - -void -cairo_xlib_device_debug_set_precision (cairo_device_t *device, - int precision) -{ - cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) device; - - if (device == NULL || device->status) - return; - if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return; - } - - cairo_xcb_device_debug_set_precision (display->xcb_device, precision); -} - -int -cairo_xlib_device_debug_get_precision (cairo_device_t *device) -{ - cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) device; - - if (device == NULL || device->status) - return -1; - if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { - cairo_status_t status; - - status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - (void) status; - return -1; - } - - return cairo_xcb_device_debug_get_precision (display->xcb_device); -} - -#endif /* CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender-private.h deleted file mode 100644 index 90769467b2d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender-private.h +++ /dev/null @@ -1,1173 +0,0 @@ -/* Cairo - a vector graphics library with display and print output - * - * Copyright © 2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - */ - -#ifndef CAIRO_XLIB_XRENDER_PRIVATE_H -#define CAIRO_XLIB_XRENDER_PRIVATE_H - -#include "cairo-features.h" -#include "cairo-compiler-private.h" - -#include - -/* These prototypes are used when defining interfaces missing from the - * render headers. As it happens, it is the case that all libxrender - * functions take a pointer as first argument. */ - -__attribute__((__unused__)) static void _void_consume (void *p, ...) { } -__attribute__((__unused__)) static void * _voidp_consume (void *p, ...) { return (void *)0; } -__attribute__((__unused__)) static int _int_consume (void *p, ...) { return 0; } -__attribute__((__unused__)) static void _void_consume_free (Display *p, XID n) { } - - -#if CAIRO_HAS_XLIB_XRENDER_SURFACE - -#include "cairo-xlib-xrender.h" - -#include -#include - -/* We require Render >= 0.6. The following defines were only added in - * 0.10. Make sure they are defined. - */ - -/* Filters included in 0.10 */ -#ifndef FilterConvolution -#define FilterConvolution "convolution" -#endif - -/* Extended repeat attributes included in 0.10 */ -#ifndef RepeatNone -#define RepeatNone 0 -#define RepeatNormal 1 -#define RepeatPad 2 -#define RepeatReflect 3 -#endif - - -#ifndef PictOptBlendMinimum -/* - * Operators only available in version 0.11 - */ -#define PictOpBlendMinimum 0x30 -#define PictOpMultiply 0x30 -#define PictOpScreen 0x31 -#define PictOpOverlay 0x32 -#define PictOpDarken 0x33 -#define PictOpLighten 0x34 -#define PictOpColorDodge 0x35 -#define PictOpColorBurn 0x36 -#define PictOpHardLight 0x37 -#define PictOpSoftLight 0x38 -#define PictOpDifference 0x39 -#define PictOpExclusion 0x3a -#define PictOpHSLHue 0x3b -#define PictOpHSLSaturation 0x3c -#define PictOpHSLColor 0x3d -#define PictOpHSLLuminosity 0x3e -#define PictOpBlendMaximum 0x3e -#endif - -#if !HAVE_XRENDERCREATESOLIDFILL -#define XRenderCreateSolidFill _int_consume -#endif - -#if !HAVE_XRENDERCREATELINEARGRADIENT -#define XRenderCreateLinearGradient _int_consume - -typedef struct _XLinearGradient { - XPointFixed p1; - XPointFixed p2; -} XLinearGradient; -#endif - -#if !HAVE_XRENDERCREATERADIALGRADIENT -#define XRenderCreateRadialGradient _int_consume - -typedef struct _XCircle { - XFixed x; - XFixed y; - XFixed radius; -} XCircle; -typedef struct _XRadialGradient { - XCircle inner; - XCircle outer; -} XRadialGradient; -#endif - -#if !HAVE_XRENDERCREATECONICALGRADIENT -#define XRenderCreateConicalGradient _int_consume - -typedef struct _XConicalGradient { - XPointFixed center; - XFixed angle; /* in degrees */ -} XConicalGradient; -#endif - - -#else /* !CAIRO_HAS_XLIB_XRENDER_SURFACE */ - -/* Provide dummy symbols and macros to get it compile and take the fallback - * route, just like as if Xrender is not available in the server at run-time. */ - - -/* Functions */ - -#define XRenderQueryExtension _int_consume -#define XRenderQueryVersion _int_consume -#define XRenderQueryFormats _int_consume -#define XRenderQuerySubpixelOrder _int_consume -#define XRenderSetSubpixelOrder _int_consume -#define XRenderFindVisualFormat _voidp_consume -#define XRenderFindFormat _voidp_consume -#define XRenderFindStandardFormat _voidp_consume -#define XRenderQueryPictIndexValues _voidp_consume -#define XRenderCreatePicture _int_consume -#define XRenderChangePicture _void_consume -#define XRenderSetPictureClipRectangles _void_consume -#define XRenderSetPictureClipRegion _void_consume -#define XRenderSetPictureTransform _void_consume -#define XRenderFreePicture _void_consume_free -#define XRenderComposite _void_consume -#define XRenderCreateGlyphSet _int_consume -#define XRenderReferenceGlyphSet _int_consume -#define XRenderFreeGlyphSet _void_consume_free -#define XRenderAddGlyphs _void_consume -#define XRenderFreeGlyphs _void_consume -#define XRenderCompositeString8 _void_consume -#define XRenderCompositeString16 _void_consume -#define XRenderCompositeString32 _void_consume -#define XRenderCompositeText8 (cairo_xrender_composite_text_func_t) _void_consume -#define XRenderCompositeText16 _void_consume -#define XRenderCompositeText32 _void_consume -#define XRenderFillRectangle _void_consume -#define XRenderFillRectangles _void_consume -#define XRenderCompositeTrapezoids _void_consume -#define XRenderCompositeTriangles _void_consume -#define XRenderCompositeTriStrip _void_consume -#define XRenderCompositeTriFan _void_consume -#define XRenderCompositeDoublePoly _void_consume -#define XRenderParseColor _int_consume -#define XRenderCreateCursor _int_consume -#define XRenderQueryFilters _voidp_consume -#define XRenderSetPictureFilter _void_consume -#define XRenderCreateAnimCursor _int_consume -#define XRenderAddTraps _void_consume -#define XRenderCreateSolidFill _int_consume -#define XRenderCreateLinearGradient _int_consume -#define XRenderCreateRadialGradient _int_consume -#define XRenderCreateConicalGradient _int_consume - -#define cairo_xlib_surface_create_with_xrender_format _voidp_consume - - - -/* The rest of this file is copied from various Xrender header files, with - * the following copyright/license information: - * - * Copyright © 2000 SuSE, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Keith Packard, SuSE, Inc. - */ - - -/* Copied from X11/extensions/render.h */ - -typedef unsigned long Glyph; -typedef unsigned long GlyphSet; -typedef unsigned long Picture; -typedef unsigned long PictFormat; - -#define BadPictFormat 0 -#define BadPicture 1 -#define BadPictOp 2 -#define BadGlyphSet 3 -#define BadGlyph 4 -#define RenderNumberErrors (BadGlyph+1) - -#define PictTypeIndexed 0 -#define PictTypeDirect 1 - -#define PictOpMinimum 0 -#define PictOpClear 0 -#define PictOpSrc 1 -#define PictOpDst 2 -#define PictOpOver 3 -#define PictOpOverReverse 4 -#define PictOpIn 5 -#define PictOpInReverse 6 -#define PictOpOut 7 -#define PictOpOutReverse 8 -#define PictOpAtop 9 -#define PictOpAtopReverse 10 -#define PictOpXor 11 -#define PictOpAdd 12 -#define PictOpSaturate 13 -#define PictOpMaximum 13 - -/* - * Operators only available in version 0.2 - */ -#define PictOpDisjointMinimum 0x10 -#define PictOpDisjointClear 0x10 -#define PictOpDisjointSrc 0x11 -#define PictOpDisjointDst 0x12 -#define PictOpDisjointOver 0x13 -#define PictOpDisjointOverReverse 0x14 -#define PictOpDisjointIn 0x15 -#define PictOpDisjointInReverse 0x16 -#define PictOpDisjointOut 0x17 -#define PictOpDisjointOutReverse 0x18 -#define PictOpDisjointAtop 0x19 -#define PictOpDisjointAtopReverse 0x1a -#define PictOpDisjointXor 0x1b -#define PictOpDisjointMaximum 0x1b - -#define PictOpConjointMinimum 0x20 -#define PictOpConjointClear 0x20 -#define PictOpConjointSrc 0x21 -#define PictOpConjointDst 0x22 -#define PictOpConjointOver 0x23 -#define PictOpConjointOverReverse 0x24 -#define PictOpConjointIn 0x25 -#define PictOpConjointInReverse 0x26 -#define PictOpConjointOut 0x27 -#define PictOpConjointOutReverse 0x28 -#define PictOpConjointAtop 0x29 -#define PictOpConjointAtopReverse 0x2a -#define PictOpConjointXor 0x2b -#define PictOpConjointMaximum 0x2b - -/* - * Operators only available in version 0.11 - */ -#define PictOpBlendMinimum 0x30 -#define PictOpMultiply 0x30 -#define PictOpScreen 0x31 -#define PictOpOverlay 0x32 -#define PictOpDarken 0x33 -#define PictOpLighten 0x34 -#define PictOpColorDodge 0x35 -#define PictOpColorBurn 0x36 -#define PictOpHardLight 0x37 -#define PictOpSoftLight 0x38 -#define PictOpDifference 0x39 -#define PictOpExclusion 0x3a -#define PictOpHSLHue 0x3b -#define PictOpHSLSaturation 0x3c -#define PictOpHSLColor 0x3d -#define PictOpHSLLuminosity 0x3e -#define PictOpBlendMaximum 0x3e - -#define PolyEdgeSharp 0 -#define PolyEdgeSmooth 1 - -#define PolyModePrecise 0 -#define PolyModeImprecise 1 - -#define CPRepeat (1 << 0) -#define CPAlphaMap (1 << 1) -#define CPAlphaXOrigin (1 << 2) -#define CPAlphaYOrigin (1 << 3) -#define CPClipXOrigin (1 << 4) -#define CPClipYOrigin (1 << 5) -#define CPClipMask (1 << 6) -#define CPGraphicsExposure (1 << 7) -#define CPSubwindowMode (1 << 8) -#define CPPolyEdge (1 << 9) -#define CPPolyMode (1 << 10) -#define CPDither (1 << 11) -#define CPComponentAlpha (1 << 12) -#define CPLastBit 12 - -/* Filters included in 0.6 */ -#define FilterNearest "nearest" -#define FilterBilinear "bilinear" -/* Filters included in 0.10 */ -#define FilterConvolution "convolution" - -#define FilterFast "fast" -#define FilterGood "good" -#define FilterBest "best" - -#define FilterAliasNone -1 - -/* Subpixel orders included in 0.6 */ -#define SubPixelUnknown 0 -#define SubPixelHorizontalRGB 1 -#define SubPixelHorizontalBGR 2 -#define SubPixelVerticalRGB 3 -#define SubPixelVerticalBGR 4 -#define SubPixelNone 5 - -/* Extended repeat attributes included in 0.10 */ -#define RepeatNone 0 -#define RepeatNormal 1 -#define RepeatPad 2 -#define RepeatReflect 3 - - - -/* Copied from X11/extensions/Xrender.h */ - -typedef struct { - short red; - short redMask; - short green; - short greenMask; - short blue; - short blueMask; - short alpha; - short alphaMask; -} XRenderDirectFormat; - -typedef struct { - PictFormat id; - int type; - int depth; - XRenderDirectFormat direct; - Colormap colormap; -} XRenderPictFormat; - -#define PictFormatID (1 << 0) -#define PictFormatType (1 << 1) -#define PictFormatDepth (1 << 2) -#define PictFormatRed (1 << 3) -#define PictFormatRedMask (1 << 4) -#define PictFormatGreen (1 << 5) -#define PictFormatGreenMask (1 << 6) -#define PictFormatBlue (1 << 7) -#define PictFormatBlueMask (1 << 8) -#define PictFormatAlpha (1 << 9) -#define PictFormatAlphaMask (1 << 10) -#define PictFormatColormap (1 << 11) - -typedef struct _XRenderPictureAttributes { - int repeat; - Picture alpha_map; - int alpha_x_origin; - int alpha_y_origin; - int clip_x_origin; - int clip_y_origin; - Pixmap clip_mask; - Bool graphics_exposures; - int subwindow_mode; - int poly_edge; - int poly_mode; - Atom dither; - Bool component_alpha; -} XRenderPictureAttributes; - -typedef struct { - unsigned short red; - unsigned short green; - unsigned short blue; - unsigned short alpha; -} XRenderColor; - -typedef struct _XGlyphInfo { - unsigned short width; - unsigned short height; - short x; - short y; - short xOff; - short yOff; -} XGlyphInfo; - -typedef struct _XGlyphElt8 { - GlyphSet glyphset; - _Xconst char *chars; - int nchars; - int xOff; - int yOff; -} XGlyphElt8; - -typedef struct _XGlyphElt16 { - GlyphSet glyphset; - _Xconst unsigned short *chars; - int nchars; - int xOff; - int yOff; -} XGlyphElt16; - -typedef struct _XGlyphElt32 { - GlyphSet glyphset; - _Xconst unsigned int *chars; - int nchars; - int xOff; - int yOff; -} XGlyphElt32; - -typedef double XDouble; - -typedef struct _XPointDouble { - XDouble x, y; -} XPointDouble; - -#define XDoubleToFixed(f) ((XFixed) ((f) * 65536)) -#define XFixedToDouble(f) (((XDouble) (f)) / 65536) - -typedef int XFixed; - -typedef struct _XPointFixed { - XFixed x, y; -} XPointFixed; - -typedef struct _XLineFixed { - XPointFixed p1, p2; -} XLineFixed; - -typedef struct _XTriangle { - XPointFixed p1, p2, p3; -} XTriangle; - -typedef struct _XCircle { - XFixed x; - XFixed y; - XFixed radius; -} XCircle; - -typedef struct _XTrapezoid { - XFixed top, bottom; - XLineFixed left, right; -} XTrapezoid; - -typedef struct _XTransform { - XFixed matrix[3][3]; -} XTransform; - -typedef struct _XFilters { - int nfilter; - char **filter; - int nalias; - short *alias; -} XFilters; - -typedef struct _XIndexValue { - unsigned long pixel; - unsigned short red, green, blue, alpha; -} XIndexValue; - -typedef struct _XAnimCursor { - Cursor cursor; - unsigned long delay; -} XAnimCursor; - -typedef struct _XSpanFix { - XFixed left, right, y; -} XSpanFix; - -typedef struct _XTrap { - XSpanFix top, bottom; -} XTrap; - -typedef struct _XLinearGradient { - XPointFixed p1; - XPointFixed p2; -} XLinearGradient; - -typedef struct _XRadialGradient { - XCircle inner; - XCircle outer; -} XRadialGradient; - -typedef struct _XConicalGradient { - XPointFixed center; - XFixed angle; /* in degrees */ -} XConicalGradient; - -#define PictStandardARGB32 0 -#define PictStandardRGB24 1 -#define PictStandardA8 2 -#define PictStandardA4 3 -#define PictStandardA1 4 -#define PictStandardNUM 5 - - - -/* Copied from X11/extensions/renderproto.h */ - -#include - -#define Window CARD32 -#define Drawable CARD32 -#define Font CARD32 -#define Pixmap CARD32 -#define Cursor CARD32 -#define Colormap CARD32 -#define GContext CARD32 -#define Atom CARD32 -#define VisualID CARD32 -#define Time CARD32 -#define KeyCode CARD8 -#define KeySym CARD32 - -#define Picture CARD32 -#define PictFormat CARD32 -#define Fixed INT32 -#define Glyphset CARD32 -#define Glyph CARD32 - -/* - * data structures - */ - -typedef struct { - CARD16 red B16; - CARD16 redMask B16; - CARD16 green B16; - CARD16 greenMask B16; - CARD16 blue B16; - CARD16 blueMask B16; - CARD16 alpha B16; - CARD16 alphaMask B16; -} xDirectFormat; - -#define sz_xDirectFormat 16 - -typedef struct { - PictFormat id B32; - CARD8 type; - CARD8 depth; - CARD16 pad1 B16; - xDirectFormat direct; - Colormap colormap; -} xPictFormInfo; - -#define sz_xPictFormInfo 28 - -typedef struct { - VisualID visual; - PictFormat format; -} xPictVisual; - -#define sz_xPictVisual 8 - -typedef struct { - CARD8 depth; - CARD8 pad1; - CARD16 nPictVisuals B16; - CARD32 pad2 B32; -} xPictDepth; - -#define sz_xPictDepth 8 - -typedef struct { - CARD32 nDepth B32; - PictFormat fallback B32; -} xPictScreen; - -#define sz_xPictScreen 8 - -typedef struct { - CARD32 pixel B32; - CARD16 red B16; - CARD16 green B16; - CARD16 blue B16; - CARD16 alpha B16; -} xIndexValue; - -#define sz_xIndexValue 12 - -typedef struct { - CARD16 red B16; - CARD16 green B16; - CARD16 blue B16; - CARD16 alpha B16; -} xRenderColor; - -#define sz_xRenderColor 8 - -typedef struct { - Fixed x B32; - Fixed y B32; -} xPointFixed; - -#define sz_xPointFixed 8 - -typedef struct { - xPointFixed p1; - xPointFixed p2; -} xLineFixed; - -#define sz_xLineFixed 16 - -typedef struct { - xPointFixed p1, p2, p3; -} xTriangle; - -#define sz_xTriangle 24 - -typedef struct { - Fixed top B32; - Fixed bottom B32; - xLineFixed left; - xLineFixed right; -} xTrapezoid; - -#define sz_xTrapezoid 40 - -typedef struct { - CARD16 width B16; - CARD16 height B16; - INT16 x B16; - INT16 y B16; - INT16 xOff B16; - INT16 yOff B16; -} xGlyphInfo; - -#define sz_xGlyphInfo 12 - -typedef struct { - CARD8 len; - CARD8 pad1; - CARD16 pad2; - INT16 deltax; - INT16 deltay; -} xGlyphElt; - -#define sz_xGlyphElt 8 - -typedef struct { - Fixed l, r, y; -} xSpanFix; - -#define sz_xSpanFix 12 - -typedef struct { - xSpanFix top, bot; -} xTrap; - -#define sz_xTrap 24 - -/* - * requests and replies - */ -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD32 majorVersion B32; - CARD32 minorVersion B32; -} xRenderQueryVersionReq; - -#define sz_xRenderQueryVersionReq 12 - -typedef struct { - BYTE type; /* X_Reply */ - BYTE pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 majorVersion B32; - CARD32 minorVersion B32; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xRenderQueryVersionReply; - -#define sz_xRenderQueryVersionReply 32 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; -} xRenderQueryPictFormatsReq; - -#define sz_xRenderQueryPictFormatsReq 4 - -typedef struct { - BYTE type; /* X_Reply */ - BYTE pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 numFormats B32; - CARD32 numScreens B32; - CARD32 numDepths B32; - CARD32 numVisuals B32; - CARD32 numSubpixel B32; /* Version 0.6 */ - CARD32 pad5 B32; -} xRenderQueryPictFormatsReply; - -#define sz_xRenderQueryPictFormatsReply 32 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - PictFormat format B32; -} xRenderQueryPictIndexValuesReq; - -#define sz_xRenderQueryPictIndexValuesReq 8 - -typedef struct { - BYTE type; /* X_Reply */ - BYTE pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 numIndexValues; - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; - CARD32 pad6 B32; -} xRenderQueryPictIndexValuesReply; - -#define sz_xRenderQueryPictIndexValuesReply 32 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture pid B32; - Drawable drawable B32; - PictFormat format B32; - CARD32 mask B32; -} xRenderCreatePictureReq; - -#define sz_xRenderCreatePictureReq 20 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture picture B32; - CARD32 mask B32; -} xRenderChangePictureReq; - -#define sz_xRenderChangePictureReq 12 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture picture B32; - INT16 xOrigin B16; - INT16 yOrigin B16; -} xRenderSetPictureClipRectanglesReq; - -#define sz_xRenderSetPictureClipRectanglesReq 12 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture picture B32; -} xRenderFreePictureReq; - -#define sz_xRenderFreePictureReq 8 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture src B32; - Picture mask B32; - Picture dst B32; - INT16 xSrc B16; - INT16 ySrc B16; - INT16 xMask B16; - INT16 yMask B16; - INT16 xDst B16; - INT16 yDst B16; - CARD16 width B16; - CARD16 height B16; -} xRenderCompositeReq; - -#define sz_xRenderCompositeReq 36 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture src B32; - Picture dst B32; - CARD32 colorScale B32; - CARD32 alphaScale B32; - INT16 xSrc B16; - INT16 ySrc B16; - INT16 xDst B16; - INT16 yDst B16; - CARD16 width B16; - CARD16 height B16; -} xRenderScaleReq; - -#define sz_xRenderScaleReq 32 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture src B32; - Picture dst B32; - PictFormat maskFormat B32; - INT16 xSrc B16; - INT16 ySrc B16; -} xRenderTrapezoidsReq; - -#define sz_xRenderTrapezoidsReq 24 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture src B32; - Picture dst B32; - PictFormat maskFormat B32; - INT16 xSrc B16; - INT16 ySrc B16; -} xRenderTrianglesReq; - -#define sz_xRenderTrianglesReq 24 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture src B32; - Picture dst B32; - PictFormat maskFormat B32; - INT16 xSrc B16; - INT16 ySrc B16; -} xRenderTriStripReq; - -#define sz_xRenderTriStripReq 24 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture src B32; - Picture dst B32; - PictFormat maskFormat B32; - INT16 xSrc B16; - INT16 ySrc B16; -} xRenderTriFanReq; - -#define sz_xRenderTriFanReq 24 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Glyphset gsid B32; - PictFormat format B32; -} xRenderCreateGlyphSetReq; - -#define sz_xRenderCreateGlyphSetReq 12 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Glyphset gsid B32; - Glyphset existing B32; -} xRenderReferenceGlyphSetReq; - -#define sz_xRenderReferenceGlyphSetReq 24 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Glyphset glyphset B32; -} xRenderFreeGlyphSetReq; - -#define sz_xRenderFreeGlyphSetReq 8 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Glyphset glyphset B32; - CARD32 nglyphs; -} xRenderAddGlyphsReq; - -#define sz_xRenderAddGlyphsReq 12 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Glyphset glyphset B32; -} xRenderFreeGlyphsReq; - -#define sz_xRenderFreeGlyphsReq 8 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture src B32; - Picture dst B32; - PictFormat maskFormat B32; - Glyphset glyphset B32; - INT16 xSrc B16; - INT16 ySrc B16; -} xRenderCompositeGlyphsReq, xRenderCompositeGlyphs8Req, -xRenderCompositeGlyphs16Req, xRenderCompositeGlyphs32Req; - -#define sz_xRenderCompositeGlyphs8Req 28 -#define sz_xRenderCompositeGlyphs16Req 28 -#define sz_xRenderCompositeGlyphs32Req 28 - -/* 0.1 and higher */ - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - CARD8 op; - CARD8 pad1; - CARD16 pad2 B16; - Picture dst B32; - xRenderColor color; -} xRenderFillRectanglesReq; - -#define sz_xRenderFillRectanglesReq 20 - -/* 0.5 and higher */ - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Cursor cid B32; - Picture src B32; - CARD16 x B16; - CARD16 y B16; -} xRenderCreateCursorReq; - -#define sz_xRenderCreateCursorReq 16 - -/* 0.6 and higher */ - -/* - * This can't use an array because 32-bit values may be in bitfields - */ -typedef struct { - Fixed matrix11 B32; - Fixed matrix12 B32; - Fixed matrix13 B32; - Fixed matrix21 B32; - Fixed matrix22 B32; - Fixed matrix23 B32; - Fixed matrix31 B32; - Fixed matrix32 B32; - Fixed matrix33 B32; -} xRenderTransform; - -#define sz_xRenderTransform 36 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture picture B32; - xRenderTransform transform; -} xRenderSetPictureTransformReq; - -#define sz_xRenderSetPictureTransformReq 44 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Drawable drawable B32; -} xRenderQueryFiltersReq; - -#define sz_xRenderQueryFiltersReq 8 - -typedef struct { - BYTE type; /* X_Reply */ - BYTE pad1; - CARD16 sequenceNumber B16; - CARD32 length B32; - CARD32 numAliases B32; /* LISTofCARD16 */ - CARD32 numFilters B32; /* LISTofSTRING8 */ - CARD32 pad2 B32; - CARD32 pad3 B32; - CARD32 pad4 B32; - CARD32 pad5 B32; -} xRenderQueryFiltersReply; - -#define sz_xRenderQueryFiltersReply 32 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture picture B32; - CARD16 nbytes B16; /* number of bytes in name */ - CARD16 pad B16; -} xRenderSetPictureFilterReq; - -#define sz_xRenderSetPictureFilterReq 12 - -/* 0.8 and higher */ - -typedef struct { - Cursor cursor B32; - CARD32 delay B32; -} xAnimCursorElt; - -#define sz_xAnimCursorElt 8 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Cursor cid B32; -} xRenderCreateAnimCursorReq; - -#define sz_xRenderCreateAnimCursorReq 8 - -/* 0.9 and higher */ - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture picture; - INT16 xOff B16; - INT16 yOff B16; -} xRenderAddTrapsReq; - -#define sz_xRenderAddTrapsReq 12 - -/* 0.10 and higher */ - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture pid B32; - xRenderColor color; -} xRenderCreateSolidFillReq; - -#define sz_xRenderCreateSolidFillReq 16 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture pid B32; - xPointFixed p1; - xPointFixed p2; - CARD32 nStops; -} xRenderCreateLinearGradientReq; - -#define sz_xRenderCreateLinearGradientReq 28 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture pid B32; - xPointFixed inner; - xPointFixed outer; - Fixed inner_radius; - Fixed outer_radius; - CARD32 nStops; -} xRenderCreateRadialGradientReq; - -#define sz_xRenderCreateRadialGradientReq 36 - -typedef struct { - CARD8 reqType; - CARD8 renderReqType; - CARD16 length B16; - Picture pid B32; - xPointFixed center; - Fixed angle; /* in degrees */ - CARD32 nStops; -} xRenderCreateConicalGradientReq; - -#define sz_xRenderCreateConicalGradientReq 24 - -#undef Window -#undef Drawable -#undef Font -#undef Pixmap -#undef Cursor -#undef Colormap -#undef GContext -#undef Atom -#undef VisualID -#undef Time -#undef KeyCode -#undef KeySym - -#undef Picture -#undef PictFormat -#undef Fixed -#undef Glyphset -#undef Glyph - - -#endif /* CAIRO_HAS_XLIB_XRENDER_SURFACE */ - -#endif /* CAIRO_XLIB_XRENDER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender.h deleted file mode 100644 index b34b057de4c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib-xrender.h +++ /dev/null @@ -1,66 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_XLIB_XRENDER_H -#define CAIRO_XLIB_XRENDER_H - -#include "cairo.h" - -#if CAIRO_HAS_XLIB_XRENDER_SURFACE - -#include -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_xlib_surface_create_with_xrender_format (Display *dpy, - Drawable drawable, - Screen *screen, - XRenderPictFormat *format, - int width, - int height); - -cairo_public XRenderPictFormat * -cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_XLIB_XRENDER_SURFACE */ -# error Cairo was not compiled with support for the xlib XRender backend -#endif /* CAIRO_HAS_XLIB_XRENDER_SURFACE */ - -#endif /* CAIRO_XLIB_XRENDER_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib.h deleted file mode 100644 index ecf8d6c86be..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xlib.h +++ /dev/null @@ -1,118 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_XLIB_H -#define CAIRO_XLIB_H - -#include "cairo.h" - -#if CAIRO_HAS_XLIB_SURFACE - -#include - -CAIRO_BEGIN_DECLS - -cairo_public cairo_surface_t * -cairo_xlib_surface_create (Display *dpy, - Drawable drawable, - Visual *visual, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_xlib_surface_create_for_bitmap (Display *dpy, - Pixmap bitmap, - Screen *screen, - int width, - int height); - -cairo_public void -cairo_xlib_surface_set_size (cairo_surface_t *surface, - int width, - int height); - -cairo_public void -cairo_xlib_surface_set_drawable (cairo_surface_t *surface, - Drawable drawable, - int width, - int height); - -cairo_public Display * -cairo_xlib_surface_get_display (cairo_surface_t *surface); - -cairo_public Drawable -cairo_xlib_surface_get_drawable (cairo_surface_t *surface); - -cairo_public Screen * -cairo_xlib_surface_get_screen (cairo_surface_t *surface); - -cairo_public Visual * -cairo_xlib_surface_get_visual (cairo_surface_t *surface); - -cairo_public int -cairo_xlib_surface_get_depth (cairo_surface_t *surface); - -cairo_public int -cairo_xlib_surface_get_width (cairo_surface_t *surface); - -cairo_public int -cairo_xlib_surface_get_height (cairo_surface_t *surface); - -/* debug interface */ - -cairo_public void -cairo_xlib_device_debug_cap_xrender_version (cairo_device_t *device, - int major_version, - int minor_version); - -/* - * @precision: -1 implies automatically choose based on antialiasing mode, - * any other value overrides and sets the corresponding PolyMode. - */ -cairo_public void -cairo_xlib_device_debug_set_precision (cairo_device_t *device, - int precision); - -cairo_public int -cairo_xlib_device_debug_get_precision (cairo_device_t *device); - -CAIRO_END_DECLS - -#else /* CAIRO_HAS_XLIB_SURFACE */ -# error Cairo was not compiled with support for the xlib backend -#endif /* CAIRO_HAS_XLIB_SURFACE */ - -#endif /* CAIRO_XLIB_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml-surface.c deleted file mode 100644 index 6dbafdba2ba..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml-surface.c +++ /dev/null @@ -1,1209 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson. - * - * Contributor(s): - * Chris Wilson - */ - -/* This surface is intended to produce a verbose, hierarchical, DAG XML file - * representing a single surface. It is intended to be used by debuggers, - * such as cairo-sphinx, or by application test-suites that what a log of - * operations. - */ - -#include "cairoint.h" - -#include "cairo-xml.h" - -#include "cairo-clip-private.h" -#include "cairo-device-private.h" -#include "cairo-default-context-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-error-private.h" -#include "cairo-output-stream-private.h" -#include "cairo-recording-surface-inline.h" - -#define static cairo_warn static - -typedef struct _cairo_xml_surface cairo_xml_surface_t; - -typedef struct _cairo_xml { - cairo_device_t base; - - cairo_output_stream_t *stream; - int indent; -} cairo_xml_t; - -struct _cairo_xml_surface { - cairo_surface_t base; - - double width, height; -}; - -slim_hidden_proto (cairo_xml_for_recording_surface); - -static const cairo_surface_backend_t _cairo_xml_surface_backend; - -static const char * -_operator_to_string (cairo_operator_t op) -{ - static const char *names[] = { - "CLEAR", /* CAIRO_OPERATOR_CLEAR */ - - "SOURCE", /* CAIRO_OPERATOR_SOURCE */ - "OVER", /* CAIRO_OPERATOR_OVER */ - "IN", /* CAIRO_OPERATOR_IN */ - "OUT", /* CAIRO_OPERATOR_OUT */ - "ATOP", /* CAIRO_OPERATOR_ATOP */ - - "DEST", /* CAIRO_OPERATOR_DEST */ - "DEST_OVER", /* CAIRO_OPERATOR_DEST_OVER */ - "DEST_IN", /* CAIRO_OPERATOR_DEST_IN */ - "DEST_OUT", /* CAIRO_OPERATOR_DEST_OUT */ - "DEST_ATOP", /* CAIRO_OPERATOR_DEST_ATOP */ - - "XOR", /* CAIRO_OPERATOR_XOR */ - "ADD", /* CAIRO_OPERATOR_ADD */ - "SATURATE", /* CAIRO_OPERATOR_SATURATE */ - - "MULTIPLY", /* CAIRO_OPERATOR_MULTIPLY */ - "SCREEN", /* CAIRO_OPERATOR_SCREEN */ - "OVERLAY", /* CAIRO_OPERATOR_OVERLAY */ - "DARKEN", /* CAIRO_OPERATOR_DARKEN */ - "LIGHTEN", /* CAIRO_OPERATOR_LIGHTEN */ - "DODGE", /* CAIRO_OPERATOR_COLOR_DODGE */ - "BURN", /* CAIRO_OPERATOR_COLOR_BURN */ - "HARD_LIGHT", /* CAIRO_OPERATOR_HARD_LIGHT */ - "SOFT_LIGHT", /* CAIRO_OPERATOR_SOFT_LIGHT */ - "DIFFERENCE", /* CAIRO_OPERATOR_DIFFERENCE */ - "EXCLUSION", /* CAIRO_OPERATOR_EXCLUSION */ - "HSL_HUE", /* CAIRO_OPERATOR_HSL_HUE */ - "HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */ - "HSL_COLOR", /* CAIRO_OPERATOR_HSL_COLOR */ - "HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */ - }; - assert (op < ARRAY_LENGTH (names)); - return names[op]; -} - -static const char * -_extend_to_string (cairo_extend_t extend) -{ - static const char *names[] = { - "EXTEND_NONE", /* CAIRO_EXTEND_NONE */ - "EXTEND_REPEAT", /* CAIRO_EXTEND_REPEAT */ - "EXTEND_REFLECT", /* CAIRO_EXTEND_REFLECT */ - "EXTEND_PAD" /* CAIRO_EXTEND_PAD */ - }; - assert (extend < ARRAY_LENGTH (names)); - return names[extend]; -} - -static const char * -_filter_to_string (cairo_filter_t filter) -{ - static const char *names[] = { - "FILTER_FAST", /* CAIRO_FILTER_FAST */ - "FILTER_GOOD", /* CAIRO_FILTER_GOOD */ - "FILTER_BEST", /* CAIRO_FILTER_BEST */ - "FILTER_NEAREST", /* CAIRO_FILTER_NEAREST */ - "FILTER_BILINEAR", /* CAIRO_FILTER_BILINEAR */ - "FILTER_GAUSSIAN", /* CAIRO_FILTER_GAUSSIAN */ - }; - assert (filter < ARRAY_LENGTH (names)); - return names[filter]; -} - -static const char * -_fill_rule_to_string (cairo_fill_rule_t rule) -{ - static const char *names[] = { - "WINDING", /* CAIRO_FILL_RULE_WINDING */ - "EVEN_ODD" /* CAIRO_FILL_RILE_EVEN_ODD */ - }; - assert (rule < ARRAY_LENGTH (names)); - return names[rule]; -} - -static const char * -_antialias_to_string (cairo_antialias_t antialias) -{ - static const char *names[] = { - "DEFAULT", /* CAIRO_ANTIALIAS_DEFAULT */ - "NONE", /* CAIRO_ANTIALIAS_NONE */ - "GRAY", /* CAIRO_ANTIALIAS_GRAY */ - "SUBPIXEL", /* CAIRO_ANTIALIAS_SUBPIXEL */ - "FAST", /* CAIRO_ANTIALIAS_FAST */ - "GOOD", /* CAIRO_ANTIALIAS_GOOD */ - "BEST", /* CAIRO_ANTIALIAS_BEST */ - }; - assert (antialias < ARRAY_LENGTH (names)); - return names[antialias]; -} - -static const char * -_line_cap_to_string (cairo_line_cap_t line_cap) -{ - static const char *names[] = { - "LINE_CAP_BUTT", /* CAIRO_LINE_CAP_BUTT */ - "LINE_CAP_ROUND", /* CAIRO_LINE_CAP_ROUND */ - "LINE_CAP_SQUARE" /* CAIRO_LINE_CAP_SQUARE */ - }; - assert (line_cap < ARRAY_LENGTH (names)); - return names[line_cap]; -} - -static const char * -_line_join_to_string (cairo_line_join_t line_join) -{ - static const char *names[] = { - "LINE_JOIN_MITER", /* CAIRO_LINE_JOIN_MITER */ - "LINE_JOIN_ROUND", /* CAIRO_LINE_JOIN_ROUND */ - "LINE_JOIN_BEVEL", /* CAIRO_LINE_JOIN_BEVEL */ - }; - assert (line_join < ARRAY_LENGTH (names)); - return names[line_join]; -} - -static const char * -_content_to_string (cairo_content_t content) -{ - switch (content) { - case CAIRO_CONTENT_ALPHA: return "ALPHA"; - case CAIRO_CONTENT_COLOR: return "COLOR"; - default: - case CAIRO_CONTENT_COLOR_ALPHA: return "COLOR_ALPHA"; - } -} - -static const char * -_format_to_string (cairo_format_t format) -{ - switch (format) { - case CAIRO_FORMAT_ARGB32: return "ARGB32"; - case CAIRO_FORMAT_RGB30: return "RGB30"; - case CAIRO_FORMAT_RGB24: return "RGB24"; - case CAIRO_FORMAT_RGB16_565: return "RGB16_565"; - case CAIRO_FORMAT_A8: return "A8"; - case CAIRO_FORMAT_A1: return "A1"; - case CAIRO_FORMAT_INVALID: return "INVALID"; - } - ASSERT_NOT_REACHED; - return "INVALID"; -} - -static cairo_status_t -_device_flush (void *abstract_device) -{ - cairo_xml_t *xml = abstract_device; - cairo_status_t status; - - status = _cairo_output_stream_flush (xml->stream); - - return status; -} - -static void -_device_destroy (void *abstract_device) -{ - cairo_xml_t *xml = abstract_device; - cairo_status_t status; - - status = _cairo_output_stream_destroy (xml->stream); - - free (xml); -} - -static const cairo_device_backend_t _cairo_xml_device_backend = { - CAIRO_DEVICE_TYPE_XML, - - NULL, NULL, /* lock, unlock */ - - _device_flush, - NULL, /* finish */ - _device_destroy -}; - -static cairo_device_t * -_cairo_xml_create_internal (cairo_output_stream_t *stream) -{ - cairo_xml_t *xml; - - xml = malloc (sizeof (cairo_xml_t)); - if (unlikely (xml == NULL)) - return _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); - - memset (xml, 0, sizeof (cairo_xml_t)); - - _cairo_device_init (&xml->base, &_cairo_xml_device_backend); - - xml->indent = 0; - xml->stream = stream; - - return &xml->base; -} - -static void -_cairo_xml_indent (cairo_xml_t *xml, int indent) -{ - xml->indent += indent; - assert (xml->indent >= 0); -} - -static void CAIRO_PRINTF_FORMAT (2, 3) -_cairo_xml_printf (cairo_xml_t *xml, const char *fmt, ...) -{ - va_list ap; - char indent[80]; - int len; - - len = MIN (xml->indent, ARRAY_LENGTH (indent)); - memset (indent, ' ', len); - _cairo_output_stream_write (xml->stream, indent, len); - - va_start (ap, fmt); - _cairo_output_stream_vprintf (xml->stream, fmt, ap); - va_end (ap); - - _cairo_output_stream_write (xml->stream, "\n", 1); -} - -static void CAIRO_PRINTF_FORMAT (2, 3) -_cairo_xml_printf_start (cairo_xml_t *xml, const char *fmt, ...) -{ - char indent[80]; - int len; - - len = MIN (xml->indent, ARRAY_LENGTH (indent)); - memset (indent, ' ', len); - _cairo_output_stream_write (xml->stream, indent, len); - - if (fmt != NULL) { - va_list ap; - - va_start (ap, fmt); - _cairo_output_stream_vprintf (xml->stream, fmt, ap); - va_end (ap); - } -} - -static void CAIRO_PRINTF_FORMAT (2, 3) -_cairo_xml_printf_continue (cairo_xml_t *xml, const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - _cairo_output_stream_vprintf (xml->stream, fmt, ap); - va_end (ap); -} - -static void CAIRO_PRINTF_FORMAT (2, 3) -_cairo_xml_printf_end (cairo_xml_t *xml, const char *fmt, ...) -{ - if (fmt != NULL) { - va_list ap; - - va_start (ap, fmt); - _cairo_output_stream_vprintf (xml->stream, fmt, ap); - va_end (ap); - } - - _cairo_output_stream_write (xml->stream, "\n", 1); -} - -static cairo_surface_t * -_cairo_xml_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - cairo_rectangle_t extents; - - extents.x = extents.y = 0; - extents.width = width; - extents.height = height; - - return cairo_recording_surface_create (content, &extents); -} - -static cairo_bool_t -_cairo_xml_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - cairo_xml_surface_t *surface = abstract_surface; - - if (surface->width < 0 || surface->height < 0) - return FALSE; - - rectangle->x = 0; - rectangle->y = 0; - rectangle->width = surface->width; - rectangle->height = surface->height; - - return TRUE; -} - -static cairo_status_t -_cairo_xml_move_to (void *closure, - const cairo_point_t *p1) -{ - _cairo_xml_printf_continue (closure, " %f %f m", - _cairo_fixed_to_double (p1->x), - _cairo_fixed_to_double (p1->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_line_to (void *closure, - const cairo_point_t *p1) -{ - _cairo_xml_printf_continue (closure, " %f %f l", - _cairo_fixed_to_double (p1->x), - _cairo_fixed_to_double (p1->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_curve_to (void *closure, - const cairo_point_t *p1, - const cairo_point_t *p2, - const cairo_point_t *p3) -{ - _cairo_xml_printf_continue (closure, " %f %f %f %f %f %f c", - _cairo_fixed_to_double (p1->x), - _cairo_fixed_to_double (p1->y), - _cairo_fixed_to_double (p2->x), - _cairo_fixed_to_double (p2->y), - _cairo_fixed_to_double (p3->x), - _cairo_fixed_to_double (p3->y)); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_close_path (void *closure) -{ - _cairo_xml_printf_continue (closure, " h"); - - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_xml_emit_path (cairo_xml_t *xml, - const cairo_path_fixed_t *path) -{ - cairo_status_t status; - - _cairo_xml_printf_start (xml, ""); - status = _cairo_path_fixed_interpret (path, - _cairo_xml_move_to, - _cairo_xml_line_to, - _cairo_xml_curve_to, - _cairo_xml_close_path, - xml); - assert (status == CAIRO_STATUS_SUCCESS); - _cairo_xml_printf_end (xml, ""); -} - -static void -_cairo_xml_emit_string (cairo_xml_t *xml, - const char *node, - const char *data) -{ - _cairo_xml_printf (xml, "<%s>%s", node, data, node); -} - -static void -_cairo_xml_emit_double (cairo_xml_t *xml, - const char *node, - double data) -{ - _cairo_xml_printf (xml, "<%s>%f", node, data, node); -} - -static cairo_xml_t * -to_xml (cairo_xml_surface_t *surface) -{ - return (cairo_xml_t *) surface->base.device; -} - -static cairo_status_t -_cairo_xml_surface_emit_clip_boxes (cairo_xml_surface_t *surface, - const cairo_clip_t *clip) -{ - cairo_box_t *box; - cairo_xml_t *xml; - int n; - - if (clip->num_boxes == 0) - return CAIRO_STATUS_SUCCESS; - - /* skip the trivial clip covering the surface extents */ - if (surface->width >= 0 && surface->height >= 0 && clip->num_boxes == 1) { - box = &clip->boxes[0]; - if (box->p1.x <= 0 && box->p1.y <= 0 && - box->p2.x - box->p1.x >= _cairo_fixed_from_double (surface->width) && - box->p2.y - box->p1.y >= _cairo_fixed_from_double (surface->height)) - { - return CAIRO_STATUS_SUCCESS; - } - } - - xml = to_xml (surface); - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - for (n = 0; n < clip->num_boxes; n++) { - box = &clip->boxes[n]; - - _cairo_xml_printf_start (xml, "%f %f m", - _cairo_fixed_to_double (box->p1.x), - _cairo_fixed_to_double (box->p1.y)); - _cairo_xml_printf_continue (xml, " %f %f l", - _cairo_fixed_to_double (box->p2.x), - _cairo_fixed_to_double (box->p1.y)); - _cairo_xml_printf_continue (xml, " %f %f l", - _cairo_fixed_to_double (box->p2.x), - _cairo_fixed_to_double (box->p2.y)); - _cairo_xml_printf_continue (xml, " %f %f l", - _cairo_fixed_to_double (box->p1.x), - _cairo_fixed_to_double (box->p2.y)); - _cairo_xml_printf_end (xml, " h"); - } - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - _cairo_xml_emit_double (xml, "tolerance", 1.0); - _cairo_xml_emit_string (xml, "antialias", - _antialias_to_string (CAIRO_ANTIALIAS_NONE)); - _cairo_xml_emit_string (xml, "fill-rule", - _fill_rule_to_string (CAIRO_FILL_RULE_WINDING)); - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_surface_emit_clip_path (cairo_xml_surface_t *surface, - const cairo_clip_path_t *clip_path) -{ - cairo_box_t box; - cairo_status_t status; - cairo_xml_t *xml; - - if (clip_path == NULL) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_xml_surface_emit_clip_path (surface, clip_path->prev); - if (unlikely (status)) - return status; - - /* skip the trivial clip covering the surface extents */ - if (surface->width >= 0 && surface->height >= 0 && - _cairo_path_fixed_is_box (&clip_path->path, &box)) - { - if (box.p1.x <= 0 && box.p1.y <= 0 && - box.p2.x - box.p1.x >= _cairo_fixed_from_double (surface->width) && - box.p2.y - box.p1.y >= _cairo_fixed_from_double (surface->height)) - { - return CAIRO_STATUS_SUCCESS; - } - } - - xml = to_xml (surface); - - _cairo_xml_printf_start (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_emit_path (xml, &clip_path->path); - _cairo_xml_emit_double (xml, "tolerance", clip_path->tolerance); - _cairo_xml_emit_string (xml, "antialias", - _antialias_to_string (clip_path->antialias)); - _cairo_xml_emit_string (xml, "fill-rule", - _fill_rule_to_string (clip_path->fill_rule)); - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf_end (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_surface_emit_clip (cairo_xml_surface_t *surface, - const cairo_clip_t *clip) -{ - cairo_status_t status; - - if (clip == NULL) - return CAIRO_STATUS_SUCCESS; - - status = _cairo_xml_surface_emit_clip_boxes (surface, clip); - if (unlikely (status)) - return status; - - return _cairo_xml_surface_emit_clip_path (surface, clip->path); -} - -static cairo_status_t -_cairo_xml_emit_solid (cairo_xml_t *xml, - const cairo_solid_pattern_t *solid) -{ - _cairo_xml_printf (xml, "%f %f %f %f", - solid->color.red, - solid->color.green, - solid->color.blue, - solid->color.alpha); - return CAIRO_STATUS_SUCCESS; -} - -static void -_cairo_xml_emit_matrix (cairo_xml_t *xml, - const cairo_matrix_t *matrix) -{ - if (! _cairo_matrix_is_identity (matrix)) { - _cairo_xml_printf (xml, "%f %f %f %f %f %f", - matrix->xx, matrix->yx, - matrix->xy, matrix->yy, - matrix->x0, matrix->y0); - } -} - -static void -_cairo_xml_emit_gradient (cairo_xml_t *xml, - const cairo_gradient_pattern_t *gradient) -{ - unsigned int i; - - for (i = 0; i < gradient->n_stops; i++) { - _cairo_xml_printf (xml, - "%f %f %f %f %f", - gradient->stops[i].offset, - gradient->stops[i].color.red, - gradient->stops[i].color.green, - gradient->stops[i].color.blue, - gradient->stops[i].color.alpha); - } -} - -static cairo_status_t -_cairo_xml_emit_linear (cairo_xml_t *xml, - const cairo_linear_pattern_t *linear) -{ - _cairo_xml_printf (xml, - "", - linear->pd1.x, linear->pd1.y, - linear->pd2.x, linear->pd2.y); - _cairo_xml_indent (xml, 2); - _cairo_xml_emit_gradient (xml, &linear->base); - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_emit_radial (cairo_xml_t *xml, - const cairo_radial_pattern_t *radial) -{ - _cairo_xml_printf (xml, - "", - radial->cd1.center.x, radial->cd1.center.y, radial->cd1.radius, - radial->cd2.center.x, radial->cd2.center.y, radial->cd2.radius); - _cairo_xml_indent (xml, 2); - _cairo_xml_emit_gradient (xml, &radial->base); - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_write_func (void *closure, const unsigned char *data, unsigned len) -{ - _cairo_output_stream_write (closure, data, len); - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_emit_image (cairo_xml_t *xml, - cairo_image_surface_t *image) -{ - cairo_output_stream_t *stream; - cairo_status_t status; - - _cairo_xml_printf_start (xml, - "", - image->width, image->height, - _format_to_string (image->format)); - - stream = _cairo_base64_stream_create (xml->stream); - status = cairo_surface_write_to_png_stream (&image->base, - _write_func, stream); - assert (status == CAIRO_STATUS_SUCCESS); - status = _cairo_output_stream_destroy (stream); - if (unlikely (status)) - return status; - - _cairo_xml_printf_end (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_emit_surface (cairo_xml_t *xml, - const cairo_surface_pattern_t *pattern) -{ - cairo_surface_t *source = pattern->surface; - cairo_status_t status; - - if (_cairo_surface_is_recording (source)) { - status = cairo_xml_for_recording_surface (&xml->base, source); - } else { - cairo_image_surface_t *image; - void *image_extra; - - status = _cairo_surface_acquire_source_image (source, - &image, &image_extra); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_image (xml, image); - - _cairo_surface_release_source_image (source, image, image_extra); - } - - return status; -} - -static cairo_status_t -_cairo_xml_emit_pattern (cairo_xml_t *xml, - const char *source_or_mask, - const cairo_pattern_t *pattern) -{ - cairo_status_t status; - - _cairo_xml_printf (xml, "<%s-pattern>", source_or_mask); - _cairo_xml_indent (xml, 2); - - switch (pattern->type) { - case CAIRO_PATTERN_TYPE_SOLID: - status = _cairo_xml_emit_solid (xml, (cairo_solid_pattern_t *) pattern); - break; - case CAIRO_PATTERN_TYPE_LINEAR: - status = _cairo_xml_emit_linear (xml, (cairo_linear_pattern_t *) pattern); - break; - case CAIRO_PATTERN_TYPE_RADIAL: - status = _cairo_xml_emit_radial (xml, (cairo_radial_pattern_t *) pattern); - break; - case CAIRO_PATTERN_TYPE_SURFACE: - status = _cairo_xml_emit_surface (xml, (cairo_surface_pattern_t *) pattern); - break; - default: - ASSERT_NOT_REACHED; - status = CAIRO_INT_STATUS_UNSUPPORTED; - break; - } - - if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) { - _cairo_xml_emit_matrix (xml, &pattern->matrix); - _cairo_xml_printf (xml, - "%s", - _extend_to_string (pattern->extend)); - _cairo_xml_printf (xml, - "%s", - _filter_to_string (pattern->filter)); - } - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, "", source_or_mask); - - return status; -} - -static cairo_int_status_t -_cairo_xml_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - cairo_xml_surface_t *surface = abstract_surface; - cairo_xml_t *xml = to_xml (surface); - cairo_status_t status; - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); - - status = _cairo_xml_surface_emit_clip (surface, clip); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_pattern (xml, "source", source); - if (unlikely (status)) - return status; - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_xml_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - cairo_xml_surface_t *surface = abstract_surface; - cairo_xml_t *xml = to_xml (surface); - cairo_status_t status; - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); - - status = _cairo_xml_surface_emit_clip (surface, clip); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_pattern (xml, "source", source); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_pattern (xml, "mask", mask); - if (unlikely (status)) - return status; - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_xml_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_xml_surface_t *surface = abstract_surface; - cairo_xml_t *xml = to_xml (surface); - cairo_status_t status; - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); - _cairo_xml_emit_double (xml, "line-width", style->line_width); - _cairo_xml_emit_double (xml, "miter-limit", style->miter_limit); - _cairo_xml_emit_string (xml, "line-cap", _line_cap_to_string (style->line_cap)); - _cairo_xml_emit_string (xml, "line-join", _line_join_to_string (style->line_join)); - - status = _cairo_xml_surface_emit_clip (surface, clip); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_pattern (xml, "source", source); - if (unlikely (status)) - return status; - - if (style->num_dashes) { - unsigned int i; - - _cairo_xml_printf_start (xml, "", - style->dash_offset); - for (i = 0; i < style->num_dashes; i++) - _cairo_xml_printf_continue (xml, "%f ", style->dash[i]); - - _cairo_xml_printf_end (xml, ""); - } - - _cairo_xml_emit_path (xml, path); - _cairo_xml_emit_double (xml, "tolerance", tolerance); - _cairo_xml_emit_string (xml, "antialias", _antialias_to_string (antialias)); - - _cairo_xml_emit_matrix (xml, ctm); - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -_cairo_xml_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t*path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - cairo_xml_surface_t *surface = abstract_surface; - cairo_xml_t *xml = to_xml (surface); - cairo_status_t status; - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); - - status = _cairo_xml_surface_emit_clip (surface, clip); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_pattern (xml, "source", source); - if (unlikely (status)) - return status; - - _cairo_xml_emit_path (xml, path); - _cairo_xml_emit_double (xml, "tolerance", tolerance); - _cairo_xml_emit_string (xml, "antialias", _antialias_to_string (antialias)); - _cairo_xml_emit_string (xml, "fill-rule", _fill_rule_to_string (fill_rule)); - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -#if CAIRO_HAS_FT_FONT -#include "cairo-ft-private.h" -static cairo_status_t -_cairo_xml_emit_type42_font (cairo_xml_t *xml, - cairo_scaled_font_t *scaled_font) -{ - const cairo_scaled_font_backend_t *backend; - cairo_output_stream_t *base64_stream; - cairo_output_stream_t *zlib_stream; - cairo_status_t status, status2; - unsigned long size; - uint32_t len; - uint8_t *buf; - - backend = scaled_font->backend; - if (backend->load_truetype_table == NULL) - return CAIRO_INT_STATUS_UNSUPPORTED; - - size = 0; - status = backend->load_truetype_table (scaled_font, 0, 0, NULL, &size); - if (unlikely (status)) - return status; - - buf = malloc (size); - if (unlikely (buf == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = backend->load_truetype_table (scaled_font, 0, 0, buf, &size); - if (unlikely (status)) { - free (buf); - return status; - } - - _cairo_xml_printf_start (xml, "", - _cairo_ft_scaled_font_get_load_flags (scaled_font)); - - - base64_stream = _cairo_base64_stream_create (xml->stream); - len = size; - _cairo_output_stream_write (base64_stream, &len, sizeof (len)); - - zlib_stream = _cairo_deflate_stream_create (base64_stream); - - _cairo_output_stream_write (zlib_stream, buf, size); - free (buf); - - status2 = _cairo_output_stream_destroy (zlib_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - status2 = _cairo_output_stream_destroy (base64_stream); - if (status == CAIRO_STATUS_SUCCESS) - status = status2; - - _cairo_xml_printf_end (xml, ""); - - return status; -} -#else -static cairo_status_t -_cairo_xml_emit_type42_font (cairo_xml_t *xml, - cairo_scaled_font_t *scaled_font) -{ - return CAIRO_INT_STATUS_UNSUPPORTED; -} -#endif - -static cairo_status_t -_cairo_xml_emit_type3_font (cairo_xml_t *xml, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs) -{ - _cairo_xml_printf_start (xml, ""); - _cairo_xml_printf_end (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -_cairo_xml_emit_scaled_font (cairo_xml_t *xml, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs) -{ - cairo_int_status_t status; - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - status = _cairo_xml_emit_type42_font (xml, scaled_font); - if (status == CAIRO_INT_STATUS_UNSUPPORTED) { - status = _cairo_xml_emit_type3_font (xml, scaled_font, - glyphs, num_glyphs); - } - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return status; -} - -static cairo_int_status_t -_cairo_xml_surface_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - cairo_xml_surface_t *surface = abstract_surface; - cairo_xml_t *xml = to_xml (surface); - cairo_status_t status; - int i; - - _cairo_xml_printf (xml, ""); - _cairo_xml_indent (xml, 2); - - _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); - - status = _cairo_xml_surface_emit_clip (surface, clip); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_pattern (xml, "source", source); - if (unlikely (status)) - return status; - - status = _cairo_xml_emit_scaled_font (xml, scaled_font, glyphs, num_glyphs); - if (unlikely (status)) - return status; - - for (i = 0; i < num_glyphs; i++) { - _cairo_xml_printf (xml, "%f %f", - glyphs[i].index, - glyphs[i].x, - glyphs[i].y); - } - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_surface_backend_t -_cairo_xml_surface_backend = { - CAIRO_SURFACE_TYPE_XML, - NULL, - - _cairo_default_context_create, - - _cairo_xml_surface_create_similar, - NULL, /* create_similar_image */ - NULL, /* map_to_image */ - NULL, /* unmap_image */ - - _cairo_surface_default_source, - NULL, /* acquire source image */ - NULL, /* release source image */ - NULL, /* snapshot */ - - NULL, /* copy page */ - NULL, /* show page */ - - _cairo_xml_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - _cairo_xml_surface_paint, - _cairo_xml_surface_mask, - _cairo_xml_surface_stroke, - _cairo_xml_surface_fill, - NULL, /* fill_stroke */ - _cairo_xml_surface_glyphs, -}; - -static cairo_surface_t * -_cairo_xml_surface_create_internal (cairo_device_t *device, - cairo_content_t content, - double width, - double height) -{ - cairo_xml_surface_t *surface; - - surface = malloc (sizeof (cairo_xml_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &_cairo_xml_surface_backend, - device, - content); - - surface->width = width; - surface->height = height; - - return &surface->base; -} - -cairo_device_t * -cairo_xml_create (const char *filename) -{ - cairo_output_stream_t *stream; - cairo_status_t status; - - stream = _cairo_output_stream_create_for_filename (filename); - if ((status = _cairo_output_stream_get_status (stream))) - return _cairo_device_create_in_error (status); - - return _cairo_xml_create_internal (stream); -} - -cairo_device_t * -cairo_xml_create_for_stream (cairo_write_func_t write_func, - void *closure) -{ - cairo_output_stream_t *stream; - cairo_status_t status; - - stream = _cairo_output_stream_create (write_func, NULL, closure); - if ((status = _cairo_output_stream_get_status (stream))) - return _cairo_device_create_in_error (status); - - return _cairo_xml_create_internal (stream); -} - -cairo_surface_t * -cairo_xml_surface_create (cairo_device_t *device, - cairo_content_t content, - double width, double height) -{ - if (unlikely (device->backend->type != CAIRO_DEVICE_TYPE_XML)) - return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - - if (unlikely (device->status)) - return _cairo_surface_create_in_error (device->status); - - return _cairo_xml_surface_create_internal (device, content, width, height); -} - -cairo_status_t -cairo_xml_for_recording_surface (cairo_device_t *device, - cairo_surface_t *recording_surface) -{ - cairo_box_t bbox; - cairo_rectangle_int_t extents; - cairo_surface_t *surface; - cairo_xml_t *xml; - cairo_status_t status; - - if (unlikely (device->status)) - return device->status; - - if (unlikely (recording_surface->status)) - return recording_surface->status; - - if (unlikely (device->backend->type != CAIRO_DEVICE_TYPE_XML)) - return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); - - if (unlikely (! _cairo_surface_is_recording (recording_surface))) - return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); - - status = _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface, - &bbox, NULL); - if (unlikely (status)) - return status; - - _cairo_box_round_to_rectangle (&bbox, &extents); - surface = _cairo_xml_surface_create_internal (device, - recording_surface->content, - extents.width, - extents.height); - if (unlikely (surface->status)) - return surface->status; - - xml = (cairo_xml_t *) device; - - _cairo_xml_printf (xml, - "", - _content_to_string (recording_surface->content), - extents.width, extents.height); - _cairo_xml_indent (xml, 2); - - cairo_surface_set_device_offset (surface, -extents.x, -extents.y); - status = _cairo_recording_surface_replay (recording_surface, surface); - cairo_surface_destroy (surface); - - _cairo_xml_indent (xml, -2); - _cairo_xml_printf (xml, ""); - - return status; -} -slim_hidden_def (cairo_xml_for_recording_surface); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml.h deleted file mode 100644 index 9ae76e90aae..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo-xml.h +++ /dev/null @@ -1,67 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2009 Chris Wilson - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Chris Wilson - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef CAIRO_XML_H -#define CAIRO_XML_H - -#include "cairo.h" - -#if CAIRO_HAS_XML_SURFACE - -CAIRO_BEGIN_DECLS - -cairo_public cairo_device_t * -cairo_xml_create (const char *filename); - -cairo_public cairo_device_t * -cairo_xml_create_for_stream (cairo_write_func_t write_func, - void *closure); - -cairo_public cairo_surface_t * -cairo_xml_surface_create (cairo_device_t *xml, - cairo_content_t content, - double width, double height); - -cairo_public cairo_status_t -cairo_xml_for_recording_surface (cairo_device_t *xml, - cairo_surface_t *surface); - -CAIRO_END_DECLS - -#else /*CAIRO_HAS_XML_SURFACE*/ -# error Cairo was not compiled with support for the XML backend -#endif /*CAIRO_HAS_XML_SURFACE*/ - -#endif /*CAIRO_XML_H*/ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo.c b/Build/source/libs/cairo/cairo-1.14.2/src/cairo.c deleted file mode 100644 index e3acf4d46c7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo.c +++ /dev/null @@ -1,4031 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Chris Wilson - */ - -#include "cairoint.h" -#include "cairo-private.h" - -#include "cairo-backend-private.h" -#include "cairo-error-private.h" -#include "cairo-path-private.h" -#include "cairo-pattern-private.h" -#include "cairo-surface-private.h" -#include "cairo-surface-backend-private.h" - -#include - -/** - * SECTION:cairo - * @Title: cairo_t - * @Short_Description: The cairo drawing context - * @See_Also: #cairo_surface_t - * - * #cairo_t is the main object used when drawing with cairo. To - * draw with cairo, you create a #cairo_t, set the target surface, - * and drawing options for the #cairo_t, create shapes with - * functions like cairo_move_to() and cairo_line_to(), and then - * draw shapes with cairo_stroke() or cairo_fill(). - * - * #cairo_t's can be pushed to a stack via cairo_save(). - * They may then safely be changed, without losing the current state. - * Use cairo_restore() to restore to the saved state. - **/ - -/** - * SECTION:cairo-text - * @Title: text - * @Short_Description: Rendering text and glyphs - * @See_Also: #cairo_font_face_t, #cairo_scaled_font_t, cairo_text_path(), - * cairo_glyph_path() - * - * The functions with text in their name form cairo's - * toy text API. The toy API takes UTF-8 encoded - * text and is limited in its functionality to rendering simple - * left-to-right text with no advanced features. That means for example - * that most complex scripts like Hebrew, Arabic, and Indic scripts are - * out of question. No kerning or correct positioning of diacritical marks - * either. The font selection is pretty limited too and doesn't handle the - * case that the selected font does not cover the characters in the text. - * This set of functions are really that, a toy text API, for testing and - * demonstration purposes. Any serious application should avoid them. - * - * The functions with glyphs in their name form cairo's - * low-level text API. The low-level API relies on - * the user to convert text to a set of glyph indexes and positions. This - * is a very hard problem and is best handled by external libraries, like - * the pangocairo that is part of the Pango text layout and rendering library. - * Pango is available from http://www.pango.org/. - **/ - -/** - * SECTION:cairo-transforms - * @Title: Transformations - * @Short_Description: Manipulating the current transformation matrix - * @See_Also: #cairo_matrix_t - * - * The current transformation matrix, ctm, is a - * two-dimensional affine transformation that maps all coordinates and other - * drawing instruments from the user space into the - * surface's canonical coordinate system, also known as the device - * space. - **/ - -#define DEFINE_NIL_CONTEXT(status) \ - { \ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ - status, /* status */ \ - { 0, 0, 0, NULL }, /* user_data */ \ - NULL \ - } - -static const cairo_t _cairo_nil[] = { - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_MEMORY), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_RESTORE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_POP_GROUP), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_CURRENT_POINT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MATRIX), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STATUS), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NULL_POINTER), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRING), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_PATH_DATA), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_READ_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_WRITE_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_FINISHED), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_PATTERN_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CONTENT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_FORMAT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_VISUAL), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_FILE_NOT_FOUND), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DASH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DSC_COMMENT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_INDEX), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_TEMP_FILE_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRIDE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_FONT_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_IMMUTABLE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NEGATIVE_COUNT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CLUSTERS), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SLANT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_WEIGHT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SIZE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MESH_CONSTRUCTION), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_FINISHED), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_JBIG2_GLOBAL_MISSING) - -}; -COMPILE_TIME_ASSERT (ARRAY_LENGTH (_cairo_nil) == CAIRO_STATUS_LAST_STATUS - 1); - -/** - * _cairo_set_error: - * @cr: a cairo context - * @status: a status value indicating an error - * - * Atomically sets cr->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS. - * - * All assignments of an error status to cr->status should happen - * through _cairo_set_error(). Note that due to the nature of the atomic - * operation, it is not safe to call this function on the nil objects. - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - **/ -static void -_cairo_set_error (cairo_t *cr, cairo_status_t status) -{ - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&cr->status, _cairo_error (status)); -} - -cairo_t * -_cairo_create_in_error (cairo_status_t status) -{ - cairo_t *cr; - - assert (status != CAIRO_STATUS_SUCCESS); - - cr = (cairo_t *) &_cairo_nil[status - CAIRO_STATUS_NO_MEMORY]; - assert (status == cr->status); - - return cr; -} - -/** - * cairo_create: - * @target: target surface for the context - * - * Creates a new #cairo_t with all graphics state parameters set to - * default values and with @target as a target surface. The target - * surface should be constructed with a backend-specific function such - * as cairo_image_surface_create() (or any other - * cairo_backend_surface_create() - * variant). - * - * This function references @target, so you can immediately - * call cairo_surface_destroy() on it if you don't need to - * maintain a separate reference to it. - * - * Return value: a newly allocated #cairo_t with a reference - * count of 1. The initial reference count should be released - * with cairo_destroy() when you are done using the #cairo_t. - * This function never returns %NULL. If memory cannot be - * allocated, a special #cairo_t object will be returned on - * which cairo_status() returns %CAIRO_STATUS_NO_MEMORY. If - * you attempt to target a surface which does not support - * writing (such as #cairo_mime_surface_t) then a - * %CAIRO_STATUS_WRITE_ERROR will be raised. You can use this - * object normally, but no drawing will be done. - * - * Since: 1.0 - **/ -cairo_t * -cairo_create (cairo_surface_t *target) -{ - if (unlikely (target == NULL)) - return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); - if (unlikely (target->status)) - return _cairo_create_in_error (target->status); - if (unlikely (target->finished)) - return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); - - if (target->backend->create_context == NULL) - return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); - - return target->backend->create_context (target); - -} -slim_hidden_def (cairo_create); - -void -_cairo_init (cairo_t *cr, - const cairo_backend_t *backend) -{ - CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1); - cr->status = CAIRO_STATUS_SUCCESS; - _cairo_user_data_array_init (&cr->user_data); - - cr->backend = backend; -} - -/** - * cairo_reference: - * @cr: a #cairo_t - * - * Increases the reference count on @cr by one. This prevents - * @cr from being destroyed until a matching call to cairo_destroy() - * is made. - * - * The number of references to a #cairo_t can be get using - * cairo_get_reference_count(). - * - * Return value: the referenced #cairo_t. - * - * Since: 1.0 - **/ -cairo_t * -cairo_reference (cairo_t *cr) -{ - if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) - return cr; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count)); - - _cairo_reference_count_inc (&cr->ref_count); - - return cr; -} - -void -_cairo_fini (cairo_t *cr) -{ - _cairo_user_data_array_fini (&cr->user_data); -} - -/** - * cairo_destroy: - * @cr: a #cairo_t - * - * Decreases the reference count on @cr by one. If the result - * is zero, then @cr and all associated resources are freed. - * See cairo_reference(). - * - * Since: 1.0 - **/ -void -cairo_destroy (cairo_t *cr) -{ - if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&cr->ref_count)) - return; - - cr->backend->destroy (cr); -} -slim_hidden_def (cairo_destroy); - -/** - * cairo_get_user_data: - * @cr: a #cairo_t - * @key: the address of the #cairo_user_data_key_t the user data was - * attached to - * - * Return user data previously attached to @cr using the specified - * key. If no user data has been attached with the given key this - * function returns %NULL. - * - * Return value: the user data previously attached or %NULL. - * - * Since: 1.4 - **/ -void * -cairo_get_user_data (cairo_t *cr, - const cairo_user_data_key_t *key) -{ - return _cairo_user_data_array_get_data (&cr->user_data, key); -} - -/** - * cairo_set_user_data: - * @cr: a #cairo_t - * @key: the address of a #cairo_user_data_key_t to attach the user data to - * @user_data: the user data to attach to the #cairo_t - * @destroy: a #cairo_destroy_func_t which will be called when the - * #cairo_t is destroyed or when new user data is attached using the - * same key. - * - * Attach user data to @cr. To remove user data from a surface, - * call this function with the key that was used to set it and %NULL - * for @data. - * - * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a - * slot could not be allocated for the user data. - * - * Since: 1.4 - **/ -cairo_status_t -cairo_set_user_data (cairo_t *cr, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) - return cr->status; - - return _cairo_user_data_array_set_data (&cr->user_data, - key, user_data, destroy); -} - -/** - * cairo_get_reference_count: - * @cr: a #cairo_t - * - * Returns the current reference count of @cr. - * - * Return value: the current reference count of @cr. If the - * object is a nil object, 0 will be returned. - * - * Since: 1.4 - **/ -unsigned int -cairo_get_reference_count (cairo_t *cr) -{ - if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&cr->ref_count); -} - -/** - * cairo_save: - * @cr: a #cairo_t - * - * Makes a copy of the current state of @cr and saves it - * on an internal stack of saved states for @cr. When - * cairo_restore() is called, @cr will be restored to - * the saved state. Multiple calls to cairo_save() and - * cairo_restore() can be nested; each call to cairo_restore() - * restores the state from the matching paired cairo_save(). - * - * It isn't necessary to clear all saved states before - * a #cairo_t is freed. If the reference count of a #cairo_t - * drops to zero in response to a call to cairo_destroy(), - * any saved states will be freed along with the #cairo_t. - * - * Since: 1.0 - **/ -void -cairo_save (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->save (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_save); - -/** - * cairo_restore: - * @cr: a #cairo_t - * - * Restores @cr to the state saved by a preceding call to - * cairo_save() and removes that state from the stack of - * saved states. - * - * Since: 1.0 - **/ -void -cairo_restore (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->restore (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_restore); - -/** - * cairo_push_group: - * @cr: a cairo context - * - * Temporarily redirects drawing to an intermediate surface known as a - * group. The redirection lasts until the group is completed by a call - * to cairo_pop_group() or cairo_pop_group_to_source(). These calls - * provide the result of any drawing to the group as a pattern, - * (either as an explicit object, or set as the source pattern). - * - * This group functionality can be convenient for performing - * intermediate compositing. One common use of a group is to render - * objects as opaque within the group, (so that they occlude each - * other), and then blend the result with translucence onto the - * destination. - * - * Groups can be nested arbitrarily deep by making balanced calls to - * cairo_push_group()/cairo_pop_group(). Each call pushes/pops the new - * target group onto/from a stack. - * - * The cairo_push_group() function calls cairo_save() so that any - * changes to the graphics state will not be visible outside the - * group, (the pop_group functions call cairo_restore()). - * - * By default the intermediate group will have a content type of - * %CAIRO_CONTENT_COLOR_ALPHA. Other content types can be chosen for - * the group by using cairo_push_group_with_content() instead. - * - * As an example, here is how one might fill and stroke a path with - * translucence, but without any portion of the fill being visible - * under the stroke: - * - * - * cairo_push_group (cr); - * cairo_set_source (cr, fill_pattern); - * cairo_fill_preserve (cr); - * cairo_set_source (cr, stroke_pattern); - * cairo_stroke (cr); - * cairo_pop_group_to_source (cr); - * cairo_paint_with_alpha (cr, alpha); - * - * - * Since: 1.2 - **/ -void -cairo_push_group (cairo_t *cr) -{ - cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA); -} - -/** - * cairo_push_group_with_content: - * @cr: a cairo context - * @content: a #cairo_content_t indicating the type of group that - * will be created - * - * Temporarily redirects drawing to an intermediate surface known as a - * group. The redirection lasts until the group is completed by a call - * to cairo_pop_group() or cairo_pop_group_to_source(). These calls - * provide the result of any drawing to the group as a pattern, - * (either as an explicit object, or set as the source pattern). - * - * The group will have a content type of @content. The ability to - * control this content type is the only distinction between this - * function and cairo_push_group() which you should see for a more - * detailed description of group rendering. - * - * Since: 1.2 - **/ -void -cairo_push_group_with_content (cairo_t *cr, cairo_content_t content) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->push_group (cr, content); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_push_group_with_content); - -/** - * cairo_pop_group: - * @cr: a cairo context - * - * Terminates the redirection begun by a call to cairo_push_group() or - * cairo_push_group_with_content() and returns a new pattern - * containing the results of all drawing operations performed to the - * group. - * - * The cairo_pop_group() function calls cairo_restore(), (balancing a - * call to cairo_save() by the push_group function), so that any - * changes to the graphics state will not be visible outside the - * group. - * - * Return value: a newly created (surface) pattern containing the - * results of all drawing operations performed to the group. The - * caller owns the returned object and should call - * cairo_pattern_destroy() when finished with it. - * - * Since: 1.2 - **/ -cairo_pattern_t * -cairo_pop_group (cairo_t *cr) -{ - cairo_pattern_t *group_pattern; - - if (unlikely (cr->status)) - return _cairo_pattern_create_in_error (cr->status); - - group_pattern = cr->backend->pop_group (cr); - if (unlikely (group_pattern->status)) - _cairo_set_error (cr, group_pattern->status); - - return group_pattern; -} -slim_hidden_def(cairo_pop_group); - -/** - * cairo_pop_group_to_source: - * @cr: a cairo context - * - * Terminates the redirection begun by a call to cairo_push_group() or - * cairo_push_group_with_content() and installs the resulting pattern - * as the source pattern in the given cairo context. - * - * The behavior of this function is equivalent to the sequence of - * operations: - * - * - * cairo_pattern_t *group = cairo_pop_group (cr); - * cairo_set_source (cr, group); - * cairo_pattern_destroy (group); - * - * - * but is more convenient as their is no need for a variable to store - * the short-lived pointer to the pattern. - * - * The cairo_pop_group() function calls cairo_restore(), (balancing a - * call to cairo_save() by the push_group function), so that any - * changes to the graphics state will not be visible outside the - * group. - * - * Since: 1.2 - **/ -void -cairo_pop_group_to_source (cairo_t *cr) -{ - cairo_pattern_t *group_pattern; - - group_pattern = cairo_pop_group (cr); - cairo_set_source (cr, group_pattern); - cairo_pattern_destroy (group_pattern); -} - -/** - * cairo_set_operator: - * @cr: a #cairo_t - * @op: a compositing operator, specified as a #cairo_operator_t - * - * Sets the compositing operator to be used for all drawing - * operations. See #cairo_operator_t for details on the semantics of - * each available compositing operator. - * - * The default operator is %CAIRO_OPERATOR_OVER. - * - * Since: 1.0 - **/ -void -cairo_set_operator (cairo_t *cr, cairo_operator_t op) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_operator (cr, op); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_operator); - - -#if 0 -/** - * cairo_set_opacity: - * @cr: a #cairo_t - * @opacity: the level of opacity to use when compositing - * - * Sets the compositing opacity to be used for all drawing - * operations. The effect is to fade out the operations - * using the alpha value. - * - * The default opacity is 1. - * - * Since: TBD - **/ -void -cairo_set_opacity (cairo_t *cr, double opacity) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_opacity (cr, opacity); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -#endif - -/** - * cairo_set_source_rgb: - * @cr: a cairo context - * @red: red component of color - * @green: green component of color - * @blue: blue component of color - * - * Sets the source pattern within @cr to an opaque color. This opaque - * color will then be used for any subsequent drawing operation until - * a new source pattern is set. - * - * The color components are floating point numbers in the range 0 to - * 1. If the values passed in are outside that range, they will be - * clamped. - * - * The default source pattern is opaque black, (that is, it is - * equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)). - * - * Since: 1.0 - **/ -void -cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_source_rgba (cr, red, green, blue, 1.); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_source_rgb); - -/** - * cairo_set_source_rgba: - * @cr: a cairo context - * @red: red component of color - * @green: green component of color - * @blue: blue component of color - * @alpha: alpha component of color - * - * Sets the source pattern within @cr to a translucent color. This - * color will then be used for any subsequent drawing operation until - * a new source pattern is set. - * - * The color and alpha components are floating point numbers in the - * range 0 to 1. If the values passed in are outside that range, they - * will be clamped. - * - * The default source pattern is opaque black, (that is, it is - * equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)). - * - * Since: 1.0 - **/ -void -cairo_set_source_rgba (cairo_t *cr, - double red, double green, double blue, - double alpha) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_source_rgba (cr, red, green, blue, alpha); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_set_source_surface: - * @cr: a cairo context - * @surface: a surface to be used to set the source pattern - * @x: User-space X coordinate for surface origin - * @y: User-space Y coordinate for surface origin - * - * This is a convenience function for creating a pattern from @surface - * and setting it as the source in @cr with cairo_set_source(). - * - * The @x and @y parameters give the user-space coordinate at which - * the surface origin should appear. (The surface origin is its - * upper-left corner before any transformation has been applied.) The - * @x and @y parameters are negated and then set as translation values - * in the pattern matrix. - * - * Other than the initial translation pattern matrix, as described - * above, all other pattern attributes, (such as its extend mode), are - * set to the default values as in cairo_pattern_create_for_surface(). - * The resulting pattern can be queried with cairo_get_source() so - * that these attributes can be modified if desired, (eg. to create a - * repeating pattern with cairo_pattern_set_extend()). - * - * Since: 1.0 - **/ -void -cairo_set_source_surface (cairo_t *cr, - cairo_surface_t *surface, - double x, - double y) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (unlikely (surface == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - status = cr->backend->set_source_surface (cr, surface, x, y); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_source_surface); - -/** - * cairo_set_source: - * @cr: a cairo context - * @source: a #cairo_pattern_t to be used as the source for - * subsequent drawing operations. - * - * Sets the source pattern within @cr to @source. This pattern - * will then be used for any subsequent drawing operation until a new - * source pattern is set. - * - * Note: The pattern's transformation matrix will be locked to the - * user space in effect at the time of cairo_set_source(). This means - * that further modifications of the current transformation matrix - * will not affect the source pattern. See cairo_pattern_set_matrix(). - * - * The default source pattern is a solid pattern that is opaque black, - * (that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, - * 0.0)). - * - * Since: 1.0 - **/ -void -cairo_set_source (cairo_t *cr, cairo_pattern_t *source) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (unlikely (source == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - if (unlikely (source->status)) { - _cairo_set_error (cr, source->status); - return; - } - - status = cr->backend->set_source (cr, source); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_source); - -/** - * cairo_get_source: - * @cr: a cairo context - * - * Gets the current source pattern for @cr. - * - * Return value: the current source pattern. This object is owned by - * cairo. To keep a reference to it, you must call - * cairo_pattern_reference(). - * - * Since: 1.0 - **/ -cairo_pattern_t * -cairo_get_source (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_pattern_create_in_error (cr->status); - - return cr->backend->get_source (cr); -} - -/** - * cairo_set_tolerance: - * @cr: a #cairo_t - * @tolerance: the tolerance, in device units (typically pixels) - * - * Sets the tolerance used when converting paths into trapezoids. - * Curved segments of the path will be subdivided until the maximum - * deviation between the original path and the polygonal approximation - * is less than @tolerance. The default value is 0.1. A larger - * value will give better performance, a smaller value, better - * appearance. (Reducing the value from the default value of 0.1 - * is unlikely to improve appearance significantly.) The accuracy of paths - * within Cairo is limited by the precision of its internal arithmetic, and - * the prescribed @tolerance is restricted to the smallest - * representable internal value. - * - * Since: 1.0 - **/ -void -cairo_set_tolerance (cairo_t *cr, double tolerance) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_tolerance (cr, tolerance); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_tolerance); - -/** - * cairo_set_antialias: - * @cr: a #cairo_t - * @antialias: the new antialiasing mode - * - * Set the antialiasing mode of the rasterizer used for drawing shapes. - * This value is a hint, and a particular backend may or may not support - * a particular value. At the current time, no backend supports - * %CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes. - * - * Note that this option does not affect text rendering, instead see - * cairo_font_options_set_antialias(). - * - * Since: 1.0 - **/ -void -cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_antialias (cr, antialias); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_set_fill_rule: - * @cr: a #cairo_t - * @fill_rule: a fill rule, specified as a #cairo_fill_rule_t - * - * Set the current fill rule within the cairo context. The fill rule - * is used to determine which regions are inside or outside a complex - * (potentially self-intersecting) path. The current fill rule affects - * both cairo_fill() and cairo_clip(). See #cairo_fill_rule_t for details - * on the semantics of each available fill rule. - * - * The default fill rule is %CAIRO_FILL_RULE_WINDING. - * - * Since: 1.0 - **/ -void -cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_fill_rule (cr, fill_rule); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_set_line_width: - * @cr: a #cairo_t - * @width: a line width - * - * Sets the current line width within the cairo context. The line - * width value specifies the diameter of a pen that is circular in - * user space, (though device-space pen may be an ellipse in general - * due to scaling/shear/rotation of the CTM). - * - * Note: When the description above refers to user space and CTM it - * refers to the user space and CTM in effect at the time of the - * stroking operation, not the user space and CTM in effect at the - * time of the call to cairo_set_line_width(). The simplest usage - * makes both of these spaces identical. That is, if there is no - * change to the CTM between a call to cairo_set_line_width() and the - * stroking operation, then one can just pass user-space values to - * cairo_set_line_width() and ignore this note. - * - * As with the other stroke parameters, the current line width is - * examined by cairo_stroke(), cairo_stroke_extents(), and - * cairo_stroke_to_path(), but does not have any effect during path - * construction. - * - * The default line width value is 2.0. - * - * Since: 1.0 - **/ -void -cairo_set_line_width (cairo_t *cr, double width) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (width < 0.) - width = 0.; - - status = cr->backend->set_line_width (cr, width); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_line_width); - -/** - * cairo_set_line_cap: - * @cr: a cairo context - * @line_cap: a line cap style - * - * Sets the current line cap style within the cairo context. See - * #cairo_line_cap_t for details about how the available line cap - * styles are drawn. - * - * As with the other stroke parameters, the current line cap style is - * examined by cairo_stroke(), cairo_stroke_extents(), and - * cairo_stroke_to_path(), but does not have any effect during path - * construction. - * - * The default line cap style is %CAIRO_LINE_CAP_BUTT. - * - * Since: 1.0 - **/ -void -cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_line_cap (cr, line_cap); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_line_cap); - -/** - * cairo_set_line_join: - * @cr: a cairo context - * @line_join: a line join style - * - * Sets the current line join style within the cairo context. See - * #cairo_line_join_t for details about how the available line join - * styles are drawn. - * - * As with the other stroke parameters, the current line join style is - * examined by cairo_stroke(), cairo_stroke_extents(), and - * cairo_stroke_to_path(), but does not have any effect during path - * construction. - * - * The default line join style is %CAIRO_LINE_JOIN_MITER. - * - * Since: 1.0 - **/ -void -cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_line_join (cr, line_join); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_line_join); - -/** - * cairo_set_dash: - * @cr: a cairo context - * @dashes: an array specifying alternate lengths of on and off stroke portions - * @num_dashes: the length of the dashes array - * @offset: an offset into the dash pattern at which the stroke should start - * - * Sets the dash pattern to be used by cairo_stroke(). A dash pattern - * is specified by @dashes, an array of positive values. Each value - * provides the length of alternate "on" and "off" portions of the - * stroke. The @offset specifies an offset into the pattern at which - * the stroke begins. - * - * Each "on" segment will have caps applied as if the segment were a - * separate sub-path. In particular, it is valid to use an "on" length - * of 0.0 with %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE in order - * to distributed dots or squares along a path. - * - * Note: The length values are in user-space units as evaluated at the - * time of stroking. This is not necessarily the same as the user - * space at the time of cairo_set_dash(). - * - * If @num_dashes is 0 dashing is disabled. - * - * If @num_dashes is 1 a symmetric pattern is assumed with alternating - * on and off portions of the size specified by the single value in - * @dashes. - * - * If any value in @dashes is negative, or if all values are 0, then - * @cr will be put into an error state with a status of - * %CAIRO_STATUS_INVALID_DASH. - * - * Since: 1.0 - **/ -void -cairo_set_dash (cairo_t *cr, - const double *dashes, - int num_dashes, - double offset) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_dash (cr, dashes, num_dashes, offset); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_get_dash_count: - * @cr: a #cairo_t - * - * This function returns the length of the dash array in @cr (0 if dashing - * is not currently in effect). - * - * See also cairo_set_dash() and cairo_get_dash(). - * - * Return value: the length of the dash array, or 0 if no dash array set. - * - * Since: 1.4 - **/ -int -cairo_get_dash_count (cairo_t *cr) -{ - int num_dashes; - - if (unlikely (cr->status)) - return 0; - - cr->backend->get_dash (cr, NULL, &num_dashes, NULL); - - return num_dashes; -} - -/** - * cairo_get_dash: - * @cr: a #cairo_t - * @dashes: return value for the dash array, or %NULL - * @offset: return value for the current dash offset, or %NULL - * - * Gets the current dash array. If not %NULL, @dashes should be big - * enough to hold at least the number of values returned by - * cairo_get_dash_count(). - * - * Since: 1.4 - **/ -void -cairo_get_dash (cairo_t *cr, - double *dashes, - double *offset) -{ - if (unlikely (cr->status)) - return; - - cr->backend->get_dash (cr, dashes, NULL, offset); -} - -/** - * cairo_set_miter_limit: - * @cr: a cairo context - * @limit: miter limit to set - * - * Sets the current miter limit within the cairo context. - * - * If the current line join style is set to %CAIRO_LINE_JOIN_MITER - * (see cairo_set_line_join()), the miter limit is used to determine - * whether the lines should be joined with a bevel instead of a miter. - * Cairo divides the length of the miter by the line width. - * If the result is greater than the miter limit, the style is - * converted to a bevel. - * - * As with the other stroke parameters, the current line miter limit is - * examined by cairo_stroke(), cairo_stroke_extents(), and - * cairo_stroke_to_path(), but does not have any effect during path - * construction. - * - * The default miter limit value is 10.0, which will convert joins - * with interior angles less than 11 degrees to bevels instead of - * miters. For reference, a miter limit of 2.0 makes the miter cutoff - * at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90 - * degrees. - * - * A miter limit for a desired angle can be computed as: miter limit = - * 1/sin(angle/2) - * - * Since: 1.0 - **/ -void -cairo_set_miter_limit (cairo_t *cr, double limit) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_miter_limit (cr, limit); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_translate: - * @cr: a cairo context - * @tx: amount to translate in the X direction - * @ty: amount to translate in the Y direction - * - * Modifies the current transformation matrix (CTM) by translating the - * user-space origin by (@tx, @ty). This offset is interpreted as a - * user-space coordinate according to the CTM in place before the new - * call to cairo_translate(). In other words, the translation of the - * user-space origin takes place after any existing transformation. - * - * Since: 1.0 - **/ -void -cairo_translate (cairo_t *cr, double tx, double ty) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->translate (cr, tx, ty); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_translate); - -/** - * cairo_scale: - * @cr: a cairo context - * @sx: scale factor for the X dimension - * @sy: scale factor for the Y dimension - * - * Modifies the current transformation matrix (CTM) by scaling the X - * and Y user-space axes by @sx and @sy respectively. The scaling of - * the axes takes place after any existing transformation of user - * space. - * - * Since: 1.0 - **/ -void -cairo_scale (cairo_t *cr, double sx, double sy) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->scale (cr, sx, sy); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_scale); - -/** - * cairo_rotate: - * @cr: a cairo context - * @angle: angle (in radians) by which the user-space axes will be - * rotated - * - * Modifies the current transformation matrix (CTM) by rotating the - * user-space axes by @angle radians. The rotation of the axes takes - * places after any existing transformation of user space. The - * rotation direction for positive angles is from the positive X axis - * toward the positive Y axis. - * - * Since: 1.0 - **/ -void -cairo_rotate (cairo_t *cr, double angle) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->rotate (cr, angle); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_transform: - * @cr: a cairo context - * @matrix: a transformation to be applied to the user-space axes - * - * Modifies the current transformation matrix (CTM) by applying - * @matrix as an additional transformation. The new transformation of - * user space takes place after any existing transformation. - * - * Since: 1.0 - **/ -void -cairo_transform (cairo_t *cr, - const cairo_matrix_t *matrix) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->transform (cr, matrix); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_transform); - -/** - * cairo_set_matrix: - * @cr: a cairo context - * @matrix: a transformation matrix from user space to device space - * - * Modifies the current transformation matrix (CTM) by setting it - * equal to @matrix. - * - * Since: 1.0 - **/ -void -cairo_set_matrix (cairo_t *cr, - const cairo_matrix_t *matrix) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_matrix (cr, matrix); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_matrix); - -/** - * cairo_identity_matrix: - * @cr: a cairo context - * - * Resets the current transformation matrix (CTM) by setting it equal - * to the identity matrix. That is, the user-space and device-space - * axes will be aligned and one user-space unit will transform to one - * device-space unit. - * - * Since: 1.0 - **/ -void -cairo_identity_matrix (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_identity_matrix (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_user_to_device: - * @cr: a cairo context - * @x: X value of coordinate (in/out parameter) - * @y: Y value of coordinate (in/out parameter) - * - * Transform a coordinate from user space to device space by - * multiplying the given point by the current transformation matrix - * (CTM). - * - * Since: 1.0 - **/ -void -cairo_user_to_device (cairo_t *cr, double *x, double *y) -{ - if (unlikely (cr->status)) - return; - - cr->backend->user_to_device (cr, x, y); -} -slim_hidden_def (cairo_user_to_device); - -/** - * cairo_user_to_device_distance: - * @cr: a cairo context - * @dx: X component of a distance vector (in/out parameter) - * @dy: Y component of a distance vector (in/out parameter) - * - * Transform a distance vector from user space to device space. This - * function is similar to cairo_user_to_device() except that the - * translation components of the CTM will be ignored when transforming - * (@dx,@dy). - * - * Since: 1.0 - **/ -void -cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy) -{ - if (unlikely (cr->status)) - return; - - cr->backend->user_to_device_distance (cr, dx, dy); -} -slim_hidden_def (cairo_user_to_device_distance); - -/** - * cairo_device_to_user: - * @cr: a cairo - * @x: X value of coordinate (in/out parameter) - * @y: Y value of coordinate (in/out parameter) - * - * Transform a coordinate from device space to user space by - * multiplying the given point by the inverse of the current - * transformation matrix (CTM). - * - * Since: 1.0 - **/ -void -cairo_device_to_user (cairo_t *cr, double *x, double *y) -{ - if (unlikely (cr->status)) - return; - - cr->backend->device_to_user (cr, x, y); -} -slim_hidden_def (cairo_device_to_user); - -/** - * cairo_device_to_user_distance: - * @cr: a cairo context - * @dx: X component of a distance vector (in/out parameter) - * @dy: Y component of a distance vector (in/out parameter) - * - * Transform a distance vector from device space to user space. This - * function is similar to cairo_device_to_user() except that the - * translation components of the inverse CTM will be ignored when - * transforming (@dx,@dy). - * - * Since: 1.0 - **/ -void -cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy) -{ - if (unlikely (cr->status)) - return; - - cr->backend->device_to_user_distance (cr, dx, dy); -} - -/** - * cairo_new_path: - * @cr: a cairo context - * - * Clears the current path. After this call there will be no path and - * no current point. - * - * Since: 1.0 - **/ -void -cairo_new_path (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->new_path (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_new_path); - -/** - * cairo_new_sub_path: - * @cr: a cairo context - * - * Begin a new sub-path. Note that the existing path is not - * affected. After this call there will be no current point. - * - * In many cases, this call is not needed since new sub-paths are - * frequently started with cairo_move_to(). - * - * A call to cairo_new_sub_path() is particularly useful when - * beginning a new sub-path with one of the cairo_arc() calls. This - * makes things easier as it is no longer necessary to manually - * compute the arc's initial coordinates for a call to - * cairo_move_to(). - * - * Since: 1.2 - **/ -void -cairo_new_sub_path (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->new_sub_path (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_move_to: - * @cr: a cairo context - * @x: the X coordinate of the new position - * @y: the Y coordinate of the new position - * - * Begin a new sub-path. After this call the current point will be (@x, - * @y). - * - * Since: 1.0 - **/ -void -cairo_move_to (cairo_t *cr, double x, double y) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->move_to (cr, x, y); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_move_to); - - -/** - * cairo_line_to: - * @cr: a cairo context - * @x: the X coordinate of the end of the new line - * @y: the Y coordinate of the end of the new line - * - * Adds a line to the path from the current point to position (@x, @y) - * in user-space coordinates. After this call the current point - * will be (@x, @y). - * - * If there is no current point before the call to cairo_line_to() - * this function will behave as cairo_move_to(@cr, @x, @y). - * - * Since: 1.0 - **/ -void -cairo_line_to (cairo_t *cr, double x, double y) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->line_to (cr, x, y); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_line_to); - -/** - * cairo_curve_to: - * @cr: a cairo context - * @x1: the X coordinate of the first control point - * @y1: the Y coordinate of the first control point - * @x2: the X coordinate of the second control point - * @y2: the Y coordinate of the second control point - * @x3: the X coordinate of the end of the curve - * @y3: the Y coordinate of the end of the curve - * - * Adds a cubic Bézier spline to the path from the current point to - * position (@x3, @y3) in user-space coordinates, using (@x1, @y1) and - * (@x2, @y2) as the control points. After this call the current point - * will be (@x3, @y3). - * - * If there is no current point before the call to cairo_curve_to() - * this function will behave as if preceded by a call to - * cairo_move_to(@cr, @x1, @y1). - * - * Since: 1.0 - **/ -void -cairo_curve_to (cairo_t *cr, - double x1, double y1, - double x2, double y2, - double x3, double y3) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->curve_to (cr, - x1, y1, - x2, y2, - x3, y3); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_curve_to); - -/** - * cairo_arc: - * @cr: a cairo context - * @xc: X position of the center of the arc - * @yc: Y position of the center of the arc - * @radius: the radius of the arc - * @angle1: the start angle, in radians - * @angle2: the end angle, in radians - * - * Adds a circular arc of the given @radius to the current path. The - * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in - * the direction of increasing angles to end at @angle2. If @angle2 is - * less than @angle1 it will be progressively increased by - * 2*M_PI until it is greater than @angle1. - * - * If there is a current point, an initial line segment will be added - * to the path to connect the current point to the beginning of the - * arc. If this initial line is undesired, it can be avoided by - * calling cairo_new_sub_path() before calling cairo_arc(). - * - * Angles are measured in radians. An angle of 0.0 is in the direction - * of the positive X axis (in user space). An angle of - * M_PI/2.0 radians (90 degrees) is in the - * direction of the positive Y axis (in user space). Angles increase - * in the direction from the positive X axis toward the positive Y - * axis. So with the default transformation matrix, angles increase in - * a clockwise direction. - * - * (To convert from degrees to radians, use degrees * (M_PI / - * 180.).) - * - * This function gives the arc in the direction of increasing angles; - * see cairo_arc_negative() to get the arc in the direction of - * decreasing angles. - * - * The arc is circular in user space. To achieve an elliptical arc, - * you can scale the current transformation matrix by different - * amounts in the X and Y directions. For example, to draw an ellipse - * in the box given by @x, @y, @width, @height: - * - * - * cairo_save (cr); - * cairo_translate (cr, x + width / 2., y + height / 2.); - * cairo_scale (cr, width / 2., height / 2.); - * cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI); - * cairo_restore (cr); - * - * - * Since: 1.0 - **/ -void -cairo_arc (cairo_t *cr, - double xc, double yc, - double radius, - double angle1, double angle2) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (angle2 < angle1) { - /* increase angle2 by multiples of full circle until it - * satisfies angle2 >= angle1 */ - angle2 = fmod (angle2 - angle1, 2 * M_PI); - if (angle2 < 0) - angle2 += 2 * M_PI; - angle2 += angle1; - } - - status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, TRUE); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_arc_negative: - * @cr: a cairo context - * @xc: X position of the center of the arc - * @yc: Y position of the center of the arc - * @radius: the radius of the arc - * @angle1: the start angle, in radians - * @angle2: the end angle, in radians - * - * Adds a circular arc of the given @radius to the current path. The - * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in - * the direction of decreasing angles to end at @angle2. If @angle2 is - * greater than @angle1 it will be progressively decreased by - * 2*M_PI until it is less than @angle1. - * - * See cairo_arc() for more details. This function differs only in the - * direction of the arc between the two angles. - * - * Since: 1.0 - **/ -void -cairo_arc_negative (cairo_t *cr, - double xc, double yc, - double radius, - double angle1, double angle2) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (angle2 > angle1) { - /* decrease angle2 by multiples of full circle until it - * satisfies angle2 <= angle1 */ - angle2 = fmod (angle2 - angle1, 2 * M_PI); - if (angle2 > 0) - angle2 -= 2 * M_PI; - angle2 += angle1; - } - - status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, FALSE); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/* XXX: NYI -void -cairo_arc_to (cairo_t *cr, - double x1, double y1, - double x2, double y2, - double radius) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->arc_to (cr, x1, y1, x2, y2, radius); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -void -cairo_rel_arc_to (cairo_t *cr, - double dx1, double dy1, - double dx2, double dy2, - double radius) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->rel_arc_to (cr, dx1, dy1, dx2, dy2, radius); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -*/ - -/** - * cairo_rel_move_to: - * @cr: a cairo context - * @dx: the X offset - * @dy: the Y offset - * - * Begin a new sub-path. After this call the current point will offset - * by (@x, @y). - * - * Given a current point of (x, y), cairo_rel_move_to(@cr, @dx, @dy) - * is logically equivalent to cairo_move_to(@cr, x + @dx, y + @dy). - * - * It is an error to call this function with no current point. Doing - * so will cause @cr to shutdown with a status of - * %CAIRO_STATUS_NO_CURRENT_POINT. - * - * Since: 1.0 - **/ -void -cairo_rel_move_to (cairo_t *cr, double dx, double dy) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->rel_move_to (cr, dx, dy); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_rel_line_to: - * @cr: a cairo context - * @dx: the X offset to the end of the new line - * @dy: the Y offset to the end of the new line - * - * Relative-coordinate version of cairo_line_to(). Adds a line to the - * path from the current point to a point that is offset from the - * current point by (@dx, @dy) in user space. After this call the - * current point will be offset by (@dx, @dy). - * - * Given a current point of (x, y), cairo_rel_line_to(@cr, @dx, @dy) - * is logically equivalent to cairo_line_to(@cr, x + @dx, y + @dy). - * - * It is an error to call this function with no current point. Doing - * so will cause @cr to shutdown with a status of - * %CAIRO_STATUS_NO_CURRENT_POINT. - * - * Since: 1.0 - **/ -void -cairo_rel_line_to (cairo_t *cr, double dx, double dy) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->rel_line_to (cr, dx, dy); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_rel_line_to); - -/** - * cairo_rel_curve_to: - * @cr: a cairo context - * @dx1: the X offset to the first control point - * @dy1: the Y offset to the first control point - * @dx2: the X offset to the second control point - * @dy2: the Y offset to the second control point - * @dx3: the X offset to the end of the curve - * @dy3: the Y offset to the end of the curve - * - * Relative-coordinate version of cairo_curve_to(). All offsets are - * relative to the current point. Adds a cubic Bézier spline to the - * path from the current point to a point offset from the current - * point by (@dx3, @dy3), using points offset by (@dx1, @dy1) and - * (@dx2, @dy2) as the control points. After this call the current - * point will be offset by (@dx3, @dy3). - * - * Given a current point of (x, y), cairo_rel_curve_to(@cr, @dx1, - * @dy1, @dx2, @dy2, @dx3, @dy3) is logically equivalent to - * cairo_curve_to(@cr, x+@dx1, y+@dy1, x+@dx2, y+@dy2, x+@dx3, y+@dy3). - * - * It is an error to call this function with no current point. Doing - * so will cause @cr to shutdown with a status of - * %CAIRO_STATUS_NO_CURRENT_POINT. - * - * Since: 1.0 - **/ -void -cairo_rel_curve_to (cairo_t *cr, - double dx1, double dy1, - double dx2, double dy2, - double dx3, double dy3) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->rel_curve_to (cr, - dx1, dy1, - dx2, dy2, - dx3, dy3); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_rectangle: - * @cr: a cairo context - * @x: the X coordinate of the top left corner of the rectangle - * @y: the Y coordinate to the top left corner of the rectangle - * @width: the width of the rectangle - * @height: the height of the rectangle - * - * Adds a closed sub-path rectangle of the given size to the current - * path at position (@x, @y) in user-space coordinates. - * - * This function is logically equivalent to: - * - * cairo_move_to (cr, x, y); - * cairo_rel_line_to (cr, width, 0); - * cairo_rel_line_to (cr, 0, height); - * cairo_rel_line_to (cr, -width, 0); - * cairo_close_path (cr); - * - * - * Since: 1.0 - **/ -void -cairo_rectangle (cairo_t *cr, - double x, double y, - double width, double height) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->rectangle (cr, x, y, width, height); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -#if 0 -/* XXX: NYI */ -void -cairo_stroke_to_path (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - /* The code in _cairo_recording_surface_get_path has a poorman's stroke_to_path */ - - status = _cairo_gstate_stroke_path (cr->gstate); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -#endif - -/** - * cairo_close_path: - * @cr: a cairo context - * - * Adds a line segment to the path from the current point to the - * beginning of the current sub-path, (the most recent point passed to - * cairo_move_to()), and closes this sub-path. After this call the - * current point will be at the joined endpoint of the sub-path. - * - * The behavior of cairo_close_path() is distinct from simply calling - * cairo_line_to() with the equivalent coordinate in the case of - * stroking. When a closed sub-path is stroked, there are no caps on - * the ends of the sub-path. Instead, there is a line join connecting - * the final and initial segments of the sub-path. - * - * If there is no current point before the call to cairo_close_path(), - * this function will have no effect. - * - * Note: As of cairo version 1.2.4 any call to cairo_close_path() will - * place an explicit MOVE_TO element into the path immediately after - * the CLOSE_PATH element, (which can be seen in cairo_copy_path() for - * example). This can simplify path processing in some cases as it may - * not be necessary to save the "last move_to point" during processing - * as the MOVE_TO immediately after the CLOSE_PATH will provide that - * point. - * - * Since: 1.0 - **/ -void -cairo_close_path (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->close_path (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_close_path); - -/** - * cairo_path_extents: - * @cr: a cairo context - * @x1: left of the resulting extents - * @y1: top of the resulting extents - * @x2: right of the resulting extents - * @y2: bottom of the resulting extents - * - * Computes a bounding box in user-space coordinates covering the - * points on the current path. If the current path is empty, returns - * an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule, - * surface dimensions and clipping are not taken into account. - * - * Contrast with cairo_fill_extents() and cairo_stroke_extents() which - * return the extents of only the area that would be "inked" by - * the corresponding drawing operations. - * - * The result of cairo_path_extents() is defined as equivalent to the - * limit of cairo_stroke_extents() with %CAIRO_LINE_CAP_ROUND as the - * line width approaches 0.0, (but never reaching the empty-rectangle - * returned by cairo_stroke_extents() for a line width of 0.0). - * - * Specifically, this means that zero-area sub-paths such as - * cairo_move_to();cairo_line_to() segments, (even degenerate cases - * where the coordinates to both calls are identical), will be - * considered as contributing to the extents. However, a lone - * cairo_move_to() will not contribute to the results of - * cairo_path_extents(). - * - * Since: 1.6 - **/ -void -cairo_path_extents (cairo_t *cr, - double *x1, double *y1, double *x2, double *y2) -{ - if (unlikely (cr->status)) { - if (x1) - *x1 = 0.0; - if (y1) - *y1 = 0.0; - if (x2) - *x2 = 0.0; - if (y2) - *y2 = 0.0; - - return; - } - - cr->backend->path_extents (cr, x1, y1, x2, y2); -} - -/** - * cairo_paint: - * @cr: a cairo context - * - * A drawing operator that paints the current source everywhere within - * the current clip region. - * - * Since: 1.0 - **/ -void -cairo_paint (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->paint (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_paint); - -/** - * cairo_paint_with_alpha: - * @cr: a cairo context - * @alpha: alpha value, between 0 (transparent) and 1 (opaque) - * - * A drawing operator that paints the current source everywhere within - * the current clip region using a mask of constant alpha value - * @alpha. The effect is similar to cairo_paint(), but the drawing - * is faded out using the alpha value. - * - * Since: 1.0 - **/ -void -cairo_paint_with_alpha (cairo_t *cr, - double alpha) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->paint_with_alpha (cr, alpha); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_mask: - * @cr: a cairo context - * @pattern: a #cairo_pattern_t - * - * A drawing operator that paints the current source - * using the alpha channel of @pattern as a mask. (Opaque - * areas of @pattern are painted with the source, transparent - * areas are not painted.) - * - * Since: 1.0 - **/ -void -cairo_mask (cairo_t *cr, - cairo_pattern_t *pattern) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (unlikely (pattern == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - if (unlikely (pattern->status)) { - _cairo_set_error (cr, pattern->status); - return; - } - - status = cr->backend->mask (cr, pattern); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_mask); - -/** - * cairo_mask_surface: - * @cr: a cairo context - * @surface: a #cairo_surface_t - * @surface_x: X coordinate at which to place the origin of @surface - * @surface_y: Y coordinate at which to place the origin of @surface - * - * A drawing operator that paints the current source - * using the alpha channel of @surface as a mask. (Opaque - * areas of @surface are painted with the source, transparent - * areas are not painted.) - * - * Since: 1.0 - **/ -void -cairo_mask_surface (cairo_t *cr, - cairo_surface_t *surface, - double surface_x, - double surface_y) -{ - cairo_pattern_t *pattern; - cairo_matrix_t matrix; - - if (unlikely (cr->status)) - return; - - pattern = cairo_pattern_create_for_surface (surface); - - cairo_matrix_init_translate (&matrix, - surface_x, - surface_y); - cairo_pattern_set_matrix (pattern, &matrix); - - cairo_mask (cr, pattern); - - cairo_pattern_destroy (pattern); -} - -/** - * cairo_stroke: - * @cr: a cairo context - * - * A drawing operator that strokes the current path according to the - * current line width, line join, line cap, and dash settings. After - * cairo_stroke(), the current path will be cleared from the cairo - * context. See cairo_set_line_width(), cairo_set_line_join(), - * cairo_set_line_cap(), cairo_set_dash(), and - * cairo_stroke_preserve(). - * - * Note: Degenerate segments and sub-paths are treated specially and - * provide a useful result. These can result in two different - * situations: - * - * 1. Zero-length "on" segments set in cairo_set_dash(). If the cap - * style is %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE then these - * segments will be drawn as circular dots or squares respectively. In - * the case of %CAIRO_LINE_CAP_SQUARE, the orientation of the squares - * is determined by the direction of the underlying path. - * - * 2. A sub-path created by cairo_move_to() followed by either a - * cairo_close_path() or one or more calls to cairo_line_to() to the - * same coordinate as the cairo_move_to(). If the cap style is - * %CAIRO_LINE_CAP_ROUND then these sub-paths will be drawn as circular - * dots. Note that in the case of %CAIRO_LINE_CAP_SQUARE a degenerate - * sub-path will not be drawn at all, (since the correct orientation - * is indeterminate). - * - * In no case will a cap style of %CAIRO_LINE_CAP_BUTT cause anything - * to be drawn in the case of either degenerate segments or sub-paths. - * - * Since: 1.0 - **/ -void -cairo_stroke (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->stroke (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_stroke); - -/** - * cairo_stroke_preserve: - * @cr: a cairo context - * - * A drawing operator that strokes the current path according to the - * current line width, line join, line cap, and dash settings. Unlike - * cairo_stroke(), cairo_stroke_preserve() preserves the path within the - * cairo context. - * - * See cairo_set_line_width(), cairo_set_line_join(), - * cairo_set_line_cap(), cairo_set_dash(), and - * cairo_stroke_preserve(). - * - * Since: 1.0 - **/ -void -cairo_stroke_preserve (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->stroke_preserve (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_stroke_preserve); - -/** - * cairo_fill: - * @cr: a cairo context - * - * A drawing operator that fills the current path according to the - * current fill rule, (each sub-path is implicitly closed before being - * filled). After cairo_fill(), the current path will be cleared from - * the cairo context. See cairo_set_fill_rule() and - * cairo_fill_preserve(). - * - * Since: 1.0 - **/ -void -cairo_fill (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->fill (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_fill_preserve: - * @cr: a cairo context - * - * A drawing operator that fills the current path according to the - * current fill rule, (each sub-path is implicitly closed before being - * filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the - * path within the cairo context. - * - * See cairo_set_fill_rule() and cairo_fill(). - * - * Since: 1.0 - **/ -void -cairo_fill_preserve (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->fill_preserve (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_fill_preserve); - -/** - * cairo_copy_page: - * @cr: a cairo context - * - * Emits the current page for backends that support multiple pages, but - * doesn't clear it, so, the contents of the current page will be retained - * for the next page too. Use cairo_show_page() if you want to get an - * empty page after the emission. - * - * This is a convenience function that simply calls - * cairo_surface_copy_page() on @cr's target. - * - * Since: 1.0 - **/ -void -cairo_copy_page (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->copy_page (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_show_page: - * @cr: a cairo context - * - * Emits and clears the current page for backends that support multiple - * pages. Use cairo_copy_page() if you don't want to clear the page. - * - * This is a convenience function that simply calls - * cairo_surface_show_page() on @cr's target. - * - * Since: 1.0 - **/ -void -cairo_show_page (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->show_page (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_in_stroke: - * @cr: a cairo context - * @x: X coordinate of the point to test - * @y: Y coordinate of the point to test - * - * Tests whether the given point is inside the area that would be - * affected by a cairo_stroke() operation given the current path and - * stroking parameters. Surface dimensions and clipping are not taken - * into account. - * - * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(), - * cairo_set_line_cap(), cairo_set_dash(), and - * cairo_stroke_preserve(). - * - * Return value: A non-zero value if the point is inside, or zero if - * outside. - * - * Since: 1.0 - **/ -cairo_bool_t -cairo_in_stroke (cairo_t *cr, double x, double y) -{ - cairo_status_t status; - cairo_bool_t inside = FALSE; - - if (unlikely (cr->status)) - return FALSE; - - status = cr->backend->in_stroke (cr, x, y, &inside); - if (unlikely (status)) - _cairo_set_error (cr, status); - - return inside; -} - -/** - * cairo_in_fill: - * @cr: a cairo context - * @x: X coordinate of the point to test - * @y: Y coordinate of the point to test - * - * Tests whether the given point is inside the area that would be - * affected by a cairo_fill() operation given the current path and - * filling parameters. Surface dimensions and clipping are not taken - * into account. - * - * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve(). - * - * Return value: A non-zero value if the point is inside, or zero if - * outside. - * - * Since: 1.0 - **/ -cairo_bool_t -cairo_in_fill (cairo_t *cr, double x, double y) -{ - cairo_status_t status; - cairo_bool_t inside = FALSE; - - if (unlikely (cr->status)) - return FALSE; - - status = cr->backend->in_fill (cr, x, y, &inside); - if (unlikely (status)) - _cairo_set_error (cr, status); - - return inside; -} - -/** - * cairo_stroke_extents: - * @cr: a cairo context - * @x1: left of the resulting extents - * @y1: top of the resulting extents - * @x2: right of the resulting extents - * @y2: bottom of the resulting extents - * - * Computes a bounding box in user coordinates covering the area that - * would be affected, (the "inked" area), by a cairo_stroke() - * operation given the current path and stroke parameters. - * If the current path is empty, returns an empty rectangle ((0,0), (0,0)). - * Surface dimensions and clipping are not taken into account. - * - * Note that if the line width is set to exactly zero, then - * cairo_stroke_extents() will return an empty rectangle. Contrast with - * cairo_path_extents() which can be used to compute the non-empty - * bounds as the line width approaches zero. - * - * Note that cairo_stroke_extents() must necessarily do more work to - * compute the precise inked areas in light of the stroke parameters, - * so cairo_path_extents() may be more desirable for sake of - * performance if non-inked path extents are desired. - * - * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(), - * cairo_set_line_cap(), cairo_set_dash(), and - * cairo_stroke_preserve(). - * - * Since: 1.0 - **/ -void -cairo_stroke_extents (cairo_t *cr, - double *x1, double *y1, double *x2, double *y2) -{ - cairo_status_t status; - - if (unlikely (cr->status)) { - if (x1) - *x1 = 0.0; - if (y1) - *y1 = 0.0; - if (x2) - *x2 = 0.0; - if (y2) - *y2 = 0.0; - - return; - } - - status = cr->backend->stroke_extents (cr, x1, y1, x2, y2); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_fill_extents: - * @cr: a cairo context - * @x1: left of the resulting extents - * @y1: top of the resulting extents - * @x2: right of the resulting extents - * @y2: bottom of the resulting extents - * - * Computes a bounding box in user coordinates covering the area that - * would be affected, (the "inked" area), by a cairo_fill() operation - * given the current path and fill parameters. If the current path is - * empty, returns an empty rectangle ((0,0), (0,0)). Surface - * dimensions and clipping are not taken into account. - * - * Contrast with cairo_path_extents(), which is similar, but returns - * non-zero extents for some paths with no inked area, (such as a - * simple line segment). - * - * Note that cairo_fill_extents() must necessarily do more work to - * compute the precise inked areas in light of the fill rule, so - * cairo_path_extents() may be more desirable for sake of performance - * if the non-inked path extents are desired. - * - * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve(). - * - * Since: 1.0 - **/ -void -cairo_fill_extents (cairo_t *cr, - double *x1, double *y1, double *x2, double *y2) -{ - cairo_status_t status; - - if (unlikely (cr->status)) { - if (x1) - *x1 = 0.0; - if (y1) - *y1 = 0.0; - if (x2) - *x2 = 0.0; - if (y2) - *y2 = 0.0; - - return; - } - - status = cr->backend->fill_extents (cr, x1, y1, x2, y2); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_clip: - * @cr: a cairo context - * - * Establishes a new clip region by intersecting the current clip - * region with the current path as it would be filled by cairo_fill() - * and according to the current fill rule (see cairo_set_fill_rule()). - * - * After cairo_clip(), the current path will be cleared from the cairo - * context. - * - * The current clip region affects all drawing operations by - * effectively masking out any changes to the surface that are outside - * the current clip region. - * - * Calling cairo_clip() can only make the clip region smaller, never - * larger. But the current clip is part of the graphics state, so a - * temporary restriction of the clip region can be achieved by - * calling cairo_clip() within a cairo_save()/cairo_restore() - * pair. The only other means of increasing the size of the clip - * region is cairo_reset_clip(). - * - * Since: 1.0 - **/ -void -cairo_clip (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->clip (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_clip_preserve: - * @cr: a cairo context - * - * Establishes a new clip region by intersecting the current clip - * region with the current path as it would be filled by cairo_fill() - * and according to the current fill rule (see cairo_set_fill_rule()). - * - * Unlike cairo_clip(), cairo_clip_preserve() preserves the path within - * the cairo context. - * - * The current clip region affects all drawing operations by - * effectively masking out any changes to the surface that are outside - * the current clip region. - * - * Calling cairo_clip_preserve() can only make the clip region smaller, never - * larger. But the current clip is part of the graphics state, so a - * temporary restriction of the clip region can be achieved by - * calling cairo_clip_preserve() within a cairo_save()/cairo_restore() - * pair. The only other means of increasing the size of the clip - * region is cairo_reset_clip(). - * - * Since: 1.0 - **/ -void -cairo_clip_preserve (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->clip_preserve (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def(cairo_clip_preserve); - -/** - * cairo_reset_clip: - * @cr: a cairo context - * - * Reset the current clip region to its original, unrestricted - * state. That is, set the clip region to an infinitely large shape - * containing the target surface. Equivalently, if infinity is too - * hard to grasp, one can imagine the clip region being reset to the - * exact bounds of the target surface. - * - * Note that code meant to be reusable should not call - * cairo_reset_clip() as it will cause results unexpected by - * higher-level code which calls cairo_clip(). Consider using - * cairo_save() and cairo_restore() around cairo_clip() as a more - * robust means of temporarily restricting the clip region. - * - * Since: 1.0 - **/ -void -cairo_reset_clip (cairo_t *cr) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->reset_clip (cr); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_clip_extents: - * @cr: a cairo context - * @x1: left of the resulting extents - * @y1: top of the resulting extents - * @x2: right of the resulting extents - * @y2: bottom of the resulting extents - * - * Computes a bounding box in user coordinates covering the area inside the - * current clip. - * - * Since: 1.4 - **/ -void -cairo_clip_extents (cairo_t *cr, - double *x1, double *y1, - double *x2, double *y2) -{ - cairo_status_t status; - - if (x1) - *x1 = 0.0; - if (y1) - *y1 = 0.0; - if (x2) - *x2 = 0.0; - if (y2) - *y2 = 0.0; - - if (unlikely (cr->status)) - return; - - status = cr->backend->clip_extents (cr, x1, y1, x2, y2); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_in_clip: - * @cr: a cairo context - * @x: X coordinate of the point to test - * @y: Y coordinate of the point to test - * - * Tests whether the given point is inside the area that would be - * visible through the current clip, i.e. the area that would be filled by - * a cairo_paint() operation. - * - * See cairo_clip(), and cairo_clip_preserve(). - * - * Return value: A non-zero value if the point is inside, or zero if - * outside. - * - * Since: 1.10 - **/ -cairo_bool_t -cairo_in_clip (cairo_t *cr, double x, double y) -{ - cairo_status_t status; - cairo_bool_t inside = FALSE; - - if (unlikely (cr->status)) - return FALSE; - - status = cr->backend->in_clip (cr, x, y, &inside); - if (unlikely (status)) - _cairo_set_error (cr, status); - - return inside; -} - -/** - * cairo_copy_clip_rectangle_list: - * @cr: a cairo context - * - * Gets the current clip region as a list of rectangles in user coordinates. - * Never returns %NULL. - * - * The status in the list may be %CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to - * indicate that the clip region cannot be represented as a list of - * user-space rectangles. The status may have other values to indicate - * other errors. - * - * Returns: the current clip region as a list of rectangles in user coordinates, - * which should be destroyed using cairo_rectangle_list_destroy(). - * - * Since: 1.4 - **/ -cairo_rectangle_list_t * -cairo_copy_clip_rectangle_list (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_rectangle_list_create_in_error (cr->status); - - return cr->backend->clip_copy_rectangle_list (cr); -} - -/** - * cairo_select_font_face: - * @cr: a #cairo_t - * @family: a font family name, encoded in UTF-8 - * @slant: the slant for the font - * @weight: the weight for the font - * - * Note: The cairo_select_font_face() function call is part of what - * the cairo designers call the "toy" text API. It is convenient for - * short demos and simple programs, but it is not expected to be - * adequate for serious text-using applications. - * - * Selects a family and style of font from a simplified description as - * a family name, slant and weight. Cairo provides no operation to - * list available family names on the system (this is a "toy", - * remember), but the standard CSS2 generic family names, ("serif", - * "sans-serif", "cursive", "fantasy", "monospace"), are likely to - * work as expected. - * - * If @family starts with the string "@cairo:", or if no native font - * backends are compiled in, cairo will use an internal font family. - * The internal font family recognizes many modifiers in the @family - * string, most notably, it recognizes the string "monospace". That is, - * the family name "@cairo:monospace" will use the monospace version of - * the internal font family. - * - * For "real" font selection, see the font-backend-specific - * font_face_create functions for the font backend you are using. (For - * example, if you are using the freetype-based cairo-ft font backend, - * see cairo_ft_font_face_create_for_ft_face() or - * cairo_ft_font_face_create_for_pattern().) The resulting font face - * could then be used with cairo_scaled_font_create() and - * cairo_set_scaled_font(). - * - * Similarly, when using the "real" font support, you can call - * directly into the underlying font system, (such as fontconfig or - * freetype), for operations such as listing available fonts, etc. - * - * It is expected that most applications will need to use a more - * comprehensive font handling and text layout library, (for example, - * pango), in conjunction with cairo. - * - * If text is drawn without a call to cairo_select_font_face(), (nor - * cairo_set_font_face() nor cairo_set_scaled_font()), the default - * family is platform-specific, but is essentially "sans-serif". - * Default slant is %CAIRO_FONT_SLANT_NORMAL, and default weight is - * %CAIRO_FONT_WEIGHT_NORMAL. - * - * This function is equivalent to a call to cairo_toy_font_face_create() - * followed by cairo_set_font_face(). - * - * Since: 1.0 - **/ -void -cairo_select_font_face (cairo_t *cr, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) -{ - cairo_font_face_t *font_face; - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - font_face = cairo_toy_font_face_create (family, slant, weight); - if (unlikely (font_face->status)) { - _cairo_set_error (cr, font_face->status); - return; - } - - status = cr->backend->set_font_face (cr, font_face); - cairo_font_face_destroy (font_face); - - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_font_extents: - * @cr: a #cairo_t - * @extents: a #cairo_font_extents_t object into which the results - * will be stored. - * - * Gets the font extents for the currently selected font. - * - * Since: 1.0 - **/ -void -cairo_font_extents (cairo_t *cr, - cairo_font_extents_t *extents) -{ - cairo_status_t status; - - extents->ascent = 0.0; - extents->descent = 0.0; - extents->height = 0.0; - extents->max_x_advance = 0.0; - extents->max_y_advance = 0.0; - - if (unlikely (cr->status)) - return; - - status = cr->backend->font_extents (cr, extents); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_set_font_face: - * @cr: a #cairo_t - * @font_face: a #cairo_font_face_t, or %NULL to restore to the default font - * - * Replaces the current #cairo_font_face_t object in the #cairo_t with - * @font_face. The replaced font face in the #cairo_t will be - * destroyed if there are no other references to it. - * - * Since: 1.0 - **/ -void -cairo_set_font_face (cairo_t *cr, - cairo_font_face_t *font_face) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_font_face (cr, font_face); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_get_font_face: - * @cr: a #cairo_t - * - * Gets the current font face for a #cairo_t. - * - * Return value: the current font face. This object is owned by - * cairo. To keep a reference to it, you must call - * cairo_font_face_reference(). - * - * This function never returns %NULL. If memory cannot be allocated, a - * special "nil" #cairo_font_face_t object will be returned on which - * cairo_font_face_status() returns %CAIRO_STATUS_NO_MEMORY. Using - * this nil object will cause its error state to propagate to other - * objects it is passed to, (for example, calling - * cairo_set_font_face() with a nil font will trigger an error that - * will shutdown the #cairo_t object). - * - * Since: 1.0 - **/ -cairo_font_face_t * -cairo_get_font_face (cairo_t *cr) -{ - if (unlikely (cr->status)) - return (cairo_font_face_t*) &_cairo_font_face_nil; - - return cr->backend->get_font_face (cr); -} - -/** - * cairo_set_font_size: - * @cr: a #cairo_t - * @size: the new font size, in user space units - * - * Sets the current font matrix to a scale by a factor of @size, replacing - * any font matrix previously set with cairo_set_font_size() or - * cairo_set_font_matrix(). This results in a font size of @size user space - * units. (More precisely, this matrix will result in the font's - * em-square being a @size by @size square in user space.) - * - * If text is drawn without a call to cairo_set_font_size(), (nor - * cairo_set_font_matrix() nor cairo_set_scaled_font()), the default - * font size is 10.0. - * - * Since: 1.0 - **/ -void -cairo_set_font_size (cairo_t *cr, double size) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_font_size (cr, size); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_font_size); - -/** - * cairo_set_font_matrix: - * @cr: a #cairo_t - * @matrix: a #cairo_matrix_t describing a transform to be applied to - * the current font. - * - * Sets the current font matrix to @matrix. The font matrix gives a - * transformation from the design space of the font (in this space, - * the em-square is 1 unit by 1 unit) to user space. Normally, a - * simple scale is used (see cairo_set_font_size()), but a more - * complex font matrix can be used to shear the font - * or stretch it unequally along the two axes - * - * Since: 1.0 - **/ -void -cairo_set_font_matrix (cairo_t *cr, - const cairo_matrix_t *matrix) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cr->backend->set_font_matrix (cr, matrix); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_font_matrix); - -/** - * cairo_get_font_matrix: - * @cr: a #cairo_t - * @matrix: return value for the matrix - * - * Stores the current font matrix into @matrix. See - * cairo_set_font_matrix(). - * - * Since: 1.0 - **/ -void -cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix) -{ - if (unlikely (cr->status)) { - cairo_matrix_init_identity (matrix); - return; - } - - cr->backend->get_font_matrix (cr, matrix); -} - -/** - * cairo_set_font_options: - * @cr: a #cairo_t - * @options: font options to use - * - * Sets a set of custom font rendering options for the #cairo_t. - * Rendering options are derived by merging these options with the - * options derived from underlying surface; if the value in @options - * has a default value (like %CAIRO_ANTIALIAS_DEFAULT), then the value - * from the surface is used. - * - * Since: 1.0 - **/ -void -cairo_set_font_options (cairo_t *cr, - const cairo_font_options_t *options) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - status = cairo_font_options_status ((cairo_font_options_t *) options); - if (unlikely (status)) { - _cairo_set_error (cr, status); - return; - } - - status = cr->backend->set_font_options (cr, options); - if (unlikely (status)) - _cairo_set_error (cr, status); -} -slim_hidden_def (cairo_set_font_options); - -/** - * cairo_get_font_options: - * @cr: a #cairo_t - * @options: a #cairo_font_options_t object into which to store - * the retrieved options. All existing values are overwritten - * - * Retrieves font rendering options set via #cairo_set_font_options. - * Note that the returned options do not include any options derived - * from the underlying surface; they are literally the options - * passed to cairo_set_font_options(). - * - * Since: 1.0 - **/ -void -cairo_get_font_options (cairo_t *cr, - cairo_font_options_t *options) -{ - /* check that we aren't trying to overwrite the nil object */ - if (cairo_font_options_status (options)) - return; - - if (unlikely (cr->status)) { - _cairo_font_options_init_default (options); - return; - } - - cr->backend->get_font_options (cr, options); -} - -/** - * cairo_set_scaled_font: - * @cr: a #cairo_t - * @scaled_font: a #cairo_scaled_font_t - * - * Replaces the current font face, font matrix, and font options in - * the #cairo_t with those of the #cairo_scaled_font_t. Except for - * some translation, the current CTM of the #cairo_t should be the - * same as that of the #cairo_scaled_font_t, which can be accessed - * using cairo_scaled_font_get_ctm(). - * - * Since: 1.2 - **/ -void -cairo_set_scaled_font (cairo_t *cr, - const cairo_scaled_font_t *scaled_font) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if ((scaled_font == NULL)) { - _cairo_set_error (cr, _cairo_error (CAIRO_STATUS_NULL_POINTER)); - return; - } - - status = scaled_font->status; - if (unlikely (status)) { - _cairo_set_error (cr, status); - return; - } - - status = cr->backend->set_scaled_font (cr, (cairo_scaled_font_t *) scaled_font); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_get_scaled_font: - * @cr: a #cairo_t - * - * Gets the current scaled font for a #cairo_t. - * - * Return value: the current scaled font. This object is owned by - * cairo. To keep a reference to it, you must call - * cairo_scaled_font_reference(). - * - * This function never returns %NULL. If memory cannot be allocated, a - * special "nil" #cairo_scaled_font_t object will be returned on which - * cairo_scaled_font_status() returns %CAIRO_STATUS_NO_MEMORY. Using - * this nil object will cause its error state to propagate to other - * objects it is passed to, (for example, calling - * cairo_set_scaled_font() with a nil font will trigger an error that - * will shutdown the #cairo_t object). - * - * Since: 1.4 - **/ -cairo_scaled_font_t * -cairo_get_scaled_font (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_scaled_font_create_in_error (cr->status); - - return cr->backend->get_scaled_font (cr); -} -slim_hidden_def (cairo_get_scaled_font); - -/** - * cairo_text_extents: - * @cr: a #cairo_t - * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL - * @extents: a #cairo_text_extents_t object into which the results - * will be stored - * - * Gets the extents for a string of text. The extents describe a - * user-space rectangle that encloses the "inked" portion of the text, - * (as it would be drawn by cairo_show_text()). Additionally, the - * x_advance and y_advance values indicate the amount by which the - * current point would be advanced by cairo_show_text(). - * - * Note that whitespace characters do not directly contribute to the - * size of the rectangle (extents.width and extents.height). They do - * contribute indirectly by changing the position of non-whitespace - * characters. In particular, trailing whitespace characters are - * likely to not affect the size of the rectangle, though they will - * affect the x_advance and y_advance values. - * - * Since: 1.0 - **/ -void -cairo_text_extents (cairo_t *cr, - const char *utf8, - cairo_text_extents_t *extents) -{ - cairo_status_t status; - cairo_scaled_font_t *scaled_font; - cairo_glyph_t *glyphs = NULL; - int num_glyphs = 0; - double x, y; - - extents->x_bearing = 0.0; - extents->y_bearing = 0.0; - extents->width = 0.0; - extents->height = 0.0; - extents->x_advance = 0.0; - extents->y_advance = 0.0; - - if (unlikely (cr->status)) - return; - - if (utf8 == NULL) - return; - - scaled_font = cairo_get_scaled_font (cr); - if (unlikely (scaled_font->status)) { - _cairo_set_error (cr, scaled_font->status); - return; - } - - cairo_get_current_point (cr, &x, &y); - status = cairo_scaled_font_text_to_glyphs (scaled_font, - x, y, - utf8, -1, - &glyphs, &num_glyphs, - NULL, NULL, NULL); - - if (likely (status == CAIRO_STATUS_SUCCESS)) { - status = cr->backend->glyph_extents (cr, - glyphs, num_glyphs, - extents); - } - cairo_glyph_free (glyphs); - - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_glyph_extents: - * @cr: a #cairo_t - * @glyphs: an array of #cairo_glyph_t objects - * @num_glyphs: the number of elements in @glyphs - * @extents: a #cairo_text_extents_t object into which the results - * will be stored - * - * Gets the extents for an array of glyphs. The extents describe a - * user-space rectangle that encloses the "inked" portion of the - * glyphs, (as they would be drawn by cairo_show_glyphs()). - * Additionally, the x_advance and y_advance values indicate the - * amount by which the current point would be advanced by - * cairo_show_glyphs(). - * - * Note that whitespace glyphs do not contribute to the size of the - * rectangle (extents.width and extents.height). - * - * Since: 1.0 - **/ -void -cairo_glyph_extents (cairo_t *cr, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents) -{ - cairo_status_t status; - - extents->x_bearing = 0.0; - extents->y_bearing = 0.0; - extents->width = 0.0; - extents->height = 0.0; - extents->x_advance = 0.0; - extents->y_advance = 0.0; - - if (unlikely (cr->status)) - return; - - if (num_glyphs == 0) - return; - - if (unlikely (num_glyphs < 0)) { - _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); - return; - } - - if (unlikely (glyphs == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - status = cr->backend->glyph_extents (cr, glyphs, num_glyphs, extents); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_show_text: - * @cr: a cairo context - * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL - * - * A drawing operator that generates the shape from a string of UTF-8 - * characters, rendered according to the current font_face, font_size - * (font_matrix), and font_options. - * - * This function first computes a set of glyphs for the string of - * text. The first glyph is placed so that its origin is at the - * current point. The origin of each subsequent glyph is offset from - * that of the previous glyph by the advance values of the previous - * glyph. - * - * After this call the current point is moved to the origin of where - * the next glyph would be placed in this same progression. That is, - * the current point will be at the origin of the final glyph offset - * by its advance values. This allows for easy display of a single - * logical string with multiple calls to cairo_show_text(). - * - * Note: The cairo_show_text() function call is part of what the cairo - * designers call the "toy" text API. It is convenient for short demos - * and simple programs, but it is not expected to be adequate for - * serious text-using applications. See cairo_show_glyphs() for the - * "real" text display API in cairo. - * - * Since: 1.0 - **/ -void -cairo_show_text (cairo_t *cr, const char *utf8) -{ - cairo_text_extents_t extents; - cairo_status_t status; - cairo_glyph_t *glyphs, *last_glyph; - cairo_text_cluster_t *clusters; - int utf8_len, num_glyphs, num_clusters; - cairo_text_cluster_flags_t cluster_flags; - double x, y; - cairo_bool_t has_show_text_glyphs; - cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; - cairo_text_cluster_t stack_clusters[CAIRO_STACK_ARRAY_LENGTH (cairo_text_cluster_t)]; - cairo_scaled_font_t *scaled_font; - cairo_glyph_text_info_t info, *i; - - if (unlikely (cr->status)) - return; - - if (utf8 == NULL) - return; - - scaled_font = cairo_get_scaled_font (cr); - if (unlikely (scaled_font->status)) { - _cairo_set_error (cr, scaled_font->status); - return; - } - - utf8_len = strlen (utf8); - - has_show_text_glyphs = - cairo_surface_has_show_text_glyphs (cairo_get_target (cr)); - - glyphs = stack_glyphs; - num_glyphs = ARRAY_LENGTH (stack_glyphs); - - if (has_show_text_glyphs) { - clusters = stack_clusters; - num_clusters = ARRAY_LENGTH (stack_clusters); - } else { - clusters = NULL; - num_clusters = 0; - } - - cairo_get_current_point (cr, &x, &y); - status = cairo_scaled_font_text_to_glyphs (scaled_font, - x, y, - utf8, utf8_len, - &glyphs, &num_glyphs, - has_show_text_glyphs ? &clusters : NULL, &num_clusters, - &cluster_flags); - if (unlikely (status)) - goto BAIL; - - if (num_glyphs == 0) - return; - - i = NULL; - if (has_show_text_glyphs) { - info.utf8 = utf8; - info.utf8_len = utf8_len; - info.clusters = clusters; - info.num_clusters = num_clusters; - info.cluster_flags = cluster_flags; - i = &info; - } - - status = cr->backend->glyphs (cr, glyphs, num_glyphs, i); - if (unlikely (status)) - goto BAIL; - - last_glyph = &glyphs[num_glyphs - 1]; - status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents); - if (unlikely (status)) - goto BAIL; - - x = last_glyph->x + extents.x_advance; - y = last_glyph->y + extents.y_advance; - cr->backend->move_to (cr, x, y); - - BAIL: - if (glyphs != stack_glyphs) - cairo_glyph_free (glyphs); - if (clusters != stack_clusters) - cairo_text_cluster_free (clusters); - - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_show_glyphs: - * @cr: a cairo context - * @glyphs: array of glyphs to show - * @num_glyphs: number of glyphs to show - * - * A drawing operator that generates the shape from an array of glyphs, - * rendered according to the current font face, font size - * (font matrix), and font options. - * - * Since: 1.0 - **/ -void -cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (num_glyphs == 0) - return; - - if (num_glyphs < 0) { - _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); - return; - } - - if (glyphs == NULL) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_show_text_glyphs: - * @cr: a cairo context - * @utf8: a string of text encoded in UTF-8 - * @utf8_len: length of @utf8 in bytes, or -1 if it is NUL-terminated - * @glyphs: array of glyphs to show - * @num_glyphs: number of glyphs to show - * @clusters: array of cluster mapping information - * @num_clusters: number of clusters in the mapping - * @cluster_flags: cluster mapping flags - * - * This operation has rendering effects similar to cairo_show_glyphs() - * but, if the target surface supports it, uses the provided text and - * cluster mapping to embed the text for the glyphs shown in the output. - * If the target does not support the extended attributes, this function - * acts like the basic cairo_show_glyphs() as if it had been passed - * @glyphs and @num_glyphs. - * - * The mapping between @utf8 and @glyphs is provided by an array of - * clusters. Each cluster covers a number of - * text bytes and glyphs, and neighboring clusters cover neighboring - * areas of @utf8 and @glyphs. The clusters should collectively cover @utf8 - * and @glyphs in entirety. - * - * The first cluster always covers bytes from the beginning of @utf8. - * If @cluster_flags do not have the %CAIRO_TEXT_CLUSTER_FLAG_BACKWARD - * set, the first cluster also covers the beginning - * of @glyphs, otherwise it covers the end of the @glyphs array and - * following clusters move backward. - * - * See #cairo_text_cluster_t for constraints on valid clusters. - * - * Since: 1.8 - **/ -void -cairo_show_text_glyphs (cairo_t *cr, - const char *utf8, - int utf8_len, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - /* A slew of sanity checks */ - - /* Special case for NULL and -1 */ - if (utf8 == NULL && utf8_len == -1) - utf8_len = 0; - - /* No NULLs for non-zeros */ - if ((num_glyphs && glyphs == NULL) || - (utf8_len && utf8 == NULL) || - (num_clusters && clusters == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - /* A -1 for utf8_len means NUL-terminated */ - if (utf8_len == -1) - utf8_len = strlen (utf8); - - /* Apart from that, no negatives */ - if (num_glyphs < 0 || utf8_len < 0 || num_clusters < 0) { - _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); - return; - } - - if (num_glyphs == 0 && utf8_len == 0) - return; - - if (utf8) { - /* Make sure clusters cover the entire glyphs and utf8 arrays, - * and that cluster boundaries are UTF-8 boundaries. */ - status = _cairo_validate_text_clusters (utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, cluster_flags); - if (status == CAIRO_STATUS_INVALID_CLUSTERS) { - /* Either got invalid UTF-8 text, or cluster mapping is bad. - * Differentiate those. */ - - cairo_status_t status2; - - status2 = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL); - if (status2) - status = status2; - } else { - cairo_glyph_text_info_t info; - - info.utf8 = utf8; - info.utf8_len = utf8_len; - info.clusters = clusters; - info.num_clusters = num_clusters; - info.cluster_flags = cluster_flags; - - status = cr->backend->glyphs (cr, glyphs, num_glyphs, &info); - } - } else { - status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL); - } - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_text_path: - * @cr: a cairo context - * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL - * - * Adds closed paths for text to the current path. The generated - * path if filled, achieves an effect similar to that of - * cairo_show_text(). - * - * Text conversion and positioning is done similar to cairo_show_text(). - * - * Like cairo_show_text(), After this call the current point is - * moved to the origin of where the next glyph would be placed in - * this same progression. That is, the current point will be at - * the origin of the final glyph offset by its advance values. - * This allows for chaining multiple calls to to cairo_text_path() - * without having to set current point in between. - * - * Note: The cairo_text_path() function call is part of what the cairo - * designers call the "toy" text API. It is convenient for short demos - * and simple programs, but it is not expected to be adequate for - * serious text-using applications. See cairo_glyph_path() for the - * "real" text path API in cairo. - * - * Since: 1.0 - **/ -void -cairo_text_path (cairo_t *cr, const char *utf8) -{ - cairo_status_t status; - cairo_text_extents_t extents; - cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; - cairo_glyph_t *glyphs, *last_glyph; - cairo_scaled_font_t *scaled_font; - int num_glyphs; - double x, y; - - if (unlikely (cr->status)) - return; - - if (utf8 == NULL) - return; - - - glyphs = stack_glyphs; - num_glyphs = ARRAY_LENGTH (stack_glyphs); - - scaled_font = cairo_get_scaled_font (cr); - if (unlikely (scaled_font->status)) { - _cairo_set_error (cr, scaled_font->status); - return; - } - - cairo_get_current_point (cr, &x, &y); - status = cairo_scaled_font_text_to_glyphs (scaled_font, - x, y, - utf8, -1, - &glyphs, &num_glyphs, - NULL, NULL, NULL); - - if (num_glyphs == 0) - return; - - status = cr->backend->glyph_path (cr, glyphs, num_glyphs); - - if (unlikely (status)) - goto BAIL; - - last_glyph = &glyphs[num_glyphs - 1]; - status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents); - - if (unlikely (status)) - goto BAIL; - - x = last_glyph->x + extents.x_advance; - y = last_glyph->y + extents.y_advance; - cr->backend->move_to (cr, x, y); - - BAIL: - if (glyphs != stack_glyphs) - cairo_glyph_free (glyphs); - - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_glyph_path: - * @cr: a cairo context - * @glyphs: array of glyphs to show - * @num_glyphs: number of glyphs to show - * - * Adds closed paths for the glyphs to the current path. The generated - * path if filled, achieves an effect similar to that of - * cairo_show_glyphs(). - * - * Since: 1.0 - **/ -void -cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (num_glyphs == 0) - return; - - if (unlikely (num_glyphs < 0)) { - _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); - return; - } - - if (unlikely (glyphs == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - status = cr->backend->glyph_path (cr, glyphs, num_glyphs); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_get_operator: - * @cr: a cairo context - * - * Gets the current compositing operator for a cairo context. - * - * Return value: the current compositing operator. - * - * Since: 1.0 - **/ -cairo_operator_t -cairo_get_operator (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_OPERATOR_DEFAULT; - - return cr->backend->get_operator (cr); -} - -#if 0 -/** - * cairo_get_opacity: - * @cr: a cairo context - * - * Gets the current compositing opacity for a cairo context. - * - * Return value: the current compositing opacity. - * - * Since: TBD - **/ -double -cairo_get_opacity (cairo_t *cr) -{ - if (unlikely (cr->status)) - return 1.; - - return cr->backend->get_opacity (cr); -} -#endif - -/** - * cairo_get_tolerance: - * @cr: a cairo context - * - * Gets the current tolerance value, as set by cairo_set_tolerance(). - * - * Return value: the current tolerance value. - * - * Since: 1.0 - **/ -double -cairo_get_tolerance (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_TOLERANCE_DEFAULT; - - return cr->backend->get_tolerance (cr); -} -slim_hidden_def (cairo_get_tolerance); - -/** - * cairo_get_antialias: - * @cr: a cairo context - * - * Gets the current shape antialiasing mode, as set by - * cairo_set_antialias(). - * - * Return value: the current shape antialiasing mode. - * - * Since: 1.0 - **/ -cairo_antialias_t -cairo_get_antialias (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_ANTIALIAS_DEFAULT; - - return cr->backend->get_antialias (cr); -} - -/** - * cairo_has_current_point: - * @cr: a cairo context - * - * Returns whether a current point is defined on the current path. - * See cairo_get_current_point() for details on the current point. - * - * Return value: whether a current point is defined. - * - * Since: 1.6 - **/ -cairo_bool_t -cairo_has_current_point (cairo_t *cr) -{ - if (unlikely (cr->status)) - return FALSE; - - return cr->backend->has_current_point (cr); -} - -/** - * cairo_get_current_point: - * @cr: a cairo context - * @x: return value for X coordinate of the current point - * @y: return value for Y coordinate of the current point - * - * Gets the current point of the current path, which is - * conceptually the final point reached by the path so far. - * - * The current point is returned in the user-space coordinate - * system. If there is no defined current point or if @cr is in an - * error status, @x and @y will both be set to 0.0. It is possible to - * check this in advance with cairo_has_current_point(). - * - * Most path construction functions alter the current point. See the - * following for details on how they affect the current point: - * cairo_new_path(), cairo_new_sub_path(), - * cairo_append_path(), cairo_close_path(), - * cairo_move_to(), cairo_line_to(), cairo_curve_to(), - * cairo_rel_move_to(), cairo_rel_line_to(), cairo_rel_curve_to(), - * cairo_arc(), cairo_arc_negative(), cairo_rectangle(), - * cairo_text_path(), cairo_glyph_path(), cairo_stroke_to_path(). - * - * Some functions use and alter the current point but do not - * otherwise change current path: - * cairo_show_text(). - * - * Some functions unset the current path and as a result, current point: - * cairo_fill(), cairo_stroke(). - * - * Since: 1.0 - **/ -void -cairo_get_current_point (cairo_t *cr, double *x_ret, double *y_ret) -{ - double x, y; - - x = y = 0; - if (cr->status == CAIRO_STATUS_SUCCESS && - cr->backend->has_current_point (cr)) - { - cr->backend->get_current_point (cr, &x, &y); - } - - if (x_ret) - *x_ret = x; - if (y_ret) - *y_ret = y; -} -slim_hidden_def(cairo_get_current_point); - -/** - * cairo_get_fill_rule: - * @cr: a cairo context - * - * Gets the current fill rule, as set by cairo_set_fill_rule(). - * - * Return value: the current fill rule. - * - * Since: 1.0 - **/ -cairo_fill_rule_t -cairo_get_fill_rule (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_FILL_RULE_DEFAULT; - - return cr->backend->get_fill_rule (cr); -} - -/** - * cairo_get_line_width: - * @cr: a cairo context - * - * This function returns the current line width value exactly as set by - * cairo_set_line_width(). Note that the value is unchanged even if - * the CTM has changed between the calls to cairo_set_line_width() and - * cairo_get_line_width(). - * - * Return value: the current line width. - * - * Since: 1.0 - **/ -double -cairo_get_line_width (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_LINE_WIDTH_DEFAULT; - - return cr->backend->get_line_width (cr); -} -slim_hidden_def (cairo_get_line_width); - -/** - * cairo_get_line_cap: - * @cr: a cairo context - * - * Gets the current line cap style, as set by cairo_set_line_cap(). - * - * Return value: the current line cap style. - * - * Since: 1.0 - **/ -cairo_line_cap_t -cairo_get_line_cap (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_LINE_CAP_DEFAULT; - - return cr->backend->get_line_cap (cr); -} - -/** - * cairo_get_line_join: - * @cr: a cairo context - * - * Gets the current line join style, as set by cairo_set_line_join(). - * - * Return value: the current line join style. - * - * Since: 1.0 - **/ -cairo_line_join_t -cairo_get_line_join (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_LINE_JOIN_DEFAULT; - - return cr->backend->get_line_join (cr); -} - -/** - * cairo_get_miter_limit: - * @cr: a cairo context - * - * Gets the current miter limit, as set by cairo_set_miter_limit(). - * - * Return value: the current miter limit. - * - * Since: 1.0 - **/ -double -cairo_get_miter_limit (cairo_t *cr) -{ - if (unlikely (cr->status)) - return CAIRO_GSTATE_MITER_LIMIT_DEFAULT; - - return cr->backend->get_miter_limit (cr); -} - -/** - * cairo_get_matrix: - * @cr: a cairo context - * @matrix: return value for the matrix - * - * Stores the current transformation matrix (CTM) into @matrix. - * - * Since: 1.0 - **/ -void -cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix) -{ - if (unlikely (cr->status)) { - cairo_matrix_init_identity (matrix); - return; - } - - cr->backend->get_matrix (cr, matrix); -} -slim_hidden_def (cairo_get_matrix); - -/** - * cairo_get_target: - * @cr: a cairo context - * - * Gets the target surface for the cairo context as passed to - * cairo_create(). - * - * This function will always return a valid pointer, but the result - * can be a "nil" surface if @cr is already in an error state, - * (ie. cairo_status() != %CAIRO_STATUS_SUCCESS). - * A nil surface is indicated by cairo_surface_status() - * != %CAIRO_STATUS_SUCCESS. - * - * Return value: the target surface. This object is owned by cairo. To - * keep a reference to it, you must call cairo_surface_reference(). - * - * Since: 1.0 - **/ -cairo_surface_t * -cairo_get_target (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_surface_create_in_error (cr->status); - - return cr->backend->get_original_target (cr); -} -slim_hidden_def (cairo_get_target); - -/** - * cairo_get_group_target: - * @cr: a cairo context - * - * Gets the current destination surface for the context. This is either - * the original target surface as passed to cairo_create() or the target - * surface for the current group as started by the most recent call to - * cairo_push_group() or cairo_push_group_with_content(). - * - * This function will always return a valid pointer, but the result - * can be a "nil" surface if @cr is already in an error state, - * (ie. cairo_status() != %CAIRO_STATUS_SUCCESS). - * A nil surface is indicated by cairo_surface_status() - * != %CAIRO_STATUS_SUCCESS. - * - * Return value: the target surface. This object is owned by cairo. To - * keep a reference to it, you must call cairo_surface_reference(). - * - * Since: 1.2 - **/ -cairo_surface_t * -cairo_get_group_target (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_surface_create_in_error (cr->status); - - return cr->backend->get_current_target (cr); -} - -/** - * cairo_copy_path: - * @cr: a cairo context - * - * Creates a copy of the current path and returns it to the user as a - * #cairo_path_t. See #cairo_path_data_t for hints on how to iterate - * over the returned data structure. - * - * This function will always return a valid pointer, but the result - * will have no data (data==%NULL and - * num_data==0), if either of the following - * conditions hold: - * - * - * If there is insufficient memory to copy the path. In this - * case path->status will be set to - * %CAIRO_STATUS_NO_MEMORY. - * If @cr is already in an error state. In this case - * path->status will contain the same status that - * would be returned by cairo_status(). - * - * - * Return value: the copy of the current path. The caller owns the - * returned object and should call cairo_path_destroy() when finished - * with it. - * - * Since: 1.0 - **/ -cairo_path_t * -cairo_copy_path (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_path_create_in_error (cr->status); - - return cr->backend->copy_path (cr); -} - -/** - * cairo_copy_path_flat: - * @cr: a cairo context - * - * Gets a flattened copy of the current path and returns it to the - * user as a #cairo_path_t. See #cairo_path_data_t for hints on - * how to iterate over the returned data structure. - * - * This function is like cairo_copy_path() except that any curves - * in the path will be approximated with piecewise-linear - * approximations, (accurate to within the current tolerance - * value). That is, the result is guaranteed to not have any elements - * of type %CAIRO_PATH_CURVE_TO which will instead be replaced by a - * series of %CAIRO_PATH_LINE_TO elements. - * - * This function will always return a valid pointer, but the result - * will have no data (data==%NULL and - * num_data==0), if either of the following - * conditions hold: - * - * - * If there is insufficient memory to copy the path. In this - * case path->status will be set to - * %CAIRO_STATUS_NO_MEMORY. - * If @cr is already in an error state. In this case - * path->status will contain the same status that - * would be returned by cairo_status(). - * - * - * Return value: the copy of the current path. The caller owns the - * returned object and should call cairo_path_destroy() when finished - * with it. - * - * Since: 1.0 - **/ -cairo_path_t * -cairo_copy_path_flat (cairo_t *cr) -{ - if (unlikely (cr->status)) - return _cairo_path_create_in_error (cr->status); - - return cr->backend->copy_path_flat (cr); -} - -/** - * cairo_append_path: - * @cr: a cairo context - * @path: path to be appended - * - * Append the @path onto the current path. The @path may be either the - * return value from one of cairo_copy_path() or - * cairo_copy_path_flat() or it may be constructed manually. See - * #cairo_path_t for details on how the path data structure should be - * initialized, and note that path->status must be - * initialized to %CAIRO_STATUS_SUCCESS. - * - * Since: 1.0 - **/ -void -cairo_append_path (cairo_t *cr, - const cairo_path_t *path) -{ - cairo_status_t status; - - if (unlikely (cr->status)) - return; - - if (unlikely (path == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - if (unlikely (path->status)) { - if (path->status > CAIRO_STATUS_SUCCESS && - path->status <= CAIRO_STATUS_LAST_STATUS) - _cairo_set_error (cr, path->status); - else - _cairo_set_error (cr, CAIRO_STATUS_INVALID_STATUS); - return; - } - - if (path->num_data == 0) - return; - - if (unlikely (path->data == NULL)) { - _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); - return; - } - - status = cr->backend->append_path (cr, path); - if (unlikely (status)) - _cairo_set_error (cr, status); -} - -/** - * cairo_status: - * @cr: a cairo context - * - * Checks whether an error has previously occurred for this context. - * - * Returns: the current status of this context, see #cairo_status_t - * - * Since: 1.0 - **/ -cairo_status_t -cairo_status (cairo_t *cr) -{ - return cr->status; -} -slim_hidden_def (cairo_status); diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairo.h deleted file mode 100644 index 3104d47e4c4..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo.h +++ /dev/null @@ -1,3153 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -#ifndef CAIRO_H -#define CAIRO_H - -#include "cairo-version.h" -#include "cairo-features.h" -#include "cairo-deprecated.h" - -#ifdef __cplusplus -# define CAIRO_BEGIN_DECLS extern "C" { -# define CAIRO_END_DECLS } -#else -# define CAIRO_BEGIN_DECLS -# define CAIRO_END_DECLS -#endif - -#ifndef cairo_public -# if defined (_MSC_VER) && ! defined (CAIRO_WIN32_STATIC_BUILD) -# define cairo_public __declspec(dllimport) -# else -# define cairo_public -# endif -#endif - -CAIRO_BEGIN_DECLS - -#define CAIRO_VERSION_ENCODE(major, minor, micro) ( \ - ((major) * 10000) \ - + ((minor) * 100) \ - + ((micro) * 1)) - -#define CAIRO_VERSION CAIRO_VERSION_ENCODE( \ - CAIRO_VERSION_MAJOR, \ - CAIRO_VERSION_MINOR, \ - CAIRO_VERSION_MICRO) - - -#define CAIRO_VERSION_STRINGIZE_(major, minor, micro) \ - #major"."#minor"."#micro -#define CAIRO_VERSION_STRINGIZE(major, minor, micro) \ - CAIRO_VERSION_STRINGIZE_(major, minor, micro) - -#define CAIRO_VERSION_STRING CAIRO_VERSION_STRINGIZE( \ - CAIRO_VERSION_MAJOR, \ - CAIRO_VERSION_MINOR, \ - CAIRO_VERSION_MICRO) - - -cairo_public int -cairo_version (void); - -cairo_public const char* -cairo_version_string (void); - -/** - * cairo_bool_t: - * - * #cairo_bool_t is used for boolean values. Returns of type - * #cairo_bool_t will always be either 0 or 1, but testing against - * these values explicitly is not encouraged; just use the - * value as a boolean condition. - * - * - * if (cairo_in_stroke (cr, x, y)) { - * /* do something */ - * } - * - * - * Since: 1.0 - **/ -typedef int cairo_bool_t; - -/** - * cairo_t: - * - * A #cairo_t contains the current state of the rendering device, - * including coordinates of yet to be drawn shapes. - * - * Cairo contexts, as #cairo_t objects are named, are central to - * cairo and all drawing with cairo is always done to a #cairo_t - * object. - * - * Memory management of #cairo_t is done with - * cairo_reference() and cairo_destroy(). - * - * Since: 1.0 - **/ -typedef struct _cairo cairo_t; - -/** - * cairo_surface_t: - * - * A #cairo_surface_t represents an image, either as the destination - * of a drawing operation or as source when drawing onto another - * surface. To draw to a #cairo_surface_t, create a cairo context - * with the surface as the target, using cairo_create(). - * - * There are different subtypes of #cairo_surface_t for - * different drawing backends; for example, cairo_image_surface_create() - * creates a bitmap image in memory. - * The type of a surface can be queried with cairo_surface_get_type(). - * - * The initial contents of a surface after creation depend upon the manner - * of its creation. If cairo creates the surface and backing storage for - * the user, it will be initially cleared; for example, - * cairo_image_surface_create() and cairo_surface_create_similar(). - * Alternatively, if the user passes in a reference to some backing storage - * and asks cairo to wrap that in a #cairo_surface_t, then the contents are - * not modified; for example, cairo_image_surface_create_for_data() and - * cairo_xlib_surface_create(). - * - * Memory management of #cairo_surface_t is done with - * cairo_surface_reference() and cairo_surface_destroy(). - * - * Since: 1.0 - **/ -typedef struct _cairo_surface cairo_surface_t; - -/** - * cairo_device_t: - * - * A #cairo_device_t represents the driver interface for drawing - * operations to a #cairo_surface_t. There are different subtypes of - * #cairo_device_t for different drawing backends; for example, - * cairo_egl_device_create() creates a device that wraps an EGL display and - * context. - * - * The type of a device can be queried with cairo_device_get_type(). - * - * Memory management of #cairo_device_t is done with - * cairo_device_reference() and cairo_device_destroy(). - * - * Since: 1.10 - **/ -typedef struct _cairo_device cairo_device_t; - -/** - * cairo_matrix_t: - * @xx: xx component of the affine transformation - * @yx: yx component of the affine transformation - * @xy: xy component of the affine transformation - * @yy: yy component of the affine transformation - * @x0: X translation component of the affine transformation - * @y0: Y translation component of the affine transformation - * - * A #cairo_matrix_t holds an affine transformation, such as a scale, - * rotation, shear, or a combination of those. The transformation of - * a point (x, y) is given by: - * - * x_new = xx * x + xy * y + x0; - * y_new = yx * x + yy * y + y0; - * - * - * Since: 1.0 - **/ -typedef struct _cairo_matrix { - double xx; double yx; - double xy; double yy; - double x0; double y0; -} cairo_matrix_t; - -/** - * cairo_pattern_t: - * - * A #cairo_pattern_t represents a source when drawing onto a - * surface. There are different subtypes of #cairo_pattern_t, - * for different types of sources; for example, - * cairo_pattern_create_rgb() creates a pattern for a solid - * opaque color. - * - * Other than various - * cairo_pattern_create_type() - * functions, some of the pattern types can be implicitly created using various - * cairo_set_source_type() functions; - * for example cairo_set_source_rgb(). - * - * The type of a pattern can be queried with cairo_pattern_get_type(). - * - * Memory management of #cairo_pattern_t is done with - * cairo_pattern_reference() and cairo_pattern_destroy(). - * - * Since: 1.0 - **/ -typedef struct _cairo_pattern cairo_pattern_t; - -/** - * cairo_destroy_func_t: - * @data: The data element being destroyed. - * - * #cairo_destroy_func_t the type of function which is called when a - * data element is destroyed. It is passed the pointer to the data - * element and should free any memory and resources allocated for it. - * - * Since: 1.0 - **/ -typedef void (*cairo_destroy_func_t) (void *data); - -/** - * cairo_user_data_key_t: - * @unused: not used; ignore. - * - * #cairo_user_data_key_t is used for attaching user data to cairo - * data structures. The actual contents of the struct is never used, - * and there is no need to initialize the object; only the unique - * address of a #cairo_data_key_t object is used. Typically, you - * would just use the address of a static #cairo_data_key_t object. - * - * Since: 1.0 - **/ -typedef struct _cairo_user_data_key { - int unused; -} cairo_user_data_key_t; - -/** - * cairo_status_t: - * @CAIRO_STATUS_SUCCESS: no error has occurred (Since 1.0) - * @CAIRO_STATUS_NO_MEMORY: out of memory (Since 1.0) - * @CAIRO_STATUS_INVALID_RESTORE: cairo_restore() called without matching cairo_save() (Since 1.0) - * @CAIRO_STATUS_INVALID_POP_GROUP: no saved group to pop, i.e. cairo_pop_group() without matching cairo_push_group() (Since 1.0) - * @CAIRO_STATUS_NO_CURRENT_POINT: no current point defined (Since 1.0) - * @CAIRO_STATUS_INVALID_MATRIX: invalid matrix (not invertible) (Since 1.0) - * @CAIRO_STATUS_INVALID_STATUS: invalid value for an input #cairo_status_t (Since 1.0) - * @CAIRO_STATUS_NULL_POINTER: %NULL pointer (Since 1.0) - * @CAIRO_STATUS_INVALID_STRING: input string not valid UTF-8 (Since 1.0) - * @CAIRO_STATUS_INVALID_PATH_DATA: input path data not valid (Since 1.0) - * @CAIRO_STATUS_READ_ERROR: error while reading from input stream (Since 1.0) - * @CAIRO_STATUS_WRITE_ERROR: error while writing to output stream (Since 1.0) - * @CAIRO_STATUS_SURFACE_FINISHED: target surface has been finished (Since 1.0) - * @CAIRO_STATUS_SURFACE_TYPE_MISMATCH: the surface type is not appropriate for the operation (Since 1.0) - * @CAIRO_STATUS_PATTERN_TYPE_MISMATCH: the pattern type is not appropriate for the operation (Since 1.0) - * @CAIRO_STATUS_INVALID_CONTENT: invalid value for an input #cairo_content_t (Since 1.0) - * @CAIRO_STATUS_INVALID_FORMAT: invalid value for an input #cairo_format_t (Since 1.0) - * @CAIRO_STATUS_INVALID_VISUAL: invalid value for an input Visual* (Since 1.0) - * @CAIRO_STATUS_FILE_NOT_FOUND: file not found (Since 1.0) - * @CAIRO_STATUS_INVALID_DASH: invalid value for a dash setting (Since 1.0) - * @CAIRO_STATUS_INVALID_DSC_COMMENT: invalid value for a DSC comment (Since 1.2) - * @CAIRO_STATUS_INVALID_INDEX: invalid index passed to getter (Since 1.4) - * @CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: clip region not representable in desired format (Since 1.4) - * @CAIRO_STATUS_TEMP_FILE_ERROR: error creating or writing to a temporary file (Since 1.6) - * @CAIRO_STATUS_INVALID_STRIDE: invalid value for stride (Since 1.6) - * @CAIRO_STATUS_FONT_TYPE_MISMATCH: the font type is not appropriate for the operation (Since 1.8) - * @CAIRO_STATUS_USER_FONT_IMMUTABLE: the user-font is immutable (Since 1.8) - * @CAIRO_STATUS_USER_FONT_ERROR: error occurred in a user-font callback function (Since 1.8) - * @CAIRO_STATUS_NEGATIVE_COUNT: negative number used where it is not allowed (Since 1.8) - * @CAIRO_STATUS_INVALID_CLUSTERS: input clusters do not represent the accompanying text and glyph array (Since 1.8) - * @CAIRO_STATUS_INVALID_SLANT: invalid value for an input #cairo_font_slant_t (Since 1.8) - * @CAIRO_STATUS_INVALID_WEIGHT: invalid value for an input #cairo_font_weight_t (Since 1.8) - * @CAIRO_STATUS_INVALID_SIZE: invalid value (typically too big) for the size of the input (surface, pattern, etc.) (Since 1.10) - * @CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: user-font method not implemented (Since 1.10) - * @CAIRO_STATUS_DEVICE_TYPE_MISMATCH: the device type is not appropriate for the operation (Since 1.10) - * @CAIRO_STATUS_DEVICE_ERROR: an operation to the device caused an unspecified error (Since 1.10) - * @CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: a mesh pattern - * construction operation was used outside of a - * cairo_mesh_pattern_begin_patch()/cairo_mesh_pattern_end_patch() - * pair (Since 1.12) - * @CAIRO_STATUS_DEVICE_FINISHED: target device has been finished (Since 1.12) - * @CAIRO_STATUS_JBIG2_GLOBAL_MISSING: %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID has been used on at least one image - * but no image provided %CAIRO_MIME_TYPE_JBIG2_GLOBAL (Since 1.14) - * @CAIRO_STATUS_LAST_STATUS: this is a special value indicating the number of - * status values defined in this enumeration. When using this value, note - * that the version of cairo at run-time may have additional status values - * defined than the value of this symbol at compile-time. (Since 1.10) - * - * #cairo_status_t is used to indicate errors that can occur when - * using Cairo. In some cases it is returned directly by functions. - * but when using #cairo_t, the last error, if any, is stored in - * the context and can be retrieved with cairo_status(). - * - * New entries may be added in future versions. Use cairo_status_to_string() - * to get a human-readable representation of an error message. - * - * Since: 1.0 - **/ -typedef enum _cairo_status { - CAIRO_STATUS_SUCCESS = 0, - - CAIRO_STATUS_NO_MEMORY, - CAIRO_STATUS_INVALID_RESTORE, - CAIRO_STATUS_INVALID_POP_GROUP, - CAIRO_STATUS_NO_CURRENT_POINT, - CAIRO_STATUS_INVALID_MATRIX, - CAIRO_STATUS_INVALID_STATUS, - CAIRO_STATUS_NULL_POINTER, - CAIRO_STATUS_INVALID_STRING, - CAIRO_STATUS_INVALID_PATH_DATA, - CAIRO_STATUS_READ_ERROR, - CAIRO_STATUS_WRITE_ERROR, - CAIRO_STATUS_SURFACE_FINISHED, - CAIRO_STATUS_SURFACE_TYPE_MISMATCH, - CAIRO_STATUS_PATTERN_TYPE_MISMATCH, - CAIRO_STATUS_INVALID_CONTENT, - CAIRO_STATUS_INVALID_FORMAT, - CAIRO_STATUS_INVALID_VISUAL, - CAIRO_STATUS_FILE_NOT_FOUND, - CAIRO_STATUS_INVALID_DASH, - CAIRO_STATUS_INVALID_DSC_COMMENT, - CAIRO_STATUS_INVALID_INDEX, - CAIRO_STATUS_CLIP_NOT_REPRESENTABLE, - CAIRO_STATUS_TEMP_FILE_ERROR, - CAIRO_STATUS_INVALID_STRIDE, - CAIRO_STATUS_FONT_TYPE_MISMATCH, - CAIRO_STATUS_USER_FONT_IMMUTABLE, - CAIRO_STATUS_USER_FONT_ERROR, - CAIRO_STATUS_NEGATIVE_COUNT, - CAIRO_STATUS_INVALID_CLUSTERS, - CAIRO_STATUS_INVALID_SLANT, - CAIRO_STATUS_INVALID_WEIGHT, - CAIRO_STATUS_INVALID_SIZE, - CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, - CAIRO_STATUS_DEVICE_TYPE_MISMATCH, - CAIRO_STATUS_DEVICE_ERROR, - CAIRO_STATUS_INVALID_MESH_CONSTRUCTION, - CAIRO_STATUS_DEVICE_FINISHED, - CAIRO_STATUS_JBIG2_GLOBAL_MISSING, - - CAIRO_STATUS_LAST_STATUS -} cairo_status_t; - -/** - * cairo_content_t: - * @CAIRO_CONTENT_COLOR: The surface will hold color content only. (Since 1.0) - * @CAIRO_CONTENT_ALPHA: The surface will hold alpha content only. (Since 1.0) - * @CAIRO_CONTENT_COLOR_ALPHA: The surface will hold color and alpha content. (Since 1.0) - * - * #cairo_content_t is used to describe the content that a surface will - * contain, whether color information, alpha information (translucence - * vs. opacity), or both. - * - * Note: The large values here are designed to keep #cairo_content_t - * values distinct from #cairo_format_t values so that the - * implementation can detect the error if users confuse the two types. - * - * Since: 1.0 - **/ -typedef enum _cairo_content { - CAIRO_CONTENT_COLOR = 0x1000, - CAIRO_CONTENT_ALPHA = 0x2000, - CAIRO_CONTENT_COLOR_ALPHA = 0x3000 -} cairo_content_t; - -/** - * cairo_format_t: - * @CAIRO_FORMAT_INVALID: no such format exists or is supported. - * @CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with - * alpha in the upper 8 bits, then red, then green, then blue. - * The 32-bit quantities are stored native-endian. Pre-multiplied - * alpha is used. (That is, 50% transparent red is 0x80800000, - * not 0x80ff0000.) (Since 1.0) - * @CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with - * the upper 8 bits unused. Red, Green, and Blue are stored - * in the remaining 24 bits in that order. (Since 1.0) - * @CAIRO_FORMAT_A8: each pixel is a 8-bit quantity holding - * an alpha value. (Since 1.0) - * @CAIRO_FORMAT_A1: each pixel is a 1-bit quantity holding - * an alpha value. Pixels are packed together into 32-bit - * quantities. The ordering of the bits matches the - * endianess of the platform. On a big-endian machine, the - * first pixel is in the uppermost bit, on a little-endian - * machine the first pixel is in the least-significant bit. (Since 1.0) - * @CAIRO_FORMAT_RGB16_565: each pixel is a 16-bit quantity - * with red in the upper 5 bits, then green in the middle - * 6 bits, and blue in the lower 5 bits. (Since 1.2) - * @CAIRO_FORMAT_RGB30: like RGB24 but with 10bpc. (Since 1.12) - * - * #cairo_format_t is used to identify the memory format of - * image data. - * - * New entries may be added in future versions. - * - * Since: 1.0 - **/ -typedef enum _cairo_format { - CAIRO_FORMAT_INVALID = -1, - CAIRO_FORMAT_ARGB32 = 0, - CAIRO_FORMAT_RGB24 = 1, - CAIRO_FORMAT_A8 = 2, - CAIRO_FORMAT_A1 = 3, - CAIRO_FORMAT_RGB16_565 = 4, - CAIRO_FORMAT_RGB30 = 5 -} cairo_format_t; - - -/** - * cairo_write_func_t: - * @closure: the output closure - * @data: the buffer containing the data to write - * @length: the amount of data to write - * - * #cairo_write_func_t is the type of function which is called when a - * backend needs to write data to an output stream. It is passed the - * closure which was specified by the user at the time the write - * function was registered, the data to write and the length of the - * data in bytes. The write function should return - * %CAIRO_STATUS_SUCCESS if all the data was successfully written, - * %CAIRO_STATUS_WRITE_ERROR otherwise. - * - * Returns: the status code of the write operation - * - * Since: 1.0 - **/ -typedef cairo_status_t (*cairo_write_func_t) (void *closure, - const unsigned char *data, - unsigned int length); - -/** - * cairo_read_func_t: - * @closure: the input closure - * @data: the buffer into which to read the data - * @length: the amount of data to read - * - * #cairo_read_func_t is the type of function which is called when a - * backend needs to read data from an input stream. It is passed the - * closure which was specified by the user at the time the read - * function was registered, the buffer to read the data into and the - * length of the data in bytes. The read function should return - * %CAIRO_STATUS_SUCCESS if all the data was successfully read, - * %CAIRO_STATUS_READ_ERROR otherwise. - * - * Returns: the status code of the read operation - * - * Since: 1.0 - **/ -typedef cairo_status_t (*cairo_read_func_t) (void *closure, - unsigned char *data, - unsigned int length); - -/** - * cairo_rectangle_int_t: - * @x: X coordinate of the left side of the rectangle - * @y: Y coordinate of the the top side of the rectangle - * @width: width of the rectangle - * @height: height of the rectangle - * - * A data structure for holding a rectangle with integer coordinates. - * - * Since: 1.10 - **/ - -typedef struct _cairo_rectangle_int { - int x, y; - int width, height; -} cairo_rectangle_int_t; - - -/* Functions for manipulating state objects */ -cairo_public cairo_t * -cairo_create (cairo_surface_t *target); - -cairo_public cairo_t * -cairo_reference (cairo_t *cr); - -cairo_public void -cairo_destroy (cairo_t *cr); - -cairo_public unsigned int -cairo_get_reference_count (cairo_t *cr); - -cairo_public void * -cairo_get_user_data (cairo_t *cr, - const cairo_user_data_key_t *key); - -cairo_public cairo_status_t -cairo_set_user_data (cairo_t *cr, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - -cairo_public void -cairo_save (cairo_t *cr); - -cairo_public void -cairo_restore (cairo_t *cr); - -cairo_public void -cairo_push_group (cairo_t *cr); - -cairo_public void -cairo_push_group_with_content (cairo_t *cr, cairo_content_t content); - -cairo_public cairo_pattern_t * -cairo_pop_group (cairo_t *cr); - -cairo_public void -cairo_pop_group_to_source (cairo_t *cr); - -/* Modify state */ - -/** - * cairo_operator_t: - * @CAIRO_OPERATOR_CLEAR: clear destination layer (bounded) (Since 1.0) - * @CAIRO_OPERATOR_SOURCE: replace destination layer (bounded) (Since 1.0) - * @CAIRO_OPERATOR_OVER: draw source layer on top of destination layer - * (bounded) (Since 1.0) - * @CAIRO_OPERATOR_IN: draw source where there was destination content - * (unbounded) (Since 1.0) - * @CAIRO_OPERATOR_OUT: draw source where there was no destination - * content (unbounded) (Since 1.0) - * @CAIRO_OPERATOR_ATOP: draw source on top of destination content and - * only there (Since 1.0) - * @CAIRO_OPERATOR_DEST: ignore the source (Since 1.0) - * @CAIRO_OPERATOR_DEST_OVER: draw destination on top of source (Since 1.0) - * @CAIRO_OPERATOR_DEST_IN: leave destination only where there was - * source content (unbounded) (Since 1.0) - * @CAIRO_OPERATOR_DEST_OUT: leave destination only where there was no - * source content (Since 1.0) - * @CAIRO_OPERATOR_DEST_ATOP: leave destination on top of source content - * and only there (unbounded) (Since 1.0) - * @CAIRO_OPERATOR_XOR: source and destination are shown where there is only - * one of them (Since 1.0) - * @CAIRO_OPERATOR_ADD: source and destination layers are accumulated (Since 1.0) - * @CAIRO_OPERATOR_SATURATE: like over, but assuming source and dest are - * disjoint geometries (Since 1.0) - * @CAIRO_OPERATOR_MULTIPLY: source and destination layers are multiplied. - * This causes the result to be at least as dark as the darker inputs. (Since 1.10) - * @CAIRO_OPERATOR_SCREEN: source and destination are complemented and - * multiplied. This causes the result to be at least as light as the lighter - * inputs. (Since 1.10) - * @CAIRO_OPERATOR_OVERLAY: multiplies or screens, depending on the - * lightness of the destination color. (Since 1.10) - * @CAIRO_OPERATOR_DARKEN: replaces the destination with the source if it - * is darker, otherwise keeps the source. (Since 1.10) - * @CAIRO_OPERATOR_LIGHTEN: replaces the destination with the source if it - * is lighter, otherwise keeps the source. (Since 1.10) - * @CAIRO_OPERATOR_COLOR_DODGE: brightens the destination color to reflect - * the source color. (Since 1.10) - * @CAIRO_OPERATOR_COLOR_BURN: darkens the destination color to reflect - * the source color. (Since 1.10) - * @CAIRO_OPERATOR_HARD_LIGHT: Multiplies or screens, dependent on source - * color. (Since 1.10) - * @CAIRO_OPERATOR_SOFT_LIGHT: Darkens or lightens, dependent on source - * color. (Since 1.10) - * @CAIRO_OPERATOR_DIFFERENCE: Takes the difference of the source and - * destination color. (Since 1.10) - * @CAIRO_OPERATOR_EXCLUSION: Produces an effect similar to difference, but - * with lower contrast. (Since 1.10) - * @CAIRO_OPERATOR_HSL_HUE: Creates a color with the hue of the source - * and the saturation and luminosity of the target. (Since 1.10) - * @CAIRO_OPERATOR_HSL_SATURATION: Creates a color with the saturation - * of the source and the hue and luminosity of the target. Painting with - * this mode onto a gray area produces no change. (Since 1.10) - * @CAIRO_OPERATOR_HSL_COLOR: Creates a color with the hue and saturation - * of the source and the luminosity of the target. This preserves the gray - * levels of the target and is useful for coloring monochrome images or - * tinting color images. (Since 1.10) - * @CAIRO_OPERATOR_HSL_LUMINOSITY: Creates a color with the luminosity of - * the source and the hue and saturation of the target. This produces an - * inverse effect to @CAIRO_OPERATOR_HSL_COLOR. (Since 1.10) - * - * #cairo_operator_t is used to set the compositing operator for all cairo - * drawing operations. - * - * The default operator is %CAIRO_OPERATOR_OVER. - * - * The operators marked as unbounded modify their - * destination even outside of the mask layer (that is, their effect is not - * bound by the mask layer). However, their effect can still be limited by - * way of clipping. - * - * To keep things simple, the operator descriptions here - * document the behavior for when both source and destination are either fully - * transparent or fully opaque. The actual implementation works for - * translucent layers too. - * For a more detailed explanation of the effects of each operator, including - * the mathematical definitions, see - * http://cairographics.org/operators/. - * - * Since: 1.0 - **/ -typedef enum _cairo_operator { - CAIRO_OPERATOR_CLEAR, - - CAIRO_OPERATOR_SOURCE, - CAIRO_OPERATOR_OVER, - CAIRO_OPERATOR_IN, - CAIRO_OPERATOR_OUT, - CAIRO_OPERATOR_ATOP, - - CAIRO_OPERATOR_DEST, - CAIRO_OPERATOR_DEST_OVER, - CAIRO_OPERATOR_DEST_IN, - CAIRO_OPERATOR_DEST_OUT, - CAIRO_OPERATOR_DEST_ATOP, - - CAIRO_OPERATOR_XOR, - CAIRO_OPERATOR_ADD, - CAIRO_OPERATOR_SATURATE, - - CAIRO_OPERATOR_MULTIPLY, - CAIRO_OPERATOR_SCREEN, - CAIRO_OPERATOR_OVERLAY, - CAIRO_OPERATOR_DARKEN, - CAIRO_OPERATOR_LIGHTEN, - CAIRO_OPERATOR_COLOR_DODGE, - CAIRO_OPERATOR_COLOR_BURN, - CAIRO_OPERATOR_HARD_LIGHT, - CAIRO_OPERATOR_SOFT_LIGHT, - CAIRO_OPERATOR_DIFFERENCE, - CAIRO_OPERATOR_EXCLUSION, - CAIRO_OPERATOR_HSL_HUE, - CAIRO_OPERATOR_HSL_SATURATION, - CAIRO_OPERATOR_HSL_COLOR, - CAIRO_OPERATOR_HSL_LUMINOSITY -} cairo_operator_t; - -cairo_public void -cairo_set_operator (cairo_t *cr, cairo_operator_t op); - -cairo_public void -cairo_set_source (cairo_t *cr, cairo_pattern_t *source); - -cairo_public void -cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue); - -cairo_public void -cairo_set_source_rgba (cairo_t *cr, - double red, double green, double blue, - double alpha); - -cairo_public void -cairo_set_source_surface (cairo_t *cr, - cairo_surface_t *surface, - double x, - double y); - -cairo_public void -cairo_set_tolerance (cairo_t *cr, double tolerance); - -/** - * cairo_antialias_t: - * @CAIRO_ANTIALIAS_DEFAULT: Use the default antialiasing for - * the subsystem and target device, since 1.0 - * @CAIRO_ANTIALIAS_NONE: Use a bilevel alpha mask, since 1.0 - * @CAIRO_ANTIALIAS_GRAY: Perform single-color antialiasing (using - * shades of gray for black text on a white background, for example), since 1.0 - * @CAIRO_ANTIALIAS_SUBPIXEL: Perform antialiasing by taking - * advantage of the order of subpixel elements on devices - * such as LCD panels, since 1.0 - * @CAIRO_ANTIALIAS_FAST: Hint that the backend should perform some - * antialiasing but prefer speed over quality, since 1.12 - * @CAIRO_ANTIALIAS_GOOD: The backend should balance quality against - * performance, since 1.12 - * @CAIRO_ANTIALIAS_BEST: Hint that the backend should render at the highest - * quality, sacrificing speed if necessary, since 1.12 - * - * Specifies the type of antialiasing to do when rendering text or shapes. - * - * As it is not necessarily clear from the above what advantages a particular - * antialias method provides, since 1.12, there is also a set of hints: - * @CAIRO_ANTIALIAS_FAST: Allow the backend to degrade raster quality for speed - * @CAIRO_ANTIALIAS_GOOD: A balance between speed and quality - * @CAIRO_ANTIALIAS_BEST: A high-fidelity, but potentially slow, raster mode - * - * These make no guarantee on how the backend will perform its rasterisation - * (if it even rasterises!), nor that they have any differing effect other - * than to enable some form of antialiasing. In the case of glyph rendering, - * @CAIRO_ANTIALIAS_FAST and @CAIRO_ANTIALIAS_GOOD will be mapped to - * @CAIRO_ANTIALIAS_GRAY, with @CAIRO_ANTALIAS_BEST being equivalent to - * @CAIRO_ANTIALIAS_SUBPIXEL. - * - * The interpretation of @CAIRO_ANTIALIAS_DEFAULT is left entirely up to - * the backend, typically this will be similar to @CAIRO_ANTIALIAS_GOOD. - * - * Since: 1.0 - **/ -typedef enum _cairo_antialias { - CAIRO_ANTIALIAS_DEFAULT, - - /* method */ - CAIRO_ANTIALIAS_NONE, - CAIRO_ANTIALIAS_GRAY, - CAIRO_ANTIALIAS_SUBPIXEL, - - /* hints */ - CAIRO_ANTIALIAS_FAST, - CAIRO_ANTIALIAS_GOOD, - CAIRO_ANTIALIAS_BEST -} cairo_antialias_t; - -cairo_public void -cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias); - -/** - * cairo_fill_rule_t: - * @CAIRO_FILL_RULE_WINDING: If the path crosses the ray from - * left-to-right, counts +1. If the path crosses the ray - * from right to left, counts -1. (Left and right are determined - * from the perspective of looking along the ray from the starting - * point.) If the total count is non-zero, the point will be filled. (Since 1.0) - * @CAIRO_FILL_RULE_EVEN_ODD: Counts the total number of - * intersections, without regard to the orientation of the contour. If - * the total number of intersections is odd, the point will be - * filled. (Since 1.0) - * - * #cairo_fill_rule_t is used to select how paths are filled. For both - * fill rules, whether or not a point is included in the fill is - * determined by taking a ray from that point to infinity and looking - * at intersections with the path. The ray can be in any direction, - * as long as it doesn't pass through the end point of a segment - * or have a tricky intersection such as intersecting tangent to the path. - * (Note that filling is not actually implemented in this way. This - * is just a description of the rule that is applied.) - * - * The default fill rule is %CAIRO_FILL_RULE_WINDING. - * - * New entries may be added in future versions. - * - * Since: 1.0 - **/ -typedef enum _cairo_fill_rule { - CAIRO_FILL_RULE_WINDING, - CAIRO_FILL_RULE_EVEN_ODD -} cairo_fill_rule_t; - -cairo_public void -cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule); - -cairo_public void -cairo_set_line_width (cairo_t *cr, double width); - -/** - * cairo_line_cap_t: - * @CAIRO_LINE_CAP_BUTT: start(stop) the line exactly at the start(end) point (Since 1.0) - * @CAIRO_LINE_CAP_ROUND: use a round ending, the center of the circle is the end point (Since 1.0) - * @CAIRO_LINE_CAP_SQUARE: use squared ending, the center of the square is the end point (Since 1.0) - * - * Specifies how to render the endpoints of the path when stroking. - * - * The default line cap style is %CAIRO_LINE_CAP_BUTT. - * - * Since: 1.0 - **/ -typedef enum _cairo_line_cap { - CAIRO_LINE_CAP_BUTT, - CAIRO_LINE_CAP_ROUND, - CAIRO_LINE_CAP_SQUARE -} cairo_line_cap_t; - -cairo_public void -cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap); - -/** - * cairo_line_join_t: - * @CAIRO_LINE_JOIN_MITER: use a sharp (angled) corner, see - * cairo_set_miter_limit() (Since 1.0) - * @CAIRO_LINE_JOIN_ROUND: use a rounded join, the center of the circle is the - * joint point (Since 1.0) - * @CAIRO_LINE_JOIN_BEVEL: use a cut-off join, the join is cut off at half - * the line width from the joint point (Since 1.0) - * - * Specifies how to render the junction of two lines when stroking. - * - * The default line join style is %CAIRO_LINE_JOIN_MITER. - * - * Since: 1.0 - **/ -typedef enum _cairo_line_join { - CAIRO_LINE_JOIN_MITER, - CAIRO_LINE_JOIN_ROUND, - CAIRO_LINE_JOIN_BEVEL -} cairo_line_join_t; - -cairo_public void -cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join); - -cairo_public void -cairo_set_dash (cairo_t *cr, - const double *dashes, - int num_dashes, - double offset); - -cairo_public void -cairo_set_miter_limit (cairo_t *cr, double limit); - -cairo_public void -cairo_translate (cairo_t *cr, double tx, double ty); - -cairo_public void -cairo_scale (cairo_t *cr, double sx, double sy); - -cairo_public void -cairo_rotate (cairo_t *cr, double angle); - -cairo_public void -cairo_transform (cairo_t *cr, - const cairo_matrix_t *matrix); - -cairo_public void -cairo_set_matrix (cairo_t *cr, - const cairo_matrix_t *matrix); - -cairo_public void -cairo_identity_matrix (cairo_t *cr); - -cairo_public void -cairo_user_to_device (cairo_t *cr, double *x, double *y); - -cairo_public void -cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy); - -cairo_public void -cairo_device_to_user (cairo_t *cr, double *x, double *y); - -cairo_public void -cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy); - -/* Path creation functions */ -cairo_public void -cairo_new_path (cairo_t *cr); - -cairo_public void -cairo_move_to (cairo_t *cr, double x, double y); - -cairo_public void -cairo_new_sub_path (cairo_t *cr); - -cairo_public void -cairo_line_to (cairo_t *cr, double x, double y); - -cairo_public void -cairo_curve_to (cairo_t *cr, - double x1, double y1, - double x2, double y2, - double x3, double y3); - -cairo_public void -cairo_arc (cairo_t *cr, - double xc, double yc, - double radius, - double angle1, double angle2); - -cairo_public void -cairo_arc_negative (cairo_t *cr, - double xc, double yc, - double radius, - double angle1, double angle2); - -/* XXX: NYI -cairo_public void -cairo_arc_to (cairo_t *cr, - double x1, double y1, - double x2, double y2, - double radius); -*/ - -cairo_public void -cairo_rel_move_to (cairo_t *cr, double dx, double dy); - -cairo_public void -cairo_rel_line_to (cairo_t *cr, double dx, double dy); - -cairo_public void -cairo_rel_curve_to (cairo_t *cr, - double dx1, double dy1, - double dx2, double dy2, - double dx3, double dy3); - -cairo_public void -cairo_rectangle (cairo_t *cr, - double x, double y, - double width, double height); - -/* XXX: NYI -cairo_public void -cairo_stroke_to_path (cairo_t *cr); -*/ - -cairo_public void -cairo_close_path (cairo_t *cr); - -cairo_public void -cairo_path_extents (cairo_t *cr, - double *x1, double *y1, - double *x2, double *y2); - -/* Painting functions */ -cairo_public void -cairo_paint (cairo_t *cr); - -cairo_public void -cairo_paint_with_alpha (cairo_t *cr, - double alpha); - -cairo_public void -cairo_mask (cairo_t *cr, - cairo_pattern_t *pattern); - -cairo_public void -cairo_mask_surface (cairo_t *cr, - cairo_surface_t *surface, - double surface_x, - double surface_y); - -cairo_public void -cairo_stroke (cairo_t *cr); - -cairo_public void -cairo_stroke_preserve (cairo_t *cr); - -cairo_public void -cairo_fill (cairo_t *cr); - -cairo_public void -cairo_fill_preserve (cairo_t *cr); - -cairo_public void -cairo_copy_page (cairo_t *cr); - -cairo_public void -cairo_show_page (cairo_t *cr); - -/* Insideness testing */ -cairo_public cairo_bool_t -cairo_in_stroke (cairo_t *cr, double x, double y); - -cairo_public cairo_bool_t -cairo_in_fill (cairo_t *cr, double x, double y); - -cairo_public cairo_bool_t -cairo_in_clip (cairo_t *cr, double x, double y); - -/* Rectangular extents */ -cairo_public void -cairo_stroke_extents (cairo_t *cr, - double *x1, double *y1, - double *x2, double *y2); - -cairo_public void -cairo_fill_extents (cairo_t *cr, - double *x1, double *y1, - double *x2, double *y2); - -/* Clipping */ -cairo_public void -cairo_reset_clip (cairo_t *cr); - -cairo_public void -cairo_clip (cairo_t *cr); - -cairo_public void -cairo_clip_preserve (cairo_t *cr); - -cairo_public void -cairo_clip_extents (cairo_t *cr, - double *x1, double *y1, - double *x2, double *y2); - -/** - * cairo_rectangle_t: - * @x: X coordinate of the left side of the rectangle - * @y: Y coordinate of the the top side of the rectangle - * @width: width of the rectangle - * @height: height of the rectangle - * - * A data structure for holding a rectangle. - * - * Since: 1.4 - **/ -typedef struct _cairo_rectangle { - double x, y, width, height; -} cairo_rectangle_t; - -/** - * cairo_rectangle_list_t: - * @status: Error status of the rectangle list - * @rectangles: Array containing the rectangles - * @num_rectangles: Number of rectangles in this list - * - * A data structure for holding a dynamically allocated - * array of rectangles. - * - * Since: 1.4 - **/ -typedef struct _cairo_rectangle_list { - cairo_status_t status; - cairo_rectangle_t *rectangles; - int num_rectangles; -} cairo_rectangle_list_t; - -cairo_public cairo_rectangle_list_t * -cairo_copy_clip_rectangle_list (cairo_t *cr); - -cairo_public void -cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list); - -/* Font/Text functions */ - -/** - * cairo_scaled_font_t: - * - * A #cairo_scaled_font_t is a font scaled to a particular size and device - * resolution. A #cairo_scaled_font_t is most useful for low-level font - * usage where a library or application wants to cache a reference - * to a scaled font to speed up the computation of metrics. - * - * There are various types of scaled fonts, depending on the - * font backend they use. The type of a - * scaled font can be queried using cairo_scaled_font_get_type(). - * - * Memory management of #cairo_scaled_font_t is done with - * cairo_scaled_font_reference() and cairo_scaled_font_destroy(). - * - * Since: 1.0 - **/ -typedef struct _cairo_scaled_font cairo_scaled_font_t; - -/** - * cairo_font_face_t: - * - * A #cairo_font_face_t specifies all aspects of a font other - * than the size or font matrix (a font matrix is used to distort - * a font by sheering it or scaling it unequally in the two - * directions) . A font face can be set on a #cairo_t by using - * cairo_set_font_face(); the size and font matrix are set with - * cairo_set_font_size() and cairo_set_font_matrix(). - * - * There are various types of font faces, depending on the - * font backend they use. The type of a - * font face can be queried using cairo_font_face_get_type(). - * - * Memory management of #cairo_font_face_t is done with - * cairo_font_face_reference() and cairo_font_face_destroy(). - * - * Since: 1.0 - **/ -typedef struct _cairo_font_face cairo_font_face_t; - -/** - * cairo_glyph_t: - * @index: glyph index in the font. The exact interpretation of the - * glyph index depends on the font technology being used. - * @x: the offset in the X direction between the origin used for - * drawing or measuring the string and the origin of this glyph. - * @y: the offset in the Y direction between the origin used for - * drawing or measuring the string and the origin of this glyph. - * - * The #cairo_glyph_t structure holds information about a single glyph - * when drawing or measuring text. A font is (in simple terms) a - * collection of shapes used to draw text. A glyph is one of these - * shapes. There can be multiple glyphs for a single character - * (alternates to be used in different contexts, for example), or a - * glyph can be a ligature of multiple - * characters. Cairo doesn't expose any way of converting input text - * into glyphs, so in order to use the Cairo interfaces that take - * arrays of glyphs, you must directly access the appropriate - * underlying font system. - * - * Note that the offsets given by @x and @y are not cumulative. When - * drawing or measuring text, each glyph is individually positioned - * with respect to the overall origin - * - * Since: 1.0 - **/ -typedef struct { - unsigned long index; - double x; - double y; -} cairo_glyph_t; - -cairo_public cairo_glyph_t * -cairo_glyph_allocate (int num_glyphs); - -cairo_public void -cairo_glyph_free (cairo_glyph_t *glyphs); - -/** - * cairo_text_cluster_t: - * @num_bytes: the number of bytes of UTF-8 text covered by cluster - * @num_glyphs: the number of glyphs covered by cluster - * - * The #cairo_text_cluster_t structure holds information about a single - * text cluster. A text cluster is a minimal - * mapping of some glyphs corresponding to some UTF-8 text. - * - * For a cluster to be valid, both @num_bytes and @num_glyphs should - * be non-negative, and at least one should be non-zero. - * Note that clusters with zero glyphs are not as well supported as - * normal clusters. For example, PDF rendering applications typically - * ignore those clusters when PDF text is being selected. - * - * See cairo_show_text_glyphs() for how clusters are used in advanced - * text operations. - * - * Since: 1.8 - **/ -typedef struct { - int num_bytes; - int num_glyphs; -} cairo_text_cluster_t; - -cairo_public cairo_text_cluster_t * -cairo_text_cluster_allocate (int num_clusters); - -cairo_public void -cairo_text_cluster_free (cairo_text_cluster_t *clusters); - -/** - * cairo_text_cluster_flags_t: - * @CAIRO_TEXT_CLUSTER_FLAG_BACKWARD: The clusters in the cluster array - * map to glyphs in the glyph array from end to start. (Since 1.8) - * - * Specifies properties of a text cluster mapping. - * - * Since: 1.8 - **/ -typedef enum _cairo_text_cluster_flags { - CAIRO_TEXT_CLUSTER_FLAG_BACKWARD = 0x00000001 -} cairo_text_cluster_flags_t; - -/** - * cairo_text_extents_t: - * @x_bearing: the horizontal distance from the origin to the - * leftmost part of the glyphs as drawn. Positive if the - * glyphs lie entirely to the right of the origin. - * @y_bearing: the vertical distance from the origin to the - * topmost part of the glyphs as drawn. Positive only if the - * glyphs lie completely below the origin; will usually be - * negative. - * @width: width of the glyphs as drawn - * @height: height of the glyphs as drawn - * @x_advance:distance to advance in the X direction - * after drawing these glyphs - * @y_advance: distance to advance in the Y direction - * after drawing these glyphs. Will typically be zero except - * for vertical text layout as found in East-Asian languages. - * - * The #cairo_text_extents_t structure stores the extents of a single - * glyph or a string of glyphs in user-space coordinates. Because text - * extents are in user-space coordinates, they are mostly, but not - * entirely, independent of the current transformation matrix. If you call - * cairo_scale(cr, 2.0, 2.0), text will - * be drawn twice as big, but the reported text extents will not be - * doubled. They will change slightly due to hinting (so you can't - * assume that metrics are independent of the transformation matrix), - * but otherwise will remain unchanged. - * - * Since: 1.0 - **/ -typedef struct { - double x_bearing; - double y_bearing; - double width; - double height; - double x_advance; - double y_advance; -} cairo_text_extents_t; - -/** - * cairo_font_extents_t: - * @ascent: the distance that the font extends above the baseline. - * Note that this is not always exactly equal to the maximum - * of the extents of all the glyphs in the font, but rather - * is picked to express the font designer's intent as to - * how the font should align with elements above it. - * @descent: the distance that the font extends below the baseline. - * This value is positive for typical fonts that include - * portions below the baseline. Note that this is not always - * exactly equal to the maximum of the extents of all the - * glyphs in the font, but rather is picked to express the - * font designer's intent as to how the font should - * align with elements below it. - * @height: the recommended vertical distance between baselines when - * setting consecutive lines of text with the font. This - * is greater than @ascent+@descent by a - * quantity known as the line spacing - * or external leading. When space - * is at a premium, most fonts can be set with only - * a distance of @ascent+@descent between lines. - * @max_x_advance: the maximum distance in the X direction that - * the origin is advanced for any glyph in the font. - * @max_y_advance: the maximum distance in the Y direction that - * the origin is advanced for any glyph in the font. - * This will be zero for normal fonts used for horizontal - * writing. (The scripts of East Asia are sometimes written - * vertically.) - * - * The #cairo_font_extents_t structure stores metric information for - * a font. Values are given in the current user-space coordinate - * system. - * - * Because font metrics are in user-space coordinates, they are - * mostly, but not entirely, independent of the current transformation - * matrix. If you call cairo_scale(cr, 2.0, 2.0), - * text will be drawn twice as big, but the reported text extents will - * not be doubled. They will change slightly due to hinting (so you - * can't assume that metrics are independent of the transformation - * matrix), but otherwise will remain unchanged. - * - * Since: 1.0 - **/ -typedef struct { - double ascent; - double descent; - double height; - double max_x_advance; - double max_y_advance; -} cairo_font_extents_t; - -/** - * cairo_font_slant_t: - * @CAIRO_FONT_SLANT_NORMAL: Upright font style, since 1.0 - * @CAIRO_FONT_SLANT_ITALIC: Italic font style, since 1.0 - * @CAIRO_FONT_SLANT_OBLIQUE: Oblique font style, since 1.0 - * - * Specifies variants of a font face based on their slant. - * - * Since: 1.0 - **/ -typedef enum _cairo_font_slant { - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_SLANT_ITALIC, - CAIRO_FONT_SLANT_OBLIQUE -} cairo_font_slant_t; - -/** - * cairo_font_weight_t: - * @CAIRO_FONT_WEIGHT_NORMAL: Normal font weight, since 1.0 - * @CAIRO_FONT_WEIGHT_BOLD: Bold font weight, since 1.0 - * - * Specifies variants of a font face based on their weight. - * - * Since: 1.0 - **/ -typedef enum _cairo_font_weight { - CAIRO_FONT_WEIGHT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD -} cairo_font_weight_t; - -/** - * cairo_subpixel_order_t: - * @CAIRO_SUBPIXEL_ORDER_DEFAULT: Use the default subpixel order for - * for the target device, since 1.0 - * @CAIRO_SUBPIXEL_ORDER_RGB: Subpixel elements are arranged horizontally - * with red at the left, since 1.0 - * @CAIRO_SUBPIXEL_ORDER_BGR: Subpixel elements are arranged horizontally - * with blue at the left, since 1.0 - * @CAIRO_SUBPIXEL_ORDER_VRGB: Subpixel elements are arranged vertically - * with red at the top, since 1.0 - * @CAIRO_SUBPIXEL_ORDER_VBGR: Subpixel elements are arranged vertically - * with blue at the top, since 1.0 - * - * The subpixel order specifies the order of color elements within - * each pixel on the display device when rendering with an - * antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL. - * - * Since: 1.0 - **/ -typedef enum _cairo_subpixel_order { - CAIRO_SUBPIXEL_ORDER_DEFAULT, - CAIRO_SUBPIXEL_ORDER_RGB, - CAIRO_SUBPIXEL_ORDER_BGR, - CAIRO_SUBPIXEL_ORDER_VRGB, - CAIRO_SUBPIXEL_ORDER_VBGR -} cairo_subpixel_order_t; - -/** - * cairo_hint_style_t: - * @CAIRO_HINT_STYLE_DEFAULT: Use the default hint style for - * font backend and target device, since 1.0 - * @CAIRO_HINT_STYLE_NONE: Do not hint outlines, since 1.0 - * @CAIRO_HINT_STYLE_SLIGHT: Hint outlines slightly to improve - * contrast while retaining good fidelity to the original - * shapes, since 1.0 - * @CAIRO_HINT_STYLE_MEDIUM: Hint outlines with medium strength - * giving a compromise between fidelity to the original shapes - * and contrast, since 1.0 - * @CAIRO_HINT_STYLE_FULL: Hint outlines to maximize contrast, since 1.0 - * - * Specifies the type of hinting to do on font outlines. Hinting - * is the process of fitting outlines to the pixel grid in order - * to improve the appearance of the result. Since hinting outlines - * involves distorting them, it also reduces the faithfulness - * to the original outline shapes. Not all of the outline hinting - * styles are supported by all font backends. - * - * New entries may be added in future versions. - * - * Since: 1.0 - **/ -typedef enum _cairo_hint_style { - CAIRO_HINT_STYLE_DEFAULT, - CAIRO_HINT_STYLE_NONE, - CAIRO_HINT_STYLE_SLIGHT, - CAIRO_HINT_STYLE_MEDIUM, - CAIRO_HINT_STYLE_FULL -} cairo_hint_style_t; - -/** - * cairo_hint_metrics_t: - * @CAIRO_HINT_METRICS_DEFAULT: Hint metrics in the default - * manner for the font backend and target device, since 1.0 - * @CAIRO_HINT_METRICS_OFF: Do not hint font metrics, since 1.0 - * @CAIRO_HINT_METRICS_ON: Hint font metrics, since 1.0 - * - * Specifies whether to hint font metrics; hinting font metrics - * means quantizing them so that they are integer values in - * device space. Doing this improves the consistency of - * letter and line spacing, however it also means that text - * will be laid out differently at different zoom factors. - * - * Since: 1.0 - **/ -typedef enum _cairo_hint_metrics { - CAIRO_HINT_METRICS_DEFAULT, - CAIRO_HINT_METRICS_OFF, - CAIRO_HINT_METRICS_ON -} cairo_hint_metrics_t; - -/** - * cairo_font_options_t: - * - * An opaque structure holding all options that are used when - * rendering fonts. - * - * Individual features of a #cairo_font_options_t can be set or - * accessed using functions named - * cairo_font_options_set_feature_name() and - * cairo_font_options_get_feature_name(), like - * cairo_font_options_set_antialias() and - * cairo_font_options_get_antialias(). - * - * New features may be added to a #cairo_font_options_t in the - * future. For this reason, cairo_font_options_copy(), - * cairo_font_options_equal(), cairo_font_options_merge(), and - * cairo_font_options_hash() should be used to copy, check - * for equality, merge, or compute a hash value of - * #cairo_font_options_t objects. - * - * Since: 1.0 - **/ -typedef struct _cairo_font_options cairo_font_options_t; - -cairo_public cairo_font_options_t * -cairo_font_options_create (void); - -cairo_public cairo_font_options_t * -cairo_font_options_copy (const cairo_font_options_t *original); - -cairo_public void -cairo_font_options_destroy (cairo_font_options_t *options); - -cairo_public cairo_status_t -cairo_font_options_status (cairo_font_options_t *options); - -cairo_public void -cairo_font_options_merge (cairo_font_options_t *options, - const cairo_font_options_t *other); -cairo_public cairo_bool_t -cairo_font_options_equal (const cairo_font_options_t *options, - const cairo_font_options_t *other); - -cairo_public unsigned long -cairo_font_options_hash (const cairo_font_options_t *options); - -cairo_public void -cairo_font_options_set_antialias (cairo_font_options_t *options, - cairo_antialias_t antialias); -cairo_public cairo_antialias_t -cairo_font_options_get_antialias (const cairo_font_options_t *options); - -cairo_public void -cairo_font_options_set_subpixel_order (cairo_font_options_t *options, - cairo_subpixel_order_t subpixel_order); -cairo_public cairo_subpixel_order_t -cairo_font_options_get_subpixel_order (const cairo_font_options_t *options); - -cairo_public void -cairo_font_options_set_hint_style (cairo_font_options_t *options, - cairo_hint_style_t hint_style); -cairo_public cairo_hint_style_t -cairo_font_options_get_hint_style (const cairo_font_options_t *options); - -cairo_public void -cairo_font_options_set_hint_metrics (cairo_font_options_t *options, - cairo_hint_metrics_t hint_metrics); -cairo_public cairo_hint_metrics_t -cairo_font_options_get_hint_metrics (const cairo_font_options_t *options); - -/* This interface is for dealing with text as text, not caring about the - font object inside the the cairo_t. */ - -cairo_public void -cairo_select_font_face (cairo_t *cr, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight); - -cairo_public void -cairo_set_font_size (cairo_t *cr, double size); - -cairo_public void -cairo_set_font_matrix (cairo_t *cr, - const cairo_matrix_t *matrix); - -cairo_public void -cairo_get_font_matrix (cairo_t *cr, - cairo_matrix_t *matrix); - -cairo_public void -cairo_set_font_options (cairo_t *cr, - const cairo_font_options_t *options); - -cairo_public void -cairo_get_font_options (cairo_t *cr, - cairo_font_options_t *options); - -cairo_public void -cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face); - -cairo_public cairo_font_face_t * -cairo_get_font_face (cairo_t *cr); - -cairo_public void -cairo_set_scaled_font (cairo_t *cr, - const cairo_scaled_font_t *scaled_font); - -cairo_public cairo_scaled_font_t * -cairo_get_scaled_font (cairo_t *cr); - -cairo_public void -cairo_show_text (cairo_t *cr, const char *utf8); - -cairo_public void -cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs); - -cairo_public void -cairo_show_text_glyphs (cairo_t *cr, - const char *utf8, - int utf8_len, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags); - -cairo_public void -cairo_text_path (cairo_t *cr, const char *utf8); - -cairo_public void -cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs); - -cairo_public void -cairo_text_extents (cairo_t *cr, - const char *utf8, - cairo_text_extents_t *extents); - -cairo_public void -cairo_glyph_extents (cairo_t *cr, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents); - -cairo_public void -cairo_font_extents (cairo_t *cr, - cairo_font_extents_t *extents); - -/* Generic identifier for a font style */ - -cairo_public cairo_font_face_t * -cairo_font_face_reference (cairo_font_face_t *font_face); - -cairo_public void -cairo_font_face_destroy (cairo_font_face_t *font_face); - -cairo_public unsigned int -cairo_font_face_get_reference_count (cairo_font_face_t *font_face); - -cairo_public cairo_status_t -cairo_font_face_status (cairo_font_face_t *font_face); - - -/** - * cairo_font_type_t: - * @CAIRO_FONT_TYPE_TOY: The font was created using cairo's toy font api (Since: 1.2) - * @CAIRO_FONT_TYPE_FT: The font is of type FreeType (Since: 1.2) - * @CAIRO_FONT_TYPE_WIN32: The font is of type Win32 (Since: 1.2) - * @CAIRO_FONT_TYPE_QUARTZ: The font is of type Quartz (Since: 1.6, in 1.2 and - * 1.4 it was named CAIRO_FONT_TYPE_ATSUI) - * @CAIRO_FONT_TYPE_USER: The font was create using cairo's user font api (Since: 1.8) - * - * #cairo_font_type_t is used to describe the type of a given font - * face or scaled font. The font types are also known as "font - * backends" within cairo. - * - * The type of a font face is determined by the function used to - * create it, which will generally be of the form - * cairo_type_font_face_create(). - * The font face type can be queried with cairo_font_face_get_type() - * - * The various #cairo_font_face_t functions can be used with a font face - * of any type. - * - * The type of a scaled font is determined by the type of the font - * face passed to cairo_scaled_font_create(). The scaled font type can - * be queried with cairo_scaled_font_get_type() - * - * The various #cairo_scaled_font_t functions can be used with scaled - * fonts of any type, but some font backends also provide - * type-specific functions that must only be called with a scaled font - * of the appropriate type. These functions have names that begin with - * cairo_type_scaled_font() - * such as cairo_ft_scaled_font_lock_face(). - * - * The behavior of calling a type-specific function with a scaled font - * of the wrong type is undefined. - * - * New entries may be added in future versions. - * - * Since: 1.2 - **/ -typedef enum _cairo_font_type { - CAIRO_FONT_TYPE_TOY, - CAIRO_FONT_TYPE_FT, - CAIRO_FONT_TYPE_WIN32, - CAIRO_FONT_TYPE_QUARTZ, - CAIRO_FONT_TYPE_USER -} cairo_font_type_t; - -cairo_public cairo_font_type_t -cairo_font_face_get_type (cairo_font_face_t *font_face); - -cairo_public void * -cairo_font_face_get_user_data (cairo_font_face_t *font_face, - const cairo_user_data_key_t *key); - -cairo_public cairo_status_t -cairo_font_face_set_user_data (cairo_font_face_t *font_face, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - -/* Portable interface to general font features. */ - -cairo_public cairo_scaled_font_t * -cairo_scaled_font_create (cairo_font_face_t *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options); - -cairo_public cairo_scaled_font_t * -cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font); - -cairo_public void -cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font); - -cairo_public unsigned int -cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font); - -cairo_public cairo_status_t -cairo_scaled_font_status (cairo_scaled_font_t *scaled_font); - -cairo_public cairo_font_type_t -cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font); - -cairo_public void * -cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font, - const cairo_user_data_key_t *key); - -cairo_public cairo_status_t -cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - -cairo_public void -cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, - cairo_font_extents_t *extents); - -cairo_public void -cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, - const char *utf8, - cairo_text_extents_t *extents); - -cairo_public void -cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_text_extents_t *extents); - -cairo_public cairo_status_t -cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font, - double x, - double y, - const char *utf8, - int utf8_len, - cairo_glyph_t **glyphs, - int *num_glyphs, - cairo_text_cluster_t **clusters, - int *num_clusters, - cairo_text_cluster_flags_t *cluster_flags); - -cairo_public cairo_font_face_t * -cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font); - -cairo_public void -cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *font_matrix); - -cairo_public void -cairo_scaled_font_get_ctm (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *ctm); - -cairo_public void -cairo_scaled_font_get_scale_matrix (cairo_scaled_font_t *scaled_font, - cairo_matrix_t *scale_matrix); - -cairo_public void -cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font, - cairo_font_options_t *options); - - -/* Toy fonts */ - -cairo_public cairo_font_face_t * -cairo_toy_font_face_create (const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight); - -cairo_public const char * -cairo_toy_font_face_get_family (cairo_font_face_t *font_face); - -cairo_public cairo_font_slant_t -cairo_toy_font_face_get_slant (cairo_font_face_t *font_face); - -cairo_public cairo_font_weight_t -cairo_toy_font_face_get_weight (cairo_font_face_t *font_face); - - -/* User fonts */ - -cairo_public cairo_font_face_t * -cairo_user_font_face_create (void); - -/* User-font method signatures */ - -/** - * cairo_user_scaled_font_init_func_t: - * @scaled_font: the scaled-font being created - * @cr: a cairo context, in font space - * @extents: font extents to fill in, in font space - * - * #cairo_user_scaled_font_init_func_t is the type of function which is - * called when a scaled-font needs to be created for a user font-face. - * - * The cairo context @cr is not used by the caller, but is prepared in font - * space, similar to what the cairo contexts passed to the render_glyph - * method will look like. The callback can use this context for extents - * computation for example. After the callback is called, @cr is checked - * for any error status. - * - * The @extents argument is where the user font sets the font extents for - * @scaled_font. It is in font space, which means that for most cases its - * ascent and descent members should add to 1.0. @extents is preset to - * hold a value of 1.0 for ascent, height, and max_x_advance, and 0.0 for - * descent and max_y_advance members. - * - * The callback is optional. If not set, default font extents as described - * in the previous paragraph will be used. - * - * Note that @scaled_font is not fully initialized at this - * point and trying to use it for text operations in the callback will result - * in deadlock. - * - * Returns: %CAIRO_STATUS_SUCCESS upon success, or an error status on error. - * - * Since: 1.8 - **/ -typedef cairo_status_t (*cairo_user_scaled_font_init_func_t) (cairo_scaled_font_t *scaled_font, - cairo_t *cr, - cairo_font_extents_t *extents); - -/** - * cairo_user_scaled_font_render_glyph_func_t: - * @scaled_font: user scaled-font - * @glyph: glyph code to render - * @cr: cairo context to draw to, in font space - * @extents: glyph extents to fill in, in font space - * - * #cairo_user_scaled_font_render_glyph_func_t is the type of function which - * is called when a user scaled-font needs to render a glyph. - * - * The callback is mandatory, and expected to draw the glyph with code @glyph to - * the cairo context @cr. @cr is prepared such that the glyph drawing is done in - * font space. That is, the matrix set on @cr is the scale matrix of @scaled_font, - * The @extents argument is where the user font sets the font extents for - * @scaled_font. However, if user prefers to draw in user space, they can - * achieve that by changing the matrix on @cr. All cairo rendering operations - * to @cr are permitted, however, the result is undefined if any source other - * than the default source on @cr is used. That means, glyph bitmaps should - * be rendered using cairo_mask() instead of cairo_paint(). - * - * Other non-default settings on @cr include a font size of 1.0 (given that - * it is set up to be in font space), and font options corresponding to - * @scaled_font. - * - * The @extents argument is preset to have x_bearing, - * width, and y_advance of zero, - * y_bearing set to -font_extents.ascent, - * height to font_extents.ascent+font_extents.descent, - * and x_advance to font_extents.max_x_advance. - * The only field user needs to set in majority of cases is - * x_advance. - * If the width field is zero upon the callback returning - * (which is its preset value), the glyph extents are automatically computed - * based on the drawings done to @cr. This is in most cases exactly what the - * desired behavior is. However, if for any reason the callback sets the - * extents, it must be ink extents, and include the extents of all drawing - * done to @cr in the callback. - * - * Returns: %CAIRO_STATUS_SUCCESS upon success, or - * %CAIRO_STATUS_USER_FONT_ERROR or any other error status on error. - * - * Since: 1.8 - **/ -typedef cairo_status_t (*cairo_user_scaled_font_render_glyph_func_t) (cairo_scaled_font_t *scaled_font, - unsigned long glyph, - cairo_t *cr, - cairo_text_extents_t *extents); - -/** - * cairo_user_scaled_font_text_to_glyphs_func_t: - * @scaled_font: the scaled-font being created - * @utf8: a string of text encoded in UTF-8 - * @utf8_len: length of @utf8 in bytes - * @glyphs: pointer to array of glyphs to fill, in font space - * @num_glyphs: pointer to number of glyphs - * @clusters: pointer to array of cluster mapping information to fill, or %NULL - * @num_clusters: pointer to number of clusters - * @cluster_flags: pointer to location to store cluster flags corresponding to the - * output @clusters - * - * #cairo_user_scaled_font_text_to_glyphs_func_t is the type of function which - * is called to convert input text to an array of glyphs. This is used by the - * cairo_show_text() operation. - * - * Using this callback the user-font has full control on glyphs and their - * positions. That means, it allows for features like ligatures and kerning, - * as well as complex shaping required for scripts like - * Arabic and Indic. - * - * The @num_glyphs argument is preset to the number of glyph entries available - * in the @glyphs buffer. If the @glyphs buffer is %NULL, the value of - * @num_glyphs will be zero. If the provided glyph array is too short for - * the conversion (or for convenience), a new glyph array may be allocated - * using cairo_glyph_allocate() and placed in @glyphs. Upon return, - * @num_glyphs should contain the number of generated glyphs. If the value - * @glyphs points at has changed after the call, the caller will free the - * allocated glyph array using cairo_glyph_free(). The caller will also free - * the original value of @glyphs, so the callback shouldn't do so. - * The callback should populate the glyph indices and positions (in font space) - * assuming that the text is to be shown at the origin. - * - * If @clusters is not %NULL, @num_clusters and @cluster_flags are also - * non-%NULL, and cluster mapping should be computed. The semantics of how - * cluster array allocation works is similar to the glyph array. That is, - * if @clusters initially points to a non-%NULL value, that array may be used - * as a cluster buffer, and @num_clusters points to the number of cluster - * entries available there. If the provided cluster array is too short for - * the conversion (or for convenience), a new cluster array may be allocated - * using cairo_text_cluster_allocate() and placed in @clusters. In this case, - * the original value of @clusters will still be freed by the caller. Upon - * return, @num_clusters should contain the number of generated clusters. - * If the value @clusters points at has changed after the call, the caller - * will free the allocated cluster array using cairo_text_cluster_free(). - * - * The callback is optional. If @num_glyphs is negative upon - * the callback returning or if the return value - * is %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, the unicode_to_glyph callback - * is tried. See #cairo_user_scaled_font_unicode_to_glyph_func_t. - * - * Note: While cairo does not impose any limitation on glyph indices, - * some applications may assume that a glyph index fits in a 16-bit - * unsigned integer. As such, it is advised that user-fonts keep their - * glyphs in the 0 to 65535 range. Furthermore, some applications may - * assume that glyph 0 is a special glyph-not-found glyph. User-fonts - * are advised to use glyph 0 for such purposes and do not use that - * glyph value for other purposes. - * - * Returns: %CAIRO_STATUS_SUCCESS upon success, - * %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED if fallback options should be tried, - * or %CAIRO_STATUS_USER_FONT_ERROR or any other error status on error. - * - * Since: 1.8 - **/ -typedef cairo_status_t (*cairo_user_scaled_font_text_to_glyphs_func_t) (cairo_scaled_font_t *scaled_font, - const char *utf8, - int utf8_len, - cairo_glyph_t **glyphs, - int *num_glyphs, - cairo_text_cluster_t **clusters, - int *num_clusters, - cairo_text_cluster_flags_t *cluster_flags); - -/** - * cairo_user_scaled_font_unicode_to_glyph_func_t: - * @scaled_font: the scaled-font being created - * @unicode: input unicode character code-point - * @glyph_index: output glyph index - * - * #cairo_user_scaled_font_unicode_to_glyph_func_t is the type of function which - * is called to convert an input Unicode character to a single glyph. - * This is used by the cairo_show_text() operation. - * - * This callback is used to provide the same functionality as the - * text_to_glyphs callback does (see #cairo_user_scaled_font_text_to_glyphs_func_t) - * but has much less control on the output, - * in exchange for increased ease of use. The inherent assumption to using - * this callback is that each character maps to one glyph, and that the - * mapping is context independent. It also assumes that glyphs are positioned - * according to their advance width. These mean no ligatures, kerning, or - * complex scripts can be implemented using this callback. - * - * The callback is optional, and only used if text_to_glyphs callback is not - * set or fails to return glyphs. If this callback is not set or if it returns - * %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, an identity mapping from Unicode - * code-points to glyph indices is assumed. - * - * Note: While cairo does not impose any limitation on glyph indices, - * some applications may assume that a glyph index fits in a 16-bit - * unsigned integer. As such, it is advised that user-fonts keep their - * glyphs in the 0 to 65535 range. Furthermore, some applications may - * assume that glyph 0 is a special glyph-not-found glyph. User-fonts - * are advised to use glyph 0 for such purposes and do not use that - * glyph value for other purposes. - * - * Returns: %CAIRO_STATUS_SUCCESS upon success, - * %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED if fallback options should be tried, - * or %CAIRO_STATUS_USER_FONT_ERROR or any other error status on error. - * - * Since: 1.8 - **/ -typedef cairo_status_t (*cairo_user_scaled_font_unicode_to_glyph_func_t) (cairo_scaled_font_t *scaled_font, - unsigned long unicode, - unsigned long *glyph_index); - -/* User-font method setters */ - -cairo_public void -cairo_user_font_face_set_init_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_init_func_t init_func); - -cairo_public void -cairo_user_font_face_set_render_glyph_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_render_glyph_func_t render_glyph_func); - -cairo_public void -cairo_user_font_face_set_text_to_glyphs_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_text_to_glyphs_func_t text_to_glyphs_func); - -cairo_public void -cairo_user_font_face_set_unicode_to_glyph_func (cairo_font_face_t *font_face, - cairo_user_scaled_font_unicode_to_glyph_func_t unicode_to_glyph_func); - -/* User-font method getters */ - -cairo_public cairo_user_scaled_font_init_func_t -cairo_user_font_face_get_init_func (cairo_font_face_t *font_face); - -cairo_public cairo_user_scaled_font_render_glyph_func_t -cairo_user_font_face_get_render_glyph_func (cairo_font_face_t *font_face); - -cairo_public cairo_user_scaled_font_text_to_glyphs_func_t -cairo_user_font_face_get_text_to_glyphs_func (cairo_font_face_t *font_face); - -cairo_public cairo_user_scaled_font_unicode_to_glyph_func_t -cairo_user_font_face_get_unicode_to_glyph_func (cairo_font_face_t *font_face); - - -/* Query functions */ - -cairo_public cairo_operator_t -cairo_get_operator (cairo_t *cr); - -cairo_public cairo_pattern_t * -cairo_get_source (cairo_t *cr); - -cairo_public double -cairo_get_tolerance (cairo_t *cr); - -cairo_public cairo_antialias_t -cairo_get_antialias (cairo_t *cr); - -cairo_public cairo_bool_t -cairo_has_current_point (cairo_t *cr); - -cairo_public void -cairo_get_current_point (cairo_t *cr, double *x, double *y); - -cairo_public cairo_fill_rule_t -cairo_get_fill_rule (cairo_t *cr); - -cairo_public double -cairo_get_line_width (cairo_t *cr); - -cairo_public cairo_line_cap_t -cairo_get_line_cap (cairo_t *cr); - -cairo_public cairo_line_join_t -cairo_get_line_join (cairo_t *cr); - -cairo_public double -cairo_get_miter_limit (cairo_t *cr); - -cairo_public int -cairo_get_dash_count (cairo_t *cr); - -cairo_public void -cairo_get_dash (cairo_t *cr, double *dashes, double *offset); - -cairo_public void -cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix); - -cairo_public cairo_surface_t * -cairo_get_target (cairo_t *cr); - -cairo_public cairo_surface_t * -cairo_get_group_target (cairo_t *cr); - -/** - * cairo_path_data_type_t: - * @CAIRO_PATH_MOVE_TO: A move-to operation, since 1.0 - * @CAIRO_PATH_LINE_TO: A line-to operation, since 1.0 - * @CAIRO_PATH_CURVE_TO: A curve-to operation, since 1.0 - * @CAIRO_PATH_CLOSE_PATH: A close-path operation, since 1.0 - * - * #cairo_path_data_t is used to describe the type of one portion - * of a path when represented as a #cairo_path_t. - * See #cairo_path_data_t for details. - * - * Since: 1.0 - **/ -typedef enum _cairo_path_data_type { - CAIRO_PATH_MOVE_TO, - CAIRO_PATH_LINE_TO, - CAIRO_PATH_CURVE_TO, - CAIRO_PATH_CLOSE_PATH -} cairo_path_data_type_t; - -/** - * cairo_path_data_t: - * - * #cairo_path_data_t is used to represent the path data inside a - * #cairo_path_t. - * - * The data structure is designed to try to balance the demands of - * efficiency and ease-of-use. A path is represented as an array of - * #cairo_path_data_t, which is a union of headers and points. - * - * Each portion of the path is represented by one or more elements in - * the array, (one header followed by 0 or more points). The length - * value of the header is the number of array elements for the current - * portion including the header, (ie. length == 1 + # of points), and - * where the number of points for each element type is as follows: - * - * - * %CAIRO_PATH_MOVE_TO: 1 point - * %CAIRO_PATH_LINE_TO: 1 point - * %CAIRO_PATH_CURVE_TO: 3 points - * %CAIRO_PATH_CLOSE_PATH: 0 points - * - * - * The semantics and ordering of the coordinate values are consistent - * with cairo_move_to(), cairo_line_to(), cairo_curve_to(), and - * cairo_close_path(). - * - * Here is sample code for iterating through a #cairo_path_t: - * - * - * int i; - * cairo_path_t *path; - * cairo_path_data_t *data; - *   - * path = cairo_copy_path (cr); - *   - * for (i=0; i < path->num_data; i += path->data[i].header.length) { - * data = &path->data[i]; - * switch (data->header.type) { - * case CAIRO_PATH_MOVE_TO: - * do_move_to_things (data[1].point.x, data[1].point.y); - * break; - * case CAIRO_PATH_LINE_TO: - * do_line_to_things (data[1].point.x, data[1].point.y); - * break; - * case CAIRO_PATH_CURVE_TO: - * do_curve_to_things (data[1].point.x, data[1].point.y, - * data[2].point.x, data[2].point.y, - * data[3].point.x, data[3].point.y); - * break; - * case CAIRO_PATH_CLOSE_PATH: - * do_close_path_things (); - * break; - * } - * } - * cairo_path_destroy (path); - * - * - * As of cairo 1.4, cairo does not mind if there are more elements in - * a portion of the path than needed. Such elements can be used by - * users of the cairo API to hold extra values in the path data - * structure. For this reason, it is recommended that applications - * always use data->header.length to - * iterate over the path data, instead of hardcoding the number of - * elements for each element type. - * - * Since: 1.0 - **/ -typedef union _cairo_path_data_t cairo_path_data_t; -union _cairo_path_data_t { - struct { - cairo_path_data_type_t type; - int length; - } header; - struct { - double x, y; - } point; -}; - -/** - * cairo_path_t: - * @status: the current error status - * @data: the elements in the path - * @num_data: the number of elements in the data array - * - * A data structure for holding a path. This data structure serves as - * the return value for cairo_copy_path() and - * cairo_copy_path_flat() as well the input value for - * cairo_append_path(). - * - * See #cairo_path_data_t for hints on how to iterate over the - * actual data within the path. - * - * The num_data member gives the number of elements in the data - * array. This number is larger than the number of independent path - * portions (defined in #cairo_path_data_type_t), since the data - * includes both headers and coordinates for each portion. - * - * Since: 1.0 - **/ -typedef struct cairo_path { - cairo_status_t status; - cairo_path_data_t *data; - int num_data; -} cairo_path_t; - -cairo_public cairo_path_t * -cairo_copy_path (cairo_t *cr); - -cairo_public cairo_path_t * -cairo_copy_path_flat (cairo_t *cr); - -cairo_public void -cairo_append_path (cairo_t *cr, - const cairo_path_t *path); - -cairo_public void -cairo_path_destroy (cairo_path_t *path); - -/* Error status queries */ - -cairo_public cairo_status_t -cairo_status (cairo_t *cr); - -cairo_public const char * -cairo_status_to_string (cairo_status_t status); - -/* Backend device manipulation */ - -cairo_public cairo_device_t * -cairo_device_reference (cairo_device_t *device); - -/** - * cairo_device_type_t: - * @CAIRO_DEVICE_TYPE_DRM: The device is of type Direct Render Manager, since 1.10 - * @CAIRO_DEVICE_TYPE_GL: The device is of type OpenGL, since 1.10 - * @CAIRO_DEVICE_TYPE_SCRIPT: The device is of type script, since 1.10 - * @CAIRO_DEVICE_TYPE_XCB: The device is of type xcb, since 1.10 - * @CAIRO_DEVICE_TYPE_XLIB: The device is of type xlib, since 1.10 - * @CAIRO_DEVICE_TYPE_XML: The device is of type XML, since 1.10 - * @CAIRO_DEVICE_TYPE_COGL: The device is of type cogl, since 1.12 - * @CAIRO_DEVICE_TYPE_WIN32: The device is of type win32, since 1.12 - * @CAIRO_DEVICE_TYPE_INVALID: The device is invalid, since 1.10 - * - * #cairo_device_type_t is used to describe the type of a given - * device. The devices types are also known as "backends" within cairo. - * - * The device type can be queried with cairo_device_get_type() - * - * The various #cairo_device_t functions can be used with devices of - * any type, but some backends also provide type-specific functions - * that must only be called with a device of the appropriate - * type. These functions have names that begin with - * cairo_type_device such as - * cairo_xcb_device_debug_cap_xrender_version(). - * - * The behavior of calling a type-specific function with a device of - * the wrong type is undefined. - * - * New entries may be added in future versions. - * - * Since: 1.10 - **/ -typedef enum _cairo_device_type { - CAIRO_DEVICE_TYPE_DRM, - CAIRO_DEVICE_TYPE_GL, - CAIRO_DEVICE_TYPE_SCRIPT, - CAIRO_DEVICE_TYPE_XCB, - CAIRO_DEVICE_TYPE_XLIB, - CAIRO_DEVICE_TYPE_XML, - CAIRO_DEVICE_TYPE_COGL, - CAIRO_DEVICE_TYPE_WIN32, - - CAIRO_DEVICE_TYPE_INVALID = -1 -} cairo_device_type_t; - -cairo_public cairo_device_type_t -cairo_device_get_type (cairo_device_t *device); - -cairo_public cairo_status_t -cairo_device_status (cairo_device_t *device); - -cairo_public cairo_status_t -cairo_device_acquire (cairo_device_t *device); - -cairo_public void -cairo_device_release (cairo_device_t *device); - -cairo_public void -cairo_device_flush (cairo_device_t *device); - -cairo_public void -cairo_device_finish (cairo_device_t *device); - -cairo_public void -cairo_device_destroy (cairo_device_t *device); - -cairo_public unsigned int -cairo_device_get_reference_count (cairo_device_t *device); - -cairo_public void * -cairo_device_get_user_data (cairo_device_t *device, - const cairo_user_data_key_t *key); - -cairo_public cairo_status_t -cairo_device_set_user_data (cairo_device_t *device, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - - -/* Surface manipulation */ - -cairo_public cairo_surface_t * -cairo_surface_create_similar (cairo_surface_t *other, - cairo_content_t content, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_surface_create_similar_image (cairo_surface_t *other, - cairo_format_t format, - int width, - int height); - -cairo_public cairo_surface_t * -cairo_surface_map_to_image (cairo_surface_t *surface, - const cairo_rectangle_int_t *extents); - -cairo_public void -cairo_surface_unmap_image (cairo_surface_t *surface, - cairo_surface_t *image); - -cairo_public cairo_surface_t * -cairo_surface_create_for_rectangle (cairo_surface_t *target, - double x, - double y, - double width, - double height); - -/** - * cairo_surface_observer_mode_t: - * @CAIRO_SURFACE_OBSERVER_NORMAL: no recording is done - * @CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS: operations are recorded - * - * Whether operations should be recorded. - * - * Since: 1.12 - **/ -typedef enum { - CAIRO_SURFACE_OBSERVER_NORMAL = 0, - CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS = 0x1 -} cairo_surface_observer_mode_t; - -cairo_public cairo_surface_t * -cairo_surface_create_observer (cairo_surface_t *target, - cairo_surface_observer_mode_t mode); - -typedef void (*cairo_surface_observer_callback_t) (cairo_surface_t *observer, - cairo_surface_t *target, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_paint_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_mask_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_fill_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_stroke_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_glyphs_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_flush_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_add_finish_callback (cairo_surface_t *abstract_surface, - cairo_surface_observer_callback_t func, - void *data); - -cairo_public cairo_status_t -cairo_surface_observer_print (cairo_surface_t *surface, - cairo_write_func_t write_func, - void *closure); -cairo_public double -cairo_surface_observer_elapsed (cairo_surface_t *surface); - -cairo_public cairo_status_t -cairo_device_observer_print (cairo_device_t *device, - cairo_write_func_t write_func, - void *closure); - -cairo_public double -cairo_device_observer_elapsed (cairo_device_t *device); - -cairo_public double -cairo_device_observer_paint_elapsed (cairo_device_t *device); - -cairo_public double -cairo_device_observer_mask_elapsed (cairo_device_t *device); - -cairo_public double -cairo_device_observer_fill_elapsed (cairo_device_t *device); - -cairo_public double -cairo_device_observer_stroke_elapsed (cairo_device_t *device); - -cairo_public double -cairo_device_observer_glyphs_elapsed (cairo_device_t *device); - -cairo_public cairo_surface_t * -cairo_surface_reference (cairo_surface_t *surface); - -cairo_public void -cairo_surface_finish (cairo_surface_t *surface); - -cairo_public void -cairo_surface_destroy (cairo_surface_t *surface); - -cairo_public cairo_device_t * -cairo_surface_get_device (cairo_surface_t *surface); - -cairo_public unsigned int -cairo_surface_get_reference_count (cairo_surface_t *surface); - -cairo_public cairo_status_t -cairo_surface_status (cairo_surface_t *surface); - -/** - * cairo_surface_type_t: - * @CAIRO_SURFACE_TYPE_IMAGE: The surface is of type image, since 1.2 - * @CAIRO_SURFACE_TYPE_PDF: The surface is of type pdf, since 1.2 - * @CAIRO_SURFACE_TYPE_PS: The surface is of type ps, since 1.2 - * @CAIRO_SURFACE_TYPE_XLIB: The surface is of type xlib, since 1.2 - * @CAIRO_SURFACE_TYPE_XCB: The surface is of type xcb, since 1.2 - * @CAIRO_SURFACE_TYPE_GLITZ: The surface is of type glitz, since 1.2 - * @CAIRO_SURFACE_TYPE_QUARTZ: The surface is of type quartz, since 1.2 - * @CAIRO_SURFACE_TYPE_WIN32: The surface is of type win32, since 1.2 - * @CAIRO_SURFACE_TYPE_BEOS: The surface is of type beos, since 1.2 - * @CAIRO_SURFACE_TYPE_DIRECTFB: The surface is of type directfb, since 1.2 - * @CAIRO_SURFACE_TYPE_SVG: The surface is of type svg, since 1.2 - * @CAIRO_SURFACE_TYPE_OS2: The surface is of type os2, since 1.4 - * @CAIRO_SURFACE_TYPE_WIN32_PRINTING: The surface is a win32 printing surface, since 1.6 - * @CAIRO_SURFACE_TYPE_QUARTZ_IMAGE: The surface is of type quartz_image, since 1.6 - * @CAIRO_SURFACE_TYPE_SCRIPT: The surface is of type script, since 1.10 - * @CAIRO_SURFACE_TYPE_QT: The surface is of type Qt, since 1.10 - * @CAIRO_SURFACE_TYPE_RECORDING: The surface is of type recording, since 1.10 - * @CAIRO_SURFACE_TYPE_VG: The surface is a OpenVG surface, since 1.10 - * @CAIRO_SURFACE_TYPE_GL: The surface is of type OpenGL, since 1.10 - * @CAIRO_SURFACE_TYPE_DRM: The surface is of type Direct Render Manager, since 1.10 - * @CAIRO_SURFACE_TYPE_TEE: The surface is of type 'tee' (a multiplexing surface), since 1.10 - * @CAIRO_SURFACE_TYPE_XML: The surface is of type XML (for debugging), since 1.10 - * @CAIRO_SURFACE_TYPE_SKIA: The surface is of type Skia, since 1.10 - * @CAIRO_SURFACE_TYPE_SUBSURFACE: The surface is a subsurface created with - * cairo_surface_create_for_rectangle(), since 1.10 - * @CAIRO_SURFACE_TYPE_COGL: This surface is of type Cogl, since 1.12 - * - * #cairo_surface_type_t is used to describe the type of a given - * surface. The surface types are also known as "backends" or "surface - * backends" within cairo. - * - * The type of a surface is determined by the function used to create - * it, which will generally be of the form - * cairo_type_surface_create(), - * (though see cairo_surface_create_similar() as well). - * - * The surface type can be queried with cairo_surface_get_type() - * - * The various #cairo_surface_t functions can be used with surfaces of - * any type, but some backends also provide type-specific functions - * that must only be called with a surface of the appropriate - * type. These functions have names that begin with - * cairo_type_surface such as cairo_image_surface_get_width(). - * - * The behavior of calling a type-specific function with a surface of - * the wrong type is undefined. - * - * New entries may be added in future versions. - * - * Since: 1.2 - **/ -typedef enum _cairo_surface_type { - CAIRO_SURFACE_TYPE_IMAGE, - CAIRO_SURFACE_TYPE_PDF, - CAIRO_SURFACE_TYPE_PS, - CAIRO_SURFACE_TYPE_XLIB, - CAIRO_SURFACE_TYPE_XCB, - CAIRO_SURFACE_TYPE_GLITZ, - CAIRO_SURFACE_TYPE_QUARTZ, - CAIRO_SURFACE_TYPE_WIN32, - CAIRO_SURFACE_TYPE_BEOS, - CAIRO_SURFACE_TYPE_DIRECTFB, - CAIRO_SURFACE_TYPE_SVG, - CAIRO_SURFACE_TYPE_OS2, - CAIRO_SURFACE_TYPE_WIN32_PRINTING, - CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, - CAIRO_SURFACE_TYPE_SCRIPT, - CAIRO_SURFACE_TYPE_QT, - CAIRO_SURFACE_TYPE_RECORDING, - CAIRO_SURFACE_TYPE_VG, - CAIRO_SURFACE_TYPE_GL, - CAIRO_SURFACE_TYPE_DRM, - CAIRO_SURFACE_TYPE_TEE, - CAIRO_SURFACE_TYPE_XML, - CAIRO_SURFACE_TYPE_SKIA, - CAIRO_SURFACE_TYPE_SUBSURFACE, - CAIRO_SURFACE_TYPE_COGL -} cairo_surface_type_t; - -cairo_public cairo_surface_type_t -cairo_surface_get_type (cairo_surface_t *surface); - -cairo_public cairo_content_t -cairo_surface_get_content (cairo_surface_t *surface); - -#if CAIRO_HAS_PNG_FUNCTIONS - -cairo_public cairo_status_t -cairo_surface_write_to_png (cairo_surface_t *surface, - const char *filename); - -cairo_public cairo_status_t -cairo_surface_write_to_png_stream (cairo_surface_t *surface, - cairo_write_func_t write_func, - void *closure); - -#endif - -cairo_public void * -cairo_surface_get_user_data (cairo_surface_t *surface, - const cairo_user_data_key_t *key); - -cairo_public cairo_status_t -cairo_surface_set_user_data (cairo_surface_t *surface, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - -#define CAIRO_MIME_TYPE_JPEG "image/jpeg" -#define CAIRO_MIME_TYPE_PNG "image/png" -#define CAIRO_MIME_TYPE_JP2 "image/jp2" -#define CAIRO_MIME_TYPE_URI "text/x-uri" -#define CAIRO_MIME_TYPE_UNIQUE_ID "application/x-cairo.uuid" -#define CAIRO_MIME_TYPE_JBIG2 "application/x-cairo.jbig2" -#define CAIRO_MIME_TYPE_JBIG2_GLOBAL "application/x-cairo.jbig2-global" -#define CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID "application/x-cairo.jbig2-global-id" - -cairo_public void -cairo_surface_get_mime_data (cairo_surface_t *surface, - const char *mime_type, - const unsigned char **data, - unsigned long *length); - -cairo_public cairo_status_t -cairo_surface_set_mime_data (cairo_surface_t *surface, - const char *mime_type, - const unsigned char *data, - unsigned long length, - cairo_destroy_func_t destroy, - void *closure); - -cairo_public cairo_bool_t -cairo_surface_supports_mime_type (cairo_surface_t *surface, - const char *mime_type); - -cairo_public void -cairo_surface_get_font_options (cairo_surface_t *surface, - cairo_font_options_t *options); - -cairo_public void -cairo_surface_flush (cairo_surface_t *surface); - -cairo_public void -cairo_surface_mark_dirty (cairo_surface_t *surface); - -cairo_public void -cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, - int x, - int y, - int width, - int height); - -cairo_public void -cairo_surface_set_device_scale (cairo_surface_t *surface, - double x_scale, - double y_scale); - -cairo_public void -cairo_surface_get_device_scale (cairo_surface_t *surface, - double *x_scale, - double *y_scale); - -cairo_public void -cairo_surface_set_device_offset (cairo_surface_t *surface, - double x_offset, - double y_offset); - -cairo_public void -cairo_surface_get_device_offset (cairo_surface_t *surface, - double *x_offset, - double *y_offset); - -cairo_public void -cairo_surface_set_fallback_resolution (cairo_surface_t *surface, - double x_pixels_per_inch, - double y_pixels_per_inch); - -cairo_public void -cairo_surface_get_fallback_resolution (cairo_surface_t *surface, - double *x_pixels_per_inch, - double *y_pixels_per_inch); - -cairo_public void -cairo_surface_copy_page (cairo_surface_t *surface); - -cairo_public void -cairo_surface_show_page (cairo_surface_t *surface); - -cairo_public cairo_bool_t -cairo_surface_has_show_text_glyphs (cairo_surface_t *surface); - -/* Image-surface functions */ - -cairo_public cairo_surface_t * -cairo_image_surface_create (cairo_format_t format, - int width, - int height); - -cairo_public int -cairo_format_stride_for_width (cairo_format_t format, - int width); - -cairo_public cairo_surface_t * -cairo_image_surface_create_for_data (unsigned char *data, - cairo_format_t format, - int width, - int height, - int stride); - -cairo_public unsigned char * -cairo_image_surface_get_data (cairo_surface_t *surface); - -cairo_public cairo_format_t -cairo_image_surface_get_format (cairo_surface_t *surface); - -cairo_public int -cairo_image_surface_get_width (cairo_surface_t *surface); - -cairo_public int -cairo_image_surface_get_height (cairo_surface_t *surface); - -cairo_public int -cairo_image_surface_get_stride (cairo_surface_t *surface); - -#if CAIRO_HAS_PNG_FUNCTIONS - -cairo_public cairo_surface_t * -cairo_image_surface_create_from_png (const char *filename); - -cairo_public cairo_surface_t * -cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, - void *closure); - -#endif - -/* Recording-surface functions */ - -cairo_public cairo_surface_t * -cairo_recording_surface_create (cairo_content_t content, - const cairo_rectangle_t *extents); - -cairo_public void -cairo_recording_surface_ink_extents (cairo_surface_t *surface, - double *x0, - double *y0, - double *width, - double *height); - -cairo_public cairo_bool_t -cairo_recording_surface_get_extents (cairo_surface_t *surface, - cairo_rectangle_t *extents); - -/* raster-source pattern (callback) functions */ - -/** - * cairo_raster_source_acquire_func_t: - * @pattern: the pattern being rendered from - * @callback_data: the user data supplied during creation - * @target: the rendering target surface - * @extents: rectangular region of interest in pixels in sample space - * - * #cairo_raster_source_acquire_func_t is the type of function which is - * called when a pattern is being rendered from. It should create a surface - * that provides the pixel data for the region of interest as defined by - * extents, though the surface itself does not have to be limited to that - * area. For convenience the surface should probably be of image type, - * created with cairo_surface_create_similar_image() for the target (which - * enables the number of copies to be reduced during transfer to the - * device). Another option, might be to return a similar surface to the - * target for explicit handling by the application of a set of cached sources - * on the device. The region of sample data provided should be defined using - * cairo_surface_set_device_offset() to specify the top-left corner of the - * sample data (along with width and height of the surface). - * - * Returns: a #cairo_surface_t - * - * Since: 1.12 - **/ -typedef cairo_surface_t * -(*cairo_raster_source_acquire_func_t) (cairo_pattern_t *pattern, - void *callback_data, - cairo_surface_t *target, - const cairo_rectangle_int_t *extents); - -/** - * cairo_raster_source_release_func_t: - * @pattern: the pattern being rendered from - * @callback_data: the user data supplied during creation - * @surface: the surface created during acquire - * - * #cairo_raster_source_release_func_t is the type of function which is - * called when the pixel data is no longer being access by the pattern - * for the rendering operation. Typically this function will simply - * destroy the surface created during acquire. - * - * Since: 1.12 - **/ -typedef void -(*cairo_raster_source_release_func_t) (cairo_pattern_t *pattern, - void *callback_data, - cairo_surface_t *surface); - -/** - * cairo_raster_source_snapshot_func_t: - * @pattern: the pattern being rendered from - * @callback_data: the user data supplied during creation - * - * #cairo_raster_source_snapshot_func_t is the type of function which is - * called when the pixel data needs to be preserved for later use - * during printing. This pattern will be accessed again later, and it - * is expected to provide the pixel data that was current at the time - * of snapshotting. - * - * Return value: CAIRO_STATUS_SUCCESS on success, or one of the - * #cairo_status_t error codes for failure. - * - * Since: 1.12 - **/ -typedef cairo_status_t -(*cairo_raster_source_snapshot_func_t) (cairo_pattern_t *pattern, - void *callback_data); - -/** - * cairo_raster_source_copy_func_t: - * @pattern: the #cairo_pattern_t that was copied to - * @callback_data: the user data supplied during creation - * @other: the #cairo_pattern_t being used as the source for the copy - * - * #cairo_raster_source_copy_func_t is the type of function which is - * called when the pattern gets copied as a normal part of rendering. - * - * Return value: CAIRO_STATUS_SUCCESS on success, or one of the - * #cairo_status_t error codes for failure. - * - * Since: 1.12 - **/ -typedef cairo_status_t -(*cairo_raster_source_copy_func_t) (cairo_pattern_t *pattern, - void *callback_data, - const cairo_pattern_t *other); - -/** - * cairo_raster_source_finish_func_t: - * @pattern: the pattern being rendered from - * @callback_data: the user data supplied during creation - * - * #cairo_raster_source_finish_func_t is the type of function which is - * called when the pattern (or a copy thereof) is no longer required. - * - * Since: 1.12 - **/ -typedef void -(*cairo_raster_source_finish_func_t) (cairo_pattern_t *pattern, - void *callback_data); - -cairo_public cairo_pattern_t * -cairo_pattern_create_raster_source (void *user_data, - cairo_content_t content, - int width, int height); - -cairo_public void -cairo_raster_source_pattern_set_callback_data (cairo_pattern_t *pattern, - void *data); - -cairo_public void * -cairo_raster_source_pattern_get_callback_data (cairo_pattern_t *pattern); - -cairo_public void -cairo_raster_source_pattern_set_acquire (cairo_pattern_t *pattern, - cairo_raster_source_acquire_func_t acquire, - cairo_raster_source_release_func_t release); - -cairo_public void -cairo_raster_source_pattern_get_acquire (cairo_pattern_t *pattern, - cairo_raster_source_acquire_func_t *acquire, - cairo_raster_source_release_func_t *release); -cairo_public void -cairo_raster_source_pattern_set_snapshot (cairo_pattern_t *pattern, - cairo_raster_source_snapshot_func_t snapshot); - -cairo_public cairo_raster_source_snapshot_func_t -cairo_raster_source_pattern_get_snapshot (cairo_pattern_t *pattern); - -cairo_public void -cairo_raster_source_pattern_set_copy (cairo_pattern_t *pattern, - cairo_raster_source_copy_func_t copy); - -cairo_public cairo_raster_source_copy_func_t -cairo_raster_source_pattern_get_copy (cairo_pattern_t *pattern); - -cairo_public void -cairo_raster_source_pattern_set_finish (cairo_pattern_t *pattern, - cairo_raster_source_finish_func_t finish); - -cairo_public cairo_raster_source_finish_func_t -cairo_raster_source_pattern_get_finish (cairo_pattern_t *pattern); - -/* Pattern creation functions */ - -cairo_public cairo_pattern_t * -cairo_pattern_create_rgb (double red, double green, double blue); - -cairo_public cairo_pattern_t * -cairo_pattern_create_rgba (double red, double green, double blue, - double alpha); - -cairo_public cairo_pattern_t * -cairo_pattern_create_for_surface (cairo_surface_t *surface); - -cairo_public cairo_pattern_t * -cairo_pattern_create_linear (double x0, double y0, - double x1, double y1); - -cairo_public cairo_pattern_t * -cairo_pattern_create_radial (double cx0, double cy0, double radius0, - double cx1, double cy1, double radius1); - -cairo_public cairo_pattern_t * -cairo_pattern_create_mesh (void); - -cairo_public cairo_pattern_t * -cairo_pattern_reference (cairo_pattern_t *pattern); - -cairo_public void -cairo_pattern_destroy (cairo_pattern_t *pattern); - -cairo_public unsigned int -cairo_pattern_get_reference_count (cairo_pattern_t *pattern); - -cairo_public cairo_status_t -cairo_pattern_status (cairo_pattern_t *pattern); - -cairo_public void * -cairo_pattern_get_user_data (cairo_pattern_t *pattern, - const cairo_user_data_key_t *key); - -cairo_public cairo_status_t -cairo_pattern_set_user_data (cairo_pattern_t *pattern, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - -/** - * cairo_pattern_type_t: - * @CAIRO_PATTERN_TYPE_SOLID: The pattern is a solid (uniform) - * color. It may be opaque or translucent, since 1.2. - * @CAIRO_PATTERN_TYPE_SURFACE: The pattern is a based on a surface (an image), since 1.2. - * @CAIRO_PATTERN_TYPE_LINEAR: The pattern is a linear gradient, since 1.2. - * @CAIRO_PATTERN_TYPE_RADIAL: The pattern is a radial gradient, since 1.2. - * @CAIRO_PATTERN_TYPE_MESH: The pattern is a mesh, since 1.12. - * @CAIRO_PATTERN_TYPE_RASTER_SOURCE: The pattern is a user pattern providing raster data, since 1.12. - * - * #cairo_pattern_type_t is used to describe the type of a given pattern. - * - * The type of a pattern is determined by the function used to create - * it. The cairo_pattern_create_rgb() and cairo_pattern_create_rgba() - * functions create SOLID patterns. The remaining - * cairo_pattern_create functions map to pattern types in obvious - * ways. - * - * The pattern type can be queried with cairo_pattern_get_type() - * - * Most #cairo_pattern_t functions can be called with a pattern of any - * type, (though trying to change the extend or filter for a solid - * pattern will have no effect). A notable exception is - * cairo_pattern_add_color_stop_rgb() and - * cairo_pattern_add_color_stop_rgba() which must only be called with - * gradient patterns (either LINEAR or RADIAL). Otherwise the pattern - * will be shutdown and put into an error state. - * - * New entries may be added in future versions. - * - * Since: 1.2 - **/ -typedef enum _cairo_pattern_type { - CAIRO_PATTERN_TYPE_SOLID, - CAIRO_PATTERN_TYPE_SURFACE, - CAIRO_PATTERN_TYPE_LINEAR, - CAIRO_PATTERN_TYPE_RADIAL, - CAIRO_PATTERN_TYPE_MESH, - CAIRO_PATTERN_TYPE_RASTER_SOURCE -} cairo_pattern_type_t; - -cairo_public cairo_pattern_type_t -cairo_pattern_get_type (cairo_pattern_t *pattern); - -cairo_public void -cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, - double offset, - double red, double green, double blue); - -cairo_public void -cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, - double offset, - double red, double green, double blue, - double alpha); - -cairo_public void -cairo_mesh_pattern_begin_patch (cairo_pattern_t *pattern); - -cairo_public void -cairo_mesh_pattern_end_patch (cairo_pattern_t *pattern); - -cairo_public void -cairo_mesh_pattern_curve_to (cairo_pattern_t *pattern, - double x1, double y1, - double x2, double y2, - double x3, double y3); - -cairo_public void -cairo_mesh_pattern_line_to (cairo_pattern_t *pattern, - double x, double y); - -cairo_public void -cairo_mesh_pattern_move_to (cairo_pattern_t *pattern, - double x, double y); - -cairo_public void -cairo_mesh_pattern_set_control_point (cairo_pattern_t *pattern, - unsigned int point_num, - double x, double y); - -cairo_public void -cairo_mesh_pattern_set_corner_color_rgb (cairo_pattern_t *pattern, - unsigned int corner_num, - double red, double green, double blue); - -cairo_public void -cairo_mesh_pattern_set_corner_color_rgba (cairo_pattern_t *pattern, - unsigned int corner_num, - double red, double green, double blue, - double alpha); - -cairo_public void -cairo_pattern_set_matrix (cairo_pattern_t *pattern, - const cairo_matrix_t *matrix); - -cairo_public void -cairo_pattern_get_matrix (cairo_pattern_t *pattern, - cairo_matrix_t *matrix); - -/** - * cairo_extend_t: - * @CAIRO_EXTEND_NONE: pixels outside of the source pattern - * are fully transparent (Since 1.0) - * @CAIRO_EXTEND_REPEAT: the pattern is tiled by repeating (Since 1.0) - * @CAIRO_EXTEND_REFLECT: the pattern is tiled by reflecting - * at the edges (Since 1.0; but only implemented for surface patterns since 1.6) - * @CAIRO_EXTEND_PAD: pixels outside of the pattern copy - * the closest pixel from the source (Since 1.2; but only - * implemented for surface patterns since 1.6) - * - * #cairo_extend_t is used to describe how pattern color/alpha will be - * determined for areas "outside" the pattern's natural area, (for - * example, outside the surface bounds or outside the gradient - * geometry). - * - * Mesh patterns are not affected by the extend mode. - * - * The default extend mode is %CAIRO_EXTEND_NONE for surface patterns - * and %CAIRO_EXTEND_PAD for gradient patterns. - * - * New entries may be added in future versions. - * - * Since: 1.0 - **/ -typedef enum _cairo_extend { - CAIRO_EXTEND_NONE, - CAIRO_EXTEND_REPEAT, - CAIRO_EXTEND_REFLECT, - CAIRO_EXTEND_PAD -} cairo_extend_t; - -cairo_public void -cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend); - -cairo_public cairo_extend_t -cairo_pattern_get_extend (cairo_pattern_t *pattern); - -/** - * cairo_filter_t: - * @CAIRO_FILTER_FAST: A high-performance filter, with quality similar - * to %CAIRO_FILTER_NEAREST (Since 1.0) - * @CAIRO_FILTER_GOOD: A reasonable-performance filter, with quality - * similar to %CAIRO_FILTER_BILINEAR (Since 1.0) - * @CAIRO_FILTER_BEST: The highest-quality available, performance may - * not be suitable for interactive use. (Since 1.0) - * @CAIRO_FILTER_NEAREST: Nearest-neighbor filtering (Since 1.0) - * @CAIRO_FILTER_BILINEAR: Linear interpolation in two dimensions (Since 1.0) - * @CAIRO_FILTER_GAUSSIAN: This filter value is currently - * unimplemented, and should not be used in current code. (Since 1.0) - * - * #cairo_filter_t is used to indicate what filtering should be - * applied when reading pixel values from patterns. See - * cairo_pattern_set_filter() for indicating the desired filter to be - * used with a particular pattern. - * - * Since: 1.0 - **/ -typedef enum _cairo_filter { - CAIRO_FILTER_FAST, - CAIRO_FILTER_GOOD, - CAIRO_FILTER_BEST, - CAIRO_FILTER_NEAREST, - CAIRO_FILTER_BILINEAR, - CAIRO_FILTER_GAUSSIAN -} cairo_filter_t; - -cairo_public void -cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter); - -cairo_public cairo_filter_t -cairo_pattern_get_filter (cairo_pattern_t *pattern); - -cairo_public cairo_status_t -cairo_pattern_get_rgba (cairo_pattern_t *pattern, - double *red, double *green, - double *blue, double *alpha); - -cairo_public cairo_status_t -cairo_pattern_get_surface (cairo_pattern_t *pattern, - cairo_surface_t **surface); - - -cairo_public cairo_status_t -cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern, - int index, double *offset, - double *red, double *green, - double *blue, double *alpha); - -cairo_public cairo_status_t -cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern, - int *count); - -cairo_public cairo_status_t -cairo_pattern_get_linear_points (cairo_pattern_t *pattern, - double *x0, double *y0, - double *x1, double *y1); - -cairo_public cairo_status_t -cairo_pattern_get_radial_circles (cairo_pattern_t *pattern, - double *x0, double *y0, double *r0, - double *x1, double *y1, double *r1); - -cairo_public cairo_status_t -cairo_mesh_pattern_get_patch_count (cairo_pattern_t *pattern, - unsigned int *count); - -cairo_public cairo_path_t * -cairo_mesh_pattern_get_path (cairo_pattern_t *pattern, - unsigned int patch_num); - -cairo_public cairo_status_t -cairo_mesh_pattern_get_corner_color_rgba (cairo_pattern_t *pattern, - unsigned int patch_num, - unsigned int corner_num, - double *red, double *green, - double *blue, double *alpha); - -cairo_public cairo_status_t -cairo_mesh_pattern_get_control_point (cairo_pattern_t *pattern, - unsigned int patch_num, - unsigned int point_num, - double *x, double *y); - -/* Matrix functions */ - -cairo_public void -cairo_matrix_init (cairo_matrix_t *matrix, - double xx, double yx, - double xy, double yy, - double x0, double y0); - -cairo_public void -cairo_matrix_init_identity (cairo_matrix_t *matrix); - -cairo_public void -cairo_matrix_init_translate (cairo_matrix_t *matrix, - double tx, double ty); - -cairo_public void -cairo_matrix_init_scale (cairo_matrix_t *matrix, - double sx, double sy); - -cairo_public void -cairo_matrix_init_rotate (cairo_matrix_t *matrix, - double radians); - -cairo_public void -cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty); - -cairo_public void -cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy); - -cairo_public void -cairo_matrix_rotate (cairo_matrix_t *matrix, double radians); - -cairo_public cairo_status_t -cairo_matrix_invert (cairo_matrix_t *matrix); - -cairo_public void -cairo_matrix_multiply (cairo_matrix_t *result, - const cairo_matrix_t *a, - const cairo_matrix_t *b); - -cairo_public void -cairo_matrix_transform_distance (const cairo_matrix_t *matrix, - double *dx, double *dy); - -cairo_public void -cairo_matrix_transform_point (const cairo_matrix_t *matrix, - double *x, double *y); - -/* Region functions */ - -/** - * cairo_region_t: - * - * A #cairo_region_t represents a set of integer-aligned rectangles. - * - * It allows set-theoretical operations like cairo_region_union() and - * cairo_region_intersect() to be performed on them. - * - * Memory management of #cairo_region_t is done with - * cairo_region_reference() and cairo_region_destroy(). - * - * Since: 1.10 - **/ -typedef struct _cairo_region cairo_region_t; - -/** - * cairo_region_overlap_t: - * @CAIRO_REGION_OVERLAP_IN: The contents are entirely inside the region. (Since 1.10) - * @CAIRO_REGION_OVERLAP_OUT: The contents are entirely outside the region. (Since 1.10) - * @CAIRO_REGION_OVERLAP_PART: The contents are partially inside and - * partially outside the region. (Since 1.10) - * - * Used as the return value for cairo_region_contains_rectangle(). - * - * Since: 1.10 - **/ -typedef enum _cairo_region_overlap { - CAIRO_REGION_OVERLAP_IN, /* completely inside region */ - CAIRO_REGION_OVERLAP_OUT, /* completely outside region */ - CAIRO_REGION_OVERLAP_PART /* partly inside region */ -} cairo_region_overlap_t; - -cairo_public cairo_region_t * -cairo_region_create (void); - -cairo_public cairo_region_t * -cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle); - -cairo_public cairo_region_t * -cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, - int count); - -cairo_public cairo_region_t * -cairo_region_copy (const cairo_region_t *original); - -cairo_public cairo_region_t * -cairo_region_reference (cairo_region_t *region); - -cairo_public void -cairo_region_destroy (cairo_region_t *region); - -cairo_public cairo_bool_t -cairo_region_equal (const cairo_region_t *a, const cairo_region_t *b); - -cairo_public cairo_status_t -cairo_region_status (const cairo_region_t *region); - -cairo_public void -cairo_region_get_extents (const cairo_region_t *region, - cairo_rectangle_int_t *extents); - -cairo_public int -cairo_region_num_rectangles (const cairo_region_t *region); - -cairo_public void -cairo_region_get_rectangle (const cairo_region_t *region, - int nth, - cairo_rectangle_int_t *rectangle); - -cairo_public cairo_bool_t -cairo_region_is_empty (const cairo_region_t *region); - -cairo_public cairo_region_overlap_t -cairo_region_contains_rectangle (const cairo_region_t *region, - const cairo_rectangle_int_t *rectangle); - -cairo_public cairo_bool_t -cairo_region_contains_point (const cairo_region_t *region, int x, int y); - -cairo_public void -cairo_region_translate (cairo_region_t *region, int dx, int dy); - -cairo_public cairo_status_t -cairo_region_subtract (cairo_region_t *dst, const cairo_region_t *other); - -cairo_public cairo_status_t -cairo_region_subtract_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle); - -cairo_public cairo_status_t -cairo_region_intersect (cairo_region_t *dst, const cairo_region_t *other); - -cairo_public cairo_status_t -cairo_region_intersect_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle); - -cairo_public cairo_status_t -cairo_region_union (cairo_region_t *dst, const cairo_region_t *other); - -cairo_public cairo_status_t -cairo_region_union_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle); - -cairo_public cairo_status_t -cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other); - -cairo_public cairo_status_t -cairo_region_xor_rectangle (cairo_region_t *dst, - const cairo_rectangle_int_t *rectangle); - -/* Functions to be used while debugging (not intended for use in production code) */ -cairo_public void -cairo_debug_reset_static_data (void); - - -CAIRO_END_DECLS - -#endif /* CAIRO_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairo.pc.in b/Build/source/libs/cairo/cairo-1.14.2/src/cairo.pc.in deleted file mode 100644 index b361edf18fb..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairo.pc.in +++ /dev/null @@ -1,13 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: cairo -Description: Multi-platform 2D graphics library -Version: @VERSION@ - -@PKGCONFIG_REQUIRES@: @CAIRO_REQUIRES@ -Libs: -L${libdir} -lcairo -Libs.private: @CAIRO_NONPKGCONFIG_LIBS@ -Cflags: -I${includedir}/cairo diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/cairoint.h b/Build/source/libs/cairo/cairo-1.14.2/src/cairoint.h deleted file mode 100644 index 5bca0038953..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/cairoint.h +++ /dev/null @@ -1,2081 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - */ - -/* - * These definitions are solely for use by the implementation of cairo - * and constitute no kind of standard. If you need any of these - * functions, please drop me a note. Either the library needs new - * functionality, or there's a way to do what you need using the - * existing published interfaces. cworth@cworth.org - */ - -#ifndef _CAIROINT_H_ -#define _CAIROINT_H_ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef _MSC_VER -#define cairo_public __declspec(dllexport) -#endif - -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -#define _USE_MATH_DEFINES -#endif -#include -#include -#include - -#include "cairo.h" -#include - -#include "cairo-compiler-private.h" -#include "cairo-error-private.h" - -#if CAIRO_HAS_PDF_SURFACE || \ - CAIRO_HAS_PS_SURFACE || \ - CAIRO_HAS_SCRIPT_SURFACE || \ - CAIRO_HAS_XML_SURFACE -#define CAIRO_HAS_DEFLATE_STREAM 1 -#endif - -#if CAIRO_HAS_PS_SURFACE || \ - CAIRO_HAS_PDF_SURFACE || \ - CAIRO_HAS_SVG_SURFACE || \ - CAIRO_HAS_WIN32_SURFACE -#define CAIRO_HAS_FONT_SUBSET 1 -#endif - -#if CAIRO_HAS_PS_SURFACE || \ - CAIRO_HAS_PDF_SURFACE || \ - CAIRO_HAS_FONT_SUBSET -#define CAIRO_HAS_PDF_OPERATORS 1 -#endif - -CAIRO_BEGIN_DECLS - -#if _WIN32 && !_WIN32_WCE /* Permissions on WinCE? No worries! */ -cairo_private FILE * -_cairo_win32_tmpfile (void); -#define tmpfile() _cairo_win32_tmpfile() -#endif - -#undef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -#undef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 -#endif - -#ifndef M_SQRT1_2 -#define M_SQRT1_2 0.707106781186547524400844362104849039 -#endif - -#undef ARRAY_LENGTH -#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) - -#undef STRINGIFY -#undef STRINGIFY_ARG -#define STRINGIFY(macro_or_string) STRINGIFY_ARG (macro_or_string) -#define STRINGIFY_ARG(contents) #contents - -#if defined (__GNUC__) -#define cairo_container_of(ptr, type, member) ({ \ - const __typeof__ (((type *) 0)->member) *mptr__ = (ptr); \ - (type *) ((char *) mptr__ - offsetof (type, member)); \ -}) -#else -#define cairo_container_of(ptr, type, member) \ - ((type *)((char *) (ptr) - (char *) &((type *)0)->member)) -#endif - - -#define ASSERT_NOT_REACHED \ -do { \ - assert (!"reached"); \ -} while (0) -#define COMPILE_TIME_ASSERT1(condition, line) \ - typedef int compile_time_assertion_at_line_##line##_failed [(condition)?1:-1] -#define COMPILE_TIME_ASSERT0(condition, line) COMPILE_TIME_ASSERT1(condition, line) -#define COMPILE_TIME_ASSERT(condition) COMPILE_TIME_ASSERT0(condition, __LINE__) - -#define CAIRO_ALPHA_IS_CLEAR(alpha) ((alpha) <= ((double)0x00ff / (double)0xffff)) -#define CAIRO_ALPHA_SHORT_IS_CLEAR(alpha) ((alpha) <= 0x00ff) - -#define CAIRO_ALPHA_IS_OPAQUE(alpha) ((alpha) >= ((double)0xff00 / (double)0xffff)) -#define CAIRO_ALPHA_SHORT_IS_OPAQUE(alpha) ((alpha) >= 0xff00) -#define CAIRO_ALPHA_IS_ZERO(alpha) ((alpha) <= 0.0) - -#define CAIRO_COLOR_IS_CLEAR(color) CAIRO_ALPHA_SHORT_IS_CLEAR ((color)->alpha_short) -#define CAIRO_COLOR_IS_OPAQUE(color) CAIRO_ALPHA_SHORT_IS_OPAQUE ((color)->alpha_short) - -/* Reverse the bits in a byte with 7 operations (no 64-bit): - * Devised by Sean Anderson, July 13, 2001. - * Source: http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits - */ -#define CAIRO_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16) - -/* Return the number of 1 bits in mask. - * - * GCC 3.4 supports a "population count" builtin, which on many targets is - * implemented with a single instruction. There is a fallback definition - * in libgcc in case a target does not have one, which should be just as - * good as the open-coded solution below, (which is "HACKMEM 169"). - */ -static inline int cairo_const -_cairo_popcount (uint32_t mask) -{ -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - return __builtin_popcount (mask); -#else - register int y; - - y = (mask >> 1) &033333333333; - y = mask - y - ((y >>1) & 033333333333); - return (((y + (y >> 3)) & 030707070707) % 077); -#endif -} - -static cairo_always_inline cairo_bool_t -_cairo_is_little_endian (void) -{ - static const int i = 1; - return *((char *) &i) == 0x01; -} - -#ifdef WORDS_BIGENDIAN -#define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) (c) -#else -#define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) CAIRO_BITSWAP8(c) -#endif - -#ifdef WORDS_BIGENDIAN - -#define cpu_to_be16(v) (v) -#define be16_to_cpu(v) (v) -#define cpu_to_be32(v) (v) -#define be32_to_cpu(v) (v) - -#else - -static inline uint16_t cairo_const -cpu_to_be16(uint16_t v) -{ - return (v << 8) | (v >> 8); -} - -static inline uint16_t cairo_const -be16_to_cpu(uint16_t v) -{ - return cpu_to_be16 (v); -} - -static inline uint32_t cairo_const -cpu_to_be32(uint32_t v) -{ - return (v >> 24) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | (v << 24); -} - -static inline uint32_t cairo_const -be32_to_cpu(uint32_t v) -{ - return cpu_to_be32 (v); -} - -#endif - -/* Unaligned big endian access - */ - -static inline uint16_t get_unaligned_be16 (const unsigned char *p) -{ - return p[0] << 8 | p[1]; -} - -static inline uint32_t get_unaligned_be32 (const unsigned char *p) -{ - return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; -} - -static inline void put_unaligned_be16 (uint16_t v, unsigned char *p) -{ - p[0] = (v >> 8) & 0xff; - p[1] = v & 0xff; -} - -static inline void put_unaligned_be32 (uint32_t v, unsigned char *p) -{ - p[0] = (v >> 24) & 0xff; - p[1] = (v >> 16) & 0xff; - p[2] = (v >> 8) & 0xff; - p[3] = v & 0xff; -} - -/* The glibc versions of ispace() and isdigit() are slow in UTF-8 locales. - */ - -static inline int cairo_const -_cairo_isspace (int c) -{ - return (c == 0x20 || (c >= 0x09 && c <= 0x0d)); -} - -static inline int cairo_const -_cairo_isdigit (int c) -{ - return (c >= '0' && c <= '9'); -} - -#include "cairo-types-private.h" -#include "cairo-cache-private.h" -#include "cairo-reference-count-private.h" -#include "cairo-spans-private.h" -#include "cairo-surface-private.h" - -cairo_private void -_cairo_box_from_doubles (cairo_box_t *box, - double *x1, double *y1, - double *x2, double *y2); - -cairo_private void -_cairo_box_to_doubles (const cairo_box_t *box, - double *x1, double *y1, - double *x2, double *y2); - -cairo_private void -_cairo_box_from_rectangle (cairo_box_t *box, - const cairo_rectangle_int_t *rectangle); - -cairo_private void -_cairo_box_round_to_rectangle (const cairo_box_t *box, - cairo_rectangle_int_t *rectangle); - -cairo_private void -_cairo_box_add_curve_to (cairo_box_t *extents, - const cairo_point_t *a, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d); - -cairo_private void -_cairo_boxes_get_extents (const cairo_box_t *boxes, - int num_boxes, - cairo_box_t *extents); - -cairo_private extern const cairo_rectangle_int_t _cairo_empty_rectangle; -cairo_private extern const cairo_rectangle_int_t _cairo_unbounded_rectangle; - -static inline void -_cairo_unbounded_rectangle_init (cairo_rectangle_int_t *rect) -{ - *rect = _cairo_unbounded_rectangle; -} - -cairo_private_no_warn cairo_bool_t -_cairo_rectangle_intersect (cairo_rectangle_int_t *dst, - const cairo_rectangle_int_t *src); - -static inline cairo_bool_t -_cairo_rectangle_intersects (const cairo_rectangle_int_t *dst, - const cairo_rectangle_int_t *src) -{ - return !(src->x >= dst->x + (int) dst->width || - src->x + (int) src->width <= dst->x || - src->y >= dst->y + (int) dst->height || - src->y + (int) src->height <= dst->y); -} - -static inline cairo_bool_t -_cairo_rectangle_contains_rectangle (const cairo_rectangle_int_t *a, - const cairo_rectangle_int_t *b) -{ - return (a->x <= b->x && - a->x + (int) a->width >= b->x + (int) b->width && - a->y <= b->y && - a->y + (int) a->height >= b->y + (int) b->height); -} - -cairo_private void -_cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti, - const cairo_rectangle_t *rectf); - -/* Extends the dst rectangle to also contain src. - * If one of the rectangles is empty, the result is undefined - */ -cairo_private void -_cairo_rectangle_union (cairo_rectangle_int_t *dst, - const cairo_rectangle_int_t *src); - -cairo_private cairo_bool_t -_cairo_box_intersects_line_segment (const cairo_box_t *box, - cairo_line_t *line) cairo_pure; - -cairo_private cairo_bool_t -_cairo_spline_intersects (const cairo_point_t *a, - const cairo_point_t *b, - const cairo_point_t *c, - const cairo_point_t *d, - const cairo_box_t *box) cairo_pure; - -typedef struct { - const cairo_user_data_key_t *key; - void *user_data; - cairo_destroy_func_t destroy; -} cairo_user_data_slot_t; - -cairo_private void -_cairo_user_data_array_init (cairo_user_data_array_t *array); - -cairo_private void -_cairo_user_data_array_fini (cairo_user_data_array_t *array); - -cairo_private void * -_cairo_user_data_array_get_data (cairo_user_data_array_t *array, - const cairo_user_data_key_t *key); - -cairo_private cairo_status_t -_cairo_user_data_array_set_data (cairo_user_data_array_t *array, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy); - -cairo_private cairo_status_t -_cairo_user_data_array_copy (cairo_user_data_array_t *dst, - const cairo_user_data_array_t *src); - -cairo_private void -_cairo_user_data_array_foreach (cairo_user_data_array_t *array, - void (*func) (const void *key, - void *elt, - void *closure), - void *closure); - -#define _CAIRO_HASH_INIT_VALUE 5381 - -cairo_private unsigned long -_cairo_hash_string (const char *c); - -cairo_private unsigned long -_cairo_hash_bytes (unsigned long hash, - const void *bytes, - unsigned int length); - -#define _cairo_scaled_glyph_index(g) ((g)->hash_entry.hash) -#define _cairo_scaled_glyph_set_index(g, i) ((g)->hash_entry.hash = (i)) - -#include "cairo-scaled-font-private.h" - -struct _cairo_font_face { - /* hash_entry must be first */ - cairo_hash_entry_t hash_entry; - cairo_status_t status; - cairo_reference_count_t ref_count; - cairo_user_data_array_t user_data; - const cairo_font_face_backend_t *backend; -}; - -cairo_private void -_cairo_default_context_reset_static_data (void); - -cairo_private void -_cairo_toy_font_face_reset_static_data (void); - -cairo_private void -_cairo_ft_font_reset_static_data (void); - -cairo_private void -_cairo_win32_font_reset_static_data (void); - -#if CAIRO_HAS_COGL_SURFACE -void -_cairo_cogl_context_reset_static_data (void); -#endif - -/* the font backend interface */ - -struct _cairo_unscaled_font_backend { - cairo_bool_t (*destroy) (void *unscaled_font); -}; - -/* #cairo_toy_font_face_t - simple family/slant/weight font faces used for - * the built-in font API - */ - -typedef struct _cairo_toy_font_face { - cairo_font_face_t base; - const char *family; - cairo_bool_t owns_family; - cairo_font_slant_t slant; - cairo_font_weight_t weight; - - cairo_font_face_t *impl_face; /* The non-toy font face this actually uses */ -} cairo_toy_font_face_t; - -typedef enum _cairo_scaled_glyph_info { - CAIRO_SCALED_GLYPH_INFO_METRICS = (1 << 0), - CAIRO_SCALED_GLYPH_INFO_SURFACE = (1 << 1), - CAIRO_SCALED_GLYPH_INFO_PATH = (1 << 2), - CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE = (1 << 3) -} cairo_scaled_glyph_info_t; - -typedef struct _cairo_scaled_font_subset { - cairo_scaled_font_t *scaled_font; - unsigned int font_id; - unsigned int subset_id; - - /* Index of glyphs array is subset_glyph_index. - * Value of glyphs array is scaled_font_glyph_index. - */ - unsigned long *glyphs; - char **utf8; - char **glyph_names; - int *to_latin_char; - unsigned long *latin_to_subset_glyph_index; - unsigned int num_glyphs; - cairo_bool_t is_composite; - cairo_bool_t is_scaled; - cairo_bool_t is_latin; -} cairo_scaled_font_subset_t; - -struct _cairo_scaled_font_backend { - cairo_font_type_t type; - - void - (*fini) (void *scaled_font); - - cairo_warn cairo_int_status_t - (*scaled_glyph_init) (void *scaled_font, - cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_glyph_info_t info); - - /* A backend only needs to implement this or ucs4_to_index(), not - * both. This allows the backend to do something more sophisticated - * then just converting characters one by one. - */ - cairo_warn cairo_int_status_t - (*text_to_glyphs) (void *scaled_font, - double x, - double y, - const char *utf8, - int utf8_len, - cairo_glyph_t **glyphs, - int *num_glyphs, - cairo_text_cluster_t **clusters, - int *num_clusters, - cairo_text_cluster_flags_t *cluster_flags); - - unsigned long - (*ucs4_to_index) (void *scaled_font, - uint32_t ucs4); - - /* Read data from a sfnt font table. - * @scaled_font: font - * @tag: 4 byte table name specifying the table to read. - * @offset: offset into the table - * @buffer: buffer to write data into. Caller must ensure there is sufficient space. - * If NULL, return the size of the table in @length. - * @length: If @buffer is NULL, the size of the table will be returned in @length. - * If @buffer is not null, @length specifies the number of bytes to read. - * - * If less than @length bytes are available to read this function - * returns CAIRO_INT_STATUS_UNSUPPORTED. Note that requesting more - * bytes than are available in the table may continue reading data - * from the following table and return success. If this is - * undesirable the caller should first query the table size. If an - * error occurs the output value of @length is undefined. - * - * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a sfnt style font or table not found. - */ - cairo_warn cairo_int_status_t - (*load_truetype_table)(void *scaled_font, - unsigned long tag, - long offset, - unsigned char *buffer, - unsigned long *length); - - /* ucs4 is set to -1 if the unicode character could not be found - * for the glyph */ - cairo_warn cairo_int_status_t - (*index_to_ucs4)(void *scaled_font, - unsigned long index, - uint32_t *ucs4); - - cairo_warn cairo_bool_t - (*is_synthetic)(void *scaled_font); - - /* For type 1 fonts, return the glyph name for a given glyph index. - * A glyph index and list of glyph names in the Type 1 fonts is provided. - * The function returns the index of the glyph in the list of glyph names. - * @scaled_font: font - * @glyph_names: the names of each glyph in the Type 1 font in the - * order they appear in the CharStrings array - * @num_glyph_names: the number of names in the glyph_names array - * @glyph_index: the given glyph index - * @glyph_array_index: (index into glyph_names) the glyph name corresponding - * to the glyph_index - */ - - cairo_warn cairo_int_status_t - (*index_to_glyph_name)(void *scaled_font, - char **glyph_names, - int num_glyph_names, - unsigned long glyph_index, - unsigned long *glyph_array_index); - - /* Read data from a PostScript font. - * @scaled_font: font - * @offset: offset into the table - * @buffer: buffer to write data into. Caller must ensure there is sufficient space. - * If NULL, return the size of the table in @length. - * @length: If @buffer is NULL, the size of the table will be returned in @length. - * If @buffer is not null, @length specifies the number of bytes to read. - * - * If less than @length bytes are available to read this function - * returns CAIRO_INT_STATUS_UNSUPPORTED. If an error occurs the - * output value of @length is undefined. - * - * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a Type 1 font. - */ - cairo_warn cairo_int_status_t - (*load_type1_data) (void *scaled_font, - long offset, - unsigned char *buffer, - unsigned long *length); -}; - -struct _cairo_font_face_backend { - cairo_font_type_t type; - - cairo_warn cairo_status_t - (*create_for_toy) (cairo_toy_font_face_t *toy_face, - cairo_font_face_t **font_face); - - /* The destroy() function is allowed to resurrect the font face - * by re-referencing. This is needed for the FreeType backend. - */ - cairo_bool_t - (*destroy) (void *font_face); - - cairo_warn cairo_status_t - (*scaled_font_create) (void *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - cairo_scaled_font_t **scaled_font); - - cairo_font_face_t * - (*get_implementation) (void *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options); -}; - -extern const cairo_private struct _cairo_font_face_backend _cairo_user_font_face_backend; - -/* concrete font backends */ -#if CAIRO_HAS_FT_FONT - -extern const cairo_private struct _cairo_font_face_backend _cairo_ft_font_face_backend; - -#endif - -#if CAIRO_HAS_WIN32_FONT - -extern const cairo_private struct _cairo_font_face_backend _cairo_win32_font_face_backend; - -#endif - -#if CAIRO_HAS_QUARTZ_FONT - -extern const cairo_private struct _cairo_font_face_backend _cairo_quartz_font_face_backend; - -#endif - -#define CAIRO_EXTEND_SURFACE_DEFAULT CAIRO_EXTEND_NONE -#define CAIRO_EXTEND_GRADIENT_DEFAULT CAIRO_EXTEND_PAD -#define CAIRO_FILTER_DEFAULT CAIRO_FILTER_GOOD - -extern const cairo_private cairo_solid_pattern_t _cairo_pattern_clear; -extern const cairo_private cairo_solid_pattern_t _cairo_pattern_black; -extern const cairo_private cairo_solid_pattern_t _cairo_pattern_white; - -struct _cairo_surface_attributes { - cairo_matrix_t matrix; - cairo_extend_t extend; - cairo_filter_t filter; - cairo_bool_t has_component_alpha; - int x_offset; - int y_offset; - void *extra; -}; - -#define CAIRO_FONT_SLANT_DEFAULT CAIRO_FONT_SLANT_NORMAL -#define CAIRO_FONT_WEIGHT_DEFAULT CAIRO_FONT_WEIGHT_NORMAL - -#define CAIRO_WIN32_FONT_FAMILY_DEFAULT "Arial" -#define CAIRO_QUARTZ_FONT_FAMILY_DEFAULT "Helvetica" -#define CAIRO_FT_FONT_FAMILY_DEFAULT "" -#define CAIRO_USER_FONT_FAMILY_DEFAULT "@cairo:" - -#if CAIRO_HAS_WIN32_FONT - -#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_WIN32_FONT_FAMILY_DEFAULT -#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_win32_font_face_backend - -#elif CAIRO_HAS_QUARTZ_FONT - -#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_QUARTZ_FONT_FAMILY_DEFAULT -#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_quartz_font_face_backend - -#elif CAIRO_HAS_FT_FONT - -#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_FT_FONT_FAMILY_DEFAULT -#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_ft_font_face_backend - -#else - -#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_FT_FONT_FAMILY_DEFAULT -#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_user_font_face_backend - -#endif - -#define CAIRO_GSTATE_OPERATOR_DEFAULT CAIRO_OPERATOR_OVER -#define CAIRO_GSTATE_TOLERANCE_DEFAULT 0.1 -#define CAIRO_GSTATE_FILL_RULE_DEFAULT CAIRO_FILL_RULE_WINDING -#define CAIRO_GSTATE_LINE_WIDTH_DEFAULT 2.0 -#define CAIRO_GSTATE_LINE_CAP_DEFAULT CAIRO_LINE_CAP_BUTT -#define CAIRO_GSTATE_LINE_JOIN_DEFAULT CAIRO_LINE_JOIN_MITER -#define CAIRO_GSTATE_MITER_LIMIT_DEFAULT 10.0 -#define CAIRO_GSTATE_DEFAULT_FONT_SIZE 10.0 - -#define CAIRO_SURFACE_RESOLUTION_DEFAULT 72.0 -#define CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT 300.0 - -typedef struct _cairo_stroke_face { - cairo_point_t ccw; - cairo_point_t point; - cairo_point_t cw; - cairo_slope_t dev_vector; - cairo_point_double_t dev_slope; - cairo_point_double_t usr_vector; - double length; -} cairo_stroke_face_t; - -/* cairo.c */ - -static inline double cairo_const -_cairo_restrict_value (double value, double min, double max) -{ - if (value < min) - return min; - else if (value > max) - return max; - else - return value; -} - -/* C99 round() rounds to the nearest integral value with halfway cases rounded - * away from 0. _cairo_round rounds halfway cases toward positive infinity. - * This matches the rounding behaviour of _cairo_lround. */ -static inline double cairo_const -_cairo_round (double r) -{ - return floor (r + .5); -} - -#if DISABLE_SOME_FLOATING_POINT -cairo_private int -_cairo_lround (double d) cairo_const; -#else -static inline int cairo_const -_cairo_lround (double r) -{ - return _cairo_round (r); -} -#endif - -cairo_private uint16_t -_cairo_half_from_float (float f) cairo_const; - -cairo_private cairo_bool_t -_cairo_operator_bounded_by_mask (cairo_operator_t op) cairo_const; - -cairo_private cairo_bool_t -_cairo_operator_bounded_by_source (cairo_operator_t op) cairo_const; - -enum { - CAIRO_OPERATOR_BOUND_BY_MASK = 1 << 1, - CAIRO_OPERATOR_BOUND_BY_SOURCE = 1 << 2, -}; - -cairo_private uint32_t -_cairo_operator_bounded_by_either (cairo_operator_t op) cairo_const; -/* cairo-color.c */ -cairo_private const cairo_color_t * -_cairo_stock_color (cairo_stock_t stock) cairo_pure; - -#define CAIRO_COLOR_WHITE _cairo_stock_color (CAIRO_STOCK_WHITE) -#define CAIRO_COLOR_BLACK _cairo_stock_color (CAIRO_STOCK_BLACK) -#define CAIRO_COLOR_TRANSPARENT _cairo_stock_color (CAIRO_STOCK_TRANSPARENT) - -cairo_private uint16_t -_cairo_color_double_to_short (double d) cairo_const; - -cairo_private void -_cairo_color_init_rgba (cairo_color_t *color, - double red, double green, double blue, - double alpha); - -cairo_private void -_cairo_color_multiply_alpha (cairo_color_t *color, - double alpha); - -cairo_private void -_cairo_color_get_rgba (cairo_color_t *color, - double *red, - double *green, - double *blue, - double *alpha); - -cairo_private void -_cairo_color_get_rgba_premultiplied (cairo_color_t *color, - double *red, - double *green, - double *blue, - double *alpha); - -cairo_private cairo_bool_t -_cairo_color_equal (const cairo_color_t *color_a, - const cairo_color_t *color_b) cairo_pure; - -cairo_private cairo_bool_t -_cairo_color_stop_equal (const cairo_color_stop_t *color_a, - const cairo_color_stop_t *color_b) cairo_pure; - -cairo_private cairo_content_t -_cairo_color_get_content (const cairo_color_t *color) cairo_pure; - -/* cairo-font-face.c */ - -extern const cairo_private cairo_font_face_t _cairo_font_face_nil; - -cairo_private void -_cairo_font_face_init (cairo_font_face_t *font_face, - const cairo_font_face_backend_t *backend); - -cairo_private cairo_bool_t -_cairo_font_face_destroy (void *abstract_face); - -cairo_private cairo_status_t -_cairo_font_face_set_error (cairo_font_face_t *font_face, - cairo_status_t status); - -cairo_private void -_cairo_unscaled_font_init (cairo_unscaled_font_t *font, - const cairo_unscaled_font_backend_t *backend); - -cairo_private_no_warn cairo_unscaled_font_t * -_cairo_unscaled_font_reference (cairo_unscaled_font_t *font); - -cairo_private void -_cairo_unscaled_font_destroy (cairo_unscaled_font_t *font); - -/* cairo-font-face-twin.c */ - -cairo_private cairo_font_face_t * -_cairo_font_face_twin_create_fallback (void); - -cairo_private cairo_status_t -_cairo_font_face_twin_create_for_toy (cairo_toy_font_face_t *toy_face, - cairo_font_face_t **font_face); - -/* cairo-font-face-twin-data.c */ - -extern const cairo_private int8_t _cairo_twin_outlines[]; -extern const cairo_private uint16_t _cairo_twin_charmap[128]; - -/* cairo-font-options.c */ - -cairo_private void -_cairo_font_options_init_default (cairo_font_options_t *options); - -cairo_private void -_cairo_font_options_init_copy (cairo_font_options_t *options, - const cairo_font_options_t *other); - -cairo_private void -_cairo_font_options_set_lcd_filter (cairo_font_options_t *options, - cairo_lcd_filter_t lcd_filter); - -cairo_private cairo_lcd_filter_t -_cairo_font_options_get_lcd_filter (const cairo_font_options_t *options); - -cairo_private void -_cairo_font_options_set_round_glyph_positions (cairo_font_options_t *options, - cairo_round_glyph_positions_t round); - -cairo_private cairo_round_glyph_positions_t -_cairo_font_options_get_round_glyph_positions (const cairo_font_options_t *options); - -/* cairo-hull.c */ -cairo_private cairo_status_t -_cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices); - -/* cairo-lzw.c */ -cairo_private unsigned char * -_cairo_lzw_compress (unsigned char *data, unsigned long *size_in_out); - -/* cairo-misc.c */ -cairo_private cairo_status_t -_cairo_validate_text_clusters (const char *utf8, - int utf8_len, - const cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags); - -cairo_private cairo_status_t -_cairo_intern_string (const char **str_inout, int len); - -cairo_private void -_cairo_intern_string_reset_static_data (void); - -cairo_private const char * -cairo_get_locale_decimal_point (void); - -/* cairo-path-fixed.c */ -cairo_private cairo_path_fixed_t * -_cairo_path_fixed_create (void); - -cairo_private void -_cairo_path_fixed_init (cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_path_fixed_init_copy (cairo_path_fixed_t *path, - const cairo_path_fixed_t *other); - -cairo_private void -_cairo_path_fixed_fini (cairo_path_fixed_t *path); - -cairo_private void -_cairo_path_fixed_destroy (cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_path_fixed_move_to (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y); - -cairo_private void -_cairo_path_fixed_new_sub_path (cairo_path_fixed_t *path); - -cairo_private cairo_status_t -_cairo_path_fixed_rel_move_to (cairo_path_fixed_t *path, - cairo_fixed_t dx, - cairo_fixed_t dy); - -cairo_private cairo_status_t -_cairo_path_fixed_line_to (cairo_path_fixed_t *path, - cairo_fixed_t x, - cairo_fixed_t y); - -cairo_private cairo_status_t -_cairo_path_fixed_rel_line_to (cairo_path_fixed_t *path, - cairo_fixed_t dx, - cairo_fixed_t dy); - -cairo_private cairo_status_t -_cairo_path_fixed_curve_to (cairo_path_fixed_t *path, - cairo_fixed_t x0, cairo_fixed_t y0, - cairo_fixed_t x1, cairo_fixed_t y1, - cairo_fixed_t x2, cairo_fixed_t y2); - -cairo_private cairo_status_t -_cairo_path_fixed_rel_curve_to (cairo_path_fixed_t *path, - cairo_fixed_t dx0, cairo_fixed_t dy0, - cairo_fixed_t dx1, cairo_fixed_t dy1, - cairo_fixed_t dx2, cairo_fixed_t dy2); - -cairo_private cairo_status_t -_cairo_path_fixed_close_path (cairo_path_fixed_t *path); - -cairo_private cairo_bool_t -_cairo_path_fixed_get_current_point (cairo_path_fixed_t *path, - cairo_fixed_t *x, - cairo_fixed_t *y); - -typedef cairo_status_t -(cairo_path_fixed_move_to_func_t) (void *closure, - const cairo_point_t *point); - -typedef cairo_status_t -(cairo_path_fixed_line_to_func_t) (void *closure, - const cairo_point_t *point); - -typedef cairo_status_t -(cairo_path_fixed_curve_to_func_t) (void *closure, - const cairo_point_t *p0, - const cairo_point_t *p1, - const cairo_point_t *p2); - -typedef cairo_status_t -(cairo_path_fixed_close_path_func_t) (void *closure); - -cairo_private cairo_status_t -_cairo_path_fixed_interpret (const cairo_path_fixed_t *path, - cairo_path_fixed_move_to_func_t *move_to, - cairo_path_fixed_line_to_func_t *line_to, - cairo_path_fixed_curve_to_func_t *curve_to, - cairo_path_fixed_close_path_func_t *close_path, - void *closure); - -cairo_private cairo_status_t -_cairo_path_fixed_interpret_flat (const cairo_path_fixed_t *path, - cairo_path_fixed_move_to_func_t *move_to, - cairo_path_fixed_line_to_func_t *line_to, - cairo_path_fixed_close_path_func_t *close_path, - void *closure, - double tolerance); - - -cairo_private cairo_bool_t -_cairo_path_bounder_extents (const cairo_path_fixed_t *path, - cairo_box_t *box); - -cairo_private cairo_bool_t -_cairo_path_fixed_extents (const cairo_path_fixed_t *path, - cairo_box_t *box); - -cairo_private void -_cairo_path_fixed_approximate_clip_extents (const cairo_path_fixed_t *path, - cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_path_fixed_approximate_fill_extents (const cairo_path_fixed_t *path, - cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_path_fixed_fill_extents (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_path_fixed_approximate_stroke_extents (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_rectangle_int_t *extents); - -cairo_private void -_cairo_path_fixed_transform (cairo_path_fixed_t *path, - const cairo_matrix_t *matrix); - -cairo_private cairo_bool_t -_cairo_path_fixed_is_box (const cairo_path_fixed_t *path, - cairo_box_t *box); - -cairo_private cairo_bool_t -_cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path, - cairo_box_t *box); - -/* cairo-path-in-fill.c */ -cairo_private cairo_bool_t -_cairo_path_fixed_in_fill (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - double x, - double y); - -/* cairo-path-fill.c */ -cairo_private cairo_status_t -_cairo_path_fixed_fill_to_polygon (const cairo_path_fixed_t *path, - double tolerance, - cairo_polygon_t *polygon); - -cairo_private cairo_status_t -_cairo_path_fixed_fill_rectilinear_to_polygon (const cairo_path_fixed_t *path, - cairo_antialias_t antialias, - cairo_polygon_t *polygon); - -cairo_private cairo_status_t -_cairo_path_fixed_fill_rectilinear_to_boxes (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - cairo_antialias_t antialias, - cairo_boxes_t *boxes); - -cairo_private cairo_region_t * -_cairo_path_fixed_fill_rectilinear_to_region (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - const cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_path_fixed_fill_to_traps (const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_traps_t *traps); - -/* cairo-path-stroke.c */ -cairo_private cairo_status_t -_cairo_path_fixed_stroke_to_polygon (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_polygon_t *polygon); - -cairo_private cairo_int_status_t -_cairo_path_fixed_stroke_to_tristrip (const cairo_path_fixed_t *path, - const cairo_stroke_style_t*style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_tristrip_t *strip); - -cairo_private cairo_status_t -_cairo_path_fixed_stroke_dashed_to_polygon (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_polygon_t *polygon); - -cairo_private cairo_int_status_t -_cairo_path_fixed_stroke_rectilinear_to_boxes (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - cairo_antialias_t antialias, - cairo_boxes_t *boxes); - -cairo_private cairo_int_status_t -_cairo_path_fixed_stroke_to_traps (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_traps_t *traps); - -cairo_private cairo_int_status_t -_cairo_path_fixed_stroke_polygon_to_traps (const cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_traps_t *traps); - -cairo_private cairo_status_t -_cairo_path_fixed_stroke_to_shaper (cairo_path_fixed_t *path, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_status_t (*add_triangle) (void *closure, - const cairo_point_t triangle[3]), - cairo_status_t (*add_triangle_fan) (void *closure, - const cairo_point_t *midpt, - const cairo_point_t *points, - int npoints), - cairo_status_t (*add_quad) (void *closure, - const cairo_point_t quad[4]), - void *closure); - -/* cairo-scaled-font.c */ - -cairo_private void -_cairo_scaled_font_freeze_cache (cairo_scaled_font_t *scaled_font); - -cairo_private void -_cairo_scaled_font_thaw_cache (cairo_scaled_font_t *scaled_font); - -cairo_private void -_cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font); - -cairo_private cairo_status_t -_cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, - cairo_status_t status); - -cairo_private cairo_scaled_font_t * -_cairo_scaled_font_create_in_error (cairo_status_t status); - -cairo_private void -_cairo_scaled_font_reset_static_data (void); - -cairo_private cairo_status_t -_cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t *scaled_font); - -cairo_private void -_cairo_scaled_font_unregister_placeholder_and_lock_font_map (cairo_scaled_font_t *scaled_font); - -cairo_private cairo_status_t -_cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, - cairo_font_face_t *font_face, - const cairo_matrix_t *font_matrix, - const cairo_matrix_t *ctm, - const cairo_font_options_t *options, - const cairo_scaled_font_backend_t *backend); - -cairo_private cairo_status_t -_cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font, - cairo_font_extents_t *fs_metrics); - -/* This should only be called on an error path by a scaled_font constructor */ -cairo_private void -_cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font); - -cairo_private cairo_status_t -_cairo_scaled_font_font_extents (cairo_scaled_font_t *scaled_font, - cairo_font_extents_t *extents); - -cairo_private cairo_status_t -_cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_rectangle_int_t *extents, - cairo_bool_t *overlap); - -cairo_private cairo_bool_t -_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_rectangle_int_t *extents); - -cairo_private cairo_status_t -_cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_surface_t *surface, - int source_x, - int source_y, - int dest_x, - int dest_y, - unsigned int width, - unsigned int height, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_region_t *clip_region); - -cairo_private cairo_status_t -_cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font, - const cairo_glyph_t *glyphs, - int num_glyphs, - cairo_path_fixed_t *path); - -cairo_private void -_cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_text_extents_t *fs_metrics); - -cairo_private void -_cairo_scaled_glyph_set_surface (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_image_surface_t *surface); - -cairo_private void -_cairo_scaled_glyph_set_path (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_path_fixed_t *path); - -cairo_private void -_cairo_scaled_glyph_set_recording_surface (cairo_scaled_glyph_t *scaled_glyph, - cairo_scaled_font_t *scaled_font, - cairo_surface_t *recording_surface); - -cairo_private cairo_int_status_t -_cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font, - unsigned long index, - cairo_scaled_glyph_info_t info, - cairo_scaled_glyph_t **scaled_glyph_ret); - -cairo_private double -_cairo_scaled_font_get_max_scale (cairo_scaled_font_t *scaled_font); - -cairo_private void -_cairo_scaled_font_map_destroy (void); - -/* cairo-stroke-style.c */ - -cairo_private void -_cairo_stroke_style_init (cairo_stroke_style_t *style); - -cairo_private cairo_status_t -_cairo_stroke_style_init_copy (cairo_stroke_style_t *style, - const cairo_stroke_style_t *other); - -cairo_private void -_cairo_stroke_style_fini (cairo_stroke_style_t *style); - -cairo_private void -_cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm, - double *dx, double *dy); -cairo_private void -_cairo_stroke_style_max_line_distance_from_path (const cairo_stroke_style_t *style, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm, - double *dx, double *dy); - -cairo_private void -_cairo_stroke_style_max_join_distance_from_path (const cairo_stroke_style_t *style, - const cairo_path_fixed_t *path, - const cairo_matrix_t *ctm, - double *dx, double *dy); - -cairo_private double -_cairo_stroke_style_dash_period (const cairo_stroke_style_t *style); - -cairo_private double -_cairo_stroke_style_dash_stroked (const cairo_stroke_style_t *style); - -cairo_private cairo_bool_t -_cairo_stroke_style_dash_can_approximate (const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - double tolerance); - -cairo_private void -_cairo_stroke_style_dash_approximate (const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - double tolerance, - double *dash_offset, - double *dashes, - unsigned int *num_dashes); - - -/* cairo-surface.c */ - -cairo_private cairo_status_t -_cairo_surface_copy_mime_data (cairo_surface_t *dst, - cairo_surface_t *src); - -cairo_private_no_warn cairo_int_status_t -_cairo_surface_set_error (cairo_surface_t *surface, - cairo_int_status_t status); - -cairo_private void -_cairo_surface_set_resolution (cairo_surface_t *surface, - double x_res, - double y_res); - -cairo_private cairo_surface_t * -_cairo_surface_create_for_rectangle_int (cairo_surface_t *target, - const cairo_rectangle_int_t *extents); - -cairo_private cairo_surface_t * -_cairo_surface_create_scratch (cairo_surface_t *other, - cairo_content_t content, - int width, - int height, - const cairo_color_t *color); - -cairo_private void -_cairo_surface_init (cairo_surface_t *surface, - const cairo_surface_backend_t *backend, - cairo_device_t *device, - cairo_content_t content); - -cairo_private void -_cairo_surface_set_font_options (cairo_surface_t *surface, - cairo_font_options_t *options); - -cairo_private cairo_status_t -_cairo_surface_paint (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip); - -cairo_private cairo_image_surface_t * -_cairo_surface_map_to_image (cairo_surface_t *surface, - const cairo_rectangle_int_t *extents); - -cairo_private_no_warn cairo_int_status_t -_cairo_surface_unmap_image (cairo_surface_t *surface, - cairo_image_surface_t *image); - -cairo_private cairo_status_t -_cairo_surface_mask (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_fill_stroke (cairo_surface_t *surface, - cairo_operator_t fill_op, - const cairo_pattern_t *fill_source, - cairo_fill_rule_t fill_rule, - double fill_tolerance, - cairo_antialias_t fill_antialias, - cairo_path_fixed_t *path, - cairo_operator_t stroke_op, - const cairo_pattern_t *stroke_source, - const cairo_stroke_style_t *stroke_style, - const cairo_matrix_t *stroke_ctm, - const cairo_matrix_t *stroke_ctm_inverse, - double stroke_tolerance, - cairo_antialias_t stroke_antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_stroke (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_fill (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_show_text_glyphs (cairo_surface_t *surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_surface_acquire_source_image (cairo_surface_t *surface, - cairo_image_surface_t **image_out, - void **image_extra); - -cairo_private void -_cairo_surface_release_source_image (cairo_surface_t *surface, - cairo_image_surface_t *image, - void *image_extra); - -cairo_private cairo_surface_t * -_cairo_surface_snapshot (cairo_surface_t *surface); - -cairo_private void -_cairo_surface_attach_snapshot (cairo_surface_t *surface, - cairo_surface_t *snapshot, - cairo_surface_func_t detach_func); - -cairo_private cairo_surface_t * -_cairo_surface_has_snapshot (cairo_surface_t *surface, - const cairo_surface_backend_t *backend); - -cairo_private void -_cairo_surface_detach_snapshot (cairo_surface_t *snapshot); - -cairo_private cairo_status_t -_cairo_surface_begin_modification (cairo_surface_t *surface); - -cairo_private_no_warn cairo_bool_t -_cairo_surface_get_extents (cairo_surface_t *surface, - cairo_rectangle_int_t *extents); - -cairo_private cairo_bool_t -_cairo_surface_has_device_transform (cairo_surface_t *surface) cairo_pure; - -cairo_private void -_cairo_surface_release_device_reference (cairo_surface_t *surface); - -/* cairo-image-surface.c */ - -/* XXX: In cairo 1.2.0 we added a new %CAIRO_FORMAT_RGB16_565 but - * neglected to adjust this macro. The net effect is that it's - * impossible to externally create an image surface with this - * format. This is perhaps a good thing since we also neglected to fix - * up things like cairo_surface_write_to_png() for the new format - * (-Wswitch-enum will tell you where). Is it obvious that format was - * added in haste? - * - * The reason for the new format was to allow the xlib backend to be - * used on X servers with a 565 visual. So the new format did its job - * for that, even without being considered "valid" for the sake of - * things like cairo_image_surface_create(). - * - * Since 1.2.0 we ran into the same situtation with X servers with BGR - * visuals. This time we invented #cairo_internal_format_t instead, - * (see it for more discussion). - * - * The punchline is that %CAIRO_FORMAT_VALID must not conside any - * internal format to be valid. Also we need to decide if the - * RGB16_565 should be moved to instead be an internal format. If so, - * this macro need not change for it. (We probably will need to leave - * an RGB16_565 value in the header files for the sake of code that - * might have that value in it.) - * - * If we do decide to start fully supporting RGB16_565 as an external - * format, then %CAIRO_FORMAT_VALID needs to be adjusted to include - * it. But that should not happen before all necessary code is fixed - * to support it (at least cairo_surface_write_to_png() and a few spots - * in cairo-xlib-surface.c--again see -Wswitch-enum). - */ -#define CAIRO_FORMAT_VALID(format) ((format) >= CAIRO_FORMAT_ARGB32 && \ - (format) <= CAIRO_FORMAT_RGB30) - -/* pixman-required stride alignment in bytes. */ -#define CAIRO_STRIDE_ALIGNMENT (sizeof (uint32_t)) -#define CAIRO_STRIDE_FOR_WIDTH_BPP(w,bpp) \ - ((((bpp)*(w)+7)/8 + CAIRO_STRIDE_ALIGNMENT-1) & -CAIRO_STRIDE_ALIGNMENT) - -#define CAIRO_CONTENT_VALID(content) ((content) && \ - (((content) & ~(CAIRO_CONTENT_COLOR | \ - CAIRO_CONTENT_ALPHA | \ - CAIRO_CONTENT_COLOR_ALPHA))\ - == 0)) - -cairo_private int -_cairo_format_bits_per_pixel (cairo_format_t format) cairo_const; - -cairo_private cairo_format_t -_cairo_format_from_content (cairo_content_t content) cairo_const; - -cairo_private cairo_format_t -_cairo_format_from_pixman_format (pixman_format_code_t pixman_format); - -cairo_private cairo_content_t -_cairo_content_from_format (cairo_format_t format) cairo_const; - -cairo_private cairo_content_t -_cairo_content_from_pixman_format (pixman_format_code_t pixman_format); - -cairo_private cairo_surface_t * -_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image, - pixman_format_code_t pixman_format); - -cairo_private pixman_format_code_t -_cairo_format_to_pixman_format_code (cairo_format_t format); - -cairo_private cairo_bool_t -_pixman_format_from_masks (cairo_format_masks_t *masks, - pixman_format_code_t *format_ret); - -cairo_private cairo_bool_t -_pixman_format_to_masks (pixman_format_code_t pixman_format, - cairo_format_masks_t *masks); - -cairo_private void -_cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, - cairo_scaled_glyph_t *scaled_glyph); - -cairo_private void -_cairo_image_reset_static_data (void); - -cairo_private cairo_surface_t * -_cairo_image_surface_create_with_pixman_format (unsigned char *data, - pixman_format_code_t pixman_format, - int width, - int height, - int stride); - -cairo_private cairo_surface_t * -_cairo_image_surface_create_with_content (cairo_content_t content, - int width, - int height); - -cairo_private void -_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface); - -cairo_private cairo_image_surface_t * -_cairo_image_surface_coerce (cairo_image_surface_t *surface); - -cairo_private cairo_image_surface_t * -_cairo_image_surface_coerce_to_format (cairo_image_surface_t *surface, - cairo_format_t format); - -cairo_private cairo_image_transparency_t -_cairo_image_analyze_transparency (cairo_image_surface_t *image); - -cairo_private cairo_image_color_t -_cairo_image_analyze_color (cairo_image_surface_t *image); - -/* cairo-pen.c */ -cairo_private int -_cairo_pen_vertices_needed (double tolerance, - double radius, - const cairo_matrix_t *matrix); - -cairo_private cairo_status_t -_cairo_pen_init (cairo_pen_t *pen, - double radius, - double tolerance, - const cairo_matrix_t *ctm); - -cairo_private void -_cairo_pen_init_empty (cairo_pen_t *pen); - -cairo_private cairo_status_t -_cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other); - -cairo_private void -_cairo_pen_fini (cairo_pen_t *pen); - -cairo_private cairo_status_t -_cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points); - -cairo_private int -_cairo_pen_find_active_cw_vertex_index (const cairo_pen_t *pen, - const cairo_slope_t *slope); - -cairo_private int -_cairo_pen_find_active_ccw_vertex_index (const cairo_pen_t *pen, - const cairo_slope_t *slope); - -cairo_private void -_cairo_pen_find_active_cw_vertices (const cairo_pen_t *pen, - const cairo_slope_t *in, - const cairo_slope_t *out, - int *start, int *stop); - -cairo_private void -_cairo_pen_find_active_ccw_vertices (const cairo_pen_t *pen, - const cairo_slope_t *in, - const cairo_slope_t *out, - int *start, int *stop); - -/* cairo-polygon.c */ -cairo_private void -_cairo_polygon_init (cairo_polygon_t *polygon, - const cairo_box_t *boxes, - int num_boxes); - -cairo_private void -_cairo_polygon_init_with_clip (cairo_polygon_t *polygon, - const cairo_clip_t *clip); - -cairo_private cairo_status_t -_cairo_polygon_init_boxes (cairo_polygon_t *polygon, - const cairo_boxes_t *boxes); - -cairo_private cairo_status_t -_cairo_polygon_init_box_array (cairo_polygon_t *polygon, - cairo_box_t *boxes, - int num_boxes); - -cairo_private void -_cairo_polygon_limit (cairo_polygon_t *polygon, - const cairo_box_t *limits, - int num_limits); - -cairo_private void -_cairo_polygon_limit_to_clip (cairo_polygon_t *polygon, - const cairo_clip_t *clip); - -cairo_private void -_cairo_polygon_fini (cairo_polygon_t *polygon); - -cairo_private_no_warn cairo_status_t -_cairo_polygon_add_line (cairo_polygon_t *polygon, - const cairo_line_t *line, - int top, int bottom, - int dir); - -cairo_private_no_warn cairo_status_t -_cairo_polygon_add_external_edge (void *polygon, - const cairo_point_t *p1, - const cairo_point_t *p2); - -cairo_private_no_warn cairo_status_t -_cairo_polygon_add_contour (cairo_polygon_t *polygon, - const cairo_contour_t *contour); - -cairo_private void -_cairo_polygon_translate (cairo_polygon_t *polygon, int dx, int dy); - -cairo_private cairo_status_t -_cairo_polygon_reduce (cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_status_t -_cairo_polygon_intersect (cairo_polygon_t *a, int winding_a, - cairo_polygon_t *b, int winding_b); - -cairo_private cairo_status_t -_cairo_polygon_intersect_with_boxes (cairo_polygon_t *polygon, - cairo_fill_rule_t *winding, - cairo_box_t *boxes, - int num_boxes); - -static inline cairo_bool_t -_cairo_polygon_is_empty (const cairo_polygon_t *polygon) -{ - return - polygon->num_edges == 0 || - polygon->extents.p2.x <= polygon->extents.p1.x; -} - -#define _cairo_polygon_status(P) ((cairo_polygon_t *) (P))->status - -/* cairo-spline.c */ -cairo_private cairo_bool_t -_cairo_spline_init (cairo_spline_t *spline, - cairo_spline_add_point_func_t add_point_func, - void *closure, - const cairo_point_t *a, const cairo_point_t *b, - const cairo_point_t *c, const cairo_point_t *d); - -cairo_private cairo_status_t -_cairo_spline_decompose (cairo_spline_t *spline, double tolerance); - -cairo_private cairo_status_t -_cairo_spline_bound (cairo_spline_add_point_func_t add_point_func, - void *closure, - const cairo_point_t *p0, const cairo_point_t *p1, - const cairo_point_t *p2, const cairo_point_t *p3); - -/* cairo-matrix.c */ -cairo_private void -_cairo_matrix_get_affine (const cairo_matrix_t *matrix, - double *xx, double *yx, - double *xy, double *yy, - double *x0, double *y0); - -cairo_private void -_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix, - double *x1, double *y1, - double *x2, double *y2, - cairo_bool_t *is_tight); - -cairo_private void -_cairo_matrix_transform_bounding_box_fixed (const cairo_matrix_t *matrix, - cairo_box_t *bbox, - cairo_bool_t *is_tight); - -cairo_private cairo_bool_t -_cairo_matrix_is_invertible (const cairo_matrix_t *matrix) cairo_pure; - -cairo_private cairo_bool_t -_cairo_matrix_is_scale_0 (const cairo_matrix_t *matrix) cairo_pure; - -cairo_private double -_cairo_matrix_compute_determinant (const cairo_matrix_t *matrix) cairo_pure; - -cairo_private cairo_status_t -_cairo_matrix_compute_basis_scale_factors (const cairo_matrix_t *matrix, - double *sx, double *sy, int x_major); - -static inline cairo_bool_t -_cairo_matrix_is_identity (const cairo_matrix_t *matrix) -{ - return (matrix->xx == 1.0 && matrix->yx == 0.0 && - matrix->xy == 0.0 && matrix->yy == 1.0 && - matrix->x0 == 0.0 && matrix->y0 == 0.0); -} - -static inline cairo_bool_t -_cairo_matrix_is_translation (const cairo_matrix_t *matrix) -{ - return (matrix->xx == 1.0 && matrix->yx == 0.0 && - matrix->xy == 0.0 && matrix->yy == 1.0); -} - -static inline cairo_bool_t -_cairo_matrix_is_scale (const cairo_matrix_t *matrix) -{ - return matrix->yx == 0.0 && matrix->xy == 0.0; -} - -cairo_private cairo_bool_t -_cairo_matrix_is_integer_translation(const cairo_matrix_t *matrix, - int *itx, int *ity); - -cairo_private cairo_bool_t -_cairo_matrix_has_unity_scale (const cairo_matrix_t *matrix); - -cairo_private cairo_bool_t -_cairo_matrix_is_pixel_exact (const cairo_matrix_t *matrix) cairo_pure; - -cairo_private double -_cairo_matrix_transformed_circle_major_axis (const cairo_matrix_t *matrix, - double radius) cairo_pure; - -cairo_private cairo_bool_t -_cairo_matrix_is_pixman_translation (const cairo_matrix_t *matrix, - cairo_filter_t filter, - int *out_x_offset, - int *out_y_offset); - -cairo_private cairo_status_t -_cairo_matrix_to_pixman_matrix_offset (const cairo_matrix_t *matrix, - cairo_filter_t filter, - double xc, - double yc, - pixman_transform_t *out_transform, - int *out_x_offset, - int *out_y_offset); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_rectilinear_polygon (cairo_traps_t *traps, - const cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t *traps, - const cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_traps (cairo_traps_t *traps, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_rectangular_traps (cairo_traps_t *traps, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_boxes (const cairo_boxes_t *in, - cairo_fill_rule_t fill_rule, - cairo_boxes_t *out); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_rectilinear_traps (cairo_traps_t *traps, - cairo_fill_rule_t fill_rule); - -cairo_private cairo_status_t -_cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (const cairo_polygon_t *polygon, - cairo_fill_rule_t fill_rule, - cairo_boxes_t *boxes); - -cairo_private void -_cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps, - cairo_trapezoid_t *src_traps, - int num_traps, - double tx, double ty, - double sx, double sy); - -#if CAIRO_HAS_DRM_SURFACE - -cairo_private void -_cairo_drm_device_reset_static_data (void); - -#endif - -cairo_private void -_cairo_clip_reset_static_data (void); - -cairo_private void -_cairo_pattern_reset_static_data (void); - -/* cairo-unicode.c */ - -cairo_private int -_cairo_utf8_get_char_validated (const char *p, - uint32_t *unicode); - -cairo_private cairo_status_t -_cairo_utf8_to_ucs4 (const char *str, - int len, - uint32_t **result, - int *items_written); - -cairo_private int -_cairo_ucs4_to_utf8 (uint32_t unicode, - char *utf8); - -#if CAIRO_HAS_WIN32_FONT || CAIRO_HAS_QUARTZ_FONT || CAIRO_HAS_PDF_OPERATORS -# define CAIRO_HAS_UTF8_TO_UTF16 1 -#endif -#if CAIRO_HAS_UTF8_TO_UTF16 -cairo_private cairo_status_t -_cairo_utf8_to_utf16 (const char *str, - int len, - uint16_t **result, - int *items_written); -#endif - -cairo_private void -_cairo_matrix_multiply (cairo_matrix_t *r, - const cairo_matrix_t *a, - const cairo_matrix_t *b); - -/* cairo-observer.c */ - -cairo_private void -_cairo_observers_notify (cairo_list_t *observers, void *arg); - -/* Avoid unnecessary PLT entries. */ -slim_hidden_proto (cairo_clip_preserve); -slim_hidden_proto (cairo_close_path); -slim_hidden_proto (cairo_create); -slim_hidden_proto (cairo_curve_to); -slim_hidden_proto (cairo_destroy); -slim_hidden_proto (cairo_fill_preserve); -slim_hidden_proto (cairo_font_face_destroy); -slim_hidden_proto (cairo_font_face_get_user_data); -slim_hidden_proto_no_warn (cairo_font_face_reference); -slim_hidden_proto (cairo_font_face_set_user_data); -slim_hidden_proto (cairo_font_options_equal); -slim_hidden_proto (cairo_font_options_hash); -slim_hidden_proto (cairo_font_options_merge); -slim_hidden_proto (cairo_font_options_set_antialias); -slim_hidden_proto (cairo_font_options_set_hint_metrics); -slim_hidden_proto (cairo_font_options_set_hint_style); -slim_hidden_proto (cairo_font_options_set_subpixel_order); -slim_hidden_proto (cairo_font_options_status); -slim_hidden_proto (cairo_format_stride_for_width); -slim_hidden_proto (cairo_get_current_point); -slim_hidden_proto (cairo_get_line_width); -slim_hidden_proto (cairo_get_matrix); -slim_hidden_proto (cairo_get_scaled_font); -slim_hidden_proto (cairo_get_target); -slim_hidden_proto (cairo_get_tolerance); -slim_hidden_proto (cairo_glyph_allocate); -slim_hidden_proto (cairo_glyph_free); -slim_hidden_proto (cairo_image_surface_create); -slim_hidden_proto (cairo_image_surface_create_for_data); -slim_hidden_proto (cairo_image_surface_get_data); -slim_hidden_proto (cairo_image_surface_get_format); -slim_hidden_proto (cairo_image_surface_get_height); -slim_hidden_proto (cairo_image_surface_get_stride); -slim_hidden_proto (cairo_image_surface_get_width); -slim_hidden_proto (cairo_line_to); -slim_hidden_proto (cairo_mask); -slim_hidden_proto (cairo_matrix_init); -slim_hidden_proto (cairo_matrix_init_identity); -slim_hidden_proto (cairo_matrix_init_rotate); -slim_hidden_proto (cairo_matrix_init_scale); -slim_hidden_proto (cairo_matrix_init_translate); -slim_hidden_proto (cairo_matrix_invert); -slim_hidden_proto (cairo_matrix_multiply); -slim_hidden_proto (cairo_matrix_scale); -slim_hidden_proto (cairo_matrix_transform_distance); -slim_hidden_proto (cairo_matrix_transform_point); -slim_hidden_proto (cairo_matrix_translate); -slim_hidden_proto (cairo_move_to); -slim_hidden_proto (cairo_new_path); -slim_hidden_proto (cairo_paint); -slim_hidden_proto (cairo_pattern_add_color_stop_rgba); -slim_hidden_proto (cairo_pattern_create_for_surface); -slim_hidden_proto (cairo_pattern_create_rgb); -slim_hidden_proto (cairo_pattern_create_rgba); -slim_hidden_proto (cairo_pattern_destroy); -slim_hidden_proto (cairo_pattern_get_extend); -slim_hidden_proto (cairo_mesh_pattern_curve_to); -slim_hidden_proto (cairo_mesh_pattern_get_control_point); -slim_hidden_proto (cairo_mesh_pattern_get_corner_color_rgba); -slim_hidden_proto (cairo_mesh_pattern_get_patch_count); -slim_hidden_proto (cairo_mesh_pattern_get_path); -slim_hidden_proto (cairo_mesh_pattern_line_to); -slim_hidden_proto (cairo_mesh_pattern_move_to); -slim_hidden_proto (cairo_mesh_pattern_set_corner_color_rgba); -slim_hidden_proto_no_warn (cairo_pattern_reference); -slim_hidden_proto (cairo_pattern_set_matrix); -slim_hidden_proto (cairo_pop_group); -slim_hidden_proto (cairo_push_group_with_content); -slim_hidden_proto_no_warn (cairo_path_destroy); -slim_hidden_proto (cairo_recording_surface_create); -slim_hidden_proto (cairo_rel_line_to); -slim_hidden_proto (cairo_restore); -slim_hidden_proto (cairo_save); -slim_hidden_proto (cairo_scale); -slim_hidden_proto (cairo_scaled_font_create); -slim_hidden_proto (cairo_scaled_font_destroy); -slim_hidden_proto (cairo_scaled_font_extents); -slim_hidden_proto (cairo_scaled_font_get_ctm); -slim_hidden_proto (cairo_scaled_font_get_font_face); -slim_hidden_proto (cairo_scaled_font_get_font_matrix); -slim_hidden_proto (cairo_scaled_font_get_font_options); -slim_hidden_proto (cairo_scaled_font_glyph_extents); -slim_hidden_proto_no_warn (cairo_scaled_font_reference); -slim_hidden_proto (cairo_scaled_font_status); -slim_hidden_proto (cairo_scaled_font_get_user_data); -slim_hidden_proto (cairo_scaled_font_set_user_data); -slim_hidden_proto (cairo_scaled_font_text_to_glyphs); -slim_hidden_proto (cairo_set_font_matrix); -slim_hidden_proto (cairo_set_font_options); -slim_hidden_proto (cairo_set_font_size); -slim_hidden_proto (cairo_set_line_cap); -slim_hidden_proto (cairo_set_line_join); -slim_hidden_proto (cairo_set_line_width); -slim_hidden_proto (cairo_set_matrix); -slim_hidden_proto (cairo_set_operator); -slim_hidden_proto (cairo_set_source); -slim_hidden_proto (cairo_set_source_rgb); -slim_hidden_proto (cairo_set_source_surface); -slim_hidden_proto (cairo_set_tolerance); -slim_hidden_proto (cairo_status); -slim_hidden_proto (cairo_stroke); -slim_hidden_proto (cairo_stroke_preserve); -slim_hidden_proto (cairo_surface_copy_page); -slim_hidden_proto (cairo_surface_create_similar_image); -slim_hidden_proto (cairo_surface_destroy); -slim_hidden_proto (cairo_surface_finish); -slim_hidden_proto (cairo_surface_flush); -slim_hidden_proto (cairo_surface_get_device_offset); -slim_hidden_proto (cairo_surface_get_device_scale); -slim_hidden_proto (cairo_surface_get_font_options); -slim_hidden_proto (cairo_surface_get_mime_data); -slim_hidden_proto (cairo_surface_has_show_text_glyphs); -slim_hidden_proto (cairo_surface_mark_dirty); -slim_hidden_proto (cairo_surface_mark_dirty_rectangle); -slim_hidden_proto_no_warn (cairo_surface_reference); -slim_hidden_proto (cairo_surface_set_device_offset); -slim_hidden_proto (cairo_surface_set_device_scale); -slim_hidden_proto (cairo_surface_set_fallback_resolution); -slim_hidden_proto (cairo_surface_set_mime_data); -slim_hidden_proto (cairo_surface_show_page); -slim_hidden_proto (cairo_surface_status); -slim_hidden_proto (cairo_surface_supports_mime_type); -slim_hidden_proto (cairo_text_cluster_allocate); -slim_hidden_proto (cairo_text_cluster_free); -slim_hidden_proto (cairo_toy_font_face_create); -slim_hidden_proto (cairo_toy_font_face_get_slant); -slim_hidden_proto (cairo_toy_font_face_get_weight); -slim_hidden_proto (cairo_translate); -slim_hidden_proto (cairo_transform); -slim_hidden_proto (cairo_user_font_face_create); -slim_hidden_proto (cairo_user_font_face_set_init_func); -slim_hidden_proto (cairo_user_font_face_set_render_glyph_func); -slim_hidden_proto (cairo_user_font_face_set_unicode_to_glyph_func); -slim_hidden_proto (cairo_device_to_user); -slim_hidden_proto (cairo_user_to_device); -slim_hidden_proto (cairo_user_to_device_distance); -slim_hidden_proto (cairo_version_string); -slim_hidden_proto (cairo_region_create); -slim_hidden_proto (cairo_region_create_rectangle); -slim_hidden_proto (cairo_region_create_rectangles); -slim_hidden_proto (cairo_region_copy); -slim_hidden_proto (cairo_region_reference); -slim_hidden_proto (cairo_region_destroy); -slim_hidden_proto (cairo_region_equal); -slim_hidden_proto (cairo_region_status); -slim_hidden_proto (cairo_region_get_extents); -slim_hidden_proto (cairo_region_num_rectangles); -slim_hidden_proto (cairo_region_get_rectangle); -slim_hidden_proto (cairo_region_is_empty); -slim_hidden_proto (cairo_region_contains_rectangle); -slim_hidden_proto (cairo_region_contains_point); -slim_hidden_proto (cairo_region_translate); -slim_hidden_proto (cairo_region_subtract); -slim_hidden_proto (cairo_region_subtract_rectangle); -slim_hidden_proto (cairo_region_intersect); -slim_hidden_proto (cairo_region_intersect_rectangle); -slim_hidden_proto (cairo_region_union); -slim_hidden_proto (cairo_region_union_rectangle); -slim_hidden_proto (cairo_region_xor); -slim_hidden_proto (cairo_region_xor_rectangle); - -#if CAIRO_HAS_PNG_FUNCTIONS - -slim_hidden_proto (cairo_surface_write_to_png_stream); - -#endif - -CAIRO_END_DECLS - -#include "cairo-mutex-private.h" -#include "cairo-fixed-private.h" -#include "cairo-wideint-private.h" -#include "cairo-malloc-private.h" -#include "cairo-hash-private.h" - -#if HAVE_VALGRIND -#include - -#define VG(x) x - -cairo_private void -_cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface); - -#else - -#define VG(x) -#define _cairo_debug_check_image_surface_is_defined(X) - -#endif - -cairo_private void -_cairo_debug_print_path (FILE *stream, cairo_path_fixed_t *path); - -cairo_private void -_cairo_debug_print_polygon (FILE *stream, cairo_polygon_t *polygon); - -cairo_private void -_cairo_debug_print_traps (FILE *file, const cairo_traps_t *traps); - -cairo_private void -_cairo_debug_print_clip (FILE *stream, const cairo_clip_t *clip); - -#if 0 -#define TRACE(x) fprintf (stderr, "%s: ", __FILE__), fprintf x -#define TRACE_(x) x -#else -#define TRACE(x) -#define TRACE_(x) -#endif - -#endif diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-def.sh b/Build/source/libs/cairo/cairo-1.14.2/src/check-def.sh deleted file mode 100755 index beefb46a333..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-def.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -LC_ALL=C -export LC_ALL - -if which nm 2>/dev/null >/dev/null; then - : -else - echo "'nm' not found; skipping test" - exit 0 -fi - -test -z "$srcdir" && srcdir=. -test -z "$MAKE" && MAKE=make -stat=0 - -$MAKE check-has-hidden-symbols.i > /dev/null || exit 1 -if tail -1 check-has-hidden-symbols.i | grep CAIRO_HAS_HIDDEN_SYMBOLS >/dev/null; then - echo "Compiler doesn't support symbol visibility; skipping test" - exit 0 -fi - -if [ "`uname -s`" = "Linux" ]; then - get_cairo_syms='( objdump -t "$so" | grep "^[^ ]* [^l.*]*[.]"; objdump -t "$so" | grep "[.]hidden.*\\ /dev/null -for def in $defs; do - lib=`echo "$def" | sed 's/[.]def$//'` - lib=`echo "$lib" | sed 's@.*/@@'` - so=.libs/lib${lib}.so - - test -f "$so" || continue - - echo Checking that $so has the same symbol list as $def - - { - echo EXPORTS - eval $get_cairo_syms | c++filt --no-params | grep -v '^_cairo_test_\|^_fini\|^_init\|^_save[fg]pr\|^_rest[fg]pr\|^_Z\|^__gnu\|^__bss\|^_edata\|^_end' | sort -u - # cheat: copy the last line from the def file! - tail -n1 "$def" - } | diff "$def" - >&2 || stat=1 -done - -exit $stat diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.awk b/Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.awk deleted file mode 100755 index 1fa8b8d2232..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.awk +++ /dev/null @@ -1,106 +0,0 @@ -BEGIN { - name_found = 1 - SECTION_DOC = 0 - PUBLIC_DOC = 1 - PRIVATE_DOC = 2 -} - -function log_msg(severity, msg) -{ - printf "%s (%d): %s: %s %s\n", FILENAME, FNR, severity, doc_name, msg -} - -function log_error(msg) -{ - log_msg("ERROR", msg) -} - -function log_warning(msg) -{ - log_msg("WARNING", msg) -} - -/^\/\*\*$/ { - in_doc = 1 - doc_line = 0 -} - -/^(\/\*\*$| \*[ \t]| \*$| \*\*\/$)/ { - valid_doc = 1 -} - -in_doc { - if (!valid_doc) - log_error("bad line: '" $0 "'") - valid_doc = 0 - - doc_line++ - if (doc_line == 2) { - # new doc name. Did we find the previous one? - # (macros are not expected to be found in the same place as - # their documentation) - if (!name_found && doc_name !~ /CAIRO_/) - log_warning("not found") - doc_name = $2 - if (doc_name ~ /^SECTION:.*$/) { - doc_type = SECTION_DOC - name_found = 1 - } else if (tolower(doc_name) ~ /^cairo_[a-z0-9_]*:$/) { - doc_type = PUBLIC_DOC - name_found = 0 - real_name = substr(doc_name, 1, length(doc_name) - 1) - } else if (tolower(doc_name) ~ /^_[a-z0-9_]*:$/) { - doc_type = PRIVATE_DOC - name_found = 0 - real_name = substr(doc_name, 1, length(doc_name) - 1) - } else { - log_error("invalid doc id (should be 'cairo_...:')") - name_found = 1 - } - } -} - -!in_doc { - regex = "(^|[ \\t\\*])" real_name "([ ;()]|$)" - if ($0 ~ regex) - name_found = 1 -} - -/^ \* Since: ([0-9]*.[0-9]*|TBD)$/ { - if (doc_has_since != 0) { - log_error("Duplicate 'Since' field") - } - doc_has_since = doc_line -} - -/^ \*\*\// { - if (doc_type == PUBLIC_DOC) { - if (!doc_has_since) { - # private types can start with cairo_ - if (doc_name ~ /^cairo_.*_t:$/) - log_warning("missing 'Since' field (is it a private type?)") - else - log_error("missing 'Since' field") - } else if (doc_has_since != doc_line - 1) - log_warning("misplaced 'Since' field (should be right before the end of the comment)") - } else { - if (doc_has_since) - log_warning("'Since' field in non-public element") - } - - in_doc = 0 - doc_has_since = 0 - doc_type = 0 -} - -/\*\// { - if (in_doc) { - in_doc = 0 - log_error("documentation comment not closed with **/") - } -} - -END { - if (!name_found) - log_warning("not found") -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.sh b/Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.sh deleted file mode 100755 index 762a48429b0..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-doc-syntax.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/sh - -LC_ALL=C -export LC_ALL - -if grep --version 2>/dev/null | grep GNU >/dev/null; then - : -else - echo "GNU grep not found; skipping test" - exit 0 -fi - -test -z "$srcdir" && srcdir=. -stat=0 - -echo Checking documentation for incorrect syntax - -cd "$srcdir" - -if test "x$SGML_DOCS" = x; then - FILES=$all_cairo_files - if test "x$FILES" = x; then - FILES=`find . -name 'cairo*.h' -or -name 'cairo*.c' -or -name 'cairo*.cpp'` - fi -fi - -enum_regexp="\([^%@']\|^\)\<\(FALSE\|TRUE\|NULL\|CAIRO_[0-9A-Z_]*\)\($\|[^(A-Za-z0-9_]\)" -if test "x$SGML_DOCS" = x; then - enum_regexp='^[^:]*:[/ ][*]\(\|[ \t].*\)'$enum_regexp\($\|[^:]\) -fi -if echo $FILES | xargs grep . /dev/null | sed -e '//,/<\/programlisting>/d' | grep "$enum_regexp" | grep -v '#####'; then - stat=1 - echo Error: some macros in the docs are not prefixed by percent sign. - echo Fix this by searching for the following regexp in the above files: - echo " '$enum_regexp'" -fi >&2 - -type_regexp="\( .*[^#']\| \|^\)\\($\|[^:]$\|[^:].\)" -if test "x$SGML_DOCS" = x; then - type_regexp='^[^:]*:[/ ][*]'$type_regexp -else - type_regexp='\(.'$type_regexp'\)\|\('$type_regexp'.\)' -fi - -if echo $FILES | xargs grep . /dev/null | sed -e '//,/<\/programlisting>/d' | grep -v "@Title" | grep "$type_regexp" | grep -v '#####'; then - stat=1 - echo Error: some type names in the docs are not prefixed by hash sign, - echo neither are the only token in the doc line followed by colon. - echo Fix this by searching for the following regexp in the above files: - echo " '$type_regexp'" -fi >&2 - -func_regexp="\([^#']\|^\)\<\(cairo_[][<>/0-9a-z_]*\>[^][<>(]\)" -if test "x$SGML_DOCS" = x; then - func_regexp='^[^:]*:[/ ][*]\(\|[ \t].*\)'$func_regexp -fi - -# We need to filter out gtk-doc markup errors for program listings. -if echo $FILES | xargs grep . /dev/null | sed -e '//,/<\/programlisting>/d' | grep "$func_regexp" | grep -v '^[^:]*: [*] [a-z_0-9]*:$' | grep -v '#####'; then - stat=1 - echo Error: some function names in the docs are not followed by parentheses. - echo Fix this by searching for the following regexp in the above files: - echo " '$func_regexp'" -fi >&2 - -note_regexp='\' -if echo $FILES | xargs grep "$note_regexp" /dev/null; then - stat=1 - echo Error: some source files contain the string 'NOTE'. - echo Be civil and replace it by 'Note' please. -fi >&2 - -# Only run the syntax checker on the source files (not doc/) -if test -e ./check-doc-syntax.awk; then - if echo $FILES | xargs awk -f ./check-doc-syntax.awk ; then - : - else - stat=1 - fi >&2 -fi - -exit $stat diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-has-hidden-symbols.c b/Build/source/libs/cairo/cairo-1.14.2/src/check-has-hidden-symbols.c deleted file mode 100644 index 12041277692..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-has-hidden-symbols.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "cairoint.h" - -CAIRO_HAS_HIDDEN_SYMBOLS diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-headers.sh b/Build/source/libs/cairo/cairo-1.14.2/src/check-headers.sh deleted file mode 100755 index 61232954bae..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-headers.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -LC_ALL=C -export LC_ALL - -test -z "$srcdir" && srcdir=. -stat=0 - -echo Checking public headers for missing cairo_public decorators - -cd "$srcdir" -FILES=$all_cairo_headers -if test "x$FILES" = x; then - FILES=`find . -name 'cairo*.h' ! -name '*-private.h' ! -name 'cairoint.h'` -fi - -grep -B 1 '^cairo_.*[ ]\+(' /dev/null $FILES | -awk ' -/^--$/ { context=""; public=0; next; } -/:cairo_.*[ ]+\(/ { if (!public) {print context; print; print "--";} next; } -/-cairo_public.*[ ]/ {public=1;} -{ context=$0; } -' | -sed 's/[.]h-/.h:/' | -grep . >&2 && stat=1 - -exit $stat diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-link.c b/Build/source/libs/cairo/cairo-1.14.2/src/check-link.c deleted file mode 100644 index 66ca1b2413c..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-link.c +++ /dev/null @@ -1,24 +0,0 @@ -#define CAIRO_VERSION_H 1 - -#include - -/* get the "real" version info instead of dummy cairo-version.h */ -#undef CAIRO_VERSION_H -#include "../cairo-version.h" - -#include - -int -main (void) -{ - printf ("Check linking to the just built cairo library\n"); - if (cairo_version () == CAIRO_VERSION) { - return 0; - } else { - fprintf (stderr, - "Error: linked to cairo version %s instead of %s\n", - cairo_version_string (), - CAIRO_VERSION_STRING); - return 1; - } -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-plt.sh b/Build/source/libs/cairo/cairo-1.14.2/src/check-plt.sh deleted file mode 100755 index 5a9dae1269d..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-plt.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -LC_ALL=C -export LC_ALL - -if which readelf 2>/dev/null >/dev/null; then - : -else - echo "'readelf' not found; skipping test" - exit 0 -fi - -test -z "$srcdir" && srcdir=. -test -z "$MAKE" && MAKE=make -stat=0 - -$MAKE check-has-hidden-symbols.i > /dev/null || exit 1 -if tail -1 check-has-hidden-symbols.i | grep CAIRO_HAS_HIDDEN_SYMBOLS >/dev/null; then - echo "Compiler doesn't support symbol visibility; skipping test" - exit 0 -fi - -for so in .libs/lib*.so; do - echo Checking "$so" for local PLT entries - readelf -W -r "$so" | grep 'JU\?MP_SLO' | grep 'cairo' >&2 && stat=1 -done - -exit $stat diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/check-preprocessor-syntax.sh b/Build/source/libs/cairo/cairo-1.14.2/src/check-preprocessor-syntax.sh deleted file mode 100755 index b718f604ee7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/check-preprocessor-syntax.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh - -LC_ALL=C -export LC_ALL - -test -z "$srcdir" && srcdir=. -cd "$srcdir" -stat=0 - - -HEADERS=$all_cairo_headers -test "x$HEADERS" = x && HEADERS=`find . -name 'cairo*.h' ! -name 'cairo*-private.h' ! -name 'cairo*-inline.h' ! -name 'cairoint.h'` - -PRIVATE=$all_cairo_private -test "x$PRIVATE" = x && PRIVATE=`find . -name 'cairo*-private.h' -or -name 'cairo*-inline.h' -or -name 'cairoint.h'` - -SOURCES=$all_cairo_sources -test "x$SOURCES" = x && SOURCES=`find . -name 'cairo*.c' -or -name 'cairo*.cpp'` - -ALL="/dev/null $HEADERS $PRIVATE $SOURCES" - -echo 'Checking that public header files #include "cairo.h" first (or none)' - -for x in $HEADERS; do - grep '#.*\' "$x" /dev/null | head -n 1 -done | -grep -v '"cairo[.]h"' | -grep -v 'cairo[.]h:' | -grep . >&2 && stat=1 - - -echo 'Checking that private header files #include "some cairo header" first (or none)' - -for x in $PRIVATE; do - grep '#.*\' "$x" /dev/null | head -n 1 -done | -grep -v '"cairo.*[.]h"' | -grep -v 'cairoint[.]h:' | -grep . >&2 && stat=1 - - -echo 'Checking that source files #include "cairoint.h" first (or none)' - -for x in $SOURCES; do - grep '#.*\' "$x" /dev/null | head -n 1 -done | -grep -v '"cairoint[.]h"' | -grep . >&2 && stat=1 - - -echo 'Checking that there is no #include ' -grep '#.*\.*<.*cairo' $ALL >&2 && stat=1 - - -echo 'Checking that feature conditionals are used with #if only (not #ifdef)' -grep '#ifdef CAIRO_HAS_' $ALL && stat=1 -grep '#if.*defined[ ]*(CAIRO_HAS_' $ALL && stat=1 - -exit $stat diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-base-compositor-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/test-base-compositor-surface.c deleted file mode 100644 index ff84b10aff7..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-base-compositor-surface.c +++ /dev/null @@ -1,824 +0,0 @@ -/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2002 University of Southern California - * Copyright © 2005 Red Hat, Inc. - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is University of Southern - * California. - * - * Contributor(s): - * Carl D. Worth - * Joonas Pihlaja - * Chris Wilson - */ - -#include "cairoint.h" - -#include "test-compositor-surface-private.h" - -#include "cairo-clip-private.h" -#include "cairo-composite-rectangles-private.h" -#include "cairo-compositor-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-region-private.h" -#include "cairo-traps-private.h" - -/* The intention is that this is a surface that just works, and most - * important of all does not try to be clever! - */ - -typedef cairo_int_status_t -(*draw_func_t) (cairo_image_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents); - -static pixman_op_t -_pixman_operator (cairo_operator_t op) -{ - switch ((int) op) { - case CAIRO_OPERATOR_CLEAR: - return PIXMAN_OP_CLEAR; - - case CAIRO_OPERATOR_SOURCE: - return PIXMAN_OP_SRC; - case CAIRO_OPERATOR_OVER: - return PIXMAN_OP_OVER; - case CAIRO_OPERATOR_IN: - return PIXMAN_OP_IN; - case CAIRO_OPERATOR_OUT: - return PIXMAN_OP_OUT; - case CAIRO_OPERATOR_ATOP: - return PIXMAN_OP_ATOP; - - case CAIRO_OPERATOR_DEST: - return PIXMAN_OP_DST; - case CAIRO_OPERATOR_DEST_OVER: - return PIXMAN_OP_OVER_REVERSE; - case CAIRO_OPERATOR_DEST_IN: - return PIXMAN_OP_IN_REVERSE; - case CAIRO_OPERATOR_DEST_OUT: - return PIXMAN_OP_OUT_REVERSE; - case CAIRO_OPERATOR_DEST_ATOP: - return PIXMAN_OP_ATOP_REVERSE; - - case CAIRO_OPERATOR_XOR: - return PIXMAN_OP_XOR; - case CAIRO_OPERATOR_ADD: - return PIXMAN_OP_ADD; - case CAIRO_OPERATOR_SATURATE: - return PIXMAN_OP_SATURATE; - - case CAIRO_OPERATOR_MULTIPLY: - return PIXMAN_OP_MULTIPLY; - case CAIRO_OPERATOR_SCREEN: - return PIXMAN_OP_SCREEN; - case CAIRO_OPERATOR_OVERLAY: - return PIXMAN_OP_OVERLAY; - case CAIRO_OPERATOR_DARKEN: - return PIXMAN_OP_DARKEN; - case CAIRO_OPERATOR_LIGHTEN: - return PIXMAN_OP_LIGHTEN; - case CAIRO_OPERATOR_COLOR_DODGE: - return PIXMAN_OP_COLOR_DODGE; - case CAIRO_OPERATOR_COLOR_BURN: - return PIXMAN_OP_COLOR_BURN; - case CAIRO_OPERATOR_HARD_LIGHT: - return PIXMAN_OP_HARD_LIGHT; - case CAIRO_OPERATOR_SOFT_LIGHT: - return PIXMAN_OP_SOFT_LIGHT; - case CAIRO_OPERATOR_DIFFERENCE: - return PIXMAN_OP_DIFFERENCE; - case CAIRO_OPERATOR_EXCLUSION: - return PIXMAN_OP_EXCLUSION; - case CAIRO_OPERATOR_HSL_HUE: - return PIXMAN_OP_HSL_HUE; - case CAIRO_OPERATOR_HSL_SATURATION: - return PIXMAN_OP_HSL_SATURATION; - case CAIRO_OPERATOR_HSL_COLOR: - return PIXMAN_OP_HSL_COLOR; - case CAIRO_OPERATOR_HSL_LUMINOSITY: - return PIXMAN_OP_HSL_LUMINOSITY; - - default: - ASSERT_NOT_REACHED; - return PIXMAN_OP_OVER; - } -} - -static cairo_image_surface_t * -create_composite_mask (cairo_image_surface_t *dst, - void *draw_closure, - draw_func_t draw_func, - const cairo_composite_rectangles_t *extents) -{ - cairo_image_surface_t *surface; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - surface = (cairo_image_surface_t *) - _cairo_image_surface_create_with_pixman_format (NULL, PIXMAN_a8, - extents->bounded.width, - extents->bounded.height, - 0); - if (unlikely (surface->base.status)) - return surface; - - status = draw_func (surface, draw_closure, - CAIRO_OPERATOR_ADD, &_cairo_pattern_white.base, - extents->bounded.x, extents->bounded.y, - &extents->bounded); - if (unlikely (status)) - goto error; - - status = _cairo_clip_combine_with_surface (extents->clip, - &surface->base, - extents->bounded.x, - extents->bounded.y); - if (unlikely (status)) - goto error; - - return surface; - -error: - cairo_surface_destroy (&surface->base); - return (cairo_image_surface_t *)_cairo_surface_create_in_error (status); -} - -/* Handles compositing with a clip surface when the operator allows - * us to combine the clip with the mask - */ -static cairo_status_t -clip_and_composite_with_mask (const cairo_composite_rectangles_t*extents, - draw_func_t draw_func, - void *draw_closure) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; - cairo_image_surface_t *mask; - pixman_image_t *src; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - int src_x, src_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - mask = create_composite_mask (dst, draw_closure, draw_func, extents); - if (unlikely (mask->base.status)) - return mask->base.status; - - src = _pixman_image_for_pattern (dst, - &extents->source_pattern.base, FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (unlikely (src == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto error; - } - - pixman_image_composite32 (_pixman_operator (extents->op), - src, mask->pixman_image, dst->pixman_image, - extents->bounded.x + src_x, - extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - pixman_image_unref (src); -error: - cairo_surface_destroy (&mask->base); - return status; -} - -/* Handles compositing with a clip surface when we have to do the operation - * in two pieces and combine them together. - */ -static cairo_status_t -clip_and_composite_combine (const cairo_composite_rectangles_t*extents, - draw_func_t draw_func, - void *draw_closure) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; - cairo_image_surface_t *tmp, *clip; - int clip_x, clip_y; - cairo_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - tmp = (cairo_image_surface_t *) - _cairo_image_surface_create_with_pixman_format (NULL, - dst->pixman_format, - extents->bounded.width, - extents->bounded.height, - 0); - if (unlikely (tmp->base.status)) - return tmp->base.status; - - pixman_image_composite32 (PIXMAN_OP_SRC, - dst->pixman_image, NULL, tmp->pixman_image, - extents->bounded.x, extents->bounded.y, - 0, 0, - 0, 0, - extents->bounded.width, extents->bounded.height); - - status = draw_func (tmp, draw_closure, - extents->op, &extents->source_pattern.base, - extents->bounded.x, extents->bounded.y, - &extents->bounded); - if (unlikely (status)) - goto error; - - clip = (cairo_image_surface_t *) - _cairo_clip_get_surface (extents->clip, &dst->base, &clip_x, &clip_y); - if (unlikely (clip->base.status)) - goto error; - - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - clip->pixman_image, NULL, dst->pixman_image, - extents->bounded.x - clip_x, extents->bounded.y - clip_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - pixman_image_composite32 (PIXMAN_OP_ADD, - tmp->pixman_image, clip->pixman_image, dst->pixman_image, - 0, 0, - extents->bounded.x - clip_x, extents->bounded.y - clip_y, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - cairo_surface_destroy (&clip->base); - - error: - cairo_surface_destroy (&tmp->base); - - return status; -} - -/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's - * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) - */ -static cairo_status_t -clip_and_composite_source (const cairo_composite_rectangles_t *extents, - draw_func_t draw_func, - void *draw_closure) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; - cairo_image_surface_t *mask; - pixman_image_t *src; - int src_x, src_y; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - mask = create_composite_mask (dst, draw_closure, draw_func, extents); - if (unlikely (mask->base.status)) - return mask->base.status; - - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - mask->pixman_image, NULL, dst->pixman_image, - 0, 0, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - src = _pixman_image_for_pattern (dst, - &extents->source_pattern.base, FALSE, - &extents->bounded, - &extents->source_sample_area, - &src_x, &src_y); - if (unlikely (src == NULL)) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto error; - } - - pixman_image_composite32 (PIXMAN_OP_ADD, - src, mask->pixman_image, dst->pixman_image, - extents->bounded.x + src_x, extents->bounded.y + src_y, - 0, 0, - extents->bounded.x, extents->bounded.y, - extents->bounded.width, extents->bounded.height); - - pixman_image_unref (src); - -error: - cairo_surface_destroy (&mask->base); - return status; -} - -static cairo_status_t -fixup_unbounded (const cairo_composite_rectangles_t *extents) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; - pixman_image_t *mask; - int mask_x, mask_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - if (! _cairo_clip_is_region (extents->clip)) { - cairo_image_surface_t *clip; - - clip = (cairo_image_surface_t *) - _cairo_clip_get_surface (extents->clip, &dst->base, - &mask_x, &mask_y); - if (unlikely (clip->base.status)) - return clip->base.status; - - mask = pixman_image_ref (clip->pixman_image); - cairo_surface_destroy (&clip->base); - } else { - mask_x = mask_y = 0; - mask = _pixman_image_for_color (CAIRO_COLOR_WHITE); - if (unlikely (mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - /* top */ - if (extents->bounded.y != extents->unbounded.y) { - int x = extents->unbounded.x; - int y = extents->unbounded.y; - int width = extents->unbounded.width; - int height = extents->bounded.y - y; - - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - mask, NULL, dst->pixman_image, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - /* left */ - if (extents->bounded.x != extents->unbounded.x) { - int x = extents->unbounded.x; - int y = extents->bounded.y; - int width = extents->bounded.x - x; - int height = extents->bounded.height; - - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - mask, NULL, dst->pixman_image, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - /* right */ - if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { - int x = extents->bounded.x + extents->bounded.width; - int y = extents->bounded.y; - int width = extents->unbounded.x + extents->unbounded.width - x; - int height = extents->bounded.height; - - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - mask, NULL, dst->pixman_image, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - /* bottom */ - if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { - int x = extents->unbounded.x; - int y = extents->bounded.y + extents->bounded.height; - int width = extents->unbounded.width; - int height = extents->unbounded.y + extents->unbounded.height - y; - - pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, - mask, NULL, dst->pixman_image, - x - mask_x, y - mask_y, - 0, 0, - x, y, - width, height); - } - - pixman_image_unref (mask); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -set_clip_region (cairo_composite_rectangles_t *extents) -{ - cairo_image_surface_t *dst = (cairo_image_surface_t *) extents->surface; - cairo_region_t *region = _cairo_clip_get_region (extents->clip); - pixman_region32_t *rgn = region ? ®ion->rgn : NULL; - if (! pixman_image_set_clip_region32 (dst->pixman_image, rgn)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -clip_and_composite (cairo_composite_rectangles_t *extents, - draw_func_t draw_func, - void *draw_closure) -{ - cairo_status_t status; - - status = set_clip_region (extents); - if (unlikely (status)) - return status; - - if (extents->op == CAIRO_OPERATOR_SOURCE) { - status = clip_and_composite_source (extents, draw_func, draw_closure); - } else { - if (extents->op == CAIRO_OPERATOR_CLEAR) { - extents->source_pattern.solid = _cairo_pattern_white; - extents->op = CAIRO_OPERATOR_DEST_OUT; - } - if (! _cairo_clip_is_region (extents->clip)) { - if (extents->is_bounded) - status = clip_and_composite_with_mask (extents, draw_func, draw_closure); - else - status = clip_and_composite_combine (extents, draw_func, draw_closure); - } else { - status = draw_func ((cairo_image_surface_t *) extents->surface, - draw_closure, - extents->op, - &extents->source_pattern.base, - 0, 0, - &extents->bounded); - } - } - - if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) - status = fixup_unbounded (extents); - - return status; -} - -/* high-level compositor interface */ - -static cairo_int_status_t -composite_paint (cairo_image_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents) -{ - cairo_rectangle_int_t sample; - pixman_image_t *src; - int src_x, src_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - _cairo_pattern_sampled_area (pattern, extents, &sample); - src = _pixman_image_for_pattern (dst, - pattern, FALSE, - extents, &sample, - &src_x, &src_y); - if (unlikely (src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - TRACE ((stderr, "%s: src=(%d, %d), dst=(%d, %d) size=%dx%d\n", __FUNCTION__, - extents->x + src_x, extents->y + src_y, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height)); - - pixman_image_composite32 (_pixman_operator (op), - src, NULL, dst->pixman_image, - extents->x + src_x, extents->y + src_y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - pixman_image_unref (src); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -base_compositor_paint (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - TRACE ((stderr, "%s\n", __FUNCTION__)); - return clip_and_composite (extents, composite_paint, NULL); -} - -static cairo_int_status_t -composite_mask (cairo_image_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents) -{ - cairo_rectangle_int_t sample; - pixman_image_t *src, *mask; - int src_x, src_y; - int mask_x, mask_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - _cairo_pattern_sampled_area (pattern, extents, &sample); - src = _pixman_image_for_pattern (dst, pattern, FALSE, - extents, &sample, - &src_x, &src_y); - if (unlikely (src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - _cairo_pattern_sampled_area (closure, extents, &sample); - mask = _pixman_image_for_pattern (dst, closure, TRUE, - extents, &sample, - &mask_x, &mask_y); - if (unlikely (mask == NULL)) { - pixman_image_unref (src); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - pixman_image_composite32 (_pixman_operator (op), - src, mask, dst->pixman_image, - extents->x + src_x, extents->y + src_y, - extents->x + mask_x, extents->y + mask_y, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - pixman_image_unref (mask); - pixman_image_unref (src); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -base_compositor_mask (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents) -{ - TRACE ((stderr, "%s\n", __FUNCTION__)); - return clip_and_composite (extents, composite_mask, &extents->mask_pattern.base); -} - -typedef struct { - cairo_traps_t traps; - cairo_antialias_t antialias; -} composite_traps_info_t; - -static cairo_int_status_t -composite_traps (cairo_image_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents) -{ - composite_traps_info_t *info = closure; - cairo_rectangle_int_t sample; - pixman_image_t *src, *mask; - int src_x, src_y; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - _cairo_pattern_sampled_area (pattern, extents, &sample); - src = _pixman_image_for_pattern (dst, pattern, FALSE, - extents, &sample, - &src_x, &src_y); - if (unlikely (src == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - mask = pixman_image_create_bits (info->antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8, - extents->width, extents->height, - NULL, 0); - if (unlikely (mask == NULL)) { - pixman_image_unref (src); - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - - _pixman_image_add_traps (mask, extents->x, extents->y, &info->traps); - pixman_image_composite32 (_pixman_operator (op), - src, mask, dst->pixman_image, - extents->x + src_x - dst_x, extents->y + src_y - dst_y, - 0, 0, - extents->x - dst_x, extents->y - dst_y, - extents->width, extents->height); - - pixman_image_unref (mask); - pixman_image_unref (src); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -trim_extents_to_traps (cairo_composite_rectangles_t *extents, - cairo_traps_t *traps) -{ - cairo_box_t box; - - /* X trims the affected area to the extents of the trapezoids, so - * we need to compensate when fixing up the unbounded area. - */ - _cairo_traps_extents (traps, &box); - return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); -} - -static cairo_int_status_t -base_compositor_stroke (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias) -{ - composite_traps_info_t info; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - info.antialias = antialias; - _cairo_traps_init_with_clip (&info.traps, extents->clip); - status = _cairo_path_fixed_stroke_polygon_to_traps (path, style, - ctm, ctm_inverse, - tolerance, - &info.traps); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = trim_extents_to_traps (extents, &info.traps); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite (extents, composite_traps, &info); - _cairo_traps_fini (&info.traps); - - return status; -} - -static cairo_int_status_t -base_compositor_fill (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias) -{ - composite_traps_info_t info; - cairo_int_status_t status; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - info.antialias = antialias; - _cairo_traps_init_with_clip (&info.traps, extents->clip); - status = _cairo_path_fixed_fill_to_traps (path, - fill_rule, tolerance, - &info.traps); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = trim_extents_to_traps (extents, &info.traps); - if (likely (status == CAIRO_INT_STATUS_SUCCESS)) - status = clip_and_composite (extents, composite_traps, &info); - _cairo_traps_fini (&info.traps); - - return status; -} - -static cairo_int_status_t -composite_glyphs (cairo_image_surface_t *dst, - void *closure, - cairo_operator_t op, - const cairo_pattern_t *pattern, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents) -{ - cairo_composite_glyphs_info_t *info = closure; - pixman_image_t *mask; - cairo_status_t status; - int i; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - - mask = pixman_image_create_bits (PIXMAN_a8, - extents->width, extents->height, - NULL, 0); - if (unlikely (mask == NULL)) - return _cairo_error (CAIRO_STATUS_NO_MEMORY); - - status = CAIRO_STATUS_SUCCESS; - _cairo_scaled_font_freeze_cache (info->font); - for (i = 0; i < info->num_glyphs; i++) { - cairo_image_surface_t *glyph_surface; - cairo_scaled_glyph_t *scaled_glyph; - unsigned long glyph_index = info->glyphs[i].index; - int x, y; - - status = _cairo_scaled_glyph_lookup (info->font, glyph_index, - CAIRO_SCALED_GLYPH_INFO_SURFACE, - &scaled_glyph); - - if (unlikely (status)) - break; - - glyph_surface = scaled_glyph->surface; - if (glyph_surface->width && glyph_surface->height) { - /* round glyph locations to the nearest pixel */ - /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ - x = _cairo_lround (info->glyphs[i].x - - glyph_surface->base.device_transform.x0); - y = _cairo_lround (info->glyphs[i].y - - glyph_surface->base.device_transform.y0); - - pixman_image_composite32 (PIXMAN_OP_ADD, - glyph_surface->pixman_image, NULL, mask, - 0, 0, - 0, 0, - x - extents->x, y - extents->y, - glyph_surface->width, - glyph_surface->height); - } - } - _cairo_scaled_font_thaw_cache (info->font); - - if (status == CAIRO_STATUS_SUCCESS) { - cairo_rectangle_int_t sample; - pixman_image_t *src; - int src_x, src_y; - - _cairo_pattern_sampled_area (pattern, extents, &sample); - src = _pixman_image_for_pattern (dst, pattern, FALSE, - extents, &sample, - &src_x, &src_y); - if (src != NULL) { - dst_x = extents->x - dst_x; - dst_y = extents->y - dst_y; - pixman_image_composite32 (_pixman_operator (op), - src, mask, dst->pixman_image, - src_x + dst_x, src_y + dst_y, - 0, 0, - dst_x, dst_y, - extents->width, extents->height); - pixman_image_unref (src); - } else - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - } - pixman_image_unref (mask); - - return status; -} - -static cairo_int_status_t -base_compositor_glyphs (const cairo_compositor_t *_compositor, - cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_bool_t overlap) -{ - cairo_composite_glyphs_info_t info; - - info.font = scaled_font; - info.glyphs = glyphs; - info.num_glyphs = num_glyphs; - - TRACE ((stderr, "%s\n", __FUNCTION__)); - return clip_and_composite (extents, composite_glyphs, &info); -} - -static const cairo_compositor_t base_compositor = { - &__cairo_no_compositor, - - base_compositor_paint, - base_compositor_mask, - base_compositor_stroke, - base_compositor_fill, - base_compositor_glyphs, -}; - -cairo_surface_t * -_cairo_test_base_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (&base_compositor, - content, width, height); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface-private.h b/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface-private.h deleted file mode 100644 index 491f241bacc..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface-private.h +++ /dev/null @@ -1,56 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef TEST_COMPOSITOR_SURFACE_PRIVATE_H -#define TEST_COMPOSITOR_SURFACE_PRIVATE_H - -#include "cairo.h" - -#include "test-compositor-surface.h" - -#include "cairo-compiler-private.h" -#include "cairo-compositor-private.h" - -CAIRO_BEGIN_DECLS - -cairo_private cairo_surface_t * -test_compositor_surface_create (const cairo_compositor_t *compositor, - cairo_content_t content, - int width, - int height); - -CAIRO_END_DECLS - -#endif /* TEST_COMPOSITOR_SURFACE_PRIVATE H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.c deleted file mode 100644 index 1cc5f692120..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.c +++ /dev/null @@ -1,264 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#include "cairoint.h" - -#include "test-compositor-surface-private.h" - -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-backend-private.h" - -typedef struct _test_compositor_surface { - cairo_image_surface_t base; -} test_compositor_surface_t; - -static const cairo_surface_backend_t test_compositor_surface_backend; - -cairo_surface_t * -test_compositor_surface_create (const cairo_compositor_t *compositor, - cairo_content_t content, - int width, - int height) -{ - test_compositor_surface_t *surface; - pixman_image_t *pixman_image; - pixman_format_code_t pixman_format; - - switch (content) { - case CAIRO_CONTENT_ALPHA: - pixman_format = PIXMAN_a8; - break; - case CAIRO_CONTENT_COLOR: - pixman_format = PIXMAN_x8r8g8b8; - break; - case CAIRO_CONTENT_COLOR_ALPHA: - pixman_format = PIXMAN_a8r8g8b8; - break; - default: - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); - } - - pixman_image = pixman_image_create_bits (pixman_format, width, height, - NULL, 0); - if (unlikely (pixman_image == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface = malloc (sizeof (test_compositor_surface_t)); - if (unlikely (surface == NULL)) { - pixman_image_unref (pixman_image); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - _cairo_surface_init (&surface->base.base, - &test_compositor_surface_backend, - NULL, /* device */ - content); - _cairo_image_surface_init (&surface->base, pixman_image, pixman_format); - - surface->base.compositor = compositor; - - return &surface->base.base; -} - -static cairo_surface_t * -test_compositor_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - test_compositor_surface_t *surface = abstract_surface; - - return test_compositor_surface_create (surface->base.compositor, - content, width, height); -} - -static cairo_int_status_t -test_compositor_surface_paint (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_paint (surface->base.compositor, - _surface, op, source, - clip); -} - -static cairo_int_status_t -test_compositor_surface_mask (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_mask (surface->base.compositor, - _surface, op, source, mask, - clip); -} - -static cairo_int_status_t -test_compositor_surface_stroke (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - if (antialias == CAIRO_ANTIALIAS_DEFAULT) - antialias = CAIRO_ANTIALIAS_BEST; - return _cairo_compositor_stroke (surface->base.compositor, - _surface, op, source, - path, style, ctm, ctm_inverse, - tolerance, antialias, - clip); -} - -static cairo_int_status_t -test_compositor_surface_fill (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - if (antialias == CAIRO_ANTIALIAS_DEFAULT) - antialias = CAIRO_ANTIALIAS_BEST; - return _cairo_compositor_fill (surface->base.compositor, - _surface, op, source, - path, fill_rule, tolerance, antialias, - clip); -} - -static cairo_int_status_t -test_compositor_surface_glyphs (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_glyphs (surface->base.compositor, - _surface, op, source, - glyphs, num_glyphs, scaled_font, - clip); -} - -static const cairo_surface_backend_t test_compositor_surface_backend = { - CAIRO_SURFACE_TYPE_IMAGE, - _cairo_image_surface_finish, - _cairo_default_context_create, - - test_compositor_surface_create_similar, - NULL, /* create similar image */ - _cairo_image_surface_map_to_image, - _cairo_image_surface_unmap_image, - - _cairo_image_surface_source, - _cairo_image_surface_acquire_source_image, - _cairo_image_surface_release_source_image, - _cairo_image_surface_snapshot, - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_image_surface_get_extents, - _cairo_image_surface_get_font_options, - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - test_compositor_surface_paint, - test_compositor_surface_mask, - test_compositor_surface_stroke, - test_compositor_surface_fill, - NULL, /* fill/stroke */ - test_compositor_surface_glyphs, -}; - -static const cairo_compositor_t * -get_fallback_compositor (void) -{ - return &_cairo_fallback_compositor; -} - -cairo_surface_t * -_cairo_test_fallback_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (get_fallback_compositor(), - content, width, height); -} - -cairo_surface_t * -_cairo_test_mask_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (_cairo_image_mask_compositor_get(), - content, width, height); -} - -cairo_surface_t * -_cairo_test_traps_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (_cairo_image_traps_compositor_get(), - content, width, height); -} - -cairo_surface_t * -_cairo_test_spans_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (_cairo_image_spans_compositor_get(), - content, width, height); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.h b/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.h deleted file mode 100644 index 8d8af2d5409..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-compositor-surface.h +++ /dev/null @@ -1,71 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef TEST_COMPOSITOR_SURFACE_H -#define TEST_COMPOSITOR_SURFACE_H - -#include "cairo.h" - -CAIRO_BEGIN_DECLS - -cairo_surface_t * -_cairo_test_fallback_compositor_surface_create (cairo_content_t content, - int width, - int height); - - -cairo_surface_t * -_cairo_test_mask_compositor_surface_create (cairo_content_t content, - int width, - int height); - -cairo_surface_t * -_cairo_test_traps_compositor_surface_create (cairo_content_t content, - int width, - int height); - -cairo_surface_t * -_cairo_test_spans_compositor_surface_create (cairo_content_t content, - int width, - int height); - -cairo_surface_t * -_cairo_test_base_compositor_surface_create (cairo_content_t content, - int width, - int height); - -CAIRO_END_DECLS - -#endif /* TEST_COMPOSITOR_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.c deleted file mode 100644 index 2301055e30a..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.c +++ /dev/null @@ -1,480 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - - -#include "cairoint.h" - -#include "test-null-compositor-surface.h" - -#include "cairo-compositor-private.h" -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-image-surface-private.h" -#include "cairo-surface-backend-private.h" -#include "cairo-spans-compositor-private.h" -#include "cairo-spans-private.h" - -typedef struct _test_compositor_surface { - cairo_image_surface_t base; -} test_compositor_surface_t; - -static const cairo_surface_backend_t test_compositor_surface_backend; - -static cairo_surface_t * -test_compositor_surface_create (const cairo_compositor_t *compositor, - cairo_content_t content, - int width, - int height) -{ - test_compositor_surface_t *surface; - pixman_image_t *pixman_image; - pixman_format_code_t pixman_format; - - switch (content) { - case CAIRO_CONTENT_ALPHA: - pixman_format = PIXMAN_a8; - break; - case CAIRO_CONTENT_COLOR: - pixman_format = PIXMAN_x8r8g8b8; - break; - case CAIRO_CONTENT_COLOR_ALPHA: - pixman_format = PIXMAN_a8r8g8b8; - break; - default: - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); - } - - pixman_image = pixman_image_create_bits (pixman_format, width, height, - NULL, 0); - if (unlikely (pixman_image == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - surface = malloc (sizeof (test_compositor_surface_t)); - if (unlikely (surface == NULL)) { - pixman_image_unref (pixman_image); - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - } - - _cairo_surface_init (&surface->base.base, - &test_compositor_surface_backend, - NULL, /* device */ - content); - _cairo_image_surface_init (&surface->base, pixman_image, pixman_format); - - surface->base.compositor = compositor; - - return &surface->base.base; -} - -static cairo_surface_t * -test_compositor_surface_create_similar (void *abstract_surface, - cairo_content_t content, - int width, - int height) -{ - test_compositor_surface_t *surface = abstract_surface; - - return test_compositor_surface_create (surface->base.compositor, - content, width, height); -} - -static cairo_int_status_t -test_compositor_surface_paint (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_paint (surface->base.compositor, - _surface, op, source, - clip); -} - -static cairo_int_status_t -test_compositor_surface_mask (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_mask (surface->base.compositor, - _surface, op, source, mask, - clip); -} - -static cairo_int_status_t -test_compositor_surface_stroke (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_stroke (surface->base.compositor, - _surface, op, source, - path, style, ctm, ctm_inverse, - tolerance, antialias, - clip); -} - -static cairo_int_status_t -test_compositor_surface_fill (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_fill (surface->base.compositor, - _surface, op, source, - path, fill_rule, tolerance, antialias, - clip); -} - -static cairo_int_status_t -test_compositor_surface_glyphs (void *_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - cairo_glyph_t *glyphs, - int num_glyphs, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - test_compositor_surface_t *surface = _surface; - return _cairo_compositor_glyphs (surface->base.compositor, - _surface, op, source, - glyphs, num_glyphs, scaled_font, - clip); -} - -static const cairo_surface_backend_t test_compositor_surface_backend = { - CAIRO_SURFACE_TYPE_IMAGE, - _cairo_image_surface_finish, - _cairo_default_context_create, - - test_compositor_surface_create_similar, - NULL, /* create similar image */ - _cairo_image_surface_map_to_image, - _cairo_image_surface_unmap_image, - - _cairo_image_surface_source, - _cairo_image_surface_acquire_source_image, - _cairo_image_surface_release_source_image, - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _cairo_image_surface_get_extents, - _cairo_image_surface_get_font_options, - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - test_compositor_surface_paint, - test_compositor_surface_mask, - test_compositor_surface_stroke, - test_compositor_surface_fill, - NULL, /* fill/stroke */ - test_compositor_surface_glyphs, -}; - -static cairo_int_status_t -acquire (void *abstract_dst) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -release (void *abstract_dst) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -set_clip_region (void *_surface, - cairo_region_t *region) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_surface_t * -pattern_to_surface (cairo_surface_t *dst, - const cairo_pattern_t *pattern, - cairo_bool_t is_mask, - const cairo_rectangle_int_t *extents, - const cairo_rectangle_int_t *sample, - int *src_x, int *src_y) -{ - return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); -} - -static cairo_int_status_t -fill_boxes (void *_dst, - cairo_operator_t op, - const cairo_color_t *color, - cairo_boxes_t *boxes) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -draw_image_boxes (void *_dst, - cairo_image_surface_t *image, - cairo_boxes_t *boxes, - int dx, int dy) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -lerp (void *_dst, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - unsigned int width, - unsigned int height) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_boxes (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - cairo_surface_t *abstract_mask, - int src_x, - int src_y, - int mask_x, - int mask_y, - int dst_x, - int dst_y, - cairo_boxes_t *boxes, - const cairo_rectangle_int_t *extents) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_traps (void *_dst, - cairo_operator_t op, - cairo_surface_t *abstract_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - const cairo_rectangle_int_t *extents, - cairo_antialias_t antialias, - cairo_traps_t *traps) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -check_composite_glyphs (const cairo_composite_rectangles_t *extents, - cairo_scaled_font_t *scaled_font, - cairo_glyph_t *glyphs, - int *num_glyphs) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -composite_glyphs (void *_dst, - cairo_operator_t op, - cairo_surface_t *_src, - int src_x, - int src_y, - int dst_x, - int dst_y, - cairo_composite_glyphs_info_t *info) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -spans (void *abstract_renderer, - int y, int height, - const cairo_half_open_span_t *spans, - unsigned num_spans) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_status_t -finish_spans (void *abstract_renderer) -{ - return CAIRO_STATUS_SUCCESS; -} - -static cairo_int_status_t -span_renderer_init (cairo_abstract_span_renderer_t *_r, - const cairo_composite_rectangles_t *composite, - cairo_antialias_t antialias, - cairo_bool_t needs_clip) -{ - cairo_span_renderer_t *r = (cairo_span_renderer_t *)_r; - r->render_rows = spans; - r->finish = finish_spans; - return CAIRO_STATUS_SUCCESS; -} - -static void -span_renderer_fini (cairo_abstract_span_renderer_t *_r, - cairo_int_status_t status) -{ -} - -static const cairo_compositor_t * -no_fallback_compositor_get (void) -{ - return &__cairo_no_compositor; -} - -static cairo_int_status_t -check_composite (const cairo_composite_rectangles_t *extents) -{ - return CAIRO_STATUS_SUCCESS; -} - -static const cairo_compositor_t * -no_traps_compositor_get (void) -{ - static cairo_traps_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_traps_compositor_init (&compositor, - no_fallback_compositor_get ()); - - compositor.acquire = acquire; - compositor.release = release; - compositor.set_clip_region = set_clip_region; - compositor.pattern_to_surface = pattern_to_surface; - compositor.draw_image_boxes = draw_image_boxes; - //compositor.copy_boxes = copy_boxes; - compositor.fill_boxes = fill_boxes; - compositor.check_composite = check_composite; - compositor.composite = composite; - compositor.lerp = lerp; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - //compositor.check_composite_traps = check_composite_traps; - compositor.composite_traps = composite_traps; - compositor.check_composite_glyphs = check_composite_glyphs; - compositor.composite_glyphs = composite_glyphs; - } - - return &compositor.base; -} - -static const cairo_compositor_t * -no_spans_compositor_get (void) -{ - static cairo_spans_compositor_t compositor; - - if (compositor.base.delegate == NULL) { - _cairo_spans_compositor_init (&compositor, - no_traps_compositor_get()); - - //compositor.acquire = acquire; - //compositor.release = release; - compositor.fill_boxes = fill_boxes; - //compositor.check_composite_boxes = check_composite_boxes; - compositor.composite_boxes = composite_boxes; - //compositor.check_span_renderer = check_span_renderer; - compositor.renderer_init = span_renderer_init; - compositor.renderer_fini = span_renderer_fini; - } - - return &compositor.base; -} - -cairo_surface_t * -_cairo_test_no_fallback_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (no_fallback_compositor_get(), - content, width, height); -} - -cairo_surface_t * -_cairo_test_no_traps_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (no_traps_compositor_get(), - content, width, height); -} - -cairo_surface_t * -_cairo_test_no_spans_compositor_surface_create (cairo_content_t content, - int width, - int height) -{ - return test_compositor_surface_create (no_spans_compositor_get(), - content, width, height); -} diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.h b/Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.h deleted file mode 100644 index 52d864b28df..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-null-compositor-surface.h +++ /dev/null @@ -1,60 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Intel Corporation - * - * Contributor(s): - * Chris Wilson - */ - -#ifndef TEST_NULL_COMPOSITOR_SURFACE_H -#define TEST_NULL_COMPOSITOR_SURFACE_H - -#include "cairo.h" - -CAIRO_BEGIN_DECLS - -cairo_surface_t * -_cairo_test_no_fallback_compositor_surface_create (cairo_content_t content, - int width, - int height); - -cairo_surface_t * -_cairo_test_no_traps_compositor_surface_create (cairo_content_t content, - int width, - int height); - -cairo_surface_t * -_cairo_test_no_spans_compositor_surface_create (cairo_content_t content, - int width, - int height); - -CAIRO_END_DECLS - -#endif /* TEST_NULL_COMPOSITOR_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.c b/Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.c deleted file mode 100644 index 0a7c79b37bf..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.c +++ /dev/null @@ -1,286 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - */ - -/* This isn't a "real" surface, but just something to be used by the - * test suite to help exercise the paginated-surface paths in cairo. - * - * The defining feature of this backend is that it uses a paginated - * surface to record all operations, and then replays everything to an - * image surface. - * - * It's possible that this code might serve as a good starting point - * for someone working on bringing up a new paginated-surface-based - * backend. - */ - -#include "cairoint.h" - -#include "test-paginated-surface.h" - -#include "cairo-default-context-private.h" -#include "cairo-error-private.h" -#include "cairo-paginated-private.h" -#include "cairo-surface-backend-private.h" - -typedef struct _test_paginated_surface { - cairo_surface_t base; - cairo_surface_t *target; - cairo_paginated_mode_t paginated_mode; -} test_paginated_surface_t; - -static const cairo_surface_backend_t test_paginated_surface_backend; -static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend; - -cairo_surface_t * -_cairo_test_paginated_surface_create (cairo_surface_t *target) -{ - cairo_status_t status; - cairo_surface_t *paginated; - test_paginated_surface_t *surface; - - status = cairo_surface_status (target); - if (unlikely (status)) - return _cairo_surface_create_in_error (status); - - surface = malloc (sizeof (test_paginated_surface_t)); - if (unlikely (surface == NULL)) - return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); - - _cairo_surface_init (&surface->base, - &test_paginated_surface_backend, - NULL, /* device */ - target->content); - - surface->target = cairo_surface_reference (target); - - paginated = _cairo_paginated_surface_create (&surface->base, - target->content, - &test_paginated_surface_paginated_backend); - status = paginated->status; - if (status == CAIRO_STATUS_SUCCESS) { - /* paginated keeps the only reference to surface now, drop ours */ - cairo_surface_destroy (&surface->base); - return paginated; - } - - cairo_surface_destroy (target); - free (surface); - return _cairo_surface_create_in_error (status); -} - -static cairo_status_t -_test_paginated_surface_finish (void *abstract_surface) -{ - test_paginated_surface_t *surface = abstract_surface; - - cairo_surface_destroy (surface->target); - - return CAIRO_STATUS_SUCCESS; -} - -static cairo_bool_t -_test_paginated_surface_get_extents (void *abstract_surface, - cairo_rectangle_int_t *rectangle) -{ - test_paginated_surface_t *surface = abstract_surface; - - return _cairo_surface_get_extents (surface->target, rectangle); -} - -static cairo_int_status_t -_test_paginated_surface_paint (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_clip_t *clip) -{ - test_paginated_surface_t *surface = abstract_surface; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_STATUS_SUCCESS; - - return _cairo_surface_paint (surface->target, op, source, clip); -} - -static cairo_int_status_t -_test_paginated_surface_mask (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_pattern_t *mask, - const cairo_clip_t *clip) -{ - test_paginated_surface_t *surface = abstract_surface; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_STATUS_SUCCESS; - - return _cairo_surface_mask (surface->target, - op, source, mask, clip); -} - -static cairo_int_status_t -_test_paginated_surface_stroke (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - const cairo_stroke_style_t *style, - const cairo_matrix_t *ctm, - const cairo_matrix_t *ctm_inverse, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - test_paginated_surface_t *surface = abstract_surface; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_STATUS_SUCCESS; - - return _cairo_surface_stroke (surface->target, op, source, - path, style, - ctm, ctm_inverse, - tolerance, antialias, - clip); -} - -static cairo_int_status_t -_test_paginated_surface_fill (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const cairo_path_fixed_t *path, - cairo_fill_rule_t fill_rule, - double tolerance, - cairo_antialias_t antialias, - const cairo_clip_t *clip) -{ - test_paginated_surface_t *surface = abstract_surface; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_STATUS_SUCCESS; - - return _cairo_surface_fill (surface->target, op, source, - path, fill_rule, - tolerance, antialias, - clip); -} - -static cairo_bool_t -_test_paginated_surface_has_show_text_glyphs (void *abstract_surface) -{ - test_paginated_surface_t *surface = abstract_surface; - - return cairo_surface_has_show_text_glyphs (surface->target); -} - -static cairo_int_status_t -_test_paginated_surface_show_text_glyphs (void *abstract_surface, - cairo_operator_t op, - const cairo_pattern_t *source, - const char *utf8, - int utf8_len, - cairo_glyph_t *glyphs, - int num_glyphs, - const cairo_text_cluster_t *clusters, - int num_clusters, - cairo_text_cluster_flags_t cluster_flags, - cairo_scaled_font_t *scaled_font, - const cairo_clip_t *clip) -{ - test_paginated_surface_t *surface = abstract_surface; - - if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) - return CAIRO_STATUS_SUCCESS; - - return _cairo_surface_show_text_glyphs (surface->target, op, source, - utf8, utf8_len, - glyphs, num_glyphs, - clusters, num_clusters, - cluster_flags, - scaled_font, - clip); -} - - -static void -_test_paginated_surface_set_paginated_mode (void *abstract_surface, - cairo_paginated_mode_t mode) -{ - test_paginated_surface_t *surface = abstract_surface; - - surface->paginated_mode = mode; -} - -static const cairo_surface_backend_t test_paginated_surface_backend = { - CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED, - _test_paginated_surface_finish, - _cairo_default_context_create, - - /* Since we are a paginated user, we get to regard most of the - * surface backend interface as historical cruft and ignore it. */ - - NULL, /* create_similar */ - NULL, /* create similar image */ - NULL, /* map to image */ - NULL, /* unmap image */ - - _cairo_surface_default_source, - NULL, /* acquire_source_image */ - NULL, /* release_source_image */ - NULL, /* snapshot */ - - NULL, /* copy_page */ - NULL, /* show_page */ - - _test_paginated_surface_get_extents, - NULL, /* get_font_options */ - - NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ - - /* Here is the more "modern" section of the surface backend - * interface which is mostly just drawing functions */ - - _test_paginated_surface_paint, - _test_paginated_surface_mask, - _test_paginated_surface_stroke, - _test_paginated_surface_fill, - NULL, /* fill-stroke */ - NULL, /* replaced by show_text_glyphs */ - _test_paginated_surface_has_show_text_glyphs, - _test_paginated_surface_show_text_glyphs -}; - -static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend = { - NULL, /* start_page */ - _test_paginated_surface_set_paginated_mode -}; diff --git a/Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.h b/Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.h deleted file mode 100644 index 2bd98aa5eee..00000000000 --- a/Build/source/libs/cairo/cairo-1.14.2/src/test-paginated-surface.h +++ /dev/null @@ -1,48 +0,0 @@ -/* cairo - a vector graphics library with display and print output - * - * Copyright © 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - * The Original Code is the cairo graphics library. - * - * The Initial Developer of the Original Code is Red Hat, Inc. - * - * Contributor(s): - * Carl Worth - */ - -#ifndef TEST_PAGINATED_SURFACE_H -#define TEST_PAGINATED_SURFACE_H - -#include "cairo.h" - -CAIRO_BEGIN_DECLS - -cairo_surface_t * -_cairo_test_paginated_surface_create (cairo_surface_t *target); - -CAIRO_END_DECLS - -#endif /* TEST_PAGINATED_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-src-PATCHES/ChangeLog b/Build/source/libs/cairo/cairo-src-PATCHES/ChangeLog new file mode 100644 index 00000000000..d8fa743af03 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src-PATCHES/ChangeLog @@ -0,0 +1,33 @@ +2015-12-28 Akira Kakuto + + Import cairo-1.14.6. + +2015-03-11 Peter Breitenlohner + + Import cairo-1.14.2. + +2014-10-15 Peter Breitenlohner + + Import cairo-1.14.0. + +2013-09-10 Peter Breitenlohner + + Import cairo-1.12.16. + +2013-05-25 Peter Breitenlohner + + Import cairo-1.12.14. + +2012-11-16 Peter Breitenlohner + + Import cairo-1.12.8. + * patch-01-mingw (removed): Obsolete. + +2012-11-15 Peter Breitenlohner + + Import cairo-1.10.2. + * patch-01-mingw (new): Build fix for MinGW. + +2012-11-10 Taco Hoekwater + + Import cairo-1.12.8. diff --git a/Build/source/libs/cairo/cairo-src-PATCHES/TL-Changes b/Build/source/libs/cairo/cairo-src-PATCHES/TL-Changes new file mode 100644 index 00000000000..07117c82d20 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src-PATCHES/TL-Changes @@ -0,0 +1,33 @@ +Changes applied to the cairo-1.14.6/ tree as obtained from: + http://cairographics.org/releases/cairo-1.14.6.tar.xz + +Removed: + Makefile.in + ChangeLog* + aclocal.m4 + build/ar-lib + build/compile + build/config.guess + build/config.sub + build/depcomp + build/install-sh + build/libtool.m4 + build/ltmain.sh + build/ltoptions.m4 + build/ltsugar.m4 + build/ltversion.m4 + build/lt~obsolete.m4 + build/missing + build/test-driver + configure + src/Makefile.in + +Removed unused dirs: + boilerplate + doc + perf + src/drm + src/skia + src/win32 + test + util diff --git a/Build/source/libs/cairo/cairo-src/AUTHORS b/Build/source/libs/cairo/cairo-src/AUTHORS new file mode 100644 index 00000000000..d85696fa81c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/AUTHORS @@ -0,0 +1,115 @@ +Josh Aas Memory leak fix for quartz backend +Daniel Amelang Many (magic) floating-point optimizations +Shawn T. Amundson Build fix +Olivier Andrieu PNG backend +Peter Dennis Bartok Bug fix for clipping +Dave Beckett Build fixes, Debian packaging +Kai-Uwe Behrmann SVG bug fixes +Christian Biesinger BeOS backend +Billy Biggs Pixman code merge. Optimization. Fixes for subtle rendering bugs. +Hans Breuer win32 bug fixes, build fixes, and improvements +Brian Cameron Flag bug in Sun's X server +Carlos Garcia Campos libspectre integration into the test-suite +Andrea Canciani Bugs, quartz backend improvements and type 6/7 patterns. +Damien Carbery Build fixes +Andrew Chant Adding const where needed +Steve Chaplin Bug fixes for PNG reading +Tomasz Cholewo Bug fixes +Manu Cornet SVG build fix +Frederic Crozat Fix test suite for OPD platforms (IA64 or PPC64) +Julien Danjou XCB fixes +Radek Doulík Bug report and test case +John Ehresman Build fixes for win32 +John Ellson First font/glyph extents functions +Michael Emmel DirectFB backend +Miklós Erdélyi Fix typo leading to a crash +Behdad Esfahbod Huge piles of bug fixes, improvements, and general maintenance +Gilles Espinasse Font related fixes +Larry Ewing Test case for group-clip +Brian Ewins ATSUI maintenance (first success at making it really work) +Bertram Felgenhauer Fixes for subtle arithmetic errors +Damian Frank Build system improvements for win32 +Bdale Garbee Provided essential support for cairo achitecture sessions +Jens Granseuer Fixes to generate proper compiler flags +Laxmi Harikumar Build fix +J. Ali Harlow win32 backend updates +Bryce Harrington Test cases, bug/typo fixes +Mathias Hasselmann Significant reduction of calls to malloc +Richard Henderson "slim" macros for better shared libraries +James Henstridge Build fixes related to freetype +Graydon Hoare Support for non-render X server, first real text support +Thomas Hunger Initial version of cairo_in_stroke/fill +Thomas Jaeger Extended repeat modes for X +Björn Lindqvist Performance test cases +Kristian Høgsberg PDF backend, PS backend with meta-surfaces +Amaury Jacquot Documentation review, appplication testing +Adrian Johnson PDF backend improvement +Michael Johnson Bug fix for pre-C99 compilers +Jonathon Jongsma Fix documentation typos +Øyvind Kolås OpenVG backend, Bug fixes. Better default values. +Martin Kretzschmar Arithmetic fix for 64-bit architectures +Mathieu Lacage several bug/typo fixes +Dominic Lachowicz PDF conformance fix, fix image surface to zero out contents +Alexander Larsson Profiling and performance fixes. +Sylvestre Ledru Static analysis fixes. +Tor Lillqvist win32 build fixes, build scripts +Jinghua Luo Add bitmap glyph transformation, many freetype and glitz fixes +Luke-Jr Build fix for cross-compiling +Kjartan Maraas Several fixes for sparse, lots of debug help for multi-thread bugs +Nis Martensen Bug fix for sub paths +Jordi Mas Bug fix for cairo_show_text +Nicholas Miell Fixes for linking bugs on AMD64 +Eugeniy Meshcheryakov PS/PDF font subsetting improvements +Zakharov Mikhail Build fix for HP-UX +Christopher (Monty) Montgomery Performnace fix (subimage_copy), multi-thread testing +Tim Mooney Fix test suite to compile with Solaris compiler +Jeff Muizelaar Patient, painful, pixman code merge. Many fixes for intricacies of dashing. +Yevgen Muntyan win32 build fix +Ravi Nanjundappa Static analysis fixes, test cases, skia backend update/fixes +Declan Naughton Fix documentation typos +Peter Nilsson Glitz backend +Henning Noren Fix memory leak +Geoff Norton Build fixes +Robert O'Callahan Const-correctness fixes, several new API functions for completeness (and to help mozilla) +Ian Osgood XCB backend maintenance +Benjamin Otte Refinements to cairo/perf timing, OpenGL backend fixups, random fixes +Mike Owens Bug fixes +Emmanuel Pacaud SVG backend +Keith Packard Original concept, polygon tessellation, dashing, font metrics rewrite +Stuart Parmenter Original GDI+ backend, win32 fixes +Alfred Peng Fixes for Sun compilers and for a memory leak +Christof Petig Build fixes related to freetype +Joonas Pihlaja Huge improvements to the tessellator performance +Mart Raudsepp Build fixes +David Reveman New pattern API, glitz backend +Calum Robinson Quartz backend +Pavel Roskin Several cleanups to eliminate warnings +Tim Rowley Quartz/ATSUI fixes, X server workarounds, win32 glyph path support, test case to expose gradient regression +Soeren Sandmann Lots of MMX love for pixman compositing +Uli Schlachter Some more XCB fixes +Torsten Schönfeld Build fixes +Jamey Sharp Surface/font backend virtualization, XCB backend +Jason Dorje Short Build fixes and bug fixes +Jeff Smith Fixes for intricacies of stroking code +Travis Spencer XCB backend fix +Bill Spitzak Build fix to find Xrender.h without xrender.pc, downscaling support +Zhe Su Add support for fontconfig's embeddedbitmap option +Owen Taylor Font rewrite, documentation, win32 backend +Pierre Tardy EGL support and testing, OpenVG backend +Karl Tomlinson Optimisation and obscure bug fixes (mozilla) +Alp Toker Fix several code/comment typos +Malcolm Tredinnick Documentation fixes +David Turner Optimize gradient calculations +Kalle Vahlman Allow perf reports to be compared across different platforms +Sasha Vasko Build fix to compile without xlib backend +Vladimir Vukicevic Quartz backend rewrite, win32/quartz maintenance +Jonathan Watt win32 fixes +Peter Weilbacher OS/2 backend +Dan Williams Implemnt MMX function to help OLPC +Chris Wilson Large-scale robustness improvements, (warn_unsed_result and malloc failure injection) +Carl Worth Original library, support for paths, images +Richard D. Worth Build fixes for cygwin +Kent Worsnop Fix PDF dashing bug +Dave Yeo Build fix for win32 + +(please let us know if we have missed anyone) diff --git a/Build/source/libs/cairo/cairo-src/BIBLIOGRAPHY b/Build/source/libs/cairo/cairo-src/BIBLIOGRAPHY new file mode 100644 index 00000000000..90a6cef205b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/BIBLIOGRAPHY @@ -0,0 +1,109 @@ +Here's an effort to document some of the academic work that was +referenced during the implementation of cairo. It is presented in the +context of operations as they would be performed by either +cairo_stroke() or cairo_fill(): + +Given a Bézier path, approximate it with line segments: + + The deCasteljau algorithm + "Outillages methodes calcul", P de Casteljau, technical + report, - Andre Citroen Automobiles SA, Paris, 1959 + + That technical report might be "hard" to find, but fortunately + this algorithm will be described in any reasonable textbook on + computational geometry. Two that have been recommended by + cairo contributors are: + + "Computational Geometry, Algorithms and Applications", M. de + Berg, M. van Kreveld, M. Overmars, M. Schwarzkopf; + Springer-Verlag, ISBN: 3-540-65620-0. + + "Computational Geometry in C (Second Edition)", Joseph + O'Rourke, Cambridge University Press, ISBN 0521640105. + +Then, if stroking, construct a polygonal representation of the pen +approximating a circle (if filling skip three steps): + + "Good approximation of circles by curvature-continuous Bezier + curves", Tor Dokken and Morten Daehlen, Computer Aided + Geometric Design 8 (1990) 22-41. + +Add points to that pen based on the initial/final path faces and take +the convex hull: + + Convex hull algorithm + + [Again, see your favorite computational geometry + textbook. Should cite the name of the algorithm cairo uses + here, if it has a name.] + +Now, "convolve" the "tracing" of the pen with the tracing of the path: + + "A Kinetic Framework for Computational Geometry", Leonidas + J. Guibas, Lyle Ramshaw, and Jorge Stolfi, Proceedings of the + 24th IEEE Annual Symposium on Foundations of Computer Science + (FOCS), November 1983, 100-111. + +The result of the convolution is a polygon that must be filled. A fill +operations begins here. We use a very conventional Bentley-Ottmann +pass for computing the intersections, informed by some hints on robust +implementation courtesy of John Hobby: + + John D. Hobby, Practical Segment Intersection with Finite + Precision Output, Computation Geometry Theory and + Applications, 13(4), 1999. + + http://cm.bell-labs.com/who/hobby/93_2-27.pdf + +Hobby's primary contribution in that paper is his "tolerance square" +algorithm for robustness against edges being "bent" due to restricting +intersection coordinates to the grid available by finite-precision +arithmetic. This is one algorithm we have not implemented yet. + +We use a data-structure called Skiplists in the our implementation +of Bentley-Ottmann: + + W. Pugh, Skip Lists: a Probabilistic Alternative to Balanced Trees, + Communications of the ACM, vol. 33, no. 6, pp.668-676, 1990. + + http://citeseer.ist.psu.edu/pugh90skip.html + +The random number generator used in our skip list implementation is a +very small generator by Hars and Petruska. The generator is based on +an invertable function on Z_{2^32} with full period and is described +in + + Hars L. and Petruska G., + ``Pseudorandom Recursions: Small and Fast Pseurodandom + Number Generators for Embedded Applications'', + Hindawi Publishing Corporation + EURASIP Journal on Embedded Systems + Volume 2007, Article ID 98417, 13 pages + doi:10.1155/2007/98417 + + http://www.hindawi.com/getarticle.aspx?doi=10.1155/2007/98417&e=cta + +From the result of the intersection-finding pass, we are currently +computing a tessellation of trapezoids, (the exact manner is +undergoing some work right now with some important speedup), but we +may want to rasterize directly from those edges at some point. + +Given the set of tessellated trapezoids, we currently execute a +straightforward, (and slow), point-sampled rasterization, (and +currently with a near-pessimal regular 15x17 grid). + +We've now computed a mask which gets fed along with the source and +destination into cairo's fundamental rendering equation. The most +basic form of this equation is: + + destination = (source IN mask) OP destination + +with the restriction that no part of the destination outside the +current clip region is affected. In this equation, IN refers to the +Porter-Duff "in" operation, while OP refers to a any user-selected +Porter-Duff operator: + + T. Porter & T. Duff, Compositing Digital Images Computer + Graphics Volume 18, Number 3 July 1984 pp 253-259 + + http://keithp.com/~keithp/porterduff/p253-porter.pdf diff --git a/Build/source/libs/cairo/cairo-src/BUGS b/Build/source/libs/cairo/cairo-src/BUGS new file mode 100644 index 00000000000..ef044046d3e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/BUGS @@ -0,0 +1,85 @@ +If you find a bug in cairo we would love to hear about it. We're also +trying to make cairo better, and learning about the bugs that users +encounter is an essential part of that. So we really appreciate the +extra effort users put in to providing high-quality bug reports. + +There are two acceptable ways to report cairo bugs, and you can choose +which you prefer: + +1) Bugzilla bug tracking database: + + You can use the following web interface to report new bugs, follow + up on previous bug reports, and search for existing, known + bugs. Just use the "cairo" product: + + http://bugs.freedesktop.org + + It is necessary to go through a quick account creation process, + (with email address verification), in order to be able to report + new bugs in bugzilla. We apologize for any inconvenience that might + cause, and hope it won't prevent you from reporting bugs. + +2) Cairo mailing list: + + For people who cannot stand the bugzilla interface, you can just + send an email to cairo mailing list (cairo@cairographics.org). The + mailing list only allows posting from subscribers, so use the + following page for subscription instructions: + + http://cairographics.org/lists + + Again, we apologize for any inconvenience this subscription step + might cause, but we've found it necessary to require this in order + to enjoy spam-free discussions on the list. + + If you don't actually _want_ to be a subscriber to the mailing + list, but just want to be able to send a message, the easiest thing + to do is to go through the subscription process, and then use the + preferences page to disable message delivery to your address. + +Which of the above you use to report bugs depends on your own +preferences. Some people find just typing an email message much easier +than using the web-based forms on bugzilla. Others greatly prefer the +ability to check back on a specific bug entry in bugzilla without +having to ask on the mailing list if an issue has been resolved. + +Regardless of which method you use, here are some general tips that +will help you improve the quality of your bug report, (which will help +in getting the bug fixed sooner): + +1) Check to see if the bug has been reported already. It's pretty easy + to run a search or two against the cairo product in the + http://bugs.freedesktop.org bugzilla database. Another place to + look for known bugs is the cairo ROADMAP: + + http://cairographics.org/ROADMAP + + which shows a planned schedule of releases and which bug fixes are + being planned for each release. + +2) Provide an accurate description of the bug with detailed steps for + how we can reproduce the problem. + +3) If possible provide a minimal test case demonstrating the bug. A + great test case would be a minimal self-contained function in C or + python or whatever language you are using for cairo. The function + might accept nothing more than a cairo context, (cairo_t* in C). + +4) If you feel like being particularly helpful, you could craft this + minimal test case in the form necessary for cairo's test + suite. This isn't much more work than writing a minimal + function. Just look at the cairo/test/README file and imitate the + style of existing test cases. + + If you do submit a test case, be sure to include Copyright + information, (with the standard MIT licensing blurb if you want us + to include your test in the test case). Also, including a reference + image showing the expected result will be extremely useful. + +5) Finally, the best bug report also comes attached with a patch to + cairo to fix the bug. So send this too if you have it! Otherwise, + don't worry about it and we'll try to fix cairo when we can. + +Thanks, and have fun with cairo! + +-Carl diff --git a/Build/source/libs/cairo/cairo-src/CODING_STYLE b/Build/source/libs/cairo/cairo-src/CODING_STYLE new file mode 100644 index 00000000000..95ceac04d84 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/CODING_STYLE @@ -0,0 +1,291 @@ +Cairo coding style. + +This document is intended to be a short description of the preferred +coding style for the cairo source code. Good style requires good +taste, which means this can't all be reduced to automated rules, and +there are exceptions. + +We want the code to be easy to understand and maintain, and consistent +style plays an important part in that, even if some of the specific +details seem trivial. If nothing else, this document gives a place to +put consistent answers for issues that would otherwise be arbitrary. + +Most of the guidelines here are demonstrated by examples, (which means +this document is quicker to read than it might appear given its +length). Most of the examples are positive examples that you should +imitate. The few negative examples are clearly marked with a comment +of /* Yuck! */. Please don't submit code to cairo that looks like any +of these. + +Indentation +----------- +Each new level is indented 4 more spaces than the previous level: + + if (condition) + do_something (); + +This may be achieved with space characters or a combination of tab +characters and space characters. It may not be achieved with tab +characters exclusively (see below). + +Tab characters +-------------- +The tab character must always be interpreted according to its +traditional meaning: + + Advance to the next column which is a multiple of 8. + +With this definition, even levels of indentation can be achieved with +a sequence of tab characters, while odd levels of indentation may +begin with a sequence of tab character but must end with 4 space +characters. + +Some programmers have been misled by certain text editors into +thinking that 4-space indentation can be achieved with tab characters +exclusively by changing the meaning of tab character to be "advance to +the next column which is a multiple of 4". Code formatted in this way, +making an assumption of a fictitious 4-character-tab will not be +accepted into cairo. + +The rationale here is that tabs are used in the code for lining things +up other than indentation, (see the Whitespace section below), and +changing the interpretation of tab from its traditional meaning will +break this alignment. + +Braces +------ +Most of the code in cairo uses bracing in the style of K&R: + + if (condition) { + do_this (); + do_that (); + } else { + do_the_other (); + } + +but some of the code uses an alternate style: + + if (condition) + { + do_this (); + do_that (); + } + else + { + do_the_other (); + } + +and that seems just fine. We won't lay down any strict rule on this +point, (though there should be some local consistency). If you came +here hoping to find some guidance, then use the first form above. + +If all of the substatements of an if statement are single statements, +the optional braces should not usually appear: + + if (condition) + do_this (); + else + do_that (); + +But the braces are mandatory when mixing single statement and compound +statements in the various clauses. For example, do not do this: + + if (condition) { + do_this (); + do_that (); + } else /* Yuck! */ + do_the_other (); + +And of course, there are exceptions for when the code just looks +better with the braces: + + if (condition) { + /* Note that we have to be careful here. */ + do_something_dangerous (with_care); + } + + if (condition && + other_condition && + yet_another) + { + do_something (); + } + +And note that this last example also shows a situation in which the +opening brace really needs to be on its own line. The following looks awful: + + if (condition && + other_condition && + yet_another) { /* Yuck! */ + do_something (); + } + +As we said above, legible code that is easy to understand and maintain +is the goal, not adherence to strict rules. + +Whitespace +---------- +Separate logically distinct chunks with a single newline. This +obviously applies between functions, but also applies within a +function or block and can even be used to good effect within a +structure definition: + + struct _cairo_gstate { + cairo_operator_t op; + + double tolerance; + + /* stroke style */ + double line_width; + cairo_line_cap_t line_cap; + cairo_line_join_t line_join; + double miter_limit; + + cairo_fill_rule_t fill_rule; + + double *dash; + int num_dashes; + double dash_offset; + + ... + } + +Use a single space before a left parenthesis, except where the +standard will not allow it, (eg. when defining a parameterized macro). + +Don't eliminate newlines just because things would still fit on one +line. This breaks the expected visual structure of the code making it +much harder to read and understand: + + if (condition) foo (); else bar (); /* Yuck! */ + +Do eliminate trailing whitespace (space or tab characters) on any +line. Also, avoid putting initial or final blank lines into any file, +and never use multiple blank lines instead of a single blank line. + +Do enable the default git pre-commit hook that detect trailing +whitespace for you and help you to avoid corrupting cairo's tree with +it. Do that as follows: + + chmod a+x .git/hooks/pre-commit + +You might also find the git-stripspace utility helpful which acts as a +filter to remove trailing whitespace as well as initial, final, and +duplicate blank lines. + +As a special case of the bracing and whitespace guidelines, function +definitions should always take the following form: + + void + my_function (argument) + { + do_my_things (); + } + +And function prototypes should similarly have the return type (and +associated specifiers and qualifiers) on a line above the function, so +that the function name is flush left. + +Break up long lines (> ~80 characters) and use whitespace to align +things nicely. For example the arguments in a long list to a function +call should all be aligned with each other: + + align_function_arguments (argument_the_first, + argument_the_second, + argument_the_third); + +And as a special rule, in a function prototype, (as well as in the +definition), whitespace should be inserted between the parameter types +and names so that the names are aligned: + + void + align_parameter_names_in_prototypes (const char *char_star_arg, + int int_arg, + double *double_star_arg, + double double_arg); + +Note that parameters with a * prefix are aligned one character to the +left so that the actual names are aligned. + +Managing nested blocks +---------------------- +Long blocks that are deeply nested make the code very hard to +read. Fortunately such blocks often indicate logically distinct chunks +of functionality that are begging to be split into their own +functions. Please listen to the blocks when they beg. + +In other cases, gratuitous nesting comes about because the primary +functionality gets buried in a nested block rather than living at the +primary level where it belongs. Consider the following: + + foo = malloc (sizeof (foo_t)); + if (foo) { /* Yuck! */ + ... + /* lots of code to initialize foo */ + ... + return SUCCESS; + } + return FAILURE; + +This kind of gratuitous nesting can be avoided by following a pattern +of handling exceptional cases early and returning: + + foo = malloc (sizeof (foo_t)); + if (foo == NULL) + return FAILURE; + + ... + /* lots of code to initialize foo */ + ... + return SUCCESS; + +The return statement is often the best thing to use in a pattern like +this. If it's not available due to additional nesting above which +require some cleanup after the current block, then consider splitting +the current block into a new function before using goto. + +Memory allocation +----------------- + +Because much of cairo's data consists of dynamically allocated arrays, +it's very easy to introduce integer overflow issues whenever malloc() +is called. Use the _cairo_malloc2(), _cairo_malloc3(), and +_cairo_malloc2_add1 macros to avoid these cases; these macros check +for overflow and will return NULL in that case. + + malloc (n * size) => _cairo_malloc_ab (n, size) + e.g. malloc (num_elts * sizeof(some_type)) => + _cairo_malloc2 (num_elts, sizeof(some_type)) + + malloc (a * b * size) => _cairo_malloc_abc (a, b, size) + e.g. malloc (width * height * 4) => + _cairo_malloc3 (width, height, 4) + + malloc (n * size + k) => _cairo_malloc_ab_plus_c (n, size, k) + e.g. malloc (num * sizeof(entry) + sizeof(header)) => + _cairo_malloc2k (num, sizeof(entry), sizeof(header)) + +In general, be wary of performing any arithmetic operations in an +argument to malloc. You should explicitly check for integer overflow +yourself in any more complex situations. + +Mode lines +---------- + +So given the rules above, what is the best way to simplify one's life as +a code monkey? Get your editor to do most of the tedious work of +beautifying your code! + +As a reward for reading this far, here are some mode lines for the more +popular editors: +/* + * vim:sw=4:sts=4:ts=8:tw=78:fo=tcroq:cindent:cino=\:0,(0 + * vim:isk=a-z,A-Z,48-57,_,.,-,> + */ + + +TODO +---- + +Write rules for common editors to use this style. Also cleanup/unify +the modelines in the source files. diff --git a/Build/source/libs/cairo/cairo-src/COPYING b/Build/source/libs/cairo/cairo-src/COPYING new file mode 100644 index 00000000000..f54969f1c94 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/COPYING @@ -0,0 +1,33 @@ +Cairo is free software. + +Every source file in the implementation[*] of cairo is available to be +redistributed and/or modified under the terms of either the GNU Lesser +General Public License (LGPL) version 2.1 or the Mozilla Public +License (MPL) version 1.1. Some files are available under more +liberal terms, but we believe that in all cases, each file may be used +under either the LGPL or the MPL. + +See the following files in this directory for the precise terms and +conditions of either license: + + COPYING-LGPL-2.1 + COPYING-MPL-1.1 + +Please see each file in the implementation for copyright and licensing +information, (in the opening comment of each file). + +[*] The implementation of cairo is contained entirely within the "src" +directory of the cairo source distribution. There are other components +of the cairo source distribution (such as the "test", "util", and "perf") +that are auxiliary to the library itself. None of the source code in these +directories contributes to a build of the cairo library itself, (libcairo.so +or cairo.dll or similar). + +These auxiliary components are also free software, but may be under +different license terms than cairo itself. For example, most of the +test cases in the perf and test directories are made available under +an MIT license to simplify any use of this code for reference purposes +in using cairo itself. Other files might be available under the GNU +General Public License (GPL), for example. Again, please see the COPYING +file under each directory and the opening comment of each file for copyright +and licensing information. diff --git a/Build/source/libs/cairo/cairo-src/COPYING-LGPL-2.1 b/Build/source/libs/cairo/cairo-src/COPYING-LGPL-2.1 new file mode 100644 index 00000000000..f1ed6182c52 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/COPYING-LGPL-2.1 @@ -0,0 +1,510 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations +below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it +becomes a de-facto standard. To achieve this, non-free programs must +be allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control +compilation and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least + three years, to give the same user the materials specified in + Subsection 6a, above, for a charge no more than the cost of + performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply, and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License +may add an explicit geographical distribution limitation excluding those +countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms +of the ordinary General Public License). + + To apply these terms, attach the following notices to the library. +It is safest to attach them to the start of each source file to most +effectively convey the exclusion of warranty; and each file should +have at least the "copyright" line and a pointer to where the full +notice is found. + + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or +your school, if any, to sign a "copyright disclaimer" for the library, +if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James + Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/Build/source/libs/cairo/cairo-src/COPYING-MPL-1.1 b/Build/source/libs/cairo/cairo-src/COPYING-MPL-1.1 new file mode 100644 index 00000000000..7714141d154 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/COPYING-MPL-1.1 @@ -0,0 +1,470 @@ + MOZILLA PUBLIC LICENSE + Version 1.1 + + --------------- + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. + + 1.5. "Executable" means Covered Code in any form other than Source + Code. + + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. + + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or + previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). + + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF + DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE + IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, + YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE + COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER + OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the NPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is ______________________________________. + + The Initial Developer of the Original Code is ________________________. + Portions created by ______________________ are Copyright (C) ______ + _______________________. All Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] + diff --git a/Build/source/libs/cairo/cairo-src/HACKING b/Build/source/libs/cairo/cairo-src/HACKING new file mode 100644 index 00000000000..aba2c545bb9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/HACKING @@ -0,0 +1,185 @@ +Hacking Cairo +============= + +This is a high-level guide to how the cairo distribution is organized +and how to get started hacking on it. Make sure you read through the +file README before continuing. + + +Coding Style +------------ + +The easiest way to write code in the cairo style is to follow code close +to the place you are hacking, but if you want a written down set of +rules, see file CODING_STYLE. + +Files for backends that depend on languages other than C (C++ or +Objective C for example) may use features specific to those languages. +For example, "//" comments are allowed, though discouraged, in those files. + + +Contact +------- + +Various ways to get in touch with other cairo developers and maintainers +have been enumerated at: + + http://cairographics.org/contact/ + +Most of that information is also reflected in the following sections. + + +Mailing Lists +------------- + +There are various mailing lists that are useful when developing cairo +code. A complete list is always available at: + + http://cairographics.org/lists/ + +It is recommended that cairo developers subscribe to all those lists. +The cairo list by itself generates much more traffic than the others +combined, so developers and contributors should not be intimidated by +the -commit and -bugs lists. + + +Bug Tracking System +------------------- + +We use a standard bugzilla bug tracking system available at: + + http://bugs.freedesktop.org/ + +See file named BUGS for detailed information on reporting bugs. In short, +for straight bug reports, it's best to report them there such that they +are not lost or forgotten. For discussion of new features or +complicated issues, use the mailing list. + + +IRC +--- + +It's a great idea to hang around the cairo IRC channel if you have any +interest in cairo. We use the #cairo channel on irc.freenode.net. + +Make sure you introduce yourself if your nick is not easy to match to +the name you use on the mailing list. + + +Version Control System +---------------------- + +We use /git/ for version control. See: + + http://cairographics.org/download/ + +For more information on using git, see: + + http://freedesktop.org/wiki/Infrastructure/git/ + + +Build System +------------ + +We use the autotools build system with cairo, but with various +customizations and advanced features. Reading configure.in is your +best bet to understanding it, or just ask on IRC. + +To bootstrap the build system run ./autogen.sh. After that the +regular "./configure; make; make install" sequence can be used. +See file named INSTALL for more details. + +There is limited support for a win32 build system. +See README.win32 and Makefile.win32 files in various directories. + + +ChangeLog +--------- + +We generate ChangeLog files automatically from the git commit log. +No manual ChangeLog writing is necessary. + + +Copyrights and Licensing +------------------------ + +The cairo library is dual-licensed under LGPL and MPL. See the file +named COPYING for details. The test suites are more liberal, and are +allowed to include GPL code. + +When writing new code, update the file headers to add your (or your +employers) copyright line and contributor line. If adding new files +or splitting a file, copy the file header from other files. + + +Source Code +----------- + +The library source code and headers live in the src/ directory. +See src/README for more information. + + +Regression Test Suite +--------------------- + +Cairo has a fairly extensive regression-testing suite. Indeed, without +these tests it would be impossible to make a cairo release without +introducing tens of regressions. We still manage to introduce +regressions with each release even with the hundreds of tests we already +have. + +The regression test suite is located under the test/ directory. +See test/README for more information. + + +Performance Test Suite +---------------------- + +There is a performance test suite located under the perf/ directory. +A collection of traces of real-world behavior are also available in the +cairo-traces repository, which can be used in isolation or hooked in +with the main performance test suite. See perf/README for more +information. + + +Boilerplate +----------- + +The cairo-boilerplate is a small private library used by the regression +and performance test suites. It includes the boilerplace code needed +to initialize various backends for the test suites, as well as allow +tweaking some of the internal workings of the backends for more testing. + +The boilerplate code is localted under the boilerplate/ directory. +See boilerplate/README for more information. + + +Documentation +------------- + +Cairo uses the gtk-doc system for reference API documentation. + +The reference documentation is located under doc/public. +See doc/public/README for more information. + +For more documentation including frequently asked questions, tutorials, +samples, roadmap, todo list, etc visit: + + http://cairographics.org/documentation/ + +Some of those should gradually be moved to doc/. + + +Utilities +--------- + +We have developed several utilities useful for writing cairo or code +that uses cairo. These tools can be found under the util/ directory. +See util/README for more information. + + +Releasing +--------- + +Now you are a cairo maintainer, so what? See file named RELEASING. + diff --git a/Build/source/libs/cairo/cairo-src/INSTALL b/Build/source/libs/cairo/cairo-src/INSTALL new file mode 100644 index 00000000000..9db68dee2ba --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/INSTALL @@ -0,0 +1,184 @@ +Quick-start build instructions +------------------------------ +1) Configure the package: + + ./configure + +2) Compile it: + + make + +3) Install it: + + make install + +This final step may require temporary root access (eg. with sudo) if +you don't have write permission to the directory in which cairo will +be installed. + +NOTE: If you are working with source from git/cvs rather than from a tar +file, then you should use ./autogen.sh in place of ./configure +anywhere it is mentioned in these instructions. + +More detailed build instructions +-------------------------------- +1) Configure the package + + The first step in building cairo is to configure the package by + running the configure script. [Note: if you don't have a configure + script, skip down below to the Extremely detailed build + instructions.] + + The configure script attempts to automatically detect as much as + possible about your system. So, you should primarily just accept + its defaults by running: + + ./configure + + The configure script does accept a large number of options for + fine-tuning its behavior. See "./configure --help" for a complete + list. The most commonly used options are discussed here. + + --prefix=PREFIX + + This option specifies the directory under which the software + should be installed. By default configure will choose a + directory such as /usr/local. If you would like to install + cairo to some other location, pass the director to configure + with the --prefix option. For example: + + ./configure --prefix=/opt/cairo + + would install cairo into the /opt/cairo directory. You could + also choose a prefix directory within your home directory if + you don't have write access to any system-wide directory. + + After installing into a custom prefix, you will need to set + some environment variables to allow the software to be + found. Assuming the /opt/cairo prefix and assuming you are + using the bash shell, the following environment variables + should be set: + + PKG_CONFIG_PATH=/opt/cairo/lib/pkgconfig + LD_LIBRARY_PATH=/opt/cairo/lib + export PKG_CONFIG_PATH LD_LIBRARY_PATH + + (NOTE: On Mac OS X, at least, use DYLD_LIBRARY_PATH in place + of LD_LIBRARY_PATH above.) + + --enable-XYZ + --enable-XYZ=yes + --enable-XYZ=auto + --enable-XYZ=no + --disable-XYZ + + Cairo's various font and surface backends and other features can be + enabled or disabled at configure time. Features can be divided into + three categories based on their default state: + + * default=yes: These are the recommended features like PNG functions + and PS/PDF/SVG backends. It is highly recommended to not disable + these features but if that's really what one wants, they can be + disabled using --disable-XYZ. + + * default=auto: These are the "native" features, that is, they are + platform specific, like the Xlib surface backend. You probably + want one or two of these. They will be automatically enabled if + all their required facilities are available. Or you can use + --enable-XYZ or --disable-XYZ to make your desire clear, and then + cairo errs during configure if your intention cannot be followed. + + * default=no: These are the "experimental" features, and hence by + default off. Use --enabled-XYZ to enable them. + + The list of all features and their default state can be seen in the + output of ./configure --help. + +2) Compile the package: + + This step is very simple. Just: + + make + + The Makefiles included with cairo are designed to work on as many + different systems as possible. + + When cairo is compiled, you can also run some automated tests of + cairo with: + + make check + + NOTE: Some versions of X servers will cause the -xlib tests to + report failures in make check even when cairo is working just + fine. If you see failures in nothing but -xlib tests, please + examine the corresponding -xlib-out.png images and compare them to + the -ref.png reference images (the -xlib-diff.png images might also + be useful). If the results seem "close enough" please do not report + a bug against cairo as the "failures" you are seeing are just due + to subtle variations in X server implementations. + +3) Install the package: + + The final step is to install the package with: + + make install + + If you are installing to a system-wide location you may need to + temporarily acquire root access in order to perform this + operation. A good way to do this is to use the sudo program: + + sudo make install + +Extremely detailed build instructions +------------------------------------- +So you want to build cairo but it didn't come with a configure +script. This is probably because you have checked out the latest +in-development code via git. If you need to be on the bleeding edge, +(for example, because you're wanting to develop some aspect of cairo +itself), then you're in the right place and should read on. + +However, if you don't need such a bleeding-edge version of cairo, then +you might prefer to start by building the latest stable cairo release: + + http://cairographics.org/releases + +or perhaps the latest (unstable) development snapshot: + + http://cairographics.org/snapshots + +There you'll find nicely packaged tar files that include a configure +script so you can go back the the simpler instructions above. + +But you're still reading, so you're someone that loves to +learn. Excellent! We hope you'll learn enough to make some excellent +contributions to cairo. Since you're not using a packaged tar file, +you're going to need some additional tools beyond just a C compiler in +order to compile cairo. Specifically, you need the following utilities: + + automake + autoconf + autoheader + aclocal + libtoolize + pkg-config [at least version 0.16] + gtk-doc (recommended) + +Hopefully your platform of choice has packages readily available so +that you can easily install things with your system's package +management tool, (such as "apt-get install automake" on Debian or "yum +install automake" on Fedora, etc.). Note that Mac OS X ships with +glibtoolize instead of libtoolize. + +Once you have all of those packages installed, the next step is to run +the autogen.sh script. That can be as simple as: + + ./autogen.sh + +But before you run that command, note that the autogen.sh script +accepts all the same arguments as the configure script, (and in fact, +will generate the configure script and run it with the arguments you +provide). So go back up to step (1) above and see what additional +arguments you might want to pass, (such as prefix). Then continue with +the instructions, simply using ./autogen.sh in place of ./configure. + +Happy hacking! diff --git a/Build/source/libs/cairo/cairo-src/KNOWN_ISSUES b/Build/source/libs/cairo/cairo-src/KNOWN_ISSUES new file mode 100644 index 00000000000..c367f918ea3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/KNOWN_ISSUES @@ -0,0 +1,3 @@ +Known Issues +------------ +None diff --git a/Build/source/libs/cairo/cairo-src/Makefile.am b/Build/source/libs/cairo/cairo-src/Makefile.am new file mode 100644 index 00000000000..03fa3523649 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/Makefile.am @@ -0,0 +1,83 @@ +include $(top_srcdir)/build/Makefile.am.common + +EXTRA_DIST += \ + KNOWN_ISSUES \ + README.win32 \ + Makefile.win32 \ + build/Makefile.win32.common \ + build/Makefile.win32.inform \ + build/Makefile.win32.features \ + build/Makefile.win32.features-h \ + $(NULL) +#MAINTAINERCLEANFILES += \ +# $(srcdir)/build/Makefile.win32.features \ +# $(srcdir)/build/Makefile.win32.features-h \ +# $(NULL) + +ACLOCAL_AMFLAGS = -I build ${ACLOCAL_FLAGS} + +DIST_SUBDIRS = src doc util boilerplate test perf +SUBDIRS = src doc util +# libpng is required for our test programs +if CAIRO_HAS_PNG_FUNCTIONS +SUBDIRS += boilerplate test perf +endif + +configure: cairo-version.h + +doc: + cd doc && $(MAKE) $(AM_MAKEFLAGS) $@ +test retest recheck: all + cd test && $(MAKE) $(AM_MAKEFLAGS) $@ +perf: all + cd perf && $(MAKE) $(AM_MAKEFLAGS) $@ +check-valgrind: all + cd test && $(MAKE) $(AM_MAKEFLAGS) check-valgrind + cd perf && $(MAKE) $(AM_MAKEFLAGS) check-valgrind +.PHONY: doc test retest recheck perf check-valgrind + + +EXTRA_DIST += \ + AUTHORS \ + BIBLIOGRAPHY \ + BUGS \ + CODING_STYLE \ + COPYING \ + COPYING-LGPL-2.1 \ + COPYING-MPL-1.1 \ + HACKING \ + INSTALL \ + NEWS \ + PORTING_GUIDE \ + README \ + RELEASING \ + autogen.sh \ + cairo-version.h \ + $(NULL) + +DISTCLEANFILES += config.cache + +MAINTAINERCLEANFILES += \ + $(srcdir)/aclocal.m4 \ + $(srcdir)/autoscan.log \ + $(srcdir)/build/compile \ + $(srcdir)/build/config.guess \ + $(srcdir)/build/config.sub \ + $(srcdir)/build/depcomp \ + $(srcdir)/build/install-sh \ + $(srcdir)/build/ltmain.sh \ + $(srcdir)/build/missing \ + $(srcdir)/build/mkinstalldirs \ + $(srcdir)/config.h.in \ + $(srcdir)/configure.scan \ + $(NULL) + +DISTCHECK_CONFIGURE_FLAGS = \ + --enable-gtk-doc \ + --enable-test-surfaces \ + --enable-full-testing \ + $(NULL) + +include $(srcdir)/build/Makefile.am.changelog +include $(srcdir)/build/Makefile.am.releasing +include $(srcdir)/build/Makefile.am.analysis diff --git a/Build/source/libs/cairo/cairo-src/Makefile.win32 b/Build/source/libs/cairo/cairo-src/Makefile.win32 new file mode 100644 index 00000000000..fbad7f3e4c9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/Makefile.win32 @@ -0,0 +1,24 @@ +default: all + +# Do not edit this file. +# Edit build/Makefile.win32.common for customization + +top_srcdir = . +include $(top_srcdir)/build/Makefile.win32.inform + +all: cairo + +cairo: inform + @$(MAKE) -C src -f Makefile.win32 + +perf: inform + @$(MAKE) -C perf -f Makefile.win32 perf + +test: inform + @$(MAKE) -C test -f Makefile.win32 test + +clean: + @$(MAKE) -C boilerplate -f Makefile.win32 clean + @$(MAKE) -C perf -f Makefile.win32 clean + @$(MAKE) -C src -f Makefile.win32 clean + @$(MAKE) -C test -f Makefile.win32 clean diff --git a/Build/source/libs/cairo/cairo-src/NEWS b/Build/source/libs/cairo/cairo-src/NEWS new file mode 100644 index 00000000000..3ec0e6c898e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/NEWS @@ -0,0 +1,7485 @@ +Release 1.14.6 (2015-12-09 Bryce Harrington ) +======================================================================== +Simple bugfix release to fix one Windows issue. + +For a complete log of changes since 1.14.4, please see: + + http://cairographics.org/releases/ChangeLog.1.14.6 + +Features +-------- +None + +API Changes +----------- +None + +Dependency Changes +------------------ +None + +Performance Optimizations +------------------------- +None + +Bug Fixes +--------- +* Fix failure on Windows due to reference of the function + cairo_win32_surface_create_with_format(), which isn't included in the + 1.14.4 release. (Bug #92771) + + +Release 1.14.4 (2015-10-28 Bryce Harrington ) +======================================================================== +Just in time for Halloween we see another bug-fix release for Cairo. +This brings a few dozen straightforward bug fixes with no API changes. + +In addition, this includes a typical assortment of fixes to tests, +cleanup of warnings and memory leaks, correction of misspellings, +updates to documentation, etc. + +For a complete log of changes since 1.14.2, please see: + + http://cairographics.org/releases/ChangeLog.cairo-1.14.4 + + +Features +-------- +None + +API Changes +----------- +None + +Dependency Changes +------------------ +None + +Performance Optimizations +------------------------- +None + +Bug Fixes +--------- +* Avoid appending empty slots to user data arrays. Fixes a memory + consumption regression since commit 9341c254a. + +* Return a better error (file-not-found) when setting up pango on + devices where the font files don't have read permissions. + +* Fix regression in the font size of canvas text in Inkscape when + compiled with the Quartz backend. (Bug #84324) + +* Fix _cairo_gl_shader_bind_matrix() to maintain compatibility with + OpenGL ES 2.0. Manually transpose the matrix. + +* Fix incorrect font descriptor conversion when the font matrix yy is + negative. (Bug #90538) + +* Fix crash when using a complex path for clip and stroke due to + discarding the intersection exactly at the top edge. + (Bug #74779) + +* Fix cairo_get_locale_decimal_point() on Android + +* Fix compilation problem on AIX due to conflicting usage of symbol + 'jmpbuf'. (Bug #89339) + +* Fix broken rendering with XCB due to snapshotting of uploaded part of + surfaces. (Bug #67505) + +* Fix loss of alpha when copying a mask for a cairo recording surface, + resulting in a double copy. (Bugs #73038, #73901) + +* Fix incorrect recording of certain paths with script surfaces. + (Bug #91054) + +* Fix typo in definition of MAYBE_WARN in configure script. + (Bug #89750) + +* Fix use of filename variable after it's been freed. + (Bug #91206) + +* Fix out of bounds access when printing pattern. + (Bug #91266) + +* Fix incorrect size calculation in glyph cache unlocking for Cairo GL + compositor. + (Bug #91321) + +* Fix memory leak in _cairo_gl_pattern_texture_setup() + (Bug #91537) + +* Fix transparent images in win32-print. + (Bug #91835) + +* Fix _put_shm_image_boxes and _put_image_boxes when no SHM available + with XCB. + + +Release 1.14.2 (2014-03-09 Bryce Harrington ) +==================================================================== +This release provides collected bug fixes, along with one feature +enhancement for the xcb backend, and a small performance improvement for +fonts. + +The running theme of the bug fixes is platform-specific issues, both +build and run-time. Platforms with fixes include Sparc, AIX, Windows +(mingw), and Windows (MSVC8). Memory leaks, valgrind issues, and PDF +issues round out our list. + +It's come to light that changes in cairo 1.14 resulted in breakage on +MacOS X 10.4. We've not yet determined whether to fix up the support, +or excise the 10.4-specific code and support only OS X 10.5 or newer. +Meantime, we'll only advertise cairo as working on OS X 10.5. + +Features +-------- + * Improve xcb's handling of per-screen subpixel ordering. If no + Xft.rgba property is specified, default to the screen's subpixel + order. + +API Changes +----------- +None + +Dependency Changes +------------------ +None + +Performance Optimizations +------------------------- + * Improve performance of cpu_to_be32 and be32_to_cpu, making truetype + subsetting of large fonts run about 15% faster. + +Bug Fixes +--------- + * Fix unaligned access on sparc with the compact font format (CFF). + Unlike truetype, all data in CFF is not aligned. + (Debian bug #712836) + * Fix unaligned access on sparc with tor-scan-converter's memory pool. + * Fix crash when loading a PDF with a transformed image. + (fdo bug #85151) + * Fix regression on mingw for bigendian test due to removal of file + extension for executables. + (fdo bug #85120) + * Fix handling of backslash in PDF interpreter + (fdo bug #85662) + * Fix crash in xlib and xcb renderers when swapping a 0-sized glyph + * Fix bug with RTL text in PDF operators + (fdo bug #86461) + * Fix compilation 'cairo-path-stroke-traps.c' with MSVC8 + (fdo bug #84908) + * Fix crash in _fill_xrgb32_lerp_opaque_spans when a span length is + negative. + * Fix valgrind error by releasing pattern created by + cairo_pattern_create_rgb(). + * Fix valgrind errors when running cairo-test-suite. + * Fix memory leak in recording surface replays + (fdo bug #87898) + * Fix destruction of fonts in api-special-cases test. + (fdo bug #87567) + * Fix duplicated surface push on similar-image, preventing trivial GTK3 + program traces from being replayable, with an error message about + invalid values for the size of the input. + (fdo bug #73580) + * Fix crash when win32 surface's image size does not cover the entire + surface. + (fdo bug #53121) + * Fix crash due to obsolete CGFontGetGlyphPath call + (fdo bug #84324) + * Fix several build issues on AIX + (fdo bugs #89338, #89340, #89356, #89354) + * Fix various documentation warnings and errors + +Release 1.14.0 (2014-10-13 Bryce Harrington ) +==================================================================== +Hard to believe it's been over a year since our last release, but it's +not for lack of activity. This release includes contributions of a wide +assortment of bug fixes, build system improvements, warnings cleanups, +codebase refactoring, test suite repairs, and static analysis work. + +This release is lighter on features (compared with 1.12.10) but includes +a highly demanded rehaul of our image downscaling functionality, which +solves a serious problem experienced by Inkscape users when shrinking +embedded bitmaps in SVG files. The new scaling algorithms are used by +the image backend and by other backends as needed for fallbacks. + + +Features +-------- + + Filtering improvements for the image backend, in particular + down-scaling of images produces filtered images that depend on all the + pixels of the source. When using the image backend you get the + following settings: + + CAIRO_FILTER_GOOD: uses a box filter for scales less than .75 in + either direction. For scales larger than this, the same filter as + CAIRO_FILTER_BILINEAR is used. + + CAIRO_FILTER_BEST: uses a Catmull-Rom filter always. When upscaling + more than 2x this will produce anti-aliased square pixels, similar + to OS/X. + + CAIRO_FILTER_GAUSSIAN: uses PIXMAN_FILTER_BEST, which in current + pixman is the same as BILINEAR. (This is subject to change in the + future). + + xlib and xcb also use the image fallback for GOOD/BEST filters, but + note that other backends do not implement these filtering fixes yet, + however other actions may cause them to use an image fallback which + will cause these filters to be used. + + Improve handling of device transformation and scaling, allowing Cairo + to now support scaling at a device level, permitting easier, more + transparent HiDPI support. + + Support JBIG2 mime data in PDF. This allows embedding of more + compressed JPEG formats within PDF, rather than including the full + uncompressed image. Also, reduce the number of transparency groups + used by PDF to keep the file size small and viewing/printing of the + PDF fast. + + Expand the embedding section to include stencil mask support. + + Reorder font declarations to be in natural order. + + Update the Skia backend to build against current Skia (as of June + 2014). + + Drop Link-Time Optimization (LTO) support from build system. This + seems to have caused much trouble for unclear benefit, and most + distros are reverting or disabling it anyway. + + Optimize VBO size on GL to 1M and to 16k for EGL. This improves + (theoretical) performance for desktop GLX use cases while avoiding + hitting VBO memory size limitations on embedded devices. + +API Changes +----------- + + cairo_surface_set_device_scale, cairo_surface_get_device_scale: + + Sets a scale that is multiplied to the device coordinates + determined by the CTM when drawing to @surface. One common use for + this is to render to very high resolution display devices at a scale + factor, so that code that assumes 1 pixel will be a certain size + will still work. + + cairo_egl_device_get_display, cairo_egl_device_get_context: + + Support get/set of EGLContext and EGLDisplay for egl-based cairo + devices, similar to GLX. + +Dependency Changes +------------------ + + Cairo now requires glib 2.14 for its gobject helper functions, + and pixman 0.30 for downscaling. + + +Bug fixes +--------- + + Don't embed CMYK Jpeg images in svg. + + Fix tests to place output in proper location. + + Fix determination of alpha for all surfaces when recording. + + Extend oversize check to cairo_gl_surface_create_for_texture, so an + error surface is returned if the texture is too large to render to. + + Fix embedding of mime data in PDF and PS files. + + Remove useless error handling in *_reply() functions in XCB. + + Fix a double-free exposed by multithreaded apps creating and + destroying the same font concurrently. + https://bugs.freedesktop.org/show_bug.cgi?id=69470 + + Fix corrupt stacks produced by bugs in operand emission for trace. + + Fix out of bounds array access in format cache for xlib + + Don't rename glyphs used by seac operator. This can cause certain + combined characters to use their decorations (e.g. umlauts on ö) to be + lost during printing of PDFs using evince. + https://bugs.freedesktop.org/show_bug.cgi?id=70364 + + Fix crash on calling cairo_create with a finished surface + + Fix SSIZE_T definition problem when making with MSYS on Windows7 + + Fix one off issue in gl context cleanup + + Fix usage of CAIRO_STACK_ARRAY_LENGTH + + Fix rectangle stroke with non rectilinear pen + + Fix imagemask with pattern source failure on some printers. This bug + could cause files converted using pdftops to fail for example on Ricoh + printers, or opening in Adobe Distiller on Windows. + https://bugs.freedesktop.org/show_bug.cgi?id=69485 + + Fix whitespace in font names + + Fix page size in generated PDFs. When printing using pdftocairo on + larger page sizes, such as 11x17, the image would be cropped to letter + size. + https://bugs.freedesktop.org/show_bug.cgi?id=73452 + + Fix path-currentpoint test by preserving current-point in + copy_path()/append_path() sequence + + Fix generation of HTML in code docs for + cairo-format-stride-for-width. Raw HTML code was being passed + to the browser, instead of displaying normally. + https://bugs.freedesktop.org/show_bug.cgi?id=63257 + + Fix spelling of "tessellator" throughout code. We're using the + American rather than British spelling of this word. + https://bugs.freedesktop.org/show_bug.cgi?id=50411 + + Fix crash in pixman_image_composite32 + + Fix crash when trying to modify a (const) all-clipped cairo_clip_t + https://bugs.freedesktop.org/show_bug.cgi?id=75819 + + Add check_composite method to all compositors, to fix crashes in the + test suite. + + Fix crash in Firefox when scrolling on certain pages. + + Fix memory leaks found by static analysis. + + Fix build of any2ppm if fork is not available. + + Fix broken build for Qt backend, due to missing libstdc++. + + Fix typo in two cairo_uint128 functions. Fixes potential build issues + on systems without a uint128 type. + + Fix build when --enable-pdf=no + + Fix cache_frozen assertions for Win32 print. + + Correctly check for xcb image surface for inplace upload + + Fix webkit-based web browser crashes due to empty boxes by skipping + over them when tesselating. + + Make pixman, libpng, and zlib paths commandline configurable for win32 + builds. + + Fix image scale on Win32 when GDI scale is not identity. + + Fix float endian configure test when using clang -O4 + + Fix compilation with Android bionic libc + + Don't try to build util/sphinx on Windows + + Fix loss of precision when emitting joins. This was caused by + discrepancies in line gradients when passing trapezoids around. + + Fix loss of precision and associated rendering issues in + cairo-tor-scan-converter from projection onto sample grid. + + Fix pixman oversampling of neighbouring edges within a cell by + eliminating self-intersections for the pixman traps compositor. + + Fix multi-line string splitting in PDFs + + Various cleanups and fixes to warnings, documentation, tests, and + build system. Improve error handling and return value checks. + Cleanup XFAIL tests and reference images. Cover recently added + functionality. + + +Release 1.12.16 (2013-08-21 Chris Wilson ) +=================================================================== +Thanks to everybody who reported a bug and helped us develop a fix, +we have amassed quite a few bug fixes. There are still more outstanding +bugs that seek attention and a little bit of TLC, but this release has +been delayed long enough... + +Bug fixes +--------- + + Set the correct orientation for simple boxes with a negative scale + factor. + + Fix the creation of the shading dictionary in PDF. + + Fix a crash in PDF when incorporating an image with CAIRO_EXTEND_PAD. + https://bugs.freedesktop.org/show_bug.cgi?id=61451 + + Avoid upscaling bitmap fonts if possible. + + Fix an assertion failure within the mempool allocator for shared memory. + + Fix allocation size for CFF subsets. + + Export cairo_matrix_t for GObject bindings. + + Fix a double free in the Quartz backend. + https://bugs.freedesktop.org/show_bug.cgi?id=62885 + + Fix origin of GDI StretchBlits for the Windows backend + https://bugs.freedesktop.org/show_bug.cgi?id=61876 + + Fix error propagation for requests to create a similar surface with + negative size. + https://bugs.freedesktop.org/show_bug.cgi?id=63196 + + Fix complex clipping of trapezoids with regions + https://bugzilla.gnome.org/show_bug.cgi?id=697357 + + Stop leaking the image data when loading PNGs + + Fix unbounded operations with a clip mask through the span compositor + https://bugs.freedesktop.org/show_bug.cgi?id=61592 + + Add missing checks before rendering to a finished surface - so we return + an error rather than hit an assert. + https://bugs.freedesktop.org/show_bug.cgi?id=68014 + + Prevent an assertion failure when creating similar GL surfaces larger + than supported by hardware. + + Prevent a double free of a similar image under Windows. + https://bugs.freedesktop.org/show_bug.cgi?id=63787 + + +Release 1.12.14 (2013-02-10 Chris Wilson ) +=================================================================== +In the last week we had a few more bugs reported and promptly resolved. +As these are a combination of regressions and stability issues, it is +time for a prompt update and release. Many thanks to everyone for +testing and reporting issues, and helping to make Cairo better. + +Bug fixes +--------- + + Prevent user callbacks accessing user-data during destroy to prevent + use-after-free bugs. + https://bugzilla.mozilla.org/show_bug.cgi?id=722975 + + Use standard names for glyphs in subset fonts (PDF). + https://bugs.freedesktop.org/show_bug.cgi?id=60248 + + Fix detection of Win98. The logic for detecting Win98 (and its broken + AlphaBlend()) was inverted, disabling AlphaBlend() for everyone. + + Prevent numeric overflow from extrapolating polygon edges to the clip + boundary and causing severe render artifacts. + https://bugs.freedesktop.org/show_bug.cgi?id=60489 + + Fix computation of glyph string coordinates when breaking up runs + for xlib. + + Fix an assertion in the win32 backend for failing to clear its + similar-images. + https://bugs.freedesktop.org/show_bug.cgi?id=60519 + + +Release 1.12.12 (2013-01-31 Chris Wilson ) +=================================================================== +The goal of this release is to fix the synchronisation problems that +were exhibited in the SHM transport for cairo-xlib. This cropped up +any place that tried to rapidly push fresh pixel data to the X server +through an ordinary image surface, such as gimp-2.9 and evince. + +Bug fixes +--------- + + Avoid replacing the entire image when uploading subimages + https://bugs.freedesktop.org/show_bug.cgi?id=59635 + + Force synchronisation for scratch SHM image buffers, so that we do + not overwrite data as it is being read by X. + https://bugs.freedesktop.org/show_bug.cgi?id=59635 (also) + + Fix typos in detecting multisampling for the GL (MSAA) backend. + + Fix a memory leak in the GL (MSAA) backend. + + Fix a reference counting bug when mapping a GL surface to an image. + + +Release 1.12.10 (2013-01-16 Chris Wilson ) +=================================================================== +A heap of bug fixes everywhere, and the gradual completion of the MSAA +backend for cairo-gl. Perhaps the most noteworthy set of the bugfixes +was the crusage lead by Behdad Eshfabod to make font handling by +pango/cairo/fontconfig fully threadsafe. This testing revealed a couple +of races that needed fixing in Cairo's scaled-font and glyph cache. + +Bug fixes +--------- + + Append coincident elements to the recording's surface bbtree so that + the list is not corrupted and the overlapping elements lost. + + Fix cairo-trace to correctly record map-to-image/unmap-image and then + replay them. + + Ignore MappingNotifies when running the XCB testsuite as they are sent + to all clients when the keyboard changes. The testsuite would detect + the unexpected event and complain. + + Handle very large images in the XCB backend. + + Fix a memory leak in the xlib/shm layer, and prevent use of the SHM + surfaces after the display is closed. + https://bugs.freedesktop.org/show_bug.cgi?id=58253 + + Handle resizing of bitmap fonts, in preparation for a fix to + fontconfig to correctly pass on the user request for scaling. + + Always include subroutine 4 (hint replacement idion) when subsetting + type 1 fonts in order to prevent a crash in cgpdftops on Mac OS/X + + Fix a couple of typos in the cairo-gobject.h header files for + introspection. + + Prevent a mutex deadlock when freeing a scaled-glyph containing a + recording-surface that itself references another scaled-glyph. + https://bugs.freedesktop.org/show_bug.cgi?id=54950 + + Make scaled-font cache actually thread-safe and prevent + use-after-frees. + + Restore support for older versions of XRender. A couple of typos and a + few forgotten chunks prevented the xlib compositor from running + correctly with XRender < 0.10. Note that there are still a few + regressions remaining. + + +Release 1.12.8 (2012-11-24 Chris Wilson ) +=================================================================== +Another couple of weeks and a few more bugs have been found and fixed, +it is time to push the next point release. Many thanks to everyone who +reported their issues and helped us track down the bugs and helped +testing the fixes. + +Bug fixes +--------- + + Expand the sanity checking for broken combinations of XSendEvent and + ShmCompletionEvent. + + Notice that "The X.Org Foundation" sometimes also identifies itself + as "The Xorg Foundation". + + Handle various ages of libXext and its Shm headers. + + Fix the invalid clipping of the source drawable when using SHM + transport to upload images. + https://bugs.freedesktop.org/show_bug.cgi?id=56547 + + Handle all Type1 postscript operators for better font compatibility. + https://bugs.freedesktop.org/show_bug.cgi?id=56265 + + Fix a couple of memory leaks in Type1 font subsetting + https://bugs.freedesktop.org/show_bug.cgi?id=56566 + + Tighten the evaluation of the start/stop pen vertices, and catch a few + instances where we would use a fan instead of a bevel. + https://bugs.freedesktop.org/show_bug.cgi?id=56432 + + Fix assumption that geometric clipping always succeeds with the + span-compositor. + https://bugs.freedesktop.org/show_bug.cgi?id=56574 + + Fix call to spline intersection when evaluating whether a stoke is + visible. + + Remember to copy inferior sources when using SHM to readback the + surface for use as a source. + +Release 1.12.6 (2012-10-22 Chris Wilson ) +=================================================================== +Thanks to everyone who download cairo-1.12.4 and gave us their feedback. +It truly was invaluable and has helped us to fix many portability issues +that crept in with some of the new features. This release aims to fix +those stability issues and run on a wider range of systems. + +Bug fixes +--------- + + Fix the recording surface to actually snapshot the source and so fix + PDF drawing. + + Calling XSendEvent with an XShmCompletionEvent is incompatabile with + older Xorg servers. + + Reorder CloseDisplay chain so that XShm is not reinstantiated after + shutdown, causing a potential crash if the Display was immediately + recreated using the same memory address. + + Make sure that the Xserver has attached to the SHM segment before + deleting it from the global namespace on systems that do not support + deferred deletion. + + Type1 subsetting support for PDF (and PS) was once again improved to + work with a larger number of PDF readers. + + GLESv2 build fixes and improved support for embedded GPUs. + + Tweak the invisible pen detection for applications that are currently + using too large values for geometric tolerance. + + A build fix for older freetype libraries. + + +Release 1.12.4 (2012-10-05 Chris Wilson ) +=================================================================== +More bugs, and more importantly, more fixes. On the cairo-gl side, we +have refinements to the MSAA compositor which enables hardware +acceleration of comparatively low-quality antialiasing - which is useful +in animations and on very high density screens. For cairo-xlib, we have +finally enabled SHM transport for image transfers to and from the X +server. A long standing required feature, SHM transport offers a notable +reduction in rendering latency by reducing the number of copies +required to upload image data - given hardware and driver support, +cairo-xlib can now perform zero copy uploads onto the GPU. And as usual +Adrian Johnson has been very busy fixing many different corner cases in +cairo-pdf, impoving opacity groups and font subsetting. Last, but not +least, for cairo-image Søren Sandmann Pedersen added support for +rendering glyphs to pixman and using that from within cairo. The new +glyph rendering facility reduces the overhead for setting up the +compositing operation, improving glyph thoughput for the image backend +by a factor of about 4. And before he did so, he also fixed up a few +bugs in the existing glyph rendering code. So many thanks to Andrea +Canciani, Adrian Johnson, Chuanbo Weng, Dongyeon Kim, Henry Song, Martin +Robinson, Søren Sandmann Pedersen and Uli Schlachter for their +contributions, finding and fixing bugs. + +Bug fixes +--------- + + Interior boxes were being dropped when amalgamating regions during + tesselation. + https://bugs.freedesktop.org/show_bug.cgi?id=49446 + + Allow building without gtk-doc installed + + Invalid edge generation whilst reducing complex polygons. + https://bugs.freedesktop.org/show_bug.cgi?id=50852 + + Stroking around tight cusps + + Use locale correct formats for reading font subsetting and valid + buffers. + https://bugs.freedesktop.org/show_bug.cgi?id=51443 + + Ensure that the type1 subset includes all the glyph encodings + https://bugs.freedesktop.org/show_bug.cgi?id=53040 + + Upload the whole source for a repeating pattern. + https://bugs.freedesktop.org/show_bug.cgi?id=51910 + + Fix damage tracking to handle continuation chunks corectly and so + prevent crashes on win32. + https://bugs.freedesktop.org/show_bug.cgi?id=53384 + + Avoid emitting miter joins for degenerate line segments + https://bugzilla.mozilla.org/show_bug.cgi?id=407107 + + Convert the relative path semgents into the backend coordinates + and then back again to user coordinates (cairo_copy_path, + cairo_append_path) + https://bugs.freedesktop.org/show_bug.cgi?id=54732 + + Fix extents computations for a degenerate path consisting only of a + move-to + https://bugs.freedesktop.org/show_bug.cgi?id=54549 + + Prevent crashing on a degenerate project edge after polygon + intersection + https://bugs.freedesktop.org/show_bug.cgi?id=54822 + + + +Release 1.12.2 (2012-04-29 Chris Wilson ) +=================================================================== +After such a long gestation period for the release of Cairo 1.12, we +inevitably accumulated a few bugs that were flushed out by broadening the +test base. Thanks to everybody who tried the release, apologies to any one +unfortunate enough to encounter a bug and many thanks for reporting it. As +a result Adrian Johnson, Alexandros Frantzis, Andrea Canciani, Kalev +Lember, Maarten Bosman, Marcus Meissner, Nis Martensen and Uli Schlachter +have squashed many more bugs and improved the documentation. I would +strongly recommend everyone to upgrade to cairo-1.12.2. +-Chris + +Bug fixes +--------- + + Allow applications to create 0x0 xlib surfaces, such as used by LibreOffice. + https://bugs.freedesktop.org/show_bug.cgi?id=49118 + + Trim composite extents for SOURCE/CLEAR operators to the mask. + + Use fallback fonts in PDF for unhandled computed glyph widths + https://bugs.freedesktop.org/show_bug.cgi?id=48349 + + Handle snapshots of recording surfaces for analysing pattern extents. + Fixes a regression of reporting the PDF bounding box as being the page size. + + Fix allocation size for PDF pattern ids. + Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49089 + + Fix emission of rectilinear dashed segments, with and without scaling, and + application of degenerate line joins. + + Clamp unbounded fixup polygons to the clip extents. + + Prevent infinite loop due to rounding errors whilst incrementing along dashes. + + Prevent overflow for inline a8 span filling. + + Miscellaneous build fixes for Cygwin on Windows and Solaris. + +Release 1.12.0 (2012-03-23 Chris Wilson ) +=================================================================== +It's taken over 18 months, but the wait is finally over. A new cairo release! +We are pleased to annouce a new stable release of Cairo that brings many +new features and performance improvements, all whilst maintaining +compatibility with cairo-1.0 and all releases since. We recommend anyone +using a previous release of Cairo to upgrade to 1.12.0. + +The major feature of this release is the introduction of a new procedural +pattern; the mesh gradient. This, albeit complex, gradient is constructed +from a set of cubic Bezier patches and is a superset of all other gradient +surfaces which allows for the construction of incredibily detailed patterns. +In PDF parlance, the mesh gradient corresponds with type 7 patterns. Many +thanks to Andrea Canciani for bringing this to Cairo, and for his work on +making gradient handling robust. + +Not content with just adding another procedural pattern, Cairo 1.12 also +adds new API to create a callback pattern, +cairo_pattern_create_raster_source, that allows the application to +provide the pixel data for the region of interest at the time of +rendering. This can be used for instance, by an application to decode +compressed images on demand and to keep a cache of those decompressed +images, independently of Cairo. When combined with the recording +surface, it should form a useful basis for a deferred renderer. + +With the release of cairo-1.12, we also introduce a new supported +backend for interoperating with X using XCB. Uli Schlachter, also +maintainer of awesome and contributor to libxcb, has volunteered to +maintain cairo-xcb for us. Thanks Uli! + +For cairo-1.12, we have also added some common API to address any +surface as an image and so allow direct modification of the raster data. +Previously, only the Quartz and Win32 backends supported a very narrow +interface to allow for efficient pixel upload. Now with +cairo_surface_create_similar_image, cairo_surface_map_to_image, and +cairo_surface_unmap_image, Cairo exports a consistent method for +treating those surfaces as an image and so allow modification inplace. +These are the same routines used internally, and should support +efficient transfer or direct mapping of the target surfaces as +applicable. + +Another focus over the past year has been to address many performance +issues, without sacrificing the composition model. To accomplish the +goal, once again the rasterisation pipeline was overhauled and made +explicit, giving the backends the freedom to implement their own +specific pipeline whilst also providing a library of common routines +from which to build the pipeline. For instance, this allows the image +backend and the gl backend to composite scan line primitives inplace, +and to then implement custom fallbacks to catch the corner cases that do +not map onto their fastest paths. Similarly, this allows for the Xlib +backend to implement trapezoidation without compromising the other +backends, yet still allow for the pipeline to be used elsewhere for +testing and fallbacks. Clipping was once again overhauled, so that the +common cases for the raster pipelines could be captured and processed +with fast paths with the emphasis on performing geometric clipping to +reduce the frequency of using multi-pass clipmasks. Stroking was made +faster, both by providing specialised fast-paths for simple, yet frequent, +cases (such as stroking around a rectangle) and by reducing the number +of edges generated by the general stroker. + +As part of the focus on performance, Cairo 1.12 introduces some +antialias hints (NONE, FAST, GOOD, BEST) that are interpolated by the +rasterisers to fine tune their performance versus quality. Cairo 1.12 +also introduces a new observation architecture, +cairo_surface_observer_t, which can be used to analyse the amount of +time consumed by drawing commands and help identify inefficiencies in +both Cairo and the application. + +Last, but by no means least, the OpenGL backend has seen significant +work including the port to GLESv2 and the exploitation of advanced +hardware features. Interesting times. + +As always, I would like to thank everyone who contributed to Cairo, +not only through writing code, but also submitting documentation, bug +reports, suggestions and generally having fun with Cairo! In particular +though this release could not have happened without the efforts of +Adrian Johnson, Alexandros Frantiz, Andrea Canicani, Martin Robinson, +Nis Martensen, and Uli Schlachter. Thanks. +-Chris + +Snapshot 1.11.4 (2012-13-12) +============================ +The cairo community is pleased to finally announce the long aniticpated +release candidate for 1.12, 1.11.4, of the cairo graphics library. This +is the first major update to cairo in over a year and brings a large +number of new features; undoubtably a few bugs as well. + +While many people have contributed and have helped to test the release, +providing feedback on 1.10 and suggesting improvements, this release +is the result of a few persevering souls who deserve recognition for their +outstanding contributions: Andrea Canciani (all round bug fixing, +performance tuning and master of the gradients), Adrian Johnson (PDF +supremo) and Uli Schlachter (who stepped forward as maintainer for the +XCB backend). + +Major additions since 1.11.2: + + * cairo_surface_map_to_image API for pixel level access to any surface + + * New antialias hints to control the trade-off between speed and quality + + * A callback pattern, cairo_pattern_create_raster_source, for lazy + decoding of image data. + + * cairo_surface_observer_t, a new type of surface to gather performance + statistics + + * XCB as a supported backend + + * A rewritten compositor pipeline for performance improvements for, but not + limited to, the xlib and image backends. + From ION and PineView through to SandyBridge, every machine I have shows + across the board performance improvement on the cairo-traces: + + i5-2520m gnome-system-monitor: 5.97x speedup + pnv gnome-system-monitor: 4.86x speedup + i5-2520m firefox-asteroids: 4.66x speedup + pnv firefox-asteroids: 4.43x speedup + image firefox-canvas: 3.82x speedup + i5-2520m firefox-canvas-alpha: 3.49x speedup + image firefox-asteroids: 2.87x speedup + pnv firefox-talos-svg: 2.83x speedup + ion grads-heat-map: 2.75x speedup + pnv firefox-canvas-alpha: 2.66x speedup + image gnome-system-monitor: 2.66x speedup + image swfdec-giant-steps: 2.46x speedup + image firefox-canvas-alpha: 2.14x speedup + i5-2520m firefox-talos-svg: 2.03x speedup + image grads-heat-map: 2.02x speedup + ion gnome-system-monitor: 2.00x speedup + pnv firefox-particles: 1.99x speedup + i5-2520m grads-heat-map: 1.96x speedup + pnv firefox-canvas: 1.92x speedup + ion firefox-particles: 1.80x speedup + image poppler-reseau: 1.77x speedup + pnv xfce4-terminal-a1: 1.72x speedup + image firefox-talos-svg: 1.65x speedup + pnv grads-heat-map: 1.63x speedup + i5-2520m firefox-canvas: 1.63x speedup + pnv swfdec-youtube: 1.62x speedup + image ocitysmap: 1.59x speedup + i5-2520m firefox-fishbowl: 1.56x speedup + i5-2520m poppler-reseau: 1.50x speedup + i5-2520m evolution: 1.50x speedup + i5-2520m midori-zoomed: 1.43x speedup + pnv firefox-planet-gnome: 1.42x speedup + i5-2520m firefox-talos-gfx: 1.41x speedup + i5-2520m gvim: 1.41x speedup + pnv ocitysmap: 1.37x speedup + image poppler: 1.31x speedup + ion firefox-canvas-alpha: 1.35x speedup + ion firefox-talos-svg: 1.34x speedup + i5-2520m ocitysmap: 1.32x speedup + pnv poppler-reseau: 1.31x speedup + i5-2520m firefox-planet-gnome: 1.31x speedup + pnv firefox-fishbowl: 1.30x speedup + pnv evolution: 1.28x speedup + image gvim: 1.27x speedup + i5-2520m swfdec-youtube: 1.25x speedup + pnv gnome-terminal-vim: 1.27x speedup + pnv gvim: 1.25x speedup + image firefox-planet-gnome: 1.25x speedup + image swfdec-youtube: 1.25x speedup + ... + +And a plethora of minor improvements everywhere! +-Chris + +Snapshot 1.11.2 (2011-01-23) +=========================== + +In this first snapshot along the way to cairo-1.12.0, we are very excited +to announce the introduction of Bezier surface gradients, known as type +6/7 gradients in PS/PDF parlance. This is the culmination of much work by +the dynamic duo: Adrian Johnson and Andrea Canciani. Thanks guys! + +Also, I want to warmly welcome Uli Schlachter who recently joined the +Cairo community on a mission. That mission is to make cairo-xcb a +supported backend for 1.12. And for this snapshot he has made great +strides in fixing all the bugs I had left behind. Thanks Uli! + +And we have also seen a new contributor, Alexandros Frantzis, who has +begun bringing up cairo-gl for GLESv2 devices. Thanks Alex! + +And lastly, I must also thank Adrian and Andrea for the vast numbers of +bugs that they have tackled between them, fixing all those little corner +cases that lie hidden until too late. + +API additions: + +The ability to construct piece-wise Bezier surface gradients: + + cairo_pattern_create_mesh + + constructs a pattern of type CAIRO_PATTERN_TYPE_MESH using + + cairo_pattern_mesh_begin_patch + cairo_pattern_mesh_end_patch + cairo_pattern_mesh_curve_to + cairo_pattern_mesh_line_to + cairo_pattern_mesh_move_to + cairo_pattern_mesh_set_control_point + cairo_pattern_mesh_set_corner_color_rgb + cairo_pattern_mesh_set_corner_color_rgba + cairo_pattern_mesh_get_patch_count + cairo_pattern_mesh_get_path + cairo_pattern_mesh_get_corner_color_rgba + cairo_pattern_mesh_get_control_point + +The introduction of a unique ID accessible via the mime data type: + CAIRO_MIME_TYPE_UNIQUE_ID + + + + + +Release 1.10.2 (2010-12-25 Chris Wilson ) +=================================================================== +The cairo community is pleased to announce the 1.10.2 release of the +cairo graphics library. This is the first update to cairo's stable 1.10 +series and contains a large number of bug fixes. + +While many people have contributed and have help to test the release, +2 people deserve special recognition for their efforts in tracking down +and fixing bugs, Andrea Canciani and Adrian Johnson. Thanks to their +tremendous efforts, and of all cairo contributors, it is much +appreciated. + +We recommend everyone upgrade to cairo 1.10.2 and hope that everyone +will continue to have lots of fun with cairo! + +-Chris + +Bug fixes +--------- + + Fix embedding of grayscale jpegs in PS. + https://bugs.freedesktop.org/show_bug.cgi?id=31632 + + Fix the reported path of extents containing a curve. + + Fix the compositing of unaligned boxes. + + Reset the clipper in PDF upon finish. + + Fix degenerates arcs to become a degenerate line. + + Build support for autoconf 2.67 + + Fix painting of transformed patterns in PS + + Fix the EPS bounding box for PS + https://bugs.freedesktop.org/show_bug.cgi?id=24688 + + Fix the missing content for EPS + https://bugs.freedesktop.org/show_bug.cgi?id=24688 + + Fix regression upon changing page size in PS/PDF + https://bugs.freedesktop.org/show_bug.cgi?id=24691 + + Only use ActualText with PDF-1.5 documents + + Fix the bbox for type1 fallbacks. + + Reset the color after ending the context in PDF + https://bugs.freedesktop.org/show_bug.cgi?id=31140 + + Fix the advance of subsetted type1 fonts + https://bugs.freedesktop.org/show_bug.cgi?id=31062 + + Fix handling of EXTEND_NONE gradients for PDF + + Restrict in-place optimisation for a8 image masks with SOURCE + + +Release 1.10.0 (2010-09-06 Chris Wilson ) +=================================================================== +The cairo community is astounded (and flabbergast) to finally announce +the 1.10.0 release of the cairo graphics library. This is a major update +to cairo, with new features and enhanced functionality which maintains +compatibility for applications written using any previous major cairo +release, (1.8, 1.6, 1.4, 1.2, or 1.0). We recommend that anybody using +a previous version of cairo upgrade to cairo 1.10.0. + +One of the more interesting departures for cairo for this release is the +inclusion of a tracing utility, cairo-trace. cairo-trace generates a +human-readable, replayable, compact representation of the sequences of +drawing commands made by an application. This can be used to inspecting +applications to understand issues and as a means for profiling +real-world usage of cairo. + +The traces generated by cairo-trace have been collected in + + git://git.cairographics.org/git/cairo-traces + +and have driven the performance tuning of cairo over the last couple of +years. In particular, the image backend is much faster with a new +polygon rasterisation and a complete overhaul of the tessellator. Not +only is this faster, but also eliminates visual artifacts from +self-intersecting strokes. Not only has cairo-trace been driving +performance improvements within cairo, but as a repeatable means of +driving complex graphics it has been used to tune OpenGL, DDX, and +pixman. + +Cairo's API has been extended to better support printing, notably +through the ability to include a single compressed representation of an +image for patterns used throughout a document, leading to dramatic file +size reductions. Also the meta-surface used to record the vector +commands compromising a drawing sequence is now exposed as a +CAIRO_SURFACE_TYPE_RECORDING, along with a new surface that is a child of a +larger surface, CAIRO_SURFACE_TYPE_SUBSURFACE. One typical usage of a +subsurface would be as a source glyph in a texture atlas, or as a +restricted subwindow within a canvas. + +Cairo's API has also resurrected the RGB16 format from the past as +the prevalence of 16-bit framebuffers has not diminished and is a +fore-taste of the extended format support we anticipate in the future. +Increasing cairo's utility, we introduce the cairo_region_t for handling +sets of pixel aligned rectangles commonly used in graphics applications. +This is a merger of the GdkRegion and the pixman_region_t, hopefully +providing the utility of the former with the speed of the latter. + +Furthermore cairo has been reworked to interoperate more closely with +various acceleration architectures, gaining the ability to share +those hardware resources through the new cairo_device_t. For instance, +with the new OpenGL backend that supersedes the Glitz backend, hardware +and rendering operations can be shared between a classic OpenGL +application mixing libVA for the hardware assisted video decode with +cairo for high quality overlays all within the same OpenGL canvas. + +Many thanks for the hard work of Adrian Johnson, Andrea Canciani, Behdad +Esfahbod, Benjamin Otte, Carl Worth, Carlos Garcia Campos, Chris Wilson, +Eric Anholt, Jeff Muizelaar, Karl Tomlinson, M Joonas Pihlaja, Søren +Sandmann Pedersen and many others that have contributed over the last +couple of years to cairo. Thank you all! + +Snapshot 1.9.14 (2010-07-26) +============================ + + A quiet couple of weeks, hopefully Cairo is seeing widescale deployment and + we are being to see the results of the stabilisation effort. Clipping bugs + seems to have been the order of the last couple of weeks, with a couple + reported and duly fixed. Thank you Igor Nikitin and Karl Tomlinsion for + finding those regressions. At this point all that seems to remain to do is + to fix the outstanding regressions in the PDF backend... + +Bugs fixes +---------- + + Clip doesn't work for text on the image backend + https://bugs.freedesktop.org/show_bug.cgi?id=29008 + + Add explicit dependency for cxx + https://bugs.freedesktop.org/show_bug.cgi?id=29114 + + Fix regressions in reporting clip extents + https://bugs.freedesktop.org/show_bug.cgi?id=29120 + https://bugs.freedesktop.org/show_bug.cgi?id=29121 + https://bugs.freedesktop.org/show_bug.cgi?id=29122 + https://bugs.freedesktop.org/show_bug.cgi?id=29124 + https://bugs.freedesktop.org/show_bug.cgi?id=29125 + + +Snapshot 1.9.12 (2010-07-12) +============================ + + A couple of weeks spent fixing those annoying bugs and cleaning up the build + system; the list of outstanding tasks to complete for the stable release is + finally shrinking. The chief bug fixer has been Benjamin Otte who not only + made sure that the public API is consistent and being tested for its + consistency, but also ensured that the documentation was up-to-date and + spent time clarifying cases where even the Cairo developers have come + unstuck in the past. Many thanks, Benjamin. However, he was not alone, + as Andrea Canciani continued his fine work in isolating broken corner cases + and proceeding to fix them, and tidying up the quartz backend. And last, but + definitely not least, M Joonas Pihlaja tried building Cairo across a + perverse range of systems and fixed up all the loose bits of code that came + unravelled. Thanks everybody! + +API Changes +----------- + + cairo_surface_set_mime_data, cairo_surface_get_mime_data: + + The length parameter is now an unsigned long (as opposed to an unsigned + int). The parameter is intended to be an equivalent to a size_t without + requiring POSIX types and be large enough to store the size of the + largest possible allocation. + + cairo_gl_surface_create_for_texture: + + This a new surface constructor for cairo-gl that explicitly enables + render-to-texture for foreign, i.e. application, textures. + + cairo_region_xor, cairo_region_xor_rectangle + + A couple of utility routines add to the region handling interface for + the purpose of replacing existing GdkRegion functionality. + +Bugs fixes +---------- + + https://bugs.launchpad.net/ubuntu/+source/cairo/+bug/600622 + + Inkscape was caught in the act of attempting to modify a finished surface. + Unfortunately, we had the ordering of our guards and assertions wrong and + so an ordinary application error was triggering an assert in Cairo. This + lead Benjamin to add a test case to ensure that the entire public API + could handle erroneous input and then proceeded to fix a whole slew of + uncovered bugs. + + + https://bugs.freedesktop.org/show_bug.cgi?id=28888 + + A regression introduced by the special casing of uploading images to an + xlib surface in-place which was ignoring the translation applied to the + image. + + +Snapshot 1.9.10 (2010-06-26) +============================ + + The first "quick" snapshot in the run up to the stable release. The + last snapshot was picked up by the bleeding edge distributions and so the + bug reports have to started to roll in. The most frequent of these are the + introduction of rendering errors by applications that modify a surface + without subsequently calling cairo_surface_mark_dirty(). Make sure the + application developers are aware of increased reliance on strict use of the + Cairo API before 1.10 is released! + + The usual slew of bugs reported and we would like to thank Zoxc for + contributing the WGL interface for cairo-gl, and finding more build + failures on win32. And it just wouldn't be a 1.9 snapshot unless + Benjamin Otte improved the error handling within cairo-gl, as well as + isolating and fixing some more errors in the test suite. The biggest bug of + the snapshot turned out to be a major sign extension issue that had lain + hidden for many years and was suddenly exposed by incorrectly rounding + rectangles when performing non-antialiased rendering. Also to the relief + of many we have included the downstream patch to honour the user's LCD + filtering preferences for subpixel rendering of fonts. The interface + remains private for the time being, whilst the proposed public API is + finalized. + +API changes +----------- + None. + +Snapshot 1.9.8 (2010-06-12) +=========================== + + One major API changes since the last snapshot, and a whole slew of bugs + fixed and inconsistencies eliminated. Far too many bugs fixed to + individually identify. We need to thank Benjamin Otte for his fantastic + work on the cairo-gl backend making it faster and more robust, Andrea + Canciani for finding so many bugs and developing test cases for them, as + well fixing them. And last but not least we must all thank Adrian Johnson for + continuing to eliminate bugs and improving the PostScript and PDF backends. + + This snapshot represents almost 4 months of bug fixing, bringing Cairo to + a point where we consider it almost ready to be a candidate for release. + There are a few known bugs left to be fixed, being tracked in + https://bugs.freedesktop.org/show_bug.cgi?id=24384, so please give Cairo a + whirl and report any regressions. The plan is to release a new snapshot + every other week leading to a 1.10 release with a target date of + 2010-08-16. + +API additions +------------- + CAIRO_FORMAT_RGB16_565 + + 16 bit devices still remain popular, and so with great demand, + CAIRO_FORMAT_RGB16_565 has been restored enabling applications to create + and use 16 bit images as sources and render targets. + + cairo_surface_create_for_rectangle() + + It is common practice to cut an image up into many smaller pieces and use + each of those as a source - a technique called texture atlasing. + cairo_surface_create_for_rectangle() extends Cairo to directly support use + of these subregions of another cairo_surface_t both as a source and as a + render target. + + cairo_region_create() + cairo_region_create_rectangle() + cairo_region_create_rectangles() + cairo_region_copy() + cairo_region_reference() + cairo_region_destroy() + cairo_region_equal() + cairo_region_status() + cairo_region_get_extents() + cairo_region_num_rectangles() + cairo_region_get_rectangle() + cairo_region_is_empty() + cairo_region_contains_rectangle() + cairo_region_contains_point() + cairo_region_translate() + cairo_region_subtract() + cairo_region_subtract_rectangle() + cairo_region_intersect() + cairo_region_intersect_rectangle() + cairo_region_union() + cairo_region_union_rectangle() + + The Cairo region API was actually added a couple of snapshots ago, but we + forgot to mention it at the time. A simple API for the handling of + rectangular pixel-aligned regions by Soeren Sandmann. + + +Backend-specific improvements +----------------------------- +cairo-gl + + Benjamin Otte made more than 200 commits in which he refactored the cairo-gl + backend, reducing a lot of code duplication and enabled him to begin working + on improving performance by reducing state changes and associated overhead. + +cairo-xlib + + Access to the underlying connection to the Display is now thread-safe + enabling cairo-xlib to be used in a multi-threaded application without fear + of random corruption. Thanks Benjamin Otte! + + cairo-xlib will now attempt to use PolyModeImprecise when compositing + trapezoids (i.e. a fill or a stroke operation with a non-trivial path) which + should allow hardware drivers more scope for accelerating the operation at + the cost of potentially incurring minute rendering errors. The mode can be + forced back to PolyModePrecise by setting the antialias parameter to + CAIRO_ANTIALIAS_SUBPIXEL. + +cairo-svg + + A notable improvement was contributed by Alexander Shulgin to enable SVG to + reference external image through the use an extended MIME data type. + +Snapshot 1.9.6 (2010-02-19) +=========================== +API additions +------------- + Add cairo_device_t + + The device is a generic method for accessing the underlying interface + with the native graphics subsystem, typically the X connection or + perhaps the GL context. By exposing a cairo_device_t on a surface and + its various methods we enable finer control over interoperability with + external interactions of the device by applications. The use case in + mind is, for example, a multi-threaded gstreamer which needs to serialise + its own direct access to the device along with Cairo's across many + threads. + + Secondly, the cairo_device_t is a unifying API for the mismash of + backend specific methods for controlling creation of surfaces with + explicit devices and a convenient hook for debugging and introspection. + + The principal components of the API are the memory management of: + + cairo_device_reference(), + cairo_device_finish() and + cairo_device_destroy(); + + along with a pair of routines for serialising interaction: + + cairo_device_acquire() and + cairo_device_release() + + and a method to flush any outstanding accesses: + + cairo_device_flush(). + + The device for a particular surface may be retrieved using: + + cairo_surface_get_device(). + + The device returned is owned by the surface. + +API changes (to API new in the cairo 1.9.x series) +-------------------------------------------------- + cairo_recording_surface_create() + cairo_recording_surface_ink_extents() + + These are the replacement names for the functions previously named + cairo_meta_surface_create and cairo_meta_surface_ink_extents. + + cairo_surface_set_mime_data + + This interface is now changed such that the MIME data will be + detached if the surface is modified at all. This guarantees that + the MIME data will not become out of synch due to surface + modifications, and also means that for the MIME data to be useful, + it must be set after all modifications to the surface are + complete. + +API removal (of experiment API) +------------------------------- + The cairo-glitz backend is removed entirely, (in favor of the new + cairo-gl backend). See below for more on cairo-gl. + +Generic fixes +------------- + + Many improvements for drawing of dashed strokes + + Fix incorrect handling of negative offset + Faster computation of first dash (avoids near-infinite looping) + Approximate extremely fine dash patterns with appropriate alpha value + + Optimize spans-based renderers for repeated rows, (such as in a rounded rectangle) + +Backend-specific improvements +----------------------------- +cairo-drm + + This is a new, direct-rendering backend that supports Intel graphics + chipsets in the i915 and i965 families. It's still experimental and + will likely remain that way for a while. It's already got extremely + good performance on the hardware it supports, so if nothing else + provides a working proof and performance target for the cairo-gl + work for Intel graphics. + +cairo-gl + + Start using GLSL to accelerate many operations. Many thanks to Eric + Anholt and T. Zachary Laine for this work. For the first time, we + have what looks like what will be a very compelling OpenGL-based + backend for cairo (in terms of both quality and performance). + + See this writeup from Eric for more details on recent progress of + cairo-gl (which he presented at FOSDEM 2010): + + http://anholt.livejournal.com/42146.html + +cairo-image + + The image backend is made dramatically faster (3-5 times faster for + benchmarks consisting primarily of glyph rendering). + +cairo-quartz fixes: + + Many fixes from Robert O'Callahan and Andrea Canciani including: + + Fixed gradient pattern painting + Improved A8 image handling + Fixes for "unbounded" and other compositing operators + +cairo-pdf fixes: + + Improvements to embedding of JPEG and JPEG2000 data. + +cairo-ps fixes: + + Fix printing of rotated user fonts. + +Snapshot 1.9.4 (2009-10-15) +=========================== +API additions: + + cairo_meta_surface_create() + cairo_meta_surface_ink_extents() + + Finally exporting the internal meta-surface so that applications + have a method to record and replay a sequence of drawing commands. + + cairo_in_clip() + + Determines whether a given point is inside the current clip. + ??? Should this be called cairo_in_paint() instead? in-clip is the test + that is performed, but in-paint would be similar to in-fill and in-stroke. + +New utilities: + + cairo-test-trace + + A companion to cairo-perf-trace, this utility replays a trace against + multiple targets in parallel and looks for differences in the output, + and then records any drawing commands that cause a failure. + Future plans: + Further minimisation of the fail trace using "delta debugging". + More control over test/reference targets. + +Backend improvements: + + xlib + + Server-side gradients. The theory is that we can offload computation + of gradients to the GPU and avoid pushing large images over the + connection. Even if the driver has to fallback and use pixman to render + a temporary source, it should be able to do so in a more efficient manner + than Cairo itself. However, cairo-perf suggests otherwise: + + On tiny, Celeron/i915: + + before: firefox-20090601 211.585 + after: firefox-20090601 270.939 + + and on tiger, CoreDuo/nvidia: + + before: firefox-20090601 70.143 + after: firefox-20090601 87.326 + + In particular, looking at tiny: + + xlib-rgba paint-with-alpha_linear-rgba_over-512 47.11 (47.16 0.05%) -> 123.42 (123.72 0.13%): 2.62x slowdown + █▋ + xlib-rgba paint-with-alpha_linear3-rgba_over-512 47.27 (47.32 0.04%) -> 123.78 (124.04 0.13%): 2.62x slowdown + █▋ + + +New experimental backends: + + QT + + OpenVG - The initial work was done by Øyvind Kolås, and made ready for + inclusion by Pierre Tardy. + + OpenGL - An advanced OpenGL compositor. The aim is to write a integrate + directed rendering using OpenGL at a high-level into Cairo. In + contrast to the previous attempt using Glitz which tried to + implement the RENDER protocol on top of OpenGL, using the + high-level interface should permit greater flexibility and + more offloading onto the GPU. + The initial work on the backend was performed by Eric Anholt. + +Long standing bugs fixed: + + Self-intersecting strokes. + + A long standing bug where the coverage from overlapping semi-opaque + strokes (including neighbouring edges) was simply summed in lieu of + a costly global calculation has been fixed (by performing the costly + global calculation!) In order to mitigate the extra cost, the + tessellator has been overhauled and tune, which handles the fallback + for when we are unable to use the new span rasteriser on the stroke + (e.g. when using the current RENDER protocol). The large number of + pixel artefacts that implementing self-intersection elimination + removes is ample justification for the potential performance + regression. If you unfortunately do suffer a substantial performance + regression in your application, please consider obtaining a + cairo-trace and submitting it to us for analysis and inclusion into + our performance suite. + +Special thanks: + + To the AuroraUX team for providing access to one of their OpenSolaris + machines for cairo and pixman development. http://www.auroraux.org/ + +Snapshot 1.9.2 (2009-06-12) +=========================== +API additions: + + cairo_surface_set_mime_data() + cairo_surface_get_mime_data() + + Should this take unsigned int, unsigned long or size_t for the length + parameter? (Some datasets may be >4GiB in size.) + + Associate an alternate, compressed, representation for a surface. + Currently: + "image/jp2" (JPEG2000) is understood by PDF >= 1.5 + "image/jpeg" is understood by PDF,PS,SVG,win32-printing. + "image/png" is understood by SVG. + + cairo_pdf_version_t + cairo_pdf_surface_restrict_to_version() + cairo_pdf_get_versions() + cairo_pdf_version_to_string() + + Similar to restrict to version and level found in SVG and PS, + these limit the features used in the output to comply with the PDF + specification for that version. + + CAIRO_STATUS_INVALID_SIZE + Indicates that the request surface size is not supported by the + backend. This generally indicates that the request is too large. + + CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED + Indicates that a required callback for a user-font was not implemented. + + CAIRO_STATUS_LAST_STATUS + This is a special value to indicate the number of status values enumerated + at compile time. (This may differ to the number known at run-time.) + + The built-in twin font is now called "@cairo:" and supports a limited set + of options like "@cairo:mono". Where are these specified? + + cairo_in_fill() now uses HTML Canvas semantics, all edges are inside. + +New experimental backends: + + CairoScript + +New utility: + + cairo-trace and cairo-perf-trace + + cairo-trace generates a human-readable, replayable, compact(-ish!) + representation of the sequences of drawing commands made by an + application. + + Under the util/cairo-script directory is a library to replay traces. + + perf/cairo-perf-trace replays traces against multiple backends + and makes useful benchmark reports. This is integrated with + 'make perf'. You may collect your own traces or take advantage + of traces collected by the community: + + git://git.cairographics.org/git/cairo-traces + + (Put this into perf/cairo-traces to run these as part of "make perf".) + + There is additional WIP in building a debugging tool for cairo applications + based on CairoScript (currently very preliminary, mostly serves to show + that GtkSourceView is too slow) : + + people.freedesktop.org:~ickle/sphinx + +Test suite overhaul: + + The test suite is undergoing an overhaul, primarily to improve its speed + and utility. (Expect more changes in the near future to improve XFAIL + handling.) + +Optimisations: + polygon rasterisation! Joonas implemented the Tor polygon scan converter, + on typical geometry is about 30% faster for the image backend. + + Bovine Polaroids! For those not in on the joke, this is the long + awaited "copy-on-write snapshot" or "COW snapshot" support. The + user-visible feature is that including the same image multiple times + into a PDF file should result in only a single instance of that + image in the final output. This is unlike previous versions of cairo + which would generate very large PDF files with multiple copies of + the same image. Adrian says that the PDF is not quite working as + well as it should yet, so we hope for further improvements before + cairo 1.10. + +Bug fixes: + + EXTEND_PAD. + + Better handling of large scale-factors on image patterns. + + Emit /Interpolate for PS,PDF images. + + Global glyph cache - cap on the total number of inactive glyphs, + should prove fairer for fonts with larger glyph sets. + + Compilation without fontconfig + + Improved handling of low-bitdepth sources (e.g. copying the contents + of 16-bit xserver windows) + +Regressions: + + cairo_traps_extract_region >10x slower. Fix pending. + +Still to come: + + Region tracking API (ssp) for damage tracking, hit testing etc + mime-surface + + An expiremental OpenGL backend? + + Tweaks to tessellator, allocations of patterns, delayed + initialisation of the xlib backend (reduce the cairo overhead of + render_bench by ~80%). + + +Release 1.8.8 (2009-06-16 Chris Wilson ) +================================================================== +The cairo community is pleased to announce the 1.8.8 release of the +cairo graphics library. This is the fourth update to cairo's stable +1.8 series and contains a small number of bug fixes (in particular a +few corrections to the documentation and a few fixes in the FreeType font +backend). This is being released just over six months after cairo 1.8.6. + +We recommend that everyone using cairo upgrade to 1.8.8. + +-Chris + +Build fixes +----------- +There were reports of incompatibilities with the autotools bundled in with +the 1.8.6 tarball. This release has been built with automake-1.10.2 and +autoconf-2.63. + +The configure check for FreeType has been improved: + + typo in check for version of freetype in configure script + https://bugs.freedesktop.org/show_bug.cgi?id=19283 + +Compilation on 64-bit MacOS/X fixes: + + Cannot build cairo_quartz_font_face_create_for_atsu_font_id on 64-bit Mac OS X + https://bugs.freedesktop.org/show_bug.cgi?id=15702 + +Bug fixes +--------- +Uninitialised status return within _cairo_clip_intersect_mask(). This caused +random crashes and general mayhem as an error could be generated causing all +rendering to the context to stop. + +Avoid transforming nearly-degenerate matrices into degenerate matrices: + + Painting stops in this case, using -moz-transform: scale, rotate and video + https://bugzilla.mozilla.org/show_bug.cgi?id=467423 + +A few FreeType font handling bugs were fixed: + + Rendering with PANGO_GRAVITY_EAST leads to different results with image and pdf + https://bugs.freedesktop.org/show_bug.cgi?id=21985 + + Don't call FT_Done_Face() on faces we did not create + + zombie ft_font_face / ft_unscaled_font mutual referencing problems + http://bugs.freedesktop.org/show_bug.cgi?id=21706 + +Ensure win32 font backend sets the return value to -1 (indicating the absent +glyph) if the font index lookup for the unicode character fails. And +similarly fix a bug where a fatal error was raised for an invalid glyph. + + cairo_scaled_font_glyph_extents breaks with invalid glyph id + http://bugs.freedesktop.org/show_bug.cgi?id=20255 + +Various improvements to the documentation, reported by Truc Troung: + + https://bugs.freedesktop.org/show_bug.cgi?id=20095 + https://bugs.freedesktop.org/show_bug.cgi?id=20154 + https://bugs.freedesktop.org/show_bug.cgi?id=20180 + https://bugs.freedesktop.org/show_bug.cgi?id=20183 + https://bugs.freedesktop.org/show_bug.cgi?id=20182 + https://bugs.freedesktop.org/show_bug.cgi?id=20441 + + +Release 1.8.6 (2008-12-13 Chris Wilson ) +================================================================== +The cairo community is pleased to announce the 1.8.6 release of the +cairo graphics library. This is the third update to cairo's stable +1.8 series and contains a small number of bug fixes (in particular a +few fixes for failures of cairo 1.8.4 on Quartz and PDF, and build fixes for +a couple of backends). This is being released just under a month after +cairo 1.8.4. + +We recommend that everyone using cairo upgrade to 1.8.6. + +-Chris + +Build fixes +----------- +Fix build of DirectFB backend with debugging enabled: + + Bug in _cairo_directfb_surface_release_source_image function + http://bugs.freedesktop.org/show_bug.cgi?id=18322 + +Fix build on OS/2. + +Bug fixes +--------- +Workaround a mis-compilation of cairo_matrix_invert() that generated invalid +matrices and triggered assertion failures later. The issue was reported by +Peter Hercek. + +Invalid computation of the modulus: + + https://bugzilla.mozilla.org/show_bug.cgi?id=466258 + +Invalid referencing of patterns in the Quartz backend: + + Failed assertion `CAIRO_REFERENCE_COUNT_HAS_REFERENCE + (&pattern->ref_count)' when using cairo quartz backend + http://bugs.freedesktop.org/show_bug.cgi?id=18632 + +Invalid references to glyphs after early culling, causing segmentation faults +in the PDF backend: + + http://lists.cairographics.org/archives/cairo/2008-December/015976.html + +Check for XRender in the XCB backend, or else we may attempt an invalid memory +access: + + XCB backend fails with missing render. + https://bugs.freedesktop.org/show_bug.cgi?id=18588 + +Release 1.8.4 (2008-11-14 Carl Worth ) +========================================================= +The cairo community is pleased to announce the 1.8.4 release of the +cairo graphics library. This is the second update to cairo's stable +1.8 series and contains a small number of bug fixes, (in particular a +few fixes for build failures of cairo 1.8.2 on various systems). This +is being released just over two weeks after cairo 1.8.2. + +We recommend that everyone using cairo upgrade to 1.8.4. + +-Carl + +Build fixes +----------- +Fix build with older XRender that doesn't define RepeatNone: + + Build of xlib backend fails against old XRender (RepeatNone undeclared) + https://bugs.freedesktop.org/show_bug.cgi?id=18385 + +Fix build with bash version <= 3.0: + + doltlibtool broken on linux with bash 3.00.0 + https://bugs.freedesktop.org/show_bug.cgi?id=18363 + +Bug fixes +--------- +Avoid triggering a bug in X.org server 6.9 resulting in a hung machine +requiring a reboot: + + https://bugs.freedesktop.org/show_bug.cgi?id=15628#c2 + +Fix display of user fonts as exercised by proposed support for type3 +fonts in poppler (unsigned promotion fixes): + + Use cairo user-font for Type 3 fonts + http://lists.freedesktop.org/archives/poppler/2008-October/004181.html + +Avoid miscomputing size of fallback images required when rendering +with CLEAR, IN, or SOURCE operator to vector surfaces, (PS, PDF, SVG, +etc.). + +Be more tolerant of broken fonts when subsetting type1 fonts: + + Error handling in cairo_type1_font_subset_get_glyph_names_and_widths + http://lists.cairographics.org/archives/cairo/2008-October/015569.html + +Fix cairo_fill_extents, cairo_stroke_extents, cairo_path_extents, to +correctly allow NULL parameters as documented. + +Fix potential crash on emitting a type3 glyph after having drawn text +paths from the same font, (for example with cairo_text_path). + +Release 1.8.2 (2008-10-29 Carl Worth ) +========================================================= +The cairo community is pleased to announce the 1.8.2 release of the +cairo graphics library. This is the first update to cairo's stable 1.8 +series and contains a large number of bug fixes. It is being released +just over one month since cairo 1.8.0. + +This release consists primarily of bug fixes, but there is one notable +new feature, (the ability to build cairo without an external font +backend), and there are a few optimizations as well. See below for +details on these changes and the most important bug fixes. + +While many people have contributed to this release, Chris Wilson +deserves particular mention. He has contributed well over twice as +many changes to cairo since 1.8.0 than everyone else combined. We +greatly appreciate the tremendous efforts of Chris and all cairo +contributors. + +We recommend everyone upgrade to cairo 1.8.2 and hope that everyone +will have lots of fun with cairo! + +-Carl + +New feature +----------- +It is now possible to build cairo without any font backend, (such as +freetype, win32 or quartz). This is most useful when the application +provides custom font rendering through the user-font API. But in the +case where no external font backend is available, and no user-font is +provided, cairo will render with a failsafe font, (a stroked font +covering visible ASCII character). (Behdad Esfahbod) + +Optimizations +------------- +Dramatically speed up compilation with dolt (removes much of the +libtool overhead) (Behdad Esfahbod with thanks to Josh Triplett). + +Several minor optimizations to tessellator (special-cased comparisons, +faster insert for skiplist, etc.) (Chris Wilson). + +Optimize away fractional translation component when doing +EXTEND_NEAREST filtering, (for better performance). + +General bug fixes +----------------- +Allow cloning sub-regions of similar surfaces to fix this bug +(Chris Wilson): + + Crafted gif file will crash firefox + [XError: 'BadAlloc (insufficient resources for operation)'] + https://bugzilla.mozilla.org/show_bug.cgi?id=424333 + +Fix some matrix confusion to fix this regression (Chris Wilson): + + Translucent star exports in a wrong way to PDF + https://bugs.launchpad.net/inkscape/+bug/234546 + +Fix some long-standing bugs with respect to properly computing the +extents of transformed, filtered surfaces (Owen Taylor, Carl Worth, +and Chris Wilson): + + Bad clipping with EXTEND_NONE + http://bugs.freedesktop.org/show_bug.cgi?id=15349 + + Improve filtering handling in cairo-pattern.c + http://bugs.freedesktop.org/show_bug.cgi?id=15367 + + Many thanks to Chris Wilson for digging out and cleaning up + these fixes. + +Fix compilation on Solaris 10 (Chris Wilson): + + Cairo requires -DREENTRANT (along with -D_POSIX_THREAD_SEMANTICS) + to compile on Solaris 10 with pthreads + https://bugs.freedesktop.org/show_bug.cgi?id=18010 + +Fix very old bug causing dashes to be rendered at the wrong length in +fallback images (Adrian Johnson) + + Dashed strokes too long in fallback images + https://bugs.freedesktop.org/show_bug.cgi?id=9189 + +Fix broken dashing when a dashed path starts outside the clip region +(Chris Wilson). + +Avoid range overflow when computing large patterns (Benjamin Otte and +Chris Wilson). + +Avoid crashing due to an invalid font with an incorrect entry in its +CMAP table (Adrian Johnson). + +Fix bugs in computing maximum size of text requests that can be sent +with the Render extension, (avoiding potential crashes when rendering +large amounts of text) (Behdad Esfahbod and Chris Wilson). + +Fix rendering of operators unbounded by the mask (Chris Wilson). + +Fix compilation on systems without compiler support for a native +64-bit type (Chris Wilson). + +Fix several cases of missing error-status propagation. (Chris Wilson, +doing the work he seems to never tire of). + +Fix several locking issues found with the lockdep valgrind skin (Chris +Wilson). + +Backend-specific bug fixes +-------------------------- +xlib: Avoid crash due to attempting XRender calls on pixmaps with +formats not supported by the Render extension (Chris Wilson): + + XRender crashes due to NULL pointer from Cairo on SGI O2 + https://bugs.freedesktop.org/show_bug.cgi?id=11734 + +xlib: Add support for XImages with depth of 4, 20, 24, or 28 bits +(Chris Wilson): + + cairo doesn't support 24 bits per pixel mode on X11 + https://bugs.freedesktop.org/show_bug.cgi?id=9102 + +xlib: Avoid mistakenly considering two surfaces as similar just +because their depths match (while their Render formats do not) (Karl +Tomlinson). + +ps: Fix slight mis-scaling of bitmapped fonts (Adrian Johnson) + +svg: Correctly emit comp-op for paint, mask, and show_glyphs +operations (Emmanuel Pacaud). + +svg: Use finer-grained fallbacks for SVG 1.2 (as PS and PDF backends +have been doing since 1.6.0) (Chris Wilson). + +win32: Fallback to DIB if DDB create fails for +cairo_surface_create_similar (Vladimir Vukicevic). + +win32: Fix compatibility with Windows Mobile (Vladimir Vukicevic). + +win32: Fix static builds to not do __declspec(dllimport) on public +functions. This requires the user to set a CAIRO_WIN32_STATIC_BUILD +environment variable when compiling (Behdad Esfahbod). + +Release 1.8.0 (2008-09-25 Carl Worth ) +========================================================= +The cairo community is happy (and relieved) to announce the 1.8.0 +release of the cairo graphics library. This is a major update to +cairo, with new features and enhanced functionality which maintains +compatibility for applications written using any previous major cairo +release, (1.6, 1.4, 1.2, or 1.0). We recommend that anybody using a +previous version of cairo upgrade to cairo 1.8.0. + +The dominant theme of this release is improvements to cairo's ability +to handle text. The highlights include a new "user fonts" feature as +well as a new cairo_show_text_glyphs API which allows glyphs to be +embedded in PDF output along with their original text, (for searching, +selection, and copy-and-paste). Another major feature is a revamp of +cairo's build system making it much easier to build cairo on various +platforms. + +See below for more details. + +User fonts +---------- +This new API allows the user of cairo API to provide drawings for +glyphs in a font. A common use for this is implementing fonts in +non-standard formats, like SVG fonts and Flash fonts. This API can +also be used by applications to provide custom glyph shapes for fonts +while still getting access to cairo's glyph caches. See +test/user-font.c and test/user-font-proxy.c for usage examples. This +is based on early work by Kristian Høgsberg. Thanks Kristian! + +This new API consists of the following functions (and corresponding +_get functions): + + cairo_user_font_face_create + + cairo_user_font_face_set_init_func + cairo_user_font_face_set_render_glyph_func + cairo_user_font_face_set_text_to_glyphs_func + cairo_user_font_face_set_unicode_to_glyph_func + +An additional, new API is + + cairo_scaled_font_text_to_glyphs + +We were previously reluctant to provide this function as +text-to-glyphs support in cairo was limited to "toy" font +functionality, not really interesting for real-world text +processing. However, with user fonts landing, this API is needed to +expose full access to how user fonts convert text to glyphs. This is +expected to be used by text toolkits like Pango, as well as "proxy" +user-font implementations. + +cairo_show_text_glyphs +---------------------- +This new API allows the caller of cairo to provide text data +corresponding to glyphs being drawn. The PDF backend implements this +new API so that complex text can be copied out of cairo's PDF output +correctly and reliably, (assuming the user of cairo calls +cairo_show_text_glyphs). The cairo_show_text_glyphs API is definitely +the most daunting API to debut in cairo. It is anticipated that pango +(and similar high-level text libraries) will be the primary users of +this API. In fact, pango 1.22 already uses cairo_show_text_glyphs. +Behdad was the architect and implementor of this effort. Thanks, +Behdad! + +The cairo_show_text_glyphs API includes the following new functions: + + cairo_show_text_glyphs + + cairo_glyph_allocate + cairo_glyph_free + + cairo_text_cluster_allocate + cairo_text_cluster_free + + cairo_surface_has_show_text_glyphs + +Build system revamp +------------------- +The primary goal of the revamp is to make the build system less +fragile, (particularly for non-Linux platforms). For example, now +people building on win32 will no longer need to maintain a +platform-specific list of files to be built. See the new README.win32 +for details. Also, the .so file will now be installed with a different +naming scheme, (for example, 1.7.6 will install with a .10800 +suffix). Many thanks to Behdad and his small army of helpers! + +Assorted API additions +---------------------- +For API completeness, several missing "getter" functions were added: + + cairo_scaled_font_get_scale_matrix + + cairo_surface_get_fallback_resolution + + cairo_toy_font_face_create + cairo_toy_font_face_get_family + cairo_toy_font_face_get_slant + cairo_toy_font_face_get_weight + +The new cairo_toy_font_face functions provide access to functionality +and settings provided by cairo_select_font_face(). Thanks Behdad! + +cairo-ps/cairo-pdf: More efficient output +----------------------------------------- +Adrian Johnson has been busy fixing all kinds of bugs in PS and PDF +backends, as well making them generate much more compact output by +avoiding things like re-emitting the color or linestyle on every +drawing operation. Thanks Adrian! + +cairo-xlib: dithering +--------------------- +Dithering: Cairo now does simple dithering when rendering to legacy X +servers. This is most visible with 8-bit visuals. Thanks Behdad! + +cairo-xlib: Avoid rendering glyphs out of surface bounds +-------------------------------------------------------- +This seemingly harmless optimization exposed a bug in OpenOffice.org 3 +versions where OO.o was passing bogus surface extents to cairo, +resulting in no text rendered in OO.o. Please contact your +distribution's OO.o maintainers if you see this bug and point them to +the following URL: + + https://bugs.freedesktop.org/show_bug.cgi?id=16209 + +cairo-xlib: Improved performance with X server without Render +------------------------------------------------------------- +Cairo now performs better on remote X servers that lack the Render +extension by being smarter about using X core protocol facilities +instead of falling back to doing all rendering on the client side. + +cairo-ft: respecting FC_FT_FACE +------------------------------- +Previously it was impossible to instruct cairo to do emboldening on a +font face object created from an FT_Face. Cairo now respects and uses +the FC_FT_FACE fontconfig pattern element, so emboldening can be +achieved by using cairo_ft_font_face_create_for_pattern() and a +carefully crafted pattern using FC_FT_FACE and FC_EMBOLDEN. Thanks +Behdad! + +cairo-directfb: backend improvements +------------------------------------ +The directfb backend, though still unsupported, has seen a good deal +of improvements. Thanks Vlad! + +Bug fixing and optimizations +---------------------------- +xlib: Faster bookkeeping (Karl Tomlinson) + https://bugzilla.mozilla.org/show_bug.cgi?id=453199#c5 + +PS: Fix gradients with non-constant alpha (Chris Wilson) + +Fix deadlock in user-font code (Richard Hughes and Behdad Esfahbod) + http://bugs.freedesktop.org/show_bug.cgi?id=16819 + +Countless other bugs have been fixed and optimizations made, many of +them thanks to Chris Wilson. Thanks Chris and others! + +Note also that the code that had been in cairo 1.7.x calling into +freetype's optional lcd_filter function was removed from cairo before +the 1.8.0 release. We do expect this code to come back in some form in +the future. + +Snapshot 1.7.6 (2008-09-17 Carl Worth ) +========================================================== +The cairo community is happy to announce the 1.7.6 snapshot of the +cairo graphics library. This is a "release candidate" for the upcoming +1.8.0 release, so we will greatly appreciate any reports of problems +in this release, and no major changes are currently planned before +1.8. + +Notable changes in 1.7.6 +------------------------ +The largest number of changes since 1.7.4 did not change the +implementation of cairo itself, but instead revamped cairo's build +system. The primary goal of the revamp is to make the build system +less fragile, (particularly for non-Linux platforms). For example, now +people building on win32 will no longer need to maintain a +platform-specific list of files to be built. Also, the .so file will +now be installed with a different naming scheme, (for example, 1.7.6 +will install with a .10706 suffix). Much thanks, Behdad! + +And, as usual, Chris Wilson has made another large round of robustness +improvements, (eliminating dead code, fixing propagation of error +status values, test suite improvements, etc. etc.). Thanks as always, +Chris! + +API changes since 1.7.4 +----------------------- +There have been a few changes of API that was new during the 1.7 +series: + +* Remove cairo_font_options_set_lcd_filter + and cairo_font_options_get_lcd_filter + + Motivation: At the Cairo Summit, this API was determined to be too + specific to the freetype font backend to be in the general + API. A similar API with a cairo_ft prefix might be introduced + in the future. Note that cairo will still respect the + corresponding fontconfig settings for these options. + +* Replace cairo_has_show_glyphs + with cairo_surface_has_show_glyphs + + Motivation: This really is a surface-specific interface, and the + convenience function on the cairo_t is not obviously + necessary. An application can easily call: + + cairo_surface_has_show_glyphs (cairo_get_target (cr)); + + as needed. + +* Add cairo_text_cluster_flags_t + to cairo_show_text_glyphs + cairo_scaled_font_text_to_glyphs + cairo_user_scaled_font_text_to_glyphs_func_t + + Motivation: This flag, (and specifically the + CAIRO_TEXT_CLUSTER_FLAG_BACKWARD value), replaces the + cairo_bool_t backward argument in each of the above + interfaces. This leads to more readable user code, and also + allows future extensibility. + +As always, there are no changes to any API from any major cairo +release, (1.0.x, 1.2.x, 1.4.x, 1.6.x). Cairo maintains the same +compatibility promise it always has. + +Bug fixes since 1.7.4 +--------------------- +xlib: Faster bookkeeping (Karl Tomlinson) + https://bugzilla.mozilla.org/show_bug.cgi?id=453199#c5 + +PS: Fix gradients with non-constant alpha (Chris Wilson) + +Fix deadlock in user-font code (Richard Hughes and Behdad Esfahbod) + http://bugs.freedesktop.org/show_bug.cgi?id=16819 + +Several other minor fixes. + +Snapshot 1.7.4 (2008-08-11 Behdad Esfahbod ) +=============================================================== +The cairo community is embarrassed to announce availability of the 1.7.4 +snapshot of the cairo graphics library. This is a followup release to the +1.7.2 snapshot to ship a tarball that can actually be built. The only +change since 1.7.4 is including the missing header file +cairo-user-font-private.h in the distribution. + +Snapshot 1.7.2 (2008-08-11 Behdad Esfahbod ) +=============================================================== +The cairo community is finally ready to announce availability of the 1.7.2 +snapshot of the cairo graphics library. This is embarrassingly the first +snapshot in the 1.7 unstable series of cairo, leading to the eventual release +of cairo 1.8, currently planned for late September. + +This snapshot comes four months after the 1.6.4 release. We have done a +really bad job on getting development snapshots out this cycle, but +hopefully all the API changes for 1.8 are now finished and the remaining +weeks will be spent on bug-fixing. There is more than 400 commits worth +of changes in this snapshot, and those can use some testing. Read on! + +Text, text, and more text! +-------------------------- +The dominant theme of this release, and 1.8 in general, is improvements +around cairo text API. Here is a high-level list of changes with text +handling: + +User fonts +---------- +This is new API allowing the user of cairo API to provide drawings for glyphs +in a font. This is most useful in implementing fonts in non-standard formats, +like SVG fonts and Flash fonts, but can also be used by games and other +applications to draw "funky" fonts. See test/user-font.c and +test/user-font-proxy.c for usage examples. This is based on early work by +Kristian Høgsberg. Thanks Kristian! + +show_text_glyphs +---------------- +This new API allows the caller of cairo to mark text glyphs with their +original text. The PDF backend implements this new API and latest Pango +master uses it. The result is (when bugs are fixed) that complex text can be +copied out of pangocairo's PDF output correctly and reliably. There are bugs +to fix though. A few poppler bugs, and some more in cairo and pango. + +To test show_text_glyph, just grab pango master and this cairo snapshot and +print text in gedit. Open in acroread or evince, select all, copy, paste +in gedit and compare. The Arabic text with diacritic marks is particularly +showing bad. Try with pango/pango-view/HELLO.txt if you are brave +enough. The Indic text is showing improvements, but is still coming out +buggy. + +LCD subpixel filtering using FreeType +------------------------------------- +FreeType 2.3.5 added support for various LCD subpixel filtering, and +fontconfig 2.6.0 added support for configuring LCD filter on a font by font +basis. Cairo now relies on FreeType and fontconfig for subpixel filtering. +This work is based on David Turner's original patch to cairo, maintained +and tested by Sylvain Pasche and others. Thanks all! + +Toy font face constructor and getter +------------------------------------ +Mostly for API completion, but also useful for higher level (like Pango) to +hook into what the user has set using cairo_select_font_face(), making that +toy API a bit more useful. + +FreeType: respecting FC_FT_FACE +------------------------------- +Previously it was impossible to instruct cairo to do emboldening on a font +face object created from an FT_Face. Cairo now respects and uses the +FC_FT_FACE fontconfig pattern element, so emboldening can be achieved by +using cairo_ft_font_face_create_for_pattern() and a carefully crafted pattern +using FC_FT_FACE and FC_EMBOLDEN. + + +PS/PDF: More efficient output +----------------------------- +Adrian Johnson has been busy fixing all kinds of bugs in PS and PDF +backends, as well making them generate much more compact output by avoiding +things like re-emitting the color or linestyle on every drawing operation. +Thanks Adrian! + + +Xlib: Dithering +--------------- +Cairo now does simple dithering when rendering to legacy X servers. This is +mostly visible with 8-bit visuals. + +Xlib: Avoid rendering glyphs out of surface bounds +-------------------------------------------------- +This seemingly harmless change manifested a bug with OpenOffice.org 3 versions +where OO.o was passing bogus surface extents to cairo, resulting in no text +rendered in OO.o. Please contact your distro's OO.o maintainers if you see +this bug and point them to the following URL: + + https://bugs.freedesktop.org/show_bug.cgi?id=16209 + +Xlib: Improved performance with Xrender-less X servers +------------------------------------------------------ +Cairo now performs better on remote, Xrender-less X servers by being smarter +about using X core protocol facilities instead of falling back to doing all +rendering on the client side. + + +Directfb: backend improvements +------------------------------ +The directfb backend, though still unsupported, has seen a good deal of +improvements. Thanks Vlad! + + +Bug fixing and optimizations +---------------------------- +Countless bugs have been fixed and optimizations made, many of them thanks to +Chris Wilson. Thanks Chris! + + +API additions +------------- + +cairo_show_text_glyphs + + This is a new text rendering API. Being a more advanced version of + cairo_show_glyphs(), it is aimed for use by higher-level text toolkits like + Pango, and enables better text extraction from output generated by backends + like PDF and SVG. The PDF backend already implements it, and the upcoming + Pango release will use it. + + To make that API work, a bunch of other additions were made: + +cairo_glyph_allocate +cairo_glyph_free +cairo_text_cluster_t +cairo_text_cluster_allocate +cairo_text_cluster_free +cairo_surface_has_show_text_glyphs + + +cairo_user_font_face_create + + This is the "user" font face constructor, accompanied by a variety of method + signatures, getters, and setters for a callback-based font backend: + +CAIRO_FONT_TYPE_USER +cairo_user_scaled_font_init_func_t +cairo_user_scaled_font_render_glyph_func_t +cairo_user_scaled_font_text_to_glyphs_func_t +cairo_user_scaled_font_unicode_to_glyph_func_t +cairo_user_font_face_set_init_func +cairo_user_font_face_set_render_glyph_func +cairo_user_font_face_set_text_to_glyphs_func +cairo_user_font_face_set_unicode_to_glyph_func +cairo_user_font_face_get_init_func +cairo_user_font_face_get_render_glyph_func +cairo_user_font_face_get_text_to_glyphs_func +cairo_user_font_face_get_unicode_to_glyph_func + + +cairo_scaled_font_text_to_glyphs + + We were previously reluctant to provide this function as text-to-glyphs + support in cairo was limited to "toy" font functionality, not really + interesting for real-world text processing. However, with user-fonts + landing, this API is needed to expose full access to how user-fonts + convert text to glyphs. This is expected to be used by text toolkits like + Pango, as well as "proxy" user-font implementations. + + +cairo_lcd_filter_t +cairo_font_options_set_lcd_filter +cairo_font_options_get_lcd_filter + + These add the possibility to choose between various available LCD subpixel + filters. The available filter values are modelled after what FreeType + provides. + + +cairo_toy_font_face_create +cairo_toy_font_face_get_family +cairo_toy_font_face_get_slant +cairo_toy_font_face_get_weight + + These provide access to functionality and settings provided by + cairo_select_font_face(). + + +cairo_scaled_font_get_scale_matrix +cairo_surface_get_fallback_resolution + + For API completeness. + + +Various new values for cairo_status_t enum + + +Known issues: + +- Type3 fonts generated by cairo's PDF backend may show up in poppler/Evince + in a different color than expected. This is fixed in poppler master branch. + This mostly affects cairo user fonts. The test case test/user-font.c + demonstrates this. + +- User fonts using other fonts in their rendering are currently embedded in + PDF as fallback bitmap glyphs. This will be (hopefully) fixed before 1.8. + The test case test/user-font-proxy.c demonstrates this. + + +Release 1.6.4 (2008-04-11 Carl Worth ) +========================================================= +The cairo community is wildly embarrassed to announce the 1.6.4 +release of the cairo graphics library. This release reverts the xlib +locking change introduced in 1.6.4, (and the application crashes that +it caused). The community would be glad to sack its current release +manager and is accepting applications for someone who could do the job +with more discipline. + +Revert 'add missing locking in cairo-xlib' +------------------------------------------ +This change was introduced in cairo 1.6.2, but also introduced a bug +which causes many cairo-xlib applications to crash, (with a +segmentation fault inside of XSetClipMask). Instead of attempting +another fix for the broken fix, the change in 1.6.2 has been +reverted. The original bug which the change was addressing has been +present since at least cairo 1.4, so it is not expected that leaving +this bug unfixed will cause any new problems for applications moving +from cairo 1.4 to cairo 1.6. + +At this point, the code of cairo 1.6.4 differs from cairo 1.6.0 only +in the fix for the PostScript-printer crashes. + +Tweak build to avoid linking with g++ +------------------------------------- +Cairo 1.6.4 avoids a quirk in automake that was causing the cairo +library to be linked with g++ and linked against libstdc++ even when +only C source files were compiled for the library. + +Release 1.6.2 (2008-04-11 Carl Worth ) +========================================================= +The cairo community is pleased (but somewhat sheepish) to announce the +1.6.2 release of the cairo graphics library. This is an update to +yesterday's 1.6.0 release with an important fix to prevent cairo's +PostScript output from crashing some printers. This release also +includes a locking fix for cairo's xlib backend to improve thread +safety. There are no changes beyond these two fixes. + +Fix for PostScript printer crash +-------------------------------- +Adrian Johnson discovered that cairo 1.6.0 was being a bit hard on +PostScript printers, by changing the font matrix very frequently. This +causes some PostScript interpreters to allocate new font objects every +few glyphs, eventually exhausting available resources. The fix +involves leaving translational components of the font matrix as zero, +so that the PostScript interpreter sees an identical font matrix +repeatedly, and can more easily share internal font object resources. + +This fix has been tested to resolve the bugs posted here, (for both +Xerox and Dell printers): + + Printing some PDFs from evince is crashing our Xerox printer + http://bugs.freedesktop.org/show_bug.cgi?id=15348 + + Cairo-generated postscript blocks Dell 5100cn + http://bugs.freedesktop.org/show_bug.cgi?id=15445 + +Add missing locking in cairo-xlib +--------------------------------- +Chris Wilson noticed that cairo 1.6.0 was manipulating an internal +cache of GC object within cairo's Xlib backend without proper +locking. The missing locking could cause failures for multi-threaded +applications. He fixed this in 1.6.2 by adding the missing locks. + +Release 1.6.0 (2008-04-10 Carl Worth ) +========================================================= +The cairo community is quite pleased to announce the 1.6.0 release of +the cairo graphics library. This is a major update to cairo, with new +features and enhanced functionality which maintains compatibility for +applications written using cairo 1.4, 1.2, or 1.0. We recommend that +anybody using a previous version of cairo upgrade to cairo 1.6.0. + +The most significant new features in this release are dramatically +improved PDF and PostScript[*] output, support for arbitrary X server +visuals (including PseudoColor), a new Quartz backend, and and a new +"win32 printing" backend. See below for more details on these and +other new features. + +New dependency on external pixman library (Thanks, Søren!) +---------------------------------------------------------- +As of cairo 1.6, cairo now depends on the pixman library, for which +the latest release can be obtained alongside cairo: + + http://cairographics.org/releases/pixman-0.10.0.tar.gz + +This library provides all software rendering for cairo, (the +implementation of the image backend as well as any image fallbacks +required for other backends). This is the same code that was +previously included as part of cairo itself, but is now an external +library so that it can be shared by both cairo and by the X server, +(which is where the code originated). + +Improved PDF, PostScript, and SVG output (Thanks, Adrian!) +---------------------------------------------------------- +Users of the cairo-pdf, cairo-ps, and cairo-svg should see a dramatic +improvement from cairo 1.2/1.4 to 1.6. With this release there are now +almost no operations that will result in unnecessary rasterization in +the PDF and PostScript. Rasterized "image fallbacks" are restricted +only to minimal portions of the document where something is being +drawn with cairo that is beyond the native capabilities of the +document, (this is rare for PDF or SVG, but occurs when blending +translucent objects for PostScript). + +This means that the final output will be of higher quality, and will +also be much smaller, and therefore will print more quickly. The +machinery for doing analysis and minimal fallbacks also benefits the +win32-printing surface described below. + +In addition to doing less rasterization, the PostScript and PDF output +also has several other improvements to make the output more efficient +and more compatible with specifications. + +[*] Note: Just before this release, a bug has been reported that the +PostScript output from cairo can crash some printers, (so far the +following models have been reported as problematic Xerox Workcentre +7228 or 7328 and Dell 5100cn). We will implement a workaround as soon +as we can learn exactly what in cairo's output these printers object +to, (and we could use help from users that have access to misbehaving +printers). This bug is being tracked here: + + Printing some PDFs from evince is crashing our Xerox printer + http://bugs.freedesktop.org/show_bug.cgi?id=15348 + +New support for arbitrary X server visuals (Thanks, Keith and Behdad!) +---------------------------------------------------------------------- +As of cairo 1.6, cairo should now work with an arbitrary TrueColor or +8-bit PseudoColor X server visual. Previous versions of cairo did not +support these X servers and refused to draw anything. We're pleased to +announce that this limitation has been lifted and people stuck with +ancient display systems need no longer be stuck with ancient software +just because of cairo. + +New, supported Quartz backend for Mac OS X (Thanks, Brian and Vladimir!) +------------------------------------------------------------------------ +As of cairo 1.6, the cairo-quartz backend is now marked as "supported" +rather than "experimental" as in previous cairo releases. Its API now +has guarantees of API stability into future cairo releases, and its +output quality is comparable to other backends. There have been +significant improvements to cairo-quartz since 1.4. It now uses many +fewer image fallbacks, (meaning better performance), and has greatly +improved text rendering. + +New, "win32 printing" backend (Thanks, Adrian and Vladimir!) +------------------------------------------------------------ +A new win32-printing surface has been added with an interface very +similar to the original win32 surface, (both accept an HDC +parameter). But this new surface should only be called with a printing +DC, and will result in all drawing commands being stored into a +meta-surface and emitted after each page is complete. This allows +cairo to analyze the contents, (as it does with PDF, PostScript, and +SVG backends), and to do minimal image-based fallbacks as +necessary. The analysis keeps things as efficient as possible, while +the presence of fallbacks, (when necessary), ensure the consistent, +high-quality output expected from cairo. + +Robustness fixes (Thanks, Chris!) +--------------------------------- +There has been a tremendous number of improvements to cairo's +robustness. Areas that have been improved include: + + * Proper reporting of errors + + * Responding correctly to invalid input + + * Avoiding integer overflows + + * Avoiding memory leaks on error-recovery paths + + * Making reference counting thread safe + + * Exhaustive testing of memory allocation points + +Other fixes (Thanks, everybody!) +-------------------------------- +Cairo's internal fixed-point representation has been changed from +16.16 to 24.8. This has a direct impact on applications as it allows +much larger objects to be drawn before internal limits in cairo make +the drawing not work. + +The CAIRO_EXTEND_PAD mode is now fully supported by surface +patterns. This mode allows applications to use cairo_rectangle and +cairo_fill to draw scaled images with high-quality bilinear filtering +for the internal of the image, but without any objectionably blurry +edges, (as would happen with the default EXTEND_NONE and cairo_paint). + +Rendering with CAIRO_ANTIALIAS_NONE has been fixed to be more +predictable, (previously image rendering and geometry rendering would +be slightly misaligned with respect to each other). + +The reference manual at http://cairographics.org/manual now documents +100% of the functions and types in cairo's public API. + +API additions +------------- +Several small features have been added to cairo with new API functions: + +cairo_format_stride_for_width + + Must be called to compute a properly aligned stride value before + calling cairo_image_surface_create_for_data. + +cairo_has_current_point + + Allows querying if there is a current point defined for the + current path. + +cairo_path_extents + + Allows querying for path extents, (independent of any fill or + stroke parameters). + +cairo_surface_copy_page +cairo_surface_show_page + + Allow beginning a new document page without requiring a cairo_t + object. + +cairo_ps_surface_restrict_to_level +cairo_ps_get_levels +cairo_ps_level_to_string +cairo_ps_surface_set_eps + + Allow controlling the Post PostScript level, (2 or 3), to + target, as well as to generate Encapsulated PostScript (EPS). + +cairo_quartz_font_face_create_for_cgfont + + Create a quartz-specific cairo_font_face_t from a CGFontRef. + +cairo_win32_font_face_create_for_logfontw_hfont + + Create a win32-specific cairo_font_face from a LOGFONTW and an + HFONT together. + +Thanks, Everyone! +----------------- +I've accounted for 32 distinct people with attributed code added to +cairo between 1.4.14 and 1.6.0, (their names are below). That's an +impressive number, but there are certainly dozens more that +contributed with testing, suggestions, clarifying questions, and +encouragement. I'm grateful for the friendships that have developed as +we have worked on cairo together. Thanks to everyone for making this +all so much fun! + +Adrian Johnson, Alp Toker, Antoine Azar, Behdad Esfahbod, +Benjamin Otte, Bernardo Innocenti, Bertram Felgenhauer, +Boying Lu, Brian Ewins, Carl Worth, Chris Heath, Chris Wilson, +Claudio Ciccani, Emmanuel Pacaud, Jeff Muizelaar, Jeremy Huddleston, +Jim Meyering, Jinghua Luo, Jody Goldberg, Jonathan Gramain, +Keith Packard, Ken Herron, Kouhei Sutou, Kristian Høgsberg, +Larry Ewing, Martin Ejdestig, Nis Martensen, Peter Weilbacher, +Richard Hult, Shailendra Jain, Søren Sandmann Pedersen, +Vladimir Vukicevic + +Snapshot 1.5.20 (2008-04-04 Carl Worth ) +=========================================================== +This is the tenth snapshot in cairo's unstable 1.5 series. It comes +just two days (and only one working day) after the 1.5.18 +snapshot. The quick snapshot is due to two embarrassing bugs (both +affecting cairo-xlib) that had been introduced in the 1.5.18 +snapshot. The fixes for these are described below along with a few +other fixes, (which hopefully aren't introducing new bugs this time). + +cairo-xlib +---------- +Revert fix from 1.5.18 to allow pattern expansion based on the filter +mode. This fix seemed so boring, (the use case it addresses is almost +never used in practice), that it didn't even get mentioned in the +1.5.18 release notes. However, the "fix" happened to break rendering +that is always used resulting in corrupt image rendering in mozilla, +evolution, and probably everything else that uses cairo. + +Fix to avoid BadMatch errors in cairo_surface_create_similar. These +were introduced, (inadvertently, of course), as part of the fix in +1.5.18 for creating similar surfaces without the Render +extension. Again, thanks to mozilla, (and Vladimir Vukicevic in +particular), for noticing our mistake. + +general +------- +Correctly handle an in-error surface in +cairo_surface_write_to_png. Previously this function would cause an +assertion failure if you gave it a finished surface. Now it cleanly +returns a CAIRO_STATUS_SURFACE_FINISHED result instead. + +Avoid potentially infinite wandering through memory inside +_cairo_hull_prev_valid. Thanks to Jonathan Watt for noticing this +problem: + + https://bugzilla.mozilla.org/show_bug.cgi?id=306649#c21 + +cairo-pdf +--------- +Fix generation of "soft" masks made by drawing to a similar surface +and then calling cairo_mask_surface() with it. + +cairo-svg +--------- +Fix for code that uses cairo_mask() on an intermediate surface which +is later passed to cairo_mask_surface(). + +Snapshot 1.5.18 (2008-04-05 Carl Worth ) +=========================================================== +This is the ninth snapshot in cairo's unstable 1.5 series. It comes +just 4 days after the 1.5.16 snapshot. We had hoped to not need +another snapshot before the final 1.6.0 release, but several critical +bugs were found and fixed in the last few days, so we thought it +important to let people test the fixes with this snapshot. See below +for details. + +documentation +------------- +The README now lists necessary dependencies. + +Various graphics state defaults are now documented, (source pattern is +opaque black, line width is 2.0, line join is miter, line cap is butt, +miter limit is 10.0, etc.). + +general +------- +Several cleanups have been made along many error-path returns, +(carefully propagating up the original error status values, cleaning +up memory leaks during error recovery, etc.). This is yet another in +Chris "ickle" Wilson's long series of error-handling cleanups during +the 1.5 series. + +Avoid undesired clipping when drawing scaled surface patterns with +bilinear filtering. + +cairo-pdf +--------- +Fix emission of 1-bit alpha masks in PDF output. + +Fix a bug that would cause glyphs to be misplaced along the Y axis: + + http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%23474136 + + Originally, an issue about a crash, but later leading to the + misplaced glyphs issue being discovered. + +cairo-ps +-------- +Fix misplaced glyphs in cairo's PostScript output. + + This issue occurs when consecutive glyphs are placed far + apart. This case is exercised by the new ft-show-glyphs-table test + case, which was originally inspired by the Debian bug #23474136 + mentioned above. + +Fix more misplaced glyphs in cairo's PostScript output: + + The issue here showed up under very particular circumstance, (when + converting a PDF file with a CFF font with CID Identity-H encoding + and using glyph 0, (defined by the CFF specification as .notdef) + as a space instead). More concretely, this problem appeared when + converting the UbuntuDesktop.pdf file mentioned in this bug + report: + + https://bugs.freedesktop.org/show_bug.cgi?id=15348#c3 + + As usual with arcane font-encoding-specific bugs like this, many + thanks to Adrian Johnson for his magical ability to dive into + specifications and emerge almost instantaneously with fixes. And + thanks to Sebastien Bacher for bringing the bug to our attention. + +cairo-xlib +---------- +Fix serious failure on X servers without the Render extension. + + Since the 1.5.14 snapshot (with support for PseudoColor visuals), + any application attempting to create a "similar" xlib surface would + fail on an X server without the Render extension. Thanks to + Frederic Crozat for pointing out that cairo's test suite was + entirely failing when run against Xvfb. + +Avoid crashing cairo-xlib applications for too-large glyphs + + Naively sending glyphs of any size to the X server will eventually + violate the X limit on maximum request sizes. We now properly + detect when a glyph would be too large and use existing fallbacks + to render the glyph rather than trying to send it to the X server. + +Enable the buggy_repeat workaround for Xorg servers < 1.4 + + We have determined that Xorg 1.3.0 (as packaged in Fedora 8 at + least) has a bug that can result in an X server crash when cairo + uses certain X Render repeat operations, (as exercised by cairo's + extend-reflect test). We avoid this crash by using fallbacks + whenever a repeating surface is needed for any Xorg server with a + version less than 1.4. This is slower, but should prevent the + crash. + + (Meanwhile, there appears to be a separate bug where some X + servers or specific X-server drivers will use random pixmap data + when asked to draw a repeating surface. The buggy_repeat + workaround would also avoid those problems, but we have not yet + characterized whether the new "version < 1.4" is a good + characterization of those problems or not.) + +cairo-quartz-font +----------------- +Implement cairo_font_extents for this backend. + +The cairo-quartz-font implementation added in the 1.5.14 snapshot was +entirely missing support for the cairo_font_extents function. Thanks to +Richard Hult for pointing out this obvious shortcoming, (and obvious +lack of coverage in our test suite): + + CGFont backend returns 0 font extents + https://bugs.freedesktop.org/show_bug.cgi?id=15319 + +Snapshot 1.5.16 (2008-04-01 Carl Worth ) +=========================================================== +This is the eighth snapshot in cairo's unstable 1.5 series. It comes +less than two weeks after the 1.5.14 snapshot and it really is a +legitimate snapshot, (in spite of sharing this date with that of many +bogus announcements). The major change in this snapshot is that the +cairo-quartz backend is now officially "supported", including new API +to construct a font face from a CGFontRef . Also several bug fixes +have been fixed in many backends. See below for details. + +general +------- +Cairo now depends on pixman 0.10.0 which was recently released. The +latest pixman release can always be found alongside cairo releases at: + + http://cairographics.org/releases + +Increase the precision of color stops for gradients. This fixes a +regression in gradient rendering that had been present since the +1.5.12 snapshot. + +paginated (all of ps, pdf, svg, and win32-printing) +--------------------------------------------------- +Fix assertion failure when some drawing elements are outside the page +boundaries, (this bug was noticed when using Inkscape to print a +drawing with landscape orientation to a portrait-oriented piece of +paper). + +cairo-ps +-------- +Fix of bug causing incorrect glyph positioning. + +Fix handling of CAIRO_OPERATOR_SOURCE. + +cairo-pdf +--------- +More reduction of unnecessary digits of precision in PDF output. + +Fix handling of CAIRO_OPERATOR_SOURCE. + +cairo-svg +--------- +Fix bug in usage of libpng that was preventing cairo_mask from working +with the svg backend. + +Fix transformation of source pattern for cairo_stroke(). + +cairo-win32-printing +-------------------- +Fix fallback resolution, (thanks again to inkscape users/developers +for helping us find this one). + +cairo-quartz +------------ +Mark the cairo-quartz backend as "supported" rather than +"experimental". This means the following: + + * The backend will now be built by default (if possible). + + * We are committing that the backend-specific API (as published in + cairo-quartz.h) are stable and will be supported in all future + cairo 1.x releases. + + * We are committing that the output quality of this backend + compares favorably with other cairo backends, (and that quality + is ensured by good results from the cairo test suite). + + * We recommend that distributions build and distribute this + backend when possible. + +Note that the cairo_quartz_image API (in cairo-quartz-image.h) is +still experimental, will not build by default, (pass +--enable-quartz-image to configure to build it), and may see API +changes before it is marked as "supported" in a future release. + +Put the CAIRO_FONT_TYPE_ATSUI name back into +cairo-deprecated.h. Without this, the cairo 1.5.14 snapshot broke all +builds for applications using the C++ cairomm bindings (and perhaps +others) which have the CAIRO_FONT_TYPE_ATSUI name in their header +files. This breakage happened even for applications not using +cairo-quartz at all. + + Note: Even though the CAIRO_FONT_TYPE_ATSUI name is provided to + avoid this build breakage, we still recommend that bindings and + applications move to the new, and more accurate, + CAIRO_FONT_TYPE_QUARTZ name. + +Replace the implementation of cairo-quartz-font to use CFFont instead +of ATSUI. The CGFont API is a better fit than ATSUI, and this new +implementation is also more correct than the old one as well. + +This also adds the following new API call: + + cairo_public cairo_font_face_t * + cairo_quartz_font_face_create_for_cgfont (CGFontRef font); + +The previous cairo_quartz_font_face_create_for_atsu_font_id function +continues to exist and is part of the supported API going +forward. (However, the old name of that same function, which was +cairo_atsui_font_face_create_for_atsu_font_id is officially +deprecated. Any source code using the old name should be updated to +use the new name.) + +Fix transformation of source pattern for cairo_stroke(). + +cairo-win32 +----------- +Avoid crash in create_similar is cairo_win32_surface_create fails. + +Snapshot 1.5.14 (2008-03-20 Carl Worth ) +=========================================================== +This is the seventh snapshot in cairo's unstable 1.5 series. It comes +3 weeks after the 1.5.12 snapshot. This snapshot includes support for +arbitrary X server visuals, (including PseudoColor), which was the +final remaining cairo-specific item on the cairo 1.6 roadmap. It also +includes a huge number of improvements to the cairo-quartz backend. So +this is effectively a cairo 1.6 release candidate. We expect very few +changes from now until 1.6 and only for specific bug fixes. + +API Change +---------- +Rename ATSUI font backend to Quartz font backend. This affects the +following usage: + + --enable-atsui -> --enable-quartz-font + CAIRO_HAS_ATSUI_FONT -> CAIRO_HAS_QUARTZ_FONT + CAIRO_FONT_TYPE_ATSUI -> CAIRO_FONT_TYPE_QUARTZ + + cairo_atsui_font_face_create_for_atsu_font_id -> + cairo_quartz_font_font_create_for_atsu_font_id + +This API change is justified by the cairo-quartz backend still be +marked as "experimental" rather than "supported", (though this is one +step toward making the change to "supported" before 1.6). Cairo will +still provide ABI compatibility with the old symbol name, however. + +paginated (all of ps, pdf, svg, and win32-printing) +--------------------------------------------------- +Optimize by not analyzing an image surface for transparency more than +once, (previously all images were analyzed twice). + +cairo-ps and cairo-pdf +---------------------- +Avoiding emitting a matrix into the stroke output when unnecessary, +(making output size more efficient). + +Reduce rounding error of path shapes by factoring large scale factors +out of the path matrix, (ensuring that a fixed-number of printed +digits for path coordinates contains as much information as possible). + +Reduce excess digits for text position coordinates. This makes the +output file size much smaller without making the result any less +correct. + +cairo-ps +-------- +Eliminate bug causing extraneous text repetition on Linux PostScript +output in some cases. + + See: Mozilla Bug 419917 – Printed page contents are reflected + inside bordered tables (Linux-only) + + https://bugzilla.mozilla.org/show_bug.cgi?id=419917 + +Optimize output when EXTEND_PAD is used. + +cairo-pdf +--------- +Fix to not use fill-stroke operator with transparent fill, (else PDF +output doesn't match the cairo-defined correct result). See: + + https://bugs.launchpad.net/inkscape/+bug/202096 + +cairo-svg +--------- +Fix stroke of path with a non-solid-color source pattern: + + http://bugs.freedesktop.org/show_bug.cgi?id=14556 + +cairo-quartz +------------ +Fix text rendering with gradient or image source pattern. + +Handling antialiasing correctly for cairo_stroke(), cairo_clip(), and +cairo_show_text()/cairo_show_glyphs(). + +Correctly handle gradients with non-identity transformations: + + Fixes http://bugs.freedesktop.org/show_bug.cgi?id=14248 + +Add native implementation of REPEAT and REFLECT extend modes for +gradients. + +Fix implementation for the "unbounded" operators, (CAIRO_OPERATOR_OUT, +_IN, _DEST_IN, and _DEST_ATOP). + +Correctly handle endiannees in multi-architecture compiles on Mac OS +X. + +Avoid behavior which would cause Core Graphics to print warnings to +the console in some cases. + +cairo-win32 +----------- +Fix handling of miter limit. + +cairo-win32-printing +-------------------- +Fix to not use a 1bpp temporary surface in some cases while printing, +(so grayscale data is preserved rather than just becoming black and +white). + +cairo-xlib +---------- +Add support for rendering to arbitrary TrueColor X server +visuals. This fixes at least the following bugs: + + cairo doesn't support 8-bit truecolor visuals + https://bugs.freedesktop.org/show_bug.cgi?id=7735 + + cairo doesn't support 655 xlib format + https://bugs.freedesktop.org/show_bug.cgi?id=9719 + +Add support for rendering to 8-bit PseudoColor X server visuals. This +fixes the following bug: + + Cairo doesn't support 8-bit pseudocolor visuals + https://bugs.freedesktop.org/show_bug.cgi?id=4945 + +Snapshot 1.5.12 (2008-02-28 Carl Worth ) +=========================================================== +This is the sixth snapshot in cairo's unstable 1.5 series. It comes 1 +week after the 1.5.10 snapshot. This snapshot includes the +long-awaited change from 16.16 to 24.8 fixed-point values, (see below +for why you should care). It also includes several backend-specific +bug fixes. + +24.8 fixed-point format +----------------------- +Cairo has always converted path coordinates to a fixed-point +representation very early in its processing. Historically, this has +been a 32-bit representation with 16 bits of integer for the +device-pixel grid and 16 bits of sub-pixel positioning. The choice of +16 bits for the integer coordinate space was based on the 16-bit limit +for X Window drawables. + +This 16-bit limit has proven problematic for many applications. It's +an especially vexing problem when targeting non-X backends that don't +have any 16-bit restriction. But even when targeting cairo-xlib, it's +often desirable to draw a large shape, (say a background rectangle), +that extends beyond the surface bounds and expect it to fill the +surface completely, (rather than overflowing and triggering random +behavior). + +Meanwhile, nobody has ever really needed 16 bits of sub-pixel +precision. + +With this snapshot, the fixed-point system is still in place and is +still using a 32-bit representation, (future versions of cairo might +move entirely to floating-point when targeting PDF output for +example). But the representation now provides 24 bits of pixel +addressing and only 8 bits of sub-pixel positioning. This should give +a much less stifling space to many applications. + +However, the underlying pixman library still has 16-bit limitations in +many places, (it has its roots in the X server as well). Until those +are also fixed, applications targeting cairo image surfaces, or +hitting software fallbacks when targeting other surfaces will still +encounter problems with device-space values needing more than 16 +integer bits. + +generic fixes +------------- +Add a few tests to the test suite to increase coverage. + +Cleanup a few error-handling paths, (propagate error correctly). + +cairo-ft +-------- +Fix handling of font sizes smaller than 1 device pixel. + +cairo-pdf +--------- +Fix to properly save/restore clip when analyzing meta-surface +patterns, (fixing a couple of test-suite failures). + +Implement native support for CAIRO_OPERATOR_SOURCE when the source +pattern is opaque. + +Emit rectangles as PDF rectangles ("re" operator) rather than as +general paths. + +cairo-ps +-------- +Fix to work properly with the 16.16->24.8 change. + +cairo-svg +--------- +Fix CAIRO_EXTEND_REFLECT by using an image fallback, (there's no +direct SVG support for reflected patterns). + +Fix the use of alpha-only masks, (such as CAIRO_FORMAT_A8). + +cairo-quartz +------------ +Add new API for efficiently using image data as a source: + + cairo_surface_t * + cairo_quartz_image_surface_create (cairo_surface_t *image_surface); + + cairo_surface_t * + cairo_quartz_image_surface_get_image (cairo_surface_t *surface); + +For full documentation, see: + + http://cairographics.org/manual/cairo-Quartz-Surfaces.html#cairo-quartz-image-surface-create + +Several fixes for cairo_mask(). + +cairo-atsui +----------- +Change default from from Monaco to Helvetica to be more consistent +with other font backends. + +Snapshot 1.5.10 (2008-02-20 Carl Worth ) +=========================================================== +This is the fifth snapshot in cairo's unstable 1.5 series. It comes 3 +weeks after the 1.5.8 snapshot. This snapshot adds one new API +function, (cairo_has_current_point), and the usual mix of +improvements, (more efficient PostScript/PDF output, optimized +stroking), and fixes (more robust error-handling, etc.). See below for +details. + +New API +------- +Add a new function to query if there is a current point: + + cairo_bool_t + cairo_has_current_point (cairo_t *cr); + +There is no current point immediately after cairo_create(), nor after +cairo_new_path() or cairo_new_sub_path(). There is a current point +after any of the path-creation functions, (cairo_move_to, +cairo_line_to, cairo_curve_to, etc.). + +With this new function, we also revert the change of the return type +of cairo_get_current_point from cairo 1.5.8, (it's now a void function +again). + +Optimizations +------------- +Optimize stroking code to avoid repeated calculation of redundant +values, (particularly significant for very large, offscreen paths). + +General fixes +------------- +Patch a few more potential buffer overruns, (due to integer +overflow). + +Many fixes and improvements to cairo's error-handling, (ensure that +correct error values are returned, clean up memory leaks on +error-handling paths, etc.). + +Fix a potential infinite loop when stroking a spline with a pen that +has been transformed to a line segment. + +Remove treating NULL as a synonym for a valid cairo_font_options_t* +with default values, (a change that had been introduced as of cairo +1.5.8). + +Remove the altered handling of tolerance and fallback-resolution that +had been introduced as of cairo 1.5.4. + +cairo-xlib +---------- +Pass the original Drawable, (as opposed to the root window), to +XCreatePixmap when creating a similar surface. This gives the X server +more information so that it can be clever and efficient. + +cairo-pdf +--------- +Fix the rendering of repeating and reflecting patterns. + +Ensure miter limit is always >= 1, (smaller limits are not meaningful, +but they can cause some PDF viewers to fail to display pages). + +Generate more efficient output when the same path is used for both +fill and stroke. + +cairo-ps +-------- +Start sharing much of the cairo-pdf code rather than implementing very +similar code in cairo-ps. + +Implement native support for repeating and reflecting linear +gradients. + +Implement reflected surface patterns. + +Ensure miter limit is always >= 1, (smaller limits are not meaningful, +but they can cause some PostScript viewers to crash). + +Generate PostScript that will perform more efficiently and use less +memory on printers, (use currentfile instead of a giant string array +for image data, and avoid using PostScript patterns for paint() and +fill() when possible). + +cairo-svg +--------- +Avoid unnecessary rasterization when copying a "similar" surface to +another svg surface, (allow the SOURCE operator to be implemented with +all-vector operations if there are no underlying objects). + +cairo-atsui +----------- +Eliminate infinite loop when attempting to render an empty string. + +Snapshot 1.5.8 (2008-01-30 Carl Worth ) +========================================================== +This is the fourth snapshot in cairo's unstable 1.5 series. It comes 2 +weeks after the 1.5.6 snapshot. It adds a few new API functions. Most +notably all callers of cairo_image_surface_create_for_data should now +be calling cairo_format_stride_for_width to compute a legal stride +value. See below for more details. + +New API in cairo 1.5.8 +---------------------- +We've added a new function that should be called to compute a legal +stride value before allocating data to be used with +cairo_image_surface_create_for_data: + + int + cairo_format_stride_for_width (cairo_format_t format, + int width); + +We've also added a new cairo_path_extents function that can be used to +compute a bounding box for geometry such as a single line segment, +(contrast with cairo_path_extents and cairo_stroke_extents): + + void + cairo_path_extents (cairo_t *cr, + double *x1, double *y1, + double *x2, double *y2); + +And finally, we've added a function to allow for querying the +XRenderPictFormat of a cairo-xlib surface: + + XRenderPictFormat * + cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface); + +API changes +----------- +Fix return types of cairo_surface_show_page and +cairo_surface_copy_page. This is an API change to functions that are +new in the 1.5 series, so not an API break compared to any stable +cairo release, (1.0.x, 1.2.x, 1.4.x). + +Change the return type of cairo_get_current_point() from void to +cairo_status_t. This allows the caller to receive a +CAIRO_STATUS_NO_CURRENT_POINT value to distinguish the a current point +at the origin from no current point existing. + +Performance improvement +----------------------- +Improve performance of clipping by using an optimized code path +internally, (with the ADD operator instead of IN). + +General bug fixes +----------------- +Fix various cairo_*_extents functions to initialize the return-value +variables even in the case of a cairo_t in error. + +Treat NULL as a legitimate value for cairo_font_options_t*. [NOTE: +On discussion afterwards, we decided against this change so it has +been removed as of cairo 1.5.10.] + +Fix rendering with CAIRO_ANTIALIAS_NONE to be more predictable, (that +is, to avoid seams appearing when geometry and imagery share an +identical edge). Portions of this fix are in the pixman library and +will appear in a future release of that library. + +Avoid triggering an error for a font size of 0. + +Miscellaneous changes +--------------------- +Require pixman >= 0.9.6. + +There has been a tremendous amount improvement to cairo's +documentation. We're delighted that 100% of the public API has at +least some documentation in the API reference manual. Many thanks to +Behdad Esfahbod and Nis Martensen for leading this effort. + +cairo-pdf and cairo-ps +---------------------- +Eliminate failure when a Type 1 font is embedded with an explicit +glyph 0. + +cairo-pdf +--------- +Implement a more correct and more efficient approach for patterns with +an extend mode of CAIRO_EXTEND_REFLECT. + +cairo-ps +-------- +Fix image masks to properly pack and pad mask bits. + +cairo-quartz +------------ +Take care to only use DrawTiledImage for integer-aligned images, (and +use slower paths to get the correct result in other cases). + +cairo-win32 +----------- +Fix for older versions of mingw. + +Improve the handling of the clipping with the win32 and win32-printing +surfaces. + +Fix rendering of non black/white text. + +Snapshot 1.5.6 (2008-01-15 Carl Worth ) +========================================================== +This is the third snapshot in cairo's unstable 1.5 series. It comes +about 6 weeks after the 1.5.4 snapshot. The only API addition compared +to 1.5.4 is very minor, (a new value CAIRO_STATUS_TEMP_FILE_ERROR). +The remainder of the changes are the usual accumulation of bug fixes +and improvements. See below for details. + +General bug fixes +----------------- +Fix handling of fonts that contain a mixture of outline and bitmapped +glyphs. There was a change in this handling in 1.5.4 that improved +some cases and also regressed other cases. Now, all cases should be +handled quite well. + +Fix alignment issues that were causing SIGBUS failures on SPARC. + +Fix a regression (which first appeared in 1.5.2) where stroking under +a large scale would sometimes incorrectly replace a miter join with a +bevel join. (Thanks to Keith Packard.) + +Fix reporting of zero-sized extents to be {0,0} rather than +{INT_MAX,INT_MIN}. This avoids several integer overflow and +allocations of massive regions in some cases. + +Fix failures of gradients with no stops, (quartz, ps, and pdf). + +Fix handling of Type 1 fonts on Windows platforms. + +Fix handling of Type 1 fonts with no specific family name in the font +itself, (generate a CairoFont-x-y name). + +Handle NULL string values in cairo_show_text, cairo_show_glyphs, and +friends. + +Many robustness improvements along error-handling paths, (thanks as +always, to Chris "ickle" Wilson). + +Various other minor fixes. + +Paginated backends (PDF/PostScript/win32-printing) +-------------------------------------------------- +Avoid unnecessary rasterization when using a paginated surface as a +source, (such as drawing from one pdf surface to another). + +Fix replaying of paginated surface with more than one level of push/pop +group. + +cairo-xlib +---------- +Fix xlib backend to not consider recent X server release as having a +buggy repeat implementation in the Render extension. + +cairo-pdf +--------- +Fix PDF output to avoid triggering very slow rendering in PDF viewers, +(avoid starting and stopping the content stream for each pattern +emission). + +Support CAIRO_OPERATOR_SOURCE in cases where there is nothing below +the object being drawn. + +Fix to avoid seams appearing between multiple fallback regions. + +cairo-ps (PostScript) +--------------------- +Use correct bounding box in Type 3 fonts. + +Fix several bugs in cairo's PostScript output. These include making +the PostScript output more compatible with recent versions of +ghostscript that are more strict about Type 3 fonts, for +example. + +Fix for win32 to not attempt to create temporary files in the root +directory, (where the user may not have write permission). + +Avoid generating Level 3 PostScript if Level 2 is sufficient. Also, +add code in output documents to alert the user if Level 3 PostScript +is handed to a device that cannot handle PostScript beyond Level +2. + +cairo-directfb +-------------- +Various performance optimizations. + +Fixed support for small surfaces (less than 8x8). + +Provide support for environment variables CAIRO_DIRECTFB_NO_ACCEL to +disable acceleration and CAIRO_DIRECTFB_ARGB_FONT to enable ARGB fonts +instead of A8. + +cairo-os2 +--------- +Allow OS/2 APIs instead of C library allocation functions. + +Snapshot 1.5.4 (2007-12-05 Carl Worth ) +========================================================== +This is the second snapshot in cairo's unstable 1.5 series. It comes +just over 1 month after the 1.5.2 snapshot. There are no API changes +or additions in 1.5.4 compared to 1.5.2, but there are several bug +fixes, and some optimizations. Most of these apply to particular +backends. See below for details. + +General improvements +-------------------- +Use less memory for spline approximation calculations. + +Change how the tolerance value is interpreted with regard to +fallback-resolution. [Note: On further discussion, we decided against +this change for now. It is removed as of cairo 1.5.10.] + +Fix precision of floating-point values in vector-output backends to +avoid rounding errors with very small numbers. + +Xlib improvements +----------------- +Fix bug in glyph rendering with xlib, (due to everything being clipped +out). This was a regression in the 1.5.2 snapshot that was visible in +the GIMP, for example. See: + + cairo 1.5.2 causes font problems in GIMP 2.4 status bar and evolution 2.12.1 + https://bugs.freedesktop.org/show_bug.cgi?id=13084 + +PostScript improvements +----------------------- +Fix bug leading to invalid PostScript files when rendering +text, (need "0 0 xyshow" instead of "0 xyshow"). + +Fix many issues with Type 3 fonts, including making the resulting text +extractable. + +Quartz improvements +------------------- +Fix font metrics height value for ATSUI, (helps webkit on GTK+ OS X +layout nicely). + +Fix gradients. + +Fix EXTEND_NONE mode for patterns. + +Fix cairo_quartz_surface_create to properly clear the new surface +in cairo_quartz_surface_create. + +Fix to correctly handle 0x0 sized surfaces. + +Optimize drawing of EXTEND_REPEAT patterns for OS X 10.5. + +Snapshot 1.5.2 (2007-10-30 Carl Worth ) +========================================================== +This is the first snapshot in cairo's unstable 1.5 series. It comes 4 +months after the 1.4.10 release. This snapshot includes significant +improvements to PDF and PostScript output, which is one of the things +in which we're most interested in getting feedback. There are a couple +of minor API additions, and several optimizations, (primarily in the +"print/vector" backends). And there are dozens of bug fixes and +robustness improvements. + +New dependency on external pixman library +----------------------------------------- +A significant change in this snapshot compared to all previous cairo +releases is that cairo now depends on an external "pixman" library for +its software rendering. Previously this same code was compiled +internally as part of cairo, but now the code is separate so that both +cairo and the X server can now share common code, (thanks very much to +Søren Sandmann for his work on separating pixman and maintaining it). + +So users will need to acquire and build pixman before being able to +build cairo. The current release is 0.9.6 and can be obtained from +here: + + http://cairographics.org/releases/pixman-0.9.6.tar.gz + + which can be verified with: + + http://cairographics.org/releases/pixman-0.9.6.tar.gz.sha1 + 66f01a682c64403a3d7a855ba5aa609ed93bcb9e pixman-0.9.6.tar.gz + + http://cairographics.org/releases/pixman-0.9.6.tar.gz.sha1.asc + (signed by Carl Worth) + +Major PDF/PostScript improvements +--------------------------------- +Adrian Johnson has done some long-awaited work to make cairo's PDF and +PostScript output more interesting than ever before. First, many +operations that previously triggered image fallbacks will now be +rendered as native vectors. These operations include: + + PDF: cairo_push_group, cairo_surface_create_similar, + cairo_mask, A8/A1 surface sources, repeating/reflecting linear + gradients. + + PostScript: cairo_push_group, cairo_surface_create_similar, + gradients, bilevel alpha masks, (for example, all values either 0 or + 255 for an A8 mask). + +Not only that, but when an image fallback is required, it will now be +limited to only the necessary region. For example, a tiny translucent +image overlaying a small portion of text would previously caused an +entire PostScript page to be rendered as a giant image. Now, the +majority of that page will be nice text, and there will only be a tiny +image in the output. + +Additionally, the PostScript output now carefully encodes text so that +if it is subsequently converted to PDF, the text will be +selectable. + +This is very exciting progress, and we're hoping to hear from users +during the 1.5 series about how things have improved, (for example, +inkscape users doing cairo-based PDF export: please let us know how +things look). And feel free to pass your thanks along to Adrian for his excellent work. + +NOTE: This much improved PDF output makes more sophisticated use of +functionality in the PDF specification. This means that cairo's output +will sometimes expose bugs in some free software PDF viewers, (evince, +poppler, and xpdf, for example), that are not yet ready for such PDF +files. We're working with the poppler maintainers to get these bugs +fixed as quickly as possible. In the meantime, please double-check +with other PDF viewers if cairo-generated PDF files are not being +rendered correctly. It may be due to a bug in the viewer rather than +in the PDF file that cairo has created. + +Robustness improvements +----------------------- +Chris Wilson has made the largest contribution by far to cairo 1.5.2, +(in number of commits). His more than 150 commits include a huge +number of fixes to increase cairo's robustness. These fixes make cairo +more robust against invalid and degenerate input, (NaN, empty path, +etc.), against size-0 malloc calls, against memory leaks on +error-recovery paths, and against other failures during error +handling. He also implemented atomic operations to cairo, and used +them to fix cairo's previously non-thread-safe reference counting, +again improving robustness. + +Chris has put a tremendous amount of time and effort into writing +analysis tools for this work, and in running those tools and fixing +the problems they report. We're very grateful for this work, and hope +that all cairo users appreciate the more robust implementation that +results from it. + +This work is largely thankless, so it might make sense to notice +sometime that cairo has been running quite smoothly for you, and when +you do, send a quick "thank you" off to Chris Wilson, since it +is all definitely running smoother thanks to his work. + +New API +------- +There are no major additions to cairo's core API. The only new, +generic functions are: + + void + cairo_surface_copy_page (cairo_surface_t *surface); + + void + cairo_surface_show_page (cairo_surface_t *surface); + +which can now be used much more conveniently than the existing +cairo_copy_page and cairo_show_page functions in some +situations. These functions act identically, but require only a +cairo_surface_t* and not a cairo_t*. + +All other API additions are specific to particular backends. + +New cairo-win32 API (new font face function and "win32 printing" surface) +------------------------------------------------------------------------- +There is a new function for creating a win32 font face for both a +logfontw and an hfont together. This complements the existing +functions for creating a font face from one or the other: + + cairo_font_face_t * + cairo_win32_font_face_create_for_logfontw_hfont (LOGFONTW *logfont, + HFONT font); + +There is also a new "win32 printing" surface: + + cairo_surface_t * + cairo_win32_printing_surface_create (HDC hdc); + +This interface looks identical to the original +cairo_win32_surface_create, (both accept and HDC), but the behavior of +this new surface is very different. It should only be called with a +printing DC, and will result in all drawing commands being stored into +a meta-surface and emitted after each page is complete, with analysis +to do as minimal image-based fallbacks as necessary. The behavior and +implementation shares much with the PDF and PostScript backends. + +New cairo-ps API (EPS and PostScript level control) +--------------------------------------------------- +An often requested feature has been the ability to generate +Encapsulated PostScript (EPS) with cairo. We have that now with the +following very simple API. Just do cairo_ps_surface_create as usual +then call this function with a true value: + + void + cairo_ps_surface_set_eps (cairo_surface_t *surface, + cairo_bool_t eps); + +[NOTE: As always with snapshots, it's possible---though not very +likely---that the API could still be modified before a final +release. For example, this is the first public cairo function that +accepts a Boolean parameter. I'm generally opposed to Boolean +parameters, but this is probably the one case where I'm willing to +accept one, (namely a "set" function that accepts a single Boolean).] + +Also, it is now possible to control what PostScript level to target, +(either level 2 or level 3), with the following new API: + + typedef enum _cairo_ps_level { + CAIRO_PS_LEVEL_2, + CAIRO_PS_LEVEL_3 + } cairo_ps_level_t; + + void + cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, + cairo_ps_level_t level); + + void + cairo_ps_get_levels (cairo_ps_level_t const **levels, + int *num_levels); + + const char * + cairo_ps_level_to_string (cairo_ps_level_t level); + +Improvement for cairo-quartz +---------------------------- +Brian Ewins had contributed several improvements to cairo-quartz. These +include an implementation of EXTEND_NONE for linear and radial +gradients, (so this extend mode will no longer trigger image fallbacks +for these gradients), as well as native surface-mask clipping, (only +on OS X 10.4+ where the CGContextClipToMask function is available). + +He also fixed a semantic mismatch between cairo and quartz for dashing +with an odd number of entries in the dash array. + +We're grateful for Brian since not many quartz-specific improvements +to cairo would be happening without him. + +Optimizations +------------- +Optimize SVG output for when the same path is both filled and stroked, +and avoid unnecessary identity matrix in SVG output. (Emmanuel Pacaud). + +Optimize PS output to take less space (Ken Herron). + +Make PS output more compliant with DSC recommendations (avoid initclip +and copy_page) (Adrian Johnson). + +Make PDF output more compact (Adrian Johnson). + +Release glyph surfaces after uploading them to the X server, (should +save some memory for many xlib-using cairo application). (Behdad +Esfahbod). + +Optimize cairo-win32 to use fewer GDI objects (Vladimir Vukicevic). + +win32-printing: Avoid falling back to images when alpha == 255 +everywhere. (Adrian Johnson). + +win32-printing: Avoid falling back for cairo_push_group and +cairo_surface_create_similar. (Adrian Johnson) + +Bug fixes +--------- +Avoid potential integer overflows when allocating large buffers +(Vladimir Vukicevic). + +Preparations to allow the 16.16 fixed-point format to change to +24.8 (Vladimir Vukicevic). + +Fix bugs for unsupported X server visuals (rgb565, rgb555, bgr888, and +abgr8888). (Carl Worth and Vladimir Vukicevic) + +Fix bugs in PDF gradients (Adrian Johnson). + +Fix cairo-xlib to build without requiring Xrender header +files (Behdad Esfahbod). + +Make cairo more resilient in the case of glyphs not being available in +the current font. (Behdad Esfahbod) + +Prevent crashes when both atsui and ft font backends are compiled in +(Brian Ewins). + +Make font subsetting code more robust against fonts that don't include +optional tables (Adrian Johnson). + +Fix CFF subsetting bug, (which manifested by generating PDF files that +Apple's Preview viewer could not read) (Adrian Johnson). + +Fixed error handling for quartz and ATSUI backends (Brian Ewins). + +Avoid rounding problems by pre-transforming to avoid integer-only +restrictions on transformation in GDI (Adrian Johnson). + +Fixed an obscure bug (#7245) computing extents for some stroked +paths (Carl Worth). + +Fix crashes due to extreme transformation of the pen, (seems to show +up in many .swf files for some reason) (Carl Worth). + +Release 1.4.10 (2007-06-27 Carl Worth ) +========================================================== +This is the fifth update in cairo's stable 1.4 series. It comes +roughly three weeks after the 1.4.8 release. The most significant +change in this release is a fix to avoid an X error in certain cases, +(that were causing OpenOffice.org to crash in Fedora). There is also a +semantic change to include child window contents when using an xlib +surface as a source, an optimization when drawing many rectangles, and +several minor fixes. + +Eliminate X errors that were killing OO.o (Chris Wilson) +-------------------------------------------------------- +Cairo is fixed to avoid the X errors propagated when cleaning up +Render Pictures after the application had already destroyed the +Drawable they reference. (It would be nice if the X server wouldn't +complain that some cleanup work is already done, but there you have +it.) This fixes the bug causing OpenOffice.org to crash as described +here: + + XError on right click menus in OOo. + https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=243811 + +Use IncludeInferiors when using xlib surface as a source (Ryan Lortie) +---------------------------------------------------------------------- +When an xlib surface is used as the source of a draw operation the +contents of child windows are now included in the source data. The +semantics of drawing to xlib surfaces are unchanged (ie: draws are +still clipped by child windows overlapping the destination window). + +Optimize drawing of many rectangles (Vladimir Vukicevic) +-------------------------------------------------------- +Avoid O(N*N) loop when filling many axis-aligned rectangles, (either +many rectangles as separate sub-paths or due to dashing). + +Miscellaneous fixes +------------------- +Fix cairo-perf on Solaris by linking to librt. (Behdad Esfahbod) + +Fix make check for systems that require executable files to have a +particular extension. (Behdad Esfahbod) + +Eliminate some warnings in cairo-quartz. (Brian Ewins) + +Fix build-breaking typo for cairo-directfb. (Chris Wilson) + +Release 1.4.8 (2007-06-07 Carl Worth ) +========================================================= +This is the fourth update in cairo's stable 1.4 series. It comes just +over five weeks after the 1.4.6 release. This release includes a +thread-safe surface-cache for solid patterns which significantly +improves text rendering with the xlib backend. Also, dozens of error +paths in cairo have been fixed thanks to extensive fault-injection +testing by Chris Wilson. + +Surface cache for solid patterns +-------------------------------- +Originally written by Jorn Baayen, the introduction of a small cache +for surfaces created for solid patterns improves performance +dramatically. For example, this reduces the volume of X requests +during text rendering to the same level as Xft. + +This cache first made its appearance in a 1.3.x snapshot, but was +removed before appearing in any previous major release due to +complications with multi-threaded programs. For example, programs like +evince that would carefully restrict usage of cairo-xlib to a single +thread were unpleasantly surprised to find that using cairo-image in a +separate thread could trigger X requests. + +Behdad Esfahbod designed a fix which was implemented by Chris +Wilson. Now, the necessary X requests are queued up until the next +time the application directly operates on an xlib surface. + +Improved error handling paths +------------------------------ +Chris Wilson continued the excellent work he started in cairo 1.4.4 to +make cairo much more robust against out-of-memory and other errors. He +applied his memory allocation fault injection cairo's main test suite, +(previously he had applied it to cairo's performance suite). + +Chris's testing found dozens of bugs which he fixed. Many of these +bugs had perhaps never been hit by any users. But at least one was +hit by the gnome-about program which resulted in dozens of duplicated +bug reports against that program: + + http://bugzilla.gnome.org/show_bug.cgi?id=431990 + +We were very pleasantly surprised to see this bug get fixed as a +side-effect of Chris's work. Well done, Chris! + +Other fixes +----------- +Cleanup of mutex declarations (Behdad Esfahbod) + +Remove unnecessary clip region from SVG output (Emmanuel Pacaud) + +Remove Xsun from the buggy_repeat blacklist (Elaine Xiong) + +ATSUI: Fix glyph measurement: faster and more correct (Brian Ewins) + +Quartz: fixed 'extend' behaviour for patterns, improved pattern performance, +and a few smaller correctness fixes. (Brian Ewins, Vladimir Vukicevic) + +Release 1.4.6 (2007-05-01 Carl Worth ) +========================================================= +This is the third update in cairo's stable 1.4 series. It comes a +little less than three weeks since the 1.4.4 release. This release +fixes the broken mutex initialization that made cairo 1.4.4 unusable +on win32, OS/2, and BeOS systems. This release also adds significant +improvements to cairo's PDF backend, (native gradients!), and a couple +of performance optimizations, (one of which is very significant for +users of the xlib backend). See below for more details. + +Repaired mutex initialization +----------------------------- +We apologize that cairo 1.4.4 did little more than crash on many +platforms which are less-frequently used by the most regular cairo +maintainers, (win32, OS/2, and BeOS). The mutex initialization +problems that caused those crashes should be fixed now. And to avoid +similar problems in the future, we've now started posting pre-release +snapshots to get better testing, (subscribe to cairo@cairographics.org +if you're interested in getting notified of those and testing them). + +PDF Improvements +---------------- +Thanks to Adrian Johnson, (cairo PDF hacker extraordinaire), we have +several improvements to cairo's PDF backend to announce: + +Native gradients: + + As of cairo 1.4.6, cairo will now generate native PDF gradients in + many cases, (previously, the presence of a gradient on any page + would force rasterized output for that page). Currently, only + gradients with extend types of PAD (the default) or NONE will + generate native PDF gradients---others will still trigger + rasterization, (but look for support for other extend modes in a + future release). Many thanks to Miklós Erdélyi as well, who did the + initial work for this support. + +Better compatibility with PDF viewers: + + The PDF output from cairo should now be displayed correctly by a + wider range of PDF viewers. Adrian tested cairo's PDF output against + many PDF viewers, identified a common bug in many of those viewers + (ignoring the CTM matrix in some cases), and modified cairo's output + to avoid triggering that bugs (pre-transforming coordinates and + using an identity matrix). + +Better OpenType/CFF subsetting: + + Cairo will now embed CFF and TrueType fonts as CID fonts. + +Performance optimizations +------------------------- +Faster cairo_paint_with_alpha: + + The cairo_paint_with_alpha call is used to apply a uniform alpha + mask to a pattern. For example, it can be used to gradually fade an + image out or in. Jeff Muizelaar fixed some missing/broken + optimizations within the implementation of this function resulting + in cairo_paint_with_alpha being up to 4 times faster when using + cairo's image backend. + +Optimize rendering of "off-screen" geometry: + + Something that applications often do is to ask cairo to render + things that are either partially or wholly outside the current clip + region. Since 1.4.0 the image backend has been fixed to not waste + too much time in this case. But other backends have still been + suffering. + + In particular, the xlib backend has often performed quite badly in + this situation. This is due to a bug in the implementation of + trapezoid rasterization in many X servers. + + Now, in cairo 1.4.6 there is a higher-level fix for this + situation. Cairo now eliminates or clips trapezoids that are wholly + or partially outside the clip region before handing the trapezoids + to the backend. This means that the X server's performance bug is + avoided in almost all cases. + + The net result is that doing an extreme zoom-in of vector-based + objects drawn with cairo might have previously brought the X server + to its knees as it allocated buffers large enough to fit all of the + geometry, (whether visible or not). But now the memory usage should + be bounded and performance should be dramatically better. + +Miscellaneous +------------- +Behdad contributed an impressively long series of changes that +organizes cairo's internals in several ways that will be very +beneficial to cairo developers. Thanks, Behdad! + +Behdad has also provided a utility for generating malloc statistics, +(which was used during the great malloc purges of 1.4.2 and +1.4.4). This utility isn't specific to cairo so may be of benefit to +others. It is found in cairo/util/malloc-stats.c and here are Behdad's +notes on using it: + + To build, do: + + make malloc-stats.so + + inside util/, and to use, run: + + LD_PRELOAD=malloc-stats.so some-program + + For binaries managed by libtool, eg, cairo-perf, do: + + ../libtool --mode=execute /bin/true ./cairo-perf + LD_PRELOAD="../util/malloc-stats.so" .libs/lt-cairo-perf + +Finally, the cairo-perf-diff-files utility was enhanced to allow for +generating performance reports from several runs of the same backend +while some system variables were changed. For example, this is now +being used to allow cairo-perf to measure the performance of various +different acceleration architectures and configuration options of the +X.org X server. + +Release 1.4.4 (2007-04-13 Carl Worth ) +========================================================= +This is the second update release in cairo's stable 1.4 series. It +comes just less than a month after 1.4.2. The changes since 1.4.2 +consist primarily of bug fixes, but also include at least one +optimization. See below for details. + +Of all the work that went into the 1.4.4 release + +There have been lots of individuals doing lots of great work on cairo, +but two efforts during the 1.4.4 series deserve particular mention: + +Internal cleanup of error handling, (Chris Wilson) +-------------------------------------------------- +Chris contributed a tremendous series of patches (74 patches!) to +improve cairo's handling of out-of-memory and other errors. He began +by adding gcc's warn_unused_attribute to as many functions as +possible, and then launched into the ambitious efforts of adding +correct code to quiet the dozens of resulting warnings. + +Chris also wrote a custom valgrind skin to systematically inject +malloc failures into cairo, and did all the work necessary to verify +that cairo's performance test suite runs to completion without +crashing. + +The end result is a much more robust implementation. Previously, many +error conditions would have gone unnoticed and would have led to +assertion failures, segmentation faults, or other harder-to-diagnose +problems. Now, more than ever, cairo should cleanly let the user know +of problems through cairo_status and other similar status +functions. Well done, Chris! + +More malloc reduction, (Mathias Hasselmann) +------------------------------------------- +After 1.4.0, Behdad launched an effort to chase down excessive calls +to malloc within the implementation of cairo. He fixed a lot of +malloc-happy objects for 1.4.2, but one of the worst offenders, +(pixman regions), was left around. Mathias contributed an excellent +series of 15 patches to finish off this effort. + +The end result is a cairo that calls malloc much less often than it +did before. Compared to 1.4.2, 55% of the calls to malloc have been +eliminate, (and 60% have been eliminated compared to 1.4.0). Well +done, Mathias! + +Other improvements since 1.4.2 +------------------------------ +• Centralize mutex declarations (will reduce future build breaks), + (Mathias Hasselmann) + +• Reduce malloc by caching recently freed pattern objects (Chris + Wilson) + +• Fix some broken composite operations (David Reveman) + https://bugs.freedesktop.org/show_bug.cgi?id=5777 + +Backend-specific fixes +---------------------- +PDF: + • Use TJ operator for more compact representation of glyphs (Adrian + Johnson) + + • Fix glyph positioning bug when glyphs are not horizontal + http://lists.freedesktop.org/archives/cairo/2007-April/010337.html + +win32: + • Fix crash when rendering with bitmap fonts (Carl Worth) + https://bugzilla.mozilla.org/show_bug.cgi?id=376498 + +xlib: + • Turn metrics-hinting on by default (Behdad Esfahbod) + + • Fix edge-effect problem with transformed images drawn to xlib + (Behdad Esfahbod) + https://bugs.freedesktop.org/show_bug.cgi?id=10508 + + • Avoid dereferencing a NULL screen. (Chris Wilson) + https://bugs.freedesktop.org/show_bug.cgi?id=10517 + +Quartz/ATSUI: + • Fix scaling of glyph surfaces + (Brian Ewins) + https://bugs.freedesktop.org/show_bug.cgi?id=9568 + + • Fix compilation failure when both xlib and quartz enabled + (Brian Ewins) + + • Fix rounding bug leading to incorrectly positioned glyphs + (Robert O'Callahan) + https://bugs.freedesktop.org/show_bug.cgi?id=10531 + +Release 1.4.2 (2007-03-19 Carl Worth ) +========================================================= +This is the first update release in cairo's stable 1.4 series. It +comes just less than 2 weeks after 1.4.0. We hadn't anticipated an +update this early, but we've managed to collect some important fixes +that we wanted to get out to cairo users as soon as possible, (6 fixes +for crashes, 1 case where graphical elements would not be drawn at +all, a handful of backend-specific bugs, and several important build +fixes). + +There's almost nothing but bug fixes in this release, (see below one +optimization that Behdad did sneak in), so we recommend that everyone +upgrade to this release when possible. + +Thanks to the many people that worked to fix these bugs, and those +that did the work to report them and to test the fixes, (wherever +possible both names are credited below). + +Critical fixes +-------------- +• Fix a crash due to a LOCK vs. UNLOCK typo (M. Drochner fixing Carl + Worth's embarrassing typo). + + http://bugs.freedesktop.org/show_bug.cgi?id=10235 + +• Fix potential buffer overflow, which on some systems with a checking + variant of snprintf would lead to a crash (Adrian Johnson, Stanislav + Brabec, and sangu). + + https://bugs.freedesktop.org/show_bug.cgi?id=10267 + https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=232576 + +• Fix a crash in cairo_stroke_extents or cairo_in_stroke when line + width is 0.0. (Carl Worth and Sebastien Bacher) + + https://bugs.freedesktop.org/show_bug.cgi?id=10231 + +• Fix a crash on certain combinations of X server/video drivers (Carl + Worth and Tomas Carnecky). + + https://bugs.freedesktop.org/show_bug.cgi?id=10250 + +• Fix a crash due to mishandling of invalid user input (Carl Worth and + Alexander Darovsky). + + https://bugs.freedesktop.org/show_bug.cgi?id=9844 + +• xlib: Cleanup server-side glyph caches on XCloseDisplay. This + eliminated a crash detected by the perf suite, (and that + applications could have run into as well). (Chris Wilson) + +Other bug fixes +--------------- +• Fix for some geometry which simply disappeared under some + transformations---a stroked line with an extreme skew in X, for + example (Carl Worth and Jonathan Watt). + + https://bugzilla.mozilla.org/show_bug.cgi?id=373632 + +• SVG: Fix radial gradients for CAIRO_EXTEND_REFLECT and when r0 > r1 + (Emmanuel Pacaud). + +• PDF: Set page group color space to DeviceRGB. + + This fixes incorrect (muddy) transparent colors when rendering cairo + PDF output in some viewers. (Adrian Johnson, Adam Goode, and + MenTaLguY). + + http://lists.freedesktop.org/archives/cairo/2006-November/008551.html + +• win32: Return correct metrics when hinting is off, and fix font + descent computation (Behdad Esfahbod). + +• quartz: Fix glyph interfaces to correctly return user-space rather + than device-space coordinates (Brian Ewins). + + https://bugs.freedesktop.org/show_bug.cgi?id=9568 + +• xcb: Fix parameter-order confusion with xcb_create_pixmap, which now + makes all tests that pass with xlib now pass with xcb (Carl Worth, + Jamey Sharp). + +• Fix some memory leaks in the perf suite (Chris Wilson). + +• Fix perf suite to consider changes in pixman/src (Mathias + Hasselmann). + +Build fixes +----------- +• Don't include pre-generated cairo-features.h file. This was causing + build failures when building with the directfb backend enabled + (Behdad Esfahbod). + + https://bugs.freedesktop.org/show_bug.cgi?id=10189 + +• Eliminate use of maintainer mode from cairo's automake/configure + script. This means that updates to files such as Makefile.am will + take effect, (by rerunning automake and friends as necessary) when + invoking make rather than being silently ignored. (Behdad Esfahbod) + +• Don't compile cairo-deflate-stream.c, which depends on zlib, unless + building the pdf backend which requires it. (Carl Worth, Tor + Lillqvist) + + https://bugs.freedesktop.org/show_bug.cgi?id=10202 + +• Don't make the ps backend link against zlib anymore, since it + doesn't require it (Carl Worth). + +• Use "find !" rather than "find -not" for better portability (Thomas + Klausner). + + https://bugs.freedesktop.org/show_bug.cgi?id=10226 + +• Don't use unsupported visibility attribute "hidden" on Solaris + (Gilles Dauphin, Thomas Klausner). + + https://bugs.freedesktop.org/show_bug.cgi?id=10227 + +Optimization +------------ +• It was Behdad that suggested we focus strictly on bug fixes now that + we shipped so many performance improvements in 1.4.0, but it was + also Behdad that got distracted by the chance to remove a lot of + mallocs from cairo. Paths, gstates, trapezoids, splines, polygons, + and gradient color stops will now use small, stack-allocated buffers + in the most common cases rather than calling malloc as + often. (Behdad Esfahbod). And look for more from Mathias Hasselmann + soon. + +Release 1.4.0 (2007-03-06 Carl Worth ) +========================================================= +The many people[*] who have been working hard on cairo are very +pleased to announce the long-awaited release of cairo 1.4. This +release comes 4 months after the last stable update release (1.2.6) +and 9 months since the initial release of 1.2.0. + +The release notes below are intended to capture the highlights of the +changes that have occurred from the 1.2 series to the new 1.4.0 +release. + +Performance improvements +------------------------ +Within the cairo project, the last 6 months or so has seen an intense +effort focusing on the performance of cairo itself. That effort has +paid off considerably, as can be seen in the following highlights of +some of the performance differences from cairo 1.2.6 to cairo 1.4.0. + +(Note: The performance results reported here were measured on an x86 +laptop. Many of the improvements in 1.4---particular those involving +text rendering---are even more dramatic on embedded platforms without +hardware floating-point units. Such devices played an important part +of many of the optimizations that found their way into cairo over the +last few months.) + +• Dramatic improvement when drawing objects that are mostly off-screen + with the image backend (with the xlib backend this case is still + slow due to an X server bug): + + image-rgba long-lines-uncropped-100 479.64 -> 4.98: 96.24x speedup + ███████████████████████████████████████████████▋ + +• Dramatic improvement when copying a small fraction of an image + surface to an xlib surface: + + xlib-rgba subimage_copy-512 3.93 -> 0.07: 54.52x speedup + ██████████████████████████▊ + +• Dramatic improvement to tessellation speed for complex objects: + + image-rgb tessellate-256-100 874.16 -> 34.79: 25.13x speedup + ████████████▏ + xlib-rgba zrusin_another_fill-415 148.40 -> 13.85: 10.72x speedup + ████▉ + xlib-rgb world_map-800 680.20 -> 345.54: 1.97x speedup + ▌ + +• Dramatic improvement to the speed of stroking rectilinear shapes, + (such as the outline of a rectangle or "box"): + + image-rgb box-outline-stroke-100 0.18 -> 0.01: 24.22x speedup + ███████████▋ + xlib-rgb box-outline-stroke-100 0.46 -> 0.06: 8.05x speedup + ███▌ + + +• Dramatic improvements to text rendering speeds: + + xlib-rgba text_image_rgba_over-256 63.12 -> 9.61: 6.57x speedup + ██▊ + +• 3x improvements to floating-point to fixed-point conversion speeds: + + image-rgba pattern_create_radial-16 9.29 -> 3.44: 2.70x speedup + ▉ + +• 2x improvements to linear gradient computation: + + image-rgb paint_linear_rgb_source-512 26.22 -> 11.61: 2.26x speedup + ▋ + +• 2x improvement to a case common in PDF rendering: + + image-rgb unaligned_clip-100 0.10 -> 0.06: 1.81x speedup + ▍ + +• 1.3x improvement to rectangle filling speed (note: this improvement + is new since 1.3.16---previously this test case was a 1.3x slowdown + compared to 1.2.6): + + image-rgba rectangles-512 6.19 -> 4.37: 1.42x speedup + ▎ + xlib-rgba rectangles-512 7.48 -> 5.58: 1.34x speedup + ▏ + +NOTE: In spite of our best efforts, there are some measurable +performance regressions in 1.4 compared to 1.2. It appears that the +primary problem is the increased overhead of the new tessellator when +drawing many, very simple shapes. The following test cases capture +some of that slowdown: + + image-rgba mosaic_tessellate_lines-800 11.03 -> 14.29: 1.30x slowdown + ▏ + image-rgba box-outline-fill-100 0.01 -> 0.01: 1.26x slowdown + ▏ + image-rgba fill_solid_rgb_over-64 0.20 -> 0.22: 1.12x slowdown + + image-rgba fill_image_rgba_over-64 0.23 -> 0.25: 1.10x slowdown + + xlib-rgb paint_image_rgba_source-256 3.24 -> 3.47: 1.07x slowdown + +We did put some special effort into eliminating this slowdown for the +very common case of drawing axis-aligned rectangles with an identity +matrix (see the box-outline-stroke and rectangles speedup numbers +above). Eliminating the rest of this slowdown will be a worthwhile +project going forward. + +Also note that the "box-outline-fill" case is a slowdown while +"box-outline-stroke" is a (huge) speedup. These two test cases +resulted from the fact that some GTK+ theme authors were filling +between two rectangles to avoid slow performance from the more natural +means of achieving the same shape by stroking a single rectangle. With +1.4 that workaround should definitely be eliminated as it will now +cause things to perform more slowly. + +Greatly improved PDF output +--------------------------- +We are very happy to be able to announce that cairo-generated PDF +output will now have text that can be selected, cut-and-pasted, and +searched with most capable PDF viewer applications. This is something +that was not ever possible with cairo 1.2. + +Also, the PDF output now has much more compact encoding of text than +before. Cairo is now much more careful to not embed multiple copies of +the same font at different sizes. It also compresses text and font +streams within the PDF output. + +API additions +------------- +There are several new functions available in 1.4 that were not +available in 1.2. Curiously, almost all of the new functions simply +allow the user to query state that has been set in cairo (many new +"get" functions) rather than providing any fundamentally new +operations. The new functionality is: + +• Getting information about the current clip region + + cairo_clip_extents + cairo_copy_clip_rectangle_list + cairo_rectangle_list_destroy + +• Getting information about the current dash setting + + cairo_get_dash_count + cairo_get_dash + +• Getting information from a pattern + + cairo_pattern_get_rgba + cairo_pattern_get_surface + cairo_pattern_get_color_stop_rgba + cairo_pattern_get_color_stop_count + cairo_pattern_get_linear_points + cairo_pattern_get_radial_circles + +• Getting the current scaled font + + cairo_get_scaled_font + +• Getting reference counts + + cairo_get_reference_count + cairo_surface_get_reference_count + cairo_pattern_get_reference_count + cairo_font_face_get_reference_count + cairo_scaled_font_get_reference_count + +• Setting/getting user data on objects + + cairo_set_user_data + cairo_get_user_data + cairo_pattern_set_user_data + cairo_pattern_get_user_data + cairo_scaled_font_set_user_data + cairo_scaled_font_get_user_data + +• New cairo-win32 functions: + + cairo_win32_surface_create_with_ddb + cairo_win32_surface_get_image + cairo_win32_scaled_font_get_logical_to_device + cairo_win32_scaled_font_get_device_to_logical + +API deprecation +--------------- +The CAIRO_FORMAT_RGB16_565 enum value has been deprecated. It never +worked as a format value for cairo_image_surface_create, and it wasn't +necessary for supporting 16-bit 565 X server visuals. + +A sampling of bug fixes in cairo 1.4 +------------------------------------ + • Fixed radial gradients + • Fixed dashing (degenerate and "leaky" cases) + • Fixed transformed images in PDF/PS output (eliminate bogus repeating) + • Eliminate errors from CAIRO_EXTEND_REFLECT and CAIRO_EXTEND_PAD + • cairo_show_page no longer needed for single-page output + • SVG: Fix bug preventing text from appearing in many viewers + • cairo-ft: Return correct metrics when hinting is off + • Eliminate crash in cairo_create_similar if nil surface is returned + • Eliminate crash after INVALID_RESTORE error + • Fix many bugs related to multi-threaded use and locking + • Fix for glyph spacing 32 times larger than desired (cairo-win32) + • Fixed several problems in cairo-atsui (assertion failures) + • Fix PDF output to avoid problems when printing from Acrobat Reader + • Fix segfault on Mac OS X (measuring a zero-length string) + • Fix text extents to not include the size of non-inked characters + • Fix for glyph cache race condition in glitz backend (Jinghua Luo) + • Fix make check to work on OPD platforms (IA64 or PPC64) + • Fix compilation problems of cairo "wideint" code on some platforms + • Many, many others... + +Experimental backends (quartz, XCB, OS/2, BeOS, directfb) +--------------------------------------------------------- +None of cairo's experimental backends are graduating to "supported" +status with 1.4.0, but two of them in particular (quartz and xcb), are +very close. + +The quartz baceknd has been entirely rewritten and is now much more +efficient. The XCB backend has been updated to track the latest XCB +API (which recently had a 1.0 release). + +We hope to see these backends become supported in a future release, +(once they are passing all the tests in cairo's test suite). + +The experimental OS/2 backend is new in cairo 1.4 compared to cairo +1.2. + +Documentation improvements +-------------------------- +We have added documentation for several functions and types that +were previously undocumented, and improved documentation on other +ones. As of this release, there remain only two undocumented +symbols: cairo_filter_t and cairo_operator_t. + +[*]Thanks to everyone +--------------------- +I've accounted for 41 distinct people with attributed code added to +cairo between 1.2.6 and 1.4.0, (their names are below). That's an +impressive number, but there are certainly dozens more that +contributed with testing, suggestions, clarifying questions, and +encouragement. I'm grateful for the friendships that have developed as +we have worked on cairo together. Thanks to everyone for making this +all so much fun! + +Adrian Johnson, Alfred Peng, Alp Toker, Behdad Esfahbod, +Benjamin Otte, Brian Ewins, Carl Worth, Christian Biesinger, +Christopher (Monty) Montgomery, Daniel Amelang, Dan Williams, +Dave Yeo, David Turner, Emmanuel Pacaud, Eugeniy Meshcheryakov, +Frederic Crozat, Hans Breuer, Ian Osgood, Jamey Sharp, Jeff Muizelaar, +Jeff Smith, Jinghua Luo, Jonathan Watt, Joonas Pihlaja, Jorn Baayen, +Kalle Vahlman, Kjartan Maraas, Kristian Høgsberg, M Joonas Pihlaja, +Mathias Hasselmann, Mathieu Lacage, Michael Emmel, Nicholas Miell, +Pavel Roskin, Peter Weilbacher, Robert O'Callahan, +Soren Sandmann Pedersen, Stuart Parmenter, T Rowley, +Vladimir Vukicevic + +Snapshot 1.3.16 (2007-03-02 Carl Worth ) +=========================================================== +New API functions +----------------- +A few new public functions have been added to the cairo API since the +1.3.14 snapshot. These include a function to query the current scaled +font: + + cairo_get_scaled_font + +New functions to query the reference count of all cairo objects: + + cairo_get_reference_count + + cairo_surface_get_reference_count + cairo_pattern_get_reference_count + + cairo_font_face_get_reference_count + cairo_scaled_font_get_reference_count + +And new functions to allow the use of user_data with any cairo object, +(previously these were only available on cairo_surface_t and +cairo_font_face_t objects): + + cairo_set_user_data + cairo_get_user_data + + cairo_pattern_set_user_data + cairo_pattern_get_user_data + + cairo_scaled_font_set_user_data + cairo_scaled_font_get_user_data + +Usability improvement for PDF/PS/SVG generation +----------------------------------------------- +In previous versions of cairo, generating single-page output with the +cairo-pdf, cairo-ps, or cairo-svg backends required a final call to +cairo_show_page. This was often quite confusing as people would port +functional code from a non-paginated backend and be totally mystified +as to why the output was blank until they learned to add this call. + +Now that call to cairo_show_page is optional, (it will be generated +implicitly if the user does not call it). So cairo_show_page is only +needed to explicitly separate multiple pages. + +Greatly improved PDF output +--------------------------- +We are very happy to be able to announce that cairo-generated PDF +output will now have text that can be selected, cut-and-paste, and +searched with most capable PDF viewer applications. This is something +that was not ever possible with cairo 1.2. + +Also, the PDF output now has much more compact encoding of text than +before. Cairo is now much more careful to not embed multiple copies of +the same font at different sizes. It also compresses text and font +streams within the PDF output. + +Major bug fixes +--------------- + • Fixed radial gradients + + The rendering of radial gradients has been greatly improved. In + the cairo 1.2 series, there was a serious regression affecting + radial gradients---results would be very incorrect unless one of + the gradient circles had a radius of 0.0 and a center point within + the other circle. These bugs have now been fixed. + + • Fixed dashing + + Several fixes have been made to the implementation of dashed + stroking. Previously, some dashed, stroked rectangles would + mis-render and fill half of the rectangle with a large triangular + shape. This bug has now been fixed. + + • Fixed transformed images in PDF/PS output + + In previous versions of cairo, painting with an image-based source + surface pattern to the PDF or PS backends would cause many kinds + of incorrect results. One of the most common problems was that an + image would be repeated many times even when the user had + explicitly requested no repetition with CAIRO_EXTEND_NONE. These + bugs have now been fixed. + + • Eliminate errors from CAIRO_EXTEND_REFLECT and CAIRO_EXTEND_PAD + + In the 1.2 version of cairo any use of CAIRO_EXTEND_REFLECT or + CAIRO_EXTEND_PAD with a surface-based pattern resulted in an + error, (cairo would stop rendering). This bug has now been + fixed. + + Now, CAIRO_EXTEND_REFLECT should work properly with surface + patterns. + + CAIRO_EXTEND_PAD is still not working correctly, but it will now + simply behave as CAIRO_EXTEND_NONE rather than triggering the + error. + +New rewrite of quartz backend (still experimental) +-------------------------------------------------- +Cairo's quartz backend has been entirely rewritten and is now much +more efficient. This backend is still marked as experimental, not +supported, but it is now much closer to becoming an officially +supported backend. (For people that used the experimental nquartz +backend in previous snapshots, that implementation has now been +renamed from "nquartz" to "quartz" and has replaced the old quartz +backend.) + +Documentation improvements +-------------------------- +We have added documentation for several functions and types that +were previously undocumented, and improved documentation on other +ones. As of this release, there remain only two undocumented +symbols: cairo_filter_t and cairo_operator_t. + +Other bug fixes +--------------- + • cairo-svg: Fix bug that was preventing text from appearing in many + viewers + + • cairo-ft: Return correct metrics when hinting is off + + • Cairo 1.3.14 deadlocks in cairo_scaled_font_glyph_extents or + _cairo_ft_unscaled_font_lock_face + + https://bugs.freedesktop.org/show_bug.cgi?id=10035 + + • cairo crashes in cairo_create_similar if nil surface returned by + other->backend->create_similar + + https://bugs.freedesktop.org/show_bug.cgi?id=9844 + + • evolution crash in _cairo_gstate_backend_to_user() + https://bugs.freedesktop.org/show_bug.cgi?id=9906 + + • Fix memory leak in rectilinear stroking code + +Things not in this release +-------------------------- + • Solid-surface-pattern cache: This patch had been applied during + the 1.3.x series, but it was reverted due to some inter-thread + problems it caused. The patch is interesting since it made a big + benefit for text rendering performance---so we'll work to bring a + corrected version of this patch back as soon as possible. + +Snapshot 1.3.14 (2006-02-13 Carl Worth ) +=========================================================== +This is the seventh development snapshot in the 1.3 series, (and there +likely won't be many more before the 1.4.0 release). It comes just +over 3 weeks after the 1.3.12 snapshot. + +Since we're so close to the 1.4.0 release, there are not a lot of new +features nor even a lot of new performance improvements in this +snapshot. Instead, there are a great number of bug fixes. Some are +long-standing bugs that we're glad to say goodbye to, and several are +fixes for regressions that were introduced as part of the optimization +efforts during the 1.3.x series. + +PDF text selection fixed +------------------------ +The inability to correctly select text in cairo-generated PDF has been +a defect ever since the initial support for the PDF backend in the +cairo 1.2.0 release. With the 1.3.14 snapshot, in most situations, and +with most PDF viewer applications, the PDF generated by cairo will +allow text to be correctly selected for copy-and-paste, (as well as +searching). + +We're very excited about this new functionality, (and very grateful to +Adrian Johnson, Behdad Esfahbod, and others that have put a lot of +work into this lately). Please test this new ability and give feedback +on the cairo@cairographics.org list. + +Many thread-safety issues fixed +------------------------------- +We've discovered that no release of cairo has ever provided safe text +rendering from a multi-threaded application. With the 1.3.14 snapshot +a huge number of the bugs in this area have been fixed, and multiple +application dvelopers have now reported success at writing +multi-threaded applications with cairo. + +Other fixes +----------- +Fixed a bug that was causing glyph spacing to be 32 times larger than +desired when using cairo-win32. + +Fixed a regression in the rendering of linear gradients that had been +present since the 1.3.8 snapshot. + +Fixed several problems in cairo-atsui that were leading to assertion +failures when rendering text. + +Fix corrupted results when rendering a transformed source image +surface to an xlib surface. This was a regression that had been +present since the 1.3.2 snapshot. + +Fixed PDF output to prevent problems printing from some versions of +Acrobat Reader, (a single glyph was being substituted for every +glyph). + +And many other fixes as well, (see the logs for details). + +Snapshot 1.3.12 (2007-01-20 Carl Worth ) +=========================================================== +The relentless march toward the cairo 1.4 release continues, (even if +slightly late out of the starting blocks in 2007). This is the sixth +development snapshot in the 1.3 series. It comes 4 weeks after the +1.3.10 snapshot. + +Performance +----------- +As usual, this snapshot has some fun performance improvements to show +off: + +image-rgba long-lines-uncropped-100 470.08 -> 4.95: 94.91x speedup +███████████████████████████████████████████████ +image-rgb long-lines-uncropped-100 461.60 -> 4.96: 93.02x speedup +██████████████████████████████████████████████ + +This 100x improvement, (and yes, that's 100x, not 100%), in the image +backend occurs when drawing large shapes where only a fraction of the +shape actually appears in the final result, (the rest being outside +the bounds of the destination surface). Many applications should see +speedups here, and the actual amount of speedup depends on the ratio +of non-visible to visible portions of geometry. + +[Note: There remains a similar performance bug when drawing mostly +non-visible objects with the xlib backend. This is due to a similar +bug in the X server itself, but we hope a future cairo snapshot will +workaround that bug to get a similar speedup with the xlib backend.] + +image-rgba unaligned_clip-100 0.09 -> 0.06: 1.67x speedup +▍ +image-rgb unaligned_clip-100 0.09 -> 0.06: 1.66x speedup +▍ + +This speedup is due to further MMX optimization by Soeren Sandmann for +a case commonly hit when rendering PDF files, (and thanks to Jeff +Muizelaar for writing code to extract the test case for us). + +There's another MMX optimization in this snapshot (without a fancy +speedup chart) by Dan Williams which improves compositing performance +specifically for the OLPC machine. + +Thanks to Adrian Johnson, cairo's PDF output is now much more +efficient in the way it encodes text output. By reducing redundant +information and adding compression to text output streams, Adrian +achieved a ~25x improvement in the efficiency of encoding text in PDF +files, (was ~45 bytes per glyph and is now ~1.6 bytes per glyph). + +Bug fixes +--------- +In addition to those performance improvements, this snapshot includes +several bug fixes: + + * A huge number of bug fixes for cairo-atsui text rendering, (for mac + OS X). These bugs affect font selection, glyph positioning, glyph + rendering, etc. One noteworthy bug fixes is that + cairo_select_font_face will no longer arbitrarily select bold nor + italic when not requested, (at least not when using a standard CSS2 + font family name such as "serif", "sans-serif", "monospace", etc.). + All these fixes are thanks to Brian Ewins who continues to do a + great job as the new cairo-atsui maintainer. + + * Fix PDF output so that images that are scaled down no longer + mysteriously repeat (Carl Worth). + + * Fix segfault on Mac OS X dues to attempt to measure extents of a + zero-length string (Behdad Esfahbod). + + * Fix text extents to not include the size of initial/trailing + non-inked characters (Behdad Esfahbod). + +API tweaks +---------- +Three functions have had API changes to improve consistency. Note that +the API functions being changed here are all functions that were +introduced as new functions during these 1.3.x snapshots. As always, +there will not be any API changes to functions included in a major +release (1.2.x, 1.4.x, etc.) of cairo. + +The changes are as follows: + + * Rename of cairo_copy_clip_rectangles to cairo_copy_clip_rectangle_list. + + * Change cairo_get_dash_count to return an int rather than accepting a + pointer to an int for the return value. + + * Change cairo_get_dash to have a void return type rather than + returning cairo_status_t. + +It's possible there will be one more round of changes to these +functions, (and perhaps cairo_get_color_stop as well), as we seek to +establish a unifying convention for returning lists of values. + +Snapshot 1.3.10 (2006-12-23 Carl Worth ) +=========================================================== +Santa Claus is coming just a little bit early this year, and he's +bringing a shiny new cairo snapshot for all the good little boys and +girls to play with. + +This is the fifth development snapshot in the 1.3 series. It comes 9 +days after the 1.3.8 snapshot, and still well within our goal of +having a new snapshot every week, (though don't expect one next +week---we'll all be too stuffed with sugar plums). + +Speaking of sugar plums, there's a sweet treat waiting in this cairo +snapshot---greatly improved performance for stroking rectilinear +shapes, like the ever common rectangle: + +image-rgb box-outline-stroke-100 0.18 -> 0.01: 25.58x speedup +████████████████████████▋ +image-rgba box-outline-stroke-100 0.18 -> 0.01: 25.57x speedup +████████████████████████▋ +xlib-rgb box-outline-stroke-100 0.49 -> 0.06: 8.67x speedup +███████▋ +xlib-rgba box-outline-stroke-100 0.22 -> 0.04: 5.39x speedup +████▍ + +In past releases of cairo, some people had noticed that using +cairo_stroke to draw rectilinear shapes could be awfully slow. Many +people had worked around this by using cairo_fill with a more complex +path and gotten a 5-15x performance benefit from that. + +If you're one of those people, please rip that workaround out, as now +the more natural use of cairo_stroke should be 1.2-2x faster than the +unnatural use of cairo_fill. + +And if you hadn't ever implemented that workaround, then you just +might get to see your stroked rectangles now get drawn 5-25x faster. + +Beyond that performance fix, there are a handful of bug fixes in this +snapshot: + + * Fix for glyph cache race condition in glitz backend (Jinghua Luo) + + * Many fixes for ATSUI text rendering (Brian Ewins) + + * Un-break recent optimization-triggered regression in rendering text + with a translation in the font matrix (Behdad Esfahbod) + + * Fix make check to work on OPD platforms (IA64 or PPC64) + (Frederic Crozat) + + * Fix a couple of character spacing issues on Windows + (Jonathan Watt) + +Have fun with that, everybody, and we'll be back for more in the new +year, (with a plan to add the last of our performance improvements in +this round, fix a few bad, lingering bugs, and then finish off a nice, +stable 1.4 release before the end of January). + +-Carl + +Snapshot 1.3.8 (2006-12-14 Carl Worth ) +========================================================== +This is the fourth development snapshot in the 1.3 series. It comes +just slightly more than one week after the 1.3.6 snapshot. + +After the bug fixes in 1.3.6, we're back to our original program of +weekly snapshots, each one faster than the one from the week +before. Cairo 1.3.8 brings a 2x improvement in the speed of rendering +linear gradients (thanks to David Turner), and a significant reduction +in X traffic when rendering text (thanks to Xan Lopez and Behdad +Esfahbod), making cairo behave very much like Xft does. + +A few other things in the 1.3.8 snapshot worth noting include a more +forgiving image comparator in the test suite, (using the "perceptual +diff" metric and GPL implementation by Hector Yee[*]), a bug fix for +broken linking on x86_64 (thanks to M Joonas Pihlaja) and an even +better implementation of _cairo_lround, (not faster, but supporting a +more complete input range), from Daniel Amelang. + +[*] http://pdiff.sourceforge.net/ + +Snapshot 1.3.6 (2006-12-06 Carl Worth ) +========================================================== +This is the third development snapshot in the 1.3 series. It comes two +weeks after the 1.3.4 snapshot. + +We don't have fancy performance charts this week as the primary +changes in this snapshot are bug fixes. The performance work continues +and the next snapshot (planned for one week from today) should include +several improvements. The bug fixes in this snapshot include: + + * Fix undesirable rounding in glyph positioning (Dan Amelang) + + This bug was noticed by several users, most commonly by seeing + improper text spacing or scrambled glyphs as drawn by nautilus. For + example: + + Update to cairo-1.3.4 worsen font rendering + https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=217819 + + * Fix reduced range of valid input coordinates to tessellator + (M Joonas Pihlaja) + + This bug was causing lots of assertion failures in mozilla as + mentioned here: + + CAIRO_BO_GUARD_BITS and coordinate space? + http://lists.freedesktop.org/archives/cairo/2006-December/008743.html + + * Fix several regressions in new tessellator (M Joonas Pihlaja) + + Joonas just had a good eye for detail here. I don't think any + external cairo users had noticed any of these bugs yet. + + * Fix compilation problems of cairo "wideint" code on some platforms + (Mathieu Lacage) + + * Fix failed configure due to broken grep (Dan Amelang) + + This bug was reported here: + + AX_C_FLOAT_WORDS_BIGENDIAN doesn't work because grep doesn't + work with binary file + https://bugs.freedesktop.org/show_bug.cgi?id=9124 + + * Remove the pkg-config minimum version requirement (Behdad Esfahbod) + + Some systems ship with pkg-config 0.15 and there was really no good + reason for cairo to insist on having version 0.19 before it would + build. + +There is also one new (but inert) feature in this snapshot. There's a +new option that can be passed to cairo's configure script: + + --disable-some-floating-point + + Disable certain code paths that rely heavily on double precision + floating-point calculation. This option can improve + performance on systems without a double precision floating-point + unit, but might degrade performance on those that do. + +As of this snapshot, this option does not make any change to cairo, +but it is possible that future versions of cairo will respect this +option and change the implementation of various functions as +appropriate. + +Snapshot 1.3.4 (2006-11-22 Carl Worth ) +========================================================== +This is the second development snapshot in the 1.3 series. It comes +one week after the 1.3.2 snapshot. + +This snapshot has a couple of significant performance improvements, +and also adds new support for producing multi-page SVG output, (when +targeting SVG 1.2)---thanks to Emmanuel Pacaud. The details of the +performance improvements are as follows: + +1. The long-awaited "new tessellator". + + The credit for this being an improvement goes to Joonas Pihlaja. He + took my really slow code and really put it through its paces to get + the dramatic performance improvement seen below (up to 38x faster + on realistic cases, and more than 10x faster for the zrusin_another + test). + + His own writeup of the work he did is quite thorough, but more than + can be quoted here. Please see his post for the interesting details: + + http://lists.freedesktop.org/archives/cairo/2006-November/008483.html + + (Though note that this snapshot also includes some additional, + significant improvements that were only sketched out in that + email---see "Generating fewer trapezoids"). + +2. More floating-point improvements + + Daniel Amelang continues to work the magic he began in the 1.3.2 + snapshot. This time he short-circuits floating-point + transformations by identity matrices and applies the earlier + floating-to-fixed-point technique to the problem of rounding. + + The improvements here will primarily benefit text performance, and + will benefit platforms without hardware floating-point more than + those that have it, (some text tests show 20% improvement on an x86 + machine and closer to 80% improvement on arm). + +The performance chart comparing 1.3.2 to 1.3.4 really speaks for +itself, (this is on an x86 laptop). This is quite a lot of progress +for one week: + + xlib-rgb stroke_similar_rgba_over-256 74.99 1.45% -> 2.03 68.38%: 36.86x speedup +███████████████████████████████████▉ + xlib-rgb stroke_similar_rgba_source-256 78.23 1.43% -> 3.30 67.05%: 23.71x speedup +██████████████████████▊ + xlib-rgba tessellate-256-100 820.42 0.15% -> 35.06 2.84%: 23.40x speedup +██████████████████████▍ +image-rgba tessellate-256-100 819.55 0.32% -> 35.04 3.56%: 23.39x speedup +██████████████████████▍ + xlib-rgb stroke_image_rgba_over-256 78.10 1.43% -> 4.33 65.56%: 18.04x speedup +█████████████████ + xlib-rgb stroke_image_rgba_source-256 80.11 1.63% -> 5.75 63.99%: 13.94x speedup +█████████████ + xlib-rgba zrusin_another_tessellate-415 89.22 0.35% -> 8.38 5.23%: 10.65x speedup +█████████▋ +image-rgba zrusin_another_tessellate-415 87.38 0.89% -> 8.37 5.22%: 10.44x speedup +█████████▍ +image-rgba zrusin_another_fill-415 117.67 1.34% -> 12.88 2.77%: 9.14x speedup +████████▏ + xlib-rgba zrusin_another_fill-415 140.52 1.57% -> 15.79 2.88%: 8.90x speedup +███████▉ +image-rgba tessellate-64-100 9.68 3.42% -> 1.42 0.60%: 6.82x speedup +█████▉ + xlib-rgba tessellate-64-100 9.78 4.35% -> 1.45 0.83%: 6.72x speedup +█████▊ + xlib-rgb stroke_linear_rgba_over-256 46.01 2.44% -> 7.74 54.51%: 5.94x speedup +█████ + xlib-rgb stroke_linear_rgba_source-256 48.09 2.15% -> 9.14 53.00%: 5.26x speedup +████▎ + xlib-rgb stroke_radial_rgba_over-256 50.96 2.34% -> 12.46 47.99%: 4.09x speedup +███▏ + xlib-rgb stroke_radial_rgba_source-256 53.06 1.57% -> 13.96 46.57%: 3.80x speedup +██▊ +image-rgba paint_similar_rgba_source-256 0.12 1.57% -> 0.08 9.92%: 1.42x speedup +▍ +image-rgba paint_image_rgba_source-256 0.12 2.49% -> 0.08 10.70%: 1.41x speedup +▍ +image-rgba world_map-800 356.28 0.46% -> 275.72 1.15%: 1.29x speedup +▎ + xlib-rgba world_map-800 456.81 0.39% -> 357.95 1.39%: 1.28x speedup +▎ +image-rgb tessellate-16-100 0.09 0.57% -> 0.07 3.43%: 1.23x speedup +▎ +image-rgba tessellate-16-100 0.09 0.06% -> 0.07 2.46%: 1.23x speedup +▎ +image-rgba text_solid_rgb_over-256 5.39 4.01% -> 4.47 0.70%: 1.21x speedup +▎ +image-rgba text_solid_rgba_over-256 5.37 0.82% -> 4.45 0.75%: 1.21x speedup +▎ +image-rgba text_image_rgb_over-64 0.78 0.10% -> 0.65 0.74%: 1.20x speedup +▎ +image-rgba text_image_rgba_over-64 0.78 0.29% -> 0.65 0.68%: 1.19x speedup +▎ +image-rgb text_solid_rgb_over-64 0.76 2.45% -> 0.63 0.81%: 1.19x speedup +▎ +image-rgba text_solid_rgba_over-64 0.76 0.33% -> 0.64 0.66%: 1.19x speedup +▎ +image-rgba text_similar_rgba_over-256 5.99 4.72% -> 5.04 1.09%: 1.19x speedup +▎ + +We should point out that there is some potential for slowdown in this +snapshot. The following are the worst slowdowns reported by the cairo +performance suite when comparing 1.3.2 to 1.3.4: + +image-rgba subimage_copy-256 0.01 0.87% -> 0.01 3.61%: 1.45x slowdown +▌ + xlib-rgb paint_solid_rgb_over-256 0.31 10.23% -> 0.38 0.33%: 1.26x slowdown +▎ +image-rgba box-outline-fill-100 0.01 0.30% -> 0.01 2.52%: 1.21x slowdown +▎ +image-rgba fill_solid_rgb_over-64 0.20 1.22% -> 0.22 1.59%: 1.12x slowdown +▏ +image-rgb fill_similar_rgb_over-64 0.21 1.04% -> 0.24 1.06%: 1.11x slowdown +▏ +image-rgba fill_image_rgb_over-64 0.21 1.19% -> 0.24 0.72%: 1.11x slowdown +▏ +image-rgba fill_similar_rgb_over-64 0.21 0.18% -> 0.24 0.30%: 1.11x slowdown +▏ +image-rgb fill_solid_rgba_over-64 0.22 1.66% -> 0.24 1.15%: 1.11x slowdown +▏ +image-rgb fill_image_rgb_over-64 0.21 0.14% -> 0.24 0.80%: 1.11x slowdown +▏ +image-rgba fill_image_rgba_over-64 0.22 1.34% -> 0.25 0.20%: 1.11x slowdown +▏ +image-rgba fill_solid_rgba_over-64 0.22 1.48% -> 0.24 0.95%: 1.11x slowdown +▏ +image-rgb fill_similar_rgba_over-64 0.22 1.13% -> 0.25 1.25%: 1.10x slowdown +▏ + +The 45% slowdown for subimage_copy is an extreme case. It's unlikely +to hit many applications unless they often use cairo_rectangle; +cairo_fill to copy a single pixel at a time. In any case, it shows a +worst-case impact of the overhead of the new tessellator. The other +slowdowns (~ 10%) are probably more realistic, and still very +concerning. + +We will work to ensure that performance regressions like these are not +present from one major release of cairo to the next, (for example, +from 1.2 to 1.4). + +But we're putting this 1.3.4 snapshot out there now, even with this +potential slowdown so that people can experiment with it. If you've +got complex geometry, we hope you will see some benefit from the new +tessellator. If you've got primarily simple geometry, we hope things +won't slowdown too much, but please let us know what slowdown you see, +if any, so we can calibrate our performance suite against real-world +impacts. + +Thanks, and have fun with cairo! + +Snapshot 1.3.2 (2006-11-14 Carl Worth ) +========================================================== +This is the first development snapshot since the 1.2 stable series +branched off shortly after the 1.2.4 release in August 2006. + +This snapshot includes all the bug fixes from the 1.2.6 release, +(since they originated here on the 1.3 branch first and were +cherry-picked over to 1.2). But more importantly, it contains some new +API in preparation for a future 1.4 release, and most importantly, it +contains several performance improvements. + +The bug fixes will not be reviewed here, as most of them are already +described in the 1.2.6 release notes. But details for the new API and +some performance improvements are included here. + +As with all snapshots, this is experimental code, and the new API +added here is still experimental and is not guaranteed to appear +unchanged in any future release of cairo. + +API additions +------------- +Several new API additions are available in this release. There is a +common theme among all the additions in that they allow cairo to +advertise information about its state that it was refusing to +volunteer earlier. So this isn't groundbreaking new functionality, but +it is essential for easily achieving several tasks. + +The new functions can be divided into three categories: + + Getting information about the current clip region + ------------------------------------------------- + cairo_clip_extents + cairo_copy_clip_rectangles + cairo_rectangle_list_destroy + + Getting information about the current dash setting + -------------------------------------------------- + cairo_get_dash_count + cairo_get_dash + + Getting information from a pattern + ---------------------------------- + cairo_pattern_get_rgba + cairo_pattern_get_surface + cairo_pattern_get_color_stop_rgba + cairo_pattern_get_color_stop_count + cairo_pattern_get_linear_points + cairo_pattern_get_radial_circles + +In each of these areas, we have new API for providing a list of +uniform values from cairo. The closest thing we had to this before was +cairo_copy_path, (which is rather unique in providing a list of +non-uniform data). + +The copy_clip_rectangles/rectangle_list_destroy functions follow a +style similar to that of cairo_copy_path. Meanwhile, the dash and +pattern color stop functions introduce a new style in which there is a +single call to return the number of elements available (get_dash_count +and get_color_stop_count) and then a function to be called once to get +each element (get_dash and get_color_stop_rgba). + +I'm interested in hearing feedback from users of these new API +functions, particularly from people writing language bindings. One +open question is whether the clip "getter" functionality should adopt +a style similar to that of the new dash and color_stop interfaces. + +API deprecation +--------------- +The CAIRO_FORMAT_RGB16_565 enum value has been deprecated. It never +worked as a format value for cairo_image_surface_create, and it wasn't +necessary for supporting 16-bit 565 X server visuals. + +XCB backend changes +------------------- +The XCB backend has been updated to track the latest XCB API (which +recently had a 1.0 release). + +New quartz backend +------------------ +Vladimir Vukicevic has written a new "native quartz" backend which +will eventually replace the current "image-surface wrapping" quartz +backend. For now, both backends are available, (the old one is +"quartz" and the new one is "nquartz"). But it is anticipated that the +new backend will replace the old one and take on the "quartz" name +before this backend is marked as supported in a release of cairo. + +New OS/2 backend +---------------- +Doodle and Peter Weilbacher have contributed a new, experimental +backend for using cairo on OS/2 systems. + +Performance improvements +------------------------ +Here are some highlights from cairo's performance suite showing +improvements from cairo 1.2.6 to cairo 1.3.2. The command used to +generate this data is: + + ./cairo-perf-diff 1.2.6 HEAD + +available in the perf/ directory of a recent checkout of cairo's +source, (the cairo-perf-diff script does require a git checkout and +will not work from a tar file---though ./cairo-perf can still be used +to generate a single report there and ./cairo-perf-diff-files can be +used to compare two reports). + +Results are described below both for an x86 laptop (with an old Radeon +video card, recent X.org build, XAA, free software drivers), as well +as for a Nokia 770. First the x86 results with comments on each, (all +times are reported in milliseconds). + +Copying subsets of an image surface to an xlib surface (much faster) +-------------------------------------------------------------------- + xlib-rgba subimage_copy-512 10.50 -> : 53.97x speedup +█████████████████████████████████████████████████████ + +Thanks to Christopher (Monty) Montgomery for this big performance +improvement. Any application which has a large image surface and is +copying small pieces of it at a time to an xlib surface, (imagine an +application that loads a single image containing all the "sprites" for +that application), will benefit from this fix. The larger the ratio of +the image surface to the portion being copied, the larger the benefit. + +Floating-point conversion (3x faster) +------------------------------------- + xlib-rgba pattern_create_radial-16 27.75 -> 3.93 : 2.94x speedup +██ +image-rgb pattern_create_radial-16 26.06 -> 3.74 : 2.90x speedup +█▉ + +Thanks to Daniel Amelang, (and others who had contributed the idea +earlier), for this nice improvement in the speed of converting +floating-point values to fixed-point. + +Text rendering (1.3 - 2x faster) +------------------------------ + xlib-rgba text_image_rgba_source-256 319.73 -> 62.40 : 2.13x speedup +█▏ +image-rgb text_solid_rgba_over-64 2.85 -> 0.88 : 1.35x speedup +▍ + +I don't think we've ever set out to improve text performance +specifically, but we did it a bit anyway. I believe the extra +improvement in the xlib backend is due to Monty's image copying fix +above, and the rest is due to the floating-point conversion speedup. + +Thin stroke improvements (1.5x faster) +--------------------------------------------- +image-rgb world_map-800 1641.09 -> 414.77 : 1.65x speedup +▋ + xlib-rgba world_map-800 1939.66 -> 529.94 : 1.52x speedup +▌ + +The most modest stuff to announce in this release is the 50% +improvement I made in the world_map case. This is in improvement that +should help basically anything that is doing strokes with many +straight line segments, (and the thinner the better, since that makes +tessellation dominate rasterization). The fixes here are to use a +custom quadrilateral tessellator rather than the generic tessellator +for straight line segments and the miter joins. + +Performance results from the Nokia 770 +-------------------------------------- + xlib-rgba subimage_copy-512 55.88 -> 2.04 : 27.34x speedup +██████████████████████████▍ + xlib-rgb text_image_rgb_over-256 1487.58 -> 294.43 : 5.05x speedup +████ +image-rgb pattern_create_radial-16 187.13 -> 91.86 : 2.04x speedup +█ + xlib-rgba world_map-800 21261.41 -> 15628.02 : 1.36x speedup +▍ + +Here we see that the subimage_copy improvement was only about half as +large as the corresponding improvement on my laptop, (27x faster +compared to 54x) and the floating-point conversion fix also was quite +as significant, (2x compared to 3x). Oddly the improvement to text +rendering performance was more than twice as good (5x compared to +2x). I don't know what the reason for that is, but I don't think it's +anything anybody should complain about. + +Release 1.2.6 (2006-11-02 Behdad Esfahbod ) +============================================================== +This is the third bug fix release in the 1.2 series, coming less than +two months after the 1.2.4 release made on August 18. + +The 1.2.4 release turned out to be a pretty solid one, except for a crasher +bug when forwarding an X connection where the client and the server have +varying byte orders, eg. from a PPC to an i686. Other than that, various +other small bugs have been fixed. + +Various improvements have been made in the testing infrastructure to prevent +false positives, and to make sure the generated cairo shared object behaves as +expected in terms of exported symbols and relocations. + +There were a total of 89 changes since 1.2.4. The following list the most +important ones: + +Common fixes +------------ +- Avoid unsigned loop control variable to eliminate infinite, + memory-scribbling loop. (#7593) +- Fix cairo_image_surface_create to report INVALID_FORMAT errors. + Previously the detected error was being lost and a nil surface was + returned that erroneously reported CAIRO_STATUS_NO_MEMORY. +- Change _cairo_color_compute_shorts to not rely on any particular + floating-point epsilon value. (#7497) +- Fix infinite-join test case (bug #8379) +- Pass correct surface to create_similar in _cairo_clip_init_deep_copy(). + +PS/PDF fixes +------------ +- Fix Type 1 embedding in PDF. +- Correct the value of /LastChar in the PDF Type 1 font dictionary. +- Improve error checking in TrueType subsetting. +- Compute right index when looking up left side bearing. (bug #8180) +- Correct an unsigned to signed conversion problem in truetype subsetting + bbox. +- Type1 subsetting: Don't put .notdef in Encoding when there are 256 glyphs. +- Add cairo version to PS header / PDF document info dictionary. +- Set CTM before path construction. + +Win32 fixes +----------- +- Get correct unhinted outlines on win32. (bug 7603) +- Make cairo as a win32 static library possible. +- Use CAIRO_FORMAT_RGB24 for BITSPIXEL==32 surfaces too. + +Build system fixes +------------------ +- Define WINVER if it's not defined. (bug 6456) +- Fix the AMD64 final link by removing SLIM from pixman. +- Misc win32 compilation fixes. +- Add Sun Pro C definition of pixman_private. +- Use pixman_private consistently as prefix not suffix. +- Added three tests check-plt.sh, check-def.sh, and check-header.sh that check + that the shared object, the .def file, and the public headers agree about + the exported symbols. +- Require pkg-config 0.19. (#8686) + + +Release 1.2.4 (2006-08-18 Carl Worth ) +========================================================= +This is the second bug fix release in the 1.2 series, coming less than +two weeks after the 1.2.2 release made on August 8. + +The big motivation for a quick release was that there were a log of +build system snags that people ran into with the 1.2.2 release. But, +by the time we got those all done, we found that we had a bunch of +fixes for cairo's rendering as well. So there's a lot of goodness in +here for such a short time period. + +Rendering fixes +--------------- +Fix image surfaces to not be clipped when used as a source (Vladimir Vukicevic) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=72e25648c4c4bc82ddd938aa4e05887a293f0d8b + +Fix a couple of corner cases in dashing degenerate paths (Jeff Muizelaar) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=fbb1758ba8384650157b2bbbc93d161b0c2a05f0 + +Fix support for type1 fonts on win32 (Adrian Johnson) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=da1019c9138695cb838a54f8b871bbfd0e8996d7 + +Fix assertion failure when rotating bitmap fonts (Carl Worth) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=0bfa6d4f33b8ddb5dc55bbe419c15df4af856ff9 + +Fix assertion failure when calling cairo_text_path with bitmap fonts (Carl Worth) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=9878a033531e6b96b5f27e69e10e90dee7440cd9 + +Fix mis-handling of cairo_close_path in some situations (Tim Rowley, Carl Worth) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=53f74e59faf1af78f2f0741ccf1f23aa5dad4efc + +Respect font_matrix translation in _cairo_gstate_glyph_path (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=f183b835b111d23e838889178aa8106ec84663b3 + +Fix vertical metrics adjustment to work with non-identity shapes (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=b7bc263842a798d657a95e539e1693372448837f + +[PS] Set correct ImageMatrix in _cairo_ps_surface_emit_bitmap_glyph_data (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=d47388ad759b0a1a0869655a87d9b5eb6ae2445d + +Build system fixes +------------------ +Fix xlib detection to prefer pkg-config to avoid false libXt dependency (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=0e78e7144353703cbd28aae6a67cd9ca261f1d68 + +Fix typos causing win32 build problem with PS,PDF, and SVG backends (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=aea83b908d020e26732753830bb3056e6702a774 + +Fix configure cache to not use stale results (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=6d0e3260444a2d5b6fb0cb223ac79f1c0e7b3a6e + +Fix to not pass unsupported warning options to the compiler (Jens Granseuer) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=97524a8fdb899de1ae4a3e920fb7bda6d76c5571 + +Fix to allow env. variables such as png_REQUIRES to override configure detection (Jens Granseuer) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=abd16e47d6331bd3811c908e524b4dcb6bd23bf0 + +Fix test suite to not use an old system cairo when converting svg2png (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=6122cc85c8f71b1ba2df3ab86907768edebe1781 + +Fix test suite to not require signal.h to be present (Behdad Esfahbod) +http://gitweb.freedesktop.org/?p=cairo;a=commit;h=6f8cf53b1e1ccdbe1ab6a275656b19c6e5120e40 + +Code cleanups +------------- +Many useful warnings cleanups from sparse, valgrind, and careful eyes +(Kjartan Maraas, Pavel Roskin) + +Release 1.2.2 (2006-08-08 Carl Worth ) +========================================================= +This is the first bug fix release in the 1.2 series since the original +1.2.0 release made six weeks ago. + +There were some very serious bugs in the 1.2.0 release, (see below), +so everybody is encouraged to upgrade from 1.2.0 to 1.2.2. The 1.2.2 +release maintains source and binary compatibility with 1.2.0 and does +not make any API additions. + +Fix crashes with BGR X servers +------------------------------ +With cairo 1.2.0 many people reported problems with all cairo-using +programs, (including all GTK+ programs with GTK+ >= 2.8) immediately +crashing with a complaint about an unsupported image format. This bug +affected X servers that do not provide the Render extension and that +provide a visual with BGR rather than RGB channel order. + +report: https://bugs.freedesktop.org/show_bug.cgi?id=7294 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=9ae66174e774b57f16ad791452ed44efc2770a59 + +Fix the "disappearing text" bug +------------------------------- +With cairo 1.2.0 many people reported that text would disappear from +applications, sometimes reappearing with mouse motion or +selection. The text would disappear after the first space in a string +of text. This bug was caused by an underlying bug in (very common) X +servers, and only affected text rendered without antialiasing, (either +a bitmap font or a vector font with antialiasing disabled). The bug +was also exacerbated by a KDE migration bug that caused antialiasing +to be disabled more than desired. + +report: https://bugs.freedesktop.org/show_bug.cgi?id=7494 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=456cdb3058f3b416109a9600167cd8842300ae14 +see also: +Xorg: https://bugs.freedesktop.org/show_bug.cgi?id=7681 +KDE: http://qa.mandriva.com/show_bug.cgi?id=23990 + +Fix broken image fallback scaling (aka. "broken printing") +---------------------------------------------------------- +The various "print" backends, (pdf, ps, and svg), sometimes fallback +to using image-based rendering for some operations. In cairo 1.2.0 +these image fallbacks were scaled improperly. Applications using cairo +can influence the resolution of the image fallbacks with +cairo_surface_set_fallback_resolution. With the bug, any value other +than 72.0 would lead to incorrect results, (larger values would lead +to increasingly shrunken output). + +report: https://bugs.freedesktop.org/show_bug.cgi?id=7533 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=1feb4291cf7813494355459bb547eec604c54ffb + +Fix inadvertent semantic change of font matrix translation (Behdad Esfahbod) +---------------------------------------------------------------------------- +The 1.2.0 release introduced an inadvertent change to how the +translation components of a font matrix are interpreted. In the 1.0 +series, font matrix translation could be used to offset the glyph +origin, (though glyph metrics were reported incorrectly in +1.0). However in 1.2.0, the translation was applied to the advance +values between each glyph. The 1.2.0 behavior is fairly useless in +practice, and it was not intentional to introduce a semantic +change. With 1.2.2 we return to the 1.0 semantics, with a much better +implementation that provides correct glyph metrics. + +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=84840e6bba6e72aa88fad7a0ee929e8955ba9051 + +Fix create_similar to preserve fallback resolution and font options (Behdad Esfahbod) +------------------------------------------------------------------------------------- +There has been a long-standing issue with cairo_surface_create_similar +such that font options and other settings from the original +destination surface would not be preserved to the intermediate +"similar" surface. This could result in incorrect rendering +(particularly with respect to text hinting/antialiasing) with +fallbacks, for example. + +report: https://bugs.freedesktop.org/show_bug.cgi?id=4106 +fixes: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=9fcb3c32c1f16fe6ab913e27eb54d18b7d9a06b0 + http://gitweb.freedesktop.org/?p=cairo;a=commit;h=bdb4e1edadb78a2118ff70b28163f8bd4317f1ec + +xlib: Fix text performance regression from 1.0 to 1.2.0 (Vladimir Vukicevic) +---------------------------------------------------------------------------- +Several people noticed that upgrading from cairo 1.0 to cairo 1.2.0 +caused a significant performance regression when using the xlib +backend. This performance regression was particularly noticeable when +doing lots of text rendering and when using a high-latency connection +to the X server, (such as a remote X server over an ssh +connection). The slowdown was identified and fixed in 1.2.2. + +report: https://bugs.freedesktop.org/show_bug.cgi?id=7514 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=b7191885c88068dad57d68ced69a752d1162b12c + +PDF: Eliminate dependency on FreeType library dependency (Adrian Johnson) +------------------------------------------------------------------------- +The cairo 1.2 series adds a supported pdf backend to cairo. In cairo +1.2.0 this backend required the freetype library, which was an +undesirable dependency on systems such as win32, (cairo is designed to +always prefer the "native" font system). As of cairo 1.2.2 the +freetype library is not required to use the pdf backend on the win32 +platform. + +report: https://bugs.freedesktop.org/show_bug.cgi?id=7538 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=a0989f427be87c60415963dd6822b3c5c3781691 + +PDF: Fix broken output on amd64 (Adrian Johnson) +------------------------------------------------ +report: http://bugzilla.gnome.org/show_bug.cgi?id=349826 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=f4b12e497b7ac282b2f6831b8fb68deebc412e60 + +PS: Fix broken output for truetype fonts > 64k (Adrian Johnson) +--------------------------------------------------------------- +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=067d97eb1793a6b0d0dddfbd0b54117844511a94 + +PDF: Fix so that dashing doesn't get stuck on (Kent Worsnop) +------------------------------------------------------------ +Kent notices that with the PDF backend in cairo 1.2.0 as soon as a +stroke was performed with dashing, all subsequent strokes would also +be dashed. There was no way to turn dashing off again. + +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=778c4730a86296bf0a71080cf7008d7291792256 + +Fix memory leaks in failure paths in gradient creation (Alfred Peng) +-------------------------------------------------------------------- +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=db06681b487873788b51a6766894fc619eb8d8f2 + +Fix memory leak in _cairo_surface_show_glyphs (Chris Wilson) +------------------------------------------------------------ +report: https://bugs.freedesktop.org/show_bug.cgi?id=7766 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=e2fddcccb43d06486d3680a19cfdd5a54963fcbd + +Solaris: Add definition of cairo_private for some Sun compilers (Alfred Peng) +----------------------------------------------------------------------------- +report: https://bugzilla.mozilla.org/show_bug.cgi?id=341874 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=04757a3aa8deeff3265719ebe01b021638990ec6 + +Solaris: Change version number of Sun's Xorg server with buggy repeat (Brian Cameron) +------------------------------------------------------------------------------------- +report: https://bugs.freedesktop.org/show_bug.cgi?id=7483 +fix: http://gitweb.freedesktop.org/?p=cairo;a=commit;h=e0ad1aa995bcec4246c0b8ab0d5a5a79871ce235 + +Various memory leak fixes +------------------------- +Fix memory leak in _cairo_surface_show_glyphs (bug 7766) +Fix file handle leak in failure path (bug 7616) +Fix some memory leaks in the test cases. +Fix some memory leaks in font subsetting code used in print backends. + +Documentation improvements (Behdad Esfahbod) +-------------------------------------------- +Added new documentation for several functions (cairo_show_page, +cairo_copy_page, cairo_in_stroke, cairo_in_fill). + +Fixed some syntax errors that were preventing some existing +documentation from being published. + +Fixed several minor typographical errors. + +Added an index for new symbols in 1.2. + +Release 1.2.0 (2006-06-27 Carl Worth ) +========================================================= +This is the culmination of the work that has gone on within the 1.1 +branch of cairo. + +There has been one API addition since the cairo 1.1.10 snapshot: + + cairo_xlib_surface_get_width + cairo_xlib_surface_get_height + +There's also a new feature without any API change: + + Dots can now be drawn by using CAIRO_LINE_CAP_ROUND with + degenerate sub-paths, (cairo_move_to() followed by either + cairo_close_path() or a cairo_line_to() to the same location). + +And at least the following bugs have been fixed: + + 6759 fontconfig option AntiAlias doesn't work in cairo 1.1.2 + 6955 Some characters aren't displayed when using xlib (cache u... + 7268 positive device_offset values don't work as source + * PDF emit_glyph function needs to support bitmapped glyphs + * PS emit_glyph function needs to support bitmapped glyphs + * SVG emit_glyph function needs to support bitmapped glyphs + * PDF: minefield page one is falling back unnecessarily + * PS/PDF: Fix broken placement for vertical glyphs + * PS: Fix to not draw BUTT-capped zero-length dash segments + * Do device offset before float->fixed conversion + http://bugzilla.gnome.org/show_bug.cgi?id=332266 + * PS: Fix source surfaces with transformations + * PS: Fix to not draw BUTT-capped degnerate sub-paths + * PS: Don't walk off end of array when printing "~>" + * Fix some memory leaks in the test suite rig + * SVG: Fix memory leak when using cairo_mask + * Fix EXTEND_REFLECT and EXTEND_PAD to not crash (though these are + still not yet fully implemented for surface patterns). + +This has been a tremendous effort by everyone, and I'm proud to have +been a part of it. Congratulations to all contributors to cairo! + +Snapshot 1.1.10 (2006-06-16 Carl Worth ) +=========================================================== +This is the fifth in a series of snapshots working toward the 1.2 +release of cairo. + +The primary motivation for this snapshot is to fix a long-standing bug +that had long been silent, but as of the 1.1.8 snapshot started +causing crashes when run against 16-bit depth X servers, (often Xvnc +or Xnest). The fix for this adds a new CAIRO_FORMAT_RGB16_565 to the +API. + +This snapshot also includes a rewrite of cairo's SVG backend to +eliminate the dependency on libxml2. With this in place, cairo 1.2 +will not depend on any libraries that cairo 1.0 did not. + +As usual, there are also a few fixes for minor bugs. + +Snapshot 1.1.8 (2006-06-14 Carl Worth ) +========================================================== +This is the fourth in a series of snapshots working toward the 1.2 +release of cairo. At this point, all major features of the 1.2 release +are in place, leaving just a few bug fixes left. + +In particular, there well be no additional API changes between this +1.1.8 snapshot and the 1.2 release. + +The announcement for 1.1.6 mentioned several API changes being +considered. Only one of these changes was actually implemented +(set_dpi -> fallback_resolution). This change does introduce one +source-level incompatibility with respect to previous 1.1.x snapshots, +so see below for details. + +Here is an abbreviated summary of changes since the 1.1.6 snapshot: + +** API Change ** +---------------- +According to the plan mentioned in the 1.1.6 notes, one source-level +incompatible change has been implemented. The following three +functions have been removed from cairo's API: + + cairo_pdf_surface_set_dpi + cairo_ps_surface_set_dpi + cairo_svg_surface_set_dpi + +and in their place the following function has been added: + + cairo_surface_set_fallback_resolution + +The signature and semantics of the function remains the same, so it is +a simple matter of changing the name of the function when calling +it. As a transition mechanism, this snapshot will (on many systems) +build to include the old symbols so that code previously compiled will +still run. However, all source code using the old names must be +updated before it will compile. And the upcoming 1.2 release is not +anticipated to include the old symbols. + +Finally, it should be pointed out that the old symbols never existed +in the supported API of any stable release of cairo. (In the stable +1.0 releases the PDF, PS, and SVG backends were advertised as +experimental and unstable.) + +And, as always, cairo continues to maintain source and binary +compatibility between major releases. So applications compiled against +supported backends in a stable release of cairo (1.0.4 say) will +continue to compile and run without modification against new major +releases (1.2.0 say) without modification. + +API additions +------------- +The following new functions have been added to cairo's API: + + cairo_surface_get_content + cairo_debug_reset_static_data + cairo_image_surface_get_data + cairo_image_surface_get_format + cairo_image_surface_get_stride + cairo_win32_font_face_create_for_hfont + +New, backend-specific pkg-config files +-------------------------------------- +In addition to the original cairo.pc file, cairo will also now install +a pkg-config files for each configured backend, (for example +cairo-pdf.pc, cairo-svg.pc, cairo-xlib.pc, cairo-win32.pc, etc.) this +also includes optional font backends (such as cairo-ft.pc) and the +optional png functionality (cairo-png.pc). + +These new pkg-config files should be very convenient for allowing +cairo-using code to easily check for the existing of optional +functionality in cairo without having to write complex rules to grub +through cairo header files or the compiled library looking for +symbols. + +Printing backend (PS, PDF, and SVG) +----------------------------------- +Improving the quality of the "printing" backends has been a priority +of the development between cairo 1.1.6 and cairo 1.1.8. + +The big improvement here is in the area of text output. Previously, at +best, text was output as paths without taking advantage of any font +support available in the output file format. + +Now, at the minimum text paths will be shared by using type3 fonts +(for PS and PDF---and similarly, defs for SVG). Also, if possible, +type3 and truetype fonts will be embedded in PostScript and PDF +output. There are still some known bugs with this, (for example, +selecting text in a cairo-generated PDF file with an embedded truetype +font does not work). So there will be some more changes in this area +before cairo 1.2, but do try test this feature out as it exists so +far. + +Many thanks to Kristian Høgsberg for the truetype and type1 font +embedding. + +win32 backend +------------- +Performance improvements by preferring GDI over pixman rendering when possible. +Fixes for text rendering. + +xlib backend +------------ +Fix potentially big performance bug by making xlib's create_similar +try harder to create a pixmap of a depth matching that of the screen. + +Bug fixes +--------- +Among various other fixes, the following bugs listed in bugzilla have +been fixed: + + Bug 2488: Patch to fix pixman samping location bug (#2488). + https://bugs.freedesktop.org/show_bug.cgi?id=2488 + + Bug 4196: undef MIN an MAX before defining to avoid duplicate definition + https://bugs.freedesktop.org/show_bug.cgi?id=4196 + + Bug 4723: configure.in: Fix m4 quoting when examining pkg-config version + https://bugs.freedesktop.org/show_bug.cgi?id=4723 + + Bug 4882: Flag Sun's X server has having buggy_repeat. + https://bugs.freedesktop.org/show_bug.cgi?id=4882 + + Bug 5306: test/pdf2png: Add missing include of stdio.h + https://bugs.freedesktop.org/show_bug.cgi?id=5306 + + Bug 7075: Fix make clean to remove cairo.def + https://bugs.freedesktop.org/show_bug.cgi?id=7075 + +(Many thanks to Behdad Esfahbod for helping us track down and fix many +of these.) + +Snapshot 1.1.6 (2006-05-04 Carl Worth ) +========================================================== +This is the third in a series of snapshots working toward the imminent +1.2 release of cairo. For a list of items still needing work on the +cairo 1.2 roadmap, please see: + + http://cairographics.org/ROADMAP + +As can be seen in that list, there are no longer any API additions +left on the roadmap. Instead, there is a feature (PDF type 3 fonts) a +performance optimization (X server gradients) and a list of bug +fixes. This gives us a fair amount of freedom to cut the 1.2 release +at almost any point by deciding to defer remaining bug fixes to +subsequent maintenance releases such as 1.2.2 and 1.2.4. + +Before we will do that, we must first be wiling to commit to all the +new API additions. As a heads-up, there are a couple of potential API +changes being considered. (Note that these are changes to new API +introduced during 1.1 so these will not introduce API +incompatibilities compared to the stable 1.0 series). The changes +being considered are: + + cairo_get_group_target: may acquire x and y offset return + parameters. May also be eliminated in favor of + cairo_get_target assuming its role + + cairo_pdf_surface_set_dpi: + cairo_ps_surface_set_dpi: + cairo_svg_surface_set_dpi: These functions may be removed in favor + of a new cairo_surface_set_fallback_resolution + +Additionally there is the possibility of a slight change in the +semantics of cairo_set_line_width. We believe the current behavior of the sequence: + + cairo_set_line_width; ... change CTM ...; cairo_stroke; + +is buggy. It is currently behaving the same as: + + ... change CTM ...; cairo_set_line_width; cairo_stroke; + +We are considering fixing this bug before 1.2 with the hope that +nobody is already relying on the buggy behavior described here. Do +shout if you suspect you might be in that position. + +The items included in this snapshot (since the 1.1.4 snapshot) are +described below. + +API additions +------------- +The long-awaited group-rendering support is now available with the +following function calls: + + cairo_push_group + cairo_push_group_with_content + cairo_pop_group + cairo_pop_group_to_source + cairo_get_group_target + +This API provides a much more convenient mechanism for doing rendering +to an intermediate surface without the need to manually create a +temporary cairo_surface_t and a temporary cairo_t and clean them up +afterwards. + +Add the following missing get function to complement +cairo_surface_set_device_offset: + + cairo_surface_get_device_offset + +PDF backend (API addition) +-------------------------- +The PDF backend now provides for per-page size changes, (similar to +what the PostScript backend got in the 1.1.4 snapshot). The new API +is: + + cairo_pdf_surface_set_size + +Xlib backend (API additions) +---------------------------- +The following functions have been added to allow the extraction of +Xlib surface: + + cairo_xlib_surface_get_display + cairo_xlib_surface_get_drawable + cairo_xlib_surface_get_screen + cairo_xlib_surface_get_visual + cairo_xlib_surface_get_depth + +XCB backend (experimental) +-------------------------- +Update backend so that it now compiles with the recent XCB 0.9 release. + +Bug fixes and memory leak cleanup +--------------------------------- +Various little things, nothing too significant though. + +Snapshot 1.1.4 (2006-05-03 Carl Worth ) +========================================================== +This is the second in a series of snapshots working toward the +upcoming 1.2 release of cairo. For a list of items still needing work +on the cairo 1.2 roadmap, please see: + + http://cairographics.org/ROADMAP + +The items included in this snapshot (since the 1.1.2 snapshot) are +described below. + +PostScript backend: new printing-oriented API +--------------------------------------------- +We anticipate that with cairo 1.2, toolkits will begin to use cairo +for printing on systems that use PostScript as the spool format. To +support this use case, we have added 4 new function calls that are +specific to the PostScript backend: + + cairo_ps_surface_set_size + cairo_ps_surface_dsc_comment + cairo_ps_surface_dsc_begin_setup + cairo_ps_surface_dsc_begin_page_setup + +These functions allow variation of the page size/orientation from one +page to the next in the PostScript output. They also allow the toolkit +to provide per-document and per-page printer control options in a +device-independent way, (for example, by using PPD options and +emitting them as DSC comments into the PostScript output). This should +allow toolkits to provide very fine-grained control of many options +available in printers, (media size, media type, tray selection, etc.). + +SVG backend: builds by default, version control +----------------------------------------------- +The SVG backend continues to see major improvements. It is expected +that the SVG backend will be a supported backend in the 1.2 +release. This backend will now be built by default if its dependencies +(freetype and libxml2) are met. + +Additionally, the SVG backend now has flexibility with regard to what +version of SVG it targets. It will target SVG 1.1 by default, which +will require image fallbacks for some of the "fancier" cairo +compositing operators. Or with the following new function calls: + + cairo_svg_surface_restrict_to_version + cairo_svg_get_versions + cairo_svg_version_to_string + +it can be made to target SVG 1.2 in which there is native support for +these compositing operators. + +Bug fixes +--------- +At least the following bugs have been fixed since the 1.1.2 snapshot: + +crash at XRenderAddGlyphs +https://bugs.freedesktop.org/show_bug.cgi?id=4705 + +Can't build cairo-1.1.2 on opensolaris due to " void function cannot return value" +https://bugs.freedesktop.org/show_bug.cgi?id=6792 + +Missing out-of-memory check at gfx/cairo/cairo/src/cairo-atsui-font.c:185 +https://bugzilla.mozilla.org/show_bug.cgi?id=336129 + +A couple of memory leaks. + +Snapshot 1.1.2 (2006-04-25 Carl Worth ) +========================================================== +This is the first in a series of snapshots working toward the upcoming +1.2 release of cairo. (Subsequent snapshot will use successive even +numbers for the third digit, 1.1.4, 1.1.6, etc.) This snapshot is +backwards-compatible with the 1.0 series---it makes a few API +additions but does not remove any API. + +PostScript and PDF backends are no longer "experimental" +-------------------------------------------------------- +The major theme of the 1.2 release is improved PostScript and PDF +backends for cairo. Unlike the 1.0 series, in the 1.2 series these +backends will not be marked as experimental and will be enabled by +default. We encourage people to test this snapshot and the PS/PDF +backends in particular as much as possible. + +The PostScript and PDF output is not yet ideal. + + * One major problem with the PostScript output is that image + fallbacks are used more often than strictly necessary, and the + image fallbacks are at a lower resolution than desired, (the + cairo_ps_surface_set_dpi call is ignored). + + * The major drawback of the current PDF backend implementation is + its text support. Every glyph is represented by a filled path in + the PDF file. The causes file sizes to be much larger and + rendering to be much slower than desired. + +It is anticipated that both of these shortcomings will see some +improvements before the final 1.2 release. + +In spite of those shortcomings, we hope that the PS and PDF backends +will yield faithful results for pretty much any cairo operations you +can throw at them. Please let us know if you are getting obviously +"different" results from the PS/PDF backends than from the image or +xlib backends. + +Other new experimental backends +------------------------------- +This snapshot includes three new backends that did not exist in the +1.0 series: + + * beos backend + + * directfb backend + + * svg backend + +These are all currently marked "experimental" and are disabled by +default. But the SVG backend in particular has seen a lot of recent +development and is very close to passing the entire cairo test +suite. It is possible that this backend will become a fully supported +backend by the time of the cairo 1.2 release. + +Public API additions +-------------------- +There have been a few new API functions added to cairo, including: + +New get_type functions for querying sub-types of object: + + cairo_surface_get_type + cairo_pattern_get_type + cairo_font_face_get_type + cairo_scaled_font_get_type + +More convenience in working with cairo_scaled_font_t with new getter +functions: + + cairo_scaled_font_get_font_face + cairo_scaled_font_get_font_matrix + cairo_scaled_font_get_ctm + cairo_scaled_font_get_font_options + +As well as a convenience function for setting a scaled font into a +cairo context: + + cairo_set_scaled_font + +and a function to allow text extents to be queried directly from a +scaled font, (without requiring a cairo_surface_t or a cairo_t): + + cairo_scaled_font_text_extents + +These new scaled font functions were motivated by the needs of the +pango library. + +Finally, a new path-construction function was added which clears the +current point in preparation for a new sub path. This makes cairo_arc +easier to use in some situations: + + cairo_new_sub_path + +Before the 1.2 release is final we do still plan a few more API +additions specifically motivated by the needs of Mozilla/Firefox. + +Optimizations and bug fixes +--------------------------- +Shortly after the 1.0 maintenance series branched off the mainline +there was a major rework of the cairo font internals. This should +provide some good performance benefits, but it's also another area +people should look at closely for potential regressions. + +There has not yet been any widespread, systematic optimization of +cairo, but various performance improvements have been made, (and some +of them are fairly significant). So if some things seem faster than +1.0 then things are good. If there are any performance regressions +compared to 1.0 then there is a real problem and we would like to hear +about that. + +There has been a huge number of bug fixes---too many to mention in +detail. Again, things should be better, and never worse compared to +1.0. Please let us know if your testing shows otherwise. + +Release 1.0.2 (2005-10-03 Carl Worth ) +========================================================= +For each bug number XXXX below, see: + + https://bugs.freedesktop.org/show_bug.cgi?id=XXXX + +for more details. + +General bug fixes +----------------- + * 4408 - Add support for dashing of stroked curves + (Carl Worth) + + * 4409 - Fix dashing so that each dash is capped on both ends + (Carl Worth) + + * 4414 - Prevent SIGILL failures (proper use of -mmmx and -msse flags) + (Sebastien Bacher, Billy Biggs) + + * 4299 - Fix crashes with text display in multi-threaded program + (Alexey Shabalin, Carl Worth) + + * 4401 - Do not use sincos function since it is buggy on some platforms) + (Tim Mooney, Carl Worth) + + * 4245 - Fix several bugs in the test suite exposed by amd64 systems + (Seemant Kulleen, Carl Worth) + + * 4321 - Add missing byteswapping on GetImage/PutImage + (Sjoerd Simons, Owen Taylor) + + * 4220 - Make the check for rectangular trapezoids simpler and more accurate + (Richard Stellingwerff, Owen Taylor) + + * 4260 - Add missing channel-order swapping for antialised fonts + (Barbie LeVile, Owen Taylor) + + * 4283 - Fix compilation failure with aggressive inlining (gcc -O3) + (Marco Manfredini, Owen Taylor) + + * 4208 - Fix some warnings from sparse + (Kjartan Maraas, Billy Biggs) + + * 4269 - Fix to not crash when compiled with -fomit-frame-pointer + (Ronald Wahl, Owen Taylor) + + * 4263 - Improve performance for vertical gradients + (Richard Stellingwerff, Owen Taylor) + + * 4231 + * 4298 - Accommodate gentoo and Mandriva versions in X server vendor string check + (Billy Biggs, Frederic Crozat, Owen Taylor) + +win32-specific fixes +-------------------- + * 4599 - Fix "missing wedges" on some stroked paths (win32) + (Tim Rowley, Jonathan Watt, Bertram Felgenhauer, Carl Worth, Keith Packard) + + * 4612 - Fix disappearing text if first character out of surface (win32) + (Tim Rowley) + + * 4602 - Fix shutdown of cairo from failing intermediate, size-0 bitmaps (win32) + Aka. the "white rectangles" bug from mozilla-svg testing + (Tim Rowley) + + * Various portability improvements for win32 + (Hans Breuer, Owen Taylor, Carl Worth) + + * 4593 - Fix font sizes to match user expectations (win32) + (Tor Lillqvist, Owen Taylor) + + * 3927 - Fix to report metrics of size 0 for glyph-not-available (win32) + (Hans Breuer, Owen Taylor, Tor Lillqvist) + + * Add locking primitives for win32 + (Hans Breuer) + +xlib-specific fixes +------------------- + * Fix crash from size-0 pixmap due to empty clip region (xlib) + (Radek Doulík, Carl Worth) + +Release 1.0.0 (2005-08-24 Carl Worth ) +========================================================= +Experimental backends +--------------------- + * The Glitz, PS, PDF, Quartz, and XCB backends have been declared + experimental, and are not part of the API guarantees that accompany + this release. They are not built by default, even when the required + libraries are available, and must be enabled explicitly with + --enable-ps, --enable-pdf, --enable-quartz or --enable-xcb. + + It is very painful for us to be pushing out a major release without + these backends enabled. There has been a tremendous amount of work + put into each one and all are quite functional to some + extent. However, each also has some limitations. And none of these + backends have been tested to the level of completeness and + correctness that we expect from cairo backends. + + We do encourage people to experiment with these backends and report + success, failure, or means of improving them. + +Operator behavior +----------------- + * Prior to 0.9.0 the SOURCE, CLEAR and a number of other operators + behaved in an inconsistent and buggy fashion and could affect areas + outside the clip mask. In 0.9.0, these six "unbounded" operators + were fixed to consistently clear areas outside the shape but within + the clip mask. This is useful behavior for an operator such as IN, + but not what was expected for SOURCE and CLEAR. So, in this release + the behavior of SOURCE and CLEAR has been changed again. They now + affect areas only within both the source and shape. We can write + the new operators as: + + SOURCE: dest' = (mask IN clip) ? source : dest + CLEAR: dest' = (mask IN clip) ? 0 : dest + +Behavior and API changes +------------------------ + * Setting the filter on a gradient pattern would change the + interpolation between color stops away from the normal linear + interpolation. This dubious behavior has been removed. + + * The CAIRO_CONTENT_VALID() and CAIRO_FORMAT_VALID() macros -- + implementation details that leaked into cairo.h -- have been moved + into an internal header. + + * The cairo_show_text function now advances the current point + according to the total advance values of the string. + +API additions +------------- + * cairo_set_dash can now detect error and can set + CAIRO_STATUS_INVALID_DASH. + +Features +-------- + * When compiled against recent versions of fontconfig and FreeType, + artificial bold fonts can now be turned on from fonts.conf using + the FC_EMBOLDEN fontconfig key. + +Optimization +------------ + * The compositing code from the 'xserver' code tree has now been + completely merged into libpixman. This includes MMX optimization of + common operations. + + * The image transformation code in libpixman has been improved and + now performs significantly faster. + +Bug fixes +--------- + * Several crashes related to corruption in the font caches have been + fixed. + + * All test cases now match pixel-for-pixel on x86 and PPC; this + required fixing bugs in the compositing, stroking, and pattern + rendering code. + + * Negative dash offsets have been fixed to work correctly. + + * The stroking of paths with mutiple subpaths has now been fixed to + apply caps to all subpaths rather than just the last one. + + * Many build fixes for better portability on various systems. + + * Lots of other bug fixes, but we're too tired to describe them in + more detail here. + +Release 0.9.2 (2005-08-13 Carl Worth ) +========================================================= +Release numbering +----------------- + * You will notice that this release jumped from 0.9.0 to 0.9.2. We've + decided to use an odd micro version number (eg. 0.9.1) to indicate + in-progress development between releases. As soon as 0.9.2 is + tagged, the version will be incremented in CVS to 0.9.3 where it + will stay until just before 0.9.4 is built, uploaded, and tagged. + + So, even-micro == a released version, odd-micro == something in-between. + +Libpixman dependency dropped +---------------------------- + * As of this release, the dependency on an external libpixman has + been dropped. Instead, the code from libpixman needed for cairo has + been incorporated into the cairo source tree. The motivation for + this change is that while cairo's API is stable and ready to be + maintained after the 1.0 release, libpixman's API is not, so we do + not want to expose it at this time. + + Also, the incorporation of libpixman into cairo also renames all + previously-public libpixman symbols in order to avoid any conflict + with a future release of libpixman + +API additions +------------- + * Macros and functions have been added so that the version of cairo + can be queried at either compile-time or at run-time. The version + is made available as both a human-readable string and as a single + integer: + + CAIRO_VERSION_STRING eg. "0.9.2" + CAIRO_VERSION eg. 000902 + + const char* + cairo_version_string (void); /* eg. "0.9.2" */ + + int + cairo_version (void); /* eg. 000902 */ + + A macro is provided to convert a three-part component version into + the encoded single-integer form: + + CAIRO_VERSION_ENCODE(X,Y,Z) + + For example, the CAIRO_VERSION value of 000902 is obtained as + CAIRO_VERSION_ENCODE(0,9,2). The intent is to make version + comparisons easy, either at compile-time: + + #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(0,9,2) + ... + #endif + + Or at run-time: + + if (cairo_version() >= CAIRO_VERSION_ENCODE(0,9,2)) { /* ... */ } + +Thread safety +------------- + * This release adds pthread-based locking (when available) to make + the caches used by cairo safe for threaded programs. Some may + remember a failed experiment with this locking between the 0.5.1 + and 0.5.2 snapshots, (where even single-threaded programs that + linked with -lpthread would deadlock). We believe that that problem + has been fixed, so we are looking forward to testing and reports + from users with threaded applications. + +Bug fixes +--------- + * The XCB and Quartz backends failed to compiled in the 0.9.0 release + due to minor syntax errors. These have now been fixed. + + * Various crashes in glitz and pixman due to size 0 glyphs have been + fixed. + +Release 0.9.0 (2005-08-08 Carl Worth ) +========================================================= +Soname change +------------- + * In all prior snapshots, the libtool library versioning was set to + 1:0:0. As this release is intended to mark the beginning of + backwards-compatible releases, the versioning has been incremented + to 2:0:0. You will notice that the numeric extension on the + installed library filename will change similarly. + + This change will also require all cairo-using applications to be + recompiled. We recognize that this may cause some frustration since + this release is backwards-compatible with 0.6.0 and in that sense + "shouldn't" require re-compilation. However, since all historical + snapshots have used the same 1:0:0 version in spite of incompatible + API changes between them, it was essential that the upcoming 1.0 + release series have distinct library versioning. + + All future releases will use the library versioning to properly + indicate compatibility between releases. So, any application + re-compiled now to work with the 0.9.0 will not need to be + recompiled when a compatible 1.0 release of cairo is made in the + future. + +API additions +------------- + * Add new function calls to set/get the current antialiasing mode in + the graphics state: + + cairo_set_antialias + cairo_get_antialias + + This call accepts the same modes recently added for font options + (NONE or GRAY) but affects the rendering of geometry other than + text. The intent of this call is to enable more precise control of + which pixels are affected by each operation, for example to allow + for full-scene antialiasing for seam-free rendering. It is not + expected that non-antialiased rendering will perform better than + anti-aliased rendering. + + * Three new functions were added to provide support for mixed cairo- + and non-cairo drawing to the same surface: + + cairo_surface_mark_dirty + cairo_surface_mark_dirty_rectangle + cairo_surface_flush + + * The return type of the several "reference" functions was change, + (API compatibly), from void to the same type as the argument. The + affected functions are: + + cairo_font_face_reference + cairo_scaled_font_reference + cairo_pattern_reference + cairo_surface_reference + cairo_reference + + This allows a convenient way to assign and reference in a single + statement. + +Semantic changes +---------------- + * The behavior of cairo_set_source with a pattern with a non-identity + matrix was previously not well-defined. The new behavior is as + follows: + + The pattern's transformation matrix will be locked to the + user space in effect at the time of cairo_set_source(). This means + that further modifications of the CTM will not affect the source + pattern. + +cairo-win32 +----------- + * Some portability improvements, (eg. workaround for missing stdint.h). + +cairo-ft +-------- + * Updated to allow compilation with older versions of freetype. + +Bug fixes +--------- + * Fix the unbounded operators to actually produce a correct result, + (previously the results were artificially restricted to the + bounding box of whatever shape was being drawn rather than + extending out infinitely). The fixed operators are: + + CAIRO_OPERATOR_CLEAR + CAIRO_OPERATOR_SOURCE + CAIRO_OPERATOR_OUT + CAIRO_OPERATOR_IN + CAIRO_OPERATOR_DEST_IN + CAIRO_OPERATOR_DEST_ATOP + + * Fix cairo_mask and cairo_mask_surface to transform the mask by the + current transformation matrix (CTM). + + * Fix cairo_set_source to lock the CTM used to transform the pattern. + + * Workaround for X server Render bug involving repeating patterns + with a general transformation matrix. + + * cairo_get_font_face fixed to return a "nil" font face object rather + than NULL on error. + + * cairo_set_font_face fixed to not crash if given a NULL font face, + (which is the documented interface for restoring the default font + face). + + * Fix xlib glyphset caching to not try to free a NULL glyph. + +Snapshot 0.6.0 (2005-07-28 Carl Worth ) +========================================================== +API changes +----------- +* The prototypes of the following functions have changed: + + cairo_xlib_surface_create_with_xrender_format + cairo_xlib_surface_create_for_bitmap + + A Screen* parameter has been added to each. This allows the cairo + xlib backend to work correctly with multi-head X servers. + +* The following function has been modified: + + cairo_scaled_font_create + + to accept a cairo_font_options_t*. See below fore more details. + +* All opaque, reference-counted cairo objects have now been moved to a + standard error-handling scheme. The new objects to receive this + treatment are cairo_font_face_t, cairo_scaled_font_t, and + cairo_surface_t. (Previous snapshots already provided this scheme + for cairo_t, cairo_path_t, and cairo_pattern_t.) + + This changes two functions to have a return type of void rather than + cairo_status_t: + + cairo_scaled_font_extent + cairo_surface_finish + + And significantly, none of the create functions for any of the + objects listed above will return NULL. The pointer returned from any + function will now always be a valid pointer and should always be + passed to the corresponding destroy function when finished + + The simplest strategy for porting code is to switch from: + + object = cairo__create (); + if (object == NULL) + goto BAILOUT; + + /* act on object */ + + cairo__destroy (object); + + to: + + object = cairo__create (); + if (cairo__status (object)) + goto BAILOUT; + + /* act on object */ + + cairo__destroy (object); + + But significantly, it is not required to check for an error status + before the "act on object" portions of the code above. All + operations on an object with an error status are, by definition, + no-ops without side effect. So new code might be written in an + easier-to-read style of: + + object = cairo__create (); + + /* act on object */ + + cairo__destroy (object); + + with cairo__status checks placed only at strategic + locations. For example, passing an error object to another object, + (eg. cairo_set_source with an in-error pattern), will propagate the + error to the subsequent object (eg. the cairo_t). This means that + error checking can often be deferred even beyond the destruction of + a temporary object. + +API additions +------------- +* New functions for checking the status of objects that have been + switched to the common error-handling scheme: + + cairo_font_face_status + cairo_scaled_font_status + cairo_surface_status + +* The _cairo_error function which was added in 0.5.1 has now been made + much more useful. In 0.5.1 only errors on cairo_t objects passed + through _cairo_error. Now, an error on any object should pass + through _cairo_error making it much more reliable as a debugging + mechanism for finding when an error first occurs. + +* Added new font options support with a myriad of functions: + + cairo_font_options_create + cairo_font_options_copy + cairo_font_options_destroy + + cairo_font_options_status + + cairo_font_options_merge + cairo_font_options_equal + cairo_font_options_hash + + cairo_font_options_set_antialias + cairo_font_options_get_antialias + cairo_font_options_set_subpixel_order + cairo_font_options_get_subpixel_order + cairo_font_options_set_hint_style + cairo_font_options_get_hint_style + cairo_font_options_set_hint_metrics + cairo_font_options_get_hint_metrics + + cairo_surface_get_font_options + + cairo_ft_font_options_substitute + + cairo_set_font_options + cairo_get_font_options + + This new font options support allows the application to have much + more fine-grained control over how fonts are rendered. + Significantly, it also allows surface backends to have some + influence over the process. For example, the xlib backend now + queries existing Xft properties to set font option defaults. + +* New function: + + cairo_xlib_surface_set_drawable + + which allows the target drawable for an xlib cairo_surface_t to be + changed to another with the same format, screen, and display. This + is necessary in certain double-buffering techniques. + +New features +------------ +* Sub-pixel text antialiasing is now supported. + +Bug fixes +--------- +* Fixed assertion failure in cairo_surface_create_similar when + application commits an error by passing a cairo_format_t rather than + a cairo_content_t. + +* Avoid division by zero in various places (cairo-ft). + +* Fix infinite loop when using non-default visuals (cairo-xlib). + +* Eliminate segfault in cairo_image_surface_create_from_png_stream. + +* Prevent errant sign-extension of masks on 64-bit architectures + (cairo-xlib and cairo-xcb). + +* Other miscellaneous fixes. + +Snapshot 0.5.2 (2005-07-18 Carl Worth ) +========================================================== +API changes +----------- +* New functions for creating patterns of a single color: + + cairo_pattern_create_rgb + cairo_pattern_create_rgba + +* Change cairo_surface_create_similar to accept a new type of + cairo_content_t rather than cairo_format_t: + + typedef enum _cairo_content { + CAIRO_CONTENT_COLOR = 0x1000, + CAIRO_CONTENT_ALPHA = 0x2000, + CAIRO_CONTENT_COLOR_ALPHA = 0x3000 + } cairo_content_t; + +* Add new CAIRO_FORMAT_VALID and CAIRO_CONTENT_VALID macros. + +* Remove unused status value: + + CAIRO_STATUS_NO_TARGET_SURFACE + +* Add new status values: + + CAIRO_STATUS_INVALID_STATUS + +* Require libpixman >= 0.1.5 (for necessary bug fixes) + +Bug fixes +--------- +* Fix cairo_surface_write_to_png for RGB24 images. + +* Fix broken metrics and rendering for bitmap fonts. Add mostly + useless bitmap glyph transformation. + +* Fix glyph caches to not eject entries that might be immediately + needed, (fixing intermittent crashes when rendering text). + +* Fix all memory leaks found by running "make check-valgrind". + +ATSUI backend changes +--------------------- +* Allow building against < 10.3 SDK. + +* Prevent crash on empty strings. + +Glitz backend changes +--------------------- +* Require glitz >= 0.4.4. + +* Use frame buffer objects instead of pbuffers for accelerated + offscreen drawing. + +* Minor improvement to gradient pattern creation. + +PostScript backend fixes +------------------------ +* Rewrite of the PS backend to generate more interesting output that + the old big-image implementation. + +Win32 backend fixes +------------------- +* Implement glyph path support. + +* Fix swap of blue and green values in the fill_rectangles path. + +Xlib backend fixes +------------------ +* Add optimization to use XCopyArea rather than XRenderComposite when + transforming only with an integer translation, and using SOURCE + operator or OVER with a source pattern without alpha. + +Snapshot 0.5.1 (2005-06-20 Carl Worth ) +========================================================== +API changes +----------- +* Removed cairo_status_string(cairo_t*) and add + cairo_status_to_string(cairo_status_t) in its place. Code using + cairo_status_string can be ported forward as follows: + + cairo_status (cr); + -> + cairo_status_to_string (cairo_status (cr)); + +* Removed the BAD_NESTING restriction which means that two different + cairo_t objects can now interleave drawing to the same + cairo_surface_t without causing an error. + +* The following functions which previously had a return type of + cairo_status_t now have a return type of void: + + cairo_pattern_add_color_stop_rgba + cairo_pattern_set_matrix + cairo_pattern_get_matrix + cairo_pattern_set_extend + cairo_pattern_set_filter + + See discussion of cairo_pattern_status below for more details. + +API additions +------------- +* Improved error handling: + + cairo_status_t + cairo_pattern_status (cairo_pattern_t *pattern); + + This snapshot expands the status-based error handling scheme from + cairo_t to cairo_path_t and cairo_pattern_t. It also expands the + scheme so that object-creating functions, (cairo_create, + cairo_pattern_create_*, cairo_copy_path_*), are now guaranteed to + not return NULL. Instead, in the case of out-of-memory these + functions will return a static object with + status==CAIRO_STATUS_NO_MEMORY. The status can be checked with the + functions cairo_status and cairo_pattern_status, or by direct + inspection of the new status field in cairo_path_t. + + Please note that some objects, including cairo_surface_t and all of + the font-related objects have not been converted to this + error-handling scheme. + +* In addition to the above changes, a new private function has been added: + + _cairo_error + + This function can be used to set a breakpoint in a debugger to make + it easier to find programming error in cairo-using code. (Currently, + _cairo_error is called when any error is detected within a cairo_t + context, but is not called for non-cairo_t errors such as for + cairo_path_t and cairo_pattern_t). + +* Fixed cairo_path_data_t so that its enum is visible to C++ code, (as + cairo_path_data_type_t). + +Performance improvements +------------------------ +* Made a minor performance improvement for clipping, (restrict clip + surface to the new intersected bounds). + +* Optimize rendering of a solid source pattern with a pixel-aligned + rectangular path to use backend clipping rather than rasterization + and backend compositing. + +* Optimize cairo_paint_with_alpha to defer to cairo_paint when alpha + is 1.0. + +Bug fixes +--------- +* Fixed memory leak in cairo_copy_path. + +* A build fix for non-srcdir builds. + +PDF backend fixes +----------------- +* New support for path-based clipping. + +* Fix for text rotated to angles other than multiples of π/2. + +Win32 backend fixes +------------------- +* Fix for text extents. + +Xlib backend +------------ +* Implemented a complex workaround for X server bug[*] related to + Render-based compositing with untransformed, repeating source + pictures. The workaround uses core Xlib when possible for + performance, (ie. with CAIRO_OPERATOR_SOURCE or CAIRO_OPERATOR_OVER + with an opaque source surface), and falls back to the pixman + image-based compositing otherwise. + + [*] https://bugs.freedesktop.org/show_bug.cgi?id=3566 + +* Various bug fixes, particularly in the fallback paths. + +Snapshot 0.5.0 (2005-05-17 Carl Worth ) +========================================================== +This is a pretty big, and fairly significant snapshot. It represents +between 2 and 3 months of solid work from a lot of people on improving +the API as much as possible. I'd like to express my appreciation and +congratulations to everyone who has worked on the big API Shakeup, +(whether in email battles over names, or fixing my silly bugs). + +This snapshot will require some effort on the part of users, since +there are a _lot_ of API changes (ie. no cairo program ever written is +safe --- they're all broken now in at least one way). But, in spite of +that, we do encourage everyone to move their code to this snapshot as +soon as possible. And we're doing everything we can think of to make +the transition as smooth as possible. + +The idea behind 0.5 is that we've tried to make every good API change +we could want now, and get them all done with. That is, between now +and the 1.0 release of cairo, we expect very few new API changes, +(though some will certainly sneak in). We will have some significant +additions, but the pain of moving code from cairo 0.4 to cairo 0.5 +should be a one time experience, and things should be much smoother as +we continue to move toward cairo 1.0. + +And with so many changes coming out for the first time in this 0.5 +release, we really do need a lot of people trying this out to make +sure the ideas are solid before we freeze the API in preparation for +the 1.0 release. + +OK, enough introduction. Here is a (not-quite-complete) description of +the API removals, changes and additions in this snapshot, (compared to +0.4.0) + +API removals +============ +The following public functions have been removed: + +- cairo_set_target_* + + This is a big change. See the description of cairo_create in + the API changes section for how to deal with this. + +- cairo_set_alpha + + Alpha blending hasn't gone away; there's just a much more + unified rendering model now. Almost all uses of + cairo_set_alpha will be trivially replaced with + cairo_set_source_rgba and a few others will be replaced just + as easily with cairo_paint_with_alpha. + +- cairo_show_surface + + Another useful function that we realized was muddling up the + rendering model. The replacement is quite easy: + cairo_set_source_surface and cairo_paint. + +- cairo_matrix_create +- cairo_matrix_destroy +- cairo_matrix_copy +- cairo_matrix_get_affine + + These functions supported an opaque cairo_matrix_t. We now + have an exposed cairo_matrix_t structure, so these can be + dropped. + +- cairo_surface_set_repeat +- cairo_surface_set_matrix +- cairo_surface_set_filter + + These properties don't belong on surfaces. If you were using + them, you'll just want to instead use + cairo_pattern_create_for_surface and then set these properties + on the pattern. + +- cairo_copy + + This was a confusing function and hopefully nobody will miss + it. But if you really don't find cairo_save/restore adequate, + let us know and we have another idea for a potential + replacement. + +And while we're on the subject of removals, we carefully tightened up +the cairo header files so they no longer gratuitously include header +files that are not strictly necessary, (stdio.h, stdint.h, pixman.h, +Xrender.h, etc. and their dependencies). This may lead to some +surprising errors, so keep your eyes open for that. + +API changes +=========== +Here are some of the API changes that have occurred: + +~ cairo_create(void) -> cairo_create(cairo_surface_t *) + + This is the big change that breaks every program. The ability + to re-target a cairo_t was not particularly useful, but it did + introduce a lot of muddy semantic questions. To eliminate + that, cairo_create now requires its target surface to be + passed in at creation time. This isn't too hard to cope with + as the typical first operation after cairo_create was often + cairo_set_target_foo. So the order of those two swap and the + application instead has cairo_foo_surface_create, then + cairo_create. + +~ cairo_current_* -> cairo_get_* + + We had a strange mixture of cairo_get and cairo_current + functions. They've all been standardized on cairo_get, (though + note one is cairo_get_current_point). + +~ CAIRO_OPERATOR_SRC -> CAIRO_OPERATOR_SOURCE +~ CAIRO_OPERATOR_OVER_REVERSE -> CAIRO_OPERATOR_DEST_OVER + + Many of the cairo_operator_t symbolic values were renamed to + reduce the amount of abbreviation. The confusing "OP_REVERSE" + naming was also changed to use "DEST_OP" instead which is + easier to read and has wider acceptance in other + libraries/languages. + +~ cairo_set_pattern -> cairo_set_source +~ cairo_set_rgb_color -> cairo_set_source_rgb + + All of the various functions that changed the source + color/pattern were unified to use cairo_set_source names to + make the relation more clear. + +~ cairo_transform_point -> cairo_user_to_device +~ cairo_transform_distance -> cairo_user_to_device_distance +~ cairo_inverse_transform_point -> cairo_device_to_user +~ cairo_inverse_transform_distance -> cairo_device_to_user_distance + + These names just seemed a lot more clear. + +~ cairo_init_clip -> cairo_reset_clip +~ cairo_concat_matrix -> cairo_transform + + More abbreviation elimination + +~ cairo_current_path -> cairo_copy_path +~ cairo_current_path_flat -> cairo_copy_path_flat + + The former mechanism for examining the current path was a + function that required 3 or 4 callbacks. This was more + complexity than warranted in most situations. The new + cairo_copy_path function copies the current path into an + exposed data structure, and the documentation provides a + convenient idiom for navigating the path data. + +API additions +------------- ++ cairo_paint + + A generalized version of the painting operators cairo_stroke + and cairo_fill. The cairo_paint call applies the source paint + everywhere within the current clip region. Very useful for + clearing a surface to a solid color, or painting an image, + (see cairo_set_source_surface). + ++ cairo_paint_with_alpha + + Like cairo_paint but applying some alpha to the source, + (making the source paint translucent, eg. to blend an image on + top of another). + ++ cairo_mask + + A more generalized version of cairo_paint_with_alpha which + allows a pattern to specify the amount of translucence at each + point rather than using a constant value everywhere. + ++ cairo_mask_surface + + A convenience function on cairo_mask for when the mask pattern + is already contained within a surface. + ++ cairo_surface_set_user_data ++ cairo_surface_get_user_data ++ cairo_font_face_set_user_data ++ cairo_font_face_get_user_data + + Associate arbitrary data with a surface or font face for later + retrieval. Get notified when a surface or font face object is + destroyed. + ++ cairo_surface_finish + + Allows the user to instruct cairo to finish all of its + operations for a given surface. This provides a safe point for + doing things such as flushing and closing files that the + surface may have had open for writing. + ++ cairo_fill_preserve ++ cairo_stroke_preserve ++ cairo_clip_preserve + + One interesting change in cairo is that the path is no longer + part of the graphics state managed by + cairo_save/restore. This allows functions to construct paths + without interfering with the graphics state. But it prevents + the traditional idiom for fill-and-stroke: + + cairo_save; cairo_fill; cairo_restore; cairo_stroke + + Instead we know have alternate versions cairo cairo_fill, + cairo_stroke, and cairo_clip that preserve the current path + rather than consuming it. So the idiom now becomes simply: + + cairo_fill_preserve; cairo_stroke + ++ cairo_surface_write_to_png ++ cairo_surface_write_to_png_stream + + In place of a single PNG backend, now a surface created + through any backend (except PDF currently) can be written out + to a PNG image. + ++ cairo_image_surface_create_from_png ++ cairo_image_surface_create_from_png_stream + + And its just as easy to load a PNG image into a surface as well. + ++ cairo_append_path + + With the new, exposed path data structure, it's now possible + to append bulk path data to the current path, (rather than + issuing a long sequence of cairo_move_to/line_to/curve_to + function calls). + +Xlib and XCB backends +--------------------- + +Any cairo_format_t and Colormap arguments have been dropped from +cairo_xlib_surface_create. There are also two new +cairo_xlib|xcb_surface_create functions: + + cairo_xlib|xcb_surface_create_for_bitmap + (Particular for creating A1 surfaces) + cairo_xlib|xcb_surface_create_with_xrender_format + (For any other surface types, not described by a Visual*) + +All of these surface create functions now accept width and height. In +addition, there are new cairo_xlib|xcb_surface_set_size functions +which must be called each time a window that is underlying a surface +changes size. + +Print backends (PS and PDF) +--------------------------- +The old FILE* based interfaces have been eliminated. In their place we +have two different functions. One accepts a simple const char +*filename. The other is a more general function which accepts a +callback write function and a void* closure. This should allow the +flexibility needed to hook up with various stream object in many +languages. + +In addition, when specifying the surface size during construction, the +units are now device-space units (ie. points) rather than inches. This +provides consistency with all the other surface types and also makes +it much easier to reason about the size of the surface when drawing to +it with the default identity matrix. + +Finally, the DPI parameters, which are only needed to control the +quality of fallbacks, have been made optional. Nothing is required +during surface_create (300 DPI is assumed) and +cairo_ps|pdf_surface_set_dpi can be used to set alternate values if +needed. + +Font system +----------- +Owen very graciously listened to feedback after the big font rework he +had done for 0.4, and came up with way to improve it even more. In 0.4 +there was a cairo_font_t that was always pre-scaled. Now, there is an +unscaled cairo_font_face_t which is easier to construct, (eg. no +scaling matrix required) and work with, (it can be scaled and +transformed after being set on the graphics state). And the font size +manipulation functions are much easier. You can set an explicit size +and read/modify/write the font matrix with: + + cairo_set_font_size + cairo_get_font_matrix + cairo_set_font_matrix + +(Previously you could only multiply in a scale factor or a matrix.) A +pleasant side effect is that we can (and do) now have a default font +size that is reasonable, as opposed to the old default height of one +device-space unit which was useless until scaled. + +Of course, the old pre-scaled font had allowed some performance +benefits when getting many metrics for a font. Those benefits are +still made available through the new cairo_scaled_font_t. And a +cairo_font_face_t can be "promoted" to a cairo_scaled_font_t by +suppling a font_matrix and the desired CTM. + +Quartz backend +-------------- +Tim Rowley put in the work to bring the Quartz backend back after it +had been disabled in the 0.4.0 snapshot. He was not able to bring back +the function that allows one to create a cairo_font_t from an ATSUI +style: + + cairo_font_t * + cairo_atsui_font_create (ATSUStyle style); + +because he didn't have a test case for it. If you care about this +function, please provide a fairly minimal test and we'll try to bring +it back in an upcoming snapshot. + +Snapshot 0.4.0 (2005-03-08 Carl Worth ) +========================================================== +New documentation +----------------- +Owen Taylor has converted cairo's documentation system to gtk-doc and +has begun some long-needed work on the documentation, which can now be +viewed online here: + + http://cairographics.org/manual/ + +New backend: win32 +------------------ +This is the first snapshot to include a functional win32 backend, +(thanks to Owen Taylor). The interface is as follows: + + #include + + void + cairo_set_target_win32 (cairo_t *cr, + HDC hdc); + + cairo_surface_t * + cairo_win32_surface_create (HDC hdc); + + cairo_font_t * + cairo_win32_font_create_for_logfontw (LOGFONTW *logfont, + cairo_matrix_t *scale); + + cairo_status_t + cairo_win32_font_select_font (cairo_font_t *font, + HDC hdc); + + void + cairo_win32_font_done_font (cairo_font_t *font); + + double + cairo_win32_font_get_scale_factor (cairo_font_t *font); + +And see also the documentation at: + +http://cairographics.org/manual/cairo-Microsoft-Windows-Backend.html + +Disabled backend: quartz +------------------------ +Unfortunately, the quartz backend code is currently out of date with +respect to some recent backend interface changes. So, the quartz +backend is disabled in this snapshot. + +If the quartz backend is brought up-to-date before the next snapshot, +we would be glad to make a 0.4.1 snapshot that re-enables it, (we do +not expect many more big backend interface changes). + +API Changes +----------- +The font system has been revamped, (as Owen Taylor's work with +integrating pango and cairo gave us the first serious usage of the +non-toy font API). + +One fundamental, user-visible change is that the cairo_font_t object +now represents a font that is scaled to a particular device +resolution. Further changes are described below. + + cairo.h + ------- + Removed cairo_font_set_transform and cairo_font_current_transform. + + Added cairo_font_extents and cairo_font_glyph_extents. See + documentation for details: + + http://cairographics.org/manual/cairo-cairo-t.html#cairo-font-extents + + cairo-ft.h + ---------- + The cairo_ft_font API changed considerably. Please see the + documentation for details: + + http://cairographics.org/manual/cairo-FreeType-Fonts.html + +Performance +----------- +Make the fast-path clipping (pixel-aligned rectangles) faster. + +Add optimization for applying a constant alpha to a pattern. + +Optimize gradients that are horizontal or vertical in device space. + +Xlib: When RENDER is not available, use image surfaces for +intermediate surfaces rather than xlib surfaces. + +Backend-specific changes +------------------------ + Glitz + ----- + Major update to glitz backend. The output quality should now be just + as good as the image and xlib backends. + + Track changes to glitz 0.4.0. + + PDF + --- + Various improvements to produce more conformant output. + +Internals +--------- +David Reveman contributed a large re-work of the cairo_pattern_t +implementation, providing cleaner code and more optimization +opportunities. + + Backend interface changes + ------------------------- + Rework backend interface to accept patterns, not surfaces for source + and mask. + + Remove set_matrix, set_filter, and set_repeat functions. + + More sophisticated backend interface for image fallbacks, + ({acquire,release}_{source,dest}_image() and clone_similar). + +Bug fixes +--------- +Only install header files for backends that have been compiled. + +Fixed some rounding errors leading to incorrectly placed glyphs. + +Many other minor fixes. + +Snapshot 0.3.0 (2005-01-21 Carl Worth ) +========================================================== +Major API changes +----------------- +1) The public header files will no longer be directly installed into + the system include directory. They will now be installed in a + subdirectory named "cairo", (eg. in /usr/include/cairo rather than + in /usr/include). + + As always, the easiest way for applications to discover the + location of the header file is to let pkg-config generate the + necessary -I CFLAGS and -L/-l LDFLAGS. For example: + + cc `pkg-config --cflags --libs cairo` -o foo foo.c + + IMPORTANT: Users with old versions of cairo installed will need to + manually remove cairo.h and cairo-features.h from the + system include directories in order to prevent the old + headers from being used in preference to the new ones. + +2) The backend-specific portions of the old monolithic cairo.h have + been split out into individual public header files. The new files + are: + + cairo-atsui.h + cairo-ft.h + cairo-glitz.h + cairo-pdf.h + cairo-png.h + cairo-ps.h + cairo-quartz.h + cairo-xcb.h + cairo-xlib.h + + Applications will need to be modified to explicitly include the new + header files where appropriate. + +3) There are two new graphics backends in this snapshot, a PDF + backend, and a Quartz backend. There is also one new font backend, + ATSUI. + +PDF backend +----------- +Kristian Høgsberg has contributed a new backend to allow cairo-based +applications to generate PDF output. The interface for creating a PDF +surface is similar to that of the PS backend, as can be seen in +cairo-pdf.h: + + void + cairo_set_target_pdf (cairo_t *cr, + FILE *file, + double width_inches, + double height_inches, + double x_pixels_per_inch, + double y_pixels_per_inch); + + cairo_surface_t * + cairo_pdf_surface_create (FILE *file, + double width_inches, + double height_inches, + double x_pixels_per_inch, + double y_pixels_per_inch); + +Once a PDF surface has been created, applications can draw to it as +any other cairo surface. + +This code is still a bit rough around the edges, and does not yet +support clipping, surface patterns, or transparent gradients. Text +only works with TrueType fonts at this point and only black text is +supported. Also, the size of the generated PDF files is currently +quite big. + +Kristian is still actively developing this backend, so watch this +space for future progress. + +Quartz backend +-------------- +Calum Robinson has contributed a new backend to allow cairo +applications to target native Mac OS X windows through the Quartz +API. Geoff Norton integrated this backend into the current +configure-based build system, while Calum also provided Xcode build +support in the separate "macosx" module available in CVS. + +The new interface, available in cairo-quartz.h, is as follows: + + void + cairo_set_target_quartz_context (cairo_t *cr, + CGContextRef context, + int width, + int height); + + cairo_surface_t * + cairo_quartz_surface_create (CGContextRef context, + int width, + int height); + +There is an example program available in CVS in cairo-demo/quartz. It +is a port of Keith Packard's fdclock program originally written for +the xlib backend. A screenshot of this program running on Mac OS X is +available here: + + http://cairographics.org/~cworth/images/fdclock-quartz.png + +ATSUI font backend +------------------ +This new font backend complements the Quartz backend by allowing +applications to use native font selection on Mac OS X. The interface +is a single new function: + + cairo_font_t * + cairo_atsui_font_create (ATSUStyle style); + +Minor API changes +----------------- +Prototype for non-existent function "cairo_ft_font_destroy" removed. + +Now depends on libpixman 0.1.2 or newer, (0.1.3 is being released +concurrently and has some useful performance improvements). + +Default paint color is now opaque black, (was opaque white). Default +background color is transparent (as before). + +Renamed "struct cairo" to "struct _cairo" to free up the word "cairo" +from the C++ identifier name space. + +Functions returning multiple return values through provided pointers, +(cairo_matrix_get_affine, cairo_current_point, and +cairo_current_color_rgb), will now accept NULL for values the user +wants to ignore. + +CAIRO_HAS_FREETYPE_FONT has now been renamed to CAIRO_HAS_FT_FONT. + +Performance improvements +------------------------ +Alexander Larsson provided some fantastic performance improvements +yielding a 10000% performance improvement in his application, (when +also including his performance work in libpixman-0.1.3). These include + + * Fixed handling of cache misses. + + * Creating intermediate clip surfaces at the minimal size required. + + * Eliminating roundtrips when creating intermediate Xlib surfaces. + +Implementation +-------------- +Major re-work of font metrics system by Keith Packard. Font metrics +should now be much more reliable. + +Glitz backend +------------- +Updated for glitz-0.3.0. +Bug fixes in reference counting. + +Test suite +---------- +New tests for cache crashing, rotating text, improper filling of +complex polygons, and leaky rasterization. + +Bug fixes +--------- +Fixed assertion failure when selecting the same font multiple times in +sequence. + +Fixed reference counting so cache_destroy functions work. + +Remove unintended copyright statement from files generated with +PostScript backend. + +Fixed to eliminate new warnings from gcc 3.4 and gcc 4. + +Snapshot 0.2.0 (2004-10-27 Carl Worth ) +=========================================================== +New license: LGPL/MPL +--------------------- +The most significant news with this release is that the license of +cairo has changed. It is now dual-licensed under the LGPL and the +MPL. For details see the COPYING file as well as COPYING-LGPL-2.1 and +COPYING-MPL-1.1. + +I express my thanks to everyone involved in the license change process +for their patience and support! + +New font and glyph internals +---------------------------- +Graydon Hoare has put a tremendous amount of work into new internals +for handling fonts and glyphs, including caches where appropriate. +This work has no impact on the user-level API, but should result in +great performance improvements for applications using text. + +New test suite +-------------- +This snapshot of cairo includes a (small) test suite in +cairo/test. The tests can be run with "make check". The test suite was +designed to make it very easy to add new tests, and we hope to see +many contributions here. As you find bugs, please try adding a minimal +test case to the suite, and submit it with the bug report to the +cairo@cairographics.org mailing list. This will make it much easier +for us to track progress in fixing bugs. + +New name for glitz backend +-------------------------- +The gl backend has now been renamed to the glitz backend. This means +that the following names have changed: + + CAIRO_HAS_GL_SURFACE -> CAIRO_HAS_GLITZ_SURFACE + cairo_set_target_gl -> cairo_set_target_glitz + cairo_gl_surface_create -> cairo_glitz_surface_create + +This change obviously breaks backwards compatibility for applications +using the old gl backend. + +Up-to-date with latest glitz snapshots +-------------------------------------- +This snapshot of cairo is now up to date with the latest glitz +snapshot, (currently 0.2.3). We know that the latest cairo and glitz +snapshots have been incompatible for a very long time. We've finally +fixed that now and we're determined to not let that happen again. + +Revert some tessellation regression bugs +---------------------------------------- +People that have been seeing some tessellation bugs, (eg. leaked +fills), in the CVS version of cairo may have better luck with this +release. A change since the last snapshot was identified to trigger +some of these bugs and was reverted before making the snapshot. The +behavior should be the same as the previous (0.1.23) snapshot. + +Miscellaneous changes +--------------------- +Changed CAIRO_FILTER_DEFAULT to CAIRO_FILTER_BEST to make gradients +easier. + +Track XCB API change regarding iterators. + +Various bug fixes +----------------- +Fix calculation of required number of vertices for pen. + +Fix to avoid zero-dimensioned pixmaps. + +Fix broken sort of pen vertices. + +Fix bug when cairo_show_text called with a NULL string. + +Fix clipping bugs. + +Fix bug in computing image length with XCB. + +Fix infinite loop bug in cairo_arc. + +Fix memory management interactions with libpixman. + +Snapshot 0.1.23 (2004-05-11 Carl Worth ) +======================================================== +Fixes for gcc 3.4 +----------------- +Fix prototype mismatches so that cairo can be built by gcc 3.4. + +Updates to track glitz +---------------------- +Various fixes to support the latest glitz snapshot (0.1.2). + +Gradient updates +---------------- +Radial gradients now support both inner and outer circles. +Transformed linear gradients are now properly handled. +Fixes for extend type reflect. + +Glitz updates +------------- +Converted shading routines to use fixed point values and introduced a +shading operator structure for more efficient shading calculations. +Support compositing with mask surface when mask is solid or +multi-texturing is available. + +PNG backend cleanups +-------------------- +Fix output to properly compensate for pre-multiplied alpha format in cairo. +Add support for A8 and A1 image formats. + +Bug fixes +--------- +Avoid crash or infinite loop on null strings and degeneratively short +splines. + +New? bugs in cairo_clip +----------------------- +There are some fairly serious bugs in cairo_clip. It is sometimes +causing an incorrect result. And even when it does work, it is +sometimes so slow as to be unusable. Some of these bugs may not be +new, (indeed cairo_clip has only ever had a braindead-slow +implementation), but I think they're worth mentioning here. + +Snapshot 0.1.22 (2004-04-16 Carl Worth ) +======================================================== +Cairo was updated to track the changes in libpixman, and now depends +on libpixman version 0.1.1. + +Snapshot 0.1.21 (2004-04-09 David Reveman ) +============================================================= +New OpenGL backend +------------------ +The OpenGL backend provides hardware accelerated output for +X11 and OS X. The significant new functions are: + + cairo_set_target_gl + cairo_gl_surface_create + +Automatic detection of available backends +----------------------------------------- +The configure script now automatically detect what backends are +available, (use ./configure --disable-`backend' to prevent +compilation of specific backends). + +Snapshot 0.1.20 (2004-04-06 Carl Worth ) +======================================================== +New pattern API +--------------- +David Reveman has contributed a new pattern API which enable linear +and radial gradient patterns in addition to the original surface-based +patterns. The significant new top-level functions are: + + cairo_pattern_create_linear + cairo_pattern_create_radial + cairo_pattern_create_for_surface + cairo_pattern_add_color_stop + cairo_set_pattern + +Any code using the old cairo_set_pattern, (which accepted a +cairo_surface_t rather than a cairo_pattern_t), will need to be +updated. + +Update to XCB backend +--------------------- +The XCB backend is now enabled by default, (use ./configure +--disable-xcb to turn it off). + +Faster clipping +--------------- +Graydon Hoare has added optimizations that make cairo_clip much faster +when the path is a pixel-aligned, rectangular region. + +Bug fixes. + +Snapshot 0.1.19 (2004-02-24 Carl Worth ) +======================================================== +New PNG backend +--------------- +Olivier Andrieu contributed a new PNG backend. It builds on the +existing image backend to make it easy to render "directly" to a +.png file. The user never needs to deal with the actual image +buffer. The significant new functions are: + + cairo_set_target_png + cairo_png_surface_create + +The PNG backend is not enabled by default so that by default there is +not a new dependency on libpng. Use ./configure --enable-png to enable +this backend. + +Snapshot 0.1.18 (2004-02-17 Carl Worth ) +======================================================== +Path query functionality +------------------------ +It's now possible to query the current path. The two new functions +are: + + cairo_current_path + cairo_current_path_flat + +Each function accepts a number of callback functions that will be +called for each element in the path (move_to, line_to, curve_to, +close_path). The cairo_current_path_flat function does not accept a +curve_to callback. Instead, all curved portions of the path will be +converted to line segments, (within the current tolerance value). This +can be handy for doing things like text-on-path without having to +manually interpolate Bézier splines. + +New XCB backend +--------------- +Jamey Sharp has contributed a second X backend that uses the new, lean +XCB library rather than Xlib. It cannot currently be compiled at the +same time as the Xlib backend. See ./configure --enable-xcb. + +Build fixes for cygwin. + +Bug fixes. + +Snapshot 0.1.17 (2003-12-16 Carl Worth ) +======================================================== + +Better text support +------------------- +This snapshot provides much better text support by implementing the +following four functions: + + cairo_text_extents + cairo_glyph_extents + cairo_text_path + cairo_glyph_path + +The text/glyph_extents functions can be used to determine the bounding +box (and advance) for text as if drawn by show_text/glyphs. + +The text/glyph_path objects functions place text shapes on the current +path, where they can be subsequently manipulated. For example, +following these functions with cairo_stroke allows outline text to be +drawn. Calling cairo_clip allows clipping to a text-shaped region. + +Combined dependencies +--------------------- +The cairo core now depends only on the libpixman library. This single +library replaces the three previous libraries libic, libpixregion, and +slim. Thanks to Dave Beckett for all of +the heavy lifting with this renaming effort. + +Conditional compilation of backends +----------------------------------- +Cairo now allows optional backends to be disabled at compile time. The +following options may now be passed to the configure script: + + --disable-xlib + --disable-ps + +Note that the first option is a change from the old --without-x option +which will no longer have any effect. + +OS X supported - several byte-order issues resolved +--------------------------------------------------- +Cairo has now been successfully compiled under OS X. Testing revealed +that there were some byte-order problems in the PostScript backend and +the PNG generation in the demos. These have now been resolved. + +2003-10 +======= +Graydon Hoare implemented the first real text +support using Freetype/fontconfig, (previous versions of cairo used +Xft and could only draw text when using an X backend). + +2003-09 +======= +Graydon Hoare added the first real support for +running cairo with a non-render-aware X server. + +Jamey Sharp virtualized the backend font and +surface interfaces in September, 2003. + +2003-06 +======= +Xr is renamed cairo to avoid confusion since it no longer had a strict +dependence on X. + +2003-05 +======= +A new image surface backend is added to Xr. Keith Packard + wrote the image compositing code in libic that is +used for the image_surface backend. This code was originally written +as the software fallback for the render extension within the X +server. + +2002-06 +======= +Carl Worth wrote the first lines of Xr, after Keith +Packard proposed the plan for a stateful drawing +library in C providing a PostScript-like rendering model. + + LocalWords: mutex BeOS extraordinaire distro's URL lcd bool tarball diff --git a/Build/source/libs/cairo/cairo-src/PORTING_GUIDE b/Build/source/libs/cairo/cairo-src/PORTING_GUIDE new file mode 100644 index 00000000000..7488173c46b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/PORTING_GUIDE @@ -0,0 +1,265 @@ + ...-----=======-----... + Cairo 1.0 Porting Guide + ...-----=======-----... + +Here are some notes on more easily porting cairo_code from cairo 0.4 +to cairo 1.0. It is sorted roughly in order of importance, (the items +near the top are expected to affect the most people). + +Automated API renamings +======================= +There have been a lot of simple renamings where the functionality is +the same but the name of the symbol is different. We have provided a +script to automate the conversion of these symbols. It can be found +within the cairo distribution in: + + util/cairo-api-update + +This script is used by installing it somewhere on your PATH, and the +running it and providing the names of your source files on the command +line. For example: + + cairo-api-update *.[ch] + +The script will first save backup copies of each file (renamed with a +.bak extension) and then will perform all of the simple renamings. + +For your benefit, the script also produces messages giving filenames +and line numbers for several of the manual API updates that you will +need to perform as described below. + + +Manual API changes +================== +This section of the porting guide describes changes you will have to +manually make to your source code. In addition to the information in +this guide, the cairo-api-update script will notify you of some of +these issues as described above. + +Cairo's deprecation warnings +---------------------------- +Also, if your compiler provides warnings for implicit declarations of +functions, (eg. "gcc -Wall"), then simply attempting to compile your +program will cause cairo to generate messages intended to guide you +through the porting process. + +For example, if you neglect to update an old call to +cairo_set_target_drawable, you might see an error message as follows: + + foo.c:10: warning: implicit declaration of function + ‘cairo_set_target_drawable_DEPRECATED_BY_cairo_xlib_surface_create’ + +This message is indicating to you that the deprecatd function +cairo_set_target_drawable appears in your program foo.c on line 10, +and you should rewrite your program to call cairo_xlib_surface_create +instead. + +The remainder of this porting guide is arranged as a set of common +code patterns that appear in old (cairo-0.4) code and how it should be +transformed to new (cairo-0.5) code. + +cairo_create +------------ +Was: cr = cairo_create (); + cairo_set_target_foo (cr, args); + /* draw */ + cairo_destroy (cr); + +Now: cairo_surface_t *surface; + + surface = cairo_foo_surface_create (args); + cr = cairo_create (surface); + /* draw */ + cairo_destroy (cr); + cairo_surface_destroy (surface); + +Or: cairo_surface_t *surface; + + surface = cairo_foo_surface_create (args); + cr = cairo_create (surface); + cairo_surface_destroy (surface); + /* draw */ + cairo_destroy (cr); + +NOTE: Many of the cairo_foo_surface_create functions accept the + identical arguments as the the old cairo_set_target_foo + functions, (minus the cairo_t*), making this transformation + quite easy. One notable exception is cairo_set_target_drawable + which, when it becomes cairo_xlib_surface_create must pickup new + arguments for the Visual*, the width, and the height. + +cairo_set_alpha (1) +------------------- +Was: cairo_set_rgb_color (cr, red, green, blue); + cairo_set_alpha (cr, alpha); + +Now: cairo_set_source_rgba (cr, red, green, blue, alpha); + +cairo_show_surface +------------------ +Was: cairo_show_surface (cr, surface, width, height); + +Now: cairo_set_source_surface (cr, surface, x, y); + cairo_paint (cr); + +NOTE: The type signatures of cairo_show_surface and cairo_set_source + are the same, but pay attention that cairo_show_surface required + the width and height, while cairo_set_source_surface requires + the X,Y location to where the surface will be placed. + +cairo_set_alpha (2) +------------------- +Was: cairo_set_alpha (cr, alpha); + cairo_show_surface (cr, surface, width, height); + +Now: cairo_set_source_surface (cr, surface, x, y); + cairo_paint_with_alpha (cr, alpha); + +filling and stroking +-------------------- +Was: cairo_save (cr); + /* set fill color */ + cairo_fiill (cr); + cairo_restore (cr); + /* set stroke color */ + cairo_stroke (cr); + +Now: /* set fill color */ + cairo_fill_preserve (cr); + /* set stroke color */ + cairo_stroke (cr); + +NOTE: The current path is no longer saved/restored by + cairo_save/cairo_restore. This can lead to some subtle + surprises, so look out. + +cairo_matrix_t +-------------- +Was: cairo_matrix_t *matrix; + + matrix = cairo_matrix_create (); + /* Do stuff with matrix */ + cairo_matrix_destroy (matrix); + +Now: cairo_matrix_t matrix; + cairo_matrix_init_identity (&matrix); + /* Do stuff with &matrix */ + +NOTE: If you are really lazy, you can still use a cairo_matrix_t* and + avoid putting the &matrix all over by just replacing + cairo_matrix_create() with malloc() and cairo_matrix_destroy() + with free(). That's not as nice, and you still need to be + careful to see if you need to initialize it to an identity + matrix as cairo_matrix_create() did for you. + +Rendering to a temporary surface +-------------------------------- +Was: cairo_save (cr); + { + cairo_set_target_surface (cr, temporary); + /* draw through cr onto temporary */ + } + cairo_restore (cr); + /* use temporary as source on cr */ + +Now: { + cr2 = cairo_create (temporary); + /* draw through cr2 onto temporary */ + cairo_destory (cr2); + } + /* use temporary as source on cr */ + +NOTE: Having to create another cairo_t is a bit annoying, but having + to invent a new name for it is just awful, (imagine a deeply + nested version of this code). Fortunately, the style above is + just a stop-gap measure until the new group API comes along. + +Iterating over a path +--------------------- +Was: cairo_current_path (cr, + my_move_to, + my_line_to, + my_curve_to, + my_close_path, + closure); + +Now: int i; + cairo_path_t *path; + cairo_path_data_t *data; + + path = cairo_copy_path (cr); + + for (i=0; i < path->num_data; i += path->data[i].header.length) { + data = &path->data[i]; + switch (data->header.type) { + case CAIRO_PATH_MOVE_TO: + my_move_to (closure, data[1].point.x, data[1].point.y); + break; + case CAIRO_PATH_LINE_TO: + my_line_to (closure, data[1].point.x, data[1].point.y); + break; + case CAIRO_PATH_CURVE_TO: + my_curve_to (closure, data[1].point.x, data[1].point.y, + data[2].point.x, data[2].point.y, + data[3].point.x, data[3].point.y); + break; + case CAIRO_PATH_CLOSE_PATH: + my_close_path (closure); + break; + } + } + cairo_path_destroy (path); + +NOTE: This version makes it looks like the new form is a _lot_ more + verbose than the old version. But realize that the old version + required the support of 4 additional functions. The new approach + allows great flexibility including the ability to inline the + entire operation within the switch statement when appropriate. + +Erasing a surface to transparent +-------------------------------- +Was: cairo_set_rgb_color (cr, 0., 0., 0.); + cairo_set_alpha (cr, 0.) + cairo_set_operator (cr, CAIRO_OPERATOR_SRC); + cairo_rectangle (cr, 0., 0., surface_width, surface_height); + cairo_fill (cr); + + or: cairo_set_rgb_color (cr, 0., 0., 0.); + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_rectangle (cr, 0., 0., surface_width, surface_height); + cairo_fill (cr); + +Now: cairo_set_source_rgba (cr, 0., 0., 0., 0.); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + or: cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + +NOTE: Using cairo_rectangle and fill would still work just fine. It's + just a lot more convenient to use cairo_paint now, (particularly + as it doesn't require you to even know what the bounds of the + target surface are). + +Drawing to a PNG file +--------------------- +Was: file = fopen (filename, "w"); + cr = cairo_create (); + cairo_set_target_png (cr, file, format, width, height); + /* draw image */ + cairo_destroy (cr); + fclose (file); + +Now: surface = cairo_image_surface_create (format, width, height); + cr = cairo_create (surface); + /* draw image */ + cairo_surface_write_to_png (surface, filename); + cairo_destroy (cr); + cairo_surface_destroy (surface); + +NOTE: The png backend is gone. So there is no cairo_png_surface_create + to take the place of cairo_set_target_png. And notice that we + used an image surface here, but it is just as easy to use + cairo_surface_write_to_png with an xlib or other surface, (but + not PDF at the moment). This is one of the big advantages of + this approach as opposed to a PNG surface. diff --git a/Build/source/libs/cairo/cairo-src/README b/Build/source/libs/cairo/cairo-src/README new file mode 100644 index 00000000000..0be9947d548 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/README @@ -0,0 +1,204 @@ +Cairo - Multi-platform 2D graphics library +http://cairographics.org + +What is cairo +============= +Cairo is a 2D graphics library with support for multiple output +devices. Currently supported output targets include the X Window +System (via both Xlib and XCB), quartz, win32, and image buffers, +as well as PDF, PostScript, and SVG file output. Experimental backends +include OpenGL, BeOS, OS/2, and DirectFB. + +Cairo is designed to produce consistent output on all output media +while taking advantage of display hardware acceleration when available +(for example, through the X Render Extension). + +The cairo API provides operations similar to the drawing operators of +PostScript and PDF. Operations in cairo include stroking and filling +cubic Bézier splines, transforming and compositing translucent images, +and antialiased text rendering. All drawing operations can be +transformed by any affine transformation (scale, rotation, shear, +etc.). + +Cairo has been designed to let you draw anything you want in a modern +2D graphical user interface. At the same time, the cairo API has been +designed to be as fun and easy to learn as possible. If you're not +having fun while programming with cairo, then we have failed +somewhere---let us know and we'll try to fix it next time around. + +Cairo is free software and is available to be redistributed and/or +modified under the terms of either the GNU Lesser General Public +License (LGPL) version 2.1 or the Mozilla Public License (MPL) version +1.1. + +Where to get more information about cairo +========================================= +The primary source of information about cairo is: + + http://cairographics.org/ + +The latest versions of cairo can always be found at: + + http://cairographics.org/download + +Documentation on using cairo and frequently-asked questions: + + http://cairographics.org/documentation + http://cairographics.org/FAQ + +Mailing lists for contacting cairo users and developers: + + http://cairographics.org/lists + +Roadmap and unscheduled things to do, (please feel free to help out): + + http://cairographics.org/roadmap + http://cairographics.org/todo + +Dependencies +============ +The set of libraries needed to compile cairo depends on which backends +are enabled when cairo is configured. So look at the list below to +determine which dependencies are needed for the backends of interest. + +For the surface backends, we have both "supported" and "experimental" +backends. Further, the supported backends can be divided into the +"standard" backends which can be easily built on any platform, and the +"platform" backends which depend on some underlying platform-specific +system, (such as the X Window System or some other window system). + +As an example, for a standard Linux build similar to what's shipped by +your distro, (with image, png, pdf, PostScript, svg, and xlib surface +backends, and the freetype font backend), the following sample commands +will install necessary dependencies: + + Debian (and similar): + + apt-get build-dep cairo + + Fedora (and similar): + + yum install libpng-devel zlib-devel libXrender-devel fontconfig-devel + +Technically you probably don't need pixman from the distribution since +if you're manually compiling Cairo you probably want an updated pixman +as well. However, if you follow the default settings and install pixman +to /usr/local, your Cairo build should properly use it in preference to +the system pixman. + + +Supported, "standard" surface backends +------------------------------------ + image backend (required) + ------------------------ + pixman >= 0.30.0 http://cairographics.org/releases + + png support (can be left out if desired, but many + ----------- applications expect it to be present) + libpng http://www.libpng.org/pub/png/libpng.html + + pdf backend + ----------- + zlib http://www.gzip.org/zlib + + postscript backend + ------------------ + zlib http://www.gzip.org/zlib + + svg backend + ----------- + [none] + +Supported, "platform" surface backends +----------------------------------- + xlib backend + ------------ + X11 http://freedesktop.org/Software/xlibs + + xlib-xrender backend + -------------------- + Xrender >= 0.6 http://freedesktop.org/Software/xlibs + + quartz backend + -------------- + MacOS X >= 10.5 with Xcode >= 3.0 + + win32 backend + ------------- + Microsoft Windows 2000 or newer[*]. + + xcb backend + ----------- + XCB http://xcb.freedesktop.org + +Font backends (required to have at least one) +--------------------------------------------- + freetype font backend + --------------------- + freetype >= 2.1.9 http://freetype.org + fontconfig http://fontconfig.org + + quartz-font backend + ------------------- + MacOS X >= 10.4 with Xcode >= 2.4 + + win32 font backend + ------------------ + Microsoft Windows 2000 or newer[*]. + + [*] The Win32 backend should work on Windows 2000 and newer + (excluding Windows Me.) Most testing has been done on + Windows XP. While some portions of the code have been + adapted to work on older versions of Windows, considerable + work still needs to be done to get cairo running in those + environments. + + Cairo can be compiled on Windows with either the gcc + toolchain (see http://www.mingw.org) or with Microsoft + Visual C++. If the gcc toolchain is used, the standard + build instructions using configure apply, (see INSTALL). + If Visual C++ is desired, GNU make is required and + Makefile.win32 can be used via 'make -f Makefile.win32'. + The compiler, include paths, and library paths must be set + up correctly in the environment. + + MSVC versions earlier than 7.1 are known to miscompile + parts of cairo and pixman, and so should be avoided. MSVC + 7.1 or later, including the free Microsoft Visual Studio + Express editions, produce correct code. + +Experimental surface backends +----------------------------- + beos backend + ------------ + No dependencies in itself other than an installed BeOS system, but cairo + requires a font backend. See the freetype dependency list. + + os2 backend + ----------- + Cairo should run on any recent version of OS/2 or eComStation, but it + requires a font backend. See the freetype dependency list. Ready to use + packages and developer dependencies are available at Netlabs: + ftp://ftp.netlabs.org/pub/cairo + + skia backend + ------------ + Requires the skia library as of June 2014. Since skia is not + API stable, building against newer (or older) versions of skia + will probably fail. + + +Compiling +========= +See the INSTALL document for build instructions. + + +History +======= +Cairo was originally developed by Carl Worth and +Keith Packard . Many thanks are due to Lyle Ramshaw +without whose patient help our ignorance would be much more apparent. + +Since the original development, many more people have contributed to +cairo. See the AUTHORS files for as complete a list as we've been able +to compile so far. diff --git a/Build/source/libs/cairo/cairo-src/README.win32 b/Build/source/libs/cairo/cairo-src/README.win32 new file mode 100644 index 00000000000..ff962b72a68 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/README.win32 @@ -0,0 +1,66 @@ +Building Cairo on Windows +========================= +There are two primary ways to build Cairo on Windows. You can use a +UNIX emulation based setup, such as Cygwin or MSYS, with the +conventional configure script shipped with Cairo releases. In this +configuration, you will build with GCC and (implicitly) libtool. In +the Cygwin case you end up with a DLL that depends on Cygwin and +should be used only from Cygwin applications. In the MSYS case you end +up with a "normal" Win32 DLL that can be used either from GCC- or +Microsoft Visual C++-compiled code. In theory, this technique is no +different than the ordinary build process for the Cairo library. In +practise there are lots of small details that can go wrong. + +The second way is to use a GNU-compatible make, but build using +Microsoft's Visual C++ compiler to produce native libraries. This is +the setup this README.win32 is written for. Also the DLL produced this +way is usable either from GCC- or MSVC-compiled code. + +Tools required +============== +You will need GNU make, version 3.80 or later. Earlier versions or +other modern make implementations may work, but are not guaranteed to. + +You will also need Microsoft Visual C++. Version 7 has been most +heavily tested, but other versions are likely to work fine. + +Libraries required +================== +Cairo requires a compatible version of the pixman library. Full build +instructions are beyond the scope of this document; however, using the +same tools, it should be possible to build pixman simply by entering +the pixman/src directory and typing: + + make -f Makefile.win32 CFG=release + +Depending on your feature set, you may also need zlib and libpng. + +Building +======== +There are a few files that you will need to edit. First, you must +determine which features will be built. Edit +build/Makefile.win32.features and set the features as desired. Note +that most features have external dependencies; specifically, +CAIRO_HAS_PNG_FUNCTIONS requires libpng to be present, and +CAIRO_HAS_PS_SURFACE and CAIRO_HAS_PDF_SURFACE both require zlib. + +To ensure that the compiler can find all dependencies, you may need to +edit build/Makefile.win32.common. In particular, ensure that +PIXMAN_CFLAGS contains a -I parameter pointing to the location of +your pixman header files and that PIXMAN_LIBS points to the actual +location of your pixman-1.lib file. You may also need to edit the +various occurrences of CAIRO_LIBS to point to other libraries +correctly. Note also that if you wish to link statically with zlib, +you should replace zdll.lib with zlib.lib. + +Finally, from the top Cairo directory, type: + + make -f Makefile.win32 CFG=release + +If this command succeeds, you will end up with src/release/cairo.dll. +To successfully use Cairo from your own programs, you will probably +want to move this file to some central location. You will also +probably want to copy the Cairo header files. These should be placed +in a cairo subdirectory (for instance, c:/code/common/include/cairo). +The exact set to copy depends on your features and is reported to you +at the end of the build. diff --git a/Build/source/libs/cairo/cairo-src/RELEASING b/Build/source/libs/cairo/cairo-src/RELEASING new file mode 100644 index 00000000000..641ac1fc4a5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/RELEASING @@ -0,0 +1,138 @@ +Here are the steps to follow to create a new cairo release: + +1) Ensure that there are no local, uncommitted/unpushed + modifications. You're probably in a good state if both "git diff + HEAD" and "git log master..origin/master" give no output. Also make + sure you have libglib2.0-doc installed (else you'll get excessive + gtk-doc cross reference warnings in the next step). + +2) Verify that the code passes "make distcheck" + + First, make sure you have 'nm' and 'readelf' commands in PATH. + this should be OK with any Linux distro. + + Running "make distcheck" should result in no warnings or + errors and end with a message of the form: + + ============================================= + cairo-X.Y.Z archives ready for distribution: + cairo-X.Y.Z.tar.gz + ============================================= + + (But the tar file isn't actually ready yet, as we still have + some more steps to follow). + + Note that it's allowed (and perhaps recommended) to run the + "make distcheck" step against an all-software X server such as + Xvfb to avoid getting tripped up by any X-server-driver-specific + bugs. See test/README for details + + If you get errors about local PLT entries, you get the list of + cairo entries with the error. For each of these, a call to + slim_hidden_def and slim_hidden_proto is needed in the cairo + implementation in the style of other similar calls. + + In the unfortunate case that you have to push a snapshot out + (note, I said snapshot, not release) without the entire test + suite passing, here's the magic env vars to set when doing + 'make distcheck' and 'make release-publish' that will let you + get away with it. At any cost, never ever release without + (implied) distchecking. Every time we got around it, it turned + out to be a disaster. Anyway, here's the pass code: + + DISPLAY= CAIRO_TEST_TARGET=" " + +3) Fill out an entry in the NEWS file + + Sift through the logs since the last release. This is most + easily done with a command such as: + + git log --stat X.Y.Z.. + + where X.Y.Z is the previous release version. + + Summarize major changes briefly in a style similar to other + entries in NEWS. Take special care to note any additions in + the API. These should be easy to find by noting modifications + to .h files in the log command above. And more specifically, + the following command will show each patch that has changed a + public header file since the given version: + + find src/ -name '*.h' ! -name '*-private.h' ! -name 'cairoint.h' ! -name 'cairo-*features*.h' | \ + xargs git diff X.Y.Z.. -- + +4) Increment cairo_version_{minor|micro} in cairo-version.h: + + If there are backward-incompatible changes in the API, stop + now and don't release. Go back and fix the API instead. Cairo + is intended to remain backwards-compatible as far as API. + + So cairo_version_major will not be incremented unless we come + up with a new versioning scheme to take advantage of it. + + If there are API additions, then increment cairo_version_minor + and reset cairo_version_micro to 0. NOTE: The minor version is + only incremented for releases, not for snapshots. + + Otherwise, (i.e. there are only bug fixes), increment + cairo_version_micro to the next larger (even) number. + +5) Commit the changes to NEWS and cairo-version.h + + It's especially important to mention the new version number in your + commit log. + +6) Run "make release-publish" which will perform the following steps + for you: + + * Generate ChangeLog files out of git repository + * Check that ChangeLog files were generated properly + * Check that the version number ends with an even micro component + * Check that no release exists with the current version + * Verify that make distcheck completes successfully + * Generate the final tar file + * Generate an sha1sum file + * Sign the sha1sum using your GPG setup (asks for your GPG password) + * scp the three files to appear on http://cairographics.org/releases + * Generate a versioned manual and upload it to appear as both: + http://cairographics.org/manual-X.Y.Z + http://cairographics.org/manual + * Place local copies of the three files in the releases directory + * Create a LATEST-package-version file (after deleting any old one) + * Tag the entire source tree with a tag of the form X.Y.Z, and sign + the tag with your GPG key (asks for your GPG password, and you + may need to set GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL to match + your public-key's setting or this fails.) + * Provide some text for the release announcement (see below). + If for some reason you lost this message, "make release-publish-message" + prints it for you. + +7) Increment cairo_version_micro to the next larger (odd) number in + cairo-version.h, commit, and push. + +8) Push the newly created tag out to the central tree with a command + something like: + + git push origin master X.Y.Z + +9) Edit the cairo bugzilla product and add the new version numbers. Note + that you need to add two versions. One for the release/snapshot (with + an even micro version), another with the post-release version (with an + odd micro version). + +10) Send a message to cairo-announce@cairographics.org and CC + cairo@cairographics.org, gnome-announce-list@gnome.org and + ftp-release@lists.freedesktop.org (pr@lwn.net as well for major + releases) to announce the new release using the text provided from + "make release-publish", adding the excerpt from NEWS, your + signature, followed by the standard "What is cairo" and "Where to + get more information about cairo" blurbs from README, and finally + the shortlog of all changes since last release, generated by: + + git shortlog X.Y.Z... + + where X.Y.Z is the last released version. + +11) Edit the cairo wiki to add the announcement to the NEWS page and + the front page. (just the parts before your signature). + diff --git a/Build/source/libs/cairo/cairo-src/acinclude.m4 b/Build/source/libs/cairo/cairo-src/acinclude.m4 new file mode 100644 index 00000000000..dcf54f9357d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/acinclude.m4 @@ -0,0 +1,55 @@ +dnl -*- mode: autoconf -*- + +dnl [m4_newline] didn't appear until autoconf 2.62 +m4_ifdef([m4_newline],,[m4_define([m4_newline],[ +])]) + +dnl These are not available in autoconf 2.59 + +m4_ifdef([m4_foreach_w],,[m4_define([m4_foreach_w], +[m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) + +m4_ifdef([AS_CASE],,[ +m4_define([_AS_CASE], +[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], + [$#], 1, [ *) $1 ;;], + [$#], 2, [ $1) m4_default([$2], [:]) ;;], + [ $1) m4_default([$2], [:]) ;; +$0(m4_shift2($@))])dnl +]) +m4_defun([AS_CASE], +[m4_ifval([$2$3], +[case $1 in +_AS_CASE(m4_shift($@)) +esac +])dnl +])# AS_CASE +]) + +m4_ifdef([m4_shift2],, [m4_define([m4_shift2], [m4_shift(m4_shift($@))])]) + + +dnl ========================================================================== + +dnl This has to be in acinclude.m4 as it includes other files + +dnl Parse Version.mk and declare m4 variables out of it +m4_define([CAIRO_PARSE_VERSION],dnl + m4_translit(dnl + m4_bpatsubst(m4_include(cairo-version.h), + [^.define \([a-zA-Z0-9_]*\) *\([0-9][0-9]*\)], + [[m4_define(\1, \2)]]), + [A-Z], [a-z])dnl +)dnl + +dnl ========================================================================== + +m4_pattern_forbid([^cr_]) + +dnl AC_AUTOCONF_VERSION was introduced in 2.62, so its definition works as +dnl a conditional on version >= 2.62. Older versions did not call +dnl m4_pattern_allow from AC_DEFINE and friends. To avoid lots of warnings we +dnl only forbid CAIRO_ if autoconf is recent enough. +m4_ifdef([AC_AUTOCONF_VERSION], +[m4_pattern_forbid([CAIRO])], +[m4_pattern_forbid([_CAIRO])]) diff --git a/Build/source/libs/cairo/cairo-src/autogen.sh b/Build/source/libs/cairo/cairo-src/autogen.sh new file mode 100755 index 00000000000..4d113f8be5f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/autogen.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +test -n "$srcdir" || srcdir=`dirname "$0"` +test -n "$srcdir" || srcdir=. + +ORIGDIR=`pwd` +cd $srcdir + +AUTORECONF=`which autoreconf` +if test -z $AUTORECONF; then + echo "*** No autoreconf found, please intall it ***" + exit 1 +fi + +GTKDOCIZE=`which gtkdocize` +if test -z $GTKDOCIZE; then + echo "*** No GTK-Doc found, documentation won't be generated ***" +else + gtkdocize || exit $? +fi + +# create dummy */Makefile.am.features and ChangeLog to make automake happy +> boilerplate/Makefile.am.features +> src/Makefile.am.features +touch ChangeLog + +autoreconf --install --verbose || exit $? + +cd $ORIGDIR +test -n "$NOCONFIGURE" || "$srcdir/configure" "$@" diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.am.analysis b/Build/source/libs/cairo/cairo-src/build/Makefile.am.analysis new file mode 100644 index 00000000000..a44077ab453 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.am.analysis @@ -0,0 +1,37 @@ +if CAIRO_HAS_LCOV +# use recursive makes in order to ignore errors during check/perf +lcov: + -$(MAKE) $(AM_MAKEFLAGS) check + $(MAKE) $(AM_MAKEFLAGS) genlcov +lcov-perf: + -$(MAKE) $(AM_MAKEFLAGS) perf + $(MAKE) $(AM_MAKEFLAGS) genlcov + +# we have to massage the lcov.info file slightly to hide the effect of libtool +# placing the objects files in the .libs/ directory separate from the *.c +genlcov: + $(LTP) --directory $(top_builddir) --path $(top_builddir) --capture --output-file cairo-lcov.info --test-name CAIRO_TEST --no-checksum + $(SED) -e 's#.libs/##' \ + -e 's#boilerplate/src#src#' \ + -e 's#$(shell pwd)#$(shell cd $(top_srcdir) && pwd)#' \ + < cairo-lcov.info > cairo-lcov.info.tmp + LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory cairo-lcov --title "Cairo Code Coverage" --show-details cairo-lcov.info.tmp + $(RM) cairo-lcov.info.tmp + +html-local: lcov +else +lcov lcov-perf genlcov: + @echo You need to configure Cairo with support for gcov enabled. + @echo e.g, ./configure --enable-gcov +endif + +lcov-clean: +if CAIRO_HAS_LCOV + -$(LTP) --directory $(top_builddir) -z +endif + -$(RM) -r cairo-lcov.info cairo-lcov + -$(FIND) -name '*.gcda' -print | $(XARGS) $(RM) + +distclean-local: lcov-clean + +.PHONY: lcov lcov-perf genlcov lcov-clean diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.am.changelog b/Build/source/libs/cairo/cairo-src/build/Makefile.am.changelog new file mode 100644 index 00000000000..07e603695cf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.am.changelog @@ -0,0 +1,82 @@ +# Creating ChangeLog files from git log: + +# We always create a ChangeLog that contains the most recent changes, and +# multiple others for changes between major releases (other than the last such +# segment that we put in 'ChangeLog'. The old ones are named +# ChangeLog.pre-X.Y where X.Y is the version number of the major release. + +CURR_CHANGELOG_VERSION=$(CAIRO_VERSION_MAJOR).$$(echo "($(CAIRO_VERSION_MINOR)+1)/2*2" | bc) +# examines $version +PREV_CHANGELOG_VERSION=$$(if test "x$$(echo "($$version-0.1)*2/2"|bc)" = "x$$(echo "$$version*2/2"|bc)"; \ + then echo "$$version-$$(echo "$$version" | sed 's/[0-9]/0/g;s/[0-9]$$/2/')"; \ + else echo "$$version-1.0"; \ + fi | bc | sed 's/[.]0*/./;s/^0[.]\?$$/initial/;s/[.]$$/.0/') + +CHANGELOGS = ChangeLog \ + `version=$(CURR_CHANGELOG_VERSION); \ + version=$(PREV_CHANGELOG_VERSION); \ + while test "x$$version" != xinitial; do \ + echo ChangeLog.pre-$$version; \ + version=$(PREV_CHANGELOG_VERSION); \ + done` + +MAINTAINERCLEANFILES += $(srcdir)/ChangeLog $(srcdir)/ChangeLog.pre-* +DISTCLEANFILES += $(srcdir)/ChangeLog.cache-* + +changelogs: + @$(MAKE) $(AM_MAKEFLAGS) $(CHANGELOGS) + +dist-hook: changelogs + changelogs="$(CHANGELOGS)"; \ + for changelog in $$changelogs; do \ + cp $(srcdir)/$$changelog $(distdir)/ 2>/dev/null || \ + cp $$changelog $(distdir)/; \ + done + +$(srcdir)/ChangeLog: + @if test -d "$(srcdir)/.git"; then \ + version=$(CURR_CHANGELOG_VERSION); \ + prev=$(PREV_CHANGELOG_VERSION).0; \ + nearest_tag=`git describe | sed 's/-.*//'`; \ + before=$(srcdir)/ChangeLog.cache-$$prev..$$nearest_tag; \ + after=$(srcdir)/ChangeLog.cache-$$nearest_tag..; \ + $(MAKE) $(AM_MAKEFLAGS) $$before $$after && \ + echo Creating $@ && \ + { echo '# Generated by configure. Do not edit.'; echo; \ + cat $$after; echo; cat $$before; } > $@; \ + else \ + test -f $@ || \ + (echo A git checkout is required to generate $@ >&2 && \ + echo A git checkout is required to generate this file >> $@); \ + fi + +DISTCLEANFILES += ChangeLog.cache-* + +ChangeLog.cache-*..: .git + +ChangeLog%: $(srcdir)/ChangeLog% + +$(srcdir)/ChangeLog.cache-% $(srcdir)/ChangeLog.pre-%: + @echo Creating $@ + @if test -d "$(srcdir)/.git"; then \ + (cd "$(srcdir)" && \ + version=$$(echo "$@" | sed 's/.*ChangeLog\([.].*-\)\?//'); \ + if echo "$@" | grep -q '^ChangeLog[.]cache'; then \ + spec=$$version; \ + else \ + to=$$version; \ + test "x$$version" = x && version=$(CURR_CHANGELOG_VERSION); \ + from=$(PREV_CHANGELOG_VERSION); \ + test "x$$to" = x || to=$$to.0; \ + test "x$$from" = xinitial || from=$$from.0; \ + spec=$$from..$$to; \ + fi; \ + $(top_srcdir)/build/missing --run git log --stat "$$spec") > $@.tmp \ + && mv -f $@.tmp $@ \ + || ($(RM) $@.tmp; \ + echo Failed to generate $@, your $@ may be outdated >&2); \ + else \ + echo A git checkout is required to generate $@ >&2; \ + fi + +.PHONY: changelogs ChangeLog $(srcdir)/ChangeLog diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.am.common b/Build/source/libs/cairo/cairo-src/build/Makefile.am.common new file mode 100644 index 00000000000..b955af58fdf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.am.common @@ -0,0 +1,14 @@ +BUILT_SOURCES = +CLEANFILES = +DISTCLEANFILES = +EXTRA_DIST = +EXTRA_LTLIBRARIES = +EXTRA_PROGRAMS = +MAINTAINERCLEANFILES = +TESTS = +check_PROGRAMS = + +CLEANFILES += *.i *.s *.gch +CLEANFILES += $(EXTRA_LTLIBRARIES) $(EXTRA_PROGRAMS) $(check_PROGRAMS) +DISTCLEANFILES += $(BUILT_SOURCES) +MAINTAINERCLEANFILES += Makefile.in diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.am.gtk-doc b/Build/source/libs/cairo/cairo-src/build/Makefile.am.gtk-doc new file mode 100644 index 00000000000..c3d642b097b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.am.gtk-doc @@ -0,0 +1,190 @@ +# BEFORE MODIFYING THIS FILE: +# +# This file is a descendant of an old copy of gtk-doc.make, modified for cairo minimally: +# +# - Moved to build/ +# - Made it append to EXTRA_DIST and CLEANFILES +# - Instead of all-local, make "doc" build docs, and err if gtk-doc not enabled +# - Some other changed introduced in 7f114b781f5c530d57530e5f76402e41cdabac6b +# +# Before changing it, check to see if a newer gtk-doc.make has fixed the issue you are facing. +# From time to time, it would be nice to udpate this to the latest copy of gtk-doc.make, but +# please do review all the differences and port our modifications forward. +# + +# -*- mode: makefile -*- + +#################################### +# Everything below here is generic # +#################################### + +if GTK_DOC_USE_LIBTOOL +GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) +else +GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) +endif + +# We set GPATH here; this gives us semantics for GNU make +# which are more like other make's VPATH, when it comes to +# whether a source that is a target of one rule is then +# searched for in VPATH/GPATH. +# +GPATH = $(srcdir) + +TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) + +EXTRA_DIST += \ + $(content_files) \ + $(HTML_IMAGES) \ + $(DOC_MAIN_SGML_FILE) \ + $(DOC_MODULE)-sections.txt \ + $(DOC_MODULE)-overrides.txt + +DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp \ + $(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp + +SCANOBJ_FILES = \ + $(DOC_MODULE).args \ + $(DOC_MODULE).hierarchy \ + $(DOC_MODULE).interfaces \ + $(DOC_MODULE).prerequisites \ + $(DOC_MODULE).signals + +REPORT_FILES = \ + $(DOC_MODULE)-undocumented.txt \ + $(DOC_MODULE)-undeclared.txt \ + $(DOC_MODULE)-unused.txt + +CLEANFILES += $(SCANOBJ_FILES) $(REPORT_FILES) $(DOC_STAMPS) + +if ENABLE_GTK_DOC +doc: html-build.stamp +else +doc: + @echo "*** gtk-doc must be installed (and --enable-gtk-doc) in order to make doc" + @false +endif + +docs: html-build.stamp + +#### scan #### + +scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB) $(EXTRA_HFILES) + @echo 'gtk-doc: Scanning header files' + @-chmod -R u+w $(srcdir) + gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="$(IGNORE_HFILES)" $(SCAN_OPTIONS) $(EXTRA_HFILES) --output-dir=$(srcdir) + if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null 2>&1 ; then \ + CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" CFLAGS="$(GTKDOC_CFLAGS)" LDFLAGS="$(GTKDOC_LIBS)" gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \ + else \ + cd $(srcdir) ; \ + for i in $(SCANOBJ_FILES) ; do \ + test -f $$i || touch $$i ; \ + done \ + fi + touch scan-build.stamp + +$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt: scan-build.stamp + @true + +#### templates #### + +tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt + @echo 'gtk-doc: Rebuilding template files' + @-chmod -R u+w $(srcdir) + cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE) $(MKTMPL_OPTIONS) + touch tmpl-build.stamp + +tmpl.stamp: tmpl-build.stamp + @true + +tmpl/*.sgml: + @true + + +#### xml #### + +# gtkdoc-mkdb is broken and requires a --root-dir=$(srcdir) option +# The _srcdir diversion is fragile but works for make check; make distcheck +sgml-build.stamp: tmpl.stamp $(HFILE_GLOB) $(CFILE_GLOB) $(DOC_MODULE)-sections.txt $(srcdir)/tmpl/*.sgml $(expand_content_files) + @echo 'gtk-doc: Building XML' + @-chmod -R u+w $(srcdir) + _srcdir="`pwd`/$(DOC_SOURCE_DIR)"; \ + cd $(srcdir) && gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$$_srcdir --output-format=xml --expand-content-files="$(expand_content_files)" --main-sgml-file=$(DOC_MAIN_SGML_FILE) $(MKDB_OPTIONS) + touch sgml-build.stamp + +sgml.stamp: sgml-build.stamp + @true + +#### html #### + +html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) + @echo 'gtk-doc: Building HTML' + @-chmod -R u+w $(srcdir) + rm -rf $(srcdir)/html + mkdir $(srcdir)/html + cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) + test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html ) + @echo 'gtk-doc: Fixing cross-references' + cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS) + touch html-build.stamp + +############## + +clean-local: + rm -f *~ *.bak + rm -rf .libs + +distclean-local: + cd $(srcdir) && \ + rm -rf xml $(REPORT_FILES) \ + $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt + +maintainer-clean-local: clean + cd $(srcdir) && rm -rf xml html + +install-data-local: + -installfiles=`echo $(srcdir)/html/*`; \ + if test "$$installfiles" = '$(srcdir)/html/*'; \ + then echo '-- Nothing to install' ; \ + else \ + $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR); \ + for i in $$installfiles; do \ + echo '-- Installing '$$i ; \ + $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \ + done; \ + echo '-- Installing $(srcdir)/html/index.sgml' ; \ + $(INSTALL_DATA) $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) || :; \ + which gtkdoc-rebase >/dev/null && \ + gtkdoc-rebase --relative --dest-dir=$(DESTDIR) --html-dir=$(DESTDIR)$(TARGET_DIR) ; \ + fi + + +uninstall-local: + rm -f $(DESTDIR)$(TARGET_DIR)/* + +# +# Require gtk-doc when making dist +# +if ENABLE_GTK_DOC +dist-check-gtkdoc: +else +dist-check-gtkdoc: + @echo "*** gtk-doc must be installed (and --enable-gtk-doc) in order to make dist" + @false +endif + +dist-hook: dist-check-gtkdoc dist-hook-local + mkdir $(distdir)/tmpl + mkdir $(distdir)/xml + mkdir $(distdir)/html + -cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl + -cp $(srcdir)/xml/*.xml $(distdir)/xml + cp $(srcdir)/html/* $(distdir)/html + -cp $(srcdir)/$(DOC_MODULE).types $(distdir)/ + -cp $(srcdir)/$(DOC_MODULE)-sections.txt $(distdir)/ + cd $(distdir) && rm -f $(DISTCLEANFILES) + -gtkdoc-rebase --online --relative --html-dir=$(distdir)/html + +.PHONY : dist-hook-local docs diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.am.releasing b/Build/source/libs/cairo/cairo-src/build/Makefile.am.releasing new file mode 100644 index 00000000000..b17faabce2f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.am.releasing @@ -0,0 +1,194 @@ +# Some custom targets to make it easier to release things. +# +# To make real stable releases or devel snapshots, use either: +# make release-check +# or make release-publish +# +# To make a quick properly named (date and git hash stamped) tarball: +# make snapshot + + +TAR_OPTIONS = --owner=0 --group=0 + +dist-hook: dist-clear-sticky-bits + +# Clean up any sticky bits we may inherit from parent dir +dist-clear-sticky-bits: + chmod -R a-s $(distdir) + + +snapshot: + distdir="$(distdir)-`date '+%Y%m%d'`"; \ + test -d "$(srcdir)/.git" && distdir=$$distdir-`cd "$(srcdir)" && git rev-parse HEAD | cut -c 1-6`; \ + TAR_OPTIONS="$(TAR_OPTIONS)" $(MAKE) $(AM_MAKEFLAGS) distdir="$$distdir" snapshot-dist + +snapshot-dist: dist + @(echo "$(distdir) archives ready for distribution: "; \ + list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ + sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' + +RELEASE_OR_SNAPSHOT = $$(if test "x$(CAIRO_VERSION_MINOR)" = "x$$(echo "$(CAIRO_VERSION_MINOR)/2*2" | bc)" ; then echo release; else echo snapshot; fi) +RELEASE_UPLOAD_HOST = cairographics.org +RELEASE_UPLOAD_BASE = /srv/cairo.freedesktop.org/www +RELEASE_UPLOAD_DIR = $(RELEASE_UPLOAD_BASE)/$(RELEASE_OR_SNAPSHOT)s +RELEASE_URL_BASE = http://cairographics.org/$(RELEASE_OR_SNAPSHOT)s +RELEASE_ANNOUNCE_LIST = cairo-announce@cairographics.org (and CC gnome-announce-list@gnome.org) + +MANUAL_VERSIONED = manual-$(VERSION) +MANUAL_TAR_FILE = $(MANUAL_VERSIONED).tar.gz +MANUAL_UPLOAD_DIR = $(RELEASE_UPLOAD_BASE) + +tar_file = $(PACKAGE)-$(VERSION).tar.xz +sha1_file = $(tar_file).sha1 +gpg_file = $(sha1_file).asc + +$(sha1_file): $(tar_file) + sha1sum $^ > $@ + +$(gpg_file): $(sha1_file) + @echo "Please enter your GPG password to sign the checksum." + gpg --armor --sign $^ + +release-verify-sane-changelogs: changelogs + @echo -n "Checking that the ChangeLog files are sane..." + @if grep -q "is required to generate" $(CHANGELOGS); then \ + (echo "Ouch." && echo "Some of the ChangeLogs are not generated correctly." \ + && echo "Remove ChangeLog* and make changelogs" \ + && false); else :; fi + @echo "Good." + +release-verify-sane-tests: + @echo "Checking that the test suite is sane..." + @cd test && $(MAKE) $(AM_MAKEFLAGS) release-verify-sane-tests + +release-verify-even-micro: + @echo -n "Checking that $(VERSION) has an even micro component..." + @test "$(CAIRO_VERSION_MICRO)" = "`echo $(CAIRO_VERSION_MICRO)/2*2 | bc`" \ + || (echo "Ouch." && echo "The version micro component '$(CAIRO_VERSION_MICRO)' is not an even number." \ + && echo "The version in configure.in must be incremented before a new release." \ + && false) + @echo "Good." + +release-verify-newer: + @echo -n "Checking that no $(VERSION) release already exists..." + @ssh $(RELEASE_UPLOAD_HOST) test ! -e $(RELEASE_UPLOAD_DIR)/$(tar_file) \ + || (echo "Ouch." && echo "Found: $(RELEASE_UPLOAD_HOST):$(RELEASE_UPLOAD_DIR)/$(tar_file)" \ + && echo "Are you sure you have an updated checkout?" \ + && echo "This should never happen." \ + && false) + @echo "Good." + +release-remove-old: + $(RM) $(tar_file) $(sha1_file) $(gpg_file) + + +# Strict ordering enforced for parallel make to work +release-check: \ + release-verify-even-micro \ + release-verify-sane-changelogs \ + release-verify-sane-tests \ + release-verify-newer \ + $(NULL) + $(MAKE) $(AM_MAKEFLAGS) release-remove-old + TAR_OPTIONS="$(TAR_OPTIONS)" $(MAKE) $(AM_MAKEFLAGS) distcheck + +release-upload: $(tar_file) $(sha1_file) $(gpg_file) + mkdir -p releases + scp $(tar_file) $(sha1_file) $(gpg_file) $(RELEASE_UPLOAD_HOST):$(RELEASE_UPLOAD_DIR) + mv $(tar_file) $(sha1_file) $(gpg_file) releases + ssh $(RELEASE_UPLOAD_HOST) "rm -f $(RELEASE_UPLOAD_DIR)/LATEST-$(PACKAGE)-[0-9]* && ln -s $(tar_file) $(RELEASE_UPLOAD_DIR)/LATEST-$(PACKAGE)-$(VERSION)" + git tag -s -m "cairo $(CAIRO_VERSION_MAJOR).$(CAIRO_VERSION_MINOR).$(CAIRO_VERSION_MICRO) release" $(CAIRO_VERSION_MAJOR).$(CAIRO_VERSION_MINOR).$(CAIRO_VERSION_MICRO) + +release-publish-message: releases/$(sha1_file) + @echo "Please follow the instructions in RELEASING to push stuff out and" + @echo "send out the announcement mails. Here is the excerpt you need:" + @echo "" + @echo "Subject: $(PACKAGE) $(RELEASE_OR_SNAPSHOT) $(VERSION) now available" + @echo "" + @echo "============================== CUT HERE ==============================" + @echo "A new $(PACKAGE) $(RELEASE_OR_SNAPSHOT) $(VERSION) is now available from:" + @echo "" + @echo " $(RELEASE_URL_BASE)/$(tar_file)" + @echo "" + @echo " which can be verified with:" + @echo "" + @echo " $(RELEASE_URL_BASE)/$(sha1_file)" + @echo -n " " + @cat releases/$(sha1_file) + @echo "" + @echo " $(RELEASE_URL_BASE)/$(gpg_file)" + @echo " (signed by `getent passwd "$$USER" | cut -d: -f 5 | cut -d, -f 1`)" + @echo "" + @echo " Additionally, a git clone of the source tree:" + @echo "" + @echo " git clone git://git.cairographics.org/git/cairo" + @echo "" + @echo " will include a signed $(VERSION) tag which points to a commit named:" + @echo " `git cat-file tag $(VERSION) | grep ^object | sed -e 's,object ,,'`" + @echo "" + @echo " which can be verified with:" + @echo " git verify-tag $(VERSION)" + @echo "" + @echo " and can be checked out with a command such as:" + @echo " git checkout -b build $(VERSION)" + @echo "" + @echo "============================== CUT HERE ==============================" + +doc-publish-versioned: doc + rm -rf ./$(MANUAL_VERSIONED) + cp -a doc/public/html $(MANUAL_VERSIONED) + tar czf $(MANUAL_TAR_FILE) $(MANUAL_VERSIONED) + scp $(MANUAL_TAR_FILE) $(RELEASE_UPLOAD_HOST):$(MANUAL_UPLOAD_DIR) + ssh $(RELEASE_UPLOAD_HOST) "cd $(MANUAL_UPLOAD_DIR) && tar xzf $(MANUAL_TAR_FILE) && ln -sf $(MANUAL_TAR_FILE) cairo-$(MANUAL_TAR_FILE)" + +doc-publish-symlinks: + ssh $(RELEASE_UPLOAD_HOST) "cd $(MANUAL_UPLOAD_DIR) && rm -f manual && ln -s $(MANUAL_VERSIONED) manual && ln -sf $(MANUAL_TAR_FILE) cairo-manual.tar.gz" + +doc-publish: + $(MAKE) $(AM_MAKEFLAGS) doc-publish-versioned + @if test "$(RELEASE_OR_SNAPSHOT)" = release; then $(MAKE) $(AM_MAKEFLAGS) doc-publish-symlinks; fi + +# Strict ordering enforced for parallel make to work +release-publish: release-check + $(MAKE) $(AM_MAKEFLAGS) release-upload + $(MAKE) $(AM_MAKEFLAGS) doc-publish + $(MAKE) $(AM_MAKEFLAGS) release-publish-message + +if OS_WIN32 + +# Win32 package zipfiles +runtime_zip_file = $(PACKAGE)-$(VERSION).zip +developer_zip_file = $(PACKAGE)-dev-$(VERSION).zip + +$(runtime_zip_file): install + -$(RM) $@ + pwd=`pwd`; cd $(prefix); \ + zip "$$pwd"/$@ bin/libcairo-$(CAIRO_VERSION_SONUM).dll + +$(developer_zip_file): install + -$(RM) $@ + pwd=`pwd`; cd $(prefix); \ + zip -r "$$pwd"/$@ include/cairo lib/libcairo.dll.a lib/cairo.lib lib/pkgconfig/cairo.pc lib/pkgconfig/cairo-*.pc share/gtk-doc/html/cairo + +zips: $(runtime_zip_file) $(developer_zip_file) + +endif + + +.PHONY: \ + dist-clear-sticky-bits \ + doc-publish \ + doc-publish-symlinks \ + doc-publish-versioned \ + release-check \ + release-publish \ + release-publish-message \ + release-remove-old \ + release-upload \ + release-verify-even-micro \ + release-verify-newer \ + release-verify-sane-changelogs \ + release-verify-sane-tests \ + snapshot \ + snapshot-dist \ + $(NULL) diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.win32.common b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.common new file mode 100644 index 00000000000..7d7e9735f15 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.common @@ -0,0 +1,74 @@ +default: all + +# +# Edit build/Makefile.win32.features to enable features to build +# +include $(top_srcdir)/build/Makefile.win32.inform +include $(top_srcdir)/build/Makefile.win32.features +include $(top_srcdir)/build/Makefile.win32.features-h + +ifeq ($(top_builddir),) +top_builddir = $(top_srcdir) +endif + +CC := cl +LD := link +AR := lib + +ifeq ($(CFG),debug) +CFG_CFLAGS := -MDd -Od -Zi +CFG_LDFLAGS := -DEBUG +else +CFG_CFLAGS := -MD -O2 +CFG_LDFLAGS := +endif + +ifeq ($(PIXMAN_PATH),) +PIXMAN_PATH := $(top_builddir)/../pixman +endif +PIXMAN_CFLAGS := -I$(PIXMAN_PATH)/pixman/ +PIXMAN_LIBS := $(PIXMAN_PATH)/pixman/$(CFG)/pixman-1.lib + +CAIRO_LIBS = gdi32.lib msimg32.lib user32.lib + +ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) +ifeq ($(LIBPNG_PATH),) +LIBPNG_PATH := $(top_builddir)/../libpng +endif +LIBPNG_CFLAGS += -I$(LIBPNG_PATH)/ +CAIRO_LIBS += $(LIBPNG_PATH)/libpng.lib +endif + +ifeq ($(CAIRO_HAS_PS_SURFACE)$(CAIRO_HAS_PDF_SURFACE),00) +else +ifeq ($(ZLIB_PATH),) +ZLIB_PATH := $(top_builddir)/../zlib +endif +ZLIB_CFLAGS += -I$(ZLIB_PATH)/ +CAIRO_LIBS += $(ZLIB_PATH)/zdll.lib +endif + +DEFAULT_CFLAGS = -nologo $(CFG_CFLAGS) +DEFAULT_CFLAGS += -I. -I$(top_srcdir) -I$(top_srcdir)/src +DEFAULT_CFLAGS += $(PIXMAN_CFLAGS) $(LIBPNG_CFLAGS) $(ZLIB_CFLAGS) + +CAIRO_CFLAGS = $(DEFAULT_CFLAGS) $(CFLAGS) + +DEFAULT_LDFLAGS = -nologo $(CFG_LDFLAGS) +DEFAULT_ARFLAGS = -nologo + +CAIRO_LDFLAGS = $(DEFAULT_LDFLAGS) $(LDFLAGS) +CAIRO_ARFLAGS = $(DEFAULT_ARFLAGS) $(LDFLAGS) + +# Some generic rules + +$(CFG)/%.obj: %.c $(top_srcdir)/src/cairo-features.h + @mkdir -p $(CFG)/`dirname $<` + @$(CC) $(CAIRO_CFLAGS) -c -Fo"$@" $< + +$(CFG)/%-static.obj: %.c $(top_srcdir)/src/cairo-features.h + @mkdir -p $(CFG)/`dirname $<` + @$(CC) $(CAIRO_CFLAGS) -c -DCAIRO_WIN32_STATIC_BUILD=1 -Fo"$@" $< + +clean: + @rm -f $(CFG)/*.obj $(CFG)/*.dll $(CFG)/*.lib $(CFG)/*.pdb $(CFG)/*.ilk || exit 0 diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.win32.features b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.features new file mode 100644 index 00000000000..8cb155dc084 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.features @@ -0,0 +1,41 @@ +# Generated by configure. Modify to customize. + +CAIRO_HAS_XLIB_SURFACE=0 +CAIRO_HAS_XLIB_XRENDER_SURFACE=0 +CAIRO_HAS_XCB_SURFACE=0 +CAIRO_HAS_XLIB_XCB_FUNCTIONS=0 +CAIRO_HAS_XCB_SHM_FUNCTIONS=0 +CAIRO_HAS_QT_SURFACE=0 +CAIRO_HAS_QUARTZ_SURFACE=0 +CAIRO_HAS_QUARTZ_FONT=0 +CAIRO_HAS_QUARTZ_IMAGE_SURFACE=0 +CAIRO_HAS_WIN32_SURFACE=1 +CAIRO_HAS_WIN32_FONT=1 +CAIRO_HAS_SKIA_SURFACE=0 +CAIRO_HAS_OS2_SURFACE=0 +CAIRO_HAS_BEOS_SURFACE=0 +CAIRO_HAS_DRM_SURFACE=0 +CAIRO_HAS_GALLIUM_SURFACE=0 +CAIRO_HAS_PNG_FUNCTIONS=1 +CAIRO_HAS_GL_SURFACE=0 +CAIRO_HAS_GLESV2_SURFACE=0 +CAIRO_HAS_COGL_SURFACE=0 +CAIRO_HAS_DIRECTFB_SURFACE=0 +CAIRO_HAS_VG_SURFACE=0 +CAIRO_HAS_EGL_FUNCTIONS=0 +CAIRO_HAS_GLX_FUNCTIONS=0 +CAIRO_HAS_WGL_FUNCTIONS=0 +CAIRO_HAS_SCRIPT_SURFACE=1 +CAIRO_HAS_FT_FONT=0 +CAIRO_HAS_FC_FONT=0 +CAIRO_HAS_PS_SURFACE=1 +CAIRO_HAS_PDF_SURFACE=1 +CAIRO_HAS_SVG_SURFACE=1 +CAIRO_HAS_TEST_SURFACES=0 +CAIRO_HAS_TEE_SURFACE=0 +CAIRO_HAS_XML_SURFACE=0 +CAIRO_HAS_PTHREAD=0 +CAIRO_HAS_GOBJECT_FUNCTIONS=0 +CAIRO_HAS_TRACE=0 +CAIRO_HAS_INTERPRETER=1 +CAIRO_HAS_SYMBOL_LOOKUP=0 diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.win32.features-h b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.features-h new file mode 100644 index 00000000000..13904cfa9f0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.features-h @@ -0,0 +1,130 @@ +# Generated by configure. Do not edit. + +$(top_srcdir)/src/cairo-features.h: $(top_srcdir)/build/Makefile.win32.features + @echo "Generating src/cairo-features.h" + @echo "/* Generated by Makefile.win32.features-h. Do not edit. */" > $(top_srcdir)/src/cairo-features.h + @echo "#ifndef CAIRO_FEATURES_H" >> $(top_srcdir)/src/cairo-features.h + @echo "#define CAIRO_FEATURES_H 1" >> $(top_srcdir)/src/cairo-features.h +ifeq ($(CAIRO_HAS_XLIB_SURFACE),1) + @echo "#define CAIRO_HAS_XLIB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_XLIB_XRENDER_SURFACE),1) + @echo "#define CAIRO_HAS_XLIB_XRENDER_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_XCB_SURFACE),1) + @echo "#define CAIRO_HAS_XCB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_XLIB_XCB_FUNCTIONS),1) + @echo "#define CAIRO_HAS_XLIB_XCB_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_XCB_SHM_FUNCTIONS),1) + @echo "#define CAIRO_HAS_XCB_SHM_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_QT_SURFACE),1) + @echo "#define CAIRO_HAS_QT_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_QUARTZ_SURFACE),1) + @echo "#define CAIRO_HAS_QUARTZ_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_QUARTZ_FONT),1) + @echo "#define CAIRO_HAS_QUARTZ_FONT 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_QUARTZ_IMAGE_SURFACE),1) + @echo "#define CAIRO_HAS_QUARTZ_IMAGE_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_WIN32_SURFACE),1) + @echo "#define CAIRO_HAS_WIN32_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_WIN32_FONT),1) + @echo "#define CAIRO_HAS_WIN32_FONT 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_SKIA_SURFACE),1) + @echo "#define CAIRO_HAS_SKIA_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_OS2_SURFACE),1) + @echo "#define CAIRO_HAS_OS2_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_BEOS_SURFACE),1) + @echo "#define CAIRO_HAS_BEOS_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_DRM_SURFACE),1) + @echo "#define CAIRO_HAS_DRM_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1) + @echo "#define CAIRO_HAS_GALLIUM_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) + @echo "#define CAIRO_HAS_PNG_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_GL_SURFACE),1) + @echo "#define CAIRO_HAS_GL_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_GLESV2_SURFACE),1) + @echo "#define CAIRO_HAS_GLESV2_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_COGL_SURFACE),1) + @echo "#define CAIRO_HAS_COGL_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1) + @echo "#define CAIRO_HAS_DIRECTFB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_VG_SURFACE),1) + @echo "#define CAIRO_HAS_VG_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1) + @echo "#define CAIRO_HAS_EGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_GLX_FUNCTIONS),1) + @echo "#define CAIRO_HAS_GLX_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1) + @echo "#define CAIRO_HAS_WGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1) + @echo "#define CAIRO_HAS_SCRIPT_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_FT_FONT),1) + @echo "#define CAIRO_HAS_FT_FONT 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_FC_FONT),1) + @echo "#define CAIRO_HAS_FC_FONT 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_PS_SURFACE),1) + @echo "#define CAIRO_HAS_PS_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_PDF_SURFACE),1) + @echo "#define CAIRO_HAS_PDF_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_SVG_SURFACE),1) + @echo "#define CAIRO_HAS_SVG_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_TEST_SURFACES),1) + @echo "#define CAIRO_HAS_TEST_SURFACES 1" >> $(top_srcdir)/src/cairo-features.h +endif + @echo "#define CAIRO_HAS_IMAGE_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h + @echo "#define CAIRO_HAS_MIME_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h + @echo "#define CAIRO_HAS_RECORDING_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h + @echo "#define CAIRO_HAS_OBSERVER_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +ifeq ($(CAIRO_HAS_TEE_SURFACE),1) + @echo "#define CAIRO_HAS_TEE_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_XML_SURFACE),1) + @echo "#define CAIRO_HAS_XML_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h +endif + @echo "#define CAIRO_HAS_USER_FONT 1" >> $(top_srcdir)/src/cairo-features.h +ifeq ($(CAIRO_HAS_PTHREAD),1) + @echo "#define CAIRO_HAS_PTHREAD 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_GOBJECT_FUNCTIONS),1) + @echo "#define CAIRO_HAS_GOBJECT_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_TRACE),1) + @echo "#define CAIRO_HAS_TRACE 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_INTERPRETER),1) + @echo "#define CAIRO_HAS_INTERPRETER 1" >> $(top_srcdir)/src/cairo-features.h +endif +ifeq ($(CAIRO_HAS_SYMBOL_LOOKUP),1) + @echo "#define CAIRO_HAS_SYMBOL_LOOKUP 1" >> $(top_srcdir)/src/cairo-features.h +endif + @echo "#endif" >> $(top_srcdir)/src/cairo-features.h diff --git a/Build/source/libs/cairo/cairo-src/build/Makefile.win32.inform b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.inform new file mode 100644 index 00000000000..ba11165050a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/Makefile.win32.inform @@ -0,0 +1,13 @@ +inform: + @echo +ifneq ($(CFG),release) +ifneq ($(CFG),debug) + @echo "Invalid configuration "$(CFG)" specified." + @echo -n "You must specify a configuration when " + @echo "running make, e.g. make CFG=debug" + @echo + @echo -n "Possible choices for configuration are " + @echo "'release' and 'debug'" + @exit 1 +endif +endif diff --git a/Build/source/libs/cairo/cairo-src/build/aclocal.cairo.m4 b/Build/source/libs/cairo/cairo-src/build/aclocal.cairo.m4 new file mode 100644 index 00000000000..44ba5fdf6f5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/aclocal.cairo.m4 @@ -0,0 +1,228 @@ +dnl ========================================================================== +dnl +dnl Cairo-specific macros +dnl + +dnl ========================================================================== + +dnl Usage: +dnl CAIRO_BIGENDIAN +dnl +AC_DEFUN([CAIRO_BIGENDIAN], +[dnl + case $host_os in + darwin*) + AH_VERBATIM([X_BYTE_ORDER], +[ +/* Deal with multiple architecture compiles on Mac OS X */ +#ifdef __APPLE_CC__ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#define FLOAT_WORDS_BIGENDIAN 1 +#else +#undef WORDS_BIGENDIAN +#undef FLOAT_WORDS_BIGENDIAN +#endif +#endif +]) + ;; + *) + AC_C_BIGENDIAN + AX_C_FLOAT_WORDS_BIGENDIAN + ;; + esac +]) + +dnl CAIRO_CHECK_FUNCS_WITH_FLAGS(FUNCTION..., CFLAGS, LIBS +dnl [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) +dnl Like AC_CHECK_FUNCS but with additional CFLAGS and LIBS +dnl -------------------------------------------------------------------- +AC_DEFUN([CAIRO_CHECK_FUNCS_WITH_FLAGS], +[dnl + _save_cflags="$CFLAGS" + _save_libs="$LIBS" + CFLAGS="$CFLAGS $2" + LIBS="$LIBS $3" + AC_CHECK_FUNCS($1, $4, $5) + CFLAGS="$_save_cflags" + LIBS="$_save_libs" +]) + +dnl CAIRO_CONFIG_COMMANDS is like AC_CONFIG_COMMANDS, except that: +dnl +dnl 1) It redirects the stdout of the command to the file. +dnl 2) It does not recreate the file if contents didn't change. +dnl +AC_DEFUN([CAIRO_CONFIG_COMMANDS], +[dnl + AC_CONFIG_COMMANDS($1, + [ + _config_file=$1 + _tmp_file=cairoconf.tmp + AC_MSG_NOTICE([creating $_config_file]) + { + $2 + } >> "$_tmp_file" || + AC_MSG_ERROR([failed to write to $_tmp_file]) + + if cmp -s "$_tmp_file" "$_config_file"; then + AC_MSG_NOTICE([$_config_file is unchanged]) + rm -f "$_tmp_file" + else + mv "$_tmp_file" "$_config_file" || + AC_MSG_ERROR([failed to update $_config_file]) + fi + ], $3) +]) + +dnl CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(env-setup, program, +dnl true-action, false-action) +dnl +dnl Compile and link the program with the given environment setup. +dnl The global cairo_cc_flag is set to "yes" or "no" according as +dnl the link succeeded or not. The link step must complete without +dnl warnings or errors to stderr. +dnl +dnl Perform true-action on success and false-action on failure. +dnl The values of CFLAGS, LIBS, LDFLAGS are saved before env-setup +dnl is executed and restored right before the end of the macro. +AC_DEFUN([CAIRO_CC_TRY_LINK_WITH_ENV_SILENT],[dnl + # AC_LANG_PROGRAM() produces a main() w/o args, + # but -Wold-style-definition doesn't like that. + # We need _some_ program so that we don't get + # warnings about empty compilation units, so always + # append a reasonable main(). + _compile_program="$2"' + int main(int c, char **v) { (void)c; (void)v; return 0; }' + + _save_cflags="$CFLAGS" + _save_ldflags="$LDFLAGS" + _save_libs="$LIBS" + $1 + AC_LINK_IFELSE( + [AC_LANG_SOURCE([$_compile_program])], + [cairo_cc_stderr=`test -f conftest.err && cat conftest.err` + cairo_cc_flag=yes], + [cairo_cc_stderr=`test -f conftest.err && cat conftest.err` + cairo_cc_flag=no]) + + if test "x$cairo_cc_stderr" != "x"; then + cairo_cc_flag=no + fi + + if test "x$cairo_cc_flag" = "xyes"; then + ifelse([$3], , :, [$3]) + else + ifelse([$4], , :, [$4]) + fi + CFLAGS="$_save_cflags" + LDFLAGS="$_save_ldflags" + LIBS="$_save_libs" +]) + +dnl check compiler flags with a program and no muttering. +AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT], +[dnl (flags..., optional program, true-action, false-action) + CAIRO_CC_TRY_LINK_WITH_ENV_SILENT([CFLAGS="$CFLAGS $1"], + [$2], [$3], [$4]) +]) + +dnl find a -Werror equivalent +AC_DEFUN([CAIRO_CC_CHECK_WERROR], +[dnl + _test_WERROR=${WERROR+set} + if test "z$_test_WERROR" != zset; then + WERROR="" + for _werror in -Werror -errwarn; do + AC_MSG_CHECKING([whether $CC supports $_werror]) + CAIRO_CC_TRY_FLAG_SILENT( + [$_werror],, + [WERROR="$WERROR $_werror"], + [:]) + AC_MSG_RESULT($cairo_cc_flag) + done + fi +]) + +dnl check compiler flags possibly using -Werror if available. +AC_DEFUN([CAIRO_CC_TRY_FLAG], +[dnl (flags..., optional program, true-action, false-action) + CAIRO_CC_CHECK_WERROR + AC_MSG_CHECKING([whether $CC supports $1]) + CAIRO_CC_TRY_FLAG_SILENT([$WERROR $1], [$2], [$3], [$4]) + AC_MSG_RESULT([$cairo_cc_flag]) +]) + +dnl Usage: +dnl CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES +AC_DEFUN([CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES], +[dnl + AC_CACHE_CHECK([for native atomic primitives], cairo_cv_atomic_primitives, + [ + cairo_cv_atomic_primitives="none" + + AC_TRY_LINK([ +int atomic_add(int i) { return __sync_fetch_and_add (&i, 1); } +int atomic_cmpxchg(int i, int j, int k) { return __sync_val_compare_and_swap (&i, j, k); } +], [], + cairo_cv_atomic_primitives="Intel" + ) + + AC_TRY_LINK([ +int atomic_add(int i) { return __atomic_fetch_add(&i, 1, __ATOMIC_SEQ_CST); } +int atomic_cmpxchg(int i, int j, int k) { return __atomic_compare_exchange_n(&i, &j, k, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } +], [], + cairo_cv_atomic_primitives="cxx11" + ) + + if test "x$cairo_cv_atomic_primitives" = "xnone"; then + AC_CHECK_HEADER([atomic_ops.h], + cairo_cv_atomic_primitives="libatomic-ops") + fi + + if test "x$cairo_cv_atomic_primitives" = "xnone"; then + AC_CHECK_HEADER([libkern/OSAtomic.h], + cairo_cv_atomic_primitives="OSAtomic") + fi + ]) + if test "x$cairo_cv_atomic_primitives" = xcxx11; then + AC_DEFINE(HAVE_CXX11_ATOMIC_PRIMITIVES, 1, + [Enable if your compiler supports the GCC __atomic_* atomic primitives]) + fi + + if test "x$cairo_cv_atomic_primitives" = xIntel; then + AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, + [Enable if your compiler supports the Intel __sync_* atomic primitives]) + fi + + if test "x$cairo_cv_atomic_primitives" = "xlibatomic-ops"; then + AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, + [Enable if you have libatomic-ops-dev installed]) + fi + + if test "x$cairo_cv_atomic_primitives" = xOSAtomic; then + AC_DEFINE(HAVE_OS_ATOMIC_OPS, 1, + [Enable if you have MacOS X atomic operations]) + fi +]) + +dnl Usage: +dnl CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER +AC_DEFUN([CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER], +[dnl + AC_CACHE_CHECK([whether atomic ops require a memory barrier], cairo_cv_atomic_op_needs_memory_barrier, + [ + case $host_cpu in + i?86) cairo_cv_atomic_op_needs_memory_barrier="no" ;; + x86_64) cairo_cv_atomic_op_needs_memory_barrier="no" ;; + arm*) cairo_cv_atomic_op_needs_memory_barrier="no" ;; + *) cairo_cv_atomic_op_needs_memory_barrier="yes" ;; + esac + ]) + if test "x$cairo_cv_atomic_op_needs_memory_barrier" = "xyes"; then + AC_DEFINE_UNQUOTED(ATOMIC_OP_NEEDS_MEMORY_BARRIER, 1, + [whether memory barriers are needed around atomic operations]) + fi +]) + +AC_DEFUN([CAIRO_TEXT_WRAP], [m4_text_wrap([$1], [$2],, 78)]) diff --git a/Build/source/libs/cairo/cairo-src/build/aclocal.compare.m4 b/Build/source/libs/cairo/cairo-src/build/aclocal.compare.m4 new file mode 100644 index 00000000000..bd6c51b289d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/aclocal.compare.m4 @@ -0,0 +1,162 @@ +dnl @synopsis AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +dnl +dnl This macro compares two version strings. It is used heavily in the +dnl macro _AX_PATH_BDB for library checking. Due to the various number +dnl of minor-version numbers that can exist, and the fact that string +dnl comparisons are not compatible with numeric comparisons, this is +dnl not necessarily trivial to do in a autoconf script. This macro +dnl makes doing these comparisons easy. +dnl +dnl The six basic comparisons are available, as well as checking +dnl equality limited to a certain number of minor-version levels. +dnl +dnl The operator OP determines what type of comparison to do, and can +dnl be one of: +dnl +dnl eq - equal (test A == B) +dnl ne - not equal (test A != B) +dnl le - less than or equal (test A <= B) +dnl ge - greater than or equal (test A >= B) +dnl lt - less than (test A < B) +dnl gt - greater than (test A > B) +dnl +dnl Additionally, the eq and ne operator can have a number after it to +dnl limit the test to that number of minor versions. +dnl +dnl eq0 - equal up to the length of the shorter version +dnl ne0 - not equal up to the length of the shorter version +dnl eqN - equal up to N sub-version levels +dnl neN - not equal up to N sub-version levels +dnl +dnl When the condition is true, shell commands ACTION-IF-TRUE are run, +dnl otherwise shell commands ACTION-IF-FALSE are run. The environment +dnl variable 'ax_compare_version' is always set to either 'true' or +dnl 'false' as well. +dnl +dnl Examples: +dnl +dnl AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) +dnl AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) +dnl +dnl would both be true. +dnl +dnl AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) +dnl AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) +dnl +dnl would both be false. +dnl +dnl AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) +dnl +dnl would be true because it is only comparing two minor versions. +dnl +dnl AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) +dnl +dnl would be true because it is only comparing the lesser number of +dnl minor versions of the two values. +dnl +dnl Note: The characters that separate the version numbers do not +dnl matter. An empty string is the same as version 0. OP is evaluated +dnl by autoconf, not configure, so must be a string, not a variable. +dnl +dnl The author would like to acknowledge Guido Draheim whose advice +dnl about the m4_case and m4_ifvaln functions make this macro only +dnl include the portions necessary to perform the specific comparison +dnl specified by the OP argument in the final configure script. +dnl +dnl @category Misc +dnl @author Tim Toolan +dnl @version 2004-03-01 +dnl @license GPLWithACException + +dnl ######################################################################### +AC_DEFUN([AX_COMPARE_VERSION], [ + # Used to indicate true or false condition + ax_compare_version=false + + # Convert the two version strings to be compared into a format that + # allows a simple string comparison. The end result is that a version + # string of the form 1.12.5-r617 will be converted to the form + # 0001001200050617. In other words, each number is zero padded to four + # digits, and non digits are removed. + AS_VAR_PUSHDEF([A],[ax_compare_version_A]) + A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + AS_VAR_PUSHDEF([B],[ax_compare_version_B]) + B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary + dnl # then the first line is used to determine if the condition is true. + dnl # The sed right after the echo is to remove any indented white space. + m4_case(m4_tolower($2), + [lt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [gt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [le],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ], + [ge],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ],[ + dnl Split the operator from the subversion count if present. + m4_bmatch(m4_substr($2,2), + [0],[ + # A count of zero means use the length of the shorter version. + # Determine the number of characters in A and B. + ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'` + ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'` + + # Set A to no more than B's length and B to no more than A's length. + A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` + B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` + ], + [[0-9]+],[ + # A count greater than zero means use only that many subversions + A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + ], + [.+],[ + AC_WARNING( + [illegal OP numeric parameter: $2]) + ],[]) + + # Pad zeros at end of numbers to make same length. + ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" + B="$B`echo $A | sed 's/./0/g'`" + A="$ax_compare_version_tmp_A" + + # Check for equality or inequality as necessary. + m4_case(m4_tolower(m4_substr($2,0,2)), + [eq],[ + test "x$A" = "x$B" && ax_compare_version=true + ], + [ne],[ + test "x$A" != "x$B" && ax_compare_version=true + ],[ + AC_WARNING([illegal OP parameter: $2]) + ]) + ]) + + AS_VAR_POPDEF([A])dnl + AS_VAR_POPDEF([B])dnl + + dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. + if test "$ax_compare_version" = "true" ; then + m4_ifvaln([$4],[$4],[:])dnl + m4_ifvaln([$5],[else $5])dnl + fi +]) dnl AX_COMPARE_VERSION diff --git a/Build/source/libs/cairo/cairo-src/build/aclocal.enable.m4 b/Build/source/libs/cairo/cairo-src/build/aclocal.enable.m4 new file mode 100644 index 00000000000..f3522b9832c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/aclocal.enable.m4 @@ -0,0 +1,409 @@ +dnl +dnl These are the facilities for enable/disabling various features, +dnl and for collecting CFLAGS/LIBS and generating per feature .pc +dnl files, assembling list of source files to compile, creating +dnl cairo-features.h and other generated files, etc... +dnl + +dnl =========================================================================== + +dnl +dnl Define a macro to enable features +dnl - Macro: _CAIRO_ENABLE (ID, NAME, WHAT, DEFAULT, COMMANDS) +dnl +dnl where: +dnl +dnl ID is the sub-namespace in function names, eg. "ft" for cairo_ft_... +dnl NAME is the human-readable name of the feature, eg. "FreeType font" +dnl WHAT is the type of feature: +dnl "surface" for surface backends +dnl "font" for font backends +dnl "functions" for set of functions +dnl "" for private configurations +dnl DEFAULT is the default state of the feature: +dnl "no" for experimental features, eg. your favorite new backend +dnl "yes" for recommended features, eg. png functions +dnl "auto" for other supported features, eg. xlib surface backend +dnl "always" for mandatory features (can't be disabled), eg. image surface backend +dnl COMMANDS are run to check whether the feature can be enabled. +dnl They should set use_$(ID) to something other than yes if the +dnl feature cannot be built, eg. "no (requires SomeThing)". It then +dnl should also set $(ID)_REQUIRES/CFLAGS/LIBS/... +dnl appropriately. Look at the macro definition for more details, +dnl or ask if in doubt. +dnl +AC_DEFUN([_CAIRO_ENABLE], +[dnl + dnl Sanity check ID + m4_if( + [$1], + m4_tolower(AS_TR_SH([$1])), + , + [m4_fatal([invalid feature name `$1'])] + )dnl + m4_pushdef([cr_feature], [$1])dnl + m4_pushdef([cr_feature_name], m4_normalize([$2]))dnl + m4_pushdef([cr_feature_what], m4_normalize([$3]))dnl + m4_pushdef([cr_feature_default], m4_normalize([$4]))dnl + m4_pushdef([cr_feature_commands], [$5])dnl + dnl + m4_pushdef([cr_feature_arg], m4_translit([$1],_,-))dnl + dnl + dnl Sanity check default + m4_case( + cr_feature_default, + [no],, + [yes],, + [auto],, + [always],, + [m4_fatal([Invalid default value `]cr_feature_default[' for feature `]cr_feature['])] + )dnl + dnl + m4_if(cr_feature_default, [always], + [dnl + enable_$1=yes + ],[dnl + AC_ARG_ENABLE(cr_feature_arg, + AS_HELP_STRING([--enable-]cr_feature_arg[=@<:@no/auto/yes@:>@], + [Enable cairo's ]cr_feature_name[ feature @<:@default=]cr_feature_default[@:>@]), + enable_$1=$enableval, enable_$1=cr_feature_default) + ])dnl + dnl + AS_CASE([$enable_$1], + [no],[dnl + use_$1="no (disabled, use --enable-cr_feature_arg to enable)" + ],dnl + [yes|auto],[dnl + AC_MSG_CHECKING([for cairo's ]cr_feature_name[ feature]) + echo + + use_[]$1=yes + CAIRO_FEATURE_VARS_FOREACH(cr_var, [cr_feature[_]cr_var[=]_CAIRO_SH_ESCAPE_UNQUOTED(m4_do([cr_var_default_]cr_var[_value]))]m4_newline) + + cr_feature_commands + + AC_MSG_CHECKING([whether cairo's ]cr_feature_name[ feature could be enabled]) + AC_MSG_RESULT([$use_$1]) + + AS_IF([test "x$enable_$1" = "xyes" -a "x$use_$1" != xyes], + [dnl + AC_MSG_ERROR( + m4_case(cr_feature_default, + [always], [mandatory], + [yes], [recommended], + , [requested] + ) cr_feature_name[ feature could not be enabled]) + ])dnl + ],dnl + [dnl + AC_MSG_ERROR([invalid argument passed to --enable-]cr_feature_arg[: `$use_$1', should be one of @<:@no/auto/yes@:>@]) + ])dnl + + AS_IF([test "x$use_$1" = "xyes"], + [dnl + CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH([cr_var], + [dnl + CAIRO_ACCUMULATE_UNQUOTED_BEFORE(cr_var, [$]cr_feature[_]cr_var) + ])dnl + ],[dnl + dnl If not enabled, empty the vars so no one accidentally uses them. + CAIRO_FEATURE_VARS_FOREACH([cr_var], [unset cr_feature[_]cr_var]m4_newline) + ])dnl + + _CAIRO_FEATURE_HOOKS(cr_feature, cr_feature_name, cr_feature_default, cr_feature_what)dnl + + m4_popdef([cr_feature])dnl + m4_popdef([cr_feature_name])dnl + m4_popdef([cr_feature_what])dnl + m4_popdef([cr_feature_default])dnl + m4_popdef([cr_feature_commands])dnl + m4_popdef([cr_feature_arg])dnl +]) + + +dnl =========================================================================== + +m4_define([_CAIRO_FEATURE_VARS]) + +dnl +dnl CAIRO_FEATURE_VARS_REGISTER(VARS, DEFAULT-VALUE=[]) +dnl +dnl Registers variables to be collected from feature-enabling code segments. +dnl VARS should be a whitespace-separate list of variable names. +dnl +dnl DEFAULT-VALUE is m4 macros to set default value of VARS +dnl +AC_DEFUN([CAIRO_FEATURE_VARS_REGISTER], +[dnl + m4_foreach_w([cr_var], [$1], + [m4_append_uniq([_CAIRO_FEATURE_VARS], cr_var, [ ],, + [m4_fatal([Feature variable `]cr_var[' already registered])])])dnl + m4_foreach_w([cr_var], [$1], + [dnl + m4_define([cr_var_default_]cr_var[_value], m4_default([$2],[[$ac_env_[]]cr_feature[[]_]]cr_var[[_value]]))dnl + ])dnl +]) + +dnl +dnl CAIRO_FEATURE_VARS_FOREACH(VAR, COMMANDS) +dnl +dnl Run COMMANDS for each registered feature variable. +dnl Defines VAR to the variable being processed. +dnl +AC_DEFUN([CAIRO_FEATURE_VARS_FOREACH], +[dnl + m4_foreach_w([$1], _CAIRO_FEATURE_VARS, [$2])dnl +]) + + +dnl =========================================================================== + +m4_define([_CAIRO_ACCUMULATORS])dnl + +m4_define([_CAIRO_ACCUMULATORS_REGISTER], +[dnl + m4_foreach_w([cr_var], [$1], + [m4_append_uniq([_CAIRO_ACCUMULATORS], cr_var, [ ],, + [m4_fatal([Accumulator `]cr_var[' already registered])])])dnl + m4_foreach_w([cr_var], [$1], [m4_define([cr_acc_]cr_var[_sep], [$2])])dnl + m4_foreach_w([cr_var], [$1], [[CAIRO_]cr_var[=$3]]m4_newline)dnl + m4_foreach_w([cr_var], [$1], [m4_pattern_allow([CAIRO_]cr_var)])dnl +])dnl + +m4_define([_CAIRO_SH_ESCAPE],['m4_bpatsubst([$1],['],[\\'])'])dnl +m4_define([_CAIRO_SH_ESCAPE_UNQUOTED],["m4_bpatsubst([$1],["],[\\"])"])dnl + +dnl +dnl CAIRO_ACCUMULATORS_REGISTER(VARS, SEPARATOR=[], INITIAL-VALUE=[]) +dnl +dnl Registers accumulators. An accumulator is a shell variable that can +dnl be accumulated to. The macros take care of adding a SEPARATOR between +dnl accumulated values. +dnl +dnl VARS should be a whitespace-separate list of variable names. The actual +dnl shell variable resulting for each variable is prefixed with CAIRO_. +dnl +AC_DEFUN([CAIRO_ACCUMULATORS_REGISTER], +[dnl + _CAIRO_ACCUMULATORS_REGISTER([$1],[$2],_CAIRO_SH_ESCAPE([$3]))dnl +])dnl + +dnl +dnl Like CAIRO_ACCUMULATORS_REGISTER but INITIAL-VALUE is left unquoted, +dnl so it can reference other shell variables for example. +dnl +AC_DEFUN([CAIRO_ACCUMULATORS_REGISTER_UNQUOTED], +[dnl + _CAIRO_ACCUMULATORS_REGISTER([$1],[$2],_CAIRO_SH_ESCAPE_UNQUOTED([$3]))dnl +])dnl + +m4_define([_CAIRO_ACCUMULATOR_CHECK], +[dnl + m4_ifdef([cr_acc_$1_sep],,[m4_fatal([Accumulator `]$1[' not defined.])])dnl +])dnl + +m4_define([_CAIRO_ACCUMULATE], +[dnl + _CAIRO_ACCUMULATOR_CHECK([$1])dnl + m4_ifval([$2], [$3]m4_newline)dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATE(VAR, VALUE) +dnl +dnl Appends VALUE to accumulator VAR +dnl +AC_DEFUN([CAIRO_ACCUMULATE], +[dnl + _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["_CAIRO_SH_ESCAPE([$2])])dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATE_BEFORE(VAR, VALUE) +dnl +dnl Prepends VALUE to accumulator VAR +dnl +AC_DEFUN([CAIRO_ACCUMULATE_BEFORE], +[dnl + _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1=_CAIRO_SH_ESCAPE([$2])"]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl +])dnl + +m4_define([_CAIRO_ACCUMULATE_UNQUOTED], +[dnl + _CAIRO_ACCUMULATOR_CHECK([$1])dnl + m4_ifval([$2], [m4_bmatch([$2],[[$]],[test -n "$2" &&]) $3]m4_newline)dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATE_UNQUOTED(VAR, VALUE) +dnl +dnl Like CAIRO_ACCUMULATE but VALUE is left unquoted, +dnl so it can reference other shell variables for example. +dnl +AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED], +[dnl + _CAIRO_ACCUMULATE_UNQUOTED([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["]_CAIRO_SH_ESCAPE_UNQUOTED([$2]))dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATE_UNQUOTED_BEFORE(VAR, VALUE) +dnl +dnl Like CAIRO_ACCUMULATE_BEFORE but VALUE is left unquoted, +dnl so it can reference other shell variables for example. +dnl +AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_BEFORE], +[dnl + _CAIRO_ACCUMULATE_UNQUOTED([$1], [$2], [CAIRO_$1=]_CAIRO_SH_ESCAPE_UNQUOTED([$2])["]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED(VAR, VALUE) +dnl +dnl Like CAIRO_ACCUMULATE_UNQUOTED but VALUE is not tested for emptiness. +dnl +AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED], +[dnl + _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1="${CAIRO_$1}]m4_do([cr_acc_$1_sep])["]_CAIRO_SH_ESCAPE_UNQUOTED([$2]))dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED_BEFORE(VAR, VALUE) +dnl +dnl Like CAIRO_ACCUMULATE_UNQUOTED_BEFORE but VALUE is not tested for emptiness. +dnl +AC_DEFUN([CAIRO_ACCUMULATE_UNQUOTED_BEFORE], +[dnl + _CAIRO_ACCUMULATE([$1], [$2], [CAIRO_$1=]_CAIRO_SH_ESCAPE_UNQUOTED([$2])["]m4_do([cr_acc_$1_sep])[${CAIRO_$1}"])dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATORS_FOREACH(VAR, COMMANDS) +dnl +dnl Run COMMANDS for each registered accumulator. +dnl Defines VAR to the accumulator being processed. +dnl +AC_DEFUN([CAIRO_ACCUMULATORS_FOREACH], +[dnl + m4_foreach_w([$1], _CAIRO_ACCUMULATORS, [$2])dnl +])dnl + + +dnl =========================================================================== + +m4_define([_CAIRO_ACCUMULATED_FEATURE_VARS])dnl + +dnl +dnl CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER(VARS, DEFAULT-VALUE=[], SEPARATOR=[], INITIAL-VALUE=[]) +dnl +dnl Defines VARS as feature variables and accumulators. Also accumulates +dnl (prepending, not appending) feature values for VARS. +dnl +AC_DEFUN([CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER], +[dnl + m4_foreach_w([cr_var], [$1], + [m4_append_uniq([_CAIRO_ACCUMULATED_FEATURE_VARS], cr_var, [ ],, + [m4_fatal([Accumulated feature variable `]cr_var[' already registered])])])dnl + CAIRO_FEATURE_VARS_REGISTER([$1],[$2])dnl + CAIRO_ACCUMULATORS_REGISTER_UNQUOTED([$1],[$3],[$4])dnl +])dnl + +dnl +dnl CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH(VAR, COMMANDS) +dnl +dnl Run COMMANDS for each registered accumulated feature variable. +dnl Defines VAR to the variable being processed. +dnl +AC_DEFUN([CAIRO_ACCUMULATED_FEATURE_VARS_FOREACH], +[dnl + m4_foreach_w([$1], _CAIRO_ACCUMULATED_FEATURE_VARS, [$2])dnl +])dnl + +dnl =========================================================================== + +dnl +dnl CAIRO_FEATURE_IF_ENABLED(FEATURE=cr_feature, COMMANDS) +dnl +dnl Run COMMANDS if FEATURE is enabled. +dnl +AC_DEFUN([CAIRO_FEATURE_IF_ENABLED], +[dnl + AS_IF([test "x$use_]m4_default([$1], cr_feature)[" = xyes], [$2], [$3])dnl +])dnl + +m4_define([_CAIRO_FEATURE_HOOK_MATCH_SH_BOOL], +[dnl + m4_case([$1], + [*], [$3], + [no], [AS_IF([test "x$2" != xyes], [:m4_newline()$3])], + [yes], [AS_IF([test "x$2" = xyes], [:m4_newline()$3])], + [m4_fatal([Invalid ENABLED value `]$1['])])dnl +])dnl + +m4_define([_CAIRO_FEATURE_HOOK_MATCH_M4], +[dnl + m4_case([$1], + [*], [$3], + [$2], [$3], + [!$2], , + [m4_bmatch([$1], [^!], [$3])])dnl +])dnl + +m4_define([_CAIRO_FEATURE_HOOKS])dnl + +dnl +dnl CAIRO_FEATURE_HOOK_REGISTER(ENABLED, DEFAULT, WHAT, COMMANDS) +dnl +dnl ENABLED is the feature enabledness to match +dnl DEFAULT is the default value of features to match +dnl WHAT is the type of features to match +dnl COMMANDS is commands to run for matched features. +dnl +dnl Runs COMMANDS for features matching ENABLED, DEFAULT, and WHAT. +dnl Hooks are run for each feature in the order they are added. +dnl +dnl DEFAULT and WHAT are matched like this: +dnl [*] matches all values +dnl [val] matches [val] +dnl [!val] matches anything other than [val] +dnl +dnl ENABLED is matched like this: +dnl [yes] matches enabled features +dnl [no] matches disabled features +dnl [*] matches all features +dnl +dnl The following macros can be used in COMMANDS: +dnl +dnl cr_feature expands to the feature id, eg "ft" +dnl cr_feature_name expands to the human-readable name of the feature, eg. "FreeType font" +dnl cr_feature_default expands to the default state of the feature: +dnl "no" for experimental features, eg. your favorite new backend +dnl "yes" for recommended features, eg. png functions +dnl "auto" for other supported features, eg. xlib surface backend +dnl "always" for mandatory features (can't be disabled), eg. image surface backend +dnl cr_what expands to the type of feature: +dnl "surface" for surface backends +dnl "font" for font backends +dnl "functions" for set of functions +dnl "" for private configurations +dnl +dnl These four values are also set as $1 to $4. To know if feature was +dnl enabled from within COMMANDS, use CAIRO_FEATURE_IF_ENABLED: +dnl +dnl CAIRO_FEATURE_IF_ENABLED($1, [IF-ENABLED], [IF-DISABLED]) +dnl +dnl or compare $use_$1 to string "yes". As in: +dnl +dnl AS_IF([test "x$use_$1" = "xyes"], [IF-ENABLED], [IF-DISABLED]) +dnl +AC_DEFUN([CAIRO_FEATURE_HOOK_REGISTER], +[dnl + m4_append([_CAIRO_FEATURE_HOOKS], + [dnl + _CAIRO_FEATURE_HOOK_MATCH_M4([$2], cr_feature_default, + [_CAIRO_FEATURE_HOOK_MATCH_M4([$3], cr_feature_what, + [_CAIRO_FEATURE_HOOK_MATCH_SH_BOOL([$1], [$use_]cr_feature, + [$4] + )])])dnl + ], m4_newline)dnl +])dnl + diff --git a/Build/source/libs/cairo/cairo-src/build/aclocal.float.m4 b/Build/source/libs/cairo/cairo-src/build/aclocal.float.m4 new file mode 100644 index 00000000000..8f85f0862ba --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/aclocal.float.m4 @@ -0,0 +1,65 @@ +# AX_C_FLOAT_WORDS_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], +# [ACTION-IF-UNKNOWN]) +# +# Checks the ordering of words within a multi-word float. This check +# is necessary because on some systems (e.g. certain ARM systems), the +# float word ordering can be different from the byte ordering. In a +# multi-word float context, "big-endian" implies that the word containing +# the sign bit is found in the memory location with the lowest address. +# This implemenation was inspired by the AC_C_BIGENDIAN macro in autoconf. +# ------------------------------------------------------------------------- +AC_DEFUN([AX_C_FLOAT_WORDS_BIGENDIAN], + [AC_CACHE_CHECK(whether float word ordering is bigendian, + ax_cv_c_float_words_bigendian, [ + +# The endianess is detected by first compiling C code that contains a special +# double float value, then grepping the resulting object file for certain +# strings of ascii values. The double is specially crafted to have a +# binary representation that corresponds with a simple string. In this +# implementation, the string "noonsees" was selected because the individual +# word values ("noon" and "sees") are palindromes, thus making this test +# byte-order agnostic. If grep finds the string "noonsees" in the object +# file, the target platform stores float words in big-endian order. If grep +# finds "seesnoon", float words are in little-endian order. If neither value +# is found, the user is instructed to specify the ordering. + +ax_cv_c_float_words_bigendian=unknown +AC_LINK_IFELSE([AC_LANG_SOURCE([[ + +double d __attribute__((used)) = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0; +int main() { return 0; } + +]])], [ + +if strings - conftest$ac_exeext | grep noonsees >/dev/null ; then + ax_cv_c_float_words_bigendian=yes +fi +if strings - conftest$ac_exeext | grep seesnoon >/dev/null ; then + if test "$ax_cv_c_float_words_bigendian" = unknown; then + ax_cv_c_float_words_bigendian=no + else + ax_cv_c_float_words_bigendian=unknown + fi +fi + +])]) + +case $ax_cv_c_float_words_bigendian in + yes) + m4_default([$1], + [AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1, + [Define to 1 if your system stores words within floats + with the most significant word first])]) ;; + no) + $2 ;; + *) + m4_default([$3], + [AC_MSG_ERROR([ + +Unknown float word ordering. You need to manually preset +ax_cv_c_float_words_bigendian=no (or yes) according to your system. + + ])]) ;; +esac + +])# AX_C_FLOAT_WORDS_BIGENDIAN diff --git a/Build/source/libs/cairo/cairo-src/build/aclocal.makefile.m4 b/Build/source/libs/cairo/cairo-src/build/aclocal.makefile.m4 new file mode 100644 index 00000000000..70777810d14 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/aclocal.makefile.m4 @@ -0,0 +1,234 @@ +dnl +dnl These are the facilities for generating Makefile.am.features and +dnl Makefile.win32.features files. +dnl + +dnl =========================================================================== + +dnl +dnl Define cr_feature_tag ala other cr_feature_* macros +dnl Expands to CAIRO_HAS_FEATURE_ID +dnl +m4_define([_CAIRO_BUILD_FEATURE_TAG_NORMALIZED], + [CAIRO_HAS_[$1]m4_bmatch([$1],[$2$],,[$2])])dnl +m4_define([_CAIRO_BUILD_FEATURE_TAG], + [_CAIRO_BUILD_FEATURE_TAG_NORMALIZED(AS_TR_CPP([$1]),AS_TR_CPP(m4_ifval([$2],[ $2])))])dnl +m4_define([cr_feature_tag], + [_CAIRO_BUILD_FEATURE_TAG(cr_feature,cr_feature_what)])dnl + + +dnl =========================================================================== +dnl +dnl CAIRO_INIT_MAKEFILES([AUX-DIR]) +dnl +dnl Sets up automake and win32 conditionals for all features +dnl +AC_DEFUN([CAIRO_INIT_MAKEFILES], +[dnl + dnl Allow feature tags in the output + m4_pattern_allow(^CAIRO_HAS_)dnl + + dnl Automake conditionals for non-builtin features + CAIRO_FEATURE_HOOK_REGISTER(*,!always,*, + [dnl + AM_CONDITIONAL(cr_feature_tag, [test "x$use_]cr_feature[" = xyes])dnl + ])dnl + + CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([_],[$1],[],[[# Generated by configure. Modify to customize.]])dnl + CAIRO_MAKEFILE_ACCUMULATE_FEATURE([_],*,!always,*,[cr_feature_tag=m4_if(cr_feature_default,[yes],1,[m4_bmatch(cr_feature,[win32],1,0)])])dnl +])dnl + +dnl =========================================================================== + +m4_define([_CAIRO_MAKEFILES])dnl + +dnl +dnl CAIRO_CONFIG_MAKEFILE(TAG, DIR, [SUFFIX], [HEADER]) +dnl +dnl Create DIR/Makefile.{am,win32}.SUFFIX files +dnl TAG is a TAG used by other CAIRO_MAKEFILE_* macros to append to these +dnl Makefile's. +dnl +dnl HEADER is appended at the top of the Makefile's. If HEADER is not +dnl set, the generic "Generated by configure. Do not edit." comment +dnl is added. +dnl +AC_DEFUN([CAIRO_CONFIG_MAKEFILE], +[dnl + m4_append_uniq([_CAIRO_MAKEFILES], [$1], [ ])dnl + CAIRO_CONFIG_MAKEFILE_PRIVATE([$1], [$2], [$3], [$4])dnl +])dnl + +dnl Like CAIRO_CONFIG_MAKEFILE but only generate win32 makefile +AC_DEFUN([CAIRO_CONFIG_MAKEFILE_WIN32], +[dnl + m4_append_uniq([_CAIRO_MAKEFILES], [$1], [ ])dnl + CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([$1], [$2], [$3], [$4])dnl +])dnl + +dnl Like CAIRO_CONFIG_MAKEFILE but only generate automake makefile +AC_DEFUN([CAIRO_CONFIG_MAKEFILE_AMAKE], +[dnl + m4_append_uniq([_CAIRO_MAKEFILES], [$1], [ ])dnl + CAIRO_CONFIG_MAKEFILE_PRIVATE_AMAKE([$1], [$2], [$3], [$4])dnl +])dnl + +dnl +dnl CAIRO_CONFIG_MAKEFILE_PRIVATE(TAG, DIR, [SUFFIX], [HEADER]) +dnl +dnl Like CAIRO_CONFIG_MAKEFILE but this makefile tag won't match +dnl against '*' in makefile accumulators. +dnl +AC_DEFUN([CAIRO_CONFIG_MAKEFILE_PRIVATE], +[dnl + m4_ifdef([cr_make_$1_dir], + [m4_fatal([Makefile `$1' already registered])])dnl + m4_define([cr_make_$1_dir],[$2])dnl + + CAIRO_CONFIG_MAKEFILE_PRIVATE_AMAKE([$1], [$2], [$3], [$4])dnl + CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([$1], [$2], [$3], [$4])dnl +])dnl + +dnl Like CAIRO_CONFIG_MAKEFILE_PRIVATE but only generate automake makefile +AC_DEFUN([CAIRO_CONFIG_MAKEFILE_PRIVATE_AMAKE], +[dnl + m4_ifdef([cr_make_$1_dir_amake], + [m4_fatal([Automake makefile `$1' already registered])])dnl + m4_define([cr_make_$1_dir_amake],[$2])dnl + m4_define([cr_make_$1_dir_any],[$2])dnl + + dnl Accumulators + CAIRO_ACCUMULATORS_REGISTER(MAKEFILE_$1_AMAKE, m4_newline, m4_default([$4],[[# Generated by configure. Do not edit.]])m4_newline)dnl + + dnl Generate + CAIRO_CONFIG_COMMANDS([$srcdir/]m4_if([$2],[.],,[$2/])[Makefile.am.]m4_default([$3],[features]), + [echo "$CAIRO_MAKEFILE_$1_AMAKE"], + [CAIRO_MAKEFILE_$1_AMAKE='$CAIRO_MAKEFILE_$1_AMAKE'])dnl +])dnl + +dnl Like CAIRO_CONFIG_MAKEFILE_PRIVATE but only generate win32 makefile +AC_DEFUN([CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32], +[dnl + m4_ifdef([cr_make_$1_dir_win32], + [m4_fatal([Win32 makefile `$1' already registered])])dnl + m4_define([cr_make_$1_dir_win32],[$2])dnl + m4_define([cr_make_$1_dir_any],[$2])dnl + + dnl Accumulators + CAIRO_ACCUMULATORS_REGISTER(MAKEFILE_$1_WIN32, m4_newline, m4_default([$4],[[# Generated by configure. Do not edit.]])m4_newline)dnl + + dnl Generate + CAIRO_CONFIG_COMMANDS([$srcdir/]m4_if([$2],[.],,[$2/])[Makefile.win32.]m4_default([$3],[features]), + [echo "$CAIRO_MAKEFILE_$1_WIN32"], + [CAIRO_MAKEFILE_$1_WIN32='$CAIRO_MAKEFILE_$1_WIN32'])dnl +])dnl + + +m4_define([_CAIRO_MAKEFILE_CHECK], +[dnl + m4_ifdef([cr_make_$1_dir_any],,[m4_fatal([Makefile `]$1[' not defined.])])dnl +])dnl + + +dnl +dnl CAIRO_MAKEFILE_INCLUDE(TAG, FILE) +dnl +dnl Include FILE from Makefile's for TAG. FILE should be placed +dnl relative to directory for TAG. If TAG is *, FILE is included from +dnl all Makefile's. +dnl +AC_DEFUN([CAIRO_MAKEFILE_INCLUDE], +[dnl + m4_if([$1],[*],,[_CAIRO_MAKEFILE_CHECK([$1])])dnl + m4_foreach_w([cr_makefile], m4_if([$1],[*],_CAIRO_MAKEFILES,[$1]), + [dnl + m4_ifdef([cr_make_]cr_makefile[_dir_amake],dnl + [CAIRO_ACCUMULATE([MAKEFILE_]cr_makefile[_AMAKE],[include $(top_srcdir)/cr_make_]cr_makefile[_dir_amake/$2]m4_newline)] + )dnl + m4_ifdef([cr_make_]cr_makefile[_dir_win32],dnl + [CAIRO_ACCUMULATE([MAKEFILE_]cr_makefile[_WIN32],[ifeq ($(top_srcdir),)]m4_newline[include $2]m4_newline[else]m4_newline[include $(top_srcdir)/cr_make_]cr_makefile[_dir_win32/$2]m4_newline[endif]m4_newline)] + )dnl + ])dnl +])dnl + + +m4_pattern_allow([cr_make_tmp]) + +dnl +dnl CAIRO_MAKEFILE_ACCUMULATE(TAG, CONTENT) +dnl +dnl Accumulates CONTENT to Makefile's for TAG. If TAG is *, +dnl CONTENT is added to all Makefile's. +dnl +AC_DEFUN([CAIRO_MAKEFILE_ACCUMULATE], +[dnl + m4_if([$1],[*],,[_CAIRO_MAKEFILE_CHECK([$1])])dnl + m4_foreach_w([cr_makefile], m4_if([$1],[*],_CAIRO_MAKEFILES,[$1]), + [dnl + m4_pushdef([cr_make_acc_contents],[$2])dnl + cr_make_tmp=_CAIRO_SH_ESCAPE(cr_make_acc_contents(cr_makefile)) + m4_popdef([cr_make_acc_contents])dnl + m4_ifdef([cr_make_]cr_makefile[_dir_amake],dnl + [CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED([MAKEFILE_]cr_makefile[_AMAKE], [$cr_make_tmp])] + )dnl + m4_ifdef([cr_make_]cr_makefile[_dir_win32],dnl + [CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED([MAKEFILE_]cr_makefile[_WIN32], [$cr_make_tmp])] + )dnl + ])dnl +])dnl + +m4_define([_CAIRO_MAKEFILE_ACCUMULATE_FEATURE], +[dnl + dnl Don't do a conditional for default=always features + m4_pushdef([cr_mk_acc_feat_enabled],m4_if([$2],[yes],[m4_if(cr_feature_default,[always],[*],[$2])],[$2]))dnl + m4_case(cr_mk_acc_feat_enabled, + [*],, + [yes], [CAIRO_ACCUMULATE([$1], [$3])], + [no], [CAIRO_ACCUMULATE([$1], [$3]m4_newline[$4])], + [m4_fatal([Invalid ENABLED value `]$2['])])dnl + CAIRO_ACCUMULATE_UNQUOTED_UNCHECKED([$1], [$6])dnl + m4_case(cr_mk_acc_feat_enabled, + [*],, + [yes], [CAIRO_ACCUMULATE([$1], [$5])], + [no], [CAIRO_ACCUMULATE([$1], [$5])], + [m4_fatal([Invalid ENABLED value `]$2['])])dnl + m4_popdef([cr_mk_acc_feat_enabled])dnl +])dnl + +dnl +dnl CAIRO_MAKEFILE_ACCUMULATE_FEATURE(TAG, ENABLED, DEFAULT, WHAT, CONTENT) +dnl +dnl Accumulates CONTENT to Makefile's for TAG for each feature matching +dnl ENABLED, DEFAULT, and WHAT. Those parameters are similar to those +dnl passed to CAIRO_FEATURE_HOOK_REGISTER. +dnl If TAG is *, CONTENT is added to all Makefile's. +dnl +AC_DEFUN([CAIRO_MAKEFILE_ACCUMULATE_FEATURE], +[dnl + m4_if([$1],[*],,[_CAIRO_MAKEFILE_CHECK([$1])])dnl + m4_append([cr_make_acc_counter],[1],[])dnl + m4_define([cr_make_acc_contents]m4_len(cr_make_acc_counter), [$5])dnl + CAIRO_FEATURE_HOOK_REGISTER(*,[$3],[$4], + [dnl + m4_foreach_w([cr_makefile], m4_if([$1],[*],_CAIRO_MAKEFILES,[$1]), + [dnl + cr_make_tmp=_CAIRO_SH_ESCAPE(cr_make_acc_contents]]m4_len(cr_make_acc_counter)([[cr_makefile,]][$][1],[$][2],[$][3],[$][4])[[) + m4_ifdef([cr_make_]cr_makefile[_dir_amake], + [_CAIRO_MAKEFILE_ACCUMULATE_FEATURE( + [MAKEFILE_]cr_makefile[_AMAKE], + [$2], + [if ]cr_feature_tag, [else], [endif], + [$cr_make_tmp]) + ])dnl + m4_ifdef([cr_make_]cr_makefile[_dir_win32], + [_CAIRO_MAKEFILE_ACCUMULATE_FEATURE( + [MAKEFILE_]cr_makefile[_WIN32], + [$2], + [ifeq ($(]cr_feature_tag[),1)], [else], [endif], + [$cr_make_tmp])dnl + ])dnl + ])dnl + ])dnl +])dnl + +m4_define([cr_make_acc_counter])dnl diff --git a/Build/source/libs/cairo/cairo-src/build/aclocal.pkg.m4 b/Build/source/libs/cairo/cairo-src/build/aclocal.pkg.m4 new file mode 100644 index 00000000000..cf90a967880 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/aclocal.pkg.m4 @@ -0,0 +1,157 @@ +# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- +# +# Copyright © 2004 Scott James Remnant . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# PKG_PROG_PKG_CONFIG([MIN-VERSION]) +# ---------------------------------- +AC_DEFUN([PKG_PROG_PKG_CONFIG], +[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) +m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=m4_default([$1], [0.9.0]) + AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + PKG_CONFIG="" + fi + +fi[]dnl +])# PKG_PROG_PKG_CONFIG + +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# +# Check to see whether a particular set of modules exists. Similar +# to PKG_CHECK_MODULES(), but does not set variables or print errors. +# +# +# Similar to PKG_CHECK_MODULES, make sure that the first instance of +# this or PKG_CHECK_MODULES is called, or make sure to call +# PKG_CHECK_EXISTS manually +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_EXISTS], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +if test -n "$PKG_CONFIG" && \ + AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then + m4_ifval([$2], [$2], [:]) +m4_ifvaln([$3], [else + $3])dnl +fi]) + + +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) +# --------------------------------------------- +m4_define([_PKG_CONFIG], +[if test -n "$$1"; then + pkg_cv_[]$1="$$1" + elif test -n "$PKG_CONFIG"; then + PKG_CHECK_EXISTS([$3], + [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], + [pkg_failed=yes]) + else + pkg_failed=untried +fi[]dnl +])# _PKG_CONFIG + +# _PKG_SHORT_ERRORS_SUPPORTED +# ----------------------------- +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi[]dnl +])# _PKG_SHORT_ERRORS_SUPPORTED + + +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND]) +# +# ACTION-IF-NOT-FOUND is not allowed to be empty, that trigger PKG_CONFIG_PATH error message. +# Use : or set a dummy variable to avoid that behavior. +# +# Note that if there is a possibility the first call to +# PKG_CHECK_MODULES might not happen, you should be sure to include an +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac +# +# +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_MODULES], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl + +pkg_failed=no +AC_MSG_CHECKING([for $1]) + +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) +_PKG_CONFIG([$1][_LIBS], [libs], [$2]) + +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS +and $1[]_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details.]) + +if test $pkg_failed = yes; then + _PKG_SHORT_ERRORS_SUPPORTED + if test $_pkg_short_errors_supported = yes; then + $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1` + else + $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD + + ifelse([$4], , [AC_MSG_ERROR(dnl +[Package requirements ($2) were not met: + +$$1_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +_PKG_TEXT +])], + [AC_MSG_RESULT([no]) + $4]) +elif test $pkg_failed = untried; then + ifelse([$4], , [AC_MSG_FAILURE(dnl +[The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +_PKG_TEXT + +To get pkg-config, see .])], + [$4]) +else + $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS + $1[]_LIBS=$pkg_cv_[]$1[]_LIBS + AC_MSG_RESULT([yes]) + ifelse([$3], , :, [$3]) +fi[]dnl +])# PKG_CHECK_MODULES diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.analysis b/Build/source/libs/cairo/cairo-src/build/configure.ac.analysis new file mode 100644 index 00000000000..11c52e70d6e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.analysis @@ -0,0 +1,106 @@ +dnl =========================================================================== +dnl +dnl LCOV +dnl +cairo_has_lcov=no +AC_ARG_ENABLE(gcov, + AS_HELP_STRING([--enable-gcov], + [Enable gcov]), + [use_gcov=$enableval], [use_gcov=no]) + +if test "x$use_gcov" = "xyes"; then + dnl we need gcc: + if test "$GCC" != "yes"; then + AC_MSG_ERROR([GCC is required for --enable-gcov]) + fi + + dnl Check if ccache is being used + AC_CHECK_PROG(SHTOOL, shtool, shtool) + case `$SHTOOL path $CC` in + *ccache*[)] gcc_ccache=yes;; + *[)] gcc_ccache=no;; + esac + + if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then + AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) + fi + + ltp_version_list="1.7 1.6 1.5 1.4" + AC_CHECK_PROG(LTP, lcov, lcov) + AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml) + + if test "$LTP"; then + AC_CACHE_CHECK([for ltp version], cairo_cv_ltp_version, [ + cairo_cv_ltp_version=invalid + ltp_version=`$LTP -v 2>/dev/null | $SED -e 's/^.* //'` + for ltp_check_version in $ltp_version_list; do + if test "$ltp_version" = "$ltp_check_version"; then + cairo_cv_ltp_version="$ltp_check_version (ok)" + fi + done + ]) + fi + + case $cairo_cv_ltp_version in + ""|invalid[)] + ;; + *) + cairo_has_lcov=yes + ;; + esac + + if test "x$cairo_has_lcov" != "xyes"; then + AC_MSG_ERROR([[To enable code coverage reporting you must have one of the following LTP versions installed: $ltp_version_list. +Please install the Linux Test Project [http://ltp.sourceforge.net/], and try again.]]) + fi + + if test -z "$LTP_GENHTML"; then + AC_MSG_ERROR([[Could not find genhtml from the LTP package. +Please install the Linux Test Project [http://ltp.sourceforge.net/], and try again.]]) + fi + + AC_DEFINE(HAVE_GCOV, 1, [Whether you have gcov]) +dnl PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Makefile.gcov, $abs_srcdir) + + dnl Remove all optimization flags from CFLAGS + changequote({,}) + CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` + CAIRO_CFLAGS=`echo "$CAIRO_CFLAGS" | $SED -e 's/-O[0-9]*//g'` + changequote([,]) + + dnl Add the special gcc flags + dnl In order to workaround a debian bug in libtool where they strip + dnl $dependency_libs from the link line and CFLAGS, we need to pass + dnl --coverage via LDFLAGS. + CAIRO_CC_TRY_FLAG([--coverage],, + [ + CAIRO_CFLAGS="$CAIRO_CFLAGS -O0 --coverage" + CAIRO_LDFLAGS="$CAIRO_LDFLAGS -O0 --coverage" + ]) +fi +AM_CONDITIONAL(CAIRO_HAS_LCOV, test "x$cairo_has_lcov" = "xyes") + +dnl =========================================================================== +dnl Check for some custom valgrind modules +AC_ARG_ENABLE(valgrind, + AS_HELP_STRING([--disable-valgrind], + [Disable valgrind support]), + [use_valgrind=$enableval], [use_valgrind=yes]) + +if test "x$use_valgrind" = "xyes"; then + PKG_CHECK_MODULES(VALGRIND, valgrind, [ + _save_CFLAGS="$CFLAGS" + _save_CPPFLAGS="$CPPFLAGS" + CFLAGS="$CFLAGS $VALGRIND_CFLAGS" + CPPFLAGS="$CPPFLAGS $VALGRIND_CFLAGS" + AC_CHECK_HEADER([valgrind.h], [AC_DEFINE([HAVE_VALGRIND], [1], + [Define to 1 if you have Valgrind])]) + AC_CHECK_HEADER([lockdep.h], [AC_DEFINE([HAVE_LOCKDEP], [1], + [Define to 1 if you have the Valgrind lockdep tool])]) + AC_CHECK_HEADER([memfault.h], [AC_DEFINE([HAVE_MEMFAULT], [1], + [Define to 1 if you have the Valgrind memfault tool])]) + CAIRO_CFLAGS="$VALGRIND_CFLAGS $CAIRO_CFLAGS" + CFLAGS="$_save_CFLAGS" + CPPFLAGS="$_save_CPPFLAGS" + ], AC_MSG_RESULT(no)) +fi diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.features b/Build/source/libs/cairo/cairo-src/build/configure.ac.features new file mode 100644 index 00000000000..77f20358889 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.features @@ -0,0 +1,427 @@ + +dnl +dnl Define macros to enable various features. +dnl - Macro: CAIRO_ENABLE_* (ID, NAME, DEFAULT, COMMANDS) +dnl +dnl where: +dnl +dnl ID is the feature id, eg. "ft" for cairo_ft_... +dnl NAME is the human-readable name of the feature, eg. "FreeType" +dnl DEFAULT is the default state of the feature: +dnl "no" for experimental backends, eg. your favorite new backend +dnl "yes" for mandatory backends, eg. png +dnl "auto" for other supported backends, eg. xlib +dnl COMMANDS are run to check whether the feature can be enabled. Their +dnl result may be cached, so user should not count on them being run. +dnl They should set use_$(ID) to something other than yes if the +dnl feature cannot be built, eg. "no (requires SomeThing)". It then +dnl should also set $(ID)_REQUIRES/CFLAGS/LIBS/... +dnl appropriately. Look at the macro definition for more details, +dnl or ask if in doubt. +dnl + +AC_DEFUN([CAIRO_ENABLE], + [_CAIRO_ENABLE([$1], [$2], , [$3],[$4])])dnl + +AC_DEFUN([CAIRO_ENABLE_SURFACE_BACKEND], + [_CAIRO_ENABLE([$1], [$2 surface backend], surface, [$3],[$4])])dnl + +AC_DEFUN([CAIRO_ENABLE_FONT_BACKEND], + [_CAIRO_ENABLE([$1], [$2 font backend], font, [$3],[$4])])dnl + +AC_DEFUN([CAIRO_ENABLE_FUNCTIONS], + [_CAIRO_ENABLE([$1], [$2 functions], functions, [$3],[$4])])dnl + + +dnl +dnl Define cr_feature_pc and friends ala other cr_feature_* macros +dnl +m4_define([cr_pc_modname], + [[cairo-]m4_translit([$1],_,-)])dnl +m4_define([cr_feature_pc], + [cr_pc_modname(cr_feature)[.pc]])dnl +m4_define([cr_feature_uninstalled_pc], + [cr_pc_modname(cr_feature)[-uninstalled.pc]])dnl + + +dnl =========================================================================== +dnl +dnl Hooks +dnl +dnl =========================================================================== + + +dnl =========================================================================== +dnl +dnl Generate {src,boilerplate}/Makefile.{am,win32}.config +dnl + +CAIRO_INIT_MAKEFILES([build]) +CAIRO_CONFIG_MAKEFILE([cairo], [src])dnl +CAIRO_CONFIG_MAKEFILE([cairo_boilerplate], [boilerplate])dnl +CAIRO_MAKEFILE_INCLUDE(*,[Makefile.sources])dnl +dnl An empty line per feature for readability +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,*,*,[])dnl + + +dnl Collect list of all supported public headers +CAIRO_MAKEFILE_ACCUMULATE(*, +[supported_$1_headers = $($1_headers)]dnl +)dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,!no,!, +[supported_$1_headers += $($1_$2_headers)]dnl +)dnl + +dnl Collect list of all unsupported public headers +CAIRO_MAKEFILE_ACCUMULATE(*, +[unsupported_$1_headers =]dnl +)dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,no,!, +[unsupported_$1_headers += $($1_$2_headers)]dnl +)dnl + +dnl Collect list of source files for all public features +CAIRO_MAKEFILE_ACCUMULATE(*, +[dnl +all_$1_headers = $($1_headers) +all_$1_private = $($1_private) +all_$1_cxx_sources = $($1_cxx_sources) +all_$1_sources = $($1_sources) +])dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,*,!, +[dnl +all_$1_headers += $($1_$2_headers) +all_$1_private += $($1_$2_private) +all_$1_cxx_sources += $($1_$2_cxx_sources) +all_$1_sources += $($1_$2_sources)]dnl +)dnl + +dnl Collect list of source files for enabled public features +CAIRO_MAKEFILE_ACCUMULATE(*, +[dnl +enabled_$1_headers = $($1_headers) +enabled_$1_private = $($1_private) +enabled_$1_cxx_sources = $($1_cxx_sources) +enabled_$1_sources = $($1_sources) +])dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,yes,*,!, +[dnl +enabled_$1_headers += $($1_$2_headers) +enabled_$1_private += $($1_$2_private) +enabled_$1_cxx_sources += $($1_$2_cxx_sources) +enabled_$1_sources += $($1_$2_sources)]dnl +)dnl + +dnl No public headers for private features + +dnl Collect list of source files for all private features +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,*,*,, +[dnl +all_$1_private += $($1_$2_private) $($1_$2_headers) +all_$1_cxx_sources += $($1_$2_cxx_sources) +all_$1_sources += $($1_$2_sources)]dnl +)dnl + +dnl Collect list of source files for enabled private features +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(*,yes,*,, +[dnl +enabled_$1_private += $($1_$2_private) $($1_$2_headers) +enabled_$1_cxx_sources += $($1_$2_cxx_sources) +enabled_$1_sources += $($1_$2_sources)]dnl +)dnl + + +dnl =========================================================================== +dnl +dnl Generate .pc files +dnl + +dnl All .pc files are generated automatically except for this one +AC_CONFIG_FILES([src/cairo.pc])dnl +AC_CONFIG_FILES([cairo-uninstalled.pc:src/cairo-uninstalled.pc.in])dnl + +dnl pkg-config requires, non-pkgconfig cflags and libs, and total cflags and libs +CAIRO_FEATURE_VARS_REGISTER([BASE],[cairo])dnl +CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER([REQUIRES],,[ ])dnl +CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER([CFLAGS NONPKGCONFIG_CFLAGS],,[ ])dnl +CAIRO_ACCUMULATED_FEATURE_VARS_REGISTER([LIBS NONPKGCONFIG_LIBS],,[ ],[$LIBS])dnl +CAIRO_FEATURE_VARS_REGISTER([NONPKGCONFIG_EXTRA_LIBS])dnl +AC_SUBST(CAIRO_REQUIRES)dnl +AC_SUBST(CAIRO_CFLAGS)dnl +AC_SUBST(CAIRO_LDFLAGS)dnl +AC_SUBST(CAIRO_NONPKGCONFIG_CFLAGS)dnl +AC_SUBST(CAIRO_LIBS)dnl +AC_SUBST(CAIRO_NONPKGCONFIG_LIBS)dnl + +dnl add non-pkgconfig values +AC_CONFIG_COMMANDS_PRE( +[dnl +CAIRO_CFLAGS="$CAIRO_CFLAGS $CAIRO_NONPKGCONFIG_CFLAGS" +CAIRO_LIBS="$CAIRO_LIBS $CAIRO_NONPKGCONFIG_LIBS" +])dnl + +m4_define([_CAIRO_FEATURE_CONFIG_PKGCONFIG_FILE], +[dnl + AC_CONFIG_FILES([$3:$4], + [dnl + mv "$3" "$3.tmp" && + $SED "dnl + s%@FEATURE_PC@%]cr_pc_modname([$1])[%g;dnl + s%@FEATURE_NAME@%$2%g;dnl + s%@FEATURE_BASE@%$$1_BASE%g;dnl + s%@FEATURE_REQUIRES@%$$1_REQUIRES%g;dnl + s%@FEATURE_NONPKGCONFIG_LIBS@%$$1_NONPKGCONFIG_LIBS%g;dnl + s%@FEATURE_NONPKGCONFIG_EXTRA_LIBS@%$$1_NONPKGCONFIG_EXTRA_LIBS%g;dnl + s%@FEATURE_NONPKGCONFIG_CFLAGS@%$$1_NONPKGCONFIG_CFLAGS%g;dnl + " < "$3.tmp" > "$3" && rm -f "$3.tmp" || + AC_MSG_ERROR(failed to update $3) + ],[dnl + SED='$SED' + $1_BASE='$$1_BASE' + $1_REQUIRES='$$1_REQUIRES' + $1_NONPKGCONFIG_LIBS='$$1_NONPKGCONFIG_LIBS' + $1_NONPKGCONFIG_EXTRA_LIBS='$$1_NONPKGCONFIG_EXTRA_LIBS' + $1_NONPKGCONFIG_CFLAGS='$$1_NONPKGCONFIG_CFLAGS' + ])dnl +])dnl + +dnl Generate .pc files for enabled non-builtin public features +CAIRO_FEATURE_HOOK_REGISTER(yes,!always,!, +[dnl + _CAIRO_FEATURE_CONFIG_PKGCONFIG_FILE( + [$1], + cr_feature_name, + [src/]cr_feature_pc, + [src/cairo-features.pc.in] + )dnl +])dnl + +dnl Generate -uninstalled.pc files for enabled non-builtin public features +CAIRO_FEATURE_HOOK_REGISTER(yes,!always,!, +[dnl + _CAIRO_FEATURE_CONFIG_PKGCONFIG_FILE( + [$1], + cr_feature_name, + cr_feature_uninstalled_pc, + [src/cairo-features-uninstalled.pc.in] + )dnl +])dnl + + +dnl Collect list of .pc files for all non-builtin public features +CAIRO_MAKEFILE_ACCUMULATE(cairo, +[all_$1_pkgconf = cairo.pc])dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(cairo,*,!always,!, +[all_$1_pkgconf += cr_feature_pc])dnl + +dnl Collect list of .pc files for enabled non-builtin public features +CAIRO_MAKEFILE_ACCUMULATE(cairo, +[enabled_$1_pkgconf = cairo.pc])dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE(cairo,yes,!always,!, +[enabled_$1_pkgconf += cr_feature_pc])dnl + + +dnl =========================================================================== +dnl +dnl Generate src/cairo-features.h, src/cairo-supported-features.h, and +dnl src/cairo-features-win32.h +dnl + +dnl Collect list of enabled public features +CAIRO_ACCUMULATORS_REGISTER(FEATURES,[ ])dnl +CAIRO_FEATURE_HOOK_REGISTER(yes,*,!,dnl +[dnl + CAIRO_ACCUMULATE(FEATURES, cr_feature_tag)dnl +])dnl +dnl Collect list of all supported public features +CAIRO_ACCUMULATORS_REGISTER(SUPPORTED_FEATURES,[ ])dnl +CAIRO_FEATURE_HOOK_REGISTER(*,!no,!,dnl +[dnl + CAIRO_ACCUMULATE(SUPPORTED_FEATURES, cr_feature_tag) +])dnl +dnl Collect list of all supported disabled public features +CAIRO_ACCUMULATORS_REGISTER(NO_FEATURES,[ ])dnl +CAIRO_FEATURE_HOOK_REGISTER(no,*,!, +[dnl + CAIRO_ACCUMULATE(NO_FEATURES, cr_feature_tag) +])dnl + +dnl Generate src/cairo-features.h +CAIRO_CONFIG_COMMANDS([src/cairo-features.h], +[dnl + echo '/* Generated by configure. Do not edit. */' + echo '#ifndef CAIRO_FEATURES_H' + echo '#define CAIRO_FEATURES_H' + echo '' + for FEATURE in $CAIRO_FEATURES; do + echo "#define $FEATURE 1" + done | LANG=C sort + echo '' + for FEATURE in $CAIRO_NO_FEATURES; do + echo "/*#undef $FEATURE */" + done | LANG=C sort + echo '' + echo '#endif' +],[dnl + CAIRO_FEATURES='$CAIRO_FEATURES' + CAIRO_NO_FEATURES='$CAIRO_NO_FEATURES' +])dnl +dnl Generate src/cairo-supported-features.h +CAIRO_CONFIG_COMMANDS([src/cairo-supported-features.h], +[dnl + echo '/* Generated by configure. Do not edit. */' + echo '#ifndef CAIRO_SUPPORTED_FEATURES_H' + echo '#define CAIRO_SUPPORTED_FEATURES_H' + echo '' + echo '/* This is a dummy header, to trick gtk-doc only */' + echo '' + for FEATURE in $CAIRO_SUPPORTED_FEATURES; do + echo "#define $FEATURE 1" + done + echo '' + echo '#endif' +],[dnl + CAIRO_SUPPORTED_FEATURES='$CAIRO_SUPPORTED_FEATURES' +])dnl + +dnl For enabled private features just define them in config.h. No fanfare! +CAIRO_FEATURE_HOOK_REGISTER(yes,*,, +[dnl + AC_DEFINE(cr_feature_tag, 1, [Define to 1 to enable cairo's ]cr_feature_name[ feature]) +])dnl + + +dnl Generate build/Makefile.win32.features-h that generates src/cairo-features.h +CAIRO_CONFIG_MAKEFILE_PRIVATE_WIN32([win32_features_h],[build],[features-h]) +dnl +CAIRO_MAKEFILE_ACCUMULATE([win32_features_h], +[$(top_srcdir)/src/cairo-features.h: $(top_srcdir)/build/Makefile.win32.features + @echo "Generating src/cairo-features.h" + @echo "/* Generated by Makefile.win32.features-h. Do not edit. */" > $(top_srcdir)/src/cairo-features.h + @echo "[#]ifndef CAIRO_FEATURES_H" >> $(top_srcdir)/src/cairo-features.h + @echo "[#]define CAIRO_FEATURES_H 1" >> $(top_srcdir)/src/cairo-features.h]dnl +) +AC_CONFIG_COMMANDS_PRE( +[dnl + CAIRO_MAKEFILE_ACCUMULATE([win32_features_h], [ @echo "[#]endif" >> $(top_srcdir)/src/cairo-features.h]) +])dnl +CAIRO_MAKEFILE_ACCUMULATE_FEATURE([win32_features_h],yes,*,*,dnl +[ @echo "[#]define cr_feature_tag 1" >> $(top_srcdir)/src/cairo-features.h]dnl +)dnl + + +dnl =========================================================================== +dnl +dnl Report +dnl + +CAIRO_ACCUMULATORS_REGISTER([WARNING_MESSAGE],m4_newline()m4_newline)dnl + +dnl Collect warning message for enabled unsupported public features +CAIRO_FEATURE_HOOK_REGISTER(yes,no,!, +[dnl + CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([The ]cr_feature_name[ feature is still under active development and is included in this release only as a preview. It does NOT fully work yet and incompatible changes may yet be made to ]cr_feature_name[ specific API.], [--- ])) +])dnl + +dnl Collect warning message for disabled recommended features +CAIRO_FEATURE_HOOK_REGISTER(no,yes,*, +[dnl + CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([It is strongly recommended that you do NOT disable the ]cr_feature_name[ feature.], [+++ ])) +])dnl + + +dnl Collect enabled native surface/font backend features +CAIRO_ACCUMULATORS_REGISTER([NATIVE_SURFACE_BACKENDS])dnl +CAIRO_ACCUMULATORS_REGISTER([NATIVE_FONT_BACKENDS])dnl +CAIRO_FEATURE_HOOK_REGISTER(yes,auto,surface, +[dnl + CAIRO_ACCUMULATE([NATIVE_SURFACE_BACKENDS], [$1]) +])dnl +CAIRO_FEATURE_HOOK_REGISTER(yes,auto,font, +[dnl + CAIRO_ACCUMULATE([NATIVE_FONT_BACKENDS], [$1]) +])dnl + +dnl Collect warning message if no native surface/font backend feature enabled +AC_CONFIG_COMMANDS_PRE(dnl +[dnl + AS_IF([test -z "$CAIRO_NATIVE_SURFACE_BACKENDS"],dnl + [dnl + CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([No native surface backends enabled for your platform. It is strongly recommended that you enable the native surface backend feature for your platform.], [*** ])) + ]) + AS_IF([test -z "$CAIRO_NATIVE_FONT_BACKENDS"],dnl + [dnl + CAIRO_ACCUMULATE([WARNING_MESSAGE], CAIRO_TEXT_WRAP([No native font backends enabled for your platform. It is strongly recommended that you enable the native font backend feature for your platform.], [*** ])) + ]) +])dnl + + +AC_DEFUN([CAIRO_REPORT], +[dnl + V="$CAIRO_VERSION_MAJOR.$CAIRO_VERSION_MINOR.$CAIRO_VERSION_MICRO" + echo "" + echo "cairo (version $V [[$CAIRO_RELEASE_STATUS]]) will be compiled with:" + echo "" + echo "The following surface backends:" + echo " Image: yes (always builtin)" + echo " Recording: yes (always builtin)" + echo " Observer: yes (always builtin)" + echo " Mime: yes (always builtin)" + echo " Tee: $use_tee" + echo " XML: $use_xml" + echo " Skia: $use_skia" + echo " Xlib: $use_xlib" + echo " Xlib Xrender: $use_xlib_xrender" + echo " Qt: $use_qt" + echo " Quartz: $use_quartz" + echo " Quartz-image: $use_quartz_image" + echo " XCB: $use_xcb" + echo " Win32: $use_win32" + echo " OS2: $use_os2" + echo " CairoScript: $use_script" + echo " PostScript: $use_ps" + echo " PDF: $use_pdf" + echo " SVG: $use_svg" + echo " OpenGL: $use_gl" + echo " OpenGL ES 2.0: $use_glesv2" + echo " BeOS: $use_beos" + echo " DirectFB: $use_directfb" + echo " OpenVG: $use_vg" + echo " DRM: $use_drm" + echo " Cogl: $use_cogl" + echo "" + echo "The following font backends:" + echo " User: yes (always builtin)" + echo " FreeType: $use_ft" + echo " Fontconfig: $use_fc" + echo " Win32: $use_win32_font" + echo " Quartz: $use_quartz_font" + echo "" + echo "The following functions:" + echo " PNG functions: $use_png" + echo " GLX functions: $use_glx" + echo " WGL functions: $use_wgl" + echo " EGL functions: $use_egl" + echo " X11-xcb functions: $use_xlib_xcb" + echo " XCB-shm functions: $use_xcb_shm" + echo "" + echo "The following features and utilities:" + echo " cairo-trace: $use_trace" + echo " cairo-script-interpreter: $use_interpreter" + echo "" + echo "And the following internal features:" + echo " pthread: $use_pthread" + echo " gtk-doc: $enable_gtk_doc" + echo " gcov support: $use_gcov" + echo " symbol-lookup: $use_symbol_lookup" + echo " test surfaces: $use_test_surfaces" + echo " ps testing: $test_ps" + echo " pdf testing: $test_pdf" + echo " svg testing: $test_svg" + if test x"$use_win32" = "xyes"; then + echo " win32 printing testing: $test_win32_printing" + fi + echo "$CAIRO_WARNING_MESSAGE" + echo "" +])dnl + diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.noversion b/Build/source/libs/cairo/cairo-src/build/configure.ac.noversion new file mode 100644 index 00000000000..18c4bd5f7ae --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.noversion @@ -0,0 +1,23 @@ +dnl +dnl Version stuff +dnl + +dnl Disable autoconf's version macros. We try hard to not rebuild the entire +dnl library just because version changed. The PACKAGE_VERSION* stuff in +dnl config.h is negating all the effort. +dnl +dnl We're not actually supposed to be doing this, and indeed adding the +dnl AC_DEFINEs below causes confdefs.h to contain duplicate incompatible +dnl #defines for the same PACKAGE_* symbols. Those are provoking warnings +dnl from the compiler, and that throws our CAIRO_TRY_LINK_*_ checks off, +dnl because they think that there's something wrong with some flag they're +dnl testing rather than confdefs.h! So let's do the gross thing and puke +dnl into confdefs.h some #undefs. +echo '#undef PACKAGE_VERSION' >>confdefs.h +echo '#undef PACKAGE_STRING' >>confdefs.h +echo '#undef PACKAGE_NAME' >>confdefs.h +echo '#undef PACKAGE_TARNAME' >>confdefs.h +AC_DEFINE(PACKAGE_VERSION, [USE_cairo_version_OR_cairo_version_string_INSTEAD]) +AC_DEFINE(PACKAGE_STRING, [USE_cairo_version_OR_cairo_version_string_INSTEAD]) +AC_DEFINE(PACKAGE_NAME, [USE_cairo_INSTEAD]) +AC_DEFINE(PACKAGE_TARNAME, [USE_cairo_INSTEAD]) diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.pthread b/Build/source/libs/cairo/cairo-src/build/configure.ac.pthread new file mode 100644 index 00000000000..29c930da932 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.pthread @@ -0,0 +1,253 @@ +dnl Defines the macro CAIRO_CONFIGURE_PTHREAD to find a suitable +dnl pthread implementation. There are two levels of pthread conformance +dnl we are looking for: +dnl +dnl a) A minimal level denoted by -DCAIRO_HAS_PTHREAD=1: This level +dnl requires mutex and recursive mutexattr support. If possible we try +dnl to use weakly linked stubs from libc over the real pthread library. +dnl This level is required by the cairo library proper. If the user +dnl invokes configure with --enable-pthread=yes or +dnl --enable-pthread=always then we avoid trying to use weak stubs. +dnl +dnl b) A full level denoted by -DCAIRO_HAS_REAL_PTHREAD=1: This level +dnl requires full support from a real pthread library, including thread +dnl creation, joins, thread attribtues, etc. This level is required by +dnl multithreaded applications using cairo, such as the test suite +dnl binaries and cairo utilities. +dnl +dnl Usage: +dnl CAIRO_ENABLE(pthread, pthread, , +dnl [CAIRO_CONFIGURE_PTHREAD]) +dnl +dnl This should be invoked near the end of configure.ac so that +dnl the pthread specific CFLAGS and LIBS end up at the front +dnl of CAIRO_CFLAGS and CAIRO_LIBS -- this helps ensure that we +dnl really do get non-weak symbols from the actual pthread library +dnl rather than possible stubs in other libraries. +dnl +dnl The user can override the choices made by +dnl CAIRO_CONFIGURE_PTHREAD by using --enable-pthread=yes and +dnl giving PTHREAD_CFLAGS and PTHREAD_LIBS to configure. +dnl +dnl Sets environment variables: +dnl use_pthread="yes" | "no ()" +dnl have_pthread="yes" | "no ( + +pthread_mutex_t test_mutex_initializer = PTHREAD_MUTEX_INITIALIZER; +int test_mutex (void) +{ + int x = 0; + pthread_mutex_t mutex; + x |= pthread_mutex_init (&mutex, NULL); + x |= pthread_mutex_lock (&mutex); + x |= pthread_mutex_unlock (&mutex); + x |= pthread_mutex_destroy (&mutex); + return 0; +} + +int test_mutex_attr (void) +{ + int x = 0; + pthread_mutexattr_t attr; + pthread_mutex_t mutex; + x |= pthread_mutexattr_init (&attr); + x |= pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + x |= pthread_mutex_init (&mutex, &attr); + x |= pthread_mutex_lock (&mutex); + x |= pthread_mutex_unlock (&mutex); + x |= pthread_mutex_destroy (&mutex); + x |= pthread_mutexattr_destroy (&attr); + return x; +}]) + +dnl ----------------------------------------------------------------------- +dnl A program to test all the features we want to be able to run the test +dnl suite or other thready cairo applications that want real threads. +m4_define([testsuite_pthread_program],[dnl +libcairo_pthread_program + +pthread_once_t once_control = PTHREAD_ONCE_INIT; +void test_once_init (void) {} +int test_once (void) +{ + return pthread_once (&once_control, test_once_init); +} + +pthread_key_t test_specific_key; +int test_specific (void) +{ + int x = 0; + x |= pthread_key_create (&test_specific_key, NULL); + x |= pthread_setspecific (test_specific_key, NULL); + x |= pthread_getspecific (test_specific_key) != NULL; + return x; +} + +void cleaner (void *arg) { (void)arg; } + +void * +test_thread_main (void *arg) +{ + pthread_cleanup_push (cleaner, arg); + pthread_exit (arg); + pthread_cleanup_pop (1); + return arg; +} + +int +test_threads (void) +{ + int x = 0; + pthread_t thread; + pthread_attr_t attr; + void *arg = NULL; + x |= pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + x |= pthread_create (&thread, &attr, test_thread_main, arg); + x |= pthread_equal (pthread_self(), thread); + x |= pthread_join (thread, &arg); + x |= pthread_attr_destroy (&attr); + return x; +}]) + +dnl ----------------------------------------------------------------------- + +dnl CAIRO_CHECK_PTHREAD(tag, cflags, libs, program, true-action, false-action) +dnl Set _{CFLAGS,LIBS} to {,} if we can compile and link +dnl with the given flags and libs. Execute on +dnl success and on failure. +AC_DEFUN([CAIRO_CHECK_PTHREAD],[dnl + CAIRO_CC_TRY_LINK_WITH_ENV_SILENT( + [CFLAGS="$CFLAGS $2"; + LIBS="$LIBS $3"], + [$4], + [$1_CFLAGS="$2"; + $1_LIBS="$3"; + $5], + [$1_CFLAGS=""; + $1_LIBS=""; + $6]) +]) + +dnl CAIRO_CONFIGURE_PTHREADS(): Look for pthreads. +dnl +dnl If the user specifies PTHREAD_CFLAGS and PTHREAD_LIBS then we use +dnl those. Otherwise we try CFLAGS=-D_REENTRANT and LIBS=-lpthread for +dnl full pthread support, and look for stubs in libc for the minimal +dnl pthread support. +dnl +dnl CFLAGS=-D_REENTRANT LIBS=-lpthread has been tested to work on: +dnl +dnl Solaris 9 (5.9) Sun C 5.8 Patch 121015-04 2007/01/10 +dnl OpenSolaris (5.11) Sun C 5.9 Patch 124868-08 2008/11/25 +dnl OpenSolaris (5.11) clang version 1.1 (trunk 90017) +dnl Tru64/OSF1 V5.1 Compaq C V6.5-003 +dnl Mac OS X 10.5.5 gcc 4.0.1 (Apple Inc. build 5465) +dnl Mac OS X 10.6 gcc 4.2.1 (Apple Inc. build 5659) +dnl FreeBSD 7.2 gcc 4.2 +dnl OpenBSD 4.5 gcc 3.3.5 (propolice) +dnl Debian Linux (Etch) gcc 4.3 +dnl +dnl Thread support is also in various libcs directly, so often using no +dnl flags at all works as well, but unfortunately Solaris 9 has +dnl practically _all_ of libpthread stubbed out in libc, so we cannot +dnl distinguish between a working libpthread and a stubbed out one by a +dnl link-only test. +dnl +dnl We also explicitly do not link to pthread-stubs or whatever other +dnl third-party stubs library, since that forces cairo clients to be +dnl extra careful when giving both libcairo and libpthread on the +dnl command line: the user would have to use "-lpthread -lcairo" rather +dnl than the more common "-lcairo -lpthread" to not accidentally use +dnl stubs pulled in by libcairo everywhere in the application. We +dnl might also need to have a way to teach pkg-config about library +dnl ordering constraints which aren't actual dependencies, and at this +dnl point it just starts doing my head in. +dnl +dnl If your unix-like doesn't work with the secret handshake +dnl -D_REENTRANT -lpthread and you can actually compile the rest of +dnl cairo just fine otherwise, please take a moment complain loudly +dnl to the cairo mailing list! +dnl +AC_DEFUN([CAIRO_CONFIGURE_PTHREAD],[dnl + dnl Try to use the user's PTHREAD_LIBS/CFLAGS + dnl if they're available. + if test "x$PTHREAD_CFLAGS" = "x"; then + PTHREAD_CFLAGS="-D_REENTRANT" + fi + if test "x$PTHREAD_LIBS" = "x"; then + PTHREAD_LIBS="-lpthread" + fi + + dnl First try to find the real pthreads. + CAIRO_CHECK_PTHREAD( + [real_pthread], [$PTHREAD_CFLAGS], [$PTHREAD_LIBS], + [testsuite_pthread_program], + [have_real_pthread=yes], + [have_real_pthread=no]) + if test "x$have_real_pthread" != "xyes"; then + dnl Give -pthread a go. + CAIRO_CHECK_PTHREAD( + [real_pthread], [-pthread], [], + [testsuite_pthread_program], + [have_real_pthread=yes], + [have_real_pthread="no (can't link with -lpthread or -pthread)"]) + fi + PTHREAD_CFLAGS= + PTHREAD_LIBS= + + dnl Check if we can use libc's stubs in libcairo. + dnl Only do this if the user hasn't explicitly enabled + dnl pthreads, but is relying on automatic configuration. + have_pthread="no" + if test "x$enable_pthread" != "xyes"; then + CAIRO_CHECK_PTHREAD( + [pthread], [-D_REENTRANT], [], + [libcairo_pthread_program], + [have_pthread=yes], + []) + fi + + dnl Default to using the real pthreads for libcairo. + if test "x$have_pthread" != "xyes"; then + have_pthread="$have_real_pthread"; + pthread_CFLAGS="$real_pthread_CFLAGS"; + pthread_LIBS="$real_pthread_LIBS"; + fi + + dnl Tell autoconf about the results. + if test "x$have_real_pthread" = "xyes"; then + AC_DEFINE([CAIRO_HAS_REAL_PTHREAD], 1, + [Define to 1 if we have full pthread support]) + fi + if test "x$have_pthread" = "xyes"; then + AC_DEFINE([CAIRO_HAS_PTHREAD], 1, + [Define to 1 f we have minimal pthread support]) + fi + + dnl Make sure we scored some pthreads. + if test "x$enable_pthread" = "xyes" -a "x$have_pthread" != "xyes"; then + AC_MSG_ERROR([pthread requested but not found]) + fi + + dnl Set the output variables for CAIRO_ENABLE. + use_pthread="$have_pthread" + pthread_REQUIRES="" +]) diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.system b/Build/source/libs/cairo/cairo-src/build/configure.ac.system new file mode 100644 index 00000000000..b9d71c8d783 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.system @@ -0,0 +1,160 @@ +dnl +dnl Non-failing checks for functions, headers, libraries, etc go here +dnl + +dnl ==================================================================== +dnl Feature checks +dnl ==================================================================== + +AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes") +CAIRO_BIGENDIAN +AC_ARG_ENABLE(atomic, + [AS_HELP_STRING([--disable-atomic], + [disable use of native atomic operations])], + [use_atomic=$enableval], [use_atomic=yes]) +AS_IF([test "x$use_atomic" = "xyes"], [ + CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES + CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER +]) +AC_CHECK_SIZEOF(void *) +AC_CHECK_SIZEOF(int) +AC_CHECK_SIZEOF(long) +AC_CHECK_SIZEOF(long long) +AC_CHECK_SIZEOF(size_t) + +AC_MSG_CHECKING([for native Win32]) +case "$host" in + *-*-mingw*) + cairo_os_win32=yes + ;; + *) + cairo_os_win32=no + ;; +esac +AC_MSG_RESULT([$cairo_os_win32]) +AM_CONDITIONAL(OS_WIN32, test "$cairo_os_win32" = "yes") + +AC_MSG_CHECKING([for Sun Solaris (non-POSIX ctime_r)]) +case "$host" in + *-*-solaris*) + CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS" + solaris_posix_pthread=yes + ;; + *) + solaris_posix_pthread=no + ;; +esac +AC_MSG_RESULT([$solaris_posix_pthread]) + +dnl ==================================================================== +dnl Library checks +dnl ==================================================================== + +AC_CHECK_LIBM +LIBS="$LIBS $LIBM" + +AC_CHECK_LIB(rt, sched_yield) + +has_shm_open= +AC_CHECK_LIB(rt, shm_open, [ + SHM_LIBS=-lrt + has_shm_open=yes + ], [SHM_LIBS=]) +AM_CONDITIONAL(HAVE_SHM, test "x$has_shm_open" = "xyes") +AC_SUBST(SHM_LIBS) + +AC_CHECK_LIB(socket, connect, [SOCKET_LIBS=-lsocket], [SOCKET_LIBS=]) +CAIROBOILERPLATE_LIBS=$SOCKET_LIBS +AC_SUBST(CAIROBOILERPLATE_LIBS) + +dnl ==================================================================== +dnl Header/function checks +dnl ==================================================================== + +dnl check if we have a __builtin_return_address for the cairo-trace +dnl utility. +AC_MSG_CHECKING([for __builtin_return_address(0)]) +AC_TRY_COMPILE([],[__builtin_return_address(0);], + [have_builtin_return_address=yes], + [have_builtin_return_address=no]) +AC_MSG_RESULT($have_builtin_return_address) +if test "x$have_builtin_return_address" = "xyes"; then + AC_DEFINE(HAVE_BUILTIN_RETURN_ADDRESS, 1, + [Define to 1 if your compiler supports the __builtin_return_address() intrinsic.]) +fi + +dnl Checks for precise integer types +AC_CHECK_HEADERS([stdint.h inttypes.h sys/int_types.h]) +AC_CHECK_TYPES([uint64_t, uint128_t, __uint128_t]) + +dnl Check for socket support for any2ppm daemon +AC_CHECK_HEADERS([fcntl.h unistd.h signal.h sys/stat.h sys/socket.h sys/poll.h sys/un.h]) + +dnl Check for infinite loops +AC_CHECK_FUNCS([alarm]) + +dnl check for CPU affinity support +AC_CHECK_HEADERS([sched.h], [AC_CHECK_FUNCS([sched_getaffinity])]) + +dnl check for mmap support +AC_CHECK_HEADERS([sys/mman.h], [AC_CHECK_FUNCS([mmap])]) + +dnl check for clock_gettime() support +AC_CHECK_HEADERS([time.h], [AC_CHECK_FUNCS([clock_gettime])]) + +dnl check for GNU-extensions to fenv +AC_CHECK_HEADER(fenv.h, + [AC_CHECK_FUNCS(feenableexcept fedisableexcept feclearexcept)]) + +dnl check for misc headers and functions +AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h sys/wait.h]) +AC_CHECK_FUNCS([ctime_r drand48 flockfile funlockfile getline link strndup]) + +dnl check for win32 headers (this detects mingw as well) +AC_CHECK_HEADERS([windows.h], have_windows=yes, have_windows=no) + + +dnl Possible headers for mkdir +AC_CHECK_HEADERS([sys/stat.h io.h]) +AC_CHECK_FUNC(mkdir, + [AC_MSG_CHECKING([mkdir variant]) + mkdir_variant="unknown" + save_CFLAGS="$CFLAGS" + CFLAGS=$WARN_CFLAGS + AC_TRY_COMPILE([ +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_IO_H +#include +#endif + ], + [mkdir ("hello.world", 0777)], + mkdir_variant="mkdir(path, mode)", + [AC_TRY_COMPILE([ +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_IO_H +#include +#endif + ], + [mkdir ("hello.world")], + mkdir_variant="mkdir(path)")]) + AC_MSG_RESULT([$mkdir_variant]) + CFLAGS="$save_CFLAGS" + if test "x$mkdir_variant" = "xmkdir(path, mode)"; then + AC_DEFINE(HAVE_MKDIR, 2, + [Define to non-zero if your system has mkdir, and to 2 if your version of mkdir requires a mode parameter]) + else + AC_DEFINE(HAVE_MKDIR, 1, + [Define to non-zero if your system has mkdir, and to 2 if your version of mkdir requires a mode parameter]) + fi]) + +dnl =========================================================================== +dnl +dnl Test for the tools required for building one big test binary +dnl + +AC_CHECK_FUNCS(fork waitpid raise) + diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.tools b/Build/source/libs/cairo/cairo-src/build/configure.ac.tools new file mode 100644 index 00000000000..a24dbcecb91 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.tools @@ -0,0 +1,25 @@ + +AC_PATH_PROG(FIND, find) +AC_PATH_PROG(XARGS, xargs) + +AC_PROG_CC +AC_PROG_CPP +AC_PROG_CXX dnl required for BeOS (and cannot be a conditional dependency) +AM_PROG_CC_C_O +AC_C_INLINE + +dnl =========================================================================== + +PKG_PROG_PKG_CONFIG() +if test "x$PKG_CONFIG" = x; then + AC_MSG_ERROR([pkg-config >= $PKGCONFIG_REQUIRED required but not found (http://pkgconfig.freedesktop.org/)]) +fi + +dnl Check for recent pkg-config which supports Requires.private +case `$PKG_CONFIG --version` in +[0.?|0.?.?|0.1[0-7]|0.1[0-7].?]) PKGCONFIG_REQUIRES="Requires"; ;; +*) PKGCONFIG_REQUIRES="Requires.private"; ;; +esac + +AC_SUBST(PKGCONFIG_REQUIRES) + diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.version b/Build/source/libs/cairo/cairo-src/build/configure.ac.version new file mode 100644 index 00000000000..a91cee39eef --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.version @@ -0,0 +1,42 @@ +dnl +dnl Version stuff +dnl + +dnl This macro expands to one of 'git', 'snapshot', or 'release' +m4_define([cairo_release_status], + [m4_if(m4_eval(cairo_version_micro % 2), [1], [git], + [m4_if(m4_eval(cairo_version_minor % 2), [1], [snapshot], + [release])])]) + +dnl This is the .so/dll number. 2 for cairo-1.x.x +m4_define([cairo_version_sonum], m4_eval(cairo_version_major + 1)) + +dnl The libtool shared library version stuff +m4_define([cairo_version], + m4_eval(cairo_version_major*10000 + cairo_version_minor*100 + cairo_version_micro)) +m4_if(m4_eval(cairo_version_minor % 2), [1], + [ + dnl for unstable releases + m4_define([cairo_libtool_revision], 0) + ], + [ + dnl for stable releases + m4_define([cairo_libtool_revision], cairo_version_micro) + ]) +m4_define([cairo_libtool_current], + m4_eval(cairo_version_sonum + cairo_version - cairo_libtool_revision)) +m4_define([cairo_libtool_age], + m4_eval(cairo_libtool_current - cairo_version_sonum)) + +CAIRO_VERSION_MAJOR=cairo_version_major +CAIRO_VERSION_MINOR=cairo_version_minor +CAIRO_VERSION_MICRO=cairo_version_micro +CAIRO_VERSION_SONUM=cairo_version_sonum +CAIRO_RELEASE_STATUS=cairo_release_status +CAIRO_LIBTOOL_VERSION_INFO=cairo_libtool_current:cairo_libtool_revision:cairo_libtool_age +AC_SUBST(CAIRO_VERSION_MAJOR) +AC_SUBST(CAIRO_VERSION_MINOR) +AC_SUBST(CAIRO_VERSION_MICRO) +AC_SUBST(CAIRO_VERSION_SONUM) +AC_SUBST(CAIRO_RELEASE_STATUS) +AC_SUBST(CAIRO_LIBTOOL_VERSION_INFO) diff --git a/Build/source/libs/cairo/cairo-src/build/configure.ac.warnings b/Build/source/libs/cairo/cairo-src/build/configure.ac.warnings new file mode 100644 index 00000000000..96c7f6f6d03 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/configure.ac.warnings @@ -0,0 +1,99 @@ +dnl Use lots of warning flags with with gcc and compatible compilers + +dnl Note: if you change the following variable, the cache is automatically +dnl skipped and all flags rechecked. So there's no need to do anything +dnl else. If for any reason you need to force a recheck, just change +dnl MAYBE_WARN in an ignorable way (like adding whitespace) + +# -Wcast-align generates lots of false positive reports we need to +# cast image data from uint8_t to uin32_t. + +# -Wlogical-op causes too much noise from strcmp("literal", str) + +MAYBE_WARN="-Wall -Wextra \ +-Wmissing-declarations -Werror-implicit-function-declaration \ +-Wpointer-arith -Wwrite-strings -Wsign-compare -Wpacked \ +-Wswitch-enum -Wmissing-format-attribute -Wvolatile-register-var \ +-Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \ +-Wno-missing-field-initializers -Wno-unused-parameter \ +-Wno-attributes -Wno-long-long -Winline" + +MAYBE_C_SPECIFIC_WARN="-Wold-style-definition \ +-Wdeclaration-after-statement -Wstrict-prototypes \ +-Wmissing-prototypes -Wbad-function-cast -Wnested-externs" + +# New -Wno options should be added here +# gcc-4.4 and later accept every -Wno- option but may complain later that this +# option is unknow each time another warning happen. +# -Wunused-but-set-variable is too noisy at present +NO_WARN="unused-but-set-variable" + +dnl Sun Studio 12 likes to rag at us for abusing enums like +dnl having cairo_status_t variables hold cairo_int_status_t +dnl values. It's bad, we know. Now please be quiet. +MAYBE_WARN="$MAYBE_WARN -erroff=E_ENUM_TYPE_MISMATCH_ARG \ + -erroff=E_ENUM_TYPE_MISMATCH_OP" + +dnl We also abuse the warning-flag facility to enable other compiler +dnl options. Namely, the following: +MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common" + +dnl Also to turn various gcc/glibc-specific preprocessor checks +MAYBE_WARN="$MAYBE_WARN -Wp,-D_FORTIFY_SOURCE=2" + +# invalidate cached value if MAYBE_WARN has changed +if test "x$cairo_cv_warn_maybe" != "x$MAYBE_WARN"; then + unset cairo_cv_warn_cflags +fi +AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [ + echo + WARN_CFLAGS="" + + # Some warning options are not supported by all versions of + # gcc, so test all desired options against the current + # compiler. + # + # Note that there are some order dependencies + # here. Specifically, an option that disables a warning will + # have no net effect if a later option then enables that + # warnings, (perhaps implicitly). So we put some grouped + # options (-Wall and -Wextra) up front and the -Wno options + # last. + + for W in $MAYBE_WARN; do + CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"]) + done + for W in $NO_WARN; do + CAIRO_CC_TRY_FLAG([-W$W -Wno-$W],, [WARN_CFLAGS="$WARN_CFLAGS -Wno-$W"]) + done + cairo_cv_warn_cflags=$WARN_CFLAGS + cairo_cv_warn_maybe="$MAYBE_WARN $MAYBE_C_SPECIFIC_WARN" + + AC_MSG_CHECKING([which warning flags were supported]) +]) +WARN_CFLAGS="$cairo_cv_warn_cflags" +CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS" + +# We only wish to enable attribute(warn_unused_result) if we can prevent +# gcc from generating thousands of warnings about the misapplication of the +# attribute to void functions and variables. +AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [ + AC_REQUIRE([AC_PROG_GREP]) + cairo_cv_warn_unused_result="" + if echo $WARN_CFLAGS | $GREP -e '-Wno-attributes' >/dev/null; then + CAIRO_CC_TRY_FLAG_SILENT( + [-Wno-attributes], + [__attribute__((__warn_unused_result__)) void f (void) {} + __attribute__((__warn_unused_result__)) int g;], + [cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"]) + fi +]) +AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result], + [Define to the value your compiler uses to support the warn-unused-result attribute]) + +dnl check linker flags +AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags, + [CAIRO_CC_TRY_FLAG_SILENT([-Wl,--allow-shlib-undefined], [], + [cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")]) +CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags" +AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS) diff --git a/Build/source/libs/cairo/cairo-src/build/gtk-doc.m4 b/Build/source/libs/cairo/cairo-src/build/gtk-doc.m4 new file mode 100644 index 00000000000..36755432b50 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/build/gtk-doc.m4 @@ -0,0 +1,88 @@ +dnl -*- mode: autoconf -*- + +# serial 2 + +dnl Usage: +dnl GTK_DOC_CHECK([minimum-gtk-doc-version]) +AC_DEFUN([GTK_DOC_CHECK], +[ + AC_REQUIRE([PKG_PROG_PKG_CONFIG]) + AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first + AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first + + ifelse([$1],[],[gtk_doc_requires="gtk-doc"],[gtk_doc_requires="gtk-doc >= $1"]) + AC_MSG_CHECKING([for gtk-doc]) + PKG_CHECK_EXISTS([$gtk_doc_requires],[have_gtk_doc=yes],[have_gtk_doc=no]) + AC_MSG_RESULT($have_gtk_doc) + + if test "$have_gtk_doc" = "no"; then + AC_MSG_WARN([ + You will not be able to create source packages with 'make dist' + because $gtk_doc_requires is not found.]) + fi + + dnl check for tools we added during development + dnl Use AC_CHECK_PROG to avoid the check target using an absolute path that + dnl may not be writable by the user. Currently, automake requires that the + dnl test name must end in '.test'. + dnl https://bugzilla.gnome.org/show_bug.cgi?id=701638 + AC_CHECK_PROG([GTKDOC_CHECK],[gtkdoc-check],[gtkdoc-check.test]) + AC_PATH_PROG([GTKDOC_CHECK_PATH],[gtkdoc-check]) + AC_PATH_PROGS([GTKDOC_REBASE],[gtkdoc-rebase],[true]) + AC_PATH_PROG([GTKDOC_MKPDF],[gtkdoc-mkpdf]) + + dnl for overriding the documentation installation directory + AC_ARG_WITH([html-dir], + AS_HELP_STRING([--with-html-dir=PATH], [path to installed docs]),, + [with_html_dir='${datadir}/gtk-doc/html']) + HTML_DIR="$with_html_dir" + AC_SUBST([HTML_DIR]) + + dnl enable/disable documentation building + AC_ARG_ENABLE([gtk-doc], + AS_HELP_STRING([--enable-gtk-doc], + [use gtk-doc to build documentation [[default=no]]]),, + [enable_gtk_doc=no]) + + AC_MSG_CHECKING([whether to build gtk-doc documentation]) + AC_MSG_RESULT($enable_gtk_doc) + + if test "x$enable_gtk_doc" = "xyes" && test "$have_gtk_doc" = "no"; then + AC_MSG_ERROR([ + You must have $gtk_doc_requires installed to build documentation for + $PACKAGE_NAME. Please install gtk-doc or disable building the + documentation by adding '--disable-gtk-doc' to '[$]0'.]) + fi + + dnl don't check for glib if we build glib + if test "x$PACKAGE_NAME" != "xglib"; then + dnl don't fail if someone does not have glib + PKG_CHECK_MODULES(GTKDOC_DEPS, glib-2.0 >= 2.10.0 gobject-2.0 >= 2.10.0,,[:]) + fi + + dnl enable/disable output formats + AC_ARG_ENABLE([gtk-doc-html], + AS_HELP_STRING([--enable-gtk-doc-html], + [build documentation in html format [[default=yes]]]),, + [enable_gtk_doc_html=yes]) + AC_ARG_ENABLE([gtk-doc-pdf], + AS_HELP_STRING([--enable-gtk-doc-pdf], + [build documentation in pdf format [[default=no]]]),, + [enable_gtk_doc_pdf=no]) + + if test -z "$GTKDOC_MKPDF"; then + enable_gtk_doc_pdf=no + fi + + if test -z "$AM_DEFAULT_VERBOSITY"; then + AM_DEFAULT_VERBOSITY=1 + fi + AC_SUBST([AM_DEFAULT_VERBOSITY]) + + AM_CONDITIONAL([HAVE_GTK_DOC], [test x$have_gtk_doc = xyes]) + AM_CONDITIONAL([ENABLE_GTK_DOC], [test x$enable_gtk_doc = xyes]) + AM_CONDITIONAL([GTK_DOC_BUILD_HTML], [test x$enable_gtk_doc_html = xyes]) + AM_CONDITIONAL([GTK_DOC_BUILD_PDF], [test x$enable_gtk_doc_pdf = xyes]) + AM_CONDITIONAL([GTK_DOC_USE_LIBTOOL], [test -n "$LIBTOOL"]) + AM_CONDITIONAL([GTK_DOC_USE_REBASE], [test -n "$GTKDOC_REBASE"]) +]) diff --git a/Build/source/libs/cairo/cairo-src/cairo-version.h b/Build/source/libs/cairo/cairo-src/cairo-version.h new file mode 100644 index 00000000000..4c1de000c1c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/cairo-version.h @@ -0,0 +1,8 @@ +#ifndef CAIRO_VERSION_H +#define CAIRO_VERSION_H + +#define CAIRO_VERSION_MAJOR 1 +#define CAIRO_VERSION_MINOR 14 +#define CAIRO_VERSION_MICRO 6 + +#endif diff --git a/Build/source/libs/cairo/cairo-src/config.h.in b/Build/source/libs/cairo/cairo-src/config.h.in new file mode 100644 index 00000000000..96345a8df65 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/config.h.in @@ -0,0 +1,416 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* whether memory barriers are needed around atomic operations */ +#undef ATOMIC_OP_NEEDS_MEMORY_BARRIER + +/* Define to 1 if the PDF backend can be tested (need poppler and other + dependencies for pdf2png) */ +#undef CAIRO_CAN_TEST_PDF_SURFACE + +/* Define to 1 if the PS backend can be tested (needs ghostscript) */ +#undef CAIRO_CAN_TEST_PS_SURFACE + +/* Define to 1 if the SVG backend can be tested */ +#undef CAIRO_CAN_TEST_SVG_SURFACE + +/* Define to 1 if the Win32 Printing backend can be tested (needs ghostscript) + */ +#undef CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE + +/* Define to 1 if dlsym is available */ +#undef CAIRO_HAS_DLSYM + +/* Define to 1 to enable cairo's cairo-script-interpreter feature */ +#undef CAIRO_HAS_INTERPRETER + +/* Define to 1 to enable cairo's pthread feature */ +#undef CAIRO_HAS_PTHREAD + +/* Define to 1 if we have full pthread support */ +#undef CAIRO_HAS_REAL_PTHREAD + +/* Define to 1 if libspectre is available */ +#undef CAIRO_HAS_SPECTRE + +/* Define to 1 to enable cairo's symbol-lookup feature */ +#undef CAIRO_HAS_SYMBOL_LOOKUP + +/* Define to 1 to enable cairo's test surfaces feature */ +#undef CAIRO_HAS_TEST_SURFACES + +/* Define to 1 to enable cairo's cairo-trace feature */ +#undef CAIRO_HAS_TRACE + +/* Define to 1 to disable certain code paths that rely heavily on double + precision floating-point calculation */ +#undef DISABLE_SOME_FLOATING_POINT + +/* Define to 1 if your system stores words within floats with the most + significant word first */ +#undef FLOAT_WORDS_BIGENDIAN + +/* Enable pixman glyph cache */ +#undef HAS_PIXMAN_GLYPHS + +/* Define to 1 if you have the `alarm' function. */ +#undef HAVE_ALARM + +/* Define to 1 if you have the binutils development files installed */ +#undef HAVE_BFD + +/* Define to 1 if your compiler supports the __builtin_return_address() + intrinsic. */ +#undef HAVE_BUILTIN_RETURN_ADDRESS + +/* Define to 1 if you have the header file. */ +#undef HAVE_BYTESWAP_H + +/* Define to 1 if you have the `clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the `ctime_r' function. */ +#undef HAVE_CTIME_R + +/* Enable if your compiler supports the GCC __atomic_* atomic primitives */ +#undef HAVE_CXX11_ATOMIC_PRIMITIVES + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the `drand48' function. */ +#undef HAVE_DRAND48 + +/* Define to 1 if you have the `FcFini' function. */ +#undef HAVE_FCFINI + +/* Define to 1 if you have the `FcInit' function. */ +#undef HAVE_FCINIT + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `feclearexcept' function. */ +#undef HAVE_FECLEAREXCEPT + +/* Define to 1 if you have the `fedisableexcept' function. */ +#undef HAVE_FEDISABLEEXCEPT + +/* Define to 1 if you have the `feenableexcept' function. */ +#undef HAVE_FEENABLEEXCEPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_FENV_H + +/* Define to 1 if you have the `flockfile' function. */ +#undef HAVE_FLOCKFILE + +/* Define to 1 if you have the `fork' function. */ +#undef HAVE_FORK + +/* Define to 1 if you have the `FT_Get_X11_Font_Format' function. */ +#undef HAVE_FT_GET_X11_FONT_FORMAT + +/* Define to 1 if you have the `FT_GlyphSlot_Embolden' function. */ +#undef HAVE_FT_GLYPHSLOT_EMBOLDEN + +/* Define to 1 if you have the `FT_GlyphSlot_Oblique' function. */ +#undef HAVE_FT_GLYPHSLOT_OBLIQUE + +/* Define to 1 if you have the `FT_Library_SetLcdFilter' function. */ +#undef HAVE_FT_LIBRARY_SETLCDFILTER + +/* Define to 1 if you have the `FT_Load_Sfnt_Table' function. */ +#undef HAVE_FT_LOAD_SFNT_TABLE + +/* Define to 1 if you have the `funlockfile' function. */ +#undef HAVE_FUNLOCKFILE + +/* Whether you have gcov */ +#undef HAVE_GCOV + +/* Define to 1 if you have the `getline' function. */ +#undef HAVE_GETLINE + +/* Enable if your compiler supports the Intel __sync_* atomic primitives */ +#undef HAVE_INTEL_ATOMIC_PRIMITIVES + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_IO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIBGEN_H + +/* Define to 1 if you have the `rt' library (-lrt). */ +#undef HAVE_LIBRT + +/* Enable if you have libatomic-ops-dev installed */ +#undef HAVE_LIB_ATOMIC_OPS + +/* Define to 1 if you have the `link' function. */ +#undef HAVE_LINK + +/* Define to 1 if you have the Valgrind lockdep tool */ +#undef HAVE_LOCKDEP + +/* Define to 1 if you have lzo available */ +#undef HAVE_LZO + +/* Define to 1 if you have the Valgrind memfault tool */ +#undef HAVE_MEMFAULT + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to non-zero if your system has mkdir, and to 2 if your version of + mkdir requires a mode parameter */ +#undef HAVE_MKDIR + +/* Define to 1 if you have the `mmap' function. */ +#undef HAVE_MMAP + +/* Enable if you have MacOS X atomic operations */ +#undef HAVE_OS_ATOMIC_OPS + +/* Define to 1 if you have the `poppler_page_render' function. */ +#undef HAVE_POPPLER_PAGE_RENDER + +/* Define to 1 if you have the `raise' function. */ +#undef HAVE_RAISE + +/* Define to 1 if you have the `rsvg_pixbuf_from_file' function. */ +#undef HAVE_RSVG_PIXBUF_FROM_FILE + +/* Define to 1 if you have the `sched_getaffinity' function. */ +#undef HAVE_SCHED_GETAFFINITY + +/* Define to 1 if you have the header file. */ +#undef HAVE_SCHED_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SETJMP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SIGNAL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strndup' function. */ +#undef HAVE_STRNDUP + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_INT_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_IOCTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_MMAN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_POLL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_WAIT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_TIME_H + +/* Define to 1 if the system has the type `uint128_t'. */ +#undef HAVE_UINT128_T + +/* Define to 1 if the system has the type `uint64_t'. */ +#undef HAVE_UINT64_T + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have Valgrind */ +#undef HAVE_VALGRIND + +/* Define to 1 if you have the `waitpid' function. */ +#undef HAVE_WAITPID + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_X11_EXTENSIONS_SHMPROTO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_X11_EXTENSIONS_SHMSTR_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_X11_EXTENSIONS_XSHM_H + +/* Define to 1 if you have the `XRenderCreateConicalGradient' function. */ +#undef HAVE_XRENDERCREATECONICALGRADIENT + +/* Define to 1 if you have the `XRenderCreateLinearGradient' function. */ +#undef HAVE_XRENDERCREATELINEARGRADIENT + +/* Define to 1 if you have the `XRenderCreateRadialGradient' function. */ +#undef HAVE_XRENDERCREATERADIALGRADIENT + +/* Define to 1 if you have the `XRenderCreateSolidFill' function. */ +#undef HAVE_XRENDERCREATESOLIDFILL + +/* Define to 1 if you have zlib available */ +#undef HAVE_ZLIB + +/* Define to 1 if the system has the type `__uint128_t'. */ +#undef HAVE___UINT128_T + +/* Define to 1 if shared memory segments are released deferred. */ +#undef IPC_RMID_DEFERRED_RELEASE + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Shared library file extension */ +#undef SHARED_LIB_EXT + +/* The size of `int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of `long long', as computed by sizeof. */ +#undef SIZEOF_LONG_LONG + +/* The size of `size_t', as computed by sizeof. */ +#undef SIZEOF_SIZE_T + +/* The size of `void *', as computed by sizeof. */ +#undef SIZEOF_VOID_P + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif + + +/* Define to the value your compiler uses to support the warn-unused-result + attribute */ +#undef WARN_UNUSED_RESULT + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + + +/* Deal with multiple architecture compiles on Mac OS X */ +#ifdef __APPLE_CC__ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#define FLOAT_WORDS_BIGENDIAN 1 +#else +#undef WORDS_BIGENDIAN +#undef FLOAT_WORDS_BIGENDIAN +#endif +#endif + + +/* Define to 1 if the X Window System is missing or not being used. */ +#undef X_DISPLAY_MISSING + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to 1 if on MINIX. */ +#undef _MINIX + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#undef _POSIX_1_SOURCE + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#undef _POSIX_SOURCE + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif diff --git a/Build/source/libs/cairo/cairo-src/configure.ac b/Build/source/libs/cairo/cairo-src/configure.ac new file mode 100644 index 00000000000..2ce19599e30 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/configure.ac @@ -0,0 +1,878 @@ +AC_PREREQ([2.63]) +CAIRO_PARSE_VERSION +AC_INIT([cairo], + [cairo_version_major.cairo_version_minor.cairo_version_micro], + [http://bugs.freedesktop.org/enter_bug.cgi?product=cairo], + [cairo], + [http://cairographics.org/]) +AC_CONFIG_AUX_DIR(build) +AC_CONFIG_MACRO_DIR(build) +AC_USE_SYSTEM_EXTENSIONS +AC_CONFIG_SRCDIR(src/cairo.h) +AC_CONFIG_HEADERS(config.h) + +AC_CHECK_HEADERS([unistd.h sys/ioctl.h]) + +AM_INIT_AUTOMAKE([1.11 foreign -Wall no-define no-dist-gzip dist-xz]) +AM_SILENT_RULES([yes]) +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) dnl Workaround for Automake 1.12 + +# Initialize libtool +LT_PREREQ([2.2]) +LT_INIT([win32-dll]) + +# Api documentation +GTK_DOC_CHECK([1.15],[--flavour no-tmpl]) + +AC_SYS_LARGEFILE + +dnl =========================================================================== +dnl +dnl The order of the includes here is rather important +dnl +m4_include(build/configure.ac.version) dnl macros setting up various version declares +m4_include(build/configure.ac.tools) dnl checks for tools we use +m4_include(build/configure.ac.features) dnl macros for backend/feature handling +m4_include(build/configure.ac.warnings) dnl checks for compiler warning +m4_include(build/configure.ac.system) dnl checks for system functions, headers, libs +m4_include(build/configure.ac.analysis) dnl checks for analysis tools (lcov, etc) +m4_include(build/configure.ac.noversion) dnl disable builtin libtool versioning +m4_include(build/configure.ac.pthread) dnl checks for pthreads +AC_CACHE_SAVE + +dnl =========================================================================== + +AC_CHECK_LIB(z, compress, + [AC_CHECK_HEADER(zlib.h, [ + have_libz=yes + AC_DEFINE(HAVE_ZLIB, 1, [Define to 1 if you have zlib available]) + ], + [have_libz="no (requires zlib http://www.gzip.org/zlib/)"])], + [have_libz="no (requires zlib http://www.gzip.org/zlib/)"]) + +save_LIBS="$LIBS" +AC_CHECK_LIB(lzo2, lzo2a_decompress, + [AC_CHECK_HEADER(lzo/lzo2a.h, [ + have_lzo=yes + AC_DEFINE(HAVE_LZO, 1, [Define to 1 if you have lzo available]) + lzo_LIBS="-llzo2" + ], + [have_lzo="no (requires lzpo http://www.oberhumer.com/opensource/lzo/)"])], + [have_lzo="no (requires lzpo http://www.oberhumer.com/opensource/lzo/)"]) +AC_SUBST(lzo_LIBS) +LIBS="$save_LIBS" + +AC_CHECK_LIB(dl, dlsym, + [have_dlsym=yes; have_dl=yes], + [have_dlsym=no; have_dl=no]) +if test "x$have_dlsym" = "xno"; then + AC_CHECK_FUNC(dlsym, [have_dlsym=yes], [have_dlsym=no]) +fi +AC_CHECK_HEADERS(dlfcn.h, [have_dlsym=yes], [have_dlsym=no]) +AM_CONDITIONAL(CAIRO_HAS_DL, test "x$have_dl" = "xyes") +if test "x$have_dlsym" = "xyes"; then + AC_DEFINE([CAIRO_HAS_DLSYM], 1, [Define to 1 if dlsym is available]) +fi +AM_CONDITIONAL(CAIRO_HAS_DLSYM, test "x$have_dlsym" = "xyes") + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(xlib, Xlib, auto, [ + xlib_REQUIRES="x11 xext" + PKG_CHECK_MODULES(xlib, $xlib_REQUIRES, , + [xlib_REQUIRES="" + AC_PATH_XTRA + if test "x$no_x" = xyes; then + use_xlib="no (requires X development libraries)" + else + xlib_NONPKGCONFIG_LIBS="$X_PRE_LIBS $X_LIBS -lX11 -lXext $X_EXTRA_LIBS" + xlib_NONPKGCONFIG_CFLAGS=$X_CFLAGS + fi]) + + AC_CHECK_HEADER(sys/ipc.h) + AC_CHECK_HEADER(sys/shm.h) + + if test "$ac_cv_header_sys_ipc_h" = "yes" -a "$ac_cv_header_sys_shm_h" = "yes"; then + AC_MSG_CHECKING(whether shmctl IPC_RMID allowes subsequent attaches) + AC_TRY_RUN([ + #include + #include + #include + int main() + { + char *shmaddr; + int id = shmget (IPC_PRIVATE, 4, IPC_CREAT | 0600); + if (id == -1) return 2; + shmaddr = shmat (id, 0, 0); + shmctl (id, IPC_RMID, 0); + if ((char*) shmat (id, 0, 0) == (char*) -1) { + shmdt (shmaddr); + return 1; + } + shmdt (shmaddr); + shmdt (shmaddr); + return 0; + } + ], + AC_DEFINE(IPC_RMID_DEFERRED_RELEASE, 1, + [Define to 1 if shared memory segments are released deferred.]) + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no), + AC_MSG_RESULT(assuming no)) + fi + + AC_CHECK_HEADERS([X11/extensions/XShm.h X11/extensions/shmproto.h X11/extensions/shmstr.h], [], [], + [#include + #include ]) +]) + +CAIRO_ENABLE_SURFACE_BACKEND(xlib_xrender, Xlib Xrender, auto, [ + if test "x$use_xlib" != "xyes"; then + use_xlib_xrender="no (requires --enable-xlib)" + else + dnl Check for Xrender header files if the Xrender package is not installed: + xlib_xrender_BASE=cairo-xlib + xlib_xrender_REQUIRES="xrender >= 0.6" + PKG_CHECK_MODULES(xlib_xrender, $xlib_xrender_REQUIRES, , + [xlib_xrender_REQUIRES="" + old_CPPFLAGS=$CPPFLAGS + CPPFLAGS="$CPPFLAGS $xlib_CFLAGS $xlib_NONPKGCONFIG_CFLAGS" + AC_CHECK_HEADER(X11/extensions/Xrender.h, + [xlib_xrender_NONPKGCONFIG_LIBS="-lXrender"], + [use_xlib_xrender="no (requires $xlib_xrender_REQUIRES http://freedesktop.org/Software/xlibs)"], + [#include ]) + CPPFLAGS=$old_CPPFLAGS + ]) + + old_CFLAGS=$CFLAGS + old_LIBS=$LIBS + CFLAGS="$CFLAGS $xlib_CFLAGS $xlib_NONPKGCONFIG_CFLAGS $xlib_xrender_CFLAGS $xlib_xrender_NONPKGCONFIG_CFLAGS" + LIBS="$LIBS $xlib_LIBS $xlib_NONPKGCONFIG_LIBS $xlib_xrender_LIBS $xlib_xrender_NONPKGCONFIG_LIBS" + AC_CHECK_FUNCS([XRenderCreateSolidFill XRenderCreateLinearGradient XRenderCreateRadialGradient XRenderCreateConicalGradient]) + CFLAGS=$old_CFLAGS + LIBS=$old_LIBS + + fi +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(xcb, XCB, auto, [ + xcb_REQUIRES="xcb >= 1.6 xcb-render >= 1.6" + PKG_CHECK_MODULES(xcb, $xcb_REQUIRES, , + [use_xcb="no (requires $xcb_REQUIRES http://xcb.freedesktop.org)"]) +]) + +CAIRO_ENABLE_FUNCTIONS(xlib_xcb, Xlib/XCB, no, [ + if test "x$use_xcb" = "xyes" -a "x$use_xlib" = "xyes"; then + xlib_xcb_REQUIRES="x11-xcb" + PKG_CHECK_MODULES(xlib_xcb, $xlib_xcb_REQUIRES, , + [use_xlib_xcb="no (requires $xlib_xcb_REQUIRES http://xcb.freedesktop.org)"]) + else + use_xlib_xcb="no (requires both --enable-xlib and --enable-xcb)" + fi +]) + +CAIRO_ENABLE_FUNCTIONS(xcb_shm, XCB/SHM, auto, [ + if test "x$use_xcb" = "xyes"; then + xcb_shm_REQUIRES="xcb-shm" + PKG_CHECK_MODULES(xcb_shm, $xcb_shm_REQUIRES, , + [use_xcb_shm="no (requires $xcb_shm http://xcb.freedesktop.org)"]) + else + use_xcb_shm="no (requires --enable-xcb)" + fi +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(qt, Qt, no, [ + qt_REQUIRES="QtGui >= 4.4.0" + PKG_CHECK_MODULES(qt, $qt_REQUIRES, , + [qt_REQUIRES="" + use_qt="no (requires Qt4 development libraries)" + ]) + qt_NONPKGCONFIG_LIBS="-lstdc++" +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(quartz, Quartz, auto, [ + dnl There is no pkgconfig for quartz; lets do a header check + AC_CHECK_HEADER(ApplicationServices/ApplicationServices.h, , [use_quartz="no (requires ApplicationServices framework)"]) + if test "x$use_quartz" != "xyes" ; then + dnl check for CoreGraphics as a separate framework + AC_CHECK_HEADER(CoreGraphics/CoreGraphics.h, , [use_quartz="no (requires CoreGraphics framework)"]) + quartz_LIBS="-Xlinker -framework -Xlinker CoreGraphics" + else + quartz_LIBS="-Xlinker -framework -Xlinker ApplicationServices" + fi +]) + +CAIRO_ENABLE_FONT_BACKEND(quartz_font, Quartz, auto, [ + use_quartz_font=$use_quartz +]) + +CAIRO_ENABLE_SURFACE_BACKEND(quartz_image, Quartz Image, no, [ + use_quartz_image=$use_quartz +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(win32, Microsoft Windows, auto, [ + if test "x$have_windows" != xyes; then + use_win32="no (requires a Win32 platform)" + fi + win32_LIBS="-lgdi32 -lmsimg32" +]) + +CAIRO_ENABLE_FONT_BACKEND(win32_font, Microsoft Windows, auto, [ + use_win32_font=$use_win32 +]) + +test_win32_printing=no +if test "x$use_win32" = "xyes"; then + AC_CHECK_PROG(GS, gs, gs) + if test "$GS"; then + AC_DEFINE([CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE], 1, [Define to 1 if the Win32 Printing backend can be tested (needs ghostscript)]) + test_win32_printing="yes" + else + AC_MSG_WARN([Win32 Printing backend will not be tested since ghostscript is not available]) + test_win32_printing="no (requires ghostscript)" + fi +fi + +AM_CONDITIONAL(CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE, test "x$test_win32_printing" = "xyes") + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(skia, Skia, no, [ + AC_ARG_WITH([skia], + [AS_HELP_STRING([--with-skia=/path/to/skia], + [directory to find compiled skia sources])], + [skia_DIR="$withval"], + [skia_DIR="`pwd`/../skia"]) + AC_ARG_WITH([skia-build-type], + [AS_HELP_STRING([--with-skia-build-type=(Release|Debug)] + [build of skia to link with, default is Release])], + [skia_BUILD_TYPE="$withval"], + [skia_BUILD_TYPE="Release"]) + skia_NONPKGCONFIG_CFLAGS="-I$skia_DIR/include/config -I$skia_DIR/include/core -I$skia_DIR/include/effects" + if test "x$skia_BUILD_TYPE" = "xRelease"; then + skia_NONPKGCONFIG_CFLAGS="-DSK_RELEASE -DSK_CAN_USE_FLOAT $skia_NONPKGCONFIG_CFLAGS" + fi + skia_NONPKGCONFIG_LIBS="-L$skia_DIR/out/$skia_BUILD_TYPE/lib.target/ -lskia -lstdc++" + AC_SUBST(skia_DIR) +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(os2, OS/2, no, [ + case "$host" in + *-*-os2*) + : + ;; + *) + use_os2="no (requires an OS/2 platform)" + ;; + esac +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(beos, BeOS/Zeta, no, [ + case "$host" in + *-*-beos) + beos_LIBS="" + dnl Add libbe and libzeta if available + AC_CHECK_LIB(be,main,beos_LIBS="$beos_LIBS -lbe") + AC_CHECK_LIB(zeta,main,beos_LIBS="$beos_LIBS -lzeta") + ;; + *) + use_beos="no (requires a BeOS platform)" + ;; + esac +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(drm, DRM, no, [ + drm_REQUIRES="libudev >= 136" + PKG_CHECK_MODULES(drm, $drm_REQUIRES, , + [use_drm="no (requires $drm_REQUIRES, udev is available from git://git.kernel.org/pub/scm/linux/hotplug/udev.git)"]) +]) + +CAIRO_ENABLE_SURFACE_BACKEND(gallium, Gallium3D, no, [ + if test "x$use_drm" = "xyes"; then + AC_ARG_WITH([gallium], + [AS_HELP_STRING([--with-gallium=/path/to/mesa], + [directory to find gallium enabled mesa])], + [mesa_DIR="$withval"], + [mesa_DIR="`pwd`/../mesa"]) + gallium_DIR="$mesa_DIR/src/gallium" + gallium_NONPKGCONFIG_CFLAGS="-I$mesa_DIR/include -I$mesa_DIR/src/mesa -I$gallium_DIR/include -I$gallium_DIR/auxiliary" + gallium_NONPKGCONFIG_LIBS="-lGL" + AC_SUBST(mesa_DIR) + AC_SUBST(gallium_DIR) + else + use_gallium="no (requires --enable-drm)" + fi +]) + +dnl =========================================================================== + +CAIRO_ENABLE_FUNCTIONS(png, PNG, yes, [ + use_png=no + AC_ARG_VAR([png_REQUIRES], [module name for libpng to search for using pkg-config]) + if test "x$png_REQUIRES" = x; then + # libpng13 is GnuWin32's libpng-1.2.8 :-( + for l in libpng libpng14 libpng12 libpng13 libpng10; do + if $PKG_CONFIG --exists $l ; then + png_REQUIRES=$l + use_png=yes + break + fi + done + else + use_png=yes + fi + + if test "x$use_png" = "xyes" ; then + PKG_CHECK_MODULES(png, $png_REQUIRES, , : ) + else + AC_MSG_WARN([Could not find libpng in the pkg-config search path]) + fi +]) + +dnl =========================================================================== +CAIRO_ENABLE_SURFACE_BACKEND(gl, OpenGL, no, [ + gl_REQUIRES="gl" + PKG_CHECK_MODULES(gl, $gl_REQUIRES,, [ + dnl Fallback to searching for headers + AC_CHECK_HEADER(GL/gl.h,, [use_gl="no (gl.pc nor OpenGL headers not found)"]) + if test "x$use_gl" = "xyes"; then + gl_NONPKGCONFIG_CFLAGS= + gl_NONPKGCONFIG_LIBS="-lGL" + fi]) + + if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then + gl_LIBS="$gl_LIBS -ldl" + fi + + need_glx_functions=yes + need_wgl_functions=yes + need_egl_functions=yes +]) + +dnl =========================================================================== +CAIRO_ENABLE_SURFACE_BACKEND(glesv2, OpenGLESv2, no, [ + glesv2_REQUIRES="glesv2" + PKG_CHECK_MODULES(glesv2, $glesv2_REQUIRES,, [ + dnl Fallback to searching for headers + AC_CHECK_HEADER(GLES2/gl2.h,, [use_glesv2="no (glesv2.pc nor OpenGL ES 2.0 headers not found)"]) + if test "x$use_glesv2" = "xyes"; then + glesv2_NONPKGCONFIG_CFLAGS= + glesv2_NONPKGCONFIG_LIBS="-lGLESv2" + fi]) + + if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then + glesv2_LIBS="$glesv2_LIBS -ldl" + fi + + if test "x$use_glesv2" = "xyes" -a "x$use_gl" = "xyes"; then + AC_MSG_ERROR([use either --enable-gl=yes or --enable-glesv2=yes. Not both at the same time.]) + fi + + need_egl_functions=yes +]) + +dnl =========================================================================== +CAIRO_ENABLE_SURFACE_BACKEND(cogl, Cogl, no, [ + cogl_REQUIRES="cogl-2.0-experimental" + PKG_CHECK_MODULES(cogl, $cogl_REQUIRES,, [use_cogl="no"]) +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(directfb, directfb, no, [ + directfb_REQUIRES=directfb + PKG_CHECK_MODULES(directfb, $directfb_REQUIRES, , + [use_directfb="no (requires $directfb_REQUIRES http://www.directfb.org)"]) +]) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(vg, OpenVG, no, [ + dnl There is no pkgconfig for OpenVG; lets do a header check + AC_CHECK_HEADER(VG/openvg.h,, [use_vg="no (OpenVG headers not found)"]) + if test "x$use_vg" = "xyes"; then + vg_NONPKGCONFIG_CFLAGS= + vg_NONPKGCONFIG_LIBS="-lOpenVG" + need_egl_functions=yes + need_glx_functions=yes + fi +]) + +CAIRO_ENABLE_FUNCTIONS(egl, EGL, auto, [ + if test "x$need_egl_functions" = "xyes"; then + egl_REQUIRES="egl" + PKG_CHECK_MODULES(egl, $egl_REQUIRES, , + [egl_REQUIRES="" + AC_CHECK_HEADER(EGL/egl.h,, [use_egl="no (EGL headers not found)"]) + if test "x$use_egl" = "xyes"; then + egl_NONPKGCONFIG_CFLAGS= + egl_NONPKGCONFIG_LIBS= + save_LIBS="$LIBS" + other_egl_LIBS="" + # Temporary workaround for missing link from egl13 + AC_CHECK_LIB(csi, csi_stream_attachresource, other_egl_LIBS="-lcsi") + LIBS="$other_egl_LIBS $LIBS" + for egl_lib in EGL egl13 egl12 egl11; do + if test -z "$egl_NONPKGCONFIG_LIBS"; then + AC_CHECK_LIB($egl_lib, eglGetError, egl_NONPKGCONFIG_LIBS="-l$egl_lib") + fi + done + if test -z "$egl_NONPKGCONFIG_LIBS"; then + use_egl="no (EGL library not found)" + else + egl_NONPKGCONFIG_LIBS="$egl_NONPKGCONFIG_LIBS $other_egl_LIBS" + fi + LIBS="$save_LIBS" + fi + ]) + else + use_egl="no (not required by any backend)" + fi +]) + +CAIRO_ENABLE_FUNCTIONS(glx, GLX, auto, [ + if test "x$need_glx_functions" = "xyes"; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $gl_CFLAGS $gl_NONPKGCONFIG_CFLAGS" + AC_CHECK_HEADER(GL/glx.h,, [use_glx="no (GLX headers not found)"]) + glx_NONPKGCONFIG_CFLAGS= + glx_NONPKGCONFIG_LIBS="-lGL" + CFLAGS="$save_CFLAGS" + else + use_glx="no (not required by any backend)" + fi +]) + +CAIRO_ENABLE_FUNCTIONS(wgl, WGL, auto, [ + if test "x$need_wgl_functions" = "xyes"; then + AC_CHECK_HEADER(windows.h,, [use_wgl="no (WGL headers not found)"]) + else + use_wgl="no (not required by any backend)" + fi +]) + +dnl =========================================================================== + +any2ppm_cs=no +CAIRO_ENABLE_SURFACE_BACKEND(script, script, yes, [ + any2ppm_cs=yes +]) + +dnl =========================================================================== + +# We use pkg-config to look for freetype2, but fall back to +# freetype-config if it fails. We prefer pkg-config, since we can +# then just put freetype2 >= $FREETYPE_MIN_VERSION in +# Requires.private, but at least up to 2003-06-07, there was no +# freetype2.pc in the release. +# +# FreeType versions come in three forms: +# release (such as 2.1.9) +# libtool (such as 9.7.3) (returned by freetype-config and pkg-config) +# platform-specific/soname (such as 6.3.4) +# and they recommend you never use the platform-specific version +# (see docs/VERSION.DLL in freetype2 sources) +# +# Set these as appropriate: + +# release number - for information only +FREETYPE_MIN_RELEASE=2.1.9 +# libtool-specific version - this is what is checked +FREETYPE_MIN_VERSION=9.7.3 + +CAIRO_ENABLE_FONT_BACKEND(ft, FreeType, auto, [ + + PKG_CHECK_MODULES(FREETYPE, freetype2 >= $FREETYPE_MIN_VERSION, + [freetype_pkgconfig=yes], + [freetype_pkgconfig=no]) + + if test "x$freetype_pkgconfig" = "xyes"; then + ft_REQUIRES="freetype2 >= $FREETYPE_MIN_VERSION $ft_REQUIRES" + else + + if test -z "$FREETYPE_CONFIG"; then + AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no) + fi + if test "x$FREETYPE_CONFIG" = "xno" ; then + use_ft='no (freetype-config not found in path or $FREETYPE_CONFIG)' + else + AC_MSG_CHECKING(freetype2 libtool version) + + FREETYPE_VERSION=`$FREETYPE_CONFIG --version` + AX_COMPARE_VERSION([$FREETYPE_VERSION], [gt], [$FREETYPE_MIN_VERSION], + [AC_MSG_RESULT($FREETYPE_VERSION - OK) + ft_NONPKGCONFIG_CFLAGS=`$FREETYPE_CONFIG --cflags` + ft_NONPKGCONFIG_LIBS=`$FREETYPE_CONFIG --libs`], + [AC_MSG_RESULT($FREETYPE_VERSION - Too old) + use_ft="no ($FREETYPE_VERSION found; version $FREETYPE_MIN_VERSION from release $FREETYPE_MIN_RELEASE required)"]) + fi + fi + + ft_CFLAGS="$FREETYPE_CFLAGS" + ft_LIBS="$FREETYPE_LIBS" +]) + +FONTCONFIG_MIN_VERSION=2.2.95 +CAIRO_ENABLE_FONT_BACKEND(fc, Fontconfig, auto, [ + use_fc=$use_ft + if test "x$use_fc" = "xyes"; then + fc_REQUIRES="fontconfig >= $FONTCONFIG_MIN_VERSION" + PKG_CHECK_MODULES(FONTCONFIG, $fc_REQUIRES,, + [use_fc="no (requires $fc_REQUIRES)"]) + fi + fc_CFLAGS="$FONTCONFIG_CFLAGS" + fc_LIBS="$FONTCONFIG_LIBS" +]) + +if test "x$use_ft" = "xyes"; then + _save_libs="$LIBS" + _save_cflags="$CFLAGS" + LIBS="$LIBS $ft_LIBS" + CFLAGS="$CFLAGS $ft_CFLAGS" + + AC_CHECK_FUNCS(FT_Get_X11_Font_Format FT_GlyphSlot_Embolden FT_GlyphSlot_Oblique FT_Load_Sfnt_Table FT_Library_SetLcdFilter) + + LIBS="$_save_libs" + CFLAGS="$_save_cflags" +fi + +if test "x$use_fc" = "xyes"; then + CAIRO_CHECK_FUNCS_WITH_FLAGS(FcInit FcFini, [$FONTCONFIG_CFLAGS], [$FONTCONFIG_LIBS]) +fi + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(ps, PostScript, yes, [ + # The ps backend requires zlib. + use_ps=$have_libz + ps_NONPKGCONFIG_LIBS=-lz +]) + +dnl =========================================================================== + +SPECTRE_VERSION_REQUIRED=0.2.0 +test_ps=no +any2ppm_ps=no +if test "x$use_ps" = "xyes"; then + AC_CHECK_PROG(GS, gs, gs) + if test "$GS"; then + AC_DEFINE([CAIRO_CAN_TEST_PS_SURFACE], 1, [Define to 1 if the PS backend can be tested (needs ghostscript)]) + test_ps="yes" + else + AC_MSG_WARN([PS backend will not be tested since ghostscript is not available]) + test_ps="no (requires ghostscript)" + fi + + libspectre_DEPENDENCY="libspectre >= $SPECTRE_VERSION_REQUIRED" + PKG_CHECK_MODULES(LIBSPECTRE, $libspectre_DEPENDENCY, + [any2ppm_ps=yes], + [test_ps="no (requires libspectre)"]) +fi + +AM_CONDITIONAL(CAIRO_CAN_TEST_PS_SURFACE, test "x$test_ps" = "xyes") +AM_CONDITIONAL(CAIRO_HAS_SPECTRE, test "x$any2ppm_ps" = "xyes") +if test "x$any2ppm_ps" = "xyes"; then + AC_DEFINE([CAIRO_HAS_SPECTRE], 1, [Define to 1 if libspectre is available]) +fi +AC_SUBST(LIBSPECTRE_CFLAGS) +AC_SUBST(LIBSPECTRE_LIBS) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(pdf, PDF, yes, [ + # The pdf backend requires zlib. + use_pdf=$have_libz + pdf_NONPKGCONFIG_LIBS=-lz +]) + +dnl =========================================================================== + +# poppler-0.17.4 fixes text-pattern and text-transform +POPPLER_VERSION_REQUIRED=0.17.4 +test_pdf=no +any2ppm_pdf=no +if test "x$use_pdf" = "xyes"; then + poppler_DEPENDENCY="poppler-glib >= $POPPLER_VERSION_REQUIRED" + PKG_CHECK_MODULES(POPPLER, $poppler_DEPENDENCY, + [CAIRO_CHECK_FUNCS_WITH_FLAGS(poppler_page_render, [$POPPLER_CFLAGS], [$POPPLER_LIBS], + [test_pdf=yes; any2ppm_pdf=yes], + [test_pdf="no (requires $poppler_DEPENDENCY)"])], + [test_pdf="no (requires $poppler_DEPENDENCY)"]) + if test "x$test_pdf" = "xyes"; then + AC_DEFINE([CAIRO_CAN_TEST_PDF_SURFACE], 1, [Define to 1 if the PDF backend can be tested (need poppler and other dependencies for pdf2png)]) + else + AC_MSG_WARN([PDF backend will not be tested since poppler >= $POPPLER_VERSION_REQUIRED is not available]) + fi +fi + +AM_CONDITIONAL(CAIRO_CAN_TEST_PDF_SURFACE, test "x$test_pdf" = "xyes") +AC_SUBST(POPPLER_CFLAGS) +AC_SUBST(POPPLER_LIBS) + +AM_CONDITIONAL(CAIRO_HAS_MULTI_PAGE_SURFACES, test "x$use_ps" = "xyes" -o "x$use_pdf" = "xyes") + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(svg, SVG, yes, [ + if test "x$use_png" != "xyes"; then + use_svg="no (requires --enable-png)" + fi +]) + +LIBRSVG_VERSION_REQUIRED=2.35.0 +test_svg=no +any2ppm_svg=no +if test "x$use_svg" = "xyes"; then + librsvg_DEPENDENCY="librsvg-2.0 >= $LIBRSVG_VERSION_REQUIRED" + PKG_CHECK_MODULES(LIBRSVG, $librsvg_DEPENDENCY gdk-2.0, + [CAIRO_CHECK_FUNCS_WITH_FLAGS(rsvg_pixbuf_from_file, [$LIBRSVG_CFLAGS], [$LIBRSVG_LIBS], + [test_svg=yes; any2ppm_svg=yes], + [test_svg="no (requires $librsvg_DEPENDENCY)"])], + [test_svg="no (requires $librsvg_DEPENDENCY)"]) + if test "x$test_svg" = "xyes"; then + AC_DEFINE([CAIRO_CAN_TEST_SVG_SURFACE], 1, [Define to 1 if the SVG backend can be tested]) + else + AC_MSG_WARN([SVG backend will not be tested since librsvg >= $LIBRSVG_VERSION_REQUIRED is not available]) + fi +fi + +AM_CONDITIONAL(CAIRO_CAN_TEST_SVG_SURFACE, test "x$test_svg" = "xyes") +AC_SUBST(LIBRSVG_CFLAGS) +AC_SUBST(LIBRSVG_LIBS) + +dnl =========================================================================== + +dnl XXX make this a private feature? +CAIRO_ENABLE(test_surfaces, test surfaces, no) + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(image, image, always, [ + pixman_REQUIRES="pixman-1 >= 0.30.0" + PKG_CHECK_MODULES(pixman, $pixman_REQUIRES, , + [use_image="no (requires $pixman_REQUIRES http://cairographics.org/releases/)"]) + image_REQUIRES=$pixman_REQUIRES + image_CFLAGS=$pixman_CFLAGS + image_LIBS=$pixman_LIBS +]) + +if pkg-config --exists 'pixman-1 >= 0.27.1'; then + AC_DEFINE([HAS_PIXMAN_GLYPHS], 1, [Enable pixman glyph cache]) +fi + + +dnl =========================================================================== + +CAIRO_ENABLE_SURFACE_BACKEND(mime, mime, always) +CAIRO_ENABLE_SURFACE_BACKEND(recording, recording, always) +CAIRO_ENABLE_SURFACE_BACKEND(observer, observer, always) +CAIRO_ENABLE_SURFACE_BACKEND(tee, tee, no) +CAIRO_ENABLE_SURFACE_BACKEND(xml, xml, no, [ + use_xml=$have_libz + xml_NONPKGCONFIG_LIBS=-lz +]) + +dnl =========================================================================== + +CAIRO_ENABLE_FONT_BACKEND(user, user, always) + +dnl =========================================================================== +dnl +dnl This needs to be last on our list of features so that the pthread libs and flags +dnl gets prefixed in front of everything else in CAIRO_{CFLAGS,LIBS}. +dnl +have_real_pthread=no +have_pthread=no +CAIRO_ENABLE(pthread, pthread, auto, [CAIRO_CONFIGURE_PTHREAD]) +AM_CONDITIONAL(HAVE_REAL_PTHREAD, test "x$use_pthread" = "xyes" -a "x$have_real_pthread" = "xyes") +AM_CONDITIONAL(HAVE_PTHREAD, test "x$use_pthread" = "xyes") +AC_SUBST(pthread_CFLAGS) +AC_SUBST(pthread_LIBS) +AC_SUBST(real_pthread_CFLAGS) +AC_SUBST(real_pthread_LIBS) + + +dnl =========================================================================== +dnl Build gobject integration library + +CAIRO_ENABLE_FUNCTIONS(gobject, gobject, auto, [ + gobject_REQUIRES="gobject-2.0 glib-2.0 >= 2.14" + PKG_CHECK_MODULES(GOBJECT, $gobject_REQUIRES, , + [use_gobject="no (requires $gobject_REQUIRES http://download.gnome.org/pub/GNOME/sources/glib/)"]) + gobject_NONPKGCONFIG_EXTRA_LIBS="-L\${libdir} -lcairo-gobject" +]) +dnl I'm too lazy to fix the caching properly +if test "x$use_gobject" = "xyes"; then + PKG_CHECK_MODULES(GOBJECT, $gobject_REQUIRES, : ) +fi + +dnl =========================================================================== +dnl Default to quick testing during development, but force a full test before +dnl release + +AC_ARG_ENABLE(full-testing, + AS_HELP_STRING([--enable-full-testing], + [Sets the test suite to perform full testing by default, which + will dramatically slow down make check, but is a + *requirement* before release.]), [ +if test "x$enableval" = "xyes"; then + CAIRO_TEST_MODE=full + AC_SUBST(CAIRO_TEST_MODE) +fi +]) + +dnl =========================================================================== +dnl Build the external converter if we have any of the test backends +AM_CONDITIONAL(BUILD_ANY2PPM, + test "x$any2ppm_svg" = "xyes" \ + -o "x$any2ppm_pdf" = "xyes" \ + -o "x$any2ppm_ps" = "xyes" \ + -o "x$any2ppm_cs" = "xyes") + +dnl =========================================================================== +dnl Some utilities need to dlopen the shared libraries, so they need to +dnl know how libtools will name them + +case $host in +*-*-darwin*) + SHLIB_EXT="dylib" + ;; +*) + SHLIB_EXT="so" + ;; +esac +AC_DEFINE_UNQUOTED(SHARED_LIB_EXT, "${SHLIB_EXT}", [Shared library file extension]) +AC_SUBST(SHLIB_EXT) + +dnl =========================================================================== +dnl The tracing utility requires LD_PRELOAD, so only build it for systems +dnl that are known to work. + +case $host in +*-linux*|*-*bsd*|*-solaris*|*-*-darwin*|*-dragonfly*|*-*-gnu*) + have_ld_preload="yes" + ;; +*) + have_ld_preload="no" + ;; +esac + +CAIRO_ENABLE(trace, cairo-trace, auto, [ + if test "x$have_ld_preload" != "xyes" -o \ + "x$have_libz" != "xyes" -o \ + "x$have_real_pthread" != "xyes" -o \ + "x$have_dlsym" != "xyes"; then + use_trace="no (requires dynamic linker and zlib and real pthreads)" + fi +]) + +CAIRO_ENABLE(interpreter, cairo-script-interpreter, yes, [ + if test "x$have_libz" != "xyes"; then + use_interpreter="no (requires zlib)" + fi +]) + +AC_CHECK_LIB(bfd, bfd_openr, + [AC_CHECK_HEADER(bfd.h, [have_bfd=yes], + [have_bfd=no])], [have_bfd=no]) +AC_CHECK_HEADER(libiberty.h,, [have_bfd=no]) +if test "x$have_bfd" = "xyes"; then + AC_DEFINE([HAVE_BFD], [1], [Define to 1 if you have the binutils development files installed]) + BFD_LIBS=-lbfd + AC_SUBST(BFD_LIBS) +fi + +CAIRO_ENABLE(symbol_lookup, symbol-lookup, auto, [ + if test "x$have_bfd" != "xyes"; then + use_symbol_lookup="no (requires bfd)" + fi +]) + +PKG_CHECK_MODULES(glib, glib-2.0, have_glib=yes, have_glib=no) +AC_SUBST(glib_CFLAGS) +AC_SUBST(glib_LIBS) +AM_CONDITIONAL(BUILD_SPHINX, test "x$have_glib" = "xyes" -a "x$have_windows" = "xno") + +save_LIBS="$LIBS" +AC_CHECK_LIB(rt, shm_open, shm_LIBS="-lrt") +AC_SUBST(shm_LIBS) +LIBS="$save_LIBS" + +dnl =========================================================================== + +AC_ARG_ENABLE(some-floating-point, + AS_HELP_STRING([--disable-some-floating-point], + [Disable certain code paths that rely heavily on double precision + floating-point calculation. This option can improve + performance on systems without a double precision floating-point + unit, but might degrade performance on those that do.]), [ +if test "x$enableval" = "xno"; then + # A value of 'no' for $enableval means that they want to disable, which + # means 'yes' for $disable_some_floating_point. + disable_some_floating_point=yes +fi +], [disable_some_floating_point=no]) + +AM_CONDITIONAL(DISABLE_SOME_FLOATING_POINT, + test "x$disable_some_floating_point" = "xyes") +if test "x$disable_some_floating_point" = "xyes"; then + AC_DEFINE(DISABLE_SOME_FLOATING_POINT, 1, + [Define to 1 to disable certain code paths that rely heavily on + double precision floating-point calculation]) +fi + +dnl =========================================================================== + +dnl Extra stuff we need to do when building C++ code +need_cxx="no" +AS_IF([test "x$use_skia" = "xyes"], [need_cxx="yes"]) +AS_IF([test "x$use_qt" = "xyes"], [need_cxx="yes"]) +AS_IF([test "x$use_beos" = "xyes"], [need_cxx="yes"]) + +AM_CONDITIONAL(BUILD_CXX, test "x$need_cxx" = "xyes") + +dnl =========================================================================== + +# We use GTK+ for some utility/debugging tools +PKG_CHECK_MODULES(gtk, "gtk+-2.0",have_gtk=yes, have_gtk=no) +AM_CONDITIONAL(HAVE_GTK, test "x$have_gtk" = "xyes") + +AC_CONFIG_FILES([ +Makefile +boilerplate/Makefile +src/Makefile +test/Makefile +test/pdiff/Makefile +perf/Makefile +perf/micro/Makefile +util/Makefile +util/cairo-fdr/Makefile +util/cairo-gobject/Makefile +util/cairo-missing/Makefile +util/cairo-script/Makefile +util/cairo-script/examples/Makefile +util/cairo-sphinx/Makefile +util/cairo-trace/Makefile +util/cairo-trace/cairo-trace +doc/Makefile +doc/public/Makefile +]) +AC_CONFIG_COMMANDS([cairo-trace], + [chmod a+x util/cairo-trace/cairo-trace]) + +AC_OUTPUT +CAIRO_REPORT diff --git a/Build/source/libs/cairo/cairo-src/src/Makefile.am b/Build/source/libs/cairo/cairo-src/src/Makefile.am new file mode 100644 index 00000000000..acf0a828100 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/Makefile.am @@ -0,0 +1,119 @@ +# Note: All source files are listed in Makefile.sources. + +include $(top_srcdir)/build/Makefile.am.common +include $(srcdir)/Makefile.am.features + +EXTRA_DIST += Makefile.win32 Makefile.win32.features +#MAINTAINERCLEANFILES += $(srcdir)/Makefile.win32.features + +AM_CPPFLAGS = -I$(srcdir) $(CAIRO_CFLAGS) +AM_LDFLAGS = $(CAIRO_LDFLAGS) + +if OS_WIN32 +export_symbols = -export-symbols cairo.def +cairo_def_dependency = cairo.def +endif + +$(top_builddir)/config.h: $(top_srcdir)/config.h.in + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) config.h + +cairoincludedir = $(includedir)/cairo +cairoinclude_HEADERS = $(enabled_cairo_headers) + +lib_LTLIBRARIES = libcairo.la + +if BUILD_CXX +cairo_cxx_lib = libcairo_cxx.la +else +cairo_cxx_lib = +endif + +noinst_LTLIBRARIES = $(cairo_cxx_lib) +libcairo_cxx_la_SOURCES = \ + $(enabled_cairo_headers) \ + $(enabled_cairo_private) \ + $(enabled_cairo_cxx_sources) \ + $(NULL) +libcairo_cxx_la_LDFLAGS = $(AM_LDFLAGS) $(export_symbols) +libcairo_cxx_la_LIBADD = $(CAIRO_LIBS) +libcairo_cxx_la_DEPENDENCIES = $(cairo_def_dependency) + + +libcairo_la_SOURCES = \ + $(enabled_cairo_headers) \ + $(enabled_cairo_private) \ + $(enabled_cairo_sources) \ + $(NULL) +libcairo_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(CAIRO_LIBTOOL_VERSION_INFO) -no-undefined $(export_symbols) +libcairo_la_LIBADD = $(CAIRO_LIBS) \ + $(cairo_cxx_lib) +libcairo_la_DEPENDENCIES = $(cairo_def_dependency) $(cairo_cxx_lib) + +# Special headers +cairoinclude_HEADERS += $(top_srcdir)/cairo-version.h +libcairo_la_SOURCES += cairo-version.h +nodist_cairoinclude_HEADERS = cairo-features.h +nodist_libcairo_la_SOURCES = cairo-features.h +BUILT_SOURCES += cairo-features.h cairo-supported-features.h +DISTCLEANFILES += cairo-features.h cairo-supported-features.h +cairo-features.h cairo-supported-features.h: + cd $(top_builddir) && ./config.status src/$@ + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = $(enabled_cairo_pkgconf) + +CLEANFILES += cairo.def +cairo.def: cairo-features.h $(enabled_cairo_headers) + @echo Generating $@ + @(echo EXPORTS; \ + (cd $(srcdir); cat $(enabled_cairo_headers) || echo 'cairo_ERROR ()' ) | \ + $(EGREP) -v '^# *include' | \ + ( cat cairo-features.h - | $(CPP) -D__cplusplus - || echo 'cairo_ERROR ()' ) | \ + $(EGREP) '^cairo_.* \(' | \ + sed -e 's/[ ].*//' | \ + sort; \ + echo LIBRARY libcairo-$(CAIRO_VERSION_SONUM).dll; \ + ) >$@ + @ ! grep -q cairo_ERROR $@ || ($(RM) $@; false) + +TESTS_ENVIRONMENT = \ + srcdir="$(srcdir)" \ + MAKE="$(MAKE) $(AM_MAKEFLAGS)" \ + all_cairo_files="$(all_cairo_files)" \ + all_cairo_headers="$(all_cairo_headers)" \ + all_cairo_private="$(all_cairo_private)" \ + all_cairo_sources="$(all_cairo_sources)" \ + enabled_cairo_headers="$(enabled_cairo_headers)" \ + enabled_cairo_private="$(enabled_cairo_private)" \ + enabled_cairo_sources="$(enabled_cairo_sources)" \ + $(NULL) +TESTS_SH = \ + check-def.sh \ + check-doc-syntax.sh \ + check-headers.sh \ + check-plt.sh \ + check-preprocessor-syntax.sh \ + $(NULL) +TESTS += $(TESTS_SH) +if CROSS_COMPILING +else +TESTS += check-link$(EXEEXT) +endif + +EXTRA_DIST += $(TESTS_SH) check-has-hidden-symbols.c check-doc-syntax.awk +check_PROGRAMS += check-link +check_link_LDADD = libcairo.la + +check: headers-standalone + +PREPROCESS_ARGS = $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) +COMPILE_ARGS = $(PREPROCESS_ARGS) $(AM_CFLAGS) $(CFLAGS) + +# The pre-processed result is used by check-{def,plt}.sh to determine whether +# cairo has been compiled with symbol hiding. +.c.i: $(cairoinclude_HEADERS) $(nodist_cairoinclude_HEADERS) cairoint.h $(top_builddir)/config.h + $(CPP) $(PREPROCESS_ARGS) $< -o $@ +.c.s: $(cairoinclude_HEADERS) $(nodist_cairoinclude_HEADERS) cairoint.h $(top_builddir)/config.h + $(CC) $(COMPILE_ARGS) $< -S -o $@ + +include $(srcdir)/Makefile.am.analysis diff --git a/Build/source/libs/cairo/cairo-src/src/Makefile.am.analysis b/Build/source/libs/cairo/cairo-src/src/Makefile.am.analysis new file mode 100644 index 00000000000..fab4cf7a514 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/Makefile.am.analysis @@ -0,0 +1,35 @@ + +SPARSE = sparse +sparse: + @echo Checking enabled sources with sparse checker + @status=true; for f in $(enabled_cairo_sources) $(enabled_cairo_cxx_sources); do \ + echo $(SPARSE) $(PREPROCESS_ARGS) $(srcdir)/$$f; \ + $(SPARSE) $(PREPROCESS_ARGS) $(srcdir)/$$f || status=false; \ + done; $$status + +SPLINT = splint -badflag +splint: + @echo Checking enabled sources with splint checker + @status=true; for f in $(enabled_cairo_sources) $(enabled_cairo_cxx_sources); do \ + echo $(SPLINT) $(PREPROCESS_ARGS) $(srcdir)/$$f; \ + $(SPLINT) $(PREPROCESS_ARGS) $(srcdir)/$$f || status=false; \ + done; $$status + +UNO = uno +uno: + @echo Checking enabled sources with uno checker + cd $(srcdir); $(UNO) $(PREPROCESS_ARGS) -DHAVE_CONFIG_H -U__GNUC__ $(enabled_cairo_sources) + +headers-standalone: $(enabled_cairo_headers) $(enabled_cairo_private) + @echo Checking that enabled public/private headers can be compiled standalone + @status=true; for f in $(enabled_cairo_headers) $(enabled_cairo_private); do \ + echo " CHECK $$f"; \ + echo "#include \"$(srcdir)/$$f\"" > headers-standalone-tmp.c; \ + echo "int main(int argc, char * argv[]) { return 0; }" >> headers-standalone-tmp.c; \ + $(COMPILE) -o headers-standalone-tmp headers-standalone-tmp.c || status=false; \ + $(RM) headers-standalone-tmp headers-standalone-tmp.c; \ + done; $$status + @touch $@ +CLEANFILES += headers-standalone + +analysis: all headers-standalone sparse splint uno diff --git a/Build/source/libs/cairo/cairo-src/src/Makefile.am.features b/Build/source/libs/cairo/cairo-src/src/Makefile.am.features new file mode 100644 index 00000000000..c58ac23da4e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/Makefile.am.features @@ -0,0 +1,657 @@ +# Generated by configure. Do not edit. + +include $(top_srcdir)/src/Makefile.sources + +supported_cairo_headers = $(cairo_headers) +unsupported_cairo_headers = +all_cairo_headers = $(cairo_headers) +all_cairo_private = $(cairo_private) +all_cairo_cxx_sources = $(cairo_cxx_sources) +all_cairo_sources = $(cairo_sources) + +enabled_cairo_headers = $(cairo_headers) +enabled_cairo_private = $(cairo_private) +enabled_cairo_cxx_sources = $(cairo_cxx_sources) +enabled_cairo_sources = $(cairo_sources) + +all_cairo_pkgconf = cairo.pc +enabled_cairo_pkgconf = cairo.pc + +supported_cairo_headers += $(cairo_xlib_headers) +all_cairo_headers += $(cairo_xlib_headers) +all_cairo_private += $(cairo_xlib_private) +all_cairo_cxx_sources += $(cairo_xlib_cxx_sources) +all_cairo_sources += $(cairo_xlib_sources) +if CAIRO_HAS_XLIB_SURFACE +enabled_cairo_headers += $(cairo_xlib_headers) +enabled_cairo_private += $(cairo_xlib_private) +enabled_cairo_cxx_sources += $(cairo_xlib_cxx_sources) +enabled_cairo_sources += $(cairo_xlib_sources) +endif +all_cairo_pkgconf += cairo-xlib.pc +if CAIRO_HAS_XLIB_SURFACE +enabled_cairo_pkgconf += cairo-xlib.pc +endif + +supported_cairo_headers += $(cairo_xlib_xrender_headers) +all_cairo_headers += $(cairo_xlib_xrender_headers) +all_cairo_private += $(cairo_xlib_xrender_private) +all_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) +all_cairo_sources += $(cairo_xlib_xrender_sources) +if CAIRO_HAS_XLIB_XRENDER_SURFACE +enabled_cairo_headers += $(cairo_xlib_xrender_headers) +enabled_cairo_private += $(cairo_xlib_xrender_private) +enabled_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) +enabled_cairo_sources += $(cairo_xlib_xrender_sources) +endif +all_cairo_pkgconf += cairo-xlib-xrender.pc +if CAIRO_HAS_XLIB_XRENDER_SURFACE +enabled_cairo_pkgconf += cairo-xlib-xrender.pc +endif + +supported_cairo_headers += $(cairo_xcb_headers) +all_cairo_headers += $(cairo_xcb_headers) +all_cairo_private += $(cairo_xcb_private) +all_cairo_cxx_sources += $(cairo_xcb_cxx_sources) +all_cairo_sources += $(cairo_xcb_sources) +if CAIRO_HAS_XCB_SURFACE +enabled_cairo_headers += $(cairo_xcb_headers) +enabled_cairo_private += $(cairo_xcb_private) +enabled_cairo_cxx_sources += $(cairo_xcb_cxx_sources) +enabled_cairo_sources += $(cairo_xcb_sources) +endif +all_cairo_pkgconf += cairo-xcb.pc +if CAIRO_HAS_XCB_SURFACE +enabled_cairo_pkgconf += cairo-xcb.pc +endif + +unsupported_cairo_headers += $(cairo_xlib_xcb_headers) +all_cairo_headers += $(cairo_xlib_xcb_headers) +all_cairo_private += $(cairo_xlib_xcb_private) +all_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) +all_cairo_sources += $(cairo_xlib_xcb_sources) +if CAIRO_HAS_XLIB_XCB_FUNCTIONS +enabled_cairo_headers += $(cairo_xlib_xcb_headers) +enabled_cairo_private += $(cairo_xlib_xcb_private) +enabled_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) +enabled_cairo_sources += $(cairo_xlib_xcb_sources) +endif +all_cairo_pkgconf += cairo-xlib-xcb.pc +if CAIRO_HAS_XLIB_XCB_FUNCTIONS +enabled_cairo_pkgconf += cairo-xlib-xcb.pc +endif + +supported_cairo_headers += $(cairo_xcb_shm_headers) +all_cairo_headers += $(cairo_xcb_shm_headers) +all_cairo_private += $(cairo_xcb_shm_private) +all_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) +all_cairo_sources += $(cairo_xcb_shm_sources) +if CAIRO_HAS_XCB_SHM_FUNCTIONS +enabled_cairo_headers += $(cairo_xcb_shm_headers) +enabled_cairo_private += $(cairo_xcb_shm_private) +enabled_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) +enabled_cairo_sources += $(cairo_xcb_shm_sources) +endif +all_cairo_pkgconf += cairo-xcb-shm.pc +if CAIRO_HAS_XCB_SHM_FUNCTIONS +enabled_cairo_pkgconf += cairo-xcb-shm.pc +endif + +unsupported_cairo_headers += $(cairo_qt_headers) +all_cairo_headers += $(cairo_qt_headers) +all_cairo_private += $(cairo_qt_private) +all_cairo_cxx_sources += $(cairo_qt_cxx_sources) +all_cairo_sources += $(cairo_qt_sources) +if CAIRO_HAS_QT_SURFACE +enabled_cairo_headers += $(cairo_qt_headers) +enabled_cairo_private += $(cairo_qt_private) +enabled_cairo_cxx_sources += $(cairo_qt_cxx_sources) +enabled_cairo_sources += $(cairo_qt_sources) +endif +all_cairo_pkgconf += cairo-qt.pc +if CAIRO_HAS_QT_SURFACE +enabled_cairo_pkgconf += cairo-qt.pc +endif + +supported_cairo_headers += $(cairo_quartz_headers) +all_cairo_headers += $(cairo_quartz_headers) +all_cairo_private += $(cairo_quartz_private) +all_cairo_cxx_sources += $(cairo_quartz_cxx_sources) +all_cairo_sources += $(cairo_quartz_sources) +if CAIRO_HAS_QUARTZ_SURFACE +enabled_cairo_headers += $(cairo_quartz_headers) +enabled_cairo_private += $(cairo_quartz_private) +enabled_cairo_cxx_sources += $(cairo_quartz_cxx_sources) +enabled_cairo_sources += $(cairo_quartz_sources) +endif +all_cairo_pkgconf += cairo-quartz.pc +if CAIRO_HAS_QUARTZ_SURFACE +enabled_cairo_pkgconf += cairo-quartz.pc +endif + +supported_cairo_headers += $(cairo_quartz_font_headers) +all_cairo_headers += $(cairo_quartz_font_headers) +all_cairo_private += $(cairo_quartz_font_private) +all_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) +all_cairo_sources += $(cairo_quartz_font_sources) +if CAIRO_HAS_QUARTZ_FONT +enabled_cairo_headers += $(cairo_quartz_font_headers) +enabled_cairo_private += $(cairo_quartz_font_private) +enabled_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) +enabled_cairo_sources += $(cairo_quartz_font_sources) +endif +all_cairo_pkgconf += cairo-quartz-font.pc +if CAIRO_HAS_QUARTZ_FONT +enabled_cairo_pkgconf += cairo-quartz-font.pc +endif + +unsupported_cairo_headers += $(cairo_quartz_image_headers) +all_cairo_headers += $(cairo_quartz_image_headers) +all_cairo_private += $(cairo_quartz_image_private) +all_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) +all_cairo_sources += $(cairo_quartz_image_sources) +if CAIRO_HAS_QUARTZ_IMAGE_SURFACE +enabled_cairo_headers += $(cairo_quartz_image_headers) +enabled_cairo_private += $(cairo_quartz_image_private) +enabled_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) +enabled_cairo_sources += $(cairo_quartz_image_sources) +endif +all_cairo_pkgconf += cairo-quartz-image.pc +if CAIRO_HAS_QUARTZ_IMAGE_SURFACE +enabled_cairo_pkgconf += cairo-quartz-image.pc +endif + +supported_cairo_headers += $(cairo_win32_headers) +all_cairo_headers += $(cairo_win32_headers) +all_cairo_private += $(cairo_win32_private) +all_cairo_cxx_sources += $(cairo_win32_cxx_sources) +all_cairo_sources += $(cairo_win32_sources) +if CAIRO_HAS_WIN32_SURFACE +enabled_cairo_headers += $(cairo_win32_headers) +enabled_cairo_private += $(cairo_win32_private) +enabled_cairo_cxx_sources += $(cairo_win32_cxx_sources) +enabled_cairo_sources += $(cairo_win32_sources) +endif +all_cairo_pkgconf += cairo-win32.pc +if CAIRO_HAS_WIN32_SURFACE +enabled_cairo_pkgconf += cairo-win32.pc +endif + +supported_cairo_headers += $(cairo_win32_font_headers) +all_cairo_headers += $(cairo_win32_font_headers) +all_cairo_private += $(cairo_win32_font_private) +all_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) +all_cairo_sources += $(cairo_win32_font_sources) +if CAIRO_HAS_WIN32_FONT +enabled_cairo_headers += $(cairo_win32_font_headers) +enabled_cairo_private += $(cairo_win32_font_private) +enabled_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) +enabled_cairo_sources += $(cairo_win32_font_sources) +endif +all_cairo_pkgconf += cairo-win32-font.pc +if CAIRO_HAS_WIN32_FONT +enabled_cairo_pkgconf += cairo-win32-font.pc +endif + +unsupported_cairo_headers += $(cairo_skia_headers) +all_cairo_headers += $(cairo_skia_headers) +all_cairo_private += $(cairo_skia_private) +all_cairo_cxx_sources += $(cairo_skia_cxx_sources) +all_cairo_sources += $(cairo_skia_sources) +if CAIRO_HAS_SKIA_SURFACE +enabled_cairo_headers += $(cairo_skia_headers) +enabled_cairo_private += $(cairo_skia_private) +enabled_cairo_cxx_sources += $(cairo_skia_cxx_sources) +enabled_cairo_sources += $(cairo_skia_sources) +endif +all_cairo_pkgconf += cairo-skia.pc +if CAIRO_HAS_SKIA_SURFACE +enabled_cairo_pkgconf += cairo-skia.pc +endif + +unsupported_cairo_headers += $(cairo_os2_headers) +all_cairo_headers += $(cairo_os2_headers) +all_cairo_private += $(cairo_os2_private) +all_cairo_cxx_sources += $(cairo_os2_cxx_sources) +all_cairo_sources += $(cairo_os2_sources) +if CAIRO_HAS_OS2_SURFACE +enabled_cairo_headers += $(cairo_os2_headers) +enabled_cairo_private += $(cairo_os2_private) +enabled_cairo_cxx_sources += $(cairo_os2_cxx_sources) +enabled_cairo_sources += $(cairo_os2_sources) +endif +all_cairo_pkgconf += cairo-os2.pc +if CAIRO_HAS_OS2_SURFACE +enabled_cairo_pkgconf += cairo-os2.pc +endif + +unsupported_cairo_headers += $(cairo_beos_headers) +all_cairo_headers += $(cairo_beos_headers) +all_cairo_private += $(cairo_beos_private) +all_cairo_cxx_sources += $(cairo_beos_cxx_sources) +all_cairo_sources += $(cairo_beos_sources) +if CAIRO_HAS_BEOS_SURFACE +enabled_cairo_headers += $(cairo_beos_headers) +enabled_cairo_private += $(cairo_beos_private) +enabled_cairo_cxx_sources += $(cairo_beos_cxx_sources) +enabled_cairo_sources += $(cairo_beos_sources) +endif +all_cairo_pkgconf += cairo-beos.pc +if CAIRO_HAS_BEOS_SURFACE +enabled_cairo_pkgconf += cairo-beos.pc +endif + +unsupported_cairo_headers += $(cairo_drm_headers) +all_cairo_headers += $(cairo_drm_headers) +all_cairo_private += $(cairo_drm_private) +all_cairo_cxx_sources += $(cairo_drm_cxx_sources) +all_cairo_sources += $(cairo_drm_sources) +if CAIRO_HAS_DRM_SURFACE +enabled_cairo_headers += $(cairo_drm_headers) +enabled_cairo_private += $(cairo_drm_private) +enabled_cairo_cxx_sources += $(cairo_drm_cxx_sources) +enabled_cairo_sources += $(cairo_drm_sources) +endif +all_cairo_pkgconf += cairo-drm.pc +if CAIRO_HAS_DRM_SURFACE +enabled_cairo_pkgconf += cairo-drm.pc +endif + +unsupported_cairo_headers += $(cairo_gallium_headers) +all_cairo_headers += $(cairo_gallium_headers) +all_cairo_private += $(cairo_gallium_private) +all_cairo_cxx_sources += $(cairo_gallium_cxx_sources) +all_cairo_sources += $(cairo_gallium_sources) +if CAIRO_HAS_GALLIUM_SURFACE +enabled_cairo_headers += $(cairo_gallium_headers) +enabled_cairo_private += $(cairo_gallium_private) +enabled_cairo_cxx_sources += $(cairo_gallium_cxx_sources) +enabled_cairo_sources += $(cairo_gallium_sources) +endif +all_cairo_pkgconf += cairo-gallium.pc +if CAIRO_HAS_GALLIUM_SURFACE +enabled_cairo_pkgconf += cairo-gallium.pc +endif + +supported_cairo_headers += $(cairo_png_headers) +all_cairo_headers += $(cairo_png_headers) +all_cairo_private += $(cairo_png_private) +all_cairo_cxx_sources += $(cairo_png_cxx_sources) +all_cairo_sources += $(cairo_png_sources) +if CAIRO_HAS_PNG_FUNCTIONS +enabled_cairo_headers += $(cairo_png_headers) +enabled_cairo_private += $(cairo_png_private) +enabled_cairo_cxx_sources += $(cairo_png_cxx_sources) +enabled_cairo_sources += $(cairo_png_sources) +endif +all_cairo_pkgconf += cairo-png.pc +if CAIRO_HAS_PNG_FUNCTIONS +enabled_cairo_pkgconf += cairo-png.pc +endif + +unsupported_cairo_headers += $(cairo_gl_headers) +all_cairo_headers += $(cairo_gl_headers) +all_cairo_private += $(cairo_gl_private) +all_cairo_cxx_sources += $(cairo_gl_cxx_sources) +all_cairo_sources += $(cairo_gl_sources) +if CAIRO_HAS_GL_SURFACE +enabled_cairo_headers += $(cairo_gl_headers) +enabled_cairo_private += $(cairo_gl_private) +enabled_cairo_cxx_sources += $(cairo_gl_cxx_sources) +enabled_cairo_sources += $(cairo_gl_sources) +endif +all_cairo_pkgconf += cairo-gl.pc +if CAIRO_HAS_GL_SURFACE +enabled_cairo_pkgconf += cairo-gl.pc +endif + +unsupported_cairo_headers += $(cairo_glesv2_headers) +all_cairo_headers += $(cairo_glesv2_headers) +all_cairo_private += $(cairo_glesv2_private) +all_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) +all_cairo_sources += $(cairo_glesv2_sources) +if CAIRO_HAS_GLESV2_SURFACE +enabled_cairo_headers += $(cairo_glesv2_headers) +enabled_cairo_private += $(cairo_glesv2_private) +enabled_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) +enabled_cairo_sources += $(cairo_glesv2_sources) +endif +all_cairo_pkgconf += cairo-glesv2.pc +if CAIRO_HAS_GLESV2_SURFACE +enabled_cairo_pkgconf += cairo-glesv2.pc +endif + +unsupported_cairo_headers += $(cairo_cogl_headers) +all_cairo_headers += $(cairo_cogl_headers) +all_cairo_private += $(cairo_cogl_private) +all_cairo_cxx_sources += $(cairo_cogl_cxx_sources) +all_cairo_sources += $(cairo_cogl_sources) +if CAIRO_HAS_COGL_SURFACE +enabled_cairo_headers += $(cairo_cogl_headers) +enabled_cairo_private += $(cairo_cogl_private) +enabled_cairo_cxx_sources += $(cairo_cogl_cxx_sources) +enabled_cairo_sources += $(cairo_cogl_sources) +endif +all_cairo_pkgconf += cairo-cogl.pc +if CAIRO_HAS_COGL_SURFACE +enabled_cairo_pkgconf += cairo-cogl.pc +endif + +unsupported_cairo_headers += $(cairo_directfb_headers) +all_cairo_headers += $(cairo_directfb_headers) +all_cairo_private += $(cairo_directfb_private) +all_cairo_cxx_sources += $(cairo_directfb_cxx_sources) +all_cairo_sources += $(cairo_directfb_sources) +if CAIRO_HAS_DIRECTFB_SURFACE +enabled_cairo_headers += $(cairo_directfb_headers) +enabled_cairo_private += $(cairo_directfb_private) +enabled_cairo_cxx_sources += $(cairo_directfb_cxx_sources) +enabled_cairo_sources += $(cairo_directfb_sources) +endif +all_cairo_pkgconf += cairo-directfb.pc +if CAIRO_HAS_DIRECTFB_SURFACE +enabled_cairo_pkgconf += cairo-directfb.pc +endif + +unsupported_cairo_headers += $(cairo_vg_headers) +all_cairo_headers += $(cairo_vg_headers) +all_cairo_private += $(cairo_vg_private) +all_cairo_cxx_sources += $(cairo_vg_cxx_sources) +all_cairo_sources += $(cairo_vg_sources) +if CAIRO_HAS_VG_SURFACE +enabled_cairo_headers += $(cairo_vg_headers) +enabled_cairo_private += $(cairo_vg_private) +enabled_cairo_cxx_sources += $(cairo_vg_cxx_sources) +enabled_cairo_sources += $(cairo_vg_sources) +endif +all_cairo_pkgconf += cairo-vg.pc +if CAIRO_HAS_VG_SURFACE +enabled_cairo_pkgconf += cairo-vg.pc +endif + +supported_cairo_headers += $(cairo_egl_headers) +all_cairo_headers += $(cairo_egl_headers) +all_cairo_private += $(cairo_egl_private) +all_cairo_cxx_sources += $(cairo_egl_cxx_sources) +all_cairo_sources += $(cairo_egl_sources) +if CAIRO_HAS_EGL_FUNCTIONS +enabled_cairo_headers += $(cairo_egl_headers) +enabled_cairo_private += $(cairo_egl_private) +enabled_cairo_cxx_sources += $(cairo_egl_cxx_sources) +enabled_cairo_sources += $(cairo_egl_sources) +endif +all_cairo_pkgconf += cairo-egl.pc +if CAIRO_HAS_EGL_FUNCTIONS +enabled_cairo_pkgconf += cairo-egl.pc +endif + +supported_cairo_headers += $(cairo_glx_headers) +all_cairo_headers += $(cairo_glx_headers) +all_cairo_private += $(cairo_glx_private) +all_cairo_cxx_sources += $(cairo_glx_cxx_sources) +all_cairo_sources += $(cairo_glx_sources) +if CAIRO_HAS_GLX_FUNCTIONS +enabled_cairo_headers += $(cairo_glx_headers) +enabled_cairo_private += $(cairo_glx_private) +enabled_cairo_cxx_sources += $(cairo_glx_cxx_sources) +enabled_cairo_sources += $(cairo_glx_sources) +endif +all_cairo_pkgconf += cairo-glx.pc +if CAIRO_HAS_GLX_FUNCTIONS +enabled_cairo_pkgconf += cairo-glx.pc +endif + +supported_cairo_headers += $(cairo_wgl_headers) +all_cairo_headers += $(cairo_wgl_headers) +all_cairo_private += $(cairo_wgl_private) +all_cairo_cxx_sources += $(cairo_wgl_cxx_sources) +all_cairo_sources += $(cairo_wgl_sources) +if CAIRO_HAS_WGL_FUNCTIONS +enabled_cairo_headers += $(cairo_wgl_headers) +enabled_cairo_private += $(cairo_wgl_private) +enabled_cairo_cxx_sources += $(cairo_wgl_cxx_sources) +enabled_cairo_sources += $(cairo_wgl_sources) +endif +all_cairo_pkgconf += cairo-wgl.pc +if CAIRO_HAS_WGL_FUNCTIONS +enabled_cairo_pkgconf += cairo-wgl.pc +endif + +supported_cairo_headers += $(cairo_script_headers) +all_cairo_headers += $(cairo_script_headers) +all_cairo_private += $(cairo_script_private) +all_cairo_cxx_sources += $(cairo_script_cxx_sources) +all_cairo_sources += $(cairo_script_sources) +if CAIRO_HAS_SCRIPT_SURFACE +enabled_cairo_headers += $(cairo_script_headers) +enabled_cairo_private += $(cairo_script_private) +enabled_cairo_cxx_sources += $(cairo_script_cxx_sources) +enabled_cairo_sources += $(cairo_script_sources) +endif +all_cairo_pkgconf += cairo-script.pc +if CAIRO_HAS_SCRIPT_SURFACE +enabled_cairo_pkgconf += cairo-script.pc +endif + +supported_cairo_headers += $(cairo_ft_headers) +all_cairo_headers += $(cairo_ft_headers) +all_cairo_private += $(cairo_ft_private) +all_cairo_cxx_sources += $(cairo_ft_cxx_sources) +all_cairo_sources += $(cairo_ft_sources) +if CAIRO_HAS_FT_FONT +enabled_cairo_headers += $(cairo_ft_headers) +enabled_cairo_private += $(cairo_ft_private) +enabled_cairo_cxx_sources += $(cairo_ft_cxx_sources) +enabled_cairo_sources += $(cairo_ft_sources) +endif +all_cairo_pkgconf += cairo-ft.pc +if CAIRO_HAS_FT_FONT +enabled_cairo_pkgconf += cairo-ft.pc +endif + +supported_cairo_headers += $(cairo_fc_headers) +all_cairo_headers += $(cairo_fc_headers) +all_cairo_private += $(cairo_fc_private) +all_cairo_cxx_sources += $(cairo_fc_cxx_sources) +all_cairo_sources += $(cairo_fc_sources) +if CAIRO_HAS_FC_FONT +enabled_cairo_headers += $(cairo_fc_headers) +enabled_cairo_private += $(cairo_fc_private) +enabled_cairo_cxx_sources += $(cairo_fc_cxx_sources) +enabled_cairo_sources += $(cairo_fc_sources) +endif +all_cairo_pkgconf += cairo-fc.pc +if CAIRO_HAS_FC_FONT +enabled_cairo_pkgconf += cairo-fc.pc +endif + +supported_cairo_headers += $(cairo_ps_headers) +all_cairo_headers += $(cairo_ps_headers) +all_cairo_private += $(cairo_ps_private) +all_cairo_cxx_sources += $(cairo_ps_cxx_sources) +all_cairo_sources += $(cairo_ps_sources) +if CAIRO_HAS_PS_SURFACE +enabled_cairo_headers += $(cairo_ps_headers) +enabled_cairo_private += $(cairo_ps_private) +enabled_cairo_cxx_sources += $(cairo_ps_cxx_sources) +enabled_cairo_sources += $(cairo_ps_sources) +endif +all_cairo_pkgconf += cairo-ps.pc +if CAIRO_HAS_PS_SURFACE +enabled_cairo_pkgconf += cairo-ps.pc +endif + +supported_cairo_headers += $(cairo_pdf_headers) +all_cairo_headers += $(cairo_pdf_headers) +all_cairo_private += $(cairo_pdf_private) +all_cairo_cxx_sources += $(cairo_pdf_cxx_sources) +all_cairo_sources += $(cairo_pdf_sources) +if CAIRO_HAS_PDF_SURFACE +enabled_cairo_headers += $(cairo_pdf_headers) +enabled_cairo_private += $(cairo_pdf_private) +enabled_cairo_cxx_sources += $(cairo_pdf_cxx_sources) +enabled_cairo_sources += $(cairo_pdf_sources) +endif +all_cairo_pkgconf += cairo-pdf.pc +if CAIRO_HAS_PDF_SURFACE +enabled_cairo_pkgconf += cairo-pdf.pc +endif + +supported_cairo_headers += $(cairo_svg_headers) +all_cairo_headers += $(cairo_svg_headers) +all_cairo_private += $(cairo_svg_private) +all_cairo_cxx_sources += $(cairo_svg_cxx_sources) +all_cairo_sources += $(cairo_svg_sources) +if CAIRO_HAS_SVG_SURFACE +enabled_cairo_headers += $(cairo_svg_headers) +enabled_cairo_private += $(cairo_svg_private) +enabled_cairo_cxx_sources += $(cairo_svg_cxx_sources) +enabled_cairo_sources += $(cairo_svg_sources) +endif +all_cairo_pkgconf += cairo-svg.pc +if CAIRO_HAS_SVG_SURFACE +enabled_cairo_pkgconf += cairo-svg.pc +endif + +all_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) +all_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) +all_cairo_sources += $(cairo_test_surfaces_sources) +if CAIRO_HAS_TEST_SURFACES +enabled_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) +enabled_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) +enabled_cairo_sources += $(cairo_test_surfaces_sources) +endif + +supported_cairo_headers += $(cairo_image_headers) +all_cairo_headers += $(cairo_image_headers) +all_cairo_private += $(cairo_image_private) +all_cairo_cxx_sources += $(cairo_image_cxx_sources) +all_cairo_sources += $(cairo_image_sources) +enabled_cairo_headers += $(cairo_image_headers) +enabled_cairo_private += $(cairo_image_private) +enabled_cairo_cxx_sources += $(cairo_image_cxx_sources) +enabled_cairo_sources += $(cairo_image_sources) + +supported_cairo_headers += $(cairo_mime_headers) +all_cairo_headers += $(cairo_mime_headers) +all_cairo_private += $(cairo_mime_private) +all_cairo_cxx_sources += $(cairo_mime_cxx_sources) +all_cairo_sources += $(cairo_mime_sources) +enabled_cairo_headers += $(cairo_mime_headers) +enabled_cairo_private += $(cairo_mime_private) +enabled_cairo_cxx_sources += $(cairo_mime_cxx_sources) +enabled_cairo_sources += $(cairo_mime_sources) + +supported_cairo_headers += $(cairo_recording_headers) +all_cairo_headers += $(cairo_recording_headers) +all_cairo_private += $(cairo_recording_private) +all_cairo_cxx_sources += $(cairo_recording_cxx_sources) +all_cairo_sources += $(cairo_recording_sources) +enabled_cairo_headers += $(cairo_recording_headers) +enabled_cairo_private += $(cairo_recording_private) +enabled_cairo_cxx_sources += $(cairo_recording_cxx_sources) +enabled_cairo_sources += $(cairo_recording_sources) + +supported_cairo_headers += $(cairo_observer_headers) +all_cairo_headers += $(cairo_observer_headers) +all_cairo_private += $(cairo_observer_private) +all_cairo_cxx_sources += $(cairo_observer_cxx_sources) +all_cairo_sources += $(cairo_observer_sources) +enabled_cairo_headers += $(cairo_observer_headers) +enabled_cairo_private += $(cairo_observer_private) +enabled_cairo_cxx_sources += $(cairo_observer_cxx_sources) +enabled_cairo_sources += $(cairo_observer_sources) + +unsupported_cairo_headers += $(cairo_tee_headers) +all_cairo_headers += $(cairo_tee_headers) +all_cairo_private += $(cairo_tee_private) +all_cairo_cxx_sources += $(cairo_tee_cxx_sources) +all_cairo_sources += $(cairo_tee_sources) +if CAIRO_HAS_TEE_SURFACE +enabled_cairo_headers += $(cairo_tee_headers) +enabled_cairo_private += $(cairo_tee_private) +enabled_cairo_cxx_sources += $(cairo_tee_cxx_sources) +enabled_cairo_sources += $(cairo_tee_sources) +endif +all_cairo_pkgconf += cairo-tee.pc +if CAIRO_HAS_TEE_SURFACE +enabled_cairo_pkgconf += cairo-tee.pc +endif + +unsupported_cairo_headers += $(cairo_xml_headers) +all_cairo_headers += $(cairo_xml_headers) +all_cairo_private += $(cairo_xml_private) +all_cairo_cxx_sources += $(cairo_xml_cxx_sources) +all_cairo_sources += $(cairo_xml_sources) +if CAIRO_HAS_XML_SURFACE +enabled_cairo_headers += $(cairo_xml_headers) +enabled_cairo_private += $(cairo_xml_private) +enabled_cairo_cxx_sources += $(cairo_xml_cxx_sources) +enabled_cairo_sources += $(cairo_xml_sources) +endif +all_cairo_pkgconf += cairo-xml.pc +if CAIRO_HAS_XML_SURFACE +enabled_cairo_pkgconf += cairo-xml.pc +endif + +supported_cairo_headers += $(cairo_user_headers) +all_cairo_headers += $(cairo_user_headers) +all_cairo_private += $(cairo_user_private) +all_cairo_cxx_sources += $(cairo_user_cxx_sources) +all_cairo_sources += $(cairo_user_sources) +enabled_cairo_headers += $(cairo_user_headers) +enabled_cairo_private += $(cairo_user_private) +enabled_cairo_cxx_sources += $(cairo_user_cxx_sources) +enabled_cairo_sources += $(cairo_user_sources) + +all_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) +all_cairo_cxx_sources += $(cairo_pthread_cxx_sources) +all_cairo_sources += $(cairo_pthread_sources) +if CAIRO_HAS_PTHREAD +enabled_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) +enabled_cairo_cxx_sources += $(cairo_pthread_cxx_sources) +enabled_cairo_sources += $(cairo_pthread_sources) +endif + +supported_cairo_headers += $(cairo_gobject_headers) +all_cairo_headers += $(cairo_gobject_headers) +all_cairo_private += $(cairo_gobject_private) +all_cairo_cxx_sources += $(cairo_gobject_cxx_sources) +all_cairo_sources += $(cairo_gobject_sources) +if CAIRO_HAS_GOBJECT_FUNCTIONS +enabled_cairo_headers += $(cairo_gobject_headers) +enabled_cairo_private += $(cairo_gobject_private) +enabled_cairo_cxx_sources += $(cairo_gobject_cxx_sources) +enabled_cairo_sources += $(cairo_gobject_sources) +endif +all_cairo_pkgconf += cairo-gobject.pc +if CAIRO_HAS_GOBJECT_FUNCTIONS +enabled_cairo_pkgconf += cairo-gobject.pc +endif + +all_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) +all_cairo_cxx_sources += $(cairo_trace_cxx_sources) +all_cairo_sources += $(cairo_trace_sources) +if CAIRO_HAS_TRACE +enabled_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) +enabled_cairo_cxx_sources += $(cairo_trace_cxx_sources) +enabled_cairo_sources += $(cairo_trace_sources) +endif + +all_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) +all_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) +all_cairo_sources += $(cairo_interpreter_sources) +if CAIRO_HAS_INTERPRETER +enabled_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) +enabled_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) +enabled_cairo_sources += $(cairo_interpreter_sources) +endif + +all_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) +all_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) +all_cairo_sources += $(cairo_symbol_lookup_sources) +if CAIRO_HAS_SYMBOL_LOOKUP +enabled_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) +enabled_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) +enabled_cairo_sources += $(cairo_symbol_lookup_sources) +endif diff --git a/Build/source/libs/cairo/cairo-src/src/Makefile.sources b/Build/source/libs/cairo/cairo-src/src/Makefile.sources new file mode 100644 index 00000000000..fac24d79d8a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/Makefile.sources @@ -0,0 +1,472 @@ +# Makefile.sources +# +# This file is the canonical location listing all the source files used +# to build the cairo library. Every source file is categorized as one of: +# +# * public header file +# * private header file (must end in -private.h except for cairoint.h) +# * source code file +# +# Every source file should be specified exactly once, grouped with the +# feature that uses the source file. If more than one feature use the +# file (like pdf_operators or font_subset files), the files should be +# appended to to the base cairo files, and the code inside them +# enabled/disabled using C preprocessor macros defined in cairoint.h. +# See how pdf_operators or font_subset are handled. +# +# The sources are picked up according to the configured features +# by the generated file Makefile.am.features or Makefile.win32.features. +# +# These are a few special source files. Those are not included in this +# file to not confuse build systems. Each build system must handle them +# separately. These files include: +# +# * cairo-features.h: +# This file is generated by configure and includes macros signifying +# which features are enabled. This file should be installed like +# other public headers, but should NOT be distributed in the cairo +# distribution. +# +# * cairo-version.h: +# This is a dummy header file used during the build, but it should +# NOT be installed. Its sole purpose is to make sure changes in the +# cairo version do not trigger a full rebuild of the library, but +# just the functions actually using the version information. +# +# * $(top_srcdir)/cairo-version.h: +# This is the real file holding the cairo version number. This file +# should be installed like other public headers. This is used during +# the build by cairo-version.c only. +# +# * cairo-supported-features.h: +# This file is generated by configure and includes macros signifying +# all supported features. This is used by gtk-doc to generate +# documentation for all those macros, enabled or not. +# This file is NOT used during the build of the library and should +# NOT be installed or distributed. +# +# Please follow the strict syntax of this file, including keeping file +# lists sorted. +# + +cairo_headers = cairo.h cairo-deprecated.h +cairo_private = \ + cairoint.h \ + cairo-analysis-surface-private.h \ + cairo-arc-private.h \ + cairo-array-private.h \ + cairo-atomic-private.h \ + cairo-backend-private.h \ + cairo-box-inline.h \ + cairo-boxes-private.h \ + cairo-cache-private.h \ + cairo-clip-inline.h \ + cairo-clip-private.h \ + cairo-combsort-inline.h \ + cairo-compiler-private.h \ + cairo-compositor-private.h \ + cairo-contour-inline.h \ + cairo-contour-private.h \ + cairo-composite-rectangles-private.h \ + cairo-damage-private.h \ + cairo-default-context-private.h \ + cairo-device-private.h \ + cairo-error-inline.h \ + cairo-error-private.h \ + cairo-fixed-private.h \ + cairo-fixed-type-private.h \ + cairo-freelist-private.h \ + cairo-freelist-type-private.h \ + cairo-freed-pool-private.h \ + cairo-fontconfig-private.h \ + cairo-gstate-private.h \ + cairo-hash-private.h \ + cairo-image-info-private.h \ + cairo-image-surface-inline.h \ + cairo-image-surface-private.h \ + cairo-line-inline.h \ + cairo-line-private.h \ + cairo-list-inline.h \ + cairo-list-private.h \ + cairo-malloc-private.h \ + cairo-mempool-private.h \ + cairo-mutex-impl-private.h \ + cairo-mutex-list-private.h \ + cairo-mutex-private.h \ + cairo-mutex-type-private.h \ + cairo-output-stream-private.h \ + cairo-paginated-private.h \ + cairo-paginated-surface-private.h \ + cairo-path-fixed-private.h \ + cairo-path-private.h \ + cairo-pattern-inline.h \ + cairo-pattern-private.h \ + cairo-pixman-private.h \ + cairo-private.h \ + cairo-recording-surface-inline.h \ + cairo-recording-surface-private.h \ + cairo-reference-count-private.h \ + cairo-region-private.h \ + cairo-rtree-private.h \ + cairo-scaled-font-private.h \ + cairo-slope-private.h \ + cairo-spans-private.h \ + cairo-spans-compositor-private.h \ + cairo-stroke-dash-private.h \ + cairo-surface-inline.h \ + cairo-surface-private.h \ + cairo-surface-backend-private.h \ + cairo-surface-clipper-private.h \ + cairo-surface-fallback-private.h \ + cairo-surface-observer-inline.h \ + cairo-surface-observer-private.h \ + cairo-surface-offset-private.h \ + cairo-surface-subsurface-inline.h \ + cairo-surface-subsurface-private.h \ + cairo-surface-snapshot-inline.h \ + cairo-surface-snapshot-private.h \ + cairo-surface-wrapper-private.h \ + cairo-time-private.h \ + cairo-types-private.h \ + cairo-traps-private.h \ + cairo-tristrip-private.h \ + cairo-user-font-private.h \ + cairo-wideint-private.h \ + cairo-wideint-type-private.h \ + $(NULL) +cairo_sources = \ + cairo-analysis-surface.c \ + cairo-arc.c \ + cairo-array.c \ + cairo-atomic.c \ + cairo-base64-stream.c \ + cairo-base85-stream.c \ + cairo-bentley-ottmann.c \ + cairo-bentley-ottmann-rectangular.c \ + cairo-bentley-ottmann-rectilinear.c \ + cairo-botor-scan-converter.c \ + cairo-boxes.c \ + cairo-boxes-intersect.c \ + cairo.c \ + cairo-cache.c \ + cairo-clip.c \ + cairo-clip-boxes.c \ + cairo-clip-polygon.c \ + cairo-clip-region.c \ + cairo-clip-surface.c \ + cairo-color.c \ + cairo-composite-rectangles.c \ + cairo-compositor.c \ + cairo-contour.c \ + cairo-damage.c \ + cairo-debug.c \ + cairo-default-context.c \ + cairo-device.c \ + cairo-error.c \ + cairo-fallback-compositor.c \ + cairo-fixed.c \ + cairo-font-face.c \ + cairo-font-face-twin.c \ + cairo-font-face-twin-data.c \ + cairo-font-options.c \ + cairo-freelist.c \ + cairo-freed-pool.c \ + cairo-gstate.c \ + cairo-hash.c \ + cairo-hull.c \ + cairo-image-compositor.c \ + cairo-image-info.c \ + cairo-image-source.c \ + cairo-image-surface.c \ + cairo-line.c \ + cairo-lzw.c \ + cairo-matrix.c \ + cairo-mask-compositor.c \ + cairo-mesh-pattern-rasterizer.c \ + cairo-mempool.c \ + cairo-misc.c \ + cairo-mono-scan-converter.c \ + cairo-mutex.c \ + cairo-no-compositor.c \ + cairo-observer.c \ + cairo-output-stream.c \ + cairo-paginated-surface.c \ + cairo-path-bounds.c \ + cairo-path.c \ + cairo-path-fill.c \ + cairo-path-fixed.c \ + cairo-path-in-fill.c \ + cairo-path-stroke.c \ + cairo-path-stroke-boxes.c \ + cairo-path-stroke-polygon.c \ + cairo-path-stroke-traps.c \ + cairo-path-stroke-tristrip.c \ + cairo-pattern.c \ + cairo-pen.c \ + cairo-polygon.c \ + cairo-polygon-intersect.c \ + cairo-polygon-reduce.c \ + cairo-raster-source-pattern.c \ + cairo-recording-surface.c \ + cairo-rectangle.c \ + cairo-rectangular-scan-converter.c \ + cairo-region.c \ + cairo-rtree.c \ + cairo-scaled-font.c \ + cairo-shape-mask-compositor.c \ + cairo-slope.c \ + cairo-spans.c \ + cairo-spans-compositor.c \ + cairo-spline.c \ + cairo-stroke-dash.c \ + cairo-stroke-style.c \ + cairo-surface.c \ + cairo-surface-clipper.c \ + cairo-surface-fallback.c \ + cairo-surface-observer.c \ + cairo-surface-offset.c \ + cairo-surface-snapshot.c \ + cairo-surface-subsurface.c \ + cairo-surface-wrapper.c \ + cairo-time.c \ + cairo-tor-scan-converter.c \ + cairo-tor22-scan-converter.c \ + cairo-clip-tor-scan-converter.c \ + cairo-toy-font-face.c \ + cairo-traps.c \ + cairo-tristrip.c \ + cairo-traps-compositor.c \ + cairo-unicode.c \ + cairo-user-font.c \ + cairo-version.c \ + cairo-wideint.c \ + $(NULL) + +_cairo_font_subset_private = \ + cairo-scaled-font-subsets-private.h \ + cairo-truetype-subset-private.h \ + cairo-type1-private.h \ + cairo-type3-glyph-surface-private.h \ + $(NULL) +_cairo_font_subset_sources = \ + cairo-cff-subset.c \ + cairo-scaled-font-subsets.c \ + cairo-truetype-subset.c \ + cairo-type1-fallback.c \ + cairo-type1-glyph-names.c \ + cairo-type1-subset.c \ + cairo-type3-glyph-surface.c \ + $(NULL) +cairo_private += $(_cairo_font_subset_private) +cairo_sources += $(_cairo_font_subset_sources) + +cairo_egl_sources = +cairo_glx_sources = +cairo_wgl_sources = + +_cairo_pdf_operators_private = cairo-pdf-operators-private.h cairo-pdf-shading-private.h +_cairo_pdf_operators_sources = cairo-pdf-operators.c cairo-pdf-shading.c +cairo_private += $(_cairo_pdf_operators_private) +cairo_sources += $(_cairo_pdf_operators_sources) + +cairo_png_sources = cairo-png.c + +cairo_ps_headers = cairo-ps.h +cairo_ps_private = cairo-ps-surface-private.h +cairo_ps_sources = cairo-ps-surface.c + +_cairo_deflate_stream_sources = cairo-deflate-stream.c +cairo_sources += $(_cairo_deflate_stream_sources) + +cairo_pdf_headers = cairo-pdf.h +cairo_pdf_private = cairo-pdf-surface-private.h +cairo_pdf_sources = cairo-pdf-surface.c + +cairo_svg_headers = cairo-svg.h +cairo_svg_private = cairo-svg-surface-private.h +cairo_svg_sources = cairo-svg-surface.c + +cairo_ft_headers = cairo-ft.h +cairo_ft_private = cairo-ft-private.h +cairo_ft_sources = cairo-ft-font.c + +# These are private, even though they look like public headers +cairo_test_surfaces_private = \ + test-compositor-surface.h \ + test-compositor-surface-private.h \ + test-null-compositor-surface.h \ + test-paginated-surface.h \ + $(NULL) +cairo_test_surfaces_sources = \ + test-compositor-surface.c \ + test-null-compositor-surface.c \ + test-base-compositor-surface.c \ + test-paginated-surface.c \ + $(NULL) + +cairo_xlib_headers = cairo-xlib.h +cairo_xlib_private = \ + cairo-xlib-private.h \ + cairo-xlib-surface-private.h \ + cairo-xlib-xrender-private.h \ + $(NULL) +cairo_xlib_sources = \ + cairo-xlib-display.c \ + cairo-xlib-core-compositor.c \ + cairo-xlib-fallback-compositor.c \ + cairo-xlib-render-compositor.c \ + cairo-xlib-screen.c \ + cairo-xlib-source.c \ + cairo-xlib-surface.c \ + cairo-xlib-surface-shm.c \ + cairo-xlib-visual.c \ + cairo-xlib-xcb-surface.c \ + $(NULL) + +cairo_xlib_xrender_headers = cairo-xlib-xrender.h + +cairo_xcb_headers = cairo-xcb.h +cairo_xcb_private = cairo-xcb-private.h +cairo_xcb_sources = \ + cairo-xcb-connection.c \ + cairo-xcb-connection-core.c \ + cairo-xcb-connection-render.c \ + cairo-xcb-connection-shm.c \ + cairo-xcb-screen.c \ + cairo-xcb-shm.c \ + cairo-xcb-surface.c \ + cairo-xcb-surface-core.c \ + cairo-xcb-surface-render.c \ + cairo-xcb-resources.c \ + $(NULL) + +cairo_qt_headers = cairo-qt.h +cairo_qt_cxx_sources = cairo-qt-surface.cpp + +cairo_quartz_headers = cairo-quartz.h +cairo_quartz_private = cairo-quartz-private.h +cairo_quartz_sources = cairo-quartz-surface.c + +cairo_quartz_image_headers = cairo-quartz-image.h +cairo_quartz_image_sources = cairo-quartz-image-surface.c + +cairo_quartz_font_sources = cairo-quartz-font.c + +cairo_win32_headers = cairo-win32.h +cairo_win32_private = win32/cairo-win32-private.h +cairo_win32_sources = \ + win32/cairo-win32-debug.c \ + win32/cairo-win32-device.c \ + win32/cairo-win32-gdi-compositor.c \ + win32/cairo-win32-system.c \ + win32/cairo-win32-surface.c \ + win32/cairo-win32-display-surface.c \ + win32/cairo-win32-printing-surface.c \ + $(NULL) +cairo_win32_font_sources = \ + win32/cairo-win32-font.c \ + $(NULL) + +cairo_skia_headers = cairo-skia.h +cairo_skia_private = skia/cairo-skia-private.h +cairo_skia_cxx_sources = \ + skia/cairo-skia-context.cpp \ + skia/cairo-skia-surface.cpp \ + $(NULL) + +cairo_os2_headers = cairo-os2.h +cairo_os2_private = cairo-os2-private.h +cairo_os2_sources = cairo-os2-surface.c + +# automake is stupid enough to always use c++ linker if we enable the +# following lines, even if beos surface is not enabled. Disable it for now. +cairo_beos_headers = cairo-beos.h +cairo_beos_cxx_sources = cairo-beos-surface.cpp + +cairo_gl_headers = cairo-gl.h +cairo_gl_private = cairo-gl-private.h \ + cairo-gl-dispatch-private.h \ + cairo-gl-ext-def-private.h \ + cairo-gl-gradient-private.h + +cairo_gl_sources = cairo-gl-composite.c \ + cairo-gl-device.c \ + cairo-gl-dispatch.c \ + cairo-gl-glyphs.c \ + cairo-gl-gradient.c \ + cairo-gl-info.c \ + cairo-gl-operand.c \ + cairo-gl-shaders.c \ + cairo-gl-msaa-compositor.c \ + cairo-gl-spans-compositor.c \ + cairo-gl-traps-compositor.c \ + cairo-gl-source.c \ + cairo-gl-surface.c + +cairo_glesv2_headers = $(cairo_gl_headers) +cairo_glesv2_private = $(cairo_gl_private) +cairo_glesv2_sources = $(cairo_gl_sources) + +cairo_egl_sources += cairo-egl-context.c +cairo_glx_sources += cairo-glx-context.c +cairo_wgl_sources += cairo-wgl-context.c + +cairo_directfb_headers = cairo-directfb.h +cairo_directfb_sources = cairo-directfb-surface.c + +cairo_drm_headers = cairo-drm.h +cairo_drm_private = drm/cairo-drm-private.h \ + drm/cairo-drm-ioctl-private.h \ + drm/cairo-drm-intel-private.h \ + drm/cairo-drm-intel-brw-defines.h \ + drm/cairo-drm-intel-brw-structs.h \ + drm/cairo-drm-intel-brw-eu.h \ + drm/cairo-drm-intel-command-private.h \ + drm/cairo-drm-intel-ioctl-private.h \ + drm/cairo-drm-i915-private.h \ + drm/cairo-drm-i965-private.h \ + drm/cairo-drm-radeon-private.h +cairo_drm_sources = drm/cairo-drm.c \ + drm/cairo-drm-bo.c \ + drm/cairo-drm-surface.c \ + drm/cairo-drm-intel.c \ + drm/cairo-drm-intel-debug.c \ + drm/cairo-drm-intel-surface.c \ + drm/cairo-drm-i915-surface.c \ + drm/cairo-drm-i915-glyphs.c \ + drm/cairo-drm-i915-shader.c \ + drm/cairo-drm-i915-spans.c \ + drm/cairo-drm-i965-surface.c \ + drm/cairo-drm-i965-glyphs.c \ + drm/cairo-drm-i965-shader.c \ + drm/cairo-drm-i965-spans.c \ + drm/cairo-drm-intel-brw-eu.c \ + drm/cairo-drm-intel-brw-eu-emit.c \ + drm/cairo-drm-intel-brw-eu-util.c \ + drm/cairo-drm-radeon.c \ + drm/cairo-drm-radeon-surface.c +cairo_gallium_sources = drm/cairo-drm-gallium-surface.c + +cairo_script_headers = cairo-script.h +cairo_script_private = cairo-script-private.h +cairo_script_sources = cairo-script-surface.c + +cairo_tee_headers = cairo-tee.h +cairo_tee_private = cairo-tee-surface-private.h +cairo_tee_sources = cairo-tee-surface.c + +cairo_xml_headers = cairo-xml.h +cairo_xml_sources = cairo-xml-surface.c + +cairo_vg_headers = cairo-vg.h +cairo_vg_sources = cairo-vg-surface.c + +cairo_cogl_headers = cairo-cogl.h +cairo_cogl_private = cairo-cogl-private.h \ + cairo-cogl-gradient-private.h \ + cairo-cogl-context-private.h \ + cairo-cogl-utils-private.h +cairo_cogl_sources = cairo-cogl-surface.c \ + cairo-cogl-gradient.c \ + cairo-cogl-context.c \ + cairo-cogl-utils.c diff --git a/Build/source/libs/cairo/cairo-src/src/Makefile.win32 b/Build/source/libs/cairo/cairo-src/src/Makefile.win32 new file mode 100644 index 00000000000..864791f377b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/Makefile.win32 @@ -0,0 +1,29 @@ +top_srcdir = .. +include $(top_srcdir)/build/Makefile.win32.common +include Makefile.win32.features + +SOURCES = $(enabled_cairo_sources) + +STATIC_SOURCES = cairo-system.c + +OBJECTS = $(patsubst %.c, $(CFG)/%.obj, $(SOURCES)) +OBJECTS_STATIC = $(patsubst %cairo-system.obj, %cairo-system-static.obj, $(OBJECTS)) + +static: inform $(CFG)/cairo-static.lib +dynamic: inform $(CFG)/cairo.dll + +$(CFG)/cairo.dll: $(OBJECTS) + @$(LD) $(CAIRO_LDFLAGS) -DLL -OUT:$@ $(CAIRO_LIBS) $(PIXMAN_LIBS) $(OBJECTS) + +$(CFG)/cairo-static.lib: $(OBJECTS_STATIC) + @$(AR) $(CAIRO_ARFLAGS) -OUT:$@ $(PIXMAN_LIBS) $(OBJECTS_STATIC) + +all: inform $(CFG)/cairo.dll $(CFG)/cairo-static.lib + @echo "Built successfully!" + @echo "You should copy the following files to a proper place now:" + @echo "" + @echo " cairo-version.h (NOTE: toplevel, not the src/cairo-version.h one!)" + @echo " src/cairo-features.h" + @for x in $(enabled_cairo_headers); do echo " src/$$x"; done + @echo " src/$(CFG)/cairo.dll" + @echo " src/$(CFG)/cairo-static.lib" diff --git a/Build/source/libs/cairo/cairo-src/src/Makefile.win32.features b/Build/source/libs/cairo/cairo-src/src/Makefile.win32.features new file mode 100644 index 00000000000..2274f4ad6cf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/Makefile.win32.features @@ -0,0 +1,661 @@ +# Generated by configure. Do not edit. + +ifeq ($(top_srcdir),) +include Makefile.sources +else +include $(top_srcdir)/src/Makefile.sources +endif + +supported_cairo_headers = $(cairo_headers) +unsupported_cairo_headers = +all_cairo_headers = $(cairo_headers) +all_cairo_private = $(cairo_private) +all_cairo_cxx_sources = $(cairo_cxx_sources) +all_cairo_sources = $(cairo_sources) + +enabled_cairo_headers = $(cairo_headers) +enabled_cairo_private = $(cairo_private) +enabled_cairo_cxx_sources = $(cairo_cxx_sources) +enabled_cairo_sources = $(cairo_sources) + +all_cairo_pkgconf = cairo.pc +enabled_cairo_pkgconf = cairo.pc + +supported_cairo_headers += $(cairo_xlib_headers) +all_cairo_headers += $(cairo_xlib_headers) +all_cairo_private += $(cairo_xlib_private) +all_cairo_cxx_sources += $(cairo_xlib_cxx_sources) +all_cairo_sources += $(cairo_xlib_sources) +ifeq ($(CAIRO_HAS_XLIB_SURFACE),1) +enabled_cairo_headers += $(cairo_xlib_headers) +enabled_cairo_private += $(cairo_xlib_private) +enabled_cairo_cxx_sources += $(cairo_xlib_cxx_sources) +enabled_cairo_sources += $(cairo_xlib_sources) +endif +all_cairo_pkgconf += cairo-xlib.pc +ifeq ($(CAIRO_HAS_XLIB_SURFACE),1) +enabled_cairo_pkgconf += cairo-xlib.pc +endif + +supported_cairo_headers += $(cairo_xlib_xrender_headers) +all_cairo_headers += $(cairo_xlib_xrender_headers) +all_cairo_private += $(cairo_xlib_xrender_private) +all_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) +all_cairo_sources += $(cairo_xlib_xrender_sources) +ifeq ($(CAIRO_HAS_XLIB_XRENDER_SURFACE),1) +enabled_cairo_headers += $(cairo_xlib_xrender_headers) +enabled_cairo_private += $(cairo_xlib_xrender_private) +enabled_cairo_cxx_sources += $(cairo_xlib_xrender_cxx_sources) +enabled_cairo_sources += $(cairo_xlib_xrender_sources) +endif +all_cairo_pkgconf += cairo-xlib-xrender.pc +ifeq ($(CAIRO_HAS_XLIB_XRENDER_SURFACE),1) +enabled_cairo_pkgconf += cairo-xlib-xrender.pc +endif + +supported_cairo_headers += $(cairo_xcb_headers) +all_cairo_headers += $(cairo_xcb_headers) +all_cairo_private += $(cairo_xcb_private) +all_cairo_cxx_sources += $(cairo_xcb_cxx_sources) +all_cairo_sources += $(cairo_xcb_sources) +ifeq ($(CAIRO_HAS_XCB_SURFACE),1) +enabled_cairo_headers += $(cairo_xcb_headers) +enabled_cairo_private += $(cairo_xcb_private) +enabled_cairo_cxx_sources += $(cairo_xcb_cxx_sources) +enabled_cairo_sources += $(cairo_xcb_sources) +endif +all_cairo_pkgconf += cairo-xcb.pc +ifeq ($(CAIRO_HAS_XCB_SURFACE),1) +enabled_cairo_pkgconf += cairo-xcb.pc +endif + +unsupported_cairo_headers += $(cairo_xlib_xcb_headers) +all_cairo_headers += $(cairo_xlib_xcb_headers) +all_cairo_private += $(cairo_xlib_xcb_private) +all_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) +all_cairo_sources += $(cairo_xlib_xcb_sources) +ifeq ($(CAIRO_HAS_XLIB_XCB_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_xlib_xcb_headers) +enabled_cairo_private += $(cairo_xlib_xcb_private) +enabled_cairo_cxx_sources += $(cairo_xlib_xcb_cxx_sources) +enabled_cairo_sources += $(cairo_xlib_xcb_sources) +endif +all_cairo_pkgconf += cairo-xlib-xcb.pc +ifeq ($(CAIRO_HAS_XLIB_XCB_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-xlib-xcb.pc +endif + +supported_cairo_headers += $(cairo_xcb_shm_headers) +all_cairo_headers += $(cairo_xcb_shm_headers) +all_cairo_private += $(cairo_xcb_shm_private) +all_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) +all_cairo_sources += $(cairo_xcb_shm_sources) +ifeq ($(CAIRO_HAS_XCB_SHM_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_xcb_shm_headers) +enabled_cairo_private += $(cairo_xcb_shm_private) +enabled_cairo_cxx_sources += $(cairo_xcb_shm_cxx_sources) +enabled_cairo_sources += $(cairo_xcb_shm_sources) +endif +all_cairo_pkgconf += cairo-xcb-shm.pc +ifeq ($(CAIRO_HAS_XCB_SHM_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-xcb-shm.pc +endif + +unsupported_cairo_headers += $(cairo_qt_headers) +all_cairo_headers += $(cairo_qt_headers) +all_cairo_private += $(cairo_qt_private) +all_cairo_cxx_sources += $(cairo_qt_cxx_sources) +all_cairo_sources += $(cairo_qt_sources) +ifeq ($(CAIRO_HAS_QT_SURFACE),1) +enabled_cairo_headers += $(cairo_qt_headers) +enabled_cairo_private += $(cairo_qt_private) +enabled_cairo_cxx_sources += $(cairo_qt_cxx_sources) +enabled_cairo_sources += $(cairo_qt_sources) +endif +all_cairo_pkgconf += cairo-qt.pc +ifeq ($(CAIRO_HAS_QT_SURFACE),1) +enabled_cairo_pkgconf += cairo-qt.pc +endif + +supported_cairo_headers += $(cairo_quartz_headers) +all_cairo_headers += $(cairo_quartz_headers) +all_cairo_private += $(cairo_quartz_private) +all_cairo_cxx_sources += $(cairo_quartz_cxx_sources) +all_cairo_sources += $(cairo_quartz_sources) +ifeq ($(CAIRO_HAS_QUARTZ_SURFACE),1) +enabled_cairo_headers += $(cairo_quartz_headers) +enabled_cairo_private += $(cairo_quartz_private) +enabled_cairo_cxx_sources += $(cairo_quartz_cxx_sources) +enabled_cairo_sources += $(cairo_quartz_sources) +endif +all_cairo_pkgconf += cairo-quartz.pc +ifeq ($(CAIRO_HAS_QUARTZ_SURFACE),1) +enabled_cairo_pkgconf += cairo-quartz.pc +endif + +supported_cairo_headers += $(cairo_quartz_font_headers) +all_cairo_headers += $(cairo_quartz_font_headers) +all_cairo_private += $(cairo_quartz_font_private) +all_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) +all_cairo_sources += $(cairo_quartz_font_sources) +ifeq ($(CAIRO_HAS_QUARTZ_FONT),1) +enabled_cairo_headers += $(cairo_quartz_font_headers) +enabled_cairo_private += $(cairo_quartz_font_private) +enabled_cairo_cxx_sources += $(cairo_quartz_font_cxx_sources) +enabled_cairo_sources += $(cairo_quartz_font_sources) +endif +all_cairo_pkgconf += cairo-quartz-font.pc +ifeq ($(CAIRO_HAS_QUARTZ_FONT),1) +enabled_cairo_pkgconf += cairo-quartz-font.pc +endif + +unsupported_cairo_headers += $(cairo_quartz_image_headers) +all_cairo_headers += $(cairo_quartz_image_headers) +all_cairo_private += $(cairo_quartz_image_private) +all_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) +all_cairo_sources += $(cairo_quartz_image_sources) +ifeq ($(CAIRO_HAS_QUARTZ_IMAGE_SURFACE),1) +enabled_cairo_headers += $(cairo_quartz_image_headers) +enabled_cairo_private += $(cairo_quartz_image_private) +enabled_cairo_cxx_sources += $(cairo_quartz_image_cxx_sources) +enabled_cairo_sources += $(cairo_quartz_image_sources) +endif +all_cairo_pkgconf += cairo-quartz-image.pc +ifeq ($(CAIRO_HAS_QUARTZ_IMAGE_SURFACE),1) +enabled_cairo_pkgconf += cairo-quartz-image.pc +endif + +supported_cairo_headers += $(cairo_win32_headers) +all_cairo_headers += $(cairo_win32_headers) +all_cairo_private += $(cairo_win32_private) +all_cairo_cxx_sources += $(cairo_win32_cxx_sources) +all_cairo_sources += $(cairo_win32_sources) +ifeq ($(CAIRO_HAS_WIN32_SURFACE),1) +enabled_cairo_headers += $(cairo_win32_headers) +enabled_cairo_private += $(cairo_win32_private) +enabled_cairo_cxx_sources += $(cairo_win32_cxx_sources) +enabled_cairo_sources += $(cairo_win32_sources) +endif +all_cairo_pkgconf += cairo-win32.pc +ifeq ($(CAIRO_HAS_WIN32_SURFACE),1) +enabled_cairo_pkgconf += cairo-win32.pc +endif + +supported_cairo_headers += $(cairo_win32_font_headers) +all_cairo_headers += $(cairo_win32_font_headers) +all_cairo_private += $(cairo_win32_font_private) +all_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) +all_cairo_sources += $(cairo_win32_font_sources) +ifeq ($(CAIRO_HAS_WIN32_FONT),1) +enabled_cairo_headers += $(cairo_win32_font_headers) +enabled_cairo_private += $(cairo_win32_font_private) +enabled_cairo_cxx_sources += $(cairo_win32_font_cxx_sources) +enabled_cairo_sources += $(cairo_win32_font_sources) +endif +all_cairo_pkgconf += cairo-win32-font.pc +ifeq ($(CAIRO_HAS_WIN32_FONT),1) +enabled_cairo_pkgconf += cairo-win32-font.pc +endif + +unsupported_cairo_headers += $(cairo_skia_headers) +all_cairo_headers += $(cairo_skia_headers) +all_cairo_private += $(cairo_skia_private) +all_cairo_cxx_sources += $(cairo_skia_cxx_sources) +all_cairo_sources += $(cairo_skia_sources) +ifeq ($(CAIRO_HAS_SKIA_SURFACE),1) +enabled_cairo_headers += $(cairo_skia_headers) +enabled_cairo_private += $(cairo_skia_private) +enabled_cairo_cxx_sources += $(cairo_skia_cxx_sources) +enabled_cairo_sources += $(cairo_skia_sources) +endif +all_cairo_pkgconf += cairo-skia.pc +ifeq ($(CAIRO_HAS_SKIA_SURFACE),1) +enabled_cairo_pkgconf += cairo-skia.pc +endif + +unsupported_cairo_headers += $(cairo_os2_headers) +all_cairo_headers += $(cairo_os2_headers) +all_cairo_private += $(cairo_os2_private) +all_cairo_cxx_sources += $(cairo_os2_cxx_sources) +all_cairo_sources += $(cairo_os2_sources) +ifeq ($(CAIRO_HAS_OS2_SURFACE),1) +enabled_cairo_headers += $(cairo_os2_headers) +enabled_cairo_private += $(cairo_os2_private) +enabled_cairo_cxx_sources += $(cairo_os2_cxx_sources) +enabled_cairo_sources += $(cairo_os2_sources) +endif +all_cairo_pkgconf += cairo-os2.pc +ifeq ($(CAIRO_HAS_OS2_SURFACE),1) +enabled_cairo_pkgconf += cairo-os2.pc +endif + +unsupported_cairo_headers += $(cairo_beos_headers) +all_cairo_headers += $(cairo_beos_headers) +all_cairo_private += $(cairo_beos_private) +all_cairo_cxx_sources += $(cairo_beos_cxx_sources) +all_cairo_sources += $(cairo_beos_sources) +ifeq ($(CAIRO_HAS_BEOS_SURFACE),1) +enabled_cairo_headers += $(cairo_beos_headers) +enabled_cairo_private += $(cairo_beos_private) +enabled_cairo_cxx_sources += $(cairo_beos_cxx_sources) +enabled_cairo_sources += $(cairo_beos_sources) +endif +all_cairo_pkgconf += cairo-beos.pc +ifeq ($(CAIRO_HAS_BEOS_SURFACE),1) +enabled_cairo_pkgconf += cairo-beos.pc +endif + +unsupported_cairo_headers += $(cairo_drm_headers) +all_cairo_headers += $(cairo_drm_headers) +all_cairo_private += $(cairo_drm_private) +all_cairo_cxx_sources += $(cairo_drm_cxx_sources) +all_cairo_sources += $(cairo_drm_sources) +ifeq ($(CAIRO_HAS_DRM_SURFACE),1) +enabled_cairo_headers += $(cairo_drm_headers) +enabled_cairo_private += $(cairo_drm_private) +enabled_cairo_cxx_sources += $(cairo_drm_cxx_sources) +enabled_cairo_sources += $(cairo_drm_sources) +endif +all_cairo_pkgconf += cairo-drm.pc +ifeq ($(CAIRO_HAS_DRM_SURFACE),1) +enabled_cairo_pkgconf += cairo-drm.pc +endif + +unsupported_cairo_headers += $(cairo_gallium_headers) +all_cairo_headers += $(cairo_gallium_headers) +all_cairo_private += $(cairo_gallium_private) +all_cairo_cxx_sources += $(cairo_gallium_cxx_sources) +all_cairo_sources += $(cairo_gallium_sources) +ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1) +enabled_cairo_headers += $(cairo_gallium_headers) +enabled_cairo_private += $(cairo_gallium_private) +enabled_cairo_cxx_sources += $(cairo_gallium_cxx_sources) +enabled_cairo_sources += $(cairo_gallium_sources) +endif +all_cairo_pkgconf += cairo-gallium.pc +ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1) +enabled_cairo_pkgconf += cairo-gallium.pc +endif + +supported_cairo_headers += $(cairo_png_headers) +all_cairo_headers += $(cairo_png_headers) +all_cairo_private += $(cairo_png_private) +all_cairo_cxx_sources += $(cairo_png_cxx_sources) +all_cairo_sources += $(cairo_png_sources) +ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_png_headers) +enabled_cairo_private += $(cairo_png_private) +enabled_cairo_cxx_sources += $(cairo_png_cxx_sources) +enabled_cairo_sources += $(cairo_png_sources) +endif +all_cairo_pkgconf += cairo-png.pc +ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-png.pc +endif + +unsupported_cairo_headers += $(cairo_gl_headers) +all_cairo_headers += $(cairo_gl_headers) +all_cairo_private += $(cairo_gl_private) +all_cairo_cxx_sources += $(cairo_gl_cxx_sources) +all_cairo_sources += $(cairo_gl_sources) +ifeq ($(CAIRO_HAS_GL_SURFACE),1) +enabled_cairo_headers += $(cairo_gl_headers) +enabled_cairo_private += $(cairo_gl_private) +enabled_cairo_cxx_sources += $(cairo_gl_cxx_sources) +enabled_cairo_sources += $(cairo_gl_sources) +endif +all_cairo_pkgconf += cairo-gl.pc +ifeq ($(CAIRO_HAS_GL_SURFACE),1) +enabled_cairo_pkgconf += cairo-gl.pc +endif + +unsupported_cairo_headers += $(cairo_glesv2_headers) +all_cairo_headers += $(cairo_glesv2_headers) +all_cairo_private += $(cairo_glesv2_private) +all_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) +all_cairo_sources += $(cairo_glesv2_sources) +ifeq ($(CAIRO_HAS_GLESV2_SURFACE),1) +enabled_cairo_headers += $(cairo_glesv2_headers) +enabled_cairo_private += $(cairo_glesv2_private) +enabled_cairo_cxx_sources += $(cairo_glesv2_cxx_sources) +enabled_cairo_sources += $(cairo_glesv2_sources) +endif +all_cairo_pkgconf += cairo-glesv2.pc +ifeq ($(CAIRO_HAS_GLESV2_SURFACE),1) +enabled_cairo_pkgconf += cairo-glesv2.pc +endif + +unsupported_cairo_headers += $(cairo_cogl_headers) +all_cairo_headers += $(cairo_cogl_headers) +all_cairo_private += $(cairo_cogl_private) +all_cairo_cxx_sources += $(cairo_cogl_cxx_sources) +all_cairo_sources += $(cairo_cogl_sources) +ifeq ($(CAIRO_HAS_COGL_SURFACE),1) +enabled_cairo_headers += $(cairo_cogl_headers) +enabled_cairo_private += $(cairo_cogl_private) +enabled_cairo_cxx_sources += $(cairo_cogl_cxx_sources) +enabled_cairo_sources += $(cairo_cogl_sources) +endif +all_cairo_pkgconf += cairo-cogl.pc +ifeq ($(CAIRO_HAS_COGL_SURFACE),1) +enabled_cairo_pkgconf += cairo-cogl.pc +endif + +unsupported_cairo_headers += $(cairo_directfb_headers) +all_cairo_headers += $(cairo_directfb_headers) +all_cairo_private += $(cairo_directfb_private) +all_cairo_cxx_sources += $(cairo_directfb_cxx_sources) +all_cairo_sources += $(cairo_directfb_sources) +ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1) +enabled_cairo_headers += $(cairo_directfb_headers) +enabled_cairo_private += $(cairo_directfb_private) +enabled_cairo_cxx_sources += $(cairo_directfb_cxx_sources) +enabled_cairo_sources += $(cairo_directfb_sources) +endif +all_cairo_pkgconf += cairo-directfb.pc +ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1) +enabled_cairo_pkgconf += cairo-directfb.pc +endif + +unsupported_cairo_headers += $(cairo_vg_headers) +all_cairo_headers += $(cairo_vg_headers) +all_cairo_private += $(cairo_vg_private) +all_cairo_cxx_sources += $(cairo_vg_cxx_sources) +all_cairo_sources += $(cairo_vg_sources) +ifeq ($(CAIRO_HAS_VG_SURFACE),1) +enabled_cairo_headers += $(cairo_vg_headers) +enabled_cairo_private += $(cairo_vg_private) +enabled_cairo_cxx_sources += $(cairo_vg_cxx_sources) +enabled_cairo_sources += $(cairo_vg_sources) +endif +all_cairo_pkgconf += cairo-vg.pc +ifeq ($(CAIRO_HAS_VG_SURFACE),1) +enabled_cairo_pkgconf += cairo-vg.pc +endif + +supported_cairo_headers += $(cairo_egl_headers) +all_cairo_headers += $(cairo_egl_headers) +all_cairo_private += $(cairo_egl_private) +all_cairo_cxx_sources += $(cairo_egl_cxx_sources) +all_cairo_sources += $(cairo_egl_sources) +ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_egl_headers) +enabled_cairo_private += $(cairo_egl_private) +enabled_cairo_cxx_sources += $(cairo_egl_cxx_sources) +enabled_cairo_sources += $(cairo_egl_sources) +endif +all_cairo_pkgconf += cairo-egl.pc +ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-egl.pc +endif + +supported_cairo_headers += $(cairo_glx_headers) +all_cairo_headers += $(cairo_glx_headers) +all_cairo_private += $(cairo_glx_private) +all_cairo_cxx_sources += $(cairo_glx_cxx_sources) +all_cairo_sources += $(cairo_glx_sources) +ifeq ($(CAIRO_HAS_GLX_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_glx_headers) +enabled_cairo_private += $(cairo_glx_private) +enabled_cairo_cxx_sources += $(cairo_glx_cxx_sources) +enabled_cairo_sources += $(cairo_glx_sources) +endif +all_cairo_pkgconf += cairo-glx.pc +ifeq ($(CAIRO_HAS_GLX_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-glx.pc +endif + +supported_cairo_headers += $(cairo_wgl_headers) +all_cairo_headers += $(cairo_wgl_headers) +all_cairo_private += $(cairo_wgl_private) +all_cairo_cxx_sources += $(cairo_wgl_cxx_sources) +all_cairo_sources += $(cairo_wgl_sources) +ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_wgl_headers) +enabled_cairo_private += $(cairo_wgl_private) +enabled_cairo_cxx_sources += $(cairo_wgl_cxx_sources) +enabled_cairo_sources += $(cairo_wgl_sources) +endif +all_cairo_pkgconf += cairo-wgl.pc +ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-wgl.pc +endif + +supported_cairo_headers += $(cairo_script_headers) +all_cairo_headers += $(cairo_script_headers) +all_cairo_private += $(cairo_script_private) +all_cairo_cxx_sources += $(cairo_script_cxx_sources) +all_cairo_sources += $(cairo_script_sources) +ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1) +enabled_cairo_headers += $(cairo_script_headers) +enabled_cairo_private += $(cairo_script_private) +enabled_cairo_cxx_sources += $(cairo_script_cxx_sources) +enabled_cairo_sources += $(cairo_script_sources) +endif +all_cairo_pkgconf += cairo-script.pc +ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1) +enabled_cairo_pkgconf += cairo-script.pc +endif + +supported_cairo_headers += $(cairo_ft_headers) +all_cairo_headers += $(cairo_ft_headers) +all_cairo_private += $(cairo_ft_private) +all_cairo_cxx_sources += $(cairo_ft_cxx_sources) +all_cairo_sources += $(cairo_ft_sources) +ifeq ($(CAIRO_HAS_FT_FONT),1) +enabled_cairo_headers += $(cairo_ft_headers) +enabled_cairo_private += $(cairo_ft_private) +enabled_cairo_cxx_sources += $(cairo_ft_cxx_sources) +enabled_cairo_sources += $(cairo_ft_sources) +endif +all_cairo_pkgconf += cairo-ft.pc +ifeq ($(CAIRO_HAS_FT_FONT),1) +enabled_cairo_pkgconf += cairo-ft.pc +endif + +supported_cairo_headers += $(cairo_fc_headers) +all_cairo_headers += $(cairo_fc_headers) +all_cairo_private += $(cairo_fc_private) +all_cairo_cxx_sources += $(cairo_fc_cxx_sources) +all_cairo_sources += $(cairo_fc_sources) +ifeq ($(CAIRO_HAS_FC_FONT),1) +enabled_cairo_headers += $(cairo_fc_headers) +enabled_cairo_private += $(cairo_fc_private) +enabled_cairo_cxx_sources += $(cairo_fc_cxx_sources) +enabled_cairo_sources += $(cairo_fc_sources) +endif +all_cairo_pkgconf += cairo-fc.pc +ifeq ($(CAIRO_HAS_FC_FONT),1) +enabled_cairo_pkgconf += cairo-fc.pc +endif + +supported_cairo_headers += $(cairo_ps_headers) +all_cairo_headers += $(cairo_ps_headers) +all_cairo_private += $(cairo_ps_private) +all_cairo_cxx_sources += $(cairo_ps_cxx_sources) +all_cairo_sources += $(cairo_ps_sources) +ifeq ($(CAIRO_HAS_PS_SURFACE),1) +enabled_cairo_headers += $(cairo_ps_headers) +enabled_cairo_private += $(cairo_ps_private) +enabled_cairo_cxx_sources += $(cairo_ps_cxx_sources) +enabled_cairo_sources += $(cairo_ps_sources) +endif +all_cairo_pkgconf += cairo-ps.pc +ifeq ($(CAIRO_HAS_PS_SURFACE),1) +enabled_cairo_pkgconf += cairo-ps.pc +endif + +supported_cairo_headers += $(cairo_pdf_headers) +all_cairo_headers += $(cairo_pdf_headers) +all_cairo_private += $(cairo_pdf_private) +all_cairo_cxx_sources += $(cairo_pdf_cxx_sources) +all_cairo_sources += $(cairo_pdf_sources) +ifeq ($(CAIRO_HAS_PDF_SURFACE),1) +enabled_cairo_headers += $(cairo_pdf_headers) +enabled_cairo_private += $(cairo_pdf_private) +enabled_cairo_cxx_sources += $(cairo_pdf_cxx_sources) +enabled_cairo_sources += $(cairo_pdf_sources) +endif +all_cairo_pkgconf += cairo-pdf.pc +ifeq ($(CAIRO_HAS_PDF_SURFACE),1) +enabled_cairo_pkgconf += cairo-pdf.pc +endif + +supported_cairo_headers += $(cairo_svg_headers) +all_cairo_headers += $(cairo_svg_headers) +all_cairo_private += $(cairo_svg_private) +all_cairo_cxx_sources += $(cairo_svg_cxx_sources) +all_cairo_sources += $(cairo_svg_sources) +ifeq ($(CAIRO_HAS_SVG_SURFACE),1) +enabled_cairo_headers += $(cairo_svg_headers) +enabled_cairo_private += $(cairo_svg_private) +enabled_cairo_cxx_sources += $(cairo_svg_cxx_sources) +enabled_cairo_sources += $(cairo_svg_sources) +endif +all_cairo_pkgconf += cairo-svg.pc +ifeq ($(CAIRO_HAS_SVG_SURFACE),1) +enabled_cairo_pkgconf += cairo-svg.pc +endif + +all_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) +all_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) +all_cairo_sources += $(cairo_test_surfaces_sources) +ifeq ($(CAIRO_HAS_TEST_SURFACES),1) +enabled_cairo_private += $(cairo_test_surfaces_private) $(cairo_test_surfaces_headers) +enabled_cairo_cxx_sources += $(cairo_test_surfaces_cxx_sources) +enabled_cairo_sources += $(cairo_test_surfaces_sources) +endif + +supported_cairo_headers += $(cairo_image_headers) +all_cairo_headers += $(cairo_image_headers) +all_cairo_private += $(cairo_image_private) +all_cairo_cxx_sources += $(cairo_image_cxx_sources) +all_cairo_sources += $(cairo_image_sources) +enabled_cairo_headers += $(cairo_image_headers) +enabled_cairo_private += $(cairo_image_private) +enabled_cairo_cxx_sources += $(cairo_image_cxx_sources) +enabled_cairo_sources += $(cairo_image_sources) + +supported_cairo_headers += $(cairo_mime_headers) +all_cairo_headers += $(cairo_mime_headers) +all_cairo_private += $(cairo_mime_private) +all_cairo_cxx_sources += $(cairo_mime_cxx_sources) +all_cairo_sources += $(cairo_mime_sources) +enabled_cairo_headers += $(cairo_mime_headers) +enabled_cairo_private += $(cairo_mime_private) +enabled_cairo_cxx_sources += $(cairo_mime_cxx_sources) +enabled_cairo_sources += $(cairo_mime_sources) + +supported_cairo_headers += $(cairo_recording_headers) +all_cairo_headers += $(cairo_recording_headers) +all_cairo_private += $(cairo_recording_private) +all_cairo_cxx_sources += $(cairo_recording_cxx_sources) +all_cairo_sources += $(cairo_recording_sources) +enabled_cairo_headers += $(cairo_recording_headers) +enabled_cairo_private += $(cairo_recording_private) +enabled_cairo_cxx_sources += $(cairo_recording_cxx_sources) +enabled_cairo_sources += $(cairo_recording_sources) + +supported_cairo_headers += $(cairo_observer_headers) +all_cairo_headers += $(cairo_observer_headers) +all_cairo_private += $(cairo_observer_private) +all_cairo_cxx_sources += $(cairo_observer_cxx_sources) +all_cairo_sources += $(cairo_observer_sources) +enabled_cairo_headers += $(cairo_observer_headers) +enabled_cairo_private += $(cairo_observer_private) +enabled_cairo_cxx_sources += $(cairo_observer_cxx_sources) +enabled_cairo_sources += $(cairo_observer_sources) + +unsupported_cairo_headers += $(cairo_tee_headers) +all_cairo_headers += $(cairo_tee_headers) +all_cairo_private += $(cairo_tee_private) +all_cairo_cxx_sources += $(cairo_tee_cxx_sources) +all_cairo_sources += $(cairo_tee_sources) +ifeq ($(CAIRO_HAS_TEE_SURFACE),1) +enabled_cairo_headers += $(cairo_tee_headers) +enabled_cairo_private += $(cairo_tee_private) +enabled_cairo_cxx_sources += $(cairo_tee_cxx_sources) +enabled_cairo_sources += $(cairo_tee_sources) +endif +all_cairo_pkgconf += cairo-tee.pc +ifeq ($(CAIRO_HAS_TEE_SURFACE),1) +enabled_cairo_pkgconf += cairo-tee.pc +endif + +unsupported_cairo_headers += $(cairo_xml_headers) +all_cairo_headers += $(cairo_xml_headers) +all_cairo_private += $(cairo_xml_private) +all_cairo_cxx_sources += $(cairo_xml_cxx_sources) +all_cairo_sources += $(cairo_xml_sources) +ifeq ($(CAIRO_HAS_XML_SURFACE),1) +enabled_cairo_headers += $(cairo_xml_headers) +enabled_cairo_private += $(cairo_xml_private) +enabled_cairo_cxx_sources += $(cairo_xml_cxx_sources) +enabled_cairo_sources += $(cairo_xml_sources) +endif +all_cairo_pkgconf += cairo-xml.pc +ifeq ($(CAIRO_HAS_XML_SURFACE),1) +enabled_cairo_pkgconf += cairo-xml.pc +endif + +supported_cairo_headers += $(cairo_user_headers) +all_cairo_headers += $(cairo_user_headers) +all_cairo_private += $(cairo_user_private) +all_cairo_cxx_sources += $(cairo_user_cxx_sources) +all_cairo_sources += $(cairo_user_sources) +enabled_cairo_headers += $(cairo_user_headers) +enabled_cairo_private += $(cairo_user_private) +enabled_cairo_cxx_sources += $(cairo_user_cxx_sources) +enabled_cairo_sources += $(cairo_user_sources) + +all_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) +all_cairo_cxx_sources += $(cairo_pthread_cxx_sources) +all_cairo_sources += $(cairo_pthread_sources) +ifeq ($(CAIRO_HAS_PTHREAD),1) +enabled_cairo_private += $(cairo_pthread_private) $(cairo_pthread_headers) +enabled_cairo_cxx_sources += $(cairo_pthread_cxx_sources) +enabled_cairo_sources += $(cairo_pthread_sources) +endif + +supported_cairo_headers += $(cairo_gobject_headers) +all_cairo_headers += $(cairo_gobject_headers) +all_cairo_private += $(cairo_gobject_private) +all_cairo_cxx_sources += $(cairo_gobject_cxx_sources) +all_cairo_sources += $(cairo_gobject_sources) +ifeq ($(CAIRO_HAS_GOBJECT_FUNCTIONS),1) +enabled_cairo_headers += $(cairo_gobject_headers) +enabled_cairo_private += $(cairo_gobject_private) +enabled_cairo_cxx_sources += $(cairo_gobject_cxx_sources) +enabled_cairo_sources += $(cairo_gobject_sources) +endif +all_cairo_pkgconf += cairo-gobject.pc +ifeq ($(CAIRO_HAS_GOBJECT_FUNCTIONS),1) +enabled_cairo_pkgconf += cairo-gobject.pc +endif + +all_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) +all_cairo_cxx_sources += $(cairo_trace_cxx_sources) +all_cairo_sources += $(cairo_trace_sources) +ifeq ($(CAIRO_HAS_TRACE),1) +enabled_cairo_private += $(cairo_trace_private) $(cairo_trace_headers) +enabled_cairo_cxx_sources += $(cairo_trace_cxx_sources) +enabled_cairo_sources += $(cairo_trace_sources) +endif + +all_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) +all_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) +all_cairo_sources += $(cairo_interpreter_sources) +ifeq ($(CAIRO_HAS_INTERPRETER),1) +enabled_cairo_private += $(cairo_interpreter_private) $(cairo_interpreter_headers) +enabled_cairo_cxx_sources += $(cairo_interpreter_cxx_sources) +enabled_cairo_sources += $(cairo_interpreter_sources) +endif + +all_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) +all_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) +all_cairo_sources += $(cairo_symbol_lookup_sources) +ifeq ($(CAIRO_HAS_SYMBOL_LOOKUP),1) +enabled_cairo_private += $(cairo_symbol_lookup_private) $(cairo_symbol_lookup_headers) +enabled_cairo_cxx_sources += $(cairo_symbol_lookup_cxx_sources) +enabled_cairo_sources += $(cairo_symbol_lookup_sources) +endif diff --git a/Build/source/libs/cairo/cairo-src/src/README b/Build/source/libs/cairo/cairo-src/src/README new file mode 100644 index 00000000000..03e4455ea58 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/README @@ -0,0 +1,69 @@ +Cairo Library Source Code +========================= + +This directory contains the source code of the cairo library. + + +Source Code Listing +------------------- + +The canonical list of source files is the file Makefile.sources. See that +file for how it works. + + +New Backends +------------ + +The rule of the thumb for adding new backends is to see how other +backends are integrated. Pick one of the simpler, unsupported, backends +and search the entire tree for it, and go from there. + +To add new backends you need to basically: + + * Modify $(top_srcdir)/configure.in to add checks for your backend. + + * Modify Makefile.sources to add source files for your backend, + + * Modify $(top_srcdir)/boilerplate/ to add boilerplate code for + testing your new backend. + + +New API +------- + +After adding new API, run "make check" in this directory and fix any +reported issues. Also add new API to the right location in +$(top_srcdir)/doc/public/cairo-sections.txt and run "make check" +in $(top_builddir)/doc/public to make sure that any newly added +documentation is correctly hooked up. + +Do not forget to add tests for the new API. See next section. + + +Tests +----- + +There are some tests in this directory that check the source code and +the build for various issues. The tests are very quick to run, and +particularly should be run after any documentation or API changes. It +does not hurt to run them after any source modification either. Run +them simply by calling: + + make check + +There are also extensive regression tests in $(top_srcdir)/test. It is +a good idea to run that test suite for any changes made to the source +code. Moreover, for any new feature, API, or bug fix, new tests should +be added to the regression test suite to test the new code. + + +Bibliography +------------ + +A detailed list of academic publications used in cairo code is available +in the file $(top_srcdir)/BIBLIOGRAPHY. Feel free to update as you +implement more papers. + +For more technical publications (eg. Adobe technical reports) just +point them out in a comment in the header of the file implementing them. + diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface-private.h new file mode 100644 index 00000000000..1e054c209ab --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface-private.h @@ -0,0 +1,74 @@ +/* + * Copyright © 2005 Keith Packard + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith Packard + */ + +#ifndef CAIRO_ANALYSIS_SURFACE_H +#define CAIRO_ANALYSIS_SURFACE_H + +#include "cairoint.h" + +cairo_private cairo_surface_t * +_cairo_analysis_surface_create (cairo_surface_t *target); + +cairo_private void +_cairo_analysis_surface_set_ctm (cairo_surface_t *surface, + const cairo_matrix_t *ctm); + +cairo_private void +_cairo_analysis_surface_get_ctm (cairo_surface_t *surface, + cairo_matrix_t *ctm); + +cairo_private cairo_region_t * +_cairo_analysis_surface_get_supported (cairo_surface_t *surface); + +cairo_private cairo_region_t * +_cairo_analysis_surface_get_unsupported (cairo_surface_t *surface); + +cairo_private cairo_bool_t +_cairo_analysis_surface_has_supported (cairo_surface_t *surface); + +cairo_private cairo_bool_t +_cairo_analysis_surface_has_unsupported (cairo_surface_t *surface); + +cairo_private void +_cairo_analysis_surface_get_bounding_box (cairo_surface_t *surface, + cairo_box_t *bbox); + +cairo_private cairo_int_status_t +_cairo_analysis_surface_merge_status (cairo_int_status_t status_a, + cairo_int_status_t status_b); + +cairo_private cairo_surface_t * +_cairo_null_surface_create (cairo_content_t content); + +#endif /* CAIRO_ANALYSIS_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface.c new file mode 100644 index 00000000000..8516094c200 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-analysis-surface.c @@ -0,0 +1,934 @@ +/* + * Copyright © 2006 Keith Packard + * Copyright © 2007 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith Packard + * Adrian Johnson + */ + +#include "cairoint.h" + +#include "cairo-analysis-surface-private.h" +#include "cairo-box-inline.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-paginated-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-inline.h" +#include "cairo-region-private.h" + +typedef struct { + cairo_surface_t base; + + cairo_surface_t *target; + + cairo_bool_t first_op; + cairo_bool_t has_supported; + cairo_bool_t has_unsupported; + + cairo_region_t supported_region; + cairo_region_t fallback_region; + cairo_box_t page_bbox; + + cairo_bool_t has_ctm; + cairo_matrix_t ctm; + +} cairo_analysis_surface_t; + +cairo_int_status_t +_cairo_analysis_surface_merge_status (cairo_int_status_t status_a, + cairo_int_status_t status_b) +{ + /* fatal errors should be checked and propagated at source */ + assert (! _cairo_int_status_is_error (status_a)); + assert (! _cairo_int_status_is_error (status_b)); + + /* return the most important status */ + if (status_a == CAIRO_INT_STATUS_UNSUPPORTED || + status_b == CAIRO_INT_STATUS_UNSUPPORTED) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (status_a == CAIRO_INT_STATUS_IMAGE_FALLBACK || + status_b == CAIRO_INT_STATUS_IMAGE_FALLBACK) + return CAIRO_INT_STATUS_IMAGE_FALLBACK; + + if (status_a == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN || + status_b == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) + return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; + + if (status_a == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY || + status_b == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY) + return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; + + /* at this point we have checked all the valid internal codes, so... */ + assert (status_a == CAIRO_INT_STATUS_SUCCESS && + status_b == CAIRO_INT_STATUS_SUCCESS); + + return CAIRO_INT_STATUS_SUCCESS; +} + +struct proxy { + cairo_surface_t base; + cairo_surface_t *target; +}; + +static cairo_status_t +proxy_finish (void *abstract_surface) +{ + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t proxy_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_NULL, + proxy_finish, +}; + +static cairo_surface_t * +attach_proxy (cairo_surface_t *source, + cairo_surface_t *target) +{ + struct proxy *proxy; + + proxy = malloc (sizeof (*proxy)); + if (unlikely (proxy == NULL)) + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_surface_init (&proxy->base, &proxy_backend, NULL, target->content); + + proxy->target = target; + _cairo_surface_attach_snapshot (source, &proxy->base, NULL); + + return &proxy->base; +} + +static void +detach_proxy (cairo_surface_t *proxy) +{ + cairo_surface_finish (proxy); + cairo_surface_destroy (proxy); +} + +static cairo_int_status_t +_analyze_recording_surface_pattern (cairo_analysis_surface_t *surface, + const cairo_pattern_t *pattern) +{ + const cairo_surface_pattern_t *surface_pattern; + cairo_analysis_surface_t *tmp; + cairo_surface_t *source, *proxy; + cairo_matrix_t p2d; + cairo_status_t status, analysis_status; + + assert (pattern->type == CAIRO_PATTERN_TYPE_SURFACE); + surface_pattern = (const cairo_surface_pattern_t *) pattern; + assert (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING); + source = surface_pattern->surface; + + proxy = _cairo_surface_has_snapshot (source, &proxy_backend); + if (proxy != NULL) { + /* nothing untoward found so far */ + return CAIRO_STATUS_SUCCESS; + } + + tmp = (cairo_analysis_surface_t *) + _cairo_analysis_surface_create (surface->target); + if (unlikely (tmp->base.status)) + return tmp->base.status; + proxy = attach_proxy (source, &tmp->base); + + p2d = pattern->matrix; + status = cairo_matrix_invert (&p2d); + assert (status == CAIRO_STATUS_SUCCESS); + + cairo_matrix_multiply (&tmp->ctm, &p2d, &surface->ctm); + tmp->has_ctm = ! _cairo_matrix_is_identity (&tmp->ctm); + + source = _cairo_surface_get_source (source, NULL); + status = _cairo_recording_surface_replay_and_create_regions (source, + &tmp->base); + analysis_status = tmp->has_unsupported ? CAIRO_INT_STATUS_IMAGE_FALLBACK : CAIRO_INT_STATUS_SUCCESS; + detach_proxy (proxy); + cairo_surface_destroy (&tmp->base); + + if (unlikely (status)) + return status; + + return analysis_status; +} + +static cairo_int_status_t +_add_operation (cairo_analysis_surface_t *surface, + cairo_rectangle_int_t *rect, + cairo_int_status_t backend_status) +{ + cairo_int_status_t status; + cairo_box_t bbox; + + if (rect->width == 0 || rect->height == 0) { + /* Even though the operation is not visible we must be careful + * to not allow unsupported operations to be replayed to the + * backend during CAIRO_PAGINATED_MODE_RENDER */ + if (backend_status == CAIRO_INT_STATUS_SUCCESS || + backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY || + backend_status == CAIRO_INT_STATUS_NOTHING_TO_DO) + { + return CAIRO_INT_STATUS_SUCCESS; + } + else + { + return CAIRO_INT_STATUS_IMAGE_FALLBACK; + } + } + + _cairo_box_from_rectangle (&bbox, rect); + + if (surface->has_ctm) { + int tx, ty; + + if (_cairo_matrix_is_integer_translation (&surface->ctm, &tx, &ty)) { + rect->x += tx; + rect->y += ty; + + tx = _cairo_fixed_from_int (tx); + bbox.p1.x += tx; + bbox.p2.x += tx; + + ty = _cairo_fixed_from_int (ty); + bbox.p1.y += ty; + bbox.p2.y += ty; + } else { + _cairo_matrix_transform_bounding_box_fixed (&surface->ctm, + &bbox, NULL); + + if (bbox.p1.x == bbox.p2.x || bbox.p1.y == bbox.p2.y) { + /* Even though the operation is not visible we must be + * careful to not allow unsupported operations to be + * replayed to the backend during + * CAIRO_PAGINATED_MODE_RENDER */ + if (backend_status == CAIRO_INT_STATUS_SUCCESS || + backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY || + backend_status == CAIRO_INT_STATUS_NOTHING_TO_DO) + { + return CAIRO_INT_STATUS_SUCCESS; + } + else + { + return CAIRO_INT_STATUS_IMAGE_FALLBACK; + } + } + + _cairo_box_round_to_rectangle (&bbox, rect); + } + } + + if (surface->first_op) { + surface->first_op = FALSE; + surface->page_bbox = bbox; + } else + _cairo_box_add_box(&surface->page_bbox, &bbox); + + /* If the operation is completely enclosed within the fallback + * region there is no benefit in emitting a native operation as + * the fallback image will be painted on top. + */ + if (cairo_region_contains_rectangle (&surface->fallback_region, rect) == CAIRO_REGION_OVERLAP_IN) + return CAIRO_INT_STATUS_IMAGE_FALLBACK; + + if (backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY) { + /* A status of CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY indicates + * that the backend only supports this operation if the + * transparency removed. If the extents of this operation does + * not intersect any other native operation, the operation is + * natively supported and the backend will blend the + * transparency into the white background. + */ + if (cairo_region_contains_rectangle (&surface->supported_region, rect) == CAIRO_REGION_OVERLAP_OUT) + backend_status = CAIRO_INT_STATUS_SUCCESS; + } + + if (backend_status == CAIRO_INT_STATUS_SUCCESS) { + /* Add the operation to the supported region. Operations in + * this region will be emitted as native operations. + */ + surface->has_supported = TRUE; + return cairo_region_union_rectangle (&surface->supported_region, rect); + } + + /* Add the operation to the unsupported region. This region will + * be painted as an image after all native operations have been + * emitted. + */ + surface->has_unsupported = TRUE; + status = cairo_region_union_rectangle (&surface->fallback_region, rect); + + /* The status CAIRO_INT_STATUS_IMAGE_FALLBACK is used to indicate + * unsupported operations to the recording surface as using + * CAIRO_INT_STATUS_UNSUPPORTED would cause cairo-surface to + * invoke the cairo-surface-fallback path then return + * CAIRO_STATUS_SUCCESS. + */ + if (status == CAIRO_INT_STATUS_SUCCESS) + return CAIRO_INT_STATUS_IMAGE_FALLBACK; + else + return status; +} + +static cairo_status_t +_cairo_analysis_surface_finish (void *abstract_surface) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + _cairo_region_fini (&surface->supported_region); + _cairo_region_fini (&surface->fallback_region); + + cairo_surface_destroy (surface->target); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_analysis_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_analysis_surface_t *surface = abstract_surface; + + return _cairo_surface_get_extents (surface->target, rectangle); +} + +static void +_rectangle_intersect_clip (cairo_rectangle_int_t *extents, const cairo_clip_t *clip) +{ + if (clip != NULL) + _cairo_rectangle_intersect (extents, _cairo_clip_get_extents (clip)); +} + +static void +_cairo_analysis_surface_operation_extents (cairo_analysis_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip, + cairo_rectangle_int_t *extents) +{ + cairo_bool_t is_empty; + + is_empty = _cairo_surface_get_extents (&surface->base, extents); + + if (_cairo_operator_bounded_by_source (op)) { + cairo_rectangle_int_t source_extents; + + _cairo_pattern_get_extents (source, &source_extents); + _cairo_rectangle_intersect (extents, &source_extents); + } + + _rectangle_intersect_clip (extents, clip); +} + +static cairo_int_status_t +_cairo_analysis_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_analysis_surface_t *surface = abstract_surface; + cairo_int_status_t backend_status; + cairo_rectangle_int_t extents; + + if (surface->target->backend->paint == NULL) { + backend_status = CAIRO_INT_STATUS_UNSUPPORTED; + } else { + backend_status = + surface->target->backend->paint (surface->target, + op, source, clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + + if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) + backend_status = _analyze_recording_surface_pattern (surface, source); + + _cairo_analysis_surface_operation_extents (surface, + op, source, clip, + &extents); + + return _add_operation (surface, &extents, backend_status); +} + +static cairo_int_status_t +_cairo_analysis_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_analysis_surface_t *surface = abstract_surface; + cairo_int_status_t backend_status; + cairo_rectangle_int_t extents; + + if (surface->target->backend->mask == NULL) { + backend_status = CAIRO_INT_STATUS_UNSUPPORTED; + } else { + backend_status = + surface->target->backend->mask (surface->target, + op, source, mask, clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + + if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) { + cairo_int_status_t backend_source_status = CAIRO_STATUS_SUCCESS; + cairo_int_status_t backend_mask_status = CAIRO_STATUS_SUCCESS; + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_t *src_surface = ((cairo_surface_pattern_t *)source)->surface; + src_surface = _cairo_surface_get_source (src_surface, NULL); + if (_cairo_surface_is_recording (src_surface)) { + backend_source_status = + _analyze_recording_surface_pattern (surface, source); + if (_cairo_int_status_is_error (backend_source_status)) + return backend_source_status; + } + } + + if (mask->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_t *mask_surface = ((cairo_surface_pattern_t *)mask)->surface; + mask_surface = _cairo_surface_get_source (mask_surface, NULL); + if (_cairo_surface_is_recording (mask_surface)) { + backend_mask_status = + _analyze_recording_surface_pattern (surface, mask); + if (_cairo_int_status_is_error (backend_mask_status)) + return backend_mask_status; + } + } + + backend_status = + _cairo_analysis_surface_merge_status (backend_source_status, + backend_mask_status); + } + + _cairo_analysis_surface_operation_extents (surface, + op, source, clip, + &extents); + + if (_cairo_operator_bounded_by_mask (op)) { + cairo_rectangle_int_t mask_extents; + + _cairo_pattern_get_extents (mask, &mask_extents); + _cairo_rectangle_intersect (&extents, &mask_extents); + } + + return _add_operation (surface, &extents, backend_status); +} + +static cairo_int_status_t +_cairo_analysis_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_analysis_surface_t *surface = abstract_surface; + cairo_int_status_t backend_status; + cairo_rectangle_int_t extents; + + if (surface->target->backend->stroke == NULL) { + backend_status = CAIRO_INT_STATUS_UNSUPPORTED; + } else { + backend_status = + surface->target->backend->stroke (surface->target, op, + source, path, style, + ctm, ctm_inverse, + tolerance, antialias, + clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + + if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) + backend_status = _analyze_recording_surface_pattern (surface, source); + + _cairo_analysis_surface_operation_extents (surface, + op, source, clip, + &extents); + + if (_cairo_operator_bounded_by_mask (op)) { + cairo_rectangle_int_t mask_extents; + cairo_int_status_t status; + + status = _cairo_path_fixed_stroke_extents (path, style, + ctm, ctm_inverse, + tolerance, + &mask_extents); + if (unlikely (status)) + return status; + + _cairo_rectangle_intersect (&extents, &mask_extents); + } + + return _add_operation (surface, &extents, backend_status); +} + +static cairo_int_status_t +_cairo_analysis_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_analysis_surface_t *surface = abstract_surface; + cairo_int_status_t backend_status; + cairo_rectangle_int_t extents; + + if (surface->target->backend->fill == NULL) { + backend_status = CAIRO_INT_STATUS_UNSUPPORTED; + } else { + backend_status = + surface->target->backend->fill (surface->target, op, + source, path, fill_rule, + tolerance, antialias, + clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + + if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) + backend_status = _analyze_recording_surface_pattern (surface, source); + + _cairo_analysis_surface_operation_extents (surface, + op, source, clip, + &extents); + + if (_cairo_operator_bounded_by_mask (op)) { + cairo_rectangle_int_t mask_extents; + + _cairo_path_fixed_fill_extents (path, fill_rule, tolerance, + &mask_extents); + + _cairo_rectangle_intersect (&extents, &mask_extents); + } + + return _add_operation (surface, &extents, backend_status); +} + +static cairo_int_status_t +_cairo_analysis_surface_show_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_analysis_surface_t *surface = abstract_surface; + cairo_int_status_t status, backend_status; + cairo_rectangle_int_t extents, glyph_extents; + + /* Adapted from _cairo_surface_show_glyphs */ + if (surface->target->backend->show_glyphs != NULL) { + backend_status = + surface->target->backend->show_glyphs (surface->target, op, + source, + glyphs, num_glyphs, + scaled_font, + clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + else if (surface->target->backend->show_text_glyphs != NULL) + { + backend_status = + surface->target->backend->show_text_glyphs (surface->target, op, + source, + NULL, 0, + glyphs, num_glyphs, + NULL, 0, + FALSE, + scaled_font, + clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + else + { + backend_status = CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) + backend_status = _analyze_recording_surface_pattern (surface, source); + + _cairo_analysis_surface_operation_extents (surface, + op, source, clip, + &extents); + + if (_cairo_operator_bounded_by_mask (op)) { + status = _cairo_scaled_font_glyph_device_extents (scaled_font, + glyphs, + num_glyphs, + &glyph_extents, + NULL); + if (unlikely (status)) + return status; + + _cairo_rectangle_intersect (&extents, &glyph_extents); + } + + return _add_operation (surface, &extents, backend_status); +} + +static cairo_bool_t +_cairo_analysis_surface_has_show_text_glyphs (void *abstract_surface) +{ + cairo_analysis_surface_t *surface = abstract_surface; + + return cairo_surface_has_show_text_glyphs (surface->target); +} + +static cairo_int_status_t +_cairo_analysis_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_analysis_surface_t *surface = abstract_surface; + cairo_int_status_t status, backend_status; + cairo_rectangle_int_t extents, glyph_extents; + + /* Adapted from _cairo_surface_show_glyphs */ + backend_status = CAIRO_INT_STATUS_UNSUPPORTED; + if (surface->target->backend->show_text_glyphs != NULL) { + backend_status = + surface->target->backend->show_text_glyphs (surface->target, op, + source, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font, + clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + if (backend_status == CAIRO_INT_STATUS_UNSUPPORTED && + surface->target->backend->show_glyphs != NULL) + { + backend_status = + surface->target->backend->show_glyphs (surface->target, op, + source, + glyphs, num_glyphs, + scaled_font, + clip); + if (_cairo_int_status_is_error (backend_status)) + return backend_status; + } + + if (backend_status == CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN) + backend_status = _analyze_recording_surface_pattern (surface, source); + + _cairo_analysis_surface_operation_extents (surface, + op, source, clip, + &extents); + + if (_cairo_operator_bounded_by_mask (op)) { + status = _cairo_scaled_font_glyph_device_extents (scaled_font, + glyphs, + num_glyphs, + &glyph_extents, + NULL); + if (unlikely (status)) + return status; + + _cairo_rectangle_intersect (&extents, &glyph_extents); + } + + return _add_operation (surface, &extents, backend_status); +} + +static const cairo_surface_backend_t cairo_analysis_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_ANALYSIS, + + _cairo_analysis_surface_finish, + NULL, + + NULL, /* create_similar */ + NULL, /* create_similar_image */ + NULL, /* map_to_image */ + NULL, /* unmap */ + + NULL, /* source */ + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_analysis_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_analysis_surface_paint, + _cairo_analysis_surface_mask, + _cairo_analysis_surface_stroke, + _cairo_analysis_surface_fill, + NULL, /* fill_stroke */ + _cairo_analysis_surface_show_glyphs, + _cairo_analysis_surface_has_show_text_glyphs, + _cairo_analysis_surface_show_text_glyphs +}; + +cairo_surface_t * +_cairo_analysis_surface_create (cairo_surface_t *target) +{ + cairo_analysis_surface_t *surface; + cairo_status_t status; + + status = target->status; + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + surface = malloc (sizeof (cairo_analysis_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + /* I believe the content type here is truly arbitrary. I'm quite + * sure nothing will ever use this value. */ + _cairo_surface_init (&surface->base, + &cairo_analysis_surface_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + cairo_matrix_init_identity (&surface->ctm); + surface->has_ctm = FALSE; + + surface->target = cairo_surface_reference (target); + surface->first_op = TRUE; + surface->has_supported = FALSE; + surface->has_unsupported = FALSE; + + _cairo_region_init (&surface->supported_region); + _cairo_region_init (&surface->fallback_region); + + surface->page_bbox.p1.x = 0; + surface->page_bbox.p1.y = 0; + surface->page_bbox.p2.x = 0; + surface->page_bbox.p2.y = 0; + + return &surface->base; +} + +void +_cairo_analysis_surface_set_ctm (cairo_surface_t *abstract_surface, + const cairo_matrix_t *ctm) +{ + cairo_analysis_surface_t *surface; + + if (abstract_surface->status) + return; + + surface = (cairo_analysis_surface_t *) abstract_surface; + + surface->ctm = *ctm; + surface->has_ctm = ! _cairo_matrix_is_identity (&surface->ctm); +} + +void +_cairo_analysis_surface_get_ctm (cairo_surface_t *abstract_surface, + cairo_matrix_t *ctm) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + *ctm = surface->ctm; +} + + +cairo_region_t * +_cairo_analysis_surface_get_supported (cairo_surface_t *abstract_surface) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + return &surface->supported_region; +} + +cairo_region_t * +_cairo_analysis_surface_get_unsupported (cairo_surface_t *abstract_surface) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + return &surface->fallback_region; +} + +cairo_bool_t +_cairo_analysis_surface_has_supported (cairo_surface_t *abstract_surface) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + return surface->has_supported; +} + +cairo_bool_t +_cairo_analysis_surface_has_unsupported (cairo_surface_t *abstract_surface) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + return surface->has_unsupported; +} + +void +_cairo_analysis_surface_get_bounding_box (cairo_surface_t *abstract_surface, + cairo_box_t *bbox) +{ + cairo_analysis_surface_t *surface = (cairo_analysis_surface_t *) abstract_surface; + + *bbox = surface->page_bbox; +} + +/* null surface type: a surface that does nothing (has no side effects, yay!) */ + +static cairo_int_status_t +_return_success (void) +{ + return CAIRO_STATUS_SUCCESS; +} + +/* These typedefs are just to silence the compiler... */ +typedef cairo_int_status_t +(*_paint_func) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +typedef cairo_int_status_t +(*_mask_func) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +typedef cairo_int_status_t +(*_stroke_func) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +typedef cairo_int_status_t +(*_fill_func) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +typedef cairo_int_status_t +(*_show_glyphs_func) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + +static const cairo_surface_backend_t cairo_null_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_NULL, + NULL, /* finish */ + + NULL, /* only accessed through the surface functions */ + + NULL, /* create_similar */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image*/ + + NULL, /* source */ + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + NULL, /* get_extents */ + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + (_paint_func) _return_success, /* paint */ + (_mask_func) _return_success, /* mask */ + (_stroke_func) _return_success, /* stroke */ + (_fill_func) _return_success, /* fill */ + NULL, /* fill_stroke */ + (_show_glyphs_func) _return_success, /* show_glyphs */ + NULL, /* has_show_text_glyphs */ + NULL /* show_text_glyphs */ +}; + +cairo_surface_t * +_cairo_null_surface_create (cairo_content_t content) +{ + cairo_surface_t *surface; + + surface = malloc (sizeof (cairo_surface_t)); + if (unlikely (surface == NULL)) { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + _cairo_surface_init (surface, + &cairo_null_surface_backend, + NULL, /* device */ + content); + + return surface; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-arc-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-arc-private.h new file mode 100644 index 00000000000..a22c01ac90b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-arc-private.h @@ -0,0 +1,61 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_ARC_PRIVATE_H +#define CAIRO_ARC_PRIVATE_H + +#include "cairoint.h" + +CAIRO_BEGIN_DECLS + +cairo_private void +_cairo_arc_path (cairo_t *cr, + double xc, + double yc, + double radius, + double angle1, + double angle2); + +cairo_private void +_cairo_arc_path_negative (cairo_t *cr, + double xc, + double yc, + double radius, + double angle1, + double angle2); + +CAIRO_END_DECLS + +#endif /* CAIRO_ARC_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-arc.c b/Build/source/libs/cairo/cairo-src/src/cairo-arc.c new file mode 100644 index 00000000000..390397bae10 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-arc.c @@ -0,0 +1,312 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-arc-private.h" + +#define MAX_FULL_CIRCLES 65536 + +/* Spline deviation from the circle in radius would be given by: + + error = sqrt (x**2 + y**2) - 1 + + A simpler error function to work with is: + + e = x**2 + y**2 - 1 + + From "Good approximation of circles by curvature-continuous Bezier + curves", Tor Dokken and Morten Daehlen, Computer Aided Geometric + Design 8 (1990) 22-41, we learn: + + abs (max(e)) = 4/27 * sin**6(angle/4) / cos**2(angle/4) + + and + abs (error) =~ 1/2 * e + + Of course, this error value applies only for the particular spline + approximation that is used in _cairo_gstate_arc_segment. +*/ +static double +_arc_error_normalized (double angle) +{ + return 2.0/27.0 * pow (sin (angle / 4), 6) / pow (cos (angle / 4), 2); +} + +static double +_arc_max_angle_for_tolerance_normalized (double tolerance) +{ + double angle, error; + int i; + + /* Use table lookup to reduce search time in most cases. */ + struct { + double angle; + double error; + } table[] = { + { M_PI / 1.0, 0.0185185185185185036127 }, + { M_PI / 2.0, 0.000272567143730179811158 }, + { M_PI / 3.0, 2.38647043651461047433e-05 }, + { M_PI / 4.0, 4.2455377443222443279e-06 }, + { M_PI / 5.0, 1.11281001494389081528e-06 }, + { M_PI / 6.0, 3.72662000942734705475e-07 }, + { M_PI / 7.0, 1.47783685574284411325e-07 }, + { M_PI / 8.0, 6.63240432022601149057e-08 }, + { M_PI / 9.0, 3.2715520137536980553e-08 }, + { M_PI / 10.0, 1.73863223499021216974e-08 }, + { M_PI / 11.0, 9.81410988043554039085e-09 }, + }; + int table_size = ARRAY_LENGTH (table); + + for (i = 0; i < table_size; i++) + if (table[i].error < tolerance) + return table[i].angle; + + ++i; + do { + angle = M_PI / i++; + error = _arc_error_normalized (angle); + } while (error > tolerance); + + return angle; +} + +static int +_arc_segments_needed (double angle, + double radius, + cairo_matrix_t *ctm, + double tolerance) +{ + double major_axis, max_angle; + + /* the error is amplified by at most the length of the + * major axis of the circle; see cairo-pen.c for a more detailed analysis + * of this. */ + major_axis = _cairo_matrix_transformed_circle_major_axis (ctm, radius); + max_angle = _arc_max_angle_for_tolerance_normalized (tolerance / major_axis); + + return ceil (fabs (angle) / max_angle); +} + +/* We want to draw a single spline approximating a circular arc radius + R from angle A to angle B. Since we want a symmetric spline that + matches the endpoints of the arc in position and slope, we know + that the spline control points must be: + + (R * cos(A), R * sin(A)) + (R * cos(A) - h * sin(A), R * sin(A) + h * cos (A)) + (R * cos(B) + h * sin(B), R * sin(B) - h * cos (B)) + (R * cos(B), R * sin(B)) + + for some value of h. + + "Approximation of circular arcs by cubic polynomials", Michael + Goldapp, Computer Aided Geometric Design 8 (1991) 227-238, provides + various values of h along with error analysis for each. + + From that paper, a very practical value of h is: + + h = 4/3 * R * tan(angle/4) + + This value does not give the spline with minimal error, but it does + provide a very good approximation, (6th-order convergence), and the + error expression is quite simple, (see the comment for + _arc_error_normalized). +*/ +static void +_cairo_arc_segment (cairo_t *cr, + double xc, + double yc, + double radius, + double angle_A, + double angle_B) +{ + double r_sin_A, r_cos_A; + double r_sin_B, r_cos_B; + double h; + + r_sin_A = radius * sin (angle_A); + r_cos_A = radius * cos (angle_A); + r_sin_B = radius * sin (angle_B); + r_cos_B = radius * cos (angle_B); + + h = 4.0/3.0 * tan ((angle_B - angle_A) / 4.0); + + cairo_curve_to (cr, + xc + r_cos_A - h * r_sin_A, + yc + r_sin_A + h * r_cos_A, + xc + r_cos_B + h * r_sin_B, + yc + r_sin_B - h * r_cos_B, + xc + r_cos_B, + yc + r_sin_B); +} + +static void +_cairo_arc_in_direction (cairo_t *cr, + double xc, + double yc, + double radius, + double angle_min, + double angle_max, + cairo_direction_t dir) +{ + if (cairo_status (cr)) + return; + + assert (angle_max >= angle_min); + + if (angle_max - angle_min > 2 * M_PI * MAX_FULL_CIRCLES) { + angle_max = fmod (angle_max - angle_min, 2 * M_PI); + angle_min = fmod (angle_min, 2 * M_PI); + angle_max += angle_min + 2 * M_PI * MAX_FULL_CIRCLES; + } + + /* Recurse if drawing arc larger than pi */ + if (angle_max - angle_min > M_PI) { + double angle_mid = angle_min + (angle_max - angle_min) / 2.0; + if (dir == CAIRO_DIRECTION_FORWARD) { + _cairo_arc_in_direction (cr, xc, yc, radius, + angle_min, angle_mid, + dir); + + _cairo_arc_in_direction (cr, xc, yc, radius, + angle_mid, angle_max, + dir); + } else { + _cairo_arc_in_direction (cr, xc, yc, radius, + angle_mid, angle_max, + dir); + + _cairo_arc_in_direction (cr, xc, yc, radius, + angle_min, angle_mid, + dir); + } + } else if (angle_max != angle_min) { + cairo_matrix_t ctm; + int i, segments; + double step; + + cairo_get_matrix (cr, &ctm); + segments = _arc_segments_needed (angle_max - angle_min, + radius, &ctm, + cairo_get_tolerance (cr)); + step = (angle_max - angle_min) / segments; + segments -= 1; + + if (dir == CAIRO_DIRECTION_REVERSE) { + double t; + + t = angle_min; + angle_min = angle_max; + angle_max = t; + + step = -step; + } + + cairo_line_to (cr, + xc + radius * cos (angle_min), + yc + radius * sin (angle_min)); + + for (i = 0; i < segments; i++, angle_min += step) { + _cairo_arc_segment (cr, xc, yc, radius, + angle_min, angle_min + step); + } + + _cairo_arc_segment (cr, xc, yc, radius, + angle_min, angle_max); + } else { + cairo_line_to (cr, + xc + radius * cos (angle_min), + yc + radius * sin (angle_min)); + } +} + +/** + * _cairo_arc_path: + * @cr: a cairo context + * @xc: X position of the center of the arc + * @yc: Y position of the center of the arc + * @radius: the radius of the arc + * @angle1: the start angle, in radians + * @angle2: the end angle, in radians + * + * Compute a path for the given arc and append it onto the current + * path within @cr. The arc will be accurate within the current + * tolerance and given the current transformation. + **/ +void +_cairo_arc_path (cairo_t *cr, + double xc, + double yc, + double radius, + double angle1, + double angle2) +{ + _cairo_arc_in_direction (cr, xc, yc, + radius, + angle1, angle2, + CAIRO_DIRECTION_FORWARD); +} + +/** + * _cairo_arc_path_negative: + * @xc: X position of the center of the arc + * @yc: Y position of the center of the arc + * @radius: the radius of the arc + * @angle1: the start angle, in radians + * @angle2: the end angle, in radians + * @ctm: the current transformation matrix + * @tolerance: the current tolerance value + * @path: the path onto which the arc will be appended + * + * Compute a path for the given arc (defined in the negative + * direction) and append it onto the current path within @cr. The arc + * will be accurate within the current tolerance and given the current + * transformation. + **/ +void +_cairo_arc_path_negative (cairo_t *cr, + double xc, + double yc, + double radius, + double angle1, + double angle2) +{ + _cairo_arc_in_direction (cr, xc, yc, + radius, + angle2, angle1, + CAIRO_DIRECTION_REVERSE); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-array-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-array-private.h new file mode 100644 index 00000000000..35b29e5fc07 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-array-private.h @@ -0,0 +1,90 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_ARRAY_PRIVATE_H +#define CAIRO_ARRAY_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-types-private.h" + +CAIRO_BEGIN_DECLS + +/* cairo-array.c structures and functions */ + +cairo_private void +_cairo_array_init (cairo_array_t *array, unsigned int element_size); + +cairo_private void +_cairo_array_fini (cairo_array_t *array); + +cairo_private cairo_status_t +_cairo_array_grow_by (cairo_array_t *array, unsigned int additional); + +cairo_private void +_cairo_array_truncate (cairo_array_t *array, unsigned int num_elements); + +cairo_private cairo_status_t +_cairo_array_append (cairo_array_t *array, const void *element); + +cairo_private cairo_status_t +_cairo_array_append_multiple (cairo_array_t *array, + const void *elements, + unsigned int num_elements); + +cairo_private cairo_status_t +_cairo_array_allocate (cairo_array_t *array, + unsigned int num_elements, + void **elements); + +cairo_private void * +_cairo_array_index (cairo_array_t *array, unsigned int index); + +cairo_private const void * +_cairo_array_index_const (const cairo_array_t *array, unsigned int index); + +cairo_private void +_cairo_array_copy_element (const cairo_array_t *array, unsigned int index, void *dst); + +cairo_private unsigned int +_cairo_array_num_elements (const cairo_array_t *array); + +cairo_private unsigned int +_cairo_array_size (const cairo_array_t *array); + +CAIRO_END_DECLS + +#endif /* CAIRO_ARRAY_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-array.c b/Build/source/libs/cairo/cairo-src/src/cairo-array.c new file mode 100644 index 00000000000..58c9a388fa4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-array.c @@ -0,0 +1,529 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Carl Worth + */ + +#include "cairoint.h" +#include "cairo-array-private.h" +#include "cairo-error-private.h" + +/** + * _cairo_array_init: + * + * Initialize a new #cairo_array_t object to store objects each of size + * @element_size. + * + * The #cairo_array_t object provides grow-by-doubling storage. It + * never interprets the data passed to it, nor does it provide any + * sort of callback mechanism for freeing resources held onto by + * stored objects. + * + * When finished using the array, _cairo_array_fini() should be + * called to free resources allocated during use of the array. + **/ +void +_cairo_array_init (cairo_array_t *array, unsigned int element_size) +{ + array->size = 0; + array->num_elements = 0; + array->element_size = element_size; + array->elements = NULL; +} + +/** + * _cairo_array_fini: + * @array: A #cairo_array_t + * + * Free all resources associated with @array. After this call, @array + * should not be used again without a subsequent call to + * _cairo_array_init() again first. + **/ +void +_cairo_array_fini (cairo_array_t *array) +{ + free (array->elements); +} + +/** + * _cairo_array_grow_by: + * @array: a #cairo_array_t + * + * Increase the size of @array (if needed) so that there are at least + * @additional free spaces in the array. The actual size of the array + * is always increased by doubling as many times as necessary. + **/ +cairo_status_t +_cairo_array_grow_by (cairo_array_t *array, unsigned int additional) +{ + char *new_elements; + unsigned int old_size = array->size; + unsigned int required_size = array->num_elements + additional; + unsigned int new_size; + + /* check for integer overflow */ + if (required_size > INT_MAX || required_size < array->num_elements) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (required_size <= old_size) + return CAIRO_STATUS_SUCCESS; + + if (old_size == 0) + new_size = 1; + else + new_size = old_size * 2; + + while (new_size < required_size) + new_size = new_size * 2; + + array->size = new_size; + new_elements = _cairo_realloc_ab (array->elements, + array->size, array->element_size); + + if (unlikely (new_elements == NULL)) { + array->size = old_size; + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + array->elements = new_elements; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_array_truncate: + * @array: a #cairo_array_t + * + * Truncate size of the array to @num_elements if less than the + * current size. No memory is actually freed. The stored objects + * beyond @num_elements are simply "forgotten". + **/ +void +_cairo_array_truncate (cairo_array_t *array, unsigned int num_elements) +{ + if (num_elements < array->num_elements) + array->num_elements = num_elements; +} + +/** + * _cairo_array_index: + * @array: a #cairo_array_t + * Returns: A pointer to the object stored at @index. + * + * If the resulting value is assigned to a pointer to an object of the same + * element_size as initially passed to _cairo_array_init() then that + * pointer may be used for further direct indexing with []. For + * example: + * + * + * cairo_array_t array; + * double *values; + * + * _cairo_array_init (&array, sizeof(double)); + * ... calls to _cairo_array_append() here ... + * + * values = _cairo_array_index (&array, 0); + * for (i = 0; i < _cairo_array_num_elements (&array); i++) + * ... use values[i] here ... + * + **/ +void * +_cairo_array_index (cairo_array_t *array, unsigned int index) +{ + /* We allow an index of 0 for the no-elements case. + * This makes for cleaner calling code which will often look like: + * + * elements = _cairo_array_index (array, 0); + * for (i=0; i < num_elements; i++) { + * ... use elements[i] here ... + * } + * + * which in the num_elements==0 case gets the NULL pointer here, + * but never dereferences it. + */ + if (index == 0 && array->num_elements == 0) + return NULL; + + assert (index < array->num_elements); + + return array->elements + index * array->element_size; +} + +/** + * _cairo_array_index_const: + * @array: a #cairo_array_t + * Returns: A pointer to the object stored at @index. + * + * If the resulting value is assigned to a pointer to an object of the same + * element_size as initially passed to _cairo_array_init() then that + * pointer may be used for further direct indexing with []. For + * example: + * + * + * cairo_array_t array; + * const double *values; + * + * _cairo_array_init (&array, sizeof(double)); + * ... calls to _cairo_array_append() here ... + * + * values = _cairo_array_index_const (&array, 0); + * for (i = 0; i < _cairo_array_num_elements (&array); i++) + * ... read values[i] here ... + * + **/ +const void * +_cairo_array_index_const (const cairo_array_t *array, unsigned int index) +{ + /* We allow an index of 0 for the no-elements case. + * This makes for cleaner calling code which will often look like: + * + * elements = _cairo_array_index_const (array, 0); + * for (i=0; i < num_elements; i++) { + * ... read elements[i] here ... + * } + * + * which in the num_elements==0 case gets the NULL pointer here, + * but never dereferences it. + */ + if (index == 0 && array->num_elements == 0) + return NULL; + + assert (index < array->num_elements); + + return array->elements + index * array->element_size; +} + +/** + * _cairo_array_copy_element: + * @array: a #cairo_array_t + * + * Copy a single element out of the array from index @index into the + * location pointed to by @dst. + **/ +void +_cairo_array_copy_element (const cairo_array_t *array, + unsigned int index, + void *dst) +{ + memcpy (dst, _cairo_array_index_const (array, index), array->element_size); +} + +/** + * _cairo_array_append: + * @array: a #cairo_array_t + * + * Append a single item onto the array by growing the array by at + * least one element, then copying element_size bytes from @element + * into the array. The address of the resulting object within the + * array can be determined with: + * + * _cairo_array_index (array, _cairo_array_num_elements (array) - 1); + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the + * operation. + **/ +cairo_status_t +_cairo_array_append (cairo_array_t *array, + const void *element) +{ + return _cairo_array_append_multiple (array, element, 1); +} + +/** + * _cairo_array_append_multiple: + * @array: a #cairo_array_t + * + * Append one or more items onto the array by growing the array by + * @num_elements, then copying @num_elements * element_size bytes from + * @elements into the array. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the + * operation. + **/ +cairo_status_t +_cairo_array_append_multiple (cairo_array_t *array, + const void *elements, + unsigned int num_elements) +{ + cairo_status_t status; + void *dest; + + status = _cairo_array_allocate (array, num_elements, &dest); + if (unlikely (status)) + return status; + + memcpy (dest, elements, num_elements * array->element_size); + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_array_allocate: + * @array: a #cairo_array_t + * + * Allocate space at the end of the array for @num_elements additional + * elements, providing the address of the new memory chunk in + * @elements. This memory will be unitialized, but will be accounted + * for in the return value of _cairo_array_num_elements(). + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the + * operation. + **/ +cairo_status_t +_cairo_array_allocate (cairo_array_t *array, + unsigned int num_elements, + void **elements) +{ + cairo_status_t status; + + status = _cairo_array_grow_by (array, num_elements); + if (unlikely (status)) + return status; + + assert (array->num_elements + num_elements <= array->size); + + *elements = array->elements + array->num_elements * array->element_size; + + array->num_elements += num_elements; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_array_num_elements: + * @array: a #cairo_array_t + * Returns: The number of elements stored in @array. + * + * This space was left intentionally blank, but gtk-doc filled it. + **/ +unsigned int +_cairo_array_num_elements (const cairo_array_t *array) +{ + return array->num_elements; +} + +/** + * _cairo_array_size: + * @array: a #cairo_array_t + * Returns: The number of elements for which there is currently space + * allocated in @array. + * + * This space was left intentionally blank, but gtk-doc filled it. + **/ +unsigned int +_cairo_array_size (const cairo_array_t *array) +{ + return array->size; +} + +/** + * _cairo_user_data_array_init: + * @array: a #cairo_user_data_array_t + * + * Initializes a #cairo_user_data_array_t structure for future + * use. After initialization, the array has no keys. Call + * _cairo_user_data_array_fini() to free any allocated memory + * when done using the array. + **/ +void +_cairo_user_data_array_init (cairo_user_data_array_t *array) +{ + _cairo_array_init (array, sizeof (cairo_user_data_slot_t)); +} + +/** + * _cairo_user_data_array_fini: + * @array: a #cairo_user_data_array_t + * + * Destroys all current keys in the user data array and deallocates + * any memory allocated for the array itself. + **/ +void +_cairo_user_data_array_fini (cairo_user_data_array_t *array) +{ + unsigned int num_slots; + + num_slots = array->num_elements; + if (num_slots) { + cairo_user_data_slot_t *slots; + + slots = _cairo_array_index (array, 0); + while (num_slots--) { + cairo_user_data_slot_t *s = &slots[num_slots]; + if (s->user_data != NULL && s->destroy != NULL) + s->destroy (s->user_data); + } + } + + _cairo_array_fini (array); +} + +/** + * _cairo_user_data_array_get_data: + * @array: a #cairo_user_data_array_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Returns user data previously attached using the specified + * key. If no user data has been attached with the given key this + * function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + **/ +void * +_cairo_user_data_array_get_data (cairo_user_data_array_t *array, + const cairo_user_data_key_t *key) +{ + int i, num_slots; + cairo_user_data_slot_t *slots; + + /* We allow this to support degenerate objects such as cairo_surface_nil. */ + if (array == NULL) + return NULL; + + num_slots = array->num_elements; + slots = _cairo_array_index (array, 0); + for (i = 0; i < num_slots; i++) { + if (slots[i].key == key) + return slots[i].user_data; + } + + return NULL; +} + +/** + * _cairo_user_data_array_set_data: + * @array: a #cairo_user_data_array_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach + * @destroy: a #cairo_destroy_func_t which will be called when the + * user data array is destroyed or when new user data is attached using the + * same key. + * + * Attaches user data to a user data array. To remove user data, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + **/ +cairo_status_t +_cairo_user_data_array_set_data (cairo_user_data_array_t *array, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + cairo_status_t status; + int i, num_slots; + cairo_user_data_slot_t *slots, *slot, new_slot; + + if (user_data) { + new_slot.key = key; + new_slot.user_data = user_data; + new_slot.destroy = destroy; + } else { + new_slot.key = NULL; + new_slot.user_data = NULL; + new_slot.destroy = NULL; + } + + slot = NULL; + num_slots = array->num_elements; + slots = _cairo_array_index (array, 0); + for (i = 0; i < num_slots; i++) { + if (slots[i].key == key) { + slot = &slots[i]; + if (slot->destroy && slot->user_data) + slot->destroy (slot->user_data); + break; + } + if (user_data && slots[i].user_data == NULL) { + slot = &slots[i]; /* Have to keep searching for an exact match */ + } + } + + if (slot) { + *slot = new_slot; + return CAIRO_STATUS_SUCCESS; + } + + if (user_data == NULL) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_array_append (array, &new_slot); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_user_data_array_copy (cairo_user_data_array_t *dst, + const cairo_user_data_array_t *src) +{ + /* discard any existing user-data */ + if (dst->num_elements != 0) { + _cairo_user_data_array_fini (dst); + _cairo_user_data_array_init (dst); + } + + return _cairo_array_append_multiple (dst, + _cairo_array_index_const (src, 0), + src->num_elements); +} + +void +_cairo_user_data_array_foreach (cairo_user_data_array_t *array, + void (*func) (const void *key, + void *elt, + void *closure), + void *closure) +{ + cairo_user_data_slot_t *slots; + int i, num_slots; + + num_slots = array->num_elements; + slots = _cairo_array_index (array, 0); + for (i = 0; i < num_slots; i++) { + if (slots[i].user_data != NULL) + func (slots[i].key, slots[i].user_data, closure); + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-atomic-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-atomic-private.h new file mode 100644 index 00000000000..11b2887a147 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-atomic-private.h @@ -0,0 +1,362 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * Copyright © 2010 Andrea Canciani + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + * Andrea Canciani + */ + +#ifndef CAIRO_ATOMIC_PRIVATE_H +#define CAIRO_ATOMIC_PRIVATE_H + +# include "cairo-compiler-private.h" + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +/* The autoconf on OpenBSD 4.5 produces the malformed constant name + * SIZEOF_VOID__ rather than SIZEOF_VOID_P. Work around that here. */ +#if !defined(SIZEOF_VOID_P) && defined(SIZEOF_VOID__) +# define SIZEOF_VOID_P SIZEOF_VOID__ +#endif + +CAIRO_BEGIN_DECLS + +/* C++11 atomic primitives were designed to be more flexible than the + * __sync_* family of primitives. Despite the name, they are available + * in C as well as C++. The motivating reason for using them is that + * for _cairo_atomic_{int,ptr}_get, the compiler is able to see that + * the load is intended to be atomic, as opposed to the __sync_* + * version, below, where the load looks like a plain load. Having + * the load appear atomic to the compiler is particular important for + * tools like ThreadSanitizer so they don't report false positives on + * memory operations that we intend to be atomic. + */ +#if HAVE_CXX11_ATOMIC_PRIMITIVES + +#define HAS_ATOMIC_OPS 1 + +typedef int cairo_atomic_int_t; + +static cairo_always_inline cairo_atomic_int_t +_cairo_atomic_int_get (cairo_atomic_int_t *x) +{ + return __atomic_load_n(x, __ATOMIC_SEQ_CST); +} + +static cairo_always_inline void * +_cairo_atomic_ptr_get (void **x) +{ + return __atomic_load_n(x, __ATOMIC_SEQ_CST); +} + +# define _cairo_atomic_int_inc(x) ((void) __atomic_fetch_add(x, 1, __ATOMIC_SEQ_CST)) +# define _cairo_atomic_int_dec(x) ((void) __atomic_fetch_sub(x, 1, __ATOMIC_SEQ_CST)) +# define _cairo_atomic_int_dec_and_test(x) (__atomic_fetch_sub(x, 1, __ATOMIC_SEQ_CST) == 1) + +#if SIZEOF_VOID_P==SIZEOF_INT +typedef int cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG +typedef long cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG +typedef long long cairo_atomic_intptr_t; +#else +#error No matching integer pointer type +#endif + +static cairo_always_inline cairo_bool_t +_cairo_atomic_int_cmpxchg_impl(cairo_atomic_int_t *x, + cairo_atomic_int_t oldv, + cairo_atomic_int_t newv) +{ + cairo_atomic_int_t expected = oldv; + return __atomic_compare_exchange_n(x, &expected, newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); +} + +#define _cairo_atomic_int_cmpxchg(x, oldv, newv) \ + _cairo_atomic_int_cmpxchg_impl(x, oldv, newv) + +static cairo_always_inline cairo_atomic_int_t +_cairo_atomic_int_cmpxchg_return_old_impl(cairo_atomic_int_t *x, + cairo_atomic_int_t oldv, + cairo_atomic_int_t newv) +{ + cairo_atomic_int_t expected = oldv; + (void) __atomic_compare_exchange_n(x, &expected, newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + return expected; +} + +#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) \ + _cairo_atomic_int_cmpxchg_return_old_impl(x, oldv, newv) + +static cairo_always_inline cairo_bool_t +_cairo_atomic_ptr_cmpxchg_impl(void **x, void *oldv, void *newv) +{ + void *expected = oldv; + return __atomic_compare_exchange_n(x, &expected, newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); +} + +#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + _cairo_atomic_ptr_cmpxchg_impl(x, oldv, newv) + +static cairo_always_inline void * +_cairo_atomic_ptr_cmpxchg_return_old_impl(void **x, void *oldv, void *newv) +{ + void *expected = oldv; + (void) __atomic_compare_exchange_n(x, &expected, newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + return expected; +} + +#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) \ + _cairo_atomic_ptr_cmpxchg_return_old_impl(x, oldv, newv) + +#endif + +#if HAVE_INTEL_ATOMIC_PRIMITIVES + +#define HAS_ATOMIC_OPS 1 + +typedef int cairo_atomic_int_t; + +#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER +static cairo_always_inline cairo_atomic_int_t +_cairo_atomic_int_get (cairo_atomic_int_t *x) +{ + __sync_synchronize (); + return *x; +} + +static cairo_always_inline void * +_cairo_atomic_ptr_get (void **x) +{ + __sync_synchronize (); + return *x; +} +#else +# define _cairo_atomic_int_get(x) (*x) +# define _cairo_atomic_ptr_get(x) (*x) +#endif + +# define _cairo_atomic_int_inc(x) ((void) __sync_fetch_and_add(x, 1)) +# define _cairo_atomic_int_dec(x) ((void) __sync_fetch_and_add(x, -1)) +# define _cairo_atomic_int_dec_and_test(x) (__sync_fetch_and_add(x, -1) == 1) +# define _cairo_atomic_int_cmpxchg(x, oldv, newv) __sync_bool_compare_and_swap (x, oldv, newv) +# define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv) + +#if SIZEOF_VOID_P==SIZEOF_INT +typedef int cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG +typedef long cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG +typedef long long cairo_atomic_intptr_t; +#else +#error No matching integer pointer type +#endif + +# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + __sync_bool_compare_and_swap ((cairo_atomic_intptr_t*)x, (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv) + +# define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) \ + _cairo_atomic_intptr_to_voidptr (__sync_val_compare_and_swap ((cairo_atomic_intptr_t*)x, (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv)) + +#endif + +#if HAVE_LIB_ATOMIC_OPS +#include + +#define HAS_ATOMIC_OPS 1 + +typedef AO_t cairo_atomic_int_t; + +# define _cairo_atomic_int_get(x) (AO_load_full (x)) + +# define _cairo_atomic_int_inc(x) ((void) AO_fetch_and_add1_full(x)) +# define _cairo_atomic_int_dec(x) ((void) AO_fetch_and_sub1_full(x)) +# define _cairo_atomic_int_dec_and_test(x) (AO_fetch_and_sub1_full(x) == 1) +# define _cairo_atomic_int_cmpxchg(x, oldv, newv) AO_compare_and_swap_full(x, oldv, newv) + +#if SIZEOF_VOID_P==SIZEOF_INT +typedef unsigned int cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG +typedef unsigned long cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG +typedef unsigned long long cairo_atomic_intptr_t; +#else +#error No matching integer pointer type +#endif + +# define _cairo_atomic_ptr_get(x) _cairo_atomic_intptr_to_voidptr (AO_load_full (x)) +# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + _cairo_atomic_int_cmpxchg ((cairo_atomic_intptr_t*)(x), (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv) + +#endif + +#if HAVE_OS_ATOMIC_OPS +#include + +#define HAS_ATOMIC_OPS 1 + +typedef int32_t cairo_atomic_int_t; + +# define _cairo_atomic_int_get(x) (OSMemoryBarrier(), *(x)) + +# define _cairo_atomic_int_inc(x) ((void) OSAtomicIncrement32Barrier (x)) +# define _cairo_atomic_int_dec(x) ((void) OSAtomicDecrement32Barrier (x)) +# define _cairo_atomic_int_dec_and_test(x) (OSAtomicDecrement32Barrier (x) == 0) +# define _cairo_atomic_int_cmpxchg(x, oldv, newv) OSAtomicCompareAndSwap32Barrier(oldv, newv, x) + +#if SIZEOF_VOID_P==4 +typedef int32_t cairo_atomic_intptr_t; +# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + OSAtomicCompareAndSwap32Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x) + +#elif SIZEOF_VOID_P==8 +typedef int64_t cairo_atomic_intptr_t; +# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + OSAtomicCompareAndSwap64Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x) + +#else +#error No matching integer pointer type +#endif + +# define _cairo_atomic_ptr_get(x) (OSMemoryBarrier(), *(x)) + +#endif + +#ifndef HAS_ATOMIC_OPS + +#if SIZEOF_VOID_P==SIZEOF_INT +typedef unsigned int cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG +typedef unsigned long cairo_atomic_intptr_t; +#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG +typedef unsigned long long cairo_atomic_intptr_t; +#else +#error No matching integer pointer type +#endif + +typedef cairo_atomic_intptr_t cairo_atomic_int_t; + +cairo_private void +_cairo_atomic_int_inc (cairo_atomic_int_t *x); + +#define _cairo_atomic_int_dec(x) _cairo_atomic_int_dec_and_test(x) + +cairo_private cairo_bool_t +_cairo_atomic_int_dec_and_test (cairo_atomic_int_t *x); + +cairo_private cairo_atomic_int_t +_cairo_atomic_int_cmpxchg_return_old_impl (cairo_atomic_int_t *x, cairo_atomic_int_t oldv, cairo_atomic_int_t newv); + +cairo_private void * +_cairo_atomic_ptr_cmpxchg_return_old_impl (void **x, void *oldv, void *newv); + +#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_int_cmpxchg_return_old_impl (x, oldv, newv) +#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_ptr_cmpxchg_return_old_impl (x, oldv, newv) + +#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER +cairo_private cairo_atomic_int_t +_cairo_atomic_int_get (cairo_atomic_int_t *x); +# define _cairo_atomic_ptr_get(x) (void *) _cairo_atomic_int_get((cairo_atomic_int_t *) x) +#else +# define _cairo_atomic_int_get(x) (*x) +# define _cairo_atomic_ptr_get(x) (*x) +#endif + +#else + +/* Workaround GCC complaining about casts */ +static cairo_always_inline void * +_cairo_atomic_intptr_to_voidptr (cairo_atomic_intptr_t x) +{ + return (void *) x; +} + +static cairo_always_inline cairo_atomic_int_t +_cairo_atomic_int_cmpxchg_return_old_fallback(cairo_atomic_int_t *x, cairo_atomic_int_t oldv, cairo_atomic_int_t newv) +{ + cairo_atomic_int_t curr; + + do { + curr = _cairo_atomic_int_get (x); + } while (curr == oldv && !_cairo_atomic_int_cmpxchg (x, oldv, newv)); + + return curr; +} + +static cairo_always_inline void * +_cairo_atomic_ptr_cmpxchg_return_old_fallback(void **x, void *oldv, void *newv) +{ + void *curr; + + do { + curr = _cairo_atomic_ptr_get (x); + } while (curr == oldv && !_cairo_atomic_ptr_cmpxchg (x, oldv, newv)); + + return curr; +} +#endif + +#ifndef _cairo_atomic_int_cmpxchg_return_old +#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_int_cmpxchg_return_old_fallback (x, oldv, newv) +#endif + +#ifndef _cairo_atomic_ptr_cmpxchg_return_old +#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_ptr_cmpxchg_return_old_fallback (x, oldv, newv) +#endif + +#ifndef _cairo_atomic_int_cmpxchg +#define _cairo_atomic_int_cmpxchg(x, oldv, newv) (_cairo_atomic_int_cmpxchg_return_old (x, oldv, newv) == oldv) +#endif + +#ifndef _cairo_atomic_ptr_cmpxchg +#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) (_cairo_atomic_ptr_cmpxchg_return_old (x, oldv, newv) == oldv) +#endif + +#define _cairo_atomic_uint_get(x) _cairo_atomic_int_get(x) +#define _cairo_atomic_uint_cmpxchg(x, oldv, newv) \ + _cairo_atomic_int_cmpxchg((cairo_atomic_int_t *)x, oldv, newv) + +#define _cairo_status_set_error(status, err) do { \ + int ret__; \ + assert (err < CAIRO_STATUS_LAST_STATUS); \ + /* hide compiler warnings about cairo_status_t != int (gcc treats its as \ + * an unsigned integer instead, and about ignoring the return value. */ \ + ret__ = _cairo_atomic_int_cmpxchg ((cairo_atomic_int_t *) status, CAIRO_STATUS_SUCCESS, err); \ + (void) ret__; \ +} while (0) + +CAIRO_END_DECLS + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-atomic.c b/Build/source/libs/cairo/cairo-src/src/cairo-atomic.c new file mode 100644 index 00000000000..909cfea4925 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-atomic.c @@ -0,0 +1,106 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-atomic-private.h" +#include "cairo-mutex-private.h" + +#ifdef HAS_ATOMIC_OPS +COMPILE_TIME_ASSERT(sizeof(void*) == sizeof(int) || + sizeof(void*) == sizeof(long) || + sizeof(void*) == sizeof(long long)); +#else +void +_cairo_atomic_int_inc (cairo_atomic_intptr_t *x) +{ + CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); + *x += 1; + CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); +} + +cairo_bool_t +_cairo_atomic_int_dec_and_test (cairo_atomic_intptr_t *x) +{ + cairo_bool_t ret; + + CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); + ret = --*x == 0; + CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); + + return ret; +} + +cairo_atomic_intptr_t +_cairo_atomic_int_cmpxchg_return_old_impl (cairo_atomic_intptr_t *x, cairo_atomic_intptr_t oldv, cairo_atomic_intptr_t newv) +{ + cairo_atomic_intptr_t ret; + + CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); + ret = *x; + if (ret == oldv) + *x = newv; + CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); + + return ret; +} + +void * +_cairo_atomic_ptr_cmpxchg_return_old_impl (void **x, void *oldv, void *newv) +{ + void *ret; + + CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); + ret = *x; + if (ret == oldv) + *x = newv; + CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); + + return ret; +} + +#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER +cairo_atomic_intptr_t +_cairo_atomic_int_get (cairo_atomic_intptr_t *x) +{ + cairo_atomic_intptr_t ret; + + CAIRO_MUTEX_LOCK (_cairo_atomic_mutex); + ret = *x; + CAIRO_MUTEX_UNLOCK (_cairo_atomic_mutex); + + return ret; +} +#endif + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-backend-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-backend-private.h new file mode 100644 index 00000000000..b05eca59ab3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-backend-private.h @@ -0,0 +1,201 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_BACKEND_PRIVATE_H +#define CAIRO_BACKEND_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-private.h" + +typedef enum _cairo_backend_type { + CAIRO_TYPE_DEFAULT, + CAIRO_TYPE_SKIA, +} cairo_backend_type_t; + +struct _cairo_backend { + cairo_backend_type_t type; + void (*destroy) (void *cr); + + cairo_surface_t *(*get_original_target) (void *cr); + cairo_surface_t *(*get_current_target) (void *cr); + + cairo_status_t (*save) (void *cr); + cairo_status_t (*restore) (void *cr); + + cairo_status_t (*push_group) (void *cr, cairo_content_t content); + cairo_pattern_t *(*pop_group) (void *cr); + + cairo_status_t (*set_source_rgba) (void *cr, double red, double green, double blue, double alpha); + cairo_status_t (*set_source_surface) (void *cr, cairo_surface_t *surface, double x, double y); + cairo_status_t (*set_source) (void *cr, cairo_pattern_t *source); + cairo_pattern_t *(*get_source) (void *cr); + + cairo_status_t (*set_antialias) (void *cr, cairo_antialias_t antialias); + cairo_status_t (*set_dash) (void *cr, const double *dashes, int num_dashes, double offset); + cairo_status_t (*set_fill_rule) (void *cr, cairo_fill_rule_t fill_rule); + cairo_status_t (*set_line_cap) (void *cr, cairo_line_cap_t line_cap); + cairo_status_t (*set_line_join) (void *cr, cairo_line_join_t line_join); + cairo_status_t (*set_line_width) (void *cr, double line_width); + cairo_status_t (*set_miter_limit) (void *cr, double limit); + cairo_status_t (*set_opacity) (void *cr, double opacity); + cairo_status_t (*set_operator) (void *cr, cairo_operator_t op); + cairo_status_t (*set_tolerance) (void *cr, double tolerance); + + cairo_antialias_t (*get_antialias) (void *cr); + void (*get_dash) (void *cr, double *dashes, int *num_dashes, double *offset); + cairo_fill_rule_t (*get_fill_rule) (void *cr); + cairo_line_cap_t (*get_line_cap) (void *cr); + cairo_line_join_t (*get_line_join) (void *cr); + double (*get_line_width) (void *cr); + double (*get_miter_limit) (void *cr); + double (*get_opacity) (void *cr); + cairo_operator_t (*get_operator) (void *cr); + double (*get_tolerance) (void *cr); + + cairo_status_t (*translate) (void *cr, double tx, double ty); + cairo_status_t (*scale) (void *cr, double sx, double sy); + cairo_status_t (*rotate) (void *cr, double theta); + cairo_status_t (*transform) (void *cr, const cairo_matrix_t *matrix); + cairo_status_t (*set_matrix) (void *cr, const cairo_matrix_t *matrix); + cairo_status_t (*set_identity_matrix) (void *cr); + void (*get_matrix) (void *cr, cairo_matrix_t *matrix); + + void (*user_to_device) (void *cr, double *x, double *y); + void (*user_to_device_distance) (void *cr, double *x, double *y); + void (*device_to_user) (void *cr, double *x, double *y); + void (*device_to_user_distance) (void *cr, double *x, double *y); + + void (*user_to_backend) (void *cr, double *x, double *y); + void (*user_to_backend_distance) (void *cr, double *x, double *y); + void (*backend_to_user) (void *cr, double *x, double *y); + void (*backend_to_user_distance) (void *cr, double *x, double *y); + + cairo_status_t (*new_path) (void *cr); + cairo_status_t (*new_sub_path) (void *cr); + cairo_status_t (*move_to) (void *cr, double x, double y); + cairo_status_t (*rel_move_to) (void *cr, double dx, double dy); + cairo_status_t (*line_to) (void *cr, double x, double y); + cairo_status_t (*rel_line_to) (void *cr, double dx, double dy); + cairo_status_t (*curve_to) (void *cr, double x1, double y1, double x2, double y2, double x3, double y3); + cairo_status_t (*rel_curve_to) (void *cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3); + cairo_status_t (*arc_to) (void *cr, double x1, double y1, double x2, double y2, double radius); + cairo_status_t (*rel_arc_to) (void *cr, double dx1, double dy1, double dx2, double dy2, double radius); + cairo_status_t (*close_path) (void *cr); + + cairo_status_t (*arc) (void *cr, double xc, double yc, double radius, double angle1, double angle2, cairo_bool_t forward); + cairo_status_t (*rectangle) (void *cr, double x, double y, double width, double height); + + void (*path_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); + cairo_bool_t (*has_current_point) (void *cr); + cairo_bool_t (*get_current_point) (void *cr, double *x, double *y); + + cairo_path_t *(*copy_path) (void *cr); + cairo_path_t *(*copy_path_flat) (void *cr); + cairo_status_t (*append_path) (void *cr, const cairo_path_t *path); + + cairo_status_t (*stroke_to_path) (void *cr); + + cairo_status_t (*clip) (void *cr); + cairo_status_t (*clip_preserve) (void *cr); + cairo_status_t (*in_clip) (void *cr, double x, double y, cairo_bool_t *inside); + cairo_status_t (*clip_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); + cairo_status_t (*reset_clip) (void *cr); + cairo_rectangle_list_t *(*clip_copy_rectangle_list) (void *cr); + + cairo_status_t (*paint) (void *cr); + cairo_status_t (*paint_with_alpha) (void *cr, double opacity); + cairo_status_t (*mask) (void *cr, cairo_pattern_t *pattern); + + cairo_status_t (*stroke) (void *cr); + cairo_status_t (*stroke_preserve) (void *cr); + cairo_status_t (*in_stroke) (void *cr, double x, double y, cairo_bool_t *inside); + cairo_status_t (*stroke_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); + + cairo_status_t (*fill) (void *cr); + cairo_status_t (*fill_preserve) (void *cr); + cairo_status_t (*in_fill) (void *cr, double x, double y, cairo_bool_t *inside); + cairo_status_t (*fill_extents) (void *cr, double *x1, double *y1, double *x2, double *y2); + + cairo_status_t (*set_font_face) (void *cr, cairo_font_face_t *font_face); + cairo_font_face_t *(*get_font_face) (void *cr); + cairo_status_t (*set_font_size) (void *cr, double size); + cairo_status_t (*set_font_matrix) (void *cr, const cairo_matrix_t *matrix); + void (*get_font_matrix) (void *cr, cairo_matrix_t *matrix); + cairo_status_t (*set_font_options) (void *cr, const cairo_font_options_t *options); + void (*get_font_options) (void *cr, cairo_font_options_t *options); + cairo_status_t (*set_scaled_font) (void *cr, cairo_scaled_font_t *scaled_font); + cairo_scaled_font_t *(*get_scaled_font) (void *cr); + cairo_status_t (*font_extents) (void *cr, cairo_font_extents_t *extents); + + cairo_status_t (*glyphs) (void *cr, + const cairo_glyph_t *glyphs, int num_glyphs, + cairo_glyph_text_info_t *info); + cairo_status_t (*glyph_path) (void *cr, + const cairo_glyph_t *glyphs, int num_glyphs); + + cairo_status_t (*glyph_extents) (void *cr, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents); + + cairo_status_t (*copy_page) (void *cr); + cairo_status_t (*show_page) (void *cr); +}; + +static inline void +_cairo_backend_to_user (cairo_t *cr, double *x, double *y) +{ + cr->backend->backend_to_user (cr, x, y); +} + +static inline void +_cairo_backend_to_user_distance (cairo_t *cr, double *x, double *y) +{ + cr->backend->backend_to_user_distance (cr, x, y); +} + +static inline void +_cairo_user_to_backend (cairo_t *cr, double *x, double *y) +{ + cr->backend->user_to_backend (cr, x, y); +} + +static inline void +_cairo_user_to_backend_distance (cairo_t *cr, double *x, double *y) +{ + cr->backend->user_to_backend_distance (cr, x, y); +} + +#endif /* CAIRO_BACKEND_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-base64-stream.c b/Build/source/libs/cairo/cairo-src/src/cairo-base64-stream.c new file mode 100644 index 00000000000..636431372b5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-base64-stream.c @@ -0,0 +1,144 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005-2007 Emmanuel Pacaud + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Author(s): + * Kristian Høgsberg + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-error-private.h" +#include "cairo-output-stream-private.h" + +typedef struct _cairo_base64_stream { + cairo_output_stream_t base; + cairo_output_stream_t *output; + unsigned int in_mem; + unsigned int trailing; + unsigned char src[3]; +} cairo_base64_stream_t; + +static char const base64_table[64] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +static cairo_status_t +_cairo_base64_stream_write (cairo_output_stream_t *base, + const unsigned char *data, + unsigned int length) +{ + cairo_base64_stream_t * stream = (cairo_base64_stream_t *) base; + unsigned char *src = stream->src; + unsigned int i; + + if (stream->in_mem + length < 3) { + for (i = 0; i < length; i++) { + src[i + stream->in_mem] = *data++; + } + stream->in_mem += length; + return CAIRO_STATUS_SUCCESS; + } + + do { + unsigned char dst[4]; + + for (i = stream->in_mem; i < 3; i++) { + src[i] = *data++; + length--; + } + stream->in_mem = 0; + + dst[0] = base64_table[src[0] >> 2]; + dst[1] = base64_table[(src[0] & 0x03) << 4 | src[1] >> 4]; + dst[2] = base64_table[(src[1] & 0x0f) << 2 | src[2] >> 6]; + dst[3] = base64_table[src[2] & 0xfc >> 2]; + /* Special case for the last missing bits */ + switch (stream->trailing) { + case 2: + dst[2] = '='; + case 1: + dst[3] = '='; + default: + break; + } + _cairo_output_stream_write (stream->output, dst, 4); + } while (length >= 3); + + for (i = 0; i < length; i++) { + src[i] = *data++; + } + stream->in_mem = length; + + return _cairo_output_stream_get_status (stream->output); +} + +static cairo_status_t +_cairo_base64_stream_close (cairo_output_stream_t *base) +{ + cairo_base64_stream_t *stream = (cairo_base64_stream_t *) base; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + if (stream->in_mem > 0) { + memset (stream->src + stream->in_mem, 0, 3 - stream->in_mem); + stream->trailing = 3 - stream->in_mem; + stream->in_mem = 3; + status = _cairo_base64_stream_write (base, NULL, 0); + } + + return status; +} + +cairo_output_stream_t * +_cairo_base64_stream_create (cairo_output_stream_t *output) +{ + cairo_base64_stream_t *stream; + + if (output->status) + return _cairo_output_stream_create_in_error (output->status); + + stream = malloc (sizeof (cairo_base64_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + _cairo_base64_stream_write, + NULL, + _cairo_base64_stream_close); + + stream->output = output; + stream->in_mem = 0; + stream->trailing = 0; + + return &stream->base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-base85-stream.c b/Build/source/libs/cairo/cairo-src/src/cairo-base85-stream.c new file mode 100644 index 00000000000..f81affb49ea --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-base85-stream.c @@ -0,0 +1,131 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Author(s): + * Kristian Høgsberg + */ + +#include "cairoint.h" +#include "cairo-error-private.h" +#include "cairo-output-stream-private.h" + +typedef struct _cairo_base85_stream { + cairo_output_stream_t base; + cairo_output_stream_t *output; + unsigned char four_tuple[4]; + int pending; +} cairo_base85_stream_t; + +static void +_expand_four_tuple_to_five (unsigned char four_tuple[4], + unsigned char five_tuple[5], + cairo_bool_t *all_zero) +{ + uint32_t value; + int digit, i; + + value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3]; + if (all_zero) + *all_zero = TRUE; + for (i = 0; i < 5; i++) { + digit = value % 85; + if (digit != 0 && all_zero) + *all_zero = FALSE; + five_tuple[4-i] = digit + 33; + value = value / 85; + } +} + +static cairo_status_t +_cairo_base85_stream_write (cairo_output_stream_t *base, + const unsigned char *data, + unsigned int length) +{ + cairo_base85_stream_t *stream = (cairo_base85_stream_t *) base; + const unsigned char *ptr = data; + unsigned char five_tuple[5]; + cairo_bool_t is_zero; + + while (length) { + stream->four_tuple[stream->pending++] = *ptr++; + length--; + if (stream->pending == 4) { + _expand_four_tuple_to_five (stream->four_tuple, five_tuple, &is_zero); + if (is_zero) + _cairo_output_stream_write (stream->output, "z", 1); + else + _cairo_output_stream_write (stream->output, five_tuple, 5); + stream->pending = 0; + } + } + + return _cairo_output_stream_get_status (stream->output); +} + +static cairo_status_t +_cairo_base85_stream_close (cairo_output_stream_t *base) +{ + cairo_base85_stream_t *stream = (cairo_base85_stream_t *) base; + unsigned char five_tuple[5]; + + if (stream->pending) { + memset (stream->four_tuple + stream->pending, 0, 4 - stream->pending); + _expand_four_tuple_to_five (stream->four_tuple, five_tuple, NULL); + _cairo_output_stream_write (stream->output, five_tuple, stream->pending + 1); + } + + return _cairo_output_stream_get_status (stream->output); +} + +cairo_output_stream_t * +_cairo_base85_stream_create (cairo_output_stream_t *output) +{ + cairo_base85_stream_t *stream; + + if (output->status) + return _cairo_output_stream_create_in_error (output->status); + + stream = malloc (sizeof (cairo_base85_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + _cairo_base85_stream_write, + NULL, + _cairo_base85_stream_close); + stream->output = output; + stream->pending = 0; + + return &stream->base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectangular.c b/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectangular.c new file mode 100644 index 00000000000..5541bdc3a2d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectangular.c @@ -0,0 +1,884 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-combsort-inline.h" +#include "cairo-list-private.h" +#include "cairo-traps-private.h" + +#include + +typedef struct _rectangle rectangle_t; +typedef struct _edge edge_t; + +struct _edge { + edge_t *next, *prev; + edge_t *right; + cairo_fixed_t x, top; + int dir; +}; + +struct _rectangle { + edge_t left, right; + int32_t top, bottom; +}; + +#define UNROLL3(x) x x x + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef struct _sweep_line { + rectangle_t **rectangles; + rectangle_t **stop; + edge_t head, tail, *insert, *cursor; + int32_t current_y; + int32_t last_y; + int stop_size; + + int32_t insert_x; + cairo_fill_rule_t fill_rule; + + cairo_bool_t do_traps; + void *container; + + jmp_buf unwind; +} sweep_line_t; + +#define DEBUG_TRAPS 0 + +#if DEBUG_TRAPS +static void +dump_traps (cairo_traps_t *traps, const char *filename) +{ + FILE *file; + int n; + + if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) + return; + + file = fopen (filename, "a"); + if (file != NULL) { + for (n = 0; n < traps->num_traps; n++) { + fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", + traps->traps[n].top, + traps->traps[n].bottom, + traps->traps[n].left.p1.x, + traps->traps[n].left.p1.y, + traps->traps[n].left.p2.x, + traps->traps[n].left.p2.y, + traps->traps[n].right.p1.x, + traps->traps[n].right.p1.y, + traps->traps[n].right.p2.x, + traps->traps[n].right.p2.y); + } + fprintf (file, "\n"); + fclose (file); + } +} +#else +#define dump_traps(traps, filename) +#endif + +static inline int +rectangle_compare_start (const rectangle_t *a, + const rectangle_t *b) +{ + return a->top - b->top; +} + +static inline int +rectangle_compare_stop (const rectangle_t *a, + const rectangle_t *b) +{ + return a->bottom - b->bottom; +} + +static inline void +pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle) +{ + rectangle_t **elements; + int i, parent; + + elements = sweep->stop; + for (i = ++sweep->stop_size; + i != PQ_FIRST_ENTRY && + rectangle_compare_stop (rectangle, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = rectangle; +} + +static inline void +rectangle_pop_stop (sweep_line_t *sweep) +{ + rectangle_t **elements = sweep->stop; + rectangle_t *tail; + int child, i; + + tail = elements[sweep->stop_size--]; + if (sweep->stop_size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= sweep->stop_size; + i = child) + { + if (child != sweep->stop_size && + rectangle_compare_stop (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (rectangle_compare_stop (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline rectangle_t * +rectangle_pop_start (sweep_line_t *sweep_line) +{ + return *sweep_line->rectangles++; +} + +static inline rectangle_t * +rectangle_peek_stop (sweep_line_t *sweep_line) +{ + return sweep_line->stop[PQ_FIRST_ENTRY]; +} + +CAIRO_COMBSORT_DECLARE (_rectangle_sort, + rectangle_t *, + rectangle_compare_start) + +static void +sweep_line_init (sweep_line_t *sweep_line, + rectangle_t **rectangles, + int num_rectangles, + cairo_fill_rule_t fill_rule, + cairo_bool_t do_traps, + void *container) +{ + rectangles[-2] = NULL; + rectangles[-1] = NULL; + rectangles[num_rectangles] = NULL; + sweep_line->rectangles = rectangles; + sweep_line->stop = rectangles - 2; + sweep_line->stop_size = 0; + + sweep_line->insert = NULL; + sweep_line->insert_x = INT_MAX; + sweep_line->cursor = &sweep_line->tail; + + sweep_line->head.dir = 0; + sweep_line->head.x = INT32_MIN; + sweep_line->head.right = NULL; + sweep_line->head.prev = NULL; + sweep_line->head.next = &sweep_line->tail; + sweep_line->tail.prev = &sweep_line->head; + sweep_line->tail.next = NULL; + sweep_line->tail.right = NULL; + sweep_line->tail.x = INT32_MAX; + sweep_line->tail.dir = 0; + + sweep_line->current_y = INT32_MIN; + sweep_line->last_y = INT32_MIN; + + sweep_line->fill_rule = fill_rule; + sweep_line->container = container; + sweep_line->do_traps = do_traps; +} + +static void +edge_end_box (sweep_line_t *sweep_line, edge_t *left, int32_t bot) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + /* Only emit (trivial) non-degenerate trapezoids with positive height. */ + if (likely (left->top < bot)) { + if (sweep_line->do_traps) { + cairo_line_t _left = { + { left->x, left->top }, + { left->x, bot }, + }, _right = { + { left->right->x, left->top }, + { left->right->x, bot }, + }; + _cairo_traps_add_trap (sweep_line->container, left->top, bot, &_left, &_right); + status = _cairo_traps_status ((cairo_traps_t *) sweep_line->container); + } else { + cairo_box_t box; + + box.p1.x = left->x; + box.p1.y = left->top; + box.p2.x = left->right->x; + box.p2.y = bot; + + status = _cairo_boxes_add (sweep_line->container, + CAIRO_ANTIALIAS_DEFAULT, + &box); + } + } + if (unlikely (status)) + longjmp (sweep_line->unwind, status); + + left->right = NULL; +} + +/* Start a new trapezoid at the given top y coordinate, whose edges + * are `edge' and `edge->next'. If `edge' already has a trapezoid, + * then either add it to the traps in `traps', if the trapezoid's + * right edge differs from `edge->next', or do nothing if the new + * trapezoid would be a continuation of the existing one. */ +static inline void +edge_start_or_continue_box (sweep_line_t *sweep_line, + edge_t *left, + edge_t *right, + int top) +{ + if (left->right == right) + return; + + if (left->right != NULL) { + if (left->right->x == right->x) { + /* continuation on right, so just swap edges */ + left->right = right; + return; + } + + edge_end_box (sweep_line, left, top); + } + + if (left->x != right->x) { + left->top = top; + left->right = right; + } +} +/* + * Merge two sorted edge lists. + * Input: + * - head_a: The head of the first list. + * - head_b: The head of the second list; head_b cannot be NULL. + * Output: + * Returns the head of the merged list. + * + * Implementation notes: + * To make it fast (in particular, to reduce to an insertion sort whenever + * one of the two input lists only has a single element) we iterate through + * a list until its head becomes greater than the head of the other list, + * then we switch their roles. As soon as one of the two lists is empty, we + * just attach the other one to the current list and exit. + * Writes to memory are only needed to "switch" lists (as it also requires + * attaching to the output list the list which we will be iterating next) and + * to attach the last non-empty list. + */ +static edge_t * +merge_sorted_edges (edge_t *head_a, edge_t *head_b) +{ + edge_t *head, *prev; + int32_t x; + + prev = head_a->prev; + if (head_a->x <= head_b->x) { + head = head_a; + } else { + head_b->prev = prev; + head = head_b; + goto start_with_b; + } + + do { + x = head_b->x; + while (head_a != NULL && head_a->x <= x) { + prev = head_a; + head_a = head_a->next; + } + + head_b->prev = prev; + prev->next = head_b; + if (head_a == NULL) + return head; + +start_with_b: + x = head_a->x; + while (head_b != NULL && head_b->x <= x) { + prev = head_b; + head_b = head_b->next; + } + + head_a->prev = prev; + prev->next = head_a; + if (head_b == NULL) + return head; + } while (1); +} + +/* + * Sort (part of) a list. + * Input: + * - list: The list to be sorted; list cannot be NULL. + * - limit: Recursion limit. + * Output: + * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the + * input list; if the input list has fewer elements, head_out be a sorted list + * containing all the elements of the input list. + * Returns the head of the list of unprocessed elements (NULL if the sorted list contains + * all the elements of the input list). + * + * Implementation notes: + * Special case single element list, unroll/inline the sorting of the first two elements. + * Some tail recursion is used since we iterate on the bottom-up solution of the problem + * (we start with a small sorted list and keep merging other lists of the same size to it). + */ +static edge_t * +sort_edges (edge_t *list, + unsigned int level, + edge_t **head_out) +{ + edge_t *head_other, *remaining; + unsigned int i; + + head_other = list->next; + + if (head_other == NULL) { + *head_out = list; + return NULL; + } + + remaining = head_other->next; + if (list->x <= head_other->x) { + *head_out = list; + head_other->next = NULL; + } else { + *head_out = head_other; + head_other->prev = list->prev; + head_other->next = list; + list->prev = head_other; + list->next = NULL; + } + + for (i = 0; i < level && remaining; i++) { + remaining = sort_edges (remaining, i, &head_other); + *head_out = merge_sorted_edges (*head_out, head_other); + } + + return remaining; +} + +static edge_t * +merge_unsorted_edges (edge_t *head, edge_t *unsorted) +{ + sort_edges (unsorted, UINT_MAX, &unsorted); + return merge_sorted_edges (head, unsorted); +} + +static void +active_edges_insert (sweep_line_t *sweep) +{ + edge_t *prev; + int x; + + x = sweep->insert_x; + prev = sweep->cursor; + if (prev->x > x) { + do { + prev = prev->prev; + } while (prev->x > x); + } else { + while (prev->next->x < x) + prev = prev->next; + } + + prev->next = merge_unsorted_edges (prev->next, sweep->insert); + sweep->cursor = sweep->insert; + sweep->insert = NULL; + sweep->insert_x = INT_MAX; +} + +static inline void +active_edges_to_traps (sweep_line_t *sweep) +{ + int top = sweep->current_y; + edge_t *pos; + + if (sweep->last_y == sweep->current_y) + return; + + if (sweep->insert) + active_edges_insert (sweep); + + pos = sweep->head.next; + if (pos == &sweep->tail) + return; + + if (sweep->fill_rule == CAIRO_FILL_RULE_WINDING) { + do { + edge_t *left, *right; + int winding; + + left = pos; + winding = left->dir; + + right = left->next; + + /* Check if there is a co-linear edge with an existing trap */ + while (right->x == left->x) { + if (right->right != NULL) { + assert (left->right == NULL); + /* continuation on left */ + left->top = right->top; + left->right = right->right; + right->right = NULL; + } + winding += right->dir; + right = right->next; + } + + if (winding == 0) { + if (left->right != NULL) + edge_end_box (sweep, left, top); + pos = right; + continue; + } + + do { + /* End all subsumed traps */ + if (unlikely (right->right != NULL)) + edge_end_box (sweep, right, top); + + /* Greedily search for the closing edge, so that we generate + * the * maximal span width with the minimal number of + * boxes. + */ + winding += right->dir; + if (winding == 0 && right->x != right->next->x) + break; + + right = right->next; + } while (TRUE); + + edge_start_or_continue_box (sweep, left, right, top); + + pos = right->next; + } while (pos != &sweep->tail); + } else { + do { + edge_t *right = pos->next; + int count = 0; + + do { + /* End all subsumed traps */ + if (unlikely (right->right != NULL)) + edge_end_box (sweep, right, top); + + /* skip co-linear edges */ + if (++count & 1 && right->x != right->next->x) + break; + + right = right->next; + } while (TRUE); + + edge_start_or_continue_box (sweep, pos, right, top); + + pos = right->next; + } while (pos != &sweep->tail); + } + + sweep->last_y = sweep->current_y; +} + +static inline void +sweep_line_delete_edge (sweep_line_t *sweep, edge_t *edge) +{ + if (edge->right != NULL) { + edge_t *next = edge->next; + if (next->x == edge->x) { + next->top = edge->top; + next->right = edge->right; + } else + edge_end_box (sweep, edge, sweep->current_y); + } + + if (sweep->cursor == edge) + sweep->cursor = edge->prev; + + edge->prev->next = edge->next; + edge->next->prev = edge->prev; +} + +static inline cairo_bool_t +sweep_line_delete (sweep_line_t *sweep, rectangle_t *rectangle) +{ + cairo_bool_t update; + + update = TRUE; + if (sweep->fill_rule == CAIRO_FILL_RULE_WINDING && + rectangle->left.prev->dir == rectangle->left.dir) + { + update = rectangle->left.next != &rectangle->right; + } + + sweep_line_delete_edge (sweep, &rectangle->left); + sweep_line_delete_edge (sweep, &rectangle->right); + + rectangle_pop_stop (sweep); + return update; +} + +static inline void +sweep_line_insert (sweep_line_t *sweep, rectangle_t *rectangle) +{ + if (sweep->insert) + sweep->insert->prev = &rectangle->right; + rectangle->right.next = sweep->insert; + rectangle->right.prev = &rectangle->left; + rectangle->left.next = &rectangle->right; + rectangle->left.prev = NULL; + sweep->insert = &rectangle->left; + if (rectangle->left.x < sweep->insert_x) + sweep->insert_x = rectangle->left.x; + + pqueue_push (sweep, rectangle); +} + +static cairo_status_t +_cairo_bentley_ottmann_tessellate_rectangular (rectangle_t **rectangles, + int num_rectangles, + cairo_fill_rule_t fill_rule, + cairo_bool_t do_traps, + void *container) +{ + sweep_line_t sweep_line; + rectangle_t *rectangle; + cairo_status_t status; + cairo_bool_t update = FALSE; + + sweep_line_init (&sweep_line, + rectangles, num_rectangles, + fill_rule, + do_traps, container); + if ((status = setjmp (sweep_line.unwind))) + return status; + + rectangle = rectangle_pop_start (&sweep_line); + do { + if (rectangle->top != sweep_line.current_y) { + rectangle_t *stop; + + stop = rectangle_peek_stop (&sweep_line); + while (stop != NULL && stop->bottom < rectangle->top) { + if (stop->bottom != sweep_line.current_y) { + if (update) { + active_edges_to_traps (&sweep_line); + update = FALSE; + } + + sweep_line.current_y = stop->bottom; + } + + update |= sweep_line_delete (&sweep_line, stop); + stop = rectangle_peek_stop (&sweep_line); + } + + if (update) { + active_edges_to_traps (&sweep_line); + update = FALSE; + } + + sweep_line.current_y = rectangle->top; + } + + do { + sweep_line_insert (&sweep_line, rectangle); + } while ((rectangle = rectangle_pop_start (&sweep_line)) != NULL && + sweep_line.current_y == rectangle->top); + update = TRUE; + } while (rectangle); + + while ((rectangle = rectangle_peek_stop (&sweep_line)) != NULL) { + if (rectangle->bottom != sweep_line.current_y) { + if (update) { + active_edges_to_traps (&sweep_line); + update = FALSE; + } + sweep_line.current_y = rectangle->bottom; + } + + update |= sweep_line_delete (&sweep_line, rectangle); + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_bentley_ottmann_tessellate_rectangular_traps (cairo_traps_t *traps, + cairo_fill_rule_t fill_rule) +{ + rectangle_t stack_rectangles[CAIRO_STACK_ARRAY_LENGTH (rectangle_t)]; + rectangle_t *stack_rectangles_ptrs[ARRAY_LENGTH (stack_rectangles) + 3]; + rectangle_t *rectangles, **rectangles_ptrs; + cairo_status_t status; + int i; + + if (unlikely (traps->num_traps <= 1)) + return CAIRO_STATUS_SUCCESS; + + assert (traps->is_rectangular); + + dump_traps (traps, "bo-rects-traps-in.txt"); + + rectangles = stack_rectangles; + rectangles_ptrs = stack_rectangles_ptrs; + if (traps->num_traps > ARRAY_LENGTH (stack_rectangles)) { + rectangles = _cairo_malloc_ab_plus_c (traps->num_traps, + sizeof (rectangle_t) + + sizeof (rectangle_t *), + 3*sizeof (rectangle_t *)); + if (unlikely (rectangles == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + rectangles_ptrs = (rectangle_t **) (rectangles + traps->num_traps); + } + + for (i = 0; i < traps->num_traps; i++) { + if (traps->traps[i].left.p1.x < traps->traps[i].right.p1.x) { + rectangles[i].left.x = traps->traps[i].left.p1.x; + rectangles[i].left.dir = 1; + + rectangles[i].right.x = traps->traps[i].right.p1.x; + rectangles[i].right.dir = -1; + } else { + rectangles[i].right.x = traps->traps[i].left.p1.x; + rectangles[i].right.dir = 1; + + rectangles[i].left.x = traps->traps[i].right.p1.x; + rectangles[i].left.dir = -1; + } + + rectangles[i].left.right = NULL; + rectangles[i].right.right = NULL; + + rectangles[i].top = traps->traps[i].top; + rectangles[i].bottom = traps->traps[i].bottom; + + rectangles_ptrs[i+2] = &rectangles[i]; + } + /* XXX incremental sort */ + _rectangle_sort (rectangles_ptrs+2, i); + + _cairo_traps_clear (traps); + status = _cairo_bentley_ottmann_tessellate_rectangular (rectangles_ptrs+2, i, + fill_rule, + TRUE, traps); + traps->is_rectilinear = TRUE; + traps->is_rectangular = TRUE; + + if (rectangles != stack_rectangles) + free (rectangles); + + dump_traps (traps, "bo-rects-traps-out.txt"); + + return status; +} + +cairo_status_t +_cairo_bentley_ottmann_tessellate_boxes (const cairo_boxes_t *in, + cairo_fill_rule_t fill_rule, + cairo_boxes_t *out) +{ + rectangle_t stack_rectangles[CAIRO_STACK_ARRAY_LENGTH (rectangle_t)]; + rectangle_t *stack_rectangles_ptrs[ARRAY_LENGTH (stack_rectangles) + 3]; + rectangle_t *rectangles, **rectangles_ptrs; + rectangle_t *stack_rectangles_chain[CAIRO_STACK_ARRAY_LENGTH (rectangle_t *) ]; + rectangle_t **rectangles_chain = NULL; + const struct _cairo_boxes_chunk *chunk; + cairo_status_t status; + int i, j, y_min, y_max; + + if (unlikely (in->num_boxes == 0)) { + _cairo_boxes_clear (out); + return CAIRO_STATUS_SUCCESS; + } + + if (in->num_boxes == 1) { + if (in == out) { + cairo_box_t *box = &in->chunks.base[0]; + + if (box->p1.x > box->p2.x) { + cairo_fixed_t tmp = box->p1.x; + box->p1.x = box->p2.x; + box->p2.x = tmp; + } + } else { + cairo_box_t box = in->chunks.base[0]; + + if (box.p1.x > box.p2.x) { + cairo_fixed_t tmp = box.p1.x; + box.p1.x = box.p2.x; + box.p2.x = tmp; + } + + _cairo_boxes_clear (out); + status = _cairo_boxes_add (out, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_STATUS_SUCCESS); + } + return CAIRO_STATUS_SUCCESS; + } + + y_min = INT_MAX; y_max = INT_MIN; + for (chunk = &in->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box = chunk->base; + for (i = 0; i < chunk->count; i++) { + if (box[i].p1.y < y_min) + y_min = box[i].p1.y; + if (box[i].p1.y > y_max) + y_max = box[i].p1.y; + } + } + y_min = _cairo_fixed_integer_floor (y_min); + y_max = _cairo_fixed_integer_floor (y_max) + 1; + y_max -= y_min; + + if (y_max < in->num_boxes) { + rectangles_chain = stack_rectangles_chain; + if (y_max > ARRAY_LENGTH (stack_rectangles_chain)) { + rectangles_chain = _cairo_malloc_ab (y_max, sizeof (rectangle_t *)); + if (unlikely (rectangles_chain == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + memset (rectangles_chain, 0, y_max * sizeof (rectangle_t*)); + } + + rectangles = stack_rectangles; + rectangles_ptrs = stack_rectangles_ptrs; + if (in->num_boxes > ARRAY_LENGTH (stack_rectangles)) { + rectangles = _cairo_malloc_ab_plus_c (in->num_boxes, + sizeof (rectangle_t) + + sizeof (rectangle_t *), + 3*sizeof (rectangle_t *)); + if (unlikely (rectangles == NULL)) { + if (rectangles_chain != stack_rectangles_chain) + free (rectangles_chain); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + rectangles_ptrs = (rectangle_t **) (rectangles + in->num_boxes); + } + + j = 0; + for (chunk = &in->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box = chunk->base; + for (i = 0; i < chunk->count; i++) { + int h; + + if (box[i].p1.x < box[i].p2.x) { + rectangles[j].left.x = box[i].p1.x; + rectangles[j].left.dir = 1; + + rectangles[j].right.x = box[i].p2.x; + rectangles[j].right.dir = -1; + } else { + rectangles[j].right.x = box[i].p1.x; + rectangles[j].right.dir = 1; + + rectangles[j].left.x = box[i].p2.x; + rectangles[j].left.dir = -1; + } + + rectangles[j].left.right = NULL; + rectangles[j].right.right = NULL; + + rectangles[j].top = box[i].p1.y; + rectangles[j].bottom = box[i].p2.y; + + if (rectangles_chain) { + h = _cairo_fixed_integer_floor (box[i].p1.y) - y_min; + rectangles[j].left.next = (edge_t *)rectangles_chain[h]; + rectangles_chain[h] = &rectangles[j]; + } else { + rectangles_ptrs[j+2] = &rectangles[j]; + } + j++; + } + } + + if (rectangles_chain) { + j = 2; + for (y_min = 0; y_min < y_max; y_min++) { + rectangle_t *r; + int start = j; + for (r = rectangles_chain[y_min]; r; r = (rectangle_t *)r->left.next) + rectangles_ptrs[j++] = r; + if (j > start + 1) + _rectangle_sort (rectangles_ptrs + start, j - start); + } + + if (rectangles_chain != stack_rectangles_chain) + free (rectangles_chain); + + j -= 2; + } else { + _rectangle_sort (rectangles_ptrs + 2, j); + } + + _cairo_boxes_clear (out); + status = _cairo_bentley_ottmann_tessellate_rectangular (rectangles_ptrs+2, j, + fill_rule, + FALSE, out); + if (rectangles != stack_rectangles) + free (rectangles); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectilinear.c b/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectilinear.c new file mode 100644 index 00000000000..7c0be69b712 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann-rectilinear.c @@ -0,0 +1,600 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-boxes-private.h" +#include "cairo-combsort-inline.h" +#include "cairo-error-private.h" +#include "cairo-traps-private.h" + +typedef struct _cairo_bo_edge cairo_bo_edge_t; +typedef struct _cairo_bo_trap cairo_bo_trap_t; + +/* A deferred trapezoid of an edge */ +struct _cairo_bo_trap { + cairo_bo_edge_t *right; + int32_t top; +}; + +struct _cairo_bo_edge { + cairo_edge_t edge; + cairo_bo_edge_t *prev; + cairo_bo_edge_t *next; + cairo_bo_trap_t deferred_trap; +}; + +typedef enum { + CAIRO_BO_EVENT_TYPE_START, + CAIRO_BO_EVENT_TYPE_STOP +} cairo_bo_event_type_t; + +typedef struct _cairo_bo_event { + cairo_bo_event_type_t type; + cairo_point_t point; + cairo_bo_edge_t *edge; +} cairo_bo_event_t; + +typedef struct _cairo_bo_sweep_line { + cairo_bo_event_t **events; + cairo_bo_edge_t *head; + cairo_bo_edge_t *stopped; + int32_t current_y; + cairo_bo_edge_t *current_edge; +} cairo_bo_sweep_line_t; + +static inline int +_cairo_point_compare (const cairo_point_t *a, + const cairo_point_t *b) +{ + int cmp; + + cmp = a->y - b->y; + if (likely (cmp)) + return cmp; + + return a->x - b->x; +} + +static inline int +_cairo_bo_edge_compare (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + int cmp; + + cmp = a->edge.line.p1.x - b->edge.line.p1.x; + if (likely (cmp)) + return cmp; + + return b->edge.bottom - a->edge.bottom; +} + +static inline int +cairo_bo_event_compare (const cairo_bo_event_t *a, + const cairo_bo_event_t *b) +{ + int cmp; + + cmp = _cairo_point_compare (&a->point, &b->point); + if (likely (cmp)) + return cmp; + + cmp = a->type - b->type; + if (cmp) + return cmp; + + return a - b; +} + +static inline cairo_bo_event_t * +_cairo_bo_event_dequeue (cairo_bo_sweep_line_t *sweep_line) +{ + return *sweep_line->events++; +} + +CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, + cairo_bo_event_t *, + cairo_bo_event_compare) + +static void +_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_event_t **events, + int num_events) +{ + _cairo_bo_event_queue_sort (events, num_events); + events[num_events] = NULL; + sweep_line->events = events; + + sweep_line->head = NULL; + sweep_line->current_y = INT32_MIN; + sweep_line->current_edge = NULL; +} + +static void +_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (sweep_line->current_edge != NULL) { + cairo_bo_edge_t *prev, *next; + int cmp; + + cmp = _cairo_bo_edge_compare (sweep_line->current_edge, edge); + if (cmp < 0) { + prev = sweep_line->current_edge; + next = prev->next; + while (next != NULL && _cairo_bo_edge_compare (next, edge) < 0) + prev = next, next = prev->next; + + prev->next = edge; + edge->prev = prev; + edge->next = next; + if (next != NULL) + next->prev = edge; + } else if (cmp > 0) { + next = sweep_line->current_edge; + prev = next->prev; + while (prev != NULL && _cairo_bo_edge_compare (prev, edge) > 0) + next = prev, prev = next->prev; + + next->prev = edge; + edge->next = next; + edge->prev = prev; + if (prev != NULL) + prev->next = edge; + else + sweep_line->head = edge; + } else { + prev = sweep_line->current_edge; + edge->prev = prev; + edge->next = prev->next; + if (prev->next != NULL) + prev->next->prev = edge; + prev->next = edge; + } + } else { + sweep_line->head = edge; + } + + sweep_line->current_edge = edge; +} + +static void +_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (edge->prev != NULL) + edge->prev->next = edge->next; + else + sweep_line->head = edge->next; + + if (edge->next != NULL) + edge->next->prev = edge->prev; + + if (sweep_line->current_edge == edge) + sweep_line->current_edge = edge->prev ? edge->prev : edge->next; +} + +static inline cairo_bool_t +edges_collinear (const cairo_bo_edge_t *a, const cairo_bo_edge_t *b) +{ + return a->edge.line.p1.x == b->edge.line.p1.x; +} + +static cairo_status_t +_cairo_bo_edge_end_trap (cairo_bo_edge_t *left, + int32_t bot, + cairo_bool_t do_traps, + void *container) +{ + cairo_bo_trap_t *trap = &left->deferred_trap; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + /* Only emit (trivial) non-degenerate trapezoids with positive height. */ + if (likely (trap->top < bot)) { + if (do_traps) { + _cairo_traps_add_trap (container, + trap->top, bot, + &left->edge.line, &trap->right->edge.line); + status = _cairo_traps_status ((cairo_traps_t *) container); + } else { + cairo_box_t box; + + box.p1.x = left->edge.line.p1.x; + box.p1.y = trap->top; + box.p2.x = trap->right->edge.line.p1.x; + box.p2.y = bot; + status = _cairo_boxes_add (container, CAIRO_ANTIALIAS_DEFAULT, &box); + } + } + + trap->right = NULL; + + return status; +} + +/* Start a new trapezoid at the given top y coordinate, whose edges + * are `edge' and `edge->next'. If `edge' already has a trapezoid, + * then either add it to the traps in `traps', if the trapezoid's + * right edge differs from `edge->next', or do nothing if the new + * trapezoid would be a continuation of the existing one. */ +static inline cairo_status_t +_cairo_bo_edge_start_or_continue_trap (cairo_bo_edge_t *left, + cairo_bo_edge_t *right, + int top, + cairo_bool_t do_traps, + void *container) +{ + cairo_status_t status; + + if (left->deferred_trap.right == right) + return CAIRO_STATUS_SUCCESS; + + if (left->deferred_trap.right != NULL) { + if (right != NULL && edges_collinear (left->deferred_trap.right, right)) + { + /* continuation on right, so just swap edges */ + left->deferred_trap.right = right; + return CAIRO_STATUS_SUCCESS; + } + + status = _cairo_bo_edge_end_trap (left, top, do_traps, container); + if (unlikely (status)) + return status; + } + + if (right != NULL && ! edges_collinear (left, right)) { + left->deferred_trap.top = top; + left->deferred_trap.right = right; + } + + return CAIRO_STATUS_SUCCESS; +} + +static inline cairo_status_t +_active_edges_to_traps (cairo_bo_edge_t *left, + int32_t top, + cairo_fill_rule_t fill_rule, + cairo_bool_t do_traps, + void *container) +{ + cairo_bo_edge_t *right; + cairo_status_t status; + + if (fill_rule == CAIRO_FILL_RULE_WINDING) { + while (left != NULL) { + int in_out; + + /* Greedily search for the closing edge, so that we generate the + * maximal span width with the minimal number of trapezoids. + */ + in_out = left->edge.dir; + + /* Check if there is a co-linear edge with an existing trap */ + right = left->next; + if (left->deferred_trap.right == NULL) { + while (right != NULL && right->deferred_trap.right == NULL) + right = right->next; + + if (right != NULL && edges_collinear (left, right)) { + /* continuation on left */ + left->deferred_trap = right->deferred_trap; + right->deferred_trap.right = NULL; + } + } + + /* End all subsumed traps */ + right = left->next; + while (right != NULL) { + if (right->deferred_trap.right != NULL) { + status = _cairo_bo_edge_end_trap (right, top, do_traps, container); + if (unlikely (status)) + return status; + } + + in_out += right->edge.dir; + if (in_out == 0) { + /* skip co-linear edges */ + if (right->next == NULL || + ! edges_collinear (right, right->next)) + { + break; + } + } + + right = right->next; + } + + status = _cairo_bo_edge_start_or_continue_trap (left, right, top, + do_traps, container); + if (unlikely (status)) + return status; + + left = right; + if (left != NULL) + left = left->next; + } + } else { + while (left != NULL) { + int in_out = 0; + + right = left->next; + while (right != NULL) { + if (right->deferred_trap.right != NULL) { + status = _cairo_bo_edge_end_trap (right, top, do_traps, container); + if (unlikely (status)) + return status; + } + + if ((in_out++ & 1) == 0) { + cairo_bo_edge_t *next; + cairo_bool_t skip = FALSE; + + /* skip co-linear edges */ + next = right->next; + if (next != NULL) + skip = edges_collinear (right, next); + + if (! skip) + break; + } + + right = right->next; + } + + status = _cairo_bo_edge_start_or_continue_trap (left, right, top, + do_traps, container); + if (unlikely (status)) + return status; + + left = right; + if (left != NULL) + left = left->next; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_bentley_ottmann_tessellate_rectilinear (cairo_bo_event_t **start_events, + int num_events, + cairo_fill_rule_t fill_rule, + cairo_bool_t do_traps, + void *container) +{ + cairo_bo_sweep_line_t sweep_line; + cairo_bo_event_t *event; + cairo_status_t status; + + _cairo_bo_sweep_line_init (&sweep_line, start_events, num_events); + + while ((event = _cairo_bo_event_dequeue (&sweep_line))) { + if (event->point.y != sweep_line.current_y) { + status = _active_edges_to_traps (sweep_line.head, + sweep_line.current_y, + fill_rule, do_traps, container); + if (unlikely (status)) + return status; + + sweep_line.current_y = event->point.y; + } + + switch (event->type) { + case CAIRO_BO_EVENT_TYPE_START: + _cairo_bo_sweep_line_insert (&sweep_line, event->edge); + break; + + case CAIRO_BO_EVENT_TYPE_STOP: + _cairo_bo_sweep_line_delete (&sweep_line, event->edge); + + if (event->edge->deferred_trap.right != NULL) { + status = _cairo_bo_edge_end_trap (event->edge, + sweep_line.current_y, + do_traps, container); + if (unlikely (status)) + return status; + } + + break; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (const cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_boxes_t *boxes) +{ + cairo_status_t status; + cairo_bo_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_event_t)]; + cairo_bo_event_t *events; + cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; + cairo_bo_event_t **event_ptrs; + cairo_bo_edge_t stack_edges[ARRAY_LENGTH (stack_events)]; + cairo_bo_edge_t *edges; + int num_events; + int i, j; + + if (unlikely (polygon->num_edges == 0)) + return CAIRO_STATUS_SUCCESS; + + num_events = 2 * polygon->num_edges; + + events = stack_events; + event_ptrs = stack_event_ptrs; + edges = stack_edges; + if (num_events > ARRAY_LENGTH (stack_events)) { + events = _cairo_malloc_ab_plus_c (num_events, + sizeof (cairo_bo_event_t) + + sizeof (cairo_bo_edge_t) + + sizeof (cairo_bo_event_t *), + sizeof (cairo_bo_event_t *)); + if (unlikely (events == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event_ptrs = (cairo_bo_event_t **) (events + num_events); + edges = (cairo_bo_edge_t *) (event_ptrs + num_events + 1); + } + + for (i = j = 0; i < polygon->num_edges; i++) { + edges[i].edge = polygon->edges[i]; + edges[i].deferred_trap.right = NULL; + edges[i].prev = NULL; + edges[i].next = NULL; + + event_ptrs[j] = &events[j]; + events[j].type = CAIRO_BO_EVENT_TYPE_START; + events[j].point.y = polygon->edges[i].top; + events[j].point.x = polygon->edges[i].line.p1.x; + events[j].edge = &edges[i]; + j++; + + event_ptrs[j] = &events[j]; + events[j].type = CAIRO_BO_EVENT_TYPE_STOP; + events[j].point.y = polygon->edges[i].bottom; + events[j].point.x = polygon->edges[i].line.p1.x; + events[j].edge = &edges[i]; + j++; + } + + status = _cairo_bentley_ottmann_tessellate_rectilinear (event_ptrs, j, + fill_rule, + FALSE, boxes); + if (events != stack_events) + free (events); + + return status; +} + +cairo_status_t +_cairo_bentley_ottmann_tessellate_rectilinear_traps (cairo_traps_t *traps, + cairo_fill_rule_t fill_rule) +{ + cairo_bo_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_event_t)]; + cairo_bo_event_t *events; + cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; + cairo_bo_event_t **event_ptrs; + cairo_bo_edge_t stack_edges[ARRAY_LENGTH (stack_events)]; + cairo_bo_edge_t *edges; + cairo_status_t status; + int i, j, k; + + if (unlikely (traps->num_traps == 0)) + return CAIRO_STATUS_SUCCESS; + + assert (traps->is_rectilinear); + + i = 4 * traps->num_traps; + + events = stack_events; + event_ptrs = stack_event_ptrs; + edges = stack_edges; + if (i > ARRAY_LENGTH (stack_events)) { + events = _cairo_malloc_ab_plus_c (i, + sizeof (cairo_bo_event_t) + + sizeof (cairo_bo_edge_t) + + sizeof (cairo_bo_event_t *), + sizeof (cairo_bo_event_t *)); + if (unlikely (events == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event_ptrs = (cairo_bo_event_t **) (events + i); + edges = (cairo_bo_edge_t *) (event_ptrs + i + 1); + } + + for (i = j = k = 0; i < traps->num_traps; i++) { + edges[k].edge.top = traps->traps[i].top; + edges[k].edge.bottom = traps->traps[i].bottom; + edges[k].edge.line = traps->traps[i].left; + edges[k].edge.dir = 1; + edges[k].deferred_trap.right = NULL; + edges[k].prev = NULL; + edges[k].next = NULL; + + event_ptrs[j] = &events[j]; + events[j].type = CAIRO_BO_EVENT_TYPE_START; + events[j].point.y = traps->traps[i].top; + events[j].point.x = traps->traps[i].left.p1.x; + events[j].edge = &edges[k]; + j++; + + event_ptrs[j] = &events[j]; + events[j].type = CAIRO_BO_EVENT_TYPE_STOP; + events[j].point.y = traps->traps[i].bottom; + events[j].point.x = traps->traps[i].left.p1.x; + events[j].edge = &edges[k]; + j++; + k++; + + edges[k].edge.top = traps->traps[i].top; + edges[k].edge.bottom = traps->traps[i].bottom; + edges[k].edge.line = traps->traps[i].right; + edges[k].edge.dir = -1; + edges[k].deferred_trap.right = NULL; + edges[k].prev = NULL; + edges[k].next = NULL; + + event_ptrs[j] = &events[j]; + events[j].type = CAIRO_BO_EVENT_TYPE_START; + events[j].point.y = traps->traps[i].top; + events[j].point.x = traps->traps[i].right.p1.x; + events[j].edge = &edges[k]; + j++; + + event_ptrs[j] = &events[j]; + events[j].type = CAIRO_BO_EVENT_TYPE_STOP; + events[j].point.y = traps->traps[i].bottom; + events[j].point.x = traps->traps[i].right.p1.x; + events[j].edge = &edges[k]; + j++; + k++; + } + + _cairo_traps_clear (traps); + status = _cairo_bentley_ottmann_tessellate_rectilinear (event_ptrs, j, + fill_rule, + TRUE, traps); + traps->is_rectilinear = TRUE; + + if (events != stack_events) + free (events); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann.c b/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann.c new file mode 100644 index 00000000000..91e41f9c3cb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-bentley-ottmann.c @@ -0,0 +1,1909 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-combsort-inline.h" +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" +#include "cairo-line-inline.h" +#include "cairo-traps-private.h" + +#define DEBUG_PRINT_STATE 0 +#define DEBUG_EVENTS 0 +#define DEBUG_TRAPS 0 + +typedef cairo_point_t cairo_bo_point32_t; + +typedef struct _cairo_bo_intersect_ordinate { + int32_t ordinate; + enum { EXACT, INEXACT } exactness; +} cairo_bo_intersect_ordinate_t; + +typedef struct _cairo_bo_intersect_point { + cairo_bo_intersect_ordinate_t x; + cairo_bo_intersect_ordinate_t y; +} cairo_bo_intersect_point_t; + +typedef struct _cairo_bo_edge cairo_bo_edge_t; +typedef struct _cairo_bo_trap cairo_bo_trap_t; + +/* A deferred trapezoid of an edge */ +struct _cairo_bo_trap { + cairo_bo_edge_t *right; + int32_t top; +}; + +struct _cairo_bo_edge { + cairo_edge_t edge; + cairo_bo_edge_t *prev; + cairo_bo_edge_t *next; + cairo_bo_edge_t *colinear; + cairo_bo_trap_t deferred_trap; +}; + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef enum { + CAIRO_BO_EVENT_TYPE_STOP, + CAIRO_BO_EVENT_TYPE_INTERSECTION, + CAIRO_BO_EVENT_TYPE_START +} cairo_bo_event_type_t; + +typedef struct _cairo_bo_event { + cairo_bo_event_type_t type; + cairo_point_t point; +} cairo_bo_event_t; + +typedef struct _cairo_bo_start_event { + cairo_bo_event_type_t type; + cairo_point_t point; + cairo_bo_edge_t edge; +} cairo_bo_start_event_t; + +typedef struct _cairo_bo_queue_event { + cairo_bo_event_type_t type; + cairo_point_t point; + cairo_bo_edge_t *e1; + cairo_bo_edge_t *e2; +} cairo_bo_queue_event_t; + +typedef struct _pqueue { + int size, max_size; + + cairo_bo_event_t **elements; + cairo_bo_event_t *elements_embedded[1024]; +} pqueue_t; + +typedef struct _cairo_bo_event_queue { + cairo_freepool_t pool; + pqueue_t pqueue; + cairo_bo_event_t **start_events; +} cairo_bo_event_queue_t; + +typedef struct _cairo_bo_sweep_line { + cairo_bo_edge_t *head; + cairo_bo_edge_t *stopped; + int32_t current_y; + cairo_bo_edge_t *current_edge; +} cairo_bo_sweep_line_t; + +#if DEBUG_TRAPS +static void +dump_traps (cairo_traps_t *traps, const char *filename) +{ + FILE *file; + cairo_box_t extents; + int n; + + if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) + return; + +#if 0 + if (traps->has_limits) { + printf ("%s: limits=(%d, %d, %d, %d)\n", + filename, + traps->limits.p1.x, traps->limits.p1.y, + traps->limits.p2.x, traps->limits.p2.y); + } +#endif + _cairo_traps_extents (traps, &extents); + printf ("%s: extents=(%d, %d, %d, %d)\n", + filename, + extents.p1.x, extents.p1.y, + extents.p2.x, extents.p2.y); + + file = fopen (filename, "a"); + if (file != NULL) { + for (n = 0; n < traps->num_traps; n++) { + fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", + traps->traps[n].top, + traps->traps[n].bottom, + traps->traps[n].left.p1.x, + traps->traps[n].left.p1.y, + traps->traps[n].left.p2.x, + traps->traps[n].left.p2.y, + traps->traps[n].right.p1.x, + traps->traps[n].right.p1.y, + traps->traps[n].right.p2.x, + traps->traps[n].right.p2.y); + } + fprintf (file, "\n"); + fclose (file); + } +} + +static void +dump_edges (cairo_bo_start_event_t *events, + int num_edges, + const char *filename) +{ + FILE *file; + int n; + + if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) + return; + + file = fopen (filename, "a"); + if (file != NULL) { + for (n = 0; n < num_edges; n++) { + fprintf (file, "(%d, %d), (%d, %d) %d %d %d\n", + events[n].edge.edge.line.p1.x, + events[n].edge.edge.line.p1.y, + events[n].edge.edge.line.p2.x, + events[n].edge.edge.line.p2.y, + events[n].edge.edge.top, + events[n].edge.edge.bottom, + events[n].edge.edge.dir); + } + fprintf (file, "\n"); + fclose (file); + } +} +#endif + +static cairo_fixed_t +_line_compute_intersection_x_for_y (const cairo_line_t *line, + cairo_fixed_t y) +{ + cairo_fixed_t x, dy; + + if (y == line->p1.y) + return line->p1.x; + if (y == line->p2.y) + return line->p2.x; + + x = line->p1.x; + dy = line->p2.y - line->p1.y; + if (dy != 0) { + x += _cairo_fixed_mul_div_floor (y - line->p1.y, + line->p2.x - line->p1.x, + dy); + } + + return x; +} + +static inline int +_cairo_bo_point32_compare (cairo_bo_point32_t const *a, + cairo_bo_point32_t const *b) +{ + int cmp; + + cmp = a->y - b->y; + if (cmp) + return cmp; + + return a->x - b->x; +} + +/* Compare the slope of a to the slope of b, returning 1, 0, -1 if the + * slope a is respectively greater than, equal to, or less than the + * slope of b. + * + * For each edge, consider the direction vector formed from: + * + * top -> bottom + * + * which is: + * + * (dx, dy) = (line.p2.x - line.p1.x, line.p2.y - line.p1.y) + * + * We then define the slope of each edge as dx/dy, (which is the + * inverse of the slope typically used in math instruction). We never + * compute a slope directly as the value approaches infinity, but we + * can derive a slope comparison without division as follows, (where + * the ? represents our compare operator). + * + * 1. slope(a) ? slope(b) + * 2. adx/ady ? bdx/bdy + * 3. (adx * bdy) ? (bdx * ady) + * + * Note that from step 2 to step 3 there is no change needed in the + * sign of the result since both ady and bdy are guaranteed to be + * greater than or equal to 0. + * + * When using this slope comparison to sort edges, some care is needed + * when interpreting the results. Since the slope compare operates on + * distance vectors from top to bottom it gives a correct left to + * right sort for edges that have a common top point, (such as two + * edges with start events at the same location). On the other hand, + * the sense of the result will be exactly reversed for two edges that + * have a common stop point. + */ +static inline int +_slope_compare (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t adx = a->edge.line.p2.x - a->edge.line.p1.x; + int32_t bdx = b->edge.line.p2.x - b->edge.line.p1.x; + + /* Since the dy's are all positive by construction we can fast + * path several common cases. + */ + + /* First check for vertical lines. */ + if (adx == 0) + return -bdx; + if (bdx == 0) + return adx; + + /* Then where the two edges point in different directions wrt x. */ + if ((adx ^ bdx) < 0) + return adx; + + /* Finally we actually need to do the general comparison. */ + { + int32_t ady = a->edge.line.p2.y - a->edge.line.p1.y; + int32_t bdy = b->edge.line.p2.y - b->edge.line.p1.y; + cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } +} + + +/* + * We need to compare the x-coordinate of a line for a particular y wrt to a + * given x, without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ X + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy (and (Y - A_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 64 bit arithmetic. + * + * See the similar discussion for _slope_compare() and + * edges_compare_x_for_y_general(). + */ +static int +edge_compare_for_y_against_x (const cairo_bo_edge_t *a, + int32_t y, + int32_t x) +{ + int32_t adx, ady; + int32_t dx, dy; + cairo_int64_t L, R; + + if (x < a->edge.line.p1.x && x < a->edge.line.p2.x) + return 1; + if (x > a->edge.line.p1.x && x > a->edge.line.p2.x) + return -1; + + adx = a->edge.line.p2.x - a->edge.line.p1.x; + dx = x - a->edge.line.p1.x; + + if (adx == 0) + return -dx; + if (dx == 0 || (adx ^ dx) < 0) + return adx; + + dy = y - a->edge.line.p1.y; + ady = a->edge.line.p2.y - a->edge.line.p1.y; + + L = _cairo_int32x32_64_mul (dy, adx); + R = _cairo_int32x32_64_mul (dx, ady); + + return _cairo_int64_cmp (L, R); +} + +static inline int +_cairo_bo_sweep_line_compare_edges (const cairo_bo_sweep_line_t *sweep_line, + const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + int cmp; + + cmp = cairo_lines_compare_at_y (&a->edge.line, + &b->edge.line, + sweep_line->current_y); + if (cmp) + return cmp; + + /* We've got two collinear edges now. */ + return b->edge.bottom - a->edge.bottom; +} + +static inline cairo_int64_t +det32_64 (int32_t a, int32_t b, + int32_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), + _cairo_int32x32_64_mul (b, c)); +} + +static inline cairo_int128_t +det64x32_128 (cairo_int64_t a, int32_t b, + cairo_int64_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), + _cairo_int64x32_128_mul (c, b)); +} + +/* Compute the intersection of two lines as defined by two edges. The + * result is provided as a coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or + * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. + */ +static cairo_bool_t +intersect_lines (cairo_bo_edge_t *a, + cairo_bo_edge_t *b, + cairo_bo_intersect_point_t *intersection) +{ + cairo_int64_t a_det, b_det; + + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm begins. + * What we're doing to mitigate this is to perform clamping in + * cairo_bo_tessellate_polygon(). + */ + int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; + int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; + + int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; + int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; + + cairo_int64_t den_det; + cairo_int64_t R; + cairo_quorem64_t qr; + + den_det = det32_64 (dx1, dy1, dx2, dy2); + + /* Q: Can we determine that the lines do not intersect (within range) + * much more cheaply than computing the intersection point i.e. by + * avoiding the division? + * + * X = ax + t * adx = bx + s * bdx; + * Y = ay + t * ady = by + s * bdy; + * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) + * => t * L = R + * + * Therefore we can reject any intersection (under the criteria for + * valid intersection events) if: + * L^R < 0 => t < 0, or + * L t > 1 + * + * (where top/bottom must at least extend to the line endpoints). + * + * A similar substitution can be performed for s, yielding: + * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) + */ + R = det32_64 (dx2, dy2, + b->edge.line.p1.x - a->edge.line.p1.x, + b->edge.line.p1.y - a->edge.line.p1.y); + if (_cairo_int64_negative (den_det)) { + if (_cairo_int64_ge (den_det, R)) + return FALSE; + } else { + if (_cairo_int64_le (den_det, R)) + return FALSE; + } + + R = det32_64 (dy1, dx1, + a->edge.line.p1.y - b->edge.line.p1.y, + a->edge.line.p1.x - b->edge.line.p1.x); + if (_cairo_int64_negative (den_det)) { + if (_cairo_int64_ge (den_det, R)) + return FALSE; + } else { + if (_cairo_int64_le (den_det, R)) + return FALSE; + } + + /* We now know that the two lines should intersect within range. */ + + a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, + a->edge.line.p2.x, a->edge.line.p2.y); + b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, + b->edge.line.p2.x, b->edge.line.p2.y); + + /* x = det (a_det, dx1, b_det, dx2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, + b_det, dx2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; +#if 0 + intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; +#else + intersection->x.exactness = EXACT; + if (! _cairo_int64_is_zero (qr.rem)) { + if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) + qr.rem = _cairo_int64_negate (qr.rem); + qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); + if (_cairo_int64_ge (qr.rem, den_det)) { + qr.quo = _cairo_int64_add (qr.quo, + _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); + } else + intersection->x.exactness = INEXACT; + } +#endif + intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); + + /* y = det (a_det, dy1, b_det, dy2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, + b_det, dy2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; +#if 0 + intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; +#else + intersection->y.exactness = EXACT; + if (! _cairo_int64_is_zero (qr.rem)) { + if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) + qr.rem = _cairo_int64_negate (qr.rem); + qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); + if (_cairo_int64_ge (qr.rem, den_det)) { + qr.quo = _cairo_int64_add (qr.quo, + _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); + } else + intersection->y.exactness = INEXACT; + } +#endif + intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); + + return TRUE; +} + +static int +_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t a, + int32_t b) +{ + /* First compare the quotient */ + if (a.ordinate > b) + return +1; + if (a.ordinate < b) + return -1; + /* With quotient identical, if remainder is 0 then compare equal */ + /* Otherwise, the non-zero remainder makes a > b */ + return INEXACT == a.exactness; +} + +/* Does the given edge contain the given point. The point must already + * be known to be contained within the line determined by the edge, + * (most likely the point results from an intersection of this edge + * with another). + * + * If we had exact arithmetic, then this function would simply be a + * matter of examining whether the y value of the point lies within + * the range of y values of the edge. But since intersection points + * are not exact due to being rounded to the nearest integer within + * the available precision, we must also examine the x value of the + * point. + * + * The definition of "contains" here is that the given intersection + * point will be seen by the sweep line after the start event for the + * given edge and before the stop event for the edge. See the comments + * in the implementation for more details. + */ +static cairo_bool_t +_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t *edge, + cairo_bo_intersect_point_t *point) +{ + int cmp_top, cmp_bottom; + + /* XXX: When running the actual algorithm, we don't actually need to + * compare against edge->top at all here, since any intersection above + * top is eliminated early via a slope comparison. We're leaving these + * here for now only for the sake of the quadratic-time intersection + * finder which needs them. + */ + + cmp_top = _cairo_bo_intersect_ordinate_32_compare (point->y, + edge->edge.top); + cmp_bottom = _cairo_bo_intersect_ordinate_32_compare (point->y, + edge->edge.bottom); + + if (cmp_top < 0 || cmp_bottom > 0) + { + return FALSE; + } + + if (cmp_top > 0 && cmp_bottom < 0) + { + return TRUE; + } + + /* At this stage, the point lies on the same y value as either + * edge->top or edge->bottom, so we have to examine the x value in + * order to properly determine containment. */ + + /* If the y value of the point is the same as the y value of the + * top of the edge, then the x value of the point must be greater + * to be considered as inside the edge. Similarly, if the y value + * of the point is the same as the y value of the bottom of the + * edge, then the x value of the point must be less to be + * considered as inside. */ + + if (cmp_top == 0) { + cairo_fixed_t top_x; + + top_x = _line_compute_intersection_x_for_y (&edge->edge.line, + edge->edge.top); + return _cairo_bo_intersect_ordinate_32_compare (point->x, top_x) > 0; + } else { /* cmp_bottom == 0 */ + cairo_fixed_t bot_x; + + bot_x = _line_compute_intersection_x_for_y (&edge->edge.line, + edge->edge.bottom); + return _cairo_bo_intersect_ordinate_32_compare (point->x, bot_x) < 0; + } +} + +/* Compute the intersection of two edges. The result is provided as a + * coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection + * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the + * intersection of the lines defined by the edges occurs outside of + * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges + * are exactly parallel. + * + * Note that when determining if a candidate intersection is "inside" + * an edge, we consider both the infinitesimal shortening and the + * infinitesimal tilt rules described by John Hobby. Specifically, if + * the intersection is exactly the same as an edge point, it is + * effectively outside (no intersection is returned). Also, if the + * intersection point has the same + */ +static cairo_bool_t +_cairo_bo_edge_intersect (cairo_bo_edge_t *a, + cairo_bo_edge_t *b, + cairo_bo_point32_t *intersection) +{ + cairo_bo_intersect_point_t quorem; + + if (! intersect_lines (a, b, &quorem)) + return FALSE; + + if (! _cairo_bo_edge_contains_intersect_point (a, &quorem)) + return FALSE; + + if (! _cairo_bo_edge_contains_intersect_point (b, &quorem)) + return FALSE; + + /* Now that we've correctly compared the intersection point and + * determined that it lies within the edge, then we know that we + * no longer need any more bits of storage for the intersection + * than we do for our edge coordinates. We also no longer need the + * remainder from the division. */ + intersection->x = quorem.x.ordinate; + intersection->y = quorem.y.ordinate; + + return TRUE; +} + +static inline int +cairo_bo_event_compare (const cairo_bo_event_t *a, + const cairo_bo_event_t *b) +{ + int cmp; + + cmp = _cairo_bo_point32_compare (&a->point, &b->point); + if (cmp) + return cmp; + + cmp = a->type - b->type; + if (cmp) + return cmp; + + return a - b; +} + +static inline void +_pqueue_init (pqueue_t *pq) +{ + pq->max_size = ARRAY_LENGTH (pq->elements_embedded); + pq->size = 0; + + pq->elements = pq->elements_embedded; +} + +static inline void +_pqueue_fini (pqueue_t *pq) +{ + if (pq->elements != pq->elements_embedded) + free (pq->elements); +} + +static cairo_status_t +_pqueue_grow (pqueue_t *pq) +{ + cairo_bo_event_t **new_elements; + pq->max_size *= 2; + + if (pq->elements == pq->elements_embedded) { + new_elements = _cairo_malloc_ab (pq->max_size, + sizeof (cairo_bo_event_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (new_elements, pq->elements_embedded, + sizeof (pq->elements_embedded)); + } else { + new_elements = _cairo_realloc_ab (pq->elements, + pq->max_size, + sizeof (cairo_bo_event_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pq->elements = new_elements; + return CAIRO_STATUS_SUCCESS; +} + +static inline cairo_status_t +_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event) +{ + cairo_bo_event_t **elements; + int i, parent; + + if (unlikely (pq->size + 1 == pq->max_size)) { + cairo_status_t status; + + status = _pqueue_grow (pq); + if (unlikely (status)) + return status; + } + + elements = pq->elements; + + for (i = ++pq->size; + i != PQ_FIRST_ENTRY && + cairo_bo_event_compare (event, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = event; + + return CAIRO_STATUS_SUCCESS; +} + +static inline void +_pqueue_pop (pqueue_t *pq) +{ + cairo_bo_event_t **elements = pq->elements; + cairo_bo_event_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + cairo_bo_event_compare (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (cairo_bo_event_compare (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline cairo_status_t +_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, + cairo_bo_event_type_t type, + cairo_bo_edge_t *e1, + cairo_bo_edge_t *e2, + const cairo_point_t *point) +{ + cairo_bo_queue_event_t *event; + + event = _cairo_freepool_alloc (&queue->pool); + if (unlikely (event == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event->type = type; + event->e1 = e1; + event->e2 = e2; + event->point = *point; + + return _pqueue_push (&queue->pqueue, (cairo_bo_event_t *) event); +} + +static void +_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue, + cairo_bo_event_t *event) +{ + _cairo_freepool_free (&queue->pool, event); +} + +static cairo_bo_event_t * +_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue) +{ + cairo_bo_event_t *event, *cmp; + + event = event_queue->pqueue.elements[PQ_FIRST_ENTRY]; + cmp = *event_queue->start_events; + if (event == NULL || + (cmp != NULL && cairo_bo_event_compare (cmp, event) < 0)) + { + event = cmp; + event_queue->start_events++; + } + else + { + _pqueue_pop (&event_queue->pqueue); + } + + return event; +} + +CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, + cairo_bo_event_t *, + cairo_bo_event_compare) + +static void +_cairo_bo_event_queue_init (cairo_bo_event_queue_t *event_queue, + cairo_bo_event_t **start_events, + int num_events) +{ + event_queue->start_events = start_events; + + _cairo_freepool_init (&event_queue->pool, + sizeof (cairo_bo_queue_event_t)); + _pqueue_init (&event_queue->pqueue); + event_queue->pqueue.elements[PQ_FIRST_ENTRY] = NULL; +} + +static cairo_status_t +_cairo_bo_event_queue_insert_stop (cairo_bo_event_queue_t *event_queue, + cairo_bo_edge_t *edge) +{ + cairo_bo_point32_t point; + + point.y = edge->edge.bottom; + point.x = _line_compute_intersection_x_for_y (&edge->edge.line, + point.y); + return _cairo_bo_event_queue_insert (event_queue, + CAIRO_BO_EVENT_TYPE_STOP, + edge, NULL, + &point); +} + +static void +_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) +{ + _pqueue_fini (&event_queue->pqueue); + _cairo_freepool_fini (&event_queue->pool); +} + +static inline cairo_status_t +_cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t *event_queue, + cairo_bo_edge_t *left, + cairo_bo_edge_t *right) +{ + cairo_bo_point32_t intersection; + + if (MAX (left->edge.line.p1.x, left->edge.line.p2.x) <= + MIN (right->edge.line.p1.x, right->edge.line.p2.x)) + return CAIRO_STATUS_SUCCESS; + + if (cairo_lines_equal (&left->edge.line, &right->edge.line)) + return CAIRO_STATUS_SUCCESS; + + /* The names "left" and "right" here are correct descriptions of + * the order of the two edges within the active edge list. So if a + * slope comparison also puts left less than right, then we know + * that the intersection of these two segments has already + * occurred before the current sweep line position. */ + if (_slope_compare (left, right) <= 0) + return CAIRO_STATUS_SUCCESS; + + if (! _cairo_bo_edge_intersect (left, right, &intersection)) + return CAIRO_STATUS_SUCCESS; + + return _cairo_bo_event_queue_insert (event_queue, + CAIRO_BO_EVENT_TYPE_INTERSECTION, + left, right, + &intersection); +} + +static void +_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line) +{ + sweep_line->head = NULL; + sweep_line->stopped = NULL; + sweep_line->current_y = INT32_MIN; + sweep_line->current_edge = NULL; +} + +static void +_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (sweep_line->current_edge != NULL) { + cairo_bo_edge_t *prev, *next; + int cmp; + + cmp = _cairo_bo_sweep_line_compare_edges (sweep_line, + sweep_line->current_edge, + edge); + if (cmp < 0) { + prev = sweep_line->current_edge; + next = prev->next; + while (next != NULL && + _cairo_bo_sweep_line_compare_edges (sweep_line, + next, edge) < 0) + { + prev = next, next = prev->next; + } + + prev->next = edge; + edge->prev = prev; + edge->next = next; + if (next != NULL) + next->prev = edge; + } else if (cmp > 0) { + next = sweep_line->current_edge; + prev = next->prev; + while (prev != NULL && + _cairo_bo_sweep_line_compare_edges (sweep_line, + prev, edge) > 0) + { + next = prev, prev = next->prev; + } + + next->prev = edge; + edge->next = next; + edge->prev = prev; + if (prev != NULL) + prev->next = edge; + else + sweep_line->head = edge; + } else { + prev = sweep_line->current_edge; + edge->prev = prev; + edge->next = prev->next; + if (prev->next != NULL) + prev->next->prev = edge; + prev->next = edge; + } + } else { + sweep_line->head = edge; + edge->next = NULL; + } + + sweep_line->current_edge = edge; +} + +static void +_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (edge->prev != NULL) + edge->prev->next = edge->next; + else + sweep_line->head = edge->next; + + if (edge->next != NULL) + edge->next->prev = edge->prev; + + if (sweep_line->current_edge == edge) + sweep_line->current_edge = edge->prev ? edge->prev : edge->next; +} + +static void +_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *left, + cairo_bo_edge_t *right) +{ + if (left->prev != NULL) + left->prev->next = right; + else + sweep_line->head = right; + + if (right->next != NULL) + right->next->prev = left; + + left->next = right->next; + right->next = left; + + right->prev = left->prev; + left->prev = right; +} + +#if DEBUG_PRINT_STATE +static void +_cairo_bo_edge_print (cairo_bo_edge_t *edge) +{ + printf ("(0x%x, 0x%x)-(0x%x, 0x%x)", + edge->edge.line.p1.x, edge->edge.line.p1.y, + edge->edge.line.p2.x, edge->edge.line.p2.y); +} + +static void +_cairo_bo_event_print (cairo_bo_event_t *event) +{ + switch (event->type) { + case CAIRO_BO_EVENT_TYPE_START: + printf ("Start: "); + break; + case CAIRO_BO_EVENT_TYPE_STOP: + printf ("Stop: "); + break; + case CAIRO_BO_EVENT_TYPE_INTERSECTION: + printf ("Intersection: "); + break; + } + printf ("(%d, %d)\t", event->point.x, event->point.y); + _cairo_bo_edge_print (event->e1); + if (event->type == CAIRO_BO_EVENT_TYPE_INTERSECTION) { + printf (" X "); + _cairo_bo_edge_print (event->e2); + } + printf ("\n"); +} + +static void +_cairo_bo_event_queue_print (cairo_bo_event_queue_t *event_queue) +{ + /* XXX: fixme to print the start/stop array too. */ + printf ("Event queue:\n"); +} + +static void +_cairo_bo_sweep_line_print (cairo_bo_sweep_line_t *sweep_line) +{ + cairo_bool_t first = TRUE; + cairo_bo_edge_t *edge; + + printf ("Sweep line from edge list: "); + first = TRUE; + for (edge = sweep_line->head; + edge; + edge = edge->next) + { + if (!first) + printf (", "); + _cairo_bo_edge_print (edge); + first = FALSE; + } + printf ("\n"); +} + +static void +print_state (const char *msg, + cairo_bo_event_t *event, + cairo_bo_event_queue_t *event_queue, + cairo_bo_sweep_line_t *sweep_line) +{ + printf ("%s ", msg); + _cairo_bo_event_print (event); + _cairo_bo_event_queue_print (event_queue); + _cairo_bo_sweep_line_print (sweep_line); + printf ("\n"); +} +#endif + +#if DEBUG_EVENTS +static void CAIRO_PRINTF_FORMAT (1, 2) +event_log (const char *fmt, ...) +{ + FILE *file; + + if (getenv ("CAIRO_DEBUG_EVENTS") == NULL) + return; + + file = fopen ("bo-events.txt", "a"); + if (file != NULL) { + va_list ap; + + va_start (ap, fmt); + vfprintf (file, fmt, ap); + va_end (ap); + + fclose (file); + } +} +#endif + +#define HAS_COLINEAR(a, b) ((cairo_bo_edge_t *)(((uintptr_t)(a))&~1) == (b)) +#define IS_COLINEAR(e) (((uintptr_t)(e))&1) +#define MARK_COLINEAR(e, v) ((cairo_bo_edge_t *)(((uintptr_t)(e))|(v))) + +static inline cairo_bool_t +edges_colinear (cairo_bo_edge_t *a, const cairo_bo_edge_t *b) +{ + unsigned p; + + if (HAS_COLINEAR(a->colinear, b)) + return IS_COLINEAR(a->colinear); + + if (HAS_COLINEAR(b->colinear, a)) { + p = IS_COLINEAR(b->colinear); + a->colinear = MARK_COLINEAR(b, p); + return p; + } + + p = 0; + p |= (a->edge.line.p1.x == b->edge.line.p1.x) << 0; + p |= (a->edge.line.p1.y == b->edge.line.p1.y) << 1; + p |= (a->edge.line.p2.x == b->edge.line.p2.x) << 3; + p |= (a->edge.line.p2.y == b->edge.line.p2.y) << 4; + if (p == ((1 << 0) | (1 << 1) | (1 << 3) | (1 << 4))) { + a->colinear = MARK_COLINEAR(b, 1); + return TRUE; + } + + if (_slope_compare (a, b)) { + a->colinear = MARK_COLINEAR(b, 0); + return FALSE; + } + + /* The choice of y is not truly arbitrary since we must guarantee that it + * is greater than the start of either line. + */ + if (p != 0) { + /* colinear if either end-point are coincident */ + p = (((p >> 1) & p) & 5) != 0; + } else if (a->edge.line.p1.y < b->edge.line.p1.y) { + p = edge_compare_for_y_against_x (b, + a->edge.line.p1.y, + a->edge.line.p1.x) == 0; + } else { + p = edge_compare_for_y_against_x (a, + b->edge.line.p1.y, + b->edge.line.p1.x) == 0; + } + + a->colinear = MARK_COLINEAR(b, p); + return p; +} + +/* Adds the trapezoid, if any, of the left edge to the #cairo_traps_t */ +static void +_cairo_bo_edge_end_trap (cairo_bo_edge_t *left, + int32_t bot, + cairo_traps_t *traps) +{ + cairo_bo_trap_t *trap = &left->deferred_trap; + + /* Only emit (trivial) non-degenerate trapezoids with positive height. */ + if (likely (trap->top < bot)) { + _cairo_traps_add_trap (traps, + trap->top, bot, + &left->edge.line, &trap->right->edge.line); + +#if DEBUG_PRINT_STATE + printf ("Deferred trap: left=(%x, %x)-(%x,%x) " + "right=(%x,%x)-(%x,%x) top=%x, bot=%x\n", + left->edge.line.p1.x, left->edge.line.p1.y, + left->edge.line.p2.x, left->edge.line.p2.y, + trap->right->edge.line.p1.x, trap->right->edge.line.p1.y, + trap->right->edge.line.p2.x, trap->right->edge.line.p2.y, + trap->top, bot); +#endif +#if DEBUG_EVENTS + event_log ("end trap: %lu %lu %d %d\n", + (long) left, + (long) trap->right, + trap->top, + bot); +#endif + } + + trap->right = NULL; +} + + +/* Start a new trapezoid at the given top y coordinate, whose edges + * are `edge' and `edge->next'. If `edge' already has a trapezoid, + * then either add it to the traps in `traps', if the trapezoid's + * right edge differs from `edge->next', or do nothing if the new + * trapezoid would be a continuation of the existing one. */ +static inline void +_cairo_bo_edge_start_or_continue_trap (cairo_bo_edge_t *left, + cairo_bo_edge_t *right, + int top, + cairo_traps_t *traps) +{ + if (left->deferred_trap.right == right) + return; + + assert (right); + if (left->deferred_trap.right != NULL) { + if (edges_colinear (left->deferred_trap.right, right)) + { + /* continuation on right, so just swap edges */ + left->deferred_trap.right = right; + return; + } + + _cairo_bo_edge_end_trap (left, top, traps); + } + + if (! edges_colinear (left, right)) { + left->deferred_trap.top = top; + left->deferred_trap.right = right; + +#if DEBUG_EVENTS + event_log ("begin trap: %lu %lu %d\n", + (long) left, + (long) right, + top); +#endif + } +} + +static inline void +_active_edges_to_traps (cairo_bo_edge_t *pos, + int32_t top, + unsigned mask, + cairo_traps_t *traps) +{ + cairo_bo_edge_t *left; + int in_out; + + +#if DEBUG_PRINT_STATE + printf ("Processing active edges for %x\n", top); +#endif + + in_out = 0; + left = pos; + while (pos != NULL) { + if (pos != left && pos->deferred_trap.right) { + /* XXX It shouldn't be possible to here with 2 deferred traps + * on colinear edges... See bug-bo-rictoz. + */ + if (left->deferred_trap.right == NULL && + edges_colinear (left, pos)) + { + /* continuation on left */ + left->deferred_trap = pos->deferred_trap; + pos->deferred_trap.right = NULL; + } + else + { + _cairo_bo_edge_end_trap (pos, top, traps); + } + } + + in_out += pos->edge.dir; + if ((in_out & mask) == 0) { + /* skip co-linear edges */ + if (pos->next == NULL || ! edges_colinear (pos, pos->next)) { + _cairo_bo_edge_start_or_continue_trap (left, pos, top, traps); + left = pos->next; + } + } + + pos = pos->next; + } +} + +/* Execute a single pass of the Bentley-Ottmann algorithm on edges, + * generating trapezoids according to the fill_rule and appending them + * to traps. */ +static cairo_status_t +_cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_event_t **start_events, + int num_events, + unsigned fill_rule, + cairo_traps_t *traps, + int *num_intersections) +{ + cairo_status_t status; + int intersection_count = 0; + cairo_bo_event_queue_t event_queue; + cairo_bo_sweep_line_t sweep_line; + cairo_bo_event_t *event; + cairo_bo_edge_t *left, *right; + cairo_bo_edge_t *e1, *e2; + + /* convert the fill_rule into a winding mask */ + if (fill_rule == CAIRO_FILL_RULE_WINDING) + fill_rule = (unsigned) -1; + else + fill_rule = 1; + +#if DEBUG_EVENTS + { + int i; + + for (i = 0; i < num_events; i++) { + cairo_bo_start_event_t *event = + ((cairo_bo_start_event_t **) start_events)[i]; + event_log ("edge: %lu (%d, %d) (%d, %d) (%d, %d) %d\n", + (long) &events[i].edge, + event->edge.edge.line.p1.x, + event->edge.edge.line.p1.y, + event->edge.edge.line.p2.x, + event->edge.edge.line.p2.y, + event->edge.top, + event->edge.bottom, + event->edge.edge.dir); + } + } +#endif + + _cairo_bo_event_queue_init (&event_queue, start_events, num_events); + _cairo_bo_sweep_line_init (&sweep_line); + + while ((event = _cairo_bo_event_dequeue (&event_queue))) { + if (event->point.y != sweep_line.current_y) { + for (e1 = sweep_line.stopped; e1; e1 = e1->next) { + if (e1->deferred_trap.right != NULL) { + _cairo_bo_edge_end_trap (e1, + e1->edge.bottom, + traps); + } + } + sweep_line.stopped = NULL; + + _active_edges_to_traps (sweep_line.head, + sweep_line.current_y, + fill_rule, traps); + + sweep_line.current_y = event->point.y; + } + +#if DEBUG_EVENTS + event_log ("event: %d (%ld, %ld) %lu, %lu\n", + event->type, + (long) event->point.x, + (long) event->point.y, + (long) event->e1, + (long) event->e2); +#endif + + switch (event->type) { + case CAIRO_BO_EVENT_TYPE_START: + e1 = &((cairo_bo_start_event_t *) event)->edge; + + _cairo_bo_sweep_line_insert (&sweep_line, e1); + + status = _cairo_bo_event_queue_insert_stop (&event_queue, e1); + if (unlikely (status)) + goto unwind; + + /* check to see if this is a continuation of a stopped edge */ + /* XXX change to an infinitesimal lengthening rule */ + for (left = sweep_line.stopped; left; left = left->next) { + if (e1->edge.top <= left->edge.bottom && + edges_colinear (e1, left)) + { + e1->deferred_trap = left->deferred_trap; + if (left->prev != NULL) + left->prev = left->next; + else + sweep_line.stopped = left->next; + if (left->next != NULL) + left->next->prev = left->prev; + break; + } + } + + left = e1->prev; + right = e1->next; + + if (left != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e1); + if (unlikely (status)) + goto unwind; + } + + if (right != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); + if (unlikely (status)) + goto unwind; + } + + break; + + case CAIRO_BO_EVENT_TYPE_STOP: + e1 = ((cairo_bo_queue_event_t *) event)->e1; + _cairo_bo_event_queue_delete (&event_queue, event); + + left = e1->prev; + right = e1->next; + + _cairo_bo_sweep_line_delete (&sweep_line, e1); + + /* first, check to see if we have a continuation via a fresh edge */ + if (e1->deferred_trap.right != NULL) { + e1->next = sweep_line.stopped; + if (sweep_line.stopped != NULL) + sweep_line.stopped->prev = e1; + sweep_line.stopped = e1; + e1->prev = NULL; + } + + if (left != NULL && right != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, right); + if (unlikely (status)) + goto unwind; + } + + break; + + case CAIRO_BO_EVENT_TYPE_INTERSECTION: + e1 = ((cairo_bo_queue_event_t *) event)->e1; + e2 = ((cairo_bo_queue_event_t *) event)->e2; + _cairo_bo_event_queue_delete (&event_queue, event); + + /* skip this intersection if its edges are not adjacent */ + if (e2 != e1->next) + break; + + intersection_count++; + + left = e1->prev; + right = e2->next; + + _cairo_bo_sweep_line_swap (&sweep_line, e1, e2); + + /* after the swap e2 is left of e1 */ + + if (left != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e2); + if (unlikely (status)) + goto unwind; + } + + if (right != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); + if (unlikely (status)) + goto unwind; + } + + break; + } + } + + *num_intersections = intersection_count; + for (e1 = sweep_line.stopped; e1; e1 = e1->next) { + if (e1->deferred_trap.right != NULL) { + _cairo_bo_edge_end_trap (e1, e1->edge.bottom, traps); + } + } + status = traps->status; + unwind: + _cairo_bo_event_queue_fini (&event_queue); + +#if DEBUG_EVENTS + event_log ("\n"); +#endif + + return status; +} + +cairo_status_t +_cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t *traps, + const cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule) +{ + int intersections; + cairo_bo_start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_start_event_t)]; + cairo_bo_start_event_t *events; + cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; + cairo_bo_event_t **event_ptrs; + cairo_bo_start_event_t *stack_event_y[64]; + cairo_bo_start_event_t **event_y = NULL; + int i, num_events, y, ymin, ymax; + cairo_status_t status; + + num_events = polygon->num_edges; + if (unlikely (0 == num_events)) + return CAIRO_STATUS_SUCCESS; + + if (polygon->num_limits) { + ymin = _cairo_fixed_integer_floor (polygon->limit.p1.y); + ymax = _cairo_fixed_integer_ceil (polygon->limit.p2.y) - ymin; + + if (ymax > 64) + event_y = _cairo_malloc_ab(sizeof (cairo_bo_event_t*), ymax); + else + event_y = stack_event_y; + memset (event_y, 0, ymax * sizeof(cairo_bo_event_t *)); + } + + events = stack_events; + event_ptrs = stack_event_ptrs; + if (num_events > ARRAY_LENGTH (stack_events)) { + events = _cairo_malloc_ab_plus_c (num_events, + sizeof (cairo_bo_start_event_t) + + sizeof (cairo_bo_event_t *), + sizeof (cairo_bo_event_t *)); + if (unlikely (events == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event_ptrs = (cairo_bo_event_t **) (events + num_events); + } + + for (i = 0; i < num_events; i++) { + events[i].type = CAIRO_BO_EVENT_TYPE_START; + events[i].point.y = polygon->edges[i].top; + events[i].point.x = + _line_compute_intersection_x_for_y (&polygon->edges[i].line, + events[i].point.y); + + events[i].edge.edge = polygon->edges[i]; + events[i].edge.deferred_trap.right = NULL; + events[i].edge.prev = NULL; + events[i].edge.next = NULL; + events[i].edge.colinear = NULL; + + if (event_y) { + y = _cairo_fixed_integer_floor (events[i].point.y) - ymin; + events[i].edge.next = (cairo_bo_edge_t *) event_y[y]; + event_y[y] = (cairo_bo_start_event_t *) &events[i]; + } else + event_ptrs[i] = (cairo_bo_event_t *) &events[i]; + } + + if (event_y) { + for (y = i = 0; y < ymax && i < num_events; y++) { + cairo_bo_start_event_t *e; + int j = i; + for (e = event_y[y]; e; e = (cairo_bo_start_event_t *)e->edge.next) + event_ptrs[i++] = (cairo_bo_event_t *) e; + if (i > j + 1) + _cairo_bo_event_queue_sort (event_ptrs+j, i-j); + } + if (event_y != stack_event_y) + free (event_y); + } else + _cairo_bo_event_queue_sort (event_ptrs, i); + event_ptrs[i] = NULL; + +#if DEBUG_TRAPS + dump_edges (events, num_events, "bo-polygon-edges.txt"); +#endif + + /* XXX: This would be the convenient place to throw in multiple + * passes of the Bentley-Ottmann algorithm. It would merely + * require storing the results of each pass into a temporary + * cairo_traps_t. */ + status = _cairo_bentley_ottmann_tessellate_bo_edges (event_ptrs, num_events, + fill_rule, traps, + &intersections); +#if DEBUG_TRAPS + dump_traps (traps, "bo-polygon-out.txt"); +#endif + + if (events != stack_events) + free (events); + + return status; +} + +cairo_status_t +_cairo_bentley_ottmann_tessellate_traps (cairo_traps_t *traps, + cairo_fill_rule_t fill_rule) +{ + cairo_status_t status; + cairo_polygon_t polygon; + int i; + + if (unlikely (0 == traps->num_traps)) + return CAIRO_STATUS_SUCCESS; + +#if DEBUG_TRAPS + dump_traps (traps, "bo-traps-in.txt"); +#endif + + _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); + + for (i = 0; i < traps->num_traps; i++) { + status = _cairo_polygon_add_line (&polygon, + &traps->traps[i].left, + traps->traps[i].top, + traps->traps[i].bottom, + 1); + if (unlikely (status)) + goto CLEANUP; + + status = _cairo_polygon_add_line (&polygon, + &traps->traps[i].right, + traps->traps[i].top, + traps->traps[i].bottom, + -1); + if (unlikely (status)) + goto CLEANUP; + } + + _cairo_traps_clear (traps); + status = _cairo_bentley_ottmann_tessellate_polygon (traps, + &polygon, + fill_rule); + +#if DEBUG_TRAPS + dump_traps (traps, "bo-traps-out.txt"); +#endif + + CLEANUP: + _cairo_polygon_fini (&polygon); + + return status; +} + +#if 0 +static cairo_bool_t +edges_have_an_intersection_quadratic (cairo_bo_edge_t *edges, + int num_edges) + +{ + int i, j; + cairo_bo_edge_t *a, *b; + cairo_bo_point32_t intersection; + + /* We must not be given any upside-down edges. */ + for (i = 0; i < num_edges; i++) { + assert (_cairo_bo_point32_compare (&edges[i].top, &edges[i].bottom) < 0); + edges[i].line.p1.x <<= CAIRO_BO_GUARD_BITS; + edges[i].line.p1.y <<= CAIRO_BO_GUARD_BITS; + edges[i].line.p2.x <<= CAIRO_BO_GUARD_BITS; + edges[i].line.p2.y <<= CAIRO_BO_GUARD_BITS; + } + + for (i = 0; i < num_edges; i++) { + for (j = 0; j < num_edges; j++) { + if (i == j) + continue; + + a = &edges[i]; + b = &edges[j]; + + if (! _cairo_bo_edge_intersect (a, b, &intersection)) + continue; + + printf ("Found intersection (%d,%d) between (%d,%d)-(%d,%d) and (%d,%d)-(%d,%d)\n", + intersection.x, + intersection.y, + a->line.p1.x, a->line.p1.y, + a->line.p2.x, a->line.p2.y, + b->line.p1.x, b->line.p1.y, + b->line.p2.x, b->line.p2.y); + + return TRUE; + } + } + return FALSE; +} + +#define TEST_MAX_EDGES 10 + +typedef struct test { + const char *name; + const char *description; + int num_edges; + cairo_bo_edge_t edges[TEST_MAX_EDGES]; +} test_t; + +static test_t +tests[] = { + { + "3 near misses", + "3 edges all intersecting very close to each other", + 3, + { + { { 4, 2}, {0, 0}, { 9, 9}, NULL, NULL }, + { { 7, 2}, {0, 0}, { 2, 3}, NULL, NULL }, + { { 5, 2}, {0, 0}, { 1, 7}, NULL, NULL } + } + }, + { + "inconsistent data", + "Derived from random testing---was leading to skip list and edge list disagreeing.", + 2, + { + { { 2, 3}, {0, 0}, { 8, 9}, NULL, NULL }, + { { 2, 3}, {0, 0}, { 6, 7}, NULL, NULL } + } + }, + { + "failed sort", + "A test derived from random testing that leads to an inconsistent sort --- looks like we just can't attempt to validate the sweep line with edge_compare?", + 3, + { + { { 6, 2}, {0, 0}, { 6, 5}, NULL, NULL }, + { { 3, 5}, {0, 0}, { 5, 6}, NULL, NULL }, + { { 9, 2}, {0, 0}, { 5, 6}, NULL, NULL }, + } + }, + { + "minimal-intersection", + "Intersection of a two from among the smallest possible edges.", + 2, + { + { { 0, 0}, {0, 0}, { 1, 1}, NULL, NULL }, + { { 1, 0}, {0, 0}, { 0, 1}, NULL, NULL } + } + }, + { + "simple", + "A simple intersection of two edges at an integer (2,2).", + 2, + { + { { 1, 1}, {0, 0}, { 3, 3}, NULL, NULL }, + { { 2, 1}, {0, 0}, { 2, 3}, NULL, NULL } + } + }, + { + "bend-to-horizontal", + "With intersection truncation one edge bends to horizontal", + 2, + { + { { 9, 1}, {0, 0}, {3, 7}, NULL, NULL }, + { { 3, 5}, {0, 0}, {9, 9}, NULL, NULL } + } + } +}; + +/* + { + "endpoint", + "An intersection that occurs at the endpoint of a segment.", + { + { { 4, 6}, { 5, 6}, NULL, { { NULL }} }, + { { 4, 5}, { 5, 7}, NULL, { { NULL }} }, + { { 0, 0}, { 0, 0}, NULL, { { NULL }} }, + } + } + { + name = "overlapping", + desc = "Parallel segments that share an endpoint, with different slopes.", + edges = { + { top = { x = 2, y = 0}, bottom = { x = 1, y = 1}}, + { top = { x = 2, y = 0}, bottom = { x = 0, y = 2}}, + { top = { x = 0, y = 3}, bottom = { x = 1, y = 3}}, + { top = { x = 0, y = 3}, bottom = { x = 2, y = 3}}, + { top = { x = 0, y = 4}, bottom = { x = 0, y = 6}}, + { top = { x = 0, y = 5}, bottom = { x = 0, y = 6}} + } + }, + { + name = "hobby_stage_3", + desc = "A particularly tricky part of the 3rd stage of the 'hobby' test below.", + edges = { + { top = { x = -1, y = -2}, bottom = { x = 4, y = 2}}, + { top = { x = 5, y = 3}, bottom = { x = 9, y = 5}}, + { top = { x = 5, y = 3}, bottom = { x = 6, y = 3}}, + } + }, + { + name = "hobby", + desc = "Example from John Hobby's paper. Requires 3 passes of the iterative algorithm.", + edges = { + { top = { x = 0, y = 0}, bottom = { x = 9, y = 5}}, + { top = { x = 0, y = 0}, bottom = { x = 13, y = 6}}, + { top = { x = -1, y = -2}, bottom = { x = 9, y = 5}} + } + }, + { + name = "slope", + desc = "Edges with same start/stop points but different slopes", + edges = { + { top = { x = 4, y = 1}, bottom = { x = 6, y = 3}}, + { top = { x = 4, y = 1}, bottom = { x = 2, y = 3}}, + { top = { x = 2, y = 4}, bottom = { x = 4, y = 6}}, + { top = { x = 6, y = 4}, bottom = { x = 4, y = 6}} + } + }, + { + name = "horizontal", + desc = "Test of a horizontal edge", + edges = { + { top = { x = 1, y = 1}, bottom = { x = 6, y = 6}}, + { top = { x = 2, y = 3}, bottom = { x = 5, y = 3}} + } + }, + { + name = "vertical", + desc = "Test of a vertical edge", + edges = { + { top = { x = 5, y = 1}, bottom = { x = 5, y = 7}}, + { top = { x = 2, y = 4}, bottom = { x = 8, y = 5}} + } + }, + { + name = "congruent", + desc = "Two overlapping edges with the same slope", + edges = { + { top = { x = 5, y = 1}, bottom = { x = 5, y = 7}}, + { top = { x = 5, y = 2}, bottom = { x = 5, y = 6}}, + { top = { x = 2, y = 4}, bottom = { x = 8, y = 5}} + } + }, + { + name = "multi", + desc = "Several segments with a common intersection point", + edges = { + { top = { x = 1, y = 2}, bottom = { x = 5, y = 4} }, + { top = { x = 1, y = 1}, bottom = { x = 5, y = 5} }, + { top = { x = 2, y = 1}, bottom = { x = 4, y = 5} }, + { top = { x = 4, y = 1}, bottom = { x = 2, y = 5} }, + { top = { x = 5, y = 1}, bottom = { x = 1, y = 5} }, + { top = { x = 5, y = 2}, bottom = { x = 1, y = 4} } + } + } +}; +*/ + +static int +run_test (const char *test_name, + cairo_bo_edge_t *test_edges, + int num_edges) +{ + int i, intersections, passes; + cairo_bo_edge_t *edges; + cairo_array_t intersected_edges; + + printf ("Testing: %s\n", test_name); + + _cairo_array_init (&intersected_edges, sizeof (cairo_bo_edge_t)); + + intersections = _cairo_bentley_ottmann_intersect_edges (test_edges, num_edges, &intersected_edges); + if (intersections) + printf ("Pass 1 found %d intersections:\n", intersections); + + + /* XXX: Multi-pass Bentley-Ottmmann. Preferable would be to add a + * pass of Hobby's tolerance-square algorithm instead. */ + passes = 1; + while (intersections) { + int num_edges = _cairo_array_num_elements (&intersected_edges); + passes++; + edges = _cairo_malloc_ab (num_edges, sizeof (cairo_bo_edge_t)); + assert (edges != NULL); + memcpy (edges, _cairo_array_index (&intersected_edges, 0), num_edges * sizeof (cairo_bo_edge_t)); + _cairo_array_fini (&intersected_edges); + _cairo_array_init (&intersected_edges, sizeof (cairo_bo_edge_t)); + intersections = _cairo_bentley_ottmann_intersect_edges (edges, num_edges, &intersected_edges); + free (edges); + + if (intersections){ + printf ("Pass %d found %d remaining intersections:\n", passes, intersections); + } else { + if (passes > 3) + for (i = 0; i < passes; i++) + printf ("*"); + printf ("No remainining intersections found after pass %d\n", passes); + } + } + + if (edges_have_an_intersection_quadratic (_cairo_array_index (&intersected_edges, 0), + _cairo_array_num_elements (&intersected_edges))) + printf ("*** FAIL ***\n"); + else + printf ("PASS\n"); + + _cairo_array_fini (&intersected_edges); + + return 0; +} + +#define MAX_RANDOM 300 + +int +main (void) +{ + char random_name[] = "random-XX"; + cairo_bo_edge_t random_edges[MAX_RANDOM], *edge; + unsigned int i, num_random; + test_t *test; + + for (i = 0; i < ARRAY_LENGTH (tests); i++) { + test = &tests[i]; + run_test (test->name, test->edges, test->num_edges); + } + + for (num_random = 0; num_random < MAX_RANDOM; num_random++) { + srand (0); + for (i = 0; i < num_random; i++) { + do { + edge = &random_edges[i]; + edge->line.p1.x = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); + edge->line.p1.y = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); + edge->line.p2.x = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); + edge->line.p2.y = (int32_t) (10.0 * (rand() / (RAND_MAX + 1.0))); + if (edge->line.p1.y > edge->line.p2.y) { + int32_t tmp = edge->line.p1.y; + edge->line.p1.y = edge->line.p2.y; + edge->line.p2.y = tmp; + } + } while (edge->line.p1.y == edge->line.p2.y); + } + + sprintf (random_name, "random-%02d", num_random); + + run_test (random_name, random_edges, num_random); + } + + return 0; +} +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-beos-surface.cpp b/Build/source/libs/cairo/cairo-src/src/cairo-beos-surface.cpp new file mode 100644 index 00000000000..c97641685fc --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-beos-surface.cpp @@ -0,0 +1,984 @@ +/* vim:set ts=8 sw=4 noet cin: */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Christian Biesinger + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Christian Biesinger + * + * + * Contributor(s): + */ + +// This is a C++ file in order to use the C++ BeOS API + +#include "cairoint.h" + +#include "cairo-beos.h" + +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" + +#include + +#include +#include +#if 0 +#include +#endif +#include +#include +#include + +/** + * SECTION:beos-surface + * @Title: BeOS Surfaces + * @Short_Description: BeOS surface support + * @See_Also: #cairo_surface_t + * + * The BeOS surface is used to render cairo graphics to BeOS views + * and bitmaps. + **/ + +#define CAIRO_INT_STATUS_SUCCESS (cairo_int_status_t)(CAIRO_STATUS_SUCCESS) + +struct cairo_beos_surface_t { + cairo_surface_t base; + + cairo_region_t *clip_region; + + BView* view; + + /* + * A view is either attached to a bitmap, a window, or unattached. + * If it is attached to a window, we can copy data out of it using BScreen. + * If it is attached to a bitmap, we can read the bitmap data. + * If it is not attached, it doesn't draw anything, we need not bother. + * + * Since there doesn't seem to be a way to get the bitmap from a view if it + * is attached to one, we have to use a special surface creation function. + */ + + BBitmap* bitmap; + + // If true, surface and view should be deleted when this surface is + // destroyed + bool owns_bitmap_view; +}; + +class AutoLockView { + public: + AutoLockView(BView* view) : mView(view) { + mOK = mView->LockLooper(); + } + + ~AutoLockView() { + if (mOK) + mView->UnlockLooper(); + } + + operator bool() { + return mOK; + } + + private: + BView* mView; + bool mOK; +}; + +static cairo_surface_t * +_cairo_beos_surface_create_internal (BView* view, + BBitmap* bmp, + bool owns_bitmap_view = false); + +static inline BRect +_cairo_rectangle_to_brect (const cairo_rectangle_int_t* rect) +{ + // A BRect is one pixel wider than you'd think + return BRect (rect->x, rect->y, + rect->x + rect->width - 1, + rect->y + rect->height - 1); +} + +static inline cairo_rectangle_int_t +_brect_to_cairo_rectangle (const BRect &rect) +{ + cairo_rectangle_int_t retval; + retval.x = floor (rect.left); + retval.y = floor (rect.top); + retval.width = ceil (rect.right) - retval.x + 1; + retval.height = ceil (rect.bottom) - rectval.y + 1; + return retval; +} + +static inline rgb_color +_cairo_color_to_be_color (const cairo_color_t *color) +{ + // This factor ensures a uniform distribution of numbers + const float factor = 256 - 1e-5; + // Using doubles to have non-premultiplied colors + rgb_color be_color = { uint8(color->red * factor), + uint8(color->green * factor), + uint8(color->blue * factor), + uint8(color->alpha * factor) }; + + return be_color; +} + +enum ViewCopyStatus { + OK, + NOT_VISIBLE, // The view or the interest rect is not visible on screen + ERROR // The view was visible, but the rect could not be copied. Probably OOM +}; + +/** + * _cairo_beos_view_to_bitmap: + * @bitmap: [out] The resulting bitmap. + * @rect: [out] The rectangle that was copied, in the view's coordinate system + * @interestRect: If non-null, only this part of the view will be copied (view's coord system). + * + * Gets the contents of the view as a BBitmap*. Caller must delete the bitmap. + **/ +static ViewCopyStatus +_cairo_beos_view_to_bitmap (BView* view, + BBitmap** bitmap, + BRect* rect = NULL, + const BRect* interestRect = NULL) +{ + *bitmap = NULL; + + BWindow* wnd = view->Window(); + // If we have no window, can't do anything + if (!wnd) + return NOT_VISIBLE; + + view->Sync(); + wnd->Sync(); + +#if 0 + // Is it a direct window? + BDirectWindow* directWnd = dynamic_cast(wnd); + if (directWnd) { + // WRITEME + } +#endif + + // Is it visible? If so, we can copy the content off the screen + if (wnd->IsHidden()) + return NOT_VISIBLE; + + BRect rectToCopy(view->Bounds()); + if (interestRect) + rectToCopy = rectToCopy & *interestRect; + + if (!rectToCopy.IsValid()) + return NOT_VISIBLE; + + BScreen screen(wnd); + BRect screenRect(view->ConvertToScreen(rectToCopy)); + screenRect = screenRect & screen.Frame(); + + if (!screen.IsValid()) + return NOT_VISIBLE; + + if (rect) + *rect = view->ConvertFromScreen(screenRect); + + if (screen.GetBitmap(bitmap, false, &screenRect) == B_OK) + return OK; + + return ERROR; +} + +static void +unpremultiply_bgra (unsigned char* data, + int width, + int height, + int stride, + unsigned char* retdata) +{ + unsigned char* end = data + stride * height; + for (unsigned char* in = data, *out = retdata; + in < end; + in += stride, out += stride) + { + for (int i = 0; i < width; i ++) { + uint8_t *b = &out[4*i]; + uint32_t pixel; + uint8_t alpha; + + memcpy (&pixel, &data[4*i], sizeof (uint32_t)); + alpha = pixel & 0xff; + if (alpha == 0) { + b[0] = b[1] = b[2] = b[3] = 0; + } else { + b[0] = (((pixel >> 24) & 0xff) * 255 + alpha / 2) / alpha; + b[1] = (((pixel >> 16) & 0xff) * 255 + alpha / 2) / alpha; + b[2] = (((pixel >> 8) & 0xff) * 255 + alpha / 2) / alpha; + b[3] = alpha; + } + } + } +} + +static inline int +multiply_alpha (int alpha, int color) +{ + int temp = (alpha * color) + 0x80; + return ((temp + (temp >> 8)) >> 8); +} + +static unsigned char* +premultiply_bgra (unsigned char* data, + int width, + int height, + int stride) +{ + uint8_t * retdata = reinterpret_cast(_cairo_malloc_ab(height, stride)); + if (!retdata) + return NULL; + + uint8_t * end = data + stride * height; + for (uint8_t * in = data, *out = retdata; + in < end; + in += stride, out += stride) + { + for (int i = 0; i < width; i ++) { + uint8_t *base = &in[4*i]; + uint8_t alpha = base[3]; + uint32_t p; + + if (alpha == 0) { + p = 0; + } else { + uint8_t blue = base[0]; + uint8_t green = base[1]; + uint8_t red = base[2]; + + if (alpha != 0xff) { + blue = multiply_alpha (alpha, blue); + green = multiply_alpha (alpha, green); + red = multiply_alpha (alpha, red); + } + p = (alpha << 0) | (red << 8) | (green << 16) | (blue << 24); + } + memcpy (&out[4*i], &p, sizeof (uint32_t)); + } + } + return retdata; +} + +static cairo_int_status_t +_cairo_beos_surface_set_clip_region (cairo_beos_surface_t *surface, + cairo_region_t *region) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + AutoLockView locker(surface->view); + assert (locker); + + if (region == surface->clip_region) + return CAIRO_INT_STATUS_SUCCESS; + + cairo_region_destroy (surface->clip_region); + surface->clip_region = cairo_region_reference (region); + + if (region == NULL) { + // No clipping + surface->view->ConstrainClippingRegion(NULL); + return CAIRO_INT_STATUS_SUCCESS; + } + + int count = cairo_region_num_rectangles (region); + BRegion bregion; + for (int i = 0; i < count; ++i) { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (region, i, &rect); + // Have to subtract one, because for pixman, the second coordinate + // lies outside the rectangle. + bregion.Include (_cairo_rectangle_to_brect (&rect)); + } + surface->view->ConstrainClippingRegion(&bregion); + return CAIRO_INT_STATUS_SUCCESS; +} + + +/** + * _cairo_beos_bitmap_to_surface: + * + * Returns an addrefed image surface for a BBitmap. The bitmap need not outlive + * the surface. + **/ +static cairo_image_surface_t* +_cairo_beos_bitmap_to_surface (BBitmap* bitmap) +{ + color_space format = bitmap->ColorSpace(); + if (format != B_RGB32 && format != B_RGBA32) { + BBitmap bmp(bitmap->Bounds(), B_RGB32, true); + BView view(bitmap->Bounds(), "Cairo bitmap drawing view", + B_FOLLOW_ALL_SIDES, 0); + bmp.AddChild(&view); + + view.LockLooper(); + + view.DrawBitmap(bitmap, BPoint(0.0, 0.0)); + view.Sync(); + + cairo_image_surface_t* imgsurf = _cairo_beos_bitmap_to_surface(&bmp); + + view.UnlockLooper(); + bmp.RemoveChild(&view); + return imgsurf; + } + + cairo_format_t cformat = format == B_RGB32 ? + CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32; + + BRect bounds(bitmap->Bounds()); + unsigned char* bits = reinterpret_cast(bitmap->Bits()); + int width = bounds.IntegerWidth() + 1; + int height = bounds.IntegerHeight() + 1; + unsigned char* premultiplied; + if (cformat == CAIRO_FORMAT_ARGB32) { + premultiplied = premultiply_bgra (bits, width, height, + bitmap->BytesPerRow()); + } else { + premultiplied = reinterpret_cast( + _cairo_malloc_ab(bitmap->BytesPerRow(), height)); + if (premultiplied) + memcpy(premultiplied, bits, bitmap->BytesPerRow() * height); + } + if (!premultiplied) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + cairo_image_surface_t* surf = reinterpret_cast + (cairo_image_surface_create_for_data(premultiplied, + cformat, + width, + height, + bitmap->BytesPerRow())); + if (surf->base.status) + free(premultiplied); + else + _cairo_image_surface_assume_ownership_of_data(surf); + return surf; +} + +/** + * _cairo_image_surface_to_bitmap: + * + * Converts an image surface to a BBitmap. The return value must be freed with + * delete. + **/ +static BBitmap* +_cairo_image_surface_to_bitmap (cairo_image_surface_t* surface) +{ + BRect size(0.0, 0.0, surface->width - 1, surface->height - 1); + switch (surface->format) { + case CAIRO_FORMAT_ARGB32: { + BBitmap* data = new BBitmap(size, B_RGBA32); + unpremultiply_bgra (surface->data, + surface->width, + surface->height, + surface->stride, + reinterpret_cast(data->Bits())); + return data; + } + case CAIRO_FORMAT_RGB24: { + BBitmap* data = new BBitmap(size, B_RGB32); + memcpy(data->Bits(), surface->data, surface->height * surface->stride); + return data; + } + default: + assert(0); + return NULL; + } +} + +/** + * _cairo_op_to_be_op: + * + * Converts a cairo drawing operator to a beos drawing_mode. Returns true if + * the operator could be converted, false otherwise. + **/ +static bool +_cairo_op_to_be_op (cairo_operator_t cairo_op, + drawing_mode* beos_op) +{ + switch (cairo_op) { + case CAIRO_OPERATOR_SOURCE: + *beos_op = B_OP_COPY; + return true; + case CAIRO_OPERATOR_OVER: + *beos_op = B_OP_ALPHA; + return true; + + case CAIRO_OPERATOR_ADD: + // Does not actually work + // XXX This is a fundamental compositing operator, it has to work! +#if 1 + return false; +#else + *beos_op = B_OP_ADD; + return true; +#endif + + case CAIRO_OPERATOR_CLEAR: + // Does not map to B_OP_ERASE - it replaces the dest with the low + // color, instead of transparency; could be done by setting low + // color appropriately. + + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_ATOP: + + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_DEST_ATOP: + + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_SATURATE: + + default: + return false; + } +} + +static cairo_surface_t * +_cairo_beos_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + + if (width <= 0) + width = 1; + if (height <= 0) + height = 1; + + BRect rect(0.0, 0.0, width - 1, height - 1); + BBitmap* bmp; + switch (content) { + case CAIRO_CONTENT_ALPHA: + return NULL; + case CAIRO_CONTENT_COLOR_ALPHA: + bmp = new BBitmap(rect, B_RGBA32, true); + break; + case CAIRO_CONTENT_COLOR: + // Match the color depth + if (surface->bitmap) { + color_space space = surface->bitmap->ColorSpace(); + // No alpha was requested -> make sure not to return + // a surface with alpha + if (space == B_RGBA32) + space = B_RGB32; + if (space == B_RGBA15) + space = B_RGB15; + bmp = new BBitmap(rect, space, true); + } else { + BScreen scr(surface->view->Window()); + color_space space = B_RGB32; + if (scr.IsValid()) + space = scr.ColorSpace(); + bmp = new BBitmap(rect, space, true); + } + break; + default: + ASSERT_NOT_REACHED; + return NULL; + } + BView* view = new BView(rect, "Cairo bitmap view", B_FOLLOW_ALL_SIDES, 0); + bmp->AddChild(view); + return _cairo_beos_surface_create_internal(view, bmp, true); +} + +static cairo_status_t +_cairo_beos_surface_finish (void *abstract_surface) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + if (surface->owns_bitmap_view) { + if (surface->bitmap) + surface->bitmap->RemoveChild(surface->view); + + delete surface->view; + delete surface->bitmap; + + surface->view = NULL; + surface->bitmap = NULL; + } + + cairo_region_destroy (surface->clip_region); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_beos_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + AutoLockView locker(surface->view); + if (!locker) + return CAIRO_STATUS_NO_MEMORY; /// XXX not exactly right, but what can we do? + + + surface->view->Sync(); + + if (surface->bitmap) { + *image_out = _cairo_beos_bitmap_to_surface (surface->bitmap); + if (unlikely ((*image_out)->base.status)) + return (*image_out)->base.status; + + *image_extra = NULL; + return CAIRO_STATUS_SUCCESS; + } + + BBitmap* bmp; + if (_cairo_beos_view_to_bitmap(surface->view, &bmp) != OK) + return CAIRO_STATUS_NO_MEMORY; /// XXX incorrect if the error was NOT_VISIBLE + + *image_out = _cairo_beos_bitmap_to_surface (bmp); + if (unlikely ((*image_out)->base.status)) { + delete bmp; + return (*image_out)->base.status; + } + *image_extra = bmp; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_beos_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); + + if (image_extra != NULL) { + BBitmap* bmp = static_cast(image_extra); + delete bmp; + } +} + +static cairo_status_t +_cairo_beos_surface_acquire_dest_image (void *abstract_surface, + cairo_rectangle_int_t *interest_rect, + cairo_image_surface_t **image_out, + cairo_rectangle_int_t *image_rect, + void **image_extra) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + + AutoLockView locker(surface->view); + if (!locker) { + *image_out = NULL; + *image_extra = NULL; + return (cairo_status_t) CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + if (surface->bitmap) { + surface->view->Sync(); + *image_out = _cairo_beos_bitmap_to_surface(surface->bitmap); + if (unlikely ((*image_out)->base.status)) + return (*image_out)->base.status; + + image_rect->x = 0; + image_rect->y = 0; + image_rect->width = (*image_out)->width; + image_rect->height = (*image_out)->height; + + *image_extra = NULL; + return CAIRO_STATUS_SUCCESS; + } + + BRect b_interest_rect (_cairo_rectangle_to_brect (interest_rect)); + + BRect rect; + BBitmap* bitmap; + ViewCopyStatus status = _cairo_beos_view_to_bitmap(surface->view, &bitmap, + &rect, &b_interest_rect); + if (status == NOT_VISIBLE) { + *image_out = NULL; + *image_extra = NULL; + return CAIRO_STATUS_SUCCESS; + } + if (status == ERROR) + return CAIRO_STATUS_NO_MEMORY; + + *image_rect = _brect_to_cairo_rectangle(rect); + *image_out = _cairo_beos_bitmap_to_surface(bitmap); + delete bitmap; + if (unlikely ((*image_out)->base.status)) + return (*image_out)->base.status; + + *image_extra = NULL; + + return CAIRO_STATUS_SUCCESS; +} + + +static void +_cairo_beos_surface_release_dest_image (void *abstract_surface, + cairo_rectangle_int_t *intersect_rect, + cairo_image_surface_t *image, + cairo_rectangle_int_t *image_rect, + void *image_extra) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + + AutoLockView locker(surface->view); + if (!locker) + return; + + BBitmap* bitmap_to_draw = _cairo_image_surface_to_bitmap(image); + surface->view->PushState(); + + surface->view->SetDrawingMode(B_OP_COPY); + + surface->view->DrawBitmap (bitmap_to_draw, + _cairo_rectangle_to_brect (image_rect)); + + surface->view->PopState(); + + delete bitmap_to_draw; + cairo_surface_destroy(&image->base); +} + +static cairo_int_status_t +_cairo_beos_surface_composite (cairo_operator_t op, + cairo_pattern_t *src, + cairo_pattern_t *mask, + void *dst, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height, + cairo_region_t *clip_region) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + dst); + cairo_int_status_t status; + AutoLockView locker(surface->view); + if (!locker) + return CAIRO_INT_STATUS_SUCCESS; + + drawing_mode mode; + if (!_cairo_op_to_be_op(op, &mode)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + // XXX Masks are not yet supported + if (mask) + return CAIRO_INT_STATUS_UNSUPPORTED; + + // XXX should eventually support the others + if (src->type != CAIRO_PATTERN_TYPE_SURFACE || + src->extend != CAIRO_EXTEND_NONE) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + // Can we maybe support other matrices as well? (scale? if the filter is right) + int itx, ity; + if (!_cairo_matrix_is_integer_translation(&src->matrix, &itx, &ity)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_beos_surface_set_clip_region (surface, clip_region); + if (unlikely (status)) + return status; + + BRect srcRect(src_x + itx, + src_y + ity, + src_x + itx + width - 1, + src_y + ity + height - 1); + BRect dstRect(dst_x, dst_y, dst_x + width - 1, dst_y + height - 1); + + cairo_surface_t* src_surface = reinterpret_cast(src)-> + surface; + + // Get a bitmap + BBitmap* bmp = NULL; + bool free_bmp = false; + if (_cairo_surface_is_image(src_surface)) { + cairo_image_surface_t* img_surface = + reinterpret_cast(src_surface); + + bmp = _cairo_image_surface_to_bitmap(img_surface); + free_bmp = true; + } else if (src_surface->backend == surface->base.backend) { + cairo_beos_surface_t *beos_surface = + reinterpret_cast(src_surface); + if (beos_surface->bitmap) { + AutoLockView locker(beos_surface->view); + if (locker) + beos_surface->view->Sync(); + bmp = beos_surface->bitmap; + } else { + _cairo_beos_view_to_bitmap(surface->view, &bmp); + free_bmp = true; + } + } + + if (!bmp) + return CAIRO_INT_STATUS_UNSUPPORTED; + + // So, BeOS seems to screw up painting an opaque bitmap onto a + // translucent one (it makes them partly transparent). Just return + // unsupported. + if (bmp->ColorSpace() == B_RGB32 && surface->bitmap && + surface->bitmap->ColorSpace() == B_RGBA32 && + (mode == B_OP_COPY || mode == B_OP_ALPHA)) + { + if (free_bmp) + delete bmp; + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + // Draw it on screen. + surface->view->PushState(); + + // If our image rect is only a subrect of the desired size, and we + // aren't using B_OP_ALPHA, then we need to fill the rect first. + if (mode == B_OP_COPY && !bmp->Bounds().Contains(srcRect)) { + rgb_color black = { 0, 0, 0, 0 }; + + surface->view->SetDrawingMode(mode); + surface->view->SetHighColor(black); + surface->view->FillRect(dstRect); + } + + if (mode == B_OP_ALPHA && bmp->ColorSpace() == B_RGB32) { + mode = B_OP_COPY; + } + surface->view->SetDrawingMode(mode); + + if (surface->bitmap && surface->bitmap->ColorSpace() == B_RGBA32) + surface->view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); + else + surface->view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); + + surface->view->DrawBitmap(bmp, srcRect, dstRect); + + surface->view->PopState(); + + if (free_bmp) + delete bmp; + + return CAIRO_INT_STATUS_SUCCESS; +} + + +static cairo_int_status_t +_cairo_beos_surface_fill_rectangles (void *abstract_surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_rectangle_int_t *rects, + int num_rects, + cairo_region_t *clip_region) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + cairo_int_status_t status; + + if (num_rects <= 0) + return CAIRO_INT_STATUS_SUCCESS; + + AutoLockView locker(surface->view); + if (!locker) + return CAIRO_INT_STATUS_SUCCESS; + + drawing_mode mode; + if (!_cairo_op_to_be_op(op, &mode)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_beos_surface_set_clip_region (surface, clip_region); + if (unlikely (status)) + return status; + + rgb_color be_color = _cairo_color_to_be_color(color); + + if (mode == B_OP_ALPHA && be_color.alpha == 0xFF) + mode = B_OP_COPY; + + // For CAIRO_OPERATOR_SOURCE, cairo expects us to use the premultiplied + // color info. This is only relevant when drawing into an rgb24 buffer + // (as for others, we can convert when asked for the image) + if (mode == B_OP_COPY && be_color.alpha != 0xFF && + (!surface->bitmap || surface->bitmap->ColorSpace() != B_RGBA32)) + { + be_color.red = color->red_short >> 8; + be_color.green = color->green_short >> 8; + be_color.blue = color->blue_short >> 8; + } + + surface->view->PushState(); + + surface->view->SetDrawingMode(mode); + surface->view->SetHighColor(be_color); + if (surface->bitmap && surface->bitmap->ColorSpace() == B_RGBA32) + surface->view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE); + else + surface->view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); + + for (int i = 0; i < num_rects; ++i) + surface->view->FillRect (_cairo_rectangle_to_brect (&rects[i])); + + surface->view->PopState(); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_beos_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_beos_surface_t *surface = reinterpret_cast( + abstract_surface); + AutoLockView locker(surface->view); + if (!locker) + return FALSE; + + *rectangle = _brect_to_cairo_rectangle (surface->view->Bounds()); + return TRUE; +} + +static const struct _cairo_surface_backend cairo_beos_surface_backend = { + CAIRO_SURFACE_TYPE_BEOS, + _cairo_beos_surface_create_similar, + _cairo_beos_surface_finish, + _cairo_beos_surface_acquire_source_image, + _cairo_beos_surface_release_source_image, + _cairo_beos_surface_acquire_dest_image, + _cairo_beos_surface_release_dest_image, + NULL, /* clone_similar */ + _cairo_beos_surface_composite, /* composite */ + _cairo_beos_surface_fill_rectangles, + NULL, /* composite_trapezoids */ + NULL, /* create_span_renderer */ + NULL, /* check_span_renderer */ + NULL, /* copy_page */ + NULL, /* show_page */ + _cairo_beos_surface_get_extents, + NULL, /* old_show_glyphs */ + NULL, /* get_font_options */ + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + NULL, /* scaled_font_fini */ + NULL, /* scaled_glyph_fini */ + + NULL, /* paint */ + NULL, /* mask */ + NULL, /* stroke */ + NULL, /* fill */ + NULL /* show_glyphs */ +}; + +static cairo_surface_t * +_cairo_beos_surface_create_internal (BView* view, + BBitmap* bmp, + bool owns_bitmap_view) +{ + // Must use malloc, because cairo code will use free() on the surface + cairo_beos_surface_t *surface = static_cast( + malloc(sizeof(cairo_beos_surface_t))); + if (surface == NULL) { + _cairo_error (CAIRO_STATUS_NO_MEMORY); + return const_cast(&_cairo_surface_nil); + } + + cairo_content_t content = CAIRO_CONTENT_COLOR; + if (bmp && (bmp->ColorSpace() == B_RGBA32 || bmp->ColorSpace() == B_RGBA15)) + content = CAIRO_CONTENT_COLOR_ALPHA; + _cairo_surface_init (&surface->base, + &cairo_beos_surface_backend, + NULL, /* device */ + content); + + surface->view = view; + surface->bitmap = bmp; + surface->owns_bitmap_view = owns_bitmap_view; + + surface->clip_region = NULL; + + return &surface->base; +} + +/** + * cairo_beos_surface_create: + * @view: The view to draw on + * + * Creates a Cairo surface that draws onto a BeOS BView. + * The caller must ensure that the view does not get deleted before the surface. + * If the view is attached to a bitmap rather than an on-screen window, use + * cairo_beos_surface_create_for_bitmap() instead of this function. + * + * Since: TBD + **/ +cairo_surface_t * +cairo_beos_surface_create (BView* view) +{ + return cairo_beos_surface_create_for_bitmap(view, NULL); +} + +/** + * cairo_beos_surface_create_for_bitmap: + * @view: The view to draw on + * @bmp: The bitmap to which the view is attached + * + * Creates a Cairo surface that draws onto a BeOS BView which is attached to a + * BBitmap. + * The caller must ensure that the view and the bitmap do not get deleted + * before the surface. + * + * For views that draw to a bitmap (as opposed to a screen), use this function + * rather than cairo_beos_surface_create(). Not using this function WILL lead to + * incorrect behaviour. + * + * For now, only views that draw to the entire area of bmp are supported. + * The view must already be attached to the bitmap. + * + * Since: TBD + **/ +cairo_surface_t * +cairo_beos_surface_create_for_bitmap (BView* view, + BBitmap* bmp) +{ + return _cairo_beos_surface_create_internal(view, bmp); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-beos.h b/Build/source/libs/cairo/cairo-src/src/cairo-beos.h new file mode 100644 index 00000000000..fdb89a6c4dc --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-beos.h @@ -0,0 +1,60 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Christian Biesinger + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Christian Biesinger + * + * + * Contributor(s): + */ + +#ifndef CAIRO_BEOS_H +#define CAIRO_BEOS_H + +#include "cairo.h" + +#if CAIRO_HAS_BEOS_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_beos_surface_create (BView* view); + +cairo_public cairo_surface_t * +cairo_beos_surface_create_for_bitmap (BView* view, + BBitmap* bmp); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_BEOS_SURFACE */ +# error Cairo was not compiled with support for the beos backend +#endif /* CAIRO_HAS_BEOS_SURFACE */ + +#endif /* CAIRO_BEOS_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-botor-scan-converter.c b/Build/source/libs/cairo/cairo-src/src/cairo-botor-scan-converter.c new file mode 100644 index 00000000000..515305bf24e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-botor-scan-converter.c @@ -0,0 +1,2164 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2007 David Turner + * Copyright © 2008 M Joonas Pihlaja + * Copyright © 2008 Chris Wilson + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * M Joonas Pihlaja + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-list-inline.h" +#include "cairo-freelist-private.h" +#include "cairo-combsort-inline.h" + +#include + +#define STEP_X CAIRO_FIXED_ONE +#define STEP_Y CAIRO_FIXED_ONE +#define UNROLL3(x) x x x + +#define STEP_XY (2*STEP_X*STEP_Y) /* Unit area in the step. */ +#define AREA_TO_ALPHA(c) (((c)*255 + STEP_XY/2) / STEP_XY) + +typedef struct _cairo_bo_intersect_ordinate { + int32_t ordinate; + enum { EXACT, INEXACT } exactness; +} cairo_bo_intersect_ordinate_t; + +typedef struct _cairo_bo_intersect_point { + cairo_bo_intersect_ordinate_t x; + cairo_bo_intersect_ordinate_t y; +} cairo_bo_intersect_point_t; + +struct quorem { + cairo_fixed_t quo; + cairo_fixed_t rem; +}; + +struct run { + struct run *next; + int sign; + cairo_fixed_t y; +}; + +typedef struct edge { + cairo_list_t link; + + cairo_edge_t edge; + + /* Current x coordinate and advancement. + * Initialised to the x coordinate of the top of the + * edge. The quotient is in cairo_fixed_t units and the + * remainder is mod dy in cairo_fixed_t units. + */ + cairo_fixed_t dy; + struct quorem x; + struct quorem dxdy; + struct quorem dxdy_full; + + cairo_bool_t vertical; + unsigned int flags; + + int current_sign; + struct run *runs; +} edge_t; + +enum { + START = 0x1, + STOP = 0x2, +}; + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef enum { + EVENT_TYPE_STOP, + EVENT_TYPE_INTERSECTION, + EVENT_TYPE_START +} event_type_t; + +typedef struct _event { + cairo_fixed_t y; + event_type_t type; +} event_t; + +typedef struct _start_event { + cairo_fixed_t y; + event_type_t type; + edge_t *edge; +} start_event_t; + +typedef struct _queue_event { + cairo_fixed_t y; + event_type_t type; + edge_t *e1; + edge_t *e2; +} queue_event_t; + +typedef struct _pqueue { + int size, max_size; + + event_t **elements; + event_t *elements_embedded[1024]; +} pqueue_t; + +struct cell { + struct cell *prev; + struct cell *next; + int x; + int uncovered_area; + int covered_height; +}; + +typedef struct _sweep_line { + cairo_list_t active; + cairo_list_t stopped; + cairo_list_t *insert_cursor; + cairo_bool_t is_vertical; + + cairo_fixed_t current_row; + cairo_fixed_t current_subrow; + + struct coverage { + struct cell head; + struct cell tail; + + struct cell *cursor; + int count; + + cairo_freepool_t pool; + } coverage; + + struct event_queue { + pqueue_t pq; + event_t **start_events; + + cairo_freepool_t pool; + } queue; + + cairo_freepool_t runs; + + jmp_buf unwind; +} sweep_line_t; + +cairo_always_inline static struct quorem +floored_divrem (int a, int b) +{ + struct quorem qr; + qr.quo = a/b; + qr.rem = a%b; + if ((a^b)<0 && qr.rem) { + qr.quo--; + qr.rem += b; + } + return qr; +} + +static struct quorem +floored_muldivrem(int x, int a, int b) +{ + struct quorem qr; + long long xa = (long long)x*a; + qr.quo = xa/b; + qr.rem = xa%b; + if ((xa>=0) != (b>=0) && qr.rem) { + qr.quo--; + qr.rem += b; + } + return qr; +} + +static cairo_fixed_t +line_compute_intersection_x_for_y (const cairo_line_t *line, + cairo_fixed_t y) +{ + cairo_fixed_t x, dy; + + if (y == line->p1.y) + return line->p1.x; + if (y == line->p2.y) + return line->p2.x; + + x = line->p1.x; + dy = line->p2.y - line->p1.y; + if (dy != 0) { + x += _cairo_fixed_mul_div_floor (y - line->p1.y, + line->p2.x - line->p1.x, + dy); + } + + return x; +} + +/* + * We need to compare the x-coordinates of a pair of lines for a particular y, + * without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy + * - (Y - A_y) * A_dx * B_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 128 bit arithmetic. For certain, but common, + * input we can reduce this down to a single 32 bit compare by inspecting the + * deltas. + * + * (And put the burden of the work on developing fast 128 bit ops, which are + * required throughout the tessellator.) + * + * See the similar discussion for _slope_compare(). + */ +static int +edges_compare_x_for_y_general (const cairo_edge_t *a, + const cairo_edge_t *b, + int32_t y) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t dx; + int32_t adx, ady; + int32_t bdx, bdy; + enum { + HAVE_NONE = 0x0, + HAVE_DX = 0x1, + HAVE_ADX = 0x2, + HAVE_DX_ADX = HAVE_DX | HAVE_ADX, + HAVE_BDX = 0x4, + HAVE_DX_BDX = HAVE_DX | HAVE_BDX, + HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, + HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX + } have_dx_adx_bdx = HAVE_ALL; + + /* don't bother solving for abscissa if the edges' bounding boxes + * can be used to order them. */ + { + int32_t amin, amax; + int32_t bmin, bmax; + if (a->line.p1.x < a->line.p2.x) { + amin = a->line.p1.x; + amax = a->line.p2.x; + } else { + amin = a->line.p2.x; + amax = a->line.p1.x; + } + if (b->line.p1.x < b->line.p2.x) { + bmin = b->line.p1.x; + bmax = b->line.p2.x; + } else { + bmin = b->line.p2.x; + bmax = b->line.p1.x; + } + if (amax < bmin) return -1; + if (amin > bmax) return +1; + } + + ady = a->line.p2.y - a->line.p1.y; + adx = a->line.p2.x - a->line.p1.x; + if (adx == 0) + have_dx_adx_bdx &= ~HAVE_ADX; + + bdy = b->line.p2.y - b->line.p1.y; + bdx = b->line.p2.x - b->line.p1.x; + if (bdx == 0) + have_dx_adx_bdx &= ~HAVE_BDX; + + dx = a->line.p1.x - b->line.p1.x; + if (dx == 0) + have_dx_adx_bdx &= ~HAVE_DX; + +#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) +#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->line.p1.y) +#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->line.p1.y) + switch (have_dx_adx_bdx) { + default: + case HAVE_NONE: + return 0; + case HAVE_DX: + /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ + return dx; /* ady * bdy is positive definite */ + case HAVE_ADX: + /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ + return adx; /* bdy * (y - a->top.y) is positive definite */ + case HAVE_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy */ + return -bdx; /* ady * (y - b->top.y) is positive definite */ + case HAVE_ADX_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ + if ((adx ^ bdx) < 0) { + return adx; + } else if (a->line.p1.y == b->line.p1.y) { /* common origin */ + cairo_int64_t adx_bdy, bdx_ady; + + /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ + + adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } else + return _cairo_int128_cmp (A, B); + case HAVE_DX_ADX: + /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ + if ((-adx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t ady_dx, dy_adx; + + ady_dx = _cairo_int32x32_64_mul (ady, dx); + dy_adx = _cairo_int32x32_64_mul (a->line.p1.y - y, adx); + + return _cairo_int64_cmp (ady_dx, dy_adx); + } + case HAVE_DX_BDX: + /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ + if ((bdx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t bdy_dx, dy_bdx; + + bdy_dx = _cairo_int32x32_64_mul (bdy, dx); + dy_bdx = _cairo_int32x32_64_mul (y - b->line.p1.y, bdx); + + return _cairo_int64_cmp (bdy_dx, dy_bdx); + } + case HAVE_ALL: + /* XXX try comparing (a->line.p2.x - b->line.p2.x) et al */ + return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); + } +#undef B +#undef A +#undef L +} + +/* + * We need to compare the x-coordinate of a line for a particular y wrt to a + * given x, without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ X + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy (and (Y - A_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 64 bit arithmetic. + * + * See the similar discussion for _slope_compare() and + * edges_compare_x_for_y_general(). + */ +static int +edge_compare_for_y_against_x (const cairo_edge_t *a, + int32_t y, + int32_t x) +{ + int32_t adx, ady; + int32_t dx, dy; + cairo_int64_t L, R; + + if (a->line.p1.x <= a->line.p2.x) { + if (x < a->line.p1.x) + return 1; + if (x > a->line.p2.x) + return -1; + } else { + if (x < a->line.p2.x) + return 1; + if (x > a->line.p1.x) + return -1; + } + + adx = a->line.p2.x - a->line.p1.x; + dx = x - a->line.p1.x; + + if (adx == 0) + return -dx; + if (dx == 0 || (adx ^ dx) < 0) + return adx; + + dy = y - a->line.p1.y; + ady = a->line.p2.y - a->line.p1.y; + + L = _cairo_int32x32_64_mul (dy, adx); + R = _cairo_int32x32_64_mul (dx, ady); + + return _cairo_int64_cmp (L, R); +} + +static int +edges_compare_x_for_y (const cairo_edge_t *a, + const cairo_edge_t *b, + int32_t y) +{ + /* If the sweep-line is currently on an end-point of a line, + * then we know its precise x value (and considering that we often need to + * compare events at end-points, this happens frequently enough to warrant + * special casing). + */ + enum { + HAVE_NEITHER = 0x0, + HAVE_AX = 0x1, + HAVE_BX = 0x2, + HAVE_BOTH = HAVE_AX | HAVE_BX + } have_ax_bx = HAVE_BOTH; + int32_t ax, bx; + + /* XXX given we have x and dx? */ + + if (y == a->line.p1.y) + ax = a->line.p1.x; + else if (y == a->line.p2.y) + ax = a->line.p2.x; + else + have_ax_bx &= ~HAVE_AX; + + if (y == b->line.p1.y) + bx = b->line.p1.x; + else if (y == b->line.p2.y) + bx = b->line.p2.x; + else + have_ax_bx &= ~HAVE_BX; + + switch (have_ax_bx) { + default: + case HAVE_NEITHER: + return edges_compare_x_for_y_general (a, b, y); + case HAVE_AX: + return -edge_compare_for_y_against_x (b, y, ax); + case HAVE_BX: + return edge_compare_for_y_against_x (a, y, bx); + case HAVE_BOTH: + return ax - bx; + } +} + +static inline int +slope_compare (const edge_t *a, + const edge_t *b) +{ + cairo_int64_t L, R; + int cmp; + + cmp = a->dxdy.quo - b->dxdy.quo; + if (cmp) + return cmp; + + if (a->dxdy.rem == 0) + return -b->dxdy.rem; + if (b->dxdy.rem == 0) + return a->dxdy.rem; + + L = _cairo_int32x32_64_mul (b->dy, a->dxdy.rem); + R = _cairo_int32x32_64_mul (a->dy, b->dxdy.rem); + return _cairo_int64_cmp (L, R); +} + +static inline int +line_equal (const cairo_line_t *a, const cairo_line_t *b) +{ + return a->p1.x == b->p1.x && a->p1.y == b->p1.y && + a->p2.x == b->p2.x && a->p2.y == b->p2.y; +} + +static inline int +sweep_line_compare_edges (const edge_t *a, + const edge_t *b, + cairo_fixed_t y) +{ + int cmp; + + if (line_equal (&a->edge.line, &b->edge.line)) + return 0; + + cmp = edges_compare_x_for_y (&a->edge, &b->edge, y); + if (cmp) + return cmp; + + return slope_compare (a, b); +} + +static inline cairo_int64_t +det32_64 (int32_t a, int32_t b, + int32_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), + _cairo_int32x32_64_mul (b, c)); +} + +static inline cairo_int128_t +det64x32_128 (cairo_int64_t a, int32_t b, + cairo_int64_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), + _cairo_int64x32_128_mul (c, b)); +} + +/* Compute the intersection of two lines as defined by two edges. The + * result is provided as a coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or + * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. + */ +static cairo_bool_t +intersect_lines (const edge_t *a, const edge_t *b, + cairo_bo_intersect_point_t *intersection) +{ + cairo_int64_t a_det, b_det; + + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm begins. + * What we're doing to mitigate this is to perform clamping in + * cairo_bo_tessellate_polygon(). + */ + int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; + int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; + + int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; + int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; + + cairo_int64_t den_det; + cairo_int64_t R; + cairo_quorem64_t qr; + + den_det = det32_64 (dx1, dy1, dx2, dy2); + + /* Q: Can we determine that the lines do not intersect (within range) + * much more cheaply than computing the intersection point i.e. by + * avoiding the division? + * + * X = ax + t * adx = bx + s * bdx; + * Y = ay + t * ady = by + s * bdy; + * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) + * => t * L = R + * + * Therefore we can reject any intersection (under the criteria for + * valid intersection events) if: + * L^R < 0 => t < 0, or + * L t > 1 + * + * (where top/bottom must at least extend to the line endpoints). + * + * A similar substitution can be performed for s, yielding: + * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) + */ + R = det32_64 (dx2, dy2, + b->edge.line.p1.x - a->edge.line.p1.x, + b->edge.line.p1.y - a->edge.line.p1.y); + if (_cairo_int64_negative (den_det)) { + if (_cairo_int64_ge (den_det, R)) + return FALSE; + } else { + if (_cairo_int64_le (den_det, R)) + return FALSE; + } + + R = det32_64 (dy1, dx1, + a->edge.line.p1.y - b->edge.line.p1.y, + a->edge.line.p1.x - b->edge.line.p1.x); + if (_cairo_int64_negative (den_det)) { + if (_cairo_int64_ge (den_det, R)) + return FALSE; + } else { + if (_cairo_int64_le (den_det, R)) + return FALSE; + } + + /* We now know that the two lines should intersect within range. */ + + a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, + a->edge.line.p2.x, a->edge.line.p2.y); + b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, + b->edge.line.p2.x, b->edge.line.p2.y); + + /* x = det (a_det, dx1, b_det, dx2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, + b_det, dx2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; +#if 0 + intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; +#else + intersection->x.exactness = EXACT; + if (! _cairo_int64_is_zero (qr.rem)) { + if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) + qr.rem = _cairo_int64_negate (qr.rem); + qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); + if (_cairo_int64_ge (qr.rem, den_det)) { + qr.quo = _cairo_int64_add (qr.quo, + _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); + } else + intersection->x.exactness = INEXACT; + } +#endif + intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); + + /* y = det (a_det, dy1, b_det, dy2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, + b_det, dy2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; +#if 0 + intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; +#else + intersection->y.exactness = EXACT; + if (! _cairo_int64_is_zero (qr.rem)) { + /* compute ceiling away from zero */ + qr.quo = _cairo_int64_add (qr.quo, + _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); + intersection->y.exactness = INEXACT; + } +#endif + intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); + + return TRUE; +} + +static int +bo_intersect_ordinate_32_compare (int32_t a, int32_t b, int exactness) +{ + int cmp; + + /* First compare the quotient */ + cmp = a - b; + if (cmp) + return cmp; + + /* With quotient identical, if remainder is 0 then compare equal */ + /* Otherwise, the non-zero remainder makes a > b */ + return -(INEXACT == exactness); +} + +/* Does the given edge contain the given point. The point must already + * be known to be contained within the line determined by the edge, + * (most likely the point results from an intersection of this edge + * with another). + * + * If we had exact arithmetic, then this function would simply be a + * matter of examining whether the y value of the point lies within + * the range of y values of the edge. But since intersection points + * are not exact due to being rounded to the nearest integer within + * the available precision, we must also examine the x value of the + * point. + * + * The definition of "contains" here is that the given intersection + * point will be seen by the sweep line after the start event for the + * given edge and before the stop event for the edge. See the comments + * in the implementation for more details. + */ +static cairo_bool_t +bo_edge_contains_intersect_point (const edge_t *edge, + cairo_bo_intersect_point_t *point) +{ + int cmp_top, cmp_bottom; + + /* XXX: When running the actual algorithm, we don't actually need to + * compare against edge->top at all here, since any intersection above + * top is eliminated early via a slope comparison. We're leaving these + * here for now only for the sake of the quadratic-time intersection + * finder which needs them. + */ + + cmp_top = bo_intersect_ordinate_32_compare (point->y.ordinate, + edge->edge.top, + point->y.exactness); + if (cmp_top < 0) + return FALSE; + + cmp_bottom = bo_intersect_ordinate_32_compare (point->y.ordinate, + edge->edge.bottom, + point->y.exactness); + if (cmp_bottom > 0) + return FALSE; + + if (cmp_top > 0 && cmp_bottom < 0) + return TRUE; + + /* At this stage, the point lies on the same y value as either + * edge->top or edge->bottom, so we have to examine the x value in + * order to properly determine containment. */ + + /* If the y value of the point is the same as the y value of the + * top of the edge, then the x value of the point must be greater + * to be considered as inside the edge. Similarly, if the y value + * of the point is the same as the y value of the bottom of the + * edge, then the x value of the point must be less to be + * considered as inside. */ + + if (cmp_top == 0) { + cairo_fixed_t top_x; + + top_x = line_compute_intersection_x_for_y (&edge->edge.line, + edge->edge.top); + return bo_intersect_ordinate_32_compare (top_x, point->x.ordinate, point->x.exactness) < 0; + } else { /* cmp_bottom == 0 */ + cairo_fixed_t bot_x; + + bot_x = line_compute_intersection_x_for_y (&edge->edge.line, + edge->edge.bottom); + return bo_intersect_ordinate_32_compare (point->x.ordinate, bot_x, point->x.exactness) < 0; + } +} + +static cairo_bool_t +edge_intersect (const edge_t *a, + const edge_t *b, + cairo_point_t *intersection) +{ + cairo_bo_intersect_point_t quorem; + + if (! intersect_lines (a, b, &quorem)) + return FALSE; + + if (a->edge.top != a->edge.line.p1.y || a->edge.bottom != a->edge.line.p2.y) { + if (! bo_edge_contains_intersect_point (a, &quorem)) + return FALSE; + } + + if (b->edge.top != b->edge.line.p1.y || b->edge.bottom != b->edge.line.p2.y) { + if (! bo_edge_contains_intersect_point (b, &quorem)) + return FALSE; + } + + /* Now that we've correctly compared the intersection point and + * determined that it lies within the edge, then we know that we + * no longer need any more bits of storage for the intersection + * than we do for our edge coordinates. We also no longer need the + * remainder from the division. */ + intersection->x = quorem.x.ordinate; + intersection->y = quorem.y.ordinate; + + return TRUE; +} + +static inline int +event_compare (const event_t *a, const event_t *b) +{ + return a->y - b->y; +} + +static void +pqueue_init (pqueue_t *pq) +{ + pq->max_size = ARRAY_LENGTH (pq->elements_embedded); + pq->size = 0; + + pq->elements = pq->elements_embedded; +} + +static void +pqueue_fini (pqueue_t *pq) +{ + if (pq->elements != pq->elements_embedded) + free (pq->elements); +} + +static cairo_bool_t +pqueue_grow (pqueue_t *pq) +{ + event_t **new_elements; + pq->max_size *= 2; + + if (pq->elements == pq->elements_embedded) { + new_elements = _cairo_malloc_ab (pq->max_size, + sizeof (event_t *)); + if (unlikely (new_elements == NULL)) + return FALSE; + + memcpy (new_elements, pq->elements_embedded, + sizeof (pq->elements_embedded)); + } else { + new_elements = _cairo_realloc_ab (pq->elements, + pq->max_size, + sizeof (event_t *)); + if (unlikely (new_elements == NULL)) + return FALSE; + } + + pq->elements = new_elements; + return TRUE; +} + +static inline void +pqueue_push (sweep_line_t *sweep_line, event_t *event) +{ + event_t **elements; + int i, parent; + + if (unlikely (sweep_line->queue.pq.size + 1 == sweep_line->queue.pq.max_size)) { + if (unlikely (! pqueue_grow (&sweep_line->queue.pq))) { + longjmp (sweep_line->unwind, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + } + + elements = sweep_line->queue.pq.elements; + for (i = ++sweep_line->queue.pq.size; + i != PQ_FIRST_ENTRY && + event_compare (event, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = event; +} + +static inline void +pqueue_pop (pqueue_t *pq) +{ + event_t **elements = pq->elements; + event_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + event_compare (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (event_compare (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline void +event_insert (sweep_line_t *sweep_line, + event_type_t type, + edge_t *e1, + edge_t *e2, + cairo_fixed_t y) +{ + queue_event_t *event; + + event = _cairo_freepool_alloc (&sweep_line->queue.pool); + if (unlikely (event == NULL)) { + longjmp (sweep_line->unwind, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + event->y = y; + event->type = type; + event->e1 = e1; + event->e2 = e2; + + pqueue_push (sweep_line, (event_t *) event); +} + +static void +event_delete (sweep_line_t *sweep_line, + event_t *event) +{ + _cairo_freepool_free (&sweep_line->queue.pool, event); +} + +static inline event_t * +event_next (sweep_line_t *sweep_line) +{ + event_t *event, *cmp; + + event = sweep_line->queue.pq.elements[PQ_FIRST_ENTRY]; + cmp = *sweep_line->queue.start_events; + if (event == NULL || + (cmp != NULL && event_compare (cmp, event) < 0)) + { + event = cmp; + sweep_line->queue.start_events++; + } + else + { + pqueue_pop (&sweep_line->queue.pq); + } + + return event; +} + +CAIRO_COMBSORT_DECLARE (start_event_sort, event_t *, event_compare) + +static inline void +event_insert_stop (sweep_line_t *sweep_line, + edge_t *edge) +{ + event_insert (sweep_line, + EVENT_TYPE_STOP, + edge, NULL, + edge->edge.bottom); +} + +static inline void +event_insert_if_intersect_below_current_y (sweep_line_t *sweep_line, + edge_t *left, + edge_t *right) +{ + cairo_point_t intersection; + + /* start points intersect */ + if (left->edge.line.p1.x == right->edge.line.p1.x && + left->edge.line.p1.y == right->edge.line.p1.y) + { + return; + } + + /* end points intersect, process DELETE events first */ + if (left->edge.line.p2.x == right->edge.line.p2.x && + left->edge.line.p2.y == right->edge.line.p2.y) + { + return; + } + + if (slope_compare (left, right) <= 0) + return; + + if (! edge_intersect (left, right, &intersection)) + return; + + event_insert (sweep_line, + EVENT_TYPE_INTERSECTION, + left, right, + intersection.y); +} + +static inline edge_t * +link_to_edge (cairo_list_t *link) +{ + return (edge_t *) link; +} + +static void +sweep_line_insert (sweep_line_t *sweep_line, + edge_t *edge) +{ + cairo_list_t *pos; + cairo_fixed_t y = sweep_line->current_subrow; + + pos = sweep_line->insert_cursor; + if (pos == &sweep_line->active) + pos = sweep_line->active.next; + if (pos != &sweep_line->active) { + int cmp; + + cmp = sweep_line_compare_edges (link_to_edge (pos), + edge, + y); + if (cmp < 0) { + while (pos->next != &sweep_line->active && + sweep_line_compare_edges (link_to_edge (pos->next), + edge, + y) < 0) + { + pos = pos->next; + } + } else if (cmp > 0) { + do { + pos = pos->prev; + } while (pos != &sweep_line->active && + sweep_line_compare_edges (link_to_edge (pos), + edge, + y) > 0); + } + } + cairo_list_add (&edge->link, pos); + sweep_line->insert_cursor = &edge->link; +} + +inline static void +coverage_rewind (struct coverage *cells) +{ + cells->cursor = &cells->head; +} + +static void +coverage_init (struct coverage *cells) +{ + _cairo_freepool_init (&cells->pool, + sizeof (struct cell)); + cells->head.prev = NULL; + cells->head.next = &cells->tail; + cells->head.x = INT_MIN; + cells->tail.prev = &cells->head; + cells->tail.next = NULL; + cells->tail.x = INT_MAX; + cells->count = 0; + coverage_rewind (cells); +} + +static void +coverage_fini (struct coverage *cells) +{ + _cairo_freepool_fini (&cells->pool); +} + +inline static void +coverage_reset (struct coverage *cells) +{ + cells->head.next = &cells->tail; + cells->tail.prev = &cells->head; + cells->count = 0; + _cairo_freepool_reset (&cells->pool); + coverage_rewind (cells); +} + +static struct cell * +coverage_alloc (sweep_line_t *sweep_line, + struct cell *tail, + int x) +{ + struct cell *cell; + + cell = _cairo_freepool_alloc (&sweep_line->coverage.pool); + if (unlikely (NULL == cell)) { + longjmp (sweep_line->unwind, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + tail->prev->next = cell; + cell->prev = tail->prev; + cell->next = tail; + tail->prev = cell; + cell->x = x; + cell->uncovered_area = 0; + cell->covered_height = 0; + sweep_line->coverage.count++; + return cell; +} + +inline static struct cell * +coverage_find (sweep_line_t *sweep_line, int x) +{ + struct cell *cell; + + cell = sweep_line->coverage.cursor; + if (unlikely (cell->x > x)) { + do { + if (cell->prev->x < x) + break; + cell = cell->prev; + } while (TRUE); + } else { + if (cell->x == x) + return cell; + + do { + UNROLL3({ + cell = cell->next; + if (cell->x >= x) + break; + }); + } while (TRUE); + } + + if (cell->x != x) + cell = coverage_alloc (sweep_line, cell, x); + + return sweep_line->coverage.cursor = cell; +} + +static void +coverage_render_cells (sweep_line_t *sweep_line, + cairo_fixed_t left, cairo_fixed_t right, + cairo_fixed_t y1, cairo_fixed_t y2, + int sign) +{ + int fx1, fx2; + int ix1, ix2; + int dx, dy; + + /* Orient the edge left-to-right. */ + dx = right - left; + if (dx >= 0) { + ix1 = _cairo_fixed_integer_part (left); + fx1 = _cairo_fixed_fractional_part (left); + + ix2 = _cairo_fixed_integer_part (right); + fx2 = _cairo_fixed_fractional_part (right); + + dy = y2 - y1; + } else { + ix1 = _cairo_fixed_integer_part (right); + fx1 = _cairo_fixed_fractional_part (right); + + ix2 = _cairo_fixed_integer_part (left); + fx2 = _cairo_fixed_fractional_part (left); + + dx = -dx; + sign = -sign; + dy = y1 - y2; + y1 = y2 - dy; + y2 = y1 + dy; + } + + /* Add coverage for all pixels [ix1,ix2] on this row crossed + * by the edge. */ + { + struct quorem y = floored_divrem ((STEP_X - fx1)*dy, dx); + struct cell *cell; + + cell = sweep_line->coverage.cursor; + if (cell->x != ix1) { + if (unlikely (cell->x > ix1)) { + do { + if (cell->prev->x < ix1) + break; + cell = cell->prev; + } while (TRUE); + } else do { + UNROLL3({ + if (cell->x >= ix1) + break; + cell = cell->next; + }); + } while (TRUE); + + if (cell->x != ix1) + cell = coverage_alloc (sweep_line, cell, ix1); + } + + cell->uncovered_area += sign * y.quo * (STEP_X + fx1); + cell->covered_height += sign * y.quo; + y.quo += y1; + + cell = cell->next; + if (cell->x != ++ix1) + cell = coverage_alloc (sweep_line, cell, ix1); + if (ix1 < ix2) { + struct quorem dydx_full = floored_divrem (STEP_X*dy, dx); + + do { + cairo_fixed_t y_skip = dydx_full.quo; + y.rem += dydx_full.rem; + if (y.rem >= dx) { + ++y_skip; + y.rem -= dx; + } + + y.quo += y_skip; + + y_skip *= sign; + cell->covered_height += y_skip; + cell->uncovered_area += y_skip*STEP_X; + + cell = cell->next; + if (cell->x != ++ix1) + cell = coverage_alloc (sweep_line, cell, ix1); + } while (ix1 != ix2); + } + cell->uncovered_area += sign*(y2 - y.quo)*fx2; + cell->covered_height += sign*(y2 - y.quo); + sweep_line->coverage.cursor = cell; + } +} + +inline static void +full_inc_edge (edge_t *edge) +{ + edge->x.quo += edge->dxdy_full.quo; + edge->x.rem += edge->dxdy_full.rem; + if (edge->x.rem >= 0) { + ++edge->x.quo; + edge->x.rem -= edge->dy; + } +} + +static void +full_add_edge (sweep_line_t *sweep_line, edge_t *edge, int sign) +{ + struct cell *cell; + cairo_fixed_t x1, x2; + int ix1, ix2; + int frac; + + edge->current_sign = sign; + + ix1 = _cairo_fixed_integer_part (edge->x.quo); + + if (edge->vertical) { + frac = _cairo_fixed_fractional_part (edge->x.quo); + cell = coverage_find (sweep_line, ix1); + cell->covered_height += sign * STEP_Y; + cell->uncovered_area += sign * 2 * frac * STEP_Y; + return; + } + + x1 = edge->x.quo; + full_inc_edge (edge); + x2 = edge->x.quo; + + ix2 = _cairo_fixed_integer_part (edge->x.quo); + + /* Edge is entirely within a column? */ + if (likely (ix1 == ix2)) { + frac = _cairo_fixed_fractional_part (x1) + + _cairo_fixed_fractional_part (x2); + cell = coverage_find (sweep_line, ix1); + cell->covered_height += sign * STEP_Y; + cell->uncovered_area += sign * frac * STEP_Y; + return; + } + + coverage_render_cells (sweep_line, x1, x2, 0, STEP_Y, sign); +} + +static void +full_nonzero (sweep_line_t *sweep_line) +{ + cairo_list_t *pos; + + sweep_line->is_vertical = TRUE; + pos = sweep_line->active.next; + do { + edge_t *left = link_to_edge (pos), *right; + int winding = left->edge.dir; + + sweep_line->is_vertical &= left->vertical; + + pos = left->link.next; + do { + if (unlikely (pos == &sweep_line->active)) { + full_add_edge (sweep_line, left, +1); + return; + } + + right = link_to_edge (pos); + pos = pos->next; + sweep_line->is_vertical &= right->vertical; + + winding += right->edge.dir; + if (0 == winding) { + if (pos == &sweep_line->active || + link_to_edge (pos)->x.quo != right->x.quo) + { + break; + } + } + + if (! right->vertical) + full_inc_edge (right); + } while (TRUE); + + full_add_edge (sweep_line, left, +1); + full_add_edge (sweep_line, right, -1); + } while (pos != &sweep_line->active); +} + +static void +full_evenodd (sweep_line_t *sweep_line) +{ + cairo_list_t *pos; + + sweep_line->is_vertical = TRUE; + pos = sweep_line->active.next; + do { + edge_t *left = link_to_edge (pos), *right; + int winding = 0; + + sweep_line->is_vertical &= left->vertical; + + pos = left->link.next; + do { + if (pos == &sweep_line->active) { + full_add_edge (sweep_line, left, +1); + return; + } + + right = link_to_edge (pos); + pos = pos->next; + sweep_line->is_vertical &= right->vertical; + + if (++winding & 1) { + if (pos == &sweep_line->active || + link_to_edge (pos)->x.quo != right->x.quo) + { + break; + } + } + + if (! right->vertical) + full_inc_edge (right); + } while (TRUE); + + full_add_edge (sweep_line, left, +1); + full_add_edge (sweep_line, right, -1); + } while (pos != &sweep_line->active); +} + +static void +render_rows (cairo_botor_scan_converter_t *self, + sweep_line_t *sweep_line, + int y, int height, + cairo_span_renderer_t *renderer) +{ + cairo_half_open_span_t spans_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_half_open_span_t)]; + cairo_half_open_span_t *spans = spans_stack; + struct cell *cell; + int prev_x, cover; + int num_spans; + cairo_status_t status; + + if (unlikely (sweep_line->coverage.count == 0)) { + status = renderer->render_rows (renderer, y, height, NULL, 0); + if (unlikely (status)) + longjmp (sweep_line->unwind, status); + return; + } + + /* Allocate enough spans for the row. */ + + num_spans = 2*sweep_line->coverage.count+2; + if (unlikely (num_spans > ARRAY_LENGTH (spans_stack))) { + spans = _cairo_malloc_ab (num_spans, sizeof (cairo_half_open_span_t)); + if (unlikely (spans == NULL)) { + longjmp (sweep_line->unwind, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + } + + /* Form the spans from the coverage and areas. */ + num_spans = 0; + prev_x = self->xmin; + cover = 0; + cell = sweep_line->coverage.head.next; + do { + int x = cell->x; + int area; + + if (x > prev_x) { + spans[num_spans].x = prev_x; + spans[num_spans].inverse = 0; + spans[num_spans].coverage = AREA_TO_ALPHA (cover); + ++num_spans; + } + + cover += cell->covered_height*STEP_X*2; + area = cover - cell->uncovered_area; + + spans[num_spans].x = x; + spans[num_spans].coverage = AREA_TO_ALPHA (area); + ++num_spans; + + prev_x = x + 1; + } while ((cell = cell->next) != &sweep_line->coverage.tail); + + if (prev_x <= self->xmax) { + spans[num_spans].x = prev_x; + spans[num_spans].inverse = 0; + spans[num_spans].coverage = AREA_TO_ALPHA (cover); + ++num_spans; + } + + if (cover && prev_x < self->xmax) { + spans[num_spans].x = self->xmax; + spans[num_spans].inverse = 1; + spans[num_spans].coverage = 0; + ++num_spans; + } + + status = renderer->render_rows (renderer, y, height, spans, num_spans); + + if (unlikely (spans != spans_stack)) + free (spans); + + coverage_reset (&sweep_line->coverage); + + if (unlikely (status)) + longjmp (sweep_line->unwind, status); +} + +static void +full_repeat (sweep_line_t *sweep) +{ + edge_t *edge; + + cairo_list_foreach_entry (edge, edge_t, &sweep->active, link) { + if (edge->current_sign) + full_add_edge (sweep, edge, edge->current_sign); + else if (! edge->vertical) + full_inc_edge (edge); + } +} + +static void +full_reset (sweep_line_t *sweep) +{ + edge_t *edge; + + cairo_list_foreach_entry (edge, edge_t, &sweep->active, link) + edge->current_sign = 0; +} + +static void +full_step (cairo_botor_scan_converter_t *self, + sweep_line_t *sweep_line, + cairo_fixed_t row, + cairo_span_renderer_t *renderer) +{ + int top, bottom; + + top = _cairo_fixed_integer_part (sweep_line->current_row); + bottom = _cairo_fixed_integer_part (row); + if (cairo_list_is_empty (&sweep_line->active)) { + cairo_status_t status; + + status = renderer->render_rows (renderer, top, bottom - top, NULL, 0); + if (unlikely (status)) + longjmp (sweep_line->unwind, status); + + return; + } + + if (self->fill_rule == CAIRO_FILL_RULE_WINDING) + full_nonzero (sweep_line); + else + full_evenodd (sweep_line); + + if (sweep_line->is_vertical || bottom == top + 1) { + render_rows (self, sweep_line, top, bottom - top, renderer); + full_reset (sweep_line); + return; + } + + render_rows (self, sweep_line, top++, 1, renderer); + do { + full_repeat (sweep_line); + render_rows (self, sweep_line, top, 1, renderer); + } while (++top != bottom); + + full_reset (sweep_line); +} + +cairo_always_inline static void +sub_inc_edge (edge_t *edge, + cairo_fixed_t height) +{ + if (height == 1) { + edge->x.quo += edge->dxdy.quo; + edge->x.rem += edge->dxdy.rem; + if (edge->x.rem >= 0) { + ++edge->x.quo; + edge->x.rem -= edge->dy; + } + } else { + edge->x.quo += height * edge->dxdy.quo; + edge->x.rem += height * edge->dxdy.rem; + if (edge->x.rem >= 0) { + int carry = edge->x.rem / edge->dy + 1; + edge->x.quo += carry; + edge->x.rem -= carry * edge->dy; + } + } +} + +static void +sub_add_run (sweep_line_t *sweep_line, edge_t *edge, int y, int sign) +{ + struct run *run; + + run = _cairo_freepool_alloc (&sweep_line->runs); + if (unlikely (run == NULL)) + longjmp (sweep_line->unwind, _cairo_error (CAIRO_STATUS_NO_MEMORY)); + + run->y = y; + run->sign = sign; + run->next = edge->runs; + edge->runs = run; + + edge->current_sign = sign; +} + +inline static cairo_bool_t +edges_coincident (edge_t *left, edge_t *right, cairo_fixed_t y) +{ + /* XXX is compare_x_for_y() worth executing during sub steps? */ + return line_equal (&left->edge.line, &right->edge.line); + //edges_compare_x_for_y (&left->edge, &right->edge, y) >= 0; +} + +static void +sub_nonzero (sweep_line_t *sweep_line) +{ + cairo_fixed_t y = sweep_line->current_subrow; + cairo_fixed_t fy = _cairo_fixed_fractional_part (y); + cairo_list_t *pos; + + pos = sweep_line->active.next; + do { + edge_t *left = link_to_edge (pos), *right; + int winding = left->edge.dir; + + pos = left->link.next; + do { + if (unlikely (pos == &sweep_line->active)) { + if (left->current_sign != +1) + sub_add_run (sweep_line, left, fy, +1); + return; + } + + right = link_to_edge (pos); + pos = pos->next; + + winding += right->edge.dir; + if (0 == winding) { + if (pos == &sweep_line->active || + ! edges_coincident (right, link_to_edge (pos), y)) + { + break; + } + } + + if (right->current_sign) + sub_add_run (sweep_line, right, fy, 0); + } while (TRUE); + + if (left->current_sign != +1) + sub_add_run (sweep_line, left, fy, +1); + if (right->current_sign != -1) + sub_add_run (sweep_line, right, fy, -1); + } while (pos != &sweep_line->active); +} + +static void +sub_evenodd (sweep_line_t *sweep_line) +{ + cairo_fixed_t y = sweep_line->current_subrow; + cairo_fixed_t fy = _cairo_fixed_fractional_part (y); + cairo_list_t *pos; + + pos = sweep_line->active.next; + do { + edge_t *left = link_to_edge (pos), *right; + int winding = 0; + + pos = left->link.next; + do { + if (unlikely (pos == &sweep_line->active)) { + if (left->current_sign != +1) + sub_add_run (sweep_line, left, fy, +1); + return; + } + + right = link_to_edge (pos); + pos = pos->next; + + if (++winding & 1) { + if (pos == &sweep_line->active || + ! edges_coincident (right, link_to_edge (pos), y)) + { + break; + } + } + + if (right->current_sign) + sub_add_run (sweep_line, right, fy, 0); + } while (TRUE); + + if (left->current_sign != +1) + sub_add_run (sweep_line, left, fy, +1); + if (right->current_sign != -1) + sub_add_run (sweep_line, right, fy, -1); + } while (pos != &sweep_line->active); +} + +cairo_always_inline static void +sub_step (cairo_botor_scan_converter_t *self, + sweep_line_t *sweep_line) +{ + if (cairo_list_is_empty (&sweep_line->active)) + return; + + if (self->fill_rule == CAIRO_FILL_RULE_WINDING) + sub_nonzero (sweep_line); + else + sub_evenodd (sweep_line); +} + +static void +coverage_render_runs (sweep_line_t *sweep, edge_t *edge, + cairo_fixed_t y1, cairo_fixed_t y2) +{ + struct run tail; + struct run *run = &tail; + + tail.next = NULL; + tail.y = y2; + + /* Order the runs top->bottom */ + while (edge->runs) { + struct run *r; + + r = edge->runs; + edge->runs = r->next; + r->next = run; + run = r; + } + + if (run->y > y1) + sub_inc_edge (edge, run->y - y1); + + do { + cairo_fixed_t x1, x2; + + y1 = run->y; + y2 = run->next->y; + + x1 = edge->x.quo; + if (y2 - y1 == STEP_Y) + full_inc_edge (edge); + else + sub_inc_edge (edge, y2 - y1); + x2 = edge->x.quo; + + if (run->sign) { + int ix1, ix2; + + ix1 = _cairo_fixed_integer_part (x1); + ix2 = _cairo_fixed_integer_part (x2); + + /* Edge is entirely within a column? */ + if (likely (ix1 == ix2)) { + struct cell *cell; + int frac; + + frac = _cairo_fixed_fractional_part (x1) + + _cairo_fixed_fractional_part (x2); + cell = coverage_find (sweep, ix1); + cell->covered_height += run->sign * (y2 - y1); + cell->uncovered_area += run->sign * (y2 - y1) * frac; + } else { + coverage_render_cells (sweep, x1, x2, y1, y2, run->sign); + } + } + + run = run->next; + } while (run->next != NULL); +} + +static void +coverage_render_vertical_runs (sweep_line_t *sweep, edge_t *edge, cairo_fixed_t y2) +{ + struct cell *cell; + struct run *run; + int height = 0; + + for (run = edge->runs; run != NULL; run = run->next) { + if (run->sign) + height += run->sign * (y2 - run->y); + y2 = run->y; + } + + cell = coverage_find (sweep, _cairo_fixed_integer_part (edge->x.quo)); + cell->covered_height += height; + cell->uncovered_area += 2 * _cairo_fixed_fractional_part (edge->x.quo) * height; +} + +cairo_always_inline static void +sub_emit (cairo_botor_scan_converter_t *self, + sweep_line_t *sweep, + cairo_span_renderer_t *renderer) +{ + edge_t *edge; + + sub_step (self, sweep); + + /* convert the runs into coverages */ + + cairo_list_foreach_entry (edge, edge_t, &sweep->active, link) { + if (edge->runs == NULL) { + if (! edge->vertical) { + if (edge->flags & START) { + sub_inc_edge (edge, + STEP_Y - _cairo_fixed_fractional_part (edge->edge.top)); + edge->flags &= ~START; + } else + full_inc_edge (edge); + } + } else { + if (edge->vertical) { + coverage_render_vertical_runs (sweep, edge, STEP_Y); + } else { + int y1 = 0; + if (edge->flags & START) { + y1 = _cairo_fixed_fractional_part (edge->edge.top); + edge->flags &= ~START; + } + coverage_render_runs (sweep, edge, y1, STEP_Y); + } + } + edge->current_sign = 0; + edge->runs = NULL; + } + + cairo_list_foreach_entry (edge, edge_t, &sweep->stopped, link) { + int y2 = _cairo_fixed_fractional_part (edge->edge.bottom); + if (edge->vertical) { + coverage_render_vertical_runs (sweep, edge, y2); + } else { + int y1 = 0; + if (edge->flags & START) + y1 = _cairo_fixed_fractional_part (edge->edge.top); + coverage_render_runs (sweep, edge, y1, y2); + } + } + cairo_list_init (&sweep->stopped); + + _cairo_freepool_reset (&sweep->runs); + + render_rows (self, sweep, + _cairo_fixed_integer_part (sweep->current_row), 1, + renderer); +} + +static void +sweep_line_init (sweep_line_t *sweep_line, + event_t **start_events, + int num_events) +{ + cairo_list_init (&sweep_line->active); + cairo_list_init (&sweep_line->stopped); + sweep_line->insert_cursor = &sweep_line->active; + + sweep_line->current_row = INT32_MIN; + sweep_line->current_subrow = INT32_MIN; + + coverage_init (&sweep_line->coverage); + _cairo_freepool_init (&sweep_line->runs, sizeof (struct run)); + + start_event_sort (start_events, num_events); + start_events[num_events] = NULL; + + sweep_line->queue.start_events = start_events; + + _cairo_freepool_init (&sweep_line->queue.pool, + sizeof (queue_event_t)); + pqueue_init (&sweep_line->queue.pq); + sweep_line->queue.pq.elements[PQ_FIRST_ENTRY] = NULL; +} + +static void +sweep_line_delete (sweep_line_t *sweep_line, + edge_t *edge) +{ + if (sweep_line->insert_cursor == &edge->link) + sweep_line->insert_cursor = edge->link.prev; + + cairo_list_del (&edge->link); + if (edge->runs) + cairo_list_add_tail (&edge->link, &sweep_line->stopped); + edge->flags |= STOP; +} + +static void +sweep_line_swap (sweep_line_t *sweep_line, + edge_t *left, + edge_t *right) +{ + right->link.prev = left->link.prev; + left->link.next = right->link.next; + right->link.next = &left->link; + left->link.prev = &right->link; + left->link.next->prev = &left->link; + right->link.prev->next = &right->link; +} + +static void +sweep_line_fini (sweep_line_t *sweep_line) +{ + pqueue_fini (&sweep_line->queue.pq); + _cairo_freepool_fini (&sweep_line->queue.pool); + coverage_fini (&sweep_line->coverage); + _cairo_freepool_fini (&sweep_line->runs); +} + +static cairo_status_t +botor_generate (cairo_botor_scan_converter_t *self, + event_t **start_events, + cairo_span_renderer_t *renderer) +{ + cairo_status_t status; + sweep_line_t sweep_line; + cairo_fixed_t ybot; + event_t *event; + cairo_list_t *left, *right; + edge_t *e1, *e2; + int bottom; + + sweep_line_init (&sweep_line, start_events, self->num_edges); + if ((status = setjmp (sweep_line.unwind))) + goto unwind; + + ybot = self->extents.p2.y; + sweep_line.current_subrow = self->extents.p1.y; + sweep_line.current_row = _cairo_fixed_floor (self->extents.p1.y); + event = *sweep_line.queue.start_events++; + do { + /* Can we process a full step in one go? */ + if (event->y >= sweep_line.current_row + STEP_Y) { + bottom = _cairo_fixed_floor (event->y); + full_step (self, &sweep_line, bottom, renderer); + sweep_line.current_row = bottom; + sweep_line.current_subrow = bottom; + } + + do { + if (event->y > sweep_line.current_subrow) { + sub_step (self, &sweep_line); + sweep_line.current_subrow = event->y; + } + + do { + /* Update the active list using Bentley-Ottmann */ + switch (event->type) { + case EVENT_TYPE_START: + e1 = ((start_event_t *) event)->edge; + + sweep_line_insert (&sweep_line, e1); + event_insert_stop (&sweep_line, e1); + + left = e1->link.prev; + right = e1->link.next; + + if (left != &sweep_line.active) { + event_insert_if_intersect_below_current_y (&sweep_line, + link_to_edge (left), e1); + } + + if (right != &sweep_line.active) { + event_insert_if_intersect_below_current_y (&sweep_line, + e1, link_to_edge (right)); + } + + break; + + case EVENT_TYPE_STOP: + e1 = ((queue_event_t *) event)->e1; + event_delete (&sweep_line, event); + + left = e1->link.prev; + right = e1->link.next; + + sweep_line_delete (&sweep_line, e1); + + if (left != &sweep_line.active && + right != &sweep_line.active) + { + event_insert_if_intersect_below_current_y (&sweep_line, + link_to_edge (left), + link_to_edge (right)); + } + + break; + + case EVENT_TYPE_INTERSECTION: + e1 = ((queue_event_t *) event)->e1; + e2 = ((queue_event_t *) event)->e2; + + event_delete (&sweep_line, event); + if (e1->flags & STOP) + break; + if (e2->flags & STOP) + break; + + /* skip this intersection if its edges are not adjacent */ + if (&e2->link != e1->link.next) + break; + + left = e1->link.prev; + right = e2->link.next; + + sweep_line_swap (&sweep_line, e1, e2); + + /* after the swap e2 is left of e1 */ + if (left != &sweep_line.active) { + event_insert_if_intersect_below_current_y (&sweep_line, + link_to_edge (left), e2); + } + + if (right != &sweep_line.active) { + event_insert_if_intersect_below_current_y (&sweep_line, + e1, link_to_edge (right)); + } + + break; + } + + event = event_next (&sweep_line); + if (event == NULL) + goto end; + } while (event->y == sweep_line.current_subrow); + } while (event->y < sweep_line.current_row + STEP_Y); + + bottom = sweep_line.current_row + STEP_Y; + sub_emit (self, &sweep_line, renderer); + sweep_line.current_subrow = bottom; + sweep_line.current_row = sweep_line.current_subrow; + } while (TRUE); + + end: + /* flush any partial spans */ + if (sweep_line.current_subrow != sweep_line.current_row) { + sub_emit (self, &sweep_line, renderer); + sweep_line.current_row += STEP_Y; + sweep_line.current_subrow = sweep_line.current_row; + } + /* clear the rest */ + if (sweep_line.current_subrow < ybot) { + bottom = _cairo_fixed_integer_part (sweep_line.current_row); + status = renderer->render_rows (renderer, + bottom, _cairo_fixed_integer_ceil (ybot) - bottom, + NULL, 0); + } + + unwind: + sweep_line_fini (&sweep_line); + + return status; +} + +static cairo_status_t +_cairo_botor_scan_converter_generate (void *converter, + cairo_span_renderer_t *renderer) +{ + cairo_botor_scan_converter_t *self = converter; + start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (start_event_t)]; + start_event_t *events; + event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; + event_t **event_ptrs; + struct _cairo_botor_scan_converter_chunk *chunk; + cairo_status_t status; + int num_events; + int i, j; + + num_events = self->num_edges; + if (unlikely (0 == num_events)) { + return renderer->render_rows (renderer, + _cairo_fixed_integer_floor (self->extents.p1.y), + _cairo_fixed_integer_ceil (self->extents.p2.y) - + _cairo_fixed_integer_floor (self->extents.p1.y), + NULL, 0); + } + + events = stack_events; + event_ptrs = stack_event_ptrs; + if (unlikely (num_events >= ARRAY_LENGTH (stack_events))) { + events = _cairo_malloc_ab_plus_c (num_events, + sizeof (start_event_t) + sizeof (event_t *), + sizeof (event_t *)); + if (unlikely (events == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event_ptrs = (event_t **) (events + num_events); + } + + j = 0; + for (chunk = &self->chunks; chunk != NULL; chunk = chunk->next) { + edge_t *edge; + + edge = chunk->base; + for (i = 0; i < chunk->count; i++) { + event_ptrs[j] = (event_t *) &events[j]; + + events[j].y = edge->edge.top; + events[j].type = EVENT_TYPE_START; + events[j].edge = edge; + + edge++, j++; + } + } + + status = botor_generate (self, event_ptrs, renderer); + + if (events != stack_events) + free (events); + + return status; +} + +static edge_t * +botor_allocate_edge (cairo_botor_scan_converter_t *self) +{ + struct _cairo_botor_scan_converter_chunk *chunk; + + chunk = self->tail; + if (chunk->count == chunk->size) { + int size; + + size = chunk->size * 2; + chunk->next = _cairo_malloc_ab_plus_c (size, + sizeof (edge_t), + sizeof (struct _cairo_botor_scan_converter_chunk)); + if (unlikely (chunk->next == NULL)) + return NULL; + + chunk = chunk->next; + chunk->next = NULL; + chunk->count = 0; + chunk->size = size; + chunk->base = chunk + 1; + self->tail = chunk; + } + + return (edge_t *) chunk->base + chunk->count++; +} + +static cairo_status_t +botor_add_edge (cairo_botor_scan_converter_t *self, + const cairo_edge_t *edge) +{ + edge_t *e; + cairo_fixed_t dx, dy; + + e = botor_allocate_edge (self); + if (unlikely (e == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + cairo_list_init (&e->link); + e->edge = *edge; + + dx = edge->line.p2.x - edge->line.p1.x; + dy = edge->line.p2.y - edge->line.p1.y; + e->dy = dy; + + if (dx == 0) { + e->vertical = TRUE; + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + e->dxdy.quo = 0; + e->dxdy.rem = 0; + e->dxdy_full.quo = 0; + e->dxdy_full.rem = 0; + } else { + e->vertical = FALSE; + e->dxdy = floored_divrem (dx, dy); + if (edge->top == edge->line.p1.y) { + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + } else { + e->x = floored_muldivrem (edge->top - edge->line.p1.y, + dx, dy); + e->x.quo += edge->line.p1.x; + } + + if (_cairo_fixed_integer_part (edge->bottom) - _cairo_fixed_integer_part (edge->top) > 1) { + e->dxdy_full = floored_muldivrem (STEP_Y, dx, dy); + } else { + e->dxdy_full.quo = 0; + e->dxdy_full.rem = 0; + } + } + + e->x.rem = -e->dy; + e->current_sign = 0; + e->runs = NULL; + e->flags = START; + + self->num_edges++; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_botor_scan_converter_destroy (void *converter) +{ + cairo_botor_scan_converter_t *self = converter; + struct _cairo_botor_scan_converter_chunk *chunk, *next; + + for (chunk = self->chunks.next; chunk != NULL; chunk = next) { + next = chunk->next; + free (chunk); + } +} + +void +_cairo_botor_scan_converter_init (cairo_botor_scan_converter_t *self, + const cairo_box_t *extents, + cairo_fill_rule_t fill_rule) +{ + self->base.destroy = _cairo_botor_scan_converter_destroy; + self->base.generate = _cairo_botor_scan_converter_generate; + + self->extents = *extents; + self->fill_rule = fill_rule; + + self->xmin = _cairo_fixed_integer_floor (extents->p1.x); + self->xmax = _cairo_fixed_integer_ceil (extents->p2.x); + + self->chunks.base = self->buf; + self->chunks.next = NULL; + self->chunks.count = 0; + self->chunks.size = sizeof (self->buf) / sizeof (edge_t); + self->tail = &self->chunks; + + self->num_edges = 0; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-box-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-box-inline.h new file mode 100644 index 00000000000..d6b994127e3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-box-inline.h @@ -0,0 +1,121 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Andrea Canciani + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Andrea Canciani + */ + +#ifndef CAIRO_BOX_H +#define CAIRO_BOX_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" +#include "cairo-fixed-private.h" + +static inline void +_cairo_box_set (cairo_box_t *box, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + box->p1 = *p1; + box->p2 = *p2; +} + +static inline void +_cairo_box_from_integers (cairo_box_t *box, int x, int y, int w, int h) +{ + box->p1.x = _cairo_fixed_from_int (x); + box->p1.y = _cairo_fixed_from_int (y); + box->p2.x = _cairo_fixed_from_int (x + w); + box->p2.y = _cairo_fixed_from_int (y + h); +} + +/* assumes box->p1 is top-left, p2 bottom-right */ +static inline void +_cairo_box_add_point (cairo_box_t *box, + const cairo_point_t *point) +{ + if (point->x < box->p1.x) + box->p1.x = point->x; + else if (point->x > box->p2.x) + box->p2.x = point->x; + + if (point->y < box->p1.y) + box->p1.y = point->y; + else if (point->y > box->p2.y) + box->p2.y = point->y; +} + +static inline void +_cairo_box_add_box (cairo_box_t *box, + const cairo_box_t *add) +{ + if (add->p1.x < box->p1.x) + box->p1.x = add->p1.x; + if (add->p2.x > box->p2.x) + box->p2.x = add->p2.x; + + if (add->p1.y < box->p1.y) + box->p1.y = add->p1.y; + if (add->p2.y > box->p2.y) + box->p2.y = add->p2.y; +} + +/* assumes box->p1 is top-left, p2 bottom-right */ +static inline cairo_bool_t +_cairo_box_contains_point (const cairo_box_t *box, + const cairo_point_t *point) +{ + return box->p1.x <= point->x && point->x <= box->p2.x && + box->p1.y <= point->y && point->y <= box->p2.y; +} + +static inline cairo_bool_t +_cairo_box_is_pixel_aligned (const cairo_box_t *box) +{ +#if CAIRO_FIXED_FRAC_BITS <= 8 && 0 + return ((box->p1.x & CAIRO_FIXED_FRAC_MASK) << 24 | + (box->p1.y & CAIRO_FIXED_FRAC_MASK) << 16 | + (box->p2.x & CAIRO_FIXED_FRAC_MASK) << 8 | + (box->p2.y & CAIRO_FIXED_FRAC_MASK) << 0) == 0; +#else /* GCC on i7 prefers this variant (bizarrely according to the profiler) */ + cairo_fixed_t f; + + f = 0; + f |= box->p1.x & CAIRO_FIXED_FRAC_MASK; + f |= box->p1.y & CAIRO_FIXED_FRAC_MASK; + f |= box->p2.x & CAIRO_FIXED_FRAC_MASK; + f |= box->p2.y & CAIRO_FIXED_FRAC_MASK; + + return f == 0; +#endif +} + +#endif /* CAIRO_BOX_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-boxes-intersect.c b/Build/source/libs/cairo/cairo-src/src/cairo-boxes-intersect.c new file mode 100644 index 00000000000..96ae66334e6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-boxes-intersect.c @@ -0,0 +1,690 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-combsort-inline.h" +#include "cairo-list-private.h" + +#include + +typedef struct _rectangle rectangle_t; +typedef struct _edge edge_t; + +struct _edge { + edge_t *next, *prev; + edge_t *right; + cairo_fixed_t x, top; + int a_or_b; + int dir; +}; + +struct _rectangle { + edge_t left, right; + int32_t top, bottom; +}; + +#define UNROLL3(x) x x x + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef struct _pqueue { + int size, max_size; + + rectangle_t **elements; + rectangle_t *elements_embedded[1024]; +} pqueue_t; + +typedef struct _sweep_line { + rectangle_t **rectangles; + pqueue_t pq; + edge_t head, tail; + edge_t *insert_left, *insert_right; + int32_t current_y; + int32_t last_y; + + jmp_buf unwind; +} sweep_line_t; + +#define DEBUG_TRAPS 0 + +#if DEBUG_TRAPS +static void +dump_traps (cairo_traps_t *traps, const char *filename) +{ + FILE *file; + int n; + + if (getenv ("CAIRO_DEBUG_TRAPS") == NULL) + return; + + file = fopen (filename, "a"); + if (file != NULL) { + for (n = 0; n < traps->num_traps; n++) { + fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", + traps->traps[n].top, + traps->traps[n].bottom, + traps->traps[n].left.p1.x, + traps->traps[n].left.p1.y, + traps->traps[n].left.p2.x, + traps->traps[n].left.p2.y, + traps->traps[n].right.p1.x, + traps->traps[n].right.p1.y, + traps->traps[n].right.p2.x, + traps->traps[n].right.p2.y); + } + fprintf (file, "\n"); + fclose (file); + } +} +#else +#define dump_traps(traps, filename) +#endif + +static inline int +rectangle_compare_start (const rectangle_t *a, + const rectangle_t *b) +{ + return a->top - b->top; +} + +static inline int +rectangle_compare_stop (const rectangle_t *a, + const rectangle_t *b) +{ + return a->bottom - b->bottom; +} + +static inline void +pqueue_init (pqueue_t *pq) +{ + pq->max_size = ARRAY_LENGTH (pq->elements_embedded); + pq->size = 0; + + pq->elements = pq->elements_embedded; + pq->elements[PQ_FIRST_ENTRY] = NULL; +} + +static inline void +pqueue_fini (pqueue_t *pq) +{ + if (pq->elements != pq->elements_embedded) + free (pq->elements); +} + +static cairo_bool_t +pqueue_grow (pqueue_t *pq) +{ + rectangle_t **new_elements; + pq->max_size *= 2; + + if (pq->elements == pq->elements_embedded) { + new_elements = _cairo_malloc_ab (pq->max_size, + sizeof (rectangle_t *)); + if (unlikely (new_elements == NULL)) + return FALSE; + + memcpy (new_elements, pq->elements_embedded, + sizeof (pq->elements_embedded)); + } else { + new_elements = _cairo_realloc_ab (pq->elements, + pq->max_size, + sizeof (rectangle_t *)); + if (unlikely (new_elements == NULL)) + return FALSE; + } + + pq->elements = new_elements; + return TRUE; +} + +static inline void +pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle) +{ + rectangle_t **elements; + int i, parent; + + if (unlikely (sweep->pq.size + 1 == sweep->pq.max_size)) { + if (unlikely (! pqueue_grow (&sweep->pq))) { + longjmp (sweep->unwind, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + } + + elements = sweep->pq.elements; + for (i = ++sweep->pq.size; + i != PQ_FIRST_ENTRY && + rectangle_compare_stop (rectangle, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = rectangle; +} + +static inline void +pqueue_pop (pqueue_t *pq) +{ + rectangle_t **elements = pq->elements; + rectangle_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + rectangle_compare_stop (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (rectangle_compare_stop (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline rectangle_t * +rectangle_pop_start (sweep_line_t *sweep_line) +{ + return *sweep_line->rectangles++; +} + +static inline rectangle_t * +rectangle_peek_stop (sweep_line_t *sweep_line) +{ + return sweep_line->pq.elements[PQ_FIRST_ENTRY]; +} + +CAIRO_COMBSORT_DECLARE (_rectangle_sort, + rectangle_t *, + rectangle_compare_start) + +static void +sweep_line_init (sweep_line_t *sweep_line, + rectangle_t **rectangles, + int num_rectangles) +{ + _rectangle_sort (rectangles, num_rectangles); + rectangles[num_rectangles] = NULL; + sweep_line->rectangles = rectangles; + + sweep_line->head.x = INT32_MIN; + sweep_line->head.right = NULL; + sweep_line->head.dir = 0; + sweep_line->head.next = &sweep_line->tail; + sweep_line->tail.x = INT32_MAX; + sweep_line->tail.right = NULL; + sweep_line->tail.dir = 0; + sweep_line->tail.prev = &sweep_line->head; + + sweep_line->insert_left = &sweep_line->tail; + sweep_line->insert_right = &sweep_line->tail; + + sweep_line->current_y = INT32_MIN; + sweep_line->last_y = INT32_MIN; + + pqueue_init (&sweep_line->pq); +} + +static void +sweep_line_fini (sweep_line_t *sweep_line) +{ + pqueue_fini (&sweep_line->pq); +} + +static void +end_box (sweep_line_t *sweep_line, edge_t *left, int32_t bot, cairo_boxes_t *out) +{ + if (likely (left->top < bot)) { + cairo_status_t status; + cairo_box_t box; + + box.p1.x = left->x; + box.p1.y = left->top; + box.p2.x = left->right->x; + box.p2.y = bot; + + status = _cairo_boxes_add (out, CAIRO_ANTIALIAS_DEFAULT, &box); + if (unlikely (status)) + longjmp (sweep_line->unwind, status); + } + + left->right = NULL; +} + +/* Start a new trapezoid at the given top y coordinate, whose edges + * are `edge' and `edge->next'. If `edge' already has a trapezoid, + * then either add it to the traps in `traps', if the trapezoid's + * right edge differs from `edge->next', or do nothing if the new + * trapezoid would be a continuation of the existing one. */ +static inline void +start_or_continue_box (sweep_line_t *sweep_line, + edge_t *left, + edge_t *right, + int top, + cairo_boxes_t *out) +{ + if (left->right == right) + return; + + if (left->right != NULL) { + if (right != NULL && left->right->x == right->x) { + /* continuation on right, so just swap edges */ + left->right = right; + return; + } + + end_box (sweep_line, left, top, out); + } + + if (right != NULL && left->x != right->x) { + left->top = top; + left->right = right; + } +} + +static inline int is_zero(const int *winding) +{ + return winding[0] == 0 || winding[1] == 0; +} + +static inline void +active_edges (sweep_line_t *sweep, cairo_boxes_t *out) +{ + int top = sweep->current_y; + int winding[2] = { 0 }; + edge_t *pos; + + if (sweep->last_y == sweep->current_y) + return; + + pos = sweep->head.next; + if (pos == &sweep->tail) + return; + + do { + edge_t *left, *right; + + left = pos; + do { + winding[left->a_or_b] += left->dir; + if (!is_zero (winding)) + break; + if (left->next == &sweep->tail) + goto out; + + if (unlikely (left->right != NULL)) + end_box (sweep, left, top, out); + + left = left->next; + } while (1); + + right = left->next; + do { + if (unlikely (right->right != NULL)) + end_box (sweep, right, top, out); + + winding[right->a_or_b] += right->dir; + if (is_zero (winding)) { + /* skip co-linear edges */ + if (likely (right->x != right->next->x)) + break; + } + + right = right->next; + } while (TRUE); + + start_or_continue_box (sweep, left, right, top, out); + + pos = right->next; + } while (pos != &sweep->tail); + +out: + sweep->last_y = sweep->current_y; +} + +static inline void +sweep_line_delete_edge (sweep_line_t *sweep_line, edge_t *edge, cairo_boxes_t *out) +{ + if (edge->right != NULL) { + edge_t *next = edge->next; + if (next->x == edge->x) { + next->top = edge->top; + next->right = edge->right; + } else { + end_box (sweep_line, edge, sweep_line->current_y, out); + } + } + + if (sweep_line->insert_left == edge) + sweep_line->insert_left = edge->next; + if (sweep_line->insert_right == edge) + sweep_line->insert_right = edge->next; + + edge->prev->next = edge->next; + edge->next->prev = edge->prev; +} + +static inline void +sweep_line_delete (sweep_line_t *sweep, + rectangle_t *rectangle, + cairo_boxes_t *out) +{ + sweep_line_delete_edge (sweep, &rectangle->left, out); + sweep_line_delete_edge (sweep, &rectangle->right, out); + + pqueue_pop (&sweep->pq); +} + +static inline void +insert_edge (edge_t *edge, edge_t *pos) +{ + if (pos->x != edge->x) { + if (pos->x > edge->x) { + do { + UNROLL3({ + if (pos->prev->x <= edge->x) + break; + pos = pos->prev; + }) + } while (TRUE); + } else { + do { + UNROLL3({ + pos = pos->next; + if (pos->x >= edge->x) + break; + }) + } while (TRUE); + } + } + + pos->prev->next = edge; + edge->prev = pos->prev; + edge->next = pos; + pos->prev = edge; +} + +static inline void +sweep_line_insert (sweep_line_t *sweep, rectangle_t *rectangle) +{ + edge_t *pos; + + /* right edge */ + pos = sweep->insert_right; + insert_edge (&rectangle->right, pos); + sweep->insert_right = &rectangle->right; + + /* left edge */ + pos = sweep->insert_left; + if (pos->x > sweep->insert_right->x) + pos = sweep->insert_right->prev; + insert_edge (&rectangle->left, pos); + sweep->insert_left = &rectangle->left; + + pqueue_push (sweep, rectangle); +} + +static cairo_status_t +intersect (rectangle_t **rectangles, int num_rectangles, cairo_boxes_t *out) +{ + sweep_line_t sweep_line; + rectangle_t *rectangle; + cairo_status_t status; + + sweep_line_init (&sweep_line, rectangles, num_rectangles); + if ((status = setjmp (sweep_line.unwind))) + goto unwind; + + rectangle = rectangle_pop_start (&sweep_line); + do { + if (rectangle->top != sweep_line.current_y) { + rectangle_t *stop; + + stop = rectangle_peek_stop (&sweep_line); + while (stop != NULL && stop->bottom < rectangle->top) { + if (stop->bottom != sweep_line.current_y) { + active_edges (&sweep_line, out); + sweep_line.current_y = stop->bottom; + } + + sweep_line_delete (&sweep_line, stop, out); + + stop = rectangle_peek_stop (&sweep_line); + } + + active_edges (&sweep_line, out); + sweep_line.current_y = rectangle->top; + } + + sweep_line_insert (&sweep_line, rectangle); + } while ((rectangle = rectangle_pop_start (&sweep_line)) != NULL); + + while ((rectangle = rectangle_peek_stop (&sweep_line)) != NULL) { + if (rectangle->bottom != sweep_line.current_y) { + active_edges (&sweep_line, out); + sweep_line.current_y = rectangle->bottom; + } + + sweep_line_delete (&sweep_line, rectangle, out); + } + +unwind: + sweep_line_fini (&sweep_line); + return status; +} + +static cairo_status_t +_cairo_boxes_intersect_with_box (const cairo_boxes_t *boxes, + const cairo_box_t *box, + cairo_boxes_t *out) +{ + cairo_status_t status; + int i, j; + + if (out == boxes) { /* inplace update */ + struct _cairo_boxes_chunk *chunk; + + out->num_boxes = 0; + for (chunk = &out->chunks; chunk != NULL; chunk = chunk->next) { + for (i = j = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + + b->p1.x = MAX (b->p1.x, box->p1.x); + b->p1.y = MAX (b->p1.y, box->p1.y); + b->p2.x = MIN (b->p2.x, box->p2.x); + b->p2.y = MIN (b->p2.y, box->p2.y); + if (b->p1.x < b->p2.x && b->p1.y < b->p2.y) { + if (i != j) + chunk->base[j] = *b; + j++; + } + } + /* XXX unlink empty chains? */ + chunk->count = j; + out->num_boxes += j; + } + } else { + const struct _cairo_boxes_chunk *chunk; + + _cairo_boxes_clear (out); + _cairo_boxes_limit (out, box, 1); + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + status = _cairo_boxes_add (out, + CAIRO_ANTIALIAS_DEFAULT, + &chunk->base[i]); + if (unlikely (status)) + return status; + } + } + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_boxes_intersect (const cairo_boxes_t *a, + const cairo_boxes_t *b, + cairo_boxes_t *out) +{ + rectangle_t stack_rectangles[CAIRO_STACK_ARRAY_LENGTH (rectangle_t)]; + rectangle_t *rectangles; + rectangle_t *stack_rectangles_ptrs[ARRAY_LENGTH (stack_rectangles) + 1]; + rectangle_t **rectangles_ptrs; + const struct _cairo_boxes_chunk *chunk; + cairo_status_t status; + int i, j, count; + + if (unlikely (a->num_boxes == 0 || b->num_boxes == 0)) { + _cairo_boxes_clear (out); + return CAIRO_STATUS_SUCCESS; + } + + if (a->num_boxes == 1) { + cairo_box_t box = a->chunks.base[0]; + return _cairo_boxes_intersect_with_box (b, &box, out); + } + if (b->num_boxes == 1) { + cairo_box_t box = b->chunks.base[0]; + return _cairo_boxes_intersect_with_box (a, &box, out); + } + + rectangles = stack_rectangles; + rectangles_ptrs = stack_rectangles_ptrs; + count = a->num_boxes + b->num_boxes; + if (count > ARRAY_LENGTH (stack_rectangles)) { + rectangles = _cairo_malloc_ab_plus_c (count, + sizeof (rectangle_t) + + sizeof (rectangle_t *), + sizeof (rectangle_t *)); + if (unlikely (rectangles == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + rectangles_ptrs = (rectangle_t **) (rectangles + count); + } + + j = 0; + for (chunk = &a->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box = chunk->base; + for (i = 0; i < chunk->count; i++) { + if (box[i].p1.x < box[i].p2.x) { + rectangles[j].left.x = box[i].p1.x; + rectangles[j].left.dir = 1; + + rectangles[j].right.x = box[i].p2.x; + rectangles[j].right.dir = -1; + } else { + rectangles[j].right.x = box[i].p1.x; + rectangles[j].right.dir = 1; + + rectangles[j].left.x = box[i].p2.x; + rectangles[j].left.dir = -1; + } + + rectangles[j].left.a_or_b = 0; + rectangles[j].left.right = NULL; + rectangles[j].right.a_or_b = 0; + rectangles[j].right.right = NULL; + + rectangles[j].top = box[i].p1.y; + rectangles[j].bottom = box[i].p2.y; + + rectangles_ptrs[j] = &rectangles[j]; + j++; + } + } + for (chunk = &b->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box = chunk->base; + for (i = 0; i < chunk->count; i++) { + if (box[i].p1.x < box[i].p2.x) { + rectangles[j].left.x = box[i].p1.x; + rectangles[j].left.dir = 1; + + rectangles[j].right.x = box[i].p2.x; + rectangles[j].right.dir = -1; + } else { + rectangles[j].right.x = box[i].p1.x; + rectangles[j].right.dir = 1; + + rectangles[j].left.x = box[i].p2.x; + rectangles[j].left.dir = -1; + } + + rectangles[j].left.a_or_b = 1; + rectangles[j].left.right = NULL; + rectangles[j].right.a_or_b = 1; + rectangles[j].right.right = NULL; + + rectangles[j].top = box[i].p1.y; + rectangles[j].bottom = box[i].p2.y; + + rectangles_ptrs[j] = &rectangles[j]; + j++; + } + } + assert (j == count); + + _cairo_boxes_clear (out); + status = intersect (rectangles_ptrs, j, out); + if (rectangles != stack_rectangles) + free (rectangles); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-boxes-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-boxes-private.h new file mode 100644 index 00000000000..d1f9dfcd1e5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-boxes-private.h @@ -0,0 +1,123 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_BOXES_H +#define CAIRO_BOXES_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" + +#include +#include + +struct _cairo_boxes_t { + cairo_status_t status; + + cairo_box_t limit; + const cairo_box_t *limits; + int num_limits; + + int num_boxes; + + unsigned int is_pixel_aligned; + + struct _cairo_boxes_chunk { + struct _cairo_boxes_chunk *next; + cairo_box_t *base; + int count; + int size; + } chunks, *tail; + cairo_box_t boxes_embedded[32]; +}; + +cairo_private void +_cairo_boxes_init (cairo_boxes_t *boxes); + +cairo_private void +_cairo_boxes_init_with_clip (cairo_boxes_t *boxes, + cairo_clip_t *clip); + +cairo_private void +_cairo_boxes_init_for_array (cairo_boxes_t *boxes, + cairo_box_t *array, + int num_boxes); + +cairo_private void +_cairo_boxes_init_from_rectangle (cairo_boxes_t *boxes, + int x, int y, int w, int h); + +cairo_private void +_cairo_boxes_limit (cairo_boxes_t *boxes, + const cairo_box_t *limits, + int num_limits); + +cairo_private cairo_status_t +_cairo_boxes_add (cairo_boxes_t *boxes, + cairo_antialias_t antialias, + const cairo_box_t *box); + +cairo_private void +_cairo_boxes_extents (const cairo_boxes_t *boxes, + cairo_box_t *box); + +cairo_private cairo_box_t * +_cairo_boxes_to_array (const cairo_boxes_t *boxes, + int *num_boxes, + cairo_bool_t force_allocation); + +cairo_private cairo_status_t +_cairo_boxes_intersect (const cairo_boxes_t *a, + const cairo_boxes_t *b, + cairo_boxes_t *out); + +cairo_private void +_cairo_boxes_clear (cairo_boxes_t *boxes); + +cairo_private_no_warn cairo_bool_t +_cairo_boxes_for_each_box (cairo_boxes_t *boxes, + cairo_bool_t (*func) (cairo_box_t *box, void *data), + void *data); + +cairo_private cairo_status_t +_cairo_rasterise_polygon_to_boxes (cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_boxes_t *boxes); + +cairo_private void +_cairo_boxes_fini (cairo_boxes_t *boxes); + +cairo_private void +_cairo_debug_print_boxes (FILE *stream, + const cairo_boxes_t *boxes); + +#endif /* CAIRO_BOXES_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-boxes.c b/Build/source/libs/cairo/cairo-src/src/cairo-boxes.c new file mode 100644 index 00000000000..63b68ddfb90 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-boxes.c @@ -0,0 +1,460 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" + +void +_cairo_boxes_init (cairo_boxes_t *boxes) +{ + boxes->status = CAIRO_STATUS_SUCCESS; + boxes->num_limits = 0; + boxes->num_boxes = 0; + + boxes->tail = &boxes->chunks; + boxes->chunks.next = NULL; + boxes->chunks.base = boxes->boxes_embedded; + boxes->chunks.size = ARRAY_LENGTH (boxes->boxes_embedded); + boxes->chunks.count = 0; + + boxes->is_pixel_aligned = TRUE; +} + +void +_cairo_boxes_init_from_rectangle (cairo_boxes_t *boxes, + int x, int y, int w, int h) +{ + _cairo_boxes_init (boxes); + + _cairo_box_from_integers (&boxes->chunks.base[0], x, y, w, h); + boxes->num_boxes = 1; +} + +void +_cairo_boxes_init_with_clip (cairo_boxes_t *boxes, + cairo_clip_t *clip) +{ + _cairo_boxes_init (boxes); + if (clip) + _cairo_boxes_limit (boxes, clip->boxes, clip->num_boxes); +} + +void +_cairo_boxes_init_for_array (cairo_boxes_t *boxes, + cairo_box_t *array, + int num_boxes) +{ + int n; + + boxes->status = CAIRO_STATUS_SUCCESS; + boxes->num_limits = 0; + boxes->num_boxes = num_boxes; + + boxes->tail = &boxes->chunks; + boxes->chunks.next = NULL; + boxes->chunks.base = array; + boxes->chunks.size = num_boxes; + boxes->chunks.count = num_boxes; + + for (n = 0; n < num_boxes; n++) { + if (! _cairo_fixed_is_integer (array[n].p1.x) || + ! _cairo_fixed_is_integer (array[n].p1.y) || + ! _cairo_fixed_is_integer (array[n].p2.x) || + ! _cairo_fixed_is_integer (array[n].p2.y)) + { + break; + } + } + + boxes->is_pixel_aligned = n == num_boxes; +} + +void +_cairo_boxes_limit (cairo_boxes_t *boxes, + const cairo_box_t *limits, + int num_limits) +{ + int n; + + boxes->limits = limits; + boxes->num_limits = num_limits; + + if (boxes->num_limits) { + boxes->limit = limits[0]; + for (n = 1; n < num_limits; n++) { + if (limits[n].p1.x < boxes->limit.p1.x) + boxes->limit.p1.x = limits[n].p1.x; + + if (limits[n].p1.y < boxes->limit.p1.y) + boxes->limit.p1.y = limits[n].p1.y; + + if (limits[n].p2.x > boxes->limit.p2.x) + boxes->limit.p2.x = limits[n].p2.x; + + if (limits[n].p2.y > boxes->limit.p2.y) + boxes->limit.p2.y = limits[n].p2.y; + } + } +} + +static void +_cairo_boxes_add_internal (cairo_boxes_t *boxes, + const cairo_box_t *box) +{ + struct _cairo_boxes_chunk *chunk; + + if (unlikely (boxes->status)) + return; + + chunk = boxes->tail; + if (unlikely (chunk->count == chunk->size)) { + int size; + + size = chunk->size * 2; + chunk->next = _cairo_malloc_ab_plus_c (size, + sizeof (cairo_box_t), + sizeof (struct _cairo_boxes_chunk)); + + if (unlikely (chunk->next == NULL)) { + boxes->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return; + } + + chunk = chunk->next; + boxes->tail = chunk; + + chunk->next = NULL; + chunk->count = 0; + chunk->size = size; + chunk->base = (cairo_box_t *) (chunk + 1); + } + + chunk->base[chunk->count++] = *box; + boxes->num_boxes++; + + if (boxes->is_pixel_aligned) + boxes->is_pixel_aligned = _cairo_box_is_pixel_aligned (box); +} + +cairo_status_t +_cairo_boxes_add (cairo_boxes_t *boxes, + cairo_antialias_t antialias, + const cairo_box_t *box) +{ + cairo_box_t b; + + if (antialias == CAIRO_ANTIALIAS_NONE) { + b.p1.x = _cairo_fixed_round_down (box->p1.x); + b.p1.y = _cairo_fixed_round_down (box->p1.y); + b.p2.x = _cairo_fixed_round_down (box->p2.x); + b.p2.y = _cairo_fixed_round_down (box->p2.y); + box = &b; + } + + if (box->p1.y == box->p2.y) + return CAIRO_STATUS_SUCCESS; + + if (box->p1.x == box->p2.x) + return CAIRO_STATUS_SUCCESS; + + if (boxes->num_limits) { + cairo_point_t p1, p2; + cairo_bool_t reversed = FALSE; + int n; + + /* support counter-clockwise winding for rectangular tessellation */ + if (box->p1.x < box->p2.x) { + p1.x = box->p1.x; + p2.x = box->p2.x; + } else { + p2.x = box->p1.x; + p1.x = box->p2.x; + reversed = ! reversed; + } + + if (p1.x >= boxes->limit.p2.x || p2.x <= boxes->limit.p1.x) + return CAIRO_STATUS_SUCCESS; + + if (box->p1.y < box->p2.y) { + p1.y = box->p1.y; + p2.y = box->p2.y; + } else { + p2.y = box->p1.y; + p1.y = box->p2.y; + reversed = ! reversed; + } + + if (p1.y >= boxes->limit.p2.y || p2.y <= boxes->limit.p1.y) + return CAIRO_STATUS_SUCCESS; + + for (n = 0; n < boxes->num_limits; n++) { + const cairo_box_t *limits = &boxes->limits[n]; + cairo_box_t _box; + cairo_point_t _p1, _p2; + + if (p1.x >= limits->p2.x || p2.x <= limits->p1.x) + continue; + if (p1.y >= limits->p2.y || p2.y <= limits->p1.y) + continue; + + /* Otherwise, clip the box to the limits. */ + _p1 = p1; + if (_p1.x < limits->p1.x) + _p1.x = limits->p1.x; + if (_p1.y < limits->p1.y) + _p1.y = limits->p1.y; + + _p2 = p2; + if (_p2.x > limits->p2.x) + _p2.x = limits->p2.x; + if (_p2.y > limits->p2.y) + _p2.y = limits->p2.y; + + if (_p2.y <= _p1.y || _p2.x <= _p1.x) + continue; + + _box.p1.y = _p1.y; + _box.p2.y = _p2.y; + if (reversed) { + _box.p1.x = _p2.x; + _box.p2.x = _p1.x; + } else { + _box.p1.x = _p1.x; + _box.p2.x = _p2.x; + } + + _cairo_boxes_add_internal (boxes, &_box); + } + } else { + _cairo_boxes_add_internal (boxes, box); + } + + return boxes->status; +} + +void +_cairo_boxes_extents (const cairo_boxes_t *boxes, + cairo_box_t *box) +{ + const struct _cairo_boxes_chunk *chunk; + cairo_box_t b; + int i; + + if (boxes->num_boxes == 0) { + box->p1.x = box->p1.y = box->p2.x = box->p2.y = 0; + return; + } + + b = boxes->chunks.base[0]; + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + if (chunk->base[i].p1.x < b.p1.x) + b.p1.x = chunk->base[i].p1.x; + + if (chunk->base[i].p1.y < b.p1.y) + b.p1.y = chunk->base[i].p1.y; + + if (chunk->base[i].p2.x > b.p2.x) + b.p2.x = chunk->base[i].p2.x; + + if (chunk->base[i].p2.y > b.p2.y) + b.p2.y = chunk->base[i].p2.y; + } + } + *box = b; +} + +void +_cairo_boxes_clear (cairo_boxes_t *boxes) +{ + struct _cairo_boxes_chunk *chunk, *next; + + for (chunk = boxes->chunks.next; chunk != NULL; chunk = next) { + next = chunk->next; + free (chunk); + } + + boxes->tail = &boxes->chunks; + boxes->chunks.next = 0; + boxes->chunks.count = 0; + boxes->chunks.base = boxes->boxes_embedded; + boxes->chunks.size = ARRAY_LENGTH (boxes->boxes_embedded); + boxes->num_boxes = 0; + + boxes->is_pixel_aligned = TRUE; +} + +cairo_box_t * +_cairo_boxes_to_array (const cairo_boxes_t *boxes, + int *num_boxes, + cairo_bool_t force_allocation) +{ + const struct _cairo_boxes_chunk *chunk; + cairo_box_t *box; + int i, j; + + *num_boxes = boxes->num_boxes; + if (boxes->chunks.next == NULL && ! force_allocation) + return boxes->chunks.base; + + box = _cairo_malloc_ab (boxes->num_boxes, sizeof (cairo_box_t)); + if (box == NULL) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + j = 0; + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) + box[j++] = chunk->base[i]; + } + + return box; +} + +void +_cairo_boxes_fini (cairo_boxes_t *boxes) +{ + struct _cairo_boxes_chunk *chunk, *next; + + for (chunk = boxes->chunks.next; chunk != NULL; chunk = next) { + next = chunk->next; + free (chunk); + } +} + +cairo_bool_t +_cairo_boxes_for_each_box (cairo_boxes_t *boxes, + cairo_bool_t (*func) (cairo_box_t *box, void *data), + void *data) +{ + struct _cairo_boxes_chunk *chunk; + int i; + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) + if (! func (&chunk->base[i], data)) + return FALSE; + } + + return TRUE; +} + +struct cairo_box_renderer { + cairo_span_renderer_t base; + cairo_boxes_t *boxes; +}; + +static cairo_status_t +span_to_boxes (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + struct cairo_box_renderer *r = abstract_renderer; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_box_t box; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + box.p1.y = _cairo_fixed_from_int (y); + box.p2.y = _cairo_fixed_from_int (y + h); + do { + if (spans[0].coverage) { + box.p1.x = _cairo_fixed_from_int(spans[0].x); + box.p2.x = _cairo_fixed_from_int(spans[1].x); + status = _cairo_boxes_add (r->boxes, CAIRO_ANTIALIAS_DEFAULT, &box); + } + spans++; + } while (--num_spans > 1 && status == CAIRO_STATUS_SUCCESS); + + return status; +} + +cairo_status_t +_cairo_rasterise_polygon_to_boxes (cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_boxes_t *boxes) +{ + struct cairo_box_renderer renderer; + cairo_scan_converter_t *converter; + cairo_int_status_t status; + cairo_rectangle_int_t r; + + TRACE ((stderr, "%s: fill_rule=%d\n", __FUNCTION__, fill_rule)); + + _cairo_box_round_to_rectangle (&polygon->extents, &r); + converter = _cairo_mono_scan_converter_create (r.x, r.y, + r.x + r.width, + r.y + r.height, + fill_rule); + status = _cairo_mono_scan_converter_add_polygon (converter, polygon); + if (unlikely (status)) + goto cleanup_converter; + + renderer.boxes = boxes; + renderer.base.render_rows = span_to_boxes; + + status = converter->generate (converter, &renderer.base); +cleanup_converter: + converter->destroy (converter); + return status; +} + +void +_cairo_debug_print_boxes (FILE *stream, const cairo_boxes_t *boxes) +{ + const struct _cairo_boxes_chunk *chunk; + cairo_box_t extents; + int i; + + _cairo_boxes_extents (boxes, &extents); + fprintf (stream, "boxes x %d: (%f, %f) x (%f, %f)\n", + boxes->num_boxes, + _cairo_fixed_to_double (extents.p1.x), + _cairo_fixed_to_double (extents.p1.y), + _cairo_fixed_to_double (extents.p2.x), + _cairo_fixed_to_double (extents.p2.y)); + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + fprintf (stderr, " box[%d]: (%f, %f), (%f, %f)\n", i, + _cairo_fixed_to_double (chunk->base[i].p1.x), + _cairo_fixed_to_double (chunk->base[i].p1.y), + _cairo_fixed_to_double (chunk->base[i].p2.x), + _cairo_fixed_to_double (chunk->base[i].p2.y)); + } + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cache-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-cache-private.h new file mode 100644 index 00000000000..24b6d0b2092 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cache-private.h @@ -0,0 +1,145 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc. + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Keith Packard + * Graydon Hoare + * Carl Worth + */ + +#ifndef CAIRO_CACHE_PRIVATE_H +#define CAIRO_CACHE_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-types-private.h" + +/** + * _cairo_cache_entry: + * + * A #cairo_cache_entry_t contains both a key and a value for + * #cairo_cache_t. User-derived types for #cairo_cache_entry_t must + * have a #cairo_cache_entry_t as their first field. For example: + * + * typedef _my_entry { + * cairo_cache_entry_t base; + * ... Remainder of key and value fields here .. + * } my_entry_t; + * + * which then allows a pointer to my_entry_t to be passed to any of + * the #cairo_cache_t functions as follows without requiring a cast: + * + * _cairo_cache_insert (cache, &my_entry->base, size); + * + * IMPORTANT: The caller is responsible for initializing + * my_entry->base.hash with a hash code derived from the key. The + * essential property of the hash code is that keys_equal must never + * return %TRUE for two keys that have different hashes. The best hash + * code will reduce the frequency of two keys with the same code for + * which keys_equal returns %FALSE. + * + * The user must also initialize my_entry->base.size to indicate + * the size of the current entry. What units to use for size is + * entirely up to the caller, (though the same units must be used for + * the max_size parameter passed to _cairo_cache_create()). If all + * entries are close to the same size, the simplest thing to do is to + * just use units of "entries", (eg. set size==1 in all entries and + * set max_size to the number of entries which you want to be saved + * in the cache). + * + * Which parts of the entry make up the "key" and which part make up + * the value are entirely up to the caller, (as determined by the + * computation going into base.hash as well as the keys_equal + * function). A few of the #cairo_cache_t functions accept an entry which + * will be used exclusively as a "key", (indicated by a parameter name + * of key). In these cases, the value-related fields of the entry need + * not be initialized if so desired. + **/ +typedef struct _cairo_cache_entry { + unsigned long hash; + unsigned long size; +} cairo_cache_entry_t; + +typedef cairo_bool_t (*cairo_cache_predicate_func_t) (const void *entry); + +struct _cairo_cache { + cairo_hash_table_t *hash_table; + + cairo_cache_predicate_func_t predicate; + cairo_destroy_func_t entry_destroy; + + unsigned long max_size; + unsigned long size; + + int freeze_count; +}; + +typedef cairo_bool_t +(*cairo_cache_keys_equal_func_t) (const void *key_a, const void *key_b); + +typedef void +(*cairo_cache_callback_func_t) (void *entry, + void *closure); + +cairo_private cairo_status_t +_cairo_cache_init (cairo_cache_t *cache, + cairo_cache_keys_equal_func_t keys_equal, + cairo_cache_predicate_func_t predicate, + cairo_destroy_func_t entry_destroy, + unsigned long max_size); + +cairo_private void +_cairo_cache_fini (cairo_cache_t *cache); + +cairo_private void +_cairo_cache_freeze (cairo_cache_t *cache); + +cairo_private void +_cairo_cache_thaw (cairo_cache_t *cache); + +cairo_private void * +_cairo_cache_lookup (cairo_cache_t *cache, + cairo_cache_entry_t *key); + +cairo_private cairo_status_t +_cairo_cache_insert (cairo_cache_t *cache, + cairo_cache_entry_t *entry); + +cairo_private void +_cairo_cache_remove (cairo_cache_t *cache, + cairo_cache_entry_t *entry); + +cairo_private void +_cairo_cache_foreach (cairo_cache_t *cache, + cairo_cache_callback_func_t cache_callback, + void *closure); + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cache.c b/Build/source/libs/cairo/cairo-src/src/cairo-cache.c new file mode 100644 index 00000000000..5c4e4caa3d0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cache.c @@ -0,0 +1,338 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc. + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Keith Packard + * Graydon Hoare + * Carl Worth + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +static void +_cairo_cache_shrink_to_accommodate (cairo_cache_t *cache, + unsigned long additional); + +static cairo_bool_t +_cairo_cache_entry_is_non_zero (const void *entry) +{ + return ((const cairo_cache_entry_t *) entry)->size; +} + + +/** + * _cairo_cache_init: + * @cache: the #cairo_cache_t to initialise + * @keys_equal: a function to return %TRUE if two keys are equal + * @entry_destroy: destroy notifier for cache entries + * @max_size: the maximum size for this cache + * Returns: the newly created #cairo_cache_t + * + * Creates a new cache using the keys_equal() function to determine + * the equality of entries. + * + * Data is provided to the cache in the form of user-derived version + * of #cairo_cache_entry_t. A cache entry must be able to hold hash + * code, a size, and the key/value pair being stored in the + * cache. Sometimes only the key will be necessary, (as in + * _cairo_cache_lookup()), and in these cases the value portion of the + * entry need not be initialized. + * + * The units for max_size can be chosen by the caller, but should be + * consistent with the units of the size field of cache entries. When + * adding an entry with _cairo_cache_insert() if the total size of + * entries in the cache would exceed max_size then entries will be + * removed at random until the new entry would fit or the cache is + * empty. Then the new entry is inserted. + * + * There are cases in which the automatic removal of entries is + * undesired. If the cache entries have reference counts, then it is a + * simple matter to use the reference counts to ensure that entries + * continue to live even after being ejected from the cache. However, + * in some cases the memory overhead of adding a reference count to + * the entry would be objectionable. In such cases, the + * _cairo_cache_freeze() and _cairo_cache_thaw() calls can be + * used to establish a window during which no automatic removal of + * entries will occur. + **/ +cairo_status_t +_cairo_cache_init (cairo_cache_t *cache, + cairo_cache_keys_equal_func_t keys_equal, + cairo_cache_predicate_func_t predicate, + cairo_destroy_func_t entry_destroy, + unsigned long max_size) +{ + cache->hash_table = _cairo_hash_table_create (keys_equal); + if (unlikely (cache->hash_table == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (predicate == NULL) + predicate = _cairo_cache_entry_is_non_zero; + cache->predicate = predicate; + cache->entry_destroy = entry_destroy; + + cache->max_size = max_size; + cache->size = 0; + + cache->freeze_count = 0; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_cache_pluck (void *entry, void *closure) +{ + _cairo_cache_remove (closure, entry); +} + +/** + * _cairo_cache_fini: + * @cache: a cache to destroy + * + * Immediately destroys the given cache, freeing all resources + * associated with it. As part of this process, the entry_destroy() + * function, (as passed to _cairo_cache_init()), will be called for + * each entry in the cache. + **/ +void +_cairo_cache_fini (cairo_cache_t *cache) +{ + _cairo_hash_table_foreach (cache->hash_table, + _cairo_cache_pluck, + cache); + assert (cache->size == 0); + _cairo_hash_table_destroy (cache->hash_table); +} + +/** + * _cairo_cache_freeze: + * @cache: a cache with some precious entries in it (or about to be + * added) + * + * Disable the automatic ejection of entries from the cache. For as + * long as the cache is "frozen", calls to _cairo_cache_insert() will + * add new entries to the cache regardless of how large the cache + * grows. See _cairo_cache_thaw(). + * + * Note: Multiple calls to _cairo_cache_freeze() will stack, in that + * the cache will remain "frozen" until a corresponding number of + * calls are made to _cairo_cache_thaw(). + **/ +void +_cairo_cache_freeze (cairo_cache_t *cache) +{ + assert (cache->freeze_count >= 0); + + cache->freeze_count++; +} + +/** + * _cairo_cache_thaw: + * @cache: a cache, just after the entries in it have become less + * precious + * + * Cancels the effects of _cairo_cache_freeze(). + * + * When a number of calls to _cairo_cache_thaw() is made corresponding + * to the number of calls to _cairo_cache_freeze() the cache will no + * longer be "frozen". If the cache had grown larger than max_size + * while frozen, entries will immediately be ejected (by random) from + * the cache until the cache is smaller than max_size. Also, the + * automatic ejection of entries on _cairo_cache_insert() will resume. + **/ +void +_cairo_cache_thaw (cairo_cache_t *cache) +{ + assert (cache->freeze_count > 0); + + if (--cache->freeze_count == 0) + _cairo_cache_shrink_to_accommodate (cache, 0); +} + +/** + * _cairo_cache_lookup: + * @cache: a cache + * @key: the key of interest + * @entry_return: pointer for return value + * + * Performs a lookup in @cache looking for an entry which has a key + * that matches @key, (as determined by the keys_equal() function + * passed to _cairo_cache_init()). + * + * Return value: %TRUE if there is an entry in the cache that matches + * @key, (which will now be in *entry_return). %FALSE otherwise, (in + * which case *entry_return will be %NULL). + **/ +void * +_cairo_cache_lookup (cairo_cache_t *cache, + cairo_cache_entry_t *key) +{ + return _cairo_hash_table_lookup (cache->hash_table, + (cairo_hash_entry_t *) key); +} + +/** + * _cairo_cache_remove_random: + * @cache: a cache + * + * Remove a random entry from the cache. + * + * Return value: %TRUE if an entry was successfully removed. + * %FALSE if there are no entries that can be removed. + **/ +static cairo_bool_t +_cairo_cache_remove_random (cairo_cache_t *cache) +{ + cairo_cache_entry_t *entry; + + entry = _cairo_hash_table_random_entry (cache->hash_table, + cache->predicate); + if (unlikely (entry == NULL)) + return FALSE; + + _cairo_cache_remove (cache, entry); + + return TRUE; +} + +/** + * _cairo_cache_shrink_to_accommodate: + * @cache: a cache + * @additional: additional size requested in bytes + * + * If cache is not frozen, eject entries randomly until the size of + * the cache is at least @additional bytes less than + * cache->max_size. That is, make enough room to accommodate a new + * entry of size @additional. + **/ +static void +_cairo_cache_shrink_to_accommodate (cairo_cache_t *cache, + unsigned long additional) +{ + while (cache->size + additional > cache->max_size) { + if (! _cairo_cache_remove_random (cache)) + return; + } +} + +/** + * _cairo_cache_insert: + * @cache: a cache + * @entry: an entry to be inserted + * + * Insert @entry into the cache. If an entry exists in the cache with + * a matching key, then the old entry will be removed first, (and the + * entry_destroy() callback will be called on it). + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available. + **/ +cairo_status_t +_cairo_cache_insert (cairo_cache_t *cache, + cairo_cache_entry_t *entry) +{ + cairo_status_t status; + + if (entry->size && ! cache->freeze_count) + _cairo_cache_shrink_to_accommodate (cache, entry->size); + + status = _cairo_hash_table_insert (cache->hash_table, + (cairo_hash_entry_t *) entry); + if (unlikely (status)) + return status; + + cache->size += entry->size; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_cache_remove: + * @cache: a cache + * @entry: an entry that exists in the cache + * + * Remove an existing entry from the cache. + **/ +void +_cairo_cache_remove (cairo_cache_t *cache, + cairo_cache_entry_t *entry) +{ + cache->size -= entry->size; + + _cairo_hash_table_remove (cache->hash_table, + (cairo_hash_entry_t *) entry); + + if (cache->entry_destroy) + cache->entry_destroy (entry); +} + +/** + * _cairo_cache_foreach: + * @cache: a cache + * @cache_callback: function to be called for each entry + * @closure: additional argument to be passed to @cache_callback + * + * Call @cache_callback for each entry in the cache, in a + * non-specified order. + **/ +void +_cairo_cache_foreach (cairo_cache_t *cache, + cairo_cache_callback_func_t cache_callback, + void *closure) +{ + _cairo_hash_table_foreach (cache->hash_table, + cache_callback, + closure); +} + +unsigned long +_cairo_hash_string (const char *c) +{ + /* This is the djb2 hash. */ + unsigned long hash = _CAIRO_HASH_INIT_VALUE; + while (c && *c) + hash = ((hash << 5) + hash) + *c++; + return hash; +} + +unsigned long +_cairo_hash_bytes (unsigned long hash, + const void *ptr, + unsigned int length) +{ + const uint8_t *bytes = ptr; + /* This is the djb2 hash. */ + while (length--) + hash = ((hash << 5) + hash) + *bytes++; + return hash; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cff-subset.c b/Build/source/libs/cairo/cairo-src/src/cairo-cff-subset.c new file mode 100644 index 00000000000..3ffe6f663f7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cff-subset.c @@ -0,0 +1,3440 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + * Eugeniy Meshcheryakov + */ + +/* + * Useful links: + * http://www.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5176.CFF.pdf + * http://www.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5177.Type2.pdf + */ + +#define _BSD_SOURCE /* for snprintf(), strdup() */ +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-truetype-subset-private.h" +#include +#include + +/* CFF Dict Operators. If the high byte is 0 the command is encoded + * with a single byte. */ +#define BASEFONTNAME_OP 0x0c16 +#define CIDCOUNT_OP 0x0c22 +#define CHARSET_OP 0x000f +#define CHARSTRINGS_OP 0x0011 +#define COPYRIGHT_OP 0x0c00 +#define DEFAULTWIDTH_OP 0x0014 +#define ENCODING_OP 0x0010 +#define FAMILYNAME_OP 0x0003 +#define FDARRAY_OP 0x0c24 +#define FDSELECT_OP 0x0c25 +#define FONTBBOX_OP 0x0005 +#define FONTMATRIX_OP 0x0c07 +#define FONTNAME_OP 0x0c26 +#define FULLNAME_OP 0x0002 +#define LOCAL_SUB_OP 0x0013 +#define NOMINALWIDTH_OP 0x0015 +#define NOTICE_OP 0x0001 +#define POSTSCRIPT_OP 0x0c15 +#define PRIVATE_OP 0x0012 +#define ROS_OP 0x0c1e +#define UNIQUEID_OP 0x000d +#define VERSION_OP 0x0000 +#define WEIGHT_OP 0x0004 +#define XUID_OP 0x000e + +#define NUM_STD_STRINGS 391 + +/* Type 2 Charstring operators */ +#define TYPE2_hstem 0x0001 +#define TYPE2_vstem 0x0003 +#define TYPE2_callsubr 0x000a + +#define TYPE2_return 0x000b +#define TYPE2_endchar 0x000e + +#define TYPE2_hstemhm 0x0012 +#define TYPE2_hintmask 0x0013 +#define TYPE2_cntrmask 0x0014 +#define TYPE2_vstemhm 0x0017 +#define TYPE2_callgsubr 0x001d + +#define TYPE2_rmoveto 0x0015 +#define TYPE2_hmoveto 0x0016 +#define TYPE2_vmoveto 0x0004 + + +#define MAX_SUBROUTINE_NESTING 10 /* From Type2 Charstring spec */ + + +typedef struct _cff_header { + uint8_t major; + uint8_t minor; + uint8_t header_size; + uint8_t offset_size; +} cff_header_t; + +typedef struct _cff_index_element { + cairo_bool_t is_copy; + unsigned char *data; + int length; +} cff_index_element_t; + +typedef struct _cff_dict_operator { + cairo_hash_entry_t base; + + unsigned short operator; + unsigned char *operand; + int operand_length; + int operand_offset; +} cff_dict_operator_t; + +typedef struct _cairo_cff_font { + + cairo_scaled_font_subset_t *scaled_font_subset; + const cairo_scaled_font_backend_t *backend; + + /* Font Data */ + unsigned char *data; + unsigned long data_length; + unsigned char *current_ptr; + unsigned char *data_end; + cff_header_t *header; + char *font_name; + char *ps_name; + cairo_hash_table_t *top_dict; + cairo_hash_table_t *private_dict; + cairo_array_t strings_index; + cairo_array_t charstrings_index; + cairo_array_t global_sub_index; + cairo_array_t local_sub_index; + unsigned char *charset; + int num_glyphs; + cairo_bool_t is_cid; + cairo_bool_t is_opentype; + int units_per_em; + int global_sub_bias; + int local_sub_bias; + double default_width; + double nominal_width; + + /* CID Font Data */ + int *fdselect; + unsigned int num_fontdicts; + cairo_hash_table_t **fd_dict; + cairo_hash_table_t **fd_private_dict; + cairo_array_t *fd_local_sub_index; + int *fd_local_sub_bias; + double *fd_default_width; + double *fd_nominal_width; + + /* Subsetted Font Data */ + char *subset_font_name; + cairo_array_t charstrings_subset_index; + cairo_array_t strings_subset_index; + int euro_sid; + int *fdselect_subset; + unsigned int num_subset_fontdicts; + int *fd_subset_map; + int *private_dict_offset; + cairo_bool_t subset_subroutines; + cairo_bool_t *global_subs_used; + cairo_bool_t *local_subs_used; + cairo_bool_t **fd_local_subs_used; + cairo_array_t output; + + /* Subset Metrics */ + int *widths; + int x_min, y_min, x_max, y_max; + int ascent, descent; + + /* Type 2 charstring data */ + int type2_stack_size; + int type2_stack_top_value; + cairo_bool_t type2_stack_top_is_int; + int type2_num_hints; + int type2_hintmask_bytes; + int type2_nesting_level; + cairo_bool_t type2_seen_first_int; + cairo_bool_t type2_find_width; + cairo_bool_t type2_found_width; + int type2_width; + cairo_bool_t type2_has_path; + +} cairo_cff_font_t; + +/* Encoded integer using maximum sized encoding. This is required for + * operands that are later modified after encoding. */ +static unsigned char * +encode_integer_max (unsigned char *p, int i) +{ + *p++ = 29; + *p++ = i >> 24; + *p++ = (i >> 16) & 0xff; + *p++ = (i >> 8) & 0xff; + *p++ = i & 0xff; + return p; +} + +static unsigned char * +encode_integer (unsigned char *p, int i) +{ + if (i >= -107 && i <= 107) { + *p++ = i + 139; + } else if (i >= 108 && i <= 1131) { + i -= 108; + *p++ = (i >> 8)+ 247; + *p++ = i & 0xff; + } else if (i >= -1131 && i <= -108) { + i = -i - 108; + *p++ = (i >> 8)+ 251; + *p++ = i & 0xff; + } else if (i >= -32768 && i <= 32767) { + *p++ = 28; + *p++ = (i >> 8) & 0xff; + *p++ = i & 0xff; + } else { + p = encode_integer_max (p, i); + } + return p; +} + +static unsigned char * +decode_integer (unsigned char *p, int *integer) +{ + if (*p == 28) { + *integer = (int)(p[1]<<8 | p[2]); + p += 3; + } else if (*p == 29) { + *integer = (int)((p[1] << 24) | (p[2] << 16) | (p[3] << 8) | p[4]); + p += 5; + } else if (*p >= 32 && *p <= 246) { + *integer = *p++ - 139; + } else if (*p <= 250) { + *integer = (p[0] - 247) * 256 + p[1] + 108; + p += 2; + } else if (*p <= 254) { + *integer = -(p[0] - 251) * 256 - p[1] - 108; + p += 2; + } else { + *integer = 0; + p += 1; + } + return p; +} + +static char * +decode_nibble (int n, char *buf) +{ + switch (n) + { + case 0xa: + *buf++ = '.'; + break; + case 0xb: + *buf++ = 'E'; + break; + case 0xc: + *buf++ = 'E'; + *buf++ = '-'; + break; + case 0xd: + *buf++ = '-'; + break; + case 0xe: + *buf++ = '-'; + break; + case 0xf: + break; + default: + *buf++ = '0' + n; + break; + } + + return buf; +} + +static unsigned char * +decode_real (unsigned char *p, double *real) +{ + const char *decimal_point; + int decimal_point_len; + int n; + char buffer[100]; + char buffer2[200]; + char *q; + char *buf = buffer; + char *buf_end = buffer + sizeof (buffer); + + decimal_point = cairo_get_locale_decimal_point (); + decimal_point_len = strlen (decimal_point); + + assert (decimal_point_len != 0); + assert (sizeof(buffer) + decimal_point_len < sizeof(buffer2)); + + p++; + while (buf + 2 < buf_end) { + n = *p >> 4; + buf = decode_nibble (n, buf); + n = *p & 0x0f; + buf = decode_nibble (n, buf); + if ((*p & 0x0f) == 0x0f) { + p++; + break; + } + p++; + }; + *buf = 0; + + buf = buffer; + if (strchr (buffer, '.')) { + q = strchr (buffer, '.'); + strncpy (buffer2, buffer, q - buffer); + buf = buffer2 + (q - buffer); + strncpy (buf, decimal_point, decimal_point_len); + buf += decimal_point_len; + strcpy (buf, q + 1); + buf = buffer2; + } + + if (sscanf(buf, "%lf", real) != 1) + *real = 0.0; + + return p; +} + +static unsigned char * +decode_number (unsigned char *p, double *number) +{ + if (*p == 30) { + p = decode_real (p, number); + } else { + int i; + p = decode_integer (p, &i); + *number = i; + } + return p; +} + +static unsigned char * +decode_operator (unsigned char *p, unsigned short *operator) +{ + unsigned short op = 0; + + op = *p++; + if (op == 12) { + op <<= 8; + op |= *p++; + } + *operator = op; + return p; +} + +/* return 0 if not an operand */ +static int +operand_length (unsigned char *p) +{ + unsigned char *begin = p; + + if (*p == 28) + return 3; + + if (*p == 29) + return 5; + + if (*p >= 32 && *p <= 246) + return 1; + + if (*p >= 247 && *p <= 254) + return 2; + + if (*p == 30) { + while ((*p & 0x0f) != 0x0f) + p++; + return p - begin + 1; + } + + return 0; +} + +static unsigned char * +encode_index_offset (unsigned char *p, int offset_size, unsigned long offset) +{ + while (--offset_size >= 0) { + p[offset_size] = (unsigned char) (offset & 0xff); + offset >>= 8; + } + return p + offset_size; +} + +static unsigned long +decode_index_offset(unsigned char *p, int off_size) +{ + unsigned long offset = 0; + + while (off_size-- > 0) + offset = offset*256 + *p++; + return offset; +} + +static void +cff_index_init (cairo_array_t *index) +{ + _cairo_array_init (index, sizeof (cff_index_element_t)); +} + +static cairo_int_status_t +cff_index_read (cairo_array_t *index, unsigned char **ptr, unsigned char *end_ptr) +{ + cff_index_element_t element; + unsigned char *data, *p; + cairo_status_t status; + int offset_size, count, start, i; + int end = 0; + + p = *ptr; + if (p + 2 > end_ptr) + return CAIRO_INT_STATUS_UNSUPPORTED; + count = get_unaligned_be16 (p); + p += 2; + if (count > 0) { + offset_size = *p++; + if (p + (count + 1)*offset_size > end_ptr) + return CAIRO_INT_STATUS_UNSUPPORTED; + data = p + offset_size*(count + 1) - 1; + start = decode_index_offset (p, offset_size); + p += offset_size; + for (i = 0; i < count; i++) { + end = decode_index_offset (p, offset_size); + p += offset_size; + if (p > end_ptr) + return CAIRO_INT_STATUS_UNSUPPORTED; + element.length = end - start; + element.is_copy = FALSE; + element.data = data + start; + status = _cairo_array_append (index, &element); + if (unlikely (status)) + return status; + start = end; + } + p = data + end; + } + *ptr = p; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cff_index_write (cairo_array_t *index, cairo_array_t *output) +{ + int offset_size; + int offset; + int num_elem; + int i; + cff_index_element_t *element; + uint16_t count; + unsigned char buf[5]; + cairo_status_t status; + + num_elem = _cairo_array_num_elements (index); + count = cpu_to_be16 ((uint16_t) num_elem); + status = _cairo_array_append_multiple (output, &count, 2); + if (unlikely (status)) + return status; + + if (num_elem == 0) + return CAIRO_STATUS_SUCCESS; + + /* Find maximum offset to determine offset size */ + offset = 1; + for (i = 0; i < num_elem; i++) { + element = _cairo_array_index (index, i); + offset += element->length; + } + if (offset < 0x100) + offset_size = 1; + else if (offset < 0x10000) + offset_size = 2; + else if (offset < 0x1000000) + offset_size = 3; + else + offset_size = 4; + + buf[0] = (unsigned char) offset_size; + status = _cairo_array_append (output, buf); + if (unlikely (status)) + return status; + + offset = 1; + encode_index_offset (buf, offset_size, offset); + status = _cairo_array_append_multiple (output, buf, offset_size); + if (unlikely (status)) + return status; + + for (i = 0; i < num_elem; i++) { + element = _cairo_array_index (index, i); + offset += element->length; + encode_index_offset (buf, offset_size, offset); + status = _cairo_array_append_multiple (output, buf, offset_size); + if (unlikely (status)) + return status; + } + + for (i = 0; i < num_elem; i++) { + element = _cairo_array_index (index, i); + if (element->length > 0) { + status = _cairo_array_append_multiple (output, + element->data, + element->length); + } + if (unlikely (status)) + return status; + } + return CAIRO_STATUS_SUCCESS; +} + +static void +cff_index_set_object (cairo_array_t *index, int obj_index, + unsigned char *object , int length) +{ + cff_index_element_t *element; + + element = _cairo_array_index (index, obj_index); + if (element->is_copy) + free (element->data); + + element->data = object; + element->length = length; + element->is_copy = FALSE; +} + +static cairo_status_t +cff_index_append (cairo_array_t *index, unsigned char *object , int length) +{ + cff_index_element_t element; + + element.length = length; + element.is_copy = FALSE; + element.data = object; + + return _cairo_array_append (index, &element); +} + +static cairo_status_t +cff_index_append_copy (cairo_array_t *index, + const unsigned char *object, + unsigned int length) +{ + cff_index_element_t element; + cairo_status_t status; + + element.length = length; + element.is_copy = TRUE; + element.data = malloc (element.length); + if (unlikely (element.data == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (element.data, object, element.length); + + status = _cairo_array_append (index, &element); + if (unlikely (status)) { + free (element.data); + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +cff_index_fini (cairo_array_t *index) +{ + cff_index_element_t *element; + unsigned int i; + + for (i = 0; i < _cairo_array_num_elements (index); i++) { + element = _cairo_array_index (index, i); + if (element->is_copy && element->data) + free (element->data); + } + _cairo_array_fini (index); +} + +static cairo_bool_t +_cairo_cff_dict_equal (const void *key_a, const void *key_b) +{ + const cff_dict_operator_t *op_a = key_a; + const cff_dict_operator_t *op_b = key_b; + + return op_a->operator == op_b->operator; +} + +static cairo_status_t +cff_dict_init (cairo_hash_table_t **dict) +{ + *dict = _cairo_hash_table_create (_cairo_cff_dict_equal); + if (unlikely (*dict == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_dict_init_key (cff_dict_operator_t *key, int operator) +{ + key->base.hash = (unsigned long) operator; + key->operator = operator; +} + +static cairo_status_t +cff_dict_create_operator (int operator, + unsigned char *operand, + int size, + cff_dict_operator_t **out) +{ + cff_dict_operator_t *op; + + op = malloc (sizeof (cff_dict_operator_t)); + if (unlikely (op == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_dict_init_key (op, operator); + op->operand = malloc (size); + if (unlikely (op->operand == NULL)) { + free (op); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + memcpy (op->operand, operand, size); + op->operand_length = size; + op->operand_offset = -1; + + *out = op; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cff_dict_read (cairo_hash_table_t *dict, unsigned char *p, int dict_size) +{ + unsigned char *end; + cairo_array_t operands; + cff_dict_operator_t *op; + unsigned short operator; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + int size; + + end = p + dict_size; + _cairo_array_init (&operands, 1); + while (p < end) { + size = operand_length (p); + if (size != 0) { + status = _cairo_array_append_multiple (&operands, p, size); + if (unlikely (status)) + goto fail; + + p += size; + } else { + p = decode_operator (p, &operator); + status = cff_dict_create_operator (operator, + _cairo_array_index (&operands, 0), + _cairo_array_num_elements (&operands), + &op); + if (unlikely (status)) + goto fail; + + status = _cairo_hash_table_insert (dict, &op->base); + if (unlikely (status)) + goto fail; + + _cairo_array_truncate (&operands, 0); + } + } + +fail: + _cairo_array_fini (&operands); + + return status; +} + +static void +cff_dict_remove (cairo_hash_table_t *dict, unsigned short operator) +{ + cff_dict_operator_t key, *op; + + _cairo_dict_init_key (&key, operator); + op = _cairo_hash_table_lookup (dict, &key.base); + if (op != NULL) { + free (op->operand); + _cairo_hash_table_remove (dict, (cairo_hash_entry_t *) op); + free (op); + } +} + +static unsigned char * +cff_dict_get_operands (cairo_hash_table_t *dict, + unsigned short operator, + int *size) +{ + cff_dict_operator_t key, *op; + + _cairo_dict_init_key (&key, operator); + op = _cairo_hash_table_lookup (dict, &key.base); + if (op != NULL) { + *size = op->operand_length; + return op->operand; + } + + return NULL; +} + +static cairo_status_t +cff_dict_set_operands (cairo_hash_table_t *dict, + unsigned short operator, + unsigned char *operand, + int size) +{ + cff_dict_operator_t key, *op; + cairo_status_t status; + + _cairo_dict_init_key (&key, operator); + op = _cairo_hash_table_lookup (dict, &key.base); + if (op != NULL) { + free (op->operand); + op->operand = malloc (size); + if (unlikely (op->operand == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (op->operand, operand, size); + op->operand_length = size; + } + else + { + status = cff_dict_create_operator (operator, operand, size, &op); + if (unlikely (status)) + return status; + + status = _cairo_hash_table_insert (dict, &op->base); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static int +cff_dict_get_location (cairo_hash_table_t *dict, + unsigned short operator, + int *size) +{ + cff_dict_operator_t key, *op; + + _cairo_dict_init_key (&key, operator); + op = _cairo_hash_table_lookup (dict, &key.base); + if (op != NULL) { + *size = op->operand_length; + return op->operand_offset; + } + + return -1; +} + +typedef struct _dict_write_info { + cairo_array_t *output; + cairo_status_t status; +} dict_write_info_t; + +static void +cairo_dict_write_operator (cff_dict_operator_t *op, dict_write_info_t *write_info) +{ + unsigned char data; + + op->operand_offset = _cairo_array_num_elements (write_info->output); + write_info->status = _cairo_array_append_multiple (write_info->output, op->operand, op->operand_length); + if (write_info->status) + return; + + if (op->operator & 0xff00) { + data = op->operator >> 8; + write_info->status = _cairo_array_append (write_info->output, &data); + if (write_info->status) + return; + } + data = op->operator & 0xff; + write_info->status = _cairo_array_append (write_info->output, &data); +} + +static void +_cairo_dict_collect (void *entry, void *closure) +{ + dict_write_info_t *write_info = closure; + cff_dict_operator_t *op = entry; + + if (write_info->status) + return; + + /* The ROS operator is handled separately in cff_dict_write() */ + if (op->operator != ROS_OP) + cairo_dict_write_operator (op, write_info); +} + +static cairo_status_t +cff_dict_write (cairo_hash_table_t *dict, cairo_array_t *output) +{ + dict_write_info_t write_info; + cff_dict_operator_t key, *op; + + write_info.output = output; + write_info.status = CAIRO_STATUS_SUCCESS; + + /* The CFF specification requires that the Top Dict of CID fonts + * begin with the ROS operator. */ + _cairo_dict_init_key (&key, ROS_OP); + op = _cairo_hash_table_lookup (dict, &key.base); + if (op != NULL) + cairo_dict_write_operator (op, &write_info); + + _cairo_hash_table_foreach (dict, _cairo_dict_collect, &write_info); + + return write_info.status; +} + +static void +_cff_dict_entry_pluck (void *_entry, void *dict) +{ + cff_dict_operator_t *entry = _entry; + + _cairo_hash_table_remove (dict, &entry->base); + free (entry->operand); + free (entry); +} + +static void +cff_dict_fini (cairo_hash_table_t *dict) +{ + _cairo_hash_table_foreach (dict, _cff_dict_entry_pluck, dict); + _cairo_hash_table_destroy (dict); +} + +static cairo_int_status_t +cairo_cff_font_read_header (cairo_cff_font_t *font) +{ + if (font->data_length < sizeof (cff_header_t)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + + font->header = (cff_header_t *) font->data; + font->current_ptr = font->data + font->header->header_size; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_cff_font_read_name (cairo_cff_font_t *font) +{ + cairo_array_t index; + cairo_int_status_t status; + cff_index_element_t *element; + unsigned char *p; + int i, len; + + cff_index_init (&index); + status = cff_index_read (&index, &font->current_ptr, font->data_end); + if (!font->is_opentype) { + element = _cairo_array_index (&index, 0); + p = element->data; + len = element->length; + + /* If font name is prefixed with a subset tag, strip it off. */ + if (len > 7 && p[6] == '+') { + for (i = 0; i < 6; i++) + if (p[i] < 'A' || p[i] > 'Z') + break; + if (i == 6) { + p += 7; + len -= 7; + } + } + font->ps_name = malloc (len + 1); + if (unlikely (font->ps_name == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (font->ps_name, p, len); + font->ps_name[len] = 0; + + status = _cairo_escape_ps_name (&font->ps_name); + } + cff_index_fini (&index); + + return status; +} + +static cairo_int_status_t +cairo_cff_font_read_private_dict (cairo_cff_font_t *font, + cairo_hash_table_t *private_dict, + cairo_array_t *local_sub_index, + int *local_sub_bias, + cairo_bool_t **local_subs_used, + double *default_width, + double *nominal_width, + unsigned char *ptr, + int size) +{ + cairo_int_status_t status; + unsigned char buf[10]; + unsigned char *end_buf; + int offset; + int i; + unsigned char *operand; + unsigned char *p; + int num_subs; + + status = cff_dict_read (private_dict, ptr, size); + if (unlikely (status)) + return status; + + operand = cff_dict_get_operands (private_dict, LOCAL_SUB_OP, &i); + if (operand) { + decode_integer (operand, &offset); + p = ptr + offset; + status = cff_index_read (local_sub_index, &p, font->data_end); + if (unlikely (status)) + return status; + + /* Use maximum sized encoding to reserve space for later modification. */ + end_buf = encode_integer_max (buf, 0); + status = cff_dict_set_operands (private_dict, LOCAL_SUB_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + } + + *default_width = 0; + operand = cff_dict_get_operands (private_dict, DEFAULTWIDTH_OP, &i); + if (operand) + decode_number (operand, default_width); + + *nominal_width = 0; + operand = cff_dict_get_operands (private_dict, NOMINALWIDTH_OP, &i); + if (operand) + decode_number (operand, nominal_width); + + num_subs = _cairo_array_num_elements (local_sub_index); + *local_subs_used = calloc (num_subs, sizeof (cairo_bool_t)); + if (unlikely (*local_subs_used == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (num_subs < 1240) + *local_sub_bias = 107; + else if (num_subs < 33900) + *local_sub_bias = 1131; + else + *local_sub_bias = 32768; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_cff_font_read_fdselect (cairo_cff_font_t *font, unsigned char *p) +{ + int type, num_ranges, first, last, fd, i, j; + + font->fdselect = calloc (font->num_glyphs, sizeof (int)); + if (unlikely (font->fdselect == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + type = *p++; + if (type == 0) + { + for (i = 0; i < font->num_glyphs; i++) + font->fdselect[i] = *p++; + } else if (type == 3) { + num_ranges = get_unaligned_be16 (p); + p += 2; + for (i = 0; i < num_ranges; i++) + { + first = get_unaligned_be16 (p); + p += 2; + fd = *p++; + last = get_unaligned_be16 (p); + for (j = first; j < last; j++) + font->fdselect[j] = fd; + } + } else { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_cff_font_read_cid_fontdict (cairo_cff_font_t *font, unsigned char *ptr) +{ + cairo_array_t index; + cff_index_element_t *element; + unsigned int i; + int size; + unsigned char *operand; + int offset; + cairo_int_status_t status; + unsigned char buf[100]; + unsigned char *end_buf; + + cff_index_init (&index); + status = cff_index_read (&index, &ptr, font->data_end); + if (unlikely (status)) + goto fail; + + font->num_fontdicts = _cairo_array_num_elements (&index); + + font->fd_dict = calloc (sizeof (cairo_hash_table_t *), font->num_fontdicts); + if (unlikely (font->fd_dict == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + font->fd_private_dict = calloc (sizeof (cairo_hash_table_t *), font->num_fontdicts); + if (unlikely (font->fd_private_dict == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + font->fd_local_sub_index = calloc (sizeof (cairo_array_t), font->num_fontdicts); + if (unlikely (font->fd_local_sub_index == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + font->fd_local_sub_bias = calloc (sizeof (int), font->num_fontdicts); + if (unlikely (font->fd_local_sub_bias == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + font->fd_local_subs_used = calloc (sizeof (cairo_bool_t *), font->num_fontdicts); + if (unlikely (font->fd_local_subs_used == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + font->fd_default_width = calloc (font->num_fontdicts, sizeof (double)); + if (unlikely (font->fd_default_width == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + font->fd_nominal_width = calloc (font->num_fontdicts, sizeof (double)); + if (unlikely (font->fd_nominal_width == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + + for (i = 0; i < font->num_fontdicts; i++) { + status = cff_dict_init (&font->fd_dict[i]); + if (unlikely (status)) + goto fail; + + element = _cairo_array_index (&index, i); + status = cff_dict_read (font->fd_dict[i], element->data, element->length); + if (unlikely (status)) + goto fail; + + operand = cff_dict_get_operands (font->fd_dict[i], PRIVATE_OP, &size); + if (operand == NULL) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto fail; + } + operand = decode_integer (operand, &size); + decode_integer (operand, &offset); + status = cff_dict_init (&font->fd_private_dict[i]); + if (unlikely (status)) + goto fail; + + cff_index_init (&font->fd_local_sub_index[i]); + status = cairo_cff_font_read_private_dict (font, + font->fd_private_dict[i], + &font->fd_local_sub_index[i], + &font->fd_local_sub_bias[i], + &font->fd_local_subs_used[i], + &font->fd_default_width[i], + &font->fd_nominal_width[i], + font->data + offset, + size); + if (unlikely (status)) + goto fail; + + /* Set integer operand to max value to use max size encoding to reserve + * space for any value later */ + end_buf = encode_integer_max (buf, 0); + end_buf = encode_integer_max (end_buf, 0); + status = cff_dict_set_operands (font->fd_dict[i], PRIVATE_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + } + + return CAIRO_STATUS_SUCCESS; + +fail: + cff_index_fini (&index); + + return status; +} + +static void +cairo_cff_font_read_font_metrics (cairo_cff_font_t *font, cairo_hash_table_t *top_dict) +{ + unsigned char *p; + unsigned char *end; + int size; + double x_min, y_min, x_max, y_max; + double xx, yx, xy, yy; + + x_min = 0.0; + y_min = 0.0; + x_max = 0.0; + y_max = 0.0; + p = cff_dict_get_operands (font->top_dict, FONTBBOX_OP, &size); + if (p) { + end = p + size; + if (p < end) + p = decode_number (p, &x_min); + if (p < end) + p = decode_number (p, &y_min); + if (p < end) + p = decode_number (p, &x_max); + if (p < end) + p = decode_number (p, &y_max); + } + font->x_min = floor (x_min); + font->y_min = floor (y_min); + font->x_max = floor (x_max); + font->y_max = floor (y_max); + font->ascent = font->y_max; + font->descent = font->y_min; + + xx = 0.001; + yx = 0.0; + xy = 0.0; + yy = 0.001; + p = cff_dict_get_operands (font->top_dict, FONTMATRIX_OP, &size); + if (p) { + end = p + size; + if (p < end) + p = decode_number (p, &xx); + if (p < end) + p = decode_number (p, &yx); + if (p < end) + p = decode_number (p, &xy); + if (p < end) + p = decode_number (p, &yy); + } + /* Freetype uses 1/abs(yy) to get units per EM */ + font->units_per_em = _cairo_round(1.0/fabs(yy)); +} + +static cairo_int_status_t +cairo_cff_font_read_top_dict (cairo_cff_font_t *font) +{ + cairo_array_t index; + cff_index_element_t *element; + unsigned char buf[20]; + unsigned char *end_buf; + unsigned char *operand; + cairo_int_status_t status; + unsigned char *p; + int size; + int offset; + + cff_index_init (&index); + status = cff_index_read (&index, &font->current_ptr, font->data_end); + if (unlikely (status)) + goto fail; + + element = _cairo_array_index (&index, 0); + status = cff_dict_read (font->top_dict, element->data, element->length); + if (unlikely (status)) + goto fail; + + if (cff_dict_get_operands (font->top_dict, ROS_OP, &size) != NULL) + font->is_cid = TRUE; + else + font->is_cid = FALSE; + + operand = cff_dict_get_operands (font->top_dict, CHARSTRINGS_OP, &size); + decode_integer (operand, &offset); + p = font->data + offset; + status = cff_index_read (&font->charstrings_index, &p, font->data_end); + if (unlikely (status)) + goto fail; + font->num_glyphs = _cairo_array_num_elements (&font->charstrings_index); + + if (font->is_cid) { + operand = cff_dict_get_operands (font->top_dict, CHARSET_OP, &size); + if (!operand) + return CAIRO_INT_STATUS_UNSUPPORTED; + + decode_integer (operand, &offset); + font->charset = font->data + offset; + if (font->charset >= font->data_end) + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (!font->is_opentype) + cairo_cff_font_read_font_metrics (font, font->top_dict); + + if (font->is_cid) { + operand = cff_dict_get_operands (font->top_dict, FDSELECT_OP, &size); + decode_integer (operand, &offset); + status = cairo_cff_font_read_fdselect (font, font->data + offset); + if (unlikely (status)) + goto fail; + + operand = cff_dict_get_operands (font->top_dict, FDARRAY_OP, &size); + decode_integer (operand, &offset); + status = cairo_cff_font_read_cid_fontdict (font, font->data + offset); + if (unlikely (status)) + goto fail; + } else { + operand = cff_dict_get_operands (font->top_dict, PRIVATE_OP, &size); + operand = decode_integer (operand, &size); + decode_integer (operand, &offset); + status = cairo_cff_font_read_private_dict (font, + font->private_dict, + &font->local_sub_index, + &font->local_sub_bias, + &font->local_subs_used, + &font->default_width, + &font->nominal_width, + font->data + offset, + size); + if (unlikely (status)) + goto fail; + } + + /* Use maximum sized encoding to reserve space for later modification. */ + end_buf = encode_integer_max (buf, 0); + status = cff_dict_set_operands (font->top_dict, + CHARSTRINGS_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + + status = cff_dict_set_operands (font->top_dict, + CHARSET_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + + if (font->scaled_font_subset->is_latin) { + status = cff_dict_set_operands (font->top_dict, + ENCODING_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + + /* Private has two operands - size and offset */ + end_buf = encode_integer_max (end_buf, 0); + cff_dict_set_operands (font->top_dict, PRIVATE_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + + } else { + status = cff_dict_set_operands (font->top_dict, + FDSELECT_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + + status = cff_dict_set_operands (font->top_dict, + FDARRAY_OP, buf, end_buf - buf); + if (unlikely (status)) + goto fail; + + cff_dict_remove (font->top_dict, ENCODING_OP); + cff_dict_remove (font->top_dict, PRIVATE_OP); + } + + /* Remove the unique identifier operators as the subsetted font is + * not the same is the original font. */ + cff_dict_remove (font->top_dict, UNIQUEID_OP); + cff_dict_remove (font->top_dict, XUID_OP); + +fail: + cff_index_fini (&index); + + return status; +} + +static cairo_int_status_t +cairo_cff_font_read_strings (cairo_cff_font_t *font) +{ + return cff_index_read (&font->strings_index, &font->current_ptr, font->data_end); +} + +static cairo_int_status_t +cairo_cff_font_read_global_subroutines (cairo_cff_font_t *font) +{ + cairo_int_status_t status; + int num_subs; + + status = cff_index_read (&font->global_sub_index, &font->current_ptr, font->data_end); + if (unlikely (status)) + return status; + + num_subs = _cairo_array_num_elements (&font->global_sub_index); + font->global_subs_used = calloc (num_subs, sizeof(cairo_bool_t)); + if (unlikely (font->global_subs_used == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (num_subs < 1240) + font->global_sub_bias = 107; + else if (num_subs < 33900) + font->global_sub_bias = 1131; + else + font->global_sub_bias = 32768; + + return CAIRO_STATUS_SUCCESS; +} + +typedef cairo_int_status_t +(*font_read_t) (cairo_cff_font_t *font); + +static const font_read_t font_read_funcs[] = { + cairo_cff_font_read_header, + cairo_cff_font_read_name, + cairo_cff_font_read_top_dict, + cairo_cff_font_read_strings, + cairo_cff_font_read_global_subroutines, +}; + +static cairo_int_status_t +cairo_cff_font_read_font (cairo_cff_font_t *font) +{ + cairo_int_status_t status; + unsigned int i; + + for (i = 0; i < ARRAY_LENGTH (font_read_funcs); i++) { + status = font_read_funcs[i] (font); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_set_ros_strings (cairo_cff_font_t *font) +{ + cairo_status_t status; + unsigned char buf[30]; + unsigned char *p; + int sid1, sid2; + const char *registry = "Adobe"; + const char *ordering = "Identity"; + + sid1 = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); + status = cff_index_append_copy (&font->strings_subset_index, + (unsigned char *)registry, + strlen(registry)); + if (unlikely (status)) + return status; + + sid2 = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); + status = cff_index_append_copy (&font->strings_subset_index, + (unsigned char *)ordering, + strlen(ordering)); + if (unlikely (status)) + return status; + + p = encode_integer (buf, sid1); + p = encode_integer (p, sid2); + p = encode_integer (p, 0); + status = cff_dict_set_operands (font->top_dict, ROS_OP, buf, p - buf); + if (unlikely (status)) + return status; + + p = encode_integer (buf, font->scaled_font_subset->num_glyphs); + status = cff_dict_set_operands (font->top_dict, CIDCOUNT_OP, buf, p - buf); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_subset_dict_string(cairo_cff_font_t *font, + cairo_hash_table_t *dict, + int operator) +{ + int size; + unsigned char *p; + int sid; + unsigned char buf[100]; + cff_index_element_t *element; + cairo_status_t status; + + p = cff_dict_get_operands (dict, operator, &size); + if (!p) + return CAIRO_STATUS_SUCCESS; + + decode_integer (p, &sid); + if (sid < NUM_STD_STRINGS) + return CAIRO_STATUS_SUCCESS; + + element = _cairo_array_index (&font->strings_index, sid - NUM_STD_STRINGS); + sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); + status = cff_index_append (&font->strings_subset_index, element->data, element->length); + if (unlikely (status)) + return status; + + p = encode_integer (buf, sid); + status = cff_dict_set_operands (dict, operator, buf, p - buf); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static const int dict_strings[] = { + VERSION_OP, + NOTICE_OP, + COPYRIGHT_OP, + FULLNAME_OP, + FAMILYNAME_OP, + WEIGHT_OP, + POSTSCRIPT_OP, + BASEFONTNAME_OP, + FONTNAME_OP, +}; + +static cairo_status_t +cairo_cff_font_subset_dict_strings (cairo_cff_font_t *font, + cairo_hash_table_t *dict) +{ + cairo_status_t status; + unsigned int i; + + for (i = 0; i < ARRAY_LENGTH (dict_strings); i++) { + status = cairo_cff_font_subset_dict_string (font, dict, dict_strings[i]); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static unsigned char * +type2_decode_integer (unsigned char *p, int *integer) +{ + if (*p == 28) { + *integer = p[1] << 8 | p[2]; + p += 3; + } else if (*p <= 246) { + *integer = *p++ - 139; + } else if (*p <= 250) { + *integer = (p[0] - 247) * 256 + p[1] + 108; + p += 2; + } else if (*p <= 254) { + *integer = -(p[0] - 251) * 256 - p[1] - 108; + p += 2; + } else { /* *p == 255 */ + /* 16.16 fixed-point number. The fraction is ignored. */ + *integer = (int16_t)((p[1] << 8) | p[2]); + p += 5; + } + return p; +} + +/* Type 2 charstring parser for finding calls to local or global + * subroutines. For non Opentype CFF fonts it also gets the glyph + * widths. + * + * When we find a subroutine operator, the subroutine is marked as in + * use and recursively followed. The subroutine number is the value on + * the top of the stack when the subroutine operator is executed. In + * most fonts the subroutine number is encoded in an integer + * immediately preceding the subroutine operator. However it is + * possible for the subroutine number on the stack to be the result of + * a computation (in which case there will be an operator preceding + * the subroutine operator). If this occurs, subroutine subsetting is + * disabled since we can't easily determine which subroutines are + * used. + * + * The width, if present, is the first integer in the charstring. The + * only way to confirm if the integer at the start of the charstring is + * the width is when the first stack clearing operator is parsed, + * check if there is an extra integer left over on the stack. + * + * When the first stack clearing operator is encountered + * type2_find_width is set to FALSE and type2_found_width is set to + * TRUE if an extra argument is found, otherwise FALSE. + */ +static cairo_status_t +cairo_cff_parse_charstring (cairo_cff_font_t *font, + unsigned char *charstring, int length, + int glyph_id, + cairo_bool_t need_width) +{ + unsigned char *p = charstring; + unsigned char *end = charstring + length; + int integer; + int hint_bytes; + int sub_num; + cff_index_element_t *element; + int fd; + + while (p < end) { + if (*p == 28 || *p >= 32) { + /* Integer value */ + p = type2_decode_integer (p, &integer); + font->type2_stack_size++; + font->type2_stack_top_value = integer; + font->type2_stack_top_is_int = TRUE; + if (!font->type2_seen_first_int) { + font->type2_width = integer; + font->type2_seen_first_int = TRUE; + } + } else if (*p == TYPE2_hstem || *p == TYPE2_vstem || + *p == TYPE2_hstemhm || *p == TYPE2_vstemhm) { + /* Hint operator. The number of hints declared by the + * operator depends on the size of the stack. */ + font->type2_stack_top_is_int = FALSE; + font->type2_num_hints += font->type2_stack_size/2; + if (font->type2_find_width && font->type2_stack_size % 2) + font->type2_found_width = TRUE; + + font->type2_stack_size = 0; + font->type2_find_width = FALSE; + p++; + } else if (*p == TYPE2_hintmask || *p == TYPE2_cntrmask) { + /* Hintmask operator. These operators are followed by a + * variable length mask where the length depends on the + * number of hints declared. The first time this is called + * it is also an implicit vstem if there are arguments on + * the stack. */ + if (font->type2_hintmask_bytes == 0) { + font->type2_stack_top_is_int = FALSE; + font->type2_num_hints += font->type2_stack_size/2; + if (font->type2_find_width && font->type2_stack_size % 2) + font->type2_found_width = TRUE; + + font->type2_stack_size = 0; + font->type2_find_width = FALSE; + font->type2_hintmask_bytes = (font->type2_num_hints+7)/8; + } + + hint_bytes = font->type2_hintmask_bytes; + p++; + p += hint_bytes; + } else if (*p == TYPE2_rmoveto) { + if (font->type2_find_width && font->type2_stack_size > 2) + font->type2_found_width = TRUE; + + font->type2_stack_size = 0; + font->type2_find_width = FALSE; + font->type2_has_path = TRUE; + p++; + } else if (*p == TYPE2_hmoveto || *p == TYPE2_vmoveto) { + if (font->type2_find_width && font->type2_stack_size > 1) + font->type2_found_width = TRUE; + + font->type2_stack_size = 0; + font->type2_find_width = FALSE; + font->type2_has_path = TRUE; + p++; + } else if (*p == TYPE2_endchar) { + if (!font->type2_has_path && font->type2_stack_size > 3) + return CAIRO_INT_STATUS_UNSUPPORTED; /* seac (Ref Appendix C of Type 2 Charstring Format */ + + if (font->type2_find_width && font->type2_stack_size > 0) + font->type2_found_width = TRUE; + + return CAIRO_STATUS_SUCCESS; + } else if (*p == TYPE2_callsubr) { + /* call to local subroutine */ + if (! font->type2_stack_top_is_int) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (++font->type2_nesting_level > MAX_SUBROUTINE_NESTING) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p++; + font->type2_stack_top_is_int = FALSE; + font->type2_stack_size--; + if (font->type2_find_width && font->type2_stack_size == 0) + font->type2_seen_first_int = FALSE; + + if (font->is_cid) { + fd = font->fdselect[glyph_id]; + sub_num = font->type2_stack_top_value + font->fd_local_sub_bias[fd]; + element = _cairo_array_index (&font->fd_local_sub_index[fd], sub_num); + if (! font->fd_local_subs_used[fd][sub_num]) { + font->fd_local_subs_used[fd][sub_num] = TRUE; + cairo_cff_parse_charstring (font, element->data, element->length, glyph_id, need_width); + } + } else { + sub_num = font->type2_stack_top_value + font->local_sub_bias; + element = _cairo_array_index (&font->local_sub_index, sub_num); + if (! font->local_subs_used[sub_num] || + (need_width && !font->type2_found_width)) + { + font->local_subs_used[sub_num] = TRUE; + cairo_cff_parse_charstring (font, element->data, element->length, glyph_id, need_width); + } + } + font->type2_nesting_level--; + } else if (*p == TYPE2_callgsubr) { + /* call to global subroutine */ + if (! font->type2_stack_top_is_int) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (++font->type2_nesting_level > MAX_SUBROUTINE_NESTING) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p++; + font->type2_stack_size--; + font->type2_stack_top_is_int = FALSE; + if (font->type2_find_width && font->type2_stack_size == 0) + font->type2_seen_first_int = FALSE; + + sub_num = font->type2_stack_top_value + font->global_sub_bias; + element = _cairo_array_index (&font->global_sub_index, sub_num); + if (! font->global_subs_used[sub_num] || + (need_width && !font->type2_found_width)) + { + font->global_subs_used[sub_num] = TRUE; + cairo_cff_parse_charstring (font, element->data, element->length, glyph_id, need_width); + } + font->type2_nesting_level--; + } else if (*p == 12) { + /* 2 byte instruction */ + + /* All the 2 byte operators are either not valid before a + * stack clearing operator or they are one of the + * arithmetic, storage, or conditional operators. */ + if (need_width && font->type2_find_width) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p += 2; + font->type2_stack_top_is_int = FALSE; + } else { + /* 1 byte instruction */ + p++; + font->type2_stack_top_is_int = FALSE; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_find_width_and_subroutines_used (cairo_cff_font_t *font, + unsigned char *charstring, int length, + int glyph_id, int subset_id) +{ + cairo_status_t status; + int width; + int fd; + + font->type2_stack_size = 0; + font->type2_stack_top_value = 0;; + font->type2_stack_top_is_int = FALSE; + font->type2_num_hints = 0; + font->type2_hintmask_bytes = 0; + font->type2_nesting_level = 0; + font->type2_seen_first_int = FALSE; + font->type2_find_width = TRUE; + font->type2_found_width = FALSE; + font->type2_width = 0; + font->type2_has_path = FALSE; + + status = cairo_cff_parse_charstring (font, charstring, length, glyph_id, TRUE); + if (status) + return status; + + if (!font->is_opentype) { + if (font->is_cid) { + fd = font->fdselect[glyph_id]; + if (font->type2_found_width) + width = font->fd_nominal_width[fd] + font->type2_width; + else + width = font->fd_default_width[fd]; + } else { + if (font->type2_found_width) + width = font->nominal_width + font->type2_width; + else + width = font->default_width; + } + font->widths[subset_id] = width; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_cff_font_get_gid_for_cid (cairo_cff_font_t *font, unsigned long cid, unsigned long *gid) +{ + unsigned char *p; + unsigned long first_gid; + unsigned long first_cid; + int num_left; + unsigned long c, g; + + if (cid == 0) { + *gid = 0; + return CAIRO_STATUS_SUCCESS; + } + + switch (font->charset[0]) { + /* Format 0 */ + case 0: + p = font->charset + 1; + g = 1; + while (g <= (unsigned)font->num_glyphs && p < font->data_end) { + c = get_unaligned_be16 (p); + if (c == cid) { + *gid = g; + return CAIRO_STATUS_SUCCESS; + } + g++; + p += 2; + } + break; + + /* Format 1 */ + case 1: + first_gid = 1; + p = font->charset + 1; + while (first_gid <= (unsigned)font->num_glyphs && p + 2 < font->data_end) { + first_cid = get_unaligned_be16 (p); + num_left = p[2]; + if (cid >= first_cid && cid <= first_cid + num_left) { + *gid = first_gid + cid - first_cid; + return CAIRO_STATUS_SUCCESS; + } + first_gid += num_left + 1; + p += 3; + } + break; + + /* Format 2 */ + case 2: + first_gid = 1; + p = font->charset + 1; + while (first_gid <= (unsigned)font->num_glyphs && p + 3 < font->data_end) { + first_cid = get_unaligned_be16 (p); + num_left = get_unaligned_be16 (p+2); + if (cid >= first_cid && cid <= first_cid + num_left) { + *gid = first_gid + cid - first_cid; + return CAIRO_STATUS_SUCCESS; + } + first_gid += num_left + 1; + p += 4; + } + break; + + default: + break; + } + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_int_status_t +cairo_cff_font_subset_charstrings_and_subroutines (cairo_cff_font_t *font) +{ + cff_index_element_t *element; + unsigned int i; + cairo_int_status_t status; + unsigned long glyph, cid; + + font->subset_subroutines = TRUE; + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + if (font->is_cid) { + cid = font->scaled_font_subset->glyphs[i]; + status = cairo_cff_font_get_gid_for_cid (font, cid, &glyph); + if (unlikely (status)) + return status; + } else { + glyph = font->scaled_font_subset->glyphs[i]; + } + element = _cairo_array_index (&font->charstrings_index, glyph); + status = cff_index_append (&font->charstrings_subset_index, + element->data, + element->length); + if (unlikely (status)) + return status; + + if (font->subset_subroutines) { + status = cairo_cff_find_width_and_subroutines_used (font, + element->data, element->length, + glyph, i); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + /* If parsing the charstrings fails we embed all the + * subroutines. But if the font is not opentype we + * need to successfully parse all charstrings to get + * the widths. */ + font->subset_subroutines = FALSE; + if (!font->is_opentype) + return status; + } else if (unlikely (status)) { + return status; + } + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_subset_fontdict (cairo_cff_font_t *font) +{ + unsigned int i; + int fd; + int *reverse_map; + unsigned long cid, gid; + cairo_int_status_t status; + + font->fdselect_subset = calloc (font->scaled_font_subset->num_glyphs, + sizeof (int)); + if (unlikely (font->fdselect_subset == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->fd_subset_map = calloc (font->num_fontdicts, sizeof (int)); + if (unlikely (font->fd_subset_map == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->private_dict_offset = calloc (font->num_fontdicts, sizeof (int)); + if (unlikely (font->private_dict_offset == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + reverse_map = calloc (font->num_fontdicts, sizeof (int)); + if (unlikely (reverse_map == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + for (i = 0; i < font->num_fontdicts; i++) + reverse_map[i] = -1; + + font->num_subset_fontdicts = 0; + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + cid = font->scaled_font_subset->glyphs[i]; + status = cairo_cff_font_get_gid_for_cid (font, cid, &gid); + if (unlikely (status)) { + free (reverse_map); + return status; + } + + fd = font->fdselect[gid]; + if (reverse_map[fd] < 0) { + font->fd_subset_map[font->num_subset_fontdicts] = fd; + reverse_map[fd] = font->num_subset_fontdicts++; + } + font->fdselect_subset[i] = reverse_map[fd]; + } + + free (reverse_map); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_create_cid_fontdict (cairo_cff_font_t *font) +{ + unsigned char buf[100]; + unsigned char *end_buf; + cairo_status_t status; + + font->num_fontdicts = 1; + font->fd_dict = malloc (sizeof (cairo_hash_table_t *)); + if (unlikely (font->fd_dict == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (cff_dict_init (&font->fd_dict[0])) { + free (font->fd_dict); + font->fd_dict = NULL; + font->num_fontdicts = 0; + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + font->fd_subset_map = malloc (sizeof (int)); + if (unlikely (font->fd_subset_map == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->private_dict_offset = malloc (sizeof (int)); + if (unlikely (font->private_dict_offset == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->fd_subset_map[0] = 0; + font->num_subset_fontdicts = 1; + + /* Set integer operand to max value to use max size encoding to reserve + * space for any value later */ + end_buf = encode_integer_max (buf, 0); + end_buf = encode_integer_max (end_buf, 0); + status = cff_dict_set_operands (font->fd_dict[0], PRIVATE_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_subset_strings (cairo_cff_font_t *font) +{ + cairo_status_t status; + unsigned int i; + + status = cairo_cff_font_subset_dict_strings (font, font->top_dict); + if (unlikely (status)) + return status; + + if (font->is_cid) { + for (i = 0; i < font->num_subset_fontdicts; i++) { + status = cairo_cff_font_subset_dict_strings (font, font->fd_dict[font->fd_subset_map[i]]); + if (unlikely (status)) + return status; + + status = cairo_cff_font_subset_dict_strings (font, font->fd_private_dict[font->fd_subset_map[i]]); + if (unlikely (status)) + return status; + } + } else { + status = cairo_cff_font_subset_dict_strings (font, font->private_dict); + } + + return status; +} + +/* The Euro is the only the only character in the winansi encoding + * with a glyph name that is not a CFF standard string. As the strings + * are written before the charset, we need to check during the + * subsetting phase if the Euro glyph is required and add the + * glyphname to the list of strings to write out. + */ +static cairo_status_t +cairo_cff_font_add_euro_charset_string (cairo_cff_font_t *font) +{ + cairo_status_t status; + unsigned int i; + int ch; + const char *euro = "Euro"; + + for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { + ch = font->scaled_font_subset->to_latin_char[i]; + if (ch == 128) { + font->euro_sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); + status = cff_index_append_copy (&font->strings_subset_index, + (unsigned char *)euro, strlen(euro)); + return status; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_subset_font (cairo_cff_font_t *font) +{ + cairo_status_t status; + + if (!font->scaled_font_subset->is_latin) { + status = cairo_cff_font_set_ros_strings (font); + if (unlikely (status)) + return status; + } + + status = cairo_cff_font_subset_charstrings_and_subroutines (font); + if (unlikely (status)) + return status; + + if (!font->scaled_font_subset->is_latin) { + if (font->is_cid) + status = cairo_cff_font_subset_fontdict (font); + else + status = cairo_cff_font_create_cid_fontdict (font); + if (unlikely (status)) + return status; + } else { + font->private_dict_offset = malloc (sizeof (int)); + if (unlikely (font->private_dict_offset == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + status = cairo_cff_font_subset_strings (font); + if (unlikely (status)) + return status; + + if (font->scaled_font_subset->is_latin) + status = cairo_cff_font_add_euro_charset_string (font); + + return status; +} + +/* Set the operand of the specified operator in the (already written) + * top dict to point to the current position in the output + * array. Operands updated with this function must have previously + * been encoded with the 5-byte (max) integer encoding. */ +static void +cairo_cff_font_set_topdict_operator_to_cur_pos (cairo_cff_font_t *font, + int operator) +{ + int cur_pos; + int offset; + int size; + unsigned char buf[10]; + unsigned char *buf_end; + unsigned char *op_ptr; + + cur_pos = _cairo_array_num_elements (&font->output); + buf_end = encode_integer_max (buf, cur_pos); + offset = cff_dict_get_location (font->top_dict, operator, &size); + assert (offset > 0); + op_ptr = _cairo_array_index (&font->output, offset); + memcpy (op_ptr, buf, buf_end - buf); +} + +static cairo_status_t +cairo_cff_font_write_header (cairo_cff_font_t *font) +{ + return _cairo_array_append_multiple (&font->output, + font->header, + font->header->header_size); +} + +static cairo_status_t +cairo_cff_font_write_name (cairo_cff_font_t *font) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_array_t index; + + cff_index_init (&index); + + status = cff_index_append_copy (&index, + (unsigned char *) font->ps_name, + strlen(font->ps_name)); + if (unlikely (status)) + goto FAIL; + + status = cff_index_write (&index, &font->output); + if (unlikely (status)) + goto FAIL; + +FAIL: + cff_index_fini (&index); + + return status; +} + +static cairo_status_t +cairo_cff_font_write_top_dict (cairo_cff_font_t *font) +{ + uint16_t count; + unsigned char buf[10]; + unsigned char *p; + int offset_index; + int dict_start, dict_size; + int offset_size = 4; + cairo_status_t status; + + /* Write an index containing the top dict */ + + count = cpu_to_be16 (1); + status = _cairo_array_append_multiple (&font->output, &count, 2); + if (unlikely (status)) + return status; + buf[0] = offset_size; + status = _cairo_array_append (&font->output, buf); + if (unlikely (status)) + return status; + encode_index_offset (buf, offset_size, 1); + status = _cairo_array_append_multiple (&font->output, buf, offset_size); + if (unlikely (status)) + return status; + + /* Reserve space for last element of offset array and update after + * dict is written */ + offset_index = _cairo_array_num_elements (&font->output); + status = _cairo_array_append_multiple (&font->output, buf, offset_size); + if (unlikely (status)) + return status; + + dict_start = _cairo_array_num_elements (&font->output); + status = cff_dict_write (font->top_dict, &font->output); + if (unlikely (status)) + return status; + dict_size = _cairo_array_num_elements (&font->output) - dict_start; + + encode_index_offset (buf, offset_size, dict_size + 1); + p = _cairo_array_index (&font->output, offset_index); + memcpy (p, buf, offset_size); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_strings (cairo_cff_font_t *font) +{ + return cff_index_write (&font->strings_subset_index, &font->output); +} + +static cairo_status_t +cairo_cff_font_write_global_subrs (cairo_cff_font_t *font) +{ + unsigned int i; + unsigned char return_op = TYPE2_return; + + /* poppler and fontforge don't like zero length subroutines so we + * replace unused subroutines with a 'return' instruction. */ + if (font->subset_subroutines) { + for (i = 0; i < _cairo_array_num_elements (&font->global_sub_index); i++) { + if (! font->global_subs_used[i]) + cff_index_set_object (&font->global_sub_index, i, &return_op, 1); + } + } + + return cff_index_write (&font->global_sub_index, &font->output); +} + +static cairo_status_t +cairo_cff_font_write_encoding (cairo_cff_font_t *font) +{ + unsigned char buf[2]; + cairo_status_t status; + unsigned int i; + + cairo_cff_font_set_topdict_operator_to_cur_pos (font, ENCODING_OP); + buf[0] = 0; /* Format 0 */ + buf[1] = font->scaled_font_subset->num_glyphs - 1; + status = _cairo_array_append_multiple (&font->output, buf, 2); + if (unlikely (status)) + return status; + + for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { + unsigned char ch = font->scaled_font_subset->to_latin_char[i]; + status = _cairo_array_append (&font->output, &ch); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_fdselect (cairo_cff_font_t *font) +{ + unsigned char data; + unsigned int i; + cairo_int_status_t status; + + cairo_cff_font_set_topdict_operator_to_cur_pos (font, FDSELECT_OP); + + if (font->is_cid) { + data = 0; + status = _cairo_array_append (&font->output, &data); + if (unlikely (status)) + return status; + + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + data = font->fdselect_subset[i]; + status = _cairo_array_append (&font->output, &data); + if (unlikely (status)) + return status; + } + } else { + unsigned char byte; + uint16_t word; + + status = _cairo_array_grow_by (&font->output, 9); + if (unlikely (status)) + return status; + + byte = 3; + status = _cairo_array_append (&font->output, &byte); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + word = cpu_to_be16 (1); + status = _cairo_array_append_multiple (&font->output, &word, 2); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + word = cpu_to_be16 (0); + status = _cairo_array_append_multiple (&font->output, &word, 2); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + byte = 0; + status = _cairo_array_append (&font->output, &byte); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + word = cpu_to_be16 (font->scaled_font_subset->num_glyphs); + status = _cairo_array_append_multiple (&font->output, &word, 2); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + return CAIRO_STATUS_SUCCESS; +} + +/* Winansi to CFF standard strings mapping for characters 128 to 255 */ +static const int winansi_to_cff_std_string[] = { + /* 128 */ + 0, 0, 117, 101, 118, 121, 112, 113, + 126, 122, 192, 107, 142, 0, 199, 0, + /* 144 */ + 0, 65, 8, 105, 119, 116, 111, 137, + 127, 153, 221, 108, 148, 0, 228, 198, + /* 160 */ + 0, 96, 97, 98, 103, 100, 160, 102, + 131, 170, 139, 106, 151, 0, 165, 128, + /* 176 */ + 161, 156, 164, 169, 125, 152, 115, 114, + 133, 150, 143, 120, 158, 155, 163, 123, + /* 192 */ + 174, 171, 172, 176, 173, 175, 138, 177, + 181, 178, 179, 180, 185, 182, 183, 184, + /* 208 */ + 154, 186, 190, 187, 188, 191, 189, 168, + 141, 196, 193, 194, 195, 197, 157, 149, + /* 224 */ + 203, 200, 201, 205, 202, 204, 144, 206, + 210, 207, 208, 209, 214, 211, 212, 213, + /* 240 */ + 167, 215, 219, 216, 217, 220, 218, 159, + 147, 225, 222, 223, 224, 226, 162, 227, +}; + +static int +cairo_cff_font_get_sid_for_winansi_char (cairo_cff_font_t *font, int ch) +{ + int sid; + + if (ch == 39) { + sid = 104; + + } else if (ch == 96) { + sid = 124; + + } else if (ch >= 32 && ch <= 126) { + sid = ch - 31; + + } else if (ch == 128) { + assert (font->euro_sid >= NUM_STD_STRINGS); + sid = font->euro_sid; + + } else if (ch >= 128 && ch <= 255) { + sid = winansi_to_cff_std_string[ch - 128]; + + } else { + sid = 0; + } + + return sid; +} + +static cairo_status_t +cairo_cff_font_write_type1_charset (cairo_cff_font_t *font) +{ + unsigned char format = 0; + unsigned int i; + int ch, sid; + cairo_status_t status; + uint16_t sid_be16; + + cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSET_OP); + status = _cairo_array_append (&font->output, &format); + if (unlikely (status)) + return status; + + for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { + ch = font->scaled_font_subset->to_latin_char[i]; + sid = cairo_cff_font_get_sid_for_winansi_char (font, ch); + if (unlikely (status)) + return status; + + sid_be16 = cpu_to_be16(sid); + status = _cairo_array_append_multiple (&font->output, &sid_be16, sizeof(sid_be16)); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_cid_charset (cairo_cff_font_t *font) +{ + unsigned char byte; + uint16_t word; + cairo_status_t status; + + cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSET_OP); + status = _cairo_array_grow_by (&font->output, 5); + if (unlikely (status)) + return status; + + byte = 2; + status = _cairo_array_append (&font->output, &byte); + assert (status == CAIRO_STATUS_SUCCESS); + + word = cpu_to_be16 (1); + status = _cairo_array_append_multiple (&font->output, &word, 2); + assert (status == CAIRO_STATUS_SUCCESS); + + word = cpu_to_be16 (font->scaled_font_subset->num_glyphs - 2); + status = _cairo_array_append_multiple (&font->output, &word, 2); + assert (status == CAIRO_STATUS_SUCCESS); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_charstrings (cairo_cff_font_t *font) +{ + cairo_cff_font_set_topdict_operator_to_cur_pos (font, CHARSTRINGS_OP); + + return cff_index_write (&font->charstrings_subset_index, &font->output); +} + +static cairo_status_t +cairo_cff_font_write_cid_fontdict (cairo_cff_font_t *font) +{ + unsigned int i; + cairo_int_status_t status; + unsigned int offset_array; + unsigned char *offset_array_ptr; + int offset_base; + uint16_t count; + uint8_t offset_size = 4; + + cairo_cff_font_set_topdict_operator_to_cur_pos (font, FDARRAY_OP); + count = cpu_to_be16 (font->num_subset_fontdicts); + status = _cairo_array_append_multiple (&font->output, &count, sizeof (uint16_t)); + if (unlikely (status)) + return status; + status = _cairo_array_append (&font->output, &offset_size); + if (unlikely (status)) + return status; + + offset_array = _cairo_array_num_elements (&font->output); + status = _cairo_array_allocate (&font->output, + (font->num_subset_fontdicts + 1)*offset_size, + (void **) &offset_array_ptr); + if (unlikely (status)) + return status; + offset_base = _cairo_array_num_elements (&font->output) - 1; + put_unaligned_be32(1, offset_array_ptr); + offset_array += sizeof(uint32_t); + for (i = 0; i < font->num_subset_fontdicts; i++) { + status = cff_dict_write (font->fd_dict[font->fd_subset_map[i]], + &font->output); + if (unlikely (status)) + return status; + + offset_array_ptr = _cairo_array_index (&font->output, offset_array); + put_unaligned_be32 (_cairo_array_num_elements (&font->output) - offset_base, + offset_array_ptr); + offset_array += sizeof(uint32_t); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_private_dict (cairo_cff_font_t *font, + int dict_num, + cairo_hash_table_t *parent_dict, + cairo_hash_table_t *private_dict) +{ + int offset; + int size; + unsigned char buf[10]; + unsigned char *buf_end; + unsigned char *p; + cairo_status_t status; + + /* Write private dict and update offset and size in top dict */ + font->private_dict_offset[dict_num] = _cairo_array_num_elements (&font->output); + status = cff_dict_write (private_dict, &font->output); + if (unlikely (status)) + return status; + + size = _cairo_array_num_elements (&font->output) - font->private_dict_offset[dict_num]; + /* private entry has two operands - size and offset */ + buf_end = encode_integer_max (buf, size); + buf_end = encode_integer_max (buf_end, font->private_dict_offset[dict_num]); + offset = cff_dict_get_location (parent_dict, PRIVATE_OP, &size); + assert (offset > 0); + p = _cairo_array_index (&font->output, offset); + memcpy (p, buf, buf_end - buf); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_local_sub (cairo_cff_font_t *font, + int dict_num, + cairo_hash_table_t *private_dict, + cairo_array_t *local_sub_index, + cairo_bool_t *local_subs_used) +{ + int offset; + int size; + unsigned char buf[10]; + unsigned char *buf_end; + unsigned char *p; + cairo_status_t status; + unsigned int i; + unsigned char return_op = TYPE2_return; + + if (_cairo_array_num_elements (local_sub_index) > 0) { + /* Write local subroutines and update offset in private + * dict. Local subroutines offset is relative to start of + * private dict */ + offset = _cairo_array_num_elements (&font->output) - font->private_dict_offset[dict_num]; + buf_end = encode_integer_max (buf, offset); + offset = cff_dict_get_location (private_dict, LOCAL_SUB_OP, &size); + assert (offset > 0); + p = _cairo_array_index (&font->output, offset); + memcpy (p, buf, buf_end - buf); + + /* poppler and fontforge don't like zero length subroutines so + * we replace unused subroutines with a 'return' instruction. + */ + if (font->subset_subroutines) { + for (i = 0; i < _cairo_array_num_elements (local_sub_index); i++) { + if (! local_subs_used[i]) + cff_index_set_object (local_sub_index, i, &return_op, 1); + } + } + status = cff_index_write (local_sub_index, &font->output); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + + +static cairo_status_t +cairo_cff_font_write_cid_private_dict_and_local_sub (cairo_cff_font_t *font) +{ + unsigned int i; + cairo_int_status_t status; + + if (font->is_cid) { + for (i = 0; i < font->num_subset_fontdicts; i++) { + status = cairo_cff_font_write_private_dict ( + font, + i, + font->fd_dict[font->fd_subset_map[i]], + font->fd_private_dict[font->fd_subset_map[i]]); + if (unlikely (status)) + return status; + } + + for (i = 0; i < font->num_subset_fontdicts; i++) { + status = cairo_cff_font_write_local_sub ( + font, + i, + font->fd_private_dict[font->fd_subset_map[i]], + &font->fd_local_sub_index[font->fd_subset_map[i]], + font->fd_local_subs_used[font->fd_subset_map[i]]); + if (unlikely (status)) + return status; + } + } else { + status = cairo_cff_font_write_private_dict (font, + 0, + font->fd_dict[0], + font->private_dict); + if (unlikely (status)) + return status; + + status = cairo_cff_font_write_local_sub (font, + 0, + font->private_dict, + &font->local_sub_index, + font->local_subs_used); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_cff_font_write_type1_private_dict_and_local_sub (cairo_cff_font_t *font) +{ + cairo_int_status_t status; + + status = cairo_cff_font_write_private_dict (font, + 0, + font->top_dict, + font->private_dict); + if (unlikely (status)) + return status; + + status = cairo_cff_font_write_local_sub (font, + 0, + font->private_dict, + &font->local_sub_index, + font->local_subs_used); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + + +typedef cairo_status_t +(*font_write_t) (cairo_cff_font_t *font); + +static const font_write_t font_write_cid_funcs[] = { + cairo_cff_font_write_header, + cairo_cff_font_write_name, + cairo_cff_font_write_top_dict, + cairo_cff_font_write_strings, + cairo_cff_font_write_global_subrs, + cairo_cff_font_write_cid_charset, + cairo_cff_font_write_fdselect, + cairo_cff_font_write_charstrings, + cairo_cff_font_write_cid_fontdict, + cairo_cff_font_write_cid_private_dict_and_local_sub, +}; + +static const font_write_t font_write_type1_funcs[] = { + cairo_cff_font_write_header, + cairo_cff_font_write_name, + cairo_cff_font_write_top_dict, + cairo_cff_font_write_strings, + cairo_cff_font_write_global_subrs, + cairo_cff_font_write_encoding, + cairo_cff_font_write_type1_charset, + cairo_cff_font_write_charstrings, + cairo_cff_font_write_type1_private_dict_and_local_sub, +}; + +static cairo_status_t +cairo_cff_font_write_subset (cairo_cff_font_t *font) +{ + cairo_int_status_t status; + unsigned int i; + + if (font->scaled_font_subset->is_latin) { + for (i = 0; i < ARRAY_LENGTH (font_write_type1_funcs); i++) { + status = font_write_type1_funcs[i] (font); + if (unlikely (status)) + return status; + } + } else { + for (i = 0; i < ARRAY_LENGTH (font_write_cid_funcs); i++) { + status = font_write_cid_funcs[i] (font); + if (unlikely (status)) + return status; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_cff_font_generate (cairo_cff_font_t *font, + const char **data, + unsigned long *length) +{ + cairo_int_status_t status; + + status = cairo_cff_font_read_font (font); + if (unlikely (status)) + return status; + + /* If the PS name is not found, create a CairoFont-x-y name. */ + if (font->ps_name == NULL) { + font->ps_name = malloc (30); + if (unlikely (font->ps_name == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + snprintf(font->ps_name, 30, "CairoFont-%u-%u", + font->scaled_font_subset->font_id, + font->scaled_font_subset->subset_id); + } + + status = cairo_cff_font_subset_font (font); + if (unlikely (status)) + return status; + + status = cairo_cff_font_write_subset (font); + if (unlikely (status)) + return status; + + + *data = _cairo_array_index (&font->output, 0); + *length = _cairo_array_num_elements (&font->output); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_cff_font_create_set_widths (cairo_cff_font_t *font) +{ + unsigned long size; + unsigned long long_entry_size; + unsigned long short_entry_size; + unsigned int i; + tt_hhea_t hhea; + int num_hmetrics; + uint16_t short_entry; + int glyph_index; + cairo_int_status_t status; + + size = sizeof (tt_hhea_t); + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hhea, 0, + (unsigned char*) &hhea, &size); + if (unlikely (status)) + return status; + num_hmetrics = be16_to_cpu (hhea.num_hmetrics); + + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + glyph_index = font->scaled_font_subset->glyphs[i]; + long_entry_size = 2 * sizeof (int16_t); + short_entry_size = sizeof (int16_t); + if (glyph_index < num_hmetrics) { + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hmtx, + glyph_index * long_entry_size, + (unsigned char *) &short_entry, + &short_entry_size); + if (unlikely (status)) + return status; + } + else + { + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hmtx, + (num_hmetrics - 1) * long_entry_size, + (unsigned char *) &short_entry, + &short_entry_size); + if (unlikely (status)) + return status; + } + font->widths[i] = be16_to_cpu (short_entry); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +check_fontdata_is_cff (const unsigned char *data, long length) +{ + cff_header_t *header; + + if (length < (long)sizeof (cff_header_t)) + return FALSE; + + header = (cff_header_t *) data; + if (header->major == 1 && + header->minor == 0 && + header->header_size == 4) + { + return TRUE; + } + + return FALSE; +} + +static cairo_int_status_t +_cairo_cff_font_load_opentype_cff (cairo_cff_font_t *font) +{ + const cairo_scaled_font_backend_t *backend = font->backend; + cairo_status_t status; + tt_head_t head; + tt_hhea_t hhea; + unsigned long size, data_length; + + if (!backend->load_truetype_table) + return CAIRO_INT_STATUS_UNSUPPORTED; + + data_length = 0; + status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_CFF, 0, NULL, &data_length); + if (status) + return status; + + size = sizeof (tt_head_t); + status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_head, 0, + (unsigned char *) &head, &size); + if (unlikely (status)) + return status; + + size = sizeof (tt_hhea_t); + status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hhea, 0, + (unsigned char *) &hhea, &size); + if (unlikely (status)) + return status; + + size = 0; + status = backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hmtx, 0, NULL, &size); + if (unlikely (status)) + return status; + + font->x_min = (int16_t) be16_to_cpu (head.x_min); + font->y_min = (int16_t) be16_to_cpu (head.y_min); + font->x_max = (int16_t) be16_to_cpu (head.x_max); + font->y_max = (int16_t) be16_to_cpu (head.y_max); + font->ascent = (int16_t) be16_to_cpu (hhea.ascender); + font->descent = (int16_t) be16_to_cpu (hhea.descender); + font->units_per_em = (int16_t) be16_to_cpu (head.units_per_em); + if (font->units_per_em == 0) + font->units_per_em = 1000; + + font->font_name = NULL; + status = _cairo_truetype_read_font_name (font->scaled_font_subset->scaled_font, + &font->ps_name, + &font->font_name); + if (_cairo_status_is_error (status)) + return status; + + font->is_opentype = TRUE; + font->data_length = data_length; + font->data = malloc (data_length); + if (unlikely (font->data == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_CFF, 0, font->data, + &font->data_length); + if (unlikely (status)) + return status; + + if (!check_fontdata_is_cff (font->data, data_length)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_cff_font_load_cff (cairo_cff_font_t *font) +{ + const cairo_scaled_font_backend_t *backend = font->backend; + cairo_status_t status; + unsigned long data_length; + + if (!backend->load_type1_data) + return CAIRO_INT_STATUS_UNSUPPORTED; + + data_length = 0; + status = backend->load_type1_data (font->scaled_font_subset->scaled_font, + 0, NULL, &data_length); + if (unlikely (status)) + return status; + + font->font_name = NULL; + font->is_opentype = FALSE; + font->data_length = data_length; + font->data = malloc (data_length); + if (unlikely (font->data == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = font->backend->load_type1_data (font->scaled_font_subset->scaled_font, + 0, font->data, &font->data_length); + if (unlikely (status)) + return status; + + if (!check_fontdata_is_cff (font->data, data_length)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_cff_font_create (cairo_scaled_font_subset_t *scaled_font_subset, + cairo_cff_font_t **font_return, + const char *subset_name) +{ + const cairo_scaled_font_backend_t *backend; + cairo_int_status_t status; + cairo_cff_font_t *font; + + backend = scaled_font_subset->scaled_font->backend; + + /* We need to use a fallback font generated from the synthesized outlines. */ + if (backend->is_synthetic && backend->is_synthetic (scaled_font_subset->scaled_font)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + font = calloc (1, sizeof (cairo_cff_font_t)); + if (unlikely (font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->backend = backend; + font->scaled_font_subset = scaled_font_subset; + + status = _cairo_cff_font_load_opentype_cff (font); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + status = _cairo_cff_font_load_cff (font); + if (status) + goto fail1; + + font->data_end = font->data + font->data_length; + _cairo_array_init (&font->output, sizeof (char)); + status = _cairo_array_grow_by (&font->output, 4096); + if (unlikely (status)) + goto fail2; + + font->subset_font_name = strdup (subset_name); + if (unlikely (font->subset_font_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + + font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int)); + if (unlikely (font->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + + if (font->is_opentype) { + status = cairo_cff_font_create_set_widths (font); + if (unlikely (status)) + goto fail4; + } + + status = cff_dict_init (&font->top_dict); + if (unlikely (status)) + goto fail4; + + status = cff_dict_init (&font->private_dict); + if (unlikely (status)) + goto fail5; + + cff_index_init (&font->strings_index); + cff_index_init (&font->charstrings_index); + cff_index_init (&font->global_sub_index); + cff_index_init (&font->local_sub_index); + cff_index_init (&font->charstrings_subset_index); + cff_index_init (&font->strings_subset_index); + font->euro_sid = 0; + font->fdselect = NULL; + font->fd_dict = NULL; + font->fd_private_dict = NULL; + font->fd_local_sub_index = NULL; + font->fd_local_sub_bias = NULL; + font->fdselect_subset = NULL; + font->fd_subset_map = NULL; + font->private_dict_offset = NULL; + font->global_subs_used = NULL; + font->local_subs_used = NULL; + font->fd_local_subs_used = NULL; + + *font_return = font; + + return CAIRO_STATUS_SUCCESS; + +fail5: + _cairo_hash_table_destroy (font->top_dict); +fail4: + free (font->widths); +fail3: + free (font->subset_font_name); +fail2: + free (font->ps_name); + _cairo_array_fini (&font->output); +fail1: + free (font->data); + free (font->font_name); + free (font); + + return status; +} + +static void +cairo_cff_font_destroy (cairo_cff_font_t *font) +{ + unsigned int i; + + free (font->widths); + free (font->font_name); + free (font->ps_name); + free (font->subset_font_name); + _cairo_array_fini (&font->output); + cff_dict_fini (font->top_dict); + cff_dict_fini (font->private_dict); + cff_index_fini (&font->strings_index); + cff_index_fini (&font->charstrings_index); + cff_index_fini (&font->global_sub_index); + cff_index_fini (&font->local_sub_index); + cff_index_fini (&font->charstrings_subset_index); + cff_index_fini (&font->strings_subset_index); + + /* If we bailed out early as a result of an error some of the + * following cairo_cff_font_t members may still be NULL */ + if (font->fd_dict) { + for (i = 0; i < font->num_fontdicts; i++) { + if (font->fd_dict[i]) + cff_dict_fini (font->fd_dict[i]); + } + free (font->fd_dict); + } + free (font->global_subs_used); + free (font->local_subs_used); + free (font->fd_subset_map); + free (font->private_dict_offset); + + if (font->is_cid) { + free (font->fdselect); + free (font->fdselect_subset); + if (font->fd_private_dict) { + for (i = 0; i < font->num_fontdicts; i++) { + if (font->fd_private_dict[i]) + cff_dict_fini (font->fd_private_dict[i]); + } + free (font->fd_private_dict); + } + if (font->fd_local_sub_index) { + for (i = 0; i < font->num_fontdicts; i++) + cff_index_fini (&font->fd_local_sub_index[i]); + free (font->fd_local_sub_index); + } + free (font->fd_local_sub_bias); + if (font->fd_local_subs_used) { + for (i = 0; i < font->num_fontdicts; i++) { + free (font->fd_local_subs_used[i]); + } + free (font->fd_local_subs_used); + } + free (font->fd_default_width); + free (font->fd_nominal_width); + } + + free (font->data); + + free (font); +} + +cairo_status_t +_cairo_cff_subset_init (cairo_cff_subset_t *cff_subset, + const char *subset_name, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_cff_font_t *font = NULL; /* squelch bogus compiler warning */ + cairo_status_t status; + const char *data = NULL; /* squelch bogus compiler warning */ + unsigned long length = 0; /* squelch bogus compiler warning */ + unsigned int i; + + status = _cairo_cff_font_create (font_subset, &font, subset_name); + if (unlikely (status)) + return status; + + status = cairo_cff_font_generate (font, &data, &length); + if (unlikely (status)) + goto fail1; + + cff_subset->ps_name = strdup (font->ps_name); + if (unlikely (cff_subset->ps_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + if (font->font_name) { + cff_subset->family_name_utf8 = strdup (font->font_name); + if (cff_subset->family_name_utf8 == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + } else { + cff_subset->family_name_utf8 = NULL; + } + + cff_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); + if (unlikely (cff_subset->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) + cff_subset->widths[i] = (double)font->widths[i]/font->units_per_em; + + cff_subset->x_min = (double)font->x_min/font->units_per_em; + cff_subset->y_min = (double)font->y_min/font->units_per_em; + cff_subset->x_max = (double)font->x_max/font->units_per_em; + cff_subset->y_max = (double)font->y_max/font->units_per_em; + cff_subset->ascent = (double)font->ascent/font->units_per_em; + cff_subset->descent = (double)font->descent/font->units_per_em; + + cff_subset->data = malloc (length); + if (unlikely (cff_subset->data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail4; + } + + memcpy (cff_subset->data, data, length); + cff_subset->data_length = length; + + cairo_cff_font_destroy (font); + + return CAIRO_STATUS_SUCCESS; + + fail4: + free (cff_subset->widths); + fail3: + free (cff_subset->family_name_utf8); + fail2: + free (cff_subset->ps_name); + fail1: + cairo_cff_font_destroy (font); + + return status; +} + +void +_cairo_cff_subset_fini (cairo_cff_subset_t *subset) +{ + free (subset->ps_name); + free (subset->family_name_utf8); + free (subset->widths); + free (subset->data); +} + +cairo_bool_t +_cairo_cff_scaled_font_is_cid_cff (cairo_scaled_font_t *scaled_font) +{ + const cairo_scaled_font_backend_t *backend; + cairo_int_status_t status; + unsigned char *data; + unsigned long data_length; + unsigned char *current_ptr; + unsigned char *data_end; + cff_header_t *header; + cff_index_element_t *element; + cairo_hash_table_t *top_dict; + cairo_array_t index; + int size; + cairo_bool_t is_cid = FALSE; + + backend = scaled_font->backend; + data = NULL; + data_length = 0; + status = CAIRO_INT_STATUS_UNSUPPORTED; + /* Try to load an OpenType/CFF font */ + if (backend->load_truetype_table && + (status = backend->load_truetype_table (scaled_font, TT_TAG_CFF, + 0, NULL, &data_length)) == CAIRO_INT_STATUS_SUCCESS) + { + data = malloc (data_length); + if (unlikely (data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + status = backend->load_truetype_table (scaled_font, TT_TAG_CFF, + 0, data, &data_length); + if (unlikely (status)) + goto fail1; + } + /* Try to load a CFF font */ + if (status == CAIRO_INT_STATUS_UNSUPPORTED && + backend->load_type1_data && + (status = backend->load_type1_data (scaled_font, + 0, NULL, &data_length)) == CAIRO_INT_STATUS_SUCCESS) + { + data = malloc (data_length); + if (unlikely (data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + status = backend->load_type1_data (scaled_font, 0, data, &data_length); + if (unlikely (status)) + goto fail1; + } + if (status) + goto fail1; + + /* Check if it looks like a CFF font */ + if (!check_fontdata_is_cff (data, data_length)) + goto fail1; + + data_end = data + data_length; + + /* skip header */ + if (data_length < sizeof (cff_header_t)) + goto fail1; + + header = (cff_header_t *) data; + current_ptr = data + header->header_size; + + /* skip name */ + cff_index_init (&index); + status = cff_index_read (&index, ¤t_ptr, data_end); + cff_index_fini (&index); + + if (status) + goto fail1; + + /* read top dict */ + cff_index_init (&index); + status = cff_index_read (&index, ¤t_ptr, data_end); + if (unlikely (status)) + goto fail2; + + status = cff_dict_init (&top_dict); + if (unlikely (status)) + goto fail2; + + element = _cairo_array_index (&index, 0); + status = cff_dict_read (top_dict, element->data, element->length); + if (unlikely (status)) + goto fail3; + + /* check for ROS operator indicating a CID font */ + if (cff_dict_get_operands (top_dict, ROS_OP, &size) != NULL) + is_cid = TRUE; + +fail3: + cff_dict_fini (top_dict); + +fail2: + cff_index_fini (&index); + +fail1: + free (data); + + return is_cid; +} + +static cairo_int_status_t +_cairo_cff_font_fallback_create (cairo_scaled_font_subset_t *scaled_font_subset, + cairo_cff_font_t **font_return, + const char *subset_name) +{ + cairo_status_t status; + cairo_cff_font_t *font; + + font = malloc (sizeof (cairo_cff_font_t)); + if (unlikely (font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->backend = NULL; + font->scaled_font_subset = scaled_font_subset; + + _cairo_array_init (&font->output, sizeof (char)); + status = _cairo_array_grow_by (&font->output, 4096); + if (unlikely (status)) + goto fail1; + + font->subset_font_name = strdup (subset_name); + if (unlikely (font->subset_font_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + font->ps_name = strdup (subset_name); + if (unlikely (font->ps_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + font->font_name = NULL; + + font->x_min = 0; + font->y_min = 0; + font->x_max = 0; + font->y_max = 0; + font->ascent = 0; + font->descent = 0; + + font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int)); + if (unlikely (font->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + + font->data_length = 0; + font->data = NULL; + font->data_end = NULL; + + status = cff_dict_init (&font->top_dict); + if (unlikely (status)) + goto fail4; + + status = cff_dict_init (&font->private_dict); + if (unlikely (status)) + goto fail5; + + cff_index_init (&font->strings_index); + cff_index_init (&font->charstrings_index); + cff_index_init (&font->global_sub_index); + cff_index_init (&font->local_sub_index); + cff_index_init (&font->charstrings_subset_index); + cff_index_init (&font->strings_subset_index); + font->global_subs_used = NULL; + font->local_subs_used = NULL; + font->subset_subroutines = FALSE; + font->fdselect = NULL; + font->fd_dict = NULL; + font->fd_private_dict = NULL; + font->fd_local_sub_index = NULL; + font->fdselect_subset = NULL; + font->fd_subset_map = NULL; + font->private_dict_offset = NULL; + + *font_return = font; + + return CAIRO_STATUS_SUCCESS; + +fail5: + _cairo_hash_table_destroy (font->top_dict); +fail4: + free (font->widths); +fail3: + free (font->font_name); + free (font->ps_name); +fail2: + free (font->subset_font_name); +fail1: + _cairo_array_fini (&font->output); + free (font); + return status; +} + +static cairo_int_status_t +cairo_cff_font_fallback_generate (cairo_cff_font_t *font, + cairo_type2_charstrings_t *type2_subset, + const char **data, + unsigned long *length) +{ + cairo_int_status_t status; + cff_header_t header; + cairo_array_t *charstring; + unsigned char buf[40]; + unsigned char *end_buf, *end_buf2; + unsigned int i; + int sid; + + /* Create header */ + header.major = 1; + header.minor = 0; + header.header_size = 4; + header.offset_size = 4; + font->header = &header; + + /* Create Top Dict */ + font->is_cid = FALSE; + + snprintf((char*)buf, sizeof(buf), "CairoFont-%u-%u", + font->scaled_font_subset->font_id, + font->scaled_font_subset->subset_id); + sid = NUM_STD_STRINGS + _cairo_array_num_elements (&font->strings_subset_index); + status = cff_index_append_copy (&font->strings_subset_index, + (unsigned char *)buf, + strlen((char*)buf)); + if (unlikely (status)) + return status; + + end_buf = encode_integer (buf, sid); + status = cff_dict_set_operands (font->top_dict, FULLNAME_OP, + buf, end_buf - buf); + if (unlikely (status)) + return status; + + status = cff_dict_set_operands (font->top_dict, FAMILYNAME_OP, + buf, end_buf - buf); + if (unlikely (status)) + return status; + + end_buf = encode_integer (buf, type2_subset->x_min); + end_buf = encode_integer (end_buf, type2_subset->y_min); + end_buf = encode_integer (end_buf, type2_subset->x_max); + end_buf = encode_integer (end_buf, type2_subset->y_max); + status = cff_dict_set_operands (font->top_dict, + FONTBBOX_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + + end_buf = encode_integer_max (buf, 0); + status = cff_dict_set_operands (font->top_dict, + CHARSTRINGS_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + + + if (font->scaled_font_subset->is_latin) { + status = cff_dict_set_operands (font->top_dict, + ENCODING_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + + /* Private has two operands - size and offset */ + end_buf2 = encode_integer_max (end_buf, 0); + cff_dict_set_operands (font->top_dict, PRIVATE_OP, buf, end_buf2 - buf); + if (unlikely (status)) + return status; + + } else { + status = cff_dict_set_operands (font->top_dict, + FDSELECT_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + + status = cff_dict_set_operands (font->top_dict, + FDARRAY_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + } + + status = cff_dict_set_operands (font->top_dict, + CHARSET_OP, buf, end_buf - buf); + if (unlikely (status)) + return status; + + if (!font->scaled_font_subset->is_latin) { + status = cairo_cff_font_set_ros_strings (font); + if (unlikely (status)) + return status; + + /* Create CID FD dictionary */ + status = cairo_cff_font_create_cid_fontdict (font); + if (unlikely (status)) + return status; + } else { + font->private_dict_offset = malloc (sizeof (int)); + if (unlikely (font->private_dict_offset == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + /* Create charstrings */ + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + charstring = _cairo_array_index(&type2_subset->charstrings, i); + + status = cff_index_append (&font->charstrings_subset_index, + _cairo_array_index (charstring, 0), + _cairo_array_num_elements (charstring)); + + if (unlikely (status)) + return status; + } + + if (font->scaled_font_subset->is_latin) + status = cairo_cff_font_add_euro_charset_string (font); + + status = cairo_cff_font_write_subset (font); + if (unlikely (status)) + return status; + + *data = _cairo_array_index (&font->output, 0); + *length = _cairo_array_num_elements (&font->output); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_cff_fallback_init (cairo_cff_subset_t *cff_subset, + const char *subset_name, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_cff_font_t *font = NULL; /* squelch bogus compiler warning */ + cairo_status_t status; + const char *data = NULL; /* squelch bogus compiler warning */ + unsigned long length = 0; /* squelch bogus compiler warning */ + unsigned int i; + cairo_type2_charstrings_t type2_subset; + + status = _cairo_cff_font_fallback_create (font_subset, &font, subset_name); + if (unlikely (status)) + return status; + + status = _cairo_type2_charstrings_init (&type2_subset, font_subset); + if (unlikely (status)) + goto fail1; + + status = cairo_cff_font_fallback_generate (font, &type2_subset, &data, &length); + if (unlikely (status)) + goto fail2; + + cff_subset->family_name_utf8 = NULL; + cff_subset->ps_name = strdup (font->ps_name); + if (unlikely (cff_subset->ps_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + + cff_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); + if (unlikely (cff_subset->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) + cff_subset->widths[i] = (double)type2_subset.widths[i]/1000; + + cff_subset->x_min = (double)type2_subset.x_min/1000; + cff_subset->y_min = (double)type2_subset.y_min/1000; + cff_subset->x_max = (double)type2_subset.x_max/1000; + cff_subset->y_max = (double)type2_subset.y_max/1000; + cff_subset->ascent = (double)type2_subset.y_max/1000; + cff_subset->descent = (double)type2_subset.y_min/1000; + + cff_subset->data = malloc (length); + if (unlikely (cff_subset->data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail4; + } + + memcpy (cff_subset->data, data, length); + cff_subset->data_length = length; + + _cairo_type2_charstrings_fini (&type2_subset); + cairo_cff_font_destroy (font); + + return CAIRO_STATUS_SUCCESS; + + fail4: + free (cff_subset->widths); + fail3: + free (cff_subset->ps_name); + fail2: + _cairo_type2_charstrings_fini (&type2_subset); + fail1: + cairo_cff_font_destroy (font); + + return status; +} + +void +_cairo_cff_fallback_fini (cairo_cff_subset_t *subset) +{ + free (subset->ps_name); + free (subset->widths); + free (subset->data); +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-boxes.c b/Build/source/libs/cairo/cairo-src/src/cairo-clip-boxes.c new file mode 100644 index 00000000000..7bcbeb1918a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-boxes.c @@ -0,0 +1,599 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-gstate-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-pattern-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-region-private.h" + +static inline int +pot (int v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} + +static cairo_bool_t +_cairo_clip_contains_rectangle_box (const cairo_clip_t *clip, + const cairo_rectangle_int_t *rect, + const cairo_box_t *box) +{ + int i; + + /* clip == NULL means no clip, so the clip contains everything */ + if (clip == NULL) + return TRUE; + + if (_cairo_clip_is_all_clipped (clip)) + return FALSE; + + /* If we have a non-trivial path, just say no */ + if (clip->path) + return FALSE; + + if (! _cairo_rectangle_contains_rectangle (&clip->extents, rect)) + return FALSE; + + if (clip->num_boxes == 0) + return TRUE; + + /* Check for a clip-box that wholly contains the rectangle */ + for (i = 0; i < clip->num_boxes; i++) { + if (box->p1.x >= clip->boxes[i].p1.x && + box->p1.y >= clip->boxes[i].p1.y && + box->p2.x <= clip->boxes[i].p2.x && + box->p2.y <= clip->boxes[i].p2.y) + { + return TRUE; + } + } + + return FALSE; +} + +cairo_bool_t +_cairo_clip_contains_box (const cairo_clip_t *clip, + const cairo_box_t *box) +{ + cairo_rectangle_int_t rect; + + _cairo_box_round_to_rectangle (box, &rect); + return _cairo_clip_contains_rectangle_box(clip, &rect, box); +} + +cairo_bool_t +_cairo_clip_contains_rectangle (const cairo_clip_t *clip, + const cairo_rectangle_int_t *rect) +{ + cairo_box_t box; + + box.p1.x = _cairo_fixed_from_int (rect->x); + box.p1.y = _cairo_fixed_from_int (rect->y); + box.p2.x = _cairo_fixed_from_int (rect->x + rect->width); + box.p2.y = _cairo_fixed_from_int (rect->y + rect->height); + + return _cairo_clip_contains_rectangle_box (clip, rect, &box); +} + +cairo_clip_t * +_cairo_clip_intersect_rectilinear_path (cairo_clip_t *clip, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias) +{ + cairo_status_t status; + cairo_boxes_t boxes; + + _cairo_boxes_init (&boxes); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + fill_rule, + antialias, + &boxes); + if (likely (status == CAIRO_STATUS_SUCCESS && boxes.num_boxes)) + clip = _cairo_clip_intersect_boxes (clip, &boxes); + else + clip = _cairo_clip_set_all_clipped (clip); + _cairo_boxes_fini (&boxes); + + return clip; +} + +static cairo_clip_t * +_cairo_clip_intersect_rectangle_box (cairo_clip_t *clip, + const cairo_rectangle_int_t *r, + const cairo_box_t *box) +{ + cairo_box_t extents_box; + cairo_bool_t changed = FALSE; + int i, j; + + if (clip == NULL) { + clip = _cairo_clip_create (); + if (clip == NULL) + return _cairo_clip_set_all_clipped (clip); + } + + if (clip->num_boxes == 0) { + clip->boxes = &clip->embedded_box; + clip->boxes[0] = *box; + clip->num_boxes = 1; + if (clip->path == NULL) { + clip->extents = *r; + } else { + if (! _cairo_rectangle_intersect (&clip->extents, r)) + return _cairo_clip_set_all_clipped (clip); + } + if (clip->path == NULL) + clip->is_region = _cairo_box_is_pixel_aligned (box); + return clip; + } + + /* Does the new box wholly subsume the clip? Perform a cheap check + * for the common condition of a single clip rectangle. + */ + if (clip->num_boxes == 1 && + clip->boxes[0].p1.x >= box->p1.x && + clip->boxes[0].p1.y >= box->p1.y && + clip->boxes[0].p2.x <= box->p2.x && + clip->boxes[0].p2.y <= box->p2.y) + { + return clip; + } + + for (i = j = 0; i < clip->num_boxes; i++) { + cairo_box_t *b = &clip->boxes[j]; + + if (j != i) + *b = clip->boxes[i]; + + if (box->p1.x > b->p1.x) + b->p1.x = box->p1.x, changed = TRUE; + if (box->p2.x < b->p2.x) + b->p2.x = box->p2.x, changed = TRUE; + + if (box->p1.y > b->p1.y) + b->p1.y = box->p1.y, changed = TRUE; + if (box->p2.y < b->p2.y) + b->p2.y = box->p2.y, changed = TRUE; + + j += b->p2.x > b->p1.x && b->p2.y > b->p1.y; + } + clip->num_boxes = j; + + if (clip->num_boxes == 0) + return _cairo_clip_set_all_clipped (clip); + + if (! changed) + return clip; + + extents_box = clip->boxes[0]; + for (i = 1; i < clip->num_boxes; i++) { + if (clip->boxes[i].p1.x < extents_box.p1.x) + extents_box.p1.x = clip->boxes[i].p1.x; + + if (clip->boxes[i].p1.y < extents_box.p1.y) + extents_box.p1.y = clip->boxes[i].p1.y; + + if (clip->boxes[i].p2.x > extents_box.p2.x) + extents_box.p2.x = clip->boxes[i].p2.x; + + if (clip->boxes[i].p2.y > extents_box.p2.y) + extents_box.p2.y = clip->boxes[i].p2.y; + } + + if (clip->path == NULL) { + _cairo_box_round_to_rectangle (&extents_box, &clip->extents); + } else { + cairo_rectangle_int_t extents_rect; + + _cairo_box_round_to_rectangle (&extents_box, &extents_rect); + if (! _cairo_rectangle_intersect (&clip->extents, &extents_rect)) + return _cairo_clip_set_all_clipped (clip); + } + + if (clip->region) { + cairo_region_destroy (clip->region); + clip->region = NULL; + } + + clip->is_region = FALSE; + return clip; +} + +cairo_clip_t * +_cairo_clip_intersect_box (cairo_clip_t *clip, + const cairo_box_t *box) +{ + cairo_rectangle_int_t r; + + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + _cairo_box_round_to_rectangle (box, &r); + if (r.width == 0 || r.height == 0) + return _cairo_clip_set_all_clipped (clip); + + return _cairo_clip_intersect_rectangle_box (clip, &r, box); +} + +cairo_clip_t * +_cairo_clip_intersect_boxes (cairo_clip_t *clip, + const cairo_boxes_t *boxes) +{ + cairo_boxes_t clip_boxes; + cairo_box_t limits; + cairo_rectangle_int_t extents; + + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + if (boxes->num_boxes == 0) + return _cairo_clip_set_all_clipped (clip); + + if (boxes->num_boxes == 1) + return _cairo_clip_intersect_box (clip, boxes->chunks.base); + + if (clip == NULL) + clip = _cairo_clip_create (); + + if (clip->num_boxes) { + _cairo_boxes_init_for_array (&clip_boxes, clip->boxes, clip->num_boxes); + if (unlikely (_cairo_boxes_intersect (&clip_boxes, boxes, &clip_boxes))) { + clip = _cairo_clip_set_all_clipped (clip); + goto out; + } + + if (clip->boxes != &clip->embedded_box) + free (clip->boxes); + + clip->boxes = NULL; + boxes = &clip_boxes; + } + + if (boxes->num_boxes == 0) { + clip = _cairo_clip_set_all_clipped (clip); + goto out; + } else if (boxes->num_boxes == 1) { + clip->boxes = &clip->embedded_box; + clip->boxes[0] = boxes->chunks.base[0]; + clip->num_boxes = 1; + } else { + clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes, TRUE); + } + _cairo_boxes_extents (boxes, &limits); + + _cairo_box_round_to_rectangle (&limits, &extents); + if (clip->path == NULL) { + clip->extents = extents; + } else if (! _cairo_rectangle_intersect (&clip->extents, &extents)) { + clip = _cairo_clip_set_all_clipped (clip); + goto out; + } + + if (clip->region) { + cairo_region_destroy (clip->region); + clip->region = NULL; + } + clip->is_region = FALSE; + +out: + if (boxes == &clip_boxes) + _cairo_boxes_fini (&clip_boxes); + + return clip; +} + +cairo_clip_t * +_cairo_clip_intersect_rectangle (cairo_clip_t *clip, + const cairo_rectangle_int_t *r) +{ + cairo_box_t box; + + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + if (r->width == 0 || r->height == 0) + return _cairo_clip_set_all_clipped (clip); + + box.p1.x = _cairo_fixed_from_int (r->x); + box.p1.y = _cairo_fixed_from_int (r->y); + box.p2.x = _cairo_fixed_from_int (r->x + r->width); + box.p2.y = _cairo_fixed_from_int (r->y + r->height); + + return _cairo_clip_intersect_rectangle_box (clip, r, &box); +} + +struct reduce { + cairo_clip_t *clip; + cairo_box_t limit; + cairo_box_t extents; + cairo_bool_t inside; + + cairo_point_t current_point; + cairo_point_t last_move_to; +}; + +static void +_add_clipped_edge (struct reduce *r, + const cairo_point_t *p1, + const cairo_point_t *p2, + int y1, int y2) +{ + cairo_fixed_t x; + + x = _cairo_edge_compute_intersection_x_for_y (p1, p2, y1); + if (x < r->extents.p1.x) + r->extents.p1.x = x; + + x = _cairo_edge_compute_intersection_x_for_y (p1, p2, y2); + if (x > r->extents.p2.x) + r->extents.p2.x = x; + + if (y1 < r->extents.p1.y) + r->extents.p1.y = y1; + + if (y2 > r->extents.p2.y) + r->extents.p2.y = y2; + + r->inside = TRUE; +} + +static void +_add_edge (struct reduce *r, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + int top, bottom; + int top_y, bot_y; + int n; + + if (p1->y < p2->y) { + top = p1->y; + bottom = p2->y; + } else { + top = p2->y; + bottom = p1->y; + } + + if (bottom < r->limit.p1.y || top > r->limit.p2.y) + return; + + if (p1->x > p2->x) { + const cairo_point_t *t = p1; + p1 = p2; + p2 = t; + } + + if (p2->x <= r->limit.p1.x || p1->x >= r->limit.p2.x) + return; + + for (n = 0; n < r->clip->num_boxes; n++) { + const cairo_box_t *limits = &r->clip->boxes[n]; + + if (bottom < limits->p1.y || top > limits->p2.y) + continue; + + if (p2->x <= limits->p1.x || p1->x >= limits->p2.x) + continue; + + if (p1->x >= limits->p1.x && p2->x <= limits->p1.x) { + top_y = top; + bot_y = bottom; + } else { + int p1_y, p2_y; + + p1_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, + limits->p1.x); + p2_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, + limits->p2.x); + if (p1_y < p2_y) { + top_y = p1_y; + bot_y = p2_y; + } else { + top_y = p2_y; + bot_y = p1_y; + } + + if (top_y < top) + top_y = top; + if (bot_y > bottom) + bot_y = bottom; + } + + if (top_y < limits->p1.y) + top_y = limits->p1.y; + + if (bot_y > limits->p2.y) + bot_y = limits->p2.y; + if (bot_y > top_y) + _add_clipped_edge (r, p1, p2, top_y, bot_y); + } +} + +static cairo_status_t +_reduce_line_to (void *closure, + const cairo_point_t *point) +{ + struct reduce *r = closure; + + _add_edge (r, &r->current_point, point); + r->current_point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_reduce_close (void *closure) +{ + struct reduce *r = closure; + + return _reduce_line_to (r, &r->last_move_to); +} + +static cairo_status_t +_reduce_move_to (void *closure, + const cairo_point_t *point) +{ + struct reduce *r = closure; + cairo_status_t status; + + /* close current subpath */ + status = _reduce_close (closure); + + /* make sure that the closure represents a degenerate path */ + r->current_point = *point; + r->last_move_to = *point; + + return status; +} + +static cairo_clip_t * +_cairo_clip_reduce_to_boxes (cairo_clip_t *clip) +{ + struct reduce r; + cairo_clip_path_t *clip_path; + cairo_status_t status; + + return clip; + if (clip->path == NULL) + return clip; + + r.clip = clip; + r.extents.p1.x = r.extents.p1.y = INT_MAX; + r.extents.p2.x = r.extents.p2.y = INT_MIN; + r.inside = FALSE; + + r.limit.p1.x = _cairo_fixed_from_int (clip->extents.x); + r.limit.p1.y = _cairo_fixed_from_int (clip->extents.y); + r.limit.p2.x = _cairo_fixed_from_int (clip->extents.x + clip->extents.width); + r.limit.p2.y = _cairo_fixed_from_int (clip->extents.y + clip->extents.height); + + clip_path = clip->path; + do { + r.current_point.x = 0; + r.current_point.y = 0; + r.last_move_to = r.current_point; + + status = _cairo_path_fixed_interpret_flat (&clip_path->path, + _reduce_move_to, + _reduce_line_to, + _reduce_close, + &r, + clip_path->tolerance); + assert (status == CAIRO_STATUS_SUCCESS); + _reduce_close (&r); + } while ((clip_path = clip_path->prev)); + + if (! r.inside) { + _cairo_clip_path_destroy (clip->path); + clip->path = NULL; + } + + return _cairo_clip_intersect_box (clip, &r.extents); +} + +cairo_clip_t * +_cairo_clip_reduce_to_rectangle (const cairo_clip_t *clip, + const cairo_rectangle_int_t *r) +{ + cairo_clip_t *copy; + + if (_cairo_clip_is_all_clipped (clip)) + return (cairo_clip_t *) clip; + + if (_cairo_clip_contains_rectangle (clip, r)) + return _cairo_clip_intersect_rectangle (NULL, r); + + copy = _cairo_clip_copy_intersect_rectangle (clip, r); + if (_cairo_clip_is_all_clipped (copy)) + return copy; + + return _cairo_clip_reduce_to_boxes (copy); +} + +cairo_clip_t * +_cairo_clip_reduce_for_composite (const cairo_clip_t *clip, + cairo_composite_rectangles_t *extents) +{ + const cairo_rectangle_int_t *r; + + r = extents->is_bounded ? &extents->bounded : &extents->unbounded; + return _cairo_clip_reduce_to_rectangle (clip, r); +} + +cairo_clip_t * +_cairo_clip_from_boxes (const cairo_boxes_t *boxes) +{ + cairo_box_t extents; + cairo_clip_t *clip = _cairo_clip_create (); + if (clip == NULL) + return _cairo_clip_set_all_clipped (clip); + + /* XXX cow-boxes? */ + if(boxes->num_boxes == 1) { + clip->boxes = &clip->embedded_box; + clip->boxes[0] = boxes->chunks.base[0]; + clip->num_boxes = 1; + } else { + clip->boxes = _cairo_boxes_to_array (boxes, &clip->num_boxes, TRUE); + if (clip->boxes == NULL) + return _cairo_clip_set_all_clipped (clip); + } + + _cairo_boxes_extents (boxes, &extents); + _cairo_box_round_to_rectangle (&extents, &clip->extents); + + return clip; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-clip-inline.h new file mode 100644 index 00000000000..a9f23269223 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-inline.h @@ -0,0 +1,83 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Chris Wilson + */ + +#ifndef CAIRO_CLIP_INLINE_H +#define CAIRO_CLIP_INLINE_H + +#include "cairo-clip-private.h" + +static inline cairo_bool_t _cairo_clip_is_all_clipped(const cairo_clip_t *clip) +{ + return clip == &__cairo_clip_all; +} + +static inline cairo_clip_t * +_cairo_clip_set_all_clipped (cairo_clip_t *clip) +{ + _cairo_clip_destroy (clip); + return (cairo_clip_t *) &__cairo_clip_all; +} + +static inline cairo_clip_t * +_cairo_clip_copy_intersect_rectangle (const cairo_clip_t *clip, + const cairo_rectangle_int_t *r) +{ + return _cairo_clip_intersect_rectangle (_cairo_clip_copy (clip), r); +} + +static inline cairo_clip_t * +_cairo_clip_copy_intersect_clip (const cairo_clip_t *clip, + const cairo_clip_t *other) +{ + return _cairo_clip_intersect_clip (_cairo_clip_copy (clip), other); +} + +static inline void +_cairo_clip_steal_boxes (cairo_clip_t *clip, cairo_boxes_t *boxes) +{ + _cairo_boxes_init_for_array (boxes, clip->boxes, clip->num_boxes); + clip->boxes = NULL; + clip->num_boxes = 0; +} + +static inline void +_cairo_clip_unsteal_boxes (cairo_clip_t *clip, cairo_boxes_t *boxes) +{ + clip->boxes = boxes->chunks.base; + clip->num_boxes = boxes->num_boxes; +} + +#endif /* CAIRO_CLIP_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-polygon.c b/Build/source/libs/cairo/cairo-src/src/cairo-clip-polygon.c new file mode 100644 index 00000000000..f40faefba80 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-polygon.c @@ -0,0 +1,156 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-gstate-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-pattern-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-region-private.h" + +static cairo_bool_t +can_convert_to_polygon (const cairo_clip_t *clip) +{ + cairo_clip_path_t *clip_path = clip->path; + cairo_antialias_t antialias = clip_path->antialias; + + while ((clip_path = clip_path->prev) != NULL) { + if (clip_path->antialias != antialias) + return FALSE; + } + + return TRUE; +} + +cairo_int_status_t +_cairo_clip_get_polygon (const cairo_clip_t *clip, + cairo_polygon_t *polygon, + cairo_fill_rule_t *fill_rule, + cairo_antialias_t *antialias) +{ + cairo_status_t status; + cairo_clip_path_t *clip_path; + + if (_cairo_clip_is_all_clipped (clip)) { + _cairo_polygon_init (polygon, NULL, 0); + return CAIRO_INT_STATUS_SUCCESS; + } + + /* If there is no clip, we need an infinite polygon */ + assert (clip && (clip->path || clip->num_boxes)); + + if (clip->path == NULL) { + *fill_rule = CAIRO_FILL_RULE_WINDING; + *antialias = CAIRO_ANTIALIAS_DEFAULT; + return _cairo_polygon_init_box_array (polygon, + clip->boxes, + clip->num_boxes); + } + + /* check that residual is all of the same type/tolerance */ + if (! can_convert_to_polygon (clip)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (clip->num_boxes < 2) + _cairo_polygon_init_with_clip (polygon, clip); + else + _cairo_polygon_init_with_clip (polygon, NULL); + + clip_path = clip->path; + *fill_rule = clip_path->fill_rule; + *antialias = clip_path->antialias; + + status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, + clip_path->tolerance, + polygon); + if (unlikely (status)) + goto err; + + if (clip->num_boxes > 1) { + status = _cairo_polygon_intersect_with_boxes (polygon, fill_rule, + clip->boxes, clip->num_boxes); + if (unlikely (status)) + goto err; + } + + polygon->limits = NULL; + polygon->num_limits = 0; + + while ((clip_path = clip_path->prev) != NULL) { + cairo_polygon_t next; + + _cairo_polygon_init (&next, NULL, 0); + status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, + clip_path->tolerance, + &next); + if (likely (status == CAIRO_STATUS_SUCCESS)) + status = _cairo_polygon_intersect (polygon, *fill_rule, + &next, clip_path->fill_rule); + _cairo_polygon_fini (&next); + if (unlikely (status)) + goto err; + + *fill_rule = CAIRO_FILL_RULE_WINDING; + } + + return CAIRO_STATUS_SUCCESS; + +err: + _cairo_polygon_fini (polygon); + return status; +} + +cairo_bool_t +_cairo_clip_is_polygon (const cairo_clip_t *clip) +{ + if (_cairo_clip_is_all_clipped (clip)) + return TRUE; + + /* If there is no clip, we need an infinite polygon */ + if (clip == NULL) + return FALSE; + + if (clip->path == NULL) + return TRUE; + + /* check that residual is all of the same type/tolerance */ + return can_convert_to_polygon (clip); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-clip-private.h new file mode 100644 index 00000000000..5fc05a64e93 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-private.h @@ -0,0 +1,198 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Chris Wilson + */ + +#ifndef CAIRO_CLIP_PRIVATE_H +#define CAIRO_CLIP_PRIVATE_H + +#include "cairo-types-private.h" + +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-reference-count-private.h" + +extern const cairo_private cairo_rectangle_list_t _cairo_rectangles_nil; + +struct _cairo_clip_path { + cairo_reference_count_t ref_count; + cairo_path_fixed_t path; + cairo_fill_rule_t fill_rule; + double tolerance; + cairo_antialias_t antialias; + cairo_clip_path_t *prev; +}; + +struct _cairo_clip { + cairo_rectangle_int_t extents; + cairo_clip_path_t *path; + + cairo_box_t *boxes; + int num_boxes; + + cairo_region_t *region; + cairo_bool_t is_region; + + cairo_box_t embedded_box; +}; + +cairo_private cairo_clip_t * +_cairo_clip_create (void); + +cairo_private cairo_clip_path_t * +_cairo_clip_path_reference (cairo_clip_path_t *clip_path); + +cairo_private void +_cairo_clip_path_destroy (cairo_clip_path_t *clip_path); + +cairo_private void +_cairo_clip_destroy (cairo_clip_t *clip); + +cairo_private extern const cairo_clip_t __cairo_clip_all; + +cairo_private cairo_clip_t * +_cairo_clip_copy (const cairo_clip_t *clip); + +cairo_private cairo_clip_t * +_cairo_clip_copy_region (const cairo_clip_t *clip); + +cairo_private cairo_clip_t * +_cairo_clip_copy_path (const cairo_clip_t *clip); + +cairo_private cairo_clip_t * +_cairo_clip_translate (cairo_clip_t *clip, int tx, int ty); + +cairo_private cairo_clip_t * +_cairo_clip_transform (cairo_clip_t *clip, const cairo_matrix_t *m); + +cairo_private cairo_clip_t * +_cairo_clip_copy_with_translation (const cairo_clip_t *clip, int tx, int ty); + +cairo_private cairo_bool_t +_cairo_clip_equal (const cairo_clip_t *clip_a, + const cairo_clip_t *clip_b); + +cairo_private cairo_clip_t * +_cairo_clip_intersect_rectangle (cairo_clip_t *clip, + const cairo_rectangle_int_t *rectangle); + +cairo_private cairo_clip_t * +_cairo_clip_intersect_clip (cairo_clip_t *clip, + const cairo_clip_t *other); + +cairo_private cairo_clip_t * +_cairo_clip_intersect_box (cairo_clip_t *clip, + const cairo_box_t *box); + +cairo_private cairo_clip_t * +_cairo_clip_intersect_boxes (cairo_clip_t *clip, + const cairo_boxes_t *boxes); + +cairo_private cairo_clip_t * +_cairo_clip_intersect_rectilinear_path (cairo_clip_t *clip, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias); + +cairo_private cairo_clip_t * +_cairo_clip_intersect_path (cairo_clip_t *clip, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias); + +cairo_private const cairo_rectangle_int_t * +_cairo_clip_get_extents (const cairo_clip_t *clip); + +cairo_private cairo_surface_t * +_cairo_clip_get_surface (const cairo_clip_t *clip, cairo_surface_t *dst, int *tx, int *ty); + +cairo_private cairo_surface_t * +_cairo_clip_get_image (const cairo_clip_t *clip, + cairo_surface_t *target, + const cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_clip_combine_with_surface (const cairo_clip_t *clip, + cairo_surface_t *dst, + int dst_x, int dst_y); + +cairo_private cairo_clip_t * +_cairo_clip_from_boxes (const cairo_boxes_t *boxes); + +cairo_private cairo_region_t * +_cairo_clip_get_region (const cairo_clip_t *clip); + +cairo_private cairo_bool_t +_cairo_clip_is_region (const cairo_clip_t *clip); + +cairo_private cairo_clip_t * +_cairo_clip_reduce_to_rectangle (const cairo_clip_t *clip, + const cairo_rectangle_int_t *r); + +cairo_private cairo_clip_t * +_cairo_clip_reduce_for_composite (const cairo_clip_t *clip, + cairo_composite_rectangles_t *extents); + +cairo_private cairo_bool_t +_cairo_clip_contains_rectangle (const cairo_clip_t *clip, + const cairo_rectangle_int_t *rect); + +cairo_private cairo_bool_t +_cairo_clip_contains_box (const cairo_clip_t *clip, + const cairo_box_t *box); + +cairo_private cairo_bool_t +_cairo_clip_contains_extents (const cairo_clip_t *clip, + const cairo_composite_rectangles_t *extents); + +cairo_private cairo_rectangle_list_t* +_cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate); + +cairo_private cairo_rectangle_list_t * +_cairo_rectangle_list_create_in_error (cairo_status_t status); + +cairo_private cairo_bool_t +_cairo_clip_is_polygon (const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_clip_get_polygon (const cairo_clip_t *clip, + cairo_polygon_t *polygon, + cairo_fill_rule_t *fill_rule, + cairo_antialias_t *antialias); + +#endif /* CAIRO_CLIP_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-region.c b/Build/source/libs/cairo/cairo-src/src/cairo-clip-region.c new file mode 100644 index 00000000000..e3f4891e3f2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-region.c @@ -0,0 +1,123 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-gstate-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-pattern-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-region-private.h" + +static void +_cairo_clip_extract_region (cairo_clip_t *clip) +{ + cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)]; + cairo_rectangle_int_t *r = stack_rects; + cairo_bool_t is_region; + int i; + + if (clip->num_boxes == 0) + return; + + if (clip->num_boxes > ARRAY_LENGTH (stack_rects)) { + r = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_rectangle_int_t)); + if (r == NULL){ + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return; + } + } + + is_region = clip->path == NULL; + for (i = 0; i < clip->num_boxes; i++) { + cairo_box_t *b = &clip->boxes[i]; + if (is_region) + is_region = + _cairo_fixed_is_integer (b->p1.x | b->p1.y | b->p2.x | b->p2.y); + r[i].x = _cairo_fixed_integer_floor (b->p1.x); + r[i].y = _cairo_fixed_integer_floor (b->p1.y); + r[i].width = _cairo_fixed_integer_ceil (b->p2.x) - r[i].x; + r[i].height = _cairo_fixed_integer_ceil (b->p2.y) - r[i].y; + } + clip->is_region = is_region; + + clip->region = cairo_region_create_rectangles (r, i); + + if (r != stack_rects) + free (r); +} + +cairo_region_t * +_cairo_clip_get_region (const cairo_clip_t *clip) +{ + if (clip == NULL) + return NULL; + + if (clip->region == NULL) + _cairo_clip_extract_region ((cairo_clip_t *) clip); + + return clip->region; +} + +cairo_bool_t +_cairo_clip_is_region (const cairo_clip_t *clip) +{ + if (clip == NULL) + return TRUE; + + if (clip->is_region) + return TRUE; + + /* XXX Geometric reduction? */ + + if (clip->path) + return FALSE; + + if (clip->num_boxes == 0) + return TRUE; + + if (clip->region == NULL) + _cairo_clip_extract_region ((cairo_clip_t *) clip); + + return clip->is_region; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-clip-surface.c new file mode 100644 index 00000000000..85feaa649eb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-surface.c @@ -0,0 +1,240 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-gstate-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-pattern-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-region-private.h" + +cairo_status_t +_cairo_clip_combine_with_surface (const cairo_clip_t *clip, + cairo_surface_t *dst, + int dst_x, int dst_y) +{ + cairo_clip_path_t *copy_path; + cairo_clip_path_t *clip_path; + cairo_clip_t *copy; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + copy = _cairo_clip_copy_with_translation (clip, -dst_x, -dst_y); + copy_path = copy->path; + copy->path = NULL; + + if (copy->boxes) { + status = _cairo_surface_paint (dst, + CAIRO_OPERATOR_IN, + &_cairo_pattern_white.base, + copy); + } + + clip = NULL; + if (_cairo_clip_is_region (copy)) + clip = copy; + clip_path = copy_path; + while (status == CAIRO_STATUS_SUCCESS && clip_path) { + status = _cairo_surface_fill (dst, + CAIRO_OPERATOR_IN, + &_cairo_pattern_white.base, + &clip_path->path, + clip_path->fill_rule, + clip_path->tolerance, + clip_path->antialias, + clip); + clip_path = clip_path->prev; + } + + copy->path = copy_path; + _cairo_clip_destroy (copy); + return status; +} + +static cairo_status_t +_cairo_path_fixed_add_box (cairo_path_fixed_t *path, + const cairo_box_t *box, + cairo_fixed_t fx, + cairo_fixed_t fy) +{ + cairo_status_t status; + + status = _cairo_path_fixed_move_to (path, box->p1.x + fx, box->p1.y + fy); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p2.x + fx, box->p1.y + fy); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p2.x + fx, box->p2.y + fy); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p1.x + fx, box->p2.y + fy); + if (unlikely (status)) + return status; + + return _cairo_path_fixed_close_path (path); +} + +cairo_surface_t * +_cairo_clip_get_surface (const cairo_clip_t *clip, + cairo_surface_t *target, + int *tx, int *ty) +{ + cairo_surface_t *surface; + cairo_status_t status; + cairo_clip_t *copy, *region; + cairo_clip_path_t *copy_path, *clip_path; + + if (clip->num_boxes) { + cairo_path_fixed_t path; + int i; + + surface = _cairo_surface_create_scratch (target, + CAIRO_CONTENT_ALPHA, + clip->extents.width, + clip->extents.height, + CAIRO_COLOR_TRANSPARENT); + if (unlikely (surface->status)) + return surface; + + _cairo_path_fixed_init (&path); + status = CAIRO_STATUS_SUCCESS; + for (i = 0; status == CAIRO_STATUS_SUCCESS && i < clip->num_boxes; i++) { + status = _cairo_path_fixed_add_box (&path, &clip->boxes[i], + -_cairo_fixed_from_int (clip->extents.x), + -_cairo_fixed_from_int (clip->extents.y)); + } + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_surface_fill (surface, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + &path, + CAIRO_FILL_RULE_WINDING, + 1., + CAIRO_ANTIALIAS_DEFAULT, + NULL); + _cairo_path_fixed_fini (&path); + if (unlikely (status)) { + cairo_surface_destroy (surface); + return _cairo_surface_create_in_error (status); + } + } else { + surface = _cairo_surface_create_scratch (target, + CAIRO_CONTENT_ALPHA, + clip->extents.width, + clip->extents.height, + CAIRO_COLOR_WHITE); + if (unlikely (surface->status)) + return surface; + } + + copy = _cairo_clip_copy_with_translation (clip, + -clip->extents.x, + -clip->extents.y); + copy_path = copy->path; + copy->path = NULL; + + region = copy; + if (! _cairo_clip_is_region (copy)) + region = _cairo_clip_copy_region (copy); + + status = CAIRO_STATUS_SUCCESS; + clip_path = copy_path; + while (status == CAIRO_STATUS_SUCCESS && clip_path) { + status = _cairo_surface_fill (surface, + CAIRO_OPERATOR_IN, + &_cairo_pattern_white.base, + &clip_path->path, + clip_path->fill_rule, + clip_path->tolerance, + clip_path->antialias, + region); + clip_path = clip_path->prev; + } + + copy->path = copy_path; + _cairo_clip_destroy (copy); + if (region != copy) + _cairo_clip_destroy (region); + + if (unlikely (status)) { + cairo_surface_destroy (surface); + return _cairo_surface_create_in_error (status); + } + + *tx = clip->extents.x; + *ty = clip->extents.y; + return surface; +} + +cairo_surface_t * +_cairo_clip_get_image (const cairo_clip_t *clip, + cairo_surface_t *target, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_t *surface; + cairo_status_t status; + + surface = cairo_surface_create_similar_image (target, + CAIRO_FORMAT_A8, + extents->width, + extents->height); + if (unlikely (surface->status)) + return surface; + + status = _cairo_surface_paint (surface, CAIRO_OPERATOR_SOURCE, + &_cairo_pattern_white.base, NULL); + if (likely (status == CAIRO_STATUS_SUCCESS)) + status = _cairo_clip_combine_with_surface (clip, surface, + extents->x, extents->y); + + if (unlikely (status)) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + + return surface; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip-tor-scan-converter.c b/Build/source/libs/cairo/cairo-src/src/cairo-clip-tor-scan-converter.c new file mode 100644 index 00000000000..e32a5a9d9c7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip-tor-scan-converter.c @@ -0,0 +1,1845 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* glitter-paths - polygon scan converter + * + * Copyright (c) 2008 M Joonas Pihlaja + * Copyright (c) 2007 David Turner + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +/* This is the Glitter paths scan converter incorporated into cairo. + * The source is from commit 734c53237a867a773640bd5b64816249fa1730f8 + * of + * + * http://gitweb.freedesktop.org/?p=users/joonas/glitter-paths + */ +/* Glitter-paths is a stand alone polygon rasteriser derived from + * David Turner's reimplementation of Tor Anderssons's 15x17 + * supersampling rasteriser from the Apparition graphics library. The + * main new feature here is cheaply choosing per-scan line between + * doing fully analytical coverage computation for an entire row at a + * time vs. using a supersampling approach. + * + * David Turner's code can be found at + * + * http://david.freetype.org/rasterizer-shootout/raster-comparison-20070813.tar.bz2 + * + * In particular this file incorporates large parts of ftgrays_tor10.h + * from raster-comparison-20070813.tar.bz2 + */ +/* Overview + * + * A scan converter's basic purpose to take polygon edges and convert + * them into an RLE compressed A8 mask. This one works in two phases: + * gathering edges and generating spans. + * + * 1) As the user feeds the scan converter edges they are vertically + * clipped and bucketted into a _polygon_ data structure. The edges + * are also snapped from the user's coordinates to the subpixel grid + * coordinates used during scan conversion. + * + * user + * | + * | edges + * V + * polygon buckets + * + * 2) Generating spans works by performing a vertical sweep of pixel + * rows from top to bottom and maintaining an _active_list_ of edges + * that intersect the row. From the active list the fill rule + * determines which edges are the left and right edges of the start of + * each span, and their contribution is then accumulated into a pixel + * coverage list (_cell_list_) as coverage deltas. Once the coverage + * deltas of all edges are known we can form spans of constant pixel + * coverage by summing the deltas during a traversal of the cell list. + * At the end of a pixel row the cell list is sent to a coverage + * blitter for rendering to some target surface. + * + * The pixel coverages are computed by either supersampling the row + * and box filtering a mono rasterisation, or by computing the exact + * coverages of edges in the active list. The supersampling method is + * used whenever some edge starts or stops within the row or there are + * edge intersections in the row. + * + * polygon bucket for \ + * current pixel row | + * | | + * | activate new edges | Repeat GRID_Y times if we + * V \ are supersampling this row, + * active list / or just once if we're computing + * | | analytical coverage. + * | coverage deltas | + * V | + * pixel coverage list / + * | + * V + * coverage blitter + */ +#include "cairoint.h" +#include "cairo-spans-private.h" +#include "cairo-error-private.h" + +#include +#include +#include +#include +#include + +/* The input coordinate scale and the rasterisation grid scales. */ +#define GLITTER_INPUT_BITS CAIRO_FIXED_FRAC_BITS +#define GRID_X_BITS CAIRO_FIXED_FRAC_BITS +#define GRID_Y 15 + +/* Set glitter up to use a cairo span renderer to do the coverage + * blitting. */ +struct pool; +struct cell_list; + +/*------------------------------------------------------------------------- + * glitter-paths.h + */ + +/* "Input scaled" numbers are fixed precision reals with multiplier + * 2**GLITTER_INPUT_BITS. Input coordinates are given to glitter as + * pixel scaled numbers. These get converted to the internal grid + * scaled numbers as soon as possible. Internal overflow is possible + * if GRID_X/Y inside glitter-paths.c is larger than + * 1< +#include +#include + +/* All polygon coordinates are snapped onto a subsample grid. "Grid + * scaled" numbers are fixed precision reals with multiplier GRID_X or + * GRID_Y. */ +typedef int grid_scaled_t; +typedef int grid_scaled_x_t; +typedef int grid_scaled_y_t; + +/* Default x/y scale factors. + * You can either define GRID_X/Y_BITS to get a power-of-two scale + * or define GRID_X/Y separately. */ +#if !defined(GRID_X) && !defined(GRID_X_BITS) +# define GRID_X_BITS 8 +#endif +#if !defined(GRID_Y) && !defined(GRID_Y_BITS) +# define GRID_Y 15 +#endif + +/* Use GRID_X/Y_BITS to define GRID_X/Y if they're available. */ +#ifdef GRID_X_BITS +# define GRID_X (1 << GRID_X_BITS) +#endif +#ifdef GRID_Y_BITS +# define GRID_Y (1 << GRID_Y_BITS) +#endif + +/* The GRID_X_TO_INT_FRAC macro splits a grid scaled coordinate into + * integer and fractional parts. The integer part is floored. */ +#if defined(GRID_X_TO_INT_FRAC) + /* do nothing */ +#elif defined(GRID_X_BITS) +# define GRID_X_TO_INT_FRAC(x, i, f) \ + _GRID_TO_INT_FRAC_shift(x, i, f, GRID_X_BITS) +#else +# define GRID_X_TO_INT_FRAC(x, i, f) \ + _GRID_TO_INT_FRAC_general(x, i, f, GRID_X) +#endif + +#define _GRID_TO_INT_FRAC_general(t, i, f, m) do { \ + (i) = (t) / (m); \ + (f) = (t) % (m); \ + if ((f) < 0) { \ + --(i); \ + (f) += (m); \ + } \ +} while (0) + +#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do { \ + (f) = (t) & ((1 << (b)) - 1); \ + (i) = (t) >> (b); \ +} while (0) + +/* A grid area is a real in [0,1] scaled by 2*GRID_X*GRID_Y. We want + * to be able to represent exactly areas of subpixel trapezoids whose + * vertices are given in grid scaled coordinates. The scale factor + * comes from needing to accurately represent the area 0.5*dx*dy of a + * triangle with base dx and height dy in grid scaled numbers. */ +typedef int grid_area_t; +#define GRID_XY (2*GRID_X*GRID_Y) /* Unit area on the grid. */ + +/* GRID_AREA_TO_ALPHA(area): map [0,GRID_XY] to [0,255]. */ +#if GRID_XY == 510 +# define GRID_AREA_TO_ALPHA(c) (((c)+1) >> 1) +#elif GRID_XY == 255 +# define GRID_AREA_TO_ALPHA(c) (c) +#elif GRID_XY == 64 +# define GRID_AREA_TO_ALPHA(c) (((c) << 2) | -(((c) & 0x40) >> 6)) +#elif GRID_XY == 128 +# define GRID_AREA_TO_ALPHA(c) ((((c) << 1) | -((c) >> 7)) & 255) +#elif GRID_XY == 256 +# define GRID_AREA_TO_ALPHA(c) (((c) | -((c) >> 8)) & 255) +#elif GRID_XY == 15 +# define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) +#elif GRID_XY == 2*256*15 +# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) +#else +# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) +#endif + +#define UNROLL3(x) x x x + +struct quorem { + int32_t quo; + int32_t rem; +}; + +/* Header for a chunk of memory in a memory pool. */ +struct _pool_chunk { + /* # bytes used in this chunk. */ + size_t size; + + /* # bytes total in this chunk */ + size_t capacity; + + /* Pointer to the previous chunk or %NULL if this is the sentinel + * chunk in the pool header. */ + struct _pool_chunk *prev_chunk; + + /* Actual data starts here. Well aligned for pointers. */ +}; + +/* A memory pool. This is supposed to be embedded on the stack or + * within some other structure. It may optionally be followed by an + * embedded array from which requests are fulfilled until + * malloc needs to be called to allocate a first real chunk. */ +struct pool { + /* Chunk we're allocating from. */ + struct _pool_chunk *current; + + jmp_buf *jmp; + + /* Free list of previously allocated chunks. All have >= default + * capacity. */ + struct _pool_chunk *first_free; + + /* The default capacity of a chunk. */ + size_t default_capacity; + + /* Header for the sentinel chunk. Directly following the pool + * struct should be some space for embedded elements from which + * the sentinel chunk allocates from. */ + struct _pool_chunk sentinel[1]; +}; + +/* A polygon edge. */ +struct edge { + /* Next in y-bucket or active list. */ + struct edge *next; + + /* Current x coordinate while the edge is on the active + * list. Initialised to the x coordinate of the top of the + * edge. The quotient is in grid_scaled_x_t units and the + * remainder is mod dy in grid_scaled_y_t units.*/ + struct quorem x; + + /* Advance of the current x when moving down a subsample line. */ + struct quorem dxdy; + + /* Advance of the current x when moving down a full pixel + * row. Only initialised when the height of the edge is large + * enough that there's a chance the edge could be stepped by a + * full row's worth of subsample rows at a time. */ + struct quorem dxdy_full; + + /* The clipped y of the top of the edge. */ + grid_scaled_y_t ytop; + + /* y2-y1 after orienting the edge downwards. */ + grid_scaled_y_t dy; + + /* Number of subsample rows remaining to scan convert of this + * edge. */ + grid_scaled_y_t height_left; + + /* Original sign of the edge: +1 for downwards, -1 for upwards + * edges. */ + int dir; + int vertical; + int clip; +}; + +/* Number of subsample rows per y-bucket. Must be GRID_Y. */ +#define EDGE_Y_BUCKET_HEIGHT GRID_Y + +#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/EDGE_Y_BUCKET_HEIGHT) + +/* A collection of sorted and vertically clipped edges of the polygon. + * Edges are moved from the polygon to an active list while scan + * converting. */ +struct polygon { + /* The vertical clip extents. */ + grid_scaled_y_t ymin, ymax; + + /* Array of edges all starting in the same bucket. An edge is put + * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when + * it is added to the polygon. */ + struct edge **y_buckets; + struct edge *y_buckets_embedded[64]; + + struct { + struct pool base[1]; + struct edge embedded[32]; + } edge_pool; +}; + +/* A cell records the effect on pixel coverage of polygon edges + * passing through a pixel. It contains two accumulators of pixel + * coverage. + * + * Consider the effects of a polygon edge on the coverage of a pixel + * it intersects and that of the following one. The coverage of the + * following pixel is the height of the edge multiplied by the width + * of the pixel, and the coverage of the pixel itself is the area of + * the trapezoid formed by the edge and the right side of the pixel. + * + * +-----------------------+-----------------------+ + * | | | + * | | | + * |_______________________|_______________________| + * | \...................|.......................|\ + * | \..................|.......................| | + * | \.................|.......................| | + * | \....covered.....|.......................| | + * | \....area.......|.......................| } covered height + * | \..............|.......................| | + * |uncovered\.............|.......................| | + * | area \............|.......................| | + * |___________\...........|.......................|/ + * | | | + * | | | + * | | | + * +-----------------------+-----------------------+ + * + * Since the coverage of the following pixel will always be a multiple + * of the width of the pixel, we can store the height of the covered + * area instead. The coverage of the pixel itself is the total + * coverage minus the area of the uncovered area to the left of the + * edge. As it's faster to compute the uncovered area we only store + * that and subtract it from the total coverage later when forming + * spans to blit. + * + * The heights and areas are signed, with left edges of the polygon + * having positive sign and right edges having negative sign. When + * two edges intersect they swap their left/rightness so their + * contribution above and below the intersection point must be + * computed separately. */ +struct cell { + struct cell *next; + int x; + grid_area_t uncovered_area; + grid_scaled_y_t covered_height; + grid_scaled_y_t clipped_height; +}; + +/* A cell list represents the scan line sparsely as cells ordered by + * ascending x. It is geared towards scanning the cells in order + * using an internal cursor. */ +struct cell_list { + /* Sentinel nodes */ + struct cell head, tail; + + /* Cursor state for iterating through the cell list. */ + struct cell *cursor; + + /* Cells in the cell list are owned by the cell list and are + * allocated from this pool. */ + struct { + struct pool base[1]; + struct cell embedded[32]; + } cell_pool; +}; + +struct cell_pair { + struct cell *cell1; + struct cell *cell2; +}; + +/* The active list contains edges in the current scan line ordered by + * the x-coordinate of the intercept of the edge and the scan line. */ +struct active_list { + /* Leftmost edge on the current scan line. */ + struct edge *head; + + /* A lower bound on the height of the active edges is used to + * estimate how soon some active edge ends. We can't advance the + * scan conversion by a full pixel row if an edge ends somewhere + * within it. */ + grid_scaled_y_t min_height; +}; + +struct glitter_scan_converter { + struct polygon polygon[1]; + struct active_list active[1]; + struct cell_list coverages[1]; + + /* Clip box. */ + grid_scaled_y_t ymin, ymax; +}; + +/* Compute the floored division a/b. Assumes / and % perform symmetric + * division. */ +inline static struct quorem +floored_divrem(int a, int b) +{ + struct quorem qr; + qr.quo = a/b; + qr.rem = a%b; + if ((a^b)<0 && qr.rem) { + qr.quo -= 1; + qr.rem += b; + } + return qr; +} + +/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric + * division. */ +static struct quorem +floored_muldivrem(int x, int a, int b) +{ + struct quorem qr; + long long xa = (long long)x*a; + qr.quo = xa/b; + qr.rem = xa%b; + if ((xa>=0) != (b>=0) && qr.rem) { + qr.quo -= 1; + qr.rem += b; + } + return qr; +} + +static struct _pool_chunk * +_pool_chunk_init( + struct _pool_chunk *p, + struct _pool_chunk *prev_chunk, + size_t capacity) +{ + p->prev_chunk = prev_chunk; + p->size = 0; + p->capacity = capacity; + return p; +} + +static struct _pool_chunk * +_pool_chunk_create(struct pool *pool, size_t size) +{ + struct _pool_chunk *p; + + p = malloc(size + sizeof(struct _pool_chunk)); + if (unlikely (NULL == p)) + longjmp (*pool->jmp, _cairo_error (CAIRO_STATUS_NO_MEMORY)); + + return _pool_chunk_init(p, pool->current, size); +} + +static void +pool_init(struct pool *pool, + jmp_buf *jmp, + size_t default_capacity, + size_t embedded_capacity) +{ + pool->jmp = jmp; + pool->current = pool->sentinel; + pool->first_free = NULL; + pool->default_capacity = default_capacity; + _pool_chunk_init(pool->sentinel, NULL, embedded_capacity); +} + +static void +pool_fini(struct pool *pool) +{ + struct _pool_chunk *p = pool->current; + do { + while (NULL != p) { + struct _pool_chunk *prev = p->prev_chunk; + if (p != pool->sentinel) + free(p); + p = prev; + } + p = pool->first_free; + pool->first_free = NULL; + } while (NULL != p); +} + +/* Satisfy an allocation by first allocating a new large enough chunk + * and adding it to the head of the pool's chunk list. This function + * is called as a fallback if pool_alloc() couldn't do a quick + * allocation from the current chunk in the pool. */ +static void * +_pool_alloc_from_new_chunk( + struct pool *pool, + size_t size) +{ + struct _pool_chunk *chunk; + void *obj; + size_t capacity; + + /* If the allocation is smaller than the default chunk size then + * try getting a chunk off the free list. Force alloc of a new + * chunk for large requests. */ + capacity = size; + chunk = NULL; + if (size < pool->default_capacity) { + capacity = pool->default_capacity; + chunk = pool->first_free; + if (chunk) { + pool->first_free = chunk->prev_chunk; + _pool_chunk_init(chunk, pool->current, chunk->capacity); + } + } + + if (NULL == chunk) + chunk = _pool_chunk_create (pool, capacity); + pool->current = chunk; + + obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); + chunk->size += size; + return obj; +} + +/* Allocate size bytes from the pool. The first allocated address + * returned from a pool is aligned to sizeof(void*). Subsequent + * addresses will maintain alignment as long as multiples of void* are + * allocated. Returns the address of a new memory area or %NULL on + * allocation failures. The pool retains ownership of the returned + * memory. */ +inline static void * +pool_alloc (struct pool *pool, size_t size) +{ + struct _pool_chunk *chunk = pool->current; + + if (size <= chunk->capacity - chunk->size) { + void *obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); + chunk->size += size; + return obj; + } else { + return _pool_alloc_from_new_chunk(pool, size); + } +} + +/* Relinquish all pool_alloced memory back to the pool. */ +static void +pool_reset (struct pool *pool) +{ + /* Transfer all used chunks to the chunk free list. */ + struct _pool_chunk *chunk = pool->current; + if (chunk != pool->sentinel) { + while (chunk->prev_chunk != pool->sentinel) { + chunk = chunk->prev_chunk; + } + chunk->prev_chunk = pool->first_free; + pool->first_free = pool->current; + } + /* Reset the sentinel as the current chunk. */ + pool->current = pool->sentinel; + pool->sentinel->size = 0; +} + +/* Rewinds the cell list's cursor to the beginning. After rewinding + * we're good to cell_list_find() the cell any x coordinate. */ +inline static void +cell_list_rewind (struct cell_list *cells) +{ + cells->cursor = &cells->head; +} + +/* Rewind the cell list if its cursor has been advanced past x. */ +inline static void +cell_list_maybe_rewind (struct cell_list *cells, int x) +{ + struct cell *tail = cells->cursor; + if (tail->x > x) + cell_list_rewind (cells); +} + +static void +cell_list_init(struct cell_list *cells, jmp_buf *jmp) +{ + pool_init(cells->cell_pool.base, jmp, + 256*sizeof(struct cell), + sizeof(cells->cell_pool.embedded)); + cells->tail.next = NULL; + cells->tail.x = INT_MAX; + cells->head.x = INT_MIN; + cells->head.next = &cells->tail; + cell_list_rewind (cells); +} + +static void +cell_list_fini(struct cell_list *cells) +{ + pool_fini (cells->cell_pool.base); +} + +/* Empty the cell list. This is called at the start of every pixel + * row. */ +inline static void +cell_list_reset (struct cell_list *cells) +{ + cell_list_rewind (cells); + cells->head.next = &cells->tail; + pool_reset (cells->cell_pool.base); +} + +static struct cell * +cell_list_alloc (struct cell_list *cells, + struct cell *tail, + int x) +{ + struct cell *cell; + + cell = pool_alloc (cells->cell_pool.base, sizeof (struct cell)); + cell->next = tail->next; + tail->next = cell; + cell->x = x; + cell->uncovered_area = 0; + cell->covered_height = 0; + cell->clipped_height = 0; + return cell; +} + +/* Find a cell at the given x-coordinate. Returns %NULL if a new cell + * needed to be allocated but couldn't be. Cells must be found with + * non-decreasing x-coordinate until the cell list is rewound using + * cell_list_rewind(). Ownership of the returned cell is retained by + * the cell list. */ +inline static struct cell * +cell_list_find (struct cell_list *cells, int x) +{ + struct cell *tail = cells->cursor; + + while (1) { + UNROLL3({ + if (tail->next->x > x) + break; + tail = tail->next; + }); + } + + if (tail->x != x) + tail = cell_list_alloc (cells, tail, x); + return cells->cursor = tail; + +} + +/* Find two cells at x1 and x2. This is exactly equivalent + * to + * + * pair.cell1 = cell_list_find(cells, x1); + * pair.cell2 = cell_list_find(cells, x2); + * + * except with less function call overhead. */ +inline static struct cell_pair +cell_list_find_pair(struct cell_list *cells, int x1, int x2) +{ + struct cell_pair pair; + + pair.cell1 = cells->cursor; + while (1) { + UNROLL3({ + if (pair.cell1->next->x > x1) + break; + pair.cell1 = pair.cell1->next; + }); + } + if (pair.cell1->x != x1) { + struct cell *cell = pool_alloc (cells->cell_pool.base, + sizeof (struct cell)); + cell->x = x1; + cell->uncovered_area = 0; + cell->covered_height = 0; + cell->clipped_height = 0; + cell->next = pair.cell1->next; + pair.cell1->next = cell; + pair.cell1 = cell; + } + + pair.cell2 = pair.cell1; + while (1) { + UNROLL3({ + if (pair.cell2->next->x > x2) + break; + pair.cell2 = pair.cell2->next; + }); + } + if (pair.cell2->x != x2) { + struct cell *cell = pool_alloc (cells->cell_pool.base, + sizeof (struct cell)); + cell->uncovered_area = 0; + cell->covered_height = 0; + cell->clipped_height = 0; + cell->x = x2; + cell->next = pair.cell2->next; + pair.cell2->next = cell; + pair.cell2 = cell; + } + + cells->cursor = pair.cell2; + return pair; +} + +/* Add a subpixel span covering [x1, x2) to the coverage cells. */ +inline static void +cell_list_add_subspan(struct cell_list *cells, + grid_scaled_x_t x1, + grid_scaled_x_t x2) +{ + int ix1, fx1; + int ix2, fx2; + + GRID_X_TO_INT_FRAC(x1, ix1, fx1); + GRID_X_TO_INT_FRAC(x2, ix2, fx2); + + if (ix1 != ix2) { + struct cell_pair p; + p = cell_list_find_pair(cells, ix1, ix2); + p.cell1->uncovered_area += 2*fx1; + ++p.cell1->covered_height; + p.cell2->uncovered_area -= 2*fx2; + --p.cell2->covered_height; + } else { + struct cell *cell = cell_list_find(cells, ix1); + cell->uncovered_area += 2*(fx1-fx2); + } +} + +/* Adds the analytical coverage of an edge crossing the current pixel + * row to the coverage cells and advances the edge's x position to the + * following row. + * + * This function is only called when we know that during this pixel row: + * + * 1) The relative order of all edges on the active list doesn't + * change. In particular, no edges intersect within this row to pixel + * precision. + * + * 2) No new edges start in this row. + * + * 3) No existing edges end mid-row. + * + * This function depends on being called with all edges from the + * active list in the order they appear on the list (i.e. with + * non-decreasing x-coordinate.) */ +static void +cell_list_render_edge( + struct cell_list *cells, + struct edge *edge, + int sign) +{ + grid_scaled_y_t y1, y2, dy; + grid_scaled_x_t dx; + int ix1, ix2; + grid_scaled_x_t fx1, fx2; + + struct quorem x1 = edge->x; + struct quorem x2 = x1; + + if (! edge->vertical) { + x2.quo += edge->dxdy_full.quo; + x2.rem += edge->dxdy_full.rem; + if (x2.rem >= 0) { + ++x2.quo; + x2.rem -= edge->dy; + } + + edge->x = x2; + } + + GRID_X_TO_INT_FRAC(x1.quo, ix1, fx1); + GRID_X_TO_INT_FRAC(x2.quo, ix2, fx2); + + /* Edge is entirely within a column? */ + if (ix1 == ix2) { + /* We always know that ix1 is >= the cell list cursor in this + * case due to the no-intersections precondition. */ + struct cell *cell = cell_list_find(cells, ix1); + cell->covered_height += sign*GRID_Y; + cell->uncovered_area += sign*(fx1 + fx2)*GRID_Y; + return; + } + + /* Orient the edge left-to-right. */ + dx = x2.quo - x1.quo; + if (dx >= 0) { + y1 = 0; + y2 = GRID_Y; + } else { + int tmp; + tmp = ix1; ix1 = ix2; ix2 = tmp; + tmp = fx1; fx1 = fx2; fx2 = tmp; + dx = -dx; + sign = -sign; + y1 = GRID_Y; + y2 = 0; + } + dy = y2 - y1; + + /* Add coverage for all pixels [ix1,ix2] on this row crossed + * by the edge. */ + { + struct cell_pair pair; + struct quorem y = floored_divrem((GRID_X - fx1)*dy, dx); + + /* When rendering a previous edge on the active list we may + * advance the cell list cursor past the leftmost pixel of the + * current edge even though the two edges don't intersect. + * e.g. consider two edges going down and rightwards: + * + * --\_+---\_+-----+-----+---- + * \_ \_ | | + * | \_ | \_ | | + * | \_| \_| | + * | \_ \_ | + * ----+-----+-\---+-\---+---- + * + * The left edge touches cells past the starting cell of the + * right edge. Fortunately such cases are rare. + * + * The rewinding is never necessary if the current edge stays + * within a single column because we've checked before calling + * this function that the active list order won't change. */ + cell_list_maybe_rewind(cells, ix1); + + pair = cell_list_find_pair(cells, ix1, ix1+1); + pair.cell1->uncovered_area += sign*y.quo*(GRID_X + fx1); + pair.cell1->covered_height += sign*y.quo; + y.quo += y1; + + if (ix1+1 < ix2) { + struct quorem dydx_full = floored_divrem(GRID_X*dy, dx); + struct cell *cell = pair.cell2; + + ++ix1; + do { + grid_scaled_y_t y_skip = dydx_full.quo; + y.rem += dydx_full.rem; + if (y.rem >= dx) { + ++y_skip; + y.rem -= dx; + } + + y.quo += y_skip; + + y_skip *= sign; + cell->uncovered_area += y_skip*GRID_X; + cell->covered_height += y_skip; + + ++ix1; + cell = cell_list_find(cells, ix1); + } while (ix1 != ix2); + + pair.cell2 = cell; + } + pair.cell2->uncovered_area += sign*(y2 - y.quo)*fx2; + pair.cell2->covered_height += sign*(y2 - y.quo); + } +} + +static void +polygon_init (struct polygon *polygon, jmp_buf *jmp) +{ + polygon->ymin = polygon->ymax = 0; + polygon->y_buckets = polygon->y_buckets_embedded; + pool_init (polygon->edge_pool.base, jmp, + 8192 - sizeof (struct _pool_chunk), + sizeof (polygon->edge_pool.embedded)); +} + +static void +polygon_fini (struct polygon *polygon) +{ + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + pool_fini (polygon->edge_pool.base); +} + +/* Empties the polygon of all edges. The polygon is then prepared to + * receive new edges and clip them to the vertical range + * [ymin,ymax). */ +static cairo_status_t +polygon_reset (struct polygon *polygon, + grid_scaled_y_t ymin, + grid_scaled_y_t ymax) +{ + unsigned h = ymax - ymin; + unsigned num_buckets = EDGE_Y_BUCKET_INDEX(ymax + EDGE_Y_BUCKET_HEIGHT-1, + ymin); + + pool_reset(polygon->edge_pool.base); + + if (unlikely (h > 0x7FFFFFFFU - EDGE_Y_BUCKET_HEIGHT)) + goto bail_no_mem; /* even if you could, you wouldn't want to. */ + + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + polygon->y_buckets = polygon->y_buckets_embedded; + if (num_buckets > ARRAY_LENGTH (polygon->y_buckets_embedded)) { + polygon->y_buckets = _cairo_malloc_ab (num_buckets, + sizeof (struct edge *)); + if (unlikely (NULL == polygon->y_buckets)) + goto bail_no_mem; + } + memset (polygon->y_buckets, 0, num_buckets * sizeof (struct edge *)); + + polygon->ymin = ymin; + polygon->ymax = ymax; + return CAIRO_STATUS_SUCCESS; + + bail_no_mem: + polygon->ymin = 0; + polygon->ymax = 0; + return CAIRO_STATUS_NO_MEMORY; +} + +static void +_polygon_insert_edge_into_its_y_bucket( + struct polygon *polygon, + struct edge *e) +{ + unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin); + struct edge **ptail = &polygon->y_buckets[ix]; + e->next = *ptail; + *ptail = e; +} + +inline static void +polygon_add_edge (struct polygon *polygon, + const cairo_edge_t *edge, + int clip) +{ + struct edge *e; + grid_scaled_x_t dx; + grid_scaled_y_t dy; + grid_scaled_y_t ytop, ybot; + grid_scaled_y_t ymin = polygon->ymin; + grid_scaled_y_t ymax = polygon->ymax; + + assert (edge->bottom > edge->top); + + if (unlikely (edge->top >= ymax || edge->bottom <= ymin)) + return; + + e = pool_alloc (polygon->edge_pool.base, sizeof (struct edge)); + + dx = edge->line.p2.x - edge->line.p1.x; + dy = edge->line.p2.y - edge->line.p1.y; + e->dy = dy; + e->dir = edge->dir; + e->clip = clip; + + ytop = edge->top >= ymin ? edge->top : ymin; + ybot = edge->bottom <= ymax ? edge->bottom : ymax; + e->ytop = ytop; + e->height_left = ybot - ytop; + + if (dx == 0) { + e->vertical = TRUE; + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + e->dxdy.quo = 0; + e->dxdy.rem = 0; + e->dxdy_full.quo = 0; + e->dxdy_full.rem = 0; + } else { + e->vertical = FALSE; + e->dxdy = floored_divrem (dx, dy); + if (ytop == edge->line.p1.y) { + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + } else { + e->x = floored_muldivrem (ytop - edge->line.p1.y, dx, dy); + e->x.quo += edge->line.p1.x; + } + + if (e->height_left >= GRID_Y) { + e->dxdy_full = floored_muldivrem (GRID_Y, dx, dy); + } else { + e->dxdy_full.quo = 0; + e->dxdy_full.rem = 0; + } + } + + _polygon_insert_edge_into_its_y_bucket (polygon, e); + + e->x.rem -= dy; /* Bias the remainder for faster + * edge advancement. */ +} + +static void +active_list_reset (struct active_list *active) +{ + active->head = NULL; + active->min_height = 0; +} + +static void +active_list_init(struct active_list *active) +{ + active_list_reset(active); +} + +/* + * Merge two sorted edge lists. + * Input: + * - head_a: The head of the first list. + * - head_b: The head of the second list; head_b cannot be NULL. + * Output: + * Returns the head of the merged list. + * + * Implementation notes: + * To make it fast (in particular, to reduce to an insertion sort whenever + * one of the two input lists only has a single element) we iterate through + * a list until its head becomes greater than the head of the other list, + * then we switch their roles. As soon as one of the two lists is empty, we + * just attach the other one to the current list and exit. + * Writes to memory are only needed to "switch" lists (as it also requires + * attaching to the output list the list which we will be iterating next) and + * to attach the last non-empty list. + */ +static struct edge * +merge_sorted_edges (struct edge *head_a, struct edge *head_b) +{ + struct edge *head, **next; + int32_t x; + + if (head_a == NULL) + return head_b; + + next = &head; + if (head_a->x.quo <= head_b->x.quo) { + head = head_a; + } else { + head = head_b; + goto start_with_b; + } + + do { + x = head_b->x.quo; + while (head_a != NULL && head_a->x.quo <= x) { + next = &head_a->next; + head_a = head_a->next; + } + + *next = head_b; + if (head_a == NULL) + return head; + +start_with_b: + x = head_a->x.quo; + while (head_b != NULL && head_b->x.quo <= x) { + next = &head_b->next; + head_b = head_b->next; + } + + *next = head_a; + if (head_b == NULL) + return head; + } while (1); +} + +/* + * Sort (part of) a list. + * Input: + * - list: The list to be sorted; list cannot be NULL. + * - limit: Recursion limit. + * Output: + * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the + * input list; if the input list has fewer elements, head_out be a sorted list + * containing all the elements of the input list. + * Returns the head of the list of unprocessed elements (NULL if the sorted list contains + * all the elements of the input list). + * + * Implementation notes: + * Special case single element list, unroll/inline the sorting of the first two elements. + * Some tail recursion is used since we iterate on the bottom-up solution of the problem + * (we start with a small sorted list and keep merging other lists of the same size to it). + */ +static struct edge * +sort_edges (struct edge *list, + unsigned int level, + struct edge **head_out) +{ + struct edge *head_other, *remaining; + unsigned int i; + + head_other = list->next; + + /* Single element list -> return */ + if (head_other == NULL) { + *head_out = list; + return NULL; + } + + /* Unroll the first iteration of the following loop (halves the number of calls to merge_sorted_edges): + * - Initialize remaining to be the list containing the elements after the second in the input list. + * - Initialize *head_out to be the sorted list containing the first two element. + */ + remaining = head_other->next; + if (list->x.quo <= head_other->x.quo) { + *head_out = list; + /* list->next = head_other; */ /* The input list is already like this. */ + head_other->next = NULL; + } else { + *head_out = head_other; + head_other->next = list; + list->next = NULL; + } + + for (i = 0; i < level && remaining; i++) { + /* Extract a sorted list of the same size as *head_out + * (2^(i+1) elements) from the list of remaining elements. */ + remaining = sort_edges (remaining, i, &head_other); + *head_out = merge_sorted_edges (*head_out, head_other); + } + + /* *head_out now contains (at most) 2^(level+1) elements. */ + + return remaining; +} + +/* Test if the edges on the active list can be safely advanced by a + * full row without intersections or any edges ending. */ +inline static int +active_list_can_step_full_row (struct active_list *active) +{ + const struct edge *e; + int prev_x = INT_MIN; + + /* Recomputes the minimum height of all edges on the active + * list if we have been dropping edges. */ + if (active->min_height <= 0) { + int min_height = INT_MAX; + + e = active->head; + while (NULL != e) { + if (e->height_left < min_height) + min_height = e->height_left; + e = e->next; + } + + active->min_height = min_height; + } + + if (active->min_height < GRID_Y) + return 0; + + /* Check for intersections as no edges end during the next row. */ + e = active->head; + while (NULL != e) { + struct quorem x = e->x; + + if (! e->vertical) { + x.quo += e->dxdy_full.quo; + x.rem += e->dxdy_full.rem; + if (x.rem >= 0) + ++x.quo; + } + + if (x.quo <= prev_x) + return 0; + + prev_x = x.quo; + e = e->next; + } + + return 1; +} + +/* Merges edges on the given subpixel row from the polygon to the + * active_list. */ +inline static void +active_list_merge_edges_from_polygon(struct active_list *active, + struct edge **ptail, + grid_scaled_y_t y, + struct polygon *polygon) +{ + /* Split off the edges on the current subrow and merge them into + * the active list. */ + int min_height = active->min_height; + struct edge *subrow_edges = NULL; + struct edge *tail = *ptail; + + do { + struct edge *next = tail->next; + + if (y == tail->ytop) { + tail->next = subrow_edges; + subrow_edges = tail; + + if (tail->height_left < min_height) + min_height = tail->height_left; + + *ptail = next; + } else + ptail = &tail->next; + + tail = next; + } while (tail); + + if (subrow_edges) { + sort_edges (subrow_edges, UINT_MAX, &subrow_edges); + active->head = merge_sorted_edges (active->head, subrow_edges); + active->min_height = min_height; + } +} + +/* Advance the edges on the active list by one subsample row by + * updating their x positions. Drop edges from the list that end. */ +inline static void +active_list_substep_edges(struct active_list *active) +{ + struct edge **cursor = &active->head; + grid_scaled_x_t prev_x = INT_MIN; + struct edge *unsorted = NULL; + struct edge *edge = *cursor; + + do { + UNROLL3({ + struct edge *next; + + if (NULL == edge) + break; + + next = edge->next; + if (--edge->height_left) { + edge->x.quo += edge->dxdy.quo; + edge->x.rem += edge->dxdy.rem; + if (edge->x.rem >= 0) { + ++edge->x.quo; + edge->x.rem -= edge->dy; + } + + if (edge->x.quo < prev_x) { + *cursor = next; + edge->next = unsorted; + unsorted = edge; + } else { + prev_x = edge->x.quo; + cursor = &edge->next; + } + } else { + *cursor = next; + } + edge = next; + }) + } while (1); + + if (unsorted) { + sort_edges (unsorted, UINT_MAX, &unsorted); + active->head = merge_sorted_edges (active->head, unsorted); + } +} + +inline static void +apply_nonzero_fill_rule_for_subrow (struct active_list *active, + struct cell_list *coverages) +{ + struct edge *edge = active->head; + int winding = 0; + int xstart; + int xend; + + cell_list_rewind (coverages); + + while (NULL != edge) { + xstart = edge->x.quo; + winding = edge->dir; + while (1) { + edge = edge->next; + if (NULL == edge) { + ASSERT_NOT_REACHED; + return; + } + + winding += edge->dir; + if (0 == winding) { + if (edge->next == NULL || edge->next->x.quo != edge->x.quo) + break; + } + } + + xend = edge->x.quo; + cell_list_add_subspan (coverages, xstart, xend); + + edge = edge->next; + } +} + +static void +apply_evenodd_fill_rule_for_subrow (struct active_list *active, + struct cell_list *coverages) +{ + struct edge *edge = active->head; + int xstart; + int xend; + + cell_list_rewind (coverages); + + while (NULL != edge) { + xstart = edge->x.quo; + + while (1) { + edge = edge->next; + if (NULL == edge) { + ASSERT_NOT_REACHED; + return; + } + + if (edge->next == NULL || edge->next->x.quo != edge->x.quo) + break; + + edge = edge->next; + } + + xend = edge->x.quo; + cell_list_add_subspan (coverages, xstart, xend); + + edge = edge->next; + } +} + +static void +apply_nonzero_fill_rule_and_step_edges (struct active_list *active, + struct cell_list *coverages) +{ + struct edge **cursor = &active->head; + struct edge *left_edge; + + left_edge = *cursor; + while (NULL != left_edge) { + struct edge *right_edge; + int winding = left_edge->dir; + + left_edge->height_left -= GRID_Y; + if (left_edge->height_left) + cursor = &left_edge->next; + else + *cursor = left_edge->next; + + while (1) { + right_edge = *cursor; + if (NULL == right_edge) { + cell_list_render_edge (coverages, left_edge, +1); + return; + } + + right_edge->height_left -= GRID_Y; + if (right_edge->height_left) + cursor = &right_edge->next; + else + *cursor = right_edge->next; + + winding += right_edge->dir; + if (0 == winding) { + if (right_edge->next == NULL || + right_edge->next->x.quo != right_edge->x.quo) + { + break; + } + } + + if (! right_edge->vertical) { + right_edge->x.quo += right_edge->dxdy_full.quo; + right_edge->x.rem += right_edge->dxdy_full.rem; + if (right_edge->x.rem >= 0) { + ++right_edge->x.quo; + right_edge->x.rem -= right_edge->dy; + } + } + } + + cell_list_render_edge (coverages, left_edge, +1); + cell_list_render_edge (coverages, right_edge, -1); + + left_edge = *cursor; + } +} + +static void +apply_evenodd_fill_rule_and_step_edges (struct active_list *active, + struct cell_list *coverages) +{ + struct edge **cursor = &active->head; + struct edge *left_edge; + + left_edge = *cursor; + while (NULL != left_edge) { + struct edge *right_edge; + + left_edge->height_left -= GRID_Y; + if (left_edge->height_left) + cursor = &left_edge->next; + else + *cursor = left_edge->next; + + while (1) { + right_edge = *cursor; + if (NULL == right_edge) { + cell_list_render_edge (coverages, left_edge, +1); + return; + } + + right_edge->height_left -= GRID_Y; + if (right_edge->height_left) + cursor = &right_edge->next; + else + *cursor = right_edge->next; + + if (right_edge->next == NULL || + right_edge->next->x.quo != right_edge->x.quo) + { + break; + } + + if (! right_edge->vertical) { + right_edge->x.quo += right_edge->dxdy_full.quo; + right_edge->x.rem += right_edge->dxdy_full.rem; + if (right_edge->x.rem >= 0) { + ++right_edge->x.quo; + right_edge->x.rem -= right_edge->dy; + } + } + } + + cell_list_render_edge (coverages, left_edge, +1); + cell_list_render_edge (coverages, right_edge, -1); + + left_edge = *cursor; + } +} + +static void +_glitter_scan_converter_init(glitter_scan_converter_t *converter, jmp_buf *jmp) +{ + polygon_init(converter->polygon, jmp); + active_list_init(converter->active); + cell_list_init(converter->coverages, jmp); + converter->ymin=0; + converter->ymax=0; +} + +static void +_glitter_scan_converter_fini(glitter_scan_converter_t *converter) +{ + polygon_fini(converter->polygon); + cell_list_fini(converter->coverages); + converter->ymin=0; + converter->ymax=0; +} + +static grid_scaled_t +int_to_grid_scaled(int i, int scale) +{ + /* Clamp to max/min representable scaled number. */ + if (i >= 0) { + if (i >= INT_MAX/scale) + i = INT_MAX/scale; + } + else { + if (i <= INT_MIN/scale) + i = INT_MIN/scale; + } + return i*scale; +} + +#define int_to_grid_scaled_x(x) int_to_grid_scaled((x), GRID_X) +#define int_to_grid_scaled_y(x) int_to_grid_scaled((x), GRID_Y) + +static cairo_status_t +glitter_scan_converter_reset(glitter_scan_converter_t *converter, + int ymin, int ymax) +{ + cairo_status_t status; + + converter->ymin = 0; + converter->ymax = 0; + + ymin = int_to_grid_scaled_y(ymin); + ymax = int_to_grid_scaled_y(ymax); + + active_list_reset(converter->active); + cell_list_reset(converter->coverages); + status = polygon_reset(converter->polygon, ymin, ymax); + if (status) + return status; + + converter->ymin = ymin; + converter->ymax = ymax; + return CAIRO_STATUS_SUCCESS; +} + +/* INPUT_TO_GRID_X/Y (in_coord, out_grid_scaled, grid_scale) + * These macros convert an input coordinate in the client's + * device space to the rasterisation grid. + */ +/* Gah.. this bit of ugly defines INPUT_TO_GRID_X/Y so as to use + * shifts if possible, and something saneish if not. + */ +#if !defined(INPUT_TO_GRID_Y) && defined(GRID_Y_BITS) && GRID_Y_BITS <= GLITTER_INPUT_BITS +# define INPUT_TO_GRID_Y(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_Y_BITS) +#else +# define INPUT_TO_GRID_Y(in, out) INPUT_TO_GRID_general(in, out, GRID_Y) +#endif + +#if !defined(INPUT_TO_GRID_X) && defined(GRID_X_BITS) && GRID_X_BITS <= GLITTER_INPUT_BITS +# define INPUT_TO_GRID_X(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_X_BITS) +#else +# define INPUT_TO_GRID_X(in, out) INPUT_TO_GRID_general(in, out, GRID_X) +#endif + +#define INPUT_TO_GRID_general(in, out, grid_scale) do { \ + long long tmp__ = (long long)(grid_scale) * (in); \ + tmp__ >>= GLITTER_INPUT_BITS; \ + (out) = tmp__; \ +} while (0) + +static void +glitter_scan_converter_add_edge (glitter_scan_converter_t *converter, + const cairo_edge_t *edge, + int clip) +{ + cairo_edge_t e; + + INPUT_TO_GRID_Y (edge->top, e.top); + INPUT_TO_GRID_Y (edge->bottom, e.bottom); + if (e.top >= e.bottom) + return; + + /* XXX: possible overflows if GRID_X/Y > 2**GLITTER_INPUT_BITS */ + INPUT_TO_GRID_Y (edge->line.p1.y, e.line.p1.y); + INPUT_TO_GRID_Y (edge->line.p2.y, e.line.p2.y); + if (e.line.p1.y == e.line.p2.y) + return; + + INPUT_TO_GRID_X (edge->line.p1.x, e.line.p1.x); + INPUT_TO_GRID_X (edge->line.p2.x, e.line.p2.x); + + e.dir = edge->dir; + + polygon_add_edge (converter->polygon, &e, clip); +} + +static cairo_bool_t +active_list_is_vertical (struct active_list *active) +{ + struct edge *e; + + for (e = active->head; e != NULL; e = e->next) { + if (! e->vertical) + return FALSE; + } + + return TRUE; +} + +static void +step_edges (struct active_list *active, int count) +{ + struct edge **cursor = &active->head; + struct edge *edge; + + for (edge = *cursor; edge != NULL; edge = *cursor) { + edge->height_left -= GRID_Y * count; + if (edge->height_left) + cursor = &edge->next; + else + *cursor = edge->next; + } +} + +static cairo_status_t +blit_coverages (struct cell_list *cells, + cairo_span_renderer_t *renderer, + struct pool *span_pool, + int y, int height) +{ + struct cell *cell = cells->head.next; + int prev_x = -1; + int cover = 0, last_cover = 0; + int clip = 0; + cairo_half_open_span_t *spans; + unsigned num_spans; + + assert (cell != &cells->tail); + + /* Count number of cells remaining. */ + { + struct cell *next = cell; + num_spans = 2; + while (next->next) { + next = next->next; + ++num_spans; + } + num_spans = 2*num_spans; + } + + /* Allocate enough spans for the row. */ + pool_reset (span_pool); + spans = pool_alloc (span_pool, sizeof(spans[0])*num_spans); + num_spans = 0; + + /* Form the spans from the coverages and areas. */ + for (; cell->next; cell = cell->next) { + int x = cell->x; + int area; + + if (x > prev_x && cover != last_cover) { + spans[num_spans].x = prev_x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); + spans[num_spans].inverse = 0; + last_cover = cover; + ++num_spans; + } + + cover += cell->covered_height*GRID_X*2; + clip += cell->covered_height*GRID_X*2; + area = cover - cell->uncovered_area; + + if (area != last_cover) { + spans[num_spans].x = x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (area); + spans[num_spans].inverse = 0; + last_cover = area; + ++num_spans; + } + + prev_x = x+1; + } + + /* Dump them into the renderer. */ + return renderer->render_rows (renderer, y, height, spans, num_spans); +} + +static void +glitter_scan_converter_render(glitter_scan_converter_t *converter, + int nonzero_fill, + cairo_span_renderer_t *span_renderer, + struct pool *span_pool) +{ + int i, j; + int ymax_i = converter->ymax / GRID_Y; + int ymin_i = converter->ymin / GRID_Y; + int h = ymax_i - ymin_i; + struct polygon *polygon = converter->polygon; + struct cell_list *coverages = converter->coverages; + struct active_list *active = converter->active; + + /* Render each pixel row. */ + for (i = 0; i < h; i = j) { + int do_full_step = 0; + + j = i + 1; + + /* Determine if we can ignore this row or use the full pixel + * stepper. */ + if (GRID_Y == EDGE_Y_BUCKET_HEIGHT && ! polygon->y_buckets[i]) { + if (! active->head) { + for (; j < h && ! polygon->y_buckets[j]; j++) + ; + continue; + } + + do_full_step = active_list_can_step_full_row (active); + } + + if (do_full_step) { + /* Step by a full pixel row's worth. */ + if (nonzero_fill) + apply_nonzero_fill_rule_and_step_edges (active, coverages); + else + apply_evenodd_fill_rule_and_step_edges (active, coverages); + + if (active_list_is_vertical (active)) { + while (j < h && + polygon->y_buckets[j] == NULL && + active->min_height >= 2*GRID_Y) + { + active->min_height -= GRID_Y; + j++; + } + if (j != i + 1) + step_edges (active, j - (i + 1)); + } + } else { + grid_scaled_y_t suby; + + /* Subsample this row. */ + for (suby = 0; suby < GRID_Y; suby++) { + grid_scaled_y_t y = (i+ymin_i)*GRID_Y + suby; + + if (polygon->y_buckets[i]) { + active_list_merge_edges_from_polygon (active, + &polygon->y_buckets[i], y, + polygon); + } + + if (nonzero_fill) + apply_nonzero_fill_rule_for_subrow (active, coverages); + else + apply_evenodd_fill_rule_for_subrow (active, coverages); + + active_list_substep_edges(active); + } + } + + blit_coverages (coverages, span_renderer, span_pool, i+ymin_i, j -i); + cell_list_reset (coverages); + + if (! active->head) + active->min_height = INT_MAX; + else + active->min_height -= GRID_Y; + } +} + +struct _cairo_clip_tor_scan_converter { + cairo_scan_converter_t base; + + glitter_scan_converter_t converter[1]; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + + cairo_fill_rule_t clip_fill_rule; + cairo_antialias_t clip_antialias; + + jmp_buf jmp; + + struct { + struct pool base[1]; + cairo_half_open_span_t embedded[32]; + } span_pool; +}; + +typedef struct _cairo_clip_tor_scan_converter cairo_clip_tor_scan_converter_t; + +static void +_cairo_clip_tor_scan_converter_destroy (void *converter) +{ + cairo_clip_tor_scan_converter_t *self = converter; + if (self == NULL) { + return; + } + _glitter_scan_converter_fini (self->converter); + pool_fini (self->span_pool.base); + free(self); +} + +static cairo_status_t +_cairo_clip_tor_scan_converter_generate (void *converter, + cairo_span_renderer_t *renderer) +{ + cairo_clip_tor_scan_converter_t *self = converter; + cairo_status_t status; + + if ((status = setjmp (self->jmp))) + return _cairo_scan_converter_set_error (self, _cairo_error (status)); + + glitter_scan_converter_render (self->converter, + self->fill_rule == CAIRO_FILL_RULE_WINDING, + renderer, + self->span_pool.base); + return CAIRO_STATUS_SUCCESS; +} + +cairo_scan_converter_t * +_cairo_clip_tor_scan_converter_create (cairo_clip_t *clip, + cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias) +{ + cairo_clip_tor_scan_converter_t *self; + cairo_polygon_t clipper; + cairo_status_t status; + int i; + + self = calloc (1, sizeof(struct _cairo_clip_tor_scan_converter)); + if (unlikely (self == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto bail_nomem; + } + + self->base.destroy = _cairo_clip_tor_scan_converter_destroy; + self->base.generate = _cairo_clip_tor_scan_converter_generate; + + pool_init (self->span_pool.base, &self->jmp, + 250 * sizeof(self->span_pool.embedded[0]), + sizeof(self->span_pool.embedded)); + + _glitter_scan_converter_init (self->converter, &self->jmp); + status = glitter_scan_converter_reset (self->converter, + clip->extents.y, + clip->extents.y + clip->extents.height); + if (unlikely (status)) + goto bail; + + self->fill_rule = fill_rule; + self->antialias = antialias; + + for (i = 0; i < polygon->num_edges; i++) + glitter_scan_converter_add_edge (self->converter, + &polygon->edges[i], + FALSE); + + status = _cairo_clip_get_polygon (clip, + &clipper, + &self->clip_fill_rule, + &self->clip_antialias); + if (unlikely (status)) + goto bail; + + for (i = 0; i < clipper.num_edges; i++) + glitter_scan_converter_add_edge (self->converter, + &clipper.edges[i], + TRUE); + _cairo_polygon_fini (&clipper); + + return &self->base; + + bail: + self->base.destroy(&self->base); + bail_nomem: + return _cairo_scan_converter_create_in_error (status); +} + diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-clip.c b/Build/source/libs/cairo/cairo-src/src/cairo-clip.c new file mode 100644 index 00000000000..0df9b06bf60 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-clip.c @@ -0,0 +1,838 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-gstate-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-pattern-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-region-private.h" + +static freed_pool_t clip_path_pool; +static freed_pool_t clip_pool; + +const cairo_clip_t __cairo_clip_all; + +static cairo_clip_path_t * +_cairo_clip_path_create (cairo_clip_t *clip) +{ + cairo_clip_path_t *clip_path; + + clip_path = _freed_pool_get (&clip_path_pool); + if (unlikely (clip_path == NULL)) { + clip_path = malloc (sizeof (cairo_clip_path_t)); + if (unlikely (clip_path == NULL)) + return NULL; + } + + CAIRO_REFERENCE_COUNT_INIT (&clip_path->ref_count, 1); + + clip_path->prev = clip->path; + clip->path = clip_path; + + return clip_path; +} + +cairo_clip_path_t * +_cairo_clip_path_reference (cairo_clip_path_t *clip_path) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&clip_path->ref_count)); + + _cairo_reference_count_inc (&clip_path->ref_count); + + return clip_path; +} + +void +_cairo_clip_path_destroy (cairo_clip_path_t *clip_path) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&clip_path->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&clip_path->ref_count)) + return; + + _cairo_path_fixed_fini (&clip_path->path); + + if (clip_path->prev != NULL) + _cairo_clip_path_destroy (clip_path->prev); + + _freed_pool_put (&clip_path_pool, clip_path); +} + +cairo_clip_t * +_cairo_clip_create (void) +{ + cairo_clip_t *clip; + + clip = _freed_pool_get (&clip_pool); + if (unlikely (clip == NULL)) { + clip = malloc (sizeof (cairo_clip_t)); + if (unlikely (clip == NULL)) + return NULL; + } + + clip->extents = _cairo_unbounded_rectangle; + + clip->path = NULL; + clip->boxes = NULL; + clip->num_boxes = 0; + clip->region = NULL; + clip->is_region = FALSE; + + return clip; +} + +void +_cairo_clip_destroy (cairo_clip_t *clip) +{ + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return; + + if (clip->path != NULL) + _cairo_clip_path_destroy (clip->path); + + if (clip->boxes != &clip->embedded_box) + free (clip->boxes); + cairo_region_destroy (clip->region); + + _freed_pool_put (&clip_pool, clip); +} + +cairo_clip_t * +_cairo_clip_copy (const cairo_clip_t *clip) +{ + cairo_clip_t *copy; + + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return (cairo_clip_t *) clip; + + copy = _cairo_clip_create (); + + if (clip->path) + copy->path = _cairo_clip_path_reference (clip->path); + + if (clip->num_boxes) { + if (clip->num_boxes == 1) { + copy->boxes = ©->embedded_box; + } else { + copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t)); + if (unlikely (copy->boxes == NULL)) + return _cairo_clip_set_all_clipped (copy); + } + + memcpy (copy->boxes, clip->boxes, + clip->num_boxes * sizeof (cairo_box_t)); + copy->num_boxes = clip->num_boxes; + } + + copy->extents = clip->extents; + copy->region = cairo_region_reference (clip->region); + copy->is_region = clip->is_region; + + return copy; +} + +cairo_clip_t * +_cairo_clip_copy_path (const cairo_clip_t *clip) +{ + cairo_clip_t *copy; + + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return (cairo_clip_t *) clip; + + assert (clip->num_boxes); + + copy = _cairo_clip_create (); + copy->extents = clip->extents; + if (clip->path) + copy->path = _cairo_clip_path_reference (clip->path); + + return copy; +} + +cairo_clip_t * +_cairo_clip_copy_region (const cairo_clip_t *clip) +{ + cairo_clip_t *copy; + int i; + + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return (cairo_clip_t *) clip; + + assert (clip->num_boxes); + + copy = _cairo_clip_create (); + copy->extents = clip->extents; + + if (clip->num_boxes == 1) { + copy->boxes = ©->embedded_box; + } else { + copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t)); + if (unlikely (copy->boxes == NULL)) + return _cairo_clip_set_all_clipped (copy); + } + + for (i = 0; i < clip->num_boxes; i++) { + copy->boxes[i].p1.x = _cairo_fixed_floor (clip->boxes[i].p1.x); + copy->boxes[i].p1.y = _cairo_fixed_floor (clip->boxes[i].p1.y); + copy->boxes[i].p2.x = _cairo_fixed_ceil (clip->boxes[i].p2.x); + copy->boxes[i].p2.y = _cairo_fixed_ceil (clip->boxes[i].p2.y); + } + copy->num_boxes = clip->num_boxes; + + copy->region = cairo_region_reference (clip->region); + copy->is_region = TRUE; + + return copy; +} + +cairo_clip_t * +_cairo_clip_intersect_path (cairo_clip_t *clip, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_clip_path_t *clip_path; + cairo_status_t status; + cairo_rectangle_int_t extents; + cairo_box_t box; + + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + /* catch the empty clip path */ + if (_cairo_path_fixed_fill_is_empty (path)) + return _cairo_clip_set_all_clipped (clip); + + if (_cairo_path_fixed_is_box (path, &box)) { + if (antialias == CAIRO_ANTIALIAS_NONE) { + box.p1.x = _cairo_fixed_round_down (box.p1.x); + box.p1.y = _cairo_fixed_round_down (box.p1.y); + box.p2.x = _cairo_fixed_round_down (box.p2.x); + box.p2.y = _cairo_fixed_round_down (box.p2.y); + } + + return _cairo_clip_intersect_box (clip, &box); + } + if (_cairo_path_fixed_fill_is_rectilinear (path)) + return _cairo_clip_intersect_rectilinear_path (clip, path, + fill_rule, antialias); + + _cairo_path_fixed_approximate_clip_extents (path, &extents); + if (extents.width == 0 || extents.height == 0) + return _cairo_clip_set_all_clipped (clip); + + clip = _cairo_clip_intersect_rectangle (clip, &extents); + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + clip_path = _cairo_clip_path_create (clip); + if (unlikely (clip_path == NULL)) + return _cairo_clip_set_all_clipped (clip); + + status = _cairo_path_fixed_init_copy (&clip_path->path, path); + if (unlikely (status)) + return _cairo_clip_set_all_clipped (clip); + + clip_path->fill_rule = fill_rule; + clip_path->tolerance = tolerance; + clip_path->antialias = antialias; + + if (clip->region) { + cairo_region_destroy (clip->region); + clip->region = NULL; + } + + clip->is_region = FALSE; + return clip; +} + +static cairo_clip_t * +_cairo_clip_intersect_clip_path (cairo_clip_t *clip, + const cairo_clip_path_t *clip_path) +{ + if (clip_path->prev) + clip = _cairo_clip_intersect_clip_path (clip, clip_path->prev); + + return _cairo_clip_intersect_path (clip, + &clip_path->path, + clip_path->fill_rule, + clip_path->tolerance, + clip_path->antialias); +} + +cairo_clip_t * +_cairo_clip_intersect_clip (cairo_clip_t *clip, + const cairo_clip_t *other) +{ + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + if (other == NULL) + return clip; + + if (clip == NULL) + return _cairo_clip_copy (other); + + if (_cairo_clip_is_all_clipped (other)) + return _cairo_clip_set_all_clipped (clip); + + if (! _cairo_rectangle_intersect (&clip->extents, &other->extents)) + return _cairo_clip_set_all_clipped (clip); + + if (other->num_boxes) { + cairo_boxes_t boxes; + + _cairo_boxes_init_for_array (&boxes, other->boxes, other->num_boxes); + clip = _cairo_clip_intersect_boxes (clip, &boxes); + } + + if (! _cairo_clip_is_all_clipped (clip)) { + if (other->path) { + if (clip->path == NULL) + clip->path = _cairo_clip_path_reference (other->path); + else + clip = _cairo_clip_intersect_clip_path (clip, other->path); + } + } + + if (clip->region) { + cairo_region_destroy (clip->region); + clip->region = NULL; + } + clip->is_region = FALSE; + + return clip; +} + +cairo_bool_t +_cairo_clip_equal (const cairo_clip_t *clip_a, + const cairo_clip_t *clip_b) +{ + const cairo_clip_path_t *cp_a, *cp_b; + + /* are both all-clipped or no-clip? */ + if (clip_a == clip_b) + return TRUE; + + /* or just one of them? */ + if (clip_a == NULL || clip_b == NULL || + _cairo_clip_is_all_clipped (clip_a) || + _cairo_clip_is_all_clipped (clip_b)) + { + return FALSE; + } + + /* We have a pair of normal clips, check their contents */ + + if (clip_a->num_boxes != clip_b->num_boxes) + return FALSE; + + if (memcmp (clip_a->boxes, clip_b->boxes, + sizeof (cairo_box_t) * clip_a->num_boxes)) + return FALSE; + + cp_a = clip_a->path; + cp_b = clip_b->path; + while (cp_a && cp_b) { + if (cp_a == cp_b) + return TRUE; + + /* XXX compare reduced polygons? */ + + if (cp_a->antialias != cp_b->antialias) + return FALSE; + + if (cp_a->tolerance != cp_b->tolerance) + return FALSE; + + if (cp_a->fill_rule != cp_b->fill_rule) + return FALSE; + + if (! _cairo_path_fixed_equal (&cp_a->path, + &cp_b->path)) + return FALSE; + + cp_a = cp_a->prev; + cp_b = cp_b->prev; + } + + return cp_a == NULL && cp_b == NULL; +} + +static cairo_clip_t * +_cairo_clip_path_copy_with_translation (cairo_clip_t *clip, + cairo_clip_path_t *other_path, + int fx, int fy) +{ + cairo_status_t status; + cairo_clip_path_t *clip_path; + + if (other_path->prev != NULL) + clip = _cairo_clip_path_copy_with_translation (clip, other_path->prev, + fx, fy); + if (_cairo_clip_is_all_clipped (clip)) + return clip; + + clip_path = _cairo_clip_path_create (clip); + if (unlikely (clip_path == NULL)) + return _cairo_clip_set_all_clipped (clip); + + status = _cairo_path_fixed_init_copy (&clip_path->path, + &other_path->path); + if (unlikely (status)) + return _cairo_clip_set_all_clipped (clip); + + _cairo_path_fixed_translate (&clip_path->path, fx, fy); + + clip_path->fill_rule = other_path->fill_rule; + clip_path->tolerance = other_path->tolerance; + clip_path->antialias = other_path->antialias; + + return clip; +} + +cairo_clip_t * +_cairo_clip_translate (cairo_clip_t *clip, int tx, int ty) +{ + int fx, fy, i; + cairo_clip_path_t *clip_path; + + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return clip; + + if (tx == 0 && ty == 0) + return clip; + + fx = _cairo_fixed_from_int (tx); + fy = _cairo_fixed_from_int (ty); + + for (i = 0; i < clip->num_boxes; i++) { + clip->boxes[i].p1.x += fx; + clip->boxes[i].p2.x += fx; + clip->boxes[i].p1.y += fy; + clip->boxes[i].p2.y += fy; + } + + clip->extents.x += tx; + clip->extents.y += ty; + + if (clip->path == NULL) + return clip; + + clip_path = clip->path; + clip->path = NULL; + clip = _cairo_clip_path_copy_with_translation (clip, clip_path, fx, fy); + _cairo_clip_path_destroy (clip_path); + + return clip; +} + +static cairo_status_t +_cairo_path_fixed_add_box (cairo_path_fixed_t *path, + const cairo_box_t *box) +{ + cairo_status_t status; + + status = _cairo_path_fixed_move_to (path, box->p1.x, box->p1.y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p2.x, box->p1.y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p2.x, box->p2.y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p1.x, box->p2.y); + if (unlikely (status)) + return status; + + return _cairo_path_fixed_close_path (path); +} + +static cairo_status_t +_cairo_path_fixed_init_from_boxes (cairo_path_fixed_t *path, + const cairo_boxes_t *boxes) +{ + cairo_status_t status; + const struct _cairo_boxes_chunk *chunk; + int i; + + _cairo_path_fixed_init (path); + if (boxes->num_boxes == 0) + return CAIRO_STATUS_SUCCESS; + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + status = _cairo_path_fixed_add_box (path, &chunk->base[i]); + if (unlikely (status)) { + _cairo_path_fixed_fini (path); + return status; + } + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_clip_t * +_cairo_clip_intersect_clip_path_transformed (cairo_clip_t *clip, + const cairo_clip_path_t *clip_path, + const cairo_matrix_t *m) +{ + cairo_path_fixed_t path; + + if (clip_path->prev) + clip = _cairo_clip_intersect_clip_path_transformed (clip, + clip_path->prev, + m); + + if (_cairo_path_fixed_init_copy (&path, &clip_path->path)) + return _cairo_clip_set_all_clipped (clip); + + _cairo_path_fixed_transform (&path, m); + + clip = _cairo_clip_intersect_path (clip, + &path, + clip_path->fill_rule, + clip_path->tolerance, + clip_path->antialias); + _cairo_path_fixed_fini (&path); + + return clip; +} + +cairo_clip_t * +_cairo_clip_transform (cairo_clip_t *clip, const cairo_matrix_t *m) +{ + cairo_clip_t *copy; + + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return clip; + + if (_cairo_matrix_is_translation (m)) + return _cairo_clip_translate (clip, m->x0, m->y0); + + copy = _cairo_clip_create (); + + if (clip->num_boxes) { + cairo_path_fixed_t path; + cairo_boxes_t boxes; + + _cairo_boxes_init_for_array (&boxes, clip->boxes, clip->num_boxes); + _cairo_path_fixed_init_from_boxes (&path, &boxes); + _cairo_path_fixed_transform (&path, m); + + copy = _cairo_clip_intersect_path (copy, &path, + CAIRO_FILL_RULE_WINDING, + 0.1, + CAIRO_ANTIALIAS_DEFAULT); + + _cairo_path_fixed_fini (&path); + } + + if (clip->path) + copy = _cairo_clip_intersect_clip_path_transformed (copy, clip->path,m); + + _cairo_clip_destroy (clip); + return copy; +} + +cairo_clip_t * +_cairo_clip_copy_with_translation (const cairo_clip_t *clip, int tx, int ty) +{ + cairo_clip_t *copy; + int fx, fy, i; + + if (clip == NULL || _cairo_clip_is_all_clipped (clip)) + return (cairo_clip_t *)clip; + + if (tx == 0 && ty == 0) + return _cairo_clip_copy (clip); + + copy = _cairo_clip_create (); + if (copy == NULL) + return _cairo_clip_set_all_clipped (copy); + + fx = _cairo_fixed_from_int (tx); + fy = _cairo_fixed_from_int (ty); + + if (clip->num_boxes) { + if (clip->num_boxes == 1) { + copy->boxes = ©->embedded_box; + } else { + copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t)); + if (unlikely (copy->boxes == NULL)) + return _cairo_clip_set_all_clipped (copy); + } + + for (i = 0; i < clip->num_boxes; i++) { + copy->boxes[i].p1.x = clip->boxes[i].p1.x + fx; + copy->boxes[i].p2.x = clip->boxes[i].p2.x + fx; + copy->boxes[i].p1.y = clip->boxes[i].p1.y + fy; + copy->boxes[i].p2.y = clip->boxes[i].p2.y + fy; + } + copy->num_boxes = clip->num_boxes; + } + + copy->extents = clip->extents; + copy->extents.x += tx; + copy->extents.y += ty; + + if (clip->path == NULL) + return copy; + + return _cairo_clip_path_copy_with_translation (copy, clip->path, fx, fy); +} + +cairo_bool_t +_cairo_clip_contains_extents (const cairo_clip_t *clip, + const cairo_composite_rectangles_t *extents) +{ + const cairo_rectangle_int_t *rect; + + rect = extents->is_bounded ? &extents->bounded : &extents->unbounded; + return _cairo_clip_contains_rectangle (clip, rect); +} + +void +_cairo_debug_print_clip (FILE *stream, const cairo_clip_t *clip) +{ + int i; + + if (clip == NULL) { + fprintf (stream, "no clip\n"); + return; + } + + if (_cairo_clip_is_all_clipped (clip)) { + fprintf (stream, "clip: all-clipped\n"); + return; + } + + fprintf (stream, "clip:\n"); + fprintf (stream, " extents: (%d, %d) x (%d, %d), is-region? %d", + clip->extents.x, clip->extents.y, + clip->extents.width, clip->extents.height, + clip->is_region); + + fprintf (stream, " num_boxes = %d\n", clip->num_boxes); + for (i = 0; i < clip->num_boxes; i++) { + fprintf (stream, " [%d] = (%f, %f), (%f, %f)\n", i, + _cairo_fixed_to_double (clip->boxes[i].p1.x), + _cairo_fixed_to_double (clip->boxes[i].p1.y), + _cairo_fixed_to_double (clip->boxes[i].p2.x), + _cairo_fixed_to_double (clip->boxes[i].p2.y)); + } + + if (clip->path) { + cairo_clip_path_t *clip_path = clip->path; + do { + fprintf (stream, "path: aa=%d, tolerance=%f, rule=%d: ", + clip_path->antialias, + clip_path->tolerance, + clip_path->fill_rule); + _cairo_debug_print_path (stream, &clip_path->path); + fprintf (stream, "\n"); + } while ((clip_path = clip_path->prev) != NULL); + } +} + +const cairo_rectangle_int_t * +_cairo_clip_get_extents (const cairo_clip_t *clip) +{ + if (clip == NULL) + return &_cairo_unbounded_rectangle; + + if (_cairo_clip_is_all_clipped (clip)) + return &_cairo_empty_rectangle; + + return &clip->extents; +} + +const cairo_rectangle_list_t _cairo_rectangles_nil = + { CAIRO_STATUS_NO_MEMORY, NULL, 0 }; +static const cairo_rectangle_list_t _cairo_rectangles_not_representable = + { CAIRO_STATUS_CLIP_NOT_REPRESENTABLE, NULL, 0 }; + +static cairo_bool_t +_cairo_clip_int_rect_to_user (cairo_gstate_t *gstate, + cairo_rectangle_int_t *clip_rect, + cairo_rectangle_t *user_rect) +{ + cairo_bool_t is_tight; + + double x1 = clip_rect->x; + double y1 = clip_rect->y; + double x2 = clip_rect->x + (int) clip_rect->width; + double y2 = clip_rect->y + (int) clip_rect->height; + + _cairo_gstate_backend_to_user_rectangle (gstate, + &x1, &y1, &x2, &y2, + &is_tight); + + user_rect->x = x1; + user_rect->y = y1; + user_rect->width = x2 - x1; + user_rect->height = y2 - y1; + + return is_tight; +} + +cairo_rectangle_list_t * +_cairo_rectangle_list_create_in_error (cairo_status_t status) +{ + cairo_rectangle_list_t *list; + + if (status == CAIRO_STATUS_NO_MEMORY) + return (cairo_rectangle_list_t*) &_cairo_rectangles_nil; + if (status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) + return (cairo_rectangle_list_t*) &_cairo_rectangles_not_representable; + + list = malloc (sizeof (*list)); + if (unlikely (list == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return (cairo_rectangle_list_t*) &_cairo_rectangles_nil; + } + + list->status = status; + list->rectangles = NULL; + list->num_rectangles = 0; + + return list; +} + +cairo_rectangle_list_t * +_cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate) +{ +#define ERROR_LIST(S) _cairo_rectangle_list_create_in_error (_cairo_error (S)) + + cairo_rectangle_list_t *list; + cairo_rectangle_t *rectangles = NULL; + cairo_region_t *region = NULL; + int n_rects = 0; + int i; + + if (clip == NULL) + return ERROR_LIST (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE); + + if (_cairo_clip_is_all_clipped (clip)) + goto DONE; + + if (! _cairo_clip_is_region (clip)) + return ERROR_LIST (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE); + + region = _cairo_clip_get_region (clip); + if (region == NULL) + return ERROR_LIST (CAIRO_STATUS_NO_MEMORY); + + n_rects = cairo_region_num_rectangles (region); + if (n_rects) { + rectangles = _cairo_malloc_ab (n_rects, sizeof (cairo_rectangle_t)); + if (unlikely (rectangles == NULL)) { + return ERROR_LIST (CAIRO_STATUS_NO_MEMORY); + } + + for (i = 0; i < n_rects; ++i) { + cairo_rectangle_int_t clip_rect; + + cairo_region_get_rectangle (region, i, &clip_rect); + + if (! _cairo_clip_int_rect_to_user (gstate, + &clip_rect, + &rectangles[i])) + { + free (rectangles); + return ERROR_LIST (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE); + } + } + } + + DONE: + list = malloc (sizeof (cairo_rectangle_list_t)); + if (unlikely (list == NULL)) { + free (rectangles); + return ERROR_LIST (CAIRO_STATUS_NO_MEMORY); + } + + list->status = CAIRO_STATUS_SUCCESS; + list->rectangles = rectangles; + list->num_rectangles = n_rects; + return list; + +#undef ERROR_LIST +} + +/** + * cairo_rectangle_list_destroy: + * @rectangle_list: a rectangle list, as obtained from cairo_copy_clip_rectangle_list() + * + * Unconditionally frees @rectangle_list and all associated + * references. After this call, the @rectangle_list pointer must not + * be dereferenced. + * + * Since: 1.4 + **/ +void +cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list) +{ + if (rectangle_list == NULL || rectangle_list == &_cairo_rectangles_nil || + rectangle_list == &_cairo_rectangles_not_representable) + return; + + free (rectangle_list->rectangles); + free (rectangle_list); +} + +void +_cairo_clip_reset_static_data (void) +{ + _freed_pool_reset (&clip_path_pool); + _freed_pool_reset (&clip_pool); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-context-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-context-private.h new file mode 100644 index 00000000000..0a7185ef1f5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-context-private.h @@ -0,0 +1,52 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ + +#ifndef CAIRO_COGL_CONTEXT_PRIVATE_H +#define CAIRO_COGL_CONTEXT_PRIVATE_H + +#include "cairo-default-context-private.h" +#include "cairo-cogl-private.h" + +typedef struct _cairo_cogl_context { + cairo_default_context_t base; + + cairo_cogl_device_t *dev; + int path_ctm_age; + cairo_path_fixed_t user_path; + + cairo_bool_t path_is_rectangle; + double x, y, width, height; +} cairo_cogl_context_t; + +cairo_t * +_cairo_cogl_context_create (void *target); + +#endif /* CAIRO_COGL_CONTEXT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-context.c b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-context.c new file mode 100644 index 00000000000..0116b0a5a93 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-context.c @@ -0,0 +1,822 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ + +/* so long as we can verify that the ctm doesn't change multiple times + * during the construction of a path we can build a shadow + * #cairo_path_fixed_t in user coordinates that we can use to create a + * hash value for caching tessellations of that path. + * + * We need to hook into all the points where the ctm can be changed + * so we can bump a cr->path_ctm_age counter. + * + * We need to hook into all the points where the path can be modified + * so we can catch the start of a path and reset the cr->path_ctm_age + * counter at that point. + * + * When a draw operation is hit we can then check that the + * path_ctm_age == 0 and if so we create a hash of the path. + * + * We use this hash to lookup a #cairo_cogl_path_meta_t struct which + * may contain tessellated triangles for the path or may just contain + * a count of how many times the path has been re-seen (we only cache + * tessellated triangles if there is evidence that the path is being + * used multiple times because there is a cost involved in allocating + * a separate buffer for the triangles). + */ + +#include "cairoint.h" + +#include "cairo-cogl-context-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-arc-private.h" +#include "cairo-path-fixed-private.h" + +#include + +static freed_pool_t context_pool; + +void +_cairo_cogl_context_reset_static_data (void) +{ + _freed_pool_reset (&context_pool); +} + +static cairo_status_t +_cairo_cogl_context_rectangle_real (cairo_cogl_context_t *cr, + double x, double y, + double width, double height) +{ + cairo_status_t status; + status = cr->dev->backend_parent.rectangle (cr, x, y, width, height); + if (unlikely (status)) + return status; + + return _cairo_cogl_path_fixed_rectangle (&cr->user_path, + _cairo_fixed_from_double (x), + _cairo_fixed_from_double (y), + _cairo_fixed_from_double (width), + _cairo_fixed_from_double (height)); +} + +/* The idea here is that we have a simplified way of tracking rectangle paths + * because rectangles are perhaps the most common shape drawn with cairo. + * + * Basically we have a speculative store for a rectangle path that doesn't + * need to use the #cairo_path_fixed_t api to describe a rectangle in terms of + * (move_to,rel_line_to,rel_line_to,_rel_line_to,close) because if you profile + * heavy rectangle drawing with Cairo that process can be overly expensive. + * + * If the user asks to add more than just a rectangle to their current path + * then we "flush" any speculative rectangle stored into the current path + * before continuing to append their operations. + * + * In addition to the speculative store cairo-cogl also has a fast-path + * fill_rectangle drawing operation that further aims to minimize the cost + * of drawing rectangles. + */ +static cairo_status_t +_flush_cr_rectangle (cairo_cogl_context_t *cr) +{ + if (!cr->path_is_rectangle) + return CAIRO_STATUS_SUCCESS; + + cr->path_is_rectangle = FALSE; + return _cairo_cogl_context_rectangle_real (cr, cr->x, cr->y, cr->width, cr->height); +} + +static cairo_status_t +_cairo_cogl_context_restore (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.restore (abstract_cr); +} + +static cairo_status_t +_cairo_cogl_context_translate (void *abstract_cr, double tx, double ty) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.translate (abstract_cr, tx, ty); +} + +static cairo_status_t +_cairo_cogl_context_scale (void *abstract_cr, double sx, double sy) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.scale (abstract_cr, sx, sy); +} + +static cairo_status_t +_cairo_cogl_context_rotate (void *abstract_cr, double theta) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.rotate (abstract_cr, theta); +} + +static cairo_status_t +_cairo_cogl_context_transform (void *abstract_cr, const cairo_matrix_t *matrix) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.transform (abstract_cr, matrix); +} + +static cairo_status_t +_cairo_cogl_context_set_matrix (void *abstract_cr, const cairo_matrix_t *matrix) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.set_matrix (abstract_cr, matrix); +} + +static cairo_status_t +_cairo_cogl_context_set_identity_matrix (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + cr->path_ctm_age++; + return cr->dev->backend_parent.set_identity_matrix (abstract_cr); +} + +static cairo_status_t +_cairo_cogl_context_new_path (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.new_path (abstract_cr); + if (unlikely (status)) + return status; + + _cairo_path_fixed_fini (&cr->user_path); + _cairo_path_fixed_init (&cr->user_path); + cr->path_is_rectangle = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_context_new_sub_path (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.new_sub_path (abstract_cr); + if (unlikely (status)) + return status; + + _cairo_path_fixed_new_sub_path (&cr->user_path); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_context_move_to (void *abstract_cr, double x, double y) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_fixed_t x_fixed, y_fixed; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.move_to (abstract_cr, x, y); + if (unlikely (status)) + return status; + + x_fixed = _cairo_fixed_from_double (x); + y_fixed = _cairo_fixed_from_double (y); + + return _cairo_path_fixed_move_to (&cr->user_path, x_fixed, y_fixed); +} + +static cairo_status_t +_cairo_cogl_context_line_to (void *abstract_cr, double x, double y) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_fixed_t x_fixed, y_fixed; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.line_to (abstract_cr, x, y); + if (unlikely (status)) + return status; + + x_fixed = _cairo_fixed_from_double (x); + y_fixed = _cairo_fixed_from_double (y); + + if (cr->user_path.buf.base.num_ops == 0) + cr->path_ctm_age = 0; + + return _cairo_path_fixed_line_to (&cr->user_path, x_fixed, y_fixed); +} + +static cairo_status_t +_cairo_cogl_context_curve_to (void *abstract_cr, + double x1, double y1, + double x2, double y2, + double x3, double y3) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_fixed_t x1_fixed, y1_fixed; + cairo_fixed_t x2_fixed, y2_fixed; + cairo_fixed_t x3_fixed, y3_fixed; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.curve_to (abstract_cr, x1, y1, x2, y2, x3, y3); + if (unlikely (status)) + return status; + + x1_fixed = _cairo_fixed_from_double (x1); + y1_fixed = _cairo_fixed_from_double (y1); + + x2_fixed = _cairo_fixed_from_double (x2); + y2_fixed = _cairo_fixed_from_double (y2); + + x3_fixed = _cairo_fixed_from_double (x3); + y3_fixed = _cairo_fixed_from_double (y3); + + if (cr->user_path.buf.base.num_ops == 0) + cr->path_ctm_age = 0; + + return _cairo_path_fixed_curve_to (&cr->user_path, + x1_fixed, y1_fixed, + x2_fixed, y2_fixed, + x3_fixed, y3_fixed); +} + +static cairo_status_t +_cairo_cogl_context_arc (void *abstract_cr, + double xc, double yc, double radius, + double angle1, double angle2, + cairo_bool_t forward) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.arc (abstract_cr, xc, yc, radius, angle1, angle2, forward); + if (unlikely (status)) + return status; + + if (cr->user_path.buf.base.num_ops == 0) + cr->path_ctm_age = 0; + + /* Do nothing, successfully, if radius is <= 0 */ + if (radius <= 0.0) { + cairo_fixed_t x_fixed, y_fixed; + + x_fixed = _cairo_fixed_from_double (xc); + y_fixed = _cairo_fixed_from_double (yc); + status = _cairo_path_fixed_line_to (&cr->user_path, x_fixed, y_fixed); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (&cr->user_path, x_fixed, y_fixed); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; + } + + status = _cairo_cogl_context_line_to (cr, + xc + radius * cos (angle1), + yc + radius * sin (angle1)); + + if (unlikely (status)) + return status; + + if (forward) + _cairo_arc_path (&cr->base.base, xc, yc, radius, angle1, angle2); + else + _cairo_arc_path_negative (&cr->base.base, xc, yc, radius, angle1, angle2); + + return CAIRO_STATUS_SUCCESS; /* any error will have already been set on cr */ +} + +static cairo_status_t +_cairo_cogl_context_rel_move_to (void *abstract_cr, double dx, double dy) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_fixed_t dx_fixed, dy_fixed; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.rel_move_to (abstract_cr, dx, dy); + if (unlikely (status)) + return status; + + dx_fixed = _cairo_fixed_from_double (dx); + dy_fixed = _cairo_fixed_from_double (dy); + + return _cairo_path_fixed_rel_move_to (&cr->user_path, dx_fixed, dy_fixed); +} + +static cairo_status_t +_cairo_cogl_context_rel_line_to (void *abstract_cr, double dx, double dy) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_fixed_t dx_fixed, dy_fixed; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.rel_line_to (abstract_cr, dx, dy); + if (unlikely (status)) + return status; + + dx_fixed = _cairo_fixed_from_double (dx); + dy_fixed = _cairo_fixed_from_double (dy); + + if (cr->user_path.buf.base.num_ops == 0) + cr->path_ctm_age = 0; + + return _cairo_path_fixed_rel_line_to (&cr->user_path, dx_fixed, dy_fixed); +} + + +static cairo_status_t +_cairo_cogl_context_rel_curve_to (void *abstract_cr, + double dx1, double dy1, + double dx2, double dy2, + double dx3, double dy3) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_fixed_t dx1_fixed, dy1_fixed; + cairo_fixed_t dx2_fixed, dy2_fixed; + cairo_fixed_t dx3_fixed, dy3_fixed; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.rel_curve_to (abstract_cr, dx1, dy1, dx2, dy2, dx3, dy3); + if (unlikely (status)) + return status; + + dx1_fixed = _cairo_fixed_from_double (dx1); + dy1_fixed = _cairo_fixed_from_double (dy1); + + dx2_fixed = _cairo_fixed_from_double (dx2); + dy2_fixed = _cairo_fixed_from_double (dy2); + + dx3_fixed = _cairo_fixed_from_double (dx3); + dy3_fixed = _cairo_fixed_from_double (dy3); + + if (cr->user_path.buf.base.num_ops == 0) + cr->path_ctm_age = 0; + + return _cairo_path_fixed_rel_curve_to (&cr->user_path, + dx1_fixed, dy1_fixed, + dx2_fixed, dy2_fixed, + dx3_fixed, dy3_fixed); +} + +#if 0 +static cairo_status_t +_cairo_cogl_context_arc_to (void *abstract_cr, + double x1, double y1, + double x2, double y2, + double radius) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.arc_to (abstract_cr, x1, y1, x2, y2, radius); + if (unlikely (status)) + return status; +#warning "FIXME" +} + +static cairo_status_t +_cairo_cogl_rel_arc_to (void *cr, + double dx1, double dy1, + double dx2, double dy2, + double radius) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.rel_arc_to (abstract_cr, dx1, dy2, dx2, dy2, radius); + if (unlikely (status)) + return status; +#warning "FIXME" +} +#endif + +static cairo_status_t +_cairo_cogl_context_close_path (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + if (cr->path_is_rectangle) { + status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + status = cr->dev->backend_parent.close_path (abstract_cr); + if (unlikely (status)) + return status; + + if (cr->user_path.buf.base.num_ops == 0) + cr->path_ctm_age = 0; + + return _cairo_path_fixed_close_path (&cr->user_path); +} + +static cairo_status_t +_cairo_cogl_context_rectangle (void *abstract_cr, + double x, double y, + double width, double height) +{ + cairo_cogl_context_t *cr = abstract_cr; + + if (cr->user_path.buf.base.num_ops == 0) { + cr->path_ctm_age = 0; + +#if 1 + /* XXX: Since drawing rectangles is so common we have a + * fast-path for drawing a single rectangle. */ + cr->x = x; + cr->y = y; + cr->width = width; + cr->height = height; + cr->path_is_rectangle = TRUE; + return CAIRO_STATUS_SUCCESS; +#endif + } + + if (cr->path_is_rectangle) { + cairo_status_t status = _flush_cr_rectangle (cr); + if (unlikely (status)) + return status; + } + + return _cairo_cogl_context_rectangle_real (cr, x, y, width, height); +} + +/* Since the surface backend drawing operator functions don't get + * passed the current #cairo_t context we don't have a good way + * to get our user-coordinates path into our surface operator + * functions. + * + * For now we use this function to set side band data on the surface + * itself. + */ +static void +_cairo_cogl_surface_set_side_band_state (cairo_cogl_surface_t *surface, + cairo_cogl_context_t *cr) +{ + + if (cr->path_ctm_age <= 1) { + surface->user_path = &cr->user_path; + surface->ctm = &cr->base.gstate->ctm; + surface->ctm_inverse = &cr->base.gstate->ctm_inverse; + surface->path_is_rectangle = cr->path_is_rectangle; + if (surface->path_is_rectangle) { + surface->path_rectangle_x = cr->x; + surface->path_rectangle_y = cr->y; + surface->path_rectangle_width = cr->width; + surface->path_rectangle_height = cr->height; + } + } else { + surface->user_path = NULL; + surface->path_is_rectangle = FALSE; + } +} + +static cairo_status_t +_cairo_cogl_context_fill (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; + + if (cr->path_is_rectangle) { + status = _cairo_cogl_surface_fill_rectangle (cr->base.gstate->target, + cr->base.gstate->op, + cr->base.gstate->source, + cr->x, + cr->y, + cr->width, + cr->height, + &cr->base.gstate->ctm, + cr->base.gstate->clip); + if (status == CAIRO_STATUS_SUCCESS) + goto DONE; + _flush_cr_rectangle (cr); + } + + _cairo_cogl_surface_set_side_band_state (surface, cr); + + status = cr->dev->backend_parent.fill (abstract_cr); + if (unlikely (status)) + return status; + +DONE: + _cairo_path_fixed_fini (&cr->user_path); + _cairo_path_fixed_init (&cr->user_path); + cr->path_is_rectangle = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_context_fill_preserve (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; + + _cairo_cogl_surface_set_side_band_state (surface, cr); + + status = cr->dev->backend_parent.fill_preserve (abstract_cr); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_context_stroke (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; + + _cairo_cogl_surface_set_side_band_state (surface, cr); + + status = cr->dev->backend_parent.stroke (abstract_cr); + if (unlikely (status)) + return status; + + _cairo_path_fixed_fini (&cr->user_path); + _cairo_path_fixed_init (&cr->user_path); + cr->path_is_rectangle = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_context_stroke_preserve (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)cr->base.gstate->target; + + _cairo_cogl_surface_set_side_band_state (surface, cr); + + status = cr->dev->backend_parent.stroke_preserve (abstract_cr); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_context_clip (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + cairo_status_t status; + + status = cr->dev->backend_parent.clip (abstract_cr); + if (unlikely (status)) + return status; + + _cairo_path_fixed_fini (&cr->user_path); + _cairo_path_fixed_init (&cr->user_path); + cr->path_is_rectangle = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_cogl_context_destroy (void *abstract_cr) +{ + cairo_cogl_context_t *cr = abstract_cr; + + _cairo_default_context_fini (&cr->base); + + _cairo_path_fixed_fini (&cr->user_path); + + /* mark the context as invalid to protect against misuse */ + cr->base.base.status = CAIRO_STATUS_NULL_POINTER; + _freed_pool_put (&context_pool, cr); +} + +/* We want to hook into the frontend of the path construction APIs so + * we can build up a path description in user coordinates instead of + * backend coordinates so that we can recognize user coordinate + * rectangles and so we can hash a user path independent of its + * transform. (With some care to catch unusual cases where the ctm + * changes mid-path) */ +cairo_t * +_cairo_cogl_context_create (void *target) +{ + cairo_cogl_surface_t *surface = target; + cairo_cogl_context_t *cr; + cairo_status_t status; + + cr = _freed_pool_get (&context_pool); + if (unlikely (cr == NULL)) { + cr = malloc (sizeof (cairo_cogl_context_t)); + if (unlikely (cr == NULL)) + return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + status = _cairo_default_context_init (&cr->base, target); + if (unlikely (status)) { + _freed_pool_put (&context_pool, cr); + return _cairo_create_in_error (status); + } + + cr->dev = (cairo_cogl_device_t *)surface->base.device; + + if (unlikely (cr->dev->backend_vtable_initialized == FALSE)) { + cairo_backend_t *backend = &cr->dev->backend; + memcpy (backend, cr->base.base.backend, sizeof (cairo_backend_t)); + memcpy (&cr->dev->backend_parent, cr->base.base.backend, sizeof (cairo_backend_t)); + + backend->destroy = _cairo_cogl_context_destroy; + + backend->restore = _cairo_cogl_context_restore; + backend->translate = _cairo_cogl_context_translate; + backend->scale = _cairo_cogl_context_scale; + backend->rotate = _cairo_cogl_context_rotate; + backend->transform = _cairo_cogl_context_transform; + backend->set_matrix = _cairo_cogl_context_set_matrix; + backend->set_identity_matrix = _cairo_cogl_context_set_identity_matrix; + + backend->new_path = _cairo_cogl_context_new_path; + backend->new_sub_path = _cairo_cogl_context_new_sub_path; + backend->move_to = _cairo_cogl_context_move_to; + backend->rel_move_to = _cairo_cogl_context_rel_move_to; + backend->line_to = _cairo_cogl_context_line_to; + backend->rel_line_to = _cairo_cogl_context_rel_line_to; + backend->curve_to = _cairo_cogl_context_curve_to; + backend->rel_curve_to = _cairo_cogl_context_rel_curve_to; +#if 0 + backend->arc_to = _cairo_cogl_context_arc_to; + backend->rel_arc_to = _cairo_cogl_context_rel_arc_to; +#endif + backend->close_path = _cairo_cogl_context_close_path; + //backend->arc = _cairo_cogl_context_arc; + backend->rectangle = _cairo_cogl_context_rectangle; + + /* Try to automatically catch if any new path APIs are added that mean + * we may need to overload more functions... */ + assert (((char *)&backend->path_extents - (char *)&backend->device_to_user_distance) + == (sizeof (void *) * 14)); + + backend->fill = _cairo_cogl_context_fill; + backend->fill_preserve = _cairo_cogl_context_fill_preserve; + backend->stroke = _cairo_cogl_context_stroke; + backend->stroke_preserve = _cairo_cogl_context_stroke_preserve; + backend->clip = _cairo_cogl_context_clip; + + cr->dev->backend_vtable_initialized = TRUE; + } + + cr->base.base.backend = &cr->dev->backend; + + _cairo_path_fixed_init (&cr->user_path); + cr->path_is_rectangle = FALSE; + + return &cr->base.base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient-private.h new file mode 100644 index 00000000000..fa684d2c6b0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient-private.h @@ -0,0 +1,89 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ + +#ifndef CAIRO_COGL_GRADIENT_PRIVATE_H +#define CAIRO_COGL_GRADIENT_PRIVATE_H + +#include "cairoint.h" +#include "cairo-pattern-private.h" + +#include + +#define CAIRO_COGL_LINEAR_GRADIENT_CACHE_SIZE (1024 * 1024) + +typedef enum _cairo_cogl_gradient_compatibility { + CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD = 1<<0, + CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT = 1<<1, + CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT = 1<<2, + CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE = 1<<3 +} cairo_cogl_gradient_compatibility_t; +#define CAIRO_COGL_GRADIENT_CAN_EXTEND_ALL (CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD |\ + CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT|\ + CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT|\ + CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE) + +typedef struct _cairo_cogl_linear_texture_entry { + cairo_cogl_gradient_compatibility_t compatibility; + CoglTexture *texture; + float translate_x; + float scale_x; +} cairo_cogl_linear_texture_entry_t; + +typedef struct _cairo_cogl_linear_gradient { + cairo_cache_entry_t cache_entry; + cairo_reference_count_t ref_count; + GList *textures; + int n_stops; + const cairo_gradient_stop_t *stops; + cairo_gradient_stop_t stops_embedded[1]; +} cairo_cogl_linear_gradient_t; + +cairo_int_status_t +_cairo_cogl_get_linear_gradient (cairo_cogl_device_t *context, + cairo_extend_t extend_mode, + int n_stops, + const cairo_gradient_stop_t *stops, + cairo_cogl_linear_gradient_t **gradient_out); + +cairo_cogl_linear_texture_entry_t * +_cairo_cogl_linear_gradient_texture_for_extend (cairo_cogl_linear_gradient_t *gradient, + cairo_extend_t extend_mode); + +cairo_cogl_linear_gradient_t * +_cairo_cogl_linear_gradient_reference (cairo_cogl_linear_gradient_t *gradient); + +void +_cairo_cogl_linear_gradient_destroy (cairo_cogl_linear_gradient_t *gradient); + +cairo_bool_t +_cairo_cogl_linear_gradient_equal (const void *key_a, const void *key_b); + +#endif /* CAIRO_COGL_GRADIENT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient.c b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient.c new file mode 100644 index 00000000000..f8c80041629 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-gradient.c @@ -0,0 +1,642 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ +//#include "cairoint.h" + +#include "cairo-cogl-private.h" +#include "cairo-cogl-gradient-private.h" +#include "cairo-image-surface-private.h" + +#include +#include + +#define DUMP_GRADIENTS_TO_PNG + +static unsigned long +_cairo_cogl_linear_gradient_hash (unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + return _cairo_hash_bytes (n_stops, stops, + sizeof (cairo_gradient_stop_t) * n_stops); +} + +static cairo_cogl_linear_gradient_t * +_cairo_cogl_linear_gradient_lookup (cairo_cogl_device_t *ctx, + unsigned long hash, + unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + cairo_cogl_linear_gradient_t lookup; + + lookup.cache_entry.hash = hash, + lookup.n_stops = n_stops; + lookup.stops = stops; + + return _cairo_cache_lookup (&ctx->linear_cache, &lookup.cache_entry); +} + +cairo_bool_t +_cairo_cogl_linear_gradient_equal (const void *key_a, const void *key_b) +{ + const cairo_cogl_linear_gradient_t *a = key_a; + const cairo_cogl_linear_gradient_t *b = key_b; + + if (a->n_stops != b->n_stops) + return FALSE; + + return memcmp (a->stops, b->stops, a->n_stops * sizeof (cairo_gradient_stop_t)) == 0; +} + +cairo_cogl_linear_gradient_t * +_cairo_cogl_linear_gradient_reference (cairo_cogl_linear_gradient_t *gradient) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); + + _cairo_reference_count_inc (&gradient->ref_count); + + return gradient; +} + +void +_cairo_cogl_linear_gradient_destroy (cairo_cogl_linear_gradient_t *gradient) +{ + GList *l; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&gradient->ref_count)) + return; + + for (l = gradient->textures; l; l = l->next) { + cairo_cogl_linear_texture_entry_t *entry = l->data; + cogl_object_unref (entry->texture); + free (entry); + } + g_list_free (gradient->textures); + + free (gradient); +} + +static int +_cairo_cogl_util_next_p2 (int a) +{ + int rval = 1; + + while (rval < a) + rval <<= 1; + + return rval; +} + +static float +get_max_color_component_range (const cairo_color_stop_t *color0, const cairo_color_stop_t *color1) +{ + float range; + float max = 0; + + range = fabs (color0->red - color1->red); + max = MAX (range, max); + range = fabs (color0->green - color1->green); + max = MAX (range, max); + range = fabs (color0->blue - color1->blue); + max = MAX (range, max); + range = fabs (color0->alpha - color1->alpha); + max = MAX (range, max); + + return max; +} + +static int +_cairo_cogl_linear_gradient_width_for_stops (cairo_extend_t extend, + unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + unsigned int n; + float max_texels_per_unit_offset = 0; + float total_offset_range; + + /* Find the stop pair demanding the most precision because we are + * interpolating the largest color-component range. + * + * From that we can define the relative sizes of all the other + * stop pairs within our texture and thus the overall size. + * + * To determine the maximum number of texels for a given gap we + * look at the range of colors we are expected to interpolate (so + * long as the stop offsets are not degenerate) and we simply + * assume we want one texel for each unique color value possible + * for a one byte-per-component representation. + * XXX: maybe this is overkill and just allowing 128 levels + * instead of 256 would be enough and then we'd rely on the + * bilinear filtering to give the full range. + * + * XXX: potentially we could try and map offsets to pixels to come + * up with a more precise mapping, but we are aiming to cache + * the gradients so we can't make assumptions about how it will be + * scaled in the future. + */ + for (n = 1; n < n_stops; n++) { + float color_range; + float offset_range; + float texels; + float texels_per_unit_offset; + + /* note: degenerate stops don't need to be represented in the + * texture but we want to be sure that solid gaps get at least + * one texel and all other gaps get at least 2 texels. + */ + + if (stops[n].offset == stops[n-1].offset) + continue; + + color_range = get_max_color_component_range (&stops[n].color, &stops[n-1].color); + if (color_range == 0) + texels = 1; + else + texels = MAX (2, 256.0f * color_range); + + /* So how many texels would we need to map over the full [0,1] + * gradient range so this gap would have enough texels? ... */ + offset_range = stops[n].offset - stops[n - 1].offset; + texels_per_unit_offset = texels / offset_range; + + if (texels_per_unit_offset > max_texels_per_unit_offset) + max_texels_per_unit_offset = texels_per_unit_offset; + } + + total_offset_range = fabs (stops[n_stops - 1].offset - stops[0].offset); + return max_texels_per_unit_offset * total_offset_range; +} + +/* Aim to create gradient textures without an alpha component so we can avoid + * needing to use blending... */ +static CoglPixelFormat +_cairo_cogl_linear_gradient_format_for_stops (cairo_extend_t extend, + unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + unsigned int n; + + /* We have to add extra transparent texels to the end of the gradient to + * handle CAIRO_EXTEND_NONE... */ + if (extend == CAIRO_EXTEND_NONE) + return COGL_PIXEL_FORMAT_BGRA_8888_PRE; + + for (n = 1; n < n_stops; n++) { + if (stops[n].color.alpha != 1.0) + return COGL_PIXEL_FORMAT_BGRA_8888_PRE; + } + + return COGL_PIXEL_FORMAT_BGR_888; +} + +static cairo_cogl_gradient_compatibility_t +_cairo_cogl_compatibility_from_extend_mode (cairo_extend_t extend_mode) +{ + switch (extend_mode) + { + case CAIRO_EXTEND_NONE: + return CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE; + case CAIRO_EXTEND_PAD: + return CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD; + case CAIRO_EXTEND_REPEAT: + return CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT; + case CAIRO_EXTEND_REFLECT: + return CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT; + } + + assert (0); /* not reached */ + return CAIRO_EXTEND_NONE; +} + +cairo_cogl_linear_texture_entry_t * +_cairo_cogl_linear_gradient_texture_for_extend (cairo_cogl_linear_gradient_t *gradient, + cairo_extend_t extend_mode) +{ + GList *l; + cairo_cogl_gradient_compatibility_t compatibility = + _cairo_cogl_compatibility_from_extend_mode (extend_mode); + for (l = gradient->textures; l; l = l->next) { + cairo_cogl_linear_texture_entry_t *entry = l->data; + if (entry->compatibility & compatibility) + return entry; + } + return NULL; +} + +static void +color_stop_lerp (const cairo_color_stop_t *c0, + const cairo_color_stop_t *c1, + float factor, + cairo_color_stop_t *dest) +{ + /* NB: we always ignore the short members in this file so we don't need to + * worry about initializing them here. */ + dest->red = c0->red * (1.0f-factor) + c1->red * factor; + dest->green = c0->green * (1.0f-factor) + c1->green * factor; + dest->blue = c0->blue * (1.0f-factor) + c1->blue * factor; + dest->alpha = c0->alpha * (1.0f-factor) + c1->alpha * factor; +} + +static size_t +_cairo_cogl_linear_gradient_size (cairo_cogl_linear_gradient_t *gradient) +{ + GList *l; + size_t size = 0; + for (l = gradient->textures; l; l = l->next) { + cairo_cogl_linear_texture_entry_t *entry = l->data; + size += cogl_texture_get_width (entry->texture) * 4; + } + return size; +} + +static void +emit_stop (CoglVertexP2C4 **position, + float left, + float right, + const cairo_color_stop_t *left_color, + const cairo_color_stop_t *right_color) +{ + CoglVertexP2C4 *p = *position; + + guint8 lr = left_color->red * 255; + guint8 lg = left_color->green * 255; + guint8 lb = left_color->blue * 255; + guint8 la = left_color->alpha * 255; + + guint8 rr = right_color->red * 255; + guint8 rg = right_color->green * 255; + guint8 rb = right_color->blue * 255; + guint8 ra = right_color->alpha * 255; + + p[0].x = left; + p[0].y = 0; + p[0].r = lr; p[0].g = lg; p[0].b = lb; p[0].a = la; + p[1].x = left; + p[1].y = 1; + p[1].r = lr; p[1].g = lg; p[1].b = lb; p[1].a = la; + p[2].x = right; + p[2].y = 1; + p[2].r = rr; p[2].g = rg; p[2].b = rb; p[2].a = ra; + + p[3].x = left; + p[3].y = 0; + p[3].r = lr; p[3].g = lg; p[3].b = lb; p[3].a = la; + p[4].x = right; + p[4].y = 1; + p[4].r = rr; p[4].g = rg; p[4].b = rb; p[4].a = ra; + p[5].x = right; + p[5].y = 0; + p[5].r = rr; p[5].g = rg; p[5].b = rb; p[5].a = ra; + + *position = &p[6]; +} + +#ifdef DUMP_GRADIENTS_TO_PNG +static void +dump_gradient_to_png (CoglTexture *texture) +{ + cairo_image_surface_t *image = (cairo_image_surface_t *) + cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + cogl_texture_get_width (texture), + cogl_texture_get_height (texture)); + CoglPixelFormat format; + static int gradient_id = 0; + char *gradient_name; + + if (image->base.status) + return; + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + format = COGL_PIXEL_FORMAT_BGRA_8888_PRE; +#else + format = COGL_PIXEL_FORMAT_ARGB_8888_PRE; +#endif + cogl_texture_get_data (texture, + format, + 0, + image->data); + gradient_name = g_strdup_printf ("./gradient%d.png", gradient_id++); + g_print ("writing gradient: %s\n", gradient_name); + cairo_surface_write_to_png ((cairo_surface_t *)image, gradient_name); + g_free (gradient_name); +} +#endif + +cairo_int_status_t +_cairo_cogl_get_linear_gradient (cairo_cogl_device_t *device, + cairo_extend_t extend_mode, + int n_stops, + const cairo_gradient_stop_t *stops, + cairo_cogl_linear_gradient_t **gradient_out) +{ + unsigned long hash; + cairo_cogl_linear_gradient_t *gradient; + cairo_cogl_linear_texture_entry_t *entry; + cairo_gradient_stop_t *internal_stops; + int stop_offset; + int n_internal_stops; + int n; + cairo_cogl_gradient_compatibility_t compatibilities; + int width; + int left_padding = 0; + cairo_color_stop_t left_padding_color; + int right_padding = 0; + cairo_color_stop_t right_padding_color; + CoglPixelFormat format; + CoglTexture2D *tex; + GError *error = NULL; + int un_padded_width; + CoglHandle offscreen; + cairo_int_status_t status; + int n_quads; + int n_vertices; + float prev; + float right; + CoglVertexP2C4 *vertices; + CoglVertexP2C4 *p; + CoglPrimitive *prim; + + hash = _cairo_cogl_linear_gradient_hash (n_stops, stops); + + gradient = _cairo_cogl_linear_gradient_lookup (device, hash, n_stops, stops); + if (gradient) { + cairo_cogl_linear_texture_entry_t *entry = + _cairo_cogl_linear_gradient_texture_for_extend (gradient, extend_mode); + if (entry) { + *gradient_out = _cairo_cogl_linear_gradient_reference (gradient); + return CAIRO_INT_STATUS_SUCCESS; + } + } + + if (!gradient) { + gradient = malloc (sizeof (cairo_cogl_linear_gradient_t) + + sizeof (cairo_gradient_stop_t) * (n_stops - 1)); + if (!gradient) + return CAIRO_INT_STATUS_NO_MEMORY; + + CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 1); + /* NB: we update the cache_entry size at the end before + * [re]adding it to the cache. */ + gradient->cache_entry.hash = hash; + gradient->textures = NULL; + gradient->n_stops = n_stops; + gradient->stops = gradient->stops_embedded; + memcpy (gradient->stops_embedded, stops, sizeof (cairo_gradient_stop_t) * n_stops); + } else + _cairo_cogl_linear_gradient_reference (gradient); + + entry = malloc (sizeof (cairo_cogl_linear_texture_entry_t)); + if (!entry) { + status = CAIRO_INT_STATUS_NO_MEMORY; + goto BAIL; + } + + compatibilities = _cairo_cogl_compatibility_from_extend_mode (extend_mode); + + n_internal_stops = n_stops; + stop_offset = 0; + + /* We really need stops covering the full [0,1] range for repeat/reflect + * if we want to use sampler REPEAT/MIRROR wrap modes so we may need + * to add some extra stops... */ + if (extend_mode == CAIRO_EXTEND_REPEAT || extend_mode == CAIRO_EXTEND_REFLECT) + { + /* If we don't need any extra stops then actually the texture + * will be shareable for repeat and reflect... */ + compatibilities = (CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT | + CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT); + + if (stops[0].offset != 0) { + n_internal_stops++; + stop_offset++; + } + + if (stops[n_stops - 1].offset != 1) + n_internal_stops++; + } + + internal_stops = alloca (n_internal_stops * sizeof (cairo_gradient_stop_t)); + memcpy (&internal_stops[stop_offset], stops, sizeof (cairo_gradient_stop_t) * n_stops); + + /* cairo_color_stop_t values are all unpremultiplied but we need to + * interpolate premultiplied colors so we premultiply all the double + * components now. (skipping any extra stops added for repeat/reflect) + * + * Anothing thing to note is that by premultiplying the colors + * early we'll also reduce the range of colors to interpolate + * which can result in smaller gradient textures. + */ + for (n = stop_offset; n < n_stops; n++) { + cairo_color_stop_t *color = &internal_stops[n].color; + color->red *= color->alpha; + color->green *= color->alpha; + color->blue *= color->alpha; + } + + if (n_internal_stops != n_stops) + { + if (extend_mode == CAIRO_EXTEND_REPEAT) { + compatibilities &= ~CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT; + if (stops[0].offset != 0) { + /* what's the wrap-around distance between the user's end-stops? */ + double dx = (1.0 - stops[n_stops - 1].offset) + stops[0].offset; + internal_stops[0].offset = 0; + color_stop_lerp (&stops[0].color, + &stops[n_stops - 1].color, + stops[0].offset / dx, + &internal_stops[0].color); + } + if (stops[n_stops - 1].offset != 1) { + internal_stops[n_internal_stops - 1].offset = 1; + internal_stops[n_internal_stops - 1].color = internal_stops[0].color; + } + } else if (extend_mode == CAIRO_EXTEND_REFLECT) { + compatibilities &= ~CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT; + if (stops[0].offset != 0) { + internal_stops[0].offset = 0; + internal_stops[0].color = stops[n_stops - 1].color; + } + if (stops[n_stops - 1].offset != 1) { + internal_stops[n_internal_stops - 1].offset = 1; + internal_stops[n_internal_stops - 1].color = stops[0].color; + } + } + } + + stops = internal_stops; + n_stops = n_internal_stops; + + width = _cairo_cogl_linear_gradient_width_for_stops (extend_mode, n_stops, stops); + + if (extend_mode == CAIRO_EXTEND_PAD) { + + /* Here we need to guarantee that the edge texels of our + * texture correspond to the desired padding color so we + * can use CLAMP_TO_EDGE. + * + * For short stop-gaps and especially for degenerate stops + * it's possible that without special consideration the + * user's end stop colors would not be present in our final + * texture. + * + * To handle this we forcibly add two extra padding texels + * at the edges which extend beyond the [0,1] range of the + * gradient itself and we will later report a translate and + * scale transform to compensate for this. + */ + + /* XXX: If we consider generating a mipmap for our 1d texture + * at some point then we also need to consider how much + * padding to add to be sure lower mipmap levels still have + * the desired edge color (as opposed to a linear blend with + * other colors of the gradient). + */ + + left_padding = 1; + left_padding_color = stops[0].color; + right_padding = 1; + right_padding_color = stops[n_stops - 1].color; + } else if (extend_mode == CAIRO_EXTEND_NONE) { + /* We handle EXTEND_NONE by adding two extra, transparent, texels at + * the ends of the texture and use CLAMP_TO_EDGE. + * + * We add a scale and translate transform so to account for our texels + * extending beyond the [0,1] range. */ + + left_padding = 1; + left_padding_color.red = 0; + left_padding_color.green = 0; + left_padding_color.blue = 0; + left_padding_color.alpha = 0; + right_padding = 1; + right_padding_color = left_padding_color; + } + + /* If we still have stops that don't cover the full [0,1] range + * then we need to define a texture-coordinate scale + translate + * transform to account for that... */ + if (stops[n_stops - 1].offset - stops[0].offset < 1) { + float range = stops[n_stops - 1].offset - stops[0].offset; + entry->scale_x = 1.0 / range; + entry->translate_x = -(stops[0].offset * entry->scale_x); + } + + width += left_padding + right_padding; + + width = _cairo_cogl_util_next_p2 (width); + width = MIN (4096, width); /* lets not go too stupidly big! */ + format = _cairo_cogl_linear_gradient_format_for_stops (extend_mode, n_stops, stops); + + do { + tex = cogl_texture_2d_new_with_size (device->cogl_context, + width, + 1, + format, + &error); + if (!tex) + g_error_free (error); + } while (tex == NULL && width >> 1); + + if (!tex) { + status = CAIRO_INT_STATUS_NO_MEMORY; + goto BAIL; + } + + entry->texture = COGL_TEXTURE (tex); + entry->compatibility = compatibilities; + + un_padded_width = width - left_padding - right_padding; + + /* XXX: only when we know the final texture width can we calculate the + * scale and translate factors needed to account for padding... */ + if (un_padded_width != width) + entry->scale_x *= (float)un_padded_width / (float)width; + if (left_padding) + entry->translate_x += (entry->scale_x / (float)un_padded_width) * (float)left_padding; + + offscreen = cogl_offscreen_new_to_texture (tex); + cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen)); + cogl_ortho (0, width, 1, 0, -1, 100); + cogl_framebuffer_clear4f (COGL_FRAMEBUFFER (offscreen), + COGL_BUFFER_BIT_COLOR, + 0, 0, 0, 0); + + n_quads = n_stops - 1 + !!left_padding + !!right_padding; + n_vertices = 6 * n_quads; + vertices = alloca (sizeof (CoglVertexP2C4) * n_vertices); + p = vertices; + if (left_padding) + emit_stop (&p, 0, left_padding, &left_padding_color, &left_padding_color); + prev = (float)left_padding; + for (n = 1; n < n_stops; n++) { + right = (float)left_padding + (float)un_padded_width * stops[n].offset; + emit_stop (&p, prev, right, &stops[n-1].color, &stops[n].color); + prev = right; + } + if (right_padding) + emit_stop (&p, prev, width, &right_padding_color, &right_padding_color); + + prim = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES, + n_vertices, + vertices); + /* Just use this as the simplest way to setup a default pipeline... */ + cogl_set_source_color4f (0, 0, 0, 0); + cogl_primitive_draw (prim); + cogl_object_unref (prim); + + cogl_pop_framebuffer (); + cogl_object_unref (offscreen); + + gradient->textures = g_list_prepend (gradient->textures, entry); + gradient->cache_entry.size = _cairo_cogl_linear_gradient_size (gradient); + +#ifdef DUMP_GRADIENTS_TO_PNG + dump_gradient_to_png (COGL_TEXTURE (tex)); +#endif + +#warning "FIXME:" + /* XXX: it seems the documentation of _cairo_cache_insert isn't true - it + * doesn't handle re-adding the same entry gracefully - the cache will + * just keep on growing and then it will start randomly evicting things + * pointlessly */ + /* we ignore errors here and just return an uncached gradient */ + if (likely (! _cairo_cache_insert (&device->linear_cache, &gradient->cache_entry))) + _cairo_cogl_linear_gradient_reference (gradient); + + *gradient_out = gradient; + return CAIRO_INT_STATUS_SUCCESS; + +BAIL: + free (entry); + if (gradient) + _cairo_cogl_linear_gradient_destroy (gradient); + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-private.h new file mode 100644 index 00000000000..13fe5a8dc76 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-private.h @@ -0,0 +1,164 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ + +#ifndef CAIRO_COGL_PRIVATE_H +#define CAIRO_COGL_PRIVATE_H + +#include "cairo-device-private.h" +#include "cairo-cache-private.h" +#include "cairo-backend-private.h" +#include "cairo-default-context-private.h" +#include "cairo-surface-private.h" + +#include + +typedef enum _cairo_cogl_template_type { + CAIRO_COGL_TEMPLATE_TYPE_SOLID, + CAIRO_COGL_TEMPLATE_TYPE_TEXTURE, + CAIRO_COGL_TEMPLATE_TYPE_MASK_SOLID, + CAIRO_COGL_TEMPLATE_TYPE_MASK_TEXTURE, + CAIRO_COGL_TEMPLATE_TYPE_COUNT +} cairo_cogl_template_type; + +typedef struct _cairo_cogl_device { + cairo_device_t base; + + cairo_bool_t backend_vtable_initialized; + cairo_backend_t backend; + + /* We save a copy of all the original backend methods that we override so + * we can chain up... + */ + cairo_backend_t backend_parent; + + CoglContext *cogl_context; + + CoglTexture *dummy_texture; + + /* This is a sparsely filled set of templates because we don't support + * the full range of operators that cairo has. All entries corresponding + * to unsupported operators are NULL. + * + * The CAIRO_OPERATOR_ADD is the operator enum with the highest value that + * we support so we at least cap the size of the array by that. + * + * For each operator we have a template for when we have a solid source + * and another for each texture format that could be used as a source. + */ + CoglPipeline *template_pipelines[CAIRO_OPERATOR_ADD + 1][CAIRO_COGL_TEMPLATE_TYPE_COUNT]; + + CoglMatrix identity; + + /* Caches 1d linear gradient textures */ + cairo_cache_t linear_cache; + + cairo_cache_t path_fill_staging_cache; + cairo_cache_t path_fill_prim_cache; + cairo_cache_t path_stroke_staging_cache; + cairo_cache_t path_stroke_prim_cache; +} cairo_cogl_device_t; + +typedef struct _cairo_cogl_clip_primitives { + cairo_t *clip; + CoglPrimitive **primitives; +} cairo_cogl_clip_primitives_t; + +typedef struct _cairo_cogl_surface { + cairo_surface_t base; + + CoglPixelFormat cogl_format; + cairo_bool_t ignore_alpha; + + /* We currently have 3 basic kinds of Cogl surfaces: + * 1) A light surface simply wrapping a CoglTexture + * 2) A CoglOffscreen framebuffer that implicitly also wraps a CoglTexture + * 3) A CoglOnscreen framebuffer which could potentially be mapped to + * a CoglTexture (e.g. via tfp on X11) but we don't currently do + * that. + */ + + CoglTexture *texture; + CoglFramebuffer *framebuffer; + + int width; + int height; + + GQueue *journal; + + CoglAttributeBuffer *buffer_stack; + size_t buffer_stack_size; + size_t buffer_stack_offset; + guint8 *buffer_stack_pointer; + + cairo_clip_t *last_clip; + + /* A small fifo of recently used cairo_clip_ts paired with CoglPrimitives + * that can be used to mask the stencil buffer. */ + GList *clips_fifo; + + int n_clip_updates_per_frame; + + /* Since the surface backend drawing operator functions don't get + * passed the current cairo_t context we don't have a good way + * to get our user-coordinates path into our surface_fill function. + * + * For now we use our _cairo_cogl_context_fill() wrapper to set this + * side band data on the surface... + */ + cairo_path_fixed_t *user_path; + cairo_matrix_t *ctm; + cairo_matrix_t *ctm_inverse; + cairo_bool_t path_is_rectangle; + double path_rectangle_x; + double path_rectangle_y; + double path_rectangle_width; + double path_rectangle_height; +} cairo_cogl_surface_t; + +cairo_status_t +_cairo_cogl_path_fixed_rectangle (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y, + cairo_fixed_t width, + cairo_fixed_t height); + +cairo_int_status_t +_cairo_cogl_surface_fill_rectangle (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + double x, + double y, + double width, + double height, + cairo_matrix_t *ctm, + const cairo_clip_t *clip); + +#endif /* CAIRO_COGL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-surface.c new file mode 100644 index 00000000000..c57fd7f433c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-surface.c @@ -0,0 +1,2805 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ +#include "cairoint.h" + +#include "cairo-cache-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-fixed-private.h" +#include "cairo-device-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-cogl-private.h" +#include "cairo-cogl-gradient-private.h" +#include "cairo-arc-private.h" +#include "cairo-traps-private.h" +#include "cairo-cogl-context-private.h" +#include "cairo-cogl-utils-private.h" +#include "cairo-box-inline.h" +#include "cairo-surface-subsurface-inline.h" +#include "cairo-surface-fallback-private.h" +#include "cairo-surface-offset-private.h" + +#include "cairo-cogl.h" + +#include +#include + +#define CAIRO_COGL_DEBUG 0 +//#define FILL_WITH_COGL_PATH +//#define USE_CAIRO_PATH_FLATTENER +#define ENABLE_PATH_CACHE +//#define DISABLE_BATCHING +#define USE_COGL_RECTANGLE_API +#define ENABLE_RECTANGLES_FASTPATH + +#if defined (USE_COGL_RECTANGLE_API) || defined (ENABLE_PATH_CACHE) +#define NEED_COGL_CONTEXT +#endif + +#if CAIRO_COGL_DEBUG && __GNUC__ +#define UNSUPPORTED(reason) ({ \ + g_warning ("cairo-cogl: hit unsupported operation: %s", reason); \ + CAIRO_INT_STATUS_UNSUPPORTED; \ +}) +#else +#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED +#endif + +#define CAIRO_COGL_PATH_META_CACHE_SIZE (1024 * 1024) + +typedef struct _cairo_cogl_texture_attributes { + /* nabbed from cairo_surface_attributes_t... */ + cairo_matrix_t matrix; + cairo_extend_t extend; + cairo_filter_t filter; + cairo_bool_t has_component_alpha; + + CoglPipelineWrapMode s_wrap; + CoglPipelineWrapMode t_wrap; +} cairo_cogl_texture_attributes_t; + +typedef enum _cairo_cogl_journal_entry_type { + CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE, + CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE, + CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH, + CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP +} cairo_cogl_journal_entry_type_t; + +typedef struct _cairo_cogl_journal_entry { + cairo_cogl_journal_entry_type_t type; +} cairo_cogl_journal_entry_t; + +typedef struct _cairo_cogl_journal_clip_entry { + cairo_cogl_journal_entry_t base; + cairo_clip_t *clip; +} cairo_cogl_journal_clip_entry_t; + +typedef struct _cairo_cogl_journal_rect_entry { + cairo_cogl_journal_entry_t base; + CoglPipeline *pipeline; + float x; + float y; + float width; + float height; + int n_layers; + cairo_matrix_t ctm; +} cairo_cogl_journal_rect_entry_t; + +typedef struct _cairo_cogl_journal_prim_entry { + cairo_cogl_journal_entry_t base; + CoglPipeline *pipeline; + CoglPrimitive *primitive; + gboolean has_transform; + cairo_matrix_t transform; +} cairo_cogl_journal_prim_entry_t; + +typedef struct _cairo_cogl_journal_path_entry { + cairo_cogl_journal_entry_t base; + CoglPipeline *pipeline; + CoglPath *path; +} cairo_cogl_journal_path_entry_t; + +typedef struct _cairo_cogl_path_fill_meta { + cairo_cache_entry_t cache_entry; + cairo_reference_count_t ref_count; + int counter; + cairo_path_fixed_t *user_path; + cairo_matrix_t ctm_inverse; + + /* TODO */ +#if 0 + /* A cached path tessellation should be re-usable with different rotations + * and translations but not for different scales. + * + * one idea is to track the diagonal lenghts of a unit rectangle + * transformed through the original ctm use to tessellate the geometry + * so we can check what the lengths are for any new ctm to know if + * this geometry is compatible. + */ +#endif + + CoglPrimitive *prim; +} cairo_cogl_path_fill_meta_t; + +typedef struct _cairo_cogl_path_stroke_meta { + cairo_cache_entry_t cache_entry; + cairo_reference_count_t ref_count; + int counter; + cairo_path_fixed_t *user_path; + cairo_matrix_t ctm_inverse; + cairo_stroke_style_t style; + double tolerance; + + /* TODO */ +#if 0 + /* A cached path tessellation should be re-usable with different rotations + * and translations but not for different scales. + * + * one idea is to track the diagonal lenghts of a unit rectangle + * transformed through the original ctm use to tessellate the geometry + * so we can check what the lengths are for any new ctm to know if + * this geometry is compatible. + */ +#endif + + CoglPrimitive *prim; +} cairo_cogl_path_stroke_meta_t; + +static cairo_surface_t * +_cairo_cogl_surface_create_full (cairo_cogl_device_t *dev, + cairo_bool_t ignore_alpha, + CoglFramebuffer *framebuffer, + CoglTexture *texture); + +static cairo_int_status_t +_cairo_cogl_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +static void +_cairo_cogl_journal_flush (cairo_cogl_surface_t *surface); + +cairo_private extern const cairo_surface_backend_t _cairo_cogl_surface_backend; + +slim_hidden_proto (cairo_cogl_device_create); +slim_hidden_proto (cairo_cogl_surface_create); +slim_hidden_proto (cairo_cogl_surface_get_framebuffer); +slim_hidden_proto (cairo_cogl_surface_get_texture); +slim_hidden_proto (cairo_cogl_surface_end_frame); + +static cairo_cogl_device_t * +to_device (cairo_device_t *device) +{ + return (cairo_cogl_device_t *)device; +} + +/* moves trap points such that they become the actual corners of the trapezoid */ +static void +_sanitize_trap (cairo_trapezoid_t *t) +{ + cairo_trapezoid_t s = *t; + +#define FIX(lr, tb, p) \ + if (t->lr.p.y != t->tb) { \ + t->lr.p.x = s.lr.p2.x + _cairo_fixed_mul_div_floor (s.lr.p1.x - s.lr.p2.x, s.tb - s.lr.p2.y, s.lr.p1.y - s.lr.p2.y); \ + t->lr.p.y = s.tb; \ + } + FIX (left, top, p1); + FIX (left, bottom, p2); + FIX (right, top, p1); + FIX (right, bottom, p2); +} + +static cairo_status_t +_cairo_cogl_surface_ensure_framebuffer (cairo_cogl_surface_t *surface) +{ + GError *error = NULL; + + if (surface->framebuffer) + return CAIRO_STATUS_SUCCESS; + + surface->framebuffer = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (surface->texture)); + if (!cogl_framebuffer_allocate (surface->framebuffer, &error)) { + g_error_free (error); + cogl_object_unref (surface->framebuffer); + surface->framebuffer = NULL; + return CAIRO_STATUS_NO_MEMORY; + } + + cogl_push_framebuffer (surface->framebuffer); + cogl_ortho (0, surface->width, + surface->height, 0, + -1, 100); + cogl_pop_framebuffer (); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_cogl_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_cogl_surface_t *reference_surface = abstract_surface; + cairo_cogl_surface_t *surface; + CoglTexture *texture; + cairo_status_t status; + + texture = cogl_texture_new_with_size (width, height, + COGL_TEXTURE_NO_SLICING, + (content & CAIRO_CONTENT_COLOR) ? + COGL_PIXEL_FORMAT_BGRA_8888_PRE : + COGL_PIXEL_FORMAT_A_8); + if (!texture) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface = (cairo_cogl_surface_t *) + _cairo_cogl_surface_create_full (to_device(reference_surface->base.device), + (content & CAIRO_CONTENT_ALPHA) == 0, + NULL, + texture); + if (unlikely (surface->base.status)) + return &surface->base; + + status = _cairo_cogl_surface_ensure_framebuffer (surface); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return _cairo_surface_create_in_error (status); + } + + return &surface->base; +} + +static cairo_bool_t +_cairo_cogl_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_cogl_surface_t *surface = abstract_surface; + + extents->x = 0; + extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + + return TRUE; +} + +static void +_cairo_cogl_journal_free (cairo_cogl_surface_t *surface) +{ + GList *l; + + for (l = surface->journal->head; l; l = l->next) { + cairo_cogl_journal_entry_t *entry = l->data; + + if (entry->type == CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE) { + cairo_cogl_journal_prim_entry_t *prim_entry = + (cairo_cogl_journal_prim_entry_t *)entry; + cogl_object_unref (prim_entry->primitive); + } else if (entry->type == CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH) { + cairo_cogl_journal_path_entry_t *path_entry = + (cairo_cogl_journal_path_entry_t *)entry; + cogl_object_unref (path_entry->path); + } + } + + g_queue_free (surface->journal); + surface->journal = NULL; +} + +#ifdef FILL_WITH_COGL_PATH +static void +_cairo_cogl_journal_log_path (cairo_cogl_surface_t *surface, + CoglPipeline *pipeline, + CoglPath *path) +{ + cairo_cogl_journal_path_entry_t *entry; + + if (unlikely (surface->journal == NULL)) + surface->journal = g_queue_new (); + + /* FIXME: Instead of a GList here we should stack allocate the journal + * entries so it would be cheaper to allocate and they can all be freed in + * one go after flushing! */ + entry = g_slice_new (cairo_cogl_journal_path_entry_t); + entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH; + + entry->pipeline = cogl_object_ref (pipeline); + entry->path = cogl_object_ref (path); + + g_queue_push_tail (surface->journal, entry); + +#ifdef DISABLE_BATCHING + _cairo_cogl_journal_flush (surface); +#endif +} +#endif /* FILL_WITH_COGL_PATH */ + +static void +_cairo_cogl_journal_log_primitive (cairo_cogl_surface_t *surface, + CoglPipeline *pipeline, + CoglPrimitive *primitive, + cairo_matrix_t *transform) +{ + cairo_cogl_journal_prim_entry_t *entry; + + if (unlikely (surface->journal == NULL)) + surface->journal = g_queue_new (); + + /* FIXME: Instead of a GList here we should stack allocate the journal + * entries so it would be cheaper to allocate and they can all be freed in + * one go after flushing! */ + entry = g_slice_new (cairo_cogl_journal_prim_entry_t); + entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE; + + entry->pipeline = cogl_object_ref (pipeline); + + if (transform) { + entry->transform = *transform; + entry->has_transform = TRUE; + } else + entry->has_transform = FALSE; + + entry->primitive = cogl_object_ref (primitive); + + g_queue_push_tail (surface->journal, entry); + +#ifdef DISABLE_BATCHING + _cairo_cogl_journal_flush (surface); +#endif +} + +static void +_cairo_cogl_journal_log_rectangle (cairo_cogl_surface_t *surface, + CoglPipeline *pipeline, + float x, + float y, + float width, + float height, + int n_layers, + cairo_matrix_t *ctm) +{ + cairo_cogl_journal_rect_entry_t *entry; + + if (unlikely (surface->journal == NULL)) + surface->journal = g_queue_new (); + + /* FIXME: Instead of a GList here we should stack allocate the journal + * entries so it would be cheaper to allocate and they can all be freed in + * one go after flushing! */ + entry = g_slice_new (cairo_cogl_journal_rect_entry_t); + entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE; + + entry->pipeline = cogl_object_ref (pipeline); + + entry->x = x; + entry->y = y; + entry->width = width; + entry->height = height; + entry->ctm = *ctm; + + entry->n_layers = n_layers; + + g_queue_push_tail (surface->journal, entry); + +#ifdef DISABLE_BATCHING + _cairo_cogl_journal_flush (surface); +#endif +} + +static void +_cairo_cogl_journal_log_clip (cairo_cogl_surface_t *surface, + const cairo_clip_t *clip) +{ + cairo_cogl_journal_clip_entry_t *entry; + + if (unlikely (surface->journal == NULL)) + surface->journal = g_queue_new (); + + /* FIXME: Instead of a GList here we should stack allocate the journal + * entries so it would be cheaper to allocate and they can all be freed in + * one go after flushing! */ + entry = g_slice_new (cairo_cogl_journal_clip_entry_t); + entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP; + entry->clip = _cairo_clip_copy (clip); + + g_queue_push_tail (surface->journal, entry); +} + +static void +_cairo_cogl_journal_discard (cairo_cogl_surface_t *surface) +{ + GList *l; + + if (!surface->journal) { + assert (surface->last_clip == NULL); + return; + } + + if (surface->buffer_stack && surface->buffer_stack_offset) { + cogl_buffer_unmap (COGL_BUFFER (surface->buffer_stack)); + cogl_object_unref (surface->buffer_stack); + surface->buffer_stack = NULL; + } + + for (l = surface->journal->head; l; l = l->next) { + cairo_cogl_journal_entry_t *entry = l->data; + gsize entry_size; + + switch (entry->type) + { + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP: { + cairo_cogl_journal_clip_entry_t *clip_entry = + (cairo_cogl_journal_clip_entry_t *)entry; + _cairo_clip_destroy (clip_entry->clip); + entry_size = sizeof (cairo_cogl_journal_clip_entry_t); + break; + } + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE: { + cairo_cogl_journal_rect_entry_t *rect_entry = + (cairo_cogl_journal_rect_entry_t *)entry; + cogl_object_unref (rect_entry->pipeline); + entry_size = sizeof (cairo_cogl_journal_rect_entry_t); + break; + } + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE: { + cairo_cogl_journal_prim_entry_t *prim_entry = + (cairo_cogl_journal_prim_entry_t *)entry; + cogl_object_unref (prim_entry->pipeline); + cogl_object_unref (prim_entry->primitive); + entry_size = sizeof (cairo_cogl_journal_prim_entry_t); + break; + } + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH: { + cairo_cogl_journal_path_entry_t *path_entry = + (cairo_cogl_journal_path_entry_t *)entry; + cogl_object_unref (path_entry->pipeline); + cogl_object_unref (path_entry->path); + entry_size = sizeof (cairo_cogl_journal_path_entry_t); + break; + } + default: + assert (0); /* not reached! */ + entry_size = 0; /* avoid compiler warning */ + } + g_slice_free1 (entry_size, entry); + } + + g_queue_clear (surface->journal); + + if (surface->last_clip) { + _cairo_clip_destroy (surface->last_clip); + surface->last_clip = NULL; + } +} + +static CoglAttributeBuffer * +_cairo_cogl_surface_allocate_buffer_space (cairo_cogl_surface_t *surface, + size_t size, + size_t *offset, + void **pointer) +{ + /* XXX: In the Cogl journal we found it more efficient to have a pool of + * buffers that we re-cycle but for now we simply thow away our stack + * buffer each time we flush. */ + if (unlikely (surface->buffer_stack && + (surface->buffer_stack_size - surface->buffer_stack_offset) < size)) { + cogl_buffer_unmap (COGL_BUFFER (surface->buffer_stack)); + cogl_object_unref (surface->buffer_stack); + surface->buffer_stack = NULL; + surface->buffer_stack_size *= 2; + } + + if (unlikely (surface->buffer_stack_size < size)) + surface->buffer_stack_size = size * 2; + + if (unlikely (surface->buffer_stack == NULL)) { + surface->buffer_stack = cogl_attribute_buffer_new (surface->buffer_stack_size, NULL); + surface->buffer_stack_pointer = + cogl_buffer_map (COGL_BUFFER (surface->buffer_stack), + COGL_BUFFER_ACCESS_WRITE, + COGL_BUFFER_MAP_HINT_DISCARD); + surface->buffer_stack_offset = 0; + } + + *pointer = surface->buffer_stack_pointer + surface->buffer_stack_offset; + *offset = surface->buffer_stack_offset; + + surface->buffer_stack_offset += size; + return cogl_object_ref (surface->buffer_stack); +} + + +static CoglAttributeBuffer * +_cairo_cogl_traps_to_triangles_buffer (cairo_cogl_surface_t *surface, + cairo_traps_t *traps, + size_t *offset, + gboolean one_shot) +{ + CoglAttributeBuffer *buffer; + int n_traps = traps->num_traps; + int i; + CoglVertexP2 *triangles; + + if (one_shot) { + buffer = _cairo_cogl_surface_allocate_buffer_space (surface, + n_traps * sizeof (CoglVertexP2) * 6, + offset, + (void **)&triangles); + if (!buffer) + return NULL; + } else { + buffer = cogl_attribute_buffer_new (n_traps * sizeof (CoglVertexP2) * 6, NULL); + if (!buffer) + return NULL; + triangles = cogl_buffer_map (COGL_BUFFER (buffer), + COGL_BUFFER_ACCESS_WRITE, + COGL_BUFFER_MAP_HINT_DISCARD); + if (!triangles) + return NULL; + *offset = 0; + } + + /* XXX: This is can be very expensive. I'm not sure a.t.m if it's + * predominantly the bandwidth required or the cost of the fixed_to_float + * conversions but either way we should try using an index buffer to + * reduce the amount we upload by 1/3 (offset by allocating and uploading + * indices though) sadly though my experience with the intel mesa drivers + * is that slow paths can easily be hit when starting to use indices. + */ + for (i = 0; i < n_traps; i++) + { + CoglVertexP2 *p = &triangles[i * 6]; + cairo_trapezoid_t *trap = &traps->traps[i]; + + p[0].x = _cairo_cogl_util_fixed_to_float (trap->left.p1.x); + p[0].y = _cairo_cogl_util_fixed_to_float (trap->left.p1.y); + + p[1].x = _cairo_cogl_util_fixed_to_float (trap->left.p2.x); + p[1].y = _cairo_cogl_util_fixed_to_float (trap->left.p2.y); + + p[2].x = _cairo_cogl_util_fixed_to_float (trap->right.p2.x); + p[2].y = _cairo_cogl_util_fixed_to_float (trap->right.p2.y); + + p[3].x = _cairo_cogl_util_fixed_to_float (trap->left.p1.x); + p[3].y = _cairo_cogl_util_fixed_to_float (trap->left.p1.y); + + p[4].x = _cairo_cogl_util_fixed_to_float (trap->right.p2.x); + p[4].y = _cairo_cogl_util_fixed_to_float (trap->right.p2.y); + + p[5].x = _cairo_cogl_util_fixed_to_float (trap->right.p1.x); + p[5].y = _cairo_cogl_util_fixed_to_float (trap->right.p1.y); + } + + if (!one_shot) + cogl_buffer_unmap (COGL_BUFFER (buffer)); + + return buffer; +} + +/* Used for solid fills, in this case we just need a mesh made of + * a single (2-component) position attribute. */ +static CoglPrimitive * +_cairo_cogl_traps_to_composite_prim_p2 (cairo_cogl_surface_t *surface, + cairo_traps_t *traps, + gboolean one_shot) +{ + size_t offset; + CoglAttributeBuffer *buffer = _cairo_cogl_traps_to_triangles_buffer (surface, traps, &offset, one_shot); + CoglAttribute *pos = cogl_attribute_new (buffer, + "cogl_position_in", + sizeof (CoglVertexP2), + offset, + 2, + COGL_ATTRIBUTE_TYPE_FLOAT); + CoglPrimitive *prim; + + /* The attribute will have taken a reference on the buffer */ + cogl_object_unref (buffer); + + prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, + traps->num_traps * 6, pos, NULL); + + /* The primitive will now keep the attribute alive... */ + cogl_object_unref (pos); + + return prim; +} + +/* Used for surface fills, in this case we need a mesh made of a single + * (2-component) position attribute + we also alias the same attribute as + * (2-component) texture coordinates */ +static CoglPrimitive * +_cairo_cogl_traps_to_composite_prim_p2t2 (cairo_cogl_surface_t *surface, + cairo_traps_t *traps, + gboolean one_shot) +{ + size_t offset; + CoglAttributeBuffer *buffer = _cairo_cogl_traps_to_triangles_buffer (surface, traps, &offset, one_shot); + CoglAttribute *pos = cogl_attribute_new (buffer, + "cogl_position_in", + sizeof (CoglVertexP2), + offset, + 2, + COGL_ATTRIBUTE_TYPE_FLOAT); + CoglAttribute *tex_coords = cogl_attribute_new (buffer, + "cogl_tex_coord0_in", + sizeof (CoglVertexP2), + 0, + 2, + COGL_ATTRIBUTE_TYPE_FLOAT); + CoglPrimitive *prim; + + /* The attributes will have taken references on the buffer */ + cogl_object_unref (buffer); + + prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, + traps->num_traps * 6, pos, tex_coords, NULL); + + /* The primitive will now keep the attributes alive... */ + cogl_object_unref (pos); + cogl_object_unref (tex_coords); + + return prim; +} + +static CoglPrimitive * +_cairo_cogl_traps_to_composite_prim (cairo_cogl_surface_t *surface, + cairo_traps_t *traps, + int n_layers, + gboolean one_shot) +{ + int n_traps = traps->num_traps; + int i; + + /* XXX: Ideally we would skip tessellating to traps entirely since + * given their representation, conversion to triangles is quite expensive. + * + * This simplifies the conversion to triangles by making the end points of + * the two side lines actually just correspond to the corners of the + * traps. + */ + for (i = 0; i < n_traps; i++) + _sanitize_trap (&traps->traps[i]); + + if (n_layers == 0) + return _cairo_cogl_traps_to_composite_prim_p2 (surface, traps, one_shot); + else { + assert (n_layers == 1); + return _cairo_cogl_traps_to_composite_prim_p2t2 (surface, traps, one_shot); + } +} + +static cairo_int_status_t +_cairo_cogl_fill_to_primitive (cairo_cogl_surface_t *surface, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + int n_layers, + cairo_bool_t one_shot, + CoglPrimitive **primitive, + size_t *size) +{ + cairo_traps_t traps; + cairo_int_status_t status; + + _cairo_traps_init (&traps); + status = _cairo_path_fixed_fill_to_traps (path, fill_rule, tolerance, &traps); + if (unlikely (status)) + goto BAIL; + + if (traps.num_traps == 0) { + status = CAIRO_INT_STATUS_NOTHING_TO_DO; + goto BAIL; + } + + *size = traps.num_traps * sizeof (CoglVertexP2) * 6; + + *primitive = _cairo_cogl_traps_to_composite_prim (surface, &traps, n_layers, one_shot); + if (!*primitive) { + status = CAIRO_INT_STATUS_NO_MEMORY; + goto BAIL; + } + +BAIL: + _cairo_traps_fini (&traps); + return status; +} + +static void +_cairo_cogl_clip_push_box (const cairo_box_t *box) +{ + if (_cairo_box_is_pixel_aligned (box)) { + cairo_rectangle_int_t rect; + _cairo_box_round_to_rectangle (box, &rect); + cogl_clip_push_window_rectangle (rect.x, rect.y, + rect.width, rect.height); + } else { + double x1, y1, x2, y2; + _cairo_box_to_doubles (box, &x1, &y1, &x2, &y2); + cogl_clip_push_rectangle (x1, y1, x2, y2); + } +} + +static void +_cairo_cogl_journal_flush (cairo_cogl_surface_t *surface) +{ + GList *l; + int clip_stack_depth = 0; + int i; + + if (!surface->journal) + return; + + if (surface->buffer_stack && surface->buffer_stack_offset) { + cogl_buffer_unmap (COGL_BUFFER (surface->buffer_stack)); + cogl_object_unref (surface->buffer_stack); + surface->buffer_stack = NULL; + } + + cogl_set_framebuffer (surface->framebuffer); + + cogl_push_matrix (); + + for (l = surface->journal->head; l; l = l->next) { + cairo_cogl_journal_entry_t *entry = l->data; + + switch (entry->type) + { + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP: { + cairo_cogl_journal_clip_entry_t *clip_entry = + (cairo_cogl_journal_clip_entry_t *)entry; + cairo_clip_path_t *path; +#if 0 + cairo_bool_t checked_for_primitives = FALSE; + cairo_cogl_clip_primitives_t *clip_primitives; +#endif + + for (i = 0; i < clip_stack_depth; i++) + cogl_clip_pop (); + clip_stack_depth = 0; + + for (path = clip_entry->clip->path, i = 0; path; path = path->prev, i++) { + cairo_rectangle_int_t extents; + cairo_int_status_t status; + CoglPrimitive *prim; + size_t prim_size; + + _cairo_path_fixed_approximate_clip_extents (&path->path, &extents); + + /* TODO - maintain a fifo of the last 10 used clips with cached + * primitives to see if we can avoid tessellating the path and + * uploading the vertices... + */ +#if 0 + if (!checked_for_primitives) { + clip_primitives = find_clip_primitives (clip); + checked_for_primitives = TRUE; + } + if (clip_primitives) + prim = clip_primitives->primitives[i]; +#endif + status = _cairo_cogl_fill_to_primitive (surface, + &path->path, + path->fill_rule, + path->tolerance, + 0, + TRUE, + &prim, + &prim_size); + if (unlikely (status)) { + g_warning ("Failed to get primitive for clip path while flushing journal"); + continue; + } + clip_stack_depth++; + cogl_clip_push_primitive (prim, + extents.x, extents.y, + extents.x + extents.width, + extents.y + extents.height); + cogl_object_unref (prim); + } + + for (i = 0; i < clip_entry->clip->num_boxes; i++) { + clip_stack_depth++; + _cairo_cogl_clip_push_box (&clip_entry->clip->boxes[i]); + } + + surface->n_clip_updates_per_frame++; + break; + } + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE: { + cairo_cogl_journal_rect_entry_t *rect_entry = + (cairo_cogl_journal_rect_entry_t *)entry; + float tex_coords[8]; + float x1 = rect_entry->x; + float y1 = rect_entry->y; + float x2 = rect_entry->x + rect_entry->width; + float y2 = rect_entry->y + rect_entry->height; + cairo_matrix_t *ctm = &rect_entry->ctm; + float ctmfv[16] = { + ctm->xx, ctm->yx, 0, 0, + ctm->xy, ctm->yy, 0, 0, + 0, 0, 1, 0, + ctm->x0, ctm->y0, 0, 1 + }; + CoglMatrix transform; + + cogl_matrix_init_from_array (&transform, ctmfv); + + if (rect_entry->n_layers) { + g_assert (rect_entry->n_layers <= 2); + tex_coords[0] = x1; + tex_coords[1] = y1; + tex_coords[2] = x2; + tex_coords[3] = y2; + if (rect_entry->n_layers > 1) + memcpy (&tex_coords[4], tex_coords, sizeof (float) * 4); + } + + cogl_set_source (rect_entry->pipeline); + cogl_push_matrix (); + cogl_transform (&transform); + cogl_rectangle_with_multitexture_coords (x1, y1, x2, y2, + tex_coords, 4 * rect_entry->n_layers); + cogl_pop_matrix (); + break; + } + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE: { + cairo_cogl_journal_prim_entry_t *prim_entry = + (cairo_cogl_journal_prim_entry_t *)entry; + CoglMatrix transform; + + cogl_push_matrix (); + if (prim_entry->has_transform) { + cairo_matrix_t *ctm = &prim_entry->transform; + float ctmfv[16] = { + ctm->xx, ctm->yx, 0, 0, + ctm->xy, ctm->yy, 0, 0, + 0, 0, 1, 0, + ctm->x0, ctm->y0, 0, 1 + }; + cogl_matrix_init_from_array (&transform, ctmfv); + cogl_transform (&transform); + } else { + cogl_matrix_init_identity (&transform); + cogl_set_modelview_matrix (&transform); + } + + cogl_set_source (prim_entry->pipeline); + cogl_primitive_draw (prim_entry->primitive); + cogl_pop_matrix (); + break; + } + case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PATH: { + cairo_cogl_journal_path_entry_t *path_entry = + (cairo_cogl_journal_path_entry_t *)entry; + + cogl_set_source (path_entry->pipeline); + cogl_path_fill (path_entry->path); + break; + } + default: + assert (0); /* not reached! */ + } + } + + cogl_pop_matrix (); + + for (i = 0; i < clip_stack_depth; i++) + cogl_clip_pop (); + + _cairo_cogl_journal_discard (surface); +} + +static cairo_status_t +_cairo_cogl_surface_flush (void *abstract_surface, + unsigned flags) +{ + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; + + if (flags) + return CAIRO_STATUS_SUCCESS; + + _cairo_cogl_journal_flush (surface); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_surface_finish (void *abstract_surface) +{ + cairo_cogl_surface_t *surface = abstract_surface; + + if (surface->texture) + cogl_object_unref (surface->texture); + + if (surface->framebuffer) + cogl_object_unref (surface->framebuffer); + + if (surface->journal) + _cairo_cogl_journal_free (surface); + + /*XXX wtf */ + cairo_device_release (surface->base.device); + + return CAIRO_STATUS_SUCCESS; +} + +static CoglPixelFormat +get_cogl_format_from_cairo_format (cairo_format_t cairo_format); + +/* XXX: We often use RGBA format for onscreen framebuffers so make sure + * to handle CAIRO_FORMAT_INVALID sensibly */ +static cairo_format_t +get_cairo_format_from_cogl_format (CoglPixelFormat format) +{ + switch ((int)format) + { + case COGL_PIXEL_FORMAT_A_8: + return CAIRO_FORMAT_A8; + case COGL_PIXEL_FORMAT_RGB_565: + return CAIRO_FORMAT_RGB16_565; + + case COGL_PIXEL_FORMAT_BGRA_8888_PRE: + case COGL_PIXEL_FORMAT_ARGB_8888_PRE: + case COGL_PIXEL_FORMAT_RGBA_8888_PRE: + /* Note: this is ambiguous since CAIRO_FORMAT_RGB24 + * would also map to the same CoglPixelFormat */ + return CAIRO_FORMAT_ARGB32; + + default: + g_warning("bad format: %x a? %d, bgr? %d, pre %d, format: %d\n", + format, + format & COGL_A_BIT, + format & COGL_BGR_BIT, + format & COGL_PREMULT_BIT, + format & ~(COGL_A_BIT | COGL_BGR_BIT | COGL_PREMULT_BIT)); + return CAIRO_FORMAT_INVALID; + } +} + +static CoglPixelFormat +get_cogl_format_from_cairo_format (cairo_format_t cairo_format) +{ + switch (cairo_format) + { + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_RGB24: +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + return COGL_PIXEL_FORMAT_BGRA_8888_PRE; +#else + return COGL_PIXEL_FORMAT_ARGB_8888_PRE; +#endif + case CAIRO_FORMAT_A8: + return COGL_PIXEL_FORMAT_A_8; + case CAIRO_FORMAT_RGB16_565: + return COGL_PIXEL_FORMAT_RGB_565; + case CAIRO_FORMAT_INVALID: + case CAIRO_FORMAT_A1: + case CAIRO_FORMAT_RGB30: + return 0; + } + + g_warn_if_reached (); + return 0; +} + +static cairo_status_t +_cairo_cogl_surface_read_rect_to_image_surface (cairo_cogl_surface_t *surface, + cairo_rectangle_int_t *interest, + cairo_image_surface_t **image_out) +{ + cairo_image_surface_t *image; + cairo_status_t status; + cairo_format_t cairo_format; + CoglPixelFormat cogl_format; + + /* TODO: Add cogl_texture_get_region() API so we don't have to ensure the + * surface is bound to an fbo to read back pixels */ + status = _cairo_cogl_surface_ensure_framebuffer (surface); + if (unlikely (status)) + return status; + + cairo_format = get_cairo_format_from_cogl_format (surface->cogl_format); + if (cairo_format == CAIRO_FORMAT_INVALID) { + cairo_format = CAIRO_FORMAT_ARGB32; + cogl_format = get_cogl_format_from_cairo_format (cairo_format); + } else { + cogl_format = cogl_framebuffer_get_color_format (surface->framebuffer); + } + + image = (cairo_image_surface_t *) + cairo_image_surface_create (cairo_format, surface->width, surface->height); + if (image->base.status) + return image->base.status; + + /* TODO: Add cogl_framebuffer_read_pixels() API */ + cogl_push_framebuffer (surface->framebuffer); + cogl_read_pixels (0, 0, surface->width, surface->height, + COGL_READ_PIXELS_COLOR_BUFFER, + cogl_format, + image->data); + cogl_pop_framebuffer (); + + *image_out = image; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_cogl_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_cogl_surface_t *surface = abstract_surface; + cairo_status_t status; + + if (surface->texture) { + cairo_format_t format = get_cairo_format_from_cogl_format (surface->cogl_format); + cairo_image_surface_t *image = (cairo_image_surface_t *) + cairo_image_surface_create (format, surface->width, surface->height); + if (image->base.status) + return image->base.status; + + cogl_texture_get_data (surface->texture, + cogl_texture_get_format (surface->texture), + 0, + image->data); + + image->base.is_clear = FALSE; + *image_out = image; + } else { + cairo_rectangle_int_t extents = { + 0, 0, surface->width, surface->height + }; + status = _cairo_cogl_surface_read_rect_to_image_surface (surface, &extents, + image_out); + if (unlikely (status)) + return status; + } + + *image_extra = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_cogl_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); +} + +static cairo_status_t +_cairo_cogl_surface_clear (cairo_cogl_surface_t *surface, + const cairo_color_t *color) +{ + /* Anything batched in the journal up until now is redundant... */ + _cairo_cogl_journal_discard (surface); + + /* XXX: we currently implicitly clear the depth and stencil buffer here + * but since we use the framebuffer_discard extension when available I + * suppose this doesn't matter too much. + * + * The main concern is that we want to avoid re-loading an external z + * buffer at the start of each frame, but also many gpu architectures have + * optimizations for how they handle the depth/stencil buffers and can get + * upset if they aren't cleared together at the start of the frame. + * + * FIXME: we need a way to assert that the clip stack currently isn't + * using the stencil buffer before clearing it here! + */ + cogl_framebuffer_clear4f (surface->framebuffer, + COGL_BUFFER_BIT_COLOR | + COGL_BUFFER_BIT_DEPTH | + COGL_BUFFER_BIT_STENCIL, + color->red * color->alpha, + color->green * color->alpha, + color->blue * color->alpha, + color->alpha); + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_cogl_path_fixed_rectangle (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y, + cairo_fixed_t width, + cairo_fixed_t height) +{ + cairo_status_t status; + + status = _cairo_path_fixed_move_to (path, x, y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_rel_line_to (path, width, 0); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_rel_line_to (path, 0, height); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_rel_line_to (path, -width, 0); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_close_path (path); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_cogl_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_cogl_surface_t *surface; + cairo_path_fixed_t path; + cairo_status_t status; + cairo_matrix_t identity; + + if (clip == NULL) { + if (op == CAIRO_OPERATOR_CLEAR) + return _cairo_cogl_surface_clear (abstract_surface, CAIRO_COLOR_TRANSPARENT); + else if (source->type == CAIRO_PATTERN_TYPE_SOLID && + (op == CAIRO_OPERATOR_SOURCE || + (op == CAIRO_OPERATOR_OVER && (((cairo_surface_t *)abstract_surface)->is_clear || _cairo_pattern_is_opaque_solid (source))))) { + return _cairo_cogl_surface_clear (abstract_surface, + &((cairo_solid_pattern_t *) source)->color); + } + } + + /* fallback to handling the paint in terms of a fill... */ + + surface = abstract_surface; + + _cairo_path_fixed_init (&path); + + status = _cairo_cogl_path_fixed_rectangle (&path, 0, 0, surface->width, surface->height); + if (unlikely (status)) + goto BAIL; + +#ifdef NEED_COGL_CONTEXT + /* XXX: in cairo-cogl-context.c we set some sideband data on the + * surface before issuing a fill so we need to do that here too... */ + surface->user_path = &path; + cairo_matrix_init_identity (&identity); + surface->ctm = &identity; + surface->ctm_inverse = &identity; + surface->path_is_rectangle = TRUE; + surface->path_rectangle_x = 0; + surface->path_rectangle_y = 0; + surface->path_rectangle_width = surface->width; + surface->path_rectangle_height = surface->height; +#endif + + status = _cairo_cogl_surface_fill (abstract_surface, + op, + source, + &path, + CAIRO_FILL_RULE_WINDING, + 1, + CAIRO_ANTIALIAS_DEFAULT, + clip); +BAIL: + _cairo_path_fixed_fini (&path); + return status; +} + +static CoglPipelineWrapMode +get_cogl_wrap_mode_for_extend (cairo_extend_t extend_mode) +{ + switch (extend_mode) + { + case CAIRO_EXTEND_NONE: + return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; + case CAIRO_EXTEND_PAD: + return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; + case CAIRO_EXTEND_REPEAT: + return COGL_PIPELINE_WRAP_MODE_REPEAT; + case CAIRO_EXTEND_REFLECT: + /* TODO: return COGL_PIPELINE_WRAP_MODE_MIRROR; */ + return CAIRO_EXTEND_REPEAT; + } + assert (0); /* not reached */ + return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; +} + +#if 0 +/* Given an arbitrary texture, check if it's already a pot texture and simply + * return it back if so. If not create a new pot texture, scale the old to + * fill it, unref the old and return a pointer to the new pot texture. */ +static cairo_int_status_t +_cairo_cogl_get_pot_texture (CoglContext *context, + CoglTexture *texture, + CoglTexture **pot_texture) +{ + int width = cogl_texture_get_width (texture); + int height = cogl_texture_get_height (texture); + int pot_width; + int pot_height; + CoglHandle offscreen = NULL; + CoglTexture2D *pot = NULL; + GError *error; + + pot_width = _cairo_cogl_util_next_p2 (width); + pot_height = _cairo_cogl_util_next_p2 (height); + + if (pot_width == width && pot_height == height) + return CAIRO_INT_STATUS_SUCCESS; + + for (;;) { + error = NULL; + pot = cogl_texture_2d_new_with_size (context, + pot_width, + pot_height, + cogl_texture_get_format (texture), + &error); + if (pot) + break; + else + g_error_free (error); + + if (pot_width > pot_height) + pot_width >>= 1; + else + pot_height >>= 1; + + if (!pot_width || !pot_height) + break; + } + + *pot_texture = COGL_TEXTURE (pot); + + if (!pot) + return CAIRO_INT_STATUS_NO_MEMORY; + + /* Use the GPU to do a bilinear filtered scale from npot to pot... */ + offscreen = cogl_offscreen_new_to_texture (COGL_TEXTURE (pot)); + error = NULL; + if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error)) { + /* NB: if we don't pass an error then Cogl is allowed to simply abort + * automatically. */ + g_error_free (error); + cogl_object_unref (pot); + *pot_texture = NULL; + return CAIRO_INT_STATUS_NO_MEMORY; + } + + cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen)); + cogl_set_source_texture (texture); + cogl_rectangle (-1, 1, 1, -1); + cogl_pop_framebuffer (); + + cogl_object_unref (offscreen); +} +#endif + +/* NB: a reference for the texture is transferred to the caller which should + * be unrefed */ +static CoglTexture * +_cairo_cogl_acquire_surface_texture (cairo_cogl_surface_t *reference_surface, + cairo_surface_t *abstract_surface) +{ + cairo_image_surface_t *image; + cairo_image_surface_t *acquired_image = NULL; + void *image_extra; + CoglPixelFormat format; + cairo_image_surface_t *image_clone = NULL; + CoglTexture2D *texture; + GError *error = NULL; + cairo_surface_t *clone; + + if (abstract_surface->device == reference_surface->base.device) { + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; + _cairo_cogl_surface_flush (surface, 0); + return surface->texture ? cogl_object_ref (surface->texture) : NULL; + } + + if (abstract_surface->type == CAIRO_SURFACE_TYPE_COGL) { + if (_cairo_surface_is_subsurface (abstract_surface)) { + cairo_cogl_surface_t *surface; + + surface = (cairo_cogl_surface_t *) + _cairo_surface_subsurface_get_target (abstract_surface); + if (surface->base.device == reference_surface->base.device) + return surface->texture ? cogl_object_ref (surface->texture) : NULL; + } + } + + clone = _cairo_surface_has_snapshot (abstract_surface, &_cairo_cogl_surface_backend); + if (clone) { + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)clone; + return surface->texture ? cogl_object_ref (surface->texture) : NULL; + } + + g_warning ("Uploading image surface to texture"); + + if (_cairo_surface_is_image (abstract_surface)) { + image = (cairo_image_surface_t *)abstract_surface; + } else { + cairo_status_t status = _cairo_surface_acquire_source_image (abstract_surface, + &acquired_image, &image_extra); + if (unlikely (status)) { + g_warning ("acquire_source_image failed: %s [%d]\n", + cairo_status_to_string (status), status); + return NULL; + } + image = acquired_image; + } + + format = get_cogl_format_from_cairo_format (image->format); + if (!format) + { + image_clone = _cairo_image_surface_coerce (image); + if (unlikely (image_clone->base.status)) { + g_warning ("image_surface_coerce failed"); + texture = NULL; + goto BAIL; + } + + format = get_cogl_format_from_cairo_format (image_clone->format); + assert (format); + } + + texture = cogl_texture_2d_new_from_data (to_device(reference_surface->base.device)->cogl_context, + image->width, + image->height, + format, /* incoming */ + format, /* desired */ + image->stride, + image->data, + &error); + if (!texture) { + g_warning ("Failed to allocate texture: %s", error->message); + g_error_free (error); + goto BAIL; + } + + clone = _cairo_cogl_surface_create_full (to_device(reference_surface->base.device), + reference_surface->ignore_alpha, + NULL, COGL_TEXTURE (texture)); + + _cairo_surface_attach_snapshot (abstract_surface, clone, NULL); + + /* Attaching the snapshot will take a reference on the clone surface... */ + cairo_surface_destroy (clone); + +BAIL: + if (image_clone) + cairo_surface_destroy (&image_clone->base); + if (acquired_image) + _cairo_surface_release_source_image (abstract_surface, acquired_image, image_extra); + + return COGL_TEXTURE (texture); +} + +/* NB: a reference for the texture is transferred to the caller which should + * be unrefed */ +static CoglTexture * +_cairo_cogl_acquire_pattern_texture (const cairo_pattern_t *pattern, + cairo_cogl_surface_t *destination, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + cairo_cogl_texture_attributes_t *attributes) +{ + CoglTexture *texture = NULL; + + switch ((int)pattern->type) + { + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_t *surface = ((cairo_surface_pattern_t *)pattern)->surface; + texture = _cairo_cogl_acquire_surface_texture (destination, surface); + if (!texture) + return NULL; + + /* XXX: determine if it would have no effect to change the + * extend mode to EXTEND_PAD instead since we can simply map + * EXTEND_PAD to CLAMP_TO_EDGE without needing fragment shader + * tricks or extra border texels. */ +#if 0 + /* TODO: We still need to consider HW such as SGX which doesn't have + * full support for NPOT textures. */ + if (pattern->extend == CAIRO_EXTEND_REPEAT || pattern->extend == CAIRO_EXTEND_REFLECT) { + _cairo_cogl_get_pot_texture (); + } +#endif + + cairo_matrix_init_identity (&attributes->matrix); + + /* Convert from un-normalized source coordinates in backend + * coordinates to normalized texture coordinates */ + cairo_matrix_scale (&attributes->matrix, + 1.0f / cogl_texture_get_width (texture), + 1.0f / cogl_texture_get_height (texture)); + + /* XXX: need to multiply in the pattern->matrix */ + + attributes->extend = pattern->extend; + attributes->filter = CAIRO_FILTER_BILINEAR; + attributes->has_component_alpha = pattern->has_component_alpha; + + attributes->s_wrap = get_cogl_wrap_mode_for_extend (pattern->extend); + attributes->t_wrap = attributes->s_wrap; + + return texture; + } + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: { + cairo_surface_t *surface; + cairo_matrix_t texture_matrix; + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + extents->width, extents->height); + if (_cairo_surface_offset_paint (surface, + extents->x, extents->y, + CAIRO_OPERATOR_SOURCE, + pattern, NULL)) { + cairo_surface_destroy (surface); + return NULL; + } + + texture = _cairo_cogl_acquire_surface_texture (destination, surface); + if (!texture) + goto BAIL; + + cairo_matrix_init_identity (&texture_matrix); + + /* Convert from un-normalized source coordinates in backend + * coordinates to normalized texture coordinates */ + cairo_matrix_scale (&texture_matrix, + 1.0f / cogl_texture_get_width (texture), + 1.0f / cogl_texture_get_height (texture)); + + cairo_matrix_translate (&texture_matrix, -extents->x, -extents->y); + + attributes->matrix = texture_matrix; + attributes->extend = pattern->extend; + attributes->filter = CAIRO_FILTER_NEAREST; + attributes->has_component_alpha = pattern->has_component_alpha; + + /* any pattern extend modes have already been dealt with... */ + attributes->s_wrap = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE; + attributes->t_wrap = attributes->s_wrap; + +BAIL: + cairo_surface_destroy (surface); + + return texture; + } + case CAIRO_PATTERN_TYPE_LINEAR: { + cairo_linear_pattern_t *linear_pattern = (cairo_linear_pattern_t *)pattern; + cairo_cogl_linear_gradient_t *gradient; + cairo_cogl_linear_texture_entry_t *linear_texture; + cairo_int_status_t status; + float a, b; + float dist; + float scale; + float angle; + + status = _cairo_cogl_get_linear_gradient (to_device(destination->base.device), + pattern->extend, + linear_pattern->base.n_stops, + linear_pattern->base.stops, + &gradient); + if (unlikely (status)) + return NULL; + + linear_texture = _cairo_cogl_linear_gradient_texture_for_extend (gradient, pattern->extend); + + attributes->extend = pattern->extend; + attributes->filter = CAIRO_FILTER_BILINEAR; + attributes->has_component_alpha = pattern->has_component_alpha; + attributes->s_wrap = get_cogl_wrap_mode_for_extend (pattern->extend); + attributes->t_wrap = COGL_PIPELINE_WRAP_MODE_REPEAT; + + cairo_matrix_init_identity (&attributes->matrix); + + a = linear_pattern->pd2.x - linear_pattern->pd1.x; + b = linear_pattern->pd2.y - linear_pattern->pd1.y; + dist = sqrtf (a*a + b*b); + scale = 1.0f / dist; + angle = - atan2f (b, a); + + cairo_matrix_rotate (&attributes->matrix, angle); + cairo_matrix_scale (&attributes->matrix, scale, scale); + + cairo_matrix_translate (&attributes->matrix, + -linear_pattern->pd1.x, + -linear_pattern->pd1.y); + + /* XXX: this caught me out: cairo doesn't follow the standard + * maths convention for multiplying two matrices A x B - cairo + * does B x A so the final matrix is as if A's transforms were + * applied first. + */ + cairo_matrix_multiply (&attributes->matrix, + &pattern->matrix, + &attributes->matrix); + + return cogl_object_ref (linear_texture->texture); + } + default: + g_warning ("Un-supported source type"); + return NULL; + } +} + +static void +set_layer_texture_with_attributes (CoglPipeline *pipeline, + int layer_index, + CoglTexture *texture, + cairo_cogl_texture_attributes_t *attributes) +{ + cogl_pipeline_set_layer_texture (pipeline, layer_index, texture); + + if (!_cairo_matrix_is_identity (&attributes->matrix)) { + cairo_matrix_t *m = &attributes->matrix; + float texture_matrixfv[16] = { + m->xx, m->yx, 0, 0, + m->xy, m->yy, 0, 0, + 0, 0, 1, 0, + m->x0, m->y0, 0, 1 + }; + CoglMatrix texture_matrix; + cogl_matrix_init_from_array (&texture_matrix, texture_matrixfv); + cogl_pipeline_set_layer_matrix (pipeline, layer_index, &texture_matrix); + } + + if (attributes->s_wrap != attributes->t_wrap) { + cogl_pipeline_set_layer_wrap_mode_s (pipeline, layer_index, attributes->s_wrap); + cogl_pipeline_set_layer_wrap_mode_t (pipeline, layer_index, attributes->t_wrap); + } else + cogl_pipeline_set_layer_wrap_mode (pipeline, layer_index, attributes->s_wrap); +} + +static CoglPipeline * +get_source_mask_operator_destination_pipeline (const cairo_pattern_t *mask, + const cairo_pattern_t *source, + cairo_operator_t op, + cairo_cogl_surface_t *destination, + cairo_composite_rectangles_t *extents) +{ + cairo_cogl_template_type template_type; + CoglPipeline *pipeline; + + switch ((int)source->type) + { + case CAIRO_PATTERN_TYPE_SOLID: + template_type = mask ? + CAIRO_COGL_TEMPLATE_TYPE_MASK_SOLID : CAIRO_COGL_TEMPLATE_TYPE_SOLID; + break; + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + template_type = mask ? + CAIRO_COGL_TEMPLATE_TYPE_MASK_TEXTURE : CAIRO_COGL_TEMPLATE_TYPE_TEXTURE; + break; + default: + g_warning ("Un-supported source type"); + return NULL; + } + + pipeline = cogl_pipeline_copy (to_device(destination->base.device)->template_pipelines[op][template_type]); + + if (source->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)source; + cogl_pipeline_set_color4f (pipeline, + solid_pattern->color.red * solid_pattern->color.alpha, + solid_pattern->color.green * solid_pattern->color.alpha, + solid_pattern->color.blue * solid_pattern->color.alpha, + solid_pattern->color.alpha); + } else { + cairo_cogl_texture_attributes_t attributes; + CoglTexture *texture = + _cairo_cogl_acquire_pattern_texture (source, destination, + &extents->bounded, + &extents->source_sample_area, + &attributes); + if (!texture) + goto BAIL; + set_layer_texture_with_attributes (pipeline, 0, texture, &attributes); + cogl_object_unref (texture); + } + + if (mask) { + if (mask->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)mask; + CoglColor color; + cogl_color_init_from_4f (&color, + solid_pattern->color.red * solid_pattern->color.alpha, + solid_pattern->color.green * solid_pattern->color.alpha, + solid_pattern->color.blue * solid_pattern->color.alpha, + solid_pattern->color.alpha); + cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color); + } else { + cairo_cogl_texture_attributes_t attributes; + CoglTexture *texture = + _cairo_cogl_acquire_pattern_texture (mask, destination, + &extents->bounded, + &extents->mask_sample_area, + &attributes); + if (!texture) + goto BAIL; + set_layer_texture_with_attributes (pipeline, 1, texture, &attributes); + cogl_object_unref (texture); + } + } + + return pipeline; + +BAIL: + cogl_object_unref (pipeline); + return NULL; +} + +#if 0 +CoglPrimitive * +_cairo_cogl_rectangle_new_p2t2t2 (float x, + float y, + float width, + float height) +{ + CoglVertexP2 vertices[] = { + {x, y}, {x, y + height}, {x + width, y + height}, + {x, y}, {x + width, y + height}, {x + width, y} + }; + CoglAttributeBuffer *buffer = cogl_attribute_buffer_new (sizeof (vertices)); + CoglAttribute *pos = cogl_attribute_new (buffer, + "cogl_position_in", + sizeof (CoglVertexP2), + 0, + 2, + COGL_ATTRIBUTE_TYPE_FLOAT); + CoglAttribute *tex_coords0 = cogl_attribute_new (buffer, + "cogl_tex_coord0_in", + sizeof (CoglVertexP2), + 0, + 2, + COGL_ATTRIBUTE_TYPE_FLOAT); + CoglAttribute *tex_coords0 = cogl_attribute_new (buffer, + "cogl_tex_coord0_in", + sizeof (CoglVertexP2), + 0, + 2, + COGL_ATTRIBUTE_TYPE_FLOAT); + CoglPrimitive *prim; + + cogl_buffer_set_data (COGL_BUFFER (buffer), 0, vertices, sizeof (vertices)); + + /* The attributes will now keep the buffer alive... */ + cogl_object_unref (buffer); + + prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, + 6, pos, tex_coords, NULL); + + /* The primitive will now keep the attribute alive... */ + cogl_object_unref (pos); + + return prim; +} +#endif + +static void +_cairo_cogl_log_clip (cairo_cogl_surface_t *surface, + const cairo_clip_t *clip) +{ + if (!_cairo_clip_equal (clip, surface->last_clip)) { + _cairo_cogl_journal_log_clip (surface, clip); + _cairo_clip_destroy (surface->last_clip); + surface->last_clip = _cairo_clip_copy (clip); + } +} + +static void +_cairo_cogl_maybe_log_clip (cairo_cogl_surface_t *surface, + cairo_composite_rectangles_t *composite) +{ + cairo_clip_t *clip = composite->clip; + + if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) + clip = NULL; + + if (clip == NULL) { + if (_cairo_composite_rectangles_can_reduce_clip (composite, + surface->last_clip)) + return; + } + + _cairo_cogl_log_clip (surface, clip); +} + +static cairo_bool_t +is_operator_supported (cairo_operator_t op) +{ + switch ((int)op) { + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_ADD: + return TRUE; + + default: + return FALSE; + } +} + +static cairo_int_status_t +_cairo_cogl_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_cogl_surface_t *surface = abstract_surface; + cairo_composite_rectangles_t extents; + cairo_status_t status; + CoglPipeline *pipeline; + cairo_matrix_t identity; + + /* XXX: Use this to smoke test the acquire_source/dest_image fallback + * paths... */ + //return CAIRO_INT_STATUS_UNSUPPORTED; + + if (!is_operator_supported (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_composite_rectangles_init_for_mask (&extents, + &surface->base, + op, source, mask, clip); + if (unlikely (status)) + return status; + + pipeline = get_source_mask_operator_destination_pipeline (mask, source, + op, surface, &extents); + if (!pipeline){ + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto BAIL; + } + + _cairo_cogl_maybe_log_clip (surface, &extents); + + cairo_matrix_init_identity (&identity); + _cairo_cogl_journal_log_rectangle (surface, pipeline, + extents.bounded.x, + extents.bounded.y, + extents.bounded.width, + extents.bounded.height, + 2, + &identity); + + /* The journal will take a reference on the pipeline and clip_path... */ + cogl_object_unref (pipeline); + +BAIL: + return status; +} + +static int +_cairo_cogl_source_n_layers (const cairo_pattern_t *source) +{ + switch ((int)source->type) + { + case CAIRO_PATTERN_TYPE_SOLID: + return 0; + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + case CAIRO_PATTERN_TYPE_SURFACE: + return 1; + default: + g_warning ("Unsupported source type"); + return 0; + } +} + +static cairo_bool_t +_cairo_cogl_path_fill_meta_equal (const void *key_a, const void *key_b) +{ + const cairo_cogl_path_fill_meta_t *meta0 = key_a; + const cairo_cogl_path_fill_meta_t *meta1 = key_b; + + return _cairo_path_fixed_equal (meta0->user_path, meta1->user_path); +} + +static cairo_bool_t +_cairo_cogl_stroke_style_equal (const cairo_stroke_style_t *a, + const cairo_stroke_style_t *b) +{ + if (a->line_width == b->line_width && + a->line_cap == b->line_cap && + a->line_join == b->line_join && + a->miter_limit == b->miter_limit && + a->num_dashes == b->num_dashes && + a->dash_offset == b->dash_offset) + { + unsigned int i; + for (i = 0; i < a->num_dashes; i++) { + if (a->dash[i] != b->dash[i]) + return FALSE; + } + } + return TRUE; +} + +static cairo_bool_t +_cairo_cogl_path_stroke_meta_equal (const void *key_a, const void *key_b) +{ + const cairo_cogl_path_stroke_meta_t *meta0 = key_a; + const cairo_cogl_path_stroke_meta_t *meta1 = key_b; + + return _cairo_cogl_stroke_style_equal (&meta0->style, &meta1->style) && + _cairo_path_fixed_equal (meta0->user_path, meta1->user_path); +} + +static cairo_cogl_path_stroke_meta_t * +_cairo_cogl_path_stroke_meta_reference (cairo_cogl_path_stroke_meta_t *meta) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); + + _cairo_reference_count_inc (&meta->ref_count); + + return meta; +} + +static void +_cairo_cogl_path_stroke_meta_destroy (cairo_cogl_path_stroke_meta_t *meta) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&meta->ref_count)) + return; + + _cairo_path_fixed_fini (meta->user_path); + free (meta->user_path); + + _cairo_stroke_style_fini (&meta->style); + + if (meta->prim) + cogl_object_unref (meta->prim); + + free (meta); +} + +static cairo_cogl_path_stroke_meta_t * +_cairo_cogl_path_stroke_meta_lookup (cairo_cogl_device_t *ctx, + unsigned long hash, + cairo_path_fixed_t *user_path, + const cairo_stroke_style_t *style, + double tolerance) +{ + cairo_cogl_path_stroke_meta_t *ret; + cairo_cogl_path_stroke_meta_t lookup; + + lookup.cache_entry.hash = hash; + lookup.user_path = user_path; + lookup.style = *style; + lookup.tolerance = tolerance; + + ret = _cairo_cache_lookup (&ctx->path_stroke_staging_cache, &lookup.cache_entry); + if (!ret) + ret = _cairo_cache_lookup (&ctx->path_stroke_prim_cache, &lookup.cache_entry); + return ret; +} + +static void +_cairo_cogl_path_stroke_meta_set_prim_size (cairo_cogl_surface_t *surface, + cairo_cogl_path_stroke_meta_t *meta, + size_t size) +{ + /* now that we know the meta structure is associated with a primitive + * we promote it from the staging cache into the primitive cache. + */ + + /* XXX: _cairo_cache borks if you try and remove an entry that's already + * been evicted so we explicitly look it up first... */ + if (_cairo_cache_lookup (&to_device(surface->base.device)->path_stroke_staging_cache, &meta->cache_entry)) { + _cairo_cogl_path_stroke_meta_reference (meta); + _cairo_cache_remove (&to_device(surface->base.device)->path_stroke_staging_cache, &meta->cache_entry); + } + + meta->cache_entry.size = size; + if (_cairo_cache_insert (&to_device(surface->base.device)->path_stroke_prim_cache, &meta->cache_entry) != + CAIRO_STATUS_SUCCESS) + _cairo_cogl_path_stroke_meta_destroy (meta); +} + +static unsigned int +_cairo_cogl_stroke_style_hash (unsigned int hash, + const cairo_stroke_style_t *style) +{ + unsigned int i; + hash = _cairo_hash_bytes (hash, &style->line_width, sizeof (style->line_width)); + hash = _cairo_hash_bytes (hash, &style->line_cap, sizeof (style->line_cap)); + hash = _cairo_hash_bytes (hash, &style->line_join, sizeof (style->line_join)); + hash = _cairo_hash_bytes (hash, &style->miter_limit, sizeof (style->miter_limit)); + hash = _cairo_hash_bytes (hash, &style->num_dashes, sizeof (style->num_dashes)); + hash = _cairo_hash_bytes (hash, &style->dash_offset, sizeof (style->dash_offset)); + for (i = 0; i < style->num_dashes; i++) + hash = _cairo_hash_bytes (hash, &style->dash[i], sizeof (double)); + return hash; +} + +static cairo_cogl_path_stroke_meta_t * +_cairo_cogl_get_path_stroke_meta (cairo_cogl_surface_t *surface, + const cairo_stroke_style_t *style, + double tolerance) +{ + unsigned long hash; + cairo_cogl_path_stroke_meta_t *meta = NULL; + cairo_path_fixed_t *meta_path = NULL; + cairo_status_t status; + + if (!surface->user_path) + return NULL; + + hash = _cairo_path_fixed_hash (surface->user_path); + hash = _cairo_cogl_stroke_style_hash (hash, style); + hash = _cairo_hash_bytes (hash, &tolerance, sizeof (tolerance)); + + meta = _cairo_cogl_path_stroke_meta_lookup (to_device(surface->base.device), hash, + surface->user_path, style, tolerance); + if (meta) + return meta; + + meta = calloc (1, sizeof (cairo_cogl_path_stroke_meta_t)); + if (!meta) + goto BAIL; + CAIRO_REFERENCE_COUNT_INIT (&meta->ref_count, 1); + meta->cache_entry.hash = hash; + meta->counter = 0; + meta_path = malloc (sizeof (cairo_path_fixed_t)); + if (!meta_path) + goto BAIL; + /* FIXME: we should add a ref-counted wrapper for our user_paths + * so we don't have to keep copying them here! */ + status = _cairo_path_fixed_init_copy (meta_path, surface->user_path); + if (unlikely (status)) + goto BAIL; + meta->user_path = meta_path; + meta->ctm_inverse = *surface->ctm_inverse; + + status = _cairo_stroke_style_init_copy (&meta->style, style); + if (unlikely (status)) { + _cairo_path_fixed_fini (meta_path); + goto BAIL; + } + meta->tolerance = tolerance; + + return meta; + +BAIL: + free (meta_path); + free (meta); + return NULL; +} + +static cairo_int_status_t +_cairo_cogl_stroke_to_primitive (cairo_cogl_surface_t *surface, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + int n_layers, + cairo_bool_t one_shot, + CoglPrimitive **primitive, + size_t *size) +{ + cairo_traps_t traps; + cairo_int_status_t status; + + _cairo_traps_init (&traps); + + status = _cairo_path_fixed_stroke_polygon_to_traps (path, style, + ctm, ctm_inverse, + tolerance, + &traps); + if (unlikely (status)) + goto BAIL; + + if (traps.num_traps == 0) { + status = CAIRO_INT_STATUS_NOTHING_TO_DO; + goto BAIL; + } + + *size = traps.num_traps * sizeof (CoglVertexP2) * 6; + + //g_print ("new stroke prim\n"); + *primitive = _cairo_cogl_traps_to_composite_prim (surface, &traps, n_layers, one_shot); + if (!*primitive) { + status = CAIRO_INT_STATUS_NO_MEMORY; + goto BAIL; + } + +BAIL: + _cairo_traps_fini (&traps); + return status; +} + +static cairo_int_status_t +_cairo_cogl_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; + cairo_composite_rectangles_t extents; + CoglPipeline *pipeline; + cairo_status_t status; +#ifdef ENABLE_PATH_CACHE + cairo_cogl_path_stroke_meta_t *meta = NULL; + cairo_matrix_t transform_matrix; +#endif + cairo_matrix_t *transform = NULL; + gboolean one_shot = TRUE; + CoglPrimitive *prim = NULL; + cairo_bool_t new_prim = FALSE; + + if (! is_operator_supported (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* FIXME - support unbounded operators */ + if (!_cairo_operator_bounded_by_mask (op)) { + /* Currently IN this is the only unbounded operator we aim to support + * in cairo-cogl. */ + assert (op == CAIRO_OPERATOR_IN); + g_warning ("FIXME: handle stroking with unbounded operators!"); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = _cairo_composite_rectangles_init_for_stroke (&extents, + &surface->base, + op, source, path, + style, + ctm, + clip); + if (unlikely (status)) + return status; + +#ifdef ENABLE_PATH_CACHE + /* FIXME: we are currently leaking the meta state if we don't reach + * the cache_insert at the end. */ + meta = _cairo_cogl_get_path_stroke_meta (surface, style, tolerance); + if (meta) { + prim = meta->prim; + if (prim) { + cairo_matrix_multiply (&transform_matrix, &meta->ctm_inverse, surface->ctm); + transform = &transform_matrix; + } else if (meta->counter++ > 10) + one_shot = FALSE; + } +#endif + + if (!prim) { + int n_layers = _cairo_cogl_source_n_layers (source); + size_t prim_size = 0; + status = _cairo_cogl_stroke_to_primitive (surface, path, style, + ctm, ctm_inverse, tolerance, + n_layers, one_shot, + &prim, &prim_size); + if (unlikely (status)) + return status; + new_prim = TRUE; +#if defined (ENABLE_PATH_CACHE) + if (meta) { + meta->prim = cogl_object_ref (prim); + _cairo_cogl_path_stroke_meta_set_prim_size (surface, meta, prim_size); + } +#endif + } + + pipeline = get_source_mask_operator_destination_pipeline (NULL, source, + op, surface, &extents); + if (!pipeline) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_cogl_maybe_log_clip (surface, &extents); + + _cairo_cogl_journal_log_primitive (surface, pipeline, prim, transform); + + /* The journal will take a reference on the pipeline and primitive... */ + cogl_object_unref (pipeline); + if (new_prim) + cogl_object_unref (prim); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_cogl_path_fill_meta_t * +_cairo_cogl_path_fill_meta_reference (cairo_cogl_path_fill_meta_t *meta) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); + + _cairo_reference_count_inc (&meta->ref_count); + + return meta; +} + +static void +_cairo_cogl_path_fill_meta_destroy (cairo_cogl_path_fill_meta_t *meta) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&meta->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&meta->ref_count)) + return; + + _cairo_path_fixed_fini (meta->user_path); + free (meta->user_path); + + if (meta->prim) + cogl_object_unref (meta->prim); + + free (meta); +} + +static cairo_cogl_path_fill_meta_t * +_cairo_cogl_path_fill_meta_lookup (cairo_cogl_device_t *ctx, + unsigned long hash, + cairo_path_fixed_t *user_path) +{ + cairo_cogl_path_fill_meta_t *ret; + cairo_cogl_path_fill_meta_t lookup; + + lookup.cache_entry.hash = hash; + lookup.user_path = user_path; + + ret = _cairo_cache_lookup (&ctx->path_fill_staging_cache, &lookup.cache_entry); + if (!ret) + ret = _cairo_cache_lookup (&ctx->path_fill_prim_cache, &lookup.cache_entry); + return ret; +} + +static void +_cairo_cogl_path_fill_meta_set_prim_size (cairo_cogl_surface_t *surface, + cairo_cogl_path_fill_meta_t *meta, + size_t size) +{ + /* now that we know the meta structure is associated with a primitive + * we promote it from the staging cache into the primitive cache. + */ + + /* XXX: _cairo_cache borks if you try and remove an entry that's already + * been evicted so we explicitly look it up first... */ + if (_cairo_cache_lookup (&to_device(surface->base.device)->path_fill_staging_cache, &meta->cache_entry)) { + _cairo_cogl_path_fill_meta_reference (meta); + _cairo_cache_remove (&to_device(surface->base.device)->path_fill_staging_cache, &meta->cache_entry); + } + + meta->cache_entry.size = size; + if (_cairo_cache_insert (&to_device(surface->base.device)->path_fill_prim_cache, &meta->cache_entry) != + CAIRO_STATUS_SUCCESS) + _cairo_cogl_path_fill_meta_destroy (meta); +} + +static cairo_cogl_path_fill_meta_t * +_cairo_cogl_get_path_fill_meta (cairo_cogl_surface_t *surface) +{ + unsigned long hash; + cairo_cogl_path_fill_meta_t *meta = NULL; + cairo_path_fixed_t *meta_path = NULL; + cairo_status_t status; + + if (!surface->user_path) + return NULL; + + hash = _cairo_path_fixed_hash (surface->user_path); + + meta = _cairo_cogl_path_fill_meta_lookup (to_device(surface->base.device), + hash, surface->user_path); + if (meta) + return meta; + + meta = calloc (1, sizeof (cairo_cogl_path_fill_meta_t)); + if (!meta) + goto BAIL; + meta->cache_entry.hash = hash; + meta->counter = 0; + CAIRO_REFERENCE_COUNT_INIT (&meta->ref_count, 1); + meta_path = malloc (sizeof (cairo_path_fixed_t)); + if (!meta_path) + goto BAIL; + /* FIXME: we should add a ref-counted wrapper for our user_paths + * so we don't have to keep copying them here! */ + status = _cairo_path_fixed_init_copy (meta_path, surface->user_path); + if (unlikely (status)) + goto BAIL; + meta->user_path = meta_path; + meta->ctm_inverse = *surface->ctm_inverse; + + /* To start with - until we associate a CoglPrimitive with the meta + * structure - we keep the meta in a staging structure until we + * see whether it actually gets re-used. */ + meta->cache_entry.size = 1; + if (_cairo_cache_insert (&to_device(surface->base.device)->path_fill_staging_cache, &meta->cache_entry) != + CAIRO_STATUS_SUCCESS) + _cairo_cogl_path_fill_meta_destroy (meta); + + return meta; + +BAIL: + free (meta_path); + free (meta); + return NULL; +} + +static cairo_int_status_t +_cairo_cogl_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_cogl_surface_t *surface = abstract_surface; + cairo_composite_rectangles_t extents; + cairo_status_t status; +#ifdef ENABLE_PATH_CACHE + cairo_cogl_path_fill_meta_t *meta = NULL; + cairo_matrix_t transform_matrix; +#endif + cairo_matrix_t *transform = NULL; + cairo_bool_t one_shot = TRUE; + CoglPrimitive *prim = NULL; + cairo_bool_t new_prim = FALSE; + CoglPipeline *pipeline; + + if (! is_operator_supported (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* FIXME - support unbounded operators */ + if (!_cairo_operator_bounded_by_mask (op)) { + /* Currently IN this is the only unbounded operator we aim to support + * in cairo-cogl. */ + assert (op == CAIRO_OPERATOR_IN); + g_warning ("FIXME: handle filling with unbounded operators!"); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = _cairo_composite_rectangles_init_for_fill (&extents, + &surface->base, + op, source, path, + clip); + if (unlikely (status)) + return status; + +#ifndef FILL_WITH_COGL_PATH +#ifdef ENABLE_PATH_CACHE + meta = _cairo_cogl_get_path_fill_meta (surface); + if (meta) { + prim = meta->prim; + if (prim) { + cairo_matrix_multiply (&transform_matrix, &meta->ctm_inverse, surface->ctm); + transform = &transform_matrix; + } else if (meta->counter++ > 10) + one_shot = FALSE; + } +#endif /* ENABLE_PATH_CACHE */ + + if (!prim) { + int n_layers = _cairo_cogl_source_n_layers (source); + size_t prim_size; + status = _cairo_cogl_fill_to_primitive (surface, path, fill_rule, tolerance, + one_shot, n_layers, &prim, &prim_size); + if (unlikely (status)) + return status; + new_prim = TRUE; +#ifdef ENABLE_PATH_CACHE + if (meta) { + meta->prim = cogl_object_ref (prim); + _cairo_cogl_path_fill_meta_set_prim_size (surface, meta, prim_size); + } +#endif /* ENABLE_PATH_CACHE */ + } + +#endif /* !FILL_WITH_COGL_PATH */ + + pipeline = get_source_mask_operator_destination_pipeline (NULL, source, + op, surface, &extents); + if (!pipeline) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_cogl_maybe_log_clip (surface, &extents); + +#ifndef FILL_WITH_COGL_PATH + _cairo_cogl_journal_log_primitive (surface, pipeline, prim, transform); + /* The journal will take a reference on the prim */ + if (new_prim) + cogl_object_unref (prim); +#else + CoglPath * cogl_path = _cairo_cogl_util_path_from_cairo (path, fill_rule, tolerance); + _cairo_cogl_journal_log_path (surface, pipeline, cogl_path); + cogl_object_unref (cogl_path); +#endif + + /* The journal will take a reference on the pipeline... */ + cogl_object_unref (pipeline); + + return CAIRO_INT_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_cogl_surface_fill_rectangle (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + double x, + double y, + double width, + double height, + cairo_matrix_t *ctm, + const cairo_clip_t *clip) +{ + cairo_cogl_surface_t *surface = abstract_surface; + CoglPipeline *pipeline; + + if (! is_operator_supported (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* FIXME - support unbounded operators */ + if (!_cairo_operator_bounded_by_mask (op)) { + /* Currently IN this is the only unbounded operator we aim to support + * in cairo-cogl. */ + assert (op == CAIRO_OPERATOR_IN); + g_warning ("FIXME: handle filling with unbounded operators!"); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* FIXME */ +#if 0 + status = _cairo_composite_rectangles_init_for_fill_rectangle (&extents, + &surface->base, + op, source, path, + clip); + if (unlikely (status)) + return status; +#endif + + if (source->type == CAIRO_PATTERN_TYPE_SOLID) { + double x1 = x; + double y1 = y; + double x2 = x1 + width; + double y2 = y1 + height; + + pipeline = get_source_mask_operator_destination_pipeline (NULL, source, + op, surface, NULL); + if (!pipeline) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_cogl_log_clip (surface, clip); + + _cairo_cogl_journal_log_rectangle (surface, + pipeline, + x1, y1, x2, y2, + 0, + ctm); + return CAIRO_INT_STATUS_SUCCESS; + } else + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* TODO: + * We need to acquire the textures here, look at the corresponding + * attributes and see if this can be trivially handled by logging + * a textured rectangle only needing simple scaling or translation + * of texture coordinates. + * + * At this point we should also aim to remap the default + * EXTEND_NONE mode to EXTEND_PAD which is more efficient if we + * know it makes no difference either way since we can map that to + * CLAMP_TO_EDGE. + */ +} + +static cairo_int_status_t +_cairo_cogl_surface_show_glyphs (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +const cairo_surface_backend_t _cairo_cogl_surface_backend = { + CAIRO_SURFACE_TYPE_COGL, + _cairo_cogl_surface_finish, +#ifdef NEED_COGL_CONTEXT + _cairo_cogl_context_create, +#else + _cairo_default_context_create, +#endif + + _cairo_cogl_surface_create_similar, + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + _cairo_cogl_surface_acquire_source_image, + _cairo_cogl_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_cogl_surface_get_extents, + NULL, /* get_font_options */ + + _cairo_cogl_surface_flush, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_cogl_surface_paint, + _cairo_cogl_surface_mask, + _cairo_cogl_surface_stroke, + _cairo_cogl_surface_fill, + NULL, /* fill_stroke*/ + _cairo_surface_fallback_glyphs, +}; + +static cairo_surface_t * +_cairo_cogl_surface_create_full (cairo_cogl_device_t *dev, + cairo_bool_t ignore_alpha, + CoglFramebuffer *framebuffer, + CoglTexture *texture) +{ + cairo_cogl_surface_t *surface; + cairo_status_t status; + + status = cairo_device_acquire (&dev->base); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + surface = malloc (sizeof (cairo_cogl_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface->ignore_alpha = ignore_alpha; + + surface->framebuffer = framebuffer; + if (framebuffer) { + surface->width = cogl_framebuffer_get_width (framebuffer); + surface->height = cogl_framebuffer_get_height (framebuffer); + surface->cogl_format = cogl_framebuffer_get_color_format (framebuffer); + cogl_object_ref (framebuffer); + } + + /* FIXME: If texture == NULL and we are given an offscreen framebuffer + * then we want a way to poke inside the framebuffer to get a texture */ + surface->texture = texture; + if (texture) { + if (!framebuffer) { + surface->width = cogl_texture_get_width (texture); + surface->height = cogl_texture_get_height (texture); + surface->cogl_format = cogl_texture_get_format (texture); + } + cogl_object_ref (texture); + } + + assert(surface->width && surface->height); + + surface->journal = NULL; + + surface->buffer_stack = NULL; + surface->buffer_stack_size = 4096; + + surface->last_clip = NULL; + + surface->n_clip_updates_per_frame = 0; + + _cairo_surface_init (&surface->base, + &_cairo_cogl_surface_backend, + &dev->base, + CAIRO_CONTENT_COLOR_ALPHA); + + return &surface->base; +} + +cairo_surface_t * +cairo_cogl_surface_create (cairo_device_t *abstract_device, + CoglFramebuffer *framebuffer) +{ + cairo_cogl_device_t *dev = (cairo_cogl_device_t *)abstract_device; + + if (abstract_device == NULL) + return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_ERROR); + + if (abstract_device->status) + return _cairo_surface_create_in_error (abstract_device->status); + + if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_COGL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + + return _cairo_cogl_surface_create_full (dev, FALSE, framebuffer, NULL); +} +slim_hidden_def (cairo_cogl_surface_create); + +CoglFramebuffer * +cairo_cogl_surface_get_framebuffer (cairo_surface_t *abstract_surface) +{ + cairo_cogl_surface_t *surface; + + if (abstract_surface->backend != &_cairo_cogl_surface_backend) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + surface = (cairo_cogl_surface_t *) abstract_surface; + + return surface->framebuffer; +} +slim_hidden_def (cairo_cogl_surface_get_framebuffer); + +CoglTexture * +cairo_cogl_surface_get_texture (cairo_surface_t *abstract_surface) +{ + cairo_cogl_surface_t *surface; + + if (abstract_surface->backend != &_cairo_cogl_surface_backend) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + surface = (cairo_cogl_surface_t *) abstract_surface; + + return surface->texture; +} +slim_hidden_def (cairo_cogl_surface_get_texture); + +static cairo_status_t +_cairo_cogl_device_flush (void *device) +{ + cairo_status_t status; + + status = cairo_device_acquire (device); + if (unlikely (status)) + return status; + + /* XXX: we don't need to flush Cogl here, we just need to flush + * any batching we do of compositing primitives. */ + + cairo_device_release (device); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_cogl_device_finish (void *device) +{ + cairo_status_t status; + + status = cairo_device_acquire (device); + if (unlikely (status)) + return; + + /* XXX: Drop references to external resources */ + + cairo_device_release (device); +} + +static void +_cairo_cogl_device_destroy (void *device) +{ + cairo_cogl_device_t *dev = device; + + /* FIXME: Free stuff! */ + + g_free (dev); +} + +static const cairo_device_backend_t _cairo_cogl_device_backend = { + CAIRO_DEVICE_TYPE_COGL, + + NULL, /* lock */ + NULL, /* unlock */ + + _cairo_cogl_device_flush, + _cairo_cogl_device_finish, + _cairo_cogl_device_destroy, +}; + +static cairo_bool_t +set_blend (CoglPipeline *pipeline, const char *blend_string) +{ + GError *error = NULL; + if (!cogl_pipeline_set_blend (pipeline, blend_string, &error)) { + g_warning ("Unsupported blend string with current gpu/driver: %s", blend_string); + g_error_free (error); + return FALSE; + } + return TRUE; +} + +static cairo_bool_t +_cairo_cogl_setup_op_state (CoglPipeline *pipeline, cairo_operator_t op) +{ + cairo_bool_t status = FALSE; + + switch ((int)op) + { + case CAIRO_OPERATOR_SOURCE: + status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)"); + break; + case CAIRO_OPERATOR_OVER: + status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR * (1 - SRC_COLOR[A]))"); + break; + case CAIRO_OPERATOR_IN: + status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * DST_COLOR[A], 0)"); + break; + case CAIRO_OPERATOR_DEST_OVER: + status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), DST_COLOR)"); + break; + case CAIRO_OPERATOR_DEST_IN: + status = set_blend (pipeline, "RGBA = ADD (0, DST_COLOR * SRC_COLOR[A])"); + break; + case CAIRO_OPERATOR_ADD: + status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR)"); + break; + } + + return status; +} + +static void +create_templates_for_op (cairo_cogl_device_t *dev, cairo_operator_t op) +{ + CoglPipeline *base = cogl_pipeline_new (); + CoglPipeline *pipeline; + CoglColor color; + + if (!_cairo_cogl_setup_op_state (base, op)) { + cogl_object_unref (base); + return; + } + + dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID] = base; + + pipeline = cogl_pipeline_copy (base); + cogl_pipeline_set_layer_texture (pipeline, 0, dev->dummy_texture); + dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_TEXTURE] = pipeline; + + pipeline = cogl_pipeline_copy (base); + cogl_pipeline_set_layer_combine (pipeline, 1, + "RGBA = MODULATE (PREVIOUS, CONSTANT[A])", + NULL); + cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color); + cogl_pipeline_set_layer_texture (pipeline, 1, dev->dummy_texture); + dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_MASK_SOLID] = pipeline; + + pipeline = cogl_pipeline_copy (base); + cogl_pipeline_set_layer_combine (pipeline, 1, + "RGBA = MODULATE (PREVIOUS, TEXTURE[A])", + NULL); + cogl_pipeline_set_layer_texture (pipeline, 1, dev->dummy_texture); + dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_MASK_TEXTURE] = pipeline; +} + +cairo_device_t * +cairo_cogl_device_create (CoglContext *cogl_context) +{ + cairo_cogl_device_t *dev = g_new0 (cairo_cogl_device_t, 1); + cairo_status_t status; + + dev->backend_vtable_initialized = FALSE; + + dev->cogl_context = cogl_context; + + dev->dummy_texture = cogl_texture_new_with_size (1, 1, + COGL_TEXTURE_NO_SLICING, + COGL_PIXEL_FORMAT_ANY); + if (!dev->dummy_texture) + goto ERROR; + + memset (dev->template_pipelines, 0, sizeof (dev->template_pipelines)); + create_templates_for_op (dev, CAIRO_OPERATOR_SOURCE); + create_templates_for_op (dev, CAIRO_OPERATOR_OVER); + create_templates_for_op (dev, CAIRO_OPERATOR_IN); + create_templates_for_op (dev, CAIRO_OPERATOR_DEST_OVER); + create_templates_for_op (dev, CAIRO_OPERATOR_DEST_IN); + create_templates_for_op (dev, CAIRO_OPERATOR_ADD); + + status = _cairo_cache_init (&dev->linear_cache, + _cairo_cogl_linear_gradient_equal, + NULL, + (cairo_destroy_func_t) _cairo_cogl_linear_gradient_destroy, + CAIRO_COGL_LINEAR_GRADIENT_CACHE_SIZE); + if (unlikely (status)) + return _cairo_device_create_in_error(status); + + status = _cairo_cache_init (&dev->path_fill_staging_cache, + _cairo_cogl_path_fill_meta_equal, + NULL, + (cairo_destroy_func_t) _cairo_cogl_path_fill_meta_destroy, + 1000); + + status = _cairo_cache_init (&dev->path_stroke_staging_cache, + _cairo_cogl_path_stroke_meta_equal, + NULL, + (cairo_destroy_func_t) _cairo_cogl_path_stroke_meta_destroy, + 1000); + + status = _cairo_cache_init (&dev->path_fill_prim_cache, + _cairo_cogl_path_fill_meta_equal, + NULL, + (cairo_destroy_func_t) _cairo_cogl_path_fill_meta_destroy, + CAIRO_COGL_PATH_META_CACHE_SIZE); + + status = _cairo_cache_init (&dev->path_stroke_prim_cache, + _cairo_cogl_path_stroke_meta_equal, + NULL, + (cairo_destroy_func_t) _cairo_cogl_path_stroke_meta_destroy, + CAIRO_COGL_PATH_META_CACHE_SIZE); + + _cairo_device_init (&dev->base, &_cairo_cogl_device_backend); + return &dev->base; + +ERROR: + g_free (dev); + return _cairo_device_create_in_error (CAIRO_STATUS_DEVICE_ERROR); +} +slim_hidden_def (cairo_cogl_device_create); + +void +cairo_cogl_surface_end_frame (cairo_surface_t *abstract_surface) +{ + cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface; + cairo_surface_flush (abstract_surface); + + //g_print ("n_clip_update_per_frame = %d\n", surface->n_clip_updates_per_frame); + surface->n_clip_updates_per_frame = 0; +} +slim_hidden_def (cairo_cogl_surface_end_frame); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils-private.h new file mode 100644 index 00000000000..ee77f3034c3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils-private.h @@ -0,0 +1,54 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ + +#ifndef CAIRO_COGL_UTILS_PRIVATE_H +#define CAIRO_COGL_UTILS_PRIVATE_H + +#include "cairo-path-fixed-private.h" +#include + +CoglPath * +_cairo_cogl_util_path_from_cairo (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + float tolerance); + +int +_cairo_cogl_util_next_p2 (int a); + +#define CAIRO_FIXED_ONE_FLOAT ((float)(1 << CAIRO_FIXED_FRAC_BITS)) + +static inline float +_cairo_cogl_util_fixed_to_float (cairo_fixed_t f) +{ + return ((float) f) / CAIRO_FIXED_ONE_FLOAT; +} + +#endif /* CAIRO_COGL_UTILS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils.c b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils.c new file mode 100644 index 00000000000..4f02aaa52da --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl-utils.c @@ -0,0 +1,126 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Robert Bragg + */ + +#include "cairoint.h" +#include "cairo-cogl-utils-private.h" + +#include +#include + +static cairo_status_t +_cogl_move_to (void *closure, + const cairo_point_t *point) +{ + cogl_path_move_to (closure, + _cairo_cogl_util_fixed_to_float (point->x), + _cairo_cogl_util_fixed_to_float (point->y)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cogl_line_to (void *closure, + const cairo_point_t *point) +{ + cogl_path_line_to (closure, + _cairo_cogl_util_fixed_to_float (point->x), + _cairo_cogl_util_fixed_to_float (point->y)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cogl_curve_to (void *closure, + const cairo_point_t *p0, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + cogl_path_curve_to (closure, + _cairo_cogl_util_fixed_to_float (p0->x), + _cairo_cogl_util_fixed_to_float (p0->y), + _cairo_cogl_util_fixed_to_float (p1->x), + _cairo_cogl_util_fixed_to_float (p1->y), + _cairo_cogl_util_fixed_to_float (p2->x), + _cairo_cogl_util_fixed_to_float (p2->y)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cogl_close_path (void *closure) +{ + cogl_path_close (closure); + return CAIRO_STATUS_SUCCESS; +} + +CoglPath * +_cairo_cogl_util_path_from_cairo (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + float tolerance) +{ + CoglPath *cogl_path = cogl_path_new (); + cairo_status_t status; + + if (fill_rule == CAIRO_FILL_RULE_EVEN_ODD) + cogl_path_set_fill_rule (cogl_path, COGL_PATH_FILL_RULE_EVEN_ODD); + else + cogl_path_set_fill_rule (cogl_path, COGL_PATH_FILL_RULE_NON_ZERO); + +#ifdef USE_CAIRO_PATH_FLATTENER + /* XXX: rely on cairo to do path flattening, since it seems Cogl's + * curve_to flattening is much slower */ + status = _cairo_path_fixed_interpret_flat (path, + _cogl_move_to, + _cogl_line_to, + _cogl_close_path, + cogl_path, + tolerance); +#else + status = _cairo_path_fixed_interpret (path, + _cogl_move_to, + _cogl_line_to, + _cogl_curve_to, + _cogl_close_path, + cogl_path); +#endif + + assert (status == CAIRO_STATUS_SUCCESS); + return cogl_path; +} + +int +_cairo_cogl_util_next_p2 (int a) +{ + int rval = 1; + + while (rval < a) + rval <<= 1; + + return rval; +} + diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-cogl.h b/Build/source/libs/cairo/cairo-src/src/cairo-cogl.h new file mode 100644 index 00000000000..f270d74d307 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-cogl.h @@ -0,0 +1,69 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Corporation. + * + * Contributor(s): + * Robert Bragg + */ + +#ifndef CAIRO_VG_H +#define CAIRO_VG_H + +#include "cairo.h" + +#if CAIRO_HAS_COGL_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_device_t * +cairo_cogl_device_create (CoglContext *context); + +cairo_public cairo_surface_t * +cairo_cogl_surface_create (cairo_device_t *device, + CoglFramebuffer *framebuffer); + +cairo_public CoglFramebuffer * +cairo_cogl_surface_get_framebuffer (cairo_surface_t *surface); + +cairo_public CoglTexture * +cairo_cogl_surface_get_texture (cairo_surface_t *surface); + +cairo_public void +cairo_cogl_surface_end_frame (cairo_surface_t *surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_COGL_SURFACE*/ +# error Cairo was not compiled with support for the Cogl backend +#endif /* CAIRO_HAS_COGL_SURFACE*/ + +#endif /* CAIRO_COGL_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-color.c b/Build/source/libs/cairo/cairo-src/src/cairo-color.c new file mode 100644 index 00000000000..c2a11a17738 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-color.c @@ -0,0 +1,193 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +static cairo_color_t const cairo_color_white = { + 1.0, 1.0, 1.0, 1.0, + 0xffff, 0xffff, 0xffff, 0xffff +}; + +static cairo_color_t const cairo_color_black = { + 0.0, 0.0, 0.0, 1.0, + 0x0, 0x0, 0x0, 0xffff +}; + +static cairo_color_t const cairo_color_transparent = { + 0.0, 0.0, 0.0, 0.0, + 0x0, 0x0, 0x0, 0x0 +}; + +static cairo_color_t const cairo_color_magenta = { + 1.0, 0.0, 1.0, 1.0, + 0xffff, 0x0, 0xffff, 0xffff +}; + +const cairo_color_t * +_cairo_stock_color (cairo_stock_t stock) +{ + switch (stock) { + case CAIRO_STOCK_WHITE: + return &cairo_color_white; + case CAIRO_STOCK_BLACK: + return &cairo_color_black; + case CAIRO_STOCK_TRANSPARENT: + return &cairo_color_transparent; + + case CAIRO_STOCK_NUM_COLORS: + default: + ASSERT_NOT_REACHED; + /* If the user can get here somehow, give a color that indicates a + * problem. */ + return &cairo_color_magenta; + } +} + +/* Convert a double in [0.0, 1.0] to an integer in [0, 65535] + * The conversion is designed to choose the integer i such that + * i / 65535.0 is as close as possible to the input value. + */ +uint16_t +_cairo_color_double_to_short (double d) +{ + return d * 65535.0 + 0.5; +} + +static void +_cairo_color_compute_shorts (cairo_color_t *color) +{ + color->red_short = _cairo_color_double_to_short (color->red * color->alpha); + color->green_short = _cairo_color_double_to_short (color->green * color->alpha); + color->blue_short = _cairo_color_double_to_short (color->blue * color->alpha); + color->alpha_short = _cairo_color_double_to_short (color->alpha); +} + +void +_cairo_color_init_rgba (cairo_color_t *color, + double red, double green, double blue, + double alpha) +{ + color->red = red; + color->green = green; + color->blue = blue; + color->alpha = alpha; + + _cairo_color_compute_shorts (color); +} + +void +_cairo_color_multiply_alpha (cairo_color_t *color, + double alpha) +{ + color->alpha *= alpha; + + _cairo_color_compute_shorts (color); +} + +void +_cairo_color_get_rgba (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha) +{ + *red = color->red; + *green = color->green; + *blue = color->blue; + *alpha = color->alpha; +} + +void +_cairo_color_get_rgba_premultiplied (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha) +{ + *red = color->red * color->alpha; + *green = color->green * color->alpha; + *blue = color->blue * color->alpha; + *alpha = color->alpha; +} + +/* NB: This function works both for unmultiplied and premultiplied colors */ +cairo_bool_t +_cairo_color_equal (const cairo_color_t *color_a, + const cairo_color_t *color_b) +{ + if (color_a == color_b) + return TRUE; + + if (color_a->alpha_short != color_b->alpha_short) + return FALSE; + + if (color_a->alpha_short == 0) + return TRUE; + + return color_a->red_short == color_b->red_short && + color_a->green_short == color_b->green_short && + color_a->blue_short == color_b->blue_short; +} + +cairo_bool_t +_cairo_color_stop_equal (const cairo_color_stop_t *color_a, + const cairo_color_stop_t *color_b) +{ + if (color_a == color_b) + return TRUE; + + return color_a->alpha_short == color_b->alpha_short && + color_a->red_short == color_b->red_short && + color_a->green_short == color_b->green_short && + color_a->blue_short == color_b->blue_short; +} + +cairo_content_t +_cairo_color_get_content (const cairo_color_t *color) +{ + if (CAIRO_COLOR_IS_OPAQUE (color)) + return CAIRO_CONTENT_COLOR; + + if (color->red_short == 0 && + color->green_short == 0 && + color->blue_short == 0) + { + return CAIRO_CONTENT_ALPHA; + } + + return CAIRO_CONTENT_COLOR_ALPHA; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-combsort-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-combsort-inline.h new file mode 100644 index 00000000000..d359faeb5b8 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-combsort-inline.h @@ -0,0 +1,94 @@ +/* + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +/* This fragment implements a comb sort (specifically combsort11) */ +#ifndef _HAVE_CAIRO_COMBSORT_NEWGAP +#define _HAVE_CAIRO_COMBSORT_NEWGAP +static inline unsigned int +_cairo_combsort_newgap (unsigned int gap) +{ + gap = 10 * gap / 13; + if (gap == 9 || gap == 10) + gap = 11; + if (gap < 1) + gap = 1; + return gap; +} +#endif + +#define CAIRO_COMBSORT_DECLARE(NAME, TYPE, CMP) \ +static void \ +NAME (TYPE *base, unsigned int nmemb) \ +{ \ + unsigned int gap = nmemb; \ + unsigned int i, j; \ + int swapped; \ + do { \ + gap = _cairo_combsort_newgap (gap); \ + swapped = gap > 1; \ + for (i = 0; i < nmemb-gap ; i++) { \ + j = i + gap; \ + if (CMP (base[i], base[j]) > 0 ) { \ + TYPE tmp; \ + tmp = base[i]; \ + base[i] = base[j]; \ + base[j] = tmp; \ + swapped = 1; \ + } \ + } \ + } while (swapped); \ +} + +#define CAIRO_COMBSORT_DECLARE_WITH_DATA(NAME, TYPE, CMP) \ +static void \ +NAME (TYPE *base, unsigned int nmemb, void *data) \ +{ \ + unsigned int gap = nmemb; \ + unsigned int i, j; \ + int swapped; \ + do { \ + gap = _cairo_combsort_newgap (gap); \ + swapped = gap > 1; \ + for (i = 0; i < nmemb-gap ; i++) { \ + j = i + gap; \ + if (CMP (base[i], base[j], data) > 0 ) { \ + TYPE tmp; \ + tmp = base[i]; \ + base[i] = base[j]; \ + base[j] = tmp; \ + swapped = 1; \ + } \ + } \ + } while (swapped); \ +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-compiler-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-compiler-private.h new file mode 100644 index 00000000000..216e71b4ec3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-compiler-private.h @@ -0,0 +1,244 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_COMPILER_PRIVATE_H +#define CAIRO_COMPILER_PRIVATE_H + +#include "cairo.h" + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +/* Size in bytes of buffer to use off the stack per functions. + * Mostly used by text functions. For larger allocations, they'll + * malloc(). */ +#ifndef CAIRO_STACK_BUFFER_SIZE +#define CAIRO_STACK_BUFFER_SIZE (512 * sizeof (int)) +#endif + +#define CAIRO_STACK_ARRAY_LENGTH(T) (CAIRO_STACK_BUFFER_SIZE / sizeof(T)) + +/* + * The goal of this block is to define the following macros for + * providing faster linkage to functions in the public API for calls + * from within cairo. + * + * slim_hidden_proto(f) + * slim_hidden_proto_no_warn(f) + * + * Declares `f' as a library internal function and hides the + * function from the global symbol table. This macro must be + * expanded after `f' has been declared with a prototype but before + * any calls to the function are seen by the compiler. The no_warn + * variant inhibits warnings about the return value being unused at + * call sites. The macro works by renaming `f' to an internal name + * in the symbol table and hiding that. As far as cairo internal + * calls are concerned they're calling a library internal function + * and thus don't need to bounce via the PLT. + * + * slim_hidden_def(f) + * + * Exports `f' back to the global symbol table. This macro must be + * expanded right after the function definition and only for symbols + * hidden previously with slim_hidden_proto(). The macro works by + * adding a global entry to the symbol table which points at the + * internal name of `f' created by slim_hidden_proto(). + * + * Functions in the public API which aren't called by the library + * don't need to be hidden and re-exported using the slim hidden + * macros. + */ +#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun) +# define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private +# define slim_hidden_proto_no_warn(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn +# define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name)) +# define slim_hidden_int_name(name) INT_##name +# define slim_hidden_proto1(name, internal) \ + extern __typeof (name) name \ + __asm__ (slim_hidden_asmname (internal)) +# define slim_hidden_def1(name, internal) \ + extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name)) \ + __attribute__((__alias__(slim_hidden_asmname(internal)))) +# define slim_hidden_ulp slim_hidden_ulp1(__USER_LABEL_PREFIX__) +# define slim_hidden_ulp1(x) slim_hidden_ulp2(x) +# define slim_hidden_ulp2(x) #x +# define slim_hidden_asmname(name) slim_hidden_asmname1(name) +# define slim_hidden_asmname1(name) slim_hidden_ulp #name +#else +# define slim_hidden_proto(name) int _cairo_dummy_prototype(void) +# define slim_hidden_proto_no_warn(name) int _cairo_dummy_prototype(void) +# define slim_hidden_def(name) int _cairo_dummy_prototype(void) +#endif + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \ + __attribute__((__format__(__printf__, fmt_index, va_index))) +#else +#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) +#endif + +/* slim_internal.h */ +#define CAIRO_HAS_HIDDEN_SYMBOLS 1 +#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && \ + (defined(__ELF__) || defined(__APPLE__)) && \ + !defined(__sun) +#define cairo_private_no_warn __attribute__((__visibility__("hidden"))) +#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) +#define cairo_private_no_warn __hidden +#else /* not gcc >= 3.3 and not Sun Studio >= 8 */ +#define cairo_private_no_warn +#undef CAIRO_HAS_HIDDEN_SYMBOLS +#endif + +#ifndef WARN_UNUSED_RESULT +#define WARN_UNUSED_RESULT +#endif +/* Add attribute(warn_unused_result) if supported */ +#define cairo_warn WARN_UNUSED_RESULT +#define cairo_private cairo_private_no_warn cairo_warn + +/* This macro allow us to deprecate a function by providing an alias + for the old function name to the new function name. With this + macro, binary compatibility is preserved. The macro only works on + some platforms --- tough. + + Meanwhile, new definitions in the public header file break the + source code so that it will no longer link against the old + symbols. Instead it will give a descriptive error message + indicating that the old function has been deprecated by the new + function. +*/ +#if __GNUC__ >= 2 && defined(__ELF__) +# define CAIRO_FUNCTION_ALIAS(old, new) \ + extern __typeof (new) old \ + __asm__ ("" #old) \ + __attribute__((__alias__("" #new))) +#else +# define CAIRO_FUNCTION_ALIAS(old, new) +#endif + +/* + * Cairo uses the following function attributes in order to improve the + * generated code (effectively by manual inter-procedural analysis). + * + * 'cairo_pure': The function is only allowed to read from its arguments + * and global memory (i.e. following a pointer argument or + * accessing a shared variable). The return value should + * only depend on its arguments, and for an identical set of + * arguments should return the same value. + * + * 'cairo_const': The function is only allowed to read from its arguments. + * It is not allowed to access global memory. The return + * value should only depend its arguments, and for an + * identical set of arguments should return the same value. + * This is currently the most strict function attribute. + * + * Both these function attributes allow gcc to perform CSE and + * constant-folding, with 'cairo_const 'also guaranteeing that pointer contents + * do not change across the function call. + */ +#if __GNUC__ >= 3 +#define cairo_pure __attribute__((pure)) +#define cairo_const __attribute__((const)) +#define cairo_always_inline inline __attribute__((always_inline)) +#else +#define cairo_pure +#define cairo_const +#define cairo_always_inline inline +#endif + +#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) +#define likely(expr) (__builtin_expect (!!(expr), 1)) +#define unlikely(expr) (__builtin_expect (!!(expr), 0)) +#else +#define likely(expr) (expr) +#define unlikely(expr) (expr) +#endif + +#ifndef __GNUC__ +#undef __attribute__ +#define __attribute__(x) +#endif + +#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) +#define access _access +#define fdopen _fdopen +#define hypot _hypot +#define pclose _pclose +#define popen _popen +#define snprintf _snprintf +#define strdup _strdup +#define unlink _unlink +#define vsnprintf _vsnprintf +#endif + +#ifdef _MSC_VER +#ifndef __cplusplus +#undef inline +#define inline __inline +#endif +#endif + +#if defined(_MSC_VER) && defined(_M_IX86) +/* When compiling with /Gy and /OPT:ICF identical functions will be folded in together. + The CAIRO_ENSURE_UNIQUE macro ensures that a function is always unique and + will never be folded into another one. Something like this might eventually + be needed for GCC but it seems fine for now. */ +#define CAIRO_ENSURE_UNIQUE \ + do { \ + char file[] = __FILE__; \ + __asm { \ + __asm jmp __internal_skip_line_no \ + __asm _emit (__COUNTER__ & 0xff) \ + __asm _emit ((__COUNTER__>>8) & 0xff) \ + __asm _emit ((__COUNTER__>>16) & 0xff)\ + __asm _emit ((__COUNTER__>>24) & 0xff)\ + __asm lea eax, dword ptr file \ + __asm __internal_skip_line_no: \ + }; \ + } while (0) +#else +#define CAIRO_ENSURE_UNIQUE do { } while (0) +#endif + +#ifdef __STRICT_ANSI__ +#undef inline +#define inline __inline__ +#endif + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles-private.h new file mode 100644 index 00000000000..fd7728995de --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles-private.h @@ -0,0 +1,159 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H +#define CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-error-private.h" +#include "cairo-pattern-private.h" + +CAIRO_BEGIN_DECLS + +/* Rectangles that take part in a composite operation. + * + * The source and mask track the extents of the respective patterns in device + * space. The unbounded rectangle is essentially the clip rectangle. And the + * intersection of all is the bounded rectangle, which is the minimum extents + * the operation may require. Whether or not the operation is actually bounded + * is tracked in the is_bounded boolean. + * + */ +struct _cairo_composite_rectangles { + cairo_surface_t *surface; + cairo_operator_t op; + + cairo_rectangle_int_t source; + cairo_rectangle_int_t mask; + cairo_rectangle_int_t destination; + + cairo_rectangle_int_t bounded; /* source? IN mask? IN unbounded */ + cairo_rectangle_int_t unbounded; /* destination IN clip */ + uint32_t is_bounded; + + cairo_rectangle_int_t source_sample_area; + cairo_rectangle_int_t mask_sample_area; + + cairo_pattern_union_t source_pattern; + cairo_pattern_union_t mask_pattern; + const cairo_pattern_t *original_source_pattern; + const cairo_pattern_t *original_mask_pattern; + + cairo_clip_t *clip; /* clip will be reduced to the minimal container */ +}; + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_paint (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_mask (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_stroke (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_fill (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_boxes (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_boxes_t *boxes, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_polygon (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_polygon_t *polygon, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_clip_t *clip, + cairo_bool_t *overlap); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_intersect_source_extents (cairo_composite_rectangles_t *extents, + const cairo_box_t *box); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t *extents, + const cairo_box_t *box); + +cairo_private cairo_bool_t +_cairo_composite_rectangles_can_reduce_clip (cairo_composite_rectangles_t *composite, + cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_composite_rectangles_add_to_damage (cairo_composite_rectangles_t *composite, + cairo_boxes_t *damage); + +cairo_private void +_cairo_composite_rectangles_fini (cairo_composite_rectangles_t *extents); + +CAIRO_END_DECLS + +#endif /* CAIRO_COMPOSITE_RECTANGLES_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles.c b/Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles.c new file mode 100644 index 00000000000..6c3e97d4a97 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-composite-rectangles.c @@ -0,0 +1,500 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-error-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-pattern-private.h" + +/* A collection of routines to facilitate writing compositors. */ + +void _cairo_composite_rectangles_fini (cairo_composite_rectangles_t *extents) +{ + _cairo_clip_destroy (extents->clip); +} + +static void +_cairo_composite_reduce_pattern (const cairo_pattern_t *src, + cairo_pattern_union_t *dst) +{ + int tx, ty; + + _cairo_pattern_init_static_copy (&dst->base, src); + if (dst->base.type == CAIRO_PATTERN_TYPE_SOLID) + return; + + dst->base.filter = _cairo_pattern_analyze_filter (&dst->base); + + tx = ty = 0; + if (_cairo_matrix_is_pixman_translation (&dst->base.matrix, + dst->base.filter, + &tx, &ty)) + { + dst->base.matrix.x0 = tx; + dst->base.matrix.y0 = ty; + } +} + +static inline cairo_bool_t +_cairo_composite_rectangles_init (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + if (_cairo_clip_is_all_clipped (clip)) + return FALSE; + + extents->surface = surface; + extents->op = op; + + _cairo_surface_get_extents (surface, &extents->destination); + extents->clip = NULL; + + extents->unbounded = extents->destination; + if (clip && ! _cairo_rectangle_intersect (&extents->unbounded, + _cairo_clip_get_extents (clip))) + return FALSE; + + extents->bounded = extents->unbounded; + extents->is_bounded = _cairo_operator_bounded_by_either (op); + + extents->original_source_pattern = source; + _cairo_composite_reduce_pattern (source, &extents->source_pattern); + + _cairo_pattern_get_extents (&extents->source_pattern.base, + &extents->source); + if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) { + if (! _cairo_rectangle_intersect (&extents->bounded, &extents->source)) + return FALSE; + } + + extents->original_mask_pattern = NULL; + extents->mask_pattern.base.type = CAIRO_PATTERN_TYPE_SOLID; + extents->mask_pattern.solid.color.alpha = 1.; /* XXX full initialisation? */ + extents->mask_pattern.solid.color.alpha_short = 0xffff; + + return TRUE; +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_paint (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + if (! _cairo_composite_rectangles_init (extents, + surface, op, source, clip)) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + extents->mask = extents->destination; + + extents->clip = _cairo_clip_reduce_for_composite (clip, extents); + if (_cairo_clip_is_all_clipped (extents->clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (! _cairo_rectangle_intersect (&extents->unbounded, + _cairo_clip_get_extents (extents->clip))) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) + _cairo_pattern_sampled_area (&extents->source_pattern.base, + &extents->bounded, + &extents->source_sample_area); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_composite_rectangles_intersect (cairo_composite_rectangles_t *extents, + const cairo_clip_t *clip) +{ + cairo_bool_t ret; + + ret = _cairo_rectangle_intersect (&extents->bounded, &extents->mask); + if (! ret && extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE)) { + extents->unbounded = extents->bounded; + } else if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) { + if (!_cairo_rectangle_intersect (&extents->unbounded, &extents->mask)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + extents->clip = _cairo_clip_reduce_for_composite (clip, extents); + if (_cairo_clip_is_all_clipped (extents->clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (! _cairo_rectangle_intersect (&extents->unbounded, + _cairo_clip_get_extents (extents->clip))) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (! _cairo_rectangle_intersect (&extents->bounded, + _cairo_clip_get_extents (extents->clip)) && + extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) + _cairo_pattern_sampled_area (&extents->source_pattern.base, + &extents->bounded, + &extents->source_sample_area); + if (extents->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) { + _cairo_pattern_sampled_area (&extents->mask_pattern.base, + &extents->bounded, + &extents->mask_sample_area); + if (extents->mask_sample_area.width == 0 || + extents->mask_sample_area.height == 0) { + _cairo_composite_rectangles_fini (extents); + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_composite_rectangles_intersect_source_extents (cairo_composite_rectangles_t *extents, + const cairo_box_t *box) +{ + cairo_rectangle_int_t rect; + cairo_clip_t *clip; + + _cairo_box_round_to_rectangle (box, &rect); + if (rect.x == extents->source.x && + rect.y == extents->source.y && + rect.width == extents->source.width && + rect.height == extents->source.height) + { + return CAIRO_INT_STATUS_SUCCESS; + } + + _cairo_rectangle_intersect (&extents->source, &rect); + + rect = extents->bounded; + if (! _cairo_rectangle_intersect (&extents->bounded, &extents->source) && + extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (rect.width == extents->bounded.width && + rect.height == extents->bounded.height) + return CAIRO_INT_STATUS_SUCCESS; + + if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE)) { + extents->unbounded = extents->bounded; + } else if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) { + if (!_cairo_rectangle_intersect (&extents->unbounded, &extents->mask)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + clip = extents->clip; + extents->clip = _cairo_clip_reduce_for_composite (clip, extents); + if (clip != extents->clip) + _cairo_clip_destroy (clip); + + if (_cairo_clip_is_all_clipped (extents->clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (! _cairo_rectangle_intersect (&extents->unbounded, + _cairo_clip_get_extents (extents->clip))) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) + _cairo_pattern_sampled_area (&extents->source_pattern.base, + &extents->bounded, + &extents->source_sample_area); + if (extents->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) { + _cairo_pattern_sampled_area (&extents->mask_pattern.base, + &extents->bounded, + &extents->mask_sample_area); + if (extents->mask_sample_area.width == 0 || + extents->mask_sample_area.height == 0) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t *extents, + const cairo_box_t *box) +{ + cairo_rectangle_int_t mask; + cairo_clip_t *clip; + + _cairo_box_round_to_rectangle (box, &mask); + if (mask.x == extents->mask.x && + mask.y == extents->mask.y && + mask.width == extents->mask.width && + mask.height == extents->mask.height) + { + return CAIRO_INT_STATUS_SUCCESS; + } + + _cairo_rectangle_intersect (&extents->mask, &mask); + + mask = extents->bounded; + if (! _cairo_rectangle_intersect (&extents->bounded, &extents->mask) && + extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (mask.width == extents->bounded.width && + mask.height == extents->bounded.height) + return CAIRO_INT_STATUS_SUCCESS; + + if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE)) { + extents->unbounded = extents->bounded; + } else if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) { + if (!_cairo_rectangle_intersect (&extents->unbounded, &extents->mask)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + clip = extents->clip; + extents->clip = _cairo_clip_reduce_for_composite (clip, extents); + if (clip != extents->clip) + _cairo_clip_destroy (clip); + + if (_cairo_clip_is_all_clipped (extents->clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (! _cairo_rectangle_intersect (&extents->unbounded, + _cairo_clip_get_extents (extents->clip))) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (extents->source_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) + _cairo_pattern_sampled_area (&extents->source_pattern.base, + &extents->bounded, + &extents->source_sample_area); + if (extents->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) { + _cairo_pattern_sampled_area (&extents->mask_pattern.base, + &extents->bounded, + &extents->mask_sample_area); + if (extents->mask_sample_area.width == 0 || + extents->mask_sample_area.height == 0) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_mask (cairo_composite_rectangles_t *extents, + cairo_surface_t*surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + if (! _cairo_composite_rectangles_init (extents, + surface, op, source, clip)) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + extents->original_mask_pattern = mask; + _cairo_composite_reduce_pattern (mask, &extents->mask_pattern); + _cairo_pattern_get_extents (&extents->mask_pattern.base, &extents->mask); + + return _cairo_composite_rectangles_intersect (extents, clip); +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_stroke (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_clip_t *clip) +{ + if (! _cairo_composite_rectangles_init (extents, + surface, op, source, clip)) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + _cairo_path_fixed_approximate_stroke_extents (path, style, ctm, &extents->mask); + + return _cairo_composite_rectangles_intersect (extents, clip); +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_fill (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_clip_t *clip) +{ + if (! _cairo_composite_rectangles_init (extents, + surface, op, source, clip)) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + _cairo_path_fixed_approximate_fill_extents (path, &extents->mask); + + return _cairo_composite_rectangles_intersect (extents, clip); +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_polygon (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_polygon_t *polygon, + const cairo_clip_t *clip) +{ + if (! _cairo_composite_rectangles_init (extents, + surface, op, source, clip)) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + _cairo_box_round_to_rectangle (&polygon->extents, &extents->mask); + return _cairo_composite_rectangles_intersect (extents, clip); +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_boxes (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_boxes_t *boxes, + const cairo_clip_t *clip) +{ + cairo_box_t box; + + if (! _cairo_composite_rectangles_init (extents, + surface, op, source, clip)) + { + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + _cairo_boxes_extents (boxes, &box); + _cairo_box_round_to_rectangle (&box, &extents->mask); + return _cairo_composite_rectangles_intersect (extents, clip); +} + +cairo_int_status_t +_cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *extents, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_clip_t *clip, + cairo_bool_t *overlap) +{ + cairo_status_t status; + + if (! _cairo_composite_rectangles_init (extents, surface, op, source, clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + /* Computing the exact bbox and the overlap is expensive. + * First perform a cheap test to see if the glyphs are all clipped out. + */ + if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK && + _cairo_scaled_font_glyph_approximate_extents (scaled_font, + glyphs, num_glyphs, + &extents->mask)) + { + if (! _cairo_rectangle_intersect (&extents->bounded, &extents->mask)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + status = _cairo_scaled_font_glyph_device_extents (scaled_font, + glyphs, num_glyphs, + &extents->mask, + overlap); + if (unlikely (status)) + return status; + + if (overlap && *overlap && + scaled_font->options.antialias == CAIRO_ANTIALIAS_NONE && + _cairo_pattern_is_opaque_solid (&extents->source_pattern.base)) + { + *overlap = FALSE; + } + + return _cairo_composite_rectangles_intersect (extents, clip); +} + +cairo_bool_t +_cairo_composite_rectangles_can_reduce_clip (cairo_composite_rectangles_t *composite, + cairo_clip_t *clip) +{ + cairo_rectangle_int_t extents; + cairo_box_t box; + + if (clip == NULL) + return TRUE; + + extents = composite->destination; + if (composite->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) + _cairo_rectangle_intersect (&extents, &composite->source); + if (composite->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) + _cairo_rectangle_intersect (&extents, &composite->mask); + + _cairo_box_from_rectangle (&box, &extents); + return _cairo_clip_contains_box (clip, &box); +} + +cairo_int_status_t +_cairo_composite_rectangles_add_to_damage (cairo_composite_rectangles_t *composite, + cairo_boxes_t *damage) +{ + cairo_int_status_t status; + int n; + + for (n = 0; n < composite->clip->num_boxes; n++) { + status = _cairo_boxes_add (damage, + CAIRO_ANTIALIAS_NONE, + &composite->clip->boxes[n]); + if (unlikely (status)) + return status; + } + + return CAIRO_INT_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-compositor-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-compositor-private.h new file mode 100644 index 00000000000..019972333f3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-compositor-private.h @@ -0,0 +1,365 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_COMPOSITOR_PRIVATE_H +#define CAIRO_COMPOSITOR_PRIVATE_H + +#include "cairo-composite-rectangles-private.h" + +CAIRO_BEGIN_DECLS + +typedef struct { + cairo_scaled_font_t *font; + cairo_glyph_t *glyphs; + int num_glyphs; + cairo_bool_t use_mask; + cairo_rectangle_int_t extents; +} cairo_composite_glyphs_info_t; + +struct cairo_compositor { + const cairo_compositor_t *delegate; + + cairo_warn cairo_int_status_t + (*paint) (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents); + + cairo_warn cairo_int_status_t + (*mask) (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents); + + cairo_warn cairo_int_status_t + (*stroke) (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias); + + cairo_warn cairo_int_status_t + (*fill) (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias); + + cairo_warn cairo_int_status_t + (*glyphs) (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap); +}; + +struct cairo_mask_compositor { + cairo_compositor_t base; + + cairo_int_status_t (*acquire) (void *surface); + cairo_int_status_t (*release) (void *surface); + + cairo_int_status_t (*set_clip_region) (void *surface, + cairo_region_t *clip_region); + + cairo_surface_t * (*pattern_to_surface) (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y); + + cairo_int_status_t (*draw_image_boxes) (void *surface, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy); + + cairo_int_status_t (*copy_boxes) (void *surface, + cairo_surface_t *src, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents, + int dx, int dy); + + cairo_int_status_t + (*fill_rectangles) (void *surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_rectangle_int_t *rectangles, + int num_rects); + + cairo_int_status_t + (*fill_boxes) (void *surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes); + + cairo_int_status_t + (*check_composite) (const cairo_composite_rectangles_t *extents); + + cairo_int_status_t + (*composite) (void *dst, + cairo_operator_t op, + cairo_surface_t *src, + cairo_surface_t *mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height); + + cairo_int_status_t + (*composite_boxes) (void *surface, + cairo_operator_t op, + cairo_surface_t *source, + cairo_surface_t *mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents); + + cairo_int_status_t + (*check_composite_glyphs) (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs); + cairo_int_status_t + (*composite_glyphs) (void *surface, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info); +}; + +struct cairo_traps_compositor { + cairo_compositor_t base; + + cairo_int_status_t + (*acquire) (void *surface); + + cairo_int_status_t + (*release) (void *surface); + + cairo_int_status_t + (*set_clip_region) (void *surface, + cairo_region_t *clip_region); + + cairo_surface_t * + (*pattern_to_surface) (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y); + + cairo_int_status_t (*draw_image_boxes) (void *surface, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy); + + cairo_int_status_t (*copy_boxes) (void *surface, + cairo_surface_t *src, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents, + int dx, int dy); + + cairo_int_status_t + (*fill_boxes) (void *surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes); + + cairo_int_status_t + (*check_composite) (const cairo_composite_rectangles_t *extents); + + cairo_int_status_t + (*composite) (void *dst, + cairo_operator_t op, + cairo_surface_t *src, + cairo_surface_t *mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height); + cairo_int_status_t + (*lerp) (void *_dst, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height); + + cairo_int_status_t + (*composite_boxes) (void *surface, + cairo_operator_t op, + cairo_surface_t *source, + cairo_surface_t *mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents); + + cairo_int_status_t + (*composite_traps) (void *dst, + cairo_operator_t op, + cairo_surface_t *source, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_traps_t *traps); + + cairo_int_status_t + (*composite_tristrip) (void *dst, + cairo_operator_t op, + cairo_surface_t *source, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_tristrip_t *tristrip); + + cairo_int_status_t + (*check_composite_glyphs) (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs); + cairo_int_status_t + (*composite_glyphs) (void *surface, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info); +}; + +cairo_private extern const cairo_compositor_t __cairo_no_compositor; +cairo_private extern const cairo_compositor_t _cairo_fallback_compositor; + +cairo_private void +_cairo_mask_compositor_init (cairo_mask_compositor_t *compositor, + const cairo_compositor_t *delegate); + +cairo_private void +_cairo_shape_mask_compositor_init (cairo_compositor_t *compositor, + const cairo_compositor_t *delegate); + +cairo_private void +_cairo_traps_compositor_init (cairo_traps_compositor_t *compositor, + const cairo_compositor_t *delegate); + +cairo_private cairo_int_status_t +_cairo_compositor_paint (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_compositor_mask (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_compositor_stroke (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_compositor_fill (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + +CAIRO_END_DECLS + +#endif /* CAIRO_COMPOSITOR_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-compositor.c new file mode 100644 index 00000000000..b31413b9964 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-compositor.c @@ -0,0 +1,268 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-compositor-private.h" +#include "cairo-damage-private.h" +#include "cairo-error-private.h" + +cairo_int_status_t +_cairo_compositor_paint (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + status = _cairo_composite_rectangles_init_for_paint (&extents, surface, + op, source, + clip); + if (unlikely (status)) + return status; + + do { + while (compositor->paint == NULL) + compositor = compositor->delegate; + + status = compositor->paint (compositor, &extents); + + compositor = compositor->delegate; + } while (status == CAIRO_INT_STATUS_UNSUPPORTED); + + if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { + TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", + __FUNCTION__, + extents.unbounded.x, extents.unbounded.y, + extents.unbounded.width, extents.unbounded.height)); + surface->damage = _cairo_damage_add_rectangle (surface->damage, + &extents.unbounded); + } + + _cairo_composite_rectangles_fini (&extents); + + return status; +} + +cairo_int_status_t +_cairo_compositor_mask (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + status = _cairo_composite_rectangles_init_for_mask (&extents, surface, + op, source, mask, + clip); + if (unlikely (status)) + return status; + + do { + while (compositor->mask == NULL) + compositor = compositor->delegate; + + status = compositor->mask (compositor, &extents); + + compositor = compositor->delegate; + } while (status == CAIRO_INT_STATUS_UNSUPPORTED); + + if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { + TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", + __FUNCTION__, + extents.unbounded.x, extents.unbounded.y, + extents.unbounded.width, extents.unbounded.height)); + surface->damage = _cairo_damage_add_rectangle (surface->damage, + &extents.unbounded); + } + + _cairo_composite_rectangles_fini (&extents); + + return status; +} + +cairo_int_status_t +_cairo_compositor_stroke (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (_cairo_pen_vertices_needed (tolerance, style->line_width/2, ctm) <= 1) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + status = _cairo_composite_rectangles_init_for_stroke (&extents, surface, + op, source, + path, style, ctm, + clip); + if (unlikely (status)) + return status; + + do { + while (compositor->stroke == NULL) + compositor = compositor->delegate; + + status = compositor->stroke (compositor, &extents, + path, style, ctm, ctm_inverse, + tolerance, antialias); + + compositor = compositor->delegate; + } while (status == CAIRO_INT_STATUS_UNSUPPORTED); + + if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { + TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", + __FUNCTION__, + extents.unbounded.x, extents.unbounded.y, + extents.unbounded.width, extents.unbounded.height)); + surface->damage = _cairo_damage_add_rectangle (surface->damage, + &extents.unbounded); + } + + _cairo_composite_rectangles_fini (&extents); + + return status; +} + +cairo_int_status_t +_cairo_compositor_fill (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + status = _cairo_composite_rectangles_init_for_fill (&extents, surface, + op, source, path, + clip); + if (unlikely (status)) + return status; + + do { + while (compositor->fill == NULL) + compositor = compositor->delegate; + + status = compositor->fill (compositor, &extents, + path, fill_rule, tolerance, antialias); + + compositor = compositor->delegate; + } while (status == CAIRO_INT_STATUS_UNSUPPORTED); + + if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { + TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", + __FUNCTION__, + extents.unbounded.x, extents.unbounded.y, + extents.unbounded.width, extents.unbounded.height)); + surface->damage = _cairo_damage_add_rectangle (surface->damage, + &extents.unbounded); + } + + _cairo_composite_rectangles_fini (&extents); + + return status; +} + +cairo_int_status_t +_cairo_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_composite_rectangles_t extents; + cairo_bool_t overlap; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + status = _cairo_composite_rectangles_init_for_glyphs (&extents, surface, + op, source, + scaled_font, + glyphs, num_glyphs, + clip, &overlap); + if (unlikely (status)) + return status; + + do { + while (compositor->glyphs == NULL) + compositor = compositor->delegate; + + status = compositor->glyphs (compositor, &extents, + scaled_font, glyphs, num_glyphs, overlap); + + compositor = compositor->delegate; + } while (status == CAIRO_INT_STATUS_UNSUPPORTED); + + if (status == CAIRO_INT_STATUS_SUCCESS && surface->damage) { + TRACE ((stderr, "%s: applying damage (%d,%d)x(%d, %d)\n", + __FUNCTION__, + extents.unbounded.x, extents.unbounded.y, + extents.unbounded.width, extents.unbounded.height)); + surface->damage = _cairo_damage_add_rectangle (surface->damage, + &extents.unbounded); + } + + _cairo_composite_rectangles_fini (&extents); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-contour-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-contour-inline.h new file mode 100644 index 00000000000..7972c1ac5e0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-contour-inline.h @@ -0,0 +1,80 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_CONTOUR_INLINE_H +#define CAIRO_CONTOUR_INLINE_H + +#include "cairo-contour-private.h" + +CAIRO_BEGIN_DECLS + +static inline cairo_int_status_t +_cairo_contour_add_point (cairo_contour_t *contour, + const cairo_point_t *point) +{ + struct _cairo_contour_chain *tail = contour->tail; + + if (unlikely (tail->num_points == tail->size_points)) + return __cairo_contour_add_point (contour, point); + + tail->points[tail->num_points++] = *point; + return CAIRO_INT_STATUS_SUCCESS; +} + +static inline cairo_point_t * +_cairo_contour_first_point (cairo_contour_t *c) +{ + return &c->chain.points[0]; +} + +static inline cairo_point_t * +_cairo_contour_last_point (cairo_contour_t *c) +{ + return &c->tail->points[c->tail->num_points-1]; +} + +static inline void +_cairo_contour_remove_last_point (cairo_contour_t *contour) +{ + if (contour->chain.num_points == 0) + return; + + if (--contour->tail->num_points == 0) + __cairo_contour_remove_last_chain (contour); +} + +CAIRO_END_DECLS + +#endif /* CAIRO_CONTOUR_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-contour-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-contour-private.h new file mode 100644 index 00000000000..1dfc46f3acd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-contour-private.h @@ -0,0 +1,124 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_CONTOUR_PRIVATE_H +#define CAIRO_CONTOUR_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" +#include "cairo-list-private.h" + +#include + +CAIRO_BEGIN_DECLS + +/* A contour is simply a closed chain of points that divide the infinite plane + * into inside and outside. Each contour is a simple polygon, that is it + * contains no holes or self-intersections, but maybe either concave or convex. + */ + +struct _cairo_contour_chain { + cairo_point_t *points; + int num_points, size_points; + struct _cairo_contour_chain *next; +}; + +struct _cairo_contour_iter { + cairo_point_t *point; + cairo_contour_chain_t *chain; +}; + +struct _cairo_contour { + cairo_list_t next; + int direction; + cairo_contour_chain_t chain, *tail; + + cairo_point_t embedded_points[64]; +}; + +/* Initial definition of a shape is a set of contours (some representing holes) */ +struct _cairo_shape { + cairo_list_t contours; +}; + +typedef struct _cairo_shape cairo_shape_t; + +#if 0 +cairo_private cairo_status_t +_cairo_shape_init_from_polygon (cairo_shape_t *shape, + const cairo_polygon_t *polygon); + +cairo_private cairo_status_t +_cairo_shape_reduce (cairo_shape_t *shape, double tolerance); +#endif + +cairo_private void +_cairo_contour_init (cairo_contour_t *contour, + int direction); + +cairo_private cairo_int_status_t +__cairo_contour_add_point (cairo_contour_t *contour, + const cairo_point_t *point); + +cairo_private void +_cairo_contour_simplify (cairo_contour_t *contour, double tolerance); + +cairo_private void +_cairo_contour_reverse (cairo_contour_t *contour); + +cairo_private cairo_int_status_t +_cairo_contour_add (cairo_contour_t *dst, + const cairo_contour_t *src); + +cairo_private cairo_int_status_t +_cairo_contour_add_reversed (cairo_contour_t *dst, + const cairo_contour_t *src); + +cairo_private void +__cairo_contour_remove_last_chain (cairo_contour_t *contour); + +cairo_private void +_cairo_contour_reset (cairo_contour_t *contour); + +cairo_private void +_cairo_contour_fini (cairo_contour_t *contour); + +cairo_private void +_cairo_debug_print_contour (FILE *file, cairo_contour_t *contour); + +CAIRO_END_DECLS + +#endif /* CAIRO_CONTOUR_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-contour.c b/Build/source/libs/cairo/cairo-src/src/cairo-contour.c new file mode 100644 index 00000000000..9ad75bdbf8d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-contour.c @@ -0,0 +1,453 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" +#include "cairo-combsort-inline.h" +#include "cairo-contour-inline.h" +#include "cairo-contour-private.h" + +void +_cairo_contour_init (cairo_contour_t *contour, + int direction) +{ + contour->direction = direction; + contour->chain.points = contour->embedded_points; + contour->chain.next = NULL; + contour->chain.num_points = 0; + contour->chain.size_points = ARRAY_LENGTH (contour->embedded_points); + contour->tail = &contour->chain; +} + +cairo_int_status_t +__cairo_contour_add_point (cairo_contour_t *contour, + const cairo_point_t *point) +{ + cairo_contour_chain_t *tail = contour->tail; + cairo_contour_chain_t *next; + + assert (tail->next == NULL); + + next = _cairo_malloc_ab_plus_c (tail->size_points*2, + sizeof (cairo_point_t), + sizeof (cairo_contour_chain_t)); + if (unlikely (next == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + next->size_points = tail->size_points*2; + next->num_points = 1; + next->points = (cairo_point_t *)(next+1); + next->next = NULL; + tail->next = next; + contour->tail = next; + + next->points[0] = *point; + return CAIRO_INT_STATUS_SUCCESS; +} + +static void +first_inc (cairo_contour_t *contour, + cairo_point_t **p, + cairo_contour_chain_t **chain) +{ + if (*p == (*chain)->points + (*chain)->num_points) { + assert ((*chain)->next); + *chain = (*chain)->next; + *p = &(*chain)->points[0]; + } else + ++*p; +} + +static void +last_dec (cairo_contour_t *contour, + cairo_point_t **p, + cairo_contour_chain_t **chain) +{ + if (*p == (*chain)->points) { + cairo_contour_chain_t *prev; + assert (*chain != &contour->chain); + for (prev = &contour->chain; prev->next != *chain; prev = prev->next) + ; + *chain = prev; + *p = &(*chain)->points[(*chain)->num_points-1]; + } else + --*p; +} + +void +_cairo_contour_reverse (cairo_contour_t *contour) +{ + cairo_contour_chain_t *first_chain, *last_chain; + cairo_point_t *first, *last; + + contour->direction = -contour->direction; + + if (contour->chain.num_points <= 1) + return; + + first_chain = &contour->chain; + last_chain = contour->tail; + + first = &first_chain->points[0]; + last = &last_chain->points[last_chain->num_points-1]; + + while (first != last) { + cairo_point_t p; + + p = *first; + *first = *last; + *last = p; + + first_inc (contour, &first, &first_chain); + last_dec (contour, &last, &last_chain); + } +} + +cairo_int_status_t +_cairo_contour_add (cairo_contour_t *dst, + const cairo_contour_t *src) +{ + const cairo_contour_chain_t *chain; + cairo_int_status_t status; + int i; + + for (chain = &src->chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + status = _cairo_contour_add_point (dst, &chain->points[i]); + if (unlikely (status)) + return status; + } + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +static inline cairo_bool_t +iter_next (cairo_contour_iter_t *iter) +{ + if (iter->point == &iter->chain->points[iter->chain->size_points-1]) { + iter->chain = iter->chain->next; + if (iter->chain == NULL) + return FALSE; + + iter->point = &iter->chain->points[0]; + return TRUE; + } else { + iter->point++; + return TRUE; + } +} + +static cairo_bool_t +iter_equal (const cairo_contour_iter_t *i1, + const cairo_contour_iter_t *i2) +{ + return i1->chain == i2->chain && i1->point == i2->point; +} + +static void +iter_init (cairo_contour_iter_t *iter, cairo_contour_t *contour) +{ + iter->chain = &contour->chain; + iter->point = &contour->chain.points[0]; +} + +static void +iter_init_last (cairo_contour_iter_t *iter, cairo_contour_t *contour) +{ + iter->chain = contour->tail; + iter->point = &contour->tail->points[contour->tail->num_points-1]; +} + +static const cairo_contour_chain_t *prev_const_chain(const cairo_contour_t *contour, + const cairo_contour_chain_t *chain) +{ + const cairo_contour_chain_t *prev; + + if (chain == &contour->chain) + return NULL; + + for (prev = &contour->chain; prev->next != chain; prev = prev->next) + ; + + return prev; +} + +cairo_int_status_t +_cairo_contour_add_reversed (cairo_contour_t *dst, + const cairo_contour_t *src) +{ + const cairo_contour_chain_t *last; + cairo_int_status_t status; + int i; + + if (src->chain.num_points == 0) + return CAIRO_INT_STATUS_SUCCESS; + + for (last = src->tail; last; last = prev_const_chain (src, last)) { + for (i = last->num_points-1; i >= 0; i--) { + status = _cairo_contour_add_point (dst, &last->points[i]); + if (unlikely (status)) + return status; + } + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_uint64_t +point_distance_sq (const cairo_point_t *p1, + const cairo_point_t *p2) +{ + int32_t dx = p1->x - p2->x; + int32_t dy = p1->y - p2->y; + return _cairo_int32x32_64_mul (dx, dx) + _cairo_int32x32_64_mul (dy, dy); +} + +#define DELETED(p) ((p)->x == INT_MIN && (p)->y == INT_MAX) +#define MARK_DELETED(p) ((p)->x = INT_MIN, (p)->y = INT_MAX) + +static cairo_bool_t +_cairo_contour_simplify_chain (cairo_contour_t *contour, const double tolerance, + const cairo_contour_iter_t *first, + const cairo_contour_iter_t *last) +{ + cairo_contour_iter_t iter, furthest; + uint64_t max_error; + int x0, y0; + int nx, ny; + int count; + + iter = *first; + iter_next (&iter); + if (iter_equal (&iter, last)) + return FALSE; + + x0 = first->point->x; + y0 = first->point->y; + nx = last->point->y - y0; + ny = x0 - last->point->x; + + count = 0; + max_error = 0; + do { + cairo_point_t *p = iter.point; + if (! DELETED(p)) { + uint64_t d = (uint64_t)nx * (x0 - p->x) + (uint64_t)ny * (y0 - p->y); + if (d * d > max_error) { + max_error = d * d; + furthest = iter; + } + count++; + } + iter_next (&iter); + } while (! iter_equal (&iter, last)); + if (count == 0) + return FALSE; + + if (max_error > tolerance * ((uint64_t)nx * nx + (uint64_t)ny * ny)) { + cairo_bool_t simplified; + + simplified = FALSE; + simplified |= _cairo_contour_simplify_chain (contour, tolerance, + first, &furthest); + simplified |= _cairo_contour_simplify_chain (contour, tolerance, + &furthest, last); + return simplified; + } else { + iter = *first; + iter_next (&iter); + do { + MARK_DELETED (iter.point); + iter_next (&iter); + } while (! iter_equal (&iter, last)); + + return TRUE; + } +} + +void +_cairo_contour_simplify (cairo_contour_t *contour, double tolerance) +{ + cairo_contour_chain_t *chain; + cairo_point_t *last = NULL; + cairo_contour_iter_t iter, furthest; + cairo_bool_t simplified; + uint64_t max = 0; + int i; + + if (contour->chain.num_points <= 2) + return; + + tolerance = tolerance * CAIRO_FIXED_ONE; + tolerance *= tolerance; + + /* stage 1: vertex reduction */ + for (chain = &contour->chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + if (last == NULL || + point_distance_sq (last, &chain->points[i]) > tolerance) { + last = &chain->points[i]; + } else { + MARK_DELETED (&chain->points[i]); + } + } + } + + /* stage2: polygon simplification using Douglas-Peucker */ + do { + last = &contour->chain.points[0]; + iter_init (&furthest, contour); + max = 0; + for (chain = &contour->chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + uint64_t d; + + if (DELETED (&chain->points[i])) + continue; + + d = point_distance_sq (last, &chain->points[i]); + if (d > max) { + furthest.chain = chain; + furthest.point = &chain->points[i]; + max = d; + } + } + } + assert (max); + + simplified = FALSE; + iter_init (&iter, contour); + simplified |= _cairo_contour_simplify_chain (contour, tolerance, + &iter, &furthest); + + iter_init_last (&iter, contour); + if (! iter_equal (&furthest, &iter)) + simplified |= _cairo_contour_simplify_chain (contour, tolerance, + &furthest, &iter); + } while (simplified); + + iter_init (&iter, contour); + for (chain = &contour->chain; chain; chain = chain->next) { + int num_points = chain->num_points; + chain->num_points = 0; + for (i = 0; i < num_points; i++) { + if (! DELETED(&chain->points[i])) { + if (iter.point != &chain->points[i]) + *iter.point = chain->points[i]; + iter.chain->num_points++; + iter_next (&iter); + } + } + } + + if (iter.chain) { + cairo_contour_chain_t *next; + + for (chain = iter.chain->next; chain; chain = next) { + next = chain->next; + free (chain); + } + + iter.chain->next = NULL; + contour->tail = iter.chain; + } +} + +void +_cairo_contour_reset (cairo_contour_t *contour) +{ + _cairo_contour_fini (contour); + _cairo_contour_init (contour, contour->direction); +} + +void +_cairo_contour_fini (cairo_contour_t *contour) +{ + cairo_contour_chain_t *chain, *next; + + for (chain = contour->chain.next; chain; chain = next) { + next = chain->next; + free (chain); + } +} + +void +_cairo_debug_print_contour (FILE *file, cairo_contour_t *contour) +{ + cairo_contour_chain_t *chain; + int num_points, size_points; + int i; + + num_points = 0; + size_points = 0; + for (chain = &contour->chain; chain; chain = chain->next) { + num_points += chain->num_points; + size_points += chain->size_points; + } + + fprintf (file, "contour: direction=%d, num_points=%d / %d\n", + contour->direction, num_points, size_points); + + num_points = 0; + for (chain = &contour->chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + fprintf (file, " [%d] = (%f, %f)\n", + num_points++, + _cairo_fixed_to_double (chain->points[i].x), + _cairo_fixed_to_double (chain->points[i].y)); + } + } +} + +void +__cairo_contour_remove_last_chain (cairo_contour_t *contour) +{ + cairo_contour_chain_t *chain; + + if (contour->tail == &contour->chain) + return; + + for (chain = &contour->chain; chain->next != contour->tail; chain = chain->next) + ; + free (contour->tail); + contour->tail = chain; + chain->next = NULL; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-damage-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-damage-private.h new file mode 100644 index 00000000000..97b177e86b4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-damage-private.h @@ -0,0 +1,85 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_DAMAGE_PRIVATE_H +#define CAIRO_DAMAGE_PRIVATE_H + +#include "cairo-types-private.h" + +#include + +CAIRO_BEGIN_DECLS + +struct _cairo_damage { + cairo_status_t status; + cairo_region_t *region; + + int dirty, remain; + struct _cairo_damage_chunk { + struct _cairo_damage_chunk *next; + cairo_box_t *base; + int count; + int size; + } chunks, *tail; + cairo_box_t boxes[32]; +}; + +cairo_private cairo_damage_t * +_cairo_damage_create (void); + +cairo_private cairo_damage_t * +_cairo_damage_create_in_error (cairo_status_t status); + +cairo_private cairo_damage_t * +_cairo_damage_add_box (cairo_damage_t *damage, + const cairo_box_t *box); + +cairo_private cairo_damage_t * +_cairo_damage_add_rectangle (cairo_damage_t *damage, + const cairo_rectangle_int_t *rect); + +cairo_private cairo_damage_t * +_cairo_damage_add_region (cairo_damage_t *damage, + const cairo_region_t *region); + +cairo_private cairo_damage_t * +_cairo_damage_reduce (cairo_damage_t *damage); + +cairo_private void +_cairo_damage_destroy (cairo_damage_t *damage); + +CAIRO_END_DECLS + +#endif /* CAIRO_DAMAGE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-damage.c b/Build/source/libs/cairo/cairo-src/src/cairo-damage.c new file mode 100644 index 00000000000..63191fee95d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-damage.c @@ -0,0 +1,241 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-damage-private.h" +#include "cairo-region-private.h" + +static const cairo_damage_t __cairo_damage__nil = { CAIRO_STATUS_NO_MEMORY }; + +cairo_damage_t * +_cairo_damage_create_in_error (cairo_status_t status) +{ + _cairo_error_throw (status); + return (cairo_damage_t *) &__cairo_damage__nil; +} + +cairo_damage_t * +_cairo_damage_create (void) +{ + cairo_damage_t *damage; + + damage = malloc (sizeof (*damage)); + if (unlikely (damage == NULL)) { + _cairo_error_throw(CAIRO_STATUS_NO_MEMORY); + return (cairo_damage_t *) &__cairo_damage__nil; + } + + damage->status = CAIRO_STATUS_SUCCESS; + damage->region = NULL; + damage->dirty = 0; + damage->tail = &damage->chunks; + damage->chunks.base = damage->boxes; + damage->chunks.size = ARRAY_LENGTH(damage->boxes); + damage->chunks.count = 0; + damage->chunks.next = NULL; + + damage->remain = damage->chunks.size; + + return damage; +} + +void +_cairo_damage_destroy (cairo_damage_t *damage) +{ + struct _cairo_damage_chunk *chunk, *next; + + if (damage == (cairo_damage_t *) &__cairo_damage__nil) + return; + + for (chunk = damage->chunks.next; chunk != NULL; chunk = next) { + next = chunk->next; + free (chunk); + } + cairo_region_destroy (damage->region); + free (damage); +} + +static cairo_damage_t * +_cairo_damage_add_boxes(cairo_damage_t *damage, + const cairo_box_t *boxes, + int count) +{ + struct _cairo_damage_chunk *chunk; + int n, size; + + TRACE ((stderr, "%s x%d\n", __FUNCTION__, count)); + + if (damage == NULL) + damage = _cairo_damage_create (); + if (damage->status) + return damage; + + damage->dirty += count; + + n = count; + if (n > damage->remain) + n = damage->remain; + + memcpy (damage->tail->base + damage->tail->count, boxes, + n * sizeof (cairo_box_t)); + + count -= n; + damage->tail->count += n; + damage->remain -= n; + + if (count == 0) + return damage; + + size = 2 * damage->tail->size; + if (size < count) + size = (count + 64) & ~63; + + chunk = malloc (sizeof (*chunk) + sizeof (cairo_box_t) * size); + if (unlikely (chunk == NULL)) { + _cairo_damage_destroy (damage); + return (cairo_damage_t *) &__cairo_damage__nil; + } + + chunk->next = NULL; + chunk->base = (cairo_box_t *) (chunk + 1); + chunk->size = size; + chunk->count = count; + + damage->tail->next = chunk; + damage->tail = chunk; + + memcpy (damage->tail->base, boxes + n, + count * sizeof (cairo_box_t)); + damage->remain = size - count; + + return damage; +} + +cairo_damage_t * +_cairo_damage_add_box(cairo_damage_t *damage, + const cairo_box_t *box) +{ + TRACE ((stderr, "%s: (%d, %d),(%d, %d)\n", __FUNCTION__, + box->p1.x, box->p1.y, box->p2.x, box->p2.y)); + + return _cairo_damage_add_boxes(damage, box, 1); +} + +cairo_damage_t * +_cairo_damage_add_rectangle(cairo_damage_t *damage, + const cairo_rectangle_int_t *r) +{ + cairo_box_t box; + + TRACE ((stderr, "%s: (%d, %d)x(%d, %d)\n", __FUNCTION__, + r->x, r->y, r->width, r->height)); + + box.p1.x = r->x; + box.p1.y = r->y; + box.p2.x = r->x + r->width; + box.p2.y = r->y + r->height; + + return _cairo_damage_add_boxes(damage, &box, 1); +} + +cairo_damage_t * +_cairo_damage_add_region (cairo_damage_t *damage, + const cairo_region_t *region) +{ + cairo_box_t *boxes; + int nbox; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + boxes = _cairo_region_get_boxes (region, &nbox); + return _cairo_damage_add_boxes(damage, boxes, nbox); +} + +cairo_damage_t * +_cairo_damage_reduce (cairo_damage_t *damage) +{ + cairo_box_t *free_boxes = NULL; + cairo_box_t *boxes, *b; + struct _cairo_damage_chunk *chunk, *last; + + TRACE ((stderr, "%s: dirty=%d\n", __FUNCTION__, + damage ? damage->dirty : -1)); + if (damage == NULL || damage->status || !damage->dirty) + return damage; + + if (damage->region) { + cairo_region_t *region; + + region = damage->region; + damage->region = NULL; + + damage = _cairo_damage_add_region (damage, region); + cairo_region_destroy (region); + + if (unlikely (damage->status)) + return damage; + } + + boxes = damage->tail->base; + if (damage->dirty > damage->tail->size) { + boxes = free_boxes = malloc (damage->dirty * sizeof (cairo_box_t)); + if (unlikely (boxes == NULL)) { + _cairo_damage_destroy (damage); + return (cairo_damage_t *) &__cairo_damage__nil; + } + + b = boxes; + last = NULL; + } else { + b = boxes + damage->tail->count; + last = damage->tail; + } + + for (chunk = &damage->chunks; chunk != last; chunk = chunk->next) { + memcpy (b, chunk->base, chunk->count * sizeof (cairo_box_t)); + b += chunk->count; + } + + damage->region = _cairo_region_create_from_boxes (boxes, damage->dirty); + free (free_boxes); + + if (unlikely (damage->region->status)) { + _cairo_damage_destroy (damage); + return (cairo_damage_t *) &__cairo_damage__nil; + } + + damage->dirty = 0; + return damage; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-debug.c b/Build/source/libs/cairo/cairo-src/src/cairo-debug.c new file mode 100644 index 00000000000..33d46aa3f79 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-debug.c @@ -0,0 +1,304 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" +#include "cairo-image-surface-private.h" + +/** + * cairo_debug_reset_static_data: + * + * Resets all static data within cairo to its original state, + * (ie. identical to the state at the time of program invocation). For + * example, all caches within cairo will be flushed empty. + * + * This function is intended to be useful when using memory-checking + * tools such as valgrind. When valgrind's memcheck analyzes a + * cairo-using program without a call to cairo_debug_reset_static_data(), + * it will report all data reachable via cairo's static objects as + * "still reachable". Calling cairo_debug_reset_static_data() just prior + * to program termination will make it easier to get squeaky clean + * reports from valgrind. + * + * WARNING: It is only safe to call this function when there are no + * active cairo objects remaining, (ie. the appropriate destroy + * functions have been called as necessary). If there are active cairo + * objects, this call is likely to cause a crash, (eg. an assertion + * failure due to a hash table being destroyed when non-empty). + * + * Since: 1.0 + **/ +void +cairo_debug_reset_static_data (void) +{ + CAIRO_MUTEX_INITIALIZE (); + + _cairo_scaled_font_map_destroy (); + + _cairo_toy_font_face_reset_static_data (); + +#if CAIRO_HAS_FT_FONT + _cairo_ft_font_reset_static_data (); +#endif + +#if CAIRO_HAS_WIN32_FONT + _cairo_win32_font_reset_static_data (); +#endif + + _cairo_intern_string_reset_static_data (); + + _cairo_scaled_font_reset_static_data (); + + _cairo_pattern_reset_static_data (); + + _cairo_clip_reset_static_data (); + + _cairo_image_reset_static_data (); + +#if CAIRO_HAS_DRM_SURFACE + _cairo_drm_device_reset_static_data (); +#endif + + _cairo_default_context_reset_static_data (); + +#if CAIRO_HAS_COGL_SURFACE + _cairo_cogl_context_reset_static_data (); +#endif + + CAIRO_MUTEX_FINALIZE (); +} + +#if HAVE_VALGRIND +void +_cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface) +{ + const cairo_image_surface_t *image = (cairo_image_surface_t *) surface; + const uint8_t *bits; + int row, width; + + if (surface == NULL) + return; + + if (! RUNNING_ON_VALGRIND) + return; + + bits = image->data; + switch (image->format) { + case CAIRO_FORMAT_A1: + width = (image->width + 7)/8; + break; + case CAIRO_FORMAT_A8: + width = image->width; + break; + case CAIRO_FORMAT_RGB16_565: + width = image->width*2; + break; + case CAIRO_FORMAT_RGB24: + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_ARGB32: + width = image->width*4; + break; + case CAIRO_FORMAT_INVALID: + default: + /* XXX compute width from pixman bpp */ + return; + } + + for (row = 0; row < image->height; row++) { + VALGRIND_CHECK_MEM_IS_DEFINED (bits, width); + /* and then silence any future valgrind warnings */ + VALGRIND_MAKE_MEM_DEFINED (bits, width); + bits += image->stride; + } +} +#endif + + +#if 0 +void +_cairo_image_surface_write_to_ppm (cairo_image_surface_t *isurf, const char *fn) +{ + char *fmt; + if (isurf->format == CAIRO_FORMAT_ARGB32 || isurf->format == CAIRO_FORMAT_RGB24) + fmt = "P6"; + else if (isurf->format == CAIRO_FORMAT_A8) + fmt = "P5"; + else + return; + + FILE *fp = fopen(fn, "wb"); + if (!fp) + return; + + fprintf (fp, "%s %d %d 255\n", fmt,isurf->width, isurf->height); + for (int j = 0; j < isurf->height; j++) { + unsigned char *row = isurf->data + isurf->stride * j; + for (int i = 0; i < isurf->width; i++) { + if (isurf->format == CAIRO_FORMAT_ARGB32 || isurf->format == CAIRO_FORMAT_RGB24) { + unsigned char r = *row++; + unsigned char g = *row++; + unsigned char b = *row++; + *row++; + putc(r, fp); + putc(g, fp); + putc(b, fp); + } else { + unsigned char a = *row++; + putc(a, fp); + } + } + } + + fclose (fp); + + fprintf (stderr, "Wrote %s\n", fn); +} +#endif + +static cairo_status_t +_print_move_to (void *closure, + const cairo_point_t *point) +{ + fprintf (closure, + " %f %f m", + _cairo_fixed_to_double (point->x), + _cairo_fixed_to_double (point->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_print_line_to (void *closure, + const cairo_point_t *point) +{ + fprintf (closure, + " %f %f l", + _cairo_fixed_to_double (point->x), + _cairo_fixed_to_double (point->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_print_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + fprintf (closure, + " %f %f %f %f %f %f c", + _cairo_fixed_to_double (p1->x), + _cairo_fixed_to_double (p1->y), + _cairo_fixed_to_double (p2->x), + _cairo_fixed_to_double (p2->y), + _cairo_fixed_to_double (p3->x), + _cairo_fixed_to_double (p3->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_print_close (void *closure) +{ + fprintf (closure, " h"); + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_debug_print_path (FILE *stream, cairo_path_fixed_t *path) +{ + cairo_status_t status; + cairo_box_t box; + + fprintf (stream, + "path: extents=(%f, %f), (%f, %f)\n", + _cairo_fixed_to_double (path->extents.p1.x), + _cairo_fixed_to_double (path->extents.p1.y), + _cairo_fixed_to_double (path->extents.p2.x), + _cairo_fixed_to_double (path->extents.p2.y)); + + status = _cairo_path_fixed_interpret (path, + _print_move_to, + _print_line_to, + _print_curve_to, + _print_close, + stream); + assert (status == CAIRO_STATUS_SUCCESS); + + if (_cairo_path_fixed_is_box (path, &box)) { + fprintf (stream, "[box (%d, %d), (%d, %d)]", + box.p1.x, box.p1.y, box.p2.x, box.p2.y); + } + + printf ("\n"); +} + +void +_cairo_debug_print_polygon (FILE *stream, cairo_polygon_t *polygon) +{ + int n; + + fprintf (stream, + "polygon: extents=(%f, %f), (%f, %f)\n", + _cairo_fixed_to_double (polygon->extents.p1.x), + _cairo_fixed_to_double (polygon->extents.p1.y), + _cairo_fixed_to_double (polygon->extents.p2.x), + _cairo_fixed_to_double (polygon->extents.p2.y)); + if (polygon->num_limits) { + fprintf (stream, + " : limit=(%f, %f), (%f, %f) x %d\n", + _cairo_fixed_to_double (polygon->limit.p1.x), + _cairo_fixed_to_double (polygon->limit.p1.y), + _cairo_fixed_to_double (polygon->limit.p2.x), + _cairo_fixed_to_double (polygon->limit.p2.y), + polygon->num_limits); + } + + for (n = 0; n < polygon->num_edges; n++) { + cairo_edge_t *edge = &polygon->edges[n]; + + fprintf (stream, + " [%d] = [(%f, %f), (%f, %f)], top=%f, bottom=%f, dir=%d\n", + n, + _cairo_fixed_to_double (edge->line.p1.x), + _cairo_fixed_to_double (edge->line.p1.y), + _cairo_fixed_to_double (edge->line.p2.x), + _cairo_fixed_to_double (edge->line.p2.y), + _cairo_fixed_to_double (edge->top), + _cairo_fixed_to_double (edge->bottom), + edge->dir); + + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-default-context-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-default-context-private.h new file mode 100644 index 00000000000..fd159b49670 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-default-context-private.h @@ -0,0 +1,68 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_DEFAULT_CONTEXT_PRIVATE_H +#define CAIRO_DEFAULT_CONTEXT_PRIVATE_H + +#include "cairo-private.h" +#include "cairo-gstate-private.h" +#include "cairo-path-fixed-private.h" + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_default_context cairo_default_context_t; + +struct _cairo_default_context { + cairo_t base; + + cairo_gstate_t *gstate; + cairo_gstate_t gstate_tail[2]; + cairo_gstate_t *gstate_freelist; + + cairo_path_fixed_t path[1]; +}; + +cairo_private cairo_t * +_cairo_default_context_create (void *target); + +cairo_private cairo_status_t +_cairo_default_context_init (cairo_default_context_t *cr, void *target); + +cairo_private void +_cairo_default_context_fini (cairo_default_context_t *cr); + +CAIRO_END_DECLS + +#endif /* CAIRO_DEFAULT_CONTEXT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-default-context.c b/Build/source/libs/cairo/cairo-src/src/cairo-default-context.c new file mode 100644 index 00000000000..1e5067bf1b8 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-default-context.c @@ -0,0 +1,1475 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-private.h" +#include "cairo-arc-private.h" +#include "cairo-backend-private.h" +#include "cairo-clip-inline.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-path-private.h" +#include "cairo-pattern-private.h" + +#define CAIRO_TOLERANCE_MINIMUM _cairo_fixed_to_double(1) + +#if !defined(INFINITY) +#define INFINITY HUGE_VAL +#endif + +static freed_pool_t context_pool; + +void +_cairo_default_context_reset_static_data (void) +{ + _freed_pool_reset (&context_pool); +} + +void +_cairo_default_context_fini (cairo_default_context_t *cr) +{ + while (cr->gstate != &cr->gstate_tail[0]) { + if (_cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist)) + break; + } + + _cairo_gstate_fini (cr->gstate); + cr->gstate_freelist = cr->gstate_freelist->next; /* skip over tail[1] */ + while (cr->gstate_freelist != NULL) { + cairo_gstate_t *gstate = cr->gstate_freelist; + cr->gstate_freelist = gstate->next; + free (gstate); + } + + _cairo_path_fixed_fini (cr->path); + + _cairo_fini (&cr->base); +} + +static void +_cairo_default_context_destroy (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_default_context_fini (cr); + + /* mark the context as invalid to protect against misuse */ + cr->base.status = CAIRO_STATUS_NULL_POINTER; + _freed_pool_put (&context_pool, cr); +} + +static cairo_surface_t * +_cairo_default_context_get_original_target (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_original_target (cr->gstate); +} + +static cairo_surface_t * +_cairo_default_context_get_current_target (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_target (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_save (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_save (&cr->gstate, &cr->gstate_freelist); +} + +static cairo_status_t +_cairo_default_context_restore (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + if (unlikely (_cairo_gstate_is_group (cr->gstate))) + return _cairo_error (CAIRO_STATUS_INVALID_RESTORE); + + return _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist); +} + +static cairo_status_t +_cairo_default_context_push_group (void *abstract_cr, cairo_content_t content) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_surface_t *group_surface; + cairo_clip_t *clip; + cairo_status_t status; + + clip = _cairo_gstate_get_clip (cr->gstate); + if (_cairo_clip_is_all_clipped (clip)) { + group_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); + status = group_surface->status; + if (unlikely (status)) + goto bail; + } else { + cairo_surface_t *parent_surface; + cairo_rectangle_int_t extents; + cairo_bool_t bounded, is_empty; + + parent_surface = _cairo_gstate_get_target (cr->gstate); + + if (unlikely (parent_surface->status)) + return parent_surface->status; + if (unlikely (parent_surface->finished)) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + /* Get the extents that we'll use in creating our new group surface */ + bounded = _cairo_surface_get_extents (parent_surface, &extents); + if (clip) + /* XXX: This assignment just fixes a compiler warning? */ + is_empty = _cairo_rectangle_intersect (&extents, + _cairo_clip_get_extents (clip)); + + if (!bounded) { + /* XXX: Generic solution? */ + group_surface = cairo_recording_surface_create (content, NULL); + extents.x = extents.y = 0; + } else { + group_surface = _cairo_surface_create_scratch (parent_surface, + content, + extents.width, + extents.height, + CAIRO_COLOR_TRANSPARENT); + } + status = group_surface->status; + if (unlikely (status)) + goto bail; + + /* Set device offsets on the new surface so that logically it appears at + * the same location on the parent surface -- when we pop_group this, + * the source pattern will get fixed up for the appropriate target surface + * device offsets, so we want to set our own surface offsets from /that/, + * and not from the device origin. */ + cairo_surface_set_device_offset (group_surface, + parent_surface->device_transform.x0 - extents.x, + parent_surface->device_transform.y0 - extents.y); + + cairo_surface_set_device_scale (group_surface, + parent_surface->device_transform.xx, + parent_surface->device_transform.yy); + + /* If we have a current path, we need to adjust it to compensate for + * the device offset just applied. */ + _cairo_path_fixed_translate (cr->path, + _cairo_fixed_from_int (-extents.x), + _cairo_fixed_from_int (-extents.y)); + } + + /* create a new gstate for the redirect */ + status = _cairo_gstate_save (&cr->gstate, &cr->gstate_freelist); + if (unlikely (status)) + goto bail; + + status = _cairo_gstate_redirect_target (cr->gstate, group_surface); + +bail: + cairo_surface_destroy (group_surface); + return status; +} + +static cairo_pattern_t * +_cairo_default_context_pop_group (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_surface_t *group_surface; + cairo_pattern_t *group_pattern; + cairo_surface_t *parent_surface; + cairo_matrix_t group_matrix; + cairo_status_t status; + + /* Verify that we are at the right nesting level */ + if (unlikely (! _cairo_gstate_is_group (cr->gstate))) + return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_POP_GROUP); + + /* Get a reference to the active surface before restoring */ + group_surface = _cairo_gstate_get_target (cr->gstate); + group_surface = cairo_surface_reference (group_surface); + + status = _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist); + assert (status == CAIRO_STATUS_SUCCESS); + + parent_surface = _cairo_gstate_get_target (cr->gstate); + + group_pattern = cairo_pattern_create_for_surface (group_surface); + status = group_pattern->status; + if (unlikely (status)) + goto done; + + _cairo_gstate_get_matrix (cr->gstate, &group_matrix); + cairo_pattern_set_matrix (group_pattern, &group_matrix); + + /* If we have a current path, we need to adjust it to compensate for + * the device offset just removed. */ + _cairo_path_fixed_translate (cr->path, + _cairo_fixed_from_int (parent_surface->device_transform.x0 - group_surface->device_transform.x0), + _cairo_fixed_from_int (parent_surface->device_transform.y0 - group_surface->device_transform.y0)); + +done: + cairo_surface_destroy (group_surface); + + return group_pattern; +} + +static cairo_status_t +_cairo_default_context_set_source (void *abstract_cr, + cairo_pattern_t *source) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_source (cr->gstate, source); +} + +static cairo_bool_t +_current_source_matches_solid (const cairo_pattern_t *pattern, + double red, + double green, + double blue, + double alpha) +{ + cairo_color_t color; + + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) + return FALSE; + + red = _cairo_restrict_value (red, 0.0, 1.0); + green = _cairo_restrict_value (green, 0.0, 1.0); + blue = _cairo_restrict_value (blue, 0.0, 1.0); + alpha = _cairo_restrict_value (alpha, 0.0, 1.0); + + _cairo_color_init_rgba (&color, red, green, blue, alpha); + return _cairo_color_equal (&color, + &((cairo_solid_pattern_t *) pattern)->color); +} + +static cairo_status_t +_cairo_default_context_set_source_rgba (void *abstract_cr, double red, double green, double blue, double alpha) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_pattern_t *pattern; + cairo_status_t status; + + if (_current_source_matches_solid (cr->gstate->source, + red, green, blue, alpha)) + return CAIRO_STATUS_SUCCESS; + + /* push the current pattern to the freed lists */ + _cairo_default_context_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black); + + pattern = cairo_pattern_create_rgba (red, green, blue, alpha); + if (unlikely (pattern->status)) + return pattern->status; + + status = _cairo_default_context_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + return status; +} + +static cairo_status_t +_cairo_default_context_set_source_surface (void *abstract_cr, + cairo_surface_t *surface, + double x, + double y) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_pattern_t *pattern; + cairo_matrix_t matrix; + cairo_status_t status; + + /* push the current pattern to the freed lists */ + _cairo_default_context_set_source (cr, (cairo_pattern_t *) &_cairo_pattern_black); + + pattern = cairo_pattern_create_for_surface (surface); + if (unlikely (pattern->status)) + return pattern->status; + + cairo_matrix_init_translate (&matrix, -x, -y); + cairo_pattern_set_matrix (pattern, &matrix); + + status = _cairo_default_context_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + return status; +} + +static cairo_pattern_t * +_cairo_default_context_get_source (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_source (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_set_tolerance (void *abstract_cr, + double tolerance) +{ + cairo_default_context_t *cr = abstract_cr; + + if (tolerance < CAIRO_TOLERANCE_MINIMUM) + tolerance = CAIRO_TOLERANCE_MINIMUM; + + return _cairo_gstate_set_tolerance (cr->gstate, tolerance); +} + +static cairo_status_t +_cairo_default_context_set_operator (void *abstract_cr, cairo_operator_t op) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_operator (cr->gstate, op); +} + +static cairo_status_t +_cairo_default_context_set_opacity (void *abstract_cr, double opacity) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_opacity (cr->gstate, opacity); +} + +static cairo_status_t +_cairo_default_context_set_antialias (void *abstract_cr, + cairo_antialias_t antialias) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_antialias (cr->gstate, antialias); +} + +static cairo_status_t +_cairo_default_context_set_fill_rule (void *abstract_cr, + cairo_fill_rule_t fill_rule) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_fill_rule (cr->gstate, fill_rule); +} + +static cairo_status_t +_cairo_default_context_set_line_width (void *abstract_cr, + double line_width) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_line_width (cr->gstate, line_width); +} + +static cairo_status_t +_cairo_default_context_set_line_cap (void *abstract_cr, + cairo_line_cap_t line_cap) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_line_cap (cr->gstate, line_cap); +} + +static cairo_status_t +_cairo_default_context_set_line_join (void *abstract_cr, + cairo_line_join_t line_join) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_line_join (cr->gstate, line_join); +} + +static cairo_status_t +_cairo_default_context_set_dash (void *abstract_cr, + const double *dashes, + int num_dashes, + double offset) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_dash (cr->gstate, + dashes, num_dashes, offset); +} + +static cairo_status_t +_cairo_default_context_set_miter_limit (void *abstract_cr, + double limit) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_miter_limit (cr->gstate, limit); +} + +static cairo_antialias_t +_cairo_default_context_get_antialias (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_antialias (cr->gstate); +} + +static void +_cairo_default_context_get_dash (void *abstract_cr, + double *dashes, + int *num_dashes, + double *offset) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_get_dash (cr->gstate, dashes, num_dashes, offset); +} + +static cairo_fill_rule_t +_cairo_default_context_get_fill_rule (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_fill_rule (cr->gstate); +} + +static double +_cairo_default_context_get_line_width (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_line_width (cr->gstate); +} + +static cairo_line_cap_t +_cairo_default_context_get_line_cap (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_line_cap (cr->gstate); +} + +static cairo_line_join_t +_cairo_default_context_get_line_join (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_line_join (cr->gstate); +} + +static double +_cairo_default_context_get_miter_limit (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_miter_limit (cr->gstate); +} + +static cairo_operator_t +_cairo_default_context_get_operator (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_operator (cr->gstate); +} + +static double +_cairo_default_context_get_opacity (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_opacity (cr->gstate); +} + +static double +_cairo_default_context_get_tolerance (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_tolerance (cr->gstate); +} + + +/* Current tranformation matrix */ + +static cairo_status_t +_cairo_default_context_translate (void *abstract_cr, + double tx, + double ty) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_translate (cr->gstate, tx, ty); +} + +static cairo_status_t +_cairo_default_context_scale (void *abstract_cr, + double sx, + double sy) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_scale (cr->gstate, sx, sy); +} + +static cairo_status_t +_cairo_default_context_rotate (void *abstract_cr, + double theta) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_rotate (cr->gstate, theta); +} + +static cairo_status_t +_cairo_default_context_transform (void *abstract_cr, + const cairo_matrix_t *matrix) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_transform (cr->gstate, matrix); +} + +static cairo_status_t +_cairo_default_context_set_matrix (void *abstract_cr, + const cairo_matrix_t *matrix) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_matrix (cr->gstate, matrix); +} + +static cairo_status_t +_cairo_default_context_set_identity_matrix (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_identity_matrix (cr->gstate); + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_default_context_get_matrix (void *abstract_cr, + cairo_matrix_t *matrix) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_get_matrix (cr->gstate, matrix); +} + +static void +_cairo_default_context_user_to_device (void *abstract_cr, + double *x, + double *y) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_user_to_device (cr->gstate, x, y); +} + +static void +_cairo_default_context_user_to_device_distance (void *abstract_cr, double *dx, double *dy) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy); +} + +static void +_cairo_default_context_device_to_user (void *abstract_cr, + double *x, + double *y) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_device_to_user (cr->gstate, x, y); +} + +static void +_cairo_default_context_device_to_user_distance (void *abstract_cr, + double *dx, + double *dy) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy); +} + +static void +_cairo_default_context_backend_to_user (void *abstract_cr, + double *x, + double *y) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_backend_to_user (cr->gstate, x, y); +} + +static void +_cairo_default_context_backend_to_user_distance (void *abstract_cr, double *dx, double *dy) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_backend_to_user_distance (cr->gstate, dx, dy); +} + +static void +_cairo_default_context_user_to_backend (void *abstract_cr, + double *x, + double *y) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_user_to_backend (cr->gstate, x, y); +} + +static void +_cairo_default_context_user_to_backend_distance (void *abstract_cr, + double *dx, + double *dy) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_user_to_backend_distance (cr->gstate, dx, dy); +} + +/* Path constructor */ + +static cairo_status_t +_cairo_default_context_new_path (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_path_fixed_fini (cr->path); + _cairo_path_fixed_init (cr->path); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_default_context_new_sub_path (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_path_fixed_new_sub_path (cr->path); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_default_context_move_to (void *abstract_cr, double x, double y) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t x_fixed, y_fixed; + + _cairo_gstate_user_to_backend (cr->gstate, &x, &y); + x_fixed = _cairo_fixed_from_double (x); + y_fixed = _cairo_fixed_from_double (y); + + return _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed); +} + +static cairo_status_t +_cairo_default_context_line_to (void *abstract_cr, double x, double y) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t x_fixed, y_fixed; + + _cairo_gstate_user_to_backend (cr->gstate, &x, &y); + x_fixed = _cairo_fixed_from_double (x); + y_fixed = _cairo_fixed_from_double (y); + + return _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); +} + +static cairo_status_t +_cairo_default_context_curve_to (void *abstract_cr, + double x1, double y1, + double x2, double y2, + double x3, double y3) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t x1_fixed, y1_fixed; + cairo_fixed_t x2_fixed, y2_fixed; + cairo_fixed_t x3_fixed, y3_fixed; + + _cairo_gstate_user_to_backend (cr->gstate, &x1, &y1); + _cairo_gstate_user_to_backend (cr->gstate, &x2, &y2); + _cairo_gstate_user_to_backend (cr->gstate, &x3, &y3); + + x1_fixed = _cairo_fixed_from_double (x1); + y1_fixed = _cairo_fixed_from_double (y1); + + x2_fixed = _cairo_fixed_from_double (x2); + y2_fixed = _cairo_fixed_from_double (y2); + + x3_fixed = _cairo_fixed_from_double (x3); + y3_fixed = _cairo_fixed_from_double (y3); + + return _cairo_path_fixed_curve_to (cr->path, + x1_fixed, y1_fixed, + x2_fixed, y2_fixed, + x3_fixed, y3_fixed); +} + +static cairo_status_t +_cairo_default_context_arc (void *abstract_cr, + double xc, double yc, double radius, + double angle1, double angle2, + cairo_bool_t forward) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_status_t status; + + /* Do nothing, successfully, if radius is <= 0 */ + if (radius <= 0.0) { + cairo_fixed_t x_fixed, y_fixed; + + _cairo_gstate_user_to_backend (cr->gstate, &xc, &yc); + x_fixed = _cairo_fixed_from_double (xc); + y_fixed = _cairo_fixed_from_double (yc); + status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; + } + + status = _cairo_default_context_line_to (cr, + xc + radius * cos (angle1), + yc + radius * sin (angle1)); + + if (unlikely (status)) + return status; + + if (forward) + _cairo_arc_path (&cr->base, xc, yc, radius, angle1, angle2); + else + _cairo_arc_path_negative (&cr->base, xc, yc, radius, angle1, angle2); + + return CAIRO_STATUS_SUCCESS; /* any error will have already been set on cr */ +} + +static cairo_status_t +_cairo_default_context_rel_move_to (void *abstract_cr, double dx, double dy) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t dx_fixed, dy_fixed; + + _cairo_gstate_user_to_backend_distance (cr->gstate, &dx, &dy); + + dx_fixed = _cairo_fixed_from_double (dx); + dy_fixed = _cairo_fixed_from_double (dy); + + return _cairo_path_fixed_rel_move_to (cr->path, dx_fixed, dy_fixed); +} + +static cairo_status_t +_cairo_default_context_rel_line_to (void *abstract_cr, double dx, double dy) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t dx_fixed, dy_fixed; + + _cairo_gstate_user_to_backend_distance (cr->gstate, &dx, &dy); + + dx_fixed = _cairo_fixed_from_double (dx); + dy_fixed = _cairo_fixed_from_double (dy); + + return _cairo_path_fixed_rel_line_to (cr->path, dx_fixed, dy_fixed); +} + + +static cairo_status_t +_cairo_default_context_rel_curve_to (void *abstract_cr, + double dx1, double dy1, + double dx2, double dy2, + double dx3, double dy3) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t dx1_fixed, dy1_fixed; + cairo_fixed_t dx2_fixed, dy2_fixed; + cairo_fixed_t dx3_fixed, dy3_fixed; + + _cairo_gstate_user_to_backend_distance (cr->gstate, &dx1, &dy1); + _cairo_gstate_user_to_backend_distance (cr->gstate, &dx2, &dy2); + _cairo_gstate_user_to_backend_distance (cr->gstate, &dx3, &dy3); + + dx1_fixed = _cairo_fixed_from_double (dx1); + dy1_fixed = _cairo_fixed_from_double (dy1); + + dx2_fixed = _cairo_fixed_from_double (dx2); + dy2_fixed = _cairo_fixed_from_double (dy2); + + dx3_fixed = _cairo_fixed_from_double (dx3); + dy3_fixed = _cairo_fixed_from_double (dy3); + + return _cairo_path_fixed_rel_curve_to (cr->path, + dx1_fixed, dy1_fixed, + dx2_fixed, dy2_fixed, + dx3_fixed, dy3_fixed); +} + +static cairo_status_t +_cairo_default_context_close_path (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_path_fixed_close_path (cr->path); +} + +static cairo_status_t +_cairo_default_context_rectangle (void *abstract_cr, + double x, double y, + double width, double height) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_status_t status; + + status = _cairo_default_context_move_to (cr, x, y); + if (unlikely (status)) + return status; + + status = _cairo_default_context_rel_line_to (cr, width, 0); + if (unlikely (status)) + return status; + + status = _cairo_default_context_rel_line_to (cr, 0, height); + if (unlikely (status)) + return status; + + status = _cairo_default_context_rel_line_to (cr, -width, 0); + if (unlikely (status)) + return status; + + return _cairo_default_context_close_path (cr); +} + +static void +_cairo_default_context_path_extents (void *abstract_cr, + double *x1, + double *y1, + double *x2, + double *y2) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_path_extents (cr->gstate, + cr->path, + x1, y1, x2, y2); +} + +static cairo_bool_t +_cairo_default_context_has_current_point (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return cr->path->has_current_point; +} + +static cairo_bool_t +_cairo_default_context_get_current_point (void *abstract_cr, + double *x, + double *y) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_fixed_t x_fixed, y_fixed; + + if (_cairo_path_fixed_get_current_point (cr->path, &x_fixed, &y_fixed)) + { + *x = _cairo_fixed_to_double (x_fixed); + *y = _cairo_fixed_to_double (y_fixed); + _cairo_gstate_backend_to_user (cr->gstate, x, y); + + return TRUE; + } + else + { + return FALSE; + } +} + +static cairo_path_t * +_cairo_default_context_copy_path (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_path_create (cr->path, &cr->base); +} + +static cairo_path_t * +_cairo_default_context_copy_path_flat (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_path_create_flat (cr->path, &cr->base); +} + +static cairo_status_t +_cairo_default_context_append_path (void *abstract_cr, + const cairo_path_t *path) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_path_append_to_context (path, &cr->base); +} + +static cairo_status_t +_cairo_default_context_paint (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_paint (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_paint_with_alpha (void *abstract_cr, + double alpha) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_solid_pattern_t pattern; + cairo_status_t status; + cairo_color_t color; + + if (CAIRO_ALPHA_IS_OPAQUE (alpha)) + return _cairo_gstate_paint (cr->gstate); + + if (CAIRO_ALPHA_IS_ZERO (alpha) && + _cairo_operator_bounded_by_mask (cr->gstate->op)) { + return CAIRO_STATUS_SUCCESS; + } + + _cairo_color_init_rgba (&color, 0., 0., 0., alpha); + _cairo_pattern_init_solid (&pattern, &color); + + status = _cairo_gstate_mask (cr->gstate, &pattern.base); + _cairo_pattern_fini (&pattern.base); + + return status; +} + +static cairo_status_t +_cairo_default_context_mask (void *abstract_cr, + cairo_pattern_t *mask) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_mask (cr->gstate, mask); +} + +static cairo_status_t +_cairo_default_context_stroke_preserve (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_stroke (cr->gstate, cr->path); +} + +static cairo_status_t +_cairo_default_context_stroke (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_status_t status; + + status = _cairo_gstate_stroke (cr->gstate, cr->path); + if (unlikely (status)) + return status; + + return _cairo_default_context_new_path (cr); +} + +static cairo_status_t +_cairo_default_context_in_stroke (void *abstract_cr, + double x, double y, + cairo_bool_t *inside) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_in_stroke (cr->gstate, + cr->path, + x, y, + inside); +} + +static cairo_status_t +_cairo_default_context_stroke_extents (void *abstract_cr, + double *x1, double *y1, double *x2, double *y2) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_stroke_extents (cr->gstate, + cr->path, + x1, y1, x2, y2); +} + +static cairo_status_t +_cairo_default_context_fill_preserve (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_fill (cr->gstate, cr->path); +} + +static cairo_status_t +_cairo_default_context_fill (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_status_t status; + + status = _cairo_gstate_fill (cr->gstate, cr->path); + if (unlikely (status)) + return status; + + return _cairo_default_context_new_path (cr); +} + +static cairo_status_t +_cairo_default_context_in_fill (void *abstract_cr, + double x, double y, + cairo_bool_t *inside) +{ + cairo_default_context_t *cr = abstract_cr; + + *inside = _cairo_gstate_in_fill (cr->gstate, + cr->path, + x, y); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_default_context_fill_extents (void *abstract_cr, + double *x1, double *y1, double *x2, double *y2) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_fill_extents (cr->gstate, + cr->path, + x1, y1, x2, y2); +} + +static cairo_status_t +_cairo_default_context_clip_preserve (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_clip (cr->gstate, cr->path); +} + +static cairo_status_t +_cairo_default_context_clip (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_status_t status; + + status = _cairo_gstate_clip (cr->gstate, cr->path); + if (unlikely (status)) + return status; + + return _cairo_default_context_new_path (cr); +} + +static cairo_status_t +_cairo_default_context_in_clip (void *abstract_cr, + double x, double y, + cairo_bool_t *inside) +{ + cairo_default_context_t *cr = abstract_cr; + + *inside = _cairo_gstate_in_clip (cr->gstate, x, y); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_default_context_reset_clip (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_reset_clip (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_clip_extents (void *abstract_cr, + double *x1, double *y1, double *x2, double *y2) +{ + cairo_default_context_t *cr = abstract_cr; + + if (! _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2)) { + *x1 = -INFINITY; + *y1 = -INFINITY; + *x2 = +INFINITY; + *y2 = +INFINITY; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_rectangle_list_t * +_cairo_default_context_copy_clip_rectangle_list (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_copy_clip_rectangle_list (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_copy_page (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_copy_page (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_show_page (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_show_page (cr->gstate); +} + +static cairo_status_t +_cairo_default_context_set_font_face (void *abstract_cr, + cairo_font_face_t *font_face) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_font_face (cr->gstate, font_face); +} + +static cairo_font_face_t * +_cairo_default_context_get_font_face (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_font_face_t *font_face; + cairo_status_t status; + + status = _cairo_gstate_get_font_face (cr->gstate, &font_face); + if (unlikely (status)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *) &_cairo_font_face_nil; + } + + return font_face; +} + +static cairo_status_t +_cairo_default_context_font_extents (void *abstract_cr, + cairo_font_extents_t *extents) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_get_font_extents (cr->gstate, extents); +} + +static cairo_status_t +_cairo_default_context_set_font_size (void *abstract_cr, + double size) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_font_size (cr->gstate, size); +} + +static cairo_status_t +_cairo_default_context_set_font_matrix (void *abstract_cr, + const cairo_matrix_t *matrix) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_set_font_matrix (cr->gstate, matrix); +} + +static void +_cairo_default_context_get_font_matrix (void *abstract_cr, + cairo_matrix_t *matrix) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_get_font_matrix (cr->gstate, matrix); +} + +static cairo_status_t +_cairo_default_context_set_font_options (void *abstract_cr, + const cairo_font_options_t *options) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_set_font_options (cr->gstate, options); + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_default_context_get_font_options (void *abstract_cr, + cairo_font_options_t *options) +{ + cairo_default_context_t *cr = abstract_cr; + + _cairo_gstate_get_font_options (cr->gstate, options); +} + +static cairo_status_t +_cairo_default_context_set_scaled_font (void *abstract_cr, + cairo_scaled_font_t *scaled_font) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_bool_t was_previous; + cairo_status_t status; + + if (scaled_font == cr->gstate->scaled_font) + return CAIRO_STATUS_SUCCESS; + + was_previous = scaled_font == cr->gstate->previous_scaled_font; + + status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face); + if (unlikely (status)) + return status; + + status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix); + if (unlikely (status)) + return status; + + _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options); + + if (was_previous) + cr->gstate->scaled_font = cairo_scaled_font_reference (scaled_font); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_scaled_font_t * +_cairo_default_context_get_scaled_font (void *abstract_cr) +{ + cairo_default_context_t *cr = abstract_cr; + cairo_scaled_font_t *scaled_font; + cairo_status_t status; + + status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font); + if (unlikely (status)) + return _cairo_scaled_font_create_in_error (status); + + return scaled_font; +} + +static cairo_status_t +_cairo_default_context_glyphs (void *abstract_cr, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_glyph_text_info_t *info) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_show_text_glyphs (cr->gstate, glyphs, num_glyphs, info); +} + +static cairo_status_t +_cairo_default_context_glyph_path (void *abstract_cr, + const cairo_glyph_t *glyphs, + int num_glyphs) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_glyph_path (cr->gstate, + glyphs, num_glyphs, + cr->path); +} + +static cairo_status_t +_cairo_default_context_glyph_extents (void *abstract_cr, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents) +{ + cairo_default_context_t *cr = abstract_cr; + + return _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents); +} + +static const cairo_backend_t _cairo_default_context_backend = { + CAIRO_TYPE_DEFAULT, + _cairo_default_context_destroy, + + _cairo_default_context_get_original_target, + _cairo_default_context_get_current_target, + + _cairo_default_context_save, + _cairo_default_context_restore, + + _cairo_default_context_push_group, + _cairo_default_context_pop_group, + + _cairo_default_context_set_source_rgba, + _cairo_default_context_set_source_surface, + _cairo_default_context_set_source, + _cairo_default_context_get_source, + + _cairo_default_context_set_antialias, + _cairo_default_context_set_dash, + _cairo_default_context_set_fill_rule, + _cairo_default_context_set_line_cap, + _cairo_default_context_set_line_join, + _cairo_default_context_set_line_width, + _cairo_default_context_set_miter_limit, + _cairo_default_context_set_opacity, + _cairo_default_context_set_operator, + _cairo_default_context_set_tolerance, + _cairo_default_context_get_antialias, + _cairo_default_context_get_dash, + _cairo_default_context_get_fill_rule, + _cairo_default_context_get_line_cap, + _cairo_default_context_get_line_join, + _cairo_default_context_get_line_width, + _cairo_default_context_get_miter_limit, + _cairo_default_context_get_opacity, + _cairo_default_context_get_operator, + _cairo_default_context_get_tolerance, + + _cairo_default_context_translate, + _cairo_default_context_scale, + _cairo_default_context_rotate, + _cairo_default_context_transform, + _cairo_default_context_set_matrix, + _cairo_default_context_set_identity_matrix, + _cairo_default_context_get_matrix, + + _cairo_default_context_user_to_device, + _cairo_default_context_user_to_device_distance, + _cairo_default_context_device_to_user, + _cairo_default_context_device_to_user_distance, + + _cairo_default_context_user_to_backend, + _cairo_default_context_user_to_backend_distance, + _cairo_default_context_backend_to_user, + _cairo_default_context_backend_to_user_distance, + + _cairo_default_context_new_path, + _cairo_default_context_new_sub_path, + _cairo_default_context_move_to, + _cairo_default_context_rel_move_to, + _cairo_default_context_line_to, + _cairo_default_context_rel_line_to, + _cairo_default_context_curve_to, + _cairo_default_context_rel_curve_to, + NULL, /* arc-to */ + NULL, /* rel-arc-to */ + _cairo_default_context_close_path, + _cairo_default_context_arc, + _cairo_default_context_rectangle, + _cairo_default_context_path_extents, + _cairo_default_context_has_current_point, + _cairo_default_context_get_current_point, + _cairo_default_context_copy_path, + _cairo_default_context_copy_path_flat, + _cairo_default_context_append_path, + + NULL, /* stroke-to-path */ + + _cairo_default_context_clip, + _cairo_default_context_clip_preserve, + _cairo_default_context_in_clip, + _cairo_default_context_clip_extents, + _cairo_default_context_reset_clip, + _cairo_default_context_copy_clip_rectangle_list, + + _cairo_default_context_paint, + _cairo_default_context_paint_with_alpha, + _cairo_default_context_mask, + + _cairo_default_context_stroke, + _cairo_default_context_stroke_preserve, + _cairo_default_context_in_stroke, + _cairo_default_context_stroke_extents, + + _cairo_default_context_fill, + _cairo_default_context_fill_preserve, + _cairo_default_context_in_fill, + _cairo_default_context_fill_extents, + + _cairo_default_context_set_font_face, + _cairo_default_context_get_font_face, + _cairo_default_context_set_font_size, + _cairo_default_context_set_font_matrix, + _cairo_default_context_get_font_matrix, + _cairo_default_context_set_font_options, + _cairo_default_context_get_font_options, + _cairo_default_context_set_scaled_font, + _cairo_default_context_get_scaled_font, + _cairo_default_context_font_extents, + + _cairo_default_context_glyphs, + _cairo_default_context_glyph_path, + _cairo_default_context_glyph_extents, + + _cairo_default_context_copy_page, + _cairo_default_context_show_page, +}; + +cairo_status_t +_cairo_default_context_init (cairo_default_context_t *cr, void *target) +{ + _cairo_init (&cr->base, &_cairo_default_context_backend); + _cairo_path_fixed_init (cr->path); + + cr->gstate = &cr->gstate_tail[0]; + cr->gstate_freelist = &cr->gstate_tail[1]; + cr->gstate_tail[1].next = NULL; + + return _cairo_gstate_init (cr->gstate, target); +} + +cairo_t * +_cairo_default_context_create (void *target) +{ + cairo_default_context_t *cr; + cairo_status_t status; + + cr = _freed_pool_get (&context_pool); + if (unlikely (cr == NULL)) { + cr = malloc (sizeof (cairo_default_context_t)); + if (unlikely (cr == NULL)) + return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + status = _cairo_default_context_init (cr, target); + if (unlikely (status)) { + _freed_pool_put (&context_pool, cr); + return _cairo_create_in_error (status); + } + + return &cr->base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-deflate-stream.c b/Build/source/libs/cairo/cairo-src/src/cairo-deflate-stream.c new file mode 100644 index 00000000000..ae23bda9472 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-deflate-stream.c @@ -0,0 +1,156 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Author(s): + * Adrian Johnson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_DEFLATE_STREAM + +#include "cairo-error-private.h" +#include "cairo-output-stream-private.h" +#include + +#define BUFFER_SIZE 16384 + +typedef struct _cairo_deflate_stream { + cairo_output_stream_t base; + cairo_output_stream_t *output; + z_stream zlib_stream; + unsigned char input_buf[BUFFER_SIZE]; + unsigned char output_buf[BUFFER_SIZE]; +} cairo_deflate_stream_t; + +static void +cairo_deflate_stream_deflate (cairo_deflate_stream_t *stream, cairo_bool_t flush) +{ + int ret; + cairo_bool_t finished; + + do { + ret = deflate (&stream->zlib_stream, flush ? Z_FINISH : Z_NO_FLUSH); + if (flush || stream->zlib_stream.avail_out == 0) + { + _cairo_output_stream_write (stream->output, + stream->output_buf, + BUFFER_SIZE - stream->zlib_stream.avail_out); + stream->zlib_stream.next_out = stream->output_buf; + stream->zlib_stream.avail_out = BUFFER_SIZE; + } + + finished = TRUE; + if (stream->zlib_stream.avail_in != 0) + finished = FALSE; + if (flush && ret != Z_STREAM_END) + finished = FALSE; + + } while (!finished); + + stream->zlib_stream.next_in = stream->input_buf; +} + +static cairo_status_t +_cairo_deflate_stream_write (cairo_output_stream_t *base, + const unsigned char *data, + unsigned int length) +{ + cairo_deflate_stream_t *stream = (cairo_deflate_stream_t *) base; + unsigned int count; + const unsigned char *p = data; + + while (length) { + count = length; + if (count > BUFFER_SIZE - stream->zlib_stream.avail_in) + count = BUFFER_SIZE - stream->zlib_stream.avail_in; + memcpy (stream->input_buf + stream->zlib_stream.avail_in, p, count); + p += count; + stream->zlib_stream.avail_in += count; + length -= count; + + if (stream->zlib_stream.avail_in == BUFFER_SIZE) + cairo_deflate_stream_deflate (stream, FALSE); + } + + return _cairo_output_stream_get_status (stream->output); +} + +static cairo_status_t +_cairo_deflate_stream_close (cairo_output_stream_t *base) +{ + cairo_deflate_stream_t *stream = (cairo_deflate_stream_t *) base; + + cairo_deflate_stream_deflate (stream, TRUE); + deflateEnd (&stream->zlib_stream); + + return _cairo_output_stream_get_status (stream->output); +} + +cairo_output_stream_t * +_cairo_deflate_stream_create (cairo_output_stream_t *output) +{ + cairo_deflate_stream_t *stream; + + if (output->status) + return _cairo_output_stream_create_in_error (output->status); + + stream = malloc (sizeof (cairo_deflate_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + _cairo_deflate_stream_write, + NULL, + _cairo_deflate_stream_close); + stream->output = output; + + stream->zlib_stream.zalloc = Z_NULL; + stream->zlib_stream.zfree = Z_NULL; + stream->zlib_stream.opaque = Z_NULL; + + if (deflateInit (&stream->zlib_stream, Z_DEFAULT_COMPRESSION) != Z_OK) { + free (stream); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + stream->zlib_stream.next_in = stream->input_buf; + stream->zlib_stream.avail_in = 0; + stream->zlib_stream.next_out = stream->output_buf; + stream->zlib_stream.avail_out = BUFFER_SIZE; + + return &stream->base; +} + +#endif /* CAIRO_HAS_DEFLATE_STREAM */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-deprecated.h b/Build/source/libs/cairo/cairo-src/src/cairo-deprecated.h new file mode 100644 index 00000000000..7a56aadbfe1 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-deprecated.h @@ -0,0 +1,123 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_DEPRECATED_H +#define CAIRO_DEPRECATED_H + +#define CAIRO_FONT_TYPE_ATSUI CAIRO_FONT_TYPE_QUARTZ + +/* Obsolete functions. These definitions exist to coerce the compiler + * into providing a little bit of guidance with its error + * messages. The idea is to help users port their old code without + * having to dig through lots of documentation. + * + * The first set of REPLACED_BY functions is for functions whose names + * have just been changed. So fixing these up is mechanical, (and + * automated by means of the cairo/util/cairo-api-update script. + * + * The second set of DEPRECATED_BY functions is for functions where + * the replacement is used in a different way, (ie. different + * arguments, multiple functions instead of one, etc). Fixing these up + * will require a bit more work on the user's part, (and hopefully we + * can get cairo-api-update to find these and print some guiding + * information). + */ +#define cairo_current_font_extents cairo_current_font_extents_REPLACED_BY_cairo_font_extents +#define cairo_get_font_extents cairo_get_font_extents_REPLACED_BY_cairo_font_extents +#define cairo_current_operator cairo_current_operator_REPLACED_BY_cairo_get_operator +#define cairo_current_tolerance cairo_current_tolerance_REPLACED_BY_cairo_get_tolerance +#define cairo_current_point cairo_current_point_REPLACED_BY_cairo_get_current_point +#define cairo_current_fill_rule cairo_current_fill_rule_REPLACED_BY_cairo_get_fill_rule +#define cairo_current_line_width cairo_current_line_width_REPLACED_BY_cairo_get_line_width +#define cairo_current_line_cap cairo_current_line_cap_REPLACED_BY_cairo_get_line_cap +#define cairo_current_line_join cairo_current_line_join_REPLACED_BY_cairo_get_line_join +#define cairo_current_miter_limit cairo_current_miter_limit_REPLACED_BY_cairo_get_miter_limit +#define cairo_current_matrix cairo_current_matrix_REPLACED_BY_cairo_get_matrix +#define cairo_current_target_surface cairo_current_target_surface_REPLACED_BY_cairo_get_target +#define cairo_get_status cairo_get_status_REPLACED_BY_cairo_status +#define cairo_concat_matrix cairo_concat_matrix_REPLACED_BY_cairo_transform +#define cairo_scale_font cairo_scale_font_REPLACED_BY_cairo_set_font_size +#define cairo_select_font cairo_select_font_REPLACED_BY_cairo_select_font_face +#define cairo_transform_font cairo_transform_font_REPLACED_BY_cairo_set_font_matrix +#define cairo_transform_point cairo_transform_point_REPLACED_BY_cairo_user_to_device +#define cairo_transform_distance cairo_transform_distance_REPLACED_BY_cairo_user_to_device_distance +#define cairo_inverse_transform_point cairo_inverse_transform_point_REPLACED_BY_cairo_device_to_user +#define cairo_inverse_transform_distance cairo_inverse_transform_distance_REPLACED_BY_cairo_device_to_user_distance +#define cairo_init_clip cairo_init_clip_REPLACED_BY_cairo_reset_clip +#define cairo_surface_create_for_image cairo_surface_create_for_image_REPLACED_BY_cairo_image_surface_create_for_data +#define cairo_default_matrix cairo_default_matrix_REPLACED_BY_cairo_identity_matrix +#define cairo_matrix_set_affine cairo_matrix_set_affine_REPLACED_BY_cairo_matrix_init +#define cairo_matrix_set_identity cairo_matrix_set_identity_REPLACED_BY_cairo_matrix_init_identity +#define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_REPLACED_BY_cairo_pattern_add_color_stop_rgba +#define cairo_set_rgb_color cairo_set_rgb_color_REPLACED_BY_cairo_set_source_rgb +#define cairo_set_pattern cairo_set_pattern_REPLACED_BY_cairo_set_source +#define cairo_xlib_surface_create_for_pixmap_with_visual cairo_xlib_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xlib_surface_create +#define cairo_xlib_surface_create_for_window_with_visual cairo_xlib_surface_create_for_window_with_visual_REPLACED_BY_cairo_xlib_surface_create +#define cairo_xcb_surface_create_for_pixmap_with_visual cairo_xcb_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xcb_surface_create +#define cairo_xcb_surface_create_for_window_with_visual cairo_xcb_surface_create_for_window_with_visual_REPLACED_BY_cairo_xcb_surface_create +#define cairo_ps_surface_set_dpi cairo_ps_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution +#define cairo_pdf_surface_set_dpi cairo_pdf_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution +#define cairo_svg_surface_set_dpi cairo_svg_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution +#define cairo_atsui_font_face_create_for_atsu_font_id cairo_atsui_font_face_create_for_atsu_font_id_REPLACED_BY_cairo_quartz_font_face_create_for_atsu_font_id + +#define cairo_current_path cairo_current_path_DEPRECATED_BY_cairo_copy_path +#define cairo_current_path_flat cairo_current_path_flat_DEPRECATED_BY_cairo_copy_path_flat +#define cairo_get_path cairo_get_path_DEPRECATED_BY_cairo_copy_path +#define cairo_get_path_flat cairo_get_path_flat_DEPRECATED_BY_cairo_get_path_flat +#define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba_OR_cairo_paint_with_alpha +#define cairo_show_surface cairo_show_surface_DEPRECATED_BY_cairo_set_source_surface_AND_cairo_paint +#define cairo_copy cairo_copy_DEPRECATED_BY_cairo_create_AND_MANY_INDIVIDUAL_FUNCTIONS +#define cairo_surface_set_repeat cairo_surface_set_repeat_DEPRECATED_BY_cairo_pattern_set_extend +#define cairo_surface_set_matrix cairo_surface_set_matrix_DEPRECATED_BY_cairo_pattern_set_matrix +#define cairo_surface_get_matrix cairo_surface_get_matrix_DEPRECATED_BY_cairo_pattern_get_matrix +#define cairo_surface_set_filter cairo_surface_set_filter_DEPRECATED_BY_cairo_pattern_set_filter +#define cairo_surface_get_filter cairo_surface_get_filter_DEPRECATED_BY_cairo_pattern_get_filter +#define cairo_matrix_create cairo_matrix_create_DEPRECATED_BY_cairo_matrix_t +#define cairo_matrix_destroy cairo_matrix_destroy_DEPRECATED_BY_cairo_matrix_t +#define cairo_matrix_copy cairo_matrix_copy_DEPRECATED_BY_cairo_matrix_t +#define cairo_matrix_get_affine cairo_matrix_get_affine_DEPRECATED_BY_cairo_matrix_t +#define cairo_set_target_surface cairo_set_target_surface_DEPRECATED_BY_cairo_create +#define cairo_set_target_image cairo_set_target_image_DEPRECATED_BY_cairo_image_surface_create_for_data +#define cairo_set_target_pdf cairo_set_target_pdf_DEPRECATED_BY_cairo_pdf_surface_create +#define cairo_set_target_png cairo_set_target_png_DEPRECATED_BY_cairo_surface_write_to_png +#define cairo_set_target_ps cairo_set_target_ps_DEPRECATED_BY_cairo_ps_surface_create +#define cairo_set_target_quartz cairo_set_target_quartz_DEPRECATED_BY_cairo_quartz_surface_create +#define cairo_set_target_win32 cairo_set_target_win32_DEPRECATED_BY_cairo_win32_surface_create +#define cairo_set_target_xcb cairo_set_target_xcb_DEPRECATED_BY_cairo_xcb_surface_create +#define cairo_set_target_drawable cairo_set_target_drawable_DEPRECATED_BY_cairo_xlib_surface_create +#define cairo_get_status_string cairo_get_status_string_DEPRECATED_BY_cairo_status_AND_cairo_status_to_string +#define cairo_status_string cairo_status_string_DEPRECATED_BY_cairo_status_AND_cairo_status_to_string + +#endif /* CAIRO_DEPRECATED_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-device-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-device-private.h new file mode 100644 index 00000000000..6eb44f3b634 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-device-private.h @@ -0,0 +1,86 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributors(s): + * Chris Wilson + */ + +#ifndef _CAIRO_DEVICE_PRIVATE_H_ +#define _CAIRO_DEVICE_PRIVATE_H_ + +#include "cairo-compiler-private.h" +#include "cairo-mutex-private.h" +#include "cairo-reference-count-private.h" +#include "cairo-types-private.h" + +struct _cairo_device { + cairo_reference_count_t ref_count; + cairo_status_t status; + cairo_user_data_array_t user_data; + + const cairo_device_backend_t *backend; + + cairo_recursive_mutex_t mutex; + unsigned mutex_depth; + + cairo_bool_t finished; +}; + +struct _cairo_device_backend { + cairo_device_type_t type; + + void (*lock) (void *device); + void (*unlock) (void *device); + + cairo_warn cairo_status_t (*flush) (void *device); + void (*finish) (void *device); + void (*destroy) (void *device); +}; + +cairo_private cairo_device_t * +_cairo_device_create_in_error (cairo_status_t status); + +cairo_private void +_cairo_device_init (cairo_device_t *device, + const cairo_device_backend_t *backend); + +cairo_private cairo_status_t +_cairo_device_set_error (cairo_device_t *device, + cairo_status_t error); + +slim_hidden_proto_no_warn (cairo_device_reference); +slim_hidden_proto (cairo_device_acquire); +slim_hidden_proto (cairo_device_release); +slim_hidden_proto (cairo_device_flush); +slim_hidden_proto (cairo_device_finish); +slim_hidden_proto (cairo_device_destroy); + +#endif /* _CAIRO_DEVICE_PRIVATE_H_ */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-device.c b/Build/source/libs/cairo/cairo-src/src/cairo-device.c new file mode 100644 index 00000000000..585a9c1c41f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-device.c @@ -0,0 +1,541 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributors(s): + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-device-private.h" +#include "cairo-error-private.h" + +/** + * SECTION:cairo-device + * @Title: cairo_device_t + * @Short_Description: interface to underlying rendering system + * @See_Also: #cairo_surface_t + * + * Devices are the abstraction Cairo employs for the rendering system + * used by a #cairo_surface_t. You can get the device of a surface using + * cairo_surface_get_device(). + * + * Devices are created using custom functions specific to the rendering + * system you want to use. See the documentation for the surface types + * for those functions. + * + * An important function that devices fulfill is sharing access to the + * rendering system between Cairo and your application. If you want to + * access a device directly that you used to draw to with Cairo, you must + * first call cairo_device_flush() to ensure that Cairo finishes all + * operations on the device and resets it to a clean state. + * + * Cairo also provides the functions cairo_device_acquire() and + * cairo_device_release() to synchronize access to the rendering system + * in a multithreaded environment. This is done internally, but can also + * be used by applications. + * + * Putting this all together, a function that works with devices should + * look something like this: + * + * void + * my_device_modifying_function (cairo_device_t *device) + * { + * cairo_status_t status; + * + * // Ensure the device is properly reset + * cairo_device_flush (device); + * // Try to acquire the device + * status = cairo_device_acquire (device); + * if (status != CAIRO_STATUS_SUCCESS) { + * printf ("Failed to acquire the device: %s\n", cairo_status_to_string (status)); + * return; + * } + * + * // Do the custom operations on the device here. + * // But do not call any Cairo functions that might acquire devices. + * + * // Release the device when done. + * cairo_device_release (device); + * } + * + * + * Please refer to the documentation of each backend for + * additional usage requirements, guarantees provided, and + * interactions with existing surface API of the device functions for + * surfaces of that type. + * + **/ + +static const cairo_device_t _nil_device = { + CAIRO_REFERENCE_COUNT_INVALID, + CAIRO_STATUS_NO_MEMORY, +}; + +static const cairo_device_t _mismatch_device = { + CAIRO_REFERENCE_COUNT_INVALID, + CAIRO_STATUS_DEVICE_TYPE_MISMATCH, +}; + +static const cairo_device_t _invalid_device = { + CAIRO_REFERENCE_COUNT_INVALID, + CAIRO_STATUS_DEVICE_ERROR, +}; + +cairo_device_t * +_cairo_device_create_in_error (cairo_status_t status) +{ + switch (status) { + case CAIRO_STATUS_NO_MEMORY: + return (cairo_device_t *) &_nil_device; + case CAIRO_STATUS_DEVICE_ERROR: + return (cairo_device_t *) &_invalid_device; + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: + return (cairo_device_t *) &_mismatch_device; + + case CAIRO_STATUS_SUCCESS: + case CAIRO_STATUS_LAST_STATUS: + ASSERT_NOT_REACHED; + /* fall-through */ + case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: + case CAIRO_STATUS_INVALID_STATUS: + case CAIRO_STATUS_INVALID_FORMAT: + case CAIRO_STATUS_INVALID_VISUAL: + case CAIRO_STATUS_READ_ERROR: + case CAIRO_STATUS_WRITE_ERROR: + case CAIRO_STATUS_FILE_NOT_FOUND: + case CAIRO_STATUS_TEMP_FILE_ERROR: + case CAIRO_STATUS_INVALID_STRIDE: + case CAIRO_STATUS_INVALID_SIZE: + case CAIRO_STATUS_INVALID_RESTORE: + case CAIRO_STATUS_INVALID_POP_GROUP: + case CAIRO_STATUS_NO_CURRENT_POINT: + case CAIRO_STATUS_INVALID_MATRIX: + case CAIRO_STATUS_NULL_POINTER: + case CAIRO_STATUS_INVALID_STRING: + case CAIRO_STATUS_INVALID_PATH_DATA: + case CAIRO_STATUS_SURFACE_FINISHED: + case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: + case CAIRO_STATUS_INVALID_DASH: + case CAIRO_STATUS_INVALID_DSC_COMMENT: + case CAIRO_STATUS_INVALID_INDEX: + case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: + case CAIRO_STATUS_FONT_TYPE_MISMATCH: + case CAIRO_STATUS_USER_FONT_IMMUTABLE: + case CAIRO_STATUS_USER_FONT_ERROR: + case CAIRO_STATUS_NEGATIVE_COUNT: + case CAIRO_STATUS_INVALID_CLUSTERS: + case CAIRO_STATUS_INVALID_SLANT: + case CAIRO_STATUS_INVALID_WEIGHT: + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: + case CAIRO_STATUS_INVALID_CONTENT: + case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: + case CAIRO_STATUS_DEVICE_FINISHED: + case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: + default: + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_device_t *) &_nil_device; + } +} + +void +_cairo_device_init (cairo_device_t *device, + const cairo_device_backend_t *backend) +{ + CAIRO_REFERENCE_COUNT_INIT (&device->ref_count, 1); + device->status = CAIRO_STATUS_SUCCESS; + + device->backend = backend; + + CAIRO_RECURSIVE_MUTEX_INIT (device->mutex); + device->mutex_depth = 0; + + device->finished = FALSE; + + _cairo_user_data_array_init (&device->user_data); +} + +/** + * cairo_device_reference: + * @device: a #cairo_device_t + * + * Increases the reference count on @device by one. This prevents + * @device from being destroyed until a matching call to + * cairo_device_destroy() is made. + * + * The number of references to a #cairo_device_t can be get using + * cairo_device_get_reference_count(). + * + * Return value: the referenced #cairo_device_t. + * + * Since: 1.10 + **/ +cairo_device_t * +cairo_device_reference (cairo_device_t *device) +{ + if (device == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + { + return device; + } + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&device->ref_count)); + _cairo_reference_count_inc (&device->ref_count); + + return device; +} +slim_hidden_def (cairo_device_reference); + +/** + * cairo_device_status: + * @device: a #cairo_device_t + * + * Checks whether an error has previously occurred for this + * device. + * + * Return value: %CAIRO_STATUS_SUCCESS on success or an error code if + * the device is in an error state. + * + * Since: 1.10 + **/ +cairo_status_t +cairo_device_status (cairo_device_t *device) +{ + if (device == NULL) + return CAIRO_STATUS_NULL_POINTER; + + return device->status; +} + +/** + * cairo_device_flush: + * @device: a #cairo_device_t + * + * Finish any pending operations for the device and also restore any + * temporary modifications cairo has made to the device's state. + * This function must be called before switching from using the + * device with Cairo to operating on it directly with native APIs. + * If the device doesn't support direct access, then this function + * does nothing. + * + * This function may acquire devices. + * + * Since: 1.10 + **/ +void +cairo_device_flush (cairo_device_t *device) +{ + cairo_status_t status; + + if (device == NULL || device->status) + return; + + if (device->finished) + return; + + if (device->backend->flush != NULL) { + status = device->backend->flush (device); + if (unlikely (status)) + status = _cairo_device_set_error (device, status); + } +} +slim_hidden_def (cairo_device_flush); + +/** + * cairo_device_finish: + * @device: the #cairo_device_t to finish + * + * This function finishes the device and drops all references to + * external resources. All surfaces, fonts and other objects created + * for this @device will be finished, too. + * Further operations on the @device will not affect the @device but + * will instead trigger a %CAIRO_STATUS_DEVICE_FINISHED error. + * + * When the last call to cairo_device_destroy() decreases the + * reference count to zero, cairo will call cairo_device_finish() if + * it hasn't been called already, before freeing the resources + * associated with the device. + * + * This function may acquire devices. + * + * Since: 1.10 + **/ +void +cairo_device_finish (cairo_device_t *device) +{ + if (device == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + { + return; + } + + if (device->finished) + return; + + cairo_device_flush (device); + + if (device->backend->finish != NULL) + device->backend->finish (device); + + /* We only finish the device after the backend's callback returns because + * the device might still be needed during the callback + * (e.g. for cairo_device_acquire ()). + */ + device->finished = TRUE; +} +slim_hidden_def (cairo_device_finish); + +/** + * cairo_device_destroy: + * @device: a #cairo_device_t + * + * Decreases the reference count on @device by one. If the result is + * zero, then @device and all associated resources are freed. See + * cairo_device_reference(). + * + * This function may acquire devices if the last reference was dropped. + * + * Since: 1.10 + **/ +void +cairo_device_destroy (cairo_device_t *device) +{ + cairo_user_data_array_t user_data; + + if (device == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + { + return; + } + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&device->ref_count)); + if (! _cairo_reference_count_dec_and_test (&device->ref_count)) + return; + + cairo_device_finish (device); + + assert (device->mutex_depth == 0); + CAIRO_MUTEX_FINI (device->mutex); + + user_data = device->user_data; + + device->backend->destroy (device); + + _cairo_user_data_array_fini (&user_data); + +} +slim_hidden_def (cairo_device_destroy); + +/** + * cairo_device_get_type: + * @device: a #cairo_device_t + * + * This function returns the type of the device. See #cairo_device_type_t + * for available types. + * + * Return value: The type of @device. + * + * Since: 1.10 + **/ +cairo_device_type_t +cairo_device_get_type (cairo_device_t *device) +{ + if (device == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + { + return CAIRO_DEVICE_TYPE_INVALID; + } + + return device->backend->type; +} + +/** + * cairo_device_acquire: + * @device: a #cairo_device_t + * + * Acquires the @device for the current thread. This function will block + * until no other thread has acquired the device. + * + * If the return value is %CAIRO_STATUS_SUCCESS, you successfully acquired the + * device. From now on your thread owns the device and no other thread will be + * able to acquire it until a matching call to cairo_device_release(). It is + * allowed to recursively acquire the device multiple times from the same + * thread. + * + * You must never acquire two different devices at the same time + * unless this is explicitly allowed. Otherwise the possibility of deadlocks + * exist. + * + * As various Cairo functions can acquire devices when called, these functions + * may also cause deadlocks when you call them with an acquired device. So you + * must not have a device acquired when calling them. These functions are + * marked in the documentation. + * + * + * Return value: %CAIRO_STATUS_SUCCESS on success or an error code if + * the device is in an error state and could not be + * acquired. After a successful call to cairo_device_acquire(), + * a matching call to cairo_device_release() is required. + * + * Since: 1.10 + **/ +cairo_status_t +cairo_device_acquire (cairo_device_t *device) +{ + if (device == NULL) + return CAIRO_STATUS_SUCCESS; + + if (unlikely (device->status)) + return device->status; + + if (unlikely (device->finished)) + return _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_FINISHED); + + CAIRO_MUTEX_LOCK (device->mutex); + if (device->mutex_depth++ == 0) { + if (device->backend->lock != NULL) + device->backend->lock (device); + } + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_device_acquire); + +/** + * cairo_device_release: + * @device: a #cairo_device_t + * + * Releases a @device previously acquired using cairo_device_acquire(). See + * that function for details. + * + * Since: 1.10 + **/ +void +cairo_device_release (cairo_device_t *device) +{ + if (device == NULL) + return; + + assert (device->mutex_depth > 0); + + if (--device->mutex_depth == 0) { + if (device->backend->unlock != NULL) + device->backend->unlock (device); + } + + CAIRO_MUTEX_UNLOCK (device->mutex); +} +slim_hidden_def (cairo_device_release); + +cairo_status_t +_cairo_device_set_error (cairo_device_t *device, + cairo_status_t status) +{ + if (status == CAIRO_STATUS_SUCCESS) + return CAIRO_STATUS_SUCCESS; + + _cairo_status_set_error (&device->status, status); + + return _cairo_error (status); +} + +/** + * cairo_device_get_reference_count: + * @device: a #cairo_device_t + * + * Returns the current reference count of @device. + * + * Return value: the current reference count of @device. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.10 + **/ +unsigned int +cairo_device_get_reference_count (cairo_device_t *device) +{ + if (device == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&device->ref_count); +} + +/** + * cairo_device_get_user_data: + * @device: a #cairo_device_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @device using the + * specified key. If no user data has been attached with the given + * key this function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.10 + **/ +void * +cairo_device_get_user_data (cairo_device_t *device, + const cairo_user_data_key_t *key) +{ + return _cairo_user_data_array_get_data (&device->user_data, + key); +} + +/** + * cairo_device_set_user_data: + * @device: a #cairo_device_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the #cairo_device_t + * @destroy: a #cairo_destroy_func_t which will be called when the + * #cairo_t is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @device. To remove user data from a surface, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.10 + **/ +cairo_status_t +cairo_device_set_user_data (cairo_device_t *device, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + return device->status; + + return _cairo_user_data_array_set_data (&device->user_data, + key, user_data, destroy); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-directfb-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-directfb-surface.c new file mode 100644 index 00000000000..5ac64ba98ee --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-directfb-surface.c @@ -0,0 +1,544 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-directfb.h" + +#include "cairo-clip-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-surface-fallback-private.h" + +#include + +#include +#include +#include +#include +#include + +slim_hidden_proto(cairo_directfb_surface_create); + +typedef struct _cairo_dfb_surface { + cairo_image_surface_t image; + + IDirectFB *dfb; + IDirectFBSurface *dfb_surface; + + unsigned blit_premultiplied : 1; +} cairo_dfb_surface_t; + +static cairo_content_t +_directfb_format_to_content (DFBSurfacePixelFormat format) +{ + cairo_content_t content = 0; + + if (DFB_PIXELFORMAT_HAS_ALPHA (format)) + content |= CAIRO_CONTENT_ALPHA; + if (DFB_COLOR_BITS_PER_PIXEL (format)) + content |= CAIRO_CONTENT_COLOR_ALPHA; + + assert(content); + return content; +} + +static inline pixman_format_code_t +_directfb_to_pixman_format (DFBSurfacePixelFormat format) +{ + switch (format) { + case DSPF_UNKNOWN: return 0; + case DSPF_ARGB1555: return PIXMAN_a1r5g5b5; + case DSPF_RGB16: return PIXMAN_r5g6b5; + case DSPF_RGB24: return PIXMAN_r8g8b8; + case DSPF_RGB32: return PIXMAN_x8r8g8b8; + case DSPF_ARGB: return PIXMAN_a8r8g8b8; + case DSPF_A8: return PIXMAN_a8; + case DSPF_YUY2: return PIXMAN_yuy2; + case DSPF_RGB332: return PIXMAN_r3g3b2; + case DSPF_UYVY: return 0; + case DSPF_I420: return 0; + case DSPF_YV12: return PIXMAN_yv12; + case DSPF_LUT8: return 0; + case DSPF_ALUT44: return 0; + case DSPF_AiRGB: return 0; + case DSPF_A1: return 0; /* bit reversed, oops */ + case DSPF_NV12: return 0; + case DSPF_NV16: return 0; + case DSPF_ARGB2554: return 0; + case DSPF_ARGB4444: return PIXMAN_a4r4g4b4; + case DSPF_NV21: return 0; + case DSPF_AYUV: return 0; + case DSPF_A4: return PIXMAN_a4; + case DSPF_ARGB1666: return 0; + case DSPF_ARGB6666: return 0; + case DSPF_RGB18: return 0; + case DSPF_LUT2: return 0; + case DSPF_RGB444: return PIXMAN_x4r4g4b4; + case DSPF_RGB555: return PIXMAN_x1r5g5b5; +#if DFB_NUM_PIXELFORMATS >= 29 + case DSPF_BGR555: return PIXMAN_x1b5g5r5; +#endif + } + return 0; +} + +static cairo_surface_t * +_cairo_dfb_surface_create_similar (void *abstract_src, + cairo_content_t content, + int width, + int height) +{ + cairo_dfb_surface_t *other = abstract_src; + DFBSurfacePixelFormat format; + IDirectFBSurface *buffer; + DFBSurfaceDescription dsc; + cairo_surface_t *surface; + + if (width <= 0 || height <= 0) + return _cairo_image_surface_create_with_content (content, width, height); + + switch (content) { + default: + ASSERT_NOT_REACHED; + case CAIRO_CONTENT_COLOR_ALPHA: + format = DSPF_ARGB; + break; + case CAIRO_CONTENT_COLOR: + format = DSPF_RGB32; + break; + case CAIRO_CONTENT_ALPHA: + format = DSPF_A8; + break; + } + + dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT; + dsc.caps = DSCAPS_PREMULTIPLIED; + dsc.width = width; + dsc.height = height; + dsc.pixelformat = format; + + if (other->dfb->CreateSurface (other->dfb, &dsc, &buffer)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_DEVICE_ERROR)); + + surface = cairo_directfb_surface_create (other->dfb, buffer); + buffer->Release (buffer); + + return surface; +} + +static cairo_status_t +_cairo_dfb_surface_finish (void *abstract_surface) +{ + cairo_dfb_surface_t *surface = abstract_surface; + + surface->dfb_surface->Release (surface->dfb_surface); + return _cairo_image_surface_finish (abstract_surface); +} + +static cairo_image_surface_t * +_cairo_dfb_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_dfb_surface_t *surface = abstract_surface; + + if (surface->image.pixman_image == NULL) { + IDirectFBSurface *buffer = surface->dfb_surface; + pixman_image_t *image; + void *data; + int pitch; + + if (buffer->Lock (buffer, DSLF_READ | DSLF_WRITE, &data, &pitch)) + return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + image = pixman_image_create_bits (surface->image.pixman_format, + surface->image.width, + surface->image.height, + data, pitch); + if (image == NULL) { + buffer->Unlock (buffer); + return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + _cairo_image_surface_init (&surface->image, image, surface->image.pixman_format); + } + + return _cairo_image_surface_map_to_image (&surface->image.base, extents); +} + +static cairo_int_status_t +_cairo_dfb_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_dfb_surface_t *surface = abstract_surface; + return _cairo_image_surface_unmap_image (&surface->image.base, image); +} + +static cairo_status_t +_cairo_dfb_surface_flush (void *abstract_surface, + unsigned flags) +{ + cairo_dfb_surface_t *surface = abstract_surface; + + if (flags) + return CAIRO_STATUS_SUCCESS; + + if (surface->image.pixman_image) { + surface->dfb_surface->Unlock (surface->dfb_surface); + + pixman_image_unref (surface->image.pixman_image); + surface->image.pixman_image = NULL; + surface->image.data = NULL; + } + + return CAIRO_STATUS_SUCCESS; +} + +#if 0 +static inline DFBSurfacePixelFormat +_directfb_from_pixman_format (pixman_format_code_t format) +{ + switch ((int) format) { + case PIXMAN_a1r5g5b5: return DSPF_ARGB1555; + case PIXMAN_r5g6b5: return DSPF_RGB16; + case PIXMAN_r8g8b8: return DSPF_RGB24; + case PIXMAN_x8r8g8b8: return DSPF_RGB32; + case PIXMAN_a8r8g8b8: return DSPF_ARGB; + case PIXMAN_a8: return DSPF_A8; + case PIXMAN_yuy2: return DSPF_YUY2; + case PIXMAN_r3g3b2: return DSPF_RGB332; + case PIXMAN_yv12: return DSPF_YV12; + case PIXMAN_a1: return DSPF_A1; /* bit reversed, oops */ + case PIXMAN_a4r4g4b4: return DSPF_ARGB4444; + case PIXMAN_a4: return DSPF_A4; + case PIXMAN_x4r4g4b4: return DSPF_RGB444; + case PIXMAN_x1r5g5b5: return DSPF_RGB555; +#if DFB_NUM_PIXELFORMATS >= 29 + case PIXMAN_x1b5g5r5: return DSPF_BGR555; +#endif + default: return 0; + } +} + +static cairo_bool_t +_directfb_get_operator (cairo_operator_t operator, + DFBSurfaceBlendFunction *ret_srcblend, + DFBSurfaceBlendFunction *ret_dstblend) +{ + DFBSurfaceBlendFunction srcblend = DSBF_ONE; + DFBSurfaceBlendFunction dstblend = DSBF_ZERO; + + switch (operator) { + case CAIRO_OPERATOR_CLEAR: + srcblend = DSBF_ZERO; + dstblend = DSBF_ZERO; + break; + case CAIRO_OPERATOR_SOURCE: + srcblend = DSBF_ONE; + dstblend = DSBF_ZERO; + break; + case CAIRO_OPERATOR_OVER: + srcblend = DSBF_ONE; + dstblend = DSBF_INVSRCALPHA; + break; + case CAIRO_OPERATOR_IN: + srcblend = DSBF_DESTALPHA; + dstblend = DSBF_ZERO; + break; + case CAIRO_OPERATOR_OUT: + srcblend = DSBF_INVDESTALPHA; + dstblend = DSBF_ZERO; + break; + case CAIRO_OPERATOR_ATOP: + srcblend = DSBF_DESTALPHA; + dstblend = DSBF_INVSRCALPHA; + break; + case CAIRO_OPERATOR_DEST: + srcblend = DSBF_ZERO; + dstblend = DSBF_ONE; + break; + case CAIRO_OPERATOR_DEST_OVER: + srcblend = DSBF_INVDESTALPHA; + dstblend = DSBF_ONE; + break; + case CAIRO_OPERATOR_DEST_IN: + srcblend = DSBF_ZERO; + dstblend = DSBF_SRCALPHA; + break; + case CAIRO_OPERATOR_DEST_OUT: + srcblend = DSBF_ZERO; + dstblend = DSBF_INVSRCALPHA; + break; + case CAIRO_OPERATOR_DEST_ATOP: + srcblend = DSBF_INVDESTALPHA; + dstblend = DSBF_SRCALPHA; + break; + case CAIRO_OPERATOR_XOR: + srcblend = DSBF_INVDESTALPHA; + dstblend = DSBF_INVSRCALPHA; + break; + case CAIRO_OPERATOR_ADD: + srcblend = DSBF_ONE; + dstblend = DSBF_ONE; + break; + case CAIRO_OPERATOR_SATURATE: + /* XXX This does not work. */ +#if 0 + srcblend = DSBF_SRCALPHASAT; + dstblend = DSBF_ONE; + break; +#endif + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + default: + return FALSE; + } + + *ret_srcblend = srcblend; + *ret_dstblend = dstblend; + + return TRUE; +} +#define RUN_CLIPPED(surface, clip_region, clip, func) {\ + if ((clip_region) != NULL) {\ + int n_clips = cairo_region_num_rectangles (clip_region), n; \ + for (n = 0; n < n_clips; n++) {\ + if (clip) {\ + DFBRegion reg, *cli = (clip); \ + cairo_rectangle_int_t rect; \ + cairo_region_get_rectangle (clip_region, n, &rect); \ + reg.x1 = rect.x; \ + reg.y1 = rect.y; \ + reg.x2 = rect.x + rect.width - 1; \ + reg.y2 = rect.y + rect.height - 1; \ + if (reg.x2 < cli->x1 || reg.y2 < cli->y1 ||\ + reg.x1 > cli->x2 || reg.y1 > cli->y2)\ + continue;\ + if (reg.x1 < cli->x1)\ + reg.x1 = cli->x1;\ + if (reg.y1 < cli->y1)\ + reg.y1 = cli->y1;\ + if (reg.x2 > cli->x2)\ + reg.x2 = cli->x2;\ + if (reg.y2 > cli->y2)\ + reg.y2 = cli->y2;\ + (surface)->dfbsurface->SetClip ((surface)->dfbsurface, ®);\ + } else {\ + DFBRegion reg; \ + cairo_rectangle_int_t rect; \ + cairo_region_get_rectangle (clip_region, n, &rect); \ + reg.x1 = rect.x; \ + reg.y1 = rect.y; \ + reg.x2 = rect.x + rect.width - 1; \ + reg.y2 = rect.y + rect.height - 1; \ + (surface)->dfbsurface->SetClip ((surface)->dfbsurface, ®); \ + }\ + func;\ + }\ + } else {\ + (surface)->dfbsurface->SetClip ((surface)->dfbsurface, clip);\ + func;\ + }\ +} + +static cairo_int_status_t +_cairo_dfb_surface_fill_rectangles (void *abstract_surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_rectangle_int_t *rects, + int n_rects) +{ + cairo_dfb_surface_t *dst = abstract_surface; + DFBSurfaceDrawingFlags flags; + DFBSurfaceBlendFunction sblend; + DFBSurfaceBlendFunction dblend; + DFBRectangle r[n_rects]; + int i; + + D_DEBUG_AT (CairoDFB_Render, + "%s( dst=%p, op=%d, color=%p, rects=%p, n_rects=%d ).\n", + __FUNCTION__, dst, op, color, rects, n_rects); + + if (! dst->supported_destination) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _directfb_get_operator (op, &sblend, &dblend)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (CAIRO_COLOR_IS_OPAQUE (color)) { + if (sblend == DSBF_SRCALPHA) + sblend = DSBF_ONE; + else if (sblend == DSBF_INVSRCALPHA) + sblend = DSBF_ZERO; + + if (dblend == DSBF_SRCALPHA) + dblend = DSBF_ONE; + else if (dblend == DSBF_INVSRCALPHA) + dblend = DSBF_ZERO; + } + if ((dst->base.content & CAIRO_CONTENT_ALPHA) == 0) { + if (sblend == DSBF_DESTALPHA) + sblend = DSBF_ONE; + else if (sblend == DSBF_INVDESTALPHA) + sblend = DSBF_ZERO; + + if (dblend == DSBF_DESTALPHA) + dblend = DSBF_ONE; + else if (dblend == DSBF_INVDESTALPHA) + dblend = DSBF_ZERO; + } + + flags = (sblend == DSBF_ONE && dblend == DSBF_ZERO) ? DSDRAW_NOFX : DSDRAW_BLEND; + dst->dfbsurface->SetDrawingFlags (dst->dfbsurface, flags); + if (flags & DSDRAW_BLEND) { + dst->dfbsurface->SetSrcBlendFunction (dst->dfbsurface, sblend); + dst->dfbsurface->SetDstBlendFunction (dst->dfbsurface, dblend); + } + + dst->dfbsurface->SetColor (dst->dfbsurface, + color->red_short >> 8, + color->green_short >> 8, + color->blue_short >> 8, + color->alpha_short >> 8); + + for (i = 0; i < n_rects; i++) { + r[i].x = rects[i].x; + r[i].y = rects[i].y; + r[i].w = rects[i].width; + r[i].h = rects[i].height; + } + + RUN_CLIPPED (dst, NULL, NULL, + dst->dfbsurface->FillRectangles (dst->dfbsurface, r, n_rects)); + + return CAIRO_STATUS_SUCCESS; +} +#endif + +static cairo_surface_backend_t +_cairo_dfb_surface_backend = { + CAIRO_SURFACE_TYPE_DIRECTFB, /*type*/ + _cairo_dfb_surface_finish, /*finish*/ + _cairo_default_context_create, + + _cairo_dfb_surface_create_similar,/*create_similar*/ + NULL, /* create similar image */ + _cairo_dfb_surface_map_to_image, + _cairo_dfb_surface_unmap_image, + + _cairo_surface_default_source, + _cairo_surface_default_acquire_source_image, + _cairo_surface_default_release_source_image, + NULL, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_image_surface_get_extents, + _cairo_image_surface_get_font_options, + + _cairo_dfb_surface_flush, + NULL, /* mark_dirty_rectangle */ + + _cairo_surface_fallback_paint, + _cairo_surface_fallback_mask, + _cairo_surface_fallback_stroke, + _cairo_surface_fallback_fill, + NULL, /* fill-stroke */ + _cairo_surface_fallback_glyphs, +}; + +cairo_surface_t * +cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *dfbsurface) +{ + cairo_dfb_surface_t *surface; + DFBSurfacePixelFormat format; + DFBSurfaceCapabilities caps; + pixman_format_code_t pixman_format; + int width, height; + + D_ASSERT (dfb != NULL); + D_ASSERT (dfbsurface != NULL); + + dfbsurface->GetPixelFormat (dfbsurface, &format); + dfbsurface->GetSize (dfbsurface, &width, &height); + + pixman_format = _directfb_to_pixman_format (format); + if (! pixman_format_supported_destination (pixman_format)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + + surface = calloc (1, sizeof (cairo_dfb_surface_t)); + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + /* XXX dfb -> device */ + _cairo_surface_init (&surface->image.base, + &_cairo_dfb_surface_backend, + NULL, /* device */ + _directfb_format_to_content (format)); + + surface->image.pixman_format = pixman_format; + surface->image.format = _cairo_format_from_pixman_format (pixman_format); + + surface->image.width = width; + surface->image.height = height; + surface->image.depth = PIXMAN_FORMAT_DEPTH(pixman_format); + + surface->dfb = dfb; + surface->dfb_surface = dfbsurface; + dfbsurface->AddRef (dfbsurface); + + dfbsurface->GetCapabilities (dfbsurface, &caps); + if (caps & DSCAPS_PREMULTIPLIED) + surface->blit_premultiplied = TRUE; + + return &surface->image.base; +} +slim_hidden_def(cairo_directfb_surface_create); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-directfb.h b/Build/source/libs/cairo/cairo-src/src/cairo-directfb.h new file mode 100644 index 00000000000..e3d818c6687 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-directfb.h @@ -0,0 +1,67 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +/* + * Environment variables affecting the backend: + * + * %CAIRO_DIRECTFB_NO_ACCEL (boolean) + * if found, disables acceleration at all + * + * %CAIRO_DIRECTFB_ARGB_FONT (boolean) + * if found, enables using ARGB fonts instead of A8 + */ + +#ifndef CAIRO_DIRECTFB_H +#define CAIRO_DIRECTFB_H + +#include "cairo.h" + +#if CAIRO_HAS_DIRECTFB_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *surface); + +CAIRO_END_DECLS + +#else /*CAIRO_HAS_DIRECTFB_SURFACE*/ +# error Cairo was not compiled with support for the directfb backend +#endif /*CAIRO_HAS_DIRECTFB_SURFACE*/ + +#endif /*CAIRO_DIRECTFB_H*/ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-drm.h b/Build/source/libs/cairo/cairo-src/src/cairo-drm.h new file mode 100644 index 00000000000..907610dcde8 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-drm.h @@ -0,0 +1,120 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + */ + +#ifndef CAIRO_DRM_H +#define CAIRO_DRM_H + +#include "cairo.h" + +#if CAIRO_HAS_DRM_SURFACE + +CAIRO_BEGIN_DECLS + +struct udev_device; + +cairo_public cairo_device_t * +cairo_drm_device_get (struct udev_device *device); + +cairo_public cairo_device_t * +cairo_drm_device_get_for_fd (int fd); + +cairo_public cairo_device_t * +cairo_drm_device_default (void); + +cairo_public int +cairo_drm_device_get_fd (cairo_device_t *device); + +cairo_public void +cairo_drm_device_throttle (cairo_device_t *device); + +cairo_public cairo_surface_t * +cairo_drm_surface_create (cairo_device_t *device, + cairo_format_t format, + int width, int height); + +cairo_public cairo_surface_t * +cairo_drm_surface_create_for_name (cairo_device_t *device, + unsigned int name, + cairo_format_t format, + int width, int height, int stride); + +cairo_public cairo_surface_t * +cairo_drm_surface_create_from_cacheable_image (cairo_device_t *device, + cairo_surface_t *surface); + +cairo_public cairo_status_t +cairo_drm_surface_enable_scan_out (cairo_surface_t *surface); + +cairo_public unsigned int +cairo_drm_surface_get_handle (cairo_surface_t *surface); + +cairo_public unsigned int +cairo_drm_surface_get_name (cairo_surface_t *surface); + +cairo_public cairo_format_t +cairo_drm_surface_get_format (cairo_surface_t *surface); + +cairo_public int +cairo_drm_surface_get_width (cairo_surface_t *surface); + +cairo_public int +cairo_drm_surface_get_height (cairo_surface_t *surface); + +cairo_public int +cairo_drm_surface_get_stride (cairo_surface_t *surface); + +/* XXX map/unmap, general surface layer? */ + +/* Rough outline, culled from a conversation on IRC: + * map() returns an image-surface representation of the drm-surface, + * which you unmap() when you are finished, i.e. map() pulls the buffer back + * from the GPU, maps it into the CPU domain and gives you direct access to + * the pixels. With the unmap(), the buffer is ready to be used again by the + * GPU and *until* the unmap(), all operations will be done in software. + * + * (Technically calling cairo_surface_flush() on the underlying drm-surface + * will also disassociate the mapping.) +*/ +cairo_public cairo_surface_t * +cairo_drm_surface_map_to_image (cairo_surface_t *surface); + +cairo_public void +cairo_drm_surface_unmap (cairo_surface_t *drm_surface, + cairo_surface_t *image_surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_DRM_SURFACE */ +# error Cairo was not compiled with support for the DRM backend +#endif /* CAIRO_HAS_DRM_SURFACE */ + +#endif /* CAIRO_DRM_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-egl-context.c b/Build/source/libs/cairo/cairo-src/src/cairo-egl-context.c new file mode 100644 index 00000000000..bf704c630fb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-egl-context.c @@ -0,0 +1,317 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-error-private.h" + +typedef struct _cairo_egl_context { + cairo_gl_context_t base; + + EGLDisplay display; + EGLContext context; + + EGLSurface dummy_surface; + + EGLContext previous_context; + EGLSurface previous_surface; +} cairo_egl_context_t; + +typedef struct _cairo_egl_surface { + cairo_gl_surface_t base; + + EGLSurface egl; +} cairo_egl_surface_t; + + +static cairo_bool_t +_context_acquisition_changed_egl_state (cairo_egl_context_t *ctx, + EGLSurface current_surface) +{ + return ctx->previous_context != ctx->context || + ctx->previous_surface != current_surface; +} + +static EGLSurface +_egl_get_current_surface (cairo_egl_context_t *ctx) +{ + if (ctx->base.current_target == NULL || + _cairo_gl_surface_is_texture (ctx->base.current_target)) { + return ctx->dummy_surface; + } + + return ((cairo_egl_surface_t *) ctx->base.current_target)->egl; +} + +static void +_egl_query_current_state (cairo_egl_context_t *ctx) +{ + ctx->previous_surface = eglGetCurrentSurface (EGL_DRAW); + ctx->previous_context = eglGetCurrentContext (); + + /* If any of the values were none, assume they are all none. Not all + drivers seem well behaved when it comes to using these values across + multiple threads. */ + if (ctx->previous_surface == EGL_NO_SURFACE || + ctx->previous_context == EGL_NO_CONTEXT) { + ctx->previous_surface = EGL_NO_SURFACE; + ctx->previous_context = EGL_NO_CONTEXT; + } +} + +static void +_egl_acquire (void *abstract_ctx) +{ + cairo_egl_context_t *ctx = abstract_ctx; + EGLSurface current_surface = _egl_get_current_surface (ctx); + + _egl_query_current_state (ctx); + if (!_context_acquisition_changed_egl_state (ctx, current_surface)) + return; + + eglMakeCurrent (ctx->display, + current_surface, current_surface, ctx->context); +} + +static void +_egl_release (void *abstract_ctx) +{ + cairo_egl_context_t *ctx = abstract_ctx; + if (!ctx->base.thread_aware || + !_context_acquisition_changed_egl_state (ctx, + _egl_get_current_surface (ctx))) { + return; + } + + eglMakeCurrent (ctx->display, + EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + +static void +_egl_make_current (void *abstract_ctx, + cairo_gl_surface_t *abstract_surface) +{ + cairo_egl_context_t *ctx = abstract_ctx; + cairo_egl_surface_t *surface = (cairo_egl_surface_t *) abstract_surface; + + eglMakeCurrent(ctx->display, surface->egl, surface->egl, ctx->context); +} + +static void +_egl_swap_buffers (void *abstract_ctx, + cairo_gl_surface_t *abstract_surface) +{ + cairo_egl_context_t *ctx = abstract_ctx; + cairo_egl_surface_t *surface = (cairo_egl_surface_t *) abstract_surface; + + eglSwapBuffers (ctx->display, surface->egl); +} + +static void +_egl_destroy (void *abstract_ctx) +{ + cairo_egl_context_t *ctx = abstract_ctx; + + eglMakeCurrent (ctx->display, + EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (ctx->dummy_surface != EGL_NO_SURFACE) + eglDestroySurface (ctx->display, ctx->dummy_surface); +} + +static cairo_bool_t +_egl_make_current_surfaceless(cairo_egl_context_t *ctx) +{ + const char *extensions; + + extensions = eglQueryString(ctx->display, EGL_EXTENSIONS); + if (strstr(extensions, "EGL_KHR_surfaceless_context") == NULL && + strstr(extensions, "EGL_KHR_surfaceless_opengl") == NULL) + return FALSE; + + if (!eglMakeCurrent(ctx->display, + EGL_NO_SURFACE, EGL_NO_SURFACE, ctx->context)) + return FALSE; + + return TRUE; +} + +cairo_device_t * +cairo_egl_device_create (EGLDisplay dpy, EGLContext egl) +{ + cairo_egl_context_t *ctx; + cairo_status_t status; + int attribs[] = { + EGL_WIDTH, 1, + EGL_HEIGHT, 1, + EGL_NONE, + }; + EGLConfig config; + EGLint numConfigs; + + ctx = calloc (1, sizeof (cairo_egl_context_t)); + if (unlikely (ctx == NULL)) + return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); + + ctx->display = dpy; + ctx->context = egl; + + ctx->base.acquire = _egl_acquire; + ctx->base.release = _egl_release; + ctx->base.make_current = _egl_make_current; + ctx->base.swap_buffers = _egl_swap_buffers; + ctx->base.destroy = _egl_destroy; + + /* We are about the change the current state of EGL, so we should + * query the pre-existing surface now instead of later. */ + _egl_query_current_state (ctx); + + if (!_egl_make_current_surfaceless (ctx)) { + /* Fall back to dummy surface, meh. */ + EGLint config_attribs[] = { + EGL_CONFIG_ID, 0, + EGL_NONE + }; + + /* + * In order to be able to make an egl context current when using a + * pbuffer surface, that surface must have been created with a config + * that is compatible with the context config. For Mesa, this means + * that the configs must be the same. + */ + eglQueryContext (dpy, egl, EGL_CONFIG_ID, &config_attribs[1]); + eglChooseConfig (dpy, config_attribs, &config, 1, &numConfigs); + + ctx->dummy_surface = eglCreatePbufferSurface (dpy, config, attribs); + if (ctx->dummy_surface == NULL) { + free (ctx); + return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) { + free (ctx); + return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + } + + status = _cairo_gl_dispatch_init (&ctx->base.dispatch, eglGetProcAddress); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + status = _cairo_gl_context_init (&ctx->base); + if (unlikely (status)) { + if (ctx->dummy_surface != EGL_NO_SURFACE) + eglDestroySurface (dpy, ctx->dummy_surface); + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + /* Tune the default VBO size to reduce overhead on embedded devices. + * This smaller size means that flushing needs to be done more often, + * but it is less demanding of scarce memory on embedded devices. + */ + ctx->base.vbo_size = 16*1024; + + eglMakeCurrent (dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + return &ctx->base.base; +} + +cairo_surface_t * +cairo_gl_surface_create_for_egl (cairo_device_t *device, + EGLSurface egl, + int width, + int height) +{ + cairo_egl_surface_t *surface; + + if (unlikely (device->status)) + return _cairo_surface_create_in_error (device->status); + + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + + if (width <= 0 || height <= 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + surface = calloc (1, sizeof (cairo_egl_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_gl_surface_init (device, &surface->base, + CAIRO_CONTENT_COLOR_ALPHA, width, height); + surface->egl = egl; + + return &surface->base.base; +} + +static cairo_bool_t is_egl_device (cairo_device_t *device) +{ + return (device->backend != NULL && + device->backend->type == CAIRO_DEVICE_TYPE_GL); +} + +static cairo_egl_context_t *to_egl_context (cairo_device_t *device) +{ + return (cairo_egl_context_t *) device; +} + +EGLDisplay +cairo_egl_device_get_display (cairo_device_t *device) +{ + if (! is_egl_device (device)) { + _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + return EGL_NO_DISPLAY; + } + + return to_egl_context (device)->display; +} + +cairo_public EGLContext +cairo_egl_device_get_context (cairo_device_t *device) +{ + if (! is_egl_device (device)) { + _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + return EGL_NO_CONTEXT; + } + + return to_egl_context (device)->context; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-error-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-error-inline.h new file mode 100644 index 00000000000..9126c5e61eb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-error-inline.h @@ -0,0 +1,52 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef _CAIRO_ERROR_INLINE_H_ +#define _CAIRO_ERROR_INLINE_H_ + +#include "cairo-error-private.h" + +CAIRO_BEGIN_DECLS + +static inline cairo_status_t +_cairo_public_status (cairo_int_status_t status) +{ + assert (status <= CAIRO_INT_STATUS_LAST_STATUS); + return (cairo_status_t) status; +} + +#endif /* _CAIRO_ERROR_INLINE_H_ */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-error-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-error-private.h new file mode 100644 index 00000000000..178078ad614 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-error-private.h @@ -0,0 +1,127 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef _CAIRO_ERROR_PRIVATE_H_ +#define _CAIRO_ERROR_PRIVATE_H_ + +#include "cairo.h" +#include "cairo-compiler-private.h" +#include "cairo-types-private.h" + +#include + +CAIRO_BEGIN_DECLS + +/* _cairo_int_status: internal status + * + * Sure wish C had a real enum type so that this would be distinct + * from #cairo_status_t. Oh well, without that, I'll use this bogus 100 + * offset. We want to keep it fit in int8_t as the compiler may choose + * that for #cairo_status_t + */ +enum _cairo_int_status { + CAIRO_INT_STATUS_SUCCESS = 0, + + CAIRO_INT_STATUS_NO_MEMORY, + CAIRO_INT_STATUS_INVALID_RESTORE, + CAIRO_INT_STATUS_INVALID_POP_GROUP, + CAIRO_INT_STATUS_NO_CURRENT_POINT, + CAIRO_INT_STATUS_INVALID_MATRIX, + CAIRO_INT_STATUS_INVALID_STATUS, + CAIRO_INT_STATUS_NULL_POINTER, + CAIRO_INT_STATUS_INVALID_STRING, + CAIRO_INT_STATUS_INVALID_PATH_DATA, + CAIRO_INT_STATUS_READ_ERROR, + CAIRO_INT_STATUS_WRITE_ERROR, + CAIRO_INT_STATUS_SURFACE_FINISHED, + CAIRO_INT_STATUS_SURFACE_TYPE_MISMATCH, + CAIRO_INT_STATUS_PATTERN_TYPE_MISMATCH, + CAIRO_INT_STATUS_INVALID_CONTENT, + CAIRO_INT_STATUS_INVALID_FORMAT, + CAIRO_INT_STATUS_INVALID_VISUAL, + CAIRO_INT_STATUS_FILE_NOT_FOUND, + CAIRO_INT_STATUS_INVALID_DASH, + CAIRO_INT_STATUS_INVALID_DSC_COMMENT, + CAIRO_INT_STATUS_INVALID_INDEX, + CAIRO_INT_STATUS_CLIP_NOT_REPRESENTABLE, + CAIRO_INT_STATUS_TEMP_FILE_ERROR, + CAIRO_INT_STATUS_INVALID_STRIDE, + CAIRO_INT_STATUS_FONT_TYPE_MISMATCH, + CAIRO_INT_STATUS_USER_FONT_IMMUTABLE, + CAIRO_INT_STATUS_USER_FONT_ERROR, + CAIRO_INT_STATUS_NEGATIVE_COUNT, + CAIRO_INT_STATUS_INVALID_CLUSTERS, + CAIRO_INT_STATUS_INVALID_SLANT, + CAIRO_INT_STATUS_INVALID_WEIGHT, + CAIRO_INT_STATUS_INVALID_SIZE, + CAIRO_INT_STATUS_USER_FONT_NOT_IMPLEMENTED, + CAIRO_INT_STATUS_DEVICE_TYPE_MISMATCH, + CAIRO_INT_STATUS_DEVICE_ERROR, + CAIRO_INT_STATUS_INVALID_MESH_CONSTRUCTION, + CAIRO_INT_STATUS_DEVICE_FINISHED, + CAIRO_INT_STATUS_JBIG2_GLOBAL_MISSING, + + CAIRO_INT_STATUS_LAST_STATUS, + + CAIRO_INT_STATUS_UNSUPPORTED = 100, + CAIRO_INT_STATUS_DEGENERATE, + CAIRO_INT_STATUS_NOTHING_TO_DO, + CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY, + CAIRO_INT_STATUS_IMAGE_FALLBACK, + CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN, +}; + +typedef enum _cairo_int_status cairo_int_status_t; + +#define _cairo_status_is_error(status) \ + (status != CAIRO_STATUS_SUCCESS && status < CAIRO_STATUS_LAST_STATUS) + +#define _cairo_int_status_is_error(status) \ + (status != CAIRO_INT_STATUS_SUCCESS && status < CAIRO_INT_STATUS_LAST_STATUS) + +cairo_private cairo_status_t +_cairo_error (cairo_status_t status); + +/* hide compiler warnings when discarding the return value */ +#define _cairo_error_throw(status) do { \ + cairo_status_t status__ = _cairo_error (status); \ + (void) status__; \ +} while (0) + +CAIRO_END_DECLS + +#endif /* _CAIRO_ERROR_PRIVATE_H_ */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-error.c b/Build/source/libs/cairo/cairo-src/src/cairo-error.c new file mode 100644 index 00000000000..1b9bd76be13 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-error.c @@ -0,0 +1,73 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" +#include "cairo-private.h" + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" + +#include + +/** + * _cairo_error: + * @status: a status value indicating an error, (eg. not + * %CAIRO_STATUS_SUCCESS) + * + * Checks that status is an error status, but does nothing else. + * + * All assignments of an error status to any user-visible object + * within the cairo application should result in a call to + * _cairo_error(). + * + * The purpose of this function is to allow the user to set a + * breakpoint in _cairo_error() to generate a stack trace for when the + * user causes cairo to detect an error. + * + * Return value: the error status. + **/ +cairo_status_t +_cairo_error (cairo_status_t status) +{ + CAIRO_ENSURE_UNIQUE; + assert (_cairo_status_is_error (status)); + + return status; +} + +COMPILE_TIME_ASSERT ((int)CAIRO_INT_STATUS_LAST_STATUS == (int)CAIRO_STATUS_LAST_STATUS); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-fallback-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-fallback-compositor.c new file mode 100644 index 00000000000..3f6199fe2bb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-fallback-compositor.c @@ -0,0 +1,185 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-compositor-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-offset-private.h" + +/* high-level compositor interface */ + +static cairo_int_status_t +_cairo_fallback_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_image_surface_t *image; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); + + status = _cairo_surface_offset_paint (&image->base, + extents->unbounded.x, + extents->unbounded.y, + extents->op, + &extents->source_pattern.base, + extents->clip); + + return _cairo_surface_unmap_image (extents->surface, image); +} + +static cairo_int_status_t +_cairo_fallback_compositor_mask (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_image_surface_t *image; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); + + status = _cairo_surface_offset_mask (&image->base, + extents->unbounded.x, + extents->unbounded.y, + extents->op, + &extents->source_pattern.base, + &extents->mask_pattern.base, + extents->clip); + + return _cairo_surface_unmap_image (extents->surface, image); +} + +static cairo_int_status_t +_cairo_fallback_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_image_surface_t *image; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); + + status = _cairo_surface_offset_stroke (&image->base, + extents->unbounded.x, + extents->unbounded.y, + extents->op, + &extents->source_pattern.base, + path, style, + ctm, ctm_inverse, + tolerance, + antialias, + extents->clip); + + return _cairo_surface_unmap_image (extents->surface, image); +} + +static cairo_int_status_t +_cairo_fallback_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_image_surface_t *image; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); + + status = _cairo_surface_offset_fill (&image->base, + extents->unbounded.x, + extents->unbounded.y, + extents->op, + &extents->source_pattern.base, + path, + fill_rule, tolerance, antialias, + extents->clip); + + return _cairo_surface_unmap_image (extents->surface, image); +} + +static cairo_int_status_t +_cairo_fallback_compositor_glyphs (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_image_surface_t *image; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = _cairo_surface_map_to_image (extents->surface, &extents->unbounded); + + status = _cairo_surface_offset_glyphs (&image->base, + extents->unbounded.x, + extents->unbounded.y, + extents->op, + &extents->source_pattern.base, + scaled_font, glyphs, num_glyphs, + extents->clip); + + return _cairo_surface_unmap_image (extents->surface, image); +} + +const cairo_compositor_t _cairo_fallback_compositor = { + &__cairo_no_compositor, + + _cairo_fallback_compositor_paint, + _cairo_fallback_compositor_mask, + _cairo_fallback_compositor_stroke, + _cairo_fallback_compositor_fill, + _cairo_fallback_compositor_glyphs, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-features-uninstalled.pc.in b/Build/source/libs/cairo/cairo-src/src/cairo-features-uninstalled.pc.in new file mode 100644 index 00000000000..b9cd9d3ad2b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-features-uninstalled.pc.in @@ -0,0 +1,7 @@ +Name: @FEATURE_PC@ +Description: @FEATURE_NAME@ for cairo graphics library +Version: @VERSION@ + +Requires: @FEATURE_BASE@ @FEATURE_REQUIRES@ +Libs: @FEATURE_NONPKGCONFIG_LIBS@ @FEATURE_NONPKGCONFIG_EXTRA_LIBS@ +Cflags: -I${pc_top_builddir}/${pcfiledir}/@srcdir@/src @FEATURE_NONPKGCONFIG_CFLAGS@ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-features.pc.in b/Build/source/libs/cairo/cairo-src/src/cairo-features.pc.in new file mode 100644 index 00000000000..9a4b657c8da --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-features.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @FEATURE_PC@ +Description: @FEATURE_NAME@ for cairo graphics library +Version: @VERSION@ + +Requires: @FEATURE_BASE@ @FEATURE_REQUIRES@ +Libs: @FEATURE_NONPKGCONFIG_LIBS@ @FEATURE_NONPKGCONFIG_EXTRA_LIBS@ +Cflags: -I${includedir}/cairo @FEATURE_NONPKGCONFIG_CFLAGS@ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-fixed-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-fixed-private.h new file mode 100644 index 00000000000..9ff8f750392 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-fixed-private.h @@ -0,0 +1,395 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#ifndef CAIRO_FIXED_PRIVATE_H +#define CAIRO_FIXED_PRIVATE_H + +#include "cairo-fixed-type-private.h" + +#include "cairo-wideint-private.h" +#include "cairoint.h" + +/* Implementation */ + +#if (CAIRO_FIXED_BITS != 32) +# error CAIRO_FIXED_BITS must be 32, and the type must be a 32-bit type. +# error To remove this limitation, you will have to fix the tessellator. +#endif + +#define CAIRO_FIXED_ONE ((cairo_fixed_t)(1 << CAIRO_FIXED_FRAC_BITS)) +#define CAIRO_FIXED_ONE_DOUBLE ((double)(1 << CAIRO_FIXED_FRAC_BITS)) +#define CAIRO_FIXED_EPSILON ((cairo_fixed_t)(1)) + +#define CAIRO_FIXED_ERROR_DOUBLE (1. / (2 * CAIRO_FIXED_ONE_DOUBLE)) + +#define CAIRO_FIXED_FRAC_MASK ((cairo_fixed_t)(((cairo_fixed_unsigned_t)(-1)) >> (CAIRO_FIXED_BITS - CAIRO_FIXED_FRAC_BITS))) +#define CAIRO_FIXED_WHOLE_MASK (~CAIRO_FIXED_FRAC_MASK) + +static inline cairo_fixed_t +_cairo_fixed_from_int (int i) +{ + return i << CAIRO_FIXED_FRAC_BITS; +} + +/* This is the "magic number" approach to converting a double into fixed + * point as described here: + * + * http://www.stereopsis.com/sree/fpu2006.html (an overview) + * http://www.d6.com/users/checker/pdfs/gdmfp.pdf (in detail) + * + * The basic idea is to add a large enough number to the double that the + * literal floating point is moved up to the extent that it forces the + * double's value to be shifted down to the bottom of the mantissa (to make + * room for the large number being added in). Since the mantissa is, at a + * given moment in time, a fixed point integer itself, one can convert a + * float to various fixed point representations by moving around the point + * of a floating point number through arithmetic operations. This behavior + * is reliable on most modern platforms as it is mandated by the IEEE-754 + * standard for floating point arithmetic. + * + * For our purposes, a "magic number" must be carefully selected that is + * both large enough to produce the desired point-shifting effect, and also + * has no lower bits in its representation that would interfere with our + * value at the bottom of the mantissa. The magic number is calculated as + * follows: + * + * (2 ^ (MANTISSA_SIZE - FRACTIONAL_SIZE)) * 1.5 + * + * where in our case: + * - MANTISSA_SIZE for 64-bit doubles is 52 + * - FRACTIONAL_SIZE for 16.16 fixed point is 16 + * + * Although this approach provides a very large speedup of this function + * on a wide-array of systems, it does come with two caveats: + * + * 1) It uses banker's rounding as opposed to arithmetic rounding. + * 2) It doesn't function properly if the FPU is in single-precision + * mode. + */ + +/* The 16.16 number must always be available */ +#define CAIRO_MAGIC_NUMBER_FIXED_16_16 (103079215104.0) + +#if CAIRO_FIXED_BITS <= 32 +#define CAIRO_MAGIC_NUMBER_FIXED ((1LL << (52 - CAIRO_FIXED_FRAC_BITS)) * 1.5) + +/* For 32-bit fixed point numbers */ +static inline cairo_fixed_t +_cairo_fixed_from_double (double d) +{ + union { + double d; + int32_t i[2]; + } u; + + u.d = d + CAIRO_MAGIC_NUMBER_FIXED; +#ifdef FLOAT_WORDS_BIGENDIAN + return u.i[1]; +#else + return u.i[0]; +#endif +} + +#else +# error Please define a magic number for your fixed point type! +# error See cairo-fixed-private.h for details. +#endif + +static inline cairo_fixed_t +_cairo_fixed_from_26_6 (uint32_t i) +{ +#if CAIRO_FIXED_FRAC_BITS > 6 + return i << (CAIRO_FIXED_FRAC_BITS - 6); +#else + return i >> (6 - CAIRO_FIXED_FRAC_BITS); +#endif +} + +static inline cairo_fixed_t +_cairo_fixed_from_16_16 (uint32_t i) +{ +#if CAIRO_FIXED_FRAC_BITS > 16 + return i << (CAIRO_FIXED_FRAC_BITS - 16); +#else + return i >> (16 - CAIRO_FIXED_FRAC_BITS); +#endif +} + +static inline double +_cairo_fixed_to_double (cairo_fixed_t f) +{ + return ((double) f) / CAIRO_FIXED_ONE_DOUBLE; +} + +static inline int +_cairo_fixed_is_integer (cairo_fixed_t f) +{ + return (f & CAIRO_FIXED_FRAC_MASK) == 0; +} + +static inline cairo_fixed_t +_cairo_fixed_floor (cairo_fixed_t f) +{ + return f & ~CAIRO_FIXED_FRAC_MASK; +} + +static inline cairo_fixed_t +_cairo_fixed_ceil (cairo_fixed_t f) +{ + return _cairo_fixed_floor (f + CAIRO_FIXED_FRAC_MASK); +} + +static inline cairo_fixed_t +_cairo_fixed_round (cairo_fixed_t f) +{ + return _cairo_fixed_floor (f + (CAIRO_FIXED_FRAC_MASK+1)/2); +} + +static inline cairo_fixed_t +_cairo_fixed_round_down (cairo_fixed_t f) +{ + return _cairo_fixed_floor (f + CAIRO_FIXED_FRAC_MASK/2); +} + +static inline int +_cairo_fixed_integer_part (cairo_fixed_t f) +{ + return f >> CAIRO_FIXED_FRAC_BITS; +} + +static inline int +_cairo_fixed_integer_round (cairo_fixed_t f) +{ + return _cairo_fixed_integer_part (f + (CAIRO_FIXED_FRAC_MASK+1)/2); +} + +static inline int +_cairo_fixed_integer_round_down (cairo_fixed_t f) +{ + return _cairo_fixed_integer_part (f + CAIRO_FIXED_FRAC_MASK/2); +} + +static inline int +_cairo_fixed_fractional_part (cairo_fixed_t f) +{ + return f & CAIRO_FIXED_FRAC_MASK; +} + +static inline int +_cairo_fixed_integer_floor (cairo_fixed_t f) +{ + if (f >= 0) + return f >> CAIRO_FIXED_FRAC_BITS; + else + return -((-f - 1) >> CAIRO_FIXED_FRAC_BITS) - 1; +} + +static inline int +_cairo_fixed_integer_ceil (cairo_fixed_t f) +{ + if (f > 0) + return ((f - 1)>>CAIRO_FIXED_FRAC_BITS) + 1; + else + return - (-f >> CAIRO_FIXED_FRAC_BITS); +} + +/* A bunch of explicit 16.16 operators; we need these + * to interface with pixman and other backends that require + * 16.16 fixed point types. + */ +static inline cairo_fixed_16_16_t +_cairo_fixed_to_16_16 (cairo_fixed_t f) +{ +#if (CAIRO_FIXED_FRAC_BITS == 16) && (CAIRO_FIXED_BITS == 32) + return f; +#elif CAIRO_FIXED_FRAC_BITS > 16 + /* We're just dropping the low bits, so we won't ever got over/underflow here */ + return f >> (CAIRO_FIXED_FRAC_BITS - 16); +#else + cairo_fixed_16_16_t x; + + /* Handle overflow/underflow by clamping to the lowest/highest + * value representable as 16.16 + */ + if ((f >> CAIRO_FIXED_FRAC_BITS) < INT16_MIN) { + x = INT32_MIN; + } else if ((f >> CAIRO_FIXED_FRAC_BITS) > INT16_MAX) { + x = INT32_MAX; + } else { + x = f << (16 - CAIRO_FIXED_FRAC_BITS); + } + + return x; +#endif +} + +static inline cairo_fixed_16_16_t +_cairo_fixed_16_16_from_double (double d) +{ + union { + double d; + int32_t i[2]; + } u; + + u.d = d + CAIRO_MAGIC_NUMBER_FIXED_16_16; +#ifdef FLOAT_WORDS_BIGENDIAN + return u.i[1]; +#else + return u.i[0]; +#endif +} + +static inline int +_cairo_fixed_16_16_floor (cairo_fixed_16_16_t f) +{ + if (f >= 0) + return f >> 16; + else + return -((-f - 1) >> 16) - 1; +} + +static inline double +_cairo_fixed_16_16_to_double (cairo_fixed_16_16_t f) +{ + return ((double) f) / (double) (1 << 16); +} + +#if CAIRO_FIXED_BITS == 32 + +static inline cairo_fixed_t +_cairo_fixed_mul (cairo_fixed_t a, cairo_fixed_t b) +{ + cairo_int64_t temp = _cairo_int32x32_64_mul (a, b); + return _cairo_int64_to_int32(_cairo_int64_rsl (temp, CAIRO_FIXED_FRAC_BITS)); +} + +/* computes round (a * b / c) */ +static inline cairo_fixed_t +_cairo_fixed_mul_div (cairo_fixed_t a, cairo_fixed_t b, cairo_fixed_t c) +{ + cairo_int64_t ab = _cairo_int32x32_64_mul (a, b); + cairo_int64_t c64 = _cairo_int32_to_int64 (c); + return _cairo_int64_to_int32 (_cairo_int64_divrem (ab, c64).quo); +} + +/* computes floor (a * b / c) */ +static inline cairo_fixed_t +_cairo_fixed_mul_div_floor (cairo_fixed_t a, cairo_fixed_t b, cairo_fixed_t c) +{ + return _cairo_int64_32_div (_cairo_int32x32_64_mul (a, b), c); +} + +/* compute y from x so that (x,y), p1, and p2 are collinear */ +static inline cairo_fixed_t +_cairo_edge_compute_intersection_y_for_x (const cairo_point_t *p1, + const cairo_point_t *p2, + cairo_fixed_t x) +{ + cairo_fixed_t y, dx; + + if (x == p1->x) + return p1->y; + if (x == p2->x) + return p2->y; + + y = p1->y; + dx = p2->x - p1->x; + if (dx != 0) + y += _cairo_fixed_mul_div_floor (x - p1->x, p2->y - p1->y, dx); + + return y; +} + +/* compute x from y so that (x,y), p1, and p2 are collinear */ +static inline cairo_fixed_t +_cairo_edge_compute_intersection_x_for_y (const cairo_point_t *p1, + const cairo_point_t *p2, + cairo_fixed_t y) +{ + cairo_fixed_t x, dy; + + if (y == p1->y) + return p1->x; + if (y == p2->y) + return p2->x; + + x = p1->x; + dy = p2->y - p1->y; + if (dy != 0) + x += _cairo_fixed_mul_div_floor (y - p1->y, p2->x - p1->x, dy); + + return x; +} + +/* Intersect two segments based on the algorithm described at + * http://paulbourke.net/geometry/pointlineplane/. This implementation + * uses floating point math. */ +static inline cairo_bool_t +_slow_segment_intersection (const cairo_point_t *seg1_p1, + const cairo_point_t *seg1_p2, + const cairo_point_t *seg2_p1, + const cairo_point_t *seg2_p2, + cairo_point_t *intersection) +{ + double denominator, u_a, u_b; + double seg1_dx, seg1_dy, seg2_dx, seg2_dy, seg_start_dx, seg_start_dy; + + seg1_dx = _cairo_fixed_to_double (seg1_p2->x - seg1_p1->x); + seg1_dy = _cairo_fixed_to_double (seg1_p2->y - seg1_p1->y); + seg2_dx = _cairo_fixed_to_double (seg2_p2->x - seg2_p1->x); + seg2_dy = _cairo_fixed_to_double (seg2_p2->y - seg2_p1->y); + denominator = (seg2_dy * seg1_dx) - (seg2_dx * seg1_dy); + if (denominator == 0) + return FALSE; + + seg_start_dx = _cairo_fixed_to_double (seg1_p1->x - seg2_p1->x); + seg_start_dy = _cairo_fixed_to_double (seg1_p1->y - seg2_p1->y); + u_a = ((seg2_dx * seg_start_dy) - (seg2_dy * seg_start_dx)) / denominator; + u_b = ((seg1_dx * seg_start_dy) - (seg1_dy * seg_start_dx)) / denominator; + + if (u_a <= 0 || u_a >= 1 || u_b <= 0 || u_b >= 1) + return FALSE; + + intersection->x = seg1_p1->x + _cairo_fixed_from_double ((u_a * seg1_dx)); + intersection->y = seg1_p1->y + _cairo_fixed_from_double ((u_a * seg1_dy)); + return TRUE; +} + +#else +# error Please define multiplication and other operands for your fixed-point type size +#endif + +#endif /* CAIRO_FIXED_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-fixed-type-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-fixed-type-private.h new file mode 100644 index 00000000000..e9f26f61539 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-fixed-type-private.h @@ -0,0 +1,75 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#ifndef CAIRO_FIXED_TYPE_PRIVATE_H +#define CAIRO_FIXED_TYPE_PRIVATE_H + +#include "cairo-wideint-type-private.h" + +/* + * Fixed-point configuration + */ + +typedef int32_t cairo_fixed_16_16_t; +typedef cairo_int64_t cairo_fixed_32_32_t; +typedef cairo_int64_t cairo_fixed_48_16_t; +typedef cairo_int128_t cairo_fixed_64_64_t; +typedef cairo_int128_t cairo_fixed_96_32_t; + +/* Eventually, we should allow changing this, but I think + * there are some assumptions in the tessellator about the + * size of a fixed type. For now, it must be 32. + */ +#define CAIRO_FIXED_BITS 32 + +/* The number of fractional bits. Changing this involves + * making sure that you compute a double-to-fixed magic number. + * (see below). + */ +#define CAIRO_FIXED_FRAC_BITS 8 + +/* A signed type %CAIRO_FIXED_BITS in size; the main fixed point type */ +typedef int32_t cairo_fixed_t; + +/* An unsigned type of the same size as #cairo_fixed_t */ +typedef uint32_t cairo_fixed_unsigned_t; + +typedef struct _cairo_point { + cairo_fixed_t x; + cairo_fixed_t y; +} cairo_point_t; + +#endif /* CAIRO_FIXED_TYPE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-fixed.c b/Build/source/libs/cairo/cairo-src/src/cairo-fixed.c new file mode 100644 index 00000000000..03e05592354 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-fixed.c @@ -0,0 +1,39 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-fixed-private.h" diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin-data.c b/Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin-data.c new file mode 100644 index 00000000000..ff09cb2be10 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin-data.c @@ -0,0 +1,1072 @@ +/* See cairo-font-face-twin.c for copyright info */ + +#include "cairoint.h" + +const int8_t _cairo_twin_outlines[] = { +/* 0x0 '\0' offset 0 */ + 0, 24, 42, 0, 2, 2, + 0, 24, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 24, -42, + 'l', 24, 0, + 'l', 0, 0, + 'e', + 'X', 'X', +/* 0x20 ' ' offset 28 */ + 0, 4, 0, 0, 0, 0, + /* snap_x */ + /* snap_y */ + 'e', + 'X', 'X', 'X', + 'X', 'X', +/* 0x21 '!' offset 40 */ + 0, 0, 42, 0, 1, 3, + 0, /* snap_x */ + -42, -14, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, -14, + 'm', 0, 0, + 'l', 0, 0, + 'e', + 'X', 'X', 'X', 'X', 'X', 'X', + 'X', 'X', 'X', 'X', 'X', 'X', + 'X', 'X', 'X', 'X', 'X', 'X', + 'X', 'X', 'X', 'X', 'X', 'X', + 'X', 'X', 'X', +/* 0x22 '"' offset 90 */ + 0, 16, 42, -28, 2, 2, + 0, 16, /* snap_x */ + -42, -28, /* snap_y */ + 'm', 0, -42, + 'l', 0, -28, + 'm', 16, -42, + 'l', 16, -28, + 'e', + 'X', +/* 0x23 '#' offset 114 */ + 0, 30, 50, 14, 2, 5, + 0, 30, /* snap_x */ + -24, -21, -15, -12, 0, /* snap_y */ + 'm', 16, -50, + 'l', 2, 14, + 'm', 28, -50, + 'l', 14, 14, + 'm', 2, -24, + 'l', 30, -24, + 'm', 0, -12, + 'l', 28, -12, + 'e', +/* 0x24 '$' offset 152 */ + 0, 28, 50, 8, 4, 4, + 0, 10, 18, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 10, -50, + 'l', 10, 8, + 'm', 18, -50, + 'l', 18, 8, + 'm', 28, -36, + 'c', 24, -42, 18, -42, 14, -42, + 'c', 10, -42, 0, -42, 0, -34, + 'c', 0, -25, 8, -24, 14, -22, + 'c', 20, -20, 28, -19, 28, -9, + 'c', 28, 0, 18, 0, 14, 0, + 'c', 10, 0, 4, 0, 0, -6, + 'e', +/* 0x25 '%' offset 224 */ + 0, 36, 42, 0, 4, 7, + 0, 14, 22, 36, /* snap_x */ + -42, -38, -28, -21, -15, -14, 0, /* snap_y */ + 'm', 10, -42, + 'c', 12, -41, 14, -40, 14, -36, + 'c', 14, -30, 11, -28, 6, -28, + 'c', 2, -28, 0, -30, 0, -34, + 'c', 0, -39, 3, -42, 8, -42, + 'l', 10, -42, + 'c', 18, -37, 28, -37, 36, -42, + 'l', 0, 0, + 'm', 28, -14, + 'c', 24, -14, 22, -11, 22, -6, + 'c', 22, -2, 24, 0, 28, 0, + 'c', 33, 0, 36, -2, 36, -8, + 'c', 36, -12, 34, -14, 30, -14, + 'l', 28, -14, + 'e', + 'X', 'X', 'X', +/* 0x26 '&' offset 323 */ + 0, 40, 42, 0, 4, 4, + 0, 10, 22, 40, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 40, -24, + 'c', 40, -27, 39, -28, 37, -28, + 'c', 29, -28, 32, 0, 12, 0, + 'c', 0, 0, 0, -8, 0, -10, + 'c', 0, -24, 22, -20, 22, -34, + 'c', 22, -45, 10, -45, 10, -34, + 'c', 10, -27, 25, 0, 36, 0, + 'c', 39, 0, 40, -1, 40, -4, + 'e', +/* 0x27 ''' offset 390 */ + 0, 4, 42, -30, 2, 2, + 0, 4, /* snap_x */ + -42, -28, /* snap_y */ + 'm', 2, -38, + 'c', -1, -38, -1, -42, 2, -42, + 'c', 6, -42, 5, -33, 0, -30, + 'e', + 'X', +/* 0x28 '(' offset 419 */ + 0, 14, 50, 14, 2, 2, + 0, 14, /* snap_x */ + -50, 14, /* snap_y */ + 'm', 14, -50, + 'c', -5, -32, -5, -5, 14, 14, + 'e', + 'X', +/* 0x29 ')' offset 441 */ + 0, 14, 50, 14, 2, 2, + 0, 14, /* snap_x */ + -15, 14, /* snap_y */ + 'm', 0, -50, + 'c', 19, -34, 19, -2, 0, 14, + 'e', + 'X', +/* 0x2a '*' offset 463 */ + 0, 20, 30, -6, 3, 3, + 0, 10, 20, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 10, -30, + 'l', 10, -6, + 'm', 0, -24, + 'l', 20, -12, + 'm', 20, -24, + 'l', 0, -12, + 'e', +/* 0x2b '+' offset 494 */ + 0, 36, 36, 0, 3, 4, + 0, 18, 36, /* snap_x */ + -21, -18, -15, 0, /* snap_y */ + 'm', 18, -36, + 'l', 18, 0, + 'm', 0, -18, + 'l', 36, -18, + 'e', +/* 0x2c ',' offset 520 */ + 0, 4, 4, 8, 2, 3, + 0, 4, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 4, -2, + 'c', 4, 1, 0, 1, 0, -2, + 'c', 0, -5, 4, -5, 4, -2, + 'c', 4, 4, 2, 6, 0, 8, + 'e', +/* 0x2d '-' offset 556 */ + 0, 36, 18, -18, 2, 4, + 0, 36, /* snap_x */ + -21, -18, -15, 0, /* snap_y */ + 'm', 0, -18, + 'l', 36, -18, + 'e', +/* 0x2e '.' offset 575 */ + 0, 4, 4, 0, 2, 3, + 0, 4, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 2, -4, + 'c', -1, -4, -1, 0, 2, 0, + 'c', 5, 0, 5, -4, 2, -4, + 'e', +/* 0x2f '/' offset 604 */ + 0, 36, 50, 14, 2, 3, + 0, 36, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 36, -50, + 'l', 0, 14, + 'e', +/* 0x30 '0' offset 622 */ + 0, 28, 42, 0, 2, 4, + 0, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 14, -42, + 'c', 9, -42, 0, -42, 0, -21, + 'c', 0, 0, 9, 0, 14, 0, + 'c', 19, 0, 28, 0, 28, -21, + 'c', 28, -42, 19, -42, 14, -42, + 'E', +/* 0x31 '1' offset 666 */ + 0, 28, 42, 0, 2, 3, + 0, 17, 28 /* snap_x */ + -42, -34, 0, /* snap_y */ + 'm', 7, -34, + 'c', 11, -35, 15, -38, 17, -42, + 'l', 17, 0, + 'e', +/* 0x32 '2' offset 691 */ + 0, 28, 42, 0, 4, 4, + 0, 2, 26, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 2, -32, + 'c', 2, -34, 2, -42, 14, -42, + 'c', 26, -42, 26, -34, 26, -32, + 'c', 26, -30, 25, -25, 10, -10, + 'l', 0, 0, + 'l', 28, 0, + 'e', +/* 0x33 '3' offset 736 */ + 0, 28, 42, 0, 2, 5, + 0, 28, /* snap_x */ + -42, -26, -21, -15, 0, /* snap_y */ + 'm', 4, -42, + 'l', 26, -42, + 'l', 14, -26, + 'c', 21, -26, 28, -26, 28, -14, + 'c', 28, 0, 17, 0, 13, 0, + 'c', 8, 0, 3, -1, 0, -8, + 'e', +/* 0x34 '4' offset 780 */ + 0, 28, 42, 0, 3, 3, + 0, 20, 30, /* snap_x */ + -42, -14, 0, /* snap_y */ + 'm', 20, 0, + 'l', 20, -42, + 'l', 0, -14, + 'l', 30, -14, + 'e', + 'X', 'X', 'X', + 'X', +/* 0x35 '5' offset 809 */ + 0, 28, 42, 0, 2, 5, + 0, 28, /* snap_x */ + -42, -28, -21, -15, 0, /* snap_y */ + 'm', 24, -42, + 'l', 4, -42, + 'l', 2, -24, + 'c', 5, -27, 10, -28, 13, -28, + 'c', 16, -28, 28, -28, 28, -14, + 'c', 28, 0, 16, 0, 13, 0, + 'c', 10, 0, 3, 0, 0, -8, + 'e', +/* 0x36 '6' offset 860 */ + 0, 28, 42, 0, 2, 5, + 0, 26, /* snap_x */ + -42, -26, -21, -15, 0, /* snap_y */ + 'm', 24, -36, + 'c', 22, -41, 19, -42, 14, -42, + 'c', 9, -42, 0, -41, 0, -19, + 'c', 0, -1, 9, 0, 13, 0, + 'c', 18, 0, 26, -3, 26, -13, + 'c', 26, -18, 23, -26, 13, -26, + 'c', 10, -26, 1, -24, 0, -14, + 'e', +/* 0x37 '7' offset 919 */ + 0, 28, 42, 0, 2, 4, + 0, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 0, -42, + 'l', 28, -42, + 'l', 8, 0, + 'e', + 'X', 'X', 'X', +/* 0x38 '8' offset 944 */ + 0, 28, 42, 0, 4, 4, + 0, 2, 26, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 14, -42, + 'c', 5, -42, 2, -40, 2, -34, + 'c', 2, -18, 28, -32, 28, -11, + 'c', 28, 0, 18, 0, 14, 0, + 'c', 10, 0, 0, 0, 0, -11, + 'c', 0, -32, 26, -18, 26, -34, + 'c', 26, -40, 23, -42, 14, -42, + 'E', +/* 0x39 '9' offset 1004 */ + 0, 28, 42, 0, 2, 5, + 0, 26, /* snap_x */ + -42, -21, -16, -15, 0, /* snap_y */ + 'm', 26, -28, + 'c', 25, -16, 13, -16, 13, -16, + 'c', 8, -16, 0, -19, 0, -29, + 'c', 0, -34, 3, -42, 13, -42, + 'c', 24, -42, 26, -32, 26, -23, + 'c', 26, -14, 24, 0, 12, 0, + 'c', 7, 0, 4, -2, 2, -6, + 'e', +/* 0x3a ':' offset 1063 */ + 0, 4, 28, 0, 2, 3, + 0, 4, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 2, -28, + 'c', -1, -28, -1, -24, 2, -24, + 'c', 5, -24, 5, -28, 2, -28, + 'm', 2, -4, + 'c', -1, -4, -1, 0, 2, 0, + 'c', 5, 0, 5, -4, 2, -4, + 'e', +/* 0x3b ';' offset 1109 */ + 0, 4, 28, 8, 2, 3, + 0, 4, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 2, -28, + 'c', -1, -28, -1, -24, 2, -24, + 'c', 5, -24, 5, -28, 2, -28, + 'm', 4, -2, + 'c', 4, 1, 0, 1, 0, -2, + 'c', 0, -5, 4, -5, 4, -2, + 'c', 4, 3, 2, 6, 0, 8, + 'e', +/* 0x3c '<' offset 1162 */ + 0, 32, 36, 0, 2, 3, + 0, 32, /* snap_x */ + -36, -18, 0, /* snap_y */ + 'm', 32, -36, + 'l', 0, -18, + 'l', 32, 0, + 'e', +/* 0x3d '=' offset 1183 */ + 0, 36, 24, -12, 2, 2, + 0, 36, /* snap_x */ + -24, -15, /* snap_y */ + 'm', 0, -24, + 'l', 36, -24, + 'm', 0, -12, + 'l', 36, -12, + 'e', + 'X', 'X', 'X', +/* 0x3e '>' offset 1209 */ + 0, 32, 36, 0, 2, 3, + 0, 32, /* snap_x */ + -36, -18, 0, /* snap_y */ + 'm', 0, -36, + 'l', 32, -18, + 'l', 0, 0, + 'e', +/* 0x3f '?' offset 1230 */ + 0, 24, 42, 0, 3, 4, + 0, 12, 24, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 0, -32, + 'c', 0, -34, 0, -42, 12, -42, + 'c', 24, -42, 24, -34, 24, -32, + 'c', 24, -29, 24, -24, 12, -20, + 'l', 12, -14, + 'm', 12, 0, + 'l', 12, 0, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', +/* 0x40 '@' offset 1288 */ + 0, 42, 42, 0, 1, 6, + 30, /* snap_x */ + -42, -32, -21, -15, -10, 0, /* snap_y */ + 'm', 30, -26, + 'c', 28, -31, 24, -32, 21, -32, + 'c', 10, -32, 10, -23, 10, -19, + 'c', 10, -13, 11, -10, 19, -10, + 'c', 30, -10, 28, -21, 30, -32, + 'c', 27, -10, 30, -10, 34, -10, + 'c', 41, -10, 42, -19, 42, -22, + 'c', 42, -34, 34, -42, 21, -42, + 'c', 9, -42, 0, -34, 0, -21, + 'c', 0, -9, 8, 0, 21, 0, + 'c', 30, 0, 34, -3, 36, -6, + 'e', +/* 0x41 'A' offset 1375 */ + 0, 32, 42, 0, 2, 3, + 0, 32, /* snap_x */ + -42, -14, 0, /* snap_y */ + 'm', 0, 0, + 'l', 16, -42, + 'l', 32, 0, + 'm', 6, -14, + 'l', 26, -14, + 'e', + 'X', 'X', 'X', + 'X', +/* 0x42 'B' offset 1406 */ + 0, 28, 42, 0, 2, 3, + 0, 28, /* snap_x */ + -42, -22, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 18, -42, + 'c', 32, -42, 32, -22, 18, -22, + 'l', 0, -22, + 'l', 18, -22, + 'c', 32, -22, 32, 0, 18, 0, + 'E', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', +/* 0x43 'C' offset 1455 */ + 0, 30, 42, 0, 2, 4, + 0, 30, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 30, -32, + 'c', 26, -42, 21, -42, 16, -42, + 'c', 2, -42, 0, -29, 0, -21, + 'c', 0, -13, 2, 0, 16, 0, + 'c', 21, 0, 26, 0, 30, -10, + 'e', +/* 0x44 'D' offset 1499 */ + 0, 28, 42, 0, 2, 2, + 0, 28, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 14, -42, + 'c', 33, -42, 33, 0, 14, 0, + 'E', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', +/* 0x45 'E' offset 1534 */ + 0, 26, 42, 0, 2, 3, + 0, 26, /* snap_x */ + -42, -22, 0, /* snap_y */ + 'm', 26, -42, + 'l', 0, -42, + 'l', 0, 0, + 'l', 26, 0, + 'm', 0, -22, + 'l', 16, -22, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', +/* 0x46 'F' offset 1572 */ + 0, 26, 42, 0, 2, 3, + 0, 26, /* snap_x */ + -42, -22, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 26, -42, + 'm', 0, -22, + 'l', 16, -22, + 'e', + 'X', 'X', 'X', + 'X', 'X', +/* 0x47 'G' offset 1604 */ + 0, 30, 42, 0, 2, 5, + 0, 30, /* snap_x */ + -42, -21, -16, -15, 0, /* snap_y */ + 'm', 30, -32, + 'c', 26, -42, 21, -42, 16, -42, + 'c', 2, -42, 0, -29, 0, -21, + 'c', 0, -13, 2, 0, 16, 0, + 'c', 28, 0, 30, -7, 30, -16, + 'l', 20, -16, + 'e', + 'X', 'X', 'X', +/* 0x48 'H' offset 1655 */ + 0, 28, 42, 0, 2, 3, + 0, 28, /* snap_x */ + -42, -22, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'm', 28, -42, + 'l', 28, 0, + 'm', 0, -22, + 'l', 28, -22, + 'e', + 'X', +/* 0x49 'I' offset 1686 */ + 0, 0, 42, 0, 1, 2, + 0, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'e', + 'X', +/* 0x4a 'J' offset 1703 */ + 0, 20, 42, 0, 2, 3, + 0, 20, /* snap_x */ + -42, -15, 0, /* snap_y */ + 'm', 20, -42, + 'l', 20, -10, + 'c', 20, 3, 0, 3, 0, -10, + 'l', 0, -14, + 'e', +/* 0x4b 'K' offset 1731 */ + 0, 28, 42, 0, 2, 3, + 0, 28, /* snap_x */ + -42, -15, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'm', 28, -42, + 'l', 0, -14, + 'm', 10, -24, + 'l', 28, 0, + 'e', +/* 0x4c 'L' offset 1761 */ + 0, 24, 42, 0, 2, 2, + 0, 24, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'l', 24, 0, + 'e', + 'X', 'X', 'X', + 'X', +/* 0x4d 'M' offset 1785 */ + 0, 32, 42, 0, 2, 2, + 0, 32, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 16, 0, + 'l', 32, -42, + 'l', 32, 0, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', +/* 0x4e 'N' offset 1821 */ + 0, 28, 42, 0, 2, 2, + 0, 28, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 28, 0, + 'l', 28, -42, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', +/* 0x4f 'O' offset 1851 */ + 0, 32, 42, 0, 2, 4, + 0, 32, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 16, -42, + 'c', 2, -42, 0, -29, 0, -21, + 'c', 0, -13, 2, 0, 16, 0, + 'c', 30, 0, 32, -13, 32, -21, + 'c', 32, -29, 30, -42, 16, -42, + 'E', +/* 0x50 'P' offset 1895 */ + 0, 28, 42, 0, 2, 5, + 0, 28, /* snap_x */ + -42, -21, -20, -15, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 18, -42, + 'c', 32, -42, 32, -20, 18, -20, + 'l', 0, -20, + 'e', + 'X', 'X', 'X', +/* 0x51 'Q' offset 1931 */ + 0, 32, 42, 4, 2, 4, + 0, 32, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 16, -42, + 'c', 2, -42, 0, -29, 0, -21, + 'c', 0, -13, 2, 0, 16, 0, + 'c', 30, 0, 32, -13, 32, -21, + 'c', 32, -29, 30, -42, 16, -42, + 'M', 18, -8, + 'l', 30, 4, + 'e', +/* 0x52 'R' offset 1981 */ + 0, 28, 42, 0, 2, 5, + 0, 28, /* snap_x */ + -42, -22, -21, -15, 0, /* snap_y */ + 'm', 0, 0, + 'l', 0, -42, + 'l', 18, -42, + 'c', 32, -42, 31, -22, 18, -22, + 'l', 0, -22, + 'm', 14, -22, + 'l', 28, 0, + 'e', + 'X', 'X', 'X', +/* 0x53 'S' offset 2023 */ + 0, 28, 42, 0, 2, 4, + 0, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 28, -36, + 'c', 25, -41, 21, -42, 14, -42, + 'c', 10, -42, 0, -42, 0, -34, + 'c', 0, -17, 28, -28, 28, -9, + 'c', 28, 0, 19, 0, 14, 0, + 'c', 7, 0, 3, -1, 0, -6, + 'e', +/* 0x54 'T' offset 2074 */ + 0, 28, 42, 0, 3, 4, + 0, 14, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 14, -42, + 'l', 14, 0, + 'm', 0, -42, + 'l', 28, -42, + 'e', +/* 0x55 'U' offset 2100 */ + 0, 28, 42, 0, 2, 2, + 0, 28, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, -12, + 'c', 0, 4, 28, 4, 28, -12, + 'l', 28, -42, + 'e', + 'X', +/* 0x56 'V' offset 2128 */ + 0, 32, 42, 0, 2, 2, + 0, 32, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 16, 0, + 'l', 32, -42, + 'e', + 'X', 'X', 'X', + 'X', +/* 0x57 'W' offset 2152 */ + 0, 40, 42, 0, 2, 2, + 0, 40, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 10, 0, + 'l', 20, -42, + 'l', 30, 0, + 'l', 40, -42, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', +/* 0x58 'X' offset 2188 */ + 0, 28, 42, 0, 2, 2, + 0, 28, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 28, 0, + 'm', 28, -42, + 'l', 0, 0, + 'e', + 'X', +/* 0x59 'Y' offset 2212 */ + 0, 32, 42, 0, 3, 3, + 0, 16, 32, /* snap_x */ + -42, -21, 0, /* snap_y */ + 'm', 0, -42, + 'l', 16, -22, + 'l', 16, 0, + 'm', 32, -42, + 'l', 16, -22, + 'e', +/* 0x5a 'Z' offset 2240 */ + 0, 28, 42, 0, 2, 4, + 0, 28, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 28, 0, + 'l', 0, 0, + 'l', 28, -42, + 'l', 0, -42, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', +/* 0x5b '[' offset 2271 */ + 0, 14, 44, 0, 2, 4, + 0, 14, /* snap_x */ + -44, -21, -15, 0, /* snap_y */ + 'm', 14, -44, + 'l', 0, -44, + 'l', 0, 0, + 'l', 14, 0, + 'e', +/* 0x5c '\' offset 2296 */ + 0, 36, 50, 14, 2, 3, + 0, 36, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 0, -50, + 'l', 36, 14, + 'e', +/* 0x5d ']' offset 2314 */ + 0, 14, 44, 0, 2, 4, + 0, 14, /* snap_x */ + -44, -21, -15, 0, /* snap_y */ + 'm', 0, -44, + 'l', 14, -44, + 'l', 14, 0, + 'l', 0, 0, + 'e', +/* 0x5e '^' offset 2339 */ + 0, 32, 46, -18, 2, 3, + 0, 32, /* snap_x */ + -21, -15, 0, /* snap_y */ + 'm', 0, -18, + 'l', 16, -46, + 'l', 32, -18, + 'e', + 'X', 'X', 'X', +/* 0x5f '_' offset 2363 */ + 0, 36, 0, 0, 2, 1, + 0, 36, /* snap_x */ + 0, /* snap_y */ + 'm', 0, 0, + 'l', 36, 0, + 'e', + 'X', 'X', +/* 0x60 '`' offset 2381 */ + 0, 4, 42, -30, 2, 2, + 0, 4, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 4, -42, + 'c', 2, -40, 0, -39, 0, -32, + 'c', 0, -31, 1, -30, 2, -30, + 'c', 5, -30, 5, -34, 2, -34, + 'e', + 'X', +/* 0x61 'a' offset 2417 */ + 0, 24, 28, 0, 2, 4, + 0, 24, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 24, -28, + 'l', 24, 0, + 'm', 24, -22, + 'c', 21, -27, 18, -28, 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 18, 0, 21, -1, 24, -6, + 'e', +/* 0x62 'b' offset 2467 */ + 0, 24, 42, 0, 2, 4, + 0, 24, /* snap_x */ + -42, -28, -15, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'm', 0, -22, + 'c', 3, -26, 6, -28, 11, -28, + 'c', 22, -28, 24, -19, 24, -14, + 'c', 24, -9, 22, 0, 11, 0, + 'c', 6, 0, 3, -2, 0, -6, + 'e', +/* 0x63 'c' offset 2517 */ + 0, 24, 28, 0, 2, 4, + 0, 24, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 24, -22, + 'c', 21, -26, 18, -28, 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 18, 0, 21, -2, 24, -6, + 'e', +/* 0x64 'd' offset 2561 */ + 0, 24, 42, 0, 2, 4, + 0, 24, /* snap_x */ + -42, -28, -15, 0, /* snap_y */ + 'm', 24, -42, + 'l', 24, 0, + 'm', 24, -22, + 'c', 21, -26, 18, -28, 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 18, 0, 21, -2, 24, -6, + 'e', +/* 0x65 'e' offset 2611 */ + 0, 24, 28, 0, 2, 5, + 0, 24, /* snap_x */ + -28, -21, -16, -15, 0, /* snap_y */ + 'm', 0, -16, + 'l', 24, -16, + 'c', 24, -20, 24, -28, 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 18, 0, 21, -2, 24, -6, + 'e', +/* 0x66 'f' offset 2659 */ + 0, 16, 42, 0, 3, 5, + 0, 6, 16, /* snap_x */ + -42, -28, -21, -15, 0, /* snap_y */ + 'm', 16, -42, + 'c', 8, -42, 6, -40, 6, -34, + 'l', 6, 0, + 'm', 0, -28, + 'l', 14, -28, + 'e', +/* 0x67 'g' offset 2693 */ + 0, 24, 28, 14, 2, 5, + 0, 24, /* snap_x */ + -28, -21, -15, 0, 14, /* snap_y */ + 'm', 24, -28, + 'l', 24, 4, + 'c', 23, 14, 16, 14, 13, 14, + 'c', 10, 14, 8, 14, 6, 12, + 'm', 24, -22, + 'c', 21, -26, 18, -28, 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 18, 0, 21, -2, 24, -6, + 'e', +/* 0x68 'h' offset 2758 */ + 0, 22, 42, 0, 2, 4, + 0, 22, /* snap_x */ + -42, -28, -15, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'm', 0, -20, + 'c', 8, -32, 22, -31, 22, -20, + 'l', 22, 0, + 'e', +/* 0x69 'i' offset 2790 */ + 0, 0, 44, 0, 1, 3, + 0, /* snap_x */ + -42, -28, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, -42, + 'm', 0, -28, + 'l', 0, 0, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', + 'X', 'X', +/* 0x6a 'j' offset 2826 */ + -8, 4, 44, 14, 3, 5, + -8, 2, 4, /* snap_x */ + -42, -21, -15, 0, 14, /* snap_y */ + 'm', 2, -42, + 'l', 2, -42, + 'm', 2, -28, + 'l', 2, 6, + 'c', 2, 13, -1, 14, -8, 14, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', +/* 0x6b 'k' offset 2870 */ + 0, 22, 42, 0, 2, 3, + 0, 22, /* snap_x */ + -42, -28, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'm', 20, -28, + 'l', 0, -8, + 'm', 8, -16, + 'l', 22, 0, + 'e', +/* 0x6c 'l' offset 2900 */ + 0, 0, 42, 0, 1, 2, + 0, /* snap_x */ + -42, 0, /* snap_y */ + 'm', 0, -42, + 'l', 0, 0, + 'e', + 'X', +/* 0x6d 'm' offset 2917 */ + 0, 44, 28, 0, 3, 3, + 0, 22, 44, /* snap_x */ + -28, -21, 0, /* snap_y */ + 'm', 0, -28, + 'l', 0, 0, + 'm', 0, -20, + 'c', 5, -29, 22, -33, 22, -20, + 'l', 22, 0, + 'm', 22, -20, + 'c', 27, -29, 44, -33, 44, -20, + 'l', 44, 0, + 'e', + 'X', +/* 0x6e 'n' offset 2963 */ + 0, 22, 28, 0, 2, 3, + 0, 22, /* snap_x */ + -28, -21, 0, /* snap_y */ + 'm', 0, -28, + 'l', 0, 0, + 'm', 0, -20, + 'c', 4, -28, 22, -34, 22, -20, + 'l', 22, 0, + 'e', + 'X', +/* 0x6f 'o' offset 2995 */ + 0, 26, 28, 0, 2, 4, + 0, 26, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 24, 0, 26, -9, 26, -14, + 'c', 26, -19, 24, -28, 13, -28, + 'E', +/* 0x70 'p' offset 3039 */ + 0, 24, 28, 14, 2, 4, + 0, 24, /* snap_x */ + -28, -21, 0, 14, /* snap_y */ + 'm', 0, -28, + 'l', 0, 14, + 'm', 0, -22, + 'c', 3, -26, 6, -28, 11, -28, + 'c', 22, -28, 24, -19, 24, -14, + 'c', 24, -9, 22, 0, 11, 0, + 'c', 6, 0, 3, -2, 0, -6, + 'e', +/* 0x71 'q' offset 3089 */ + 0, 24, 28, 14, 2, 4, + 0, 24, /* snap_x */ + -28, -21, 0, 14, /* snap_y */ + 'm', 24, -28, + 'l', 24, 14, + 'm', 24, -22, + 'c', 21, -26, 18, -28, 13, -28, + 'c', 2, -28, 0, -19, 0, -14, + 'c', 0, -9, 2, 0, 13, 0, + 'c', 18, 0, 21, -2, 24, -6, + 'e', +/* 0x72 'r' offset 3139 */ + 0, 16, 28, 0, 2, 4, + 0, 16, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 0, -28, + 'l', 0, 0, + 'm', 0, -16, + 'c', 2, -27, 7, -28, 16, -28, + 'e', +/* 0x73 's' offset 3168 */ + 0, 22, 28, 0, 2, 4, + 0, 22, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 22, -22, + 'c', 22, -27, 16, -28, 11, -28, + 'c', 4, -28, 0, -26, 0, -22, + 'c', 0, -11, 22, -20, 22, -7, + 'c', 22, 0, 17, 0, 11, 0, + 'c', 6, 0, 0, -1, 0, -6, + 'e', +/* 0x74 't' offset 3219 */ + 0, 16, 42, 0, 3, 4, + 0, 6, 16, /* snap_x */ + -42, -28, -21, 0, /* snap_y */ + 'm', 6, -42, + 'l', 6, -8, + 'c', 6, -2, 8, 0, 16, 0, + 'm', 0, -28, + 'l', 14, -28, + 'e', +/* 0x75 'u' offset 3252 */ + 0, 22, 28, 0, 2, 3, + 0, 22, /* snap_x */ + -28, -15, 0, /* snap_y */ + 'm', 0, -28, + 'l', 0, -8, + 'c', 0, 6, 18, 0, 22, -8, + 'm', 22, -28, + 'l', 22, 0, + 'e', +/* 0x76 'v' offset 3283 */ + 0, 24, 28, 0, 2, 3, + 0, 24, /* snap_x */ + -28, -15, 0, /* snap_y */ + 'm', 0, -28, + 'l', 12, 0, + 'l', 24, -28, + 'e', + 'X', 'X', 'X', +/* 0x77 'w' offset 3307 */ + 0, 32, 28, 0, 2, 3, + 0, 32, /* snap_x */ + -28, -15, 0, /* snap_y */ + 'm', 0, -28, + 'l', 8, 0, + 'l', 16, -28, + 'l', 24, 0, + 'l', 32, -28, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', + 'X', 'X', 'X', +/* 0x78 'x' offset 3343 */ + 0, 22, 28, 0, 2, 2, + 0, 22, /* snap_x */ + -28, 0, /* snap_y */ + 'm', 0, -28, + 'l', 22, 0, + 'm', 22, -28, + 'l', 0, 0, + 'e', + 'X', +/* 0x79 'y' offset 3367 */ + -2, 24, 28, 14, 2, 4, + 0, 24, /* snap_x */ + -28, -15, 0, 14, /* snap_y */ + 'm', 0, -28, + 'l', 12, 0, + 'm', 24, -28, + 'l', 12, 0, + 'c', 6, 13, 0, 14, -2, 14, + 'e', +/* 0x7a 'z' offset 3399 */ + 0, 22, 28, 0, 2, 4, + 0, 22, /* snap_x */ + -28, -21, -15, 0, /* snap_y */ + 'm', 22, 0, + 'l', 0, 0, + 'l', 22, -28, + 'l', 0, -28, + 'e', + 'X', 'X', 'X', + 'X', 'X', 'X', +/* 0x7b '{' offset 3430 */ + 0, 16, 44, 0, 3, 5, + 0, 6, 16, /* snap_x */ + -44, -24, -21, -15, 0, /* snap_y */ + 'm', 16, -44, + 'c', 10, -44, 6, -42, 6, -36, + 'l', 6, -24, + 'l', 0, -24, + 'l', 6, -24, + 'l', 6, -8, + 'c', 6, -2, 10, 0, 16, 0, + 'e', +/* 0x7c '|' offset 3474 */ + 0, 0, 50, 14, 1, 2, + 0, /* snap_x */ + -50, 14, /* snap_y */ + 'm', 0, -50, + 'l', 0, 14, + 'e', + 'X', +/* 0x7d '}' offset 3491 */ + 0, 16, 44, 0, 3, 5, + 0, 10, 16, /* snap_x */ + -44, -24, -21, -15, 0, /* snap_y */ + 'm', 0, -44, + 'c', 6, -44, 10, -42, 10, -36, + 'l', 10, -24, + 'l', 16, -24, + 'l', 10, -24, + 'l', 10, -8, + 'c', 10, -2, 6, 0, 0, 0, + 'e', +/* 0x7e '~' offset 3535 */ + 0, 36, 24, -12, 2, 5, + 0, 36, /* snap_x */ + -24, -21, -15, -12, 0, /* snap_y */ + 'm', 0, -14, + 'c', 1, -21, 4, -24, 8, -24, + 'c', 18, -24, 18, -12, 28, -12, + 'c', 32, -12, 35, -15, 36, -22, + 'e', +}; + +const uint16_t _cairo_twin_charmap[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 28, 40, 90, 114, 152, 224, 323, 390, + 419, 441, 463, 494, 520, 556, 575, 604, + 622, 666, 691, 736, 780, 809, 860, 919, + 944, 1004, 1063, 1109, 1162, 1183, 1209, 1230, + 1288, 1375, 1406, 1455, 1499, 1534, 1572, 1604, + 1655, 1686, 1703, 1731, 1761, 1785, 1821, 1851, + 1895, 1931, 1981, 2023, 2074, 2100, 2128, 2152, + 2188, 2212, 2240, 2271, 2296, 2314, 2339, 2363, + 2381, 2417, 2467, 2517, 2561, 2611, 2659, 2693, + 2758, 2790, 2826, 2870, 2900, 2917, 2963, 2995, + 3039, 3089, 3139, 3168, 3219, 3252, 3283, 3307, + 3343, 3367, 3399, 3430, 3474, 3491, 3535, 0, +}; + diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin.c b/Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin.c new file mode 100644 index 00000000000..2ad26302849 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-font-face-twin.c @@ -0,0 +1,752 @@ +/* + * Copyright © 2004 Keith Packard + * Copyright © 2008 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith Packard + * Behdad Esfahbod + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +#include + +/* + * This file implements a user-font rendering the descendant of the Hershey + * font coded by Keith Packard for use in the Twin window system. + * The actual font data is in cairo-font-face-twin-data.c + * + * Ported to cairo user font and extended by Behdad Esfahbod. + */ + + + +static cairo_user_data_key_t twin_properties_key; + + +/* + * Face properties + */ + +/* We synthesize multiple faces from the twin data. Here is the parameters. */ + +/* The following tables and matching code are copied from Pango */ + +/* CSS weight */ +typedef enum { + TWIN_WEIGHT_THIN = 100, + TWIN_WEIGHT_ULTRALIGHT = 200, + TWIN_WEIGHT_LIGHT = 300, + TWIN_WEIGHT_BOOK = 380, + TWIN_WEIGHT_NORMAL = 400, + TWIN_WEIGHT_MEDIUM = 500, + TWIN_WEIGHT_SEMIBOLD = 600, + TWIN_WEIGHT_BOLD = 700, + TWIN_WEIGHT_ULTRABOLD = 800, + TWIN_WEIGHT_HEAVY = 900, + TWIN_WEIGHT_ULTRAHEAVY = 1000 +} twin_face_weight_t; + +/* CSS stretch */ +typedef enum { + TWIN_STRETCH_ULTRA_CONDENSED, + TWIN_STRETCH_EXTRA_CONDENSED, + TWIN_STRETCH_CONDENSED, + TWIN_STRETCH_SEMI_CONDENSED, + TWIN_STRETCH_NORMAL, + TWIN_STRETCH_SEMI_EXPANDED, + TWIN_STRETCH_EXPANDED, + TWIN_STRETCH_EXTRA_EXPANDED, + TWIN_STRETCH_ULTRA_EXPANDED +} twin_face_stretch_t; + +typedef struct +{ + int value; + const char str[16]; +} FieldMap; + +static const FieldMap slant_map[] = { + { CAIRO_FONT_SLANT_NORMAL, "" }, + { CAIRO_FONT_SLANT_NORMAL, "Roman" }, + { CAIRO_FONT_SLANT_OBLIQUE, "Oblique" }, + { CAIRO_FONT_SLANT_ITALIC, "Italic" } +}; + +static const FieldMap smallcaps_map[] = { + { FALSE, "" }, + { TRUE, "Small-Caps" } +}; + +static const FieldMap weight_map[] = { + { TWIN_WEIGHT_THIN, "Thin" }, + { TWIN_WEIGHT_ULTRALIGHT, "Ultra-Light" }, + { TWIN_WEIGHT_ULTRALIGHT, "Extra-Light" }, + { TWIN_WEIGHT_LIGHT, "Light" }, + { TWIN_WEIGHT_BOOK, "Book" }, + { TWIN_WEIGHT_NORMAL, "" }, + { TWIN_WEIGHT_NORMAL, "Regular" }, + { TWIN_WEIGHT_MEDIUM, "Medium" }, + { TWIN_WEIGHT_SEMIBOLD, "Semi-Bold" }, + { TWIN_WEIGHT_SEMIBOLD, "Demi-Bold" }, + { TWIN_WEIGHT_BOLD, "Bold" }, + { TWIN_WEIGHT_ULTRABOLD, "Ultra-Bold" }, + { TWIN_WEIGHT_ULTRABOLD, "Extra-Bold" }, + { TWIN_WEIGHT_HEAVY, "Heavy" }, + { TWIN_WEIGHT_HEAVY, "Black" }, + { TWIN_WEIGHT_ULTRAHEAVY, "Ultra-Heavy" }, + { TWIN_WEIGHT_ULTRAHEAVY, "Extra-Heavy" }, + { TWIN_WEIGHT_ULTRAHEAVY, "Ultra-Black" }, + { TWIN_WEIGHT_ULTRAHEAVY, "Extra-Black" } +}; + +static const FieldMap stretch_map[] = { + { TWIN_STRETCH_ULTRA_CONDENSED, "Ultra-Condensed" }, + { TWIN_STRETCH_EXTRA_CONDENSED, "Extra-Condensed" }, + { TWIN_STRETCH_CONDENSED, "Condensed" }, + { TWIN_STRETCH_SEMI_CONDENSED, "Semi-Condensed" }, + { TWIN_STRETCH_NORMAL, "" }, + { TWIN_STRETCH_SEMI_EXPANDED, "Semi-Expanded" }, + { TWIN_STRETCH_EXPANDED, "Expanded" }, + { TWIN_STRETCH_EXTRA_EXPANDED, "Extra-Expanded" }, + { TWIN_STRETCH_ULTRA_EXPANDED, "Ultra-Expanded" } +}; + +static const FieldMap monospace_map[] = { + { FALSE, "" }, + { TRUE, "Mono" }, + { TRUE, "Monospace" } +}; + + +typedef struct _twin_face_properties { + cairo_font_slant_t slant; + twin_face_weight_t weight; + twin_face_stretch_t stretch; + + /* lets have some fun */ + cairo_bool_t monospace; + cairo_bool_t smallcaps; +} twin_face_properties_t; + +static cairo_bool_t +field_matches (const char *s1, + const char *s2, + int len) +{ + int c1, c2; + + while (len && *s1 && *s2) + { +#define TOLOWER(c) \ + (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c)) + + c1 = TOLOWER (*s1); + c2 = TOLOWER (*s2); + if (c1 != c2) { + if (c1 == '-') { + s1++; + continue; + } + return FALSE; + } + s1++; s2++; + len--; + } + + return len == 0 && *s1 == '\0'; +} + +static cairo_bool_t +parse_int (const char *word, + size_t wordlen, + int *out) +{ + char *end; + long val = strtol (word, &end, 10); + int i = val; + + if (end != word && (end == word + wordlen) && val >= 0 && val == i) + { + if (out) + *out = i; + + return TRUE; + } + + return FALSE; +} + +static cairo_bool_t +find_field (const char *what, + const FieldMap *map, + int n_elements, + const char *str, + int len, + int *val) +{ + int i; + cairo_bool_t had_prefix = FALSE; + + if (what) + { + i = strlen (what); + if (len > i && 0 == strncmp (what, str, i) && str[i] == '=') + { + str += i + 1; + len -= i + 1; + had_prefix = TRUE; + } + } + + for (i=0; iNAME)) \ + return; \ + + FIELD (weight); + FIELD (slant); + FIELD (stretch); + FIELD (smallcaps); + FIELD (monospace); + +#undef FIELD +} + +static void +face_props_parse (twin_face_properties_t *props, + const char *s) +{ + const char *start, *end; + + for (start = end = s; *end; end++) { + if (*end != ' ' && *end != ':') + continue; + + if (start < end) + parse_field (props, start, end - start); + start = end + 1; + } + if (start < end) + parse_field (props, start, end - start); +} + +static twin_face_properties_t * +twin_font_face_create_properties (cairo_font_face_t *twin_face) +{ + twin_face_properties_t *props; + + props = malloc (sizeof (twin_face_properties_t)); + if (unlikely (props == NULL)) + return NULL; + + props->stretch = TWIN_STRETCH_NORMAL; + props->slant = CAIRO_FONT_SLANT_NORMAL; + props->weight = TWIN_WEIGHT_NORMAL; + props->monospace = FALSE; + props->smallcaps = FALSE; + + if (unlikely (cairo_font_face_set_user_data (twin_face, + &twin_properties_key, + props, free))) { + free (props); + return NULL; + } + + return props; +} + +static cairo_status_t +twin_font_face_set_properties_from_toy (cairo_font_face_t *twin_face, + cairo_toy_font_face_t *toy_face) +{ + twin_face_properties_t *props; + + props = twin_font_face_create_properties (twin_face); + if (unlikely (props == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + props->slant = toy_face->slant; + props->weight = toy_face->weight == CAIRO_FONT_WEIGHT_NORMAL ? + TWIN_WEIGHT_NORMAL : TWIN_WEIGHT_BOLD; + face_props_parse (props, toy_face->family); + + return CAIRO_STATUS_SUCCESS; +} + + +/* + * Scaled properties + */ + +typedef struct _twin_scaled_properties { + twin_face_properties_t *face_props; + + cairo_bool_t snap; /* hint outlines */ + + double weight; /* unhinted pen width */ + double penx, peny; /* hinted pen width */ + double marginl, marginr; /* hinted side margins */ + + double stretch; /* stretch factor */ +} twin_scaled_properties_t; + +static void +compute_hinting_scale (cairo_t *cr, + double x, double y, + double *scale, double *inv) +{ + cairo_user_to_device_distance (cr, &x, &y); + *scale = x == 0 ? y : y == 0 ? x :sqrt (x*x + y*y); + *inv = 1 / *scale; +} + +static void +compute_hinting_scales (cairo_t *cr, + double *x_scale, double *x_scale_inv, + double *y_scale, double *y_scale_inv) +{ + double x, y; + + x = 1; y = 0; + compute_hinting_scale (cr, x, y, x_scale, x_scale_inv); + + x = 0; y = 1; + compute_hinting_scale (cr, x, y, y_scale, y_scale_inv); +} + +#define SNAPXI(p) (_cairo_round ((p) * x_scale) * x_scale_inv) +#define SNAPYI(p) (_cairo_round ((p) * y_scale) * y_scale_inv) + +/* This controls the global font size */ +#define F(g) ((g) / 72.) + +static void +twin_hint_pen_and_margins(cairo_t *cr, + double *penx, double *peny, + double *marginl, double *marginr) +{ + double x_scale, x_scale_inv; + double y_scale, y_scale_inv; + double margin; + + compute_hinting_scales (cr, + &x_scale, &x_scale_inv, + &y_scale, &y_scale_inv); + + *penx = SNAPXI (*penx); + if (*penx < x_scale_inv) + *penx = x_scale_inv; + + *peny = SNAPYI (*peny); + if (*peny < y_scale_inv) + *peny = y_scale_inv; + + margin = *marginl + *marginr; + *marginl = SNAPXI (*marginl); + if (*marginl < x_scale_inv) + *marginl = x_scale_inv; + + *marginr = margin - *marginl; + if (*marginr < 0) + *marginr = 0; + *marginr = SNAPXI (*marginr); +} + +static cairo_status_t +twin_scaled_font_compute_properties (cairo_scaled_font_t *scaled_font, + cairo_t *cr) +{ + cairo_status_t status; + twin_scaled_properties_t *props; + + props = malloc (sizeof (twin_scaled_properties_t)); + if (unlikely (props == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + + props->face_props = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font), + &twin_properties_key); + + props->snap = scaled_font->options.hint_style > CAIRO_HINT_STYLE_NONE; + + /* weight */ + props->weight = props->face_props->weight * (F (4) / TWIN_WEIGHT_NORMAL); + + /* pen & margins */ + props->penx = props->peny = props->weight; + props->marginl = props->marginr = F (4); + if (scaled_font->options.hint_style > CAIRO_HINT_STYLE_SLIGHT) + twin_hint_pen_and_margins(cr, + &props->penx, &props->peny, + &props->marginl, &props->marginr); + + /* stretch */ + props->stretch = 1 + .1 * ((int) props->face_props->stretch - (int) TWIN_STRETCH_NORMAL); + + + /* Save it */ + status = cairo_scaled_font_set_user_data (scaled_font, + &twin_properties_key, + props, free); + if (unlikely (status)) + goto FREE_PROPS; + + return CAIRO_STATUS_SUCCESS; + +FREE_PROPS: + free (props); + return status; +} + + +/* + * User-font implementation + */ + +static cairo_status_t +twin_scaled_font_init (cairo_scaled_font_t *scaled_font, + cairo_t *cr, + cairo_font_extents_t *metrics) +{ + metrics->ascent = F (54); + metrics->descent = 1 - metrics->ascent; + + return twin_scaled_font_compute_properties (scaled_font, cr); +} + +#define TWIN_GLYPH_MAX_SNAP_X 4 +#define TWIN_GLYPH_MAX_SNAP_Y 7 + +typedef struct { + int n_snap_x; + int8_t snap_x[TWIN_GLYPH_MAX_SNAP_X]; + double snapped_x[TWIN_GLYPH_MAX_SNAP_X]; + int n_snap_y; + int8_t snap_y[TWIN_GLYPH_MAX_SNAP_Y]; + double snapped_y[TWIN_GLYPH_MAX_SNAP_Y]; +} twin_snap_info_t; + +#define twin_glyph_left(g) ((g)[0]) +#define twin_glyph_right(g) ((g)[1]) +#define twin_glyph_ascent(g) ((g)[2]) +#define twin_glyph_descent(g) ((g)[3]) + +#define twin_glyph_n_snap_x(g) ((g)[4]) +#define twin_glyph_n_snap_y(g) ((g)[5]) +#define twin_glyph_snap_x(g) (&g[6]) +#define twin_glyph_snap_y(g) (twin_glyph_snap_x(g) + twin_glyph_n_snap_x(g)) +#define twin_glyph_draw(g) (twin_glyph_snap_y(g) + twin_glyph_n_snap_y(g)) + +static void +twin_compute_snap (cairo_t *cr, + twin_snap_info_t *info, + const signed char *b) +{ + int s, n; + const signed char *snap; + double x_scale, x_scale_inv; + double y_scale, y_scale_inv; + + compute_hinting_scales (cr, + &x_scale, &x_scale_inv, + &y_scale, &y_scale_inv); + + snap = twin_glyph_snap_x (b); + n = twin_glyph_n_snap_x (b); + info->n_snap_x = n; + assert (n <= TWIN_GLYPH_MAX_SNAP_X); + for (s = 0; s < n; s++) { + info->snap_x[s] = snap[s]; + info->snapped_x[s] = SNAPXI (F (snap[s])); + } + + snap = twin_glyph_snap_y (b); + n = twin_glyph_n_snap_y (b); + info->n_snap_y = n; + assert (n <= TWIN_GLYPH_MAX_SNAP_Y); + for (s = 0; s < n; s++) { + info->snap_y[s] = snap[s]; + info->snapped_y[s] = SNAPYI (F (snap[s])); + } +} + +static double +twin_snap (int8_t v, int n, int8_t *snap, double *snapped) +{ + int s; + + if (!n) + return F(v); + + if (snap[0] == v) + return snapped[0]; + + for (s = 0; s < n - 1; s++) + { + if (snap[s+1] == v) + return snapped[s+1]; + + if (snap[s] <= v && v <= snap[s+1]) + { + int before = snap[s]; + int after = snap[s+1]; + int dist = after - before; + double snap_before = snapped[s]; + double snap_after = snapped[s+1]; + double dist_before = v - before; + return snap_before + (snap_after - snap_before) * dist_before / dist; + } + } + return F(v); +} + +#define SNAPX(p) twin_snap (p, info.n_snap_x, info.snap_x, info.snapped_x) +#define SNAPY(p) twin_snap (p, info.n_snap_y, info.snap_y, info.snapped_y) + +static cairo_status_t +twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font, + unsigned long glyph, + cairo_t *cr, + cairo_text_extents_t *metrics) +{ + double x1, y1, x2, y2, x3, y3; + double marginl; + twin_scaled_properties_t *props; + twin_snap_info_t info; + const int8_t *b; + const int8_t *g; + int8_t w; + double gw; + + props = cairo_scaled_font_get_user_data (scaled_font, &twin_properties_key); + + /* Save glyph space, we need it when stroking */ + cairo_save (cr); + + /* center the pen */ + cairo_translate (cr, props->penx * .5, -props->peny * .5); + + /* small-caps */ + if (props->face_props->smallcaps && glyph >= 'a' && glyph <= 'z') { + glyph += 'A' - 'a'; + /* 28 and 42 are small and capital letter heights of the glyph data */ + cairo_scale (cr, 1, 28. / 42); + } + + /* slant */ + if (props->face_props->slant != CAIRO_FONT_SLANT_NORMAL) { + cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0}; + cairo_transform (cr, &shear); + } + + b = _cairo_twin_outlines + + _cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph]; + g = twin_glyph_draw(b); + w = twin_glyph_right(b); + gw = F(w); + + marginl = props->marginl; + + /* monospace */ + if (props->face_props->monospace) { + double monow = F(24); + double extra = props->penx + props->marginl + props->marginr; + cairo_scale (cr, (monow + extra) / (gw + extra), 1); + gw = monow; + + /* resnap margin for new transform */ + { + double x, y, x_scale, x_scale_inv; + x = 1; y = 0; + compute_hinting_scale (cr, x, y, &x_scale, &x_scale_inv); + marginl = SNAPXI (marginl); + } + } + + cairo_translate (cr, marginl, 0); + + /* stretch */ + cairo_scale (cr, props->stretch, 1); + + if (props->snap) + twin_compute_snap (cr, &info, b); + else + info.n_snap_x = info.n_snap_y = 0; + + /* advance width */ + metrics->x_advance = gw * props->stretch + props->penx + props->marginl + props->marginr; + + /* glyph shape */ + for (;;) { + switch (*g++) { + case 'M': + cairo_close_path (cr); + /* fall through */ + case 'm': + x1 = SNAPX(*g++); + y1 = SNAPY(*g++); + cairo_move_to (cr, x1, y1); + continue; + case 'L': + cairo_close_path (cr); + /* fall through */ + case 'l': + x1 = SNAPX(*g++); + y1 = SNAPY(*g++); + cairo_line_to (cr, x1, y1); + continue; + case 'C': + cairo_close_path (cr); + /* fall through */ + case 'c': + x1 = SNAPX(*g++); + y1 = SNAPY(*g++); + x2 = SNAPX(*g++); + y2 = SNAPY(*g++); + x3 = SNAPX(*g++); + y3 = SNAPY(*g++); + cairo_curve_to (cr, x1, y1, x2, y2, x3, y3); + continue; + case 'E': + cairo_close_path (cr); + /* fall through */ + case 'e': + cairo_restore (cr); /* restore glyph space */ + cairo_set_tolerance (cr, 0.01); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_width (cr, 1); + cairo_scale (cr, props->penx, props->peny); + cairo_stroke (cr); + break; + case 'X': + /* filler */ + continue; + } + break; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +twin_scaled_font_unicode_to_glyph (cairo_scaled_font_t *scaled_font, + unsigned long unicode, + unsigned long *glyph) +{ + /* We use an identity charmap. Which means we could live + * with no unicode_to_glyph method too. But we define this + * to map all unknown chars to a single unknown glyph to + * reduce pressure on cache. */ + + if (likely (unicode < ARRAY_LENGTH (_cairo_twin_charmap))) + *glyph = unicode; + else + *glyph = 0; + + return CAIRO_STATUS_SUCCESS; +} + + +/* + * Face constructor + */ + +static cairo_font_face_t * +_cairo_font_face_twin_create_internal (void) +{ + cairo_font_face_t *twin_font_face; + + twin_font_face = cairo_user_font_face_create (); + cairo_user_font_face_set_init_func (twin_font_face, twin_scaled_font_init); + cairo_user_font_face_set_render_glyph_func (twin_font_face, twin_scaled_font_render_glyph); + cairo_user_font_face_set_unicode_to_glyph_func (twin_font_face, twin_scaled_font_unicode_to_glyph); + + return twin_font_face; +} + +cairo_font_face_t * +_cairo_font_face_twin_create_fallback (void) +{ + cairo_font_face_t *twin_font_face; + + twin_font_face = _cairo_font_face_twin_create_internal (); + if (! twin_font_face_create_properties (twin_font_face)) { + cairo_font_face_destroy (twin_font_face); + return (cairo_font_face_t *) &_cairo_font_face_nil; + } + + return twin_font_face; +} + +cairo_status_t +_cairo_font_face_twin_create_for_toy (cairo_toy_font_face_t *toy_face, + cairo_font_face_t **font_face) +{ + cairo_status_t status; + cairo_font_face_t *twin_font_face; + + twin_font_face = _cairo_font_face_twin_create_internal (); + status = twin_font_face_set_properties_from_toy (twin_font_face, toy_face); + if (status) { + cairo_font_face_destroy (twin_font_face); + return status; + } + + *font_face = twin_font_face; + + return CAIRO_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-font-face.c b/Build/source/libs/cairo/cairo-src/src/cairo-font-face.c new file mode 100644 index 00000000000..795951b1420 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-font-face.c @@ -0,0 +1,345 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Graydon Hoare + * Owen Taylor + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +/** + * SECTION:cairo-font-face + * @Title: cairo_font_face_t + * @Short_Description: Base class for font faces + * @See_Also: #cairo_scaled_font_t + * + * #cairo_font_face_t represents a particular font at a particular weight, + * slant, and other characteristic but no size, transformation, or size. + * + * Font faces are created using font-backend-specific + * constructors, typically of the form + * cairo_backend_font_face_create(), + * or implicitly using the toy text API by way of + * cairo_select_font_face(). The resulting face can be accessed using + * cairo_get_font_face(). + **/ + +/* #cairo_font_face_t */ + +const cairo_font_face_t _cairo_font_face_nil = { + { 0 }, /* hash_entry */ + CAIRO_STATUS_NO_MEMORY, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL +}; +const cairo_font_face_t _cairo_font_face_nil_file_not_found = { + { 0 }, /* hash_entry */ + CAIRO_STATUS_FILE_NOT_FOUND, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL +}; + +cairo_status_t +_cairo_font_face_set_error (cairo_font_face_t *font_face, + cairo_status_t status) +{ + if (status == CAIRO_STATUS_SUCCESS) + return status; + + /* Don't overwrite an existing error. This preserves the first + * error, which is the most significant. */ + _cairo_status_set_error (&font_face->status, status); + + return _cairo_error (status); +} + +void +_cairo_font_face_init (cairo_font_face_t *font_face, + const cairo_font_face_backend_t *backend) +{ + CAIRO_MUTEX_INITIALIZE (); + + font_face->status = CAIRO_STATUS_SUCCESS; + CAIRO_REFERENCE_COUNT_INIT (&font_face->ref_count, 1); + font_face->backend = backend; + + _cairo_user_data_array_init (&font_face->user_data); +} + +/** + * cairo_font_face_reference: + * @font_face: a #cairo_font_face_t, (may be %NULL in which case this + * function does nothing). + * + * Increases the reference count on @font_face by one. This prevents + * @font_face from being destroyed until a matching call to + * cairo_font_face_destroy() is made. + * + * The number of references to a #cairo_font_face_t can be get using + * cairo_font_face_get_reference_count(). + * + * Return value: the referenced #cairo_font_face_t. + * + * Since: 1.0 + **/ +cairo_font_face_t * +cairo_font_face_reference (cairo_font_face_t *font_face) +{ + if (font_face == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + return font_face; + + /* We would normally assert that we have a reference here but we + * can't get away with that due to the zombie case as documented + * in _cairo_ft_font_face_destroy. */ + + _cairo_reference_count_inc (&font_face->ref_count); + + return font_face; +} +slim_hidden_def (cairo_font_face_reference); + +static inline cairo_bool_t +__put(cairo_reference_count_t *v) +{ + int c, old; + + c = CAIRO_REFERENCE_COUNT_GET_VALUE(v); + while (c != 1 && (old = _cairo_atomic_int_cmpxchg_return_old(&v->ref_count, c, c - 1)) != c) + c = old; + + return c != 1; +} + +cairo_bool_t +_cairo_font_face_destroy (void *abstract_face) +{ +#if 0 /* Nothing needs to be done, we can just drop the last reference */ + cairo_font_face_t *font_face = abstract_face; + return _cairo_reference_count_dec_and_test (&font_face->ref_count); +#endif + return TRUE; +} + +/** + * cairo_font_face_destroy: + * @font_face: a #cairo_font_face_t + * + * Decreases the reference count on @font_face by one. If the result + * is zero, then @font_face and all associated resources are freed. + * See cairo_font_face_reference(). + * + * Since: 1.0 + **/ +void +cairo_font_face_destroy (cairo_font_face_t *font_face) +{ + if (font_face == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->ref_count)); + + /* We allow resurrection to deal with some memory management for the + * FreeType backend where cairo_ft_font_face_t and cairo_ft_unscaled_font_t + * need to effectively mutually reference each other + */ + if (__put (&font_face->ref_count)) + return; + + if (! font_face->backend->destroy (font_face)) + return; + + _cairo_user_data_array_fini (&font_face->user_data); + + free (font_face); +} +slim_hidden_def (cairo_font_face_destroy); + +/** + * cairo_font_face_get_type: + * @font_face: a font face + * + * This function returns the type of the backend used to create + * a font face. See #cairo_font_type_t for available types. + * + * Return value: The type of @font_face. + * + * Since: 1.2 + **/ +cairo_font_type_t +cairo_font_face_get_type (cairo_font_face_t *font_face) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + return CAIRO_FONT_TYPE_TOY; + + return font_face->backend->type; +} + +/** + * cairo_font_face_get_reference_count: + * @font_face: a #cairo_font_face_t + * + * Returns the current reference count of @font_face. + * + * Return value: the current reference count of @font_face. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.4 + **/ +unsigned int +cairo_font_face_get_reference_count (cairo_font_face_t *font_face) +{ + if (font_face == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&font_face->ref_count); +} + +/** + * cairo_font_face_status: + * @font_face: a #cairo_font_face_t + * + * Checks whether an error has previously occurred for this + * font face + * + * Return value: %CAIRO_STATUS_SUCCESS or another error such as + * %CAIRO_STATUS_NO_MEMORY. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_font_face_status (cairo_font_face_t *font_face) +{ + return font_face->status; +} + +/** + * cairo_font_face_get_user_data: + * @font_face: a #cairo_font_face_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @font_face using the specified + * key. If no user data has been attached with the given key this + * function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.0 + **/ +void * +cairo_font_face_get_user_data (cairo_font_face_t *font_face, + const cairo_user_data_key_t *key) +{ + return _cairo_user_data_array_get_data (&font_face->user_data, + key); +} +slim_hidden_def (cairo_font_face_get_user_data); + +/** + * cairo_font_face_set_user_data: + * @font_face: a #cairo_font_face_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the font face + * @destroy: a #cairo_destroy_func_t which will be called when the + * font face is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @font_face. To remove user data from a font face, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_font_face_set_user_data (cairo_font_face_t *font_face, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + return font_face->status; + + return _cairo_user_data_array_set_data (&font_face->user_data, + key, user_data, destroy); +} +slim_hidden_def (cairo_font_face_set_user_data); + +void +_cairo_unscaled_font_init (cairo_unscaled_font_t *unscaled_font, + const cairo_unscaled_font_backend_t *backend) +{ + CAIRO_REFERENCE_COUNT_INIT (&unscaled_font->ref_count, 1); + unscaled_font->backend = backend; +} + +cairo_unscaled_font_t * +_cairo_unscaled_font_reference (cairo_unscaled_font_t *unscaled_font) +{ + if (unscaled_font == NULL) + return NULL; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&unscaled_font->ref_count)); + + _cairo_reference_count_inc (&unscaled_font->ref_count); + + return unscaled_font; +} + +void +_cairo_unscaled_font_destroy (cairo_unscaled_font_t *unscaled_font) +{ + if (unscaled_font == NULL) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&unscaled_font->ref_count)); + + if (__put (&unscaled_font->ref_count)) + return; + + if (! unscaled_font->backend->destroy (unscaled_font)) + return; + + free (unscaled_font); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-font-options.c b/Build/source/libs/cairo/cairo-src/src/cairo-font-options.c new file mode 100644 index 00000000000..ad28745e6b9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-font-options.c @@ -0,0 +1,535 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Owen Taylor + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +/** + * SECTION:cairo-font-options + * @Title: cairo_font_options_t + * @Short_Description: How a font should be rendered + * @See_Also: #cairo_scaled_font_t + * + * The font options specify how fonts should be rendered. Most of the + * time the font options implied by a surface are just right and do not + * need any changes, but for pixel-based targets tweaking font options + * may result in superior output on a particular display. + **/ + +static const cairo_font_options_t _cairo_font_options_nil = { + CAIRO_ANTIALIAS_DEFAULT, + CAIRO_SUBPIXEL_ORDER_DEFAULT, + CAIRO_LCD_FILTER_DEFAULT, + CAIRO_HINT_STYLE_DEFAULT, + CAIRO_HINT_METRICS_DEFAULT, + CAIRO_ROUND_GLYPH_POS_DEFAULT +}; + +/** + * _cairo_font_options_init_default: + * @options: a #cairo_font_options_t + * + * Initializes all fields of the font options object to default values. + **/ +void +_cairo_font_options_init_default (cairo_font_options_t *options) +{ + options->antialias = CAIRO_ANTIALIAS_DEFAULT; + options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + options->lcd_filter = CAIRO_LCD_FILTER_DEFAULT; + options->hint_style = CAIRO_HINT_STYLE_DEFAULT; + options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT; + options->round_glyph_positions = CAIRO_ROUND_GLYPH_POS_DEFAULT; +} + +void +_cairo_font_options_init_copy (cairo_font_options_t *options, + const cairo_font_options_t *other) +{ + options->antialias = other->antialias; + options->subpixel_order = other->subpixel_order; + options->lcd_filter = other->lcd_filter; + options->hint_style = other->hint_style; + options->hint_metrics = other->hint_metrics; + options->round_glyph_positions = other->round_glyph_positions; +} + +/** + * cairo_font_options_create: + * + * Allocates a new font options object with all options initialized + * to default values. + * + * Return value: a newly allocated #cairo_font_options_t. Free with + * cairo_font_options_destroy(). This function always returns a + * valid pointer; if memory cannot be allocated, then a special + * error object is returned where all operations on the object do nothing. + * You can check for this with cairo_font_options_status(). + * + * Since: 1.0 + **/ +cairo_font_options_t * +cairo_font_options_create (void) +{ + cairo_font_options_t *options; + + options = malloc (sizeof (cairo_font_options_t)); + if (!options) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_options_t *) &_cairo_font_options_nil; + } + + _cairo_font_options_init_default (options); + + return options; +} + +/** + * cairo_font_options_copy: + * @original: a #cairo_font_options_t + * + * Allocates a new font options object copying the option values from + * @original. + * + * Return value: a newly allocated #cairo_font_options_t. Free with + * cairo_font_options_destroy(). This function always returns a + * valid pointer; if memory cannot be allocated, then a special + * error object is returned where all operations on the object do nothing. + * You can check for this with cairo_font_options_status(). + * + * Since: 1.0 + **/ +cairo_font_options_t * +cairo_font_options_copy (const cairo_font_options_t *original) +{ + cairo_font_options_t *options; + + if (cairo_font_options_status ((cairo_font_options_t *) original)) + return (cairo_font_options_t *) &_cairo_font_options_nil; + + options = malloc (sizeof (cairo_font_options_t)); + if (!options) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_options_t *) &_cairo_font_options_nil; + } + + _cairo_font_options_init_copy (options, original); + + return options; +} + +/** + * cairo_font_options_destroy: + * @options: a #cairo_font_options_t + * + * Destroys a #cairo_font_options_t object created with + * cairo_font_options_create() or cairo_font_options_copy(). + * + * Since: 1.0 + **/ +void +cairo_font_options_destroy (cairo_font_options_t *options) +{ + if (cairo_font_options_status (options)) + return; + + free (options); +} + +/** + * cairo_font_options_status: + * @options: a #cairo_font_options_t + * + * Checks whether an error has previously occurred for this + * font options object + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.0 + **/ +cairo_status_t +cairo_font_options_status (cairo_font_options_t *options) +{ + if (options == NULL) + return CAIRO_STATUS_NULL_POINTER; + else if (options == (cairo_font_options_t *) &_cairo_font_options_nil) + return CAIRO_STATUS_NO_MEMORY; + else + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_font_options_status); + +/** + * cairo_font_options_merge: + * @options: a #cairo_font_options_t + * @other: another #cairo_font_options_t + * + * Merges non-default options from @other into @options, replacing + * existing values. This operation can be thought of as somewhat + * similar to compositing @other onto @options with the operation + * of %CAIRO_OPERATOR_OVER. + * + * Since: 1.0 + **/ +void +cairo_font_options_merge (cairo_font_options_t *options, + const cairo_font_options_t *other) +{ + if (cairo_font_options_status (options)) + return; + + if (cairo_font_options_status ((cairo_font_options_t *) other)) + return; + + if (other->antialias != CAIRO_ANTIALIAS_DEFAULT) + options->antialias = other->antialias; + if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) + options->subpixel_order = other->subpixel_order; + if (other->lcd_filter != CAIRO_LCD_FILTER_DEFAULT) + options->lcd_filter = other->lcd_filter; + if (other->hint_style != CAIRO_HINT_STYLE_DEFAULT) + options->hint_style = other->hint_style; + if (other->hint_metrics != CAIRO_HINT_METRICS_DEFAULT) + options->hint_metrics = other->hint_metrics; + if (other->round_glyph_positions != CAIRO_ROUND_GLYPH_POS_DEFAULT) + options->round_glyph_positions = other->round_glyph_positions; +} +slim_hidden_def (cairo_font_options_merge); + +/** + * cairo_font_options_equal: + * @options: a #cairo_font_options_t + * @other: another #cairo_font_options_t + * + * Compares two font options objects for equality. + * + * Return value: %TRUE if all fields of the two font options objects match. + * Note that this function will return %FALSE if either object is in + * error. + * + * Since: 1.0 + **/ +cairo_bool_t +cairo_font_options_equal (const cairo_font_options_t *options, + const cairo_font_options_t *other) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return FALSE; + if (cairo_font_options_status ((cairo_font_options_t *) other)) + return FALSE; + + if (options == other) + return TRUE; + + return (options->antialias == other->antialias && + options->subpixel_order == other->subpixel_order && + options->lcd_filter == other->lcd_filter && + options->hint_style == other->hint_style && + options->hint_metrics == other->hint_metrics && + options->round_glyph_positions == other->round_glyph_positions); +} +slim_hidden_def (cairo_font_options_equal); + +/** + * cairo_font_options_hash: + * @options: a #cairo_font_options_t + * + * Compute a hash for the font options object; this value will + * be useful when storing an object containing a #cairo_font_options_t + * in a hash table. + * + * Return value: the hash value for the font options object. + * The return value can be cast to a 32-bit type if a + * 32-bit hash value is needed. + * + * Since: 1.0 + **/ +unsigned long +cairo_font_options_hash (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + options = &_cairo_font_options_nil; /* force default values */ + + return ((options->antialias) | + (options->subpixel_order << 4) | + (options->lcd_filter << 8) | + (options->hint_style << 12) | + (options->hint_metrics << 16)); +} +slim_hidden_def (cairo_font_options_hash); + +/** + * cairo_font_options_set_antialias: + * @options: a #cairo_font_options_t + * @antialias: the new antialiasing mode + * + * Sets the antialiasing mode for the font options object. This + * specifies the type of antialiasing to do when rendering text. + * + * Since: 1.0 + **/ +void +cairo_font_options_set_antialias (cairo_font_options_t *options, + cairo_antialias_t antialias) +{ + if (cairo_font_options_status (options)) + return; + + options->antialias = antialias; +} +slim_hidden_def (cairo_font_options_set_antialias); + +/** + * cairo_font_options_get_antialias: + * @options: a #cairo_font_options_t + * + * Gets the antialiasing mode for the font options object. + * + * Return value: the antialiasing mode + * + * Since: 1.0 + **/ +cairo_antialias_t +cairo_font_options_get_antialias (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_ANTIALIAS_DEFAULT; + + return options->antialias; +} + +/** + * cairo_font_options_set_subpixel_order: + * @options: a #cairo_font_options_t + * @subpixel_order: the new subpixel order + * + * Sets the subpixel order for the font options object. The subpixel + * order specifies the order of color elements within each pixel on + * the display device when rendering with an antialiasing mode of + * %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for + * #cairo_subpixel_order_t for full details. + * + * Since: 1.0 + **/ +void +cairo_font_options_set_subpixel_order (cairo_font_options_t *options, + cairo_subpixel_order_t subpixel_order) +{ + if (cairo_font_options_status (options)) + return; + + options->subpixel_order = subpixel_order; +} +slim_hidden_def (cairo_font_options_set_subpixel_order); + +/** + * cairo_font_options_get_subpixel_order: + * @options: a #cairo_font_options_t + * + * Gets the subpixel order for the font options object. + * See the documentation for #cairo_subpixel_order_t for full details. + * + * Return value: the subpixel order for the font options object + * + * Since: 1.0 + **/ +cairo_subpixel_order_t +cairo_font_options_get_subpixel_order (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_SUBPIXEL_ORDER_DEFAULT; + + return options->subpixel_order; +} + +/** + * _cairo_font_options_set_lcd_filter: + * @options: a #cairo_font_options_t + * @lcd_filter: the new LCD filter + * + * Sets the LCD filter for the font options object. The LCD filter + * specifies how pixels are filtered when rendered with an antialiasing + * mode of %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for + * #cairo_lcd_filter_t for full details. + **/ +void +_cairo_font_options_set_lcd_filter (cairo_font_options_t *options, + cairo_lcd_filter_t lcd_filter) +{ + if (cairo_font_options_status (options)) + return; + + options->lcd_filter = lcd_filter; +} + +/** + * _cairo_font_options_get_lcd_filter: + * @options: a #cairo_font_options_t + * + * Gets the LCD filter for the font options object. + * See the documentation for #cairo_lcd_filter_t for full details. + * + * Return value: the LCD filter for the font options object + **/ +cairo_lcd_filter_t +_cairo_font_options_get_lcd_filter (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_LCD_FILTER_DEFAULT; + + return options->lcd_filter; +} + +/** + * _cairo_font_options_set_round_glyph_positions: + * @options: a #cairo_font_options_t + * @round: the new rounding value + * + * Sets the rounding options for the font options object. If rounding is set, a + * glyph's position will be rounded to integer values. + **/ +void +_cairo_font_options_set_round_glyph_positions (cairo_font_options_t *options, + cairo_round_glyph_positions_t round) +{ + if (cairo_font_options_status (options)) + return; + + options->round_glyph_positions = round; +} + +/** + * _cairo_font_options_get_round_glyph_positions: + * @options: a #cairo_font_options_t + * + * Gets the glyph position rounding option for the font options object. + * + * Return value: The round glyph posistions flag for the font options object. + **/ +cairo_round_glyph_positions_t +_cairo_font_options_get_round_glyph_positions (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_ROUND_GLYPH_POS_DEFAULT; + + return options->round_glyph_positions; +} + +/** + * cairo_font_options_set_hint_style: + * @options: a #cairo_font_options_t + * @hint_style: the new hint style + * + * Sets the hint style for font outlines for the font options object. + * This controls whether to fit font outlines to the pixel grid, + * and if so, whether to optimize for fidelity or contrast. + * See the documentation for #cairo_hint_style_t for full details. + * + * Since: 1.0 + **/ +void +cairo_font_options_set_hint_style (cairo_font_options_t *options, + cairo_hint_style_t hint_style) +{ + if (cairo_font_options_status (options)) + return; + + options->hint_style = hint_style; +} +slim_hidden_def (cairo_font_options_set_hint_style); + +/** + * cairo_font_options_get_hint_style: + * @options: a #cairo_font_options_t + * + * Gets the hint style for font outlines for the font options object. + * See the documentation for #cairo_hint_style_t for full details. + * + * Return value: the hint style for the font options object + * + * Since: 1.0 + **/ +cairo_hint_style_t +cairo_font_options_get_hint_style (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_HINT_STYLE_DEFAULT; + + return options->hint_style; +} + +/** + * cairo_font_options_set_hint_metrics: + * @options: a #cairo_font_options_t + * @hint_metrics: the new metrics hinting mode + * + * Sets the metrics hinting mode for the font options object. This + * controls whether metrics are quantized to integer values in + * device units. + * See the documentation for #cairo_hint_metrics_t for full details. + * + * Since: 1.0 + **/ +void +cairo_font_options_set_hint_metrics (cairo_font_options_t *options, + cairo_hint_metrics_t hint_metrics) +{ + if (cairo_font_options_status (options)) + return; + + options->hint_metrics = hint_metrics; +} +slim_hidden_def (cairo_font_options_set_hint_metrics); + +/** + * cairo_font_options_get_hint_metrics: + * @options: a #cairo_font_options_t + * + * Gets the metrics hinting mode for the font options object. + * See the documentation for #cairo_hint_metrics_t for full details. + * + * Return value: the metrics hinting mode for the font options object + * + * Since: 1.0 + **/ +cairo_hint_metrics_t +cairo_font_options_get_hint_metrics (const cairo_font_options_t *options) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return CAIRO_HINT_METRICS_DEFAULT; + + return options->hint_metrics; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-fontconfig-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-fontconfig-private.h new file mode 100644 index 00000000000..ea873abe7e4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-fontconfig-private.h @@ -0,0 +1,78 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2000 Keith Packard + * Copyright © 2005 Red Hat, Inc + * Copyright © 2010 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Graydon Hoare + * Owen Taylor + * Keith Packard + * Carl Worth + * Chris Wilson + */ + +#ifndef _CAIRO_FONTCONFIG_PRIVATE_H +#define _CAIRO_FONTCONFIG_PRIVATE_H + +#include "cairo.h" + +#if CAIRO_HAS_FC_FONT +#include +#include +#endif + +/* sub-pixel order */ +#ifndef FC_RGBA_UNKNOWN +#define FC_RGBA_UNKNOWN 0 +#define FC_RGBA_RGB 1 +#define FC_RGBA_BGR 2 +#define FC_RGBA_VRGB 3 +#define FC_RGBA_VBGR 4 +#define FC_RGBA_NONE 5 +#endif + +/* hinting style */ +#ifndef FC_HINT_NONE +#define FC_HINT_NONE 0 +#define FC_HINT_SLIGHT 1 +#define FC_HINT_MEDIUM 2 +#define FC_HINT_FULL 3 +#endif + +/* LCD filter */ +#ifndef FC_LCD_NONE +#define FC_LCD_NONE 0 +#define FC_LCD_DEFAULT 1 +#define FC_LCD_LIGHT 2 +#define FC_LCD_LEGACY 3 +#endif + +#endif /* _CAIRO_FONTCONFIG_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-freed-pool-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-freed-pool-private.h new file mode 100644 index 00000000000..0ec6de3d1f1 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-freed-pool-private.h @@ -0,0 +1,139 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_FREED_POOL_H +#define CAIRO_FREED_POOL_H + +#include "cairoint.h" +#include "cairo-atomic-private.h" + +CAIRO_BEGIN_DECLS + +#define DISABLE_FREED_POOLS 0 + +#if HAS_ATOMIC_OPS && ! DISABLE_FREED_POOLS +/* Keep a stash of recently freed clip_paths, since we need to + * reallocate them frequently. + */ +#define MAX_FREED_POOL_SIZE 16 +typedef struct { + void *pool[MAX_FREED_POOL_SIZE]; + int top; +} freed_pool_t; + +static cairo_always_inline void * +_atomic_fetch (void **slot) +{ + void *ptr; + + do { + ptr = _cairo_atomic_ptr_get (slot); + } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); + + return ptr; +} + +static cairo_always_inline cairo_bool_t +_atomic_store (void **slot, void *ptr) +{ + return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr); +} + +cairo_private void * +_freed_pool_get_search (freed_pool_t *pool); + +static inline void * +_freed_pool_get (freed_pool_t *pool) +{ + void *ptr; + int i; + + i = pool->top - 1; + if (i < 0) + i = 0; + + ptr = _atomic_fetch (&pool->pool[i]); + if (likely (ptr != NULL)) { + pool->top = i; + return ptr; + } + + /* either empty or contended */ + return _freed_pool_get_search (pool); +} + +cairo_private void +_freed_pool_put_search (freed_pool_t *pool, void *ptr); + +static inline void +_freed_pool_put (freed_pool_t *pool, void *ptr) +{ + int i; + + i = pool->top; + if (likely (i < ARRAY_LENGTH (pool->pool) && + _atomic_store (&pool->pool[i], ptr))) + { + pool->top = i + 1; + return; + } + + /* either full or contended */ + _freed_pool_put_search (pool, ptr); +} + +cairo_private void +_freed_pool_reset (freed_pool_t *pool); + +#define HAS_FREED_POOL 1 + +#else + +/* A warning about an unused freed-pool in a build without atomics + * enabled usually indicates a missing _freed_pool_reset() in the + * static reset function */ + +typedef int freed_pool_t; + +#define _freed_pool_get(pool) NULL +#define _freed_pool_put(pool, ptr) free(ptr) +#define _freed_pool_reset(ptr) + +#endif + +CAIRO_END_DECLS + +#endif /* CAIRO_FREED_POOL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-freed-pool.c b/Build/source/libs/cairo/cairo-src/src/cairo-freed-pool.c new file mode 100644 index 00000000000..cfdc8e96b05 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-freed-pool.c @@ -0,0 +1,93 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-freed-pool-private.h" + +#if HAS_FREED_POOL + +void * +_freed_pool_get_search (freed_pool_t *pool) +{ + void *ptr; + int i; + + for (i = ARRAY_LENGTH (pool->pool); i--;) { + ptr = _atomic_fetch (&pool->pool[i]); + if (ptr != NULL) { + pool->top = i; + return ptr; + } + } + + /* empty */ + pool->top = 0; + return NULL; +} + +void +_freed_pool_put_search (freed_pool_t *pool, void *ptr) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) { + if (_atomic_store (&pool->pool[i], ptr)) { + pool->top = i + 1; + return; + } + } + + /* full */ + pool->top = i; + free (ptr); +} + +void +_freed_pool_reset (freed_pool_t *pool) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) { + free (pool->pool[i]); + pool->pool[i] = NULL; + } + + pool->top = 0; +} + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-freelist-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-freelist-private.h new file mode 100644 index 00000000000..8fe6516f385 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-freelist-private.h @@ -0,0 +1,139 @@ +/* + * Copyright © 2006 Joonas Pihlaja + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +#ifndef CAIRO_FREELIST_H +#define CAIRO_FREELIST_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" +#include "cairo-freelist-type-private.h" + +/* for stand-alone compilation*/ +#ifndef VG +#define VG(x) +#endif + +#ifndef NULL +#define NULL (void *) 0 +#endif + +/* Initialise a freelist that will be responsible for allocating + * nodes of size nodesize. */ +cairo_private void +_cairo_freelist_init (cairo_freelist_t *freelist, unsigned nodesize); + +/* Deallocate any nodes in the freelist. */ +cairo_private void +_cairo_freelist_fini (cairo_freelist_t *freelist); + +/* Allocate a new node from the freelist. If the freelist contains no + * nodes, a new one will be allocated using malloc(). The caller is + * responsible for calling _cairo_freelist_free() or free() on the + * returned node. Returns %NULL on memory allocation error. */ +cairo_private void * +_cairo_freelist_alloc (cairo_freelist_t *freelist); + +/* Allocate a new node from the freelist. If the freelist contains no + * nodes, a new one will be allocated using calloc(). The caller is + * responsible for calling _cairo_freelist_free() or free() on the + * returned node. Returns %NULL on memory allocation error. */ +cairo_private void * +_cairo_freelist_calloc (cairo_freelist_t *freelist); + +/* Return a node to the freelist. This does not deallocate the memory, + * but makes it available for later reuse by + * _cairo_freelist_alloc(). */ +cairo_private void +_cairo_freelist_free (cairo_freelist_t *freelist, void *node); + + +cairo_private void +_cairo_freepool_init (cairo_freepool_t *freepool, unsigned nodesize); + +cairo_private void +_cairo_freepool_fini (cairo_freepool_t *freepool); + +static inline void +_cairo_freepool_reset (cairo_freepool_t *freepool) +{ + while (freepool->pools != &freepool->embedded_pool) { + cairo_freelist_pool_t *pool = freepool->pools; + freepool->pools = pool->next; + pool->next = freepool->freepools; + freepool->freepools = pool; + } + + freepool->embedded_pool.rem = sizeof (freepool->embedded_data); + freepool->embedded_pool.data = freepool->embedded_data; +} + +cairo_private void * +_cairo_freepool_alloc_from_new_pool (cairo_freepool_t *freepool); + +static inline void * +_cairo_freepool_alloc_from_pool (cairo_freepool_t *freepool) +{ + cairo_freelist_pool_t *pool; + uint8_t *ptr; + + pool = freepool->pools; + if (unlikely (freepool->nodesize > pool->rem)) + return _cairo_freepool_alloc_from_new_pool (freepool); + + ptr = pool->data; + pool->data += freepool->nodesize; + pool->rem -= freepool->nodesize; + VG (VALGRIND_MAKE_MEM_UNDEFINED (ptr, freepool->nodesize)); + return ptr; +} + +static inline void * +_cairo_freepool_alloc (cairo_freepool_t *freepool) +{ + cairo_freelist_node_t *node; + + node = freepool->first_free_node; + if (node == NULL) + return _cairo_freepool_alloc_from_pool (freepool); + + VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); + freepool->first_free_node = node->next; + VG (VALGRIND_MAKE_MEM_UNDEFINED (node, freepool->nodesize)); + + return node; +} + +cairo_private cairo_status_t +_cairo_freepool_alloc_array (cairo_freepool_t *freepool, + int count, + void **array); + +static inline void +_cairo_freepool_free (cairo_freepool_t *freepool, void *ptr) +{ + cairo_freelist_node_t *node = ptr; + + node->next = freepool->first_free_node; + freepool->first_free_node = node; + VG (VALGRIND_MAKE_MEM_NOACCESS (node, freepool->nodesize)); +} + +#endif /* CAIRO_FREELIST_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-freelist-type-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-freelist-type-private.h new file mode 100644 index 00000000000..4dd05646107 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-freelist-type-private.h @@ -0,0 +1,54 @@ +/* + * Copyright © 2010 Joonas Pihlaja + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +#ifndef CAIRO_FREELIST_TYPE_H +#define CAIRO_FREELIST_TYPE_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" + +typedef struct _cairo_freelist_node cairo_freelist_node_t; +struct _cairo_freelist_node { + cairo_freelist_node_t *next; +}; + +typedef struct _cairo_freelist { + cairo_freelist_node_t *first_free_node; + unsigned nodesize; +} cairo_freelist_t; + +typedef struct _cairo_freelist_pool cairo_freelist_pool_t; +struct _cairo_freelist_pool { + cairo_freelist_pool_t *next; + unsigned size, rem; + uint8_t *data; +}; + +typedef struct _cairo_freepool { + cairo_freelist_node_t *first_free_node; + cairo_freelist_pool_t *pools; + cairo_freelist_pool_t *freepools; + unsigned nodesize; + cairo_freelist_pool_t embedded_pool; + uint8_t embedded_data[1000]; +} cairo_freepool_t; + +#endif /* CAIRO_FREELIST_TYPE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-freelist.c b/Build/source/libs/cairo/cairo-src/src/cairo-freelist.c new file mode 100644 index 00000000000..d596eab81dc --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-freelist.c @@ -0,0 +1,191 @@ +/* + * Copyright © 2006 Joonas Pihlaja + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" + +void +_cairo_freelist_init (cairo_freelist_t *freelist, unsigned nodesize) +{ + memset (freelist, 0, sizeof (cairo_freelist_t)); + freelist->nodesize = nodesize; +} + +void +_cairo_freelist_fini (cairo_freelist_t *freelist) +{ + cairo_freelist_node_t *node = freelist->first_free_node; + while (node) { + cairo_freelist_node_t *next; + + VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); + next = node->next; + + free (node); + node = next; + } +} + +void * +_cairo_freelist_alloc (cairo_freelist_t *freelist) +{ + if (freelist->first_free_node) { + cairo_freelist_node_t *node; + + node = freelist->first_free_node; + VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); + freelist->first_free_node = node->next; + VG (VALGRIND_MAKE_MEM_UNDEFINED (node, freelist->nodesize)); + + return node; + } + + return malloc (freelist->nodesize); +} + +void * +_cairo_freelist_calloc (cairo_freelist_t *freelist) +{ + void *node = _cairo_freelist_alloc (freelist); + if (node) + memset (node, 0, freelist->nodesize); + return node; +} + +void +_cairo_freelist_free (cairo_freelist_t *freelist, void *voidnode) +{ + cairo_freelist_node_t *node = voidnode; + if (node) { + node->next = freelist->first_free_node; + freelist->first_free_node = node; + VG (VALGRIND_MAKE_MEM_NOACCESS (node, freelist->nodesize)); + } +} + +void +_cairo_freepool_init (cairo_freepool_t *freepool, unsigned nodesize) +{ + freepool->first_free_node = NULL; + freepool->pools = &freepool->embedded_pool; + freepool->freepools = NULL; + freepool->nodesize = nodesize; + + freepool->embedded_pool.next = NULL; + freepool->embedded_pool.size = sizeof (freepool->embedded_data); + freepool->embedded_pool.rem = sizeof (freepool->embedded_data); + freepool->embedded_pool.data = freepool->embedded_data; + + VG (VALGRIND_MAKE_MEM_NOACCESS (freepool->embedded_data, sizeof (freepool->embedded_data))); +} + +void +_cairo_freepool_fini (cairo_freepool_t *freepool) +{ + cairo_freelist_pool_t *pool; + + pool = freepool->pools; + while (pool != &freepool->embedded_pool) { + cairo_freelist_pool_t *next = pool->next; + free (pool); + pool = next; + } + + pool = freepool->freepools; + while (pool != NULL) { + cairo_freelist_pool_t *next = pool->next; + free (pool); + pool = next; + } + + VG (VALGRIND_MAKE_MEM_NOACCESS (freepool, sizeof (freepool))); +} + +void * +_cairo_freepool_alloc_from_new_pool (cairo_freepool_t *freepool) +{ + cairo_freelist_pool_t *pool; + int poolsize; + + if (freepool->freepools != NULL) { + pool = freepool->freepools; + freepool->freepools = pool->next; + + poolsize = pool->size; + } else { + if (freepool->pools != &freepool->embedded_pool) + poolsize = 2 * freepool->pools->size; + else + poolsize = (128 * freepool->nodesize + 8191) & -8192; + + pool = malloc (sizeof (cairo_freelist_pool_t) + poolsize); + if (unlikely (pool == NULL)) + return pool; + + pool->size = poolsize; + } + + pool->next = freepool->pools; + freepool->pools = pool; + + pool->rem = poolsize - freepool->nodesize; + pool->data = (uint8_t *) (pool + 1) + freepool->nodesize; + + VG (VALGRIND_MAKE_MEM_NOACCESS (pool->data, pool->rem)); + + return pool + 1; +} + +cairo_status_t +_cairo_freepool_alloc_array (cairo_freepool_t *freepool, + int count, + void **array) +{ + int i; + + for (i = 0; i < count; i++) { + cairo_freelist_node_t *node; + + node = freepool->first_free_node; + if (likely (node != NULL)) { + VG (VALGRIND_MAKE_MEM_DEFINED (node, sizeof (node->next))); + freepool->first_free_node = node->next; + VG (VALGRIND_MAKE_MEM_UNDEFINED (node, freepool->nodesize)); + } else { + node = _cairo_freepool_alloc_from_pool (freepool); + if (unlikely (node == NULL)) + goto CLEANUP; + } + + array[i] = node; + } + + return CAIRO_STATUS_SUCCESS; + + CLEANUP: + while (i--) + _cairo_freepool_free (freepool, array[i]); + + return _cairo_error (CAIRO_STATUS_NO_MEMORY); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-ft-font.c b/Build/source/libs/cairo/cairo-src/src/cairo-ft-font.c new file mode 100644 index 00000000000..3e485c5b74c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-ft-font.c @@ -0,0 +1,3596 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2000 Keith Packard + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Graydon Hoare + * Owen Taylor + * Keith Packard + * Carl Worth + */ + +#define _BSD_SOURCE /* for strdup() */ +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-ft-private.h" +#include "cairo-pattern-private.h" +#include "cairo-pixman-private.h" + +#include + +#include "cairo-fontconfig-private.h" + +#include +#include FT_FREETYPE_H +#include FT_OUTLINE_H +#include FT_IMAGE_H +#include FT_BITMAP_H +#include FT_TRUETYPE_TABLES_H +#include FT_XFREE86_H +#if HAVE_FT_GLYPHSLOT_EMBOLDEN +#include FT_SYNTHESIS_H +#endif + +#if HAVE_FT_LIBRARY_SETLCDFILTER +#include FT_LCD_FILTER_H +#endif + +#if HAVE_UNISTD_H +#include +#else +#define access(p, m) 0 +#endif + +/* Fontconfig version older than 2.6 didn't have these options */ +#ifndef FC_LCD_FILTER +#define FC_LCD_FILTER "lcdfilter" +#endif +/* Some Ubuntu versions defined FC_LCD_FILTER without defining the following */ +#ifndef FC_LCD_NONE +#define FC_LCD_NONE 0 +#define FC_LCD_DEFAULT 1 +#define FC_LCD_LIGHT 2 +#define FC_LCD_LEGACY 3 +#endif + +/* FreeType version older than 2.3.5(?) didn't have these options */ +#ifndef FT_LCD_FILTER_NONE +#define FT_LCD_FILTER_NONE 0 +#define FT_LCD_FILTER_DEFAULT 1 +#define FT_LCD_FILTER_LIGHT 2 +#define FT_LCD_FILTER_LEGACY 16 +#endif + +#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0)) +#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0) +#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0)) +#define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0) + +/* This is the max number of FT_face objects we keep open at once + */ +#define MAX_OPEN_FACES 10 + +/** + * SECTION:cairo-ft + * @Title: FreeType Fonts + * @Short_Description: Font support for FreeType + * @See_Also: #cairo_font_face_t + * + * The FreeType font backend is primarily used to render text on GNU/Linux + * systems, but can be used on other platforms too. + **/ + +/** + * CAIRO_HAS_FT_FONT: + * + * Defined if the FreeType font backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.0 + **/ + +/** + * CAIRO_HAS_FC_FONT: + * + * Defined if the Fontconfig-specific functions of the FreeType font backend + * are available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.10 + **/ + +/* + * The simple 2x2 matrix is converted into separate scale and shape + * factors so that hinting works right + */ + +typedef struct _cairo_ft_font_transform { + double x_scale, y_scale; + double shape[2][2]; +} cairo_ft_font_transform_t; + +/* + * We create an object that corresponds to a single font on the disk; + * (identified by a filename/id pair) these are shared between all + * fonts using that file. For cairo_ft_font_face_create_for_ft_face(), we + * just create a one-off version with a permanent face value. + */ + +typedef struct _cairo_ft_font_face cairo_ft_font_face_t; + +struct _cairo_ft_unscaled_font { + cairo_unscaled_font_t base; + + cairo_bool_t from_face; /* was the FT_Face provided by user? */ + FT_Face face; /* provided or cached face */ + + /* only set if from_face is false */ + char *filename; + int id; + + /* We temporarily scale the unscaled font as needed */ + cairo_bool_t have_scale; + cairo_matrix_t current_scale; + double x_scale; /* Extracted X scale factor */ + double y_scale; /* Extracted Y scale factor */ + cairo_bool_t have_shape; /* true if the current scale has a non-scale component*/ + cairo_matrix_t current_shape; + FT_Matrix Current_Shape; + + cairo_mutex_t mutex; + int lock_count; + + cairo_ft_font_face_t *faces; /* Linked list of faces for this font */ +}; + +static int +_cairo_ft_unscaled_font_keys_equal (const void *key_a, + const void *key_b); + +static void +_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled); + +typedef struct _cairo_ft_options { + cairo_font_options_t base; + unsigned int load_flags; /* flags for FT_Load_Glyph */ + unsigned int synth_flags; +} cairo_ft_options_t; + +struct _cairo_ft_font_face { + cairo_font_face_t base; + + cairo_ft_unscaled_font_t *unscaled; + cairo_ft_options_t ft_options; + cairo_ft_font_face_t *next; + +#if CAIRO_HAS_FC_FONT + FcPattern *pattern; /* if pattern is set, the above fields will be NULL */ + cairo_font_face_t *resolved_font_face; + FcConfig *resolved_config; +#endif +}; + +static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend; + +#if CAIRO_HAS_FC_FONT +static cairo_status_t +_cairo_ft_font_options_substitute (const cairo_font_options_t *options, + FcPattern *pattern); + +static cairo_font_face_t * +_cairo_ft_resolve_pattern (FcPattern *pattern, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options); + +#endif + +static cairo_status_t +_ft_to_cairo_error (FT_Error error) +{ + /* Currently we don't get many (any?) useful statuses here. + * Populate as needed. */ + switch (error) + { + default: return CAIRO_STATUS_NO_MEMORY; + } +} + +/* + * We maintain a hash table to map file/id => #cairo_ft_unscaled_font_t. + * The hash table itself isn't limited in size. However, we limit the + * number of FT_Face objects we keep around; when we've exceeded that + * limit and need to create a new FT_Face, we dump the FT_Face from a + * random #cairo_ft_unscaled_font_t which has an unlocked FT_Face, (if + * there are any). + */ + +typedef struct _cairo_ft_unscaled_font_map { + cairo_hash_table_t *hash_table; + FT_Library ft_library; + int num_open_faces; +} cairo_ft_unscaled_font_map_t; + +static cairo_ft_unscaled_font_map_t *cairo_ft_unscaled_font_map = NULL; + + +static FT_Face +_cairo_ft_unscaled_font_lock_face (cairo_ft_unscaled_font_t *unscaled); + +static void +_cairo_ft_unscaled_font_unlock_face (cairo_ft_unscaled_font_t *unscaled); + +static cairo_bool_t +_cairo_ft_scaled_font_is_vertical (cairo_scaled_font_t *scaled_font); + + +static void +_font_map_release_face_lock_held (cairo_ft_unscaled_font_map_t *font_map, + cairo_ft_unscaled_font_t *unscaled) +{ + if (unscaled->face) { + FT_Done_Face (unscaled->face); + unscaled->face = NULL; + unscaled->have_scale = FALSE; + + font_map->num_open_faces--; + } +} + +static cairo_status_t +_cairo_ft_unscaled_font_map_create (void) +{ + cairo_ft_unscaled_font_map_t *font_map; + + /* This function is only intended to be called from + * _cairo_ft_unscaled_font_map_lock. So we'll crash if we can + * detect some other call path. */ + assert (cairo_ft_unscaled_font_map == NULL); + + font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t)); + if (unlikely (font_map == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font_map->hash_table = + _cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal); + + if (unlikely (font_map->hash_table == NULL)) + goto FAIL; + + if (unlikely (FT_Init_FreeType (&font_map->ft_library))) + goto FAIL; + + font_map->num_open_faces = 0; + + cairo_ft_unscaled_font_map = font_map; + return CAIRO_STATUS_SUCCESS; + +FAIL: + if (font_map->hash_table) + _cairo_hash_table_destroy (font_map->hash_table); + free (font_map); + + return _cairo_error (CAIRO_STATUS_NO_MEMORY); +} + + +static void +_cairo_ft_unscaled_font_map_pluck_entry (void *entry, void *closure) +{ + cairo_ft_unscaled_font_t *unscaled = entry; + cairo_ft_unscaled_font_map_t *font_map = closure; + + _cairo_hash_table_remove (font_map->hash_table, + &unscaled->base.hash_entry); + + if (! unscaled->from_face) + _font_map_release_face_lock_held (font_map, unscaled); + + _cairo_ft_unscaled_font_fini (unscaled); + free (unscaled); +} + +static void +_cairo_ft_unscaled_font_map_destroy (void) +{ + cairo_ft_unscaled_font_map_t *font_map; + + CAIRO_MUTEX_LOCK (_cairo_ft_unscaled_font_map_mutex); + font_map = cairo_ft_unscaled_font_map; + cairo_ft_unscaled_font_map = NULL; + CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); + + if (font_map != NULL) { + _cairo_hash_table_foreach (font_map->hash_table, + _cairo_ft_unscaled_font_map_pluck_entry, + font_map); + assert (font_map->num_open_faces == 0); + + FT_Done_FreeType (font_map->ft_library); + + _cairo_hash_table_destroy (font_map->hash_table); + + free (font_map); + } +} + +static cairo_ft_unscaled_font_map_t * +_cairo_ft_unscaled_font_map_lock (void) +{ + CAIRO_MUTEX_LOCK (_cairo_ft_unscaled_font_map_mutex); + + if (unlikely (cairo_ft_unscaled_font_map == NULL)) { + if (unlikely (_cairo_ft_unscaled_font_map_create ())) { + CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); + return NULL; + } + } + + return cairo_ft_unscaled_font_map; +} + +static void +_cairo_ft_unscaled_font_map_unlock (void) +{ + CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); +} + +static void +_cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key, + cairo_bool_t from_face, + char *filename, + int id, + FT_Face face) +{ + unsigned long hash; + + key->from_face = from_face; + key->filename = filename; + key->id = id; + key->face = face; + + hash = _cairo_hash_string (filename); + /* the constants are just arbitrary primes */ + hash += ((unsigned long) id) * 1607; + hash += ((unsigned long) face) * 2137; + + key->base.hash_entry.hash = hash; +} + +/** + * _cairo_ft_unscaled_font_init: + * + * Initialize a #cairo_ft_unscaled_font_t. + * + * There are two basic flavors of #cairo_ft_unscaled_font_t, one + * created from an FT_Face and the other created from a filename/id + * pair. These two flavors are identified as from_face and !from_face. + * + * To initialize a from_face font, pass filename==%NULL, id=0 and the + * desired face. + * + * To initialize a !from_face font, pass the filename/id as desired + * and face==%NULL. + * + * Note that the code handles these two flavors in very distinct + * ways. For example there is a hash_table mapping + * filename/id->#cairo_unscaled_font_t in the !from_face case, but no + * parallel in the from_face case, (where the calling code would have + * to do its own mapping to ensure similar sharing). + **/ +static cairo_status_t +_cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled, + cairo_bool_t from_face, + const char *filename, + int id, + FT_Face face) +{ + _cairo_unscaled_font_init (&unscaled->base, + &cairo_ft_unscaled_font_backend); + + if (from_face) { + unscaled->from_face = TRUE; + _cairo_ft_unscaled_font_init_key (unscaled, TRUE, NULL, 0, face); + } else { + char *filename_copy; + + unscaled->from_face = FALSE; + unscaled->face = NULL; + + filename_copy = strdup (filename); + if (unlikely (filename_copy == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_ft_unscaled_font_init_key (unscaled, FALSE, filename_copy, id, NULL); + } + + unscaled->have_scale = FALSE; + CAIRO_MUTEX_INIT (unscaled->mutex); + unscaled->lock_count = 0; + + unscaled->faces = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_ft_unscaled_font_fini: + * + * Free all data associated with a #cairo_ft_unscaled_font_t. + * + * CAUTION: The unscaled->face field must be %NULL before calling this + * function. This is because the #cairo_ft_unscaled_font_t_map keeps a + * count of these faces (font_map->num_open_faces) so it maintains the + * unscaled->face field while it has its lock held. See + * _font_map_release_face_lock_held(). + **/ +static void +_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled) +{ + assert (unscaled->face == NULL); + + free (unscaled->filename); + unscaled->filename = NULL; + + CAIRO_MUTEX_FINI (unscaled->mutex); +} + +static int +_cairo_ft_unscaled_font_keys_equal (const void *key_a, + const void *key_b) +{ + const cairo_ft_unscaled_font_t *unscaled_a = key_a; + const cairo_ft_unscaled_font_t *unscaled_b = key_b; + + if (unscaled_a->id == unscaled_b->id && + unscaled_a->from_face == unscaled_b->from_face) + { + if (unscaled_a->from_face) + return unscaled_a->face == unscaled_b->face; + + if (unscaled_a->filename == NULL && unscaled_b->filename == NULL) + return TRUE; + else if (unscaled_a->filename == NULL || unscaled_b->filename == NULL) + return FALSE; + else + return (strcmp (unscaled_a->filename, unscaled_b->filename) == 0); + } + + return FALSE; +} + +/* Finds or creates a #cairo_ft_unscaled_font_t for the filename/id from + * pattern. Returns a new reference to the unscaled font. + */ +static cairo_status_t +_cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face, + char *filename, + int id, + FT_Face font_face, + cairo_ft_unscaled_font_t **out) +{ + cairo_ft_unscaled_font_t key, *unscaled; + cairo_ft_unscaled_font_map_t *font_map; + cairo_status_t status; + + font_map = _cairo_ft_unscaled_font_map_lock (); + if (unlikely (font_map == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_ft_unscaled_font_init_key (&key, from_face, filename, id, font_face); + + /* Return existing unscaled font if it exists in the hash table. */ + unscaled = _cairo_hash_table_lookup (font_map->hash_table, + &key.base.hash_entry); + if (unscaled != NULL) { + _cairo_unscaled_font_reference (&unscaled->base); + goto DONE; + } + + /* Otherwise create it and insert into hash table. */ + unscaled = malloc (sizeof (cairo_ft_unscaled_font_t)); + if (unlikely (unscaled == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto UNWIND_FONT_MAP_LOCK; + } + + status = _cairo_ft_unscaled_font_init (unscaled, from_face, filename, id, font_face); + if (unlikely (status)) + goto UNWIND_UNSCALED_MALLOC; + + assert (unscaled->base.hash_entry.hash == key.base.hash_entry.hash); + status = _cairo_hash_table_insert (font_map->hash_table, + &unscaled->base.hash_entry); + if (unlikely (status)) + goto UNWIND_UNSCALED_FONT_INIT; + +DONE: + _cairo_ft_unscaled_font_map_unlock (); + *out = unscaled; + return CAIRO_STATUS_SUCCESS; + +UNWIND_UNSCALED_FONT_INIT: + _cairo_ft_unscaled_font_fini (unscaled); +UNWIND_UNSCALED_MALLOC: + free (unscaled); +UNWIND_FONT_MAP_LOCK: + _cairo_ft_unscaled_font_map_unlock (); + return status; +} + + +#if CAIRO_HAS_FC_FONT +static cairo_status_t +_cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern, + cairo_ft_unscaled_font_t **out) +{ + FT_Face font_face = NULL; + char *filename = NULL; + int id = 0; + FcResult ret; + + ret = FcPatternGetFTFace (pattern, FC_FT_FACE, 0, &font_face); + if (ret == FcResultMatch) + goto DONE; + if (ret == FcResultOutOfMemory) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + ret = FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **) &filename); + if (ret == FcResultOutOfMemory) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + if (ret == FcResultMatch) { + if (access (filename, R_OK) == 0) { + /* If FC_INDEX is not set, we just use 0 */ + ret = FcPatternGetInteger (pattern, FC_INDEX, 0, &id); + if (ret == FcResultOutOfMemory) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + goto DONE; + } else + return _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND); + } + + /* The pattern contains neither a face nor a filename, resolve it later. */ + *out = NULL; + return CAIRO_STATUS_SUCCESS; + +DONE: + return _cairo_ft_unscaled_font_create_internal (font_face != NULL, + filename, id, font_face, + out); +} +#endif + +static cairo_status_t +_cairo_ft_unscaled_font_create_from_face (FT_Face face, + cairo_ft_unscaled_font_t **out) +{ + return _cairo_ft_unscaled_font_create_internal (TRUE, NULL, 0, face, out); +} + +static cairo_bool_t +_cairo_ft_unscaled_font_destroy (void *abstract_font) +{ + cairo_ft_unscaled_font_t *unscaled = abstract_font; + cairo_ft_unscaled_font_map_t *font_map; + + font_map = _cairo_ft_unscaled_font_map_lock (); + /* All created objects must have been mapped in the font map. */ + assert (font_map != NULL); + + if (! _cairo_reference_count_dec_and_test (&unscaled->base.ref_count)) { + /* somebody recreated the font whilst we waited for the lock */ + _cairo_ft_unscaled_font_map_unlock (); + return FALSE; + } + + _cairo_hash_table_remove (font_map->hash_table, + &unscaled->base.hash_entry); + + if (unscaled->from_face) { + /* See comments in _ft_font_face_destroy about the "zombie" state + * for a _ft_font_face. + */ + if (unscaled->faces && unscaled->faces->unscaled == NULL) { + assert (unscaled->faces->next == NULL); + cairo_font_face_destroy (&unscaled->faces->base); + } + } else { + _font_map_release_face_lock_held (font_map, unscaled); + } + unscaled->face = NULL; + + _cairo_ft_unscaled_font_map_unlock (); + + _cairo_ft_unscaled_font_fini (unscaled); + return TRUE; +} + +static cairo_bool_t +_has_unlocked_face (const void *entry) +{ + const cairo_ft_unscaled_font_t *unscaled = entry; + + return (!unscaled->from_face && unscaled->lock_count == 0 && unscaled->face); +} + +/* Ensures that an unscaled font has a face object. If we exceed + * MAX_OPEN_FACES, try to close some. + * + * This differs from _cairo_ft_scaled_font_lock_face in that it doesn't + * set the scale on the face, but just returns it at the last scale. + */ +static cairo_warn FT_Face +_cairo_ft_unscaled_font_lock_face (cairo_ft_unscaled_font_t *unscaled) +{ + cairo_ft_unscaled_font_map_t *font_map; + FT_Face face = NULL; + FT_Error error; + + CAIRO_MUTEX_LOCK (unscaled->mutex); + unscaled->lock_count++; + + if (unscaled->face) + return unscaled->face; + + /* If this unscaled font was created from an FT_Face then we just + * returned it above. */ + assert (!unscaled->from_face); + + font_map = _cairo_ft_unscaled_font_map_lock (); + { + assert (font_map != NULL); + + while (font_map->num_open_faces >= MAX_OPEN_FACES) + { + cairo_ft_unscaled_font_t *entry; + + entry = _cairo_hash_table_random_entry (font_map->hash_table, + _has_unlocked_face); + if (entry == NULL) + break; + + _font_map_release_face_lock_held (font_map, entry); + } + } + _cairo_ft_unscaled_font_map_unlock (); + + error = FT_New_Face (font_map->ft_library, + unscaled->filename, + unscaled->id, + &face); + if (error) + { + unscaled->lock_count--; + CAIRO_MUTEX_UNLOCK (unscaled->mutex); + _cairo_error_throw (_ft_to_cairo_error (error)); + return NULL; + } + + unscaled->face = face; + + font_map->num_open_faces++; + + return face; +} + + +/* Unlock unscaled font locked with _cairo_ft_unscaled_font_lock_face + */ +static void +_cairo_ft_unscaled_font_unlock_face (cairo_ft_unscaled_font_t *unscaled) +{ + assert (unscaled->lock_count > 0); + + unscaled->lock_count--; + + CAIRO_MUTEX_UNLOCK (unscaled->mutex); +} + + +static cairo_status_t +_compute_transform (cairo_ft_font_transform_t *sf, + cairo_matrix_t *scale, + cairo_ft_unscaled_font_t *unscaled) +{ + cairo_status_t status; + double x_scale, y_scale; + cairo_matrix_t normalized = *scale; + + /* The font matrix has x and y "scale" components which we extract and + * use as character scale values. These influence the way freetype + * chooses hints, as well as selecting different bitmaps in + * hand-rendered fonts. We also copy the normalized matrix to + * freetype's transformation. + */ + + status = _cairo_matrix_compute_basis_scale_factors (scale, + &x_scale, &y_scale, + 1); + if (unlikely (status)) + return status; + + /* FreeType docs say this about x_scale and y_scale: + * "A character width or height smaller than 1pt is set to 1pt;" + * So, we cap them from below at 1.0 and let the FT transform + * take care of sub-1.0 scaling. */ + if (x_scale < 1.0) + x_scale = 1.0; + if (y_scale < 1.0) + y_scale = 1.0; + + if (unscaled && (unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) == 0) { + double min_distance = DBL_MAX; + cairo_bool_t magnify = TRUE; + int i; + double best_x_size = 0; + double best_y_size = 0; + + for (i = 0; i < unscaled->face->num_fixed_sizes; i++) { + double x_size = unscaled->face->available_sizes[i].x_ppem / 64.; + double y_size = unscaled->face->available_sizes[i].y_ppem / 64.; + double distance = y_size - y_scale; + + /* + * distance is positive if current strike is larger than desired + * size, and negative if smaller. + * + * We like to prefer down-scaling to upscaling. + */ + + if ((magnify && distance >= 0) || fabs (distance) <= min_distance) { + magnify = distance < 0; + min_distance = fabs (distance); + best_x_size = x_size; + best_y_size = y_size; + } + } + + x_scale = best_x_size; + y_scale = best_y_size; + } + + sf->x_scale = x_scale; + sf->y_scale = y_scale; + + cairo_matrix_scale (&normalized, 1.0 / x_scale, 1.0 / y_scale); + + _cairo_matrix_get_affine (&normalized, + &sf->shape[0][0], &sf->shape[0][1], + &sf->shape[1][0], &sf->shape[1][1], + NULL, NULL); + + return CAIRO_STATUS_SUCCESS; +} + +/* Temporarily scales an unscaled font to the give scale. We catch + * scaling to the same size, since changing a FT_Face is expensive. + */ +static cairo_status_t +_cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled, + cairo_matrix_t *scale) +{ + cairo_status_t status; + cairo_ft_font_transform_t sf; + FT_Matrix mat; + FT_Error error; + + assert (unscaled->face != NULL); + + if (unscaled->have_scale && + scale->xx == unscaled->current_scale.xx && + scale->yx == unscaled->current_scale.yx && + scale->xy == unscaled->current_scale.xy && + scale->yy == unscaled->current_scale.yy) + return CAIRO_STATUS_SUCCESS; + + unscaled->have_scale = TRUE; + unscaled->current_scale = *scale; + + status = _compute_transform (&sf, scale, unscaled); + if (unlikely (status)) + return status; + + unscaled->x_scale = sf.x_scale; + unscaled->y_scale = sf.y_scale; + + mat.xx = DOUBLE_TO_16_16(sf.shape[0][0]); + mat.yx = - DOUBLE_TO_16_16(sf.shape[0][1]); + mat.xy = - DOUBLE_TO_16_16(sf.shape[1][0]); + mat.yy = DOUBLE_TO_16_16(sf.shape[1][1]); + + unscaled->have_shape = (mat.xx != 0x10000 || + mat.yx != 0x00000 || + mat.xy != 0x00000 || + mat.yy != 0x10000); + + unscaled->Current_Shape = mat; + cairo_matrix_init (&unscaled->current_shape, + sf.shape[0][0], sf.shape[0][1], + sf.shape[1][0], sf.shape[1][1], + 0.0, 0.0); + + FT_Set_Transform(unscaled->face, &mat, NULL); + + error = FT_Set_Char_Size (unscaled->face, + sf.x_scale * 64.0 + .5, + sf.y_scale * 64.0 + .5, + 0, 0); + if (error) + return _cairo_error (_ft_to_cairo_error (error)); + + return CAIRO_STATUS_SUCCESS; +} + +/* we sometimes need to convert the glyph bitmap in a FT_GlyphSlot + * into a different format. For example, we want to convert a + * FT_PIXEL_MODE_LCD or FT_PIXEL_MODE_LCD_V bitmap into a 32-bit + * ARGB or ABGR bitmap. + * + * this function prepares a target descriptor for this operation. + * + * input :: target bitmap descriptor. The function will set its + * 'width', 'rows' and 'pitch' fields, and only these + * + * slot :: the glyph slot containing the source bitmap. this + * function assumes that slot->format == FT_GLYPH_FORMAT_BITMAP + * + * mode :: the requested final rendering mode. supported values are + * MONO, NORMAL (i.e. gray), LCD and LCD_V + * + * the function returns the size in bytes of the corresponding buffer, + * it's up to the caller to allocate the corresponding memory block + * before calling _fill_xrender_bitmap + * + * it also returns -1 in case of error (e.g. incompatible arguments, + * like trying to convert a gray bitmap into a monochrome one) + */ +static int +_compute_xrender_bitmap_size(FT_Bitmap *target, + FT_GlyphSlot slot, + FT_Render_Mode mode) +{ + FT_Bitmap *ftbit; + int width, height, pitch; + + if (slot->format != FT_GLYPH_FORMAT_BITMAP) + return -1; + + /* compute the size of the final bitmap */ + ftbit = &slot->bitmap; + + width = ftbit->width; + height = ftbit->rows; + pitch = (width + 3) & ~3; + + switch (ftbit->pixel_mode) { + case FT_PIXEL_MODE_MONO: + if (mode == FT_RENDER_MODE_MONO) { + pitch = (((width + 31) & ~31) >> 3); + break; + } + /* fall-through */ + + case FT_PIXEL_MODE_GRAY: + if (mode == FT_RENDER_MODE_LCD || + mode == FT_RENDER_MODE_LCD_V) + { + /* each pixel is replicated into a 32-bit ARGB value */ + pitch = width * 4; + } + break; + + case FT_PIXEL_MODE_LCD: + if (mode != FT_RENDER_MODE_LCD) + return -1; + + /* horz pixel triplets are packed into 32-bit ARGB values */ + width /= 3; + pitch = width * 4; + break; + + case FT_PIXEL_MODE_LCD_V: + if (mode != FT_RENDER_MODE_LCD_V) + return -1; + + /* vert pixel triplets are packed into 32-bit ARGB values */ + height /= 3; + pitch = width * 4; + break; + + default: /* unsupported source format */ + return -1; + } + + target->width = width; + target->rows = height; + target->pitch = pitch; + target->buffer = NULL; + + return pitch * height; +} + +/* this functions converts the glyph bitmap found in a FT_GlyphSlot + * into a different format (see _compute_xrender_bitmap_size) + * + * you should call this function after _compute_xrender_bitmap_size + * + * target :: target bitmap descriptor. Note that its 'buffer' pointer + * must point to memory allocated by the caller + * + * slot :: the glyph slot containing the source bitmap + * + * mode :: the requested final rendering mode + * + * bgr :: boolean, set if BGR or VBGR pixel ordering is needed + */ +static void +_fill_xrender_bitmap(FT_Bitmap *target, + FT_GlyphSlot slot, + FT_Render_Mode mode, + int bgr) +{ + FT_Bitmap *ftbit = &slot->bitmap; + unsigned char *srcLine = ftbit->buffer; + unsigned char *dstLine = target->buffer; + int src_pitch = ftbit->pitch; + int width = target->width; + int height = target->rows; + int pitch = target->pitch; + int subpixel; + int h; + + subpixel = (mode == FT_RENDER_MODE_LCD || + mode == FT_RENDER_MODE_LCD_V); + + if (src_pitch < 0) + srcLine -= src_pitch * (ftbit->rows - 1); + + target->pixel_mode = ftbit->pixel_mode; + + switch (ftbit->pixel_mode) { + case FT_PIXEL_MODE_MONO: + if (subpixel) { + /* convert mono to ARGB32 values */ + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { + int x; + + for (x = 0; x < width; x++) { + if (srcLine[(x >> 3)] & (0x80 >> (x & 7))) + ((unsigned int *) dstLine)[x] = 0xffffffffU; + } + } + target->pixel_mode = FT_PIXEL_MODE_LCD; + + } else if (mode == FT_RENDER_MODE_NORMAL) { + /* convert mono to 8-bit gray */ + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { + int x; + + for (x = 0; x < width; x++) { + if (srcLine[(x >> 3)] & (0x80 >> (x & 7))) + dstLine[x] = 0xff; + } + } + target->pixel_mode = FT_PIXEL_MODE_GRAY; + + } else { + /* copy mono to mono */ + + int bytes = (width + 7) >> 3; + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) + memcpy (dstLine, srcLine, bytes); + } + break; + + case FT_PIXEL_MODE_GRAY: + if (subpixel) { + /* convert gray to ARGB32 values */ + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { + int x; + unsigned int *dst = (unsigned int *) dstLine; + + for (x = 0; x < width; x++) { + unsigned int pix = srcLine[x]; + + pix |= (pix << 8); + pix |= (pix << 16); + + dst[x] = pix; + } + } + target->pixel_mode = FT_PIXEL_MODE_LCD; + } else { + /* copy gray into gray */ + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) + memcpy (dstLine, srcLine, width); + } + break; + + case FT_PIXEL_MODE_LCD: + if (!bgr) { + /* convert horizontal RGB into ARGB32 */ + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { + int x; + unsigned char *src = srcLine; + unsigned int *dst = (unsigned int *) dstLine; + + for (x = 0; x < width; x++, src += 3) { + unsigned int pix; + + pix = ((unsigned int)src[0] << 16) | + ((unsigned int)src[1] << 8) | + ((unsigned int)src[2] ) | + ((unsigned int)src[1] << 24) ; + + dst[x] = pix; + } + } + } else { + /* convert horizontal BGR into ARGB32 */ + + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) { + + int x; + unsigned char *src = srcLine; + unsigned int *dst = (unsigned int *) dstLine; + + for (x = 0; x < width; x++, src += 3) { + unsigned int pix; + + pix = ((unsigned int)src[2] << 16) | + ((unsigned int)src[1] << 8) | + ((unsigned int)src[0] ) | + ((unsigned int)src[1] << 24) ; + + dst[x] = pix; + } + } + } + break; + + default: /* FT_PIXEL_MODE_LCD_V */ + /* convert vertical RGB into ARGB32 */ + if (!bgr) { + + for (h = height; h > 0; h--, srcLine += 3 * src_pitch, dstLine += pitch) { + int x; + unsigned char* src = srcLine; + unsigned int* dst = (unsigned int *) dstLine; + + for (x = 0; x < width; x++, src += 1) { + unsigned int pix; + pix = ((unsigned int)src[0] << 16) | + ((unsigned int)src[src_pitch] << 8) | + ((unsigned int)src[src_pitch*2] ) | + ((unsigned int)src[src_pitch] << 24) ; + dst[x] = pix; + } + } + } else { + + for (h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch) { + int x; + unsigned char *src = srcLine; + unsigned int *dst = (unsigned int *) dstLine; + + for (x = 0; x < width; x++, src += 1) { + unsigned int pix; + + pix = ((unsigned int)src[src_pitch * 2] << 16) | + ((unsigned int)src[src_pitch] << 8) | + ((unsigned int)src[0] ) | + ((unsigned int)src[src_pitch] << 24) ; + + dst[x] = pix; + } + } + } + } +} + + +/* Fills in val->image with an image surface created from @bitmap + */ +static cairo_status_t +_get_bitmap_surface (FT_Bitmap *bitmap, + FT_Library library, + cairo_bool_t own_buffer, + cairo_font_options_t *font_options, + cairo_image_surface_t **surface) +{ + unsigned int width, height; + unsigned char *data; + int format = CAIRO_FORMAT_A8; + int stride; + cairo_image_surface_t *image; + cairo_bool_t component_alpha = FALSE; + + width = bitmap->width; + height = bitmap->rows; + + if (width == 0 || height == 0) { + *surface = (cairo_image_surface_t *) + cairo_image_surface_create_for_data (NULL, format, 0, 0, 0); + return (*surface)->base.status; + } + + switch (bitmap->pixel_mode) { + case FT_PIXEL_MODE_MONO: + stride = (((width + 31) & ~31) >> 3); + if (own_buffer) { + data = bitmap->buffer; + assert (stride == bitmap->pitch); + } else { + data = _cairo_malloc_ab (height, stride); + if (!data) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (stride == bitmap->pitch) { + memcpy (data, bitmap->buffer, stride * height); + } else { + int i; + unsigned char *source, *dest; + + source = bitmap->buffer; + dest = data; + for (i = height; i; i--) { + memcpy (dest, source, bitmap->pitch); + memset (dest + bitmap->pitch, '\0', stride - bitmap->pitch); + + source += bitmap->pitch; + dest += stride; + } + } + } + +#ifndef WORDS_BIGENDIAN + { + uint8_t *d = data; + int count = stride * height; + + while (count--) { + *d = CAIRO_BITSWAP8 (*d); + d++; + } + } +#endif + format = CAIRO_FORMAT_A1; + break; + + case FT_PIXEL_MODE_LCD: + case FT_PIXEL_MODE_LCD_V: + case FT_PIXEL_MODE_GRAY: + if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL || + bitmap->pixel_mode == FT_PIXEL_MODE_GRAY) + { + stride = bitmap->pitch; + + /* We don't support stride not multiple of 4. */ + if (stride & 3) + { + assert (!own_buffer); + goto convert; + } + + if (own_buffer) { + data = bitmap->buffer; + } else { + data = _cairo_malloc_ab (height, stride); + if (!data) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (data, bitmap->buffer, stride * height); + } + + format = CAIRO_FORMAT_A8; + } else { + data = bitmap->buffer; + stride = bitmap->pitch; + format = CAIRO_FORMAT_ARGB32; + component_alpha = TRUE; + } + break; +#ifdef FT_LOAD_COLOR + case FT_PIXEL_MODE_BGRA: + stride = width * 4; + if (own_buffer) { + data = bitmap->buffer; + } else { + data = _cairo_malloc_ab (height, stride); + if (!data) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (data, bitmap->buffer, stride * height); + } + format = CAIRO_FORMAT_ARGB32; + break; +#endif + case FT_PIXEL_MODE_GRAY2: + case FT_PIXEL_MODE_GRAY4: + convert: + if (!own_buffer && library) + { + /* This is pretty much the only case that we can get in here. */ + /* Convert to 8bit grayscale. */ + + FT_Bitmap tmp; + FT_Int align; + FT_Error error; + + format = CAIRO_FORMAT_A8; + + align = cairo_format_stride_for_width (format, bitmap->width); + + FT_Bitmap_New( &tmp ); + + error = FT_Bitmap_Convert( library, bitmap, &tmp, align ); + if (error) + return _cairo_error (_ft_to_cairo_error (error)); + + FT_Bitmap_Done( library, bitmap ); + *bitmap = tmp; + + stride = bitmap->pitch; + data = _cairo_malloc_ab (height, stride); + if (!data) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (bitmap->num_grays != 256) + { + unsigned int x, y; + unsigned int mul = 255 / (bitmap->num_grays - 1); + FT_Byte *p = bitmap->buffer; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) + p[x] *= mul; + p += bitmap->pitch; + } + } + + memcpy (data, bitmap->buffer, stride * height); + break; + } + /* These could be triggered by very rare types of TrueType fonts */ + default: + if (own_buffer) + free (bitmap->buffer); + return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + } + + /* XXX */ + *surface = image = (cairo_image_surface_t *) + cairo_image_surface_create_for_data (data, + format, + width, height, stride); + if (image->base.status) { + free (data); + return (*surface)->base.status; + } + + if (component_alpha) + pixman_image_set_component_alpha (image->pixman_image, TRUE); + + _cairo_image_surface_assume_ownership_of_data (image); + + _cairo_debug_check_image_surface_is_defined (&image->base); + + return CAIRO_STATUS_SUCCESS; +} + +/* Converts an outline FT_GlyphSlot into an image + * + * This could go through _render_glyph_bitmap as well, letting + * FreeType convert the outline to a bitmap, but doing it ourselves + * has two minor advantages: first, we save a copy of the bitmap + * buffer: we can directly use the buffer that FreeType renders + * into. + * + * Second, it may help when we add support for subpixel + * rendering: the Xft code does it this way. (Keith thinks that + * it may also be possible to get the subpixel rendering with + * FT_Render_Glyph: something worth looking into in more detail + * when we add subpixel support. If so, we may want to eliminate + * this version of the code path entirely. + */ +static cairo_status_t +_render_glyph_outline (FT_Face face, + cairo_font_options_t *font_options, + cairo_image_surface_t **surface) +{ + int rgba = FC_RGBA_UNKNOWN; + int lcd_filter = FT_LCD_FILTER_LEGACY; + FT_GlyphSlot glyphslot = face->glyph; + FT_Outline *outline = &glyphslot->outline; + FT_Bitmap bitmap; + FT_BBox cbox; + unsigned int width, height; + cairo_status_t status; + FT_Error error; + FT_Library library = glyphslot->library; + FT_Render_Mode render_mode = FT_RENDER_MODE_NORMAL; + + switch (font_options->antialias) { + case CAIRO_ANTIALIAS_NONE: + render_mode = FT_RENDER_MODE_MONO; + break; + + case CAIRO_ANTIALIAS_SUBPIXEL: + case CAIRO_ANTIALIAS_BEST: + switch (font_options->subpixel_order) { + case CAIRO_SUBPIXEL_ORDER_DEFAULT: + case CAIRO_SUBPIXEL_ORDER_RGB: + case CAIRO_SUBPIXEL_ORDER_BGR: + render_mode = FT_RENDER_MODE_LCD; + break; + + case CAIRO_SUBPIXEL_ORDER_VRGB: + case CAIRO_SUBPIXEL_ORDER_VBGR: + render_mode = FT_RENDER_MODE_LCD_V; + break; + } + + switch (font_options->lcd_filter) { + case CAIRO_LCD_FILTER_NONE: + lcd_filter = FT_LCD_FILTER_NONE; + break; + case CAIRO_LCD_FILTER_DEFAULT: + case CAIRO_LCD_FILTER_INTRA_PIXEL: + lcd_filter = FT_LCD_FILTER_LEGACY; + break; + case CAIRO_LCD_FILTER_FIR3: + lcd_filter = FT_LCD_FILTER_LIGHT; + break; + case CAIRO_LCD_FILTER_FIR5: + lcd_filter = FT_LCD_FILTER_DEFAULT; + break; + } + + break; + + case CAIRO_ANTIALIAS_DEFAULT: + case CAIRO_ANTIALIAS_GRAY: + case CAIRO_ANTIALIAS_GOOD: + case CAIRO_ANTIALIAS_FAST: + render_mode = FT_RENDER_MODE_NORMAL; + } + + FT_Outline_Get_CBox (outline, &cbox); + + cbox.xMin &= -64; + cbox.yMin &= -64; + cbox.xMax = (cbox.xMax + 63) & -64; + cbox.yMax = (cbox.yMax + 63) & -64; + + width = (unsigned int) ((cbox.xMax - cbox.xMin) >> 6); + height = (unsigned int) ((cbox.yMax - cbox.yMin) >> 6); + + if (width * height == 0) { + cairo_format_t format; + /* Looks like fb handles zero-sized images just fine */ + switch (render_mode) { + case FT_RENDER_MODE_MONO: + format = CAIRO_FORMAT_A1; + break; + case FT_RENDER_MODE_LCD: + case FT_RENDER_MODE_LCD_V: + format= CAIRO_FORMAT_ARGB32; + break; + case FT_RENDER_MODE_LIGHT: + case FT_RENDER_MODE_NORMAL: + case FT_RENDER_MODE_MAX: + default: + format = CAIRO_FORMAT_A8; + break; + } + + (*surface) = (cairo_image_surface_t *) + cairo_image_surface_create_for_data (NULL, format, 0, 0, 0); + if ((*surface)->base.status) + return (*surface)->base.status; + } else { + + int bitmap_size; + + switch (render_mode) { + case FT_RENDER_MODE_LCD: + if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_BGR) + rgba = FC_RGBA_BGR; + else + rgba = FC_RGBA_RGB; + break; + + case FT_RENDER_MODE_LCD_V: + if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_VBGR) + rgba = FC_RGBA_VBGR; + else + rgba = FC_RGBA_VRGB; + break; + + case FT_RENDER_MODE_MONO: + case FT_RENDER_MODE_LIGHT: + case FT_RENDER_MODE_NORMAL: + case FT_RENDER_MODE_MAX: + default: + break; + } + +#if HAVE_FT_LIBRARY_SETLCDFILTER + FT_Library_SetLcdFilter (library, lcd_filter); +#endif + + error = FT_Render_Glyph (face->glyph, render_mode); + +#if HAVE_FT_LIBRARY_SETLCDFILTER + FT_Library_SetLcdFilter (library, FT_LCD_FILTER_NONE); +#endif + + if (error) + return _cairo_error (_ft_to_cairo_error (error)); + + bitmap_size = _compute_xrender_bitmap_size (&bitmap, + face->glyph, + render_mode); + if (bitmap_size < 0) + return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + + bitmap.buffer = calloc (1, bitmap_size); + if (bitmap.buffer == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _fill_xrender_bitmap (&bitmap, face->glyph, render_mode, + (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR)); + + /* Note: + * _get_bitmap_surface will free bitmap.buffer if there is an error + */ + status = _get_bitmap_surface (&bitmap, NULL, TRUE, font_options, surface); + if (unlikely (status)) + return status; + + /* Note: the font's coordinate system is upside down from ours, so the + * Y coordinate of the control box needs to be negated. Moreover, device + * offsets are position of glyph origin relative to top left while xMin + * and yMax are offsets of top left relative to origin. Another negation. + */ + cairo_surface_set_device_offset (&(*surface)->base, + (double)-glyphslot->bitmap_left, + (double)+glyphslot->bitmap_top); + } + + return CAIRO_STATUS_SUCCESS; +} + +/* Converts a bitmap (or other) FT_GlyphSlot into an image */ +static cairo_status_t +_render_glyph_bitmap (FT_Face face, + cairo_font_options_t *font_options, + cairo_image_surface_t **surface) +{ + FT_GlyphSlot glyphslot = face->glyph; + cairo_status_t status; + FT_Error error; + + /* According to the FreeType docs, glyphslot->format could be + * something other than FT_GLYPH_FORMAT_OUTLINE or + * FT_GLYPH_FORMAT_BITMAP. Calling FT_Render_Glyph gives FreeType + * the opportunity to convert such to + * bitmap. FT_GLYPH_FORMAT_COMPOSITE will not be encountered since + * we avoid the FT_LOAD_NO_RECURSE flag. + */ + error = FT_Render_Glyph (glyphslot, FT_RENDER_MODE_NORMAL); + /* XXX ignoring all other errors for now. They are not fatal, typically + * just a glyph-not-found. */ + if (error == FT_Err_Out_Of_Memory) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _get_bitmap_surface (&glyphslot->bitmap, + glyphslot->library, + FALSE, font_options, + surface); + if (unlikely (status)) + return status; + + /* + * Note: the font's coordinate system is upside down from ours, so the + * Y coordinate of the control box needs to be negated. Moreover, device + * offsets are position of glyph origin relative to top left while + * bitmap_left and bitmap_top are offsets of top left relative to origin. + * Another negation. + */ + cairo_surface_set_device_offset (&(*surface)->base, + -glyphslot->bitmap_left, + +glyphslot->bitmap_top); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_transform_glyph_bitmap (cairo_matrix_t * shape, + cairo_image_surface_t ** surface) +{ + cairo_matrix_t original_to_transformed; + cairo_matrix_t transformed_to_original; + cairo_image_surface_t *old_image; + cairo_surface_t *image; + double x[4], y[4]; + double origin_x, origin_y; + int orig_width, orig_height; + int i; + int x_min, y_min, x_max, y_max; + int width, height; + cairo_status_t status; + cairo_surface_pattern_t pattern; + + /* We want to compute a transform that takes the origin + * (device_x_offset, device_y_offset) to 0,0, then applies + * the "shape" portion of the font transform + */ + original_to_transformed = *shape; + + cairo_surface_get_device_offset (&(*surface)->base, &origin_x, &origin_y); + orig_width = (*surface)->width; + orig_height = (*surface)->height; + + cairo_matrix_translate (&original_to_transformed, + -origin_x, -origin_y); + + /* Find the bounding box of the original bitmap under that + * transform + */ + x[0] = 0; y[0] = 0; + x[1] = orig_width; y[1] = 0; + x[2] = orig_width; y[2] = orig_height; + x[3] = 0; y[3] = orig_height; + + for (i = 0; i < 4; i++) + cairo_matrix_transform_point (&original_to_transformed, + &x[i], &y[i]); + + x_min = floor (x[0]); y_min = floor (y[0]); + x_max = ceil (x[0]); y_max = ceil (y[0]); + + for (i = 1; i < 4; i++) { + if (x[i] < x_min) + x_min = floor (x[i]); + else if (x[i] > x_max) + x_max = ceil (x[i]); + if (y[i] < y_min) + y_min = floor (y[i]); + else if (y[i] > y_max) + y_max = ceil (y[i]); + } + + /* Adjust the transform so that the bounding box starts at 0,0 ... + * this gives our final transform from original bitmap to transformed + * bitmap. + */ + original_to_transformed.x0 -= x_min; + original_to_transformed.y0 -= y_min; + + /* Create the transformed bitmap */ + width = x_max - x_min; + height = y_max - y_min; + + transformed_to_original = original_to_transformed; + status = cairo_matrix_invert (&transformed_to_original); + if (unlikely (status)) + return status; + + if ((*surface)->format == CAIRO_FORMAT_ARGB32 && + !pixman_image_get_component_alpha ((*surface)->pixman_image)) + image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + else + image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height); + if (unlikely (image->status)) + return image->status; + + /* Draw the original bitmap transformed into the new bitmap + */ + _cairo_pattern_init_for_surface (&pattern, &(*surface)->base); + cairo_pattern_set_matrix (&pattern.base, &transformed_to_original); + + status = _cairo_surface_paint (image, + CAIRO_OPERATOR_SOURCE, + &pattern.base, + NULL); + + _cairo_pattern_fini (&pattern.base); + + if (unlikely (status)) { + cairo_surface_destroy (image); + return status; + } + + /* Now update the cache entry for the new bitmap, recomputing + * the origin based on the final transform. + */ + cairo_matrix_transform_point (&original_to_transformed, + &origin_x, &origin_y); + + old_image = (*surface); + (*surface) = (cairo_image_surface_t *)image; + cairo_surface_destroy (&old_image->base); + + cairo_surface_set_device_offset (&(*surface)->base, + _cairo_lround (origin_x), + _cairo_lround (origin_y)); + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend = { + _cairo_ft_unscaled_font_destroy, +#if 0 + _cairo_ft_unscaled_font_create_glyph +#endif +}; + +/* #cairo_ft_scaled_font_t */ + +typedef struct _cairo_ft_scaled_font { + cairo_scaled_font_t base; + cairo_ft_unscaled_font_t *unscaled; + cairo_ft_options_t ft_options; +} cairo_ft_scaled_font_t; + +static const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend; + +#if CAIRO_HAS_FC_FONT +/* The load flags passed to FT_Load_Glyph control aspects like hinting and + * antialiasing. Here we compute them from the fields of a FcPattern. + */ +static void +_get_pattern_ft_options (FcPattern *pattern, cairo_ft_options_t *ret) +{ + FcBool antialias, vertical_layout, hinting, autohint, bitmap, embolden; + cairo_ft_options_t ft_options; + int rgba; +#ifdef FC_HINT_STYLE + int hintstyle; +#endif + + _cairo_font_options_init_default (&ft_options.base); + ft_options.load_flags = FT_LOAD_DEFAULT; + ft_options.synth_flags = 0; + +#ifndef FC_EMBEDDED_BITMAP +#define FC_EMBEDDED_BITMAP "embeddedbitmap" +#endif + + /* Check whether to force use of embedded bitmaps */ + if (FcPatternGetBool (pattern, + FC_EMBEDDED_BITMAP, 0, &bitmap) != FcResultMatch) + bitmap = FcFalse; + + /* disable antialiasing if requested */ + if (FcPatternGetBool (pattern, + FC_ANTIALIAS, 0, &antialias) != FcResultMatch) + antialias = FcTrue; + + if (antialias) { + cairo_subpixel_order_t subpixel_order; + int lcd_filter; + + /* disable hinting if requested */ + if (FcPatternGetBool (pattern, + FC_HINTING, 0, &hinting) != FcResultMatch) + hinting = FcTrue; + + if (FcPatternGetInteger (pattern, + FC_RGBA, 0, &rgba) != FcResultMatch) + rgba = FC_RGBA_UNKNOWN; + + switch (rgba) { + case FC_RGBA_RGB: + subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; + break; + case FC_RGBA_BGR: + subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; + break; + case FC_RGBA_VRGB: + subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; + break; + case FC_RGBA_VBGR: + subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; + break; + case FC_RGBA_UNKNOWN: + case FC_RGBA_NONE: + default: + subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + break; + } + + if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) { + ft_options.base.subpixel_order = subpixel_order; + ft_options.base.antialias = CAIRO_ANTIALIAS_SUBPIXEL; + } + + if (FcPatternGetInteger (pattern, + FC_LCD_FILTER, 0, &lcd_filter) == FcResultMatch) + { + switch (lcd_filter) { + case FC_LCD_NONE: + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_NONE; + break; + case FC_LCD_DEFAULT: + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR5; + break; + case FC_LCD_LIGHT: + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR3; + break; + case FC_LCD_LEGACY: + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL; + break; + } + } + +#ifdef FC_HINT_STYLE + if (FcPatternGetInteger (pattern, + FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch) + hintstyle = FC_HINT_FULL; + + if (!hinting) + hintstyle = FC_HINT_NONE; + + switch (hintstyle) { + case FC_HINT_NONE: + ft_options.base.hint_style = CAIRO_HINT_STYLE_NONE; + break; + case FC_HINT_SLIGHT: + ft_options.base.hint_style = CAIRO_HINT_STYLE_SLIGHT; + break; + case FC_HINT_MEDIUM: + default: + ft_options.base.hint_style = CAIRO_HINT_STYLE_MEDIUM; + break; + case FC_HINT_FULL: + ft_options.base.hint_style = CAIRO_HINT_STYLE_FULL; + break; + } +#else /* !FC_HINT_STYLE */ + if (!hinting) { + ft_options.base.hint_style = CAIRO_HINT_STYLE_NONE; + } +#endif /* FC_HINT_STYLE */ + + /* Force embedded bitmaps off if no hinting requested */ + if (ft_options.base.hint_style == CAIRO_HINT_STYLE_NONE) + bitmap = FcFalse; + + if (!bitmap) + ft_options.load_flags |= FT_LOAD_NO_BITMAP; + + } else { + ft_options.base.antialias = CAIRO_ANTIALIAS_NONE; + } + + /* force autohinting if requested */ + if (FcPatternGetBool (pattern, + FC_AUTOHINT, 0, &autohint) != FcResultMatch) + autohint = FcFalse; + + if (autohint) + ft_options.load_flags |= FT_LOAD_FORCE_AUTOHINT; + + if (FcPatternGetBool (pattern, + FC_VERTICAL_LAYOUT, 0, &vertical_layout) != FcResultMatch) + vertical_layout = FcFalse; + + if (vertical_layout) + ft_options.load_flags |= FT_LOAD_VERTICAL_LAYOUT; + +#ifndef FC_EMBOLDEN +#define FC_EMBOLDEN "embolden" +#endif + if (FcPatternGetBool (pattern, + FC_EMBOLDEN, 0, &embolden) != FcResultMatch) + embolden = FcFalse; + + if (embolden) + ft_options.synth_flags |= CAIRO_FT_SYNTHESIZE_BOLD; + + *ret = ft_options; +} +#endif + +static void +_cairo_ft_options_merge (cairo_ft_options_t *options, + cairo_ft_options_t *other) +{ + int load_flags = other->load_flags; + int load_target = FT_LOAD_TARGET_NORMAL; + + /* clear load target mode */ + load_flags &= ~(FT_LOAD_TARGET_(FT_LOAD_TARGET_MODE(other->load_flags))); + + if (load_flags & FT_LOAD_NO_HINTING) + other->base.hint_style = CAIRO_HINT_STYLE_NONE; + + if (other->base.antialias == CAIRO_ANTIALIAS_NONE || + options->base.antialias == CAIRO_ANTIALIAS_NONE) { + options->base.antialias = CAIRO_ANTIALIAS_NONE; + options->base.subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + } + + if (other->base.antialias == CAIRO_ANTIALIAS_SUBPIXEL && + (options->base.antialias == CAIRO_ANTIALIAS_DEFAULT || + options->base.antialias == CAIRO_ANTIALIAS_GRAY)) { + options->base.antialias = CAIRO_ANTIALIAS_SUBPIXEL; + options->base.subpixel_order = other->base.subpixel_order; + } + + if (options->base.hint_style == CAIRO_HINT_STYLE_DEFAULT) + options->base.hint_style = other->base.hint_style; + + if (other->base.hint_style == CAIRO_HINT_STYLE_NONE) + options->base.hint_style = CAIRO_HINT_STYLE_NONE; + + if (options->base.lcd_filter == CAIRO_LCD_FILTER_DEFAULT) + options->base.lcd_filter = other->base.lcd_filter; + + if (other->base.lcd_filter == CAIRO_LCD_FILTER_NONE) + options->base.lcd_filter = CAIRO_LCD_FILTER_NONE; + + if (options->base.antialias == CAIRO_ANTIALIAS_NONE) { + if (options->base.hint_style == CAIRO_HINT_STYLE_NONE) + load_flags |= FT_LOAD_NO_HINTING; + else + load_target = FT_LOAD_TARGET_MONO; + load_flags |= FT_LOAD_MONOCHROME; + } else { + switch (options->base.hint_style) { + case CAIRO_HINT_STYLE_NONE: + load_flags |= FT_LOAD_NO_HINTING; + break; + case CAIRO_HINT_STYLE_SLIGHT: + load_target = FT_LOAD_TARGET_LIGHT; + break; + case CAIRO_HINT_STYLE_MEDIUM: + break; + case CAIRO_HINT_STYLE_FULL: + case CAIRO_HINT_STYLE_DEFAULT: + if (options->base.antialias == CAIRO_ANTIALIAS_SUBPIXEL) { + switch (options->base.subpixel_order) { + case CAIRO_SUBPIXEL_ORDER_DEFAULT: + case CAIRO_SUBPIXEL_ORDER_RGB: + case CAIRO_SUBPIXEL_ORDER_BGR: + load_target = FT_LOAD_TARGET_LCD; + break; + case CAIRO_SUBPIXEL_ORDER_VRGB: + case CAIRO_SUBPIXEL_ORDER_VBGR: + load_target = FT_LOAD_TARGET_LCD_V; + break; + } + } + break; + } + } + + options->load_flags = load_flags | load_target; + options->synth_flags = other->synth_flags; +} + +static cairo_status_t +_cairo_ft_font_face_scaled_font_create (void *abstract_font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + cairo_scaled_font_t **font_out) +{ + cairo_ft_font_face_t *font_face = abstract_font_face; + cairo_ft_scaled_font_t *scaled_font; + FT_Face face; + FT_Size_Metrics *metrics; + cairo_font_extents_t fs_metrics; + cairo_status_t status; + cairo_ft_unscaled_font_t *unscaled; + + assert (font_face->unscaled); + + face = _cairo_ft_unscaled_font_lock_face (font_face->unscaled); + if (unlikely (face == NULL)) /* backend error */ + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + scaled_font = malloc (sizeof (cairo_ft_scaled_font_t)); + if (unlikely (scaled_font == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FAIL; + } + + scaled_font->unscaled = unscaled = font_face->unscaled; + _cairo_unscaled_font_reference (&unscaled->base); + + _cairo_font_options_init_copy (&scaled_font->ft_options.base, options); + _cairo_ft_options_merge (&scaled_font->ft_options, &font_face->ft_options); + + status = _cairo_scaled_font_init (&scaled_font->base, + &font_face->base, + font_matrix, ctm, options, + &_cairo_ft_scaled_font_backend); + if (unlikely (status)) + goto CLEANUP_SCALED_FONT; + + status = _cairo_ft_unscaled_font_set_scale (unscaled, + &scaled_font->base.scale); + if (unlikely (status)) { + /* This can only fail if we encounter an error with the underlying + * font, so propagate the error back to the font-face. */ + _cairo_ft_unscaled_font_unlock_face (unscaled); + _cairo_unscaled_font_destroy (&unscaled->base); + free (scaled_font); + return status; + } + + + metrics = &face->size->metrics; + + /* + * Get to unscaled metrics so that the upper level can get back to + * user space + * + * Also use this path for bitmap-only fonts. The other branch uses + * face members that are only relevant for scalable fonts. This is + * detected by simply checking for units_per_EM==0. + */ + if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF || + face->units_per_EM == 0) { + double x_factor, y_factor; + + if (unscaled->x_scale == 0) + x_factor = 0; + else + x_factor = 1 / unscaled->x_scale; + + if (unscaled->y_scale == 0) + y_factor = 0; + else + y_factor = 1 / unscaled->y_scale; + + fs_metrics.ascent = DOUBLE_FROM_26_6(metrics->ascender) * y_factor; + fs_metrics.descent = DOUBLE_FROM_26_6(- metrics->descender) * y_factor; + fs_metrics.height = DOUBLE_FROM_26_6(metrics->height) * y_factor; + if (!_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) { + fs_metrics.max_x_advance = DOUBLE_FROM_26_6(metrics->max_advance) * x_factor; + fs_metrics.max_y_advance = 0; + } else { + fs_metrics.max_x_advance = 0; + fs_metrics.max_y_advance = DOUBLE_FROM_26_6(metrics->max_advance) * y_factor; + } + } else { + double scale = face->units_per_EM; + + fs_metrics.ascent = face->ascender / scale; + fs_metrics.descent = - face->descender / scale; + fs_metrics.height = face->height / scale; + if (!_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) { + fs_metrics.max_x_advance = face->max_advance_width / scale; + fs_metrics.max_y_advance = 0; + } else { + fs_metrics.max_x_advance = 0; + fs_metrics.max_y_advance = face->max_advance_height / scale; + } + } + + status = _cairo_scaled_font_set_metrics (&scaled_font->base, &fs_metrics); + if (unlikely (status)) + goto CLEANUP_SCALED_FONT; + + _cairo_ft_unscaled_font_unlock_face (unscaled); + + *font_out = &scaled_font->base; + return CAIRO_STATUS_SUCCESS; + + CLEANUP_SCALED_FONT: + _cairo_unscaled_font_destroy (&unscaled->base); + free (scaled_font); + FAIL: + _cairo_ft_unscaled_font_unlock_face (font_face->unscaled); + *font_out = _cairo_scaled_font_create_in_error (status); + return CAIRO_STATUS_SUCCESS; /* non-backend error */ +} + +cairo_bool_t +_cairo_scaled_font_is_ft (cairo_scaled_font_t *scaled_font) +{ + return scaled_font->backend == &_cairo_ft_scaled_font_backend; +} + +static void +_cairo_ft_scaled_font_fini (void *abstract_font) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + + if (scaled_font == NULL) + return; + + _cairo_unscaled_font_destroy (&scaled_font->unscaled->base); +} + +static int +_move_to (FT_Vector *to, void *closure) +{ + cairo_path_fixed_t *path = closure; + cairo_fixed_t x, y; + + x = _cairo_fixed_from_26_6 (to->x); + y = _cairo_fixed_from_26_6 (to->y); + + if (_cairo_path_fixed_close_path (path) != CAIRO_STATUS_SUCCESS) + return 1; + if (_cairo_path_fixed_move_to (path, x, y) != CAIRO_STATUS_SUCCESS) + return 1; + + return 0; +} + +static int +_line_to (FT_Vector *to, void *closure) +{ + cairo_path_fixed_t *path = closure; + cairo_fixed_t x, y; + + x = _cairo_fixed_from_26_6 (to->x); + y = _cairo_fixed_from_26_6 (to->y); + + if (_cairo_path_fixed_line_to (path, x, y) != CAIRO_STATUS_SUCCESS) + return 1; + + return 0; +} + +static int +_conic_to (FT_Vector *control, FT_Vector *to, void *closure) +{ + cairo_path_fixed_t *path = closure; + + cairo_fixed_t x0, y0; + cairo_fixed_t x1, y1; + cairo_fixed_t x2, y2; + cairo_fixed_t x3, y3; + cairo_point_t conic; + + if (! _cairo_path_fixed_get_current_point (path, &x0, &y0)) + return 1; + + conic.x = _cairo_fixed_from_26_6 (control->x); + conic.y = _cairo_fixed_from_26_6 (control->y); + + x3 = _cairo_fixed_from_26_6 (to->x); + y3 = _cairo_fixed_from_26_6 (to->y); + + x1 = x0 + 2.0/3.0 * (conic.x - x0); + y1 = y0 + 2.0/3.0 * (conic.y - y0); + + x2 = x3 + 2.0/3.0 * (conic.x - x3); + y2 = y3 + 2.0/3.0 * (conic.y - y3); + + if (_cairo_path_fixed_curve_to (path, + x1, y1, + x2, y2, + x3, y3) != CAIRO_STATUS_SUCCESS) + return 1; + + return 0; +} + +static int +_cubic_to (FT_Vector *control1, FT_Vector *control2, + FT_Vector *to, void *closure) +{ + cairo_path_fixed_t *path = closure; + cairo_fixed_t x0, y0; + cairo_fixed_t x1, y1; + cairo_fixed_t x2, y2; + + x0 = _cairo_fixed_from_26_6 (control1->x); + y0 = _cairo_fixed_from_26_6 (control1->y); + + x1 = _cairo_fixed_from_26_6 (control2->x); + y1 = _cairo_fixed_from_26_6 (control2->y); + + x2 = _cairo_fixed_from_26_6 (to->x); + y2 = _cairo_fixed_from_26_6 (to->y); + + if (_cairo_path_fixed_curve_to (path, + x0, y0, + x1, y1, + x2, y2) != CAIRO_STATUS_SUCCESS) + return 1; + + return 0; +} + +static cairo_status_t +_decompose_glyph_outline (FT_Face face, + cairo_font_options_t *options, + cairo_path_fixed_t **pathp) +{ + static const FT_Outline_Funcs outline_funcs = { + (FT_Outline_MoveToFunc)_move_to, + (FT_Outline_LineToFunc)_line_to, + (FT_Outline_ConicToFunc)_conic_to, + (FT_Outline_CubicToFunc)_cubic_to, + 0, /* shift */ + 0, /* delta */ + }; + static const FT_Matrix invert_y = { + DOUBLE_TO_16_16 (1.0), 0, + 0, DOUBLE_TO_16_16 (-1.0), + }; + + FT_GlyphSlot glyph; + cairo_path_fixed_t *path; + cairo_status_t status; + + path = _cairo_path_fixed_create (); + if (!path) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + glyph = face->glyph; + + /* Font glyphs have an inverted Y axis compared to cairo. */ + FT_Outline_Transform (&glyph->outline, &invert_y); + if (FT_Outline_Decompose (&glyph->outline, &outline_funcs, path)) { + _cairo_path_fixed_destroy (path); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + status = _cairo_path_fixed_close_path (path); + if (unlikely (status)) { + _cairo_path_fixed_destroy (path); + return status; + } + + *pathp = path; + + return CAIRO_STATUS_SUCCESS; +} + +/* + * Translate glyph to match its metrics. + */ +static void +_cairo_ft_scaled_glyph_vertical_layout_bearing_fix (void *abstract_font, + FT_GlyphSlot glyph) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + FT_Vector vector; + + vector.x = glyph->metrics.vertBearingX - glyph->metrics.horiBearingX; + vector.y = -glyph->metrics.vertBearingY - glyph->metrics.horiBearingY; + + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { + FT_Vector_Transform (&vector, &scaled_font->unscaled->Current_Shape); + FT_Outline_Translate(&glyph->outline, vector.x, vector.y); + } else if (glyph->format == FT_GLYPH_FORMAT_BITMAP) { + glyph->bitmap_left += vector.x / 64; + glyph->bitmap_top += vector.y / 64; + } +} + +static cairo_int_status_t +_cairo_ft_scaled_glyph_init (void *abstract_font, + cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_glyph_info_t info) +{ + cairo_text_extents_t fs_metrics; + cairo_ft_scaled_font_t *scaled_font = abstract_font; + cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; + FT_GlyphSlot glyph; + FT_Face face; + FT_Error error; + int load_flags = scaled_font->ft_options.load_flags; + FT_Glyph_Metrics *metrics; + double x_factor, y_factor; + cairo_bool_t vertical_layout = FALSE; + cairo_status_t status; + + face = _cairo_ft_unscaled_font_lock_face (unscaled); + if (!face) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled, + &scaled_font->base.scale); + if (unlikely (status)) + goto FAIL; + + /* Ignore global advance unconditionally */ + load_flags |= FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH; + + if ((info & CAIRO_SCALED_GLYPH_INFO_PATH) != 0 && + (info & CAIRO_SCALED_GLYPH_INFO_SURFACE) == 0) + load_flags |= FT_LOAD_NO_BITMAP; + + /* + * Don't pass FT_LOAD_VERTICAL_LAYOUT to FT_Load_Glyph here as + * suggested by freetype people. + */ + if (load_flags & FT_LOAD_VERTICAL_LAYOUT) { + load_flags &= ~FT_LOAD_VERTICAL_LAYOUT; + vertical_layout = TRUE; + } + +#ifdef FT_LOAD_COLOR + /* Color-glyph support: + * + * This flags needs plumbing through fontconfig (does it?), and + * maybe we should cache color and grayscale bitmaps separately + * such that users of the font (ie. the surface) can choose which + * version to use based on target content type. + * + * Moreover, none of our backends and compositors currently support + * color glyphs. As such, this is currently disabled. + */ + /* load_flags |= FT_LOAD_COLOR; */ +#endif + + error = FT_Load_Glyph (face, + _cairo_scaled_glyph_index(scaled_glyph), + load_flags); + /* XXX ignoring all other errors for now. They are not fatal, typically + * just a glyph-not-found. */ + if (error == FT_Err_Out_Of_Memory) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FAIL; + } + + glyph = face->glyph; + + /* + * synthesize glyphs if requested + */ +#if HAVE_FT_GLYPHSLOT_EMBOLDEN + if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_BOLD) + FT_GlyphSlot_Embolden (glyph); +#endif + +#if HAVE_FT_GLYPHSLOT_OBLIQUE + if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_OBLIQUE) + FT_GlyphSlot_Oblique (glyph); +#endif + + if (vertical_layout) + _cairo_ft_scaled_glyph_vertical_layout_bearing_fix (scaled_font, glyph); + + if (info & CAIRO_SCALED_GLYPH_INFO_METRICS) { + + cairo_bool_t hint_metrics = scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF; + /* + * Compute font-space metrics + */ + metrics = &glyph->metrics; + + if (unscaled->x_scale == 0) + x_factor = 0; + else + x_factor = 1 / unscaled->x_scale; + + if (unscaled->y_scale == 0) + y_factor = 0; + else + y_factor = 1 / unscaled->y_scale; + + /* + * Note: Y coordinates of the horizontal bearing need to be negated. + * + * Scale metrics back to glyph space from the scaled glyph space returned + * by FreeType + * + * If we want hinted metrics but aren't asking for hinted glyphs from + * FreeType, then we need to do the metric hinting ourselves. + */ + + if (hint_metrics && (load_flags & FT_LOAD_NO_HINTING)) + { + FT_Pos x1, x2; + FT_Pos y1, y2; + FT_Pos advance; + + if (!vertical_layout) { + x1 = (metrics->horiBearingX) & -64; + x2 = (metrics->horiBearingX + metrics->width + 63) & -64; + y1 = (-metrics->horiBearingY) & -64; + y2 = (-metrics->horiBearingY + metrics->height + 63) & -64; + + advance = ((metrics->horiAdvance + 32) & -64); + + fs_metrics.x_bearing = DOUBLE_FROM_26_6 (x1) * x_factor; + fs_metrics.y_bearing = DOUBLE_FROM_26_6 (y1) * y_factor; + + fs_metrics.width = DOUBLE_FROM_26_6 (x2 - x1) * x_factor; + fs_metrics.height = DOUBLE_FROM_26_6 (y2 - y1) * y_factor; + + fs_metrics.x_advance = DOUBLE_FROM_26_6 (advance) * x_factor; + fs_metrics.y_advance = 0; + } else { + x1 = (metrics->vertBearingX) & -64; + x2 = (metrics->vertBearingX + metrics->width + 63) & -64; + y1 = (metrics->vertBearingY) & -64; + y2 = (metrics->vertBearingY + metrics->height + 63) & -64; + + advance = ((metrics->vertAdvance + 32) & -64); + + fs_metrics.x_bearing = DOUBLE_FROM_26_6 (x1) * x_factor; + fs_metrics.y_bearing = DOUBLE_FROM_26_6 (y1) * y_factor; + + fs_metrics.width = DOUBLE_FROM_26_6 (x2 - x1) * x_factor; + fs_metrics.height = DOUBLE_FROM_26_6 (y2 - y1) * y_factor; + + fs_metrics.x_advance = 0; + fs_metrics.y_advance = DOUBLE_FROM_26_6 (advance) * y_factor; + } + } else { + fs_metrics.width = DOUBLE_FROM_26_6 (metrics->width) * x_factor; + fs_metrics.height = DOUBLE_FROM_26_6 (metrics->height) * y_factor; + + if (!vertical_layout) { + fs_metrics.x_bearing = DOUBLE_FROM_26_6 (metrics->horiBearingX) * x_factor; + fs_metrics.y_bearing = DOUBLE_FROM_26_6 (-metrics->horiBearingY) * y_factor; + + if (hint_metrics || glyph->format != FT_GLYPH_FORMAT_OUTLINE) + fs_metrics.x_advance = DOUBLE_FROM_26_6 (metrics->horiAdvance) * x_factor; + else + fs_metrics.x_advance = DOUBLE_FROM_16_16 (glyph->linearHoriAdvance) * x_factor; + fs_metrics.y_advance = 0 * y_factor; + } else { + fs_metrics.x_bearing = DOUBLE_FROM_26_6 (metrics->vertBearingX) * x_factor; + fs_metrics.y_bearing = DOUBLE_FROM_26_6 (metrics->vertBearingY) * y_factor; + + fs_metrics.x_advance = 0 * x_factor; + if (hint_metrics || glyph->format != FT_GLYPH_FORMAT_OUTLINE) + fs_metrics.y_advance = DOUBLE_FROM_26_6 (metrics->vertAdvance) * y_factor; + else + fs_metrics.y_advance = DOUBLE_FROM_16_16 (glyph->linearVertAdvance) * y_factor; + } + } + + _cairo_scaled_glyph_set_metrics (scaled_glyph, + &scaled_font->base, + &fs_metrics); + } + + if ((info & CAIRO_SCALED_GLYPH_INFO_SURFACE) != 0) { + cairo_image_surface_t *surface; + + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { + status = _render_glyph_outline (face, &scaled_font->ft_options.base, + &surface); + } else { + status = _render_glyph_bitmap (face, &scaled_font->ft_options.base, + &surface); + if (likely (status == CAIRO_STATUS_SUCCESS) && + unscaled->have_shape) + { + status = _transform_glyph_bitmap (&unscaled->current_shape, + &surface); + if (unlikely (status)) + cairo_surface_destroy (&surface->base); + } + } + if (unlikely (status)) + goto FAIL; + + _cairo_scaled_glyph_set_surface (scaled_glyph, + &scaled_font->base, + surface); + } + + if (info & CAIRO_SCALED_GLYPH_INFO_PATH) { + cairo_path_fixed_t *path = NULL; /* hide compiler warning */ + + /* + * A kludge -- the above code will trash the outline, + * so reload it. This will probably never occur though + */ + if ((info & CAIRO_SCALED_GLYPH_INFO_SURFACE) != 0) { + error = FT_Load_Glyph (face, + _cairo_scaled_glyph_index(scaled_glyph), + load_flags | FT_LOAD_NO_BITMAP); + /* XXX ignoring all other errors for now. They are not fatal, typically + * just a glyph-not-found. */ + if (error == FT_Err_Out_Of_Memory) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FAIL; + } +#if HAVE_FT_GLYPHSLOT_EMBOLDEN + if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_BOLD) + FT_GlyphSlot_Embolden (glyph); +#endif +#if HAVE_FT_GLYPHSLOT_OBLIQUE + if (scaled_font->ft_options.synth_flags & CAIRO_FT_SYNTHESIZE_OBLIQUE) + FT_GlyphSlot_Oblique (glyph); +#endif + if (vertical_layout) + _cairo_ft_scaled_glyph_vertical_layout_bearing_fix (scaled_font, glyph); + + } + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) + status = _decompose_glyph_outline (face, &scaled_font->ft_options.base, + &path); + else + status = CAIRO_INT_STATUS_UNSUPPORTED; + + if (unlikely (status)) + goto FAIL; + + _cairo_scaled_glyph_set_path (scaled_glyph, + &scaled_font->base, + path); + } + FAIL: + _cairo_ft_unscaled_font_unlock_face (unscaled); + + return status; +} + +static unsigned long +_cairo_ft_ucs4_to_index (void *abstract_font, + uint32_t ucs4) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; + FT_Face face; + FT_UInt index; + + face = _cairo_ft_unscaled_font_lock_face (unscaled); + if (!face) + return 0; + +#if CAIRO_HAS_FC_FONT + index = FcFreeTypeCharIndex (face, ucs4); +#else + index = FT_Get_Char_Index (face, ucs4); +#endif + + _cairo_ft_unscaled_font_unlock_face (unscaled); + return index; +} + +static cairo_int_status_t +_cairo_ft_load_truetype_table (void *abstract_font, + unsigned long tag, + long offset, + unsigned char *buffer, + unsigned long *length) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; + FT_Face face; + cairo_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + /* We don't support the FreeType feature of loading a table + * without specifying the size since this may overflow our + * buffer. */ + assert (length != NULL); + + if (_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) + return CAIRO_INT_STATUS_UNSUPPORTED; + +#if HAVE_FT_LOAD_SFNT_TABLE + face = _cairo_ft_unscaled_font_lock_face (unscaled); + if (!face) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (FT_IS_SFNT (face)) { + if (buffer == NULL) + *length = 0; + + if (FT_Load_Sfnt_Table (face, tag, offset, buffer, length) == 0) + status = CAIRO_STATUS_SUCCESS; + } + + _cairo_ft_unscaled_font_unlock_face (unscaled); +#endif + + return status; +} + +static cairo_int_status_t +_cairo_ft_index_to_ucs4(void *abstract_font, + unsigned long index, + uint32_t *ucs4) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; + FT_Face face; + FT_ULong charcode; + FT_UInt gindex; + + face = _cairo_ft_unscaled_font_lock_face (unscaled); + if (!face) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + *ucs4 = (uint32_t) -1; + charcode = FT_Get_First_Char(face, &gindex); + while (gindex != 0) { + if (gindex == index) { + *ucs4 = charcode; + break; + } + charcode = FT_Get_Next_Char (face, charcode, &gindex); + } + + _cairo_ft_unscaled_font_unlock_face (unscaled); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_ft_is_synthetic (void *abstract_font) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + return scaled_font->ft_options.synth_flags != 0; +} + +static cairo_int_status_t +_cairo_index_to_glyph_name (void *abstract_font, + char **glyph_names, + int num_glyph_names, + unsigned long glyph_index, + unsigned long *glyph_array_index) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; + FT_Face face; + char buffer[256]; /* PLRM spcifies max name length of 127 */ + FT_Error error; + int i; + + face = _cairo_ft_unscaled_font_lock_face (unscaled); + if (!face) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + error = FT_Get_Glyph_Name (face, glyph_index, buffer, sizeof buffer); + + _cairo_ft_unscaled_font_unlock_face (unscaled); + + if (error != FT_Err_Ok) { + /* propagate fatal errors from FreeType */ + if (error == FT_Err_Out_Of_Memory) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* FT first numbers the glyphs in the order they are read from the + * Type 1 font. Then if .notdef is not the first glyph, the first + * glyph is swapped with .notdef to ensure that .notdef is at + * glyph index 0. + * + * As all but two glyphs in glyph_names already have the same + * index as the FT glyph index, we first check if + * glyph_names[glyph_index] is the name we are looking for. If not + * we fall back to searching the entire array. + */ + + if ((long)glyph_index < num_glyph_names && + strcmp (glyph_names[glyph_index], buffer) == 0) + { + *glyph_array_index = glyph_index; + + return CAIRO_STATUS_SUCCESS; + } + + for (i = 0; i < num_glyph_names; i++) { + if (strcmp (glyph_names[i], buffer) == 0) { + *glyph_array_index = i; + + return CAIRO_STATUS_SUCCESS; + } + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_bool_t +_ft_is_type1 (FT_Face face) +{ +#if HAVE_FT_GET_X11_FONT_FORMAT + const char *font_format = FT_Get_X11_Font_Format (face); + if (font_format && + (strcmp (font_format, "Type 1") == 0 || + strcmp (font_format, "CFF") == 0)) + { + return TRUE; + } +#endif + + return FALSE; +} + +static cairo_int_status_t +_cairo_ft_load_type1_data (void *abstract_font, + long offset, + unsigned char *buffer, + unsigned long *length) +{ + cairo_ft_scaled_font_t *scaled_font = abstract_font; + cairo_ft_unscaled_font_t *unscaled = scaled_font->unscaled; + FT_Face face; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + unsigned long available_length; + unsigned long ret; + + assert (length != NULL); + + if (_cairo_ft_scaled_font_is_vertical (&scaled_font->base)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + face = _cairo_ft_unscaled_font_lock_face (unscaled); + if (!face) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + +#if HAVE_FT_LOAD_SFNT_TABLE + if (FT_IS_SFNT (face)) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto unlock; + } +#endif + + if (! _ft_is_type1 (face)) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto unlock; + } + + available_length = MAX (face->stream->size - offset, 0); + if (!buffer) { + *length = available_length; + } else { + if (*length > available_length) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + } else if (face->stream->read != NULL) { + /* Note that read() may be implemented as a macro, thanks POSIX!, so we + * need to wrap the following usage in parentheses in order to + * disambiguate it for the pre-processor - using the verbose function + * pointer dereference for clarity. + */ + ret = (* face->stream->read) (face->stream, + offset, + buffer, + *length); + if (ret != *length) + status = _cairo_error (CAIRO_STATUS_READ_ERROR); + } else { + memcpy (buffer, face->stream->base + offset, *length); + } + } + + unlock: + _cairo_ft_unscaled_font_unlock_face (unscaled); + + return status; +} + +static const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend = { + CAIRO_FONT_TYPE_FT, + _cairo_ft_scaled_font_fini, + _cairo_ft_scaled_glyph_init, + NULL, /* text_to_glyphs */ + _cairo_ft_ucs4_to_index, + _cairo_ft_load_truetype_table, + _cairo_ft_index_to_ucs4, + _cairo_ft_is_synthetic, + _cairo_index_to_glyph_name, + _cairo_ft_load_type1_data +}; + +/* #cairo_ft_font_face_t */ + +#if CAIRO_HAS_FC_FONT +static cairo_font_face_t * +_cairo_ft_font_face_create_for_pattern (FcPattern *pattern); + +static cairo_status_t +_cairo_ft_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, + cairo_font_face_t **font_face_out) +{ + cairo_font_face_t *font_face = (cairo_font_face_t *) &_cairo_font_face_nil; + FcPattern *pattern; + int fcslant; + int fcweight; + + pattern = FcPatternCreate (); + if (!pattern) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return font_face->status; + } + + if (!FcPatternAddString (pattern, + FC_FAMILY, (unsigned char *) toy_face->family)) + { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + goto FREE_PATTERN; + } + + switch (toy_face->slant) + { + case CAIRO_FONT_SLANT_ITALIC: + fcslant = FC_SLANT_ITALIC; + break; + case CAIRO_FONT_SLANT_OBLIQUE: + fcslant = FC_SLANT_OBLIQUE; + break; + case CAIRO_FONT_SLANT_NORMAL: + default: + fcslant = FC_SLANT_ROMAN; + break; + } + + if (!FcPatternAddInteger (pattern, FC_SLANT, fcslant)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + goto FREE_PATTERN; + } + + switch (toy_face->weight) + { + case CAIRO_FONT_WEIGHT_BOLD: + fcweight = FC_WEIGHT_BOLD; + break; + case CAIRO_FONT_WEIGHT_NORMAL: + default: + fcweight = FC_WEIGHT_MEDIUM; + break; + } + + if (!FcPatternAddInteger (pattern, FC_WEIGHT, fcweight)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + goto FREE_PATTERN; + } + + font_face = _cairo_ft_font_face_create_for_pattern (pattern); + + FREE_PATTERN: + FcPatternDestroy (pattern); + + *font_face_out = font_face; + return font_face->status; +} +#endif + +static cairo_bool_t +_cairo_ft_font_face_destroy (void *abstract_face) +{ + cairo_ft_font_face_t *font_face = abstract_face; + + /* When destroying a face created by cairo_ft_font_face_create_for_ft_face, + * we have a special "zombie" state for the face when the unscaled font + * is still alive but there are no other references to a font face with + * the same FT_Face. + * + * We go from: + * + * font_face ------> unscaled + * <-....weak....../ + * + * To: + * + * font_face <------- unscaled + */ + + if (font_face->unscaled && + font_face->unscaled->from_face && + font_face->next == NULL && + font_face->unscaled->faces == font_face && + CAIRO_REFERENCE_COUNT_GET_VALUE (&font_face->unscaled->base.ref_count) > 1) + { + _cairo_unscaled_font_destroy (&font_face->unscaled->base); + font_face->unscaled = NULL; + + return FALSE; + } + + if (font_face->unscaled) { + cairo_ft_font_face_t *tmp_face = NULL; + cairo_ft_font_face_t *last_face = NULL; + + /* Remove face from linked list */ + for (tmp_face = font_face->unscaled->faces; + tmp_face; + tmp_face = tmp_face->next) + { + if (tmp_face == font_face) { + if (last_face) + last_face->next = tmp_face->next; + else + font_face->unscaled->faces = tmp_face->next; + } + + last_face = tmp_face; + } + + _cairo_unscaled_font_destroy (&font_face->unscaled->base); + font_face->unscaled = NULL; + } + +#if CAIRO_HAS_FC_FONT + if (font_face->pattern) { + FcPatternDestroy (font_face->pattern); + cairo_font_face_destroy (font_face->resolved_font_face); + } +#endif + + return TRUE; +} + +static cairo_font_face_t * +_cairo_ft_font_face_get_implementation (void *abstract_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options) +{ + cairo_ft_font_face_t *font_face = abstract_face; + + /* The handling of font options is different depending on how the + * font face was created. When the user creates a font face with + * cairo_ft_font_face_create_for_ft_face(), then the load flags + * passed in augment the load flags for the options. But for + * cairo_ft_font_face_create_for_pattern(), the load flags are + * derived from a pattern where the user has called + * cairo_ft_font_options_substitute(), so *just* use those load + * flags and ignore the options. + */ + +#if CAIRO_HAS_FC_FONT + /* If we have an unresolved pattern, resolve it and create + * unscaled font. Otherwise, use the ones stored in font_face. + */ + if (font_face->pattern) { + cairo_font_face_t *resolved; + + /* Cache the resolved font whilst the FcConfig remains consistent. */ + resolved = font_face->resolved_font_face; + if (resolved != NULL) { + if (! FcInitBringUptoDate ()) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *) &_cairo_font_face_nil; + } + + if (font_face->resolved_config == FcConfigGetCurrent ()) + return cairo_font_face_reference (resolved); + + cairo_font_face_destroy (resolved); + font_face->resolved_font_face = NULL; + } + + resolved = _cairo_ft_resolve_pattern (font_face->pattern, + font_matrix, + ctm, + options); + if (unlikely (resolved->status)) + return resolved; + + font_face->resolved_font_face = cairo_font_face_reference (resolved); + font_face->resolved_config = FcConfigGetCurrent (); + + return resolved; + } +#endif + + return abstract_face; +} + +const cairo_font_face_backend_t _cairo_ft_font_face_backend = { + CAIRO_FONT_TYPE_FT, +#if CAIRO_HAS_FC_FONT + _cairo_ft_font_face_create_for_toy, +#else + NULL, +#endif + _cairo_ft_font_face_destroy, + _cairo_ft_font_face_scaled_font_create, + _cairo_ft_font_face_get_implementation +}; + +#if CAIRO_HAS_FC_FONT +static cairo_font_face_t * +_cairo_ft_font_face_create_for_pattern (FcPattern *pattern) +{ + cairo_ft_font_face_t *font_face; + + font_face = malloc (sizeof (cairo_ft_font_face_t)); + if (unlikely (font_face == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *) &_cairo_font_face_nil; + } + + font_face->unscaled = NULL; + font_face->next = NULL; + + font_face->pattern = FcPatternDuplicate (pattern); + if (unlikely (font_face->pattern == NULL)) { + free (font_face); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *) &_cairo_font_face_nil; + } + + font_face->resolved_font_face = NULL; + font_face->resolved_config = NULL; + + _cairo_font_face_init (&font_face->base, &_cairo_ft_font_face_backend); + + return &font_face->base; +} +#endif + +static cairo_font_face_t * +_cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled, + cairo_ft_options_t *ft_options) +{ + cairo_ft_font_face_t *font_face, **prev_font_face; + + /* Looked for an existing matching font face */ + for (font_face = unscaled->faces, prev_font_face = &unscaled->faces; + font_face; + prev_font_face = &font_face->next, font_face = font_face->next) + { + if (font_face->ft_options.load_flags == ft_options->load_flags && + font_face->ft_options.synth_flags == ft_options->synth_flags && + cairo_font_options_equal (&font_face->ft_options.base, &ft_options->base)) + { + if (font_face->base.status) { + /* The font_face has been left in an error state, abandon it. */ + *prev_font_face = font_face->next; + break; + } + + if (font_face->unscaled == NULL) { + /* Resurrect this "zombie" font_face (from + * _cairo_ft_font_face_destroy), switching its unscaled_font + * from owner to ownee. */ + font_face->unscaled = unscaled; + _cairo_unscaled_font_reference (&unscaled->base); + return &font_face->base; + } else + return cairo_font_face_reference (&font_face->base); + } + } + + /* No match found, create a new one */ + font_face = malloc (sizeof (cairo_ft_font_face_t)); + if (unlikely (!font_face)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *)&_cairo_font_face_nil; + } + + font_face->unscaled = unscaled; + _cairo_unscaled_font_reference (&unscaled->base); + + font_face->ft_options = *ft_options; + + if (unscaled->faces && unscaled->faces->unscaled == NULL) { + /* This "zombie" font_face (from _cairo_ft_font_face_destroy) + * is no longer needed. */ + assert (unscaled->from_face && unscaled->faces->next == NULL); + cairo_font_face_destroy (&unscaled->faces->base); + unscaled->faces = NULL; + } + + font_face->next = unscaled->faces; + unscaled->faces = font_face; + +#if CAIRO_HAS_FC_FONT + font_face->pattern = NULL; +#endif + + _cairo_font_face_init (&font_face->base, &_cairo_ft_font_face_backend); + + return &font_face->base; +} + +/* implement the platform-specific interface */ + +#if CAIRO_HAS_FC_FONT +static cairo_status_t +_cairo_ft_font_options_substitute (const cairo_font_options_t *options, + FcPattern *pattern) +{ + FcValue v; + + if (options->antialias != CAIRO_ANTIALIAS_DEFAULT) + { + if (FcPatternGet (pattern, FC_ANTIALIAS, 0, &v) == FcResultNoMatch) + { + if (! FcPatternAddBool (pattern, + FC_ANTIALIAS, + options->antialias != CAIRO_ANTIALIAS_NONE)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (options->antialias != CAIRO_ANTIALIAS_SUBPIXEL) { + FcPatternDel (pattern, FC_RGBA); + if (! FcPatternAddInteger (pattern, FC_RGBA, FC_RGBA_NONE)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + } + + if (options->antialias != CAIRO_ANTIALIAS_DEFAULT) + { + if (FcPatternGet (pattern, FC_RGBA, 0, &v) == FcResultNoMatch) + { + int rgba; + + if (options->antialias == CAIRO_ANTIALIAS_SUBPIXEL) { + switch (options->subpixel_order) { + case CAIRO_SUBPIXEL_ORDER_DEFAULT: + case CAIRO_SUBPIXEL_ORDER_RGB: + default: + rgba = FC_RGBA_RGB; + break; + case CAIRO_SUBPIXEL_ORDER_BGR: + rgba = FC_RGBA_BGR; + break; + case CAIRO_SUBPIXEL_ORDER_VRGB: + rgba = FC_RGBA_VRGB; + break; + case CAIRO_SUBPIXEL_ORDER_VBGR: + rgba = FC_RGBA_VBGR; + break; + } + } else { + rgba = FC_RGBA_NONE; + } + + if (! FcPatternAddInteger (pattern, FC_RGBA, rgba)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + if (options->lcd_filter != CAIRO_LCD_FILTER_DEFAULT) + { + if (FcPatternGet (pattern, FC_LCD_FILTER, 0, &v) == FcResultNoMatch) + { + int lcd_filter; + + switch (options->lcd_filter) { + case CAIRO_LCD_FILTER_NONE: + lcd_filter = FT_LCD_FILTER_NONE; + break; + case CAIRO_LCD_FILTER_DEFAULT: + case CAIRO_LCD_FILTER_INTRA_PIXEL: + lcd_filter = FT_LCD_FILTER_LEGACY; + break; + case CAIRO_LCD_FILTER_FIR3: + lcd_filter = FT_LCD_FILTER_LIGHT; + break; + default: + case CAIRO_LCD_FILTER_FIR5: + lcd_filter = FT_LCD_FILTER_DEFAULT; + break; + } + + if (! FcPatternAddInteger (pattern, FC_LCD_FILTER, lcd_filter)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + if (options->hint_style != CAIRO_HINT_STYLE_DEFAULT) + { + if (FcPatternGet (pattern, FC_HINTING, 0, &v) == FcResultNoMatch) + { + if (! FcPatternAddBool (pattern, + FC_HINTING, + options->hint_style != CAIRO_HINT_STYLE_NONE)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + +#ifdef FC_HINT_STYLE + if (FcPatternGet (pattern, FC_HINT_STYLE, 0, &v) == FcResultNoMatch) + { + int hint_style; + + switch (options->hint_style) { + case CAIRO_HINT_STYLE_NONE: + hint_style = FC_HINT_NONE; + break; + case CAIRO_HINT_STYLE_SLIGHT: + hint_style = FC_HINT_SLIGHT; + break; + case CAIRO_HINT_STYLE_MEDIUM: + hint_style = FC_HINT_MEDIUM; + break; + case CAIRO_HINT_STYLE_FULL: + case CAIRO_HINT_STYLE_DEFAULT: + default: + hint_style = FC_HINT_FULL; + break; + } + + if (! FcPatternAddInteger (pattern, FC_HINT_STYLE, hint_style)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } +#endif + } + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_ft_font_options_substitute: + * @options: a #cairo_font_options_t object + * @pattern: an existing #FcPattern + * + * Add options to a #FcPattern based on a #cairo_font_options_t font + * options object. Options that are already in the pattern, are not overridden, + * so you should call this function after calling FcConfigSubstitute() (the + * user's settings should override options based on the surface type), but + * before calling FcDefaultSubstitute(). + * + * Since: 1.0 + **/ +void +cairo_ft_font_options_substitute (const cairo_font_options_t *options, + FcPattern *pattern) +{ + if (cairo_font_options_status ((cairo_font_options_t *) options)) + return; + + _cairo_ft_font_options_substitute (options, pattern); +} + +static cairo_font_face_t * +_cairo_ft_resolve_pattern (FcPattern *pattern, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *font_options) +{ + cairo_status_t status; + + cairo_matrix_t scale; + FcPattern *resolved; + cairo_ft_font_transform_t sf; + FcResult result; + cairo_ft_unscaled_font_t *unscaled; + cairo_ft_options_t ft_options; + cairo_font_face_t *font_face; + + scale = *ctm; + scale.x0 = scale.y0 = 0; + cairo_matrix_multiply (&scale, + font_matrix, + &scale); + + status = _compute_transform (&sf, &scale, NULL); + if (unlikely (status)) + return (cairo_font_face_t *)&_cairo_font_face_nil; + + pattern = FcPatternDuplicate (pattern); + if (pattern == NULL) + return (cairo_font_face_t *)&_cairo_font_face_nil; + + if (! FcPatternAddDouble (pattern, FC_PIXEL_SIZE, sf.y_scale)) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; + goto FREE_PATTERN; + } + + if (! FcConfigSubstitute (NULL, pattern, FcMatchPattern)) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; + goto FREE_PATTERN; + } + + status = _cairo_ft_font_options_substitute (font_options, pattern); + if (status) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; + goto FREE_PATTERN; + } + + FcDefaultSubstitute (pattern); + + status = _cairo_ft_unscaled_font_create_for_pattern (pattern, &unscaled); + if (unlikely (status)) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; + goto FREE_PATTERN; + } + + if (unscaled == NULL) { + resolved = FcFontMatch (NULL, pattern, &result); + if (!resolved) { + /* We failed to find any font. Substitute twin so that the user can + * see something (and hopefully recognise that the font is missing) + * and not just receive a NO_MEMORY error during rendering. + */ + font_face = _cairo_font_face_twin_create_fallback (); + goto FREE_PATTERN; + } + + status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled); + if (unlikely (status || unscaled == NULL)) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; + goto FREE_RESOLVED; + } + } else + resolved = pattern; + + _get_pattern_ft_options (resolved, &ft_options); + font_face = _cairo_ft_font_face_create (unscaled, &ft_options); + _cairo_unscaled_font_destroy (&unscaled->base); + +FREE_RESOLVED: + if (resolved != pattern) + FcPatternDestroy (resolved); + +FREE_PATTERN: + FcPatternDestroy (pattern); + + return font_face; +} + +/** + * cairo_ft_font_face_create_for_pattern: + * @pattern: A fontconfig pattern. Cairo makes a copy of the pattern + * if it needs to. You are free to modify or free @pattern after this call. + * + * Creates a new font face for the FreeType font backend based on a + * fontconfig pattern. This font can then be used with + * cairo_set_font_face() or cairo_scaled_font_create(). The + * #cairo_scaled_font_t returned from cairo_scaled_font_create() is + * also for the FreeType backend and can be used with functions such + * as cairo_ft_scaled_font_lock_face(). + * + * Font rendering options are represented both here and when you + * call cairo_scaled_font_create(). Font options that have a representation + * in a #FcPattern must be passed in here; to modify #FcPattern + * appropriately to reflect the options in a #cairo_font_options_t, call + * cairo_ft_font_options_substitute(). + * + * The pattern's FC_FT_FACE element is inspected first and if that is set, + * that will be the FreeType font face associated with the returned cairo + * font face. Otherwise the FC_FILE element is checked. If it's set, + * that and the value of the FC_INDEX element (defaults to zero) of @pattern + * are used to load a font face from file. + * + * If both steps from the previous paragraph fails, @pattern will be passed + * to FcConfigSubstitute, FcDefaultSubstitute, and finally FcFontMatch, + * and the resulting font pattern is used. + * + * If the FC_FT_FACE element of @pattern is set, the user is responsible + * for making sure that the referenced FT_Face remains valid for the life + * time of the returned #cairo_font_face_t. See + * cairo_ft_font_face_create_for_ft_face() for an example of how to couple + * the life time of the FT_Face to that of the cairo font-face. + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.0 + **/ +cairo_font_face_t * +cairo_ft_font_face_create_for_pattern (FcPattern *pattern) +{ + cairo_ft_unscaled_font_t *unscaled; + cairo_font_face_t *font_face; + cairo_ft_options_t ft_options; + cairo_status_t status; + + status = _cairo_ft_unscaled_font_create_for_pattern (pattern, &unscaled); + if (unlikely (status)) { + if (status == CAIRO_STATUS_FILE_NOT_FOUND) + return (cairo_font_face_t *) &_cairo_font_face_nil_file_not_found; + else + return (cairo_font_face_t *) &_cairo_font_face_nil; + } + if (unlikely (unscaled == NULL)) { + /* Store the pattern. We will resolve it and create unscaled + * font when creating scaled fonts */ + return _cairo_ft_font_face_create_for_pattern (pattern); + } + + _get_pattern_ft_options (pattern, &ft_options); + font_face = _cairo_ft_font_face_create (unscaled, &ft_options); + _cairo_unscaled_font_destroy (&unscaled->base); + + return font_face; +} +#endif + +/** + * cairo_ft_font_face_create_for_ft_face: + * @face: A FreeType face object, already opened. This must + * be kept around until the face's ref_count drops to + * zero and it is freed. Since the face may be referenced + * internally to Cairo, the best way to determine when it + * is safe to free the face is to pass a + * #cairo_destroy_func_t to cairo_font_face_set_user_data() + * @load_flags: flags to pass to FT_Load_Glyph when loading + * glyphs from the font. These flags are OR'ed together with + * the flags derived from the #cairo_font_options_t passed + * to cairo_scaled_font_create(), so only a few values such + * as %FT_LOAD_VERTICAL_LAYOUT, and %FT_LOAD_FORCE_AUTOHINT + * are useful. You should not pass any of the flags affecting + * the load target, such as %FT_LOAD_TARGET_LIGHT. + * + * Creates a new font face for the FreeType font backend from a + * pre-opened FreeType face. This font can then be used with + * cairo_set_font_face() or cairo_scaled_font_create(). The + * #cairo_scaled_font_t returned from cairo_scaled_font_create() is + * also for the FreeType backend and can be used with functions such + * as cairo_ft_scaled_font_lock_face(). Note that Cairo may keep a reference + * to the FT_Face alive in a font-cache and the exact lifetime of the reference + * depends highly upon the exact usage pattern and is subject to external + * factors. You must not call FT_Done_Face() before the last reference to the + * #cairo_font_face_t has been dropped. + * + * As an example, below is how one might correctly couple the lifetime of + * the FreeType face object to the #cairo_font_face_t. + * + * + * static const cairo_user_data_key_t key; + * + * font_face = cairo_ft_font_face_create_for_ft_face (ft_face, 0); + * status = cairo_font_face_set_user_data (font_face, &key, + * ft_face, (cairo_destroy_func_t) FT_Done_Face); + * if (status) { + * cairo_font_face_destroy (font_face); + * FT_Done_Face (ft_face); + * return ERROR; + * } + * + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.0 + **/ +cairo_font_face_t * +cairo_ft_font_face_create_for_ft_face (FT_Face face, + int load_flags) +{ + cairo_ft_unscaled_font_t *unscaled; + cairo_font_face_t *font_face; + cairo_ft_options_t ft_options; + cairo_status_t status; + + status = _cairo_ft_unscaled_font_create_from_face (face, &unscaled); + if (unlikely (status)) + return (cairo_font_face_t *)&_cairo_font_face_nil; + + ft_options.load_flags = load_flags; + ft_options.synth_flags = 0; + _cairo_font_options_init_default (&ft_options.base); + + font_face = _cairo_ft_font_face_create (unscaled, &ft_options); + _cairo_unscaled_font_destroy (&unscaled->base); + + return font_face; +} + +/** + * cairo_ft_font_face_set_synthesize: + * @font_face: The #cairo_ft_font_face_t object to modify + * @synth_flags: the set of synthesis options to enable + * + * FreeType provides the ability to synthesize different glyphs from a base + * font, which is useful if you lack those glyphs from a true bold or oblique + * font. See also #cairo_ft_synthesize_t. + * + * Since: 1.12 + **/ +void +cairo_ft_font_face_set_synthesize (cairo_font_face_t *font_face, + unsigned int synth_flags) +{ + cairo_ft_font_face_t *ft; + + if (font_face->backend->type != CAIRO_FONT_TYPE_FT) + return; + + ft = (cairo_ft_font_face_t *) font_face; + ft->ft_options.synth_flags |= synth_flags; +} + +/** + * cairo_ft_font_face_unset_synthesize: + * @font_face: The #cairo_ft_font_face_t object to modify + * @synth_flags: the set of synthesis options to disable + * + * See cairo_ft_font_face_set_synthesize(). + * + * Since: 1.12 + **/ +void +cairo_ft_font_face_unset_synthesize (cairo_font_face_t *font_face, + unsigned int synth_flags) +{ + cairo_ft_font_face_t *ft; + + if (font_face->backend->type != CAIRO_FONT_TYPE_FT) + return; + + ft = (cairo_ft_font_face_t *) font_face; + ft->ft_options.synth_flags &= ~synth_flags; +} + +/** + * cairo_ft_font_face_get_synthesize: + * @font_face: The #cairo_ft_font_face_t object to query + * + * See #cairo_ft_synthesize_t. + * + * Returns: the current set of synthesis options. + * + * Since: 1.12 + **/ +unsigned int +cairo_ft_font_face_get_synthesize (cairo_font_face_t *font_face) +{ + cairo_ft_font_face_t *ft; + + if (font_face->backend->type != CAIRO_FONT_TYPE_FT) + return 0; + + ft = (cairo_ft_font_face_t *) font_face; + return ft->ft_options.synth_flags; +} + +/** + * cairo_ft_scaled_font_lock_face: + * @scaled_font: A #cairo_scaled_font_t from the FreeType font backend. Such an + * object can be created by calling cairo_scaled_font_create() on a + * FreeType backend font face (see cairo_ft_font_face_create_for_pattern(), + * cairo_ft_font_face_create_for_ft_face()). + * + * cairo_ft_scaled_font_lock_face() gets the #FT_Face object from a FreeType + * backend font and scales it appropriately for the font. You must + * release the face with cairo_ft_scaled_font_unlock_face() + * when you are done using it. Since the #FT_Face object can be + * shared between multiple #cairo_scaled_font_t objects, you must not + * lock any other font objects until you unlock this one. A count is + * kept of the number of times cairo_ft_scaled_font_lock_face() is + * called. cairo_ft_scaled_font_unlock_face() must be called the same number + * of times. + * + * You must be careful when using this function in a library or in a + * threaded application, because freetype's design makes it unsafe to + * call freetype functions simultaneously from multiple threads, (even + * if using distinct FT_Face objects). Because of this, application + * code that acquires an FT_Face object with this call must add its + * own locking to protect any use of that object, (and which also must + * protect any other calls into cairo as almost any cairo function + * might result in a call into the freetype library). + * + * Return value: The #FT_Face object for @font, scaled appropriately, + * or %NULL if @scaled_font is in an error state (see + * cairo_scaled_font_status()) or there is insufficient memory. + * + * Since: 1.0 + **/ +FT_Face +cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font) +{ + cairo_ft_scaled_font_t *scaled_font = (cairo_ft_scaled_font_t *) abstract_font; + FT_Face face; + cairo_status_t status; + + if (! _cairo_scaled_font_is_ft (abstract_font)) { + _cairo_error_throw (CAIRO_STATUS_FONT_TYPE_MISMATCH); + return NULL; + } + + if (scaled_font->base.status) + return NULL; + + face = _cairo_ft_unscaled_font_lock_face (scaled_font->unscaled); + if (unlikely (face == NULL)) { + status = _cairo_scaled_font_set_error (&scaled_font->base, CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled, + &scaled_font->base.scale); + if (unlikely (status)) { + _cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled); + status = _cairo_scaled_font_set_error (&scaled_font->base, status); + return NULL; + } + + /* Note: We deliberately release the unscaled font's mutex here, + * so that we are not holding a lock across two separate calls to + * cairo function, (which would give the application some + * opportunity for creating deadlock. This is obviously unsafe, + * but as documented, the user must add manual locking when using + * this function. */ + CAIRO_MUTEX_UNLOCK (scaled_font->unscaled->mutex); + + return face; +} + +/** + * cairo_ft_scaled_font_unlock_face: + * @scaled_font: A #cairo_scaled_font_t from the FreeType font backend. Such an + * object can be created by calling cairo_scaled_font_create() on a + * FreeType backend font face (see cairo_ft_font_face_create_for_pattern(), + * cairo_ft_font_face_create_for_ft_face()). + * + * Releases a face obtained with cairo_ft_scaled_font_lock_face(). + * + * Since: 1.0 + **/ +void +cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *abstract_font) +{ + cairo_ft_scaled_font_t *scaled_font = (cairo_ft_scaled_font_t *) abstract_font; + + if (! _cairo_scaled_font_is_ft (abstract_font)) { + _cairo_error_throw (CAIRO_STATUS_FONT_TYPE_MISMATCH); + return; + } + + if (scaled_font->base.status) + return; + + /* Note: We released the unscaled font's mutex at the end of + * cairo_ft_scaled_font_lock_face, so we have to acquire it again + * as _cairo_ft_unscaled_font_unlock_face expects it to be held + * when we call into it. */ + CAIRO_MUTEX_LOCK (scaled_font->unscaled->mutex); + + _cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled); +} + +static cairo_bool_t +_cairo_ft_scaled_font_is_vertical (cairo_scaled_font_t *scaled_font) +{ + cairo_ft_scaled_font_t *ft_scaled_font; + + if (!_cairo_scaled_font_is_ft (scaled_font)) + return FALSE; + + ft_scaled_font = (cairo_ft_scaled_font_t *) scaled_font; + if (ft_scaled_font->ft_options.load_flags & FT_LOAD_VERTICAL_LAYOUT) + return TRUE; + return FALSE; +} + +unsigned int +_cairo_ft_scaled_font_get_load_flags (cairo_scaled_font_t *scaled_font) +{ + cairo_ft_scaled_font_t *ft_scaled_font; + + if (! _cairo_scaled_font_is_ft (scaled_font)) + return 0; + + ft_scaled_font = (cairo_ft_scaled_font_t *) scaled_font; + return ft_scaled_font->ft_options.load_flags; +} + +void +_cairo_ft_font_reset_static_data (void) +{ + _cairo_ft_unscaled_font_map_destroy (); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-ft-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-ft-private.h new file mode 100644 index 00000000000..0dc8114726f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-ft-private.h @@ -0,0 +1,61 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Graydon Hoare + * Owen Taylor + */ + +#ifndef CAIRO_FT_PRIVATE_H +#define CAIRO_FT_PRIVATE_H + +#include "cairoint.h" +#include "cairo-ft.h" + +#if CAIRO_HAS_FT_FONT + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_ft_unscaled_font cairo_ft_unscaled_font_t; + +cairo_private cairo_bool_t +_cairo_scaled_font_is_ft (cairo_scaled_font_t *scaled_font); + +/* These functions are needed by the PDF backend, which needs to keep track of the + * the different fonts-on-disk used by a document, so it can embed them + */ +cairo_private unsigned int +_cairo_ft_scaled_font_get_load_flags (cairo_scaled_font_t *scaled_font); + +CAIRO_END_DECLS + +#endif /* CAIRO_HAS_FT_FONT */ +#endif /* CAIRO_FT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-ft.h b/Build/source/libs/cairo/cairo-src/src/cairo-ft.h new file mode 100644 index 00000000000..29c43c9655b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-ft.h @@ -0,0 +1,118 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Graydon Hoare + * Owen Taylor + */ + +#ifndef CAIRO_FT_H +#define CAIRO_FT_H + +#include "cairo.h" + +#if CAIRO_HAS_FT_FONT + +/* Fontconfig/Freetype platform-specific font interface */ + +#include +#include FT_FREETYPE_H + +#if CAIRO_HAS_FC_FONT +#include +#endif + +CAIRO_BEGIN_DECLS + +cairo_public cairo_font_face_t * +cairo_ft_font_face_create_for_ft_face (FT_Face face, + int load_flags); + +/** + * cairo_ft_synthesize_t: + * @CAIRO_FT_SYNTHESIZE_BOLD: Embolden the glyphs (redraw with a pixel offset) + * @CAIRO_FT_SYNTHESIZE_OBLIQUE: Slant the glyph outline by 12 degrees to the + * right. + * + * A set of synthesis options to control how FreeType renders the glyphs + * for a particular font face. + * + * Individual synthesis features of a #cairo_ft_font_face_t can be set + * using cairo_ft_font_face_set_synthesize(), or disabled using + * cairo_ft_font_face_unset_synthesize(). The currently enabled set of + * synthesis options can be queried with cairo_ft_font_face_get_synthesize(). + * + * Note: that when synthesizing glyphs, the font metrics returned will only + * be estimates. + * + * Since: 1.12 + **/ +typedef enum { + CAIRO_FT_SYNTHESIZE_BOLD = 1 << 0, + CAIRO_FT_SYNTHESIZE_OBLIQUE = 1 << 1 +} cairo_ft_synthesize_t; + +cairo_public void +cairo_ft_font_face_set_synthesize (cairo_font_face_t *font_face, + unsigned int synth_flags); + +cairo_public void +cairo_ft_font_face_unset_synthesize (cairo_font_face_t *font_face, + unsigned int synth_flags); + +cairo_public unsigned int +cairo_ft_font_face_get_synthesize (cairo_font_face_t *font_face); + + +cairo_public FT_Face +cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *scaled_font); + +cairo_public void +cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *scaled_font); + +#if CAIRO_HAS_FC_FONT + +cairo_public cairo_font_face_t * +cairo_ft_font_face_create_for_pattern (FcPattern *pattern); + +cairo_public void +cairo_ft_font_options_substitute (const cairo_font_options_t *options, + FcPattern *pattern); + +#endif + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_FT_FONT */ +# error Cairo was not compiled with support for the freetype font backend +#endif /* CAIRO_HAS_FT_FONT */ + +#endif /* CAIRO_FT_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-composite.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-composite.c new file mode 100644 index 00000000000..5b1411472d0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-composite.c @@ -0,0 +1,1265 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * Copyright © 2011 Linaro Limited + * Copyright © 2011 Samsung Electronics + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + * Alexandros Frantzis + * Henry Song + * Martin Robinson + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" + +cairo_int_status_t +_cairo_gl_composite_set_source (cairo_gl_composite_t *setup, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen) +{ + _cairo_gl_operand_destroy (&setup->src); + return _cairo_gl_operand_init (&setup->src, pattern, setup->dst, + sample, extents, use_texgen); +} + +void +_cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup, + const cairo_gl_operand_t *source) +{ + _cairo_gl_operand_destroy (&setup->src); + _cairo_gl_operand_copy (&setup->src, source); +} + +void +_cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup, + const cairo_color_t *color) +{ + _cairo_gl_operand_destroy (&setup->src); + _cairo_gl_solid_operand_init (&setup->src, color); +} + +cairo_int_status_t +_cairo_gl_composite_set_mask (cairo_gl_composite_t *setup, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen) +{ + _cairo_gl_operand_destroy (&setup->mask); + if (pattern == NULL) + return CAIRO_STATUS_SUCCESS; + + return _cairo_gl_operand_init (&setup->mask, pattern, setup->dst, + sample, extents, use_texgen); +} + +void +_cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup, + const cairo_gl_operand_t *mask) +{ + _cairo_gl_operand_destroy (&setup->mask); + if (mask) + _cairo_gl_operand_copy (&setup->mask, mask); +} + +void +_cairo_gl_composite_set_spans (cairo_gl_composite_t *setup) +{ + setup->spans = TRUE; +} + +void +_cairo_gl_composite_set_multisample (cairo_gl_composite_t *setup) +{ + setup->multisample = TRUE; +} + +void +_cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup, + cairo_region_t *clip_region) +{ + setup->clip_region = clip_region; +} + +void +_cairo_gl_composite_set_clip (cairo_gl_composite_t *setup, + cairo_clip_t *clip) +{ + setup->clip = clip; +} + +static void +_cairo_gl_composite_bind_to_shader (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup) +{ + _cairo_gl_shader_bind_matrix4f(ctx, ctx->current_shader->mvp_location, + ctx->modelviewprojection_matrix); + _cairo_gl_operand_bind_to_shader (ctx, &setup->src, CAIRO_GL_TEX_SOURCE); + _cairo_gl_operand_bind_to_shader (ctx, &setup->mask, CAIRO_GL_TEX_MASK); +} + +static void +_cairo_gl_texture_set_filter (cairo_gl_context_t *ctx, + GLuint target, + cairo_filter_t filter) +{ + switch (filter) { + case CAIRO_FILTER_FAST: + case CAIRO_FILTER_NEAREST: + glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + break; + case CAIRO_FILTER_GOOD: + case CAIRO_FILTER_BEST: + case CAIRO_FILTER_BILINEAR: + glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + break; + default: + case CAIRO_FILTER_GAUSSIAN: + ASSERT_NOT_REACHED; + } +} + +static void +_cairo_gl_texture_set_extend (cairo_gl_context_t *ctx, + GLuint target, + cairo_extend_t extend) +{ + GLint wrap_mode; + assert (! _cairo_gl_device_requires_power_of_two_textures (&ctx->base) || + (extend != CAIRO_EXTEND_REPEAT && extend != CAIRO_EXTEND_REFLECT)); + + switch (extend) { + case CAIRO_EXTEND_NONE: + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) + wrap_mode = GL_CLAMP_TO_EDGE; + else + wrap_mode = GL_CLAMP_TO_BORDER; + break; + case CAIRO_EXTEND_PAD: + wrap_mode = GL_CLAMP_TO_EDGE; + break; + case CAIRO_EXTEND_REPEAT: + if (ctx->has_npot_repeat) + wrap_mode = GL_REPEAT; + else + wrap_mode = GL_CLAMP_TO_EDGE; + break; + case CAIRO_EXTEND_REFLECT: + if (ctx->has_npot_repeat) + wrap_mode = GL_MIRRORED_REPEAT; + else + wrap_mode = GL_CLAMP_TO_EDGE; + break; + default: + wrap_mode = 0; + } + + if (likely (wrap_mode)) { + glTexParameteri (target, GL_TEXTURE_WRAP_S, wrap_mode); + glTexParameteri (target, GL_TEXTURE_WRAP_T, wrap_mode); + } +} + + +static void +_cairo_gl_context_setup_operand (cairo_gl_context_t *ctx, + cairo_gl_tex_t tex_unit, + cairo_gl_operand_t *operand, + unsigned int vertex_offset, + cairo_bool_t vertex_size_changed) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + cairo_bool_t needs_setup; + + /* XXX: we need to do setup when switching from shaders + * to no shaders (or back) */ + needs_setup = vertex_size_changed; + needs_setup |= _cairo_gl_operand_needs_setup (&ctx->operands[tex_unit], + operand, + vertex_offset); + + if (needs_setup) { + _cairo_gl_composite_flush (ctx); + _cairo_gl_context_destroy_operand (ctx, tex_unit); + } + + memcpy (&ctx->operands[tex_unit], operand, sizeof (cairo_gl_operand_t)); + ctx->operands[tex_unit].vertex_offset = vertex_offset; + + if (! needs_setup) + return; + + switch (operand->type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + break; + /* fall through */ + case CAIRO_GL_OPERAND_CONSTANT: + break; + case CAIRO_GL_OPERAND_TEXTURE: + glActiveTexture (GL_TEXTURE0 + tex_unit); + glBindTexture (ctx->tex_target, operand->texture.tex); + _cairo_gl_texture_set_extend (ctx, ctx->tex_target, + operand->texture.attributes.extend); + _cairo_gl_texture_set_filter (ctx, ctx->tex_target, + operand->texture.attributes.filter); + + if (! operand->texture.texgen) { + dispatch->VertexAttribPointer (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit, 2, + GL_FLOAT, GL_FALSE, ctx->vertex_size, + ctx->vb + vertex_offset); + dispatch->EnableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); + } + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + glActiveTexture (GL_TEXTURE0 + tex_unit); + glBindTexture (ctx->tex_target, operand->gradient.gradient->tex); + _cairo_gl_texture_set_extend (ctx, ctx->tex_target, operand->gradient.extend); + _cairo_gl_texture_set_filter (ctx, ctx->tex_target, CAIRO_FILTER_BILINEAR); + + if (! operand->gradient.texgen) { + dispatch->VertexAttribPointer (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit, 2, + GL_FLOAT, GL_FALSE, ctx->vertex_size, + ctx->vb + vertex_offset); + dispatch->EnableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); + } + break; + } +} + +static void +_cairo_gl_context_setup_spans (cairo_gl_context_t *ctx, + cairo_bool_t spans_enabled, + unsigned int vertex_size, + unsigned int vertex_offset) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + + if (! spans_enabled) { + dispatch->DisableVertexAttribArray (CAIRO_GL_COLOR_ATTRIB_INDEX); + ctx->spans = FALSE; + return; + } + + dispatch->VertexAttribPointer (CAIRO_GL_COLOR_ATTRIB_INDEX, 4, + GL_UNSIGNED_BYTE, GL_TRUE, vertex_size, + ctx->vb + vertex_offset); + dispatch->EnableVertexAttribArray (CAIRO_GL_COLOR_ATTRIB_INDEX); + ctx->spans = TRUE; +} + +void +_cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx, + cairo_gl_tex_t tex_unit) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + + if (!_cairo_gl_context_is_flushed (ctx)) + _cairo_gl_composite_flush (ctx); + + switch (ctx->operands[tex_unit].type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + break; + /* fall through */ + case CAIRO_GL_OPERAND_CONSTANT: + break; + case CAIRO_GL_OPERAND_TEXTURE: + dispatch->DisableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + dispatch->DisableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit); + break; + } + + memset (&ctx->operands[tex_unit], 0, sizeof (cairo_gl_operand_t)); +} + +static void +_cairo_gl_set_operator (cairo_gl_context_t *ctx, + cairo_operator_t op, + cairo_bool_t component_alpha) +{ + struct { + GLenum src; + GLenum dst; + } blend_factors[] = { + { GL_ZERO, GL_ZERO }, /* Clear */ + { GL_ONE, GL_ZERO }, /* Source */ + { GL_ONE, GL_ONE_MINUS_SRC_ALPHA }, /* Over */ + { GL_DST_ALPHA, GL_ZERO }, /* In */ + { GL_ONE_MINUS_DST_ALPHA, GL_ZERO }, /* Out */ + { GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, /* Atop */ + + { GL_ZERO, GL_ONE }, /* Dest */ + { GL_ONE_MINUS_DST_ALPHA, GL_ONE }, /* DestOver */ + { GL_ZERO, GL_SRC_ALPHA }, /* DestIn */ + { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }, /* DestOut */ + { GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA }, /* DestAtop */ + + { GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, /* Xor */ + { GL_ONE, GL_ONE }, /* Add */ + }; + GLenum src_factor, dst_factor; + + assert (op < ARRAY_LENGTH (blend_factors)); + /* different dst and component_alpha changes cause flushes elsewhere */ + if (ctx->current_operator != op) + _cairo_gl_composite_flush (ctx); + ctx->current_operator = op; + + src_factor = blend_factors[op].src; + dst_factor = blend_factors[op].dst; + + /* Even when the user requests CAIRO_CONTENT_COLOR, we use GL_RGBA + * due to texture filtering of GL_CLAMP_TO_BORDER. So fix those + * bits in that case. + */ + if (ctx->current_target->base.content == CAIRO_CONTENT_COLOR) { + if (src_factor == GL_ONE_MINUS_DST_ALPHA) + src_factor = GL_ZERO; + if (src_factor == GL_DST_ALPHA) + src_factor = GL_ONE; + } + + if (component_alpha) { + if (dst_factor == GL_ONE_MINUS_SRC_ALPHA) + dst_factor = GL_ONE_MINUS_SRC_COLOR; + if (dst_factor == GL_SRC_ALPHA) + dst_factor = GL_SRC_COLOR; + } + + if (ctx->current_target->base.content == CAIRO_CONTENT_ALPHA) { + glBlendFuncSeparate (GL_ZERO, GL_ZERO, src_factor, dst_factor); + } else if (ctx->current_target->base.content == CAIRO_CONTENT_COLOR) { + glBlendFuncSeparate (src_factor, dst_factor, GL_ONE, GL_ONE); + } else { + glBlendFunc (src_factor, dst_factor); + } +} + +static cairo_status_t +_cairo_gl_composite_begin_component_alpha (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup) +{ + cairo_gl_shader_t *pre_shader = NULL; + cairo_status_t status; + + /* For CLEAR, cairo's rendering equation (quoting Owen's description in: + * http://lists.cairographics.org/archives/cairo/2005-August/004992.html) + * is: + * mask IN clip ? src OP dest : dest + * or more simply: + * mask IN CLIP ? 0 : dest + * + * where the ternary operator A ? B : C is (A * B) + ((1 - A) * C). + * + * The model we use in _cairo_gl_set_operator() is Render's: + * src IN mask IN clip OP dest + * which would boil down to: + * 0 (bounded by the extents of the drawing). + * + * However, we can do a Render operation using an opaque source + * and DEST_OUT to produce: + * 1 IN mask IN clip DEST_OUT dest + * which is + * mask IN clip ? 0 : dest + */ + if (setup->op == CAIRO_OPERATOR_CLEAR) { + _cairo_gl_solid_operand_init (&setup->src, CAIRO_COLOR_WHITE); + setup->op = CAIRO_OPERATOR_DEST_OUT; + } + + /* + * implements component-alpha %CAIRO_OPERATOR_OVER using two passes of + * the simpler operations %CAIRO_OPERATOR_DEST_OUT and %CAIRO_OPERATOR_ADD. + * + * From http://anholt.livejournal.com/32058.html: + * + * The trouble is that component-alpha rendering requires two different sources + * for blending: one for the source value to the blender, which is the + * per-channel multiplication of source and mask, and one for the source alpha + * for multiplying with the destination channels, which is the multiplication + * of the source channels by the mask alpha. So the equation for Over is: + * + * dst.A = src.A * mask.A + (1 - (src.A * mask.A)) * dst.A + * dst.R = src.R * mask.R + (1 - (src.A * mask.R)) * dst.R + * dst.G = src.G * mask.G + (1 - (src.A * mask.G)) * dst.G + * dst.B = src.B * mask.B + (1 - (src.A * mask.B)) * dst.B + * + * But we can do some simpler operations, right? How about PictOpOutReverse, + * which has a source factor of 0 and dest factor of (1 - source alpha). We + * can get the source alpha value (srca.X = src.A * mask.X) out of the texture + * blenders pretty easily. So we can do a component-alpha OutReverse, which + * gets us: + * + * dst.A = 0 + (1 - (src.A * mask.A)) * dst.A + * dst.R = 0 + (1 - (src.A * mask.R)) * dst.R + * dst.G = 0 + (1 - (src.A * mask.G)) * dst.G + * dst.B = 0 + (1 - (src.A * mask.B)) * dst.B + * + * OK. And if an op doesn't use the source alpha value for the destination + * factor, then we can do the channel multiplication in the texture blenders + * to get the source value, and ignore the source alpha that we wouldn't use. + * We've supported this in the Radeon driver for a long time. An example would + * be PictOpAdd, which does: + * + * dst.A = src.A * mask.A + dst.A + * dst.R = src.R * mask.R + dst.R + * dst.G = src.G * mask.G + dst.G + * dst.B = src.B * mask.B + dst.B + * + * Hey, this looks good! If we do a PictOpOutReverse and then a PictOpAdd right + * after it, we get: + * + * dst.A = src.A * mask.A + ((1 - (src.A * mask.A)) * dst.A) + * dst.R = src.R * mask.R + ((1 - (src.A * mask.R)) * dst.R) + * dst.G = src.G * mask.G + ((1 - (src.A * mask.G)) * dst.G) + * dst.B = src.B * mask.B + ((1 - (src.A * mask.B)) * dst.B) + * + * This two-pass trickery could be avoided using a new GL extension that + * lets two values come out of the shader and into the blend unit. + */ + if (setup->op == CAIRO_OPERATOR_OVER) { + setup->op = CAIRO_OPERATOR_ADD; + status = _cairo_gl_get_shader_by_type (ctx, + &setup->src, + &setup->mask, + setup->spans, + CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA, + &pre_shader); + if (unlikely (status)) + return status; + } + + if (ctx->pre_shader != pre_shader) + _cairo_gl_composite_flush (ctx); + ctx->pre_shader = pre_shader; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_scissor_to_doubles (cairo_gl_surface_t *surface, + double x1, double y1, + double x2, double y2) +{ + double height; + + height = y2 - y1; + if (_cairo_gl_surface_is_texture (surface) == FALSE) + y1 = surface->height - (y1 + height); + glScissor (x1, y1, x2 - x1, height); + glEnable (GL_SCISSOR_TEST); +} + +void +_cairo_gl_scissor_to_rectangle (cairo_gl_surface_t *surface, + const cairo_rectangle_int_t *r) +{ + _scissor_to_doubles (surface, r->x, r->y, r->x+r->width, r->y+r->height); +} + +static void +_scissor_to_box (cairo_gl_surface_t *surface, + const cairo_box_t *box) +{ + double x1, y1, x2, y2; + _cairo_box_to_doubles (box, &x1, &y1, &x2, &y2); + _scissor_to_doubles (surface, x1, y1, x2, y2); +} + +static cairo_bool_t +_cairo_gl_composite_setup_vbo (cairo_gl_context_t *ctx, + unsigned int size_per_vertex) +{ + cairo_bool_t vertex_size_changed = ctx->vertex_size != size_per_vertex; + if (vertex_size_changed) { + ctx->vertex_size = size_per_vertex; + _cairo_gl_composite_flush (ctx); + } + + if (_cairo_gl_context_is_flushed (ctx)) { + ctx->dispatch.VertexAttribPointer (CAIRO_GL_VERTEX_ATTRIB_INDEX, 2, + GL_FLOAT, GL_FALSE, size_per_vertex, + ctx->vb); + ctx->dispatch.EnableVertexAttribArray (CAIRO_GL_VERTEX_ATTRIB_INDEX); + } + + return vertex_size_changed; +} + +static void +_disable_stencil_buffer (void) +{ + glDisable (GL_STENCIL_TEST); + glDepthMask (GL_FALSE); +} + +static cairo_int_status_t +_cairo_gl_composite_setup_painted_clipping (cairo_gl_composite_t *setup, + cairo_gl_context_t *ctx, + int vertex_size) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + + cairo_gl_surface_t *dst = setup->dst; + cairo_clip_t *clip = setup->clip; + + if (clip->num_boxes == 1 && clip->path == NULL) { + _scissor_to_box (dst, &clip->boxes[0]); + goto disable_stencil_buffer_and_return; + } + + if (! _cairo_gl_ensure_stencil (ctx, setup->dst)) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto disable_stencil_buffer_and_return; + } + + /* We only want to clear the part of the stencil buffer + * that we are about to use. It also does not hurt to + * scissor around the painted clip. */ + _cairo_gl_scissor_to_rectangle (dst, _cairo_clip_get_extents (clip)); + + /* The clip is not rectangular, so use the stencil buffer. */ + glDepthMask (GL_TRUE); + glEnable (GL_STENCIL_TEST); + + /* Texture surfaces have private depth/stencil buffers, so we can + * rely on any previous clip being cached there. */ + if (_cairo_gl_surface_is_texture (setup->dst)) { + cairo_clip_t *old_clip = setup->dst->clip_on_stencil_buffer; + if (_cairo_clip_equal (old_clip, setup->clip)) + goto activate_stencil_buffer_and_return; + + if (old_clip) { + _cairo_clip_destroy (setup->dst->clip_on_stencil_buffer); + } + + setup->dst->clip_on_stencil_buffer = _cairo_clip_copy (setup->clip); + } + + glClearStencil (0); + glClear (GL_STENCIL_BUFFER_BIT); + + glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE); + glStencilFunc (GL_EQUAL, 1, 0xffffffff); + glColorMask (0, 0, 0, 0); + + status = _cairo_gl_msaa_compositor_draw_clip (ctx, setup, clip); + + if (unlikely (status)) { + glColorMask (1, 1, 1, 1); + goto disable_stencil_buffer_and_return; + } + + /* We want to only render to the stencil buffer, so draw everything now. + Flushing also unbinds the VBO, which we want to rebind for regular + drawing. */ + _cairo_gl_composite_flush (ctx); + _cairo_gl_composite_setup_vbo (ctx, vertex_size); + +activate_stencil_buffer_and_return: + glColorMask (1, 1, 1, 1); + glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); + glStencilFunc (GL_EQUAL, 1, 0xffffffff); + return CAIRO_INT_STATUS_SUCCESS; + +disable_stencil_buffer_and_return: + _disable_stencil_buffer (); + return status; +} + +static cairo_int_status_t +_cairo_gl_composite_setup_clipping (cairo_gl_composite_t *setup, + cairo_gl_context_t *ctx, + int vertex_size) +{ + cairo_bool_t clip_changing = TRUE; + cairo_bool_t clip_region_changing = TRUE; + + if (! ctx->clip && ! setup->clip && ! setup->clip_region && ! ctx->clip_region) + goto disable_all_clipping; + + clip_changing = ! _cairo_clip_equal (ctx->clip, setup->clip); + clip_region_changing = ! cairo_region_equal (ctx->clip_region, setup->clip_region); + if (! _cairo_gl_context_is_flushed (ctx) && + (clip_region_changing || clip_changing)) + _cairo_gl_composite_flush (ctx); + + assert (!setup->clip_region || !setup->clip); + + /* setup->clip is only used by the msaa compositor and setup->clip_region + * only by the other compositors, so it's safe to wait to clean up obsolete + * clips. */ + if (clip_region_changing) { + cairo_region_destroy (ctx->clip_region); + ctx->clip_region = cairo_region_reference (setup->clip_region); + } + if (clip_changing) { + _cairo_clip_destroy (ctx->clip); + ctx->clip = _cairo_clip_copy (setup->clip); + } + + /* For clip regions, we scissor right before drawing. */ + if (setup->clip_region) + goto disable_all_clipping; + + if (setup->clip) + return _cairo_gl_composite_setup_painted_clipping (setup, ctx, + vertex_size); +disable_all_clipping: + _disable_stencil_buffer (); + glDisable (GL_SCISSOR_TEST); + return CAIRO_INT_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gl_set_operands_and_operator (cairo_gl_composite_t *setup, + cairo_gl_context_t *ctx) +{ + unsigned int dst_size, src_size, mask_size, vertex_size; + cairo_status_t status; + cairo_gl_shader_t *shader; + cairo_bool_t component_alpha; + cairo_bool_t vertex_size_changed; + + component_alpha = + setup->mask.type == CAIRO_GL_OPERAND_TEXTURE && + setup->mask.texture.attributes.has_component_alpha; + + /* Do various magic for component alpha */ + if (component_alpha) { + status = _cairo_gl_composite_begin_component_alpha (ctx, setup); + if (unlikely (status)) + return status; + } else { + if (ctx->pre_shader) { + _cairo_gl_composite_flush (ctx); + ctx->pre_shader = NULL; + } + } + + status = _cairo_gl_get_shader_by_type (ctx, + &setup->src, + &setup->mask, + setup->spans, + component_alpha ? + CAIRO_GL_SHADER_IN_CA_SOURCE : + CAIRO_GL_SHADER_IN_NORMAL, + &shader); + if (unlikely (status)) { + ctx->pre_shader = NULL; + return status; + } + if (ctx->current_shader != shader) + _cairo_gl_composite_flush (ctx); + + status = CAIRO_STATUS_SUCCESS; + + dst_size = 2 * sizeof (GLfloat); + src_size = _cairo_gl_operand_get_vertex_size (&setup->src); + mask_size = _cairo_gl_operand_get_vertex_size (&setup->mask); + vertex_size = dst_size + src_size + mask_size; + + if (setup->spans) + vertex_size += sizeof (GLfloat); + + vertex_size_changed = _cairo_gl_composite_setup_vbo (ctx, vertex_size); + + _cairo_gl_context_setup_operand (ctx, CAIRO_GL_TEX_SOURCE, &setup->src, dst_size, vertex_size_changed); + _cairo_gl_context_setup_operand (ctx, CAIRO_GL_TEX_MASK, &setup->mask, dst_size + src_size, vertex_size_changed); + + _cairo_gl_context_setup_spans (ctx, setup->spans, vertex_size, + dst_size + src_size + mask_size); + + _cairo_gl_set_operator (ctx, setup->op, component_alpha); + + if (_cairo_gl_context_is_flushed (ctx)) { + if (ctx->pre_shader) { + _cairo_gl_set_shader (ctx, ctx->pre_shader); + _cairo_gl_composite_bind_to_shader (ctx, setup); + } + _cairo_gl_set_shader (ctx, shader); + _cairo_gl_composite_bind_to_shader (ctx, setup); + } + + return status; +} + +cairo_status_t +_cairo_gl_composite_begin (cairo_gl_composite_t *setup, + cairo_gl_context_t **ctx_out) +{ + cairo_gl_context_t *ctx; + cairo_status_t status; + + assert (setup->dst); + + status = _cairo_gl_context_acquire (setup->dst->base.device, &ctx); + if (unlikely (status)) + return status; + + _cairo_gl_context_set_destination (ctx, setup->dst, setup->multisample); + glEnable (GL_BLEND); + + status = _cairo_gl_set_operands_and_operator (setup, ctx); + if (unlikely (status)) + goto FAIL; + + status = _cairo_gl_composite_setup_clipping (setup, ctx, ctx->vertex_size); + if (unlikely (status)) + goto FAIL; + + *ctx_out = ctx; + +FAIL: + if (unlikely (status)) + status = _cairo_gl_context_release (ctx, status); + + return status; +} + +static inline void +_cairo_gl_composite_draw_tristrip (cairo_gl_context_t *ctx) +{ + cairo_array_t* indices = &ctx->tristrip_indices; + const unsigned short *indices_array = _cairo_array_index_const (indices, 0); + + if (ctx->pre_shader) { + cairo_gl_shader_t *prev_shader = ctx->current_shader; + + _cairo_gl_set_shader (ctx, ctx->pre_shader); + _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_DEST_OUT, TRUE); + glDrawElements (GL_TRIANGLE_STRIP, _cairo_array_num_elements (indices), GL_UNSIGNED_SHORT, indices_array); + + _cairo_gl_set_shader (ctx, prev_shader); + _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_ADD, TRUE); + } + + glDrawElements (GL_TRIANGLE_STRIP, _cairo_array_num_elements (indices), GL_UNSIGNED_SHORT, indices_array); + _cairo_array_truncate (indices, 0); +} + +static inline void +_cairo_gl_composite_draw_triangles (cairo_gl_context_t *ctx, + unsigned int count) +{ + if (! ctx->pre_shader) { + glDrawArrays (GL_TRIANGLES, 0, count); + } else { + cairo_gl_shader_t *prev_shader = ctx->current_shader; + + _cairo_gl_set_shader (ctx, ctx->pre_shader); + _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_DEST_OUT, TRUE); + glDrawArrays (GL_TRIANGLES, 0, count); + + _cairo_gl_set_shader (ctx, prev_shader); + _cairo_gl_set_operator (ctx, CAIRO_OPERATOR_ADD, TRUE); + glDrawArrays (GL_TRIANGLES, 0, count); + } +} + +static void +_cairo_gl_composite_draw_triangles_with_clip_region (cairo_gl_context_t *ctx, + unsigned int count) +{ + int i, num_rectangles; + + if (!ctx->clip_region) { + _cairo_gl_composite_draw_triangles (ctx, count); + return; + } + + num_rectangles = cairo_region_num_rectangles (ctx->clip_region); + for (i = 0; i < num_rectangles; i++) { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (ctx->clip_region, i, &rect); + + _cairo_gl_scissor_to_rectangle (ctx->current_target, &rect); + _cairo_gl_composite_draw_triangles (ctx, count); + } +} + +static void +_cairo_gl_composite_unmap_vertex_buffer (cairo_gl_context_t *ctx) +{ + ctx->vb_offset = 0; +} + +void +_cairo_gl_composite_flush (cairo_gl_context_t *ctx) +{ + unsigned int count; + int i; + + if (_cairo_gl_context_is_flushed (ctx)) + return; + + count = ctx->vb_offset / ctx->vertex_size; + _cairo_gl_composite_unmap_vertex_buffer (ctx); + + if (ctx->primitive_type == CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS) { + _cairo_gl_composite_draw_tristrip (ctx); + } else { + assert (ctx->primitive_type == CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); + _cairo_gl_composite_draw_triangles_with_clip_region (ctx, count); + } + + for (i = 0; i < ARRAY_LENGTH (ctx->glyph_cache); i++) + _cairo_gl_glyph_cache_unlock (&ctx->glyph_cache[i]); +} + +static void +_cairo_gl_composite_prepare_buffer (cairo_gl_context_t *ctx, + unsigned int n_vertices, + cairo_gl_primitive_type_t primitive_type) +{ + if (ctx->primitive_type != primitive_type) { + _cairo_gl_composite_flush (ctx); + ctx->primitive_type = primitive_type; + } + + assert(ctx->vbo_size > 0); + if (ctx->vb_offset + n_vertices * ctx->vertex_size > ctx->vbo_size) + _cairo_gl_composite_flush (ctx); +} + +static inline void +_cairo_gl_composite_emit_vertex (cairo_gl_context_t *ctx, + GLfloat x, GLfloat y) +{ + GLfloat *vb = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; + + *vb++ = x; + *vb++ = y; + + _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_SOURCE], &vb, x, y); + _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_MASK ], &vb, x, y); + + ctx->vb_offset += ctx->vertex_size; +} + +static inline void +_cairo_gl_composite_emit_alpha_vertex (cairo_gl_context_t *ctx, + GLfloat x, GLfloat y, uint8_t alpha) +{ + GLfloat *vb = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; + union fi { + float f; + GLbyte bytes[4]; + } fi; + + *vb++ = x; + *vb++ = y; + + _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_SOURCE], &vb, x, y); + _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_MASK ], &vb, x, y); + + fi.bytes[0] = 0; + fi.bytes[1] = 0; + fi.bytes[2] = 0; + fi.bytes[3] = alpha; + *vb++ = fi.f; + + ctx->vb_offset += ctx->vertex_size; +} + +static void +_cairo_gl_composite_emit_point (cairo_gl_context_t *ctx, + const cairo_point_t *point) +{ + _cairo_gl_composite_emit_vertex (ctx, + _cairo_fixed_to_double (point->x), + _cairo_fixed_to_double (point->y)); +} + +static void +_cairo_gl_composite_emit_rect (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2) +{ + _cairo_gl_composite_prepare_buffer (ctx, 6, + CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); + + _cairo_gl_composite_emit_vertex (ctx, x1, y1); + _cairo_gl_composite_emit_vertex (ctx, x2, y1); + _cairo_gl_composite_emit_vertex (ctx, x1, y2); + + _cairo_gl_composite_emit_vertex (ctx, x2, y1); + _cairo_gl_composite_emit_vertex (ctx, x2, y2); + _cairo_gl_composite_emit_vertex (ctx, x1, y2); +} + +cairo_gl_emit_rect_t +_cairo_gl_context_choose_emit_rect (cairo_gl_context_t *ctx) +{ + return _cairo_gl_composite_emit_rect; +} + +void +_cairo_gl_context_emit_rect (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2) +{ + _cairo_gl_composite_emit_rect (ctx, x1, y1, x2, y2); +} + +static void +_cairo_gl_composite_emit_span (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2, + uint8_t alpha) +{ + _cairo_gl_composite_prepare_buffer (ctx, 6, + CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); + + _cairo_gl_composite_emit_alpha_vertex (ctx, x1, y1, alpha); + _cairo_gl_composite_emit_alpha_vertex (ctx, x2, y1, alpha); + _cairo_gl_composite_emit_alpha_vertex (ctx, x1, y2, alpha); + + _cairo_gl_composite_emit_alpha_vertex (ctx, x2, y1, alpha); + _cairo_gl_composite_emit_alpha_vertex (ctx, x2, y2, alpha); + _cairo_gl_composite_emit_alpha_vertex (ctx, x1, y2, alpha); +} + +static void +_cairo_gl_composite_emit_solid_span (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2, + uint8_t alpha) +{ + GLfloat *v; + union fi { + float f; + GLbyte bytes[4]; + } fi; + + _cairo_gl_composite_prepare_buffer (ctx, 6, + CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); + v = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; + + v[15] = v[ 6] = v[0] = x1; + v[10] = v[ 4] = v[1] = y1; + v[12] = v[ 9] = v[3] = x2; + v[16] = v[13] = v[7] = y2; + + fi.bytes[0] = 0; + fi.bytes[1] = 0; + fi.bytes[2] = 0; + fi.bytes[3] = alpha; + v[17] =v[14] = v[11] = v[8] = v[5] = v[2] = fi.f; + + ctx->vb_offset += 6*3 * sizeof(GLfloat); +} + +cairo_gl_emit_span_t +_cairo_gl_context_choose_emit_span (cairo_gl_context_t *ctx) +{ + if (ctx->operands[CAIRO_GL_TEX_MASK].type != CAIRO_GL_OPERAND_NONE) { + switch (ctx->operands[CAIRO_GL_TEX_MASK].type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + break; + + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + if (!ctx->operands[CAIRO_GL_TEX_MASK].gradient.texgen) + return _cairo_gl_composite_emit_span; + break; + + case CAIRO_GL_OPERAND_TEXTURE: + if (!ctx->operands[CAIRO_GL_TEX_MASK].texture.texgen) + return _cairo_gl_composite_emit_span; + break; + } + } + + switch (ctx->operands[CAIRO_GL_TEX_SOURCE].type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + break; + + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + if (!ctx->operands[CAIRO_GL_TEX_SOURCE].gradient.texgen) + return _cairo_gl_composite_emit_span; + break; + + case CAIRO_GL_OPERAND_TEXTURE: + if (!ctx->operands[CAIRO_GL_TEX_SOURCE].texture.texgen) + return _cairo_gl_composite_emit_span; + } + + return _cairo_gl_composite_emit_solid_span; +} + +static inline void +_cairo_gl_composite_emit_glyph_vertex (cairo_gl_context_t *ctx, + GLfloat x, GLfloat y, + GLfloat glyph_x, GLfloat glyph_y) +{ + GLfloat *vb = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; + + *vb++ = x; + *vb++ = y; + + _cairo_gl_operand_emit (&ctx->operands[CAIRO_GL_TEX_SOURCE], &vb, x, y); + + *vb++ = glyph_x; + *vb++ = glyph_y; + + ctx->vb_offset += ctx->vertex_size; +} + +static void +_cairo_gl_composite_emit_glyph (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2, + GLfloat glyph_x1, GLfloat glyph_y1, + GLfloat glyph_x2, GLfloat glyph_y2) +{ + _cairo_gl_composite_prepare_buffer (ctx, 6, + CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); + + _cairo_gl_composite_emit_glyph_vertex (ctx, x1, y1, glyph_x1, glyph_y1); + _cairo_gl_composite_emit_glyph_vertex (ctx, x2, y1, glyph_x2, glyph_y1); + _cairo_gl_composite_emit_glyph_vertex (ctx, x1, y2, glyph_x1, glyph_y2); + + _cairo_gl_composite_emit_glyph_vertex (ctx, x2, y1, glyph_x2, glyph_y1); + _cairo_gl_composite_emit_glyph_vertex (ctx, x2, y2, glyph_x2, glyph_y2); + _cairo_gl_composite_emit_glyph_vertex (ctx, x1, y2, glyph_x1, glyph_y2); +} + +static void +_cairo_gl_composite_emit_solid_glyph (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2, + GLfloat glyph_x1, GLfloat glyph_y1, + GLfloat glyph_x2, GLfloat glyph_y2) +{ + GLfloat *v; + + _cairo_gl_composite_prepare_buffer (ctx, 6, + CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES); + + v = (GLfloat *) (void *) &ctx->vb[ctx->vb_offset]; + + v[20] = v[ 8] = v[0] = x1; + v[13] = v[ 5] = v[1] = y1; + v[22] = v[10] = v[2] = glyph_x1; + v[15] = v[ 7] = v[3] = glyph_y1; + + v[16] = v[12] = v[4] = x2; + v[18] = v[14] = v[6] = glyph_x2; + + v[21] = v[17] = v[ 9] = y2; + v[23] = v[19] = v[11] = glyph_y2; + + ctx->vb_offset += 4 * 6 * sizeof (GLfloat); +} + +cairo_gl_emit_glyph_t +_cairo_gl_context_choose_emit_glyph (cairo_gl_context_t *ctx) +{ + switch (ctx->operands[CAIRO_GL_TEX_SOURCE].type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + return _cairo_gl_composite_emit_solid_glyph; + + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + case CAIRO_GL_OPERAND_TEXTURE: + return _cairo_gl_composite_emit_glyph; + } +} + +void +_cairo_gl_composite_fini (cairo_gl_composite_t *setup) +{ + _cairo_gl_operand_destroy (&setup->src); + _cairo_gl_operand_destroy (&setup->mask); +} + +cairo_status_t +_cairo_gl_composite_set_operator (cairo_gl_composite_t *setup, + cairo_operator_t op, + cairo_bool_t assume_component_alpha) +{ + if (assume_component_alpha) { + if (op != CAIRO_OPERATOR_CLEAR && + op != CAIRO_OPERATOR_OVER && + op != CAIRO_OPERATOR_ADD) + return UNSUPPORTED ("unsupported component alpha operator"); + } else { + if (! _cairo_gl_operator_is_supported (op)) + return UNSUPPORTED ("unsupported operator"); + } + + setup->op = op; + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gl_composite_init (cairo_gl_composite_t *setup, + cairo_operator_t op, + cairo_gl_surface_t *dst, + cairo_bool_t assume_component_alpha) +{ + cairo_status_t status; + + memset (setup, 0, sizeof (cairo_gl_composite_t)); + + status = _cairo_gl_composite_set_operator (setup, op, + assume_component_alpha); + if (status) + return status; + + setup->dst = dst; + setup->clip_region = dst->clip_region; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_gl_composite_append_vertex_indices (cairo_gl_context_t *ctx, + int number_of_new_indices) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + cairo_array_t *indices = &ctx->tristrip_indices; + int number_of_indices = _cairo_array_num_elements (indices); + unsigned short current_vertex_index = 0; + int i; + + assert (number_of_new_indices > 0); + + /* If any preexisting triangle triangle strip indices exist on this + context, we insert a set of degenerate triangles from the last + preexisting vertex to our first one. */ + if (number_of_indices > 0) { + const unsigned short *indices_array = _cairo_array_index_const (indices, 0); + current_vertex_index = indices_array[number_of_indices - 1]; + + status = _cairo_array_append (indices, ¤t_vertex_index); + if (unlikely (status)) + return status; + + current_vertex_index++; + status =_cairo_array_append (indices, ¤t_vertex_index); + if (unlikely (status)) + return status; + } + + for (i = 0; i < number_of_new_indices; i++) { + status = _cairo_array_append (indices, ¤t_vertex_index); + current_vertex_index++; + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + const cairo_point_t quad[4]) +{ + _cairo_gl_composite_prepare_buffer (ctx, 4, + CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS); + + _cairo_gl_composite_emit_point (ctx, &quad[0]); + _cairo_gl_composite_emit_point (ctx, &quad[1]); + + /* Cairo stores quad vertices in counter-clockwise order, but we need to + emit them from top to bottom in the triangle strip, so we need to reverse + the order of the last two vertices. */ + _cairo_gl_composite_emit_point (ctx, &quad[3]); + _cairo_gl_composite_emit_point (ctx, &quad[2]); + + return _cairo_gl_composite_append_vertex_indices (ctx, 4); +} + +cairo_int_status_t +_cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + const cairo_point_t triangle[3]) +{ + _cairo_gl_composite_prepare_buffer (ctx, 3, + CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS); + + _cairo_gl_composite_emit_point (ctx, &triangle[0]); + _cairo_gl_composite_emit_point (ctx, &triangle[1]); + _cairo_gl_composite_emit_point (ctx, &triangle[2]); + return _cairo_gl_composite_append_vertex_indices (ctx, 3); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-device.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-device.c new file mode 100644 index 00000000000..7235d9ae123 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-device.c @@ -0,0 +1,804 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * Copyright © 2010 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + * Alexandros Frantzis + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-gl-private.h" + +#define MAX_MSAA_SAMPLES 4 + +static void +_gl_lock (void *device) +{ + cairo_gl_context_t *ctx = (cairo_gl_context_t *) device; + + ctx->acquire (ctx); +} + +static void +_gl_unlock (void *device) +{ + cairo_gl_context_t *ctx = (cairo_gl_context_t *) device; + + ctx->release (ctx); +} + +static cairo_status_t +_gl_flush (void *device) +{ + cairo_gl_context_t *ctx; + cairo_status_t status; + + status = _cairo_gl_context_acquire (device, &ctx); + if (unlikely (status)) + return status; + + _cairo_gl_composite_flush (ctx); + + _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_SOURCE); + _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_MASK); + + if (ctx->clip_region) { + cairo_region_destroy (ctx->clip_region); + ctx->clip_region = NULL; + } + + ctx->current_target = NULL; + ctx->current_operator = -1; + ctx->vertex_size = 0; + ctx->pre_shader = NULL; + _cairo_gl_set_shader (ctx, NULL); + + ctx->dispatch.BindBuffer (GL_ARRAY_BUFFER, 0); + + glDisable (GL_SCISSOR_TEST); + glDisable (GL_BLEND); + + return _cairo_gl_context_release (ctx, status); +} + +static void +_gl_finish (void *device) +{ + cairo_gl_context_t *ctx = device; + int n; + + _gl_lock (device); + + _cairo_cache_fini (&ctx->gradients); + + _cairo_gl_context_fini_shaders (ctx); + + for (n = 0; n < ARRAY_LENGTH (ctx->glyph_cache); n++) + _cairo_gl_glyph_cache_fini (ctx, &ctx->glyph_cache[n]); + + _gl_unlock (device); +} + +static void +_gl_destroy (void *device) +{ + cairo_gl_context_t *ctx = device; + + ctx->acquire (ctx); + + while (! cairo_list_is_empty (&ctx->fonts)) { + cairo_gl_font_t *font; + + font = cairo_list_first_entry (&ctx->fonts, + cairo_gl_font_t, + link); + + cairo_list_del (&font->base.link); + cairo_list_del (&font->link); + free (font); + } + + _cairo_array_fini (&ctx->tristrip_indices); + + cairo_region_destroy (ctx->clip_region); + _cairo_clip_destroy (ctx->clip); + + free (ctx->vb); + + ctx->destroy (ctx); + + free (ctx); +} + +static const cairo_device_backend_t _cairo_gl_device_backend = { + CAIRO_DEVICE_TYPE_GL, + + _gl_lock, + _gl_unlock, + + _gl_flush, /* flush */ + _gl_finish, + _gl_destroy, +}; + +static cairo_bool_t +_cairo_gl_msaa_compositor_enabled (void) +{ + const char *env = getenv ("CAIRO_GL_COMPOSITOR"); + return env && strcmp(env, "msaa") == 0; +} + +static cairo_bool_t +test_can_read_bgra (cairo_gl_flavor_t gl_flavor) +{ + /* Desktop GL always supports BGRA formats. */ + if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + return TRUE; + + assert (gl_flavor == CAIRO_GL_FLAVOR_ES); + + /* For OpenGL ES we have to look for the specific extension and BGRA only + * matches cairo's integer packed bytes on little-endian machines. */ + if (!_cairo_is_little_endian()) + return FALSE; + return _cairo_gl_has_extension ("EXT_read_format_bgra"); +} + +cairo_status_t +_cairo_gl_context_init (cairo_gl_context_t *ctx) +{ + cairo_status_t status; + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + int gl_version = _cairo_gl_get_version (); + cairo_gl_flavor_t gl_flavor = _cairo_gl_get_flavor (); + int n; + + cairo_bool_t is_desktop = gl_flavor == CAIRO_GL_FLAVOR_DESKTOP; + cairo_bool_t is_gles = gl_flavor == CAIRO_GL_FLAVOR_ES; + + _cairo_device_init (&ctx->base, &_cairo_gl_device_backend); + + /* XXX The choice of compositor should be made automatically at runtime. + * However, it is useful to force one particular compositor whilst + * testing. + */ + if (_cairo_gl_msaa_compositor_enabled ()) + ctx->compositor = _cairo_gl_msaa_compositor_get (); + else + ctx->compositor = _cairo_gl_span_compositor_get (); + + + ctx->thread_aware = TRUE; + + memset (ctx->glyph_cache, 0, sizeof (ctx->glyph_cache)); + cairo_list_init (&ctx->fonts); + + /* Support only GL version >= 1.3 */ + if (gl_version < CAIRO_GL_VERSION_ENCODE (1, 3)) + return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + + /* Check for required extensions */ + if (is_desktop) { + if (_cairo_gl_has_extension ("GL_ARB_texture_non_power_of_two")) { + ctx->tex_target = GL_TEXTURE_2D; + ctx->has_npot_repeat = TRUE; + } else if (_cairo_gl_has_extension ("GL_ARB_texture_rectangle")) { + ctx->tex_target = GL_TEXTURE_RECTANGLE; + ctx->has_npot_repeat = FALSE; + } else + return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + } else { + ctx->tex_target = GL_TEXTURE_2D; + if (_cairo_gl_has_extension ("GL_OES_texture_npot") || + _cairo_gl_has_extension ("GL_IMG_texture_npot")) + ctx->has_npot_repeat = TRUE; + else + ctx->has_npot_repeat = FALSE; + } + + if (is_desktop && gl_version < CAIRO_GL_VERSION_ENCODE (2, 1) && + ! _cairo_gl_has_extension ("GL_ARB_pixel_buffer_object")) + return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + + if (is_gles && ! _cairo_gl_has_extension ("GL_EXT_texture_format_BGRA8888")) + return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + + ctx->has_map_buffer = + is_desktop || (is_gles && _cairo_gl_has_extension ("GL_OES_mapbuffer")); + + ctx->can_read_bgra = test_can_read_bgra (gl_flavor); + + ctx->has_mesa_pack_invert = + _cairo_gl_has_extension ("GL_MESA_pack_invert"); + + ctx->has_packed_depth_stencil = + (is_desktop && _cairo_gl_has_extension ("GL_EXT_packed_depth_stencil")) || + (is_gles && _cairo_gl_has_extension ("GL_OES_packed_depth_stencil")); + + ctx->num_samples = 1; + +#if CAIRO_HAS_GL_SURFACE + if (is_desktop && ctx->has_packed_depth_stencil && + (gl_version >= CAIRO_GL_VERSION_ENCODE (3, 0) || + _cairo_gl_has_extension ("GL_ARB_framebuffer_object") || + (_cairo_gl_has_extension ("GL_EXT_framebuffer_blit") && + _cairo_gl_has_extension ("GL_EXT_framebuffer_multisample")))) { + glGetIntegerv(GL_MAX_SAMPLES_EXT, &ctx->num_samples); + } +#endif + +#if CAIRO_HAS_GLESV2_SURFACE && defined(GL_MAX_SAMPLES_EXT) + if (is_gles && ctx->has_packed_depth_stencil && + _cairo_gl_has_extension ("GL_EXT_multisampled_render_to_texture")) { + glGetIntegerv(GL_MAX_SAMPLES_EXT, &ctx->num_samples); + } +#endif + +#if CAIRO_HAS_GLESV2_SURFACE && defined(GL_MAX_SAMPLES_IMG) + if (is_gles && ctx->has_packed_depth_stencil && + _cairo_gl_has_extension ("GL_IMG_multisampled_render_to_texture")) { + glGetIntegerv(GL_MAX_SAMPLES_IMG, &ctx->num_samples); + } +#endif + + ctx->supports_msaa = ctx->num_samples > 1; + if (ctx->num_samples > MAX_MSAA_SAMPLES) + ctx->num_samples = MAX_MSAA_SAMPLES; + + + ctx->current_operator = -1; + ctx->gl_flavor = gl_flavor; + + status = _cairo_gl_context_init_shaders (ctx); + if (unlikely (status)) + return status; + + status = _cairo_cache_init (&ctx->gradients, + _cairo_gl_gradient_equal, + NULL, + (cairo_destroy_func_t) _cairo_gl_gradient_destroy, + CAIRO_GL_GRADIENT_CACHE_SIZE); + if (unlikely (status)) + return status; + + ctx->vbo_size = _cairo_gl_get_vbo_size(); + + ctx->vb = malloc (ctx->vbo_size); + if (unlikely (ctx->vb == NULL)) { + _cairo_cache_fini (&ctx->gradients); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + ctx->primitive_type = CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES; + _cairo_array_init (&ctx->tristrip_indices, sizeof (unsigned short)); + + /* PBO for any sort of texture upload */ + dispatch->GenBuffers (1, &ctx->texture_load_pbo); + + ctx->max_framebuffer_size = 0; + glGetIntegerv (GL_MAX_RENDERBUFFER_SIZE, &ctx->max_framebuffer_size); + ctx->max_texture_size = 0; + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &ctx->max_texture_size); + ctx->max_textures = 0; + glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS, &ctx->max_textures); + + for (n = 0; n < ARRAY_LENGTH (ctx->glyph_cache); n++) + _cairo_gl_glyph_cache_init (&ctx->glyph_cache[n]); + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gl_context_activate (cairo_gl_context_t *ctx, + cairo_gl_tex_t tex_unit) +{ + if (ctx->max_textures <= (GLint) tex_unit) { + if (tex_unit < 2) { + _cairo_gl_composite_flush (ctx); + _cairo_gl_context_destroy_operand (ctx, ctx->max_textures - 1); + } + glActiveTexture (ctx->max_textures - 1); + } else { + glActiveTexture (GL_TEXTURE0 + tex_unit); + } +} + +static GLenum +_get_depth_stencil_format (cairo_gl_context_t *ctx) +{ + /* This is necessary to properly handle the situation where both + OpenGL and OpenGLES are active and returning a sane default. */ +#if CAIRO_HAS_GL_SURFACE + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + return GL_DEPTH_STENCIL; +#endif + +#if CAIRO_HAS_GLESV2_SURFACE + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + return GL_DEPTH24_STENCIL8_OES; +#endif + +#if CAIRO_HAS_GL_SURFACE + return GL_DEPTH_STENCIL; +#elif CAIRO_HAS_GLESV2_SURFACE + return GL_DEPTH24_STENCIL8_OES; +#endif +} + +#if CAIRO_HAS_GLESV2_SURFACE +static void +_cairo_gl_ensure_msaa_gles_framebuffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + if (surface->msaa_active) + return; + + ctx->dispatch.FramebufferTexture2DMultisample(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + ctx->tex_target, + surface->tex, + 0, + ctx->num_samples); + + /* From now on MSAA will always be active on this surface. */ + surface->msaa_active = TRUE; +} +#endif + +static void +_cairo_gl_ensure_framebuffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + GLenum status; + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + + if (likely (surface->fb)) + return; + + /* Create a framebuffer object wrapping the texture so that we can render + * to it. + */ + dispatch->GenFramebuffers (1, &surface->fb); + dispatch->BindFramebuffer (GL_FRAMEBUFFER, surface->fb); + + /* Unlike for desktop GL we only maintain one multisampling framebuffer + for OpenGLES since the EXT_multisampled_render_to_texture extension + does not require an explicit multisample resolution. */ +#if CAIRO_HAS_GLESV2_SURFACE + if (surface->supports_msaa && _cairo_gl_msaa_compositor_enabled () && + ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { + _cairo_gl_ensure_msaa_gles_framebuffer (ctx, surface); + } else +#endif + dispatch->FramebufferTexture2D (GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + ctx->tex_target, + surface->tex, + 0); + +#if CAIRO_HAS_GL_SURFACE + glDrawBuffer (GL_COLOR_ATTACHMENT0); + glReadBuffer (GL_COLOR_ATTACHMENT0); +#endif + + status = dispatch->CheckFramebufferStatus (GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + const char *str; + switch (status) { + //case GL_FRAMEBUFFER_UNDEFINED: str= "undefined"; break; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: str= "incomplete attachment"; break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: str= "incomplete/missing attachment"; break; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: str= "incomplete draw buffer"; break; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: str= "incomplete read buffer"; break; + case GL_FRAMEBUFFER_UNSUPPORTED: str= "unsupported"; break; + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: str= "incomplete multiple"; break; + default: str = "unknown error"; break; + } + + fprintf (stderr, + "destination is framebuffer incomplete: %s [%#x]\n", + str, status); + } +} +#if CAIRO_HAS_GL_SURFACE +static void +_cairo_gl_ensure_multisampling (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + assert (surface->supports_msaa); + assert (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP); + + if (surface->msaa_fb) + return; + + /* We maintain a separate framebuffer for multisampling operations. + This allows us to do a fast paint to the non-multisampling framebuffer + when mulitsampling is disabled. */ + ctx->dispatch.GenFramebuffers (1, &surface->msaa_fb); + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->msaa_fb); + ctx->dispatch.GenRenderbuffers (1, &surface->msaa_rb); + ctx->dispatch.BindRenderbuffer (GL_RENDERBUFFER, surface->msaa_rb); + + /* FIXME: For now we assume that textures passed from the outside have GL_RGBA + format, but eventually we need to expose a way for the API consumer to pass + this information. */ + ctx->dispatch.RenderbufferStorageMultisample (GL_RENDERBUFFER, + ctx->num_samples, + GL_RGBA, + surface->width, + surface->height); + ctx->dispatch.FramebufferRenderbuffer (GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, + surface->msaa_rb); + + /* Cairo surfaces start out initialized to transparent (black) */ + glDisable (GL_SCISSOR_TEST); + glClearColor (0, 0, 0, 0); + glClear (GL_COLOR_BUFFER_BIT); +} +#endif + +static cairo_bool_t +_cairo_gl_ensure_msaa_depth_stencil_buffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + if (surface->msaa_depth_stencil) + return TRUE; + + _cairo_gl_ensure_framebuffer (ctx, surface); +#if CAIRO_HAS_GL_SURFACE + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + _cairo_gl_ensure_multisampling (ctx, surface); +#endif + + dispatch->GenRenderbuffers (1, &surface->msaa_depth_stencil); + dispatch->BindRenderbuffer (GL_RENDERBUFFER, + surface->msaa_depth_stencil); + + dispatch->RenderbufferStorageMultisample (GL_RENDERBUFFER, + ctx->num_samples, + _get_depth_stencil_format (ctx), + surface->width, + surface->height); + +#if CAIRO_HAS_GL_SURFACE + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) { + dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, + GL_DEPTH_STENCIL_ATTACHMENT, + GL_RENDERBUFFER, + surface->msaa_depth_stencil); + } +#endif + +#if CAIRO_HAS_GLESV2_SURFACE + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { + dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, + GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, + surface->msaa_depth_stencil); + dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, + GL_STENCIL_ATTACHMENT, + GL_RENDERBUFFER, + surface->msaa_depth_stencil); + } +#endif + + if (dispatch->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + dispatch->DeleteRenderbuffers (1, &surface->msaa_depth_stencil); + surface->msaa_depth_stencil = 0; + return FALSE; + } + + return TRUE; +} + +static cairo_bool_t +_cairo_gl_ensure_depth_stencil_buffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + + if (surface->depth_stencil) + return TRUE; + + _cairo_gl_ensure_framebuffer (ctx, surface); + + dispatch->GenRenderbuffers (1, &surface->depth_stencil); + dispatch->BindRenderbuffer (GL_RENDERBUFFER, surface->depth_stencil); + dispatch->RenderbufferStorage (GL_RENDERBUFFER, + _get_depth_stencil_format (ctx), + surface->width, surface->height); + + dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, + GL_RENDERBUFFER, surface->depth_stencil); + dispatch->FramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, surface->depth_stencil); + if (dispatch->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + dispatch->DeleteRenderbuffers (1, &surface->depth_stencil); + surface->depth_stencil = 0; + return FALSE; + } + + return TRUE; +} + +cairo_bool_t +_cairo_gl_ensure_stencil (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + if (! _cairo_gl_surface_is_texture (surface)) + return TRUE; /* best guess for now, will check later */ + if (! ctx->has_packed_depth_stencil) + return FALSE; + + if (surface->msaa_active) + return _cairo_gl_ensure_msaa_depth_stencil_buffer (ctx, surface); + else + return _cairo_gl_ensure_depth_stencil_buffer (ctx, surface); +} + +/* + * Stores a parallel projection transformation in matrix 'm', + * using column-major order. + * + * This is equivalent to: + * + * glLoadIdentity() + * gluOrtho2D() + * + * The calculation for the ortho tranformation was taken from the + * mesa source code. + */ +static void +_gl_identity_ortho (GLfloat *m, + GLfloat left, GLfloat right, + GLfloat bottom, GLfloat top) +{ +#define M(row,col) m[col*4+row] + M(0,0) = 2.f / (right - left); + M(0,1) = 0.f; + M(0,2) = 0.f; + M(0,3) = -(right + left) / (right - left); + + M(1,0) = 0.f; + M(1,1) = 2.f / (top - bottom); + M(1,2) = 0.f; + M(1,3) = -(top + bottom) / (top - bottom); + + M(2,0) = 0.f; + M(2,1) = 0.f; + M(2,2) = -1.f; + M(2,3) = 0.f; + + M(3,0) = 0.f; + M(3,1) = 0.f; + M(3,2) = 0.f; + M(3,3) = 1.f; +#undef M +} + +#if CAIRO_HAS_GL_SURFACE +static void +bind_multisample_framebuffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + cairo_bool_t stencil_test_enabled; + cairo_bool_t scissor_test_enabled; + + assert (surface->supports_msaa); + assert (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP); + + _cairo_gl_ensure_framebuffer (ctx, surface); + _cairo_gl_ensure_multisampling (ctx, surface); + + if (surface->msaa_active) { + glEnable (GL_MULTISAMPLE); + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->msaa_fb); + return; + } + + _cairo_gl_composite_flush (ctx); + + stencil_test_enabled = glIsEnabled (GL_STENCIL_TEST); + scissor_test_enabled = glIsEnabled (GL_SCISSOR_TEST); + glDisable (GL_STENCIL_TEST); + glDisable (GL_SCISSOR_TEST); + + glEnable (GL_MULTISAMPLE); + + /* The last time we drew to the surface, we were not using multisampling, + so we need to blit from the non-multisampling framebuffer into the + multisampling framebuffer. */ + ctx->dispatch.BindFramebuffer (GL_DRAW_FRAMEBUFFER, surface->msaa_fb); + ctx->dispatch.BindFramebuffer (GL_READ_FRAMEBUFFER, surface->fb); + ctx->dispatch.BlitFramebuffer (0, 0, surface->width, surface->height, + 0, 0, surface->width, surface->height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->msaa_fb); + + if (stencil_test_enabled) + glEnable (GL_STENCIL_TEST); + if (scissor_test_enabled) + glEnable (GL_SCISSOR_TEST); +} +#endif + +#if CAIRO_HAS_GL_SURFACE +static void +bind_singlesample_framebuffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface) +{ + cairo_bool_t stencil_test_enabled; + cairo_bool_t scissor_test_enabled; + + assert (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP); + _cairo_gl_ensure_framebuffer (ctx, surface); + + if (! surface->msaa_active) { + glDisable (GL_MULTISAMPLE); + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->fb); + return; + } + + _cairo_gl_composite_flush (ctx); + + stencil_test_enabled = glIsEnabled (GL_STENCIL_TEST); + scissor_test_enabled = glIsEnabled (GL_SCISSOR_TEST); + glDisable (GL_STENCIL_TEST); + glDisable (GL_SCISSOR_TEST); + + glDisable (GL_MULTISAMPLE); + + /* The last time we drew to the surface, we were using multisampling, + so we need to blit from the multisampling framebuffer into the + non-multisampling framebuffer. */ + ctx->dispatch.BindFramebuffer (GL_DRAW_FRAMEBUFFER, surface->fb); + ctx->dispatch.BindFramebuffer (GL_READ_FRAMEBUFFER, surface->msaa_fb); + ctx->dispatch.BlitFramebuffer (0, 0, surface->width, surface->height, + 0, 0, surface->width, surface->height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->fb); + + if (stencil_test_enabled) + glEnable (GL_STENCIL_TEST); + if (scissor_test_enabled) + glEnable (GL_SCISSOR_TEST); +} +#endif + +void +_cairo_gl_context_bind_framebuffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface, + cairo_bool_t multisampling) +{ + if (_cairo_gl_surface_is_texture (surface)) { + /* OpenGL ES surfaces only have either a multisample framebuffer or a + * singlesample framebuffer, so we cannot switch back and forth. */ + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { + _cairo_gl_ensure_framebuffer (ctx, surface); + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, surface->fb); + return; + } + +#if CAIRO_HAS_GL_SURFACE + if (multisampling) + bind_multisample_framebuffer (ctx, surface); + else + bind_singlesample_framebuffer (ctx, surface); +#endif + } else { + ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, 0); + +#if CAIRO_HAS_GL_SURFACE + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) { + if (multisampling) + glEnable (GL_MULTISAMPLE); + else + glDisable (GL_MULTISAMPLE); + } +#endif + } + + surface->msaa_active = multisampling; +} + +void +_cairo_gl_context_set_destination (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface, + cairo_bool_t multisampling) +{ + cairo_bool_t changing_surface, changing_sampling; + + /* The decision whether or not to use multisampling happens when + * we create an OpenGL ES surface, so we can never switch modes. */ + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) + multisampling = surface->msaa_active; + + changing_surface = ctx->current_target != surface || surface->needs_update; + changing_sampling = surface->msaa_active != multisampling; + if (! changing_surface && ! changing_sampling) + return; + + if (! changing_surface) { + _cairo_gl_composite_flush (ctx); + _cairo_gl_context_bind_framebuffer (ctx, surface, multisampling); + return; + } + + _cairo_gl_composite_flush (ctx); + + ctx->current_target = surface; + surface->needs_update = FALSE; + + if (! _cairo_gl_surface_is_texture (surface)) { + ctx->make_current (ctx, surface); + } + + _cairo_gl_context_bind_framebuffer (ctx, surface, multisampling); + + if (! _cairo_gl_surface_is_texture (surface)) { +#if CAIRO_HAS_GL_SURFACE + glDrawBuffer (GL_BACK_LEFT); + glReadBuffer (GL_BACK_LEFT); +#endif + } + + glDisable (GL_DITHER); + glViewport (0, 0, surface->width, surface->height); + + if (_cairo_gl_surface_is_texture (surface)) + _gl_identity_ortho (ctx->modelviewprojection_matrix, + 0, surface->width, 0, surface->height); + else + _gl_identity_ortho (ctx->modelviewprojection_matrix, + 0, surface->width, surface->height, 0); +} + +void +cairo_gl_device_set_thread_aware (cairo_device_t *device, + cairo_bool_t thread_aware) +{ + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { + _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + return; + } + ((cairo_gl_context_t *) device)->thread_aware = thread_aware; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch-private.h new file mode 100644 index 00000000000..cabf76f0d6b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch-private.h @@ -0,0 +1,129 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Alexandros Frantzis + */ + +#ifndef CAIRO_GL_DISPATCH_PRIVATE_H +#define CAIRO_GL_DISPATCH_PRIVATE_H + +#include "cairo-gl-private.h" +#include + +typedef enum _cairo_gl_dispatch_name { + CAIRO_GL_DISPATCH_NAME_CORE, + CAIRO_GL_DISPATCH_NAME_EXT, + CAIRO_GL_DISPATCH_NAME_ES, + CAIRO_GL_DISPATCH_NAME_COUNT +} cairo_gl_dispatch_name_t; + +typedef struct _cairo_gl_dispatch_entry { + const char *name[CAIRO_GL_DISPATCH_NAME_COUNT]; + size_t offset; +} cairo_gl_dispatch_entry_t; + +#define DISPATCH_ENTRY_ARB(name) { { "gl"#name, "gl"#name"ARB", "gl"#name }, \ + offsetof(cairo_gl_dispatch_t, name) } +#define DISPATCH_ENTRY_EXT(name) { { "gl"#name, "gl"#name"EXT", "gl"#name }, \ + offsetof(cairo_gl_dispatch_t, name) } +#define DISPATCH_ENTRY_ARB_OES(name) { { "gl"#name, "gl"#name"ARB", "gl"#name"OES" }, \ + offsetof(cairo_gl_dispatch_t, name) } +#define DISPATCH_ENTRY_EXT_IMG(name) { { "gl"#name, "gl"#name"EXT", "gl"#name"IMG" }, \ + offsetof(cairo_gl_dispatch_t, name) } +#define DISPATCH_ENTRY_CUSTOM(name, name2) { { "gl"#name, "gl"#name2, "gl"#name }, \ + offsetof(cairo_gl_dispatch_t, name)} +#define DISPATCH_ENTRY_LAST { { NULL, NULL, NULL }, 0 } + +cairo_private cairo_gl_dispatch_entry_t dispatch_buffers_entries[] = { + DISPATCH_ENTRY_ARB (GenBuffers), + DISPATCH_ENTRY_ARB (BindBuffer), + DISPATCH_ENTRY_ARB (BufferData), + DISPATCH_ENTRY_ARB_OES (MapBuffer), + DISPATCH_ENTRY_ARB_OES (UnmapBuffer), + DISPATCH_ENTRY_LAST +}; + +cairo_private cairo_gl_dispatch_entry_t dispatch_shaders_entries[] = { + /* Shaders */ + DISPATCH_ENTRY_CUSTOM (CreateShader, CreateShaderObjectARB), + DISPATCH_ENTRY_ARB (ShaderSource), + DISPATCH_ENTRY_ARB (CompileShader), + DISPATCH_ENTRY_CUSTOM (GetShaderiv, GetObjectParameterivARB), + DISPATCH_ENTRY_CUSTOM (GetShaderInfoLog, GetInfoLogARB), + DISPATCH_ENTRY_CUSTOM (DeleteShader, DeleteObjectARB), + + /* Programs */ + DISPATCH_ENTRY_CUSTOM (CreateProgram, CreateProgramObjectARB), + DISPATCH_ENTRY_CUSTOM (AttachShader, AttachObjectARB), + DISPATCH_ENTRY_CUSTOM (DeleteProgram, DeleteObjectARB), + DISPATCH_ENTRY_ARB (LinkProgram), + DISPATCH_ENTRY_CUSTOM (UseProgram, UseProgramObjectARB), + DISPATCH_ENTRY_CUSTOM (GetProgramiv, GetObjectParameterivARB), + DISPATCH_ENTRY_CUSTOM (GetProgramInfoLog, GetInfoLogARB), + + /* Uniforms */ + DISPATCH_ENTRY_ARB (GetUniformLocation), + DISPATCH_ENTRY_ARB (Uniform1f), + DISPATCH_ENTRY_ARB (Uniform2f), + DISPATCH_ENTRY_ARB (Uniform3f), + DISPATCH_ENTRY_ARB (Uniform4f), + DISPATCH_ENTRY_ARB (UniformMatrix3fv), + DISPATCH_ENTRY_ARB (UniformMatrix4fv), + DISPATCH_ENTRY_ARB (Uniform1i), + + /* Attributes */ + DISPATCH_ENTRY_ARB (BindAttribLocation), + DISPATCH_ENTRY_ARB (VertexAttribPointer), + DISPATCH_ENTRY_ARB (EnableVertexAttribArray), + DISPATCH_ENTRY_ARB (DisableVertexAttribArray), + + DISPATCH_ENTRY_LAST +}; + +cairo_private cairo_gl_dispatch_entry_t dispatch_fbo_entries[] = { + DISPATCH_ENTRY_EXT (GenFramebuffers), + DISPATCH_ENTRY_EXT (BindFramebuffer), + DISPATCH_ENTRY_EXT (FramebufferTexture2D), + DISPATCH_ENTRY_EXT (CheckFramebufferStatus), + DISPATCH_ENTRY_EXT (DeleteFramebuffers), + DISPATCH_ENTRY_EXT (GenRenderbuffers), + DISPATCH_ENTRY_EXT (BindRenderbuffer), + DISPATCH_ENTRY_EXT (RenderbufferStorage), + DISPATCH_ENTRY_EXT (FramebufferRenderbuffer), + DISPATCH_ENTRY_EXT (DeleteRenderbuffers), + DISPATCH_ENTRY_EXT (BlitFramebuffer), + DISPATCH_ENTRY_LAST +}; + +cairo_private cairo_gl_dispatch_entry_t dispatch_multisampling_entries[] = { + DISPATCH_ENTRY_EXT_IMG (RenderbufferStorageMultisample), + DISPATCH_ENTRY_EXT_IMG (FramebufferTexture2DMultisample), + DISPATCH_ENTRY_LAST +}; + +#endif /* CAIRO_GL_DISPATCH_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch.c new file mode 100644 index 00000000000..76c3115ba37 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-dispatch.c @@ -0,0 +1,261 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Alexandros Frantzis + */ + +#include "cairoint.h" +#include "cairo-gl-private.h" +#include "cairo-gl-dispatch-private.h" +#if CAIRO_HAS_DLSYM +#include +#endif + +#if CAIRO_HAS_DLSYM +static void * +_cairo_gl_dispatch_open_lib (void) +{ + return dlopen (NULL, RTLD_LAZY); +} + +static void +_cairo_gl_dispatch_close_lib (void *handle) +{ + dlclose (handle); +} + +static cairo_gl_generic_func_t +_cairo_gl_dispatch_get_proc_addr (void *handle, const char *name) +{ + return (cairo_gl_generic_func_t) dlsym (handle, name); +} +#else +static void * +_cairo_gl_dispatch_open_lib (void) +{ + return NULL; +} + +static void +_cairo_gl_dispatch_close_lib (void *handle) +{ + return; +} + +static cairo_gl_generic_func_t +_cairo_gl_dispatch_get_proc_addr (void *handle, const char *name) +{ + return NULL; +} +#endif /* CAIRO_HAS_DLSYM */ + + +static void +_cairo_gl_dispatch_init_entries (cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr, + cairo_gl_dispatch_entry_t *entries, + cairo_gl_dispatch_name_t dispatch_name) +{ + cairo_gl_dispatch_entry_t *entry = entries; + void *handle = _cairo_gl_dispatch_open_lib (); + + while (entry->name[CAIRO_GL_DISPATCH_NAME_CORE] != NULL) { + void *dispatch_ptr = &((char *) dispatch)[entry->offset]; + const char *name = entry->name[dispatch_name]; + + /* + * In strictly conforming EGL implementations, eglGetProcAddress() can + * be used only to get extension functions, but some of the functions + * we want belong to core GL(ES). If the *GetProcAddress function + * provided by the context fails, try to get the address of the wanted + * GL function using standard system facilities (eg dlsym() in *nix + * systems). + */ + cairo_gl_generic_func_t func = get_proc_addr (name); + if (func == NULL) + func = _cairo_gl_dispatch_get_proc_addr (handle, name); + + *((cairo_gl_generic_func_t *) dispatch_ptr) = func; + + ++entry; + } + + _cairo_gl_dispatch_close_lib (handle); +} + +static cairo_status_t +_cairo_gl_dispatch_init_buffers (cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr, + int gl_version, cairo_gl_flavor_t gl_flavor) +{ + cairo_gl_dispatch_name_t dispatch_name; + + if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + { + if (gl_version >= CAIRO_GL_VERSION_ENCODE (1, 5)) + dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; + else if (_cairo_gl_has_extension ("GL_ARB_vertex_buffer_object")) + dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; + else + return CAIRO_STATUS_DEVICE_ERROR; + } + else if (gl_flavor == CAIRO_GL_FLAVOR_ES && + gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) + { + dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; + } + else + { + return CAIRO_STATUS_DEVICE_ERROR; + } + + _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, + dispatch_buffers_entries, dispatch_name); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_dispatch_init_shaders (cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr, + int gl_version, cairo_gl_flavor_t gl_flavor) +{ + cairo_gl_dispatch_name_t dispatch_name; + + if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + { + if (gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) + dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; + else if (_cairo_gl_has_extension ("GL_ARB_shader_objects")) + dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; + else + return CAIRO_STATUS_DEVICE_ERROR; + } + else if (gl_flavor == CAIRO_GL_FLAVOR_ES && + gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) + { + dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; + } + else + { + return CAIRO_STATUS_DEVICE_ERROR; + } + + _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, + dispatch_shaders_entries, dispatch_name); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_dispatch_init_fbo (cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr, + int gl_version, cairo_gl_flavor_t gl_flavor) +{ + cairo_gl_dispatch_name_t dispatch_name; + + if (gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + { + if (gl_version >= CAIRO_GL_VERSION_ENCODE (3, 0) || + _cairo_gl_has_extension ("GL_ARB_framebuffer_object")) + dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; + else if (_cairo_gl_has_extension ("GL_EXT_framebuffer_object")) + dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; + else + return CAIRO_STATUS_DEVICE_ERROR; + } + else if (gl_flavor == CAIRO_GL_FLAVOR_ES && + gl_version >= CAIRO_GL_VERSION_ENCODE (2, 0)) + { + dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; + } + else + { + return CAIRO_STATUS_DEVICE_ERROR; + } + + _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, + dispatch_fbo_entries, dispatch_name); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_dispatch_init_multisampling (cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr, + int gl_version, + cairo_gl_flavor_t gl_flavor) +{ + /* For the multisampling table, there are two GLES versions of the + * extension, so we put one in the EXT slot and one in the real ES slot.*/ + cairo_gl_dispatch_name_t dispatch_name = CAIRO_GL_DISPATCH_NAME_CORE; + if (gl_flavor == CAIRO_GL_FLAVOR_ES) { + if (_cairo_gl_has_extension ("GL_EXT_multisampled_render_to_texture")) + dispatch_name = CAIRO_GL_DISPATCH_NAME_EXT; + else if (_cairo_gl_has_extension ("GL_IMG_multisampled_render_to_texture")) + dispatch_name = CAIRO_GL_DISPATCH_NAME_ES; + } + _cairo_gl_dispatch_init_entries (dispatch, get_proc_addr, + dispatch_multisampling_entries, + dispatch_name); + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gl_dispatch_init (cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr) +{ + cairo_status_t status; + int gl_version; + cairo_gl_flavor_t gl_flavor; + + gl_version = _cairo_gl_get_version (); + gl_flavor = _cairo_gl_get_flavor (); + + status = _cairo_gl_dispatch_init_buffers (dispatch, get_proc_addr, + gl_version, gl_flavor); + if (status != CAIRO_STATUS_SUCCESS) + return status; + + status = _cairo_gl_dispatch_init_shaders (dispatch, get_proc_addr, + gl_version, gl_flavor); + if (status != CAIRO_STATUS_SUCCESS) + return status; + + status = _cairo_gl_dispatch_init_fbo (dispatch, get_proc_addr, + gl_version, gl_flavor); + if (status != CAIRO_STATUS_SUCCESS) + return status; + + status = _cairo_gl_dispatch_init_multisampling (dispatch, get_proc_addr, + gl_version, gl_flavor); + if (status != CAIRO_STATUS_SUCCESS) + return status; + + return CAIRO_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-ext-def-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-gl-ext-def-private.h new file mode 100644 index 00000000000..a261947bef0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-ext-def-private.h @@ -0,0 +1,143 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Alexandros Frantzis + */ + +#ifndef CAIRO_GL_EXT_DEF_PRIVATE_H +#define CAIRO_GL_EXT_DEF_PRIVATE_H + +#ifndef GL_TEXTURE_RECTANGLE +#define GL_TEXTURE_RECTANGLE 0x84F5 +#endif + +#ifndef GL_ARRAY_BUFFER +#define GL_ARRAY_BUFFER 0x8892 +#endif + +#ifndef GL_STREAM_DRAW +#define GL_STREAM_DRAW 0x88E0 +#endif + +#ifndef GL_WRITE_ONLY +#define GL_WRITE_ONLY 0x88B9 +#endif + +#ifndef GL_PIXEL_UNPACK_BUFFER +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#endif + +#ifndef GL_FRAMEBUFFER +#define GL_FRAMEBUFFER 0x8D40 +#endif + +#ifndef GL_COLOR_ATTACHMENT0 +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#endif + +#ifndef GL_FRAMEBUFFER_COMPLETE +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_FORMATS +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 0x8CDA +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#endif + +#ifndef GL_FRAMEBUFFER_UNSUPPORTED +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#endif + +#ifndef GL_PACK_INVERT_MESA +#define GL_PACK_INVERT_MESA 0x8758 +#endif + +#ifndef GL_CLAMP_TO_BORDER +#define GL_CLAMP_TO_BORDER 0x812D +#endif + +#ifndef GL_BGR +#define GL_BGR 0x80E0 +#endif + +#ifndef GL_BGRA +#define GL_BGRA 0x80E1 +#endif + +#ifndef GL_RGBA8 +#define GL_RGBA8 0x8058 +#endif + +#ifndef GL_UNSIGNED_INT_8_8_8_8 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#endif + +#ifndef GL_UNSIGNED_SHORT_5_6_5_REV +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#endif + +#ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#endif + +#ifndef GL_UNSIGNED_INT_8_8_8_8_REV +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#endif + +#ifndef GL_PACK_ROW_LENGTH +#define GL_PACK_ROW_LENGTH 0x0D02 +#endif + +#ifndef GL_UNPACK_ROW_LENGTH +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#endif + +#ifndef GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#endif + +#endif /* CAIRO_GL_EXT_DEF_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-glyphs.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-glyphs.c new file mode 100644 index 00000000000..8a1a548d939 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-glyphs.c @@ -0,0 +1,503 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * Copyright © 2010 Intel Corporation + * Copyright © 2010 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributors: + * Benjamin Otte + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-rtree-private.h" + +#define GLYPH_CACHE_WIDTH 1024 +#define GLYPH_CACHE_HEIGHT 1024 +#define GLYPH_CACHE_MIN_SIZE 4 +#define GLYPH_CACHE_MAX_SIZE 128 + +typedef struct _cairo_gl_glyph { + cairo_rtree_node_t node; + cairo_scaled_glyph_private_t base; + cairo_scaled_glyph_t *glyph; + cairo_gl_glyph_cache_t *cache; + struct { float x, y; } p1, p2; +} cairo_gl_glyph_t; + +static void +_cairo_gl_node_destroy (cairo_rtree_node_t *node) +{ + cairo_gl_glyph_t *priv = cairo_container_of (node, cairo_gl_glyph_t, node); + cairo_scaled_glyph_t *glyph; + + glyph = priv->glyph; + if (glyph == NULL) + return; + + if (glyph->dev_private_key == priv->cache) { + glyph->dev_private = NULL; + glyph->dev_private_key = NULL; + } + cairo_list_del (&priv->base.link); + priv->glyph = NULL; +} + +static void +_cairo_gl_glyph_fini (cairo_scaled_glyph_private_t *glyph_private, + cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font) +{ + cairo_gl_glyph_t *priv = cairo_container_of (glyph_private, + cairo_gl_glyph_t, + base); + + assert (priv->glyph); + + _cairo_gl_node_destroy (&priv->node); + + /* XXX thread-safety? Probably ok due to the frozen scaled-font. */ + if (! priv->node.pinned) + _cairo_rtree_node_remove (&priv->cache->rtree, &priv->node); + + assert (priv->glyph == NULL); +} + +static cairo_int_status_t +_cairo_gl_glyph_cache_add_glyph (cairo_gl_context_t *ctx, + cairo_gl_glyph_cache_t *cache, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_image_surface_t *glyph_surface = scaled_glyph->surface; + cairo_gl_glyph_t *glyph_private; + cairo_rtree_node_t *node = NULL; + cairo_int_status_t status; + int width, height; + + width = glyph_surface->width; + if (width < GLYPH_CACHE_MIN_SIZE) + width = GLYPH_CACHE_MIN_SIZE; + height = glyph_surface->height; + if (height < GLYPH_CACHE_MIN_SIZE) + height = GLYPH_CACHE_MIN_SIZE; + + /* search for an available slot */ + status = _cairo_rtree_insert (&cache->rtree, width, height, &node); + /* search for an unlocked slot */ + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = _cairo_rtree_evict_random (&cache->rtree, + width, height, &node); + if (status == CAIRO_INT_STATUS_SUCCESS) { + status = _cairo_rtree_node_insert (&cache->rtree, + node, width, height, &node); + } + } + if (status) + return status; + + /* XXX: Make sure we use the mask texture. This should work automagically somehow */ + glActiveTexture (GL_TEXTURE1); + status = _cairo_gl_surface_draw_image (cache->surface, glyph_surface, + 0, 0, + glyph_surface->width, glyph_surface->height, + node->x, node->y, FALSE); + if (unlikely (status)) + return status; + + glyph_private = (cairo_gl_glyph_t *) node; + glyph_private->cache = cache; + glyph_private->glyph = scaled_glyph; + _cairo_scaled_glyph_attach_private (scaled_glyph, + &glyph_private->base, + cache, + _cairo_gl_glyph_fini); + + scaled_glyph->dev_private = glyph_private; + scaled_glyph->dev_private_key = cache; + + /* compute tex coords */ + glyph_private->p1.x = node->x; + glyph_private->p1.y = node->y; + glyph_private->p2.x = node->x + glyph_surface->width; + glyph_private->p2.y = node->y + glyph_surface->height; + if (! _cairo_gl_device_requires_power_of_two_textures (&ctx->base)) { + glyph_private->p1.x /= GLYPH_CACHE_WIDTH; + glyph_private->p2.x /= GLYPH_CACHE_WIDTH; + glyph_private->p1.y /= GLYPH_CACHE_HEIGHT; + glyph_private->p2.y /= GLYPH_CACHE_HEIGHT; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_gl_glyph_t * +_cairo_gl_glyph_cache_lock (cairo_gl_glyph_cache_t *cache, + cairo_scaled_glyph_t *scaled_glyph) +{ + return _cairo_rtree_pin (&cache->rtree, scaled_glyph->dev_private); +} + +static cairo_status_t +cairo_gl_context_get_glyph_cache (cairo_gl_context_t *ctx, + cairo_format_t format, + cairo_gl_glyph_cache_t **cache_out) +{ + cairo_gl_glyph_cache_t *cache; + cairo_content_t content; + + switch (format) { + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_RGB16_565: + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_RGB24: + cache = &ctx->glyph_cache[0]; + content = CAIRO_CONTENT_COLOR_ALPHA; + break; + case CAIRO_FORMAT_A8: + case CAIRO_FORMAT_A1: + cache = &ctx->glyph_cache[1]; + content = CAIRO_CONTENT_ALPHA; + break; + default: + case CAIRO_FORMAT_INVALID: + ASSERT_NOT_REACHED; + return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + } + + if (unlikely (cache->surface == NULL)) { + cairo_surface_t *surface; + + surface = _cairo_gl_surface_create_scratch_for_caching (ctx, + content, + GLYPH_CACHE_WIDTH, + GLYPH_CACHE_HEIGHT); + if (unlikely (surface->status)) + return surface->status; + + _cairo_surface_release_device_reference (surface); + + cache->surface = (cairo_gl_surface_t *)surface; + cache->surface->operand.texture.attributes.has_component_alpha = + content == CAIRO_CONTENT_COLOR_ALPHA; + } + + *cache_out = cache; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +render_glyphs (cairo_gl_surface_t *dst, + int dst_x, int dst_y, + cairo_operator_t op, + cairo_surface_t *source, + cairo_composite_glyphs_info_t *info, + cairo_bool_t *has_component_alpha, + cairo_clip_t *clip) +{ + cairo_format_t last_format = CAIRO_FORMAT_INVALID; + cairo_gl_glyph_cache_t *cache = NULL; + cairo_gl_context_t *ctx; + cairo_gl_emit_glyph_t emit = NULL; + cairo_gl_composite_t setup; + cairo_int_status_t status; + int i = 0; + + TRACE ((stderr, "%s (%d, %d)x(%d, %d)\n", __FUNCTION__, + info->extents.x, info->extents.y, + info->extents.width, info->extents.height)); + + *has_component_alpha = FALSE; + + status = _cairo_gl_context_acquire (dst->base.device, &ctx); + if (unlikely (status)) + return status; + + status = _cairo_gl_composite_init (&setup, op, dst, TRUE); + if (unlikely (status)) + goto FINISH; + + if (source == NULL) { + _cairo_gl_composite_set_solid_source (&setup, CAIRO_COLOR_WHITE); + } else { + _cairo_gl_composite_set_source_operand (&setup, + source_to_operand (source)); + + } + + _cairo_gl_composite_set_clip (&setup, clip); + + for (i = 0; i < info->num_glyphs; i++) { + cairo_scaled_glyph_t *scaled_glyph; + cairo_gl_glyph_t *glyph; + double x_offset, y_offset; + double x1, x2, y1, y2; + + status = _cairo_scaled_glyph_lookup (info->font, + info->glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + if (unlikely (status)) + goto FINISH; + + if (scaled_glyph->surface->width == 0 || + scaled_glyph->surface->height == 0) + { + continue; + } + if (scaled_glyph->surface->format != last_format) { + status = cairo_gl_context_get_glyph_cache (ctx, + scaled_glyph->surface->format, + &cache); + if (unlikely (status)) + goto FINISH; + + last_format = scaled_glyph->surface->format; + + _cairo_gl_composite_set_mask_operand (&setup, &cache->surface->operand); + *has_component_alpha |= cache->surface->operand.texture.attributes.has_component_alpha; + + /* XXX Shoot me. */ + status = _cairo_gl_composite_begin (&setup, &ctx); + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) + goto FINISH; + + emit = _cairo_gl_context_choose_emit_glyph (ctx); + } + + if (scaled_glyph->dev_private_key != cache) { + cairo_scaled_glyph_private_t *priv; + + priv = _cairo_scaled_glyph_find_private (scaled_glyph, cache); + if (priv) { + scaled_glyph->dev_private_key = cache; + scaled_glyph->dev_private = cairo_container_of (priv, + cairo_gl_glyph_t, + base); + } else { + status = _cairo_gl_glyph_cache_add_glyph (ctx, cache, scaled_glyph); + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + /* Cache is full, so flush existing prims and try again. */ + _cairo_gl_composite_flush (ctx); + _cairo_gl_glyph_cache_unlock (cache); + status = _cairo_gl_glyph_cache_add_glyph (ctx, cache, scaled_glyph); + } + + if (unlikely (_cairo_int_status_is_error (status))) + goto FINISH; + } + } + + x_offset = scaled_glyph->surface->base.device_transform.x0; + y_offset = scaled_glyph->surface->base.device_transform.y0; + + x1 = _cairo_lround (info->glyphs[i].x - x_offset - dst_x); + y1 = _cairo_lround (info->glyphs[i].y - y_offset - dst_y); + x2 = x1 + scaled_glyph->surface->width; + y2 = y1 + scaled_glyph->surface->height; + + glyph = _cairo_gl_glyph_cache_lock (cache, scaled_glyph); + assert (emit); + emit (ctx, + x1, y1, x2, y2, + glyph->p1.x, glyph->p1.y, + glyph->p2.x, glyph->p2.y); + } + + status = CAIRO_STATUS_SUCCESS; + FINISH: + status = _cairo_gl_context_release (ctx, status); + + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_int_status_t +render_glyphs_via_mask (cairo_gl_surface_t *dst, + int dst_x, int dst_y, + cairo_operator_t op, + cairo_surface_t *source, + cairo_composite_glyphs_info_t *info, + cairo_clip_t *clip) +{ + cairo_surface_t *mask; + cairo_status_t status; + cairo_bool_t has_component_alpha; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + /* XXX: For non-CA, this should be CAIRO_CONTENT_ALPHA to save memory */ + mask = cairo_gl_surface_create (dst->base.device, + CAIRO_CONTENT_COLOR_ALPHA, + info->extents.width, + info->extents.height); + if (unlikely (mask->status)) + return mask->status; + + status = render_glyphs ((cairo_gl_surface_t *) mask, + info->extents.x, info->extents.y, + CAIRO_OPERATOR_ADD, NULL, + info, &has_component_alpha, NULL); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + cairo_surface_pattern_t mask_pattern; + cairo_surface_pattern_t source_pattern; + cairo_rectangle_int_t clip_extents; + + mask->is_clear = FALSE; + _cairo_pattern_init_for_surface (&mask_pattern, mask); + mask_pattern.base.has_component_alpha = has_component_alpha; + mask_pattern.base.filter = CAIRO_FILTER_NEAREST; + mask_pattern.base.extend = CAIRO_EXTEND_NONE; + + cairo_matrix_init_translate (&mask_pattern.base.matrix, + dst_x-info->extents.x, dst_y-info->extents.y); + + _cairo_pattern_init_for_surface (&source_pattern, source); + cairo_matrix_init_translate (&source_pattern.base.matrix, + dst_x-info->extents.x, dst_y-info->extents.y); + + clip = _cairo_clip_copy (clip); + clip_extents.x = info->extents.x - dst_x; + clip_extents.y = info->extents.y - dst_y; + clip_extents.width = info->extents.width; + clip_extents.height = info->extents.height; + clip = _cairo_clip_intersect_rectangle (clip, &clip_extents); + + status = _cairo_surface_mask (&dst->base, op, + &source_pattern.base, + &mask_pattern.base, + clip); + + _cairo_clip_destroy (clip); + + _cairo_pattern_fini (&mask_pattern.base); + _cairo_pattern_fini (&source_pattern.base); + } + + cairo_surface_destroy (mask); + + return status; +} + +cairo_int_status_t +_cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs) +{ + if (! _cairo_gl_operator_is_supported (extents->op)) + return UNSUPPORTED ("unsupported operator"); + + /* XXX use individual masks for large glyphs? */ + if (ceil (scaled_font->max_scale) >= GLYPH_CACHE_MAX_SIZE) + return UNSUPPORTED ("glyphs too large"); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_gl_composite_glyphs_with_clip (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info, + cairo_clip_t *clip) +{ + cairo_gl_surface_t *dst = _dst; + cairo_bool_t has_component_alpha; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + /* If any of the glyphs require component alpha, we have to go through + * a mask, since only _cairo_gl_surface_composite() currently supports + * component alpha. + */ + if (!dst->base.is_clear && ! info->use_mask && op != CAIRO_OPERATOR_OVER && + (info->font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL || + info->font->options.antialias == CAIRO_ANTIALIAS_BEST)) + { + info->use_mask = TRUE; + } + + if (info->use_mask) { + return render_glyphs_via_mask (dst, dst_x, dst_y, + op, _src, info, clip); + } else { + return render_glyphs (dst, dst_x, dst_y, + op, _src, info, + &has_component_alpha, + clip); + } + +} + +cairo_int_status_t +_cairo_gl_composite_glyphs (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + return _cairo_gl_composite_glyphs_with_clip (_dst, op, _src, src_x, src_y, + dst_x, dst_y, info, NULL); +} + +void +_cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache) +{ + _cairo_rtree_init (&cache->rtree, + GLYPH_CACHE_WIDTH, + GLYPH_CACHE_HEIGHT, + GLYPH_CACHE_MIN_SIZE, + sizeof (cairo_gl_glyph_t), + _cairo_gl_node_destroy); +} + +void +_cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx, + cairo_gl_glyph_cache_t *cache) +{ + _cairo_rtree_fini (&cache->rtree); + cairo_surface_destroy (&cache->surface->base); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient-private.h new file mode 100644 index 00000000000..77f9bbdc5f5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient-private.h @@ -0,0 +1,93 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + */ + +#ifndef CAIRO_GL_GRADIENT_PRIVATE_H +#define CAIRO_GL_GRADIENT_PRIVATE_H + +#define GL_GLEXT_PROTOTYPES + +#include "cairo-cache-private.h" +#include "cairo-device-private.h" +#include "cairo-reference-count-private.h" +#include "cairo-pattern-private.h" +#include "cairo-types-private.h" + +#include "cairo-gl.h" + +#if CAIRO_HAS_GL_SURFACE +#include +#include +#elif CAIRO_HAS_GLESV2_SURFACE +#include +#include +#endif + +#define CAIRO_GL_GRADIENT_CACHE_SIZE 4096 + +/* XXX: Declare in a better place */ +typedef struct _cairo_gl_context cairo_gl_context_t; + +typedef struct _cairo_gl_gradient { + cairo_cache_entry_t cache_entry; + cairo_reference_count_t ref_count; + cairo_device_t *device; /* NB: we don't hold a reference */ + GLuint tex; + unsigned int n_stops; + const cairo_gradient_stop_t *stops; + cairo_gradient_stop_t stops_embedded[1]; +} cairo_gl_gradient_t; + +cairo_private cairo_int_status_t +_cairo_gl_gradient_create (cairo_gl_context_t *ctx, + unsigned int n_stops, + const cairo_gradient_stop_t *stops, + cairo_gl_gradient_t **gradient_out); + +cairo_private_no_warn cairo_gl_gradient_t * +_cairo_gl_gradient_reference (cairo_gl_gradient_t *gradient); + +cairo_private void +_cairo_gl_gradient_destroy (cairo_gl_gradient_t *gradient); + +cairo_private cairo_bool_t +_cairo_gl_gradient_equal (const void *key_a, const void *key_b); + + +#endif /* CAIRO_GL_GRADIENT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient.c new file mode 100644 index 00000000000..ac3292101ec --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-gradient.c @@ -0,0 +1,338 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-gl-gradient-private.h" +#include "cairo-gl-private.h" + + +static int +_cairo_gl_gradient_sample_width (unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + unsigned int n; + int width; + + width = 8; + for (n = 1; n < n_stops; n++) { + double dx = stops[n].offset - stops[n-1].offset; + double delta, max; + int ramp; + + if (dx == 0) + return 1024; /* we need to emulate an infinitely sharp step */ + + max = fabs (stops[n].color.red - stops[n-1].color.red); + + delta = fabs (stops[n].color.green - stops[n-1].color.green); + if (delta > max) + max = delta; + + delta = fabs (stops[n].color.blue - stops[n-1].color.blue); + if (delta > max) + max = delta; + + delta = fabs (stops[n].color.alpha - stops[n-1].color.alpha); + if (delta > max) + max = delta; + + ramp = 128 * max / dx; + if (ramp > width) + width = ramp; + } + + return (width + 7) & -8; +} + +static uint8_t premultiply(double c, double a) +{ + int v = c * a * 256; + return v - (v >> 8); +} + +static uint32_t color_stop_to_pixel(const cairo_gradient_stop_t *stop) +{ + uint8_t a, r, g, b; + + a = stop->color.alpha_short >> 8; + r = premultiply(stop->color.red, stop->color.alpha); + g = premultiply(stop->color.green, stop->color.alpha); + b = premultiply(stop->color.blue, stop->color.alpha); + + if (_cairo_is_little_endian ()) + return a << 24 | r << 16 | g << 8 | b << 0; + else + return a << 0 | r << 8 | g << 16 | b << 24; +} + +static cairo_status_t +_cairo_gl_gradient_render (const cairo_gl_context_t *ctx, + unsigned int n_stops, + const cairo_gradient_stop_t *stops, + void *bytes, + int width) +{ + pixman_image_t *gradient, *image; + pixman_gradient_stop_t pixman_stops_stack[32]; + pixman_gradient_stop_t *pixman_stops; + pixman_point_fixed_t p1, p2; + unsigned int i; + pixman_format_code_t gradient_pixman_format; + + /* + * Ensure that the order of the gradient's components in memory is BGRA. + * This is done so that the gradient's pixel data is always suitable for + * texture upload using format=GL_BGRA and type=GL_UNSIGNED_BYTE. + */ + if (_cairo_is_little_endian ()) + gradient_pixman_format = PIXMAN_a8r8g8b8; + else + gradient_pixman_format = PIXMAN_b8g8r8a8; + + pixman_stops = pixman_stops_stack; + if (unlikely (n_stops > ARRAY_LENGTH (pixman_stops_stack))) { + pixman_stops = _cairo_malloc_ab (n_stops, + sizeof (pixman_gradient_stop_t)); + if (unlikely (pixman_stops == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + for (i = 0; i < n_stops; i++) { + pixman_stops[i].x = _cairo_fixed_16_16_from_double (stops[i].offset); + pixman_stops[i].color.red = stops[i].color.red_short; + pixman_stops[i].color.green = stops[i].color.green_short; + pixman_stops[i].color.blue = stops[i].color.blue_short; + pixman_stops[i].color.alpha = stops[i].color.alpha_short; + } + + p1.x = _cairo_fixed_16_16_from_double (0.5); + p1.y = 0; + p2.x = _cairo_fixed_16_16_from_double (width - 0.5); + p2.y = 0; + + gradient = pixman_image_create_linear_gradient (&p1, &p2, + pixman_stops, + n_stops); + if (pixman_stops != pixman_stops_stack) + free (pixman_stops); + + if (unlikely (gradient == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + pixman_image_set_filter (gradient, PIXMAN_FILTER_BILINEAR, NULL, 0); + pixman_image_set_repeat (gradient, PIXMAN_REPEAT_PAD); + + image = pixman_image_create_bits (gradient_pixman_format, width, 1, + bytes, sizeof(uint32_t)*width); + if (unlikely (image == NULL)) { + pixman_image_unref (gradient); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pixman_image_composite32 (PIXMAN_OP_SRC, + gradient, NULL, image, + 0, 0, + 0, 0, + 0, 0, + width, 1); + + pixman_image_unref (gradient); + pixman_image_unref (image); + + /* We need to fudge pixel 0 to hold the left-most color stop and not + * the neareset stop to the zeroth pixel centre in order to correctly + * populate the border color. For completeness, do both edges. + */ + ((uint32_t*)bytes)[0] = color_stop_to_pixel(&stops[0]); + ((uint32_t*)bytes)[width-1] = color_stop_to_pixel(&stops[n_stops-1]); + + return CAIRO_STATUS_SUCCESS; +} + +static unsigned long +_cairo_gl_gradient_hash (unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + return _cairo_hash_bytes (n_stops, + stops, + sizeof (cairo_gradient_stop_t) * n_stops); +} + +static cairo_gl_gradient_t * +_cairo_gl_gradient_lookup (cairo_gl_context_t *ctx, + unsigned long hash, + unsigned int n_stops, + const cairo_gradient_stop_t *stops) +{ + cairo_gl_gradient_t lookup; + + lookup.cache_entry.hash = hash, + lookup.n_stops = n_stops; + lookup.stops = stops; + + return _cairo_cache_lookup (&ctx->gradients, &lookup.cache_entry); +} + +cairo_bool_t +_cairo_gl_gradient_equal (const void *key_a, const void *key_b) +{ + const cairo_gl_gradient_t *a = key_a; + const cairo_gl_gradient_t *b = key_b; + + if (a->n_stops != b->n_stops) + return FALSE; + + return memcmp (a->stops, b->stops, a->n_stops * sizeof (cairo_gradient_stop_t)) == 0; +} + +cairo_int_status_t +_cairo_gl_gradient_create (cairo_gl_context_t *ctx, + unsigned int n_stops, + const cairo_gradient_stop_t *stops, + cairo_gl_gradient_t **gradient_out) +{ + unsigned long hash; + cairo_gl_gradient_t *gradient; + cairo_status_t status; + int tex_width; + GLint internal_format; + void *data; + + if ((unsigned int) ctx->max_texture_size / 2 <= n_stops) + return CAIRO_INT_STATUS_UNSUPPORTED; + + hash = _cairo_gl_gradient_hash (n_stops, stops); + + gradient = _cairo_gl_gradient_lookup (ctx, hash, n_stops, stops); + if (gradient) { + *gradient_out = _cairo_gl_gradient_reference (gradient); + return CAIRO_STATUS_SUCCESS; + } + + gradient = malloc (sizeof (cairo_gl_gradient_t) + sizeof (cairo_gradient_stop_t) * (n_stops - 1)); + if (gradient == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + tex_width = _cairo_gl_gradient_sample_width (n_stops, stops); + if (tex_width > ctx->max_texture_size) + tex_width = ctx->max_texture_size; + + CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 2); + gradient->cache_entry.hash = hash; + gradient->cache_entry.size = tex_width; + gradient->device = &ctx->base; + gradient->n_stops = n_stops; + gradient->stops = gradient->stops_embedded; + memcpy (gradient->stops_embedded, stops, n_stops * sizeof (cairo_gradient_stop_t)); + + glGenTextures (1, &gradient->tex); + _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); + glBindTexture (ctx->tex_target, gradient->tex); + + data = _cairo_malloc_ab (tex_width, sizeof (uint32_t)); + if (unlikely (data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup_gradient; + } + + status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width); + if (unlikely (status)) + goto cleanup_data; + + /* + * In OpenGL ES 2.0 no format conversion is allowed i.e. 'internalFormat' + * must match 'format' in glTexImage2D. + */ + if (_cairo_gl_get_flavor () == CAIRO_GL_FLAVOR_ES) + internal_format = GL_BGRA; + else + internal_format = GL_RGBA; + + glTexImage2D (ctx->tex_target, 0, internal_format, tex_width, 1, 0, + GL_BGRA, GL_UNSIGNED_BYTE, data); + + free (data); + + /* we ignore errors here and just return an uncached gradient */ + if (unlikely (_cairo_cache_insert (&ctx->gradients, &gradient->cache_entry))) + CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 1); + + *gradient_out = gradient; + return CAIRO_STATUS_SUCCESS; + +cleanup_data: + free (data); +cleanup_gradient: + free (gradient); + return status; +} + +cairo_gl_gradient_t * +_cairo_gl_gradient_reference (cairo_gl_gradient_t *gradient) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); + + _cairo_reference_count_inc (&gradient->ref_count); + + return gradient; +} + +void +_cairo_gl_gradient_destroy (cairo_gl_gradient_t *gradient) +{ + cairo_gl_context_t *ctx; + cairo_status_t ignore; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&gradient->ref_count)) + return; + + if (_cairo_gl_context_acquire (gradient->device, &ctx) == CAIRO_STATUS_SUCCESS) { + /* The gradient my still be active in the last operation, so flush */ + _cairo_gl_composite_flush (ctx); + glDeleteTextures (1, &gradient->tex); + ignore = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + } + + free (gradient); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-info.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-info.c new file mode 100644 index 00000000000..acefbb91059 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-info.c @@ -0,0 +1,111 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Alexandros Frantzis + */ + +#include "cairoint.h" +#include "cairo-gl-private.h" + +#include + +int +_cairo_gl_get_version (void) +{ + int major, minor; + const char *version = (const char *) glGetString (GL_VERSION); + const char *dot = version == NULL ? NULL : strchr (version, '.'); + const char *major_start = dot; + + /* Sanity check */ + if (dot == NULL || dot == version || *(dot + 1) == '\0') { + major = 0; + minor = 0; + } else { + /* Find the start of the major version in the string */ + while (major_start > version && *major_start != ' ') + --major_start; + major = strtol (major_start, NULL, 10); + minor = strtol (dot + 1, NULL, 10); + } + + return CAIRO_GL_VERSION_ENCODE (major, minor); +} + +cairo_gl_flavor_t +_cairo_gl_get_flavor (void) +{ + const char *version = (const char *) glGetString (GL_VERSION); + cairo_gl_flavor_t flavor; + + if (version == NULL) + flavor = CAIRO_GL_FLAVOR_NONE; + else if (strstr (version, "OpenGL ES") != NULL) + flavor = CAIRO_GL_FLAVOR_ES; + else + flavor = CAIRO_GL_FLAVOR_DESKTOP; + + return flavor; +} + +unsigned long +_cairo_gl_get_vbo_size (void) +{ + unsigned long vbo_size; + + const char *env = getenv ("CAIRO_GL_VBO_SIZE"); + if (env == NULL) { + vbo_size = CAIRO_GL_VBO_SIZE_DEFAULT; + } else { + errno = 0; + vbo_size = strtol (env, NULL, 10); + assert (errno == 0); + assert (vbo_size > 0); + } + + return vbo_size; +} + +cairo_bool_t +_cairo_gl_has_extension (const char *ext) +{ + const char *extensions = (const char *) glGetString (GL_EXTENSIONS); + size_t len = strlen (ext); + const char *ext_ptr = extensions; + + if (unlikely (ext_ptr == NULL)) + return 0; + + while ((ext_ptr = strstr (ext_ptr, ext)) != NULL) { + if (ext_ptr[len] == ' ' || ext_ptr[len] == '\0') + break; + ext_ptr += len; + } + + return (ext_ptr != NULL); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-msaa-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-msaa-compositor.c new file mode 100644 index 00000000000..83e8eb2d160 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-msaa-compositor.c @@ -0,0 +1,944 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * Copyright © 2011 Samsung Electronics + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Henry Song + * Martin Robinson + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-gl-private.h" +#include "cairo-path-private.h" +#include "cairo-traps-private.h" + +static cairo_bool_t +can_use_msaa_compositor (cairo_gl_surface_t *surface, + cairo_antialias_t antialias); + +static void +query_surface_capabilities (cairo_gl_surface_t *surface); + +struct _tristrip_composite_info { + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; +}; + +static cairo_int_status_t +_draw_trap (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_trapezoid_t *trap) +{ + cairo_point_t quad[4]; + + quad[0].x = _cairo_edge_compute_intersection_x_for_y (&trap->left.p1, + &trap->left.p2, + trap->top); + quad[0].y = trap->top; + + quad[1].x = _cairo_edge_compute_intersection_x_for_y (&trap->left.p1, + &trap->left.p2, + trap->bottom); + quad[1].y = trap->bottom; + + quad[2].x = _cairo_edge_compute_intersection_x_for_y (&trap->right.p1, + &trap->right.p2, + trap->bottom); + quad[2].y = trap->bottom; + + quad[3].x = _cairo_edge_compute_intersection_x_for_y (&trap->right.p1, + &trap->right.p2, + trap->top); + quad[3].y = trap->top; + return _cairo_gl_composite_emit_quad_as_tristrip (ctx, setup, quad); +} + +static cairo_int_status_t +_draw_traps (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_traps_t *traps) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + int i; + + for (i = 0; i < traps->num_traps; i++) { + cairo_trapezoid_t *trap = traps->traps + i; + if (unlikely ((status = _draw_trap (ctx, setup, trap)))) + return status; + } + + return status; +} + +static cairo_int_status_t +_draw_int_rect (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_rectangle_int_t *rect) +{ + cairo_box_t box; + cairo_point_t quad[4]; + + _cairo_box_from_rectangle (&box, rect); + quad[0].x = box.p1.x; + quad[0].y = box.p1.y; + quad[1].x = box.p1.x; + quad[1].y = box.p2.y; + quad[2].x = box.p2.x; + quad[2].y = box.p2.y; + quad[3].x = box.p2.x; + quad[3].y = box.p1.y; + + return _cairo_gl_composite_emit_quad_as_tristrip (ctx, setup, quad); +} + +static cairo_int_status_t +_draw_triangle_fan (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + const cairo_point_t *midpt, + const cairo_point_t *points, + int npoints) +{ + int i; + + /* Our strategy here is to not even try to build a triangle fan, but to + draw each triangle as if it was an unconnected member of a triangle strip. */ + for (i = 1; i < npoints; i++) { + cairo_int_status_t status; + cairo_point_t triangle[3]; + + triangle[0] = *midpt; + triangle[1] = points[i - 1]; + triangle[2] = points[i]; + + status = _cairo_gl_composite_emit_triangle_as_tristrip (ctx, setup, triangle); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_clip_to_traps (cairo_clip_t *clip, + cairo_traps_t *traps) +{ + cairo_int_status_t status; + cairo_polygon_t polygon; + cairo_antialias_t antialias; + cairo_fill_rule_t fill_rule; + + _cairo_traps_init (traps); + + if (clip->num_boxes == 1 && clip->path == NULL) { + cairo_boxes_t boxes; + _cairo_boxes_init_for_array (&boxes, clip->boxes, clip->num_boxes); + return _cairo_traps_init_boxes (traps, &boxes); + } + + status = _cairo_clip_get_polygon (clip, &polygon, &fill_rule, &antialias); + if (unlikely (status)) + return status; + + /* We ignore the antialias mode of the clip here, since the user requested + * unantialiased rendering of their path and we expect that this stencil + * based rendering of the clip to be a reasonable approximation to + * the intersection between that clip and the path. + * + * In other words, what the user expects when they try to perform + * a geometric intersection between an unantialiased polygon and an + * antialiased polygon is open to interpretation. And we choose the fast + * option. + */ + + _cairo_traps_init (traps); + status = _cairo_bentley_ottmann_tessellate_polygon (traps, + &polygon, + fill_rule); + _cairo_polygon_fini (&polygon); + + return status; +} + +cairo_int_status_t +_cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_clip_t *clip) +{ + cairo_int_status_t status; + cairo_traps_t traps; + + status = _clip_to_traps (clip, &traps); + if (unlikely (status)) + return status; + status = _draw_traps (ctx, setup, &traps); + + _cairo_traps_fini (&traps); + return status; +} + +static cairo_bool_t +_should_use_unbounded_surface (cairo_composite_rectangles_t *composite) +{ + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + cairo_rectangle_int_t *source = &composite->source; + + if (composite->is_bounded) + return FALSE; + + /* This isn't just an optimization. It also detects when painting is used + to paint back the unbounded surface, preventing infinite recursion. */ + return ! (source->x <= 0 && source->y <= 0 && + source->height + source->y >= dst->height && + source->width + source->x >= dst->width); +} + +static cairo_surface_t* +_prepare_unbounded_surface (cairo_gl_surface_t *dst) +{ + + cairo_surface_t* surface = cairo_gl_surface_create (dst->base.device, + dst->base.content, + dst->width, + dst->height); + if (surface == NULL) + return NULL; + if (unlikely (surface->status)) { + cairo_surface_destroy (surface); + return NULL; + } + return surface; +} + +static cairo_int_status_t +_paint_back_unbounded_surface (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + cairo_surface_t *surface) +{ + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + cairo_int_status_t status; + + cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface); + if (unlikely (pattern->status)) { + status = pattern->status; + goto finish; + } + + status = _cairo_compositor_paint (compositor, &dst->base, + composite->op, pattern, + composite->clip); + +finish: + cairo_pattern_destroy (pattern); + cairo_surface_destroy (surface); + return status; +} + +static cairo_bool_t +can_use_msaa_compositor (cairo_gl_surface_t *surface, + cairo_antialias_t antialias) +{ + query_surface_capabilities (surface); + if (! surface->supports_stencil) + return FALSE; + + /* Multisampling OpenGL ES surfaces only maintain one multisampling + framebuffer and thus must use the spans compositor to do non-antialiased + rendering. */ + if (((cairo_gl_context_t *) surface->base.device)->gl_flavor == CAIRO_GL_FLAVOR_ES + && surface->supports_msaa + && antialias == CAIRO_ANTIALIAS_NONE) + return FALSE; + + /* The MSAA compositor has a single-sample mode, so we can + support non-antialiased rendering. */ + if (antialias == CAIRO_ANTIALIAS_NONE) + return TRUE; + + if (antialias == CAIRO_ANTIALIAS_FAST || antialias == CAIRO_ANTIALIAS_DEFAULT) + return surface->supports_msaa; + return FALSE; +} + +static void +_cairo_gl_msaa_compositor_set_clip (cairo_composite_rectangles_t *composite, + cairo_gl_composite_t *setup) +{ + if (_cairo_composite_rectangles_can_reduce_clip (composite, composite->clip)) + return; + _cairo_gl_composite_set_clip (setup, composite->clip); +} + +/* Masking with the SOURCE operator requires two passes. In the first + * pass we use the mask as the source to get: + * result = (1 - ma) * dst + * In the second pass we use the add operator to achieve: + * result = (src * ma) + dst + * Combined this produces: + * result = (src * ma) + (1 - ma) * dst + */ +static cairo_int_status_t +_cairo_gl_msaa_compositor_mask_source_operator (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite) +{ + cairo_gl_composite_t setup; + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + cairo_gl_context_t *ctx = NULL; + cairo_int_status_t status; + + cairo_clip_t *clip = composite->clip; + cairo_traps_t traps; + + /* If we have a non-rectangular clip, we can avoid using the stencil buffer + * for clipping and just draw the clip polygon. */ + if (clip) { + status = _clip_to_traps (clip, &traps); + if (unlikely (status)) { + _cairo_traps_fini (&traps); + return status; + } + } + + status = _cairo_gl_composite_init (&setup, + CAIRO_OPERATOR_DEST_OUT, + dst, + FALSE /* assume_component_alpha */); + if (unlikely (status)) + return status; + status = _cairo_gl_composite_set_source (&setup, + &composite->mask_pattern.base, + &composite->mask_sample_area, + &composite->bounded, + FALSE); + if (unlikely (status)) + goto finish; + _cairo_gl_composite_set_multisample (&setup); + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto finish; + + if (! clip) + status = _draw_int_rect (ctx, &setup, &composite->bounded); + else + status = _draw_traps (ctx, &setup, &traps); + if (unlikely (status)) + goto finish; + + /* Now draw the second pass. */ + status = _cairo_gl_composite_set_operator (&setup, CAIRO_OPERATOR_ADD, + FALSE /* assume_component_alpha */); + if (unlikely (status)) + goto finish; + status = _cairo_gl_composite_set_source (&setup, + &composite->source_pattern.base, + &composite->source_sample_area, + &composite->bounded, + FALSE); + if (unlikely (status)) + goto finish; + status = _cairo_gl_composite_set_mask (&setup, + &composite->mask_pattern.base, + &composite->source_sample_area, + &composite->bounded, + FALSE); + if (unlikely (status)) + goto finish; + status = _cairo_gl_set_operands_and_operator (&setup, ctx); + if (unlikely (status)) + goto finish; + + if (! clip) + status = _draw_int_rect (ctx, &setup, &composite->bounded); + else + status = _draw_traps (ctx, &setup, &traps); + +finish: + _cairo_gl_composite_fini (&setup); + if (ctx) + status = _cairo_gl_context_release (ctx, status); + if (clip) + _cairo_traps_fini (&traps); + + return status; +} + +static cairo_int_status_t +_cairo_gl_msaa_compositor_mask (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite) +{ + cairo_gl_composite_t setup; + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + cairo_gl_context_t *ctx = NULL; + cairo_int_status_t status; + cairo_operator_t op = composite->op; + cairo_clip_t *clip = composite->clip; + + if (! can_use_msaa_compositor (dst, CAIRO_ANTIALIAS_DEFAULT)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (composite->op == CAIRO_OPERATOR_CLEAR && + composite->original_mask_pattern != NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* GL compositing operators cannot properly represent a mask operation + using the SOURCE compositing operator in one pass. This only matters if + there actually is a mask (there isn't in a paint operation) and if the + mask isn't totally opaque. */ + if (op == CAIRO_OPERATOR_SOURCE && + composite->original_mask_pattern != NULL && + ! _cairo_pattern_is_opaque (&composite->mask_pattern.base, + &composite->mask_sample_area)) { + + if (! _cairo_pattern_is_opaque (&composite->source_pattern.base, + &composite->source_sample_area)) { + return _cairo_gl_msaa_compositor_mask_source_operator (compositor, composite); + } + + /* If the source is opaque the operation reduces to OVER. */ + op = CAIRO_OPERATOR_OVER; + } + + if (_should_use_unbounded_surface (composite)) { + cairo_surface_t* surface = _prepare_unbounded_surface (dst); + + if (unlikely (surface == NULL)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* This may be a paint operation. */ + if (composite->original_mask_pattern == NULL) { + status = _cairo_compositor_paint (compositor, surface, + CAIRO_OPERATOR_SOURCE, + &composite->source_pattern.base, + NULL); + } else { + status = _cairo_compositor_mask (compositor, surface, + CAIRO_OPERATOR_SOURCE, + &composite->source_pattern.base, + &composite->mask_pattern.base, + NULL); + } + + if (unlikely (status)) { + cairo_surface_destroy (surface); + return status; + } + + return _paint_back_unbounded_surface (compositor, composite, surface); + } + + status = _cairo_gl_composite_init (&setup, + op, + dst, + FALSE /* assume_component_alpha */); + if (unlikely (status)) + return status; + + status = _cairo_gl_composite_set_source (&setup, + &composite->source_pattern.base, + &composite->source_sample_area, + &composite->bounded, + FALSE); + if (unlikely (status)) + goto finish; + + if (composite->original_mask_pattern != NULL) { + status = _cairo_gl_composite_set_mask (&setup, + &composite->mask_pattern.base, + &composite->mask_sample_area, + &composite->bounded, + FALSE); + } + if (unlikely (status)) + goto finish; + + /* We always use multisampling here, because we do not yet have the smarts + to calculate when the clip or the source requires it. */ + _cairo_gl_composite_set_multisample (&setup); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto finish; + + if (! clip) + status = _draw_int_rect (ctx, &setup, &composite->bounded); + else + status = _cairo_gl_msaa_compositor_draw_clip (ctx, &setup, clip); + +finish: + _cairo_gl_composite_fini (&setup); + + if (ctx) + status = _cairo_gl_context_release (ctx, status); + + return status; +} + +static cairo_int_status_t +_cairo_gl_msaa_compositor_paint (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite) +{ + return _cairo_gl_msaa_compositor_mask (compositor, composite); +} + +static cairo_status_t +_stroke_shaper_add_triangle (void *closure, + const cairo_point_t triangle[3]) +{ + struct _tristrip_composite_info *info = closure; + return _cairo_gl_composite_emit_triangle_as_tristrip (info->ctx, + &info->setup, + triangle); +} + +static cairo_status_t +_stroke_shaper_add_triangle_fan (void *closure, + const cairo_point_t *midpoint, + const cairo_point_t *points, + int npoints) +{ + struct _tristrip_composite_info *info = closure; + return _draw_triangle_fan (info->ctx, &info->setup, + midpoint, points, npoints); +} + +static cairo_status_t +_stroke_shaper_add_quad (void *closure, + const cairo_point_t quad[4]) +{ + struct _tristrip_composite_info *info = closure; + return _cairo_gl_composite_emit_quad_as_tristrip (info->ctx, &info->setup, + quad); +} + +static cairo_int_status_t +_prevent_overlapping_strokes (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_composite_rectangles_t *composite, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm) +{ + cairo_rectangle_int_t stroke_extents; + + if (! _cairo_gl_ensure_stencil (ctx, setup->dst)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (_cairo_pattern_is_opaque (&composite->source_pattern.base, + &composite->source_sample_area)) + return CAIRO_INT_STATUS_SUCCESS; + + if (glIsEnabled (GL_STENCIL_TEST) == FALSE) { + cairo_bool_t scissor_was_enabled; + + /* In case we have pending operations we have to flush before + adding the stencil buffer. */ + _cairo_gl_composite_flush (ctx); + + /* Enable the stencil buffer, even if we are not using it for clipping, + so we can use it below to prevent overlapping shapes. We initialize + it all to one here which represents infinite clip. */ + glDepthMask (GL_TRUE); + glEnable (GL_STENCIL_TEST); + + /* We scissor here so that we don't have to clear the entire stencil + * buffer. If the scissor test is already enabled, it was enabled + * for clipping. In that case, instead of calculating an intersection, + * we just reuse it, and risk clearing too much. */ + scissor_was_enabled = glIsEnabled (GL_SCISSOR_TEST); + if (! scissor_was_enabled) { + _cairo_path_fixed_approximate_stroke_extents (path, style, ctm, + &stroke_extents); + _cairo_gl_scissor_to_rectangle (setup->dst, &stroke_extents); + } + glClearStencil (1); + glClear (GL_STENCIL_BUFFER_BIT); + if (! scissor_was_enabled) + glDisable (GL_SCISSOR_TEST); + + glStencilFunc (GL_EQUAL, 1, 1); + } + + /* This means that once we draw to a particular pixel nothing else can + be drawn there until the stencil buffer is reset or the stencil test + is disabled. */ + glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO); + + _cairo_clip_destroy (setup->dst->clip_on_stencil_buffer); + setup->dst->clip_on_stencil_buffer = NULL; + + return CAIRO_INT_STATUS_SUCCESS; +} + +static void +query_surface_capabilities (cairo_gl_surface_t *surface) +{ + GLint samples, stencil_bits; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + /* Texture surfaces are create in such a way that they always + have stencil and multisample bits if possible, so we don't + need to query their capabilities lazily. */ + if (_cairo_gl_surface_is_texture (surface)) + return; + if (surface->stencil_and_msaa_caps_initialized) + return; + + surface->stencil_and_msaa_caps_initialized = TRUE; + surface->supports_stencil = FALSE; + surface->supports_msaa = FALSE; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return; + + _cairo_gl_context_set_destination (ctx, surface, FALSE); + + glGetIntegerv(GL_SAMPLES, &samples); + glGetIntegerv(GL_STENCIL_BITS, &stencil_bits); + surface->supports_stencil = stencil_bits > 0; + surface->supports_msaa = samples > 1; + + status = _cairo_gl_context_release (ctx, status); +} + +static cairo_int_status_t +_cairo_gl_msaa_compositor_stroke (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_int_status_t status; + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + struct _tristrip_composite_info info; + + if (! can_use_msaa_compositor (dst, antialias)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (composite->is_bounded == FALSE) { + cairo_surface_t* surface = _prepare_unbounded_surface (dst); + + if (unlikely (surface == NULL)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_stroke (compositor, surface, + CAIRO_OPERATOR_SOURCE, + &composite->source_pattern.base, + path, style, ctm, ctm_inverse, + tolerance, antialias, NULL); + if (unlikely (status)) { + cairo_surface_destroy (surface); + return status; + } + + return _paint_back_unbounded_surface (compositor, composite, surface); + } + + status = _cairo_gl_composite_init (&info.setup, + composite->op, + dst, + FALSE /* assume_component_alpha */); + if (unlikely (status)) + return status; + + info.ctx = NULL; + + status = _cairo_gl_composite_set_source (&info.setup, + &composite->source_pattern.base, + &composite->source_sample_area, + &composite->bounded, + FALSE); + if (unlikely (status)) + goto finish; + + _cairo_gl_msaa_compositor_set_clip (composite, &info.setup); + if (antialias != CAIRO_ANTIALIAS_NONE) + _cairo_gl_composite_set_multisample (&info.setup); + + status = _cairo_gl_composite_begin (&info.setup, &info.ctx); + if (unlikely (status)) + goto finish; + + status = _prevent_overlapping_strokes (info.ctx, &info.setup, + composite, path, style, ctm); + if (unlikely (status)) + goto finish; + + status = _cairo_path_fixed_stroke_to_shaper ((cairo_path_fixed_t *) path, + style, + ctm, + ctm_inverse, + tolerance, + _stroke_shaper_add_triangle, + _stroke_shaper_add_triangle_fan, + _stroke_shaper_add_quad, + &info); + if (unlikely (status)) + goto finish; + +finish: + _cairo_gl_composite_fini (&info.setup); + + if (info.ctx) + status = _cairo_gl_context_release (info.ctx, status); + + return status; +} + +static cairo_int_status_t +_draw_simple_quad_path (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + const cairo_path_fixed_t *path) +{ + cairo_point_t triangle[3]; + cairo_int_status_t status; + const cairo_point_t *points; + + points = cairo_path_head (path)->points; + triangle[0] = points[0]; + triangle[1] = points[1]; + triangle[2] = points[2]; + status = _cairo_gl_composite_emit_triangle_as_tristrip (ctx, setup, triangle); + if (status) + return status; + + triangle[0] = points[2]; + triangle[1] = points[3]; + triangle[2] = points[0]; + return _cairo_gl_composite_emit_triangle_as_tristrip (ctx, setup, triangle); +} + +static cairo_int_status_t +_cairo_gl_msaa_compositor_fill (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_gl_composite_t setup; + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + cairo_gl_context_t *ctx = NULL; + cairo_int_status_t status; + cairo_traps_t traps; + cairo_bool_t draw_path_with_traps; + + if (! can_use_msaa_compositor (dst, antialias)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (composite->is_bounded == FALSE) { + cairo_surface_t* surface = _prepare_unbounded_surface (dst); + + if (unlikely (surface == NULL)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + + status = _cairo_compositor_fill (compositor, surface, + CAIRO_OPERATOR_SOURCE, + &composite->source_pattern.base, + path, fill_rule, tolerance, + antialias, NULL); + + if (unlikely (status)) { + cairo_surface_destroy (surface); + return status; + } + + return _paint_back_unbounded_surface (compositor, composite, surface); + } + + draw_path_with_traps = ! _cairo_path_fixed_is_simple_quad (path); + + if (draw_path_with_traps) { + _cairo_traps_init (&traps); + status = _cairo_path_fixed_fill_to_traps (path, fill_rule, tolerance, &traps); + if (unlikely (status)) + goto cleanup_traps; + } + + status = _cairo_gl_composite_init (&setup, + composite->op, + dst, + FALSE /* assume_component_alpha */); + if (unlikely (status)) + goto cleanup_traps; + + status = _cairo_gl_composite_set_source (&setup, + &composite->source_pattern.base, + &composite->source_sample_area, + &composite->bounded, + FALSE); + if (unlikely (status)) + goto cleanup_setup; + + _cairo_gl_msaa_compositor_set_clip (composite, &setup); + if (antialias != CAIRO_ANTIALIAS_NONE) + _cairo_gl_composite_set_multisample (&setup); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto cleanup_setup; + + if (! draw_path_with_traps) + status = _draw_simple_quad_path (ctx, &setup, path); + else + status = _draw_traps (ctx, &setup, &traps); + if (unlikely (status)) + goto cleanup_setup; + +cleanup_setup: + _cairo_gl_composite_fini (&setup); + + if (ctx) + status = _cairo_gl_context_release (ctx, status); + +cleanup_traps: + if (draw_path_with_traps) + _cairo_traps_fini (&traps); + + return status; +} + +static cairo_int_status_t +_cairo_gl_msaa_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_int_status_t status; + cairo_surface_t *src = NULL; + int src_x, src_y; + cairo_composite_glyphs_info_t info; + + cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface; + + query_surface_capabilities (dst); + if (! dst->supports_stencil) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (composite->op == CAIRO_OPERATOR_CLEAR) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (composite->is_bounded == FALSE) { + cairo_surface_t* surface = _prepare_unbounded_surface (dst); + + if (unlikely (surface == NULL)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_glyphs (compositor, surface, + CAIRO_OPERATOR_SOURCE, + &composite->source_pattern.base, + glyphs, num_glyphs, + scaled_font, composite->clip); + + if (unlikely (status)) { + cairo_surface_destroy (surface); + return status; + } + + return _paint_back_unbounded_surface (compositor, composite, surface); + } + + src = _cairo_gl_pattern_to_source (&dst->base, + &composite->source_pattern.base, + FALSE, + &composite->bounded, + &composite->source_sample_area, + &src_x, &src_y); + if (unlikely (src->status)) { + status = src->status; + goto finish; + } + + status = _cairo_gl_check_composite_glyphs (composite, + scaled_font, glyphs, + &num_glyphs); + if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) + goto finish; + + info.font = scaled_font; + info.glyphs = glyphs; + info.num_glyphs = num_glyphs; + info.use_mask = overlap || ! composite->is_bounded || + composite->op == CAIRO_OPERATOR_SOURCE; + info.extents = composite->bounded; + + _cairo_scaled_font_freeze_cache (scaled_font); + status = _cairo_gl_composite_glyphs_with_clip (dst, composite->op, + src, src_x, src_y, + 0, 0, &info, + composite->clip); + + _cairo_scaled_font_thaw_cache (scaled_font); + +finish: + if (src) + cairo_surface_destroy (src); + + return status; +} + +static void +_cairo_gl_msaa_compositor_init (cairo_compositor_t *compositor, + const cairo_compositor_t *delegate) +{ + compositor->delegate = delegate; + + compositor->paint = _cairo_gl_msaa_compositor_paint; + compositor->mask = _cairo_gl_msaa_compositor_mask; + compositor->fill = _cairo_gl_msaa_compositor_fill; + compositor->stroke = _cairo_gl_msaa_compositor_stroke; + compositor->glyphs = _cairo_gl_msaa_compositor_glyphs; +} + +const cairo_compositor_t * +_cairo_gl_msaa_compositor_get (void) +{ + static cairo_compositor_t compositor; + if (compositor.delegate == NULL) + _cairo_gl_msaa_compositor_init (&compositor, + _cairo_gl_span_compositor_get ()); + + return &compositor; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-operand.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-operand.c new file mode 100644 index 00000000000..1d1465a0be9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-operand.c @@ -0,0 +1,792 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-surface-offset-private.h" +#include "cairo-surface-subsurface-inline.h" + +static cairo_int_status_t +_cairo_gl_create_gradient_texture (cairo_gl_surface_t *dst, + const cairo_gradient_pattern_t *pattern, + cairo_gl_gradient_t **gradient) +{ + cairo_gl_context_t *ctx; + cairo_status_t status; + + status = _cairo_gl_context_acquire (dst->base.device, &ctx); + if (unlikely (status)) + return status; + + status = _cairo_gl_gradient_create (ctx, pattern->n_stops, pattern->stops, gradient); + + return _cairo_gl_context_release (ctx, status); +} + +static cairo_status_t +_cairo_gl_subsurface_clone_operand_init (cairo_gl_operand_t *operand, + const cairo_pattern_t *_src, + cairo_gl_surface_t *dst, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen) +{ + const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src; + cairo_surface_pattern_t local_pattern; + cairo_surface_subsurface_t *sub; + cairo_gl_surface_t *surface; + cairo_gl_context_t *ctx; + cairo_surface_attributes_t *attributes; + cairo_status_t status; + + sub = (cairo_surface_subsurface_t *) src->surface; + + if (sub->snapshot && + sub->snapshot->type == CAIRO_SURFACE_TYPE_GL && + sub->snapshot->device == dst->base.device) + { + surface = (cairo_gl_surface_t *) + cairo_surface_reference (sub->snapshot); + } + else + { + status = _cairo_gl_context_acquire (dst->base.device, &ctx); + if (unlikely (status)) + return status; + + /* XXX Trim surface to the sample area within the subsurface? */ + surface = (cairo_gl_surface_t *) + _cairo_gl_surface_create_scratch (ctx, + sub->target->content, + sub->extents.width, + sub->extents.height); + if (surface->base.status) + return _cairo_gl_context_release (ctx, surface->base.status); + + _cairo_pattern_init_for_surface (&local_pattern, sub->target); + cairo_matrix_init_translate (&local_pattern.base.matrix, + sub->extents.x, sub->extents.y); + local_pattern.base.filter = CAIRO_FILTER_NEAREST; + status = _cairo_surface_paint (&surface->base, + CAIRO_OPERATOR_SOURCE, + &local_pattern.base, + NULL); + _cairo_pattern_fini (&local_pattern.base); + + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return status; + } + + _cairo_surface_subsurface_set_snapshot (&sub->base, &surface->base); + } + + status = _cairo_gl_surface_resolve_multisampling (surface); + if (unlikely (status)) + return status; + + attributes = &operand->texture.attributes; + + operand->type = CAIRO_GL_OPERAND_TEXTURE; + operand->texture.surface = surface; + operand->texture.owns_surface = surface; + operand->texture.tex = surface->tex; + + if (_cairo_gl_device_requires_power_of_two_textures (dst->base.device)) { + attributes->matrix = src->base.matrix; + } else { + cairo_matrix_t m; + + cairo_matrix_init_scale (&m, + 1.0 / surface->width, + 1.0 / surface->height); + cairo_matrix_multiply (&attributes->matrix, &src->base.matrix, &m); + } + + attributes->extend = src->base.extend; + attributes->filter = src->base.filter; + attributes->has_component_alpha = src->base.has_component_alpha; + + operand->texture.texgen = use_texgen; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_subsurface_operand_init (cairo_gl_operand_t *operand, + const cairo_pattern_t *_src, + cairo_gl_surface_t *dst, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen) +{ + const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src; + cairo_surface_subsurface_t *sub; + cairo_gl_surface_t *surface; + cairo_surface_attributes_t *attributes; + cairo_int_status_t status; + + sub = (cairo_surface_subsurface_t *) src->surface; + + if (sample->x < 0 || sample->y < 0 || + sample->x + sample->width > sub->extents.width || + sample->y + sample->height > sub->extents.height) + { + return _cairo_gl_subsurface_clone_operand_init (operand, _src, + dst, sample, extents, + use_texgen); + } + + surface = (cairo_gl_surface_t *) sub->target; + if (surface->base.device && surface->base.device != dst->base.device) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_gl_surface_is_texture (surface)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_gl_surface_resolve_multisampling (surface); + if (unlikely (status)) + return status; + + /* Translate the matrix from + * (unnormalized src -> unnormalized src) to + * (unnormalized dst -> unnormalized src) + */ + _cairo_gl_operand_copy(operand, &surface->operand); + + attributes = &operand->texture.attributes; + attributes->matrix = src->base.matrix; + attributes->matrix.x0 += sub->extents.x; + attributes->matrix.y0 += sub->extents.y; + cairo_matrix_multiply (&attributes->matrix, + &attributes->matrix, + &surface->operand.texture.attributes.matrix); + + attributes->extend = src->base.extend; + attributes->filter = src->base.filter; + attributes->has_component_alpha = src->base.has_component_alpha; + + operand->texture.texgen = use_texgen; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_surface_operand_init (cairo_gl_operand_t *operand, + const cairo_pattern_t *_src, + cairo_gl_surface_t *dst, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen) +{ + const cairo_surface_pattern_t *src = (cairo_surface_pattern_t *)_src; + cairo_gl_surface_t *surface; + cairo_surface_attributes_t *attributes; + cairo_int_status_t status; + + surface = (cairo_gl_surface_t *) src->surface; + if (surface->base.type != CAIRO_SURFACE_TYPE_GL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (surface->base.backend->type != CAIRO_SURFACE_TYPE_GL) { + if (_cairo_surface_is_subsurface (&surface->base)) + return _cairo_gl_subsurface_operand_init (operand, _src, dst, + sample, extents, + use_texgen); + + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (surface->base.device && surface->base.device != dst->base.device) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (surface->base.device && ! _cairo_gl_surface_is_texture (surface)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_gl_surface_resolve_multisampling (surface); + if (unlikely (status)) + return status; + + _cairo_gl_operand_copy(operand, &surface->operand); + + attributes = &operand->texture.attributes; + cairo_matrix_multiply (&attributes->matrix, + &src->base.matrix, + &attributes->matrix); + + attributes->extend = src->base.extend; + attributes->filter = src->base.filter; + attributes->has_component_alpha = src->base.has_component_alpha; + + operand->texture.texgen = use_texgen; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_pattern_texture_setup (cairo_gl_operand_t *operand, + const cairo_pattern_t *_src, + cairo_gl_surface_t *dst, + const cairo_rectangle_int_t *extents) +{ + cairo_status_t status; + cairo_gl_surface_t *surface; + cairo_gl_context_t *ctx; + cairo_image_surface_t *image; + cairo_bool_t src_is_gl_surface = FALSE; + cairo_rectangle_int_t map_extents; + + if (_src->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_t* src_surface = ((cairo_surface_pattern_t *) _src)->surface; + src_is_gl_surface = src_surface->type == CAIRO_SURFACE_TYPE_GL; + } + + status = _cairo_gl_context_acquire (dst->base.device, &ctx); + if (unlikely (status)) + return status; + + surface = (cairo_gl_surface_t *) + _cairo_gl_surface_create_scratch (ctx, + CAIRO_CONTENT_COLOR_ALPHA, + extents->width, extents->height); + map_extents = *extents; + map_extents.x = map_extents.y = 0; + image = _cairo_surface_map_to_image (&surface->base, &map_extents); + + /* If the pattern is a GL surface, it belongs to some other GL context, + so we need to release this device while we paint it to the image. */ + if (src_is_gl_surface) { + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) { + _cairo_surface_unmap_image (&surface->base, image); + goto fail; + } + } + + status = _cairo_surface_offset_paint (&image->base, extents->x, extents->y, + CAIRO_OPERATOR_SOURCE, _src, NULL); + + if (src_is_gl_surface) { + status = _cairo_gl_context_acquire (dst->base.device, &ctx); + if (unlikely (status)) { + _cairo_surface_unmap_image (&surface->base, image); + goto fail; + } + } + + status = _cairo_surface_unmap_image (&surface->base, image); + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) + goto fail; + + *operand = surface->operand; + operand->texture.owns_surface = surface; + operand->texture.attributes.matrix.x0 -= extents->x * operand->texture.attributes.matrix.xx; + operand->texture.attributes.matrix.y0 -= extents->y * operand->texture.attributes.matrix.yy; + return CAIRO_STATUS_SUCCESS; + +fail: + cairo_surface_destroy (&surface->base); + return status; +} + +void +_cairo_gl_solid_operand_init (cairo_gl_operand_t *operand, + const cairo_color_t *color) +{ + operand->type = CAIRO_GL_OPERAND_CONSTANT; + operand->constant.color[0] = color->red * color->alpha; + operand->constant.color[1] = color->green * color->alpha; + operand->constant.color[2] = color->blue * color->alpha; + operand->constant.color[3] = color->alpha; +} + +void +_cairo_gl_operand_translate (cairo_gl_operand_t *operand, + double tx, double ty) +{ + switch (operand->type) { + case CAIRO_GL_OPERAND_TEXTURE: + operand->texture.attributes.matrix.x0 -= tx * operand->texture.attributes.matrix.xx; + operand->texture.attributes.matrix.y0 -= ty * operand->texture.attributes.matrix.yy; + break; + + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + operand->gradient.m.x0 -= tx * operand->gradient.m.xx; + operand->gradient.m.y0 -= ty * operand->gradient.m.yy; + break; + + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + case CAIRO_GL_OPERAND_COUNT: + default: + break; + } +} + +static cairo_status_t +_cairo_gl_gradient_operand_init (cairo_gl_operand_t *operand, + const cairo_pattern_t *pattern, + cairo_gl_surface_t *dst, + cairo_bool_t use_texgen) +{ + const cairo_gradient_pattern_t *gradient = (const cairo_gradient_pattern_t *)pattern; + cairo_status_t status; + + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + + if (! _cairo_gl_device_has_glsl (dst->base.device)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_gl_create_gradient_texture (dst, + gradient, + &operand->gradient.gradient); + if (unlikely (status)) + return status; + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; + double x0, y0, dx, dy, sf, offset; + + dx = linear->pd2.x - linear->pd1.x; + dy = linear->pd2.y - linear->pd1.y; + sf = 1.0 / (dx * dx + dy * dy); + dx *= sf; + dy *= sf; + + x0 = linear->pd1.x; + y0 = linear->pd1.y; + offset = dx * x0 + dy * y0; + + operand->type = CAIRO_GL_OPERAND_LINEAR_GRADIENT; + + cairo_matrix_init (&operand->gradient.m, dx, 0, dy, 1, -offset, 0); + if (! _cairo_matrix_is_identity (&pattern->matrix)) { + cairo_matrix_multiply (&operand->gradient.m, + &pattern->matrix, + &operand->gradient.m); + } + } else { + cairo_matrix_t m; + cairo_circle_double_t circles[2]; + double x0, y0, r0, dx, dy, dr; + + /* + * Some fragment shader implementations use half-floats to + * represent numbers, so the maximum number they can represent + * is about 2^14. Some intermediate computations used in the + * radial gradient shaders can produce results of up to 2*k^4. + * Setting k=8 makes the maximum result about 8192 (assuming + * that the extreme circles are not much smaller than the + * destination image). + */ + _cairo_gradient_pattern_fit_to_range (gradient, 8., + &operand->gradient.m, circles); + + x0 = circles[0].center.x; + y0 = circles[0].center.y; + r0 = circles[0].radius; + dx = circles[1].center.x - x0; + dy = circles[1].center.y - y0; + dr = circles[1].radius - r0; + + operand->gradient.a = dx * dx + dy * dy - dr * dr; + operand->gradient.radius_0 = r0; + operand->gradient.circle_d.center.x = dx; + operand->gradient.circle_d.center.y = dy; + operand->gradient.circle_d.radius = dr; + + if (operand->gradient.a == 0) + operand->type = CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0; + else if (pattern->extend == CAIRO_EXTEND_NONE) + operand->type = CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE; + else + operand->type = CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT; + + cairo_matrix_init_translate (&m, -x0, -y0); + cairo_matrix_multiply (&operand->gradient.m, + &operand->gradient.m, + &m); + } + + operand->gradient.extend = pattern->extend; + operand->gradient.texgen = use_texgen; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gl_operand_copy (cairo_gl_operand_t *dst, + const cairo_gl_operand_t *src) +{ + *dst = *src; + switch (dst->type) { + case CAIRO_GL_OPERAND_CONSTANT: + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + _cairo_gl_gradient_reference (dst->gradient.gradient); + break; + case CAIRO_GL_OPERAND_TEXTURE: + cairo_surface_reference (&dst->texture.owns_surface->base); + break; + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + break; + } +} + +void +_cairo_gl_operand_destroy (cairo_gl_operand_t *operand) +{ + switch (operand->type) { + case CAIRO_GL_OPERAND_CONSTANT: + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + _cairo_gl_gradient_destroy (operand->gradient.gradient); + break; + case CAIRO_GL_OPERAND_TEXTURE: + cairo_surface_destroy (&operand->texture.owns_surface->base); + break; + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + break; + } + + operand->type = CAIRO_GL_OPERAND_NONE; +} + +cairo_int_status_t +_cairo_gl_operand_init (cairo_gl_operand_t *operand, + const cairo_pattern_t *pattern, + cairo_gl_surface_t *dst, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s: type=%d\n", __FUNCTION__, pattern->type)); + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + _cairo_gl_solid_operand_init (operand, + &((cairo_solid_pattern_t *) pattern)->color); + return CAIRO_STATUS_SUCCESS; + case CAIRO_PATTERN_TYPE_SURFACE: + status = _cairo_gl_surface_operand_init (operand, pattern, dst, + sample, extents, use_texgen); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + break; + + return status; + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + status = _cairo_gl_gradient_operand_init (operand, pattern, dst, + use_texgen); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + break; + + return status; + + default: + case CAIRO_PATTERN_TYPE_MESH: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + break; + } + + return _cairo_gl_pattern_texture_setup (operand, pattern, dst, extents); +} + +cairo_filter_t +_cairo_gl_operand_get_filter (cairo_gl_operand_t *operand) +{ + cairo_filter_t filter; + + switch ((int) operand->type) { + case CAIRO_GL_OPERAND_TEXTURE: + filter = operand->texture.attributes.filter; + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + filter = CAIRO_FILTER_BILINEAR; + break; + default: + filter = CAIRO_FILTER_DEFAULT; + break; + } + + return filter; +} + +GLint +_cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand) +{ + cairo_filter_t filter = _cairo_gl_operand_get_filter (operand); + + return filter != CAIRO_FILTER_FAST && filter != CAIRO_FILTER_NEAREST ? + GL_LINEAR : + GL_NEAREST; +} + +cairo_extend_t +_cairo_gl_operand_get_extend (cairo_gl_operand_t *operand) +{ + cairo_extend_t extend; + + switch ((int) operand->type) { + case CAIRO_GL_OPERAND_TEXTURE: + extend = operand->texture.attributes.extend; + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + extend = operand->gradient.extend; + break; + default: + extend = CAIRO_EXTEND_NONE; + break; + } + + return extend; +} + + +void +_cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, + cairo_gl_operand_t *operand, + cairo_gl_tex_t tex_unit) +{ + const cairo_matrix_t *texgen = NULL; + + switch (operand->type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + return; + + case CAIRO_GL_OPERAND_CONSTANT: + _cairo_gl_shader_bind_vec4 (ctx, + ctx->current_shader->constant_location[tex_unit], + operand->constant.color[0], + operand->constant.color[1], + operand->constant.color[2], + operand->constant.color[3]); + return; + + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + _cairo_gl_shader_bind_float (ctx, + ctx->current_shader->a_location[tex_unit], + operand->gradient.a); + /* fall through */ + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + _cairo_gl_shader_bind_vec3 (ctx, + ctx->current_shader->circle_d_location[tex_unit], + operand->gradient.circle_d.center.x, + operand->gradient.circle_d.center.y, + operand->gradient.circle_d.radius); + _cairo_gl_shader_bind_float (ctx, + ctx->current_shader->radius_0_location[tex_unit], + operand->gradient.radius_0); + /* fall through */ + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_TEXTURE: + /* + * For GLES2 we use shaders to implement GL_CLAMP_TO_BORDER (used + * with CAIRO_EXTEND_NONE). When bilinear filtering is enabled, + * these shaders need the texture dimensions for their calculations. + */ + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + _cairo_gl_operand_get_extend (operand) == CAIRO_EXTEND_NONE && + _cairo_gl_operand_get_gl_filter (operand) == GL_LINEAR) + { + float width, height; + if (operand->type == CAIRO_GL_OPERAND_TEXTURE) { + width = operand->texture.surface->width; + height = operand->texture.surface->height; + } + else { + width = operand->gradient.gradient->cache_entry.size, + height = 1; + } + _cairo_gl_shader_bind_vec2 (ctx, + ctx->current_shader->texdims_location[tex_unit], + width, height); + } + break; + } + + if (operand->type == CAIRO_GL_OPERAND_TEXTURE) { + if (operand->texture.texgen) + texgen = &operand->texture.attributes.matrix; + } else { + if (operand->gradient.texgen) + texgen = &operand->gradient.m; + } + if (texgen) { + _cairo_gl_shader_bind_matrix(ctx, + ctx->current_shader->texgen_location[tex_unit], + texgen); + } +} + + +cairo_bool_t +_cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest, + cairo_gl_operand_t *source, + unsigned int vertex_offset) +{ + if (dest->type != source->type) + return TRUE; + if (dest->vertex_offset != vertex_offset) + return TRUE; + + switch (source->type) { + case CAIRO_GL_OPERAND_NONE: + return FALSE; + case CAIRO_GL_OPERAND_CONSTANT: + return dest->constant.color[0] != source->constant.color[0] || + dest->constant.color[1] != source->constant.color[1] || + dest->constant.color[2] != source->constant.color[2] || + dest->constant.color[3] != source->constant.color[3]; + case CAIRO_GL_OPERAND_TEXTURE: + return dest->texture.surface != source->texture.surface || + dest->texture.attributes.extend != source->texture.attributes.extend || + dest->texture.attributes.filter != source->texture.attributes.filter || + dest->texture.attributes.has_component_alpha != source->texture.attributes.has_component_alpha; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + /* XXX: improve this */ + return TRUE; + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + break; + } + return TRUE; +} + +unsigned int +_cairo_gl_operand_get_vertex_size (const cairo_gl_operand_t *operand) +{ + switch (operand->type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + return 0; + case CAIRO_GL_OPERAND_TEXTURE: + return operand->texture.texgen ? 0 : 2 * sizeof (GLfloat); + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + return operand->gradient.texgen ? 0 : 2 * sizeof (GLfloat); + } +} + +void +_cairo_gl_operand_emit (cairo_gl_operand_t *operand, + GLfloat ** vb, + GLfloat x, + GLfloat y) +{ + switch (operand->type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + if (! operand->gradient.texgen) { + double s = x; + double t = y; + + cairo_matrix_transform_point (&operand->gradient.m, &s, &t); + + *(*vb)++ = s; + *(*vb)++ = t; + } + break; + case CAIRO_GL_OPERAND_TEXTURE: + if (! operand->texture.texgen) { + cairo_surface_attributes_t *src_attributes = &operand->texture.attributes; + double s = x; + double t = y; + + cairo_matrix_transform_point (&src_attributes->matrix, &s, &t); + *(*vb)++ = s; + *(*vb)++ = t; + } + break; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-gl-private.h new file mode 100644 index 00000000000..cb915c8cf25 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-private.h @@ -0,0 +1,853 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * Copyright © 2011 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + * T. Zachary Laine + * Alexandros Frantzis + */ + +#ifndef CAIRO_GL_PRIVATE_H +#define CAIRO_GL_PRIVATE_H + +#define GL_GLEXT_PROTOTYPES + +#include "cairoint.h" + +#include "cairo-gl.h" +#include "cairo-gl-gradient-private.h" + +#include "cairo-device-private.h" +#include "cairo-error-private.h" +#include "cairo-rtree-private.h" +#include "cairo-scaled-font-private.h" +#include "cairo-spans-compositor-private.h" +#include "cairo-array-private.h" + +#include + +#if CAIRO_HAS_GL_SURFACE +#include +#include +#elif CAIRO_HAS_GLESV2_SURFACE +#include +#include +#endif + +#include "cairo-gl-ext-def-private.h" + +#define DEBUG_GL 0 + +#if DEBUG_GL && __GNUC__ +#define UNSUPPORTED(reason) ({ \ + fprintf (stderr, \ + "cairo-gl: hit unsupported operation in %s(), line %d: %s\n", \ + __FUNCTION__, __LINE__, reason); \ + CAIRO_INT_STATUS_UNSUPPORTED; \ +}) +#else +#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED +#endif + +#define CAIRO_GL_VERSION_ENCODE(major, minor) ( \ + ((major) * 256) \ + + ((minor) * 1)) + +/* maximal number of shaders we keep in the cache. + * Random number that is hopefully big enough to not cause many cache evictions. */ +#define CAIRO_GL_MAX_SHADERS_PER_CONTEXT 64 + +/* VBO size that we allocate, smaller size means we gotta flush more often, + * but larger means hogging more memory and can cause trouble for drivers + * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment + * variable to set this to a different size. */ +#define CAIRO_GL_VBO_SIZE_DEFAULT (1024*1024) + +typedef struct _cairo_gl_surface cairo_gl_surface_t; + +/* GL flavor */ +typedef enum cairo_gl_flavor { + CAIRO_GL_FLAVOR_NONE = 0, + CAIRO_GL_FLAVOR_DESKTOP = 1, + CAIRO_GL_FLAVOR_ES = 2 +} cairo_gl_flavor_t; + +/* Indices for vertex attributes used by BindAttribLocation etc */ +enum { + CAIRO_GL_VERTEX_ATTRIB_INDEX = 0, + CAIRO_GL_COLOR_ATTRIB_INDEX = 1, + CAIRO_GL_TEXCOORD0_ATTRIB_INDEX = 2, + CAIRO_GL_TEXCOORD1_ATTRIB_INDEX = CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + 1 +}; + +typedef enum cairo_gl_operand_type { + CAIRO_GL_OPERAND_NONE, + CAIRO_GL_OPERAND_CONSTANT, + CAIRO_GL_OPERAND_TEXTURE, + CAIRO_GL_OPERAND_LINEAR_GRADIENT, + CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0, + CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE, + CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT, + + CAIRO_GL_OPERAND_COUNT +} cairo_gl_operand_type_t; + +/* This union structure describes a potential source or mask operand to the + * compositing equation. + */ +typedef struct cairo_gl_operand { + cairo_gl_operand_type_t type; + union { + struct { + GLuint tex; + cairo_gl_surface_t *surface; + cairo_gl_surface_t *owns_surface; + cairo_surface_attributes_t attributes; + int texgen; + } texture; + struct { + GLfloat color[4]; + } constant; + struct { + cairo_gl_gradient_t *gradient; + cairo_matrix_t m; + cairo_circle_double_t circle_d; + double radius_0, a; + cairo_extend_t extend; + int texgen; + } gradient; + }; + unsigned int vertex_offset; +} cairo_gl_operand_t; + +typedef struct cairo_gl_source { + cairo_surface_t base; + cairo_gl_operand_t operand; +} cairo_gl_source_t; + +struct _cairo_gl_surface { + cairo_surface_t base; + cairo_gl_operand_t operand; + + int width, height; + + GLuint tex; /* GL texture object containing our data. */ + GLuint fb; /* GL framebuffer object wrapping our data. */ + GLuint depth_stencil; /* GL renderbuffer object for holding stencil buffer clip. */ + +#if CAIRO_HAS_GL_SURFACE + GLuint msaa_rb; /* The ARB MSAA path uses a renderbuffer. */ + GLuint msaa_fb; +#endif + GLuint msaa_depth_stencil; + + cairo_bool_t stencil_and_msaa_caps_initialized; + cairo_bool_t supports_stencil; /* Stencil support for for non-texture surfaces. */ + cairo_bool_t supports_msaa; + cairo_bool_t msaa_active; /* Whether the multisampling + framebuffer is active or not. */ + cairo_clip_t *clip_on_stencil_buffer; + + int owns_tex; + cairo_bool_t needs_update; + + cairo_region_t *clip_region; +}; + +typedef struct cairo_gl_glyph_cache { + cairo_rtree_t rtree; + cairo_gl_surface_t *surface; +} cairo_gl_glyph_cache_t; + +typedef enum cairo_gl_tex { + CAIRO_GL_TEX_SOURCE = 0, + CAIRO_GL_TEX_MASK = 1, + CAIRO_GL_TEX_TEMP = 2 +} cairo_gl_tex_t; + +typedef struct cairo_gl_shader { + GLuint fragment_shader; + GLuint program; + GLint mvp_location; + GLint constant_location[2]; + GLint a_location[2]; + GLint circle_d_location[2]; + GLint radius_0_location[2]; + GLint texdims_location[2]; + GLint texgen_location[2]; +} cairo_gl_shader_t; + +typedef enum cairo_gl_shader_in { + CAIRO_GL_SHADER_IN_NORMAL, + CAIRO_GL_SHADER_IN_CA_SOURCE, + CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA, + + CAIRO_GL_SHADER_IN_COUNT +} cairo_gl_shader_in_t; + +typedef enum cairo_gl_var_type { + CAIRO_GL_VAR_NONE, + CAIRO_GL_VAR_TEXCOORDS, + CAIRO_GL_VAR_TEXGEN, +} cairo_gl_var_type_t; + +typedef enum cairo_gl_primitive_type { + CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES, + CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS +} cairo_gl_primitive_type_t; + +typedef void (*cairo_gl_emit_rect_t) (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2); + +typedef void (*cairo_gl_emit_span_t) (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2, + uint8_t alpha); + +typedef void (*cairo_gl_emit_glyph_t) (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2, + GLfloat glyph_x1, GLfloat glyph_y1, + GLfloat glyph_x2, GLfloat glyph_y2); + +#define cairo_gl_var_type_hash(src,mask,spans,dest) ((spans) << 5) | ((mask) << 3 | (src << 1) | (dest)) +#define CAIRO_GL_VAR_TYPE_MAX (1 << 6) + +typedef void (*cairo_gl_generic_func_t)(void); +typedef cairo_gl_generic_func_t (*cairo_gl_get_proc_addr_func_t)(const char *procname); + +typedef struct _cairo_gl_dispatch { + /* Buffers */ + void (*GenBuffers) (GLsizei n, GLuint *buffers); + void (*BindBuffer) (GLenum target, GLuint buffer); + void (*BufferData) (GLenum target, GLsizeiptr size, + const GLvoid* data, GLenum usage); + GLvoid *(*MapBuffer) (GLenum target, GLenum access); + GLboolean (*UnmapBuffer) (GLenum target); + + /* Shaders */ + GLuint (*CreateShader) (GLenum type); + void (*ShaderSource) (GLuint shader, GLsizei count, + const GLchar** string, const GLint* length); + void (*CompileShader) (GLuint shader); + void (*GetShaderiv) (GLuint shader, GLenum pname, GLint *params); + void (*GetShaderInfoLog) (GLuint shader, GLsizei bufSize, + GLsizei *length, GLchar *infoLog); + void (*DeleteShader) (GLuint shader); + + /* Programs */ + GLuint (*CreateProgram) (void); + void (*AttachShader) (GLuint program, GLuint shader); + void (*DeleteProgram) (GLuint program); + void (*LinkProgram) (GLuint program); + void (*UseProgram) (GLuint program); + void (*GetProgramiv) (GLuint program, GLenum pname, GLint *params); + void (*GetProgramInfoLog) (GLuint program, GLsizei bufSize, + GLsizei *length, GLchar *infoLog); + + /* Uniforms */ + GLint (*GetUniformLocation) (GLuint program, const GLchar* name); + void (*Uniform1f) (GLint location, GLfloat x); + void (*Uniform2f) (GLint location, GLfloat x, GLfloat y); + void (*Uniform3f) (GLint location, GLfloat x, GLfloat y, GLfloat z); + void (*Uniform4f) (GLint location, GLfloat x, GLfloat y, GLfloat z, + GLfloat w); + void (*UniformMatrix3fv) (GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value); + void (*UniformMatrix4fv) (GLint location, GLsizei count, + GLboolean transpose, const GLfloat *value); + void (*Uniform1i) (GLint location, GLint x); + + /* Attributes */ + void (*BindAttribLocation) (GLuint program, GLuint index, + const GLchar *name); + void (*VertexAttribPointer) (GLuint index, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, + const GLvoid *pointer); + void (*EnableVertexAttribArray) (GLuint index); + void (*DisableVertexAttribArray) (GLuint index); + + /* Framebuffer objects */ + void (*GenFramebuffers) (GLsizei n, GLuint* framebuffers); + void (*BindFramebuffer) (GLenum target, GLuint framebuffer); + void (*FramebufferTexture2D) (GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level); + GLenum (*CheckFramebufferStatus) (GLenum target); + void (*DeleteFramebuffers) (GLsizei n, const GLuint* framebuffers); + void (*GenRenderbuffers) (GLsizei n, GLuint *renderbuffers); + void (*BindRenderbuffer) (GLenum target, GLuint renderbuffer); + void (*RenderbufferStorage) (GLenum target, GLenum internal_format, + GLsizei width, GLsizei height); + void (*FramebufferRenderbuffer) (GLenum target, GLenum attachment, + GLenum renderbuffer_ttarget, GLuint renderbuffer); + void (*DeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers); + void (*BlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, + GLbitfield mask, GLenum filter); + void (*RenderbufferStorageMultisample) (GLenum target, GLsizei samples, + GLenum internalformat, + GLsizei width, GLsizei height); + void (*FramebufferTexture2DMultisample) (GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level, GLsizei samples); +} cairo_gl_dispatch_t; + +struct _cairo_gl_context { + cairo_device_t base; + + const cairo_compositor_t *compositor; + + GLuint texture_load_pbo; + GLint max_framebuffer_size; + GLint max_texture_size; + GLint max_textures; + GLenum tex_target; + + GLint num_samples; + cairo_bool_t supports_msaa; + char *vb; + + cairo_bool_t has_shader_support; + + GLuint vertex_shaders[CAIRO_GL_VAR_TYPE_MAX]; + cairo_gl_shader_t fill_rectangles_shader; + cairo_cache_t shaders; + + cairo_cache_t gradients; + + cairo_gl_glyph_cache_t glyph_cache[2]; + cairo_list_t fonts; + + cairo_gl_surface_t *current_target; + cairo_operator_t current_operator; + cairo_gl_shader_t *pre_shader; /* for component alpha */ + cairo_gl_shader_t *current_shader; + + cairo_gl_operand_t operands[2]; + cairo_bool_t spans; + + unsigned int vbo_size; + unsigned int vb_offset; + unsigned int vertex_size; + cairo_region_t *clip_region; + cairo_clip_t *clip; + + cairo_gl_primitive_type_t primitive_type; + cairo_array_t tristrip_indices; + + cairo_bool_t has_mesa_pack_invert; + cairo_gl_dispatch_t dispatch; + GLfloat modelviewprojection_matrix[16]; + cairo_gl_flavor_t gl_flavor; + cairo_bool_t has_map_buffer; + cairo_bool_t has_packed_depth_stencil; + cairo_bool_t has_npot_repeat; + cairo_bool_t can_read_bgra; + + cairo_bool_t thread_aware; + + void (*acquire) (void *ctx); + void (*release) (void *ctx); + + void (*make_current) (void *ctx, cairo_gl_surface_t *surface); + void (*swap_buffers)(void *ctx, cairo_gl_surface_t *surface); + void (*destroy) (void *ctx); +}; + +typedef struct _cairo_gl_composite { + cairo_gl_surface_t *dst; + cairo_operator_t op; + cairo_region_t *clip_region; + + cairo_gl_operand_t src; + cairo_gl_operand_t mask; + cairo_bool_t spans; + + cairo_clip_t *clip; + cairo_bool_t multisample; +} cairo_gl_composite_t; + +typedef struct _cairo_gl_font { + cairo_scaled_font_private_t base; + cairo_device_t *device; + cairo_list_t link; +} cairo_gl_font_t; + +static cairo_always_inline GLenum +_cairo_gl_get_error (void) +{ + GLenum err = glGetError(); + + if (unlikely (err)) + while (glGetError ()); + + return err; +} + +static inline cairo_device_t * +_cairo_gl_context_create_in_error (cairo_status_t status) +{ + return (cairo_device_t *) _cairo_device_create_in_error (status); +} + +cairo_private cairo_status_t +_cairo_gl_context_init (cairo_gl_context_t *ctx); + +cairo_private void +_cairo_gl_surface_init (cairo_device_t *device, + cairo_gl_surface_t *surface, + cairo_content_t content, + int width, int height); + +static cairo_always_inline cairo_bool_t cairo_warn +_cairo_gl_surface_is_texture (cairo_gl_surface_t *surface) +{ + return surface->tex != 0; +} + +cairo_private cairo_status_t +_cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, + cairo_image_surface_t *src, + int src_x, int src_y, + int width, int height, + int dst_x, int dst_y, + cairo_bool_t force_flush); + +cairo_private cairo_int_status_t +_cairo_gl_surface_resolve_multisampling (cairo_gl_surface_t *surface); + +static cairo_always_inline cairo_bool_t +_cairo_gl_device_has_glsl (cairo_device_t *device) +{ + return ((cairo_gl_context_t *) device)->has_shader_support; +} + +static cairo_always_inline cairo_bool_t +_cairo_gl_device_requires_power_of_two_textures (cairo_device_t *device) +{ + return ((cairo_gl_context_t *) device)->tex_target == GL_TEXTURE_RECTANGLE; +} + +static cairo_always_inline cairo_status_t cairo_warn +_cairo_gl_context_acquire (cairo_device_t *device, + cairo_gl_context_t **ctx) +{ + cairo_status_t status; + + status = cairo_device_acquire (device); + if (unlikely (status)) + return status; + + /* clear potential previous GL errors */ + _cairo_gl_get_error (); + + *ctx = (cairo_gl_context_t *) device; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_always_inline cairo_warn cairo_status_t +_cairo_gl_context_release (cairo_gl_context_t *ctx, cairo_status_t status) +{ + GLenum err; + + err = _cairo_gl_get_error (); + + if (unlikely (err)) { + cairo_status_t new_status; + new_status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + if (status == CAIRO_STATUS_SUCCESS) + status = new_status; + } + + cairo_device_release (&(ctx)->base); + + return status; +} + +cairo_private void +_cairo_gl_context_set_destination (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface, + cairo_bool_t multisampling); + +cairo_private void +_cairo_gl_context_bind_framebuffer (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface, + cairo_bool_t multisampling); + +cairo_private cairo_gl_emit_rect_t +_cairo_gl_context_choose_emit_rect (cairo_gl_context_t *ctx); + +cairo_private void +_cairo_gl_context_emit_rect (cairo_gl_context_t *ctx, + GLfloat x1, GLfloat y1, + GLfloat x2, GLfloat y2); + +cairo_private cairo_gl_emit_span_t +_cairo_gl_context_choose_emit_span (cairo_gl_context_t *ctx); + +cairo_private cairo_gl_emit_glyph_t +_cairo_gl_context_choose_emit_glyph (cairo_gl_context_t *ctx); + +cairo_private void +_cairo_gl_context_activate (cairo_gl_context_t *ctx, + cairo_gl_tex_t tex_unit); + +cairo_private cairo_bool_t +_cairo_gl_operator_is_supported (cairo_operator_t op); + +cairo_private cairo_bool_t +_cairo_gl_ensure_stencil (cairo_gl_context_t *ctx, + cairo_gl_surface_t *surface); + +cairo_private cairo_status_t +_cairo_gl_composite_init (cairo_gl_composite_t *setup, + cairo_operator_t op, + cairo_gl_surface_t *dst, + cairo_bool_t has_component_alpha); + +cairo_private void +_cairo_gl_composite_fini (cairo_gl_composite_t *setup); + +cairo_private cairo_status_t +_cairo_gl_composite_set_operator (cairo_gl_composite_t *setup, + cairo_operator_t op, + cairo_bool_t assume_component_alpha); + +cairo_private void +_cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup, + cairo_region_t *clip_region); + +cairo_private void +_cairo_gl_composite_set_clip(cairo_gl_composite_t *setup, + cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_gl_composite_set_source (cairo_gl_composite_t *setup, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen); + +cairo_private void +_cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup, + const cairo_color_t *color); + +cairo_private void +_cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup, + const cairo_gl_operand_t *source); + +cairo_private cairo_int_status_t +_cairo_gl_composite_set_mask (cairo_gl_composite_t *setup, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen); + +cairo_private void +_cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup, + const cairo_gl_operand_t *mask); + +cairo_private void +_cairo_gl_composite_set_spans (cairo_gl_composite_t *setup); + +cairo_private void +_cairo_gl_composite_set_multisample (cairo_gl_composite_t *setup); + +cairo_private cairo_status_t +_cairo_gl_composite_begin (cairo_gl_composite_t *setup, + cairo_gl_context_t **ctx); + +cairo_private cairo_status_t +_cairo_gl_set_operands_and_operator (cairo_gl_composite_t *setup, + cairo_gl_context_t *ctx); + +cairo_private void +_cairo_gl_composite_flush (cairo_gl_context_t *ctx); + +cairo_private cairo_int_status_t +_cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + const cairo_point_t quad[4]); + +cairo_private cairo_int_status_t +_cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + const cairo_point_t triangle[3]); + +cairo_private void +_cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx, + cairo_gl_tex_t tex_unit); + +cairo_private cairo_bool_t +_cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor, + pixman_format_code_t pixman_format, + GLenum *internal_format, GLenum *format, + GLenum *type, cairo_bool_t *has_alpha, + cairo_bool_t *needs_swap); + +cairo_private void +_cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache); + +cairo_private void +_cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx, + cairo_gl_glyph_cache_t *cache); + +cairo_private cairo_int_status_t +_cairo_gl_surface_show_glyphs (void *abstract_dst, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip, + int *remaining_glyphs); + +cairo_private cairo_status_t +_cairo_gl_context_init_shaders (cairo_gl_context_t *ctx); + +cairo_private void +_cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx); + +static cairo_always_inline cairo_bool_t +_cairo_gl_context_is_flushed (cairo_gl_context_t *ctx) +{ + return ctx->vb_offset == 0; +} + +cairo_private cairo_status_t +_cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx, + cairo_gl_operand_t *source, + cairo_gl_operand_t *mask, + cairo_bool_t use_coverage, + cairo_gl_shader_in_t in, + cairo_gl_shader_t **shader); + +cairo_private void +_cairo_gl_shader_bind_float (cairo_gl_context_t *ctx, + GLint location, + float value); + +cairo_private void +_cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx, + GLint location, + float value0, float value1); + +cairo_private void +_cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx, + GLint location, + float value0, + float value1, + float value2); + +cairo_private void +_cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx, + GLint location, + float value0, float value1, + float value2, float value3); + +cairo_private void +_cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx, + GLint location, + const cairo_matrix_t* m); + +cairo_private void +_cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx, + GLint location, + GLfloat* gl_m); + +cairo_private void +_cairo_gl_set_shader (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader); + +cairo_private void +_cairo_gl_shader_fini (cairo_gl_context_t *ctx, cairo_gl_shader_t *shader); + +cairo_private int +_cairo_gl_get_version (void); + +cairo_private cairo_gl_flavor_t +_cairo_gl_get_flavor (void); + +cairo_private unsigned long +_cairo_gl_get_vbo_size (void); + +cairo_private cairo_bool_t +_cairo_gl_has_extension (const char *ext); + +cairo_private cairo_status_t +_cairo_gl_dispatch_init(cairo_gl_dispatch_t *dispatch, + cairo_gl_get_proc_addr_func_t get_proc_addr); + +cairo_private cairo_int_status_t +_cairo_gl_operand_init (cairo_gl_operand_t *operand, + const cairo_pattern_t *pattern, + cairo_gl_surface_t *dst, + const cairo_rectangle_int_t *sample, + const cairo_rectangle_int_t *extents, + cairo_bool_t use_texgen); + +cairo_private void +_cairo_gl_solid_operand_init (cairo_gl_operand_t *operand, + const cairo_color_t *color); + +cairo_private cairo_filter_t +_cairo_gl_operand_get_filter (cairo_gl_operand_t *operand); + +cairo_private GLint +_cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand); + +cairo_private cairo_extend_t +_cairo_gl_operand_get_extend (cairo_gl_operand_t *operand); + +cairo_private unsigned int +_cairo_gl_operand_get_vertex_size (const cairo_gl_operand_t *operand); + +cairo_private cairo_bool_t +_cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest, + cairo_gl_operand_t *source, + unsigned int vertex_offset); + +cairo_private void +_cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, + cairo_gl_operand_t *operand, + cairo_gl_tex_t tex_unit); + +cairo_private void +_cairo_gl_operand_emit (cairo_gl_operand_t *operand, + GLfloat ** vb, + GLfloat x, + GLfloat y); + +cairo_private void +_cairo_gl_operand_copy (cairo_gl_operand_t *dst, + const cairo_gl_operand_t *src); + +cairo_private void +_cairo_gl_operand_translate (cairo_gl_operand_t *operand, + double tx, double ty); + +cairo_private void +_cairo_gl_operand_destroy (cairo_gl_operand_t *operand); + +cairo_private const cairo_compositor_t * +_cairo_gl_msaa_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_gl_span_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_gl_traps_compositor_get (void); + +cairo_private cairo_int_status_t +_cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs); + +cairo_private cairo_int_status_t +_cairo_gl_composite_glyphs (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info); + +cairo_private cairo_int_status_t +_cairo_gl_composite_glyphs_with_clip (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info, + cairo_clip_t *clip); + +cairo_private cairo_surface_t * +_cairo_gl_surface_create_scratch (cairo_gl_context_t *ctx, + cairo_content_t content, + int width, + int height); + +cairo_private cairo_surface_t * +_cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx, + cairo_content_t content, + int width, + int height); + +cairo_private cairo_surface_t * +_cairo_gl_pattern_to_source (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y); + +cairo_private cairo_int_status_t +_cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_clip_t *clip); + +cairo_private cairo_surface_t * +_cairo_gl_white_source (void); + +cairo_private void +_cairo_gl_scissor_to_rectangle (cairo_gl_surface_t *surface, + const cairo_rectangle_int_t *r); + +static inline cairo_gl_operand_t * +source_to_operand (cairo_surface_t *surface) +{ + cairo_gl_source_t *source = (cairo_gl_source_t *)surface; + return source ? &source->operand : NULL; +} + +static inline void +_cairo_gl_glyph_cache_unlock (cairo_gl_glyph_cache_t *cache) +{ + _cairo_rtree_unpin (&cache->rtree); +} + + +slim_hidden_proto (cairo_gl_surface_create); +slim_hidden_proto (cairo_gl_surface_create_for_texture); + +#endif /* CAIRO_GL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-shaders.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-shaders.c new file mode 100644 index 00000000000..fe975d2d7c9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-shaders.c @@ -0,0 +1,1093 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 T. Zachary Laine + * Copyright © 2010 Eric Anholt + * Copyright © 2010 Red Hat, Inc + * Copyright © 2010 Linaro Limited + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is T. Zachary Laine. + * + * Contributor(s): + * Benjamin Otte + * Eric Anholt + * T. Zachary Laine + * Alexandros Frantzis + */ + +#include "cairoint.h" +#include "cairo-gl-private.h" +#include "cairo-error-private.h" +#include "cairo-output-stream-private.h" + +static cairo_status_t +_cairo_gl_shader_compile_and_link (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader, + cairo_gl_var_type_t src, + cairo_gl_var_type_t mask, + cairo_bool_t use_coverage, + const char *fragment_text); + +typedef struct _cairo_shader_cache_entry { + cairo_cache_entry_t base; + + unsigned vertex; + + cairo_gl_operand_type_t src; + cairo_gl_operand_type_t mask; + cairo_gl_operand_type_t dest; + cairo_bool_t use_coverage; + + cairo_gl_shader_in_t in; + GLint src_gl_filter; + cairo_bool_t src_border_fade; + cairo_extend_t src_extend; + GLint mask_gl_filter; + cairo_bool_t mask_border_fade; + cairo_extend_t mask_extend; + + cairo_gl_context_t *ctx; /* XXX: needed to destroy the program */ + cairo_gl_shader_t shader; +} cairo_shader_cache_entry_t; + +static cairo_bool_t +_cairo_gl_shader_cache_equal_desktop (const void *key_a, const void *key_b) +{ + const cairo_shader_cache_entry_t *a = key_a; + const cairo_shader_cache_entry_t *b = key_b; + cairo_bool_t both_have_npot_repeat = + a->ctx->has_npot_repeat && b->ctx->has_npot_repeat; + + return (a->vertex == b->vertex && + a->src == b->src && + a->mask == b->mask && + a->dest == b->dest && + a->use_coverage == b->use_coverage && + a->in == b->in && + (both_have_npot_repeat || a->src_extend == b->src_extend) && + (both_have_npot_repeat || a->mask_extend == b->mask_extend)); +} + +/* + * For GLES2 we use more complicated shaders to implement missing GL + * features. In this case we need more parameters to uniquely identify + * a shader (vs _cairo_gl_shader_cache_equal_desktop()). + */ +static cairo_bool_t +_cairo_gl_shader_cache_equal_gles2 (const void *key_a, const void *key_b) +{ + const cairo_shader_cache_entry_t *a = key_a; + const cairo_shader_cache_entry_t *b = key_b; + cairo_bool_t both_have_npot_repeat = + a->ctx->has_npot_repeat && b->ctx->has_npot_repeat; + + return (a->vertex == b->vertex && + a->src == b->src && + a->mask == b->mask && + a->dest == b->dest && + a->use_coverage == b->use_coverage && + a->in == b->in && + a->src_gl_filter == b->src_gl_filter && + a->src_border_fade == b->src_border_fade && + (both_have_npot_repeat || a->src_extend == b->src_extend) && + a->mask_gl_filter == b->mask_gl_filter && + a->mask_border_fade == b->mask_border_fade && + (both_have_npot_repeat || a->mask_extend == b->mask_extend)); +} + +static unsigned long +_cairo_gl_shader_cache_hash (const cairo_shader_cache_entry_t *entry) +{ + return ((entry->src << 24) | (entry->mask << 16) | (entry->dest << 8) | (entry->in << 1) | entry->use_coverage) ^ entry->vertex; +} + +static void +_cairo_gl_shader_cache_destroy (void *data) +{ + cairo_shader_cache_entry_t *entry = data; + + _cairo_gl_shader_fini (entry->ctx, &entry->shader); + if (entry->ctx->current_shader == &entry->shader) + entry->ctx->current_shader = NULL; + free (entry); +} + +static void +_cairo_gl_shader_init (cairo_gl_shader_t *shader) +{ + shader->fragment_shader = 0; + shader->program = 0; +} + +cairo_status_t +_cairo_gl_context_init_shaders (cairo_gl_context_t *ctx) +{ + static const char *fill_fs_source = + "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "uniform vec4 color;\n" + "void main()\n" + "{\n" + " gl_FragColor = color;\n" + "}\n"; + cairo_status_t status; + + if (_cairo_gl_get_version () >= CAIRO_GL_VERSION_ENCODE (2, 0) || + (_cairo_gl_has_extension ("GL_ARB_shader_objects") && + _cairo_gl_has_extension ("GL_ARB_fragment_shader") && + _cairo_gl_has_extension ("GL_ARB_vertex_shader"))) { + ctx->has_shader_support = TRUE; + } else { + ctx->has_shader_support = FALSE; + fprintf (stderr, "Error: The cairo gl backend requires shader support!\n"); + return CAIRO_STATUS_DEVICE_ERROR; + } + + memset (ctx->vertex_shaders, 0, sizeof (ctx->vertex_shaders)); + + status = _cairo_cache_init (&ctx->shaders, + ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP ? + _cairo_gl_shader_cache_equal_desktop : + _cairo_gl_shader_cache_equal_gles2, + NULL, + _cairo_gl_shader_cache_destroy, + CAIRO_GL_MAX_SHADERS_PER_CONTEXT); + if (unlikely (status)) + return status; + + _cairo_gl_shader_init (&ctx->fill_rectangles_shader); + status = _cairo_gl_shader_compile_and_link (ctx, + &ctx->fill_rectangles_shader, + CAIRO_GL_VAR_NONE, + CAIRO_GL_VAR_NONE, + FALSE, + fill_fs_source); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx) +{ + int i; + + for (i = 0; i < CAIRO_GL_VAR_TYPE_MAX; i++) { + if (ctx->vertex_shaders[i]) + ctx->dispatch.DeleteShader (ctx->vertex_shaders[i]); + } + + _cairo_cache_fini (&ctx->shaders); +} + +void +_cairo_gl_shader_fini (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader) +{ + if (shader->fragment_shader) + ctx->dispatch.DeleteShader (shader->fragment_shader); + + if (shader->program) + ctx->dispatch.DeleteProgram (shader->program); +} + +static const char *operand_names[] = { "source", "mask", "dest" }; + +static cairo_gl_var_type_t +cairo_gl_operand_get_var_type (cairo_gl_operand_t *operand) +{ + switch (operand->type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_CONSTANT: + return CAIRO_GL_VAR_NONE; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + return operand->gradient.texgen ? CAIRO_GL_VAR_TEXGEN : CAIRO_GL_VAR_TEXCOORDS; + case CAIRO_GL_OPERAND_TEXTURE: + return operand->texture.texgen ? CAIRO_GL_VAR_TEXGEN : CAIRO_GL_VAR_TEXCOORDS; + } +} + +static void +cairo_gl_shader_emit_variable (cairo_output_stream_t *stream, + cairo_gl_var_type_t type, + cairo_gl_tex_t name) +{ + switch (type) { + default: + ASSERT_NOT_REACHED; + case CAIRO_GL_VAR_NONE: + break; + case CAIRO_GL_VAR_TEXCOORDS: + _cairo_output_stream_printf (stream, + "attribute vec4 MultiTexCoord%d;\n" + "varying vec2 %s_texcoords;\n", + name, + operand_names[name]); + break; + case CAIRO_GL_VAR_TEXGEN: + _cairo_output_stream_printf (stream, + "uniform mat3 %s_texgen;\n" + "varying vec2 %s_texcoords;\n", + operand_names[name], + operand_names[name]); + break; + } +} + +static void +cairo_gl_shader_emit_vertex (cairo_output_stream_t *stream, + cairo_gl_var_type_t type, + cairo_gl_tex_t name) +{ + switch (type) { + default: + ASSERT_NOT_REACHED; + case CAIRO_GL_VAR_NONE: + break; + case CAIRO_GL_VAR_TEXCOORDS: + _cairo_output_stream_printf (stream, + " %s_texcoords = MultiTexCoord%d.xy;\n", + operand_names[name], name); + break; + + case CAIRO_GL_VAR_TEXGEN: + _cairo_output_stream_printf (stream, + " %s_texcoords = (%s_texgen * Vertex.xyw).xy;\n", + operand_names[name], operand_names[name]); + break; + } +} + +static void +cairo_gl_shader_dcl_coverage (cairo_output_stream_t *stream) +{ + _cairo_output_stream_printf (stream, "varying float coverage;\n"); +} + +static void +cairo_gl_shader_def_coverage (cairo_output_stream_t *stream) +{ + _cairo_output_stream_printf (stream, " coverage = Color.a;\n"); +} + +static cairo_status_t +cairo_gl_shader_get_vertex_source (cairo_gl_var_type_t src, + cairo_gl_var_type_t mask, + cairo_bool_t use_coverage, + cairo_gl_var_type_t dest, + char **out) +{ + cairo_output_stream_t *stream = _cairo_memory_stream_create (); + unsigned char *source; + unsigned long length; + cairo_status_t status; + + cairo_gl_shader_emit_variable (stream, src, CAIRO_GL_TEX_SOURCE); + cairo_gl_shader_emit_variable (stream, mask, CAIRO_GL_TEX_MASK); + if (use_coverage) + cairo_gl_shader_dcl_coverage (stream); + + _cairo_output_stream_printf (stream, + "attribute vec4 Vertex;\n" + "attribute vec4 Color;\n" + "uniform mat4 ModelViewProjectionMatrix;\n" + "void main()\n" + "{\n" + " gl_Position = ModelViewProjectionMatrix * Vertex;\n"); + + cairo_gl_shader_emit_vertex (stream, src, CAIRO_GL_TEX_SOURCE); + cairo_gl_shader_emit_vertex (stream, mask, CAIRO_GL_TEX_MASK); + if (use_coverage) + cairo_gl_shader_def_coverage (stream); + + _cairo_output_stream_write (stream, + "}\n\0", 3); + + status = _cairo_memory_stream_destroy (stream, &source, &length); + if (unlikely (status)) + return status; + + *out = (char *) source; + return CAIRO_STATUS_SUCCESS; +} + +/* + * Returns whether an operand needs a special border fade fragment shader + * to simulate the GL_CLAMP_TO_BORDER wrapping method that is missing in GLES2. + */ +static cairo_bool_t +_cairo_gl_shader_needs_border_fade (cairo_gl_operand_t *operand) +{ + cairo_extend_t extend =_cairo_gl_operand_get_extend (operand); + + return extend == CAIRO_EXTEND_NONE && + (operand->type == CAIRO_GL_OPERAND_TEXTURE || + operand->type == CAIRO_GL_OPERAND_LINEAR_GRADIENT || + operand->type == CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE || + operand->type == CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0); +} + +static void +cairo_gl_shader_emit_color (cairo_output_stream_t *stream, + cairo_gl_context_t *ctx, + cairo_gl_operand_t *op, + cairo_gl_tex_t name) +{ + const char *namestr = operand_names[name]; + const char *rectstr = (ctx->tex_target == GL_TEXTURE_RECTANGLE ? "Rect" : ""); + + switch (op->type) { + case CAIRO_GL_OPERAND_COUNT: + default: + ASSERT_NOT_REACHED; + break; + case CAIRO_GL_OPERAND_NONE: + _cairo_output_stream_printf (stream, + "vec4 get_%s()\n" + "{\n" + " return vec4 (0, 0, 0, 1);\n" + "}\n", + namestr); + break; + case CAIRO_GL_OPERAND_CONSTANT: + _cairo_output_stream_printf (stream, + "uniform vec4 %s_constant;\n" + "vec4 get_%s()\n" + "{\n" + " return %s_constant;\n" + "}\n", + namestr, namestr, namestr); + break; + case CAIRO_GL_OPERAND_TEXTURE: + _cairo_output_stream_printf (stream, + "uniform sampler2D%s %s_sampler;\n" + "uniform vec2 %s_texdims;\n" + "varying vec2 %s_texcoords;\n" + "vec4 get_%s()\n" + "{\n", + rectstr, namestr, namestr, namestr, namestr); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + _cairo_gl_shader_needs_border_fade (op)) + { + _cairo_output_stream_printf (stream, + " vec2 border_fade = %s_border_fade (%s_texcoords, %s_texdims);\n" + " vec4 texel = texture2D%s (%s_sampler, %s_texcoords);\n" + " return texel * border_fade.x * border_fade.y;\n" + "}\n", + namestr, namestr, namestr, rectstr, namestr, namestr); + } + else + { + _cairo_output_stream_printf (stream, + " return texture2D%s (%s_sampler, %s_wrap (%s_texcoords));\n" + "}\n", + rectstr, namestr, namestr, namestr); + } + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + _cairo_output_stream_printf (stream, + "varying vec2 %s_texcoords;\n" + "uniform vec2 %s_texdims;\n" + "uniform sampler2D%s %s_sampler;\n" + "\n" + "vec4 get_%s()\n" + "{\n", + namestr, namestr, rectstr, namestr, namestr); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + _cairo_gl_shader_needs_border_fade (op)) + { + _cairo_output_stream_printf (stream, + " float border_fade = %s_border_fade (%s_texcoords.x, %s_texdims.x);\n" + " vec4 texel = texture2D%s (%s_sampler, vec2 (%s_texcoords.x, 0.5));\n" + " return texel * border_fade;\n" + "}\n", + namestr, namestr, namestr, rectstr, namestr, namestr); + } + else + { + _cairo_output_stream_printf (stream, + " return texture2D%s (%s_sampler, %s_wrap (vec2 (%s_texcoords.x, 0.5)));\n" + "}\n", + rectstr, namestr, namestr, namestr); + } + break; + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0: + _cairo_output_stream_printf (stream, + "varying vec2 %s_texcoords;\n" + "uniform vec2 %s_texdims;\n" + "uniform sampler2D%s %s_sampler;\n" + "uniform vec3 %s_circle_d;\n" + "uniform float %s_radius_0;\n" + "\n" + "vec4 get_%s()\n" + "{\n" + " vec3 pos = vec3 (%s_texcoords, %s_radius_0);\n" + " \n" + " float B = dot (pos, %s_circle_d);\n" + " float C = dot (pos, vec3 (pos.xy, -pos.z));\n" + " \n" + " float t = 0.5 * C / B;\n" + " float is_valid = step (-%s_radius_0, t * %s_circle_d.z);\n", + namestr, namestr, rectstr, namestr, namestr, namestr, namestr, + namestr, namestr, namestr, namestr, namestr); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + _cairo_gl_shader_needs_border_fade (op)) + { + _cairo_output_stream_printf (stream, + " float border_fade = %s_border_fade (t, %s_texdims.x);\n" + " vec4 texel = texture2D%s (%s_sampler, vec2 (t, 0.5));\n" + " return mix (vec4 (0.0), texel * border_fade, is_valid);\n" + "}\n", + namestr, namestr, rectstr, namestr); + } + else + { + _cairo_output_stream_printf (stream, + " vec4 texel = texture2D%s (%s_sampler, %s_wrap (vec2 (t, 0.5)));\n" + " return mix (vec4 (0.0), texel, is_valid);\n" + "}\n", + rectstr, namestr, namestr); + } + break; + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE: + _cairo_output_stream_printf (stream, + "varying vec2 %s_texcoords;\n" + "uniform vec2 %s_texdims;\n" + "uniform sampler2D%s %s_sampler;\n" + "uniform vec3 %s_circle_d;\n" + "uniform float %s_a;\n" + "uniform float %s_radius_0;\n" + "\n" + "vec4 get_%s()\n" + "{\n" + " vec3 pos = vec3 (%s_texcoords, %s_radius_0);\n" + " \n" + " float B = dot (pos, %s_circle_d);\n" + " float C = dot (pos, vec3 (pos.xy, -pos.z));\n" + " \n" + " float det = dot (vec2 (B, %s_a), vec2 (B, -C));\n" + " float sqrtdet = sqrt (abs (det));\n" + " vec2 t = (B + vec2 (sqrtdet, -sqrtdet)) / %s_a;\n" + " \n" + " vec2 is_valid = step (vec2 (0.0), t) * step (t, vec2(1.0));\n" + " float has_color = step (0., det) * max (is_valid.x, is_valid.y);\n" + " \n" + " float upper_t = mix (t.y, t.x, is_valid.x);\n", + namestr, namestr, rectstr, namestr, namestr, namestr, namestr, + namestr, namestr, namestr, namestr, namestr, namestr); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + _cairo_gl_shader_needs_border_fade (op)) + { + _cairo_output_stream_printf (stream, + " float border_fade = %s_border_fade (upper_t, %s_texdims.x);\n" + " vec4 texel = texture2D%s (%s_sampler, vec2 (upper_t, 0.5));\n" + " return mix (vec4 (0.0), texel * border_fade, has_color);\n" + "}\n", + namestr, namestr, rectstr, namestr); + } + else + { + _cairo_output_stream_printf (stream, + " vec4 texel = texture2D%s (%s_sampler, %s_wrap (vec2(upper_t, 0.5)));\n" + " return mix (vec4 (0.0), texel, has_color);\n" + "}\n", + rectstr, namestr, namestr); + } + break; + case CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT: + _cairo_output_stream_printf (stream, + "varying vec2 %s_texcoords;\n" + "uniform sampler2D%s %s_sampler;\n" + "uniform vec3 %s_circle_d;\n" + "uniform float %s_a;\n" + "uniform float %s_radius_0;\n" + "\n" + "vec4 get_%s()\n" + "{\n" + " vec3 pos = vec3 (%s_texcoords, %s_radius_0);\n" + " \n" + " float B = dot (pos, %s_circle_d);\n" + " float C = dot (pos, vec3 (pos.xy, -pos.z));\n" + " \n" + " float det = dot (vec2 (B, %s_a), vec2 (B, -C));\n" + " float sqrtdet = sqrt (abs (det));\n" + " vec2 t = (B + vec2 (sqrtdet, -sqrtdet)) / %s_a;\n" + " \n" + " vec2 is_valid = step (vec2 (-%s_radius_0), t * %s_circle_d.z);\n" + " float has_color = step (0., det) * max (is_valid.x, is_valid.y);\n" + " \n" + " float upper_t = mix (t.y, t.x, is_valid.x);\n" + " vec4 texel = texture2D%s (%s_sampler, %s_wrap (vec2(upper_t, 0.5)));\n" + " return mix (vec4 (0.0), texel, has_color);\n" + "}\n", + namestr, rectstr, namestr, namestr, namestr, namestr, + namestr, namestr, namestr, namestr, namestr, + namestr, namestr, namestr, rectstr, namestr, namestr); + break; + } +} + +/* + * Emits the border fade functions used by an operand. + * + * If bilinear filtering is used, the emitted function performs a linear + * fade to transparency effect in the intervals [-1/2n, 1/2n] and + * [1 - 1/2n, 1 + 1/2n] (n: texture size). + * + * If nearest filtering is used, the emitted function just returns + * 0.0 for all values outside [0, 1). + */ +static void +_cairo_gl_shader_emit_border_fade (cairo_output_stream_t *stream, + cairo_gl_operand_t *operand, + cairo_gl_tex_t name) +{ + const char *namestr = operand_names[name]; + GLint gl_filter = _cairo_gl_operand_get_gl_filter (operand); + + /* 2D version */ + _cairo_output_stream_printf (stream, + "vec2 %s_border_fade (vec2 coords, vec2 dims)\n" + "{\n", + namestr); + + if (gl_filter == GL_LINEAR) + _cairo_output_stream_printf (stream, + " return clamp(-abs(dims * (coords - 0.5)) + (dims + vec2(1.0)) * 0.5, 0.0, 1.0);\n"); + else + _cairo_output_stream_printf (stream, + " bvec2 in_tex1 = greaterThanEqual (coords, vec2 (0.0));\n" + " bvec2 in_tex2 = lessThan (coords, vec2 (1.0));\n" + " return vec2 (float (all (in_tex1) && all (in_tex2)));\n"); + + _cairo_output_stream_printf (stream, "}\n"); + + /* 1D version */ + _cairo_output_stream_printf (stream, + "float %s_border_fade (float x, float dim)\n" + "{\n", + namestr); + if (gl_filter == GL_LINEAR) + _cairo_output_stream_printf (stream, + " return clamp(-abs(dim * (x - 0.5)) + (dim + 1.0) * 0.5, 0.0, 1.0);\n"); + else + _cairo_output_stream_printf (stream, + " bool in_tex = x >= 0.0 && x < 1.0;\n" + " return float (in_tex);\n"); + + _cairo_output_stream_printf (stream, "}\n"); +} + +/* + * Emits the wrap function used by an operand. + * + * In OpenGL ES 2.0, repeat wrap modes (GL_REPEAT and GL_MIRRORED REPEAT) are + * only available for NPOT textures if the GL_OES_texture_npot is supported. + * If GL_OES_texture_npot is not supported, we need to implement the wrapping + * functionality in the shader. + */ +static void +_cairo_gl_shader_emit_wrap (cairo_gl_context_t *ctx, + cairo_output_stream_t *stream, + cairo_gl_operand_t *operand, + cairo_gl_tex_t name) +{ + const char *namestr = operand_names[name]; + cairo_extend_t extend = _cairo_gl_operand_get_extend (operand); + + _cairo_output_stream_printf (stream, + "vec2 %s_wrap(vec2 coords)\n" + "{\n", + namestr); + + if (! ctx->has_npot_repeat && + (extend == CAIRO_EXTEND_REPEAT || extend == CAIRO_EXTEND_REFLECT)) + { + if (extend == CAIRO_EXTEND_REPEAT) { + _cairo_output_stream_printf (stream, + " return fract(coords);\n"); + } else { /* CAIRO_EXTEND_REFLECT */ + _cairo_output_stream_printf (stream, + " return mix(fract(coords), 1.0 - fract(coords), floor(mod(coords, 2.0)));\n"); + } + } + else + { + _cairo_output_stream_printf (stream, " return coords;\n"); + } + + _cairo_output_stream_printf (stream, "}\n"); +} + +static cairo_status_t +cairo_gl_shader_get_fragment_source (cairo_gl_context_t *ctx, + cairo_gl_shader_in_t in, + cairo_gl_operand_t *src, + cairo_gl_operand_t *mask, + cairo_bool_t use_coverage, + cairo_gl_operand_type_t dest_type, + char **out) +{ + cairo_output_stream_t *stream = _cairo_memory_stream_create (); + unsigned char *source; + unsigned long length; + cairo_status_t status; + const char *coverage_str; + + _cairo_output_stream_printf (stream, + "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n"); + + _cairo_gl_shader_emit_wrap (ctx, stream, src, CAIRO_GL_TEX_SOURCE); + _cairo_gl_shader_emit_wrap (ctx, stream, mask, CAIRO_GL_TEX_MASK); + + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { + if (_cairo_gl_shader_needs_border_fade (src)) + _cairo_gl_shader_emit_border_fade (stream, src, CAIRO_GL_TEX_SOURCE); + if (_cairo_gl_shader_needs_border_fade (mask)) + _cairo_gl_shader_emit_border_fade (stream, mask, CAIRO_GL_TEX_MASK); + } + + cairo_gl_shader_emit_color (stream, ctx, src, CAIRO_GL_TEX_SOURCE); + cairo_gl_shader_emit_color (stream, ctx, mask, CAIRO_GL_TEX_MASK); + + coverage_str = ""; + if (use_coverage) { + _cairo_output_stream_printf (stream, "varying float coverage;\n"); + coverage_str = " * coverage"; + } + + _cairo_output_stream_printf (stream, + "void main()\n" + "{\n"); + switch (in) { + case CAIRO_GL_SHADER_IN_COUNT: + default: + ASSERT_NOT_REACHED; + case CAIRO_GL_SHADER_IN_NORMAL: + _cairo_output_stream_printf (stream, + " gl_FragColor = get_source() * get_mask().a%s;\n", + coverage_str); + break; + case CAIRO_GL_SHADER_IN_CA_SOURCE: + _cairo_output_stream_printf (stream, + " gl_FragColor = get_source() * get_mask()%s;\n", + coverage_str); + break; + case CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA: + _cairo_output_stream_printf (stream, + " gl_FragColor = get_source().a * get_mask()%s;\n", + coverage_str); + break; + } + + _cairo_output_stream_write (stream, + "}\n\0", 3); + + status = _cairo_memory_stream_destroy (stream, &source, &length); + if (unlikely (status)) + return status; + + *out = (char *) source; + return CAIRO_STATUS_SUCCESS; +} + +static void +compile_shader (cairo_gl_context_t *ctx, + GLuint *shader, + GLenum type, + const char *source) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + GLint success, log_size, num_chars; + char *log; + + *shader = dispatch->CreateShader (type); + dispatch->ShaderSource (*shader, 1, &source, 0); + dispatch->CompileShader (*shader); + dispatch->GetShaderiv (*shader, GL_COMPILE_STATUS, &success); + + if (success) + return; + + dispatch->GetShaderiv (*shader, GL_INFO_LOG_LENGTH, &log_size); + if (log_size < 0) { + printf ("OpenGL shader compilation failed.\n"); + ASSERT_NOT_REACHED; + return; + } + + log = _cairo_malloc (log_size + 1); + dispatch->GetShaderInfoLog (*shader, log_size, &num_chars, log); + log[num_chars] = '\0'; + + printf ("OpenGL shader compilation failed. Shader:\n%s\n", source); + printf ("OpenGL compilation log:\n%s\n", log); + + free (log); + ASSERT_NOT_REACHED; +} + +static void +link_shader_program (cairo_gl_context_t *ctx, + GLuint *program, + GLuint vert, + GLuint frag) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + GLint success, log_size, num_chars; + char *log; + + *program = dispatch->CreateProgram (); + dispatch->AttachShader (*program, vert); + dispatch->AttachShader (*program, frag); + + dispatch->BindAttribLocation (*program, CAIRO_GL_VERTEX_ATTRIB_INDEX, + "Vertex"); + dispatch->BindAttribLocation (*program, CAIRO_GL_COLOR_ATTRIB_INDEX, + "Color"); + dispatch->BindAttribLocation (*program, CAIRO_GL_TEXCOORD0_ATTRIB_INDEX, + "MultiTexCoord0"); + dispatch->BindAttribLocation (*program, CAIRO_GL_TEXCOORD1_ATTRIB_INDEX, + "MultiTexCoord1"); + + dispatch->LinkProgram (*program); + dispatch->GetProgramiv (*program, GL_LINK_STATUS, &success); + if (success) + return; + + dispatch->GetProgramiv (*program, GL_INFO_LOG_LENGTH, &log_size); + if (log_size < 0) { + printf ("OpenGL shader link failed.\n"); + ASSERT_NOT_REACHED; + return; + } + + log = _cairo_malloc (log_size + 1); + dispatch->GetProgramInfoLog (*program, log_size, &num_chars, log); + log[num_chars] = '\0'; + + printf ("OpenGL shader link failed:\n%s\n", log); + free (log); + ASSERT_NOT_REACHED; +} + +static GLint +_cairo_gl_get_op_uniform_location(cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader, + cairo_gl_tex_t tex_unit, + const char *suffix) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + char uniform_name[100]; + const char *unit_name[2] = { "source", "mask" }; + + snprintf (uniform_name, sizeof (uniform_name), "%s_%s", + unit_name[tex_unit], suffix); + + return dispatch->GetUniformLocation (shader->program, uniform_name); +} + +static cairo_status_t +_cairo_gl_shader_compile_and_link (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader, + cairo_gl_var_type_t src, + cairo_gl_var_type_t mask, + cairo_bool_t use_coverage, + const char *fragment_text) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + unsigned int vertex_shader; + cairo_status_t status; + int i; + + assert (shader->program == 0); + + vertex_shader = cairo_gl_var_type_hash (src, mask, use_coverage, + CAIRO_GL_VAR_NONE); + if (ctx->vertex_shaders[vertex_shader] == 0) { + char *source; + + status = cairo_gl_shader_get_vertex_source (src, + mask, + use_coverage, + CAIRO_GL_VAR_NONE, + &source); + if (unlikely (status)) + goto FAILURE; + + compile_shader (ctx, &ctx->vertex_shaders[vertex_shader], + GL_VERTEX_SHADER, source); + free (source); + } + + compile_shader (ctx, &shader->fragment_shader, + GL_FRAGMENT_SHADER, fragment_text); + + link_shader_program (ctx, &shader->program, + ctx->vertex_shaders[vertex_shader], + shader->fragment_shader); + + shader->mvp_location = + dispatch->GetUniformLocation (shader->program, + "ModelViewProjectionMatrix"); + + for (i = 0; i < 2; i++) { + shader->constant_location[i] = + _cairo_gl_get_op_uniform_location (ctx, shader, i, "constant"); + shader->a_location[i] = + _cairo_gl_get_op_uniform_location (ctx, shader, i, "a"); + shader->circle_d_location[i] = + _cairo_gl_get_op_uniform_location (ctx, shader, i, "circle_d"); + shader->radius_0_location[i] = + _cairo_gl_get_op_uniform_location (ctx, shader, i, "radius_0"); + shader->texdims_location[i] = + _cairo_gl_get_op_uniform_location (ctx, shader, i, "texdims"); + shader->texgen_location[i] = + _cairo_gl_get_op_uniform_location (ctx, shader, i, "texgen"); + } + + return CAIRO_STATUS_SUCCESS; + + FAILURE: + _cairo_gl_shader_fini (ctx, shader); + shader->fragment_shader = 0; + shader->program = 0; + + return status; +} + +/* We always bind the source to texture unit 0 if present, and mask to + * texture unit 1 if present, so we can just initialize these once at + * compile time. + */ +static void +_cairo_gl_shader_set_samplers (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + GLint location; + GLint saved_program; + + /* We have to save/restore the current program because we might be + * asked for a different program while a shader is bound. This shouldn't + * be a performance issue, since this is only called once per compile. + */ + glGetIntegerv (GL_CURRENT_PROGRAM, &saved_program); + dispatch->UseProgram (shader->program); + + location = dispatch->GetUniformLocation (shader->program, "source_sampler"); + if (location != -1) { + dispatch->Uniform1i (location, CAIRO_GL_TEX_SOURCE); + } + + location = dispatch->GetUniformLocation (shader->program, "mask_sampler"); + if (location != -1) { + dispatch->Uniform1i (location, CAIRO_GL_TEX_MASK); + } + + dispatch->UseProgram (saved_program); +} + +void +_cairo_gl_shader_bind_float (cairo_gl_context_t *ctx, + GLint location, + float value) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + assert (location != -1); + dispatch->Uniform1f (location, value); +} + +void +_cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx, + GLint location, + float value0, + float value1) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + assert (location != -1); + dispatch->Uniform2f (location, value0, value1); +} + +void +_cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx, + GLint location, + float value0, + float value1, + float value2) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + assert (location != -1); + dispatch->Uniform3f (location, value0, value1, value2); +} + +void +_cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx, + GLint location, + float value0, float value1, + float value2, float value3) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + assert (location != -1); + dispatch->Uniform4f (location, value0, value1, value2, value3); +} + +void +_cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx, + GLint location, + const cairo_matrix_t* m) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + float gl_m[9] = { + m->xx, m->yx, 0, + m->xy, m->yy, 0, + m->x0, m->y0, 1 + }; + assert (location != -1); + dispatch->UniformMatrix3fv (location, 1, GL_FALSE, gl_m); +} + +void +_cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx, + GLint location, GLfloat* gl_m) +{ + cairo_gl_dispatch_t *dispatch = &ctx->dispatch; + assert (location != -1); + dispatch->UniformMatrix4fv (location, 1, GL_FALSE, gl_m); +} + +void +_cairo_gl_set_shader (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader) +{ + if (ctx->current_shader == shader) + return; + + if (shader) + ctx->dispatch.UseProgram (shader->program); + else + ctx->dispatch.UseProgram (0); + + ctx->current_shader = shader; +} + +cairo_status_t +_cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx, + cairo_gl_operand_t *source, + cairo_gl_operand_t *mask, + cairo_bool_t use_coverage, + cairo_gl_shader_in_t in, + cairo_gl_shader_t **shader) +{ + cairo_shader_cache_entry_t lookup, *entry; + char *fs_source; + cairo_status_t status; + + lookup.ctx = ctx; + + lookup.vertex = cairo_gl_var_type_hash (cairo_gl_operand_get_var_type (source), + cairo_gl_operand_get_var_type (mask), + use_coverage, + CAIRO_GL_VAR_NONE); + + lookup.src = source->type; + lookup.mask = mask->type; + lookup.dest = CAIRO_GL_OPERAND_NONE; + lookup.use_coverage = use_coverage; + lookup.in = in; + lookup.src_gl_filter = _cairo_gl_operand_get_gl_filter (source); + lookup.src_border_fade = _cairo_gl_shader_needs_border_fade (source); + lookup.src_extend = _cairo_gl_operand_get_extend (source); + lookup.mask_gl_filter = _cairo_gl_operand_get_gl_filter (mask); + lookup.mask_border_fade = _cairo_gl_shader_needs_border_fade (mask); + lookup.mask_extend = _cairo_gl_operand_get_extend (mask); + lookup.base.hash = _cairo_gl_shader_cache_hash (&lookup); + lookup.base.size = 1; + + entry = _cairo_cache_lookup (&ctx->shaders, &lookup.base); + if (entry) { + assert (entry->shader.program); + *shader = &entry->shader; + return CAIRO_STATUS_SUCCESS; + } + + status = cairo_gl_shader_get_fragment_source (ctx, + in, + source, + mask, + use_coverage, + CAIRO_GL_OPERAND_NONE, + &fs_source); + if (unlikely (status)) + return status; + + entry = malloc (sizeof (cairo_shader_cache_entry_t)); + if (unlikely (entry == NULL)) { + free (fs_source); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + memcpy (entry, &lookup, sizeof (cairo_shader_cache_entry_t)); + + entry->ctx = ctx; + _cairo_gl_shader_init (&entry->shader); + status = _cairo_gl_shader_compile_and_link (ctx, + &entry->shader, + cairo_gl_operand_get_var_type (source), + cairo_gl_operand_get_var_type (mask), + use_coverage, + fs_source); + free (fs_source); + + if (unlikely (status)) { + free (entry); + return status; + } + + _cairo_gl_shader_set_samplers (ctx, &entry->shader); + + status = _cairo_cache_insert (&ctx->shaders, &entry->base); + if (unlikely (status)) { + _cairo_gl_shader_fini (ctx, &entry->shader); + free (entry); + return status; + } + + *shader = &entry->shader; + + return CAIRO_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-source.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-source.c new file mode 100644 index 00000000000..12235295f40 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-source.c @@ -0,0 +1,111 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-surface-backend-private.h" + +static cairo_status_t +_cairo_gl_source_finish (void *abstract_surface) +{ + cairo_gl_source_t *source = abstract_surface; + + _cairo_gl_operand_destroy (&source->operand); + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t cairo_gl_source_backend = { + CAIRO_SURFACE_TYPE_GL, + _cairo_gl_source_finish, + NULL, /* read-only wrapper */ +}; + +cairo_surface_t * +_cairo_gl_pattern_to_source (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_gl_source_t *source; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (pattern == NULL) + return _cairo_gl_white_source (); + + source = malloc (sizeof (*source)); + if (unlikely (source == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&source->base, + &cairo_gl_source_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + *src_x = *src_y = 0; + status = _cairo_gl_operand_init (&source->operand, pattern, + (cairo_gl_surface_t *)dst, + sample, extents, + FALSE); + if (unlikely (status)) { + cairo_surface_destroy (&source->base); + return _cairo_surface_create_in_error (status); + } + + return &source->base; +} + +cairo_surface_t * +_cairo_gl_white_source (void) +{ + cairo_gl_source_t *source; + + source = malloc (sizeof (*source)); + if (unlikely (source == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&source->base, + &cairo_gl_source_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + _cairo_gl_solid_operand_init (&source->operand, CAIRO_COLOR_WHITE); + + return &source->base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-spans-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-spans-compositor.c new file mode 100644 index 00000000000..4317ccd074a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-spans-compositor.c @@ -0,0 +1,553 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-spans-compositor-private.h" +#include "cairo-surface-backend-private.h" + +typedef struct _cairo_gl_span_renderer { + cairo_span_renderer_t base; + + cairo_gl_composite_t setup; + double opacity; + + cairo_gl_emit_span_t emit; + + int xmin, xmax; + int ymin, ymax; + + cairo_gl_context_t *ctx; +} cairo_gl_span_renderer_t; + +static cairo_status_t +_cairo_gl_bounded_opaque_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_gl_span_renderer_t *r = abstract_renderer; + cairo_gl_emit_span_t emit = r->emit; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + do { + if (spans[0].coverage) { + emit (r->ctx, + spans[0].x, y, + spans[1].x, y + height, + spans[0].coverage); + } + + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_bounded_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_gl_span_renderer_t *r = abstract_renderer; + cairo_gl_emit_span_t emit = r->emit; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + do { + if (spans[0].coverage) { + emit (r->ctx, + spans[0].x, y, + spans[1].x, y + height, + r->opacity * spans[0].coverage); + } + + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_unbounded_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_gl_span_renderer_t *r = abstract_renderer; + cairo_gl_emit_span_t emit = r->emit; + + if (y > r->ymin) { + emit (r->ctx, + r->xmin, r->ymin, + r->xmax, y, + 0); + } + + if (num_spans == 0) { + emit (r->ctx, + r->xmin, y, + r->xmax, y + height, + 0); + } else { + if (spans[0].x != r->xmin) { + emit (r->ctx, + r->xmin, y, + spans[0].x, y + height, + 0); + } + + do { + emit (r->ctx, + spans[0].x, y, + spans[1].x, y + height, + r->opacity * spans[0].coverage); + spans++; + } while (--num_spans > 1); + + if (spans[0].x != r->xmax) { + emit (r->ctx, + spans[0].x, y, + r->xmax, y + height, + 0); + } + } + + r->ymin = y + height; + return CAIRO_STATUS_SUCCESS; +} + +/* XXX */ +static cairo_status_t +_cairo_gl_clipped_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_gl_span_renderer_t *r = abstract_renderer; + cairo_gl_emit_span_t emit = r->emit; + + if (y > r->ymin) { + emit (r->ctx, + r->xmin, r->ymin, + r->xmax, y, + 0); + } + + if (num_spans == 0) { + emit (r->ctx, + r->xmin, y, + r->xmax, y + height, + 0); + } else { + if (spans[0].x != r->xmin) { + emit (r->ctx, + r->xmin, y, + spans[0].x, y + height, + 0); + } + + do { + emit (r->ctx, + spans[0].x, y, + spans[1].x, y + height, + r->opacity * spans[0].coverage); + spans++; + } while (--num_spans > 1); + + if (spans[0].x != r->xmax) { + emit (r->ctx, + spans[0].x, y, + r->xmax, y + height, + 0); + } + } + + r->ymin = y + height; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gl_finish_unbounded_spans (void *abstract_renderer) +{ + cairo_gl_span_renderer_t *r = abstract_renderer; + cairo_gl_emit_span_t emit = r->emit; + + if (r->ymax > r->ymin) { + emit (r->ctx, + r->xmin, r->ymin, + r->xmax, r->ymax, + 0); + } + + return _cairo_gl_context_release (r->ctx, CAIRO_STATUS_SUCCESS); +} + +static cairo_status_t +_cairo_gl_finish_bounded_spans (void *abstract_renderer) +{ + cairo_gl_span_renderer_t *r = abstract_renderer; + + return _cairo_gl_context_release (r->ctx, CAIRO_STATUS_SUCCESS); +} + +static void +emit_aligned_boxes (cairo_gl_context_t *ctx, + const cairo_boxes_t *boxes) +{ + const struct _cairo_boxes_chunk *chunk; + cairo_gl_emit_rect_t emit = _cairo_gl_context_choose_emit_rect (ctx); + int i; + + TRACE ((stderr, "%s: num_boxes=%d\n", __FUNCTION__, boxes->num_boxes)); + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + emit (ctx, x1, y1, x2, y2); + } + } +} + +static cairo_int_status_t +fill_boxes (void *_dst, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_solid_source (&setup, color); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + emit_aligned_boxes (ctx, boxes); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_int_status_t +draw_image_boxes (void *_dst, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy) +{ + cairo_gl_surface_t *dst = _dst; + struct _cairo_boxes_chunk *chunk; + int i; + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + int x = _cairo_fixed_integer_part (b->p1.x); + int y = _cairo_fixed_integer_part (b->p1.y); + int w = _cairo_fixed_integer_part (b->p2.x) - x; + int h = _cairo_fixed_integer_part (b->p2.y) - y; + cairo_status_t status; + + status = _cairo_gl_surface_draw_image (dst, image, + x + dx, y + dy, + w, h, + x, y, TRUE); + if (unlikely (status)) + return status; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t copy_boxes (void *_dst, + cairo_surface_t *_src, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents, + int dx, int dy) +{ + cairo_gl_surface_t *dst = _dst; + cairo_gl_surface_t *src = (cairo_gl_surface_t *)_src; + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (! _cairo_gl_surface_is_texture (src)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (src->base.device != dst->base.device) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_gl_composite_init (&setup, CAIRO_OPERATOR_SOURCE, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_source_operand (&setup, &src->operand); + _cairo_gl_operand_translate (&setup.src, -dx, -dy); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + emit_aligned_boxes (ctx, boxes); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_int_status_t +composite_boxes (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + cairo_gl_operand_t tmp_operand; + cairo_gl_operand_t *src_operand; + + TRACE ((stderr, "%s mask=(%d,%d), dst=(%d, %d)\n", __FUNCTION__, + mask_x, mask_y, dst_x, dst_y)); + + if (abstract_mask) { + if (op == CAIRO_OPERATOR_CLEAR) { + _cairo_gl_solid_operand_init (&tmp_operand, CAIRO_COLOR_WHITE); + src_operand = &tmp_operand; + op = CAIRO_OPERATOR_DEST_OUT; + } else if (op == CAIRO_OPERATOR_SOURCE) { + /* requires a LERP in the shader between dest and source */ + return CAIRO_INT_STATUS_UNSUPPORTED; + } else + src_operand = source_to_operand (abstract_src); + } else + src_operand = source_to_operand (abstract_src); + + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_source_operand (&setup, + src_operand); + _cairo_gl_operand_translate (&setup.src, -src_x, -src_y); + + _cairo_gl_composite_set_mask_operand (&setup, + source_to_operand (abstract_mask)); + _cairo_gl_operand_translate (&setup.mask, -mask_x, -mask_y); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + emit_aligned_boxes (ctx, boxes); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + if (src_operand == &tmp_operand) + _cairo_gl_operand_destroy (&tmp_operand); + return status; +} + +static cairo_int_status_t +_cairo_gl_span_renderer_init (cairo_abstract_span_renderer_t *_r, + const cairo_composite_rectangles_t *composite, + cairo_antialias_t antialias, + cairo_bool_t needs_clip) +{ + cairo_gl_span_renderer_t *r = (cairo_gl_span_renderer_t *)_r; + const cairo_pattern_t *source = &composite->source_pattern.base; + cairo_operator_t op = composite->op; + cairo_int_status_t status; + + if (op == CAIRO_OPERATOR_SOURCE) { + if (! _cairo_pattern_is_opaque (&composite->source_pattern.base, + &composite->source_sample_area)) + return CAIRO_INT_STATUS_UNSUPPORTED; + op = CAIRO_OPERATOR_OVER; + } + + /* XXX earlier! */ + if (op == CAIRO_OPERATOR_CLEAR) { + source = &_cairo_pattern_white.base; + op = CAIRO_OPERATOR_DEST_OUT; + } else if (composite->surface->is_clear && + (op == CAIRO_OPERATOR_SOURCE || + op == CAIRO_OPERATOR_OVER || + op == CAIRO_OPERATOR_ADD)) { + op = CAIRO_OPERATOR_SOURCE; + } else if (op == CAIRO_OPERATOR_SOURCE) { + /* no lerp equivalent without some major PITA */ + return CAIRO_INT_STATUS_UNSUPPORTED; + } else if (! _cairo_gl_operator_is_supported (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_gl_composite_init (&r->setup, + op, (cairo_gl_surface_t *)composite->surface, + FALSE); + if (unlikely (status)) + goto FAIL; + + status = _cairo_gl_composite_set_source (&r->setup, source, + &composite->source_sample_area, + &composite->unbounded, + TRUE); + if (unlikely (status)) + goto FAIL; + + r->opacity = 1.0; + if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { + r->opacity = composite->mask_pattern.solid.color.alpha; + } else { + status = _cairo_gl_composite_set_mask (&r->setup, + &composite->mask_pattern.base, + &composite->mask_sample_area, + &composite->unbounded, + TRUE); + if (unlikely (status)) + goto FAIL; + } + + _cairo_gl_composite_set_spans (&r->setup); + + status = _cairo_gl_composite_begin (&r->setup, &r->ctx); + if (unlikely (status)) + goto FAIL; + + r->emit = _cairo_gl_context_choose_emit_span (r->ctx); + if (composite->is_bounded) { + if (r->opacity == 1.) + r->base.render_rows = _cairo_gl_bounded_opaque_spans; + else + r->base.render_rows = _cairo_gl_bounded_spans; + r->base.finish = _cairo_gl_finish_bounded_spans; + } else { + if (needs_clip) + r->base.render_rows = _cairo_gl_clipped_spans; + else + r->base.render_rows = _cairo_gl_unbounded_spans; + r->base.finish = _cairo_gl_finish_unbounded_spans; + r->xmin = composite->unbounded.x; + r->xmax = composite->unbounded.x + composite->unbounded.width; + r->ymin = composite->unbounded.y; + r->ymax = composite->unbounded.y + composite->unbounded.height; + } + + return CAIRO_STATUS_SUCCESS; + +FAIL: + return status; +} + +static void +_cairo_gl_span_renderer_fini (cairo_abstract_span_renderer_t *_r, + cairo_int_status_t status) +{ + cairo_gl_span_renderer_t *r = (cairo_gl_span_renderer_t *) _r; + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + return; + + if (status == CAIRO_INT_STATUS_SUCCESS) + r->base.finish (r); + + _cairo_gl_composite_fini (&r->setup); +} + +const cairo_compositor_t * +_cairo_gl_span_compositor_get (void) +{ + static cairo_spans_compositor_t spans; + static cairo_compositor_t shape; + + if (spans.base.delegate == NULL) { + /* The fallback to traps here is essentially just for glyphs... */ + _cairo_shape_mask_compositor_init (&shape, + _cairo_gl_traps_compositor_get()); + shape.glyphs = NULL; + + _cairo_spans_compositor_init (&spans, &shape); + spans.fill_boxes = fill_boxes; + spans.draw_image_boxes = draw_image_boxes; + spans.copy_boxes = copy_boxes; + //spans.check_composite_boxes = check_composite_boxes; + spans.pattern_to_surface = _cairo_gl_pattern_to_source; + spans.composite_boxes = composite_boxes; + //spans.check_span_renderer = check_span_renderer; + spans.renderer_init = _cairo_gl_span_renderer_init; + spans.renderer_fini = _cairo_gl_span_renderer_fini; + } + + return &spans.base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-surface.c new file mode 100644 index 00000000000..cfccf4dfda5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-surface.c @@ -0,0 +1,1459 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-surface-backend-private.h" + +static const cairo_surface_backend_t _cairo_gl_surface_backend; + +static cairo_status_t +_cairo_gl_surface_flush (void *abstract_surface, unsigned flags); + +static cairo_bool_t _cairo_surface_is_gl (cairo_surface_t *surface) +{ + return surface->backend == &_cairo_gl_surface_backend; +} + +static cairo_bool_t +_cairo_gl_get_image_format_and_type_gles2 (pixman_format_code_t pixman_format, + GLenum *internal_format, GLenum *format, + GLenum *type, cairo_bool_t *has_alpha, + cairo_bool_t *needs_swap) +{ + cairo_bool_t is_little_endian = _cairo_is_little_endian (); + + *has_alpha = TRUE; + + switch ((int) pixman_format) { + case PIXMAN_a8r8g8b8: + *internal_format = GL_BGRA; + *format = GL_BGRA; + *type = GL_UNSIGNED_BYTE; + *needs_swap = !is_little_endian; + return TRUE; + + case PIXMAN_x8r8g8b8: + *internal_format = GL_BGRA; + *format = GL_BGRA; + *type = GL_UNSIGNED_BYTE; + *has_alpha = FALSE; + *needs_swap = !is_little_endian; + return TRUE; + + case PIXMAN_a8b8g8r8: + *internal_format = GL_RGBA; + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + *needs_swap = !is_little_endian; + return TRUE; + + case PIXMAN_x8b8g8r8: + *internal_format = GL_RGBA; + *format = GL_RGBA; + *type = GL_UNSIGNED_BYTE; + *has_alpha = FALSE; + *needs_swap = !is_little_endian; + return TRUE; + + case PIXMAN_b8g8r8a8: + *internal_format = GL_BGRA; + *format = GL_BGRA; + *type = GL_UNSIGNED_BYTE; + *needs_swap = is_little_endian; + return TRUE; + + case PIXMAN_b8g8r8x8: + *internal_format = GL_BGRA; + *format = GL_BGRA; + *type = GL_UNSIGNED_BYTE; + *has_alpha = FALSE; + *needs_swap = is_little_endian; + return TRUE; + + case PIXMAN_r8g8b8: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + *needs_swap = is_little_endian; + return TRUE; + + case PIXMAN_b8g8r8: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + *needs_swap = !is_little_endian; + return TRUE; + + case PIXMAN_r5g6b5: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_SHORT_5_6_5; + *needs_swap = FALSE; + return TRUE; + + case PIXMAN_b5g6r5: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_SHORT_5_6_5; + *needs_swap = TRUE; + return TRUE; + + case PIXMAN_a1b5g5r5: + *internal_format = GL_RGBA; + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_5_5_5_1; + *needs_swap = TRUE; + return TRUE; + + case PIXMAN_x1b5g5r5: + *internal_format = GL_RGBA; + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_5_5_5_1; + *has_alpha = FALSE; + *needs_swap = TRUE; + return TRUE; + + case PIXMAN_a8: + *internal_format = GL_ALPHA; + *format = GL_ALPHA; + *type = GL_UNSIGNED_BYTE; + *needs_swap = FALSE; + return TRUE; + + default: + return FALSE; + } +} + +static cairo_bool_t +_cairo_gl_get_image_format_and_type_gl (pixman_format_code_t pixman_format, + GLenum *internal_format, GLenum *format, + GLenum *type, cairo_bool_t *has_alpha, + cairo_bool_t *needs_swap) +{ + *has_alpha = TRUE; + *needs_swap = FALSE; + + switch (pixman_format) { + case PIXMAN_a8r8g8b8: + *internal_format = GL_RGBA; + *format = GL_BGRA; + *type = GL_UNSIGNED_INT_8_8_8_8_REV; + return TRUE; + case PIXMAN_x8r8g8b8: + *internal_format = GL_RGB; + *format = GL_BGRA; + *type = GL_UNSIGNED_INT_8_8_8_8_REV; + *has_alpha = FALSE; + return TRUE; + case PIXMAN_a8b8g8r8: + *internal_format = GL_RGBA; + *format = GL_RGBA; + *type = GL_UNSIGNED_INT_8_8_8_8_REV; + return TRUE; + case PIXMAN_x8b8g8r8: + *internal_format = GL_RGB; + *format = GL_RGBA; + *type = GL_UNSIGNED_INT_8_8_8_8_REV; + *has_alpha = FALSE; + return TRUE; + case PIXMAN_b8g8r8a8: + *internal_format = GL_RGBA; + *format = GL_BGRA; + *type = GL_UNSIGNED_INT_8_8_8_8; + return TRUE; + case PIXMAN_b8g8r8x8: + *internal_format = GL_RGB; + *format = GL_BGRA; + *type = GL_UNSIGNED_INT_8_8_8_8; + *has_alpha = FALSE; + return TRUE; + case PIXMAN_r8g8b8: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_BYTE; + return TRUE; + case PIXMAN_b8g8r8: + *internal_format = GL_RGB; + *format = GL_BGR; + *type = GL_UNSIGNED_BYTE; + return TRUE; + case PIXMAN_r5g6b5: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_SHORT_5_6_5; + return TRUE; + case PIXMAN_b5g6r5: + *internal_format = GL_RGB; + *format = GL_RGB; + *type = GL_UNSIGNED_SHORT_5_6_5_REV; + return TRUE; + case PIXMAN_a1r5g5b5: + *internal_format = GL_RGBA; + *format = GL_BGRA; + *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + return TRUE; + case PIXMAN_x1r5g5b5: + *internal_format = GL_RGB; + *format = GL_BGRA; + *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + *has_alpha = FALSE; + return TRUE; + case PIXMAN_a1b5g5r5: + *internal_format = GL_RGBA; + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + return TRUE; + case PIXMAN_x1b5g5r5: + *internal_format = GL_RGB; + *format = GL_RGBA; + *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; + *has_alpha = FALSE; + return TRUE; + case PIXMAN_a8: + *internal_format = GL_ALPHA; + *format = GL_ALPHA; + *type = GL_UNSIGNED_BYTE; + return TRUE; + +#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,27,2) + case PIXMAN_a8r8g8b8_sRGB: +#endif + case PIXMAN_a2b10g10r10: + case PIXMAN_x2b10g10r10: + case PIXMAN_a4r4g4b4: + case PIXMAN_x4r4g4b4: + case PIXMAN_a4b4g4r4: + case PIXMAN_x4b4g4r4: + case PIXMAN_r3g3b2: + case PIXMAN_b2g3r3: + case PIXMAN_a2r2g2b2: + case PIXMAN_a2b2g2r2: + case PIXMAN_c8: + case PIXMAN_x4a4: + /* case PIXMAN_x4c4: */ + case PIXMAN_x4g4: + case PIXMAN_a4: + case PIXMAN_r1g2b1: + case PIXMAN_b1g2r1: + case PIXMAN_a1r1g1b1: + case PIXMAN_a1b1g1r1: + case PIXMAN_c4: + case PIXMAN_g4: + case PIXMAN_a1: + case PIXMAN_g1: + case PIXMAN_yuy2: + case PIXMAN_yv12: + case PIXMAN_x2r10g10b10: + case PIXMAN_a2r10g10b10: + case PIXMAN_r8g8b8x8: + case PIXMAN_r8g8b8a8: + case PIXMAN_x14r6g6b6: + default: + return FALSE; + } +} + +/* + * Extracts pixel data from an image surface. + */ +static cairo_status_t +_cairo_gl_surface_extract_image_data (cairo_image_surface_t *image, + int x, int y, + int width, int height, + void **output) +{ + int cpp = PIXMAN_FORMAT_BPP (image->pixman_format) / 8; + char *data = _cairo_malloc_ab (width * height, cpp); + char *dst = data; + unsigned char *src = image->data + y * image->stride + x * cpp; + int i; + + if (unlikely (data == NULL)) + return CAIRO_STATUS_NO_MEMORY; + + for (i = 0; i < height; i++) { + memcpy (dst, src, width * cpp); + src += image->stride; + dst += width * cpp; + } + + *output = data; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_bool_t +_cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor, + pixman_format_code_t pixman_format, + GLenum *internal_format, GLenum *format, + GLenum *type, cairo_bool_t *has_alpha, + cairo_bool_t *needs_swap) +{ + if (flavor == CAIRO_GL_FLAVOR_DESKTOP) + return _cairo_gl_get_image_format_and_type_gl (pixman_format, + internal_format, format, + type, has_alpha, + needs_swap); + else + return _cairo_gl_get_image_format_and_type_gles2 (pixman_format, + internal_format, format, + type, has_alpha, + needs_swap); + +} + +cairo_bool_t +_cairo_gl_operator_is_supported (cairo_operator_t op) +{ + return op < CAIRO_OPERATOR_SATURATE; +} + +static void +_cairo_gl_surface_embedded_operand_init (cairo_gl_surface_t *surface) +{ + cairo_gl_operand_t *operand = &surface->operand; + cairo_surface_attributes_t *attributes = &operand->texture.attributes; + + memset (operand, 0, sizeof (cairo_gl_operand_t)); + + operand->type = CAIRO_GL_OPERAND_TEXTURE; + operand->texture.surface = surface; + operand->texture.tex = surface->tex; + + if (_cairo_gl_device_requires_power_of_two_textures (surface->base.device)) { + cairo_matrix_init_identity (&attributes->matrix); + } else { + cairo_matrix_init_scale (&attributes->matrix, + 1.0 / surface->width, + 1.0 / surface->height); + } + + attributes->extend = CAIRO_EXTEND_NONE; + attributes->filter = CAIRO_FILTER_NEAREST; +} + +void +_cairo_gl_surface_init (cairo_device_t *device, + cairo_gl_surface_t *surface, + cairo_content_t content, + int width, int height) +{ + assert (width > 0 && height > 0); + + _cairo_surface_init (&surface->base, + &_cairo_gl_surface_backend, + device, + content); + + surface->width = width; + surface->height = height; + surface->needs_update = FALSE; + + _cairo_gl_surface_embedded_operand_init (surface); +} + +static cairo_bool_t +_cairo_gl_surface_size_valid_for_context (cairo_gl_context_t *ctx, + int width, int height) +{ + return width > 0 && height > 0 && + width <= ctx->max_framebuffer_size && + height <= ctx->max_framebuffer_size; +} + +static cairo_bool_t +_cairo_gl_surface_size_valid (cairo_gl_surface_t *surface, + int width, int height) +{ + cairo_gl_context_t *ctx = (cairo_gl_context_t *)surface->base.device; + return _cairo_gl_surface_size_valid_for_context (ctx, width, height); +} + +static cairo_surface_t * +_cairo_gl_surface_create_scratch_for_texture (cairo_gl_context_t *ctx, + cairo_content_t content, + GLuint tex, + int width, + int height) +{ + cairo_gl_surface_t *surface; + + surface = calloc (1, sizeof (cairo_gl_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface->tex = tex; + _cairo_gl_surface_init (&ctx->base, surface, content, width, height); + + surface->supports_msaa = ctx->supports_msaa; + surface->supports_stencil = TRUE; + + /* Create the texture used to store the surface's data. */ + _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); + glBindTexture (ctx->tex_target, surface->tex); + glTexParameteri (ctx->tex_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (ctx->tex_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + return &surface->base; +} + +static cairo_surface_t * +_create_scratch_internal (cairo_gl_context_t *ctx, + cairo_content_t content, + int width, + int height, + cairo_bool_t for_caching) +{ + cairo_gl_surface_t *surface; + GLenum format; + GLuint tex; + + glGenTextures (1, &tex); + surface = (cairo_gl_surface_t *) + _cairo_gl_surface_create_scratch_for_texture (ctx, content, + tex, width, height); + if (unlikely (surface->base.status)) + return &surface->base; + + surface->owns_tex = TRUE; + + /* adjust the texture size after setting our real extents */ + if (width < 1) + width = 1; + if (height < 1) + height = 1; + + switch (content) { + default: + ASSERT_NOT_REACHED; + case CAIRO_CONTENT_COLOR_ALPHA: + format = GL_RGBA; + break; + case CAIRO_CONTENT_ALPHA: + /* When using GL_ALPHA, compositing doesn't work properly, but for + * caching surfaces, we are just uploading pixel data, so it isn't + * an issue. */ + if (for_caching) + format = GL_ALPHA; + else + format = GL_RGBA; + break; + case CAIRO_CONTENT_COLOR: + /* GL_RGB is almost what we want here -- sampling 1 alpha when + * texturing, using 1 as destination alpha factor in blending, + * etc. However, when filtering with GL_CLAMP_TO_BORDER, the + * alpha channel of the border color will also be clamped to + * 1, when we actually want the border color we explicitly + * specified. So, we have to store RGBA, and fill the alpha + * channel with 1 when blending. + */ + format = GL_RGBA; + break; + } + + glTexImage2D (ctx->tex_target, 0, format, width, height, 0, + format, GL_UNSIGNED_BYTE, NULL); + + return &surface->base; +} + +cairo_surface_t * +_cairo_gl_surface_create_scratch (cairo_gl_context_t *ctx, + cairo_content_t content, + int width, + int height) +{ + return _create_scratch_internal (ctx, content, width, height, FALSE); +} + +cairo_surface_t * +_cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx, + cairo_content_t content, + int width, + int height) +{ + return _create_scratch_internal (ctx, content, width, height, TRUE); +} + +static cairo_status_t +_cairo_gl_surface_clear (cairo_gl_surface_t *surface, + const cairo_color_t *color) +{ + cairo_gl_context_t *ctx; + cairo_status_t status; + double r, g, b, a; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return status; + + _cairo_gl_context_set_destination (ctx, surface, surface->msaa_active); + if (surface->base.content & CAIRO_CONTENT_COLOR) { + r = color->red * color->alpha; + g = color->green * color->alpha; + b = color->blue * color->alpha; + } else { + r = g = b = 0; + } + if (surface->base.content & CAIRO_CONTENT_ALPHA) { + a = color->alpha; + } else { + a = 1.0; + } + + glDisable (GL_SCISSOR_TEST); + glClearColor (r, g, b, a); + glClear (GL_COLOR_BUFFER_BIT); + + if (a == 0) + surface->base.is_clear = TRUE; + + return _cairo_gl_context_release (ctx, status); +} + +static cairo_surface_t * +_cairo_gl_surface_create_and_clear_scratch (cairo_gl_context_t *ctx, + cairo_content_t content, + int width, + int height) +{ + cairo_gl_surface_t *surface; + cairo_int_status_t status; + + surface = (cairo_gl_surface_t *) + _cairo_gl_surface_create_scratch (ctx, content, width, height); + if (unlikely (surface->base.status)) + return &surface->base; + + /* Cairo surfaces start out initialized to transparent (black) */ + status = _cairo_gl_surface_clear (surface, CAIRO_COLOR_TRANSPARENT); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return _cairo_surface_create_in_error (status); + } + + return &surface->base; +} + +cairo_surface_t * +cairo_gl_surface_create (cairo_device_t *abstract_device, + cairo_content_t content, + int width, + int height) +{ + cairo_gl_context_t *ctx; + cairo_gl_surface_t *surface; + cairo_status_t status; + + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); + + if (abstract_device == NULL) + return _cairo_image_surface_create_with_content (content, width, height); + + if (abstract_device->status) + return _cairo_surface_create_in_error (abstract_device->status); + + if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_GL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + + status = _cairo_gl_context_acquire (abstract_device, &ctx); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (! _cairo_gl_surface_size_valid_for_context (ctx, width, height)) { + status = _cairo_gl_context_release (ctx, status); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + } + + surface = (cairo_gl_surface_t *) + _cairo_gl_surface_create_and_clear_scratch (ctx, content, width, height); + if (unlikely (surface->base.status)) { + status = _cairo_gl_context_release (ctx, surface->base.status); + cairo_surface_destroy (&surface->base); + return _cairo_surface_create_in_error (status); + } + + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return _cairo_surface_create_in_error (status); + } + + return &surface->base; +} +slim_hidden_def (cairo_gl_surface_create); + +/** + * cairo_gl_surface_create_for_texture: + * @content: type of content in the surface + * @tex: name of texture to use for storage of surface pixels + * @width: width of the surface, in pixels + * @height: height of the surface, in pixels + * + * Creates a GL surface for the specified texture with the specified + * content and dimensions. The texture must be kept around until the + * #cairo_surface_t is destroyed or cairo_surface_finish() is called + * on the surface. The initial contents of @tex will be used as the + * initial image contents; you must explicitly clear the buffer, + * using, for example, cairo_rectangle() and cairo_fill() if you want + * it cleared. The format of @tex should be compatible with @content, + * in the sense that it must have the color components required by + * @content. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: TBD + **/ +cairo_surface_t * +cairo_gl_surface_create_for_texture (cairo_device_t *abstract_device, + cairo_content_t content, + unsigned int tex, + int width, + int height) +{ + cairo_gl_context_t *ctx; + cairo_gl_surface_t *surface; + cairo_status_t status; + + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); + + if (abstract_device == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); + + if (abstract_device->status) + return _cairo_surface_create_in_error (abstract_device->status); + + if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_GL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH)); + + status = _cairo_gl_context_acquire (abstract_device, &ctx); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (! _cairo_gl_surface_size_valid_for_context (ctx, width, height)) { + status = _cairo_gl_context_release (ctx, status); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + } + + surface = (cairo_gl_surface_t *) + _cairo_gl_surface_create_scratch_for_texture (ctx, content, + tex, width, height); + status = _cairo_gl_context_release (ctx, status); + + return &surface->base; +} +slim_hidden_def (cairo_gl_surface_create_for_texture); + + +void +cairo_gl_surface_set_size (cairo_surface_t *abstract_surface, + int width, + int height) +{ + cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (! _cairo_surface_is_gl (abstract_surface) || + _cairo_gl_surface_is_texture (surface)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + if (surface->width != width || surface->height != height) { + surface->needs_update = TRUE; + surface->width = width; + surface->height = height; + } +} + +int +cairo_gl_surface_get_width (cairo_surface_t *abstract_surface) +{ + cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; + + if (! _cairo_surface_is_gl (abstract_surface)) + return 0; + + return surface->width; +} + +int +cairo_gl_surface_get_height (cairo_surface_t *abstract_surface) +{ + cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; + + if (! _cairo_surface_is_gl (abstract_surface)) + return 0; + + return surface->height; +} + +void +cairo_gl_surface_swapbuffers (cairo_surface_t *abstract_surface) +{ + cairo_gl_surface_t *surface = (cairo_gl_surface_t *) abstract_surface; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (! _cairo_surface_is_gl (abstract_surface)) { + _cairo_surface_set_error (abstract_surface, + CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return; + } + + if (! _cairo_gl_surface_is_texture (surface)) { + cairo_gl_context_t *ctx; + cairo_status_t status; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return; + + /* For swapping on EGL, at least, we need a valid context/target. */ + _cairo_gl_context_set_destination (ctx, surface, FALSE); + /* And in any case we should flush any pending operations. */ + _cairo_gl_composite_flush (ctx); + + ctx->swap_buffers (ctx, surface); + + status = _cairo_gl_context_release (ctx, status); + if (status) + status = _cairo_surface_set_error (abstract_surface, status); + } +} + +static cairo_surface_t * +_cairo_gl_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_surface_t *surface = abstract_surface; + cairo_gl_context_t *ctx; + cairo_status_t status; + + if (! _cairo_gl_surface_size_valid (abstract_surface, width, height)) + return _cairo_image_surface_create_with_content (content, width, height); + + status = _cairo_gl_context_acquire (surface->device, &ctx); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + surface = _cairo_gl_surface_create_and_clear_scratch (ctx, content, width, height); + + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) { + cairo_surface_destroy (surface); + return _cairo_surface_create_in_error (status); + } + + return surface; +} + +static cairo_int_status_t +_cairo_gl_surface_fill_alpha_channel (cairo_gl_surface_t *dst, + cairo_gl_context_t *ctx, + int x, int y, + int width, int height) +{ + cairo_gl_composite_t setup; + cairo_status_t status; + + _cairo_gl_composite_flush (ctx); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); + + status = _cairo_gl_composite_init (&setup, CAIRO_OPERATOR_SOURCE, + dst, FALSE); + if (unlikely (status)) + goto CLEANUP; + + _cairo_gl_composite_set_solid_source (&setup, CAIRO_COLOR_BLACK); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto CLEANUP; + + _cairo_gl_context_emit_rect (ctx, x, y, x + width, y + height); + + status = _cairo_gl_context_release (ctx, status); + + CLEANUP: + _cairo_gl_composite_fini (&setup); + + _cairo_gl_composite_flush (ctx); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + return status; +} + +cairo_status_t +_cairo_gl_surface_draw_image (cairo_gl_surface_t *dst, + cairo_image_surface_t *src, + int src_x, int src_y, + int width, int height, + int dst_x, int dst_y, + cairo_bool_t force_flush) +{ + GLenum internal_format, format, type; + cairo_bool_t has_alpha, needs_swap; + cairo_image_surface_t *clone = NULL; + cairo_gl_context_t *ctx; + int cpp; + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + + status = _cairo_gl_context_acquire (dst->base.device, &ctx); + if (unlikely (status)) + return status; + + if (! _cairo_gl_get_image_format_and_type (ctx->gl_flavor, + src->pixman_format, + &internal_format, + &format, + &type, + &has_alpha, + &needs_swap)) + { + cairo_bool_t is_supported; + + clone = _cairo_image_surface_coerce (src); + if (unlikely (status = clone->base.status)) + goto FAIL; + + is_supported = + _cairo_gl_get_image_format_and_type (ctx->gl_flavor, + clone->pixman_format, + &internal_format, + &format, + &type, + &has_alpha, + &needs_swap); + assert (is_supported); + assert (!needs_swap); + src = clone; + } + + cpp = PIXMAN_FORMAT_BPP (src->pixman_format) / 8; + + if (force_flush) { + status = _cairo_gl_surface_flush (&dst->base, 0); + if (unlikely (status)) + goto FAIL; + } + + if (_cairo_gl_surface_is_texture (dst)) { + void *data_start = src->data + src_y * src->stride + src_x * cpp; + void *data_start_gles2 = NULL; + + /* + * Due to GL_UNPACK_ROW_LENGTH missing in GLES2 we have to extract the + * image data ourselves in some cases. In particular, we must extract + * the pixels if: + * a. we don't want full-length lines or + * b. the row stride cannot be handled by GL itself using a 4 byte + * alignment constraint + */ + if (src->stride < 0 || + (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + (src->width * cpp < src->stride - 3 || + width != src->width))) + { + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + status = _cairo_gl_surface_extract_image_data (src, src_x, src_y, + width, height, + &data_start_gles2); + if (unlikely (status)) + goto FAIL; + + data_start = data_start_gles2; + } + else + { + glPixelStorei (GL_UNPACK_ALIGNMENT, 4); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + glPixelStorei (GL_UNPACK_ROW_LENGTH, src->stride / cpp); + } + + _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); + glBindTexture (ctx->tex_target, dst->tex); + glTexParameteri (ctx->tex_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (ctx->tex_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexSubImage2D (ctx->tex_target, 0, + dst_x, dst_y, width, height, + format, type, data_start); + + free (data_start_gles2); + + /* If we just treated some rgb-only data as rgba, then we have to + * go back and fix up the alpha channel where we filled in this + * texture data. + */ + if (!has_alpha) { + _cairo_gl_surface_fill_alpha_channel (dst, ctx, + dst_x, dst_y, + width, height); + } + } else { + cairo_surface_t *tmp; + + tmp = _cairo_gl_surface_create_scratch (ctx, + dst->base.content, + width, height); + if (unlikely (tmp->status)) + goto FAIL; + + status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *) tmp, + src, + src_x, src_y, + width, height, + 0, 0, force_flush); + if (status == CAIRO_INT_STATUS_SUCCESS) { + cairo_surface_pattern_t tmp_pattern; + cairo_rectangle_int_t r; + cairo_clip_t *clip; + + _cairo_pattern_init_for_surface (&tmp_pattern, tmp); + cairo_matrix_init_translate (&tmp_pattern.base.matrix, + -dst_x, -dst_y); + tmp_pattern.base.filter = CAIRO_FILTER_NEAREST; + tmp_pattern.base.extend = CAIRO_EXTEND_NONE; + + r.x = dst_x; + r.y = dst_y; + r.width = width; + r.height = height; + clip = _cairo_clip_intersect_rectangle (NULL, &r); + status = _cairo_surface_paint (&dst->base, + CAIRO_OPERATOR_SOURCE, + &tmp_pattern.base, + clip); + _cairo_clip_destroy (clip); + _cairo_pattern_fini (&tmp_pattern.base); + } + + cairo_surface_destroy (tmp); + } + +FAIL: + status = _cairo_gl_context_release (ctx, status); + + if (clone) + cairo_surface_destroy (&clone->base); + + return status; +} + +static int _cairo_gl_surface_flavor (cairo_gl_surface_t *surface) +{ + cairo_gl_context_t *ctx = (cairo_gl_context_t *)surface->base.device; + return ctx->gl_flavor; +} + +static cairo_status_t +_cairo_gl_surface_finish (void *abstract_surface) +{ + cairo_gl_surface_t *surface = abstract_surface; + cairo_status_t status; + cairo_gl_context_t *ctx; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return status; + + if (ctx->operands[CAIRO_GL_TEX_SOURCE].type == CAIRO_GL_OPERAND_TEXTURE && + ctx->operands[CAIRO_GL_TEX_SOURCE].texture.surface == surface) + _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_SOURCE); + if (ctx->operands[CAIRO_GL_TEX_MASK].type == CAIRO_GL_OPERAND_TEXTURE && + ctx->operands[CAIRO_GL_TEX_MASK].texture.surface == surface) + _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_MASK); + if (ctx->current_target == surface) + ctx->current_target = NULL; + + if (surface->fb) + ctx->dispatch.DeleteFramebuffers (1, &surface->fb); + if (surface->depth_stencil) + ctx->dispatch.DeleteRenderbuffers (1, &surface->depth_stencil); + if (surface->owns_tex) + glDeleteTextures (1, &surface->tex); + + if (surface->msaa_depth_stencil) + ctx->dispatch.DeleteRenderbuffers (1, &surface->msaa_depth_stencil); + +#if CAIRO_HAS_GL_SURFACE + if (surface->msaa_fb) + ctx->dispatch.DeleteFramebuffers (1, &surface->msaa_fb); + if (surface->msaa_rb) + ctx->dispatch.DeleteRenderbuffers (1, &surface->msaa_rb); +#endif + + _cairo_clip_destroy (surface->clip_on_stencil_buffer); + + return _cairo_gl_context_release (ctx, status); +} + +static cairo_image_surface_t * +_cairo_gl_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_gl_surface_t *surface = abstract_surface; + cairo_image_surface_t *image; + cairo_gl_context_t *ctx; + GLenum format, type; + pixman_format_code_t pixman_format; + unsigned int cpp; + cairo_bool_t flipped, mesa_invert; + cairo_status_t status; + int y; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) { + return _cairo_image_surface_create_in_error (status); + } + + /* Want to use a switch statement here but the compiler gets whiny. */ + if (surface->base.content == CAIRO_CONTENT_COLOR_ALPHA) { + format = GL_BGRA; + pixman_format = PIXMAN_a8r8g8b8; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + cpp = 4; + } else if (surface->base.content == CAIRO_CONTENT_COLOR) { + format = GL_BGRA; + pixman_format = PIXMAN_x8r8g8b8; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + cpp = 4; + } else if (surface->base.content == CAIRO_CONTENT_ALPHA) { + format = GL_ALPHA; + pixman_format = PIXMAN_a8; + type = GL_UNSIGNED_BYTE; + cpp = 1; + } else { + ASSERT_NOT_REACHED; + return NULL; + } + + if (_cairo_gl_surface_flavor (surface) == CAIRO_GL_FLAVOR_ES) { + /* If only RGBA is supported, we must download data in a compatible + * format. This means that pixman will convert the data on the CPU when + * interacting with other image surfaces. For ALPHA, GLES2 does not + * support GL_PACK_ROW_LENGTH anyway, and this makes sure that the + * pixman image that is created has row_stride = row_width * bpp. */ + if (surface->base.content == CAIRO_CONTENT_ALPHA || !ctx->can_read_bgra) { + cairo_bool_t little_endian = _cairo_is_little_endian (); + format = GL_RGBA; + + if (surface->base.content == CAIRO_CONTENT_COLOR) { + pixman_format = little_endian ? + PIXMAN_x8b8g8r8 : PIXMAN_r8g8b8x8; + } else { + pixman_format = little_endian ? + PIXMAN_a8b8g8r8 : PIXMAN_r8g8b8a8; + } + } + + /* GLES2 only supports GL_UNSIGNED_BYTE. */ + type = GL_UNSIGNED_BYTE; + cpp = 4; + } + + image = (cairo_image_surface_t*) + _cairo_image_surface_create_with_pixman_format (NULL, + pixman_format, + extents->width, + extents->height, + -1); + if (unlikely (image->base.status)) { + status = _cairo_gl_context_release (ctx, status); + return image; + } + + cairo_surface_set_device_offset (&image->base, -extents->x, -extents->y); + + /* If the original surface has not been modified or + * is clear, we can avoid downloading data. */ + if (surface->base.is_clear || surface->base.serial == 0) { + status = _cairo_gl_context_release (ctx, status); + return image; + } + + /* This is inefficient, as we'd rather just read the thing without making + * it the destination. But then, this is the fallback path, so let's not + * fall back instead. + */ + _cairo_gl_composite_flush (ctx); + _cairo_gl_context_set_destination (ctx, surface, FALSE); + + flipped = ! _cairo_gl_surface_is_texture (surface); + mesa_invert = flipped && ctx->has_mesa_pack_invert; + + glPixelStorei (GL_PACK_ALIGNMENT, 4); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + glPixelStorei (GL_PACK_ROW_LENGTH, image->stride / cpp); + if (mesa_invert) + glPixelStorei (GL_PACK_INVERT_MESA, 1); + + y = extents->y; + if (flipped) + y = surface->height - extents->y - extents->height; + + glReadPixels (extents->x, y, + extents->width, extents->height, + format, type, image->data); + if (mesa_invert) + glPixelStorei (GL_PACK_INVERT_MESA, 0); + + status = _cairo_gl_context_release (ctx, status); + if (unlikely (status)) { + cairo_surface_destroy (&image->base); + return _cairo_image_surface_create_in_error (status); + } + + /* We must invert the image manualy if we lack GL_MESA_pack_invert */ + if (flipped && ! mesa_invert) { + uint8_t stack[1024], *row = stack; + uint8_t *top = image->data; + uint8_t *bot = image->data + (image->height-1)*image->stride; + + if (image->stride > (int)sizeof(stack)) { + row = malloc (image->stride); + if (unlikely (row == NULL)) { + cairo_surface_destroy (&image->base); + return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + } + + while (top < bot) { + memcpy (row, top, image->stride); + memcpy (top, bot, image->stride); + memcpy (bot, row, image->stride); + top += image->stride; + bot -= image->stride; + } + + if (row != stack) + free(row); + } + + image->base.is_clear = FALSE; + return image; +} + +static cairo_surface_t * +_cairo_gl_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_gl_surface_t *surface = abstract_surface; + + if (extents) { + extents->x = extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + } + + return &surface->base; +} + +static cairo_status_t +_cairo_gl_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_gl_surface_t *surface = abstract_surface; + cairo_rectangle_int_t extents; + + *image_extra = NULL; + + extents.x = extents.y = 0; + extents.width = surface->width; + extents.height = surface->height; + + *image_out = (cairo_image_surface_t *) + _cairo_gl_surface_map_to_image (surface, &extents); + return (*image_out)->base.status; +} + +static void +_cairo_gl_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); +} + +static cairo_int_status_t +_cairo_gl_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_int_status_t status; + + status = _cairo_gl_surface_draw_image (abstract_surface, image, + 0, 0, + image->width, image->height, + image->base.device_transform_inverse.x0, + image->base.device_transform_inverse.y0, + TRUE); + + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return status; +} + +static cairo_bool_t +_cairo_gl_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_gl_surface_t *surface = abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + rectangle->width = surface->width; + rectangle->height = surface->height; + + return TRUE; +} + +static cairo_status_t +_cairo_gl_surface_flush (void *abstract_surface, unsigned flags) +{ + cairo_gl_surface_t *surface = abstract_surface; + cairo_status_t status; + cairo_gl_context_t *ctx; + + if (flags) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return status; + + if ((ctx->operands[CAIRO_GL_TEX_SOURCE].type == CAIRO_GL_OPERAND_TEXTURE && + ctx->operands[CAIRO_GL_TEX_SOURCE].texture.surface == surface) || + (ctx->operands[CAIRO_GL_TEX_MASK].type == CAIRO_GL_OPERAND_TEXTURE && + ctx->operands[CAIRO_GL_TEX_MASK].texture.surface == surface) || + (ctx->current_target == surface)) + _cairo_gl_composite_flush (ctx); + + status = _cairo_gl_surface_resolve_multisampling (surface); + + return _cairo_gl_context_release (ctx, status); +} + +cairo_int_status_t +_cairo_gl_surface_resolve_multisampling (cairo_gl_surface_t *surface) +{ + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + if (! surface->msaa_active) + return CAIRO_INT_STATUS_SUCCESS; + + if (surface->base.device == NULL) + return CAIRO_INT_STATUS_SUCCESS; + + /* GLES surfaces do not need explicit resolution. */ + if (((cairo_gl_context_t *) surface->base.device)->gl_flavor == CAIRO_GL_FLAVOR_ES) + return CAIRO_INT_STATUS_SUCCESS; + + if (! _cairo_gl_surface_is_texture (surface)) + return CAIRO_INT_STATUS_SUCCESS; + + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return status; + + ctx->current_target = surface; + +#if CAIRO_HAS_GL_SURFACE + _cairo_gl_context_bind_framebuffer (ctx, surface, FALSE); +#endif + + status = _cairo_gl_context_release (ctx, status); + return status; +} + +static const cairo_compositor_t * +get_compositor (cairo_gl_surface_t *surface) +{ + cairo_gl_context_t *ctx = (cairo_gl_context_t *)surface->base.device; + return ctx->compositor; +} + +static cairo_int_status_t +_cairo_gl_surface_paint (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + /* simplify the common case of clearing the surface */ + if (clip == NULL) { + if (op == CAIRO_OPERATOR_CLEAR) + return _cairo_gl_surface_clear (surface, CAIRO_COLOR_TRANSPARENT); + else if (source->type == CAIRO_PATTERN_TYPE_SOLID && + (op == CAIRO_OPERATOR_SOURCE || + (op == CAIRO_OPERATOR_OVER && _cairo_pattern_is_opaque_solid (source)))) { + return _cairo_gl_surface_clear (surface, + &((cairo_solid_pattern_t *) source)->color); + } + } + + return _cairo_compositor_paint (get_compositor (surface), surface, + op, source, clip); +} + +static cairo_int_status_t +_cairo_gl_surface_mask (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + return _cairo_compositor_mask (get_compositor (surface), surface, + op, source, mask, clip); +} + +static cairo_int_status_t +_cairo_gl_surface_stroke (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + return _cairo_compositor_stroke (get_compositor (surface), surface, + op, source, path, style, + ctm, ctm_inverse, tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_gl_surface_fill (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + return _cairo_compositor_fill (get_compositor (surface), surface, + op, source, path, + fill_rule, tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_gl_surface_glyphs (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *font, + const cairo_clip_t *clip) +{ + return _cairo_compositor_glyphs (get_compositor (surface), surface, + op, source, glyphs, num_glyphs, font, + clip); +} + +static const cairo_surface_backend_t _cairo_gl_surface_backend = { + CAIRO_SURFACE_TYPE_GL, + _cairo_gl_surface_finish, + _cairo_default_context_create, + + _cairo_gl_surface_create_similar, + NULL, /* similar image */ + _cairo_gl_surface_map_to_image, + _cairo_gl_surface_unmap_image, + + _cairo_gl_surface_source, + _cairo_gl_surface_acquire_source_image, + _cairo_gl_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_gl_surface_get_extents, + _cairo_image_surface_get_font_options, + + _cairo_gl_surface_flush, + NULL, /* mark_dirty_rectangle */ + + _cairo_gl_surface_paint, + _cairo_gl_surface_mask, + _cairo_gl_surface_stroke, + _cairo_gl_surface_fill, + NULL, /* fill/stroke */ + _cairo_gl_surface_glyphs, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl-traps-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-gl-traps-compositor.c new file mode 100644 index 00000000000..125ed4eabcb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl-traps-compositor.c @@ -0,0 +1,558 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005,2010 Red Hat, Inc + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Benjamin Otte + * Carl Worth + * Chris Wilson + * Eric Anholt + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-spans-compositor-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-surface-offset-private.h" + +static cairo_int_status_t +acquire (void *abstract_dst) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +release (void *abstract_dst) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +set_clip_region (void *_surface, + cairo_region_t *region) +{ + cairo_gl_surface_t *surface = _surface; + + surface->clip_region = region; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +draw_image_boxes (void *_dst, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy) +{ + cairo_gl_surface_t *dst = _dst; + struct _cairo_boxes_chunk *chunk; + int i; + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + int x = _cairo_fixed_integer_part (b->p1.x); + int y = _cairo_fixed_integer_part (b->p1.y); + int w = _cairo_fixed_integer_part (b->p2.x) - x; + int h = _cairo_fixed_integer_part (b->p2.y) - y; + cairo_status_t status; + + status = _cairo_gl_surface_draw_image (dst, image, + x + dx, y + dy, + w, h, + x, y, + TRUE); + if (unlikely (status)) + return status; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +emit_aligned_boxes (cairo_gl_context_t *ctx, + const cairo_boxes_t *boxes) +{ + const struct _cairo_boxes_chunk *chunk; + cairo_gl_emit_rect_t emit = _cairo_gl_context_choose_emit_rect (ctx); + int i; + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + emit (ctx, x1, y1, x2, y2); + } + } +} + +static cairo_int_status_t +fill_boxes (void *_dst, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_solid_source (&setup, color); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + emit_aligned_boxes (ctx, boxes); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_int_status_t +composite_boxes (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_source_operand (&setup, + source_to_operand (abstract_src)); + _cairo_gl_operand_translate (&setup.src, dst_x-src_x, dst_y-src_y); + + _cairo_gl_composite_set_mask_operand (&setup, + source_to_operand (abstract_mask)); + _cairo_gl_operand_translate (&setup.mask, dst_x-mask_x, dst_y-mask_y); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + emit_aligned_boxes (ctx, boxes); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_int_status_t +composite (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_source_operand (&setup, + source_to_operand (abstract_src)); + _cairo_gl_operand_translate (&setup.src, dst_x-src_x, dst_y-src_y); + + _cairo_gl_composite_set_mask_operand (&setup, + source_to_operand (abstract_mask)); + _cairo_gl_operand_translate (&setup.mask, dst_x-mask_x, dst_y-mask_y); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + /* XXX clip */ + _cairo_gl_context_emit_rect (ctx, dst_x, dst_y, dst_x+width, dst_y+height); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_int_status_t +lerp (void *dst, + cairo_surface_t *src, + cairo_surface_t *mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + cairo_int_status_t status; + + /* we could avoid some repetition... */ + status = composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + mask_x, mask_y, + 0, 0, + dst_x, dst_y, + width, height); + if (unlikely (status)) + return status; + + status = composite (dst, CAIRO_OPERATOR_ADD, src, mask, + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +traps_to_operand (void *_dst, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_traps_t *traps, + cairo_gl_operand_t *operand, + int dst_x, int dst_y) +{ + pixman_format_code_t pixman_format; + pixman_image_t *pixman_image; + cairo_surface_t *image, *mask; + cairo_surface_pattern_t pattern; + cairo_status_t status; + + pixman_format = antialias != CAIRO_ANTIALIAS_NONE ? PIXMAN_a8 : PIXMAN_a1; + pixman_image = pixman_image_create_bits (pixman_format, + extents->width, + extents->height, + NULL, 0); + if (unlikely (pixman_image == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _pixman_image_add_traps (pixman_image, extents->x, extents->y, traps); + image = _cairo_image_surface_create_for_pixman_image (pixman_image, + pixman_format); + if (unlikely (image->status)) { + pixman_image_unref (pixman_image); + return image->status; + } + + /* GLES2 only supports RGB/RGBA when uploading */ + if (_cairo_gl_get_flavor () == CAIRO_GL_FLAVOR_ES) { + cairo_surface_pattern_t pattern; + cairo_surface_t *rgba_image; + + /* XXX perform this fixup inside _cairo_gl_draw_image() */ + + rgba_image = + _cairo_image_surface_create_with_pixman_format (NULL, + _cairo_is_little_endian () ? PIXMAN_a8b8g8r8 : PIXMAN_r8g8b8a8, + extents->width, + extents->height, + 0); + if (unlikely (rgba_image->status)) + return rgba_image->status; + + _cairo_pattern_init_for_surface (&pattern, image); + status = _cairo_surface_paint (rgba_image, CAIRO_OPERATOR_SOURCE, + &pattern.base, NULL); + _cairo_pattern_fini (&pattern.base); + + cairo_surface_destroy (image); + image = rgba_image; + + if (unlikely (status)) { + cairo_surface_destroy (image); + return status; + } + } + + mask = _cairo_surface_create_scratch (_dst, + CAIRO_CONTENT_COLOR_ALPHA, + extents->width, + extents->height, + NULL); + if (unlikely (mask->status)) { + cairo_surface_destroy (image); + return mask->status; + } + + status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *)mask, + (cairo_image_surface_t *)image, + 0, 0, + extents->width, extents->height, + 0, 0, + TRUE); + cairo_surface_destroy (image); + + if (unlikely (status)) + goto error; + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->x+dst_x, -extents->y+dst_y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + status = _cairo_gl_operand_init (operand, &pattern.base, _dst, + &_cairo_unbounded_rectangle, + &_cairo_unbounded_rectangle, + FALSE); + _cairo_pattern_fini (&pattern.base); + + if (unlikely (status)) + goto error; + + operand->texture.owns_surface = (cairo_gl_surface_t *)mask; + return CAIRO_STATUS_SUCCESS; + +error: + cairo_surface_destroy (mask); + return status; +} + +static cairo_int_status_t +composite_traps (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_traps_t *traps) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_int_status_t status; + + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_source_operand (&setup, + source_to_operand (abstract_src)); + _cairo_gl_operand_translate (&setup.src, -src_x-dst_x, -src_y-dst_y); + status = traps_to_operand (_dst, extents, antialias, traps, &setup.mask, dst_x, dst_y); + if (unlikely (status)) + goto FAIL; + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + /* XXX clip */ + _cairo_gl_context_emit_rect (ctx, + extents->x-dst_x, extents->y-dst_y, + extents->x-dst_x+extents->width, + extents->y-dst_y+extents->height); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + return status; +} + +static cairo_gl_surface_t * +tristrip_to_surface (void *_dst, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_tristrip_t *strip) +{ + pixman_format_code_t pixman_format; + pixman_image_t *pixman_image; + cairo_surface_t *image, *mask; + cairo_status_t status; + + pixman_format = antialias != CAIRO_ANTIALIAS_NONE ? PIXMAN_a8 : PIXMAN_a1, + pixman_image = pixman_image_create_bits (pixman_format, + extents->width, + extents->height, + NULL, 0); + if (unlikely (pixman_image == NULL)) + return (cairo_gl_surface_t *)_cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _pixman_image_add_tristrip (pixman_image, extents->x, extents->y, strip); + image = _cairo_image_surface_create_for_pixman_image (pixman_image, + pixman_format); + if (unlikely (image->status)) { + pixman_image_unref (pixman_image); + return (cairo_gl_surface_t *)image; + } + + mask = _cairo_surface_create_scratch (_dst, + CAIRO_CONTENT_COLOR_ALPHA, + extents->width, + extents->height, + NULL); + if (unlikely (mask->status)) { + cairo_surface_destroy (image); + return (cairo_gl_surface_t *)mask; + } + + status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *)mask, + (cairo_image_surface_t *)image, + 0, 0, + extents->width, extents->height, + 0, 0, + TRUE); + cairo_surface_destroy (image); + if (unlikely (status)) { + cairo_surface_destroy (mask); + return (cairo_gl_surface_t*)_cairo_surface_create_in_error (status); + } + + return (cairo_gl_surface_t*)mask; +} + +static cairo_int_status_t +composite_tristrip (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_tristrip_t *strip) +{ + cairo_gl_composite_t setup; + cairo_gl_context_t *ctx; + cairo_gl_surface_t *mask; + cairo_int_status_t status; + + mask = tristrip_to_surface (_dst, extents, antialias, strip); + if (unlikely (mask->base.status)) + return mask->base.status; + + status = _cairo_gl_composite_init (&setup, op, _dst, FALSE); + if (unlikely (status)) + goto FAIL; + + _cairo_gl_composite_set_source_operand (&setup, + source_to_operand (abstract_src)); + + //_cairo_gl_composite_set_mask_surface (&setup, mask, 0, 0); + + status = _cairo_gl_composite_begin (&setup, &ctx); + if (unlikely (status)) + goto FAIL; + + /* XXX clip */ + _cairo_gl_context_emit_rect (ctx, + dst_x, dst_y, + dst_x+extents->width, + dst_y+extents->height); + status = _cairo_gl_context_release (ctx, CAIRO_STATUS_SUCCESS); + +FAIL: + _cairo_gl_composite_fini (&setup); + cairo_surface_destroy (&mask->base); + return status; +} + +static cairo_int_status_t +check_composite (const cairo_composite_rectangles_t *extents) +{ + if (! _cairo_gl_operator_is_supported (extents->op)) + return UNSUPPORTED ("unsupported operator"); + + return CAIRO_STATUS_SUCCESS; +} + +const cairo_compositor_t * +_cairo_gl_traps_compositor_get (void) +{ + static cairo_traps_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_traps_compositor_init (&compositor, &_cairo_fallback_compositor); + compositor.acquire = acquire; + compositor.release = release; + compositor.set_clip_region = set_clip_region; + compositor.pattern_to_surface = _cairo_gl_pattern_to_source; + compositor.draw_image_boxes = draw_image_boxes; + //compositor.copy_boxes = copy_boxes; + compositor.fill_boxes = fill_boxes; + compositor.check_composite = check_composite; + compositor.composite = composite; + compositor.lerp = lerp; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + //compositor.check_composite_traps = check_composite_traps; + compositor.composite_traps = composite_traps; + //compositor.check_composite_tristrip = check_composite_traps; + compositor.composite_tristrip = composite_tristrip; + compositor.check_composite_glyphs = _cairo_gl_check_composite_glyphs; + compositor.composite_glyphs = _cairo_gl_composite_glyphs; + } + + return &compositor.base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gl.h b/Build/source/libs/cairo/cairo-src/src/cairo-gl.h new file mode 100644 index 00000000000..9fd7608f5cf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gl.h @@ -0,0 +1,155 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Eric Anholt. + */ + +/* + * cairo-gl.h: + * + * The cairo-gl backend provides an implementation of possibly + * hardware-accelerated cairo rendering by targeting the OpenGL API. + * The goal of the cairo-gl backend is to provide better performance + * with equal functionality to cairo-image where possible. It does + * not directly provide for applying additional OpenGL effects to + * cairo surfaces. + * + * Cairo-gl allows interoperability with other GL rendering through GL + * context sharing. Cairo-gl surfaces are created in reference to a + * #cairo_device_t, which represents a GL context created by the user. + * When that GL context is created with its sharePtr set to another + * context (or vice versa), its objects (textures backing cairo-gl + * surfaces) can be accessed in the other OpenGL context. This allows + * cairo-gl to maintain its drawing state in one context while the + * user's 3D rendering occurs in the user's other context. + * + * However, as only one context can be current to a thread at a time, + * cairo-gl may make its context current to the thread on any cairo + * call which interacts with a cairo-gl surface or the cairo-gl + * device. As a result, the user must make their own context current + * between any cairo calls and their own OpenGL rendering. + **/ + +#ifndef CAIRO_GL_H +#define CAIRO_GL_H + +#include "cairo.h" + +#if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_gl_surface_create (cairo_device_t *device, + cairo_content_t content, + int width, int height); + +cairo_public cairo_surface_t * +cairo_gl_surface_create_for_texture (cairo_device_t *abstract_device, + cairo_content_t content, + unsigned int tex, + int width, int height); +cairo_public void +cairo_gl_surface_set_size (cairo_surface_t *surface, int width, int height); + +cairo_public int +cairo_gl_surface_get_width (cairo_surface_t *abstract_surface); + +cairo_public int +cairo_gl_surface_get_height (cairo_surface_t *abstract_surface); + +cairo_public void +cairo_gl_surface_swapbuffers (cairo_surface_t *surface); + +cairo_public void +cairo_gl_device_set_thread_aware (cairo_device_t *device, + cairo_bool_t thread_aware); + +#if CAIRO_HAS_GLX_FUNCTIONS +#include + +cairo_public cairo_device_t * +cairo_glx_device_create (Display *dpy, GLXContext gl_ctx); + +cairo_public Display * +cairo_glx_device_get_display (cairo_device_t *device); + +cairo_public GLXContext +cairo_glx_device_get_context (cairo_device_t *device); + +cairo_public cairo_surface_t * +cairo_gl_surface_create_for_window (cairo_device_t *device, + Window win, + int width, int height); +#endif + +#if CAIRO_HAS_WGL_FUNCTIONS +#include + +cairo_public cairo_device_t * +cairo_wgl_device_create (HGLRC rc); + +cairo_public HGLRC +cairo_wgl_device_get_context (cairo_device_t *device); + +cairo_public cairo_surface_t * +cairo_gl_surface_create_for_dc (cairo_device_t *device, + HDC dc, + int width, + int height); +#endif + +#if CAIRO_HAS_EGL_FUNCTIONS +#include + +cairo_public cairo_device_t * +cairo_egl_device_create (EGLDisplay dpy, EGLContext egl); + +cairo_public cairo_surface_t * +cairo_gl_surface_create_for_egl (cairo_device_t *device, + EGLSurface egl, + int width, + int height); + +cairo_public EGLDisplay +cairo_egl_device_get_display (cairo_device_t *device); + +cairo_public EGLSurface +cairo_egl_device_get_context (cairo_device_t *device); + +#endif + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_GL_SURFACE */ +# error Cairo was not compiled with support for the GL backend +#endif /* CAIRO_HAS_GL_SURFACE */ + +#endif /* CAIRO_GL_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-glx-context.c b/Build/source/libs/cairo/cairo-src/src/cairo-glx-context.c new file mode 100644 index 00000000000..3761b9079a4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-glx-context.c @@ -0,0 +1,324 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-error-private.h" + +#include + +/* XXX needs hooking into XCloseDisplay() */ + +typedef struct _cairo_glx_context { + cairo_gl_context_t base; + + Display *display; + Window dummy_window; + GLXContext context; + + GLXDrawable previous_drawable; + GLXContext previous_context; + + cairo_bool_t has_multithread_makecurrent; +} cairo_glx_context_t; + +typedef struct _cairo_glx_surface { + cairo_gl_surface_t base; + + Window win; +} cairo_glx_surface_t; + +static cairo_bool_t +_context_acquisition_changed_glx_state (cairo_glx_context_t *ctx, + GLXDrawable current_drawable) +{ + return ctx->previous_drawable != current_drawable || + ctx->previous_context != ctx->context; +} + +static GLXDrawable +_glx_get_current_drawable (cairo_glx_context_t *ctx) +{ + if (ctx->base.current_target == NULL || + _cairo_gl_surface_is_texture (ctx->base.current_target)) { + return ctx->dummy_window; + } + + return ((cairo_glx_surface_t *) ctx->base.current_target)->win; +} + +static void +_glx_query_current_state (cairo_glx_context_t * ctx) +{ + ctx->previous_drawable = glXGetCurrentDrawable (); + ctx->previous_context = glXGetCurrentContext (); + + /* If any of the values were none, assume they are all none. Not all + drivers seem well behaved when it comes to using these values across + multiple threads. */ + if (ctx->previous_drawable == None || + ctx->previous_context == None) { + ctx->previous_drawable = None; + ctx->previous_context = None; + } +} + +static void +_glx_acquire (void *abstract_ctx) +{ + cairo_glx_context_t *ctx = abstract_ctx; + GLXDrawable current_drawable = _glx_get_current_drawable (ctx); + + _glx_query_current_state (ctx); + if (!_context_acquisition_changed_glx_state (ctx, current_drawable)) + return; + + glXMakeCurrent (ctx->display, current_drawable, ctx->context); +} + +static void +_glx_make_current (void *abstract_ctx, cairo_gl_surface_t *abstract_surface) +{ + cairo_glx_context_t *ctx = abstract_ctx; + cairo_glx_surface_t *surface = (cairo_glx_surface_t *) abstract_surface; + + /* Set the window as the target of our context. */ + glXMakeCurrent (ctx->display, surface->win, ctx->context); +} + +static void +_glx_release (void *abstract_ctx) +{ + cairo_glx_context_t *ctx = abstract_ctx; + + if (ctx->has_multithread_makecurrent || !ctx->base.thread_aware || + !_context_acquisition_changed_glx_state (ctx, + _glx_get_current_drawable (ctx))) { + return; + } + + glXMakeCurrent (ctx->display, None, None); +} + +static void +_glx_swap_buffers (void *abstract_ctx, + cairo_gl_surface_t *abstract_surface) +{ + cairo_glx_context_t *ctx = abstract_ctx; + cairo_glx_surface_t *surface = (cairo_glx_surface_t *) abstract_surface; + + glXSwapBuffers (ctx->display, surface->win); +} + +static void +_glx_destroy (void *abstract_ctx) +{ + cairo_glx_context_t *ctx = abstract_ctx; + + if (ctx->dummy_window != None) + XDestroyWindow (ctx->display, ctx->dummy_window); + + glXMakeCurrent (ctx->display, None, None); +} + +static cairo_status_t +_glx_dummy_window (Display *dpy, GLXContext gl_ctx, Window *dummy) +{ + int attr[3] = { GLX_FBCONFIG_ID, 0, None }; + GLXFBConfig *config; + XVisualInfo *vi; + Colormap cmap; + XSetWindowAttributes swa; + Window win = None; + int cnt; + + /* Create a dummy window created for the target GLX context that we can + * use to query the available GL/GLX extensions. + */ + glXQueryContext (dpy, gl_ctx, GLX_FBCONFIG_ID, &attr[1]); + + cnt = 0; + config = glXChooseFBConfig (dpy, DefaultScreen (dpy), attr, &cnt); + if (unlikely (cnt == 0)) + return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + + vi = glXGetVisualFromFBConfig (dpy, config[0]); + XFree (config); + + if (unlikely (vi == NULL)) + return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + + cmap = XCreateColormap (dpy, + RootWindow (dpy, vi->screen), + vi->visual, + AllocNone); + swa.colormap = cmap; + swa.border_pixel = 0; + win = XCreateWindow (dpy, RootWindow (dpy, vi->screen), + -1, -1, 1, 1, 0, + vi->depth, + InputOutput, + vi->visual, + CWBorderPixel | CWColormap, &swa); + XFreeColormap (dpy, cmap); + XFree (vi); + + XFlush (dpy); + if (unlikely (! glXMakeCurrent (dpy, win, gl_ctx))) { + XDestroyWindow (dpy, win); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + *dummy = win; + return CAIRO_STATUS_SUCCESS; +} + +cairo_device_t * +cairo_glx_device_create (Display *dpy, GLXContext gl_ctx) +{ + cairo_glx_context_t *ctx; + cairo_status_t status; + Window dummy = None; + const char *glx_extensions; + + ctx = calloc (1, sizeof (cairo_glx_context_t)); + if (unlikely (ctx == NULL)) + return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); + + /* glx_dummy_window will call glXMakeCurrent, so we need to + * query the current state of the context now. */ + _glx_query_current_state (ctx); + + status = _glx_dummy_window (dpy, gl_ctx, &dummy); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + ctx->display = dpy; + ctx->dummy_window = dummy; + ctx->context = gl_ctx; + + ctx->base.acquire = _glx_acquire; + ctx->base.release = _glx_release; + ctx->base.make_current = _glx_make_current; + ctx->base.swap_buffers = _glx_swap_buffers; + ctx->base.destroy = _glx_destroy; + + status = _cairo_gl_dispatch_init (&ctx->base.dispatch, + (cairo_gl_get_proc_addr_func_t) glXGetProcAddress); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + status = _cairo_gl_context_init (&ctx->base); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + glx_extensions = glXQueryExtensionsString (dpy, DefaultScreen (dpy)); + if (strstr(glx_extensions, "GLX_MESA_multithread_makecurrent")) { + ctx->has_multithread_makecurrent = TRUE; + } + + ctx->base.release (ctx); + + return &ctx->base.base; +} + +Display * +cairo_glx_device_get_display (cairo_device_t *device) +{ + cairo_glx_context_t *ctx; + + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { + _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + return NULL; + } + + ctx = (cairo_glx_context_t *) device; + + return ctx->display; +} + +GLXContext +cairo_glx_device_get_context (cairo_device_t *device) +{ + cairo_glx_context_t *ctx; + + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { + _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + return NULL; + } + + ctx = (cairo_glx_context_t *) device; + + return ctx->context; +} + +cairo_surface_t * +cairo_gl_surface_create_for_window (cairo_device_t *device, + Window win, + int width, + int height) +{ + cairo_glx_surface_t *surface; + + if (unlikely (device->status)) + return _cairo_surface_create_in_error (device->status); + + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + + if (width <= 0 || height <= 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + surface = calloc (1, sizeof (cairo_glx_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_gl_surface_init (device, &surface->base, + CAIRO_CONTENT_COLOR_ALPHA, width, height); + surface->win = win; + + return &surface->base.base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gstate-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-gstate-private.h new file mode 100644 index 00000000000..b2ccc76d145 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gstate-private.h @@ -0,0 +1,387 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_GSTATE_PRIVATE_H +#define CAIRO_GSTATE_PRIVATE_H + +#include "cairo-clip-private.h" + +struct _cairo_gstate { + cairo_operator_t op; + + double opacity; + double tolerance; + cairo_antialias_t antialias; + + cairo_stroke_style_t stroke_style; + + cairo_fill_rule_t fill_rule; + + cairo_font_face_t *font_face; + cairo_scaled_font_t *scaled_font; /* Specific to the current CTM */ + cairo_scaled_font_t *previous_scaled_font; /* holdover */ + cairo_matrix_t font_matrix; + cairo_font_options_t font_options; + + cairo_clip_t *clip; + + cairo_surface_t *target; /* The target to which all rendering is directed */ + cairo_surface_t *parent_target; /* The previous target which was receiving rendering */ + cairo_surface_t *original_target; /* The original target the initial gstate was created with */ + + /* the user is allowed to update the device after we have cached the matrices... */ + cairo_observer_t device_transform_observer; + + cairo_matrix_t ctm; + cairo_matrix_t ctm_inverse; + cairo_matrix_t source_ctm_inverse; /* At the time ->source was set */ + cairo_bool_t is_identity; + + cairo_pattern_t *source; + + struct _cairo_gstate *next; +}; + +/* cairo-gstate.c */ +cairo_private cairo_status_t +_cairo_gstate_init (cairo_gstate_t *gstate, + cairo_surface_t *target); + +cairo_private void +_cairo_gstate_fini (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist); + +cairo_private cairo_status_t +_cairo_gstate_restore (cairo_gstate_t **gstate, cairo_gstate_t **freelist); + +cairo_private cairo_bool_t +_cairo_gstate_is_group (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child); + +cairo_private cairo_surface_t * +_cairo_gstate_get_target (cairo_gstate_t *gstate); + +cairo_private cairo_surface_t * +_cairo_gstate_get_original_target (cairo_gstate_t *gstate); + +cairo_private cairo_clip_t * +_cairo_gstate_get_clip (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_source (cairo_gstate_t *gstate, cairo_pattern_t *source); + +cairo_private cairo_pattern_t * +_cairo_gstate_get_source (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_operator (cairo_gstate_t *gstate, cairo_operator_t op); + +cairo_private cairo_operator_t +_cairo_gstate_get_operator (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_opacity (cairo_gstate_t *gstate, double opacity); + +cairo_private double +_cairo_gstate_get_opacity (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_tolerance (cairo_gstate_t *gstate, double tolerance); + +cairo_private double +_cairo_gstate_get_tolerance (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule); + +cairo_private cairo_fill_rule_t +_cairo_gstate_get_fill_rule (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_line_width (cairo_gstate_t *gstate, double width); + +cairo_private double +_cairo_gstate_get_line_width (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_line_cap (cairo_gstate_t *gstate, cairo_line_cap_t line_cap); + +cairo_private cairo_line_cap_t +_cairo_gstate_get_line_cap (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_line_join (cairo_gstate_t *gstate, cairo_line_join_t line_join); + +cairo_private cairo_line_join_t +_cairo_gstate_get_line_join (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dashes, double offset); + +cairo_private void +_cairo_gstate_get_dash (cairo_gstate_t *gstate, double *dash, int *num_dashes, double *offset); + +cairo_private cairo_status_t +_cairo_gstate_set_miter_limit (cairo_gstate_t *gstate, double limit); + +cairo_private double +_cairo_gstate_get_miter_limit (cairo_gstate_t *gstate); + +cairo_private void +_cairo_gstate_get_matrix (cairo_gstate_t *gstate, cairo_matrix_t *matrix); + +cairo_private cairo_status_t +_cairo_gstate_translate (cairo_gstate_t *gstate, double tx, double ty); + +cairo_private cairo_status_t +_cairo_gstate_scale (cairo_gstate_t *gstate, double sx, double sy); + +cairo_private cairo_status_t +_cairo_gstate_rotate (cairo_gstate_t *gstate, double angle); + +cairo_private cairo_status_t +_cairo_gstate_transform (cairo_gstate_t *gstate, + const cairo_matrix_t *matrix); + +cairo_private cairo_status_t +_cairo_gstate_set_matrix (cairo_gstate_t *gstate, + const cairo_matrix_t *matrix); + +cairo_private void +_cairo_gstate_identity_matrix (cairo_gstate_t *gstate); + +cairo_private void +_cairo_gstate_user_to_device (cairo_gstate_t *gstate, double *x, double *y); + +cairo_private void +_cairo_gstate_user_to_device_distance (cairo_gstate_t *gstate, double *dx, double *dy); + +cairo_private void +_cairo_gstate_device_to_user (cairo_gstate_t *gstate, double *x, double *y); + +cairo_private void +_cairo_gstate_device_to_user_distance (cairo_gstate_t *gstate, double *dx, double *dy); + +cairo_private void +_do_cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y); + +static inline void +_cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y) +{ + if (! gstate->is_identity) + _do_cairo_gstate_user_to_backend (gstate, x, y); +} + +cairo_private void +_do_cairo_gstate_user_to_backend_distance (cairo_gstate_t *gstate, double *x, double *y); + +static inline void +_cairo_gstate_user_to_backend_distance (cairo_gstate_t *gstate, double *x, double *y) +{ + if (! gstate->is_identity) + _do_cairo_gstate_user_to_backend_distance (gstate, x, y); +} + +cairo_private void +_do_cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y); + +static inline void +_cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y) +{ + if (! gstate->is_identity) + _do_cairo_gstate_backend_to_user (gstate, x, y); +} + +cairo_private void +_do_cairo_gstate_backend_to_user_distance (cairo_gstate_t *gstate, double *x, double *y); + +static inline void +_cairo_gstate_backend_to_user_distance (cairo_gstate_t *gstate, double *x, double *y) +{ + if (! gstate->is_identity) + _do_cairo_gstate_backend_to_user_distance (gstate, x, y); +} + +cairo_private void +_cairo_gstate_backend_to_user_rectangle (cairo_gstate_t *gstate, + double *x1, double *y1, + double *x2, double *y2, + cairo_bool_t *is_tight); + +cairo_private void +_cairo_gstate_path_extents (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double *x1, double *y1, + double *x2, double *y2); + +cairo_private cairo_status_t +_cairo_gstate_paint (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_mask (cairo_gstate_t *gstate, + cairo_pattern_t *mask); + +cairo_private cairo_status_t +_cairo_gstate_stroke (cairo_gstate_t *gstate, cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_gstate_copy_page (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_show_page (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_stroke_extents (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double *x1, double *y1, + double *x2, double *y2); + +cairo_private cairo_status_t +_cairo_gstate_fill_extents (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double *x1, double *y1, + double *x2, double *y2); + +cairo_private cairo_status_t +_cairo_gstate_in_stroke (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double x, + double y, + cairo_bool_t *inside_ret); + +cairo_private cairo_bool_t +_cairo_gstate_in_fill (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double x, + double y); + +cairo_private cairo_bool_t +_cairo_gstate_in_clip (cairo_gstate_t *gstate, + double x, + double y); + +cairo_private cairo_status_t +_cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_gstate_reset_clip (cairo_gstate_t *gstate); + +cairo_private cairo_bool_t +_cairo_gstate_clip_extents (cairo_gstate_t *gstate, + double *x1, + double *y1, + double *x2, + double *y2); + +cairo_private cairo_rectangle_list_t* +_cairo_gstate_copy_clip_rectangle_list (cairo_gstate_t *gstate); + +cairo_private cairo_status_t +_cairo_gstate_show_surface (cairo_gstate_t *gstate, + cairo_surface_t *surface, + double x, + double y, + double width, + double height); + +cairo_private cairo_status_t +_cairo_gstate_set_font_size (cairo_gstate_t *gstate, + double size); + +cairo_private void +_cairo_gstate_get_font_matrix (cairo_gstate_t *gstate, + cairo_matrix_t *matrix); + +cairo_private cairo_status_t +_cairo_gstate_set_font_matrix (cairo_gstate_t *gstate, + const cairo_matrix_t *matrix); + +cairo_private void +_cairo_gstate_get_font_options (cairo_gstate_t *gstate, + cairo_font_options_t *options); + +cairo_private void +_cairo_gstate_set_font_options (cairo_gstate_t *gstate, + const cairo_font_options_t *options); + +cairo_private cairo_status_t +_cairo_gstate_get_font_face (cairo_gstate_t *gstate, + cairo_font_face_t **font_face); + +cairo_private cairo_status_t +_cairo_gstate_get_scaled_font (cairo_gstate_t *gstate, + cairo_scaled_font_t **scaled_font); + +cairo_private cairo_status_t +_cairo_gstate_get_font_extents (cairo_gstate_t *gstate, + cairo_font_extents_t *extents); + +cairo_private cairo_status_t +_cairo_gstate_set_font_face (cairo_gstate_t *gstate, + cairo_font_face_t *font_face); + +cairo_private cairo_status_t +_cairo_gstate_glyph_extents (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents); + +cairo_private cairo_status_t +_cairo_gstate_show_text_glyphs (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_glyph_text_info_t *info); + +cairo_private cairo_status_t +_cairo_gstate_glyph_path (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_gstate_set_antialias (cairo_gstate_t *gstate, + cairo_antialias_t antialias); + +cairo_private cairo_antialias_t +_cairo_gstate_get_antialias (cairo_gstate_t *gstate); + +#endif /* CAIRO_GSTATE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-gstate.c b/Build/source/libs/cairo/cairo-src/src/cairo-gstate.c new file mode 100644 index 00000000000..b4e988e96d8 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-gstate.c @@ -0,0 +1,2346 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-list-inline.h" +#include "cairo-gstate-private.h" +#include "cairo-pattern-private.h" +#include "cairo-traps-private.h" + +#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE) +#define ISFINITE(x) isfinite (x) +#else +#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */ +#endif + +static cairo_status_t +_cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other); + +static cairo_status_t +_cairo_gstate_ensure_font_face (cairo_gstate_t *gstate); + +static cairo_status_t +_cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate); + +static void +_cairo_gstate_unset_scaled_font (cairo_gstate_t *gstate); + +static void +_cairo_gstate_transform_glyphs_to_backend (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_glyph_t *transformed_glyphs, + int *num_transformed_glyphs, + cairo_text_cluster_t *transformed_clusters); + +static void +_cairo_gstate_update_device_transform (cairo_observer_t *observer, + void *arg) +{ + cairo_gstate_t *gstate = cairo_container_of (observer, + cairo_gstate_t, + device_transform_observer); + + gstate->is_identity = (_cairo_matrix_is_identity (&gstate->ctm) && + _cairo_matrix_is_identity (&gstate->target->device_transform)); +} + +cairo_status_t +_cairo_gstate_init (cairo_gstate_t *gstate, + cairo_surface_t *target) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (gstate, sizeof (cairo_gstate_t))); + + gstate->next = NULL; + + gstate->op = CAIRO_GSTATE_OPERATOR_DEFAULT; + gstate->opacity = 1.; + + gstate->tolerance = CAIRO_GSTATE_TOLERANCE_DEFAULT; + gstate->antialias = CAIRO_ANTIALIAS_DEFAULT; + + _cairo_stroke_style_init (&gstate->stroke_style); + + gstate->fill_rule = CAIRO_GSTATE_FILL_RULE_DEFAULT; + + gstate->font_face = NULL; + gstate->scaled_font = NULL; + gstate->previous_scaled_font = NULL; + + cairo_matrix_init_scale (&gstate->font_matrix, + CAIRO_GSTATE_DEFAULT_FONT_SIZE, + CAIRO_GSTATE_DEFAULT_FONT_SIZE); + + _cairo_font_options_init_default (&gstate->font_options); + + gstate->clip = NULL; + + gstate->target = cairo_surface_reference (target); + gstate->parent_target = NULL; + gstate->original_target = cairo_surface_reference (target); + + gstate->device_transform_observer.callback = _cairo_gstate_update_device_transform; + cairo_list_add (&gstate->device_transform_observer.link, + &gstate->target->device_transform_observers); + + gstate->is_identity = _cairo_matrix_is_identity (&gstate->target->device_transform); + cairo_matrix_init_identity (&gstate->ctm); + gstate->ctm_inverse = gstate->ctm; + gstate->source_ctm_inverse = gstate->ctm; + + gstate->source = (cairo_pattern_t *) &_cairo_pattern_black.base; + + /* Now that the gstate is fully initialized and ready for the eventual + * _cairo_gstate_fini(), we can check for errors (and not worry about + * the resource deallocation). */ + return target->status; +} + +/** + * _cairo_gstate_init_copy: + * + * Initialize @gstate by performing a deep copy of state fields from + * @other. Note that gstate->next is not copied but is set to %NULL by + * this function. + **/ +static cairo_status_t +_cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other) +{ + cairo_status_t status; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (gstate, sizeof (cairo_gstate_t))); + + gstate->op = other->op; + gstate->opacity = other->opacity; + + gstate->tolerance = other->tolerance; + gstate->antialias = other->antialias; + + status = _cairo_stroke_style_init_copy (&gstate->stroke_style, + &other->stroke_style); + if (unlikely (status)) + return status; + + gstate->fill_rule = other->fill_rule; + + gstate->font_face = cairo_font_face_reference (other->font_face); + gstate->scaled_font = cairo_scaled_font_reference (other->scaled_font); + gstate->previous_scaled_font = cairo_scaled_font_reference (other->previous_scaled_font); + + gstate->font_matrix = other->font_matrix; + + _cairo_font_options_init_copy (&gstate->font_options , &other->font_options); + + gstate->clip = _cairo_clip_copy (other->clip); + + gstate->target = cairo_surface_reference (other->target); + /* parent_target is always set to NULL; it's only ever set by redirect_target */ + gstate->parent_target = NULL; + gstate->original_target = cairo_surface_reference (other->original_target); + + gstate->device_transform_observer.callback = _cairo_gstate_update_device_transform; + cairo_list_add (&gstate->device_transform_observer.link, + &gstate->target->device_transform_observers); + + gstate->is_identity = other->is_identity; + gstate->ctm = other->ctm; + gstate->ctm_inverse = other->ctm_inverse; + gstate->source_ctm_inverse = other->source_ctm_inverse; + + gstate->source = cairo_pattern_reference (other->source); + + gstate->next = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gstate_fini (cairo_gstate_t *gstate) +{ + _cairo_stroke_style_fini (&gstate->stroke_style); + + cairo_font_face_destroy (gstate->font_face); + gstate->font_face = NULL; + + cairo_scaled_font_destroy (gstate->previous_scaled_font); + gstate->previous_scaled_font = NULL; + + cairo_scaled_font_destroy (gstate->scaled_font); + gstate->scaled_font = NULL; + + _cairo_clip_destroy (gstate->clip); + + cairo_list_del (&gstate->device_transform_observer.link); + + cairo_surface_destroy (gstate->target); + gstate->target = NULL; + + cairo_surface_destroy (gstate->parent_target); + gstate->parent_target = NULL; + + cairo_surface_destroy (gstate->original_target); + gstate->original_target = NULL; + + cairo_pattern_destroy (gstate->source); + gstate->source = NULL; + + VG (VALGRIND_MAKE_MEM_NOACCESS (gstate, sizeof (cairo_gstate_t))); +} + +/** + * _cairo_gstate_save: + * @gstate: input/output gstate pointer + * + * Makes a copy of the current state of @gstate and saves it + * to @gstate->next, then put the address of the newly allcated + * copy into @gstate. _cairo_gstate_restore() reverses this. + **/ +cairo_status_t +_cairo_gstate_save (cairo_gstate_t **gstate, cairo_gstate_t **freelist) +{ + cairo_gstate_t *top; + cairo_status_t status; + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + top = *freelist; + if (top == NULL) { + top = malloc (sizeof (cairo_gstate_t)); + if (unlikely (top == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + *freelist = top->next; + + status = _cairo_gstate_init_copy (top, *gstate); + if (unlikely (status)) { + top->next = *freelist; + *freelist = top; + return status; + } + + top->next = *gstate; + *gstate = top; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_gstate_restore: + * @gstate: input/output gstate pointer + * + * Reverses the effects of one _cairo_gstate_save() call. + **/ +cairo_status_t +_cairo_gstate_restore (cairo_gstate_t **gstate, cairo_gstate_t **freelist) +{ + cairo_gstate_t *top; + + top = *gstate; + if (top->next == NULL) + return _cairo_error (CAIRO_STATUS_INVALID_RESTORE); + + *gstate = top->next; + + _cairo_gstate_fini (top); + VG (VALGRIND_MAKE_MEM_UNDEFINED (&top->next, sizeof (cairo_gstate_t *))); + top->next = *freelist; + *freelist = top; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_gstate_redirect_target: + * @gstate: a #cairo_gstate_t + * @child: the new child target + * + * Redirect @gstate rendering to a "child" target. The original + * "parent" target with which the gstate was created will not be + * affected. See _cairo_gstate_get_target(). + **/ +cairo_status_t +_cairo_gstate_redirect_target (cairo_gstate_t *gstate, cairo_surface_t *child) +{ + /* If this gstate is already redirected, this is an error; we need a + * new gstate to be able to redirect */ + assert (gstate->parent_target == NULL); + + /* Set up our new parent_target based on our current target; + * gstate->parent_target will take the ref that is held by gstate->target + */ + gstate->parent_target = gstate->target; + + /* Now set up our new target; we overwrite gstate->target directly, + * since its ref is now owned by gstate->parent_target */ + gstate->target = cairo_surface_reference (child); + gstate->is_identity &= _cairo_matrix_is_identity (&child->device_transform); + cairo_list_move (&gstate->device_transform_observer.link, + &gstate->target->device_transform_observers); + + /* The clip is in surface backend coordinates for the previous target; + * translate it into the child's backend coordinates. */ + _cairo_clip_destroy (gstate->clip); + gstate->clip = _cairo_clip_copy_with_translation (gstate->next->clip, + child->device_transform.x0 - gstate->parent_target->device_transform.x0, + child->device_transform.y0 - gstate->parent_target->device_transform.y0); + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_gstate_is_group: + * @gstate: a #cairo_gstate_t + * + * Check if _cairo_gstate_redirect_target has been called on the head + * of the stack. + * + * Return value: %TRUE if @gstate is redirected to a target different + * than the previous state in the stack, %FALSE otherwise. + **/ +cairo_bool_t +_cairo_gstate_is_group (cairo_gstate_t *gstate) +{ + return gstate->parent_target != NULL; +} + +/** + * _cairo_gstate_get_target: + * @gstate: a #cairo_gstate_t + * + * Return the current drawing target; if drawing is not redirected, + * this will be the same as _cairo_gstate_get_original_target(). + * + * Return value: the current target surface + **/ +cairo_surface_t * +_cairo_gstate_get_target (cairo_gstate_t *gstate) +{ + return gstate->target; +} + +/** + * _cairo_gstate_get_original_target: + * @gstate: a #cairo_gstate_t + * + * Return the original target with which @gstate was created. This + * function always returns the original target independent of any + * child target that may have been set with + * _cairo_gstate_redirect_target. + * + * Return value: the original target surface + **/ +cairo_surface_t * +_cairo_gstate_get_original_target (cairo_gstate_t *gstate) +{ + return gstate->original_target; +} + +/** + * _cairo_gstate_get_clip: + * @gstate: a #cairo_gstate_t + * + * This space left intentionally blank. + * + * Return value: a pointer to the gstate's #cairo_clip_t structure. + **/ +cairo_clip_t * +_cairo_gstate_get_clip (cairo_gstate_t *gstate) +{ + return gstate->clip; +} + +cairo_status_t +_cairo_gstate_set_source (cairo_gstate_t *gstate, + cairo_pattern_t *source) +{ + if (source->status) + return source->status; + + source = cairo_pattern_reference (source); + cairo_pattern_destroy (gstate->source); + gstate->source = source; + gstate->source_ctm_inverse = gstate->ctm_inverse; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_pattern_t * +_cairo_gstate_get_source (cairo_gstate_t *gstate) +{ + if (gstate->source == &_cairo_pattern_black.base) { + /* do not expose the static object to the user */ + gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK); + } + + return gstate->source; +} + +cairo_status_t +_cairo_gstate_set_operator (cairo_gstate_t *gstate, cairo_operator_t op) +{ + gstate->op = op; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_operator_t +_cairo_gstate_get_operator (cairo_gstate_t *gstate) +{ + return gstate->op; +} + +cairo_status_t +_cairo_gstate_set_opacity (cairo_gstate_t *gstate, double op) +{ + gstate->opacity = op; + + return CAIRO_STATUS_SUCCESS; +} + +double +_cairo_gstate_get_opacity (cairo_gstate_t *gstate) +{ + return gstate->opacity; +} + +cairo_status_t +_cairo_gstate_set_tolerance (cairo_gstate_t *gstate, double tolerance) +{ + gstate->tolerance = tolerance; + + return CAIRO_STATUS_SUCCESS; +} + +double +_cairo_gstate_get_tolerance (cairo_gstate_t *gstate) +{ + return gstate->tolerance; +} + +cairo_status_t +_cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule) +{ + gstate->fill_rule = fill_rule; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_fill_rule_t +_cairo_gstate_get_fill_rule (cairo_gstate_t *gstate) +{ + return gstate->fill_rule; +} + +cairo_status_t +_cairo_gstate_set_line_width (cairo_gstate_t *gstate, double width) +{ + gstate->stroke_style.line_width = width; + + return CAIRO_STATUS_SUCCESS; +} + +double +_cairo_gstate_get_line_width (cairo_gstate_t *gstate) +{ + return gstate->stroke_style.line_width; +} + +cairo_status_t +_cairo_gstate_set_line_cap (cairo_gstate_t *gstate, cairo_line_cap_t line_cap) +{ + gstate->stroke_style.line_cap = line_cap; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_line_cap_t +_cairo_gstate_get_line_cap (cairo_gstate_t *gstate) +{ + return gstate->stroke_style.line_cap; +} + +cairo_status_t +_cairo_gstate_set_line_join (cairo_gstate_t *gstate, cairo_line_join_t line_join) +{ + gstate->stroke_style.line_join = line_join; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_line_join_t +_cairo_gstate_get_line_join (cairo_gstate_t *gstate) +{ + return gstate->stroke_style.line_join; +} + +cairo_status_t +_cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dashes, double offset) +{ + double dash_total, on_total, off_total; + int i, j; + + free (gstate->stroke_style.dash); + + gstate->stroke_style.num_dashes = num_dashes; + + if (gstate->stroke_style.num_dashes == 0) { + gstate->stroke_style.dash = NULL; + gstate->stroke_style.dash_offset = 0.0; + return CAIRO_STATUS_SUCCESS; + } + + gstate->stroke_style.dash = _cairo_malloc_ab (gstate->stroke_style.num_dashes, sizeof (double)); + if (unlikely (gstate->stroke_style.dash == NULL)) { + gstate->stroke_style.num_dashes = 0; + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + on_total = off_total = dash_total = 0.0; + for (i = j = 0; i < num_dashes; i++) { + if (dash[i] < 0) + return _cairo_error (CAIRO_STATUS_INVALID_DASH); + + if (dash[i] == 0 && i > 0 && i < num_dashes - 1) { + if (dash[++i] < 0) + return _cairo_error (CAIRO_STATUS_INVALID_DASH); + + gstate->stroke_style.dash[j-1] += dash[i]; + gstate->stroke_style.num_dashes -= 2; + } else + gstate->stroke_style.dash[j++] = dash[i]; + + if (dash[i]) { + dash_total += dash[i]; + if ((i & 1) == 0) + on_total += dash[i]; + else + off_total += dash[i]; + } + } + + if (dash_total == 0.0) + return _cairo_error (CAIRO_STATUS_INVALID_DASH); + + /* An odd dash value indicate symmetric repeating, so the total + * is twice as long. */ + if (gstate->stroke_style.num_dashes & 1) { + dash_total *= 2; + on_total += off_total; + } + + if (dash_total - on_total < CAIRO_FIXED_ERROR_DOUBLE) { + /* Degenerate dash -> solid line */ + free (gstate->stroke_style.dash); + gstate->stroke_style.dash = NULL; + gstate->stroke_style.num_dashes = 0; + gstate->stroke_style.dash_offset = 0.0; + return CAIRO_STATUS_SUCCESS; + } + + /* The dashing code doesn't like a negative offset or a big positive + * offset, so we compute an equivalent offset which is guaranteed to be + * positive and less than twice the pattern length. */ + offset = fmod (offset, dash_total); + if (offset < 0.0) + offset += dash_total; + if (offset <= 0.0) /* Take care of -0 */ + offset = 0.0; + gstate->stroke_style.dash_offset = offset; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gstate_get_dash (cairo_gstate_t *gstate, + double *dashes, + int *num_dashes, + double *offset) +{ + if (dashes) { + memcpy (dashes, + gstate->stroke_style.dash, + sizeof (double) * gstate->stroke_style.num_dashes); + } + + if (num_dashes) + *num_dashes = gstate->stroke_style.num_dashes; + + if (offset) + *offset = gstate->stroke_style.dash_offset; +} + +cairo_status_t +_cairo_gstate_set_miter_limit (cairo_gstate_t *gstate, double limit) +{ + gstate->stroke_style.miter_limit = limit; + + return CAIRO_STATUS_SUCCESS; +} + +double +_cairo_gstate_get_miter_limit (cairo_gstate_t *gstate) +{ + return gstate->stroke_style.miter_limit; +} + +void +_cairo_gstate_get_matrix (cairo_gstate_t *gstate, cairo_matrix_t *matrix) +{ + *matrix = gstate->ctm; +} + +cairo_status_t +_cairo_gstate_translate (cairo_gstate_t *gstate, double tx, double ty) +{ + cairo_matrix_t tmp; + + if (! ISFINITE (tx) || ! ISFINITE (ty)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + _cairo_gstate_unset_scaled_font (gstate); + + cairo_matrix_init_translate (&tmp, tx, ty); + cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm); + gstate->is_identity = FALSE; + + /* paranoid check against gradual numerical instability */ + if (! _cairo_matrix_is_invertible (&gstate->ctm)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + cairo_matrix_init_translate (&tmp, -tx, -ty); + cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_scale (cairo_gstate_t *gstate, double sx, double sy) +{ + cairo_matrix_t tmp; + + if (sx * sy == 0.) /* either sx or sy is 0, or det == 0 due to underflow */ + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + if (! ISFINITE (sx) || ! ISFINITE (sy)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + _cairo_gstate_unset_scaled_font (gstate); + + cairo_matrix_init_scale (&tmp, sx, sy); + cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm); + gstate->is_identity = FALSE; + + /* paranoid check against gradual numerical instability */ + if (! _cairo_matrix_is_invertible (&gstate->ctm)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + cairo_matrix_init_scale (&tmp, 1/sx, 1/sy); + cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_rotate (cairo_gstate_t *gstate, double angle) +{ + cairo_matrix_t tmp; + + if (angle == 0.) + return CAIRO_STATUS_SUCCESS; + + if (! ISFINITE (angle)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + _cairo_gstate_unset_scaled_font (gstate); + + cairo_matrix_init_rotate (&tmp, angle); + cairo_matrix_multiply (&gstate->ctm, &tmp, &gstate->ctm); + gstate->is_identity = FALSE; + + /* paranoid check against gradual numerical instability */ + if (! _cairo_matrix_is_invertible (&gstate->ctm)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + cairo_matrix_init_rotate (&tmp, -angle); + cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_transform (cairo_gstate_t *gstate, + const cairo_matrix_t *matrix) +{ + cairo_matrix_t tmp; + cairo_status_t status; + + if (! _cairo_matrix_is_invertible (matrix)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + if (_cairo_matrix_is_identity (matrix)) + return CAIRO_STATUS_SUCCESS; + + tmp = *matrix; + status = cairo_matrix_invert (&tmp); + if (unlikely (status)) + return status; + + _cairo_gstate_unset_scaled_font (gstate); + + cairo_matrix_multiply (&gstate->ctm, matrix, &gstate->ctm); + cairo_matrix_multiply (&gstate->ctm_inverse, &gstate->ctm_inverse, &tmp); + gstate->is_identity = FALSE; + + /* paranoid check against gradual numerical instability */ + if (! _cairo_matrix_is_invertible (&gstate->ctm)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_set_matrix (cairo_gstate_t *gstate, + const cairo_matrix_t *matrix) +{ + cairo_status_t status; + + if (memcmp (matrix, &gstate->ctm, sizeof (cairo_matrix_t)) == 0) + return CAIRO_STATUS_SUCCESS; + + if (! _cairo_matrix_is_invertible (matrix)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + if (_cairo_matrix_is_identity (matrix)) { + _cairo_gstate_identity_matrix (gstate); + return CAIRO_STATUS_SUCCESS; + } + + _cairo_gstate_unset_scaled_font (gstate); + + gstate->ctm = *matrix; + gstate->ctm_inverse = *matrix; + status = cairo_matrix_invert (&gstate->ctm_inverse); + assert (status == CAIRO_STATUS_SUCCESS); + gstate->is_identity = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gstate_identity_matrix (cairo_gstate_t *gstate) +{ + if (_cairo_matrix_is_identity (&gstate->ctm)) + return; + + _cairo_gstate_unset_scaled_font (gstate); + + cairo_matrix_init_identity (&gstate->ctm); + cairo_matrix_init_identity (&gstate->ctm_inverse); + gstate->is_identity = _cairo_matrix_is_identity (&gstate->target->device_transform); +} + +void +_cairo_gstate_user_to_device (cairo_gstate_t *gstate, double *x, double *y) +{ + cairo_matrix_transform_point (&gstate->ctm, x, y); +} + +void +_cairo_gstate_user_to_device_distance (cairo_gstate_t *gstate, + double *dx, double *dy) +{ + cairo_matrix_transform_distance (&gstate->ctm, dx, dy); +} + +void +_cairo_gstate_device_to_user (cairo_gstate_t *gstate, double *x, double *y) +{ + cairo_matrix_transform_point (&gstate->ctm_inverse, x, y); +} + +void +_cairo_gstate_device_to_user_distance (cairo_gstate_t *gstate, + double *dx, double *dy) +{ + cairo_matrix_transform_distance (&gstate->ctm_inverse, dx, dy); +} + +void +_do_cairo_gstate_user_to_backend (cairo_gstate_t *gstate, double *x, double *y) +{ + cairo_matrix_transform_point (&gstate->ctm, x, y); + cairo_matrix_transform_point (&gstate->target->device_transform, x, y); +} + +void +_do_cairo_gstate_user_to_backend_distance (cairo_gstate_t *gstate, double *x, double *y) +{ + cairo_matrix_transform_distance (&gstate->ctm, x, y); + cairo_matrix_transform_distance (&gstate->target->device_transform, x, y); +} + +void +_do_cairo_gstate_backend_to_user (cairo_gstate_t *gstate, double *x, double *y) +{ + cairo_matrix_transform_point (&gstate->target->device_transform_inverse, x, y); + cairo_matrix_transform_point (&gstate->ctm_inverse, x, y); +} + +void +_do_cairo_gstate_backend_to_user_distance (cairo_gstate_t *gstate, double *x, double *y) +{ + cairo_matrix_transform_distance (&gstate->target->device_transform_inverse, x, y); + cairo_matrix_transform_distance (&gstate->ctm_inverse, x, y); +} + +void +_cairo_gstate_backend_to_user_rectangle (cairo_gstate_t *gstate, + double *x1, double *y1, + double *x2, double *y2, + cairo_bool_t *is_tight) +{ + cairo_matrix_t matrix_inverse; + + if (! _cairo_matrix_is_identity (&gstate->target->device_transform_inverse) || + ! _cairo_matrix_is_identity (&gstate->ctm_inverse)) + { + cairo_matrix_multiply (&matrix_inverse, + &gstate->target->device_transform_inverse, + &gstate->ctm_inverse); + _cairo_matrix_transform_bounding_box (&matrix_inverse, + x1, y1, x2, y2, is_tight); + } + + else + { + if (is_tight) + *is_tight = TRUE; + } +} + +/* XXX: NYI +cairo_status_t +_cairo_gstate_stroke_to_path (cairo_gstate_t *gstate) +{ + cairo_status_t status; + + _cairo_pen_init (&gstate); + return CAIRO_STATUS_SUCCESS; +} +*/ + +void +_cairo_gstate_path_extents (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double *x1, double *y1, + double *x2, double *y2) +{ + cairo_box_t box; + double px1, py1, px2, py2; + + if (_cairo_path_fixed_extents (path, &box)) { + px1 = _cairo_fixed_to_double (box.p1.x); + py1 = _cairo_fixed_to_double (box.p1.y); + px2 = _cairo_fixed_to_double (box.p2.x); + py2 = _cairo_fixed_to_double (box.p2.y); + + _cairo_gstate_backend_to_user_rectangle (gstate, + &px1, &py1, &px2, &py2, + NULL); + } else { + px1 = 0.0; + py1 = 0.0; + px2 = 0.0; + py2 = 0.0; + } + + if (x1) + *x1 = px1; + if (y1) + *y1 = py1; + if (x2) + *x2 = px2; + if (y2) + *y2 = py2; +} + +static void +_cairo_gstate_copy_pattern (cairo_pattern_t *pattern, + const cairo_pattern_t *original) +{ + /* First check if the we can replace the original with a much simpler + * pattern. For example, gradients that are uniform or just have a single + * stop can sometimes be replaced with a solid. + */ + + if (_cairo_pattern_is_clear (original)) { + _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, + CAIRO_COLOR_TRANSPARENT); + return; + } + + if (original->type == CAIRO_PATTERN_TYPE_LINEAR || + original->type == CAIRO_PATTERN_TYPE_RADIAL) + { + cairo_color_t color; + if (_cairo_gradient_pattern_is_solid ((cairo_gradient_pattern_t *) original, + NULL, + &color)) + { + _cairo_pattern_init_solid ((cairo_solid_pattern_t *) pattern, + &color); + return; + } + } + + _cairo_pattern_init_static_copy (pattern, original); +} + +static void +_cairo_gstate_copy_transformed_pattern (cairo_gstate_t *gstate, + cairo_pattern_t *pattern, + const cairo_pattern_t *original, + const cairo_matrix_t *ctm_inverse) +{ + _cairo_gstate_copy_pattern (pattern, original); + + /* apply device_transform first so that it is transformed by ctm_inverse */ + if (original->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surface_pattern; + cairo_surface_t *surface; + + surface_pattern = (cairo_surface_pattern_t *) original; + surface = surface_pattern->surface; + + if (_cairo_surface_has_device_transform (surface)) + _cairo_pattern_pretransform (pattern, &surface->device_transform); + } + + if (! _cairo_matrix_is_identity (ctm_inverse)) + _cairo_pattern_transform (pattern, ctm_inverse); + + if (_cairo_surface_has_device_transform (gstate->target)) { + _cairo_pattern_transform (pattern, + &gstate->target->device_transform_inverse); + } +} + +static void +_cairo_gstate_copy_transformed_source (cairo_gstate_t *gstate, + cairo_pattern_t *pattern) +{ + _cairo_gstate_copy_transformed_pattern (gstate, pattern, + gstate->source, + &gstate->source_ctm_inverse); +} + +static void +_cairo_gstate_copy_transformed_mask (cairo_gstate_t *gstate, + cairo_pattern_t *pattern, + cairo_pattern_t *mask) +{ + _cairo_gstate_copy_transformed_pattern (gstate, pattern, + mask, + &gstate->ctm_inverse); +} + +static cairo_operator_t +_reduce_op (cairo_gstate_t *gstate) +{ + cairo_operator_t op; + const cairo_pattern_t *pattern; + + op = gstate->op; + if (op != CAIRO_OPERATOR_SOURCE) + return op; + + pattern = gstate->source; + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { + const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; + if (solid->color.alpha_short <= 0x00ff) { + op = CAIRO_OPERATOR_CLEAR; + } else if ((gstate->target->content & CAIRO_CONTENT_ALPHA) == 0) { + if ((solid->color.red_short | + solid->color.green_short | + solid->color.blue_short) <= 0x00ff) + { + op = CAIRO_OPERATOR_CLEAR; + } + } + } else if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + const cairo_surface_pattern_t *surface = (cairo_surface_pattern_t *) pattern; + if (surface->surface->is_clear && + surface->surface->content & CAIRO_CONTENT_ALPHA) + { + op = CAIRO_OPERATOR_CLEAR; + } + } else { + const cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern; + if (gradient->n_stops == 0) + op = CAIRO_OPERATOR_CLEAR; + } + + return op; +} + +static cairo_status_t +_cairo_gstate_get_pattern_status (const cairo_pattern_t *pattern) +{ + if (unlikely (pattern->type == CAIRO_PATTERN_TYPE_MESH && + ((const cairo_mesh_pattern_t *) pattern)->current_patch)) + { + /* If current patch != NULL, the pattern is under construction + * and cannot be used as a source */ + return CAIRO_STATUS_INVALID_MESH_CONSTRUCTION; + } + + return pattern->status; +} + +cairo_status_t +_cairo_gstate_paint (cairo_gstate_t *gstate) +{ + cairo_pattern_union_t source_pattern; + const cairo_pattern_t *pattern; + cairo_status_t status; + cairo_operator_t op; + + status = _cairo_gstate_get_pattern_status (gstate->source); + if (unlikely (status)) + return status; + + if (gstate->op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_clip_is_all_clipped (gstate->clip)) + return CAIRO_STATUS_SUCCESS; + + op = _reduce_op (gstate); + if (op == CAIRO_OPERATOR_CLEAR) { + pattern = &_cairo_pattern_clear.base; + } else { + _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); + pattern = &source_pattern.base; + } + + return _cairo_surface_paint (gstate->target, + op, pattern, + gstate->clip); +} + +cairo_status_t +_cairo_gstate_mask (cairo_gstate_t *gstate, + cairo_pattern_t *mask) +{ + cairo_pattern_union_t source_pattern, mask_pattern; + const cairo_pattern_t *source; + cairo_operator_t op; + cairo_status_t status; + + status = _cairo_gstate_get_pattern_status (mask); + if (unlikely (status)) + return status; + + status = _cairo_gstate_get_pattern_status (gstate->source); + if (unlikely (status)) + return status; + + if (gstate->op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_clip_is_all_clipped (gstate->clip)) + return CAIRO_STATUS_SUCCESS; + + assert (gstate->opacity == 1.0); + + if (_cairo_pattern_is_opaque (mask, NULL)) + return _cairo_gstate_paint (gstate); + + if (_cairo_pattern_is_clear (mask) && + _cairo_operator_bounded_by_mask (gstate->op)) + { + return CAIRO_STATUS_SUCCESS; + } + + op = _reduce_op (gstate); + if (op == CAIRO_OPERATOR_CLEAR) { + source = &_cairo_pattern_clear.base; + } else { + _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); + source = &source_pattern.base; + } + _cairo_gstate_copy_transformed_mask (gstate, &mask_pattern.base, mask); + + if (source->type == CAIRO_PATTERN_TYPE_SOLID && + mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && + _cairo_operator_bounded_by_source (op)) + { + const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) source; + cairo_color_t combined; + + if (mask_pattern.base.has_component_alpha) { +#define M(R, A, B, c) R.c = A.c * B.c + M(combined, solid->color, mask_pattern.solid.color, red); + M(combined, solid->color, mask_pattern.solid.color, green); + M(combined, solid->color, mask_pattern.solid.color, blue); + M(combined, solid->color, mask_pattern.solid.color, alpha); +#undef M + } else { + combined = solid->color; + _cairo_color_multiply_alpha (&combined, mask_pattern.solid.color.alpha); + } + + _cairo_pattern_init_solid (&source_pattern.solid, &combined); + + status = _cairo_surface_paint (gstate->target, op, + &source_pattern.base, + gstate->clip); + } + else + { + status = _cairo_surface_mask (gstate->target, op, + source, + &mask_pattern.base, + gstate->clip); + } + + return status; +} + +cairo_status_t +_cairo_gstate_stroke (cairo_gstate_t *gstate, cairo_path_fixed_t *path) +{ + cairo_pattern_union_t source_pattern; + cairo_stroke_style_t style; + double dash[2]; + cairo_status_t status; + cairo_matrix_t aggregate_transform; + cairo_matrix_t aggregate_transform_inverse; + + status = _cairo_gstate_get_pattern_status (gstate->source); + if (unlikely (status)) + return status; + + if (gstate->op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (gstate->stroke_style.line_width <= 0.0) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_clip_is_all_clipped (gstate->clip)) + return CAIRO_STATUS_SUCCESS; + + assert (gstate->opacity == 1.0); + + cairo_matrix_multiply (&aggregate_transform, + &gstate->ctm, + &gstate->target->device_transform); + cairo_matrix_multiply (&aggregate_transform_inverse, + &gstate->target->device_transform_inverse, + &gstate->ctm_inverse); + + memcpy (&style, &gstate->stroke_style, sizeof (gstate->stroke_style)); + if (_cairo_stroke_style_dash_can_approximate (&gstate->stroke_style, &aggregate_transform, gstate->tolerance)) { + style.dash = dash; + _cairo_stroke_style_dash_approximate (&gstate->stroke_style, &gstate->ctm, gstate->tolerance, + &style.dash_offset, + style.dash, + &style.num_dashes); + } + + _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); + + return _cairo_surface_stroke (gstate->target, + gstate->op, + &source_pattern.base, + path, + &style, + &aggregate_transform, + &aggregate_transform_inverse, + gstate->tolerance, + gstate->antialias, + gstate->clip); +} + +cairo_status_t +_cairo_gstate_in_stroke (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double x, + double y, + cairo_bool_t *inside_ret) +{ + cairo_status_t status; + cairo_rectangle_int_t extents; + cairo_box_t limit; + cairo_traps_t traps; + + if (gstate->stroke_style.line_width <= 0.0) { + *inside_ret = FALSE; + return CAIRO_STATUS_SUCCESS; + } + + _cairo_gstate_user_to_backend (gstate, &x, &y); + + /* Before we perform the expensive stroke analysis, + * check whether the point is within the extents of the path. + */ + _cairo_path_fixed_approximate_stroke_extents (path, + &gstate->stroke_style, + &gstate->ctm, + &extents); + if (x < extents.x || x > extents.x + extents.width || + y < extents.y || y > extents.y + extents.height) + { + *inside_ret = FALSE; + return CAIRO_STATUS_SUCCESS; + } + + limit.p1.x = _cairo_fixed_from_double (x) - 1; + limit.p1.y = _cairo_fixed_from_double (y) - 1; + limit.p2.x = limit.p1.x + 2; + limit.p2.y = limit.p1.y + 2; + + _cairo_traps_init (&traps); + _cairo_traps_limit (&traps, &limit, 1); + + status = _cairo_path_fixed_stroke_polygon_to_traps (path, + &gstate->stroke_style, + &gstate->ctm, + &gstate->ctm_inverse, + gstate->tolerance, + &traps); + if (unlikely (status)) + goto BAIL; + + *inside_ret = _cairo_traps_contain (&traps, x, y); + +BAIL: + _cairo_traps_fini (&traps); + + return status; +} + +cairo_status_t +_cairo_gstate_fill (cairo_gstate_t *gstate, cairo_path_fixed_t *path) +{ + cairo_status_t status; + + status = _cairo_gstate_get_pattern_status (gstate->source); + if (unlikely (status)) + return status; + + if (gstate->op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_clip_is_all_clipped (gstate->clip)) + return CAIRO_STATUS_SUCCESS; + + assert (gstate->opacity == 1.0); + + if (_cairo_path_fixed_fill_is_empty (path)) { + if (_cairo_operator_bounded_by_mask (gstate->op)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_paint (gstate->target, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + gstate->clip); + } else { + cairo_pattern_union_t source_pattern; + const cairo_pattern_t *pattern; + cairo_operator_t op; + cairo_rectangle_int_t extents; + cairo_box_t box; + + op = _reduce_op (gstate); + if (op == CAIRO_OPERATOR_CLEAR) { + pattern = &_cairo_pattern_clear.base; + } else { + _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); + pattern = &source_pattern.base; + } + + /* Toolkits often paint the entire background with a fill */ + if (_cairo_surface_get_extents (gstate->target, &extents) && + _cairo_path_fixed_is_box (path, &box) && + box.p1.x <= _cairo_fixed_from_int (extents.x) && + box.p1.y <= _cairo_fixed_from_int (extents.y) && + box.p2.x >= _cairo_fixed_from_int (extents.x + extents.width) && + box.p2.y >= _cairo_fixed_from_int (extents.y + extents.height)) + { + status = _cairo_surface_paint (gstate->target, op, pattern, + gstate->clip); + } + else + { + status = _cairo_surface_fill (gstate->target, op, pattern, + path, + gstate->fill_rule, + gstate->tolerance, + gstate->antialias, + gstate->clip); + } + } + + return status; +} + +cairo_bool_t +_cairo_gstate_in_fill (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double x, + double y) +{ + _cairo_gstate_user_to_backend (gstate, &x, &y); + + return _cairo_path_fixed_in_fill (path, + gstate->fill_rule, + gstate->tolerance, + x, y); +} + +cairo_bool_t +_cairo_gstate_in_clip (cairo_gstate_t *gstate, + double x, + double y) +{ + cairo_clip_t *clip = gstate->clip; + int i; + + if (_cairo_clip_is_all_clipped (clip)) + return FALSE; + + if (clip == NULL) + return TRUE; + + _cairo_gstate_user_to_backend (gstate, &x, &y); + + if (x < clip->extents.x || + x >= clip->extents.x + clip->extents.width || + y < clip->extents.y || + y >= clip->extents.y + clip->extents.height) + { + return FALSE; + } + + if (clip->num_boxes) { + int fx, fy; + + fx = _cairo_fixed_from_double (x); + fy = _cairo_fixed_from_double (y); + for (i = 0; i < clip->num_boxes; i++) { + if (fx >= clip->boxes[i].p1.x && fx <= clip->boxes[i].p2.x && + fy >= clip->boxes[i].p1.y && fy <= clip->boxes[i].p2.y) + break; + } + if (i == clip->num_boxes) + return FALSE; + } + + if (clip->path) { + cairo_clip_path_t *clip_path = clip->path; + do { + if (! _cairo_path_fixed_in_fill (&clip_path->path, + clip_path->fill_rule, + clip_path->tolerance, + x, y)) + return FALSE; + } while ((clip_path = clip_path->prev) != NULL); + } + + return TRUE; +} + +cairo_status_t +_cairo_gstate_copy_page (cairo_gstate_t *gstate) +{ + cairo_surface_copy_page (gstate->target); + return cairo_surface_status (gstate->target); +} + +cairo_status_t +_cairo_gstate_show_page (cairo_gstate_t *gstate) +{ + cairo_surface_show_page (gstate->target); + return cairo_surface_status (gstate->target); +} + +static void +_cairo_gstate_extents_to_user_rectangle (cairo_gstate_t *gstate, + const cairo_box_t *extents, + double *x1, double *y1, + double *x2, double *y2) +{ + double px1, py1, px2, py2; + + px1 = _cairo_fixed_to_double (extents->p1.x); + py1 = _cairo_fixed_to_double (extents->p1.y); + px2 = _cairo_fixed_to_double (extents->p2.x); + py2 = _cairo_fixed_to_double (extents->p2.y); + + _cairo_gstate_backend_to_user_rectangle (gstate, + &px1, &py1, &px2, &py2, + NULL); + if (x1) + *x1 = px1; + if (y1) + *y1 = py1; + if (x2) + *x2 = px2; + if (y2) + *y2 = py2; +} + +cairo_status_t +_cairo_gstate_stroke_extents (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double *x1, double *y1, + double *x2, double *y2) +{ + cairo_int_status_t status; + cairo_box_t extents; + cairo_bool_t empty; + + if (x1) + *x1 = 0.0; + if (y1) + *y1 = 0.0; + if (x2) + *x2 = 0.0; + if (y2) + *y2 = 0.0; + + if (gstate->stroke_style.line_width <= 0.0) + return CAIRO_STATUS_SUCCESS; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_stroke_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init (&boxes); + status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, + &gstate->stroke_style, + &gstate->ctm, + gstate->antialias, + &boxes); + empty = boxes.num_boxes == 0; + if (! empty) + _cairo_boxes_extents (&boxes, &extents); + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_polygon_t polygon; + + _cairo_polygon_init (&polygon, NULL, 0); + status = _cairo_path_fixed_stroke_to_polygon (path, + &gstate->stroke_style, + &gstate->ctm, + &gstate->ctm_inverse, + gstate->tolerance, + &polygon); + empty = polygon.num_edges == 0; + if (! empty) + extents = polygon.extents; + _cairo_polygon_fini (&polygon); + } + if (! empty) { + _cairo_gstate_extents_to_user_rectangle (gstate, &extents, + x1, y1, x2, y2); + } + + return status; +} + +cairo_status_t +_cairo_gstate_fill_extents (cairo_gstate_t *gstate, + cairo_path_fixed_t *path, + double *x1, double *y1, + double *x2, double *y2) +{ + cairo_status_t status; + cairo_box_t extents; + cairo_bool_t empty; + + if (x1) + *x1 = 0.0; + if (y1) + *y1 = 0.0; + if (x2) + *x2 = 0.0; + if (y2) + *y2 = 0.0; + + if (_cairo_path_fixed_fill_is_empty (path)) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_path_fixed_fill_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init (&boxes); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + gstate->fill_rule, + gstate->antialias, + &boxes); + empty = boxes.num_boxes == 0; + if (! empty) + _cairo_boxes_extents (&boxes, &extents); + + _cairo_boxes_fini (&boxes); + } else { + cairo_traps_t traps; + + _cairo_traps_init (&traps); + + status = _cairo_path_fixed_fill_to_traps (path, + gstate->fill_rule, + gstate->tolerance, + &traps); + empty = traps.num_traps == 0; + if (! empty) + _cairo_traps_extents (&traps, &extents); + + _cairo_traps_fini (&traps); + } + + if (! empty) { + _cairo_gstate_extents_to_user_rectangle (gstate, &extents, + x1, y1, x2, y2); + } + + return status; +} + +cairo_status_t +_cairo_gstate_reset_clip (cairo_gstate_t *gstate) +{ + _cairo_clip_destroy (gstate->clip); + gstate->clip = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path) +{ + gstate->clip = + _cairo_clip_intersect_path (gstate->clip, + path, + gstate->fill_rule, + gstate->tolerance, + gstate->antialias); + /* XXX */ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_gstate_int_clip_extents (cairo_gstate_t *gstate, + cairo_rectangle_int_t *extents) +{ + cairo_bool_t is_bounded; + + is_bounded = _cairo_surface_get_extents (gstate->target, extents); + + if (gstate->clip) { + _cairo_rectangle_intersect (extents, + _cairo_clip_get_extents (gstate->clip)); + is_bounded = TRUE; + } + + return is_bounded; +} + +cairo_bool_t +_cairo_gstate_clip_extents (cairo_gstate_t *gstate, + double *x1, + double *y1, + double *x2, + double *y2) +{ + cairo_rectangle_int_t extents; + double px1, py1, px2, py2; + + if (! _cairo_gstate_int_clip_extents (gstate, &extents)) + return FALSE; + + px1 = extents.x; + py1 = extents.y; + px2 = extents.x + (int) extents.width; + py2 = extents.y + (int) extents.height; + + _cairo_gstate_backend_to_user_rectangle (gstate, + &px1, &py1, &px2, &py2, + NULL); + + if (x1) + *x1 = px1; + if (y1) + *y1 = py1; + if (x2) + *x2 = px2; + if (y2) + *y2 = py2; + + return TRUE; +} + +cairo_rectangle_list_t* +_cairo_gstate_copy_clip_rectangle_list (cairo_gstate_t *gstate) +{ + cairo_rectangle_int_t extents; + cairo_rectangle_list_t *list; + cairo_clip_t *clip; + + if (_cairo_surface_get_extents (gstate->target, &extents)) + clip = _cairo_clip_copy_intersect_rectangle (gstate->clip, &extents); + else + clip = gstate->clip; + + list = _cairo_clip_copy_rectangle_list (clip, gstate); + + if (clip != gstate->clip) + _cairo_clip_destroy (clip); + + return list; +} + +static void +_cairo_gstate_unset_scaled_font (cairo_gstate_t *gstate) +{ + if (gstate->scaled_font == NULL) + return; + + if (gstate->previous_scaled_font != NULL) + cairo_scaled_font_destroy (gstate->previous_scaled_font); + + gstate->previous_scaled_font = gstate->scaled_font; + gstate->scaled_font = NULL; +} + +cairo_status_t +_cairo_gstate_set_font_size (cairo_gstate_t *gstate, + double size) +{ + _cairo_gstate_unset_scaled_font (gstate); + + cairo_matrix_init_scale (&gstate->font_matrix, size, size); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_set_font_matrix (cairo_gstate_t *gstate, + const cairo_matrix_t *matrix) +{ + if (memcmp (matrix, &gstate->font_matrix, sizeof (cairo_matrix_t)) == 0) + return CAIRO_STATUS_SUCCESS; + + _cairo_gstate_unset_scaled_font (gstate); + + gstate->font_matrix = *matrix; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_gstate_get_font_matrix (cairo_gstate_t *gstate, + cairo_matrix_t *matrix) +{ + *matrix = gstate->font_matrix; +} + +void +_cairo_gstate_set_font_options (cairo_gstate_t *gstate, + const cairo_font_options_t *options) +{ + if (memcmp (options, &gstate->font_options, sizeof (cairo_font_options_t)) == 0) + return; + + _cairo_gstate_unset_scaled_font (gstate); + + _cairo_font_options_init_copy (&gstate->font_options, options); +} + +void +_cairo_gstate_get_font_options (cairo_gstate_t *gstate, + cairo_font_options_t *options) +{ + *options = gstate->font_options; +} + +cairo_status_t +_cairo_gstate_get_font_face (cairo_gstate_t *gstate, + cairo_font_face_t **font_face) +{ + cairo_status_t status; + + status = _cairo_gstate_ensure_font_face (gstate); + if (unlikely (status)) + return status; + + *font_face = gstate->font_face; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_get_scaled_font (cairo_gstate_t *gstate, + cairo_scaled_font_t **scaled_font) +{ + cairo_status_t status; + + status = _cairo_gstate_ensure_scaled_font (gstate); + if (unlikely (status)) + return status; + + *scaled_font = gstate->scaled_font; + + return CAIRO_STATUS_SUCCESS; +} + +/* + * Like everything else in this file, fonts involve Too Many Coordinate Spaces; + * it is easy to get confused about what's going on. + * + * The user's view + * --------------- + * + * Users ask for things in user space. When cairo starts, a user space unit + * is about 1/96 inch, which is similar to (but importantly different from) + * the normal "point" units most users think in terms of. When a user + * selects a font, its scale is set to "one user unit". The user can then + * independently scale the user coordinate system *or* the font matrix, in + * order to adjust the rendered size of the font. + * + * Metrics are returned in user space, whether they are obtained from + * the currently selected font in a #cairo_t or from a #cairo_scaled_font_t + * which is a font specialized to a particular scale matrix, CTM, and target + * surface. + * + * The font's view + * --------------- + * + * Fonts are designed and stored (in say .ttf files) in "font space", which + * describes an "EM Square" (a design tile) and has some abstract number + * such as 1000, 1024, or 2048 units per "EM". This is basically an + * uninteresting space for us, but we need to remember that it exists. + * + * Font resources (from libraries or operating systems) render themselves + * to a particular device. Since they do not want to make most programmers + * worry about the font design space, the scaling API is simplified to + * involve just telling the font the required pixel size of the EM square + * (that is, in device space). + * + * + * Cairo's gstate view + * ------------------- + * + * In addition to the CTM and CTM inverse, we keep a matrix in the gstate + * called the "font matrix" which describes the user's most recent + * font-scaling or font-transforming request. This is kept in terms of an + * abstract scale factor, composed with the CTM and used to set the font's + * pixel size. So if the user asks to "scale the font by 12", the matrix + * is: + * + * [ 12.0, 0.0, 0.0, 12.0, 0.0, 0.0 ] + * + * It is an affine matrix, like all cairo matrices, where its tx and ty + * components are used to "nudging" fonts around and are handled in gstate + * and then ignored by the "scaled-font" layer. + * + * In order to perform any action on a font, we must build an object + * called a #cairo_font_scale_t; this contains the central 2x2 matrix + * resulting from "font matrix * CTM" (sans the font matrix translation + * components as stated in the previous paragraph). + * + * We pass this to the font when making requests of it, which causes it to + * reply for a particular [user request, device] combination, under the CTM + * (to accommodate the "zoom in" == "bigger fonts" issue above). + * + * The other terms in our communication with the font are therefore in + * device space. When we ask it to perform text->glyph conversion, it will + * produce a glyph string in device space. Glyph vectors we pass to it for + * measuring or rendering should be in device space. The metrics which we + * get back from the font will be in device space. The contents of the + * global glyph image cache will be in device space. + * + * + * Cairo's public view + * ------------------- + * + * Since the values entering and leaving via public API calls are in user + * space, the gstate functions typically need to multiply arguments by the + * CTM (for user-input glyph vectors), and return values by the CTM inverse + * (for font responses such as metrics or glyph vectors). + * + */ + +static cairo_status_t +_cairo_gstate_ensure_font_face (cairo_gstate_t *gstate) +{ + cairo_font_face_t *font_face; + + if (gstate->font_face != NULL) + return gstate->font_face->status; + + + font_face = cairo_toy_font_face_create (CAIRO_FONT_FAMILY_DEFAULT, + CAIRO_FONT_SLANT_DEFAULT, + CAIRO_FONT_WEIGHT_DEFAULT); + if (font_face->status) + return font_face->status; + + gstate->font_face = font_face; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_gstate_ensure_scaled_font (cairo_gstate_t *gstate) +{ + cairo_status_t status; + cairo_font_options_t options; + cairo_scaled_font_t *scaled_font; + cairo_matrix_t font_ctm; + + if (gstate->scaled_font != NULL) + return gstate->scaled_font->status; + + status = _cairo_gstate_ensure_font_face (gstate); + if (unlikely (status)) + return status; + + cairo_surface_get_font_options (gstate->target, &options); + cairo_font_options_merge (&options, &gstate->font_options); + + cairo_matrix_multiply (&font_ctm, + &gstate->ctm, + &gstate->target->device_transform); + + scaled_font = cairo_scaled_font_create (gstate->font_face, + &gstate->font_matrix, + &font_ctm, + &options); + + status = cairo_scaled_font_status (scaled_font); + if (unlikely (status)) + return status; + + gstate->scaled_font = scaled_font; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_get_font_extents (cairo_gstate_t *gstate, + cairo_font_extents_t *extents) +{ + cairo_status_t status = _cairo_gstate_ensure_scaled_font (gstate); + if (unlikely (status)) + return status; + + cairo_scaled_font_extents (gstate->scaled_font, extents); + + return cairo_scaled_font_status (gstate->scaled_font); +} + +cairo_status_t +_cairo_gstate_set_font_face (cairo_gstate_t *gstate, + cairo_font_face_t *font_face) +{ + if (font_face && font_face->status) + return _cairo_error (font_face->status); + + if (font_face == gstate->font_face) + return CAIRO_STATUS_SUCCESS; + + cairo_font_face_destroy (gstate->font_face); + gstate->font_face = cairo_font_face_reference (font_face); + + _cairo_gstate_unset_scaled_font (gstate); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_glyph_extents (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents) +{ + cairo_status_t status; + + status = _cairo_gstate_ensure_scaled_font (gstate); + if (unlikely (status)) + return status; + + cairo_scaled_font_glyph_extents (gstate->scaled_font, + glyphs, num_glyphs, + extents); + + return cairo_scaled_font_status (gstate->scaled_font); +} + +cairo_status_t +_cairo_gstate_show_text_glyphs (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_glyph_text_info_t *info) +{ + cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; + cairo_text_cluster_t stack_transformed_clusters[CAIRO_STACK_ARRAY_LENGTH (cairo_text_cluster_t)]; + cairo_pattern_union_t source_pattern; + cairo_glyph_t *transformed_glyphs; + const cairo_pattern_t *pattern; + cairo_text_cluster_t *transformed_clusters; + cairo_operator_t op; + cairo_status_t status; + + status = _cairo_gstate_get_pattern_status (gstate->source); + if (unlikely (status)) + return status; + + if (gstate->op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_clip_is_all_clipped (gstate->clip)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_gstate_ensure_scaled_font (gstate); + if (unlikely (status)) + return status; + + transformed_glyphs = stack_transformed_glyphs; + transformed_clusters = stack_transformed_clusters; + + if (num_glyphs > ARRAY_LENGTH (stack_transformed_glyphs)) { + transformed_glyphs = cairo_glyph_allocate (num_glyphs); + if (unlikely (transformed_glyphs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + if (info != NULL) { + if (info->num_clusters > ARRAY_LENGTH (stack_transformed_clusters)) { + transformed_clusters = cairo_text_cluster_allocate (info->num_clusters); + if (unlikely (transformed_clusters == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_GLYPHS; + } + } + + _cairo_gstate_transform_glyphs_to_backend (gstate, + glyphs, num_glyphs, + info->clusters, + info->num_clusters, + info->cluster_flags, + transformed_glyphs, + &num_glyphs, + transformed_clusters); + } else { + _cairo_gstate_transform_glyphs_to_backend (gstate, + glyphs, num_glyphs, + NULL, 0, 0, + transformed_glyphs, + &num_glyphs, + NULL); + } + + if (num_glyphs == 0) + goto CLEANUP_GLYPHS; + + op = _reduce_op (gstate); + if (op == CAIRO_OPERATOR_CLEAR) { + pattern = &_cairo_pattern_clear.base; + } else { + _cairo_gstate_copy_transformed_source (gstate, &source_pattern.base); + pattern = &source_pattern.base; + } + + /* For really huge font sizes, we can just do path;fill instead of + * show_glyphs, as show_glyphs would put excess pressure on the cache, + * and moreover, not all components below us correctly handle huge font + * sizes. I wanted to set the limit at 256. But alas, seems like cairo's + * rasterizer is something like ten times slower than freetype's for huge + * sizes. So, no win just yet. For now, do it for insanely-huge sizes, + * just to make sure we don't make anyone unhappy. When we get a really + * fast rasterizer in cairo, we may want to readjust this. + * + * Needless to say, do this only if show_text_glyphs is not available. */ + if (cairo_surface_has_show_text_glyphs (gstate->target) || + _cairo_scaled_font_get_max_scale (gstate->scaled_font) <= 10240) + { + + if (info != NULL) { + status = _cairo_surface_show_text_glyphs (gstate->target, op, pattern, + info->utf8, info->utf8_len, + transformed_glyphs, num_glyphs, + transformed_clusters, info->num_clusters, + info->cluster_flags, + gstate->scaled_font, + gstate->clip); + } else { + status = _cairo_surface_show_text_glyphs (gstate->target, op, pattern, + NULL, 0, + transformed_glyphs, num_glyphs, + NULL, 0, 0, + gstate->scaled_font, + gstate->clip); + } + } + else + { + cairo_path_fixed_t path; + + _cairo_path_fixed_init (&path); + + status = _cairo_scaled_font_glyph_path (gstate->scaled_font, + transformed_glyphs, num_glyphs, + &path); + + if (status == CAIRO_STATUS_SUCCESS) { + status = _cairo_surface_fill (gstate->target, op, pattern, + &path, + CAIRO_FILL_RULE_WINDING, + gstate->tolerance, + gstate->scaled_font->options.antialias, + gstate->clip); + } + + _cairo_path_fixed_fini (&path); + } + +CLEANUP_GLYPHS: + if (transformed_glyphs != stack_transformed_glyphs) + cairo_glyph_free (transformed_glyphs); + if (transformed_clusters != stack_transformed_clusters) + cairo_text_cluster_free (transformed_clusters); + + return status; +} + +cairo_status_t +_cairo_gstate_glyph_path (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_path_fixed_t *path) +{ + cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; + cairo_glyph_t *transformed_glyphs; + cairo_status_t status; + + status = _cairo_gstate_ensure_scaled_font (gstate); + if (unlikely (status)) + return status; + + if (num_glyphs < ARRAY_LENGTH (stack_transformed_glyphs)) { + transformed_glyphs = stack_transformed_glyphs; + } else { + transformed_glyphs = cairo_glyph_allocate (num_glyphs); + if (unlikely (transformed_glyphs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_gstate_transform_glyphs_to_backend (gstate, + glyphs, num_glyphs, + NULL, 0, 0, + transformed_glyphs, + &num_glyphs, NULL); + + status = _cairo_scaled_font_glyph_path (gstate->scaled_font, + transformed_glyphs, num_glyphs, + path); + + if (transformed_glyphs != stack_transformed_glyphs) + cairo_glyph_free (transformed_glyphs); + + return status; +} + +cairo_status_t +_cairo_gstate_set_antialias (cairo_gstate_t *gstate, + cairo_antialias_t antialias) +{ + gstate->antialias = antialias; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_antialias_t +_cairo_gstate_get_antialias (cairo_gstate_t *gstate) +{ + return gstate->antialias; +} + +/** + * _cairo_gstate_transform_glyphs_to_backend: + * @gstate: a #cairo_gstate_t + * @glyphs: the array of #cairo_glyph_t objects to be transformed + * @num_glyphs: the number of elements in @glyphs + * @transformed_glyphs: a pre-allocated array of at least @num_glyphs + * #cairo_glyph_t objects + * @num_transformed_glyphs: the number of elements in @transformed_glyphs + * after dropping out of bounds glyphs, or %NULL if glyphs shouldn't be + * dropped + * + * Transform an array of glyphs to backend space by first adding the offset + * of the font matrix, then transforming from user space to backend space. + * The result of the transformation is placed in @transformed_glyphs. + * + * This also uses information from the scaled font and the surface to + * cull/drop glyphs that will not be visible. + **/ +static void +_cairo_gstate_transform_glyphs_to_backend (cairo_gstate_t *gstate, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_glyph_t *transformed_glyphs, + int *num_transformed_glyphs, + cairo_text_cluster_t *transformed_clusters) +{ + cairo_rectangle_int_t surface_extents; + cairo_matrix_t *ctm = &gstate->ctm; + cairo_matrix_t *font_matrix = &gstate->font_matrix; + cairo_matrix_t *device_transform = &gstate->target->device_transform; + cairo_bool_t drop = FALSE; + double x1 = 0, x2 = 0, y1 = 0, y2 = 0; + int i, j, k; + + drop = TRUE; + if (! _cairo_gstate_int_clip_extents (gstate, &surface_extents)) { + drop = FALSE; /* unbounded surface */ + } else { + double scale10 = 10 * _cairo_scaled_font_get_max_scale (gstate->scaled_font); + if (surface_extents.width == 0 || surface_extents.height == 0) { + /* No visible area. Don't draw anything */ + *num_transformed_glyphs = 0; + return; + } + /* XXX We currently drop any glyphs that has its position outside + * of the surface boundaries by a safety margin depending on the + * font scale. This however can fail in extreme cases where the + * font has really long swashes for example... We can correctly + * handle that by looking the glyph up and using its device bbox + * to device if it's going to be visible, but I'm not inclined to + * do that now. + */ + x1 = surface_extents.x - scale10; + y1 = surface_extents.y - scale10; + x2 = surface_extents.x + (int) surface_extents.width + scale10; + y2 = surface_extents.y + (int) surface_extents.height + scale10; + } + + if (!drop) + *num_transformed_glyphs = num_glyphs; + +#define KEEP_GLYPH(glyph) (x1 <= glyph.x && glyph.x <= x2 && y1 <= glyph.y && glyph.y <= y2) + + j = 0; + if (_cairo_matrix_is_identity (ctm) && + _cairo_matrix_is_identity (device_transform) && + font_matrix->x0 == 0 && font_matrix->y0 == 0) + { + if (! drop) { + memcpy (transformed_glyphs, glyphs, + num_glyphs * sizeof (cairo_glyph_t)); + memcpy (transformed_clusters, clusters, + num_clusters * sizeof (cairo_text_cluster_t)); + j = num_glyphs; + } else if (num_clusters == 0) { + for (i = 0; i < num_glyphs; i++) { + transformed_glyphs[j].index = glyphs[i].index; + transformed_glyphs[j].x = glyphs[i].x; + transformed_glyphs[j].y = glyphs[i].y; + if (KEEP_GLYPH (transformed_glyphs[j])) + j++; + } + } else { + const cairo_glyph_t *cur_glyph; + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph = glyphs + num_glyphs - 1; + else + cur_glyph = glyphs; + + for (i = 0; i < num_clusters; i++) { + cairo_bool_t cluster_visible = FALSE; + + for (k = 0; k < clusters[i].num_glyphs; k++) { + transformed_glyphs[j+k].index = cur_glyph->index; + transformed_glyphs[j+k].x = cur_glyph->x; + transformed_glyphs[j+k].y = cur_glyph->y; + if (KEEP_GLYPH (transformed_glyphs[j+k])) + cluster_visible = TRUE; + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph--; + else + cur_glyph++; + } + + transformed_clusters[i] = clusters[i]; + if (cluster_visible) + j += k; + else + transformed_clusters[i].num_glyphs = 0; + } + } + } + else if (_cairo_matrix_is_translation (ctm) && + _cairo_matrix_is_translation (device_transform)) + { + double tx = font_matrix->x0 + ctm->x0 + device_transform->x0; + double ty = font_matrix->y0 + ctm->y0 + device_transform->y0; + + if (! drop || num_clusters == 0) { + for (i = 0; i < num_glyphs; i++) { + transformed_glyphs[j].index = glyphs[i].index; + transformed_glyphs[j].x = glyphs[i].x + tx; + transformed_glyphs[j].y = glyphs[i].y + ty; + if (!drop || KEEP_GLYPH (transformed_glyphs[j])) + j++; + } + memcpy (transformed_clusters, clusters, + num_clusters * sizeof (cairo_text_cluster_t)); + } else { + const cairo_glyph_t *cur_glyph; + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph = glyphs + num_glyphs - 1; + else + cur_glyph = glyphs; + + for (i = 0; i < num_clusters; i++) { + cairo_bool_t cluster_visible = FALSE; + + for (k = 0; k < clusters[i].num_glyphs; k++) { + transformed_glyphs[j+k].index = cur_glyph->index; + transformed_glyphs[j+k].x = cur_glyph->x + tx; + transformed_glyphs[j+k].y = cur_glyph->y + ty; + if (KEEP_GLYPH (transformed_glyphs[j+k])) + cluster_visible = TRUE; + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph--; + else + cur_glyph++; + } + + transformed_clusters[i] = clusters[i]; + if (cluster_visible) + j += k; + else + transformed_clusters[i].num_glyphs = 0; + } + } + } + else + { + cairo_matrix_t aggregate_transform; + + cairo_matrix_init_translate (&aggregate_transform, + gstate->font_matrix.x0, + gstate->font_matrix.y0); + cairo_matrix_multiply (&aggregate_transform, + &aggregate_transform, ctm); + cairo_matrix_multiply (&aggregate_transform, + &aggregate_transform, device_transform); + + if (! drop || num_clusters == 0) { + for (i = 0; i < num_glyphs; i++) { + transformed_glyphs[j] = glyphs[i]; + cairo_matrix_transform_point (&aggregate_transform, + &transformed_glyphs[j].x, + &transformed_glyphs[j].y); + if (! drop || KEEP_GLYPH (transformed_glyphs[j])) + j++; + } + memcpy (transformed_clusters, clusters, + num_clusters * sizeof (cairo_text_cluster_t)); + } else { + const cairo_glyph_t *cur_glyph; + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph = glyphs + num_glyphs - 1; + else + cur_glyph = glyphs; + + for (i = 0; i < num_clusters; i++) { + cairo_bool_t cluster_visible = FALSE; + for (k = 0; k < clusters[i].num_glyphs; k++) { + transformed_glyphs[j+k] = *cur_glyph; + cairo_matrix_transform_point (&aggregate_transform, + &transformed_glyphs[j+k].x, + &transformed_glyphs[j+k].y); + if (KEEP_GLYPH (transformed_glyphs[j+k])) + cluster_visible = TRUE; + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph--; + else + cur_glyph++; + } + + transformed_clusters[i] = clusters[i]; + if (cluster_visible) + j += k; + else + transformed_clusters[i].num_glyphs = 0; + } + } + } + *num_transformed_glyphs = j; + + if (num_clusters != 0 && cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) { + for (i = 0; i < --j; i++) { + cairo_glyph_t tmp; + + tmp = transformed_glyphs[i]; + transformed_glyphs[i] = transformed_glyphs[j]; + transformed_glyphs[j] = tmp; + } + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-hash-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-hash-private.h new file mode 100644 index 00000000000..30e51ffe669 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-hash-private.h @@ -0,0 +1,87 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc. + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Keith Packard + * Graydon Hoare + * Carl Worth + */ + +#ifndef CAIRO_HASH_PRIVATE_H +#define CAIRO_HASH_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-types-private.h" + +/* XXX: I'd like this file to be self-contained in terms of + * includeability, but that's not really possible with the current + * monolithic cairoint.h. So, for now, just include cairoint.h instead + * if you want to include this file. */ + +typedef cairo_bool_t +(*cairo_hash_keys_equal_func_t) (const void *key_a, const void *key_b); + +typedef cairo_bool_t +(*cairo_hash_predicate_func_t) (const void *entry); + +typedef void +(*cairo_hash_callback_func_t) (void *entry, + void *closure); + +cairo_private cairo_hash_table_t * +_cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal); + +cairo_private void +_cairo_hash_table_destroy (cairo_hash_table_t *hash_table); + +cairo_private void * +_cairo_hash_table_lookup (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key); + +cairo_private void * +_cairo_hash_table_random_entry (cairo_hash_table_t *hash_table, + cairo_hash_predicate_func_t predicate); + +cairo_private cairo_status_t +_cairo_hash_table_insert (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *entry); + +cairo_private void +_cairo_hash_table_remove (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key); + +cairo_private void +_cairo_hash_table_foreach (cairo_hash_table_t *hash_table, + cairo_hash_callback_func_t hash_callback, + void *closure); + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-hash.c b/Build/source/libs/cairo/cairo-src/src/cairo-hash.c new file mode 100644 index 00000000000..928c74b8bd6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-hash.c @@ -0,0 +1,578 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc. + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Keith Packard + * Graydon Hoare + * Carl Worth + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +/* + * An entry can be in one of three states: + * + * FREE: Entry has never been used, terminates all searches. + * Appears in the table as a %NULL pointer. + * + * DEAD: Entry had been live in the past. A dead entry can be reused + * but does not terminate a search for an exact entry. + * Appears in the table as a pointer to DEAD_ENTRY. + * + * LIVE: Entry is currently being used. + * Appears in the table as any non-%NULL, non-DEAD_ENTRY pointer. + */ + +#define DEAD_ENTRY ((cairo_hash_entry_t *) 0x1) + +#define ENTRY_IS_FREE(entry) ((entry) == NULL) +#define ENTRY_IS_DEAD(entry) ((entry) == DEAD_ENTRY) +#define ENTRY_IS_LIVE(entry) ((entry) > DEAD_ENTRY) + +/* + * This table is open-addressed with double hashing. Each table size + * is a prime and it makes for the "first" hash modulus; a second + * prime (2 less than the first prime) serves as the "second" hash + * modulus, which is smaller and thus guarantees a complete + * permutation of table indices. + * + * Hash tables are rehashed in order to keep between 12.5% and 50% + * entries in the hash table alive and at least 25% free. When table + * size is changed, the new table has about 25% live elements. + * + * The free entries guarantee an expected constant-time lookup. + * Doubling/halving the table in the described fashion guarantees + * amortized O(1) insertion/removal. + * + * This structure, and accompanying table, is borrowed/modified from the + * file xserver/render/glyph.c in the freedesktop.org x server, with + * permission (and suggested modification of doubling sizes) by Keith + * Packard. + */ + +static const unsigned long hash_table_sizes[] = { + 43, + 73, + 151, + 283, + 571, + 1153, + 2269, + 4519, + 9013, + 18043, + 36109, + 72091, + 144409, + 288361, + 576883, + 1153459, + 2307163, + 4613893, + 9227641, + 18455029, + 36911011, + 73819861, + 147639589, + 295279081, + 590559793 +}; + +struct _cairo_hash_table { + cairo_hash_keys_equal_func_t keys_equal; + + cairo_hash_entry_t *cache[32]; + + const unsigned long *table_size; + cairo_hash_entry_t **entries; + + unsigned long live_entries; + unsigned long free_entries; + unsigned long iterating; /* Iterating, no insert, no resize */ +}; + +/** + * _cairo_hash_table_uid_keys_equal: + * @key_a: the first key to be compared + * @key_b: the second key to be compared + * + * Provides a #cairo_hash_keys_equal_func_t which always returns + * %TRUE. This is useful to create hash tables using keys whose hash + * completely describes the key, because in this special case + * comparing the hashes is sufficient to guarantee that the keys are + * equal. + * + * Return value: %TRUE. + **/ +static cairo_bool_t +_cairo_hash_table_uid_keys_equal (const void *key_a, const void *key_b) +{ + return TRUE; +} + +/** + * _cairo_hash_table_create: + * @keys_equal: a function to return %TRUE if two keys are equal + * + * Creates a new hash table which will use the keys_equal() function + * to compare hash keys. Data is provided to the hash table in the + * form of user-derived versions of #cairo_hash_entry_t. A hash entry + * must be able to hold both a key (including a hash code) and a + * value. Sometimes only the key will be necessary, (as in + * _cairo_hash_table_remove), and other times both a key and a value + * will be necessary, (as in _cairo_hash_table_insert). + * + * If @keys_equal is %NULL, two keys will be considered equal if and + * only if their hashes are equal. + * + * See #cairo_hash_entry_t for more details. + * + * Return value: the new hash table or %NULL if out of memory. + **/ +cairo_hash_table_t * +_cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal) +{ + cairo_hash_table_t *hash_table; + + hash_table = malloc (sizeof (cairo_hash_table_t)); + if (unlikely (hash_table == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + if (keys_equal == NULL) + hash_table->keys_equal = _cairo_hash_table_uid_keys_equal; + else + hash_table->keys_equal = keys_equal; + + memset (&hash_table->cache, 0, sizeof (hash_table->cache)); + hash_table->table_size = &hash_table_sizes[0]; + + hash_table->entries = calloc (*hash_table->table_size, + sizeof (cairo_hash_entry_t *)); + if (unlikely (hash_table->entries == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + free (hash_table); + return NULL; + } + + hash_table->live_entries = 0; + hash_table->free_entries = *hash_table->table_size; + hash_table->iterating = 0; + + return hash_table; +} + +/** + * _cairo_hash_table_destroy: + * @hash_table: an empty hash table to destroy + * + * Immediately destroys the given hash table, freeing all resources + * associated with it. + * + * WARNING: The hash_table must have no live entries in it before + * _cairo_hash_table_destroy is called. It is a fatal error otherwise, + * and this function will halt. The rationale for this behavior is to + * avoid memory leaks and to avoid needless complication of the API + * with destroy notifiy callbacks. + * + * WARNING: The hash_table must have no running iterators in it when + * _cairo_hash_table_destroy is called. It is a fatal error otherwise, + * and this function will halt. + **/ +void +_cairo_hash_table_destroy (cairo_hash_table_t *hash_table) +{ + /* The hash table must be empty. Otherwise, halt. */ + assert (hash_table->live_entries == 0); + /* No iterators can be running. Otherwise, halt. */ + assert (hash_table->iterating == 0); + + free (hash_table->entries); + free (hash_table); +} + +static cairo_hash_entry_t ** +_cairo_hash_table_lookup_unique_key (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key) +{ + unsigned long table_size, i, idx, step; + cairo_hash_entry_t **entry; + + table_size = *hash_table->table_size; + idx = key->hash % table_size; + + entry = &hash_table->entries[idx]; + if (! ENTRY_IS_LIVE (*entry)) + return entry; + + i = 1; + step = 1 + key->hash % (table_size - 2); + do { + idx += step; + if (idx >= table_size) + idx -= table_size; + + entry = &hash_table->entries[idx]; + if (! ENTRY_IS_LIVE (*entry)) + return entry; + } while (++i < table_size); + + ASSERT_NOT_REACHED; + return NULL; +} + +/** + * _cairo_hash_table_manage: + * @hash_table: a hash table + * + * Resize the hash table if the number of entries has gotten much + * bigger or smaller than the ideal number of entries for the current + * size and guarantee some free entries to be used as lookup + * termination points. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if out of memory. + **/ +static cairo_status_t +_cairo_hash_table_manage (cairo_hash_table_t *hash_table) +{ + cairo_hash_table_t tmp; + unsigned long new_size, i; + + /* Keep between 12.5% and 50% entries in the hash table alive and + * at least 25% free. */ + unsigned long live_high = *hash_table->table_size >> 1; + unsigned long live_low = live_high >> 2; + unsigned long free_low = live_high >> 1; + + tmp = *hash_table; + + if (hash_table->live_entries > live_high) + { + tmp.table_size = hash_table->table_size + 1; + /* This code is being abused if we can't make a table big enough. */ + assert (tmp.table_size - hash_table_sizes < + ARRAY_LENGTH (hash_table_sizes)); + } + else if (hash_table->live_entries < live_low) + { + /* Can't shrink if we're at the smallest size */ + if (hash_table->table_size == &hash_table_sizes[0]) + tmp.table_size = hash_table->table_size; + else + tmp.table_size = hash_table->table_size - 1; + } + + if (tmp.table_size == hash_table->table_size && + hash_table->free_entries > free_low) + { + /* The number of live entries is within the desired bounds + * (we're not going to resize the table) and we have enough + * free entries. Do nothing. */ + return CAIRO_STATUS_SUCCESS; + } + + new_size = *tmp.table_size; + tmp.entries = calloc (new_size, sizeof (cairo_hash_entry_t*)); + if (unlikely (tmp.entries == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + for (i = 0; i < *hash_table->table_size; ++i) { + if (ENTRY_IS_LIVE (hash_table->entries[i])) { + *_cairo_hash_table_lookup_unique_key (&tmp, hash_table->entries[i]) + = hash_table->entries[i]; + } + } + + free (hash_table->entries); + hash_table->entries = tmp.entries; + hash_table->table_size = tmp.table_size; + hash_table->free_entries = new_size - hash_table->live_entries; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_hash_table_lookup: + * @hash_table: a hash table + * @key: the key of interest + * + * Performs a lookup in @hash_table looking for an entry which has a + * key that matches @key, (as determined by the keys_equal() function + * passed to _cairo_hash_table_create). + * + * Return value: the matching entry, of %NULL if no match was found. + **/ +void * +_cairo_hash_table_lookup (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key) +{ + cairo_hash_entry_t *entry; + unsigned long table_size, i, idx, step; + unsigned long hash = key->hash; + + entry = hash_table->cache[hash & 31]; + if (entry && entry->hash == hash && hash_table->keys_equal (key, entry)) + return entry; + + table_size = *hash_table->table_size; + idx = hash % table_size; + + entry = hash_table->entries[idx]; + if (ENTRY_IS_LIVE (entry)) { + if (entry->hash == hash && hash_table->keys_equal (key, entry)) + goto insert_cache; + } else if (ENTRY_IS_FREE (entry)) + return NULL; + + i = 1; + step = 1 + hash % (table_size - 2); + do { + idx += step; + if (idx >= table_size) + idx -= table_size; + + entry = hash_table->entries[idx]; + if (ENTRY_IS_LIVE (entry)) { + if (entry->hash == hash && hash_table->keys_equal (key, entry)) + goto insert_cache; + } else if (ENTRY_IS_FREE (entry)) + return NULL; + } while (++i < table_size); + + ASSERT_NOT_REACHED; + return NULL; + +insert_cache: + hash_table->cache[hash & 31] = entry; + return entry; +} + +/** + * _cairo_hash_table_random_entry: + * @hash_table: a hash table + * @predicate: a predicate function. + * + * Find a random entry in the hash table satisfying the given + * @predicate. + * + * We use the same algorithm as the lookup algorithm to walk over the + * entries in the hash table in a pseudo-random order. Walking + * linearly would favor entries following gaps in the hash table. We + * could also call rand() repeatedly, which works well for almost-full + * tables, but degrades when the table is almost empty, or predicate + * returns %TRUE for most entries. + * + * Return value: a random live entry or %NULL if there are no entries + * that match the given predicate. In particular, if predicate is + * %NULL, a %NULL return value indicates that the table is empty. + **/ +void * +_cairo_hash_table_random_entry (cairo_hash_table_t *hash_table, + cairo_hash_predicate_func_t predicate) +{ + cairo_hash_entry_t *entry; + unsigned long hash; + unsigned long table_size, i, idx, step; + + assert (predicate != NULL); + + table_size = *hash_table->table_size; + hash = rand (); + idx = hash % table_size; + + entry = hash_table->entries[idx]; + if (ENTRY_IS_LIVE (entry) && predicate (entry)) + return entry; + + i = 1; + step = 1 + hash % (table_size - 2); + do { + idx += step; + if (idx >= table_size) + idx -= table_size; + + entry = hash_table->entries[idx]; + if (ENTRY_IS_LIVE (entry) && predicate (entry)) + return entry; + } while (++i < table_size); + + return NULL; +} + +/** + * _cairo_hash_table_insert: + * @hash_table: a hash table + * @key_and_value: an entry to be inserted + * + * Insert the entry #key_and_value into the hash table. + * + * WARNING: There must not be an existing entry in the hash table + * with a matching key. + * + * WARNING: It is a fatal error to insert an element while + * an iterator is running + * + * Instead of using insert to replace an entry, consider just editing + * the entry obtained with _cairo_hash_table_lookup. Or if absolutely + * necessary, use _cairo_hash_table_remove first. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if insufficient memory is available. + **/ +cairo_status_t +_cairo_hash_table_insert (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key_and_value) +{ + cairo_hash_entry_t **entry; + cairo_status_t status; + + /* Insert is illegal while an iterator is running. */ + assert (hash_table->iterating == 0); + + status = _cairo_hash_table_manage (hash_table); + if (unlikely (status)) + return status; + + entry = _cairo_hash_table_lookup_unique_key (hash_table, key_and_value); + + if (ENTRY_IS_FREE (*entry)) + hash_table->free_entries--; + + *entry = key_and_value; + hash_table->cache[key_and_value->hash & 31] = key_and_value; + hash_table->live_entries++; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_hash_entry_t ** +_cairo_hash_table_lookup_exact_key (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key) +{ + unsigned long table_size, i, idx, step; + cairo_hash_entry_t **entry; + + table_size = *hash_table->table_size; + idx = key->hash % table_size; + + entry = &hash_table->entries[idx]; + if (*entry == key) + return entry; + + i = 1; + step = 1 + key->hash % (table_size - 2); + do { + idx += step; + if (idx >= table_size) + idx -= table_size; + + entry = &hash_table->entries[idx]; + if (*entry == key) + return entry; + } while (++i < table_size); + + ASSERT_NOT_REACHED; + return NULL; +} +/** + * _cairo_hash_table_remove: + * @hash_table: a hash table + * @key: key of entry to be removed + * + * Remove an entry from the hash table which points to @key. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful or + * %CAIRO_STATUS_NO_MEMORY if out of memory. + **/ +void +_cairo_hash_table_remove (cairo_hash_table_t *hash_table, + cairo_hash_entry_t *key) +{ + *_cairo_hash_table_lookup_exact_key (hash_table, key) = DEAD_ENTRY; + hash_table->live_entries--; + hash_table->cache[key->hash & 31] = NULL; + + /* Check for table resize. Don't do this when iterating as this will + * reorder elements of the table and cause the iteration to potentially + * skip some elements. */ + if (hash_table->iterating == 0) { + /* This call _can_ fail, but only in failing to allocate new + * memory to shrink the hash table. It does leave the table in a + * consistent state, and we've already succeeded in removing the + * entry, so we don't examine the failure status of this call. */ + _cairo_hash_table_manage (hash_table); + } +} + +/** + * _cairo_hash_table_foreach: + * @hash_table: a hash table + * @hash_callback: function to be called for each live entry + * @closure: additional argument to be passed to @hash_callback + * + * Call @hash_callback for each live entry in the hash table, in a + * non-specified order. + * + * Entries in @hash_table may be removed by code executed from @hash_callback. + * + * Entries may not be inserted to @hash_table, nor may @hash_table + * be destroyed by code executed from @hash_callback. The relevant + * functions will halt in these cases. + **/ +void +_cairo_hash_table_foreach (cairo_hash_table_t *hash_table, + cairo_hash_callback_func_t hash_callback, + void *closure) +{ + unsigned long i; + cairo_hash_entry_t *entry; + + /* Mark the table for iteration */ + ++hash_table->iterating; + for (i = 0; i < *hash_table->table_size; i++) { + entry = hash_table->entries[i]; + if (ENTRY_IS_LIVE(entry)) + hash_callback (entry, closure); + } + /* If some elements were deleted during the iteration, + * the table may need resizing. Just do this every time + * as the check is inexpensive. + */ + if (--hash_table->iterating == 0) { + /* Should we fail to shrink the hash table, it is left unaltered, + * and we don't need to propagate the error status. */ + _cairo_hash_table_manage (hash_table); + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-hull.c b/Build/source/libs/cairo/cairo-src/src/cairo-hull.c new file mode 100644 index 00000000000..c65593327f6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-hull.c @@ -0,0 +1,235 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-slope-private.h" + +typedef struct cairo_hull { + cairo_point_t point; + cairo_slope_t slope; + int discard; + int id; +} cairo_hull_t; + +static void +_cairo_hull_init (cairo_hull_t *hull, + cairo_pen_vertex_t *vertices, + int num_vertices) +{ + cairo_point_t *p, *extremum, tmp; + int i; + + extremum = &vertices[0].point; + for (i = 1; i < num_vertices; i++) { + p = &vertices[i].point; + if (p->y < extremum->y || (p->y == extremum->y && p->x < extremum->x)) + extremum = p; + } + /* Put the extremal point at the beginning of the array */ + tmp = *extremum; + *extremum = vertices[0].point; + vertices[0].point = tmp; + + for (i = 0; i < num_vertices; i++) { + hull[i].point = vertices[i].point; + _cairo_slope_init (&hull[i].slope, &hull[0].point, &hull[i].point); + + /* give each point a unique id for later comparison */ + hull[i].id = i; + + /* Don't discard by default */ + hull[i].discard = 0; + + /* Discard all points coincident with the extremal point */ + if (i != 0 && hull[i].slope.dx == 0 && hull[i].slope.dy == 0) + hull[i].discard = 1; + } +} + +static inline cairo_int64_t +_slope_length (cairo_slope_t *slope) +{ + return _cairo_int64_add (_cairo_int32x32_64_mul (slope->dx, slope->dx), + _cairo_int32x32_64_mul (slope->dy, slope->dy)); +} + +static int +_cairo_hull_vertex_compare (const void *av, const void *bv) +{ + cairo_hull_t *a = (cairo_hull_t *) av; + cairo_hull_t *b = (cairo_hull_t *) bv; + int ret; + + /* Some libraries are reported to actually compare identical + * pointers and require the result to be 0. This is the crazy world we + * have to live in. + */ + if (a == b) + return 0; + + ret = _cairo_slope_compare (&a->slope, &b->slope); + + /* + * In the case of two vertices with identical slope from the + * extremal point discard the nearer point. + */ + if (ret == 0) { + int cmp; + + cmp = _cairo_int64_cmp (_slope_length (&a->slope), + _slope_length (&b->slope)); + + /* + * Use the points' ids to ensure a well-defined ordering, + * and avoid setting discard on both points. + */ + if (cmp < 0 || (cmp == 0 && a->id < b->id)) { + a->discard = 1; + ret = -1; + } else { + b->discard = 1; + ret = 1; + } + } + + return ret; +} + +static int +_cairo_hull_prev_valid (cairo_hull_t *hull, int num_hull, int index) +{ + /* hull[0] is always valid, and we never need to wraparound, (if + * we are passed an index of 0 here, then the calling loop is just + * about to terminate). */ + if (index == 0) + return 0; + + do { + index--; + } while (hull[index].discard); + + return index; +} + +static int +_cairo_hull_next_valid (cairo_hull_t *hull, int num_hull, int index) +{ + do { + index = (index + 1) % num_hull; + } while (hull[index].discard); + + return index; +} + +static void +_cairo_hull_eliminate_concave (cairo_hull_t *hull, int num_hull) +{ + int i, j, k; + cairo_slope_t slope_ij, slope_jk; + + i = 0; + j = _cairo_hull_next_valid (hull, num_hull, i); + k = _cairo_hull_next_valid (hull, num_hull, j); + + do { + _cairo_slope_init (&slope_ij, &hull[i].point, &hull[j].point); + _cairo_slope_init (&slope_jk, &hull[j].point, &hull[k].point); + + /* Is the angle formed by ij and jk concave? */ + if (_cairo_slope_compare (&slope_ij, &slope_jk) >= 0) { + if (i == k) + return; + hull[j].discard = 1; + j = i; + i = _cairo_hull_prev_valid (hull, num_hull, j); + } else { + i = j; + j = k; + k = _cairo_hull_next_valid (hull, num_hull, j); + } + } while (j != 0); +} + +static void +_cairo_hull_to_pen (cairo_hull_t *hull, cairo_pen_vertex_t *vertices, int *num_vertices) +{ + int i, j = 0; + + for (i = 0; i < *num_vertices; i++) { + if (hull[i].discard) + continue; + vertices[j++].point = hull[i].point; + } + + *num_vertices = j; +} + +/* Given a set of vertices, compute the convex hull using the Graham + scan algorithm. */ +cairo_status_t +_cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices) +{ + cairo_hull_t hull_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_hull_t)]; + cairo_hull_t *hull; + int num_hull = *num_vertices; + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (num_hull > ARRAY_LENGTH (hull_stack)) { + hull = _cairo_malloc_ab (num_hull, sizeof (cairo_hull_t)); + if (unlikely (hull == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else { + hull = hull_stack; + } + + _cairo_hull_init (hull, vertices, num_hull); + + qsort (hull + 1, num_hull - 1, + sizeof (cairo_hull_t), _cairo_hull_vertex_compare); + + _cairo_hull_eliminate_concave (hull, num_hull); + + _cairo_hull_to_pen (hull, vertices, num_vertices); + + if (hull != hull_stack) + free (hull); + + return CAIRO_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-image-compositor.c new file mode 100644 index 00000000000..48072f81bd0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-compositor.c @@ -0,0 +1,3137 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * Copyright © 2009,2010,2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* The primarily reason for keeping a traps-compositor around is + * for validating cairo-xlib (which currently also uses traps). + */ + +#include "cairoint.h" + +#include "cairo-image-surface-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-spans-compositor-private.h" + +#include "cairo-region-private.h" +#include "cairo-traps-private.h" +#include "cairo-tristrip-private.h" + +#include "cairo-pixman-private.h" + +static pixman_image_t * +to_pixman_image (cairo_surface_t *s) +{ + return ((cairo_image_surface_t *)s)->pixman_image; +} + +static cairo_int_status_t +acquire (void *abstract_dst) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +release (void *abstract_dst) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +set_clip_region (void *_surface, + cairo_region_t *region) +{ + cairo_image_surface_t *surface = _surface; + pixman_region32_t *rgn = region ? ®ion->rgn : NULL; + + if (! pixman_image_set_clip_region32 (surface->pixman_image, rgn)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +draw_image_boxes (void *_dst, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy) +{ + cairo_image_surface_t *dst = _dst; + struct _cairo_boxes_chunk *chunk; + int i; + + TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + int x = _cairo_fixed_integer_part (b->p1.x); + int y = _cairo_fixed_integer_part (b->p1.y); + int w = _cairo_fixed_integer_part (b->p2.x) - x; + int h = _cairo_fixed_integer_part (b->p2.y) - y; + if (dst->pixman_format != image->pixman_format || + ! pixman_blt ((uint32_t *)image->data, (uint32_t *)dst->data, + image->stride / sizeof (uint32_t), + dst->stride / sizeof (uint32_t), + PIXMAN_FORMAT_BPP (image->pixman_format), + PIXMAN_FORMAT_BPP (dst->pixman_format), + x + dx, y + dy, + x, y, + w, h)) + { + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, NULL, dst->pixman_image, + x + dx, y + dy, + 0, 0, + x, y, + w, h); + } + } + } + return CAIRO_STATUS_SUCCESS; +} + +static inline uint32_t +color_to_uint32 (const cairo_color_t *color) +{ + return + (color->alpha_short >> 8 << 24) | + (color->red_short >> 8 << 16) | + (color->green_short & 0xff00) | + (color->blue_short >> 8); +} + +static inline cairo_bool_t +color_to_pixel (const cairo_color_t *color, + pixman_format_code_t format, + uint32_t *pixel) +{ + uint32_t c; + + if (!(format == PIXMAN_a8r8g8b8 || + format == PIXMAN_x8r8g8b8 || + format == PIXMAN_a8b8g8r8 || + format == PIXMAN_x8b8g8r8 || + format == PIXMAN_b8g8r8a8 || + format == PIXMAN_b8g8r8x8 || + format == PIXMAN_r5g6b5 || + format == PIXMAN_b5g6r5 || + format == PIXMAN_a8)) + { + return FALSE; + } + + c = color_to_uint32 (color); + + if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_ABGR) { + c = ((c & 0xff000000) >> 0) | + ((c & 0x00ff0000) >> 16) | + ((c & 0x0000ff00) >> 0) | + ((c & 0x000000ff) << 16); + } + + if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_BGRA) { + c = ((c & 0xff000000) >> 24) | + ((c & 0x00ff0000) >> 8) | + ((c & 0x0000ff00) << 8) | + ((c & 0x000000ff) << 24); + } + + if (format == PIXMAN_a8) { + c = c >> 24; + } else if (format == PIXMAN_r5g6b5 || format == PIXMAN_b5g6r5) { + c = ((((c) >> 3) & 0x001f) | + (((c) >> 5) & 0x07e0) | + (((c) >> 8) & 0xf800)); + } + + *pixel = c; + return TRUE; +} + +static pixman_op_t +_pixman_operator (cairo_operator_t op) +{ + switch ((int) op) { + case CAIRO_OPERATOR_CLEAR: + return PIXMAN_OP_CLEAR; + + case CAIRO_OPERATOR_SOURCE: + return PIXMAN_OP_SRC; + case CAIRO_OPERATOR_OVER: + return PIXMAN_OP_OVER; + case CAIRO_OPERATOR_IN: + return PIXMAN_OP_IN; + case CAIRO_OPERATOR_OUT: + return PIXMAN_OP_OUT; + case CAIRO_OPERATOR_ATOP: + return PIXMAN_OP_ATOP; + + case CAIRO_OPERATOR_DEST: + return PIXMAN_OP_DST; + case CAIRO_OPERATOR_DEST_OVER: + return PIXMAN_OP_OVER_REVERSE; + case CAIRO_OPERATOR_DEST_IN: + return PIXMAN_OP_IN_REVERSE; + case CAIRO_OPERATOR_DEST_OUT: + return PIXMAN_OP_OUT_REVERSE; + case CAIRO_OPERATOR_DEST_ATOP: + return PIXMAN_OP_ATOP_REVERSE; + + case CAIRO_OPERATOR_XOR: + return PIXMAN_OP_XOR; + case CAIRO_OPERATOR_ADD: + return PIXMAN_OP_ADD; + case CAIRO_OPERATOR_SATURATE: + return PIXMAN_OP_SATURATE; + + case CAIRO_OPERATOR_MULTIPLY: + return PIXMAN_OP_MULTIPLY; + case CAIRO_OPERATOR_SCREEN: + return PIXMAN_OP_SCREEN; + case CAIRO_OPERATOR_OVERLAY: + return PIXMAN_OP_OVERLAY; + case CAIRO_OPERATOR_DARKEN: + return PIXMAN_OP_DARKEN; + case CAIRO_OPERATOR_LIGHTEN: + return PIXMAN_OP_LIGHTEN; + case CAIRO_OPERATOR_COLOR_DODGE: + return PIXMAN_OP_COLOR_DODGE; + case CAIRO_OPERATOR_COLOR_BURN: + return PIXMAN_OP_COLOR_BURN; + case CAIRO_OPERATOR_HARD_LIGHT: + return PIXMAN_OP_HARD_LIGHT; + case CAIRO_OPERATOR_SOFT_LIGHT: + return PIXMAN_OP_SOFT_LIGHT; + case CAIRO_OPERATOR_DIFFERENCE: + return PIXMAN_OP_DIFFERENCE; + case CAIRO_OPERATOR_EXCLUSION: + return PIXMAN_OP_EXCLUSION; + case CAIRO_OPERATOR_HSL_HUE: + return PIXMAN_OP_HSL_HUE; + case CAIRO_OPERATOR_HSL_SATURATION: + return PIXMAN_OP_HSL_SATURATION; + case CAIRO_OPERATOR_HSL_COLOR: + return PIXMAN_OP_HSL_COLOR; + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return PIXMAN_OP_HSL_LUMINOSITY; + + default: + ASSERT_NOT_REACHED; + return PIXMAN_OP_OVER; + } +} + +static cairo_bool_t +__fill_reduces_to_source (cairo_operator_t op, + const cairo_color_t *color, + const cairo_image_surface_t *dst) +{ + if (op == CAIRO_OPERATOR_SOURCE || op == CAIRO_OPERATOR_CLEAR) + return TRUE; + if (op == CAIRO_OPERATOR_OVER && CAIRO_COLOR_IS_OPAQUE (color)) + return TRUE; + if (dst->base.is_clear) + return op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD; + + return FALSE; +} + +static cairo_bool_t +fill_reduces_to_source (cairo_operator_t op, + const cairo_color_t *color, + const cairo_image_surface_t *dst, + uint32_t *pixel) +{ + if (__fill_reduces_to_source (op, color, dst)) { + return color_to_pixel (color, dst->pixman_format, pixel); + } + + return FALSE; +} + +static cairo_int_status_t +fill_rectangles (void *_dst, + cairo_operator_t op, + const cairo_color_t *color, + cairo_rectangle_int_t *rects, + int num_rects) +{ + cairo_image_surface_t *dst = _dst; + uint32_t pixel; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (fill_reduces_to_source (op, color, dst, &pixel)) { + for (i = 0; i < num_rects; i++) { + pixman_fill ((uint32_t *) dst->data, dst->stride / sizeof (uint32_t), + PIXMAN_FORMAT_BPP (dst->pixman_format), + rects[i].x, rects[i].y, + rects[i].width, rects[i].height, + pixel); + } + } else { + pixman_image_t *src = _pixman_image_for_color (color); + if (unlikely (src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + op = _pixman_operator (op); + for (i = 0; i < num_rects; i++) { + pixman_image_composite32 (op, + src, NULL, dst->pixman_image, + 0, 0, + 0, 0, + rects[i].x, rects[i].y, + rects[i].width, rects[i].height); + } + + pixman_image_unref (src); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +fill_boxes (void *_dst, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + cairo_image_surface_t *dst = _dst; + struct _cairo_boxes_chunk *chunk; + uint32_t pixel; + int i; + + TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); + + if (fill_reduces_to_source (op, color, dst, &pixel)) { + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int w = _cairo_fixed_integer_part (chunk->base[i].p2.x) - x; + int h = _cairo_fixed_integer_part (chunk->base[i].p2.y) - y; + pixman_fill ((uint32_t *) dst->data, + dst->stride / sizeof (uint32_t), + PIXMAN_FORMAT_BPP (dst->pixman_format), + x, y, w, h, pixel); + } + } + } + else + { + pixman_image_t *src = _pixman_image_for_color (color); + if (unlikely (src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + op = _pixman_operator (op); + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + pixman_image_composite32 (op, + src, NULL, dst->pixman_image, + 0, 0, + 0, 0, + x1, y1, + x2-x1, y2-y1); + } + } + + pixman_image_unref (src); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + cairo_image_source_t *src = (cairo_image_source_t *)abstract_src; + cairo_image_source_t *mask = (cairo_image_source_t *)abstract_mask; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (mask) { + pixman_image_composite32 (_pixman_operator (op), + src->pixman_image, mask->pixman_image, to_pixman_image (_dst), + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height); + } else { + pixman_image_composite32 (_pixman_operator (op), + src->pixman_image, NULL, to_pixman_image (_dst), + src_x, src_y, + 0, 0, + dst_x, dst_y, + width, height); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +lerp (void *_dst, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + cairo_image_surface_t *dst = _dst; + cairo_image_source_t *src = (cairo_image_source_t *)abstract_src; + cairo_image_source_t *mask = (cairo_image_source_t *)abstract_mask; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + +#if PIXMAN_HAS_OP_LERP + pixman_image_composite32 (PIXMAN_OP_LERP_SRC, + src->pixman_image, mask->pixman_image, dst->pixman_image, + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height); +#else + /* Punch the clip out of the destination */ + TRACE ((stderr, "%s - OUT_REVERSE (mask=%d/%p, dst=%d/%p)\n", + __FUNCTION__, + mask->base.unique_id, mask->pixman_image, + dst->base.unique_id, dst->pixman_image)); + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + mask->pixman_image, NULL, dst->pixman_image, + mask_x, mask_y, + 0, 0, + dst_x, dst_y, + width, height); + + /* Now add the two results together */ + TRACE ((stderr, "%s - ADD (src=%d/%p, mask=%d/%p, dst=%d/%p)\n", + __FUNCTION__, + src->base.unique_id, src->pixman_image, + mask->base.unique_id, mask->pixman_image, + dst->base.unique_id, dst->pixman_image)); + pixman_image_composite32 (PIXMAN_OP_ADD, + src->pixman_image, mask->pixman_image, dst->pixman_image, + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height); +#endif + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_boxes (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents) +{ + pixman_image_t *dst = to_pixman_image (_dst); + pixman_image_t *src = ((cairo_image_source_t *)abstract_src)->pixman_image; + pixman_image_t *mask = abstract_mask ? ((cairo_image_source_t *)abstract_mask)->pixman_image : NULL; + pixman_image_t *free_src = NULL; + struct _cairo_boxes_chunk *chunk; + int i; + + /* XXX consider using a region? saves multiple prepare-composite */ + TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); + + if (((cairo_surface_t *)_dst)->is_clear && + (op == CAIRO_OPERATOR_SOURCE || + op == CAIRO_OPERATOR_OVER || + op == CAIRO_OPERATOR_ADD)) { + op = PIXMAN_OP_SRC; + } else if (mask) { + if (op == CAIRO_OPERATOR_CLEAR) { +#if PIXMAN_HAS_OP_LERP + op = PIXMAN_OP_LERP_CLEAR; +#else + free_src = src = _pixman_image_for_color (CAIRO_COLOR_WHITE); + if (unlikely (src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + op = PIXMAN_OP_OUT_REVERSE; +#endif + } else if (op == CAIRO_OPERATOR_SOURCE) { +#if PIXMAN_HAS_OP_LERP + op = PIXMAN_OP_LERP_SRC; +#else + return CAIRO_INT_STATUS_UNSUPPORTED; +#endif + } else { + op = _pixman_operator (op); + } + } else { + op = _pixman_operator (op); + } + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + + pixman_image_composite32 (op, src, mask, dst, + x1 + src_x, y1 + src_y, + x1 + mask_x, y1 + mask_y, + x1 + dst_x, y1 + dst_y, + x2 - x1, y2 - y1); + } + } + + if (free_src) + pixman_image_unref (free_src); + + return CAIRO_STATUS_SUCCESS; +} + +#define CAIRO_FIXED_16_16_MIN _cairo_fixed_from_int (-32768) +#define CAIRO_FIXED_16_16_MAX _cairo_fixed_from_int (32767) + +static cairo_bool_t +line_exceeds_16_16 (const cairo_line_t *line) +{ + return + line->p1.x <= CAIRO_FIXED_16_16_MIN || + line->p1.x >= CAIRO_FIXED_16_16_MAX || + + line->p2.x <= CAIRO_FIXED_16_16_MIN || + line->p2.x >= CAIRO_FIXED_16_16_MAX || + + line->p1.y <= CAIRO_FIXED_16_16_MIN || + line->p1.y >= CAIRO_FIXED_16_16_MAX || + + line->p2.y <= CAIRO_FIXED_16_16_MIN || + line->p2.y >= CAIRO_FIXED_16_16_MAX; +} + +static void +project_line_x_onto_16_16 (const cairo_line_t *line, + cairo_fixed_t top, + cairo_fixed_t bottom, + pixman_line_fixed_t *out) +{ + /* XXX use fixed-point arithmetic? */ + cairo_point_double_t p1, p2; + double m; + + p1.x = _cairo_fixed_to_double (line->p1.x); + p1.y = _cairo_fixed_to_double (line->p1.y); + + p2.x = _cairo_fixed_to_double (line->p2.x); + p2.y = _cairo_fixed_to_double (line->p2.y); + + m = (p2.x - p1.x) / (p2.y - p1.y); + out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); + out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); +} + +void +_pixman_image_add_traps (pixman_image_t *image, + int dst_x, int dst_y, + cairo_traps_t *traps) +{ + cairo_trapezoid_t *t = traps->traps; + int num_traps = traps->num_traps; + while (num_traps--) { + pixman_trapezoid_t trap; + + /* top/bottom will be clamped to surface bounds */ + trap.top = _cairo_fixed_to_16_16 (t->top); + trap.bottom = _cairo_fixed_to_16_16 (t->bottom); + + /* However, all the other coordinates will have been left untouched so + * as not to introduce numerical error. Recompute them if they + * exceed the 16.16 limits. + */ + if (unlikely (line_exceeds_16_16 (&t->left))) { + project_line_x_onto_16_16 (&t->left, t->top, t->bottom, &trap.left); + trap.left.p1.y = trap.top; + trap.left.p2.y = trap.bottom; + } else { + trap.left.p1.x = _cairo_fixed_to_16_16 (t->left.p1.x); + trap.left.p1.y = _cairo_fixed_to_16_16 (t->left.p1.y); + trap.left.p2.x = _cairo_fixed_to_16_16 (t->left.p2.x); + trap.left.p2.y = _cairo_fixed_to_16_16 (t->left.p2.y); + } + + if (unlikely (line_exceeds_16_16 (&t->right))) { + project_line_x_onto_16_16 (&t->right, t->top, t->bottom, &trap.right); + trap.right.p1.y = trap.top; + trap.right.p2.y = trap.bottom; + } else { + trap.right.p1.x = _cairo_fixed_to_16_16 (t->right.p1.x); + trap.right.p1.y = _cairo_fixed_to_16_16 (t->right.p1.y); + trap.right.p2.x = _cairo_fixed_to_16_16 (t->right.p2.x); + trap.right.p2.y = _cairo_fixed_to_16_16 (t->right.p2.y); + } + + pixman_rasterize_trapezoid (image, &trap, -dst_x, -dst_y); + t++; + } +} + +static cairo_int_status_t +composite_traps (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_traps_t *traps) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *) _dst; + cairo_image_source_t *src = (cairo_image_source_t *) abstract_src; + cairo_int_status_t status; + pixman_image_t *mask; + pixman_format_code_t format; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + /* pixman doesn't eliminate self-intersecting trapezoids/edges */ + status = _cairo_bentley_ottmann_tessellate_traps (traps, + CAIRO_FILL_RULE_WINDING); + if (status != CAIRO_INT_STATUS_SUCCESS) + return status; + + /* Special case adding trapezoids onto a mask surface; we want to avoid + * creating an intermediate temporary mask unnecessarily. + * + * We make the assumption here that the portion of the trapezoids + * contained within the surface is bounded by [dst_x,dst_y,width,height]; + * the Cairo core code passes bounds based on the trapezoid extents. + */ + format = antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8; + if (dst->pixman_format == format && + (abstract_src == NULL || + (op == CAIRO_OPERATOR_ADD && src->is_opaque_solid))) + { + _pixman_image_add_traps (dst->pixman_image, dst_x, dst_y, traps); + return CAIRO_STATUS_SUCCESS; + } + + mask = pixman_image_create_bits (format, + extents->width, extents->height, + NULL, 0); + if (unlikely (mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _pixman_image_add_traps (mask, extents->x, extents->y, traps); + pixman_image_composite32 (_pixman_operator (op), + src->pixman_image, mask, dst->pixman_image, + extents->x + src_x, extents->y + src_y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + pixman_image_unref (mask); + + return CAIRO_STATUS_SUCCESS; +} + +#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) +static void +set_point (pixman_point_fixed_t *p, cairo_point_t *c) +{ + p->x = _cairo_fixed_to_16_16 (c->x); + p->y = _cairo_fixed_to_16_16 (c->y); +} + +void +_pixman_image_add_tristrip (pixman_image_t *image, + int dst_x, int dst_y, + cairo_tristrip_t *strip) +{ + pixman_triangle_t tri; + pixman_point_fixed_t *p[3] = {&tri.p1, &tri.p2, &tri.p3 }; + int n; + + set_point (p[0], &strip->points[0]); + set_point (p[1], &strip->points[1]); + set_point (p[2], &strip->points[2]); + pixman_add_triangles (image, -dst_x, -dst_y, 1, &tri); + for (n = 3; n < strip->num_points; n++) { + set_point (p[n%3], &strip->points[n]); + pixman_add_triangles (image, -dst_x, -dst_y, 1, &tri); + } +} + +static cairo_int_status_t +composite_tristrip (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_tristrip_t *strip) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *) _dst; + cairo_image_source_t *src = (cairo_image_source_t *) abstract_src; + pixman_image_t *mask; + pixman_format_code_t format; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (strip->num_points < 3) + return CAIRO_STATUS_SUCCESS; + + if (1) { /* pixman doesn't eliminate self-intersecting triangles/edges */ + cairo_int_status_t status; + cairo_traps_t traps; + int n; + + _cairo_traps_init (&traps); + for (n = 0; n < strip->num_points; n++) { + cairo_point_t p[4]; + + p[0] = strip->points[0]; + p[1] = strip->points[1]; + p[2] = strip->points[2]; + p[3] = strip->points[0]; + + _cairo_traps_tessellate_convex_quad (&traps, p); + } + status = composite_traps (_dst, op, abstract_src, + src_x, src_y, + dst_x, dst_y, + extents, antialias, &traps); + _cairo_traps_fini (&traps); + + return status; + } + + format = antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8; + if (dst->pixman_format == format && + (abstract_src == NULL || + (op == CAIRO_OPERATOR_ADD && src->is_opaque_solid))) + { + _pixman_image_add_tristrip (dst->pixman_image, dst_x, dst_y, strip); + return CAIRO_STATUS_SUCCESS; + } + + mask = pixman_image_create_bits (format, + extents->width, extents->height, + NULL, 0); + if (unlikely (mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _pixman_image_add_tristrip (mask, extents->x, extents->y, strip); + pixman_image_composite32 (_pixman_operator (op), + src->pixman_image, mask, dst->pixman_image, + extents->x + src_x, extents->y + src_y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + pixman_image_unref (mask); + + return CAIRO_STATUS_SUCCESS; +} +#endif + +static cairo_int_status_t +check_composite_glyphs (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs) +{ + return CAIRO_STATUS_SUCCESS; +} + +#if HAS_PIXMAN_GLYPHS +static pixman_glyph_cache_t *global_glyph_cache; + +static inline pixman_glyph_cache_t * +get_glyph_cache (void) +{ + if (!global_glyph_cache) + global_glyph_cache = pixman_glyph_cache_create (); + + return global_glyph_cache; +} + +void +_cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_t *scaled_glyph) +{ + CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); + + if (global_glyph_cache) { + pixman_glyph_cache_remove ( + global_glyph_cache, scaled_font, + (void *)_cairo_scaled_glyph_index (scaled_glyph)); + } + + CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); +} + +static cairo_int_status_t +composite_glyphs (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + pixman_glyph_cache_t *glyph_cache; + pixman_glyph_t pglyphs_stack[CAIRO_STACK_ARRAY_LENGTH (pixman_glyph_t)]; + pixman_glyph_t *pglyphs = pglyphs_stack; + pixman_glyph_t *pg; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); + + glyph_cache = get_glyph_cache(); + if (unlikely (glyph_cache == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto out_unlock; + } + + pixman_glyph_cache_freeze (glyph_cache); + + if (info->num_glyphs > ARRAY_LENGTH (pglyphs_stack)) { + pglyphs = _cairo_malloc_ab (info->num_glyphs, sizeof (pixman_glyph_t)); + if (unlikely (pglyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto out_thaw; + } + } + + pg = pglyphs; + for (i = 0; i < info->num_glyphs; i++) { + unsigned long index = info->glyphs[i].index; + const void *glyph; + + glyph = pixman_glyph_cache_lookup (glyph_cache, info->font, (void *)index); + if (!glyph) { + cairo_scaled_glyph_t *scaled_glyph; + cairo_image_surface_t *glyph_surface; + + /* This call can actually end up recursing, so we have to + * drop the mutex around it. + */ + CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); + status = _cairo_scaled_glyph_lookup (info->font, index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); + + if (unlikely (status)) + goto out_thaw; + + glyph_surface = scaled_glyph->surface; + glyph = pixman_glyph_cache_insert (glyph_cache, info->font, (void *)index, + glyph_surface->base.device_transform.x0, + glyph_surface->base.device_transform.y0, + glyph_surface->pixman_image); + if (unlikely (!glyph)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto out_thaw; + } + } + + pg->x = _cairo_lround (info->glyphs[i].x); + pg->y = _cairo_lround (info->glyphs[i].y); + pg->glyph = glyph; + pg++; + } + + if (info->use_mask) { + pixman_format_code_t mask_format; + + mask_format = pixman_glyph_get_mask_format (glyph_cache, pg - pglyphs, pglyphs); + + pixman_composite_glyphs (_pixman_operator (op), + ((cairo_image_source_t *)_src)->pixman_image, + to_pixman_image (_dst), + mask_format, + info->extents.x + src_x, info->extents.y + src_y, + info->extents.x, info->extents.y, + info->extents.x - dst_x, info->extents.y - dst_y, + info->extents.width, info->extents.height, + glyph_cache, pg - pglyphs, pglyphs); + } else { + pixman_composite_glyphs_no_mask (_pixman_operator (op), + ((cairo_image_source_t *)_src)->pixman_image, + to_pixman_image (_dst), + src_x, src_y, + - dst_x, - dst_y, + glyph_cache, pg - pglyphs, pglyphs); + } + +out_thaw: + pixman_glyph_cache_thaw (glyph_cache); + + if (pglyphs != pglyphs_stack) + free(pglyphs); + +out_unlock: + CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); + return status; +} +#else +void +_cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_t *scaled_glyph) +{ +} + +static cairo_int_status_t +composite_one_glyph (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + cairo_image_surface_t *glyph_surface; + cairo_scaled_glyph_t *scaled_glyph; + cairo_status_t status; + int x, y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = _cairo_scaled_glyph_lookup (info->font, + info->glyphs[0].index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + + if (unlikely (status)) + return status; + + glyph_surface = scaled_glyph->surface; + if (glyph_surface->width == 0 || glyph_surface->height == 0) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + /* round glyph locations to the nearest pixel */ + /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ + x = _cairo_lround (info->glyphs[0].x - + glyph_surface->base.device_transform.x0); + y = _cairo_lround (info->glyphs[0].y - + glyph_surface->base.device_transform.y0); + + pixman_image_composite32 (_pixman_operator (op), + ((cairo_image_source_t *)_src)->pixman_image, + glyph_surface->pixman_image, + to_pixman_image (_dst), + x + src_x, y + src_y, + 0, 0, + x - dst_x, y - dst_y, + glyph_surface->width, + glyph_surface->height); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_glyphs_via_mask (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + cairo_scaled_glyph_t *glyph_cache[64]; + pixman_image_t *white = _pixman_image_for_color (CAIRO_COLOR_WHITE); + cairo_scaled_glyph_t *scaled_glyph; + uint8_t buf[2048]; + pixman_image_t *mask; + pixman_format_code_t format; + cairo_status_t status; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (unlikely (white == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* XXX convert the glyphs to common formats a8/a8r8g8b8 to hit + * optimised paths through pixman. Should we increase the bit + * depth of the target surface, we should reconsider the appropriate + * mask formats. + */ + + status = _cairo_scaled_glyph_lookup (info->font, + info->glyphs[0].index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + if (unlikely (status)) { + pixman_image_unref (white); + return status; + } + + memset (glyph_cache, 0, sizeof (glyph_cache)); + glyph_cache[info->glyphs[0].index % ARRAY_LENGTH (glyph_cache)] = scaled_glyph; + + format = PIXMAN_a8; + i = (info->extents.width + 3) & ~3; + if (scaled_glyph->surface->base.content & CAIRO_CONTENT_COLOR) { + format = PIXMAN_a8r8g8b8; + i = info->extents.width * 4; + } + + if (i * info->extents.height > (int) sizeof (buf)) { + mask = pixman_image_create_bits (format, + info->extents.width, + info->extents.height, + NULL, 0); + } else { + memset (buf, 0, i * info->extents.height); + mask = pixman_image_create_bits (format, + info->extents.width, + info->extents.height, + (uint32_t *)buf, i); + } + if (unlikely (mask == NULL)) { + pixman_image_unref (white); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + status = CAIRO_STATUS_SUCCESS; + for (i = 0; i < info->num_glyphs; i++) { + unsigned long glyph_index = info->glyphs[i].index; + int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); + cairo_image_surface_t *glyph_surface; + int x, y; + + scaled_glyph = glyph_cache[cache_index]; + if (scaled_glyph == NULL || + _cairo_scaled_glyph_index (scaled_glyph) != glyph_index) + { + status = _cairo_scaled_glyph_lookup (info->font, glyph_index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + + if (unlikely (status)) { + pixman_image_unref (mask); + pixman_image_unref (white); + return status; + } + + glyph_cache[cache_index] = scaled_glyph; + } + + glyph_surface = scaled_glyph->surface; + if (glyph_surface->width && glyph_surface->height) { + if (glyph_surface->base.content & CAIRO_CONTENT_COLOR && + format == PIXMAN_a8) { + pixman_image_t *ca_mask; + + format = PIXMAN_a8r8g8b8; + ca_mask = pixman_image_create_bits (format, + info->extents.width, + info->extents.height, + NULL, 0); + if (unlikely (ca_mask == NULL)) { + pixman_image_unref (mask); + pixman_image_unref (white); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pixman_image_composite32 (PIXMAN_OP_SRC, + white, mask, ca_mask, + 0, 0, + 0, 0, + 0, 0, + info->extents.width, + info->extents.height); + pixman_image_unref (mask); + mask = ca_mask; + } + + /* round glyph locations to the nearest pixel */ + /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ + x = _cairo_lround (info->glyphs[i].x - + glyph_surface->base.device_transform.x0); + y = _cairo_lround (info->glyphs[i].y - + glyph_surface->base.device_transform.y0); + + if (glyph_surface->pixman_format == format) { + pixman_image_composite32 (PIXMAN_OP_ADD, + glyph_surface->pixman_image, NULL, mask, + 0, 0, + 0, 0, + x - info->extents.x, y - info->extents.y, + glyph_surface->width, + glyph_surface->height); + } else { + pixman_image_composite32 (PIXMAN_OP_ADD, + white, glyph_surface->pixman_image, mask, + 0, 0, + 0, 0, + x - info->extents.x, y - info->extents.y, + glyph_surface->width, + glyph_surface->height); + } + } + } + + if (format == PIXMAN_a8r8g8b8) + pixman_image_set_component_alpha (mask, TRUE); + + pixman_image_composite32 (_pixman_operator (op), + ((cairo_image_source_t *)_src)->pixman_image, + mask, + to_pixman_image (_dst), + info->extents.x + src_x, info->extents.y + src_y, + 0, 0, + info->extents.x - dst_x, info->extents.y - dst_y, + info->extents.width, info->extents.height); + pixman_image_unref (mask); + pixman_image_unref (white); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_glyphs (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + cairo_scaled_glyph_t *glyph_cache[64]; + pixman_image_t *dst, *src; + cairo_status_t status; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (info->num_glyphs == 1) + return composite_one_glyph(_dst, op, _src, src_x, src_y, dst_x, dst_y, info); + + if (info->use_mask) + return composite_glyphs_via_mask(_dst, op, _src, src_x, src_y, dst_x, dst_y, info); + + op = _pixman_operator (op); + dst = to_pixman_image (_dst); + src = ((cairo_image_source_t *)_src)->pixman_image; + + memset (glyph_cache, 0, sizeof (glyph_cache)); + status = CAIRO_STATUS_SUCCESS; + + for (i = 0; i < info->num_glyphs; i++) { + int x, y; + cairo_image_surface_t *glyph_surface; + cairo_scaled_glyph_t *scaled_glyph; + unsigned long glyph_index = info->glyphs[i].index; + int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); + + scaled_glyph = glyph_cache[cache_index]; + if (scaled_glyph == NULL || + _cairo_scaled_glyph_index (scaled_glyph) != glyph_index) + { + status = _cairo_scaled_glyph_lookup (info->font, glyph_index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + + if (unlikely (status)) + break; + + glyph_cache[cache_index] = scaled_glyph; + } + + glyph_surface = scaled_glyph->surface; + if (glyph_surface->width && glyph_surface->height) { + /* round glyph locations to the nearest pixel */ + /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ + x = _cairo_lround (info->glyphs[i].x - + glyph_surface->base.device_transform.x0); + y = _cairo_lround (info->glyphs[i].y - + glyph_surface->base.device_transform.y0); + + pixman_image_composite32 (op, src, glyph_surface->pixman_image, dst, + x + src_x, y + src_y, + 0, 0, + x - dst_x, y - dst_y, + glyph_surface->width, + glyph_surface->height); + } + } + + return status; +} +#endif + +static cairo_int_status_t +check_composite (const cairo_composite_rectangles_t *extents) +{ + return CAIRO_STATUS_SUCCESS; +} + +const cairo_compositor_t * +_cairo_image_traps_compositor_get (void) +{ + static cairo_traps_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_traps_compositor_init (&compositor, + &__cairo_no_compositor); + compositor.acquire = acquire; + compositor.release = release; + compositor.set_clip_region = set_clip_region; + compositor.pattern_to_surface = _cairo_image_source_create_for_pattern; + compositor.draw_image_boxes = draw_image_boxes; + //compositor.copy_boxes = copy_boxes; + compositor.fill_boxes = fill_boxes; + compositor.check_composite = check_composite; + compositor.composite = composite; + compositor.lerp = lerp; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + //compositor.check_composite_traps = check_composite_traps; + compositor.composite_traps = composite_traps; + //compositor.check_composite_tristrip = check_composite_traps; +#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) + compositor.composite_tristrip = composite_tristrip; +#endif + compositor.check_composite_glyphs = check_composite_glyphs; + compositor.composite_glyphs = composite_glyphs; + } + + return &compositor.base; +} + +const cairo_compositor_t * +_cairo_image_mask_compositor_get (void) +{ + static cairo_mask_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_mask_compositor_init (&compositor, + _cairo_image_traps_compositor_get ()); + compositor.acquire = acquire; + compositor.release = release; + compositor.set_clip_region = set_clip_region; + compositor.pattern_to_surface = _cairo_image_source_create_for_pattern; + compositor.draw_image_boxes = draw_image_boxes; + compositor.fill_rectangles = fill_rectangles; + compositor.fill_boxes = fill_boxes; + compositor.check_composite = check_composite; + compositor.composite = composite; + //compositor.lerp = lerp; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + compositor.check_composite_glyphs = check_composite_glyphs; + compositor.composite_glyphs = composite_glyphs; + } + + return &compositor.base; +} + +#if PIXMAN_HAS_COMPOSITOR +typedef struct _cairo_image_span_renderer { + cairo_span_renderer_t base; + + pixman_image_compositor_t *compositor; + pixman_image_t *src, *mask; + float opacity; + cairo_rectangle_int_t extents; +} cairo_image_span_renderer_t; +COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t)); + +static cairo_status_t +_cairo_image_bounded_opaque_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + do { + if (spans[0].coverage) + pixman_image_compositor_blt (r->compositor, + spans[0].x, y, + spans[1].x - spans[0].x, height, + spans[0].coverage); + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_image_bounded_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + do { + if (spans[0].coverage) { + pixman_image_compositor_blt (r->compositor, + spans[0].x, y, + spans[1].x - spans[0].x, height, + r->opacity * spans[0].coverage); + } + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_image_unbounded_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + assert (y + height <= r->extents.height); + if (y > r->extents.y) { + pixman_image_compositor_blt (r->compositor, + r->extents.x, r->extents.y, + r->extents.width, y - r->extents.y, + 0); + } + + if (num_spans == 0) { + pixman_image_compositor_blt (r->compositor, + r->extents.x, y, + r->extents.width, height, + 0); + } else { + if (spans[0].x != r->extents.x) { + pixman_image_compositor_blt (r->compositor, + r->extents.x, y, + spans[0].x - r->extents.x, + height, + 0); + } + + do { + assert (spans[0].x < r->extents.x + r->extents.width); + pixman_image_compositor_blt (r->compositor, + spans[0].x, y, + spans[1].x - spans[0].x, height, + r->opacity * spans[0].coverage); + spans++; + } while (--num_spans > 1); + + if (spans[0].x != r->extents.x + r->extents.width) { + assert (spans[0].x < r->extents.x + r->extents.width); + pixman_image_compositor_blt (r->compositor, + spans[0].x, y, + r->extents.x + r->extents.width - spans[0].x, height, + 0); + } + } + + r->extents.y = y + height; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_image_clipped_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + assert (num_spans); + + do { + if (! spans[0].inverse) + pixman_image_compositor_blt (r->compositor, + spans[0].x, y, + spans[1].x - spans[0].x, height, + r->opacity * spans[0].coverage); + spans++; + } while (--num_spans > 1); + + r->extents.y = y + height; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_image_finish_unbounded_spans (void *abstract_renderer) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (r->extents.y < r->extents.height) { + pixman_image_compositor_blt (r->compositor, + r->extents.x, r->extents.y, + r->extents.width, + r->extents.height - r->extents.y, + 0); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +span_renderer_init (cairo_abstract_span_renderer_t *_r, + const cairo_composite_rectangles_t *composite, + cairo_bool_t needs_clip) +{ + cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; + cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; + const cairo_pattern_t *source = &composite->source_pattern.base; + cairo_operator_t op = composite->op; + int src_x, src_y; + int mask_x, mask_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (op == CAIRO_OPERATOR_CLEAR) { + op = PIXMAN_OP_LERP_CLEAR; + } else if (dst->base.is_clear && + (op == CAIRO_OPERATOR_SOURCE || + op == CAIRO_OPERATOR_OVER || + op == CAIRO_OPERATOR_ADD)) { + op = PIXMAN_OP_SRC; + } else if (op == CAIRO_OPERATOR_SOURCE) { + op = PIXMAN_OP_LERP_SRC; + } else { + op = _pixman_operator (op); + } + + r->compositor = NULL; + r->mask = NULL; + r->src = _pixman_image_for_pattern (dst, source, FALSE, + &composite->unbounded, + &composite->source_sample_area, + &src_x, &src_y); + if (unlikely (r->src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + r->opacity = 1.0; + if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { + r->opacity = composite->mask_pattern.solid.color.alpha; + } else { + r->mask = _pixman_image_for_pattern (dst, + &composite->mask_pattern.base, + TRUE, + &composite->unbounded, + &composite->mask_sample_area, + &mask_x, &mask_y); + if (unlikely (r->mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* XXX Component-alpha? */ + if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && + _cairo_pattern_is_opaque (source, &composite->source_sample_area)) + { + pixman_image_unref (r->src); + r->src = r->mask; + src_x = mask_x; + src_y = mask_y; + r->mask = NULL; + } + } + + if (composite->is_bounded) { + if (r->opacity == 1.) + r->base.render_rows = _cairo_image_bounded_opaque_spans; + else + r->base.render_rows = _cairo_image_bounded_spans; + r->base.finish = NULL; + } else { + if (needs_clip) + r->base.render_rows = _cairo_image_clipped_spans; + else + r->base.render_rows = _cairo_image_unbounded_spans; + r->base.finish = _cairo_image_finish_unbounded_spans; + r->extents = composite->unbounded; + r->extents.height += r->extents.y; + } + + r->compositor = + pixman_image_create_compositor (op, r->src, r->mask, dst->pixman_image, + composite->unbounded.x + src_x, + composite->unbounded.y + src_y, + composite->unbounded.x + mask_x, + composite->unbounded.y + mask_y, + composite->unbounded.x, + composite->unbounded.y, + composite->unbounded.width, + composite->unbounded.height); + if (unlikely (r->compositor == NULL)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + return CAIRO_STATUS_SUCCESS; +} + +static void +span_renderer_fini (cairo_abstract_span_renderer_t *_r, + cairo_int_status_t status) +{ + cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *) _r; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (status == CAIRO_INT_STATUS_SUCCESS && r->base.finish) + r->base.finish (r); + + if (r->compositor) + pixman_image_compositor_destroy (r->compositor); + + if (r->src) + pixman_image_unref (r->src); + if (r->mask) + pixman_image_unref (r->mask); +} +#else +typedef struct _cairo_image_span_renderer { + cairo_span_renderer_t base; + + const cairo_composite_rectangles_t *composite; + + float opacity; + uint8_t op; + int bpp; + + pixman_image_t *src, *mask; + union { + struct fill { + int stride; + uint8_t *data; + uint32_t pixel; + } fill; + struct blit { + int stride; + uint8_t *data; + int src_stride; + uint8_t *src_data; + } blit; + struct composite { + pixman_image_t *dst; + int src_x, src_y; + int mask_x, mask_y; + int run_length; + } composite; + struct finish { + cairo_rectangle_int_t extents; + int src_x, src_y; + int stride; + uint8_t *data; + } mask; + } u; + uint8_t _buf[0]; +#define SZ_BUF (int)(sizeof (cairo_abstract_span_renderer_t) - sizeof (cairo_image_span_renderer_t)) +} cairo_image_span_renderer_t; +COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t)); + +static cairo_status_t +_cairo_image_spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + uint8_t *mask, *row; + int len; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + mask = r->u.mask.data + (y - r->u.mask.extents.y) * r->u.mask.stride; + mask += spans[0].x - r->u.mask.extents.x; + row = mask; + + do { + len = spans[1].x - spans[0].x; + if (spans[0].coverage) { + *row++ = r->opacity * spans[0].coverage; + if (--len) + memset (row, row[-1], len); + } + row += len; + spans++; + } while (--num_spans > 1); + + len = row - mask; + row = mask; + while (--height) { + mask += r->u.mask.stride; + memcpy (mask, row, len); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_image_spans_and_zero (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + uint8_t *mask; + int len; + + mask = r->u.mask.data; + if (y > r->u.mask.extents.y) { + len = (y - r->u.mask.extents.y) * r->u.mask.stride; + memset (mask, 0, len); + mask += len; + } + + r->u.mask.extents.y = y + height; + r->u.mask.data = mask + height * r->u.mask.stride; + if (num_spans == 0) { + memset (mask, 0, height * r->u.mask.stride); + } else { + uint8_t *row = mask; + + if (spans[0].x != r->u.mask.extents.x) { + len = spans[0].x - r->u.mask.extents.x; + memset (row, 0, len); + row += len; + } + + do { + len = spans[1].x - spans[0].x; + *row++ = r->opacity * spans[0].coverage; + if (len > 1) { + memset (row, row[-1], --len); + row += len; + } + spans++; + } while (--num_spans > 1); + + if (spans[0].x != r->u.mask.extents.x + r->u.mask.extents.width) { + len = r->u.mask.extents.x + r->u.mask.extents.width - spans[0].x; + memset (row, 0, len); + } + + row = mask; + while (--height) { + mask += r->u.mask.stride; + memcpy (mask, row, r->u.mask.extents.width); + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_image_finish_spans_and_zero (void *abstract_renderer) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (r->u.mask.extents.y < r->u.mask.extents.height) + memset (r->u.mask.data, 0, (r->u.mask.extents.height - r->u.mask.extents.y) * r->u.mask.stride); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_fill8_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + do { + if (spans[0].coverage) { + int len = spans[1].x - spans[0].x; + uint8_t *d = r->u.fill.data + r->u.fill.stride*y + spans[0].x; + if (len == 1) + *d = r->u.fill.pixel; + else + memset(d, r->u.fill.pixel, len); + } + spans++; + } while (--num_spans > 1); + } else { + do { + if (spans[0].coverage) { + int yy = y, hh = h; + do { + int len = spans[1].x - spans[0].x; + uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; + if (len == 1) + *d = r->u.fill.pixel; + else + memset(d, r->u.fill.pixel, len); + yy++; + } while (--hh); + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_fill16_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + do { + if (spans[0].coverage) { + int len = spans[1].x - spans[0].x; + uint16_t *d = (uint16_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*2); + while (len--) + *d++ = r->u.fill.pixel; + } + spans++; + } while (--num_spans > 1); + } else { + do { + if (spans[0].coverage) { + int yy = y, hh = h; + do { + int len = spans[1].x - spans[0].x; + uint16_t *d = (uint16_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*2); + while (len--) + *d++ = r->u.fill.pixel; + yy++; + } while (--hh); + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_fill32_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + do { + if (spans[0].coverage) { + int len = spans[1].x - spans[0].x; + if (len > 32) { + pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), r->bpp, + spans[0].x, y, len, 1, r->u.fill.pixel); + } else { + uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); + while (len--) + *d++ = r->u.fill.pixel; + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + if (spans[0].coverage) { + if (spans[1].x - spans[0].x > 16) { + pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), r->bpp, + spans[0].x, y, spans[1].x - spans[0].x, h, + r->u.fill.pixel); + } else { + int yy = y, hh = h; + do { + int len = spans[1].x - spans[0].x; + uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); + while (len--) + *d++ = r->u.fill.pixel; + yy++; + } while (--hh); + } + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +#if 0 +static cairo_status_t +_fill_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + do { + if (spans[0].coverage) { + pixman_fill ((uint32_t *) r->data, r->stride, r->bpp, + spans[0].x, y, + spans[1].x - spans[0].x, h, + r->pixel); + } + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} +#endif + +static cairo_status_t +_blit_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + int cpp; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + cpp = r->bpp/8; + if (likely (h == 1)) { + uint8_t *src = r->u.blit.src_data + y*r->u.blit.src_stride; + uint8_t *dst = r->u.blit.data + y*r->u.blit.stride; + do { + if (spans[0].coverage) { + void *s = src + spans[0].x*cpp; + void *d = dst + spans[0].x*cpp; + int len = (spans[1].x - spans[0].x) * cpp; + switch (len) { + case 1: + *(uint8_t *)d = *(uint8_t *)s; + break; + case 2: + *(uint16_t *)d = *(uint16_t *)s; + break; + case 4: + *(uint32_t *)d = *(uint32_t *)s; + break; +#if HAVE_UINT64_T + case 8: + *(uint64_t *)d = *(uint64_t *)s; + break; +#endif + default: + memcpy(d, s, len); + break; + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + if (spans[0].coverage) { + int yy = y, hh = h; + do { + void *src = r->u.blit.src_data + yy*r->u.blit.src_stride + spans[0].x*cpp; + void *dst = r->u.blit.data + yy*r->u.blit.stride + spans[0].x*cpp; + int len = (spans[1].x - spans[0].x) * cpp; + switch (len) { + case 1: + *(uint8_t *)dst = *(uint8_t *)src; + break; + case 2: + *(uint16_t *)dst = *(uint16_t *)src; + break; + case 4: + *(uint32_t *)dst = *(uint32_t *)src; + break; +#if HAVE_UINT64_T + case 8: + *(uint64_t *)dst = *(uint64_t *)src; + break; +#endif + default: + memcpy(dst, src, len); + break; + } + yy++; + } while (--hh); + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_mono_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + do { + if (spans[0].coverage) { + pixman_image_composite32 (r->op, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, + 0, 0, + spans[0].x, y, + spans[1].x - spans[0].x, h); + } + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_mono_unbounded_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) { + pixman_image_composite32 (PIXMAN_OP_CLEAR, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, + 0, 0, + r->composite->unbounded.x, y, + r->composite->unbounded.width, h); + r->u.composite.mask_y = y + h; + return CAIRO_STATUS_SUCCESS; + } + + if (y != r->u.composite.mask_y) { + pixman_image_composite32 (PIXMAN_OP_CLEAR, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, + 0, 0, + r->composite->unbounded.x, r->u.composite.mask_y, + r->composite->unbounded.width, y - r->u.composite.mask_y); + } + + if (spans[0].x != r->composite->unbounded.x) { + pixman_image_composite32 (PIXMAN_OP_CLEAR, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, + 0, 0, + r->composite->unbounded.x, y, + spans[0].x - r->composite->unbounded.x, h); + } + + do { + int op = spans[0].coverage ? r->op : PIXMAN_OP_CLEAR; + pixman_image_composite32 (op, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, + 0, 0, + spans[0].x, y, + spans[1].x - spans[0].x, h); + spans++; + } while (--num_spans > 1); + + if (spans[0].x != r->composite->unbounded.x + r->composite->unbounded.width) { + pixman_image_composite32 (PIXMAN_OP_CLEAR, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, + 0, 0, + spans[0].x, y, + r->composite->unbounded.x + r->composite->unbounded.width - spans[0].x, h); + } + + r->u.composite.mask_y = y + h; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_mono_finish_unbounded_spans (void *abstract_renderer) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (r->u.composite.mask_y < r->composite->unbounded.y + r->composite->unbounded.height) { + pixman_image_composite32 (PIXMAN_OP_CLEAR, + r->src, NULL, r->u.composite.dst, + r->composite->unbounded.x + r->u.composite.src_x, r->u.composite.mask_y + r->u.composite.src_y, + 0, 0, + r->composite->unbounded.x, r->u.composite.mask_y, + r->composite->unbounded.width, + r->composite->unbounded.y + r->composite->unbounded.height - r->u.composite.mask_y); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +mono_renderer_init (cairo_image_span_renderer_t *r, + const cairo_composite_rectangles_t *composite, + cairo_antialias_t antialias, + cairo_bool_t needs_clip) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; + + if (antialias != CAIRO_ANTIALIAS_NONE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (!_cairo_pattern_is_opaque_solid (&composite->mask_pattern.base)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + r->base.render_rows = NULL; + if (composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { + const cairo_color_t *color; + + color = &composite->source_pattern.solid.color; + if (composite->op == CAIRO_OPERATOR_CLEAR) + color = CAIRO_COLOR_TRANSPARENT; + + if (fill_reduces_to_source (composite->op, color, dst, &r->u.fill.pixel)) { + /* Use plain C for the fill operations as the span length is + * typically small, too small to payback the startup overheads of + * using SSE2 etc. + */ + switch (PIXMAN_FORMAT_BPP(dst->pixman_format)) { + case 8: r->base.render_rows = _fill8_spans; break; + case 16: r->base.render_rows = _fill16_spans; break; + case 32: r->base.render_rows = _fill32_spans; break; + default: break; + } + r->u.fill.data = dst->data; + r->u.fill.stride = dst->stride; + } + } else if ((composite->op == CAIRO_OPERATOR_SOURCE || + (composite->op == CAIRO_OPERATOR_OVER && + (dst->base.is_clear || (dst->base.content & CAIRO_CONTENT_ALPHA) == 0))) && + composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && + composite->source_pattern.surface.surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE && + to_image_surface(composite->source_pattern.surface.surface)->format == dst->format) + { + cairo_image_surface_t *src = + to_image_surface(composite->source_pattern.surface.surface); + int tx, ty; + + if (_cairo_matrix_is_integer_translation(&composite->source_pattern.base.matrix, + &tx, &ty) && + composite->bounded.x + tx >= 0 && + composite->bounded.y + ty >= 0 && + composite->bounded.x + composite->bounded.width + tx <= src->width && + composite->bounded.y + composite->bounded.height + ty <= src->height) { + + r->u.blit.stride = dst->stride; + r->u.blit.data = dst->data; + r->u.blit.src_stride = src->stride; + r->u.blit.src_data = src->data + src->stride * ty + tx * 4; + r->base.render_rows = _blit_spans; + } + } + + if (r->base.render_rows == NULL) { + r->src = _pixman_image_for_pattern (dst, &composite->source_pattern.base, FALSE, + &composite->unbounded, + &composite->source_sample_area, + &r->u.composite.src_x, &r->u.composite.src_y); + if (unlikely (r->src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + r->u.composite.dst = to_pixman_image (composite->surface); + r->op = _pixman_operator (composite->op); + if (composite->is_bounded == 0) { + r->base.render_rows = _mono_unbounded_spans; + r->base.finish = _mono_finish_unbounded_spans; + r->u.composite.mask_y = composite->unbounded.y; + } else + r->base.render_rows = _mono_spans; + } + r->bpp = PIXMAN_FORMAT_BPP(dst->pixman_format); + + return CAIRO_INT_STATUS_SUCCESS; +} + +#define ONE_HALF 0x7f +#define RB_MASK 0x00ff00ff +#define RB_ONE_HALF 0x007f007f +#define RB_MASK_PLUS_ONE 0x01000100 +#define G_SHIFT 8 +static inline uint32_t +mul8x2_8 (uint32_t a, uint8_t b) +{ + uint32_t t = (a & RB_MASK) * b + RB_ONE_HALF; + return ((t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT) & RB_MASK; +} + +static inline uint32_t +add8x2_8x2 (uint32_t a, uint32_t b) +{ + uint32_t t = a + b; + t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK); + return t & RB_MASK; +} + +static inline uint8_t +mul8_8 (uint8_t a, uint8_t b) +{ + uint16_t t = a * (uint16_t)b + ONE_HALF; + return ((t >> G_SHIFT) + t) >> G_SHIFT; +} + +static inline uint32_t +lerp8x4 (uint32_t src, uint8_t a, uint32_t dst) +{ + return (add8x2_8x2 (mul8x2_8 (src, a), + mul8x2_8 (dst, ~a)) | + add8x2_8x2 (mul8x2_8 (src >> G_SHIFT, a), + mul8x2_8 (dst >> G_SHIFT, ~a)) << G_SHIFT); +} + +static cairo_status_t +_fill_a8_lerp_opaque_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + uint8_t *d = r->u.fill.data + r->u.fill.stride*y; + do { + uint8_t a = spans[0].coverage; + if (a) { + int len = spans[1].x - spans[0].x; + if (a == 0xff) { + memset(d + spans[0].x, r->u.fill.pixel, len); + } else { + uint8_t s = mul8_8(a, r->u.fill.pixel); + uint8_t *dst = d + spans[0].x; + a = ~a; + while (len--) { + uint8_t t = mul8_8(*dst, a); + *dst++ = t + s; + } + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + uint8_t a = spans[0].coverage; + if (a) { + int yy = y, hh = h; + if (a == 0xff) { + do { + int len = spans[1].x - spans[0].x; + uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; + memset(d, r->u.fill.pixel, len); + yy++; + } while (--hh); + } else { + uint8_t s = mul8_8(a, r->u.fill.pixel); + a = ~a; + do { + int len = spans[1].x - spans[0].x; + uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; + while (len--) { + uint8_t t = mul8_8(*d, a); + *d++ = t + s; + } + yy++; + } while (--hh); + } + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_fill_xrgb32_lerp_opaque_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + do { + uint8_t a = spans[0].coverage; + if (a) { + int len = spans[1].x - spans[0].x; + uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); + if (a == 0xff) { + if (len > 31) { + pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), 32, + spans[0].x, y, len, 1, r->u.fill.pixel); + } else { + uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); + while (len-- > 0) + *d++ = r->u.fill.pixel; + } + } else while (len-- > 0) { + *d = lerp8x4 (r->u.fill.pixel, a, *d); + d++; + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + uint8_t a = spans[0].coverage; + if (a) { + if (a == 0xff) { + if (spans[1].x - spans[0].x > 16) { + pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), 32, + spans[0].x, y, spans[1].x - spans[0].x, h, + r->u.fill.pixel); + } else { + int yy = y, hh = h; + do { + int len = spans[1].x - spans[0].x; + uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); + while (len--) + *d++ = r->u.fill.pixel; + yy++; + } while (--hh); + } + } else { + int yy = y, hh = h; + do { + int len = spans[1].x - spans[0].x; + uint32_t *d = (uint32_t *)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); + while (len--) { + *d = lerp8x4 (r->u.fill.pixel, a, *d); + d++; + } + yy++; + } while (--hh); + } + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_fill_a8_lerp_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + do { + uint8_t a = mul8_8 (spans[0].coverage, r->bpp); + if (a) { + int len = spans[1].x - spans[0].x; + uint8_t *d = r->u.fill.data + r->u.fill.stride*y + spans[0].x; + uint16_t p = (uint16_t)a * r->u.fill.pixel + 0x7f; + uint16_t ia = ~a; + while (len--) { + uint16_t t = *d*ia + p; + *d++ = (t + (t>>8)) >> 8; + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + uint8_t a = mul8_8 (spans[0].coverage, r->bpp); + if (a) { + int yy = y, hh = h; + uint16_t p = (uint16_t)a * r->u.fill.pixel + 0x7f; + uint16_t ia = ~a; + do { + int len = spans[1].x - spans[0].x; + uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; + while (len--) { + uint16_t t = *d*ia + p; + *d++ = (t + (t>>8)) >> 8; + } + yy++; + } while (--hh); + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_fill_xrgb32_lerp_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + do { + uint8_t a = mul8_8 (spans[0].coverage, r->bpp); + if (a) { + int len = spans[1].x - spans[0].x; + uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); + while (len--) { + *d = lerp8x4 (r->u.fill.pixel, a, *d); + d++; + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + uint8_t a = mul8_8 (spans[0].coverage, r->bpp); + if (a) { + int yy = y, hh = h; + do { + int len = spans[1].x - spans[0].x; + uint32_t *d = (uint32_t *)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); + while (len--) { + *d = lerp8x4 (r->u.fill.pixel, a, *d); + d++; + } + yy++; + } while (--hh); + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_blit_xrgb32_lerp_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (likely(h == 1)) { + uint8_t *src = r->u.blit.src_data + y*r->u.blit.src_stride; + uint8_t *dst = r->u.blit.data + y*r->u.blit.stride; + do { + uint8_t a = mul8_8 (spans[0].coverage, r->bpp); + if (a) { + uint32_t *s = (uint32_t*)src + spans[0].x; + uint32_t *d = (uint32_t*)dst + spans[0].x; + int len = spans[1].x - spans[0].x; + if (a == 0xff) { + if (len == 1) + *d = *s; + else + memcpy(d, s, len*4); + } else { + while (len--) { + *d = lerp8x4 (*s, a, *d); + s++, d++; + } + } + } + spans++; + } while (--num_spans > 1); + } else { + do { + uint8_t a = mul8_8 (spans[0].coverage, r->bpp); + if (a) { + int yy = y, hh = h; + do { + uint32_t *s = (uint32_t *)(r->u.blit.src_data + yy*r->u.blit.src_stride + spans[0].x * 4); + uint32_t *d = (uint32_t *)(r->u.blit.data + yy*r->u.blit.stride + spans[0].x * 4); + int len = spans[1].x - spans[0].x; + if (a == 0xff) { + if (len == 1) + *d = *s; + else + memcpy(d, s, len * 4); + } else { + while (len--) { + *d = lerp8x4 (*s, a, *d); + s++, d++; + } + } + yy++; + } while (--hh); + } + spans++; + } while (--num_spans > 1); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_inplace_spans (void *abstract_renderer, + int y, int h, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + uint8_t *mask; + int x0, x1; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + if (num_spans == 2 && spans[0].coverage == 0xff) { + pixman_image_composite32 (r->op, r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + spans[0].x, y, + spans[1].x - spans[0].x, h); + return CAIRO_STATUS_SUCCESS; + } + + mask = (uint8_t *)pixman_image_get_data (r->mask); + x1 = x0 = spans[0].x; + do { + int len = spans[1].x - spans[0].x; + *mask++ = spans[0].coverage; + if (len > 1) { + if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) { + if (x1 != x0) { + pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + x1 - x0, h); + } + pixman_image_composite32 (r->op, r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + spans[0].x, y, + len, h); + mask = (uint8_t *)pixman_image_get_data (r->mask); + x0 = spans[1].x; + } else if (spans[0].coverage == 0x0 && + x1 - x0 > r->u.composite.run_length) { + pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + x1 - x0, h); + mask = (uint8_t *)pixman_image_get_data (r->mask); + x0 = spans[1].x; + }else { + memset (mask, spans[0].coverage, --len); + mask += len; + } + } + x1 = spans[1].x; + spans++; + } while (--num_spans > 1); + + if (x1 != x0) { + pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + x1 - x0, h); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_inplace_opacity_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + uint8_t *mask; + int x0, x1; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + mask = (uint8_t *)pixman_image_get_data (r->mask); + x1 = x0 = spans[0].x; + do { + int len = spans[1].x - spans[0].x; + uint8_t m = mul8_8(spans[0].coverage, r->bpp); + *mask++ = m; + if (len > 1) { + if (m == 0 && + x1 - x0 > r->u.composite.run_length) { + pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + x1 - x0, h); + mask = (uint8_t *)pixman_image_get_data (r->mask); + x0 = spans[1].x; + }else { + memset (mask, m, --len); + mask += len; + } + } + x1 = spans[1].x; + spans++; + } while (--num_spans > 1); + + if (x1 != x0) { + pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + x1 - x0, h); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_inplace_src_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + uint8_t *m; + int x0; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + x0 = spans[0].x; + m = r->_buf; + do { + int len = spans[1].x - spans[0].x; + if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) { + if (spans[0].x != x0) { +#if PIXMAN_HAS_OP_LERP + pixman_image_composite32 (PIXMAN_OP_LERP_SRC, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#else + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + r->mask, NULL, r->u.composite.dst, + 0, 0, + 0, 0, + x0, y, + spans[0].x - x0, h); + pixman_image_composite32 (PIXMAN_OP_ADD, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#endif + } + + pixman_image_composite32 (PIXMAN_OP_SRC, + r->src, NULL, r->u.composite.dst, + spans[0].x + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + spans[0].x, y, + spans[1].x - spans[0].x, h); + + m = r->_buf; + x0 = spans[1].x; + } else if (spans[0].coverage == 0x0) { + if (spans[0].x != x0) { +#if PIXMAN_HAS_OP_LERP + pixman_image_composite32 (PIXMAN_OP_LERP_SRC, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#else + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + r->mask, NULL, r->u.composite.dst, + 0, 0, + 0, 0, + x0, y, + spans[0].x - x0, h); + pixman_image_composite32 (PIXMAN_OP_ADD, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#endif + } + + m = r->_buf; + x0 = spans[1].x; + } else { + *m++ = spans[0].coverage; + if (len > 1) { + memset (m, spans[0].coverage, --len); + m += len; + } + } + spans++; + } while (--num_spans > 1); + + if (spans[0].x != x0) { +#if PIXMAN_HAS_OP_LERP + pixman_image_composite32 (PIXMAN_OP_LERP_SRC, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#else + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + r->mask, NULL, r->u.composite.dst, + 0, 0, + 0, 0, + x0, y, + spans[0].x - x0, h); + pixman_image_composite32 (PIXMAN_OP_ADD, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#endif + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_inplace_src_opacity_spans (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + cairo_image_span_renderer_t *r = abstract_renderer; + uint8_t *mask; + int x0; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + x0 = spans[0].x; + mask = (uint8_t *)pixman_image_get_data (r->mask); + do { + int len = spans[1].x - spans[0].x; + uint8_t m = mul8_8(spans[0].coverage, r->bpp); + if (m == 0) { + if (spans[0].x != x0) { +#if PIXMAN_HAS_OP_LERP + pixman_image_composite32 (PIXMAN_OP_LERP_SRC, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#else + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + r->mask, NULL, r->u.composite.dst, + 0, 0, + 0, 0, + x0, y, + spans[0].x - x0, h); + pixman_image_composite32 (PIXMAN_OP_ADD, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#endif + } + + mask = (uint8_t *)pixman_image_get_data (r->mask); + x0 = spans[1].x; + } else { + *mask++ = m; + if (len > 1) { + memset (mask, m, --len); + mask += len; + } + } + spans++; + } while (--num_spans > 1); + + if (spans[0].x != x0) { +#if PIXMAN_HAS_OP_LERP + pixman_image_composite32 (PIXMAN_OP_LERP_SRC, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#else + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + r->mask, NULL, r->u.composite.dst, + 0, 0, + 0, 0, + x0, y, + spans[0].x - x0, h); + pixman_image_composite32 (PIXMAN_OP_ADD, + r->src, r->mask, r->u.composite.dst, + x0 + r->u.composite.src_x, + y + r->u.composite.src_y, + 0, 0, + x0, y, + spans[0].x - x0, h); +#endif + } + + return CAIRO_STATUS_SUCCESS; +} + +static void free_pixels (pixman_image_t *image, void *data) +{ + free (data); +} + +static cairo_int_status_t +inplace_renderer_init (cairo_image_span_renderer_t *r, + const cairo_composite_rectangles_t *composite, + cairo_antialias_t antialias, + cairo_bool_t needs_clip) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; + uint8_t *buf; + + if (composite->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) + return CAIRO_INT_STATUS_UNSUPPORTED; + + r->base.render_rows = NULL; + r->bpp = composite->mask_pattern.solid.color.alpha_short >> 8; + + if (composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { + const cairo_color_t *color; + + color = &composite->source_pattern.solid.color; + if (composite->op == CAIRO_OPERATOR_CLEAR) + color = CAIRO_COLOR_TRANSPARENT; + + if (fill_reduces_to_source (composite->op, color, dst, &r->u.fill.pixel)) { + /* Use plain C for the fill operations as the span length is + * typically small, too small to payback the startup overheads of + * using SSE2 etc. + */ + if (r->bpp == 0xff) { + switch (dst->format) { + case CAIRO_FORMAT_A8: + r->base.render_rows = _fill_a8_lerp_opaque_spans; + break; + case CAIRO_FORMAT_RGB24: + case CAIRO_FORMAT_ARGB32: + r->base.render_rows = _fill_xrgb32_lerp_opaque_spans; + break; + case CAIRO_FORMAT_A1: + case CAIRO_FORMAT_RGB16_565: + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_INVALID: + default: break; + } + } else { + switch (dst->format) { + case CAIRO_FORMAT_A8: + r->base.render_rows = _fill_a8_lerp_spans; + break; + case CAIRO_FORMAT_RGB24: + case CAIRO_FORMAT_ARGB32: + r->base.render_rows = _fill_xrgb32_lerp_spans; + break; + case CAIRO_FORMAT_A1: + case CAIRO_FORMAT_RGB16_565: + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_INVALID: + default: break; + } + } + r->u.fill.data = dst->data; + r->u.fill.stride = dst->stride; + } + } else if ((dst->format == CAIRO_FORMAT_ARGB32 || dst->format == CAIRO_FORMAT_RGB24) && + (composite->op == CAIRO_OPERATOR_SOURCE || + (composite->op == CAIRO_OPERATOR_OVER && + (dst->base.is_clear || (dst->base.content & CAIRO_CONTENT_ALPHA) == 0))) && + composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && + composite->source_pattern.surface.surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE && + to_image_surface(composite->source_pattern.surface.surface)->format == dst->format) + { + cairo_image_surface_t *src = + to_image_surface(composite->source_pattern.surface.surface); + int tx, ty; + + if (_cairo_matrix_is_integer_translation(&composite->source_pattern.base.matrix, + &tx, &ty) && + composite->bounded.x + tx >= 0 && + composite->bounded.y + ty >= 0 && + composite->bounded.x + composite->bounded.width + tx <= src->width && + composite->bounded.y + composite->bounded.height + ty <= src->height) { + + assert(PIXMAN_FORMAT_BPP(dst->pixman_format) == 32); + r->u.blit.stride = dst->stride; + r->u.blit.data = dst->data; + r->u.blit.src_stride = src->stride; + r->u.blit.src_data = src->data + src->stride * ty + tx * 4; + r->base.render_rows = _blit_xrgb32_lerp_spans; + } + } + if (r->base.render_rows == NULL) { + const cairo_pattern_t *src = &composite->source_pattern.base; + unsigned int width; + + if (composite->is_bounded == 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + r->base.render_rows = r->bpp == 0xff ? _inplace_spans : _inplace_opacity_spans; + width = (composite->bounded.width + 3) & ~3; + + r->u.composite.run_length = 8; + if (src->type == CAIRO_PATTERN_TYPE_LINEAR || + src->type == CAIRO_PATTERN_TYPE_RADIAL) + r->u.composite.run_length = 256; + if (dst->base.is_clear && + (composite->op == CAIRO_OPERATOR_SOURCE || + composite->op == CAIRO_OPERATOR_OVER || + composite->op == CAIRO_OPERATOR_ADD)) { + r->op = PIXMAN_OP_SRC; + } else if (composite->op == CAIRO_OPERATOR_SOURCE) { + r->base.render_rows = r->bpp == 0xff ? _inplace_src_spans : _inplace_src_opacity_spans; + r->u.composite.mask_y = r->composite->unbounded.y; + width = (composite->unbounded.width + 3) & ~3; + } else if (composite->op == CAIRO_OPERATOR_CLEAR) { + r->op = PIXMAN_OP_OUT_REVERSE; + src = NULL; + } else { + r->op = _pixman_operator (composite->op); + } + + r->src = _pixman_image_for_pattern (dst, src, FALSE, + &composite->bounded, + &composite->source_sample_area, + &r->u.composite.src_x, &r->u.composite.src_y); + if (unlikely (r->src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* Create an effectively unbounded mask by repeating the single line */ + buf = r->_buf; + if (width > SZ_BUF) { + buf = malloc (width); + if (unlikely (buf == NULL)) { + pixman_image_unref (r->src); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + r->mask = pixman_image_create_bits (PIXMAN_a8, + width, composite->unbounded.height, + (uint32_t *)buf, 0); + if (unlikely (r->mask == NULL)) { + pixman_image_unref (r->src); + if (buf != r->_buf) + free (buf); + return _cairo_error(CAIRO_STATUS_NO_MEMORY); + } + + if (buf != r->_buf) + pixman_image_set_destroy_function (r->mask, free_pixels, buf); + + r->u.composite.dst = dst->pixman_image; + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +span_renderer_init (cairo_abstract_span_renderer_t *_r, + const cairo_composite_rectangles_t *composite, + cairo_antialias_t antialias, + cairo_bool_t needs_clip) +{ + cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; + cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; + const cairo_pattern_t *source = &composite->source_pattern.base; + cairo_operator_t op = composite->op; + cairo_int_status_t status; + + TRACE ((stderr, "%s: antialias=%d, needs_clip=%d\n", __FUNCTION__, + antialias, needs_clip)); + + if (needs_clip) + return CAIRO_INT_STATUS_UNSUPPORTED; + + r->composite = composite; + r->mask = NULL; + r->src = NULL; + r->base.finish = NULL; + + status = mono_renderer_init (r, composite, antialias, needs_clip); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = inplace_renderer_init (r, composite, antialias, needs_clip); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + r->bpp = 0; + + if (op == CAIRO_OPERATOR_CLEAR) { +#if PIXMAN_HAS_OP_LERP + op = PIXMAN_OP_LERP_CLEAR; +#else + source = &_cairo_pattern_white.base; + op = PIXMAN_OP_OUT_REVERSE; +#endif + } else if (dst->base.is_clear && + (op == CAIRO_OPERATOR_SOURCE || + op == CAIRO_OPERATOR_OVER || + op == CAIRO_OPERATOR_ADD)) { + op = PIXMAN_OP_SRC; + } else if (op == CAIRO_OPERATOR_SOURCE) { + if (_cairo_pattern_is_opaque (&composite->source_pattern.base, + &composite->source_sample_area)) + { + op = PIXMAN_OP_OVER; + } + else + { +#if PIXMAN_HAS_OP_LERP + op = PIXMAN_OP_LERP_SRC; +#else + return CAIRO_INT_STATUS_UNSUPPORTED; +#endif + } + } else { + op = _pixman_operator (op); + } + r->op = op; + + r->src = _pixman_image_for_pattern (dst, source, FALSE, + &composite->unbounded, + &composite->source_sample_area, + &r->u.mask.src_x, &r->u.mask.src_y); + if (unlikely (r->src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + r->opacity = 1.0; + if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { + r->opacity = composite->mask_pattern.solid.color.alpha; + } else { + pixman_image_t *mask; + int mask_x, mask_y; + + mask = _pixman_image_for_pattern (dst, + &composite->mask_pattern.base, + TRUE, + &composite->unbounded, + &composite->mask_sample_area, + &mask_x, &mask_y); + if (unlikely (mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* XXX Component-alpha? */ + if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && + _cairo_pattern_is_opaque (source, &composite->source_sample_area)) + { + pixman_image_unref (r->src); + r->src = mask; + r->u.mask.src_x = mask_x; + r->u.mask.src_y = mask_y; + mask = NULL; + } + + if (mask) { + pixman_image_unref (mask); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + + r->u.mask.extents = composite->unbounded; + r->u.mask.stride = (r->u.mask.extents.width + 3) & ~3; + if (r->u.mask.extents.height * r->u.mask.stride > SZ_BUF) { + r->mask = pixman_image_create_bits (PIXMAN_a8, + r->u.mask.extents.width, + r->u.mask.extents.height, + NULL, 0); + + r->base.render_rows = _cairo_image_spans; + r->base.finish = NULL; + } else { + r->mask = pixman_image_create_bits (PIXMAN_a8, + r->u.mask.extents.width, + r->u.mask.extents.height, + (uint32_t *)r->_buf, r->u.mask.stride); + + r->base.render_rows = _cairo_image_spans_and_zero; + r->base.finish = _cairo_image_finish_spans_and_zero; + } + if (unlikely (r->mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + r->u.mask.data = (uint8_t *) pixman_image_get_data (r->mask); + r->u.mask.stride = pixman_image_get_stride (r->mask); + + r->u.mask.extents.height += r->u.mask.extents.y; + return CAIRO_STATUS_SUCCESS; +} + +static void +span_renderer_fini (cairo_abstract_span_renderer_t *_r, + cairo_int_status_t status) +{ + cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *) _r; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + if (r->base.finish) + r->base.finish (r); + } + if (likely (status == CAIRO_INT_STATUS_SUCCESS && r->bpp == 0)) { + const cairo_composite_rectangles_t *composite = r->composite; + + pixman_image_composite32 (r->op, r->src, r->mask, + to_pixman_image (composite->surface), + composite->unbounded.x + r->u.mask.src_x, + composite->unbounded.y + r->u.mask.src_y, + 0, 0, + composite->unbounded.x, + composite->unbounded.y, + composite->unbounded.width, + composite->unbounded.height); + } + + if (r->src) + pixman_image_unref (r->src); + if (r->mask) + pixman_image_unref (r->mask); +} +#endif + +const cairo_compositor_t * +_cairo_image_spans_compositor_get (void) +{ + static cairo_spans_compositor_t spans; + static cairo_compositor_t shape; + + if (spans.base.delegate == NULL) { + _cairo_shape_mask_compositor_init (&shape, + _cairo_image_traps_compositor_get()); + shape.glyphs = NULL; + + _cairo_spans_compositor_init (&spans, &shape); + + spans.flags = 0; +#if PIXMAN_HAS_OP_LERP + spans.flags |= CAIRO_SPANS_COMPOSITOR_HAS_LERP; +#endif + + //spans.acquire = acquire; + //spans.release = release; + spans.fill_boxes = fill_boxes; + spans.draw_image_boxes = draw_image_boxes; + //spans.copy_boxes = copy_boxes; + spans.pattern_to_surface = _cairo_image_source_create_for_pattern; + //spans.check_composite_boxes = check_composite_boxes; + spans.composite_boxes = composite_boxes; + //spans.check_span_renderer = check_span_renderer; + spans.renderer_init = span_renderer_init; + spans.renderer_fini = span_renderer_fini; + } + + return &spans.base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-info-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-image-info-private.h new file mode 100644 index 00000000000..e64928e40ec --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-info-private.h @@ -0,0 +1,68 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + */ + +#ifndef CAIRO_IMAGE_INFO_PRIVATE_H +#define CAIRO_IMAGE_INFO_PRIVATE_H + +#include "cairoint.h" + +typedef struct _cairo_image_info { + int width; + int height; + int num_components; + int bits_per_component; +} cairo_image_info_t; + +cairo_private cairo_int_status_t +_cairo_image_info_get_jpeg_info (cairo_image_info_t *info, + const unsigned char *data, + long length); + +cairo_private cairo_int_status_t +_cairo_image_info_get_jpx_info (cairo_image_info_t *info, + const unsigned char *data, + unsigned long length); + +cairo_private cairo_int_status_t +_cairo_image_info_get_png_info (cairo_image_info_t *info, + const unsigned char *data, + unsigned long length); + +cairo_private cairo_int_status_t +_cairo_image_info_get_jbig2_info (cairo_image_info_t *info, + const unsigned char *data, + unsigned long length); + +#endif /* CAIRO_IMAGE_INFO_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-info.c b/Build/source/libs/cairo/cairo-src/src/cairo-image-info.c new file mode 100644 index 00000000000..26e7ae5afd1 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-info.c @@ -0,0 +1,421 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-image-info-private.h" + +/* JPEG (image/jpeg) + * + * http://www.w3.org/Graphics/JPEG/itu-t81.pdf + */ + +/* Markers with no parameters. All other markers are followed by a two + * byte length of the parameters. */ +#define TEM 0x01 +#define RST_begin 0xd0 +#define RST_end 0xd7 +#define SOI 0xd8 +#define EOI 0xd9 + +/* Start of frame markers. */ +#define SOF0 0xc0 +#define SOF1 0xc1 +#define SOF2 0xc2 +#define SOF3 0xc3 +#define SOF5 0xc5 +#define SOF6 0xc6 +#define SOF7 0xc7 +#define SOF9 0xc9 +#define SOF10 0xca +#define SOF11 0xcb +#define SOF13 0xcd +#define SOF14 0xce +#define SOF15 0xcf + +static const unsigned char * +_jpeg_skip_segment (const unsigned char *p) +{ + int len; + + p++; + len = (p[0] << 8) | p[1]; + + return p + len; +} + +static void +_jpeg_extract_info (cairo_image_info_t *info, const unsigned char *p) +{ + info->width = (p[6] << 8) + p[7]; + info->height = (p[4] << 8) + p[5]; + info->num_components = p[8]; + info->bits_per_component = p[3]; +} + +cairo_int_status_t +_cairo_image_info_get_jpeg_info (cairo_image_info_t *info, + const unsigned char *data, + long length) +{ + const unsigned char *p = data; + + while (p + 1 < data + length) { + if (*p != 0xff) + return CAIRO_INT_STATUS_UNSUPPORTED; + p++; + + switch (*p) { + /* skip fill bytes */ + case 0xff: + p++; + break; + + case TEM: + case SOI: + case EOI: + p++; + break; + + case SOF0: + case SOF1: + case SOF2: + case SOF3: + case SOF5: + case SOF6: + case SOF7: + case SOF9: + case SOF10: + case SOF11: + case SOF13: + case SOF14: + case SOF15: + /* Start of frame found. Extract the image parameters. */ + if (p + 8 > data + length) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _jpeg_extract_info (info, p); + return CAIRO_STATUS_SUCCESS; + + default: + if (*p >= RST_begin && *p <= RST_end) { + p++; + break; + } + + if (p + 2 > data + length) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p = _jpeg_skip_segment (p); + break; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +/* JPEG 2000 (image/jp2) + * + * http://www.jpeg.org/public/15444-1annexi.pdf + */ + +#define JPX_FILETYPE 0x66747970 +#define JPX_JP2_HEADER 0x6A703268 +#define JPX_IMAGE_HEADER 0x69686472 + +static const unsigned char _jpx_signature[] = { + 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a +}; + +static const unsigned char * +_jpx_next_box (const unsigned char *p) +{ + return p + get_unaligned_be32 (p); +} + +static const unsigned char * +_jpx_get_box_contents (const unsigned char *p) +{ + return p + 8; +} + +static cairo_bool_t +_jpx_match_box (const unsigned char *p, const unsigned char *end, uint32_t type) +{ + uint32_t length; + + if (p + 8 < end) { + length = get_unaligned_be32 (p); + if (get_unaligned_be32 (p + 4) == type && p + length < end) + return TRUE; + } + + return FALSE; +} + +static const unsigned char * +_jpx_find_box (const unsigned char *p, const unsigned char *end, uint32_t type) +{ + while (p < end) { + if (_jpx_match_box (p, end, type)) + return p; + p = _jpx_next_box (p); + } + + return NULL; +} + +static void +_jpx_extract_info (const unsigned char *p, cairo_image_info_t *info) +{ + info->height = get_unaligned_be32 (p); + info->width = get_unaligned_be32 (p + 4); + info->num_components = (p[8] << 8) + p[9]; + info->bits_per_component = p[10]; +} + +cairo_int_status_t +_cairo_image_info_get_jpx_info (cairo_image_info_t *info, + const unsigned char *data, + unsigned long length) +{ + const unsigned char *p = data; + const unsigned char *end = data + length; + + /* First 12 bytes must be the JPEG 2000 signature box. */ + if (length < ARRAY_LENGTH(_jpx_signature) || + memcmp(p, _jpx_signature, ARRAY_LENGTH(_jpx_signature)) != 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p += ARRAY_LENGTH(_jpx_signature); + + /* Next box must be a File Type Box */ + if (! _jpx_match_box (p, end, JPX_FILETYPE)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p = _jpx_next_box (p); + + /* Locate the JP2 header box. */ + p = _jpx_find_box (p, end, JPX_JP2_HEADER); + if (!p) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Step into the JP2 header box. First box must be the Image + * Header */ + p = _jpx_get_box_contents (p); + if (! _jpx_match_box (p, end, JPX_IMAGE_HEADER)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Get the image info */ + p = _jpx_get_box_contents (p); + _jpx_extract_info (p, info); + + return CAIRO_STATUS_SUCCESS; +} + +/* PNG (image/png) + * + * http://www.w3.org/TR/2003/REC-PNG-20031110/ + */ + +#define PNG_IHDR 0x49484452 + +static const unsigned char _png_magic[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; + +cairo_int_status_t +_cairo_image_info_get_png_info (cairo_image_info_t *info, + const unsigned char *data, + unsigned long length) +{ + const unsigned char *p = data; + const unsigned char *end = data + length; + + if (length < 8 || memcmp (data, _png_magic, 8) != 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p += 8; + + /* The first chunk must be IDHR. IDHR has 13 bytes of data plus + * the 12 bytes of overhead for the chunk. */ + if (p + 13 + 12 > end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p += 4; + if (get_unaligned_be32 (p) != PNG_IHDR) + return CAIRO_INT_STATUS_UNSUPPORTED; + + p += 4; + info->width = get_unaligned_be32 (p); + p += 4; + info->height = get_unaligned_be32 (p); + + return CAIRO_STATUS_SUCCESS; +} + +static const unsigned char * +_jbig2_find_data_end (const unsigned char *p, + const unsigned char *end, + int type) +{ + unsigned char end_seq[2]; + int mmr; + + /* Segments of type "Immediate generic region" may have an + * unspecified data length. The JBIG2 specification specifies the + * method to find the end of the data for these segments. */ + if (type == 36 || type == 38 || type == 39) { + if (p + 18 < end) { + mmr = p[17] & 0x01; + if (mmr) { + /* MMR encoding ends with 0x00, 0x00 */ + end_seq[0] = 0x00; + end_seq[1] = 0x00; + } else { + /* Template encoding ends with 0xff, 0xac */ + end_seq[0] = 0xff; + end_seq[1] = 0xac; + } + p += 18; + while (p < end) { + if (p[0] == end_seq[0] && p[1] == end_seq[1]) { + /* Skip the 2 terminating bytes and the 4 byte row count that follows. */ + p += 6; + if (p < end) + return p; + } + p++; + } + } + } + + return NULL; +} + +static const unsigned char * +_jbig2_get_next_segment (const unsigned char *p, + const unsigned char *end, + int *type, + const unsigned char **data, + unsigned long *data_len) +{ + unsigned long seg_num; + cairo_bool_t big_page_size; + int num_segs; + int ref_seg_bytes; + int referred_size; + + if (p + 6 >= end) + return NULL; + + seg_num = get_unaligned_be32 (p); + *type = p[4] & 0x3f; + big_page_size = (p[4] & 0x40) != 0; + p += 5; + + num_segs = p[0] >> 5; + if (num_segs == 7) { + num_segs = get_unaligned_be32 (p) & 0x1fffffff; + ref_seg_bytes = 4 + ((num_segs + 1)/8); + } else { + ref_seg_bytes = 1; + } + p += ref_seg_bytes; + + if (seg_num <= 256) + referred_size = 1; + else if (seg_num <= 65536) + referred_size = 2; + else + referred_size = 4; + + p += num_segs * referred_size; + p += big_page_size ? 4 : 1; + if (p + 4 >= end) + return NULL; + + *data_len = get_unaligned_be32 (p); + p += 4; + *data = p; + + if (*data_len == 0xffffffff) { + /* if data length is -1 we have to scan through the data to find the end */ + p = _jbig2_find_data_end (*data, end, *type); + if (!p || p >= end) + return NULL; + + *data_len = p - *data; + } else { + p += *data_len; + } + + if (p < end) + return p; + else + return NULL; +} + +static void +_jbig2_extract_info (cairo_image_info_t *info, const unsigned char *p) +{ + info->width = get_unaligned_be32 (p); + info->height = get_unaligned_be32 (p + 4); + info->num_components = 1; + info->bits_per_component = 1; +} + +cairo_int_status_t +_cairo_image_info_get_jbig2_info (cairo_image_info_t *info, + const unsigned char *data, + unsigned long length) +{ + const unsigned char *p = data; + const unsigned char *end = data + length; + int seg_type; + const unsigned char *seg_data; + unsigned long seg_data_len; + + while (p && p < end) { + p = _jbig2_get_next_segment (p, end, &seg_type, &seg_data, &seg_data_len); + if (p && seg_type == 48 && seg_data_len > 8) { + /* page information segment */ + _jbig2_extract_info (info, seg_data); + return CAIRO_STATUS_SUCCESS; + } + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-source.c b/Build/source/libs/cairo/cairo-src/src/cairo-image-source.c new file mode 100644 index 00000000000..950053db2c1 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-source.c @@ -0,0 +1,1601 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * Copyright © 2009,2010,2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* The purpose of this file/surface is to simply translate a pattern + * to a pixman_image_t and thence to feed it back to the general + * compositor interface. + */ + +#include "cairoint.h" + +#include "cairo-image-surface-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-error-private.h" +#include "cairo-pattern-inline.h" +#include "cairo-paginated-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-observer-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-private.h" + +#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ + +#if CAIRO_NO_MUTEX +#define PIXMAN_HAS_ATOMIC_OPS 1 +#endif + +#if PIXMAN_HAS_ATOMIC_OPS +static pixman_image_t *__pixman_transparent_image; +static pixman_image_t *__pixman_black_image; +static pixman_image_t *__pixman_white_image; + +static pixman_image_t * +_pixman_transparent_image (void) +{ + pixman_image_t *image; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = __pixman_transparent_image; + if (unlikely (image == NULL)) { + pixman_color_t color; + + color.red = 0x00; + color.green = 0x00; + color.blue = 0x00; + color.alpha = 0x00; + + image = pixman_image_create_solid_fill (&color); + if (unlikely (image == NULL)) + return NULL; + + if (_cairo_atomic_ptr_cmpxchg (&__pixman_transparent_image, + NULL, image)) + { + pixman_image_ref (image); + } + } else { + pixman_image_ref (image); + } + + return image; +} + +static pixman_image_t * +_pixman_black_image (void) +{ + pixman_image_t *image; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = __pixman_black_image; + if (unlikely (image == NULL)) { + pixman_color_t color; + + color.red = 0x00; + color.green = 0x00; + color.blue = 0x00; + color.alpha = 0xffff; + + image = pixman_image_create_solid_fill (&color); + if (unlikely (image == NULL)) + return NULL; + + if (_cairo_atomic_ptr_cmpxchg (&__pixman_black_image, + NULL, image)) + { + pixman_image_ref (image); + } + } else { + pixman_image_ref (image); + } + + return image; +} + +static pixman_image_t * +_pixman_white_image (void) +{ + pixman_image_t *image; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + image = __pixman_white_image; + if (unlikely (image == NULL)) { + pixman_color_t color; + + color.red = 0xffff; + color.green = 0xffff; + color.blue = 0xffff; + color.alpha = 0xffff; + + image = pixman_image_create_solid_fill (&color); + if (unlikely (image == NULL)) + return NULL; + + if (_cairo_atomic_ptr_cmpxchg (&__pixman_white_image, + NULL, image)) + { + pixman_image_ref (image); + } + } else { + pixman_image_ref (image); + } + + return image; +} + +static uint32_t +hars_petruska_f54_1_random (void) +{ +#define rol(x,k) ((x << k) | (x >> (32-k))) + static uint32_t x; + return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; +#undef rol +} + +static struct { + cairo_color_t color; + pixman_image_t *image; +} cache[16]; +static int n_cached; + +#else /* !PIXMAN_HAS_ATOMIC_OPS */ +static pixman_image_t * +_pixman_transparent_image (void) +{ + TRACE ((stderr, "%s\n", __FUNCTION__)); + return _pixman_image_for_color (CAIRO_COLOR_TRANSPARENT); +} + +static pixman_image_t * +_pixman_black_image (void) +{ + TRACE ((stderr, "%s\n", __FUNCTION__)); + return _pixman_image_for_color (CAIRO_COLOR_BLACK); +} + +static pixman_image_t * +_pixman_white_image (void) +{ + TRACE ((stderr, "%s\n", __FUNCTION__)); + return _pixman_image_for_color (CAIRO_COLOR_WHITE); +} +#endif /* !PIXMAN_HAS_ATOMIC_OPS */ + + +pixman_image_t * +_pixman_image_for_color (const cairo_color_t *cairo_color) +{ + pixman_color_t color; + pixman_image_t *image; + +#if PIXMAN_HAS_ATOMIC_OPS + int i; + + if (CAIRO_COLOR_IS_CLEAR (cairo_color)) + return _pixman_transparent_image (); + + if (CAIRO_COLOR_IS_OPAQUE (cairo_color)) { + if (cairo_color->red_short <= 0x00ff && + cairo_color->green_short <= 0x00ff && + cairo_color->blue_short <= 0x00ff) + { + return _pixman_black_image (); + } + + if (cairo_color->red_short >= 0xff00 && + cairo_color->green_short >= 0xff00 && + cairo_color->blue_short >= 0xff00) + { + return _pixman_white_image (); + } + } + + CAIRO_MUTEX_LOCK (_cairo_image_solid_cache_mutex); + for (i = 0; i < n_cached; i++) { + if (_cairo_color_equal (&cache[i].color, cairo_color)) { + image = pixman_image_ref (cache[i].image); + goto UNLOCK; + } + } +#endif + + color.red = cairo_color->red_short; + color.green = cairo_color->green_short; + color.blue = cairo_color->blue_short; + color.alpha = cairo_color->alpha_short; + + image = pixman_image_create_solid_fill (&color); +#if PIXMAN_HAS_ATOMIC_OPS + if (image == NULL) + goto UNLOCK; + + if (n_cached < ARRAY_LENGTH (cache)) { + i = n_cached++; + } else { + i = hars_petruska_f54_1_random () % ARRAY_LENGTH (cache); + pixman_image_unref (cache[i].image); + } + cache[i].image = pixman_image_ref (image); + cache[i].color = *cairo_color; + +UNLOCK: + CAIRO_MUTEX_UNLOCK (_cairo_image_solid_cache_mutex); +#endif + return image; +} + + +void +_cairo_image_reset_static_data (void) +{ +#if PIXMAN_HAS_ATOMIC_OPS + while (n_cached) + pixman_image_unref (cache[--n_cached].image); + + if (__pixman_transparent_image) { + pixman_image_unref (__pixman_transparent_image); + __pixman_transparent_image = NULL; + } + + if (__pixman_black_image) { + pixman_image_unref (__pixman_black_image); + __pixman_black_image = NULL; + } + + if (__pixman_white_image) { + pixman_image_unref (__pixman_white_image); + __pixman_white_image = NULL; + } +#endif +} + +static pixman_image_t * +_pixman_image_for_gradient (const cairo_gradient_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + int *ix, int *iy) +{ + pixman_image_t *pixman_image; + pixman_gradient_stop_t pixman_stops_static[2]; + pixman_gradient_stop_t *pixman_stops = pixman_stops_static; + pixman_transform_t pixman_transform; + cairo_matrix_t matrix; + cairo_circle_double_t extremes[2]; + pixman_point_fixed_t p1, p2; + unsigned int i; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (pattern->n_stops > ARRAY_LENGTH(pixman_stops_static)) { + pixman_stops = _cairo_malloc_ab (pattern->n_stops, + sizeof(pixman_gradient_stop_t)); + if (unlikely (pixman_stops == NULL)) + return NULL; + } + + for (i = 0; i < pattern->n_stops; i++) { + pixman_stops[i].x = _cairo_fixed_16_16_from_double (pattern->stops[i].offset); + pixman_stops[i].color.red = pattern->stops[i].color.red_short; + pixman_stops[i].color.green = pattern->stops[i].color.green_short; + pixman_stops[i].color.blue = pattern->stops[i].color.blue_short; + pixman_stops[i].color.alpha = pattern->stops[i].color.alpha_short; + } + + _cairo_gradient_pattern_fit_to_range (pattern, PIXMAN_MAX_INT >> 1, &matrix, extremes); + + p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); + p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); + p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); + p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); + + if (pattern->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + pixman_image = pixman_image_create_linear_gradient (&p1, &p2, + pixman_stops, + pattern->n_stops); + } else { + pixman_fixed_t r1, r2; + + r1 = _cairo_fixed_16_16_from_double (extremes[0].radius); + r2 = _cairo_fixed_16_16_from_double (extremes[1].radius); + + pixman_image = pixman_image_create_radial_gradient (&p1, &p2, r1, r2, + pixman_stops, + pattern->n_stops); + } + + if (pixman_stops != pixman_stops_static) + free (pixman_stops); + + if (unlikely (pixman_image == NULL)) + return NULL; + + *ix = *iy = 0; + status = _cairo_matrix_to_pixman_matrix_offset (&matrix, pattern->base.filter, + extents->x + extents->width/2., + extents->y + extents->height/2., + &pixman_transform, ix, iy); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + if (unlikely (status != CAIRO_INT_STATUS_SUCCESS) || + ! pixman_image_set_transform (pixman_image, &pixman_transform)) + { + pixman_image_unref (pixman_image); + return NULL; + } + } + + { + pixman_repeat_t pixman_repeat; + + switch (pattern->base.extend) { + default: + case CAIRO_EXTEND_NONE: + pixman_repeat = PIXMAN_REPEAT_NONE; + break; + case CAIRO_EXTEND_REPEAT: + pixman_repeat = PIXMAN_REPEAT_NORMAL; + break; + case CAIRO_EXTEND_REFLECT: + pixman_repeat = PIXMAN_REPEAT_REFLECT; + break; + case CAIRO_EXTEND_PAD: + pixman_repeat = PIXMAN_REPEAT_PAD; + break; + } + + pixman_image_set_repeat (pixman_image, pixman_repeat); + } + + return pixman_image; +} + +static pixman_image_t * +_pixman_image_for_mesh (const cairo_mesh_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + int *tx, int *ty) +{ + pixman_image_t *image; + int width, height; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + *tx = -extents->x; + *ty = -extents->y; + width = extents->width; + height = extents->height; + + image = pixman_image_create_bits (PIXMAN_a8r8g8b8, width, height, NULL, 0); + if (unlikely (image == NULL)) + return NULL; + + _cairo_mesh_pattern_rasterize (pattern, + pixman_image_get_data (image), + width, height, + pixman_image_get_stride (image), + *tx, *ty); + return image; +} + +struct acquire_source_cleanup { + cairo_surface_t *surface; + cairo_image_surface_t *image; + void *image_extra; +}; + +static void +_acquire_source_cleanup (pixman_image_t *pixman_image, + void *closure) +{ + struct acquire_source_cleanup *data = closure; + + _cairo_surface_release_source_image (data->surface, + data->image, + data->image_extra); + free (data); +} + +static void +_defer_free_cleanup (pixman_image_t *pixman_image, + void *closure) +{ + cairo_surface_destroy (closure); +} + +static uint16_t +expand_channel (uint16_t v, uint32_t bits) +{ + int offset = 16 - bits; + while (offset > 0) { + v |= v >> bits; + offset -= bits; + bits += bits; + } + return v; +} + +static pixman_image_t * +_pixel_to_solid (cairo_image_surface_t *image, int x, int y) +{ + uint32_t pixel; + pixman_color_t color; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + switch (image->format) { + default: + case CAIRO_FORMAT_INVALID: + ASSERT_NOT_REACHED; + return NULL; + + case CAIRO_FORMAT_A1: + pixel = *(uint8_t *) (image->data + y * image->stride + x/8); + return pixel & (1 << (x&7)) ? _pixman_black_image () : _pixman_transparent_image (); + + case CAIRO_FORMAT_A8: + color.alpha = *(uint8_t *) (image->data + y * image->stride + x); + color.alpha |= color.alpha << 8; + if (color.alpha == 0) + return _pixman_transparent_image (); + if (color.alpha == 0xffff) + return _pixman_black_image (); + + color.red = color.green = color.blue = 0; + return pixman_image_create_solid_fill (&color); + + case CAIRO_FORMAT_RGB16_565: + pixel = *(uint16_t *) (image->data + y * image->stride + 2 * x); + if (pixel == 0) + return _pixman_black_image (); + if (pixel == 0xffff) + return _pixman_white_image (); + + color.alpha = 0xffff; + color.red = expand_channel ((pixel >> 11 & 0x1f) << 11, 5); + color.green = expand_channel ((pixel >> 5 & 0x3f) << 10, 6); + color.blue = expand_channel ((pixel & 0x1f) << 11, 5); + return pixman_image_create_solid_fill (&color); + + case CAIRO_FORMAT_RGB30: + pixel = *(uint32_t *) (image->data + y * image->stride + 4 * x); + pixel &= 0x3fffffff; /* ignore alpha bits */ + if (pixel == 0) + return _pixman_black_image (); + if (pixel == 0x3fffffff) + return _pixman_white_image (); + + /* convert 10bpc to 16bpc */ + color.alpha = 0xffff; + color.red = expand_channel((pixel >> 20) & 0x3fff, 10); + color.green = expand_channel((pixel >> 10) & 0x3fff, 10); + color.blue = expand_channel(pixel & 0x3fff, 10); + return pixman_image_create_solid_fill (&color); + + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_RGB24: + pixel = *(uint32_t *) (image->data + y * image->stride + 4 * x); + color.alpha = image->format == CAIRO_FORMAT_ARGB32 ? (pixel >> 24) | (pixel >> 16 & 0xff00) : 0xffff; + if (color.alpha == 0) + return _pixman_transparent_image (); + if (pixel == 0xffffffff) + return _pixman_white_image (); + if (color.alpha == 0xffff && (pixel & 0xffffff) == 0) + return _pixman_black_image (); + + color.red = (pixel >> 16 & 0xff) | (pixel >> 8 & 0xff00); + color.green = (pixel >> 8 & 0xff) | (pixel & 0xff00); + color.blue = (pixel & 0xff) | (pixel << 8 & 0xff00); + return pixman_image_create_solid_fill (&color); + } +} + +/* ========================================================================== */ + +/* Index into filter table */ +typedef enum +{ + KERNEL_IMPULSE, + KERNEL_BOX, + KERNEL_LINEAR, + KERNEL_MITCHELL, + KERNEL_NOTCH, + KERNEL_CATMULL_ROM, + KERNEL_LANCZOS3, + KERNEL_LANCZOS3_STRETCHED, + KERNEL_TENT +} kernel_t; + +/* Produce contribution of a filter of size r for pixel centered on x. + For a typical low-pass function this evaluates the function at x/r. + If the frequency is higher than 1/2, such as when r is less than 1, + this may need to integrate several samples, see cubic for examples. +*/ +typedef double (* kernel_func_t) (double x, double r); + +/* Return maximum number of pixels that will be non-zero. Except for + impluse this is the maximum of 2 and the width of the non-zero part + of the filter rounded up to the next integer. +*/ +typedef int (* kernel_width_func_t) (double r); + +/* Table of filters */ +typedef struct +{ + kernel_t kernel; + kernel_func_t func; + kernel_width_func_t width; +} filter_info_t; + +/* PIXMAN_KERNEL_IMPULSE: Returns pixel nearest the center. This + matches PIXMAN_FILTER_NEAREST. This is useful if you wish to + combine the result of nearest in one direction with another filter + in the other. +*/ + +static double +impulse_kernel (double x, double r) +{ + return 1; +} + +static int +impulse_width (double r) +{ + return 1; +} + +/* PIXMAN_KERNEL_BOX: Intersection of a box of width r with square + pixels. This is the smallest possible filter such that the output + image contains an equal contribution from all the input + pixels. Lots of software uses this. The function is a trapazoid of + width r+1, not a box. + + When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and + PIXMAN_KERNEL_TENT all produce the same filter, allowing + them to be exchanged at this point. +*/ + +static double +box_kernel (double x, double r) +{ + return MAX (0.0, MIN (MIN (r, 1.0), + MIN ((r + 1) / 2 - x, (r + 1) / 2 + x))); +} + +static int +box_width (double r) +{ + return r < 1.0 ? 2 : ceil(r + 1); +} + +/* PIXMAN_KERNEL_LINEAR: Weighted sum of the two pixels nearest the + center, or a triangle of width 2. This matches + PIXMAN_FILTER_BILINEAR. This is useful if you wish to combine the + result of bilinear in one direction with another filter in the + other. This is not a good filter if r > 1. You may actually want + PIXMAN_FILTER_TENT. + + When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and + PIXMAN_KERNEL_TENT all produce the same filter, allowing + them to be exchanged at this point. +*/ + +static double +linear_kernel (double x, double r) +{ + return MAX (1.0 - fabs(x), 0.0); +} + +static int +linear_width (double r) +{ + return 2; +} + +/* Cubic functions described in the Mitchell-Netravali paper. + http://mentallandscape.com/Papers_siggraph88.pdf. This describes + all possible cubic functions that can be used for sampling. +*/ + +static double +general_cubic (double x, double r, double B, double C) +{ + double ax; + if (r < 1.0) + return + general_cubic(x * 2 - .5, r * 2, B, C) + + general_cubic(x * 2 + .5, r * 2, B, C); + + ax = fabs (x / r); + + if (ax < 1) + { + return (((12 - 9 * B - 6 * C) * ax + + (-18 + 12 * B + 6 * C)) * ax * ax + + (6 - 2 * B)) / 6; + } + else if (ax < 2) + { + return ((((-B - 6 * C) * ax + + (6 * B + 30 * C)) * ax + + (-12 * B - 48 * C)) * ax + + (8 * B + 24 * C)) / 6; + } + else + { + return 0.0; + } +} + +static int +cubic_width (double r) +{ + return MAX (2, ceil (r * 4)); +} + +/* PIXMAN_KERNEL_CATMULL_ROM: Catmull-Rom interpolation. Often called + "cubic interpolation", "b-spline", or just "cubic" by other + software. This filter has negative values so it can produce ringing + and output pixels outside the range of input pixels. This is very + close to lanczos2 so there is no reason to supply that as well. +*/ + +static double +cubic_kernel (double x, double r) +{ + return general_cubic (x, r, 0.0, 0.5); +} + +/* PIXMAN_KERNEL_MITCHELL: Cubic recommended by the Mitchell-Netravali + paper. This has negative values and because the values at +/-1 are + not zero it does not interpolate the pixels, meaning it will change + an image even if there is no translation. +*/ + +static double +mitchell_kernel (double x, double r) +{ + return general_cubic (x, r, 1/3.0, 1/3.0); +} + +/* PIXMAN_KERNEL_NOTCH: Cubic recommended by the Mitchell-Netravali + paper to remove postaliasing artifacts. This does not remove + aliasing already present in the source image, though it may appear + to due to it's excessive blurriness. In any case this is more + useful than gaussian for image reconstruction. +*/ + +static double +notch_kernel (double x, double r) +{ + return general_cubic (x, r, 1.5, -0.25); +} + +/* PIXMAN_KERNEL_LANCZOS3: lanczos windowed sinc function from -3 to + +3. Very popular with high-end software though I think any + advantage over cubics is hidden by quantization and programming + mistakes. You will see LANCZOS5 or even 7 sometimes. +*/ + +static double +sinc (double x) +{ + return x ? sin (M_PI * x) / (M_PI * x) : 1.0; +} + +static double +lanczos (double x, double n) +{ + return fabs (x) < n ? sinc (x) * sinc (x * (1.0 / n)) : 0.0; +} + +static double +lanczos3_kernel (double x, double r) +{ + if (r < 1.0) + return + lanczos3_kernel (x * 2 - .5, r * 2) + + lanczos3_kernel (x * 2 + .5, r * 2); + else + return lanczos (x / r, 3.0); +} + +static int +lanczos3_width (double r) +{ + return MAX (2, ceil (r * 6)); +} + +/* PIXMAN_KERNEL_LANCZOS3_STRETCHED - The LANCZOS3 kernel widened by + 4/3. Recommended by Jim Blinn + http://graphics.cs.cmu.edu/nsp/course/15-462/Fall07/462/papers/jaggy.pdf +*/ + +static double +nice_kernel (double x, double r) +{ + return lanczos3_kernel (x, r * (4.0/3)); +} + +static int +nice_width (double r) +{ + return MAX (2.0, ceil (r * 8)); +} + +/* PIXMAN_KERNEL_TENT: Triangle of width 2r. Lots of software uses + this as a "better" filter, twice the size of a box but smaller than + a cubic. + + When r == 1.0, PIXMAN_KERNEL_BOX, PIXMAN_KERNEL_LINEAR, and + PIXMAN_KERNEL_TENT all produce the same filter, allowing + them to be exchanged at this point. +*/ + +static double +tent_kernel (double x, double r) +{ + if (r < 1.0) + return box_kernel(x, r); + else + return MAX (1.0 - fabs(x / r), 0.0); +} + +static int +tent_width (double r) +{ + return r < 1.0 ? 2 : ceil(2 * r); +} + + +static const filter_info_t filters[] = +{ + { KERNEL_IMPULSE, impulse_kernel, impulse_width }, + { KERNEL_BOX, box_kernel, box_width }, + { KERNEL_LINEAR, linear_kernel, linear_width }, + { KERNEL_MITCHELL, mitchell_kernel, cubic_width }, + { KERNEL_NOTCH, notch_kernel, cubic_width }, + { KERNEL_CATMULL_ROM, cubic_kernel, cubic_width }, + { KERNEL_LANCZOS3, lanczos3_kernel, lanczos3_width }, + { KERNEL_LANCZOS3_STRETCHED,nice_kernel, nice_width }, + { KERNEL_TENT, tent_kernel, tent_width } +}; + +/* Fills in one dimension of the filter array */ +static void get_filter(kernel_t filter, double r, + int width, int subsample, + pixman_fixed_t* out) +{ + int i; + pixman_fixed_t *p = out; + int n_phases = 1 << subsample; + double step = 1.0 / n_phases; + kernel_func_t func = filters[filter].func; + + /* special-case the impulse filter: */ + if (width <= 1) + { + for (i = 0; i < n_phases; ++i) + *p++ = pixman_fixed_1; + return; + } + + for (i = 0; i < n_phases; ++i) + { + double frac = (i + .5) * step; + /* Center of left-most pixel: */ + double x1 = ceil (frac - width / 2.0 - 0.5) - frac + 0.5; + double total = 0; + pixman_fixed_t new_total = 0; + int j; + + for (j = 0; j < width; ++j) + { + double v = func(x1 + j, r); + total += v; + p[j] = pixman_double_to_fixed (v); + } + + /* Normalize */ + total = 1 / total; + for (j = 0; j < width; ++j) + new_total += (p[j] *= total); + + /* Put any error on center pixel */ + p[width / 2] += (pixman_fixed_1 - new_total); + + p += width; + } +} + + +/* Create the parameter list for a SEPARABLE_CONVOLUTION filter + * with the given kernels and scale parameters. + */ +static pixman_fixed_t * +create_separable_convolution (int *n_values, + kernel_t xfilter, + double sx, + kernel_t yfilter, + double sy) +{ + int xwidth, xsubsample, ywidth, ysubsample, size_x, size_y; + pixman_fixed_t *params; + + xwidth = filters[xfilter].width(sx); + xsubsample = 0; + if (xwidth > 1) + while (sx * (1 << xsubsample) <= 128.0) xsubsample++; + size_x = (1 << xsubsample) * xwidth; + + ywidth = filters[yfilter].width(sy); + ysubsample = 0; + if (ywidth > 1) + while (sy * (1 << ysubsample) <= 128.0) ysubsample++; + size_y = (1 << ysubsample) * ywidth; + + *n_values = 4 + size_x + size_y; + params = malloc (*n_values * sizeof (pixman_fixed_t)); + if (!params) return 0; + + params[0] = pixman_int_to_fixed (xwidth); + params[1] = pixman_int_to_fixed (ywidth); + params[2] = pixman_int_to_fixed (xsubsample); + params[3] = pixman_int_to_fixed (ysubsample); + + get_filter(xfilter, sx, xwidth, xsubsample, params + 4); + get_filter(yfilter, sy, ywidth, ysubsample, params + 4 + size_x); + + return params; +} + +/* ========================================================================== */ + +static cairo_bool_t +_pixman_image_set_properties (pixman_image_t *pixman_image, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + int *ix,int *iy) +{ + pixman_transform_t pixman_transform; + cairo_int_status_t status; + + status = _cairo_matrix_to_pixman_matrix_offset (&pattern->matrix, + pattern->filter, + extents->x + extents->width/2., + extents->y + extents->height/2., + &pixman_transform, ix, iy); + if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) + { + /* If the transform is an identity, we don't need to set it + * and we can use any filtering, so choose the fastest one. */ + pixman_image_set_filter (pixman_image, PIXMAN_FILTER_NEAREST, NULL, 0); + } + else if (unlikely (status != CAIRO_INT_STATUS_SUCCESS || + ! pixman_image_set_transform (pixman_image, + &pixman_transform))) + { + return FALSE; + } + else + { + pixman_filter_t pixman_filter; + kernel_t kernel; + double dx, dy; + + /* Compute scale factors from the pattern matrix. These scale + * factors are from user to pattern space, and as such they + * are greater than 1.0 for downscaling and less than 1.0 for + * upscaling. The factors are the size of an axis-aligned + * rectangle with the same area as the parallelgram a 1x1 + * square transforms to. + */ + dx = hypot (pattern->matrix.xx, pattern->matrix.xy); + dy = hypot (pattern->matrix.yx, pattern->matrix.yy); + + /* Clip at maximum pixman_fixed number. Besides making it + * passable to pixman, this avoids errors from inf and nan. + */ + if (! (dx < 0x7FFF)) dx = 0x7FFF; + if (! (dy < 0x7FFF)) dy = 0x7FFF; + + switch (pattern->filter) { + case CAIRO_FILTER_FAST: + pixman_filter = PIXMAN_FILTER_FAST; + break; + case CAIRO_FILTER_GOOD: + pixman_filter = PIXMAN_FILTER_SEPARABLE_CONVOLUTION; + kernel = KERNEL_BOX; + /* Clip the filter size to prevent extreme slowness. This + value could be raised if 2-pass filtering is done */ + if (dx > 16.0) dx = 16.0; + if (dy > 16.0) dy = 16.0; + /* Match the bilinear filter for scales > .75: */ + if (dx < 1.0/0.75) dx = 1.0; + if (dy < 1.0/0.75) dy = 1.0; + break; + case CAIRO_FILTER_BEST: + pixman_filter = PIXMAN_FILTER_SEPARABLE_CONVOLUTION; + kernel = KERNEL_CATMULL_ROM; /* LANCZOS3 is better but not much */ + /* Clip the filter size to prevent extreme slowness. This + value could be raised if 2-pass filtering is done */ + if (dx > 16.0) { dx = 16.0; kernel = KERNEL_BOX; } + /* blur up to 2x scale, then blend to square pixels for larger: */ + else if (dx < 1.0) { + if (dx < 1.0/128) dx = 1.0/127; + else if (dx < 0.5) dx = 1.0 / (1.0 / dx - 1.0); + else dx = 1.0; + } + if (dy > 16.0) { dy = 16.0; kernel = KERNEL_BOX; } + else if (dy < 1.0) { + if (dy < 1.0/128) dy = 1.0/127; + else if (dy < 0.5) dy = 1.0 / (1.0 / dy - 1.0); + else dy = 1.0; + } + break; + case CAIRO_FILTER_NEAREST: + pixman_filter = PIXMAN_FILTER_NEAREST; + break; + case CAIRO_FILTER_BILINEAR: + pixman_filter = PIXMAN_FILTER_BILINEAR; + break; + case CAIRO_FILTER_GAUSSIAN: + /* XXX: The GAUSSIAN value has no implementation in cairo + * whatsoever, so it was really a mistake to have it in the + * API. We could fix this by officially deprecating it, or + * else inventing semantics and providing an actual + * implementation for it. */ + default: + pixman_filter = PIXMAN_FILTER_BEST; + } + + if (pixman_filter == PIXMAN_FILTER_SEPARABLE_CONVOLUTION) { + int n_params; + pixman_fixed_t *params; + params = create_separable_convolution + (&n_params, kernel, dx, kernel, dy); + pixman_image_set_filter (pixman_image, pixman_filter, + params, n_params); + free (params); + } else { + pixman_image_set_filter (pixman_image, pixman_filter, NULL, 0); + } + } + + { + pixman_repeat_t pixman_repeat; + + switch (pattern->extend) { + default: + case CAIRO_EXTEND_NONE: + pixman_repeat = PIXMAN_REPEAT_NONE; + break; + case CAIRO_EXTEND_REPEAT: + pixman_repeat = PIXMAN_REPEAT_NORMAL; + break; + case CAIRO_EXTEND_REFLECT: + pixman_repeat = PIXMAN_REPEAT_REFLECT; + break; + case CAIRO_EXTEND_PAD: + pixman_repeat = PIXMAN_REPEAT_PAD; + break; + } + + pixman_image_set_repeat (pixman_image, pixman_repeat); + } + + if (pattern->has_component_alpha) + pixman_image_set_component_alpha (pixman_image, TRUE); + + return TRUE; +} + +struct proxy { + cairo_surface_t base; + cairo_surface_t *image; +}; + +static cairo_status_t +proxy_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + struct proxy *proxy = abstract_surface; + return _cairo_surface_acquire_source_image (proxy->image, image_out, image_extra); +} + +static void +proxy_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + struct proxy *proxy = abstract_surface; + _cairo_surface_release_source_image (proxy->image, image, image_extra); +} + +static cairo_status_t +proxy_finish (void *abstract_surface) +{ + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t proxy_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_NULL, + proxy_finish, + NULL, + + NULL, /* create similar */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + proxy_acquire_source_image, + proxy_release_source_image, +}; + +static cairo_surface_t * +attach_proxy (cairo_surface_t *source, + cairo_surface_t *image) +{ + struct proxy *proxy; + + proxy = malloc (sizeof (*proxy)); + if (unlikely (proxy == NULL)) + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_surface_init (&proxy->base, &proxy_backend, NULL, image->content); + + proxy->image = image; + _cairo_surface_attach_snapshot (source, &proxy->base, NULL); + + return &proxy->base; +} + +static void +detach_proxy (cairo_surface_t *source, + cairo_surface_t *proxy) +{ + cairo_surface_finish (proxy); + cairo_surface_destroy (proxy); +} + +static cairo_surface_t * +get_proxy (cairo_surface_t *proxy) +{ + return ((struct proxy *)proxy)->image; +} + +static pixman_image_t * +_pixman_image_for_recording (cairo_image_surface_t *dst, + const cairo_surface_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *ix, int *iy) +{ + cairo_surface_t *source, *clone, *proxy; + cairo_rectangle_int_t limit; + pixman_image_t *pixman_image; + cairo_status_t status; + cairo_extend_t extend; + cairo_matrix_t *m, matrix; + int tx = 0, ty = 0; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + *ix = *iy = 0; + + source = _cairo_pattern_get_source (pattern, &limit); + + extend = pattern->base.extend; + if (_cairo_rectangle_contains_rectangle (&limit, sample)) + extend = CAIRO_EXTEND_NONE; + if (extend == CAIRO_EXTEND_NONE) { + if (! _cairo_rectangle_intersect (&limit, sample)) + return _pixman_transparent_image (); + + if (! _cairo_matrix_is_identity (&pattern->base.matrix)) { + double x1, y1, x2, y2; + + matrix = pattern->base.matrix; + status = cairo_matrix_invert (&matrix); + assert (status == CAIRO_STATUS_SUCCESS); + + x1 = limit.x; + y1 = limit.y; + x2 = limit.x + limit.width; + y2 = limit.y + limit.height; + + _cairo_matrix_transform_bounding_box (&matrix, + &x1, &y1, &x2, &y2, NULL); + + limit.x = floor (x1); + limit.y = floor (y1); + limit.width = ceil (x2) - limit.x; + limit.height = ceil (y2) - limit.y; + } + } + tx = limit.x; + ty = limit.y; + + /* XXX transformations! */ + proxy = _cairo_surface_has_snapshot (source, &proxy_backend); + if (proxy != NULL) { + clone = cairo_surface_reference (get_proxy (proxy)); + goto done; + } + + if (is_mask) { + clone = cairo_image_surface_create (CAIRO_FORMAT_A8, + limit.width, limit.height); + } else { + if (dst->base.content == source->content) + clone = cairo_image_surface_create (dst->format, + limit.width, limit.height); + else + clone = _cairo_image_surface_create_with_content (source->content, + limit.width, + limit.height); + } + + m = NULL; + if (extend == CAIRO_EXTEND_NONE) { + matrix = pattern->base.matrix; + if (tx | ty) + cairo_matrix_translate (&matrix, tx, ty); + m = &matrix; + } else { + /* XXX extract scale factor for repeating patterns */ + } + + /* Handle recursion by returning future reads from the current image */ + proxy = attach_proxy (source, clone); + status = _cairo_recording_surface_replay_with_clip (source, m, clone, NULL); + detach_proxy (source, proxy); + if (unlikely (status)) { + cairo_surface_destroy (clone); + return NULL; + } + +done: + pixman_image = pixman_image_ref (((cairo_image_surface_t *)clone)->pixman_image); + cairo_surface_destroy (clone); + + *ix = -limit.x; + *iy = -limit.y; + if (extend != CAIRO_EXTEND_NONE) { + if (! _pixman_image_set_properties (pixman_image, + &pattern->base, extents, + ix, iy)) { + pixman_image_unref (pixman_image); + pixman_image= NULL; + } + } + + return pixman_image; +} + +static pixman_image_t * +_pixman_image_for_surface (cairo_image_surface_t *dst, + const cairo_surface_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *ix, int *iy) +{ + cairo_extend_t extend = pattern->base.extend; + pixman_image_t *pixman_image; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + *ix = *iy = 0; + pixman_image = NULL; + if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + return _pixman_image_for_recording(dst, pattern, + is_mask, extents, sample, + ix, iy); + + if (pattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE && + (! is_mask || ! pattern->base.has_component_alpha || + (pattern->surface->content & CAIRO_CONTENT_COLOR) == 0)) + { + cairo_surface_t *defer_free = NULL; + cairo_image_surface_t *source = (cairo_image_surface_t *) pattern->surface; + cairo_surface_type_t type; + + if (_cairo_surface_is_snapshot (&source->base)) { + defer_free = _cairo_surface_snapshot_get_target (&source->base); + source = (cairo_image_surface_t *) defer_free; + } + + type = source->base.backend->type; + if (type == CAIRO_SURFACE_TYPE_IMAGE) { + if (extend != CAIRO_EXTEND_NONE && + sample->x >= 0 && + sample->y >= 0 && + sample->x + sample->width <= source->width && + sample->y + sample->height <= source->height) + { + extend = CAIRO_EXTEND_NONE; + } + + if (sample->width == 1 && sample->height == 1) { + if (sample->x < 0 || + sample->y < 0 || + sample->x >= source->width || + sample->y >= source->height) + { + if (extend == CAIRO_EXTEND_NONE) { + cairo_surface_destroy (defer_free); + return _pixman_transparent_image (); + } + } + else + { + pixman_image = _pixel_to_solid (source, + sample->x, sample->y); + if (pixman_image) { + cairo_surface_destroy (defer_free); + return pixman_image; + } + } + } + +#if PIXMAN_HAS_ATOMIC_OPS + /* avoid allocating a 'pattern' image if we can reuse the original */ + if (extend == CAIRO_EXTEND_NONE && + _cairo_matrix_is_pixman_translation (&pattern->base.matrix, + pattern->base.filter, + ix, iy)) + { + cairo_surface_destroy (defer_free); + return pixman_image_ref (source->pixman_image); + } +#endif + + pixman_image = pixman_image_create_bits (source->pixman_format, + source->width, + source->height, + (uint32_t *) source->data, + source->stride); + if (unlikely (pixman_image == NULL)) { + cairo_surface_destroy (defer_free); + return NULL; + } + + if (defer_free) { + pixman_image_set_destroy_function (pixman_image, + _defer_free_cleanup, + defer_free); + } + } else if (type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub; + cairo_bool_t is_contained = FALSE; + + sub = (cairo_surface_subsurface_t *) source; + source = (cairo_image_surface_t *) sub->target; + + if (sample->x >= 0 && + sample->y >= 0 && + sample->x + sample->width <= sub->extents.width && + sample->y + sample->height <= sub->extents.height) + { + is_contained = TRUE; + } + + if (sample->width == 1 && sample->height == 1) { + if (is_contained) { + pixman_image = _pixel_to_solid (source, + sub->extents.x + sample->x, + sub->extents.y + sample->y); + if (pixman_image) + return pixman_image; + } else { + if (extend == CAIRO_EXTEND_NONE) + return _pixman_transparent_image (); + } + } + +#if PIXMAN_HAS_ATOMIC_OPS + *ix = sub->extents.x; + *iy = sub->extents.y; + if (is_contained && + _cairo_matrix_is_pixman_translation (&pattern->base.matrix, + pattern->base.filter, + ix, iy)) + { + return pixman_image_ref (source->pixman_image); + } +#endif + + /* Avoid sub-byte offsets, force a copy in that case. */ + if (PIXMAN_FORMAT_BPP (source->pixman_format) >= 8) { + if (is_contained) { + void *data = source->data + + sub->extents.x * PIXMAN_FORMAT_BPP(source->pixman_format)/8 + + sub->extents.y * source->stride; + pixman_image = pixman_image_create_bits (source->pixman_format, + sub->extents.width, + sub->extents.height, + data, + source->stride); + if (unlikely (pixman_image == NULL)) + return NULL; + } else { + /* XXX for a simple translation and EXTEND_NONE we can + * fix up the pattern matrix instead. + */ + } + } + } + } + + if (pixman_image == NULL) { + struct acquire_source_cleanup *cleanup; + cairo_image_surface_t *image; + void *extra; + cairo_status_t status; + + status = _cairo_surface_acquire_source_image (pattern->surface, &image, &extra); + if (unlikely (status)) + return NULL; + + pixman_image = pixman_image_create_bits (image->pixman_format, + image->width, + image->height, + (uint32_t *) image->data, + image->stride); + if (unlikely (pixman_image == NULL)) { + _cairo_surface_release_source_image (pattern->surface, image, extra); + return NULL; + } + + cleanup = malloc (sizeof (*cleanup)); + if (unlikely (cleanup == NULL)) { + _cairo_surface_release_source_image (pattern->surface, image, extra); + pixman_image_unref (pixman_image); + return NULL; + } + + cleanup->surface = pattern->surface; + cleanup->image = image; + cleanup->image_extra = extra; + pixman_image_set_destroy_function (pixman_image, + _acquire_source_cleanup, cleanup); + } + + if (! _pixman_image_set_properties (pixman_image, + &pattern->base, extents, + ix, iy)) { + pixman_image_unref (pixman_image); + pixman_image= NULL; + } + + return pixman_image; +} + +struct raster_source_cleanup { + const cairo_pattern_t *pattern; + cairo_surface_t *surface; + cairo_image_surface_t *image; + void *image_extra; +}; + +static void +_raster_source_cleanup (pixman_image_t *pixman_image, + void *closure) +{ + struct raster_source_cleanup *data = closure; + + _cairo_surface_release_source_image (data->surface, + data->image, + data->image_extra); + + _cairo_raster_source_pattern_release (data->pattern, + data->surface); + + free (data); +} + +static pixman_image_t * +_pixman_image_for_raster (cairo_image_surface_t *dst, + const cairo_raster_source_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *ix, int *iy) +{ + pixman_image_t *pixman_image; + struct raster_source_cleanup *cleanup; + cairo_image_surface_t *image; + void *extra; + cairo_status_t status; + cairo_surface_t *surface; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + *ix = *iy = 0; + + surface = _cairo_raster_source_pattern_acquire (&pattern->base, + &dst->base, NULL); + if (unlikely (surface == NULL || surface->status)) + return NULL; + + status = _cairo_surface_acquire_source_image (surface, &image, &extra); + if (unlikely (status)) { + _cairo_raster_source_pattern_release (&pattern->base, surface); + return NULL; + } + + assert (image->width == pattern->extents.width); + assert (image->height == pattern->extents.height); + + pixman_image = pixman_image_create_bits (image->pixman_format, + image->width, + image->height, + (uint32_t *) image->data, + image->stride); + if (unlikely (pixman_image == NULL)) { + _cairo_surface_release_source_image (surface, image, extra); + _cairo_raster_source_pattern_release (&pattern->base, surface); + return NULL; + } + + cleanup = malloc (sizeof (*cleanup)); + if (unlikely (cleanup == NULL)) { + pixman_image_unref (pixman_image); + _cairo_surface_release_source_image (surface, image, extra); + _cairo_raster_source_pattern_release (&pattern->base, surface); + return NULL; + } + + cleanup->pattern = &pattern->base; + cleanup->surface = surface; + cleanup->image = image; + cleanup->image_extra = extra; + pixman_image_set_destroy_function (pixman_image, + _raster_source_cleanup, cleanup); + + if (! _pixman_image_set_properties (pixman_image, + &pattern->base, extents, + ix, iy)) { + pixman_image_unref (pixman_image); + pixman_image= NULL; + } + + return pixman_image; +} + +pixman_image_t * +_pixman_image_for_pattern (cairo_image_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *tx, int *ty) +{ + *tx = *ty = 0; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (pattern == NULL) + return _pixman_white_image (); + + switch (pattern->type) { + default: + ASSERT_NOT_REACHED; + case CAIRO_PATTERN_TYPE_SOLID: + return _pixman_image_for_color (&((const cairo_solid_pattern_t *) pattern)->color); + + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_LINEAR: + return _pixman_image_for_gradient ((const cairo_gradient_pattern_t *) pattern, + extents, tx, ty); + + case CAIRO_PATTERN_TYPE_MESH: + return _pixman_image_for_mesh ((const cairo_mesh_pattern_t *) pattern, + extents, tx, ty); + + case CAIRO_PATTERN_TYPE_SURFACE: + return _pixman_image_for_surface (dst, + (const cairo_surface_pattern_t *) pattern, + is_mask, extents, sample, + tx, ty); + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _pixman_image_for_raster (dst, + (const cairo_raster_source_pattern_t *) pattern, + is_mask, extents, sample, + tx, ty); + } +} + +static cairo_status_t +_cairo_image_source_finish (void *abstract_surface) +{ + cairo_image_source_t *source = abstract_surface; + + pixman_image_unref (source->pixman_image); + return CAIRO_STATUS_SUCCESS; +} + +const cairo_surface_backend_t _cairo_image_source_backend = { + CAIRO_SURFACE_TYPE_IMAGE, + _cairo_image_source_finish, + NULL, /* read-only wrapper */ +}; + +cairo_surface_t * +_cairo_image_source_create_for_pattern (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_image_source_t *source; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + source = malloc (sizeof (cairo_image_source_t)); + if (unlikely (source == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + source->pixman_image = + _pixman_image_for_pattern ((cairo_image_surface_t *)dst, + pattern, is_mask, + extents, sample, + src_x, src_y); + if (unlikely (source->pixman_image == NULL)) { + free (source); + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_surface_init (&source->base, + &_cairo_image_source_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + source->is_opaque_solid = + pattern == NULL || _cairo_pattern_is_opaque_solid (pattern); + + return &source->base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-surface-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-image-surface-inline.h new file mode 100644 index 00000000000..743d5fd3e75 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-surface-inline.h @@ -0,0 +1,96 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_IMAGE_SURFACE_INLINE_H +#define CAIRO_IMAGE_SURFACE_INLINE_H + +#include "cairo-surface-private.h" +#include "cairo-image-surface-private.h" + +CAIRO_BEGIN_DECLS + +static inline cairo_image_surface_t * +_cairo_image_surface_create_in_error (cairo_status_t status) +{ + return (cairo_image_surface_t *) _cairo_surface_create_in_error (status); +} + +static inline void +_cairo_image_surface_set_parent (cairo_image_surface_t *image, + cairo_surface_t *parent) +{ + image->parent = parent; +} + +static inline cairo_bool_t +_cairo_image_surface_is_clone (cairo_image_surface_t *image) +{ + return image->parent != NULL; +} + +/** + * _cairo_surface_is_image: + * @surface: a #cairo_surface_t + * + * Checks if a surface is an #cairo_image_surface_t + * + * Return value: %TRUE if the surface is an image surface + **/ +static inline cairo_bool_t +_cairo_surface_is_image (const cairo_surface_t *surface) +{ + /* _cairo_surface_nil sets a NULL backend so be safe */ + return surface->backend && surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE; +} + +/** + * _cairo_surface_is_image_source: + * @surface: a #cairo_surface_t + * + * Checks if a surface is an #cairo_image_source_t + * + * Return value: %TRUE if the surface is an image source + **/ +static inline cairo_bool_t +_cairo_surface_is_image_source (const cairo_surface_t *surface) +{ + return surface->backend == &_cairo_image_source_backend; +} + +CAIRO_END_DECLS + +#endif /* CAIRO_IMAGE_SURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-image-surface-private.h new file mode 100644 index 00000000000..8ca694c5e3e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-surface-private.h @@ -0,0 +1,238 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_IMAGE_SURFACE_PRIVATE_H +#define CAIRO_IMAGE_SURFACE_PRIVATE_H + +#include "cairo-surface-private.h" + +#include + +CAIRO_BEGIN_DECLS + +/* The canonical image backend */ +struct _cairo_image_surface { + cairo_surface_t base; + + pixman_image_t *pixman_image; + const cairo_compositor_t *compositor; + + /* Parenting is tricky wrt lifetime tracking... + * + * One use for tracking the parent of an image surface is for + * create_similar_image() where we wish to create a device specific + * surface but return an image surface to the user. In such a case, + * the image may be owned by the device specific surface, its parent, + * but the user lifetime tracking is then performed on the image. So + * when the image is then finalized we call cairo_surface_destroy() + * on the parent. However, for normal usage where the lifetime tracking + * is done on the parent surface, we need to be careful to unhook + * the image->parent pointer before finalizing the image. + */ + cairo_surface_t *parent; + + pixman_format_code_t pixman_format; + cairo_format_t format; + unsigned char *data; + + int width; + int height; + int stride; + int depth; + + unsigned owns_data : 1; + unsigned transparency : 2; + unsigned color : 2; +}; +#define to_image_surface(S) ((cairo_image_surface_t *)(S)) + +/* A wrapper for holding pixman images returned by create_for_pattern */ +typedef struct _cairo_image_source { + cairo_surface_t base; + + pixman_image_t *pixman_image; + unsigned is_opaque_solid : 1; +} cairo_image_source_t; + +cairo_private extern const cairo_surface_backend_t _cairo_image_surface_backend; +cairo_private extern const cairo_surface_backend_t _cairo_image_source_backend; + +cairo_private const cairo_compositor_t * +_cairo_image_mask_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_image_traps_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_image_spans_compositor_get (void); + +#define _cairo_image_default_compositor_get _cairo_image_spans_compositor_get + +cairo_private cairo_int_status_t +_cairo_image_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_image_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_image_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_image_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_image_surface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + +cairo_private void +_cairo_image_surface_init (cairo_image_surface_t *surface, + pixman_image_t *pixman_image, + pixman_format_code_t pixman_format); + +cairo_private cairo_surface_t * +_cairo_image_surface_create_similar (void *abstract_other, + cairo_content_t content, + int width, + int height); + +cairo_private cairo_image_surface_t * +_cairo_image_surface_map_to_image (void *abstract_other, + const cairo_rectangle_int_t *extents); + +cairo_private cairo_int_status_t +_cairo_image_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image); + +cairo_private cairo_surface_t * +_cairo_image_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_image_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra); + +cairo_private void +_cairo_image_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra); + +cairo_private cairo_surface_t * +_cairo_image_surface_snapshot (void *abstract_surface); + +cairo_private_no_warn cairo_bool_t +_cairo_image_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle); + +cairo_private void +_cairo_image_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options); + +cairo_private cairo_surface_t * +_cairo_image_source_create_for_pattern (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y); + +cairo_private cairo_status_t +_cairo_image_surface_finish (void *abstract_surface); + +cairo_private pixman_image_t * +_pixman_image_for_color (const cairo_color_t *cairo_color); + +cairo_private pixman_image_t * +_pixman_image_for_pattern (cairo_image_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *tx, int *ty); + +cairo_private void +_pixman_image_add_traps (pixman_image_t *image, + int dst_x, int dst_y, + cairo_traps_t *traps); + +cairo_private void +_pixman_image_add_tristrip (pixman_image_t *image, + int dst_x, int dst_y, + cairo_tristrip_t *strip); + +cairo_private cairo_image_surface_t * +_cairo_image_surface_clone_subimage (cairo_surface_t *surface, + const cairo_rectangle_int_t *extents); + +/* Similar to clone; but allow format conversion */ +cairo_private cairo_image_surface_t * +_cairo_image_surface_create_from_image (cairo_image_surface_t *other, + pixman_format_code_t format, + int x, int y, int width, int height, + int stride); + +CAIRO_END_DECLS + +#endif /* CAIRO_IMAGE_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-image-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-image-surface.c new file mode 100644 index 00000000000..1fd563d1c34 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-image-surface.c @@ -0,0 +1,1321 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * Copyright © 2009,2010,2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-boxes-private.h" +#include "cairo-clip-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-paginated-private.h" +#include "cairo-pattern-private.h" +#include "cairo-pixman-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-region-private.h" +#include "cairo-scaled-font-private.h" +#include "cairo-surface-snapshot-private.h" +#include "cairo-surface-subsurface-private.h" + +/* Limit on the width / height of an image surface in pixels. This is + * mainly determined by coordinates of things sent to pixman at the + * moment being in 16.16 format. */ +#define MAX_IMAGE_SIZE 32767 + +/** + * SECTION:cairo-image + * @Title: Image Surfaces + * @Short_Description: Rendering to memory buffers + * @See_Also: #cairo_surface_t + * + * Image surfaces provide the ability to render to memory buffers + * either allocated by cairo or by the calling code. The supported + * image formats are those defined in #cairo_format_t. + **/ + +/** + * CAIRO_HAS_IMAGE_SURFACE: + * + * Defined if the image surface backend is available. + * The image surface backend is always built in. + * This macro was added for completeness in cairo 1.8. + * + * Since: 1.8 + **/ + +static cairo_bool_t +_cairo_image_surface_is_size_valid (int width, int height) +{ + return 0 <= width && width <= MAX_IMAGE_SIZE && + 0 <= height && height <= MAX_IMAGE_SIZE; +} + +cairo_format_t +_cairo_format_from_pixman_format (pixman_format_code_t pixman_format) +{ + switch (pixman_format) { + case PIXMAN_a8r8g8b8: + return CAIRO_FORMAT_ARGB32; + case PIXMAN_x2r10g10b10: + return CAIRO_FORMAT_RGB30; + case PIXMAN_x8r8g8b8: + return CAIRO_FORMAT_RGB24; + case PIXMAN_a8: + return CAIRO_FORMAT_A8; + case PIXMAN_a1: + return CAIRO_FORMAT_A1; + case PIXMAN_r5g6b5: + return CAIRO_FORMAT_RGB16_565; +#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) + case PIXMAN_r8g8b8a8: case PIXMAN_r8g8b8x8: +#endif +#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,27,2) + case PIXMAN_a8r8g8b8_sRGB: +#endif + case PIXMAN_a8b8g8r8: case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8: + case PIXMAN_b8g8r8: case PIXMAN_b5g6r5: + case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5: + case PIXMAN_x1b5g5r5: case PIXMAN_a4r4g4b4: case PIXMAN_x4r4g4b4: + case PIXMAN_a4b4g4r4: case PIXMAN_x4b4g4r4: case PIXMAN_r3g3b2: + case PIXMAN_b2g3r3: case PIXMAN_a2r2g2b2: case PIXMAN_a2b2g2r2: + case PIXMAN_c8: case PIXMAN_g8: case PIXMAN_x4a4: + case PIXMAN_a4: case PIXMAN_r1g2b1: case PIXMAN_b1g2r1: + case PIXMAN_a1r1g1b1: case PIXMAN_a1b1g1r1: case PIXMAN_c4: + case PIXMAN_g4: case PIXMAN_g1: + case PIXMAN_yuy2: case PIXMAN_yv12: + case PIXMAN_b8g8r8x8: + case PIXMAN_b8g8r8a8: + case PIXMAN_a2b10g10r10: + case PIXMAN_x2b10g10r10: + case PIXMAN_a2r10g10b10: +#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0,22,0) + case PIXMAN_x14r6g6b6: +#endif + default: + return CAIRO_FORMAT_INVALID; + } + + return CAIRO_FORMAT_INVALID; +} + +cairo_content_t +_cairo_content_from_pixman_format (pixman_format_code_t pixman_format) +{ + cairo_content_t content; + + content = 0; + if (PIXMAN_FORMAT_RGB (pixman_format)) + content |= CAIRO_CONTENT_COLOR; + if (PIXMAN_FORMAT_A (pixman_format)) + content |= CAIRO_CONTENT_ALPHA; + + return content; +} + +void +_cairo_image_surface_init (cairo_image_surface_t *surface, + pixman_image_t *pixman_image, + pixman_format_code_t pixman_format) +{ + surface->parent = NULL; + surface->pixman_image = pixman_image; + + surface->pixman_format = pixman_format; + surface->format = _cairo_format_from_pixman_format (pixman_format); + surface->data = (uint8_t *) pixman_image_get_data (pixman_image); + surface->owns_data = FALSE; + surface->transparency = CAIRO_IMAGE_UNKNOWN; + surface->color = CAIRO_IMAGE_UNKNOWN_COLOR; + + surface->width = pixman_image_get_width (pixman_image); + surface->height = pixman_image_get_height (pixman_image); + surface->stride = pixman_image_get_stride (pixman_image); + surface->depth = pixman_image_get_depth (pixman_image); + + surface->base.is_clear = surface->width == 0 || surface->height == 0; + + surface->compositor = _cairo_image_spans_compositor_get (); +} + +cairo_surface_t * +_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image, + pixman_format_code_t pixman_format) +{ + cairo_image_surface_t *surface; + + surface = malloc (sizeof (cairo_image_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_image_surface_backend, + NULL, /* device */ + _cairo_content_from_pixman_format (pixman_format)); + + _cairo_image_surface_init (surface, pixman_image, pixman_format); + + return &surface->base; +} + +cairo_bool_t +_pixman_format_from_masks (cairo_format_masks_t *masks, + pixman_format_code_t *format_ret) +{ + pixman_format_code_t format; + int format_type; + int a, r, g, b; + cairo_format_masks_t format_masks; + + a = _cairo_popcount (masks->alpha_mask); + r = _cairo_popcount (masks->red_mask); + g = _cairo_popcount (masks->green_mask); + b = _cairo_popcount (masks->blue_mask); + + if (masks->red_mask) { + if (masks->red_mask > masks->blue_mask) + format_type = PIXMAN_TYPE_ARGB; + else + format_type = PIXMAN_TYPE_ABGR; + } else if (masks->alpha_mask) { + format_type = PIXMAN_TYPE_A; + } else { + return FALSE; + } + + format = PIXMAN_FORMAT (masks->bpp, format_type, a, r, g, b); + + if (! pixman_format_supported_destination (format)) + return FALSE; + + /* Sanity check that we got out of PIXMAN_FORMAT exactly what we + * expected. This avoid any problems from something bizarre like + * alpha in the least-significant bits, or insane channel order, + * or whatever. */ + if (!_pixman_format_to_masks (format, &format_masks) || + masks->bpp != format_masks.bpp || + masks->red_mask != format_masks.red_mask || + masks->green_mask != format_masks.green_mask || + masks->blue_mask != format_masks.blue_mask) + { + return FALSE; + } + + *format_ret = format; + return TRUE; +} + +/* A mask consisting of N bits set to 1. */ +#define MASK(N) ((1UL << (N))-1) + +cairo_bool_t +_pixman_format_to_masks (pixman_format_code_t format, + cairo_format_masks_t *masks) +{ + int a, r, g, b; + + masks->bpp = PIXMAN_FORMAT_BPP (format); + + /* Number of bits in each channel */ + a = PIXMAN_FORMAT_A (format); + r = PIXMAN_FORMAT_R (format); + g = PIXMAN_FORMAT_G (format); + b = PIXMAN_FORMAT_B (format); + + switch (PIXMAN_FORMAT_TYPE (format)) { + case PIXMAN_TYPE_ARGB: + masks->alpha_mask = MASK (a) << (r + g + b); + masks->red_mask = MASK (r) << (g + b); + masks->green_mask = MASK (g) << (b); + masks->blue_mask = MASK (b); + return TRUE; + case PIXMAN_TYPE_ABGR: + masks->alpha_mask = MASK (a) << (b + g + r); + masks->blue_mask = MASK (b) << (g + r); + masks->green_mask = MASK (g) << (r); + masks->red_mask = MASK (r); + return TRUE; +#ifdef PIXMAN_TYPE_BGRA + case PIXMAN_TYPE_BGRA: + masks->blue_mask = MASK (b) << (masks->bpp - b); + masks->green_mask = MASK (g) << (masks->bpp - b - g); + masks->red_mask = MASK (r) << (masks->bpp - b - g - r); + masks->alpha_mask = MASK (a); + return TRUE; +#endif + case PIXMAN_TYPE_A: + masks->alpha_mask = MASK (a); + masks->red_mask = 0; + masks->green_mask = 0; + masks->blue_mask = 0; + return TRUE; + case PIXMAN_TYPE_OTHER: + case PIXMAN_TYPE_COLOR: + case PIXMAN_TYPE_GRAY: + case PIXMAN_TYPE_YUY2: + case PIXMAN_TYPE_YV12: + default: + masks->alpha_mask = 0; + masks->red_mask = 0; + masks->green_mask = 0; + masks->blue_mask = 0; + return FALSE; + } +} + +pixman_format_code_t +_cairo_format_to_pixman_format_code (cairo_format_t format) +{ + pixman_format_code_t ret; + switch (format) { + case CAIRO_FORMAT_A1: + ret = PIXMAN_a1; + break; + case CAIRO_FORMAT_A8: + ret = PIXMAN_a8; + break; + case CAIRO_FORMAT_RGB24: + ret = PIXMAN_x8r8g8b8; + break; + case CAIRO_FORMAT_RGB30: + ret = PIXMAN_x2r10g10b10; + break; + case CAIRO_FORMAT_RGB16_565: + ret = PIXMAN_r5g6b5; + break; + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_INVALID: + default: + ret = PIXMAN_a8r8g8b8; + break; + } + return ret; +} + +cairo_surface_t * +_cairo_image_surface_create_with_pixman_format (unsigned char *data, + pixman_format_code_t pixman_format, + int width, + int height, + int stride) +{ + cairo_surface_t *surface; + pixman_image_t *pixman_image; + + if (! _cairo_image_surface_is_size_valid (width, height)) + { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + } + + pixman_image = pixman_image_create_bits (pixman_format, width, height, + (uint32_t *) data, stride); + + if (unlikely (pixman_image == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface = _cairo_image_surface_create_for_pixman_image (pixman_image, + pixman_format); + if (unlikely (surface->status)) { + pixman_image_unref (pixman_image); + return surface; + } + + /* we can not make any assumptions about the initial state of user data */ + surface->is_clear = data == NULL; + return surface; +} + +/** + * cairo_image_surface_create: + * @format: format of pixels in the surface to create + * @width: width of the surface, in pixels + * @height: height of the surface, in pixels + * + * Creates an image surface of the specified format and + * dimensions. Initially the surface contents are all + * 0. (Specifically, within each pixel, each color or alpha channel + * belonging to format will be 0. The contents of bits within a pixel, + * but not belonging to the given format are undefined). + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_image_surface_create (cairo_format_t format, + int width, + int height) +{ + pixman_format_code_t pixman_format; + + if (! CAIRO_FORMAT_VALID (format)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + + pixman_format = _cairo_format_to_pixman_format_code (format); + + return _cairo_image_surface_create_with_pixman_format (NULL, pixman_format, + width, height, -1); +} +slim_hidden_def (cairo_image_surface_create); + + cairo_surface_t * +_cairo_image_surface_create_with_content (cairo_content_t content, + int width, + int height) +{ + return cairo_image_surface_create (_cairo_format_from_content (content), + width, height); +} + +/** + * cairo_format_stride_for_width: + * @format: A #cairo_format_t value + * @width: The desired width of an image surface to be created. + * + * This function provides a stride value that will respect all + * alignment requirements of the accelerated image-rendering code + * within cairo. Typical usage will be of the form: + * + * + * int stride; + * unsigned char *data; + * cairo_surface_t *surface; + * + * stride = cairo_format_stride_for_width (format, width); + * data = malloc (stride * height); + * surface = cairo_image_surface_create_for_data (data, format, + * width, height, + * stride); + * + * + * Return value: the appropriate stride to use given the desired + * format and width, or -1 if either the format is invalid or the width + * too large. + * + * Since: 1.6 + **/ + int +cairo_format_stride_for_width (cairo_format_t format, + int width) +{ + int bpp; + + if (! CAIRO_FORMAT_VALID (format)) { + _cairo_error_throw (CAIRO_STATUS_INVALID_FORMAT); + return -1; + } + + bpp = _cairo_format_bits_per_pixel (format); + if ((unsigned) (width) >= (INT32_MAX - 7) / (unsigned) (bpp)) + return -1; + + return CAIRO_STRIDE_FOR_WIDTH_BPP (width, bpp); +} +slim_hidden_def (cairo_format_stride_for_width); + +/** + * cairo_image_surface_create_for_data: + * @data: a pointer to a buffer supplied by the application in which + * to write contents. This pointer must be suitably aligned for any + * kind of variable, (for example, a pointer returned by malloc). + * @format: the format of pixels in the buffer + * @width: the width of the image to be stored in the buffer + * @height: the height of the image to be stored in the buffer + * @stride: the number of bytes between the start of rows in the + * buffer as allocated. This value should always be computed by + * cairo_format_stride_for_width() before allocating the data + * buffer. + * + * Creates an image surface for the provided pixel data. The output + * buffer must be kept around until the #cairo_surface_t is destroyed + * or cairo_surface_finish() is called on the surface. The initial + * contents of @data will be used as the initial image contents; you + * must explicitly clear the buffer, using, for example, + * cairo_rectangle() and cairo_fill() if you want it cleared. + * + * Note that the stride may be larger than + * width*bytes_per_pixel to provide proper alignment for each pixel + * and row. This alignment is required to allow high-performance rendering + * within cairo. The correct way to obtain a legal stride value is to + * call cairo_format_stride_for_width() with the desired format and + * maximum image width value, and then use the resulting stride value + * to allocate the data and to create the image surface. See + * cairo_format_stride_for_width() for example code. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface in the case of an error such as out of + * memory or an invalid stride value. In case of invalid stride value + * the error status of the returned surface will be + * %CAIRO_STATUS_INVALID_STRIDE. You can use + * cairo_surface_status() to check for this. + * + * See cairo_surface_set_user_data() for a means of attaching a + * destroy-notification fallback to the surface if necessary. + * + * Since: 1.0 + **/ + cairo_surface_t * +cairo_image_surface_create_for_data (unsigned char *data, + cairo_format_t format, + int width, + int height, + int stride) +{ + pixman_format_code_t pixman_format; + int minstride; + + if (! CAIRO_FORMAT_VALID (format)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + + if ((stride & (CAIRO_STRIDE_ALIGNMENT-1)) != 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); + + if (! _cairo_image_surface_is_size_valid (width, height)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + minstride = cairo_format_stride_for_width (format, width); + if (stride < 0) { + if (stride > -minstride) { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); + } + } else { + if (stride < minstride) { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); + } + } + + pixman_format = _cairo_format_to_pixman_format_code (format); + return _cairo_image_surface_create_with_pixman_format (data, + pixman_format, + width, height, + stride); +} +slim_hidden_def (cairo_image_surface_create_for_data); + +/** + * cairo_image_surface_get_data: + * @surface: a #cairo_image_surface_t + * + * Get a pointer to the data of the image surface, for direct + * inspection or modification. + * + * A call to cairo_surface_flush() is required before accessing the + * pixel data to ensure that all pending drawing operations are + * finished. A call to cairo_surface_mark_dirty() is required after + * the data is modified. + * + * Return value: a pointer to the image data of this surface or %NULL + * if @surface is not an image surface, or if cairo_surface_finish() + * has been called. + * + * Since: 1.2 + **/ +unsigned char * +cairo_image_surface_get_data (cairo_surface_t *surface) +{ + cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; + + if (! _cairo_surface_is_image (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return image_surface->data; +} +slim_hidden_def (cairo_image_surface_get_data); + +/** + * cairo_image_surface_get_format: + * @surface: a #cairo_image_surface_t + * + * Get the format of the surface. + * + * Return value: the format of the surface + * + * Since: 1.2 + **/ +cairo_format_t +cairo_image_surface_get_format (cairo_surface_t *surface) +{ + cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; + + if (! _cairo_surface_is_image (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return CAIRO_FORMAT_INVALID; + } + + return image_surface->format; +} +slim_hidden_def (cairo_image_surface_get_format); + +/** + * cairo_image_surface_get_width: + * @surface: a #cairo_image_surface_t + * + * Get the width of the image surface in pixels. + * + * Return value: the width of the surface in pixels. + * + * Since: 1.0 + **/ +int +cairo_image_surface_get_width (cairo_surface_t *surface) +{ + cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; + + if (! _cairo_surface_is_image (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return image_surface->width; +} +slim_hidden_def (cairo_image_surface_get_width); + +/** + * cairo_image_surface_get_height: + * @surface: a #cairo_image_surface_t + * + * Get the height of the image surface in pixels. + * + * Return value: the height of the surface in pixels. + * + * Since: 1.0 + **/ +int +cairo_image_surface_get_height (cairo_surface_t *surface) +{ + cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; + + if (! _cairo_surface_is_image (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return image_surface->height; +} +slim_hidden_def (cairo_image_surface_get_height); + +/** + * cairo_image_surface_get_stride: + * @surface: a #cairo_image_surface_t + * + * Get the stride of the image surface in bytes + * + * Return value: the stride of the image surface in bytes (or 0 if + * @surface is not an image surface). The stride is the distance in + * bytes from the beginning of one row of the image data to the + * beginning of the next row. + * + * Since: 1.2 + **/ +int +cairo_image_surface_get_stride (cairo_surface_t *surface) +{ + + cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface; + + if (! _cairo_surface_is_image (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return image_surface->stride; +} +slim_hidden_def (cairo_image_surface_get_stride); + + cairo_format_t +_cairo_format_from_content (cairo_content_t content) +{ + switch (content) { + case CAIRO_CONTENT_COLOR: + return CAIRO_FORMAT_RGB24; + case CAIRO_CONTENT_ALPHA: + return CAIRO_FORMAT_A8; + case CAIRO_CONTENT_COLOR_ALPHA: + return CAIRO_FORMAT_ARGB32; + } + + ASSERT_NOT_REACHED; + return CAIRO_FORMAT_INVALID; +} + + cairo_content_t +_cairo_content_from_format (cairo_format_t format) +{ + switch (format) { + case CAIRO_FORMAT_ARGB32: + return CAIRO_CONTENT_COLOR_ALPHA; + case CAIRO_FORMAT_RGB30: + return CAIRO_CONTENT_COLOR; + case CAIRO_FORMAT_RGB24: + return CAIRO_CONTENT_COLOR; + case CAIRO_FORMAT_RGB16_565: + return CAIRO_CONTENT_COLOR; + case CAIRO_FORMAT_A8: + case CAIRO_FORMAT_A1: + return CAIRO_CONTENT_ALPHA; + case CAIRO_FORMAT_INVALID: + break; + } + + ASSERT_NOT_REACHED; + return CAIRO_CONTENT_COLOR_ALPHA; +} + + int +_cairo_format_bits_per_pixel (cairo_format_t format) +{ + switch (format) { + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_RGB24: + return 32; + case CAIRO_FORMAT_RGB16_565: + return 16; + case CAIRO_FORMAT_A8: + return 8; + case CAIRO_FORMAT_A1: + return 1; + case CAIRO_FORMAT_INVALID: + default: + ASSERT_NOT_REACHED; + return 0; + } +} + +cairo_surface_t * +_cairo_image_surface_create_similar (void *abstract_other, + cairo_content_t content, + int width, + int height) +{ + cairo_image_surface_t *other = abstract_other; + + TRACE ((stderr, "%s (other=%u)\n", __FUNCTION__, other->base.unique_id)); + + if (! _cairo_image_surface_is_size_valid (width, height)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + if (content == other->base.content) { + return _cairo_image_surface_create_with_pixman_format (NULL, + other->pixman_format, + width, height, + 0); + } + + return _cairo_image_surface_create_with_content (content, + width, height); +} + +cairo_surface_t * +_cairo_image_surface_snapshot (void *abstract_surface) +{ + cairo_image_surface_t *image = abstract_surface; + cairo_image_surface_t *clone; + + /* If we own the image, we can simply steal the memory for the snapshot */ + if (image->owns_data && image->base._finishing) { + clone = (cairo_image_surface_t *) + _cairo_image_surface_create_for_pixman_image (image->pixman_image, + image->pixman_format); + if (unlikely (clone->base.status)) + return &clone->base; + + image->pixman_image = NULL; + image->owns_data = FALSE; + + clone->transparency = image->transparency; + clone->color = image->color; + + clone->owns_data = TRUE; + return &clone->base; + } + + clone = (cairo_image_surface_t *) + _cairo_image_surface_create_with_pixman_format (NULL, + image->pixman_format, + image->width, + image->height, + 0); + if (unlikely (clone->base.status)) + return &clone->base; + + if (clone->stride == image->stride) { + memcpy (clone->data, image->data, clone->stride * clone->height); + } else { + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, NULL, clone->pixman_image, + 0, 0, + 0, 0, + 0, 0, + image->width, image->height); + } + clone->base.is_clear = FALSE; + return &clone->base; +} + +cairo_image_surface_t * +_cairo_image_surface_map_to_image (void *abstract_other, + const cairo_rectangle_int_t *extents) +{ + cairo_image_surface_t *other = abstract_other; + cairo_surface_t *surface; + uint8_t *data; + + data = other->data; + data += extents->y * other->stride; + data += extents->x * PIXMAN_FORMAT_BPP (other->pixman_format)/ 8; + + surface = + _cairo_image_surface_create_with_pixman_format (data, + other->pixman_format, + extents->width, + extents->height, + other->stride); + + cairo_surface_set_device_offset (surface, -extents->x, -extents->y); + return (cairo_image_surface_t *) surface; +} + +cairo_int_status_t +_cairo_image_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return CAIRO_INT_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_image_surface_finish (void *abstract_surface) +{ + cairo_image_surface_t *surface = abstract_surface; + + if (surface->pixman_image) { + pixman_image_unref (surface->pixman_image); + surface->pixman_image = NULL; + } + + if (surface->owns_data) { + free (surface->data); + surface->data = NULL; + } + + if (surface->parent) { + cairo_surface_t *parent = surface->parent; + surface->parent = NULL; + cairo_surface_destroy (parent); + } + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface) +{ + surface->owns_data = TRUE; +} + +cairo_surface_t * +_cairo_image_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_image_surface_t *surface = abstract_surface; + + if (extents) { + extents->x = extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + } + + return &surface->base; +} + +cairo_status_t +_cairo_image_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + *image_out = abstract_surface; + *image_extra = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_image_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ +} + +/* high level image interface */ +cairo_bool_t +_cairo_image_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_image_surface_t *surface = abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + rectangle->width = surface->width; + rectangle->height = surface->height; + + return TRUE; +} + +cairo_int_status_t +_cairo_image_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_image_surface_t *surface = abstract_surface; + + TRACE ((stderr, "%s (surface=%d)\n", + __FUNCTION__, surface->base.unique_id)); + + return _cairo_compositor_paint (surface->compositor, + &surface->base, op, source, clip); +} + +cairo_int_status_t +_cairo_image_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_image_surface_t *surface = abstract_surface; + + TRACE ((stderr, "%s (surface=%d)\n", + __FUNCTION__, surface->base.unique_id)); + + return _cairo_compositor_mask (surface->compositor, + &surface->base, op, source, mask, clip); +} + +cairo_int_status_t +_cairo_image_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_image_surface_t *surface = abstract_surface; + + TRACE ((stderr, "%s (surface=%d)\n", + __FUNCTION__, surface->base.unique_id)); + + return _cairo_compositor_stroke (surface->compositor, &surface->base, + op, source, path, + style, ctm, ctm_inverse, + tolerance, antialias, clip); +} + +cairo_int_status_t +_cairo_image_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_image_surface_t *surface = abstract_surface; + + TRACE ((stderr, "%s (surface=%d)\n", + __FUNCTION__, surface->base.unique_id)); + + return _cairo_compositor_fill (surface->compositor, &surface->base, + op, source, path, + fill_rule, tolerance, antialias, + clip); +} + +cairo_int_status_t +_cairo_image_surface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_image_surface_t *surface = abstract_surface; + + TRACE ((stderr, "%s (surface=%d)\n", + __FUNCTION__, surface->base.unique_id)); + + return _cairo_compositor_glyphs (surface->compositor, &surface->base, + op, source, + glyphs, num_glyphs, scaled_font, + clip); +} + +void +_cairo_image_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + _cairo_font_options_init_default (options); + + cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON); + _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_ON); +} + +const cairo_surface_backend_t _cairo_image_surface_backend = { + CAIRO_SURFACE_TYPE_IMAGE, + _cairo_image_surface_finish, + + _cairo_default_context_create, + + _cairo_image_surface_create_similar, + NULL, /* create similar image */ + _cairo_image_surface_map_to_image, + _cairo_image_surface_unmap_image, + + _cairo_image_surface_source, + _cairo_image_surface_acquire_source_image, + _cairo_image_surface_release_source_image, + _cairo_image_surface_snapshot, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_image_surface_get_extents, + _cairo_image_surface_get_font_options, + + NULL, /* flush */ + NULL, + + _cairo_image_surface_paint, + _cairo_image_surface_mask, + _cairo_image_surface_stroke, + _cairo_image_surface_fill, + NULL, /* fill-stroke */ + _cairo_image_surface_glyphs, +}; + +/* A convenience function for when one needs to coerce an image + * surface to an alternate format. */ +cairo_image_surface_t * +_cairo_image_surface_coerce (cairo_image_surface_t *surface) +{ + return _cairo_image_surface_coerce_to_format (surface, + _cairo_format_from_content (surface->base.content)); +} + +/* A convenience function for when one needs to coerce an image + * surface to an alternate format. */ +cairo_image_surface_t * +_cairo_image_surface_coerce_to_format (cairo_image_surface_t *surface, + cairo_format_t format) +{ + cairo_image_surface_t *clone; + cairo_status_t status; + + status = surface->base.status; + if (unlikely (status)) + return (cairo_image_surface_t *)_cairo_surface_create_in_error (status); + + if (surface->format == format) + return (cairo_image_surface_t *)cairo_surface_reference(&surface->base); + + clone = (cairo_image_surface_t *) + cairo_image_surface_create (format, surface->width, surface->height); + if (unlikely (clone->base.status)) + return clone; + + pixman_image_composite32 (PIXMAN_OP_SRC, + surface->pixman_image, NULL, clone->pixman_image, + 0, 0, + 0, 0, + 0, 0, + surface->width, surface->height); + clone->base.is_clear = FALSE; + + clone->base.device_transform = + surface->base.device_transform; + clone->base.device_transform_inverse = + surface->base.device_transform_inverse; + + return clone; +} + +cairo_image_surface_t * +_cairo_image_surface_create_from_image (cairo_image_surface_t *other, + pixman_format_code_t format, + int x, int y, + int width, int height, int stride) +{ + cairo_image_surface_t *surface; + cairo_status_t status; + pixman_image_t *image; + void *mem = NULL; + + status = other->base.status; + if (unlikely (status)) + goto cleanup; + + if (stride) { + mem = _cairo_malloc_ab (height, stride); + if (unlikely (mem == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + } + + image = pixman_image_create_bits (format, width, height, mem, stride); + if (unlikely (image == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup_mem; + } + + surface = (cairo_image_surface_t *) + _cairo_image_surface_create_for_pixman_image (image, format); + if (unlikely (surface->base.status)) { + status = surface->base.status; + goto cleanup_image; + } + + pixman_image_composite32 (PIXMAN_OP_SRC, + other->pixman_image, NULL, image, + x, y, + 0, 0, + 0, 0, + width, height); + surface->base.is_clear = FALSE; + surface->owns_data = mem != NULL; + + return surface; + +cleanup_image: + pixman_image_unref (image); +cleanup_mem: + free (mem); +cleanup: + return (cairo_image_surface_t *) _cairo_surface_create_in_error (status); +} + +cairo_image_transparency_t +_cairo_image_analyze_transparency (cairo_image_surface_t *image) +{ + int x, y; + + if (image->transparency != CAIRO_IMAGE_UNKNOWN) + return image->transparency; + + if ((image->base.content & CAIRO_CONTENT_ALPHA) == 0) + return image->transparency = CAIRO_IMAGE_IS_OPAQUE; + + if (image->base.is_clear) + return image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; + + if ((image->base.content & CAIRO_CONTENT_COLOR) == 0) { + if (image->format == CAIRO_FORMAT_A1) { + return image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; + } else if (image->format == CAIRO_FORMAT_A8) { + for (y = 0; y < image->height; y++) { + uint8_t *alpha = (uint8_t *) (image->data + y * image->stride); + + for (x = 0; x < image->width; x++, alpha++) { + if (*alpha > 0 && *alpha < 255) + return image->transparency = CAIRO_IMAGE_HAS_ALPHA; + } + } + return image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; + } else { + return image->transparency = CAIRO_IMAGE_HAS_ALPHA; + } + } + + if (image->format == CAIRO_FORMAT_RGB16_565) { + image->transparency = CAIRO_IMAGE_IS_OPAQUE; + return CAIRO_IMAGE_IS_OPAQUE; + } + + if (image->format != CAIRO_FORMAT_ARGB32) + return image->transparency = CAIRO_IMAGE_HAS_ALPHA; + + image->transparency = CAIRO_IMAGE_IS_OPAQUE; + for (y = 0; y < image->height; y++) { + uint32_t *pixel = (uint32_t *) (image->data + y * image->stride); + + for (x = 0; x < image->width; x++, pixel++) { + int a = (*pixel & 0xff000000) >> 24; + if (a > 0 && a < 255) { + return image->transparency = CAIRO_IMAGE_HAS_ALPHA; + } else if (a == 0) { + image->transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; + } + } + } + + return image->transparency; +} + +cairo_image_color_t +_cairo_image_analyze_color (cairo_image_surface_t *image) +{ + int x, y; + + if (image->color != CAIRO_IMAGE_UNKNOWN_COLOR) + return image->color; + + if (image->format == CAIRO_FORMAT_A1) + return image->color = CAIRO_IMAGE_IS_MONOCHROME; + + if (image->format == CAIRO_FORMAT_A8) + return image->color = CAIRO_IMAGE_IS_GRAYSCALE; + + if (image->format == CAIRO_FORMAT_ARGB32) { + image->color = CAIRO_IMAGE_IS_MONOCHROME; + for (y = 0; y < image->height; y++) { + uint32_t *pixel = (uint32_t *) (image->data + y * image->stride); + + for (x = 0; x < image->width; x++, pixel++) { + int a = (*pixel & 0xff000000) >> 24; + int r = (*pixel & 0x00ff0000) >> 16; + int g = (*pixel & 0x0000ff00) >> 8; + int b = (*pixel & 0x000000ff); + if (a == 0) { + r = g = b = 0; + } else { + r = (r * 255 + a / 2) / a; + g = (g * 255 + a / 2) / a; + b = (b * 255 + a / 2) / a; + } + if (!(r == g && g == b)) + return image->color = CAIRO_IMAGE_IS_COLOR; + else if (r > 0 && r < 255) + image->color = CAIRO_IMAGE_IS_GRAYSCALE; + } + } + return image->color; + } + + if (image->format == CAIRO_FORMAT_RGB24) { + image->color = CAIRO_IMAGE_IS_MONOCHROME; + for (y = 0; y < image->height; y++) { + uint32_t *pixel = (uint32_t *) (image->data + y * image->stride); + + for (x = 0; x < image->width; x++, pixel++) { + int r = (*pixel & 0x00ff0000) >> 16; + int g = (*pixel & 0x0000ff00) >> 8; + int b = (*pixel & 0x000000ff); + if (!(r == g && g == b)) + return image->color = CAIRO_IMAGE_IS_COLOR; + else if (r > 0 && r < 255) + image->color = CAIRO_IMAGE_IS_GRAYSCALE; + } + } + return image->color; + } + + return image->color = CAIRO_IMAGE_IS_COLOR; +} + +cairo_image_surface_t * +_cairo_image_surface_clone_subimage (cairo_surface_t *surface, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_t *image; + cairo_surface_pattern_t pattern; + cairo_status_t status; + + image = cairo_surface_create_similar_image (surface, + _cairo_format_from_content (surface->content), + extents->width, + extents->height); + if (image->status) + return to_image_surface (image); + + /* TODO: check me with non-identity device_transform. Should we + * clone the scaling, too? */ + cairo_surface_set_device_offset (image, + -extents->x, + -extents->y); + + _cairo_pattern_init_for_surface (&pattern, surface); + pattern.base.filter = CAIRO_FILTER_NEAREST; + + status = _cairo_surface_paint (image, + CAIRO_OPERATOR_SOURCE, + &pattern.base, + NULL); + + _cairo_pattern_fini (&pattern.base); + + if (unlikely (status)) + goto error; + + /* We use the parent as a flag during map-to-image/umap-image that the + * resultant image came from a fallback rather than as direct call + * to the backend's map_to_image(). Whilst we use it as a simple flag, + * we need to make sure the parent surface obeys the reference counting + * semantics and is consistent for all callers. + */ + _cairo_image_surface_set_parent (to_image_surface (image), + cairo_surface_reference (surface)); + + return to_image_surface (image); + +error: + cairo_surface_destroy (image); + return to_image_surface (_cairo_surface_create_in_error (status)); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-line-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-line-inline.h new file mode 100644 index 00000000000..71cc5e7ebf4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-line-inline.h @@ -0,0 +1,48 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2014 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + */ + +#ifndef CAIRO_LINE_INLINE_H +#define CAIRO_LINE_INLINE_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" +#include "cairo-fixed-private.h" +#include "cairo-line-private.h" + +static inline int +cairo_lines_equal (const cairo_line_t *a, const cairo_line_t *b) +{ + return (a->p1.x == b->p1.x && a->p1.y == b->p1.y && + a->p2.x == b->p2.x && a->p2.y == b->p2.y); +} + +#endif /* CAIRO_LINE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-line-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-line-private.h new file mode 100644 index 00000000000..08bf4b3587c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-line-private.h @@ -0,0 +1,51 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2014 Intel Corporation, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + */ + +#ifndef CAIRO_LINE_PRIVATE_H +#define CAIRO_LINE_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-error-private.h" +#include "cairo-compiler-private.h" + +CAIRO_BEGIN_DECLS + +cairo_private int +cairo_lines_compare_at_y(const cairo_line_t *a, + const cairo_line_t *b, + int y); + +CAIRO_END_DECLS + +#endif /* CAIRO_LINE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-line.c b/Build/source/libs/cairo/cairo-src/src/cairo-line.c new file mode 100644 index 00000000000..cb13927bdce --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-line.c @@ -0,0 +1,306 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * Copyright © 2014 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + * + */ + +#include "cairoint.h" + +#include "cairo-line-inline.h" +#include "cairo-slope-private.h" + +static int +line_compare_for_y_against_x (const cairo_line_t *a, + int32_t y, + int32_t x) +{ + int32_t adx, ady; + int32_t dx, dy; + cairo_int64_t L, R; + + if (x < a->p1.x && x < a->p2.x) + return 1; + if (x > a->p1.x && x > a->p2.x) + return -1; + + adx = a->p2.x - a->p1.x; + dx = x - a->p1.x; + + if (adx == 0) + return -dx; + if (dx == 0 || (adx ^ dx) < 0) + return adx; + + dy = y - a->p1.y; + ady = a->p2.y - a->p1.y; + + L = _cairo_int32x32_64_mul (dy, adx); + R = _cairo_int32x32_64_mul (dx, ady); + + return _cairo_int64_cmp (L, R); +} + +/* + * We need to compare the x-coordinates of a pair of lines for a particular y, + * without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy + * - (Y - A_y) * A_dx * B_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 128 bit arithmetic. For certain, but common, + * input we can reduce this down to a single 32 bit compare by inspecting the + * deltas. + * + * (And put the burden of the work on developing fast 128 bit ops, which are + * required throughout the tessellator.) + * + * See the similar discussion for _slope_compare(). + */ +static int +lines_compare_x_for_y_general (const cairo_line_t *a, + const cairo_line_t *b, + int32_t y) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t dx; + int32_t adx, ady; + int32_t bdx, bdy; + enum { + HAVE_NONE = 0x0, + HAVE_DX = 0x1, + HAVE_ADX = 0x2, + HAVE_DX_ADX = HAVE_DX | HAVE_ADX, + HAVE_BDX = 0x4, + HAVE_DX_BDX = HAVE_DX | HAVE_BDX, + HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, + HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX + } have_dx_adx_bdx = HAVE_ALL; + + ady = a->p2.y - a->p1.y; + adx = a->p2.x - a->p1.x; + if (adx == 0) + have_dx_adx_bdx &= ~HAVE_ADX; + + bdy = b->p2.y - b->p1.y; + bdx = b->p2.x - b->p1.x; + if (bdx == 0) + have_dx_adx_bdx &= ~HAVE_BDX; + + dx = a->p1.x - b->p1.x; + if (dx == 0) + have_dx_adx_bdx &= ~HAVE_DX; + +#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) +#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->p1.y) +#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->p1.y) + switch (have_dx_adx_bdx) { + default: + case HAVE_NONE: + return 0; + case HAVE_DX: + /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ + return dx; /* ady * bdy is positive definite */ + case HAVE_ADX: + /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ + return adx; /* bdy * (y - a->top.y) is positive definite */ + case HAVE_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy */ + return -bdx; /* ady * (y - b->top.y) is positive definite */ + case HAVE_ADX_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ + if ((adx ^ bdx) < 0) { + return adx; + } else if (a->p1.y == b->p1.y) { /* common origin */ + cairo_int64_t adx_bdy, bdx_ady; + + /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ + + adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } else + return _cairo_int128_cmp (A, B); + case HAVE_DX_ADX: + /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ + if ((-adx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t ady_dx, dy_adx; + + ady_dx = _cairo_int32x32_64_mul (ady, dx); + dy_adx = _cairo_int32x32_64_mul (a->p1.y - y, adx); + + return _cairo_int64_cmp (ady_dx, dy_adx); + } + case HAVE_DX_BDX: + /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ + if ((bdx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t bdy_dx, dy_bdx; + + bdy_dx = _cairo_int32x32_64_mul (bdy, dx); + dy_bdx = _cairo_int32x32_64_mul (y - b->p1.y, bdx); + + return _cairo_int64_cmp (bdy_dx, dy_bdx); + } + case HAVE_ALL: + /* XXX try comparing (a->p2.x - b->p2.x) et al */ + return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); + } +#undef B +#undef A +#undef L +} + +static int +lines_compare_x_for_y (const cairo_line_t *a, + const cairo_line_t *b, + int32_t y) +{ + /* If the sweep-line is currently on an end-point of a line, + * then we know its precise x value (and considering that we often need to + * compare events at end-points, this happens frequently enough to warrant + * special casing). + */ + enum { + HAVE_NEITHER = 0x0, + HAVE_AX = 0x1, + HAVE_BX = 0x2, + HAVE_BOTH = HAVE_AX | HAVE_BX + } have_ax_bx = HAVE_BOTH; + int32_t ax, bx; + + if (y == a->p1.y) + ax = a->p1.x; + else if (y == a->p2.y) + ax = a->p2.x; + else + have_ax_bx &= ~HAVE_AX; + + if (y == b->p1.y) + bx = b->p1.x; + else if (y == b->p2.y) + bx = b->p2.x; + else + have_ax_bx &= ~HAVE_BX; + + switch (have_ax_bx) { + default: + case HAVE_NEITHER: + return lines_compare_x_for_y_general (a, b, y); + case HAVE_AX: + return -line_compare_for_y_against_x (b, y, ax); + case HAVE_BX: + return line_compare_for_y_against_x (a, y, bx); + case HAVE_BOTH: + return ax - bx; + } +} + +static int bbox_compare (const cairo_line_t *a, + const cairo_line_t *b) +{ + int32_t amin, amax; + int32_t bmin, bmax; + + if (a->p1.x < a->p2.x) { + amin = a->p1.x; + amax = a->p2.x; + } else { + amin = a->p2.x; + amax = a->p1.x; + } + + if (b->p1.x < b->p2.x) { + bmin = b->p1.x; + bmax = b->p2.x; + } else { + bmin = b->p2.x; + bmax = b->p1.x; + } + + if (amax < bmin) + return -1; + + if (amin > bmax) + return +1; + + return 0; +} + +int cairo_lines_compare_at_y (const cairo_line_t *a, + const cairo_line_t *b, + int y) +{ + cairo_slope_t sa, sb; + int ret; + + if (cairo_lines_equal (a, b)) + return 0; + + /* Don't bother solving for abscissa if the edges' bounding boxes + * can be used to order them. + */ + ret = bbox_compare (a, b); + if (ret) + return ret; + + ret = lines_compare_x_for_y (a, b, y); + if (ret) + return ret; + + _cairo_slope_init (&sa, &a->p1, &a->p2); + _cairo_slope_init (&sb, &b->p1, &b->p2); + + return _cairo_slope_compare (&sb, &sa); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-list-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-list-inline.h new file mode 100644 index 00000000000..0955178d24f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-list-inline.h @@ -0,0 +1,215 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + * + */ + +#ifndef CAIRO_LIST_INLINE_H +#define CAIRO_LIST_INLINE_H + +#include "cairo-list-private.h" + +#define cairo_list_entry(ptr, type, member) \ + cairo_container_of(ptr, type, member) + +#define cairo_list_first_entry(ptr, type, member) \ + cairo_list_entry((ptr)->next, type, member) + +#define cairo_list_last_entry(ptr, type, member) \ + cairo_list_entry((ptr)->prev, type, member) + +#define cairo_list_foreach(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +#define cairo_list_foreach_entry(pos, type, head, member) \ + for (pos = cairo_list_entry((head)->next, type, member);\ + &pos->member != (head); \ + pos = cairo_list_entry(pos->member.next, type, member)) + +#define cairo_list_foreach_entry_safe(pos, n, type, head, member) \ + for (pos = cairo_list_entry ((head)->next, type, member),\ + n = cairo_list_entry (pos->member.next, type, member);\ + &pos->member != (head); \ + pos = n, n = cairo_list_entry (n->member.next, type, member)) + +#define cairo_list_foreach_entry_reverse(pos, type, head, member) \ + for (pos = cairo_list_entry((head)->prev, type, member);\ + &pos->member != (head); \ + pos = cairo_list_entry(pos->member.prev, type, member)) + +#define cairo_list_foreach_entry_reverse_safe(pos, n, type, head, member) \ + for (pos = cairo_list_entry((head)->prev, type, member),\ + n = cairo_list_entry (pos->member.prev, type, member);\ + &pos->member != (head); \ + pos = n, n = cairo_list_entry (n->member.prev, type, member)) + +#ifdef CAIRO_LIST_DEBUG +static inline void +_cairo_list_validate (const cairo_list_t *link) +{ + assert (link->next->prev == link); + assert (link->prev->next == link); +} +static inline void +cairo_list_validate (const cairo_list_t *head) +{ + cairo_list_t *link; + + cairo_list_foreach (link, head) + _cairo_list_validate (link); +} +static inline cairo_bool_t +cairo_list_is_empty (const cairo_list_t *head); +static inline void +cairo_list_validate_is_empty (const cairo_list_t *head) +{ + assert (head->next == NULL || (cairo_list_is_empty (head) && head->next == head->prev)); +} +#else +#define _cairo_list_validate(link) +#define cairo_list_validate(head) +#define cairo_list_validate_is_empty(head) +#endif + +static inline void +cairo_list_init (cairo_list_t *entry) +{ + entry->next = entry; + entry->prev = entry; +} + +static inline void +__cairo_list_add (cairo_list_t *entry, + cairo_list_t *prev, + cairo_list_t *next) +{ + next->prev = entry; + entry->next = next; + entry->prev = prev; + prev->next = entry; +} + +static inline void +cairo_list_add (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + cairo_list_validate_is_empty (entry); + __cairo_list_add (entry, head, head->next); + cairo_list_validate (head); +} + +static inline void +cairo_list_add_tail (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + cairo_list_validate_is_empty (entry); + __cairo_list_add (entry, head->prev, head); + cairo_list_validate (head); +} + +static inline void +__cairo_list_del (cairo_list_t *prev, cairo_list_t *next) +{ + next->prev = prev; + prev->next = next; +} + +static inline void +_cairo_list_del (cairo_list_t *entry) +{ + __cairo_list_del (entry->prev, entry->next); +} + +static inline void +cairo_list_del (cairo_list_t *entry) +{ + _cairo_list_del (entry); + cairo_list_init (entry); +} + +static inline void +cairo_list_move (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + __cairo_list_del (entry->prev, entry->next); + __cairo_list_add (entry, head, head->next); + cairo_list_validate (head); +} + +static inline void +cairo_list_move_tail (cairo_list_t *entry, cairo_list_t *head) +{ + cairo_list_validate (head); + __cairo_list_del (entry->prev, entry->next); + __cairo_list_add (entry, head->prev, head); + cairo_list_validate (head); +} + +static inline void +cairo_list_swap (cairo_list_t *entry, cairo_list_t *other) +{ + __cairo_list_add (entry, other->prev, other->next); + cairo_list_init (other); +} + +static inline cairo_bool_t +cairo_list_is_first (const cairo_list_t *entry, + const cairo_list_t *head) +{ + cairo_list_validate (head); + return entry->prev == head; +} + +static inline cairo_bool_t +cairo_list_is_last (const cairo_list_t *entry, + const cairo_list_t *head) +{ + cairo_list_validate (head); + return entry->next == head; +} + +static inline cairo_bool_t +cairo_list_is_empty (const cairo_list_t *head) +{ + cairo_list_validate (head); + return head->next == head; +} + +static inline cairo_bool_t +cairo_list_is_singular (const cairo_list_t *head) +{ + cairo_list_validate (head); + return head->next == head || head->next == head->prev; +} + +#endif /* CAIRO_LIST_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-list-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-list-private.h new file mode 100644 index 00000000000..9f39b668f82 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-list-private.h @@ -0,0 +1,48 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + * + */ + +#ifndef CAIRO_LIST_PRIVATE_H +#define CAIRO_LIST_PRIVATE_H + +#include "cairo-compiler-private.h" + +/* Basic circular, doubly linked list implementation */ + +typedef struct _cairo_list { + struct _cairo_list *next, *prev; +} cairo_list_t; + +#endif /* CAIRO_LIST_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-lzw.c b/Build/source/libs/cairo/cairo-src/src/cairo-lzw.c new file mode 100644 index 00000000000..de7f9998376 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-lzw.c @@ -0,0 +1,404 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +typedef struct _lzw_buf { + cairo_status_t status; + + unsigned char *data; + int data_size; + int num_data; + uint32_t pending; + unsigned int pending_bits; +} lzw_buf_t; + +/* An lzw_buf_t is a simple, growable chunk of memory for holding + * variable-size objects of up to 16 bits each. + * + * Initialize an lzw_buf_t to the given size in bytes. + * + * To store objects into the lzw_buf_t, call _lzw_buf_store_bits and + * when finished, call _lzw_buf_store_pending, (which flushes out the + * last few bits that hadn't yet made a complete byte yet). + * + * Instead of returning failure from any functions, lzw_buf_t provides + * a status value that the caller can query, (and should query at + * least once when done with the object). The status value will be + * either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY; + */ +static void +_lzw_buf_init (lzw_buf_t *buf, int size) +{ + if (size == 0) + size = 16; + + buf->status = CAIRO_STATUS_SUCCESS; + buf->data_size = size; + buf->num_data = 0; + buf->pending = 0; + buf->pending_bits = 0; + + buf->data = malloc (size); + if (unlikely (buf->data == NULL)) { + buf->data_size = 0; + buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return; + } +} + +/* Increase the buffer size by doubling. + * + * Returns %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + */ +static cairo_status_t +_lzw_buf_grow (lzw_buf_t *buf) +{ + int new_size = buf->data_size * 2; + unsigned char *new_data; + + if (buf->status) + return buf->status; + + new_data = NULL; + /* check for integer overflow */ + if (new_size / 2 == buf->data_size) + new_data = realloc (buf->data, new_size); + + if (unlikely (new_data == NULL)) { + free (buf->data); + buf->data_size = 0; + buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return buf->status; + } + + buf->data = new_data; + buf->data_size = new_size; + + return CAIRO_STATUS_SUCCESS; +} + +/* Store the lowest num_bits bits of values into buf. + * + * Note: The bits of value above size_in_bits must be 0, (so don't lie + * about the size). + * + * See also _lzw_buf_store_pending which must be called after the last + * call to _lzw_buf_store_bits. + * + * Sets buf->status to either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY. + */ +static void +_lzw_buf_store_bits (lzw_buf_t *buf, uint16_t value, int num_bits) +{ + cairo_status_t status; + + assert (value <= (1 << num_bits) - 1); + + if (buf->status) + return; + + buf->pending = (buf->pending << num_bits) | value; + buf->pending_bits += num_bits; + + while (buf->pending_bits >= 8) { + if (buf->num_data >= buf->data_size) { + status = _lzw_buf_grow (buf); + if (unlikely (status)) + return; + } + buf->data[buf->num_data++] = buf->pending >> (buf->pending_bits - 8); + buf->pending_bits -= 8; + } +} + +/* Store the last remaining pending bits into the buffer. + * + * Note: This function must be called after the last call to + * _lzw_buf_store_bits. + * + * Sets buf->status to either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY. + */ +static void +_lzw_buf_store_pending (lzw_buf_t *buf) +{ + cairo_status_t status; + + if (buf->status) + return; + + if (buf->pending_bits == 0) + return; + + assert (buf->pending_bits < 8); + + if (buf->num_data >= buf->data_size) { + status = _lzw_buf_grow (buf); + if (unlikely (status)) + return; + } + + buf->data[buf->num_data++] = buf->pending << (8 - buf->pending_bits); + buf->pending_bits = 0; +} + +/* LZW defines a few magic code values */ +#define LZW_CODE_CLEAR_TABLE 256 +#define LZW_CODE_EOD 257 +#define LZW_CODE_FIRST 258 + +/* We pack three separate values into a symbol as follows: + * + * 12 bits (31 down to 20): CODE: code value used to represent this symbol + * 12 bits (19 down to 8): PREV: previous code value in chain + * 8 bits ( 7 down to 0): NEXT: next byte value in chain + */ +typedef uint32_t lzw_symbol_t; + +#define LZW_SYMBOL_SET(sym, prev, next) ((sym) = ((prev) << 8)|(next)) +#define LZW_SYMBOL_SET_CODE(sym, code, prev, next) ((sym) = ((code << 20)|(prev) << 8)|(next)) +#define LZW_SYMBOL_GET_CODE(sym) (((sym) >> 20)) +#define LZW_SYMBOL_GET_PREV(sym) (((sym) >> 8) & 0x7ff) +#define LZW_SYMBOL_GET_BYTE(sym) (((sym) >> 0) & 0x0ff) + +/* The PREV+NEXT fields can be seen as the key used to fetch values + * from the hash table, while the code is the value fetched. + */ +#define LZW_SYMBOL_KEY_MASK 0x000fffff + +/* Since code values are only stored starting with 258 we can safely + * use a zero value to represent free slots in the hash table. */ +#define LZW_SYMBOL_FREE 0x00000000 + +/* These really aren't very free for modifying. First, the PostScript + * specification sets the 9-12 bit range. Second, the encoding of + * lzw_symbol_t above also relies on 2 of LZW_BITS_MAX plus one byte + * fitting within 32 bits. + * + * But other than that, the LZW compression scheme could function with + * more bits per code. + */ +#define LZW_BITS_MIN 9 +#define LZW_BITS_MAX 12 +#define LZW_BITS_BOUNDARY(bits) ((1<<(bits))-1) +#define LZW_MAX_SYMBOLS (1<table, 0, LZW_SYMBOL_TABLE_SIZE * sizeof (lzw_symbol_t)); +} + +/* Lookup a symbol in the symbol table. The PREV and NEXT fields of + * symbol form the key for the lookup. + * + * If successful, then this function returns %TRUE and slot_ret will be + * left pointing at the result that will have the CODE field of + * interest. + * + * If the lookup fails, then this function returns %FALSE and slot_ret + * will be pointing at the location in the table to which a new CODE + * value should be stored along with PREV and NEXT. + */ +static cairo_bool_t +_lzw_symbol_table_lookup (lzw_symbol_table_t *table, + lzw_symbol_t symbol, + lzw_symbol_t **slot_ret) +{ + /* The algorithm here is identical to that in cairo-hash.c. We + * copy it here to allow for a rather more efficient + * implementation due to several circumstances that do not apply + * to the more general case: + * + * 1) We have a known bound on the total number of symbols, so we + * have a fixed-size table without any copying when growing + * + * 2) We never delete any entries, so we don't need to + * support/check for DEAD entries during lookup. + * + * 3) The object fits in 32 bits so we store each object in its + * entirety within the table rather than storing objects + * externally and putting pointers in the table, (which here + * would just double the storage requirements and have negative + * impacts on memory locality). + */ + int i, idx, step, hash = symbol & LZW_SYMBOL_KEY_MASK; + lzw_symbol_t candidate; + + idx = hash % LZW_SYMBOL_MOD1; + step = 0; + + *slot_ret = NULL; + for (i = 0; i < LZW_SYMBOL_TABLE_SIZE; i++) + { + candidate = table->table[idx]; + if (candidate == LZW_SYMBOL_FREE) + { + *slot_ret = &table->table[idx]; + return FALSE; + } + else /* candidate is LIVE */ + { + if ((candidate & LZW_SYMBOL_KEY_MASK) == + (symbol & LZW_SYMBOL_KEY_MASK)) + { + *slot_ret = &table->table[idx]; + return TRUE; + } + } + + if (step == 0) { + step = hash % LZW_SYMBOL_MOD2; + if (step == 0) + step = 1; + } + + idx += step; + if (idx >= LZW_SYMBOL_TABLE_SIZE) + idx -= LZW_SYMBOL_TABLE_SIZE; + } + + return FALSE; +} + +/* Compress a bytestream using the LZW algorithm. + * + * This is an original implementation based on reading the + * specification of the LZWDecode filter in the PostScript Language + * Reference. The free parameters in the LZW algorithm are set to the + * values mandated by PostScript, (symbols encoded with widths from 9 + * to 12 bits). + * + * This function returns a pointer to a newly allocated buffer holding + * the compressed data, or %NULL if an out-of-memory situation + * occurs. + * + * Notice that any one of the _lzw_buf functions called here could + * trigger an out-of-memory condition. But lzw_buf_t uses cairo's + * shutdown-on-error idiom, so it's safe to continue to call into + * lzw_buf without having to check for errors, (until a final check at + * the end). + */ +unsigned char * +_cairo_lzw_compress (unsigned char *data, unsigned long *size_in_out) +{ + int bytes_remaining = *size_in_out; + lzw_buf_t buf; + lzw_symbol_table_t table; + lzw_symbol_t symbol, *slot = NULL; /* just to squelch a warning */ + int code_next = LZW_CODE_FIRST; + int code_bits = LZW_BITS_MIN; + int prev, next = 0; /* just to squelch a warning */ + + if (*size_in_out == 0) + return NULL; + + _lzw_buf_init (&buf, *size_in_out); + + _lzw_symbol_table_init (&table); + + /* The LZW header is a clear table code. */ + _lzw_buf_store_bits (&buf, LZW_CODE_CLEAR_TABLE, code_bits); + + while (1) { + + /* Find the longest existing code in the symbol table that + * matches the current input, if any. */ + prev = *data++; + bytes_remaining--; + if (bytes_remaining) { + do + { + next = *data++; + bytes_remaining--; + LZW_SYMBOL_SET (symbol, prev, next); + if (_lzw_symbol_table_lookup (&table, symbol, &slot)) + prev = LZW_SYMBOL_GET_CODE (*slot); + } while (bytes_remaining && *slot != LZW_SYMBOL_FREE); + if (*slot == LZW_SYMBOL_FREE) { + data--; + bytes_remaining++; + } + } + + /* Write the code into the output. This is either a byte read + * directly from the input, or a code from the last successful + * lookup. */ + _lzw_buf_store_bits (&buf, prev, code_bits); + + if (bytes_remaining == 0) + break; + + LZW_SYMBOL_SET_CODE (*slot, code_next++, prev, next); + + if (code_next > LZW_BITS_BOUNDARY(code_bits)) + { + code_bits++; + if (code_bits > LZW_BITS_MAX) { + _lzw_symbol_table_init (&table); + _lzw_buf_store_bits (&buf, LZW_CODE_CLEAR_TABLE, code_bits - 1); + code_bits = LZW_BITS_MIN; + code_next = LZW_CODE_FIRST; + } + } + } + + /* The LZW footer is an end-of-data code. */ + _lzw_buf_store_bits (&buf, LZW_CODE_EOD, code_bits); + + _lzw_buf_store_pending (&buf); + + /* See if we ever ran out of memory while writing to buf. */ + if (buf.status == CAIRO_STATUS_NO_MEMORY) { + *size_in_out = 0; + return NULL; + } + + assert (buf.status == CAIRO_STATUS_SUCCESS); + + *size_in_out = buf.num_data; + return buf.data; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-malloc-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-malloc-private.h new file mode 100644 index 00000000000..1e2c67f8d9a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-malloc-private.h @@ -0,0 +1,149 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#ifndef CAIRO_MALLOC_PRIVATE_H +#define CAIRO_MALLOC_PRIVATE_H + +#include "cairo-wideint-private.h" +#include + +#if HAVE_MEMFAULT +#include +#define CAIRO_INJECT_FAULT() MEMFAULT_INJECT_FAULT() +#else +#define CAIRO_INJECT_FAULT() 0 +#endif + +/** + * _cairo_malloc: + * @size: size in bytes + * + * Allocate @size memory using malloc(). + * The memory should be freed using free(). + * malloc is skipped, if 0 bytes are requested, and %NULL will be returned. + * + * Return value: A pointer to the newly allocated memory, or %NULL in + * case of malloc() failure or size is 0. + **/ + +#define _cairo_malloc(size) \ + ((size) ? malloc((unsigned) (size)) : NULL) + +/** + * _cairo_malloc_ab: + * @a: number of elements to allocate + * @size: size of each element + * + * Allocates @a*@size memory using _cairo_malloc(), taking care to not + * overflow when doing the multiplication. Behaves much like + * calloc(), except that the returned memory is not set to zero. + * The memory should be freed using free(). + * + * @size should be a constant so that the compiler can optimize + * out a constant division. + * + * Return value: A pointer to the newly allocated memory, or %NULL in + * case of malloc() failure or overflow. + **/ + +#define _cairo_malloc_ab(a, size) \ + ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ + _cairo_malloc((unsigned) (a) * (unsigned) (size))) + +/** + * _cairo_realloc_ab: + * @ptr: original pointer to block of memory to be resized + * @a: number of elements to allocate + * @size: size of each element + * + * Reallocates @ptr a block of @a*@size memory using realloc(), taking + * care to not overflow when doing the multiplication. The memory + * should be freed using free(). + * + * @size should be a constant so that the compiler can optimize + * out a constant division. + * + * Return value: A pointer to the newly allocated memory, or %NULL in + * case of realloc() failure or overflow (whereupon the original block + * of memory * is left untouched). + **/ + +#define _cairo_realloc_ab(ptr, a, size) \ + ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ + realloc(ptr, (unsigned) (a) * (unsigned) (size))) + +/** + * _cairo_malloc_abc: + * @a: first factor of number of elements to allocate + * @b: second factor of number of elements to allocate + * @size: size of each element + * + * Allocates @a*@b*@size memory using _cairo_malloc(), taking care to not + * overflow when doing the multiplication. Behaves like + * _cairo_malloc_ab(). The memory should be freed using free(). + * + * @size should be a constant so that the compiler can optimize + * out a constant division. + * + * Return value: A pointer to the newly allocated memory, or %NULL in + * case of malloc() failure or overflow. + **/ + +#define _cairo_malloc_abc(a, b, size) \ + ((b) && (unsigned) (a) >= INT32_MAX / (unsigned) (b) ? NULL : \ + (size) && (unsigned) ((a)*(b)) >= INT32_MAX / (unsigned) (size) ? NULL : \ + _cairo_malloc((unsigned) (a) * (unsigned) (b) * (unsigned) (size))) + +/** + * _cairo_malloc_ab_plus_c: + * @a: number of elements to allocate + * @size: size of each element + * @c: additional size to allocate + * + * Allocates @a*@size+@c memory using _cairo_malloc(), taking care to not + * overflow when doing the arithmetic. Behaves similar to + * _cairo_malloc_ab(). The memory should be freed using free(). + * + * Return value: A pointer to the newly allocated memory, or %NULL in + * case of malloc() failure or overflow. + **/ + +#define _cairo_malloc_ab_plus_c(a, size, c) \ + ((size) && (unsigned) (a) >= INT32_MAX / (unsigned) (size) ? NULL : \ + (unsigned) (c) >= INT32_MAX - (unsigned) (a) * (unsigned) (size) ? NULL : \ + _cairo_malloc((unsigned) (a) * (unsigned) (size) + (unsigned) (c))) + +#endif /* CAIRO_MALLOC_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mask-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-mask-compositor.c new file mode 100644 index 00000000000..4d6b118dda5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mask-compositor.c @@ -0,0 +1,1481 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +/* This compositor renders the shape to a mask using an image surface + * then calls composite. + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-compositor-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-pattern-inline.h" +#include "cairo-region-private.h" +#include "cairo-surface-observer-private.h" +#include "cairo-surface-offset-private.h" +#include "cairo-surface-snapshot-private.h" +#include "cairo-surface-subsurface-private.h" + +typedef cairo_int_status_t +(*draw_func_t) (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *src, + const cairo_rectangle_int_t *src_sample, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip); + +static void do_unaligned_row(void (*blt)(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage), + void *closure, + const cairo_box_t *b, + int tx, int y, int h, + uint16_t coverage) +{ + int x1 = _cairo_fixed_integer_part (b->p1.x) - tx; + int x2 = _cairo_fixed_integer_part (b->p2.x) - tx; + if (x2 > x1) { + if (! _cairo_fixed_is_integer (b->p1.x)) { + blt(closure, x1, y, 1, h, + coverage * (256 - _cairo_fixed_fractional_part (b->p1.x))); + x1++; + } + + if (x2 > x1) + blt(closure, x1, y, x2-x1, h, (coverage << 8) - (coverage >> 8)); + + if (! _cairo_fixed_is_integer (b->p2.x)) + blt(closure, x2, y, 1, h, + coverage * _cairo_fixed_fractional_part (b->p2.x)); + } else + blt(closure, x1, y, 1, h, + coverage * (b->p2.x - b->p1.x)); +} + +static void do_unaligned_box(void (*blt)(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage), + void *closure, + const cairo_box_t *b, int tx, int ty) +{ + int y1 = _cairo_fixed_integer_part (b->p1.y) - ty; + int y2 = _cairo_fixed_integer_part (b->p2.y) - ty; + if (y2 > y1) { + if (! _cairo_fixed_is_integer (b->p1.y)) { + do_unaligned_row(blt, closure, b, tx, y1, 1, + 256 - _cairo_fixed_fractional_part (b->p1.y)); + y1++; + } + + if (y2 > y1) + do_unaligned_row(blt, closure, b, tx, y1, y2-y1, 256); + + if (! _cairo_fixed_is_integer (b->p2.y)) + do_unaligned_row(blt, closure, b, tx, y2, 1, + _cairo_fixed_fractional_part (b->p2.y)); + } else + do_unaligned_row(blt, closure, b, tx, y1, 1, + b->p2.y - b->p1.y); +} + +struct blt_in { + const cairo_mask_compositor_t *compositor; + cairo_surface_t *dst; +}; + +static void blt_in(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct blt_in *info = closure; + cairo_color_t color; + cairo_rectangle_int_t rect; + + if (coverage == 0xffff) + return; + + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + + _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double) 0xffff); + info->compositor->fill_rectangles (info->dst, CAIRO_OPERATOR_IN, + &color, &rect, 1); +} + +static cairo_surface_t * +create_composite_mask (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + void *draw_closure, + draw_func_t draw_func, + draw_func_t mask_func, + const cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *surface; + cairo_int_status_t status; + struct blt_in info; + int i; + + surface = _cairo_surface_create_scratch (dst, CAIRO_CONTENT_ALPHA, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (surface->status)) + return surface; + + status = compositor->acquire (surface); + if (unlikely (status)) { + cairo_surface_destroy (surface); + return _cairo_int_surface_create_in_error (status); + } + + if (!surface->is_clear) { + cairo_rectangle_int_t rect; + + rect.x = rect.y = 0; + rect.width = extents->bounded.width; + rect.height = extents->bounded.height; + + status = compositor->fill_rectangles (surface, CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &rect, 1); + if (unlikely (status)) + goto error; + } + + if (mask_func) { + status = mask_func (compositor, surface, draw_closure, + CAIRO_OPERATOR_SOURCE, NULL, NULL, + extents->bounded.x, extents->bounded.y, + &extents->bounded, extents->clip); + if (likely (status != CAIRO_INT_STATUS_UNSUPPORTED)) + goto out; + } + + /* Is it worth setting the clip region here? */ + status = draw_func (compositor, surface, draw_closure, + CAIRO_OPERATOR_ADD, NULL, NULL, + extents->bounded.x, extents->bounded.y, + &extents->bounded, NULL); + if (unlikely (status)) + goto error; + + info.compositor = compositor; + info.dst = surface; + for (i = 0; i < extents->clip->num_boxes; i++) { + cairo_box_t *b = &extents->clip->boxes[i]; + + if (! _cairo_fixed_is_integer (b->p1.x) || + ! _cairo_fixed_is_integer (b->p1.y) || + ! _cairo_fixed_is_integer (b->p2.x) || + ! _cairo_fixed_is_integer (b->p2.y)) + { + do_unaligned_box(blt_in, &info, b, + extents->bounded.x, + extents->bounded.y); + } + } + + if (extents->clip->path != NULL) { + status = _cairo_clip_combine_with_surface (extents->clip, surface, + extents->bounded.x, + extents->bounded.y); + if (unlikely (status)) + goto error; + } + +out: + compositor->release (surface); + surface->is_clear = FALSE; + return surface; + +error: + compositor->release (surface); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + cairo_surface_destroy (surface); + surface = _cairo_int_surface_create_in_error (status); + } + return surface; +} + +/* Handles compositing with a clip surface when the operator allows + * us to combine the clip with the mask + */ +static cairo_status_t +clip_and_composite_with_mask (const cairo_mask_compositor_t *compositor, + void *draw_closure, + draw_func_t draw_func, + draw_func_t mask_func, + cairo_operator_t op, + cairo_pattern_t *pattern, + const cairo_composite_rectangles_t*extents) +{ + cairo_surface_t *dst = extents->surface; + cairo_surface_t *mask, *src; + int src_x, src_y; + + mask = create_composite_mask (compositor, dst, draw_closure, + draw_func, mask_func, + extents); + if (unlikely (mask->status)) + return mask->status; + + if (pattern != NULL || dst->content != CAIRO_CONTENT_ALPHA) { + src = compositor->pattern_to_surface (dst, + &extents->source_pattern.base, + FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (unlikely (src->status)) { + cairo_surface_destroy (mask); + return src->status; + } + + compositor->composite (dst, op, src, mask, + extents->bounded.x + src_x, + extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + cairo_surface_destroy (src); + } else { + compositor->composite (dst, op, mask, NULL, + 0, 0, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } + cairo_surface_destroy (mask); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +get_clip_source (const cairo_mask_compositor_t *compositor, + cairo_clip_t *clip, + cairo_surface_t *dst, + const cairo_rectangle_int_t *bounds, + int *out_x, int *out_y) +{ + cairo_surface_pattern_t pattern; + cairo_rectangle_int_t r; + cairo_surface_t *surface; + + surface = _cairo_clip_get_image (clip, dst, bounds); + if (unlikely (surface->status)) + return surface; + + _cairo_pattern_init_for_surface (&pattern, surface); + pattern.base.filter = CAIRO_FILTER_NEAREST; + cairo_surface_destroy (surface); + + r.x = r.y = 0; + r.width = bounds->width; + r.height = bounds->height; + + surface = compositor->pattern_to_surface (dst, &pattern.base, TRUE, + &r, &r, out_x, out_y); + _cairo_pattern_fini (&pattern.base); + + *out_x += -bounds->x; + *out_y += -bounds->y; + return surface; +} + +/* Handles compositing with a clip surface when we have to do the operation + * in two pieces and combine them together. + */ +static cairo_status_t +clip_and_composite_combine (const cairo_mask_compositor_t *compositor, + void *draw_closure, + draw_func_t draw_func, + cairo_operator_t op, + const cairo_pattern_t *pattern, + const cairo_composite_rectangles_t*extents) +{ + cairo_surface_t *dst = extents->surface; + cairo_surface_t *tmp, *clip; + cairo_status_t status; + int clip_x, clip_y; + + tmp = _cairo_surface_create_scratch (dst, dst->content, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (tmp->status)) + return tmp->status; + + compositor->composite (tmp, CAIRO_OPERATOR_SOURCE, dst, NULL, + extents->bounded.x, extents->bounded.y, + 0, 0, + 0, 0, + extents->bounded.width, extents->bounded.height); + + status = draw_func (compositor, tmp, draw_closure, op, + pattern, &extents->source_sample_area, + extents->bounded.x, extents->bounded.y, + &extents->bounded, NULL); + if (unlikely (status)) + goto cleanup; + + clip = get_clip_source (compositor, + extents->clip, dst, &extents->bounded, + &clip_x, &clip_y); + if (unlikely ((status = clip->status))) + goto cleanup; + + if (dst->is_clear) { + compositor->composite (dst, CAIRO_OPERATOR_SOURCE, tmp, clip, + 0, 0, + clip_x, clip_y, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } else { + /* Punch the clip out of the destination */ + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, clip, NULL, + clip_x, clip_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + /* Now add the two results together */ + compositor->composite (dst, CAIRO_OPERATOR_ADD, tmp, clip, + 0, 0, + clip_x, clip_y, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } + cairo_surface_destroy (clip); + +cleanup: + cairo_surface_destroy (tmp); + return status; +} + +/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's + * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) + */ +static cairo_status_t +clip_and_composite_source (const cairo_mask_compositor_t *compositor, + void *draw_closure, + draw_func_t draw_func, + draw_func_t mask_func, + cairo_pattern_t *pattern, + const cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *dst = extents->surface; + cairo_surface_t *mask, *src; + int src_x, src_y; + + /* Create a surface that is mask IN clip */ + mask = create_composite_mask (compositor, dst, draw_closure, + draw_func, mask_func, + extents); + if (unlikely (mask->status)) + return mask->status; + + src = compositor->pattern_to_surface (dst, + pattern, + FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (unlikely (src->status)) { + cairo_surface_destroy (mask); + return src->status; + } + + if (dst->is_clear) { + compositor->composite (dst, CAIRO_OPERATOR_SOURCE, src, mask, + extents->bounded.x + src_x, extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } else { + /* Compute dest' = dest OUT (mask IN clip) */ + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + 0, 0, 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + /* Now compute (src IN (mask IN clip)) ADD dest' */ + compositor->composite (dst, CAIRO_OPERATOR_ADD, src, mask, + extents->bounded.x + src_x, extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } + + cairo_surface_destroy (src); + cairo_surface_destroy (mask); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +can_reduce_alpha_op (cairo_operator_t op) +{ + int iop = op; + switch (iop) { + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_ADD: + return TRUE; + default: + return FALSE; + } +} + +static cairo_bool_t +reduce_alpha_op (cairo_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *pattern) +{ + return dst->is_clear && + dst->content == CAIRO_CONTENT_ALPHA && + _cairo_pattern_is_opaque_solid (pattern) && + can_reduce_alpha_op (op); +} + +static cairo_status_t +fixup_unbounded (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + const cairo_composite_rectangles_t *extents) +{ + cairo_rectangle_int_t rects[4]; + int n; + + if (extents->bounded.width == extents->unbounded.width && + extents->bounded.height == extents->unbounded.height) + { + return CAIRO_STATUS_SUCCESS; + } + + n = 0; + if (extents->bounded.width == 0 || extents->bounded.height == 0) { + rects[n].x = extents->unbounded.x; + rects[n].width = extents->unbounded.width; + rects[n].y = extents->unbounded.y; + rects[n].height = extents->unbounded.height; + n++; + } else { + /* top */ + if (extents->bounded.y != extents->unbounded.y) { + rects[n].x = extents->unbounded.x; + rects[n].width = extents->unbounded.width; + rects[n].y = extents->unbounded.y; + rects[n].height = extents->bounded.y - extents->unbounded.y; + n++; + } + /* left */ + if (extents->bounded.x != extents->unbounded.x) { + rects[n].x = extents->unbounded.x; + rects[n].width = extents->bounded.x - extents->unbounded.x; + rects[n].y = extents->bounded.y; + rects[n].height = extents->bounded.height; + n++; + } + /* right */ + if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { + rects[n].x = extents->bounded.x + extents->bounded.width; + rects[n].width = extents->unbounded.x + extents->unbounded.width - rects[n].x; + rects[n].y = extents->bounded.y; + rects[n].height = extents->bounded.height; + n++; + } + /* bottom */ + if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { + rects[n].x = extents->unbounded.x; + rects[n].width = extents->unbounded.width; + rects[n].y = extents->bounded.y + extents->bounded.height; + rects[n].height = extents->unbounded.y + extents->unbounded.height - rects[n].y; + n++; + } + } + + return compositor->fill_rectangles (dst, CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + rects, n); +} + +static cairo_status_t +fixup_unbounded_with_mask (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + const cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *mask; + int mask_x, mask_y; + + mask = get_clip_source (compositor, + extents->clip, dst, &extents->unbounded, + &mask_x, &mask_y); + if (unlikely (mask->status)) + return mask->status; + + /* top */ + if (extents->bounded.y != extents->unbounded.y) { + int x = extents->unbounded.x; + int y = extents->unbounded.y; + int width = extents->unbounded.width; + int height = extents->bounded.y - y; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + x + mask_x, y + mask_y, + 0, 0, + x, y, + width, height); + } + + /* left */ + if (extents->bounded.x != extents->unbounded.x) { + int x = extents->unbounded.x; + int y = extents->bounded.y; + int width = extents->bounded.x - x; + int height = extents->bounded.height; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + x + mask_x, y + mask_y, + 0, 0, + x, y, + width, height); + } + + /* right */ + if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { + int x = extents->bounded.x + extents->bounded.width; + int y = extents->bounded.y; + int width = extents->unbounded.x + extents->unbounded.width - x; + int height = extents->bounded.height; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + x + mask_x, y + mask_y, + 0, 0, + x, y, + width, height); + } + + /* bottom */ + if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { + int x = extents->unbounded.x; + int y = extents->bounded.y + extents->bounded.height; + int width = extents->unbounded.width; + int height = extents->unbounded.y + extents->unbounded.height - y; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + x + mask_x, y + mask_y, + 0, 0, + x, y, + width, height); + } + + cairo_surface_destroy (mask); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +fixup_unbounded_boxes (const cairo_mask_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + cairo_boxes_t clear; + cairo_region_t *clip_region; + cairo_box_t box; + cairo_status_t status; + struct _cairo_boxes_chunk *chunk; + int i; + + assert (boxes->is_pixel_aligned); + + clip_region = NULL; + if (_cairo_clip_is_region (extents->clip) && + (clip_region = _cairo_clip_get_region (extents->clip)) && + cairo_region_contains_rectangle (clip_region, + &extents->bounded) == CAIRO_REGION_OVERLAP_IN) + clip_region = NULL; + + + if (boxes->num_boxes <= 1 && clip_region == NULL) + return fixup_unbounded (compositor, dst, extents); + + _cairo_boxes_init (&clear); + + box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); + box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); + box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); + box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); + + if (clip_region == NULL) { + cairo_boxes_t tmp; + + _cairo_boxes_init (&tmp); + + status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_STATUS_SUCCESS); + + tmp.chunks.next = &boxes->chunks; + tmp.num_boxes += boxes->num_boxes; + + status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, + CAIRO_FILL_RULE_WINDING, + &clear); + + tmp.chunks.next = NULL; + } else { + pixman_box32_t *pbox; + + pbox = pixman_region32_rectangles (&clip_region->rgn, &i); + _cairo_boxes_limit (&clear, (cairo_box_t *) pbox, i); + + status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_STATUS_SUCCESS); + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + status = _cairo_boxes_add (&clear, + CAIRO_ANTIALIAS_DEFAULT, + &chunk->base[i]); + if (unlikely (status)) { + _cairo_boxes_fini (&clear); + return status; + } + } + } + + status = _cairo_bentley_ottmann_tessellate_boxes (&clear, + CAIRO_FILL_RULE_WINDING, + &clear); + } + + if (likely (status == CAIRO_STATUS_SUCCESS)) { + status = compositor->fill_boxes (dst, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + } + + _cairo_boxes_fini (&clear); + + return status; +} + +enum { + NEED_CLIP_REGION = 0x1, + NEED_CLIP_SURFACE = 0x2, + FORCE_CLIP_REGION = 0x4, +}; + +static cairo_bool_t +need_bounded_clip (cairo_composite_rectangles_t *extents) +{ + unsigned int flags = NEED_CLIP_REGION; + if (! _cairo_clip_is_region (extents->clip)) + flags |= NEED_CLIP_SURFACE; + return flags; +} + +static cairo_bool_t +need_unbounded_clip (cairo_composite_rectangles_t *extents) +{ + unsigned int flags = 0; + if (! extents->is_bounded) { + flags |= NEED_CLIP_REGION; + if (! _cairo_clip_is_region (extents->clip)) + flags |= NEED_CLIP_SURFACE; + } + if (extents->clip->path != NULL) + flags |= NEED_CLIP_SURFACE; + return flags; +} + +static cairo_status_t +clip_and_composite (const cairo_mask_compositor_t *compositor, + draw_func_t draw_func, + draw_func_t mask_func, + void *draw_closure, + cairo_composite_rectangles_t*extents, + unsigned int need_clip) +{ + cairo_surface_t *dst = extents->surface; + cairo_operator_t op = extents->op; + cairo_pattern_t *src = &extents->source_pattern.base; + cairo_region_t *clip_region = NULL; + cairo_status_t status; + + compositor->acquire (dst); + + if (need_clip & NEED_CLIP_REGION) { + clip_region = _cairo_clip_get_region (extents->clip); + if ((need_clip & FORCE_CLIP_REGION) == 0 && + _cairo_composite_rectangles_can_reduce_clip (extents, + extents->clip)) + clip_region = NULL; + if (clip_region != NULL) { + status = compositor->set_clip_region (dst, clip_region); + if (unlikely (status)) { + compositor->release (dst); + return status; + } + } + } + + if (reduce_alpha_op (dst, op, &extents->source_pattern.base)) { + op = CAIRO_OPERATOR_ADD; + src = NULL; + } + + if (op == CAIRO_OPERATOR_SOURCE) { + status = clip_and_composite_source (compositor, + draw_closure, draw_func, mask_func, + src, extents); + } else { + if (op == CAIRO_OPERATOR_CLEAR) { + op = CAIRO_OPERATOR_DEST_OUT; + src = NULL; + } + + if (need_clip & NEED_CLIP_SURFACE) { + if (extents->is_bounded) { + status = clip_and_composite_with_mask (compositor, + draw_closure, + draw_func, + mask_func, + op, src, extents); + } else { + status = clip_and_composite_combine (compositor, + draw_closure, + draw_func, + op, src, extents); + } + } else { + status = draw_func (compositor, + dst, draw_closure, + op, src, &extents->source_sample_area, + 0, 0, + &extents->bounded, + extents->clip); + } + } + + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { + if (need_clip & NEED_CLIP_SURFACE) + status = fixup_unbounded_with_mask (compositor, dst, extents); + else + status = fixup_unbounded (compositor, dst, extents); + } + + if (clip_region) + compositor->set_clip_region (dst, NULL); + + compositor->release (dst); + + return status; +} + +static cairo_int_status_t +trim_extents_to_boxes (cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_box_t box; + + _cairo_boxes_extents (boxes, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_status_t +upload_boxes (const cairo_mask_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + const cairo_pattern_t *source = &extents->source_pattern.base; + cairo_surface_t *src; + cairo_rectangle_int_t limit; + cairo_int_status_t status; + int tx, ty; + + src = _cairo_pattern_get_source ((cairo_surface_pattern_t *)source, &limit); + if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Check that the data is entirely within the image */ + if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width || + extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height) + return CAIRO_INT_STATUS_UNSUPPORTED; + + tx += limit.x; + ty += limit.y; + + if (src->type == CAIRO_SURFACE_TYPE_IMAGE) + status = compositor->draw_image_boxes (dst, + (cairo_image_surface_t *)src, + boxes, tx, ty); + else + status = compositor->copy_boxes (dst, src, boxes, &extents->bounded, + tx, ty); + + return status; +} + +static cairo_status_t +composite_boxes (const cairo_mask_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + cairo_operator_t op = extents->op; + const cairo_pattern_t *source = &extents->source_pattern.base; + cairo_bool_t need_clip_mask = extents->clip->path != NULL; + cairo_status_t status; + + if (need_clip_mask && + (! extents->is_bounded || op == CAIRO_OPERATOR_SOURCE)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = compositor->acquire (dst); + if (unlikely (status)) + return status; + + if (! need_clip_mask && source->type == CAIRO_PATTERN_TYPE_SOLID) { + const cairo_color_t *color; + + color = &((cairo_solid_pattern_t *) source)->color; + status = compositor->fill_boxes (dst, op, color, boxes); + } else { + cairo_surface_t *src, *mask = NULL; + int src_x, src_y; + int mask_x = 0, mask_y = 0; + + if (need_clip_mask) { + mask = get_clip_source (compositor, + extents->clip, dst, &extents->bounded, + &mask_x, &mask_y); + if (unlikely (mask->status)) + return mask->status; + + if (op == CAIRO_OPERATOR_CLEAR) { + source = NULL; + op = CAIRO_OPERATOR_DEST_OUT; + } + } + + if (source || mask == NULL) { + src = compositor->pattern_to_surface (dst, source, FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + } else { + src = mask; + src_x = mask_x; + src_y = mask_y; + mask = NULL; + } + + status = compositor->composite_boxes (dst, op, src, mask, + src_x, src_y, + mask_x, mask_y, + 0, 0, + boxes, &extents->bounded); + + cairo_surface_destroy (src); + cairo_surface_destroy (mask); + } + + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) + status = fixup_unbounded_boxes (compositor, extents, boxes); + + compositor->release (dst); + + return status; +} + +static cairo_status_t +clip_and_composite_boxes (const cairo_mask_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + cairo_int_status_t status; + + if (boxes->num_boxes == 0) { + if (extents->is_bounded) + return CAIRO_STATUS_SUCCESS; + + return fixup_unbounded_boxes (compositor, extents, boxes); + } + + if (! boxes->is_pixel_aligned) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = trim_extents_to_boxes (extents, boxes); + if (unlikely (status)) + return status; + + if (extents->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && + extents->clip->path == NULL && + (extents->op == CAIRO_OPERATOR_SOURCE || + (dst->is_clear && (extents->op == CAIRO_OPERATOR_OVER || + extents->op == CAIRO_OPERATOR_ADD)))) + { + status = upload_boxes (compositor, extents, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + return composite_boxes (compositor, extents, boxes); +} + +/* high-level compositor interface */ + +static cairo_int_status_t +_cairo_mask_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; + cairo_boxes_t boxes; + cairo_int_status_t status; + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + _cairo_clip_steal_boxes (extents->clip, &boxes); + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_clip_unsteal_boxes (extents->clip, &boxes); + + return status; +} + +struct composite_opacity_info { + const cairo_mask_compositor_t *compositor; + uint8_t op; + cairo_surface_t *dst; + cairo_surface_t *src; + int src_x, src_y; + double opacity; +}; + +static void composite_opacity(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct composite_opacity_info *info = closure; + const cairo_mask_compositor_t *compositor = info->compositor; + cairo_surface_t *mask; + int mask_x, mask_y; + cairo_color_t color; + cairo_solid_pattern_t solid; + + _cairo_color_init_rgba (&color, 0, 0, 0, info->opacity * coverage); + _cairo_pattern_init_solid (&solid, &color); + mask = compositor->pattern_to_surface (info->dst, &solid.base, TRUE, + &_cairo_unbounded_rectangle, + &_cairo_unbounded_rectangle, + &mask_x, &mask_y); + if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { + if (info->src) { + compositor->composite (info->dst, info->op, info->src, mask, + x + info->src_x, y + info->src_y, + mask_x, mask_y, + x, y, + w, h); + } else { + compositor->composite (info->dst, info->op, mask, NULL, + mask_x, mask_y, + 0, 0, + x, y, + w, h); + } + } + + cairo_surface_destroy (mask); +} + +static cairo_int_status_t +composite_opacity_boxes (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + const cairo_rectangle_int_t *src_sample, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + const cairo_solid_pattern_t *mask_pattern = closure; + struct composite_opacity_info info; + int i; + + assert (clip); + + info.compositor = compositor; + info.op = op; + info.dst = dst; + + if (src_pattern != NULL) { + info.src = compositor->pattern_to_surface (dst, src_pattern, FALSE, + extents, src_sample, + &info.src_x, &info.src_y); + if (unlikely (info.src->status)) + return info.src->status; + } else + info.src = NULL; + + info.opacity = mask_pattern->color.alpha / (double) 0xffff; + + /* XXX for lots of boxes create a clip region for the fully opaque areas */ + for (i = 0; i < clip->num_boxes; i++) + do_unaligned_box(composite_opacity, &info, + &clip->boxes[i], dst_x, dst_y); + cairo_surface_destroy (info.src); + + return CAIRO_STATUS_SUCCESS; +} + +struct composite_box_info { + const cairo_mask_compositor_t *compositor; + cairo_surface_t *dst; + cairo_surface_t *src; + int src_x, src_y; + uint8_t op; +}; + +static void composite_box(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct composite_box_info *info = closure; + const cairo_mask_compositor_t *compositor = info->compositor; + + if (! CAIRO_ALPHA_SHORT_IS_OPAQUE (coverage)) { + cairo_surface_t *mask; + cairo_color_t color; + cairo_solid_pattern_t solid; + int mask_x, mask_y; + + _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double)0xffff); + _cairo_pattern_init_solid (&solid, &color); + + mask = compositor->pattern_to_surface (info->dst, &solid.base, FALSE, + &_cairo_unbounded_rectangle, + &_cairo_unbounded_rectangle, + &mask_x, &mask_y); + + if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { + compositor->composite (info->dst, info->op, info->src, mask, + x + info->src_x, y + info->src_y, + mask_x, mask_y, + x, y, + w, h); + } + + cairo_surface_destroy (mask); + } else { + compositor->composite (info->dst, info->op, info->src, NULL, + x + info->src_x, y + info->src_y, + 0, 0, + x, y, + w, h); + } +} + +static cairo_int_status_t +composite_mask_clip_boxes (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + const cairo_rectangle_int_t *src_sample, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + cairo_composite_rectangles_t *composite = closure; + struct composite_box_info info; + int i; + + assert (src_pattern == NULL); + assert (op == CAIRO_OPERATOR_SOURCE); + + info.compositor = compositor; + info.op = CAIRO_OPERATOR_SOURCE; + info.dst = dst; + info.src = compositor->pattern_to_surface (dst, + &composite->mask_pattern.base, + FALSE, extents, + &composite->mask_sample_area, + &info.src_x, &info.src_y); + if (unlikely (info.src->status)) + return info.src->status; + + info.src_x += dst_x; + info.src_y += dst_y; + + for (i = 0; i < clip->num_boxes; i++) + do_unaligned_box(composite_box, &info, &clip->boxes[i], dst_x, dst_y); + + cairo_surface_destroy (info.src); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_mask (const cairo_mask_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + const cairo_rectangle_int_t *src_sample, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + cairo_composite_rectangles_t *composite = closure; + cairo_surface_t *src, *mask; + int src_x, src_y; + int mask_x, mask_y; + + if (src_pattern != NULL) { + src = compositor->pattern_to_surface (dst, src_pattern, FALSE, + extents, src_sample, + &src_x, &src_y); + if (unlikely (src->status)) + return src->status; + + mask = compositor->pattern_to_surface (dst, &composite->mask_pattern.base, TRUE, + extents, &composite->mask_sample_area, + &mask_x, &mask_y); + if (unlikely (mask->status)) { + cairo_surface_destroy (src); + return mask->status; + } + + compositor->composite (dst, op, src, mask, + extents->x + src_x, extents->y + src_y, + extents->x + mask_x, extents->y + mask_y, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + cairo_surface_destroy (mask); + cairo_surface_destroy (src); + } else { + src = compositor->pattern_to_surface (dst, &composite->mask_pattern.base, FALSE, + extents, &composite->mask_sample_area, + &src_x, &src_y); + if (unlikely (src->status)) + return src->status; + + compositor->composite (dst, op, src, NULL, + extents->x + src_x, extents->y + src_y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + cairo_surface_destroy (src); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_mask_compositor_mask (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + if (extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && + extents->clip->path == NULL && + _cairo_clip_is_region (extents->clip)) { + status = clip_and_composite (compositor, + composite_opacity_boxes, + composite_opacity_boxes, + &extents->mask_pattern.solid, + extents, need_unbounded_clip (extents)); + } else { + status = clip_and_composite (compositor, + composite_mask, + extents->clip->path == NULL ? composite_mask_clip_boxes : NULL, + extents, + extents, need_bounded_clip (extents)); + } + + return status; +} + +static cairo_int_status_t +_cairo_mask_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; + cairo_surface_t *mask; + cairo_surface_pattern_t pattern; + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + if (_cairo_path_fixed_stroke_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, extents->clip); + status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, + style, + ctm, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + mask = cairo_surface_create_similar_image (extents->surface, + CAIRO_FORMAT_A8, + extents->bounded.width, + extents->bounded.height); + if (unlikely (mask->status)) + return mask->status; + + status = _cairo_surface_offset_stroke (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + path, style, ctm, ctm_inverse, + tolerance, antialias, + extents->clip); + if (unlikely (status)) { + cairo_surface_destroy (mask); + return status; + } + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_surface_destroy (mask); + + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->bounded.x, + -extents->bounded.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + status = _cairo_surface_mask (extents->surface, + extents->op, + &extents->source_pattern.base, + &pattern.base, + extents->clip); + _cairo_pattern_fini (&pattern.base); + } + + return status; +} + +static cairo_int_status_t +_cairo_mask_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; + cairo_surface_t *mask; + cairo_surface_pattern_t pattern; + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + if (_cairo_path_fixed_fill_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, extents->clip); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + fill_rule, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + mask = cairo_surface_create_similar_image (extents->surface, + CAIRO_FORMAT_A8, + extents->bounded.width, + extents->bounded.height); + if (unlikely (mask->status)) + return mask->status; + + status = _cairo_surface_offset_fill (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + path, fill_rule, tolerance, antialias, + extents->clip); + if (unlikely (status)) { + cairo_surface_destroy (mask); + return status; + } + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_surface_destroy (mask); + + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->bounded.x, + -extents->bounded.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + status = _cairo_surface_mask (extents->surface, + extents->op, + &extents->source_pattern.base, + &pattern.base, + extents->clip); + _cairo_pattern_fini (&pattern.base); + } + + return status; +} + +static cairo_int_status_t +_cairo_mask_compositor_glyphs (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + const cairo_mask_compositor_t *compositor = (cairo_mask_compositor_t*)_compositor; + cairo_surface_t *mask; + cairo_surface_pattern_t pattern; + cairo_int_status_t status; + + status = compositor->check_composite (extents); + if (unlikely (status)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + mask = cairo_surface_create_similar_image (extents->surface, + CAIRO_FORMAT_A8, + extents->bounded.width, + extents->bounded.height); + if (unlikely (mask->status)) + return mask->status; + + status = _cairo_surface_offset_glyphs (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + scaled_font, glyphs, num_glyphs, + extents->clip); + if (unlikely (status)) { + cairo_surface_destroy (mask); + return status; + } + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_surface_destroy (mask); + + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->bounded.x, + -extents->bounded.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + status = _cairo_surface_mask (extents->surface, + extents->op, + &extents->source_pattern.base, + &pattern.base, + extents->clip); + _cairo_pattern_fini (&pattern.base); + + return status; +} + +void +_cairo_mask_compositor_init (cairo_mask_compositor_t *compositor, + const cairo_compositor_t *delegate) +{ + compositor->base.delegate = delegate; + + compositor->base.paint = _cairo_mask_compositor_paint; + compositor->base.mask = _cairo_mask_compositor_mask; + compositor->base.fill = _cairo_mask_compositor_fill; + compositor->base.stroke = _cairo_mask_compositor_stroke; + compositor->base.glyphs = _cairo_mask_compositor_glyphs; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-matrix.c b/Build/source/libs/cairo/cairo-src/src/cairo-matrix.c new file mode 100644 index 00000000000..ae498f5151a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-matrix.c @@ -0,0 +1,1212 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" +#include "cairo-error-private.h" +#include + +#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ + +#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE) +#define ISFINITE(x) isfinite (x) +#else +#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */ +#endif + +/** + * SECTION:cairo-matrix + * @Title: cairo_matrix_t + * @Short_Description: Generic matrix operations + * @See_Also: #cairo_t + * + * #cairo_matrix_t is used throughout cairo to convert between different + * coordinate spaces. A #cairo_matrix_t holds an affine transformation, + * such as a scale, rotation, shear, or a combination of these. + * The transformation of a point (x,y) + * is given by: + * + * + * x_new = xx * x + xy * y + x0; + * y_new = yx * x + yy * y + y0; + * + * + * The current transformation matrix of a #cairo_t, represented as a + * #cairo_matrix_t, defines the transformation from user-space + * coordinates to device-space coordinates. See cairo_get_matrix() and + * cairo_set_matrix(). + **/ + +static void +_cairo_matrix_scalar_multiply (cairo_matrix_t *matrix, double scalar); + +static void +_cairo_matrix_compute_adjoint (cairo_matrix_t *matrix); + +/** + * cairo_matrix_init_identity: + * @matrix: a #cairo_matrix_t + * + * Modifies @matrix to be an identity transformation. + * + * Since: 1.0 + **/ +void +cairo_matrix_init_identity (cairo_matrix_t *matrix) +{ + cairo_matrix_init (matrix, + 1, 0, + 0, 1, + 0, 0); +} +slim_hidden_def(cairo_matrix_init_identity); + +/** + * cairo_matrix_init: + * @matrix: a #cairo_matrix_t + * @xx: xx component of the affine transformation + * @yx: yx component of the affine transformation + * @xy: xy component of the affine transformation + * @yy: yy component of the affine transformation + * @x0: X translation component of the affine transformation + * @y0: Y translation component of the affine transformation + * + * Sets @matrix to be the affine transformation given by + * @xx, @yx, @xy, @yy, @x0, @y0. The transformation is given + * by: + * + * x_new = xx * x + xy * y + x0; + * y_new = yx * x + yy * y + y0; + * + * + * Since: 1.0 + **/ +void +cairo_matrix_init (cairo_matrix_t *matrix, + double xx, double yx, + + double xy, double yy, + double x0, double y0) +{ + matrix->xx = xx; matrix->yx = yx; + matrix->xy = xy; matrix->yy = yy; + matrix->x0 = x0; matrix->y0 = y0; +} +slim_hidden_def(cairo_matrix_init); + +/** + * _cairo_matrix_get_affine: + * @matrix: a #cairo_matrix_t + * @xx: location to store xx component of matrix + * @yx: location to store yx component of matrix + * @xy: location to store xy component of matrix + * @yy: location to store yy component of matrix + * @x0: location to store x0 (X-translation component) of matrix, or %NULL + * @y0: location to store y0 (Y-translation component) of matrix, or %NULL + * + * Gets the matrix values for the affine transformation that @matrix represents. + * See cairo_matrix_init(). + * + * + * This function is a leftover from the old public API, but is still + * mildly useful as an internal means for getting at the matrix + * members in a positional way. For example, when reassigning to some + * external matrix type, or when renaming members to more meaningful + * names (such as a,b,c,d,e,f) for particular manipulations. + **/ +void +_cairo_matrix_get_affine (const cairo_matrix_t *matrix, + double *xx, double *yx, + double *xy, double *yy, + double *x0, double *y0) +{ + *xx = matrix->xx; + *yx = matrix->yx; + + *xy = matrix->xy; + *yy = matrix->yy; + + if (x0) + *x0 = matrix->x0; + if (y0) + *y0 = matrix->y0; +} + +/** + * cairo_matrix_init_translate: + * @matrix: a #cairo_matrix_t + * @tx: amount to translate in the X direction + * @ty: amount to translate in the Y direction + * + * Initializes @matrix to a transformation that translates by @tx and + * @ty in the X and Y dimensions, respectively. + * + * Since: 1.0 + **/ +void +cairo_matrix_init_translate (cairo_matrix_t *matrix, + double tx, double ty) +{ + cairo_matrix_init (matrix, + 1, 0, + 0, 1, + tx, ty); +} +slim_hidden_def(cairo_matrix_init_translate); + +/** + * cairo_matrix_translate: + * @matrix: a #cairo_matrix_t + * @tx: amount to translate in the X direction + * @ty: amount to translate in the Y direction + * + * Applies a translation by @tx, @ty to the transformation in + * @matrix. The effect of the new transformation is to first translate + * the coordinates by @tx and @ty, then apply the original transformation + * to the coordinates. + * + * Since: 1.0 + **/ +void +cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty) +{ + cairo_matrix_t tmp; + + cairo_matrix_init_translate (&tmp, tx, ty); + + cairo_matrix_multiply (matrix, &tmp, matrix); +} +slim_hidden_def (cairo_matrix_translate); + +/** + * cairo_matrix_init_scale: + * @matrix: a #cairo_matrix_t + * @sx: scale factor in the X direction + * @sy: scale factor in the Y direction + * + * Initializes @matrix to a transformation that scales by @sx and @sy + * in the X and Y dimensions, respectively. + * + * Since: 1.0 + **/ +void +cairo_matrix_init_scale (cairo_matrix_t *matrix, + double sx, double sy) +{ + cairo_matrix_init (matrix, + sx, 0, + 0, sy, + 0, 0); +} +slim_hidden_def(cairo_matrix_init_scale); + +/** + * cairo_matrix_scale: + * @matrix: a #cairo_matrix_t + * @sx: scale factor in the X direction + * @sy: scale factor in the Y direction + * + * Applies scaling by @sx, @sy to the transformation in @matrix. The + * effect of the new transformation is to first scale the coordinates + * by @sx and @sy, then apply the original transformation to the coordinates. + * + * Since: 1.0 + **/ +void +cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy) +{ + cairo_matrix_t tmp; + + cairo_matrix_init_scale (&tmp, sx, sy); + + cairo_matrix_multiply (matrix, &tmp, matrix); +} +slim_hidden_def(cairo_matrix_scale); + +/** + * cairo_matrix_init_rotate: + * @matrix: a #cairo_matrix_t + * @radians: angle of rotation, in radians. The direction of rotation + * is defined such that positive angles rotate in the direction from + * the positive X axis toward the positive Y axis. With the default + * axis orientation of cairo, positive angles rotate in a clockwise + * direction. + * + * Initialized @matrix to a transformation that rotates by @radians. + * + * Since: 1.0 + **/ +void +cairo_matrix_init_rotate (cairo_matrix_t *matrix, + double radians) +{ + double s; + double c; + + s = sin (radians); + c = cos (radians); + + cairo_matrix_init (matrix, + c, s, + -s, c, + 0, 0); +} +slim_hidden_def(cairo_matrix_init_rotate); + +/** + * cairo_matrix_rotate: + * @matrix: a #cairo_matrix_t + * @radians: angle of rotation, in radians. The direction of rotation + * is defined such that positive angles rotate in the direction from + * the positive X axis toward the positive Y axis. With the default + * axis orientation of cairo, positive angles rotate in a clockwise + * direction. + * + * Applies rotation by @radians to the transformation in + * @matrix. The effect of the new transformation is to first rotate the + * coordinates by @radians, then apply the original transformation + * to the coordinates. + * + * Since: 1.0 + **/ +void +cairo_matrix_rotate (cairo_matrix_t *matrix, double radians) +{ + cairo_matrix_t tmp; + + cairo_matrix_init_rotate (&tmp, radians); + + cairo_matrix_multiply (matrix, &tmp, matrix); +} + +/** + * cairo_matrix_multiply: + * @result: a #cairo_matrix_t in which to store the result + * @a: a #cairo_matrix_t + * @b: a #cairo_matrix_t + * + * Multiplies the affine transformations in @a and @b together + * and stores the result in @result. The effect of the resulting + * transformation is to first apply the transformation in @a to the + * coordinates and then apply the transformation in @b to the + * coordinates. + * + * It is allowable for @result to be identical to either @a or @b. + * + * Since: 1.0 + **/ +/* + * XXX: The ordering of the arguments to this function corresponds + * to [row_vector]*A*B. If we want to use column vectors instead, + * then we need to switch the two arguments and fix up all + * uses. + */ +void +cairo_matrix_multiply (cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b) +{ + cairo_matrix_t r; + + r.xx = a->xx * b->xx + a->yx * b->xy; + r.yx = a->xx * b->yx + a->yx * b->yy; + + r.xy = a->xy * b->xx + a->yy * b->xy; + r.yy = a->xy * b->yx + a->yy * b->yy; + + r.x0 = a->x0 * b->xx + a->y0 * b->xy + b->x0; + r.y0 = a->x0 * b->yx + a->y0 * b->yy + b->y0; + + *result = r; +} +slim_hidden_def(cairo_matrix_multiply); + +void +_cairo_matrix_multiply (cairo_matrix_t *r, + const cairo_matrix_t *a, + const cairo_matrix_t *b) +{ + r->xx = a->xx * b->xx + a->yx * b->xy; + r->yx = a->xx * b->yx + a->yx * b->yy; + + r->xy = a->xy * b->xx + a->yy * b->xy; + r->yy = a->xy * b->yx + a->yy * b->yy; + + r->x0 = a->x0 * b->xx + a->y0 * b->xy + b->x0; + r->y0 = a->x0 * b->yx + a->y0 * b->yy + b->y0; +} + +/** + * cairo_matrix_transform_distance: + * @matrix: a #cairo_matrix_t + * @dx: X component of a distance vector. An in/out parameter + * @dy: Y component of a distance vector. An in/out parameter + * + * Transforms the distance vector (@dx,@dy) by @matrix. This is + * similar to cairo_matrix_transform_point() except that the translation + * components of the transformation are ignored. The calculation of + * the returned vector is as follows: + * + * + * dx2 = dx1 * a + dy1 * c; + * dy2 = dx1 * b + dy1 * d; + * + * + * Affine transformations are position invariant, so the same vector + * always transforms to the same vector. If (@x1,@y1) transforms + * to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to + * (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2. + * + * Since: 1.0 + **/ +void +cairo_matrix_transform_distance (const cairo_matrix_t *matrix, double *dx, double *dy) +{ + double new_x, new_y; + + new_x = (matrix->xx * *dx + matrix->xy * *dy); + new_y = (matrix->yx * *dx + matrix->yy * *dy); + + *dx = new_x; + *dy = new_y; +} +slim_hidden_def(cairo_matrix_transform_distance); + +/** + * cairo_matrix_transform_point: + * @matrix: a #cairo_matrix_t + * @x: X position. An in/out parameter + * @y: Y position. An in/out parameter + * + * Transforms the point (@x, @y) by @matrix. + * + * Since: 1.0 + **/ +void +cairo_matrix_transform_point (const cairo_matrix_t *matrix, double *x, double *y) +{ + cairo_matrix_transform_distance (matrix, x, y); + + *x += matrix->x0; + *y += matrix->y0; +} +slim_hidden_def(cairo_matrix_transform_point); + +void +_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix, + double *x1, double *y1, + double *x2, double *y2, + cairo_bool_t *is_tight) +{ + int i; + double quad_x[4], quad_y[4]; + double min_x, max_x; + double min_y, max_y; + + if (matrix->xy == 0. && matrix->yx == 0.) { + /* non-rotation/skew matrix, just map the two extreme points */ + + if (matrix->xx != 1.) { + quad_x[0] = *x1 * matrix->xx; + quad_x[1] = *x2 * matrix->xx; + if (quad_x[0] < quad_x[1]) { + *x1 = quad_x[0]; + *x2 = quad_x[1]; + } else { + *x1 = quad_x[1]; + *x2 = quad_x[0]; + } + } + if (matrix->x0 != 0.) { + *x1 += matrix->x0; + *x2 += matrix->x0; + } + + if (matrix->yy != 1.) { + quad_y[0] = *y1 * matrix->yy; + quad_y[1] = *y2 * matrix->yy; + if (quad_y[0] < quad_y[1]) { + *y1 = quad_y[0]; + *y2 = quad_y[1]; + } else { + *y1 = quad_y[1]; + *y2 = quad_y[0]; + } + } + if (matrix->y0 != 0.) { + *y1 += matrix->y0; + *y2 += matrix->y0; + } + + if (is_tight) + *is_tight = TRUE; + + return; + } + + /* general matrix */ + quad_x[0] = *x1; + quad_y[0] = *y1; + cairo_matrix_transform_point (matrix, &quad_x[0], &quad_y[0]); + + quad_x[1] = *x2; + quad_y[1] = *y1; + cairo_matrix_transform_point (matrix, &quad_x[1], &quad_y[1]); + + quad_x[2] = *x1; + quad_y[2] = *y2; + cairo_matrix_transform_point (matrix, &quad_x[2], &quad_y[2]); + + quad_x[3] = *x2; + quad_y[3] = *y2; + cairo_matrix_transform_point (matrix, &quad_x[3], &quad_y[3]); + + min_x = max_x = quad_x[0]; + min_y = max_y = quad_y[0]; + + for (i=1; i < 4; i++) { + if (quad_x[i] < min_x) + min_x = quad_x[i]; + if (quad_x[i] > max_x) + max_x = quad_x[i]; + + if (quad_y[i] < min_y) + min_y = quad_y[i]; + if (quad_y[i] > max_y) + max_y = quad_y[i]; + } + + *x1 = min_x; + *y1 = min_y; + *x2 = max_x; + *y2 = max_y; + + if (is_tight) { + /* it's tight if and only if the four corner points form an axis-aligned + rectangle. + And that's true if and only if we can derive corners 0 and 3 from + corners 1 and 2 in one of two straightforward ways... + We could use a tolerance here but for now we'll fall back to FALSE in the case + of floating point error. + */ + *is_tight = + (quad_x[1] == quad_x[0] && quad_y[1] == quad_y[3] && + quad_x[2] == quad_x[3] && quad_y[2] == quad_y[0]) || + (quad_x[1] == quad_x[3] && quad_y[1] == quad_y[0] && + quad_x[2] == quad_x[0] && quad_y[2] == quad_y[3]); + } +} + +cairo_private void +_cairo_matrix_transform_bounding_box_fixed (const cairo_matrix_t *matrix, + cairo_box_t *bbox, + cairo_bool_t *is_tight) +{ + double x1, y1, x2, y2; + + _cairo_box_to_doubles (bbox, &x1, &y1, &x2, &y2); + _cairo_matrix_transform_bounding_box (matrix, &x1, &y1, &x2, &y2, is_tight); + _cairo_box_from_doubles (bbox, &x1, &y1, &x2, &y2); +} + +static void +_cairo_matrix_scalar_multiply (cairo_matrix_t *matrix, double scalar) +{ + matrix->xx *= scalar; + matrix->yx *= scalar; + + matrix->xy *= scalar; + matrix->yy *= scalar; + + matrix->x0 *= scalar; + matrix->y0 *= scalar; +} + +/* This function isn't a correct adjoint in that the implicit 1 in the + homogeneous result should actually be ad-bc instead. But, since this + adjoint is only used in the computation of the inverse, which + divides by det (A)=ad-bc anyway, everything works out in the end. */ +static void +_cairo_matrix_compute_adjoint (cairo_matrix_t *matrix) +{ + /* adj (A) = transpose (C:cofactor (A,i,j)) */ + double a, b, c, d, tx, ty; + + _cairo_matrix_get_affine (matrix, + &a, &b, + &c, &d, + &tx, &ty); + + cairo_matrix_init (matrix, + d, -b, + -c, a, + c*ty - d*tx, b*tx - a*ty); +} + +/** + * cairo_matrix_invert: + * @matrix: a #cairo_matrix_t + * + * Changes @matrix to be the inverse of its original value. Not + * all transformation matrices have inverses; if the matrix + * collapses points together (it is degenerate), + * then it has no inverse and this function will fail. + * + * Returns: If @matrix has an inverse, modifies @matrix to + * be the inverse matrix and returns %CAIRO_STATUS_SUCCESS. Otherwise, + * returns %CAIRO_STATUS_INVALID_MATRIX. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_matrix_invert (cairo_matrix_t *matrix) +{ + double det; + + /* Simple scaling|translation matrices are quite common... */ + if (matrix->xy == 0. && matrix->yx == 0.) { + matrix->x0 = -matrix->x0; + matrix->y0 = -matrix->y0; + + if (matrix->xx != 1.) { + if (matrix->xx == 0.) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + matrix->xx = 1. / matrix->xx; + matrix->x0 *= matrix->xx; + } + + if (matrix->yy != 1.) { + if (matrix->yy == 0.) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + matrix->yy = 1. / matrix->yy; + matrix->y0 *= matrix->yy; + } + + return CAIRO_STATUS_SUCCESS; + } + + /* inv (A) = 1/det (A) * adj (A) */ + det = _cairo_matrix_compute_determinant (matrix); + + if (! ISFINITE (det)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + if (det == 0) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + _cairo_matrix_compute_adjoint (matrix); + _cairo_matrix_scalar_multiply (matrix, 1 / det); + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def(cairo_matrix_invert); + +cairo_bool_t +_cairo_matrix_is_invertible (const cairo_matrix_t *matrix) +{ + double det; + + det = _cairo_matrix_compute_determinant (matrix); + + return ISFINITE (det) && det != 0.; +} + +cairo_bool_t +_cairo_matrix_is_scale_0 (const cairo_matrix_t *matrix) +{ + return matrix->xx == 0. && + matrix->xy == 0. && + matrix->yx == 0. && + matrix->yy == 0.; +} + +double +_cairo_matrix_compute_determinant (const cairo_matrix_t *matrix) +{ + double a, b, c, d; + + a = matrix->xx; b = matrix->yx; + c = matrix->xy; d = matrix->yy; + + return a*d - b*c; +} + +/** + * _cairo_matrix_compute_basis_scale_factors: + * @matrix: a matrix + * @basis_scale: the scale factor in the direction of basis + * @normal_scale: the scale factor in the direction normal to the basis + * @x_basis: basis to use. X basis if true, Y basis otherwise. + * + * Computes |Mv| and det(M)/|Mv| for v=[1,0] if x_basis is true, and v=[0,1] + * otherwise, and M is @matrix. + * + * Return value: the scale factor of @matrix on the height of the font, + * or 1.0 if @matrix is %NULL. + **/ +cairo_status_t +_cairo_matrix_compute_basis_scale_factors (const cairo_matrix_t *matrix, + double *basis_scale, double *normal_scale, + cairo_bool_t x_basis) +{ + double det; + + det = _cairo_matrix_compute_determinant (matrix); + + if (! ISFINITE (det)) + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + + if (det == 0) + { + *basis_scale = *normal_scale = 0; + } + else + { + double x = x_basis != 0; + double y = x == 0; + double major, minor; + + cairo_matrix_transform_distance (matrix, &x, &y); + major = hypot (x, y); + /* + * ignore mirroring + */ + if (det < 0) + det = -det; + if (major) + minor = det / major; + else + minor = 0.0; + if (x_basis) + { + *basis_scale = major; + *normal_scale = minor; + } + else + { + *basis_scale = minor; + *normal_scale = major; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_bool_t +_cairo_matrix_is_integer_translation (const cairo_matrix_t *matrix, + int *itx, int *ity) +{ + if (_cairo_matrix_is_translation (matrix)) + { + cairo_fixed_t x0_fixed = _cairo_fixed_from_double (matrix->x0); + cairo_fixed_t y0_fixed = _cairo_fixed_from_double (matrix->y0); + + if (_cairo_fixed_is_integer (x0_fixed) && + _cairo_fixed_is_integer (y0_fixed)) + { + if (itx) + *itx = _cairo_fixed_integer_part (x0_fixed); + if (ity) + *ity = _cairo_fixed_integer_part (y0_fixed); + + return TRUE; + } + } + + return FALSE; +} + +#define SCALING_EPSILON _cairo_fixed_to_double(1) + +/* This only returns true if the matrix is 90 degree rotations or + * flips. It appears calling code is relying on this. It will return + * false for other rotations even if the scale is one. Approximations + * are allowed to handle matricies filled in using trig functions + * such as sin(M_PI_2). + */ +cairo_bool_t +_cairo_matrix_has_unity_scale (const cairo_matrix_t *matrix) +{ + /* check that the determinant is near +/-1 */ + double det = _cairo_matrix_compute_determinant (matrix); + if (fabs (det * det - 1.0) < SCALING_EPSILON) { + /* check that one axis is close to zero */ + if (fabs (matrix->xy) < SCALING_EPSILON && + fabs (matrix->yx) < SCALING_EPSILON) + return TRUE; + if (fabs (matrix->xx) < SCALING_EPSILON && + fabs (matrix->yy) < SCALING_EPSILON) + return TRUE; + /* If rotations are allowed then it must instead test for + * orthogonality. This is xx*xy+yx*yy ~= 0. + */ + } + return FALSE; +} + +/* By pixel exact here, we mean a matrix that is composed only of + * 90 degree rotations, flips, and integer translations and produces a 1:1 + * mapping between source and destination pixels. If we transform an image + * with a pixel-exact matrix, filtering is not useful. + */ +cairo_bool_t +_cairo_matrix_is_pixel_exact (const cairo_matrix_t *matrix) +{ + cairo_fixed_t x0_fixed, y0_fixed; + + if (! _cairo_matrix_has_unity_scale (matrix)) + return FALSE; + + x0_fixed = _cairo_fixed_from_double (matrix->x0); + y0_fixed = _cairo_fixed_from_double (matrix->y0); + + return _cairo_fixed_is_integer (x0_fixed) && _cairo_fixed_is_integer (y0_fixed); +} + +/* + A circle in user space is transformed into an ellipse in device space. + + The following is a derivation of a formula to calculate the length of the + major axis for this ellipse; this is useful for error bounds calculations. + + Thanks to Walter Brisken for this derivation: + + 1. First some notation: + + All capital letters represent vectors in two dimensions. A prime ' + represents a transformed coordinate. Matrices are written in underlined + form, ie _R_. Lowercase letters represent scalar real values. + + 2. The question has been posed: What is the maximum expansion factor + achieved by the linear transformation + + X' = X _R_ + + where _R_ is a real-valued 2x2 matrix with entries: + + _R_ = [a b] + [c d] . + + In other words, what is the maximum radius, MAX[ |X'| ], reached for any + X on the unit circle ( |X| = 1 ) ? + + 3. Some useful formulae + + (A) through (C) below are standard double-angle formulae. (D) is a lesser + known result and is derived below: + + (A) sin²(θ) = (1 - cos(2*θ))/2 + (B) cos²(θ) = (1 + cos(2*θ))/2 + (C) sin(θ)*cos(θ) = sin(2*θ)/2 + (D) MAX[a*cos(θ) + b*sin(θ)] = sqrt(a² + b²) + + Proof of (D): + + find the maximum of the function by setting the derivative to zero: + + -a*sin(θ)+b*cos(θ) = 0 + + From this it follows that + + tan(θ) = b/a + + and hence + + sin(θ) = b/sqrt(a² + b²) + + and + + cos(θ) = a/sqrt(a² + b²) + + Thus the maximum value is + + MAX[a*cos(θ) + b*sin(θ)] = (a² + b²)/sqrt(a² + b²) + = sqrt(a² + b²) + + 4. Derivation of maximum expansion + + To find MAX[ |X'| ] we search brute force method using calculus. The unit + circle on which X is constrained is to be parameterized by t: + + X(θ) = (cos(θ), sin(θ)) + + Thus + + X'(θ) = X(θ) * _R_ = (cos(θ), sin(θ)) * [a b] + [c d] + = (a*cos(θ) + c*sin(θ), b*cos(θ) + d*sin(θ)). + + Define + + r(θ) = |X'(θ)| + + Thus + + r²(θ) = (a*cos(θ) + c*sin(θ))² + (b*cos(θ) + d*sin(θ))² + = (a² + b²)*cos²(θ) + (c² + d²)*sin²(θ) + + 2*(a*c + b*d)*cos(θ)*sin(θ) + + Now apply the double angle formulae (A) to (C) from above: + + r²(θ) = (a² + b² + c² + d²)/2 + + (a² + b² - c² - d²)*cos(2*θ)/2 + + (a*c + b*d)*sin(2*θ) + = f + g*cos(φ) + h*sin(φ) + + Where + + f = (a² + b² + c² + d²)/2 + g = (a² + b² - c² - d²)/2 + h = (a*c + d*d) + φ = 2*θ + + It is clear that MAX[ |X'| ] = sqrt(MAX[ r² ]). Here we determine MAX[ r² ] + using (D) from above: + + MAX[ r² ] = f + sqrt(g² + h²) + + And finally + + MAX[ |X'| ] = sqrt( f + sqrt(g² + h²) ) + + Which is the solution to this problem. + + Walter Brisken + 2004/10/08 + + (Note that the minor axis length is at the minimum of the above solution, + which is just sqrt ( f - sqrt(g² + h²) ) given the symmetry of (D)). + + + For another derivation of the same result, using Singular Value Decomposition, + see doc/tutorial/src/singular.c. +*/ + +/* determine the length of the major axis of a circle of the given radius + after applying the transformation matrix. */ +double +_cairo_matrix_transformed_circle_major_axis (const cairo_matrix_t *matrix, + double radius) +{ + double a, b, c, d, f, g, h, i, j; + + if (_cairo_matrix_has_unity_scale (matrix)) + return radius; + + _cairo_matrix_get_affine (matrix, + &a, &b, + &c, &d, + NULL, NULL); + + i = a*a + b*b; + j = c*c + d*d; + + f = 0.5 * (i + j); + g = 0.5 * (i - j); + h = a*c + b*d; + + return radius * sqrt (f + hypot (g, h)); + + /* + * we don't need the minor axis length, which is + * double min = radius * sqrt (f - sqrt (g*g+h*h)); + */ +} + +static const pixman_transform_t pixman_identity_transform = {{ + {1 << 16, 0, 0}, + { 0, 1 << 16, 0}, + { 0, 0, 1 << 16} + }}; + +static cairo_status_t +_cairo_matrix_to_pixman_matrix (const cairo_matrix_t *matrix, + pixman_transform_t *pixman_transform, + double xc, + double yc) +{ + cairo_matrix_t inv; + unsigned max_iterations; + + pixman_transform->matrix[0][0] = _cairo_fixed_16_16_from_double (matrix->xx); + pixman_transform->matrix[0][1] = _cairo_fixed_16_16_from_double (matrix->xy); + pixman_transform->matrix[0][2] = _cairo_fixed_16_16_from_double (matrix->x0); + + pixman_transform->matrix[1][0] = _cairo_fixed_16_16_from_double (matrix->yx); + pixman_transform->matrix[1][1] = _cairo_fixed_16_16_from_double (matrix->yy); + pixman_transform->matrix[1][2] = _cairo_fixed_16_16_from_double (matrix->y0); + + pixman_transform->matrix[2][0] = 0; + pixman_transform->matrix[2][1] = 0; + pixman_transform->matrix[2][2] = 1 << 16; + + /* The conversion above breaks cairo's translation invariance: + * a translation of (a, b) in device space translates to + * a translation of (xx * a + xy * b, yx * a + yy * b) + * for cairo, while pixman uses rounded versions of xx ... yy. + * This error increases as a and b get larger. + * + * To compensate for this, we fix the point (xc, yc) in pattern + * space and adjust pixman's transform to agree with cairo's at + * that point. + */ + + if (_cairo_matrix_has_unity_scale (matrix)) + return CAIRO_STATUS_SUCCESS; + + if (unlikely (fabs (matrix->xx) > PIXMAN_MAX_INT || + fabs (matrix->xy) > PIXMAN_MAX_INT || + fabs (matrix->x0) > PIXMAN_MAX_INT || + fabs (matrix->yx) > PIXMAN_MAX_INT || + fabs (matrix->yy) > PIXMAN_MAX_INT || + fabs (matrix->y0) > PIXMAN_MAX_INT)) + { + return _cairo_error (CAIRO_STATUS_INVALID_MATRIX); + } + + /* Note: If we can't invert the transformation, skip the adjustment. */ + inv = *matrix; + if (cairo_matrix_invert (&inv) != CAIRO_STATUS_SUCCESS) + return CAIRO_STATUS_SUCCESS; + + /* find the pattern space coordinate that maps to (xc, yc) */ + max_iterations = 5; + do { + double x,y; + pixman_vector_t vector; + cairo_fixed_16_16_t dx, dy; + + vector.vector[0] = _cairo_fixed_16_16_from_double (xc); + vector.vector[1] = _cairo_fixed_16_16_from_double (yc); + vector.vector[2] = 1 << 16; + + /* If we can't transform the reference point, skip the adjustment. */ + if (! pixman_transform_point_3d (pixman_transform, &vector)) + return CAIRO_STATUS_SUCCESS; + + x = pixman_fixed_to_double (vector.vector[0]); + y = pixman_fixed_to_double (vector.vector[1]); + cairo_matrix_transform_point (&inv, &x, &y); + + /* Ideally, the vector should now be (xc, yc). + * We can now compensate for the resulting error. + */ + x -= xc; + y -= yc; + cairo_matrix_transform_distance (matrix, &x, &y); + dx = _cairo_fixed_16_16_from_double (x); + dy = _cairo_fixed_16_16_from_double (y); + pixman_transform->matrix[0][2] -= dx; + pixman_transform->matrix[1][2] -= dy; + + if (dx == 0 && dy == 0) + return CAIRO_STATUS_SUCCESS; + } while (--max_iterations); + + /* We didn't find an exact match between cairo and pixman, but + * the matrix should be mostly correct */ + return CAIRO_STATUS_SUCCESS; +} + +static inline double +_pixman_nearest_sample (double d) +{ + return ceil (d - .5); +} + +/** + * _cairo_matrix_is_pixman_translation: + * @matrix: a matrix + * @filter: the filter to be used on the pattern transformed by @matrix + * @x_offset: the translation in the X direction + * @y_offset: the translation in the Y direction + * + * Checks if @matrix translated by (x_offset, y_offset) can be + * represented using just an offset (within the range pixman can + * accept) and an identity matrix. + * + * Passing a non-zero value in x_offset/y_offset has the same effect + * as applying cairo_matrix_translate(matrix, x_offset, y_offset) and + * setting x_offset and y_offset to 0. + * + * Upon return x_offset and y_offset contain the translation vector if + * the return value is %TRUE. If the return value is %FALSE, they will + * not be modified. + * + * Return value: %TRUE if @matrix can be represented as a pixman + * translation, %FALSE otherwise. + **/ +cairo_bool_t +_cairo_matrix_is_pixman_translation (const cairo_matrix_t *matrix, + cairo_filter_t filter, + int *x_offset, + int *y_offset) +{ + double tx, ty; + + if (!_cairo_matrix_is_translation (matrix)) + return FALSE; + + if (matrix->x0 == 0. && matrix->y0 == 0.) + return TRUE; + + tx = matrix->x0 + *x_offset; + ty = matrix->y0 + *y_offset; + + if (filter == CAIRO_FILTER_FAST || filter == CAIRO_FILTER_NEAREST) { + tx = _pixman_nearest_sample (tx); + ty = _pixman_nearest_sample (ty); + } else if (tx != floor (tx) || ty != floor (ty)) { + return FALSE; + } + + if (fabs (tx) > PIXMAN_MAX_INT || fabs (ty) > PIXMAN_MAX_INT) + return FALSE; + + *x_offset = _cairo_lround (tx); + *y_offset = _cairo_lround (ty); + return TRUE; +} + +/** + * _cairo_matrix_to_pixman_matrix_offset: + * @matrix: a matrix + * @filter: the filter to be used on the pattern transformed by @matrix + * @xc: the X coordinate of the point to fix in pattern space + * @yc: the Y coordinate of the point to fix in pattern space + * @out_transform: the transformation which best approximates @matrix + * @x_offset: the translation in the X direction + * @y_offset: the translation in the Y direction + * + * This function tries to represent @matrix translated by (x_offset, + * y_offset) as a %pixman_transform_t and an translation. + * + * Passing a non-zero value in x_offset/y_offset has the same effect + * as applying cairo_matrix_translate(matrix, x_offset, y_offset) and + * setting x_offset and y_offset to 0. + * + * If it is possible to represent the matrix with an identity + * %pixman_transform_t and a translation within the valid range for + * pixman, this function will set @out_transform to be the identity, + * @x_offset and @y_offset to be the translation vector and will + * return %CAIRO_INT_STATUS_NOTHING_TO_DO. Otherwise it will try to + * evenly divide the translational component of @matrix between + * @out_transform and (@x_offset, @y_offset). + * + * Upon return x_offset and y_offset contain the translation vector. + * + * Return value: %CAIRO_INT_STATUS_NOTHING_TO_DO if the out_transform + * is the identity, %CAIRO_STATUS_INVALID_MATRIX if it was not + * possible to represent @matrix as a pixman_transform_t without + * overflows, %CAIRO_STATUS_SUCCESS otherwise. + **/ +cairo_status_t +_cairo_matrix_to_pixman_matrix_offset (const cairo_matrix_t *matrix, + cairo_filter_t filter, + double xc, + double yc, + pixman_transform_t *out_transform, + int *x_offset, + int *y_offset) +{ + cairo_bool_t is_pixman_translation; + + is_pixman_translation = _cairo_matrix_is_pixman_translation (matrix, + filter, + x_offset, + y_offset); + + if (is_pixman_translation) { + *out_transform = pixman_identity_transform; + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } else { + cairo_matrix_t m; + + m = *matrix; + cairo_matrix_translate (&m, *x_offset, *y_offset); + if (m.x0 != 0.0 || m.y0 != 0.0) { + double tx, ty, norm; + int i, j; + + /* pixman also limits the [xy]_offset to 16 bits so evenly + * spread the bits between the two. + * + * To do this, find the solutions of: + * |x| = |x*m.xx + y*m.xy + m.x0| + * |y| = |x*m.yx + y*m.yy + m.y0| + * + * and select the one whose maximum norm is smallest. + */ + tx = m.x0; + ty = m.y0; + norm = MAX (fabs (tx), fabs (ty)); + + for (i = -1; i < 2; i+=2) { + for (j = -1; j < 2; j+=2) { + double x, y, den, new_norm; + + den = (m.xx + i) * (m.yy + j) - m.xy * m.yx; + if (fabs (den) < DBL_EPSILON) + continue; + + x = m.y0 * m.xy - m.x0 * (m.yy + j); + y = m.x0 * m.yx - m.y0 * (m.xx + i); + + den = 1 / den; + x *= den; + y *= den; + + new_norm = MAX (fabs (x), fabs (y)); + if (norm > new_norm) { + norm = new_norm; + tx = x; + ty = y; + } + } + } + + tx = floor (tx); + ty = floor (ty); + *x_offset = -tx; + *y_offset = -ty; + cairo_matrix_translate (&m, tx, ty); + } else { + *x_offset = 0; + *y_offset = 0; + } + + return _cairo_matrix_to_pixman_matrix (&m, out_transform, xc, yc); + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mempool-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-mempool-private.h new file mode 100644 index 00000000000..a09f6ce51f6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mempool-private.h @@ -0,0 +1,85 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributors(s): + * Chris Wilson + */ + +#ifndef CAIRO_MEMPOOL_PRIVATE_H +#define CAIRO_MEMPOOL_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" + +#include /* for size_t */ + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_mempool cairo_mempool_t; + +struct _cairo_mempool { + char *base; + struct _cairo_memblock { + int bits; + cairo_list_t link; + } *blocks; + cairo_list_t free[32]; + unsigned char *map; + + unsigned int num_blocks; + int min_bits; /* Minimum block size is 1 << min_bits */ + int num_sizes; + int max_free_bits; + + size_t free_bytes; + size_t max_bytes; +}; + +cairo_private cairo_status_t +_cairo_mempool_init (cairo_mempool_t *pool, + void *base, + size_t bytes, + int min_bits, + int num_sizes); + +cairo_private void * +_cairo_mempool_alloc (cairo_mempool_t *pi, size_t bytes); + +cairo_private void +_cairo_mempool_free (cairo_mempool_t *pi, void *storage); + +cairo_private void +_cairo_mempool_fini (cairo_mempool_t *pool); + +CAIRO_END_DECLS + +#endif /* CAIRO_MEMPOOL_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mempool.c b/Build/source/libs/cairo/cairo-src/src/cairo-mempool.c new file mode 100644 index 00000000000..751ede320f3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mempool.c @@ -0,0 +1,369 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipoolent may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributors(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-mempool-private.h" +#include "cairo-list-inline.h" + +/* a simple buddy allocator for memory pools + * XXX fragmentation? use Doug Lea's malloc? + */ + +#define BITTEST(p, n) ((p)->map[(n) >> 3] & (128 >> ((n) & 7))) +#define BITSET(p, n) ((p)->map[(n) >> 3] |= (128 >> ((n) & 7))) +#define BITCLEAR(p, n) ((p)->map[(n) >> 3] &= ~(128 >> ((n) & 7))) + +static void +clear_bits (cairo_mempool_t *pool, size_t first, size_t last) +{ + size_t i, n = last; + size_t first_full = (first + 7) & ~7; + size_t past_full = last & ~7; + size_t bytes; + + if (n > first_full) + n = first_full; + for (i = first; i < n; i++) + BITCLEAR (pool, i); + + if (past_full > first_full) { + bytes = past_full - first_full; + bytes = bytes >> 3; + memset (pool->map + (first_full >> 3), 0, bytes); + } + + if (past_full < n) + past_full = n; + for (i = past_full; i < last; i++) + BITCLEAR (pool, i); +} + +static void +free_bits (cairo_mempool_t *pool, size_t start, int bits, cairo_bool_t clear) +{ + struct _cairo_memblock *block; + + if (clear) + clear_bits (pool, start, start + (1 << bits)); + + block = pool->blocks + start; + block->bits = bits; + + cairo_list_add (&block->link, &pool->free[bits]); + + pool->free_bytes += 1 << (bits + pool->min_bits); + if (bits > pool->max_free_bits) + pool->max_free_bits = bits; +} + +/* Add a chunk to the free list */ +static void +free_blocks (cairo_mempool_t *pool, + size_t first, + size_t last, + cairo_bool_t clear) +{ + size_t i, len; + int bits = 0; + + for (i = first, len = 1; i < last; i += len) { + /* To avoid cost quadratic in the number of different + * blocks produced from this chunk of store, we have to + * use the size of the previous block produced from this + * chunk as the starting point to work out the size of the + * next block we can produce. If you look at the binary + * representation of the starting points of the blocks + * produced, you can see that you first of all increase the + * size of the blocks produced up to some maximum as the + * address dealt with gets offsets added on which zap out + * low order bits, then decrease as the low order bits of the + * final block produced get added in. E.g. as you go from + * 001 to 0111 you generate blocks + * of size 001 at 001 taking you to 010 + * of size 010 at 010 taking you to 100 + * of size 010 at 100 taking you to 110 + * of size 001 at 110 taking you to 111 + * So the maximum total cost of the loops below this comment + * is one trip from the lowest blocksize to the highest and + * back again. + */ + while (bits < pool->num_sizes - 1) { + size_t next_bits = bits + 1; + size_t next_len = len << 1; + + if (i + next_bits > last) { + /* off end of chunk to be freed */ + break; + } + + if (i & (next_len - 1)) /* block would not be on boundary */ + break; + + bits = next_bits; + len = next_len; + } + + do { + if (i + len <= last && /* off end of chunk to be freed */ + (i & (len - 1)) == 0) /* block would not be on boundary */ + break; + + bits--; len >>=1; + } while (len); + + if (len == 0) + break; + + free_bits (pool, i, bits, clear); + } +} + +static struct _cairo_memblock * +get_buddy (cairo_mempool_t *pool, size_t offset, int bits) +{ + struct _cairo_memblock *block; + + if (offset + (1 << bits) >= pool->num_blocks) + return NULL; /* invalid */ + + if (BITTEST (pool, offset + (1 << bits) - 1)) + return NULL; /* buddy is allocated */ + + block = pool->blocks + offset; + if (block->bits != bits) + return NULL; /* buddy is partially allocated */ + + return block; +} + +static void +merge_buddies (cairo_mempool_t *pool, + struct _cairo_memblock *block, + int max_bits) +{ + size_t block_offset = block - pool->blocks; + int bits = block->bits; + + while (bits < max_bits - 1) { + /* while you can, merge two blocks and get a legal block size */ + size_t buddy_offset = block_offset ^ (1 << bits); + + block = get_buddy (pool, buddy_offset, bits); + if (block == NULL) + break; + + cairo_list_del (&block->link); + + /* Merged block starts at buddy */ + if (buddy_offset < block_offset) + block_offset = buddy_offset; + + bits++; + } + + block = pool->blocks + block_offset; + block->bits = bits; + cairo_list_add (&block->link, &pool->free[bits]); + + if (bits > pool->max_free_bits) + pool->max_free_bits = bits; +} + +/* attempt to merge all available buddies up to a particular size */ +static int +merge_bits (cairo_mempool_t *pool, int max_bits) +{ + struct _cairo_memblock *block, *buddy, *next; + int bits; + + for (bits = 0; bits < max_bits - 1; bits++) { + cairo_list_foreach_entry_safe (block, next, + struct _cairo_memblock, + &pool->free[bits], + link) + { + size_t buddy_offset = (block - pool->blocks) ^ (1 << bits); + + buddy = get_buddy (pool, buddy_offset, bits); + if (buddy == NULL) + continue; + + if (buddy == next) { + next = cairo_container_of (buddy->link.next, + struct _cairo_memblock, + link); + } + + cairo_list_del (&block->link); + merge_buddies (pool, block, max_bits); + } + } + + return pool->max_free_bits; +} + +/* find store for 1 << bits blocks */ +static void * +buddy_malloc (cairo_mempool_t *pool, int bits) +{ + size_t past, offset; + struct _cairo_memblock *block; + int b; + + if (bits > pool->max_free_bits && bits > merge_bits (pool, bits)) + return NULL; + + /* Find a list with blocks big enough on it */ + block = NULL; + for (b = bits; b <= pool->max_free_bits; b++) { + if (! cairo_list_is_empty (&pool->free[b])) { + block = cairo_list_first_entry (&pool->free[b], + struct _cairo_memblock, + link); + break; + } + } + assert (block != NULL); + + cairo_list_del (&block->link); + + while (cairo_list_is_empty (&pool->free[pool->max_free_bits])) { + if (--pool->max_free_bits == -1) + break; + } + + /* Mark end of allocated area */ + offset = block - pool->blocks; + past = offset + (1 << bits); + BITSET (pool, past - 1); + block->bits = bits; + + /* If we used a larger free block than we needed, free the rest */ + pool->free_bytes -= 1 << (b + pool->min_bits); + free_blocks (pool, past, offset + (1 << b), 0); + + return pool->base + ((block - pool->blocks) << pool->min_bits); +} + +cairo_status_t +_cairo_mempool_init (cairo_mempool_t *pool, + void *base, size_t bytes, + int min_bits, int num_sizes) +{ + unsigned long tmp; + int num_blocks; + int i; + + /* Align the start to an integral chunk */ + tmp = ((unsigned long) base) & ((1 << min_bits) - 1); + if (tmp) { + tmp = (1 << min_bits) - tmp; + base = (char *)base + tmp; + bytes -= tmp; + } + + assert ((((unsigned long) base) & ((1 << min_bits) - 1)) == 0); + assert (num_sizes < ARRAY_LENGTH (pool->free)); + + pool->base = base; + pool->free_bytes = 0; + pool->max_bytes = bytes; + pool->max_free_bits = -1; + + num_blocks = bytes >> min_bits; + pool->blocks = calloc (num_blocks, sizeof (struct _cairo_memblock)); + if (pool->blocks == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + pool->num_blocks = num_blocks; + pool->min_bits = min_bits; + pool->num_sizes = num_sizes; + + for (i = 0; i < ARRAY_LENGTH (pool->free); i++) + cairo_list_init (&pool->free[i]); + + pool->map = malloc ((num_blocks + 7) >> 3); + if (pool->map == NULL) { + free (pool->blocks); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + memset (pool->map, -1, (num_blocks + 7) >> 3); + clear_bits (pool, 0, num_blocks); + + /* Now add all blocks to the free list */ + free_blocks (pool, 0, num_blocks, 1); + + return CAIRO_STATUS_SUCCESS; +} + +void * +_cairo_mempool_alloc (cairo_mempool_t *pool, size_t bytes) +{ + size_t size; + int bits; + + size = 1 << pool->min_bits; + for (bits = 0; size < bytes; bits++) + size <<= 1; + if (bits >= pool->num_sizes) + return NULL; + + return buddy_malloc (pool, bits); +} + +void +_cairo_mempool_free (cairo_mempool_t *pool, void *storage) +{ + size_t block_offset; + struct _cairo_memblock *block; + + block_offset = ((char *)storage - pool->base) >> pool->min_bits; + block = pool->blocks + block_offset; + + BITCLEAR (pool, block_offset + ((1 << block->bits) - 1)); + pool->free_bytes += 1 << (block->bits + pool->min_bits); + + merge_buddies (pool, block, pool->num_sizes); +} + +void +_cairo_mempool_fini (cairo_mempool_t *pool) +{ + free (pool->map); + free (pool->blocks); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mesh-pattern-rasterizer.c b/Build/source/libs/cairo/cairo-src/src/cairo-mesh-pattern-rasterizer.c new file mode 100644 index 00000000000..1b63ca8a660 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mesh-pattern-rasterizer.c @@ -0,0 +1,941 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright 2009 Andrea Canciani + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Andrea Canciani. + * + * Contributor(s): + * Andrea Canciani + */ + +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-pattern-private.h" + +/* + * Rasterizer for mesh patterns. + * + * This implementation is based on techniques derived from several + * papers (available from ACM): + * + * - Lien, Shantz and Pratt "Adaptive Forward Differencing for + * Rendering Curves and Surfaces" (discussion of the AFD technique, + * bound of 1/sqrt(2) on step length without proof) + * + * - Popescu and Rosen, "Forward rasterization" (description of + * forward rasterization, proof of the previous bound) + * + * - Klassen, "Integer Forward Differencing of Cubic Polynomials: + * Analysis and Algorithms" + * + * - Klassen, "Exact Integer Hybrid Subdivision and Forward + * Differencing of Cubics" (improving the bound on the minimum + * number of steps) + * + * - Chang, Shantz and Rocchetti, "Rendering Cubic Curves and Surfaces + * with Integer Adaptive Forward Differencing" (analysis of forward + * differencing applied to Bezier patches) + * + * Notes: + * - Poor performance expected in degenerate cases + * + * - Patches mostly outside the drawing area are drawn completely (and + * clipped), wasting time + * + * - Both previous problems are greatly reduced by splitting until a + * reasonably small size and clipping the new tiles: execution time + * is quadratic in the convex-hull diameter instead than linear to + * the painted area. Splitting the tiles doesn't change the painted + * area but (usually) reduces the bounding box area (bbox area can + * remain the same after splitting, but cannot grow) + * + * - The initial implementation used adaptive forward differencing, + * but simple forward differencing scored better in benchmarks + * + * Idea: + * + * We do a sampling over the cubic patch with step du and dv (in the + * two parameters) that guarantees that any point of our sampling will + * be at most at 1/sqrt(2) from its adjacent points. In formulae + * (assuming B is the patch): + * + * |B(u,v) - B(u+du,v)| < 1/sqrt(2) + * |B(u,v) - B(u,v+dv)| < 1/sqrt(2) + * + * This means that every pixel covered by the patch will contain at + * least one of the samples, thus forward rasterization can be + * performed. Sketch of proof (from Popescu and Rosen): + * + * Let's take the P pixel we're interested into. If we assume it to be + * square, its boundaries define 9 regions on the plane: + * + * 1|2|3 + * -+-+- + * 8|P|4 + * -+-+- + * 7|6|5 + * + * Let's check that the pixel P will contain at least one point + * assuming that it is covered by the patch. + * + * Since the pixel is covered by the patch, its center will belong to + * (at least) one of the quads: + * + * {(B(u,v), B(u+du,v), B(u,v+dv), B(u+du,v+dv)) for u,v in [0,1]} + * + * If P doesn't contain any of the corners of the quad: + * + * - if one of the corners is in 1,3,5 or 7, other two of them have to + * be in 2,4,6 or 8, thus if the last corner is not in P, the length + * of one of the edges will be > 1/sqrt(2) + * + * - if none of the corners is in 1,3,5 or 7, all of them are in 2,4,6 + * and/or 8. If they are all in different regions, they can't + * satisfy the distance constraint. If two of them are in the same + * region (let's say 2), no point is in 6 and again it is impossible + * to have the center of P in the quad respecting the distance + * constraint (both these assertions can be checked by continuity + * considering the length of the edges of a quad with the vertices + * on the edges of P) + * + * Each of the cases led to a contradiction, so P contains at least + * one of the corners of the quad. + */ + +/* + * Make sure that errors are less than 1 in fixed point math if you + * change these values. + * + * The error is amplified by about steps^3/4 times. + * The rasterizer always uses a number of steps that is a power of 2. + * + * 256 is the maximum allowed number of steps (to have error < 1) + * using 8.24 for the differences. + */ +#define STEPS_MAX_V 256.0 +#define STEPS_MAX_U 256.0 + +/* + * If the patch/curve is only partially visible, split it to a finer + * resolution to get higher chances to clip (part of) it. + * + * These values have not been computed, but simply obtained + * empirically (by benchmarking some patches). They should never be + * greater than STEPS_MAX_V (or STEPS_MAX_U), but they can be as small + * as 1 (depending on how much you want to spend time in splitting the + * patch/curve when trying to save some rasterization time). + */ +#define STEPS_CLIP_V 64.0 +#define STEPS_CLIP_U 64.0 + + +/* Utils */ +static inline double +sqlen (cairo_point_double_t p0, cairo_point_double_t p1) +{ + cairo_point_double_t delta; + + delta.x = p0.x - p1.x; + delta.y = p0.y - p1.y; + + return delta.x * delta.x + delta.y * delta.y; +} + +static inline int16_t +_color_delta_to_shifted_short (int32_t from, int32_t to, int shift) +{ + int32_t delta = to - from; + + /* We need to round toward zero, because otherwise adding the + * delta 2^shift times can overflow */ + if (delta >= 0) + return delta >> shift; + else + return -((-delta) >> shift); +} + +/* + * Convert a number of steps to the equivalent shift. + * + * Input: the square of the minimum number of steps + * + * Output: the smallest integer x such that 2^x > steps + */ +static inline int +sqsteps2shift (double steps_sq) +{ + int r; + frexp (MAX (1.0, steps_sq), &r); + return (r + 1) >> 1; +} + +/* + * FD functions + * + * A Bezier curve is defined (with respect to a parameter t in + * [0,1]) from its nodes (x,y,z,w) like this: + * + * B(t) = x(1-t)^3 + 3yt(1-t)^2 + 3zt^2(1-t) + wt^3 + * + * To efficiently evaluate a Bezier curve, the rasterizer uses forward + * differences. Given x, y, z, w (the 4 nodes of the Bezier curve), it + * is possible to convert them to forward differences form and walk + * over the curve using fd_init (), fd_down () and fd_fwd (). + * + * f[0] is always the value of the Bezier curve for "current" t. + */ + +/* + * Initialize the coefficient for forward differences. + * + * Input: x,y,z,w are the 4 nodes of the Bezier curve + * + * Output: f[i] is the i-th difference of the curve + * + * f[0] is the value of the curve for t==0, i.e. f[0]==x. + * + * The initial step is 1; this means that each step increases t by 1 + * (so fd_init () immediately followed by fd_fwd (f) n times makes + * f[0] be the value of the curve for t==n). + */ +static inline void +fd_init (double x, double y, double z, double w, double f[4]) +{ + f[0] = x; + f[1] = w - x; + f[2] = 6. * (w - 2. * z + y); + f[3] = 6. * (w - 3. * z + 3. * y - x); +} + +/* + * Halve the step of the coefficients for forward differences. + * + * Input: f[i] is the i-th difference of the curve + * + * Output: f[i] is the i-th difference of the curve with half the + * original step + * + * f[0] is not affected, so the current t is not changed. + * + * The other coefficients are changed so that the step is half the + * original step. This means that doing fd_fwd (f) n times with the + * input f results in the same f[0] as doing fd_fwd (f) 2n times with + * the output f. + */ +static inline void +fd_down (double f[4]) +{ + f[3] *= 0.125; + f[2] = f[2] * 0.25 - f[3]; + f[1] = (f[1] - f[2]) * 0.5; +} + +/* + * Perform one step of forward differences along the curve. + * + * Input: f[i] is the i-th difference of the curve + * + * Output: f[i] is the i-th difference of the curve after one step + */ +static inline void +fd_fwd (double f[4]) +{ + f[0] += f[1]; + f[1] += f[2]; + f[2] += f[3]; +} + +/* + * Transform to integer forward differences. + * + * Input: d[n] is the n-th difference (in double precision) + * + * Output: i[n] is the n-th difference (in fixed point precision) + * + * i[0] is 9.23 fixed point, other differences are 4.28 fixed point. + */ +static inline void +fd_fixed (double d[4], int32_t i[4]) +{ + i[0] = _cairo_fixed_16_16_from_double (256 * 2 * d[0]); + i[1] = _cairo_fixed_16_16_from_double (256 * 16 * d[1]); + i[2] = _cairo_fixed_16_16_from_double (256 * 16 * d[2]); + i[3] = _cairo_fixed_16_16_from_double (256 * 16 * d[3]); +} + +/* + * Perform one step of integer forward differences along the curve. + * + * Input: f[n] is the n-th difference + * + * Output: f[n] is the n-th difference + * + * f[0] is 9.23 fixed point, other differences are 4.28 fixed point. + */ +static inline void +fd_fixed_fwd (int32_t f[4]) +{ + f[0] += (f[1] >> 5) + ((f[1] >> 4) & 1); + f[1] += f[2]; + f[2] += f[3]; +} + +/* + * Compute the minimum number of steps that guarantee that walking + * over a curve will leave no holes. + * + * Input: p[0..3] the nodes of the Bezier curve + * + * Returns: the square of the number of steps + * + * Idea: + * + * We want to make sure that at every step we move by less than + * 1/sqrt(2). + * + * The derivative of the cubic Bezier with nodes (p0, p1, p2, p3) is + * the quadratic Bezier with nodes (p1-p0, p2-p1, p3-p2) scaled by 3, + * so (since a Bezier curve is always bounded by its convex hull), we + * can say that: + * + * max(|B'(t)|) <= 3 max (|p1-p0|, |p2-p1|, |p3-p2|) + * + * We can improve this by noticing that a quadratic Bezier (a,b,c) is + * bounded by the quad (a,lerp(a,b,t),lerp(b,c,t),c) for any t, so + * (substituting the previous values, using t=0.5 and simplifying): + * + * max(|B'(t)|) <= 3 max (|p1-p0|, |p2-p0|/2, |p3-p1|/2, |p3-p2|) + * + * So, to guarantee a maximum step length of 1/sqrt(2) we must do: + * + * 3 max (|p1-p0|, |p2-p0|/2, |p3-p1|/2, |p3-p2|) sqrt(2) steps + */ +static inline double +bezier_steps_sq (cairo_point_double_t p[4]) +{ + double tmp = sqlen (p[0], p[1]); + tmp = MAX (tmp, sqlen (p[2], p[3])); + tmp = MAX (tmp, sqlen (p[0], p[2]) * .25); + tmp = MAX (tmp, sqlen (p[1], p[3]) * .25); + return 18.0 * tmp; +} + +/* + * Split a 1D Bezier cubic using de Casteljau's algorithm. + * + * Input: x,y,z,w the nodes of the Bezier curve + * + * Output: x0,y0,z0,w0 and x1,y1,z1,w1 are respectively the nodes of + * the first half and of the second half of the curve + * + * The output control nodes have to be distinct. + */ +static inline void +split_bezier_1D (double x, double y, double z, double w, + double *x0, double *y0, double *z0, double *w0, + double *x1, double *y1, double *z1, double *w1) +{ + double tmp; + + *x0 = x; + *w1 = w; + + tmp = 0.5 * (y + z); + *y0 = 0.5 * (x + y); + *z1 = 0.5 * (z + w); + + *z0 = 0.5 * (*y0 + tmp); + *y1 = 0.5 * (tmp + *z1); + + *w0 = *x1 = 0.5 * (*z0 + *y1); +} + +/* + * Split a Bezier curve using de Casteljau's algorithm. + * + * Input: p[0..3] the nodes of the Bezier curve + * + * Output: fst_half[0..3] and snd_half[0..3] are respectively the + * nodes of the first and of the second half of the curve + * + * fst_half and snd_half must be different, but they can be the same as + * nodes. + */ +static void +split_bezier (cairo_point_double_t p[4], + cairo_point_double_t fst_half[4], + cairo_point_double_t snd_half[4]) +{ + split_bezier_1D (p[0].x, p[1].x, p[2].x, p[3].x, + &fst_half[0].x, &fst_half[1].x, &fst_half[2].x, &fst_half[3].x, + &snd_half[0].x, &snd_half[1].x, &snd_half[2].x, &snd_half[3].x); + + split_bezier_1D (p[0].y, p[1].y, p[2].y, p[3].y, + &fst_half[0].y, &fst_half[1].y, &fst_half[2].y, &fst_half[3].y, + &snd_half[0].y, &snd_half[1].y, &snd_half[2].y, &snd_half[3].y); +} + + +typedef enum _intersection { + INSIDE = -1, /* the interval is entirely contained in the reference interval */ + OUTSIDE = 0, /* the interval has no intersection with the reference interval */ + PARTIAL = 1 /* the interval intersects the reference interval (but is not fully inside it) */ +} intersection_t; + +/* + * Check if an interval if inside another. + * + * Input: a,b are the extrema of the first interval + * c,d are the extrema of the second interval + * + * Returns: INSIDE iff [a,b) intersection [c,d) = [a,b) + * OUTSIDE iff [a,b) intersection [c,d) = {} + * PARTIAL otherwise + * + * The function assumes a < b and c < d + * + * Note: Bitwise-anding the results along each component gives the + * expected result for [a,b) x [A,B) intersection [c,d) x [C,D). + */ +static inline int +intersect_interval (double a, double b, double c, double d) +{ + if (c <= a && b <= d) + return INSIDE; + else if (a >= d || b <= c) + return OUTSIDE; + else + return PARTIAL; +} + +/* + * Set the color of a pixel. + * + * Input: data is the base pointer of the image + * width, height are the dimensions of the image + * stride is the stride in bytes between adjacent rows + * x, y are the coordinates of the pixel to be colored + * r,g,b,a are the color components of the color to be set + * + * Output: the (x,y) pixel in data has the (r,g,b,a) color + * + * The input color components are not premultiplied, but the data + * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, + * premultiplied). + * + * If the pixel to be set is outside the image, this function does + * nothing. + */ +static inline void +draw_pixel (unsigned char *data, int width, int height, int stride, + int x, int y, uint16_t r, uint16_t g, uint16_t b, uint16_t a) +{ + if (likely (0 <= x && 0 <= y && x < width && y < height)) { + uint32_t tr, tg, tb, ta; + + /* Premultiply and round */ + ta = a; + tr = r * ta + 0x8000; + tg = g * ta + 0x8000; + tb = b * ta + 0x8000; + + tr += tr >> 16; + tg += tg >> 16; + tb += tb >> 16; + + *((uint32_t*) (data + y*stride + 4*x)) = ((ta << 16) & 0xff000000) | + ((tr >> 8) & 0xff0000) | ((tg >> 16) & 0xff00) | (tb >> 24); + } +} + +/* + * Forward-rasterize a cubic curve using forward differences. + * + * Input: data is the base pointer of the image + * width, height are the dimensions of the image + * stride is the stride in bytes between adjacent rows + * ushift is log2(n) if n is the number of desired steps + * dxu[i], dyu[i] are the x,y forward differences of the curve + * r0,g0,b0,a0 are the color components of the start point + * r3,g3,b3,a3 are the color components of the end point + * + * Output: data will be changed to have the requested curve drawn in + * the specified colors + * + * The input color components are not premultiplied, but the data + * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, + * premultiplied). + * + * The function draws n+1 pixels, that is from the point at step 0 to + * the point at step n, both included. This is the discrete equivalent + * to drawing the curve for values of the interpolation parameter in + * [0,1] (including both extremes). + */ +static inline void +rasterize_bezier_curve (unsigned char *data, int width, int height, int stride, + int ushift, double dxu[4], double dyu[4], + uint16_t r0, uint16_t g0, uint16_t b0, uint16_t a0, + uint16_t r3, uint16_t g3, uint16_t b3, uint16_t a3) +{ + int32_t xu[4], yu[4]; + int x0, y0, u, usteps = 1 << ushift; + + uint16_t r = r0, g = g0, b = b0, a = a0; + int16_t dr = _color_delta_to_shifted_short (r0, r3, ushift); + int16_t dg = _color_delta_to_shifted_short (g0, g3, ushift); + int16_t db = _color_delta_to_shifted_short (b0, b3, ushift); + int16_t da = _color_delta_to_shifted_short (a0, a3, ushift); + + fd_fixed (dxu, xu); + fd_fixed (dyu, yu); + + /* + * Use (dxu[0],dyu[0]) as origin for the forward differences. + * + * This makes it possible to handle much larger coordinates (the + * ones that can be represented as cairo_fixed_t) + */ + x0 = _cairo_fixed_from_double (dxu[0]); + y0 = _cairo_fixed_from_double (dyu[0]); + xu[0] = 0; + yu[0] = 0; + + for (u = 0; u <= usteps; ++u) { + /* + * This rasterizer assumes that pixels are integer aligned + * squares, so a generic (x,y) point belongs to the pixel with + * top-left coordinates (floor(x), floor(y)) + */ + + int x = _cairo_fixed_integer_floor (x0 + (xu[0] >> 15) + ((xu[0] >> 14) & 1)); + int y = _cairo_fixed_integer_floor (y0 + (yu[0] >> 15) + ((yu[0] >> 14) & 1)); + + draw_pixel (data, width, height, stride, x, y, r, g, b, a); + + fd_fixed_fwd (xu); + fd_fixed_fwd (yu); + r += dr; + g += dg; + b += db; + a += da; + } +} + +/* + * Clip, split and rasterize a Bezier curve. + * + * Input: data is the base pointer of the image + * width, height are the dimensions of the image + * stride is the stride in bytes between adjacent rows + * p[i] is the i-th node of the Bezier curve + * c0[i] is the i-th color component at the start point + * c3[i] is the i-th color component at the end point + * + * Output: data will be changed to have the requested curve drawn in + * the specified colors + * + * The input color components are not premultiplied, but the data + * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, + * premultiplied). + * + * The color components are red, green, blue and alpha, in this order. + * + * The function guarantees that it will draw the curve with a step + * small enough to never have a distance above 1/sqrt(2) between two + * consecutive points (which is needed to ensure that no hole can + * appear when using this function to rasterize a patch). + */ +static void +draw_bezier_curve (unsigned char *data, int width, int height, int stride, + cairo_point_double_t p[4], double c0[4], double c3[4]) +{ + double top, bottom, left, right, steps_sq; + int i, v; + + top = bottom = p[0].y; + for (i = 1; i < 4; ++i) { + top = MIN (top, p[i].y); + bottom = MAX (bottom, p[i].y); + } + + /* Check visibility */ + v = intersect_interval (top, bottom, 0, height); + if (v == OUTSIDE) + return; + + left = right = p[0].x; + for (i = 1; i < 4; ++i) { + left = MIN (left, p[i].x); + right = MAX (right, p[i].x); + } + + v &= intersect_interval (left, right, 0, width); + if (v == OUTSIDE) + return; + + steps_sq = bezier_steps_sq (p); + if (steps_sq >= (v == INSIDE ? STEPS_MAX_U * STEPS_MAX_U : STEPS_CLIP_U * STEPS_CLIP_U)) { + /* + * The number of steps is greater than the threshold. This + * means that either the error would become too big if we + * directly rasterized it or that we can probably save some + * time by splitting the curve and clipping part of it + */ + cairo_point_double_t first[4], second[4]; + double midc[4]; + split_bezier (p, first, second); + midc[0] = (c0[0] + c3[0]) * 0.5; + midc[1] = (c0[1] + c3[1]) * 0.5; + midc[2] = (c0[2] + c3[2]) * 0.5; + midc[3] = (c0[3] + c3[3]) * 0.5; + draw_bezier_curve (data, width, height, stride, first, c0, midc); + draw_bezier_curve (data, width, height, stride, second, midc, c3); + } else { + double xu[4], yu[4]; + int ushift = sqsteps2shift (steps_sq), k; + + fd_init (p[0].x, p[1].x, p[2].x, p[3].x, xu); + fd_init (p[0].y, p[1].y, p[2].y, p[3].y, yu); + + for (k = 0; k < ushift; ++k) { + fd_down (xu); + fd_down (yu); + } + + rasterize_bezier_curve (data, width, height, stride, ushift, + xu, yu, + _cairo_color_double_to_short (c0[0]), + _cairo_color_double_to_short (c0[1]), + _cairo_color_double_to_short (c0[2]), + _cairo_color_double_to_short (c0[3]), + _cairo_color_double_to_short (c3[0]), + _cairo_color_double_to_short (c3[1]), + _cairo_color_double_to_short (c3[2]), + _cairo_color_double_to_short (c3[3])); + + /* Draw the end point, to make sure that we didn't leave it + * out because of rounding */ + draw_pixel (data, width, height, stride, + _cairo_fixed_integer_floor (_cairo_fixed_from_double (p[3].x)), + _cairo_fixed_integer_floor (_cairo_fixed_from_double (p[3].y)), + _cairo_color_double_to_short (c3[0]), + _cairo_color_double_to_short (c3[1]), + _cairo_color_double_to_short (c3[2]), + _cairo_color_double_to_short (c3[3])); + } +} + +/* + * Forward-rasterize a cubic Bezier patch using forward differences. + * + * Input: data is the base pointer of the image + * width, height are the dimensions of the image + * stride is the stride in bytes between adjacent rows + * vshift is log2(n) if n is the number of desired steps + * p[i][j], p[i][j] are the the nodes of the Bezier patch + * col[i][j] is the j-th color component of the i-th corner + * + * Output: data will be changed to have the requested patch drawn in + * the specified colors + * + * The nodes of the patch are as follows: + * + * u\v 0 - > 1 + * 0 p00 p01 p02 p03 + * | p10 p11 p12 p13 + * v p20 p21 p22 p23 + * 1 p30 p31 p32 p33 + * + * i.e. u varies along the first component (rows), v varies along the + * second one (columns). + * + * The color components are red, green, blue and alpha, in this order. + * c[0..3] are the colors in p00, p30, p03, p33 respectively + * + * The input color components are not premultiplied, but the data + * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, + * premultiplied). + * + * If the patch folds over itself, the part with the highest v + * parameter is considered above. If both have the same v, the one + * with the highest u parameter is above. + * + * The function draws n+1 curves, that is from the curve at step 0 to + * the curve at step n, both included. This is the discrete equivalent + * to drawing the patch for values of the interpolation parameter in + * [0,1] (including both extremes). + */ +static inline void +rasterize_bezier_patch (unsigned char *data, int width, int height, int stride, int vshift, + cairo_point_double_t p[4][4], double col[4][4]) +{ + double pv[4][2][4], cstart[4], cend[4], dcstart[4], dcend[4]; + int v, i, k; + + v = 1 << vshift; + + /* + * pv[i][0] is the function (represented using forward + * differences) mapping v to the x coordinate of the i-th node of + * the Bezier curve with parameter u. + * (Likewise p[i][0] gives the y coordinate). + * + * This means that (pv[0][0][0],pv[0][1][0]), + * (pv[1][0][0],pv[1][1][0]), (pv[2][0][0],pv[2][1][0]) and + * (pv[3][0][0],pv[3][1][0]) are the nodes of the Bezier curve for + * the "current" v value (see the FD comments for more details). + */ + for (i = 0; i < 4; ++i) { + fd_init (p[i][0].x, p[i][1].x, p[i][2].x, p[i][3].x, pv[i][0]); + fd_init (p[i][0].y, p[i][1].y, p[i][2].y, p[i][3].y, pv[i][1]); + for (k = 0; k < vshift; ++k) { + fd_down (pv[i][0]); + fd_down (pv[i][1]); + } + } + + for (i = 0; i < 4; ++i) { + cstart[i] = col[0][i]; + cend[i] = col[1][i]; + dcstart[i] = (col[2][i] - col[0][i]) / v; + dcend[i] = (col[3][i] - col[1][i]) / v; + } + + v++; + while (v--) { + cairo_point_double_t nodes[4]; + for (i = 0; i < 4; ++i) { + nodes[i].x = pv[i][0][0]; + nodes[i].y = pv[i][1][0]; + } + + draw_bezier_curve (data, width, height, stride, nodes, cstart, cend); + + for (i = 0; i < 4; ++i) { + fd_fwd (pv[i][0]); + fd_fwd (pv[i][1]); + cstart[i] += dcstart[i]; + cend[i] += dcend[i]; + } + } +} + +/* + * Clip, split and rasterize a Bezier cubic patch. + * + * Input: data is the base pointer of the image + * width, height are the dimensions of the image + * stride is the stride in bytes between adjacent rows + * p[i][j], p[i][j] are the nodes of the patch + * col[i][j] is the j-th color component of the i-th corner + * + * Output: data will be changed to have the requested patch drawn in + * the specified colors + * + * The nodes of the patch are as follows: + * + * u\v 0 - > 1 + * 0 p00 p01 p02 p03 + * | p10 p11 p12 p13 + * v p20 p21 p22 p23 + * 1 p30 p31 p32 p33 + * + * i.e. u varies along the first component (rows), v varies along the + * second one (columns). + * + * The color components are red, green, blue and alpha, in this order. + * c[0..3] are the colors in p00, p30, p03, p33 respectively + * + * The input color components are not premultiplied, but the data + * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc, + * premultiplied). + * + * If the patch folds over itself, the part with the highest v + * parameter is considered above. If both have the same v, the one + * with the highest u parameter is above. + * + * The function guarantees that it will draw the patch with a step + * small enough to never have a distance above 1/sqrt(2) between two + * adjacent points (which guarantees that no hole can appear). + * + * This function can be used to rasterize a tile of PDF type 7 + * shadings (see http://www.adobe.com/devnet/pdf/pdf_reference.html). + */ +static void +draw_bezier_patch (unsigned char *data, int width, int height, int stride, + cairo_point_double_t p[4][4], double c[4][4]) +{ + double top, bottom, left, right, steps_sq; + int i, j, v; + + top = bottom = p[0][0].y; + for (i = 0; i < 4; ++i) { + for (j= 0; j < 4; ++j) { + top = MIN (top, p[i][j].y); + bottom = MAX (bottom, p[i][j].y); + } + } + + v = intersect_interval (top, bottom, 0, height); + if (v == OUTSIDE) + return; + + left = right = p[0][0].x; + for (i = 0; i < 4; ++i) { + for (j= 0; j < 4; ++j) { + left = MIN (left, p[i][j].x); + right = MAX (right, p[i][j].x); + } + } + + v &= intersect_interval (left, right, 0, width); + if (v == OUTSIDE) + return; + + steps_sq = 0; + for (i = 0; i < 4; ++i) + steps_sq = MAX (steps_sq, bezier_steps_sq (p[i])); + + if (steps_sq >= (v == INSIDE ? STEPS_MAX_V * STEPS_MAX_V : STEPS_CLIP_V * STEPS_CLIP_V)) { + /* The number of steps is greater than the threshold. This + * means that either the error would become too big if we + * directly rasterized it or that we can probably save some + * time by splitting the curve and clipping part of it. The + * patch is only split in the v direction to guarantee that + * rasterizing each part will overwrite parts with low v with + * overlapping parts with higher v. */ + + cairo_point_double_t first[4][4], second[4][4]; + double subc[4][4]; + + for (i = 0; i < 4; ++i) + split_bezier (p[i], first[i], second[i]); + + for (i = 0; i < 4; ++i) { + subc[0][i] = c[0][i]; + subc[1][i] = c[1][i]; + subc[2][i] = 0.5 * (c[0][i] + c[2][i]); + subc[3][i] = 0.5 * (c[1][i] + c[3][i]); + } + + draw_bezier_patch (data, width, height, stride, first, subc); + + for (i = 0; i < 4; ++i) { + subc[0][i] = subc[2][i]; + subc[1][i] = subc[3][i]; + subc[2][i] = c[2][i]; + subc[3][i] = c[3][i]; + } + draw_bezier_patch (data, width, height, stride, second, subc); + } else { + rasterize_bezier_patch (data, width, height, stride, sqsteps2shift (steps_sq), p, c); + } +} + +/* + * Draw a tensor product shading pattern. + * + * Input: mesh is the mesh pattern + * data is the base pointer of the image + * width, height are the dimensions of the image + * stride is the stride in bytes between adjacent rows + * + * Output: data will be changed to have the pattern drawn on it + * + * data is assumed to be clear and its content is assumed to be in + * CAIRO_FORMAT_ARGB32 (8 bpc, premultiplied). + * + * This function can be used to rasterize a PDF type 7 shading (see + * http://www.adobe.com/devnet/pdf/pdf_reference.html). + */ +void +_cairo_mesh_pattern_rasterize (const cairo_mesh_pattern_t *mesh, + void *data, + int width, + int height, + int stride, + double x_offset, + double y_offset) +{ + cairo_point_double_t nodes[4][4]; + double colors[4][4]; + cairo_matrix_t p2u; + unsigned int i, j, k, n; + cairo_status_t status; + const cairo_mesh_patch_t *patch; + const cairo_color_t *c; + + assert (mesh->base.status == CAIRO_STATUS_SUCCESS); + assert (mesh->current_patch == NULL); + + p2u = mesh->base.matrix; + status = cairo_matrix_invert (&p2u); + assert (status == CAIRO_STATUS_SUCCESS); + + n = _cairo_array_num_elements (&mesh->patches); + patch = _cairo_array_index_const (&mesh->patches, 0); + for (i = 0; i < n; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) { + nodes[j][k] = patch->points[j][k]; + cairo_matrix_transform_point (&p2u, &nodes[j][k].x, &nodes[j][k].y); + nodes[j][k].x += x_offset; + nodes[j][k].y += y_offset; + } + } + + c = &patch->colors[0]; + colors[0][0] = c->red; + colors[0][1] = c->green; + colors[0][2] = c->blue; + colors[0][3] = c->alpha; + + c = &patch->colors[3]; + colors[1][0] = c->red; + colors[1][1] = c->green; + colors[1][2] = c->blue; + colors[1][3] = c->alpha; + + c = &patch->colors[1]; + colors[2][0] = c->red; + colors[2][1] = c->green; + colors[2][2] = c->blue; + colors[2][3] = c->alpha; + + c = &patch->colors[2]; + colors[3][0] = c->red; + colors[3][1] = c->green; + colors[3][2] = c->blue; + colors[3][3] = c->alpha; + + draw_bezier_patch (data, width, height, stride, nodes, colors); + patch++; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-misc.c b/Build/source/libs/cairo/cairo-src/src/cairo-misc.c new file mode 100644 index 00000000000..3c7c959862d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-misc.c @@ -0,0 +1,955 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2007 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Adrian Johnson + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +COMPILE_TIME_ASSERT ((int)CAIRO_STATUS_LAST_STATUS < (int)CAIRO_INT_STATUS_UNSUPPORTED); +COMPILE_TIME_ASSERT (CAIRO_INT_STATUS_LAST_STATUS <= 127); + +/** + * SECTION:cairo-status + * @Title: Error handling + * @Short_Description: Decoding cairo's status + * @See_Also: cairo_status(), cairo_surface_status(), cairo_pattern_status(), + * cairo_font_face_status(), cairo_scaled_font_status(), + * cairo_region_status() + * + * Cairo uses a single status type to represent all kinds of errors. A status + * value of %CAIRO_STATUS_SUCCESS represents no error and has an integer value + * of zero. All other status values represent an error. + * + * Cairo's error handling is designed to be easy to use and safe. All major + * cairo objects retain an error status internally which + * can be queried anytime by the users using cairo*_status() calls. In + * the mean time, it is safe to call all cairo functions normally even if the + * underlying object is in an error status. This means that no error handling + * code is required before or after each individual cairo function call. + **/ + +/* Public stuff */ + +/** + * cairo_status_to_string: + * @status: a cairo status + * + * Provides a human-readable description of a #cairo_status_t. + * + * Returns: a string representation of the status + * + * Since: 1.0 + **/ +const char * +cairo_status_to_string (cairo_status_t status) +{ + switch (status) { + case CAIRO_STATUS_SUCCESS: + return "no error has occurred"; + case CAIRO_STATUS_NO_MEMORY: + return "out of memory"; + case CAIRO_STATUS_INVALID_RESTORE: + return "cairo_restore() without matching cairo_save()"; + case CAIRO_STATUS_INVALID_POP_GROUP: + return "no saved group to pop, i.e. cairo_pop_group() without matching cairo_push_group()"; + case CAIRO_STATUS_NO_CURRENT_POINT: + return "no current point defined"; + case CAIRO_STATUS_INVALID_MATRIX: + return "invalid matrix (not invertible)"; + case CAIRO_STATUS_INVALID_STATUS: + return "invalid value for an input cairo_status_t"; + case CAIRO_STATUS_NULL_POINTER: + return "NULL pointer"; + case CAIRO_STATUS_INVALID_STRING: + return "input string not valid UTF-8"; + case CAIRO_STATUS_INVALID_PATH_DATA: + return "input path data not valid"; + case CAIRO_STATUS_READ_ERROR: + return "error while reading from input stream"; + case CAIRO_STATUS_WRITE_ERROR: + return "error while writing to output stream"; + case CAIRO_STATUS_SURFACE_FINISHED: + return "the target surface has been finished"; + case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: + return "the surface type is not appropriate for the operation"; + case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: + return "the pattern type is not appropriate for the operation"; + case CAIRO_STATUS_INVALID_CONTENT: + return "invalid value for an input cairo_content_t"; + case CAIRO_STATUS_INVALID_FORMAT: + return "invalid value for an input cairo_format_t"; + case CAIRO_STATUS_INVALID_VISUAL: + return "invalid value for an input Visual*"; + case CAIRO_STATUS_FILE_NOT_FOUND: + return "file not found"; + case CAIRO_STATUS_INVALID_DASH: + return "invalid value for a dash setting"; + case CAIRO_STATUS_INVALID_DSC_COMMENT: + return "invalid value for a DSC comment"; + case CAIRO_STATUS_INVALID_INDEX: + return "invalid index passed to getter"; + case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: + return "clip region not representable in desired format"; + case CAIRO_STATUS_TEMP_FILE_ERROR: + return "error creating or writing to a temporary file"; + case CAIRO_STATUS_INVALID_STRIDE: + return "invalid value for stride"; + case CAIRO_STATUS_FONT_TYPE_MISMATCH: + return "the font type is not appropriate for the operation"; + case CAIRO_STATUS_USER_FONT_IMMUTABLE: + return "the user-font is immutable"; + case CAIRO_STATUS_USER_FONT_ERROR: + return "error occurred in a user-font callback function"; + case CAIRO_STATUS_NEGATIVE_COUNT: + return "negative number used where it is not allowed"; + case CAIRO_STATUS_INVALID_CLUSTERS: + return "input clusters do not represent the accompanying text and glyph arrays"; + case CAIRO_STATUS_INVALID_SLANT: + return "invalid value for an input cairo_font_slant_t"; + case CAIRO_STATUS_INVALID_WEIGHT: + return "invalid value for an input cairo_font_weight_t"; + case CAIRO_STATUS_INVALID_SIZE: + return "invalid value (typically too big) for the size of the input (surface, pattern, etc.)"; + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: + return "user-font method not implemented"; + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: + return "the device type is not appropriate for the operation"; + case CAIRO_STATUS_DEVICE_ERROR: + return "an operation to the device caused an unspecified error"; + case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: + return "invalid operation during mesh pattern construction"; + case CAIRO_STATUS_DEVICE_FINISHED: + return "the target device has been finished"; + case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: + return "CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID used but no CAIRO_MIME_TYPE_JBIG2_GLOBAL data provided"; + default: + case CAIRO_STATUS_LAST_STATUS: + return ""; + } +} + + +/** + * cairo_glyph_allocate: + * @num_glyphs: number of glyphs to allocate + * + * Allocates an array of #cairo_glyph_t's. + * This function is only useful in implementations of + * #cairo_user_scaled_font_text_to_glyphs_func_t where the user + * needs to allocate an array of glyphs that cairo will free. + * For all other uses, user can use their own allocation method + * for glyphs. + * + * This function returns %NULL if @num_glyphs is not positive, + * or if out of memory. That means, the %NULL return value + * signals out-of-memory only if @num_glyphs was positive. + * + * Returns: the newly allocated array of glyphs that should be + * freed using cairo_glyph_free() + * + * Since: 1.8 + **/ +cairo_glyph_t * +cairo_glyph_allocate (int num_glyphs) +{ + if (num_glyphs <= 0) + return NULL; + + return _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); +} +slim_hidden_def (cairo_glyph_allocate); + +/** + * cairo_glyph_free: + * @glyphs: array of glyphs to free, or %NULL + * + * Frees an array of #cairo_glyph_t's allocated using cairo_glyph_allocate(). + * This function is only useful to free glyph array returned + * by cairo_scaled_font_text_to_glyphs() where cairo returns + * an array of glyphs that the user will free. + * For all other uses, user can use their own allocation method + * for glyphs. + * + * Since: 1.8 + **/ +void +cairo_glyph_free (cairo_glyph_t *glyphs) +{ + free (glyphs); +} +slim_hidden_def (cairo_glyph_free); + +/** + * cairo_text_cluster_allocate: + * @num_clusters: number of text_clusters to allocate + * + * Allocates an array of #cairo_text_cluster_t's. + * This function is only useful in implementations of + * #cairo_user_scaled_font_text_to_glyphs_func_t where the user + * needs to allocate an array of text clusters that cairo will free. + * For all other uses, user can use their own allocation method + * for text clusters. + * + * This function returns %NULL if @num_clusters is not positive, + * or if out of memory. That means, the %NULL return value + * signals out-of-memory only if @num_clusters was positive. + * + * Returns: the newly allocated array of text clusters that should be + * freed using cairo_text_cluster_free() + * + * Since: 1.8 + **/ +cairo_text_cluster_t * +cairo_text_cluster_allocate (int num_clusters) +{ + if (num_clusters <= 0) + return NULL; + + return _cairo_malloc_ab (num_clusters, sizeof (cairo_text_cluster_t)); +} +slim_hidden_def (cairo_text_cluster_allocate); + +/** + * cairo_text_cluster_free: + * @clusters: array of text clusters to free, or %NULL + * + * Frees an array of #cairo_text_cluster's allocated using cairo_text_cluster_allocate(). + * This function is only useful to free text cluster array returned + * by cairo_scaled_font_text_to_glyphs() where cairo returns + * an array of text clusters that the user will free. + * For all other uses, user can use their own allocation method + * for text clusters. + * + * Since: 1.8 + **/ +void +cairo_text_cluster_free (cairo_text_cluster_t *clusters) +{ + free (clusters); +} +slim_hidden_def (cairo_text_cluster_free); + + +/* Private stuff */ + +/** + * _cairo_validate_text_clusters: + * @utf8: UTF-8 text + * @utf8_len: length of @utf8 in bytes + * @glyphs: array of glyphs + * @num_glyphs: number of glyphs + * @clusters: array of cluster mapping information + * @num_clusters: number of clusters in the mapping + * @cluster_flags: cluster flags + * + * Check that clusters cover the entire glyphs and utf8 arrays, + * and that cluster boundaries are UTF-8 boundaries. + * + * Return value: %CAIRO_STATUS_SUCCESS upon success, or + * %CAIRO_STATUS_INVALID_CLUSTERS on error. + * The error is either invalid UTF-8 input, + * or bad cluster mapping. + **/ +cairo_status_t +_cairo_validate_text_clusters (const char *utf8, + int utf8_len, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags) +{ + cairo_status_t status; + unsigned int n_bytes = 0; + unsigned int n_glyphs = 0; + int i; + + for (i = 0; i < num_clusters; i++) { + int cluster_bytes = clusters[i].num_bytes; + int cluster_glyphs = clusters[i].num_glyphs; + + if (cluster_bytes < 0 || cluster_glyphs < 0) + goto BAD; + + /* A cluster should cover at least one character or glyph. + * I can't see any use for a 0,0 cluster. + * I can't see an immediate use for a zero-text cluster + * right now either, but they don't harm. + * Zero-glyph clusters on the other hand are useful for + * things like U+200C ZERO WIDTH NON-JOINER */ + if (cluster_bytes == 0 && cluster_glyphs == 0) + goto BAD; + + /* Since n_bytes and n_glyphs are unsigned, but the rest of + * values involved are signed, we can detect overflow easily */ + if (n_bytes+cluster_bytes > (unsigned int)utf8_len || n_glyphs+cluster_glyphs > (unsigned int)num_glyphs) + goto BAD; + + /* Make sure we've got valid UTF-8 for the cluster */ + status = _cairo_utf8_to_ucs4 (utf8+n_bytes, cluster_bytes, NULL, NULL); + if (unlikely (status)) + return _cairo_error (CAIRO_STATUS_INVALID_CLUSTERS); + + n_bytes += cluster_bytes ; + n_glyphs += cluster_glyphs; + } + + if (n_bytes != (unsigned int) utf8_len || n_glyphs != (unsigned int) num_glyphs) { + BAD: + return _cairo_error (CAIRO_STATUS_INVALID_CLUSTERS); + } + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_operator_bounded_by_mask: + * @op: a #cairo_operator_t + * + * A bounded operator is one where mask pixel + * of zero results in no effect on the destination image. + * + * Unbounded operators often require special handling; if you, for + * example, draw trapezoids with an unbounded operator, the effect + * extends past the bounding box of the trapezoids. + * + * Return value: %TRUE if the operator is bounded by the mask operand + **/ +cairo_bool_t +_cairo_operator_bounded_by_mask (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_ATOP: + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return TRUE; + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_ATOP: + return FALSE; + } + + ASSERT_NOT_REACHED; + return FALSE; +} + +/** + * _cairo_operator_bounded_by_source: + * @op: a #cairo_operator_t + * + * A bounded operator is one where source pixels of zero + * (in all four components, r, g, b and a) effect no change + * in the resulting destination image. + * + * Unbounded operators often require special handling; if you, for + * example, copy a surface with the SOURCE operator, the effect + * extends past the bounding box of the source surface. + * + * Return value: %TRUE if the operator is bounded by the source operand + **/ +cairo_bool_t +_cairo_operator_bounded_by_source (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_ATOP: + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return TRUE; + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_ATOP: + return FALSE; + } + + ASSERT_NOT_REACHED; + return FALSE; +} + +uint32_t +_cairo_operator_bounded_by_either (cairo_operator_t op) +{ + switch (op) { + default: + ASSERT_NOT_REACHED; + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_ATOP: + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE; + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + return CAIRO_OPERATOR_BOUND_BY_MASK; + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_ATOP: + return 0; + } + +} + +#if DISABLE_SOME_FLOATING_POINT +/* This function is identical to the C99 function lround(), except that it + * performs arithmetic rounding (floor(d + .5) instead of away-from-zero rounding) and + * has a valid input range of (INT_MIN, INT_MAX] instead of + * [INT_MIN, INT_MAX]. It is much faster on both x86 and FPU-less systems + * than other commonly used methods for rounding (lround, round, rint, lrint + * or float (d + 0.5)). + * + * The reason why this function is much faster on x86 than other + * methods is due to the fact that it avoids the fldcw instruction. + * This instruction incurs a large performance penalty on modern Intel + * processors due to how it prevents efficient instruction pipelining. + * + * The reason why this function is much faster on FPU-less systems is for + * an entirely different reason. All common rounding methods involve multiple + * floating-point operations. Each one of these operations has to be + * emulated in software, which adds up to be a large performance penalty. + * This function doesn't perform any floating-point calculations, and thus + * avoids this penalty. + */ +int +_cairo_lround (double d) +{ + uint32_t top, shift_amount, output; + union { + double d; + uint64_t ui64; + uint32_t ui32[2]; + } u; + + u.d = d; + + /* If the integer word order doesn't match the float word order, we swap + * the words of the input double. This is needed because we will be + * treating the whole double as a 64-bit unsigned integer. Notice that we + * use WORDS_BIGENDIAN to detect the integer word order, which isn't + * exactly correct because WORDS_BIGENDIAN refers to byte order, not word + * order. Thus, we are making the assumption that the byte order is the + * same as the integer word order which, on the modern machines that we + * care about, is OK. + */ +#if ( defined(FLOAT_WORDS_BIGENDIAN) && !defined(WORDS_BIGENDIAN)) || \ + (!defined(FLOAT_WORDS_BIGENDIAN) && defined(WORDS_BIGENDIAN)) + { + uint32_t temp = u.ui32[0]; + u.ui32[0] = u.ui32[1]; + u.ui32[1] = temp; + } +#endif + +#ifdef WORDS_BIGENDIAN + #define MSW (0) /* Most Significant Word */ + #define LSW (1) /* Least Significant Word */ +#else + #define MSW (1) + #define LSW (0) +#endif + + /* By shifting the most significant word of the input double to the + * right 20 places, we get the very "top" of the double where the exponent + * and sign bit lie. + */ + top = u.ui32[MSW] >> 20; + + /* Here, we calculate how much we have to shift the mantissa to normalize + * it to an integer value. We extract the exponent "top" by masking out the + * sign bit, then we calculate the shift amount by subtracting the exponent + * from the bias. Notice that the correct bias for 64-bit doubles is + * actually 1075, but we use 1053 instead for two reasons: + * + * 1) To perform rounding later on, we will first need the target + * value in a 31.1 fixed-point format. Thus, the bias needs to be one + * less: (1075 - 1: 1074). + * + * 2) To avoid shifting the mantissa as a full 64-bit integer (which is + * costly on certain architectures), we break the shift into two parts. + * First, the upper and lower parts of the mantissa are shifted + * individually by a constant amount that all valid inputs will require + * at the very least. This amount is chosen to be 21, because this will + * allow the two parts of the mantissa to later be combined into a + * single 32-bit representation, on which the remainder of the shift + * will be performed. Thus, we decrease the bias by an additional 21: + * (1074 - 21: 1053). + */ + shift_amount = 1053 - (top & 0x7FF); + + /* We are done with the exponent portion in "top", so here we shift it off + * the end. + */ + top >>= 11; + + /* Before we perform any operations on the mantissa, we need to OR in + * the implicit 1 at the top (see the IEEE-754 spec). We needn't mask + * off the sign bit nor the exponent bits because these higher bits won't + * make a bit of difference in the rest of our calculations. + */ + u.ui32[MSW] |= 0x100000; + + /* If the input double is negative, we have to decrease the mantissa + * by a hair. This is an important part of performing arithmetic rounding, + * as negative numbers must round towards positive infinity in the + * halfwase case of -x.5. Since "top" contains only the sign bit at this + * point, we can just decrease the mantissa by the value of "top". + */ + u.ui64 -= top; + + /* By decrementing "top", we create a bitmask with a value of either + * 0x0 (if the input was negative) or 0xFFFFFFFF (if the input was positive + * and thus the unsigned subtraction underflowed) that we'll use later. + */ + top--; + + /* Here, we shift the mantissa by the constant value as described above. + * We can emulate a 64-bit shift right by 21 through shifting the top 32 + * bits left 11 places and ORing in the bottom 32 bits shifted 21 places + * to the right. Both parts of the mantissa are now packed into a single + * 32-bit integer. Although we severely truncate the lower part in the + * process, we still have enough significant bits to perform the conversion + * without error (for all valid inputs). + */ + output = (u.ui32[MSW] << 11) | (u.ui32[LSW] >> 21); + + /* Next, we perform the shift that converts the X.Y fixed-point number + * currently found in "output" to the desired 31.1 fixed-point format + * needed for the following rounding step. It is important to consider + * all possible values for "shift_amount" at this point: + * + * - {shift_amount < 0} Since shift_amount is an unsigned integer, it + * really can't have a value less than zero. But, if the shift_amount + * calculation above caused underflow (which would happen with + * input > INT_MAX or input <= INT_MIN) then shift_amount will now be + * a very large number, and so this shift will result in complete + * garbage. But that's OK, as the input was out of our range, so our + * output is undefined. + * + * - {shift_amount > 31} If the magnitude of the input was very small + * (i.e. |input| << 1.0), shift_amount will have a value greater than + * 31. Thus, this shift will also result in garbage. After performing + * the shift, we will zero-out "output" if this is the case. + * + * - {0 <= shift_amount < 32} In this case, the shift will properly convert + * the mantissa into a 31.1 fixed-point number. + */ + output >>= shift_amount; + + /* This is where we perform rounding with the 31.1 fixed-point number. + * Since what we're after is arithmetic rounding, we simply add the single + * fractional bit into the integer part of "output", and just keep the + * integer part. + */ + output = (output >> 1) + (output & 1); + + /* Here, we zero-out the result if the magnitude if the input was very small + * (as explained in the section above). Notice that all input out of the + * valid range is also caught by this condition, which means we produce 0 + * for all invalid input, which is a nice side effect. + * + * The most straightforward way to do this would be: + * + * if (shift_amount > 31) + * output = 0; + * + * But we can use a little trick to avoid the potential branch. The + * expression (shift_amount > 31) will be either 1 or 0, which when + * decremented will be either 0x0 or 0xFFFFFFFF (unsigned underflow), + * which can be used to conditionally mask away all the bits in "output" + * (in the 0x0 case), effectively zeroing it out. Certain, compilers would + * have done this for us automatically. + */ + output &= ((shift_amount > 31) - 1); + + /* If the input double was a negative number, then we have to negate our + * output. The most straightforward way to do this would be: + * + * if (!top) + * output = -output; + * + * as "top" at this point is either 0x0 (if the input was negative) or + * 0xFFFFFFFF (if the input was positive). But, we can use a trick to + * avoid the branch. Observe that the following snippet of code has the + * same effect as the reference snippet above: + * + * if (!top) + * output = 0 - output; + * else + * output = output - 0; + * + * Armed with the bitmask found in "top", we can condense the two statements + * into the following: + * + * output = (output & top) - (output & ~top); + * + * where, in the case that the input double was negative, "top" will be 0, + * and the statement will be equivalent to: + * + * output = (0) - (output); + * + * and if the input double was positive, "top" will be 0xFFFFFFFF, and the + * statement will be equivalent to: + * + * output = (output) - (0); + * + * Which, as pointed out earlier, is equivalent to the original reference + * snippet. + */ + output = (output & top) - (output & ~top); + + return output; +#undef MSW +#undef LSW +} +#endif + +/* Convert a 32-bit IEEE single precision floating point number to a + * 'half' representation (s10.5) + */ +uint16_t +_cairo_half_from_float (float f) +{ + union { + uint32_t ui; + float f; + } u; + int s, e, m; + + u.f = f; + s = (u.ui >> 16) & 0x00008000; + e = ((u.ui >> 23) & 0x000000ff) - (127 - 15); + m = u.ui & 0x007fffff; + if (e <= 0) { + if (e < -10) { + /* underflow */ + return 0; + } + + m = (m | 0x00800000) >> (1 - e); + + /* round to nearest, round 0.5 up. */ + if (m & 0x00001000) + m += 0x00002000; + return s | (m >> 13); + } else if (e == 0xff - (127 - 15)) { + if (m == 0) { + /* infinity */ + return s | 0x7c00; + } else { + /* nan */ + m >>= 13; + return s | 0x7c00 | m | (m == 0); + } + } else { + /* round to nearest, round 0.5 up. */ + if (m & 0x00001000) { + m += 0x00002000; + + if (m & 0x00800000) { + m = 0; + e += 1; + } + } + + if (e > 30) { + /* overflow -> infinity */ + return s | 0x7c00; + } + + return s | (e << 10) | (m >> 13); + } +} + +#ifndef __BIONIC__ +# include + +const char * +cairo_get_locale_decimal_point (void) +{ + struct lconv *locale_data = localeconv (); + return locale_data->decimal_point; +} + +#else +/* Android's Bionic libc doesn't provide decimal_point */ +const char * +cairo_get_locale_decimal_point (void) +{ + return "."; +} +#endif + +#ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN +/* We require Windows 2000 features such as ETO_PDY */ +#if !defined(WINVER) || (WINVER < 0x0500) +# define WINVER 0x0500 +#endif +#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) +# define _WIN32_WINNT 0x0500 +#endif + +#include +#include + +#if !_WIN32_WCE +/* tmpfile() replacement for Windows. + * + * On Windows tmpfile() creates the file in the root directory. This + * may fail due to unsufficient privileges. However, this isn't a + * problem on Windows CE so we don't use it there. + */ +FILE * +_cairo_win32_tmpfile (void) +{ + DWORD path_len; + WCHAR path_name[MAX_PATH + 1]; + WCHAR file_name[MAX_PATH + 1]; + HANDLE handle; + int fd; + FILE *fp; + + path_len = GetTempPathW (MAX_PATH, path_name); + if (path_len <= 0 || path_len >= MAX_PATH) + return NULL; + + if (GetTempFileNameW (path_name, L"ps_", 0, file_name) == 0) + return NULL; + + handle = CreateFileW (file_name, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, + NULL); + if (handle == INVALID_HANDLE_VALUE) { + DeleteFileW (file_name); + return NULL; + } + + fd = _open_osfhandle((intptr_t) handle, 0); + if (fd < 0) { + CloseHandle (handle); + return NULL; + } + + fp = fdopen(fd, "w+b"); + if (fp == NULL) { + _close(fd); + return NULL; + } + + return fp; +} +#endif /* !_WIN32_WCE */ + +#endif /* _WIN32 */ + +typedef struct _cairo_intern_string { + cairo_hash_entry_t hash_entry; + int len; + char *string; +} cairo_intern_string_t; + +static cairo_hash_table_t *_cairo_intern_string_ht; + +static unsigned long +_intern_string_hash (const char *str, int len) +{ + const signed char *p = (const signed char *) str; + unsigned int h = *p; + + for (p += 1; --len; p++) + h = (h << 5) - h + *p; + + return h; +} + +static cairo_bool_t +_intern_string_equal (const void *_a, const void *_b) +{ + const cairo_intern_string_t *a = _a; + const cairo_intern_string_t *b = _b; + + if (a->len != b->len) + return FALSE; + + return memcmp (a->string, b->string, a->len) == 0; +} + +cairo_status_t +_cairo_intern_string (const char **str_inout, int len) +{ + char *str = (char *) *str_inout; + cairo_intern_string_t tmpl, *istring; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (len < 0) + len = strlen (str); + tmpl.hash_entry.hash = _intern_string_hash (str, len); + tmpl.len = len; + tmpl.string = (char *) str; + + CAIRO_MUTEX_LOCK (_cairo_intern_string_mutex); + if (_cairo_intern_string_ht == NULL) { + _cairo_intern_string_ht = _cairo_hash_table_create (_intern_string_equal); + if (unlikely (_cairo_intern_string_ht == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + } + + istring = _cairo_hash_table_lookup (_cairo_intern_string_ht, + &tmpl.hash_entry); + if (istring == NULL) { + istring = malloc (sizeof (cairo_intern_string_t) + len + 1); + if (likely (istring != NULL)) { + istring->hash_entry.hash = tmpl.hash_entry.hash; + istring->len = tmpl.len; + istring->string = (char *) (istring + 1); + memcpy (istring->string, str, len); + istring->string[len] = '\0'; + + status = _cairo_hash_table_insert (_cairo_intern_string_ht, + &istring->hash_entry); + if (unlikely (status)) { + free (istring); + goto BAIL; + } + } else { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + } + + *str_inout = istring->string; + + BAIL: + CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex); + return status; +} + +static void +_intern_string_pluck (void *entry, void *closure) +{ + _cairo_hash_table_remove (closure, entry); + free (entry); +} + +void +_cairo_intern_string_reset_static_data (void) +{ + CAIRO_MUTEX_LOCK (_cairo_intern_string_mutex); + if (_cairo_intern_string_ht != NULL) { + _cairo_hash_table_foreach (_cairo_intern_string_ht, + _intern_string_pluck, + _cairo_intern_string_ht); + _cairo_hash_table_destroy(_cairo_intern_string_ht); + _cairo_intern_string_ht = NULL; + } + CAIRO_MUTEX_UNLOCK (_cairo_intern_string_mutex); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mono-scan-converter.c b/Build/source/libs/cairo/cairo-src/src/cairo-mono-scan-converter.c new file mode 100644 index 00000000000..2a9546cf82a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mono-scan-converter.c @@ -0,0 +1,612 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* + * Copyright (c) 2011 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#include "cairoint.h" +#include "cairo-spans-private.h" +#include "cairo-error-private.h" + +#include +#include +#include + +struct quorem { + int32_t quo; + int32_t rem; +}; + +struct edge { + struct edge *next, *prev; + + int32_t height_left; + int32_t dir; + int32_t vertical; + + int32_t dy; + struct quorem x; + struct quorem dxdy; +}; + +/* A collection of sorted and vertically clipped edges of the polygon. + * Edges are moved from the polygon to an active list while scan + * converting. */ +struct polygon { + /* The vertical clip extents. */ + int32_t ymin, ymax; + + int num_edges; + struct edge *edges; + + /* Array of edges all starting in the same bucket. An edge is put + * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when + * it is added to the polygon. */ + struct edge **y_buckets; + + struct edge *y_buckets_embedded[64]; + struct edge edges_embedded[32]; +}; + +struct mono_scan_converter { + struct polygon polygon[1]; + + /* Leftmost edge on the current scan line. */ + struct edge head, tail; + int is_vertical; + + cairo_half_open_span_t *spans; + cairo_half_open_span_t spans_embedded[64]; + int num_spans; + + /* Clip box. */ + int32_t xmin, xmax; + int32_t ymin, ymax; +}; + +#define I(x) _cairo_fixed_integer_round_down(x) + +/* Compute the floored division a/b. Assumes / and % perform symmetric + * division. */ +inline static struct quorem +floored_divrem(int a, int b) +{ + struct quorem qr; + qr.quo = a/b; + qr.rem = a%b; + if ((a^b)<0 && qr.rem) { + qr.quo -= 1; + qr.rem += b; + } + return qr; +} + +/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric + * division. */ +static struct quorem +floored_muldivrem(int x, int a, int b) +{ + struct quorem qr; + long long xa = (long long)x*a; + qr.quo = xa/b; + qr.rem = xa%b; + if ((xa>=0) != (b>=0) && qr.rem) { + qr.quo -= 1; + qr.rem += b; + } + return qr; +} + +static cairo_status_t +polygon_init (struct polygon *polygon, int ymin, int ymax) +{ + unsigned h = ymax - ymin + 1; + + polygon->y_buckets = polygon->y_buckets_embedded; + if (h > ARRAY_LENGTH (polygon->y_buckets_embedded)) { + polygon->y_buckets = _cairo_malloc_ab (h, sizeof (struct edge *)); + if (unlikely (NULL == polygon->y_buckets)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + memset (polygon->y_buckets, 0, h * sizeof (struct edge *)); + polygon->y_buckets[h-1] = (void *)-1; + + polygon->ymin = ymin; + polygon->ymax = ymax; + return CAIRO_STATUS_SUCCESS; +} + +static void +polygon_fini (struct polygon *polygon) +{ + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + if (polygon->edges != polygon->edges_embedded) + free (polygon->edges); +} + +static void +_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, + struct edge *e, + int y) +{ + struct edge **ptail = &polygon->y_buckets[y - polygon->ymin]; + if (*ptail) + (*ptail)->prev = e; + e->next = *ptail; + e->prev = NULL; + *ptail = e; +} + +inline static void +polygon_add_edge (struct polygon *polygon, + const cairo_edge_t *edge) +{ + struct edge *e; + cairo_fixed_t dx; + cairo_fixed_t dy; + int y, ytop, ybot; + int ymin = polygon->ymin; + int ymax = polygon->ymax; + + y = I(edge->top); + ytop = MAX(y, ymin); + + y = I(edge->bottom); + ybot = MIN(y, ymax); + + if (ybot <= ytop) + return; + + e = polygon->edges + polygon->num_edges++; + e->height_left = ybot - ytop; + e->dir = edge->dir; + + dx = edge->line.p2.x - edge->line.p1.x; + dy = edge->line.p2.y - edge->line.p1.y; + + if (dx == 0) { + e->vertical = TRUE; + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + e->dxdy.quo = 0; + e->dxdy.rem = 0; + e->dy = 0; + } else { + e->vertical = FALSE; + e->dxdy = floored_muldivrem (dx, CAIRO_FIXED_ONE, dy); + e->dy = dy; + + e->x = floored_muldivrem (ytop * CAIRO_FIXED_ONE + CAIRO_FIXED_FRAC_MASK/2 - edge->line.p1.y, + dx, dy); + e->x.quo += edge->line.p1.x; + } + e->x.rem -= dy; + + _polygon_insert_edge_into_its_y_bucket (polygon, e, ytop); +} + +static struct edge * +merge_sorted_edges (struct edge *head_a, struct edge *head_b) +{ + struct edge *head, **next, *prev; + int32_t x; + + prev = head_a->prev; + next = &head; + if (head_a->x.quo <= head_b->x.quo) { + head = head_a; + } else { + head = head_b; + head_b->prev = prev; + goto start_with_b; + } + + do { + x = head_b->x.quo; + while (head_a != NULL && head_a->x.quo <= x) { + prev = head_a; + next = &head_a->next; + head_a = head_a->next; + } + + head_b->prev = prev; + *next = head_b; + if (head_a == NULL) + return head; + +start_with_b: + x = head_a->x.quo; + while (head_b != NULL && head_b->x.quo <= x) { + prev = head_b; + next = &head_b->next; + head_b = head_b->next; + } + + head_a->prev = prev; + *next = head_a; + if (head_b == NULL) + return head; + } while (1); +} + +static struct edge * +sort_edges (struct edge *list, + unsigned int level, + struct edge **head_out) +{ + struct edge *head_other, *remaining; + unsigned int i; + + head_other = list->next; + + if (head_other == NULL) { + *head_out = list; + return NULL; + } + + remaining = head_other->next; + if (list->x.quo <= head_other->x.quo) { + *head_out = list; + head_other->next = NULL; + } else { + *head_out = head_other; + head_other->prev = list->prev; + head_other->next = list; + list->prev = head_other; + list->next = NULL; + } + + for (i = 0; i < level && remaining; i++) { + remaining = sort_edges (remaining, i, &head_other); + *head_out = merge_sorted_edges (*head_out, head_other); + } + + return remaining; +} + +static struct edge * +merge_unsorted_edges (struct edge *head, struct edge *unsorted) +{ + sort_edges (unsorted, UINT_MAX, &unsorted); + return merge_sorted_edges (head, unsorted); +} + +inline static void +active_list_merge_edges (struct mono_scan_converter *c, struct edge *edges) +{ + struct edge *e; + + for (e = edges; c->is_vertical && e; e = e->next) + c->is_vertical = e->vertical; + + c->head.next = merge_unsorted_edges (c->head.next, edges); +} + +inline static void +add_span (struct mono_scan_converter *c, int x1, int x2) +{ + int n; + + if (x1 < c->xmin) + x1 = c->xmin; + if (x2 > c->xmax) + x2 = c->xmax; + if (x2 <= x1) + return; + + n = c->num_spans++; + c->spans[n].x = x1; + c->spans[n].coverage = 255; + + n = c->num_spans++; + c->spans[n].x = x2; + c->spans[n].coverage = 0; +} + +inline static void +row (struct mono_scan_converter *c, unsigned int mask) +{ + struct edge *edge = c->head.next; + int xstart = INT_MIN, prev_x = INT_MIN; + int winding = 0; + + c->num_spans = 0; + while (&c->tail != edge) { + struct edge *next = edge->next; + int xend = I(edge->x.quo); + + if (--edge->height_left) { + if (!edge->vertical) { + edge->x.quo += edge->dxdy.quo; + edge->x.rem += edge->dxdy.rem; + if (edge->x.rem >= 0) { + ++edge->x.quo; + edge->x.rem -= edge->dy; + } + } + + if (edge->x.quo < prev_x) { + struct edge *pos = edge->prev; + pos->next = next; + next->prev = pos; + do { + pos = pos->prev; + } while (edge->x.quo < pos->x.quo); + pos->next->prev = edge; + edge->next = pos->next; + edge->prev = pos; + pos->next = edge; + } else + prev_x = edge->x.quo; + } else { + edge->prev->next = next; + next->prev = edge->prev; + } + + winding += edge->dir; + if ((winding & mask) == 0) { + if (I(next->x.quo) > xend + 1) { + add_span (c, xstart, xend); + xstart = INT_MIN; + } + } else if (xstart == INT_MIN) + xstart = xend; + + edge = next; + } +} + +inline static void dec (struct edge *e, int h) +{ + e->height_left -= h; + if (e->height_left == 0) { + e->prev->next = e->next; + e->next->prev = e->prev; + } +} + +static cairo_status_t +_mono_scan_converter_init(struct mono_scan_converter *c, + int xmin, int ymin, + int xmax, int ymax) +{ + cairo_status_t status; + int max_num_spans; + + status = polygon_init (c->polygon, ymin, ymax); + if (unlikely (status)) + return status; + + max_num_spans = xmax - xmin + 1; + if (max_num_spans > ARRAY_LENGTH(c->spans_embedded)) { + c->spans = _cairo_malloc_ab (max_num_spans, + sizeof (cairo_half_open_span_t)); + if (unlikely (c->spans == NULL)) { + polygon_fini (c->polygon); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } else + c->spans = c->spans_embedded; + + c->xmin = xmin; + c->xmax = xmax; + c->ymin = ymin; + c->ymax = ymax; + + c->head.vertical = 1; + c->head.height_left = INT_MAX; + c->head.x.quo = _cairo_fixed_from_int (_cairo_fixed_integer_part (INT_MIN)); + c->head.prev = NULL; + c->head.next = &c->tail; + c->tail.prev = &c->head; + c->tail.next = NULL; + c->tail.x.quo = _cairo_fixed_from_int (_cairo_fixed_integer_part (INT_MAX)); + c->tail.height_left = INT_MAX; + c->tail.vertical = 1; + + c->is_vertical = 1; + return CAIRO_STATUS_SUCCESS; +} + +static void +_mono_scan_converter_fini(struct mono_scan_converter *self) +{ + if (self->spans != self->spans_embedded) + free (self->spans); + + polygon_fini(self->polygon); +} + +static cairo_status_t +mono_scan_converter_allocate_edges(struct mono_scan_converter *c, + int num_edges) + +{ + c->polygon->num_edges = 0; + c->polygon->edges = c->polygon->edges_embedded; + if (num_edges > ARRAY_LENGTH (c->polygon->edges_embedded)) { + c->polygon->edges = _cairo_malloc_ab (num_edges, sizeof (struct edge)); + if (unlikely (c->polygon->edges == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +mono_scan_converter_add_edge (struct mono_scan_converter *c, + const cairo_edge_t *edge) +{ + polygon_add_edge (c->polygon, edge); +} + +static void +step_edges (struct mono_scan_converter *c, int count) +{ + struct edge *edge; + + for (edge = c->head.next; edge != &c->tail; edge = edge->next) { + edge->height_left -= count; + if (! edge->height_left) { + edge->prev->next = edge->next; + edge->next->prev = edge->prev; + } + } +} + +static cairo_status_t +mono_scan_converter_render(struct mono_scan_converter *c, + unsigned int winding_mask, + cairo_span_renderer_t *renderer) +{ + struct polygon *polygon = c->polygon; + int i, j, h = c->ymax - c->ymin; + cairo_status_t status; + + for (i = 0; i < h; i = j) { + j = i + 1; + + if (polygon->y_buckets[i]) + active_list_merge_edges (c, polygon->y_buckets[i]); + + if (c->is_vertical) { + int min_height; + struct edge *e; + + e = c->head.next; + min_height = e->height_left; + while (e != &c->tail) { + if (e->height_left < min_height) + min_height = e->height_left; + e = e->next; + } + + while (--min_height >= 1 && polygon->y_buckets[j] == NULL) + j++; + if (j != i + 1) + step_edges (c, j - (i + 1)); + } + + row (c, winding_mask); + if (c->num_spans) { + status = renderer->render_rows (renderer, c->ymin+i, j-i, + c->spans, c->num_spans); + if (unlikely (status)) + return status; + } + + /* XXX recompute after dropping edges? */ + if (c->head.next == &c->tail) + c->is_vertical = 1; + } + + return CAIRO_STATUS_SUCCESS; +} + +struct _cairo_mono_scan_converter { + cairo_scan_converter_t base; + + struct mono_scan_converter converter[1]; + cairo_fill_rule_t fill_rule; +}; + +typedef struct _cairo_mono_scan_converter cairo_mono_scan_converter_t; + +static void +_cairo_mono_scan_converter_destroy (void *converter) +{ + cairo_mono_scan_converter_t *self = converter; + _mono_scan_converter_fini (self->converter); + free(self); +} + +cairo_status_t +_cairo_mono_scan_converter_add_polygon (void *converter, + const cairo_polygon_t *polygon) +{ + cairo_mono_scan_converter_t *self = converter; + cairo_status_t status; + int i; + +#if 0 + FILE *file = fopen ("polygon.txt", "w"); + _cairo_debug_print_polygon (file, polygon); + fclose (file); +#endif + + status = mono_scan_converter_allocate_edges (self->converter, + polygon->num_edges); + if (unlikely (status)) + return status; + + for (i = 0; i < polygon->num_edges; i++) + mono_scan_converter_add_edge (self->converter, &polygon->edges[i]); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_mono_scan_converter_generate (void *converter, + cairo_span_renderer_t *renderer) +{ + cairo_mono_scan_converter_t *self = converter; + + return mono_scan_converter_render (self->converter, + self->fill_rule == CAIRO_FILL_RULE_WINDING ? ~0 : 1, + renderer); +} + +cairo_scan_converter_t * +_cairo_mono_scan_converter_create (int xmin, + int ymin, + int xmax, + int ymax, + cairo_fill_rule_t fill_rule) +{ + cairo_mono_scan_converter_t *self; + cairo_status_t status; + + self = malloc (sizeof(struct _cairo_mono_scan_converter)); + if (unlikely (self == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto bail_nomem; + } + + self->base.destroy = _cairo_mono_scan_converter_destroy; + self->base.generate = _cairo_mono_scan_converter_generate; + + status = _mono_scan_converter_init (self->converter, + xmin, ymin, xmax, ymax); + if (unlikely (status)) + goto bail; + + self->fill_rule = fill_rule; + + return &self->base; + + bail: + self->base.destroy(&self->base); + bail_nomem: + return _cairo_scan_converter_create_in_error (status); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mutex-impl-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-impl-private.h new file mode 100644 index 00000000000..25223f3eac0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-impl-private.h @@ -0,0 +1,278 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005,2007 Red Hat, Inc. + * Copyright © 2007 Mathias Hasselmann + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Mathias Hasselmann + * Behdad Esfahbod + */ + +#ifndef CAIRO_MUTEX_IMPL_PRIVATE_H +#define CAIRO_MUTEX_IMPL_PRIVATE_H + +#include "cairo.h" + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#if HAVE_LOCKDEP +#include +#endif + +/* A fully qualified no-operation statement */ +#define CAIRO_MUTEX_IMPL_NOOP do {/*no-op*/} while (0) +/* And one that evaluates its argument once */ +#define CAIRO_MUTEX_IMPL_NOOP1(expr) do { (void)(expr); } while (0) +/* Note: 'if (expr) {}' is an alternative to '(void)(expr);' that will 'use' the + * result of __attribute__((warn_used_result)) functions. */ + +/* Cairo mutex implementation: + * + * Any new mutex implementation needs to do the following: + * + * - Condition on the right header or feature. Headers are + * preferred as eg. you still can use win32 mutex implementation + * on a win32 system even if you do not compile the win32 + * surface/backend. + * + * - typedef #cairo_mutex_impl_t to the proper mutex type on your target + * system. Note that you may or may not need to use a pointer, + * depending on what kinds of initialization your mutex + * implementation supports. No trailing semicolon needed. + * You should be able to compile the following snippet (don't try + * running it): + * + * + * cairo_mutex_impl_t _cairo_some_mutex; + * + * + * - #define %CAIRO_MUTEX_IMPL_ 1 with suitable name for your platform. You + * can later use this symbol in cairo-system.c. + * + * - #define CAIRO_MUTEX_IMPL_LOCK(mutex) and CAIRO_MUTEX_IMPL_UNLOCK(mutex) to + * proper statement to lock/unlock the mutex object passed in. + * You can (and should) assume that the mutex is already + * initialized, and is-not-already-locked/is-locked, + * respectively. Use the "do { ... } while (0)" idiom if necessary. + * No trailing semicolons are needed (in any macro you define here). + * You should be able to compile the following snippet: + * + * + * cairo_mutex_impl_t _cairo_some_mutex; + * + * if (1) + * CAIRO_MUTEX_IMPL_LOCK (_cairo_some_mutex); + * else + * CAIRO_MUTEX_IMPL_UNLOCK (_cairo_some_mutex); + * + * + * - #define %CAIRO_MUTEX_IMPL_NIL_INITIALIZER to something that can + * initialize the #cairo_mutex_impl_t type you defined. Most of the + * time one of 0, %NULL, or {} works. At this point + * you should be able to compile the following snippet: + * + * + * cairo_mutex_impl_t _cairo_some_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; + * + * if (1) + * CAIRO_MUTEX_IMPL_LOCK (_cairo_some_mutex); + * else + * CAIRO_MUTEX_IMPL_UNLOCK (_cairo_some_mutex); + * + * + * - If the above code is not enough to initialize a mutex on + * your platform, #define CAIRO_MUTEX_IMPL_INIT(mutex) to statement + * to initialize the mutex (allocate resources, etc). Such that + * you should be able to compile AND RUN the following snippet: + * + * + * cairo_mutex_impl_t _cairo_some_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; + * + * CAIRO_MUTEX_IMPL_INIT (_cairo_some_mutex); + * + * if (1) + * CAIRO_MUTEX_IMPL_LOCK (_cairo_some_mutex); + * else + * CAIRO_MUTEX_IMPL_UNLOCK (_cairo_some_mutex); + * + * + * - If you define CAIRO_MUTEX_IMPL_INIT(mutex), cairo will use it to + * initialize all static mutex'es. If for any reason that should + * not happen (eg. %CAIRO_MUTEX_IMPL_INIT is just a faster way than + * what cairo does using %CAIRO_MUTEX_IMPL_NIL_INITIALIZER), then + * + * #define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP + * + * + * - If your system supports freeing a mutex object (deallocating + * resources, etc), then #define CAIRO_MUTEX_IMPL_FINI(mutex) to do + * that. + * + * - If you define CAIRO_MUTEX_IMPL_FINI(mutex), cairo will use it to + * define a finalizer function to finalize all static mutex'es. + * However, it's up to you to call CAIRO_MUTEX_IMPL_FINALIZE() at + * proper places, eg. when the system is unloading the cairo library. + * So, if for any reason finalizing static mutex'es is not needed + * (eg. you never call CAIRO_MUTEX_IMPL_FINALIZE()), then + * + * #define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP + * + * + * - That is all. If for any reason you think the above API is + * not enough to implement #cairo_mutex_impl_t on your system, please + * stop and write to the cairo mailing list about it. DO NOT + * poke around cairo-mutex-private.h for possible solutions. + */ + +#if CAIRO_NO_MUTEX + +/* No mutexes */ + + typedef int cairo_mutex_impl_t; + +# define CAIRO_MUTEX_IMPL_NO 1 +# define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP +# define CAIRO_MUTEX_IMPL_LOCK(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) +# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) +# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER 0 + +# define CAIRO_MUTEX_HAS_RECURSIVE_IMPL 1 + + typedef int cairo_recursive_mutex_impl_t; + +# define CAIRO_RECURSIVE_MUTEX_IMPL_INIT(mutex) +# define CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER 0 + +#elif defined(_WIN32) /******************************************************/ + +#define WIN32_LEAN_AND_MEAN +/* We require Windows 2000 features such as ETO_PDY */ +#if !defined(WINVER) || (WINVER < 0x0500) +# define WINVER 0x0500 +#endif +#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) +# define _WIN32_WINNT 0x0500 +#endif + +# include + + typedef CRITICAL_SECTION cairo_mutex_impl_t; + +# define CAIRO_MUTEX_IMPL_WIN32 1 +# define CAIRO_MUTEX_IMPL_LOCK(mutex) EnterCriticalSection (&(mutex)) +# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) LeaveCriticalSection (&(mutex)) +# define CAIRO_MUTEX_IMPL_INIT(mutex) InitializeCriticalSection (&(mutex)) +# define CAIRO_MUTEX_IMPL_FINI(mutex) DeleteCriticalSection (&(mutex)) +# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 } + +#elif defined __OS2__ /******************************************************/ + +# define INCL_BASE +# define INCL_PM +# include + + typedef HMTX cairo_mutex_impl_t; + +# define CAIRO_MUTEX_IMPL_OS2 1 +# define CAIRO_MUTEX_IMPL_LOCK(mutex) DosRequestMutexSem(mutex, SEM_INDEFINITE_WAIT) +# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) DosReleaseMutexSem(mutex) +# define CAIRO_MUTEX_IMPL_INIT(mutex) DosCreateMutexSem (NULL, &(mutex), 0L, FALSE) +# define CAIRO_MUTEX_IMPL_FINI(mutex) DosCloseMutexSem (mutex) +# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER 0 + +#elif CAIRO_HAS_BEOS_SURFACE /***********************************************/ + + typedef BLocker* cairo_mutex_impl_t; + +# define CAIRO_MUTEX_IMPL_BEOS 1 +# define CAIRO_MUTEX_IMPL_LOCK(mutex) (mutex)->Lock() +# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) (mutex)->Unlock() +# define CAIRO_MUTEX_IMPL_INIT(mutex) (mutex) = new BLocker() +# define CAIRO_MUTEX_IMPL_FINI(mutex) delete (mutex) +# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER NULL + +#elif CAIRO_HAS_PTHREAD /* and finally if there are no native mutexes ********/ + +# include + + typedef pthread_mutex_t cairo_mutex_impl_t; + typedef pthread_mutex_t cairo_recursive_mutex_impl_t; + +# define CAIRO_MUTEX_IMPL_PTHREAD 1 +#if HAVE_LOCKDEP +/* expose all mutexes to the validator */ +# define CAIRO_MUTEX_IMPL_INIT(mutex) pthread_mutex_init (&(mutex), NULL) +#endif +# define CAIRO_MUTEX_IMPL_LOCK(mutex) pthread_mutex_lock (&(mutex)) +# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) +#if HAVE_LOCKDEP +# define CAIRO_MUTEX_IS_LOCKED(mutex) LOCKDEP_IS_LOCKED (&(mutex)) +# define CAIRO_MUTEX_IS_UNLOCKED(mutex) LOCKDEP_IS_UNLOCKED (&(mutex)) +#endif +# define CAIRO_MUTEX_IMPL_FINI(mutex) pthread_mutex_destroy (&(mutex)) +#if ! HAVE_LOCKDEP +# define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP +#endif +# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER + +# define CAIRO_MUTEX_HAS_RECURSIVE_IMPL 1 +# define CAIRO_RECURSIVE_MUTEX_IMPL_INIT(mutex) do { \ + pthread_mutexattr_t attr; \ + pthread_mutexattr_init (&attr); \ + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); \ + pthread_mutex_init (&(mutex), &attr); \ + pthread_mutexattr_destroy (&attr); \ +} while (0) +# define CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +#else /**********************************************************************/ + +# error "XXX: No mutex implementation found. Cairo will not work with multiple threads. Define CAIRO_NO_MUTEX to 1 to acknowledge and accept this limitation and compile cairo without thread-safety support." + +#endif + +/* By default mutex implementations are assumed to be recursive */ +#if ! CAIRO_MUTEX_HAS_RECURSIVE_IMPL + +# define CAIRO_MUTEX_HAS_RECURSIVE_IMPL 1 + + typedef cairo_mutex_impl_t cairo_recursive_mutex_impl_t; + +# define CAIRO_RECURSIVE_MUTEX_IMPL_INIT(mutex) CAIRO_MUTEX_IMPL_INIT(mutex) +# define CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER CAIRO_MUTEX_IMPL_NIL_INITIALIZER + +#endif + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mutex-list-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-list-private.h new file mode 100644 index 00000000000..f46afadb04b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-list-private.h @@ -0,0 +1,78 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Mathias Hasselmann + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Mathias Hasselmann + */ + +#ifndef CAIRO_FEATURES_H +/* This block is to just make this header file standalone */ +#define CAIRO_MUTEX_DECLARE(mutex) +#endif + +CAIRO_MUTEX_DECLARE (_cairo_pattern_solid_surface_cache_lock) + +CAIRO_MUTEX_DECLARE (_cairo_image_solid_cache_mutex) + +CAIRO_MUTEX_DECLARE (_cairo_toy_font_face_mutex) +CAIRO_MUTEX_DECLARE (_cairo_intern_string_mutex) +CAIRO_MUTEX_DECLARE (_cairo_scaled_font_map_mutex) +CAIRO_MUTEX_DECLARE (_cairo_scaled_glyph_page_cache_mutex) +CAIRO_MUTEX_DECLARE (_cairo_scaled_font_error_mutex) +CAIRO_MUTEX_DECLARE (_cairo_glyph_cache_mutex) + +#if CAIRO_HAS_FT_FONT +CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_font_map_mutex) +#endif + +#if CAIRO_HAS_WIN32_FONT +CAIRO_MUTEX_DECLARE (_cairo_win32_font_face_mutex) +#endif + +#if CAIRO_HAS_XLIB_SURFACE +CAIRO_MUTEX_DECLARE (_cairo_xlib_display_mutex) +#endif + +#if CAIRO_HAS_XCB_SURFACE +CAIRO_MUTEX_DECLARE (_cairo_xcb_connections_mutex) +#endif + +#if CAIRO_HAS_GL_SURFACE +CAIRO_MUTEX_DECLARE (_cairo_gl_context_mutex) +#endif + +#if !defined (HAS_ATOMIC_OPS) || defined (ATOMIC_OP_NEEDS_MEMORY_BARRIER) +CAIRO_MUTEX_DECLARE (_cairo_atomic_mutex) +#endif + +#if CAIRO_HAS_DRM_SURFACE +CAIRO_MUTEX_DECLARE (_cairo_drm_device_mutex) +#endif +/* Undefine, to err on unintended inclusion */ +#undef CAIRO_MUTEX_DECLARE diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mutex-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-private.h new file mode 100644 index 00000000000..61a7160a066 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-private.h @@ -0,0 +1,67 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005,2007 Red Hat, Inc. + * Copyright © 2007 Mathias Hasselmann + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Mathias Hasselmann + * Behdad Esfahbod + */ + +#ifndef CAIRO_MUTEX_PRIVATE_H +#define CAIRO_MUTEX_PRIVATE_H + +#include "cairo-mutex-type-private.h" + +CAIRO_BEGIN_DECLS + +#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER +cairo_private void _cairo_mutex_initialize (void); +#endif +#if _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER +cairo_private void _cairo_mutex_finalize (void); +#endif +/* only if using static initializer and/or finalizer define the boolean */ +#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER + cairo_private extern cairo_bool_t _cairo_mutex_initialized; +#endif + +/* Finally, extern the static mutexes and undef */ + +#define CAIRO_MUTEX_DECLARE(mutex) cairo_private extern cairo_mutex_t mutex; +#include "cairo-mutex-list-private.h" +#undef CAIRO_MUTEX_DECLARE + +CAIRO_END_DECLS + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mutex-type-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-type-private.h new file mode 100644 index 00000000000..e8c493985c9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mutex-type-private.h @@ -0,0 +1,194 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005,2007 Red Hat, Inc. + * Copyright © 2007 Mathias Hasselmann + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Mathias Hasselmann + * Behdad Esfahbod + */ + +#ifndef CAIRO_MUTEX_TYPE_PRIVATE_H +#define CAIRO_MUTEX_TYPE_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-mutex-impl-private.h" + +/* Only the following four are mandatory at this point */ +#ifndef CAIRO_MUTEX_IMPL_LOCK +# error "CAIRO_MUTEX_IMPL_LOCK not defined. Check cairo-mutex-impl-private.h." +#endif +#ifndef CAIRO_MUTEX_IMPL_UNLOCK +# error "CAIRO_MUTEX_IMPL_UNLOCK not defined. Check cairo-mutex-impl-private.h." +#endif +#ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER +# error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined. Check cairo-mutex-impl-private.h." +#endif +#ifndef CAIRO_RECURSIVE_MUTEX_IMPL_INIT +# error "CAIRO_RECURSIVE_MUTEX_IMPL_INIT not defined. Check cairo-mutex-impl-private.h." +#endif + + +/* make sure implementations don't fool us: we decide these ourself */ +#undef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER +#undef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER + + +#ifdef CAIRO_MUTEX_IMPL_INIT + +/* If %CAIRO_MUTEX_IMPL_INIT is defined, we may need to initialize all + * static mutex'es. */ +# ifndef CAIRO_MUTEX_IMPL_INITIALIZE +# define CAIRO_MUTEX_IMPL_INITIALIZE() do { \ + if (!_cairo_mutex_initialized) \ + _cairo_mutex_initialize (); \ + } while(0) + +/* and make sure we implement the above */ +# define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 1 +# endif /* CAIRO_MUTEX_IMPL_INITIALIZE */ + +#else /* no CAIRO_MUTEX_IMPL_INIT */ + +/* Otherwise we probably don't need to initialize static mutex'es, */ +# ifndef CAIRO_MUTEX_IMPL_INITIALIZE +# define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP +# endif /* CAIRO_MUTEX_IMPL_INITIALIZE */ + +/* and dynamic ones can be initialized using the static initializer. */ +# define CAIRO_MUTEX_IMPL_INIT(mutex) do { \ + cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; \ + memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \ + } while (0) + +#endif /* CAIRO_MUTEX_IMPL_INIT */ + +#ifdef CAIRO_MUTEX_IMPL_FINI + +/* If %CAIRO_MUTEX_IMPL_FINI is defined, we may need to finalize all + * static mutex'es. */ +# ifndef CAIRO_MUTEX_IMPL_FINALIZE +# define CAIRO_MUTEX_IMPL_FINALIZE() do { \ + if (_cairo_mutex_initialized) \ + _cairo_mutex_finalize (); \ + } while(0) + +/* and make sure we implement the above */ +# define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 1 +# endif /* CAIRO_MUTEX_IMPL_FINALIZE */ + +#else /* no CAIRO_MUTEX_IMPL_FINI */ + +/* Otherwise we probably don't need to finalize static mutex'es, */ +# ifndef CAIRO_MUTEX_IMPL_FINALIZE +# define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP +# endif /* CAIRO_MUTEX_IMPL_FINALIZE */ + +/* neither do the dynamic ones. */ +# define CAIRO_MUTEX_IMPL_FINI(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) + +#endif /* CAIRO_MUTEX_IMPL_FINI */ + + +#ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER +#define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 0 +#endif +#ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER +#define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 0 +#endif + + +/* Make sure everything we want is defined */ +#ifndef CAIRO_MUTEX_IMPL_INITIALIZE +# error "CAIRO_MUTEX_IMPL_INITIALIZE not defined" +#endif +#ifndef CAIRO_MUTEX_IMPL_FINALIZE +# error "CAIRO_MUTEX_IMPL_FINALIZE not defined" +#endif +#ifndef CAIRO_MUTEX_IMPL_LOCK +# error "CAIRO_MUTEX_IMPL_LOCK not defined" +#endif +#ifndef CAIRO_MUTEX_IMPL_UNLOCK +# error "CAIRO_MUTEX_IMPL_UNLOCK not defined" +#endif +#ifndef CAIRO_MUTEX_IMPL_INIT +# error "CAIRO_MUTEX_IMPL_INIT not defined" +#endif +#ifndef CAIRO_MUTEX_IMPL_FINI +# error "CAIRO_MUTEX_IMPL_FINI not defined" +#endif +#ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER +# error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined" +#endif + + +/* Public interface. */ + +/* By default it simply uses the implementation provided. + * But we can provide for debugging features by overriding them */ + +#ifndef CAIRO_MUTEX_DEBUG +typedef cairo_mutex_impl_t cairo_mutex_t; +typedef cairo_recursive_mutex_impl_t cairo_recursive_mutex_t; +#else +# define cairo_mutex_t cairo_mutex_impl_t +#endif + +#define CAIRO_MUTEX_INITIALIZE CAIRO_MUTEX_IMPL_INITIALIZE +#define CAIRO_MUTEX_FINALIZE CAIRO_MUTEX_IMPL_FINALIZE +#define CAIRO_MUTEX_LOCK CAIRO_MUTEX_IMPL_LOCK +#define CAIRO_MUTEX_UNLOCK CAIRO_MUTEX_IMPL_UNLOCK +#define CAIRO_MUTEX_INIT CAIRO_MUTEX_IMPL_INIT +#define CAIRO_MUTEX_FINI CAIRO_MUTEX_IMPL_FINI +#define CAIRO_MUTEX_NIL_INITIALIZER CAIRO_MUTEX_IMPL_NIL_INITIALIZER + +#define CAIRO_RECURSIVE_MUTEX_INIT CAIRO_RECURSIVE_MUTEX_IMPL_INIT +#define CAIRO_RECURSIVE_MUTEX_NIL_INITIALIZER CAIRO_RECURSIVE_MUTEX_IMPL_NIL_INITIALIZER + +#ifndef CAIRO_MUTEX_IS_LOCKED +# define CAIRO_MUTEX_IS_LOCKED(name) 1 +#endif +#ifndef CAIRO_MUTEX_IS_UNLOCKED +# define CAIRO_MUTEX_IS_UNLOCKED(name) 1 +#endif + + +/* Debugging support */ + +#ifdef CAIRO_MUTEX_DEBUG + +/* TODO add mutex debugging facilities here (eg deadlock detection) */ + +#endif /* CAIRO_MUTEX_DEBUG */ + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-mutex.c b/Build/source/libs/cairo/cairo-src/src/cairo-mutex.c new file mode 100644 index 00000000000..0a31dced3e1 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-mutex.c @@ -0,0 +1,82 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Mathias Hasselmann + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Mathias Hasselmann + */ + +#include "cairoint.h" + +#include "cairo-mutex-private.h" + +#define CAIRO_MUTEX_DECLARE(mutex) cairo_mutex_t mutex = CAIRO_MUTEX_NIL_INITIALIZER; +#include "cairo-mutex-list-private.h" +#undef CAIRO_MUTEX_DECLARE + +#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER + +# if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER +# define _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE FALSE +# else +# define _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE TRUE +# endif + +cairo_bool_t _cairo_mutex_initialized = _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE; + +# undef _CAIRO_MUTEX_IMPL_INITIALIZED_DEFAULT_VALUE + +#endif + +#if _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER +void _cairo_mutex_initialize (void) +{ + if (_cairo_mutex_initialized) + return; + + _cairo_mutex_initialized = TRUE; + +#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (mutex); +#include "cairo-mutex-list-private.h" +#undef CAIRO_MUTEX_DECLARE +} +#endif + +#if _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER +void _cairo_mutex_finalize (void) +{ + if (!_cairo_mutex_initialized) + return; + + _cairo_mutex_initialized = FALSE; + +#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_FINI (mutex); +#include "cairo-mutex-list-private.h" +#undef CAIRO_MUTEX_DECLARE +} +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-no-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-no-compositor.c new file mode 100644 index 00000000000..1602a12f63a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-no-compositor.c @@ -0,0 +1,107 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-compositor-private.h" + +static cairo_int_status_t +_cairo_no_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_no_compositor_mask (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents) +{ + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_no_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_no_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_no_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +const cairo_compositor_t __cairo_no_compositor = { + NULL, + _cairo_no_compositor_paint, + _cairo_no_compositor_mask, + _cairo_no_compositor_stroke, + _cairo_no_compositor_fill, + _cairo_no_compositor_glyphs, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-observer.c b/Build/source/libs/cairo/cairo-src/src/cairo-observer.c new file mode 100644 index 00000000000..36d6b93bd63 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-observer.c @@ -0,0 +1,52 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2010 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-list-inline.h" + +void +_cairo_observers_notify (cairo_list_t *observers, void *arg) +{ + cairo_observer_t *obs, *next; + + cairo_list_foreach_entry_safe (obs, next, + cairo_observer_t, + observers, link) + { + obs->callback (obs, arg); + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-os2-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-os2-private.h new file mode 100644 index 00000000000..829dd3c8d41 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-os2-private.h @@ -0,0 +1,67 @@ +/* vim: set sw=4 sts=4 et cin: */ +/* cairo - a vector graphics library with display and print output + * + * Copyright (c) 2005-2006 netlabs.org + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is + * Doodle + * + * Contributor(s): + * Peter Weilbacher + */ + +#ifndef CAIRO_OS2_PRIVATE_H +#define CAIRO_OS2_PRIVATE_H + +#include "cairo-os2.h" +#include "cairoint.h" + +typedef struct _cairo_os2_surface +{ + cairo_surface_t base; + + /* Mutex semaphore to protect private fields from concurrent access */ + HMTX hmtx_use_private_fields; + /* Private fields: */ + HPS hps_client_window; + HWND hwnd_client_window; + BITMAPINFO2 bitmap_info; + unsigned char *pixels; + cairo_image_surface_t *image_surface; + int pixel_array_lend_count; + HEV hev_pixel_array_came_back; + + RECTL rcl_dirty_area; + cairo_bool_t dirty_area_present; + + /* General flags: */ + cairo_bool_t blit_as_changes; + cairo_bool_t use_24bpp; +} cairo_os2_surface_t; + +#endif /* CAIRO_OS2_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-os2-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-os2-surface.c new file mode 100644 index 00000000000..1ab50f97798 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-os2-surface.c @@ -0,0 +1,1415 @@ +/* vim: set sw=4 sts=4 et cin: */ +/* cairo - a vector graphics library with display and print output + * + * Copyright (c) 2005-2006 netlabs.org + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is + * Doodle + * + * Contributor(s): + * Peter Weilbacher + * Rich Walsh + */ + +#include "cairoint.h" + +#include "cairo-os2-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-surface-fallback-private.h" +#include "cairo-image-surface-private.h" + +#if CAIRO_HAS_FC_FONT +#include +#endif + +#include +#ifdef BUILD_CAIRO_DLL +# include "cairo-os2.h" +# ifndef __WATCOMC__ +# include +# endif +#endif + +/* + * Here comes the extra API for the OS/2 platform. Currently it consists + * of two extra functions, the cairo_os2_init() and the + * cairo_os2_fini(). Both of them are called automatically if + * Cairo is compiled to be a DLL file, but you have to call them before + * using the Cairo API if you link to Cairo statically! + * + * You'll also find the code in here which deals with DLL initialization + * and termination, if the code is built to be a DLL. + * (if BUILD_CAIRO_DLL is defined) + */ + +/* Initialization counter: */ +static int cairo_os2_initialization_count = 0; + +static inline void +DisableFPUException (void) +{ + unsigned short usCW; + + /* Some OS/2 PM API calls modify the FPU Control Word, + * but forget to restore it. + * + * This can result in XCPT_FLOAT_INVALID_OPCODE exceptions, + * so to be sure, we disable Invalid Opcode FPU exception + * before using FPU stuffs. + */ + usCW = _control87 (0, 0); + usCW = usCW | EM_INVALID | 0x80; + _control87 (usCW, MCW_EM | 0x80); +} + +/** + * cairo_os2_init: + * + * Initializes the Cairo library. This function is automatically called if + * Cairo was compiled to be a DLL (however it's not a problem if it's called + * multiple times). But if you link to Cairo statically, you have to call it + * once to set up Cairo's internal structures and mutexes. + * + * Since: 1.4 + **/ +cairo_public void +cairo_os2_init (void) +{ + /* This may initialize some stuffs, like create mutex semaphores etc.. */ + + cairo_os2_initialization_count++; + if (cairo_os2_initialization_count > 1) return; + + DisableFPUException (); + +#if CAIRO_HAS_FC_FONT + /* Initialize FontConfig */ + FcInit (); +#endif + + CAIRO_MUTEX_INITIALIZE (); +} + +/** + * cairo_os2_fini: + * + * Uninitializes the Cairo library. This function is automatically called if + * Cairo was compiled to be a DLL (however it's not a problem if it's called + * multiple times). But if you link to Cairo statically, you have to call it + * once to shut down Cairo, to let it free all the resources it has allocated. + * + * Since: 1.4 + **/ +cairo_public void +cairo_os2_fini (void) +{ + /* This has to uninitialize some stuffs, like destroy mutex semaphores etc.. */ + + if (cairo_os2_initialization_count <= 0) return; + cairo_os2_initialization_count--; + if (cairo_os2_initialization_count > 0) return; + + DisableFPUException (); + + cairo_debug_reset_static_data (); + +#if CAIRO_HAS_FC_FONT +# if HAVE_FCFINI + /* Uninitialize FontConfig */ + FcFini (); +# endif +#endif + +#ifdef __WATCOMC__ + /* It can happen that the libraries we use have memory leaks, + * so there are still memory chunks allocated at this point. + * In these cases, Watcom might still have a bigger memory chunk, + * called "the heap" allocated from the OS. + * As we want to minimize the memory we lose from the point of + * view of the OS, we call this function to shrink that heap + * as much as possible. + */ + _heapshrink (); +#else + /* GCC has a heapmin function that approximately corresponds to + * what the Watcom function does + */ + _heapmin (); +#endif +} + +/* + * This function calls the allocation function depending on which + * method was compiled into the library: it can be native allocation + * (DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free). + * Actually, for pixel buffers that we use this function for, cairo + * uses _cairo_malloc_abc, so we use that here, too. And use the + * change to check the size argument + */ +void *_buffer_alloc (size_t a, size_t b, const unsigned int size) +{ + size_t nbytes; + void *buffer = NULL; + + if (!a || !b || !size || + a >= INT32_MAX / b || a*b >= INT32_MAX / size) { + return NULL; + } + nbytes = a * b * size; + +#ifdef OS2_USE_PLATFORM_ALLOC + /* Using OBJ_ANY on a machine that isn't configured for hi-mem + * will cause ERROR_INVALID_PARAMETER. If this occurs, or this + * build doesn't have hi-mem enabled, fall back to using lo-mem. + */ +#ifdef OS2_HIGH_MEMORY + if (!DosAllocMem (&buffer, nbytes, + OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT)) + return buffer; +#endif + if (DosAllocMem (&buffer, nbytes, + PAG_READ | PAG_WRITE | PAG_COMMIT)) + return NULL; +#else + /* Clear the malloc'd buffer the way DosAllocMem() does. */ + buffer = malloc (nbytes); + if (buffer) { + memset (buffer, 0, nbytes); + } +#endif + return buffer; +} + +/* + * This function selects the free function depending on which + * allocation method was compiled into the library + */ +void _buffer_free (void *buffer) +{ +#ifdef OS2_USE_PLATFORM_ALLOC + DosFreeMem (buffer); +#else + free (buffer); +#endif +} + +/* XXX + * The cairo_os2_ini() and cairo_os2_fini() functions should be removed and + * the LibMain code moved to cairo-system.c. It should also call + * cairo_debug_reset_static_data() instead of duplicating its logic... + */ + +#ifdef BUILD_CAIRO_DLL +/* The main DLL entry for DLL initialization and uninitialization */ +/* Only include this code if we're about to build a DLL. */ + +#ifdef __WATCOMC__ +unsigned _System +LibMain (unsigned hmod, + unsigned termination) +#else +unsigned long _System +_DLL_InitTerm (unsigned long hModule, + unsigned long termination) +#endif +{ + if (termination) { + /* Unloading the DLL */ + cairo_os2_fini (); + +#ifndef __WATCOMC__ + /* Uninitialize RTL of GCC */ + __ctordtorTerm (); + _CRT_term (); +#endif + return 1; + } else { + /* Loading the DLL */ +#ifndef __WATCOMC__ + /* Initialize RTL of GCC */ + if (_CRT_init () != 0) + return 0; + __ctordtorInit (); +#endif + + cairo_os2_init (); + return 1; + } +} + +#endif /* BUILD_CAIRO_DLL */ + +/* + * The following part of the source file contains the code which might + * be called the "core" of the OS/2 backend support. This contains the + * OS/2 surface support functions and structures. + */ + +/* Forward declaration */ +static const cairo_surface_backend_t cairo_os2_surface_backend; + +/* Unpublished API: + * GpiEnableYInversion = PMGPI.723 + * GpiQueryYInversion = PMGPI.726 + * BOOL APIENTRY GpiEnableYInversion (HPS hps, LONG lHeight); + * LONG APIENTRY GpiQueryYInversion (HPS hps); + */ +BOOL APIENTRY GpiEnableYInversion (HPS hps, LONG lHeight); +LONG APIENTRY GpiQueryYInversion (HPS hps); + +#ifdef __WATCOMC__ +/* Function declaration for GpiDrawBits () (missing from OpenWatcom headers) */ +LONG APIENTRY GpiDrawBits (HPS hps, + PVOID pBits, + PBITMAPINFO2 pbmiInfoTable, + LONG lCount, + PPOINTL aptlPoints, + LONG lRop, + ULONG flOptions); +#endif + +static void +_cairo_os2_surface_blit_pixels (cairo_os2_surface_t *surface, + HPS hps_begin_paint, + PRECTL prcl_begin_paint_rect) +{ + POINTL aptlPoints[4]; + LONG lOldYInversion; + LONG rc = GPI_OK; + + /* Check the limits (may not be necessary) */ + if (prcl_begin_paint_rect->xLeft < 0) + prcl_begin_paint_rect->xLeft = 0; + if (prcl_begin_paint_rect->yBottom < 0) + prcl_begin_paint_rect->yBottom = 0; + if (prcl_begin_paint_rect->xRight > (LONG) surface->bitmap_info.cx) + prcl_begin_paint_rect->xRight = (LONG) surface->bitmap_info.cx; + if (prcl_begin_paint_rect->yTop > (LONG) surface->bitmap_info.cy) + prcl_begin_paint_rect->yTop = (LONG) surface->bitmap_info.cy; + + /* Exit if the rectangle is empty */ + if (prcl_begin_paint_rect->xLeft >= prcl_begin_paint_rect->xRight || + prcl_begin_paint_rect->yBottom >= prcl_begin_paint_rect->yTop) + return; + + /* Set the Target & Source coordinates */ + *((PRECTL)&aptlPoints[0]) = *prcl_begin_paint_rect; + *((PRECTL)&aptlPoints[2]) = *prcl_begin_paint_rect; + + /* Make the Target coordinates non-inclusive */ + aptlPoints[1].x -= 1; + aptlPoints[1].y -= 1; + + /* Enable Y Inversion for the HPS, so GpiDrawBits will + * work with upside-top image, not with upside-down image! + */ + lOldYInversion = GpiQueryYInversion (hps_begin_paint); + GpiEnableYInversion (hps_begin_paint, surface->bitmap_info.cy-1); + + /* Debug code to draw rectangle limits */ +#if 0 + { + int x, y; + unsigned char *pixels; + + pixels = surface->pixels; + for (x = 0; x < surface->bitmap_info.cx; x++) { + for (y = 0; y < surface->bitmap_info.cy; y++) { + if ((x == 0) || + (y == 0) || + (x == y) || + (x >= surface->bitmap_info.cx-1) || + (y >= surface->bitmap_info.cy-1)) + { + pixels[y*surface->bitmap_info.cx*4+x*4] = 255; + } + } + } + } +#endif + if (!surface->use_24bpp) { + rc = GpiDrawBits (hps_begin_paint, + surface->pixels, + &(surface->bitmap_info), + 4, + aptlPoints, + ROP_SRCCOPY, + BBO_IGNORE); + if (rc != GPI_OK) + surface->use_24bpp = TRUE; + } + + if (surface->use_24bpp) { + /* If GpiDrawBits () failed then this is most likely because the + * display driver could not handle a 32bit bitmap. So we need to + * - create a buffer that only contains 3 bytes per pixel + * - change the bitmap info header to contain 24bit + * - pass the new buffer to GpiDrawBits () again + * - clean up the new buffer + */ + BITMAPINFO2 bmpinfo; + unsigned char *pchPixBuf; + unsigned char *pchTarget; + ULONG *pulSource; + ULONG ulX; + ULONG ulY; + ULONG ulPad; + + /* Set up the bitmap header, but this time for 24bit depth. */ + bmpinfo = surface->bitmap_info; + bmpinfo.cBitCount = 24; + + /* The start of each row has to be DWORD aligned. Calculate the + * of number aligned bytes per row, the total size of the bitmap, + * and the number of padding bytes at the end of each row. + */ + ulX = (((bmpinfo.cx * bmpinfo.cBitCount) + 31) / 32) * 4; + bmpinfo.cbImage = ulX * bmpinfo.cy; + ulPad = ulX - bmpinfo.cx * 3; + + /* Allocate temporary pixel buffer. If the rows don't need + * padding, it has to be 1 byte larger than the size of the + * bitmap or else the high-order byte from the last source + * row will end up in unallocated memory. + */ + pchPixBuf = (unsigned char *)_buffer_alloc (1, 1, + bmpinfo.cbImage + (ulPad ? 0 : 1)); + + if (pchPixBuf) { + /* Copy 4 bytes from the source but advance the target ptr only + * 3 bytes, so the high-order alpha byte will be overwritten by + * the next copy. At the end of each row, skip over the padding. + */ + pchTarget = pchPixBuf; + pulSource = (ULONG*)surface->pixels; + for (ulY = bmpinfo.cy; ulY; ulY--) { + for (ulX = bmpinfo.cx; ulX; ulX--) { + *((ULONG*)pchTarget) = *pulSource++; + pchTarget += 3; + } + pchTarget += ulPad; + } + + rc = GpiDrawBits (hps_begin_paint, + pchPixBuf, + &bmpinfo, + 4, + aptlPoints, + ROP_SRCCOPY, + BBO_IGNORE); + if (rc != GPI_OK) + surface->use_24bpp = FALSE; + + _buffer_free (pchPixBuf); + } + } + + /* Restore Y inversion */ + GpiEnableYInversion (hps_begin_paint, lOldYInversion); +} + +static void +_cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface, + HPS hps_begin_paint, + PRECTL prcl_begin_paint_rect) +{ + HPS hps; + HDC hdc; + SIZEL sizlTemp; + HBITMAP hbmpTemp; + BITMAPINFO2 bmi2Temp; + POINTL aptlPoints[4]; + int y; + unsigned char *pchTemp; + + /* To copy pixels from screen to our buffer, we do the following steps: + * + * - Blit pixels from screen to a HBITMAP: + * -- Create Memory Device Context + * -- Create a PS into it + * -- Create a HBITMAP + * -- Select HBITMAP into memory PS + * -- Blit dirty pixels from screen to HBITMAP + * - Copy HBITMAP lines (pixels) into our buffer + * - Free resources + */ + + /* Create a memory device context */ + hdc = DevOpenDC (0, OD_MEMORY,"*",0L, NULL, NULLHANDLE); + if (!hdc) { + return; + } + + /* Create a memory PS */ + sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft; + sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom; + hps = GpiCreatePS (0, + hdc, + &sizlTemp, + PU_PELS | GPIT_NORMAL | GPIA_ASSOC); + if (!hps) { + DevCloseDC (hdc); + return; + } + + /* Create an uninitialized bitmap. */ + /* Prepare BITMAPINFO2 structure for our buffer */ + memset (&bmi2Temp, 0, sizeof (bmi2Temp)); + bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2); + bmi2Temp.cx = sizlTemp.cx; + bmi2Temp.cy = sizlTemp.cy; + bmi2Temp.cPlanes = 1; + bmi2Temp.cBitCount = 32; + + hbmpTemp = GpiCreateBitmap (hps, + (PBITMAPINFOHEADER2) &bmi2Temp, + 0, + NULL, + NULL); + + if (!hbmpTemp) { + GpiDestroyPS (hps); + DevCloseDC (hdc); + return; + } + + /* Select the bitmap into the memory device context. */ + GpiSetBitmap (hps, hbmpTemp); + + /* Target coordinates (Noninclusive) */ + aptlPoints[0].x = 0; + aptlPoints[0].y = 0; + + aptlPoints[1].x = sizlTemp.cx; + aptlPoints[1].y = sizlTemp.cy; + + /* Source coordinates (Inclusive) */ + aptlPoints[2].x = prcl_begin_paint_rect->xLeft; + aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom; + + aptlPoints[3].x = prcl_begin_paint_rect->xRight; + aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop; + + /* Blit pixels from screen to bitmap */ + GpiBitBlt (hps, + hps_begin_paint, + 4, + aptlPoints, + ROP_SRCCOPY, + BBO_IGNORE); + + /* Now we have to extract the pixels from the bitmap. */ + pchTemp = + surface->pixels + + (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 + + prcl_begin_paint_rect->xLeft*4; + for (y = 0; y < sizlTemp.cy; y++) { + /* Get one line of pixels */ + GpiQueryBitmapBits (hps, + sizlTemp.cy - y - 1, /* lScanStart */ + 1, /* lScans */ + (PBYTE)pchTemp, + &bmi2Temp); + + /* Go for next line */ + pchTemp += surface->bitmap_info.cx*4; + } + + /* Clean up resources */ + GpiSetBitmap (hps, (HBITMAP) NULL); + GpiDeleteBitmap (hbmpTemp); + GpiDestroyPS (hps); + DevCloseDC (hdc); +} + +static cairo_status_t +_cairo_os2_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; + + DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); + + /* Increase lend counter */ + surface->pixel_array_lend_count++; + + *image_out = surface->image_surface; + *image_extra = NULL; + + DosReleaseMutexSem (surface->hmtx_use_private_fields); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_os2_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; + + /* Decrease Lend counter! */ + DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); + + if (surface->pixel_array_lend_count > 0) + surface->pixel_array_lend_count--; + DosPostEventSem (surface->hev_pixel_array_came_back); + + DosReleaseMutexSem (surface->hmtx_use_private_fields); +} + +static cairo_image_surface_t * +_cairo_os2_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; + + DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); + /* Increase lend counter */ + surface->pixel_array_lend_count++; + DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); + + /* XXX: BROKEN! */ + *image_out = _cairo_surface_create_for_rectangle_int (surface->image_surface, + extents); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_os2_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; + + /* So, we got back the image, and if all goes well, then + * something has been changed inside the interest_rect. + * So, we blit it to the screen! + */ + if (surface->blit_as_changes) { + RECTL rclToBlit; + + /* Get mutex, we'll work with the pixel array! */ + if (DosRequestMutexSem (surface->hmtx_use_private_fields, + SEM_INDEFINITE_WAIT) != NO_ERROR) + { + /* Could not get mutex! */ + return; + } + + rclToBlit.xLeft = image->base.device_transform_inverse.x0; + rclToBlit.xRight = rclToBlit.xLeft + image->width; /* Noninclusive */ + rclToBlit.yTop = image->base.device_transform_inverse.y0; + rclToBlit.yBottom = rclToBlit.yTop + image->height; /* Noninclusive */ + + if (surface->hwnd_client_window) { + /* We know the HWND, so let's invalidate the window region, + * so the application will redraw itself, using the + * cairo_os2_surface_refresh_window () API from its own PM thread. + * + * This is the safe method, which should be preferred every time. + */ + rclToBlit.yTop = surface->bitmap_info.cy - rclToBlit.yTop; + rclToBlit.yBottom = surface->bitmap_info.cy - rclToBlit.yTop; + WinInvalidateRect (surface->hwnd_client_window, + &rclToBlit, + FALSE); + } else { + /* We don't know the HWND, so try to blit the pixels from here! + * Please note that it can be problematic if this is not the PM thread! + * + * It can cause internal PM stuffs to be screwed up, for some reason. + * Please always tell the HWND to the surface using the + * cairo_os2_surface_set_hwnd () API, and call cairo_os2_surface_refresh_window () + * from your WM_PAINT, if it's possible! + */ + _cairo_os2_surface_blit_pixels (surface, + surface->hps_client_window, + &rclToBlit); + } + + DosReleaseMutexSem (surface->hmtx_use_private_fields); + } + /* Also decrease Lend counter! */ + DosRequestMutexSem (surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); + + if (surface->pixel_array_lend_count > 0) + surface->pixel_array_lend_count--; + DosPostEventSem (surface->hev_pixel_array_came_back); + + DosReleaseMutexSem (surface->hmtx_use_private_fields); +} + +static cairo_bool_t +_cairo_os2_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_os2_surface_t *surface = (cairo_os2_surface_t *) abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + rectangle->width = surface->bitmap_info.cx; + rectangle->height = surface->bitmap_info.cy; + + return TRUE; +} + +/** + * cairo_os2_surface_create: + * @hps_client_window: the presentation handle to bind the surface to + * @width: the width of the surface + * @height: the height of the surface + * + * Create a Cairo surface which is bound to a given presentation space (HPS). + * The caller retains ownership of the HPS and must dispose of it after the + * the surface has been destroyed. The surface will be created to have the + * given size. By default every change to the surface will be made visible + * immediately by blitting it into the window. This can be changed with + * cairo_os2_surface_set_manual_window_refresh(). + * Note that the surface will contain garbage when created, so the pixels + * have to be initialized by hand first. You can use the Cairo functions to + * fill it with black, or use cairo_surface_mark_dirty() to fill the surface + * with pixels from the window/HPS. + * + * Return value: the newly created surface + * + * Since: 1.4 + **/ +cairo_surface_t * +cairo_os2_surface_create (HPS hps_client_window, + int width, + int height) +{ + cairo_os2_surface_t *local_os2_surface = 0; + cairo_status_t status; + int rc; + + /* Check the size of the window */ + if ((width <= 0) || (height <= 0)) { + status = _cairo_error (CAIRO_STATUS_INVALID_SIZE); + goto error_exit; + } + + /* Allocate an OS/2 surface structure. */ + local_os2_surface = (cairo_os2_surface_t *) malloc (sizeof (cairo_os2_surface_t)); + if (!local_os2_surface) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto error_exit; + } + + memset(local_os2_surface, 0, sizeof(cairo_os2_surface_t)); + + /* Allocate resources: mutex & event semaphores and the pixel buffer */ + if (DosCreateMutexSem (NULL, + &(local_os2_surface->hmtx_use_private_fields), + 0, + FALSE)) + { + status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + goto error_exit; + } + + if (DosCreateEventSem (NULL, + &(local_os2_surface->hev_pixel_array_came_back), + 0, + FALSE)) + { + status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + goto error_exit; + } + + local_os2_surface->pixels = (unsigned char *) _buffer_alloc (height, width, 4); + if (!local_os2_surface->pixels) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto error_exit; + } + + /* Create image surface from pixel array */ + local_os2_surface->image_surface = (cairo_image_surface_t *) + cairo_image_surface_create_for_data (local_os2_surface->pixels, + CAIRO_FORMAT_ARGB32, + width, /* Width */ + height, /* Height */ + width * 4); /* Rowstride */ + status = local_os2_surface->image_surface->base.status; + if (status) + goto error_exit; + + /* Set values for OS/2-specific data that aren't zero/NULL/FALSE. + * Note: hps_client_window may be null if this was called by + * cairo_os2_surface_create_for_window(). + */ + local_os2_surface->hps_client_window = hps_client_window; + local_os2_surface->blit_as_changes = TRUE; + + /* Prepare BITMAPINFO2 structure for our buffer */ + local_os2_surface->bitmap_info.cbFix = sizeof (BITMAPINFOHEADER2); + local_os2_surface->bitmap_info.cx = width; + local_os2_surface->bitmap_info.cy = height; + local_os2_surface->bitmap_info.cPlanes = 1; + local_os2_surface->bitmap_info.cBitCount = 32; + + /* Initialize base surface */ + _cairo_surface_init (&local_os2_surface->base, + &cairo_os2_surface_backend, + NULL, /* device */ + _cairo_content_from_format (CAIRO_FORMAT_ARGB32)); + + /* Successful exit */ + return (cairo_surface_t *)local_os2_surface; + + error_exit: + + /* This point will only be reached if an error occurred */ + + if (local_os2_surface) { + if (local_os2_surface->pixels) + _buffer_free (local_os2_surface->pixels); + if (local_os2_surface->hev_pixel_array_came_back) + DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); + if (local_os2_surface->hmtx_use_private_fields) + DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); + free (local_os2_surface); + } + + return _cairo_surface_create_in_error (status); +} + +/** + * cairo_os2_surface_create_for_window: + * @hwnd_client_window: the window handle to bind the surface to + * @width: the width of the surface + * @height: the height of the surface + * + * Create a Cairo surface which is bound to a given window; the caller retains + * ownership of the window. This is a convenience function for use with + * windows that will only be updated when cairo_os2_surface_refresh_window() + * is called (usually in response to a WM_PAINT message). It avoids the need + * to create a persistent HPS for every window and assumes that one will be + * supplied by the caller when a cairo function needs one. If it isn't, an + * HPS will be created on-the-fly and released before the function which needs + * it returns. + * + * Return value: the newly created surface + * + * Since: 1.10 + **/ +cairo_surface_t * +cairo_os2_surface_create_for_window (HWND hwnd_client_window, + int width, + int height) +{ + cairo_os2_surface_t *local_os2_surface; + + /* A window handle must be provided. */ + if (!hwnd_client_window) { + return _cairo_surface_create_in_error ( + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + /* Create the surface. */ + local_os2_surface = (cairo_os2_surface_t *) + cairo_os2_surface_create (0, width, height); + + /* If successful, save the hwnd & turn off automatic repainting. */ + if (!local_os2_surface->image_surface->base.status) { + local_os2_surface->hwnd_client_window = hwnd_client_window; + local_os2_surface->blit_as_changes = FALSE; + } + + return (cairo_surface_t *)local_os2_surface; +} + +/** + * cairo_os2_surface_set_size: + * @surface: the cairo surface to resize + * @new_width: the new width of the surface + * @new_height: the new height of the surface + * @timeout: timeout value in milliseconds + * + * When the client window is resized, call this API to set the new size in the + * underlying surface accordingly. This function will reallocate everything, + * so you'll have to redraw everything in the surface after this call. + * The surface will contain garbage after the resizing. So the notes of + * cairo_os2_surface_create() apply here, too. + * + * The timeout value specifies how long the function should wait on other parts + * of the program to release the buffers. It is necessary, because it can happen + * that Cairo is just drawing something into the surface while we want to + * destroy and recreate it. + * + * Return value: %CAIRO_STATUS_SUCCESS if the surface could be resized, + * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface, + * %CAIRO_STATUS_INVALID_SIZE for invalid sizes + * %CAIRO_STATUS_NO_MEMORY if the new size could not be allocated, or if the + * timeout happened before all the buffers were released + * + * Since: 1.4 + **/ +int +cairo_os2_surface_set_size (cairo_surface_t *surface, + int new_width, + int new_height, + int timeout) +{ + cairo_os2_surface_t *local_os2_surface; + unsigned char *pchNewPixels; + int rc; + cairo_image_surface_t *pNewImageSurface; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + } + + if ((new_width <= 0) || + (new_height <= 0)) + { + /* Invalid size! */ + return _cairo_error (CAIRO_STATUS_INVALID_SIZE); + } + + /* Allocate memory for new stuffs */ + pchNewPixels = (unsigned char *) _buffer_alloc (new_height, new_width, 4); + if (!pchNewPixels) { + /* Not enough memory for the pixels! + * Everything remains the same! + */ + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + /* Create image surface from new pixel array */ + pNewImageSurface = (cairo_image_surface_t *) + cairo_image_surface_create_for_data (pchNewPixels, + CAIRO_FORMAT_ARGB32, + new_width, /* Width */ + new_height, /* Height */ + new_width * 4); /* Rowstride */ + + if (pNewImageSurface->base.status) { + /* Could not create image surface! + * Everything remains the same! + */ + _buffer_free (pchNewPixels); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + /* Okay, new memory allocated, so it's time to swap old buffers + * to new ones! + */ + if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)!=NO_ERROR) { + /* Could not get mutex! + * Everything remains the same! + */ + cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface); + _buffer_free (pchNewPixels); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + /* We have to make sure that we won't destroy a surface which + * is lent to some other code (Cairo is drawing into it)! + */ + while (local_os2_surface->pixel_array_lend_count > 0) { + ULONG ulPostCount; + DosResetEventSem (local_os2_surface->hev_pixel_array_came_back, &ulPostCount); + DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); + /* Wait for somebody to return the pixels! */ + rc = DosWaitEventSem (local_os2_surface->hev_pixel_array_came_back, timeout); + if (rc != NO_ERROR) { + /* Either timeout or something wrong... Exit. */ + cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface); + _buffer_free (pchNewPixels); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + /* Okay, grab mutex and check counter again! */ + if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) + != NO_ERROR) + { + /* Could not get mutex! + * Everything remains the same! + */ + cairo_surface_destroy ((cairo_surface_t *) pNewImageSurface); + _buffer_free (pchNewPixels); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + /* Destroy old image surface */ + cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface)); + /* Destroy old pixel buffer */ + _buffer_free (local_os2_surface->pixels); + /* Set new image surface */ + local_os2_surface->image_surface = pNewImageSurface; + /* Set new pixel buffer */ + local_os2_surface->pixels = pchNewPixels; + /* Change bitmap2 structure */ + local_os2_surface->bitmap_info.cx = new_width; + local_os2_surface->bitmap_info.cy = new_height; + + DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_os2_surface_refresh_window: + * @surface: the cairo surface to refresh + * @hps_begin_paint: the presentation handle of the window to refresh + * @prcl_begin_paint_rect: the rectangle to redraw + * + * This function can be used to force a repaint of a given area of the client + * window. It should usually be called from the WM_PAINT processing of the + * window procedure. However, it can be called any time a given part of the + * window has to be updated. + * + * The HPS and RECTL to be passed can be taken from the usual WinBeginPaint call + * of the window procedure, but you can also get the HPS using WinGetPS, and you + * can assemble your own update rectangle by hand. + * If hps_begin_paint is %NULL, the function will use the HPS passed into + * cairo_os2_surface_create(). If @prcl_begin_paint_rect is %NULL, the function + * will query the current window size and repaint the whole window. + * + * Cairo assumes that if you set the HWND to the surface using + * cairo_os2_surface_set_hwnd(), this function will be called by the application + * every time it gets a WM_PAINT for that HWND. If the HWND is set in the + * surface, Cairo uses this function to handle dirty areas too. + * + * Since: 1.4 + **/ +void +cairo_os2_surface_refresh_window (cairo_surface_t *surface, + HPS hps_begin_paint, + PRECTL prcl_begin_paint_rect) +{ + cairo_os2_surface_t *local_os2_surface; + RECTL rclTemp; + HPS hpsTemp = 0; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return; + } + + /* If an HPS wasn't provided, see if we can get one. */ + if (!hps_begin_paint) { + hps_begin_paint = local_os2_surface->hps_client_window; + if (!hps_begin_paint) { + if (local_os2_surface->hwnd_client_window) { + hpsTemp = WinGetPS(local_os2_surface->hwnd_client_window); + hps_begin_paint = hpsTemp; + } + /* No HPS & no way to get one, so exit */ + if (!hps_begin_paint) + return; + } + } + + if (prcl_begin_paint_rect == NULL) { + /* Update the whole window! */ + rclTemp.xLeft = 0; + rclTemp.xRight = local_os2_surface->bitmap_info.cx; + rclTemp.yTop = local_os2_surface->bitmap_info.cy; + rclTemp.yBottom = 0; + } else { + /* Use the rectangle we got passed as parameter! */ + rclTemp.xLeft = prcl_begin_paint_rect->xLeft; + rclTemp.xRight = prcl_begin_paint_rect->xRight; + rclTemp.yTop = local_os2_surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom; + rclTemp.yBottom = local_os2_surface->bitmap_info.cy - prcl_begin_paint_rect->yTop ; + } + + /* Get mutex, we'll work with the pixel array! */ + if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) + != NO_ERROR) + { + /* Could not get mutex! */ + if (hpsTemp) + WinReleasePS(hpsTemp); + return; + } + + if ((local_os2_surface->dirty_area_present) && + (local_os2_surface->rcl_dirty_area.xLeft == rclTemp.xLeft) && + (local_os2_surface->rcl_dirty_area.xRight == rclTemp.xRight) && + (local_os2_surface->rcl_dirty_area.yTop == rclTemp.yTop) && + (local_os2_surface->rcl_dirty_area.yBottom == rclTemp.yBottom)) + { + /* Aha, this call was because of a dirty area, so in this case we + * have to blit the pixels from the screen to the surface! + */ + local_os2_surface->dirty_area_present = FALSE; + _cairo_os2_surface_get_pixels_from_screen (local_os2_surface, + hps_begin_paint, + &rclTemp); + } else { + /* Okay, we have the surface, have the HPS + * (might be from WinBeginPaint () or from WinGetPS () ) + * Now blit there the stuffs! + */ + _cairo_os2_surface_blit_pixels (local_os2_surface, + hps_begin_paint, + &rclTemp); + } + + DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); + + if (hpsTemp) + WinReleasePS(hpsTemp); +} + +static cairo_status_t +_cairo_os2_surface_finish (void *abstract_surface) +{ + cairo_os2_surface_t *local_os2_surface; + + local_os2_surface = (cairo_os2_surface_t *) abstract_surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + } + + DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT); + + /* Destroy old image surface */ + cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface)); + /* Destroy old pixel buffer */ + _buffer_free (local_os2_surface->pixels); + DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); + DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); + + /* The memory itself will be free'd by the cairo_surface_destroy () + * who called us. + */ + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_os2_surface_set_hwnd: + * @surface: the cairo surface to associate with the window handle + * @hwnd_client_window: the window handle of the client window + * + * Sets window handle for surface; the caller retains ownership of the window. + * If Cairo wants to blit into the window because it is set to blit as the + * surface changes (see cairo_os2_surface_set_manual_window_refresh()), then + * there are two ways it can choose: + * If it knows the HWND of the surface, then it invalidates that area, so the + * application will get a WM_PAINT message and it can call + * cairo_os2_surface_refresh_window() to redraw that area. Otherwise cairo itself + * will use the HPS it got at surface creation time, and blit the pixels itself. + * It's also a solution, but experience shows that if this happens from a non-PM + * thread, then it can screw up PM internals. + * + * So, best solution is to set the HWND for the surface after the surface + * creation, so every blit will be done from application's message processing + * loop, which is the safest way to do. + * + * Since: 1.4 + **/ +void +cairo_os2_surface_set_hwnd (cairo_surface_t *surface, + HWND hwnd_client_window) +{ + cairo_os2_surface_t *local_os2_surface; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return; + } + + if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) + != NO_ERROR) + { + /* Could not get mutex! */ + return; + } + + local_os2_surface->hwnd_client_window = hwnd_client_window; + + DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); +} + +/** + * cairo_os2_surface_set_manual_window_refresh: + * @surface: the cairo surface to set the refresh mode for + * @manual_refresh: the switch for manual surface refresh + * + * This API can tell Cairo if it should show every change to this surface + * immediately in the window or if it should be cached and will only be visible + * once the user calls cairo_os2_surface_refresh_window() explicitly. If the + * HWND was not set in the cairo surface, then the HPS will be used to blit the + * graphics. Otherwise it will invalidate the given window region so the user + * will get the WM_PAINT message to redraw that area of the window. + * + * So, if you're only interested in displaying the final result after several + * drawing operations, you might get better performance if you put the surface + * into manual refresh mode by passing a true value to this function. Then call + * cairo_os2_surface_refresh() whenever desired. + * + * Since: 1.4 + **/ +void +cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface, + cairo_bool_t manual_refresh) +{ + cairo_os2_surface_t *local_os2_surface; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return; + } + + local_os2_surface->blit_as_changes = !manual_refresh; +} + +/** + * cairo_os2_surface_get_manual_window_refresh: + * @surface: the cairo surface to query the refresh mode from + * + * This space left intentionally blank. + * + * Return value: current refresh mode of the surface (true by default) + * + * Since: 1.4 + **/ +cairo_bool_t +cairo_os2_surface_get_manual_window_refresh (cairo_surface_t *surface) +{ + cairo_os2_surface_t *local_os2_surface; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return FALSE; + } + + return !(local_os2_surface->blit_as_changes); +} + +/** + * cairo_os2_surface_get_hps: + * @surface: the cairo surface to be querued + * @hps: HPS currently associated with the surface (if any) + * + * This API retrieves the HPS associated with the surface. + * + * Return value: %CAIRO_STATUS_SUCCESS if the hps could be retrieved, + * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface, + * %CAIRO_STATUS_NULL_POINTER if the hps argument is null + * + * Since: 1.10 + **/ +cairo_status_t +cairo_os2_surface_get_hps (cairo_surface_t *surface, + HPS *hps) +{ + cairo_os2_surface_t *local_os2_surface; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + } + if (!hps) + { + return _cairo_error (CAIRO_STATUS_NULL_POINTER); + } + *hps = local_os2_surface->hps_client_window; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_os2_surface_set_hps: + * @surface: the cairo surface to associate with the HPS + * @hps: new HPS to be associated with the surface (the HPS may be null) + * + * This API replaces the HPS associated with the surface with a new one. + * The caller retains ownership of the HPS and must dispose of it after + * the surface has been destroyed or it has been replaced by another + * call to this function. + * + * Return value: %CAIRO_STATUS_SUCCESS if the hps could be replaced, + * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface, + * + * Since: 1.10 + **/ +cairo_status_t +cairo_os2_surface_set_hps (cairo_surface_t *surface, + HPS hps) +{ + cairo_os2_surface_t *local_os2_surface; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + } + local_os2_surface->hps_client_window = hps; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_os2_surface_mark_dirty_rectangle (void *surface, + int x, + int y, + int width, + int height) +{ + cairo_os2_surface_t *local_os2_surface; + RECTL rclToBlit; + + local_os2_surface = (cairo_os2_surface_t *) surface; + if ((!local_os2_surface) || + (local_os2_surface->base.backend != &cairo_os2_surface_backend)) + { + /* Invalid parameter (wrong surface)! */ + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + } + + /* Get mutex, we'll work with the pixel array! */ + if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT) + != NO_ERROR) + { + /* Could not get mutex! */ + return CAIRO_STATUS_NO_MEMORY; + } + + /* Check for defaults */ + if (width < 0) + width = local_os2_surface->bitmap_info.cx; + if (height < 0) + height = local_os2_surface->bitmap_info.cy; + + if (local_os2_surface->hwnd_client_window) { + /* We know the HWND, so let's invalidate the window region, + * so the application will redraw itself, using the + * cairo_os2_surface_refresh_window () API from its own PM thread. + * From that function we'll note that it's not a redraw but a + * dirty-rectangle deal stuff, so we'll handle the things from + * there. + * + * This is the safe method, which should be preferred every time. + */ + rclToBlit.xLeft = x; + rclToBlit.xRight = x + width; /* Noninclusive */ + rclToBlit.yTop = local_os2_surface->bitmap_info.cy - (y); + rclToBlit.yBottom = local_os2_surface->bitmap_info.cy - (y + height); /* Noninclusive */ + +#if 0 + if (local_os2_surface->dirty_area_present) { + /* Yikes, there is already a dirty area which should be + * cleaned up, but we'll overwrite it. Sorry. + * TODO: Something clever should be done here. + */ + } +#endif + + /* Set up dirty area reminder stuff */ + memcpy (&(local_os2_surface->rcl_dirty_area), &rclToBlit, sizeof (RECTL)); + local_os2_surface->dirty_area_present = TRUE; + + /* Invalidate window area */ + WinInvalidateRect (local_os2_surface->hwnd_client_window, + &rclToBlit, + FALSE); + } else { + /* We don't know the HWND, so try to blit the pixels from here! + * Please note that it can be problematic if this is not the PM thread! + * + * It can cause internal PM stuffs to be scewed up, for some reason. + * Please always tell the HWND to the surface using the + * cairo_os2_surface_set_hwnd () API, and call cairo_os2_surface_refresh_window () + * from your WM_PAINT, if it's possible! + */ + + rclToBlit.xLeft = x; + rclToBlit.xRight = x + width; /* Noninclusive */ + rclToBlit.yBottom = y; + rclToBlit.yTop = y + height; /* Noninclusive */ + /* Now get the pixels from the screen! */ + _cairo_os2_surface_get_pixels_from_screen (local_os2_surface, + local_os2_surface->hps_client_window, + &rclToBlit); + } + + DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields); + + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t cairo_os2_surface_backend = { + CAIRO_SURFACE_TYPE_OS2, + _cairo_os2_surface_finish, + _cairo_default_context_create, + + NULL, /* create_similar */ + NULL, /* create_similar_image */ + _cairo_os2_surface_map_to_image, + _cairo_os2_surface_unmap_image, + + _cairo_surface_default_source, + _cairo_os2_surface_acquire_source_image, + _cairo_os2_surface_release_source_image, + NULL, /* snapshot */ + + _cairo_os2_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + _cairo_os2_surface_mark_dirty_rectangle, + + _cairo_surface_fallback_paint, + _cairo_surface_fallback_mask, + _cairo_surface_fallback_fill, + _cairo_surface_fallback_stroke, + NULL, /* fill/stroke */ + _cairo_surface_fallback_glyphs, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-os2.h b/Build/source/libs/cairo/cairo-src/src/cairo-os2.h new file mode 100644 index 00000000000..d23f2dec42a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-os2.h @@ -0,0 +1,110 @@ +/* vim: set sw=4 sts=4 et cin: */ +/* cairo - a vector graphics library with display and print output + * + * Copyright (c) 2005-2006 netlabs.org + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is + * Doodle + * + * Contributor(s): + * Peter Weilbacher + * Rich Walsh + */ + +#ifndef _CAIRO_OS2_H_ +#define _CAIRO_OS2_H_ + +#define INCL_DOS +#define INCL_DOSSEMAPHORES +#define INCL_DOSERRORS +#define INCL_WIN +#define INCL_GPI + +#include "cairo.h" + +#include + +CAIRO_BEGIN_DECLS + +/* The OS/2 Specific Cairo API */ + +cairo_public void +cairo_os2_init (void); + +cairo_public void +cairo_os2_fini (void); + +#if CAIRO_HAS_OS2_SURFACE + +cairo_public cairo_surface_t * +cairo_os2_surface_create (HPS hps_client_window, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_os2_surface_create_for_window (HWND hwnd_client_window, + int width, + int height); + +cairo_public void +cairo_os2_surface_set_hwnd (cairo_surface_t *surface, + HWND hwnd_client_window); + +cairo_public int +cairo_os2_surface_set_size (cairo_surface_t *surface, + int new_width, + int new_height, + int timeout); + +cairo_public void +cairo_os2_surface_refresh_window (cairo_surface_t *surface, + HPS hps_begin_paint, + PRECTL prcl_begin_paint_rect); + +cairo_public void +cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface, + cairo_bool_t manual_refresh); + +cairo_public cairo_bool_t +cairo_os2_surface_get_manual_window_refresh (cairo_surface_t *surface); + +cairo_public cairo_status_t +cairo_os2_surface_get_hps (cairo_surface_t *surface, + HPS *hps); + +cairo_public cairo_status_t +cairo_os2_surface_set_hps (cairo_surface_t *surface, + HPS hps); + +#else /* CAIRO_HAS_OS2_SURFACE */ +# error Cairo was not compiled with support for the OS/2 backend +#endif /* CAIRO_HAS_OS2_SURFACE */ + +CAIRO_END_DECLS + +#endif /* _CAIRO_OS2_H_ */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-output-stream-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-output-stream-private.h new file mode 100644 index 00000000000..2542646b860 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-output-stream-private.h @@ -0,0 +1,201 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Author(s): + * Kristian Høgsberg + */ + +#ifndef CAIRO_OUTPUT_STREAM_PRIVATE_H +#define CAIRO_OUTPUT_STREAM_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-types-private.h" + +#include +#include +#include + +typedef cairo_status_t +(*cairo_output_stream_write_func_t) (cairo_output_stream_t *output_stream, + const unsigned char *data, + unsigned int length); + +typedef cairo_status_t +(*cairo_output_stream_flush_func_t) (cairo_output_stream_t *output_stream); + +typedef cairo_status_t +(*cairo_output_stream_close_func_t) (cairo_output_stream_t *output_stream); + +struct _cairo_output_stream { + cairo_output_stream_write_func_t write_func; + cairo_output_stream_flush_func_t flush_func; + cairo_output_stream_close_func_t close_func; + unsigned long position; + cairo_status_t status; + cairo_bool_t closed; +}; + +extern const cairo_private cairo_output_stream_t _cairo_output_stream_nil; + +cairo_private void +_cairo_output_stream_init (cairo_output_stream_t *stream, + cairo_output_stream_write_func_t write_func, + cairo_output_stream_flush_func_t flush_func, + cairo_output_stream_close_func_t close_func); + +cairo_private cairo_status_t +_cairo_output_stream_fini (cairo_output_stream_t *stream); + + +/* We already have the following declared in cairo.h: + +typedef cairo_status_t (*cairo_write_func_t) (void *closure, + const unsigned char *data, + unsigned int length); +*/ +typedef cairo_status_t (*cairo_close_func_t) (void *closure); + + +/* This function never returns %NULL. If an error occurs (NO_MEMORY) + * while trying to create the output stream this function returns a + * valid pointer to a nil output stream. + * + * Note that even with a nil surface, the close_func callback will be + * called by a call to _cairo_output_stream_close or + * _cairo_output_stream_destroy. + */ +cairo_private cairo_output_stream_t * +_cairo_output_stream_create (cairo_write_func_t write_func, + cairo_close_func_t close_func, + void *closure); + +cairo_private cairo_output_stream_t * +_cairo_output_stream_create_in_error (cairo_status_t status); + +/* Tries to flush any buffer maintained by the stream or its delegates. */ +cairo_private cairo_status_t +_cairo_output_stream_flush (cairo_output_stream_t *stream); + +/* Returns the final status value associated with this object, just + * before its last gasp. This final status value will capture any + * status failure returned by the stream's close_func as well. */ +cairo_private cairo_status_t +_cairo_output_stream_close (cairo_output_stream_t *stream); + +/* Returns the final status value associated with this object, just + * before its last gasp. This final status value will capture any + * status failure returned by the stream's close_func as well. */ +cairo_private cairo_status_t +_cairo_output_stream_destroy (cairo_output_stream_t *stream); + +cairo_private void +_cairo_output_stream_write (cairo_output_stream_t *stream, + const void *data, size_t length); + +cairo_private void +_cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, + const unsigned char *data, + size_t length); + +cairo_private void +_cairo_output_stream_vprintf (cairo_output_stream_t *stream, + const char *fmt, + va_list ap) CAIRO_PRINTF_FORMAT ( 2, 0); + +cairo_private void +_cairo_output_stream_printf (cairo_output_stream_t *stream, + const char *fmt, + ...) CAIRO_PRINTF_FORMAT (2, 3); + +/* Print matrix element values with rounding of insignificant digits. */ +cairo_private void +_cairo_output_stream_print_matrix (cairo_output_stream_t *stream, + const cairo_matrix_t *matrix); + +cairo_private long +_cairo_output_stream_get_position (cairo_output_stream_t *stream); + +cairo_private cairo_status_t +_cairo_output_stream_get_status (cairo_output_stream_t *stream); + +/* This function never returns %NULL. If an error occurs (NO_MEMORY or + * WRITE_ERROR) while trying to create the output stream this function + * returns a valid pointer to a nil output stream. + * + * Note: Even if a nil surface is returned, the caller should still + * call _cairo_output_stream_destroy (or _cairo_output_stream_close at + * least) in order to ensure that everything is properly cleaned up. + */ +cairo_private cairo_output_stream_t * +_cairo_output_stream_create_for_filename (const char *filename); + +/* This function never returns %NULL. If an error occurs (NO_MEMORY or + * WRITE_ERROR) while trying to create the output stream this function + * returns a valid pointer to a nil output stream. + * + * The caller still "owns" file and is responsible for calling fclose + * on it when finished. The stream will not do this itself. + */ +cairo_private cairo_output_stream_t * +_cairo_output_stream_create_for_file (FILE *file); + +cairo_private cairo_output_stream_t * +_cairo_memory_stream_create (void); + +cairo_private void +_cairo_memory_stream_copy (cairo_output_stream_t *base, + cairo_output_stream_t *dest); + +cairo_private int +_cairo_memory_stream_length (cairo_output_stream_t *stream); + +cairo_private cairo_status_t +_cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream, + unsigned char **data_out, + unsigned long *length_out); + +cairo_private cairo_output_stream_t * +_cairo_null_stream_create (void); + +/* cairo-base85-stream.c */ +cairo_private cairo_output_stream_t * +_cairo_base85_stream_create (cairo_output_stream_t *output); + +/* cairo-base64-stream.c */ +cairo_private cairo_output_stream_t * +_cairo_base64_stream_create (cairo_output_stream_t *output); + +/* cairo-deflate-stream.c */ +cairo_private cairo_output_stream_t * +_cairo_deflate_stream_create (cairo_output_stream_t *output); + + +#endif /* CAIRO_OUTPUT_STREAM_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-output-stream.c b/Build/source/libs/cairo/cairo-src/src/cairo-output-stream.c new file mode 100644 index 00000000000..369a59bfba8 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-output-stream.c @@ -0,0 +1,802 @@ +/* cairo-output-stream.c: Output stream abstraction + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Author(s): + * Kristian Høgsberg + */ + +#define _BSD_SOURCE /* for snprintf() */ +#include "cairoint.h" + +#include "cairo-output-stream-private.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" +#include "cairo-compiler-private.h" + +#include +#include + +/* Numbers printed with %f are printed with this number of significant + * digits after the decimal. + */ +#define SIGNIFICANT_DIGITS_AFTER_DECIMAL 6 + +/* Numbers printed with %g are assumed to only have %CAIRO_FIXED_FRAC_BITS + * bits of precision available after the decimal point. + * + * FIXED_POINT_DECIMAL_DIGITS specifies the minimum number of decimal + * digits after the decimal point required to preserve the available + * precision. + * + * The conversion is: + * + * + * FIXED_POINT_DECIMAL_DIGITS = ceil( CAIRO_FIXED_FRAC_BITS * ln(2)/ln(10) ) + * + * + * We can replace ceil(x) with (int)(x+1) since x will never be an + * integer for any likely value of %CAIRO_FIXED_FRAC_BITS. + */ +#define FIXED_POINT_DECIMAL_DIGITS ((int)(CAIRO_FIXED_FRAC_BITS*0.301029996 + 1)) + +void +_cairo_output_stream_init (cairo_output_stream_t *stream, + cairo_output_stream_write_func_t write_func, + cairo_output_stream_flush_func_t flush_func, + cairo_output_stream_close_func_t close_func) +{ + stream->write_func = write_func; + stream->flush_func = flush_func; + stream->close_func = close_func; + stream->position = 0; + stream->status = CAIRO_STATUS_SUCCESS; + stream->closed = FALSE; +} + +cairo_status_t +_cairo_output_stream_fini (cairo_output_stream_t *stream) +{ + return _cairo_output_stream_close (stream); +} + +const cairo_output_stream_t _cairo_output_stream_nil = { + NULL, /* write_func */ + NULL, /* flush_func */ + NULL, /* close_func */ + 0, /* position */ + CAIRO_STATUS_NO_MEMORY, + FALSE /* closed */ +}; + +static const cairo_output_stream_t _cairo_output_stream_nil_write_error = { + NULL, /* write_func */ + NULL, /* flush_func */ + NULL, /* close_func */ + 0, /* position */ + CAIRO_STATUS_WRITE_ERROR, + FALSE /* closed */ +}; + +typedef struct _cairo_output_stream_with_closure { + cairo_output_stream_t base; + cairo_write_func_t write_func; + cairo_close_func_t close_func; + void *closure; +} cairo_output_stream_with_closure_t; + + +static cairo_status_t +closure_write (cairo_output_stream_t *stream, + const unsigned char *data, unsigned int length) +{ + cairo_output_stream_with_closure_t *stream_with_closure = + (cairo_output_stream_with_closure_t *) stream; + + if (stream_with_closure->write_func == NULL) + return CAIRO_STATUS_SUCCESS; + + return stream_with_closure->write_func (stream_with_closure->closure, + data, length); +} + +static cairo_status_t +closure_close (cairo_output_stream_t *stream) +{ + cairo_output_stream_with_closure_t *stream_with_closure = + (cairo_output_stream_with_closure_t *) stream; + + if (stream_with_closure->close_func != NULL) + return stream_with_closure->close_func (stream_with_closure->closure); + else + return CAIRO_STATUS_SUCCESS; +} + +cairo_output_stream_t * +_cairo_output_stream_create (cairo_write_func_t write_func, + cairo_close_func_t close_func, + void *closure) +{ + cairo_output_stream_with_closure_t *stream; + + stream = malloc (sizeof (cairo_output_stream_with_closure_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + closure_write, NULL, closure_close); + stream->write_func = write_func; + stream->close_func = close_func; + stream->closure = closure; + + return &stream->base; +} + +cairo_output_stream_t * +_cairo_output_stream_create_in_error (cairo_status_t status) +{ + cairo_output_stream_t *stream; + + /* check for the common ones */ + if (status == CAIRO_STATUS_NO_MEMORY) + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + if (status == CAIRO_STATUS_WRITE_ERROR) + return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error; + + stream = malloc (sizeof (cairo_output_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (stream, NULL, NULL, NULL); + stream->status = status; + + return stream; +} + +cairo_status_t +_cairo_output_stream_flush (cairo_output_stream_t *stream) +{ + cairo_status_t status; + + if (stream->closed) + return stream->status; + + if (stream == &_cairo_output_stream_nil || + stream == &_cairo_output_stream_nil_write_error) + { + return stream->status; + } + + if (stream->flush_func) { + status = stream->flush_func (stream); + /* Don't overwrite a pre-existing status failure. */ + if (stream->status == CAIRO_STATUS_SUCCESS) + stream->status = status; + } + + return stream->status; +} + +cairo_status_t +_cairo_output_stream_close (cairo_output_stream_t *stream) +{ + cairo_status_t status; + + if (stream->closed) + return stream->status; + + if (stream == &_cairo_output_stream_nil || + stream == &_cairo_output_stream_nil_write_error) + { + return stream->status; + } + + if (stream->close_func) { + status = stream->close_func (stream); + /* Don't overwrite a pre-existing status failure. */ + if (stream->status == CAIRO_STATUS_SUCCESS) + stream->status = status; + } + + stream->closed = TRUE; + + return stream->status; +} + +cairo_status_t +_cairo_output_stream_destroy (cairo_output_stream_t *stream) +{ + cairo_status_t status; + + assert (stream != NULL); + + if (stream == &_cairo_output_stream_nil || + stream == &_cairo_output_stream_nil_write_error) + { + return stream->status; + } + + status = _cairo_output_stream_fini (stream); + free (stream); + + return status; +} + +void +_cairo_output_stream_write (cairo_output_stream_t *stream, + const void *data, size_t length) +{ + if (length == 0) + return; + + if (stream->status) + return; + + stream->status = stream->write_func (stream, data, length); + stream->position += length; +} + +void +_cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, + const unsigned char *data, + size_t length) +{ + const char hex_chars[] = "0123456789abcdef"; + char buffer[2]; + unsigned int i, column; + + if (stream->status) + return; + + for (i = 0, column = 0; i < length; i++, column++) { + if (column == 38) { + _cairo_output_stream_write (stream, "\n", 1); + column = 0; + } + buffer[0] = hex_chars[(data[i] >> 4) & 0x0f]; + buffer[1] = hex_chars[data[i] & 0x0f]; + _cairo_output_stream_write (stream, buffer, 2); + } +} + +/* Format a double in a locale independent way and trim trailing + * zeros. Based on code from Alex Larson . + * http://mail.gnome.org/archives/gtk-devel-list/2001-October/msg00087.html + * + * The code in the patch is copyright Red Hat, Inc under the LGPL, but + * has been relicensed under the LGPL/MPL dual license for inclusion + * into cairo (see COPYING). -- Kristian Høgsberg + */ +static void +_cairo_dtostr (char *buffer, size_t size, double d, cairo_bool_t limited_precision) +{ + const char *decimal_point; + int decimal_point_len; + char *p; + int decimal_len; + int num_zeros, decimal_digits; + + /* Omit the minus sign from negative zero. */ + if (d == 0.0) + d = 0.0; + + decimal_point = cairo_get_locale_decimal_point (); + decimal_point_len = strlen (decimal_point); + + assert (decimal_point_len != 0); + + if (limited_precision) { + snprintf (buffer, size, "%.*f", FIXED_POINT_DECIMAL_DIGITS, d); + } else { + /* Using "%f" to print numbers less than 0.1 will result in + * reduced precision due to the default 6 digits after the + * decimal point. + * + * For numbers is < 0.1, we print with maximum precision and count + * the number of zeros between the decimal point and the first + * significant digit. We then print the number again with the + * number of decimal places that gives us the required number of + * significant digits. This ensures the number is correctly + * rounded. + */ + if (fabs (d) >= 0.1) { + snprintf (buffer, size, "%f", d); + } else { + snprintf (buffer, size, "%.18f", d); + p = buffer; + + if (*p == '+' || *p == '-') + p++; + + while (_cairo_isdigit (*p)) + p++; + + if (strncmp (p, decimal_point, decimal_point_len) == 0) + p += decimal_point_len; + + num_zeros = 0; + while (*p++ == '0') + num_zeros++; + + decimal_digits = num_zeros + SIGNIFICANT_DIGITS_AFTER_DECIMAL; + + if (decimal_digits < 18) + snprintf (buffer, size, "%.*f", decimal_digits, d); + } + } + p = buffer; + + if (*p == '+' || *p == '-') + p++; + + while (_cairo_isdigit (*p)) + p++; + + if (strncmp (p, decimal_point, decimal_point_len) == 0) { + *p = '.'; + decimal_len = strlen (p + decimal_point_len); + memmove (p + 1, p + decimal_point_len, decimal_len); + p[1 + decimal_len] = 0; + + /* Remove trailing zeros and decimal point if possible. */ + for (p = p + decimal_len; *p == '0'; p--) + *p = 0; + + if (*p == '.') { + *p = 0; + p--; + } + } +} + +enum { + LENGTH_MODIFIER_LONG = 0x100 +}; + +/* Here's a limited reimplementation of printf. The reason for doing + * this is primarily to special case handling of doubles. We want + * locale independent formatting of doubles and we want to trim + * trailing zeros. This is handled by dtostr() above, and the code + * below handles everything else by calling snprintf() to do the + * formatting. This functionality is only for internal use and we + * only implement the formats we actually use. + */ +void +_cairo_output_stream_vprintf (cairo_output_stream_t *stream, + const char *fmt, va_list ap) +{ +#define SINGLE_FMT_BUFFER_SIZE 32 + char buffer[512], single_fmt[SINGLE_FMT_BUFFER_SIZE]; + int single_fmt_length; + char *p; + const char *f, *start; + int length_modifier, width; + cairo_bool_t var_width; + + if (stream->status) + return; + + f = fmt; + p = buffer; + while (*f != '\0') { + if (p == buffer + sizeof (buffer)) { + _cairo_output_stream_write (stream, buffer, sizeof (buffer)); + p = buffer; + } + + if (*f != '%') { + *p++ = *f++; + continue; + } + + start = f; + f++; + + if (*f == '0') + f++; + + var_width = FALSE; + if (*f == '*') { + var_width = TRUE; + f++; + } + + while (_cairo_isdigit (*f)) + f++; + + length_modifier = 0; + if (*f == 'l') { + length_modifier = LENGTH_MODIFIER_LONG; + f++; + } + + /* The only format strings exist in the cairo implementation + * itself. So there's an internal consistency problem if any + * of them is larger than our format buffer size. */ + single_fmt_length = f - start + 1; + assert (single_fmt_length + 1 <= SINGLE_FMT_BUFFER_SIZE); + + /* Reuse the format string for this conversion. */ + memcpy (single_fmt, start, single_fmt_length); + single_fmt[single_fmt_length] = '\0'; + + /* Flush contents of buffer before snprintf()'ing into it. */ + _cairo_output_stream_write (stream, buffer, p - buffer); + + /* We group signed and unsigned together in this switch, the + * only thing that matters here is the size of the arguments, + * since we're just passing the data through to sprintf(). */ + switch (*f | length_modifier) { + case '%': + buffer[0] = *f; + buffer[1] = 0; + break; + case 'd': + case 'u': + case 'o': + case 'x': + case 'X': + if (var_width) { + width = va_arg (ap, int); + snprintf (buffer, sizeof buffer, + single_fmt, width, va_arg (ap, int)); + } else { + snprintf (buffer, sizeof buffer, single_fmt, va_arg (ap, int)); + } + break; + case 'd' | LENGTH_MODIFIER_LONG: + case 'u' | LENGTH_MODIFIER_LONG: + case 'o' | LENGTH_MODIFIER_LONG: + case 'x' | LENGTH_MODIFIER_LONG: + case 'X' | LENGTH_MODIFIER_LONG: + if (var_width) { + width = va_arg (ap, int); + snprintf (buffer, sizeof buffer, + single_fmt, width, va_arg (ap, long int)); + } else { + snprintf (buffer, sizeof buffer, + single_fmt, va_arg (ap, long int)); + } + break; + case 's': + snprintf (buffer, sizeof buffer, + single_fmt, va_arg (ap, const char *)); + break; + case 'f': + _cairo_dtostr (buffer, sizeof buffer, va_arg (ap, double), FALSE); + break; + case 'g': + _cairo_dtostr (buffer, sizeof buffer, va_arg (ap, double), TRUE); + break; + case 'c': + buffer[0] = va_arg (ap, int); + buffer[1] = 0; + break; + default: + ASSERT_NOT_REACHED; + } + p = buffer + strlen (buffer); + f++; + } + + _cairo_output_stream_write (stream, buffer, p - buffer); +} + +void +_cairo_output_stream_printf (cairo_output_stream_t *stream, + const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + _cairo_output_stream_vprintf (stream, fmt, ap); + + va_end (ap); +} + +/* Matrix elements that are smaller than the value of the largest element * MATRIX_ROUNDING_TOLERANCE + * are rounded down to zero. */ +#define MATRIX_ROUNDING_TOLERANCE 1e-12 + +void +_cairo_output_stream_print_matrix (cairo_output_stream_t *stream, + const cairo_matrix_t *matrix) +{ + cairo_matrix_t m; + double s, e; + + m = *matrix; + s = fabs (m.xx); + if (fabs (m.xy) > s) + s = fabs (m.xy); + if (fabs (m.yx) > s) + s = fabs (m.yx); + if (fabs (m.yy) > s) + s = fabs (m.yy); + + e = s * MATRIX_ROUNDING_TOLERANCE; + if (fabs(m.xx) < e) + m.xx = 0; + if (fabs(m.xy) < e) + m.xy = 0; + if (fabs(m.yx) < e) + m.yx = 0; + if (fabs(m.yy) < e) + m.yy = 0; + if (fabs(m.x0) < e) + m.x0 = 0; + if (fabs(m.y0) < e) + m.y0 = 0; + + _cairo_output_stream_printf (stream, + "%f %f %f %f %f %f", + m.xx, m.yx, m.xy, m.yy, m.x0, m.y0); +} + +long +_cairo_output_stream_get_position (cairo_output_stream_t *stream) +{ + return stream->position; +} + +cairo_status_t +_cairo_output_stream_get_status (cairo_output_stream_t *stream) +{ + return stream->status; +} + +/* Maybe this should be a configure time option, so embedded targets + * don't have to pull in stdio. */ + + +typedef struct _stdio_stream { + cairo_output_stream_t base; + FILE *file; +} stdio_stream_t; + +static cairo_status_t +stdio_write (cairo_output_stream_t *base, + const unsigned char *data, unsigned int length) +{ + stdio_stream_t *stream = (stdio_stream_t *) base; + + if (fwrite (data, 1, length, stream->file) != length) + return _cairo_error (CAIRO_STATUS_WRITE_ERROR); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +stdio_flush (cairo_output_stream_t *base) +{ + stdio_stream_t *stream = (stdio_stream_t *) base; + + fflush (stream->file); + + if (ferror (stream->file)) + return _cairo_error (CAIRO_STATUS_WRITE_ERROR); + else + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +stdio_close (cairo_output_stream_t *base) +{ + cairo_status_t status; + stdio_stream_t *stream = (stdio_stream_t *) base; + + status = stdio_flush (base); + + fclose (stream->file); + + return status; +} + +cairo_output_stream_t * +_cairo_output_stream_create_for_file (FILE *file) +{ + stdio_stream_t *stream; + + if (file == NULL) { + _cairo_error_throw (CAIRO_STATUS_WRITE_ERROR); + return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error; + } + + stream = malloc (sizeof *stream); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + stdio_write, stdio_flush, stdio_flush); + stream->file = file; + + return &stream->base; +} + +cairo_output_stream_t * +_cairo_output_stream_create_for_filename (const char *filename) +{ + stdio_stream_t *stream; + FILE *file; + + if (filename == NULL) + return _cairo_null_stream_create (); + + file = fopen (filename, "wb"); + if (file == NULL) { + switch (errno) { + case ENOMEM: + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + default: + _cairo_error_throw (CAIRO_STATUS_WRITE_ERROR); + return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error; + } + } + + stream = malloc (sizeof *stream); + if (unlikely (stream == NULL)) { + fclose (file); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + stdio_write, stdio_flush, stdio_close); + stream->file = file; + + return &stream->base; +} + + +typedef struct _memory_stream { + cairo_output_stream_t base; + cairo_array_t array; +} memory_stream_t; + +static cairo_status_t +memory_write (cairo_output_stream_t *base, + const unsigned char *data, unsigned int length) +{ + memory_stream_t *stream = (memory_stream_t *) base; + + return _cairo_array_append_multiple (&stream->array, data, length); +} + +static cairo_status_t +memory_close (cairo_output_stream_t *base) +{ + memory_stream_t *stream = (memory_stream_t *) base; + + _cairo_array_fini (&stream->array); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_output_stream_t * +_cairo_memory_stream_create (void) +{ + memory_stream_t *stream; + + stream = malloc (sizeof *stream); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, memory_write, NULL, memory_close); + _cairo_array_init (&stream->array, 1); + + return &stream->base; +} + +cairo_status_t +_cairo_memory_stream_destroy (cairo_output_stream_t *abstract_stream, + unsigned char **data_out, + unsigned long *length_out) +{ + memory_stream_t *stream; + cairo_status_t status; + + status = abstract_stream->status; + if (unlikely (status)) + return _cairo_output_stream_destroy (abstract_stream); + + stream = (memory_stream_t *) abstract_stream; + + *length_out = _cairo_array_num_elements (&stream->array); + *data_out = malloc (*length_out); + if (unlikely (*data_out == NULL)) { + status = _cairo_output_stream_destroy (abstract_stream); + assert (status == CAIRO_STATUS_SUCCESS); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + memcpy (*data_out, _cairo_array_index (&stream->array, 0), *length_out); + + return _cairo_output_stream_destroy (abstract_stream); +} + +void +_cairo_memory_stream_copy (cairo_output_stream_t *base, + cairo_output_stream_t *dest) +{ + memory_stream_t *stream = (memory_stream_t *) base; + + if (dest->status) + return; + + if (base->status) { + dest->status = base->status; + return; + } + + _cairo_output_stream_write (dest, + _cairo_array_index (&stream->array, 0), + _cairo_array_num_elements (&stream->array)); +} + +int +_cairo_memory_stream_length (cairo_output_stream_t *base) +{ + memory_stream_t *stream = (memory_stream_t *) base; + + return _cairo_array_num_elements (&stream->array); +} + +static cairo_status_t +null_write (cairo_output_stream_t *base, + const unsigned char *data, unsigned int length) +{ + return CAIRO_STATUS_SUCCESS; +} + +cairo_output_stream_t * +_cairo_null_stream_create (void) +{ + cairo_output_stream_t *stream; + + stream = malloc (sizeof *stream); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (stream, null_write, NULL, NULL); + + return stream; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-paginated-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-paginated-private.h new file mode 100644 index 00000000000..b827faba0ef --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-paginated-private.h @@ -0,0 +1,168 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + */ + +#ifndef CAIRO_PAGINATED_H +#define CAIRO_PAGINATED_H + +#include "cairoint.h" + +struct _cairo_paginated_surface_backend { + /* Optional. Will be called once for each page. + * + * Note: With respect to the order of drawing operations as seen + * by the target, this call will occur before any drawing + * operations for the relevant page. However, with respect to the + * function calls as made by the user, this call will be *after* + * any drawing operations for the page, (that is, it will occur + * during the user's call to cairo_show_page or cairo_copy_page). + */ + cairo_warn cairo_int_status_t + (*start_page) (void *surface); + + /* Required. Will be called twice for each page, once with an + * argument of CAIRO_PAGINATED_MODE_ANALYZE and once with + * CAIRO_PAGINATED_MODE_RENDER. See more details in the + * documentation for _cairo_paginated_surface_create below. + */ + void + (*set_paginated_mode) (void *surface, + cairo_paginated_mode_t mode); + + /* Optional. Specifies the smallest box that encloses all objects + * on the page. Will be called at the end of the ANALYZE phase but + * before the mode is changed to RENDER. + */ + cairo_warn cairo_int_status_t + (*set_bounding_box) (void *surface, + cairo_box_t *bbox); + + /* Optional. Indicates whether the page requires fallback images. + * Will be called at the end of the ANALYZE phase but before the + * mode is changed to RENDER. + */ + cairo_warn cairo_int_status_t + (*set_fallback_images_required) (void *surface, + cairo_bool_t fallbacks_required); + + cairo_bool_t + (*supports_fine_grained_fallbacks) (void *surface); +}; + +/* A #cairo_paginated_surface_t provides a very convenient wrapper that + * is well-suited for doing the analysis common to most surfaces that + * have paginated output, (that is, things directed at printers, or + * for saving content in files such as PostScript or PDF files). + * + * To use the paginated surface, you'll first need to create your + * 'real' surface using _cairo_surface_init() and the standard + * #cairo_surface_backend_t. Then you also call + * _cairo_paginated_surface_create which takes its own, much simpler, + * #cairo_paginated_surface_backend_t. You are free to return the result + * of _cairo_paginated_surface_create() from your public + * cairo__surface_create(). The paginated backend will be careful + * to not let the user see that they really got a "wrapped" + * surface. See test-paginated-surface.c for a fairly minimal example + * of a paginated-using surface. That should be a reasonable example + * to follow. + * + * What the paginated surface does is first save all drawing + * operations for a page into a recording-surface. Then when the user calls + * cairo_show_page(), the paginated surface performs the following + * sequence of operations (using the backend functions passed to + * cairo_paginated_surface_create()): + * + * 1. Calls start_page() (if not %NULL). At this point, it is appropriate + * for the target to emit any page-specific header information into + * its output. + * + * 2. Calls set_paginated_mode() with an argument of %CAIRO_PAGINATED_MODE_ANALYZE + * + * 3. Replays the recording-surface to the target surface, (with an + * analysis surface inserted between which watches the return value + * from each operation). This analysis stage is used to decide which + * operations will require fallbacks. + * + * 4. Calls set_bounding_box() to provide the target surface with the + * tight bounding box of the page. + * + * 5. Calls set_paginated_mode() with an argument of %CAIRO_PAGINATED_MODE_RENDER + * + * 6. Replays a subset of the recording-surface operations to the target surface + * + * 7. Calls set_paginated_mode() with an argument of %CAIRO_PAGINATED_MODE_FALLBACK + * + * 8. Replays the remaining operations to an image surface, sets an + * appropriate clip on the target, then paints the resulting image + * surface to the target. + * + * So, the target will see drawing operations during three separate + * stages, (ANALYZE, RENDER and FALLBACK). During the ANALYZE phase + * the target should not actually perform any rendering, (for example, + * if performing output to a file, no output should be generated + * during this stage). Instead the drawing functions simply need to + * return %CAIRO_STATUS_SUCCESS or %CAIRO_INT_STATUS_UNSUPPORTED to + * indicate whether rendering would be supported. And it should do + * this as quickly as possible. The FALLBACK phase allows the surface + * to distinguish fallback images from native rendering in case they + * need to be handled as a special case. + * + * Note: The paginated surface layer assumes that the target surface + * is "blank" by default at the beginning of each page, without any + * need for an explicit erase operation, (as opposed to an image + * surface, for example, which might have uninitialized content + * originally). As such, it optimizes away CLEAR operations that + * happen at the beginning of each page---the target surface will not + * even see these operations. + */ +cairo_private cairo_surface_t * +_cairo_paginated_surface_create (cairo_surface_t *target, + cairo_content_t content, + const cairo_paginated_surface_backend_t *backend); + +cairo_private cairo_surface_t * +_cairo_paginated_surface_get_target (cairo_surface_t *surface); + +cairo_private cairo_surface_t * +_cairo_paginated_surface_get_recording (cairo_surface_t *surface); + +cairo_private cairo_bool_t +_cairo_surface_is_paginated (cairo_surface_t *surface); + +cairo_private cairo_status_t +_cairo_paginated_surface_set_size (cairo_surface_t *surface, + int width, + int height); + +#endif /* CAIRO_PAGINATED_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface-private.h new file mode 100644 index 00000000000..ebf4b342492 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface-private.h @@ -0,0 +1,62 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + */ + +#ifndef CAIRO_PAGINATED_SURFACE_H +#define CAIRO_PAGINATED_SURFACE_H + +#include "cairo.h" + +#include "cairo-surface-private.h" + +typedef struct _cairo_paginated_surface { + cairo_surface_t base; + + /* The target surface to hold the final result. */ + cairo_surface_t *target; + + cairo_content_t content; + + /* Paginated-surface specific functions for the target */ + const cairo_paginated_surface_backend_t *backend; + + /* A cairo_recording_surface to record all operations. To be replayed + * against target, and also against image surface as necessary for + * fallbacks. */ + cairo_surface_t *recording_surface; + + int page_num; +} cairo_paginated_surface_t; + +#endif /* CAIRO_PAGINATED_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface.c new file mode 100644 index 00000000000..68e4e0e34fd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-paginated-surface.c @@ -0,0 +1,716 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * Copyright © 2007 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + * Keith Packard + * Adrian Johnson + */ + +/* The paginated surface layer exists to provide as much code sharing + * as possible for the various paginated surface backends in cairo + * (PostScript, PDF, etc.). See cairo-paginated-private.h for + * more details on how it works and how to use it. + */ + +#include "cairoint.h" + +#include "cairo-paginated-private.h" +#include "cairo-paginated-surface-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-analysis-surface-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-subsurface-inline.h" + +static const cairo_surface_backend_t cairo_paginated_surface_backend; + +static cairo_int_status_t +_cairo_paginated_surface_show_page (void *abstract_surface); + +static cairo_surface_t * +_cairo_paginated_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_rectangle_t rect; + rect.x = rect.y = 0.; + rect.width = width; + rect.height = height; + return cairo_recording_surface_create (content, &rect); +} + +static cairo_surface_t * +_create_recording_surface_for_target (cairo_surface_t *target, + cairo_content_t content) +{ + cairo_rectangle_int_t rect; + + if (_cairo_surface_get_extents (target, &rect)) { + cairo_rectangle_t recording_extents; + + recording_extents.x = rect.x; + recording_extents.y = rect.y; + recording_extents.width = rect.width; + recording_extents.height = rect.height; + + return cairo_recording_surface_create (content, &recording_extents); + } else { + return cairo_recording_surface_create (content, NULL); + } +} + +cairo_surface_t * +_cairo_paginated_surface_create (cairo_surface_t *target, + cairo_content_t content, + const cairo_paginated_surface_backend_t *backend) +{ + cairo_paginated_surface_t *surface; + cairo_status_t status; + + surface = malloc (sizeof (cairo_paginated_surface_t)); + if (unlikely (surface == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FAIL; + } + + _cairo_surface_init (&surface->base, + &cairo_paginated_surface_backend, + NULL, /* device */ + content); + + /* Override surface->base.type with target's type so we don't leak + * evidence of the paginated wrapper out to the user. */ + surface->base.type = target->type; + + surface->target = cairo_surface_reference (target); + + surface->content = content; + surface->backend = backend; + + surface->recording_surface = _create_recording_surface_for_target (target, content); + status = surface->recording_surface->status; + if (unlikely (status)) + goto FAIL_CLEANUP_SURFACE; + + surface->page_num = 1; + surface->base.is_clear = TRUE; + + return &surface->base; + + FAIL_CLEANUP_SURFACE: + cairo_surface_destroy (target); + free (surface); + FAIL: + return _cairo_surface_create_in_error (status); +} + +cairo_bool_t +_cairo_surface_is_paginated (cairo_surface_t *surface) +{ + return surface->backend == &cairo_paginated_surface_backend; +} + +cairo_surface_t * +_cairo_paginated_surface_get_target (cairo_surface_t *surface) +{ + cairo_paginated_surface_t *paginated_surface; + + assert (_cairo_surface_is_paginated (surface)); + + paginated_surface = (cairo_paginated_surface_t *) surface; + return paginated_surface->target; +} + +cairo_surface_t * +_cairo_paginated_surface_get_recording (cairo_surface_t *surface) +{ + cairo_paginated_surface_t *paginated_surface; + + assert (_cairo_surface_is_paginated (surface)); + + paginated_surface = (cairo_paginated_surface_t *) surface; + return paginated_surface->recording_surface; +} + +cairo_status_t +_cairo_paginated_surface_set_size (cairo_surface_t *surface, + int width, + int height) +{ + cairo_paginated_surface_t *paginated_surface; + cairo_status_t status; + cairo_rectangle_t recording_extents; + + assert (_cairo_surface_is_paginated (surface)); + + paginated_surface = (cairo_paginated_surface_t *) surface; + + recording_extents.x = 0; + recording_extents.y = 0; + recording_extents.width = width; + recording_extents.height = height; + + cairo_surface_destroy (paginated_surface->recording_surface); + paginated_surface->recording_surface = cairo_recording_surface_create (paginated_surface->content, + &recording_extents); + status = paginated_surface->recording_surface->status; + if (unlikely (status)) + return _cairo_surface_set_error (surface, status); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_paginated_surface_finish (void *abstract_surface) +{ + cairo_paginated_surface_t *surface = abstract_surface; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + if (! surface->base.is_clear || surface->page_num == 1) { + /* Bypass some of the sanity checking in cairo-surface.c, as we + * know that the surface is finished... + */ + status = _cairo_paginated_surface_show_page (surface); + } + + /* XXX We want to propagate any errors from destroy(), but those are not + * returned via the api. So we need to explicitly finish the target, + * and check the status afterwards. However, we can only call finish() + * on the target, if we own it. + */ + if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->target->ref_count) == 1) + cairo_surface_finish (surface->target); + if (status == CAIRO_STATUS_SUCCESS) + status = cairo_surface_status (surface->target); + cairo_surface_destroy (surface->target); + + cairo_surface_finish (surface->recording_surface); + if (status == CAIRO_STATUS_SUCCESS) + status = cairo_surface_status (surface->recording_surface); + cairo_surface_destroy (surface->recording_surface); + + return status; +} + +static cairo_surface_t * +_cairo_paginated_surface_create_image_surface (void *abstract_surface, + int width, + int height) +{ + cairo_paginated_surface_t *surface = abstract_surface; + cairo_surface_t *image; + cairo_font_options_t options; + + image = _cairo_image_surface_create_with_content (surface->content, + width, + height); + + cairo_surface_get_font_options (&surface->base, &options); + _cairo_surface_set_font_options (image, &options); + + return image; +} + +static cairo_surface_t * +_cairo_paginated_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_paginated_surface_t *surface = abstract_surface; + return _cairo_surface_get_source (surface->target, extents); +} + +static cairo_status_t +_cairo_paginated_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_paginated_surface_t *surface = abstract_surface; + cairo_bool_t is_bounded; + cairo_surface_t *image; + cairo_status_t status; + cairo_rectangle_int_t extents; + + is_bounded = _cairo_surface_get_extents (surface->target, &extents); + if (! is_bounded) + return CAIRO_INT_STATUS_UNSUPPORTED; + + image = _cairo_paginated_surface_create_image_surface (surface, + extents.width, + extents.height); + + status = _cairo_recording_surface_replay (surface->recording_surface, image); + if (unlikely (status)) { + cairo_surface_destroy (image); + return status; + } + + *image_out = (cairo_image_surface_t*) image; + *image_extra = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_paginated_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); +} + +static cairo_int_status_t +_paint_fallback_image (cairo_paginated_surface_t *surface, + cairo_rectangle_int_t *rect) +{ + double x_scale = surface->base.x_fallback_resolution / surface->target->x_resolution; + double y_scale = surface->base.y_fallback_resolution / surface->target->y_resolution; + int x, y, width, height; + cairo_status_t status; + cairo_surface_t *image; + cairo_surface_pattern_t pattern; + cairo_clip_t *clip; + + x = rect->x; + y = rect->y; + width = rect->width; + height = rect->height; + image = _cairo_paginated_surface_create_image_surface (surface, + ceil (width * x_scale), + ceil (height * y_scale)); + cairo_surface_set_device_scale (image, x_scale, y_scale); + /* set_device_offset just sets the x0/y0 components of the matrix; + * so we have to do the scaling manually. */ + cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale); + + status = _cairo_recording_surface_replay (surface->recording_surface, image); + if (unlikely (status)) + goto CLEANUP_IMAGE; + + _cairo_pattern_init_for_surface (&pattern, image); + cairo_matrix_init (&pattern.base.matrix, + x_scale, 0, 0, y_scale, -x*x_scale, -y*y_scale); + /* the fallback should be rendered at native resolution, so disable + * filtering (if possible) to avoid introducing potential artifacts. */ + pattern.base.filter = CAIRO_FILTER_NEAREST; + + clip = _cairo_clip_intersect_rectangle (NULL, rect); + status = _cairo_surface_paint (surface->target, + CAIRO_OPERATOR_SOURCE, + &pattern.base, clip); + _cairo_clip_destroy (clip); + _cairo_pattern_fini (&pattern.base); + +CLEANUP_IMAGE: + cairo_surface_destroy (image); + + return status; +} + +static cairo_int_status_t +_paint_page (cairo_paginated_surface_t *surface) +{ + cairo_surface_t *analysis; + cairo_int_status_t status; + cairo_bool_t has_supported, has_page_fallback, has_finegrained_fallback; + + if (unlikely (surface->target->status)) + return surface->target->status; + + analysis = _cairo_analysis_surface_create (surface->target); + if (unlikely (analysis->status)) + return _cairo_surface_set_error (surface->target, analysis->status); + + surface->backend->set_paginated_mode (surface->target, + CAIRO_PAGINATED_MODE_ANALYZE); + status = _cairo_recording_surface_replay_and_create_regions (surface->recording_surface, + analysis); + if (status) + goto FAIL; + + assert (analysis->status == CAIRO_STATUS_SUCCESS); + + if (surface->backend->set_bounding_box) { + cairo_box_t bbox; + + _cairo_analysis_surface_get_bounding_box (analysis, &bbox); + status = surface->backend->set_bounding_box (surface->target, &bbox); + if (unlikely (status)) + goto FAIL; + } + + if (surface->backend->set_fallback_images_required) { + cairo_bool_t has_fallbacks = _cairo_analysis_surface_has_unsupported (analysis); + + status = surface->backend->set_fallback_images_required (surface->target, + has_fallbacks); + if (unlikely (status)) + goto FAIL; + } + + /* Finer grained fallbacks are currently only supported for some + * surface types */ + if (surface->backend->supports_fine_grained_fallbacks != NULL && + surface->backend->supports_fine_grained_fallbacks (surface->target)) + { + has_supported = _cairo_analysis_surface_has_supported (analysis); + has_page_fallback = FALSE; + has_finegrained_fallback = _cairo_analysis_surface_has_unsupported (analysis); + } + else + { + if (_cairo_analysis_surface_has_unsupported (analysis)) { + has_supported = FALSE; + has_page_fallback = TRUE; + } else { + has_supported = TRUE; + has_page_fallback = FALSE; + } + has_finegrained_fallback = FALSE; + } + + if (has_supported) { + surface->backend->set_paginated_mode (surface->target, + CAIRO_PAGINATED_MODE_RENDER); + + status = _cairo_recording_surface_replay_region (surface->recording_surface, + NULL, + surface->target, + CAIRO_RECORDING_REGION_NATIVE); + assert (status != CAIRO_INT_STATUS_UNSUPPORTED); + if (unlikely (status)) + goto FAIL; + } + + if (has_page_fallback) { + cairo_rectangle_int_t extents; + cairo_bool_t is_bounded; + + surface->backend->set_paginated_mode (surface->target, + CAIRO_PAGINATED_MODE_FALLBACK); + + is_bounded = _cairo_surface_get_extents (surface->target, &extents); + if (! is_bounded) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto FAIL; + } + + status = _paint_fallback_image (surface, &extents); + if (unlikely (status)) + goto FAIL; + } + + if (has_finegrained_fallback) { + cairo_region_t *region; + int num_rects, i; + + surface->backend->set_paginated_mode (surface->target, + CAIRO_PAGINATED_MODE_FALLBACK); + + region = _cairo_analysis_surface_get_unsupported (analysis); + + num_rects = cairo_region_num_rectangles (region); + for (i = 0; i < num_rects; i++) { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (region, i, &rect); + status = _paint_fallback_image (surface, &rect); + if (unlikely (status)) + goto FAIL; + } + } + + FAIL: + cairo_surface_destroy (analysis); + + return _cairo_surface_set_error (surface->target, status); +} + +static cairo_status_t +_start_page (cairo_paginated_surface_t *surface) +{ + if (surface->target->status) + return surface->target->status; + + if (! surface->backend->start_page) + return CAIRO_STATUS_SUCCESS; + + return _cairo_surface_set_error (surface->target, + surface->backend->start_page (surface->target)); +} + +static cairo_int_status_t +_cairo_paginated_surface_copy_page (void *abstract_surface) +{ + cairo_status_t status; + cairo_paginated_surface_t *surface = abstract_surface; + + status = _start_page (surface); + if (unlikely (status)) + return status; + + status = _paint_page (surface); + if (unlikely (status)) + return status; + + surface->page_num++; + + /* XXX: It might make sense to add some support here for calling + * cairo_surface_copy_page on the target surface. It would be an + * optimization for the output, but the interaction with image + * fallbacks gets tricky. For now, we just let the target see a + * show_page and we implement the copying by simply not destroying + * the recording-surface. */ + + cairo_surface_show_page (surface->target); + return cairo_surface_status (surface->target); +} + +static cairo_int_status_t +_cairo_paginated_surface_show_page (void *abstract_surface) +{ + cairo_status_t status; + cairo_paginated_surface_t *surface = abstract_surface; + + status = _start_page (surface); + if (unlikely (status)) + return status; + + status = _paint_page (surface); + if (unlikely (status)) + return status; + + cairo_surface_show_page (surface->target); + status = surface->target->status; + if (unlikely (status)) + return status; + + status = surface->recording_surface->status; + if (unlikely (status)) + return status; + + if (! surface->base.finished) { + cairo_surface_destroy (surface->recording_surface); + + surface->recording_surface = _create_recording_surface_for_target (surface->target, + surface->content); + status = surface->recording_surface->status; + if (unlikely (status)) + return status; + + surface->page_num++; + surface->base.is_clear = TRUE; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_paginated_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_get_extents (surface->target, rectangle); +} + +static void +_cairo_paginated_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + cairo_surface_get_font_options (surface->target, options); +} + +static cairo_int_status_t +_cairo_paginated_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_paint (surface->recording_surface, op, source, clip); +} + +static cairo_int_status_t +_cairo_paginated_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_mask (surface->recording_surface, op, source, mask, clip); +} + +static cairo_int_status_t +_cairo_paginated_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_stroke (surface->recording_surface, op, source, + path, style, + ctm, ctm_inverse, + tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_paginated_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_fill (surface->recording_surface, op, source, + path, fill_rule, + tolerance, antialias, + clip); +} + +static cairo_bool_t +_cairo_paginated_surface_has_show_text_glyphs (void *abstract_surface) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return cairo_surface_has_show_text_glyphs (surface->target); +} + +static cairo_int_status_t +_cairo_paginated_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_show_text_glyphs (surface->recording_surface, op, source, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font, + clip); +} + +static const char ** +_cairo_paginated_surface_get_supported_mime_types (void *abstract_surface) +{ + cairo_paginated_surface_t *surface = abstract_surface; + + if (surface->target->backend->get_supported_mime_types) + return surface->target->backend->get_supported_mime_types (surface->target); + + return NULL; +} + +static cairo_surface_t * +_cairo_paginated_surface_snapshot (void *abstract_other) +{ + cairo_paginated_surface_t *other = abstract_other; + + return other->recording_surface->backend->snapshot (other->recording_surface); +} + +static cairo_t * +_cairo_paginated_context_create (void *target) +{ + cairo_paginated_surface_t *surface = target; + + if (_cairo_surface_is_subsurface (&surface->base)) + surface = (cairo_paginated_surface_t *) + _cairo_surface_subsurface_get_target (&surface->base); + + return surface->recording_surface->backend->create_context (target); +} + +static const cairo_surface_backend_t cairo_paginated_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, + _cairo_paginated_surface_finish, + + _cairo_paginated_context_create, + + _cairo_paginated_surface_create_similar, + NULL, /* create simlar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_paginated_surface_source, + _cairo_paginated_surface_acquire_source_image, + _cairo_paginated_surface_release_source_image, + _cairo_paginated_surface_snapshot, + + _cairo_paginated_surface_copy_page, + _cairo_paginated_surface_show_page, + + _cairo_paginated_surface_get_extents, + _cairo_paginated_surface_get_font_options, + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_paginated_surface_paint, + _cairo_paginated_surface_mask, + _cairo_paginated_surface_stroke, + _cairo_paginated_surface_fill, + NULL, /* fill_stroke */ + NULL, /* show_glyphs */ + _cairo_paginated_surface_has_show_text_glyphs, + _cairo_paginated_surface_show_text_glyphs, + _cairo_paginated_surface_get_supported_mime_types, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-bounds.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-bounds.c new file mode 100644 index 00000000000..9c7222426d3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-bounds.c @@ -0,0 +1,207 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" +#include "cairo-box-inline.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" + +typedef struct _cairo_path_bounder { + cairo_point_t current_point; + cairo_bool_t has_extents; + cairo_box_t extents; +} cairo_path_bounder_t; + +static cairo_status_t +_cairo_path_bounder_move_to (void *closure, + const cairo_point_t *point) +{ + cairo_path_bounder_t *bounder = closure; + + bounder->current_point = *point; + + if (likely (bounder->has_extents)) { + _cairo_box_add_point (&bounder->extents, point); + } else { + bounder->has_extents = TRUE; + _cairo_box_set (&bounder->extents, point, point); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_bounder_line_to (void *closure, + const cairo_point_t *point) +{ + cairo_path_bounder_t *bounder = closure; + + bounder->current_point = *point; + _cairo_box_add_point (&bounder->extents, point); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_bounder_curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + cairo_path_bounder_t *bounder = closure; + + _cairo_box_add_curve_to (&bounder->extents, + &bounder->current_point, + b, c, d); + bounder->current_point = *d; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_bounder_close_path (void *closure) +{ + return CAIRO_STATUS_SUCCESS; +} + +cairo_bool_t +_cairo_path_bounder_extents (const cairo_path_fixed_t *path, + cairo_box_t *extents) +{ + cairo_path_bounder_t bounder; + cairo_status_t status; + + bounder.has_extents = FALSE; + status = _cairo_path_fixed_interpret (path, + _cairo_path_bounder_move_to, + _cairo_path_bounder_line_to, + _cairo_path_bounder_curve_to, + _cairo_path_bounder_close_path, + &bounder); + assert (!status); + + if (bounder.has_extents) + *extents = bounder.extents; + + return bounder.has_extents; +} + +void +_cairo_path_fixed_approximate_clip_extents (const cairo_path_fixed_t *path, + cairo_rectangle_int_t *extents) +{ + _cairo_path_fixed_approximate_fill_extents (path, extents); +} + +void +_cairo_path_fixed_approximate_fill_extents (const cairo_path_fixed_t *path, + cairo_rectangle_int_t *extents) +{ + _cairo_path_fixed_fill_extents (path, CAIRO_FILL_RULE_WINDING, 0, extents); +} + +void +_cairo_path_fixed_fill_extents (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_rectangle_int_t *extents) +{ + if (path->extents.p1.x < path->extents.p2.x && + path->extents.p1.y < path->extents.p2.y) { + _cairo_box_round_to_rectangle (&path->extents, extents); + } else { + extents->x = extents->y = 0; + extents->width = extents->height = 0; + } +} + +/* Adjusts the fill extents (above) by the device-space pen. */ +void +_cairo_path_fixed_approximate_stroke_extents (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + cairo_rectangle_int_t *extents) +{ + if (path->has_extents) { + cairo_box_t box_extents; + double dx, dy; + + _cairo_stroke_style_max_distance_from_path (style, path, ctm, &dx, &dy); + + box_extents = path->extents; + box_extents.p1.x -= _cairo_fixed_from_double (dx); + box_extents.p1.y -= _cairo_fixed_from_double (dy); + box_extents.p2.x += _cairo_fixed_from_double (dx); + box_extents.p2.y += _cairo_fixed_from_double (dy); + + _cairo_box_round_to_rectangle (&box_extents, extents); + } else { + extents->x = extents->y = 0; + extents->width = extents->height = 0; + } +} + +cairo_status_t +_cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_rectangle_int_t *extents) +{ + cairo_polygon_t polygon; + cairo_status_t status; + + _cairo_polygon_init (&polygon, NULL, 0); + status = _cairo_path_fixed_stroke_to_polygon (path, + stroke_style, + ctm, ctm_inverse, + tolerance, + &polygon); + _cairo_box_round_to_rectangle (&polygon.extents, extents); + _cairo_polygon_fini (&polygon); + + return status; +} + +cairo_bool_t +_cairo_path_fixed_extents (const cairo_path_fixed_t *path, + cairo_box_t *box) +{ + *box = path->extents; + return path->has_extents; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-fill.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-fill.c new file mode 100644 index 00000000000..4000c9c586e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-fill.c @@ -0,0 +1,341 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-region-private.h" +#include "cairo-traps-private.h" + +typedef struct cairo_filler { + cairo_polygon_t *polygon; + double tolerance; + + cairo_box_t limit; + cairo_bool_t has_limits; + + cairo_point_t current_point; + cairo_point_t last_move_to; +} cairo_filler_t; + +static cairo_status_t +_cairo_filler_line_to (void *closure, + const cairo_point_t *point) +{ + cairo_filler_t *filler = closure; + cairo_status_t status; + + status = _cairo_polygon_add_external_edge (filler->polygon, + &filler->current_point, + point); + + filler->current_point = *point; + + return status; +} + +static cairo_status_t +_cairo_filler_close (void *closure) +{ + cairo_filler_t *filler = closure; + + /* close the subpath */ + return _cairo_filler_line_to (closure, &filler->last_move_to); +} + +static cairo_status_t +_cairo_filler_move_to (void *closure, + const cairo_point_t *point) +{ + cairo_filler_t *filler = closure; + cairo_status_t status; + + /* close current subpath */ + status = _cairo_filler_close (closure); + if (unlikely (status)) + return status; + + /* make sure that the closure represents a degenerate path */ + filler->current_point = *point; + filler->last_move_to = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_filler_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + cairo_filler_t *filler = closure; + cairo_spline_t spline; + + if (filler->has_limits) { + if (! _cairo_spline_intersects (&filler->current_point, p1, p2, p3, + &filler->limit)) + return _cairo_filler_line_to (filler, p3); + } + + if (! _cairo_spline_init (&spline, + (cairo_spline_add_point_func_t)_cairo_filler_line_to, filler, + &filler->current_point, p1, p2, p3)) + { + return _cairo_filler_line_to (closure, p3); + } + + return _cairo_spline_decompose (&spline, filler->tolerance); +} + +cairo_status_t +_cairo_path_fixed_fill_to_polygon (const cairo_path_fixed_t *path, + double tolerance, + cairo_polygon_t *polygon) +{ + cairo_filler_t filler; + cairo_status_t status; + + filler.polygon = polygon; + filler.tolerance = tolerance; + + filler.has_limits = FALSE; + if (polygon->num_limits) { + filler.has_limits = TRUE; + filler.limit = polygon->limit; + } + + /* make sure that the closure represents a degenerate path */ + filler.current_point.x = 0; + filler.current_point.y = 0; + filler.last_move_to = filler.current_point; + + status = _cairo_path_fixed_interpret (path, + _cairo_filler_move_to, + _cairo_filler_line_to, + _cairo_filler_curve_to, + _cairo_filler_close, + &filler); + if (unlikely (status)) + return status; + + return _cairo_filler_close (&filler); +} + +typedef struct cairo_filler_rectilinear_aligned { + cairo_polygon_t *polygon; + + cairo_point_t current_point; + cairo_point_t last_move_to; +} cairo_filler_ra_t; + +static cairo_status_t +_cairo_filler_ra_line_to (void *closure, + const cairo_point_t *point) +{ + cairo_filler_ra_t *filler = closure; + cairo_status_t status; + cairo_point_t p; + + p.x = _cairo_fixed_round_down (point->x); + p.y = _cairo_fixed_round_down (point->y); + + status = _cairo_polygon_add_external_edge (filler->polygon, + &filler->current_point, + &p); + + filler->current_point = p; + + return status; +} + +static cairo_status_t +_cairo_filler_ra_close (void *closure) +{ + cairo_filler_ra_t *filler = closure; + return _cairo_filler_ra_line_to (closure, &filler->last_move_to); +} + +static cairo_status_t +_cairo_filler_ra_move_to (void *closure, + const cairo_point_t *point) +{ + cairo_filler_ra_t *filler = closure; + cairo_status_t status; + cairo_point_t p; + + /* close current subpath */ + status = _cairo_filler_ra_close (closure); + if (unlikely (status)) + return status; + + p.x = _cairo_fixed_round_down (point->x); + p.y = _cairo_fixed_round_down (point->y); + + /* make sure that the closure represents a degenerate path */ + filler->current_point = p; + filler->last_move_to = p; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_path_fixed_fill_rectilinear_to_polygon (const cairo_path_fixed_t *path, + cairo_antialias_t antialias, + cairo_polygon_t *polygon) +{ + cairo_filler_ra_t filler; + cairo_status_t status; + + if (antialias != CAIRO_ANTIALIAS_NONE) + return _cairo_path_fixed_fill_to_polygon (path, 0., polygon); + + filler.polygon = polygon; + + /* make sure that the closure represents a degenerate path */ + filler.current_point.x = 0; + filler.current_point.y = 0; + filler.last_move_to = filler.current_point; + + status = _cairo_path_fixed_interpret_flat (path, + _cairo_filler_ra_move_to, + _cairo_filler_ra_line_to, + _cairo_filler_ra_close, + &filler, + 0.); + if (unlikely (status)) + return status; + + return _cairo_filler_ra_close (&filler); +} + +cairo_status_t +_cairo_path_fixed_fill_to_traps (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_traps_t *traps) +{ + cairo_polygon_t polygon; + cairo_status_t status; + + if (_cairo_path_fixed_fill_is_empty (path)) + return CAIRO_STATUS_SUCCESS; + + _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); + status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); + if (unlikely (status || polygon.num_edges == 0)) + goto CLEANUP; + + status = _cairo_bentley_ottmann_tessellate_polygon (traps, + &polygon, fill_rule); + + CLEANUP: + _cairo_polygon_fini (&polygon); + return status; +} + +static cairo_status_t +_cairo_path_fixed_fill_rectilinear_tessellate_to_boxes (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias, + cairo_boxes_t *boxes) +{ + cairo_polygon_t polygon; + cairo_status_t status; + + _cairo_polygon_init (&polygon, boxes->limits, boxes->num_limits); + boxes->num_limits = 0; + + /* tolerance will be ignored as the path is rectilinear */ + status = _cairo_path_fixed_fill_rectilinear_to_polygon (path, antialias, &polygon); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + status = + _cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (&polygon, + fill_rule, + boxes); + } + + _cairo_polygon_fini (&polygon); + + return status; +} + +cairo_status_t +_cairo_path_fixed_fill_rectilinear_to_boxes (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias, + cairo_boxes_t *boxes) +{ + cairo_path_fixed_iter_t iter; + cairo_status_t status; + cairo_box_t box; + + if (_cairo_path_fixed_is_box (path, &box)) + return _cairo_boxes_add (boxes, antialias, &box); + + _cairo_path_fixed_iter_init (&iter, path); + while (_cairo_path_fixed_iter_is_fill_box (&iter, &box)) { + if (box.p1.y == box.p2.y || box.p1.x == box.p2.x) + continue; + + if (box.p1.y > box.p2.y) { + cairo_fixed_t t; + + t = box.p1.y; + box.p1.y = box.p2.y; + box.p2.y = t; + + t = box.p1.x; + box.p1.x = box.p2.x; + box.p2.x = t; + } + + status = _cairo_boxes_add (boxes, antialias, &box); + if (unlikely (status)) + return status; + } + + if (_cairo_path_fixed_iter_at_end (&iter)) + return _cairo_bentley_ottmann_tessellate_boxes (boxes, fill_rule, boxes); + + /* path is not rectangular, try extracting clipped rectilinear edges */ + _cairo_boxes_clear (boxes); + return _cairo_path_fixed_fill_rectilinear_tessellate_to_boxes (path, + fill_rule, + antialias, + boxes); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-fixed-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-path-fixed-private.h new file mode 100644 index 00000000000..cf7cd0836fb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-fixed-private.h @@ -0,0 +1,206 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PATH_FIXED_PRIVATE_H +#define CAIRO_PATH_FIXED_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" +#include "cairo-list-private.h" + +#define WATCH_PATH 0 +#if WATCH_PATH +#include +#endif + +enum cairo_path_op { + CAIRO_PATH_OP_MOVE_TO = 0, + CAIRO_PATH_OP_LINE_TO = 1, + CAIRO_PATH_OP_CURVE_TO = 2, + CAIRO_PATH_OP_CLOSE_PATH = 3 +}; + +/* we want to make sure a single byte is used for the enum */ +typedef char cairo_path_op_t; + +/* make _cairo_path_fixed fit into ~512 bytes -- about 50 items */ +#define CAIRO_PATH_BUF_SIZE ((512 - sizeof (cairo_path_buf_t)) \ + / (2 * sizeof (cairo_point_t) + sizeof (cairo_path_op_t))) + +#define cairo_path_head(path__) (&(path__)->buf.base) +#define cairo_path_tail(path__) cairo_path_buf_prev (cairo_path_head (path__)) + +#define cairo_path_buf_next(pos__) \ + cairo_list_entry ((pos__)->link.next, cairo_path_buf_t, link) +#define cairo_path_buf_prev(pos__) \ + cairo_list_entry ((pos__)->link.prev, cairo_path_buf_t, link) + +#define cairo_path_foreach_buf_start(pos__, path__) \ + pos__ = cairo_path_head (path__); do +#define cairo_path_foreach_buf_end(pos__, path__) \ + while ((pos__ = cairo_path_buf_next (pos__)) != cairo_path_head (path__)) + + +typedef struct _cairo_path_buf { + cairo_list_t link; + unsigned int num_ops; + unsigned int size_ops; + unsigned int num_points; + unsigned int size_points; + + cairo_path_op_t *op; + cairo_point_t *points; +} cairo_path_buf_t; + +typedef struct _cairo_path_buf_fixed { + cairo_path_buf_t base; + + cairo_path_op_t op[CAIRO_PATH_BUF_SIZE]; + cairo_point_t points[2 * CAIRO_PATH_BUF_SIZE]; +} cairo_path_buf_fixed_t; + +/* + NOTES: + has_curve_to => !stroke_is_rectilinear + fill_is_rectilinear => stroke_is_rectilinear + fill_is_empty => fill_is_rectilinear + fill_maybe_region => fill_is_rectilinear +*/ +struct _cairo_path_fixed { + cairo_point_t last_move_point; + cairo_point_t current_point; + unsigned int has_current_point : 1; + unsigned int needs_move_to : 1; + unsigned int has_extents : 1; + unsigned int has_curve_to : 1; + unsigned int stroke_is_rectilinear : 1; + unsigned int fill_is_rectilinear : 1; + unsigned int fill_maybe_region : 1; + unsigned int fill_is_empty : 1; + + cairo_box_t extents; + + cairo_path_buf_fixed_t buf; +}; + +cairo_private void +_cairo_path_fixed_translate (cairo_path_fixed_t *path, + cairo_fixed_t offx, + cairo_fixed_t offy); + +cairo_private cairo_status_t +_cairo_path_fixed_append (cairo_path_fixed_t *path, + const cairo_path_fixed_t *other, + cairo_fixed_t tx, + cairo_fixed_t ty); + +cairo_private unsigned long +_cairo_path_fixed_hash (const cairo_path_fixed_t *path); + +cairo_private unsigned long +_cairo_path_fixed_size (const cairo_path_fixed_t *path); + +cairo_private cairo_bool_t +_cairo_path_fixed_equal (const cairo_path_fixed_t *a, + const cairo_path_fixed_t *b); + +typedef struct _cairo_path_fixed_iter { + const cairo_path_buf_t *first; + const cairo_path_buf_t *buf; + unsigned int n_op; + unsigned int n_point; +} cairo_path_fixed_iter_t; + +cairo_private void +_cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter, + const cairo_path_fixed_t *path); + +cairo_private cairo_bool_t +_cairo_path_fixed_iter_is_fill_box (cairo_path_fixed_iter_t *_iter, + cairo_box_t *box); + +cairo_private cairo_bool_t +_cairo_path_fixed_iter_at_end (const cairo_path_fixed_iter_t *iter); + +static inline cairo_bool_t +_cairo_path_fixed_fill_is_empty (const cairo_path_fixed_t *path) +{ + return path->fill_is_empty; +} + +static inline cairo_bool_t +_cairo_path_fixed_fill_is_rectilinear (const cairo_path_fixed_t *path) +{ + if (! path->fill_is_rectilinear) + return 0; + + if (! path->has_current_point || path->needs_move_to) + return 1; + + /* check whether the implicit close preserves the rectilinear property */ + return path->current_point.x == path->last_move_point.x || + path->current_point.y == path->last_move_point.y; +} + +static inline cairo_bool_t +_cairo_path_fixed_stroke_is_rectilinear (const cairo_path_fixed_t *path) +{ + return path->stroke_is_rectilinear; +} + +static inline cairo_bool_t +_cairo_path_fixed_fill_maybe_region (const cairo_path_fixed_t *path) +{ + if (! path->fill_maybe_region) + return 0; + + if (! path->has_current_point || path->needs_move_to) + return 1; + + /* check whether the implicit close preserves the rectilinear property + * (the integer point property is automatically preserved) + */ + return path->current_point.x == path->last_move_point.x || + path->current_point.y == path->last_move_point.y; +} + +cairo_private cairo_bool_t +_cairo_path_fixed_is_stroke_box (const cairo_path_fixed_t *path, + cairo_box_t *box); + +cairo_private cairo_bool_t +_cairo_path_fixed_is_simple_quad (const cairo_path_fixed_t *path); + +#endif /* CAIRO_PATH_FIXED_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-fixed.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-fixed.c new file mode 100644 index 00000000000..4bbf496f075 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-fixed.c @@ -0,0 +1,1589 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-error-private.h" +#include "cairo-list-inline.h" +#include "cairo-path-fixed-private.h" +#include "cairo-slope-private.h" + +static cairo_status_t +_cairo_path_fixed_add (cairo_path_fixed_t *path, + cairo_path_op_t op, + const cairo_point_t *points, + int num_points); + +static void +_cairo_path_fixed_add_buf (cairo_path_fixed_t *path, + cairo_path_buf_t *buf); + +static cairo_path_buf_t * +_cairo_path_buf_create (int size_ops, int size_points); + +static void +_cairo_path_buf_destroy (cairo_path_buf_t *buf); + +static void +_cairo_path_buf_add_op (cairo_path_buf_t *buf, + cairo_path_op_t op); + +static void +_cairo_path_buf_add_points (cairo_path_buf_t *buf, + const cairo_point_t *points, + int num_points); + +void +_cairo_path_fixed_init (cairo_path_fixed_t *path) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (path, sizeof (cairo_path_fixed_t))); + + cairo_list_init (&path->buf.base.link); + + path->buf.base.num_ops = 0; + path->buf.base.num_points = 0; + path->buf.base.size_ops = ARRAY_LENGTH (path->buf.op); + path->buf.base.size_points = ARRAY_LENGTH (path->buf.points); + path->buf.base.op = path->buf.op; + path->buf.base.points = path->buf.points; + + path->current_point.x = 0; + path->current_point.y = 0; + path->last_move_point = path->current_point; + + path->has_current_point = FALSE; + path->needs_move_to = TRUE; + path->has_extents = FALSE; + path->has_curve_to = FALSE; + path->stroke_is_rectilinear = TRUE; + path->fill_is_rectilinear = TRUE; + path->fill_maybe_region = TRUE; + path->fill_is_empty = TRUE; + + path->extents.p1.x = path->extents.p1.y = 0; + path->extents.p2.x = path->extents.p2.y = 0; +} + +cairo_status_t +_cairo_path_fixed_init_copy (cairo_path_fixed_t *path, + const cairo_path_fixed_t *other) +{ + cairo_path_buf_t *buf, *other_buf; + unsigned int num_points, num_ops; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (path, sizeof (cairo_path_fixed_t))); + + cairo_list_init (&path->buf.base.link); + + path->buf.base.op = path->buf.op; + path->buf.base.points = path->buf.points; + path->buf.base.size_ops = ARRAY_LENGTH (path->buf.op); + path->buf.base.size_points = ARRAY_LENGTH (path->buf.points); + + path->current_point = other->current_point; + path->last_move_point = other->last_move_point; + + path->has_current_point = other->has_current_point; + path->needs_move_to = other->needs_move_to; + path->has_extents = other->has_extents; + path->has_curve_to = other->has_curve_to; + path->stroke_is_rectilinear = other->stroke_is_rectilinear; + path->fill_is_rectilinear = other->fill_is_rectilinear; + path->fill_maybe_region = other->fill_maybe_region; + path->fill_is_empty = other->fill_is_empty; + + path->extents = other->extents; + + path->buf.base.num_ops = other->buf.base.num_ops; + path->buf.base.num_points = other->buf.base.num_points; + memcpy (path->buf.op, other->buf.base.op, + other->buf.base.num_ops * sizeof (other->buf.op[0])); + memcpy (path->buf.points, other->buf.points, + other->buf.base.num_points * sizeof (other->buf.points[0])); + + num_points = num_ops = 0; + for (other_buf = cairo_path_buf_next (cairo_path_head (other)); + other_buf != cairo_path_head (other); + other_buf = cairo_path_buf_next (other_buf)) + { + num_ops += other_buf->num_ops; + num_points += other_buf->num_points; + } + + if (num_ops) { + buf = _cairo_path_buf_create (num_ops, num_points); + if (unlikely (buf == NULL)) { + _cairo_path_fixed_fini (path); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + for (other_buf = cairo_path_buf_next (cairo_path_head (other)); + other_buf != cairo_path_head (other); + other_buf = cairo_path_buf_next (other_buf)) + { + memcpy (buf->op + buf->num_ops, other_buf->op, + other_buf->num_ops * sizeof (buf->op[0])); + buf->num_ops += other_buf->num_ops; + + memcpy (buf->points + buf->num_points, other_buf->points, + other_buf->num_points * sizeof (buf->points[0])); + buf->num_points += other_buf->num_points; + } + + _cairo_path_fixed_add_buf (path, buf); + } + + return CAIRO_STATUS_SUCCESS; +} + +unsigned long +_cairo_path_fixed_hash (const cairo_path_fixed_t *path) +{ + unsigned long hash = _CAIRO_HASH_INIT_VALUE; + const cairo_path_buf_t *buf; + unsigned int count; + + count = 0; + cairo_path_foreach_buf_start (buf, path) { + hash = _cairo_hash_bytes (hash, buf->op, + buf->num_ops * sizeof (buf->op[0])); + count += buf->num_ops; + } cairo_path_foreach_buf_end (buf, path); + hash = _cairo_hash_bytes (hash, &count, sizeof (count)); + + count = 0; + cairo_path_foreach_buf_start (buf, path) { + hash = _cairo_hash_bytes (hash, buf->points, + buf->num_points * sizeof (buf->points[0])); + count += buf->num_points; + } cairo_path_foreach_buf_end (buf, path); + hash = _cairo_hash_bytes (hash, &count, sizeof (count)); + + return hash; +} + +unsigned long +_cairo_path_fixed_size (const cairo_path_fixed_t *path) +{ + const cairo_path_buf_t *buf; + int num_points, num_ops; + + num_ops = num_points = 0; + cairo_path_foreach_buf_start (buf, path) { + num_ops += buf->num_ops; + num_points += buf->num_points; + } cairo_path_foreach_buf_end (buf, path); + + return num_ops * sizeof (buf->op[0]) + + num_points * sizeof (buf->points[0]); +} + +cairo_bool_t +_cairo_path_fixed_equal (const cairo_path_fixed_t *a, + const cairo_path_fixed_t *b) +{ + const cairo_path_buf_t *buf_a, *buf_b; + const cairo_path_op_t *ops_a, *ops_b; + const cairo_point_t *points_a, *points_b; + int num_points_a, num_ops_a; + int num_points_b, num_ops_b; + + if (a == b) + return TRUE; + + /* use the flags to quickly differentiate based on contents */ + if (a->has_curve_to != b->has_curve_to) + { + return FALSE; + } + + if (a->extents.p1.x != b->extents.p1.x || + a->extents.p1.y != b->extents.p1.y || + a->extents.p2.x != b->extents.p2.x || + a->extents.p2.y != b->extents.p2.y) + { + return FALSE; + } + + num_ops_a = num_points_a = 0; + cairo_path_foreach_buf_start (buf_a, a) { + num_ops_a += buf_a->num_ops; + num_points_a += buf_a->num_points; + } cairo_path_foreach_buf_end (buf_a, a); + + num_ops_b = num_points_b = 0; + cairo_path_foreach_buf_start (buf_b, b) { + num_ops_b += buf_b->num_ops; + num_points_b += buf_b->num_points; + } cairo_path_foreach_buf_end (buf_b, b); + + if (num_ops_a == 0 && num_ops_b == 0) + return TRUE; + + if (num_ops_a != num_ops_b || num_points_a != num_points_b) + return FALSE; + + buf_a = cairo_path_head (a); + num_points_a = buf_a->num_points; + num_ops_a = buf_a->num_ops; + ops_a = buf_a->op; + points_a = buf_a->points; + + buf_b = cairo_path_head (b); + num_points_b = buf_b->num_points; + num_ops_b = buf_b->num_ops; + ops_b = buf_b->op; + points_b = buf_b->points; + + while (TRUE) { + int num_ops = MIN (num_ops_a, num_ops_b); + int num_points = MIN (num_points_a, num_points_b); + + if (memcmp (ops_a, ops_b, num_ops * sizeof (cairo_path_op_t))) + return FALSE; + if (memcmp (points_a, points_b, num_points * sizeof (cairo_point_t))) + return FALSE; + + num_ops_a -= num_ops; + ops_a += num_ops; + num_points_a -= num_points; + points_a += num_points; + if (num_ops_a == 0 || num_points_a == 0) { + if (num_ops_a || num_points_a) + return FALSE; + + buf_a = cairo_path_buf_next (buf_a); + if (buf_a == cairo_path_head (a)) + break; + + num_points_a = buf_a->num_points; + num_ops_a = buf_a->num_ops; + ops_a = buf_a->op; + points_a = buf_a->points; + } + + num_ops_b -= num_ops; + ops_b += num_ops; + num_points_b -= num_points; + points_b += num_points; + if (num_ops_b == 0 || num_points_b == 0) { + if (num_ops_b || num_points_b) + return FALSE; + + buf_b = cairo_path_buf_next (buf_b); + if (buf_b == cairo_path_head (b)) + break; + + num_points_b = buf_b->num_points; + num_ops_b = buf_b->num_ops; + ops_b = buf_b->op; + points_b = buf_b->points; + } + } + + return TRUE; +} + +cairo_path_fixed_t * +_cairo_path_fixed_create (void) +{ + cairo_path_fixed_t *path; + + path = malloc (sizeof (cairo_path_fixed_t)); + if (!path) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + _cairo_path_fixed_init (path); + return path; +} + +void +_cairo_path_fixed_fini (cairo_path_fixed_t *path) +{ + cairo_path_buf_t *buf; + + buf = cairo_path_buf_next (cairo_path_head (path)); + while (buf != cairo_path_head (path)) { + cairo_path_buf_t *this = buf; + buf = cairo_path_buf_next (buf); + _cairo_path_buf_destroy (this); + } + + VG (VALGRIND_MAKE_MEM_NOACCESS (path, sizeof (cairo_path_fixed_t))); +} + +void +_cairo_path_fixed_destroy (cairo_path_fixed_t *path) +{ + _cairo_path_fixed_fini (path); + free (path); +} + +static cairo_path_op_t +_cairo_path_fixed_last_op (cairo_path_fixed_t *path) +{ + cairo_path_buf_t *buf; + + buf = cairo_path_tail (path); + assert (buf->num_ops != 0); + + return buf->op[buf->num_ops - 1]; +} + +static inline const cairo_point_t * +_cairo_path_fixed_penultimate_point (cairo_path_fixed_t *path) +{ + cairo_path_buf_t *buf; + + buf = cairo_path_tail (path); + if (likely (buf->num_points >= 2)) { + return &buf->points[buf->num_points - 2]; + } else { + cairo_path_buf_t *prev_buf = cairo_path_buf_prev (buf); + + assert (prev_buf->num_points >= 2 - buf->num_points); + return &prev_buf->points[prev_buf->num_points - (2 - buf->num_points)]; + } +} + +static void +_cairo_path_fixed_drop_line_to (cairo_path_fixed_t *path) +{ + cairo_path_buf_t *buf; + + assert (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO); + + buf = cairo_path_tail (path); + buf->num_points--; + buf->num_ops--; +} + +cairo_status_t +_cairo_path_fixed_move_to (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y) +{ + _cairo_path_fixed_new_sub_path (path); + + path->has_current_point = TRUE; + path->current_point.x = x; + path->current_point.y = y; + path->last_move_point = path->current_point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_fixed_move_to_apply (cairo_path_fixed_t *path) +{ + if (likely (! path->needs_move_to)) + return CAIRO_STATUS_SUCCESS; + + path->needs_move_to = FALSE; + + if (path->has_extents) { + _cairo_box_add_point (&path->extents, &path->current_point); + } else { + _cairo_box_set (&path->extents, &path->current_point, &path->current_point); + path->has_extents = TRUE; + } + + if (path->fill_maybe_region) { + path->fill_maybe_region = _cairo_fixed_is_integer (path->current_point.x) && + _cairo_fixed_is_integer (path->current_point.y); + } + + path->last_move_point = path->current_point; + + return _cairo_path_fixed_add (path, CAIRO_PATH_OP_MOVE_TO, &path->current_point, 1); +} + +void +_cairo_path_fixed_new_sub_path (cairo_path_fixed_t *path) +{ + if (! path->needs_move_to) { + /* If the current subpath doesn't need_move_to, it contains at least one command */ + if (path->fill_is_rectilinear) { + /* Implicitly close for fill */ + path->fill_is_rectilinear = path->current_point.x == path->last_move_point.x || + path->current_point.y == path->last_move_point.y; + path->fill_maybe_region &= path->fill_is_rectilinear; + } + path->needs_move_to = TRUE; + } + + path->has_current_point = FALSE; +} + +cairo_status_t +_cairo_path_fixed_rel_move_to (cairo_path_fixed_t *path, + cairo_fixed_t dx, + cairo_fixed_t dy) +{ + if (unlikely (! path->has_current_point)) + return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); + + return _cairo_path_fixed_move_to (path, + path->current_point.x + dx, + path->current_point.y + dy); + +} + +cairo_status_t +_cairo_path_fixed_line_to (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y) +{ + cairo_status_t status; + cairo_point_t point; + + point.x = x; + point.y = y; + + /* When there is not yet a current point, the line_to operation + * becomes a move_to instead. Note: We have to do this by + * explicitly calling into _cairo_path_fixed_move_to to ensure + * that the last_move_point state is updated properly. + */ + if (! path->has_current_point) + return _cairo_path_fixed_move_to (path, point.x, point.y); + + status = _cairo_path_fixed_move_to_apply (path); + if (unlikely (status)) + return status; + + /* If the previous op was but the initial MOVE_TO and this segment + * is degenerate, then we can simply skip this point. Note that + * a move-to followed by a degenerate line-to is a valid path for + * stroking, but at all other times is simply a degenerate segment. + */ + if (_cairo_path_fixed_last_op (path) != CAIRO_PATH_OP_MOVE_TO) { + if (x == path->current_point.x && y == path->current_point.y) + return CAIRO_STATUS_SUCCESS; + } + + /* If the previous op was also a LINE_TO with the same gradient, + * then just change its end-point rather than adding a new op. + */ + if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) { + const cairo_point_t *p; + + p = _cairo_path_fixed_penultimate_point (path); + if (p->x == path->current_point.x && p->y == path->current_point.y) { + /* previous line element was degenerate, replace */ + _cairo_path_fixed_drop_line_to (path); + } else { + cairo_slope_t prev, self; + + _cairo_slope_init (&prev, p, &path->current_point); + _cairo_slope_init (&self, &path->current_point, &point); + if (_cairo_slope_equal (&prev, &self) && + /* cannot trim anti-parallel segments whilst stroking */ + ! _cairo_slope_backwards (&prev, &self)) + { + _cairo_path_fixed_drop_line_to (path); + /* In this case the flags might be more restrictive than + * what we actually need. + * When changing the flags definition we should check if + * changing the line_to point can affect them. + */ + } + } + } + + if (path->stroke_is_rectilinear) { + path->stroke_is_rectilinear = path->current_point.x == x || + path->current_point.y == y; + path->fill_is_rectilinear &= path->stroke_is_rectilinear; + path->fill_maybe_region &= path->fill_is_rectilinear; + if (path->fill_maybe_region) { + path->fill_maybe_region = _cairo_fixed_is_integer (x) && + _cairo_fixed_is_integer (y); + } + if (path->fill_is_empty) { + path->fill_is_empty = path->current_point.x == x && + path->current_point.y == y; + } + } + + path->current_point = point; + + _cairo_box_add_point (&path->extents, &point); + + return _cairo_path_fixed_add (path, CAIRO_PATH_OP_LINE_TO, &point, 1); +} + +cairo_status_t +_cairo_path_fixed_rel_line_to (cairo_path_fixed_t *path, + cairo_fixed_t dx, + cairo_fixed_t dy) +{ + if (unlikely (! path->has_current_point)) + return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); + + return _cairo_path_fixed_line_to (path, + path->current_point.x + dx, + path->current_point.y + dy); +} + +cairo_status_t +_cairo_path_fixed_curve_to (cairo_path_fixed_t *path, + cairo_fixed_t x0, cairo_fixed_t y0, + cairo_fixed_t x1, cairo_fixed_t y1, + cairo_fixed_t x2, cairo_fixed_t y2) +{ + cairo_status_t status; + cairo_point_t point[3]; + + /* If this curves does not move, replace it with a line-to. + * This frequently happens with rounded-rectangles and r==0. + */ + if (path->current_point.x == x2 && path->current_point.y == y2) { + if (x1 == x2 && x0 == x2 && y1 == y2 && y0 == y2) + return _cairo_path_fixed_line_to (path, x2, y2); + + /* We may want to check for the absence of a cusp, in which case + * we can also replace the curve-to with a line-to. + */ + } + + /* make sure subpaths are started properly */ + if (! path->has_current_point) { + status = _cairo_path_fixed_move_to (path, x0, y0); + assert (status == CAIRO_STATUS_SUCCESS); + } + + status = _cairo_path_fixed_move_to_apply (path); + if (unlikely (status)) + return status; + + /* If the previous op was a degenerate LINE_TO, drop it. */ + if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) { + const cairo_point_t *p; + + p = _cairo_path_fixed_penultimate_point (path); + if (p->x == path->current_point.x && p->y == path->current_point.y) { + /* previous line element was degenerate, replace */ + _cairo_path_fixed_drop_line_to (path); + } + } + + point[0].x = x0; point[0].y = y0; + point[1].x = x1; point[1].y = y1; + point[2].x = x2; point[2].y = y2; + + _cairo_box_add_curve_to (&path->extents, &path->current_point, + &point[0], &point[1], &point[2]); + + path->current_point = point[2]; + path->has_curve_to = TRUE; + path->stroke_is_rectilinear = FALSE; + path->fill_is_rectilinear = FALSE; + path->fill_maybe_region = FALSE; + path->fill_is_empty = FALSE; + + return _cairo_path_fixed_add (path, CAIRO_PATH_OP_CURVE_TO, point, 3); +} + +cairo_status_t +_cairo_path_fixed_rel_curve_to (cairo_path_fixed_t *path, + cairo_fixed_t dx0, cairo_fixed_t dy0, + cairo_fixed_t dx1, cairo_fixed_t dy1, + cairo_fixed_t dx2, cairo_fixed_t dy2) +{ + if (unlikely (! path->has_current_point)) + return _cairo_error (CAIRO_STATUS_NO_CURRENT_POINT); + + return _cairo_path_fixed_curve_to (path, + path->current_point.x + dx0, + path->current_point.y + dy0, + + path->current_point.x + dx1, + path->current_point.y + dy1, + + path->current_point.x + dx2, + path->current_point.y + dy2); +} + +cairo_status_t +_cairo_path_fixed_close_path (cairo_path_fixed_t *path) +{ + cairo_status_t status; + + if (! path->has_current_point) + return CAIRO_STATUS_SUCCESS; + + /* + * Add a line_to, to compute flags and solve any degeneracy. + * It will be removed later (if it was actually added). + */ + status = _cairo_path_fixed_line_to (path, + path->last_move_point.x, + path->last_move_point.y); + if (unlikely (status)) + return status; + + /* + * If the command used to close the path is a line_to, drop it. + * We must check that last command is actually a line_to, + * because the path could have been closed with a curve_to (and + * the previous line_to not added as it would be degenerate). + */ + if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) + _cairo_path_fixed_drop_line_to (path); + + path->needs_move_to = TRUE; /* After close_path, add an implicit move_to */ + + return _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0); +} + +cairo_bool_t +_cairo_path_fixed_get_current_point (cairo_path_fixed_t *path, + cairo_fixed_t *x, + cairo_fixed_t *y) +{ + if (! path->has_current_point) + return FALSE; + + *x = path->current_point.x; + *y = path->current_point.y; + + return TRUE; +} + +static cairo_status_t +_cairo_path_fixed_add (cairo_path_fixed_t *path, + cairo_path_op_t op, + const cairo_point_t *points, + int num_points) +{ + cairo_path_buf_t *buf = cairo_path_tail (path); + + if (buf->num_ops + 1 > buf->size_ops || + buf->num_points + num_points > buf->size_points) + { + buf = _cairo_path_buf_create (buf->num_ops * 2, buf->num_points * 2); + if (unlikely (buf == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_path_fixed_add_buf (path, buf); + } + + if (WATCH_PATH) { + const char *op_str[] = { + "move-to", + "line-to", + "curve-to", + "close-path", + }; + char buf[1024]; + int len = 0; + int i; + + len += snprintf (buf + len, sizeof (buf), "["); + for (i = 0; i < num_points; i++) { + if (i != 0) + len += snprintf (buf + len, sizeof (buf), " "); + len += snprintf (buf + len, sizeof (buf), "(%f, %f)", + _cairo_fixed_to_double (points[i].x), + _cairo_fixed_to_double (points[i].y)); + } + len += snprintf (buf + len, sizeof (buf), "]"); + +#define STRINGIFYFLAG(x) (path->x ? #x " " : "") + fprintf (stderr, + "_cairo_path_fixed_add (%s, %s) [%s%s%s%s%s%s%s%s]\n", + op_str[(int) op], buf, + STRINGIFYFLAG(has_current_point), + STRINGIFYFLAG(needs_move_to), + STRINGIFYFLAG(has_extents), + STRINGIFYFLAG(has_curve_to), + STRINGIFYFLAG(stroke_is_rectilinear), + STRINGIFYFLAG(fill_is_rectilinear), + STRINGIFYFLAG(fill_is_empty), + STRINGIFYFLAG(fill_maybe_region) + ); +#undef STRINGIFYFLAG + } + + _cairo_path_buf_add_op (buf, op); + _cairo_path_buf_add_points (buf, points, num_points); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_path_fixed_add_buf (cairo_path_fixed_t *path, + cairo_path_buf_t *buf) +{ + cairo_list_add_tail (&buf->link, &cairo_path_head (path)->link); +} + +COMPILE_TIME_ASSERT (sizeof (cairo_path_op_t) == 1); +static cairo_path_buf_t * +_cairo_path_buf_create (int size_ops, int size_points) +{ + cairo_path_buf_t *buf; + + /* adjust size_ops to ensure that buf->points is naturally aligned */ + size_ops += sizeof (double) - ((sizeof (cairo_path_buf_t) + size_ops) % sizeof (double)); + buf = _cairo_malloc_ab_plus_c (size_points, sizeof (cairo_point_t), size_ops + sizeof (cairo_path_buf_t)); + if (buf) { + buf->num_ops = 0; + buf->num_points = 0; + buf->size_ops = size_ops; + buf->size_points = size_points; + + buf->op = (cairo_path_op_t *) (buf + 1); + buf->points = (cairo_point_t *) (buf->op + size_ops); + } + + return buf; +} + +static void +_cairo_path_buf_destroy (cairo_path_buf_t *buf) +{ + free (buf); +} + +static void +_cairo_path_buf_add_op (cairo_path_buf_t *buf, + cairo_path_op_t op) +{ + buf->op[buf->num_ops++] = op; +} + +static void +_cairo_path_buf_add_points (cairo_path_buf_t *buf, + const cairo_point_t *points, + int num_points) +{ + if (num_points == 0) + return; + + memcpy (buf->points + buf->num_points, + points, + sizeof (points[0]) * num_points); + buf->num_points += num_points; +} + +cairo_status_t +_cairo_path_fixed_interpret (const cairo_path_fixed_t *path, + cairo_path_fixed_move_to_func_t *move_to, + cairo_path_fixed_line_to_func_t *line_to, + cairo_path_fixed_curve_to_func_t *curve_to, + cairo_path_fixed_close_path_func_t *close_path, + void *closure) +{ + const cairo_path_buf_t *buf; + cairo_status_t status; + + cairo_path_foreach_buf_start (buf, path) { + const cairo_point_t *points = buf->points; + unsigned int i; + + for (i = 0; i < buf->num_ops; i++) { + switch (buf->op[i]) { + case CAIRO_PATH_OP_MOVE_TO: + status = (*move_to) (closure, &points[0]); + points += 1; + break; + case CAIRO_PATH_OP_LINE_TO: + status = (*line_to) (closure, &points[0]); + points += 1; + break; + case CAIRO_PATH_OP_CURVE_TO: + status = (*curve_to) (closure, &points[0], &points[1], &points[2]); + points += 3; + break; + default: + ASSERT_NOT_REACHED; + case CAIRO_PATH_OP_CLOSE_PATH: + status = (*close_path) (closure); + break; + } + + if (unlikely (status)) + return status; + } + } cairo_path_foreach_buf_end (buf, path); + + if (path->needs_move_to && path->has_current_point) + return (*move_to) (closure, &path->current_point); + + return CAIRO_STATUS_SUCCESS; +} + +typedef struct _cairo_path_fixed_append_closure { + cairo_point_t offset; + cairo_path_fixed_t *path; +} cairo_path_fixed_append_closure_t; + +static cairo_status_t +_append_move_to (void *abstract_closure, + const cairo_point_t *point) +{ + cairo_path_fixed_append_closure_t *closure = abstract_closure; + + return _cairo_path_fixed_move_to (closure->path, + point->x + closure->offset.x, + point->y + closure->offset.y); +} + +static cairo_status_t +_append_line_to (void *abstract_closure, + const cairo_point_t *point) +{ + cairo_path_fixed_append_closure_t *closure = abstract_closure; + + return _cairo_path_fixed_line_to (closure->path, + point->x + closure->offset.x, + point->y + closure->offset.y); +} + +static cairo_status_t +_append_curve_to (void *abstract_closure, + const cairo_point_t *p0, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + cairo_path_fixed_append_closure_t *closure = abstract_closure; + + return _cairo_path_fixed_curve_to (closure->path, + p0->x + closure->offset.x, + p0->y + closure->offset.y, + p1->x + closure->offset.x, + p1->y + closure->offset.y, + p2->x + closure->offset.x, + p2->y + closure->offset.y); +} + +static cairo_status_t +_append_close_path (void *abstract_closure) +{ + cairo_path_fixed_append_closure_t *closure = abstract_closure; + + return _cairo_path_fixed_close_path (closure->path); +} + +cairo_status_t +_cairo_path_fixed_append (cairo_path_fixed_t *path, + const cairo_path_fixed_t *other, + cairo_fixed_t tx, + cairo_fixed_t ty) +{ + cairo_path_fixed_append_closure_t closure; + + closure.path = path; + closure.offset.x = tx; + closure.offset.y = ty; + + return _cairo_path_fixed_interpret (other, + _append_move_to, + _append_line_to, + _append_curve_to, + _append_close_path, + &closure); +} + +static void +_cairo_path_fixed_offset_and_scale (cairo_path_fixed_t *path, + cairo_fixed_t offx, + cairo_fixed_t offy, + cairo_fixed_t scalex, + cairo_fixed_t scaley) +{ + cairo_path_buf_t *buf; + unsigned int i; + + if (scalex == CAIRO_FIXED_ONE && scaley == CAIRO_FIXED_ONE) { + _cairo_path_fixed_translate (path, offx, offy); + return; + } + + path->last_move_point.x = _cairo_fixed_mul (scalex, path->last_move_point.x) + offx; + path->last_move_point.y = _cairo_fixed_mul (scaley, path->last_move_point.y) + offy; + path->current_point.x = _cairo_fixed_mul (scalex, path->current_point.x) + offx; + path->current_point.y = _cairo_fixed_mul (scaley, path->current_point.y) + offy; + + path->fill_maybe_region = TRUE; + + cairo_path_foreach_buf_start (buf, path) { + for (i = 0; i < buf->num_points; i++) { + if (scalex != CAIRO_FIXED_ONE) + buf->points[i].x = _cairo_fixed_mul (buf->points[i].x, scalex); + buf->points[i].x += offx; + + if (scaley != CAIRO_FIXED_ONE) + buf->points[i].y = _cairo_fixed_mul (buf->points[i].y, scaley); + buf->points[i].y += offy; + + if (path->fill_maybe_region) { + path->fill_maybe_region = _cairo_fixed_is_integer (buf->points[i].x) && + _cairo_fixed_is_integer (buf->points[i].y); + } + } + } cairo_path_foreach_buf_end (buf, path); + + path->fill_maybe_region &= path->fill_is_rectilinear; + + path->extents.p1.x = _cairo_fixed_mul (scalex, path->extents.p1.x) + offx; + path->extents.p2.x = _cairo_fixed_mul (scalex, path->extents.p2.x) + offx; + if (scalex < 0) { + cairo_fixed_t t = path->extents.p1.x; + path->extents.p1.x = path->extents.p2.x; + path->extents.p2.x = t; + } + + path->extents.p1.y = _cairo_fixed_mul (scaley, path->extents.p1.y) + offy; + path->extents.p2.y = _cairo_fixed_mul (scaley, path->extents.p2.y) + offy; + if (scaley < 0) { + cairo_fixed_t t = path->extents.p1.y; + path->extents.p1.y = path->extents.p2.y; + path->extents.p2.y = t; + } +} + +void +_cairo_path_fixed_translate (cairo_path_fixed_t *path, + cairo_fixed_t offx, + cairo_fixed_t offy) +{ + cairo_path_buf_t *buf; + unsigned int i; + + if (offx == 0 && offy == 0) + return; + + path->last_move_point.x += offx; + path->last_move_point.y += offy; + path->current_point.x += offx; + path->current_point.y += offy; + + path->fill_maybe_region = TRUE; + + cairo_path_foreach_buf_start (buf, path) { + for (i = 0; i < buf->num_points; i++) { + buf->points[i].x += offx; + buf->points[i].y += offy; + + if (path->fill_maybe_region) { + path->fill_maybe_region = _cairo_fixed_is_integer (buf->points[i].x) && + _cairo_fixed_is_integer (buf->points[i].y); + } + } + } cairo_path_foreach_buf_end (buf, path); + + path->fill_maybe_region &= path->fill_is_rectilinear; + + path->extents.p1.x += offx; + path->extents.p1.y += offy; + path->extents.p2.x += offx; + path->extents.p2.y += offy; +} + + +static inline void +_cairo_path_fixed_transform_point (cairo_point_t *p, + const cairo_matrix_t *matrix) +{ + double dx, dy; + + dx = _cairo_fixed_to_double (p->x); + dy = _cairo_fixed_to_double (p->y); + cairo_matrix_transform_point (matrix, &dx, &dy); + p->x = _cairo_fixed_from_double (dx); + p->y = _cairo_fixed_from_double (dy); +} + +/** + * _cairo_path_fixed_transform: + * @path: a #cairo_path_fixed_t to be transformed + * @matrix: a #cairo_matrix_t + * + * Transform the fixed-point path according to the given matrix. + * There is a fast path for the case where @matrix has no rotation + * or shear. + **/ +void +_cairo_path_fixed_transform (cairo_path_fixed_t *path, + const cairo_matrix_t *matrix) +{ + cairo_box_t extents; + cairo_point_t point; + cairo_path_buf_t *buf; + unsigned int i; + + if (matrix->yx == 0.0 && matrix->xy == 0.0) { + /* Fast path for the common case of scale+transform */ + _cairo_path_fixed_offset_and_scale (path, + _cairo_fixed_from_double (matrix->x0), + _cairo_fixed_from_double (matrix->y0), + _cairo_fixed_from_double (matrix->xx), + _cairo_fixed_from_double (matrix->yy)); + return; + } + + _cairo_path_fixed_transform_point (&path->last_move_point, matrix); + _cairo_path_fixed_transform_point (&path->current_point, matrix); + + buf = cairo_path_head (path); + if (buf->num_points == 0) + return; + + extents = path->extents; + point = buf->points[0]; + _cairo_path_fixed_transform_point (&point, matrix); + _cairo_box_set (&path->extents, &point, &point); + + cairo_path_foreach_buf_start (buf, path) { + for (i = 0; i < buf->num_points; i++) { + _cairo_path_fixed_transform_point (&buf->points[i], matrix); + _cairo_box_add_point (&path->extents, &buf->points[i]); + } + } cairo_path_foreach_buf_end (buf, path); + + if (path->has_curve_to) { + cairo_bool_t is_tight; + + _cairo_matrix_transform_bounding_box_fixed (matrix, &extents, &is_tight); + if (!is_tight) { + cairo_bool_t has_extents; + + has_extents = _cairo_path_bounder_extents (path, &extents); + assert (has_extents); + } + path->extents = extents; + } + + /* flags might become more strict than needed */ + path->stroke_is_rectilinear = FALSE; + path->fill_is_rectilinear = FALSE; + path->fill_is_empty = FALSE; + path->fill_maybe_region = FALSE; +} + +/* Closure for path flattening */ +typedef struct cairo_path_flattener { + double tolerance; + cairo_point_t current_point; + cairo_path_fixed_move_to_func_t *move_to; + cairo_path_fixed_line_to_func_t *line_to; + cairo_path_fixed_close_path_func_t *close_path; + void *closure; +} cpf_t; + +static cairo_status_t +_cpf_move_to (void *closure, + const cairo_point_t *point) +{ + cpf_t *cpf = closure; + + cpf->current_point = *point; + + return cpf->move_to (cpf->closure, point); +} + +static cairo_status_t +_cpf_line_to (void *closure, + const cairo_point_t *point) +{ + cpf_t *cpf = closure; + + cpf->current_point = *point; + + return cpf->line_to (cpf->closure, point); +} + +static cairo_status_t +_cpf_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + cpf_t *cpf = closure; + cairo_spline_t spline; + + cairo_point_t *p0 = &cpf->current_point; + + if (! _cairo_spline_init (&spline, + (cairo_spline_add_point_func_t)cpf->line_to, + cpf->closure, + p0, p1, p2, p3)) + { + return _cpf_line_to (closure, p3); + } + + cpf->current_point = *p3; + + return _cairo_spline_decompose (&spline, cpf->tolerance); +} + +static cairo_status_t +_cpf_close_path (void *closure) +{ + cpf_t *cpf = closure; + + return cpf->close_path (cpf->closure); +} + +cairo_status_t +_cairo_path_fixed_interpret_flat (const cairo_path_fixed_t *path, + cairo_path_fixed_move_to_func_t *move_to, + cairo_path_fixed_line_to_func_t *line_to, + cairo_path_fixed_close_path_func_t *close_path, + void *closure, + double tolerance) +{ + cpf_t flattener; + + if (! path->has_curve_to) { + return _cairo_path_fixed_interpret (path, + move_to, + line_to, + NULL, + close_path, + closure); + } + + flattener.tolerance = tolerance; + flattener.move_to = move_to; + flattener.line_to = line_to; + flattener.close_path = close_path; + flattener.closure = closure; + return _cairo_path_fixed_interpret (path, + _cpf_move_to, + _cpf_line_to, + _cpf_curve_to, + _cpf_close_path, + &flattener); +} + +static inline void +_canonical_box (cairo_box_t *box, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + if (p1->x <= p2->x) { + box->p1.x = p1->x; + box->p2.x = p2->x; + } else { + box->p1.x = p2->x; + box->p2.x = p1->x; + } + + if (p1->y <= p2->y) { + box->p1.y = p1->y; + box->p2.y = p2->y; + } else { + box->p1.y = p2->y; + box->p2.y = p1->y; + } +} + +static inline cairo_bool_t +_path_is_quad (const cairo_path_fixed_t *path) +{ + const cairo_path_buf_t *buf = cairo_path_head (path); + + /* Do we have the right number of ops? */ + if (buf->num_ops < 4 || buf->num_ops > 6) + return FALSE; + + /* Check whether the ops are those that would be used for a rectangle */ + if (buf->op[0] != CAIRO_PATH_OP_MOVE_TO || + buf->op[1] != CAIRO_PATH_OP_LINE_TO || + buf->op[2] != CAIRO_PATH_OP_LINE_TO || + buf->op[3] != CAIRO_PATH_OP_LINE_TO) + { + return FALSE; + } + + /* we accept an implicit close for filled paths */ + if (buf->num_ops > 4) { + /* Now, there are choices. The rectangle might end with a LINE_TO + * (to the original point), but this isn't required. If it + * doesn't, then it must end with a CLOSE_PATH. */ + if (buf->op[4] == CAIRO_PATH_OP_LINE_TO) { + if (buf->points[4].x != buf->points[0].x || + buf->points[4].y != buf->points[0].y) + return FALSE; + } else if (buf->op[4] != CAIRO_PATH_OP_CLOSE_PATH) { + return FALSE; + } + + if (buf->num_ops == 6) { + /* A trailing CLOSE_PATH or MOVE_TO is ok */ + if (buf->op[5] != CAIRO_PATH_OP_MOVE_TO && + buf->op[5] != CAIRO_PATH_OP_CLOSE_PATH) + return FALSE; + } + } + + return TRUE; +} + +static inline cairo_bool_t +_points_form_rect (const cairo_point_t *points) +{ + if (points[0].y == points[1].y && + points[1].x == points[2].x && + points[2].y == points[3].y && + points[3].x == points[0].x) + return TRUE; + if (points[0].x == points[1].x && + points[1].y == points[2].y && + points[2].x == points[3].x && + points[3].y == points[0].y) + return TRUE; + return FALSE; +} + +/* + * Check whether the given path contains a single rectangle. + */ +cairo_bool_t +_cairo_path_fixed_is_box (const cairo_path_fixed_t *path, + cairo_box_t *box) +{ + const cairo_path_buf_t *buf; + + if (! path->fill_is_rectilinear) + return FALSE; + + if (! _path_is_quad (path)) + return FALSE; + + buf = cairo_path_head (path); + if (_points_form_rect (buf->points)) { + _canonical_box (box, &buf->points[0], &buf->points[2]); + return TRUE; + } + + return FALSE; +} + +/* Determine whether two lines A->B and C->D intersect based on the + * algorithm described here: http://paulbourke.net/geometry/pointlineplane/ */ +static inline cairo_bool_t +_lines_intersect_or_are_coincident (cairo_point_t a, + cairo_point_t b, + cairo_point_t c, + cairo_point_t d) +{ + cairo_int64_t numerator_a, numerator_b, denominator; + cairo_bool_t denominator_negative; + + denominator = _cairo_int64_sub (_cairo_int32x32_64_mul (d.y - c.y, b.x - a.x), + _cairo_int32x32_64_mul (d.x - c.x, b.y - a.y)); + numerator_a = _cairo_int64_sub (_cairo_int32x32_64_mul (d.x - c.x, a.y - c.y), + _cairo_int32x32_64_mul (d.y - c.y, a.x - c.x)); + numerator_b = _cairo_int64_sub (_cairo_int32x32_64_mul (b.x - a.x, a.y - c.y), + _cairo_int32x32_64_mul (b.y - a.y, a.x - c.x)); + + if (_cairo_int64_is_zero (denominator)) { + /* If the denominator and numerators are both zero, + * the lines are coincident. */ + if (_cairo_int64_is_zero (numerator_a) && _cairo_int64_is_zero (numerator_b)) + return TRUE; + + /* Otherwise, a zero denominator indicates the lines are + * parallel and never intersect. */ + return FALSE; + } + + /* The lines intersect if both quotients are between 0 and 1 (exclusive). */ + + /* We first test whether either quotient is a negative number. */ + denominator_negative = _cairo_int64_negative (denominator); + if (_cairo_int64_negative (numerator_a) ^ denominator_negative) + return FALSE; + if (_cairo_int64_negative (numerator_b) ^ denominator_negative) + return FALSE; + + /* A zero quotient indicates an "intersection" at an endpoint, which + * we aren't considering a true intersection. */ + if (_cairo_int64_is_zero (numerator_a) || _cairo_int64_is_zero (numerator_b)) + return FALSE; + + /* If the absolute value of the numerator is larger than or equal to the + * denominator the result of the division would be greater than or equal + * to one. */ + if (! denominator_negative) { + if (! _cairo_int64_lt (numerator_a, denominator) || + ! _cairo_int64_lt (numerator_b, denominator)) + return FALSE; + } else { + if (! _cairo_int64_lt (denominator, numerator_a) || + ! _cairo_int64_lt (denominator, numerator_b)) + return FALSE; + } + + return TRUE; +} + +cairo_bool_t +_cairo_path_fixed_is_simple_quad (const cairo_path_fixed_t *path) +{ + const cairo_point_t *points; + + if (! _path_is_quad (path)) + return FALSE; + + points = cairo_path_head (path)->points; + if (_points_form_rect (points)) + return TRUE; + + if (_lines_intersect_or_are_coincident (points[0], points[1], + points[3], points[2])) + return FALSE; + + if (_lines_intersect_or_are_coincident (points[0], points[3], + points[1], points[2])) + return FALSE; + + return TRUE; +} + +cairo_bool_t +_cairo_path_fixed_is_stroke_box (const cairo_path_fixed_t *path, + cairo_box_t *box) +{ + const cairo_path_buf_t *buf = cairo_path_head (path); + + if (! path->fill_is_rectilinear) + return FALSE; + + /* Do we have the right number of ops? */ + if (buf->num_ops != 5) + return FALSE; + + /* Check whether the ops are those that would be used for a rectangle */ + if (buf->op[0] != CAIRO_PATH_OP_MOVE_TO || + buf->op[1] != CAIRO_PATH_OP_LINE_TO || + buf->op[2] != CAIRO_PATH_OP_LINE_TO || + buf->op[3] != CAIRO_PATH_OP_LINE_TO || + buf->op[4] != CAIRO_PATH_OP_CLOSE_PATH) + { + return FALSE; + } + + /* Ok, we may have a box, if the points line up */ + if (buf->points[0].y == buf->points[1].y && + buf->points[1].x == buf->points[2].x && + buf->points[2].y == buf->points[3].y && + buf->points[3].x == buf->points[0].x) + { + _canonical_box (box, &buf->points[0], &buf->points[2]); + return TRUE; + } + + if (buf->points[0].x == buf->points[1].x && + buf->points[1].y == buf->points[2].y && + buf->points[2].x == buf->points[3].x && + buf->points[3].y == buf->points[0].y) + { + _canonical_box (box, &buf->points[0], &buf->points[2]); + return TRUE; + } + + return FALSE; +} + +/* + * Check whether the given path contains a single rectangle + * that is logically equivalent to: + * + * cairo_move_to (cr, x, y); + * cairo_rel_line_to (cr, width, 0); + * cairo_rel_line_to (cr, 0, height); + * cairo_rel_line_to (cr, -width, 0); + * cairo_close_path (cr); + * + */ +cairo_bool_t +_cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path, + cairo_box_t *box) +{ + const cairo_path_buf_t *buf; + + if (! _cairo_path_fixed_is_box (path, box)) + return FALSE; + + /* This check is valid because the current implementation of + * _cairo_path_fixed_is_box () only accepts rectangles like: + * move,line,line,line[,line|close[,close|move]]. */ + buf = cairo_path_head (path); + if (buf->num_ops > 4) + return TRUE; + + return FALSE; +} + +void +_cairo_path_fixed_iter_init (cairo_path_fixed_iter_t *iter, + const cairo_path_fixed_t *path) +{ + iter->first = iter->buf = cairo_path_head (path); + iter->n_op = 0; + iter->n_point = 0; +} + +static cairo_bool_t +_cairo_path_fixed_iter_next_op (cairo_path_fixed_iter_t *iter) +{ + if (++iter->n_op >= iter->buf->num_ops) { + iter->buf = cairo_path_buf_next (iter->buf); + if (iter->buf == iter->first) { + iter->buf = NULL; + return FALSE; + } + + iter->n_op = 0; + iter->n_point = 0; + } + + return TRUE; +} + +cairo_bool_t +_cairo_path_fixed_iter_is_fill_box (cairo_path_fixed_iter_t *_iter, + cairo_box_t *box) +{ + cairo_point_t points[5]; + cairo_path_fixed_iter_t iter; + + if (_iter->buf == NULL) + return FALSE; + + iter = *_iter; + + if (iter.n_op == iter.buf->num_ops && ! _cairo_path_fixed_iter_next_op (&iter)) + return FALSE; + + /* Check whether the ops are those that would be used for a rectangle */ + if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_MOVE_TO) + return FALSE; + points[0] = iter.buf->points[iter.n_point++]; + if (! _cairo_path_fixed_iter_next_op (&iter)) + return FALSE; + + if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_LINE_TO) + return FALSE; + points[1] = iter.buf->points[iter.n_point++]; + if (! _cairo_path_fixed_iter_next_op (&iter)) + return FALSE; + + /* a horizontal/vertical closed line is also a degenerate rectangle */ + switch (iter.buf->op[iter.n_op]) { + case CAIRO_PATH_OP_CLOSE_PATH: + _cairo_path_fixed_iter_next_op (&iter); + case CAIRO_PATH_OP_MOVE_TO: /* implicit close */ + box->p1 = box->p2 = points[0]; + *_iter = iter; + return TRUE; + default: + return FALSE; + case CAIRO_PATH_OP_LINE_TO: + break; + } + + points[2] = iter.buf->points[iter.n_point++]; + if (! _cairo_path_fixed_iter_next_op (&iter)) + return FALSE; + + if (iter.buf->op[iter.n_op] != CAIRO_PATH_OP_LINE_TO) + return FALSE; + points[3] = iter.buf->points[iter.n_point++]; + + /* Now, there are choices. The rectangle might end with a LINE_TO + * (to the original point), but this isn't required. If it + * doesn't, then it must end with a CLOSE_PATH (which may be implicit). */ + if (! _cairo_path_fixed_iter_next_op (&iter)) { + /* implicit close due to fill */ + } else if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_LINE_TO) { + points[4] = iter.buf->points[iter.n_point++]; + if (points[4].x != points[0].x || points[4].y != points[0].y) + return FALSE; + _cairo_path_fixed_iter_next_op (&iter); + } else if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_CLOSE_PATH) { + _cairo_path_fixed_iter_next_op (&iter); + } else if (iter.buf->op[iter.n_op] == CAIRO_PATH_OP_MOVE_TO) { + /* implicit close-path due to new-sub-path */ + } else { + return FALSE; + } + + /* Ok, we may have a box, if the points line up */ + if (points[0].y == points[1].y && + points[1].x == points[2].x && + points[2].y == points[3].y && + points[3].x == points[0].x) + { + box->p1 = points[0]; + box->p2 = points[2]; + *_iter = iter; + return TRUE; + } + + if (points[0].x == points[1].x && + points[1].y == points[2].y && + points[2].x == points[3].x && + points[3].y == points[0].y) + { + box->p1 = points[1]; + box->p2 = points[3]; + *_iter = iter; + return TRUE; + } + + return FALSE; +} + +cairo_bool_t +_cairo_path_fixed_iter_at_end (const cairo_path_fixed_iter_t *iter) +{ + if (iter->buf == NULL) + return TRUE; + + return iter->n_op == iter->buf->num_ops; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-in-fill.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-in-fill.c new file mode 100644 index 00000000000..1787fb1a3ba --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-in-fill.c @@ -0,0 +1,290 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-path-fixed-private.h" + +typedef struct cairo_in_fill { + double tolerance; + cairo_bool_t on_edge; + int winding; + + cairo_fixed_t x, y; + + cairo_bool_t has_current_point; + cairo_point_t current_point; + cairo_point_t first_point; +} cairo_in_fill_t; + +static void +_cairo_in_fill_init (cairo_in_fill_t *in_fill, + double tolerance, + double x, + double y) +{ + in_fill->on_edge = FALSE; + in_fill->winding = 0; + in_fill->tolerance = tolerance; + + in_fill->x = _cairo_fixed_from_double (x); + in_fill->y = _cairo_fixed_from_double (y); + + in_fill->has_current_point = FALSE; + in_fill->current_point.x = 0; + in_fill->current_point.y = 0; +} + +static void +_cairo_in_fill_fini (cairo_in_fill_t *in_fill) +{ +} + +static int +edge_compare_for_y_against_x (const cairo_point_t *p1, + const cairo_point_t *p2, + cairo_fixed_t y, + cairo_fixed_t x) +{ + cairo_fixed_t adx, ady; + cairo_fixed_t dx, dy; + cairo_int64_t L, R; + + adx = p2->x - p1->x; + dx = x - p1->x; + + if (adx == 0) + return -dx; + if ((adx ^ dx) < 0) + return adx; + + dy = y - p1->y; + ady = p2->y - p1->y; + + L = _cairo_int32x32_64_mul (dy, adx); + R = _cairo_int32x32_64_mul (dx, ady); + + return _cairo_int64_cmp (L, R); +} + +static void +_cairo_in_fill_add_edge (cairo_in_fill_t *in_fill, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + int dir; + + if (in_fill->on_edge) + return; + + /* count the number of edge crossing to -∞ */ + + dir = 1; + if (p2->y < p1->y) { + const cairo_point_t *tmp; + + tmp = p1; + p1 = p2; + p2 = tmp; + + dir = -1; + } + + /* First check whether the query is on an edge */ + if ((p1->x == in_fill->x && p1->y == in_fill->y) || + (p2->x == in_fill->x && p2->y == in_fill->y) || + (! (p2->y < in_fill->y || p1->y > in_fill->y || + (p1->x > in_fill->x && p2->x > in_fill->x) || + (p1->x < in_fill->x && p2->x < in_fill->x)) && + edge_compare_for_y_against_x (p1, p2, in_fill->y, in_fill->x) == 0)) + { + in_fill->on_edge = TRUE; + return; + } + + /* edge is entirely above or below, note the shortening rule */ + if (p2->y <= in_fill->y || p1->y > in_fill->y) + return; + + /* edge lies wholly to the right */ + if (p1->x >= in_fill->x && p2->x >= in_fill->x) + return; + + if ((p1->x <= in_fill->x && p2->x <= in_fill->x) || + edge_compare_for_y_against_x (p1, p2, in_fill->y, in_fill->x) < 0) + { + in_fill->winding += dir; + } +} + +static cairo_status_t +_cairo_in_fill_move_to (void *closure, + const cairo_point_t *point) +{ + cairo_in_fill_t *in_fill = closure; + + /* implicit close path */ + if (in_fill->has_current_point) { + _cairo_in_fill_add_edge (in_fill, + &in_fill->current_point, + &in_fill->first_point); + } + + in_fill->first_point = *point; + in_fill->current_point = *point; + in_fill->has_current_point = TRUE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_in_fill_line_to (void *closure, + const cairo_point_t *point) +{ + cairo_in_fill_t *in_fill = closure; + + if (in_fill->has_current_point) + _cairo_in_fill_add_edge (in_fill, &in_fill->current_point, point); + + in_fill->current_point = *point; + in_fill->has_current_point = TRUE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_in_fill_curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + cairo_in_fill_t *in_fill = closure; + cairo_spline_t spline; + cairo_fixed_t top, bot, left; + + /* first reject based on bbox */ + bot = top = in_fill->current_point.y; + if (b->y < top) top = b->y; + if (b->y > bot) bot = b->y; + if (c->y < top) top = c->y; + if (c->y > bot) bot = c->y; + if (d->y < top) top = d->y; + if (d->y > bot) bot = d->y; + if (bot < in_fill->y || top > in_fill->y) { + in_fill->current_point = *d; + return CAIRO_STATUS_SUCCESS; + } + + left = in_fill->current_point.x; + if (b->x < left) left = b->x; + if (c->x < left) left = c->x; + if (d->x < left) left = d->x; + if (left > in_fill->x) { + in_fill->current_point = *d; + return CAIRO_STATUS_SUCCESS; + } + + /* XXX Investigate direct inspection of the inflections? */ + if (! _cairo_spline_init (&spline, + (cairo_spline_add_point_func_t)_cairo_in_fill_line_to, + in_fill, + &in_fill->current_point, b, c, d)) + { + return CAIRO_STATUS_SUCCESS; + } + + return _cairo_spline_decompose (&spline, in_fill->tolerance); +} + +static cairo_status_t +_cairo_in_fill_close_path (void *closure) +{ + cairo_in_fill_t *in_fill = closure; + + if (in_fill->has_current_point) { + _cairo_in_fill_add_edge (in_fill, + &in_fill->current_point, + &in_fill->first_point); + + in_fill->has_current_point = FALSE; + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_bool_t +_cairo_path_fixed_in_fill (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + double x, + double y) +{ + cairo_in_fill_t in_fill; + cairo_status_t status; + cairo_bool_t is_inside; + + if (_cairo_path_fixed_fill_is_empty (path)) + return FALSE; + + _cairo_in_fill_init (&in_fill, tolerance, x, y); + + status = _cairo_path_fixed_interpret (path, + _cairo_in_fill_move_to, + _cairo_in_fill_line_to, + _cairo_in_fill_curve_to, + _cairo_in_fill_close_path, + &in_fill); + assert (status == CAIRO_STATUS_SUCCESS); + + _cairo_in_fill_close_path (&in_fill); + + if (in_fill.on_edge) { + is_inside = TRUE; + } else switch (fill_rule) { + case CAIRO_FILL_RULE_EVEN_ODD: + is_inside = in_fill.winding & 1; + break; + case CAIRO_FILL_RULE_WINDING: + is_inside = in_fill.winding != 0; + break; + default: + ASSERT_NOT_REACHED; + is_inside = FALSE; + break; + } + + _cairo_in_fill_fini (&in_fill); + + return is_inside; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-path-private.h new file mode 100644 index 00000000000..7b54317e20e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-private.h @@ -0,0 +1,57 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PATH_PRIVATE_H +#define CAIRO_PATH_PRIVATE_H + +#include "cairoint.h" + +cairo_private cairo_path_t * +_cairo_path_create (cairo_path_fixed_t *path, + cairo_t *cr); + +cairo_private cairo_path_t * +_cairo_path_create_flat (cairo_path_fixed_t *path, + cairo_t *cr); + +cairo_private cairo_path_t * +_cairo_path_create_in_error (cairo_status_t status); + +cairo_private cairo_status_t +_cairo_path_append_to_context (const cairo_path_t *path, + cairo_t *cr); + +#endif /* CAIRO_PATH_DATA_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-boxes.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-boxes.c new file mode 100644 index 00000000000..7f25bf76cf7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-boxes.c @@ -0,0 +1,711 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#define _BSD_SOURCE /* for hypot() */ +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-slope-private.h" +#include "cairo-stroke-dash-private.h" + +typedef struct _segment_t { + cairo_point_t p1, p2; + unsigned flags; +#define HORIZONTAL 0x1 +#define FORWARDS 0x2 +#define JOIN 0x4 +} segment_t; + +typedef struct _cairo_rectilinear_stroker { + const cairo_stroke_style_t *stroke_style; + const cairo_matrix_t *ctm; + cairo_antialias_t antialias; + + cairo_fixed_t half_line_x, half_line_y; + cairo_boxes_t *boxes; + cairo_point_t current_point; + cairo_point_t first_point; + cairo_bool_t open_sub_path; + + cairo_stroker_dash_t dash; + + cairo_bool_t has_bounds; + cairo_box_t bounds; + + int num_segments; + int segments_size; + segment_t *segments; + segment_t segments_embedded[8]; /* common case is a single rectangle */ +} cairo_rectilinear_stroker_t; + +static void +_cairo_rectilinear_stroker_limit (cairo_rectilinear_stroker_t *stroker, + const cairo_box_t *boxes, + int num_boxes) +{ + stroker->has_bounds = TRUE; + _cairo_boxes_get_extents (boxes, num_boxes, &stroker->bounds); + + stroker->bounds.p1.x -= stroker->half_line_x; + stroker->bounds.p2.x += stroker->half_line_x; + + stroker->bounds.p1.y -= stroker->half_line_y; + stroker->bounds.p2.y += stroker->half_line_y; +} + +static cairo_bool_t +_cairo_rectilinear_stroker_init (cairo_rectilinear_stroker_t *stroker, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + cairo_antialias_t antialias, + cairo_boxes_t *boxes) +{ + /* This special-case rectilinear stroker only supports + * miter-joined lines (not curves) and a translation-only matrix + * (though it could probably be extended to support a matrix with + * uniform, integer scaling). + * + * It also only supports horizontal and vertical line_to + * elements. But we don't catch that here, but instead return + * UNSUPPORTED from _cairo_rectilinear_stroker_line_to if any + * non-rectilinear line_to is encountered. + */ + if (stroke_style->line_join != CAIRO_LINE_JOIN_MITER) + return FALSE; + + /* If the miter limit turns right angles into bevels, then we + * can't use this optimization. Remember, the ratio is + * 1/sin(ɸ/2). So the cutoff is 1/sin(π/4.0) or ⎷2, + * which we round for safety. */ + if (stroke_style->miter_limit < M_SQRT2) + return FALSE; + + if (! (stroke_style->line_cap == CAIRO_LINE_CAP_BUTT || + stroke_style->line_cap == CAIRO_LINE_CAP_SQUARE)) + { + return FALSE; + } + + if (! _cairo_matrix_is_scale (ctm)) + return FALSE; + + stroker->stroke_style = stroke_style; + stroker->ctm = ctm; + stroker->antialias = antialias; + + stroker->half_line_x = + _cairo_fixed_from_double (fabs(ctm->xx) * stroke_style->line_width / 2.0); + stroker->half_line_y = + _cairo_fixed_from_double (fabs(ctm->yy) * stroke_style->line_width / 2.0); + + stroker->open_sub_path = FALSE; + stroker->segments = stroker->segments_embedded; + stroker->segments_size = ARRAY_LENGTH (stroker->segments_embedded); + stroker->num_segments = 0; + + _cairo_stroker_dash_init (&stroker->dash, stroke_style); + + stroker->has_bounds = FALSE; + + stroker->boxes = boxes; + + return TRUE; +} + +static void +_cairo_rectilinear_stroker_fini (cairo_rectilinear_stroker_t *stroker) +{ + if (stroker->segments != stroker->segments_embedded) + free (stroker->segments); +} + +static cairo_status_t +_cairo_rectilinear_stroker_add_segment (cairo_rectilinear_stroker_t *stroker, + const cairo_point_t *p1, + const cairo_point_t *p2, + unsigned flags) +{ + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (stroker->num_segments == stroker->segments_size) { + int new_size = stroker->segments_size * 2; + segment_t *new_segments; + + if (stroker->segments == stroker->segments_embedded) { + new_segments = _cairo_malloc_ab (new_size, sizeof (segment_t)); + if (unlikely (new_segments == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (new_segments, stroker->segments, + stroker->num_segments * sizeof (segment_t)); + } else { + new_segments = _cairo_realloc_ab (stroker->segments, + new_size, sizeof (segment_t)); + if (unlikely (new_segments == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + stroker->segments_size = new_size; + stroker->segments = new_segments; + } + + stroker->segments[stroker->num_segments].p1 = *p1; + stroker->segments[stroker->num_segments].p2 = *p2; + stroker->segments[stroker->num_segments].flags = flags; + stroker->num_segments++; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_rectilinear_stroker_emit_segments (cairo_rectilinear_stroker_t *stroker) +{ + cairo_line_cap_t line_cap = stroker->stroke_style->line_cap; + cairo_fixed_t half_line_x = stroker->half_line_x; + cairo_fixed_t half_line_y = stroker->half_line_y; + cairo_status_t status; + int i, j; + + /* For each segment we generate a single rectangle. + * This rectangle is based on a perpendicular extension (by half the + * line width) of the segment endpoints * after some adjustments of the + * endpoints to account for caps and joins. + */ + for (i = 0; i < stroker->num_segments; i++) { + cairo_bool_t lengthen_initial, lengthen_final; + cairo_point_t *a, *b; + cairo_box_t box; + + a = &stroker->segments[i].p1; + b = &stroker->segments[i].p2; + + /* We adjust the initial point of the segment to extend the + * rectangle to include the previous cap or join, (this + * adjustment applies to all segments except for the first + * segment of open, butt-capped paths). However, we must be + * careful not to emit a miter join across a degenerate segment + * which has been elided. + * + * Overlapping segments will be eliminated by the tessellation. + * Ideally, we would not emit these self-intersections at all, + * but that is tricky with segments shorter than half_line_width. + */ + j = i == 0 ? stroker->num_segments - 1 : i-1; + lengthen_initial = (stroker->segments[i].flags ^ stroker->segments[j].flags) & HORIZONTAL; + j = i == stroker->num_segments - 1 ? 0 : i+1; + lengthen_final = (stroker->segments[i].flags ^ stroker->segments[j].flags) & HORIZONTAL; + if (stroker->open_sub_path) { + if (i == 0) + lengthen_initial = line_cap != CAIRO_LINE_CAP_BUTT; + + if (i == stroker->num_segments - 1) + lengthen_final = line_cap != CAIRO_LINE_CAP_BUTT; + } + + /* Perform the adjustments of the endpoints. */ + if (lengthen_initial | lengthen_final) { + if (a->y == b->y) { + if (a->x < b->x) { + if (lengthen_initial) + a->x -= half_line_x; + if (lengthen_final) + b->x += half_line_x; + } else { + if (lengthen_initial) + a->x += half_line_x; + if (lengthen_final) + b->x -= half_line_x; + } + } else { + if (a->y < b->y) { + if (lengthen_initial) + a->y -= half_line_y; + if (lengthen_final) + b->y += half_line_y; + } else { + if (lengthen_initial) + a->y += half_line_y; + if (lengthen_final) + b->y -= half_line_y; + } + } + } + + /* Form the rectangle by expanding by half the line width in + * either perpendicular direction. */ + if (a->y == b->y) { + a->y -= half_line_y; + b->y += half_line_y; + } else { + a->x -= half_line_x; + b->x += half_line_x; + } + + if (a->x < b->x) { + box.p1.x = a->x; + box.p2.x = b->x; + } else { + box.p1.x = b->x; + box.p2.x = a->x; + } + if (a->y < b->y) { + box.p1.y = a->y; + box.p2.y = b->y; + } else { + box.p1.y = b->y; + box.p2.y = a->y; + } + + status = _cairo_boxes_add (stroker->boxes, stroker->antialias, &box); + if (unlikely (status)) + return status; + } + + stroker->num_segments = 0; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_rectilinear_stroker_emit_segments_dashed (cairo_rectilinear_stroker_t *stroker) +{ + cairo_status_t status; + cairo_line_cap_t line_cap = stroker->stroke_style->line_cap; + cairo_fixed_t half_line_x = stroker->half_line_x; + cairo_fixed_t half_line_y = stroker->half_line_y; + int i; + + for (i = 0; i < stroker->num_segments; i++) { + cairo_point_t *a, *b; + cairo_bool_t is_horizontal; + cairo_box_t box; + + a = &stroker->segments[i].p1; + b = &stroker->segments[i].p2; + + is_horizontal = stroker->segments[i].flags & HORIZONTAL; + + /* Handle the joins for a potentially degenerate segment. */ + if (line_cap == CAIRO_LINE_CAP_BUTT && + stroker->segments[i].flags & JOIN && + (i != stroker->num_segments - 1 || + (! stroker->open_sub_path && stroker->dash.dash_starts_on))) + { + cairo_slope_t out_slope; + int j = (i + 1) % stroker->num_segments; + cairo_bool_t forwards = !!(stroker->segments[i].flags & FORWARDS); + + _cairo_slope_init (&out_slope, + &stroker->segments[j].p1, + &stroker->segments[j].p2); + box.p2 = box.p1 = stroker->segments[i].p2; + + if (is_horizontal) { + if (forwards) + box.p2.x += half_line_x; + else + box.p1.x -= half_line_x; + + if (out_slope.dy > 0) + box.p1.y -= half_line_y; + else + box.p2.y += half_line_y; + } else { + if (forwards) + box.p2.y += half_line_y; + else + box.p1.y -= half_line_y; + + if (out_slope.dx > 0) + box.p1.x -= half_line_x; + else + box.p2.x += half_line_x; + } + + status = _cairo_boxes_add (stroker->boxes, stroker->antialias, &box); + if (unlikely (status)) + return status; + } + + /* Perform the adjustments of the endpoints. */ + if (is_horizontal) { + if (line_cap == CAIRO_LINE_CAP_SQUARE) { + if (a->x <= b->x) { + a->x -= half_line_x; + b->x += half_line_x; + } else { + a->x += half_line_x; + b->x -= half_line_x; + } + } + + a->y += half_line_y; + b->y -= half_line_y; + } else { + if (line_cap == CAIRO_LINE_CAP_SQUARE) { + if (a->y <= b->y) { + a->y -= half_line_y; + b->y += half_line_y; + } else { + a->y += half_line_y; + b->y -= half_line_y; + } + } + + a->x += half_line_x; + b->x -= half_line_x; + } + + if (a->x == b->x && a->y == b->y) + continue; + + if (a->x < b->x) { + box.p1.x = a->x; + box.p2.x = b->x; + } else { + box.p1.x = b->x; + box.p2.x = a->x; + } + if (a->y < b->y) { + box.p1.y = a->y; + box.p2.y = b->y; + } else { + box.p1.y = b->y; + box.p2.y = a->y; + } + + status = _cairo_boxes_add (stroker->boxes, stroker->antialias, &box); + if (unlikely (status)) + return status; + } + + stroker->num_segments = 0; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_rectilinear_stroker_move_to (void *closure, + const cairo_point_t *point) +{ + cairo_rectilinear_stroker_t *stroker = closure; + cairo_status_t status; + + if (stroker->dash.dashed) + status = _cairo_rectilinear_stroker_emit_segments_dashed (stroker); + else + status = _cairo_rectilinear_stroker_emit_segments (stroker); + if (unlikely (status)) + return status; + + /* reset the dash pattern for new sub paths */ + _cairo_stroker_dash_start (&stroker->dash); + + stroker->current_point = *point; + stroker->first_point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_rectilinear_stroker_line_to (void *closure, + const cairo_point_t *b) +{ + cairo_rectilinear_stroker_t *stroker = closure; + cairo_point_t *a = &stroker->current_point; + cairo_status_t status; + + /* We only support horizontal or vertical elements. */ + assert (a->x == b->x || a->y == b->y); + + /* We don't draw anything for degenerate paths. */ + if (a->x == b->x && a->y == b->y) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_rectilinear_stroker_add_segment (stroker, a, b, + (a->y == b->y) | JOIN); + + stroker->current_point = *b; + stroker->open_sub_path = TRUE; + + return status; +} + +static cairo_status_t +_cairo_rectilinear_stroker_line_to_dashed (void *closure, + const cairo_point_t *point) +{ + cairo_rectilinear_stroker_t *stroker = closure; + const cairo_point_t *a = &stroker->current_point; + const cairo_point_t *b = point; + cairo_bool_t fully_in_bounds; + double sf, sign, remain; + cairo_fixed_t mag; + cairo_status_t status; + cairo_line_t segment; + cairo_bool_t dash_on = FALSE; + unsigned is_horizontal; + + /* We don't draw anything for degenerate paths. */ + if (a->x == b->x && a->y == b->y) + return CAIRO_STATUS_SUCCESS; + + /* We only support horizontal or vertical elements. */ + assert (a->x == b->x || a->y == b->y); + + fully_in_bounds = TRUE; + if (stroker->has_bounds && + (! _cairo_box_contains_point (&stroker->bounds, a) || + ! _cairo_box_contains_point (&stroker->bounds, b))) + { + fully_in_bounds = FALSE; + } + + is_horizontal = a->y == b->y; + if (is_horizontal) { + mag = b->x - a->x; + sf = fabs (stroker->ctm->xx); + } else { + mag = b->y - a->y; + sf = fabs (stroker->ctm->yy); + } + if (mag < 0) { + remain = _cairo_fixed_to_double (-mag); + sign = 1.; + } else { + remain = _cairo_fixed_to_double (mag); + is_horizontal |= FORWARDS; + sign = -1.; + } + + segment.p2 = segment.p1 = *a; + while (remain > 0.) { + double step_length; + + step_length = MIN (sf * stroker->dash.dash_remain, remain); + remain -= step_length; + + mag = _cairo_fixed_from_double (sign*remain); + if (is_horizontal & 0x1) + segment.p2.x = b->x + mag; + else + segment.p2.y = b->y + mag; + + if (stroker->dash.dash_on && + (fully_in_bounds || + _cairo_box_intersects_line_segment (&stroker->bounds, &segment))) + { + status = _cairo_rectilinear_stroker_add_segment (stroker, + &segment.p1, + &segment.p2, + is_horizontal | (remain <= 0.) << 2); + if (unlikely (status)) + return status; + + dash_on = TRUE; + } + else + { + dash_on = FALSE; + } + + _cairo_stroker_dash_step (&stroker->dash, step_length / sf); + segment.p1 = segment.p2; + } + + if (stroker->dash.dash_on && ! dash_on && + (fully_in_bounds || + _cairo_box_intersects_line_segment (&stroker->bounds, &segment))) + { + + /* This segment ends on a transition to dash_on, compute a new face + * and add cap for the beginning of the next dash_on step. + */ + + status = _cairo_rectilinear_stroker_add_segment (stroker, + &segment.p1, + &segment.p1, + is_horizontal | JOIN); + if (unlikely (status)) + return status; + } + + stroker->current_point = *point; + stroker->open_sub_path = TRUE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_rectilinear_stroker_close_path (void *closure) +{ + cairo_rectilinear_stroker_t *stroker = closure; + cairo_status_t status; + + /* We don't draw anything for degenerate paths. */ + if (! stroker->open_sub_path) + return CAIRO_STATUS_SUCCESS; + + if (stroker->dash.dashed) { + status = _cairo_rectilinear_stroker_line_to_dashed (stroker, + &stroker->first_point); + } else { + status = _cairo_rectilinear_stroker_line_to (stroker, + &stroker->first_point); + } + if (unlikely (status)) + return status; + + stroker->open_sub_path = FALSE; + + if (stroker->dash.dashed) + status = _cairo_rectilinear_stroker_emit_segments_dashed (stroker); + else + status = _cairo_rectilinear_stroker_emit_segments (stroker); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_path_fixed_stroke_rectilinear_to_boxes (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + cairo_antialias_t antialias, + cairo_boxes_t *boxes) +{ + cairo_rectilinear_stroker_t rectilinear_stroker; + cairo_int_status_t status; + cairo_box_t box; + + assert (_cairo_path_fixed_stroke_is_rectilinear (path)); + + if (! _cairo_rectilinear_stroker_init (&rectilinear_stroker, + stroke_style, ctm, antialias, + boxes)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (! rectilinear_stroker.dash.dashed && + _cairo_path_fixed_is_stroke_box (path, &box) && + /* if the segments overlap we need to feed them into the tessellator */ + box.p2.x - box.p1.x > 2* rectilinear_stroker.half_line_x && + box.p2.y - box.p1.y > 2* rectilinear_stroker.half_line_y) + { + cairo_box_t b; + + /* top */ + b.p1.x = box.p1.x - rectilinear_stroker.half_line_x; + b.p2.x = box.p2.x + rectilinear_stroker.half_line_x; + b.p1.y = box.p1.y - rectilinear_stroker.half_line_y; + b.p2.y = box.p1.y + rectilinear_stroker.half_line_y; + status = _cairo_boxes_add (boxes, antialias, &b); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + /* left (excluding top/bottom) */ + b.p1.x = box.p1.x - rectilinear_stroker.half_line_x; + b.p2.x = box.p1.x + rectilinear_stroker.half_line_x; + b.p1.y = box.p1.y + rectilinear_stroker.half_line_y; + b.p2.y = box.p2.y - rectilinear_stroker.half_line_y; + status = _cairo_boxes_add (boxes, antialias, &b); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + /* right (excluding top/bottom) */ + b.p1.x = box.p2.x - rectilinear_stroker.half_line_x; + b.p2.x = box.p2.x + rectilinear_stroker.half_line_x; + b.p1.y = box.p1.y + rectilinear_stroker.half_line_y; + b.p2.y = box.p2.y - rectilinear_stroker.half_line_y; + status = _cairo_boxes_add (boxes, antialias, &b); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + /* bottom */ + b.p1.x = box.p1.x - rectilinear_stroker.half_line_x; + b.p2.x = box.p2.x + rectilinear_stroker.half_line_x; + b.p1.y = box.p2.y - rectilinear_stroker.half_line_y; + b.p2.y = box.p2.y + rectilinear_stroker.half_line_y; + status = _cairo_boxes_add (boxes, antialias, &b); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + goto done; + } + + if (boxes->num_limits) { + _cairo_rectilinear_stroker_limit (&rectilinear_stroker, + boxes->limits, + boxes->num_limits); + } + + status = _cairo_path_fixed_interpret (path, + _cairo_rectilinear_stroker_move_to, + rectilinear_stroker.dash.dashed ? + _cairo_rectilinear_stroker_line_to_dashed : + _cairo_rectilinear_stroker_line_to, + NULL, + _cairo_rectilinear_stroker_close_path, + &rectilinear_stroker); + if (unlikely (status)) + goto BAIL; + + if (rectilinear_stroker.dash.dashed) + status = _cairo_rectilinear_stroker_emit_segments_dashed (&rectilinear_stroker); + else + status = _cairo_rectilinear_stroker_emit_segments (&rectilinear_stroker); + if (unlikely (status)) + goto BAIL; + + /* As we incrementally tessellate, we do not eliminate self-intersections */ + status = _cairo_bentley_ottmann_tessellate_boxes (boxes, + CAIRO_FILL_RULE_WINDING, + boxes); + if (unlikely (status)) + goto BAIL; + +done: + _cairo_rectilinear_stroker_fini (&rectilinear_stroker); + return CAIRO_STATUS_SUCCESS; + +BAIL: + _cairo_rectilinear_stroker_fini (&rectilinear_stroker); + _cairo_boxes_clear (boxes); + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-polygon.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-polygon.c new file mode 100644 index 00000000000..e5082bbec68 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-polygon.c @@ -0,0 +1,1364 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#define _BSD_SOURCE /* for hypot() */ +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-contour-inline.h" +#include "cairo-contour-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-slope-private.h" + +#define DEBUG 0 + +struct stroker { + cairo_stroke_style_t style; + +#if DEBUG + cairo_contour_t path; +#endif + + struct stroke_contour { + /* Note that these are not strictly contours as they may intersect */ + cairo_contour_t contour; + } cw, ccw; + cairo_uint64_t contour_tolerance; + cairo_polygon_t *polygon; + + const cairo_matrix_t *ctm; + const cairo_matrix_t *ctm_inverse; + double tolerance; + double spline_cusp_tolerance; + double half_line_width; + cairo_bool_t ctm_det_positive; + + cairo_pen_t pen; + + cairo_point_t first_point; + + cairo_bool_t has_initial_sub_path; + + cairo_bool_t has_current_face; + cairo_stroke_face_t current_face; + + cairo_bool_t has_first_face; + cairo_stroke_face_t first_face; + + cairo_bool_t has_bounds; + cairo_box_t bounds; +}; + +static inline double +normalize_slope (double *dx, double *dy); + +static void +compute_face (const cairo_point_t *point, + const cairo_slope_t *dev_slope, + struct stroker *stroker, + cairo_stroke_face_t *face); + +static cairo_uint64_t +point_distance_sq (const cairo_point_t *p1, + const cairo_point_t *p2) +{ + int32_t dx = p1->x - p2->x; + int32_t dy = p1->y - p2->y; + return _cairo_int32x32_64_mul (dx, dx) + _cairo_int32x32_64_mul (dy, dy); +} + +static cairo_bool_t +within_tolerance (const cairo_point_t *p1, + const cairo_point_t *p2, + cairo_uint64_t tolerance) +{ + return FALSE; + return _cairo_int64_lt (point_distance_sq (p1, p2), tolerance); +} + +static void +contour_add_point (struct stroker *stroker, + struct stroke_contour *c, + const cairo_point_t *point) +{ + if (! within_tolerance (point, _cairo_contour_last_point (&c->contour), + stroker->contour_tolerance)) + _cairo_contour_add_point (&c->contour, point); + //*_cairo_contour_last_point (&c->contour) = *point; +} + +static void +translate_point (cairo_point_t *point, const cairo_point_t *offset) +{ + point->x += offset->x; + point->y += offset->y; +} + +static int +slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) +{ + double c = (dx1 * dy2 - dx2 * dy1); + + if (c > 0) return 1; + if (c < 0) return -1; + return 0; +} + +static inline int +range_step (int i, int step, int max) +{ + i += step; + if (i < 0) + i = max - 1; + if (i >= max) + i = 0; + return i; +} + +/* + * Construct a fan around the midpoint using the vertices from pen between + * inpt and outpt. + */ +static void +add_fan (struct stroker *stroker, + const cairo_slope_t *in_vector, + const cairo_slope_t *out_vector, + const cairo_point_t *midpt, + cairo_bool_t clockwise, + struct stroke_contour *c) +{ + cairo_pen_t *pen = &stroker->pen; + int start, stop; + + if (stroker->has_bounds && + ! _cairo_box_contains_point (&stroker->bounds, midpt)) + return; + + assert (stroker->pen.num_vertices); + + if (clockwise) { + _cairo_pen_find_active_cw_vertices (pen, + in_vector, out_vector, + &start, &stop); + while (start != stop) { + cairo_point_t p = *midpt; + translate_point (&p, &pen->vertices[start].point); + contour_add_point (stroker, c, &p); + + if (++start == pen->num_vertices) + start = 0; + } + } else { + _cairo_pen_find_active_ccw_vertices (pen, + in_vector, out_vector, + &start, &stop); + while (start != stop) { + cairo_point_t p = *midpt; + translate_point (&p, &pen->vertices[start].point); + contour_add_point (stroker, c, &p); + + if (start-- == 0) + start += pen->num_vertices; + } + } +} + +static int +join_is_clockwise (const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + return _cairo_slope_compare (&in->dev_vector, &out->dev_vector) < 0; +} + +static void +inner_join (struct stroker *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out, + int clockwise) +{ +#if 0 + cairo_point_t last; + const cairo_point_t *p, *outpt; + struct stroke_contour *inner; + cairo_int64_t d_p, d_last; + cairo_int64_t half_line_width; + cairo_bool_t negate; + + /* XXX line segments shorter than line-width */ + + if (clockwise) { + inner = &stroker->ccw; + outpt = &out->ccw; + negate = 1; + } else { + inner = &stroker->cw; + outpt = &out->cw; + negate = 0; + } + + half_line_width = CAIRO_FIXED_ONE*CAIRO_FIXED_ONE/2 * stroker->style.line_width * out->length + .5; + + /* On the inside, the previous end-point is always + * closer to the new face by definition. + */ + last = *_cairo_contour_last_point (&inner->contour); + d_last = distance_from_face (out, &last, negate); + _cairo_contour_remove_last_point (&inner->contour); + +prev: + if (inner->contour.chain.num_points == 0) { + contour_add_point (stroker, inner, outpt); + return; + } + p = _cairo_contour_last_point (&inner->contour); + d_p = distance_from_face (out, p, negate); + if (_cairo_int64_lt (d_p, half_line_width) && + !_cairo_int64_negative (distance_along_face (out, p))) + { + last = *p; + d_last = d_p; + _cairo_contour_remove_last_point (&inner->contour); + goto prev; + } + + compute_inner_joint (&last, d_last, p, d_p, half_line_width); + contour_add_point (stroker, inner, &last); +#else + const cairo_point_t *outpt; + struct stroke_contour *inner; + + if (clockwise) { + inner = &stroker->ccw; + outpt = &out->ccw; + } else { + inner = &stroker->cw; + outpt = &out->cw; + } + contour_add_point (stroker, inner, &in->point); + contour_add_point (stroker, inner, outpt); +#endif +} + +static void +inner_close (struct stroker *stroker, + const cairo_stroke_face_t *in, + cairo_stroke_face_t *out) +{ +#if 0 + cairo_point_t last; + const cairo_point_t *p, *outpt, *inpt; + struct stroke_contour *inner; + struct _cairo_contour_chain *chain; + + /* XXX line segments shorter than line-width */ + + if (join_is_clockwise (in, out)) { + inner = &stroker->ccw; + outpt = &in->ccw; + inpt = &out->ccw; + } else { + inner = &stroker->cw; + outpt = &in->cw; + inpt = &out->cw; + } + + if (inner->contour.chain.num_points == 0) { + contour_add_point (stroker, inner, &in->point); + contour_add_point (stroker, inner, inpt); + *_cairo_contour_first_point (&inner->contour) = + *_cairo_contour_last_point (&inner->contour); + return; + } + + line_width = stroker->style.line_width/2; + line_width *= CAIRO_FIXED_ONE; + + d_last = sign * distance_from_face (out, outpt); + last = *outpt; + + for (chain = &inner->contour.chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + p = &chain->points[i]; + if ((d_p = sign * distance_from_face (in, p)) >= line_width && + distance_from_edge (stroker, inpt, &last, p) < line_width) + { + goto out; + } + + if (p->x != last.x || p->y != last.y) { + last = *p; + d_last = d_p; + } + } + } +out: + + if (d_p != d_last) { + double dot = (line_width - d_last) / (d_p - d_last); + last.x += dot * (p->x - last.x); + last.y += dot * (p->y - last.y); + } + *_cairo_contour_last_point (&inner->contour) = last; + + for (chain = &inner->contour.chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + cairo_point_t *pp = &chain->points[i]; + if (pp == p) + return; + *pp = last; + } + } +#else + const cairo_point_t *inpt; + struct stroke_contour *inner; + + if (join_is_clockwise (in, out)) { + inner = &stroker->ccw; + inpt = &out->ccw; + } else { + inner = &stroker->cw; + inpt = &out->cw; + } + + contour_add_point (stroker, inner, &in->point); + contour_add_point (stroker, inner, inpt); + *_cairo_contour_first_point (&inner->contour) = + *_cairo_contour_last_point (&inner->contour); +#endif +} + +static void +outer_close (struct stroker *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + const cairo_point_t *inpt, *outpt; + struct stroke_contour *outer; + int clockwise; + + if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && + in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) + { + return; + } + + clockwise = join_is_clockwise (in, out); + if (clockwise) { + inpt = &in->cw; + outpt = &out->cw; + outer = &stroker->cw; + } else { + inpt = &in->ccw; + outpt = &out->ccw; + outer = &stroker->ccw; + } + + if (within_tolerance (inpt, outpt, stroker->contour_tolerance)) { + *_cairo_contour_first_point (&outer->contour) = + *_cairo_contour_last_point (&outer->contour); + return; + } + + switch (stroker->style.line_join) { + case CAIRO_LINE_JOIN_ROUND: + /* construct a fan around the common midpoint */ + if ((in->dev_slope.x * out->dev_slope.x + + in->dev_slope.y * out->dev_slope.y) < stroker->spline_cusp_tolerance) + { + add_fan (stroker, + &in->dev_vector, &out->dev_vector, &in->point, + clockwise, outer); + break; + } + + case CAIRO_LINE_JOIN_MITER: + default: { + /* dot product of incoming slope vector with outgoing slope vector */ + double in_dot_out = in->dev_slope.x * out->dev_slope.x + + in->dev_slope.y * out->dev_slope.y; + double ml = stroker->style.miter_limit; + + /* Check the miter limit -- lines meeting at an acute angle + * can generate long miters, the limit converts them to bevel + * + * Consider the miter join formed when two line segments + * meet at an angle psi: + * + * /.\ + * /. .\ + * /./ \.\ + * /./psi\.\ + * + * We can zoom in on the right half of that to see: + * + * |\ + * | \ psi/2 + * | \ + * | \ + * | \ + * | \ + * miter \ + * length \ + * | \ + * | .\ + * | . \ + * |. line \ + * \ width \ + * \ \ + * + * + * The right triangle in that figure, (the line-width side is + * shown faintly with three '.' characters), gives us the + * following expression relating miter length, angle and line + * width: + * + * 1 /sin (psi/2) = miter_length / line_width + * + * The right-hand side of this relationship is the same ratio + * in which the miter limit (ml) is expressed. We want to know + * when the miter length is within the miter limit. That is + * when the following condition holds: + * + * 1/sin(psi/2) <= ml + * 1 <= ml sin(psi/2) + * 1 <= ml² sin²(psi/2) + * 2 <= ml² 2 sin²(psi/2) + * 2·sin²(psi/2) = 1-cos(psi) + * 2 <= ml² (1-cos(psi)) + * + * in · out = |in| |out| cos (psi) + * + * in and out are both unit vectors, so: + * + * in · out = cos (psi) + * + * 2 <= ml² (1 - in · out) + * + */ + if (2 <= ml * ml * (1 + in_dot_out)) { + double x1, y1, x2, y2; + double mx, my; + double dx1, dx2, dy1, dy2; + double ix, iy; + double fdx1, fdy1, fdx2, fdy2; + double mdx, mdy; + + /* + * we've got the points already transformed to device + * space, but need to do some computation with them and + * also need to transform the slope from user space to + * device space + */ + /* outer point of incoming line face */ + x1 = _cairo_fixed_to_double (inpt->x); + y1 = _cairo_fixed_to_double (inpt->y); + dx1 = in->dev_slope.x; + dy1 = in->dev_slope.y; + + /* outer point of outgoing line face */ + x2 = _cairo_fixed_to_double (outpt->x); + y2 = _cairo_fixed_to_double (outpt->y); + dx2 = out->dev_slope.x; + dy2 = out->dev_slope.y; + + /* + * Compute the location of the outer corner of the miter. + * That's pretty easy -- just the intersection of the two + * outer edges. We've got slopes and points on each + * of those edges. Compute my directly, then compute + * mx by using the edge with the larger dy; that avoids + * dividing by values close to zero. + */ + my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / + (dx1 * dy2 - dx2 * dy1)); + if (fabs (dy1) >= fabs (dy2)) + mx = (my - y1) * dx1 / dy1 + x1; + else + mx = (my - y2) * dx2 / dy2 + x2; + + /* + * When the two outer edges are nearly parallel, slight + * perturbations in the position of the outer points of the lines + * caused by representing them in fixed point form can cause the + * intersection point of the miter to move a large amount. If + * that moves the miter intersection from between the two faces, + * then draw a bevel instead. + */ + + ix = _cairo_fixed_to_double (in->point.x); + iy = _cairo_fixed_to_double (in->point.y); + + /* slope of one face */ + fdx1 = x1 - ix; fdy1 = y1 - iy; + + /* slope of the other face */ + fdx2 = x2 - ix; fdy2 = y2 - iy; + + /* slope from the intersection to the miter point */ + mdx = mx - ix; mdy = my - iy; + + /* + * Make sure the miter point line lies between the two + * faces by comparing the slopes + */ + if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != + slope_compare_sgn (fdx2, fdy2, mdx, mdy)) + { + cairo_point_t p; + + p.x = _cairo_fixed_from_double (mx); + p.y = _cairo_fixed_from_double (my); + + *_cairo_contour_last_point (&outer->contour) = p; + *_cairo_contour_first_point (&outer->contour) = p; + return; + } + } + break; + } + + case CAIRO_LINE_JOIN_BEVEL: + break; + } + contour_add_point (stroker, outer, outpt); +} + +static void +outer_join (struct stroker *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out, + int clockwise) +{ + const cairo_point_t *inpt, *outpt; + struct stroke_contour *outer; + + if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && + in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) + { + return; + } + if (clockwise) { + inpt = &in->cw; + outpt = &out->cw; + outer = &stroker->cw; + } else { + inpt = &in->ccw; + outpt = &out->ccw; + outer = &stroker->ccw; + } + + switch (stroker->style.line_join) { + case CAIRO_LINE_JOIN_ROUND: + /* construct a fan around the common midpoint */ + add_fan (stroker, + &in->dev_vector, &out->dev_vector, &in->point, + clockwise, outer); + break; + + case CAIRO_LINE_JOIN_MITER: + default: { + /* dot product of incoming slope vector with outgoing slope vector */ + double in_dot_out = in->dev_slope.x * out->dev_slope.x + + in->dev_slope.y * out->dev_slope.y; + double ml = stroker->style.miter_limit; + + /* Check the miter limit -- lines meeting at an acute angle + * can generate long miters, the limit converts them to bevel + * + * Consider the miter join formed when two line segments + * meet at an angle psi: + * + * /.\ + * /. .\ + * /./ \.\ + * /./psi\.\ + * + * We can zoom in on the right half of that to see: + * + * |\ + * | \ psi/2 + * | \ + * | \ + * | \ + * | \ + * miter \ + * length \ + * | \ + * | .\ + * | . \ + * |. line \ + * \ width \ + * \ \ + * + * + * The right triangle in that figure, (the line-width side is + * shown faintly with three '.' characters), gives us the + * following expression relating miter length, angle and line + * width: + * + * 1 /sin (psi/2) = miter_length / line_width + * + * The right-hand side of this relationship is the same ratio + * in which the miter limit (ml) is expressed. We want to know + * when the miter length is within the miter limit. That is + * when the following condition holds: + * + * 1/sin(psi/2) <= ml + * 1 <= ml sin(psi/2) + * 1 <= ml² sin²(psi/2) + * 2 <= ml² 2 sin²(psi/2) + * 2·sin²(psi/2) = 1-cos(psi) + * 2 <= ml² (1-cos(psi)) + * + * in · out = |in| |out| cos (psi) + * + * in and out are both unit vectors, so: + * + * in · out = cos (psi) + * + * 2 <= ml² (1 - in · out) + * + */ + if (2 <= ml * ml * (1 + in_dot_out)) { + double x1, y1, x2, y2; + double mx, my; + double dx1, dx2, dy1, dy2; + double ix, iy; + double fdx1, fdy1, fdx2, fdy2; + double mdx, mdy; + + /* + * we've got the points already transformed to device + * space, but need to do some computation with them and + * also need to transform the slope from user space to + * device space + */ + /* outer point of incoming line face */ + x1 = _cairo_fixed_to_double (inpt->x); + y1 = _cairo_fixed_to_double (inpt->y); + dx1 = in->dev_slope.x; + dy1 = in->dev_slope.y; + + /* outer point of outgoing line face */ + x2 = _cairo_fixed_to_double (outpt->x); + y2 = _cairo_fixed_to_double (outpt->y); + dx2 = out->dev_slope.x; + dy2 = out->dev_slope.y; + + /* + * Compute the location of the outer corner of the miter. + * That's pretty easy -- just the intersection of the two + * outer edges. We've got slopes and points on each + * of those edges. Compute my directly, then compute + * mx by using the edge with the larger dy; that avoids + * dividing by values close to zero. + */ + my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / + (dx1 * dy2 - dx2 * dy1)); + if (fabs (dy1) >= fabs (dy2)) + mx = (my - y1) * dx1 / dy1 + x1; + else + mx = (my - y2) * dx2 / dy2 + x2; + + /* + * When the two outer edges are nearly parallel, slight + * perturbations in the position of the outer points of the lines + * caused by representing them in fixed point form can cause the + * intersection point of the miter to move a large amount. If + * that moves the miter intersection from between the two faces, + * then draw a bevel instead. + */ + + ix = _cairo_fixed_to_double (in->point.x); + iy = _cairo_fixed_to_double (in->point.y); + + /* slope of one face */ + fdx1 = x1 - ix; fdy1 = y1 - iy; + + /* slope of the other face */ + fdx2 = x2 - ix; fdy2 = y2 - iy; + + /* slope from the intersection to the miter point */ + mdx = mx - ix; mdy = my - iy; + + /* + * Make sure the miter point line lies between the two + * faces by comparing the slopes + */ + if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != + slope_compare_sgn (fdx2, fdy2, mdx, mdy)) + { + cairo_point_t p; + + p.x = _cairo_fixed_from_double (mx); + p.y = _cairo_fixed_from_double (my); + + *_cairo_contour_last_point (&outer->contour) = p; + return; + } + } + break; + } + + case CAIRO_LINE_JOIN_BEVEL: + break; + } + contour_add_point (stroker,outer, outpt); +} + +static void +add_cap (struct stroker *stroker, + const cairo_stroke_face_t *f, + struct stroke_contour *c) +{ + switch (stroker->style.line_cap) { + case CAIRO_LINE_CAP_ROUND: { + cairo_slope_t slope; + + slope.dx = -f->dev_vector.dx; + slope.dy = -f->dev_vector.dy; + + add_fan (stroker, &f->dev_vector, &slope, &f->point, FALSE, c); + break; + } + + case CAIRO_LINE_CAP_SQUARE: { + cairo_slope_t fvector; + cairo_point_t p; + double dx, dy; + + dx = f->usr_vector.x; + dy = f->usr_vector.y; + dx *= stroker->half_line_width; + dy *= stroker->half_line_width; + cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); + fvector.dx = _cairo_fixed_from_double (dx); + fvector.dy = _cairo_fixed_from_double (dy); + + p.x = f->ccw.x + fvector.dx; + p.y = f->ccw.y + fvector.dy; + contour_add_point (stroker, c, &p); + + p.x = f->cw.x + fvector.dx; + p.y = f->cw.y + fvector.dy; + contour_add_point (stroker, c, &p); + } + + case CAIRO_LINE_CAP_BUTT: + default: + break; + } + contour_add_point (stroker, c, &f->cw); +} + +static void +add_leading_cap (struct stroker *stroker, + const cairo_stroke_face_t *face, + struct stroke_contour *c) +{ + cairo_stroke_face_t reversed; + cairo_point_t t; + + reversed = *face; + + /* The initial cap needs an outward facing vector. Reverse everything */ + reversed.usr_vector.x = -reversed.usr_vector.x; + reversed.usr_vector.y = -reversed.usr_vector.y; + reversed.dev_vector.dx = -reversed.dev_vector.dx; + reversed.dev_vector.dy = -reversed.dev_vector.dy; + + t = reversed.cw; + reversed.cw = reversed.ccw; + reversed.ccw = t; + + add_cap (stroker, &reversed, c); +} + +static void +add_trailing_cap (struct stroker *stroker, + const cairo_stroke_face_t *face, + struct stroke_contour *c) +{ + add_cap (stroker, face, c); +} + +static inline double +normalize_slope (double *dx, double *dy) +{ + double dx0 = *dx, dy0 = *dy; + double mag; + + assert (dx0 != 0.0 || dy0 != 0.0); + + if (dx0 == 0.0) { + *dx = 0.0; + if (dy0 > 0.0) { + mag = dy0; + *dy = 1.0; + } else { + mag = -dy0; + *dy = -1.0; + } + } else if (dy0 == 0.0) { + *dy = 0.0; + if (dx0 > 0.0) { + mag = dx0; + *dx = 1.0; + } else { + mag = -dx0; + *dx = -1.0; + } + } else { + mag = hypot (dx0, dy0); + *dx = dx0 / mag; + *dy = dy0 / mag; + } + + return mag; +} + +static void +compute_face (const cairo_point_t *point, + const cairo_slope_t *dev_slope, + struct stroker *stroker, + cairo_stroke_face_t *face) +{ + double face_dx, face_dy; + cairo_point_t offset_ccw, offset_cw; + double slope_dx, slope_dy; + + slope_dx = _cairo_fixed_to_double (dev_slope->dx); + slope_dy = _cairo_fixed_to_double (dev_slope->dy); + face->length = normalize_slope (&slope_dx, &slope_dy); + face->dev_slope.x = slope_dx; + face->dev_slope.y = slope_dy; + + /* + * rotate to get a line_width/2 vector along the face, note that + * the vector must be rotated the right direction in device space, + * but by 90° in user space. So, the rotation depends on + * whether the ctm reflects or not, and that can be determined + * by looking at the determinant of the matrix. + */ + if (! _cairo_matrix_is_identity (stroker->ctm_inverse)) { + /* Normalize the matrix! */ + cairo_matrix_transform_distance (stroker->ctm_inverse, + &slope_dx, &slope_dy); + normalize_slope (&slope_dx, &slope_dy); + + if (stroker->ctm_det_positive) { + face_dx = - slope_dy * stroker->half_line_width; + face_dy = slope_dx * stroker->half_line_width; + } else { + face_dx = slope_dy * stroker->half_line_width; + face_dy = - slope_dx * stroker->half_line_width; + } + + /* back to device space */ + cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); + } else { + face_dx = - slope_dy * stroker->half_line_width; + face_dy = slope_dx * stroker->half_line_width; + } + + offset_ccw.x = _cairo_fixed_from_double (face_dx); + offset_ccw.y = _cairo_fixed_from_double (face_dy); + offset_cw.x = -offset_ccw.x; + offset_cw.y = -offset_ccw.y; + + face->ccw = *point; + translate_point (&face->ccw, &offset_ccw); + + face->point = *point; + + face->cw = *point; + translate_point (&face->cw, &offset_cw); + + face->usr_vector.x = slope_dx; + face->usr_vector.y = slope_dy; + + face->dev_vector = *dev_slope; +} + +static void +add_caps (struct stroker *stroker) +{ + /* check for a degenerative sub_path */ + if (stroker->has_initial_sub_path && + ! stroker->has_first_face && + ! stroker->has_current_face && + stroker->style.line_cap == CAIRO_LINE_CAP_ROUND) + { + /* pick an arbitrary slope to use */ + cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; + cairo_stroke_face_t face; + + /* arbitrarily choose first_point */ + compute_face (&stroker->first_point, &slope, stroker, &face); + + add_leading_cap (stroker, &face, &stroker->ccw); + add_trailing_cap (stroker, &face, &stroker->ccw); + + /* ensure the circle is complete */ + _cairo_contour_add_point (&stroker->ccw.contour, + _cairo_contour_first_point (&stroker->ccw.contour)); + + _cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); + _cairo_contour_reset (&stroker->ccw.contour); + } else { + if (stroker->has_current_face) + add_trailing_cap (stroker, &stroker->current_face, &stroker->ccw); + +#if DEBUG + { + FILE *file = fopen ("contours.txt", "a"); + _cairo_debug_print_contour (file, &stroker->path); + _cairo_debug_print_contour (file, &stroker->cw.contour); + _cairo_debug_print_contour (file, &stroker->ccw.contour); + fclose (file); + _cairo_contour_reset (&stroker->path); + } +#endif + + _cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); + _cairo_contour_reset (&stroker->ccw.contour); + + if (stroker->has_first_face) { + _cairo_contour_add_point (&stroker->ccw.contour, + &stroker->first_face.cw); + add_leading_cap (stroker, &stroker->first_face, &stroker->ccw); +#if DEBUG + { + FILE *file = fopen ("contours.txt", "a"); + _cairo_debug_print_contour (file, &stroker->ccw.contour); + fclose (file); + } +#endif + + _cairo_polygon_add_contour (stroker->polygon, + &stroker->ccw.contour); + _cairo_contour_reset (&stroker->ccw.contour); + } + + _cairo_polygon_add_contour (stroker->polygon, &stroker->cw.contour); + _cairo_contour_reset (&stroker->cw.contour); + } +} + +static cairo_status_t +close_path (void *closure); + +static cairo_status_t +move_to (void *closure, + const cairo_point_t *point) +{ + struct stroker *stroker = closure; + + /* Cap the start and end of the previous sub path as needed */ + add_caps (stroker); + + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + stroker->has_initial_sub_path = FALSE; + + stroker->first_point = *point; + +#if DEBUG + _cairo_contour_add_point (&stroker->path, point); +#endif + + stroker->current_face.point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +line_to (void *closure, + const cairo_point_t *point) +{ + struct stroker *stroker = closure; + cairo_stroke_face_t start; + cairo_point_t *p1 = &stroker->current_face.point; + cairo_slope_t dev_slope; + + stroker->has_initial_sub_path = TRUE; + + if (p1->x == point->x && p1->y == point->y) + return CAIRO_STATUS_SUCCESS; + +#if DEBUG + _cairo_contour_add_point (&stroker->path, point); +#endif + + _cairo_slope_init (&dev_slope, p1, point); + compute_face (p1, &dev_slope, stroker, &start); + + if (stroker->has_current_face) { + int clockwise = _cairo_slope_compare (&stroker->current_face.dev_vector, + &start.dev_vector); + if (clockwise) { + clockwise = clockwise < 0; + /* Join with final face from previous segment */ + if (! within_tolerance (&stroker->current_face.ccw, &start.ccw, + stroker->contour_tolerance) || + ! within_tolerance (&stroker->current_face.cw, &start.cw, + stroker->contour_tolerance)) + { + outer_join (stroker, &stroker->current_face, &start, clockwise); + inner_join (stroker, &stroker->current_face, &start, clockwise); + } + } + } else { + if (! stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = start; + stroker->has_first_face = TRUE; + } + stroker->has_current_face = TRUE; + + contour_add_point (stroker, &stroker->cw, &start.cw); + contour_add_point (stroker, &stroker->ccw, &start.ccw); + } + + stroker->current_face = start; + stroker->current_face.point = *point; + stroker->current_face.ccw.x += dev_slope.dx; + stroker->current_face.ccw.y += dev_slope.dy; + stroker->current_face.cw.x += dev_slope.dx; + stroker->current_face.cw.y += dev_slope.dy; + + contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw); + contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +spline_to (void *closure, + const cairo_point_t *point, + const cairo_slope_t *tangent) +{ + struct stroker *stroker = closure; + cairo_stroke_face_t face; + +#if DEBUG + _cairo_contour_add_point (&stroker->path, point); +#endif + if ((tangent->dx | tangent->dy) == 0) { + struct stroke_contour *outer; + cairo_point_t t; + int clockwise; + + face = stroker->current_face; + + face.usr_vector.x = -face.usr_vector.x; + face.usr_vector.y = -face.usr_vector.y; + face.dev_vector.dx = -face.dev_vector.dx; + face.dev_vector.dy = -face.dev_vector.dy; + + t = face.cw; + face.cw = face.ccw; + face.ccw = t; + + clockwise = join_is_clockwise (&stroker->current_face, &face); + if (clockwise) { + outer = &stroker->cw; + } else { + outer = &stroker->ccw; + } + + add_fan (stroker, + &stroker->current_face.dev_vector, + &face.dev_vector, + &stroker->current_face.point, + clockwise, outer); + } else { + compute_face (point, tangent, stroker, &face); + + if ((face.dev_slope.x * stroker->current_face.dev_slope.x + + face.dev_slope.y * stroker->current_face.dev_slope.y) < stroker->spline_cusp_tolerance) + { + struct stroke_contour *outer; + int clockwise = join_is_clockwise (&stroker->current_face, &face); + + stroker->current_face.cw.x += face.point.x - stroker->current_face.point.x; + stroker->current_face.cw.y += face.point.y - stroker->current_face.point.y; + contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw); + + stroker->current_face.ccw.x += face.point.x - stroker->current_face.point.x; + stroker->current_face.ccw.y += face.point.y - stroker->current_face.point.y; + contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw); + + if (clockwise) { + outer = &stroker->cw; + } else { + outer = &stroker->ccw; + } + add_fan (stroker, + &stroker->current_face.dev_vector, + &face.dev_vector, + &stroker->current_face.point, + clockwise, outer); + } + + contour_add_point (stroker, &stroker->cw, &face.cw); + contour_add_point (stroker, &stroker->ccw, &face.ccw); + } + + stroker->current_face = face; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + struct stroker *stroker = closure; + cairo_spline_t spline; + cairo_stroke_face_t face; + + if (stroker->has_bounds && + ! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, + &stroker->bounds)) + return line_to (closure, d); + + if (! _cairo_spline_init (&spline, spline_to, stroker, + &stroker->current_face.point, b, c, d)) + return line_to (closure, d); + + compute_face (&stroker->current_face.point, &spline.initial_slope, + stroker, &face); + + if (stroker->has_current_face) { + int clockwise = join_is_clockwise (&stroker->current_face, &face); + /* Join with final face from previous segment */ + outer_join (stroker, &stroker->current_face, &face, clockwise); + inner_join (stroker, &stroker->current_face, &face, clockwise); + } else { + if (! stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = face; + stroker->has_first_face = TRUE; + } + stroker->has_current_face = TRUE; + + contour_add_point (stroker, &stroker->cw, &face.cw); + contour_add_point (stroker, &stroker->ccw, &face.ccw); + } + stroker->current_face = face; + + return _cairo_spline_decompose (&spline, stroker->tolerance); +} + +static cairo_status_t +close_path (void *closure) +{ + struct stroker *stroker = closure; + cairo_status_t status; + + status = line_to (stroker, &stroker->first_point); + if (unlikely (status)) + return status; + + if (stroker->has_first_face && stroker->has_current_face) { + /* Join first and final faces of sub path */ + outer_close (stroker, &stroker->current_face, &stroker->first_face); + inner_close (stroker, &stroker->current_face, &stroker->first_face); +#if 0 + *_cairo_contour_first_point (&stroker->ccw.contour) = + *_cairo_contour_last_point (&stroker->ccw.contour); + + *_cairo_contour_first_point (&stroker->cw.contour) = + *_cairo_contour_last_point (&stroker->cw.contour); +#endif + + _cairo_polygon_add_contour (stroker->polygon, &stroker->cw.contour); + _cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); + +#if DEBUG + { + FILE *file = fopen ("contours.txt", "a"); + _cairo_debug_print_contour (file, &stroker->path); + _cairo_debug_print_contour (file, &stroker->cw.contour); + _cairo_debug_print_contour (file, &stroker->ccw.contour); + fclose (file); + + _cairo_contour_reset (&stroker->path); + } +#endif + _cairo_contour_reset (&stroker->cw.contour); + _cairo_contour_reset (&stroker->ccw.contour); + } else { + /* Cap the start and end of the sub path as needed */ + add_caps (stroker); + } + + stroker->has_initial_sub_path = FALSE; + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_path_fixed_stroke_to_polygon (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_polygon_t *polygon) +{ + struct stroker stroker; + cairo_status_t status; + + if (style->num_dashes) { + return _cairo_path_fixed_stroke_dashed_to_polygon (path, + style, + ctm, + ctm_inverse, + tolerance, + polygon); + } + + stroker.has_bounds = polygon->num_limits; + if (stroker.has_bounds) { + /* Extend the bounds in each direction to account for the maximum area + * we might generate trapezoids, to capture line segments that are + * outside of the bounds but which might generate rendering that's + * within bounds. + */ + double dx, dy; + cairo_fixed_t fdx, fdy; + int i; + + stroker.bounds = polygon->limits[0]; + for (i = 1; i < polygon->num_limits; i++) + _cairo_box_add_box (&stroker.bounds, &polygon->limits[i]); + + _cairo_stroke_style_max_distance_from_path (style, path, ctm, &dx, &dy); + fdx = _cairo_fixed_from_double (dx); + fdy = _cairo_fixed_from_double (dy); + + stroker.bounds.p1.x -= fdx; + stroker.bounds.p2.x += fdx; + stroker.bounds.p1.y -= fdy; + stroker.bounds.p2.y += fdy; + } + + stroker.style = *style; + stroker.ctm = ctm; + stroker.ctm_inverse = ctm_inverse; + stroker.tolerance = tolerance; + stroker.half_line_width = style->line_width / 2.; + /* To test whether we need to join two segments of a spline using + * a round-join or a bevel-join, we can inspect the angle between the + * two segments. If the difference between the chord distance + * (half-line-width times the cosine of the bisection angle) and the + * half-line-width itself is greater than tolerance then we need to + * inject a point. + */ + stroker.spline_cusp_tolerance = 1 - tolerance / stroker.half_line_width; + stroker.spline_cusp_tolerance *= stroker.spline_cusp_tolerance; + stroker.spline_cusp_tolerance *= 2; + stroker.spline_cusp_tolerance -= 1; + stroker.ctm_det_positive = + _cairo_matrix_compute_determinant (ctm) >= 0.0; + + stroker.pen.num_vertices = 0; + if (path->has_curve_to || + style->line_join == CAIRO_LINE_JOIN_ROUND || + style->line_cap == CAIRO_LINE_CAP_ROUND) { + status = _cairo_pen_init (&stroker.pen, + stroker.half_line_width, + tolerance, ctm); + if (unlikely (status)) + return status; + + /* If the line width is so small that the pen is reduced to a + single point, then we have nothing to do. */ + if (stroker.pen.num_vertices <= 1) + return CAIRO_STATUS_SUCCESS; + } + + stroker.has_current_face = FALSE; + stroker.has_first_face = FALSE; + stroker.has_initial_sub_path = FALSE; + +#if DEBUG + remove ("contours.txt"); + remove ("polygons.txt"); + _cairo_contour_init (&stroker.path, 0); +#endif + _cairo_contour_init (&stroker.cw.contour, 1); + _cairo_contour_init (&stroker.ccw.contour, -1); + tolerance *= CAIRO_FIXED_ONE; + tolerance *= tolerance; + stroker.contour_tolerance = tolerance; + stroker.polygon = polygon; + + status = _cairo_path_fixed_interpret (path, + move_to, + line_to, + curve_to, + close_path, + &stroker); + /* Cap the start and end of the final sub path as needed */ + if (likely (status == CAIRO_STATUS_SUCCESS)) + add_caps (&stroker); + + _cairo_contour_fini (&stroker.cw.contour); + _cairo_contour_fini (&stroker.ccw.contour); + if (stroker.pen.num_vertices) + _cairo_pen_fini (&stroker.pen); + +#if DEBUG + { + FILE *file = fopen ("polygons.txt", "a"); + _cairo_debug_print_polygon (file, polygon); + fclose (file); + } +#endif + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-traps.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-traps.c new file mode 100644 index 00000000000..da54e5a358f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-traps.c @@ -0,0 +1,1149 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2013 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-path-fixed-private.h" +#include "cairo-slope-private.h" +#include "cairo-stroke-dash-private.h" +#include "cairo-traps-private.h" + +#include + +struct stroker { + const cairo_stroke_style_t *style; + + const cairo_matrix_t *ctm; + const cairo_matrix_t *ctm_inverse; + double spline_cusp_tolerance; + double half_line_width; + double tolerance; + double ctm_determinant; + cairo_bool_t ctm_det_positive; + cairo_line_join_t line_join; + + cairo_traps_t *traps; + + cairo_pen_t pen; + + cairo_point_t first_point; + + cairo_bool_t has_initial_sub_path; + + cairo_bool_t has_current_face; + cairo_stroke_face_t current_face; + + cairo_bool_t has_first_face; + cairo_stroke_face_t first_face; + + cairo_stroker_dash_t dash; + + cairo_bool_t has_bounds; + cairo_box_t tight_bounds; + cairo_box_t line_bounds; + cairo_box_t join_bounds; +}; + +static cairo_status_t +stroker_init (struct stroker *stroker, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_traps_t *traps) +{ + cairo_status_t status; + + stroker->style = style; + stroker->ctm = ctm; + stroker->ctm_inverse = NULL; + if (! _cairo_matrix_is_identity (ctm_inverse)) + stroker->ctm_inverse = ctm_inverse; + stroker->line_join = style->line_join; + stroker->half_line_width = style->line_width / 2.0; + stroker->tolerance = tolerance; + stroker->traps = traps; + + /* To test whether we need to join two segments of a spline using + * a round-join or a bevel-join, we can inspect the angle between the + * two segments. If the difference between the chord distance + * (half-line-width times the cosine of the bisection angle) and the + * half-line-width itself is greater than tolerance then we need to + * inject a point. + */ + stroker->spline_cusp_tolerance = 1 - tolerance / stroker->half_line_width; + stroker->spline_cusp_tolerance *= stroker->spline_cusp_tolerance; + stroker->spline_cusp_tolerance *= 2; + stroker->spline_cusp_tolerance -= 1; + + stroker->ctm_determinant = _cairo_matrix_compute_determinant (stroker->ctm); + stroker->ctm_det_positive = stroker->ctm_determinant >= 0.0; + + status = _cairo_pen_init (&stroker->pen, + stroker->half_line_width, + tolerance, ctm); + if (unlikely (status)) + return status; + + stroker->has_current_face = FALSE; + stroker->has_first_face = FALSE; + stroker->has_initial_sub_path = FALSE; + + _cairo_stroker_dash_init (&stroker->dash, style); + + stroker->has_bounds = traps->num_limits; + if (stroker->has_bounds) { + /* Extend the bounds in each direction to account for the maximum area + * we might generate trapezoids, to capture line segments that are outside + * of the bounds but which might generate rendering that's within bounds. + */ + double dx, dy; + cairo_fixed_t fdx, fdy; + + stroker->tight_bounds = traps->bounds; + + _cairo_stroke_style_max_distance_from_path (stroker->style, path, + stroker->ctm, &dx, &dy); + + _cairo_stroke_style_max_line_distance_from_path (stroker->style, path, + stroker->ctm, &dx, &dy); + + fdx = _cairo_fixed_from_double (dx); + fdy = _cairo_fixed_from_double (dy); + + stroker->line_bounds = stroker->tight_bounds; + stroker->line_bounds.p1.x -= fdx; + stroker->line_bounds.p2.x += fdx; + stroker->line_bounds.p1.y -= fdy; + stroker->line_bounds.p2.y += fdy; + + _cairo_stroke_style_max_join_distance_from_path (stroker->style, path, + stroker->ctm, &dx, &dy); + + fdx = _cairo_fixed_from_double (dx); + fdy = _cairo_fixed_from_double (dy); + + stroker->join_bounds = stroker->tight_bounds; + stroker->join_bounds.p1.x -= fdx; + stroker->join_bounds.p2.x += fdx; + stroker->join_bounds.p1.y -= fdy; + stroker->join_bounds.p2.y += fdy; + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +stroker_fini (struct stroker *stroker) +{ + _cairo_pen_fini (&stroker->pen); +} + +static void +translate_point (cairo_point_t *point, cairo_point_t *offset) +{ + point->x += offset->x; + point->y += offset->y; +} + +static int +join_is_clockwise (const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + return _cairo_slope_compare (&in->dev_vector, &out->dev_vector) < 0; +} + +static int +slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) +{ + double c = dx1 * dy2 - dx2 * dy1; + if (c > 0) return 1; + if (c < 0) return -1; + return 0; +} + +static cairo_bool_t +stroker_intersects_join (const struct stroker *stroker, + const cairo_point_t *in, + const cairo_point_t *out) +{ + cairo_line_t segment; + + if (! stroker->has_bounds) + return TRUE; + + segment.p1 = *in; + segment.p2 = *out; + return _cairo_box_intersects_line_segment (&stroker->join_bounds, &segment); +} + +static void +join (struct stroker *stroker, + cairo_stroke_face_t *in, + cairo_stroke_face_t *out) +{ + int clockwise = join_is_clockwise (out, in); + cairo_point_t *inpt, *outpt; + + if (in->cw.x == out->cw.x && + in->cw.y == out->cw.y && + in->ccw.x == out->ccw.x && + in->ccw.y == out->ccw.y) + { + return; + } + + if (clockwise) { + inpt = &in->ccw; + outpt = &out->ccw; + } else { + inpt = &in->cw; + outpt = &out->cw; + } + + if (! stroker_intersects_join (stroker, inpt, outpt)) + return; + + switch (stroker->line_join) { + case CAIRO_LINE_JOIN_ROUND: + /* construct a fan around the common midpoint */ + if ((in->dev_slope.x * out->dev_slope.x + + in->dev_slope.y * out->dev_slope.y) < stroker->spline_cusp_tolerance) + { + int start, stop; + cairo_point_t tri[3], edges[4]; + cairo_pen_t *pen = &stroker->pen; + + edges[0] = in->cw; + edges[1] = in->ccw; + tri[0] = in->point; + tri[1] = *inpt; + if (clockwise) { + _cairo_pen_find_active_ccw_vertices (pen, + &in->dev_vector, &out->dev_vector, + &start, &stop); + while (start != stop) { + tri[2] = in->point; + translate_point (&tri[2], &pen->vertices[start].point); + edges[2] = in->point; + edges[3] = tri[2]; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, + tri, edges); + tri[1] = tri[2]; + edges[0] = edges[2]; + edges[1] = edges[3]; + + if (start-- == 0) + start += pen->num_vertices; + } + } else { + _cairo_pen_find_active_cw_vertices (pen, + &in->dev_vector, &out->dev_vector, + &start, &stop); + while (start != stop) { + tri[2] = in->point; + translate_point (&tri[2], &pen->vertices[start].point); + edges[2] = in->point; + edges[3] = tri[2]; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, + tri, edges); + tri[1] = tri[2]; + edges[0] = edges[2]; + edges[1] = edges[3]; + + if (++start == pen->num_vertices) + start = 0; + } + } + tri[2] = *outpt; + edges[2] = out->cw; + edges[3] = out->ccw; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, + tri, edges); + } else { + cairo_point_t t[] = { { in->point.x, in->point.y}, { inpt->x, inpt->y }, { outpt->x, outpt->y } }; + cairo_point_t e[] = { { in->cw.x, in->cw.y}, { in->ccw.x, in->ccw.y }, + { out->cw.x, out->cw.y}, { out->ccw.x, out->ccw.y } }; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, t, e); + } + break; + + case CAIRO_LINE_JOIN_MITER: + default: { + /* dot product of incoming slope vector with outgoing slope vector */ + double in_dot_out = (-in->usr_vector.x * out->usr_vector.x + + -in->usr_vector.y * out->usr_vector.y); + double ml = stroker->style->miter_limit; + + /* Check the miter limit -- lines meeting at an acute angle + * can generate long miters, the limit converts them to bevel + * + * Consider the miter join formed when two line segments + * meet at an angle psi: + * + * /.\ + * /. .\ + * /./ \.\ + * /./psi\.\ + * + * We can zoom in on the right half of that to see: + * + * |\ + * | \ psi/2 + * | \ + * | \ + * | \ + * | \ + * miter \ + * length \ + * | \ + * | .\ + * | . \ + * |. line \ + * \ width \ + * \ \ + * + * + * The right triangle in that figure, (the line-width side is + * shown faintly with three '.' characters), gives us the + * following expression relating miter length, angle and line + * width: + * + * 1 /sin (psi/2) = miter_length / line_width + * + * The right-hand side of this relationship is the same ratio + * in which the miter limit (ml) is expressed. We want to know + * when the miter length is within the miter limit. That is + * when the following condition holds: + * + * 1/sin(psi/2) <= ml + * 1 <= ml sin(psi/2) + * 1 <= ml² sin²(psi/2) + * 2 <= ml² 2 sin²(psi/2) + * 2·sin²(psi/2) = 1-cos(psi) + * 2 <= ml² (1-cos(psi)) + * + * in · out = |in| |out| cos (psi) + * + * in and out are both unit vectors, so: + * + * in · out = cos (psi) + * + * 2 <= ml² (1 - in · out) + * + */ + if (2 <= ml * ml * (1 - in_dot_out)) { + double x1, y1, x2, y2; + double mx, my; + double dx1, dx2, dy1, dy2; + cairo_point_t outer; + cairo_point_t quad[4]; + double ix, iy; + double fdx1, fdy1, fdx2, fdy2; + double mdx, mdy; + + /* + * we've got the points already transformed to device + * space, but need to do some computation with them and + * also need to transform the slope from user space to + * device space + */ + /* outer point of incoming line face */ + x1 = _cairo_fixed_to_double (inpt->x); + y1 = _cairo_fixed_to_double (inpt->y); + dx1 = in->usr_vector.x; + dy1 = in->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); + + /* outer point of outgoing line face */ + x2 = _cairo_fixed_to_double (outpt->x); + y2 = _cairo_fixed_to_double (outpt->y); + dx2 = out->usr_vector.x; + dy2 = out->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); + + /* + * Compute the location of the outer corner of the miter. + * That's pretty easy -- just the intersection of the two + * outer edges. We've got slopes and points on each + * of those edges. Compute my directly, then compute + * mx by using the edge with the larger dy; that avoids + * dividing by values close to zero. + */ + my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / + (dx1 * dy2 - dx2 * dy1)); + if (fabs (dy1) >= fabs (dy2)) + mx = (my - y1) * dx1 / dy1 + x1; + else + mx = (my - y2) * dx2 / dy2 + x2; + + /* + * When the two outer edges are nearly parallel, slight + * perturbations in the position of the outer points of the lines + * caused by representing them in fixed point form can cause the + * intersection point of the miter to move a large amount. If + * that moves the miter intersection from between the two faces, + * then draw a bevel instead. + */ + + ix = _cairo_fixed_to_double (in->point.x); + iy = _cairo_fixed_to_double (in->point.y); + + /* slope of one face */ + fdx1 = x1 - ix; fdy1 = y1 - iy; + + /* slope of the other face */ + fdx2 = x2 - ix; fdy2 = y2 - iy; + + /* slope from the intersection to the miter point */ + mdx = mx - ix; mdy = my - iy; + + /* + * Make sure the miter point line lies between the two + * faces by comparing the slopes + */ + if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != + slope_compare_sgn (fdx2, fdy2, mdx, mdy)) + { + /* + * Draw the quadrilateral + */ + outer.x = _cairo_fixed_from_double (mx); + outer.y = _cairo_fixed_from_double (my); + + quad[0] = in->point; + quad[1] = *inpt; + quad[2] = outer; + quad[3] = *outpt; + + _cairo_traps_tessellate_convex_quad (stroker->traps, quad); + break; + } + } + /* fall through ... */ + } + + case CAIRO_LINE_JOIN_BEVEL: { + cairo_point_t t[] = { { in->point.x, in->point.y }, { inpt->x, inpt->y }, { outpt->x, outpt->y } }; + cairo_point_t e[] = { { in->cw.x, in->cw.y }, { in->ccw.x, in->ccw.y }, + { out->cw.x, out->cw.y }, { out->ccw.x, out->ccw.y } }; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, t, e); + break; + } + } +} + +static void +add_cap (struct stroker *stroker, cairo_stroke_face_t *f) +{ + switch (stroker->style->line_cap) { + case CAIRO_LINE_CAP_ROUND: { + int start, stop; + cairo_slope_t in_slope, out_slope; + cairo_point_t tri[3], edges[4]; + cairo_pen_t *pen = &stroker->pen; + + in_slope = f->dev_vector; + out_slope.dx = -in_slope.dx; + out_slope.dy = -in_slope.dy; + _cairo_pen_find_active_cw_vertices (pen, &in_slope, &out_slope, + &start, &stop); + edges[0] = f->cw; + edges[1] = f->ccw; + tri[0] = f->point; + tri[1] = f->cw; + while (start != stop) { + tri[2] = f->point; + translate_point (&tri[2], &pen->vertices[start].point); + edges[2] = f->point; + edges[3] = tri[2]; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, + tri, edges); + + tri[1] = tri[2]; + edges[0] = edges[2]; + edges[1] = edges[3]; + if (++start == pen->num_vertices) + start = 0; + } + tri[2] = f->ccw; + edges[2] = f->cw; + edges[3] = f->ccw; + _cairo_traps_tessellate_triangle_with_edges (stroker->traps, + tri, edges); + break; + } + + case CAIRO_LINE_CAP_SQUARE: { + double dx, dy; + cairo_slope_t fvector; + cairo_point_t quad[4]; + + dx = f->usr_vector.x; + dy = f->usr_vector.y; + dx *= stroker->half_line_width; + dy *= stroker->half_line_width; + cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); + fvector.dx = _cairo_fixed_from_double (dx); + fvector.dy = _cairo_fixed_from_double (dy); + + quad[0] = f->cw; + quad[1].x = f->cw.x + fvector.dx; + quad[1].y = f->cw.y + fvector.dy; + quad[2].x = f->ccw.x + fvector.dx; + quad[2].y = f->ccw.y + fvector.dy; + quad[3] = f->ccw; + + _cairo_traps_tessellate_convex_quad (stroker->traps, quad); + break; + } + + case CAIRO_LINE_CAP_BUTT: + default: + break; + } +} + +static void +add_leading_cap (struct stroker *stroker, + cairo_stroke_face_t *face) +{ + cairo_stroke_face_t reversed; + cairo_point_t t; + + reversed = *face; + + /* The initial cap needs an outward facing vector. Reverse everything */ + reversed.usr_vector.x = -reversed.usr_vector.x; + reversed.usr_vector.y = -reversed.usr_vector.y; + reversed.dev_vector.dx = -reversed.dev_vector.dx; + reversed.dev_vector.dy = -reversed.dev_vector.dy; + t = reversed.cw; + reversed.cw = reversed.ccw; + reversed.ccw = t; + + add_cap (stroker, &reversed); +} + +static void +add_trailing_cap (struct stroker *stroker, cairo_stroke_face_t *face) +{ + add_cap (stroker, face); +} + +static inline double +normalize_slope (double *dx, double *dy) +{ + double dx0 = *dx, dy0 = *dy; + + if (dx0 == 0.0 && dy0 == 0.0) + return 0; + + if (dx0 == 0.0) { + *dx = 0.0; + if (dy0 > 0.0) { + *dy = 1.0; + return dy0; + } else { + *dy = -1.0; + return -dy0; + } + } else if (dy0 == 0.0) { + *dy = 0.0; + if (dx0 > 0.0) { + *dx = 1.0; + return dx0; + } else { + *dx = -1.0; + return -dx0; + } + } else { + double mag = hypot (dx0, dy0); + *dx = dx0 / mag; + *dy = dy0 / mag; + return mag; + } +} + +static void +compute_face (const cairo_point_t *point, + const cairo_slope_t *dev_slope, + struct stroker *stroker, + cairo_stroke_face_t *face) +{ + double face_dx, face_dy; + cairo_point_t offset_ccw, offset_cw; + double slope_dx, slope_dy; + + slope_dx = _cairo_fixed_to_double (dev_slope->dx); + slope_dy = _cairo_fixed_to_double (dev_slope->dy); + face->length = normalize_slope (&slope_dx, &slope_dy); + face->dev_slope.x = slope_dx; + face->dev_slope.y = slope_dy; + + /* + * rotate to get a line_width/2 vector along the face, note that + * the vector must be rotated the right direction in device space, + * but by 90° in user space. So, the rotation depends on + * whether the ctm reflects or not, and that can be determined + * by looking at the determinant of the matrix. + */ + if (stroker->ctm_inverse) { + cairo_matrix_transform_distance (stroker->ctm_inverse, &slope_dx, &slope_dy); + normalize_slope (&slope_dx, &slope_dy); + + if (stroker->ctm_det_positive) { + face_dx = - slope_dy * stroker->half_line_width; + face_dy = slope_dx * stroker->half_line_width; + } else { + face_dx = slope_dy * stroker->half_line_width; + face_dy = - slope_dx * stroker->half_line_width; + } + + /* back to device space */ + cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); + } else { + face_dx = - slope_dy * stroker->half_line_width; + face_dy = slope_dx * stroker->half_line_width; + } + + offset_ccw.x = _cairo_fixed_from_double (face_dx); + offset_ccw.y = _cairo_fixed_from_double (face_dy); + offset_cw.x = -offset_ccw.x; + offset_cw.y = -offset_ccw.y; + + face->ccw = *point; + translate_point (&face->ccw, &offset_ccw); + + face->point = *point; + + face->cw = *point; + translate_point (&face->cw, &offset_cw); + + face->usr_vector.x = slope_dx; + face->usr_vector.y = slope_dy; + + face->dev_vector = *dev_slope; +} + +static void +add_caps (struct stroker *stroker) +{ + /* check for a degenerative sub_path */ + if (stroker->has_initial_sub_path && + !stroker->has_first_face && + !stroker->has_current_face && + stroker->style->line_cap == CAIRO_LINE_CAP_ROUND) + { + /* pick an arbitrary slope to use */ + cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; + cairo_stroke_face_t face; + + /* arbitrarily choose first_point + * first_point and current_point should be the same */ + compute_face (&stroker->first_point, &slope, stroker, &face); + + add_leading_cap (stroker, &face); + add_trailing_cap (stroker, &face); + } + + if (stroker->has_first_face) + add_leading_cap (stroker, &stroker->first_face); + + if (stroker->has_current_face) + add_trailing_cap (stroker, &stroker->current_face); +} + +static cairo_bool_t +stroker_intersects_edge (const struct stroker *stroker, + const cairo_stroke_face_t *start, + const cairo_stroke_face_t *end) +{ + cairo_box_t box; + + if (! stroker->has_bounds) + return TRUE; + + if (_cairo_box_contains_point (&stroker->tight_bounds, &start->cw)) + return TRUE; + box.p2 = box.p1 = start->cw; + + if (_cairo_box_contains_point (&stroker->tight_bounds, &start->ccw)) + return TRUE; + _cairo_box_add_point (&box, &start->ccw); + + if (_cairo_box_contains_point (&stroker->tight_bounds, &end->cw)) + return TRUE; + _cairo_box_add_point (&box, &end->cw); + + if (_cairo_box_contains_point (&stroker->tight_bounds, &end->ccw)) + return TRUE; + _cairo_box_add_point (&box, &end->ccw); + + return (box.p2.x > stroker->tight_bounds.p1.x && + box.p1.x < stroker->tight_bounds.p2.x && + box.p2.y > stroker->tight_bounds.p1.y && + box.p1.y < stroker->tight_bounds.p2.y); +} + +static void +add_sub_edge (struct stroker *stroker, + const cairo_point_t *p1, const cairo_point_t *p2, + const cairo_slope_t *dev_slope, + cairo_stroke_face_t *start, cairo_stroke_face_t *end) +{ + cairo_point_t rectangle[4]; + + compute_face (p1, dev_slope, stroker, start); + + *end = *start; + end->point = *p2; + rectangle[0].x = p2->x - p1->x; + rectangle[0].y = p2->y - p1->y; + translate_point (&end->ccw, &rectangle[0]); + translate_point (&end->cw, &rectangle[0]); + + if (p1->x == p2->x && p1->y == p2->y) + return; + + if (! stroker_intersects_edge (stroker, start, end)) + return; + + rectangle[0] = start->cw; + rectangle[1] = start->ccw; + rectangle[2] = end->ccw; + rectangle[3] = end->cw; + + _cairo_traps_tessellate_convex_quad (stroker->traps, rectangle); +} + +static cairo_status_t +move_to (void *closure, const cairo_point_t *point) +{ + struct stroker *stroker = closure; + + /* Cap the start and end of the previous sub path as needed */ + add_caps (stroker); + + stroker->first_point = *point; + stroker->current_face.point = *point; + + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + stroker->has_initial_sub_path = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +move_to_dashed (void *closure, const cairo_point_t *point) +{ + /* reset the dash pattern for new sub paths */ + struct stroker *stroker = closure; + + _cairo_stroker_dash_start (&stroker->dash); + return move_to (closure, point); +} + +static cairo_status_t +line_to (void *closure, const cairo_point_t *point) +{ + struct stroker *stroker = closure; + cairo_stroke_face_t start, end; + const cairo_point_t *p1 = &stroker->current_face.point; + const cairo_point_t *p2 = point; + cairo_slope_t dev_slope; + + stroker->has_initial_sub_path = TRUE; + + if (p1->x == p2->x && p1->y == p2->y) + return CAIRO_STATUS_SUCCESS; + + _cairo_slope_init (&dev_slope, p1, p2); + add_sub_edge (stroker, p1, p2, &dev_slope, &start, &end); + + if (stroker->has_current_face) { + /* Join with final face from previous segment */ + join (stroker, &stroker->current_face, &start); + } else if (!stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = start; + stroker->has_first_face = TRUE; + } + stroker->current_face = end; + stroker->has_current_face = TRUE; + + return CAIRO_STATUS_SUCCESS; +} + +/* + * Dashed lines. Cap each dash end, join around turns when on + */ +static cairo_status_t +line_to_dashed (void *closure, const cairo_point_t *point) +{ + struct stroker *stroker = closure; + double mag, remain, step_length = 0; + double slope_dx, slope_dy; + double dx2, dy2; + cairo_stroke_face_t sub_start, sub_end; + const cairo_point_t *p1 = &stroker->current_face.point; + const cairo_point_t *p2 = point; + cairo_slope_t dev_slope; + cairo_line_t segment; + cairo_bool_t fully_in_bounds; + + stroker->has_initial_sub_path = stroker->dash.dash_starts_on; + + if (p1->x == p2->x && p1->y == p2->y) + return CAIRO_STATUS_SUCCESS; + + fully_in_bounds = TRUE; + if (stroker->has_bounds && + (! _cairo_box_contains_point (&stroker->join_bounds, p1) || + ! _cairo_box_contains_point (&stroker->join_bounds, p2))) + { + fully_in_bounds = FALSE; + } + + _cairo_slope_init (&dev_slope, p1, p2); + + slope_dx = _cairo_fixed_to_double (p2->x - p1->x); + slope_dy = _cairo_fixed_to_double (p2->y - p1->y); + + if (stroker->ctm_inverse) + cairo_matrix_transform_distance (stroker->ctm_inverse, &slope_dx, &slope_dy); + mag = normalize_slope (&slope_dx, &slope_dy); + if (mag <= DBL_EPSILON) + return CAIRO_STATUS_SUCCESS; + + remain = mag; + segment.p1 = *p1; + while (remain) { + step_length = MIN (stroker->dash.dash_remain, remain); + remain -= step_length; + dx2 = slope_dx * (mag - remain); + dy2 = slope_dy * (mag - remain); + cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); + segment.p2.x = _cairo_fixed_from_double (dx2) + p1->x; + segment.p2.y = _cairo_fixed_from_double (dy2) + p1->y; + + if (stroker->dash.dash_on && + (fully_in_bounds || + (! stroker->has_first_face && stroker->dash.dash_starts_on) || + _cairo_box_intersects_line_segment (&stroker->join_bounds, &segment))) + { + add_sub_edge (stroker, + &segment.p1, &segment.p2, + &dev_slope, + &sub_start, &sub_end); + + if (stroker->has_current_face) { + /* Join with final face from previous segment */ + join (stroker, &stroker->current_face, &sub_start); + + stroker->has_current_face = FALSE; + } else if (! stroker->has_first_face && stroker->dash.dash_starts_on) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = sub_start; + stroker->has_first_face = TRUE; + } else { + /* Cap dash start if not connecting to a previous segment */ + add_leading_cap (stroker, &sub_start); + } + + if (remain) { + /* Cap dash end if not at end of segment */ + add_trailing_cap (stroker, &sub_end); + } else { + stroker->current_face = sub_end; + stroker->has_current_face = TRUE; + } + } else { + if (stroker->has_current_face) { + /* Cap final face from previous segment */ + add_trailing_cap (stroker, &stroker->current_face); + + stroker->has_current_face = FALSE; + } + } + + _cairo_stroker_dash_step (&stroker->dash, step_length); + segment.p1 = segment.p2; + } + + if (stroker->dash.dash_on && ! stroker->has_current_face) { + /* This segment ends on a transition to dash_on, compute a new face + * and add cap for the beginning of the next dash_on step. + * + * Note: this will create a degenerate cap if this is not the last line + * in the path. Whether this behaviour is desirable or not is debatable. + * On one side these degenerate caps can not be reproduced with regular + * path stroking. + * On the other hand, Acroread 7 also produces the degenerate caps. + */ + compute_face (point, &dev_slope, stroker, &stroker->current_face); + + add_leading_cap (stroker, &stroker->current_face); + + stroker->has_current_face = TRUE; + } else + stroker->current_face.point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +spline_to (void *closure, + const cairo_point_t *point, + const cairo_slope_t *tangent) +{ + struct stroker *stroker = closure; + cairo_stroke_face_t face; + + if ((tangent->dx | tangent->dy) == 0) { + cairo_point_t t; + + face = stroker->current_face; + + face.usr_vector.x = -face.usr_vector.x; + face.usr_vector.y = -face.usr_vector.y; + face.dev_slope.x = -face.dev_slope.x; + face.dev_slope.y = -face.dev_slope.y; + face.dev_vector.dx = -face.dev_vector.dx; + face.dev_vector.dy = -face.dev_vector.dy; + + t = face.cw; + face.cw = face.ccw; + face.ccw = t; + + join (stroker, &stroker->current_face, &face); + } else { + cairo_point_t rectangle[4]; + + compute_face (&stroker->current_face.point, tangent, stroker, &face); + join (stroker, &stroker->current_face, &face); + + rectangle[0] = face.cw; + rectangle[1] = face.ccw; + + rectangle[2].x = point->x - face.point.x; + rectangle[2].y = point->y - face.point.y; + face.point = *point; + translate_point (&face.ccw, &rectangle[2]); + translate_point (&face.cw, &rectangle[2]); + + rectangle[2] = face.ccw; + rectangle[3] = face.cw; + + _cairo_traps_tessellate_convex_quad (stroker->traps, rectangle); + } + + stroker->current_face = face; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + struct stroker *stroker = closure; + cairo_line_join_t line_join_save; + cairo_spline_t spline; + cairo_stroke_face_t face; + cairo_status_t status; + + if (stroker->has_bounds && + ! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, + &stroker->line_bounds)) + return line_to (closure, d); + + if (! _cairo_spline_init (&spline, spline_to, stroker, + &stroker->current_face.point, b, c, d)) + return line_to (closure, d); + + compute_face (&stroker->current_face.point, &spline.initial_slope, + stroker, &face); + + if (stroker->has_current_face) { + /* Join with final face from previous segment */ + join (stroker, &stroker->current_face, &face); + } else { + if (! stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = face; + stroker->has_first_face = TRUE; + } + stroker->has_current_face = TRUE; + } + stroker->current_face = face; + + /* Temporarily modify the stroker to use round joins to guarantee + * smooth stroked curves. */ + line_join_save = stroker->line_join; + stroker->line_join = CAIRO_LINE_JOIN_ROUND; + + status = _cairo_spline_decompose (&spline, stroker->tolerance); + + stroker->line_join = line_join_save; + + return status; +} + +static cairo_status_t +curve_to_dashed (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + struct stroker *stroker = closure; + cairo_spline_t spline; + cairo_line_join_t line_join_save; + cairo_spline_add_point_func_t func; + cairo_status_t status; + + func = (cairo_spline_add_point_func_t)line_to_dashed; + + if (stroker->has_bounds && + ! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, + &stroker->line_bounds)) + return func (closure, d, NULL); + + if (! _cairo_spline_init (&spline, func, stroker, + &stroker->current_face.point, b, c, d)) + return func (closure, d, NULL); + + /* Temporarily modify the stroker to use round joins to guarantee + * smooth stroked curves. */ + line_join_save = stroker->line_join; + stroker->line_join = CAIRO_LINE_JOIN_ROUND; + + status = _cairo_spline_decompose (&spline, stroker->tolerance); + + stroker->line_join = line_join_save; + + return status; +} + +static cairo_status_t +_close_path (struct stroker *stroker) +{ + if (stroker->has_first_face && stroker->has_current_face) { + /* Join first and final faces of sub path */ + join (stroker, &stroker->current_face, &stroker->first_face); + } else { + /* Cap the start and end of the sub path as needed */ + add_caps (stroker); + } + + stroker->has_initial_sub_path = FALSE; + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +close_path (void *closure) +{ + struct stroker *stroker = closure; + cairo_status_t status; + + status = line_to (stroker, &stroker->first_point); + if (unlikely (status)) + return status; + + return _close_path (stroker); +} + +static cairo_status_t +close_path_dashed (void *closure) +{ + struct stroker *stroker = closure; + cairo_status_t status; + + status = line_to_dashed (stroker, &stroker->first_point); + if (unlikely (status)) + return status; + + return _close_path (stroker); +} + +cairo_int_status_t +_cairo_path_fixed_stroke_to_traps (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_traps_t *traps) +{ + struct stroker stroker; + cairo_status_t status; + + status = stroker_init (&stroker, path, style, + ctm, ctm_inverse, tolerance, + traps); + if (unlikely (status)) + return status; + + if (stroker.dash.dashed) + status = _cairo_path_fixed_interpret (path, + move_to_dashed, + line_to_dashed, + curve_to_dashed, + close_path_dashed, + &stroker); + else + status = _cairo_path_fixed_interpret (path, + move_to, + line_to, + curve_to, + close_path, + &stroker); + assert(status == CAIRO_STATUS_SUCCESS); + add_caps (&stroker); + + stroker_fini (&stroker); + + return traps->status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-tristrip.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-tristrip.c new file mode 100644 index 00000000000..6ce4131cc0f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke-tristrip.c @@ -0,0 +1,1088 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#define _BSD_SOURCE /* for hypot() */ +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-slope-private.h" +#include "cairo-tristrip-private.h" + +struct stroker { + cairo_stroke_style_t style; + + cairo_tristrip_t *strip; + + const cairo_matrix_t *ctm; + const cairo_matrix_t *ctm_inverse; + double tolerance; + cairo_bool_t ctm_det_positive; + + cairo_pen_t pen; + + cairo_bool_t has_sub_path; + + cairo_point_t first_point; + + cairo_bool_t has_current_face; + cairo_stroke_face_t current_face; + + cairo_bool_t has_first_face; + cairo_stroke_face_t first_face; + + cairo_box_t limit; + cairo_bool_t has_limits; +}; + +static inline double +normalize_slope (double *dx, double *dy); + +static void +compute_face (const cairo_point_t *point, + const cairo_slope_t *dev_slope, + struct stroker *stroker, + cairo_stroke_face_t *face); + +static void +translate_point (cairo_point_t *point, const cairo_point_t *offset) +{ + point->x += offset->x; + point->y += offset->y; +} + +static int +slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) +{ + double c = (dx1 * dy2 - dx2 * dy1); + + if (c > 0) return 1; + if (c < 0) return -1; + return 0; +} + +static inline int +range_step (int i, int step, int max) +{ + i += step; + if (i < 0) + i = max - 1; + if (i >= max) + i = 0; + return i; +} + +/* + * Construct a fan around the midpoint using the vertices from pen between + * inpt and outpt. + */ +static void +add_fan (struct stroker *stroker, + const cairo_slope_t *in_vector, + const cairo_slope_t *out_vector, + const cairo_point_t *midpt, + const cairo_point_t *inpt, + const cairo_point_t *outpt, + cairo_bool_t clockwise) +{ + int start, stop, step, i, npoints; + + if (clockwise) { + step = 1; + + start = _cairo_pen_find_active_cw_vertex_index (&stroker->pen, + in_vector); + if (_cairo_slope_compare (&stroker->pen.vertices[start].slope_cw, + in_vector) < 0) + start = range_step (start, 1, stroker->pen.num_vertices); + + stop = _cairo_pen_find_active_cw_vertex_index (&stroker->pen, + out_vector); + if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_ccw, + out_vector) > 0) + { + stop = range_step (stop, -1, stroker->pen.num_vertices); + if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_cw, + in_vector) < 0) + return; + } + + npoints = stop - start; + } else { + step = -1; + + start = _cairo_pen_find_active_ccw_vertex_index (&stroker->pen, + in_vector); + if (_cairo_slope_compare (&stroker->pen.vertices[start].slope_ccw, + in_vector) < 0) + start = range_step (start, -1, stroker->pen.num_vertices); + + stop = _cairo_pen_find_active_ccw_vertex_index (&stroker->pen, + out_vector); + if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_cw, + out_vector) > 0) + { + stop = range_step (stop, 1, stroker->pen.num_vertices); + if (_cairo_slope_compare (&stroker->pen.vertices[stop].slope_ccw, + in_vector) < 0) + return; + } + + npoints = start - stop; + } + stop = range_step (stop, step, stroker->pen.num_vertices); + if (npoints < 0) + npoints += stroker->pen.num_vertices; + if (npoints <= 1) + return; + + for (i = start; + i != stop; + i = range_step (i, step, stroker->pen.num_vertices)) + { + cairo_point_t p = *midpt; + translate_point (&p, &stroker->pen.vertices[i].point); + //contour_add_point (stroker, c, &p); + } +} + +static int +join_is_clockwise (const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + return _cairo_slope_compare (&in->dev_vector, &out->dev_vector) < 0; +} + +static void +inner_join (struct stroker *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out, + int clockwise) +{ + const cairo_point_t *outpt; + + if (clockwise) { + outpt = &out->ccw; + } else { + outpt = &out->cw; + } + //contour_add_point (stroker, inner, &in->point); + //contour_add_point (stroker, inner, outpt); +} + +static void +inner_close (struct stroker *stroker, + const cairo_stroke_face_t *in, + cairo_stroke_face_t *out) +{ + const cairo_point_t *inpt; + + if (join_is_clockwise (in, out)) { + inpt = &out->ccw; + } else { + inpt = &out->cw; + } + + //contour_add_point (stroker, inner, &in->point); + //contour_add_point (stroker, inner, inpt); + //*_cairo_contour_first_point (&inner->contour) = + //*_cairo_contour_last_point (&inner->contour); +} + +static void +outer_close (struct stroker *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + const cairo_point_t *inpt, *outpt; + int clockwise; + + if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && + in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) + { + return; + } + clockwise = join_is_clockwise (in, out); + if (clockwise) { + inpt = &in->cw; + outpt = &out->cw; + } else { + inpt = &in->ccw; + outpt = &out->ccw; + } + + switch (stroker->style.line_join) { + case CAIRO_LINE_JOIN_ROUND: + /* construct a fan around the common midpoint */ + add_fan (stroker, + &in->dev_vector, + &out->dev_vector, + &in->point, inpt, outpt, + clockwise); + break; + + case CAIRO_LINE_JOIN_MITER: + default: { + /* dot product of incoming slope vector with outgoing slope vector */ + double in_dot_out = -in->usr_vector.x * out->usr_vector.x + + -in->usr_vector.y * out->usr_vector.y; + double ml = stroker->style.miter_limit; + + /* Check the miter limit -- lines meeting at an acute angle + * can generate long miters, the limit converts them to bevel + * + * Consider the miter join formed when two line segments + * meet at an angle psi: + * + * /.\ + * /. .\ + * /./ \.\ + * /./psi\.\ + * + * We can zoom in on the right half of that to see: + * + * |\ + * | \ psi/2 + * | \ + * | \ + * | \ + * | \ + * miter \ + * length \ + * | \ + * | .\ + * | . \ + * |. line \ + * \ width \ + * \ \ + * + * + * The right triangle in that figure, (the line-width side is + * shown faintly with three '.' characters), gives us the + * following expression relating miter length, angle and line + * width: + * + * 1 /sin (psi/2) = miter_length / line_width + * + * The right-hand side of this relationship is the same ratio + * in which the miter limit (ml) is expressed. We want to know + * when the miter length is within the miter limit. That is + * when the following condition holds: + * + * 1/sin(psi/2) <= ml + * 1 <= ml sin(psi/2) + * 1 <= ml² sin²(psi/2) + * 2 <= ml² 2 sin²(psi/2) + * 2·sin²(psi/2) = 1-cos(psi) + * 2 <= ml² (1-cos(psi)) + * + * in · out = |in| |out| cos (psi) + * + * in and out are both unit vectors, so: + * + * in · out = cos (psi) + * + * 2 <= ml² (1 - in · out) + * + */ + if (2 <= ml * ml * (1 - in_dot_out)) { + double x1, y1, x2, y2; + double mx, my; + double dx1, dx2, dy1, dy2; + double ix, iy; + double fdx1, fdy1, fdx2, fdy2; + double mdx, mdy; + + /* + * we've got the points already transformed to device + * space, but need to do some computation with them and + * also need to transform the slope from user space to + * device space + */ + /* outer point of incoming line face */ + x1 = _cairo_fixed_to_double (inpt->x); + y1 = _cairo_fixed_to_double (inpt->y); + dx1 = in->usr_vector.x; + dy1 = in->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); + + /* outer point of outgoing line face */ + x2 = _cairo_fixed_to_double (outpt->x); + y2 = _cairo_fixed_to_double (outpt->y); + dx2 = out->usr_vector.x; + dy2 = out->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); + + /* + * Compute the location of the outer corner of the miter. + * That's pretty easy -- just the intersection of the two + * outer edges. We've got slopes and points on each + * of those edges. Compute my directly, then compute + * mx by using the edge with the larger dy; that avoids + * dividing by values close to zero. + */ + my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / + (dx1 * dy2 - dx2 * dy1)); + if (fabs (dy1) >= fabs (dy2)) + mx = (my - y1) * dx1 / dy1 + x1; + else + mx = (my - y2) * dx2 / dy2 + x2; + + /* + * When the two outer edges are nearly parallel, slight + * perturbations in the position of the outer points of the lines + * caused by representing them in fixed point form can cause the + * intersection point of the miter to move a large amount. If + * that moves the miter intersection from between the two faces, + * then draw a bevel instead. + */ + + ix = _cairo_fixed_to_double (in->point.x); + iy = _cairo_fixed_to_double (in->point.y); + + /* slope of one face */ + fdx1 = x1 - ix; fdy1 = y1 - iy; + + /* slope of the other face */ + fdx2 = x2 - ix; fdy2 = y2 - iy; + + /* slope from the intersection to the miter point */ + mdx = mx - ix; mdy = my - iy; + + /* + * Make sure the miter point line lies between the two + * faces by comparing the slopes + */ + if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != + slope_compare_sgn (fdx2, fdy2, mdx, mdy)) + { + cairo_point_t p; + + p.x = _cairo_fixed_from_double (mx); + p.y = _cairo_fixed_from_double (my); + + //*_cairo_contour_last_point (&outer->contour) = p; + //*_cairo_contour_first_point (&outer->contour) = p; + return; + } + } + break; + } + + case CAIRO_LINE_JOIN_BEVEL: + break; + } + //contour_add_point (stroker, outer, outpt); +} + +static void +outer_join (struct stroker *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out, + int clockwise) +{ + const cairo_point_t *inpt, *outpt; + + if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && + in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) + { + return; + } + if (clockwise) { + inpt = &in->cw; + outpt = &out->cw; + } else { + inpt = &in->ccw; + outpt = &out->ccw; + } + + switch (stroker->style.line_join) { + case CAIRO_LINE_JOIN_ROUND: + /* construct a fan around the common midpoint */ + add_fan (stroker, + &in->dev_vector, + &out->dev_vector, + &in->point, inpt, outpt, + clockwise); + break; + + case CAIRO_LINE_JOIN_MITER: + default: { + /* dot product of incoming slope vector with outgoing slope vector */ + double in_dot_out = -in->usr_vector.x * out->usr_vector.x + + -in->usr_vector.y * out->usr_vector.y; + double ml = stroker->style.miter_limit; + + /* Check the miter limit -- lines meeting at an acute angle + * can generate long miters, the limit converts them to bevel + * + * Consider the miter join formed when two line segments + * meet at an angle psi: + * + * /.\ + * /. .\ + * /./ \.\ + * /./psi\.\ + * + * We can zoom in on the right half of that to see: + * + * |\ + * | \ psi/2 + * | \ + * | \ + * | \ + * | \ + * miter \ + * length \ + * | \ + * | .\ + * | . \ + * |. line \ + * \ width \ + * \ \ + * + * + * The right triangle in that figure, (the line-width side is + * shown faintly with three '.' characters), gives us the + * following expression relating miter length, angle and line + * width: + * + * 1 /sin (psi/2) = miter_length / line_width + * + * The right-hand side of this relationship is the same ratio + * in which the miter limit (ml) is expressed. We want to know + * when the miter length is within the miter limit. That is + * when the following condition holds: + * + * 1/sin(psi/2) <= ml + * 1 <= ml sin(psi/2) + * 1 <= ml² sin²(psi/2) + * 2 <= ml² 2 sin²(psi/2) + * 2·sin²(psi/2) = 1-cos(psi) + * 2 <= ml² (1-cos(psi)) + * + * in · out = |in| |out| cos (psi) + * + * in and out are both unit vectors, so: + * + * in · out = cos (psi) + * + * 2 <= ml² (1 - in · out) + * + */ + if (2 <= ml * ml * (1 - in_dot_out)) { + double x1, y1, x2, y2; + double mx, my; + double dx1, dx2, dy1, dy2; + double ix, iy; + double fdx1, fdy1, fdx2, fdy2; + double mdx, mdy; + + /* + * we've got the points already transformed to device + * space, but need to do some computation with them and + * also need to transform the slope from user space to + * device space + */ + /* outer point of incoming line face */ + x1 = _cairo_fixed_to_double (inpt->x); + y1 = _cairo_fixed_to_double (inpt->y); + dx1 = in->usr_vector.x; + dy1 = in->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); + + /* outer point of outgoing line face */ + x2 = _cairo_fixed_to_double (outpt->x); + y2 = _cairo_fixed_to_double (outpt->y); + dx2 = out->usr_vector.x; + dy2 = out->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); + + /* + * Compute the location of the outer corner of the miter. + * That's pretty easy -- just the intersection of the two + * outer edges. We've got slopes and points on each + * of those edges. Compute my directly, then compute + * mx by using the edge with the larger dy; that avoids + * dividing by values close to zero. + */ + my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / + (dx1 * dy2 - dx2 * dy1)); + if (fabs (dy1) >= fabs (dy2)) + mx = (my - y1) * dx1 / dy1 + x1; + else + mx = (my - y2) * dx2 / dy2 + x2; + + /* + * When the two outer edges are nearly parallel, slight + * perturbations in the position of the outer points of the lines + * caused by representing them in fixed point form can cause the + * intersection point of the miter to move a large amount. If + * that moves the miter intersection from between the two faces, + * then draw a bevel instead. + */ + + ix = _cairo_fixed_to_double (in->point.x); + iy = _cairo_fixed_to_double (in->point.y); + + /* slope of one face */ + fdx1 = x1 - ix; fdy1 = y1 - iy; + + /* slope of the other face */ + fdx2 = x2 - ix; fdy2 = y2 - iy; + + /* slope from the intersection to the miter point */ + mdx = mx - ix; mdy = my - iy; + + /* + * Make sure the miter point line lies between the two + * faces by comparing the slopes + */ + if (slope_compare_sgn (fdx1, fdy1, mdx, mdy) != + slope_compare_sgn (fdx2, fdy2, mdx, mdy)) + { + cairo_point_t p; + + p.x = _cairo_fixed_from_double (mx); + p.y = _cairo_fixed_from_double (my); + + //*_cairo_contour_last_point (&outer->contour) = p; + return; + } + } + break; + } + + case CAIRO_LINE_JOIN_BEVEL: + break; + } + //contour_add_point (stroker,outer, outpt); +} + +static void +add_cap (struct stroker *stroker, + const cairo_stroke_face_t *f) +{ + switch (stroker->style.line_cap) { + case CAIRO_LINE_CAP_ROUND: { + cairo_slope_t slope; + + slope.dx = -f->dev_vector.dx; + slope.dy = -f->dev_vector.dy; + + add_fan (stroker, &f->dev_vector, &slope, + &f->point, &f->ccw, &f->cw, + FALSE); + break; + } + + case CAIRO_LINE_CAP_SQUARE: { + double dx, dy; + cairo_slope_t fvector; + cairo_point_t quad[4]; + + dx = f->usr_vector.x; + dy = f->usr_vector.y; + dx *= stroker->style.line_width / 2.0; + dy *= stroker->style.line_width / 2.0; + cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); + fvector.dx = _cairo_fixed_from_double (dx); + fvector.dy = _cairo_fixed_from_double (dy); + + quad[0] = f->ccw; + quad[1].x = f->ccw.x + fvector.dx; + quad[1].y = f->ccw.y + fvector.dy; + quad[2].x = f->cw.x + fvector.dx; + quad[2].y = f->cw.y + fvector.dy; + quad[3] = f->cw; + + //contour_add_point (stroker, c, &quad[1]); + //contour_add_point (stroker, c, &quad[2]); + } + + case CAIRO_LINE_CAP_BUTT: + default: + break; + } + //contour_add_point (stroker, c, &f->cw); +} + +static void +add_leading_cap (struct stroker *stroker, + const cairo_stroke_face_t *face) +{ + cairo_stroke_face_t reversed; + cairo_point_t t; + + reversed = *face; + + /* The initial cap needs an outward facing vector. Reverse everything */ + reversed.usr_vector.x = -reversed.usr_vector.x; + reversed.usr_vector.y = -reversed.usr_vector.y; + reversed.dev_vector.dx = -reversed.dev_vector.dx; + reversed.dev_vector.dy = -reversed.dev_vector.dy; + + t = reversed.cw; + reversed.cw = reversed.ccw; + reversed.ccw = t; + + add_cap (stroker, &reversed); +} + +static void +add_trailing_cap (struct stroker *stroker, + const cairo_stroke_face_t *face) +{ + add_cap (stroker, face); +} + +static inline double +normalize_slope (double *dx, double *dy) +{ + double dx0 = *dx, dy0 = *dy; + double mag; + + assert (dx0 != 0.0 || dy0 != 0.0); + + if (dx0 == 0.0) { + *dx = 0.0; + if (dy0 > 0.0) { + mag = dy0; + *dy = 1.0; + } else { + mag = -dy0; + *dy = -1.0; + } + } else if (dy0 == 0.0) { + *dy = 0.0; + if (dx0 > 0.0) { + mag = dx0; + *dx = 1.0; + } else { + mag = -dx0; + *dx = -1.0; + } + } else { + mag = hypot (dx0, dy0); + *dx = dx0 / mag; + *dy = dy0 / mag; + } + + return mag; +} + +static void +compute_face (const cairo_point_t *point, + const cairo_slope_t *dev_slope, + struct stroker *stroker, + cairo_stroke_face_t *face) +{ + double face_dx, face_dy; + cairo_point_t offset_ccw, offset_cw; + double slope_dx, slope_dy; + + slope_dx = _cairo_fixed_to_double (dev_slope->dx); + slope_dy = _cairo_fixed_to_double (dev_slope->dy); + face->length = normalize_slope (&slope_dx, &slope_dy); + face->dev_slope.x = slope_dx; + face->dev_slope.y = slope_dy; + + /* + * rotate to get a line_width/2 vector along the face, note that + * the vector must be rotated the right direction in device space, + * but by 90° in user space. So, the rotation depends on + * whether the ctm reflects or not, and that can be determined + * by looking at the determinant of the matrix. + */ + if (! _cairo_matrix_is_identity (stroker->ctm_inverse)) { + /* Normalize the matrix! */ + cairo_matrix_transform_distance (stroker->ctm_inverse, + &slope_dx, &slope_dy); + normalize_slope (&slope_dx, &slope_dy); + + if (stroker->ctm_det_positive) { + face_dx = - slope_dy * (stroker->style.line_width / 2.0); + face_dy = slope_dx * (stroker->style.line_width / 2.0); + } else { + face_dx = slope_dy * (stroker->style.line_width / 2.0); + face_dy = - slope_dx * (stroker->style.line_width / 2.0); + } + + /* back to device space */ + cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); + } else { + face_dx = - slope_dy * (stroker->style.line_width / 2.0); + face_dy = slope_dx * (stroker->style.line_width / 2.0); + } + + offset_ccw.x = _cairo_fixed_from_double (face_dx); + offset_ccw.y = _cairo_fixed_from_double (face_dy); + offset_cw.x = -offset_ccw.x; + offset_cw.y = -offset_ccw.y; + + face->ccw = *point; + translate_point (&face->ccw, &offset_ccw); + + face->point = *point; + + face->cw = *point; + translate_point (&face->cw, &offset_cw); + + face->usr_vector.x = slope_dx; + face->usr_vector.y = slope_dy; + + face->dev_vector = *dev_slope; +} + +static void +add_caps (struct stroker *stroker) +{ + /* check for a degenerative sub_path */ + if (stroker->has_sub_path && + ! stroker->has_first_face && + ! stroker->has_current_face && + stroker->style.line_cap == CAIRO_LINE_CAP_ROUND) + { + /* pick an arbitrary slope to use */ + cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; + cairo_stroke_face_t face; + + /* arbitrarily choose first_point */ + compute_face (&stroker->first_point, &slope, stroker, &face); + + add_leading_cap (stroker, &face); + add_trailing_cap (stroker, &face); + + /* ensure the circle is complete */ + //_cairo_contour_add_point (&stroker->ccw.contour, + //_cairo_contour_first_point (&stroker->ccw.contour)); + } else { + if (stroker->has_current_face) + add_trailing_cap (stroker, &stroker->current_face); + + //_cairo_polygon_add_contour (stroker->polygon, &stroker->ccw.contour); + //_cairo_contour_reset (&stroker->ccw.contour); + + if (stroker->has_first_face) { + //_cairo_contour_add_point (&stroker->ccw.contour, + //&stroker->first_face.cw); + add_leading_cap (stroker, &stroker->first_face); + //_cairo_polygon_add_contour (stroker->polygon, + //&stroker->ccw.contour); + //_cairo_contour_reset (&stroker->ccw.contour); + } + } +} + +static cairo_status_t +move_to (void *closure, + const cairo_point_t *point) +{ + struct stroker *stroker = closure; + + /* Cap the start and end of the previous sub path as needed */ + add_caps (stroker); + + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + stroker->has_sub_path = FALSE; + + stroker->first_point = *point; + + stroker->current_face.point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +line_to (void *closure, + const cairo_point_t *point) +{ + struct stroker *stroker = closure; + cairo_stroke_face_t start; + cairo_point_t *p1 = &stroker->current_face.point; + cairo_slope_t dev_slope; + + stroker->has_sub_path = TRUE; + + if (p1->x == point->x && p1->y == point->y) + return CAIRO_STATUS_SUCCESS; + + _cairo_slope_init (&dev_slope, p1, point); + compute_face (p1, &dev_slope, stroker, &start); + + if (stroker->has_current_face) { + int clockwise = join_is_clockwise (&stroker->current_face, &start); + /* Join with final face from previous segment */ + outer_join (stroker, &stroker->current_face, &start, clockwise); + inner_join (stroker, &stroker->current_face, &start, clockwise); + } else { + if (! stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = start; + _cairo_tristrip_move_to (stroker->strip, &start.cw); + stroker->has_first_face = TRUE; + } + stroker->has_current_face = TRUE; + + _cairo_tristrip_add_point (stroker->strip, &start.cw); + _cairo_tristrip_add_point (stroker->strip, &start.ccw); + } + + stroker->current_face = start; + stroker->current_face.point = *point; + stroker->current_face.ccw.x += dev_slope.dx; + stroker->current_face.ccw.y += dev_slope.dy; + stroker->current_face.cw.x += dev_slope.dx; + stroker->current_face.cw.y += dev_slope.dy; + + _cairo_tristrip_add_point (stroker->strip, &stroker->current_face.cw); + _cairo_tristrip_add_point (stroker->strip, &stroker->current_face.ccw); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +spline_to (void *closure, + const cairo_point_t *point, + const cairo_slope_t *tangent) +{ + struct stroker *stroker = closure; + cairo_stroke_face_t face; + + if (tangent->dx == 0 && tangent->dy == 0) { + const cairo_point_t *inpt, *outpt; + cairo_point_t t; + int clockwise; + + face = stroker->current_face; + + face.usr_vector.x = -face.usr_vector.x; + face.usr_vector.y = -face.usr_vector.y; + face.dev_vector.dx = -face.dev_vector.dx; + face.dev_vector.dy = -face.dev_vector.dy; + + t = face.cw; + face.cw = face.ccw; + face.ccw = t; + + clockwise = join_is_clockwise (&stroker->current_face, &face); + if (clockwise) { + inpt = &stroker->current_face.cw; + outpt = &face.cw; + } else { + inpt = &stroker->current_face.ccw; + outpt = &face.ccw; + } + + add_fan (stroker, + &stroker->current_face.dev_vector, + &face.dev_vector, + &stroker->current_face.point, inpt, outpt, + clockwise); + } else { + compute_face (point, tangent, stroker, &face); + + if (face.dev_slope.x * stroker->current_face.dev_slope.x + + face.dev_slope.y * stroker->current_face.dev_slope.y < 0) + { + const cairo_point_t *inpt, *outpt; + int clockwise = join_is_clockwise (&stroker->current_face, &face); + + stroker->current_face.cw.x += face.point.x - stroker->current_face.point.x; + stroker->current_face.cw.y += face.point.y - stroker->current_face.point.y; + //contour_add_point (stroker, &stroker->cw, &stroker->current_face.cw); + + stroker->current_face.ccw.x += face.point.x - stroker->current_face.point.x; + stroker->current_face.ccw.y += face.point.y - stroker->current_face.point.y; + //contour_add_point (stroker, &stroker->ccw, &stroker->current_face.ccw); + + if (clockwise) { + inpt = &stroker->current_face.cw; + outpt = &face.cw; + } else { + inpt = &stroker->current_face.ccw; + outpt = &face.ccw; + } + add_fan (stroker, + &stroker->current_face.dev_vector, + &face.dev_vector, + &stroker->current_face.point, inpt, outpt, + clockwise); + } + + _cairo_tristrip_add_point (stroker->strip, &face.cw); + _cairo_tristrip_add_point (stroker->strip, &face.ccw); + } + + stroker->current_face = face; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + struct stroker *stroker = closure; + cairo_spline_t spline; + cairo_stroke_face_t face; + + if (stroker->has_limits) { + if (! _cairo_spline_intersects (&stroker->current_face.point, b, c, d, + &stroker->limit)) + return line_to (closure, d); + } + + if (! _cairo_spline_init (&spline, spline_to, stroker, + &stroker->current_face.point, b, c, d)) + return line_to (closure, d); + + compute_face (&stroker->current_face.point, &spline.initial_slope, + stroker, &face); + + if (stroker->has_current_face) { + int clockwise = join_is_clockwise (&stroker->current_face, &face); + /* Join with final face from previous segment */ + outer_join (stroker, &stroker->current_face, &face, clockwise); + inner_join (stroker, &stroker->current_face, &face, clockwise); + } else { + if (! stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = face; + _cairo_tristrip_move_to (stroker->strip, &face.cw); + stroker->has_first_face = TRUE; + } + stroker->has_current_face = TRUE; + + _cairo_tristrip_add_point (stroker->strip, &face.cw); + _cairo_tristrip_add_point (stroker->strip, &face.ccw); + } + stroker->current_face = face; + + return _cairo_spline_decompose (&spline, stroker->tolerance); +} + +static cairo_status_t +close_path (void *closure) +{ + struct stroker *stroker = closure; + cairo_status_t status; + + status = line_to (stroker, &stroker->first_point); + if (unlikely (status)) + return status; + + if (stroker->has_first_face && stroker->has_current_face) { + /* Join first and final faces of sub path */ + outer_close (stroker, &stroker->current_face, &stroker->first_face); + inner_close (stroker, &stroker->current_face, &stroker->first_face); + } else { + /* Cap the start and end of the sub path as needed */ + add_caps (stroker); + } + + stroker->has_sub_path = FALSE; + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_path_fixed_stroke_to_tristrip (const cairo_path_fixed_t *path, + const cairo_stroke_style_t*style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_tristrip_t *strip) +{ + struct stroker stroker; + cairo_int_status_t status; + int i; + + if (style->num_dashes) + return CAIRO_INT_STATUS_UNSUPPORTED; + + stroker.style = *style; + stroker.ctm = ctm; + stroker.ctm_inverse = ctm_inverse; + stroker.tolerance = tolerance; + + stroker.ctm_det_positive = + _cairo_matrix_compute_determinant (ctm) >= 0.0; + + status = _cairo_pen_init (&stroker.pen, + style->line_width / 2.0, + tolerance, ctm); + if (unlikely (status)) + return status; + + if (stroker.pen.num_vertices <= 1) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + stroker.has_current_face = FALSE; + stroker.has_first_face = FALSE; + stroker.has_sub_path = FALSE; + + stroker.has_limits = strip->num_limits > 0; + stroker.limit = strip->limits[0]; + for (i = 1; i < strip->num_limits; i++) + _cairo_box_add_box (&stroker.limit, &strip->limits[i]); + + stroker.strip = strip; + + status = _cairo_path_fixed_interpret (path, + move_to, + line_to, + curve_to, + close_path, + &stroker); + /* Cap the start and end of the final sub path as needed */ + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + add_caps (&stroker); + + _cairo_pen_fini (&stroker.pen); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke.c b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke.c new file mode 100644 index 00000000000..4d4ede81361 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path-stroke.c @@ -0,0 +1,1485 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#define _BSD_SOURCE /* for hypot() */ +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-slope-private.h" +#include "cairo-stroke-dash-private.h" +#include "cairo-traps-private.h" + +typedef struct cairo_stroker { + cairo_stroke_style_t style; + + const cairo_matrix_t *ctm; + const cairo_matrix_t *ctm_inverse; + double half_line_width; + double tolerance; + double spline_cusp_tolerance; + double ctm_determinant; + cairo_bool_t ctm_det_positive; + + void *closure; + cairo_status_t (*add_external_edge) (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2); + cairo_status_t (*add_triangle) (void *closure, + const cairo_point_t triangle[3]); + cairo_status_t (*add_triangle_fan) (void *closure, + const cairo_point_t *midpt, + const cairo_point_t *points, + int npoints); + cairo_status_t (*add_convex_quad) (void *closure, + const cairo_point_t quad[4]); + + cairo_pen_t pen; + + cairo_point_t current_point; + cairo_point_t first_point; + + cairo_bool_t has_initial_sub_path; + + cairo_bool_t has_current_face; + cairo_stroke_face_t current_face; + + cairo_bool_t has_first_face; + cairo_stroke_face_t first_face; + + cairo_stroker_dash_t dash; + + cairo_bool_t has_bounds; + cairo_box_t bounds; +} cairo_stroker_t; + +static void +_cairo_stroker_limit (cairo_stroker_t *stroker, + const cairo_path_fixed_t *path, + const cairo_box_t *boxes, + int num_boxes) +{ + double dx, dy; + cairo_fixed_t fdx, fdy; + + stroker->has_bounds = TRUE; + _cairo_boxes_get_extents (boxes, num_boxes, &stroker->bounds); + + /* Extend the bounds in each direction to account for the maximum area + * we might generate trapezoids, to capture line segments that are outside + * of the bounds but which might generate rendering that's within bounds. + */ + + _cairo_stroke_style_max_distance_from_path (&stroker->style, path, + stroker->ctm, &dx, &dy); + + fdx = _cairo_fixed_from_double (dx); + fdy = _cairo_fixed_from_double (dy); + + stroker->bounds.p1.x -= fdx; + stroker->bounds.p2.x += fdx; + + stroker->bounds.p1.y -= fdy; + stroker->bounds.p2.y += fdy; +} + +static cairo_status_t +_cairo_stroker_init (cairo_stroker_t *stroker, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + const cairo_box_t *limits, + int num_limits) +{ + cairo_status_t status; + + stroker->style = *stroke_style; + stroker->ctm = ctm; + stroker->ctm_inverse = ctm_inverse; + stroker->tolerance = tolerance; + stroker->half_line_width = stroke_style->line_width / 2.0; + + /* To test whether we need to join two segments of a spline using + * a round-join or a bevel-join, we can inspect the angle between the + * two segments. If the difference between the chord distance + * (half-line-width times the cosine of the bisection angle) and the + * half-line-width itself is greater than tolerance then we need to + * inject a point. + */ + stroker->spline_cusp_tolerance = 1 - tolerance / stroker->half_line_width; + stroker->spline_cusp_tolerance *= stroker->spline_cusp_tolerance; + stroker->spline_cusp_tolerance *= 2; + stroker->spline_cusp_tolerance -= 1; + + stroker->ctm_determinant = _cairo_matrix_compute_determinant (stroker->ctm); + stroker->ctm_det_positive = stroker->ctm_determinant >= 0.0; + + status = _cairo_pen_init (&stroker->pen, + stroker->half_line_width, tolerance, ctm); + if (unlikely (status)) + return status; + + stroker->has_current_face = FALSE; + stroker->has_first_face = FALSE; + stroker->has_initial_sub_path = FALSE; + + _cairo_stroker_dash_init (&stroker->dash, stroke_style); + + stroker->add_external_edge = NULL; + + stroker->has_bounds = FALSE; + if (num_limits) + _cairo_stroker_limit (stroker, path, limits, num_limits); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_stroker_fini (cairo_stroker_t *stroker) +{ + _cairo_pen_fini (&stroker->pen); +} + +static void +_translate_point (cairo_point_t *point, const cairo_point_t *offset) +{ + point->x += offset->x; + point->y += offset->y; +} + +static int +_cairo_stroker_join_is_clockwise (const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + cairo_slope_t in_slope, out_slope; + + _cairo_slope_init (&in_slope, &in->point, &in->cw); + _cairo_slope_init (&out_slope, &out->point, &out->cw); + + return _cairo_slope_compare (&in_slope, &out_slope) < 0; +} + +/** + * _cairo_slope_compare_sgn: + * + * Return -1, 0 or 1 depending on the relative slopes of + * two lines. + **/ +static int +_cairo_slope_compare_sgn (double dx1, double dy1, double dx2, double dy2) +{ + double c = (dx1 * dy2 - dx2 * dy1); + + if (c > 0) return 1; + if (c < 0) return -1; + return 0; +} + +static inline int +_range_step (int i, int step, int max) +{ + i += step; + if (i < 0) + i = max - 1; + if (i >= max) + i = 0; + return i; +} + +/* + * Construct a fan around the midpoint using the vertices from pen between + * inpt and outpt. + */ +static cairo_status_t +_tessellate_fan (cairo_stroker_t *stroker, + const cairo_slope_t *in_vector, + const cairo_slope_t *out_vector, + const cairo_point_t *midpt, + const cairo_point_t *inpt, + const cairo_point_t *outpt, + cairo_bool_t clockwise) +{ + cairo_point_t stack_points[64], *points = stack_points; + cairo_pen_t *pen = &stroker->pen; + int start, stop, num_points = 0; + cairo_status_t status; + + if (stroker->has_bounds && + ! _cairo_box_contains_point (&stroker->bounds, midpt)) + goto BEVEL; + + assert (stroker->pen.num_vertices); + + if (clockwise) { + _cairo_pen_find_active_ccw_vertices (pen, + in_vector, out_vector, + &start, &stop); + if (stroker->add_external_edge) { + cairo_point_t last; + last = *inpt; + while (start != stop) { + cairo_point_t p = *midpt; + _translate_point (&p, &pen->vertices[start].point); + + status = stroker->add_external_edge (stroker->closure, + &last, &p); + if (unlikely (status)) + return status; + last = p; + + if (start-- == 0) + start += pen->num_vertices; + } + status = stroker->add_external_edge (stroker->closure, + &last, outpt); + } else { + if (start == stop) + goto BEVEL; + + num_points = stop - start; + if (num_points < 0) + num_points += pen->num_vertices; + num_points += 2; + if (num_points > ARRAY_LENGTH(stack_points)) { + points = _cairo_malloc_ab (num_points, sizeof (cairo_point_t)); + if (unlikely (points == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + points[0] = *inpt; + num_points = 1; + while (start != stop) { + points[num_points] = *midpt; + _translate_point (&points[num_points], &pen->vertices[start].point); + num_points++; + + if (start-- == 0) + start += pen->num_vertices; + } + points[num_points++] = *outpt; + } + } else { + _cairo_pen_find_active_cw_vertices (pen, + in_vector, out_vector, + &start, &stop); + if (stroker->add_external_edge) { + cairo_point_t last; + last = *inpt; + while (start != stop) { + cairo_point_t p = *midpt; + _translate_point (&p, &pen->vertices[start].point); + + status = stroker->add_external_edge (stroker->closure, + &p, &last); + if (unlikely (status)) + return status; + last = p; + + if (++start == pen->num_vertices) + start = 0; + } + status = stroker->add_external_edge (stroker->closure, + outpt, &last); + } else { + if (start == stop) + goto BEVEL; + + num_points = stop - start; + if (num_points < 0) + num_points += pen->num_vertices; + num_points += 2; + if (num_points > ARRAY_LENGTH(stack_points)) { + points = _cairo_malloc_ab (num_points, sizeof (cairo_point_t)); + if (unlikely (points == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + points[0] = *inpt; + num_points = 1; + while (start != stop) { + points[num_points] = *midpt; + _translate_point (&points[num_points], &pen->vertices[start].point); + num_points++; + + if (++start == pen->num_vertices) + start = 0; + } + points[num_points++] = *outpt; + } + } + + if (num_points) { + status = stroker->add_triangle_fan (stroker->closure, + midpt, points, num_points); + } + + if (points != stack_points) + free (points); + + return status; + +BEVEL: + /* Ensure a leak free connection... */ + if (stroker->add_external_edge != NULL) { + if (clockwise) + return stroker->add_external_edge (stroker->closure, inpt, outpt); + else + return stroker->add_external_edge (stroker->closure, outpt, inpt); + } else { + stack_points[0] = *midpt; + stack_points[1] = *inpt; + stack_points[2] = *outpt; + return stroker->add_triangle (stroker->closure, stack_points); + } +} + +static cairo_status_t +_cairo_stroker_join (cairo_stroker_t *stroker, + const cairo_stroke_face_t *in, + const cairo_stroke_face_t *out) +{ + int clockwise = _cairo_stroker_join_is_clockwise (out, in); + const cairo_point_t *inpt, *outpt; + cairo_point_t points[4]; + cairo_status_t status; + + if (in->cw.x == out->cw.x && in->cw.y == out->cw.y && + in->ccw.x == out->ccw.x && in->ccw.y == out->ccw.y) + { + return CAIRO_STATUS_SUCCESS; + } + + if (clockwise) { + if (stroker->add_external_edge != NULL) { + status = stroker->add_external_edge (stroker->closure, + &out->cw, &in->point); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &in->point, &in->cw); + if (unlikely (status)) + return status; + } + + inpt = &in->ccw; + outpt = &out->ccw; + } else { + if (stroker->add_external_edge != NULL) { + status = stroker->add_external_edge (stroker->closure, + &in->ccw, &in->point); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &in->point, &out->ccw); + if (unlikely (status)) + return status; + } + + inpt = &in->cw; + outpt = &out->cw; + } + + switch (stroker->style.line_join) { + case CAIRO_LINE_JOIN_ROUND: + /* construct a fan around the common midpoint */ + return _tessellate_fan (stroker, + &in->dev_vector, + &out->dev_vector, + &in->point, inpt, outpt, + clockwise); + + case CAIRO_LINE_JOIN_MITER: + default: { + /* dot product of incoming slope vector with outgoing slope vector */ + double in_dot_out = -in->usr_vector.x * out->usr_vector.x + + -in->usr_vector.y * out->usr_vector.y; + double ml = stroker->style.miter_limit; + + /* Check the miter limit -- lines meeting at an acute angle + * can generate long miters, the limit converts them to bevel + * + * Consider the miter join formed when two line segments + * meet at an angle psi: + * + * /.\ + * /. .\ + * /./ \.\ + * /./psi\.\ + * + * We can zoom in on the right half of that to see: + * + * |\ + * | \ psi/2 + * | \ + * | \ + * | \ + * | \ + * miter \ + * length \ + * | \ + * | .\ + * | . \ + * |. line \ + * \ width \ + * \ \ + * + * + * The right triangle in that figure, (the line-width side is + * shown faintly with three '.' characters), gives us the + * following expression relating miter length, angle and line + * width: + * + * 1 /sin (psi/2) = miter_length / line_width + * + * The right-hand side of this relationship is the same ratio + * in which the miter limit (ml) is expressed. We want to know + * when the miter length is within the miter limit. That is + * when the following condition holds: + * + * 1/sin(psi/2) <= ml + * 1 <= ml sin(psi/2) + * 1 <= ml² sin²(psi/2) + * 2 <= ml² 2 sin²(psi/2) + * 2·sin²(psi/2) = 1-cos(psi) + * 2 <= ml² (1-cos(psi)) + * + * in · out = |in| |out| cos (psi) + * + * in and out are both unit vectors, so: + * + * in · out = cos (psi) + * + * 2 <= ml² (1 - in · out) + * + */ + if (2 <= ml * ml * (1 - in_dot_out)) { + double x1, y1, x2, y2; + double mx, my; + double dx1, dx2, dy1, dy2; + double ix, iy; + double fdx1, fdy1, fdx2, fdy2; + double mdx, mdy; + + /* + * we've got the points already transformed to device + * space, but need to do some computation with them and + * also need to transform the slope from user space to + * device space + */ + /* outer point of incoming line face */ + x1 = _cairo_fixed_to_double (inpt->x); + y1 = _cairo_fixed_to_double (inpt->y); + dx1 = in->usr_vector.x; + dy1 = in->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx1, &dy1); + + /* outer point of outgoing line face */ + x2 = _cairo_fixed_to_double (outpt->x); + y2 = _cairo_fixed_to_double (outpt->y); + dx2 = out->usr_vector.x; + dy2 = out->usr_vector.y; + cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); + + /* + * Compute the location of the outer corner of the miter. + * That's pretty easy -- just the intersection of the two + * outer edges. We've got slopes and points on each + * of those edges. Compute my directly, then compute + * mx by using the edge with the larger dy; that avoids + * dividing by values close to zero. + */ + my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) / + (dx1 * dy2 - dx2 * dy1)); + if (fabs (dy1) >= fabs (dy2)) + mx = (my - y1) * dx1 / dy1 + x1; + else + mx = (my - y2) * dx2 / dy2 + x2; + + /* + * When the two outer edges are nearly parallel, slight + * perturbations in the position of the outer points of the lines + * caused by representing them in fixed point form can cause the + * intersection point of the miter to move a large amount. If + * that moves the miter intersection from between the two faces, + * then draw a bevel instead. + */ + + ix = _cairo_fixed_to_double (in->point.x); + iy = _cairo_fixed_to_double (in->point.y); + + /* slope of one face */ + fdx1 = x1 - ix; fdy1 = y1 - iy; + + /* slope of the other face */ + fdx2 = x2 - ix; fdy2 = y2 - iy; + + /* slope from the intersection to the miter point */ + mdx = mx - ix; mdy = my - iy; + + /* + * Make sure the miter point line lies between the two + * faces by comparing the slopes + */ + if (_cairo_slope_compare_sgn (fdx1, fdy1, mdx, mdy) != + _cairo_slope_compare_sgn (fdx2, fdy2, mdx, mdy)) + { + if (stroker->add_external_edge != NULL) { + points[0].x = _cairo_fixed_from_double (mx); + points[0].y = _cairo_fixed_from_double (my); + + if (clockwise) { + status = stroker->add_external_edge (stroker->closure, + inpt, &points[0]); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &points[0], outpt); + if (unlikely (status)) + return status; + } else { + status = stroker->add_external_edge (stroker->closure, + outpt, &points[0]); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &points[0], inpt); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; + } else { + points[0] = in->point; + points[1] = *inpt; + points[2].x = _cairo_fixed_from_double (mx); + points[2].y = _cairo_fixed_from_double (my); + points[3] = *outpt; + + return stroker->add_convex_quad (stroker->closure, points); + } + } + } + } + + /* fall through ... */ + + case CAIRO_LINE_JOIN_BEVEL: + if (stroker->add_external_edge != NULL) { + if (clockwise) { + return stroker->add_external_edge (stroker->closure, + inpt, outpt); + } else { + return stroker->add_external_edge (stroker->closure, + outpt, inpt); + } + } else { + points[0] = in->point; + points[1] = *inpt; + points[2] = *outpt; + + return stroker->add_triangle (stroker->closure, points); + } + } +} + +static cairo_status_t +_cairo_stroker_add_cap (cairo_stroker_t *stroker, + const cairo_stroke_face_t *f) +{ + switch (stroker->style.line_cap) { + case CAIRO_LINE_CAP_ROUND: { + cairo_slope_t slope; + + slope.dx = -f->dev_vector.dx; + slope.dy = -f->dev_vector.dy; + + return _tessellate_fan (stroker, + &f->dev_vector, + &slope, + &f->point, &f->cw, &f->ccw, + FALSE); + + } + + case CAIRO_LINE_CAP_SQUARE: { + double dx, dy; + cairo_slope_t fvector; + cairo_point_t quad[4]; + + dx = f->usr_vector.x; + dy = f->usr_vector.y; + dx *= stroker->half_line_width; + dy *= stroker->half_line_width; + cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); + fvector.dx = _cairo_fixed_from_double (dx); + fvector.dy = _cairo_fixed_from_double (dy); + + quad[0] = f->ccw; + quad[1].x = f->ccw.x + fvector.dx; + quad[1].y = f->ccw.y + fvector.dy; + quad[2].x = f->cw.x + fvector.dx; + quad[2].y = f->cw.y + fvector.dy; + quad[3] = f->cw; + + if (stroker->add_external_edge != NULL) { + cairo_status_t status; + + status = stroker->add_external_edge (stroker->closure, + &quad[0], &quad[1]); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &quad[1], &quad[2]); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &quad[2], &quad[3]); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; + } else { + return stroker->add_convex_quad (stroker->closure, quad); + } + } + + case CAIRO_LINE_CAP_BUTT: + default: + if (stroker->add_external_edge != NULL) { + return stroker->add_external_edge (stroker->closure, + &f->ccw, &f->cw); + } else { + return CAIRO_STATUS_SUCCESS; + } + } +} + +static cairo_status_t +_cairo_stroker_add_leading_cap (cairo_stroker_t *stroker, + const cairo_stroke_face_t *face) +{ + cairo_stroke_face_t reversed; + cairo_point_t t; + + reversed = *face; + + /* The initial cap needs an outward facing vector. Reverse everything */ + reversed.usr_vector.x = -reversed.usr_vector.x; + reversed.usr_vector.y = -reversed.usr_vector.y; + reversed.dev_vector.dx = -reversed.dev_vector.dx; + reversed.dev_vector.dy = -reversed.dev_vector.dy; + t = reversed.cw; + reversed.cw = reversed.ccw; + reversed.ccw = t; + + return _cairo_stroker_add_cap (stroker, &reversed); +} + +static cairo_status_t +_cairo_stroker_add_trailing_cap (cairo_stroker_t *stroker, + const cairo_stroke_face_t *face) +{ + return _cairo_stroker_add_cap (stroker, face); +} + +static inline cairo_bool_t +_compute_normalized_device_slope (double *dx, double *dy, + const cairo_matrix_t *ctm_inverse, + double *mag_out) +{ + double dx0 = *dx, dy0 = *dy; + double mag; + + cairo_matrix_transform_distance (ctm_inverse, &dx0, &dy0); + + if (dx0 == 0.0 && dy0 == 0.0) { + if (mag_out) + *mag_out = 0.0; + return FALSE; + } + + if (dx0 == 0.0) { + *dx = 0.0; + if (dy0 > 0.0) { + mag = dy0; + *dy = 1.0; + } else { + mag = -dy0; + *dy = -1.0; + } + } else if (dy0 == 0.0) { + *dy = 0.0; + if (dx0 > 0.0) { + mag = dx0; + *dx = 1.0; + } else { + mag = -dx0; + *dx = -1.0; + } + } else { + mag = hypot (dx0, dy0); + *dx = dx0 / mag; + *dy = dy0 / mag; + } + + if (mag_out) + *mag_out = mag; + + return TRUE; +} + +static void +_compute_face (const cairo_point_t *point, + const cairo_slope_t *dev_slope, + double slope_dx, + double slope_dy, + cairo_stroker_t *stroker, + cairo_stroke_face_t *face) +{ + double face_dx, face_dy; + cairo_point_t offset_ccw, offset_cw; + + /* + * rotate to get a line_width/2 vector along the face, note that + * the vector must be rotated the right direction in device space, + * but by 90° in user space. So, the rotation depends on + * whether the ctm reflects or not, and that can be determined + * by looking at the determinant of the matrix. + */ + if (stroker->ctm_det_positive) + { + face_dx = - slope_dy * stroker->half_line_width; + face_dy = slope_dx * stroker->half_line_width; + } + else + { + face_dx = slope_dy * stroker->half_line_width; + face_dy = - slope_dx * stroker->half_line_width; + } + + /* back to device space */ + cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy); + + offset_ccw.x = _cairo_fixed_from_double (face_dx); + offset_ccw.y = _cairo_fixed_from_double (face_dy); + offset_cw.x = -offset_ccw.x; + offset_cw.y = -offset_ccw.y; + + face->ccw = *point; + _translate_point (&face->ccw, &offset_ccw); + + face->point = *point; + + face->cw = *point; + _translate_point (&face->cw, &offset_cw); + + face->usr_vector.x = slope_dx; + face->usr_vector.y = slope_dy; + + face->dev_vector = *dev_slope; +} + +static cairo_status_t +_cairo_stroker_add_caps (cairo_stroker_t *stroker) +{ + cairo_status_t status; + + /* check for a degenerative sub_path */ + if (stroker->has_initial_sub_path + && ! stroker->has_first_face + && ! stroker->has_current_face + && stroker->style.line_cap == CAIRO_LINE_CAP_ROUND) + { + /* pick an arbitrary slope to use */ + double dx = 1.0, dy = 0.0; + cairo_slope_t slope = { CAIRO_FIXED_ONE, 0 }; + cairo_stroke_face_t face; + + _compute_normalized_device_slope (&dx, &dy, + stroker->ctm_inverse, NULL); + + /* arbitrarily choose first_point + * first_point and current_point should be the same */ + _compute_face (&stroker->first_point, &slope, dx, dy, stroker, &face); + + status = _cairo_stroker_add_leading_cap (stroker, &face); + if (unlikely (status)) + return status; + + status = _cairo_stroker_add_trailing_cap (stroker, &face); + if (unlikely (status)) + return status; + } + + if (stroker->has_first_face) { + status = _cairo_stroker_add_leading_cap (stroker, + &stroker->first_face); + if (unlikely (status)) + return status; + } + + if (stroker->has_current_face) { + status = _cairo_stroker_add_trailing_cap (stroker, + &stroker->current_face); + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_stroker_add_sub_edge (cairo_stroker_t *stroker, + const cairo_point_t *p1, + const cairo_point_t *p2, + cairo_slope_t *dev_slope, + double slope_dx, double slope_dy, + cairo_stroke_face_t *start, + cairo_stroke_face_t *end) +{ + _compute_face (p1, dev_slope, slope_dx, slope_dy, stroker, start); + *end = *start; + + if (p1->x == p2->x && p1->y == p2->y) + return CAIRO_STATUS_SUCCESS; + + end->point = *p2; + end->ccw.x += p2->x - p1->x; + end->ccw.y += p2->y - p1->y; + end->cw.x += p2->x - p1->x; + end->cw.y += p2->y - p1->y; + + if (stroker->add_external_edge != NULL) { + cairo_status_t status; + + status = stroker->add_external_edge (stroker->closure, + &end->cw, &start->cw); + if (unlikely (status)) + return status; + + status = stroker->add_external_edge (stroker->closure, + &start->ccw, &end->ccw); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; + } else { + cairo_point_t quad[4]; + + quad[0] = start->cw; + quad[1] = end->cw; + quad[2] = end->ccw; + quad[3] = start->ccw; + + return stroker->add_convex_quad (stroker->closure, quad); + } +} + +static cairo_status_t +_cairo_stroker_move_to (void *closure, + const cairo_point_t *point) +{ + cairo_stroker_t *stroker = closure; + cairo_status_t status; + + /* reset the dash pattern for new sub paths */ + _cairo_stroker_dash_start (&stroker->dash); + + /* Cap the start and end of the previous sub path as needed */ + status = _cairo_stroker_add_caps (stroker); + if (unlikely (status)) + return status; + + stroker->first_point = *point; + stroker->current_point = *point; + + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + stroker->has_initial_sub_path = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_stroker_line_to (void *closure, + const cairo_point_t *point) +{ + cairo_stroker_t *stroker = closure; + cairo_stroke_face_t start, end; + cairo_point_t *p1 = &stroker->current_point; + cairo_slope_t dev_slope; + double slope_dx, slope_dy; + cairo_status_t status; + + stroker->has_initial_sub_path = TRUE; + + if (p1->x == point->x && p1->y == point->y) + return CAIRO_STATUS_SUCCESS; + + _cairo_slope_init (&dev_slope, p1, point); + slope_dx = _cairo_fixed_to_double (point->x - p1->x); + slope_dy = _cairo_fixed_to_double (point->y - p1->y); + _compute_normalized_device_slope (&slope_dx, &slope_dy, + stroker->ctm_inverse, NULL); + + status = _cairo_stroker_add_sub_edge (stroker, + p1, point, + &dev_slope, + slope_dx, slope_dy, + &start, &end); + if (unlikely (status)) + return status; + + if (stroker->has_current_face) { + /* Join with final face from previous segment */ + status = _cairo_stroker_join (stroker, + &stroker->current_face, + &start); + if (unlikely (status)) + return status; + } else if (! stroker->has_first_face) { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = start; + stroker->has_first_face = TRUE; + } + stroker->current_face = end; + stroker->has_current_face = TRUE; + + stroker->current_point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_stroker_spline_to (void *closure, + const cairo_point_t *point, + const cairo_slope_t *tangent) +{ + cairo_stroker_t *stroker = closure; + cairo_stroke_face_t new_face; + double slope_dx, slope_dy; + cairo_point_t points[3]; + cairo_point_t intersect_point; + + stroker->has_initial_sub_path = TRUE; + + if (stroker->current_point.x == point->x && + stroker->current_point.y == point->y) + return CAIRO_STATUS_SUCCESS; + + slope_dx = _cairo_fixed_to_double (tangent->dx); + slope_dy = _cairo_fixed_to_double (tangent->dy); + + if (! _compute_normalized_device_slope (&slope_dx, &slope_dy, + stroker->ctm_inverse, NULL)) + return CAIRO_STATUS_SUCCESS; + + _compute_face (point, tangent, + slope_dx, slope_dy, + stroker, &new_face); + + assert (stroker->has_current_face); + + if ((new_face.dev_slope.x * stroker->current_face.dev_slope.x + + new_face.dev_slope.y * stroker->current_face.dev_slope.y) < stroker->spline_cusp_tolerance) { + + const cairo_point_t *inpt, *outpt; + int clockwise = _cairo_stroker_join_is_clockwise (&new_face, + &stroker->current_face); + + if (clockwise) { + inpt = &stroker->current_face.cw; + outpt = &new_face.cw; + } else { + inpt = &stroker->current_face.ccw; + outpt = &new_face.ccw; + } + + _tessellate_fan (stroker, + &stroker->current_face.dev_vector, + &new_face.dev_vector, + &stroker->current_face.point, + inpt, outpt, + clockwise); + } + + if (_slow_segment_intersection (&stroker->current_face.cw, + &stroker->current_face.ccw, + &new_face.cw, + &new_face.ccw, + &intersect_point)) { + points[0] = stroker->current_face.ccw; + points[1] = new_face.ccw; + points[2] = intersect_point; + stroker->add_triangle (stroker->closure, points); + + points[0] = stroker->current_face.cw; + points[1] = new_face.cw; + stroker->add_triangle (stroker->closure, points); + } else { + points[0] = stroker->current_face.ccw; + points[1] = stroker->current_face.cw; + points[2] = new_face.cw; + stroker->add_triangle (stroker->closure, points); + + points[0] = stroker->current_face.ccw; + points[1] = new_face.cw; + points[2] = new_face.ccw; + stroker->add_triangle (stroker->closure, points); + } + + stroker->current_face = new_face; + stroker->has_current_face = TRUE; + stroker->current_point = *point; + + return CAIRO_STATUS_SUCCESS; +} + +/* + * Dashed lines. Cap each dash end, join around turns when on + */ +static cairo_status_t +_cairo_stroker_line_to_dashed (void *closure, + const cairo_point_t *p2) +{ + cairo_stroker_t *stroker = closure; + double mag, remain, step_length = 0; + double slope_dx, slope_dy; + double dx2, dy2; + cairo_stroke_face_t sub_start, sub_end; + cairo_point_t *p1 = &stroker->current_point; + cairo_slope_t dev_slope; + cairo_line_t segment; + cairo_bool_t fully_in_bounds; + cairo_status_t status; + + stroker->has_initial_sub_path = stroker->dash.dash_starts_on; + + if (p1->x == p2->x && p1->y == p2->y) + return CAIRO_STATUS_SUCCESS; + + fully_in_bounds = TRUE; + if (stroker->has_bounds && + (! _cairo_box_contains_point (&stroker->bounds, p1) || + ! _cairo_box_contains_point (&stroker->bounds, p2))) + { + fully_in_bounds = FALSE; + } + + _cairo_slope_init (&dev_slope, p1, p2); + + slope_dx = _cairo_fixed_to_double (p2->x - p1->x); + slope_dy = _cairo_fixed_to_double (p2->y - p1->y); + + if (! _compute_normalized_device_slope (&slope_dx, &slope_dy, + stroker->ctm_inverse, &mag)) + { + return CAIRO_STATUS_SUCCESS; + } + + remain = mag; + segment.p1 = *p1; + while (remain) { + step_length = MIN (stroker->dash.dash_remain, remain); + remain -= step_length; + dx2 = slope_dx * (mag - remain); + dy2 = slope_dy * (mag - remain); + cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2); + segment.p2.x = _cairo_fixed_from_double (dx2) + p1->x; + segment.p2.y = _cairo_fixed_from_double (dy2) + p1->y; + + if (stroker->dash.dash_on && + (fully_in_bounds || + (! stroker->has_first_face && stroker->dash.dash_starts_on) || + _cairo_box_intersects_line_segment (&stroker->bounds, &segment))) + { + status = _cairo_stroker_add_sub_edge (stroker, + &segment.p1, &segment.p2, + &dev_slope, + slope_dx, slope_dy, + &sub_start, &sub_end); + if (unlikely (status)) + return status; + + if (stroker->has_current_face) + { + /* Join with final face from previous segment */ + status = _cairo_stroker_join (stroker, + &stroker->current_face, + &sub_start); + if (unlikely (status)) + return status; + + stroker->has_current_face = FALSE; + } + else if (! stroker->has_first_face && + stroker->dash.dash_starts_on) + { + /* Save sub path's first face in case needed for closing join */ + stroker->first_face = sub_start; + stroker->has_first_face = TRUE; + } + else + { + /* Cap dash start if not connecting to a previous segment */ + status = _cairo_stroker_add_leading_cap (stroker, &sub_start); + if (unlikely (status)) + return status; + } + + if (remain) { + /* Cap dash end if not at end of segment */ + status = _cairo_stroker_add_trailing_cap (stroker, &sub_end); + if (unlikely (status)) + return status; + } else { + stroker->current_face = sub_end; + stroker->has_current_face = TRUE; + } + } else { + if (stroker->has_current_face) { + /* Cap final face from previous segment */ + status = _cairo_stroker_add_trailing_cap (stroker, + &stroker->current_face); + if (unlikely (status)) + return status; + + stroker->has_current_face = FALSE; + } + } + + _cairo_stroker_dash_step (&stroker->dash, step_length); + segment.p1 = segment.p2; + } + + if (stroker->dash.dash_on && ! stroker->has_current_face) { + /* This segment ends on a transition to dash_on, compute a new face + * and add cap for the beginning of the next dash_on step. + * + * Note: this will create a degenerate cap if this is not the last line + * in the path. Whether this behaviour is desirable or not is debatable. + * On one side these degenerate caps can not be reproduced with regular + * path stroking. + * On the other hand, Acroread 7 also produces the degenerate caps. + */ + _compute_face (p2, &dev_slope, + slope_dx, slope_dy, + stroker, + &stroker->current_face); + + status = _cairo_stroker_add_leading_cap (stroker, + &stroker->current_face); + if (unlikely (status)) + return status; + + stroker->has_current_face = TRUE; + } + + stroker->current_point = *p2; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_stroker_curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + cairo_stroker_t *stroker = closure; + cairo_spline_t spline; + cairo_line_join_t line_join_save; + cairo_stroke_face_t face; + double slope_dx, slope_dy; + cairo_spline_add_point_func_t line_to; + cairo_spline_add_point_func_t spline_to; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + line_to = stroker->dash.dashed ? + (cairo_spline_add_point_func_t) _cairo_stroker_line_to_dashed : + (cairo_spline_add_point_func_t) _cairo_stroker_line_to; + + /* spline_to is only capable of rendering non-degenerate splines. */ + spline_to = stroker->dash.dashed ? + (cairo_spline_add_point_func_t) _cairo_stroker_line_to_dashed : + (cairo_spline_add_point_func_t) _cairo_stroker_spline_to; + + if (! _cairo_spline_init (&spline, + spline_to, + stroker, + &stroker->current_point, b, c, d)) + { + cairo_slope_t fallback_slope; + _cairo_slope_init (&fallback_slope, &stroker->current_point, d); + return line_to (closure, d, &fallback_slope); + } + + /* If the line width is so small that the pen is reduced to a + single point, then we have nothing to do. */ + if (stroker->pen.num_vertices <= 1) + return CAIRO_STATUS_SUCCESS; + + /* Compute the initial face */ + if (! stroker->dash.dashed || stroker->dash.dash_on) { + slope_dx = _cairo_fixed_to_double (spline.initial_slope.dx); + slope_dy = _cairo_fixed_to_double (spline.initial_slope.dy); + if (_compute_normalized_device_slope (&slope_dx, &slope_dy, + stroker->ctm_inverse, NULL)) + { + _compute_face (&stroker->current_point, + &spline.initial_slope, + slope_dx, slope_dy, + stroker, &face); + } + if (stroker->has_current_face) { + status = _cairo_stroker_join (stroker, + &stroker->current_face, &face); + if (unlikely (status)) + return status; + } else if (! stroker->has_first_face) { + stroker->first_face = face; + stroker->has_first_face = TRUE; + } + + stroker->current_face = face; + stroker->has_current_face = TRUE; + } + + /* Temporarily modify the stroker to use round joins to guarantee + * smooth stroked curves. */ + line_join_save = stroker->style.line_join; + stroker->style.line_join = CAIRO_LINE_JOIN_ROUND; + + status = _cairo_spline_decompose (&spline, stroker->tolerance); + if (unlikely (status)) + return status; + + /* And join the final face */ + if (! stroker->dash.dashed || stroker->dash.dash_on) { + slope_dx = _cairo_fixed_to_double (spline.final_slope.dx); + slope_dy = _cairo_fixed_to_double (spline.final_slope.dy); + if (_compute_normalized_device_slope (&slope_dx, &slope_dy, + stroker->ctm_inverse, NULL)) + { + _compute_face (&stroker->current_point, + &spline.final_slope, + slope_dx, slope_dy, + stroker, &face); + } + + status = _cairo_stroker_join (stroker, &stroker->current_face, &face); + if (unlikely (status)) + return status; + + stroker->current_face = face; + } + + stroker->style.line_join = line_join_save; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_stroker_close_path (void *closure) +{ + cairo_stroker_t *stroker = closure; + cairo_status_t status; + + if (stroker->dash.dashed) + status = _cairo_stroker_line_to_dashed (stroker, &stroker->first_point); + else + status = _cairo_stroker_line_to (stroker, &stroker->first_point); + if (unlikely (status)) + return status; + + if (stroker->has_first_face && stroker->has_current_face) { + /* Join first and final faces of sub path */ + status = _cairo_stroker_join (stroker, + &stroker->current_face, + &stroker->first_face); + if (unlikely (status)) + return status; + } else { + /* Cap the start and end of the sub path as needed */ + status = _cairo_stroker_add_caps (stroker); + if (unlikely (status)) + return status; + } + + stroker->has_initial_sub_path = FALSE; + stroker->has_first_face = FALSE; + stroker->has_current_face = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_path_fixed_stroke_to_shaper (cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_status_t (*add_triangle) (void *closure, + const cairo_point_t triangle[3]), + cairo_status_t (*add_triangle_fan) (void *closure, + const cairo_point_t *midpt, + const cairo_point_t *points, + int npoints), + cairo_status_t (*add_convex_quad) (void *closure, + const cairo_point_t quad[4]), + void *closure) +{ + cairo_stroker_t stroker; + cairo_status_t status; + + status = _cairo_stroker_init (&stroker, path, stroke_style, + ctm, ctm_inverse, tolerance, + NULL, 0); + if (unlikely (status)) + return status; + + stroker.add_triangle = add_triangle; + stroker.add_triangle_fan = add_triangle_fan; + stroker.add_convex_quad = add_convex_quad; + stroker.closure = closure; + + status = _cairo_path_fixed_interpret (path, + _cairo_stroker_move_to, + stroker.dash.dashed ? + _cairo_stroker_line_to_dashed : + _cairo_stroker_line_to, + _cairo_stroker_curve_to, + _cairo_stroker_close_path, + &stroker); + + if (unlikely (status)) + goto BAIL; + + /* Cap the start and end of the final sub path as needed */ + status = _cairo_stroker_add_caps (&stroker); + +BAIL: + _cairo_stroker_fini (&stroker); + + return status; +} + +cairo_status_t +_cairo_path_fixed_stroke_dashed_to_polygon (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_polygon_t *polygon) +{ + cairo_stroker_t stroker; + cairo_status_t status; + + status = _cairo_stroker_init (&stroker, path, stroke_style, + ctm, ctm_inverse, tolerance, + polygon->limits, polygon->num_limits); + if (unlikely (status)) + return status; + + stroker.add_external_edge = _cairo_polygon_add_external_edge, + stroker.closure = polygon; + + status = _cairo_path_fixed_interpret (path, + _cairo_stroker_move_to, + stroker.dash.dashed ? + _cairo_stroker_line_to_dashed : + _cairo_stroker_line_to, + _cairo_stroker_curve_to, + _cairo_stroker_close_path, + &stroker); + + if (unlikely (status)) + goto BAIL; + + /* Cap the start and end of the final sub path as needed */ + status = _cairo_stroker_add_caps (&stroker); + +BAIL: + _cairo_stroker_fini (&stroker); + + return status; +} + +cairo_int_status_t +_cairo_path_fixed_stroke_polygon_to_traps (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_traps_t *traps) +{ + cairo_int_status_t status; + cairo_polygon_t polygon; + + _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); + status = _cairo_path_fixed_stroke_to_polygon (path, + stroke_style, + ctm, + ctm_inverse, + tolerance, + &polygon); + if (unlikely (status)) + goto BAIL; + + status = _cairo_polygon_status (&polygon); + if (unlikely (status)) + goto BAIL; + + status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, + CAIRO_FILL_RULE_WINDING); + +BAIL: + _cairo_polygon_fini (&polygon); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-path.c b/Build/source/libs/cairo/cairo-src/src/cairo-path.c new file mode 100644 index 00000000000..43cd175a3c5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-path.c @@ -0,0 +1,479 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-private.h" +#include "cairo-backend-private.h" +#include "cairo-error-private.h" +#include "cairo-path-private.h" +#include "cairo-path-fixed-private.h" + +/** + * SECTION:cairo-paths + * @Title: Paths + * @Short_Description: Creating paths and manipulating path data + * + * Paths are the most basic drawing tools and are primarily used to implicitly + * generate simple masks. + **/ + +static const cairo_path_t _cairo_path_nil = { CAIRO_STATUS_NO_MEMORY, NULL, 0 }; + +/* Closure for path interpretation. */ +typedef struct cairo_path_count { + int count; +} cpc_t; + +static cairo_status_t +_cpc_move_to (void *closure, + const cairo_point_t *point) +{ + cpc_t *cpc = closure; + + cpc->count += 2; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cpc_line_to (void *closure, + const cairo_point_t *point) +{ + cpc_t *cpc = closure; + + cpc->count += 2; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cpc_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + cpc_t *cpc = closure; + + cpc->count += 4; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cpc_close_path (void *closure) +{ + cpc_t *cpc = closure; + + cpc->count += 1; + + return CAIRO_STATUS_SUCCESS; +} + +static int +_cairo_path_count (cairo_path_t *path, + cairo_path_fixed_t *path_fixed, + double tolerance, + cairo_bool_t flatten) +{ + cairo_status_t status; + cpc_t cpc; + + cpc.count = 0; + + if (flatten) { + status = _cairo_path_fixed_interpret_flat (path_fixed, + _cpc_move_to, + _cpc_line_to, + _cpc_close_path, + &cpc, + tolerance); + } else { + status = _cairo_path_fixed_interpret (path_fixed, + _cpc_move_to, + _cpc_line_to, + _cpc_curve_to, + _cpc_close_path, + &cpc); + } + + if (unlikely (status)) + return -1; + + return cpc.count; +} + +/* Closure for path interpretation. */ +typedef struct cairo_path_populate { + cairo_path_data_t *data; + cairo_t *cr; +} cpp_t; + +static cairo_status_t +_cpp_move_to (void *closure, + const cairo_point_t *point) +{ + cpp_t *cpp = closure; + cairo_path_data_t *data = cpp->data; + double x, y; + + x = _cairo_fixed_to_double (point->x); + y = _cairo_fixed_to_double (point->y); + + _cairo_backend_to_user (cpp->cr, &x, &y); + + data->header.type = CAIRO_PATH_MOVE_TO; + data->header.length = 2; + + /* We index from 1 to leave room for data->header */ + data[1].point.x = x; + data[1].point.y = y; + + cpp->data += data->header.length; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cpp_line_to (void *closure, + const cairo_point_t *point) +{ + cpp_t *cpp = closure; + cairo_path_data_t *data = cpp->data; + double x, y; + + x = _cairo_fixed_to_double (point->x); + y = _cairo_fixed_to_double (point->y); + + _cairo_backend_to_user (cpp->cr, &x, &y); + + data->header.type = CAIRO_PATH_LINE_TO; + data->header.length = 2; + + /* We index from 1 to leave room for data->header */ + data[1].point.x = x; + data[1].point.y = y; + + cpp->data += data->header.length; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cpp_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + cpp_t *cpp = closure; + cairo_path_data_t *data = cpp->data; + double x1, y1; + double x2, y2; + double x3, y3; + + x1 = _cairo_fixed_to_double (p1->x); + y1 = _cairo_fixed_to_double (p1->y); + _cairo_backend_to_user (cpp->cr, &x1, &y1); + + x2 = _cairo_fixed_to_double (p2->x); + y2 = _cairo_fixed_to_double (p2->y); + _cairo_backend_to_user (cpp->cr, &x2, &y2); + + x3 = _cairo_fixed_to_double (p3->x); + y3 = _cairo_fixed_to_double (p3->y); + _cairo_backend_to_user (cpp->cr, &x3, &y3); + + data->header.type = CAIRO_PATH_CURVE_TO; + data->header.length = 4; + + /* We index from 1 to leave room for data->header */ + data[1].point.x = x1; + data[1].point.y = y1; + + data[2].point.x = x2; + data[2].point.y = y2; + + data[3].point.x = x3; + data[3].point.y = y3; + + cpp->data += data->header.length; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cpp_close_path (void *closure) +{ + cpp_t *cpp = closure; + cairo_path_data_t *data = cpp->data; + + data->header.type = CAIRO_PATH_CLOSE_PATH; + data->header.length = 1; + + cpp->data += data->header.length; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_populate (cairo_path_t *path, + cairo_path_fixed_t *path_fixed, + cairo_t *cr, + cairo_bool_t flatten) +{ + cairo_status_t status; + cpp_t cpp; + + cpp.data = path->data; + cpp.cr = cr; + + if (flatten) { + status = _cairo_path_fixed_interpret_flat (path_fixed, + _cpp_move_to, + _cpp_line_to, + _cpp_close_path, + &cpp, + cairo_get_tolerance (cr)); + } else { + status = _cairo_path_fixed_interpret (path_fixed, + _cpp_move_to, + _cpp_line_to, + _cpp_curve_to, + _cpp_close_path, + &cpp); + } + + if (unlikely (status)) + return status; + + /* Sanity check the count */ + assert (cpp.data - path->data == path->num_data); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_path_t * +_cairo_path_create_in_error (cairo_status_t status) +{ + cairo_path_t *path; + + /* special case NO_MEMORY so as to avoid allocations */ + if (status == CAIRO_STATUS_NO_MEMORY) + return (cairo_path_t*) &_cairo_path_nil; + + path = malloc (sizeof (cairo_path_t)); + if (unlikely (path == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_path_t*) &_cairo_path_nil; + } + + path->num_data = 0; + path->data = NULL; + path->status = status; + + return path; +} + +static cairo_path_t * +_cairo_path_create_internal (cairo_path_fixed_t *path_fixed, + cairo_t *cr, + cairo_bool_t flatten) +{ + cairo_path_t *path; + + path = malloc (sizeof (cairo_path_t)); + if (unlikely (path == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_path_t*) &_cairo_path_nil; + } + + path->num_data = _cairo_path_count (path, path_fixed, + cairo_get_tolerance (cr), + flatten); + if (path->num_data < 0) { + free (path); + return (cairo_path_t*) &_cairo_path_nil; + } + + if (path->num_data) { + path->data = _cairo_malloc_ab (path->num_data, + sizeof (cairo_path_data_t)); + if (unlikely (path->data == NULL)) { + free (path); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_path_t*) &_cairo_path_nil; + } + + path->status = _cairo_path_populate (path, path_fixed, cr, flatten); + } else { + path->data = NULL; + path->status = CAIRO_STATUS_SUCCESS; + } + + return path; +} + +/** + * cairo_path_destroy: + * @path: a path previously returned by either cairo_copy_path() or + * cairo_copy_path_flat(). + * + * Immediately releases all memory associated with @path. After a call + * to cairo_path_destroy() the @path pointer is no longer valid and + * should not be used further. + * + * Note: cairo_path_destroy() should only be called with a + * pointer to a #cairo_path_t returned by a cairo function. Any path + * that is created manually (ie. outside of cairo) should be destroyed + * manually as well. + * + * Since: 1.0 + **/ +void +cairo_path_destroy (cairo_path_t *path) +{ + if (path == NULL || path == &_cairo_path_nil) + return; + + free (path->data); + + free (path); +} +slim_hidden_def (cairo_path_destroy); + +/** + * _cairo_path_create: + * @path: a fixed-point, device-space path to be converted and copied + * @cr: the current graphics context + * + * Creates a user-space #cairo_path_t copy of the given device-space + * @path. The @cr parameter provides the inverse CTM for the + * conversion. + * + * Return value: the new copy of the path. If there is insufficient + * memory a pointer to a special static nil #cairo_path_t will be + * returned instead with status==%CAIRO_STATUS_NO_MEMORY and + * data==%NULL. + **/ +cairo_path_t * +_cairo_path_create (cairo_path_fixed_t *path, + cairo_t *cr) +{ + return _cairo_path_create_internal (path, cr, FALSE); +} + +/** + * _cairo_path_create_flat: + * @path: a fixed-point, device-space path to be flattened, converted and copied + * @cr: the current graphics context + * + * Creates a flattened, user-space #cairo_path_t copy of the given + * device-space @path. The @cr parameter provide the inverse CTM + * for the conversion, as well as the tolerance value to control the + * accuracy of the flattening. + * + * Return value: the flattened copy of the path. If there is insufficient + * memory a pointer to a special static nil #cairo_path_t will be + * returned instead with status==%CAIRO_STATUS_NO_MEMORY and + * data==%NULL. + **/ +cairo_path_t * +_cairo_path_create_flat (cairo_path_fixed_t *path, + cairo_t *cr) +{ + return _cairo_path_create_internal (path, cr, TRUE); +} + +/** + * _cairo_path_append_to_context: + * @path: the path data to be appended + * @cr: a cairo context + * + * Append @path to the current path within @cr. + * + * Return value: %CAIRO_STATUS_INVALID_PATH_DATA if the data in @path + * is invalid, and %CAIRO_STATUS_SUCCESS otherwise. + **/ +cairo_status_t +_cairo_path_append_to_context (const cairo_path_t *path, + cairo_t *cr) +{ + const cairo_path_data_t *p, *end; + + end = &path->data[path->num_data]; + for (p = &path->data[0]; p < end; p += p->header.length) { + switch (p->header.type) { + case CAIRO_PATH_MOVE_TO: + if (unlikely (p->header.length < 2)) + return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); + + cairo_move_to (cr, p[1].point.x, p[1].point.y); + break; + + case CAIRO_PATH_LINE_TO: + if (unlikely (p->header.length < 2)) + return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); + + cairo_line_to (cr, p[1].point.x, p[1].point.y); + break; + + case CAIRO_PATH_CURVE_TO: + if (unlikely (p->header.length < 4)) + return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); + + cairo_curve_to (cr, + p[1].point.x, p[1].point.y, + p[2].point.x, p[2].point.y, + p[3].point.x, p[3].point.y); + break; + + case CAIRO_PATH_CLOSE_PATH: + if (unlikely (p->header.length < 1)) + return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); + + cairo_close_path (cr); + break; + + default: + return _cairo_error (CAIRO_STATUS_INVALID_PATH_DATA); + } + + if (unlikely (cr->status)) + return cr->status; + } + + return CAIRO_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pattern-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-pattern-inline.h new file mode 100644 index 00000000000..97e8ea034e4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pattern-inline.h @@ -0,0 +1,65 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PATTERN_INLINE_H +#define CAIRO_PATTERN_INLINE_H + +#include "cairo-pattern-private.h" + +#include "cairo-list-inline.h" + +CAIRO_BEGIN_DECLS + +static inline void +_cairo_pattern_add_observer (cairo_pattern_t *pattern, + cairo_pattern_observer_t *observer, + void (*func) (cairo_pattern_observer_t *, + cairo_pattern_t *, + unsigned int)) +{ + observer->notify = func; + cairo_list_add (&observer->link, &pattern->observers); +} + +static inline cairo_surface_t * +_cairo_pattern_get_source (const cairo_surface_pattern_t *pattern, + cairo_rectangle_int_t *extents) +{ + return _cairo_surface_get_source (pattern->surface, extents); +} + +CAIRO_END_DECLS + +#endif /* CAIRO_PATTERN_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pattern-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-pattern-private.h new file mode 100644 index 00000000000..be8ab9fc239 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pattern-private.h @@ -0,0 +1,369 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PATTERN_PRIVATE_H +#define CAIRO_PATTERN_PRIVATE_H + +#include "cairo-error-private.h" +#include "cairo-types-private.h" +#include "cairo-list-private.h" +#include "cairo-surface-private.h" + +#include /* FILE* */ + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_pattern_observer cairo_pattern_observer_t; + +enum { + CAIRO_PATTERN_NOTIFY_MATRIX = 0x1, + CAIRO_PATTERN_NOTIFY_FILTER = 0x2, + CAIRO_PATTERN_NOTIFY_EXTEND = 0x4, + CAIRO_PATTERN_NOTIFY_OPACITY = 0x9, +}; + +struct _cairo_pattern_observer { + void (*notify) (cairo_pattern_observer_t *, + cairo_pattern_t *pattern, + unsigned int flags); + cairo_list_t link; +}; + +struct _cairo_pattern { + cairo_reference_count_t ref_count; + cairo_status_t status; + cairo_user_data_array_t user_data; + cairo_list_t observers; + + cairo_pattern_type_t type; + + cairo_filter_t filter; + cairo_extend_t extend; + cairo_bool_t has_component_alpha; + + cairo_matrix_t matrix; + double opacity; +}; + +struct _cairo_solid_pattern { + cairo_pattern_t base; + cairo_color_t color; +}; + +typedef struct _cairo_surface_pattern { + cairo_pattern_t base; + + cairo_surface_t *surface; +} cairo_surface_pattern_t; + +typedef struct _cairo_gradient_stop { + double offset; + cairo_color_stop_t color; +} cairo_gradient_stop_t; + +typedef struct _cairo_gradient_pattern { + cairo_pattern_t base; + + unsigned int n_stops; + unsigned int stops_size; + cairo_gradient_stop_t *stops; + cairo_gradient_stop_t stops_embedded[2]; +} cairo_gradient_pattern_t; + +typedef struct _cairo_linear_pattern { + cairo_gradient_pattern_t base; + + cairo_point_double_t pd1; + cairo_point_double_t pd2; +} cairo_linear_pattern_t; + +typedef struct _cairo_radial_pattern { + cairo_gradient_pattern_t base; + + cairo_circle_double_t cd1; + cairo_circle_double_t cd2; +} cairo_radial_pattern_t; + +typedef union { + cairo_gradient_pattern_t base; + + cairo_linear_pattern_t linear; + cairo_radial_pattern_t radial; +} cairo_gradient_pattern_union_t; + +/* + * A mesh patch is a tensor-product patch (bicubic Bezier surface + * patch). It has 16 control points. Each set of 4 points along the + * sides of the 4x4 grid of control points is a Bezier curve that + * defines one side of the patch. A color is assigned to each + * corner. The inner 4 points provide additional control over the + * shape and the color mapping. + * + * Cairo uses the same convention as the PDF Reference for numbering + * the points and side of the patch. + * + * + * Side 1 + * + * p[0][3] p[1][3] p[2][3] p[3][3] + * Side 0 p[0][2] p[1][2] p[2][2] p[3][2] Side 2 + * p[0][1] p[1][1] p[2][1] p[3][1] + * p[0][0] p[1][0] p[2][0] p[3][0] + * + * Side 3 + * + * + * Point Color + * ------------------------- + * points[0][0] colors[0] + * points[0][3] colors[1] + * points[3][3] colors[2] + * points[3][0] colors[3] + */ + +typedef struct _cairo_mesh_patch { + cairo_point_double_t points[4][4]; + cairo_color_t colors[4]; +} cairo_mesh_patch_t; + +typedef struct _cairo_mesh_pattern { + cairo_pattern_t base; + + cairo_array_t patches; + cairo_mesh_patch_t *current_patch; + int current_side; + cairo_bool_t has_control_point[4]; + cairo_bool_t has_color[4]; +} cairo_mesh_pattern_t; + +typedef struct _cairo_raster_source_pattern { + cairo_pattern_t base; + + cairo_content_t content; + cairo_rectangle_int_t extents; + + cairo_raster_source_acquire_func_t acquire; + cairo_raster_source_release_func_t release; + cairo_raster_source_snapshot_func_t snapshot; + cairo_raster_source_copy_func_t copy; + cairo_raster_source_finish_func_t finish; + + /* an explicit pre-allocated member in preference to the general user-data */ + void *user_data; +} cairo_raster_source_pattern_t; + +typedef union { + cairo_pattern_t base; + + cairo_solid_pattern_t solid; + cairo_surface_pattern_t surface; + cairo_gradient_pattern_union_t gradient; + cairo_mesh_pattern_t mesh; + cairo_raster_source_pattern_t raster_source; +} cairo_pattern_union_t; + +/* cairo-pattern.c */ + +cairo_private cairo_pattern_t * +_cairo_pattern_create_in_error (cairo_status_t status); + +cairo_private cairo_status_t +_cairo_pattern_create_copy (cairo_pattern_t **pattern, + const cairo_pattern_t *other); + +cairo_private void +_cairo_pattern_init (cairo_pattern_t *pattern, + cairo_pattern_type_t type); + +cairo_private cairo_status_t +_cairo_pattern_init_copy (cairo_pattern_t *pattern, + const cairo_pattern_t *other); + +cairo_private void +_cairo_pattern_init_static_copy (cairo_pattern_t *pattern, + const cairo_pattern_t *other); + +cairo_private cairo_status_t +_cairo_pattern_init_snapshot (cairo_pattern_t *pattern, + const cairo_pattern_t *other); + +cairo_private void +_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, + const cairo_color_t *color); + +cairo_private void +_cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, + cairo_surface_t *surface); + +cairo_private void +_cairo_pattern_fini (cairo_pattern_t *pattern); + +cairo_private cairo_pattern_t * +_cairo_pattern_create_solid (const cairo_color_t *color); + +cairo_private void +_cairo_pattern_transform (cairo_pattern_t *pattern, + const cairo_matrix_t *ctm_inverse); + +cairo_private void +_cairo_pattern_pretransform (cairo_pattern_t *pattern, + const cairo_matrix_t *ctm); + +cairo_private cairo_bool_t +_cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern); + +cairo_private cairo_bool_t +_cairo_pattern_is_opaque (const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents); + +cairo_private cairo_bool_t +_cairo_pattern_is_clear (const cairo_pattern_t *pattern); + +cairo_private cairo_bool_t +_cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents, + cairo_color_t *color); + +cairo_private void +_cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient, + double max_value, + cairo_matrix_t *out_matrix, + cairo_circle_double_t out_circle[2]); + +cairo_private cairo_bool_t +_cairo_radial_pattern_focus_is_inside (const cairo_radial_pattern_t *radial); + +cairo_private void +_cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient, + double x0, double y0, + double x1, double y1, + double tolerance, + double out_range[2]); + +cairo_private void +_cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient, + double t, + cairo_circle_double_t *out_circle); + +cairo_private void +_cairo_pattern_alpha_range (const cairo_pattern_t *pattern, + double *out_min, + double *out_max); + +cairo_private cairo_bool_t +_cairo_mesh_pattern_coord_box (const cairo_mesh_pattern_t *mesh, + double *out_xmin, + double *out_ymin, + double *out_xmax, + double *out_ymax); + +cairo_private void +_cairo_pattern_sampled_area (const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + cairo_rectangle_int_t *sample); + +cairo_private void +_cairo_pattern_get_extents (const cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents); + +cairo_private cairo_int_status_t +_cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents); + +cairo_private unsigned long +_cairo_pattern_hash (const cairo_pattern_t *pattern); + +cairo_private unsigned long +_cairo_linear_pattern_hash (unsigned long hash, + const cairo_linear_pattern_t *linear); + +cairo_private unsigned long +_cairo_radial_pattern_hash (unsigned long hash, + const cairo_radial_pattern_t *radial); + +cairo_private cairo_bool_t +_cairo_linear_pattern_equal (const cairo_linear_pattern_t *a, + const cairo_linear_pattern_t *b); + +cairo_private unsigned long +_cairo_pattern_size (const cairo_pattern_t *pattern); + +cairo_private cairo_bool_t +_cairo_radial_pattern_equal (const cairo_radial_pattern_t *a, + const cairo_radial_pattern_t *b); + +cairo_private cairo_bool_t +_cairo_pattern_equal (const cairo_pattern_t *a, + const cairo_pattern_t *b); + +cairo_private cairo_filter_t +_cairo_pattern_analyze_filter (const cairo_pattern_t *pattern); + +/* cairo-mesh-pattern-rasterizer.c */ + +cairo_private void +_cairo_mesh_pattern_rasterize (const cairo_mesh_pattern_t *mesh, + void *data, + int width, + int height, + int stride, + double x_offset, + double y_offset); + +cairo_private cairo_surface_t * +_cairo_raster_source_pattern_acquire (const cairo_pattern_t *abstract_pattern, + cairo_surface_t *target, + const cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_raster_source_pattern_release (const cairo_pattern_t *abstract_pattern, + cairo_surface_t *surface); + +cairo_private cairo_status_t +_cairo_raster_source_pattern_snapshot (cairo_pattern_t *abstract_pattern); + +cairo_private cairo_status_t +_cairo_raster_source_pattern_init_copy (cairo_pattern_t *pattern, + const cairo_pattern_t *other); + +cairo_private void +_cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern); + +cairo_private void +_cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern); + +CAIRO_END_DECLS + +#endif /* CAIRO_PATTERN_PRIVATE */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pattern.c b/Build/source/libs/cairo/cairo-src/src/cairo-pattern.c new file mode 100644 index 00000000000..ac5d7af20a2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pattern.c @@ -0,0 +1,4699 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 David Reveman + * Copyright © 2005 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of David + * Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. David Reveman makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: David Reveman + * Keith Packard + * Carl Worth + */ + +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" +#include "cairo-freed-pool-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-path-private.h" +#include "cairo-pattern-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-surface-snapshot-inline.h" + +#include + +#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ + +/** + * SECTION:cairo-pattern + * @Title: cairo_pattern_t + * @Short_Description: Sources for drawing + * @See_Also: #cairo_t, #cairo_surface_t + * + * #cairo_pattern_t is the paint with which cairo draws. + * The primary use of patterns is as the source for all cairo drawing + * operations, although they can also be used as masks, that is, as the + * brush too. + * + * A cairo pattern is created by using one of the many constructors, + * of the form + * cairo_pattern_create_type() + * or implicitly through + * cairo_set_source_type() + * functions. + **/ + +static freed_pool_t freed_pattern_pool[5]; + +static const cairo_solid_pattern_t _cairo_pattern_nil = { + { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_NO_MEMORY, /* status */ + { 0, 0, 0, NULL }, /* user_data */ + { NULL, NULL }, /* observers */ + + CAIRO_PATTERN_TYPE_SOLID, /* type */ + CAIRO_FILTER_DEFAULT, /* filter */ + CAIRO_EXTEND_GRADIENT_DEFAULT, /* extend */ + FALSE, /* has component alpha */ + { 1., 0., 0., 1., 0., 0., }, /* matrix */ + 1.0 /* opacity */ + } +}; + +static const cairo_solid_pattern_t _cairo_pattern_nil_null_pointer = { + { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_NULL_POINTER, /* status */ + { 0, 0, 0, NULL }, /* user_data */ + { NULL, NULL }, /* observers */ + + CAIRO_PATTERN_TYPE_SOLID, /* type */ + CAIRO_FILTER_DEFAULT, /* filter */ + CAIRO_EXTEND_GRADIENT_DEFAULT, /* extend */ + FALSE, /* has component alpha */ + { 1., 0., 0., 1., 0., 0., }, /* matrix */ + 1.0 /* opacity */ + } +}; + +const cairo_solid_pattern_t _cairo_pattern_black = { + { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_SUCCESS, /* status */ + { 0, 0, 0, NULL }, /* user_data */ + { NULL, NULL }, /* observers */ + + CAIRO_PATTERN_TYPE_SOLID, /* type */ + CAIRO_FILTER_NEAREST, /* filter */ + CAIRO_EXTEND_REPEAT, /* extend */ + FALSE, /* has component alpha */ + { 1., 0., 0., 1., 0., 0., }, /* matrix */ + 1.0 /* opacity */ + }, + { 0., 0., 0., 1., 0, 0, 0, 0xffff },/* color (double rgba, short rgba) */ +}; + +const cairo_solid_pattern_t _cairo_pattern_clear = { + { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_SUCCESS, /* status */ + { 0, 0, 0, NULL }, /* user_data */ + { NULL, NULL }, /* observers */ + + CAIRO_PATTERN_TYPE_SOLID, /* type */ + CAIRO_FILTER_NEAREST, /* filter */ + CAIRO_EXTEND_REPEAT, /* extend */ + FALSE, /* has component alpha */ + { 1., 0., 0., 1., 0., 0., }, /* matrix */ + 1.0 /* opacity */ + }, + { 0., 0., 0., 0., 0, 0, 0, 0 },/* color (double rgba, short rgba) */ +}; + +const cairo_solid_pattern_t _cairo_pattern_white = { + { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_SUCCESS, /* status */ + { 0, 0, 0, NULL }, /* user_data */ + { NULL, NULL }, /* observers */ + + CAIRO_PATTERN_TYPE_SOLID, /* type */ + CAIRO_FILTER_NEAREST, /* filter */ + CAIRO_EXTEND_REPEAT, /* extend */ + FALSE, /* has component alpha */ + { 1., 0., 0., 1., 0., 0., }, /* matrix */ + 1.0 /* opacity */ + }, + { 1., 1., 1., 1., 0xffff, 0xffff, 0xffff, 0xffff },/* color (double rgba, short rgba) */ +}; + +static void +_cairo_pattern_notify_observers (cairo_pattern_t *pattern, + unsigned int flags) +{ + cairo_pattern_observer_t *pos; + + cairo_list_foreach_entry (pos, cairo_pattern_observer_t, &pattern->observers, link) + pos->notify (pos, pattern, flags); +} + +/** + * _cairo_pattern_set_error: + * @pattern: a pattern + * @status: a status value indicating an error + * + * Atomically sets pattern->status to @status and calls _cairo_error; + * Does nothing if status is %CAIRO_STATUS_SUCCESS. + * + * All assignments of an error status to pattern->status should happen + * through _cairo_pattern_set_error(). Note that due to the nature of + * the atomic operation, it is not safe to call this function on the nil + * objects. + * + * The purpose of this function is to allow the user to set a + * breakpoint in _cairo_error() to generate a stack trace for when the + * user causes cairo to detect an error. + **/ +static cairo_status_t +_cairo_pattern_set_error (cairo_pattern_t *pattern, + cairo_status_t status) +{ + if (status == CAIRO_STATUS_SUCCESS) + return status; + + /* Don't overwrite an existing error. This preserves the first + * error, which is the most significant. */ + _cairo_status_set_error (&pattern->status, status); + + return _cairo_error (status); +} + +void +_cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type) +{ +#if HAVE_VALGRIND + switch (type) { + case CAIRO_PATTERN_TYPE_SOLID: + VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_solid_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_surface_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_linear_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_radial_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_MESH: + VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_mesh_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + break; + } +#endif + + pattern->type = type; + pattern->status = CAIRO_STATUS_SUCCESS; + + /* Set the reference count to zero for on-stack patterns. + * Callers needs to explicitly increment the count for heap allocations. */ + CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); + + _cairo_user_data_array_init (&pattern->user_data); + + if (type == CAIRO_PATTERN_TYPE_SURFACE || + type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) + pattern->extend = CAIRO_EXTEND_SURFACE_DEFAULT; + else + pattern->extend = CAIRO_EXTEND_GRADIENT_DEFAULT; + + pattern->filter = CAIRO_FILTER_DEFAULT; + pattern->opacity = 1.0; + + pattern->has_component_alpha = FALSE; + + cairo_matrix_init_identity (&pattern->matrix); + + cairo_list_init (&pattern->observers); +} + +static cairo_status_t +_cairo_gradient_pattern_init_copy (cairo_gradient_pattern_t *pattern, + const cairo_gradient_pattern_t *other) +{ + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (other->base.type == CAIRO_PATTERN_TYPE_LINEAR) + { + cairo_linear_pattern_t *dst = (cairo_linear_pattern_t *) pattern; + cairo_linear_pattern_t *src = (cairo_linear_pattern_t *) other; + + *dst = *src; + } + else + { + cairo_radial_pattern_t *dst = (cairo_radial_pattern_t *) pattern; + cairo_radial_pattern_t *src = (cairo_radial_pattern_t *) other; + + *dst = *src; + } + + if (other->stops == other->stops_embedded) + pattern->stops = pattern->stops_embedded; + else if (other->stops) + { + pattern->stops = _cairo_malloc_ab (other->stops_size, + sizeof (cairo_gradient_stop_t)); + if (unlikely (pattern->stops == NULL)) { + pattern->stops_size = 0; + pattern->n_stops = 0; + return _cairo_pattern_set_error (&pattern->base, CAIRO_STATUS_NO_MEMORY); + } + + memcpy (pattern->stops, other->stops, + other->n_stops * sizeof (cairo_gradient_stop_t)); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_mesh_pattern_init_copy (cairo_mesh_pattern_t *pattern, + const cairo_mesh_pattern_t *other) +{ + *pattern = *other; + + _cairo_array_init (&pattern->patches, sizeof (cairo_mesh_patch_t)); + return _cairo_array_append_multiple (&pattern->patches, + _cairo_array_index_const (&other->patches, 0), + _cairo_array_num_elements (&other->patches)); +} + +cairo_status_t +_cairo_pattern_init_copy (cairo_pattern_t *pattern, + const cairo_pattern_t *other) +{ + cairo_status_t status; + + if (other->status) + return _cairo_pattern_set_error (pattern, other->status); + + switch (other->type) { + case CAIRO_PATTERN_TYPE_SOLID: { + cairo_solid_pattern_t *dst = (cairo_solid_pattern_t *) pattern; + cairo_solid_pattern_t *src = (cairo_solid_pattern_t *) other; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_solid_pattern_t))); + + *dst = *src; + } break; + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_pattern_t *dst = (cairo_surface_pattern_t *) pattern; + cairo_surface_pattern_t *src = (cairo_surface_pattern_t *) other; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_surface_pattern_t))); + + *dst = *src; + cairo_surface_reference (dst->surface); + } break; + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: { + cairo_gradient_pattern_t *dst = (cairo_gradient_pattern_t *) pattern; + cairo_gradient_pattern_t *src = (cairo_gradient_pattern_t *) other; + + if (other->type == CAIRO_PATTERN_TYPE_LINEAR) { + VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_linear_pattern_t))); + } else { + VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_radial_pattern_t))); + } + + status = _cairo_gradient_pattern_init_copy (dst, src); + if (unlikely (status)) + return status; + + } break; + case CAIRO_PATTERN_TYPE_MESH: { + cairo_mesh_pattern_t *dst = (cairo_mesh_pattern_t *) pattern; + cairo_mesh_pattern_t *src = (cairo_mesh_pattern_t *) other; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_mesh_pattern_t))); + + status = _cairo_mesh_pattern_init_copy (dst, src); + if (unlikely (status)) + return status; + + } break; + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: { + status = _cairo_raster_source_pattern_init_copy (pattern, other); + if (unlikely (status)) + return status; + } break; + } + + /* The reference count and user_data array are unique to the copy. */ + CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); + _cairo_user_data_array_init (&pattern->user_data); + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_pattern_init_static_copy (cairo_pattern_t *pattern, + const cairo_pattern_t *other) +{ + int size; + + assert (other->status == CAIRO_STATUS_SUCCESS); + + switch (other->type) { + default: + ASSERT_NOT_REACHED; + case CAIRO_PATTERN_TYPE_SOLID: + size = sizeof (cairo_solid_pattern_t); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + size = sizeof (cairo_surface_pattern_t); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + size = sizeof (cairo_linear_pattern_t); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + size = sizeof (cairo_radial_pattern_t); + break; + case CAIRO_PATTERN_TYPE_MESH: + size = sizeof (cairo_mesh_pattern_t); + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + size = sizeof (cairo_raster_source_pattern_t); + break; + } + + memcpy (pattern, other, size); + + CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); + _cairo_user_data_array_init (&pattern->user_data); +} + +cairo_status_t +_cairo_pattern_init_snapshot (cairo_pattern_t *pattern, + const cairo_pattern_t *other) +{ + cairo_status_t status; + + /* We don't bother doing any fancy copy-on-write implementation + * for the pattern's data. It's generally quite tiny. */ + status = _cairo_pattern_init_copy (pattern, other); + if (unlikely (status)) + return status; + + /* But we do let the surface snapshot stuff be as fancy as it + * would like to be. */ + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surface_pattern = + (cairo_surface_pattern_t *) pattern; + cairo_surface_t *surface = surface_pattern->surface; + + surface_pattern->surface = _cairo_surface_snapshot (surface); + + cairo_surface_destroy (surface); + + status = surface_pattern->surface->status; + } else if (pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) + status = _cairo_raster_source_pattern_snapshot (pattern); + + return status; +} + +void +_cairo_pattern_fini (cairo_pattern_t *pattern) +{ + _cairo_user_data_array_fini (&pattern->user_data); + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + break; + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_pattern_t *surface_pattern = + (cairo_surface_pattern_t *) pattern; + + cairo_surface_destroy (surface_pattern->surface); + } break; + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: { + cairo_gradient_pattern_t *gradient = + (cairo_gradient_pattern_t *) pattern; + + if (gradient->stops && gradient->stops != gradient->stops_embedded) + free (gradient->stops); + } break; + case CAIRO_PATTERN_TYPE_MESH: { + cairo_mesh_pattern_t *mesh = + (cairo_mesh_pattern_t *) pattern; + + _cairo_array_fini (&mesh->patches); + } break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + _cairo_raster_source_pattern_finish (pattern); + break; + } + +#if HAVE_VALGRIND + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_solid_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_surface_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_linear_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_radial_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_MESH: + VALGRIND_MAKE_MEM_NOACCESS (pattern, sizeof (cairo_mesh_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + break; + } +#endif +} + +cairo_status_t +_cairo_pattern_create_copy (cairo_pattern_t **pattern_out, + const cairo_pattern_t *other) +{ + cairo_pattern_t *pattern; + cairo_status_t status; + + if (other->status) + return other->status; + + switch (other->type) { + case CAIRO_PATTERN_TYPE_SOLID: + pattern = malloc (sizeof (cairo_solid_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + pattern = malloc (sizeof (cairo_surface_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + pattern = malloc (sizeof (cairo_linear_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + pattern = malloc (sizeof (cairo_radial_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_MESH: + pattern = malloc (sizeof (cairo_mesh_pattern_t)); + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + pattern = malloc (sizeof (cairo_raster_source_pattern_t)); + break; + default: + ASSERT_NOT_REACHED; + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + } + if (unlikely (pattern == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_pattern_init_copy (pattern, other); + if (unlikely (status)) { + free (pattern); + return status; + } + + CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 1); + *pattern_out = pattern; + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, + const cairo_color_t *color) +{ + _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SOLID); + pattern->color = *color; +} + +void +_cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, + cairo_surface_t *surface) +{ + if (surface->status) { + /* Force to solid to simplify the pattern_fini process. */ + _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SOLID); + _cairo_pattern_set_error (&pattern->base, surface->status); + return; + } + + _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SURFACE); + + pattern->surface = cairo_surface_reference (surface); +} + +static void +_cairo_pattern_init_gradient (cairo_gradient_pattern_t *pattern, + cairo_pattern_type_t type) +{ + _cairo_pattern_init (&pattern->base, type); + + pattern->n_stops = 0; + pattern->stops_size = 0; + pattern->stops = NULL; +} + +static void +_cairo_pattern_init_linear (cairo_linear_pattern_t *pattern, + double x0, double y0, double x1, double y1) +{ + _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_LINEAR); + + pattern->pd1.x = x0; + pattern->pd1.y = y0; + pattern->pd2.x = x1; + pattern->pd2.y = y1; +} + +static void +_cairo_pattern_init_radial (cairo_radial_pattern_t *pattern, + double cx0, double cy0, double radius0, + double cx1, double cy1, double radius1) +{ + _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_RADIAL); + + pattern->cd1.center.x = cx0; + pattern->cd1.center.y = cy0; + pattern->cd1.radius = fabs (radius0); + pattern->cd2.center.x = cx1; + pattern->cd2.center.y = cy1; + pattern->cd2.radius = fabs (radius1); +} + +cairo_pattern_t * +_cairo_pattern_create_solid (const cairo_color_t *color) +{ + cairo_solid_pattern_t *pattern; + + pattern = + _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_SOLID]); + if (unlikely (pattern == NULL)) { + /* None cached, need to create a new pattern. */ + pattern = malloc (sizeof (cairo_solid_pattern_t)); + if (unlikely (pattern == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_pattern_t *) &_cairo_pattern_nil; + } + } + + _cairo_pattern_init_solid (pattern, color); + CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); + + return &pattern->base; +} + +cairo_pattern_t * +_cairo_pattern_create_in_error (cairo_status_t status) +{ + cairo_pattern_t *pattern; + + if (status == CAIRO_STATUS_NO_MEMORY) + return (cairo_pattern_t *)&_cairo_pattern_nil.base; + + CAIRO_MUTEX_INITIALIZE (); + + pattern = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK); + if (pattern->status == CAIRO_STATUS_SUCCESS) + status = _cairo_pattern_set_error (pattern, status); + + return pattern; +} + +/** + * cairo_pattern_create_rgb: + * @red: red component of the color + * @green: green component of the color + * @blue: blue component of the color + * + * Creates a new #cairo_pattern_t corresponding to an opaque color. The + * color components are floating point numbers in the range 0 to 1. + * If the values passed in are outside that range, they will be + * clamped. + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_pattern_create_rgb (double red, double green, double blue) +{ + return cairo_pattern_create_rgba (red, green, blue, 1.0); +} +slim_hidden_def (cairo_pattern_create_rgb); + +/** + * cairo_pattern_create_rgba: + * @red: red component of the color + * @green: green component of the color + * @blue: blue component of the color + * @alpha: alpha component of the color + * + * Creates a new #cairo_pattern_t corresponding to a translucent color. + * The color components are floating point numbers in the range 0 to + * 1. If the values passed in are outside that range, they will be + * clamped. + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_pattern_create_rgba (double red, double green, double blue, + double alpha) +{ + cairo_color_t color; + + red = _cairo_restrict_value (red, 0.0, 1.0); + green = _cairo_restrict_value (green, 0.0, 1.0); + blue = _cairo_restrict_value (blue, 0.0, 1.0); + alpha = _cairo_restrict_value (alpha, 0.0, 1.0); + + _cairo_color_init_rgba (&color, red, green, blue, alpha); + + CAIRO_MUTEX_INITIALIZE (); + + return _cairo_pattern_create_solid (&color); +} +slim_hidden_def (cairo_pattern_create_rgba); + +/** + * cairo_pattern_create_for_surface: + * @surface: the surface + * + * Create a new #cairo_pattern_t for the given surface. + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_pattern_create_for_surface (cairo_surface_t *surface) +{ + cairo_surface_pattern_t *pattern; + + if (surface == NULL) { + _cairo_error_throw (CAIRO_STATUS_NULL_POINTER); + return (cairo_pattern_t*) &_cairo_pattern_nil_null_pointer; + } + + if (surface->status) + return _cairo_pattern_create_in_error (surface->status); + + pattern = + _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_SURFACE]); + if (unlikely (pattern == NULL)) { + pattern = malloc (sizeof (cairo_surface_pattern_t)); + if (unlikely (pattern == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_pattern_t *)&_cairo_pattern_nil.base; + } + } + + CAIRO_MUTEX_INITIALIZE (); + + _cairo_pattern_init_for_surface (pattern, surface); + CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); + + return &pattern->base; +} +slim_hidden_def (cairo_pattern_create_for_surface); + +/** + * cairo_pattern_create_linear: + * @x0: x coordinate of the start point + * @y0: y coordinate of the start point + * @x1: x coordinate of the end point + * @y1: y coordinate of the end point + * + * Create a new linear gradient #cairo_pattern_t along the line defined + * by (x0, y0) and (x1, y1). Before using the gradient pattern, a + * number of color stops should be defined using + * cairo_pattern_add_color_stop_rgb() or + * cairo_pattern_add_color_stop_rgba(). + * + * Note: The coordinates here are in pattern space. For a new pattern, + * pattern space is identical to user space, but the relationship + * between the spaces can be changed with cairo_pattern_set_matrix(). + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_pattern_create_linear (double x0, double y0, double x1, double y1) +{ + cairo_linear_pattern_t *pattern; + + pattern = + _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_LINEAR]); + if (unlikely (pattern == NULL)) { + pattern = malloc (sizeof (cairo_linear_pattern_t)); + if (unlikely (pattern == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_pattern_t *) &_cairo_pattern_nil.base; + } + } + + CAIRO_MUTEX_INITIALIZE (); + + _cairo_pattern_init_linear (pattern, x0, y0, x1, y1); + CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); + + return &pattern->base.base; +} + +/** + * cairo_pattern_create_radial: + * @cx0: x coordinate for the center of the start circle + * @cy0: y coordinate for the center of the start circle + * @radius0: radius of the start circle + * @cx1: x coordinate for the center of the end circle + * @cy1: y coordinate for the center of the end circle + * @radius1: radius of the end circle + * + * Creates a new radial gradient #cairo_pattern_t between the two + * circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1). Before using the + * gradient pattern, a number of color stops should be defined using + * cairo_pattern_add_color_stop_rgb() or + * cairo_pattern_add_color_stop_rgba(). + * + * Note: The coordinates here are in pattern space. For a new pattern, + * pattern space is identical to user space, but the relationship + * between the spaces can be changed with cairo_pattern_set_matrix(). + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the + * returned object and should call cairo_pattern_destroy() when + * finished with it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect + * the status of a pattern use cairo_pattern_status(). + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_pattern_create_radial (double cx0, double cy0, double radius0, + double cx1, double cy1, double radius1) +{ + cairo_radial_pattern_t *pattern; + + pattern = + _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_RADIAL]); + if (unlikely (pattern == NULL)) { + pattern = malloc (sizeof (cairo_radial_pattern_t)); + if (unlikely (pattern == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_pattern_t *) &_cairo_pattern_nil.base; + } + } + + CAIRO_MUTEX_INITIALIZE (); + + _cairo_pattern_init_radial (pattern, cx0, cy0, radius0, cx1, cy1, radius1); + CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); + + return &pattern->base.base; +} + +/* This order is specified in the diagram in the documentation for + * cairo_pattern_create_mesh() */ +static const int mesh_path_point_i[12] = { 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1 }; +static const int mesh_path_point_j[12] = { 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0 }; +static const int mesh_control_point_i[4] = { 1, 1, 2, 2 }; +static const int mesh_control_point_j[4] = { 1, 2, 2, 1 }; + +/** + * cairo_pattern_create_mesh: + * + * Create a new mesh pattern. + * + * Mesh patterns are tensor-product patch meshes (type 7 shadings in + * PDF). Mesh patterns may also be used to create other types of + * shadings that are special cases of tensor-product patch meshes such + * as Coons patch meshes (type 6 shading in PDF) and Gouraud-shaded + * triangle meshes (type 4 and 5 shadings in PDF). + * + * Mesh patterns consist of one or more tensor-product patches, which + * should be defined before using the mesh pattern. Using a mesh + * pattern with a partially defined patch as source or mask will put + * the context in an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * A tensor-product patch is defined by 4 Bézier curves (side 0, 1, 2, + * 3) and by 4 additional control points (P0, P1, P2, P3) that provide + * further control over the patch and complete the definition of the + * tensor-product patch. The corner C0 is the first point of the + * patch. + * + * Degenerate sides are permitted so straight lines may be used. A + * zero length line on one side may be used to create 3 sided patches. + * + * + * C1 Side 1 C2 + * +---------------+ + * | | + * | P1 P2 | + * | | + * Side 0 | | Side 2 + * | | + * | | + * | P0 P3 | + * | | + * +---------------+ + * C0 Side 3 C3 + * + * + * Each patch is constructed by first calling + * cairo_mesh_pattern_begin_patch(), then cairo_mesh_pattern_move_to() + * to specify the first point in the patch (C0). Then the sides are + * specified with calls to cairo_mesh_pattern_curve_to() and + * cairo_mesh_pattern_line_to(). + * + * The four additional control points (P0, P1, P2, P3) in a patch can + * be specified with cairo_mesh_pattern_set_control_point(). + * + * At each corner of the patch (C0, C1, C2, C3) a color may be + * specified with cairo_mesh_pattern_set_corner_color_rgb() or + * cairo_mesh_pattern_set_corner_color_rgba(). Any corner whose color + * is not explicitly specified defaults to transparent black. + * + * A Coons patch is a special case of the tensor-product patch where + * the control points are implicitly defined by the sides of the + * patch. The default value for any control point not specified is the + * implicit value for a Coons patch, i.e. if no control points are + * specified the patch is a Coons patch. + * + * A triangle is a special case of the tensor-product patch where the + * control points are implicitly defined by the sides of the patch, + * all the sides are lines and one of them has length 0, i.e. if the + * patch is specified using just 3 lines, it is a triangle. If the + * corners connected by the 0-length side have the same color, the + * patch is a Gouraud-shaded triangle. + * + * Patches may be oriented differently to the above diagram. For + * example the first point could be at the top left. The diagram only + * shows the relationship between the sides, corners and control + * points. Regardless of where the first point is located, when + * specifying colors, corner 0 will always be the first point, corner + * 1 the point between side 0 and side 1 etc. + * + * Calling cairo_mesh_pattern_end_patch() completes the current + * patch. If less than 4 sides have been defined, the first missing + * side is defined as a line from the current point to the first point + * of the patch (C0) and the other sides are degenerate lines from C0 + * to C0. The corners between the added sides will all be coincident + * with C0 of the patch and their color will be set to be the same as + * the color of C0. + * + * Additional patches may be added with additional calls to + * cairo_mesh_pattern_begin_patch()/cairo_mesh_pattern_end_patch(). + * + * + * cairo_pattern_t *pattern = cairo_pattern_create_mesh (); + * + * /* Add a Coons patch */ + * cairo_mesh_pattern_begin_patch (pattern); + * cairo_mesh_pattern_move_to (pattern, 0, 0); + * cairo_mesh_pattern_curve_to (pattern, 30, -30, 60, 30, 100, 0); + * cairo_mesh_pattern_curve_to (pattern, 60, 30, 130, 60, 100, 100); + * cairo_mesh_pattern_curve_to (pattern, 60, 70, 30, 130, 0, 100); + * cairo_mesh_pattern_curve_to (pattern, 30, 70, -30, 30, 0, 0); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); + * cairo_mesh_pattern_end_patch (pattern); + * + * /* Add a Gouraud-shaded triangle */ + * cairo_mesh_pattern_begin_patch (pattern) + * cairo_mesh_pattern_move_to (pattern, 100, 100); + * cairo_mesh_pattern_line_to (pattern, 130, 130); + * cairo_mesh_pattern_line_to (pattern, 130, 70); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); + * cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); + * cairo_mesh_pattern_end_patch (pattern) + * + * + * When two patches overlap, the last one that has been added is drawn + * over the first one. + * + * When a patch folds over itself, points are sorted depending on + * their parameter coordinates inside the patch. The v coordinate + * ranges from 0 to 1 when moving from side 3 to side 1; the u + * coordinate ranges from 0 to 1 when going from side 0 to side + * 2. Points with higher v coordinate hide points with lower v + * coordinate. When two points have the same v coordinate, the one + * with higher u coordinate is above. This means that points nearer to + * side 1 are above points nearer to side 3; when this is not + * sufficient to decide which point is above (for example when both + * points belong to side 1 or side 3) points nearer to side 2 are + * above points nearer to side 0. + * + * For a complete definition of tensor-product patches, see the PDF + * specification (ISO32000), which describes the parametrization in + * detail. + * + * Note: The coordinates are always in pattern space. For a new + * pattern, pattern space is identical to user space, but the + * relationship between the spaces can be changed with + * cairo_pattern_set_matrix(). + * + * Return value: the newly created #cairo_pattern_t if successful, or + * an error pattern in case of no memory. The caller owns the returned + * object and should call cairo_pattern_destroy() when finished with + * it. + * + * This function will always return a valid pointer, but if an error + * occurred the pattern status will be set to an error. To inspect the + * status of a pattern use cairo_pattern_status(). + * + * Since: 1.12 + **/ +cairo_pattern_t * +cairo_pattern_create_mesh (void) +{ + cairo_mesh_pattern_t *pattern; + + pattern = + _freed_pool_get (&freed_pattern_pool[CAIRO_PATTERN_TYPE_MESH]); + if (unlikely (pattern == NULL)) { + pattern = malloc (sizeof (cairo_mesh_pattern_t)); + if (unlikely (pattern == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_pattern_t *) &_cairo_pattern_nil.base; + } + } + + CAIRO_MUTEX_INITIALIZE (); + + _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_MESH); + _cairo_array_init (&pattern->patches, sizeof (cairo_mesh_patch_t)); + pattern->current_patch = NULL; + CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); + + return &pattern->base; +} + +/** + * cairo_pattern_reference: + * @pattern: a #cairo_pattern_t + * + * Increases the reference count on @pattern by one. This prevents + * @pattern from being destroyed until a matching call to + * cairo_pattern_destroy() is made. + * + * The number of references to a #cairo_pattern_t can be get using + * cairo_pattern_get_reference_count(). + * + * Return value: the referenced #cairo_pattern_t. + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_pattern_reference (cairo_pattern_t *pattern) +{ + if (pattern == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) + return pattern; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&pattern->ref_count)); + + _cairo_reference_count_inc (&pattern->ref_count); + + return pattern; +} +slim_hidden_def (cairo_pattern_reference); + +/** + * cairo_pattern_get_type: + * @pattern: a #cairo_pattern_t + * + * This function returns the type a pattern. + * See #cairo_pattern_type_t for available types. + * + * Return value: The type of @pattern. + * + * Since: 1.2 + **/ +cairo_pattern_type_t +cairo_pattern_get_type (cairo_pattern_t *pattern) +{ + return pattern->type; +} + +/** + * cairo_pattern_status: + * @pattern: a #cairo_pattern_t + * + * Checks whether an error has previously occurred for this + * pattern. + * + * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_STATUS_NO_MEMORY, + * %CAIRO_STATUS_INVALID_MATRIX, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH, + * or %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_pattern_status (cairo_pattern_t *pattern) +{ + return pattern->status; +} + +/** + * cairo_pattern_destroy: + * @pattern: a #cairo_pattern_t + * + * Decreases the reference count on @pattern by one. If the result is + * zero, then @pattern and all associated resources are freed. See + * cairo_pattern_reference(). + * + * Since: 1.0 + **/ +void +cairo_pattern_destroy (cairo_pattern_t *pattern) +{ + cairo_pattern_type_t type; + + if (pattern == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&pattern->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&pattern->ref_count)) + return; + + type = pattern->type; + _cairo_pattern_fini (pattern); + + /* maintain a small cache of freed patterns */ + if (type < ARRAY_LENGTH (freed_pattern_pool)) + _freed_pool_put (&freed_pattern_pool[type], pattern); + else + free (pattern); +} +slim_hidden_def (cairo_pattern_destroy); + +/** + * cairo_pattern_get_reference_count: + * @pattern: a #cairo_pattern_t + * + * Returns the current reference count of @pattern. + * + * Return value: the current reference count of @pattern. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.4 + **/ +unsigned int +cairo_pattern_get_reference_count (cairo_pattern_t *pattern) +{ + if (pattern == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&pattern->ref_count); +} + +/** + * cairo_pattern_get_user_data: + * @pattern: a #cairo_pattern_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @pattern using the + * specified key. If no user data has been attached with the given + * key this function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.4 + **/ +void * +cairo_pattern_get_user_data (cairo_pattern_t *pattern, + const cairo_user_data_key_t *key) +{ + return _cairo_user_data_array_get_data (&pattern->user_data, + key); +} + +/** + * cairo_pattern_set_user_data: + * @pattern: a #cairo_pattern_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the #cairo_pattern_t + * @destroy: a #cairo_destroy_func_t which will be called when the + * #cairo_t is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @pattern. To remove user data from a surface, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_set_user_data (cairo_pattern_t *pattern, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) + return pattern->status; + + return _cairo_user_data_array_set_data (&pattern->user_data, + key, user_data, destroy); +} + +/** + * cairo_mesh_pattern_begin_patch: + * @pattern: a #cairo_pattern_t + * + * Begin a patch in a mesh pattern. + * + * After calling this function, the patch shape should be defined with + * cairo_mesh_pattern_move_to(), cairo_mesh_pattern_line_to() and + * cairo_mesh_pattern_curve_to(). + * + * After defining the patch, cairo_mesh_pattern_end_patch() must be + * called before using @pattern as a source or mask. + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern already has a + * current patch, it will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_begin_patch (cairo_pattern_t *pattern) +{ + cairo_mesh_pattern_t *mesh; + cairo_status_t status; + cairo_mesh_patch_t *current_patch; + int i; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + if (unlikely (mesh->current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + status = _cairo_array_allocate (&mesh->patches, 1, (void **) ¤t_patch); + if (unlikely (status)) { + _cairo_pattern_set_error (pattern, status); + return; + } + + mesh->current_patch = current_patch; + mesh->current_side = -2; /* no current point */ + + for (i = 0; i < 4; i++) + mesh->has_control_point[i] = FALSE; + + for (i = 0; i < 4; i++) + mesh->has_color[i] = FALSE; +} + + +static void +_calc_control_point (cairo_mesh_patch_t *patch, int control_point) +{ + /* The Coons patch is a special case of the Tensor Product patch + * where the four control points are: + * + * P11 = S(1/3, 1/3) + * P12 = S(1/3, 2/3) + * P21 = S(2/3, 1/3) + * P22 = S(2/3, 2/3) + * + * where S is the gradient surface. + * + * When one or more control points has not been specified + * calculated the Coons patch control points are substituted. If + * no control points are specified the gradient will be a Coons + * patch. + * + * The equations below are defined in the ISO32000 standard. + */ + cairo_point_double_t *p[3][3]; + int cp_i, cp_j, i, j; + + cp_i = mesh_control_point_i[control_point]; + cp_j = mesh_control_point_j[control_point]; + + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + p[i][j] = &patch->points[cp_i ^ i][cp_j ^ j]; + + p[0][0]->x = (- 4 * p[1][1]->x + + 6 * (p[1][0]->x + p[0][1]->x) + - 2 * (p[1][2]->x + p[2][1]->x) + + 3 * (p[2][0]->x + p[0][2]->x) + - 1 * p[2][2]->x) * (1. / 9); + + p[0][0]->y = (- 4 * p[1][1]->y + + 6 * (p[1][0]->y + p[0][1]->y) + - 2 * (p[1][2]->y + p[2][1]->y) + + 3 * (p[2][0]->y + p[0][2]->y) + - 1 * p[2][2]->y) * (1. / 9); +} + +/** + * cairo_mesh_pattern_end_patch: + * @pattern: a #cairo_pattern_t + * + * Indicates the end of the current patch in a mesh pattern. + * + * If the current patch has less than 4 sides, it is closed with a + * straight line from the current point to the first point of the + * patch as if cairo_mesh_pattern_line_to() was used. + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current + * patch or the current patch has no current point, @pattern will be + * put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_end_patch (cairo_pattern_t *pattern) +{ + cairo_mesh_pattern_t *mesh; + cairo_mesh_patch_t *current_patch; + int i; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + current_patch = mesh->current_patch; + if (unlikely (!current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + if (unlikely (mesh->current_side == -2)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + while (mesh->current_side < 3) { + int corner_num; + + cairo_mesh_pattern_line_to (pattern, + current_patch->points[0][0].x, + current_patch->points[0][0].y); + + corner_num = mesh->current_side + 1; + if (corner_num < 4 && ! mesh->has_color[corner_num]) { + current_patch->colors[corner_num] = current_patch->colors[0]; + mesh->has_color[corner_num] = TRUE; + } + } + + for (i = 0; i < 4; i++) { + if (! mesh->has_control_point[i]) + _calc_control_point (current_patch, i); + } + + for (i = 0; i < 4; i++) { + if (! mesh->has_color[i]) + current_patch->colors[i] = *CAIRO_COLOR_TRANSPARENT; + } + + mesh->current_patch = NULL; +} + +/** + * cairo_mesh_pattern_curve_to: + * @pattern: a #cairo_pattern_t + * @x1: the X coordinate of the first control point + * @y1: the Y coordinate of the first control point + * @x2: the X coordinate of the second control point + * @y2: the Y coordinate of the second control point + * @x3: the X coordinate of the end of the curve + * @y3: the Y coordinate of the end of the curve + * + * Adds a cubic Bézier spline to the current patch from the current + * point to position (@x3, @y3) in pattern-space coordinates, using + * (@x1, @y1) and (@x2, @y2) as the control points. + * + * If the current patch has no current point before the call to + * cairo_mesh_pattern_curve_to(), this function will behave as if + * preceded by a call to cairo_mesh_pattern_move_to(@pattern, @x1, + * @y1). + * + * After this call the current point will be (@x3, @y3). + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current + * patch or the current patch already has 4 sides, @pattern will be + * put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_curve_to (cairo_pattern_t *pattern, + double x1, double y1, + double x2, double y2, + double x3, double y3) +{ + cairo_mesh_pattern_t *mesh; + int current_point, i, j; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + if (unlikely (!mesh->current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + if (unlikely (mesh->current_side == 3)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + if (mesh->current_side == -2) + cairo_mesh_pattern_move_to (pattern, x1, y1); + + assert (mesh->current_side >= -1); + assert (pattern->status == CAIRO_STATUS_SUCCESS); + + mesh->current_side++; + + current_point = 3 * mesh->current_side; + + current_point++; + i = mesh_path_point_i[current_point]; + j = mesh_path_point_j[current_point]; + mesh->current_patch->points[i][j].x = x1; + mesh->current_patch->points[i][j].y = y1; + + current_point++; + i = mesh_path_point_i[current_point]; + j = mesh_path_point_j[current_point]; + mesh->current_patch->points[i][j].x = x2; + mesh->current_patch->points[i][j].y = y2; + + current_point++; + if (current_point < 12) { + i = mesh_path_point_i[current_point]; + j = mesh_path_point_j[current_point]; + mesh->current_patch->points[i][j].x = x3; + mesh->current_patch->points[i][j].y = y3; + } +} +slim_hidden_def (cairo_mesh_pattern_curve_to); + +/** + * cairo_mesh_pattern_line_to: + * @pattern: a #cairo_pattern_t + * @x: the X coordinate of the end of the new line + * @y: the Y coordinate of the end of the new line + * + * Adds a line to the current patch from the current point to position + * (@x, @y) in pattern-space coordinates. + * + * If there is no current point before the call to + * cairo_mesh_pattern_line_to() this function will behave as + * cairo_mesh_pattern_move_to(@pattern, @x, @y). + * + * After this call the current point will be (@x, @y). + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current + * patch or the current patch already has 4 sides, @pattern will be + * put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_line_to (cairo_pattern_t *pattern, + double x, double y) +{ + cairo_mesh_pattern_t *mesh; + cairo_point_double_t last_point; + int last_point_idx, i, j; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + if (unlikely (!mesh->current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + if (unlikely (mesh->current_side == 3)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + if (mesh->current_side == -2) { + cairo_mesh_pattern_move_to (pattern, x, y); + return; + } + + last_point_idx = 3 * (mesh->current_side + 1); + i = mesh_path_point_i[last_point_idx]; + j = mesh_path_point_j[last_point_idx]; + + last_point = mesh->current_patch->points[i][j]; + + cairo_mesh_pattern_curve_to (pattern, + (2 * last_point.x + x) * (1. / 3), + (2 * last_point.y + y) * (1. / 3), + (last_point.x + 2 * x) * (1. / 3), + (last_point.y + 2 * y) * (1. / 3), + x, y); +} +slim_hidden_def (cairo_mesh_pattern_line_to); + +/** + * cairo_mesh_pattern_move_to: + * @pattern: a #cairo_pattern_t + * @x: the X coordinate of the new position + * @y: the Y coordinate of the new position + * + * Define the first point of the current patch in a mesh pattern. + * + * After this call the current point will be (@x, @y). + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @pattern has no current + * patch or the current patch already has at least one side, @pattern + * will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_move_to (cairo_pattern_t *pattern, + double x, double y) +{ + cairo_mesh_pattern_t *mesh; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + if (unlikely (!mesh->current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + if (unlikely (mesh->current_side >= 0)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + mesh->current_side = -1; + mesh->current_patch->points[0][0].x = x; + mesh->current_patch->points[0][0].y = y; +} +slim_hidden_def (cairo_mesh_pattern_move_to); + +/** + * cairo_mesh_pattern_set_control_point: + * @pattern: a #cairo_pattern_t + * @point_num: the control point to set the position for + * @x: the X coordinate of the control point + * @y: the Y coordinate of the control point + * + * Set an internal control point of the current patch. + * + * Valid values for @point_num are from 0 to 3 and identify the + * control points as explained in cairo_pattern_create_mesh(). + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @point_num is not valid, + * @pattern will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_INDEX. If @pattern has no current patch, + * @pattern will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_set_control_point (cairo_pattern_t *pattern, + unsigned int point_num, + double x, + double y) +{ + cairo_mesh_pattern_t *mesh; + int i, j; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + if (unlikely (point_num > 3)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_INDEX); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + if (unlikely (!mesh->current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + i = mesh_control_point_i[point_num]; + j = mesh_control_point_j[point_num]; + + mesh->current_patch->points[i][j].x = x; + mesh->current_patch->points[i][j].y = y; + mesh->has_control_point[point_num] = TRUE; +} + +/* make room for at least one more color stop */ +static cairo_status_t +_cairo_pattern_gradient_grow (cairo_gradient_pattern_t *pattern) +{ + cairo_gradient_stop_t *new_stops; + int old_size = pattern->stops_size; + int embedded_size = ARRAY_LENGTH (pattern->stops_embedded); + int new_size = 2 * MAX (old_size, 4); + + /* we have a local buffer at pattern->stops_embedded. try to fulfill the request + * from there. */ + if (old_size < embedded_size) { + pattern->stops = pattern->stops_embedded; + pattern->stops_size = embedded_size; + return CAIRO_STATUS_SUCCESS; + } + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + assert (pattern->n_stops <= pattern->stops_size); + + if (pattern->stops == pattern->stops_embedded) { + new_stops = _cairo_malloc_ab (new_size, sizeof (cairo_gradient_stop_t)); + if (new_stops) + memcpy (new_stops, pattern->stops, old_size * sizeof (cairo_gradient_stop_t)); + } else { + new_stops = _cairo_realloc_ab (pattern->stops, + new_size, + sizeof (cairo_gradient_stop_t)); + } + + if (unlikely (new_stops == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + pattern->stops = new_stops; + pattern->stops_size = new_size; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_mesh_pattern_set_corner_color (cairo_mesh_pattern_t *mesh, + unsigned int corner_num, + double red, double green, double blue, + double alpha) +{ + cairo_color_t *color; + + assert (mesh->current_patch); + assert (corner_num <= 3); + + color = &mesh->current_patch->colors[corner_num]; + color->red = red; + color->green = green; + color->blue = blue; + color->alpha = alpha; + + color->red_short = _cairo_color_double_to_short (red); + color->green_short = _cairo_color_double_to_short (green); + color->blue_short = _cairo_color_double_to_short (blue); + color->alpha_short = _cairo_color_double_to_short (alpha); + + mesh->has_color[corner_num] = TRUE; +} + +/** + * cairo_mesh_pattern_set_corner_color_rgb: + * @pattern: a #cairo_pattern_t + * @corner_num: the corner to set the color for + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * + * Sets the color of a corner of the current patch in a mesh pattern. + * + * The color is specified in the same way as in cairo_set_source_rgb(). + * + * Valid values for @corner_num are from 0 to 3 and identify the + * corners as explained in cairo_pattern_create_mesh(). + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @corner_num is not valid, + * @pattern will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_INDEX. If @pattern has no current patch, + * @pattern will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_set_corner_color_rgb (cairo_pattern_t *pattern, + unsigned int corner_num, + double red, double green, double blue) +{ + cairo_mesh_pattern_set_corner_color_rgba (pattern, corner_num, red, green, blue, 1.0); +} + +/** + * cairo_mesh_pattern_set_corner_color_rgba: + * @pattern: a #cairo_pattern_t + * @corner_num: the corner to set the color for + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * @alpha: alpha component of color + * + * Sets the color of a corner of the current patch in a mesh pattern. + * + * The color is specified in the same way as in cairo_set_source_rgba(). + * + * Valid values for @corner_num are from 0 to 3 and identify the + * corners as explained in cairo_pattern_create_mesh(). + * + * Note: If @pattern is not a mesh pattern then @pattern will be put + * into an error status with a status of + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. If @corner_num is not valid, + * @pattern will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_INDEX. If @pattern has no current patch, + * @pattern will be put into an error status with a status of + * %CAIRO_STATUS_INVALID_MESH_CONSTRUCTION. + * + * Since: 1.12 + **/ +void +cairo_mesh_pattern_set_corner_color_rgba (cairo_pattern_t *pattern, + unsigned int corner_num, + double red, double green, double blue, + double alpha) +{ + cairo_mesh_pattern_t *mesh; + + if (unlikely (pattern->status)) + return; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + if (unlikely (corner_num > 3)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_INDEX); + return; + } + + mesh = (cairo_mesh_pattern_t *) pattern; + if (unlikely (!mesh->current_patch)) { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION); + return; + } + + red = _cairo_restrict_value (red, 0.0, 1.0); + green = _cairo_restrict_value (green, 0.0, 1.0); + blue = _cairo_restrict_value (blue, 0.0, 1.0); + alpha = _cairo_restrict_value (alpha, 0.0, 1.0); + + _cairo_mesh_pattern_set_corner_color (mesh, corner_num, red, green, blue, alpha); +} +slim_hidden_def (cairo_mesh_pattern_set_corner_color_rgba); + +static void +_cairo_pattern_add_color_stop (cairo_gradient_pattern_t *pattern, + double offset, + double red, + double green, + double blue, + double alpha) +{ + cairo_gradient_stop_t *stops; + unsigned int i; + + if (pattern->n_stops >= pattern->stops_size) { + cairo_status_t status = _cairo_pattern_gradient_grow (pattern); + if (unlikely (status)) { + status = _cairo_pattern_set_error (&pattern->base, status); + return; + } + } + + stops = pattern->stops; + + for (i = 0; i < pattern->n_stops; i++) + { + if (offset < stops[i].offset) + { + memmove (&stops[i + 1], &stops[i], + sizeof (cairo_gradient_stop_t) * (pattern->n_stops - i)); + + break; + } + } + + stops[i].offset = offset; + + stops[i].color.red = red; + stops[i].color.green = green; + stops[i].color.blue = blue; + stops[i].color.alpha = alpha; + + stops[i].color.red_short = _cairo_color_double_to_short (red); + stops[i].color.green_short = _cairo_color_double_to_short (green); + stops[i].color.blue_short = _cairo_color_double_to_short (blue); + stops[i].color.alpha_short = _cairo_color_double_to_short (alpha); + + pattern->n_stops++; +} + +/** + * cairo_pattern_add_color_stop_rgb: + * @pattern: a #cairo_pattern_t + * @offset: an offset in the range [0.0 .. 1.0] + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * + * Adds an opaque color stop to a gradient pattern. The offset + * specifies the location along the gradient's control vector. For + * example, a linear gradient's control vector is from (x0,y0) to + * (x1,y1) while a radial gradient's control vector is from any point + * on the start circle to the corresponding point on the end circle. + * + * The color is specified in the same way as in cairo_set_source_rgb(). + * + * If two (or more) stops are specified with identical offset values, + * they will be sorted according to the order in which the stops are + * added, (stops added earlier will compare less than stops added + * later). This can be useful for reliably making sharp color + * transitions instead of the typical blend. + * + * + * Note: If the pattern is not a gradient pattern, (eg. a linear or + * radial pattern), then the pattern will be put into an error status + * with a status of %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. + * + * Since: 1.0 + **/ +void +cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, + double offset, + double red, + double green, + double blue) +{ + cairo_pattern_add_color_stop_rgba (pattern, offset, red, green, blue, 1.0); +} + +/** + * cairo_pattern_add_color_stop_rgba: + * @pattern: a #cairo_pattern_t + * @offset: an offset in the range [0.0 .. 1.0] + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * @alpha: alpha component of color + * + * Adds a translucent color stop to a gradient pattern. The offset + * specifies the location along the gradient's control vector. For + * example, a linear gradient's control vector is from (x0,y0) to + * (x1,y1) while a radial gradient's control vector is from any point + * on the start circle to the corresponding point on the end circle. + * + * The color is specified in the same way as in cairo_set_source_rgba(). + * + * If two (or more) stops are specified with identical offset values, + * they will be sorted according to the order in which the stops are + * added, (stops added earlier will compare less than stops added + * later). This can be useful for reliably making sharp color + * transitions instead of the typical blend. + * + * Note: If the pattern is not a gradient pattern, (eg. a linear or + * radial pattern), then the pattern will be put into an error status + * with a status of %CAIRO_STATUS_PATTERN_TYPE_MISMATCH. + * + * Since: 1.0 + **/ +void +cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, + double offset, + double red, + double green, + double blue, + double alpha) +{ + if (pattern->status) + return; + + if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && + pattern->type != CAIRO_PATTERN_TYPE_RADIAL) + { + _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + return; + } + + offset = _cairo_restrict_value (offset, 0.0, 1.0); + red = _cairo_restrict_value (red, 0.0, 1.0); + green = _cairo_restrict_value (green, 0.0, 1.0); + blue = _cairo_restrict_value (blue, 0.0, 1.0); + alpha = _cairo_restrict_value (alpha, 0.0, 1.0); + + _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern, + offset, red, green, blue, alpha); +} +slim_hidden_def (cairo_pattern_add_color_stop_rgba); + +/** + * cairo_pattern_set_matrix: + * @pattern: a #cairo_pattern_t + * @matrix: a #cairo_matrix_t + * + * Sets the pattern's transformation matrix to @matrix. This matrix is + * a transformation from user space to pattern space. + * + * When a pattern is first created it always has the identity matrix + * for its transformation matrix, which means that pattern space is + * initially identical to user space. + * + * Important: Please note that the direction of this transformation + * matrix is from user space to pattern space. This means that if you + * imagine the flow from a pattern to user space (and on to device + * space), then coordinates in that flow will be transformed by the + * inverse of the pattern matrix. + * + * For example, if you want to make a pattern appear twice as large as + * it does by default the correct code to use is: + * + * + * cairo_matrix_init_scale (&matrix, 0.5, 0.5); + * cairo_pattern_set_matrix (pattern, &matrix); + * + * + * Meanwhile, using values of 2.0 rather than 0.5 in the code above + * would cause the pattern to appear at half of its default size. + * + * Also, please note the discussion of the user-space locking + * semantics of cairo_set_source(). + * + * Since: 1.0 + **/ +void +cairo_pattern_set_matrix (cairo_pattern_t *pattern, + const cairo_matrix_t *matrix) +{ + cairo_matrix_t inverse; + cairo_status_t status; + + if (pattern->status) + return; + + if (memcmp (&pattern->matrix, matrix, sizeof (cairo_matrix_t)) == 0) + return; + + pattern->matrix = *matrix; + _cairo_pattern_notify_observers (pattern, CAIRO_PATTERN_NOTIFY_MATRIX); + + inverse = *matrix; + status = cairo_matrix_invert (&inverse); + if (unlikely (status)) + status = _cairo_pattern_set_error (pattern, status); +} +slim_hidden_def (cairo_pattern_set_matrix); + +/** + * cairo_pattern_get_matrix: + * @pattern: a #cairo_pattern_t + * @matrix: return value for the matrix + * + * Stores the pattern's transformation matrix into @matrix. + * + * Since: 1.0 + **/ +void +cairo_pattern_get_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix) +{ + *matrix = pattern->matrix; +} + +/** + * cairo_pattern_set_filter: + * @pattern: a #cairo_pattern_t + * @filter: a #cairo_filter_t describing the filter to use for resizing + * the pattern + * + * Sets the filter to be used for resizing when using this pattern. + * See #cairo_filter_t for details on each filter. + * + * * Note that you might want to control filtering even when you do not + * have an explicit #cairo_pattern_t object, (for example when using + * cairo_set_source_surface()). In these cases, it is convenient to + * use cairo_get_source() to get access to the pattern that cairo + * creates implicitly. For example: + * + * + * cairo_set_source_surface (cr, image, x, y); + * cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + * + * + * Since: 1.0 + **/ +void +cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter) +{ + if (pattern->status) + return; + + pattern->filter = filter; + _cairo_pattern_notify_observers (pattern, CAIRO_PATTERN_NOTIFY_FILTER); +} + +/** + * cairo_pattern_get_filter: + * @pattern: a #cairo_pattern_t + * + * Gets the current filter for a pattern. See #cairo_filter_t + * for details on each filter. + * + * Return value: the current filter used for resizing the pattern. + * + * Since: 1.0 + **/ +cairo_filter_t +cairo_pattern_get_filter (cairo_pattern_t *pattern) +{ + return pattern->filter; +} + +/** + * cairo_pattern_set_extend: + * @pattern: a #cairo_pattern_t + * @extend: a #cairo_extend_t describing how the area outside of the + * pattern will be drawn + * + * Sets the mode to be used for drawing outside the area of a pattern. + * See #cairo_extend_t for details on the semantics of each extend + * strategy. + * + * The default extend mode is %CAIRO_EXTEND_NONE for surface patterns + * and %CAIRO_EXTEND_PAD for gradient patterns. + * + * Since: 1.0 + **/ +void +cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend) +{ + if (pattern->status) + return; + + pattern->extend = extend; + _cairo_pattern_notify_observers (pattern, CAIRO_PATTERN_NOTIFY_EXTEND); +} + +/** + * cairo_pattern_get_extend: + * @pattern: a #cairo_pattern_t + * + * Gets the current extend mode for a pattern. See #cairo_extend_t + * for details on the semantics of each extend strategy. + * + * Return value: the current extend strategy used for drawing the + * pattern. + * + * Since: 1.0 + **/ +cairo_extend_t +cairo_pattern_get_extend (cairo_pattern_t *pattern) +{ + return pattern->extend; +} +slim_hidden_def (cairo_pattern_get_extend); + +void +_cairo_pattern_pretransform (cairo_pattern_t *pattern, + const cairo_matrix_t *ctm) +{ + if (pattern->status) + return; + + cairo_matrix_multiply (&pattern->matrix, &pattern->matrix, ctm); +} + +void +_cairo_pattern_transform (cairo_pattern_t *pattern, + const cairo_matrix_t *ctm_inverse) +{ + if (pattern->status) + return; + + cairo_matrix_multiply (&pattern->matrix, ctm_inverse, &pattern->matrix); +} + +static cairo_bool_t +_linear_pattern_is_degenerate (const cairo_linear_pattern_t *linear) +{ + return fabs (linear->pd1.x - linear->pd2.x) < DBL_EPSILON && + fabs (linear->pd1.y - linear->pd2.y) < DBL_EPSILON; +} + +static cairo_bool_t +_radial_pattern_is_degenerate (const cairo_radial_pattern_t *radial) +{ + /* A radial pattern is considered degenerate if it can be + * represented as a solid or clear pattern. This corresponds to + * one of the two cases: + * + * 1) The radii are both very small: + * |dr| < DBL_EPSILON && min (r0, r1) < DBL_EPSILON + * + * 2) The two circles have about the same radius and are very + * close to each other (approximately a cylinder gradient that + * doesn't move with the parameter): + * |dr| < DBL_EPSILON && max (|dx|, |dy|) < 2 * DBL_EPSILON + * + * These checks are consistent with the assumptions used in + * _cairo_radial_pattern_box_to_parameter (). + */ + + return fabs (radial->cd1.radius - radial->cd2.radius) < DBL_EPSILON && + (MIN (radial->cd1.radius, radial->cd2.radius) < DBL_EPSILON || + MAX (fabs (radial->cd1.center.x - radial->cd2.center.x), + fabs (radial->cd1.center.y - radial->cd2.center.y)) < 2 * DBL_EPSILON); +} + +static void +_cairo_linear_pattern_box_to_parameter (const cairo_linear_pattern_t *linear, + double x0, double y0, + double x1, double y1, + double range[2]) +{ + double t0, tdx, tdy; + double p1x, p1y, pdx, pdy, invsqnorm; + + assert (! _linear_pattern_is_degenerate (linear)); + + /* + * Linear gradients are othrogonal to the line passing through + * their extremes. Because of convexity, the parameter range can + * be computed as the convex hull (one the real line) of the + * parameter values of the 4 corners of the box. + * + * The parameter value t for a point (x,y) can be computed as: + * + * t = (p2 - p1) . (x,y) / |p2 - p1|^2 + * + * t0 is the t value for the top left corner + * tdx is the difference between left and right corners + * tdy is the difference between top and bottom corners + */ + + p1x = linear->pd1.x; + p1y = linear->pd1.y; + pdx = linear->pd2.x - p1x; + pdy = linear->pd2.y - p1y; + invsqnorm = 1.0 / (pdx * pdx + pdy * pdy); + pdx *= invsqnorm; + pdy *= invsqnorm; + + t0 = (x0 - p1x) * pdx + (y0 - p1y) * pdy; + tdx = (x1 - x0) * pdx; + tdy = (y1 - y0) * pdy; + + /* + * Because of the linearity of the t value, tdx can simply be + * added the t0 to move along the top edge. After this, range[0] + * and range[1] represent the parameter range for the top edge, so + * extending it to include the whole box simply requires adding + * tdy to the correct extreme. + */ + + range[0] = range[1] = t0; + if (tdx < 0) + range[0] += tdx; + else + range[1] += tdx; + + if (tdy < 0) + range[0] += tdy; + else + range[1] += tdy; +} + +static cairo_bool_t +_extend_range (double range[2], double value, cairo_bool_t valid) +{ + if (!valid) + range[0] = range[1] = value; + else if (value < range[0]) + range[0] = value; + else if (value > range[1]) + range[1] = value; + + return TRUE; +} + +/* + * _cairo_radial_pattern_focus_is_inside: + * + * Returns %TRUE if and only if the focus point exists and is + * contained in one of the two extreme circles. This condition is + * equivalent to one of the two extreme circles being completely + * contained in the other one. + * + * Note: if the focus is on the border of one of the two circles (in + * which case the circles are tangent in the focus point), it is not + * considered as contained in the circle, hence this function returns + * %FALSE. + * + */ +cairo_bool_t +_cairo_radial_pattern_focus_is_inside (const cairo_radial_pattern_t *radial) +{ + double cx, cy, cr, dx, dy, dr; + + cx = radial->cd1.center.x; + cy = radial->cd1.center.y; + cr = radial->cd1.radius; + dx = radial->cd2.center.x - cx; + dy = radial->cd2.center.y - cy; + dr = radial->cd2.radius - cr; + + return dx*dx + dy*dy < dr*dr; +} + +static void +_cairo_radial_pattern_box_to_parameter (const cairo_radial_pattern_t *radial, + double x0, double y0, + double x1, double y1, + double tolerance, + double range[2]) +{ + double cx, cy, cr, dx, dy, dr; + double a, x_focus, y_focus; + double mindr, minx, miny, maxx, maxy; + cairo_bool_t valid; + + assert (! _radial_pattern_is_degenerate (radial)); + assert (x0 < x1); + assert (y0 < y1); + + tolerance = MAX (tolerance, DBL_EPSILON); + + range[0] = range[1] = 0; + valid = FALSE; + + x_focus = y_focus = 0; /* silence gcc */ + + cx = radial->cd1.center.x; + cy = radial->cd1.center.y; + cr = radial->cd1.radius; + dx = radial->cd2.center.x - cx; + dy = radial->cd2.center.y - cy; + dr = radial->cd2.radius - cr; + + /* translate by -(cx, cy) to simplify computations */ + x0 -= cx; + y0 -= cy; + x1 -= cx; + y1 -= cy; + + /* enlarge boundaries slightly to avoid rounding problems in the + * parameter range computation */ + x0 -= DBL_EPSILON; + y0 -= DBL_EPSILON; + x1 += DBL_EPSILON; + y1 += DBL_EPSILON; + + /* enlarge boundaries even more to avoid rounding problems when + * testing if a point belongs to the box */ + minx = x0 - DBL_EPSILON; + miny = y0 - DBL_EPSILON; + maxx = x1 + DBL_EPSILON; + maxy = y1 + DBL_EPSILON; + + /* we dont' allow negative radiuses, so we will be checking that + * t*dr >= mindr to consider t valid */ + mindr = -(cr + DBL_EPSILON); + + /* + * After the previous transformations, the start circle is + * centered in the origin and has radius cr. A 1-unit change in + * the t parameter corresponds to dx,dy,dr changes in the x,y,r of + * the circle (center coordinates, radius). + * + * To compute the minimum range needed to correctly draw the + * pattern, we start with an empty range and extend it to include + * the circles touching the bounding box or within it. + */ + + /* + * Focus, the point where the circle has radius == 0. + * + * r = cr + t * dr = 0 + * t = -cr / dr + * + * If the radius is constant (dr == 0) there is no focus (the + * gradient represents a cylinder instead of a cone). + */ + if (fabs (dr) >= DBL_EPSILON) { + double t_focus; + + t_focus = -cr / dr; + x_focus = t_focus * dx; + y_focus = t_focus * dy; + if (minx <= x_focus && x_focus <= maxx && + miny <= y_focus && y_focus <= maxy) + { + valid = _extend_range (range, t_focus, valid); + } + } + + /* + * Circles externally tangent to box edges. + * + * All circles have center in (dx, dy) * t + * + * If the circle is tangent to the line defined by the edge of the + * box, then at least one of the following holds true: + * + * (dx*t) + (cr + dr*t) == x0 (left edge) + * (dx*t) - (cr + dr*t) == x1 (right edge) + * (dy*t) + (cr + dr*t) == y0 (top edge) + * (dy*t) - (cr + dr*t) == y1 (bottom edge) + * + * The solution is only valid if the tangent point is actually on + * the edge, i.e. if its y coordinate is in [y0,y1] for left/right + * edges and if its x coordinate is in [x0,x1] for top/bottom + * edges. + * + * For the first equation: + * + * (dx + dr) * t = x0 - cr + * t = (x0 - cr) / (dx + dr) + * y = dy * t + * + * in the code this becomes: + * + * t_edge = (num) / (den) + * v = (delta) * t_edge + * + * If the denominator in t is 0, the pattern is tangent to a line + * parallel to the edge under examination. The corner-case where + * the boundary line is the same as the edge is handled by the + * focus point case and/or by the a==0 case. + */ +#define T_EDGE(num,den,delta,lower,upper) \ + if (fabs (den) >= DBL_EPSILON) { \ + double t_edge, v; \ + \ + t_edge = (num) / (den); \ + v = t_edge * (delta); \ + if (t_edge * dr >= mindr && (lower) <= v && v <= (upper)) \ + valid = _extend_range (range, t_edge, valid); \ + } + + /* circles tangent (externally) to left/right/top/bottom edge */ + T_EDGE (x0 - cr, dx + dr, dy, miny, maxy); + T_EDGE (x1 + cr, dx - dr, dy, miny, maxy); + T_EDGE (y0 - cr, dy + dr, dx, minx, maxx); + T_EDGE (y1 + cr, dy - dr, dx, minx, maxx); + +#undef T_EDGE + + /* + * Circles passing through a corner. + * + * A circle passing through the point (x,y) satisfies: + * + * (x-t*dx)^2 + (y-t*dy)^2 == (cr + t*dr)^2 + * + * If we set: + * a = dx^2 + dy^2 - dr^2 + * b = x*dx + y*dy + cr*dr + * c = x^2 + y^2 - cr^2 + * we have: + * a*t^2 - 2*b*t + c == 0 + */ + a = dx * dx + dy * dy - dr * dr; + if (fabs (a) < DBL_EPSILON * DBL_EPSILON) { + double b, maxd2; + + /* Ensure that gradients with both a and dr small are + * considered degenerate. + * The floating point version of the degeneracy test implemented + * in _radial_pattern_is_degenerate() is: + * + * 1) The circles are practically the same size: + * |dr| < DBL_EPSILON + * AND + * 2a) The circles are both very small: + * min (r0, r1) < DBL_EPSILON + * OR + * 2b) The circles are very close to each other: + * max (|dx|, |dy|) < 2 * DBL_EPSILON + * + * Assuming that the gradient is not degenerate, we want to + * show that |a| < DBL_EPSILON^2 implies |dr| >= DBL_EPSILON. + * + * If the gradient is not degenerate yet it has |dr| < + * DBL_EPSILON, (2b) is false, thus: + * + * max (|dx|, |dy|) >= 2*DBL_EPSILON + * which implies: + * 4*DBL_EPSILON^2 <= max (|dx|, |dy|)^2 <= dx^2 + dy^2 + * + * From the definition of a, we get: + * a = dx^2 + dy^2 - dr^2 < DBL_EPSILON^2 + * dx^2 + dy^2 - DBL_EPSILON^2 < dr^2 + * 3*DBL_EPSILON^2 < dr^2 + * + * which is inconsistent with the hypotheses, thus |dr| < + * DBL_EPSILON is false or the gradient is degenerate. + */ + assert (fabs (dr) >= DBL_EPSILON); + + /* + * If a == 0, all the circles are tangent to a line in the + * focus point. If this line is within the box extents, we + * should add the circle with infinite radius, but this would + * make the range unbounded, so we add the smallest circle whose + * distance to the desired (degenerate) circle within the + * bounding box does not exceed tolerance. + * + * The equation of the line is b==0, i.e.: + * x*dx + y*dy + cr*dr == 0 + * + * We compute the intersection of the line with the box and + * keep the intersection with maximum square distance (maxd2) + * from the focus point. + * + * In the code the intersection is represented in another + * coordinate system, whose origin is the focus point and + * which has a u,v axes, which are respectively orthogonal and + * parallel to the edge being intersected. + * + * The intersection is valid only if it belongs to the box, + * otherwise it is ignored. + * + * For example: + * + * y = y0 + * x*dx + y0*dy + cr*dr == 0 + * x = -(y0*dy + cr*dr) / dx + * + * which in (u,v) is: + * u = y0 - y_focus + * v = -(y0*dy + cr*dr) / dx - x_focus + * + * In the code: + * u = (edge) - (u_origin) + * v = -((edge) * (delta) + cr*dr) / (den) - v_focus + */ +#define T_EDGE(edge,delta,den,lower,upper,u_origin,v_origin) \ + if (fabs (den) >= DBL_EPSILON) { \ + double v; \ + \ + v = -((edge) * (delta) + cr * dr) / (den); \ + if ((lower) <= v && v <= (upper)) { \ + double u, d2; \ + \ + u = (edge) - (u_origin); \ + v -= (v_origin); \ + d2 = u*u + v*v; \ + if (maxd2 < d2) \ + maxd2 = d2; \ + } \ + } + + maxd2 = 0; + + /* degenerate circles (lines) passing through each edge */ + T_EDGE (y0, dy, dx, minx, maxx, y_focus, x_focus); + T_EDGE (y1, dy, dx, minx, maxx, y_focus, x_focus); + T_EDGE (x0, dx, dy, miny, maxy, x_focus, y_focus); + T_EDGE (x1, dx, dy, miny, maxy, x_focus, y_focus); + +#undef T_EDGE + + /* + * The limit circle can be transformed rigidly to the y=0 line + * and the circles tangent to it in (0,0) are: + * + * x^2 + (y-r)^2 = r^2 <=> x^2 + y^2 - 2*y*r = 0 + * + * y is the distance from the line, in our case tolerance; + * x is the distance along the line, i.e. sqrt(maxd2), + * so: + * + * r = cr + dr * t = (maxd2 + tolerance^2) / (2*tolerance) + * t = (r - cr) / dr = + * (maxd2 + tolerance^2 - 2*tolerance*cr) / (2*tolerance*dr) + */ + if (maxd2 > 0) { + double t_limit = maxd2 + tolerance*tolerance - 2*tolerance*cr; + t_limit /= 2 * tolerance * dr; + valid = _extend_range (range, t_limit, valid); + } + + /* + * Nondegenerate, nonlimit circles passing through the corners. + * + * a == 0 && a*t^2 - 2*b*t + c == 0 + * + * t = c / (2*b) + * + * The b == 0 case has just been handled, so we only have to + * compute this if b != 0. + */ +#define T_CORNER(x,y) \ + b = (x) * dx + (y) * dy + cr * dr; \ + if (fabs (b) >= DBL_EPSILON) { \ + double t_corner; \ + double x2 = (x) * (x); \ + double y2 = (y) * (y); \ + double cr2 = (cr) * (cr); \ + double c = x2 + y2 - cr2; \ + \ + t_corner = 0.5 * c / b; \ + if (t_corner * dr >= mindr) \ + valid = _extend_range (range, t_corner, valid); \ + } + + /* circles touching each corner */ + T_CORNER (x0, y0); + T_CORNER (x0, y1); + T_CORNER (x1, y0); + T_CORNER (x1, y1); + +#undef T_CORNER + } else { + double inva, b, c, d; + + inva = 1 / a; + + /* + * Nondegenerate, nonlimit circles passing through the corners. + * + * a != 0 && a*t^2 - 2*b*t + c == 0 + * + * t = (b +- sqrt (b*b - a*c)) / a + * + * If the argument of sqrt() is negative, then no circle + * passes through the corner. + */ +#define T_CORNER(x,y) \ + b = (x) * dx + (y) * dy + cr * dr; \ + c = (x) * (x) + (y) * (y) - cr * cr; \ + d = b * b - a * c; \ + if (d >= 0) { \ + double t_corner; \ + \ + d = sqrt (d); \ + t_corner = (b + d) * inva; \ + if (t_corner * dr >= mindr) \ + valid = _extend_range (range, t_corner, valid); \ + t_corner = (b - d) * inva; \ + if (t_corner * dr >= mindr) \ + valid = _extend_range (range, t_corner, valid); \ + } + + /* circles touching each corner */ + T_CORNER (x0, y0); + T_CORNER (x0, y1); + T_CORNER (x1, y0); + T_CORNER (x1, y1); + +#undef T_CORNER + } +} + +/** + * _cairo_gradient_pattern_box_to_parameter: + * + * Compute a interpolation range sufficient to draw (within the given + * tolerance) the gradient in the given box getting the same result as + * using the (-inf, +inf) range. + * + * Assumes that the pattern is not degenerate. This can be guaranteed + * by simplifying it to a solid clear if _cairo_pattern_is_clear or to + * a solid color if _cairo_gradient_pattern_is_solid. + * + * The range isn't guaranteed to be minimal, but it tries to. + **/ +void +_cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient, + double x0, double y0, + double x1, double y1, + double tolerance, + double out_range[2]) +{ + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + _cairo_linear_pattern_box_to_parameter ((cairo_linear_pattern_t *) gradient, + x0, y0, x1, y1, out_range); + } else { + _cairo_radial_pattern_box_to_parameter ((cairo_radial_pattern_t *) gradient, + x0, y0, x1, y1, tolerance, out_range); + } +} + +/** + * _cairo_gradient_pattern_interpolate: + * + * Interpolate between the start and end objects of linear or radial + * gradients. The interpolated object is stored in out_circle, with + * the radius being zero in the linear gradient case. + **/ +void +_cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient, + double t, + cairo_circle_double_t *out_circle) +{ + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + +#define lerp(a,b) (a)*(1-t) + (b)*t + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; + out_circle->center.x = lerp (linear->pd1.x, linear->pd2.x); + out_circle->center.y = lerp (linear->pd1.y, linear->pd2.y); + out_circle->radius = 0; + } else { + cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient; + out_circle->center.x = lerp (radial->cd1.center.x, radial->cd2.center.x); + out_circle->center.y = lerp (radial->cd1.center.y, radial->cd2.center.y); + out_circle->radius = lerp (radial->cd1.radius , radial->cd2.radius); + } + +#undef lerp +} + + +/** + * _cairo_gradient_pattern_fit_to_range: + * + * Scale the extremes of a gradient to guarantee that the coordinates + * and their deltas are within the range (-max_value, max_value). The + * new extremes are stored in out_circle. + * + * The pattern matrix is scaled to guarantee that the aspect of the + * gradient is the same and the result is stored in out_matrix. + * + **/ +void +_cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient, + double max_value, + cairo_matrix_t *out_matrix, + cairo_circle_double_t out_circle[2]) +{ + double dim; + + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; + + out_circle[0].center = linear->pd1; + out_circle[0].radius = 0; + out_circle[1].center = linear->pd2; + out_circle[1].radius = 0; + + dim = fabs (linear->pd1.x); + dim = MAX (dim, fabs (linear->pd1.y)); + dim = MAX (dim, fabs (linear->pd2.x)); + dim = MAX (dim, fabs (linear->pd2.y)); + dim = MAX (dim, fabs (linear->pd1.x - linear->pd2.x)); + dim = MAX (dim, fabs (linear->pd1.y - linear->pd2.y)); + } else { + cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient; + + out_circle[0] = radial->cd1; + out_circle[1] = radial->cd2; + + dim = fabs (radial->cd1.center.x); + dim = MAX (dim, fabs (radial->cd1.center.y)); + dim = MAX (dim, fabs (radial->cd1.radius)); + dim = MAX (dim, fabs (radial->cd2.center.x)); + dim = MAX (dim, fabs (radial->cd2.center.y)); + dim = MAX (dim, fabs (radial->cd2.radius)); + dim = MAX (dim, fabs (radial->cd1.center.x - radial->cd2.center.x)); + dim = MAX (dim, fabs (radial->cd1.center.y - radial->cd2.center.y)); + dim = MAX (dim, fabs (radial->cd1.radius - radial->cd2.radius)); + } + + if (unlikely (dim > max_value)) { + cairo_matrix_t scale; + + dim = max_value / dim; + + out_circle[0].center.x *= dim; + out_circle[0].center.y *= dim; + out_circle[0].radius *= dim; + out_circle[1].center.x *= dim; + out_circle[1].center.y *= dim; + out_circle[1].radius *= dim; + + cairo_matrix_init_scale (&scale, dim, dim); + cairo_matrix_multiply (out_matrix, &gradient->base.matrix, &scale); + } else { + *out_matrix = gradient->base.matrix; + } +} + +static cairo_bool_t +_gradient_is_clear (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents) +{ + unsigned int i; + + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + + if (gradient->n_stops == 0 || + (gradient->base.extend == CAIRO_EXTEND_NONE && + gradient->stops[0].offset == gradient->stops[gradient->n_stops - 1].offset)) + return TRUE; + + if (gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL) { + /* degenerate radial gradients are clear */ + if (_radial_pattern_is_degenerate ((cairo_radial_pattern_t *) gradient)) + return TRUE; + } else if (gradient->base.extend == CAIRO_EXTEND_NONE) { + /* EXTEND_NONE degenerate linear gradients are clear */ + if (_linear_pattern_is_degenerate ((cairo_linear_pattern_t *) gradient)) + return TRUE; + } + + /* Check if the extents intersect the drawn part of the pattern. */ + if (extents != NULL && + (gradient->base.extend == CAIRO_EXTEND_NONE || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL)) + { + double t[2]; + + _cairo_gradient_pattern_box_to_parameter (gradient, + extents->x, + extents->y, + extents->x + extents->width, + extents->y + extents->height, + DBL_EPSILON, + t); + + if (gradient->base.extend == CAIRO_EXTEND_NONE && + (t[0] >= gradient->stops[gradient->n_stops - 1].offset || + t[1] <= gradient->stops[0].offset)) + { + return TRUE; + } + + if (t[0] == t[1]) + return TRUE; + } + + for (i = 0; i < gradient->n_stops; i++) + if (! CAIRO_COLOR_IS_CLEAR (&gradient->stops[i].color)) + return FALSE; + + return TRUE; +} + +static void +_gradient_color_average (const cairo_gradient_pattern_t *gradient, + cairo_color_t *color) +{ + double delta0, delta1; + double r, g, b, a; + unsigned int i, start = 1, end; + + assert (gradient->n_stops > 0); + assert (gradient->base.extend != CAIRO_EXTEND_NONE); + + if (gradient->n_stops == 1) { + _cairo_color_init_rgba (color, + gradient->stops[0].color.red, + gradient->stops[0].color.green, + gradient->stops[0].color.blue, + gradient->stops[0].color.alpha); + return; + } + + end = gradient->n_stops - 1; + + switch (gradient->base.extend) { + case CAIRO_EXTEND_REPEAT: + /* + * Sa, Sb and Sy, Sz are the first two and last two stops respectively. + * The weight of the first and last stop can be computed as the area of + * the following triangles (taken with height 1, since the whole [0-1] + * will have total weight 1 this way): b*h/2 + * + * + + + * / |\ / | \ + * / | \ / | \ + * / | \ / | \ + * ~~~~~+---+---+---+~~~~~~~+-------+---+---+~~~~~ + * -1+Sz 0 Sa Sb Sy Sz 1 1+Sa + * + * For the first stop: (Sb-(-1+Sz)/2 = (1+Sb-Sz)/2 + * For the last stop: ((1+Sa)-Sy)/2 = (1+Sa-Sy)/2 + * Halving the result is done after summing up all the areas. + */ + delta0 = 1.0 + gradient->stops[1].offset - gradient->stops[end].offset; + delta1 = 1.0 + gradient->stops[0].offset - gradient->stops[end-1].offset; + break; + + case CAIRO_EXTEND_REFLECT: + /* + * Sa, Sb and Sy, Sz are the first two and last two stops respectively. + * The weight of the first and last stop can be computed as the area of + * the following trapezoids (taken with height 1, since the whole [0-1] + * will have total weight 1 this way): (b+B)*h/2 + * + * +-------+ +---+ + * | |\ / | | + * | | \ / | | + * | | \ / | | + * +-------+---+~~~~~~~+-------+---+ + * 0 Sa Sb Sy Sz 1 + * + * For the first stop: (Sa+Sb)/2 + * For the last stop: ((1-Sz) + (1-Sy))/2 = (2-Sy-Sz)/2 + * Halving the result is done after summing up all the areas. + */ + delta0 = gradient->stops[0].offset + gradient->stops[1].offset; + delta1 = 2.0 - gradient->stops[end-1].offset - gradient->stops[end].offset; + break; + + case CAIRO_EXTEND_PAD: + /* PAD is computed as the average of the first and last stop: + * - take both of them with weight 1 (they will be halved + * after the whole sum has been computed). + * - avoid summing any of the inner stops. + */ + delta0 = delta1 = 1.0; + start = end; + break; + + case CAIRO_EXTEND_NONE: + default: + ASSERT_NOT_REACHED; + _cairo_color_init_rgba (color, 0, 0, 0, 0); + return; + } + + r = delta0 * gradient->stops[0].color.red; + g = delta0 * gradient->stops[0].color.green; + b = delta0 * gradient->stops[0].color.blue; + a = delta0 * gradient->stops[0].color.alpha; + + for (i = start; i < end; ++i) { + /* Inner stops weight is the same as the area of the triangle they influence + * (which goes from the stop before to the stop after), again with height 1 + * since the whole must sum up to 1: b*h/2 + * Halving is done after the whole sum has been computed. + */ + double delta = gradient->stops[i+1].offset - gradient->stops[i-1].offset; + r += delta * gradient->stops[i].color.red; + g += delta * gradient->stops[i].color.green; + b += delta * gradient->stops[i].color.blue; + a += delta * gradient->stops[i].color.alpha; + } + + r += delta1 * gradient->stops[end].color.red; + g += delta1 * gradient->stops[end].color.green; + b += delta1 * gradient->stops[end].color.blue; + a += delta1 * gradient->stops[end].color.alpha; + + _cairo_color_init_rgba (color, r * .5, g * .5, b * .5, a * .5); +} + +/** + * _cairo_pattern_alpha_range: + * + * Convenience function to determine the minimum and maximum alpha in + * the drawn part of a pattern (i.e. ignoring clear parts caused by + * extend modes and/or pattern shape). + * + * If not NULL, out_min and out_max will be set respectively to the + * minimum and maximum alpha value of the pattern. + **/ +void +_cairo_pattern_alpha_range (const cairo_pattern_t *pattern, + double *out_min, + double *out_max) +{ + double alpha_min, alpha_max; + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: { + const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; + alpha_min = alpha_max = solid->color.alpha; + break; + } + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: { + const cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern; + unsigned int i; + + assert (gradient->n_stops >= 1); + + alpha_min = alpha_max = gradient->stops[0].color.alpha; + for (i = 1; i < gradient->n_stops; i++) { + if (alpha_min > gradient->stops[i].color.alpha) + alpha_min = gradient->stops[i].color.alpha; + else if (alpha_max < gradient->stops[i].color.alpha) + alpha_max = gradient->stops[i].color.alpha; + } + + break; + } + + case CAIRO_PATTERN_TYPE_MESH: { + const cairo_mesh_pattern_t *mesh = (const cairo_mesh_pattern_t *) pattern; + const cairo_mesh_patch_t *patch = _cairo_array_index_const (&mesh->patches, 0); + unsigned int i, j, n = _cairo_array_num_elements (&mesh->patches); + + assert (n >= 1); + + alpha_min = alpha_max = patch[0].colors[0].alpha; + for (i = 0; i < n; i++) { + for (j = 0; j < 4; j++) { + if (patch[i].colors[j].alpha < alpha_min) + alpha_min = patch[i].colors[j].alpha; + else if (patch[i].colors[j].alpha > alpha_max) + alpha_max = patch[i].colors[j].alpha; + } + } + + break; + } + + default: + ASSERT_NOT_REACHED; + /* fall through */ + + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + alpha_min = 0; + alpha_max = 1; + break; + } + + if (out_min) + *out_min = alpha_min; + if (out_max) + *out_max = alpha_max; +} + +/** + * _cairo_mesh_pattern_coord_box: + * + * Convenience function to determine the range of the coordinates of + * the points used to define the patches of the mesh. + * + * This is guaranteed to contain the pattern extents, but might not be + * tight, just like a Bezier curve is always inside the convex hull of + * the control points. + * + * This function cannot be used while the mesh is being constructed. + * + * The function returns TRUE and sets the output parametes to define + * the coodrinate range if the mesh pattern contains at least one + * patch, otherwise it returns FALSE. + **/ +cairo_bool_t +_cairo_mesh_pattern_coord_box (const cairo_mesh_pattern_t *mesh, + double *out_xmin, + double *out_ymin, + double *out_xmax, + double *out_ymax) +{ + const cairo_mesh_patch_t *patch; + unsigned int num_patches, i, j, k; + double x0, y0, x1, y1; + + assert (mesh->current_patch == NULL); + + num_patches = _cairo_array_num_elements (&mesh->patches); + + if (num_patches == 0) + return FALSE; + + patch = _cairo_array_index_const (&mesh->patches, 0); + x0 = x1 = patch->points[0][0].x; + y0 = y1 = patch->points[0][0].y; + + for (i = 0; i < num_patches; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) { + x0 = MIN (x0, patch[i].points[j][k].x); + y0 = MIN (y0, patch[i].points[j][k].y); + x1 = MAX (x1, patch[i].points[j][k].x); + y1 = MAX (y1, patch[i].points[j][k].y); + } + } + } + + *out_xmin = x0; + *out_ymin = y0; + *out_xmax = x1; + *out_ymax = y1; + + return TRUE; +} + +/** + * _cairo_gradient_pattern_is_solid: + * + * Convenience function to determine whether a gradient pattern is + * a solid color within the given extents. In this case the color + * argument is initialized to the color the pattern represents. + * This functions doesn't handle completely transparent gradients, + * thus it should be called only after _cairo_pattern_is_clear has + * returned FALSE. + * + * Return value: %TRUE if the pattern is a solid color. + **/ +cairo_bool_t +_cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents, + cairo_color_t *color) +{ + unsigned int i; + + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + + /* TODO: radial */ + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; + if (_linear_pattern_is_degenerate (linear)) { + _gradient_color_average (gradient, color); + return TRUE; + } + + if (gradient->base.extend == CAIRO_EXTEND_NONE) { + double t[2]; + + /* We already know that the pattern is not clear, thus if some + * part of it is clear, the whole is not solid. + */ + + if (extents == NULL) + return FALSE; + + _cairo_linear_pattern_box_to_parameter (linear, + extents->x, + extents->y, + extents->x + extents->width, + extents->y + extents->height, + t); + + if (t[0] < 0.0 || t[1] > 1.0) + return FALSE; + } + } else + return FALSE; + + for (i = 1; i < gradient->n_stops; i++) + if (! _cairo_color_stop_equal (&gradient->stops[0].color, + &gradient->stops[i].color)) + return FALSE; + + _cairo_color_init_rgba (color, + gradient->stops[0].color.red, + gradient->stops[0].color.green, + gradient->stops[0].color.blue, + gradient->stops[0].color.alpha); + + return TRUE; +} + +static cairo_bool_t +_mesh_is_clear (const cairo_mesh_pattern_t *mesh) +{ + double x1, y1, x2, y2; + cairo_bool_t is_valid; + + is_valid = _cairo_mesh_pattern_coord_box (mesh, &x1, &y1, &x2, &y2); + if (!is_valid) + return TRUE; + + if (x2 - x1 < DBL_EPSILON || y2 - y1 < DBL_EPSILON) + return TRUE; + + return FALSE; +} + +/** + * _cairo_pattern_is_opaque_solid: + * + * Convenience function to determine whether a pattern is an opaque + * (alpha==1.0) solid color pattern. This is done by testing whether + * the pattern's alpha value when converted to a byte is 255, so if a + * backend actually supported deep alpha channels this function might + * not do the right thing. + * + * Return value: %TRUE if the pattern is an opaque, solid color. + **/ +cairo_bool_t +_cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern) +{ + cairo_solid_pattern_t *solid; + + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) + return FALSE; + + solid = (cairo_solid_pattern_t *) pattern; + + return CAIRO_COLOR_IS_OPAQUE (&solid->color); +} + +static cairo_bool_t +_surface_is_opaque (const cairo_surface_pattern_t *pattern, + const cairo_rectangle_int_t *sample) +{ + cairo_rectangle_int_t extents; + + if (pattern->surface->content & CAIRO_CONTENT_ALPHA) + return FALSE; + + if (pattern->base.extend != CAIRO_EXTEND_NONE) + return TRUE; + + if (! _cairo_surface_get_extents (pattern->surface, &extents)) + return TRUE; + + if (sample == NULL) + return FALSE; + + return _cairo_rectangle_contains_rectangle (&extents, sample); +} + +static cairo_bool_t +_raster_source_is_opaque (const cairo_raster_source_pattern_t *pattern, + const cairo_rectangle_int_t *sample) +{ + if (pattern->content & CAIRO_CONTENT_ALPHA) + return FALSE; + + if (pattern->base.extend != CAIRO_EXTEND_NONE) + return TRUE; + + if (sample == NULL) + return FALSE; + + return _cairo_rectangle_contains_rectangle (&pattern->extents, sample); +} + +static cairo_bool_t +_surface_is_clear (const cairo_surface_pattern_t *pattern) +{ + cairo_rectangle_int_t extents; + + if (_cairo_surface_get_extents (pattern->surface, &extents) && + (extents.width == 0 || extents.height == 0)) + return TRUE; + + return pattern->surface->is_clear && + pattern->surface->content & CAIRO_CONTENT_ALPHA; +} + +static cairo_bool_t +_raster_source_is_clear (const cairo_raster_source_pattern_t *pattern) +{ + return pattern->extents.width == 0 || pattern->extents.height == 0; +} + +static cairo_bool_t +_gradient_is_opaque (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *sample) +{ + unsigned int i; + + assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR || + gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL); + + if (gradient->n_stops == 0 || + (gradient->base.extend == CAIRO_EXTEND_NONE && + gradient->stops[0].offset == gradient->stops[gradient->n_stops - 1].offset)) + return FALSE; + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + if (gradient->base.extend == CAIRO_EXTEND_NONE) { + double t[2]; + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient; + + /* EXTEND_NONE degenerate radial gradients are clear */ + if (_linear_pattern_is_degenerate (linear)) + return FALSE; + + if (sample == NULL) + return FALSE; + + _cairo_linear_pattern_box_to_parameter (linear, + sample->x, + sample->y, + sample->x + sample->width, + sample->y + sample->height, + t); + + if (t[0] < 0.0 || t[1] > 1.0) + return FALSE; + } + } else + return FALSE; /* TODO: check actual intersection */ + + for (i = 0; i < gradient->n_stops; i++) + if (! CAIRO_COLOR_IS_OPAQUE (&gradient->stops[i].color)) + return FALSE; + + return TRUE; +} + +/** + * _cairo_pattern_is_opaque: + * + * Convenience function to determine whether a pattern is an opaque + * pattern (of any type). The same caveats that apply to + * _cairo_pattern_is_opaque_solid apply here as well. + * + * Return value: %TRUE if the pattern is a opaque. + **/ +cairo_bool_t +_cairo_pattern_is_opaque (const cairo_pattern_t *abstract_pattern, + const cairo_rectangle_int_t *sample) +{ + const cairo_pattern_union_t *pattern; + + if (abstract_pattern->has_component_alpha) + return FALSE; + + pattern = (cairo_pattern_union_t *) abstract_pattern; + switch (pattern->base.type) { + case CAIRO_PATTERN_TYPE_SOLID: + return _cairo_pattern_is_opaque_solid (abstract_pattern); + case CAIRO_PATTERN_TYPE_SURFACE: + return _surface_is_opaque (&pattern->surface, sample); + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _raster_source_is_opaque (&pattern->raster_source, sample); + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + return _gradient_is_opaque (&pattern->gradient.base, sample); + case CAIRO_PATTERN_TYPE_MESH: + return FALSE; + } + + ASSERT_NOT_REACHED; + return FALSE; +} + +cairo_bool_t +_cairo_pattern_is_clear (const cairo_pattern_t *abstract_pattern) +{ + const cairo_pattern_union_t *pattern; + + if (abstract_pattern->has_component_alpha) + return FALSE; + + pattern = (cairo_pattern_union_t *) abstract_pattern; + switch (abstract_pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return CAIRO_COLOR_IS_CLEAR (&pattern->solid.color); + case CAIRO_PATTERN_TYPE_SURFACE: + return _surface_is_clear (&pattern->surface); + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _raster_source_is_clear (&pattern->raster_source); + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + return _gradient_is_clear (&pattern->gradient.base, NULL); + case CAIRO_PATTERN_TYPE_MESH: + return _mesh_is_clear (&pattern->mesh); + } + + ASSERT_NOT_REACHED; + return FALSE; +} + +/* + * Will given row of back-translation matrix work with bilinear scale? + * This is true for scales larger than 1. Also it was judged acceptable + * for scales larger than .75. And if there is integer translation + * then a scale of exactly .5 works. + */ +static int +use_bilinear(double x, double y, double t) +{ + /* This is the inverse matrix! */ + double h = x*x + y*y; + if (h < 1.0 / (0.75 * 0.75)) + return TRUE; /* scale > .75 */ + if ((h > 3.99 && h < 4.01) /* scale is 1/2 */ + && !_cairo_fixed_from_double(x*y) /* parallel to an axis */ + && _cairo_fixed_is_integer (_cairo_fixed_from_double (t))) + return TRUE; + return FALSE; +} + +/** + * _cairo_pattern_analyze_filter: + * @pattern: surface pattern + * Returns: the optimized #cairo_filter_t to use with @pattern. + * + * Possibly optimize the filter to a simpler value depending on transformation + **/ +cairo_filter_t +_cairo_pattern_analyze_filter (const cairo_pattern_t *pattern) +{ + switch (pattern->filter) { + case CAIRO_FILTER_GOOD: + case CAIRO_FILTER_BEST: + case CAIRO_FILTER_BILINEAR: + case CAIRO_FILTER_FAST: + /* If source pixels map 1:1 onto destination pixels, we do + * not need to filter (and do not want to filter, since it + * will cause blurriness) + */ + if (_cairo_matrix_is_pixel_exact (&pattern->matrix)) { + return CAIRO_FILTER_NEAREST; + } else { + /* Use BILINEAR for any scale greater than .75 instead + * of GOOD. For scales of 1 and larger this is identical, + * for the smaller sizes it was judged that the artifacts + * were not worse than the artifacts from a box filer. + * BILINEAR can also be used if the scale is exactly .5 + * and the translation in that direction is an integer. + */ + if (pattern->filter == CAIRO_FILTER_GOOD && + use_bilinear (pattern->matrix.xx, pattern->matrix.xy, + pattern->matrix.x0) && + use_bilinear (pattern->matrix.yx, pattern->matrix.yy, + pattern->matrix.y0)) + return CAIRO_FILTER_BILINEAR; + } + break; + + case CAIRO_FILTER_NEAREST: + case CAIRO_FILTER_GAUSSIAN: + default: + break; + } + + return pattern->filter; +} + +/** + * _cairo_hypot: + * Returns: value similar to hypot(@x,@y) + * + * May want to replace this with Manhattan distance (abs(x)+abs(y)) if + * hypot is too slow, as there is no need for accuracy here. + **/ +static inline double +_cairo_hypot(double x, double y) +{ + return hypot(x, y); +} + +/** + * _cairo_pattern_sampled_area: + * + * Return region of @pattern that will be sampled to fill @extents, + * based on the transformation and filter. + * + * This does not include pixels that are mulitiplied by values very + * close to zero by the ends of filters. This is so that transforms + * that should be the identity or 90 degree rotations do not expand + * the source unexpectedly. + * + * XXX: We don't actually have any way of querying the backend for + * the filter radius, so we just guess base on what we know that + * backends do currently (see bug #10508) + **/ +void +_cairo_pattern_sampled_area (const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + cairo_rectangle_int_t *sample) +{ + double x1, x2, y1, y2; + double padx, pady; + + /* Assume filters are interpolating, which means identity + cannot change the image */ + if (_cairo_matrix_is_identity (&pattern->matrix)) { + *sample = *extents; + return; + } + + /* Transform the centers of the corner pixels */ + x1 = extents->x + 0.5; + y1 = extents->y + 0.5; + x2 = x1 + (extents->width - 1); + y2 = y1 + (extents->height - 1); + _cairo_matrix_transform_bounding_box (&pattern->matrix, + &x1, &y1, &x2, &y2, + NULL); + + /* How far away from center will it actually sample? + * This is the distance from a transformed pixel center to the + * furthest sample of reasonable size. + */ + switch (pattern->filter) { + case CAIRO_FILTER_NEAREST: + case CAIRO_FILTER_FAST: + /* Correct value is zero, but when the sample is on an integer + * it is unknown if the backend will sample the pixel to the + * left or right. This value makes it include both possible pixels. + */ + padx = pady = 0.004; + break; + case CAIRO_FILTER_BILINEAR: + case CAIRO_FILTER_GAUSSIAN: + default: + /* Correct value is .5 */ + padx = pady = 0.495; + break; + case CAIRO_FILTER_GOOD: + /* Correct value is max(width,1)*.5 */ + padx = _cairo_hypot (pattern->matrix.xx, pattern->matrix.xy); + if (padx <= 1.0) padx = 0.495; + else if (padx >= 16.0) padx = 7.92; + else padx *= 0.495; + pady = _cairo_hypot (pattern->matrix.yx, pattern->matrix.yy); + if (pady <= 1.0) pady = 0.495; + else if (pady >= 16.0) pady = 7.92; + else pady *= 0.495; + break; + case CAIRO_FILTER_BEST: + /* Correct value is width*2 */ + padx = _cairo_hypot (pattern->matrix.xx, pattern->matrix.xy) * 1.98; + if (padx > 7.92) padx = 7.92; + pady = _cairo_hypot (pattern->matrix.yx, pattern->matrix.yy) * 1.98; + if (pady > 7.92) pady = 7.92; + break; + } + + /* round furthest samples to edge of pixels */ + x1 = floor (x1 - padx); + if (x1 < CAIRO_RECT_INT_MIN) x1 = CAIRO_RECT_INT_MIN; + sample->x = x1; + + y1 = floor (y1 - pady); + if (y1 < CAIRO_RECT_INT_MIN) y1 = CAIRO_RECT_INT_MIN; + sample->y = y1; + + x2 = floor (x2 + padx) + 1.0; + if (x2 > CAIRO_RECT_INT_MAX) x2 = CAIRO_RECT_INT_MAX; + sample->width = x2 - x1; + + y2 = floor (y2 + pady) + 1.0; + if (y2 > CAIRO_RECT_INT_MAX) y2 = CAIRO_RECT_INT_MAX; + sample->height = y2 - y1; +} + +/** + * _cairo_pattern_get_extents: + * + * Return the "target-space" extents of @pattern in @extents. + * + * For unbounded patterns, the @extents will be initialized with + * "infinite" extents, (minimum and maximum fixed-point values). + * + * XXX: Currently, bounded gradient patterns will also return + * "infinite" extents, though it would be possible to optimize these + * with a little more work. + **/ +void +_cairo_pattern_get_extents (const cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents) +{ + double x1, y1, x2, y2; + int ix1, ix2, iy1, iy2; + cairo_bool_t round_x = FALSE; + cairo_bool_t round_y = FALSE; + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + goto UNBOUNDED; + + case CAIRO_PATTERN_TYPE_SURFACE: + { + cairo_rectangle_int_t surface_extents; + const cairo_surface_pattern_t *surface_pattern = + (const cairo_surface_pattern_t *) pattern; + cairo_surface_t *surface = surface_pattern->surface; + + if (! _cairo_surface_get_extents (surface, &surface_extents)) + goto UNBOUNDED; + + if (surface_extents.width == 0 || surface_extents.height == 0) + goto EMPTY; + + if (pattern->extend != CAIRO_EXTEND_NONE) + goto UNBOUNDED; + + x1 = surface_extents.x; + y1 = surface_extents.y; + x2 = surface_extents.x + (int) surface_extents.width; + y2 = surface_extents.y + (int) surface_extents.height; + + goto HANDLE_FILTER; + } + break; + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + { + const cairo_raster_source_pattern_t *raster = + (const cairo_raster_source_pattern_t *) pattern; + + if (raster->extents.width == 0 || raster->extents.height == 0) + goto EMPTY; + + if (pattern->extend != CAIRO_EXTEND_NONE) + goto UNBOUNDED; + + x1 = raster->extents.x; + y1 = raster->extents.y; + x2 = raster->extents.x + (int) raster->extents.width; + y2 = raster->extents.y + (int) raster->extents.height; + } + HANDLE_FILTER: + switch (pattern->filter) { + case CAIRO_FILTER_NEAREST: + case CAIRO_FILTER_FAST: + round_x = round_y = TRUE; + /* We don't know which way .5 will go, so fudge it slightly. */ + x1 -= 0.004; + y1 -= 0.004; + x2 += 0.004; + y2 += 0.004; + break; + case CAIRO_FILTER_BEST: + /* Assume best filter will produce nice antialiased edges */ + break; + case CAIRO_FILTER_BILINEAR: + case CAIRO_FILTER_GAUSSIAN: + case CAIRO_FILTER_GOOD: + default: + /* These filters can blur the edge out 1/2 pixel when scaling up */ + if (_cairo_hypot (pattern->matrix.xx, pattern->matrix.yx) < 1.0) { + x1 -= 0.5; + x2 += 0.5; + round_x = TRUE; + } + if (_cairo_hypot (pattern->matrix.xy, pattern->matrix.yy) < 1.0) { + y1 -= 0.5; + y2 += 0.5; + round_y = TRUE; + } + break; + } + break; + + case CAIRO_PATTERN_TYPE_RADIAL: + { + const cairo_radial_pattern_t *radial = + (const cairo_radial_pattern_t *) pattern; + double cx1, cy1; + double cx2, cy2; + double r1, r2; + + if (_radial_pattern_is_degenerate (radial)) { + /* cairo-gstate should have optimised degenerate + * patterns to solid clear patterns, so we can ignore + * them here. */ + goto EMPTY; + } + + /* TODO: in some cases (focus outside/on the circle) it is + * half-bounded. */ + if (pattern->extend != CAIRO_EXTEND_NONE) + goto UNBOUNDED; + + cx1 = radial->cd1.center.x; + cy1 = radial->cd1.center.y; + r1 = radial->cd1.radius; + + cx2 = radial->cd2.center.x; + cy2 = radial->cd2.center.y; + r2 = radial->cd2.radius; + + x1 = MIN (cx1 - r1, cx2 - r2); + y1 = MIN (cy1 - r1, cy2 - r2); + x2 = MAX (cx1 + r1, cx2 + r2); + y2 = MAX (cy1 + r1, cy2 + r2); + } + break; + + case CAIRO_PATTERN_TYPE_LINEAR: + { + const cairo_linear_pattern_t *linear = + (const cairo_linear_pattern_t *) pattern; + + if (pattern->extend != CAIRO_EXTEND_NONE) + goto UNBOUNDED; + + if (_linear_pattern_is_degenerate (linear)) { + /* cairo-gstate should have optimised degenerate + * patterns to solid ones, so we can again ignore + * them here. */ + goto EMPTY; + } + + /* TODO: to get tight extents, use the matrix to transform + * the pattern instead of transforming the extents later. */ + if (pattern->matrix.xy != 0. || pattern->matrix.yx != 0.) + goto UNBOUNDED; + + if (linear->pd1.x == linear->pd2.x) { + x1 = -HUGE_VAL; + x2 = HUGE_VAL; + y1 = MIN (linear->pd1.y, linear->pd2.y); + y2 = MAX (linear->pd1.y, linear->pd2.y); + } else if (linear->pd1.y == linear->pd2.y) { + x1 = MIN (linear->pd1.x, linear->pd2.x); + x2 = MAX (linear->pd1.x, linear->pd2.x); + y1 = -HUGE_VAL; + y2 = HUGE_VAL; + } else { + goto UNBOUNDED; + } + + /* The current linear renderer just point-samples in the middle + of the pixels, similar to the NEAREST filter: */ + round_x = round_y = TRUE; + } + break; + + case CAIRO_PATTERN_TYPE_MESH: + { + const cairo_mesh_pattern_t *mesh = + (const cairo_mesh_pattern_t *) pattern; + if (! _cairo_mesh_pattern_coord_box (mesh, &x1, &y1, &x2, &y2)) + goto EMPTY; + } + break; + + default: + ASSERT_NOT_REACHED; + } + + if (_cairo_matrix_is_translation (&pattern->matrix)) { + x1 -= pattern->matrix.x0; x2 -= pattern->matrix.x0; + y1 -= pattern->matrix.y0; y2 -= pattern->matrix.y0; + } else { + cairo_matrix_t imatrix; + cairo_status_t status; + + imatrix = pattern->matrix; + status = cairo_matrix_invert (&imatrix); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + _cairo_matrix_transform_bounding_box (&imatrix, + &x1, &y1, &x2, &y2, + NULL); + } + + if (!round_x) { + x1 -= 0.5; + x2 += 0.5; + } + if (x1 < CAIRO_RECT_INT_MIN) + ix1 = CAIRO_RECT_INT_MIN; + else + ix1 = _cairo_lround (x1); + if (x2 > CAIRO_RECT_INT_MAX) + ix2 = CAIRO_RECT_INT_MAX; + else + ix2 = _cairo_lround (x2); + extents->x = ix1; extents->width = ix2 - ix1; + + if (!round_y) { + y1 -= 0.5; + y2 += 0.5; + } + if (y1 < CAIRO_RECT_INT_MIN) + iy1 = CAIRO_RECT_INT_MIN; + else + iy1 = _cairo_lround (y1); + if (y2 > CAIRO_RECT_INT_MAX) + iy2 = CAIRO_RECT_INT_MAX; + else + iy2 = _cairo_lround (y2); + extents->y = iy1; extents->height = iy2 - iy1; + + return; + + UNBOUNDED: + /* unbounded patterns -> 'infinite' extents */ + _cairo_unbounded_rectangle_init (extents); + return; + + EMPTY: + extents->x = extents->y = 0; + extents->width = extents->height = 0; + return; +} + +/** + * _cairo_pattern_get_ink_extents: + * + * Return the "target-space" inked extents of @pattern in @extents. + **/ +cairo_int_status_t +_cairo_pattern_get_ink_extents (const cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents) +{ + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE && + pattern->extend == CAIRO_EXTEND_NONE) + { + const cairo_surface_pattern_t *surface_pattern = + (const cairo_surface_pattern_t *) pattern; + cairo_surface_t *surface = surface_pattern->surface; + + surface = _cairo_surface_get_source (surface, NULL); + if (_cairo_surface_is_recording (surface)) { + cairo_matrix_t imatrix; + cairo_box_t box; + cairo_status_t status; + + imatrix = pattern->matrix; + status = cairo_matrix_invert (&imatrix); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + status = _cairo_recording_surface_get_ink_bbox ((cairo_recording_surface_t *)surface, + &box, &imatrix); + if (unlikely (status)) + return status; + + _cairo_box_round_to_rectangle (&box, extents); + return CAIRO_STATUS_SUCCESS; + } + } + + _cairo_pattern_get_extents (pattern, extents); + return CAIRO_STATUS_SUCCESS; +} + +static unsigned long +_cairo_solid_pattern_hash (unsigned long hash, + const cairo_solid_pattern_t *solid) +{ + hash = _cairo_hash_bytes (hash, &solid->color, sizeof (solid->color)); + + return hash; +} + +static unsigned long +_cairo_gradient_color_stops_hash (unsigned long hash, + const cairo_gradient_pattern_t *gradient) +{ + unsigned int n; + + hash = _cairo_hash_bytes (hash, + &gradient->n_stops, + sizeof (gradient->n_stops)); + + for (n = 0; n < gradient->n_stops; n++) { + hash = _cairo_hash_bytes (hash, + &gradient->stops[n].offset, + sizeof (double)); + hash = _cairo_hash_bytes (hash, + &gradient->stops[n].color, + sizeof (cairo_color_stop_t)); + } + + return hash; +} + +unsigned long +_cairo_linear_pattern_hash (unsigned long hash, + const cairo_linear_pattern_t *linear) +{ + hash = _cairo_hash_bytes (hash, &linear->pd1, sizeof (linear->pd1)); + hash = _cairo_hash_bytes (hash, &linear->pd2, sizeof (linear->pd2)); + + return _cairo_gradient_color_stops_hash (hash, &linear->base); +} + +unsigned long +_cairo_radial_pattern_hash (unsigned long hash, + const cairo_radial_pattern_t *radial) +{ + hash = _cairo_hash_bytes (hash, &radial->cd1.center, sizeof (radial->cd1.center)); + hash = _cairo_hash_bytes (hash, &radial->cd1.radius, sizeof (radial->cd1.radius)); + hash = _cairo_hash_bytes (hash, &radial->cd2.center, sizeof (radial->cd2.center)); + hash = _cairo_hash_bytes (hash, &radial->cd2.radius, sizeof (radial->cd2.radius)); + + return _cairo_gradient_color_stops_hash (hash, &radial->base); +} + +static unsigned long +_cairo_mesh_pattern_hash (unsigned long hash, const cairo_mesh_pattern_t *mesh) +{ + const cairo_mesh_patch_t *patch = _cairo_array_index_const (&mesh->patches, 0); + unsigned int i, n = _cairo_array_num_elements (&mesh->patches); + + for (i = 0; i < n; i++) + hash = _cairo_hash_bytes (hash, patch + i, sizeof (cairo_mesh_patch_t)); + + return hash; +} + +static unsigned long +_cairo_surface_pattern_hash (unsigned long hash, + const cairo_surface_pattern_t *surface) +{ + hash ^= surface->surface->unique_id; + + return hash; +} + +static unsigned long +_cairo_raster_source_pattern_hash (unsigned long hash, + const cairo_raster_source_pattern_t *raster) +{ + hash ^= (uintptr_t)raster->user_data; + + return hash; +} + +unsigned long +_cairo_pattern_hash (const cairo_pattern_t *pattern) +{ + unsigned long hash = _CAIRO_HASH_INIT_VALUE; + + if (pattern->status) + return 0; + + hash = _cairo_hash_bytes (hash, &pattern->type, sizeof (pattern->type)); + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) { + hash = _cairo_hash_bytes (hash, + &pattern->matrix, sizeof (pattern->matrix)); + hash = _cairo_hash_bytes (hash, + &pattern->filter, sizeof (pattern->filter)); + hash = _cairo_hash_bytes (hash, + &pattern->extend, sizeof (pattern->extend)); + hash = _cairo_hash_bytes (hash, + &pattern->has_component_alpha, + sizeof (pattern->has_component_alpha)); + } + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return _cairo_solid_pattern_hash (hash, (cairo_solid_pattern_t *) pattern); + case CAIRO_PATTERN_TYPE_LINEAR: + return _cairo_linear_pattern_hash (hash, (cairo_linear_pattern_t *) pattern); + case CAIRO_PATTERN_TYPE_RADIAL: + return _cairo_radial_pattern_hash (hash, (cairo_radial_pattern_t *) pattern); + case CAIRO_PATTERN_TYPE_MESH: + return _cairo_mesh_pattern_hash (hash, (cairo_mesh_pattern_t *) pattern); + case CAIRO_PATTERN_TYPE_SURFACE: + return _cairo_surface_pattern_hash (hash, (cairo_surface_pattern_t *) pattern); + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _cairo_raster_source_pattern_hash (hash, (cairo_raster_source_pattern_t *) pattern); + default: + ASSERT_NOT_REACHED; + return FALSE; + } +} + +static cairo_bool_t +_cairo_solid_pattern_equal (const cairo_solid_pattern_t *a, + const cairo_solid_pattern_t *b) +{ + return _cairo_color_equal (&a->color, &b->color); +} + +static cairo_bool_t +_cairo_gradient_color_stops_equal (const cairo_gradient_pattern_t *a, + const cairo_gradient_pattern_t *b) +{ + unsigned int n; + + if (a->n_stops != b->n_stops) + return FALSE; + + for (n = 0; n < a->n_stops; n++) { + if (a->stops[n].offset != b->stops[n].offset) + return FALSE; + if (! _cairo_color_stop_equal (&a->stops[n].color, &b->stops[n].color)) + return FALSE; + } + + return TRUE; +} + +cairo_bool_t +_cairo_linear_pattern_equal (const cairo_linear_pattern_t *a, + const cairo_linear_pattern_t *b) +{ + if (a->pd1.x != b->pd1.x) + return FALSE; + + if (a->pd1.y != b->pd1.y) + return FALSE; + + if (a->pd2.x != b->pd2.x) + return FALSE; + + if (a->pd2.y != b->pd2.y) + return FALSE; + + return _cairo_gradient_color_stops_equal (&a->base, &b->base); +} + +cairo_bool_t +_cairo_radial_pattern_equal (const cairo_radial_pattern_t *a, + const cairo_radial_pattern_t *b) +{ + if (a->cd1.center.x != b->cd1.center.x) + return FALSE; + + if (a->cd1.center.y != b->cd1.center.y) + return FALSE; + + if (a->cd1.radius != b->cd1.radius) + return FALSE; + + if (a->cd2.center.x != b->cd2.center.x) + return FALSE; + + if (a->cd2.center.y != b->cd2.center.y) + return FALSE; + + if (a->cd2.radius != b->cd2.radius) + return FALSE; + + return _cairo_gradient_color_stops_equal (&a->base, &b->base); +} + +static cairo_bool_t +_cairo_mesh_pattern_equal (const cairo_mesh_pattern_t *a, + const cairo_mesh_pattern_t *b) +{ + const cairo_mesh_patch_t *patch_a, *patch_b; + unsigned int i, num_patches_a, num_patches_b; + + num_patches_a = _cairo_array_num_elements (&a->patches); + num_patches_b = _cairo_array_num_elements (&b->patches); + + if (num_patches_a != num_patches_b) + return FALSE; + + for (i = 0; i < num_patches_a; i++) { + patch_a = _cairo_array_index_const (&a->patches, i); + patch_b = _cairo_array_index_const (&b->patches, i); + if (memcmp (patch_a, patch_b, sizeof(cairo_mesh_patch_t)) != 0) + return FALSE; + } + + return TRUE; +} + +static cairo_bool_t +_cairo_surface_pattern_equal (const cairo_surface_pattern_t *a, + const cairo_surface_pattern_t *b) +{ + return a->surface->unique_id == b->surface->unique_id; +} + +static cairo_bool_t +_cairo_raster_source_pattern_equal (const cairo_raster_source_pattern_t *a, + const cairo_raster_source_pattern_t *b) +{ + return a->user_data == b->user_data; +} + +cairo_bool_t +_cairo_pattern_equal (const cairo_pattern_t *a, const cairo_pattern_t *b) +{ + if (a->status || b->status) + return FALSE; + + if (a == b) + return TRUE; + + if (a->type != b->type) + return FALSE; + + if (a->has_component_alpha != b->has_component_alpha) + return FALSE; + + if (a->type != CAIRO_PATTERN_TYPE_SOLID) { + if (memcmp (&a->matrix, &b->matrix, sizeof (cairo_matrix_t))) + return FALSE; + + if (a->filter != b->filter) + return FALSE; + + if (a->extend != b->extend) + return FALSE; + } + + switch (a->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return _cairo_solid_pattern_equal ((cairo_solid_pattern_t *) a, + (cairo_solid_pattern_t *) b); + case CAIRO_PATTERN_TYPE_LINEAR: + return _cairo_linear_pattern_equal ((cairo_linear_pattern_t *) a, + (cairo_linear_pattern_t *) b); + case CAIRO_PATTERN_TYPE_RADIAL: + return _cairo_radial_pattern_equal ((cairo_radial_pattern_t *) a, + (cairo_radial_pattern_t *) b); + case CAIRO_PATTERN_TYPE_MESH: + return _cairo_mesh_pattern_equal ((cairo_mesh_pattern_t *) a, + (cairo_mesh_pattern_t *) b); + case CAIRO_PATTERN_TYPE_SURFACE: + return _cairo_surface_pattern_equal ((cairo_surface_pattern_t *) a, + (cairo_surface_pattern_t *) b); + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _cairo_raster_source_pattern_equal ((cairo_raster_source_pattern_t *) a, + (cairo_raster_source_pattern_t *) b); + default: + ASSERT_NOT_REACHED; + return FALSE; + } +} + +/** + * cairo_pattern_get_rgba: + * @pattern: a #cairo_pattern_t + * @red: return value for red component of color, or %NULL + * @green: return value for green component of color, or %NULL + * @blue: return value for blue component of color, or %NULL + * @alpha: return value for alpha component of color, or %NULL + * + * Gets the solid color for a solid color pattern. + * + * Return value: %CAIRO_STATUS_SUCCESS, or + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a solid + * color pattern. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_get_rgba (cairo_pattern_t *pattern, + double *red, double *green, + double *blue, double *alpha) +{ + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) pattern; + double r0, g0, b0, a0; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + _cairo_color_get_rgba (&solid->color, &r0, &g0, &b0, &a0); + + if (red) + *red = r0; + if (green) + *green = g0; + if (blue) + *blue = b0; + if (alpha) + *alpha = a0; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_pattern_get_surface: + * @pattern: a #cairo_pattern_t + * @surface: return value for surface of pattern, or %NULL + * + * Gets the surface of a surface pattern. The reference returned in + * @surface is owned by the pattern; the caller should call + * cairo_surface_reference() if the surface is to be retained. + * + * Return value: %CAIRO_STATUS_SUCCESS, or + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a surface + * pattern. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_get_surface (cairo_pattern_t *pattern, + cairo_surface_t **surface) +{ + cairo_surface_pattern_t *spat = (cairo_surface_pattern_t*) pattern; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (surface) + *surface = spat->surface; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_pattern_get_color_stop_rgba: + * @pattern: a #cairo_pattern_t + * @index: index of the stop to return data for + * @offset: return value for the offset of the stop, or %NULL + * @red: return value for red component of color, or %NULL + * @green: return value for green component of color, or %NULL + * @blue: return value for blue component of color, or %NULL + * @alpha: return value for alpha component of color, or %NULL + * + * Gets the color and offset information at the given @index for a + * gradient pattern. Values of @index range from 0 to n-1 + * where n is the number returned + * by cairo_pattern_get_color_stop_count(). + * + * Return value: %CAIRO_STATUS_SUCCESS, or %CAIRO_STATUS_INVALID_INDEX + * if @index is not valid for the given pattern. If the pattern is + * not a gradient pattern, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH is + * returned. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern, + int index, double *offset, + double *red, double *green, + double *blue, double *alpha) +{ + cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t*) pattern; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && + pattern->type != CAIRO_PATTERN_TYPE_RADIAL) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (index < 0 || (unsigned int) index >= gradient->n_stops) + return _cairo_error (CAIRO_STATUS_INVALID_INDEX); + + if (offset) + *offset = gradient->stops[index].offset; + if (red) + *red = gradient->stops[index].color.red; + if (green) + *green = gradient->stops[index].color.green; + if (blue) + *blue = gradient->stops[index].color.blue; + if (alpha) + *alpha = gradient->stops[index].color.alpha; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_pattern_get_color_stop_count: + * @pattern: a #cairo_pattern_t + * @count: return value for the number of color stops, or %NULL + * + * Gets the number of color stops specified in the given gradient + * pattern. + * + * Return value: %CAIRO_STATUS_SUCCESS, or + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a gradient + * pattern. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern, + int *count) +{ + cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t*) pattern; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && + pattern->type != CAIRO_PATTERN_TYPE_RADIAL) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (count) + *count = gradient->n_stops; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_pattern_get_linear_points: + * @pattern: a #cairo_pattern_t + * @x0: return value for the x coordinate of the first point, or %NULL + * @y0: return value for the y coordinate of the first point, or %NULL + * @x1: return value for the x coordinate of the second point, or %NULL + * @y1: return value for the y coordinate of the second point, or %NULL + * + * Gets the gradient endpoints for a linear gradient. + * + * Return value: %CAIRO_STATUS_SUCCESS, or + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a linear + * gradient pattern. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_get_linear_points (cairo_pattern_t *pattern, + double *x0, double *y0, + double *x1, double *y1) +{ + cairo_linear_pattern_t *linear = (cairo_linear_pattern_t*) pattern; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (x0) + *x0 = linear->pd1.x; + if (y0) + *y0 = linear->pd1.y; + if (x1) + *x1 = linear->pd2.x; + if (y1) + *y1 = linear->pd2.y; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_pattern_get_radial_circles: + * @pattern: a #cairo_pattern_t + * @x0: return value for the x coordinate of the center of the first circle, or %NULL + * @y0: return value for the y coordinate of the center of the first circle, or %NULL + * @r0: return value for the radius of the first circle, or %NULL + * @x1: return value for the x coordinate of the center of the second circle, or %NULL + * @y1: return value for the y coordinate of the center of the second circle, or %NULL + * @r1: return value for the radius of the second circle, or %NULL + * + * Gets the gradient endpoint circles for a radial gradient, each + * specified as a center coordinate and a radius. + * + * Return value: %CAIRO_STATUS_SUCCESS, or + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a radial + * gradient pattern. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_pattern_get_radial_circles (cairo_pattern_t *pattern, + double *x0, double *y0, double *r0, + double *x1, double *y1, double *r1) +{ + cairo_radial_pattern_t *radial = (cairo_radial_pattern_t*) pattern; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_RADIAL) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (x0) + *x0 = radial->cd1.center.x; + if (y0) + *y0 = radial->cd1.center.y; + if (r0) + *r0 = radial->cd1.radius; + if (x1) + *x1 = radial->cd2.center.x; + if (y1) + *y1 = radial->cd2.center.y; + if (r1) + *r1 = radial->cd2.radius; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_mesh_pattern_get_patch_count: + * @pattern: a #cairo_pattern_t + * @count: return value for the number patches, or %NULL + * + * Gets the number of patches specified in the given mesh pattern. + * + * The number only includes patches which have been finished by + * calling cairo_mesh_pattern_end_patch(). For example it will be 0 + * during the definition of the first patch. + * + * Return value: %CAIRO_STATUS_SUCCESS, or + * %CAIRO_STATUS_PATTERN_TYPE_MISMATCH if @pattern is not a mesh + * pattern. + * + * Since: 1.12 + **/ +cairo_status_t +cairo_mesh_pattern_get_patch_count (cairo_pattern_t *pattern, + unsigned int *count) +{ + cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; + + if (unlikely (pattern->status)) + return pattern->status; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (count) { + *count = _cairo_array_num_elements (&mesh->patches); + if (mesh->current_patch) + *count -= 1; + } + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_mesh_pattern_get_patch_count); + +/** + * cairo_mesh_pattern_get_path: + * @pattern: a #cairo_pattern_t + * @patch_num: the patch number to return data for + * + * Gets path defining the patch @patch_num for a mesh + * pattern. + * + * @patch_num can range from 0 to n-1 where n is the number returned by + * cairo_mesh_pattern_get_patch_count(). + * + * Return value: the path defining the patch, or a path with status + * %CAIRO_STATUS_INVALID_INDEX if @patch_num or @point_num is not + * valid for @pattern. If @pattern is not a mesh pattern, a path with + * status %CAIRO_STATUS_PATTERN_TYPE_MISMATCH is returned. + * + * Since: 1.12 + **/ +cairo_path_t * +cairo_mesh_pattern_get_path (cairo_pattern_t *pattern, + unsigned int patch_num) +{ + cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; + const cairo_mesh_patch_t *patch; + cairo_path_t *path; + cairo_path_data_t *data; + unsigned int patch_count; + int l, current_point; + + if (unlikely (pattern->status)) + return _cairo_path_create_in_error (pattern->status); + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) + return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH)); + + patch_count = _cairo_array_num_elements (&mesh->patches); + if (mesh->current_patch) + patch_count--; + + if (unlikely (patch_num >= patch_count)) + return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_INDEX)); + + patch = _cairo_array_index_const (&mesh->patches, patch_num); + + path = malloc (sizeof (cairo_path_t)); + if (path == NULL) + return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + path->num_data = 18; + path->data = _cairo_malloc_ab (path->num_data, + sizeof (cairo_path_data_t)); + if (path->data == NULL) { + free (path); + return _cairo_path_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + data = path->data; + data[0].header.type = CAIRO_PATH_MOVE_TO; + data[0].header.length = 2; + data[1].point.x = patch->points[0][0].x; + data[1].point.y = patch->points[0][0].y; + data += data[0].header.length; + + current_point = 0; + + for (l = 0; l < 4; l++) { + int i, j, k; + + data[0].header.type = CAIRO_PATH_CURVE_TO; + data[0].header.length = 4; + + for (k = 1; k < 4; k++) { + current_point = (current_point + 1) % 12; + i = mesh_path_point_i[current_point]; + j = mesh_path_point_j[current_point]; + data[k].point.x = patch->points[i][j].x; + data[k].point.y = patch->points[i][j].y; + } + + data += data[0].header.length; + } + + path->status = CAIRO_STATUS_SUCCESS; + + return path; +} +slim_hidden_def (cairo_mesh_pattern_get_path); + +/** + * cairo_mesh_pattern_get_corner_color_rgba: + * @pattern: a #cairo_pattern_t + * @patch_num: the patch number to return data for + * @corner_num: the corner number to return data for + * @red: return value for red component of color, or %NULL + * @green: return value for green component of color, or %NULL + * @blue: return value for blue component of color, or %NULL + * @alpha: return value for alpha component of color, or %NULL + * + * Gets the color information in corner @corner_num of patch + * @patch_num for a mesh pattern. + * + * @patch_num can range from 0 to n-1 where n is the number returned by + * cairo_mesh_pattern_get_patch_count(). + * + * Valid values for @corner_num are from 0 to 3 and identify the + * corners as explained in cairo_pattern_create_mesh(). + * + * Return value: %CAIRO_STATUS_SUCCESS, or %CAIRO_STATUS_INVALID_INDEX + * if @patch_num or @corner_num is not valid for @pattern. If + * @pattern is not a mesh pattern, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH + * is returned. + * + * Since: 1.12 + **/ +cairo_status_t +cairo_mesh_pattern_get_corner_color_rgba (cairo_pattern_t *pattern, + unsigned int patch_num, + unsigned int corner_num, + double *red, double *green, + double *blue, double *alpha) +{ + cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; + unsigned int patch_count; + const cairo_mesh_patch_t *patch; + + if (unlikely (pattern->status)) + return pattern->status; + + if (unlikely (pattern->type != CAIRO_PATTERN_TYPE_MESH)) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (unlikely (corner_num > 3)) + return _cairo_error (CAIRO_STATUS_INVALID_INDEX); + + patch_count = _cairo_array_num_elements (&mesh->patches); + if (mesh->current_patch) + patch_count--; + + if (unlikely (patch_num >= patch_count)) + return _cairo_error (CAIRO_STATUS_INVALID_INDEX); + + patch = _cairo_array_index_const (&mesh->patches, patch_num); + + if (red) + *red = patch->colors[corner_num].red; + if (green) + *green = patch->colors[corner_num].green; + if (blue) + *blue = patch->colors[corner_num].blue; + if (alpha) + *alpha = patch->colors[corner_num].alpha; + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_mesh_pattern_get_corner_color_rgba); + +/** + * cairo_mesh_pattern_get_control_point: + * @pattern: a #cairo_pattern_t + * @patch_num: the patch number to return data for + * @point_num: the control point number to return data for + * @x: return value for the x coordinate of the control point, or %NULL + * @y: return value for the y coordinate of the control point, or %NULL + * + * Gets the control point @point_num of patch @patch_num for a mesh + * pattern. + * + * @patch_num can range from 0 to n-1 where n is the number returned by + * cairo_mesh_pattern_get_patch_count(). + * + * Valid values for @point_num are from 0 to 3 and identify the + * control points as explained in cairo_pattern_create_mesh(). + * + * Return value: %CAIRO_STATUS_SUCCESS, or %CAIRO_STATUS_INVALID_INDEX + * if @patch_num or @point_num is not valid for @pattern. If @pattern + * is not a mesh pattern, %CAIRO_STATUS_PATTERN_TYPE_MISMATCH is + * returned. + * + * Since: 1.12 + **/ +cairo_status_t +cairo_mesh_pattern_get_control_point (cairo_pattern_t *pattern, + unsigned int patch_num, + unsigned int point_num, + double *x, double *y) +{ + cairo_mesh_pattern_t *mesh = (cairo_mesh_pattern_t *) pattern; + const cairo_mesh_patch_t *patch; + unsigned int patch_count; + int i, j; + + if (pattern->status) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_MESH) + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + + if (point_num > 3) + return _cairo_error (CAIRO_STATUS_INVALID_INDEX); + + patch_count = _cairo_array_num_elements (&mesh->patches); + if (mesh->current_patch) + patch_count--; + + if (unlikely (patch_num >= patch_count)) + return _cairo_error (CAIRO_STATUS_INVALID_INDEX); + + patch = _cairo_array_index_const (&mesh->patches, patch_num); + + i = mesh_control_point_i[point_num]; + j = mesh_control_point_j[point_num]; + + if (x) + *x = patch->points[i][j].x; + if (y) + *y = patch->points[i][j].y; + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_mesh_pattern_get_control_point); + +void +_cairo_pattern_reset_static_data (void) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (freed_pattern_pool); i++) + _freed_pool_reset (&freed_pattern_pool[i]); +} + +static void +_cairo_debug_print_surface_pattern (FILE *file, + const cairo_surface_pattern_t *pattern) +{ + printf (" surface type: %d\n", pattern->surface->type); +} + +static void +_cairo_debug_print_raster_source_pattern (FILE *file, + const cairo_raster_source_pattern_t *raster) +{ + printf (" content: %x, size %dx%d\n", raster->content, raster->extents.width, raster->extents.height); +} + +static void +_cairo_debug_print_linear_pattern (FILE *file, + const cairo_linear_pattern_t *pattern) +{ +} + +static void +_cairo_debug_print_radial_pattern (FILE *file, + const cairo_radial_pattern_t *pattern) +{ +} + +static void +_cairo_debug_print_mesh_pattern (FILE *file, + const cairo_mesh_pattern_t *pattern) +{ +} + +void +_cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern) +{ + const char *s; + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: s = "solid"; break; + case CAIRO_PATTERN_TYPE_SURFACE: s = "surface"; break; + case CAIRO_PATTERN_TYPE_LINEAR: s = "linear"; break; + case CAIRO_PATTERN_TYPE_RADIAL: s = "radial"; break; + case CAIRO_PATTERN_TYPE_MESH: s = "mesh"; break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: s = "raster"; break; + default: s = "invalid"; ASSERT_NOT_REACHED; break; + } + + fprintf (file, "pattern: %s\n", s); + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) + return; + + switch (pattern->extend) { + case CAIRO_EXTEND_NONE: s = "none"; break; + case CAIRO_EXTEND_REPEAT: s = "repeat"; break; + case CAIRO_EXTEND_REFLECT: s = "reflect"; break; + case CAIRO_EXTEND_PAD: s = "pad"; break; + default: s = "invalid"; ASSERT_NOT_REACHED; break; + } + fprintf (file, " extend: %s\n", s); + + switch (pattern->filter) { + case CAIRO_FILTER_FAST: s = "fast"; break; + case CAIRO_FILTER_GOOD: s = "good"; break; + case CAIRO_FILTER_BEST: s = "best"; break; + case CAIRO_FILTER_NEAREST: s = "nearest"; break; + case CAIRO_FILTER_BILINEAR: s = "bilinear"; break; + case CAIRO_FILTER_GAUSSIAN: s = "guassian"; break; + default: s = "invalid"; ASSERT_NOT_REACHED; break; + } + fprintf (file, " filter: %s\n", s); + fprintf (file, " matrix: [%g %g %g %g %g %g]\n", + pattern->matrix.xx, pattern->matrix.yx, + pattern->matrix.xy, pattern->matrix.yy, + pattern->matrix.x0, pattern->matrix.y0); + switch (pattern->type) { + default: + case CAIRO_PATTERN_TYPE_SOLID: + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + _cairo_debug_print_raster_source_pattern (file, (cairo_raster_source_pattern_t *)pattern); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + _cairo_debug_print_surface_pattern (file, (cairo_surface_pattern_t *)pattern); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + _cairo_debug_print_linear_pattern (file, (cairo_linear_pattern_t *)pattern); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + _cairo_debug_print_radial_pattern (file, (cairo_radial_pattern_t *)pattern); + break; + case CAIRO_PATTERN_TYPE_MESH: + _cairo_debug_print_mesh_pattern (file, (cairo_mesh_pattern_t *)pattern); + break; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators-private.h new file mode 100644 index 00000000000..4314a042e81 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators-private.h @@ -0,0 +1,176 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * Copyright © 2006 Red Hat, Inc + * Copyright © 2007 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Carl Worth + * Adrian Johnson + */ + +#ifndef CAIRO_PDF_OPERATORS_H +#define CAIRO_PDF_OPERATORS_H + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" +#include "cairo-types-private.h" + +/* The glyph buffer size is based on the expected maximum glyphs in a + * line so that an entire line can be emitted in as one string. If the + * glyphs in a line exceeds this size the only downside is the slight + * overhead of emitting two strings. + */ +#define PDF_GLYPH_BUFFER_SIZE 200 + +typedef cairo_int_status_t +(*cairo_pdf_operators_use_font_subset_t) (unsigned int font_id, + unsigned int subset_id, + void *closure); + +typedef struct _cairo_pdf_glyph { + unsigned int glyph_index; + double x_position; + double x_advance; +} cairo_pdf_glyph_t; + +typedef struct _cairo_pdf_operators { + cairo_output_stream_t *stream; + cairo_matrix_t cairo_to_pdf; + cairo_scaled_font_subsets_t *font_subsets; + cairo_pdf_operators_use_font_subset_t use_font_subset; + void *use_font_subset_closure; + cairo_bool_t ps_output; /* output is for PostScript */ + cairo_bool_t use_actual_text; + cairo_bool_t in_text_object; /* inside BT/ET pair */ + + /* PDF text state */ + cairo_bool_t is_new_text_object; /* text object started but matrix and font not yet selected */ + unsigned int font_id; + unsigned int subset_id; + cairo_matrix_t text_matrix; /* PDF text matrix (Tlm in the PDF reference) */ + cairo_matrix_t cairo_to_pdftext; /* translate cairo coords to PDF text space */ + cairo_matrix_t font_matrix_inverse; + double cur_x; /* Current position in PDF text space (Tm in the PDF reference) */ + double cur_y; + int hex_width; + cairo_bool_t is_latin; + int num_glyphs; + double glyph_buf_x_pos; + cairo_pdf_glyph_t glyphs[PDF_GLYPH_BUFFER_SIZE]; + + /* PDF line style */ + cairo_bool_t has_line_style; + double line_width; + cairo_line_cap_t line_cap; + cairo_line_join_t line_join; + double miter_limit; + cairo_bool_t has_dashes; +} cairo_pdf_operators_t; + +cairo_private void +_cairo_pdf_operators_init (cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream, + cairo_matrix_t *cairo_to_pdf, + cairo_scaled_font_subsets_t *font_subsets, + cairo_bool_t ps); + +cairo_private cairo_status_t +_cairo_pdf_operators_fini (cairo_pdf_operators_t *pdf_operators); + +cairo_private void +_cairo_pdf_operators_set_font_subsets_callback (cairo_pdf_operators_t *pdf_operators, + cairo_pdf_operators_use_font_subset_t use_font_subset, + void *closure); + +cairo_private void +_cairo_pdf_operators_set_stream (cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream); + + +cairo_private void +_cairo_pdf_operators_set_cairo_to_pdf_matrix (cairo_pdf_operators_t *pdf_operators, + cairo_matrix_t *cairo_to_pdf); + +cairo_private void +_cairo_pdf_operators_enable_actual_text (cairo_pdf_operators_t *pdf_operators, + cairo_bool_t enable); + +cairo_private cairo_status_t +_cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators); + +cairo_private void +_cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators); + +cairo_private cairo_int_status_t +_cairo_pdf_operators_clip (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_int_status_t +_cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t *pdf_operators, + const cairo_stroke_style_t *style, + double scale); + +cairo_private cairo_int_status_t +_cairo_pdf_operators_stroke (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse); + +cairo_private cairo_int_status_t +_cairo_pdf_operators_fill (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_int_status_t +_cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse); + +cairo_private cairo_int_status_t +_cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t *pdf_operators, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font); + +#endif /* CAIRO_PDF_OPERATORS_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators.c b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators.c new file mode 100644 index 00000000000..dcee25f0c23 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-operators.c @@ -0,0 +1,1560 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * Copyright © 2006 Red Hat, Inc + * Copyright © 2007, 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Carl Worth + * Adrian Johnson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_PDF_OPERATORS + +#include "cairo-error-private.h" +#include "cairo-pdf-operators-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-scaled-font-subsets-private.h" + +static cairo_status_t +_cairo_pdf_operators_end_text (cairo_pdf_operators_t *pdf_operators); + + +void +_cairo_pdf_operators_init (cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream, + cairo_matrix_t *cairo_to_pdf, + cairo_scaled_font_subsets_t *font_subsets, + cairo_bool_t ps) +{ + pdf_operators->stream = stream; + pdf_operators->cairo_to_pdf = *cairo_to_pdf; + pdf_operators->font_subsets = font_subsets; + pdf_operators->ps_output = ps; + pdf_operators->use_font_subset = NULL; + pdf_operators->use_font_subset_closure = NULL; + pdf_operators->in_text_object = FALSE; + pdf_operators->num_glyphs = 0; + pdf_operators->has_line_style = FALSE; + pdf_operators->use_actual_text = FALSE; +} + +cairo_status_t +_cairo_pdf_operators_fini (cairo_pdf_operators_t *pdf_operators) +{ + return _cairo_pdf_operators_flush (pdf_operators); +} + +void +_cairo_pdf_operators_set_font_subsets_callback (cairo_pdf_operators_t *pdf_operators, + cairo_pdf_operators_use_font_subset_t use_font_subset, + void *closure) +{ + pdf_operators->use_font_subset = use_font_subset; + pdf_operators->use_font_subset_closure = closure; +} + +/* Change the output stream to a different stream. + * _cairo_pdf_operators_flush() should always be called before calling + * this function. + */ +void +_cairo_pdf_operators_set_stream (cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream) +{ + pdf_operators->stream = stream; + pdf_operators->has_line_style = FALSE; +} + +void +_cairo_pdf_operators_set_cairo_to_pdf_matrix (cairo_pdf_operators_t *pdf_operators, + cairo_matrix_t *cairo_to_pdf) +{ + pdf_operators->cairo_to_pdf = *cairo_to_pdf; + pdf_operators->has_line_style = FALSE; +} + +cairo_private void +_cairo_pdf_operators_enable_actual_text (cairo_pdf_operators_t *pdf_operators, + cairo_bool_t enable) +{ + pdf_operators->use_actual_text = enable; +} + +/* Finish writing out any pending commands to the stream. This + * function must be called by the surface before emitting anything + * into the PDF stream. + * + * pdf_operators may leave the emitted PDF for some operations + * unfinished in case subsequent operations can be merged. This + * function will finish off any incomplete operation so the stream + * will be in a state where the surface may emit its own PDF + * operations (eg changing patterns). + * + */ +cairo_status_t +_cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + if (pdf_operators->in_text_object) + status = _cairo_pdf_operators_end_text (pdf_operators); + + return status; +} + +/* Reset the known graphics state of the PDF consumer. ie no + * assumptions will be made about the state. The next time a + * particular graphics state is required (eg line width) the state + * operator is always emitted and then remembered for subsequent + * operatations. + * + * This should be called when starting a new stream or after emitting + * the 'Q' operator (where pdf-operators functions were called inside + * the q/Q pair). + */ +void +_cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators) +{ + pdf_operators->has_line_style = FALSE; +} + +/* A word wrap stream can be used as a filter to do word wrapping on + * top of an existing output stream. The word wrapping is quite + * simple, using isspace to determine characters that separate + * words. Any word that will cause the column count exceed the given + * max_column will have a '\n' character emitted before it. + * + * The stream is careful to maintain integrity for words that cross + * the boundary from one call to write to the next. + * + * Note: This stream does not guarantee that the output will never + * exceed max_column. In particular, if a single word is larger than + * max_column it will not be broken up. + */ + +typedef enum _cairo_word_wrap_state { + WRAP_STATE_DELIMITER, + WRAP_STATE_WORD, + WRAP_STATE_STRING, + WRAP_STATE_HEXSTRING +} cairo_word_wrap_state_t; + + +typedef struct _word_wrap_stream { + cairo_output_stream_t base; + cairo_output_stream_t *output; + int max_column; + cairo_bool_t ps_output; + int column; + cairo_word_wrap_state_t state; + cairo_bool_t in_escape; + int escape_digits; +} word_wrap_stream_t; + + + +/* Emit word bytes up to the next delimiter character */ +static int +_word_wrap_stream_count_word_up_to (word_wrap_stream_t *stream, + const unsigned char *data, int length) +{ + const unsigned char *s = data; + int count = 0; + + while (length--) { + if (_cairo_isspace (*s) || *s == '<' || *s == '(') { + stream->state = WRAP_STATE_DELIMITER; + break; + } + + count++; + stream->column++; + s++; + } + + if (count) + _cairo_output_stream_write (stream->output, data, count); + + return count; +} + + +/* Emit hexstring bytes up to either the end of the ASCII hexstring or the number + * of columns remaining. + */ +static int +_word_wrap_stream_count_hexstring_up_to (word_wrap_stream_t *stream, + const unsigned char *data, int length) +{ + const unsigned char *s = data; + int count = 0; + cairo_bool_t newline = FALSE; + + while (length--) { + count++; + stream->column++; + if (*s == '>') { + stream->state = WRAP_STATE_DELIMITER; + break; + } + + if (stream->column > stream->max_column) { + newline = TRUE; + break; + } + s++; + } + + if (count) + _cairo_output_stream_write (stream->output, data, count); + + if (newline) { + _cairo_output_stream_printf (stream->output, "\n"); + stream->column = 0; + } + + return count; +} + +/* Count up to either the end of the string or the number of columns + * remaining. + */ +static int +_word_wrap_stream_count_string_up_to (word_wrap_stream_t *stream, + const unsigned char *data, int length) +{ + const unsigned char *s = data; + int count = 0; + cairo_bool_t newline = FALSE; + + while (length--) { + count++; + stream->column++; + if (!stream->in_escape) { + if (*s == ')') { + stream->state = WRAP_STATE_DELIMITER; + break; + } + if (*s == '\\') { + stream->in_escape = TRUE; + stream->escape_digits = 0; + } else if (stream->ps_output && stream->column > stream->max_column) { + newline = TRUE; + break; + } + } else { + if (!_cairo_isdigit(*s) || ++stream->escape_digits == 3) + stream->in_escape = FALSE; + } + s++; + } + + if (count) + _cairo_output_stream_write (stream->output, data, count); + + if (newline) { + _cairo_output_stream_printf (stream->output, "\\\n"); + stream->column = 0; + } + + return count; +} + +static cairo_status_t +_word_wrap_stream_write (cairo_output_stream_t *base, + const unsigned char *data, + unsigned int length) +{ + word_wrap_stream_t *stream = (word_wrap_stream_t *) base; + int count; + + while (length) { + switch (stream->state) { + case WRAP_STATE_WORD: + count = _word_wrap_stream_count_word_up_to (stream, data, length); + break; + case WRAP_STATE_HEXSTRING: + count = _word_wrap_stream_count_hexstring_up_to (stream, data, length); + break; + case WRAP_STATE_STRING: + count = _word_wrap_stream_count_string_up_to (stream, data, length); + break; + case WRAP_STATE_DELIMITER: + count = 1; + stream->column++; + if (*data == '\n' || stream->column >= stream->max_column) { + _cairo_output_stream_printf (stream->output, "\n"); + stream->column = 0; + } else if (*data == '<') { + stream->state = WRAP_STATE_HEXSTRING; + } else if (*data == '(') { + stream->state = WRAP_STATE_STRING; + } else if (!_cairo_isspace (*data)) { + stream->state = WRAP_STATE_WORD; + } + if (*data != '\n') + _cairo_output_stream_write (stream->output, data, 1); + break; + + default: + ASSERT_NOT_REACHED; + count = length; + break; + } + data += count; + length -= count; + } + + return _cairo_output_stream_get_status (stream->output); +} + +static cairo_status_t +_word_wrap_stream_close (cairo_output_stream_t *base) +{ + word_wrap_stream_t *stream = (word_wrap_stream_t *) base; + + return _cairo_output_stream_get_status (stream->output); +} + +static cairo_output_stream_t * +_word_wrap_stream_create (cairo_output_stream_t *output, cairo_bool_t ps, int max_column) +{ + word_wrap_stream_t *stream; + + if (output->status) + return _cairo_output_stream_create_in_error (output->status); + + stream = malloc (sizeof (word_wrap_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + _word_wrap_stream_write, + NULL, + _word_wrap_stream_close); + stream->output = output; + stream->max_column = max_column; + stream->ps_output = ps; + stream->column = 0; + stream->state = WRAP_STATE_DELIMITER; + stream->in_escape = FALSE; + stream->escape_digits = 0; + + return &stream->base; +} + +typedef struct _pdf_path_info { + cairo_output_stream_t *output; + cairo_matrix_t *path_transform; + cairo_line_cap_t line_cap; + cairo_point_t last_move_to_point; + cairo_bool_t has_sub_path; +} pdf_path_info_t; + +static cairo_status_t +_cairo_pdf_path_move_to (void *closure, + const cairo_point_t *point) +{ + pdf_path_info_t *info = closure; + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + info->last_move_to_point = *point; + info->has_sub_path = FALSE; + cairo_matrix_transform_point (info->path_transform, &x, &y); + _cairo_output_stream_printf (info->output, + "%g %g m ", x, y); + + return _cairo_output_stream_get_status (info->output); +} + +static cairo_status_t +_cairo_pdf_path_line_to (void *closure, + const cairo_point_t *point) +{ + pdf_path_info_t *info = closure; + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (info->line_cap != CAIRO_LINE_CAP_ROUND && + ! info->has_sub_path && + point->x == info->last_move_to_point.x && + point->y == info->last_move_to_point.y) + { + return CAIRO_STATUS_SUCCESS; + } + + info->has_sub_path = TRUE; + cairo_matrix_transform_point (info->path_transform, &x, &y); + _cairo_output_stream_printf (info->output, + "%g %g l ", x, y); + + return _cairo_output_stream_get_status (info->output); +} + +static cairo_status_t +_cairo_pdf_path_curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + pdf_path_info_t *info = closure; + double bx = _cairo_fixed_to_double (b->x); + double by = _cairo_fixed_to_double (b->y); + double cx = _cairo_fixed_to_double (c->x); + double cy = _cairo_fixed_to_double (c->y); + double dx = _cairo_fixed_to_double (d->x); + double dy = _cairo_fixed_to_double (d->y); + + info->has_sub_path = TRUE; + cairo_matrix_transform_point (info->path_transform, &bx, &by); + cairo_matrix_transform_point (info->path_transform, &cx, &cy); + cairo_matrix_transform_point (info->path_transform, &dx, &dy); + _cairo_output_stream_printf (info->output, + "%g %g %g %g %g %g c ", + bx, by, cx, cy, dx, dy); + return _cairo_output_stream_get_status (info->output); +} + +static cairo_status_t +_cairo_pdf_path_close_path (void *closure) +{ + pdf_path_info_t *info = closure; + + if (info->line_cap != CAIRO_LINE_CAP_ROUND && + ! info->has_sub_path) + { + return CAIRO_STATUS_SUCCESS; + } + + _cairo_output_stream_printf (info->output, + "h\n"); + + return _cairo_output_stream_get_status (info->output); +} + +static cairo_status_t +_cairo_pdf_path_rectangle (pdf_path_info_t *info, cairo_box_t *box) +{ + double x1 = _cairo_fixed_to_double (box->p1.x); + double y1 = _cairo_fixed_to_double (box->p1.y); + double x2 = _cairo_fixed_to_double (box->p2.x); + double y2 = _cairo_fixed_to_double (box->p2.y); + + cairo_matrix_transform_point (info->path_transform, &x1, &y1); + cairo_matrix_transform_point (info->path_transform, &x2, &y2); + _cairo_output_stream_printf (info->output, + "%g %g %g %g re ", + x1, y1, x2 - x1, y2 - y1); + + return _cairo_output_stream_get_status (info->output); +} + +/* The line cap value is needed to workaround the fact that PostScript + * and PDF semantics for stroking degenerate sub-paths do not match + * cairo semantics. (PostScript draws something for any line cap + * value, while cairo draws something only for round caps). + * + * When using this function to emit a path to be filled, rather than + * stroked, simply pass %CAIRO_LINE_CAP_ROUND which will guarantee that + * the stroke workaround will not modify the path being emitted. + */ +static cairo_status_t +_cairo_pdf_operators_emit_path (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t*path, + cairo_matrix_t *path_transform, + cairo_line_cap_t line_cap) +{ + cairo_output_stream_t *word_wrap; + cairo_status_t status, status2; + pdf_path_info_t info; + cairo_box_t box; + + word_wrap = _word_wrap_stream_create (pdf_operators->stream, pdf_operators->ps_output, 72); + status = _cairo_output_stream_get_status (word_wrap); + if (unlikely (status)) + return _cairo_output_stream_destroy (word_wrap); + + info.output = word_wrap; + info.path_transform = path_transform; + info.line_cap = line_cap; + if (_cairo_path_fixed_is_rectangle (path, &box) && + ((path_transform->xx == 0 && path_transform->yy == 0) || + (path_transform->xy == 0 && path_transform->yx == 0))) { + status = _cairo_pdf_path_rectangle (&info, &box); + } else { + status = _cairo_path_fixed_interpret (path, + _cairo_pdf_path_move_to, + _cairo_pdf_path_line_to, + _cairo_pdf_path_curve_to, + _cairo_pdf_path_close_path, + &info); + } + + status2 = _cairo_output_stream_destroy (word_wrap); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + return status; +} + +cairo_int_status_t +_cairo_pdf_operators_clip (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule) +{ + const char *pdf_operator; + cairo_status_t status; + + if (pdf_operators->in_text_object) { + status = _cairo_pdf_operators_end_text (pdf_operators); + if (unlikely (status)) + return status; + } + + if (! path->has_current_point) { + /* construct an empty path */ + _cairo_output_stream_printf (pdf_operators->stream, "0 0 m "); + } else { + status = _cairo_pdf_operators_emit_path (pdf_operators, + path, + &pdf_operators->cairo_to_pdf, + CAIRO_LINE_CAP_ROUND); + if (unlikely (status)) + return status; + } + + switch (fill_rule) { + default: + ASSERT_NOT_REACHED; + case CAIRO_FILL_RULE_WINDING: + pdf_operator = "W"; + break; + case CAIRO_FILL_RULE_EVEN_ODD: + pdf_operator = "W*"; + break; + } + + _cairo_output_stream_printf (pdf_operators->stream, + "%s n\n", + pdf_operator); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +static int +_cairo_pdf_line_cap (cairo_line_cap_t cap) +{ + switch (cap) { + case CAIRO_LINE_CAP_BUTT: + return 0; + case CAIRO_LINE_CAP_ROUND: + return 1; + case CAIRO_LINE_CAP_SQUARE: + return 2; + default: + ASSERT_NOT_REACHED; + return 0; + } +} + +static int +_cairo_pdf_line_join (cairo_line_join_t join) +{ + switch (join) { + case CAIRO_LINE_JOIN_MITER: + return 0; + case CAIRO_LINE_JOIN_ROUND: + return 1; + case CAIRO_LINE_JOIN_BEVEL: + return 2; + default: + ASSERT_NOT_REACHED; + return 0; + } +} + +cairo_int_status_t +_cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t *pdf_operators, + const cairo_stroke_style_t *style, + double scale) +{ + double *dash = style->dash; + int num_dashes = style->num_dashes; + double dash_offset = style->dash_offset; + double line_width = style->line_width * scale; + + /* PostScript has "special needs" when it comes to zero-length + * dash segments with butt caps. It apparently (at least + * according to ghostscript) draws hairlines for this + * case. That's not what the cairo semantics want, so we first + * touch up the array to eliminate any 0.0 values that will + * result in "on" segments. + */ + if (num_dashes && style->line_cap == CAIRO_LINE_CAP_BUTT) { + int i; + + /* If there's an odd number of dash values they will each get + * interpreted as both on and off. So we first explicitly + * expand the array to remove the duplicate usage so that we + * can modify some of the values. + */ + if (num_dashes % 2) { + dash = _cairo_malloc_abc (num_dashes, 2, sizeof (double)); + if (unlikely (dash == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (dash, style->dash, num_dashes * sizeof (double)); + memcpy (dash + num_dashes, style->dash, num_dashes * sizeof (double)); + + num_dashes *= 2; + } + + for (i = 0; i < num_dashes; i += 2) { + if (dash[i] == 0.0) { + /* Do not modify the dashes in-place, as we may need to also + * replay this stroke to an image fallback. + */ + if (dash == style->dash) { + dash = _cairo_malloc_ab (num_dashes, sizeof (double)); + if (unlikely (dash == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + memcpy (dash, style->dash, num_dashes * sizeof (double)); + } + + /* If we're at the front of the list, we first rotate + * two elements from the end of the list to the front + * of the list before folding away the 0.0. Or, if + * there are only two dash elements, then there is + * nothing at all to draw. + */ + if (i == 0) { + double last_two[2]; + + if (num_dashes == 2) { + free (dash); + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + /* The cases of num_dashes == 0, 1, or 3 elements + * cannot exist, so the rotation of 2 elements + * will always be safe */ + memcpy (last_two, dash + num_dashes - 2, sizeof (last_two)); + memmove (dash + 2, dash, (num_dashes - 2) * sizeof (double)); + memcpy (dash, last_two, sizeof (last_two)); + dash_offset += dash[0] + dash[1]; + i = 2; + } + dash[i-1] += dash[i+1]; + num_dashes -= 2; + memmove (dash + i, dash + i + 2, (num_dashes - i) * sizeof (double)); + /* If we might have just rotated, it's possible that + * we rotated a 0.0 value to the front of the list. + * Set i to -2 so it will get incremented to 0. */ + if (i == 2) + i = -2; + } + } + } + + if (!pdf_operators->has_line_style || pdf_operators->line_width != line_width) { + _cairo_output_stream_printf (pdf_operators->stream, + "%f w\n", + line_width); + pdf_operators->line_width = line_width; + } + + if (!pdf_operators->has_line_style || pdf_operators->line_cap != style->line_cap) { + _cairo_output_stream_printf (pdf_operators->stream, + "%d J\n", + _cairo_pdf_line_cap (style->line_cap)); + pdf_operators->line_cap = style->line_cap; + } + + if (!pdf_operators->has_line_style || pdf_operators->line_join != style->line_join) { + _cairo_output_stream_printf (pdf_operators->stream, + "%d j\n", + _cairo_pdf_line_join (style->line_join)); + pdf_operators->line_join = style->line_join; + } + + if (num_dashes) { + int d; + + _cairo_output_stream_printf (pdf_operators->stream, "["); + for (d = 0; d < num_dashes; d++) + _cairo_output_stream_printf (pdf_operators->stream, " %f", dash[d] * scale); + _cairo_output_stream_printf (pdf_operators->stream, "] %f d\n", + dash_offset * scale); + pdf_operators->has_dashes = TRUE; + } else if (!pdf_operators->has_line_style || pdf_operators->has_dashes) { + _cairo_output_stream_printf (pdf_operators->stream, "[] 0.0 d\n"); + pdf_operators->has_dashes = FALSE; + } + if (dash != style->dash) + free (dash); + + if (!pdf_operators->has_line_style || pdf_operators->miter_limit != style->miter_limit) { + _cairo_output_stream_printf (pdf_operators->stream, + "%f M ", + style->miter_limit < 1.0 ? 1.0 : style->miter_limit); + pdf_operators->miter_limit = style->miter_limit; + } + pdf_operators->has_line_style = TRUE; + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +/* Scale the matrix so the largest absolute value of the non + * translation components is 1.0. Return the scale required to restore + * the matrix to the original values. + * + * eg the matrix [ 100 0 0 50 20 10 ] + * + * is rescaled to [ 1 0 0 0.5 0.2 0.1 ] + * and the scale returned is 100 + */ +static void +_cairo_matrix_factor_out_scale (cairo_matrix_t *m, double *scale) +{ + double s; + + s = fabs (m->xx); + if (fabs (m->xy) > s) + s = fabs (m->xy); + if (fabs (m->yx) > s) + s = fabs (m->yx); + if (fabs (m->yy) > s) + s = fabs (m->yy); + *scale = s; + s = 1.0/s; + cairo_matrix_scale (m, s, s); +} + +static cairo_int_status_t +_cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + const char *pdf_operator) +{ + cairo_int_status_t status; + cairo_matrix_t m, path_transform; + cairo_bool_t has_ctm = TRUE; + double scale = 1.0; + + if (pdf_operators->in_text_object) { + status = _cairo_pdf_operators_end_text (pdf_operators); + if (unlikely (status)) + return status; + } + + /* Optimize away the stroke ctm when it does not affect the + * stroke. There are other ctm cases that could be optimized + * however this is the most common. + */ + if (fabs(ctm->xx) == 1.0 && fabs(ctm->yy) == 1.0 && + fabs(ctm->xy) == 0.0 && fabs(ctm->yx) == 0.0) + { + has_ctm = FALSE; + } + + /* The PDF CTM is transformed to the user space CTM when stroking + * so the corect pen shape will be used. This also requires that + * the path be transformed to user space when emitted. The + * conversion of path coordinates to user space may cause rounding + * errors. For example the device space point (1.234, 3.142) when + * transformed to a user space CTM of [100 0 0 100 0 0] will be + * emitted as (0.012, 0.031). + * + * To avoid the rounding problem we scale the user space CTM + * matrix so that all the non translation components of the matrix + * are <= 1. The line width and and dashes are scaled by the + * inverse of the scale applied to the CTM. This maintains the + * shape of the stroke pen while keeping the user space CTM within + * the range that maximizes the precision of the emitted path. + */ + if (has_ctm) { + m = *ctm; + /* Zero out the translation since it does not affect the pen + * shape however it may cause unnecessary digits to be emitted. + */ + m.x0 = 0.0; + m.y0 = 0.0; + _cairo_matrix_factor_out_scale (&m, &scale); + path_transform = m; + status = cairo_matrix_invert (&path_transform); + if (unlikely (status)) + return status; + + cairo_matrix_multiply (&m, &m, &pdf_operators->cairo_to_pdf); + } + + status = _cairo_pdf_operators_emit_stroke_style (pdf_operators, style, scale); + if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) + return CAIRO_STATUS_SUCCESS; + if (unlikely (status)) + return status; + + if (has_ctm) { + _cairo_output_stream_printf (pdf_operators->stream, "q "); + _cairo_output_stream_print_matrix (pdf_operators->stream, &m); + _cairo_output_stream_printf (pdf_operators->stream, " cm\n"); + } else { + path_transform = pdf_operators->cairo_to_pdf; + } + + status = _cairo_pdf_operators_emit_path (pdf_operators, + path, + &path_transform, + style->line_cap); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (pdf_operators->stream, "%s", pdf_operator); + if (has_ctm) + _cairo_output_stream_printf (pdf_operators->stream, " Q"); + + _cairo_output_stream_printf (pdf_operators->stream, "\n"); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +cairo_int_status_t +_cairo_pdf_operators_stroke (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse) +{ + return _cairo_pdf_operators_emit_stroke (pdf_operators, + path, + style, + ctm, + ctm_inverse, + "S"); +} + +cairo_int_status_t +_cairo_pdf_operators_fill (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule) +{ + const char *pdf_operator; + cairo_status_t status; + + if (pdf_operators->in_text_object) { + status = _cairo_pdf_operators_end_text (pdf_operators); + if (unlikely (status)) + return status; + } + + status = _cairo_pdf_operators_emit_path (pdf_operators, + path, + &pdf_operators->cairo_to_pdf, + CAIRO_LINE_CAP_ROUND); + if (unlikely (status)) + return status; + + switch (fill_rule) { + default: + ASSERT_NOT_REACHED; + case CAIRO_FILL_RULE_WINDING: + pdf_operator = "f"; + break; + case CAIRO_FILL_RULE_EVEN_ODD: + pdf_operator = "f*"; + break; + } + + _cairo_output_stream_printf (pdf_operators->stream, + "%s\n", + pdf_operator); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +cairo_int_status_t +_cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t *pdf_operators, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse) +{ + const char *operator; + + switch (fill_rule) { + default: + ASSERT_NOT_REACHED; + case CAIRO_FILL_RULE_WINDING: + operator = "B"; + break; + case CAIRO_FILL_RULE_EVEN_ODD: + operator = "B*"; + break; + } + + return _cairo_pdf_operators_emit_stroke (pdf_operators, + path, + style, + ctm, + ctm_inverse, + operator); +} + +static void +_cairo_pdf_operators_emit_glyph_index (cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream, + unsigned int glyph) +{ + if (pdf_operators->is_latin) { + if (glyph == '(' || glyph == ')' || glyph == '\\') + _cairo_output_stream_printf (stream, "\\%c", glyph); + else if (glyph >= 0x20 && glyph <= 0x7e) + _cairo_output_stream_printf (stream, "%c", glyph); + else + _cairo_output_stream_printf (stream, "\\%03o", glyph); + } else { + _cairo_output_stream_printf (stream, + "%0*x", + pdf_operators->hex_width, + glyph); + } +} + +#define GLYPH_POSITION_TOLERANCE 0.001 + +/* Emit the string of glyphs using the 'Tj' operator. This requires + * that the glyphs are positioned at their natural glyph advances. */ +static cairo_status_t +_cairo_pdf_operators_emit_glyph_string (cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream) +{ + int i; + + _cairo_output_stream_printf (stream, "%s", pdf_operators->is_latin ? "(" : "<"); + for (i = 0; i < pdf_operators->num_glyphs; i++) { + _cairo_pdf_operators_emit_glyph_index (pdf_operators, + stream, + pdf_operators->glyphs[i].glyph_index); + pdf_operators->cur_x += pdf_operators->glyphs[i].x_advance; + } + _cairo_output_stream_printf (stream, "%sTj\n", pdf_operators->is_latin ? ")" : ">"); + + return _cairo_output_stream_get_status (stream); +} + +/* Emit the string of glyphs using the 'TJ' operator. + * + * The TJ operator takes an array of strings of glyphs. Each string of + * glyphs is displayed using the glyph advances of each glyph to + * position the glyphs. A relative adjustment to the glyph advance may + * be specified by including the adjustment between two strings. The + * adjustment is in units of text space * -1000. + */ +static cairo_status_t +_cairo_pdf_operators_emit_glyph_string_with_positioning ( + cairo_pdf_operators_t *pdf_operators, + cairo_output_stream_t *stream) +{ + int i; + + _cairo_output_stream_printf (stream, "[%s", pdf_operators->is_latin ? "(" : "<"); + for (i = 0; i < pdf_operators->num_glyphs; i++) { + if (pdf_operators->glyphs[i].x_position != pdf_operators->cur_x) + { + double delta = pdf_operators->glyphs[i].x_position - pdf_operators->cur_x; + int rounded_delta; + + delta = -1000.0*delta; + /* As the delta is in 1/1000 of a unit of text space, + * rounding to an integer should still provide sufficient + * precision. We round the delta before adding to Tm_x so + * that we keep track of the accumulated rounding error in + * the PDF interpreter and compensate for it when + * calculating subsequent deltas. + */ + rounded_delta = _cairo_lround (delta); + if (abs(rounded_delta) < 3) + rounded_delta = 0; + if (rounded_delta != 0) { + if (pdf_operators->is_latin) { + _cairo_output_stream_printf (stream, + ")%d(", + rounded_delta); + } else { + _cairo_output_stream_printf (stream, + ">%d<", + rounded_delta); + } + } + + /* Convert the rounded delta back to text + * space before adding to the current text + * position. */ + delta = rounded_delta/-1000.0; + pdf_operators->cur_x += delta; + } + + _cairo_pdf_operators_emit_glyph_index (pdf_operators, + stream, + pdf_operators->glyphs[i].glyph_index); + pdf_operators->cur_x += pdf_operators->glyphs[i].x_advance; + } + _cairo_output_stream_printf (stream, "%s]TJ\n", pdf_operators->is_latin ? ")" : ">"); + + return _cairo_output_stream_get_status (stream); +} + +static cairo_status_t +_cairo_pdf_operators_flush_glyphs (cairo_pdf_operators_t *pdf_operators) +{ + cairo_output_stream_t *word_wrap_stream; + cairo_status_t status, status2; + int i; + double x; + + if (pdf_operators->num_glyphs == 0) + return CAIRO_STATUS_SUCCESS; + + word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, pdf_operators->ps_output, 72); + status = _cairo_output_stream_get_status (word_wrap_stream); + if (unlikely (status)) + return _cairo_output_stream_destroy (word_wrap_stream); + + /* Check if glyph advance used to position every glyph */ + x = pdf_operators->cur_x; + for (i = 0; i < pdf_operators->num_glyphs; i++) { + if (fabs(pdf_operators->glyphs[i].x_position - x) > GLYPH_POSITION_TOLERANCE) + break; + x += pdf_operators->glyphs[i].x_advance; + } + if (i == pdf_operators->num_glyphs) { + status = _cairo_pdf_operators_emit_glyph_string (pdf_operators, + word_wrap_stream); + } else { + status = _cairo_pdf_operators_emit_glyph_string_with_positioning ( + pdf_operators, word_wrap_stream); + } + + pdf_operators->num_glyphs = 0; + pdf_operators->glyph_buf_x_pos = pdf_operators->cur_x; + status2 = _cairo_output_stream_destroy (word_wrap_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + return status; +} + +static cairo_status_t +_cairo_pdf_operators_add_glyph (cairo_pdf_operators_t *pdf_operators, + cairo_scaled_font_subsets_glyph_t *glyph, + double x_position) +{ + double x, y; + + x = glyph->x_advance; + y = glyph->y_advance; + if (glyph->is_scaled) + cairo_matrix_transform_distance (&pdf_operators->font_matrix_inverse, &x, &y); + + pdf_operators->glyphs[pdf_operators->num_glyphs].x_position = x_position; + pdf_operators->glyphs[pdf_operators->num_glyphs].glyph_index = glyph->subset_glyph_index; + pdf_operators->glyphs[pdf_operators->num_glyphs].x_advance = x; + pdf_operators->glyph_buf_x_pos += x; + pdf_operators->num_glyphs++; + if (pdf_operators->num_glyphs == PDF_GLYPH_BUFFER_SIZE) + return _cairo_pdf_operators_flush_glyphs (pdf_operators); + + return CAIRO_STATUS_SUCCESS; +} + +/* Use 'Tm' operator to set the PDF text matrix. */ +static cairo_status_t +_cairo_pdf_operators_set_text_matrix (cairo_pdf_operators_t *pdf_operators, + cairo_matrix_t *matrix) +{ + cairo_matrix_t inverse; + cairo_status_t status; + + /* We require the matrix to be invertable. */ + inverse = *matrix; + status = cairo_matrix_invert (&inverse); + if (unlikely (status)) + return status; + + pdf_operators->text_matrix = *matrix; + pdf_operators->cur_x = 0; + pdf_operators->cur_y = 0; + pdf_operators->glyph_buf_x_pos = 0; + _cairo_output_stream_print_matrix (pdf_operators->stream, &pdf_operators->text_matrix); + _cairo_output_stream_printf (pdf_operators->stream, " Tm\n"); + + pdf_operators->cairo_to_pdftext = *matrix; + status = cairo_matrix_invert (&pdf_operators->cairo_to_pdftext); + assert (status == CAIRO_STATUS_SUCCESS); + cairo_matrix_multiply (&pdf_operators->cairo_to_pdftext, + &pdf_operators->cairo_to_pdf, + &pdf_operators->cairo_to_pdftext); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +#define TEXT_MATRIX_TOLERANCE 1e-6 + +/* Set the translation components of the PDF text matrix to x, y. The + * 'Td' operator is used to transform the text matrix. + */ +static cairo_status_t +_cairo_pdf_operators_set_text_position (cairo_pdf_operators_t *pdf_operators, + double x, + double y) +{ + cairo_matrix_t translate, inverse; + cairo_status_t status; + + /* The Td operator transforms the text_matrix with: + * + * text_matrix' = T x text_matrix + * + * where T is a translation matrix with the translation components + * set to the Td operands tx and ty. + */ + inverse = pdf_operators->text_matrix; + status = cairo_matrix_invert (&inverse); + assert (status == CAIRO_STATUS_SUCCESS); + pdf_operators->text_matrix.x0 = x; + pdf_operators->text_matrix.y0 = y; + cairo_matrix_multiply (&translate, &pdf_operators->text_matrix, &inverse); + if (fabs(translate.x0) < TEXT_MATRIX_TOLERANCE) + translate.x0 = 0.0; + if (fabs(translate.y0) < TEXT_MATRIX_TOLERANCE) + translate.y0 = 0.0; + _cairo_output_stream_printf (pdf_operators->stream, + "%f %f Td\n", + translate.x0, + translate.y0); + pdf_operators->cur_x = 0; + pdf_operators->cur_y = 0; + pdf_operators->glyph_buf_x_pos = 0; + + pdf_operators->cairo_to_pdftext = pdf_operators->text_matrix; + status = cairo_matrix_invert (&pdf_operators->cairo_to_pdftext); + assert (status == CAIRO_STATUS_SUCCESS); + cairo_matrix_multiply (&pdf_operators->cairo_to_pdftext, + &pdf_operators->cairo_to_pdf, + &pdf_operators->cairo_to_pdftext); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +/* Select the font using the 'Tf' operator. The font size is set to 1 + * as we use the 'Tm' operator to set the font scale. + */ +static cairo_status_t +_cairo_pdf_operators_set_font_subset (cairo_pdf_operators_t *pdf_operators, + cairo_scaled_font_subsets_glyph_t *subset_glyph) +{ + cairo_status_t status; + + _cairo_output_stream_printf (pdf_operators->stream, + "/f-%d-%d 1 Tf\n", + subset_glyph->font_id, + subset_glyph->subset_id); + if (pdf_operators->use_font_subset) { + status = pdf_operators->use_font_subset (subset_glyph->font_id, + subset_glyph->subset_id, + pdf_operators->use_font_subset_closure); + if (unlikely (status)) + return status; + } + pdf_operators->font_id = subset_glyph->font_id; + pdf_operators->subset_id = subset_glyph->subset_id; + pdf_operators->is_latin = subset_glyph->is_latin; + + if (subset_glyph->is_composite) + pdf_operators->hex_width = 4; + else + pdf_operators->hex_width = 2; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_pdf_operators_begin_text (cairo_pdf_operators_t *pdf_operators) +{ + _cairo_output_stream_printf (pdf_operators->stream, "BT\n"); + + pdf_operators->in_text_object = TRUE; + pdf_operators->num_glyphs = 0; + pdf_operators->glyph_buf_x_pos = 0; + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +static cairo_status_t +_cairo_pdf_operators_end_text (cairo_pdf_operators_t *pdf_operators) +{ + cairo_status_t status; + + status = _cairo_pdf_operators_flush_glyphs (pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (pdf_operators->stream, "ET\n"); + + pdf_operators->in_text_object = FALSE; + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +/* Compare the scale components of two matrices. The translation + * components are ignored. */ +static cairo_bool_t +_cairo_matrix_scale_equal (cairo_matrix_t *a, cairo_matrix_t *b) +{ + return (a->xx == b->xx && + a->xy == b->xy && + a->yx == b->yx && + a->yy == b->yy); +} + +static cairo_status_t +_cairo_pdf_operators_begin_actualtext (cairo_pdf_operators_t *pdf_operators, + const char *utf8, + int utf8_len) +{ + uint16_t *utf16; + int utf16_len; + cairo_status_t status; + int i; + + _cairo_output_stream_printf (pdf_operators->stream, "/Span << /ActualText stream, + "%04x", (int) (utf16[i])); + } + free (utf16); + } + _cairo_output_stream_printf (pdf_operators->stream, "> >> BDC\n"); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +static cairo_status_t +_cairo_pdf_operators_end_actualtext (cairo_pdf_operators_t *pdf_operators) +{ + _cairo_output_stream_printf (pdf_operators->stream, "EMC\n"); + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +static cairo_status_t +_cairo_pdf_operators_emit_glyph (cairo_pdf_operators_t *pdf_operators, + cairo_glyph_t *glyph, + cairo_scaled_font_subsets_glyph_t *subset_glyph) +{ + double x, y; + cairo_status_t status; + + if (pdf_operators->is_new_text_object || + pdf_operators->font_id != subset_glyph->font_id || + pdf_operators->subset_id != subset_glyph->subset_id) + { + status = _cairo_pdf_operators_flush_glyphs (pdf_operators); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_set_font_subset (pdf_operators, subset_glyph); + if (unlikely (status)) + return status; + + pdf_operators->is_new_text_object = FALSE; + } + + x = glyph->x; + y = glyph->y; + cairo_matrix_transform_point (&pdf_operators->cairo_to_pdftext, &x, &y); + + /* The TJ operator for displaying text strings can only set + * the horizontal position of the glyphs. If the y position + * (in text space) changes, use the Td operator to change the + * current position to the next glyph. We also use the Td + * operator to move the current position if the horizontal + * position changes by more than 10 (in text space + * units). This is becauses the horizontal glyph positioning + * in the TJ operator is intended for kerning and there may be + * PDF consumers that do not handle very large position + * adjustments in TJ. + */ + if (fabs(x - pdf_operators->glyph_buf_x_pos) > 10 || + fabs(y - pdf_operators->cur_y) > GLYPH_POSITION_TOLERANCE) + { + status = _cairo_pdf_operators_flush_glyphs (pdf_operators); + if (unlikely (status)) + return status; + + x = glyph->x; + y = glyph->y; + cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &x, &y); + status = _cairo_pdf_operators_set_text_position (pdf_operators, x, y); + if (unlikely (status)) + return status; + + x = 0.0; + y = 0.0; + } + + status = _cairo_pdf_operators_add_glyph (pdf_operators, + subset_glyph, + x); + return status; +} + +/* A utf8_len of -1 indicates no unicode text. A utf8_len = 0 is an + * empty string. + */ +static cairo_int_status_t +_cairo_pdf_operators_emit_cluster (cairo_pdf_operators_t *pdf_operators, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font) +{ + cairo_scaled_font_subsets_glyph_t subset_glyph; + cairo_glyph_t *cur_glyph; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + int i; + + /* If the cluster maps 1 glyph to 1 or more unicode characters, we + * first try _map_glyph() with the unicode string to see if it can + * use toUnicode to map our glyph to the unicode. This will fail + * if the glyph is already mapped to a different unicode string. + * + * We also go through this path if no unicode mapping was + * supplied (utf8_len < 0). + * + * Mapping a glyph to a zero length unicode string requires the + * use of ActualText. + */ + if (num_glyphs == 1 && utf8_len != 0) { + status = _cairo_scaled_font_subsets_map_glyph (pdf_operators->font_subsets, + scaled_font, + glyphs->index, + utf8, + utf8_len, + &subset_glyph); + if (unlikely (status)) + return status; + + if (subset_glyph.utf8_is_mapped || utf8_len < 0) { + status = _cairo_pdf_operators_emit_glyph (pdf_operators, + glyphs, + &subset_glyph); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; + } + } + + if (pdf_operators->use_actual_text) { + /* Fallback to using ActualText to map zero or more glyphs to a + * unicode string. */ + status = _cairo_pdf_operators_flush_glyphs (pdf_operators); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_begin_actualtext (pdf_operators, utf8, utf8_len); + if (unlikely (status)) + return status; + } + + if (cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD) + cur_glyph = glyphs + num_glyphs - 1; + else + cur_glyph = glyphs; + + /* XXX + * If no glyphs, we should put *something* here for the text to be selectable. */ + for (i = 0; i < num_glyphs; i++) { + status = _cairo_scaled_font_subsets_map_glyph (pdf_operators->font_subsets, + scaled_font, + cur_glyph->index, + NULL, -1, + &subset_glyph); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_emit_glyph (pdf_operators, + cur_glyph, + &subset_glyph); + if (unlikely (status)) + return status; + + if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) + cur_glyph--; + else + cur_glyph++; + } + + if (pdf_operators->use_actual_text) { + status = _cairo_pdf_operators_flush_glyphs (pdf_operators); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_end_actualtext (pdf_operators); + } + + return status; +} + +cairo_int_status_t +_cairo_pdf_operators_show_text_glyphs (cairo_pdf_operators_t *pdf_operators, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font) +{ + cairo_status_t status; + int i; + cairo_matrix_t text_matrix, invert_y_axis; + double x, y; + const char *cur_text; + cairo_glyph_t *cur_glyph; + + pdf_operators->font_matrix_inverse = scaled_font->font_matrix; + status = cairo_matrix_invert (&pdf_operators->font_matrix_inverse); + if (status == CAIRO_STATUS_INVALID_MATRIX) + return CAIRO_STATUS_SUCCESS; + assert (status == CAIRO_STATUS_SUCCESS); + + pdf_operators->is_new_text_object = FALSE; + if (pdf_operators->in_text_object == FALSE) { + status = _cairo_pdf_operators_begin_text (pdf_operators); + if (unlikely (status)) + return status; + + /* Force Tm and Tf to be emitted when starting a new text + * object.*/ + pdf_operators->is_new_text_object = TRUE; + } + + cairo_matrix_init_scale (&invert_y_axis, 1, -1); + text_matrix = scaled_font->scale; + + /* Invert y axis in font space */ + cairo_matrix_multiply (&text_matrix, &text_matrix, &invert_y_axis); + + /* Invert y axis in device space */ + cairo_matrix_multiply (&text_matrix, &invert_y_axis, &text_matrix); + + if (pdf_operators->is_new_text_object || + ! _cairo_matrix_scale_equal (&pdf_operators->text_matrix, &text_matrix)) + { + status = _cairo_pdf_operators_flush_glyphs (pdf_operators); + if (unlikely (status)) + return status; + + x = glyphs[0].x; + y = glyphs[0].y; + cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &x, &y); + text_matrix.x0 = x; + text_matrix.y0 = y; + status = _cairo_pdf_operators_set_text_matrix (pdf_operators, &text_matrix); + if (status == CAIRO_STATUS_INVALID_MATRIX) + return CAIRO_STATUS_SUCCESS; + if (unlikely (status)) + return status; + } + + if (num_clusters > 0) { + cur_text = utf8; + if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) + cur_glyph = glyphs + num_glyphs; + else + cur_glyph = glyphs; + for (i = 0; i < num_clusters; i++) { + if ((cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) + cur_glyph -= clusters[i].num_glyphs; + status = _cairo_pdf_operators_emit_cluster (pdf_operators, + cur_text, + clusters[i].num_bytes, + cur_glyph, + clusters[i].num_glyphs, + cluster_flags, + scaled_font); + if (unlikely (status)) + return status; + + cur_text += clusters[i].num_bytes; + if (!(cluster_flags & CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)) + cur_glyph += clusters[i].num_glyphs; + } + } else { + for (i = 0; i < num_glyphs; i++) { + status = _cairo_pdf_operators_emit_cluster (pdf_operators, + NULL, + -1, /* no unicode string available */ + &glyphs[i], + 1, + FALSE, + scaled_font); + if (unlikely (status)) + return status; + } + } + + return _cairo_output_stream_get_status (pdf_operators->stream); +} + +#endif /* CAIRO_HAS_PDF_OPERATORS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading-private.h new file mode 100644 index 00000000000..0ca8cb7d518 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading-private.h @@ -0,0 +1,100 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + */ + +#ifndef CAIRO_PDF_SHADING_H +#define CAIRO_PDF_SHADING_H + +#include "cairo-compiler-private.h" +#include "cairo-types-private.h" +#include "cairo-pattern-private.h" + + +typedef struct _cairo_pdf_shading { + int shading_type; + int bits_per_coordinate; + int bits_per_component; + int bits_per_flag; + double *decode_array; + int decode_array_length; + unsigned char *data; + unsigned long data_length; +} cairo_pdf_shading_t; + + +/** + * _cairo_pdf_shading_init_color: + * @shading: a #cairo_pdf_shading_t to initialize + * @pattern: the #cairo_mesh_pattern_t to initialize from + * + * Generate the PDF shading dictionary data for the a PDF type 7 + * shading from RGB part of the specified mesh pattern. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_pdf_shading_init_color (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *pattern); + + +/** + * _cairo_pdf_shading_init_alpha: + * @shading: a #cairo_pdf_shading_t to initialize + * @pattern: the #cairo_mesh_pattern_t to initialize from + * + * Generate the PDF shading dictionary data for a PDF type 7 + * shading from alpha part of the specified mesh pattern. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_pdf_shading_init_alpha (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *pattern); + +/** + * _cairo_pdf_shading_fini: + * @shading: a #cairo_pdf_shading_t + * + * Free all resources associated with @shading. After this call, + * @shading should not be used again without a subsequent call to + * _cairo_pdf_shading_init() again first. + **/ +cairo_private void +_cairo_pdf_shading_fini (cairo_pdf_shading_t *shading); + + +#endif /* CAIRO_PDF_SHADING_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading.c b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading.c new file mode 100644 index 00000000000..646e2cd4902 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-shading.c @@ -0,0 +1,279 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_PDF_OPERATORS + +#include "cairo-pdf-shading-private.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" +#include + +static unsigned char * +encode_coordinate (unsigned char *p, double c) +{ + uint32_t f; + + f = c; + *p++ = f >> 24; + *p++ = (f >> 16) & 0xff; + *p++ = (f >> 8) & 0xff; + *p++ = f & 0xff; + + return p; +} + +static unsigned char * +encode_point (unsigned char *p, const cairo_point_double_t *point) +{ + p = encode_coordinate (p, point->x); + p = encode_coordinate (p, point->y); + + return p; +} + +static unsigned char * +encode_color_component (unsigned char *p, double color) +{ + uint16_t c; + + c = _cairo_color_double_to_short (color); + *p++ = c >> 8; + *p++ = c & 0xff; + + return p; +} + +static unsigned char * +encode_color (unsigned char *p, const cairo_color_t *color) +{ + p = encode_color_component (p, color->red); + p = encode_color_component (p, color->green); + p = encode_color_component (p, color->blue); + + return p; +} + +static unsigned char * +encode_alpha (unsigned char *p, const cairo_color_t *color) +{ + p = encode_color_component (p, color->alpha); + + return p; +} + +static cairo_status_t +_cairo_pdf_shading_generate_decode_array (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *mesh, + cairo_bool_t is_alpha) +{ + unsigned int num_color_components, i; + cairo_bool_t is_valid; + + if (is_alpha) + num_color_components = 1; + else + num_color_components = 3; + + shading->decode_array_length = 4 + num_color_components * 2; + shading->decode_array = _cairo_malloc_ab (shading->decode_array_length, + sizeof (double)); + if (unlikely (shading->decode_array == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + is_valid = _cairo_mesh_pattern_coord_box (mesh, + &shading->decode_array[0], + &shading->decode_array[2], + &shading->decode_array[1], + &shading->decode_array[3]); + + assert (is_valid); + assert (shading->decode_array[1] - shading->decode_array[0] >= DBL_EPSILON); + assert (shading->decode_array[3] - shading->decode_array[2] >= DBL_EPSILON); + + for (i = 0; i < num_color_components; i++) { + shading->decode_array[4 + 2*i] = 0; + shading->decode_array[5 + 2*i] = 1; + } + + return CAIRO_STATUS_SUCCESS; +} + +/* The ISO32000 specification mandates this order for the points which + * define the patch. */ +static const int pdf_points_order_i[16] = { + 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2 }; +static const int pdf_points_order_j[16] = { + 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1 }; + +static cairo_status_t +_cairo_pdf_shading_generate_data (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *mesh, + cairo_bool_t is_alpha) +{ + const cairo_mesh_patch_t *patch; + double x_off, y_off, x_scale, y_scale; + unsigned int num_patches; + unsigned int num_color_components; + unsigned char *p; + unsigned int i, j; + + if (is_alpha) + num_color_components = 1; + else + num_color_components = 3; + + num_patches = _cairo_array_num_elements (&mesh->patches); + patch = _cairo_array_index_const (&mesh->patches, 0); + + /* Each patch requires: + * + * 1 flag - 1 byte + * 16 points. Each point is 2 coordinates. Each coordinate is + * stored in 4 bytes. + * + * 4 colors. Each color is stored in 2 bytes * num_color_components. + */ + shading->data_length = num_patches * (1 + 16 * 2 * 4 + 4 * 2 * num_color_components); + shading->data = malloc (shading->data_length); + if (unlikely (shading->data == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + x_off = shading->decode_array[0]; + y_off = shading->decode_array[2]; + x_scale = UINT32_MAX / (shading->decode_array[1] - x_off); + y_scale = UINT32_MAX / (shading->decode_array[3] - y_off); + + p = shading->data; + for (i = 0; i < num_patches; i++) { + /* edge flag */ + *p++ = 0; + + /* 16 points */ + for (j = 0; j < 16; j++) { + cairo_point_double_t point; + int pi, pj; + + pi = pdf_points_order_i[j]; + pj = pdf_points_order_j[j]; + point = patch[i].points[pi][pj]; + + /* Transform the point as specified in the decode array */ + point.x -= x_off; + point.y -= y_off; + point.x *= x_scale; + point.y *= y_scale; + + /* Make sure that rounding errors don't cause + * wraparounds */ + point.x = _cairo_restrict_value (point.x, 0, UINT32_MAX); + point.y = _cairo_restrict_value (point.y, 0, UINT32_MAX); + + p = encode_point (p, &point); + } + + /* 4 colors */ + for (j = 0; j < 4; j++) { + if (is_alpha) + p = encode_alpha (p, &patch[i].colors[j]); + else + p = encode_color (p, &patch[i].colors[j]); + } + } + + assert (p == shading->data + shading->data_length); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_pdf_shading_init (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *mesh, + cairo_bool_t is_alpha) +{ + cairo_status_t status; + + assert (mesh->base.status == CAIRO_STATUS_SUCCESS); + assert (mesh->current_patch == NULL); + + shading->shading_type = 7; + + /* + * Coordinates from the minimum to the maximum value of the mesh + * map to the [0..UINT32_MAX] range and are represented as + * uint32_t values. + * + * Color components are represented as uint16_t (in a 0.16 fixed + * point format, as in the rest of cairo). + */ + shading->bits_per_coordinate = 32; + shading->bits_per_component = 16; + shading->bits_per_flag = 8; + + shading->decode_array = NULL; + shading->data = NULL; + + status = _cairo_pdf_shading_generate_decode_array (shading, mesh, is_alpha); + if (unlikely (status)) + return status; + + return _cairo_pdf_shading_generate_data (shading, mesh, is_alpha); +} + +cairo_status_t +_cairo_pdf_shading_init_color (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *pattern) +{ + return _cairo_pdf_shading_init (shading, pattern, FALSE); +} + +cairo_status_t +_cairo_pdf_shading_init_alpha (cairo_pdf_shading_t *shading, + const cairo_mesh_pattern_t *pattern) +{ + return _cairo_pdf_shading_init (shading, pattern, TRUE); +} + +void +_cairo_pdf_shading_fini (cairo_pdf_shading_t *shading) +{ + free (shading->data); + free (shading->decode_array); +} + +#endif /* CAIRO_HAS_PDF_OPERATORS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface-private.h new file mode 100644 index 00000000000..618ca4ede9f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface-private.h @@ -0,0 +1,218 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * Copyright © 2006 Red Hat, Inc + * Copyright © 2007, 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Carl Worth + * Adrian Johnson + */ + +#ifndef CAIRO_PDF_SURFACE_PRIVATE_H +#define CAIRO_PDF_SURFACE_PRIVATE_H + +#include "cairo-pdf.h" + +#include "cairo-surface-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-pdf-operators-private.h" +#include "cairo-path-fixed-private.h" + +typedef struct _cairo_pdf_resource { + unsigned int id; +} cairo_pdf_resource_t; + +#define CAIRO_NUM_OPERATORS (CAIRO_OPERATOR_HSL_LUMINOSITY + 1) + +typedef struct _cairo_pdf_group_resources { + cairo_bool_t operators[CAIRO_NUM_OPERATORS]; + cairo_array_t alphas; + cairo_array_t smasks; + cairo_array_t patterns; + cairo_array_t shadings; + cairo_array_t xobjects; + cairo_array_t fonts; +} cairo_pdf_group_resources_t; + +typedef struct _cairo_pdf_source_surface_entry { + cairo_hash_entry_t base; + unsigned int id; + unsigned char *unique_id; + unsigned long unique_id_length; + cairo_operator_t operator; + cairo_bool_t interpolate; + cairo_bool_t stencil_mask; + cairo_bool_t smask; + cairo_pdf_resource_t surface_res; + cairo_pdf_resource_t smask_res; + int width; + int height; + cairo_rectangle_int_t extents; +} cairo_pdf_source_surface_entry_t; + +typedef struct _cairo_pdf_source_surface { + cairo_pattern_type_t type; + cairo_surface_t *surface; + cairo_pattern_t *raster_pattern; + cairo_pdf_source_surface_entry_t *hash_entry; +} cairo_pdf_source_surface_t; + +typedef struct _cairo_pdf_pattern { + double width; + double height; + cairo_rectangle_int_t extents; + cairo_pattern_t *pattern; + cairo_pdf_resource_t pattern_res; + cairo_pdf_resource_t gstate_res; + cairo_operator_t operator; + cairo_bool_t is_shading; +} cairo_pdf_pattern_t; + +typedef enum _cairo_pdf_operation { + PDF_PAINT, + PDF_MASK, + PDF_FILL, + PDF_STROKE, + PDF_SHOW_GLYPHS +} cairo_pdf_operation_t; + +typedef struct _cairo_pdf_smask_group { + double width; + double height; + cairo_rectangle_int_t extents; + cairo_pdf_resource_t group_res; + cairo_pdf_operation_t operation; + cairo_pattern_t *source; + cairo_pdf_resource_t source_res; + cairo_pattern_t *mask; + cairo_path_fixed_t path; + cairo_fill_rule_t fill_rule; + cairo_stroke_style_t style; + cairo_matrix_t ctm; + cairo_matrix_t ctm_inverse; + char *utf8; + int utf8_len; + cairo_glyph_t *glyphs; + int num_glyphs; + cairo_text_cluster_t *clusters; + int num_clusters; + cairo_bool_t cluster_flags; + cairo_scaled_font_t *scaled_font; +} cairo_pdf_smask_group_t; + +typedef struct _cairo_pdf_jbig2_global { + unsigned char *id; + unsigned long id_length; + cairo_pdf_resource_t res; + cairo_bool_t emitted; +} cairo_pdf_jbig2_global_t; + +typedef struct _cairo_pdf_surface cairo_pdf_surface_t; + +struct _cairo_pdf_surface { + cairo_surface_t base; + + /* Prefer the name "output" here to avoid confusion over the + * structure within a PDF document known as a "stream". */ + cairo_output_stream_t *output; + + double width; + double height; + cairo_matrix_t cairo_to_pdf; + + cairo_array_t objects; + cairo_array_t pages; + cairo_array_t rgb_linear_functions; + cairo_array_t alpha_linear_functions; + cairo_array_t page_patterns; + cairo_array_t page_surfaces; + cairo_hash_table_t *all_surfaces; + cairo_array_t smask_groups; + cairo_array_t knockout_group; + cairo_array_t jbig2_global; + + cairo_scaled_font_subsets_t *font_subsets; + cairo_array_t fonts; + + cairo_pdf_resource_t next_available_resource; + cairo_pdf_resource_t pages_resource; + + cairo_pdf_version_t pdf_version; + cairo_bool_t compress_content; + + cairo_pdf_resource_t content; + cairo_pdf_resource_t content_resources; + cairo_pdf_group_resources_t resources; + cairo_bool_t has_fallback_images; + cairo_bool_t header_emitted; + + struct { + cairo_bool_t active; + cairo_pdf_resource_t self; + cairo_pdf_resource_t length; + long start_offset; + cairo_bool_t compressed; + cairo_output_stream_t *old_output; + } pdf_stream; + + struct { + cairo_bool_t active; + cairo_output_stream_t *stream; + cairo_output_stream_t *mem_stream; + cairo_output_stream_t *old_output; + cairo_pdf_resource_t resource; + cairo_box_double_t bbox; + cairo_bool_t is_knockout; + } group_stream; + + cairo_surface_clipper_t clipper; + + cairo_pdf_operators_t pdf_operators; + cairo_paginated_mode_t paginated_mode; + cairo_bool_t select_pattern_gstate_saved; + + cairo_bool_t force_fallbacks; + + cairo_operator_t current_operator; + cairo_bool_t current_pattern_is_solid_color; + cairo_bool_t current_color_is_stroke; + double current_color_red; + double current_color_green; + double current_color_blue; + double current_color_alpha; + + cairo_surface_t *paginated_surface; +}; + +#endif /* CAIRO_PDF_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface.c new file mode 100644 index 00000000000..4bc2947964e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf-surface.c @@ -0,0 +1,7880 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * Copyright © 2006 Red Hat, Inc + * Copyright © 2007, 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Carl Worth + * Adrian Johnson + */ + +#define _BSD_SOURCE /* for snprintf() */ +#include "cairoint.h" + +#include "cairo-pdf.h" +#include "cairo-pdf-surface-private.h" +#include "cairo-pdf-operators-private.h" +#include "cairo-pdf-shading-private.h" + +#include "cairo-array-private.h" +#include "cairo-analysis-surface-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-image-info-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-paginated-private.h" +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-private.h" +#include "cairo-type3-glyph-surface-private.h" + +#include +#include + +/* Issues: + * + * - We embed an image in the stream each time it's composited. We + * could add generation counters to surfaces and remember the stream + * ID for a particular generation for a particular surface. + * + * - Backend specific meta data. + */ + +/* + * Page Structure of the Generated PDF: + * + * Each page requiring fallbacks images contains a knockout group at + * the top level. The first operation of the knockout group paints a + * group containing all the supported drawing operations. Fallback + * images (if any) are painted in the knockout group. This ensures + * that fallback images do not composite with any content under the + * fallback images. + * + * Streams: + * + * This PDF surface has three types of streams: + * - PDF Stream + * - Content Stream + * - Group Stream + * + * Calling _cairo_output_stream_printf (surface->output, ...) will + * write to the currently open stream. + * + * PDF Stream: + * A PDF Stream may be opened and closed with the following functions: + * _cairo_pdf_surface_open stream () + * _cairo_pdf_surface_close_stream () + * + * PDF Streams are written directly to the PDF file. They are used for + * fonts, images and patterns. + * + * Content Stream: + * The Content Stream is opened and closed with the following functions: + * _cairo_pdf_surface_open_content_stream () + * _cairo_pdf_surface_close_content_stream () + * + * The Content Stream contains the text and graphics operators. + * + * Group Stream: + * A Group Stream may be opened and closed with the following functions: + * _cairo_pdf_surface_open_group () + * _cairo_pdf_surface_close_group () + * + * A Group Stream is a Form XObject. It is used for short sequences + * of operators. As the content is very short the group is stored in + * memory until it is closed. This allows some optimization such as + * including the Resource dictionary and stream length inside the + * XObject instead of using an indirect object. + */ + +/** + * SECTION:cairo-pdf + * @Title: PDF Surfaces + * @Short_Description: Rendering PDF documents + * @See_Also: #cairo_surface_t + * + * The PDF surface is used to render cairo graphics to Adobe + * PDF files and is a multi-page vector surface backend. + * + * The following mime types are supported: %CAIRO_MIME_TYPE_JPEG, + * %CAIRO_MIME_TYPE_JP2, %CAIRO_MIME_TYPE_UNIQUE_ID, + * %CAIRO_MIME_TYPE_JBIG2, %CAIRO_MIME_TYPE_JBIG2_GLOBAL, + * %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID. + * + * JBIG2 data in PDF must be in the embedded format as described in + * ISO/IEC 11544. Image specific JBIG2 data must be in + * %CAIRO_MIME_TYPE_JBIG2. Any global segments in the JBIG2 data + * (segments with page association field set to 0) must be in + * %CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data may be shared by + * multiple images. All images sharing the same global data must set + * %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID to a unique identifer. At least + * one of the images must provide the global data using + * %CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data will only be + * embedded once but shared by all JBIG2 images with the same + * %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID. + **/ + +static cairo_bool_t +_cairo_pdf_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle); + +/** + * CAIRO_HAS_PDF_SURFACE: + * + * Defined if the PDF surface backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.2 + **/ + +static const cairo_pdf_version_t _cairo_pdf_versions[] = +{ + CAIRO_PDF_VERSION_1_4, + CAIRO_PDF_VERSION_1_5 +}; + +#define CAIRO_PDF_VERSION_LAST ARRAY_LENGTH (_cairo_pdf_versions) + +static const char * _cairo_pdf_version_strings[CAIRO_PDF_VERSION_LAST] = +{ + "PDF 1.4", + "PDF 1.5" +}; + +static const char *_cairo_pdf_supported_mime_types[] = +{ + CAIRO_MIME_TYPE_JPEG, + CAIRO_MIME_TYPE_JP2, + CAIRO_MIME_TYPE_UNIQUE_ID, + CAIRO_MIME_TYPE_JBIG2, + CAIRO_MIME_TYPE_JBIG2_GLOBAL, + CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, + NULL +}; + +typedef struct _cairo_pdf_object { + long offset; +} cairo_pdf_object_t; + +typedef struct _cairo_pdf_font { + unsigned int font_id; + unsigned int subset_id; + cairo_pdf_resource_t subset_resource; +} cairo_pdf_font_t; + +typedef struct _cairo_pdf_rgb_linear_function { + cairo_pdf_resource_t resource; + double color1[3]; + double color2[3]; +} cairo_pdf_rgb_linear_function_t; + +typedef struct _cairo_pdf_alpha_linear_function { + cairo_pdf_resource_t resource; + double alpha1; + double alpha2; +} cairo_pdf_alpha_linear_function_t; + +static cairo_pdf_resource_t +_cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface); + +static void +_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface); + +static void +_cairo_pdf_smask_group_destroy (cairo_pdf_smask_group_t *group); + +static cairo_int_status_t +_cairo_pdf_surface_add_font (unsigned int font_id, + unsigned int subset_id, + void *closure); + +static void +_cairo_pdf_group_resources_init (cairo_pdf_group_resources_t *res); + +static cairo_int_status_t +_cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t *resource, + cairo_bool_t compressed, + const char *fmt, + ...) CAIRO_PRINTF_FORMAT(4, 5); +static cairo_int_status_t +_cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface); + +static cairo_int_status_t +_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface); + +static void +_cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface); + +static cairo_pdf_resource_t +_cairo_pdf_surface_write_info (cairo_pdf_surface_t *surface); + +static cairo_pdf_resource_t +_cairo_pdf_surface_write_catalog (cairo_pdf_surface_t *surface); + +static long +_cairo_pdf_surface_write_xref (cairo_pdf_surface_t *surface); + +static cairo_int_status_t +_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface); + +static cairo_int_status_t +_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface); + +static cairo_bool_t +_cairo_pdf_source_surface_equal (const void *key_a, const void *key_b); + +static const cairo_surface_backend_t cairo_pdf_surface_backend; +static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend; + +static cairo_pdf_resource_t +_cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface) +{ + cairo_pdf_resource_t resource; + cairo_int_status_t status; + cairo_pdf_object_t object; + + object.offset = _cairo_output_stream_get_position (surface->output); + + status = _cairo_array_append (&surface->objects, &object); + if (unlikely (status)) { + resource.id = 0; + return resource; + } + + resource = surface->next_available_resource; + surface->next_available_resource.id++; + + return resource; +} + +static void +_cairo_pdf_surface_update_object (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t resource) +{ + cairo_pdf_object_t *object; + + object = _cairo_array_index (&surface->objects, resource.id - 1); + object->offset = _cairo_output_stream_get_position (surface->output); +} + +static void +_cairo_pdf_surface_set_size_internal (cairo_pdf_surface_t *surface, + double width, + double height) +{ + surface->width = width; + surface->height = height; + cairo_matrix_init (&surface->cairo_to_pdf, 1, 0, 0, -1, 0, height); + _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, + &surface->cairo_to_pdf); +} + +static cairo_bool_t +_path_covers_bbox (cairo_pdf_surface_t *surface, + cairo_path_fixed_t *path) +{ + cairo_box_t box; + + return _cairo_path_fixed_is_box (path, &box) && + box.p1.x <= 0 && + box.p1.y <= 0 && + box.p2.x >= _cairo_fixed_from_double (surface->width) && + box.p2.y >= _cairo_fixed_from_double (surface->height); +} + +static cairo_status_t +_cairo_pdf_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_pdf_surface_t *surface = cairo_container_of (clipper, + cairo_pdf_surface_t, + clipper); + cairo_int_status_t status; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + if (path == NULL) { + _cairo_output_stream_printf (surface->output, "Q q\n"); + + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + + return CAIRO_STATUS_SUCCESS; + } + + if (_path_covers_bbox (surface, path)) + return CAIRO_STATUS_SUCCESS; + + return _cairo_pdf_operators_clip (&surface->pdf_operators, path, fill_rule); +} + +static cairo_surface_t * +_cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *output, + double width, + double height) +{ + cairo_pdf_surface_t *surface; + cairo_status_t status, status_ignored; + + surface = malloc (sizeof (cairo_pdf_surface_t)); + if (unlikely (surface == NULL)) { + /* destroy stream on behalf of caller */ + status = _cairo_output_stream_destroy (output); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + _cairo_surface_init (&surface->base, + &cairo_pdf_surface_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + surface->output = output; + surface->width = width; + surface->height = height; + cairo_matrix_init (&surface->cairo_to_pdf, 1, 0, 0, -1, 0, height); + + _cairo_array_init (&surface->objects, sizeof (cairo_pdf_object_t)); + _cairo_array_init (&surface->pages, sizeof (cairo_pdf_resource_t)); + _cairo_array_init (&surface->rgb_linear_functions, sizeof (cairo_pdf_rgb_linear_function_t)); + _cairo_array_init (&surface->alpha_linear_functions, sizeof (cairo_pdf_alpha_linear_function_t)); + _cairo_array_init (&surface->fonts, sizeof (cairo_pdf_font_t)); + _cairo_array_init (&surface->smask_groups, sizeof (cairo_pdf_smask_group_t *)); + _cairo_array_init (&surface->knockout_group, sizeof (cairo_pdf_resource_t)); + + _cairo_array_init (&surface->page_patterns, sizeof (cairo_pdf_pattern_t)); + _cairo_array_init (&surface->page_surfaces, sizeof (cairo_pdf_source_surface_t)); + _cairo_array_init (&surface->jbig2_global, sizeof (cairo_pdf_jbig2_global_t)); + surface->all_surfaces = _cairo_hash_table_create (_cairo_pdf_source_surface_equal); + if (unlikely (surface->all_surfaces == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL0; + } + + _cairo_pdf_group_resources_init (&surface->resources); + + surface->font_subsets = _cairo_scaled_font_subsets_create_composite (); + if (! surface->font_subsets) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL1; + } + + _cairo_scaled_font_subsets_enable_latin_subset (surface->font_subsets, TRUE); + + surface->next_available_resource.id = 1; + surface->pages_resource = _cairo_pdf_surface_new_object (surface); + if (surface->pages_resource.id == 0) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL2; + } + + surface->pdf_version = CAIRO_PDF_VERSION_1_5; + surface->compress_content = TRUE; + surface->pdf_stream.active = FALSE; + surface->pdf_stream.old_output = NULL; + surface->group_stream.active = FALSE; + surface->group_stream.stream = NULL; + surface->group_stream.mem_stream = NULL; + + surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE; + + surface->force_fallbacks = FALSE; + surface->select_pattern_gstate_saved = FALSE; + surface->current_pattern_is_solid_color = FALSE; + surface->current_operator = CAIRO_OPERATOR_OVER; + surface->header_emitted = FALSE; + + _cairo_surface_clipper_init (&surface->clipper, + _cairo_pdf_surface_clipper_intersect_clip_path); + + _cairo_pdf_operators_init (&surface->pdf_operators, + surface->output, + &surface->cairo_to_pdf, + surface->font_subsets, + FALSE); + _cairo_pdf_operators_set_font_subsets_callback (&surface->pdf_operators, + _cairo_pdf_surface_add_font, + surface); + _cairo_pdf_operators_enable_actual_text(&surface->pdf_operators, TRUE); + + surface->paginated_surface = _cairo_paginated_surface_create ( + &surface->base, + CAIRO_CONTENT_COLOR_ALPHA, + &cairo_pdf_surface_paginated_backend); + + status = surface->paginated_surface->status; + if (status == CAIRO_STATUS_SUCCESS) { + /* paginated keeps the only reference to surface now, drop ours */ + cairo_surface_destroy (&surface->base); + return surface->paginated_surface; + } + +BAIL2: + _cairo_scaled_font_subsets_destroy (surface->font_subsets); +BAIL1: + _cairo_hash_table_destroy (surface->all_surfaces); +BAIL0: + _cairo_array_fini (&surface->objects); + free (surface); + + /* destroy stream on behalf of caller */ + status_ignored = _cairo_output_stream_destroy (output); + + return _cairo_surface_create_in_error (status); +} + +/** + * cairo_pdf_surface_create_for_stream: + * @write_func: a #cairo_write_func_t to accept the output data, may be %NULL + * to indicate a no-op @write_func. With a no-op @write_func, + * the surface may be queried or used as a source without + * generating any temporary files. + * @closure: the closure argument for @write_func + * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) + * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) + * + * Creates a PDF surface of the specified size in points to be written + * incrementally to the stream represented by @write_func and @closure. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, + void *closure, + double width_in_points, + double height_in_points) +{ + cairo_output_stream_t *output; + + output = _cairo_output_stream_create (write_func, NULL, closure); + if (_cairo_output_stream_get_status (output)) + return _cairo_surface_create_in_error (_cairo_output_stream_destroy (output)); + + return _cairo_pdf_surface_create_for_stream_internal (output, + width_in_points, + height_in_points); +} + +/** + * cairo_pdf_surface_create: + * @filename: a filename for the PDF output (must be writable), %NULL may be + * used to specify no output. This will generate a PDF surface that + * may be queried and used as a source, without generating a + * temporary file. + * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) + * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) + * + * Creates a PDF surface of the specified size in points to be written + * to @filename. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_pdf_surface_create (const char *filename, + double width_in_points, + double height_in_points) +{ + cairo_output_stream_t *output; + + output = _cairo_output_stream_create_for_filename (filename); + if (_cairo_output_stream_get_status (output)) + return _cairo_surface_create_in_error (_cairo_output_stream_destroy (output)); + + return _cairo_pdf_surface_create_for_stream_internal (output, + width_in_points, + height_in_points); +} + +static cairo_bool_t +_cairo_surface_is_pdf (cairo_surface_t *surface) +{ + return surface->backend == &cairo_pdf_surface_backend; +} + +/* If the abstract_surface is a paginated surface, and that paginated + * surface's target is a pdf_surface, then set pdf_surface to that + * target. Otherwise return FALSE. + */ +static cairo_bool_t +_extract_pdf_surface (cairo_surface_t *surface, + cairo_pdf_surface_t **pdf_surface) +{ + cairo_surface_t *target; + cairo_status_t status_ignored; + + if (surface->status) + return FALSE; + if (surface->finished) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (! _cairo_surface_is_paginated (surface)) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return FALSE; + } + + target = _cairo_paginated_surface_get_target (surface); + if (target->status) { + status_ignored = _cairo_surface_set_error (surface, + target->status); + return FALSE; + } + if (target->finished) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (! _cairo_surface_is_pdf (target)) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return FALSE; + } + + *pdf_surface = (cairo_pdf_surface_t *) target; + return TRUE; +} + +/** + * cairo_pdf_surface_restrict_to_version: + * @surface: a PDF #cairo_surface_t + * @version: PDF version + * + * Restricts the generated PDF file to @version. See cairo_pdf_get_versions() + * for a list of available version values that can be used here. + * + * This function should only be called before any drawing operations + * have been performed on the given surface. The simplest way to do + * this is to call this function immediately after creating the + * surface. + * + * Since: 1.10 + **/ +void +cairo_pdf_surface_restrict_to_version (cairo_surface_t *abstract_surface, + cairo_pdf_version_t version) +{ + cairo_pdf_surface_t *surface = NULL; /* hide compiler warning */ + + if (! _extract_pdf_surface (abstract_surface, &surface)) + return; + + if (version < CAIRO_PDF_VERSION_LAST) + surface->pdf_version = version; + + _cairo_pdf_operators_enable_actual_text(&surface->pdf_operators, + version >= CAIRO_PDF_VERSION_1_5); +} + +/** + * cairo_pdf_get_versions: + * @versions: supported version list + * @num_versions: list length + * + * Used to retrieve the list of supported versions. See + * cairo_pdf_surface_restrict_to_version(). + * + * Since: 1.10 + **/ +void +cairo_pdf_get_versions (cairo_pdf_version_t const **versions, + int *num_versions) +{ + if (versions != NULL) + *versions = _cairo_pdf_versions; + + if (num_versions != NULL) + *num_versions = CAIRO_PDF_VERSION_LAST; +} + +/** + * cairo_pdf_version_to_string: + * @version: a version id + * + * Get the string representation of the given @version id. This function + * will return %NULL if @version isn't valid. See cairo_pdf_get_versions() + * for a way to get the list of valid version ids. + * + * Return value: the string associated to given version. + * + * Since: 1.10 + **/ +const char * +cairo_pdf_version_to_string (cairo_pdf_version_t version) +{ + if (version >= CAIRO_PDF_VERSION_LAST) + return NULL; + + return _cairo_pdf_version_strings[version]; +} + +/** + * cairo_pdf_surface_set_size: + * @surface: a PDF #cairo_surface_t + * @width_in_points: new surface width, in points (1 point == 1/72.0 inch) + * @height_in_points: new surface height, in points (1 point == 1/72.0 inch) + * + * Changes the size of a PDF surface for the current (and + * subsequent) pages. + * + * This function should only be called before any drawing operations + * have been performed on the current page. The simplest way to do + * this is to call this function immediately after creating the + * surface or immediately after completing a page with either + * cairo_show_page() or cairo_copy_page(). + * + * Since: 1.2 + **/ +void +cairo_pdf_surface_set_size (cairo_surface_t *surface, + double width_in_points, + double height_in_points) +{ + cairo_pdf_surface_t *pdf_surface = NULL; /* hide compiler warning */ + cairo_status_t status; + + if (! _extract_pdf_surface (surface, &pdf_surface)) + return; + + _cairo_pdf_surface_set_size_internal (pdf_surface, + width_in_points, + height_in_points); + status = _cairo_paginated_surface_set_size (pdf_surface->paginated_surface, + width_in_points, + height_in_points); + if (status) + status = _cairo_surface_set_error (surface, status); +} + +static void +_cairo_pdf_surface_clear (cairo_pdf_surface_t *surface) +{ + int i, size; + cairo_pdf_pattern_t *pattern; + cairo_pdf_source_surface_t *src_surface; + cairo_pdf_smask_group_t *group; + + size = _cairo_array_num_elements (&surface->page_patterns); + for (i = 0; i < size; i++) { + pattern = (cairo_pdf_pattern_t *) _cairo_array_index (&surface->page_patterns, i); + cairo_pattern_destroy (pattern->pattern); + } + _cairo_array_truncate (&surface->page_patterns, 0); + + size = _cairo_array_num_elements (&surface->page_surfaces); + for (i = 0; i < size; i++) { + src_surface = (cairo_pdf_source_surface_t *) _cairo_array_index (&surface->page_surfaces, i); + cairo_surface_destroy (src_surface->surface); + } + _cairo_array_truncate (&surface->page_surfaces, 0); + + size = _cairo_array_num_elements (&surface->smask_groups); + for (i = 0; i < size; i++) { + _cairo_array_copy_element (&surface->smask_groups, i, &group); + _cairo_pdf_smask_group_destroy (group); + } + _cairo_array_truncate (&surface->smask_groups, 0); + _cairo_array_truncate (&surface->knockout_group, 0); +} + +static void +_cairo_pdf_group_resources_init (cairo_pdf_group_resources_t *res) +{ + int i; + + for (i = 0; i < CAIRO_NUM_OPERATORS; i++) + res->operators[i] = FALSE; + + _cairo_array_init (&res->alphas, sizeof (double)); + _cairo_array_init (&res->smasks, sizeof (cairo_pdf_resource_t)); + _cairo_array_init (&res->patterns, sizeof (cairo_pdf_resource_t)); + _cairo_array_init (&res->shadings, sizeof (cairo_pdf_resource_t)); + _cairo_array_init (&res->xobjects, sizeof (cairo_pdf_resource_t)); + _cairo_array_init (&res->fonts, sizeof (cairo_pdf_font_t)); +} + +static void +_cairo_pdf_group_resources_fini (cairo_pdf_group_resources_t *res) +{ + _cairo_array_fini (&res->alphas); + _cairo_array_fini (&res->smasks); + _cairo_array_fini (&res->patterns); + _cairo_array_fini (&res->shadings); + _cairo_array_fini (&res->xobjects); + _cairo_array_fini (&res->fonts); +} + +static void +_cairo_pdf_group_resources_clear (cairo_pdf_group_resources_t *res) +{ + int i; + + for (i = 0; i < CAIRO_NUM_OPERATORS; i++) + res->operators[i] = FALSE; + + _cairo_array_truncate (&res->alphas, 0); + _cairo_array_truncate (&res->smasks, 0); + _cairo_array_truncate (&res->patterns, 0); + _cairo_array_truncate (&res->shadings, 0); + _cairo_array_truncate (&res->xobjects, 0); + _cairo_array_truncate (&res->fonts, 0); +} + +static void +_cairo_pdf_surface_add_operator (cairo_pdf_surface_t *surface, + cairo_operator_t op) +{ + cairo_pdf_group_resources_t *res = &surface->resources; + + res->operators[op] = TRUE; +} + +static cairo_int_status_t +_cairo_pdf_surface_add_alpha (cairo_pdf_surface_t *surface, + double alpha, + int *index) +{ + int num_alphas, i; + double other; + cairo_int_status_t status; + cairo_pdf_group_resources_t *res = &surface->resources; + + num_alphas = _cairo_array_num_elements (&res->alphas); + for (i = 0; i < num_alphas; i++) { + _cairo_array_copy_element (&res->alphas, i, &other); + if (alpha == other) { + *index = i; + return CAIRO_STATUS_SUCCESS; + } + } + + status = _cairo_array_append (&res->alphas, &alpha); + if (unlikely (status)) + return status; + + *index = _cairo_array_num_elements (&res->alphas) - 1; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_add_smask (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t smask) +{ + return _cairo_array_append (&(surface->resources.smasks), &smask); +} + +static cairo_int_status_t +_cairo_pdf_surface_add_pattern (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t pattern) +{ + return _cairo_array_append (&(surface->resources.patterns), &pattern); +} + +static cairo_int_status_t +_cairo_pdf_surface_add_shading (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t shading) +{ + return _cairo_array_append (&(surface->resources.shadings), &shading); +} + + +static cairo_int_status_t +_cairo_pdf_surface_add_xobject (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t xobject) +{ + return _cairo_array_append (&(surface->resources.xobjects), &xobject); +} + +static cairo_int_status_t +_cairo_pdf_surface_add_font (unsigned int font_id, + unsigned int subset_id, + void *closure) +{ + cairo_pdf_surface_t *surface = closure; + cairo_pdf_font_t font; + int num_fonts, i; + cairo_int_status_t status; + cairo_pdf_group_resources_t *res = &surface->resources; + + num_fonts = _cairo_array_num_elements (&res->fonts); + for (i = 0; i < num_fonts; i++) { + _cairo_array_copy_element (&res->fonts, i, &font); + if (font.font_id == font_id && + font.subset_id == subset_id) + return CAIRO_STATUS_SUCCESS; + } + + num_fonts = _cairo_array_num_elements (&surface->fonts); + for (i = 0; i < num_fonts; i++) { + _cairo_array_copy_element (&surface->fonts, i, &font); + if (font.font_id == font_id && + font.subset_id == subset_id) + return _cairo_array_append (&res->fonts, &font); + } + + font.font_id = font_id; + font.subset_id = subset_id; + font.subset_resource = _cairo_pdf_surface_new_object (surface); + if (font.subset_resource.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_array_append (&surface->fonts, &font); + if (unlikely (status)) + return status; + + return _cairo_array_append (&res->fonts, &font); +} + +static cairo_pdf_resource_t +_cairo_pdf_surface_get_font_resource (cairo_pdf_surface_t *surface, + unsigned int font_id, + unsigned int subset_id) +{ + cairo_pdf_font_t font; + int num_fonts, i; + + num_fonts = _cairo_array_num_elements (&surface->fonts); + for (i = 0; i < num_fonts; i++) { + _cairo_array_copy_element (&surface->fonts, i, &font); + if (font.font_id == font_id && font.subset_id == subset_id) + return font.subset_resource; + } + + font.subset_resource.id = 0; + return font.subset_resource; +} + +static const char * +_cairo_operator_to_pdf_blend_mode (cairo_operator_t op) +{ + switch (op) { + /* The extend blend mode operators */ + case CAIRO_OPERATOR_MULTIPLY: return "Multiply"; + case CAIRO_OPERATOR_SCREEN: return "Screen"; + case CAIRO_OPERATOR_OVERLAY: return "Overlay"; + case CAIRO_OPERATOR_DARKEN: return "Darken"; + case CAIRO_OPERATOR_LIGHTEN: return "Lighten"; + case CAIRO_OPERATOR_COLOR_DODGE: return "ColorDodge"; + case CAIRO_OPERATOR_COLOR_BURN: return "ColorBurn"; + case CAIRO_OPERATOR_HARD_LIGHT: return "HardLight"; + case CAIRO_OPERATOR_SOFT_LIGHT: return "SoftLight"; + case CAIRO_OPERATOR_DIFFERENCE: return "Difference"; + case CAIRO_OPERATOR_EXCLUSION: return "Exclusion"; + case CAIRO_OPERATOR_HSL_HUE: return "Hue"; + case CAIRO_OPERATOR_HSL_SATURATION: return "Saturation"; + case CAIRO_OPERATOR_HSL_COLOR: return "Color"; + case CAIRO_OPERATOR_HSL_LUMINOSITY: return "Luminosity"; + + default: + /* The original Porter-Duff set */ + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_ATOP: + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_DEST_ATOP: + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + return "Normal"; + } +} + +static void +_cairo_pdf_surface_emit_group_resources (cairo_pdf_surface_t *surface, + cairo_pdf_group_resources_t *res) +{ + int num_alphas, num_smasks, num_resources, i; + double alpha; + cairo_pdf_resource_t *smask, *pattern, *shading, *xobject; + cairo_pdf_font_t *font; + + _cairo_output_stream_printf (surface->output, "<<\n"); + + num_alphas = _cairo_array_num_elements (&res->alphas); + num_smasks = _cairo_array_num_elements (&res->smasks); + if (num_alphas > 0 || num_smasks > 0) { + _cairo_output_stream_printf (surface->output, + " /ExtGState <<\n"); + + for (i = 0; i < CAIRO_NUM_OPERATORS; i++) { + if (res->operators[i]) { + _cairo_output_stream_printf (surface->output, + " /b%d << /BM /%s >>\n", + i, _cairo_operator_to_pdf_blend_mode(i)); + } + } + + for (i = 0; i < num_alphas; i++) { + _cairo_array_copy_element (&res->alphas, i, &alpha); + _cairo_output_stream_printf (surface->output, + " /a%d << /CA %f /ca %f >>\n", + i, alpha, alpha); + } + + for (i = 0; i < num_smasks; i++) { + smask = _cairo_array_index (&res->smasks, i); + _cairo_output_stream_printf (surface->output, + " /s%d %d 0 R\n", + smask->id, smask->id); + } + + _cairo_output_stream_printf (surface->output, + " >>\n"); + } + + num_resources = _cairo_array_num_elements (&res->patterns); + if (num_resources > 0) { + _cairo_output_stream_printf (surface->output, + " /Pattern <<"); + for (i = 0; i < num_resources; i++) { + pattern = _cairo_array_index (&res->patterns, i); + _cairo_output_stream_printf (surface->output, + " /p%d %d 0 R", + pattern->id, pattern->id); + } + + _cairo_output_stream_printf (surface->output, + " >>\n"); + } + + num_resources = _cairo_array_num_elements (&res->shadings); + if (num_resources > 0) { + _cairo_output_stream_printf (surface->output, + " /Shading <<"); + for (i = 0; i < num_resources; i++) { + shading = _cairo_array_index (&res->shadings, i); + _cairo_output_stream_printf (surface->output, + " /sh%d %d 0 R", + shading->id, shading->id); + } + + _cairo_output_stream_printf (surface->output, + " >>\n"); + } + + num_resources = _cairo_array_num_elements (&res->xobjects); + if (num_resources > 0) { + _cairo_output_stream_printf (surface->output, + " /XObject <<"); + + for (i = 0; i < num_resources; i++) { + xobject = _cairo_array_index (&res->xobjects, i); + _cairo_output_stream_printf (surface->output, + " /x%d %d 0 R", + xobject->id, xobject->id); + } + + _cairo_output_stream_printf (surface->output, + " >>\n"); + } + + num_resources = _cairo_array_num_elements (&res->fonts); + if (num_resources > 0) { + _cairo_output_stream_printf (surface->output," /Font <<\n"); + for (i = 0; i < num_resources; i++) { + font = _cairo_array_index (&res->fonts, i); + _cairo_output_stream_printf (surface->output, + " /f-%d-%d %d 0 R\n", + font->font_id, + font->subset_id, + font->subset_resource.id); + } + _cairo_output_stream_printf (surface->output, " >>\n"); + } + + _cairo_output_stream_printf (surface->output, + ">>\n"); +} + +static cairo_pdf_smask_group_t * +_cairo_pdf_surface_create_smask_group (cairo_pdf_surface_t *surface, + const cairo_rectangle_int_t *extents) +{ + cairo_pdf_smask_group_t *group; + + group = calloc (1, sizeof (cairo_pdf_smask_group_t)); + if (unlikely (group == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + group->group_res = _cairo_pdf_surface_new_object (surface); + if (group->group_res.id == 0) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + free (group); + return NULL; + } + group->width = surface->width; + group->height = surface->height; + if (extents != NULL) { + group->extents = *extents; + } else { + group->extents.x = 0; + group->extents.y = 0; + group->extents.width = surface->width; + group->extents.height = surface->height; + } + group->extents = *extents; + + return group; +} + +static void +_cairo_pdf_smask_group_destroy (cairo_pdf_smask_group_t *group) +{ + if (group->operation == PDF_FILL || group->operation == PDF_STROKE) + _cairo_path_fixed_fini (&group->path); + if (group->source) + cairo_pattern_destroy (group->source); + if (group->mask) + cairo_pattern_destroy (group->mask); + free (group->utf8); + free (group->glyphs); + free (group->clusters); + if (group->scaled_font) + cairo_scaled_font_destroy (group->scaled_font); + free (group); +} + +static cairo_int_status_t +_cairo_pdf_surface_add_smask_group (cairo_pdf_surface_t *surface, + cairo_pdf_smask_group_t *group) +{ + return _cairo_array_append (&surface->smask_groups, &group); +} + +static cairo_bool_t +_cairo_pdf_source_surface_equal (const void *key_a, const void *key_b) +{ + const cairo_pdf_source_surface_entry_t *a = key_a; + const cairo_pdf_source_surface_entry_t *b = key_b; + + if (a->interpolate != b->interpolate) + return FALSE; + + if (a->unique_id && b->unique_id && a->unique_id_length == b->unique_id_length) + return (memcmp (a->unique_id, b->unique_id, a->unique_id_length) == 0); + + return (a->id == b->id); +} + +static void +_cairo_pdf_source_surface_init_key (cairo_pdf_source_surface_entry_t *key) +{ + if (key->unique_id && key->unique_id_length > 0) { + key->base.hash = _cairo_hash_bytes (_CAIRO_HASH_INIT_VALUE, + key->unique_id, key->unique_id_length); + } else { + key->base.hash = key->id; + } +} + +static cairo_int_status_t +_cairo_pdf_surface_acquire_source_image_from_pattern (cairo_pdf_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_image_surface_t **image, + void **image_extra) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) pattern; + return _cairo_surface_acquire_source_image (surf_pat->surface, image, image_extra); + } break; + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: { + cairo_surface_t *surf; + surf = _cairo_raster_source_pattern_acquire (pattern, &surface->base, NULL); + if (!surf) + return CAIRO_INT_STATUS_UNSUPPORTED; + assert (_cairo_surface_is_image (surf)); + *image = (cairo_image_surface_t *) surf; + } break; + + case CAIRO_PATTERN_TYPE_SOLID: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + default: + ASSERT_NOT_REACHED; + break; + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_pdf_surface_release_source_image_from_pattern (cairo_pdf_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_image_surface_t *image, + void *image_extra) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) pattern; + _cairo_surface_release_source_image (surf_pat->surface, image, image_extra); + } break; + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + _cairo_raster_source_pattern_release (pattern, &image->base); + break; + + case CAIRO_PATTERN_TYPE_SOLID: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + default: + + ASSERT_NOT_REACHED; + break; + } +} + +static cairo_int_status_t +_get_jbig2_image_info (cairo_surface_t *source, + cairo_image_info_t *info, + const unsigned char **mime_data, + unsigned long *mime_data_length) +{ + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2, + mime_data, mime_data_length); + if (*mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return _cairo_image_info_get_jbig2_info (info, *mime_data, *mime_data_length); +} + +static cairo_int_status_t +_get_jpx_image_info (cairo_surface_t *source, + cairo_image_info_t *info, + const unsigned char **mime_data, + unsigned long *mime_data_length) +{ + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JP2, + mime_data, mime_data_length); + if (*mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return _cairo_image_info_get_jpx_info (info, *mime_data, *mime_data_length); +} + +static cairo_int_status_t +_get_jpeg_image_info (cairo_surface_t *source, + cairo_image_info_t *info, + const unsigned char **mime_data, + unsigned long *mime_data_length) +{ + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG, + mime_data, mime_data_length); + if (*mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return _cairo_image_info_get_jpeg_info (info, *mime_data, *mime_data_length); +} + +static cairo_int_status_t +_get_source_surface_size (cairo_surface_t *source, + int *width, + int *height, + cairo_rectangle_int_t *extents) +{ + cairo_int_status_t status; + cairo_image_info_t info; + const unsigned char *mime_data; + unsigned long mime_data_length; + + if (source->type == CAIRO_SURFACE_TYPE_RECORDING) { + if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; + + *extents = sub->extents; + *width = extents->width; + *height = extents->height; + } else { + cairo_surface_t *free_me = NULL; + cairo_rectangle_int_t surf_extents; + cairo_box_t box; + cairo_bool_t bounded; + + if (_cairo_surface_is_snapshot (source)) + free_me = source = _cairo_surface_snapshot_get_target (source); + + status = _cairo_recording_surface_get_ink_bbox ((cairo_recording_surface_t *)source, + &box, NULL); + if (unlikely (status)) { + cairo_surface_destroy (free_me); + return status; + } + + bounded = _cairo_surface_get_extents (source, &surf_extents); + cairo_surface_destroy (free_me); + + *width = surf_extents.width; + *height = surf_extents.height; + + _cairo_box_round_to_rectangle (&box, extents); + } + + return CAIRO_STATUS_SUCCESS; + } + + extents->x = 0; + extents->y = 0; + + status = _get_jbig2_image_info (source, &info, &mime_data, &mime_data_length); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + *width = info.width; + *height = info.height; + extents->width = info.width; + extents->height = info.height; + return status; + } + + status = _get_jpx_image_info (source, &info, &mime_data, &mime_data_length); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + *width = info.width; + *height = info.height; + extents->width = info.width; + extents->height = info.height; + return status; + } + + status = _get_jpeg_image_info (source, &info, &mime_data, &mime_data_length); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + *width = info.width; + *height = info.height; + extents->width = info.width; + extents->height = info.height; + return status; + } + + if (! _cairo_surface_get_extents (source, extents)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + *width = extents->width; + *height = extents->height; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_pdf_surface_add_source_surface: + * @surface: the pdf surface + * @source_surface: A #cairo_surface_t to use as the source surface + * @source_pattern: A #cairo_pattern_t of type SURFACE or RASTER_SOURCE to use as the source + * @op: the operator used to composite this source + * @filter: filter type of the source pattern + * @stencil_mask: if true, the surface will be written to the PDF as an /ImageMask + * @smask: if true, only the alpha channel will be written (images only) + * @extents: extents of the operation that is using this source + * @smask_res: if not NULL, the image written will specify this resource as the smask for the image (images only) + * @surface_res: return PDF resource number of the surface + * @width: returns width of surface + * @height: returns height of surface + * @x_offset: x offset of surface + * @t_offset: y offset of surface + * @source_extents: returns extents of source (either ink extents or extents needed to cover @extents) + * + * Add surface or raster_source pattern to list of surfaces to be + * written to the PDF file when the current page is finished. Returns + * a PDF resource to reference the image. A hash table of all images + * in the PDF files (keyed by CAIRO_MIME_TYPE_UNIQUE_ID or surface + * unique_id) to ensure surfaces with the same id are only written + * once to the PDF file. + * + * Only one of @source_pattern or @source_surface is to be + * specified. Set the other to NULL. + **/ +static cairo_int_status_t +_cairo_pdf_surface_add_source_surface (cairo_pdf_surface_t *surface, + cairo_surface_t *source_surface, + const cairo_pattern_t *source_pattern, + cairo_operator_t op, + cairo_filter_t filter, + cairo_bool_t stencil_mask, + cairo_bool_t smask, + const cairo_rectangle_int_t *extents, + cairo_pdf_resource_t *smask_res, + cairo_pdf_resource_t *surface_res, + int *width, + int *height, + double *x_offset, + double *y_offset, + cairo_rectangle_int_t *source_extents) +{ + cairo_pdf_source_surface_t src_surface; + cairo_pdf_source_surface_entry_t surface_key; + cairo_pdf_source_surface_entry_t *surface_entry; + cairo_int_status_t status; + cairo_bool_t interpolate; + unsigned char *unique_id = NULL; + unsigned long unique_id_length = 0; + cairo_image_surface_t *image; + void *image_extra; + + switch (filter) { + default: + case CAIRO_FILTER_GOOD: + case CAIRO_FILTER_BEST: + case CAIRO_FILTER_BILINEAR: + interpolate = TRUE; + break; + case CAIRO_FILTER_FAST: + case CAIRO_FILTER_NEAREST: + case CAIRO_FILTER_GAUSSIAN: + interpolate = FALSE; + break; + } + + *x_offset = 0; + *y_offset = 0; + if (source_pattern) { + if (source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { + status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source_pattern, + &image, &image_extra); + if (unlikely (status)) + return status; + source_surface = &image->base; + cairo_surface_get_device_offset (source_surface, x_offset, y_offset); + } else { + cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) source_pattern; + source_surface = surface_pattern->surface; + } + } + + surface_key.id = source_surface->unique_id; + surface_key.interpolate = interpolate; + cairo_surface_get_mime_data (source_surface, CAIRO_MIME_TYPE_UNIQUE_ID, + (const unsigned char **) &surface_key.unique_id, + &surface_key.unique_id_length); + _cairo_pdf_source_surface_init_key (&surface_key); + surface_entry = _cairo_hash_table_lookup (surface->all_surfaces, &surface_key.base); + if (surface_entry) { + *surface_res = surface_entry->surface_res; + *width = surface_entry->width; + *height = surface_entry->height; + *source_extents = surface_entry->extents; + status = CAIRO_STATUS_SUCCESS; + } else { + status = _get_source_surface_size (source_surface, + width, + height, + source_extents); + if (unlikely(status)) + goto release_source; + + if (surface_key.unique_id && surface_key.unique_id_length > 0) { + unique_id = _cairo_malloc (surface_key.unique_id_length); + if (unique_id == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto release_source; + } + + unique_id_length = surface_key.unique_id_length; + memcpy (unique_id, surface_key.unique_id, unique_id_length); + } else { + unique_id = NULL; + unique_id_length = 0; + } + } + +release_source: + if (source_pattern && source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) + _cairo_pdf_surface_release_source_image_from_pattern (surface, source_pattern, image, image_extra); + + if (status || surface_entry) + return status; + + surface_entry = malloc (sizeof (cairo_pdf_source_surface_entry_t)); + if (surface_entry == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + surface_entry->id = surface_key.id; + surface_entry->operator = op; + surface_entry->interpolate = interpolate; + surface_entry->stencil_mask = stencil_mask; + surface_entry->smask = smask; + surface_entry->unique_id_length = unique_id_length; + surface_entry->unique_id = unique_id; + surface_entry->width = *width; + surface_entry->height = *height; + surface_entry->extents = *source_extents; + if (smask_res) + surface_entry->smask_res = *smask_res; + else + surface_entry->smask_res.id = 0; + _cairo_pdf_source_surface_init_key (surface_entry); + + src_surface.hash_entry = surface_entry; + if (source_pattern && source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { + src_surface.type = CAIRO_PATTERN_TYPE_RASTER_SOURCE; + src_surface.surface = NULL; + status = _cairo_pattern_create_copy (&src_surface.raster_pattern, source_pattern); + if (unlikely (status)) + goto fail2; + + } else { + src_surface.type = CAIRO_PATTERN_TYPE_SURFACE; + src_surface.surface = cairo_surface_reference (source_surface); + src_surface.raster_pattern = NULL; + } + + surface_entry->surface_res = _cairo_pdf_surface_new_object (surface); + if (surface_entry->surface_res.id == 0) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + + status = _cairo_array_append (&surface->page_surfaces, &src_surface); + if (unlikely (status)) + goto fail3; + + status = _cairo_hash_table_insert (surface->all_surfaces, + &surface_entry->base); + if (unlikely(status)) + goto fail3; + + *surface_res = surface_entry->surface_res; + + return status; + +fail3: + if (source_pattern && source_pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) + cairo_pattern_destroy (src_surface.raster_pattern); + else + cairo_surface_destroy (src_surface.surface); + +fail2: + free (surface_entry); + +fail1: + free (unique_id); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_add_pdf_pattern_or_shading (cairo_pdf_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_operator_t op, + const cairo_rectangle_int_t *extents, + cairo_bool_t is_shading, + cairo_pdf_resource_t *pattern_res, + cairo_pdf_resource_t *gstate_res) +{ + cairo_pdf_pattern_t pdf_pattern; + cairo_int_status_t status; + + pdf_pattern.is_shading = is_shading; + pdf_pattern.operator = op; + + /* Solid colors are emitted into the content stream */ + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { + pattern_res->id = 0; + gstate_res->id = 0; + return CAIRO_INT_STATUS_SUCCESS; + } + + status = _cairo_pattern_create_copy (&pdf_pattern.pattern, pattern); + if (unlikely (status)) + return status; + + pdf_pattern.pattern_res = _cairo_pdf_surface_new_object (surface); + if (pdf_pattern.pattern_res.id == 0) { + cairo_pattern_destroy (pdf_pattern.pattern); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pdf_pattern.gstate_res.id = 0; + + /* gradient patterns require an smask object to implement transparency */ + if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || + pattern->type == CAIRO_PATTERN_TYPE_RADIAL || + pattern->type == CAIRO_PATTERN_TYPE_MESH) + { + double min_alpha; + + _cairo_pattern_alpha_range (pattern, &min_alpha, NULL); + if (! CAIRO_ALPHA_IS_OPAQUE (min_alpha)) { + pdf_pattern.gstate_res = _cairo_pdf_surface_new_object (surface); + if (pdf_pattern.gstate_res.id == 0) { + cairo_pattern_destroy (pdf_pattern.pattern); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + } + + pdf_pattern.width = surface->width; + pdf_pattern.height = surface->height; + if (extents != NULL) { + pdf_pattern.extents = *extents; + } else { + pdf_pattern.extents.x = 0; + pdf_pattern.extents.y = 0; + pdf_pattern.extents.width = surface->width; + pdf_pattern.extents.height = surface->height; + } + + *pattern_res = pdf_pattern.pattern_res; + *gstate_res = pdf_pattern.gstate_res; + + status = _cairo_array_append (&surface->page_patterns, &pdf_pattern); + if (unlikely (status)) { + cairo_pattern_destroy (pdf_pattern.pattern); + return status; + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +/* Get BBox in PDF coordinates from extents in cairo coordinates */ +static void +_get_bbox_from_extents (double surface_height, + const cairo_rectangle_int_t *extents, + cairo_box_double_t *bbox) +{ + bbox->p1.x = extents->x; + bbox->p1.y = surface_height - (extents->y + extents->height); + bbox->p2.x = extents->x + extents->width; + bbox->p2.y = surface_height - extents->y; +} + +static cairo_int_status_t +_cairo_pdf_surface_add_pdf_shading (cairo_pdf_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_operator_t op, + const cairo_rectangle_int_t *extents, + cairo_pdf_resource_t *shading_res, + cairo_pdf_resource_t *gstate_res) +{ + return _cairo_pdf_surface_add_pdf_pattern_or_shading (surface, + pattern, + op, + extents, + TRUE, + shading_res, + gstate_res); +} + +static cairo_int_status_t +_cairo_pdf_surface_add_pdf_pattern (cairo_pdf_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_operator_t op, + const cairo_rectangle_int_t *extents, + cairo_pdf_resource_t *pattern_res, + cairo_pdf_resource_t *gstate_res) +{ + return _cairo_pdf_surface_add_pdf_pattern_or_shading (surface, + pattern, + op, + extents, + FALSE, + pattern_res, + gstate_res); +} + +static cairo_int_status_t +_cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t *resource, + cairo_bool_t compressed, + const char *fmt, + ...) +{ + va_list ap; + cairo_pdf_resource_t self, length; + cairo_output_stream_t *output = NULL; + + if (resource) { + self = *resource; + _cairo_pdf_surface_update_object (surface, self); + } else { + self = _cairo_pdf_surface_new_object (surface); + if (self.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + length = _cairo_pdf_surface_new_object (surface); + if (length.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (compressed) { + output = _cairo_deflate_stream_create (surface->output); + if (_cairo_output_stream_get_status (output)) + return _cairo_output_stream_destroy (output); + } + + surface->pdf_stream.active = TRUE; + surface->pdf_stream.self = self; + surface->pdf_stream.length = length; + surface->pdf_stream.compressed = compressed; + surface->current_pattern_is_solid_color = FALSE; + surface->current_operator = CAIRO_OPERATOR_OVER; + _cairo_pdf_operators_reset (&surface->pdf_operators); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Length %d 0 R\n", + surface->pdf_stream.self.id, + surface->pdf_stream.length.id); + if (compressed) + _cairo_output_stream_printf (surface->output, + " /Filter /FlateDecode\n"); + + if (fmt != NULL) { + va_start (ap, fmt); + _cairo_output_stream_vprintf (surface->output, fmt, ap); + va_end (ap); + } + + _cairo_output_stream_printf (surface->output, + ">>\n" + "stream\n"); + + surface->pdf_stream.start_offset = _cairo_output_stream_get_position (surface->output); + + if (compressed) { + assert (surface->pdf_stream.old_output == NULL); + surface->pdf_stream.old_output = surface->output; + surface->output = output; + _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); + } + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +_cairo_pdf_surface_close_stream (cairo_pdf_surface_t *surface) +{ + cairo_int_status_t status; + long length; + + if (! surface->pdf_stream.active) + return CAIRO_INT_STATUS_SUCCESS; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + + if (surface->pdf_stream.compressed) { + cairo_int_status_t status2; + + status2 = _cairo_output_stream_destroy (surface->output); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = status2; + + surface->output = surface->pdf_stream.old_output; + _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); + surface->pdf_stream.old_output = NULL; + } + + length = _cairo_output_stream_get_position (surface->output) - + surface->pdf_stream.start_offset; + _cairo_output_stream_printf (surface->output, + "\n" + "endstream\n" + "endobj\n"); + + _cairo_pdf_surface_update_object (surface, + surface->pdf_stream.length); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + " %ld\n" + "endobj\n", + surface->pdf_stream.length.id, + length); + + surface->pdf_stream.active = FALSE; + + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = _cairo_output_stream_get_status (surface->output); + + return status; +} + +static void +_cairo_pdf_surface_write_memory_stream (cairo_pdf_surface_t *surface, + cairo_output_stream_t *mem_stream, + cairo_pdf_resource_t resource, + cairo_pdf_group_resources_t *resources, + cairo_bool_t is_knockout_group, + const cairo_box_double_t *bbox) +{ + _cairo_pdf_surface_update_object (surface, resource); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /XObject\n" + " /Length %d\n", + resource.id, + _cairo_memory_stream_length (mem_stream)); + + if (surface->compress_content) { + _cairo_output_stream_printf (surface->output, + " /Filter /FlateDecode\n"); + } + + _cairo_output_stream_printf (surface->output, + " /Subtype /Form\n" + " /BBox [ %f %f %f %f ]\n" + " /Group <<\n" + " /Type /Group\n" + " /S /Transparency\n" + " /I true\n" + " /CS /DeviceRGB\n", + bbox->p1.x, bbox->p1.y, bbox->p2.x, bbox->p2.y); + + if (is_knockout_group) + _cairo_output_stream_printf (surface->output, + " /K true\n"); + + _cairo_output_stream_printf (surface->output, + " >>\n" + " /Resources\n"); + _cairo_pdf_surface_emit_group_resources (surface, resources); + _cairo_output_stream_printf (surface->output, + ">>\n" + "stream\n"); + _cairo_memory_stream_copy (mem_stream, surface->output); + _cairo_output_stream_printf (surface->output, + "endstream\n" + "endobj\n"); +} + +static cairo_int_status_t +_cairo_pdf_surface_open_group (cairo_pdf_surface_t *surface, + const cairo_box_double_t *bbox, + cairo_pdf_resource_t *resource) +{ + cairo_int_status_t status; + + assert (surface->pdf_stream.active == FALSE); + assert (surface->group_stream.active == FALSE); + + surface->group_stream.active = TRUE; + surface->current_pattern_is_solid_color = FALSE; + surface->current_operator = CAIRO_OPERATOR_OVER; + _cairo_pdf_operators_reset (&surface->pdf_operators); + + surface->group_stream.mem_stream = _cairo_memory_stream_create (); + + if (surface->compress_content) { + surface->group_stream.stream = + _cairo_deflate_stream_create (surface->group_stream.mem_stream); + } else { + surface->group_stream.stream = surface->group_stream.mem_stream; + } + status = _cairo_output_stream_get_status (surface->group_stream.stream); + + surface->group_stream.old_output = surface->output; + surface->output = surface->group_stream.stream; + _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); + _cairo_pdf_group_resources_clear (&surface->resources); + + if (resource) { + surface->group_stream.resource = *resource; + } else { + surface->group_stream.resource = _cairo_pdf_surface_new_object (surface); + if (surface->group_stream.resource.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + surface->group_stream.is_knockout = FALSE; + surface->group_stream.bbox = *bbox; + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_open_knockout_group (cairo_pdf_surface_t *surface, + const cairo_box_double_t *bbox) +{ + cairo_int_status_t status; + + status = _cairo_pdf_surface_open_group (surface, bbox, NULL); + if (unlikely (status)) + return status; + + surface->group_stream.is_knockout = TRUE; + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_close_group (cairo_pdf_surface_t *surface, + cairo_pdf_resource_t *group) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS, status2; + + assert (surface->pdf_stream.active == FALSE); + assert (surface->group_stream.active == TRUE); + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + if (surface->compress_content) { + status = _cairo_output_stream_destroy (surface->group_stream.stream); + surface->group_stream.stream = NULL; + + _cairo_output_stream_printf (surface->group_stream.mem_stream, + "\n"); + } + surface->output = surface->group_stream.old_output; + _cairo_pdf_operators_set_stream (&surface->pdf_operators, surface->output); + surface->group_stream.active = FALSE; + _cairo_pdf_surface_write_memory_stream (surface, + surface->group_stream.mem_stream, + surface->group_stream.resource, + &surface->resources, + surface->group_stream.is_knockout, + &surface->group_stream.bbox); + if (group) + *group = surface->group_stream.resource; + + status2 = _cairo_output_stream_destroy (surface->group_stream.mem_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + + surface->group_stream.mem_stream = NULL; + surface->group_stream.stream = NULL; + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface, + const cairo_box_double_t *bbox, + cairo_pdf_resource_t *resource, + cairo_bool_t is_form, + cairo_bool_t is_group) +{ + cairo_int_status_t status; + + assert (surface->pdf_stream.active == FALSE); + assert (surface->group_stream.active == FALSE); + + surface->content_resources = _cairo_pdf_surface_new_object (surface); + if (surface->content_resources.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + if (is_form) { + assert (bbox != NULL); + + if (is_group) { + status = + _cairo_pdf_surface_open_stream (surface, + resource, + surface->compress_content, + " /Type /XObject\n" + " /Subtype /Form\n" + " /BBox [ %f %f %f %f ]\n" + " /Group <<\n" + " /Type /Group\n" + " /S /Transparency\n" + " /I true\n" + " /CS /DeviceRGB\n" + " >>\n" + " /Resources %d 0 R\n", + bbox->p1.x, + bbox->p1.y, + bbox->p2.x, + bbox->p2.y, + surface->content_resources.id); + } else { + status = + _cairo_pdf_surface_open_stream (surface, + resource, + surface->compress_content, + " /Type /XObject\n" + " /Subtype /Form\n" + " /BBox [ %f %f %f %f ]\n" + " /Resources %d 0 R\n", + bbox->p1.x, + bbox->p1.y, + bbox->p2.x, + bbox->p2.y, + surface->content_resources.id); + } + } else { + status = + _cairo_pdf_surface_open_stream (surface, + resource, + surface->compress_content, + NULL); + } + if (unlikely (status)) + return status; + + surface->content = surface->pdf_stream.self; + + _cairo_output_stream_printf (surface->output, "q\n"); + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +_cairo_pdf_surface_close_content_stream (cairo_pdf_surface_t *surface) +{ + cairo_int_status_t status; + + assert (surface->pdf_stream.active == TRUE); + assert (surface->group_stream.active == FALSE); + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "Q\n"); + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) + return status; + + _cairo_pdf_surface_update_object (surface, surface->content_resources); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n", + surface->content_resources.id); + _cairo_pdf_surface_emit_group_resources (surface, &surface->resources); + _cairo_output_stream_printf (surface->output, + "endobj\n"); + + return _cairo_output_stream_get_status (surface->output); +} + +static void +_cairo_pdf_source_surface_entry_pluck (void *entry, void *closure) +{ + cairo_pdf_source_surface_entry_t *surface_entry = entry; + cairo_hash_table_t *patterns = closure; + + _cairo_hash_table_remove (patterns, &surface_entry->base); + free (surface_entry->unique_id); + + free (surface_entry); +} + +static cairo_status_t +_cairo_pdf_surface_finish (void *abstract_surface) +{ + cairo_pdf_surface_t *surface = abstract_surface; + long offset; + cairo_pdf_resource_t info, catalog; + cairo_status_t status, status2; + int size, i; + cairo_pdf_jbig2_global_t *global; + + status = surface->base.status; + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_pdf_surface_emit_font_subsets (surface); + + _cairo_pdf_surface_write_pages (surface); + + info = _cairo_pdf_surface_write_info (surface); + if (info.id == 0 && status == CAIRO_STATUS_SUCCESS) + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + + catalog = _cairo_pdf_surface_write_catalog (surface); + if (catalog.id == 0 && status == CAIRO_STATUS_SUCCESS) + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + + offset = _cairo_pdf_surface_write_xref (surface); + + _cairo_output_stream_printf (surface->output, + "trailer\n" + "<< /Size %d\n" + " /Root %d 0 R\n" + " /Info %d 0 R\n" + ">>\n", + surface->next_available_resource.id, + catalog.id, + info.id); + + _cairo_output_stream_printf (surface->output, + "startxref\n" + "%ld\n" + "%%%%EOF\n", + offset); + + /* pdf_operators has already been flushed when the last stream was + * closed so we should never be writing anything here - however, + * the stream may itself be in an error state. */ + status2 = _cairo_pdf_operators_fini (&surface->pdf_operators); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + /* close any active streams still open due to fatal errors */ + status2 = _cairo_pdf_surface_close_stream (surface); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + if (surface->group_stream.stream != NULL) { + status2 = _cairo_output_stream_destroy (surface->group_stream.stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + } + if (surface->group_stream.mem_stream != NULL) { + status2 = _cairo_output_stream_destroy (surface->group_stream.mem_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + } + if (surface->pdf_stream.active) + surface->output = surface->pdf_stream.old_output; + if (surface->group_stream.active) + surface->output = surface->group_stream.old_output; + + /* and finish the pdf surface */ + status2 = _cairo_output_stream_destroy (surface->output); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + _cairo_pdf_surface_clear (surface); + _cairo_pdf_group_resources_fini (&surface->resources); + + _cairo_array_fini (&surface->objects); + _cairo_array_fini (&surface->pages); + _cairo_array_fini (&surface->rgb_linear_functions); + _cairo_array_fini (&surface->alpha_linear_functions); + _cairo_array_fini (&surface->page_patterns); + _cairo_array_fini (&surface->page_surfaces); + _cairo_hash_table_foreach (surface->all_surfaces, + _cairo_pdf_source_surface_entry_pluck, + surface->all_surfaces); + _cairo_hash_table_destroy (surface->all_surfaces); + _cairo_array_fini (&surface->smask_groups); + _cairo_array_fini (&surface->fonts); + _cairo_array_fini (&surface->knockout_group); + + if (surface->font_subsets) { + _cairo_scaled_font_subsets_destroy (surface->font_subsets); + surface->font_subsets = NULL; + } + + size = _cairo_array_num_elements (&surface->jbig2_global); + for (i = 0; i < size; i++) { + global = (cairo_pdf_jbig2_global_t *) _cairo_array_index (&surface->jbig2_global, i); + free(global->id); + if (!global->emitted) + return _cairo_error (CAIRO_STATUS_JBIG2_GLOBAL_MISSING); + } + _cairo_array_fini (&surface->jbig2_global); + + _cairo_array_truncate (&surface->page_surfaces, 0); + + _cairo_surface_clipper_reset (&surface->clipper); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_start_page (void *abstract_surface) +{ + cairo_pdf_surface_t *surface = abstract_surface; + + /* Document header */ + if (! surface->header_emitted) { + const char *version; + + switch (surface->pdf_version) { + case CAIRO_PDF_VERSION_1_4: + version = "1.4"; + break; + default: + case CAIRO_PDF_VERSION_1_5: + version = "1.5"; + break; + } + + _cairo_output_stream_printf (surface->output, + "%%PDF-%s\n", version); + _cairo_output_stream_printf (surface->output, + "%%%c%c%c%c\n", 181, 237, 174, 251); + surface->header_emitted = TRUE; + } + + _cairo_pdf_group_resources_clear (&surface->resources); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_has_fallback_images (void *abstract_surface, + cairo_bool_t has_fallbacks) +{ + cairo_int_status_t status; + cairo_pdf_surface_t *surface = abstract_surface; + cairo_box_double_t bbox; + + surface->has_fallback_images = has_fallbacks; + bbox.p1.x = 0; + bbox.p1.y = 0; + bbox.p2.x = surface->width; + bbox.p2.y = surface->height; + status = _cairo_pdf_surface_open_content_stream (surface, &bbox, NULL, has_fallbacks, has_fallbacks); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_pdf_surface_supports_fine_grained_fallbacks (void *abstract_surface) +{ + return TRUE; +} + +static cairo_int_status_t +_cairo_pdf_surface_add_padded_image_surface (cairo_pdf_surface_t *surface, + const cairo_pattern_t *source, + const cairo_rectangle_int_t *extents, + cairo_pdf_resource_t *surface_res, + int *width, + int *height, + double *x_offset, + double *y_offset) +{ + cairo_image_surface_t *image; + cairo_surface_t *pad_image; + void *image_extra; + cairo_int_status_t status; + int w, h; + cairo_rectangle_int_t extents2; + cairo_box_t box; + cairo_rectangle_int_t rect; + cairo_surface_pattern_t pad_pattern; + + status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source, + &image, &image_extra); + if (unlikely (status)) + return status; + + pad_image = &image->base; + + /* get the operation extents in pattern space */ + _cairo_box_from_rectangle (&box, extents); + _cairo_matrix_transform_bounding_box_fixed (&source->matrix, &box, NULL); + _cairo_box_round_to_rectangle (&box, &rect); + + /* Check if image needs padding to fill extents */ + w = image->width; + h = image->height; + if (_cairo_fixed_integer_ceil(box.p1.x) < 0 || + _cairo_fixed_integer_ceil(box.p1.y) < 0 || + _cairo_fixed_integer_floor(box.p2.x) > w || + _cairo_fixed_integer_floor(box.p2.y) > h) + { + pad_image = _cairo_image_surface_create_with_content (image->base.content, + rect.width, + rect.height); + if (pad_image->status) { + status = pad_image->status; + goto BAIL; + } + + _cairo_pattern_init_for_surface (&pad_pattern, &image->base); + cairo_matrix_init_translate (&pad_pattern.base.matrix, rect.x, rect.y); + pad_pattern.base.extend = CAIRO_EXTEND_PAD; + status = _cairo_surface_paint (pad_image, + CAIRO_OPERATOR_SOURCE, &pad_pattern.base, + NULL); + _cairo_pattern_fini (&pad_pattern.base); + if (unlikely (status)) + goto BAIL; + } + + status = _cairo_pdf_surface_add_source_surface (surface, + pad_image, + NULL, + FALSE, + source->filter, + FALSE, + FALSE, + extents, + NULL, + surface_res, + width, + height, + x_offset, + y_offset, + &extents2); + if (unlikely (status)) + goto BAIL; + + if (pad_image != &image->base) { + /* If using a padded image, replace _add_source_surface + * x/y_offset with padded image offset. Note: + * _add_source_surface only sets a non zero x/y_offset for + * RASTER_SOURCE patterns. _add_source_surface will always set + * x/y_offset to 0 for surfaces so we can ignore the returned + * offset and replace it with the offset required for the + * padded image */ + *x_offset = rect.x; + *y_offset = rect.y; + } + +BAIL: + if (pad_image != &image->base) + cairo_surface_destroy (pad_image); + + _cairo_pdf_surface_release_source_image_from_pattern (surface, source, image, image_extra); + + return status; +} + +/* Emit alpha channel from the image into stream_res. + */ +static cairo_int_status_t +_cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface, + cairo_image_surface_t *image, + cairo_bool_t stencil_mask, + cairo_bool_t interpolate, + cairo_pdf_resource_t *stream_res) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + char *alpha; + unsigned long alpha_size; + uint32_t *pixel32; + uint8_t *pixel8; + int i, x, y, bit, a; + cairo_image_transparency_t transparency; + + /* This is the only image format we support, which simplifies things. */ + assert (image->format == CAIRO_FORMAT_ARGB32 || + image->format == CAIRO_FORMAT_RGB24 || + image->format == CAIRO_FORMAT_A8 || + image->format == CAIRO_FORMAT_A1 ); + + transparency = _cairo_image_analyze_transparency (image); + if (stencil_mask) { + assert (transparency == CAIRO_IMAGE_IS_OPAQUE || + transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA); + } else { + assert (transparency != CAIRO_IMAGE_IS_OPAQUE); + } + + if (transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA || transparency == CAIRO_IMAGE_IS_OPAQUE) { + alpha_size = (image->width + 7) / 8 * image->height; + alpha = _cairo_malloc_ab ((image->width+7) / 8, image->height); + } else { + alpha_size = image->height * image->width; + alpha = _cairo_malloc_ab (image->height, image->width); + } + + if (unlikely (alpha == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP; + } + + i = 0; + for (y = 0; y < image->height; y++) { + if (transparency == CAIRO_IMAGE_IS_OPAQUE) { + for (x = 0; x < (image->width + 7) / 8; x++) + alpha[i++] = 0xff; + } else if (image->format == CAIRO_FORMAT_A1) { + pixel8 = (uint8_t *) (image->data + y * image->stride); + + for (x = 0; x < (image->width + 7) / 8; x++, pixel8++) { + a = *pixel8; + a = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (a); + alpha[i++] = a; + } + } else { + pixel8 = (uint8_t *) (image->data + y * image->stride); + pixel32 = (uint32_t *) (image->data + y * image->stride); + bit = 7; + for (x = 0; x < image->width; x++) { + if (image->format == CAIRO_FORMAT_ARGB32) { + a = (*pixel32 & 0xff000000) >> 24; + pixel32++; + } else { + a = *pixel8; + pixel8++; + } + + if (transparency == CAIRO_IMAGE_HAS_ALPHA) { + alpha[i++] = a; + } else { /* transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA or CAIRO_IMAGE_IS_OPAQUE */ + if (bit == 7) + alpha[i] = 0; + if (a != 0) + alpha[i] |= (1 << bit); + bit--; + if (bit < 0) { + bit = 7; + i++; + } + } + } + if (bit != 7) + i++; + } + } + + if (stencil_mask) { + status = _cairo_pdf_surface_open_stream (surface, + stream_res, + TRUE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /ImageMask true\n" + " /Width %d\n" + " /Height %d\n" + " /Interpolate %s\n" + " /BitsPerComponent 1\n" + " /Decode [1 0]\n", + image->width, image->height, + interpolate ? "true" : "false"); + } else { + status = _cairo_pdf_surface_open_stream (surface, + stream_res, + TRUE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /Width %d\n" + " /Height %d\n" + " /ColorSpace /DeviceGray\n" + " /Interpolate %s\n" + " /BitsPerComponent %d\n", + image->width, image->height, + interpolate ? "true" : "false", + transparency == CAIRO_IMAGE_HAS_ALPHA ? 8 : 1); + } + if (unlikely (status)) + goto CLEANUP_ALPHA; + + _cairo_output_stream_write (surface->output, alpha, alpha_size); + status = _cairo_pdf_surface_close_stream (surface); + + CLEANUP_ALPHA: + free (alpha); + CLEANUP: + return status; +} + +/** + * _cairo_pdf_surface_emit_image: + * @surface: the pdf surface + * @image_surf: The image to write + * @surface_entry: Contains image resource, smask resource, interpolate and stencil mask parameters. + * + * Emit an image stream using the @image_res resource and write out + * the image data from @image_surf. If @smask_res is not null, @smask_res will + * be specified as the smask for the image. Otherwise emit the an smask if + * the image is requires one. + **/ +static cairo_int_status_t +_cairo_pdf_surface_emit_image (cairo_pdf_surface_t *surface, + cairo_image_surface_t *image_surf, + cairo_pdf_source_surface_entry_t *surface_entry) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + char *data; + unsigned long data_size; + uint32_t *pixel; + int i, x, y, bit; + cairo_pdf_resource_t smask = {0}; /* squelch bogus compiler warning */ + cairo_bool_t need_smask; + cairo_image_color_t color; + cairo_image_surface_t *image; + cairo_image_transparency_t transparency; + char smask_buf[30]; + + image = image_surf; + if (image->format != CAIRO_FORMAT_RGB24 && + image->format != CAIRO_FORMAT_ARGB32 && + image->format != CAIRO_FORMAT_A8 && + image->format != CAIRO_FORMAT_A1) + { + cairo_surface_t *surf; + cairo_surface_pattern_t pattern; + + surf = _cairo_image_surface_create_with_content (image_surf->base.content, + image_surf->width, + image_surf->height); + image = (cairo_image_surface_t *) surf; + if (surf->status) { + status = surf->status; + goto CLEANUP; + } + + _cairo_pattern_init_for_surface (&pattern, &image_surf->base); + status = _cairo_surface_paint (surf, + CAIRO_OPERATOR_SOURCE, &pattern.base, + NULL); + _cairo_pattern_fini (&pattern.base); + if (unlikely (status)) + goto CLEANUP; + } + + if (surface_entry->smask || surface_entry->stencil_mask) { + return _cairo_pdf_surface_emit_smask (surface, image, + surface_entry->stencil_mask, + surface_entry->interpolate, + &surface_entry->surface_res); + } + + color = _cairo_image_analyze_color (image); + switch (color) { + default: + case CAIRO_IMAGE_UNKNOWN_COLOR: + ASSERT_NOT_REACHED; + case CAIRO_IMAGE_IS_COLOR: + data_size = image->height * image->width * 3; + data = _cairo_malloc_abc (image->width, image->height, 3); + break; + + case CAIRO_IMAGE_IS_GRAYSCALE: + data_size = image->height * image->width; + data = _cairo_malloc_ab (image->width, image->height); + break; + case CAIRO_IMAGE_IS_MONOCHROME: + data_size = (image->width + 7) / 8 * image->height; + data = _cairo_malloc_ab ((image->width+7) / 8, image->height); + break; + } + if (unlikely (data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP; + } + + i = 0; + for (y = 0; y < image->height; y++) { + pixel = (uint32_t *) (image->data + y * image->stride); + + bit = 7; + for (x = 0; x < image->width; x++, pixel++) { + int r, g, b; + + /* XXX: We're un-premultiplying alpha here. My reading of the PDF + * specification suggests that we should be able to avoid having + * to do this by filling in the SMask's Matte dictionary + * appropriately, but my attempts to do that so far have + * failed. */ + if (image->format == CAIRO_FORMAT_ARGB32) { + uint8_t a; + a = (*pixel & 0xff000000) >> 24; + if (a == 0) { + r = g = b = 0; + } else { + r = (((*pixel & 0xff0000) >> 16) * 255 + a / 2) / a; + g = (((*pixel & 0x00ff00) >> 8) * 255 + a / 2) / a; + b = (((*pixel & 0x0000ff) >> 0) * 255 + a / 2) / a; + } + } else if (image->format == CAIRO_FORMAT_RGB24) { + r = (*pixel & 0x00ff0000) >> 16; + g = (*pixel & 0x0000ff00) >> 8; + b = (*pixel & 0x000000ff) >> 0; + } else { + r = g = b = 0; + } + + switch (color) { + case CAIRO_IMAGE_IS_COLOR: + case CAIRO_IMAGE_UNKNOWN_COLOR: + data[i++] = r; + data[i++] = g; + data[i++] = b; + break; + + case CAIRO_IMAGE_IS_GRAYSCALE: + data[i++] = r; + break; + + case CAIRO_IMAGE_IS_MONOCHROME: + if (bit == 7) + data[i] = 0; + if (r != 0) + data[i] |= (1 << bit); + bit--; + if (bit < 0) { + bit = 7; + i++; + } + break; + } + } + if (bit != 7) + i++; + } + + if (surface_entry->smask_res.id != 0) { + need_smask = TRUE; + smask = surface_entry->smask_res; + } else { + need_smask = FALSE; + if (image->format == CAIRO_FORMAT_ARGB32 || + image->format == CAIRO_FORMAT_A8 || + image->format == CAIRO_FORMAT_A1) + { + transparency = _cairo_image_analyze_transparency (image); + if (transparency != CAIRO_IMAGE_IS_OPAQUE) { + need_smask = TRUE; + smask = _cairo_pdf_surface_new_object (surface); + if (smask.id == 0) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_RGB; + } + + status = _cairo_pdf_surface_emit_smask (surface, image, FALSE, surface_entry->interpolate, &smask); + if (unlikely (status)) + goto CLEANUP_RGB; + } + } + } + + if (need_smask) + snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", smask.id); + else + smask_buf[0] = 0; + + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + TRUE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /Width %d\n" + " /Height %d\n" + " /ColorSpace %s\n" + " /Interpolate %s\n" + " /BitsPerComponent %d\n" + "%s", + image->width, + image->height, + color == CAIRO_IMAGE_IS_COLOR ? "/DeviceRGB" : "/DeviceGray", + surface_entry->interpolate ? "true" : "false", + color == CAIRO_IMAGE_IS_MONOCHROME? 1 : 8, + smask_buf); + if (unlikely (status)) + goto CLEANUP_RGB; + +#undef IMAGE_DICTIONARY + + _cairo_output_stream_write (surface->output, data, data_size); + status = _cairo_pdf_surface_close_stream (surface); + +CLEANUP_RGB: + free (data); +CLEANUP: + if (image != image_surf) + cairo_surface_destroy (&image->base); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_lookup_jbig2_global (cairo_pdf_surface_t *surface, + const unsigned char *global_id, + unsigned long global_id_length, + cairo_pdf_jbig2_global_t **entry) +{ + cairo_pdf_jbig2_global_t global; + int size, i; + cairo_int_status_t status; + + size = _cairo_array_num_elements (&surface->jbig2_global); + for (i = 0; i < size; i++) { + *entry = (cairo_pdf_jbig2_global_t *) _cairo_array_index (&surface->jbig2_global, i); + if ((*entry)->id && global_id && (*entry)->id_length == global_id_length + && memcmp((*entry)->id, global_id, global_id_length) == 0) { + return CAIRO_STATUS_SUCCESS; + } + } + + global.id = malloc(global_id_length); + if (unlikely (global.id == NULL)) { + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + memcpy (global.id, global_id, global_id_length); + global.id_length = global_id_length; + global.res = _cairo_pdf_surface_new_object (surface); + if (global.res.id == 0) { + free(global.id); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + global.emitted = FALSE; + status = _cairo_array_append (&surface->jbig2_global, &global); + if (unlikely(status)) + return status; + + size = _cairo_array_num_elements (&surface->jbig2_global); + *entry = (cairo_pdf_jbig2_global_t *) _cairo_array_index (&surface->jbig2_global, size - 1); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_jbig2_image (cairo_pdf_surface_t *surface, + cairo_surface_t *source, + cairo_pdf_source_surface_entry_t *surface_entry) +{ + cairo_int_status_t status; + const unsigned char *mime_data; + unsigned long mime_data_length; + cairo_image_info_t info; + const unsigned char *global_id; + unsigned long global_id_length; + const unsigned char *global_data; + unsigned long global_data_length; + cairo_pdf_jbig2_global_t *global_entry = NULL; /* hide compiler warning */ + char smask_buf[30]; + char decode_parms_buf[100]; + + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2, + &mime_data, &mime_data_length); + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_image_info_get_jbig2_info (&info, mime_data, mime_data_length); + if (status) + return status; + + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, + &global_id, &global_id_length); + if (global_id && global_id_length > 0) { + status = _cairo_pdf_surface_lookup_jbig2_global (surface, global_id, global_id_length, &global_entry); + if (unlikely(status)) + return status; + + if (!global_entry->emitted) { + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JBIG2_GLOBAL, + &global_data, &global_data_length); + if (global_data) { + status = _cairo_pdf_surface_open_stream (surface, &global_entry->res, FALSE, NULL); + if (unlikely(status)) + return status; + + _cairo_output_stream_write (surface->output, global_data, global_data_length); + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely(status)) + return status; + + global_entry->emitted = TRUE; + } + } + + snprintf(decode_parms_buf, sizeof(decode_parms_buf), + " /DecodeParms << /JBIG2Globals %d 0 R >>\n", global_entry->res.id); + } else { + decode_parms_buf[0] = 0; + } + + if (surface_entry->smask_res.id) + snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", surface_entry->smask_res.id); + else + smask_buf[0] = 0; + + if (surface_entry->stencil_mask) { + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + FALSE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /ImageMask true\n" + " /Width %d\n" + " /Height %d\n" + " /Interpolate %s\n" + " /BitsPerComponent 1\n" + " /Decode [1 0]\n" + " /Filter /JPXDecode\n" + "%s", + info.width, + info.height, + surface_entry->interpolate ? "true" : "false", + decode_parms_buf); + } else { + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + FALSE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /Width %d\n" + " /Height %d\n" + " /ColorSpace /DeviceGray\n" + " /BitsPerComponent 1\n" + " /Interpolate %s\n" + "%s" + " /Filter /JBIG2Decode\n" + "%s", + info.width, + info.height, + surface_entry->interpolate ? "true" : "false", + smask_buf, + decode_parms_buf); + } + if (unlikely(status)) + return status; + + _cairo_output_stream_write (surface->output, mime_data, mime_data_length); + status = _cairo_pdf_surface_close_stream (surface); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_jpx_image (cairo_pdf_surface_t *surface, + cairo_surface_t *source, + cairo_pdf_source_surface_entry_t *surface_entry) +{ + cairo_int_status_t status; + const unsigned char *mime_data; + unsigned long mime_data_length; + cairo_image_info_t info; + char smask_buf[30]; + + if (surface->pdf_version < CAIRO_PDF_VERSION_1_5) + return CAIRO_INT_STATUS_UNSUPPORTED; + + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JP2, + &mime_data, &mime_data_length); + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_image_info_get_jpx_info (&info, mime_data, mime_data_length); + if (status) + return status; + + if ((surface_entry->smask || surface_entry->stencil_mask) && info.num_components != 1) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface_entry->stencil_mask) && info.bits_per_component != 1) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (surface_entry->smask_res.id) + snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", surface_entry->smask_res.id); + else + smask_buf[0] = 0; + + if (surface_entry->stencil_mask) { + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + FALSE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /ImageMask true\n" + " /Width %d\n" + " /Height %d\n" + " /Interpolate %s\n" + " /BitsPerComponent 1\n" + " /Decode [1 0]\n" + " /Filter /JPXDecode\n", + info.width, + info.height, + surface_entry->interpolate ? "true" : "false"); + } else { + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + FALSE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /Width %d\n" + " /Height %d\n" + " /Interpolate %s\n" + "%s" + " /Filter /JPXDecode\n", + info.width, + info.height, + surface_entry->interpolate ? "true" : "false", + smask_buf); + } + if (status) + return status; + + _cairo_output_stream_write (surface->output, mime_data, mime_data_length); + status = _cairo_pdf_surface_close_stream (surface); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_jpeg_image (cairo_pdf_surface_t *surface, + cairo_surface_t *source, + cairo_pdf_source_surface_entry_t *surface_entry) +{ + cairo_int_status_t status; + const unsigned char *mime_data; + unsigned long mime_data_length; + cairo_image_info_t info; + const char *colorspace; + char smask_buf[30]; + + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG, + &mime_data, &mime_data_length); + if (unlikely (source->status)) + return source->status; + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_image_info_get_jpeg_info (&info, mime_data, mime_data_length); + if (unlikely (status)) + return status; + + if ((surface_entry->smask || surface_entry->stencil_mask) && info.num_components != 1) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface_entry->stencil_mask) && info.bits_per_component != 1) + return CAIRO_INT_STATUS_UNSUPPORTED; + + switch (info.num_components) { + case 1: + colorspace = "/DeviceGray"; + break; + case 3: + colorspace = "/DeviceRGB"; + break; + case 4: + colorspace = "/DeviceCMYK"; + break; + default: + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (surface_entry->smask_res.id) + snprintf(smask_buf, sizeof(smask_buf), " /SMask %d 0 R\n", surface_entry->smask_res.id); + else + smask_buf[0] = 0; + + if (surface_entry->stencil_mask) { + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + FALSE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /ImageMask true\n" + " /Width %d\n" + " /Height %d\n" + " /Interpolate %s\n" + " /BitsPerComponent 1\n" + " /Decode [1 0]\n" + " /Filter /DCTDecode\n", + info.width, + info.height, + surface_entry->interpolate ? "true" : "false"); + } else { + status = _cairo_pdf_surface_open_stream (surface, + &surface_entry->surface_res, + FALSE, + " /Type /XObject\n" + " /Subtype /Image\n" + " /Width %d\n" + " /Height %d\n" + " /ColorSpace %s\n" + " /Interpolate %s\n" + " /BitsPerComponent %d\n" + "%s" + " /Filter /DCTDecode\n", + info.width, + info.height, + colorspace, + surface_entry->interpolate ? "true" : "false", + info.bits_per_component, + smask_buf); + } + if (unlikely (status)) + return status; + + _cairo_output_stream_write (surface->output, mime_data, mime_data_length); + status = _cairo_pdf_surface_close_stream (surface); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_image_surface (cairo_pdf_surface_t *surface, + cairo_pdf_source_surface_t *source) +{ + cairo_image_surface_t *image; + void *image_extra; + cairo_int_status_t status; + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { + status = _cairo_pdf_surface_emit_jbig2_image (surface, source->surface, source->hash_entry); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_pdf_surface_emit_jpx_image (surface, source->surface, source->hash_entry); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_pdf_surface_emit_jpeg_image (surface, source->surface, source->hash_entry); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { + status = _cairo_surface_acquire_source_image (source->surface, &image, &image_extra); + } else { + status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source->raster_pattern, + &image, &image_extra); + } + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_image (surface, + image, + source->hash_entry); + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) + _cairo_surface_release_source_image (source->surface, image, image_extra); + else + _cairo_pdf_surface_release_source_image_from_pattern (surface, source->raster_pattern, + image, image_extra); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_recording_surface (cairo_pdf_surface_t *surface, + cairo_pdf_source_surface_t *pdf_source) +{ + double old_width, old_height; + cairo_paginated_mode_t old_paginated_mode; + cairo_surface_clipper_t old_clipper; + cairo_box_double_t bbox; + cairo_int_status_t status; + int alpha = 0; + cairo_surface_t *free_me = NULL; + cairo_surface_t *source; + const cairo_rectangle_int_t *extents; + int width; + int height; + cairo_bool_t is_subsurface; + cairo_bool_t transparency_group; + cairo_recording_surface_t *recording; + + assert (pdf_source->type == CAIRO_PATTERN_TYPE_SURFACE); + extents = &pdf_source->hash_entry->extents; + width = pdf_source->hash_entry->width; + height = pdf_source->hash_entry->height; + is_subsurface = FALSE; + source = pdf_source->surface; + if (_cairo_surface_is_snapshot (source)) { + free_me = source = _cairo_surface_snapshot_get_target (source); + } else if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; + + source = sub->target; + extents = &sub->extents; + width = extents->width; + height = extents->height; + is_subsurface = TRUE; + } + + assert (source->type == CAIRO_SURFACE_TYPE_RECORDING); + recording = (cairo_recording_surface_t *) source; + + old_width = surface->width; + old_height = surface->height; + old_paginated_mode = surface->paginated_mode; + old_clipper = surface->clipper; + _cairo_surface_clipper_init (&surface->clipper, + _cairo_pdf_surface_clipper_intersect_clip_path); + + _cairo_pdf_surface_set_size_internal (surface, width, height); + + /* Patterns are emitted after fallback images. The paginated mode + * needs to be set to _RENDER while the recording surface is replayed + * back to this surface. + */ + surface->paginated_mode = CAIRO_PAGINATED_MODE_RENDER; + _cairo_pdf_group_resources_clear (&surface->resources); + _get_bbox_from_extents (height, extents, &bbox); + + /* We can optimize away the transparency group allowing the viewer + * to replay the group in place when all operators are OVER and the + * recording contains only opaque and/or clear alpha. + */ + transparency_group = !(pdf_source->hash_entry->operator == CAIRO_OPERATOR_OVER && + _cairo_recording_surface_has_only_bilevel_alpha (recording) && + _cairo_recording_surface_has_only_op_over (recording)); + status = _cairo_pdf_surface_open_content_stream (surface, &bbox, &pdf_source->hash_entry->surface_res, + TRUE, transparency_group); + if (unlikely (status)) + goto err; + + if (source->content == CAIRO_CONTENT_COLOR) { + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (unlikely (status)) + goto err; + + _cairo_output_stream_printf (surface->output, + "q /a%d gs 0 0 0 rg 0 0 %f %f re f Q\n", + alpha, + surface->width, + surface->height); + } + + status = _cairo_recording_surface_replay_region (source, + is_subsurface ? extents : NULL, + &surface->base, + CAIRO_RECORDING_REGION_NATIVE); + assert (status != CAIRO_INT_STATUS_UNSUPPORTED); + if (unlikely (status)) + goto err; + + status = _cairo_pdf_surface_close_content_stream (surface); + + _cairo_surface_clipper_reset (&surface->clipper); + surface->clipper = old_clipper; + _cairo_pdf_surface_set_size_internal (surface, + old_width, + old_height); + surface->paginated_mode = old_paginated_mode; + +err: + cairo_surface_destroy (free_me); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_surface (cairo_pdf_surface_t *surface, + cairo_pdf_source_surface_t *src_surface) +{ + if (src_surface->type == CAIRO_PATTERN_TYPE_SURFACE && + src_surface->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + return _cairo_pdf_surface_emit_recording_surface (surface, src_surface); + + return _cairo_pdf_surface_emit_image_surface (surface, src_surface); +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_surface_pattern (cairo_pdf_surface_t *surface, + cairo_pdf_pattern_t *pdf_pattern) +{ + cairo_pattern_t *pattern = pdf_pattern->pattern; + cairo_int_status_t status; + cairo_pdf_resource_t pattern_resource = {0}; + cairo_matrix_t cairo_p2d, pdf_p2d; + cairo_extend_t extend = cairo_pattern_get_extend (pattern); + double xstep, ystep; + cairo_rectangle_int_t pattern_extents; + int pattern_width = 0; /* squelch bogus compiler warning */ + int pattern_height = 0; /* squelch bogus compiler warning */ + double x_offset; + double y_offset; + char draw_surface[200]; + cairo_box_double_t bbox; + + if (pattern->extend == CAIRO_EXTEND_PAD) { + status = _cairo_pdf_surface_add_padded_image_surface (surface, + pattern, + &pdf_pattern->extents, + &pattern_resource, + &pattern_width, + &pattern_height, + &x_offset, + &y_offset); + pattern_extents.x = 0; + pattern_extents.y = 0; + pattern_extents.width = pattern_width; + pattern_extents.height = pattern_height; + } else { + status = _cairo_pdf_surface_add_source_surface (surface, + NULL, + pattern, + pdf_pattern->operator, + pattern->filter, + FALSE, + FALSE, + &pdf_pattern->extents, + NULL, + &pattern_resource, + &pattern_width, + &pattern_height, + &x_offset, + &y_offset, + &pattern_extents); + } + if (unlikely (status)) + return status; + + switch (extend) { + case CAIRO_EXTEND_PAD: + case CAIRO_EXTEND_NONE: + { + /* In PS/PDF, (as far as I can tell), all patterns are + * repeating. So we support cairo's EXTEND_NONE semantics + * by setting the repeat step size to a size large enough + * to guarantee that no more than a single occurrence will + * be visible. + * + * First, map the surface extents into pattern space (since + * xstep and ystep are in pattern space). Then use an upper + * bound on the length of the diagonal of the pattern image + * and the surface as repeat size. This guarantees to never + * repeat visibly. + */ + double x1 = 0.0, y1 = 0.0; + double x2 = surface->width, y2 = surface->height; + _cairo_matrix_transform_bounding_box (&pattern->matrix, + &x1, &y1, &x2, &y2, + NULL); + + /* Rather than computing precise bounds of the union, just + * add the surface extents unconditionally. We only + * required an answer that's large enough, we don't really + * care if it's not as tight as possible.*/ + xstep = ystep = ceil ((x2 - x1) + (y2 - y1) + + pattern_width + pattern_height); + } + break; + case CAIRO_EXTEND_REPEAT: + xstep = pattern_width; + ystep = pattern_height; + break; + case CAIRO_EXTEND_REFLECT: + pattern_extents.x = 0; + pattern_extents.y = 0; + pattern_extents.width = pattern_width*2; + pattern_extents.height = pattern_height*2; + xstep = pattern_width*2; + ystep = pattern_height*2; + break; + /* All the rest (if any) should have been analyzed away, so this + * case should be unreachable. */ + default: + ASSERT_NOT_REACHED; + xstep = 0; + ystep = 0; + } + + /* At this point, (that is, within the surface backend interface), + * the pattern's matrix maps from cairo's device space to cairo's + * pattern space, (both with their origin at the upper-left, and + * cairo's pattern space of size width,height). + * + * Then, we must emit a PDF pattern object that maps from its own + * pattern space, (which has a size that we establish in the BBox + * dictionary entry), to the PDF page's *initial* space, (which + * does not benefit from the Y-axis flipping matrix that we emit + * on each page). So the PDF patterns matrix maps from a + * (width,height) pattern space to a device space with the origin + * in the lower-left corner. + * + * So to handle all of that, we start with an identity matrix for + * the PDF pattern to device matrix. We translate it up by the + * image height then flip it in the Y direction, (moving us from + * the PDF origin to cairo's origin). We then multiply in the + * inverse of the cairo pattern matrix, (since it maps from device + * to pattern, while we're setting up pattern to device). Finally, + * we translate back down by the image height and flip again to + * end up at the lower-left origin that PDF expects. + * + * Additionally, within the stream that paints the pattern itself, + * we are using a PDF image object that has a size of (1,1) so we + * have to scale it up by the image width and height to fill our + * pattern cell. + */ + cairo_p2d = pattern->matrix; + status = cairo_matrix_invert (&cairo_p2d); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + + cairo_matrix_multiply (&pdf_p2d, &cairo_p2d, &surface->cairo_to_pdf); + cairo_matrix_translate (&pdf_p2d, -x_offset, -y_offset); + cairo_matrix_translate (&pdf_p2d, 0.0, pattern_height); + cairo_matrix_scale (&pdf_p2d, 1.0, -1.0); + + _get_bbox_from_extents (pattern_height, &pattern_extents, &bbox); + _cairo_pdf_surface_update_object (surface, pdf_pattern->pattern_res); + status = _cairo_pdf_surface_open_stream (surface, + &pdf_pattern->pattern_res, + FALSE, + " /PatternType 1\n" + " /BBox [ %f %f %f %f ]\n" + " /XStep %f\n" + " /YStep %f\n" + " /TilingType 1\n" + " /PaintType 1\n" + " /Matrix [ %f %f %f %f %f %f ]\n" + " /Resources << /XObject << /x%d %d 0 R >> >>\n", + bbox.p1.x, bbox.p1.y, bbox.p2.x, bbox.p2.y, + xstep, ystep, + pdf_p2d.xx, pdf_p2d.yx, + pdf_p2d.xy, pdf_p2d.yy, + pdf_p2d.x0, pdf_p2d.y0, + pattern_resource.id, + pattern_resource.id); + if (unlikely (status)) + return status; + + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *) pattern)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { + snprintf(draw_surface, + sizeof (draw_surface), + "/x%d Do\n", + pattern_resource.id); + } else { + snprintf(draw_surface, + sizeof (draw_surface), + "q %d 0 0 %d 0 0 cm /x%d Do Q", + pattern_width, + pattern_height, + pattern_resource.id); + } + + if (extend == CAIRO_EXTEND_REFLECT) { + _cairo_output_stream_printf (surface->output, + "q 0 0 %d %d re W n %s Q\n" + "q -1 0 0 1 %d 0 cm 0 0 %d %d re W n %s Q\n" + "q 1 0 0 -1 0 %d cm 0 0 %d %d re W n %s Q\n" + "q -1 0 0 -1 %d %d cm 0 0 %d %d re W n %s Q\n", + pattern_width, pattern_height, + draw_surface, + pattern_width*2, pattern_width, pattern_height, + draw_surface, + pattern_height*2, pattern_width, pattern_height, + draw_surface, + pattern_width*2, pattern_height*2, pattern_width, pattern_height, + draw_surface); + } else { + _cairo_output_stream_printf (surface->output, + " %s \n", + draw_surface); + } + + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) + return status; + + return _cairo_output_stream_get_status (surface->output); +} + +typedef struct _cairo_pdf_color_stop { + double offset; + double color[4]; + cairo_pdf_resource_t resource; +} cairo_pdf_color_stop_t; + +static cairo_int_status_t +cairo_pdf_surface_emit_rgb_linear_function (cairo_pdf_surface_t *surface, + cairo_pdf_color_stop_t *stop1, + cairo_pdf_color_stop_t *stop2, + cairo_pdf_resource_t *function) +{ + int num_elems, i; + cairo_pdf_rgb_linear_function_t elem; + cairo_pdf_resource_t res; + cairo_int_status_t status; + + num_elems = _cairo_array_num_elements (&surface->rgb_linear_functions); + for (i = 0; i < num_elems; i++) { + _cairo_array_copy_element (&surface->rgb_linear_functions, i, &elem); + if (memcmp (&elem.color1[0], &stop1->color[0], sizeof (double)*3) != 0) + continue; + if (memcmp (&elem.color2[0], &stop2->color[0], sizeof (double)*3) != 0) + continue; + *function = elem.resource; + return CAIRO_STATUS_SUCCESS; + } + + res = _cairo_pdf_surface_new_object (surface); + if (res.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /FunctionType 2\n" + " /Domain [ 0 1 ]\n" + " /C0 [ %f %f %f ]\n" + " /C1 [ %f %f %f ]\n" + " /N 1\n" + ">>\n" + "endobj\n", + res.id, + stop1->color[0], + stop1->color[1], + stop1->color[2], + stop2->color[0], + stop2->color[1], + stop2->color[2]); + + elem.resource = res; + memcpy (&elem.color1[0], &stop1->color[0], sizeof (double)*3); + memcpy (&elem.color2[0], &stop2->color[0], sizeof (double)*3); + + status = _cairo_array_append (&surface->rgb_linear_functions, &elem); + *function = res; + + return status; +} + +static cairo_int_status_t +cairo_pdf_surface_emit_alpha_linear_function (cairo_pdf_surface_t *surface, + cairo_pdf_color_stop_t *stop1, + cairo_pdf_color_stop_t *stop2, + cairo_pdf_resource_t *function) +{ + int num_elems, i; + cairo_pdf_alpha_linear_function_t elem; + cairo_pdf_resource_t res; + cairo_int_status_t status; + + num_elems = _cairo_array_num_elements (&surface->alpha_linear_functions); + for (i = 0; i < num_elems; i++) { + _cairo_array_copy_element (&surface->alpha_linear_functions, i, &elem); + if (elem.alpha1 != stop1->color[3]) + continue; + if (elem.alpha2 != stop2->color[3]) + continue; + *function = elem.resource; + return CAIRO_STATUS_SUCCESS; + } + + res = _cairo_pdf_surface_new_object (surface); + if (res.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /FunctionType 2\n" + " /Domain [ 0 1 ]\n" + " /C0 [ %f ]\n" + " /C1 [ %f ]\n" + " /N 1\n" + ">>\n" + "endobj\n", + res.id, + stop1->color[3], + stop2->color[3]); + + elem.resource = res; + elem.alpha1 = stop1->color[3]; + elem.alpha2 = stop2->color[3]; + + status = _cairo_array_append (&surface->alpha_linear_functions, &elem); + *function = res; + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_stitched_colorgradient (cairo_pdf_surface_t *surface, + unsigned int n_stops, + cairo_pdf_color_stop_t *stops, + cairo_bool_t is_alpha, + cairo_pdf_resource_t *function) +{ + cairo_pdf_resource_t res; + unsigned int i; + cairo_int_status_t status; + + /* emit linear gradients between pairs of subsequent stops... */ + for (i = 0; i < n_stops-1; i++) { + if (is_alpha) { + status = cairo_pdf_surface_emit_alpha_linear_function (surface, + &stops[i], + &stops[i+1], + &stops[i].resource); + if (unlikely (status)) + return status; + } else { + status = cairo_pdf_surface_emit_rgb_linear_function (surface, + &stops[i], + &stops[i+1], + &stops[i].resource); + if (unlikely (status)) + return status; + } + } + + /* ... and stitch them together */ + res = _cairo_pdf_surface_new_object (surface); + if (res.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /FunctionType 3\n" + " /Domain [ %f %f ]\n", + res.id, + stops[0].offset, + stops[n_stops - 1].offset); + + _cairo_output_stream_printf (surface->output, + " /Functions [ "); + for (i = 0; i < n_stops-1; i++) + _cairo_output_stream_printf (surface->output, + "%d 0 R ", stops[i].resource.id); + _cairo_output_stream_printf (surface->output, + "]\n"); + + _cairo_output_stream_printf (surface->output, + " /Bounds [ "); + for (i = 1; i < n_stops-1; i++) + _cairo_output_stream_printf (surface->output, + "%f ", stops[i].offset); + _cairo_output_stream_printf (surface->output, + "]\n"); + + _cairo_output_stream_printf (surface->output, + " /Encode [ "); + for (i = 1; i < n_stops; i++) + _cairo_output_stream_printf (surface->output, + "0 1 "); + _cairo_output_stream_printf (surface->output, + "]\n"); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + + *function = res; + + return _cairo_output_stream_get_status (surface->output); +} + + +static void +calc_gradient_color (cairo_pdf_color_stop_t *new_stop, + cairo_pdf_color_stop_t *stop1, + cairo_pdf_color_stop_t *stop2) +{ + int i; + double offset = stop1->offset / (stop1->offset + 1.0 - stop2->offset); + + for (i = 0; i < 4; i++) + new_stop->color[i] = stop1->color[i] + offset*(stop2->color[i] - stop1->color[i]); +} + +#define COLOR_STOP_EPSILON 1e-6 + +static cairo_int_status_t +_cairo_pdf_surface_emit_pattern_stops (cairo_pdf_surface_t *surface, + cairo_gradient_pattern_t *pattern, + cairo_pdf_resource_t *color_function, + cairo_pdf_resource_t *alpha_function) +{ + cairo_pdf_color_stop_t *allstops, *stops; + unsigned int n_stops; + unsigned int i; + cairo_bool_t emit_alpha = FALSE; + cairo_int_status_t status; + + color_function->id = 0; + alpha_function->id = 0; + + allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_pdf_color_stop_t)); + if (unlikely (allstops == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + stops = &allstops[1]; + n_stops = pattern->n_stops; + + for (i = 0; i < n_stops; i++) { + stops[i].color[0] = pattern->stops[i].color.red; + stops[i].color[1] = pattern->stops[i].color.green; + stops[i].color[2] = pattern->stops[i].color.blue; + stops[i].color[3] = pattern->stops[i].color.alpha; + if (!CAIRO_ALPHA_IS_OPAQUE (stops[i].color[3])) + emit_alpha = TRUE; + stops[i].offset = pattern->stops[i].offset; + } + + if (pattern->base.extend == CAIRO_EXTEND_REPEAT || + pattern->base.extend == CAIRO_EXTEND_REFLECT) { + if (stops[0].offset > COLOR_STOP_EPSILON) { + if (pattern->base.extend == CAIRO_EXTEND_REFLECT) + memcpy (allstops, stops, sizeof (cairo_pdf_color_stop_t)); + else + calc_gradient_color (&allstops[0], &stops[0], &stops[n_stops-1]); + stops = allstops; + n_stops++; + } + stops[0].offset = 0.0; + + if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) { + if (pattern->base.extend == CAIRO_EXTEND_REFLECT) { + memcpy (&stops[n_stops], + &stops[n_stops - 1], + sizeof (cairo_pdf_color_stop_t)); + } else { + calc_gradient_color (&stops[n_stops], &stops[0], &stops[n_stops-1]); + } + n_stops++; + } + stops[n_stops-1].offset = 1.0; + } + + if (stops[0].offset == stops[n_stops - 1].offset) { + /* + * The first and the last stops have the same offset, but we + * don't want a function with an empty domain, because that + * would provoke underdefined behaviour from rasterisers. + * This can only happen with EXTEND_PAD, because EXTEND_NONE + * is optimised into a clear pattern in cairo-gstate, and + * REFLECT/REPEAT are always transformed to have the first + * stop at t=0 and the last stop at t=1. Thus we want a step + * function going from the first color to the last one. + * + * This can be accomplished by stitching three functions: + * - a constant first color function, + * - a step from the first color to the last color (with empty domain) + * - a constant last color function + */ + cairo_pdf_color_stop_t pad_stops[4]; + + assert (pattern->base.extend == CAIRO_EXTEND_PAD); + + pad_stops[0] = pad_stops[1] = stops[0]; + pad_stops[2] = pad_stops[3] = stops[n_stops - 1]; + + pad_stops[0].offset = 0; + pad_stops[3].offset = 1; + + status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, + 4, + pad_stops, + FALSE, + color_function); + if (unlikely (status)) + goto BAIL; + + if (emit_alpha) { + status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, + 4, + pad_stops, + TRUE, + alpha_function); + if (unlikely (status)) + goto BAIL; + } + } else if (n_stops == 2) { + /* no need for stitched function */ + status = cairo_pdf_surface_emit_rgb_linear_function (surface, + &stops[0], + &stops[n_stops - 1], + color_function); + if (unlikely (status)) + goto BAIL; + + if (emit_alpha) { + status = cairo_pdf_surface_emit_alpha_linear_function (surface, + &stops[0], + &stops[n_stops - 1], + alpha_function); + if (unlikely (status)) + goto BAIL; + } + } else { + /* multiple stops: stitch. XXX possible optimization: regularly spaced + * stops do not require stitching. XXX */ + status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, + n_stops, + stops, + FALSE, + color_function); + if (unlikely (status)) + goto BAIL; + + if (emit_alpha) { + status = _cairo_pdf_surface_emit_stitched_colorgradient (surface, + n_stops, + stops, + TRUE, + alpha_function); + if (unlikely (status)) + goto BAIL; + } + } + +BAIL: + free (allstops); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_repeating_function (cairo_pdf_surface_t *surface, + cairo_gradient_pattern_t *pattern, + cairo_pdf_resource_t *function, + int begin, + int end) +{ + cairo_pdf_resource_t res; + int i; + + res = _cairo_pdf_surface_new_object (surface); + if (res.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /FunctionType 3\n" + " /Domain [ %d %d ]\n", + res.id, + begin, + end); + + _cairo_output_stream_printf (surface->output, + " /Functions [ "); + for (i = begin; i < end; i++) + _cairo_output_stream_printf (surface->output, + "%d 0 R ", function->id); + _cairo_output_stream_printf (surface->output, + "]\n"); + + _cairo_output_stream_printf (surface->output, + " /Bounds [ "); + for (i = begin + 1; i < end; i++) + _cairo_output_stream_printf (surface->output, + "%d ", i); + _cairo_output_stream_printf (surface->output, + "]\n"); + + _cairo_output_stream_printf (surface->output, + " /Encode [ "); + for (i = begin; i < end; i++) { + if ((i % 2) && pattern->base.extend == CAIRO_EXTEND_REFLECT) { + _cairo_output_stream_printf (surface->output, + "1 0 "); + } else { + _cairo_output_stream_printf (surface->output, + "0 1 "); + } + } + _cairo_output_stream_printf (surface->output, + "]\n"); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + + *function = res; + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +cairo_pdf_surface_emit_transparency_group (cairo_pdf_surface_t *surface, + cairo_pdf_pattern_t *pdf_pattern, + cairo_pdf_resource_t gstate_resource, + cairo_pdf_resource_t gradient_mask) +{ + cairo_pdf_resource_t smask_resource; + cairo_int_status_t status; + char buf[100]; + double x1, y1, x2, y2; + + if (pdf_pattern->is_shading) { + snprintf(buf, sizeof(buf), + " /Shading\n" + " << /sh%d %d 0 R >>\n", + gradient_mask.id, + gradient_mask.id); + } else { + snprintf(buf, sizeof(buf), + " /Pattern\n" + " << /p%d %d 0 R >>\n", + gradient_mask.id, + gradient_mask.id); + } + + if (pdf_pattern->is_shading) { + cairo_box_t box; + + /* When emitting a shading operator we are in cairo pattern + * coordinates. _cairo_pdf_surface_paint_gradient has set the + * ctm to the pattern matrix (including the convertion from + * pdf to cairo coordinates) */ + _cairo_box_from_rectangle (&box, &pdf_pattern->extents); + _cairo_box_to_doubles (&box, &x1, &y1, &x2, &y2); + _cairo_matrix_transform_bounding_box (&pdf_pattern->pattern->matrix, &x1, &y1, &x2, &y2, NULL); + } else { + cairo_box_double_t box; + + /* When emitting a shading pattern we are in pdf page + * coordinates. The color and alpha shading patterns painted + * in the XObject below contain the cairo pattern to pdf page + * matrix in the /Matrix entry of the pattern. */ + _get_bbox_from_extents (pdf_pattern->height, &pdf_pattern->extents, &box); + x1 = box.p1.x; + y1 = box.p1.y; + x2 = box.p2.x; + y2 = box.p2.y; + } + status = _cairo_pdf_surface_open_stream (surface, + NULL, + surface->compress_content, + " /Type /XObject\n" + " /Subtype /Form\n" + " /FormType 1\n" + " /BBox [ %f %f %f %f ]\n" + " /Resources\n" + " << /ExtGState\n" + " << /a0 << /ca 1 /CA 1 >>" + " >>\n" + "%s" + " >>\n" + " /Group\n" + " << /Type /Group\n" + " /S /Transparency\n" + " /I true\n" + " /CS /DeviceGray\n" + " >>\n", + x1,y1,x2,y2, + buf); + if (unlikely (status)) + return status; + + if (pdf_pattern->is_shading) { + _cairo_output_stream_printf (surface->output, + "/a0 gs /sh%d sh\n", + gradient_mask.id); + } else { + _cairo_output_stream_printf (surface->output, + "q\n" + "/a0 gs\n" + "/Pattern cs /p%d scn\n" + "0 0 %f %f re\n" + "f\n" + "Q\n", + gradient_mask.id, + surface->width, + surface->height); + } + + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) + return status; + + smask_resource = _cairo_pdf_surface_new_object (surface); + if (smask_resource.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Mask\n" + " /S /Luminosity\n" + " /G %d 0 R\n" + ">>\n" + "endobj\n", + smask_resource.id, + surface->pdf_stream.self.id); + + /* Create GState which uses the transparency group as an SMask. */ + _cairo_pdf_surface_update_object (surface, gstate_resource); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /ExtGState\n" + " /SMask %d 0 R\n" + " /ca 1\n" + " /CA 1\n" + " /AIS false\n" + ">>\n" + "endobj\n", + gstate_resource.id, + smask_resource.id); + + return _cairo_output_stream_get_status (surface->output); +} + +static void +_cairo_pdf_surface_output_gradient (cairo_pdf_surface_t *surface, + const cairo_pdf_pattern_t *pdf_pattern, + cairo_pdf_resource_t pattern_resource, + const cairo_matrix_t *pat_to_pdf, + const cairo_circle_double_t*start, + const cairo_circle_double_t*end, + const double *domain, + const char *colorspace, + cairo_pdf_resource_t color_function) +{ + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n", + pattern_resource.id); + + if (!pdf_pattern->is_shading) { + _cairo_output_stream_printf (surface->output, + "<< /Type /Pattern\n" + " /PatternType 2\n" + " /Matrix [ "); + _cairo_output_stream_print_matrix (surface->output, pat_to_pdf); + _cairo_output_stream_printf (surface->output, + " ]\n" + " /Shading\n"); + } + + if (pdf_pattern->pattern->type == CAIRO_PATTERN_TYPE_LINEAR) { + _cairo_output_stream_printf (surface->output, + " << /ShadingType 2\n" + " /ColorSpace %s\n" + " /Coords [ %f %f %f %f ]\n", + colorspace, + start->center.x, start->center.y, + end->center.x, end->center.y); + } else { + _cairo_output_stream_printf (surface->output, + " << /ShadingType 3\n" + " /ColorSpace %s\n" + " /Coords [ %f %f %f %f %f %f ]\n", + colorspace, + start->center.x, start->center.y, + MAX (start->radius, 0), + end->center.x, end->center.y, + MAX (end->radius, 0)); + } + + _cairo_output_stream_printf (surface->output, + " /Domain [ %f %f ]\n", + domain[0], domain[1]); + + if (pdf_pattern->pattern->extend != CAIRO_EXTEND_NONE) { + _cairo_output_stream_printf (surface->output, + " /Extend [ true true ]\n"); + } else { + _cairo_output_stream_printf (surface->output, + " /Extend [ false false ]\n"); + } + + _cairo_output_stream_printf (surface->output, + " /Function %d 0 R\n" + " >>\n", + color_function.id); + + if (!pdf_pattern->is_shading) { + _cairo_output_stream_printf (surface->output, + ">>\n"); + } + + _cairo_output_stream_printf (surface->output, + "endobj\n"); +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_gradient (cairo_pdf_surface_t *surface, + cairo_pdf_pattern_t *pdf_pattern) +{ + cairo_gradient_pattern_t *pattern = (cairo_gradient_pattern_t *) pdf_pattern->pattern; + cairo_pdf_resource_t color_function, alpha_function; + cairo_matrix_t pat_to_pdf; + cairo_circle_double_t start, end; + double domain[2]; + cairo_int_status_t status; + + assert (pattern->n_stops != 0); + + status = _cairo_pdf_surface_emit_pattern_stops (surface, + pattern, + &color_function, + &alpha_function); + if (unlikely (status)) + return status; + + pat_to_pdf = pattern->base.matrix; + status = cairo_matrix_invert (&pat_to_pdf); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf); + + if (pattern->base.extend == CAIRO_EXTEND_REPEAT || + pattern->base.extend == CAIRO_EXTEND_REFLECT) + { + double bounds_x1, bounds_x2, bounds_y1, bounds_y2; + double x_scale, y_scale, tolerance; + + /* TODO: use tighter extents */ + bounds_x1 = 0; + bounds_y1 = 0; + bounds_x2 = surface->width; + bounds_y2 = surface->height; + _cairo_matrix_transform_bounding_box (&pattern->base.matrix, + &bounds_x1, &bounds_y1, + &bounds_x2, &bounds_y2, + NULL); + + x_scale = surface->base.x_resolution / surface->base.x_fallback_resolution; + y_scale = surface->base.y_resolution / surface->base.y_fallback_resolution; + + tolerance = fabs (_cairo_matrix_compute_determinant (&pattern->base.matrix)); + tolerance /= _cairo_matrix_transformed_circle_major_axis (&pattern->base.matrix, 1); + tolerance *= MIN (x_scale, y_scale); + + _cairo_gradient_pattern_box_to_parameter (pattern, + bounds_x1, bounds_y1, + bounds_x2, bounds_y2, + tolerance, domain); + } else if (pattern->stops[0].offset == pattern->stops[pattern->n_stops - 1].offset) { + /* + * If the first and the last stop offset are the same, then + * the color function is a step function. + * _cairo_ps_surface_emit_pattern_stops emits it as a stitched + * function no matter how many stops the pattern has. The + * domain of the stitched function will be [0 1] in this case. + * + * This is done to avoid emitting degenerate gradients for + * EXTEND_PAD patterns having a step color function. + */ + domain[0] = 0.0; + domain[1] = 1.0; + + assert (pattern->base.extend == CAIRO_EXTEND_PAD); + } else { + domain[0] = pattern->stops[0].offset; + domain[1] = pattern->stops[pattern->n_stops - 1].offset; + } + + /* PDF requires the first and last stop to be the same as the + * extreme coordinates. For repeating patterns this moves the + * extreme coordinates out to the begin/end of the repeating + * function. For non repeating patterns this may move the extreme + * coordinates in if there are not stops at offset 0 and 1. */ + _cairo_gradient_pattern_interpolate (pattern, domain[0], &start); + _cairo_gradient_pattern_interpolate (pattern, domain[1], &end); + + if (pattern->base.extend == CAIRO_EXTEND_REPEAT || + pattern->base.extend == CAIRO_EXTEND_REFLECT) + { + int repeat_begin, repeat_end; + + repeat_begin = floor (domain[0]); + repeat_end = ceil (domain[1]); + + status = _cairo_pdf_surface_emit_repeating_function (surface, + pattern, + &color_function, + repeat_begin, + repeat_end); + if (unlikely (status)) + return status; + + if (alpha_function.id != 0) { + status = _cairo_pdf_surface_emit_repeating_function (surface, + pattern, + &alpha_function, + repeat_begin, + repeat_end); + if (unlikely (status)) + return status; + } + } else if (pattern->n_stops <= 2) { + /* For EXTEND_NONE and EXTEND_PAD if there are only two stops a + * Type 2 function is used by itself without a stitching + * function. Type 2 functions always have the domain [0 1] */ + domain[0] = 0.0; + domain[1] = 1.0; + } + + _cairo_pdf_surface_update_object (surface, pdf_pattern->pattern_res); + _cairo_pdf_surface_output_gradient (surface, pdf_pattern, + pdf_pattern->pattern_res, + &pat_to_pdf, &start, &end, domain, + "/DeviceRGB", color_function); + + if (alpha_function.id != 0) { + cairo_pdf_resource_t mask_resource; + + assert (pdf_pattern->gstate_res.id != 0); + + /* Create pattern for SMask. */ + mask_resource = _cairo_pdf_surface_new_object (surface); + if (mask_resource.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_pdf_surface_output_gradient (surface, pdf_pattern, + mask_resource, + &pat_to_pdf, &start, &end, domain, + "/DeviceGray", alpha_function); + + status = cairo_pdf_surface_emit_transparency_group (surface, + pdf_pattern, + pdf_pattern->gstate_res, + mask_resource); + if (unlikely (status)) + return status; + } + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_mesh_pattern (cairo_pdf_surface_t *surface, + cairo_pdf_pattern_t *pdf_pattern) +{ + cairo_matrix_t pat_to_pdf; + cairo_int_status_t status; + cairo_pattern_t *pattern = pdf_pattern->pattern; + cairo_pdf_shading_t shading; + int i; + cairo_pdf_resource_t res; + + pat_to_pdf = pattern->matrix; + status = cairo_matrix_invert (&pat_to_pdf); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + + cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf); + + status = _cairo_pdf_shading_init_color (&shading, (cairo_mesh_pattern_t *) pattern); + if (unlikely (status)) + return status; + + res = _cairo_pdf_surface_new_object (surface); + if (unlikely (res.id == 0)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /ShadingType %d\n" + " /ColorSpace /DeviceRGB\n" + " /BitsPerCoordinate %d\n" + " /BitsPerComponent %d\n" + " /BitsPerFlag %d\n" + " /Decode [", + res.id, + shading.shading_type, + shading.bits_per_coordinate, + shading.bits_per_component, + shading.bits_per_flag); + + for (i = 0; i < shading.decode_array_length; i++) + _cairo_output_stream_printf (surface->output, "%f ", shading.decode_array[i]); + + _cairo_output_stream_printf (surface->output, + "]\n" + " /Length %ld\n" + ">>\n" + "stream\n", + shading.data_length); + + _cairo_output_stream_write (surface->output, shading.data, shading.data_length); + + _cairo_output_stream_printf (surface->output, + "\nendstream\n" + "endobj\n"); + + _cairo_pdf_shading_fini (&shading); + + _cairo_pdf_surface_update_object (surface, pdf_pattern->pattern_res); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Pattern\n" + " /PatternType 2\n" + " /Matrix [ ", + pdf_pattern->pattern_res.id); + _cairo_output_stream_print_matrix (surface->output, &pat_to_pdf); + _cairo_output_stream_printf (surface->output, + " ]\n" + " /Shading %d 0 R\n" + ">>\n" + "endobj\n", + res.id); + + if (pdf_pattern->gstate_res.id != 0) { + cairo_pdf_resource_t mask_resource; + + /* Create pattern for SMask. */ + res = _cairo_pdf_surface_new_object (surface); + if (unlikely (res.id == 0)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_pdf_shading_init_alpha (&shading, (cairo_mesh_pattern_t *) pattern); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /ShadingType %d\n" + " /ColorSpace /DeviceGray\n" + " /BitsPerCoordinate %d\n" + " /BitsPerComponent %d\n" + " /BitsPerFlag %d\n" + " /Decode [", + res.id, + shading.shading_type, + shading.bits_per_coordinate, + shading.bits_per_component, + shading.bits_per_flag); + + for (i = 0; i < shading.decode_array_length; i++) + _cairo_output_stream_printf (surface->output, "%f ", shading.decode_array[i]); + + _cairo_output_stream_printf (surface->output, + "]\n" + " /Length %ld\n" + ">>\n" + "stream\n", + shading.data_length); + + _cairo_output_stream_write (surface->output, shading.data, shading.data_length); + + _cairo_output_stream_printf (surface->output, + "\nendstream\n" + "endobj\n"); + _cairo_pdf_shading_fini (&shading); + + mask_resource = _cairo_pdf_surface_new_object (surface); + if (unlikely (mask_resource.id == 0)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Pattern\n" + " /PatternType 2\n" + " /Matrix [ ", + mask_resource.id); + _cairo_output_stream_print_matrix (surface->output, &pat_to_pdf); + _cairo_output_stream_printf (surface->output, + " ]\n" + " /Shading %d 0 R\n" + ">>\n" + "endobj\n", + res.id); + + status = cairo_pdf_surface_emit_transparency_group (surface, + pdf_pattern, + pdf_pattern->gstate_res, + mask_resource); + if (unlikely (status)) + return status; + } + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_pattern (cairo_pdf_surface_t *surface, cairo_pdf_pattern_t *pdf_pattern) +{ + double old_width, old_height; + cairo_int_status_t status; + + old_width = surface->width; + old_height = surface->height; + _cairo_pdf_surface_set_size_internal (surface, + pdf_pattern->width, + pdf_pattern->height); + + switch (pdf_pattern->pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + ASSERT_NOT_REACHED; + status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + break; + + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + status = _cairo_pdf_surface_emit_surface_pattern (surface, pdf_pattern); + break; + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + status = _cairo_pdf_surface_emit_gradient (surface, pdf_pattern); + break; + + case CAIRO_PATTERN_TYPE_MESH: + status = _cairo_pdf_surface_emit_mesh_pattern (surface, pdf_pattern); + break; + + default: + ASSERT_NOT_REACHED; + status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); + break; + } + + _cairo_pdf_surface_set_size_internal (surface, + old_width, + old_height); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_paint_surface_pattern (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_rectangle_int_t *extents, + cairo_pdf_resource_t *smask_res, + cairo_bool_t stencil_mask) +{ + cairo_pdf_resource_t surface_res; + int width, height; + cairo_matrix_t cairo_p2d, pdf_p2d; + cairo_int_status_t status; + int alpha; + cairo_rectangle_int_t extents2; + double x_offset; + double y_offset; + + if (source->extend == CAIRO_EXTEND_PAD && + !(source->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *)source)->surface->type == CAIRO_SURFACE_TYPE_RECORDING)) + { + status = _cairo_pdf_surface_add_padded_image_surface (surface, + source, + extents, + &surface_res, + &width, + &height, + &x_offset, + &y_offset); + } else { + status = _cairo_pdf_surface_add_source_surface (surface, + NULL, + source, + op, + source->filter, + stencil_mask, + FALSE, + extents, + smask_res, + &surface_res, + &width, + &height, + &x_offset, + &y_offset, + &extents2); + } + if (unlikely (status)) + return status; + + cairo_p2d = source->matrix; + status = cairo_matrix_invert (&cairo_p2d); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + + pdf_p2d = surface->cairo_to_pdf; + cairo_matrix_multiply (&pdf_p2d, &cairo_p2d, &pdf_p2d); + cairo_matrix_translate (&pdf_p2d, x_offset, y_offset); + cairo_matrix_translate (&pdf_p2d, 0.0, height); + cairo_matrix_scale (&pdf_p2d, 1.0, -1.0); + if (!(source->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *)source)->surface->type == CAIRO_SURFACE_TYPE_RECORDING)) + { + cairo_matrix_scale (&pdf_p2d, width, height); + } + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + if (! _cairo_matrix_is_identity (&pdf_p2d)) { + _cairo_output_stream_print_matrix (surface->output, &pdf_p2d); + _cairo_output_stream_printf (surface->output, " cm\n"); + } + + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (unlikely (status)) + return status; + + if (stencil_mask) { + _cairo_output_stream_printf (surface->output, + "/x%d Do\n", + surface_res.id); + } else { + _cairo_output_stream_printf (surface->output, + "/a%d gs /x%d Do\n", + alpha, + surface_res.id); + } + + return _cairo_pdf_surface_add_xobject (surface, surface_res); +} + +static cairo_int_status_t +_cairo_pdf_surface_paint_gradient (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_rectangle_int_t *extents) +{ + cairo_pdf_resource_t shading_res, gstate_res; + cairo_matrix_t pat_to_pdf; + cairo_int_status_t status; + int alpha; + + status = _cairo_pdf_surface_add_pdf_shading (surface, source, + op, extents, + &shading_res, &gstate_res); + if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO)) + return CAIRO_INT_STATUS_SUCCESS; + if (unlikely (status)) + return status; + + pat_to_pdf = source->matrix; + status = cairo_matrix_invert (&pat_to_pdf); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + cairo_matrix_multiply (&pat_to_pdf, &pat_to_pdf, &surface->cairo_to_pdf); + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + if (! _cairo_matrix_is_identity (&pat_to_pdf)) { + _cairo_output_stream_print_matrix (surface->output, &pat_to_pdf); + _cairo_output_stream_printf (surface->output, " cm\n"); + } + + status = _cairo_pdf_surface_add_shading (surface, shading_res); + if (unlikely (status)) + return status; + + if (gstate_res.id != 0) { + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "/s%d gs /sh%d sh\n", + gstate_res.id, + shading_res.id); + } else { + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "/a%d gs /sh%d sh\n", + alpha, + shading_res.id); + } + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_paint_pattern (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_rectangle_int_t *extents, + cairo_bool_t mask) +{ + switch (source->type) { + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _cairo_pdf_surface_paint_surface_pattern (surface, + op, + source, + extents, + NULL, + mask); + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + return _cairo_pdf_surface_paint_gradient (surface, + op, + source, + extents); + + case CAIRO_PATTERN_TYPE_SOLID: + default: + ASSERT_NOT_REACHED; + return CAIRO_STATUS_SUCCESS; + } +} + +static cairo_bool_t +_can_paint_pattern (const cairo_pattern_t *pattern) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return FALSE; + + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return (pattern->extend == CAIRO_EXTEND_NONE || + pattern->extend == CAIRO_EXTEND_PAD); + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + return TRUE; + + case CAIRO_PATTERN_TYPE_MESH: + return FALSE; + + default: + ASSERT_NOT_REACHED; + return FALSE; + } +} + +static cairo_int_status_t +_cairo_pdf_surface_select_operator (cairo_pdf_surface_t *surface, + cairo_operator_t op) +{ + cairo_int_status_t status; + + if (op == surface->current_operator) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "/b%d gs\n", op); + surface->current_operator = op; + _cairo_pdf_surface_add_operator (surface, op); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_pdf_resource_t pattern_res, + cairo_bool_t is_stroke) +{ + cairo_int_status_t status; + int alpha; + const cairo_color_t *solid_color = NULL; + + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { + const cairo_solid_pattern_t *solid = (const cairo_solid_pattern_t *) pattern; + + solid_color = &solid->color; + } + + if (solid_color != NULL) { + if (surface->current_pattern_is_solid_color == FALSE || + surface->current_color_red != solid_color->red || + surface->current_color_green != solid_color->green || + surface->current_color_blue != solid_color->blue || + surface->current_color_is_stroke != is_stroke) + { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "%f %f %f ", + solid_color->red, + solid_color->green, + solid_color->blue); + + if (is_stroke) + _cairo_output_stream_printf (surface->output, "RG "); + else + _cairo_output_stream_printf (surface->output, "rg "); + + surface->current_color_red = solid_color->red; + surface->current_color_green = solid_color->green; + surface->current_color_blue = solid_color->blue; + surface->current_color_is_stroke = is_stroke; + } + + if (surface->current_pattern_is_solid_color == FALSE || + surface->current_color_alpha != solid_color->alpha) + { + status = _cairo_pdf_surface_add_alpha (surface, solid_color->alpha, &alpha); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "/a%d gs\n", + alpha); + surface->current_color_alpha = solid_color->alpha; + } + + surface->current_pattern_is_solid_color = TRUE; + } else { + status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_add_pattern (surface, pattern_res); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + /* fill-stroke calls select_pattern twice. Don't save if the + * gstate is already saved. */ + if (!surface->select_pattern_gstate_saved) + _cairo_output_stream_printf (surface->output, "q "); + + if (is_stroke) { + _cairo_output_stream_printf (surface->output, + "/Pattern CS /p%d SCN ", + pattern_res.id); + } else { + _cairo_output_stream_printf (surface->output, + "/Pattern cs /p%d scn ", + pattern_res.id); + } + _cairo_output_stream_printf (surface->output, + "/a%d gs\n", + alpha); + surface->select_pattern_gstate_saved = TRUE; + surface->current_pattern_is_solid_color = FALSE; + } + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +_cairo_pdf_surface_unselect_pattern (cairo_pdf_surface_t *surface) +{ + cairo_int_status_t status; + + if (surface->select_pattern_gstate_saved) { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "Q\n"); + _cairo_pdf_operators_reset (&surface->pdf_operators); + surface->current_pattern_is_solid_color = FALSE; + } + surface->select_pattern_gstate_saved = FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_show_page (void *abstract_surface) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + status = _cairo_pdf_surface_close_content_stream (surface); + if (unlikely (status)) + return status; + + _cairo_surface_clipper_reset (&surface->clipper); + + status = _cairo_pdf_surface_write_page (surface); + if (unlikely (status)) + return status; + + _cairo_pdf_surface_clear (surface); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_pdf_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_pdf_surface_t *surface = abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + + /* XXX: The conversion to integers here is pretty bogus, (not to + * mention the arbitrary limitation of width to a short(!). We + * may need to come up with a better interface for get_size. + */ + rectangle->width = ceil (surface->width); + rectangle->height = ceil (surface->height); + + return TRUE; +} + +static void +_cairo_pdf_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + _cairo_font_options_init_default (options); + + cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); + _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); +} + +static cairo_pdf_resource_t +_cairo_pdf_surface_write_info (cairo_pdf_surface_t *surface) +{ + cairo_pdf_resource_t info; + + info = _cairo_pdf_surface_new_object (surface); + if (info.id == 0) + return info; + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Creator (cairo %s (http://cairographics.org))\n" + " /Producer (cairo %s (http://cairographics.org))\n" + ">>\n" + "endobj\n", + info.id, + cairo_version_string (), + cairo_version_string ()); + + return info; +} + +static void +_cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface) +{ + cairo_pdf_resource_t page; + int num_pages, i; + + _cairo_pdf_surface_update_object (surface, surface->pages_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Pages\n" + " /Kids [ ", + surface->pages_resource.id); + + num_pages = _cairo_array_num_elements (&surface->pages); + for (i = 0; i < num_pages; i++) { + _cairo_array_copy_element (&surface->pages, i, &page); + _cairo_output_stream_printf (surface->output, "%d 0 R ", page.id); + } + + _cairo_output_stream_printf (surface->output, "]\n"); + _cairo_output_stream_printf (surface->output, " /Count %d\n", num_pages); + + + /* TODO: Figure out which other defaults to be inherited by /Page + * objects. */ + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); +} + +static cairo_int_status_t +_utf8_to_pdf_string (const char *utf8, char **str_out) +{ + int i; + int len; + cairo_bool_t ascii; + char *str; + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + + ascii = TRUE; + len = strlen (utf8); + for (i = 0; i < len; i++) { + unsigned c = utf8[i]; + if (c < 32 || c > 126 || c == '(' || c == ')' || c == '\\') { + ascii = FALSE; + break; + } + } + + if (ascii) { + str = malloc (len + 3); + if (str == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + str[0] = '('; + for (i = 0; i < len; i++) + str[i+1] = utf8[i]; + str[i+1] = ')'; + str[i+2] = 0; + } else { + uint16_t *utf16 = NULL; + int utf16_len = 0; + + status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len); + if (unlikely (status)) + return status; + + str = malloc (utf16_len*4 + 7); + if (str == NULL) { + free (utf16); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + strcpy (str, ""); + free (utf16); + } + *str_out = str; + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_unicode_for_glyph (cairo_pdf_surface_t *surface, + const char *utf8) +{ + uint16_t *utf16 = NULL; + int utf16_len = 0; + cairo_int_status_t status; + int i; + + if (utf8 && *utf8) { + status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len); + if (unlikely (status)) + return status; + } + + _cairo_output_stream_printf (surface->output, "<"); + if (utf16 == NULL || utf16_len == 0) { + /* According to the "ToUnicode Mapping File Tutorial" + * http://www.adobe.com/devnet/acrobat/pdfs/5411.ToUnicode.pdf + * + * Glyphs that do not map to a Unicode code point must be + * mapped to 0xfffd "REPLACEMENT CHARACTER". + */ + _cairo_output_stream_printf (surface->output, + "fffd"); + } else { + for (i = 0; i < utf16_len; i++) + _cairo_output_stream_printf (surface->output, + "%04x", (int) (utf16[i])); + } + _cairo_output_stream_printf (surface->output, ">"); + + free (utf16); + + return CAIRO_STATUS_SUCCESS; +} + +/* Bob Jenkins hash + * + * Public domain code from: + * http://burtleburtle.net/bob/hash/doobs.html + */ + +#define HASH_MIX(a,b,c) \ +{ \ + a -= b; a -= c; a ^= (c>>13); \ + b -= c; b -= a; b ^= (a<<8); \ + c -= a; c -= b; c ^= (b>>13); \ + a -= b; a -= c; a ^= (c>>12); \ + b -= c; b -= a; b ^= (a<<16); \ + c -= a; c -= b; c ^= (b>>5); \ + a -= b; a -= c; a ^= (c>>3); \ + b -= c; b -= a; b ^= (a<<10); \ + c -= a; c -= b; c ^= (b>>15); \ +} + +static uint32_t +_hash_data (const unsigned char *data, int length, uint32_t initval) +{ + uint32_t a, b, c, len; + + len = length; + a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */ + c = initval; /* the previous hash value */ + + while (len >= 12) { + a += (data[0] + ((uint32_t)data[1]<<8) + ((uint32_t)data[2]<<16) + ((uint32_t)data[3]<<24)); + b += (data[4] + ((uint32_t)data[5]<<8) + ((uint32_t)data[6]<<16) + ((uint32_t)data[7]<<24)); + c += (data[8] + ((uint32_t)data[9]<<8) + ((uint32_t)data[10]<<16)+ ((uint32_t)data[11]<<24)); + HASH_MIX (a,b,c); + data += 12; + len -= 12; + } + + c += length; + switch(len) { + case 11: c+= ((uint32_t) data[10] << 24); + case 10: c+= ((uint32_t) data[9] << 16); + case 9 : c+= ((uint32_t) data[8] << 8); + case 8 : b+= ((uint32_t) data[7] << 24); + case 7 : b+= ((uint32_t) data[6] << 16); + case 6 : b+= ((uint32_t) data[5] << 8); + case 5 : b+= data[4]; + case 4 : a+= ((uint32_t) data[3] << 24); + case 3 : a+= ((uint32_t) data[2] << 16); + case 2 : a+= ((uint32_t) data[1] << 8); + case 1 : a+= data[0]; + } + HASH_MIX (a,b,c); + + return c; +} + +static void +_create_font_subset_tag (cairo_scaled_font_subset_t *font_subset, + const char *font_name, + char *tag) +{ + uint32_t hash; + int i; + long numerator; + ldiv_t d; + + hash = _hash_data ((unsigned char *) font_name, strlen(font_name), 0); + hash = _hash_data ((unsigned char *) (font_subset->glyphs), + font_subset->num_glyphs * sizeof(unsigned long), hash); + + numerator = abs (hash); + for (i = 0; i < 6; i++) { + d = ldiv (numerator, 26); + numerator = d.quot; + tag[i] = 'A' + d.rem; + } + tag[i] = 0; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset, + cairo_pdf_resource_t *stream) +{ + unsigned int i, num_bfchar; + cairo_int_status_t status; + + stream->id = 0; + + status = _cairo_pdf_surface_open_stream (surface, + NULL, + surface->compress_content, + NULL); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "/CIDInit /ProcSet findresource begin\n" + "12 dict begin\n" + "begincmap\n" + "/CIDSystemInfo\n" + "<< /Registry (Adobe)\n" + " /Ordering (UCS)\n" + " /Supplement 0\n" + ">> def\n" + "/CMapName /Adobe-Identity-UCS def\n" + "/CMapType 2 def\n" + "1 begincodespacerange\n"); + + if (font_subset->is_composite && !font_subset->is_latin) { + _cairo_output_stream_printf (surface->output, + "<0000> \n"); + } else { + _cairo_output_stream_printf (surface->output, + "<00> \n"); + } + + _cairo_output_stream_printf (surface->output, + "endcodespacerange\n"); + + if (font_subset->is_scaled) { + /* Type 3 fonts include glyph 0 in the subset */ + num_bfchar = font_subset->num_glyphs; + + /* The CMap specification has a limit of 100 characters per beginbfchar operator */ + _cairo_output_stream_printf (surface->output, + "%d beginbfchar\n", + num_bfchar > 100 ? 100 : num_bfchar); + + for (i = 0; i < num_bfchar; i++) { + if (i != 0 && i % 100 == 0) { + _cairo_output_stream_printf (surface->output, + "endbfchar\n" + "%d beginbfchar\n", + num_bfchar - i > 100 ? 100 : num_bfchar - i); + } + _cairo_output_stream_printf (surface->output, "<%02x> ", i); + status = _cairo_pdf_surface_emit_unicode_for_glyph (surface, + font_subset->utf8[i]); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "\n"); + } + } else { + /* Other fonts reserve glyph 0 for .notdef. Omit glyph 0 from the /ToUnicode map */ + num_bfchar = font_subset->num_glyphs - 1; + + /* The CMap specification has a limit of 100 characters per beginbfchar operator */ + _cairo_output_stream_printf (surface->output, + "%d beginbfchar\n", + num_bfchar > 100 ? 100 : num_bfchar); + + for (i = 0; i < num_bfchar; i++) { + if (i != 0 && i % 100 == 0) { + _cairo_output_stream_printf (surface->output, + "endbfchar\n" + "%d beginbfchar\n", + num_bfchar - i > 100 ? 100 : num_bfchar - i); + } + if (font_subset->is_latin) + _cairo_output_stream_printf (surface->output, "<%02x> ", font_subset->to_latin_char[i + 1]); + else if (font_subset->is_composite) + _cairo_output_stream_printf (surface->output, "<%04x> ", i + 1); + else + _cairo_output_stream_printf (surface->output, "<%02x> ", i + 1); + + status = _cairo_pdf_surface_emit_unicode_for_glyph (surface, + font_subset->utf8[i + 1]); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "\n"); + } + } + + _cairo_output_stream_printf (surface->output, + "endbfchar\n"); + + _cairo_output_stream_printf (surface->output, + "endcmap\n" + "CMapName currentdict /CMap defineresource pop\n" + "end\n" + "end\n"); + + *stream = surface->pdf_stream.self; + return _cairo_pdf_surface_close_stream (surface); +} + +#define PDF_UNITS_PER_EM 1000 + +static cairo_int_status_t +_cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset, + cairo_cff_subset_t *subset) +{ + cairo_pdf_resource_t stream, descriptor, cidfont_dict; + cairo_pdf_resource_t subset_resource, to_unicode_stream; + cairo_pdf_font_t font; + unsigned int i, last_glyph; + cairo_int_status_t status; + char tag[10]; + + _create_font_subset_tag (font_subset, subset->ps_name, tag); + + subset_resource = _cairo_pdf_surface_get_font_resource (surface, + font_subset->font_id, + font_subset->subset_id); + if (subset_resource.id == 0) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_pdf_surface_open_stream (surface, + NULL, + TRUE, + font_subset->is_latin ? + " /Subtype /Type1C\n" : + " /Subtype /CIDFontType0C\n"); + if (unlikely (status)) + return status; + + stream = surface->pdf_stream.self; + _cairo_output_stream_write (surface->output, + subset->data, subset->data_length); + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_to_unicode_stream (surface, + font_subset, + &to_unicode_stream); + if (_cairo_int_status_is_error (status)) + return status; + + descriptor = _cairo_pdf_surface_new_object (surface); + if (descriptor.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /FontDescriptor\n" + " /FontName /%s+%s\n", + descriptor.id, + tag, + subset->ps_name); + + if (subset->family_name_utf8) { + char *pdf_str; + + status = _utf8_to_pdf_string (subset->family_name_utf8, &pdf_str); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + " /FontFamily %s\n", + pdf_str); + free (pdf_str); + } + + _cairo_output_stream_printf (surface->output, + " /Flags 4\n" + " /FontBBox [ %ld %ld %ld %ld ]\n" + " /ItalicAngle 0\n" + " /Ascent %ld\n" + " /Descent %ld\n" + " /CapHeight %ld\n" + " /StemV 80\n" + " /StemH 80\n" + " /FontFile3 %u 0 R\n" + ">>\n" + "endobj\n", + (long)(subset->x_min*PDF_UNITS_PER_EM), + (long)(subset->y_min*PDF_UNITS_PER_EM), + (long)(subset->x_max*PDF_UNITS_PER_EM), + (long)(subset->y_max*PDF_UNITS_PER_EM), + (long)(subset->ascent*PDF_UNITS_PER_EM), + (long)(subset->descent*PDF_UNITS_PER_EM), + (long)(subset->y_max*PDF_UNITS_PER_EM), + stream.id); + + if (font_subset->is_latin) { + /* find last glyph used */ + for (i = 255; i >= 32; i--) + if (font_subset->latin_to_subset_glyph_index[i] > 0) + break; + + last_glyph = i; + _cairo_pdf_surface_update_object (surface, subset_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /Type1\n" + " /BaseFont /%s+%s\n" + " /FirstChar 32\n" + " /LastChar %d\n" + " /FontDescriptor %d 0 R\n" + " /Encoding /WinAnsiEncoding\n" + " /Widths [", + subset_resource.id, + tag, + subset->ps_name, + last_glyph, + descriptor.id); + + for (i = 32; i < last_glyph + 1; i++) { + int glyph = font_subset->latin_to_subset_glyph_index[i]; + if (glyph > 0) { + _cairo_output_stream_printf (surface->output, + " %ld", + (long)(subset->widths[glyph]*PDF_UNITS_PER_EM)); + } else { + _cairo_output_stream_printf (surface->output, " 0"); + } + } + + _cairo_output_stream_printf (surface->output, + " ]\n"); + + if (to_unicode_stream.id != 0) + _cairo_output_stream_printf (surface->output, + " /ToUnicode %d 0 R\n", + to_unicode_stream.id); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + } else { + cidfont_dict = _cairo_pdf_surface_new_object (surface); + if (cidfont_dict.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /CIDFontType0\n" + " /BaseFont /%s+%s\n" + " /CIDSystemInfo\n" + " << /Registry (Adobe)\n" + " /Ordering (Identity)\n" + " /Supplement 0\n" + " >>\n" + " /FontDescriptor %d 0 R\n" + " /W [0 [", + cidfont_dict.id, + tag, + subset->ps_name, + descriptor.id); + + for (i = 0; i < font_subset->num_glyphs; i++) + _cairo_output_stream_printf (surface->output, + " %ld", + (long)(subset->widths[i]*PDF_UNITS_PER_EM)); + + _cairo_output_stream_printf (surface->output, + " ]]\n" + ">>\n" + "endobj\n"); + + _cairo_pdf_surface_update_object (surface, subset_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /Type0\n" + " /BaseFont /%s+%s\n" + " /Encoding /Identity-H\n" + " /DescendantFonts [ %d 0 R]\n", + subset_resource.id, + tag, + subset->ps_name, + cidfont_dict.id); + + if (to_unicode_stream.id != 0) + _cairo_output_stream_printf (surface->output, + " /ToUnicode %d 0 R\n", + to_unicode_stream.id); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + } + + font.font_id = font_subset->font_id; + font.subset_id = font_subset->subset_id; + font.subset_resource = subset_resource; + status = _cairo_array_append (&surface->fonts, &font); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_cff_font_subset (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_int_status_t status; + cairo_cff_subset_t subset; + char name[64]; + + snprintf (name, sizeof name, "CairoFont-%d-%d", + font_subset->font_id, font_subset->subset_id); + status = _cairo_cff_subset_init (&subset, name, font_subset); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset); + + _cairo_cff_subset_fini (&subset); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_cff_fallback_font (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_int_status_t status; + cairo_cff_subset_t subset; + char name[64]; + + /* CFF fallback subsetting does not work with 8-bit glyphs unless + * they are a latin subset */ + if (!font_subset->is_composite && !font_subset->is_latin) + return CAIRO_INT_STATUS_UNSUPPORTED; + + snprintf (name, sizeof name, "CairoFont-%d-%d", + font_subset->font_id, font_subset->subset_id); + status = _cairo_cff_fallback_init (&subset, name, font_subset); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_cff_font (surface, font_subset, &subset); + + _cairo_cff_fallback_fini (&subset); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset, + cairo_type1_subset_t *subset) +{ + cairo_pdf_resource_t stream, descriptor, subset_resource, to_unicode_stream; + cairo_pdf_font_t font; + cairo_int_status_t status; + unsigned long length; + unsigned int i, last_glyph; + char tag[10]; + + _create_font_subset_tag (font_subset, subset->base_font, tag); + + subset_resource = _cairo_pdf_surface_get_font_resource (surface, + font_subset->font_id, + font_subset->subset_id); + if (subset_resource.id == 0) + return CAIRO_STATUS_SUCCESS; + + length = subset->header_length + subset->data_length + subset->trailer_length; + status = _cairo_pdf_surface_open_stream (surface, + NULL, + TRUE, + " /Length1 %lu\n" + " /Length2 %lu\n" + " /Length3 %lu\n", + subset->header_length, + subset->data_length, + subset->trailer_length); + if (unlikely (status)) + return status; + + stream = surface->pdf_stream.self; + _cairo_output_stream_write (surface->output, subset->data, length); + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_to_unicode_stream (surface, + font_subset, + &to_unicode_stream); + if (_cairo_int_status_is_error (status)) + return status; + + last_glyph = font_subset->num_glyphs - 1; + if (font_subset->is_latin) { + /* find last glyph used */ + for (i = 255; i >= 32; i--) + if (font_subset->latin_to_subset_glyph_index[i] > 0) + break; + + last_glyph = i; + } + + descriptor = _cairo_pdf_surface_new_object (surface); + if (descriptor.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /FontDescriptor\n" + " /FontName /%s+%s\n" + " /Flags 4\n" + " /FontBBox [ %ld %ld %ld %ld ]\n" + " /ItalicAngle 0\n" + " /Ascent %ld\n" + " /Descent %ld\n" + " /CapHeight %ld\n" + " /StemV 80\n" + " /StemH 80\n" + " /FontFile %u 0 R\n" + ">>\n" + "endobj\n", + descriptor.id, + tag, + subset->base_font, + (long)(subset->x_min*PDF_UNITS_PER_EM), + (long)(subset->y_min*PDF_UNITS_PER_EM), + (long)(subset->x_max*PDF_UNITS_PER_EM), + (long)(subset->y_max*PDF_UNITS_PER_EM), + (long)(subset->ascent*PDF_UNITS_PER_EM), + (long)(subset->descent*PDF_UNITS_PER_EM), + (long)(subset->y_max*PDF_UNITS_PER_EM), + stream.id); + + _cairo_pdf_surface_update_object (surface, subset_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /Type1\n" + " /BaseFont /%s+%s\n" + " /FirstChar %d\n" + " /LastChar %d\n" + " /FontDescriptor %d 0 R\n", + subset_resource.id, + tag, + subset->base_font, + font_subset->is_latin ? 32 : 0, + last_glyph, + descriptor.id); + + if (font_subset->is_latin) + _cairo_output_stream_printf (surface->output, " /Encoding /WinAnsiEncoding\n"); + + _cairo_output_stream_printf (surface->output, " /Widths ["); + if (font_subset->is_latin) { + for (i = 32; i < last_glyph + 1; i++) { + int glyph = font_subset->latin_to_subset_glyph_index[i]; + if (glyph > 0) { + _cairo_output_stream_printf (surface->output, + " %ld", + (long)(subset->widths[glyph]*PDF_UNITS_PER_EM)); + } else { + _cairo_output_stream_printf (surface->output, " 0"); + } + } + } else { + for (i = 0; i < font_subset->num_glyphs; i++) + _cairo_output_stream_printf (surface->output, + " %ld", + (long)(subset->widths[i]*PDF_UNITS_PER_EM)); + } + + _cairo_output_stream_printf (surface->output, + " ]\n"); + + if (to_unicode_stream.id != 0) + _cairo_output_stream_printf (surface->output, + " /ToUnicode %d 0 R\n", + to_unicode_stream.id); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + + font.font_id = font_subset->font_id; + font.subset_id = font_subset->subset_id; + font.subset_resource = subset_resource; + return _cairo_array_append (&surface->fonts, &font); +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_type1_font_subset (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_int_status_t status; + cairo_type1_subset_t subset; + char name[64]; + + /* 16-bit glyphs not compatible with Type 1 fonts */ + if (font_subset->is_composite && !font_subset->is_latin) + return CAIRO_INT_STATUS_UNSUPPORTED; + + snprintf (name, sizeof name, "CairoFont-%d-%d", + font_subset->font_id, font_subset->subset_id); + status = _cairo_type1_subset_init (&subset, name, font_subset, FALSE); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset); + + _cairo_type1_subset_fini (&subset); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_type1_fallback_font (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_int_status_t status; + cairo_type1_subset_t subset; + char name[64]; + + /* 16-bit glyphs not compatible with Type 1 fonts */ + if (font_subset->is_composite && !font_subset->is_latin) + return CAIRO_INT_STATUS_UNSUPPORTED; + + snprintf (name, sizeof name, "CairoFont-%d-%d", + font_subset->font_id, font_subset->subset_id); + status = _cairo_type1_fallback_init_binary (&subset, name, font_subset); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_emit_type1_font (surface, font_subset, &subset); + + _cairo_type1_fallback_fini (&subset); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_pdf_resource_t stream, descriptor, cidfont_dict; + cairo_pdf_resource_t subset_resource, to_unicode_stream; + cairo_int_status_t status; + cairo_pdf_font_t font; + cairo_truetype_subset_t subset; + unsigned int i, last_glyph; + char tag[10]; + + subset_resource = _cairo_pdf_surface_get_font_resource (surface, + font_subset->font_id, + font_subset->subset_id); + if (subset_resource.id == 0) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_truetype_subset_init_pdf (&subset, font_subset); + if (unlikely (status)) + return status; + + _create_font_subset_tag (font_subset, subset.ps_name, tag); + + status = _cairo_pdf_surface_open_stream (surface, + NULL, + TRUE, + " /Length1 %lu\n", + subset.data_length); + if (unlikely (status)) { + _cairo_truetype_subset_fini (&subset); + return status; + } + + stream = surface->pdf_stream.self; + _cairo_output_stream_write (surface->output, + subset.data, subset.data_length); + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) { + _cairo_truetype_subset_fini (&subset); + return status; + } + + status = _cairo_pdf_surface_emit_to_unicode_stream (surface, + font_subset, + &to_unicode_stream); + if (_cairo_int_status_is_error (status)) { + _cairo_truetype_subset_fini (&subset); + return status; + } + + descriptor = _cairo_pdf_surface_new_object (surface); + if (descriptor.id == 0) { + _cairo_truetype_subset_fini (&subset); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /FontDescriptor\n" + " /FontName /%s+%s\n", + descriptor.id, + tag, + subset.ps_name); + + if (subset.family_name_utf8) { + char *pdf_str; + + status = _utf8_to_pdf_string (subset.family_name_utf8, &pdf_str); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + " /FontFamily %s\n", + pdf_str); + free (pdf_str); + } + + _cairo_output_stream_printf (surface->output, + " /Flags %d\n" + " /FontBBox [ %ld %ld %ld %ld ]\n" + " /ItalicAngle 0\n" + " /Ascent %ld\n" + " /Descent %ld\n" + " /CapHeight %ld\n" + " /StemV 80\n" + " /StemH 80\n" + " /FontFile2 %u 0 R\n" + ">>\n" + "endobj\n", + font_subset->is_latin ? 32 : 4, + (long)(subset.x_min*PDF_UNITS_PER_EM), + (long)(subset.y_min*PDF_UNITS_PER_EM), + (long)(subset.x_max*PDF_UNITS_PER_EM), + (long)(subset.y_max*PDF_UNITS_PER_EM), + (long)(subset.ascent*PDF_UNITS_PER_EM), + (long)(subset.descent*PDF_UNITS_PER_EM), + (long)(subset.y_max*PDF_UNITS_PER_EM), + stream.id); + + if (font_subset->is_latin) { + /* find last glyph used */ + for (i = 255; i >= 32; i--) + if (font_subset->latin_to_subset_glyph_index[i] > 0) + break; + + last_glyph = i; + _cairo_pdf_surface_update_object (surface, subset_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /TrueType\n" + " /BaseFont /%s+%s\n" + " /FirstChar 32\n" + " /LastChar %d\n" + " /FontDescriptor %d 0 R\n" + " /Encoding /WinAnsiEncoding\n" + " /Widths [", + subset_resource.id, + tag, + subset.ps_name, + last_glyph, + descriptor.id); + + for (i = 32; i < last_glyph + 1; i++) { + int glyph = font_subset->latin_to_subset_glyph_index[i]; + if (glyph > 0) { + _cairo_output_stream_printf (surface->output, + " %ld", + (long)(subset.widths[glyph]*PDF_UNITS_PER_EM)); + } else { + _cairo_output_stream_printf (surface->output, " 0"); + } + } + + _cairo_output_stream_printf (surface->output, + " ]\n"); + + if (to_unicode_stream.id != 0) + _cairo_output_stream_printf (surface->output, + " /ToUnicode %d 0 R\n", + to_unicode_stream.id); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + } else { + cidfont_dict = _cairo_pdf_surface_new_object (surface); + if (cidfont_dict.id == 0) { + _cairo_truetype_subset_fini (&subset); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /CIDFontType2\n" + " /BaseFont /%s+%s\n" + " /CIDSystemInfo\n" + " << /Registry (Adobe)\n" + " /Ordering (Identity)\n" + " /Supplement 0\n" + " >>\n" + " /FontDescriptor %d 0 R\n" + " /W [0 [", + cidfont_dict.id, + tag, + subset.ps_name, + descriptor.id); + + for (i = 0; i < font_subset->num_glyphs; i++) + _cairo_output_stream_printf (surface->output, + " %ld", + (long)(subset.widths[i]*PDF_UNITS_PER_EM)); + + _cairo_output_stream_printf (surface->output, + " ]]\n" + ">>\n" + "endobj\n"); + + _cairo_pdf_surface_update_object (surface, subset_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /Type0\n" + " /BaseFont /%s+%s\n" + " /Encoding /Identity-H\n" + " /DescendantFonts [ %d 0 R]\n", + subset_resource.id, + tag, + subset.ps_name, + cidfont_dict.id); + + if (to_unicode_stream.id != 0) + _cairo_output_stream_printf (surface->output, + " /ToUnicode %d 0 R\n", + to_unicode_stream.id); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + } + + font.font_id = font_subset->font_id; + font.subset_id = font_subset->subset_id; + font.subset_resource = subset_resource; + status = _cairo_array_append (&surface->fonts, &font); + + _cairo_truetype_subset_fini (&subset); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_emit_imagemask (cairo_image_surface_t *image, + cairo_output_stream_t *stream) +{ + uint8_t *byte, output_byte; + int row, col, num_cols; + + /* The only image type supported by Type 3 fonts are 1-bit image + * masks */ + assert (image->format == CAIRO_FORMAT_A1); + + _cairo_output_stream_printf (stream, + "BI\n" + "/IM true\n" + "/W %d\n" + "/H %d\n" + "/BPC 1\n" + "/D [1 0]\n", + image->width, + image->height); + + _cairo_output_stream_printf (stream, + "ID "); + + num_cols = (image->width + 7) / 8; + for (row = 0; row < image->height; row++) { + byte = image->data + row * image->stride; + for (col = 0; col < num_cols; col++) { + output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte); + _cairo_output_stream_write (stream, &output_byte, 1); + byte++; + } + } + + _cairo_output_stream_printf (stream, + "\nEI\n"); + + return _cairo_output_stream_get_status (stream); +} + +static cairo_int_status_t +_cairo_pdf_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_pdf_surface_t *surface = closure; + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + cairo_int_status_t status2; + unsigned int i; + cairo_surface_t *type3_surface; + cairo_output_stream_t *null_stream; + + null_stream = _cairo_null_stream_create (); + type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, + null_stream, + _cairo_pdf_emit_imagemask, + surface->font_subsets, + FALSE); + if (unlikely (type3_surface->status)) { + status2 = _cairo_output_stream_destroy (null_stream); + return type3_surface->status; + } + + _cairo_type3_glyph_surface_set_font_subsets_callback (type3_surface, + _cairo_pdf_surface_add_font, + surface); + + for (i = 0; i < font_subset->num_glyphs; i++) { + status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface, + font_subset->glyphs[i]); + if (unlikely (status)) + break; + } + + cairo_surface_destroy (type3_surface); + status2 = _cairo_output_stream_destroy (null_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + cairo_pdf_resource_t *glyphs, encoding, char_procs, subset_resource, to_unicode_stream; + cairo_pdf_font_t font; + double *widths; + unsigned int i; + cairo_box_t font_bbox = {{0,0},{0,0}}; + cairo_box_t bbox = {{0,0},{0,0}}; + cairo_surface_t *type3_surface; + + if (font_subset->num_glyphs == 0) + return CAIRO_STATUS_SUCCESS; + + subset_resource = _cairo_pdf_surface_get_font_resource (surface, + font_subset->font_id, + font_subset->subset_id); + if (subset_resource.id == 0) + return CAIRO_STATUS_SUCCESS; + + glyphs = _cairo_malloc_ab (font_subset->num_glyphs, sizeof (cairo_pdf_resource_t)); + if (unlikely (glyphs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + widths = _cairo_malloc_ab (font_subset->num_glyphs, sizeof (double)); + if (unlikely (widths == NULL)) { + free (glyphs); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_pdf_group_resources_clear (&surface->resources); + type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, + NULL, + _cairo_pdf_emit_imagemask, + surface->font_subsets, + FALSE); + if (unlikely (type3_surface->status)) { + free (glyphs); + free (widths); + return type3_surface->status; + } + + _cairo_type3_glyph_surface_set_font_subsets_callback (type3_surface, + _cairo_pdf_surface_add_font, + surface); + + for (i = 0; i < font_subset->num_glyphs; i++) { + status = _cairo_pdf_surface_open_stream (surface, + NULL, + surface->compress_content, + NULL); + if (unlikely (status)) + break; + + glyphs[i] = surface->pdf_stream.self; + status = _cairo_type3_glyph_surface_emit_glyph (type3_surface, + surface->output, + font_subset->glyphs[i], + &bbox, + &widths[i]); + if (unlikely (status)) + break; + + status = _cairo_pdf_surface_close_stream (surface); + if (unlikely (status)) + break; + + if (i == 0) { + font_bbox.p1.x = bbox.p1.x; + font_bbox.p1.y = bbox.p1.y; + font_bbox.p2.x = bbox.p2.x; + font_bbox.p2.y = bbox.p2.y; + } else { + if (bbox.p1.x < font_bbox.p1.x) + font_bbox.p1.x = bbox.p1.x; + if (bbox.p1.y < font_bbox.p1.y) + font_bbox.p1.y = bbox.p1.y; + if (bbox.p2.x > font_bbox.p2.x) + font_bbox.p2.x = bbox.p2.x; + if (bbox.p2.y > font_bbox.p2.y) + font_bbox.p2.y = bbox.p2.y; + } + } + cairo_surface_destroy (type3_surface); + if (unlikely (status)) { + free (glyphs); + free (widths); + return status; + } + + encoding = _cairo_pdf_surface_new_object (surface); + if (encoding.id == 0) { + free (glyphs); + free (widths); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Encoding\n" + " /Differences [0", encoding.id); + for (i = 0; i < font_subset->num_glyphs; i++) + _cairo_output_stream_printf (surface->output, + " /%d", i); + _cairo_output_stream_printf (surface->output, + "]\n" + ">>\n" + "endobj\n"); + + char_procs = _cairo_pdf_surface_new_object (surface); + if (char_procs.id == 0) { + free (glyphs); + free (widths); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<<\n", char_procs.id); + for (i = 0; i < font_subset->num_glyphs; i++) + _cairo_output_stream_printf (surface->output, + " /%d %d 0 R\n", + i, glyphs[i].id); + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + + free (glyphs); + + status = _cairo_pdf_surface_emit_to_unicode_stream (surface, + font_subset, + &to_unicode_stream); + if (_cairo_int_status_is_error (status)) { + free (widths); + return status; + } + + _cairo_pdf_surface_update_object (surface, subset_resource); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Font\n" + " /Subtype /Type3\n" + " /FontBBox [%f %f %f %f]\n" + " /FontMatrix [ 1 0 0 1 0 0 ]\n" + " /Encoding %d 0 R\n" + " /CharProcs %d 0 R\n" + " /FirstChar 0\n" + " /LastChar %d\n", + subset_resource.id, + _cairo_fixed_to_double (font_bbox.p1.x), + - _cairo_fixed_to_double (font_bbox.p2.y), + _cairo_fixed_to_double (font_bbox.p2.x), + - _cairo_fixed_to_double (font_bbox.p1.y), + encoding.id, + char_procs.id, + font_subset->num_glyphs - 1); + + _cairo_output_stream_printf (surface->output, + " /Widths ["); + for (i = 0; i < font_subset->num_glyphs; i++) + _cairo_output_stream_printf (surface->output, " %f", widths[i]); + _cairo_output_stream_printf (surface->output, + "]\n"); + free (widths); + + _cairo_output_stream_printf (surface->output, + " /Resources\n"); + _cairo_pdf_surface_emit_group_resources (surface, &surface->resources); + + if (to_unicode_stream.id != 0) + _cairo_output_stream_printf (surface->output, + " /ToUnicode %d 0 R\n", + to_unicode_stream.id); + + _cairo_output_stream_printf (surface->output, + ">>\n" + "endobj\n"); + + font.font_id = font_subset->font_id; + font.subset_id = font_subset->subset_id; + font.subset_resource = subset_resource; + return _cairo_array_append (&surface->fonts, &font); +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_pdf_surface_t *surface = closure; + cairo_int_status_t status; + + status = _cairo_pdf_surface_emit_cff_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_pdf_surface_emit_truetype_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_pdf_surface_emit_type1_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_pdf_surface_emit_cff_fallback_font (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_pdf_surface_emit_type1_fallback_font (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_pdf_surface_t *surface = closure; + cairo_int_status_t status; + + status = _cairo_pdf_surface_emit_type3_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface) +{ + cairo_int_status_t status; + + status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, + _cairo_pdf_surface_analyze_user_font_subset, + surface); + if (unlikely (status)) + goto BAIL; + + status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets, + _cairo_pdf_surface_emit_unscaled_font_subset, + surface); + if (unlikely (status)) + goto BAIL; + + status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets, + _cairo_pdf_surface_emit_scaled_font_subset, + surface); + if (unlikely (status)) + goto BAIL; + + status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, + _cairo_pdf_surface_emit_scaled_font_subset, + surface); + +BAIL: + _cairo_scaled_font_subsets_destroy (surface->font_subsets); + surface->font_subsets = NULL; + + return status; +} + +static cairo_pdf_resource_t +_cairo_pdf_surface_write_catalog (cairo_pdf_surface_t *surface) +{ + cairo_pdf_resource_t catalog; + + catalog = _cairo_pdf_surface_new_object (surface); + if (catalog.id == 0) + return catalog; + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Catalog\n" + " /Pages %d 0 R\n" + ">>\n" + "endobj\n", + catalog.id, + surface->pages_resource.id); + + return catalog; +} + +static long +_cairo_pdf_surface_write_xref (cairo_pdf_surface_t *surface) +{ + cairo_pdf_object_t *object; + int num_objects, i; + long offset; + char buffer[11]; + + num_objects = _cairo_array_num_elements (&surface->objects); + + offset = _cairo_output_stream_get_position (surface->output); + _cairo_output_stream_printf (surface->output, + "xref\n" + "%d %d\n", + 0, num_objects + 1); + + _cairo_output_stream_printf (surface->output, + "0000000000 65535 f \n"); + for (i = 0; i < num_objects; i++) { + object = _cairo_array_index (&surface->objects, i); + snprintf (buffer, sizeof buffer, "%010ld", object->offset); + _cairo_output_stream_printf (surface->output, + "%s 00000 n \n", buffer); + } + + return offset; +} + +static cairo_int_status_t +_cairo_pdf_surface_write_mask_group (cairo_pdf_surface_t *surface, + cairo_pdf_smask_group_t *group) +{ + cairo_pdf_resource_t mask_group; + cairo_pdf_resource_t smask; + cairo_pdf_smask_group_t *smask_group; + cairo_pdf_resource_t pattern_res, gstate_res; + cairo_int_status_t status; + cairo_box_double_t bbox; + + /* Create mask group */ + _get_bbox_from_extents (group->height, &group->extents, &bbox); + status = _cairo_pdf_surface_open_group (surface, &bbox, NULL); + if (unlikely (status)) + return status; + + if (_can_paint_pattern (group->mask)) { + _cairo_output_stream_printf (surface->output, "q\n"); + status = _cairo_pdf_surface_paint_pattern (surface, + CAIRO_OPERATOR_OVER, + group->mask, + &group->extents, + FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "Q\n"); + } else { + pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, group->mask, + CAIRO_OPERATOR_OVER, + NULL, + &pattern_res, &gstate_res); + if (unlikely (status)) + return status; + + if (gstate_res.id != 0) { + smask_group = _cairo_pdf_surface_create_smask_group (surface, &group->extents); + if (unlikely (smask_group == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + smask_group->width = group->width; + smask_group->height = group->height; + smask_group->operation = PDF_PAINT; + smask_group->source = cairo_pattern_reference (group->mask); + smask_group->source_res = pattern_res; + status = _cairo_pdf_surface_add_smask_group (surface, smask_group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (smask_group); + return status; + } + + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_add_xobject (surface, smask_group->group_res); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + gstate_res.id, + smask_group->group_res.id); + } else { + status = _cairo_pdf_surface_select_pattern (surface, group->mask, pattern_res, FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "%f %f %f %f re f\n", + bbox.p1.x, + bbox.p1.y, + bbox.p2.x - bbox.p1.x, + bbox.p2.y - bbox.p1.y); + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + return status; + } + } + + status = _cairo_pdf_surface_close_group (surface, &mask_group); + if (unlikely (status)) + return status; + + /* Create source group */ + status = _cairo_pdf_surface_open_group (surface, &bbox, &group->source_res); + if (unlikely (status)) + return status; + + if (_can_paint_pattern (group->source)) { + _cairo_output_stream_printf (surface->output, "q\n"); + status = _cairo_pdf_surface_paint_pattern (surface, + CAIRO_OPERATOR_OVER, + group->source, + &group->extents, + FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "Q\n"); + } else { + pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, group->source, + CAIRO_OPERATOR_OVER, + NULL, + &pattern_res, &gstate_res); + if (unlikely (status)) + return status; + + if (gstate_res.id != 0) { + smask_group = _cairo_pdf_surface_create_smask_group (surface, &group->extents); + if (unlikely (smask_group == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + smask_group->operation = PDF_PAINT; + smask_group->source = cairo_pattern_reference (group->source); + smask_group->source_res = pattern_res; + status = _cairo_pdf_surface_add_smask_group (surface, smask_group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (smask_group); + return status; + } + + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_add_xobject (surface, smask_group->group_res); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + gstate_res.id, + smask_group->group_res.id); + } else { + status = _cairo_pdf_surface_select_pattern (surface, group->source, pattern_res, FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "%f %f %f %f re f\n", + bbox.p1.x, + bbox.p1.y, + bbox.p2.x - bbox.p1.x, + bbox.p2.y - bbox.p1.y); + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + return status; + } + } + + status = _cairo_pdf_surface_close_group (surface, NULL); + if (unlikely (status)) + return status; + + /* Create an smask based on the alpha component of mask_group */ + smask = _cairo_pdf_surface_new_object (surface); + if (smask.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Mask\n" + " /S /Alpha\n" + " /G %d 0 R\n" + ">>\n" + "endobj\n", + smask.id, + mask_group.id); + + /* Create a GState that uses the smask */ + _cairo_pdf_surface_update_object (surface, group->group_res); + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /ExtGState\n" + " /SMask %d 0 R\n" + " /ca 1\n" + " /CA 1\n" + " /AIS false\n" + ">>\n" + "endobj\n", + group->group_res.id, + smask.id); + + return _cairo_output_stream_get_status (surface->output); +} + +static cairo_int_status_t +_cairo_pdf_surface_write_smask_group (cairo_pdf_surface_t *surface, + cairo_pdf_smask_group_t *group) +{ + double old_width, old_height; + cairo_int_status_t status; + cairo_box_double_t bbox; + + old_width = surface->width; + old_height = surface->height; + _cairo_pdf_surface_set_size_internal (surface, + group->width, + group->height); + /* _mask is a special case that requires two groups - source + * and mask as well as a smask and gstate dictionary */ + if (group->operation == PDF_MASK) { + status = _cairo_pdf_surface_write_mask_group (surface, group); + goto RESTORE_SIZE; + } + + _get_bbox_from_extents (group->height, &group->extents, &bbox); + status = _cairo_pdf_surface_open_group (surface, &bbox, &group->group_res); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_select_pattern (surface, + group->source, + group->source_res, + group->operation == PDF_STROKE); + if (unlikely (status)) + return status; + + switch (group->operation) { + case PDF_PAINT: + _cairo_output_stream_printf (surface->output, + "0 0 %f %f re f\n", + surface->width, surface->height); + break; + case PDF_MASK: + ASSERT_NOT_REACHED; + break; + case PDF_FILL: + status = _cairo_pdf_operators_fill (&surface->pdf_operators, + &group->path, + group->fill_rule); + break; + case PDF_STROKE: + status = _cairo_pdf_operators_stroke (&surface->pdf_operators, + &group->path, + &group->style, + &group->ctm, + &group->ctm_inverse); + break; + case PDF_SHOW_GLYPHS: + status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, + group->utf8, group->utf8_len, + group->glyphs, group->num_glyphs, + group->clusters, group->num_clusters, + group->cluster_flags, + group->scaled_font); + break; + } + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_close_group (surface, NULL); + +RESTORE_SIZE: + _cairo_pdf_surface_set_size_internal (surface, + old_width, + old_height); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_write_patterns_and_smask_groups (cairo_pdf_surface_t *surface) +{ + cairo_pdf_pattern_t pattern; + cairo_pdf_smask_group_t *group; + cairo_pdf_source_surface_t src_surface; + unsigned int pattern_index, group_index, surface_index; + cairo_int_status_t status; + + /* Writing out PDF_MASK groups will cause additional smask groups + * to be appended to surface->smask_groups. Additional patterns + * may also be appended to surface->patterns. + * + * Writing recording surface patterns will cause additional patterns + * and groups to be appended. + */ + pattern_index = 0; + group_index = 0; + surface_index = 0; + while ((pattern_index < _cairo_array_num_elements (&surface->page_patterns)) || + (group_index < _cairo_array_num_elements (&surface->smask_groups)) || + (surface_index < _cairo_array_num_elements (&surface->page_surfaces))) + { + for (; group_index < _cairo_array_num_elements (&surface->smask_groups); group_index++) { + _cairo_array_copy_element (&surface->smask_groups, group_index, &group); + status = _cairo_pdf_surface_write_smask_group (surface, group); + if (unlikely (status)) + return status; + } + + for (; pattern_index < _cairo_array_num_elements (&surface->page_patterns); pattern_index++) { + _cairo_array_copy_element (&surface->page_patterns, pattern_index, &pattern); + status = _cairo_pdf_surface_emit_pattern (surface, &pattern); + if (unlikely (status)) + return status; + } + + for (; surface_index < _cairo_array_num_elements (&surface->page_surfaces); surface_index++) { + _cairo_array_copy_element (&surface->page_surfaces, surface_index, &src_surface); + status = _cairo_pdf_surface_emit_surface (surface, &src_surface); + if (unlikely (status)) + return status; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface) +{ + cairo_pdf_resource_t page, knockout, res; + cairo_int_status_t status; + unsigned int i, len; + + _cairo_pdf_group_resources_clear (&surface->resources); + if (surface->has_fallback_images) { + cairo_rectangle_int_t extents; + cairo_box_double_t bbox; + + extents.x = 0; + extents.y = 0; + extents.width = ceil (surface->width); + extents.height = ceil (surface->height); + _get_bbox_from_extents (surface->height, &extents, &bbox); + status = _cairo_pdf_surface_open_knockout_group (surface, &bbox); + if (unlikely (status)) + return status; + + len = _cairo_array_num_elements (&surface->knockout_group); + for (i = 0; i < len; i++) { + _cairo_array_copy_element (&surface->knockout_group, i, &res); + _cairo_output_stream_printf (surface->output, + "/x%d Do\n", + res.id); + status = _cairo_pdf_surface_add_xobject (surface, res); + if (unlikely (status)) + return status; + } + _cairo_output_stream_printf (surface->output, + "/x%d Do\n", + surface->content.id); + status = _cairo_pdf_surface_add_xobject (surface, surface->content); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_close_group (surface, &knockout); + if (unlikely (status)) + return status; + + _cairo_pdf_group_resources_clear (&surface->resources); + status = _cairo_pdf_surface_open_content_stream (surface, NULL, NULL, FALSE, FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, + "/x%d Do\n", + knockout.id); + status = _cairo_pdf_surface_add_xobject (surface, knockout); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_close_content_stream (surface); + if (unlikely (status)) + return status; + } + + page = _cairo_pdf_surface_new_object (surface); + if (page.id == 0) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->output, + "%d 0 obj\n" + "<< /Type /Page\n" + " /Parent %d 0 R\n" + " /MediaBox [ 0 0 %f %f ]\n" + " /Contents %d 0 R\n" + " /Group <<\n" + " /Type /Group\n" + " /S /Transparency\n" + " /I true\n" + " /CS /DeviceRGB\n" + " >>\n" + " /Resources %d 0 R\n" + ">>\n" + "endobj\n", + page.id, + surface->pages_resource.id, + surface->width, + surface->height, + surface->content.id, + surface->content_resources.id); + + status = _cairo_array_append (&surface->pages, &page); + if (unlikely (status)) + return status; + + status = _cairo_pdf_surface_write_patterns_and_smask_groups (surface); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_pdf_surface_analyze_surface_pattern_transparency (cairo_pdf_surface_t *surface, + cairo_surface_pattern_t *pattern) +{ + cairo_image_surface_t *image; + void *image_extra; + cairo_int_status_t status; + cairo_image_transparency_t transparency; + + status = _cairo_surface_acquire_source_image (pattern->surface, + &image, + &image_extra); + if (unlikely (status)) + return status; + + if (image->base.status) + return image->base.status; + + transparency = _cairo_image_analyze_transparency (image); + if (transparency == CAIRO_IMAGE_IS_OPAQUE) + status = CAIRO_STATUS_SUCCESS; + else + status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; + + _cairo_surface_release_source_image (pattern->surface, image, image_extra); + + return status; +} + +static cairo_bool_t +_surface_pattern_supported (cairo_surface_pattern_t *pattern) +{ + cairo_extend_t extend; + + if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + return TRUE; + + if (pattern->surface->backend->acquire_source_image == NULL) + return FALSE; + + /* Does an ALPHA-only source surface even make sense? Maybe, but I + * don't think it's worth the extra code to support it. */ + +/* XXX: Need to write this function here... + if (pattern->surface->content == CAIRO_CONTENT_ALPHA) + return FALSE; +*/ + + extend = cairo_pattern_get_extend (&pattern->base); + switch (extend) { + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_REPEAT: + case CAIRO_EXTEND_REFLECT: + /* There's no point returning FALSE for EXTEND_PAD, as the image + * surface does not currently implement it either */ + case CAIRO_EXTEND_PAD: + return TRUE; + } + + ASSERT_NOT_REACHED; + return FALSE; +} + +static cairo_bool_t +_pattern_supported (const cairo_pattern_t *pattern) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return TRUE; + + case CAIRO_PATTERN_TYPE_SURFACE: + return _surface_pattern_supported ((cairo_surface_pattern_t *) pattern); + + default: + ASSERT_NOT_REACHED; + return FALSE; + } +} + +static cairo_bool_t +_pdf_operator_supported (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return TRUE; + + default: + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_ATOP: + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_DEST_ATOP: + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + return FALSE; + } +} + +static cairo_int_status_t +_cairo_pdf_surface_analyze_operation (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + if (surface->force_fallbacks && + surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (! _pattern_supported (pattern)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (_pdf_operator_supported (op)) { + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; + + if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { + if (pattern->extend == CAIRO_EXTEND_PAD) { + cairo_box_t box; + cairo_rectangle_int_t rect; + cairo_rectangle_int_t rec_extents; + + /* get the operation extents in pattern space */ + _cairo_box_from_rectangle (&box, extents); + _cairo_matrix_transform_bounding_box_fixed (&pattern->matrix, &box, NULL); + _cairo_box_round_to_rectangle (&box, &rect); + + /* Check if surface needs padding to fill extents */ + if (_cairo_surface_get_extents (surface_pattern->surface, &rec_extents)) { + if (_cairo_fixed_integer_ceil(box.p1.x) < rec_extents.x || + _cairo_fixed_integer_ceil(box.p1.y) < rec_extents.y || + _cairo_fixed_integer_floor(box.p2.y) > rec_extents.x + rec_extents.width || + _cairo_fixed_integer_floor(box.p2.y) > rec_extents.y + rec_extents.height) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + } + return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; + } + } + + return CAIRO_STATUS_SUCCESS; + } + + + /* The SOURCE operator is supported if the pattern is opaque or if + * there is nothing painted underneath. */ + if (op == CAIRO_OPERATOR_SOURCE) { + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; + + if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { + if (_cairo_pattern_is_opaque (pattern, extents)) { + return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; + } else { + /* FIXME: The analysis surface does not yet have + * the capability to analyze a non opaque recording + * surface and mark it supported if there is + * nothing underneath. For now recording surfaces of + * type CONTENT_COLOR_ALPHA painted with + * OPERATOR_SOURCE will result in a fallback + * image. */ + + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } else { + return _cairo_pdf_surface_analyze_surface_pattern_transparency (surface, + surface_pattern); + } + } + + if (_cairo_pattern_is_opaque (pattern, extents)) + return CAIRO_STATUS_SUCCESS; + else + return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_bool_t +_cairo_pdf_surface_operation_supported (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + return _cairo_pdf_surface_analyze_operation (surface, op, pattern, extents) != CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_int_status_t +_cairo_pdf_surface_start_fallback (cairo_pdf_surface_t *surface) +{ + cairo_box_double_t bbox; + cairo_int_status_t status; + + status = _cairo_pdf_surface_close_content_stream (surface); + if (unlikely (status)) + return status; + + status = _cairo_array_append (&surface->knockout_group, &surface->content); + if (unlikely (status)) + return status; + + _cairo_pdf_group_resources_clear (&surface->resources); + bbox.p1.x = 0; + bbox.p1.y = 0; + bbox.p2.x = surface->width; + bbox.p2.y = surface->height; + return _cairo_pdf_surface_open_content_stream (surface, &bbox, NULL, TRUE, TRUE); +} + +/* If source is an opaque image and mask is an image and both images + * have the same bounding box we can emit them as a image/smask pair. + */ +static cairo_int_status_t +_cairo_pdf_surface_emit_combined_smask (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_rectangle_int_t *extents) +{ + cairo_int_status_t status; + cairo_image_surface_t *image; + void *image_extra; + cairo_image_transparency_t transparency; + cairo_pdf_resource_t smask_res; + int src_width, src_height; + int mask_width, mask_height; + double src_x_offset, src_y_offset; + double mask_x_offset, mask_y_offset; + double src_x1, src_y1, src_x2, src_y2; + double mask_x1, mask_y1, mask_x2, mask_y2; + cairo_matrix_t p2u; + double src_radius, mask_radius, e; + cairo_rectangle_int_t extents2; + cairo_bool_t need_smask; + + /* Check that source and mask are images */ + + if (!((source->type == CAIRO_PATTERN_TYPE_SURFACE || source->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) && + (mask->type == CAIRO_PATTERN_TYPE_SURFACE || mask->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *) source)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (mask->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *) mask)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (source->extend != CAIRO_EXTEND_NONE || mask->extend != CAIRO_EXTEND_NONE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Check that source is opaque and get image sizes */ + + status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, source, + &image, &image_extra); + if (unlikely (status)) + return status; + + if (image->base.status) + return image->base.status; + + src_width = image->width; + src_height = image->height; + if (source->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { + cairo_surface_get_device_offset (&image->base, &src_x_offset, &src_y_offset); + } else { + src_x_offset = 0; + src_y_offset = 0; + } + + transparency = _cairo_image_analyze_transparency (image); + _cairo_pdf_surface_release_source_image_from_pattern (surface, source, image, image_extra); + + if (transparency != CAIRO_IMAGE_IS_OPAQUE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, mask, + &image, &image_extra); + if (unlikely (status)) + return status; + + if (image->base.status) + return image->base.status; + + mask_width = image->width; + mask_height = image->height; + if (mask->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { + cairo_surface_get_device_offset (&image->base, &mask_x_offset, &mask_y_offset); + } else { + mask_x_offset = 0; + mask_y_offset = 0; + } + + transparency = _cairo_image_analyze_transparency (image); + need_smask = transparency != CAIRO_IMAGE_IS_OPAQUE; + + _cairo_pdf_surface_release_source_image_from_pattern (surface, mask, image, image_extra); + + /* Check that both images have the same extents with a tolerance + * of half the smallest source pixel. */ + + p2u = source->matrix; + status = cairo_matrix_invert (&p2u); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + src_x1 = 0; + src_y1 = 0; + src_x2 = src_width; + src_y2 = src_height; + cairo_matrix_transform_point (&p2u, &src_x1, &src_y1); + cairo_matrix_transform_point (&p2u, &src_x2, &src_y2); + src_radius = _cairo_matrix_transformed_circle_major_axis (&p2u, 0.5); + + p2u = mask->matrix; + status = cairo_matrix_invert (&p2u); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_INT_STATUS_SUCCESS); + mask_x1 = 0; + mask_y1 = 0; + mask_x2 = mask_width; + mask_y2 = mask_height; + cairo_matrix_transform_point (&p2u, &mask_x1, &mask_y1); + cairo_matrix_transform_point (&p2u, &mask_x2, &mask_y2); + mask_radius = _cairo_matrix_transformed_circle_major_axis (&p2u, 0.5); + + if (src_radius < mask_radius) + e = src_radius; + else + e = mask_radius; + + if (fabs(src_x1 - mask_x1) > e || + fabs(src_x2 - mask_x2) > e || + fabs(src_y1 - mask_y1) > e || + fabs(src_y2 - mask_y2) > e) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Check both images have same device offset */ + if (fabs(src_x_offset - mask_x_offset) > e || + fabs(src_y_offset - mask_y_offset) > e) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (need_smask) { + status = _cairo_pdf_surface_add_source_surface (surface, + NULL, + mask, + op, + source->filter, + FALSE, + TRUE, + extents, + NULL, + &smask_res, + &mask_width, + &mask_height, + &mask_x_offset, + &mask_y_offset, + &extents2); + if (unlikely (status)) + return status; + } + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "q\n"); + status = _cairo_pdf_surface_paint_surface_pattern (surface, op, source, extents, + need_smask ? &smask_res : NULL, + FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "Q\n"); + + status = _cairo_output_stream_get_status (surface->output); + + + return status; +} + +/* A PDF stencil mask is an A1 mask used with the current color */ +static cairo_int_status_t +_cairo_pdf_surface_emit_stencil_mask (cairo_pdf_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_rectangle_int_t *extents) +{ + cairo_int_status_t status; + cairo_image_surface_t *image; + void *image_extra; + cairo_image_transparency_t transparency; + cairo_pdf_resource_t pattern_res = {0}; + + if (! (source->type == CAIRO_PATTERN_TYPE_SOLID && + (mask->type == CAIRO_PATTERN_TYPE_SURFACE || mask->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (mask->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *) mask)->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = _cairo_pdf_surface_acquire_source_image_from_pattern (surface, mask, + &image, &image_extra); + if (unlikely (status)) + return status; + + if (image->base.status) + return image->base.status; + + transparency = _cairo_image_analyze_transparency (image); + if (transparency != CAIRO_IMAGE_IS_OPAQUE && + transparency != CAIRO_IMAGE_HAS_BILEVEL_ALPHA) + { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + + status = _cairo_pdf_surface_select_pattern (surface, source, + pattern_res, FALSE); + if (unlikely (status)) + return status; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "q\n"); + status = _cairo_pdf_surface_paint_surface_pattern (surface, op, mask, extents, NULL, TRUE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->output, "Q\n"); + + status = _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_pdf_surface_release_source_image_from_pattern (surface, mask, image, image_extra); + + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_set_clip (cairo_pdf_surface_t *surface, + cairo_composite_rectangles_t *composite) +{ + cairo_clip_t *clip = composite->clip; + + if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) + clip = NULL; + + if (clip == NULL) { + if (_cairo_composite_rectangles_can_reduce_clip (composite, + surface->clipper.clip)) + return CAIRO_STATUS_SUCCESS; + } + + return _cairo_surface_clipper_set_clip (&surface->clipper, clip); +} + +static cairo_int_status_t +_cairo_pdf_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_pdf_smask_group_t *group; + cairo_pdf_resource_t pattern_res, gstate_res; + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + status = _cairo_composite_rectangles_init_for_paint (&extents, + &surface->base, + op, source, clip); + if (unlikely (status)) + return status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); + goto cleanup; + } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { + status = _cairo_pdf_surface_start_fallback (surface); + if (unlikely (status)) + goto cleanup; + } + + assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); + + status = _cairo_pdf_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_operator (surface, op); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + + if (_can_paint_pattern (source)) { + _cairo_output_stream_printf (surface->output, "q\n"); + status = _cairo_pdf_surface_paint_pattern (surface, + op, + source, + &extents.bounded, + FALSE); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, "Q\n"); + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + } + + pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, + &extents.bounded, + &pattern_res, &gstate_res); + if (unlikely (status)) + goto cleanup; + + if (gstate_res.id != 0) { + group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); + if (unlikely (group == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + + group->operation = PDF_PAINT; + status = _cairo_pattern_create_copy (&group->source, source); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + group->source_res = pattern_res; + status = _cairo_pdf_surface_add_smask_group (surface, group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_add_xobject (surface, group->group_res); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + gstate_res.id, + group->group_res.id); + } else { + status = _cairo_pdf_surface_select_pattern (surface, source, + pattern_res, FALSE); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, + "0 0 %f %f re f\n", + surface->width, surface->height); + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + goto cleanup; + } + + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_pdf_smask_group_t *group; + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + cairo_rectangle_int_t r; + cairo_box_t box; + + status = _cairo_composite_rectangles_init_for_mask (&extents, + &surface->base, + op, source, mask, clip); + if (unlikely (status)) + return status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + cairo_int_status_t source_status, mask_status; + + status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); + if (_cairo_int_status_is_error (status)) + goto cleanup; + source_status = status; + + if (mask->has_component_alpha) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + } else { + status = _cairo_pdf_surface_analyze_operation (surface, op, mask, &extents.bounded); + if (_cairo_int_status_is_error (status)) + goto cleanup; + } + mask_status = status; + + _cairo_composite_rectangles_fini (&extents); + return _cairo_analysis_surface_merge_status (source_status, + mask_status); + } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { + status = _cairo_pdf_surface_start_fallback (surface); + if (unlikely (status)) + goto cleanup; + } + + assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); + assert (_cairo_pdf_surface_operation_supported (surface, op, mask, &extents.bounded)); + + /* get the accurate extents */ + status = _cairo_pattern_get_ink_extents (source, &r); + if (unlikely (status)) + goto cleanup; + + /* XXX slight impedance mismatch */ + _cairo_box_from_rectangle (&box, &r); + status = _cairo_composite_rectangles_intersect_source_extents (&extents, + &box); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pattern_get_ink_extents (mask, &r); + if (unlikely (status)) + goto cleanup; + + _cairo_box_from_rectangle (&box, &r); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, + &box); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_operator (surface, op); + if (unlikely (status)) + goto cleanup; + + /* Check if we can combine source and mask into a smask image */ + status = _cairo_pdf_surface_emit_combined_smask (surface, op, source, mask, &extents.bounded); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + goto cleanup; + + /* Check if we can use a stencil mask */ + status = _cairo_pdf_surface_emit_stencil_mask (surface, op, source, mask, &extents.bounded); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + goto cleanup; + + group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); + if (unlikely (group == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + + group->operation = PDF_MASK; + status = _cairo_pattern_create_copy (&group->source, source); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + status = _cairo_pattern_create_copy (&group->mask, mask); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + group->source_res = _cairo_pdf_surface_new_object (surface); + if (group->source_res.id == 0) { + _cairo_pdf_smask_group_destroy (group); + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + + status = _cairo_pdf_surface_add_smask_group (surface, group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + status = _cairo_pdf_surface_add_smask (surface, group->group_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_add_xobject (surface, group->source_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + group->group_res.id, + group->source_res.id); + + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_pdf_smask_group_t *group; + cairo_pdf_resource_t pattern_res, gstate_res; + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + status = _cairo_composite_rectangles_init_for_stroke (&extents, + &surface->base, + op, source, + path, style, ctm, + clip); + if (unlikely (status)) + return status; + + /* use the more accurate extents */ + if (extents.is_bounded) { + cairo_rectangle_int_t mask; + cairo_box_t box; + + status = _cairo_path_fixed_stroke_extents (path, style, + ctm, ctm_inverse, + tolerance, + &mask); + if (unlikely (status)) + goto cleanup; + + _cairo_box_from_rectangle (&box, &mask); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, + &box); + if (unlikely (status)) + goto cleanup; + } + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); + goto cleanup; + } + + assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); + + status = _cairo_pdf_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup; + + pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, + &extents.bounded, + &pattern_res, &gstate_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_operator (surface, op); + if (unlikely (status)) + goto cleanup; + + if (gstate_res.id != 0) { + group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); + if (unlikely (group == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + + group->operation = PDF_STROKE; + status = _cairo_pattern_create_copy (&group->source, source); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + group->source_res = pattern_res; + status = _cairo_path_fixed_init_copy (&group->path, path); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + group->style = *style; + group->ctm = *ctm; + group->ctm_inverse = *ctm_inverse; + status = _cairo_pdf_surface_add_smask_group (surface, group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_add_xobject (surface, group->group_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + gstate_res.id, + group->group_res.id); + } else { + status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, TRUE); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_stroke (&surface->pdf_operators, + path, + style, + ctm, + ctm_inverse); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + goto cleanup; + } + + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_int_status_t status; + cairo_pdf_smask_group_t *group; + cairo_pdf_resource_t pattern_res, gstate_res; + cairo_composite_rectangles_t extents; + + status = _cairo_composite_rectangles_init_for_fill (&extents, + &surface->base, + op, source, path, + clip); + if (unlikely (status)) + return status; + + /* use the more accurate extents */ + if (extents.is_bounded) { + cairo_rectangle_int_t mask; + cairo_box_t box; + + _cairo_path_fixed_fill_extents (path, + fill_rule, + tolerance, + &mask); + + _cairo_box_from_rectangle (&box, &mask); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, + &box); + if (unlikely (status)) + goto cleanup; + } + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); + goto cleanup; + } else if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { + status = _cairo_pdf_surface_start_fallback (surface); + if (unlikely (status)) + goto cleanup; + } + + assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); + + status = _cairo_pdf_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_operator (surface, op); + if (unlikely (status)) + goto cleanup; + + if (_can_paint_pattern (source)) { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, "q\n"); + status = _cairo_pdf_operators_clip (&surface->pdf_operators, + path, + fill_rule); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_paint_pattern (surface, + op, + source, + &extents.bounded, + FALSE); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, "Q\n"); + status = _cairo_output_stream_get_status (surface->output); + goto cleanup; + } + + pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, + &extents.bounded, + &pattern_res, &gstate_res); + if (unlikely (status)) + goto cleanup; + + if (gstate_res.id != 0) { + group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); + if (unlikely (group == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + + group->operation = PDF_FILL; + status = _cairo_pattern_create_copy (&group->source, source); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + group->source_res = pattern_res; + status = _cairo_path_fixed_init_copy (&group->path, path); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + group->fill_rule = fill_rule; + status = _cairo_pdf_surface_add_smask_group (surface, group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_add_xobject (surface, group->group_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + gstate_res.id, + group->group_res.id); + } else { + status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_fill (&surface->pdf_operators, + path, + fill_rule); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + goto cleanup; + } + + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_pdf_surface_fill_stroke (void *abstract_surface, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + const cairo_path_fixed_t*path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_int_status_t status; + cairo_pdf_resource_t fill_pattern_res, stroke_pattern_res, gstate_res; + cairo_composite_rectangles_t extents; + + /* During analysis we return unsupported and let the _fill and + * _stroke functions that are on the fallback path do the analysis + * for us. During render we may still encounter unsupported + * combinations of fill/stroke patterns. However we can return + * unsupported anytime to let the _fill and _stroke functions take + * over. + */ + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* PDF rendering of fill-stroke is not the same as cairo when + * either the fill or stroke is not opaque. + */ + if ( !_cairo_pattern_is_opaque (fill_source, NULL) || + !_cairo_pattern_is_opaque (stroke_source, NULL)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (fill_op != stroke_op) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Compute the operation extents using the stroke which will naturally + * be larger than the fill extents. + */ + status = _cairo_composite_rectangles_init_for_stroke (&extents, + &surface->base, + stroke_op, stroke_source, + path, stroke_style, stroke_ctm, + clip); + if (unlikely (status)) + return status; + + /* use the more accurate extents */ + if (extents.is_bounded) { + cairo_rectangle_int_t mask; + cairo_box_t box; + + status = _cairo_path_fixed_stroke_extents (path, stroke_style, + stroke_ctm, stroke_ctm_inverse, + stroke_tolerance, + &mask); + if (unlikely (status)) + goto cleanup; + + _cairo_box_from_rectangle (&box, &mask); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, + &box); + if (unlikely (status)) + goto cleanup; + } + + status = _cairo_pdf_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_operator (surface, fill_op); + if (unlikely (status)) + goto cleanup; + + /* use the more accurate extents */ + if (extents.is_bounded) { + cairo_rectangle_int_t mask; + cairo_box_t box; + + _cairo_path_fixed_fill_extents (path, + fill_rule, + fill_tolerance, + &mask); + + _cairo_box_from_rectangle (&box, &mask); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, + &box); + if (unlikely (status)) + goto cleanup; + } + + fill_pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, fill_source, + fill_op, + &extents.bounded, + &fill_pattern_res, + &gstate_res); + if (unlikely (status)) + goto cleanup; + + assert (gstate_res.id == 0); + + stroke_pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, + stroke_source, + stroke_op, + &extents.bounded, + &stroke_pattern_res, + &gstate_res); + if (unlikely (status)) + goto cleanup; + + assert (gstate_res.id == 0); + + /* As PDF has separate graphics state for fill and stroke we can + * select both at the same time */ + status = _cairo_pdf_surface_select_pattern (surface, fill_source, + fill_pattern_res, FALSE); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_pattern (surface, stroke_source, + stroke_pattern_res, TRUE); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_fill_stroke (&surface->pdf_operators, + path, + fill_rule, + stroke_style, + stroke_ctm, + stroke_ctm_inverse); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + goto cleanup; + + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_bool_t +_cairo_pdf_surface_has_show_text_glyphs (void *abstract_surface) +{ + return TRUE; +} + +static cairo_int_status_t +_cairo_pdf_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_pdf_surface_t *surface = abstract_surface; + cairo_pdf_smask_group_t *group; + cairo_pdf_resource_t pattern_res, gstate_res; + cairo_composite_rectangles_t extents; + cairo_bool_t overlap; + cairo_int_status_t status; + + status = _cairo_composite_rectangles_init_for_glyphs (&extents, + &surface->base, + op, source, + scaled_font, + glyphs, num_glyphs, + clip, + &overlap); + if (unlikely (status)) + return status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_pdf_surface_analyze_operation (surface, op, source, &extents.bounded); + goto cleanup; + } + + assert (_cairo_pdf_surface_operation_supported (surface, op, source, &extents.bounded)); + + status = _cairo_pdf_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup; + + pattern_res.id = 0; + gstate_res.id = 0; + status = _cairo_pdf_surface_add_pdf_pattern (surface, source, op, + &extents.bounded, + &pattern_res, &gstate_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_select_operator (surface, op); + if (unlikely (status)) + goto cleanup; + + if (gstate_res.id != 0) { + group = _cairo_pdf_surface_create_smask_group (surface, &extents.bounded); + if (unlikely (group == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + + group->operation = PDF_SHOW_GLYPHS; + status = _cairo_pattern_create_copy (&group->source, source); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + group->source_res = pattern_res; + + if (utf8_len) { + group->utf8 = malloc (utf8_len); + if (unlikely (group->utf8 == NULL)) { + _cairo_pdf_smask_group_destroy (group); + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + memcpy (group->utf8, utf8, utf8_len); + } + group->utf8_len = utf8_len; + + if (num_glyphs) { + group->glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); + if (unlikely (group->glyphs == NULL)) { + _cairo_pdf_smask_group_destroy (group); + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + memcpy (group->glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); + } + group->num_glyphs = num_glyphs; + + if (num_clusters) { + group->clusters = _cairo_malloc_ab (num_clusters, sizeof (cairo_text_cluster_t)); + if (unlikely (group->clusters == NULL)) { + _cairo_pdf_smask_group_destroy (group); + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto cleanup; + } + memcpy (group->clusters, clusters, sizeof (cairo_text_cluster_t) * num_clusters); + } + group->num_clusters = num_clusters; + + group->scaled_font = cairo_scaled_font_reference (scaled_font); + status = _cairo_pdf_surface_add_smask_group (surface, group); + if (unlikely (status)) { + _cairo_pdf_smask_group_destroy (group); + goto cleanup; + } + + status = _cairo_pdf_surface_add_smask (surface, gstate_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_add_xobject (surface, group->group_res); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + + _cairo_output_stream_printf (surface->output, + "q /s%d gs /x%d Do Q\n", + gstate_res.id, + group->group_res.id); + } else { + status = _cairo_pdf_surface_select_pattern (surface, source, pattern_res, FALSE); + if (unlikely (status)) + goto cleanup; + + /* Each call to show_glyphs() with a transclucent pattern must + * be in a separate text object otherwise overlapping text + * from separate calls to show_glyphs will not composite with + * each other. */ + if (! _cairo_pattern_is_opaque (source, &extents.bounded)) { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup; + } + + status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_surface_unselect_pattern (surface); + if (unlikely (status)) + goto cleanup; + } + + _cairo_composite_rectangles_fini (&extents); + return _cairo_output_stream_get_status (surface->output); + +cleanup: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static const char ** +_cairo_pdf_surface_get_supported_mime_types (void *abstract_surface) +{ + return _cairo_pdf_supported_mime_types; +} + +static void +_cairo_pdf_surface_set_paginated_mode (void *abstract_surface, + cairo_paginated_mode_t paginated_mode) +{ + cairo_pdf_surface_t *surface = abstract_surface; + + surface->paginated_mode = paginated_mode; +} + +static const cairo_surface_backend_t cairo_pdf_surface_backend = { + CAIRO_SURFACE_TYPE_PDF, + _cairo_pdf_surface_finish, + + _cairo_default_context_create, + + NULL, /* create similar: handled by wrapper */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* _cairo_pdf_surface_copy_page */ + _cairo_pdf_surface_show_page, + + _cairo_pdf_surface_get_extents, + _cairo_pdf_surface_get_font_options, + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + /* Here are the drawing functions */ + _cairo_pdf_surface_paint, + _cairo_pdf_surface_mask, + _cairo_pdf_surface_stroke, + _cairo_pdf_surface_fill, + _cairo_pdf_surface_fill_stroke, + NULL, /* show_glyphs */ + _cairo_pdf_surface_has_show_text_glyphs, + _cairo_pdf_surface_show_text_glyphs, + _cairo_pdf_surface_get_supported_mime_types, +}; + +static const cairo_paginated_surface_backend_t +cairo_pdf_surface_paginated_backend = { + _cairo_pdf_surface_start_page, + _cairo_pdf_surface_set_paginated_mode, + NULL, /* set_bounding_box */ + _cairo_pdf_surface_has_fallback_images, + _cairo_pdf_surface_supports_fine_grained_fallbacks, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pdf.h b/Build/source/libs/cairo/cairo-src/src/cairo-pdf.h new file mode 100644 index 00000000000..1bc8524f2b1 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pdf.h @@ -0,0 +1,94 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PDF_H +#define CAIRO_PDF_H + +#include "cairo.h" + +#if CAIRO_HAS_PDF_SURFACE + +CAIRO_BEGIN_DECLS + +/** + * cairo_pdf_version_t: + * @CAIRO_PDF_VERSION_1_4: The version 1.4 of the PDF specification. (Since 1.10) + * @CAIRO_PDF_VERSION_1_5: The version 1.5 of the PDF specification. (Since 1.10) + * + * #cairo_pdf_version_t is used to describe the version number of the PDF + * specification that a generated PDF file will conform to. + * + * Since: 1.10 + **/ +typedef enum _cairo_pdf_version { + CAIRO_PDF_VERSION_1_4, + CAIRO_PDF_VERSION_1_5 +} cairo_pdf_version_t; + +cairo_public cairo_surface_t * +cairo_pdf_surface_create (const char *filename, + double width_in_points, + double height_in_points); + +cairo_public cairo_surface_t * +cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, + void *closure, + double width_in_points, + double height_in_points); + +cairo_public void +cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface, + cairo_pdf_version_t version); + +cairo_public void +cairo_pdf_get_versions (cairo_pdf_version_t const **versions, + int *num_versions); + +cairo_public const char * +cairo_pdf_version_to_string (cairo_pdf_version_t version); + +cairo_public void +cairo_pdf_surface_set_size (cairo_surface_t *surface, + double width_in_points, + double height_in_points); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_PDF_SURFACE */ +# error Cairo was not compiled with support for the pdf backend +#endif /* CAIRO_HAS_PDF_SURFACE */ + +#endif /* CAIRO_PDF_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pen.c b/Build/source/libs/cairo/cairo-src/src/cairo-pen.c new file mode 100644 index 00000000000..61be0e8299d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pen.c @@ -0,0 +1,475 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-slope-private.h" + +static void +_cairo_pen_compute_slopes (cairo_pen_t *pen); + +cairo_status_t +_cairo_pen_init (cairo_pen_t *pen, + double radius, + double tolerance, + const cairo_matrix_t *ctm) +{ + int i; + int reflect; + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + VG (VALGRIND_MAKE_MEM_UNDEFINED (pen, sizeof (cairo_pen_t))); + + pen->radius = radius; + pen->tolerance = tolerance; + + reflect = _cairo_matrix_compute_determinant (ctm) < 0.; + + pen->num_vertices = _cairo_pen_vertices_needed (tolerance, + radius, + ctm); + + if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) { + pen->vertices = _cairo_malloc_ab (pen->num_vertices, + sizeof (cairo_pen_vertex_t)); + if (unlikely (pen->vertices == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else { + pen->vertices = pen->vertices_embedded; + } + + /* + * Compute pen coordinates. To generate the right ellipse, compute points around + * a circle in user space and transform them to device space. To get a consistent + * orientation in device space, flip the pen if the transformation matrix + * is reflecting + */ + for (i=0; i < pen->num_vertices; i++) { + cairo_pen_vertex_t *v = &pen->vertices[i]; + double theta = 2 * M_PI * i / (double) pen->num_vertices, dx, dy; + if (reflect) + theta = -theta; + dx = radius * cos (theta); + dy = radius * sin (theta); + cairo_matrix_transform_distance (ctm, &dx, &dy); + v->point.x = _cairo_fixed_from_double (dx); + v->point.y = _cairo_fixed_from_double (dy); + } + + _cairo_pen_compute_slopes (pen); + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_pen_fini (cairo_pen_t *pen) +{ + if (pen->vertices != pen->vertices_embedded) + free (pen->vertices); + + + VG (VALGRIND_MAKE_MEM_NOACCESS (pen, sizeof (cairo_pen_t))); +} + +cairo_status_t +_cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (pen, sizeof (cairo_pen_t))); + + *pen = *other; + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + pen->vertices = pen->vertices_embedded; + if (pen->num_vertices) { + if (pen->num_vertices > ARRAY_LENGTH (pen->vertices_embedded)) { + pen->vertices = _cairo_malloc_ab (pen->num_vertices, + sizeof (cairo_pen_vertex_t)); + if (unlikely (pen->vertices == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + memcpy (pen->vertices, other->vertices, + pen->num_vertices * sizeof (cairo_pen_vertex_t)); + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points) +{ + cairo_status_t status; + int num_vertices; + int i; + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + num_vertices = pen->num_vertices + num_points; + if (num_vertices > ARRAY_LENGTH (pen->vertices_embedded) || + pen->vertices != pen->vertices_embedded) + { + cairo_pen_vertex_t *vertices; + + if (pen->vertices == pen->vertices_embedded) { + vertices = _cairo_malloc_ab (num_vertices, + sizeof (cairo_pen_vertex_t)); + if (unlikely (vertices == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (vertices, pen->vertices, + pen->num_vertices * sizeof (cairo_pen_vertex_t)); + } else { + vertices = _cairo_realloc_ab (pen->vertices, + num_vertices, + sizeof (cairo_pen_vertex_t)); + if (unlikely (vertices == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pen->vertices = vertices; + } + + pen->num_vertices = num_vertices; + + /* initialize new vertices */ + for (i=0; i < num_points; i++) + pen->vertices[pen->num_vertices-num_points+i].point = point[i]; + + status = _cairo_hull_compute (pen->vertices, &pen->num_vertices); + if (unlikely (status)) + return status; + + _cairo_pen_compute_slopes (pen); + + return CAIRO_STATUS_SUCCESS; +} + +/* +The circular pen in user space is transformed into an ellipse in +device space. + +We construct the pen by computing points along the circumference +using equally spaced angles. + +We show that this approximation to the ellipse has maximum error at the +major axis of the ellipse. + +Set + + M = major axis length + m = minor axis length + +Align 'M' along the X axis and 'm' along the Y axis and draw +an ellipse parameterized by angle 't': + + x = M cos t y = m sin t + +Perturb t by ± d and compute two new points (x+,y+), (x-,y-). +The distance from the average of these two points to (x,y) represents +the maximum error in approximating the ellipse with a polygon formed +from vertices 2∆ radians apart. + + x+ = M cos (t+∆) y+ = m sin (t+∆) + x- = M cos (t-∆) y- = m sin (t-∆) + +Now compute the approximation error, E: + + Ex = (x - (x+ + x-) / 2) + Ex = (M cos(t) - (Mcos(t+∆) + Mcos(t-∆))/2) + = M (cos(t) - (cos(t)cos(∆) + sin(t)sin(∆) + + cos(t)cos(∆) - sin(t)sin(∆))/2) + = M(cos(t) - cos(t)cos(∆)) + = M cos(t) (1 - cos(∆)) + + Ey = y - (y+ - y-) / 2 + = m sin (t) - (m sin(t+∆) + m sin(t-∆)) / 2 + = m (sin(t) - (sin(t)cos(∆) + cos(t)sin(∆) + + sin(t)cos(∆) - cos(t)sin(∆))/2) + = m (sin(t) - sin(t)cos(∆)) + = m sin(t) (1 - cos(∆)) + + E² = Ex² + Ey² + = (M cos(t) (1 - cos (∆)))² + (m sin(t) (1-cos(∆)))² + = (1 - cos(∆))² (M² cos²(t) + m² sin²(t)) + = (1 - cos(∆))² ((m² + M² - m²) cos² (t) + m² sin²(t)) + = (1 - cos(∆))² (M² - m²) cos² (t) + (1 - cos(∆))² m² + +Find the extremum by differentiation wrt t and setting that to zero + +∂(E²)/∂(t) = (1-cos(∆))² (M² - m²) (-2 cos(t) sin(t)) + + 0 = 2 cos (t) sin (t) + 0 = sin (2t) + t = nπ + +Which is to say that the maximum and minimum errors occur on the +axes of the ellipse at 0 and π radians: + + E²(0) = (1-cos(∆))² (M² - m²) + (1-cos(∆))² m² + = (1-cos(∆))² M² + E²(π) = (1-cos(∆))² m² + +maximum error = M (1-cos(∆)) +minimum error = m (1-cos(∆)) + +We must make maximum error ≤ tolerance, so compute the ∆ needed: + + tolerance = M (1-cos(∆)) + tolerance / M = 1 - cos (∆) + cos(∆) = 1 - tolerance/M + ∆ = acos (1 - tolerance / M); + +Remembering that ∆ is half of our angle between vertices, +the number of vertices is then + + vertices = ceil(2π/2∆). + = ceil(π/∆). + +Note that this also equation works for M == m (a circle) as it +doesn't matter where on the circle the error is computed. +*/ + +int +_cairo_pen_vertices_needed (double tolerance, + double radius, + const cairo_matrix_t *matrix) +{ + /* + * the pen is a circle that gets transformed to an ellipse by matrix. + * compute major axis length for a pen with the specified radius. + * we don't need the minor axis length. + */ + double major_axis = _cairo_matrix_transformed_circle_major_axis (matrix, + radius); + int num_vertices; + + if (tolerance >= 4*major_axis) { /* XXX relaxed from 2*major for inkscape */ + num_vertices = 1; + } else if (tolerance >= major_axis) { + num_vertices = 4; + } else { + num_vertices = ceil (2*M_PI / acos (1 - tolerance / major_axis)); + + /* number of vertices must be even */ + if (num_vertices % 2) + num_vertices++; + + /* And we must always have at least 4 vertices. */ + if (num_vertices < 4) + num_vertices = 4; + } + + return num_vertices; +} + +static void +_cairo_pen_compute_slopes (cairo_pen_t *pen) +{ + int i, i_prev; + cairo_pen_vertex_t *prev, *v, *next; + + for (i=0, i_prev = pen->num_vertices - 1; + i < pen->num_vertices; + i_prev = i++) { + prev = &pen->vertices[i_prev]; + v = &pen->vertices[i]; + next = &pen->vertices[(i + 1) % pen->num_vertices]; + + _cairo_slope_init (&v->slope_cw, &prev->point, &v->point); + _cairo_slope_init (&v->slope_ccw, &v->point, &next->point); + } +} +/* + * Find active pen vertex for clockwise edge of stroke at the given slope. + * + * The strictness of the inequalities here is delicate. The issue is + * that the slope_ccw member of one pen vertex will be equivalent to + * the slope_cw member of the next pen vertex in a counterclockwise + * order. However, for this function, we care strongly about which + * vertex is returned. + * + * [I think the "care strongly" above has to do with ensuring that the + * pen's "extra points" from the spline's initial and final slopes are + * properly found when beginning the spline stroking.] + */ +int +_cairo_pen_find_active_cw_vertex_index (const cairo_pen_t *pen, + const cairo_slope_t *slope) +{ + int i; + + for (i=0; i < pen->num_vertices; i++) { + if ((_cairo_slope_compare (slope, &pen->vertices[i].slope_ccw) < 0) && + (_cairo_slope_compare (slope, &pen->vertices[i].slope_cw) >= 0)) + break; + } + + /* If the desired slope cannot be found between any of the pen + * vertices, then we must have a degenerate pen, (such as a pen + * that's been transformed to a line). In that case, we consider + * the first pen vertex as the appropriate clockwise vertex. + */ + if (i == pen->num_vertices) + i = 0; + + return i; +} + +/* Find active pen vertex for counterclockwise edge of stroke at the given slope. + * + * Note: See the comments for _cairo_pen_find_active_cw_vertex_index + * for some details about the strictness of the inequalities here. + */ +int +_cairo_pen_find_active_ccw_vertex_index (const cairo_pen_t *pen, + const cairo_slope_t *slope) +{ + cairo_slope_t slope_reverse; + int i; + + slope_reverse = *slope; + slope_reverse.dx = -slope_reverse.dx; + slope_reverse.dy = -slope_reverse.dy; + + for (i=pen->num_vertices-1; i >= 0; i--) { + if ((_cairo_slope_compare (&pen->vertices[i].slope_ccw, &slope_reverse) >= 0) && + (_cairo_slope_compare (&pen->vertices[i].slope_cw, &slope_reverse) < 0)) + break; + } + + /* If the desired slope cannot be found between any of the pen + * vertices, then we must have a degenerate pen, (such as a pen + * that's been transformed to a line). In that case, we consider + * the last pen vertex as the appropriate counterclockwise vertex. + */ + if (i < 0) + i = pen->num_vertices - 1; + + return i; +} + +void +_cairo_pen_find_active_cw_vertices (const cairo_pen_t *pen, + const cairo_slope_t *in, + const cairo_slope_t *out, + int *start, int *stop) +{ + + int lo = 0, hi = pen->num_vertices; + int i; + + i = (lo + hi) >> 1; + do { + if (_cairo_slope_compare (&pen->vertices[i].slope_cw, in) < 0) + lo = i; + else + hi = i; + i = (lo + hi) >> 1; + } while (hi - lo > 1); + if (_cairo_slope_compare (&pen->vertices[i].slope_cw, in) < 0) + if (++i == pen->num_vertices) + i = 0; + *start = i; + + if (_cairo_slope_compare (out, &pen->vertices[i].slope_ccw) >= 0) { + lo = i; + hi = i + pen->num_vertices; + i = (lo + hi) >> 1; + do { + int j = i; + if (j >= pen->num_vertices) + j -= pen->num_vertices; + if (_cairo_slope_compare (&pen->vertices[j].slope_cw, out) > 0) + hi = i; + else + lo = i; + i = (lo + hi) >> 1; + } while (hi - lo > 1); + if (i >= pen->num_vertices) + i -= pen->num_vertices; + } + *stop = i; +} + +void +_cairo_pen_find_active_ccw_vertices (const cairo_pen_t *pen, + const cairo_slope_t *in, + const cairo_slope_t *out, + int *start, int *stop) +{ + int lo = 0, hi = pen->num_vertices; + int i; + + i = (lo + hi) >> 1; + do { + if (_cairo_slope_compare (in, &pen->vertices[i].slope_ccw) < 0) + lo = i; + else + hi = i; + i = (lo + hi) >> 1; + } while (hi - lo > 1); + if (_cairo_slope_compare (in, &pen->vertices[i].slope_ccw) < 0) + if (++i == pen->num_vertices) + i = 0; + *start = i; + + if (_cairo_slope_compare (&pen->vertices[i].slope_cw, out) <= 0) { + lo = i; + hi = i + pen->num_vertices; + i = (lo + hi) >> 1; + do { + int j = i; + if (j >= pen->num_vertices) + j -= pen->num_vertices; + if (_cairo_slope_compare (out, &pen->vertices[j].slope_ccw) > 0) + hi = i; + else + lo = i; + i = (lo + hi) >> 1; + } while (hi - lo > 1); + if (i >= pen->num_vertices) + i -= pen->num_vertices; + } + *stop = i; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-pixman-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-pixman-private.h new file mode 100644 index 00000000000..d705025c8ee --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-pixman-private.h @@ -0,0 +1,51 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright ©2013 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_PIXMAN_PRIVATE_H +#define CAIRO_PIXMAN_PRIVATE_H + +#include "cairo-pixman-private.h" /* keep make check happy */ + +#include + +#if PIXMAN_VERSION < PIXMAN_VERSION_ENCODE(0,22,0) +#define pixman_image_composite32 pixman_image_composite +#define pixman_image_get_component_alpha(i) 0 +#define pixman_image_set_component_alpha(i, x) do { } while (0) +#endif + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-png.c b/Build/source/libs/cairo/cairo-src/src/cairo-png.c new file mode 100644 index 00000000000..068617d588d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-png.c @@ -0,0 +1,819 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-output-stream-private.h" + +#include +#include +#include + +/** + * SECTION:cairo-png + * @Title: PNG Support + * @Short_Description: Reading and writing PNG images + * @See_Also: #cairo_surface_t + * + * The PNG functions allow reading PNG images into image surfaces, and writing + * any surface to a PNG file. + * + * It is a toy API. It only offers very simple support for reading and + * writing PNG files, which is sufficient for testing and + * demonstration purposes. Applications which need more control over + * the generated PNG file should access the pixel data directly, using + * cairo_image_surface_get_data() or a backend-specific access + * function, and process it with another library, e.g. gdk-pixbuf or + * libpng. + **/ + +/** + * CAIRO_HAS_PNG_FUNCTIONS: + * + * Defined if the PNG functions are available. + * This macro can be used to conditionally compile code using the cairo + * PNG functions. + * + * Since: 1.0 + **/ + +struct png_read_closure_t { + cairo_read_func_t read_func; + void *closure; + cairo_output_stream_t *png_data; +}; + + +/* Unpremultiplies data and converts native endian ARGB => RGBA bytes */ +static void +unpremultiply_data (png_structp png, png_row_infop row_info, png_bytep data) +{ + unsigned int i; + + for (i = 0; i < row_info->rowbytes; i += 4) { + uint8_t *b = &data[i]; + uint32_t pixel; + uint8_t alpha; + + memcpy (&pixel, b, sizeof (uint32_t)); + alpha = (pixel & 0xff000000) >> 24; + if (alpha == 0) { + b[0] = b[1] = b[2] = b[3] = 0; + } else { + b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha; + b[1] = (((pixel & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha; + b[2] = (((pixel & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha; + b[3] = alpha; + } + } +} + +/* Converts native endian xRGB => RGBx bytes */ +static void +convert_data_to_bytes (png_structp png, png_row_infop row_info, png_bytep data) +{ + unsigned int i; + + for (i = 0; i < row_info->rowbytes; i += 4) { + uint8_t *b = &data[i]; + uint32_t pixel; + + memcpy (&pixel, b, sizeof (uint32_t)); + + b[0] = (pixel & 0xff0000) >> 16; + b[1] = (pixel & 0x00ff00) >> 8; + b[2] = (pixel & 0x0000ff) >> 0; + b[3] = 0; + } +} + +/* Use a couple of simple error callbacks that do not print anything to + * stderr and rely on the user to check for errors via the #cairo_status_t + * return. + */ +static void +png_simple_error_callback (png_structp png, + png_const_charp error_msg) +{ + cairo_status_t *error = png_get_error_ptr (png); + + /* default to the most likely error */ + if (*error == CAIRO_STATUS_SUCCESS) + *error = _cairo_error (CAIRO_STATUS_NO_MEMORY); + +#ifdef PNG_SETJMP_SUPPORTED + longjmp (png_jmpbuf (png), 1); +#endif + + /* if we get here, then we have to choice but to abort ... */ +} + +static void +png_simple_warning_callback (png_structp png, + png_const_charp error_msg) +{ + /* png does not expect to abort and will try to tidy up and continue + * loading the image after a warning. So we also want to return the + * (incorrect?) surface. + * + * We use our own warning callback to squelch any attempts by libpng + * to write to stderr as we may not be in control of that output. + */ +} + + +/* Starting with libpng-1.2.30, we must explicitly specify an output_flush_fn. + * Otherwise, we will segfault if we are writing to a stream. */ +static void +png_simple_output_flush_fn (png_structp png_ptr) +{ +} + +static cairo_status_t +write_png (cairo_surface_t *surface, + png_rw_ptr write_func, + void *closure) +{ + int i; + cairo_int_status_t status; + cairo_image_surface_t *image; + cairo_image_surface_t * volatile clone; + void *image_extra; + png_struct *png; + png_info *info; + png_byte **volatile rows = NULL; + png_color_16 white; + int png_color_type; + int bpc; + + status = _cairo_surface_acquire_source_image (surface, + &image, + &image_extra); + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + else if (unlikely (status)) + return status; + + /* PNG complains about "Image width or height is zero in IHDR" */ + if (image->width == 0 || image->height == 0) { + status = _cairo_error (CAIRO_STATUS_WRITE_ERROR); + goto BAIL1; + } + + /* Handle the various fallback formats (e.g. low bit-depth XServers) + * by coercing them to a simpler format using pixman. + */ + clone = _cairo_image_surface_coerce (image); + status = clone->base.status; + if (unlikely (status)) + goto BAIL1; + + rows = _cairo_malloc_ab (clone->height, sizeof (png_byte*)); + if (unlikely (rows == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL2; + } + + for (i = 0; i < clone->height; i++) + rows[i] = (png_byte *) clone->data + i * clone->stride; + + png = png_create_write_struct (PNG_LIBPNG_VER_STRING, &status, + png_simple_error_callback, + png_simple_warning_callback); + if (unlikely (png == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL3; + } + + info = png_create_info_struct (png); + if (unlikely (info == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL4; + } + +#ifdef PNG_SETJMP_SUPPORTED + if (setjmp (png_jmpbuf (png))) + goto BAIL4; +#endif + + png_set_write_fn (png, closure, write_func, png_simple_output_flush_fn); + + switch (clone->format) { + case CAIRO_FORMAT_ARGB32: + bpc = 8; + if (_cairo_image_analyze_transparency (clone) == CAIRO_IMAGE_IS_OPAQUE) + png_color_type = PNG_COLOR_TYPE_RGB; + else + png_color_type = PNG_COLOR_TYPE_RGB_ALPHA; + break; + case CAIRO_FORMAT_RGB30: + bpc = 10; + png_color_type = PNG_COLOR_TYPE_RGB; + break; + case CAIRO_FORMAT_RGB24: + bpc = 8; + png_color_type = PNG_COLOR_TYPE_RGB; + break; + case CAIRO_FORMAT_A8: + bpc = 8; + png_color_type = PNG_COLOR_TYPE_GRAY; + break; + case CAIRO_FORMAT_A1: + bpc = 1; + png_color_type = PNG_COLOR_TYPE_GRAY; +#ifndef WORDS_BIGENDIAN + png_set_packswap (png); +#endif + break; + case CAIRO_FORMAT_INVALID: + case CAIRO_FORMAT_RGB16_565: + default: + status = _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + goto BAIL4; + } + + png_set_IHDR (png, info, + clone->width, + clone->height, bpc, + png_color_type, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + + white.gray = (1 << bpc) - 1; + white.red = white.blue = white.green = white.gray; + png_set_bKGD (png, info, &white); + + if (0) { /* XXX extract meta-data from surface (i.e. creation date) */ + png_time pt; + + png_convert_from_time_t (&pt, time (NULL)); + png_set_tIME (png, info, &pt); + } + + /* We have to call png_write_info() before setting up the write + * transformation, since it stores data internally in 'png' + * that is needed for the write transformation functions to work. + */ + png_write_info (png, info); + + if (png_color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + png_set_write_user_transform_fn (png, unpremultiply_data); + } else if (png_color_type == PNG_COLOR_TYPE_RGB) { + png_set_write_user_transform_fn (png, convert_data_to_bytes); + png_set_filler (png, 0, PNG_FILLER_AFTER); + } + + png_write_image (png, rows); + png_write_end (png, info); + +BAIL4: + png_destroy_write_struct (&png, &info); +BAIL3: + free (rows); +BAIL2: + cairo_surface_destroy (&clone->base); +BAIL1: + _cairo_surface_release_source_image (surface, image, image_extra); + + return status; +} + +static void +stdio_write_func (png_structp png, png_bytep data, png_size_t size) +{ + FILE *fp; + + fp = png_get_io_ptr (png); + while (size) { + size_t ret = fwrite (data, 1, size, fp); + size -= ret; + data += ret; + if (size && ferror (fp)) { + cairo_status_t *error = png_get_error_ptr (png); + if (*error == CAIRO_STATUS_SUCCESS) + *error = _cairo_error (CAIRO_STATUS_WRITE_ERROR); + png_error (png, NULL); + } + } +} + +/** + * cairo_surface_write_to_png: + * @surface: a #cairo_surface_t with pixel contents + * @filename: the name of a file to write to + * + * Writes the contents of @surface to a new file @filename as a PNG + * image. + * + * Return value: %CAIRO_STATUS_SUCCESS if the PNG file was written + * successfully. Otherwise, %CAIRO_STATUS_NO_MEMORY if memory could not + * be allocated for the operation or + * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have + * pixel contents, or %CAIRO_STATUS_WRITE_ERROR if an I/O error occurs + * while attempting to write the file. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_surface_write_to_png (cairo_surface_t *surface, + const char *filename) +{ + FILE *fp; + cairo_status_t status; + + if (surface->status) + return surface->status; + + if (surface->finished) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + fp = fopen (filename, "wb"); + if (fp == NULL) { + switch (errno) { + case ENOMEM: + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + default: + return _cairo_error (CAIRO_STATUS_WRITE_ERROR); + } + } + + status = write_png (surface, stdio_write_func, fp); + + if (fclose (fp) && status == CAIRO_STATUS_SUCCESS) + status = _cairo_error (CAIRO_STATUS_WRITE_ERROR); + + return status; +} + +struct png_write_closure_t { + cairo_write_func_t write_func; + void *closure; +}; + +static void +stream_write_func (png_structp png, png_bytep data, png_size_t size) +{ + cairo_status_t status; + struct png_write_closure_t *png_closure; + + png_closure = png_get_io_ptr (png); + status = png_closure->write_func (png_closure->closure, data, size); + if (unlikely (status)) { + cairo_status_t *error = png_get_error_ptr (png); + if (*error == CAIRO_STATUS_SUCCESS) + *error = status; + png_error (png, NULL); + } +} + +/** + * cairo_surface_write_to_png_stream: + * @surface: a #cairo_surface_t with pixel contents + * @write_func: a #cairo_write_func_t + * @closure: closure data for the write function + * + * Writes the image surface to the write function. + * + * Return value: %CAIRO_STATUS_SUCCESS if the PNG file was written + * successfully. Otherwise, %CAIRO_STATUS_NO_MEMORY is returned if + * memory could not be allocated for the operation, + * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have + * pixel contents. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_surface_write_to_png_stream (cairo_surface_t *surface, + cairo_write_func_t write_func, + void *closure) +{ + struct png_write_closure_t png_closure; + + if (surface->status) + return surface->status; + + if (surface->finished) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + png_closure.write_func = write_func; + png_closure.closure = closure; + + return write_png (surface, stream_write_func, &png_closure); +} +slim_hidden_def (cairo_surface_write_to_png_stream); + +static inline int +multiply_alpha (int alpha, int color) +{ + int temp = (alpha * color) + 0x80; + return ((temp + (temp >> 8)) >> 8); +} + +/* Premultiplies data and converts RGBA bytes => native endian */ +static void +premultiply_data (png_structp png, + png_row_infop row_info, + png_bytep data) +{ + unsigned int i; + + for (i = 0; i < row_info->rowbytes; i += 4) { + uint8_t *base = &data[i]; + uint8_t alpha = base[3]; + uint32_t p; + + if (alpha == 0) { + p = 0; + } else { + uint8_t red = base[0]; + uint8_t green = base[1]; + uint8_t blue = base[2]; + + if (alpha != 0xff) { + red = multiply_alpha (alpha, red); + green = multiply_alpha (alpha, green); + blue = multiply_alpha (alpha, blue); + } + p = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0); + } + memcpy (base, &p, sizeof (uint32_t)); + } +} + +/* Converts RGBx bytes to native endian xRGB */ +static void +convert_bytes_to_data (png_structp png, png_row_infop row_info, png_bytep data) +{ + unsigned int i; + + for (i = 0; i < row_info->rowbytes; i += 4) { + uint8_t *base = &data[i]; + uint8_t red = base[0]; + uint8_t green = base[1]; + uint8_t blue = base[2]; + uint32_t pixel; + + pixel = (0xff << 24) | (red << 16) | (green << 8) | (blue << 0); + memcpy (base, &pixel, sizeof (uint32_t)); + } +} + +static cairo_status_t +stdio_read_func (void *closure, unsigned char *data, unsigned int size) +{ + FILE *file = closure; + + while (size) { + size_t ret; + + ret = fread (data, 1, size, file); + size -= ret; + data += ret; + + if (size && (feof (file) || ferror (file))) + return _cairo_error (CAIRO_STATUS_READ_ERROR); + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +stream_read_func (png_structp png, png_bytep data, png_size_t size) +{ + cairo_status_t status; + struct png_read_closure_t *png_closure; + + png_closure = png_get_io_ptr (png); + status = png_closure->read_func (png_closure->closure, data, size); + if (unlikely (status)) { + cairo_status_t *error = png_get_error_ptr (png); + if (*error == CAIRO_STATUS_SUCCESS) + *error = status; + png_error (png, NULL); + } + + _cairo_output_stream_write (png_closure->png_data, data, size); +} + +static cairo_surface_t * +read_png (struct png_read_closure_t *png_closure) +{ + cairo_surface_t *surface; + png_struct *png = NULL; + png_info *info; + png_byte *data = NULL; + png_byte **row_pointers = NULL; + png_uint_32 png_width, png_height; + int depth, color_type, interlace, stride; + unsigned int i; + cairo_format_t format; + cairo_status_t status; + unsigned char *mime_data; + unsigned long mime_data_length; + + png_closure->png_data = _cairo_memory_stream_create (); + + /* XXX: Perhaps we'll want some other error handlers? */ + png = png_create_read_struct (PNG_LIBPNG_VER_STRING, + &status, + png_simple_error_callback, + png_simple_warning_callback); + if (unlikely (png == NULL)) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + goto BAIL; + } + + info = png_create_info_struct (png); + if (unlikely (info == NULL)) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + goto BAIL; + } + + png_set_read_fn (png, png_closure, stream_read_func); + + status = CAIRO_STATUS_SUCCESS; +#ifdef PNG_SETJMP_SUPPORTED + if (setjmp (png_jmpbuf (png))) { + surface = _cairo_surface_create_in_error (status); + goto BAIL; + } +#endif + + png_read_info (png, info); + + png_get_IHDR (png, info, + &png_width, &png_height, &depth, + &color_type, &interlace, NULL, NULL); + if (unlikely (status)) { /* catch any early warnings */ + surface = _cairo_surface_create_in_error (status); + goto BAIL; + } + + /* convert palette/gray image to rgb */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb (png); + + /* expand gray bit depth if needed */ + if (color_type == PNG_COLOR_TYPE_GRAY) { +#if PNG_LIBPNG_VER >= 10209 + png_set_expand_gray_1_2_4_to_8 (png); +#else + png_set_gray_1_2_4_to_8 (png); +#endif + } + + /* transform transparency to alpha */ + if (png_get_valid (png, info, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha (png); + + if (depth == 16) + png_set_strip_16 (png); + + if (depth < 8) + png_set_packing (png); + + /* convert grayscale to RGB */ + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + png_set_gray_to_rgb (png); + } + + if (interlace != PNG_INTERLACE_NONE) + png_set_interlace_handling (png); + + png_set_filler (png, 0xff, PNG_FILLER_AFTER); + + /* recheck header after setting EXPAND options */ + png_read_update_info (png, info); + png_get_IHDR (png, info, + &png_width, &png_height, &depth, + &color_type, &interlace, NULL, NULL); + if (depth != 8 || + ! (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA)) + { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_READ_ERROR)); + goto BAIL; + } + + switch (color_type) { + default: + ASSERT_NOT_REACHED; + /* fall-through just in case ;-) */ + + case PNG_COLOR_TYPE_RGB_ALPHA: + format = CAIRO_FORMAT_ARGB32; + png_set_read_user_transform_fn (png, premultiply_data); + break; + + case PNG_COLOR_TYPE_RGB: + format = CAIRO_FORMAT_RGB24; + png_set_read_user_transform_fn (png, convert_bytes_to_data); + break; + } + + stride = cairo_format_stride_for_width (format, png_width); + if (stride < 0) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE)); + goto BAIL; + } + + data = _cairo_malloc_ab (png_height, stride); + if (unlikely (data == NULL)) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + goto BAIL; + } + + row_pointers = _cairo_malloc_ab (png_height, sizeof (char *)); + if (unlikely (row_pointers == NULL)) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + goto BAIL; + } + + for (i = 0; i < png_height; i++) + row_pointers[i] = &data[i * stride]; + + png_read_image (png, row_pointers); + png_read_end (png, info); + + if (unlikely (status)) { /* catch any late warnings - probably hit an error already */ + surface = _cairo_surface_create_in_error (status); + goto BAIL; + } + + surface = cairo_image_surface_create_for_data (data, format, + png_width, png_height, + stride); + if (surface->status) + goto BAIL; + + _cairo_image_surface_assume_ownership_of_data ((cairo_image_surface_t*)surface); + data = NULL; + + _cairo_debug_check_image_surface_is_defined (surface); + + status = _cairo_memory_stream_destroy (png_closure->png_data, + &mime_data, + &mime_data_length); + png_closure->png_data = NULL; + if (unlikely (status)) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + goto BAIL; + } + + status = cairo_surface_set_mime_data (surface, + CAIRO_MIME_TYPE_PNG, + mime_data, + mime_data_length, + free, + mime_data); + if (unlikely (status)) { + free (mime_data); + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + goto BAIL; + } + + BAIL: + free (row_pointers); + free (data); + if (png != NULL) + png_destroy_read_struct (&png, &info, NULL); + if (png_closure->png_data != NULL) { + cairo_status_t status_ignored; + + status_ignored = _cairo_output_stream_destroy (png_closure->png_data); + } + + return surface; +} + +/** + * cairo_image_surface_create_from_png: + * @filename: name of PNG file to load + * + * Creates a new image surface and initializes the contents to the + * given PNG file. + * + * Return value: a new #cairo_surface_t initialized with the contents + * of the PNG file, or a "nil" surface if any error occurred. A nil + * surface can be checked for with cairo_surface_status(surface) which + * may return one of the following values: + * + * %CAIRO_STATUS_NO_MEMORY + * %CAIRO_STATUS_FILE_NOT_FOUND + * %CAIRO_STATUS_READ_ERROR + * + * Alternatively, you can allow errors to propagate through the drawing + * operations and check the status on the context upon completion + * using cairo_status(). + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_image_surface_create_from_png (const char *filename) +{ + struct png_read_closure_t png_closure; + cairo_surface_t *surface; + + png_closure.closure = fopen (filename, "rb"); + if (png_closure.closure == NULL) { + cairo_status_t status; + switch (errno) { + case ENOMEM: + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + break; + case ENOENT: + status = _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND); + break; + default: + status = _cairo_error (CAIRO_STATUS_READ_ERROR); + break; + } + return _cairo_surface_create_in_error (status); + } + + png_closure.read_func = stdio_read_func; + + surface = read_png (&png_closure); + + fclose (png_closure.closure); + + return surface; +} + +/** + * cairo_image_surface_create_from_png_stream: + * @read_func: function called to read the data of the file + * @closure: data to pass to @read_func. + * + * Creates a new image surface from PNG data read incrementally + * via the @read_func function. + * + * Return value: a new #cairo_surface_t initialized with the contents + * of the PNG file or a "nil" surface if the data read is not a valid PNG image + * or memory could not be allocated for the operation. A nil + * surface can be checked for with cairo_surface_status(surface) which + * may return one of the following values: + * + * %CAIRO_STATUS_NO_MEMORY + * %CAIRO_STATUS_READ_ERROR + * + * Alternatively, you can allow errors to propagate through the drawing + * operations and check the status on the context upon completion + * using cairo_status(). + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, + void *closure) +{ + struct png_read_closure_t png_closure; + + png_closure.read_func = read_func; + png_closure.closure = closure; + + return read_png (&png_closure); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-polygon-intersect.c b/Build/source/libs/cairo/cairo-src/src/cairo-polygon-intersect.c new file mode 100644 index 00000000000..8cb8fb1208b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-polygon-intersect.c @@ -0,0 +1,1471 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" +#include "cairo-combsort-inline.h" + + +typedef struct _cairo_bo_intersect_ordinate { + int32_t ordinate; + enum { EXCESS = -1, EXACT = 0, DEFAULT = 1 } approx; +} cairo_bo_intersect_ordinate_t; + +typedef struct _cairo_bo_intersect_point { + cairo_bo_intersect_ordinate_t x; + cairo_bo_intersect_ordinate_t y; +} cairo_bo_intersect_point_t; + +typedef struct _cairo_bo_edge cairo_bo_edge_t; + +typedef struct _cairo_bo_deferred { + cairo_bo_edge_t *other; + int32_t top; +} cairo_bo_deferred_t; + +struct _cairo_bo_edge { + int a_or_b; + cairo_edge_t edge; + cairo_bo_edge_t *prev; + cairo_bo_edge_t *next; + cairo_bo_deferred_t deferred; +}; + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef enum { + CAIRO_BO_EVENT_TYPE_STOP = -1, + CAIRO_BO_EVENT_TYPE_INTERSECTION, + CAIRO_BO_EVENT_TYPE_START +} cairo_bo_event_type_t; + +typedef struct _cairo_bo_event { + cairo_bo_event_type_t type; + cairo_bo_intersect_point_t point; +} cairo_bo_event_t; + +typedef struct _cairo_bo_start_event { + cairo_bo_event_type_t type; + cairo_bo_intersect_point_t point; + cairo_bo_edge_t edge; +} cairo_bo_start_event_t; + +typedef struct _cairo_bo_queue_event { + cairo_bo_event_type_t type; + cairo_bo_intersect_point_t point; + cairo_bo_edge_t *e1; + cairo_bo_edge_t *e2; +} cairo_bo_queue_event_t; + +typedef struct _pqueue { + int size, max_size; + + cairo_bo_event_t **elements; + cairo_bo_event_t *elements_embedded[1024]; +} pqueue_t; + +typedef struct _cairo_bo_event_queue { + cairo_freepool_t pool; + pqueue_t pqueue; + cairo_bo_event_t **start_events; +} cairo_bo_event_queue_t; + +typedef struct _cairo_bo_sweep_line { + cairo_bo_edge_t *head; + int32_t current_y; + cairo_bo_edge_t *current_edge; +} cairo_bo_sweep_line_t; + +static cairo_fixed_t +_line_compute_intersection_x_for_y (const cairo_line_t *line, + cairo_fixed_t y) +{ + cairo_fixed_t x, dy; + + if (y == line->p1.y) + return line->p1.x; + if (y == line->p2.y) + return line->p2.x; + + x = line->p1.x; + dy = line->p2.y - line->p1.y; + if (dy != 0) { + x += _cairo_fixed_mul_div_floor (y - line->p1.y, + line->p2.x - line->p1.x, + dy); + } + + return x; +} + +static inline int +_cairo_bo_point32_compare (cairo_bo_intersect_point_t const *a, + cairo_bo_intersect_point_t const *b) +{ + int cmp; + + cmp = a->y.ordinate - b->y.ordinate; + if (cmp) + return cmp; + + cmp = a->y.approx - b->y.approx; + if (cmp) + return cmp; + + return a->x.ordinate - b->x.ordinate; +} + +/* Compare the slope of a to the slope of b, returning 1, 0, -1 if the + * slope a is respectively greater than, equal to, or less than the + * slope of b. + * + * For each edge, consider the direction vector formed from: + * + * top -> bottom + * + * which is: + * + * (dx, dy) = (line.p2.x - line.p1.x, line.p2.y - line.p1.y) + * + * We then define the slope of each edge as dx/dy, (which is the + * inverse of the slope typically used in math instruction). We never + * compute a slope directly as the value approaches infinity, but we + * can derive a slope comparison without division as follows, (where + * the ? represents our compare operator). + * + * 1. slope(a) ? slope(b) + * 2. adx/ady ? bdx/bdy + * 3. (adx * bdy) ? (bdx * ady) + * + * Note that from step 2 to step 3 there is no change needed in the + * sign of the result since both ady and bdy are guaranteed to be + * greater than or equal to 0. + * + * When using this slope comparison to sort edges, some care is needed + * when interpreting the results. Since the slope compare operates on + * distance vectors from top to bottom it gives a correct left to + * right sort for edges that have a common top point, (such as two + * edges with start events at the same location). On the other hand, + * the sense of the result will be exactly reversed for two edges that + * have a common stop point. + */ +static inline int +_slope_compare (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t adx = a->edge.line.p2.x - a->edge.line.p1.x; + int32_t bdx = b->edge.line.p2.x - b->edge.line.p1.x; + + /* Since the dy's are all positive by construction we can fast + * path several common cases. + */ + + /* First check for vertical lines. */ + if (adx == 0) + return -bdx; + if (bdx == 0) + return adx; + + /* Then where the two edges point in different directions wrt x. */ + if ((adx ^ bdx) < 0) + return adx; + + /* Finally we actually need to do the general comparison. */ + { + int32_t ady = a->edge.line.p2.y - a->edge.line.p1.y; + int32_t bdy = b->edge.line.p2.y - b->edge.line.p1.y; + cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } +} + +/* + * We need to compare the x-coordinates of a pair of lines for a particular y, + * without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy + * - (Y - A_y) * A_dx * B_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 128 bit arithmetic. For certain, but common, + * input we can reduce this down to a single 32 bit compare by inspecting the + * deltas. + * + * (And put the burden of the work on developing fast 128 bit ops, which are + * required throughout the tessellator.) + * + * See the similar discussion for _slope_compare(). + */ +static int +edges_compare_x_for_y_general (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b, + int32_t y) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t dx; + int32_t adx, ady; + int32_t bdx, bdy; + enum { + HAVE_NONE = 0x0, + HAVE_DX = 0x1, + HAVE_ADX = 0x2, + HAVE_DX_ADX = HAVE_DX | HAVE_ADX, + HAVE_BDX = 0x4, + HAVE_DX_BDX = HAVE_DX | HAVE_BDX, + HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, + HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX + } have_dx_adx_bdx = HAVE_ALL; + + /* don't bother solving for abscissa if the edges' bounding boxes + * can be used to order them. */ + { + int32_t amin, amax; + int32_t bmin, bmax; + if (a->edge.line.p1.x < a->edge.line.p2.x) { + amin = a->edge.line.p1.x; + amax = a->edge.line.p2.x; + } else { + amin = a->edge.line.p2.x; + amax = a->edge.line.p1.x; + } + if (b->edge.line.p1.x < b->edge.line.p2.x) { + bmin = b->edge.line.p1.x; + bmax = b->edge.line.p2.x; + } else { + bmin = b->edge.line.p2.x; + bmax = b->edge.line.p1.x; + } + if (amax < bmin) return -1; + if (amin > bmax) return +1; + } + + ady = a->edge.line.p2.y - a->edge.line.p1.y; + adx = a->edge.line.p2.x - a->edge.line.p1.x; + if (adx == 0) + have_dx_adx_bdx &= ~HAVE_ADX; + + bdy = b->edge.line.p2.y - b->edge.line.p1.y; + bdx = b->edge.line.p2.x - b->edge.line.p1.x; + if (bdx == 0) + have_dx_adx_bdx &= ~HAVE_BDX; + + dx = a->edge.line.p1.x - b->edge.line.p1.x; + if (dx == 0) + have_dx_adx_bdx &= ~HAVE_DX; + +#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) +#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->edge.line.p1.y) +#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->edge.line.p1.y) + switch (have_dx_adx_bdx) { + default: + case HAVE_NONE: + return 0; + case HAVE_DX: + /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ + return dx; /* ady * bdy is positive definite */ + case HAVE_ADX: + /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ + return adx; /* bdy * (y - a->top.y) is positive definite */ + case HAVE_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy */ + return -bdx; /* ady * (y - b->top.y) is positive definite */ + case HAVE_ADX_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ + if ((adx ^ bdx) < 0) { + return adx; + } else if (a->edge.line.p1.y == b->edge.line.p1.y) { /* common origin */ + cairo_int64_t adx_bdy, bdx_ady; + + /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ + + adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } else + return _cairo_int128_cmp (A, B); + case HAVE_DX_ADX: + /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ + if ((-adx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t ady_dx, dy_adx; + + ady_dx = _cairo_int32x32_64_mul (ady, dx); + dy_adx = _cairo_int32x32_64_mul (a->edge.line.p1.y - y, adx); + + return _cairo_int64_cmp (ady_dx, dy_adx); + } + case HAVE_DX_BDX: + /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ + if ((bdx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t bdy_dx, dy_bdx; + + bdy_dx = _cairo_int32x32_64_mul (bdy, dx); + dy_bdx = _cairo_int32x32_64_mul (y - b->edge.line.p1.y, bdx); + + return _cairo_int64_cmp (bdy_dx, dy_bdx); + } + case HAVE_ALL: + /* XXX try comparing (a->edge.line.p2.x - b->edge.line.p2.x) et al */ + return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); + } +#undef B +#undef A +#undef L +} + +/* + * We need to compare the x-coordinate of a line for a particular y wrt to a + * given x, without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ X + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy (and (Y - A_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 64 bit arithmetic. + * + * See the similar discussion for _slope_compare() and + * edges_compare_x_for_y_general(). + */ +static int +edge_compare_for_y_against_x (const cairo_bo_edge_t *a, + int32_t y, + int32_t x) +{ + int32_t adx, ady; + int32_t dx, dy; + cairo_int64_t L, R; + + if (x < a->edge.line.p1.x && x < a->edge.line.p2.x) + return 1; + if (x > a->edge.line.p1.x && x > a->edge.line.p2.x) + return -1; + + adx = a->edge.line.p2.x - a->edge.line.p1.x; + dx = x - a->edge.line.p1.x; + + if (adx == 0) + return -dx; + if (dx == 0 || (adx ^ dx) < 0) + return adx; + + dy = y - a->edge.line.p1.y; + ady = a->edge.line.p2.y - a->edge.line.p1.y; + + L = _cairo_int32x32_64_mul (dy, adx); + R = _cairo_int32x32_64_mul (dx, ady); + + return _cairo_int64_cmp (L, R); +} + +static int +edges_compare_x_for_y (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b, + int32_t y) +{ + /* If the sweep-line is currently on an end-point of a line, + * then we know its precise x value (and considering that we often need to + * compare events at end-points, this happens frequently enough to warrant + * special casing). + */ + enum { + HAVE_NEITHER = 0x0, + HAVE_AX = 0x1, + HAVE_BX = 0x2, + HAVE_BOTH = HAVE_AX | HAVE_BX + } have_ax_bx = HAVE_BOTH; + int32_t ax, bx; + + if (y == a->edge.line.p1.y) + ax = a->edge.line.p1.x; + else if (y == a->edge.line.p2.y) + ax = a->edge.line.p2.x; + else + have_ax_bx &= ~HAVE_AX; + + if (y == b->edge.line.p1.y) + bx = b->edge.line.p1.x; + else if (y == b->edge.line.p2.y) + bx = b->edge.line.p2.x; + else + have_ax_bx &= ~HAVE_BX; + + switch (have_ax_bx) { + default: + case HAVE_NEITHER: + return edges_compare_x_for_y_general (a, b, y); + case HAVE_AX: + return -edge_compare_for_y_against_x (b, y, ax); + case HAVE_BX: + return edge_compare_for_y_against_x (a, y, bx); + case HAVE_BOTH: + return ax - bx; + } +} + +static inline int +_line_equal (const cairo_line_t *a, const cairo_line_t *b) +{ + return a->p1.x == b->p1.x && a->p1.y == b->p1.y && + a->p2.x == b->p2.x && a->p2.y == b->p2.y; +} + +static int +_cairo_bo_sweep_line_compare_edges (cairo_bo_sweep_line_t *sweep_line, + const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + int cmp; + + /* compare the edges if not identical */ + if (! _line_equal (&a->edge.line, &b->edge.line)) { + cmp = edges_compare_x_for_y (a, b, sweep_line->current_y); + if (cmp) + return cmp; + + /* The two edges intersect exactly at y, so fall back on slope + * comparison. We know that this compare_edges function will be + * called only when starting a new edge, (not when stopping an + * edge), so we don't have to worry about conditionally inverting + * the sense of _slope_compare. */ + cmp = _slope_compare (a, b); + if (cmp) + return cmp; + } + + /* We've got two collinear edges now. */ + return b->edge.bottom - a->edge.bottom; +} + +static inline cairo_int64_t +det32_64 (int32_t a, int32_t b, + int32_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), + _cairo_int32x32_64_mul (b, c)); +} + +static inline cairo_int128_t +det64x32_128 (cairo_int64_t a, int32_t b, + cairo_int64_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), + _cairo_int64x32_128_mul (c, b)); +} + +static inline cairo_bo_intersect_ordinate_t +round_to_nearest (cairo_quorem64_t d, + cairo_int64_t den) +{ + cairo_bo_intersect_ordinate_t ordinate; + int32_t quo = d.quo; + cairo_int64_t drem_2 = _cairo_int64_mul (d.rem, _cairo_int32_to_int64 (2)); + + /* assert (! _cairo_int64_negative (den));*/ + + if (_cairo_int64_lt (drem_2, _cairo_int64_negate (den))) { + quo -= 1; + drem_2 = _cairo_int64_negate (drem_2); + } else if (_cairo_int64_le (den, drem_2)) { + quo += 1; + drem_2 = _cairo_int64_negate (drem_2); + } + + ordinate.ordinate = quo; + ordinate.approx = _cairo_int64_is_zero (drem_2) ? EXACT : _cairo_int64_negative (drem_2) ? EXCESS : DEFAULT; + + return ordinate; +} + +/* Compute the intersection of two lines as defined by two edges. The + * result is provided as a coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or + * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. + */ +static cairo_bool_t +intersect_lines (cairo_bo_edge_t *a, + cairo_bo_edge_t *b, + cairo_bo_intersect_point_t *intersection) +{ + cairo_int64_t a_det, b_det; + + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm begins. + * What we're doing to mitigate this is to perform clamping in + * cairo_bo_tessellate_polygon(). + */ + int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; + int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; + + int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; + int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; + + cairo_int64_t den_det; + cairo_int64_t R; + cairo_quorem64_t qr; + + den_det = det32_64 (dx1, dy1, dx2, dy2); + + /* Q: Can we determine that the lines do not intersect (within range) + * much more cheaply than computing the intersection point i.e. by + * avoiding the division? + * + * X = ax + t * adx = bx + s * bdx; + * Y = ay + t * ady = by + s * bdy; + * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) + * => t * L = R + * + * Therefore we can reject any intersection (under the criteria for + * valid intersection events) if: + * L^R < 0 => t < 0, or + * L t > 1 + * + * (where top/bottom must at least extend to the line endpoints). + * + * A similar substitution can be performed for s, yielding: + * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) + */ + R = det32_64 (dx2, dy2, + b->edge.line.p1.x - a->edge.line.p1.x, + b->edge.line.p1.y - a->edge.line.p1.y); + if (_cairo_int64_le (den_det, R)) + return FALSE; + + R = det32_64 (dy1, dx1, + a->edge.line.p1.y - b->edge.line.p1.y, + a->edge.line.p1.x - b->edge.line.p1.x); + if (_cairo_int64_le (den_det, R)) + return FALSE; + + /* We now know that the two lines should intersect within range. */ + + a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, + a->edge.line.p2.x, a->edge.line.p2.y); + b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, + b->edge.line.p2.x, b->edge.line.p2.y); + + /* x = det (a_det, dx1, b_det, dx2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, + b_det, dx2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; + + intersection->x = round_to_nearest (qr, den_det); + + /* y = det (a_det, dy1, b_det, dy2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, + b_det, dy2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; + + intersection->y = round_to_nearest (qr, den_det); + + return TRUE; +} + +static int +_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t a, + int32_t b) +{ + /* First compare the quotient */ + if (a.ordinate > b) + return +1; + if (a.ordinate < b) + return -1; + + return a.approx; /* == EXCESS ? -1 : a.approx == EXACT ? 0 : 1;*/ +} + +/* Does the given edge contain the given point. The point must already + * be known to be contained within the line determined by the edge, + * (most likely the point results from an intersection of this edge + * with another). + * + * If we had exact arithmetic, then this function would simply be a + * matter of examining whether the y value of the point lies within + * the range of y values of the edge. But since intersection points + * are not exact due to being rounded to the nearest integer within + * the available precision, we must also examine the x value of the + * point. + * + * The definition of "contains" here is that the given intersection + * point will be seen by the sweep line after the start event for the + * given edge and before the stop event for the edge. See the comments + * in the implementation for more details. + */ +static cairo_bool_t +_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t *edge, + cairo_bo_intersect_point_t *point) +{ + return _cairo_bo_intersect_ordinate_32_compare (point->y, + edge->edge.bottom) < 0; +} + +/* Compute the intersection of two edges. The result is provided as a + * coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection + * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the + * intersection of the lines defined by the edges occurs outside of + * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges + * are exactly parallel. + * + * Note that when determining if a candidate intersection is "inside" + * an edge, we consider both the infinitesimal shortening and the + * infinitesimal tilt rules described by John Hobby. Specifically, if + * the intersection is exactly the same as an edge point, it is + * effectively outside (no intersection is returned). Also, if the + * intersection point has the same + */ +static cairo_bool_t +_cairo_bo_edge_intersect (cairo_bo_edge_t *a, + cairo_bo_edge_t *b, + cairo_bo_intersect_point_t *intersection) +{ + if (! intersect_lines (a, b, intersection)) + return FALSE; + + if (! _cairo_bo_edge_contains_intersect_point (a, intersection)) + return FALSE; + + if (! _cairo_bo_edge_contains_intersect_point (b, intersection)) + return FALSE; + + return TRUE; +} + +static inline int +cairo_bo_event_compare (const cairo_bo_event_t *a, + const cairo_bo_event_t *b) +{ + int cmp; + + cmp = _cairo_bo_point32_compare (&a->point, &b->point); + if (cmp) + return cmp; + + cmp = a->type - b->type; + if (cmp) + return cmp; + + return a < b ? -1 : a == b ? 0 : 1; +} + +static inline void +_pqueue_init (pqueue_t *pq) +{ + pq->max_size = ARRAY_LENGTH (pq->elements_embedded); + pq->size = 0; + + pq->elements = pq->elements_embedded; +} + +static inline void +_pqueue_fini (pqueue_t *pq) +{ + if (pq->elements != pq->elements_embedded) + free (pq->elements); +} + +static cairo_status_t +_pqueue_grow (pqueue_t *pq) +{ + cairo_bo_event_t **new_elements; + pq->max_size *= 2; + + if (pq->elements == pq->elements_embedded) { + new_elements = _cairo_malloc_ab (pq->max_size, + sizeof (cairo_bo_event_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (new_elements, pq->elements_embedded, + sizeof (pq->elements_embedded)); + } else { + new_elements = _cairo_realloc_ab (pq->elements, + pq->max_size, + sizeof (cairo_bo_event_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pq->elements = new_elements; + return CAIRO_STATUS_SUCCESS; +} + +static inline cairo_status_t +_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event) +{ + cairo_bo_event_t **elements; + int i, parent; + + if (unlikely (pq->size + 1 == pq->max_size)) { + cairo_status_t status; + + status = _pqueue_grow (pq); + if (unlikely (status)) + return status; + } + + elements = pq->elements; + + for (i = ++pq->size; + i != PQ_FIRST_ENTRY && + cairo_bo_event_compare (event, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = event; + + return CAIRO_STATUS_SUCCESS; +} + +static inline void +_pqueue_pop (pqueue_t *pq) +{ + cairo_bo_event_t **elements = pq->elements; + cairo_bo_event_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + cairo_bo_event_compare (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (cairo_bo_event_compare (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline cairo_status_t +_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, + cairo_bo_event_type_t type, + cairo_bo_edge_t *e1, + cairo_bo_edge_t *e2, + const cairo_bo_intersect_point_t *point) +{ + cairo_bo_queue_event_t *event; + + event = _cairo_freepool_alloc (&queue->pool); + if (unlikely (event == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event->type = type; + event->e1 = e1; + event->e2 = e2; + event->point = *point; + + return _pqueue_push (&queue->pqueue, (cairo_bo_event_t *) event); +} + +static void +_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue, + cairo_bo_event_t *event) +{ + _cairo_freepool_free (&queue->pool, event); +} + +static cairo_bo_event_t * +_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue) +{ + cairo_bo_event_t *event, *cmp; + + event = event_queue->pqueue.elements[PQ_FIRST_ENTRY]; + cmp = *event_queue->start_events; + if (event == NULL || + (cmp != NULL && cairo_bo_event_compare (cmp, event) < 0)) + { + event = cmp; + event_queue->start_events++; + } + else + { + _pqueue_pop (&event_queue->pqueue); + } + + return event; +} + +CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, + cairo_bo_event_t *, + cairo_bo_event_compare) + +static void +_cairo_bo_event_queue_init (cairo_bo_event_queue_t *event_queue, + cairo_bo_event_t **start_events, + int num_events) +{ + _cairo_bo_event_queue_sort (start_events, num_events); + start_events[num_events] = NULL; + + event_queue->start_events = start_events; + + _cairo_freepool_init (&event_queue->pool, + sizeof (cairo_bo_queue_event_t)); + _pqueue_init (&event_queue->pqueue); + event_queue->pqueue.elements[PQ_FIRST_ENTRY] = NULL; +} + +static cairo_status_t +event_queue_insert_stop (cairo_bo_event_queue_t *event_queue, + cairo_bo_edge_t *edge) +{ + cairo_bo_intersect_point_t point; + + point.y.ordinate = edge->edge.bottom; + point.y.approx = EXACT; + point.x.ordinate = _line_compute_intersection_x_for_y (&edge->edge.line, + point.y.ordinate); + point.x.approx = EXACT; + + return _cairo_bo_event_queue_insert (event_queue, + CAIRO_BO_EVENT_TYPE_STOP, + edge, NULL, + &point); +} + +static void +_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) +{ + _pqueue_fini (&event_queue->pqueue); + _cairo_freepool_fini (&event_queue->pool); +} + +static inline cairo_status_t +event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t *event_queue, + cairo_bo_edge_t *left, + cairo_bo_edge_t *right) +{ + cairo_bo_intersect_point_t intersection; + + if (_line_equal (&left->edge.line, &right->edge.line)) + return CAIRO_STATUS_SUCCESS; + + /* The names "left" and "right" here are correct descriptions of + * the order of the two edges within the active edge list. So if a + * slope comparison also puts left less than right, then we know + * that the intersection of these two segments has already + * occurred before the current sweep line position. */ + if (_slope_compare (left, right) <= 0) + return CAIRO_STATUS_SUCCESS; + + if (! _cairo_bo_edge_intersect (left, right, &intersection)) + return CAIRO_STATUS_SUCCESS; + + return _cairo_bo_event_queue_insert (event_queue, + CAIRO_BO_EVENT_TYPE_INTERSECTION, + left, right, + &intersection); +} + +static void +_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line) +{ + sweep_line->head = NULL; + sweep_line->current_y = INT32_MIN; + sweep_line->current_edge = NULL; +} + +static cairo_status_t +sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (sweep_line->current_edge != NULL) { + cairo_bo_edge_t *prev, *next; + int cmp; + + cmp = _cairo_bo_sweep_line_compare_edges (sweep_line, + sweep_line->current_edge, + edge); + if (cmp < 0) { + prev = sweep_line->current_edge; + next = prev->next; + while (next != NULL && + _cairo_bo_sweep_line_compare_edges (sweep_line, + next, edge) < 0) + { + prev = next, next = prev->next; + } + + prev->next = edge; + edge->prev = prev; + edge->next = next; + if (next != NULL) + next->prev = edge; + } else if (cmp > 0) { + next = sweep_line->current_edge; + prev = next->prev; + while (prev != NULL && + _cairo_bo_sweep_line_compare_edges (sweep_line, + prev, edge) > 0) + { + next = prev, prev = next->prev; + } + + next->prev = edge; + edge->next = next; + edge->prev = prev; + if (prev != NULL) + prev->next = edge; + else + sweep_line->head = edge; + } else { + prev = sweep_line->current_edge; + edge->prev = prev; + edge->next = prev->next; + if (prev->next != NULL) + prev->next->prev = edge; + prev->next = edge; + } + } else { + sweep_line->head = edge; + } + + sweep_line->current_edge = edge; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (edge->prev != NULL) + edge->prev->next = edge->next; + else + sweep_line->head = edge->next; + + if (edge->next != NULL) + edge->next->prev = edge->prev; + + if (sweep_line->current_edge == edge) + sweep_line->current_edge = edge->prev ? edge->prev : edge->next; +} + +static void +_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *left, + cairo_bo_edge_t *right) +{ + if (left->prev != NULL) + left->prev->next = right; + else + sweep_line->head = right; + + if (right->next != NULL) + right->next->prev = left; + + left->next = right->next; + right->next = left; + + right->prev = left->prev; + left->prev = right; +} + +static inline cairo_bool_t +edges_colinear (const cairo_bo_edge_t *a, const cairo_bo_edge_t *b) +{ + if (_line_equal (&a->edge.line, &b->edge.line)) + return TRUE; + + if (_slope_compare (a, b)) + return FALSE; + + /* The choice of y is not truly arbitrary since we must guarantee that it + * is greater than the start of either line. + */ + if (a->edge.line.p1.y == b->edge.line.p1.y) { + return a->edge.line.p1.x == b->edge.line.p1.x; + } else if (a->edge.line.p1.y < b->edge.line.p1.y) { + return edge_compare_for_y_against_x (b, + a->edge.line.p1.y, + a->edge.line.p1.x) == 0; + } else { + return edge_compare_for_y_against_x (a, + b->edge.line.p1.y, + b->edge.line.p1.x) == 0; + } +} + +static void +edges_end (cairo_bo_edge_t *left, + int32_t bot, + cairo_polygon_t *polygon) +{ + cairo_bo_deferred_t *l = &left->deferred; + cairo_bo_edge_t *right = l->other; + + assert(right->deferred.other == NULL); + if (likely (l->top < bot)) { + _cairo_polygon_add_line (polygon, &left->edge.line, l->top, bot, 1); + _cairo_polygon_add_line (polygon, &right->edge.line, l->top, bot, -1); + } + + l->other = NULL; +} + +static inline void +edges_start_or_continue (cairo_bo_edge_t *left, + cairo_bo_edge_t *right, + int top, + cairo_polygon_t *polygon) +{ + assert (right->deferred.other == NULL); + + if (left->deferred.other == right) + return; + + if (left->deferred.other != NULL) { + if (right != NULL && edges_colinear (left->deferred.other, right)) { + cairo_bo_edge_t *old = left->deferred.other; + + /* continuation on right, extend right to cover both */ + assert (old->deferred.other == NULL); + assert (old->edge.line.p2.y > old->edge.line.p1.y); + + if (old->edge.line.p1.y < right->edge.line.p1.y) + right->edge.line.p1 = old->edge.line.p1; + if (old->edge.line.p2.y > right->edge.line.p2.y) + right->edge.line.p2 = old->edge.line.p2; + left->deferred.other = right; + return; + } + + edges_end (left, top, polygon); + } + + if (right != NULL && ! edges_colinear (left, right)) { + left->deferred.top = top; + left->deferred.other = right; + } +} + +#define is_zero(w) ((w)[0] == 0 || (w)[1] == 0) + +static inline void +active_edges (cairo_bo_edge_t *left, + int32_t top, + cairo_polygon_t *polygon) +{ + cairo_bo_edge_t *right; + int winding[2] = {0, 0}; + + /* Yes, this is naive. Consider this a placeholder. */ + + while (left != NULL) { + assert (is_zero (winding)); + + do { + winding[left->a_or_b] += left->edge.dir; + if (! is_zero (winding)) + break; + + if unlikely ((left->deferred.other)) + edges_end (left, top, polygon); + + left = left->next; + if (! left) + return; + } while (1); + + right = left->next; + do { + if unlikely ((right->deferred.other)) + edges_end (right, top, polygon); + + winding[right->a_or_b] += right->edge.dir; + if (is_zero (winding)) { + if (right->next == NULL || + ! edges_colinear (right, right->next)) + break; + } + + right = right->next; + } while (1); + + edges_start_or_continue (left, right, top, polygon); + + left = right->next; + } +} + +static cairo_status_t +intersection_sweep (cairo_bo_event_t **start_events, + int num_events, + cairo_polygon_t *polygon) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; /* silence compiler */ + cairo_bo_event_queue_t event_queue; + cairo_bo_sweep_line_t sweep_line; + cairo_bo_event_t *event; + cairo_bo_edge_t *left, *right; + cairo_bo_edge_t *e1, *e2; + + _cairo_bo_event_queue_init (&event_queue, start_events, num_events); + _cairo_bo_sweep_line_init (&sweep_line); + + while ((event = _cairo_bo_event_dequeue (&event_queue))) { + if (event->point.y.ordinate != sweep_line.current_y) { + active_edges (sweep_line.head, + sweep_line.current_y, + polygon); + sweep_line.current_y = event->point.y.ordinate; + } + + switch (event->type) { + case CAIRO_BO_EVENT_TYPE_START: + e1 = &((cairo_bo_start_event_t *) event)->edge; + + status = sweep_line_insert (&sweep_line, e1); + if (unlikely (status)) + goto unwind; + + status = event_queue_insert_stop (&event_queue, e1); + if (unlikely (status)) + goto unwind; + + left = e1->prev; + right = e1->next; + + if (left != NULL) { + status = event_queue_insert_if_intersect_below_current_y (&event_queue, left, e1); + if (unlikely (status)) + goto unwind; + } + + if (right != NULL) { + status = event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); + if (unlikely (status)) + goto unwind; + } + + break; + + case CAIRO_BO_EVENT_TYPE_STOP: + e1 = ((cairo_bo_queue_event_t *) event)->e1; + _cairo_bo_event_queue_delete (&event_queue, event); + + if (e1->deferred.other) + edges_end (e1, sweep_line.current_y, polygon); + + left = e1->prev; + right = e1->next; + + _cairo_bo_sweep_line_delete (&sweep_line, e1); + + if (left != NULL && right != NULL) { + status = event_queue_insert_if_intersect_below_current_y (&event_queue, left, right); + if (unlikely (status)) + goto unwind; + } + + break; + + case CAIRO_BO_EVENT_TYPE_INTERSECTION: + e1 = ((cairo_bo_queue_event_t *) event)->e1; + e2 = ((cairo_bo_queue_event_t *) event)->e2; + _cairo_bo_event_queue_delete (&event_queue, event); + + /* skip this intersection if its edges are not adjacent */ + if (e2 != e1->next) + break; + + if (e1->deferred.other) + edges_end (e1, sweep_line.current_y, polygon); + if (e2->deferred.other) + edges_end (e2, sweep_line.current_y, polygon); + + left = e1->prev; + right = e2->next; + + _cairo_bo_sweep_line_swap (&sweep_line, e1, e2); + + /* after the swap e2 is left of e1 */ + + if (left != NULL) { + status = event_queue_insert_if_intersect_below_current_y (&event_queue, left, e2); + if (unlikely (status)) + goto unwind; + } + + if (right != NULL) { + status = event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); + if (unlikely (status)) + goto unwind; + } + + break; + } + } + + unwind: + _cairo_bo_event_queue_fini (&event_queue); + + return status; +} + +cairo_status_t +_cairo_polygon_intersect (cairo_polygon_t *a, int winding_a, + cairo_polygon_t *b, int winding_b) +{ + cairo_status_t status; + cairo_bo_start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_start_event_t)]; + cairo_bo_start_event_t *events; + cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; + cairo_bo_event_t **event_ptrs; + int num_events; + int i, j; + + /* XXX lazy */ + if (winding_a != CAIRO_FILL_RULE_WINDING) { + status = _cairo_polygon_reduce (a, winding_a); + if (unlikely (status)) + return status; + } + + if (winding_b != CAIRO_FILL_RULE_WINDING) { + status = _cairo_polygon_reduce (b, winding_b); + if (unlikely (status)) + return status; + } + + if (unlikely (0 == a->num_edges)) + return CAIRO_STATUS_SUCCESS; + + if (unlikely (0 == b->num_edges)) { + a->num_edges = 0; + return CAIRO_STATUS_SUCCESS; + } + + events = stack_events; + event_ptrs = stack_event_ptrs; + num_events = a->num_edges + b->num_edges; + if (num_events > ARRAY_LENGTH (stack_events)) { + events = _cairo_malloc_ab_plus_c (num_events, + sizeof (cairo_bo_start_event_t) + + sizeof (cairo_bo_event_t *), + sizeof (cairo_bo_event_t *)); + if (unlikely (events == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event_ptrs = (cairo_bo_event_t **) (events + num_events); + } + + j = 0; + for (i = 0; i < a->num_edges; i++) { + event_ptrs[j] = (cairo_bo_event_t *) &events[j]; + + events[j].type = CAIRO_BO_EVENT_TYPE_START; + events[j].point.y.ordinate = a->edges[i].top; + events[j].point.y.approx = EXACT; + events[j].point.x.ordinate = + _line_compute_intersection_x_for_y (&a->edges[i].line, + events[j].point.y.ordinate); + events[j].point.x.approx = EXACT; + + events[j].edge.a_or_b = 0; + events[j].edge.edge = a->edges[i]; + events[j].edge.deferred.other = NULL; + events[j].edge.prev = NULL; + events[j].edge.next = NULL; + j++; + } + + for (i = 0; i < b->num_edges; i++) { + event_ptrs[j] = (cairo_bo_event_t *) &events[j]; + + events[j].type = CAIRO_BO_EVENT_TYPE_START; + events[j].point.y.ordinate = b->edges[i].top; + events[j].point.y.approx = EXACT; + events[j].point.x.ordinate = + _line_compute_intersection_x_for_y (&b->edges[i].line, + events[j].point.y.ordinate); + events[j].point.x.approx = EXACT; + + events[j].edge.a_or_b = 1; + events[j].edge.edge = b->edges[i]; + events[j].edge.deferred.other = NULL; + events[j].edge.prev = NULL; + events[j].edge.next = NULL; + j++; + } + assert (j == num_events); + +#if 0 + { + FILE *file = fopen ("clip_a.txt", "w"); + _cairo_debug_print_polygon (file, a); + fclose (file); + } + { + FILE *file = fopen ("clip_b.txt", "w"); + _cairo_debug_print_polygon (file, b); + fclose (file); + } +#endif + + a->num_edges = 0; + status = intersection_sweep (event_ptrs, num_events, a); + if (events != stack_events) + free (events); + +#if 0 + { + FILE *file = fopen ("clip_result.txt", "w"); + _cairo_debug_print_polygon (file, a); + fclose (file); + } +#endif + + return status; +} + +cairo_status_t +_cairo_polygon_intersect_with_boxes (cairo_polygon_t *polygon, + cairo_fill_rule_t *winding, + cairo_box_t *boxes, + int num_boxes) +{ + cairo_polygon_t b; + cairo_status_t status; + int n; + + if (num_boxes == 0) { + polygon->num_edges = 0; + return CAIRO_STATUS_SUCCESS; + } + + for (n = 0; n < num_boxes; n++) { + if (polygon->extents.p1.x >= boxes[n].p1.x && + polygon->extents.p2.x <= boxes[n].p2.x && + polygon->extents.p1.y >= boxes[n].p1.y && + polygon->extents.p2.y <= boxes[n].p2.y) + { + return CAIRO_STATUS_SUCCESS; + } + } + + _cairo_polygon_init (&b, NULL, 0); + for (n = 0; n < num_boxes; n++) { + if (boxes[n].p2.x > polygon->extents.p1.x && + boxes[n].p1.x < polygon->extents.p2.x && + boxes[n].p2.y > polygon->extents.p1.y && + boxes[n].p1.y < polygon->extents.p2.y) + { + cairo_point_t p1, p2; + + p1.y = boxes[n].p1.y; + p2.y = boxes[n].p2.y; + + p2.x = p1.x = boxes[n].p1.x; + _cairo_polygon_add_external_edge (&b, &p1, &p2); + + p2.x = p1.x = boxes[n].p2.x; + _cairo_polygon_add_external_edge (&b, &p2, &p1); + } + } + + status = _cairo_polygon_intersect (polygon, *winding, + &b, CAIRO_FILL_RULE_WINDING); + _cairo_polygon_fini (&b); + + *winding = CAIRO_FILL_RULE_WINDING; + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-polygon-reduce.c b/Build/source/libs/cairo/cairo-src/src/cairo-polygon-reduce.c new file mode 100644 index 00000000000..ea457fe4edf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-polygon-reduce.c @@ -0,0 +1,1438 @@ +/* + * Copyright © 2004 Carl Worth + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Carl Worth + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +/* Provide definitions for standalone compilation */ +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" +#include "cairo-combsort-inline.h" + +#define DEBUG_POLYGON 0 + +typedef cairo_point_t cairo_bo_point32_t; + +typedef struct _cairo_bo_intersect_ordinate { + int32_t ordinate; + enum { EXACT, INEXACT } exactness; +} cairo_bo_intersect_ordinate_t; + +typedef struct _cairo_bo_intersect_point { + cairo_bo_intersect_ordinate_t x; + cairo_bo_intersect_ordinate_t y; +} cairo_bo_intersect_point_t; + +typedef struct _cairo_bo_edge cairo_bo_edge_t; + +typedef struct _cairo_bo_deferred { + cairo_bo_edge_t *right; + int32_t top; +} cairo_bo_deferred_t; + +struct _cairo_bo_edge { + cairo_edge_t edge; + cairo_bo_edge_t *prev; + cairo_bo_edge_t *next; + cairo_bo_deferred_t deferred; +}; + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef enum { + CAIRO_BO_EVENT_TYPE_STOP, + CAIRO_BO_EVENT_TYPE_INTERSECTION, + CAIRO_BO_EVENT_TYPE_START +} cairo_bo_event_type_t; + +typedef struct _cairo_bo_event { + cairo_bo_event_type_t type; + cairo_point_t point; +} cairo_bo_event_t; + +typedef struct _cairo_bo_start_event { + cairo_bo_event_type_t type; + cairo_point_t point; + cairo_bo_edge_t edge; +} cairo_bo_start_event_t; + +typedef struct _cairo_bo_queue_event { + cairo_bo_event_type_t type; + cairo_point_t point; + cairo_bo_edge_t *e1; + cairo_bo_edge_t *e2; +} cairo_bo_queue_event_t; + +typedef struct _pqueue { + int size, max_size; + + cairo_bo_event_t **elements; + cairo_bo_event_t *elements_embedded[1024]; +} pqueue_t; + +typedef struct _cairo_bo_event_queue { + cairo_freepool_t pool; + pqueue_t pqueue; + cairo_bo_event_t **start_events; +} cairo_bo_event_queue_t; + +typedef struct _cairo_bo_sweep_line { + cairo_bo_edge_t *head; + int32_t current_y; + cairo_bo_edge_t *current_edge; +} cairo_bo_sweep_line_t; + +static cairo_fixed_t +_line_compute_intersection_x_for_y (const cairo_line_t *line, + cairo_fixed_t y) +{ + cairo_fixed_t x, dy; + + if (y == line->p1.y) + return line->p1.x; + if (y == line->p2.y) + return line->p2.x; + + x = line->p1.x; + dy = line->p2.y - line->p1.y; + if (dy != 0) { + x += _cairo_fixed_mul_div_floor (y - line->p1.y, + line->p2.x - line->p1.x, + dy); + } + + return x; +} + +static inline int +_cairo_bo_point32_compare (cairo_bo_point32_t const *a, + cairo_bo_point32_t const *b) +{ + int cmp; + + cmp = a->y - b->y; + if (cmp) + return cmp; + + return a->x - b->x; +} + +/* Compare the slope of a to the slope of b, returning 1, 0, -1 if the + * slope a is respectively greater than, equal to, or less than the + * slope of b. + * + * For each edge, consider the direction vector formed from: + * + * top -> bottom + * + * which is: + * + * (dx, dy) = (line.p2.x - line.p1.x, line.p2.y - line.p1.y) + * + * We then define the slope of each edge as dx/dy, (which is the + * inverse of the slope typically used in math instruction). We never + * compute a slope directly as the value approaches infinity, but we + * can derive a slope comparison without division as follows, (where + * the ? represents our compare operator). + * + * 1. slope(a) ? slope(b) + * 2. adx/ady ? bdx/bdy + * 3. (adx * bdy) ? (bdx * ady) + * + * Note that from step 2 to step 3 there is no change needed in the + * sign of the result since both ady and bdy are guaranteed to be + * greater than or equal to 0. + * + * When using this slope comparison to sort edges, some care is needed + * when interpreting the results. Since the slope compare operates on + * distance vectors from top to bottom it gives a correct left to + * right sort for edges that have a common top point, (such as two + * edges with start events at the same location). On the other hand, + * the sense of the result will be exactly reversed for two edges that + * have a common stop point. + */ +static inline int +_slope_compare (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t adx = a->edge.line.p2.x - a->edge.line.p1.x; + int32_t bdx = b->edge.line.p2.x - b->edge.line.p1.x; + + /* Since the dy's are all positive by construction we can fast + * path several common cases. + */ + + /* First check for vertical lines. */ + if (adx == 0) + return -bdx; + if (bdx == 0) + return adx; + + /* Then where the two edges point in different directions wrt x. */ + if ((adx ^ bdx) < 0) + return adx; + + /* Finally we actually need to do the general comparison. */ + { + int32_t ady = a->edge.line.p2.y - a->edge.line.p1.y; + int32_t bdy = b->edge.line.p2.y - b->edge.line.p1.y; + cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } +} + +/* + * We need to compare the x-coordinates of a pair of lines for a particular y, + * without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ B_x + (Y - B_y) * B_dx / B_dy, + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy and B_dy (and (Y - A_y), (Y - B_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * A_dy * B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx * A_dy + * - (Y - A_y) * A_dx * B_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 128 bit arithmetic. For certain, but common, + * input we can reduce this down to a single 32 bit compare by inspecting the + * deltas. + * + * (And put the burden of the work on developing fast 128 bit ops, which are + * required throughout the tessellator.) + * + * See the similar discussion for _slope_compare(). + */ +static int +edges_compare_x_for_y_general (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b, + int32_t y) +{ + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm + * begins. + */ + int32_t dx; + int32_t adx, ady; + int32_t bdx, bdy; + enum { + HAVE_NONE = 0x0, + HAVE_DX = 0x1, + HAVE_ADX = 0x2, + HAVE_DX_ADX = HAVE_DX | HAVE_ADX, + HAVE_BDX = 0x4, + HAVE_DX_BDX = HAVE_DX | HAVE_BDX, + HAVE_ADX_BDX = HAVE_ADX | HAVE_BDX, + HAVE_ALL = HAVE_DX | HAVE_ADX | HAVE_BDX + } have_dx_adx_bdx = HAVE_ALL; + + /* don't bother solving for abscissa if the edges' bounding boxes + * can be used to order them. */ + { + int32_t amin, amax; + int32_t bmin, bmax; + if (a->edge.line.p1.x < a->edge.line.p2.x) { + amin = a->edge.line.p1.x; + amax = a->edge.line.p2.x; + } else { + amin = a->edge.line.p2.x; + amax = a->edge.line.p1.x; + } + if (b->edge.line.p1.x < b->edge.line.p2.x) { + bmin = b->edge.line.p1.x; + bmax = b->edge.line.p2.x; + } else { + bmin = b->edge.line.p2.x; + bmax = b->edge.line.p1.x; + } + if (amax < bmin) return -1; + if (amin > bmax) return +1; + } + + ady = a->edge.line.p2.y - a->edge.line.p1.y; + adx = a->edge.line.p2.x - a->edge.line.p1.x; + if (adx == 0) + have_dx_adx_bdx &= ~HAVE_ADX; + + bdy = b->edge.line.p2.y - b->edge.line.p1.y; + bdx = b->edge.line.p2.x - b->edge.line.p1.x; + if (bdx == 0) + have_dx_adx_bdx &= ~HAVE_BDX; + + dx = a->edge.line.p1.x - b->edge.line.p1.x; + if (dx == 0) + have_dx_adx_bdx &= ~HAVE_DX; + +#define L _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (ady, bdy), dx) +#define A _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (adx, bdy), y - a->edge.line.p1.y) +#define B _cairo_int64x32_128_mul (_cairo_int32x32_64_mul (bdx, ady), y - b->edge.line.p1.y) + switch (have_dx_adx_bdx) { + default: + case HAVE_NONE: + return 0; + case HAVE_DX: + /* A_dy * B_dy * (A_x - B_x) ∘ 0 */ + return dx; /* ady * bdy is positive definite */ + case HAVE_ADX: + /* 0 ∘ - (Y - A_y) * A_dx * B_dy */ + return adx; /* bdy * (y - a->top.y) is positive definite */ + case HAVE_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy */ + return -bdx; /* ady * (y - b->top.y) is positive definite */ + case HAVE_ADX_BDX: + /* 0 ∘ (Y - B_y) * B_dx * A_dy - (Y - A_y) * A_dx * B_dy */ + if ((adx ^ bdx) < 0) { + return adx; + } else if (a->edge.line.p1.y == b->edge.line.p1.y) { /* common origin */ + cairo_int64_t adx_bdy, bdx_ady; + + /* ∴ A_dx * B_dy ∘ B_dx * A_dy */ + + adx_bdy = _cairo_int32x32_64_mul (adx, bdy); + bdx_ady = _cairo_int32x32_64_mul (bdx, ady); + + return _cairo_int64_cmp (adx_bdy, bdx_ady); + } else + return _cairo_int128_cmp (A, B); + case HAVE_DX_ADX: + /* A_dy * (A_x - B_x) ∘ - (Y - A_y) * A_dx */ + if ((-adx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t ady_dx, dy_adx; + + ady_dx = _cairo_int32x32_64_mul (ady, dx); + dy_adx = _cairo_int32x32_64_mul (a->edge.line.p1.y - y, adx); + + return _cairo_int64_cmp (ady_dx, dy_adx); + } + case HAVE_DX_BDX: + /* B_dy * (A_x - B_x) ∘ (Y - B_y) * B_dx */ + if ((bdx ^ dx) < 0) { + return dx; + } else { + cairo_int64_t bdy_dx, dy_bdx; + + bdy_dx = _cairo_int32x32_64_mul (bdy, dx); + dy_bdx = _cairo_int32x32_64_mul (y - b->edge.line.p1.y, bdx); + + return _cairo_int64_cmp (bdy_dx, dy_bdx); + } + case HAVE_ALL: + /* XXX try comparing (a->edge.line.p2.x - b->edge.line.p2.x) et al */ + return _cairo_int128_cmp (L, _cairo_int128_sub (B, A)); + } +#undef B +#undef A +#undef L +} + +/* + * We need to compare the x-coordinate of a line for a particular y wrt to a + * given x, without loss of precision. + * + * The x-coordinate along an edge for a given y is: + * X = A_x + (Y - A_y) * A_dx / A_dy + * + * So the inequality we wish to test is: + * A_x + (Y - A_y) * A_dx / A_dy ∘ X + * where ∘ is our inequality operator. + * + * By construction, we know that A_dy (and (Y - A_y)) are + * all positive, so we can rearrange it thus without causing a sign change: + * (Y - A_y) * A_dx ∘ (X - A_x) * A_dy + * + * Given the assumption that all the deltas fit within 32 bits, we can compute + * this comparison directly using 64 bit arithmetic. + * + * See the similar discussion for _slope_compare() and + * edges_compare_x_for_y_general(). + */ +static int +edge_compare_for_y_against_x (const cairo_bo_edge_t *a, + int32_t y, + int32_t x) +{ + int32_t adx, ady; + int32_t dx, dy; + cairo_int64_t L, R; + + if (x < a->edge.line.p1.x && x < a->edge.line.p2.x) + return 1; + if (x > a->edge.line.p1.x && x > a->edge.line.p2.x) + return -1; + + adx = a->edge.line.p2.x - a->edge.line.p1.x; + dx = x - a->edge.line.p1.x; + + if (adx == 0) + return -dx; + if (dx == 0 || (adx ^ dx) < 0) + return adx; + + dy = y - a->edge.line.p1.y; + ady = a->edge.line.p2.y - a->edge.line.p1.y; + + L = _cairo_int32x32_64_mul (dy, adx); + R = _cairo_int32x32_64_mul (dx, ady); + + return _cairo_int64_cmp (L, R); +} + +static int +edges_compare_x_for_y (const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b, + int32_t y) +{ + /* If the sweep-line is currently on an end-point of a line, + * then we know its precise x value (and considering that we often need to + * compare events at end-points, this happens frequently enough to warrant + * special casing). + */ + enum { + HAVE_NEITHER = 0x0, + HAVE_AX = 0x1, + HAVE_BX = 0x2, + HAVE_BOTH = HAVE_AX | HAVE_BX + } have_ax_bx = HAVE_BOTH; + int32_t ax, bx; + + if (y == a->edge.line.p1.y) + ax = a->edge.line.p1.x; + else if (y == a->edge.line.p2.y) + ax = a->edge.line.p2.x; + else + have_ax_bx &= ~HAVE_AX; + + if (y == b->edge.line.p1.y) + bx = b->edge.line.p1.x; + else if (y == b->edge.line.p2.y) + bx = b->edge.line.p2.x; + else + have_ax_bx &= ~HAVE_BX; + + switch (have_ax_bx) { + default: + case HAVE_NEITHER: + return edges_compare_x_for_y_general (a, b, y); + case HAVE_AX: + return -edge_compare_for_y_against_x (b, y, ax); + case HAVE_BX: + return edge_compare_for_y_against_x (a, y, bx); + case HAVE_BOTH: + return ax - bx; + } +} + +static inline int +_line_equal (const cairo_line_t *a, const cairo_line_t *b) +{ + return (a->p1.x == b->p1.x && a->p1.y == b->p1.y && + a->p2.x == b->p2.x && a->p2.y == b->p2.y); +} + +static int +_cairo_bo_sweep_line_compare_edges (cairo_bo_sweep_line_t *sweep_line, + const cairo_bo_edge_t *a, + const cairo_bo_edge_t *b) +{ + int cmp; + + /* compare the edges if not identical */ + if (! _line_equal (&a->edge.line, &b->edge.line)) { + cmp = edges_compare_x_for_y (a, b, sweep_line->current_y); + if (cmp) + return cmp; + + /* The two edges intersect exactly at y, so fall back on slope + * comparison. We know that this compare_edges function will be + * called only when starting a new edge, (not when stopping an + * edge), so we don't have to worry about conditionally inverting + * the sense of _slope_compare. */ + cmp = _slope_compare (a, b); + if (cmp) + return cmp; + } + + /* We've got two collinear edges now. */ + return b->edge.bottom - a->edge.bottom; +} + +static inline cairo_int64_t +det32_64 (int32_t a, int32_t b, + int32_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int64_sub (_cairo_int32x32_64_mul (a, d), + _cairo_int32x32_64_mul (b, c)); +} + +static inline cairo_int128_t +det64x32_128 (cairo_int64_t a, int32_t b, + cairo_int64_t c, int32_t d) +{ + /* det = a * d - b * c */ + return _cairo_int128_sub (_cairo_int64x32_128_mul (a, d), + _cairo_int64x32_128_mul (c, b)); +} + +/* Compute the intersection of two lines as defined by two edges. The + * result is provided as a coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or + * %CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel. + */ +static cairo_bool_t +intersect_lines (cairo_bo_edge_t *a, + cairo_bo_edge_t *b, + cairo_bo_intersect_point_t *intersection) +{ + cairo_int64_t a_det, b_det; + + /* XXX: We're assuming here that dx and dy will still fit in 32 + * bits. That's not true in general as there could be overflow. We + * should prevent that before the tessellation algorithm begins. + * What we're doing to mitigate this is to perform clamping in + * cairo_bo_tessellate_polygon(). + */ + int32_t dx1 = a->edge.line.p1.x - a->edge.line.p2.x; + int32_t dy1 = a->edge.line.p1.y - a->edge.line.p2.y; + + int32_t dx2 = b->edge.line.p1.x - b->edge.line.p2.x; + int32_t dy2 = b->edge.line.p1.y - b->edge.line.p2.y; + + cairo_int64_t den_det; + cairo_int64_t R; + cairo_quorem64_t qr; + + den_det = det32_64 (dx1, dy1, dx2, dy2); + + /* Q: Can we determine that the lines do not intersect (within range) + * much more cheaply than computing the intersection point i.e. by + * avoiding the division? + * + * X = ax + t * adx = bx + s * bdx; + * Y = ay + t * ady = by + s * bdy; + * ∴ t * (ady*bdx - bdy*adx) = bdx * (by - ay) + bdy * (ax - bx) + * => t * L = R + * + * Therefore we can reject any intersection (under the criteria for + * valid intersection events) if: + * L^R < 0 => t < 0, or + * L t > 1 + * + * (where top/bottom must at least extend to the line endpoints). + * + * A similar substitution can be performed for s, yielding: + * s * (ady*bdx - bdy*adx) = ady * (ax - bx) - adx * (ay - by) + */ + R = det32_64 (dx2, dy2, + b->edge.line.p1.x - a->edge.line.p1.x, + b->edge.line.p1.y - a->edge.line.p1.y); + if (_cairo_int64_negative (den_det)) { + if (_cairo_int64_ge (den_det, R)) + return FALSE; + } else { + if (_cairo_int64_le (den_det, R)) + return FALSE; + } + + R = det32_64 (dy1, dx1, + a->edge.line.p1.y - b->edge.line.p1.y, + a->edge.line.p1.x - b->edge.line.p1.x); + if (_cairo_int64_negative (den_det)) { + if (_cairo_int64_ge (den_det, R)) + return FALSE; + } else { + if (_cairo_int64_le (den_det, R)) + return FALSE; + } + + /* We now know that the two lines should intersect within range. */ + + a_det = det32_64 (a->edge.line.p1.x, a->edge.line.p1.y, + a->edge.line.p2.x, a->edge.line.p2.y); + b_det = det32_64 (b->edge.line.p1.x, b->edge.line.p1.y, + b->edge.line.p2.x, b->edge.line.p2.y); + + /* x = det (a_det, dx1, b_det, dx2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1, + b_det, dx2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; +#if 0 + intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; +#else + intersection->x.exactness = EXACT; + if (! _cairo_int64_is_zero (qr.rem)) { + if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) + qr.rem = _cairo_int64_negate (qr.rem); + qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); + if (_cairo_int64_ge (qr.rem, den_det)) { + qr.quo = _cairo_int64_add (qr.quo, + _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); + } else + intersection->x.exactness = INEXACT; + } +#endif + intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo); + + /* y = det (a_det, dy1, b_det, dy2) / den_det */ + qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1, + b_det, dy2), + den_det); + if (_cairo_int64_eq (qr.rem, den_det)) + return FALSE; +#if 0 + intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT; +#else + intersection->y.exactness = EXACT; + if (! _cairo_int64_is_zero (qr.rem)) { + if (_cairo_int64_negative (den_det) ^ _cairo_int64_negative (qr.rem)) + qr.rem = _cairo_int64_negate (qr.rem); + qr.rem = _cairo_int64_mul (qr.rem, _cairo_int32_to_int64 (2)); + if (_cairo_int64_ge (qr.rem, den_det)) { + qr.quo = _cairo_int64_add (qr.quo, + _cairo_int32_to_int64 (_cairo_int64_negative (qr.quo) ? -1 : 1)); + } else + intersection->y.exactness = INEXACT; + } +#endif + intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo); + + return TRUE; +} + +static int +_cairo_bo_intersect_ordinate_32_compare (cairo_bo_intersect_ordinate_t a, + int32_t b) +{ + /* First compare the quotient */ + if (a.ordinate > b) + return +1; + if (a.ordinate < b) + return -1; + /* With quotient identical, if remainder is 0 then compare equal */ + /* Otherwise, the non-zero remainder makes a > b */ + return INEXACT == a.exactness; +} + +/* Does the given edge contain the given point. The point must already + * be known to be contained within the line determined by the edge, + * (most likely the point results from an intersection of this edge + * with another). + * + * If we had exact arithmetic, then this function would simply be a + * matter of examining whether the y value of the point lies within + * the range of y values of the edge. But since intersection points + * are not exact due to being rounded to the nearest integer within + * the available precision, we must also examine the x value of the + * point. + * + * The definition of "contains" here is that the given intersection + * point will be seen by the sweep line after the start event for the + * given edge and before the stop event for the edge. See the comments + * in the implementation for more details. + */ +static cairo_bool_t +_cairo_bo_edge_contains_intersect_point (cairo_bo_edge_t *edge, + cairo_bo_intersect_point_t *point) +{ + int cmp_top, cmp_bottom; + + /* XXX: When running the actual algorithm, we don't actually need to + * compare against edge->top at all here, since any intersection above + * top is eliminated early via a slope comparison. We're leaving these + * here for now only for the sake of the quadratic-time intersection + * finder which needs them. + */ + + cmp_top = _cairo_bo_intersect_ordinate_32_compare (point->y, + edge->edge.top); + cmp_bottom = _cairo_bo_intersect_ordinate_32_compare (point->y, + edge->edge.bottom); + + if (cmp_top < 0 || cmp_bottom > 0) + { + return FALSE; + } + + if (cmp_top > 0 && cmp_bottom < 0) + { + return TRUE; + } + + /* At this stage, the point lies on the same y value as either + * edge->top or edge->bottom, so we have to examine the x value in + * order to properly determine containment. */ + + /* If the y value of the point is the same as the y value of the + * top of the edge, then the x value of the point must be greater + * to be considered as inside the edge. Similarly, if the y value + * of the point is the same as the y value of the bottom of the + * edge, then the x value of the point must be less to be + * considered as inside. */ + + if (cmp_top == 0) { + cairo_fixed_t top_x; + + top_x = _line_compute_intersection_x_for_y (&edge->edge.line, + edge->edge.top); + return _cairo_bo_intersect_ordinate_32_compare (point->x, top_x) > 0; + } else { /* cmp_bottom == 0 */ + cairo_fixed_t bot_x; + + bot_x = _line_compute_intersection_x_for_y (&edge->edge.line, + edge->edge.bottom); + return _cairo_bo_intersect_ordinate_32_compare (point->x, bot_x) < 0; + } +} + +/* Compute the intersection of two edges. The result is provided as a + * coordinate pair of 128-bit integers. + * + * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection + * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the + * intersection of the lines defined by the edges occurs outside of + * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges + * are exactly parallel. + * + * Note that when determining if a candidate intersection is "inside" + * an edge, we consider both the infinitesimal shortening and the + * infinitesimal tilt rules described by John Hobby. Specifically, if + * the intersection is exactly the same as an edge point, it is + * effectively outside (no intersection is returned). Also, if the + * intersection point has the same + */ +static cairo_bool_t +_cairo_bo_edge_intersect (cairo_bo_edge_t *a, + cairo_bo_edge_t *b, + cairo_bo_point32_t *intersection) +{ + cairo_bo_intersect_point_t quorem; + + if (! intersect_lines (a, b, &quorem)) + return FALSE; + + if (! _cairo_bo_edge_contains_intersect_point (a, &quorem)) + return FALSE; + + if (! _cairo_bo_edge_contains_intersect_point (b, &quorem)) + return FALSE; + + /* Now that we've correctly compared the intersection point and + * determined that it lies within the edge, then we know that we + * no longer need any more bits of storage for the intersection + * than we do for our edge coordinates. We also no longer need the + * remainder from the division. */ + intersection->x = quorem.x.ordinate; + intersection->y = quorem.y.ordinate; + + return TRUE; +} + +static inline int +cairo_bo_event_compare (const cairo_bo_event_t *a, + const cairo_bo_event_t *b) +{ + int cmp; + + cmp = _cairo_bo_point32_compare (&a->point, &b->point); + if (cmp) + return cmp; + + cmp = a->type - b->type; + if (cmp) + return cmp; + + return a - b; +} + +static inline void +_pqueue_init (pqueue_t *pq) +{ + pq->max_size = ARRAY_LENGTH (pq->elements_embedded); + pq->size = 0; + + pq->elements = pq->elements_embedded; +} + +static inline void +_pqueue_fini (pqueue_t *pq) +{ + if (pq->elements != pq->elements_embedded) + free (pq->elements); +} + +static cairo_status_t +_pqueue_grow (pqueue_t *pq) +{ + cairo_bo_event_t **new_elements; + pq->max_size *= 2; + + if (pq->elements == pq->elements_embedded) { + new_elements = _cairo_malloc_ab (pq->max_size, + sizeof (cairo_bo_event_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (new_elements, pq->elements_embedded, + sizeof (pq->elements_embedded)); + } else { + new_elements = _cairo_realloc_ab (pq->elements, + pq->max_size, + sizeof (cairo_bo_event_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pq->elements = new_elements; + return CAIRO_STATUS_SUCCESS; +} + +static inline cairo_status_t +_pqueue_push (pqueue_t *pq, cairo_bo_event_t *event) +{ + cairo_bo_event_t **elements; + int i, parent; + + if (unlikely (pq->size + 1 == pq->max_size)) { + cairo_status_t status; + + status = _pqueue_grow (pq); + if (unlikely (status)) + return status; + } + + elements = pq->elements; + + for (i = ++pq->size; + i != PQ_FIRST_ENTRY && + cairo_bo_event_compare (event, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = event; + + return CAIRO_STATUS_SUCCESS; +} + +static inline void +_pqueue_pop (pqueue_t *pq) +{ + cairo_bo_event_t **elements = pq->elements; + cairo_bo_event_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + cairo_bo_event_compare (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (cairo_bo_event_compare (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline cairo_status_t +_cairo_bo_event_queue_insert (cairo_bo_event_queue_t *queue, + cairo_bo_event_type_t type, + cairo_bo_edge_t *e1, + cairo_bo_edge_t *e2, + const cairo_point_t *point) +{ + cairo_bo_queue_event_t *event; + + event = _cairo_freepool_alloc (&queue->pool); + if (unlikely (event == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event->type = type; + event->e1 = e1; + event->e2 = e2; + event->point = *point; + + return _pqueue_push (&queue->pqueue, (cairo_bo_event_t *) event); +} + +static void +_cairo_bo_event_queue_delete (cairo_bo_event_queue_t *queue, + cairo_bo_event_t *event) +{ + _cairo_freepool_free (&queue->pool, event); +} + +static cairo_bo_event_t * +_cairo_bo_event_dequeue (cairo_bo_event_queue_t *event_queue) +{ + cairo_bo_event_t *event, *cmp; + + event = event_queue->pqueue.elements[PQ_FIRST_ENTRY]; + cmp = *event_queue->start_events; + if (event == NULL || + (cmp != NULL && cairo_bo_event_compare (cmp, event) < 0)) + { + event = cmp; + event_queue->start_events++; + } + else + { + _pqueue_pop (&event_queue->pqueue); + } + + return event; +} + +CAIRO_COMBSORT_DECLARE (_cairo_bo_event_queue_sort, + cairo_bo_event_t *, + cairo_bo_event_compare) + +static void +_cairo_bo_event_queue_init (cairo_bo_event_queue_t *event_queue, + cairo_bo_event_t **start_events, + int num_events) +{ + _cairo_bo_event_queue_sort (start_events, num_events); + start_events[num_events] = NULL; + + event_queue->start_events = start_events; + + _cairo_freepool_init (&event_queue->pool, + sizeof (cairo_bo_queue_event_t)); + _pqueue_init (&event_queue->pqueue); + event_queue->pqueue.elements[PQ_FIRST_ENTRY] = NULL; +} + +static cairo_status_t +_cairo_bo_event_queue_insert_stop (cairo_bo_event_queue_t *event_queue, + cairo_bo_edge_t *edge) +{ + cairo_bo_point32_t point; + + point.y = edge->edge.bottom; + point.x = _line_compute_intersection_x_for_y (&edge->edge.line, + point.y); + return _cairo_bo_event_queue_insert (event_queue, + CAIRO_BO_EVENT_TYPE_STOP, + edge, NULL, + &point); +} + +static void +_cairo_bo_event_queue_fini (cairo_bo_event_queue_t *event_queue) +{ + _pqueue_fini (&event_queue->pqueue); + _cairo_freepool_fini (&event_queue->pool); +} + +static inline cairo_status_t +_cairo_bo_event_queue_insert_if_intersect_below_current_y (cairo_bo_event_queue_t *event_queue, + cairo_bo_edge_t *left, + cairo_bo_edge_t *right) +{ + cairo_bo_point32_t intersection; + + if (_line_equal (&left->edge.line, &right->edge.line)) + return CAIRO_STATUS_SUCCESS; + + /* The names "left" and "right" here are correct descriptions of + * the order of the two edges within the active edge list. So if a + * slope comparison also puts left less than right, then we know + * that the intersection of these two segments has already + * occurred before the current sweep line position. */ + if (_slope_compare (left, right) <= 0) + return CAIRO_STATUS_SUCCESS; + + if (! _cairo_bo_edge_intersect (left, right, &intersection)) + return CAIRO_STATUS_SUCCESS; + + return _cairo_bo_event_queue_insert (event_queue, + CAIRO_BO_EVENT_TYPE_INTERSECTION, + left, right, + &intersection); +} + +static void +_cairo_bo_sweep_line_init (cairo_bo_sweep_line_t *sweep_line) +{ + sweep_line->head = NULL; + sweep_line->current_y = INT32_MIN; + sweep_line->current_edge = NULL; +} + +static cairo_status_t +_cairo_bo_sweep_line_insert (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (sweep_line->current_edge != NULL) { + cairo_bo_edge_t *prev, *next; + int cmp; + + cmp = _cairo_bo_sweep_line_compare_edges (sweep_line, + sweep_line->current_edge, + edge); + if (cmp < 0) { + prev = sweep_line->current_edge; + next = prev->next; + while (next != NULL && + _cairo_bo_sweep_line_compare_edges (sweep_line, + next, edge) < 0) + { + prev = next, next = prev->next; + } + + prev->next = edge; + edge->prev = prev; + edge->next = next; + if (next != NULL) + next->prev = edge; + } else if (cmp > 0) { + next = sweep_line->current_edge; + prev = next->prev; + while (prev != NULL && + _cairo_bo_sweep_line_compare_edges (sweep_line, + prev, edge) > 0) + { + next = prev, prev = next->prev; + } + + next->prev = edge; + edge->next = next; + edge->prev = prev; + if (prev != NULL) + prev->next = edge; + else + sweep_line->head = edge; + } else { + prev = sweep_line->current_edge; + edge->prev = prev; + edge->next = prev->next; + if (prev->next != NULL) + prev->next->prev = edge; + prev->next = edge; + } + } else { + sweep_line->head = edge; + } + + sweep_line->current_edge = edge; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_bo_sweep_line_delete (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *edge) +{ + if (edge->prev != NULL) + edge->prev->next = edge->next; + else + sweep_line->head = edge->next; + + if (edge->next != NULL) + edge->next->prev = edge->prev; + + if (sweep_line->current_edge == edge) + sweep_line->current_edge = edge->prev ? edge->prev : edge->next; +} + +static void +_cairo_bo_sweep_line_swap (cairo_bo_sweep_line_t *sweep_line, + cairo_bo_edge_t *left, + cairo_bo_edge_t *right) +{ + if (left->prev != NULL) + left->prev->next = right; + else + sweep_line->head = right; + + if (right->next != NULL) + right->next->prev = left; + + left->next = right->next; + right->next = left; + + right->prev = left->prev; + left->prev = right; +} + +static inline cairo_bool_t +edges_colinear (const cairo_bo_edge_t *a, const cairo_bo_edge_t *b) +{ + if (_line_equal (&a->edge.line, &b->edge.line)) + return TRUE; + + if (_slope_compare (a, b)) + return FALSE; + + /* The choice of y is not truly arbitrary since we must guarantee that it + * is greater than the start of either line. + */ + if (a->edge.line.p1.y == b->edge.line.p1.y) { + return a->edge.line.p1.x == b->edge.line.p1.x; + } else if (a->edge.line.p2.y == b->edge.line.p2.y) { + return a->edge.line.p2.x == b->edge.line.p2.x; + } else if (a->edge.line.p1.y < b->edge.line.p1.y) { + return edge_compare_for_y_against_x (b, + a->edge.line.p1.y, + a->edge.line.p1.x) == 0; + } else { + return edge_compare_for_y_against_x (a, + b->edge.line.p1.y, + b->edge.line.p1.x) == 0; + } +} + +static void +_cairo_bo_edge_end (cairo_bo_edge_t *left, + int32_t bot, + cairo_polygon_t *polygon) +{ + cairo_bo_deferred_t *d = &left->deferred; + + if (likely (d->top < bot)) { + _cairo_polygon_add_line (polygon, + &left->edge.line, + d->top, bot, + 1); + _cairo_polygon_add_line (polygon, + &d->right->edge.line, + d->top, bot, + -1); + } + + d->right = NULL; +} + + +static inline void +_cairo_bo_edge_start_or_continue (cairo_bo_edge_t *left, + cairo_bo_edge_t *right, + int top, + cairo_polygon_t *polygon) +{ + if (left->deferred.right == right) + return; + + if (left->deferred.right != NULL) { + if (right != NULL && edges_colinear (left->deferred.right, right)) + { + /* continuation on right, so just swap edges */ + left->deferred.right = right; + return; + } + + _cairo_bo_edge_end (left, top, polygon); + } + + if (right != NULL && ! edges_colinear (left, right)) { + left->deferred.top = top; + left->deferred.right = right; + } +} + +static inline void +_active_edges_to_polygon (cairo_bo_edge_t *left, + int32_t top, + cairo_fill_rule_t fill_rule, + cairo_polygon_t *polygon) +{ + cairo_bo_edge_t *right; + unsigned int mask; + + if (fill_rule == CAIRO_FILL_RULE_WINDING) + mask = ~0; + else + mask = 1; + + while (left != NULL) { + int in_out = left->edge.dir; + + right = left->next; + if (left->deferred.right == NULL) { + while (right != NULL && right->deferred.right == NULL) + right = right->next; + + if (right != NULL && edges_colinear (left, right)) { + /* continuation on left */ + left->deferred = right->deferred; + right->deferred.right = NULL; + } + } + + right = left->next; + while (right != NULL) { + if (right->deferred.right != NULL) + _cairo_bo_edge_end (right, top, polygon); + + in_out += right->edge.dir; + if ((in_out & mask) == 0) { + /* skip co-linear edges */ + if (right->next == NULL || !edges_colinear (right, right->next)) + break; + } + + right = right->next; + } + + _cairo_bo_edge_start_or_continue (left, right, top, polygon); + + left = right; + if (left != NULL) + left = left->next; + } +} + + +static cairo_status_t +_cairo_bentley_ottmann_tessellate_bo_edges (cairo_bo_event_t **start_events, + int num_events, + cairo_fill_rule_t fill_rule, + cairo_polygon_t *polygon) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; /* silence compiler */ + cairo_bo_event_queue_t event_queue; + cairo_bo_sweep_line_t sweep_line; + cairo_bo_event_t *event; + cairo_bo_edge_t *left, *right; + cairo_bo_edge_t *e1, *e2; + + _cairo_bo_event_queue_init (&event_queue, start_events, num_events); + _cairo_bo_sweep_line_init (&sweep_line); + + while ((event = _cairo_bo_event_dequeue (&event_queue))) { + if (event->point.y != sweep_line.current_y) { + _active_edges_to_polygon (sweep_line.head, + sweep_line.current_y, + fill_rule, polygon); + + sweep_line.current_y = event->point.y; + } + + switch (event->type) { + case CAIRO_BO_EVENT_TYPE_START: + e1 = &((cairo_bo_start_event_t *) event)->edge; + + status = _cairo_bo_sweep_line_insert (&sweep_line, e1); + if (unlikely (status)) + goto unwind; + + status = _cairo_bo_event_queue_insert_stop (&event_queue, e1); + if (unlikely (status)) + goto unwind; + + left = e1->prev; + right = e1->next; + + if (left != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e1); + if (unlikely (status)) + goto unwind; + } + + if (right != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); + if (unlikely (status)) + goto unwind; + } + + break; + + case CAIRO_BO_EVENT_TYPE_STOP: + e1 = ((cairo_bo_queue_event_t *) event)->e1; + _cairo_bo_event_queue_delete (&event_queue, event); + + left = e1->prev; + right = e1->next; + + _cairo_bo_sweep_line_delete (&sweep_line, e1); + + if (e1->deferred.right != NULL) + _cairo_bo_edge_end (e1, e1->edge.bottom, polygon); + + if (left != NULL && right != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, right); + if (unlikely (status)) + goto unwind; + } + + break; + + case CAIRO_BO_EVENT_TYPE_INTERSECTION: + e1 = ((cairo_bo_queue_event_t *) event)->e1; + e2 = ((cairo_bo_queue_event_t *) event)->e2; + _cairo_bo_event_queue_delete (&event_queue, event); + + /* skip this intersection if its edges are not adjacent */ + if (e2 != e1->next) + break; + + left = e1->prev; + right = e2->next; + + _cairo_bo_sweep_line_swap (&sweep_line, e1, e2); + + /* after the swap e2 is left of e1 */ + + if (left != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, left, e2); + if (unlikely (status)) + goto unwind; + } + + if (right != NULL) { + status = _cairo_bo_event_queue_insert_if_intersect_below_current_y (&event_queue, e1, right); + if (unlikely (status)) + goto unwind; + } + + break; + } + } + + unwind: + _cairo_bo_event_queue_fini (&event_queue); + + return status; +} + +cairo_status_t +_cairo_polygon_reduce (cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule) +{ + cairo_status_t status; + cairo_bo_start_event_t stack_events[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_start_event_t)]; + cairo_bo_start_event_t *events; + cairo_bo_event_t *stack_event_ptrs[ARRAY_LENGTH (stack_events) + 1]; + cairo_bo_event_t **event_ptrs; + int num_limits; + int num_events; + int i; + + num_events = polygon->num_edges; + if (unlikely (0 == num_events)) + return CAIRO_STATUS_SUCCESS; + + if (DEBUG_POLYGON) { + FILE *file = fopen ("reduce_in.txt", "w"); + _cairo_debug_print_polygon (file, polygon); + fclose (file); + } + + events = stack_events; + event_ptrs = stack_event_ptrs; + if (num_events > ARRAY_LENGTH (stack_events)) { + events = _cairo_malloc_ab_plus_c (num_events, + sizeof (cairo_bo_start_event_t) + + sizeof (cairo_bo_event_t *), + sizeof (cairo_bo_event_t *)); + if (unlikely (events == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + event_ptrs = (cairo_bo_event_t **) (events + num_events); + } + + for (i = 0; i < num_events; i++) { + event_ptrs[i] = (cairo_bo_event_t *) &events[i]; + + events[i].type = CAIRO_BO_EVENT_TYPE_START; + events[i].point.y = polygon->edges[i].top; + events[i].point.x = + _line_compute_intersection_x_for_y (&polygon->edges[i].line, + events[i].point.y); + + events[i].edge.edge = polygon->edges[i]; + events[i].edge.deferred.right = NULL; + events[i].edge.prev = NULL; + events[i].edge.next = NULL; + } + + num_limits = polygon->num_limits; polygon->num_limits = 0; + polygon->num_edges = 0; + + status = _cairo_bentley_ottmann_tessellate_bo_edges (event_ptrs, + num_events, + fill_rule, + polygon); + polygon->num_limits = num_limits; + + if (events != stack_events) + free (events); + + if (DEBUG_POLYGON) { + FILE *file = fopen ("reduce_out.txt", "w"); + _cairo_debug_print_polygon (file, polygon); + fclose (file); + } + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-polygon.c b/Build/source/libs/cairo/cairo-src/src/cairo-polygon.c new file mode 100644 index 00000000000..b0424f6e72e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-polygon.c @@ -0,0 +1,608 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-boxes-private.h" +#include "cairo-contour-private.h" +#include "cairo-error-private.h" + +#define DEBUG_POLYGON 0 + +#if DEBUG_POLYGON && !NDEBUG +static void +assert_last_edge_is_valid(cairo_polygon_t *polygon, + const cairo_box_t *limit) +{ + cairo_edge_t *edge; + cairo_fixed_t x; + + edge = &polygon->edges[polygon->num_edges-1]; + + assert (edge->bottom > edge->top); + assert (edge->top >= limit->p1.y); + assert (edge->bottom <= limit->p2.y); + + x = _cairo_edge_compute_intersection_x_for_y (&edge->line.p1, + &edge->line.p2, + edge->top); + assert (x >= limit->p1.x); + assert (x <= limit->p2.x); + + x = _cairo_edge_compute_intersection_x_for_y (&edge->line.p1, + &edge->line.p2, + edge->bottom); + assert (x >= limit->p1.x); + assert (x <= limit->p2.x); +} +#else +#define assert_last_edge_is_valid(p, l) +#endif + +static void +_cairo_polygon_add_edge (cairo_polygon_t *polygon, + const cairo_point_t *p1, + const cairo_point_t *p2, + int dir); + +void +_cairo_polygon_limit (cairo_polygon_t *polygon, + const cairo_box_t *limits, + int num_limits) +{ + int n; + + polygon->limits = limits; + polygon->num_limits = num_limits; + + if (polygon->num_limits) { + polygon->limit = limits[0]; + for (n = 1; n < num_limits; n++) { + if (limits[n].p1.x < polygon->limit.p1.x) + polygon->limit.p1.x = limits[n].p1.x; + + if (limits[n].p1.y < polygon->limit.p1.y) + polygon->limit.p1.y = limits[n].p1.y; + + if (limits[n].p2.x > polygon->limit.p2.x) + polygon->limit.p2.x = limits[n].p2.x; + + if (limits[n].p2.y > polygon->limit.p2.y) + polygon->limit.p2.y = limits[n].p2.y; + } + } +} + +void +_cairo_polygon_limit_to_clip (cairo_polygon_t *polygon, + const cairo_clip_t *clip) +{ + if (clip) + _cairo_polygon_limit (polygon, clip->boxes, clip->num_boxes); + else + _cairo_polygon_limit (polygon, 0, 0); +} + +void +_cairo_polygon_init (cairo_polygon_t *polygon, + const cairo_box_t *limits, + int num_limits) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t))); + + polygon->status = CAIRO_STATUS_SUCCESS; + + polygon->num_edges = 0; + + polygon->edges = polygon->edges_embedded; + polygon->edges_size = ARRAY_LENGTH (polygon->edges_embedded); + + polygon->extents.p1.x = polygon->extents.p1.y = INT32_MAX; + polygon->extents.p2.x = polygon->extents.p2.y = INT32_MIN; + + _cairo_polygon_limit (polygon, limits, num_limits); +} + +void +_cairo_polygon_init_with_clip (cairo_polygon_t *polygon, + const cairo_clip_t *clip) +{ + if (clip) + _cairo_polygon_init (polygon, clip->boxes, clip->num_boxes); + else + _cairo_polygon_init (polygon, 0, 0); +} + +cairo_status_t +_cairo_polygon_init_boxes (cairo_polygon_t *polygon, + const cairo_boxes_t *boxes) +{ + const struct _cairo_boxes_chunk *chunk; + int i; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t))); + + polygon->status = CAIRO_STATUS_SUCCESS; + + polygon->num_edges = 0; + + polygon->edges = polygon->edges_embedded; + polygon->edges_size = ARRAY_LENGTH (polygon->edges_embedded); + if (boxes->num_boxes > ARRAY_LENGTH (polygon->edges_embedded)/2) { + polygon->edges_size = 2 * boxes->num_boxes; + polygon->edges = _cairo_malloc_ab (polygon->edges_size, + 2*sizeof(cairo_edge_t)); + if (unlikely (polygon->edges == NULL)) + return polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + polygon->extents.p1.x = polygon->extents.p1.y = INT32_MAX; + polygon->extents.p2.x = polygon->extents.p2.y = INT32_MIN; + + polygon->limits = NULL; + polygon->num_limits = 0; + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_point_t p1, p2; + + p1 = chunk->base[i].p1; + p2.x = p1.x; + p2.y = chunk->base[i].p2.y; + _cairo_polygon_add_edge (polygon, &p1, &p2, 1); + + p1 = chunk->base[i].p2; + p2.x = p1.x; + p2.y = chunk->base[i].p1.y; + _cairo_polygon_add_edge (polygon, &p1, &p2, 1); + } + } + + return polygon->status; +} + +cairo_status_t +_cairo_polygon_init_box_array (cairo_polygon_t *polygon, + cairo_box_t *boxes, + int num_boxes) +{ + int i; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t))); + + polygon->status = CAIRO_STATUS_SUCCESS; + + polygon->num_edges = 0; + + polygon->edges = polygon->edges_embedded; + polygon->edges_size = ARRAY_LENGTH (polygon->edges_embedded); + if (num_boxes > ARRAY_LENGTH (polygon->edges_embedded)/2) { + polygon->edges_size = 2 * num_boxes; + polygon->edges = _cairo_malloc_ab (polygon->edges_size, + 2*sizeof(cairo_edge_t)); + if (unlikely (polygon->edges == NULL)) + return polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + polygon->extents.p1.x = polygon->extents.p1.y = INT32_MAX; + polygon->extents.p2.x = polygon->extents.p2.y = INT32_MIN; + + polygon->limits = NULL; + polygon->num_limits = 0; + + for (i = 0; i < num_boxes; i++) { + cairo_point_t p1, p2; + + p1 = boxes[i].p1; + p2.x = p1.x; + p2.y = boxes[i].p2.y; + _cairo_polygon_add_edge (polygon, &p1, &p2, 1); + + p1 = boxes[i].p2; + p2.x = p1.x; + p2.y = boxes[i].p1.y; + _cairo_polygon_add_edge (polygon, &p1, &p2, 1); + } + + return polygon->status; +} + + +void +_cairo_polygon_fini (cairo_polygon_t *polygon) +{ + if (polygon->edges != polygon->edges_embedded) + free (polygon->edges); + + VG (VALGRIND_MAKE_MEM_NOACCESS (polygon, sizeof (cairo_polygon_t))); +} + +/* make room for at least one more edge */ +static cairo_bool_t +_cairo_polygon_grow (cairo_polygon_t *polygon) +{ + cairo_edge_t *new_edges; + int old_size = polygon->edges_size; + int new_size = 4 * old_size; + + if (CAIRO_INJECT_FAULT ()) { + polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + if (polygon->edges == polygon->edges_embedded) { + new_edges = _cairo_malloc_ab (new_size, sizeof (cairo_edge_t)); + if (new_edges != NULL) + memcpy (new_edges, polygon->edges, old_size * sizeof (cairo_edge_t)); + } else { + new_edges = _cairo_realloc_ab (polygon->edges, + new_size, sizeof (cairo_edge_t)); + } + + if (unlikely (new_edges == NULL)) { + polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + polygon->edges = new_edges; + polygon->edges_size = new_size; + + return TRUE; +} + +static void +_add_edge (cairo_polygon_t *polygon, + const cairo_point_t *p1, + const cairo_point_t *p2, + int top, int bottom, + int dir) +{ + cairo_edge_t *edge; + + assert (top < bottom); + + if (unlikely (polygon->num_edges == polygon->edges_size)) { + if (! _cairo_polygon_grow (polygon)) + return; + } + + edge = &polygon->edges[polygon->num_edges++]; + edge->line.p1 = *p1; + edge->line.p2 = *p2; + edge->top = top; + edge->bottom = bottom; + edge->dir = dir; + + if (top < polygon->extents.p1.y) + polygon->extents.p1.y = top; + if (bottom > polygon->extents.p2.y) + polygon->extents.p2.y = bottom; + + if (p1->x < polygon->extents.p1.x || p1->x > polygon->extents.p2.x) { + cairo_fixed_t x = p1->x; + if (top != p1->y) + x = _cairo_edge_compute_intersection_x_for_y (p1, p2, top); + if (x < polygon->extents.p1.x) + polygon->extents.p1.x = x; + if (x > polygon->extents.p2.x) + polygon->extents.p2.x = x; + } + + if (p2->x < polygon->extents.p1.x || p2->x > polygon->extents.p2.x) { + cairo_fixed_t x = p2->x; + if (bottom != p2->y) + x = _cairo_edge_compute_intersection_x_for_y (p1, p2, bottom); + if (x < polygon->extents.p1.x) + polygon->extents.p1.x = x; + if (x > polygon->extents.p2.x) + polygon->extents.p2.x = x; + } +} + +static void +_add_clipped_edge (cairo_polygon_t *polygon, + const cairo_point_t *p1, + const cairo_point_t *p2, + const int top, const int bottom, + const int dir) +{ + cairo_point_t bot_left, top_right; + cairo_fixed_t top_y, bot_y; + int n; + + for (n = 0; n < polygon->num_limits; n++) { + const cairo_box_t *limits = &polygon->limits[n]; + cairo_fixed_t pleft, pright; + + if (top >= limits->p2.y) + continue; + if (bottom <= limits->p1.y) + continue; + + bot_left.x = limits->p1.x; + bot_left.y = limits->p2.y; + + top_right.x = limits->p2.x; + top_right.y = limits->p1.y; + + /* The useful region */ + top_y = MAX (top, limits->p1.y); + bot_y = MIN (bottom, limits->p2.y); + + /* The projection of the edge on the horizontal axis */ + pleft = MIN (p1->x, p2->x); + pright = MAX (p1->x, p2->x); + + if (limits->p1.x <= pleft && pright <= limits->p2.x) { + /* Projection of the edge completely contained in the box: + * clip vertically by restricting top and bottom */ + + _add_edge (polygon, p1, p2, top_y, bot_y, dir); + assert_last_edge_is_valid (polygon, limits); + } else if (pright <= limits->p1.x) { + /* Projection of the edge to the left of the box: + * replace with the left side of the box (clipped top/bottom) */ + + _add_edge (polygon, &limits->p1, &bot_left, top_y, bot_y, dir); + assert_last_edge_is_valid (polygon, limits); + } else if (limits->p2.x <= pleft) { + /* Projection of the edge to the right of the box: + * replace with the right side of the box (clipped top/bottom) */ + + _add_edge (polygon, &top_right, &limits->p2, top_y, bot_y, dir); + assert_last_edge_is_valid (polygon, limits); + } else { + /* The edge and the box intersect in a generic way */ + cairo_fixed_t left_y, right_y; + cairo_bool_t top_left_to_bottom_right; + + /* + * The edge intersects the lines corresponding to the left + * and right sides of the limit box at left_y and right_y, + * but we need to add edges for the range from top_y to + * bot_y. + * + * For both intersections, there are three cases: + * + * 1) It is outside the vertical range of the limit + * box. In this case we can simply further clip the + * edge we will be emitting (i.e. restrict its + * top/bottom limits to those of the limit box). + * + * 2) It is inside the vertical range of the limit + * box. In this case, we need to add the vertical edge + * connecting the correct vertex to the intersection, + * in order to preserve the winding count. + * + * 3) It is exactly on the box. In this case, do nothing. + * + * These operations restrict the active range (stored in + * top_y/bot_y) so that the p1-p2 edge is completely + * inside the box if it is clipped to this vertical range. + */ + + top_left_to_bottom_right = (p1->x <= p2->x) == (p1->y <= p2->y); + if (top_left_to_bottom_right) { + if (pleft >= limits->p1.x) { + left_y = top_y; + } else { + left_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, + limits->p1.x); + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) + left_y++; + } + + left_y = MIN (left_y, bot_y); + if (top_y < left_y) { + _add_edge (polygon, &limits->p1, &bot_left, + top_y, left_y, dir); + assert_last_edge_is_valid (polygon, limits); + top_y = left_y; + } + + if (pright <= limits->p2.x) { + right_y = bot_y; + } else { + right_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, + limits->p2.x); + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) + right_y--; + } + + right_y = MAX (right_y, top_y); + if (bot_y > right_y) { + _add_edge (polygon, &top_right, &limits->p2, + right_y, bot_y, dir); + assert_last_edge_is_valid (polygon, limits); + bot_y = right_y; + } + } else { + if (pright <= limits->p2.x) { + right_y = top_y; + } else { + right_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, + limits->p2.x); + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) + right_y++; + } + + right_y = MIN (right_y, bot_y); + if (top_y < right_y) { + _add_edge (polygon, &top_right, &limits->p2, + top_y, right_y, dir); + assert_last_edge_is_valid (polygon, limits); + top_y = right_y; + } + + if (pleft >= limits->p1.x) { + left_y = bot_y; + } else { + left_y = _cairo_edge_compute_intersection_y_for_x (p1, p2, + limits->p1.x); + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) + left_y--; + } + + left_y = MAX (left_y, top_y); + if (bot_y > left_y) { + _add_edge (polygon, &limits->p1, &bot_left, + left_y, bot_y, dir); + assert_last_edge_is_valid (polygon, limits); + bot_y = left_y; + } + } + + if (top_y != bot_y) { + _add_edge (polygon, p1, p2, top_y, bot_y, dir); + assert_last_edge_is_valid (polygon, limits); + } + } + } +} + +static void +_cairo_polygon_add_edge (cairo_polygon_t *polygon, + const cairo_point_t *p1, + const cairo_point_t *p2, + int dir) +{ + /* drop horizontal edges */ + if (p1->y == p2->y) + return; + + if (p1->y > p2->y) { + const cairo_point_t *t; + t = p1, p1 = p2, p2 = t; + dir = -dir; + } + + if (polygon->num_limits) { + if (p2->y <= polygon->limit.p1.y) + return; + + if (p1->y >= polygon->limit.p2.y) + return; + + _add_clipped_edge (polygon, p1, p2, p1->y, p2->y, dir); + } else + _add_edge (polygon, p1, p2, p1->y, p2->y, dir); +} + +cairo_status_t +_cairo_polygon_add_external_edge (void *polygon, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + _cairo_polygon_add_edge (polygon, p1, p2, 1); + return _cairo_polygon_status (polygon); +} + +cairo_status_t +_cairo_polygon_add_line (cairo_polygon_t *polygon, + const cairo_line_t *line, + int top, int bottom, + int dir) +{ + /* drop horizontal edges */ + if (line->p1.y == line->p2.y) + return CAIRO_STATUS_SUCCESS; + + if (bottom <= top) + return CAIRO_STATUS_SUCCESS; + + if (polygon->num_limits) { + if (line->p2.y <= polygon->limit.p1.y) + return CAIRO_STATUS_SUCCESS; + + if (line->p1.y >= polygon->limit.p2.y) + return CAIRO_STATUS_SUCCESS; + + _add_clipped_edge (polygon, &line->p1, &line->p2, top, bottom, dir); + } else + _add_edge (polygon, &line->p1, &line->p2, top, bottom, dir); + + return polygon->status; +} + +cairo_status_t +_cairo_polygon_add_contour (cairo_polygon_t *polygon, + const cairo_contour_t *contour) +{ + const struct _cairo_contour_chain *chain; + const cairo_point_t *prev = NULL; + int i; + + if (contour->chain.num_points <= 1) + return CAIRO_INT_STATUS_SUCCESS; + + prev = &contour->chain.points[0]; + for (chain = &contour->chain; chain; chain = chain->next) { + for (i = 0; i < chain->num_points; i++) { + _cairo_polygon_add_edge (polygon, prev, &chain->points[i], + contour->direction); + prev = &chain->points[i]; + } + } + + return polygon->status; +} + +void +_cairo_polygon_translate (cairo_polygon_t *polygon, int dx, int dy) +{ + int n; + + dx = _cairo_fixed_from_int (dx); + dy = _cairo_fixed_from_int (dy); + + polygon->extents.p1.x += dx; + polygon->extents.p2.x += dx; + polygon->extents.p1.y += dy; + polygon->extents.p2.y += dy; + + for (n = 0; n < polygon->num_edges; n++) { + cairo_edge_t *e = &polygon->edges[n]; + + e->top += dy; + e->bottom += dy; + + e->line.p1.x += dx; + e->line.p2.x += dx; + e->line.p1.y += dy; + e->line.p2.y += dy; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-private.h new file mode 100644 index 00000000000..9f4f55b7cea --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-private.h @@ -0,0 +1,64 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PRIVATE_H +#define CAIRO_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-reference-count-private.h" + +CAIRO_BEGIN_DECLS + +struct _cairo { + cairo_reference_count_t ref_count; + cairo_status_t status; + cairo_user_data_array_t user_data; + + const cairo_backend_t *backend; +}; + +cairo_private cairo_t * +_cairo_create_in_error (cairo_status_t status); + +cairo_private void +_cairo_init (cairo_t *cr, + const cairo_backend_t *backend); + +cairo_private void +_cairo_fini (cairo_t *cr); + +CAIRO_END_DECLS + +#endif /* CAIRO_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-ps-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-ps-surface-private.h new file mode 100644 index 00000000000..1d5d27d4910 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-ps-surface-private.h @@ -0,0 +1,104 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Keith Packard + */ + +#ifndef CAIRO_PS_SURFACE_PRIVATE_H +#define CAIRO_PS_SURFACE_PRIVATE_H + +#include "cairo-ps.h" + +#include "cairo-surface-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-pdf-operators-private.h" + +#include + +typedef struct cairo_ps_surface { + cairo_surface_t base; + + /* Here final_stream corresponds to the stream/file passed to + * cairo_ps_surface_create surface is built. Meanwhile stream is a + * temporary stream in which the file output is built, (so that + * the header can be built and inserted into the target stream + * before the contents of the temporary stream are copied). */ + cairo_output_stream_t *final_stream; + + FILE *tmpfile; + cairo_output_stream_t *stream; + + cairo_bool_t eps; + cairo_content_t content; + double width; + double height; + cairo_rectangle_int_t page_bbox; + int bbox_x1, bbox_y1, bbox_x2, bbox_y2; + cairo_matrix_t cairo_to_ps; + + cairo_bool_t use_string_datasource; + + cairo_bool_t current_pattern_is_solid_color; + cairo_color_t current_color; + + int num_pages; + + cairo_paginated_mode_t paginated_mode; + + cairo_bool_t force_fallbacks; + cairo_bool_t has_creation_date; + time_t creation_date; + + cairo_scaled_font_subsets_t *font_subsets; + + cairo_list_t document_media; + cairo_array_t dsc_header_comments; + cairo_array_t dsc_setup_comments; + cairo_array_t dsc_page_setup_comments; + + cairo_array_t *dsc_comment_target; + + cairo_ps_level_t ps_level; + cairo_ps_level_t ps_level_used; + + cairo_surface_clipper_t clipper; + + cairo_pdf_operators_t pdf_operators; + cairo_surface_t *paginated_surface; +} cairo_ps_surface_t; + +#endif /* CAIRO_PS_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-ps-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-ps-surface.c new file mode 100644 index 00000000000..03eba62db5d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-ps-surface.c @@ -0,0 +1,4694 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * Copyright © 2005 Red Hat, Inc + * Copyright © 2007,2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Keith Packard + * Adrian Johnson + */ + + +/* + * Design of the PS output: + * + * The PS output is harmonised with the PDF operations using PS procedures + * to emulate the PDF operators. + * + * This has a number of advantages: + * 1. A large chunk of code is shared between the PDF and PS backends. + * See cairo-pdf-operators. + * 2. Using gs to do PS -> PDF and PDF -> PS will always work well. + */ + +#define _BSD_SOURCE /* for ctime_r(), snprintf(), strdup() */ +#include "cairoint.h" + +#include "cairo-ps.h" +#include "cairo-ps-surface-private.h" + +#include "cairo-pdf-operators-private.h" +#include "cairo-pdf-shading-private.h" + +#include "cairo-array-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-list-inline.h" +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-paginated-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-type3-glyph-surface-private.h" +#include "cairo-image-info-private.h" + +#include +#include +#include +#include +#include + +#define DEBUG_PS 0 + +#if DEBUG_PS +#define DEBUG_FALLBACK(s) \ + fprintf (stderr, "%s::%d -- %s\n", __FUNCTION__, __LINE__, (s)) +#else +#define DEBUG_FALLBACK(s) +#endif + +#ifndef HAVE_CTIME_R +#define ctime_r(T, BUF) ctime (T) +#endif + +/** + * SECTION:cairo-ps + * @Title: PostScript Surfaces + * @Short_Description: Rendering PostScript documents + * @See_Also: #cairo_surface_t + * + * The PostScript surface is used to render cairo graphics to Adobe + * PostScript files and is a multi-page vector surface backend. + **/ + +/** + * CAIRO_HAS_PS_SURFACE: + * + * Defined if the PostScript surface backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.2 + **/ + +typedef enum { + CAIRO_PS_COMPRESS_NONE, + CAIRO_PS_COMPRESS_LZW, + CAIRO_PS_COMPRESS_DEFLATE + } cairo_ps_compress_t; + +static const cairo_surface_backend_t cairo_ps_surface_backend; +static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend; + +static cairo_bool_t +_cairo_ps_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle); + +static const cairo_ps_level_t _cairo_ps_levels[] = +{ + CAIRO_PS_LEVEL_2, + CAIRO_PS_LEVEL_3 +}; + +#define CAIRO_PS_LEVEL_LAST ARRAY_LENGTH (_cairo_ps_levels) + +static const char * _cairo_ps_level_strings[CAIRO_PS_LEVEL_LAST] = +{ + "PS Level 2", + "PS Level 3" +}; + +static const char *_cairo_ps_supported_mime_types[] = +{ + CAIRO_MIME_TYPE_JPEG, + NULL +}; + +typedef struct _cairo_page_standard_media { + const char *name; + int width; + int height; +} cairo_page_standard_media_t; + +static const cairo_page_standard_media_t _cairo_page_standard_media[] = +{ + { "A0", 2384, 3371 }, + { "A1", 1685, 2384 }, + { "A2", 1190, 1684 }, + { "A3", 842, 1190 }, + { "A4", 595, 842 }, + { "A5", 420, 595 }, + { "B4", 729, 1032 }, + { "B5", 516, 729 }, + { "Letter", 612, 792 }, + { "Tabloid", 792, 1224 }, + { "Ledger", 1224, 792 }, + { "Legal", 612, 1008 }, + { "Statement", 396, 612 }, + { "Executive", 540, 720 }, + { "Folio", 612, 936 }, + { "Quarto", 610, 780 }, + { "10x14", 720, 1008 }, +}; + +typedef struct _cairo_page_media { + char *name; + int width; + int height; + cairo_list_t link; +} cairo_page_media_t; + +static void +_cairo_ps_surface_emit_header (cairo_ps_surface_t *surface) +{ + char ctime_buf[26]; + time_t now; + char **comments; + int i, num_comments; + int level; + const char *eps_header = ""; + cairo_bool_t has_bbox; + + if (surface->has_creation_date) + now = surface->creation_date; + else + now = time (NULL); + + if (surface->ps_level_used == CAIRO_PS_LEVEL_2) + level = 2; + else + level = 3; + + if (surface->eps) + eps_header = " EPSF-3.0"; + + _cairo_output_stream_printf (surface->final_stream, + "%%!PS-Adobe-3.0%s\n" + "%%%%Creator: cairo %s (http://cairographics.org)\n" + "%%%%CreationDate: %s" + "%%%%Pages: %d\n", + eps_header, + cairo_version_string (), + ctime_r (&now, ctime_buf), + surface->num_pages); + + _cairo_output_stream_printf (surface->final_stream, + "%%%%DocumentData: Clean7Bit\n" + "%%%%LanguageLevel: %d\n", + level); + + if (!cairo_list_is_empty (&surface->document_media)) { + cairo_page_media_t *page; + cairo_bool_t first = TRUE; + + cairo_list_foreach_entry (page, cairo_page_media_t, &surface->document_media, link) { + if (first) { + _cairo_output_stream_printf (surface->final_stream, + "%%%%DocumentMedia: "); + first = FALSE; + } else { + _cairo_output_stream_printf (surface->final_stream, + "%%%%+ "); + } + _cairo_output_stream_printf (surface->final_stream, + "%s %d %d 0 () ()\n", + page->name, + page->width, + page->height); + } + } + + has_bbox = FALSE; + num_comments = _cairo_array_num_elements (&surface->dsc_header_comments); + comments = _cairo_array_index (&surface->dsc_header_comments, 0); + for (i = 0; i < num_comments; i++) { + _cairo_output_stream_printf (surface->final_stream, + "%s\n", comments[i]); + if (strncmp (comments[i], "%%BoundingBox:", 14) == 0) + has_bbox = TRUE; + + free (comments[i]); + comments[i] = NULL; + } + + if (!has_bbox) { + _cairo_output_stream_printf (surface->final_stream, + "%%%%BoundingBox: %d %d %d %d\n", + surface->bbox_x1, + surface->bbox_y1, + surface->bbox_x2, + surface->bbox_y2); + } + + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndComments\n"); + + _cairo_output_stream_printf (surface->final_stream, + "%%%%BeginProlog\n"); + + if (surface->eps) { + _cairo_output_stream_printf (surface->final_stream, + "save\n" + "50 dict begin\n"); + } else { + _cairo_output_stream_printf (surface->final_stream, + "/languagelevel where\n" + "{ pop languagelevel } { 1 } ifelse\n" + "%d lt { /Helvetica findfont 12 scalefont setfont 50 500 moveto\n" + " (This print job requires a PostScript Language Level %d printer.) show\n" + " showpage quit } if\n", + level, + level); + } + + _cairo_output_stream_printf (surface->final_stream, + "/q { gsave } bind def\n" + "/Q { grestore } bind def\n" + "/cm { 6 array astore concat } bind def\n" + "/w { setlinewidth } bind def\n" + "/J { setlinecap } bind def\n" + "/j { setlinejoin } bind def\n" + "/M { setmiterlimit } bind def\n" + "/d { setdash } bind def\n" + "/m { moveto } bind def\n" + "/l { lineto } bind def\n" + "/c { curveto } bind def\n" + "/h { closepath } bind def\n" + "/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto\n" + " 0 exch rlineto 0 rlineto closepath } bind def\n" + "/S { stroke } bind def\n" + "/f { fill } bind def\n" + "/f* { eofill } bind def\n" + "/n { newpath } bind def\n" + "/W { clip } bind def\n" + "/W* { eoclip } bind def\n" + "/BT { } bind def\n" + "/ET { } bind def\n" + "/pdfmark where { pop globaldict /?pdfmark /exec load put }\n" + " { globaldict begin /?pdfmark /pop load def /pdfmark\n" + " /cleartomark load def end } ifelse\n" + "/BDC { mark 3 1 roll /BDC pdfmark } bind def\n" + "/EMC { mark /EMC pdfmark } bind def\n" + "/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def\n" + "/Tj { show currentpoint cairo_store_point } bind def\n" + "/TJ {\n" + " {\n" + " dup\n" + " type /stringtype eq\n" + " { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse\n" + " } forall\n" + " currentpoint cairo_store_point\n" + "} bind def\n" + "/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore\n" + " cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def\n" + "/Tf { pop /cairo_font exch def /cairo_font_matrix where\n" + " { pop cairo_selectfont } if } bind def\n" + "/Td { matrix translate cairo_font_matrix matrix concatmatrix dup\n" + " /cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point\n" + " /cairo_font where { pop cairo_selectfont } if } bind def\n" + "/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def\n" + " cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def\n" + "/g { setgray } bind def\n" + "/rg { setrgbcolor } bind def\n" + "/d1 { setcachedevice } bind def\n"); + + if (!surface->eps) { + _cairo_output_stream_printf (surface->final_stream, + "/cairo_set_page_size {\n" + " %% Change paper size, but only if different from previous paper size otherwise\n" + " %% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size\n" + " %% so we use the same when checking if the size changes.\n" + " /setpagedevice where {\n" + " pop currentpagedevice\n" + " /PageSize known {\n" + " 2 copy\n" + " currentpagedevice /PageSize get aload pop\n" + " exch 4 1 roll\n" + " sub abs 5 gt\n" + " 3 1 roll\n" + " sub abs 5 gt\n" + " or\n" + " } {\n" + " true\n" + " } ifelse\n" + " {\n" + " 2 array astore\n" + " 2 dict begin\n" + " /PageSize exch def\n" + " /ImagingBBox null def\n" + " currentdict end\n" + " setpagedevice\n" + " } {\n" + " pop pop\n" + " } ifelse\n" + " } {\n" + " pop\n" + " } ifelse\n" + "} def\n"); + } + + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndProlog\n"); + _cairo_output_stream_printf (surface->final_stream, + "%%%%BeginSetup\n"); + + num_comments = _cairo_array_num_elements (&surface->dsc_setup_comments); + if (num_comments) { + comments = _cairo_array_index (&surface->dsc_setup_comments, 0); + for (i = 0; i < num_comments; i++) { + _cairo_output_stream_printf (surface->final_stream, + "%s\n", comments[i]); + free (comments[i]); + comments[i] = NULL; + } + } +} + +static cairo_status_t +_cairo_ps_surface_emit_type1_font_subset (cairo_ps_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) + + +{ + cairo_type1_subset_t subset; + cairo_status_t status; + int length; + char name[64]; + + snprintf (name, sizeof name, "f-%d-%d", + font_subset->font_id, font_subset->subset_id); + status = _cairo_type1_subset_init (&subset, name, font_subset, TRUE); + if (unlikely (status)) + return status; + + /* FIXME: Figure out document structure convention for fonts */ + +#if DEBUG_PS + _cairo_output_stream_printf (surface->final_stream, + "%% _cairo_ps_surface_emit_type1_font_subset\n"); +#endif + + _cairo_output_stream_printf (surface->final_stream, + "%%%%BeginResource: font %s\n", + subset.base_font); + length = subset.header_length + subset.data_length + subset.trailer_length; + _cairo_output_stream_write (surface->final_stream, subset.data, length); + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndResource\n"); + + _cairo_type1_subset_fini (&subset); + + return CAIRO_STATUS_SUCCESS; +} + + +static cairo_status_t +_cairo_ps_surface_emit_type1_font_fallback (cairo_ps_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) +{ + cairo_type1_subset_t subset; + cairo_status_t status; + int length; + char name[64]; + + snprintf (name, sizeof name, "f-%d-%d", + font_subset->font_id, font_subset->subset_id); + status = _cairo_type1_fallback_init_hex (&subset, name, font_subset); + if (unlikely (status)) + return status; + +#if DEBUG_PS + _cairo_output_stream_printf (surface->final_stream, + "%% _cairo_ps_surface_emit_type1_font_fallback\n"); +#endif + + _cairo_output_stream_printf (surface->final_stream, + "%%%%BeginResource: font %s\n", + subset.base_font); + length = subset.header_length + subset.data_length + subset.trailer_length; + _cairo_output_stream_write (surface->final_stream, subset.data, length); + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndResource\n"); + + _cairo_type1_fallback_fini (&subset); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) + + +{ + cairo_truetype_subset_t subset; + cairo_status_t status; + unsigned int i, begin, end; + + status = _cairo_truetype_subset_init_ps (&subset, font_subset); + if (unlikely (status)) + return status; + + /* FIXME: Figure out document structure convention for fonts */ + +#if DEBUG_PS + _cairo_output_stream_printf (surface->final_stream, + "%% _cairo_ps_surface_emit_truetype_font_subset\n"); +#endif + + _cairo_output_stream_printf (surface->final_stream, + "%%%%BeginResource: font %s\n", + subset.ps_name); + _cairo_output_stream_printf (surface->final_stream, + "11 dict begin\n" + "/FontType 42 def\n" + "/FontName /%s def\n" + "/PaintType 0 def\n" + "/FontMatrix [ 1 0 0 1 0 0 ] def\n" + "/FontBBox [ 0 0 0 0 ] def\n" + "/Encoding 256 array def\n" + "0 1 255 { Encoding exch /.notdef put } for\n", + subset.ps_name); + + /* FIXME: Figure out how subset->x_max etc maps to the /FontBBox */ + + if (font_subset->is_latin) { + for (i = 1; i < 256; i++) { + if (font_subset->latin_to_subset_glyph_index[i] > 0) { + if (font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (surface->final_stream, + "Encoding %d /%s put\n", + i, font_subset->glyph_names[font_subset->latin_to_subset_glyph_index[i]]); + } else { + _cairo_output_stream_printf (surface->final_stream, + "Encoding %d /g%ld put\n", i, font_subset->latin_to_subset_glyph_index[i]); + } + } + } + } else { + for (i = 1; i < font_subset->num_glyphs; i++) { + if (font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (surface->final_stream, + "Encoding %d /%s put\n", + i, font_subset->glyph_names[i]); + } else { + _cairo_output_stream_printf (surface->final_stream, + "Encoding %d /g%d put\n", i, i); + } + } + } + + _cairo_output_stream_printf (surface->final_stream, + "/CharStrings %d dict dup begin\n" + "/.notdef 0 def\n", + font_subset->num_glyphs); + + for (i = 1; i < font_subset->num_glyphs; i++) { + if (font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (surface->final_stream, + "/%s %d def\n", + font_subset->glyph_names[i], i); + } else { + _cairo_output_stream_printf (surface->final_stream, + "/g%d %d def\n", i, i); + } + } + + _cairo_output_stream_printf (surface->final_stream, + "end readonly def\n"); + + _cairo_output_stream_printf (surface->final_stream, + "/sfnts [\n"); + begin = 0; + end = 0; + for (i = 0; i < subset.num_string_offsets; i++) { + end = subset.string_offsets[i]; + _cairo_output_stream_printf (surface->final_stream,"<"); + _cairo_output_stream_write_hex_string (surface->final_stream, + subset.data + begin, end - begin); + _cairo_output_stream_printf (surface->final_stream,"00>\n"); + begin = end; + } + if (subset.data_length > end) { + _cairo_output_stream_printf (surface->final_stream,"<"); + _cairo_output_stream_write_hex_string (surface->final_stream, + subset.data + end, subset.data_length - end); + _cairo_output_stream_printf (surface->final_stream,"00>\n"); + } + + _cairo_output_stream_printf (surface->final_stream, + "] def\n" + "/f-%d-%d currentdict end definefont pop\n", + font_subset->font_id, + font_subset->subset_id); + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndResource\n"); + _cairo_truetype_subset_fini (&subset); + + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_ps_emit_imagemask (cairo_image_surface_t *image, + cairo_output_stream_t *stream) +{ + uint8_t *row, *byte; + int rows, cols; + + /* The only image type supported by Type 3 fonts are 1-bit image + * masks */ + assert (image->format == CAIRO_FORMAT_A1); + + _cairo_output_stream_printf (stream, + "<<\n" + " /ImageType 1\n" + " /Width %d\n" + " /Height %d\n" + " /ImageMatrix [%d 0 0 %d 0 %d]\n" + " /Decode [1 0]\n" + " /BitsPerComponent 1\n", + image->width, + image->height, + image->width, + -image->height, + image->height); + + _cairo_output_stream_printf (stream, + " /DataSource {<\n "); + for (row = image->data, rows = image->height; rows; row += image->stride, rows--) { + for (byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) { + uint8_t output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte); + _cairo_output_stream_printf (stream, "%02x ", output_byte); + } + _cairo_output_stream_printf (stream, "\n "); + } + _cairo_output_stream_printf (stream, ">}\n>>\n"); + + _cairo_output_stream_printf (stream, + "imagemask\n"); + + return _cairo_output_stream_get_status (stream); +} + +static cairo_int_status_t +_cairo_ps_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_ps_surface_t *surface = closure; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + unsigned int i; + cairo_surface_t *type3_surface; + + type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, + NULL, + _cairo_ps_emit_imagemask, + surface->font_subsets, + TRUE); + + for (i = 0; i < font_subset->num_glyphs; i++) { + status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface, + font_subset->glyphs[i]); + if (unlikely (status)) + break; + + } + cairo_surface_finish (type3_surface); + cairo_surface_destroy (type3_surface); + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t *surface, + cairo_scaled_font_subset_t *font_subset) + + +{ + cairo_status_t status; + unsigned int i; + cairo_box_t font_bbox = {{0,0},{0,0}}; + cairo_box_t bbox = {{0,0},{0,0}}; + cairo_surface_t *type3_surface; + double width; + + if (font_subset->num_glyphs == 0) + return CAIRO_STATUS_SUCCESS; + +#if DEBUG_PS + _cairo_output_stream_printf (surface->final_stream, + "%% _cairo_ps_surface_emit_type3_font_subset\n"); +#endif + + _cairo_output_stream_printf (surface->final_stream, + "%%%%BeginResource: font\n"); + _cairo_output_stream_printf (surface->final_stream, + "8 dict begin\n" + "/FontType 3 def\n" + "/FontMatrix [1 0 0 1 0 0] def\n" + "/Encoding 256 array def\n" + "0 1 255 { Encoding exch /.notdef put } for\n"); + + type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font, + NULL, + _cairo_ps_emit_imagemask, + surface->font_subsets, + TRUE); + status = type3_surface->status; + if (unlikely (status)) + return status; + + for (i = 0; i < font_subset->num_glyphs; i++) { + if (font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (surface->final_stream, + "Encoding %d /%s put\n", + i, font_subset->glyph_names[i]); + } else { + _cairo_output_stream_printf (surface->final_stream, + "Encoding %d /g%d put\n", i, i); + } + } + + _cairo_output_stream_printf (surface->final_stream, + "/Glyphs [\n"); + + for (i = 0; i < font_subset->num_glyphs; i++) { + _cairo_output_stream_printf (surface->final_stream, + " { %% %d\n", i); + status = _cairo_type3_glyph_surface_emit_glyph (type3_surface, + surface->final_stream, + font_subset->glyphs[i], + &bbox, + &width); + if (unlikely (status)) + break; + + _cairo_output_stream_printf (surface->final_stream, + " }\n"); + if (i == 0) { + font_bbox.p1.x = bbox.p1.x; + font_bbox.p1.y = bbox.p1.y; + font_bbox.p2.x = bbox.p2.x; + font_bbox.p2.y = bbox.p2.y; + } else { + if (bbox.p1.x < font_bbox.p1.x) + font_bbox.p1.x = bbox.p1.x; + if (bbox.p1.y < font_bbox.p1.y) + font_bbox.p1.y = bbox.p1.y; + if (bbox.p2.x > font_bbox.p2.x) + font_bbox.p2.x = bbox.p2.x; + if (bbox.p2.y > font_bbox.p2.y) + font_bbox.p2.y = bbox.p2.y; + } + } + cairo_surface_finish (type3_surface); + cairo_surface_destroy (type3_surface); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->final_stream, + "] def\n" + "/FontBBox [%f %f %f %f] def\n" + "/BuildChar {\n" + " exch /Glyphs get\n" + " exch get\n" + " 10 dict begin exec end\n" + "} bind def\n" + "currentdict\n" + "end\n" + "/f-%d-%d exch definefont pop\n", + _cairo_fixed_to_double (font_bbox.p1.x), + - _cairo_fixed_to_double (font_bbox.p2.y), + _cairo_fixed_to_double (font_bbox.p2.x), + - _cairo_fixed_to_double (font_bbox.p1.y), + font_subset->font_id, + font_subset->subset_id); + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndResource\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_ps_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_ps_surface_t *surface = closure; + cairo_int_status_t status; + + status = _cairo_scaled_font_subset_create_glyph_names (font_subset); + if (_cairo_int_status_is_error (status)) + return status; + + status = _cairo_ps_surface_emit_type1_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_ps_surface_emit_truetype_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_ps_surface_emit_type1_font_fallback (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + ASSERT_NOT_REACHED; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_ps_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_ps_surface_t *surface = closure; + cairo_int_status_t status; + + status = _cairo_scaled_font_subset_create_glyph_names (font_subset); + if (_cairo_int_status_is_error (status)) + return status; + + status = _cairo_ps_surface_emit_type3_font_subset (surface, font_subset); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_ps_surface_emit_font_subsets (cairo_ps_surface_t *surface) +{ + cairo_status_t status; + +#if DEBUG_PS + _cairo_output_stream_printf (surface->final_stream, + "%% _cairo_ps_surface_emit_font_subsets\n"); +#endif + + status = _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, + _cairo_ps_surface_analyze_user_font_subset, + surface); + if (unlikely (status)) + return status; + + status = _cairo_scaled_font_subsets_foreach_unscaled (surface->font_subsets, + _cairo_ps_surface_emit_unscaled_font_subset, + surface); + if (unlikely (status)) + return status; + + status = _cairo_scaled_font_subsets_foreach_scaled (surface->font_subsets, + _cairo_ps_surface_emit_scaled_font_subset, + surface); + if (unlikely (status)) + return status; + + return _cairo_scaled_font_subsets_foreach_user (surface->font_subsets, + _cairo_ps_surface_emit_scaled_font_subset, + surface); +} + +static cairo_status_t +_cairo_ps_surface_emit_body (cairo_ps_surface_t *surface) +{ + char buf[4096]; + int n; + + if (ferror (surface->tmpfile) != 0) + return _cairo_error (CAIRO_STATUS_TEMP_FILE_ERROR); + + rewind (surface->tmpfile); + while ((n = fread (buf, 1, sizeof (buf), surface->tmpfile)) > 0) + _cairo_output_stream_write (surface->final_stream, buf, n); + + if (ferror (surface->tmpfile) != 0) + return _cairo_error (CAIRO_STATUS_TEMP_FILE_ERROR); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_ps_surface_emit_footer (cairo_ps_surface_t *surface) +{ + _cairo_output_stream_printf (surface->final_stream, + "%%%%Trailer\n"); + + if (surface->eps) { + _cairo_output_stream_printf (surface->final_stream, + "end restore\n"); + } + + _cairo_output_stream_printf (surface->final_stream, + "%%%%EOF\n"); +} + +static cairo_bool_t +_path_covers_bbox (cairo_ps_surface_t *surface, + cairo_path_fixed_t *path) +{ + cairo_box_t box; + + if (_cairo_path_fixed_is_box (path, &box)) { + cairo_rectangle_int_t rect; + + _cairo_box_round_to_rectangle (&box, &rect); + + /* skip trivial whole-page clips */ + if (_cairo_rectangle_intersect (&rect, &surface->page_bbox)) { + if (rect.x == surface->page_bbox.x && + rect.width == surface->page_bbox.width && + rect.y == surface->page_bbox.y && + rect.height == surface->page_bbox.height) + { + return TRUE; + } + } + } + + return FALSE; +} + +static cairo_status_t +_cairo_ps_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_ps_surface_t *surface = cairo_container_of (clipper, + cairo_ps_surface_t, + clipper); + cairo_output_stream_t *stream = surface->stream; + cairo_status_t status; + + assert (surface->paginated_mode != CAIRO_PAGINATED_MODE_ANALYZE); + +#if DEBUG_PS + _cairo_output_stream_printf (stream, + "%% _cairo_ps_surface_intersect_clip_path\n"); +#endif + + if (path == NULL) { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (stream, "Q q\n"); + + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + + return CAIRO_STATUS_SUCCESS; + } + + if (_path_covers_bbox (surface, path)) + return CAIRO_STATUS_SUCCESS; + + return _cairo_pdf_operators_clip (&surface->pdf_operators, + path, + fill_rule); +} + +/* PLRM specifies a tolerance of 5 points when matching page sizes */ +static cairo_bool_t +_ps_page_dimension_equal (int a, int b) +{ + return (abs (a - b) < 5); +} + +static const char * +_cairo_ps_surface_get_page_media (cairo_ps_surface_t *surface) +{ + int width, height, i; + char buf[50]; + cairo_page_media_t *page; + const char *page_name; + + width = _cairo_lround (surface->width); + height = _cairo_lround (surface->height); + + /* search previously used page sizes */ + cairo_list_foreach_entry (page, cairo_page_media_t, &surface->document_media, link) { + if (_ps_page_dimension_equal (width, page->width) && + _ps_page_dimension_equal (height, page->height)) + return page->name; + } + + /* search list of standard page sizes */ + page_name = NULL; + for (i = 0; i < ARRAY_LENGTH (_cairo_page_standard_media); i++) { + if (_ps_page_dimension_equal (width, _cairo_page_standard_media[i].width) && + _ps_page_dimension_equal (height, _cairo_page_standard_media[i].height)) + { + page_name = _cairo_page_standard_media[i].name; + width = _cairo_page_standard_media[i].width; + height = _cairo_page_standard_media[i].height; + break; + } + } + + page = malloc (sizeof (cairo_page_media_t)); + if (unlikely (page == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + if (page_name) { + page->name = strdup (page_name); + } else { + snprintf (buf, sizeof (buf), "%dx%dmm", + (int) _cairo_lround (surface->width * 25.4/72), + (int) _cairo_lround (surface->height * 25.4/72)); + page->name = strdup (buf); + } + + if (unlikely (page->name == NULL)) { + free (page); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + page->width = width; + page->height = height; + cairo_list_add_tail (&page->link, &surface->document_media); + + return page->name; +} + +static cairo_surface_t * +_cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, + double width, + double height) +{ + cairo_status_t status, status_ignored; + cairo_ps_surface_t *surface; + + surface = malloc (sizeof (cairo_ps_surface_t)); + if (unlikely (surface == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP; + } + + _cairo_surface_init (&surface->base, + &cairo_ps_surface_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + surface->final_stream = stream; + + surface->tmpfile = tmpfile (); + if (surface->tmpfile == NULL) { + switch (errno) { + case ENOMEM: + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + break; + default: + status = _cairo_error (CAIRO_STATUS_TEMP_FILE_ERROR); + break; + } + goto CLEANUP_SURFACE; + } + + surface->stream = _cairo_output_stream_create_for_file (surface->tmpfile); + status = _cairo_output_stream_get_status (surface->stream); + if (unlikely (status)) + goto CLEANUP_OUTPUT_STREAM; + + surface->font_subsets = _cairo_scaled_font_subsets_create_simple (); + if (unlikely (surface->font_subsets == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_OUTPUT_STREAM; + } + + _cairo_scaled_font_subsets_enable_latin_subset (surface->font_subsets, TRUE); + surface->has_creation_date = FALSE; + surface->eps = FALSE; + surface->ps_level = CAIRO_PS_LEVEL_3; + surface->ps_level_used = CAIRO_PS_LEVEL_2; + surface->width = width; + surface->height = height; + cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, height); + surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE; + surface->force_fallbacks = FALSE; + surface->content = CAIRO_CONTENT_COLOR_ALPHA; + surface->use_string_datasource = FALSE; + surface->current_pattern_is_solid_color = FALSE; + + surface->page_bbox.x = 0; + surface->page_bbox.y = 0; + surface->page_bbox.width = width; + surface->page_bbox.height = height; + + _cairo_surface_clipper_init (&surface->clipper, + _cairo_ps_surface_clipper_intersect_clip_path); + + _cairo_pdf_operators_init (&surface->pdf_operators, + surface->stream, + &surface->cairo_to_ps, + surface->font_subsets, + TRUE); + surface->num_pages = 0; + + cairo_list_init (&surface->document_media); + _cairo_array_init (&surface->dsc_header_comments, sizeof (char *)); + _cairo_array_init (&surface->dsc_setup_comments, sizeof (char *)); + _cairo_array_init (&surface->dsc_page_setup_comments, sizeof (char *)); + + surface->dsc_comment_target = &surface->dsc_header_comments; + + surface->paginated_surface = _cairo_paginated_surface_create ( + &surface->base, + CAIRO_CONTENT_COLOR_ALPHA, + &cairo_ps_surface_paginated_backend); + status = surface->paginated_surface->status; + if (status == CAIRO_STATUS_SUCCESS) { + /* paginated keeps the only reference to surface now, drop ours */ + cairo_surface_destroy (&surface->base); + return surface->paginated_surface; + } + + _cairo_scaled_font_subsets_destroy (surface->font_subsets); + CLEANUP_OUTPUT_STREAM: + status_ignored = _cairo_output_stream_destroy (surface->stream); + fclose (surface->tmpfile); + CLEANUP_SURFACE: + free (surface); + CLEANUP: + /* destroy stream on behalf of caller */ + status_ignored = _cairo_output_stream_destroy (stream); + + return _cairo_surface_create_in_error (status); +} + +/** + * cairo_ps_surface_create: + * @filename: a filename for the PS output (must be writable), %NULL may be + * used to specify no output. This will generate a PS surface that + * may be queried and used as a source, without generating a + * temporary file. + * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) + * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) + * + * Creates a PostScript surface of the specified size in points to be + * written to @filename. See cairo_ps_surface_create_for_stream() for + * a more flexible mechanism for handling the PostScript output than + * simply writing it to a named file. + * + * Note that the size of individual pages of the PostScript output can + * vary. See cairo_ps_surface_set_size(). + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_ps_surface_create (const char *filename, + double width_in_points, + double height_in_points) +{ + cairo_output_stream_t *stream; + + stream = _cairo_output_stream_create_for_filename (filename); + if (_cairo_output_stream_get_status (stream)) + return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); + + return _cairo_ps_surface_create_for_stream_internal (stream, + width_in_points, + height_in_points); +} + +/** + * cairo_ps_surface_create_for_stream: + * @write_func: a #cairo_write_func_t to accept the output data, may be %NULL + * to indicate a no-op @write_func. With a no-op @write_func, + * the surface may be queried or used as a source without + * generating any temporary files. + * @closure: the closure argument for @write_func + * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) + * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) + * + * Creates a PostScript surface of the specified size in points to be + * written incrementally to the stream represented by @write_func and + * @closure. See cairo_ps_surface_create() for a more convenient way + * to simply direct the PostScript output to a named file. + * + * Note that the size of individual pages of the PostScript + * output can vary. See cairo_ps_surface_set_size(). + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, + void *closure, + double width_in_points, + double height_in_points) +{ + cairo_output_stream_t *stream; + + stream = _cairo_output_stream_create (write_func, NULL, closure); + if (_cairo_output_stream_get_status (stream)) + return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); + + return _cairo_ps_surface_create_for_stream_internal (stream, + width_in_points, + height_in_points); +} + +static cairo_bool_t +_cairo_surface_is_ps (cairo_surface_t *surface) +{ + return surface->backend == &cairo_ps_surface_backend; +} + +/* If the abstract_surface is a paginated surface, and that paginated + * surface's target is a ps_surface, then set ps_surface to that + * target. Otherwise return FALSE. + */ +static cairo_bool_t +_extract_ps_surface (cairo_surface_t *surface, + cairo_bool_t set_error_on_failure, + cairo_ps_surface_t **ps_surface) +{ + cairo_surface_t *target; + + if (surface->status) + return FALSE; + if (surface->finished) { + if (set_error_on_failure) + _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (! _cairo_surface_is_paginated (surface)) { + if (set_error_on_failure) + _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return FALSE; + } + + target = _cairo_paginated_surface_get_target (surface); + if (target->status) { + if (set_error_on_failure) + _cairo_surface_set_error (surface, target->status); + return FALSE; + } + if (target->finished) { + if (set_error_on_failure) + _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (! _cairo_surface_is_ps (target)) { + if (set_error_on_failure) + _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return FALSE; + } + + *ps_surface = (cairo_ps_surface_t *) target; + return TRUE; +} + +/** + * cairo_ps_surface_restrict_to_level: + * @surface: a PostScript #cairo_surface_t + * @level: PostScript level + * + * Restricts the generated PostSript file to @level. See + * cairo_ps_get_levels() for a list of available level values that + * can be used here. + * + * This function should only be called before any drawing operations + * have been performed on the given surface. The simplest way to do + * this is to call this function immediately after creating the + * surface. + * + * Since: 1.6 + **/ +void +cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, + cairo_ps_level_t level) +{ + cairo_ps_surface_t *ps_surface = NULL; + + if (! _extract_ps_surface (surface, TRUE, &ps_surface)) + return; + + if (level < CAIRO_PS_LEVEL_LAST) + ps_surface->ps_level = level; +} + +/** + * cairo_ps_get_levels: + * @levels: supported level list + * @num_levels: list length + * + * Used to retrieve the list of supported levels. See + * cairo_ps_surface_restrict_to_level(). + * + * Since: 1.6 + **/ +void +cairo_ps_get_levels (cairo_ps_level_t const **levels, + int *num_levels) +{ + if (levels != NULL) + *levels = _cairo_ps_levels; + + if (num_levels != NULL) + *num_levels = CAIRO_PS_LEVEL_LAST; +} + +/** + * cairo_ps_level_to_string: + * @level: a level id + * + * Get the string representation of the given @level id. This function + * will return %NULL if @level id isn't valid. See cairo_ps_get_levels() + * for a way to get the list of valid level ids. + * + * Return value: the string associated to given level. + * + * Since: 1.6 + **/ +const char * +cairo_ps_level_to_string (cairo_ps_level_t level) +{ + if (level >= CAIRO_PS_LEVEL_LAST) + return NULL; + + return _cairo_ps_level_strings[level]; +} + +/** + * cairo_ps_surface_set_eps: + * @surface: a PostScript #cairo_surface_t + * @eps: %TRUE to output EPS format PostScript + * + * If @eps is %TRUE, the PostScript surface will output Encapsulated + * PostScript. + * + * This function should only be called before any drawing operations + * have been performed on the current page. The simplest way to do + * this is to call this function immediately after creating the + * surface. An Encapsulated PostScript file should never contain more + * than one page. + * + * Since: 1.6 + **/ +void +cairo_ps_surface_set_eps (cairo_surface_t *surface, + cairo_bool_t eps) +{ + cairo_ps_surface_t *ps_surface = NULL; + + if (! _extract_ps_surface (surface, TRUE, &ps_surface)) + return; + + ps_surface->eps = eps; +} + +/** + * cairo_ps_surface_get_eps: + * @surface: a PostScript #cairo_surface_t + * + * Check whether the PostScript surface will output Encapsulated PostScript. + * + * Return value: %TRUE if the surface will output Encapsulated PostScript. + * + * Since: 1.6 + **/ +cairo_public cairo_bool_t +cairo_ps_surface_get_eps (cairo_surface_t *surface) +{ + cairo_ps_surface_t *ps_surface = NULL; + + if (! _extract_ps_surface (surface, FALSE, &ps_surface)) + return FALSE; + + return ps_surface->eps; +} + +/** + * cairo_ps_surface_set_size: + * @surface: a PostScript #cairo_surface_t + * @width_in_points: new surface width, in points (1 point == 1/72.0 inch) + * @height_in_points: new surface height, in points (1 point == 1/72.0 inch) + * + * Changes the size of a PostScript surface for the current (and + * subsequent) pages. + * + * This function should only be called before any drawing operations + * have been performed on the current page. The simplest way to do + * this is to call this function immediately after creating the + * surface or immediately after completing a page with either + * cairo_show_page() or cairo_copy_page(). + * + * Since: 1.2 + **/ +void +cairo_ps_surface_set_size (cairo_surface_t *surface, + double width_in_points, + double height_in_points) +{ + cairo_ps_surface_t *ps_surface = NULL; + cairo_status_t status; + + if (! _extract_ps_surface (surface, TRUE, &ps_surface)) + return; + + ps_surface->width = width_in_points; + ps_surface->height = height_in_points; + cairo_matrix_init (&ps_surface->cairo_to_ps, 1, 0, 0, -1, 0, height_in_points); + _cairo_pdf_operators_set_cairo_to_pdf_matrix (&ps_surface->pdf_operators, + &ps_surface->cairo_to_ps); + status = _cairo_paginated_surface_set_size (ps_surface->paginated_surface, + width_in_points, + height_in_points); + if (status) + status = _cairo_surface_set_error (surface, status); +} + +/** + * cairo_ps_surface_dsc_comment: + * @surface: a PostScript #cairo_surface_t + * @comment: a comment string to be emitted into the PostScript output + * + * Emit a comment into the PostScript output for the given surface. + * + * The comment is expected to conform to the PostScript Language + * Document Structuring Conventions (DSC). Please see that manual for + * details on the available comments and their meanings. In + * particular, the \%\%IncludeFeature comment allows a + * device-independent means of controlling printer device features. So + * the PostScript Printer Description Files Specification will also be + * a useful reference. + * + * The comment string must begin with a percent character (\%) and the + * total length of the string (including any initial percent + * characters) must not exceed 255 characters. Violating either of + * these conditions will place @surface into an error state. But + * beyond these two conditions, this function will not enforce + * conformance of the comment with any particular specification. + * + * The comment string should not have a trailing newline. + * + * The DSC specifies different sections in which particular comments + * can appear. This function provides for comments to be emitted + * within three sections: the header, the Setup section, and the + * PageSetup section. Comments appearing in the first two sections + * apply to the entire document while comments in the BeginPageSetup + * section apply only to a single page. + * + * For comments to appear in the header section, this function should + * be called after the surface is created, but before a call to + * cairo_ps_surface_dsc_begin_setup(). + * + * For comments to appear in the Setup section, this function should + * be called after a call to cairo_ps_surface_dsc_begin_setup() but + * before a call to cairo_ps_surface_dsc_begin_page_setup(). + * + * For comments to appear in the PageSetup section, this function + * should be called after a call to + * cairo_ps_surface_dsc_begin_page_setup(). + * + * Note that it is only necessary to call + * cairo_ps_surface_dsc_begin_page_setup() for the first page of any + * surface. After a call to cairo_show_page() or cairo_copy_page() + * comments are unambiguously directed to the PageSetup section of the + * current page. But it doesn't hurt to call this function at the + * beginning of every page as that consistency may make the calling + * code simpler. + * + * As a final note, cairo automatically generates several comments on + * its own. As such, applications must not manually generate any of + * the following comments: + * + * Header section: \%!PS-Adobe-3.0, \%\%Creator, \%\%CreationDate, \%\%Pages, + * \%\%BoundingBox, \%\%DocumentData, \%\%LanguageLevel, \%\%EndComments. + * + * Setup section: \%\%BeginSetup, \%\%EndSetup + * + * PageSetup section: \%\%BeginPageSetup, \%\%PageBoundingBox, \%\%EndPageSetup. + * + * Other sections: \%\%BeginProlog, \%\%EndProlog, \%\%Page, \%\%Trailer, \%\%EOF + * + * Here is an example sequence showing how this function might be used: + * + * + * cairo_surface_t *surface = cairo_ps_surface_create (filename, width, height); + * ... + * cairo_ps_surface_dsc_comment (surface, "%%Title: My excellent document"); + * cairo_ps_surface_dsc_comment (surface, "%%Copyright: Copyright (C) 2006 Cairo Lover") + * ... + * cairo_ps_surface_dsc_begin_setup (surface); + * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor White"); + * ... + * cairo_ps_surface_dsc_begin_page_setup (surface); + * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A3"); + * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *InputSlot LargeCapacity"); + * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaType Glossy"); + * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor Blue"); + * ... draw to first page here .. + * cairo_show_page (cr); + * ... + * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A5"); + * ... + * + * + * Since: 1.2 + **/ +void +cairo_ps_surface_dsc_comment (cairo_surface_t *surface, + const char *comment) +{ + cairo_ps_surface_t *ps_surface = NULL; + cairo_status_t status; + char *comment_copy; + + if (! _extract_ps_surface (surface, TRUE, &ps_surface)) + return; + + /* A couple of sanity checks on the comment value. */ + if (comment == NULL) { + status = _cairo_surface_set_error (surface, CAIRO_STATUS_NULL_POINTER); + return; + } + + if (comment[0] != '%' || strlen (comment) > 255) { + status = _cairo_surface_set_error (surface, CAIRO_STATUS_INVALID_DSC_COMMENT); + return; + } + + /* Then, copy the comment and store it in the appropriate array. */ + comment_copy = strdup (comment); + if (unlikely (comment_copy == NULL)) { + status = _cairo_surface_set_error (surface, CAIRO_STATUS_NO_MEMORY); + return; + } + + status = _cairo_array_append (ps_surface->dsc_comment_target, &comment_copy); + if (unlikely (status)) { + free (comment_copy); + status = _cairo_surface_set_error (surface, status); + return; + } +} + +/** + * cairo_ps_surface_dsc_begin_setup: + * @surface: a PostScript #cairo_surface_t + * + * This function indicates that subsequent calls to + * cairo_ps_surface_dsc_comment() should direct comments to the Setup + * section of the PostScript output. + * + * This function should be called at most once per surface, and must + * be called before any call to cairo_ps_surface_dsc_begin_page_setup() + * and before any drawing is performed to the surface. + * + * See cairo_ps_surface_dsc_comment() for more details. + * + * Since: 1.2 + **/ +void +cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface) +{ + cairo_ps_surface_t *ps_surface = NULL; + + if (! _extract_ps_surface (surface, TRUE, &ps_surface)) + return; + + if (ps_surface->dsc_comment_target == &ps_surface->dsc_header_comments) + ps_surface->dsc_comment_target = &ps_surface->dsc_setup_comments; +} + +/** + * cairo_ps_surface_dsc_begin_page_setup: + * @surface: a PostScript #cairo_surface_t + * + * This function indicates that subsequent calls to + * cairo_ps_surface_dsc_comment() should direct comments to the + * PageSetup section of the PostScript output. + * + * This function call is only needed for the first page of a + * surface. It should be called after any call to + * cairo_ps_surface_dsc_begin_setup() and before any drawing is + * performed to the surface. + * + * See cairo_ps_surface_dsc_comment() for more details. + * + * Since: 1.2 + **/ +void +cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface) +{ + cairo_ps_surface_t *ps_surface = NULL; + + if (! _extract_ps_surface (surface, TRUE, &ps_surface)) + return; + + if (ps_surface->dsc_comment_target == &ps_surface->dsc_header_comments || + ps_surface->dsc_comment_target == &ps_surface->dsc_setup_comments) + { + ps_surface->dsc_comment_target = &ps_surface->dsc_page_setup_comments; + } +} + +static cairo_status_t +_cairo_ps_surface_finish (void *abstract_surface) +{ + cairo_status_t status, status2; + cairo_ps_surface_t *surface = abstract_surface; + int i, num_comments; + char **comments; + + status = surface->base.status; + if (unlikely (status)) + goto CLEANUP; + + _cairo_ps_surface_emit_header (surface); + + status = _cairo_ps_surface_emit_font_subsets (surface); + if (unlikely (status)) + goto CLEANUP; + + _cairo_output_stream_printf (surface->final_stream, + "%%%%EndSetup\n"); + + status = _cairo_ps_surface_emit_body (surface); + if (unlikely (status)) + goto CLEANUP; + + _cairo_ps_surface_emit_footer (surface); + +CLEANUP: + _cairo_scaled_font_subsets_destroy (surface->font_subsets); + + status2 = _cairo_output_stream_destroy (surface->stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + fclose (surface->tmpfile); + + status2 = _cairo_output_stream_destroy (surface->final_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + while (! cairo_list_is_empty (&surface->document_media)) { + cairo_page_media_t *page; + + page = cairo_list_first_entry (&surface->document_media, + cairo_page_media_t, + link); + cairo_list_del (&page->link); + free (page->name); + free (page); + } + + num_comments = _cairo_array_num_elements (&surface->dsc_header_comments); + comments = _cairo_array_index (&surface->dsc_header_comments, 0); + for (i = 0; i < num_comments; i++) + free (comments[i]); + _cairo_array_fini (&surface->dsc_header_comments); + + num_comments = _cairo_array_num_elements (&surface->dsc_setup_comments); + comments = _cairo_array_index (&surface->dsc_setup_comments, 0); + for (i = 0; i < num_comments; i++) + free (comments[i]); + _cairo_array_fini (&surface->dsc_setup_comments); + + num_comments = _cairo_array_num_elements (&surface->dsc_page_setup_comments); + comments = _cairo_array_index (&surface->dsc_page_setup_comments, 0); + for (i = 0; i < num_comments; i++) + free (comments[i]); + _cairo_array_fini (&surface->dsc_page_setup_comments); + + _cairo_surface_clipper_reset (&surface->clipper); + + return status; +} + +static cairo_int_status_t +_cairo_ps_surface_start_page (void *abstract_surface) +{ + cairo_ps_surface_t *surface = abstract_surface; + + /* Increment before print so page numbers start at 1. */ + surface->num_pages++; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_ps_surface_show_page (void *abstract_surface) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + if (surface->clipper.clip != NULL) + _cairo_surface_clipper_reset (&surface->clipper); + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->stream, + "Q Q\n" + "showpage\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +color_is_gray (double red, double green, double blue) +{ + const double epsilon = 0.00001; + + return (fabs (red - green) < epsilon && + fabs (red - blue) < epsilon); +} + +/** + * _cairo_ps_surface_acquire_source_surface_from_pattern: + * @surface: the ps surface + * @pattern: A #cairo_pattern_t of type SURFACE or RASTER_SOURCE to use as the source + * @extents: extents of the operation that is using this source + * @width: returns width of surface + * @height: returns height of surface + * @x_offset: returns x offset of surface + * @y_offset: returns y offset of surface + * @surface: returns surface of type image surface or recording surface + * @image_extra: returns image extra for image type surface + * + * Acquire source surface or raster source pattern. + **/ +static cairo_status_t +_cairo_ps_surface_acquire_source_surface_from_pattern (cairo_ps_surface_t *surface, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + int *width, + int *height, + double *x_offset, + double *y_offset, + cairo_surface_t **source_surface, + void **image_extra) +{ + cairo_status_t status; + cairo_image_surface_t *image; + + *x_offset = *y_offset = 0; + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_t *surf = ((cairo_surface_pattern_t *) pattern)->surface; + + if (surf->type == CAIRO_SURFACE_TYPE_RECORDING) { + if (surf->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) surf; + + *width = sub->extents.width; + *height = sub->extents.height; + } else { + cairo_surface_t *free_me = NULL; + cairo_recording_surface_t *recording_surface; + cairo_box_t bbox; + cairo_rectangle_int_t extents; + + recording_surface = (cairo_recording_surface_t *) surf; + if (_cairo_surface_is_snapshot (&recording_surface->base)) { + free_me = _cairo_surface_snapshot_get_target (&recording_surface->base); + recording_surface = (cairo_recording_surface_t *) free_me; + } + + status = _cairo_recording_surface_get_bbox (recording_surface, &bbox, NULL); + cairo_surface_destroy (free_me); + if (unlikely (status)) + return status; + + _cairo_box_round_to_rectangle (&bbox, &extents); + *width = extents.width; + *height = extents.height; + } + *source_surface = surf; + + return CAIRO_STATUS_SUCCESS; + } else { + status = _cairo_surface_acquire_source_image (surf, &image, image_extra); + if (unlikely (status)) + return status; + } + } break; + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: { + cairo_surface_t *surf; + cairo_box_t box; + cairo_rectangle_int_t rect; + + /* get the operation extents in pattern space */ + _cairo_box_from_rectangle (&box, extents); + _cairo_matrix_transform_bounding_box_fixed (&pattern->matrix, &box, NULL); + _cairo_box_round_to_rectangle (&box, &rect); + surf = _cairo_raster_source_pattern_acquire (pattern, &surface->base, &rect); + if (!surf) + return CAIRO_INT_STATUS_UNSUPPORTED; + assert (_cairo_surface_is_image (surf)); + image = (cairo_image_surface_t *) surf; + } break; + + case CAIRO_PATTERN_TYPE_SOLID: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + default: + ASSERT_NOT_REACHED; + break; + } + + *width = image->width; + *height = image->height; + *source_surface = &image->base; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_ps_surface_release_source_surface_from_pattern (cairo_ps_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_surface_t *source, + void *image_extra) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SURFACE: { + cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) pattern; + if (surf_pat->surface->type != CAIRO_SURFACE_TYPE_RECORDING) { + cairo_image_surface_t *image = (cairo_image_surface_t *) source; + _cairo_surface_release_source_image (surf_pat->surface, image, image_extra); + } + } break; + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + _cairo_raster_source_pattern_release (pattern, source); + break; + + case CAIRO_PATTERN_TYPE_SOLID: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + default: + + ASSERT_NOT_REACHED; + break; + } +} + +/** + * _cairo_ps_surface_create_padded_image_from_image: + * @surface: the ps surface + * @source: The source image + * @extents: extents of the operation that is using this source + * @width: returns width of padded image + * @height: returns height of padded image + * @x_offset: returns x offset of padded image + * @y_offset: returns y offset of padded image + * @image: returns the padded image or NULL if padding not required to fill @extents + * + * Creates a padded image if the source image does not fill the extents. + **/ +static cairo_status_t +_cairo_ps_surface_create_padded_image_from_image (cairo_ps_surface_t *surface, + cairo_image_surface_t *source, + const cairo_matrix_t *source_matrix, + const cairo_rectangle_int_t *extents, + int *width, + int *height, + double *x_offset, + double *y_offset, + cairo_image_surface_t **image) +{ + cairo_box_t box; + cairo_rectangle_int_t rect; + cairo_surface_t *pad_image; + cairo_surface_pattern_t pad_pattern; + int w, h; + cairo_int_status_t status; + + /* get the operation extents in pattern space */ + _cairo_box_from_rectangle (&box, extents); + _cairo_matrix_transform_bounding_box_fixed (source_matrix, &box, NULL); + _cairo_box_round_to_rectangle (&box, &rect); + + /* Check if image needs padding to fill extents. */ + w = source->width; + h = source->height; + if (_cairo_fixed_integer_ceil(box.p1.x) < 0 || + _cairo_fixed_integer_ceil(box.p1.y) < 0 || + _cairo_fixed_integer_floor(box.p2.y) > w || + _cairo_fixed_integer_floor(box.p2.y) > h) + { + pad_image = + _cairo_image_surface_create_with_pixman_format (NULL, + source->pixman_format, + rect.width, rect.height, + 0); + if (pad_image->status) + return pad_image->status; + + _cairo_pattern_init_for_surface (&pad_pattern, &source->base); + cairo_matrix_init_translate (&pad_pattern.base.matrix, rect.x, rect.y); + pad_pattern.base.extend = CAIRO_EXTEND_PAD; + status = _cairo_surface_paint (pad_image, + CAIRO_OPERATOR_SOURCE, + &pad_pattern.base, + NULL); + _cairo_pattern_fini (&pad_pattern.base); + *image = (cairo_image_surface_t *) pad_image; + *width = rect.width; + *height = rect.height; + *x_offset = rect.x; + *y_offset = rect.y; + } else { + *image = NULL; + status = CAIRO_STATUS_SUCCESS; + } + + return status; +} + +static cairo_int_status_t +_cairo_ps_surface_analyze_surface_pattern_transparency (cairo_ps_surface_t *surface, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + int width, height; + double x_offset, y_offset; + cairo_surface_t *source; + cairo_image_surface_t *image; + void *image_extra; + cairo_int_status_t status; + cairo_image_transparency_t transparency; + + status = _cairo_ps_surface_acquire_source_surface_from_pattern (surface, + pattern, + extents, + &width, + &height, + &x_offset, + &y_offset, + &source, + &image_extra); + if (unlikely (status)) + return status; + + image = (cairo_image_surface_t *) source; + if (image->base.status) + return image->base.status; + + transparency = _cairo_image_analyze_transparency (image); + switch (transparency) { + case CAIRO_IMAGE_IS_OPAQUE: + status = CAIRO_STATUS_SUCCESS; + break; + + case CAIRO_IMAGE_HAS_BILEVEL_ALPHA: + if (surface->ps_level == CAIRO_PS_LEVEL_2) { + status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; + } else { + surface->ps_level_used = CAIRO_PS_LEVEL_3; + status = CAIRO_STATUS_SUCCESS; + } + break; + + case CAIRO_IMAGE_HAS_ALPHA: + status = CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; + break; + + case CAIRO_IMAGE_UNKNOWN: + ASSERT_NOT_REACHED; + } + + _cairo_ps_surface_release_source_surface_from_pattern (surface, pattern, source, image_extra); + + return status; +} + +static cairo_bool_t +surface_pattern_supported (const cairo_surface_pattern_t *pattern) +{ + if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + return TRUE; + + if (pattern->surface->backend->acquire_source_image == NULL) + return FALSE; + + /* Does an ALPHA-only source surface even make sense? Maybe, but I + * don't think it's worth the extra code to support it. */ + +/* XXX: Need to write this function here... + content = pattern->surface->content; + if (content == CAIRO_CONTENT_ALPHA) + return FALSE; +*/ + + return TRUE; +} + +static cairo_bool_t +_gradient_pattern_supported (cairo_ps_surface_t *surface, + const cairo_pattern_t *pattern) +{ + double min_alpha, max_alpha; + + if (surface->ps_level == CAIRO_PS_LEVEL_2) + return FALSE; + + /* Alpha gradients are only supported (by flattening the alpha) + * if there is no variation in the alpha across the gradient. */ + _cairo_pattern_alpha_range (pattern, &min_alpha, &max_alpha); + if (min_alpha != max_alpha) + return FALSE; + + surface->ps_level_used = CAIRO_PS_LEVEL_3; + + return TRUE; +} + +static cairo_bool_t +pattern_supported (cairo_ps_surface_t *surface, const cairo_pattern_t *pattern) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return TRUE; + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + return _gradient_pattern_supported (surface, pattern); + + case CAIRO_PATTERN_TYPE_SURFACE: + return surface_pattern_supported ((cairo_surface_pattern_t *) pattern); + + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return TRUE; + + default: + ASSERT_NOT_REACHED; + return FALSE; + } +} + +static cairo_bool_t +mask_supported (cairo_ps_surface_t *surface, + const cairo_pattern_t *mask, + const cairo_rectangle_int_t *extents) +{ + if (surface->ps_level == CAIRO_PS_LEVEL_2) + return FALSE; + + if (mask->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) mask; + if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE) { + /* check if mask if opaque or bilevel alpha */ + if (_cairo_ps_surface_analyze_surface_pattern_transparency (surface, mask, extents) == CAIRO_INT_STATUS_SUCCESS) { + surface->ps_level_used = CAIRO_PS_LEVEL_3; + return TRUE; + } + } + } + + return FALSE; +} + +static cairo_int_status_t +_cairo_ps_surface_analyze_operation (cairo_ps_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern, + const cairo_pattern_t *mask, + const cairo_rectangle_int_t *extents) +{ + double min_alpha; + + if (surface->force_fallbacks && + surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (! pattern_supported (surface, pattern)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! (op == CAIRO_OPERATOR_SOURCE || op == CAIRO_OPERATOR_OVER)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Mask is only supported when the mask is an image with opaque or bilevel alpha. */ + if (mask && !mask_supported (surface, mask, extents)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; + + if (surface_pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { + if (pattern->extend == CAIRO_EXTEND_PAD) { + cairo_box_t box; + cairo_rectangle_int_t rect; + cairo_rectangle_int_t rec_extents; + + /* get the operation extents in pattern space */ + _cairo_box_from_rectangle (&box, extents); + _cairo_matrix_transform_bounding_box_fixed (&pattern->matrix, &box, NULL); + _cairo_box_round_to_rectangle (&box, &rect); + + /* Check if surface needs padding to fill extents */ + if (_cairo_surface_get_extents (surface_pattern->surface, &rec_extents)) { + if (_cairo_fixed_integer_ceil(box.p1.x) < rec_extents.x || + _cairo_fixed_integer_ceil(box.p1.y) < rec_extents.y || + _cairo_fixed_integer_floor(box.p2.y) > rec_extents.x + rec_extents.width || + _cairo_fixed_integer_floor(box.p2.y) > rec_extents.y + rec_extents.height) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + } + return CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN; + } + } + + if (op == CAIRO_OPERATOR_SOURCE) { + if (mask) + return CAIRO_INT_STATUS_UNSUPPORTED; + else + return CAIRO_STATUS_SUCCESS; + } + + /* CAIRO_OPERATOR_OVER is only supported for opaque patterns. If + * the pattern contains transparency, we return + * CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY to the analysis + * surface. If the analysis surface determines that there is + * anything drawn under this operation, a fallback image will be + * used. Otherwise the operation will be replayed during the + * render stage and we blend the transparency into the white + * background to convert the pattern to opaque. + */ + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE || pattern->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return _cairo_ps_surface_analyze_surface_pattern_transparency (surface, pattern, extents); + + /* Patterns whose drawn part is opaque are directly supported; + those whose drawn part is partially transparent can be + supported by flattening the alpha. */ + _cairo_pattern_alpha_range (pattern, &min_alpha, NULL); + if (CAIRO_ALPHA_IS_OPAQUE (min_alpha)) + return CAIRO_STATUS_SUCCESS; + + return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; +} + +static cairo_bool_t +_cairo_ps_surface_operation_supported (cairo_ps_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern, + const cairo_pattern_t *mask, + const cairo_rectangle_int_t *extents) +{ + return _cairo_ps_surface_analyze_operation (surface, op, pattern, mask, extents) != CAIRO_INT_STATUS_UNSUPPORTED; +} + +/* The "standard" implementation limit for PostScript string sizes is + * 65535 characters (see PostScript Language Reference, Appendix + * B). We go one short of that because we sometimes need two + * characters in a string to represent a single ASCII85 byte, (for the + * escape sequences "\\", "\(", and "\)") and we must not split these + * across two strings. So we'd be in trouble if we went right to the + * limit and one of these escape sequences just happened to land at + * the end. + */ +#define STRING_ARRAY_MAX_STRING_SIZE (65535-1) +#define STRING_ARRAY_MAX_COLUMN 72 + +typedef struct _string_array_stream { + cairo_output_stream_t base; + cairo_output_stream_t *output; + int column; + int string_size; + cairo_bool_t use_strings; +} string_array_stream_t; + +static cairo_status_t +_string_array_stream_write (cairo_output_stream_t *base, + const unsigned char *data, + unsigned int length) +{ + string_array_stream_t *stream = (string_array_stream_t *) base; + unsigned char c; + const unsigned char backslash = '\\'; + + if (length == 0) + return CAIRO_STATUS_SUCCESS; + + while (length--) { + if (stream->string_size == 0 && stream->use_strings) { + _cairo_output_stream_printf (stream->output, "("); + stream->column++; + } + + c = *data++; + if (stream->use_strings) { + switch (c) { + case '\\': + case '(': + case ')': + _cairo_output_stream_write (stream->output, &backslash, 1); + stream->column++; + stream->string_size++; + break; + } + } + /* Have to be careful to never split the final ~> sequence. */ + if (c == '~') { + _cairo_output_stream_write (stream->output, &c, 1); + stream->column++; + stream->string_size++; + + if (length-- == 0) + break; + + c = *data++; + } + _cairo_output_stream_write (stream->output, &c, 1); + stream->column++; + stream->string_size++; + + if (stream->use_strings && + stream->string_size >= STRING_ARRAY_MAX_STRING_SIZE) + { + _cairo_output_stream_printf (stream->output, ")\n"); + stream->string_size = 0; + stream->column = 0; + } + if (stream->column >= STRING_ARRAY_MAX_COLUMN) { + _cairo_output_stream_printf (stream->output, "\n "); + stream->string_size += 2; + stream->column = 1; + } + } + + return _cairo_output_stream_get_status (stream->output); +} + +static cairo_status_t +_string_array_stream_close (cairo_output_stream_t *base) +{ + cairo_status_t status; + string_array_stream_t *stream = (string_array_stream_t *) base; + + if (stream->use_strings) + _cairo_output_stream_printf (stream->output, ")\n"); + + status = _cairo_output_stream_get_status (stream->output); + + return status; +} + +/* A string_array_stream wraps an existing output stream. It takes the + * data provided to it and output one or more consecutive string + * objects, each within the standard PostScript implementation limit + * of 65k characters. + * + * The strings are each separated by a space character for easy + * inclusion within an array object, (but the array delimiters are not + * added by the string_array_stream). + * + * The string array stream is also careful to wrap the output within + * STRING_ARRAY_MAX_COLUMN columns (+/- 1). The stream also adds + * necessary escaping for special characters within a string, + * (specifically '\', '(', and ')'). + */ +static cairo_output_stream_t * +_string_array_stream_create (cairo_output_stream_t *output) +{ + string_array_stream_t *stream; + + stream = malloc (sizeof (string_array_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + _string_array_stream_write, + NULL, + _string_array_stream_close); + stream->output = output; + stream->column = 0; + stream->string_size = 0; + stream->use_strings = TRUE; + + return &stream->base; +} + +/* A base85_array_stream wraps an existing output stream. It wraps the + * output within STRING_ARRAY_MAX_COLUMN columns (+/- 1). The output + * is not enclosed in strings like string_array_stream. + */ +static cairo_output_stream_t * +_base85_array_stream_create (cairo_output_stream_t *output) +{ + string_array_stream_t *stream; + + stream = malloc (sizeof (string_array_stream_t)); + if (unlikely (stream == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_output_stream_t *) &_cairo_output_stream_nil; + } + + _cairo_output_stream_init (&stream->base, + _string_array_stream_write, + NULL, + _string_array_stream_close); + stream->output = output; + stream->column = 0; + stream->string_size = 0; + stream->use_strings = FALSE; + + return &stream->base; +} + + +/* PS Output - this section handles output of the parts of the recording + * surface we can render natively in PS. */ + +static cairo_status_t +_cairo_ps_surface_flatten_image_transparency (cairo_ps_surface_t *surface, + cairo_image_surface_t *image, + cairo_image_surface_t **opaque_image) +{ + cairo_surface_t *opaque; + cairo_surface_pattern_t pattern; + cairo_status_t status; + + opaque = cairo_image_surface_create (CAIRO_FORMAT_RGB24, + image->width, + image->height); + if (unlikely (opaque->status)) + return opaque->status; + + if (surface->content == CAIRO_CONTENT_COLOR_ALPHA) { + status = _cairo_surface_paint (opaque, + CAIRO_OPERATOR_SOURCE, + &_cairo_pattern_white.base, + NULL); + if (unlikely (status)) { + cairo_surface_destroy (opaque); + return status; + } + } + + _cairo_pattern_init_for_surface (&pattern, &image->base); + pattern.base.filter = CAIRO_FILTER_NEAREST; + status = _cairo_surface_paint (opaque, CAIRO_OPERATOR_OVER, &pattern.base, NULL); + _cairo_pattern_fini (&pattern.base); + if (unlikely (status)) { + cairo_surface_destroy (opaque); + return status; + } + + *opaque_image = (cairo_image_surface_t *) opaque; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_ps_surface_emit_base85_string (cairo_ps_surface_t *surface, + const unsigned char *data, + unsigned long length, + cairo_ps_compress_t compress, + cairo_bool_t use_strings) +{ + cairo_output_stream_t *base85_stream, *string_array_stream, *deflate_stream; + unsigned char *data_compressed; + unsigned long data_compressed_size; + cairo_status_t status, status2; + + if (use_strings) + string_array_stream = _string_array_stream_create (surface->stream); + else + string_array_stream = _base85_array_stream_create (surface->stream); + + status = _cairo_output_stream_get_status (string_array_stream); + if (unlikely (status)) + return _cairo_output_stream_destroy (string_array_stream); + + base85_stream = _cairo_base85_stream_create (string_array_stream); + status = _cairo_output_stream_get_status (base85_stream); + if (unlikely (status)) { + status2 = _cairo_output_stream_destroy (string_array_stream); + return _cairo_output_stream_destroy (base85_stream); + } + + switch (compress) { + case CAIRO_PS_COMPRESS_NONE: + _cairo_output_stream_write (base85_stream, data, length); + break; + + case CAIRO_PS_COMPRESS_LZW: + /* XXX: Should fix cairo-lzw to provide a stream-based interface + * instead. */ + data_compressed_size = length; + data_compressed = _cairo_lzw_compress ((unsigned char*)data, &data_compressed_size); + if (unlikely (data_compressed == NULL)) { + status = _cairo_output_stream_destroy (string_array_stream); + status = _cairo_output_stream_destroy (base85_stream); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + _cairo_output_stream_write (base85_stream, data_compressed, data_compressed_size); + free (data_compressed); + break; + + case CAIRO_PS_COMPRESS_DEFLATE: + deflate_stream = _cairo_deflate_stream_create (base85_stream); + if (_cairo_output_stream_get_status (deflate_stream)) { + return _cairo_output_stream_destroy (deflate_stream); + } + _cairo_output_stream_write (deflate_stream, data, length); + status = _cairo_output_stream_destroy (deflate_stream); + if (unlikely (status)) { + status2 = _cairo_output_stream_destroy (string_array_stream); + status2 = _cairo_output_stream_destroy (base85_stream); + return _cairo_output_stream_destroy (deflate_stream); + } + break; + } + status = _cairo_output_stream_destroy (base85_stream); + + /* Mark end of base85 data */ + _cairo_output_stream_printf (string_array_stream, "~>"); + status2 = _cairo_output_stream_destroy (string_array_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_image (cairo_ps_surface_t *surface, + cairo_image_surface_t *image_surf, + cairo_operator_t op, + cairo_filter_t filter, + cairo_bool_t stencil_mask) +{ + cairo_status_t status; + unsigned char *data; + unsigned long data_size; + cairo_image_surface_t *ps_image; + int x, y, i, a; + cairo_image_transparency_t transparency; + cairo_bool_t use_mask; + uint32_t *pixel32; + uint8_t *pixel8; + int bit; + cairo_image_color_t color; + const char *interpolate; + cairo_ps_compress_t compress; + const char *compress_filter; + cairo_image_surface_t *image; + + if (image_surf->base.status) + return image_surf->base.status; + + image = image_surf; + if (image->format != CAIRO_FORMAT_RGB24 && + image->format != CAIRO_FORMAT_ARGB32 && + image->format != CAIRO_FORMAT_A8 && + image->format != CAIRO_FORMAT_A1) + { + cairo_surface_t *surf; + cairo_surface_pattern_t pattern; + + surf = _cairo_image_surface_create_with_content (image_surf->base.content, + image_surf->width, + image_surf->height); + image = (cairo_image_surface_t *) surf; + if (surf->status) { + status = surf->status; + goto bail0; + } + + _cairo_pattern_init_for_surface (&pattern, &image_surf->base); + status = _cairo_surface_paint (surf, + CAIRO_OPERATOR_SOURCE, &pattern.base, + NULL); + _cairo_pattern_fini (&pattern.base); + if (unlikely (status)) + goto bail0; + } + ps_image = image; + + switch (filter) { + default: + case CAIRO_FILTER_GOOD: + case CAIRO_FILTER_BEST: + case CAIRO_FILTER_BILINEAR: + interpolate = "true"; + break; + case CAIRO_FILTER_FAST: + case CAIRO_FILTER_NEAREST: + case CAIRO_FILTER_GAUSSIAN: + interpolate = "false"; + break; + } + + if (stencil_mask) { + use_mask = FALSE; + color = CAIRO_IMAGE_IS_MONOCHROME; + transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA; + } else { + transparency = _cairo_image_analyze_transparency (image); + + /* PostScript can not represent the alpha channel, so we blend the + current image over a white (or black for CONTENT_COLOR + surfaces) RGB surface to eliminate it. */ + + if (op == CAIRO_OPERATOR_SOURCE || + transparency == CAIRO_IMAGE_HAS_ALPHA || + (transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA && + surface->ps_level == CAIRO_PS_LEVEL_2)) + { + status = _cairo_ps_surface_flatten_image_transparency (surface, + image, + &ps_image); + if (unlikely (status)) + return status; + + use_mask = FALSE; + } else if (transparency == CAIRO_IMAGE_IS_OPAQUE) { + use_mask = FALSE; + } else { /* transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA */ + use_mask = TRUE; + } + + color = _cairo_image_analyze_color (ps_image); + } + + /* Type 2 (mask and image interleaved) has the mask and image + * samples interleaved by row. The mask row is first, one bit per + * pixel with (bit 7 first). The row is padded to byte + * boundaries. The image data is 3 bytes per pixel RGB format. */ + switch (color) { + default: + case CAIRO_IMAGE_UNKNOWN_COLOR: + ASSERT_NOT_REACHED; + case CAIRO_IMAGE_IS_COLOR: + data_size = ps_image->width * 3; + break; + case CAIRO_IMAGE_IS_GRAYSCALE: + data_size = ps_image->width; + break; + case CAIRO_IMAGE_IS_MONOCHROME: + data_size = (ps_image->width + 7)/8; + break; + } + if (use_mask) + data_size += (ps_image->width + 7)/8; + data_size *= ps_image->height; + data = malloc (data_size); + if (unlikely (data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto bail1; + } + + i = 0; + for (y = 0; y < ps_image->height; y++) { + if (stencil_mask || use_mask) { + /* mask row */ + if (ps_image->format == CAIRO_FORMAT_A1) { + pixel8 = (uint8_t *) (ps_image->data + y * ps_image->stride); + + for (x = 0; x < (ps_image->width + 7) / 8; x++, pixel8++) { + a = *pixel8; + a = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (a); + data[i++] = a; + } + } else { + pixel8 = (uint8_t *) (ps_image->data + y * ps_image->stride); + pixel32 = (uint32_t *) (ps_image->data + y * ps_image->stride); + bit = 7; + for (x = 0; x < ps_image->width; x++) { + if (ps_image->format == CAIRO_FORMAT_ARGB32) { + a = (*pixel32 & 0xff000000) >> 24; + pixel32++; + } else { + a = *pixel8; + pixel8++; + } + + if (transparency == CAIRO_IMAGE_HAS_ALPHA) { + data[i++] = a; + } else { /* transparency == CAIRO_IMAGE_HAS_BILEVEL_ALPHA or CAIRO_IMAGE_IS_OPAQUE */ + if (bit == 7) + data[i] = 0; + if (a != 0) + data[i] |= (1 << bit); + bit--; + if (bit < 0) { + bit = 7; + i++; + } + } + } + if (bit != 7) + i++; + } + } + if (stencil_mask) + continue; + + /* image row*/ + pixel32 = (uint32_t *) (ps_image->data + y * ps_image->stride); + bit = 7; + for (x = 0; x < ps_image->width; x++, pixel32++) { + int r, g, b; + + if (ps_image->format == CAIRO_FORMAT_ARGB32) { + /* At this point ARGB32 images are either opaque or + * bilevel alpha so we don't need to unpremultiply. */ + if (((*pixel32 & 0xff000000) >> 24) == 0) { + r = g = b = 0; + } else { + r = (*pixel32 & 0x00ff0000) >> 16; + g = (*pixel32 & 0x0000ff00) >> 8; + b = (*pixel32 & 0x000000ff) >> 0; + } + } else if (ps_image->format == CAIRO_FORMAT_RGB24) { + r = (*pixel32 & 0x00ff0000) >> 16; + g = (*pixel32 & 0x0000ff00) >> 8; + b = (*pixel32 & 0x000000ff) >> 0; + } else { + r = g = b = 0; + } + + switch (color) { + case CAIRO_IMAGE_IS_COLOR: + case CAIRO_IMAGE_UNKNOWN_COLOR: + data[i++] = r; + data[i++] = g; + data[i++] = b; + break; + + case CAIRO_IMAGE_IS_GRAYSCALE: + data[i++] = r; + break; + + case CAIRO_IMAGE_IS_MONOCHROME: + if (bit == 7) + data[i] = 0; + if (r != 0) + data[i] |= (1 << bit); + bit--; + if (bit < 0) { + bit = 7; + i++; + } + break; + } + } + if (bit != 7) + i++; + } + + if (surface->ps_level == CAIRO_PS_LEVEL_2) { + compress = CAIRO_PS_COMPRESS_LZW; + compress_filter = "LZWDecode"; + } else { + compress = CAIRO_PS_COMPRESS_DEFLATE; + compress_filter = "FlateDecode"; + surface->ps_level_used = CAIRO_PS_LEVEL_3; + } + + if (surface->use_string_datasource) { + /* Emit the image data as a base85-encoded string which will + * be used as the data source for the image operator later. */ + _cairo_output_stream_printf (surface->stream, + "/CairoImageData [\n"); + + status = _cairo_ps_surface_emit_base85_string (surface, + data, + data_size, + compress, + TRUE); + if (unlikely (status)) + goto bail2; + + _cairo_output_stream_printf (surface->stream, + "] def\n"); + _cairo_output_stream_printf (surface->stream, + "/CairoImageDataIndex 0 def\n"); + } + + if (use_mask) { + _cairo_output_stream_printf (surface->stream, + "%s setcolorspace\n" + "5 dict dup begin\n" + " /ImageType 3 def\n" + " /InterleaveType 2 def\n" + " /DataDict 8 dict def\n" + " DataDict begin\n" + " /ImageType 1 def\n" + " /Width %d def\n" + " /Height %d def\n" + " /Interpolate %s def\n" + " /BitsPerComponent %d def\n" + " /Decode [ %s ] def\n", + color == CAIRO_IMAGE_IS_COLOR ? "/DeviceRGB" : "/DeviceGray", + ps_image->width, + ps_image->height, + interpolate, + color == CAIRO_IMAGE_IS_MONOCHROME ? 1 : 8, + color == CAIRO_IMAGE_IS_COLOR ? "0 1 0 1 0 1" : "0 1"); + + if (surface->use_string_datasource) { + _cairo_output_stream_printf (surface->stream, + " /DataSource {\n" + " CairoImageData CairoImageDataIndex get\n" + " /CairoImageDataIndex CairoImageDataIndex 1 add def\n" + " CairoImageDataIndex CairoImageData length 1 sub gt\n" + " { /CairoImageDataIndex 0 def } if\n" + " } /ASCII85Decode filter /%s filter def\n", + compress_filter); + } else { + _cairo_output_stream_printf (surface->stream, + " /DataSource currentfile /ASCII85Decode filter /%s filter def\n", + compress_filter); + } + + _cairo_output_stream_printf (surface->stream, + " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" + " end\n" + " /MaskDict 8 dict def\n" + " MaskDict begin\n" + " /ImageType 1 def\n" + " /Width %d def\n" + " /Height %d def\n" + " /Interpolate %s def\n" + " /BitsPerComponent 1 def\n" + " /Decode [ 1 0 ] def\n" + " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" + " end\n" + "end\n" + "image\n", + ps_image->height, + ps_image->width, + ps_image->height, + interpolate, + ps_image->height); + } else { + if (!stencil_mask) { + _cairo_output_stream_printf (surface->stream, + "%s setcolorspace\n", + color == CAIRO_IMAGE_IS_COLOR ? "/DeviceRGB" : "/DeviceGray"); + } + _cairo_output_stream_printf (surface->stream, + "8 dict dup begin\n" + " /ImageType 1 def\n" + " /Width %d def\n" + " /Height %d def\n" + " /Interpolate %s def\n" + " /BitsPerComponent %d def\n" + " /Decode [ %s ] def\n", + ps_image->width, + ps_image->height, + interpolate, + color == CAIRO_IMAGE_IS_MONOCHROME ? 1 : 8, + stencil_mask ? "1 0" : color == CAIRO_IMAGE_IS_COLOR ? "0 1 0 1 0 1" : "0 1"); + if (surface->use_string_datasource) { + _cairo_output_stream_printf (surface->stream, + " /DataSource {\n" + " CairoImageData CairoImageDataIndex get\n" + " /CairoImageDataIndex CairoImageDataIndex 1 add def\n" + " CairoImageDataIndex CairoImageData length 1 sub gt\n" + " { /CairoImageDataIndex 0 def } if\n" + " } /ASCII85Decode filter /%s filter def\n", + compress_filter); + } else { + _cairo_output_stream_printf (surface->stream, + " /DataSource currentfile /ASCII85Decode filter /%s filter def\n", + compress_filter); + } + + _cairo_output_stream_printf (surface->stream, + " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" + "end\n" + "%s\n", + ps_image->height, + stencil_mask ? "imagemask" : "image"); + } + + if (!surface->use_string_datasource) { + /* Emit the image data as a base85-encoded string which will + * be used as the data source for the image operator. */ + status = _cairo_ps_surface_emit_base85_string (surface, + data, + data_size, + compress, + FALSE); + _cairo_output_stream_printf (surface->stream, "\n"); + } else { + status = CAIRO_STATUS_SUCCESS; + } + +bail2: + free (data); + +bail1: + if (!use_mask && ps_image != image) + cairo_surface_destroy (&ps_image->base); + +bail0: + if (image != image_surf) + cairo_surface_destroy (&image->base); + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_jpeg_image (cairo_ps_surface_t *surface, + cairo_surface_t *source, + int width, + int height) +{ + cairo_status_t status; + const unsigned char *mime_data; + unsigned long mime_data_length; + cairo_image_info_t info; + const char *colorspace; + const char *decode; + + cairo_surface_get_mime_data (source, CAIRO_MIME_TYPE_JPEG, + &mime_data, &mime_data_length); + if (unlikely (source->status)) + return source->status; + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_image_info_get_jpeg_info (&info, mime_data, mime_data_length); + if (unlikely (status)) + return status; + + switch (info.num_components) { + case 1: + colorspace = "/DeviceGray"; + decode = "0 1"; + break; + case 3: + colorspace = "/DeviceRGB"; + decode = "0 1 0 1 0 1"; + break; + case 4: + colorspace = "/DeviceCMYK"; + decode = "0 1 0 1 0 1 0 1"; + break; + default: + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (surface->use_string_datasource) { + /* Emit the image data as a base85-encoded string which will + * be used as the data source for the image operator later. */ + _cairo_output_stream_printf (surface->stream, + "/CairoImageData [\n"); + + status = _cairo_ps_surface_emit_base85_string (surface, + mime_data, + mime_data_length, + CAIRO_PS_COMPRESS_NONE, + TRUE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->stream, + "] def\n"); + _cairo_output_stream_printf (surface->stream, + "/CairoImageDataIndex 0 def\n"); + } + + _cairo_output_stream_printf (surface->stream, + "%s setcolorspace\n" + "8 dict dup begin\n" + " /ImageType 1 def\n" + " /Width %d def\n" + " /Height %d def\n" + " /BitsPerComponent %d def\n" + " /Decode [ %s ] def\n", + colorspace, + info.width, + info.height, + info.bits_per_component, + decode); + + if (surface->use_string_datasource) { + _cairo_output_stream_printf (surface->stream, + " /DataSource {\n" + " CairoImageData CairoImageDataIndex get\n" + " /CairoImageDataIndex CairoImageDataIndex 1 add def\n" + " CairoImageDataIndex CairoImageData length 1 sub gt\n" + " { /CairoImageDataIndex 0 def } if\n" + " } /ASCII85Decode filter /DCTDecode filter def\n"); + } else { + _cairo_output_stream_printf (surface->stream, + " /DataSource currentfile /ASCII85Decode filter /DCTDecode filter def\n"); + } + + _cairo_output_stream_printf (surface->stream, + " /ImageMatrix [ 1 0 0 -1 0 %d ] def\n" + "end\n" + "image\n", + info.height); + + if (!surface->use_string_datasource) { + /* Emit the image data as a base85-encoded string which will + * be used as the data source for the image operator. */ + status = _cairo_ps_surface_emit_base85_string (surface, + mime_data, + mime_data_length, + CAIRO_PS_COMPRESS_NONE, + FALSE); + } + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_recording_surface (cairo_ps_surface_t *surface, + cairo_surface_t *recording_surface) +{ + double old_width, old_height; + cairo_matrix_t old_cairo_to_ps; + cairo_content_t old_content; + cairo_rectangle_int_t old_page_bbox; + cairo_surface_t *free_me = NULL; + cairo_surface_clipper_t old_clipper; + cairo_box_t bbox; + cairo_int_status_t status; + + old_content = surface->content; + old_width = surface->width; + old_height = surface->height; + old_page_bbox = surface->page_bbox; + old_cairo_to_ps = surface->cairo_to_ps; + old_clipper = surface->clipper; + _cairo_surface_clipper_init (&surface->clipper, + _cairo_ps_surface_clipper_intersect_clip_path); + + if (_cairo_surface_is_snapshot (recording_surface)) + free_me = recording_surface = _cairo_surface_snapshot_get_target (recording_surface); + + status = + _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface, + &bbox, + NULL); + if (unlikely (status)) + goto err; + +#if DEBUG_PS + _cairo_output_stream_printf (surface->stream, + "%% _cairo_ps_surface_emit_recording_surface (%f, %f), (%f, %f)\n", + _cairo_fixed_to_double (bbox.p1.x), + _cairo_fixed_to_double (bbox.p1.y), + _cairo_fixed_to_double (bbox.p2.x), + _cairo_fixed_to_double (bbox.p2.y)); +#endif + + surface->width = _cairo_fixed_to_double (bbox.p2.x - bbox.p1.x); + surface->height = _cairo_fixed_to_double (bbox.p2.y - bbox.p1.y); + _cairo_box_round_to_rectangle (&bbox, &surface->page_bbox); + + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, surface->height); + _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, + &surface->cairo_to_ps); + _cairo_output_stream_printf (surface->stream, " q\n"); + + if (recording_surface->content == CAIRO_CONTENT_COLOR) { + surface->content = CAIRO_CONTENT_COLOR; + _cairo_output_stream_printf (surface->stream, + " 0 g %d %d %d %d rectfill\n", + surface->page_bbox.x, + surface->page_bbox.y, + surface->page_bbox.width, + surface->page_bbox.height); + } + + status = _cairo_recording_surface_replay_region (recording_surface, + NULL, + &surface->base, + CAIRO_RECORDING_REGION_NATIVE); + assert (status != CAIRO_INT_STATUS_UNSUPPORTED); + if (unlikely (status)) + goto err; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto err; + + _cairo_output_stream_printf (surface->stream, " Q\n"); + + _cairo_surface_clipper_reset (&surface->clipper); + surface->clipper = old_clipper; + surface->content = old_content; + surface->width = old_width; + surface->height = old_height; + surface->page_bbox = old_page_bbox; + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + surface->cairo_to_ps = old_cairo_to_ps; + + _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, + &surface->cairo_to_ps); + +err: + cairo_surface_destroy (free_me); + return status; +} + +static cairo_int_status_t +_cairo_ps_surface_emit_recording_subsurface (cairo_ps_surface_t *surface, + cairo_surface_t *recording_surface, + const cairo_rectangle_int_t *extents) +{ + double old_width, old_height; + cairo_matrix_t old_cairo_to_ps; + cairo_content_t old_content; + cairo_rectangle_int_t old_page_bbox; + cairo_surface_clipper_t old_clipper; + cairo_surface_t *free_me = NULL; + cairo_int_status_t status; + + old_content = surface->content; + old_width = surface->width; + old_height = surface->height; + old_page_bbox = surface->page_bbox; + old_cairo_to_ps = surface->cairo_to_ps; + old_clipper = surface->clipper; + _cairo_surface_clipper_init (&surface->clipper, + _cairo_ps_surface_clipper_intersect_clip_path); + +#if DEBUG_PS + _cairo_output_stream_printf (surface->stream, + "%% _cairo_ps_surface_emit_recording_subsurface (%d, %d), (%d, %d)\n", + extents->x, extents->y, + extents->width, extents->height); +#endif + + surface->page_bbox.x = surface->page_bbox.y = 0; + surface->page_bbox.width = surface->width = extents->width; + surface->page_bbox.height = surface->height = extents->height; + + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, surface->height); + _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, + &surface->cairo_to_ps); + _cairo_output_stream_printf (surface->stream, " q\n"); + + if (_cairo_surface_is_snapshot (recording_surface)) + free_me = recording_surface = _cairo_surface_snapshot_get_target (recording_surface); + + if (recording_surface->content == CAIRO_CONTENT_COLOR) { + surface->content = CAIRO_CONTENT_COLOR; + _cairo_output_stream_printf (surface->stream, + " 0 g %d %d %d %d rectfill\n", + surface->page_bbox.x, + surface->page_bbox.y, + surface->page_bbox.width, + surface->page_bbox.height); + } + + status = _cairo_recording_surface_replay_region (recording_surface, + extents, + &surface->base, + CAIRO_RECORDING_REGION_NATIVE); + assert (status != CAIRO_INT_STATUS_UNSUPPORTED); + if (unlikely (status)) + goto err; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto err; + + _cairo_output_stream_printf (surface->stream, " Q\n"); + + _cairo_surface_clipper_reset (&surface->clipper); + surface->clipper = old_clipper; + surface->content = old_content; + surface->width = old_width; + surface->height = old_height; + surface->page_bbox = old_page_bbox; + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + surface->cairo_to_ps = old_cairo_to_ps; + + _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators, + &surface->cairo_to_ps); + +err: + cairo_surface_destroy (free_me); + return status; +} + +static void +_cairo_ps_surface_flatten_transparency (cairo_ps_surface_t *surface, + const cairo_color_t *color, + double *red, + double *green, + double *blue) +{ + *red = color->red; + *green = color->green; + *blue = color->blue; + + if (! CAIRO_COLOR_IS_OPAQUE (color)) { + *red *= color->alpha; + *green *= color->alpha; + *blue *= color->alpha; + if (surface->content == CAIRO_CONTENT_COLOR_ALPHA) { + double one_minus_alpha = 1. - color->alpha; + *red += one_minus_alpha; + *green += one_minus_alpha; + *blue += one_minus_alpha; + } + } +} + +static void +_cairo_ps_surface_emit_solid_pattern (cairo_ps_surface_t *surface, + cairo_solid_pattern_t *pattern) +{ + double red, green, blue; + + _cairo_ps_surface_flatten_transparency (surface, &pattern->color, &red, &green, &blue); + + if (color_is_gray (red, green, blue)) + _cairo_output_stream_printf (surface->stream, + "%f g\n", + red); + else + _cairo_output_stream_printf (surface->stream, + "%f %f %f rg\n", + red, green, blue); +} + +static cairo_status_t +_cairo_ps_surface_emit_surface (cairo_ps_surface_t *surface, + cairo_pattern_t *source_pattern, + cairo_surface_t *source_surface, + cairo_operator_t op, + int width, + int height, + cairo_bool_t stencil_mask) +{ + cairo_int_status_t status; + + if (source_pattern->type == CAIRO_PATTERN_TYPE_SURFACE && + source_pattern->extend != CAIRO_EXTEND_PAD) + { + cairo_surface_t *surf = ((cairo_surface_pattern_t *) source_pattern)->surface; + + status = _cairo_ps_surface_emit_jpeg_image (surface, surf, width, height); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + if (source_surface->type == CAIRO_SURFACE_TYPE_RECORDING) { + if (source_surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source_surface; + status = _cairo_ps_surface_emit_recording_subsurface (surface, sub->target, &sub->extents); + } else { + status = _cairo_ps_surface_emit_recording_surface (surface, source_surface); + } + } else { + cairo_image_surface_t *image = (cairo_image_surface_t *) source_surface; + + status = _cairo_ps_surface_emit_image (surface, image, + op, source_pattern->filter, stencil_mask); + } + + return status; +} + + +static void +_path_fixed_init_rectangle (cairo_path_fixed_t *path, + cairo_rectangle_int_t *rect) +{ + cairo_status_t status; + + _cairo_path_fixed_init (path); + + status = _cairo_path_fixed_move_to (path, + _cairo_fixed_from_int (rect->x), + _cairo_fixed_from_int (rect->y)); + assert (status == CAIRO_STATUS_SUCCESS); + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (rect->width), + _cairo_fixed_from_int (0)); + assert (status == CAIRO_STATUS_SUCCESS); + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (0), + _cairo_fixed_from_int (rect->height)); + assert (status == CAIRO_STATUS_SUCCESS); + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (-rect->width), + _cairo_fixed_from_int (0)); + assert (status == CAIRO_STATUS_SUCCESS); + + status = _cairo_path_fixed_close_path (path); + assert (status == CAIRO_STATUS_SUCCESS); +} + +static cairo_status_t +_cairo_ps_surface_paint_surface (cairo_ps_surface_t *surface, + cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents, + cairo_operator_t op, + cairo_bool_t stencil_mask) +{ + cairo_status_t status; + int width, height; + cairo_matrix_t cairo_p2d, ps_p2d; + cairo_path_fixed_t path; + double x_offset, y_offset; + cairo_surface_t *source; + cairo_image_surface_t *image = NULL; + void *image_extra; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + status = _cairo_ps_surface_acquire_source_surface_from_pattern (surface, + pattern, + extents, + &width, &height, + &x_offset, &y_offset, + &source, + &image_extra); + if (unlikely (status)) + return status; + + if (pattern->extend == CAIRO_EXTEND_PAD && + pattern->type == CAIRO_PATTERN_TYPE_SURFACE && + ((cairo_surface_pattern_t *)pattern)->surface->type == CAIRO_SURFACE_TYPE_IMAGE) { + cairo_image_surface_t *img; + + img = (cairo_image_surface_t *) source; + status = _cairo_ps_surface_create_padded_image_from_image (surface, + img, + &pattern->matrix, + extents, + &width, &height, + &x_offset, &y_offset, + &image); + if (unlikely (status)) + goto release_source; + } + + _path_fixed_init_rectangle (&path, extents); + status = _cairo_pdf_operators_clip (&surface->pdf_operators, + &path, + CAIRO_FILL_RULE_WINDING); + _cairo_path_fixed_fini (&path); + if (unlikely (status)) + goto release_source; + + cairo_p2d = pattern->matrix; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_FALLBACK) { + double x_scale = cairo_p2d.xx; + double y_scale = cairo_p2d.yy; + + _cairo_output_stream_printf (surface->stream, + "%% Fallback Image: x=%f y=%f w=%d h=%d ", + -cairo_p2d.x0/x_scale, + -cairo_p2d.y0/y_scale, + (int)(width/x_scale), + (int)(height/y_scale)); + if (x_scale == y_scale) { + _cairo_output_stream_printf (surface->stream, + "res=%fppi ", + x_scale*72); + } else { + _cairo_output_stream_printf (surface->stream, + "res=%fx%fppi ", + x_scale*72, + y_scale*72); + } + _cairo_output_stream_printf (surface->stream, + "size=%ld\n", + (long)width*height*3); + } else { + if (op == CAIRO_OPERATOR_SOURCE) { + _cairo_output_stream_printf (surface->stream, + "%d g 0 0 %f %f rectfill\n", + surface->content == CAIRO_CONTENT_COLOR ? 0 : 1, + surface->width, + surface->height); + } + } + + status = cairo_matrix_invert (&cairo_p2d); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + ps_p2d = surface->cairo_to_ps; + cairo_matrix_multiply (&ps_p2d, &cairo_p2d, &ps_p2d); + cairo_matrix_translate (&ps_p2d, x_offset, y_offset); + cairo_matrix_translate (&ps_p2d, 0.0, height); + cairo_matrix_scale (&ps_p2d, 1.0, -1.0); + + if (! _cairo_matrix_is_identity (&ps_p2d)) { + _cairo_output_stream_printf (surface->stream, "[ "); + _cairo_output_stream_print_matrix (surface->stream, &ps_p2d); + _cairo_output_stream_printf (surface->stream, " ] concat\n"); + } + + status = _cairo_ps_surface_emit_surface (surface, + pattern, + image ? &image->base : source, + op, + width, height, + stencil_mask); + + release_source: + if (image) + cairo_surface_destroy (&image->base); + + _cairo_ps_surface_release_source_surface_from_pattern (surface, pattern, source, image_extra); + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_surface_pattern (cairo_ps_surface_t *surface, + cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents, + cairo_operator_t op) +{ + cairo_status_t status; + int pattern_width = 0; /* squelch bogus compiler warning */ + int pattern_height = 0; /* squelch bogus compiler warning */ + double xstep, ystep; + cairo_matrix_t cairo_p2d, ps_p2d; + cairo_bool_t old_use_string_datasource; + double x_offset, y_offset; + cairo_surface_t *source; + cairo_image_surface_t *image = NULL; + void *image_extra; + + cairo_p2d = pattern->matrix; + status = cairo_matrix_invert (&cairo_p2d); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + status = _cairo_ps_surface_acquire_source_surface_from_pattern (surface, + pattern, + extents, + &pattern_width, &pattern_height, + &x_offset, &y_offset, + &source, + &image_extra); + if (unlikely (status)) + return status; + + if (pattern->extend == CAIRO_EXTEND_PAD) { + cairo_image_surface_t *img; + + assert (source->type == CAIRO_SURFACE_TYPE_IMAGE); + img = (cairo_image_surface_t *) source; + status = _cairo_ps_surface_create_padded_image_from_image (surface, + img, + &pattern->matrix, + extents, + &pattern_width, &pattern_height, + &x_offset, &y_offset, + &image); + if (unlikely (status)) + goto release_source; + } + if (unlikely (status)) + goto release_source; + + switch (pattern->extend) { + case CAIRO_EXTEND_PAD: + case CAIRO_EXTEND_NONE: + { + /* In PS/PDF, (as far as I can tell), all patterns are + * repeating. So we support cairo's EXTEND_NONE semantics + * by setting the repeat step size to a size large enough + * to guarantee that no more than a single occurrence will + * be visible. + * + * First, map the surface extents into pattern space (since + * xstep and ystep are in pattern space). Then use an upper + * bound on the length of the diagonal of the pattern image + * and the surface as repeat size. This guarantees to never + * repeat visibly. + */ + double x1 = 0.0, y1 = 0.0; + double x2 = surface->width, y2 = surface->height; + _cairo_matrix_transform_bounding_box (&pattern->matrix, + &x1, &y1, &x2, &y2, + NULL); + + /* Rather than computing precise bounds of the union, just + * add the surface extents unconditionally. We only + * required an answer that's large enough, we don't really + * care if it's not as tight as possible.*/ + xstep = ystep = ceil ((x2 - x1) + (y2 - y1) + + pattern_width + pattern_height); + break; + } + case CAIRO_EXTEND_REPEAT: + xstep = pattern_width; + ystep = pattern_height; + break; + case CAIRO_EXTEND_REFLECT: + xstep = pattern_width*2; + ystep = pattern_height*2; + break; + /* All the rest (if any) should have been analyzed away, so these + * cases should be unreachable. */ + default: + ASSERT_NOT_REACHED; + xstep = 0; + ystep = 0; + } + + _cairo_output_stream_printf (surface->stream, + "/CairoPattern {\n"); + + old_use_string_datasource = surface->use_string_datasource; + surface->use_string_datasource = TRUE; + if (op == CAIRO_OPERATOR_SOURCE) { + _cairo_output_stream_printf (surface->stream, + "%d g 0 0 %f %f rectfill\n", + surface->content == CAIRO_CONTENT_COLOR ? 0 : 1, + xstep, ystep); + } + status = _cairo_ps_surface_emit_surface (surface, + pattern, + image ? &image->base : source, + op, + pattern_width, pattern_height, FALSE); + if (unlikely (status)) + goto release_source; + + surface->use_string_datasource = old_use_string_datasource; + _cairo_output_stream_printf (surface->stream, + "} bind def\n"); + + _cairo_output_stream_printf (surface->stream, + "<< /PatternType 1\n" + " /PaintType 1\n" + " /TilingType 1\n"); + _cairo_output_stream_printf (surface->stream, + " /XStep %f /YStep %f\n", + xstep, ystep); + + if (pattern->extend == CAIRO_EXTEND_REFLECT) { + _cairo_output_stream_printf (surface->stream, + " /BBox [0 0 %d %d]\n" + " /PaintProc {\n" + " pop CairoPattern\n" + " [-1 0 0 1 %d 0] concat CairoPattern\n" + " [ 1 0 0 -1 0 %d] concat CairoPattern\n" + " [-1 0 0 1 %d 0] concat CairoPattern\n" + " CairoPattern\n" + " } bind\n", + pattern_width*2, pattern_height*2, + pattern_width*2, + pattern_height*2, + pattern_width*2); + } else { + if (op == CAIRO_OPERATOR_SOURCE) { + _cairo_output_stream_printf (surface->stream, + " /BBox [0 0 %f %f]\n", + xstep, ystep); + } else { + _cairo_output_stream_printf (surface->stream, + " /BBox [0 0 %d %d]\n", + pattern_width, pattern_height); + } + _cairo_output_stream_printf (surface->stream, + " /PaintProc { pop CairoPattern }\n"); + } + + _cairo_output_stream_printf (surface->stream, + ">>\n"); + + cairo_p2d = pattern->matrix; + status = cairo_matrix_invert (&cairo_p2d); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + cairo_matrix_init_identity (&ps_p2d); + cairo_matrix_translate (&ps_p2d, 0.0, surface->height); + cairo_matrix_scale (&ps_p2d, 1.0, -1.0); + cairo_matrix_multiply (&ps_p2d, &cairo_p2d, &ps_p2d); + cairo_matrix_translate (&ps_p2d, 0.0, pattern_height); + cairo_matrix_scale (&ps_p2d, 1.0, -1.0); + + _cairo_output_stream_printf (surface->stream, "[ "); + _cairo_output_stream_print_matrix (surface->stream, &ps_p2d); + _cairo_output_stream_printf (surface->stream, + " ]\n" + "makepattern setpattern\n"); + + release_source: + if (image) + cairo_surface_destroy (&image->base); + + _cairo_ps_surface_release_source_surface_from_pattern (surface, pattern, source, image_extra); + + return status; +} + +typedef struct _cairo_ps_color_stop { + double offset; + double color[4]; +} cairo_ps_color_stop_t; + +static void +_cairo_ps_surface_emit_linear_colorgradient (cairo_ps_surface_t *surface, + cairo_ps_color_stop_t *stop1, + cairo_ps_color_stop_t *stop2) +{ + _cairo_output_stream_printf (surface->stream, + " << /FunctionType 2\n" + " /Domain [ 0 1 ]\n" + " /C0 [ %f %f %f ]\n" + " /C1 [ %f %f %f ]\n" + " /N 1\n" + " >>\n", + stop1->color[0], + stop1->color[1], + stop1->color[2], + stop2->color[0], + stop2->color[1], + stop2->color[2]); +} + +static void +_cairo_ps_surface_emit_stitched_colorgradient (cairo_ps_surface_t *surface, + unsigned int n_stops, + cairo_ps_color_stop_t stops[]) +{ + unsigned int i; + + _cairo_output_stream_printf (surface->stream, + "<< /FunctionType 3\n" + " /Domain [ 0 1 ]\n" + " /Functions [\n"); + for (i = 0; i < n_stops - 1; i++) + _cairo_ps_surface_emit_linear_colorgradient (surface, &stops[i], &stops[i+1]); + + _cairo_output_stream_printf (surface->stream, " ]\n"); + + _cairo_output_stream_printf (surface->stream, " /Bounds [ "); + for (i = 1; i < n_stops-1; i++) + _cairo_output_stream_printf (surface->stream, "%f ", stops[i].offset); + _cairo_output_stream_printf (surface->stream, "]\n"); + + _cairo_output_stream_printf (surface->stream, " /Encode [ 1 1 %d { pop 0 1 } for ]\n", + n_stops - 1); + + _cairo_output_stream_printf (surface->stream, ">>\n"); +} + +static void +calc_gradient_color (cairo_ps_color_stop_t *new_stop, + cairo_ps_color_stop_t *stop1, + cairo_ps_color_stop_t *stop2) +{ + int i; + double offset = stop1->offset / (stop1->offset + 1.0 - stop2->offset); + + for (i = 0; i < 4; i++) + new_stop->color[i] = stop1->color[i] + offset*(stop2->color[i] - stop1->color[i]); +} + +#define COLOR_STOP_EPSILON 1e-6 + +static cairo_status_t +_cairo_ps_surface_emit_pattern_stops (cairo_ps_surface_t *surface, + cairo_gradient_pattern_t *pattern) +{ + cairo_ps_color_stop_t *allstops, *stops; + unsigned int i, n_stops; + + allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_ps_color_stop_t)); + if (unlikely (allstops == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + stops = &allstops[1]; + n_stops = pattern->n_stops; + + for (i = 0; i < n_stops; i++) { + cairo_gradient_stop_t *stop = &pattern->stops[i]; + + stops[i].color[0] = stop->color.red; + stops[i].color[1] = stop->color.green; + stops[i].color[2] = stop->color.blue; + stops[i].color[3] = stop->color.alpha; + stops[i].offset = pattern->stops[i].offset; + } + + if (pattern->base.extend == CAIRO_EXTEND_REPEAT || + pattern->base.extend == CAIRO_EXTEND_REFLECT) + { + if (stops[0].offset > COLOR_STOP_EPSILON) { + if (pattern->base.extend == CAIRO_EXTEND_REFLECT) + memcpy (allstops, stops, sizeof (cairo_ps_color_stop_t)); + else + calc_gradient_color (&allstops[0], &stops[0], &stops[n_stops-1]); + stops = allstops; + n_stops++; + } + stops[0].offset = 0.0; + + if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) { + if (pattern->base.extend == CAIRO_EXTEND_REFLECT) { + memcpy (&stops[n_stops], + &stops[n_stops - 1], + sizeof (cairo_ps_color_stop_t)); + } else { + calc_gradient_color (&stops[n_stops], &stops[0], &stops[n_stops-1]); + } + n_stops++; + } + stops[n_stops-1].offset = 1.0; + } + + for (i = 0; i < n_stops; i++) { + double red, green, blue; + cairo_color_t color; + + _cairo_color_init_rgba (&color, + stops[i].color[0], + stops[i].color[1], + stops[i].color[2], + stops[i].color[3]); + _cairo_ps_surface_flatten_transparency (surface, &color, + &red, &green, &blue); + stops[i].color[0] = red; + stops[i].color[1] = green; + stops[i].color[2] = blue; + } + + _cairo_output_stream_printf (surface->stream, + "/CairoFunction\n"); + if (stops[0].offset == stops[n_stops - 1].offset) { + /* + * The first and the last stops have the same offset, but we + * don't want a function with an empty domain, because that + * would provoke underdefined behaviour from rasterisers. + * This can only happen with EXTEND_PAD, because EXTEND_NONE + * is optimised into a clear pattern in cairo-gstate, and + * REFLECT/REPEAT are always transformed to have the first + * stop at t=0 and the last stop at t=1. Thus we want a step + * function going from the first color to the last one. + * + * This can be accomplished by stitching three functions: + * - a constant first color function, + * - a step from the first color to the last color (with empty domain) + * - a constant last color function + */ + cairo_ps_color_stop_t pad_stops[4]; + + assert (pattern->base.extend == CAIRO_EXTEND_PAD); + + pad_stops[0] = pad_stops[1] = stops[0]; + pad_stops[2] = pad_stops[3] = stops[n_stops - 1]; + + pad_stops[0].offset = 0; + pad_stops[3].offset = 1; + + _cairo_ps_surface_emit_stitched_colorgradient (surface, 4, pad_stops); + } else if (n_stops == 2) { + /* no need for stitched function */ + _cairo_ps_surface_emit_linear_colorgradient (surface, &stops[0], &stops[1]); + } else { + /* multiple stops: stitch. XXX possible optimization: regulary spaced + * stops do not require stitching. XXX */ + _cairo_ps_surface_emit_stitched_colorgradient (surface, n_stops, stops); + } + _cairo_output_stream_printf (surface->stream, + "def\n"); + + free (allstops); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_ps_surface_emit_repeating_function (cairo_ps_surface_t *surface, + cairo_gradient_pattern_t *pattern, + int begin, + int end) +{ + _cairo_output_stream_printf (surface->stream, + "/CairoFunction\n" + "<< /FunctionType 3\n" + " /Domain [ %d %d ]\n" + " /Functions [ %d {CairoFunction} repeat ]\n" + " /Bounds [ %d 1 %d {} for ]\n", + begin, + end, + end - begin, + begin + 1, + end - 1); + + if (pattern->base.extend == CAIRO_EXTEND_REFLECT) { + _cairo_output_stream_printf (surface->stream, " /Encode [ %d 1 %d { 2 mod 0 eq {0 1} {1 0} ifelse } for ]\n", + begin, + end - 1); + } else { + _cairo_output_stream_printf (surface->stream, " /Encode [ %d 1 %d { pop 0 1 } for ]\n", + begin, + end - 1); + } + + _cairo_output_stream_printf (surface->stream, ">> def\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_ps_surface_emit_gradient (cairo_ps_surface_t *surface, + cairo_gradient_pattern_t *pattern, + cairo_bool_t is_ps_pattern) +{ + cairo_matrix_t pat_to_ps; + cairo_circle_double_t start, end; + double domain[2]; + cairo_status_t status; + + assert (pattern->n_stops != 0); + + status = _cairo_ps_surface_emit_pattern_stops (surface, pattern); + if (unlikely (status)) + return status; + + pat_to_ps = pattern->base.matrix; + status = cairo_matrix_invert (&pat_to_ps); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + cairo_matrix_multiply (&pat_to_ps, &pat_to_ps, &surface->cairo_to_ps); + + if (pattern->base.extend == CAIRO_EXTEND_REPEAT || + pattern->base.extend == CAIRO_EXTEND_REFLECT) + { + double bounds_x1, bounds_x2, bounds_y1, bounds_y2; + double x_scale, y_scale, tolerance; + + /* TODO: use tighter extents */ + bounds_x1 = 0; + bounds_y1 = 0; + bounds_x2 = surface->width; + bounds_y2 = surface->height; + _cairo_matrix_transform_bounding_box (&pattern->base.matrix, + &bounds_x1, &bounds_y1, + &bounds_x2, &bounds_y2, + NULL); + + x_scale = surface->base.x_resolution / surface->base.x_fallback_resolution; + y_scale = surface->base.y_resolution / surface->base.y_fallback_resolution; + + tolerance = fabs (_cairo_matrix_compute_determinant (&pattern->base.matrix)); + tolerance /= _cairo_matrix_transformed_circle_major_axis (&pattern->base.matrix, 1); + tolerance *= MIN (x_scale, y_scale); + + _cairo_gradient_pattern_box_to_parameter (pattern, + bounds_x1, bounds_y1, + bounds_x2, bounds_y2, + tolerance, domain); + } else if (pattern->stops[0].offset == pattern->stops[pattern->n_stops - 1].offset) { + /* + * If the first and the last stop offset are the same, then + * the color function is a step function. + * _cairo_ps_surface_emit_pattern_stops emits it as a stitched + * function no matter how many stops the pattern has. The + * domain of the stitched function will be [0 1] in this case. + * + * This is done to avoid emitting degenerate gradients for + * EXTEND_PAD patterns having a step color function. + */ + domain[0] = 0.0; + domain[1] = 1.0; + + assert (pattern->base.extend == CAIRO_EXTEND_PAD); + } else { + domain[0] = pattern->stops[0].offset; + domain[1] = pattern->stops[pattern->n_stops - 1].offset; + } + + /* PS requires the first and last stop to be the same as the + * extreme coordinates. For repeating patterns this moves the + * extreme coordinates out to the begin/end of the repeating + * function. For non repeating patterns this may move the extreme + * coordinates in if there are not stops at offset 0 and 1. */ + _cairo_gradient_pattern_interpolate (pattern, domain[0], &start); + _cairo_gradient_pattern_interpolate (pattern, domain[1], &end); + + if (pattern->base.extend == CAIRO_EXTEND_REPEAT || + pattern->base.extend == CAIRO_EXTEND_REFLECT) + { + int repeat_begin, repeat_end; + + repeat_begin = floor (domain[0]); + repeat_end = ceil (domain[1]); + + status = _cairo_ps_surface_emit_repeating_function (surface, + pattern, + repeat_begin, + repeat_end); + if (unlikely (status)) + return status; + } else if (pattern->n_stops <= 2) { + /* For EXTEND_NONE and EXTEND_PAD if there are only two stops a + * Type 2 function is used by itself without a stitching + * function. Type 2 functions always have the domain [0 1] */ + domain[0] = 0.0; + domain[1] = 1.0; + } + + if (is_ps_pattern) { + _cairo_output_stream_printf (surface->stream, + "<< /PatternType 2\n" + " /Shading\n"); + } + + if (pattern->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + _cairo_output_stream_printf (surface->stream, + " << /ShadingType 2\n" + " /ColorSpace /DeviceRGB\n" + " /Coords [ %f %f %f %f ]\n", + start.center.x, start.center.y, + end.center.x, end.center.y); + } else { + _cairo_output_stream_printf (surface->stream, + " << /ShadingType 3\n" + " /ColorSpace /DeviceRGB\n" + " /Coords [ %f %f %f %f %f %f ]\n", + start.center.x, start.center.y, + MAX (start.radius, 0), + end.center.x, end.center.y, + MAX (end.radius, 0)); + } + + if (pattern->base.extend != CAIRO_EXTEND_NONE) { + _cairo_output_stream_printf (surface->stream, + " /Extend [ true true ]\n"); + } else { + _cairo_output_stream_printf (surface->stream, + " /Extend [ false false ]\n"); + } + + if (domain[0] == 0.0 && domain[1] == 1.0) { + _cairo_output_stream_printf (surface->stream, + " /Function CairoFunction\n"); + } else { + _cairo_output_stream_printf (surface->stream, + " /Function <<\n" + " /FunctionType 3\n" + " /Domain [ 0 1 ]\n" + " /Bounds [ ]\n" + " /Encode [ %f %f ]\n" + " /Functions [ CairoFunction ]\n" + " >>\n", + domain[0], domain[1]); + } + + _cairo_output_stream_printf (surface->stream, + " >>\n"); + + if (is_ps_pattern) { + _cairo_output_stream_printf (surface->stream, + ">>\n" + "[ "); + _cairo_output_stream_print_matrix (surface->stream, &pat_to_ps); + _cairo_output_stream_printf (surface->stream, " ]\n" + "makepattern setpattern\n"); + } else { + _cairo_output_stream_printf (surface->stream, + "shfill\n"); + } + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_mesh_pattern (cairo_ps_surface_t *surface, + cairo_mesh_pattern_t *pattern, + cairo_bool_t is_ps_pattern) +{ + cairo_matrix_t pat_to_ps; + cairo_status_t status; + cairo_pdf_shading_t shading; + int i; + + if (_cairo_array_num_elements (&pattern->patches) == 0) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + pat_to_ps = pattern->base.matrix; + status = cairo_matrix_invert (&pat_to_ps); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + cairo_matrix_multiply (&pat_to_ps, &pat_to_ps, &surface->cairo_to_ps); + + status = _cairo_pdf_shading_init_color (&shading, pattern); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->stream, + "currentfile\n" + "/ASCII85Decode filter /FlateDecode filter /ReusableStreamDecode filter\n"); + + status = _cairo_ps_surface_emit_base85_string (surface, + shading.data, + shading.data_length, + CAIRO_PS_COMPRESS_DEFLATE, + FALSE); + if (status) + return status; + + _cairo_output_stream_printf (surface->stream, + "\n" + "/CairoData exch def\n"); + + if (is_ps_pattern) { + _cairo_output_stream_printf (surface->stream, + "<< /PatternType 2\n" + " /Shading\n"); + } + + _cairo_output_stream_printf (surface->stream, + " << /ShadingType %d\n" + " /ColorSpace /DeviceRGB\n" + " /DataSource CairoData\n" + " /BitsPerCoordinate %d\n" + " /BitsPerComponent %d\n" + " /BitsPerFlag %d\n" + " /Decode [", + shading.shading_type, + shading.bits_per_coordinate, + shading.bits_per_component, + shading.bits_per_flag); + + for (i = 0; i < shading.decode_array_length; i++) + _cairo_output_stream_printf (surface->stream, "%f ", shading.decode_array[i]); + + _cairo_output_stream_printf (surface->stream, + "]\n" + " >>\n"); + + if (is_ps_pattern) { + _cairo_output_stream_printf (surface->stream, + ">>\n" + "[ \n"); + _cairo_output_stream_print_matrix (surface->stream, &pat_to_ps); + _cairo_output_stream_printf (surface->stream, + " ]\n" + "makepattern\n" + "setpattern\n"); + } else { + _cairo_output_stream_printf (surface->stream, "shfill\n"); + } + + _cairo_output_stream_printf (surface->stream, + "currentdict /CairoData undef\n"); + + _cairo_pdf_shading_fini (&shading); + + return status; +} + +static cairo_status_t +_cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_rectangle_int_t *extents, + cairo_operator_t op) +{ + cairo_status_t status; + + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; + + if (surface->current_pattern_is_solid_color == FALSE || + ! _cairo_color_equal (&surface->current_color, &solid->color)) + { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); + + surface->current_pattern_is_solid_color = TRUE; + surface->current_color = solid->color; + } + + return CAIRO_STATUS_SUCCESS; + } + + surface->current_pattern_is_solid_color = FALSE; + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + return status; + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + + _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); + break; + + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + status = _cairo_ps_surface_emit_surface_pattern (surface, + (cairo_pattern_t *)pattern, + extents, + op); + if (unlikely (status)) + return status; + break; + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + status = _cairo_ps_surface_emit_gradient (surface, + (cairo_gradient_pattern_t *) pattern, + TRUE); + if (unlikely (status)) + return status; + break; + + case CAIRO_PATTERN_TYPE_MESH: + status = _cairo_ps_surface_emit_mesh_pattern (surface, + (cairo_mesh_pattern_t *) pattern, + TRUE); + if (unlikely (status)) + return status; + break; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_ps_surface_paint_gradient (cairo_ps_surface_t *surface, + const cairo_pattern_t *source, + const cairo_rectangle_int_t *extents) +{ + cairo_matrix_t pat_to_ps; + cairo_status_t status; + + pat_to_ps = source->matrix; + status = cairo_matrix_invert (&pat_to_ps); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + cairo_matrix_multiply (&pat_to_ps, &pat_to_ps, &surface->cairo_to_ps); + + if (! _cairo_matrix_is_identity (&pat_to_ps)) { + _cairo_output_stream_printf (surface->stream, "["); + _cairo_output_stream_print_matrix (surface->stream, &pat_to_ps); + _cairo_output_stream_printf (surface->stream, "] concat\n"); + } + + if (source->type == CAIRO_PATTERN_TYPE_MESH) { + status = _cairo_ps_surface_emit_mesh_pattern (surface, + (cairo_mesh_pattern_t *)source, + FALSE); + if (unlikely (status)) + return status; + } else { + status = _cairo_ps_surface_emit_gradient (surface, + (cairo_gradient_pattern_t *)source, + FALSE); + if (unlikely (status)) + return status; + } + + return status; +} + +static cairo_status_t +_cairo_ps_surface_paint_pattern (cairo_ps_surface_t *surface, + const cairo_pattern_t *source, + cairo_rectangle_int_t *extents, + cairo_operator_t op, + cairo_bool_t stencil_mask) +{ + switch (source->type) { + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _cairo_ps_surface_paint_surface (surface, + (cairo_pattern_t *)source, + extents, + op, + stencil_mask); + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + return _cairo_ps_surface_paint_gradient (surface, + source, + extents); + + case CAIRO_PATTERN_TYPE_SOLID: + default: + ASSERT_NOT_REACHED; + return CAIRO_STATUS_SUCCESS; + } +} + +static cairo_bool_t +_can_paint_pattern (const cairo_pattern_t *pattern) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return FALSE; + + case CAIRO_PATTERN_TYPE_SURFACE: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return (pattern->extend == CAIRO_EXTEND_NONE || + pattern->extend == CAIRO_EXTEND_PAD); + + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + return TRUE; + + default: + ASSERT_NOT_REACHED; + return FALSE; + } +} + +static cairo_bool_t +_cairo_ps_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_ps_surface_t *surface = abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + + /* XXX: The conversion to integers here is pretty bogus, (not to + * mention the aribitray limitation of width to a short(!). We + * may need to come up with a better interface for get_extents. + */ + rectangle->width = ceil (surface->width); + rectangle->height = ceil (surface->height); + + return TRUE; +} + +static void +_cairo_ps_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + _cairo_font_options_init_default (options); + + cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); + _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); +} + +static cairo_int_status_t +_cairo_ps_surface_set_clip (cairo_ps_surface_t *surface, + cairo_composite_rectangles_t *composite) +{ + cairo_clip_t *clip = composite->clip; + + if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) + clip = NULL; + + if (clip == NULL) { + if (_cairo_composite_rectangles_can_reduce_clip (composite, + surface->clipper.clip)) + return CAIRO_STATUS_SUCCESS; + } + + return _cairo_surface_clipper_set_clip (&surface->clipper, clip); +} + +static cairo_int_status_t +_cairo_ps_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_output_stream_t *stream = surface->stream; + cairo_composite_rectangles_t extents; + cairo_status_t status; + + status = _cairo_composite_rectangles_init_for_paint (&extents, + &surface->base, + op, source, clip); + if (unlikely (status)) + return status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); + goto cleanup_composite; + } + + assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); + +#if DEBUG_PS + _cairo_output_stream_printf (stream, + "%% _cairo_ps_surface_paint\n"); +#endif + + status = _cairo_ps_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup_composite; + + if (_can_paint_pattern (source)) { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_output_stream_printf (stream, "q\n"); + status = _cairo_ps_surface_paint_pattern (surface, + source, + &extents.bounded, op, FALSE); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_output_stream_printf (stream, "Q\n"); + } else { + status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_output_stream_printf (stream, "0 0 %f %f rectfill\n", + surface->width, surface->height); + } + +cleanup_composite: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_ps_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_output_stream_t *stream = surface->stream; + cairo_composite_rectangles_t extents; + cairo_status_t status; + + status = _cairo_composite_rectangles_init_for_mask (&extents, + &surface->base, + op, source, mask, clip); + if (unlikely (status)) + return status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_ps_surface_analyze_operation (surface, op, source, mask, &extents.bounded); + goto cleanup_composite; + } + + assert (_cairo_ps_surface_operation_supported (surface, op, source, mask, &extents.bounded)); + +#if DEBUG_PS + _cairo_output_stream_printf (stream, + "%% _cairo_ps_surface_mask\n"); +#endif + + status = _cairo_ps_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_output_stream_printf (stream, "q\n"); + status = _cairo_ps_surface_paint_pattern (surface, + mask, + &extents.bounded, op, TRUE); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_output_stream_printf (stream, "Q\n"); + +cleanup_composite: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_ps_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + status = _cairo_composite_rectangles_init_for_stroke (&extents, + &surface->base, + op, source, + path, style, ctm, + clip); + if (unlikely (status)) + return status; + + /* use the more accurate extents */ + { + cairo_rectangle_int_t r; + cairo_box_t b; + + status = _cairo_path_fixed_stroke_extents (path, style, + ctm, ctm_inverse, + tolerance, + &r); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_box_from_rectangle (&b, &r); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, &b); + if (unlikely (status)) + goto cleanup_composite; + } + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); + goto cleanup_composite; + } + + assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); + +#if DEBUG_PS + _cairo_output_stream_printf (surface->stream, + "%% _cairo_ps_surface_stroke\n"); +#endif + + status = _cairo_ps_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_pdf_operators_stroke (&surface->pdf_operators, + path, + style, + ctm, + ctm_inverse); + +cleanup_composite: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_int_status_t +_cairo_ps_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_composite_rectangles_t extents; + cairo_int_status_t status; + + status = _cairo_composite_rectangles_init_for_fill (&extents, + &surface->base, + op, source, path, + clip); + if (unlikely (status)) + return status; + + /* use the more accurate extents */ + { + cairo_rectangle_int_t r; + cairo_box_t b; + + _cairo_path_fixed_fill_extents (path, + fill_rule, + tolerance, + &r); + + _cairo_box_from_rectangle (&b, &r); + status = _cairo_composite_rectangles_intersect_mask_extents (&extents, &b); + if (unlikely (status)) + goto cleanup_composite; + } + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); + goto cleanup_composite; + } + + assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); + +#if DEBUG_PS + _cairo_output_stream_printf (surface->stream, + "%% _cairo_ps_surface_fill\n"); +#endif + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_ps_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup_composite; + + if (_can_paint_pattern (source)) { + _cairo_output_stream_printf (surface->stream, "q\n"); + + status = _cairo_pdf_operators_clip (&surface->pdf_operators, + path, + fill_rule); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_ps_surface_paint_pattern (surface, + source, + &extents.bounded, op, FALSE); + if (unlikely (status)) + goto cleanup_composite; + + _cairo_output_stream_printf (surface->stream, "Q\n"); + _cairo_pdf_operators_reset (&surface->pdf_operators); + } else { + status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_pdf_operators_fill (&surface->pdf_operators, + path, + fill_rule); + } + +cleanup_composite: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static cairo_bool_t +_cairo_ps_surface_has_show_text_glyphs (void *abstract_surface) +{ + return TRUE; +} + +static cairo_int_status_t +_cairo_ps_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_composite_rectangles_t extents; + cairo_bool_t overlap; + cairo_status_t status; + + status = _cairo_composite_rectangles_init_for_glyphs (&extents, + &surface->base, + op, source, + scaled_font, + glyphs, num_glyphs, + clip, + &overlap); + if (unlikely (status)) + return status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + status = _cairo_ps_surface_analyze_operation (surface, op, source, NULL, &extents.bounded); + goto cleanup_composite; + } + + assert (_cairo_ps_surface_operation_supported (surface, op, source, NULL, &extents.bounded)); + +#if DEBUG_PS + _cairo_output_stream_printf (surface->stream, + "%% _cairo_ps_surface_show_glyphs\n"); +#endif + + status = _cairo_ps_surface_set_clip (surface, &extents); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op); + if (unlikely (status)) + goto cleanup_composite; + + status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font); + +cleanup_composite: + _cairo_composite_rectangles_fini (&extents); + return status; +} + +static const char ** +_cairo_ps_surface_get_supported_mime_types (void *abstract_surface) +{ + return _cairo_ps_supported_mime_types; +} + +static void +_cairo_ps_surface_set_paginated_mode (void *abstract_surface, + cairo_paginated_mode_t paginated_mode) +{ + cairo_ps_surface_t *surface = abstract_surface; + cairo_status_t status; + + surface->paginated_mode = paginated_mode; + + if (surface->clipper.clip != NULL) { + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + + _cairo_output_stream_printf (surface->stream, "Q q\n"); + _cairo_surface_clipper_reset (&surface->clipper); + } +} + +static cairo_int_status_t +_cairo_ps_surface_set_bounding_box (void *abstract_surface, + cairo_box_t *bbox) +{ + cairo_ps_surface_t *surface = abstract_surface; + int i, num_comments; + char **comments; + int x1, y1, x2, y2; + cairo_bool_t has_page_media, has_page_bbox; + const char *page_media; + + x1 = floor (_cairo_fixed_to_double (bbox->p1.x)); + y1 = floor (surface->height - _cairo_fixed_to_double (bbox->p2.y)); + x2 = ceil (_cairo_fixed_to_double (bbox->p2.x)); + y2 = ceil (surface->height - _cairo_fixed_to_double (bbox->p1.y)); + + surface->page_bbox.x = x1; + surface->page_bbox.y = y1; + surface->page_bbox.width = x2 - x1; + surface->page_bbox.height = y2 - y1; + + _cairo_output_stream_printf (surface->stream, + "%%%%Page: %d %d\n", + surface->num_pages, + surface->num_pages); + + _cairo_output_stream_printf (surface->stream, + "%%%%BeginPageSetup\n"); + + has_page_media = FALSE; + has_page_bbox = FALSE; + num_comments = _cairo_array_num_elements (&surface->dsc_page_setup_comments); + comments = _cairo_array_index (&surface->dsc_page_setup_comments, 0); + for (i = 0; i < num_comments; i++) { + _cairo_output_stream_printf (surface->stream, + "%s\n", comments[i]); + if (strncmp (comments[i], "%%PageMedia:", 11) == 0) + has_page_media = TRUE; + + if (strncmp (comments[i], "%%PageBoundingBox:", 18) == 0) + has_page_bbox = TRUE; + + free (comments[i]); + comments[i] = NULL; + } + _cairo_array_truncate (&surface->dsc_page_setup_comments, 0); + + if (!has_page_media && !surface->eps) { + page_media = _cairo_ps_surface_get_page_media (surface); + if (unlikely (page_media == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_output_stream_printf (surface->stream, + "%%%%PageMedia: %s\n", + page_media); + } + + if (!has_page_bbox) { + _cairo_output_stream_printf (surface->stream, + "%%%%PageBoundingBox: %d %d %d %d\n", + x1, y1, x2, y2); + } + + if (!surface->eps) { + _cairo_output_stream_printf (surface->stream, + "%f %f cairo_set_page_size\n", + ceil(surface->width), + ceil(surface->height)); + } + + _cairo_output_stream_printf (surface->stream, + "%%%%EndPageSetup\n" + "q %d %d %d %d rectclip q\n", + surface->page_bbox.x, + surface->page_bbox.y, + surface->page_bbox.width, + surface->page_bbox.height); + + if (surface->num_pages == 1) { + surface->bbox_x1 = x1; + surface->bbox_y1 = y1; + surface->bbox_x2 = x2; + surface->bbox_y2 = y2; + } else { + if (x1 < surface->bbox_x1) + surface->bbox_x1 = x1; + if (y1 < surface->bbox_y1) + surface->bbox_y1 = y1; + if (x2 > surface->bbox_x2) + surface->bbox_x2 = x2; + if (y2 > surface->bbox_y2) + surface->bbox_y2 = y2; + } + surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); + + return _cairo_output_stream_get_status (surface->stream); +} + +static cairo_bool_t +_cairo_ps_surface_supports_fine_grained_fallbacks (void *abstract_surface) +{ + return TRUE; +} + +static const cairo_surface_backend_t cairo_ps_surface_backend = { + CAIRO_SURFACE_TYPE_PS, + _cairo_ps_surface_finish, + + _cairo_default_context_create, + + NULL, /* create similar: handled by wrapper */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* cairo_ps_surface_copy_page */ + _cairo_ps_surface_show_page, + + _cairo_ps_surface_get_extents, + _cairo_ps_surface_get_font_options, + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + /* Here are the drawing functions */ + + _cairo_ps_surface_paint, /* paint */ + _cairo_ps_surface_mask, + _cairo_ps_surface_stroke, + _cairo_ps_surface_fill, + NULL, /* fill-stroke */ + NULL, /* show_glyphs */ + _cairo_ps_surface_has_show_text_glyphs, + _cairo_ps_surface_show_text_glyphs, + _cairo_ps_surface_get_supported_mime_types, +}; + +static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend = { + _cairo_ps_surface_start_page, + _cairo_ps_surface_set_paginated_mode, + _cairo_ps_surface_set_bounding_box, + NULL, /* _cairo_ps_surface_has_fallback_images, */ + _cairo_ps_surface_supports_fine_grained_fallbacks, +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-ps.h b/Build/source/libs/cairo/cairo-src/src/cairo-ps.h new file mode 100644 index 00000000000..33d0e0d941b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-ps.h @@ -0,0 +1,116 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_PS_H +#define CAIRO_PS_H + +#include "cairo.h" + +#if CAIRO_HAS_PS_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +/* PS-surface functions */ + +/** + * cairo_ps_level_t: + * @CAIRO_PS_LEVEL_2: The language level 2 of the PostScript specification. (Since 1.6) + * @CAIRO_PS_LEVEL_3: The language level 3 of the PostScript specification. (Since 1.6) + * + * #cairo_ps_level_t is used to describe the language level of the + * PostScript Language Reference that a generated PostScript file will + * conform to. + * + * Since: 1.6 + **/ +typedef enum _cairo_ps_level { + CAIRO_PS_LEVEL_2, + CAIRO_PS_LEVEL_3 +} cairo_ps_level_t; + +cairo_public cairo_surface_t * +cairo_ps_surface_create (const char *filename, + double width_in_points, + double height_in_points); + +cairo_public cairo_surface_t * +cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, + void *closure, + double width_in_points, + double height_in_points); + +cairo_public void +cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, + cairo_ps_level_t level); + +cairo_public void +cairo_ps_get_levels (cairo_ps_level_t const **levels, + int *num_levels); + +cairo_public const char * +cairo_ps_level_to_string (cairo_ps_level_t level); + +cairo_public void +cairo_ps_surface_set_eps (cairo_surface_t *surface, + cairo_bool_t eps); + +cairo_public cairo_bool_t +cairo_ps_surface_get_eps (cairo_surface_t *surface); + +cairo_public void +cairo_ps_surface_set_size (cairo_surface_t *surface, + double width_in_points, + double height_in_points); + +cairo_public void +cairo_ps_surface_dsc_comment (cairo_surface_t *surface, + const char *comment); + +cairo_public void +cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface); + +cairo_public void +cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_PS_SURFACE */ +# error Cairo was not compiled with support for the ps backend +#endif /* CAIRO_HAS_PS_SURFACE */ + +#endif /* CAIRO_PS_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-qt-surface.cpp b/Build/source/libs/cairo/cairo-src/src/cairo-qt-surface.cpp new file mode 100644 index 00000000000..7ddad77df37 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-qt-surface.cpp @@ -0,0 +1,1738 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Corporation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +/* Get INT16_MIN etc. as per C99 */ +#define __STDC_LIMIT_MACROS + +#include "cairoint.h" + +#include "cairo-clip-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-region-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-types-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-surface-fallback-private.h" + +#include "cairo-ft.h" +#include "cairo-qt.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if ((QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) || defined(QT_GLYPHS_API_BACKPORT)) && 0 +extern void qt_draw_glyphs(QPainter *, const quint32 *glyphs, const QPointF *positions, int count); +#endif + +#include + +/* Enable workaround slow regional Qt paths */ +#define ENABLE_FAST_FILL 0 +#define ENABLE_FAST_CLIP 0 + +#if 0 +#define D(x) x +static const char * +_opstr (cairo_operator_t op) +{ + const char *ops[] = { + "CLEAR", + "SOURCE", + "OVER", + "IN", + "OUT", + "ATOP", + "DEST", + "DEST_OVER", + "DEST_IN", + "DEST_OUT", + "DEST_ATOP", + "XOR", + "ADD", + "SATURATE" + }; + + if (op < CAIRO_OPERATOR_CLEAR || op > CAIRO_OPERATOR_SATURATE) + return "(\?\?\?)"; + + return ops[op]; +} +#else +#define D(x) do { } while(0) +#endif + +#ifndef CAIRO_INT_STATUS_SUCCESS +#define CAIRO_INT_STATUS_SUCCESS ((cairo_int_status_t) CAIRO_STATUS_SUCCESS) +#endif + +/* Qt::PenStyle optimization based on the assumption that dots are 1*w and dashes are 3*w. */ +#define DOT_LENGTH 1.0 +#define DASH_LENGTH 3.0 + +struct cairo_qt_surface_t { + cairo_surface_t base; + + cairo_bool_t supports_porter_duff; + + QPainter *p; + + /* The pixmap/image constructors will store their objects here */ + QPixmap *pixmap; + QImage *image; + + QRect window; + + cairo_surface_clipper_t clipper; + + cairo_surface_t *image_equiv; +}; + +/* Will be true if we ever try to create a QPixmap and end + * up with one without an alpha channel. + */ +static cairo_bool_t _qpixmaps_have_no_alpha = FALSE; + +/* + * Helper methods + */ + +static QPainter::CompositionMode +_qpainter_compositionmode_from_cairo_op (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_CLEAR: + return QPainter::CompositionMode_Clear; + + case CAIRO_OPERATOR_SOURCE: + return QPainter::CompositionMode_Source; + case CAIRO_OPERATOR_OVER: + return QPainter::CompositionMode_SourceOver; + case CAIRO_OPERATOR_IN: + return QPainter::CompositionMode_SourceIn; + case CAIRO_OPERATOR_OUT: + return QPainter::CompositionMode_SourceOut; + case CAIRO_OPERATOR_ATOP: + return QPainter::CompositionMode_SourceAtop; + + case CAIRO_OPERATOR_DEST: + return QPainter::CompositionMode_Destination; + case CAIRO_OPERATOR_DEST_OVER: + return QPainter::CompositionMode_DestinationOver; + case CAIRO_OPERATOR_DEST_IN: + return QPainter::CompositionMode_DestinationIn; + case CAIRO_OPERATOR_DEST_OUT: + return QPainter::CompositionMode_DestinationOut; + case CAIRO_OPERATOR_DEST_ATOP: + return QPainter::CompositionMode_DestinationAtop; + + case CAIRO_OPERATOR_XOR: + return QPainter::CompositionMode_Xor; + + default: + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + ASSERT_NOT_REACHED; + } +} + +static bool +_op_is_supported (cairo_qt_surface_t *qs, cairo_operator_t op) +{ + if (qs->p == NULL) + return false; + + if (qs->supports_porter_duff) { + switch (op) { + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_ATOP: + + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_DEST_ATOP: + + case CAIRO_OPERATOR_XOR: + return TRUE; + + default: + ASSERT_NOT_REACHED; + case CAIRO_OPERATOR_ADD: + case CAIRO_OPERATOR_SATURATE: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return FALSE; + + } + } else { + return op == CAIRO_OPERATOR_OVER; + } +} + +static cairo_format_t +_cairo_format_from_qimage_format (QImage::Format fmt) +{ + switch (fmt) { + case QImage::Format_ARGB32_Premultiplied: + return CAIRO_FORMAT_ARGB32; + case QImage::Format_RGB32: + return CAIRO_FORMAT_RGB24; + case QImage::Format_Indexed8: // XXX not quite + return CAIRO_FORMAT_A8; +#ifdef WORDS_BIGENDIAN + case QImage::Format_Mono: +#else + case QImage::Format_MonoLSB: +#endif + return CAIRO_FORMAT_A1; + + case QImage::Format_Invalid: +#ifdef WORDS_BIGENDIAN + case QImage::Format_MonoLSB: +#else + case QImage::Format_Mono: +#endif + case QImage::Format_ARGB32: + case QImage::Format_RGB16: + case QImage::Format_ARGB8565_Premultiplied: + case QImage::Format_RGB666: + case QImage::Format_ARGB6666_Premultiplied: + case QImage::Format_RGB555: + case QImage::Format_ARGB8555_Premultiplied: + case QImage::Format_RGB888: + case QImage::Format_RGB444: + case QImage::Format_ARGB4444_Premultiplied: + case QImage::NImageFormats: + default: + ASSERT_NOT_REACHED; + return (cairo_format_t) -1; + } +} + +static QImage::Format +_qimage_format_from_cairo_format (cairo_format_t fmt) +{ + switch (fmt) { + case CAIRO_FORMAT_INVALID: + ASSERT_NOT_REACHED; + case CAIRO_FORMAT_ARGB32: + return QImage::Format_ARGB32_Premultiplied; + case CAIRO_FORMAT_RGB24: + return QImage::Format_RGB32; + case CAIRO_FORMAT_RGB16_565: + return QImage::Format_RGB16; + case CAIRO_FORMAT_A8: + return QImage::Format_Indexed8; // XXX not quite + case CAIRO_FORMAT_A1: +#ifdef WORDS_BIGENDIAN + return QImage::Format_Mono; // XXX think we need to choose between this and LSB +#else + return QImage::Format_MonoLSB; +#endif + case CAIRO_FORMAT_RGB30: + return QImage::Format_Mono; + } + + return QImage::Format_Mono; +} + +static inline QMatrix +_qmatrix_from_cairo_matrix (const cairo_matrix_t& m) +{ + return QMatrix(m.xx, m.yx, m.xy, m.yy, m.x0, m.y0); +} + +/* Path conversion */ +typedef struct _qpainter_path_transform { + QPainterPath path; + const cairo_matrix_t *ctm_inverse; +} qpainter_path_data; + +/* cairo path -> execute in context */ +static cairo_status_t +_cairo_path_to_qpainterpath_move_to (void *closure, const cairo_point_t *point) +{ + qpainter_path_data *pdata = static_cast (closure); + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (pdata->ctm_inverse) + cairo_matrix_transform_point (pdata->ctm_inverse, &x, &y); + + pdata->path.moveTo(x, y); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_to_qpainterpath_line_to (void *closure, const cairo_point_t *point) +{ + qpainter_path_data *pdata = static_cast (closure); + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (pdata->ctm_inverse) + cairo_matrix_transform_point (pdata->ctm_inverse, &x, &y); + + pdata->path.lineTo(x, y); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_to_qpainterpath_curve_to (void *closure, const cairo_point_t *p0, const cairo_point_t *p1, const cairo_point_t *p2) +{ + qpainter_path_data *pdata = static_cast (closure); + double x0 = _cairo_fixed_to_double (p0->x); + double y0 = _cairo_fixed_to_double (p0->y); + double x1 = _cairo_fixed_to_double (p1->x); + double y1 = _cairo_fixed_to_double (p1->y); + double x2 = _cairo_fixed_to_double (p2->x); + double y2 = _cairo_fixed_to_double (p2->y); + + if (pdata->ctm_inverse) { + cairo_matrix_transform_point (pdata->ctm_inverse, &x0, &y0); + cairo_matrix_transform_point (pdata->ctm_inverse, &x1, &y1); + cairo_matrix_transform_point (pdata->ctm_inverse, &x2, &y2); + } + + pdata->path.cubicTo (x0, y0, x1, y1, x2, y2); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_to_qpainterpath_close_path (void *closure) +{ + qpainter_path_data *pdata = static_cast (closure); + + pdata->path.closeSubpath(); + + return CAIRO_STATUS_SUCCESS; +} + +static QPainterPath +path_to_qt (const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm_inverse = NULL) +{ + qpainter_path_data data; + cairo_status_t status; + + if (ctm_inverse && _cairo_matrix_is_identity (ctm_inverse)) + ctm_inverse = NULL; + data.ctm_inverse = ctm_inverse; + + status = _cairo_path_fixed_interpret (path, + _cairo_path_to_qpainterpath_move_to, + _cairo_path_to_qpainterpath_line_to, + _cairo_path_to_qpainterpath_curve_to, + _cairo_path_to_qpainterpath_close_path, + &data); + assert (status == CAIRO_STATUS_SUCCESS); + + return data.path; +} + +static inline QPainterPath +path_to_qt (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + cairo_matrix_t *ctm_inverse = NULL) +{ + QPainterPath qpath = path_to_qt (path, ctm_inverse); + + qpath.setFillRule (fill_rule == CAIRO_FILL_RULE_WINDING ? + Qt::WindingFill : + Qt::OddEvenFill); + + return qpath; +} + +/* + * Surface backend methods + */ +static cairo_surface_t * +_cairo_qt_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + bool use_pixmap; + + D(fprintf(stderr, "q[%p] create_similar: %d %d [%d] -> ", abstract_surface, width, height, content)); + + use_pixmap = qs->image == NULL; + if (use_pixmap) { + switch (content) { + case CAIRO_CONTENT_ALPHA: + use_pixmap = FALSE; + break; + case CAIRO_CONTENT_COLOR: + break; + case CAIRO_CONTENT_COLOR_ALPHA: + use_pixmap = ! _qpixmaps_have_no_alpha; + break; + } + } + + if (use_pixmap) { + cairo_surface_t *result = + cairo_qt_surface_create_with_qpixmap (content, width, height); + + /* XXX result->content is always content. ??? */ + if (result->content == content) { + D(fprintf(stderr, "qpixmap content: %d\n", content)); + return result; + } + + _qpixmaps_have_no_alpha = TRUE; + cairo_surface_destroy (result); + } + + D(fprintf (stderr, "qimage\n")); + return cairo_qt_surface_create_with_qimage + (_cairo_format_from_content (content), width, height); +} + +static cairo_status_t +_cairo_qt_surface_finish (void *abstract_surface) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] finish\n", abstract_surface)); + + /* Only delete p if we created it */ + if (qs->image || qs->pixmap) + delete qs->p; + else + qs->p->restore (); + + if (qs->image_equiv) + cairo_surface_destroy (qs->image_equiv); + + _cairo_surface_clipper_reset (&qs->clipper); + + if (qs->image) + delete qs->image; + + if (qs->pixmap) + delete qs->pixmap; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_qimg_destroy (void *closure) +{ + QImage *qimg = (QImage *) closure; + delete qimg; +} + +static cairo_status_t +_cairo_qt_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] acquire_source_image\n", abstract_surface)); + + *image_extra = NULL; + + if (qs->image_equiv) { + *image_out = (cairo_image_surface_t*) + cairo_surface_reference (qs->image_equiv); + + return CAIRO_STATUS_SUCCESS; + } + + if (qs->pixmap) { + QImage *qimg = new QImage(qs->pixmap->toImage()); + cairo_surface_t *image; + cairo_status_t status; + + image = cairo_image_surface_create_for_data (qimg->bits(), + _cairo_format_from_qimage_format (qimg->format()), + qimg->width(), qimg->height(), + qimg->bytesPerLine()); + + status = _cairo_user_data_array_set_data (&image->user_data, + (const cairo_user_data_key_t *)&_qimg_destroy, + qimg, + _qimg_destroy); + if (status) { + cairo_surface_destroy (image); + return status; + } + + *image_out = (cairo_image_surface_t *) image; + return CAIRO_STATUS_SUCCESS; + } + + return _cairo_error (CAIRO_STATUS_NO_MEMORY); +} + +static void +_cairo_qt_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + //cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] release_source_image\n", abstract_surface)); + + cairo_surface_destroy (&image->base); +} + +struct _qimage_surface { + cairo_image_surface_t image; + QImage *qimg; +}; + +static cairo_surface_t * +map_qimage_to_image (QImage *qimg, const cairo_rectangle_int_t *extents) +{ + struct _qimage_surface *surface; + pixman_image_t *pixman_image; + pixman_format_code_t pixman_format; + uint8_t *data; + + if (qimg == NULL) + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + switch (qimg->format()) { + case QImage::Format_ARGB32_Premultiplied: + pixman_format = PIXMAN_a8r8g8b8; + break; + case QImage::Format_RGB32: + pixman_format = PIXMAN_x8r8g8b8; + break; + case QImage::Format_Indexed8: // XXX not quite + pixman_format = PIXMAN_a8; + break; +#ifdef WORDS_BIGENDIAN + case QImage::Format_Mono: +#else + case QImage::Format_MonoLSB: +#endif + pixman_format = PIXMAN_a1; + break; + + case QImage::Format_Invalid: +#ifdef WORDS_BIGENDIAN + case QImage::Format_MonoLSB: +#else + case QImage::Format_Mono: +#endif + case QImage::Format_ARGB32: + case QImage::Format_RGB16: + case QImage::Format_ARGB8565_Premultiplied: + case QImage::Format_RGB666: + case QImage::Format_ARGB6666_Premultiplied: + case QImage::Format_RGB555: + case QImage::Format_ARGB8555_Premultiplied: + case QImage::Format_RGB888: + case QImage::Format_RGB444: + case QImage::Format_ARGB4444_Premultiplied: + case QImage::NImageFormats: + default: + delete qimg; + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_FORMAT); + } + + data = qimg->bits(); + data += extents->y * qimg->bytesPerLine(); + data += extents->x * PIXMAN_FORMAT_BPP (pixman_format) / 8; + + pixman_image = pixman_image_create_bits (pixman_format, + extents->width, + extents->height, + (uint32_t *)data, + qimg->bytesPerLine()); + if (pixman_image == NULL) { + delete qimg; + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + surface = (struct _qimage_surface *) malloc (sizeof(*surface)); + if (unlikely (surface == NULL)) { + pixman_image_unref (pixman_image); + delete qimg; + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_image_surface_init (&surface->image, pixman_image, pixman_format); + surface->qimg = qimg; + + cairo_surface_set_device_offset (&surface->image.base, + -extents->x, -extents->y); + + return &surface->image.base; +} + +static cairo_image_surface_t * +_cairo_qt_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + QImage *qimg = NULL; + + D(fprintf(stderr, "q[%p] acquire_dest_image\n", abstract_surface)); + + if (qs->image_equiv) + return _cairo_image_surface_map_to_image (qs->image_equiv, + extents); + + QPoint offset; + + if (qs->pixmap) { + qimg = new QImage(qs->pixmap->toImage()); + } else { + // Try to figure out what kind of QPaintDevice we have, and + // how we can grab an image from it + QPaintDevice *pd = qs->p->device(); + if (!pd) + return (cairo_image_surface_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + QPaintDevice *rpd = QPainter::redirected(pd, &offset); + if (rpd) + pd = rpd; + + if (pd->devType() == QInternal::Image) { + qimg = new QImage(((QImage*) pd)->copy()); + } else if (pd->devType() == QInternal::Pixmap) { + qimg = new QImage(((QPixmap*) pd)->toImage()); + } else if (pd->devType() == QInternal::Widget) { + qimg = new QImage(QPixmap::grabWindow(((QWidget*)pd)->winId()).toImage()); + } + } + + return (cairo_image_surface_t *) map_qimage_to_image (qimg, extents); +} + +static cairo_int_status_t +_cairo_qt_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] release_dest_image\n", abstract_surface)); + + if (!qs->image_equiv) { + struct _qimage_surface *qimage = (struct _qimage_surface *)image; + + // XXX should I be using setBackgroundMode here instead of setCompositionMode? + if (qs->supports_porter_duff) + qs->p->setCompositionMode (QPainter::CompositionMode_Source); + + qs->p->drawImage ((int)qimage->image.base.device_transform.x0, + (int)qimage->image.base.device_transform.y0, + *qimage->qimg, + (int)qimage->image.base.device_transform.x0, + (int)qimage->image.base.device_transform.y0, + (int)qimage->image.width, + (int)qimage->image.height); + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); + + delete qimage->qimg; + } + + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_qt_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + extents->x = qs->window.x(); + extents->y = qs->window.y(); + extents->width = qs->window.width(); + extents->height = qs->window.height(); + + return TRUE; +} + +static cairo_status_t +_cairo_qt_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_qt_surface_t *qs = cairo_container_of (clipper, + cairo_qt_surface_t, + clipper); + + if (path == NULL) { + if (qs->pixmap || qs->image) { + // we own p + qs->p->setClipping (false); + } else { + qs->p->restore (); + qs->p->save (); + } + } else { + // XXX Antialiasing is ignored + qs->p->setClipPath (path_to_qt (path, fill_rule), Qt::IntersectClip); + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_qt_surface_set_clip_region (cairo_qt_surface_t *qs, + const cairo_region_t *clip_region) +{ + _cairo_surface_clipper_reset (&qs->clipper); + + if (clip_region == NULL) { + // How the clip path is reset depends on whether we own p or not + if (qs->pixmap || qs->image) { + // we own p + qs->p->setClipping (false); + } else { + qs->p->restore (); + qs->p->save (); + } + } else { + QRegion qr; + int num_rects = cairo_region_num_rectangles (clip_region); + for (int i = 0; i < num_rects; ++i) { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (clip_region, i, &rect); + + QRect r(rect.x, rect.y, rect.width, rect.height); + qr = qr.unite(r); + } + + qs->p->setClipRegion (qr, Qt::IntersectClip); + } +} + +static cairo_int_status_t +_cairo_qt_surface_set_clip (cairo_qt_surface_t *qs, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + D(fprintf(stderr, "q[%p] intersect_clip_path %s\n", abstract_surface, path ? "(path)" : "(clear)")); + + if (clip == NULL) { + _cairo_surface_clipper_reset (&qs->clipper); + // How the clip path is reset depends on whether we own p or not + if (qs->pixmap || qs->image) { + // we own p + qs->p->setClipping (false); + } else { + qs->p->restore (); + qs->p->save (); + } + + return CAIRO_INT_STATUS_SUCCESS; + } + +#if ENABLE_FAST_CLIP + // Qt will implicitly enable clipping, and will use ReplaceClip + // instead of IntersectClip if clipping was disabled before + + // Note: Qt is really bad at dealing with clip paths. It doesn't + // seem to usefully recognize rectangular paths, instead going down + // extremely slow paths whenever a clip path is set. So, + // we do a bunch of work here to try to get rectangles or regions + // down to Qt for clipping. + + cairo_region_t *clip_region = NULL; + + status = _cairo_clip_get_region (clip, &clip_region); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + // We weren't able to extract a region from the traps. + // Just hand the path down to QPainter. + status = (cairo_int_status_t) + _cairo_surface_clipper_set_clip (&qs->clipper, clip); + } else if (status == CAIRO_INT_STATUS_SUCCESS) { + _cairo_qt_surface_set_clip_region (qs, clip_region); + status = CAIRO_INT_STATUS_SUCCESS; + } +#else + status = (cairo_int_status_t) + _cairo_surface_clipper_set_clip (&qs->clipper, clip); +#endif + + return status; +} + +/* + * Brush conversion + */ + +struct PatternToBrushConverter { + PatternToBrushConverter (const cairo_pattern_t *pattern) + __attribute__ ((noinline)) : + mAcquiredImageParent(0), + mAcquiredImage(0), + mAcquiredImageExtra(0) + { + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) pattern; + QColor color; + color.setRgbF(solid->color.red, + solid->color.green, + solid->color.blue, + solid->color.alpha); + + mBrush = QBrush(color); + } else if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t*) pattern; + cairo_surface_t *surface = spattern->surface; + + if (surface->type == CAIRO_SURFACE_TYPE_QT) { + cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; + + if (qs->image) { + mBrush = QBrush(*qs->image); + } else if (qs->pixmap) { + mBrush = QBrush(*qs->pixmap); + } else { + // do something smart + mBrush = QBrush(0xff0000ff); + } + } else { + cairo_image_surface_t *isurf = NULL; + + if (surface->type == CAIRO_SURFACE_TYPE_IMAGE) { + isurf = (cairo_image_surface_t*) surface; + } else { + void *image_extra; + + if (_cairo_surface_acquire_source_image (surface, &isurf, &image_extra) == CAIRO_STATUS_SUCCESS) { + mAcquiredImageParent = surface; + mAcquiredImage = isurf; + mAcquiredImageExtra = image_extra; + } else { + isurf = NULL; + } + } + + if (isurf) { + mBrush = QBrush (QImage ((const uchar *) isurf->data, + isurf->width, + isurf->height, + isurf->stride, + _qimage_format_from_cairo_format (isurf->format))); + } else { + mBrush = QBrush(0x0000ffff); + } + } + } else if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || + pattern->type == CAIRO_PATTERN_TYPE_RADIAL) + { + QGradient *grad; + cairo_bool_t reverse_stops = FALSE; + cairo_bool_t emulate_reflect = FALSE; + double offset = 0.0; + + cairo_extend_t extend = pattern->extend; + + cairo_gradient_pattern_t *gpat = (cairo_gradient_pattern_t *) pattern; + + if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR) { + cairo_linear_pattern_t *lpat = (cairo_linear_pattern_t *) pattern; + grad = new QLinearGradient (lpat->pd1.x, lpat->pd1.y, + lpat->pd2.x, lpat->pd2.y); + } else if (pattern->type == CAIRO_PATTERN_TYPE_RADIAL) { + cairo_radial_pattern_t *rpat = (cairo_radial_pattern_t *) pattern; + + /* Based on the SVG surface code */ + + cairo_circle_double_t *c0, *c1; + double x0, y0, r0, x1, y1, r1; + + if (rpat->cd1.radius < rpat->cd2.radius) { + c0 = &rpat->cd1; + c1 = &rpat->cd2; + reverse_stops = FALSE; + } else { + c0 = &rpat->cd2; + c1 = &rpat->cd1; + reverse_stops = TRUE; + } + + x0 = c0->center.x; + y0 = c0->center.y; + r0 = c0->radius; + x1 = c1->center.x; + y1 = c1->center.y; + r1 = c1->radius; + + if (r0 == r1) { + grad = new QRadialGradient (x1, y1, r1, x1, y1); + } else { + double fx = (r1 * x0 - r0 * x1) / (r1 - r0); + double fy = (r1 * y0 - r0 * y1) / (r1 - r0); + + /* QPainter doesn't support the inner circle and use instead a gradient focal. + * That means we need to emulate the cairo behaviour by processing the + * cairo gradient stops. + * The CAIRO_EXTENT_NONE and CAIRO_EXTENT_PAD modes are quite easy to handle, + * it's just a matter of stop position translation and calculation of + * the corresponding SVG radial gradient focal. + * The CAIRO_EXTENT_REFLECT and CAIRO_EXTEND_REPEAT modes require to compute a new + * radial gradient, with an new outer circle, equal to r1 - r0 in the CAIRO_EXTEND_REPEAT + * case, and 2 * (r1 - r0) in the CAIRO_EXTENT_REFLECT case, and a new gradient stop + * list that maps to the original cairo stop list. + */ + if ((extend == CAIRO_EXTEND_REFLECT || extend == CAIRO_EXTEND_REPEAT) && r0 > 0.0) { + double r_org = r1; + double r, x, y; + + if (extend == CAIRO_EXTEND_REFLECT) { + r1 = 2 * r1 - r0; + emulate_reflect = TRUE; + } + + offset = fmod (r1, r1 - r0) / (r1 - r0) - 1.0; + r = r1 - r0; + + /* New position of outer circle. */ + x = r * (x1 - fx) / r_org + fx; + y = r * (y1 - fy) / r_org + fy; + + x1 = x; + y1 = y; + r1 = r; + r0 = 0.0; + } else { + offset = r0 / r1; + } + + grad = new QRadialGradient (x1, y1, r1, fx, fy); + + if (extend == CAIRO_EXTEND_NONE && r0 != 0.0) + grad->setColorAt (r0 / r1, Qt::transparent); + } + } + + switch (extend) { + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_PAD: + grad->setSpread(QGradient::PadSpread); + + grad->setColorAt (0.0, Qt::transparent); + grad->setColorAt (1.0, Qt::transparent); + break; + + case CAIRO_EXTEND_REFLECT: + grad->setSpread(QGradient::ReflectSpread); + break; + + case CAIRO_EXTEND_REPEAT: + grad->setSpread(QGradient::RepeatSpread); + break; + } + + for (unsigned int i = 0; i < gpat->n_stops; i++) { + int index = i; + if (reverse_stops) + index = gpat->n_stops - i - 1; + + double offset = gpat->stops[i].offset; + QColor color; + color.setRgbF (gpat->stops[i].color.red, + gpat->stops[i].color.green, + gpat->stops[i].color.blue, + gpat->stops[i].color.alpha); + + if (emulate_reflect) { + offset = offset / 2.0; + grad->setColorAt (1.0 - offset, color); + } + + grad->setColorAt (offset, color); + } + + mBrush = QBrush(*grad); + + delete grad; + } + + if (mBrush.style() != Qt::NoBrush && + pattern->type != CAIRO_PATTERN_TYPE_SOLID && + ! _cairo_matrix_is_identity (&pattern->matrix)) + { + cairo_matrix_t pm = pattern->matrix; + cairo_status_t status = cairo_matrix_invert (&pm); + assert (status == CAIRO_STATUS_SUCCESS); + mBrush.setMatrix (_qmatrix_from_cairo_matrix (pm)); + } + } + + ~PatternToBrushConverter () __attribute__ ((noinline)){ + if (mAcquiredImageParent) + _cairo_surface_release_source_image (mAcquiredImageParent, mAcquiredImage, mAcquiredImageExtra); + } + + operator QBrush& () { + return mBrush; + } + + QBrush mBrush; + + private: + cairo_surface_t *mAcquiredImageParent; + cairo_image_surface_t *mAcquiredImage; + void *mAcquiredImageExtra; +}; + +struct PatternToPenConverter { + PatternToPenConverter (const cairo_pattern_t *source, + const cairo_stroke_style_t *style) : + mBrushConverter(source) + { + Qt::PenJoinStyle join = Qt::MiterJoin; + Qt::PenCapStyle cap = Qt::SquareCap; + + switch (style->line_cap) { + case CAIRO_LINE_CAP_BUTT: + cap = Qt::FlatCap; + break; + case CAIRO_LINE_CAP_ROUND: + cap = Qt::RoundCap; + break; + case CAIRO_LINE_CAP_SQUARE: + cap = Qt::SquareCap; + break; + } + + switch (style->line_join) { + case CAIRO_LINE_JOIN_MITER: + join = Qt::MiterJoin; + break; + case CAIRO_LINE_JOIN_ROUND: + join = Qt::RoundJoin; + break; + case CAIRO_LINE_JOIN_BEVEL: + join = Qt::BevelJoin; + break; + } + + mPen = QPen(mBrushConverter, style->line_width, Qt::SolidLine, cap, join); + mPen.setMiterLimit (style->miter_limit); + + if (style->dash && style->num_dashes) { + Qt::PenStyle pstyle = Qt::NoPen; + + if (style->num_dashes == 2) { + if ((style->dash[0] == style->line_width && + style->dash[1] == style->line_width && style->line_width <= 2.0) || + (style->dash[0] == 0.0 && + style->dash[1] == style->line_width * 2 && cap == Qt::RoundCap)) + { + pstyle = Qt::DotLine; + } else if (style->dash[0] == style->line_width * DASH_LENGTH && + style->dash[1] == style->line_width * DASH_LENGTH && + cap == Qt::FlatCap) + { + pstyle = Qt::DashLine; + } + } + + if (pstyle != Qt::NoPen) { + mPen.setStyle(pstyle); + return; + } + + unsigned int odd_dash = style->num_dashes % 2; + + QVector dashes (odd_dash ? style->num_dashes * 2 : style->num_dashes); + for (unsigned int i = 0; i < odd_dash+1; i++) { + for (unsigned int j = 0; j < style->num_dashes; j++) { + // In Qt, the dash lengths are given in units of line width, whereas + // in cairo, they are in user-space units. We'll always apply the CTM, + // so all we have to do here is divide cairo's dash lengths by the line + // width. + dashes.append (style->dash[j] / style->line_width); + } + } + + mPen.setDashPattern(dashes); + mPen.setDashOffset(style->dash_offset / style->line_width); + } + } + + ~PatternToPenConverter() { } + + operator QPen& () { + return mPen; + } + + QPen mPen; + PatternToBrushConverter mBrushConverter; +}; + +/* + * Core drawing operations + */ + +static bool +_cairo_qt_fast_fill (cairo_qt_surface_t *qs, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path = NULL, + cairo_fill_rule_t fill_rule = CAIRO_FILL_RULE_WINDING, + double tolerance = 0.0, + cairo_antialias_t antialias = CAIRO_ANTIALIAS_NONE) +{ +#if ENABLE_FAST_FILL + QImage *qsSrc_image = NULL; + QPixmap *qsSrc_pixmap = NULL; + std::auto_ptr qsSrc_image_d; + + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t*) source; + if (spattern->surface->type == CAIRO_SURFACE_TYPE_QT) { + cairo_qt_surface_t *p = (cairo_qt_surface_t*) spattern->surface; + + qsSrc_image = p->image; + qsSrc_pixmap = p->pixmap; + } else if (spattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE) { + cairo_image_surface_t *p = (cairo_image_surface_t*) spattern->surface; + qsSrc_image = new QImage((const uchar*) p->data, + p->width, + p->height, + p->stride, + _qimage_format_from_cairo_format(p->format)); + qsSrc_image_d.reset(qsSrc_image); + } + } + + if (!qsSrc_image && !qsSrc_pixmap) + return false; + + // We can only drawTiledPixmap; there's no drawTiledImage + if (! qsSrc_pixmap && + (source->extend == CAIRO_EXTEND_REPEAT || + source->extend == CAIRO_EXTEND_REFLECT)) + { + return false; + } + + QMatrix sourceMatrix = _qmatrix_from_cairo_matrix (source->matrix); + + // We can draw this faster by clipping and calling drawImage/drawPixmap. + // Use our own clipping function so that we can get the + // region handling to end up with the fastest possible clip. + // + // XXX Antialiasing will fail pretty hard here, since we can't clip with AA + // with QPainter. + qs->p->save(); + + if (path) { + cairo_int_status_t status; + + cairo_clip_t clip, old_clip = qs->clipper.clip; + + _cairo_clip_init_copy (&clip, &qs->clipper.clip); + status = (cairo_int_status_t) _cairo_clip_clip (&clip, + path, + fill_rule, + tolerance, + antialias); + if (unlikely (status)) { + qs->p->restore(); + return false; + } + + status = _cairo_qt_surface_set_clip (qs, &clip); + if (unlikely (status)) { + qs->p->restore(); + return false; + } + + _cairo_clip_reset (&clip); + qs->clipper.clip = old_clip; + } + + qs->p->setWorldMatrix (sourceMatrix.inverted(), true); + + switch (source->extend) { + case CAIRO_EXTEND_REPEAT: + // XXX handle reflect by tiling 4 times first + case CAIRO_EXTEND_REFLECT: { + assert (qsSrc_pixmap); + + // Render the tiling to cover the entire destination window (because + // it'll be clipped). Transform the window rect by the inverse + // of the current world transform so that the device coordinates + // end up as the right thing. + QRectF dest = qs->p->worldTransform().inverted().mapRect(QRectF(qs->window)); + QPointF origin = sourceMatrix.map(QPointF(0.0, 0.0)); + + qs->p->drawTiledPixmap (dest, *qsSrc_pixmap, origin); + } + break; + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_PAD: // XXX not exactly right, but good enough + default: + if (qsSrc_image) + qs->p->drawImage (0, 0, *qsSrc_image); + else if (qsSrc_pixmap) + qs->p->drawPixmap (0, 0, *qsSrc_pixmap); + break; + } + + qs->p->restore(); + + return true; +#else + return false; +#endif +} + +static cairo_int_status_t +_cairo_qt_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + cairo_int_status_t status; + + D(fprintf(stderr, "q[%p] paint op:%s\n", abstract_surface, _opstr(op))); + + if (! _op_is_supported (qs, op)) + return _cairo_surface_fallback_paint (abstract_surface, op, source, clip); + + status = _cairo_qt_surface_set_clip (qs, clip); + if (unlikely (status)) + return status; + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op)); + + if (! _cairo_qt_fast_fill (qs, source)) { + PatternToBrushConverter brush (source); + qs->p->fillRect (qs->window, brush); + } + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_qt_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] fill op:%s\n", abstract_surface, _opstr(op))); + + if (! _op_is_supported (qs, op)) + return _cairo_surface_fallback_fill (abstract_surface, op, + source, path, fill_rule, + tolerance, antialias, clip); + + cairo_int_status_t status = _cairo_qt_surface_set_clip (qs, clip); + if (unlikely (status)) + return status; + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op)); + + // XXX Qt4.3, 4.4 misrenders some complex paths if antialiasing is + // enabled + //qs->p->setRenderHint (QPainter::Antialiasing, antialias == CAIRO_ANTIALIAS_NONE ? false : true); + qs->p->setRenderHint (QPainter::SmoothPixmapTransform, source->filter != CAIRO_FILTER_FAST); + + if (! _cairo_qt_fast_fill (qs, source, + path, fill_rule, tolerance, antialias)) + { + PatternToBrushConverter brush(source); + qs->p->fillPath (path_to_qt (path, fill_rule), brush); + } + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_qt_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] stroke op:%s\n", abstract_surface, _opstr(op))); + + if (! _op_is_supported (qs, op)) + return _cairo_surface_fallback_stroke (abstract_surface, op, + source, path, style, ctm, + ctm_inverse, tolerance, + antialias, clip); + + cairo_int_status_t int_status = _cairo_qt_surface_set_clip (qs, clip); + if (unlikely (int_status)) + return int_status; + + QMatrix savedMatrix = qs->p->worldMatrix(); + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op)); + + qs->p->setWorldMatrix (_qmatrix_from_cairo_matrix (*ctm), true); + // XXX Qt4.3, 4.4 misrenders some complex paths if antialiasing is + // enabled + //qs->p->setRenderHint (QPainter::Antialiasing, antialias == CAIRO_ANTIALIAS_NONE ? false : true); + qs->p->setRenderHint (QPainter::SmoothPixmapTransform, source->filter != CAIRO_FILTER_FAST); + + PatternToPenConverter pen(source, style); + + qs->p->setPen(pen); + qs->p->drawPath(path_to_qt (path, ctm_inverse)); + qs->p->setPen(Qt::black); + + qs->p->setWorldMatrix (savedMatrix, false); + + if (qs->supports_porter_duff) + qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_qt_surface_show_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ +#if ((QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)) || defined(QT_GLYPHS_API_BACKPORT)) && 0 + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + // pick out the colour to use from the cairo source + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t*) source; + cairo_scaled_glyph_t* glyph; + // documentation says you have to freeze the cache, but I don't believe it + _cairo_scaled_font_freeze_cache(scaled_font); + + QColor tempColour(solid->color.red * 255, solid->color.green * 255, solid->color.blue * 255); + QVarLengthArray positions(num_glyphs); + QVarLengthArray glyphss(num_glyphs); + FT_Face face = cairo_ft_scaled_font_lock_face (scaled_font); + const FT_Size_Metrics& ftMetrics = face->size->metrics; + QFont font(face->family_name); + font.setStyleStrategy(QFont::NoFontMerging); + font.setBold(face->style_flags & FT_STYLE_FLAG_BOLD); + font.setItalic(face->style_flags & FT_STYLE_FLAG_ITALIC); + font.setKerning(face->face_flags & FT_FACE_FLAG_KERNING); + font.setPixelSize(ftMetrics.y_ppem); + cairo_ft_scaled_font_unlock_face(scaled_font); + qs->p->setFont(font); + qs->p->setPen(tempColour); + for (int currentGlyph = 0; currentGlyph < num_glyphs; currentGlyph++) { + positions[currentGlyph].setX(glyphs[currentGlyph].x); + positions[currentGlyph].setY(glyphs[currentGlyph].y); + glyphss[currentGlyph] = glyphs[currentGlyph].index; + } + qt_draw_glyphs(qs->p, glyphss.data(), positions.data(), num_glyphs); + _cairo_scaled_font_thaw_cache(scaled_font); + return CAIRO_INT_STATUS_SUCCESS; +#else + return _cairo_surface_fallback_glyphs (abstract_surface, op, + source, glyphs, num_glyphs, + scaled_font, clip); +#endif +} + +static cairo_int_status_t +_cairo_qt_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + D(fprintf(stderr, "q[%p] mask op:%s\n", abstract_surface, _opstr(op))); + + if (qs->p && mask->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid_mask = (cairo_solid_pattern_t *) mask; + cairo_int_status_t result; + + qs->p->setOpacity (solid_mask->color.alpha); + + result = _cairo_qt_surface_paint (abstract_surface, op, source, clip); + + qs->p->setOpacity (1.0); + + return result; + } + + // otherwise skip for now + return _cairo_surface_fallback_mask (abstract_surface, op, source, mask, clip); +} + +static cairo_status_t +_cairo_qt_surface_mark_dirty (void *abstract_surface, + int x, int y, + int width, int height) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t *) abstract_surface; + + if (qs->p && !(qs->image || qs->pixmap)) + qs->p->save (); + + return CAIRO_STATUS_SUCCESS; +} + +/* + * Backend struct + */ + +static const cairo_surface_backend_t cairo_qt_surface_backend = { + CAIRO_SURFACE_TYPE_QT, + _cairo_qt_surface_finish, + + _cairo_default_context_create, /* XXX */ + + _cairo_qt_surface_create_similar, + NULL, /* similar image */ + _cairo_qt_surface_map_to_image, + _cairo_qt_surface_unmap_image, + + _cairo_surface_default_source, + _cairo_qt_surface_acquire_source_image, + _cairo_qt_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_qt_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + _cairo_qt_surface_mark_dirty, + + _cairo_qt_surface_paint, + _cairo_qt_surface_mask, + _cairo_qt_surface_stroke, + _cairo_qt_surface_fill, + NULL, /* fill_stroke */ + _cairo_qt_surface_show_glyphs +}; + +cairo_surface_t * +cairo_qt_surface_create (QPainter *painter) +{ + cairo_qt_surface_t *qs; + + qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); + if (qs == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + memset (qs, 0, sizeof(cairo_qt_surface_t)); + + _cairo_surface_init (&qs->base, + &cairo_qt_surface_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + _cairo_surface_clipper_init (&qs->clipper, + _cairo_qt_surface_clipper_intersect_clip_path); + + qs->p = painter; + if (qs->p->paintEngine()) + qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); + else + qs->supports_porter_duff = FALSE; + + // Save so that we can always get back to the original state + qs->p->save(); + + qs->window = painter->window(); + + D(fprintf(stderr, "qpainter_surface_create: window: [%d %d %d %d] pd:%d\n", + qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), + qs->supports_porter_duff)); + + return &qs->base; +} + +cairo_surface_t * +cairo_qt_surface_create_with_qimage (cairo_format_t format, + int width, + int height) +{ + cairo_qt_surface_t *qs; + + qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); + if (qs == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + memset (qs, 0, sizeof(cairo_qt_surface_t)); + + _cairo_surface_init (&qs->base, + &cairo_qt_surface_backend, + NULL, /* device */ + _cairo_content_from_format (format)); + + _cairo_surface_clipper_init (&qs->clipper, + _cairo_qt_surface_clipper_intersect_clip_path); + + + QImage *image = new QImage (width, height, + _qimage_format_from_cairo_format (format)); + + qs->image = image; + + if (!image->isNull()) { + qs->p = new QPainter(image); + qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); + } + + qs->image_equiv = cairo_image_surface_create_for_data (image->bits(), + format, + width, height, + image->bytesPerLine()); + + qs->window = QRect(0, 0, width, height); + + D(fprintf(stderr, "qpainter_surface_create: qimage: [%d %d %d %d] pd:%d\n", + qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), + qs->supports_porter_duff)); + + return &qs->base; +} + +cairo_surface_t * +cairo_qt_surface_create_with_qpixmap (cairo_content_t content, + int width, + int height) +{ + cairo_qt_surface_t *qs; + + if ((content & CAIRO_CONTENT_COLOR) == 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); + + qs = (cairo_qt_surface_t *) malloc (sizeof(cairo_qt_surface_t)); + if (qs == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + memset (qs, 0, sizeof(cairo_qt_surface_t)); + + QPixmap *pixmap = new QPixmap (width, height); + if (pixmap == NULL) { + free (qs); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + // By default, a QPixmap is opaque; however, if it's filled + // with a color with a transparency component, it is converted + // to a format that preserves transparency. + if (content == CAIRO_CONTENT_COLOR_ALPHA) + pixmap->fill(Qt::transparent); + + _cairo_surface_init (&qs->base, + &cairo_qt_surface_backend, + NULL, /* device */ + content); + + _cairo_surface_clipper_init (&qs->clipper, + _cairo_qt_surface_clipper_intersect_clip_path); + + qs->pixmap = pixmap; + + if (!pixmap->isNull()) { + qs->p = new QPainter(pixmap); + qs->supports_porter_duff = qs->p->paintEngine()->hasFeature(QPaintEngine::PorterDuff); + } + + qs->window = QRect(0, 0, width, height); + + D(fprintf(stderr, "qpainter_surface_create: qpixmap: [%d %d %d %d] pd:%d\n", + qs->window.x(), qs->window.y(), qs->window.width(), qs->window.height(), + qs->supports_porter_duff)); + + return &qs->base; +} + +/** + * _cairo_surface_is_qt: + * @surface: a #cairo_surface_t + * + * Checks if a surface is a #cairo_qt_surface_t + * + * Return value: True if the surface is an qt surface + **/ +static inline cairo_bool_t +_cairo_surface_is_qt (cairo_surface_t *surface) +{ + return surface->backend == &cairo_qt_surface_backend; +} + +QPainter * +cairo_qt_surface_get_qpainter (cairo_surface_t *surface) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; + + /* Throw an error for a non-qt surface */ + if (! _cairo_surface_is_qt (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return qs->p; +} + +QImage * +cairo_qt_surface_get_qimage (cairo_surface_t *surface) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; + + /* Throw an error for a non-qt surface */ + if (! _cairo_surface_is_qt (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return qs->image; +} + +cairo_surface_t * +cairo_qt_surface_get_image (cairo_surface_t *surface) +{ + cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface; + + /* Throw an error for a non-qt surface */ + if (! _cairo_surface_is_qt (surface)) { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + } + + return qs->image_equiv; +} + +/* + * TODO: + * + * - Figure out why QBrush isn't working with non-repeated images + * + * - Correct repeat mode; right now, every surface source is EXTEND_REPEAT + * - implement EXTEND_NONE (?? probably need to clip to the extents of the source) + * - implement EXTEND_REFLECT (create temporary and copy 4x, then EXTEND_REPEAT that) + * + * - stroke-image failure + * + * - Implement mask() with non-solid masks (probably will need to use a temporary and use IN) + * + * - Implement gradient sources + * + * - Make create_similar smarter -- create QPixmaps in more circumstances + * (e.g. if the pixmap can have alpha) + * + * - Implement show_glyphs() in terms of Qt + * + */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-qt.h b/Build/source/libs/cairo/cairo-src/src/cairo-qt.h new file mode 100644 index 00000000000..c20bbb18d0b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-qt.h @@ -0,0 +1,85 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Corporation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#ifndef CAIRO_QT_H +#define CAIRO_QT_H + +#include "cairo.h" + +#if CAIRO_HAS_QT_SURFACE + +#include +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_qt_surface_create (QPainter *painter); + +cairo_public cairo_surface_t * +cairo_qt_surface_create_with_qimage (cairo_format_t format, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_qt_surface_create_with_qpixmap (cairo_content_t content, + int width, + int height); + +cairo_public QPainter * +cairo_qt_surface_get_qpainter (cairo_surface_t *surface); + +/* XXX needs hooking to generic surface layer, my vote is for +cairo_public cairo_surface_t * +cairo_surface_map_image (cairo_surface_t *surface); +cairo_public void +cairo_surface_unmap_image (cairo_surface_t *surface, cairo_surface_t *image); +*/ +cairo_public cairo_surface_t * +cairo_qt_surface_get_image (cairo_surface_t *surface); + +cairo_public QImage * +cairo_qt_surface_get_qimage (cairo_surface_t *surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_QT_SURFACE */ + +# error Cairo was not compiled with support for the Qt backend + +#endif /* CAIRO_HAS_QT_SURFACE */ + +#endif /* CAIRO_QT_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-quartz-font.c b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-font.c new file mode 100644 index 00000000000..feee61a0d86 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-font.c @@ -0,0 +1,859 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright � 2008 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#include "cairoint.h" + +#include + +#include "cairo-image-surface-private.h" +#include "cairo-quartz.h" +#include "cairo-quartz-private.h" + +#include "cairo-error-private.h" + +/** + * SECTION:cairo-quartz-fonts + * @Title: Quartz (CGFont) Fonts + * @Short_Description: Font support via CGFont on OS X + * @See_Also: #cairo_font_face_t + * + * The Quartz font backend is primarily used to render text on Apple + * MacOS X systems. The CGFont API is used for the internal + * implementation of the font backend methods. + **/ + +/** + * CAIRO_HAS_QUARTZ_FONT: + * + * Defined if the Quartz font backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.6 + **/ + +static CFDataRef (*CGFontCopyTableForTagPtr) (CGFontRef font, uint32_t tag) = NULL; + +/* CreateWithFontName exists in 10.5, but not in 10.4; CreateWithName isn't public in 10.4 */ +static CGFontRef (*CGFontCreateWithFontNamePtr) (CFStringRef) = NULL; +static CGFontRef (*CGFontCreateWithNamePtr) (const char *) = NULL; + +/* These aren't public before 10.5, and some have different names in 10.4 */ +static int (*CGFontGetUnitsPerEmPtr) (CGFontRef) = NULL; +static bool (*CGFontGetGlyphAdvancesPtr) (CGFontRef, const CGGlyph[], size_t, int[]) = NULL; +static bool (*CGFontGetGlyphBBoxesPtr) (CGFontRef, const CGGlyph[], size_t, CGRect[]) = NULL; +static CGRect (*CGFontGetFontBBoxPtr) (CGFontRef) = NULL; + +/* Not public, but present */ +static void (*CGFontGetGlyphsForUnicharsPtr) (CGFontRef, const UniChar[], const CGGlyph[], size_t) = NULL; +static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; +static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; + +/* CGFontGetHMetrics isn't public, but the other functions are public/present in 10.5 */ +typedef struct { + int ascent; + int descent; + int leading; +} quartz_CGFontMetrics; +static quartz_CGFontMetrics* (*CGFontGetHMetricsPtr) (CGFontRef fontRef) = NULL; +static int (*CGFontGetAscentPtr) (CGFontRef fontRef) = NULL; +static int (*CGFontGetDescentPtr) (CGFontRef fontRef) = NULL; +static int (*CGFontGetLeadingPtr) (CGFontRef fontRef) = NULL; + +/* Not public anymore in 64-bits nor in 10.7 */ +static ATSFontRef (*FMGetATSFontRefFromFontPtr) (FMFont iFont) = NULL; + +static cairo_bool_t _cairo_quartz_font_symbol_lookup_done = FALSE; +static cairo_bool_t _cairo_quartz_font_symbols_present = FALSE; + +static void +quartz_font_ensure_symbols(void) +{ + if (_cairo_quartz_font_symbol_lookup_done) + return; + + CGFontCopyTableForTagPtr = dlsym(RTLD_DEFAULT, "CGFontCopyTableForTag"); + + /* Look for the 10.5 versions first */ + CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBBoxes"); + if (!CGFontGetGlyphBBoxesPtr) + CGFontGetGlyphBBoxesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphBoundingBoxes"); + + CGFontGetGlyphsForUnicharsPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnichars"); + if (!CGFontGetGlyphsForUnicharsPtr) + CGFontGetGlyphsForUnicharsPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnicodes"); + + CGFontGetFontBBoxPtr = dlsym(RTLD_DEFAULT, "CGFontGetFontBBox"); + + /* We just need one of these two */ + CGFontCreateWithFontNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithFontName"); + CGFontCreateWithNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithName"); + + /* These have the same name in 10.4 and 10.5 */ + CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm"); + CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphAdvances"); + + CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics"); + CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent"); + CGFontGetDescentPtr = dlsym(RTLD_DEFAULT, "CGFontGetDescent"); + CGFontGetLeadingPtr = dlsym(RTLD_DEFAULT, "CGFontGetLeading"); + + CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing"); + CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing"); + + FMGetATSFontRefFromFontPtr = dlsym(RTLD_DEFAULT, "FMGetATSFontRefFromFont"); + + if ((CGFontCreateWithFontNamePtr || CGFontCreateWithNamePtr) && + CGFontGetGlyphBBoxesPtr && + CGFontGetGlyphsForUnicharsPtr && + CGFontGetUnitsPerEmPtr && + CGFontGetGlyphAdvancesPtr && + (CGFontGetHMetricsPtr || (CGFontGetAscentPtr && CGFontGetDescentPtr && CGFontGetLeadingPtr))) + _cairo_quartz_font_symbols_present = TRUE; + + _cairo_quartz_font_symbol_lookup_done = TRUE; +} + +typedef struct _cairo_quartz_font_face cairo_quartz_font_face_t; +typedef struct _cairo_quartz_scaled_font cairo_quartz_scaled_font_t; + +struct _cairo_quartz_scaled_font { + cairo_scaled_font_t base; +}; + +struct _cairo_quartz_font_face { + cairo_font_face_t base; + + CGFontRef cgFont; +}; + +/* + * font face backend + */ + +static cairo_status_t +_cairo_quartz_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, + cairo_font_face_t **font_face) +{ + const char *family; + char *full_name; + CFStringRef cgFontName = NULL; + CGFontRef cgFont = NULL; + int loop; + + quartz_font_ensure_symbols(); + if (! _cairo_quartz_font_symbols_present) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + family = toy_face->family; + full_name = malloc (strlen (family) + 64); // give us a bit of room to tack on Bold, Oblique, etc. + /* handle CSS-ish faces */ + if (!strcmp(family, "serif") || !strcmp(family, "Times Roman")) + family = "Times"; + else if (!strcmp(family, "sans-serif") || !strcmp(family, "sans")) + family = "Helvetica"; + else if (!strcmp(family, "cursive")) + family = "Apple Chancery"; + else if (!strcmp(family, "fantasy")) + family = "Papyrus"; + else if (!strcmp(family, "monospace") || !strcmp(family, "mono")) + family = "Courier"; + + /* Try to build up the full name, e.g. "Helvetica Bold Oblique" first, + * then drop the bold, then drop the slant, then drop both.. finally + * just use "Helvetica". And if Helvetica doesn't exist, give up. + */ + for (loop = 0; loop < 5; loop++) { + if (loop == 4) + family = "Helvetica"; + + strcpy (full_name, family); + + if (loop < 3 && (loop & 1) == 0) { + if (toy_face->weight == CAIRO_FONT_WEIGHT_BOLD) + strcat (full_name, " Bold"); + } + + if (loop < 3 && (loop & 2) == 0) { + if (toy_face->slant == CAIRO_FONT_SLANT_ITALIC) + strcat (full_name, " Italic"); + else if (toy_face->slant == CAIRO_FONT_SLANT_OBLIQUE) + strcat (full_name, " Oblique"); + } + + if (CGFontCreateWithFontNamePtr) { + cgFontName = CFStringCreateWithCString (NULL, full_name, kCFStringEncodingASCII); + cgFont = CGFontCreateWithFontNamePtr (cgFontName); + CFRelease (cgFontName); + } else { + cgFont = CGFontCreateWithNamePtr (full_name); + } + + if (cgFont) + break; + } + + if (!cgFont) { + /* Give up */ + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + *font_face = cairo_quartz_font_face_create_for_cgfont (cgFont); + CGFontRelease (cgFont); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_quartz_font_face_destroy (void *abstract_face) +{ + cairo_quartz_font_face_t *font_face = (cairo_quartz_font_face_t*) abstract_face; + + CGFontRelease (font_face->cgFont); + return TRUE; +} + +static const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend; + +static cairo_status_t +_cairo_quartz_font_face_scaled_font_create (void *abstract_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + cairo_scaled_font_t **font_out) +{ + cairo_quartz_font_face_t *font_face = abstract_face; + cairo_quartz_scaled_font_t *font = NULL; + cairo_status_t status; + cairo_font_extents_t fs_metrics; + double ems; + CGRect bbox; + + quartz_font_ensure_symbols(); + if (!_cairo_quartz_font_symbols_present) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font = malloc(sizeof(cairo_quartz_scaled_font_t)); + if (font == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memset (font, 0, sizeof(cairo_quartz_scaled_font_t)); + + status = _cairo_scaled_font_init (&font->base, + &font_face->base, font_matrix, ctm, options, + &_cairo_quartz_scaled_font_backend); + if (status) + goto FINISH; + + ems = CGFontGetUnitsPerEmPtr (font_face->cgFont); + + /* initialize metrics */ + if (CGFontGetFontBBoxPtr && CGFontGetAscentPtr) { + fs_metrics.ascent = (CGFontGetAscentPtr (font_face->cgFont) / ems); + fs_metrics.descent = - (CGFontGetDescentPtr (font_face->cgFont) / ems); + fs_metrics.height = fs_metrics.ascent + fs_metrics.descent + + (CGFontGetLeadingPtr (font_face->cgFont) / ems); + + bbox = CGFontGetFontBBoxPtr (font_face->cgFont); + fs_metrics.max_x_advance = CGRectGetMaxX(bbox) / ems; + fs_metrics.max_y_advance = 0.0; + } else { + CGGlyph wGlyph; + UniChar u; + + quartz_CGFontMetrics *m; + m = CGFontGetHMetricsPtr (font_face->cgFont); + + /* On OX 10.4, GetHMetricsPtr sometimes returns NULL for unknown reasons */ + if (!m) { + status = _cairo_error(CAIRO_STATUS_NULL_POINTER); + goto FINISH; + } + + fs_metrics.ascent = (m->ascent / ems); + fs_metrics.descent = - (m->descent / ems); + fs_metrics.height = fs_metrics.ascent + fs_metrics.descent + (m->leading / ems); + + /* We kind of have to guess here; W's big, right? */ + u = (UniChar) 'W'; + CGFontGetGlyphsForUnicharsPtr (font_face->cgFont, &u, &wGlyph, 1); + if (wGlyph && CGFontGetGlyphBBoxesPtr (font_face->cgFont, &wGlyph, 1, &bbox)) { + fs_metrics.max_x_advance = CGRectGetMaxX(bbox) / ems; + fs_metrics.max_y_advance = 0.0; + } else { + fs_metrics.max_x_advance = 0.0; + fs_metrics.max_y_advance = 0.0; + } + } + + status = _cairo_scaled_font_set_metrics (&font->base, &fs_metrics); + +FINISH: + if (status != CAIRO_STATUS_SUCCESS) { + free (font); + } else { + *font_out = (cairo_scaled_font_t*) font; + } + + return status; +} + +const cairo_font_face_backend_t _cairo_quartz_font_face_backend = { + CAIRO_FONT_TYPE_QUARTZ, + _cairo_quartz_font_face_create_for_toy, + _cairo_quartz_font_face_destroy, + _cairo_quartz_font_face_scaled_font_create +}; + +/** + * cairo_quartz_font_face_create_for_cgfont: + * @font: a #CGFontRef obtained through a method external to cairo. + * + * Creates a new font for the Quartz font backend based on a + * #CGFontRef. This font can then be used with + * cairo_set_font_face() or cairo_scaled_font_create(). + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.6 + **/ +cairo_font_face_t * +cairo_quartz_font_face_create_for_cgfont (CGFontRef font) +{ + cairo_quartz_font_face_t *font_face; + + quartz_font_ensure_symbols(); + + font_face = malloc (sizeof (cairo_quartz_font_face_t)); + if (!font_face) { + cairo_status_t ignore_status; + ignore_status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *)&_cairo_font_face_nil; + } + + font_face->cgFont = CGFontRetain (font); + + _cairo_font_face_init (&font_face->base, &_cairo_quartz_font_face_backend); + + return &font_face->base; +} + +/* + * scaled font backend + */ + +static cairo_quartz_font_face_t * +_cairo_quartz_scaled_to_face (void *abstract_font) +{ + cairo_quartz_scaled_font_t *sfont = (cairo_quartz_scaled_font_t*) abstract_font; + cairo_font_face_t *font_face = sfont->base.font_face; + assert (font_face->backend->type == CAIRO_FONT_TYPE_QUARTZ); + return (cairo_quartz_font_face_t*) font_face; +} + +static void +_cairo_quartz_scaled_font_fini(void *abstract_font) +{ +} + +#define INVALID_GLYPH 0x00 + +static inline CGGlyph +_cairo_quartz_scaled_glyph_index (cairo_scaled_glyph_t *scaled_glyph) { + unsigned long index = _cairo_scaled_glyph_index (scaled_glyph); + if (index > 0xffff) + return INVALID_GLYPH; + return (CGGlyph) index; +} + +static cairo_int_status_t +_cairo_quartz_init_glyph_metrics (cairo_quartz_scaled_font_t *font, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + + cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); + cairo_text_extents_t extents = {0, 0, 0, 0, 0, 0}; + CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); + int advance; + CGRect bbox; + double emscale = CGFontGetUnitsPerEmPtr (font_face->cgFont); + double xmin, ymin, xmax, ymax; + + if (glyph == INVALID_GLYPH) + goto FAIL; + + if (!CGFontGetGlyphAdvancesPtr (font_face->cgFont, &glyph, 1, &advance) || + !CGFontGetGlyphBBoxesPtr (font_face->cgFont, &glyph, 1, &bbox)) + goto FAIL; + + /* broken fonts like Al Bayan return incorrect bounds for some null characters, + see https://bugzilla.mozilla.org/show_bug.cgi?id=534260 */ + if (unlikely (bbox.origin.x == -32767 && + bbox.origin.y == -32767 && + bbox.size.width == 65534 && + bbox.size.height == 65534)) { + bbox.origin.x = bbox.origin.y = 0; + bbox.size.width = bbox.size.height = 0; + } + + bbox = CGRectMake (bbox.origin.x / emscale, + bbox.origin.y / emscale, + bbox.size.width / emscale, + bbox.size.height / emscale); + + /* Should we want to always integer-align glyph extents, we can do so in this way */ +#if 0 + { + CGAffineTransform textMatrix; + textMatrix = CGAffineTransformMake (font->base.scale.xx, + -font->base.scale.yx, + -font->base.scale.xy, + font->base.scale.yy, + 0.0f, 0.0f); + + bbox = CGRectApplyAffineTransform (bbox, textMatrix); + bbox = CGRectIntegral (bbox); + bbox = CGRectApplyAffineTransform (bbox, CGAffineTransformInvert (textMatrix)); + } +#endif + +#if 0 + fprintf (stderr, "[0x%04x] bbox: %f %f %f %f\n", glyph, + bbox.origin.x / emscale, bbox.origin.y / emscale, + bbox.size.width / emscale, bbox.size.height / emscale); +#endif + + xmin = CGRectGetMinX(bbox); + ymin = CGRectGetMinY(bbox); + xmax = CGRectGetMaxX(bbox); + ymax = CGRectGetMaxY(bbox); + + extents.x_bearing = xmin; + extents.y_bearing = - ymax; + extents.width = xmax - xmin; + extents.height = ymax - ymin; + + extents.x_advance = (double) advance / emscale; + extents.y_advance = 0.0; + +#if 0 + fprintf (stderr, "[0x%04x] extents: bearings: %f %f dim: %f %f adv: %f\n\n", glyph, + extents.x_bearing, extents.y_bearing, extents.width, extents.height, extents.x_advance); +#endif + + FAIL: + _cairo_scaled_glyph_set_metrics (scaled_glyph, + &font->base, + &extents); + + return status; +} + +static void +_cairo_quartz_path_apply_func (void *info, const CGPathElement *el) +{ + cairo_path_fixed_t *path = (cairo_path_fixed_t *) info; + cairo_status_t status; + + switch (el->type) { + case kCGPathElementMoveToPoint: + status = _cairo_path_fixed_move_to (path, + _cairo_fixed_from_double(el->points[0].x), + _cairo_fixed_from_double(el->points[0].y)); + assert(!status); + break; + case kCGPathElementAddLineToPoint: + status = _cairo_path_fixed_line_to (path, + _cairo_fixed_from_double(el->points[0].x), + _cairo_fixed_from_double(el->points[0].y)); + assert(!status); + break; + case kCGPathElementAddQuadCurveToPoint: { + cairo_fixed_t fx, fy; + double x, y; + if (!_cairo_path_fixed_get_current_point (path, &fx, &fy)) + fx = fy = 0; + x = _cairo_fixed_to_double (fx); + y = _cairo_fixed_to_double (fy); + + status = _cairo_path_fixed_curve_to (path, + _cairo_fixed_from_double((x + el->points[0].x * 2.0) / 3.0), + _cairo_fixed_from_double((y + el->points[0].y * 2.0) / 3.0), + _cairo_fixed_from_double((el->points[0].x * 2.0 + el->points[1].x) / 3.0), + _cairo_fixed_from_double((el->points[0].y * 2.0 + el->points[1].y) / 3.0), + _cairo_fixed_from_double(el->points[1].x), + _cairo_fixed_from_double(el->points[1].y)); + } + assert(!status); + break; + case kCGPathElementAddCurveToPoint: + status = _cairo_path_fixed_curve_to (path, + _cairo_fixed_from_double(el->points[0].x), + _cairo_fixed_from_double(el->points[0].y), + _cairo_fixed_from_double(el->points[1].x), + _cairo_fixed_from_double(el->points[1].y), + _cairo_fixed_from_double(el->points[2].x), + _cairo_fixed_from_double(el->points[2].y)); + assert(!status); + break; + case kCGPathElementCloseSubpath: + status = _cairo_path_fixed_close_path (path); + assert(!status); + break; + } +} + +static cairo_int_status_t +_cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); + CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); + CGAffineTransform textMatrix; + CGPathRef glyphPath; + CTFontRef ctFont; + cairo_path_fixed_t *path; + + if (glyph == INVALID_GLYPH) { + _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, _cairo_path_fixed_create()); + return CAIRO_STATUS_SUCCESS; + } + + /* scale(1,-1) * font->base.scale */ + textMatrix = CGAffineTransformMake (font->base.scale.xx, + font->base.scale.yx, + -font->base.scale.xy, + -font->base.scale.yy, + 0, 0); + + ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 1.0, NULL, NULL); + glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix); + CFRelease (ctFont); + if (!glyphPath) + return CAIRO_INT_STATUS_UNSUPPORTED; + + path = _cairo_path_fixed_create (); + if (!path) { + CGPathRelease (glyphPath); + return _cairo_error(CAIRO_STATUS_NO_MEMORY); + } + + CGPathApply (glyphPath, path, _cairo_quartz_path_apply_func); + + CGPathRelease (glyphPath); + + _cairo_scaled_glyph_set_path (scaled_glyph, &font->base, path); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_quartz_init_glyph_surface (cairo_quartz_scaled_font_t *font, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + + cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font); + + cairo_image_surface_t *surface = NULL; + + CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); + + int advance; + CGRect bbox; + double width, height; + double emscale = CGFontGetUnitsPerEmPtr (font_face->cgFont); + + CGContextRef cgContext = NULL; + CGAffineTransform textMatrix; + CGRect glyphRect, glyphRectInt; + CGPoint glyphOrigin; + + //fprintf (stderr, "scaled_glyph: %p surface: %p\n", scaled_glyph, scaled_glyph->surface); + + /* Create blank 2x2 image if we don't have this character. + * Maybe we should draw a better missing-glyph slug or something, + * but this is ok for now. + */ + if (glyph == INVALID_GLYPH) { + surface = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2); + status = cairo_surface_status ((cairo_surface_t *) surface); + if (status) + return status; + + _cairo_scaled_glyph_set_surface (scaled_glyph, + &font->base, + surface); + return CAIRO_STATUS_SUCCESS; + } + + if (!CGFontGetGlyphAdvancesPtr (font_face->cgFont, &glyph, 1, &advance) || + !CGFontGetGlyphBBoxesPtr (font_face->cgFont, &glyph, 1, &bbox)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* scale(1,-1) * font->base.scale * scale(1,-1) */ + textMatrix = CGAffineTransformMake (font->base.scale.xx, + -font->base.scale.yx, + -font->base.scale.xy, + font->base.scale.yy, + 0, -0); + glyphRect = CGRectMake (bbox.origin.x / emscale, + bbox.origin.y / emscale, + bbox.size.width / emscale, + bbox.size.height / emscale); + + glyphRect = CGRectApplyAffineTransform (glyphRect, textMatrix); + + /* Round the rectangle outwards, so that we don't have to deal + * with non-integer-pixel origins or dimensions. + */ + glyphRectInt = CGRectIntegral (glyphRect); + +#if 0 + fprintf (stderr, "glyphRect[o]: %f %f %f %f\n", + glyphRect.origin.x, glyphRect.origin.y, glyphRect.size.width, glyphRect.size.height); + fprintf (stderr, "glyphRectInt: %f %f %f %f\n", + glyphRectInt.origin.x, glyphRectInt.origin.y, glyphRectInt.size.width, glyphRectInt.size.height); +#endif + + glyphOrigin = glyphRectInt.origin; + + //textMatrix = CGAffineTransformConcat (textMatrix, CGAffineTransformInvert (ctm)); + + width = glyphRectInt.size.width; + height = glyphRectInt.size.height; + + //fprintf (stderr, "glyphRect[n]: %f %f %f %f\n", glyphRect.origin.x, glyphRect.origin.y, glyphRect.size.width, glyphRect.size.height); + + surface = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_A8, width, height); + if (surface->base.status) + return surface->base.status; + + if (surface->width != 0 && surface->height != 0) { + cgContext = CGBitmapContextCreate (surface->data, + surface->width, + surface->height, + 8, + surface->stride, + NULL, + kCGImageAlphaOnly); + + if (cgContext == NULL) { + cairo_surface_destroy (&surface->base); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + CGContextSetFont (cgContext, font_face->cgFont); + CGContextSetFontSize (cgContext, 1.0); + CGContextSetTextMatrix (cgContext, textMatrix); + + switch (font->base.options.antialias) { + case CAIRO_ANTIALIAS_SUBPIXEL: + case CAIRO_ANTIALIAS_BEST: + CGContextSetShouldAntialias (cgContext, TRUE); + CGContextSetShouldSmoothFonts (cgContext, TRUE); + if (CGContextSetAllowsFontSmoothingPtr && + !CGContextGetAllowsFontSmoothingPtr (cgContext)) + CGContextSetAllowsFontSmoothingPtr (cgContext, TRUE); + break; + case CAIRO_ANTIALIAS_NONE: + CGContextSetShouldAntialias (cgContext, FALSE); + break; + case CAIRO_ANTIALIAS_GRAY: + case CAIRO_ANTIALIAS_GOOD: + case CAIRO_ANTIALIAS_FAST: + CGContextSetShouldAntialias (cgContext, TRUE); + CGContextSetShouldSmoothFonts (cgContext, FALSE); + break; + case CAIRO_ANTIALIAS_DEFAULT: + default: + /* Don't do anything */ + break; + } + + CGContextSetAlpha (cgContext, 1.0); + CGContextShowGlyphsAtPoint (cgContext, - glyphOrigin.x, - glyphOrigin.y, &glyph, 1); + + CGContextRelease (cgContext); + } + + cairo_surface_set_device_offset (&surface->base, + - glyphOrigin.x, + height + glyphOrigin.y); + + _cairo_scaled_glyph_set_surface (scaled_glyph, &font->base, surface); + + return status; +} + +static cairo_int_status_t +_cairo_quartz_scaled_glyph_init (void *abstract_font, + cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_glyph_info_t info) +{ + cairo_quartz_scaled_font_t *font = (cairo_quartz_scaled_font_t *) abstract_font; + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + + if (!status && (info & CAIRO_SCALED_GLYPH_INFO_METRICS)) + status = _cairo_quartz_init_glyph_metrics (font, scaled_glyph); + + if (!status && (info & CAIRO_SCALED_GLYPH_INFO_PATH)) + status = _cairo_quartz_init_glyph_path (font, scaled_glyph); + + if (!status && (info & CAIRO_SCALED_GLYPH_INFO_SURFACE)) + status = _cairo_quartz_init_glyph_surface (font, scaled_glyph); + + return status; +} + +static unsigned long +_cairo_quartz_ucs4_to_index (void *abstract_font, + uint32_t ucs4) +{ + cairo_quartz_scaled_font_t *font = (cairo_quartz_scaled_font_t*) abstract_font; + cairo_quartz_font_face_t *ffont = _cairo_quartz_scaled_to_face(font); + UniChar u = (UniChar) ucs4; + CGGlyph glyph; + + CGFontGetGlyphsForUnicharsPtr (ffont->cgFont, &u, &glyph, 1); + + return glyph; +} + +static cairo_int_status_t +_cairo_quartz_load_truetype_table (void *abstract_font, + unsigned long tag, + long offset, + unsigned char *buffer, + unsigned long *length) +{ + cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face (abstract_font); + CFDataRef data = NULL; + + if (likely (CGFontCopyTableForTagPtr)) + data = CGFontCopyTableForTagPtr (font_face->cgFont, tag); + + if (!data) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (buffer == NULL) { + *length = CFDataGetLength (data); + CFRelease (data); + return CAIRO_STATUS_SUCCESS; + } + + if (CFDataGetLength (data) < offset + (long) *length) { + CFRelease (data); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + CFDataGetBytes (data, CFRangeMake (offset, *length), buffer); + CFRelease (data); + + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend = { + CAIRO_FONT_TYPE_QUARTZ, + _cairo_quartz_scaled_font_fini, + _cairo_quartz_scaled_glyph_init, + NULL, /* text_to_glyphs */ + _cairo_quartz_ucs4_to_index, + _cairo_quartz_load_truetype_table, + NULL, /* map_glyphs_to_unicode */ +}; + +/* + * private methods that the quartz surface uses + */ + +CGFontRef +_cairo_quartz_scaled_font_get_cg_font_ref (cairo_scaled_font_t *abstract_font) +{ + cairo_quartz_font_face_t *ffont = _cairo_quartz_scaled_to_face(abstract_font); + + return ffont->cgFont; +} + +/* + * compat with old ATSUI backend + */ + +/** + * cairo_quartz_font_face_create_for_atsu_font_id: + * @font_id: an ATSUFontID for the font. + * + * Creates a new font for the Quartz font backend based on an + * #ATSUFontID. This font can then be used with + * cairo_set_font_face() or cairo_scaled_font_create(). + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.6 + **/ +cairo_font_face_t * +cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id) +{ + quartz_font_ensure_symbols(); + + if (FMGetATSFontRefFromFontPtr != NULL) { + ATSFontRef atsFont = FMGetATSFontRefFromFontPtr (font_id); + CGFontRef cgFont = CGFontCreateWithPlatformFont (&atsFont); + cairo_font_face_t *ff; + + ff = cairo_quartz_font_face_create_for_cgfont (cgFont); + + CGFontRelease (cgFont); + + return ff; + } else { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *)&_cairo_font_face_nil; + } +} + +/* This is the old name for the above function, exported for compat purposes */ +cairo_font_face_t *cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id); + +cairo_font_face_t * +cairo_atsui_font_face_create_for_atsu_font_id (ATSUFontID font_id) +{ + return cairo_quartz_font_face_create_for_atsu_font_id (font_id); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-quartz-image-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-image-surface.c new file mode 100644 index 00000000000..498a7b06436 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-image-surface.c @@ -0,0 +1,387 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright � 2008 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#include "cairoint.h" + +#include "cairo-image-surface-inline.h" +#include "cairo-quartz-image.h" +#include "cairo-quartz-private.h" +#include "cairo-surface-backend-private.h" + +#include "cairo-error-private.h" +#include "cairo-default-context-private.h" + +#define SURFACE_ERROR_NO_MEMORY (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_NO_MEMORY))) +#define SURFACE_ERROR_TYPE_MISMATCH (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_SURFACE_TYPE_MISMATCH))) +#define SURFACE_ERROR_INVALID_SIZE (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_INVALID_SIZE))) +#define SURFACE_ERROR_INVALID_FORMAT (_cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_INVALID_FORMAT))) + +static void +DataProviderReleaseCallback (void *info, const void *data, size_t size) +{ + cairo_surface_t *surface = (cairo_surface_t *) info; + cairo_surface_destroy (surface); +} + +static cairo_surface_t * +_cairo_quartz_image_surface_create_similar (void *asurface, + cairo_content_t content, + int width, + int height) +{ + cairo_surface_t *isurf = + _cairo_image_surface_create_with_content (content, width, height); + cairo_surface_t *result = cairo_quartz_image_surface_create (isurf); + cairo_surface_destroy (isurf); + + return result; +} + +static cairo_surface_t * +_cairo_quartz_image_surface_create_similar_image (void *asurface, + cairo_format_t format, + int width, + int height) +{ + cairo_surface_t *isurf = cairo_image_surface_create (format, width, height); + cairo_surface_t *result = cairo_quartz_image_surface_create (isurf); + cairo_surface_destroy (isurf); + + return result; +} + +static cairo_status_t +_cairo_quartz_image_surface_finish (void *asurface) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; + + /* the imageSurface will be destroyed by the data provider's release callback */ + CGImageRelease (surface->image); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_quartz_image_surface_acquire_source_image (void *asurface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; + + *image_out = surface->imageSurface; + *image_extra = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_image_surface_t * +_cairo_quartz_image_surface_map_to_image (void *asurface, + const cairo_rectangle_int_t *extents) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; + return _cairo_surface_map_to_image (&surface->imageSurface->base, extents); +} + +static cairo_int_status_t +_cairo_quartz_image_surface_unmap_image (void *asurface, + cairo_image_surface_t *image) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; + return _cairo_surface_unmap_image (&surface->imageSurface->base, image); +} + +static cairo_bool_t +_cairo_quartz_image_surface_get_extents (void *asurface, + cairo_rectangle_int_t *extents) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; + + extents->x = 0; + extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + return TRUE; +} + +/* we assume some drawing happened to the image buffer; make sure it's + * represented in the CGImage on flush() + */ + +static cairo_status_t +_cairo_quartz_image_surface_flush (void *asurface, + unsigned flags) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) asurface; + CGImageRef oldImage = surface->image; + CGImageRef newImage = NULL; + + if (flags) + return CAIRO_STATUS_SUCCESS; + + /* XXX only flush if the image has been modified. */ + + /* To be released by the ReleaseCallback */ + cairo_surface_reference ((cairo_surface_t*) surface->imageSurface); + + newImage = CairoQuartzCreateCGImage (surface->imageSurface->format, + surface->imageSurface->width, + surface->imageSurface->height, + surface->imageSurface->stride, + surface->imageSurface->data, + TRUE, + NULL, + DataProviderReleaseCallback, + surface->imageSurface); + + surface->image = newImage; + CGImageRelease (oldImage); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_quartz_image_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_quartz_image_surface_t *surface = abstract_surface; + return _cairo_surface_paint (&surface->imageSurface->base, + op, source, clip); +} + +static cairo_int_status_t +_cairo_quartz_image_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_quartz_image_surface_t *surface = abstract_surface; + return _cairo_surface_mask (&surface->imageSurface->base, + op, source, mask, clip); +} + +static cairo_int_status_t +_cairo_quartz_image_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_quartz_image_surface_t *surface = abstract_surface; + return _cairo_surface_stroke (&surface->imageSurface->base, + op, source, path, + style, ctm, ctm_inverse, + tolerance, antialias, clip); +} + +static cairo_int_status_t +_cairo_quartz_image_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_quartz_image_surface_t *surface = abstract_surface; + return _cairo_surface_fill (&surface->imageSurface->base, + op, source, path, + fill_rule, tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_quartz_image_surface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_quartz_image_surface_t *surface = abstract_surface; + return _cairo_surface_show_text_glyphs (&surface->imageSurface->base, + op, source, + NULL, 0, + glyphs, num_glyphs, + NULL, 0, 0, + scaled_font, clip); +} + + +static const cairo_surface_backend_t cairo_quartz_image_surface_backend = { + CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, + _cairo_quartz_image_surface_finish, + + _cairo_default_context_create, + + _cairo_quartz_image_surface_create_similar, + _cairo_quartz_image_surface_create_similar_image, + _cairo_quartz_image_surface_map_to_image, + _cairo_quartz_image_surface_unmap_image, + + _cairo_surface_default_source, + _cairo_quartz_image_surface_acquire_source_image, + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_quartz_image_surface_get_extents, + NULL, /* get_font_options */ + + _cairo_quartz_image_surface_flush, + NULL, /* mark_dirty_rectangle */ + + _cairo_quartz_image_surface_paint, + _cairo_quartz_image_surface_mask, + _cairo_quartz_image_surface_stroke, + _cairo_quartz_image_surface_fill, + NULL, /* fill-stroke */ + _cairo_quartz_image_surface_glyphs, +}; + +/** + * cairo_quartz_image_surface_create: + * @image_surface: a cairo image surface to wrap with a quartz image surface + * + * Creates a Quartz surface backed by a CGImageRef that references the + * given image surface. The resulting surface can be rendered quickly + * when used as a source when rendering to a #cairo_quartz_surface. If + * the data in the image surface is ever updated, cairo_surface_flush() + * must be called on the #cairo_quartz_image_surface to ensure that the + * CGImageRef refers to the updated data. + * + * Return value: the newly created surface. + * + * Since: 1.6 + **/ +cairo_surface_t * +cairo_quartz_image_surface_create (cairo_surface_t *surface) +{ + cairo_quartz_image_surface_t *qisurf; + + CGImageRef image; + + cairo_image_surface_t *image_surface; + int width, height, stride; + cairo_format_t format; + unsigned char *data; + + if (surface->status) + return surface; + + if (! _cairo_surface_is_image (surface)) + return SURFACE_ERROR_TYPE_MISMATCH; + + image_surface = (cairo_image_surface_t*) surface; + width = image_surface->width; + height = image_surface->height; + stride = image_surface->stride; + format = image_surface->format; + data = image_surface->data; + + if (!_cairo_quartz_verify_surface_size(width, height)) + return SURFACE_ERROR_INVALID_SIZE; + + if (width == 0 || height == 0) + return SURFACE_ERROR_INVALID_SIZE; + + if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) + return SURFACE_ERROR_INVALID_FORMAT; + + qisurf = malloc(sizeof(cairo_quartz_image_surface_t)); + if (qisurf == NULL) + return SURFACE_ERROR_NO_MEMORY; + + memset (qisurf, 0, sizeof(cairo_quartz_image_surface_t)); + + /* In case the create_cgimage fails, this ref will + * be released via the callback (which will be called in + * case of failure.) + */ + cairo_surface_reference (surface); + + image = CairoQuartzCreateCGImage (format, + width, height, + stride, + data, + TRUE, + NULL, + DataProviderReleaseCallback, + image_surface); + + if (!image) { + free (qisurf); + return SURFACE_ERROR_NO_MEMORY; + } + + _cairo_surface_init (&qisurf->base, + &cairo_quartz_image_surface_backend, + NULL, /* device */ + _cairo_content_from_format (format)); + + qisurf->width = width; + qisurf->height = height; + + qisurf->image = image; + qisurf->imageSurface = image_surface; + + return &qisurf->base; +} + + +cairo_surface_t * +cairo_quartz_image_surface_get_image (cairo_surface_t *asurface) +{ + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t*) asurface; + + /* Throw an error for a non-quartz surface */ + if (! _cairo_surface_is_quartz (asurface)) { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + } + + return (cairo_surface_t*) surface->imageSurface; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-quartz-image.h b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-image.h new file mode 100644 index 00000000000..dae234dacae --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-image.h @@ -0,0 +1,59 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright 2008 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#ifndef CAIRO_QUARTZ_IMAGE_H +#define CAIRO_QUARTZ_IMAGE_H + +#include "cairo.h" + +#if CAIRO_HAS_QUARTZ_IMAGE_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_quartz_image_surface_create (cairo_surface_t *image_surface); + +cairo_public cairo_surface_t * +cairo_quartz_image_surface_get_image (cairo_surface_t *surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_QUARTZ_IMAGE_SURFACE */ +# error Cairo was not compiled with support for the quartz-image backend +#endif /* CAIRO_HAS_QUARTZ_IMAGE_SURFACE */ + +#endif /* CAIRO_QUARTZ_IMAGE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-quartz-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-private.h new file mode 100644 index 00000000000..3ef14c3ae60 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-private.h @@ -0,0 +1,109 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Calum Robinson + * Copyright (C) 2006,2007 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Calum Robinson + * + * Contributor(s): + * Calum Robinson + * Vladimir Vukicevic + */ + +#ifndef CAIRO_QUARTZ_PRIVATE_H +#define CAIRO_QUARTZ_PRIVATE_H + +#include "cairoint.h" + +#if CAIRO_HAS_QUARTZ_SURFACE +#include "cairo-quartz.h" +#include "cairo-surface-clipper-private.h" + +#ifdef CGFLOAT_DEFINED +typedef CGFloat cairo_quartz_float_t; +#else +typedef float cairo_quartz_float_t; +#endif + +typedef enum { + DO_DIRECT, + DO_SHADING, + DO_IMAGE, + DO_TILED_IMAGE +} cairo_quartz_action_t; + +typedef struct cairo_quartz_surface { + cairo_surface_t base; + + CGContextRef cgContext; + CGAffineTransform cgContextBaseCTM; + + void *imageData; + cairo_surface_t *imageSurfaceEquiv; + + cairo_surface_clipper_t clipper; + cairo_rectangle_int_t extents; + cairo_rectangle_int_t virtual_extents; +} cairo_quartz_surface_t; + +typedef struct cairo_quartz_image_surface { + cairo_surface_t base; + + int width, height; + + CGImageRef image; + cairo_image_surface_t *imageSurface; +} cairo_quartz_image_surface_t; + +cairo_private cairo_bool_t +_cairo_quartz_verify_surface_size(int width, int height); + +cairo_private cairo_bool_t +_cairo_surface_is_quartz (const cairo_surface_t *surface); + +cairo_private CGImageRef +CairoQuartzCreateCGImage (cairo_format_t format, + unsigned int width, + unsigned int height, + unsigned int stride, + void *data, + cairo_bool_t interpolate, + CGColorSpaceRef colorSpaceOverride, + CGDataProviderReleaseDataCallback releaseCallback, + void *releaseInfo); + +cairo_private CGFontRef +_cairo_quartz_scaled_font_get_cg_font_ref (cairo_scaled_font_t *sfont); + +#else + +# error Cairo was not compiled with support for the quartz backend + +#endif /* CAIRO_HAS_QUARTZ_SURFACE */ + +#endif /* CAIRO_QUARTZ_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-quartz-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-surface.c new file mode 100644 index 00000000000..1116ff94c1e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-quartz-surface.c @@ -0,0 +1,2574 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright � 2006, 2007 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#define _GNU_SOURCE /* required for RTLD_DEFAULT */ +#include "cairoint.h" + +#include "cairo-quartz-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-recording-surface-private.h" + +#include + +#ifndef RTLD_DEFAULT +#define RTLD_DEFAULT ((void *) 0) +#endif + +#include + +#undef QUARTZ_DEBUG + +#ifdef QUARTZ_DEBUG +#define ND(_x) fprintf _x +#else +#define ND(_x) do {} while(0) +#endif + +#define IS_EMPTY(s) ((s)->extents.width == 0 || (s)->extents.height == 0) + +/** + * SECTION:cairo-quartz + * @Title: Quartz Surfaces + * @Short_Description: Rendering to Quartz surfaces + * @See_Also: #cairo_surface_t + * + * The Quartz surface is used to render cairo graphics targeting the + * Apple OS X Quartz rendering system. + **/ + +/** + * CAIRO_HAS_QUARTZ_SURFACE: + * + * Defined if the Quartz surface backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.6 + **/ + +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 +/* This method is private, but it exists. Its params are are exposed + * as args to the NS* method, but not as CG. + */ +enum PrivateCGCompositeMode { + kPrivateCGCompositeClear = 0, + kPrivateCGCompositeCopy = 1, + kPrivateCGCompositeSourceOver = 2, + kPrivateCGCompositeSourceIn = 3, + kPrivateCGCompositeSourceOut = 4, + kPrivateCGCompositeSourceAtop = 5, + kPrivateCGCompositeDestinationOver = 6, + kPrivateCGCompositeDestinationIn = 7, + kPrivateCGCompositeDestinationOut = 8, + kPrivateCGCompositeDestinationAtop = 9, + kPrivateCGCompositeXOR = 10, + kPrivateCGCompositePlusDarker = 11, // (max (0, (1-d) + (1-s))) + kPrivateCGCompositePlusLighter = 12, // (min (1, s + d)) +}; +typedef enum PrivateCGCompositeMode PrivateCGCompositeMode; +CG_EXTERN void CGContextSetCompositeOperation (CGContextRef, PrivateCGCompositeMode); +#endif + +/* Some of these are present in earlier versions of the OS than where + * they are public; other are not public at all + */ +/* public since 10.5 */ +static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL; + +/* public since 10.6 */ +static CGPathRef (*CGContextCopyPathPtr) (CGContextRef) = NULL; +static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; + +/* not yet public */ +static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL; +static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; + +static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE; + +/* + * Utility functions + */ + +#ifdef QUARTZ_DEBUG +static void quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest); +static void quartz_image_to_png (CGImageRef, char *dest); +#endif + +static cairo_quartz_surface_t * +_cairo_quartz_surface_create_internal (CGContextRef cgContext, + cairo_content_t content, + unsigned int width, + unsigned int height); + +/* Load all extra symbols */ +static void quartz_ensure_symbols (void) +{ + if (likely (_cairo_quartz_symbol_lookup_done)) + return; + + CGContextDrawTiledImagePtr = dlsym (RTLD_DEFAULT, "CGContextDrawTiledImage"); + CGContextGetTypePtr = dlsym (RTLD_DEFAULT, "CGContextGetType"); + CGContextCopyPathPtr = dlsym (RTLD_DEFAULT, "CGContextCopyPath"); + CGContextGetAllowsFontSmoothingPtr = dlsym (RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing"); + CGContextSetAllowsFontSmoothingPtr = dlsym (RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing"); + + _cairo_quartz_symbol_lookup_done = TRUE; +} + +CGImageRef +CairoQuartzCreateCGImage (cairo_format_t format, + unsigned int width, + unsigned int height, + unsigned int stride, + void *data, + cairo_bool_t interpolate, + CGColorSpaceRef colorSpaceOverride, + CGDataProviderReleaseDataCallback releaseCallback, + void *releaseInfo) +{ + CGImageRef image = NULL; + CGDataProviderRef dataProvider = NULL; + CGColorSpaceRef colorSpace = colorSpaceOverride; + CGBitmapInfo bitinfo = kCGBitmapByteOrder32Host; + int bitsPerComponent, bitsPerPixel; + + switch (format) { + case CAIRO_FORMAT_ARGB32: + if (colorSpace == NULL) + colorSpace = CGColorSpaceCreateDeviceRGB (); + bitinfo |= kCGImageAlphaPremultipliedFirst; + bitsPerComponent = 8; + bitsPerPixel = 32; + break; + + case CAIRO_FORMAT_RGB24: + if (colorSpace == NULL) + colorSpace = CGColorSpaceCreateDeviceRGB (); + bitinfo |= kCGImageAlphaNoneSkipFirst; + bitsPerComponent = 8; + bitsPerPixel = 32; + break; + + case CAIRO_FORMAT_A8: + bitsPerComponent = 8; + bitsPerPixel = 8; + break; + + case CAIRO_FORMAT_A1: +#ifdef WORDS_BIGENDIAN + bitsPerComponent = 1; + bitsPerPixel = 1; + break; +#endif + + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_RGB16_565: + case CAIRO_FORMAT_INVALID: + default: + return NULL; + } + + dataProvider = CGDataProviderCreateWithData (releaseInfo, + data, + height * stride, + releaseCallback); + + if (unlikely (!dataProvider)) { + // manually release + if (releaseCallback) + releaseCallback (releaseInfo, data, height * stride); + goto FINISH; + } + + if (format == CAIRO_FORMAT_A8 || format == CAIRO_FORMAT_A1) { + cairo_quartz_float_t decode[] = {1.0, 0.0}; + image = CGImageMaskCreate (width, height, + bitsPerComponent, + bitsPerPixel, + stride, + dataProvider, + decode, + interpolate); + } else + image = CGImageCreate (width, height, + bitsPerComponent, + bitsPerPixel, + stride, + colorSpace, + bitinfo, + dataProvider, + NULL, + interpolate, + kCGRenderingIntentDefault); + +FINISH: + + CGDataProviderRelease (dataProvider); + + if (colorSpace != colorSpaceOverride) + CGColorSpaceRelease (colorSpace); + + return image; +} + +static inline cairo_bool_t +_cairo_quartz_is_cgcontext_bitmap_context (CGContextRef cgc) +{ + if (unlikely (cgc == NULL)) + return FALSE; + + if (likely (CGContextGetTypePtr)) { + /* 4 is the type value of a bitmap context */ + return CGContextGetTypePtr (cgc) == 4; + } + + /* This will cause a (harmless) warning to be printed if called on a non-bitmap context */ + return CGBitmapContextGetBitsPerPixel (cgc) != 0; +} + +/* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */ + +#define CG_MAX_HEIGHT SHRT_MAX +#define CG_MAX_WIDTH USHRT_MAX + +/* is the desired size of the surface within bounds? */ +cairo_bool_t +_cairo_quartz_verify_surface_size (int width, int height) +{ + /* hmmm, allow width, height == 0 ? */ + if (width < 0 || height < 0) + return FALSE; + + if (width > CG_MAX_WIDTH || height > CG_MAX_HEIGHT) + return FALSE; + + return TRUE; +} + +/* + * Cairo path -> Quartz path conversion helpers + */ + +/* cairo path -> execute in context */ +static cairo_status_t +_cairo_path_to_quartz_context_move_to (void *closure, + const cairo_point_t *point) +{ + //ND ((stderr, "moveto: %f %f\n", _cairo_fixed_to_double (point->x), _cairo_fixed_to_double (point->y))); + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + CGContextMoveToPoint (closure, x, y); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_to_quartz_context_line_to (void *closure, + const cairo_point_t *point) +{ + //ND ((stderr, "lineto: %f %f\n", _cairo_fixed_to_double (point->x), _cairo_fixed_to_double (point->y))); + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + CGContextAddLineToPoint (closure, x, y); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_to_quartz_context_curve_to (void *closure, + const cairo_point_t *p0, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + //ND ((stderr, "curveto: %f,%f %f,%f %f,%f\n", + // _cairo_fixed_to_double (p0->x), _cairo_fixed_to_double (p0->y), + // _cairo_fixed_to_double (p1->x), _cairo_fixed_to_double (p1->y), + // _cairo_fixed_to_double (p2->x), _cairo_fixed_to_double (p2->y))); + double x0 = _cairo_fixed_to_double (p0->x); + double y0 = _cairo_fixed_to_double (p0->y); + double x1 = _cairo_fixed_to_double (p1->x); + double y1 = _cairo_fixed_to_double (p1->y); + double x2 = _cairo_fixed_to_double (p2->x); + double y2 = _cairo_fixed_to_double (p2->y); + + CGContextAddCurveToPoint (closure, x0, y0, x1, y1, x2, y2); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_path_to_quartz_context_close_path (void *closure) +{ + //ND ((stderr, "closepath\n")); + CGContextClosePath (closure); + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_quartz_cairo_path_to_quartz_context (const cairo_path_fixed_t *path, + CGContextRef closure) +{ + cairo_status_t status; + + CGContextBeginPath (closure); + status = _cairo_path_fixed_interpret (path, + _cairo_path_to_quartz_context_move_to, + _cairo_path_to_quartz_context_line_to, + _cairo_path_to_quartz_context_curve_to, + _cairo_path_to_quartz_context_close_path, + closure); + + assert (status == CAIRO_STATUS_SUCCESS); +} + +/* + * Misc helpers/callbacks + */ + +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 +static PrivateCGCompositeMode +_cairo_quartz_cairo_operator_to_quartz_composite (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_CLEAR: + return kPrivateCGCompositeClear; + case CAIRO_OPERATOR_SOURCE: + return kPrivateCGCompositeCopy; + case CAIRO_OPERATOR_OVER: + return kPrivateCGCompositeSourceOver; + case CAIRO_OPERATOR_IN: + return kPrivateCGCompositeSourceIn; + case CAIRO_OPERATOR_OUT: + return kPrivateCGCompositeSourceOut; + case CAIRO_OPERATOR_ATOP: + return kPrivateCGCompositeSourceAtop; + case CAIRO_OPERATOR_DEST_OVER: + return kPrivateCGCompositeDestinationOver; + case CAIRO_OPERATOR_DEST_IN: + return kPrivateCGCompositeDestinationIn; + case CAIRO_OPERATOR_DEST_OUT: + return kPrivateCGCompositeDestinationOut; + case CAIRO_OPERATOR_DEST_ATOP: + return kPrivateCGCompositeDestinationAtop; + case CAIRO_OPERATOR_XOR: + return kPrivateCGCompositeXOR; + case CAIRO_OPERATOR_ADD: + return kPrivateCGCompositePlusLighter; + + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_SATURATE: + case CAIRO_OPERATOR_MULTIPLY: + case CAIRO_OPERATOR_SCREEN: + case CAIRO_OPERATOR_OVERLAY: + case CAIRO_OPERATOR_DARKEN: + case CAIRO_OPERATOR_LIGHTEN: + case CAIRO_OPERATOR_COLOR_DODGE: + case CAIRO_OPERATOR_COLOR_BURN: + case CAIRO_OPERATOR_HARD_LIGHT: + case CAIRO_OPERATOR_SOFT_LIGHT: + case CAIRO_OPERATOR_DIFFERENCE: + case CAIRO_OPERATOR_EXCLUSION: + case CAIRO_OPERATOR_HSL_HUE: + case CAIRO_OPERATOR_HSL_SATURATION: + case CAIRO_OPERATOR_HSL_COLOR: + case CAIRO_OPERATOR_HSL_LUMINOSITY: + default: + ASSERT_NOT_REACHED; + } +} +#endif + +static CGBlendMode +_cairo_quartz_cairo_operator_to_quartz_blend (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_MULTIPLY: + return kCGBlendModeMultiply; + case CAIRO_OPERATOR_SCREEN: + return kCGBlendModeScreen; + case CAIRO_OPERATOR_OVERLAY: + return kCGBlendModeOverlay; + case CAIRO_OPERATOR_DARKEN: + return kCGBlendModeDarken; + case CAIRO_OPERATOR_LIGHTEN: + return kCGBlendModeLighten; + case CAIRO_OPERATOR_COLOR_DODGE: + return kCGBlendModeColorDodge; + case CAIRO_OPERATOR_COLOR_BURN: + return kCGBlendModeColorBurn; + case CAIRO_OPERATOR_HARD_LIGHT: + return kCGBlendModeHardLight; + case CAIRO_OPERATOR_SOFT_LIGHT: + return kCGBlendModeSoftLight; + case CAIRO_OPERATOR_DIFFERENCE: + return kCGBlendModeDifference; + case CAIRO_OPERATOR_EXCLUSION: + return kCGBlendModeExclusion; + case CAIRO_OPERATOR_HSL_HUE: + return kCGBlendModeHue; + case CAIRO_OPERATOR_HSL_SATURATION: + return kCGBlendModeSaturation; + case CAIRO_OPERATOR_HSL_COLOR: + return kCGBlendModeColor; + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return kCGBlendModeLuminosity; + +#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 + case CAIRO_OPERATOR_CLEAR: + return kCGBlendModeClear; + case CAIRO_OPERATOR_SOURCE: + return kCGBlendModeCopy; + case CAIRO_OPERATOR_OVER: + return kCGBlendModeNormal; + case CAIRO_OPERATOR_IN: + return kCGBlendModeSourceIn; + case CAIRO_OPERATOR_OUT: + return kCGBlendModeSourceOut; + case CAIRO_OPERATOR_ATOP: + return kCGBlendModeSourceAtop; + case CAIRO_OPERATOR_DEST_OVER: + return kCGBlendModeDestinationOver; + case CAIRO_OPERATOR_DEST_IN: + return kCGBlendModeDestinationIn; + case CAIRO_OPERATOR_DEST_OUT: + return kCGBlendModeDestinationOut; + case CAIRO_OPERATOR_DEST_ATOP: + return kCGBlendModeDestinationAtop; + case CAIRO_OPERATOR_XOR: + return kCGBlendModeXOR; + case CAIRO_OPERATOR_ADD: + return kCGBlendModePlusLighter; +#else + case CAIRO_OPERATOR_CLEAR: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_OUT: + case CAIRO_OPERATOR_ATOP: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_DEST_OUT: + case CAIRO_OPERATOR_DEST_ATOP: + case CAIRO_OPERATOR_XOR: + case CAIRO_OPERATOR_ADD: +#endif + + case CAIRO_OPERATOR_DEST: + case CAIRO_OPERATOR_SATURATE: + default: + ASSERT_NOT_REACHED; + } +} + +static cairo_int_status_t +_cairo_cgcontext_set_cairo_operator (CGContextRef context, cairo_operator_t op) +{ + CGBlendMode blendmode; + + assert (op != CAIRO_OPERATOR_DEST); + + /* Quartz doesn't support SATURATE at all. COLOR_DODGE and + * COLOR_BURN in Quartz follow the ISO32000 definition, but cairo + * uses the definition from the Adobe Supplement. + */ + if (op == CAIRO_OPERATOR_SATURATE || + op == CAIRO_OPERATOR_COLOR_DODGE || + op == CAIRO_OPERATOR_COLOR_BURN) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 + if (op <= CAIRO_OPERATOR_ADD) { + PrivateCGCompositeMode compmode; + + compmode = _cairo_quartz_cairo_operator_to_quartz_composite (op); + CGContextSetCompositeOperation (context, compmode); + return CAIRO_STATUS_SUCCESS; + } +#endif + + blendmode = _cairo_quartz_cairo_operator_to_quartz_blend (op); + CGContextSetBlendMode (context, blendmode); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_quartz_surface_set_cairo_operator (cairo_quartz_surface_t *surface, cairo_operator_t op) +{ + ND((stderr, "%p _cairo_quartz_surface_set_cairo_operator %d\n", surface, op)); + + /* When the destination has no color components, we can avoid some + * fallbacks, but we have to workaround operators which behave + * differently in Quartz. */ + if (surface->base.content == CAIRO_CONTENT_ALPHA) { + assert (op != CAIRO_OPERATOR_ATOP); /* filtered by surface layer */ + + if (op == CAIRO_OPERATOR_SOURCE || + op == CAIRO_OPERATOR_IN || + op == CAIRO_OPERATOR_OUT || + op == CAIRO_OPERATOR_DEST_IN || + op == CAIRO_OPERATOR_DEST_ATOP || + op == CAIRO_OPERATOR_XOR) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (op == CAIRO_OPERATOR_DEST_OVER) + op = CAIRO_OPERATOR_OVER; + else if (op == CAIRO_OPERATOR_SATURATE) + op = CAIRO_OPERATOR_ADD; + else if (op == CAIRO_OPERATOR_COLOR_DODGE) + op = CAIRO_OPERATOR_OVER; + else if (op == CAIRO_OPERATOR_COLOR_BURN) + op = CAIRO_OPERATOR_OVER; + } + + return _cairo_cgcontext_set_cairo_operator (surface->cgContext, op); +} + +static inline CGLineCap +_cairo_quartz_cairo_line_cap_to_quartz (cairo_line_cap_t ccap) +{ + switch (ccap) { + default: + ASSERT_NOT_REACHED; + + case CAIRO_LINE_CAP_BUTT: + return kCGLineCapButt; + + case CAIRO_LINE_CAP_ROUND: + return kCGLineCapRound; + + case CAIRO_LINE_CAP_SQUARE: + return kCGLineCapSquare; + } +} + +static inline CGLineJoin +_cairo_quartz_cairo_line_join_to_quartz (cairo_line_join_t cjoin) +{ + switch (cjoin) { + default: + ASSERT_NOT_REACHED; + + case CAIRO_LINE_JOIN_MITER: + return kCGLineJoinMiter; + + case CAIRO_LINE_JOIN_ROUND: + return kCGLineJoinRound; + + case CAIRO_LINE_JOIN_BEVEL: + return kCGLineJoinBevel; + } +} + +static inline CGInterpolationQuality +_cairo_quartz_filter_to_quartz (cairo_filter_t filter) +{ + switch (filter) { + case CAIRO_FILTER_NEAREST: + case CAIRO_FILTER_FAST: + return kCGInterpolationNone; + + case CAIRO_FILTER_BEST: + case CAIRO_FILTER_GOOD: + case CAIRO_FILTER_BILINEAR: + case CAIRO_FILTER_GAUSSIAN: + return kCGInterpolationDefault; + + default: + ASSERT_NOT_REACHED; + return kCGInterpolationDefault; + } +} + +static inline void +_cairo_quartz_cairo_matrix_to_quartz (const cairo_matrix_t *src, + CGAffineTransform *dst) +{ + dst->a = src->xx; + dst->b = src->yx; + dst->c = src->xy; + dst->d = src->yy; + dst->tx = src->x0; + dst->ty = src->y0; +} + + +/* + * Source -> Quartz setup and finish functions + */ + +static void +ComputeGradientValue (void *info, + const cairo_quartz_float_t *in, + cairo_quartz_float_t *out) +{ + double fdist = *in; + const cairo_gradient_pattern_t *grad = (cairo_gradient_pattern_t*) info; + unsigned int i; + + /* Put fdist back in the 0.0..1.0 range if we're doing + * REPEAT/REFLECT + */ + if (grad->base.extend == CAIRO_EXTEND_REPEAT) { + fdist = fdist - floor (fdist); + } else if (grad->base.extend == CAIRO_EXTEND_REFLECT) { + fdist = fmod (fabs (fdist), 2.0); + if (fdist > 1.0) + fdist = 2.0 - fdist; + } + + for (i = 0; i < grad->n_stops; i++) + if (grad->stops[i].offset > fdist) + break; + + if (i == 0 || i == grad->n_stops) { + if (i == grad->n_stops) + --i; + out[0] = grad->stops[i].color.red; + out[1] = grad->stops[i].color.green; + out[2] = grad->stops[i].color.blue; + out[3] = grad->stops[i].color.alpha; + } else { + cairo_quartz_float_t ax = grad->stops[i-1].offset; + cairo_quartz_float_t bx = grad->stops[i].offset - ax; + cairo_quartz_float_t bp = (fdist - ax)/bx; + cairo_quartz_float_t ap = 1.0 - bp; + + out[0] = + grad->stops[i-1].color.red * ap + + grad->stops[i].color.red * bp; + out[1] = + grad->stops[i-1].color.green * ap + + grad->stops[i].color.green * bp; + out[2] = + grad->stops[i-1].color.blue * ap + + grad->stops[i].color.blue * bp; + out[3] = + grad->stops[i-1].color.alpha * ap + + grad->stops[i].color.alpha * bp; + } +} + +static const cairo_quartz_float_t gradient_output_value_ranges[8] = { + 0.f, 1.f, 0.f, 1.f, 0.f, 1.f, 0.f, 1.f +}; +static const CGFunctionCallbacks gradient_callbacks = { + 0, ComputeGradientValue, (CGFunctionReleaseInfoCallback) cairo_pattern_destroy +}; + +/* Quartz computes a small number of samples of the gradient color + * function. On MacOS X 10.5 it apparently computes only 1024 + * samples. */ +#define MAX_GRADIENT_RANGE 1024 + +static CGFunctionRef +CairoQuartzCreateGradientFunction (const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents, + cairo_circle_double_t *start, + cairo_circle_double_t *end) +{ + cairo_pattern_t *pat; + cairo_quartz_float_t input_value_range[2]; + + if (gradient->base.extend != CAIRO_EXTEND_NONE) { + double bounds_x1, bounds_x2, bounds_y1, bounds_y2; + double t[2], tolerance; + + tolerance = fabs (_cairo_matrix_compute_determinant (&gradient->base.matrix)); + tolerance /= _cairo_matrix_transformed_circle_major_axis (&gradient->base.matrix, 1); + + bounds_x1 = extents->x; + bounds_y1 = extents->y; + bounds_x2 = extents->x + extents->width; + bounds_y2 = extents->y + extents->height; + _cairo_matrix_transform_bounding_box (&gradient->base.matrix, + &bounds_x1, &bounds_y1, + &bounds_x2, &bounds_y2, + NULL); + + _cairo_gradient_pattern_box_to_parameter (gradient, + bounds_x1, bounds_y1, + bounds_x2, bounds_y2, + tolerance, + t); + + if (gradient->base.extend == CAIRO_EXTEND_PAD) { + t[0] = MAX (t[0], -0.5); + t[1] = MIN (t[1], 1.5); + } else if (t[1] - t[0] > MAX_GRADIENT_RANGE) + return NULL; + + /* set the input range for the function -- the function knows how + to map values outside of 0.0 .. 1.0 to the correct color */ + input_value_range[0] = t[0]; + input_value_range[1] = t[1]; + } else { + input_value_range[0] = 0; + input_value_range[1] = 1; + } + + _cairo_gradient_pattern_interpolate (gradient, input_value_range[0], start); + _cairo_gradient_pattern_interpolate (gradient, input_value_range[1], end); + + if (_cairo_pattern_create_copy (&pat, &gradient->base)) + return NULL; + + return CGFunctionCreate (pat, + 1, + input_value_range, + 4, + gradient_output_value_ranges, + &gradient_callbacks); +} + +/* Obtain a CGImageRef from a #cairo_surface_t * */ + +typedef struct { + cairo_surface_t *surface; + cairo_image_surface_t *image_out; + void *image_extra; +} quartz_source_image_t; + +static void +DataProviderReleaseCallback (void *info, const void *data, size_t size) +{ + quartz_source_image_t *source_img = info; + _cairo_surface_release_source_image (source_img->surface, source_img->image_out, source_img->image_extra); + free (source_img); +} + +static cairo_status_t +_cairo_surface_to_cgimage (cairo_surface_t *source, + cairo_rectangle_int_t *extents, + cairo_format_t format, + cairo_matrix_t *matrix, + const cairo_clip_t *clip, + CGImageRef *image_out) +{ + cairo_status_t status; + quartz_source_image_t *source_img; + cairo_image_surface_t *image_surface; + + if (source->backend && source->backend->type == CAIRO_SURFACE_TYPE_QUARTZ_IMAGE) { + cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t *) source; + *image_out = CGImageRetain (surface->image); + return CAIRO_STATUS_SUCCESS; + } + + if (_cairo_surface_is_quartz (source)) { + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) source; + if (IS_EMPTY (surface)) { + *image_out = NULL; + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + if (_cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) { + *image_out = CGBitmapContextCreateImage (surface->cgContext); + if (*image_out) + return CAIRO_STATUS_SUCCESS; + } + } + + source_img = malloc (sizeof (quartz_source_image_t)); + if (unlikely (source_img == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + source_img->surface = source; + + if (source->type == CAIRO_SURFACE_TYPE_RECORDING) { + image_surface = (cairo_image_surface_t *) + cairo_image_surface_create (format, extents->width, extents->height); + if (unlikely (image_surface->base.status)) { + status = image_surface->base.status; + cairo_surface_destroy (&image_surface->base); + free (source_img); + return status; + } + + status = _cairo_recording_surface_replay_with_clip (source, + matrix, + &image_surface->base, + NULL); + if (unlikely (status)) { + cairo_surface_destroy (&image_surface->base); + free (source_img); + return status; + } + + source_img->image_out = image_surface; + source_img->image_extra = NULL; + + cairo_matrix_init_identity (matrix); + } + else { + status = _cairo_surface_acquire_source_image (source_img->surface, + &source_img->image_out, + &source_img->image_extra); + if (unlikely (status)) { + free (source_img); + return status; + } + } + + if (source_img->image_out->width == 0 || source_img->image_out->height == 0) { + *image_out = NULL; + DataProviderReleaseCallback (source_img, + source_img->image_out->data, + source_img->image_out->height * source_img->image_out->stride); + } else { + *image_out = CairoQuartzCreateCGImage (source_img->image_out->format, + source_img->image_out->width, + source_img->image_out->height, + source_img->image_out->stride, + source_img->image_out->data, + TRUE, + NULL, + DataProviderReleaseCallback, + source_img); + + /* TODO: differentiate memory error and unsupported surface type */ + if (unlikely (*image_out == NULL)) + status = CAIRO_INT_STATUS_UNSUPPORTED; + } + + return status; +} + +/* Generic #cairo_pattern_t -> CGPattern function */ + +typedef struct { + CGImageRef image; + CGRect imageBounds; + cairo_bool_t do_reflect; +} SurfacePatternDrawInfo; + +static void +SurfacePatternDrawFunc (void *ainfo, CGContextRef context) +{ + SurfacePatternDrawInfo *info = (SurfacePatternDrawInfo*) ainfo; + + CGContextTranslateCTM (context, 0, info->imageBounds.size.height); + CGContextScaleCTM (context, 1, -1); + + CGContextDrawImage (context, info->imageBounds, info->image); + if (info->do_reflect) { + /* draw 3 more copies of the image, flipped. + * DrawImage draws the image according to the current Y-direction into the rectangle given + * (imageBounds); at the time of the first DrawImage above, the origin is at the bottom left + * of the base image position, and the Y axis is extending upwards. + */ + + /* Make the y axis extend downwards, and draw a flipped image below */ + CGContextScaleCTM (context, 1, -1); + CGContextDrawImage (context, info->imageBounds, info->image); + + /* Shift over to the right, and flip vertically (translation is 2x, + * since we'll be flipping and thus rendering the rectangle "backwards" + */ + CGContextTranslateCTM (context, 2 * info->imageBounds.size.width, 0); + CGContextScaleCTM (context, -1, 1); + CGContextDrawImage (context, info->imageBounds, info->image); + + /* Then unflip the Y-axis again, and draw the image above the point. */ + CGContextScaleCTM (context, 1, -1); + CGContextDrawImage (context, info->imageBounds, info->image); + } +} + +static void +SurfacePatternReleaseInfoFunc (void *ainfo) +{ + SurfacePatternDrawInfo *info = (SurfacePatternDrawInfo*) ainfo; + + CGImageRelease (info->image); + free (info); +} + +static cairo_int_status_t +_cairo_quartz_cairo_repeating_surface_pattern_to_quartz (cairo_quartz_surface_t *dest, + const cairo_pattern_t *apattern, + const cairo_clip_t *clip, + CGPatternRef *cgpat) +{ + cairo_surface_pattern_t *spattern; + cairo_surface_t *pat_surf; + cairo_rectangle_int_t extents; + cairo_format_t format = _cairo_format_from_content (dest->base.content); + + CGImageRef image; + CGRect pbounds; + CGAffineTransform ptransform, stransform; + CGPatternCallbacks cb = { 0, + SurfacePatternDrawFunc, + SurfacePatternReleaseInfoFunc }; + SurfacePatternDrawInfo *info; + cairo_quartz_float_t rw, rh; + cairo_status_t status; + cairo_bool_t is_bounded; + + cairo_matrix_t m; + + /* SURFACE is the only type we'll handle here */ + assert (apattern->type == CAIRO_PATTERN_TYPE_SURFACE); + + spattern = (cairo_surface_pattern_t *) apattern; + pat_surf = spattern->surface; + + if (pat_surf->type != CAIRO_SURFACE_TYPE_RECORDING) { + is_bounded = _cairo_surface_get_extents (pat_surf, &extents); + assert (is_bounded); + } + else + _cairo_surface_get_extents (&dest->base, &extents); + + m = spattern->base.matrix; + status = _cairo_surface_to_cgimage (pat_surf, &extents, format, + &m, clip, &image); + if (unlikely (status)) + return status; + + info = malloc (sizeof (SurfacePatternDrawInfo)); + if (unlikely (!info)) + return CAIRO_STATUS_NO_MEMORY; + + /* XXX -- if we're printing, we may need to call CGImageCreateCopy to make sure + * that the data will stick around for this image when the printer gets to it. + * Otherwise, the underlying data store may disappear from under us! + * + * _cairo_surface_to_cgimage will copy when it converts non-Quartz surfaces, + * since the Quartz surfaces have a higher chance of sticking around. If the + * source is a quartz image surface, then it's set up to retain a ref to the + * image surface that it's backed by. + */ + info->image = image; + info->imageBounds = CGRectMake (0, 0, extents.width, extents.height); + info->do_reflect = FALSE; + + pbounds.origin.x = 0; + pbounds.origin.y = 0; + + if (spattern->base.extend == CAIRO_EXTEND_REFLECT) { + pbounds.size.width = 2.0 * extents.width; + pbounds.size.height = 2.0 * extents.height; + info->do_reflect = TRUE; + } else { + pbounds.size.width = extents.width; + pbounds.size.height = extents.height; + } + rw = pbounds.size.width; + rh = pbounds.size.height; + + cairo_matrix_invert (&m); + _cairo_quartz_cairo_matrix_to_quartz (&m, &stransform); + + /* The pattern matrix is relative to the bottom left, again; the + * incoming cairo pattern matrix is relative to the upper left. + * So we take the pattern matrix and the original context matrix, + * which gives us the correct base translation/y flip. + */ + ptransform = CGAffineTransformConcat (stransform, dest->cgContextBaseCTM); + +#ifdef QUARTZ_DEBUG + ND ((stderr, " pbounds: %f %f %f %f\n", pbounds.origin.x, pbounds.origin.y, pbounds.size.width, pbounds.size.height)); + ND ((stderr, " pattern xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", ptransform.tx, ptransform.ty, ptransform.a, ptransform.b, ptransform.c, ptransform.d)); + CGAffineTransform xform = CGContextGetCTM (dest->cgContext); + ND ((stderr, " context xform: t: %f %f xx: %f xy: %f yx: %f yy: %f\n", xform.tx, xform.ty, xform.a, xform.b, xform.c, xform.d)); +#endif + + *cgpat = CGPatternCreate (info, + pbounds, + ptransform, + rw, rh, + kCGPatternTilingConstantSpacing, /* kCGPatternTilingNoDistortion, */ + TRUE, + &cb); + + return CAIRO_STATUS_SUCCESS; +} + +/* State used during a drawing operation. */ +typedef struct { + /* The destination of the mask */ + CGContextRef cgMaskContext; + + /* The destination of the drawing of the source */ + CGContextRef cgDrawContext; + + /* The filter to be used when drawing the source */ + CGInterpolationQuality filter; + + /* Action type */ + cairo_quartz_action_t action; + + /* Destination rect */ + CGRect rect; + + /* Used with DO_SHADING, DO_IMAGE and DO_TILED_IMAGE */ + CGAffineTransform transform; + + /* Used with DO_IMAGE and DO_TILED_IMAGE */ + CGImageRef image; + + /* Used with DO_SHADING */ + CGShadingRef shading; + + /* Temporary destination for unbounded operations */ + CGLayerRef layer; + CGRect clipRect; +} cairo_quartz_drawing_state_t; + +/* +Quartz does not support repeating radients. We handle repeating gradients +by manually extending the gradient and repeating color stops. We need to +minimize the number of repetitions since Quartz seems to sample our color +function across the entire range, even if part of that range is not needed +for the visible area of the gradient, and it samples with some fixed resolution, +so if the gradient range is too large it samples with very low resolution and +the gradient is very coarse. _cairo_quartz_create_gradient_function computes +the number of repetitions needed based on the extents. +*/ +static cairo_int_status_t +_cairo_quartz_setup_gradient_source (cairo_quartz_drawing_state_t *state, + const cairo_gradient_pattern_t *gradient, + const cairo_rectangle_int_t *extents) +{ + cairo_matrix_t mat; + cairo_circle_double_t start, end; + CGFunctionRef gradFunc; + CGColorSpaceRef rgb; + bool extend = gradient->base.extend != CAIRO_EXTEND_NONE; + + assert (gradient->n_stops > 0); + + mat = gradient->base.matrix; + cairo_matrix_invert (&mat); + _cairo_quartz_cairo_matrix_to_quartz (&mat, &state->transform); + + gradFunc = CairoQuartzCreateGradientFunction (gradient, extents, + &start, &end); + + if (unlikely (gradFunc == NULL)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + rgb = CGColorSpaceCreateDeviceRGB (); + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + state->shading = CGShadingCreateAxial (rgb, + CGPointMake (start.center.x, + start.center.y), + CGPointMake (end.center.x, + end.center.y), + gradFunc, + extend, extend); + } else { + state->shading = CGShadingCreateRadial (rgb, + CGPointMake (start.center.x, + start.center.y), + MAX (start.radius, 0), + CGPointMake (end.center.x, + end.center.y), + MAX (end.radius, 0), + gradFunc, + extend, extend); + } + + CGColorSpaceRelease (rgb); + CGFunctionRelease (gradFunc); + + state->action = DO_SHADING; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_quartz_setup_state (cairo_quartz_drawing_state_t *state, + cairo_composite_rectangles_t *composite) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) composite->surface; + cairo_operator_t op = composite->op; + const cairo_pattern_t *source = &composite->source_pattern.base; + const cairo_clip_t *clip = composite->clip; + cairo_bool_t needs_temp; + cairo_status_t status; + cairo_format_t format = _cairo_format_from_content (composite->surface->content); + + state->layer = NULL; + state->image = NULL; + state->shading = NULL; + state->cgDrawContext = NULL; + state->cgMaskContext = NULL; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + status = _cairo_quartz_surface_set_cairo_operator (surface, op); + if (unlikely (status)) + return status; + + /* Save before we change the pattern, colorspace, etc. so that + * we can restore and make sure that quartz releases our + * pattern (which may be stack allocated) + */ + + CGContextSaveGState (surface->cgContext); + state->clipRect = CGContextGetClipBoundingBox (surface->cgContext); + state->clipRect = CGRectIntegral (state->clipRect); + state->rect = state->clipRect; + + state->cgMaskContext = surface->cgContext; + state->cgDrawContext = state->cgMaskContext; + + state->filter = _cairo_quartz_filter_to_quartz (source->filter); + + if (op == CAIRO_OPERATOR_CLEAR) { + CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 1); + + state->action = DO_DIRECT; + return CAIRO_STATUS_SUCCESS; + } + + /* + * To implement mask unbounded operations Quartz needs a temporary + * surface which will be composited entirely (ignoring the mask). + * To implement source unbounded operations Quartz needs a + * temporary surface which allows extending the source to a size + * covering the whole mask, but there are some optimization + * opportunities: + * + * - CLEAR completely ignores the source, thus we can just use a + * solid color fill. + * + * - SOURCE can be implemented by drawing the source and clearing + * outside of the source as long as the two regions have no + * intersection. This happens when the source is a pixel-aligned + * rectangle. If the source is at least as big as the + * intersection between the clip rectangle and the mask + * rectangle, no clear operation is needed. + */ + needs_temp = ! _cairo_operator_bounded_by_mask (op); + + if (needs_temp) { + state->layer = CGLayerCreateWithContext (surface->cgContext, + state->clipRect.size, + NULL); + state->cgDrawContext = CGLayerGetContext (state->layer); + state->cgMaskContext = state->cgDrawContext; + CGContextTranslateCTM (state->cgDrawContext, + -state->clipRect.origin.x, + -state->clipRect.origin.y); + } + + if (source->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) source; + + CGContextSetRGBStrokeColor (state->cgDrawContext, + solid->color.red, + solid->color.green, + solid->color.blue, + solid->color.alpha); + CGContextSetRGBFillColor (state->cgDrawContext, + solid->color.red, + solid->color.green, + solid->color.blue, + solid->color.alpha); + + state->action = DO_DIRECT; + return CAIRO_STATUS_SUCCESS; + } + + if (source->type == CAIRO_PATTERN_TYPE_LINEAR || + source->type == CAIRO_PATTERN_TYPE_RADIAL) + { + const cairo_gradient_pattern_t *gpat = (const cairo_gradient_pattern_t *)source; + cairo_rectangle_int_t extents; + + extents = surface->virtual_extents; + extents.x -= surface->base.device_transform.x0; + extents.y -= surface->base.device_transform.y0; + _cairo_rectangle_union (&extents, &surface->extents); + + return _cairo_quartz_setup_gradient_source (state, gpat, &extents); + } + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE && + (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT))) + { + const cairo_surface_pattern_t *spat = (const cairo_surface_pattern_t *) source; + cairo_surface_t *pat_surf = spat->surface; + CGImageRef img; + cairo_matrix_t m = spat->base.matrix; + cairo_rectangle_int_t extents; + CGAffineTransform xform; + CGRect srcRect; + cairo_fixed_t fw, fh; + cairo_bool_t is_bounded; + + _cairo_surface_get_extents (composite->surface, &extents); + status = _cairo_surface_to_cgimage (pat_surf, &extents, format, + &m, clip, &img); + if (unlikely (status)) + return status; + + state->image = img; + + if (state->filter == kCGInterpolationNone && _cairo_matrix_is_translation (&m)) { + m.x0 = -ceil (m.x0 - 0.5); + m.y0 = -ceil (m.y0 - 0.5); + } else { + cairo_matrix_invert (&m); + } + + _cairo_quartz_cairo_matrix_to_quartz (&m, &state->transform); + + if (pat_surf->type != CAIRO_SURFACE_TYPE_RECORDING) { + is_bounded = _cairo_surface_get_extents (pat_surf, &extents); + assert (is_bounded); + } + + srcRect = CGRectMake (0, 0, extents.width, extents.height); + + if (source->extend == CAIRO_EXTEND_NONE) { + int x, y; + if (op == CAIRO_OPERATOR_SOURCE && + (pat_surf->content == CAIRO_CONTENT_ALPHA || + ! _cairo_matrix_is_integer_translation (&m, &x, &y))) + { + state->layer = CGLayerCreateWithContext (surface->cgContext, + state->clipRect.size, + NULL); + state->cgDrawContext = CGLayerGetContext (state->layer); + CGContextTranslateCTM (state->cgDrawContext, + -state->clipRect.origin.x, + -state->clipRect.origin.y); + } + + CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 1); + + state->rect = srcRect; + state->action = DO_IMAGE; + return CAIRO_STATUS_SUCCESS; + } + + CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 1); + + /* Quartz seems to tile images at pixel-aligned regions only -- this + * leads to seams if the image doesn't end up scaling to fill the + * space exactly. The CGPattern tiling approach doesn't have this + * problem. Check if we're going to fill up the space (within some + * epsilon), and if not, fall back to the CGPattern type. + */ + + xform = CGAffineTransformConcat (CGContextGetCTM (state->cgDrawContext), + state->transform); + + srcRect = CGRectApplyAffineTransform (srcRect, xform); + + fw = _cairo_fixed_from_double (srcRect.size.width); + fh = _cairo_fixed_from_double (srcRect.size.height); + + if ((fw & CAIRO_FIXED_FRAC_MASK) <= CAIRO_FIXED_EPSILON && + (fh & CAIRO_FIXED_FRAC_MASK) <= CAIRO_FIXED_EPSILON) + { + /* We're good to use DrawTiledImage, but ensure that + * the math works out */ + + srcRect.size.width = round (srcRect.size.width); + srcRect.size.height = round (srcRect.size.height); + + xform = CGAffineTransformInvert (xform); + + srcRect = CGRectApplyAffineTransform (srcRect, xform); + + state->rect = srcRect; + state->action = DO_TILED_IMAGE; + return CAIRO_STATUS_SUCCESS; + } + + /* Fall through to generic SURFACE case */ + } + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_quartz_float_t patternAlpha = 1.0f; + CGColorSpaceRef patternSpace; + CGPatternRef pattern = NULL; + cairo_int_status_t status; + + status = _cairo_quartz_cairo_repeating_surface_pattern_to_quartz (surface, source, clip, &pattern); + if (unlikely (status)) + return status; + + patternSpace = CGColorSpaceCreatePattern (NULL); + CGContextSetFillColorSpace (state->cgDrawContext, patternSpace); + CGContextSetFillPattern (state->cgDrawContext, pattern, &patternAlpha); + CGContextSetStrokeColorSpace (state->cgDrawContext, patternSpace); + CGContextSetStrokePattern (state->cgDrawContext, pattern, &patternAlpha); + CGColorSpaceRelease (patternSpace); + + /* Quartz likes to munge the pattern phase (as yet unexplained + * why); force it to 0,0 as we've already baked in the correct + * pattern translation into the pattern matrix + */ + CGContextSetPatternPhase (state->cgDrawContext, CGSizeMake (0, 0)); + + CGPatternRelease (pattern); + + state->action = DO_DIRECT; + return CAIRO_STATUS_SUCCESS; + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static void +_cairo_quartz_teardown_state (cairo_quartz_drawing_state_t *state, + cairo_composite_rectangles_t *extents) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) extents->surface; + + if (state->layer) { + CGContextDrawLayerInRect (surface->cgContext, + state->clipRect, + state->layer); + CGLayerRelease (state->layer); + } + + if (state->cgMaskContext) + CGContextRestoreGState (surface->cgContext); + + if (state->image) + CGImageRelease (state->image); + + if (state->shading) + CGShadingRelease (state->shading); +} + +static void +_cairo_quartz_draw_source (cairo_quartz_drawing_state_t *state, + cairo_operator_t op) +{ + CGContextSetShouldAntialias (state->cgDrawContext, state->filter != kCGInterpolationNone); + CGContextSetInterpolationQuality(state->cgDrawContext, state->filter); + + if (state->action == DO_DIRECT) { + CGContextFillRect (state->cgDrawContext, state->rect); + return; + } + + CGContextConcatCTM (state->cgDrawContext, state->transform); + + if (state->action == DO_SHADING) { + CGContextDrawShading (state->cgDrawContext, state->shading); + return; + } + + CGContextTranslateCTM (state->cgDrawContext, 0, state->rect.size.height); + CGContextScaleCTM (state->cgDrawContext, 1, -1); + + if (state->action == DO_IMAGE) { + CGContextDrawImage (state->cgDrawContext, state->rect, state->image); + if (op == CAIRO_OPERATOR_SOURCE && + state->cgDrawContext == state->cgMaskContext) + { + CGContextBeginPath (state->cgDrawContext); + CGContextAddRect (state->cgDrawContext, state->rect); + + CGContextTranslateCTM (state->cgDrawContext, 0, state->rect.size.height); + CGContextScaleCTM (state->cgDrawContext, 1, -1); + CGContextConcatCTM (state->cgDrawContext, + CGAffineTransformInvert (state->transform)); + + CGContextAddRect (state->cgDrawContext, state->clipRect); + + CGContextSetRGBFillColor (state->cgDrawContext, 0, 0, 0, 0); + CGContextEOFillPath (state->cgDrawContext); + } + } else { + CGContextDrawTiledImagePtr (state->cgDrawContext, state->rect, state->image); + } +} + +static cairo_image_surface_t * +_cairo_quartz_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; + unsigned int stride, bitinfo, bpp, color_comps; + CGColorSpaceRef colorspace; + void *imageData; + cairo_format_t format; + + if (surface->imageSurfaceEquiv) + return _cairo_surface_map_to_image (surface->imageSurfaceEquiv, extents); + + if (IS_EMPTY (surface)) + return (cairo_image_surface_t *) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); + + if (! _cairo_quartz_is_cgcontext_bitmap_context (surface->cgContext)) + return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + bitinfo = CGBitmapContextGetBitmapInfo (surface->cgContext); + bpp = CGBitmapContextGetBitsPerPixel (surface->cgContext); + + // let's hope they don't add YUV under us + colorspace = CGBitmapContextGetColorSpace (surface->cgContext); + color_comps = CGColorSpaceGetNumberOfComponents (colorspace); + + /* XXX TODO: We can handle many more data formats by + * converting to pixman_format_t */ + + if (bpp == 32 && color_comps == 3 && + (bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst && + (bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host) + { + format = CAIRO_FORMAT_ARGB32; + } + else if (bpp == 32 && color_comps == 3 && + (bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst && + (bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host) + { + format = CAIRO_FORMAT_RGB24; + } + else if (bpp == 8 && color_comps == 1) + { + format = CAIRO_FORMAT_A1; + } + else + { + return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + imageData = CGBitmapContextGetData (surface->cgContext); + stride = CGBitmapContextGetBytesPerRow (surface->cgContext); + + return (cairo_image_surface_t *) cairo_image_surface_create_for_data (imageData, + format, + extents->width, + extents->height, + stride); +} + +static cairo_int_status_t +_cairo_quartz_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; + + if (surface->imageSurfaceEquiv) + return _cairo_surface_unmap_image (surface->imageSurfaceEquiv, image); + + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return CAIRO_STATUS_SUCCESS; +} + + +/* + * Cairo surface backend implementations + */ + +static cairo_status_t +_cairo_quartz_surface_finish (void *abstract_surface) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; + + ND ((stderr, "_cairo_quartz_surface_finish[%p] cgc: %p\n", surface, surface->cgContext)); + + if (IS_EMPTY (surface)) + return CAIRO_STATUS_SUCCESS; + + /* Restore our saved gstate that we use to reset clipping */ + CGContextRestoreGState (surface->cgContext); + _cairo_surface_clipper_reset (&surface->clipper); + + CGContextRelease (surface->cgContext); + + surface->cgContext = NULL; + + if (surface->imageSurfaceEquiv) { + cairo_surface_destroy (surface->imageSurfaceEquiv); + surface->imageSurfaceEquiv = NULL; + } + + free (surface->imageData); + surface->imageData = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_quartz_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; + + //ND ((stderr, "%p _cairo_quartz_surface_acquire_source_image\n", surface)); + + *image_extra = NULL; + + *image_out = _cairo_quartz_surface_map_to_image (surface, &surface->extents); + if (unlikely (cairo_surface_status(&(*image_out)->base))) { + cairo_surface_destroy (&(*image_out)->base); + *image_out = NULL; + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_quartz_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + _cairo_quartz_surface_unmap_image (abstract_surface, image); +} + +static cairo_surface_t * +_cairo_quartz_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_quartz_surface_t *surface, *similar_quartz; + cairo_surface_t *similar; + cairo_format_t format; + + if (content == CAIRO_CONTENT_COLOR_ALPHA) + format = CAIRO_FORMAT_ARGB32; + else if (content == CAIRO_CONTENT_COLOR) + format = CAIRO_FORMAT_RGB24; + else if (content == CAIRO_CONTENT_ALPHA) + format = CAIRO_FORMAT_A8; + else + return NULL; + + // verify width and height of surface + if (!_cairo_quartz_verify_surface_size (width, height)) { + return _cairo_surface_create_in_error (_cairo_error + (CAIRO_STATUS_INVALID_SIZE)); + } + + similar = cairo_quartz_surface_create (format, width, height); + if (unlikely (similar->status)) + return similar; + + surface = (cairo_quartz_surface_t *) abstract_surface; + similar_quartz = (cairo_quartz_surface_t *) similar; + similar_quartz->virtual_extents = surface->virtual_extents; + + return similar; +} + +static cairo_bool_t +_cairo_quartz_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface; + + *extents = surface->extents; + return TRUE; +} + +static cairo_int_status_t +_cairo_quartz_cg_paint (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_quartz_drawing_state_t state; + cairo_int_status_t rv; + + ND ((stderr, "%p _cairo_quartz_surface_paint op %d source->type %d\n", + extents->surface, extents->op, extents->source_pattern.base.type)); + + rv = _cairo_quartz_setup_state (&state, extents); + if (unlikely (rv)) + goto BAIL; + + _cairo_quartz_draw_source (&state, extents->op); + +BAIL: + _cairo_quartz_teardown_state (&state, extents); + + ND ((stderr, "-- paint\n")); + return rv; +} + +static cairo_int_status_t +_cairo_quartz_cg_mask_with_surface (cairo_composite_rectangles_t *extents, + cairo_surface_t *mask_surf, + const cairo_matrix_t *mask_mat, + CGInterpolationQuality filter) +{ + CGRect rect; + CGImageRef img; + cairo_status_t status; + CGAffineTransform mask_matrix; + cairo_quartz_drawing_state_t state; + cairo_format_t format = _cairo_format_from_content (extents->surface->content); + cairo_rectangle_int_t dest_extents; + cairo_matrix_t m = *mask_mat; + + _cairo_surface_get_extents (extents->surface, &dest_extents); + status = _cairo_surface_to_cgimage (mask_surf, &dest_extents, format, + &m, extents->clip, &img); + if (unlikely (status)) + return status; + + status = _cairo_quartz_setup_state (&state, extents); + if (unlikely (status)) + goto BAIL; + + rect = CGRectMake (0.0, 0.0, CGImageGetWidth (img), CGImageGetHeight (img)); + _cairo_quartz_cairo_matrix_to_quartz (&m, &mask_matrix); + + /* ClipToMask is essentially drawing an image, so we need to flip the CTM + * to get the image to appear oriented the right way */ + CGContextConcatCTM (state.cgMaskContext, CGAffineTransformInvert (mask_matrix)); + CGContextTranslateCTM (state.cgMaskContext, 0.0, rect.size.height); + CGContextScaleCTM (state.cgMaskContext, 1.0, -1.0); + + state.filter = filter; + + CGContextSetInterpolationQuality (state.cgMaskContext, filter); + CGContextSetShouldAntialias (state.cgMaskContext, filter != kCGInterpolationNone); + + CGContextClipToMask (state.cgMaskContext, rect, img); + + CGContextScaleCTM (state.cgMaskContext, 1.0, -1.0); + CGContextTranslateCTM (state.cgMaskContext, 0.0, -rect.size.height); + CGContextConcatCTM (state.cgMaskContext, mask_matrix); + + _cairo_quartz_draw_source (&state, extents->op); + +BAIL: + _cairo_quartz_teardown_state (&state, extents); + + CGImageRelease (img); + + return status; +} + +static cairo_int_status_t +_cairo_quartz_cg_mask_with_solid (cairo_quartz_surface_t *surface, + cairo_composite_rectangles_t *extents) +{ + cairo_quartz_drawing_state_t state; + double alpha = extents->mask_pattern.solid.color.alpha; + cairo_status_t status; + + status = _cairo_quartz_setup_state (&state, extents); + if (unlikely (status)) + return status; + + CGContextSetAlpha (surface->cgContext, alpha); + _cairo_quartz_draw_source (&state, extents->op); + + _cairo_quartz_teardown_state (&state, extents); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_quartz_cg_mask (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *)extents->surface; + const cairo_pattern_t *source = &extents->source_pattern.base; + const cairo_pattern_t *mask = &extents->mask_pattern.base; + cairo_surface_t *mask_surf; + cairo_matrix_t matrix; + cairo_status_t status; + cairo_bool_t need_temp; + CGInterpolationQuality filter; + + ND ((stderr, "%p _cairo_quartz_surface_mask op %d source->type %d mask->type %d\n", + extents->surface, extents->op, extents->source_pattern.base.type, + extents->mask_pattern.base.type)); + + if (mask->type == CAIRO_PATTERN_TYPE_SOLID) + return _cairo_quartz_cg_mask_with_solid (surface, extents); + + need_temp = (mask->type != CAIRO_PATTERN_TYPE_SURFACE || + mask->extend != CAIRO_EXTEND_NONE); + + filter = _cairo_quartz_filter_to_quartz (source->filter); + + if (! need_temp) { + mask_surf = extents->mask_pattern.surface.surface; + + /* When an opaque surface used as a mask in Quartz, its + * luminosity is used as the alpha value, so we con only use + * surfaces with alpha without creating a temporary mask. */ + need_temp = ! (mask_surf->content & CAIRO_CONTENT_ALPHA); + } + + if (! need_temp) { + CGInterpolationQuality mask_filter; + cairo_bool_t simple_transform; + + matrix = mask->matrix; + + mask_filter = _cairo_quartz_filter_to_quartz (mask->filter); + if (mask_filter == kCGInterpolationNone) { + simple_transform = _cairo_matrix_is_translation (&matrix); + if (simple_transform) { + matrix.x0 = ceil (matrix.x0 - 0.5); + matrix.y0 = ceil (matrix.y0 - 0.5); + } + } else { + simple_transform = _cairo_matrix_is_integer_translation (&matrix, + NULL, + NULL); + } + + /* Quartz only allows one interpolation to be set for mask and + * source, so we can skip the temp surface only if the source + * filtering makes the mask look correct. */ + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) + need_temp = ! (simple_transform || filter == mask_filter); + else + filter = mask_filter; + } + + if (need_temp) { + /* Render the mask to a surface */ + mask_surf = _cairo_quartz_surface_create_similar (surface, + CAIRO_CONTENT_ALPHA, + surface->extents.width, + surface->extents.height); + status = mask_surf->status; + if (unlikely (status)) + goto BAIL; + + /* mask_surf is clear, so use OVER instead of SOURCE to avoid a + * temporary layer or fallback to cairo-image. */ + status = _cairo_surface_paint (mask_surf, CAIRO_OPERATOR_OVER, mask, NULL); + if (unlikely (status)) + goto BAIL; + + cairo_matrix_init_identity (&matrix); + } + + status = _cairo_quartz_cg_mask_with_surface (extents, + mask_surf, &matrix, filter); + +BAIL: + + if (need_temp) + cairo_surface_destroy (mask_surf); + + return status; +} + +static cairo_int_status_t +_cairo_quartz_cg_fill (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_quartz_drawing_state_t state; + cairo_int_status_t rv = CAIRO_STATUS_SUCCESS; + + ND ((stderr, "%p _cairo_quartz_surface_fill op %d source->type %d\n", + extents->surface, extents->op, extents->source_pattern.base.type)); + + rv = _cairo_quartz_setup_state (&state, extents); + if (unlikely (rv)) + goto BAIL; + + CGContextSetShouldAntialias (state.cgMaskContext, (antialias != CAIRO_ANTIALIAS_NONE)); + + _cairo_quartz_cairo_path_to_quartz_context (path, state.cgMaskContext); + + if (state.action == DO_DIRECT) { + assert (state.cgDrawContext == state.cgMaskContext); + if (fill_rule == CAIRO_FILL_RULE_WINDING) + CGContextFillPath (state.cgMaskContext); + else + CGContextEOFillPath (state.cgMaskContext); + } else { + if (fill_rule == CAIRO_FILL_RULE_WINDING) + CGContextClip (state.cgMaskContext); + else + CGContextEOClip (state.cgMaskContext); + + _cairo_quartz_draw_source (&state, extents->op); + } + +BAIL: + _cairo_quartz_teardown_state (&state, extents); + + ND ((stderr, "-- fill\n")); + return rv; +} + +static cairo_int_status_t +_cairo_quartz_cg_stroke (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_quartz_drawing_state_t state; + cairo_int_status_t rv = CAIRO_STATUS_SUCCESS; + CGAffineTransform strokeTransform, invStrokeTransform; + + ND ((stderr, "%p _cairo_quartz_surface_stroke op %d source->type %d\n", + extents->surface, extents->op, extents->source_pattern.base.type)); + + rv = _cairo_quartz_setup_state (&state, extents); + if (unlikely (rv)) + goto BAIL; + + // Turning antialiasing off used to cause misrendering with + // single-pixel lines (e.g. 20,10.5 -> 21,10.5 end up being rendered as 2 pixels). + // That's been since fixed in at least 10.5, and in the latest 10.4 dot releases. + CGContextSetShouldAntialias (state.cgMaskContext, (antialias != CAIRO_ANTIALIAS_NONE)); + CGContextSetLineWidth (state.cgMaskContext, style->line_width); + CGContextSetLineCap (state.cgMaskContext, _cairo_quartz_cairo_line_cap_to_quartz (style->line_cap)); + CGContextSetLineJoin (state.cgMaskContext, _cairo_quartz_cairo_line_join_to_quartz (style->line_join)); + CGContextSetMiterLimit (state.cgMaskContext, style->miter_limit); + + if (style->dash && style->num_dashes) { + cairo_quartz_float_t sdash[CAIRO_STACK_ARRAY_LENGTH (cairo_quartz_float_t)]; + cairo_quartz_float_t *fdash = sdash; + unsigned int max_dashes = style->num_dashes; + unsigned int k; + + if (style->num_dashes%2) + max_dashes *= 2; + if (max_dashes > ARRAY_LENGTH (sdash)) + fdash = _cairo_malloc_ab (max_dashes, sizeof (cairo_quartz_float_t)); + if (unlikely (fdash == NULL)) { + rv = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + + for (k = 0; k < max_dashes; k++) + fdash[k] = (cairo_quartz_float_t) style->dash[k % style->num_dashes]; + + CGContextSetLineDash (state.cgMaskContext, style->dash_offset, fdash, max_dashes); + if (fdash != sdash) + free (fdash); + } else + CGContextSetLineDash (state.cgMaskContext, 0, NULL, 0); + + _cairo_quartz_cairo_path_to_quartz_context (path, state.cgMaskContext); + + _cairo_quartz_cairo_matrix_to_quartz (ctm, &strokeTransform); + CGContextConcatCTM (state.cgMaskContext, strokeTransform); + + if (state.action == DO_DIRECT) { + assert (state.cgDrawContext == state.cgMaskContext); + CGContextStrokePath (state.cgMaskContext); + } else { + CGContextReplacePathWithStrokedPath (state.cgMaskContext); + CGContextClip (state.cgMaskContext); + + _cairo_quartz_cairo_matrix_to_quartz (ctm_inverse, &invStrokeTransform); + CGContextConcatCTM (state.cgMaskContext, invStrokeTransform); + + _cairo_quartz_draw_source (&state, extents->op); + } + +BAIL: + _cairo_quartz_teardown_state (&state, extents); + + ND ((stderr, "-- stroke\n")); + return rv; +} + +#if CAIRO_HAS_QUARTZ_FONT +static cairo_int_status_t +_cairo_quartz_cg_glyphs (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + CGAffineTransform textTransform, invTextTransform; + CGGlyph glyphs_static[CAIRO_STACK_ARRAY_LENGTH (CGSize)]; + CGSize cg_advances_static[CAIRO_STACK_ARRAY_LENGTH (CGSize)]; + CGGlyph *cg_glyphs = &glyphs_static[0]; + CGSize *cg_advances = &cg_advances_static[0]; + COMPILE_TIME_ASSERT (sizeof (CGGlyph) <= sizeof (CGSize)); + + cairo_quartz_drawing_state_t state; + cairo_int_status_t rv = CAIRO_INT_STATUS_UNSUPPORTED; + cairo_quartz_float_t xprev, yprev; + int i; + CGFontRef cgfref = NULL; + + cairo_bool_t didForceFontSmoothing = FALSE; + + if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ) + return CAIRO_INT_STATUS_UNSUPPORTED; + + rv = _cairo_quartz_setup_state (&state, extents); + if (unlikely (rv)) + goto BAIL; + + if (state.action == DO_DIRECT) { + assert (state.cgDrawContext == state.cgMaskContext); + CGContextSetTextDrawingMode (state.cgMaskContext, kCGTextFill); + } else { + CGContextSetTextDrawingMode (state.cgMaskContext, kCGTextClip); + } + + /* this doesn't addref */ + cgfref = _cairo_quartz_scaled_font_get_cg_font_ref (scaled_font); + CGContextSetFont (state.cgMaskContext, cgfref); + CGContextSetFontSize (state.cgMaskContext, 1.0); + + switch (scaled_font->options.antialias) { + case CAIRO_ANTIALIAS_SUBPIXEL: + case CAIRO_ANTIALIAS_BEST: + CGContextSetShouldAntialias (state.cgMaskContext, TRUE); + CGContextSetShouldSmoothFonts (state.cgMaskContext, TRUE); + if (CGContextSetAllowsFontSmoothingPtr && + !CGContextGetAllowsFontSmoothingPtr (state.cgMaskContext)) + { + didForceFontSmoothing = TRUE; + CGContextSetAllowsFontSmoothingPtr (state.cgMaskContext, TRUE); + } + break; + case CAIRO_ANTIALIAS_NONE: + CGContextSetShouldAntialias (state.cgMaskContext, FALSE); + break; + case CAIRO_ANTIALIAS_GRAY: + case CAIRO_ANTIALIAS_GOOD: + case CAIRO_ANTIALIAS_FAST: + CGContextSetShouldAntialias (state.cgMaskContext, TRUE); + CGContextSetShouldSmoothFonts (state.cgMaskContext, FALSE); + break; + case CAIRO_ANTIALIAS_DEFAULT: + /* Don't do anything */ + break; + } + + if (num_glyphs > ARRAY_LENGTH (glyphs_static)) { + cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof (CGGlyph) + sizeof (CGSize)); + if (unlikely (cg_glyphs == NULL)) { + rv = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + + cg_advances = (CGSize*) (cg_glyphs + num_glyphs); + } + + /* scale(1,-1) * scaled_font->scale */ + textTransform = CGAffineTransformMake (scaled_font->scale.xx, + scaled_font->scale.yx, + -scaled_font->scale.xy, + -scaled_font->scale.yy, + 0.0, 0.0); + + /* scaled_font->scale_inverse * scale(1,-1) */ + invTextTransform = CGAffineTransformMake (scaled_font->scale_inverse.xx, + -scaled_font->scale_inverse.yx, + scaled_font->scale_inverse.xy, + -scaled_font->scale_inverse.yy, + 0.0, 0.0); + + CGContextSetTextPosition (state.cgMaskContext, 0.0, 0.0); + CGContextSetTextMatrix (state.cgMaskContext, CGAffineTransformIdentity); + + /* Convert our glyph positions to glyph advances. We need n-1 advances, + * since the advance at index 0 is applied after glyph 0. */ + xprev = glyphs[0].x; + yprev = glyphs[0].y; + + cg_glyphs[0] = glyphs[0].index; + + for (i = 1; i < num_glyphs; i++) { + cairo_quartz_float_t xf = glyphs[i].x; + cairo_quartz_float_t yf = glyphs[i].y; + cg_glyphs[i] = glyphs[i].index; + cg_advances[i - 1] = CGSizeApplyAffineTransform (CGSizeMake (xf - xprev, yf - yprev), invTextTransform); + xprev = xf; + yprev = yf; + } + + /* Translate to the first glyph's position before drawing */ + CGContextTranslateCTM (state.cgMaskContext, glyphs[0].x, glyphs[0].y); + CGContextConcatCTM (state.cgMaskContext, textTransform); + + CGContextShowGlyphsWithAdvances (state.cgMaskContext, + cg_glyphs, + cg_advances, + num_glyphs); + + CGContextConcatCTM (state.cgMaskContext, invTextTransform); + CGContextTranslateCTM (state.cgMaskContext, -glyphs[0].x, -glyphs[0].y); + + if (state.action != DO_DIRECT) + _cairo_quartz_draw_source (&state, extents->op); + +BAIL: + if (didForceFontSmoothing) + CGContextSetAllowsFontSmoothingPtr (state.cgMaskContext, FALSE); + + _cairo_quartz_teardown_state (&state, extents); + + if (cg_glyphs != glyphs_static) + free (cg_glyphs); + + return rv; +} +#endif /* CAIRO_HAS_QUARTZ_FONT */ + +static const cairo_compositor_t _cairo_quartz_cg_compositor = { + &_cairo_fallback_compositor, + + _cairo_quartz_cg_paint, + _cairo_quartz_cg_mask, + _cairo_quartz_cg_stroke, + _cairo_quartz_cg_fill, +#if CAIRO_HAS_QUARTZ_FONT + _cairo_quartz_cg_glyphs, +#else + NULL, +#endif +}; + +static cairo_int_status_t +_cairo_quartz_surface_paint (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + return _cairo_compositor_paint (&_cairo_quartz_cg_compositor, + surface, op, source, clip); +} + +static cairo_int_status_t +_cairo_quartz_surface_mask (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + return _cairo_compositor_mask (&_cairo_quartz_cg_compositor, + surface, op, source, mask, + clip); +} + +static cairo_int_status_t +_cairo_quartz_surface_fill (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + return _cairo_compositor_fill (&_cairo_quartz_cg_compositor, + surface, op, source, path, + fill_rule, tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_quartz_surface_stroke (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + return _cairo_compositor_stroke (&_cairo_quartz_cg_compositor, + surface, op, source, path, + style, ctm,ctm_inverse, + tolerance, antialias, clip); +} + +static cairo_int_status_t +_cairo_quartz_surface_glyphs (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + return _cairo_compositor_glyphs (&_cairo_quartz_cg_compositor, + surface, op, source, + glyphs, num_glyphs, scaled_font, + clip); +} + +static cairo_status_t +_cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_quartz_surface_t *surface = + cairo_container_of (clipper, cairo_quartz_surface_t, clipper); + + ND ((stderr, "%p _cairo_quartz_surface_intersect_clip_path path: %p\n", surface, path)); + + if (IS_EMPTY (surface)) + return CAIRO_STATUS_SUCCESS; + + if (path == NULL) { + /* If we're being asked to reset the clip, we can only do it + * by restoring the gstate to our previous saved one, and + * saving it again. + * + * Note that this assumes that ALL quartz surface creation + * functions will do a SaveGState first; we do this in create_internal. + */ + CGContextRestoreGState (surface->cgContext); + CGContextSaveGState (surface->cgContext); + } else { + CGContextSetShouldAntialias (surface->cgContext, (antialias != CAIRO_ANTIALIAS_NONE)); + + _cairo_quartz_cairo_path_to_quartz_context (path, surface->cgContext); + + if (fill_rule == CAIRO_FILL_RULE_WINDING) + CGContextClip (surface->cgContext); + else + CGContextEOClip (surface->cgContext); + } + + ND ((stderr, "-- intersect_clip_path\n")); + + return CAIRO_STATUS_SUCCESS; +} + +// XXXtodo implement show_page; need to figure out how to handle begin/end + +static const struct _cairo_surface_backend cairo_quartz_surface_backend = { + CAIRO_SURFACE_TYPE_QUARTZ, + _cairo_quartz_surface_finish, + + _cairo_default_context_create, + + _cairo_quartz_surface_create_similar, + NULL, /* similar image */ + _cairo_quartz_surface_map_to_image, + _cairo_quartz_surface_unmap_image, + + _cairo_surface_default_source, + _cairo_quartz_surface_acquire_source_image, + _cairo_quartz_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_quartz_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_quartz_surface_paint, + _cairo_quartz_surface_mask, + _cairo_quartz_surface_stroke, + _cairo_quartz_surface_fill, + NULL, /* fill-stroke */ + _cairo_quartz_surface_glyphs, +}; + +cairo_quartz_surface_t * +_cairo_quartz_surface_create_internal (CGContextRef cgContext, + cairo_content_t content, + unsigned int width, + unsigned int height) +{ + cairo_quartz_surface_t *surface; + + quartz_ensure_symbols (); + + /* Init the base surface */ + surface = malloc (sizeof (cairo_quartz_surface_t)); + if (unlikely (surface == NULL)) + return (cairo_quartz_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + memset (surface, 0, sizeof (cairo_quartz_surface_t)); + + _cairo_surface_init (&surface->base, + &cairo_quartz_surface_backend, + NULL, /* device */ + content); + + _cairo_surface_clipper_init (&surface->clipper, + _cairo_quartz_surface_clipper_intersect_clip_path); + + /* Save our extents */ + surface->extents.x = surface->extents.y = 0; + surface->extents.width = width; + surface->extents.height = height; + surface->virtual_extents = surface->extents; + + if (IS_EMPTY (surface)) { + surface->cgContext = NULL; + surface->cgContextBaseCTM = CGAffineTransformIdentity; + surface->imageData = NULL; + surface->base.is_clear = TRUE; + return surface; + } + + /* Save so we can always get back to a known-good CGContext -- this is + * required for proper behaviour of intersect_clip_path(NULL) + */ + CGContextSaveGState (cgContext); + + surface->cgContext = cgContext; + surface->cgContextBaseCTM = CGContextGetCTM (cgContext); + + surface->imageData = NULL; + surface->imageSurfaceEquiv = NULL; + + return surface; +} + +/** + * cairo_quartz_surface_create_for_cg_context: + * @cgContext: the existing CGContext for which to create the surface + * @width: width of the surface, in pixels + * @height: height of the surface, in pixels + * + * Creates a Quartz surface that wraps the given CGContext. The + * CGContext is assumed to be in the standard Cairo coordinate space + * (that is, with the origin at the upper left and the Y axis + * increasing downward). If the CGContext is in the Quartz coordinate + * space (with the origin at the bottom left), then it should be + * flipped before this function is called. The flip can be accomplished + * using a translate and a scale; for example: + * + * + * CGContextTranslateCTM (cgContext, 0.0, height); + * CGContextScaleCTM (cgContext, 1.0, -1.0); + * + * + * All Cairo operations are implemented in terms of Quartz operations, + * as long as Quartz-compatible elements are used (such as Quartz fonts). + * + * Return value: the newly created Cairo surface. + * + * Since: 1.6 + **/ + +cairo_surface_t * +cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext, + unsigned int width, + unsigned int height) +{ + cairo_quartz_surface_t *surf; + + surf = _cairo_quartz_surface_create_internal (cgContext, CAIRO_CONTENT_COLOR_ALPHA, + width, height); + if (likely (!surf->base.status)) + CGContextRetain (cgContext); + + return &surf->base; +} + +/** + * cairo_quartz_surface_create: + * @format: format of pixels in the surface to create + * @width: width of the surface, in pixels + * @height: height of the surface, in pixels + * + * Creates a Quartz surface backed by a CGBitmap. The surface is + * created using the Device RGB (or Device Gray, for A8) color space. + * All Cairo operations, including those that require software + * rendering, will succeed on this surface. + * + * Return value: the newly created surface. + * + * Since: 1.6 + **/ +cairo_surface_t * +cairo_quartz_surface_create (cairo_format_t format, + unsigned int width, + unsigned int height) +{ + cairo_quartz_surface_t *surf; + CGContextRef cgc; + CGColorSpaceRef cgColorspace; + CGBitmapInfo bitinfo; + void *imageData; + int stride; + int bitsPerComponent; + + if (!_cairo_quartz_verify_surface_size (width, height)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + if (width == 0 || height == 0) { + return &_cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format), + width, height)->base; + } + + if (format == CAIRO_FORMAT_ARGB32 || + format == CAIRO_FORMAT_RGB24) + { + cgColorspace = CGColorSpaceCreateDeviceRGB (); + bitinfo = kCGBitmapByteOrder32Host; + if (format == CAIRO_FORMAT_ARGB32) + bitinfo |= kCGImageAlphaPremultipliedFirst; + else + bitinfo |= kCGImageAlphaNoneSkipFirst; + bitsPerComponent = 8; + stride = width * 4; + } else if (format == CAIRO_FORMAT_A8) { + cgColorspace = NULL; + stride = width; + bitinfo = kCGImageAlphaOnly; + bitsPerComponent = 8; + } else if (format == CAIRO_FORMAT_A1) { + /* I don't think we can usefully support this, as defined by + * cairo_format_t -- these are 1-bit pixels stored in 32-bit + * quantities. + */ + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + } else { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + } + + /* The Apple docs say that for best performance, the stride and the data + * pointer should be 16-byte aligned. malloc already aligns to 16-bytes, + * so we don't have to anything special on allocation. + */ + stride = (stride + 15) & ~15; + + imageData = _cairo_malloc_ab (height, stride); + if (unlikely (!imageData)) { + CGColorSpaceRelease (cgColorspace); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + /* zero the memory to match the image surface behaviour */ + memset (imageData, 0, height * stride); + + cgc = CGBitmapContextCreate (imageData, + width, + height, + bitsPerComponent, + stride, + cgColorspace, + bitinfo); + CGColorSpaceRelease (cgColorspace); + + if (!cgc) { + free (imageData); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + /* flip the Y axis */ + CGContextTranslateCTM (cgc, 0.0, height); + CGContextScaleCTM (cgc, 1.0, -1.0); + + surf = _cairo_quartz_surface_create_internal (cgc, _cairo_content_from_format (format), + width, height); + if (surf->base.status) { + CGContextRelease (cgc); + free (imageData); + // create_internal will have set an error + return &surf->base; + } + + surf->base.is_clear = TRUE; + + surf->imageData = imageData; + surf->imageSurfaceEquiv = cairo_image_surface_create_for_data (imageData, format, width, height, stride); + + return &surf->base; +} + +/** + * cairo_quartz_surface_get_cg_context: + * @surface: the Cairo Quartz surface + * + * Returns the CGContextRef that the given Quartz surface is backed + * by. + * + * A call to cairo_surface_flush() is required before using the + * CGContextRef to ensure that all pending drawing operations are + * finished and to restore any temporary modification cairo has made + * to its state. A call to cairo_surface_mark_dirty() is required + * after the state or the content of the CGContextRef has been + * modified. + * + * Return value: the CGContextRef for the given surface. + * + * Since: 1.6 + **/ +CGContextRef +cairo_quartz_surface_get_cg_context (cairo_surface_t *surface) +{ + if (surface && _cairo_surface_is_quartz (surface)) { + cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t *) surface; + return quartz->cgContext; + } else + return NULL; +} + +/** + * _cairo_surface_is_quartz: + * @surface: a #cairo_surface_t + * + * Checks if a surface is a #cairo_quartz_surface_t + * + * Return value: True if the surface is an quartz surface + **/ +cairo_bool_t +_cairo_surface_is_quartz (const cairo_surface_t *surface) +{ + return surface->backend == &cairo_quartz_surface_backend; +} + +/* Debug stuff */ + +#ifdef QUARTZ_DEBUG + +#include + +void ExportCGImageToPNGFile (CGImageRef inImageRef, char* dest) +{ + Handle dataRef = NULL; + OSType dataRefType; + CFStringRef inPath = CFStringCreateWithCString (NULL, dest, kCFStringEncodingASCII); + + GraphicsExportComponent grex = 0; + unsigned long sizeWritten; + + ComponentResult result; + + // create the data reference + result = QTNewDataReferenceFromFullPathCFString (inPath, kQTNativeDefaultPathStyle, + 0, &dataRef, &dataRefType); + + if (NULL != dataRef && noErr == result) { + // get the PNG exporter + result = OpenADefaultComponent (GraphicsExporterComponentType, kQTFileTypePNG, + &grex); + + if (grex) { + // tell the exporter where to find its source image + result = GraphicsExportSetInputCGImage (grex, inImageRef); + + if (noErr == result) { + // tell the exporter where to save the exporter image + result = GraphicsExportSetOutputDataReference (grex, dataRef, + dataRefType); + + if (noErr == result) { + // write the PNG file + result = GraphicsExportDoExport (grex, &sizeWritten); + } + } + + // remember to close the component + CloseComponent (grex); + } + + // remember to dispose of the data reference handle + DisposeHandle (dataRef); + } +} + +void +quartz_image_to_png (CGImageRef imgref, char *dest) +{ + static int sctr = 0; + char sptr[] = "/Users/vladimir/Desktop/barXXXXX.png"; + + if (dest == NULL) { + fprintf (stderr, "** Writing %p to bar%d\n", imgref, sctr); + sprintf (sptr, "/Users/vladimir/Desktop/bar%d.png", sctr); + sctr++; + dest = sptr; + } + + ExportCGImageToPNGFile (imgref, dest); +} + +void +quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest) +{ + static int sctr = 0; + char sptr[] = "/Users/vladimir/Desktop/fooXXXXX.png"; + + if (nq->base.type != CAIRO_SURFACE_TYPE_QUARTZ) { + fprintf (stderr, "** quartz_surface_to_png: surface %p isn't quartz!\n", nq); + return; + } + + if (dest == NULL) { + fprintf (stderr, "** Writing %p to foo%d\n", nq, sctr); + sprintf (sptr, "/Users/vladimir/Desktop/foo%d.png", sctr); + sctr++; + dest = sptr; + } + + CGImageRef imgref = CGBitmapContextCreateImage (nq->cgContext); + if (imgref == NULL) { + fprintf (stderr, "quartz surface at %p is not a bitmap context!\n", nq); + return; + } + + ExportCGImageToPNGFile (imgref, dest); + + CGImageRelease (imgref); +} + +#endif /* QUARTZ_DEBUG */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-quartz.h b/Build/source/libs/cairo/cairo-src/src/cairo-quartz.h new file mode 100644 index 00000000000..9be5f9ae5cf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-quartz.h @@ -0,0 +1,82 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright 2006, 2007 Mozilla Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * + * Contributor(s): + * Vladimir Vukicevic + */ + +#ifndef CAIRO_QUARTZ_H +#define CAIRO_QUARTZ_H + +#include "cairo.h" + +#if CAIRO_HAS_QUARTZ_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_quartz_surface_create (cairo_format_t format, + unsigned int width, + unsigned int height); + +cairo_public cairo_surface_t * +cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext, + unsigned int width, + unsigned int height); + +cairo_public CGContextRef +cairo_quartz_surface_get_cg_context (cairo_surface_t *surface); + +#if CAIRO_HAS_QUARTZ_FONT + +/* + * Quartz font support + */ + +cairo_public cairo_font_face_t * +cairo_quartz_font_face_create_for_cgfont (CGFontRef font); + +cairo_public cairo_font_face_t * +cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id); + +#endif /* CAIRO_HAS_QUARTZ_FONT */ + +CAIRO_END_DECLS + +#else + +# error Cairo was not compiled with support for the quartz backend + +#endif /* CAIRO_HAS_QUARTZ_SURFACE */ + +#endif /* CAIRO_QUARTZ_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-raster-source-pattern.c b/Build/source/libs/cairo/cairo-src/src/cairo-raster-source-pattern.c new file mode 100644 index 00000000000..64520feae52 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-raster-source-pattern.c @@ -0,0 +1,430 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-error-private.h" +#include "cairo-pattern-private.h" + +/** + * SECTION:cairo-raster-source + * @Title: Raster Sources + * @Short_Description: Supplying arbitrary image data + * @See_Also: #cairo_pattern_t + * + * The raster source provides the ability to supply arbitrary pixel data + * whilst rendering. The pixels are queried at the time of rasterisation + * by means of user callback functions, allowing for the ultimate + * flexibility. For example, in handling compressed image sources, you + * may keep a MRU cache of decompressed images and decompress sources on the + * fly and discard old ones to conserve memory. + * + * For the raster source to be effective, you must at least specify + * the acquire and release callbacks which are used to retrieve the pixel + * data for the region of interest and demark when it can be freed afterwards. + * Other callbacks are provided for when the pattern is copied temporarily + * during rasterisation, or more permanently as a snapshot in order to keep + * the pixel data available for printing. + **/ + +cairo_surface_t * +_cairo_raster_source_pattern_acquire (const cairo_pattern_t *abstract_pattern, + cairo_surface_t *target, + const cairo_rectangle_int_t *extents) +{ + cairo_raster_source_pattern_t *pattern = + (cairo_raster_source_pattern_t *) abstract_pattern; + + if (pattern->acquire == NULL) + return NULL; + + if (extents == NULL) + extents = &pattern->extents; + + return pattern->acquire (&pattern->base, pattern->user_data, + target, extents); +} + +void +_cairo_raster_source_pattern_release (const cairo_pattern_t *abstract_pattern, + cairo_surface_t *surface) +{ + cairo_raster_source_pattern_t *pattern = + (cairo_raster_source_pattern_t *) abstract_pattern; + + if (pattern->release == NULL) + return; + + pattern->release (&pattern->base, pattern->user_data, surface); +} + +cairo_status_t +_cairo_raster_source_pattern_init_copy (cairo_pattern_t *abstract_pattern, + const cairo_pattern_t *other) +{ + cairo_raster_source_pattern_t *pattern = + (cairo_raster_source_pattern_t *) abstract_pattern; + cairo_status_t status; + + VG (VALGRIND_MAKE_MEM_UNDEFINED (pattern, sizeof (cairo_raster_source_pattern_t))); + memcpy(pattern, other, sizeof (cairo_raster_source_pattern_t)); + + status = CAIRO_STATUS_SUCCESS; + if (pattern->copy) + status = pattern->copy (&pattern->base, pattern->user_data, other); + + return status; +} + +cairo_status_t +_cairo_raster_source_pattern_snapshot (cairo_pattern_t *abstract_pattern) +{ + cairo_raster_source_pattern_t *pattern = + (cairo_raster_source_pattern_t *) abstract_pattern; + + if (pattern->snapshot == NULL) + return CAIRO_STATUS_SUCCESS; + + return pattern->snapshot (&pattern->base, pattern->user_data); +} + +void +_cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern) +{ + cairo_raster_source_pattern_t *pattern = + (cairo_raster_source_pattern_t *) abstract_pattern; + + if (pattern->finish == NULL) + return; + + pattern->finish (&pattern->base, pattern->user_data); +} + +/* Public interface */ + +/** + * cairo_pattern_create_raster_source: + * @user_data: the user data to be passed to all callbacks + * @content: content type for the pixel data that will be returned. Knowing + * the content type ahead of time is used for analysing the operation and + * picking the appropriate rendering path. + * @width: maximum size of the sample area + * @height: maximum size of the sample area + * + * Creates a new user pattern for providing pixel data. + * + * Use the setter functions to associate callbacks with the returned + * pattern. The only mandatory callback is acquire. + * + * Return value: a newly created #cairo_pattern_t. Free with + * cairo_pattern_destroy() when you are done using it. + * + * Since: 1.12 + **/ +cairo_pattern_t * +cairo_pattern_create_raster_source (void *user_data, + cairo_content_t content, + int width, int height) +{ + cairo_raster_source_pattern_t *pattern; + + CAIRO_MUTEX_INITIALIZE (); + + if (width < 0 || height < 0) + return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_SIZE); + + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_CONTENT); + + pattern = calloc (1, sizeof (*pattern)); + if (unlikely (pattern == NULL)) + return _cairo_pattern_create_in_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_pattern_init (&pattern->base, + CAIRO_PATTERN_TYPE_RASTER_SOURCE); + CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); + + pattern->content = content; + + pattern->extents.x = 0; + pattern->extents.y = 0; + pattern->extents.width = width; + pattern->extents.height = height; + + pattern->user_data = user_data; + + return &pattern->base; +} + +/** + * cairo_raster_source_pattern_set_callback_data: + * @pattern: the pattern to update + * @data: the user data to be passed to all callbacks + * + * Updates the user data that is provided to all callbacks. + * + * Since: 1.12 + **/ +void +cairo_raster_source_pattern_set_callback_data (cairo_pattern_t *abstract_pattern, + void *data) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + pattern->user_data = data; +} + +/** + * cairo_raster_source_pattern_get_callback_data: + * @pattern: the pattern to update + * + * Queries the current user data. + * + * Return value: the current user-data passed to each callback + * + * Since: 1.12 + **/ +void * +cairo_raster_source_pattern_get_callback_data (cairo_pattern_t *abstract_pattern) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return NULL; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + return pattern->user_data; +} + +/** + * cairo_raster_source_pattern_set_acquire: + * @pattern: the pattern to update + * @acquire: acquire callback + * @release: release callback + * + * Specifies the callbacks used to generate the image surface for a rendering + * operation (acquire) and the function used to cleanup that surface afterwards. + * + * The @acquire callback should create a surface (preferably an image + * surface created to match the target using + * cairo_surface_create_similar_image()) that defines at least the region + * of interest specified by extents. The surface is allowed to be the entire + * sample area, but if it does contain a subsection of the sample area, + * the surface extents should be provided by setting the device offset (along + * with its width and height) using cairo_surface_set_device_offset(). + * + * Since: 1.12 + **/ +void +cairo_raster_source_pattern_set_acquire (cairo_pattern_t *abstract_pattern, + cairo_raster_source_acquire_func_t acquire, + cairo_raster_source_release_func_t release) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + pattern->acquire = acquire; + pattern->release = release; +} + +/** + * cairo_raster_source_pattern_get_acquire: + * @pattern: the pattern to query + * @acquire: return value for the current acquire callback + * @release: return value for the current release callback + * + * Queries the current acquire and release callbacks. + * + * Since: 1.12 + **/ +void +cairo_raster_source_pattern_get_acquire (cairo_pattern_t *abstract_pattern, + cairo_raster_source_acquire_func_t *acquire, + cairo_raster_source_release_func_t *release) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + if (acquire) + *acquire = pattern->acquire; + if (release) + *release = pattern->release; +} + +/** + * cairo_raster_source_pattern_set_snapshot: + * @pattern: the pattern to update + * @snapshot: snapshot callback + * + * Sets the callback that will be used whenever a snapshot is taken of the + * pattern, that is whenever the current contents of the pattern should be + * preserved for later use. This is typically invoked whilst printing. + * + * Since: 1.12 + **/ +void +cairo_raster_source_pattern_set_snapshot (cairo_pattern_t *abstract_pattern, + cairo_raster_source_snapshot_func_t snapshot) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + pattern->snapshot = snapshot; +} + +/** + * cairo_raster_source_pattern_get_snapshot: + * @pattern: the pattern to query + * + * Queries the current snapshot callback. + * + * Return value: the current snapshot callback + * + * Since: 1.12 + **/ +cairo_raster_source_snapshot_func_t +cairo_raster_source_pattern_get_snapshot (cairo_pattern_t *abstract_pattern) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return NULL; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + return pattern->snapshot; +} + +/** + * cairo_raster_source_pattern_set_copy: + * @pattern: the pattern to update + * @copy: the copy callback + * + * Updates the copy callback which is used whenever a temporary copy of the + * pattern is taken. + * + * Since: 1.12 + **/ +void +cairo_raster_source_pattern_set_copy (cairo_pattern_t *abstract_pattern, + cairo_raster_source_copy_func_t copy) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + pattern->copy = copy; +} + +/** + * cairo_raster_source_pattern_get_copy: + * @pattern: the pattern to query + * + * Queries the current copy callback. + * + * Return value: the current copy callback + * + * Since: 1.12 + **/ +cairo_raster_source_copy_func_t +cairo_raster_source_pattern_get_copy (cairo_pattern_t *abstract_pattern) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return NULL; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + return pattern->copy; +} + +/** + * cairo_raster_source_pattern_set_finish: + * @pattern: the pattern to update + * @finish: the finish callback + * + * Updates the finish callback which is used whenever a pattern (or a copy + * thereof) will no longer be used. + * + * Since: 1.12 + **/ +void +cairo_raster_source_pattern_set_finish (cairo_pattern_t *abstract_pattern, + cairo_raster_source_finish_func_t finish) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + pattern->finish = finish; +} + +/** + * cairo_raster_source_pattern_get_finish: + * @pattern: the pattern to query + * + * Queries the current finish callback. + * + * Return value: the current finish callback + * + * Since: 1.12 + **/ +cairo_raster_source_finish_func_t +cairo_raster_source_pattern_get_finish (cairo_pattern_t *abstract_pattern) +{ + cairo_raster_source_pattern_t *pattern; + + if (abstract_pattern->type != CAIRO_PATTERN_TYPE_RASTER_SOURCE) + return NULL; + + pattern = (cairo_raster_source_pattern_t *) abstract_pattern; + return pattern->finish; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-inline.h new file mode 100644 index 00000000000..9002ccd6938 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-inline.h @@ -0,0 +1,68 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Adrian Johnson + */ + +#ifndef CAIRO_RECORDING_SURFACE_INLINE_H +#define CAIRO_RECORDING_SURFACE_INLINE_H + +#include "cairo-recording-surface-private.h" + +static inline cairo_bool_t +_cairo_recording_surface_get_bounds (cairo_surface_t *surface, + cairo_rectangle_t *extents) +{ + cairo_recording_surface_t *recording = (cairo_recording_surface_t *)surface; + if (recording->unbounded) + return FALSE; + + *extents = recording->extents_pixels; + return TRUE; +} + +/** + * _cairo_surface_is_recording: + * @surface: a #cairo_surface_t + * + * Checks if a surface is a #cairo_recording_surface_t + * + * Return value: %TRUE if the surface is a recording surface + **/ +static inline cairo_bool_t +_cairo_surface_is_recording (const cairo_surface_t *surface) +{ + return surface->backend->type == CAIRO_SURFACE_TYPE_RECORDING; +} + +#endif /* CAIRO_RECORDING_SURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-private.h new file mode 100644 index 00000000000..456c63389b7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface-private.h @@ -0,0 +1,195 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Adrian Johnson + */ + +#ifndef CAIRO_RECORDING_SURFACE_H +#define CAIRO_RECORDING_SURFACE_H + +#include "cairoint.h" +#include "cairo-path-fixed-private.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-backend-private.h" + +typedef enum { + /* The 5 basic drawing operations. */ + CAIRO_COMMAND_PAINT, + CAIRO_COMMAND_MASK, + CAIRO_COMMAND_STROKE, + CAIRO_COMMAND_FILL, + CAIRO_COMMAND_SHOW_TEXT_GLYPHS, +} cairo_command_type_t; + +typedef enum { + CAIRO_RECORDING_REGION_ALL, + CAIRO_RECORDING_REGION_NATIVE, + CAIRO_RECORDING_REGION_IMAGE_FALLBACK +} cairo_recording_region_type_t; + +typedef struct _cairo_command_header { + cairo_command_type_t type; + cairo_recording_region_type_t region; + cairo_operator_t op; + cairo_rectangle_int_t extents; + cairo_clip_t *clip; + + int index; + struct _cairo_command_header *chain; +} cairo_command_header_t; + +typedef struct _cairo_command_paint { + cairo_command_header_t header; + cairo_pattern_union_t source; +} cairo_command_paint_t; + +typedef struct _cairo_command_mask { + cairo_command_header_t header; + cairo_pattern_union_t source; + cairo_pattern_union_t mask; +} cairo_command_mask_t; + +typedef struct _cairo_command_stroke { + cairo_command_header_t header; + cairo_pattern_union_t source; + cairo_path_fixed_t path; + cairo_stroke_style_t style; + cairo_matrix_t ctm; + cairo_matrix_t ctm_inverse; + double tolerance; + cairo_antialias_t antialias; +} cairo_command_stroke_t; + +typedef struct _cairo_command_fill { + cairo_command_header_t header; + cairo_pattern_union_t source; + cairo_path_fixed_t path; + cairo_fill_rule_t fill_rule; + double tolerance; + cairo_antialias_t antialias; +} cairo_command_fill_t; + +typedef struct _cairo_command_show_text_glyphs { + cairo_command_header_t header; + cairo_pattern_union_t source; + char *utf8; + int utf8_len; + cairo_glyph_t *glyphs; + unsigned int num_glyphs; + cairo_text_cluster_t *clusters; + int num_clusters; + cairo_text_cluster_flags_t cluster_flags; + cairo_scaled_font_t *scaled_font; +} cairo_command_show_text_glyphs_t; + +typedef union _cairo_command { + cairo_command_header_t header; + + cairo_command_paint_t paint; + cairo_command_mask_t mask; + cairo_command_stroke_t stroke; + cairo_command_fill_t fill; + cairo_command_show_text_glyphs_t show_text_glyphs; +} cairo_command_t; + +typedef struct _cairo_recording_surface { + cairo_surface_t base; + + /* A recording-surface is logically unbounded, but when used as a + * source we need to render it to an image, so we need a size at + * which to create that image. */ + cairo_rectangle_t extents_pixels; + cairo_rectangle_int_t extents; + cairo_bool_t unbounded; + + cairo_array_t commands; + unsigned int *indices; + unsigned int num_indices; + cairo_bool_t optimize_clears; + cairo_bool_t has_bilevel_alpha; + cairo_bool_t has_only_op_over; + + struct bbtree { + cairo_box_t extents; + struct bbtree *left, *right; + cairo_command_header_t *chain; + } bbtree; +} cairo_recording_surface_t; + +slim_hidden_proto (cairo_recording_surface_create); + +cairo_private cairo_int_status_t +_cairo_recording_surface_get_path (cairo_surface_t *surface, + cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_recording_surface_replay_one (cairo_recording_surface_t *surface, + long unsigned index, + cairo_surface_t *target); + +cairo_private cairo_status_t +_cairo_recording_surface_replay (cairo_surface_t *surface, + cairo_surface_t *target); + +cairo_private cairo_status_t +_cairo_recording_surface_replay_with_clip (cairo_surface_t *surface, + const cairo_matrix_t *surface_transform, + cairo_surface_t *target, + const cairo_clip_t *target_clip); + +cairo_private cairo_status_t +_cairo_recording_surface_replay_and_create_regions (cairo_surface_t *surface, + cairo_surface_t *target); +cairo_private cairo_status_t +_cairo_recording_surface_replay_region (cairo_surface_t *surface, + const cairo_rectangle_int_t *surface_extents, + cairo_surface_t *target, + cairo_recording_region_type_t region); + +cairo_private cairo_status_t +_cairo_recording_surface_get_bbox (cairo_recording_surface_t *recording, + cairo_box_t *bbox, + const cairo_matrix_t *transform); + +cairo_private cairo_status_t +_cairo_recording_surface_get_ink_bbox (cairo_recording_surface_t *surface, + cairo_box_t *bbox, + const cairo_matrix_t *transform); + +cairo_private cairo_bool_t +_cairo_recording_surface_has_only_bilevel_alpha (cairo_recording_surface_t *surface); + +cairo_private cairo_bool_t +_cairo_recording_surface_has_only_op_over (cairo_recording_surface_t *surface); + +#endif /* CAIRO_RECORDING_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface.c new file mode 100644 index 00000000000..78e7cfa7efc --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-recording-surface.c @@ -0,0 +1,2188 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * Copyright © 2007 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Carl Worth + * Adrian Johnson + */ + +/** + * SECTION:cairo-recording + * @Title: Recording Surfaces + * @Short_Description: Records all drawing operations + * @See_Also: #cairo_surface_t + * + * A recording surface is a surface that records all drawing operations at + * the highest level of the surface backend interface, (that is, the + * level of paint, mask, stroke, fill, and show_text_glyphs). The recording + * surface can then be "replayed" against any target surface by using it + * as a source surface. + * + * If you want to replay a surface so that the results in target will be + * identical to the results that would have been obtained if the original + * operations applied to the recording surface had instead been applied to the + * target surface, you can use code like this: + * + * cairo_t *cr; + * + * cr = cairo_create (target); + * cairo_set_source_surface (cr, recording_surface, 0.0, 0.0); + * cairo_paint (cr); + * cairo_destroy (cr); + * + * + * A recording surface is logically unbounded, i.e. it has no implicit constraint + * on the size of the drawing surface. However, in practice this is rarely + * useful as you wish to replay against a particular target surface with + * known bounds. For this case, it is more efficient to specify the target + * extents to the recording surface upon creation. + * + * The recording phase of the recording surface is careful to snapshot all + * necessary objects (paths, patterns, etc.), in order to achieve + * accurate replay. The efficiency of the recording surface could be + * improved by improving the implementation of snapshot for the + * various objects. For example, it would be nice to have a + * copy-on-write implementation for _cairo_surface_snapshot. + **/ + +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-analysis-surface-private.h" +#include "cairo-clip-private.h" +#include "cairo-combsort-inline.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-wrapper-private.h" +#include "cairo-traps-private.h" + +typedef enum { + CAIRO_RECORDING_REPLAY, + CAIRO_RECORDING_CREATE_REGIONS +} cairo_recording_replay_type_t; + +static const cairo_surface_backend_t cairo_recording_surface_backend; + +/** + * CAIRO_HAS_RECORDING_SURFACE: + * + * Defined if the recording surface backend is available. + * The recording surface backend is always built in. + * This macro was added for completeness in cairo 1.10. + * + * Since: 1.10 + **/ + +/* Currently all recording surfaces do have a size which should be passed + * in as the maximum size of any target surface against which the + * recording-surface will ever be replayed. + * + * XXX: The naming of "pixels" in the size here is a misnomer. It's + * actually a size in whatever device-space units are desired (again, + * according to the intended replay target). + */ + +static int bbtree_left_or_right (struct bbtree *bbt, + const cairo_box_t *box) +{ + int left, right; + + if (bbt->left) { + cairo_box_t *e = &bbt->left->extents; + cairo_box_t b; + + b.p1.x = MIN (e->p1.x, box->p1.x); + b.p1.y = MIN (e->p1.y, box->p1.y); + b.p2.x = MAX (e->p2.x, box->p2.x); + b.p2.y = MAX (e->p2.y, box->p2.y); + + left = _cairo_fixed_integer_part (b.p2.x - b.p1.x) * _cairo_fixed_integer_part (b.p2.y - b.p1.y); + left -= _cairo_fixed_integer_part (e->p2.x - e->p1.x) * _cairo_fixed_integer_part (e->p2.y - e->p1.y); + } else + left = 0; + + if (bbt->right) { + cairo_box_t *e = &bbt->right->extents; + cairo_box_t b; + + b.p1.x = MIN (e->p1.x, box->p1.x); + b.p1.y = MIN (e->p1.y, box->p1.y); + b.p2.x = MAX (e->p2.x, box->p2.x); + b.p2.y = MAX (e->p2.y, box->p2.y); + + right = _cairo_fixed_integer_part (b.p2.x - b.p1.x) * _cairo_fixed_integer_part (b.p2.y - b.p1.y); + right -= _cairo_fixed_integer_part (e->p2.x - e->p1.x) * _cairo_fixed_integer_part (e->p2.y - e->p1.y); + } else + right = 0; + + return left <= right; +} + +#define INVALID_CHAIN ((cairo_command_header_t *)-1) + +static struct bbtree * +bbtree_new (const cairo_box_t *box, cairo_command_header_t *chain) +{ + struct bbtree *bbt = malloc (sizeof (*bbt)); + if (bbt == NULL) + return NULL; + bbt->extents = *box; + bbt->left = bbt->right = NULL; + bbt->chain = chain; + return bbt; +} + +static void +bbtree_init (struct bbtree *bbt, cairo_command_header_t *header) +{ + _cairo_box_from_rectangle (&bbt->extents, &header->extents); + bbt->chain = header; +} + +static cairo_status_t +bbtree_add (struct bbtree *bbt, + cairo_command_header_t *header, + const cairo_box_t *box) +{ + if (box->p1.x < bbt->extents.p1.x || box->p1.y < bbt->extents.p1.y || + box->p2.x > bbt->extents.p2.x || box->p2.y > bbt->extents.p2.y) + { + if (bbt->chain) { + if (bbtree_left_or_right (bbt, &bbt->extents)) { + if (bbt->left == NULL) { + bbt->left = bbtree_new (&bbt->extents, bbt->chain); + if (unlikely (bbt->left == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + bbtree_add (bbt->left, bbt->chain, &bbt->extents); + } else { + if (bbt->right == NULL) { + bbt->right = bbtree_new (&bbt->extents, bbt->chain); + if (unlikely (bbt->right == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + bbtree_add (bbt->right, bbt->chain, &bbt->extents); + } + + bbt->chain = NULL; + } + + bbt->extents.p1.x = MIN (bbt->extents.p1.x, box->p1.x); + bbt->extents.p1.y = MIN (bbt->extents.p1.y, box->p1.y); + bbt->extents.p2.x = MAX (bbt->extents.p2.x, box->p2.x); + bbt->extents.p2.y = MAX (bbt->extents.p2.y, box->p2.y); + } + + if (box->p1.x == bbt->extents.p1.x && box->p1.y == bbt->extents.p1.y && + box->p2.x == bbt->extents.p2.x && box->p2.y == bbt->extents.p2.y) + { + cairo_command_header_t *last = header; + while (last->chain) /* expected to be infrequent */ + last = last->chain; + last->chain = bbt->chain; + bbt->chain = header; + return CAIRO_STATUS_SUCCESS; + } + + if (bbtree_left_or_right (bbt, box)) { + if (bbt->left == NULL) { + bbt->left = bbtree_new (box, header); + if (unlikely (bbt->left == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + return bbtree_add (bbt->left, header, box); + } else { + if (bbt->right == NULL) { + bbt->right = bbtree_new (box, header); + if (unlikely (bbt->right == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + return bbtree_add (bbt->right, header, box); + } + + return CAIRO_STATUS_SUCCESS; +} + +static void bbtree_del (struct bbtree *bbt) +{ + if (bbt->left) + bbtree_del (bbt->left); + if (bbt->right) + bbtree_del (bbt->right); + + free (bbt); +} + +static cairo_bool_t box_outside (const cairo_box_t *a, const cairo_box_t *b) +{ + return + a->p1.x >= b->p2.x || a->p1.y >= b->p2.y || + a->p2.x <= b->p1.x || a->p2.y <= b->p1.y; +} + +static void +bbtree_foreach_mark_visible (struct bbtree *bbt, + const cairo_box_t *box, + unsigned int **indices) +{ + cairo_command_header_t *chain; + + for (chain = bbt->chain; chain; chain = chain->chain) + *(*indices)++ = chain->index; + + if (bbt->left && ! box_outside (box, &bbt->left->extents)) + bbtree_foreach_mark_visible (bbt->left, box, indices); + if (bbt->right && ! box_outside (box, &bbt->right->extents)) + bbtree_foreach_mark_visible (bbt->right, box, indices); +} + +static inline int intcmp (const unsigned int a, const unsigned int b) +{ + return a - b; +} +CAIRO_COMBSORT_DECLARE (sort_indices, unsigned int, intcmp) + +static inline int sizecmp (unsigned int a, unsigned int b, cairo_command_header_t **elements) +{ + const cairo_rectangle_int_t *r; + + r = &elements[a]->extents; + a = r->width * r->height; + + r = &elements[b]->extents; + b = r->width * r->height; + + return b - a; +} +CAIRO_COMBSORT_DECLARE_WITH_DATA (sort_commands, unsigned int, sizecmp) + +static void +_cairo_recording_surface_destroy_bbtree (cairo_recording_surface_t *surface) +{ + cairo_command_t **elements; + int i, num_elements; + + if (surface->bbtree.chain == INVALID_CHAIN) + return; + + if (surface->bbtree.left) { + bbtree_del (surface->bbtree.left); + surface->bbtree.left = NULL; + } + if (surface->bbtree.right) { + bbtree_del (surface->bbtree.right); + surface->bbtree.right = NULL; + } + + elements = _cairo_array_index (&surface->commands, 0); + num_elements = surface->commands.num_elements; + for (i = 0; i < num_elements; i++) + elements[i]->header.chain = NULL; + + surface->bbtree.chain = INVALID_CHAIN; +} + +static cairo_status_t +_cairo_recording_surface_create_bbtree (cairo_recording_surface_t *surface) +{ + cairo_command_t **elements = _cairo_array_index (&surface->commands, 0); + unsigned int *indices; + cairo_status_t status; + unsigned int i, count; + + count = surface->commands.num_elements; + if (count > surface->num_indices) { + free (surface->indices); + surface->indices = _cairo_malloc_ab (count, sizeof (int)); + if (unlikely (surface->indices == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + surface->num_indices = count; + } + + indices = surface->indices; + for (i = 0; i < count; i++) + indices[i] = i; + + sort_commands (indices, count, elements); + + bbtree_init (&surface->bbtree, &elements[indices[0]]->header); + for (i = 1; i < count; i++) { + cairo_command_header_t *header = &elements[indices[i]]->header; + cairo_box_t box; + + _cairo_box_from_rectangle (&box, &header->extents); + status = bbtree_add (&surface->bbtree, header, &box); + if (unlikely (status)) + goto cleanup; + } + + return CAIRO_STATUS_SUCCESS; + +cleanup: + bbtree_del (&surface->bbtree); + return status; +} + +/** + * cairo_recording_surface_create: + * @content: the content of the recording surface + * @extents: the extents to record in pixels, can be %NULL to record + * unbounded operations. + * + * Creates a recording-surface which can be used to record all drawing operations + * at the highest level (that is, the level of paint, mask, stroke, fill + * and show_text_glyphs). The recording surface can then be "replayed" against + * any target surface by using it as a source to drawing operations. + * + * The recording phase of the recording surface is careful to snapshot all + * necessary objects (paths, patterns, etc.), in order to achieve + * accurate replay. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * Since: 1.10 + **/ +cairo_surface_t * +cairo_recording_surface_create (cairo_content_t content, + const cairo_rectangle_t *extents) +{ + cairo_recording_surface_t *surface; + + surface = malloc (sizeof (cairo_recording_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &cairo_recording_surface_backend, + NULL, /* device */ + content); + + + surface->unbounded = TRUE; + + /* unbounded -> 'infinite' extents */ + if (extents != NULL) { + surface->extents_pixels = *extents; + + /* XXX check for overflow */ + surface->extents.x = floor (extents->x); + surface->extents.y = floor (extents->y); + surface->extents.width = ceil (extents->x + extents->width) - surface->extents.x; + surface->extents.height = ceil (extents->y + extents->height) - surface->extents.y; + + surface->unbounded = FALSE; + } + + _cairo_array_init (&surface->commands, sizeof (cairo_command_t *)); + + surface->base.is_clear = TRUE; + + surface->bbtree.left = surface->bbtree.right = NULL; + surface->bbtree.chain = INVALID_CHAIN; + + surface->indices = NULL; + surface->num_indices = 0; + surface->optimize_clears = TRUE; + surface->has_bilevel_alpha = FALSE; + surface->has_only_op_over = FALSE; + + return &surface->base; +} +slim_hidden_def (cairo_recording_surface_create); + +static cairo_surface_t * +_cairo_recording_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_rectangle_t extents; + extents.x = extents.y = 0; + extents.width = width; + extents.height = height; + return cairo_recording_surface_create (content, &extents); +} + +static cairo_status_t +_cairo_recording_surface_finish (void *abstract_surface) +{ + cairo_recording_surface_t *surface = abstract_surface; + cairo_command_t **elements; + int i, num_elements; + + num_elements = surface->commands.num_elements; + elements = _cairo_array_index (&surface->commands, 0); + for (i = 0; i < num_elements; i++) { + cairo_command_t *command = elements[i]; + + switch (command->header.type) { + case CAIRO_COMMAND_PAINT: + _cairo_pattern_fini (&command->paint.source.base); + break; + + case CAIRO_COMMAND_MASK: + _cairo_pattern_fini (&command->mask.source.base); + _cairo_pattern_fini (&command->mask.mask.base); + break; + + case CAIRO_COMMAND_STROKE: + _cairo_pattern_fini (&command->stroke.source.base); + _cairo_path_fixed_fini (&command->stroke.path); + _cairo_stroke_style_fini (&command->stroke.style); + break; + + case CAIRO_COMMAND_FILL: + _cairo_pattern_fini (&command->fill.source.base); + _cairo_path_fixed_fini (&command->fill.path); + break; + + case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: + _cairo_pattern_fini (&command->show_text_glyphs.source.base); + free (command->show_text_glyphs.utf8); + free (command->show_text_glyphs.glyphs); + free (command->show_text_glyphs.clusters); + cairo_scaled_font_destroy (command->show_text_glyphs.scaled_font); + break; + + default: + ASSERT_NOT_REACHED; + } + + _cairo_clip_destroy (command->header.clip); + free (command); + } + + _cairo_array_fini (&surface->commands); + + if (surface->bbtree.left) + bbtree_del (surface->bbtree.left); + if (surface->bbtree.right) + bbtree_del (surface->bbtree.right); + + free (surface->indices); + + return CAIRO_STATUS_SUCCESS; +} + +struct proxy { + cairo_surface_t base; + cairo_surface_t *image; +}; + +static cairo_status_t +proxy_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + struct proxy *proxy = abstract_surface; + return _cairo_surface_acquire_source_image (proxy->image, image_out, image_extra); +} + +static void +proxy_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + struct proxy *proxy = abstract_surface; + _cairo_surface_release_source_image (proxy->image, image, image_extra); +} + +static cairo_status_t +proxy_finish (void *abstract_surface) +{ + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t proxy_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_NULL, + proxy_finish, + NULL, + + NULL, /* create similar */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + proxy_acquire_source_image, + proxy_release_source_image, +}; + +static cairo_surface_t * +attach_proxy (cairo_surface_t *source, + cairo_surface_t *image) +{ + struct proxy *proxy; + + proxy = malloc (sizeof (*proxy)); + if (unlikely (proxy == NULL)) + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_surface_init (&proxy->base, &proxy_backend, NULL, image->content); + + proxy->image = image; + _cairo_surface_attach_snapshot (source, &proxy->base, NULL); + + return &proxy->base; +} + +static void +detach_proxy (cairo_surface_t *source, + cairo_surface_t *proxy) +{ + cairo_surface_finish (proxy); + cairo_surface_destroy (proxy); +} + +static cairo_surface_t * +get_proxy (cairo_surface_t *proxy) +{ + return ((struct proxy *)proxy)->image; +} + +static cairo_status_t +_cairo_recording_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_recording_surface_t *surface = abstract_surface; + cairo_surface_t *image, *proxy; + cairo_status_t status; + + proxy = _cairo_surface_has_snapshot (abstract_surface, &proxy_backend); + if (proxy != NULL) { + *image_out = (cairo_image_surface_t *) + cairo_surface_reference (get_proxy (proxy)); + *image_extra = NULL; + return CAIRO_STATUS_SUCCESS; + } + + assert (! surface->unbounded); + image = _cairo_image_surface_create_with_content (surface->base.content, + surface->extents.width, + surface->extents.height); + if (unlikely (image->status)) + return image->status; + + /* Handle recursion by returning future reads from the current image */ + proxy = attach_proxy (abstract_surface, image); + status = _cairo_recording_surface_replay (&surface->base, image); + detach_proxy (abstract_surface, proxy); + + if (unlikely (status)) { + cairo_surface_destroy (image); + return status; + } + + *image_out = (cairo_image_surface_t *) image; + *image_extra = NULL; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_recording_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); +} + +static cairo_status_t +_command_init (cairo_recording_surface_t *surface, + cairo_command_header_t *command, + cairo_command_type_t type, + cairo_operator_t op, + cairo_composite_rectangles_t *composite) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + command->type = type; + command->op = op; + command->region = CAIRO_RECORDING_REGION_ALL; + + command->extents = composite->unbounded; + command->chain = NULL; + command->index = surface->commands.num_elements; + + /* steal the clip */ + command->clip = NULL; + if (! _cairo_composite_rectangles_can_reduce_clip (composite, + composite->clip)) + { + command->clip = composite->clip; + composite->clip = NULL; + } + + return status; +} + +static void +_cairo_recording_surface_break_self_copy_loop (cairo_recording_surface_t *surface) +{ + cairo_surface_flush (&surface->base); +} + +static cairo_status_t +_cairo_recording_surface_commit (cairo_recording_surface_t *surface, + cairo_command_header_t *command) +{ + _cairo_recording_surface_break_self_copy_loop (surface); + return _cairo_array_append (&surface->commands, &command); +} + +static void +_cairo_recording_surface_reset (cairo_recording_surface_t *surface) +{ + /* Reset the commands and temporaries */ + _cairo_recording_surface_finish (surface); + + surface->bbtree.left = surface->bbtree.right = NULL; + surface->bbtree.chain = INVALID_CHAIN; + + surface->indices = NULL; + surface->num_indices = 0; + + _cairo_array_init (&surface->commands, sizeof (cairo_command_t *)); +} + +static cairo_bool_t +is_identity_recording_pattern (const cairo_pattern_t *pattern) +{ + cairo_surface_t *surface; + + if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) + return FALSE; + + if (!_cairo_matrix_is_identity(&pattern->matrix)) + return FALSE; + + surface = ((cairo_surface_pattern_t *)pattern)->surface; + return surface->backend->type == CAIRO_SURFACE_TYPE_RECORDING; +} + +static cairo_int_status_t +_cairo_recording_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_recording_surface_t *surface = abstract_surface; + cairo_command_paint_t *command; + cairo_composite_rectangles_t composite; + + TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); + + if (op == CAIRO_OPERATOR_CLEAR && clip == NULL) { + if (surface->optimize_clears) { + _cairo_recording_surface_reset (surface); + return CAIRO_STATUS_SUCCESS; + } + } + + if (clip == NULL && surface->optimize_clears && + (op == CAIRO_OPERATOR_SOURCE || + (op == CAIRO_OPERATOR_OVER && + (surface->base.is_clear || _cairo_pattern_is_opaque_solid (source))))) + { + _cairo_recording_surface_reset (surface); + if (is_identity_recording_pattern (source)) { + cairo_surface_t *src = ((cairo_surface_pattern_t *)source)->surface; + return _cairo_recording_surface_replay (src, &surface->base); + } + } + + status = _cairo_composite_rectangles_init_for_paint (&composite, + &surface->base, + op, source, + clip); + if (unlikely (status)) + return status; + + command = malloc (sizeof (cairo_command_paint_t)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_COMPOSITE; + } + + status = _command_init (surface, + &command->header, CAIRO_COMMAND_PAINT, op, + &composite); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_pattern_init_snapshot (&command->source.base, source); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto CLEANUP_SOURCE; + + _cairo_recording_surface_destroy_bbtree (surface); + + _cairo_composite_rectangles_fini (&composite); + return CAIRO_STATUS_SUCCESS; + + CLEANUP_SOURCE: + _cairo_pattern_fini (&command->source.base); + CLEANUP_COMMAND: + _cairo_clip_destroy (command->header.clip); + free (command); +CLEANUP_COMPOSITE: + _cairo_composite_rectangles_fini (&composite); + return status; +} + +static cairo_int_status_t +_cairo_recording_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_recording_surface_t *surface = abstract_surface; + cairo_command_mask_t *command; + cairo_composite_rectangles_t composite; + + TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); + + status = _cairo_composite_rectangles_init_for_mask (&composite, + &surface->base, + op, source, mask, + clip); + if (unlikely (status)) + return status; + + command = malloc (sizeof (cairo_command_mask_t)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_COMPOSITE; + } + + status = _command_init (surface, + &command->header, CAIRO_COMMAND_MASK, op, + &composite); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_pattern_init_snapshot (&command->source.base, source); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_pattern_init_snapshot (&command->mask.base, mask); + if (unlikely (status)) + goto CLEANUP_SOURCE; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto CLEANUP_MASK; + + _cairo_recording_surface_destroy_bbtree (surface); + + _cairo_composite_rectangles_fini (&composite); + return CAIRO_STATUS_SUCCESS; + + CLEANUP_MASK: + _cairo_pattern_fini (&command->mask.base); + CLEANUP_SOURCE: + _cairo_pattern_fini (&command->source.base); + CLEANUP_COMMAND: + _cairo_clip_destroy (command->header.clip); + free (command); +CLEANUP_COMPOSITE: + _cairo_composite_rectangles_fini (&composite); + return status; +} + +static cairo_int_status_t +_cairo_recording_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_recording_surface_t *surface = abstract_surface; + cairo_command_stroke_t *command; + cairo_composite_rectangles_t composite; + + TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); + + status = _cairo_composite_rectangles_init_for_stroke (&composite, + &surface->base, + op, source, + path, style, ctm, + clip); + if (unlikely (status)) + return status; + + command = malloc (sizeof (cairo_command_stroke_t)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_COMPOSITE; + } + + status = _command_init (surface, + &command->header, CAIRO_COMMAND_STROKE, op, + &composite); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_pattern_init_snapshot (&command->source.base, source); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_path_fixed_init_copy (&command->path, path); + if (unlikely (status)) + goto CLEANUP_SOURCE; + + status = _cairo_stroke_style_init_copy (&command->style, style); + if (unlikely (status)) + goto CLEANUP_PATH; + + command->ctm = *ctm; + command->ctm_inverse = *ctm_inverse; + command->tolerance = tolerance; + command->antialias = antialias; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto CLEANUP_STYLE; + + _cairo_recording_surface_destroy_bbtree (surface); + + _cairo_composite_rectangles_fini (&composite); + return CAIRO_STATUS_SUCCESS; + + CLEANUP_STYLE: + _cairo_stroke_style_fini (&command->style); + CLEANUP_PATH: + _cairo_path_fixed_fini (&command->path); + CLEANUP_SOURCE: + _cairo_pattern_fini (&command->source.base); + CLEANUP_COMMAND: + _cairo_clip_destroy (command->header.clip); + free (command); +CLEANUP_COMPOSITE: + _cairo_composite_rectangles_fini (&composite); + return status; +} + +static cairo_int_status_t +_cairo_recording_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_recording_surface_t *surface = abstract_surface; + cairo_command_fill_t *command; + cairo_composite_rectangles_t composite; + + TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); + + status = _cairo_composite_rectangles_init_for_fill (&composite, + &surface->base, + op, source, path, + clip); + if (unlikely (status)) + return status; + + command = malloc (sizeof (cairo_command_fill_t)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_COMPOSITE; + } + + status =_command_init (surface, + &command->header, CAIRO_COMMAND_FILL, op, + &composite); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_pattern_init_snapshot (&command->source.base, source); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_path_fixed_init_copy (&command->path, path); + if (unlikely (status)) + goto CLEANUP_SOURCE; + + command->fill_rule = fill_rule; + command->tolerance = tolerance; + command->antialias = antialias; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto CLEANUP_PATH; + + _cairo_recording_surface_destroy_bbtree (surface); + + _cairo_composite_rectangles_fini (&composite); + return CAIRO_STATUS_SUCCESS; + + CLEANUP_PATH: + _cairo_path_fixed_fini (&command->path); + CLEANUP_SOURCE: + _cairo_pattern_fini (&command->source.base); + CLEANUP_COMMAND: + _cairo_clip_destroy (command->header.clip); + free (command); +CLEANUP_COMPOSITE: + _cairo_composite_rectangles_fini (&composite); + return status; +} + +static cairo_bool_t +_cairo_recording_surface_has_show_text_glyphs (void *abstract_surface) +{ + return TRUE; +} + +static cairo_int_status_t +_cairo_recording_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_recording_surface_t *surface = abstract_surface; + cairo_command_show_text_glyphs_t *command; + cairo_composite_rectangles_t composite; + + TRACE ((stderr, "%s: surface=%d\n", __FUNCTION__, surface->base.unique_id)); + + status = _cairo_composite_rectangles_init_for_glyphs (&composite, + &surface->base, + op, source, + scaled_font, + glyphs, num_glyphs, + clip, + NULL); + if (unlikely (status)) + return status; + + command = malloc (sizeof (cairo_command_show_text_glyphs_t)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_COMPOSITE; + } + + status = _command_init (surface, + &command->header, CAIRO_COMMAND_SHOW_TEXT_GLYPHS, + op, &composite); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + status = _cairo_pattern_init_snapshot (&command->source.base, source); + if (unlikely (status)) + goto CLEANUP_COMMAND; + + command->utf8 = NULL; + command->utf8_len = utf8_len; + command->glyphs = NULL; + command->num_glyphs = num_glyphs; + command->clusters = NULL; + command->num_clusters = num_clusters; + + if (utf8_len) { + command->utf8 = malloc (utf8_len); + if (unlikely (command->utf8 == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_ARRAYS; + } + memcpy (command->utf8, utf8, utf8_len); + } + if (num_glyphs) { + command->glyphs = _cairo_malloc_ab (num_glyphs, sizeof (glyphs[0])); + if (unlikely (command->glyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_ARRAYS; + } + memcpy (command->glyphs, glyphs, sizeof (glyphs[0]) * num_glyphs); + } + if (num_clusters) { + command->clusters = _cairo_malloc_ab (num_clusters, sizeof (clusters[0])); + if (unlikely (command->clusters == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_ARRAYS; + } + memcpy (command->clusters, clusters, sizeof (clusters[0]) * num_clusters); + } + + command->cluster_flags = cluster_flags; + + command->scaled_font = cairo_scaled_font_reference (scaled_font); + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto CLEANUP_SCALED_FONT; + + _cairo_composite_rectangles_fini (&composite); + return CAIRO_STATUS_SUCCESS; + + CLEANUP_SCALED_FONT: + cairo_scaled_font_destroy (command->scaled_font); + CLEANUP_ARRAYS: + free (command->utf8); + free (command->glyphs); + free (command->clusters); + + _cairo_pattern_fini (&command->source.base); + CLEANUP_COMMAND: + _cairo_clip_destroy (command->header.clip); + free (command); +CLEANUP_COMPOSITE: + _cairo_composite_rectangles_fini (&composite); + return status; +} + +static void +_command_init_copy (cairo_recording_surface_t *surface, + cairo_command_header_t *dst, + const cairo_command_header_t *src) +{ + dst->type = src->type; + dst->op = src->op; + dst->region = CAIRO_RECORDING_REGION_ALL; + + dst->extents = src->extents; + dst->chain = NULL; + dst->index = surface->commands.num_elements; + + dst->clip = _cairo_clip_copy (src->clip); +} + +static cairo_status_t +_cairo_recording_surface_copy__paint (cairo_recording_surface_t *surface, + const cairo_command_t *src) +{ + cairo_command_paint_t *command; + cairo_status_t status; + + command = malloc (sizeof (*command)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err; + } + + _command_init_copy (surface, &command->header, &src->header); + + status = _cairo_pattern_init_copy (&command->source.base, + &src->paint.source.base); + if (unlikely (status)) + goto err_command; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto err_source; + + return CAIRO_STATUS_SUCCESS; + +err_source: + _cairo_pattern_fini (&command->source.base); +err_command: + free(command); +err: + return status; +} + +static cairo_status_t +_cairo_recording_surface_copy__mask (cairo_recording_surface_t *surface, + const cairo_command_t *src) +{ + cairo_command_mask_t *command; + cairo_status_t status; + + command = malloc (sizeof (*command)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err; + } + + _command_init_copy (surface, &command->header, &src->header); + + status = _cairo_pattern_init_copy (&command->source.base, + &src->mask.source.base); + if (unlikely (status)) + goto err_command; + + status = _cairo_pattern_init_copy (&command->mask.base, + &src->mask.mask.base); + if (unlikely (status)) + goto err_source; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto err_mask; + + return CAIRO_STATUS_SUCCESS; + +err_mask: + _cairo_pattern_fini (&command->mask.base); +err_source: + _cairo_pattern_fini (&command->source.base); +err_command: + free(command); +err: + return status; +} + +static cairo_status_t +_cairo_recording_surface_copy__stroke (cairo_recording_surface_t *surface, + const cairo_command_t *src) +{ + cairo_command_stroke_t *command; + cairo_status_t status; + + command = malloc (sizeof (*command)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err; + } + + _command_init_copy (surface, &command->header, &src->header); + + status = _cairo_pattern_init_copy (&command->source.base, + &src->stroke.source.base); + if (unlikely (status)) + goto err_command; + + status = _cairo_path_fixed_init_copy (&command->path, &src->stroke.path); + if (unlikely (status)) + goto err_source; + + status = _cairo_stroke_style_init_copy (&command->style, + &src->stroke.style); + if (unlikely (status)) + goto err_path; + + command->ctm = src->stroke.ctm; + command->ctm_inverse = src->stroke.ctm_inverse; + command->tolerance = src->stroke.tolerance; + command->antialias = src->stroke.antialias; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto err_style; + + return CAIRO_STATUS_SUCCESS; + +err_style: + _cairo_stroke_style_fini (&command->style); +err_path: + _cairo_path_fixed_fini (&command->path); +err_source: + _cairo_pattern_fini (&command->source.base); +err_command: + free(command); +err: + return status; +} + +static cairo_status_t +_cairo_recording_surface_copy__fill (cairo_recording_surface_t *surface, + const cairo_command_t *src) +{ + cairo_command_fill_t *command; + cairo_status_t status; + + command = malloc (sizeof (*command)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err; + } + + _command_init_copy (surface, &command->header, &src->header); + + status = _cairo_pattern_init_copy (&command->source.base, + &src->fill.source.base); + if (unlikely (status)) + goto err_command; + + status = _cairo_path_fixed_init_copy (&command->path, &src->fill.path); + if (unlikely (status)) + goto err_source; + + command->fill_rule = src->fill.fill_rule; + command->tolerance = src->fill.tolerance; + command->antialias = src->fill.antialias; + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto err_path; + + return CAIRO_STATUS_SUCCESS; + +err_path: + _cairo_path_fixed_fini (&command->path); +err_source: + _cairo_pattern_fini (&command->source.base); +err_command: + free(command); +err: + return status; +} + +static cairo_status_t +_cairo_recording_surface_copy__glyphs (cairo_recording_surface_t *surface, + const cairo_command_t *src) +{ + cairo_command_show_text_glyphs_t *command; + cairo_status_t status; + + command = malloc (sizeof (*command)); + if (unlikely (command == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err; + } + + _command_init_copy (surface, &command->header, &src->header); + + status = _cairo_pattern_init_copy (&command->source.base, + &src->show_text_glyphs.source.base); + if (unlikely (status)) + goto err_command; + + command->utf8 = NULL; + command->utf8_len = src->show_text_glyphs.utf8_len; + command->glyphs = NULL; + command->num_glyphs = src->show_text_glyphs.num_glyphs; + command->clusters = NULL; + command->num_clusters = src->show_text_glyphs.num_clusters; + + if (command->utf8_len) { + command->utf8 = malloc (command->utf8_len); + if (unlikely (command->utf8 == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err_arrays; + } + memcpy (command->utf8, src->show_text_glyphs.utf8, command->utf8_len); + } + if (command->num_glyphs) { + command->glyphs = _cairo_malloc_ab (command->num_glyphs, + sizeof (command->glyphs[0])); + if (unlikely (command->glyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err_arrays; + } + memcpy (command->glyphs, src->show_text_glyphs.glyphs, + sizeof (command->glyphs[0]) * command->num_glyphs); + } + if (command->num_clusters) { + command->clusters = _cairo_malloc_ab (command->num_clusters, + sizeof (command->clusters[0])); + if (unlikely (command->clusters == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto err_arrays; + } + memcpy (command->clusters, src->show_text_glyphs.clusters, + sizeof (command->clusters[0]) * command->num_clusters); + } + + command->cluster_flags = src->show_text_glyphs.cluster_flags; + + command->scaled_font = + cairo_scaled_font_reference (src->show_text_glyphs.scaled_font); + + status = _cairo_recording_surface_commit (surface, &command->header); + if (unlikely (status)) + goto err_arrays; + + return CAIRO_STATUS_SUCCESS; + +err_arrays: + free (command->utf8); + free (command->glyphs); + free (command->clusters); + _cairo_pattern_fini (&command->source.base); +err_command: + free(command); +err: + return status; +} + +static cairo_status_t +_cairo_recording_surface_copy (cairo_recording_surface_t *dst, + cairo_recording_surface_t *src) +{ + cairo_command_t **elements; + int i, num_elements; + cairo_status_t status; + + elements = _cairo_array_index (&src->commands, 0); + num_elements = src->commands.num_elements; + for (i = 0; i < num_elements; i++) { + const cairo_command_t *command = elements[i]; + + switch (command->header.type) { + case CAIRO_COMMAND_PAINT: + status = _cairo_recording_surface_copy__paint (dst, command); + break; + + case CAIRO_COMMAND_MASK: + status = _cairo_recording_surface_copy__mask (dst, command); + break; + + case CAIRO_COMMAND_STROKE: + status = _cairo_recording_surface_copy__stroke (dst, command); + break; + + case CAIRO_COMMAND_FILL: + status = _cairo_recording_surface_copy__fill (dst, command); + break; + + case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: + status = _cairo_recording_surface_copy__glyphs (dst, command); + break; + + default: + ASSERT_NOT_REACHED; + } + + if (unlikely (status)) + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_recording_surface_snapshot: + * @surface: a #cairo_surface_t which must be a recording surface + * + * Make an immutable copy of @surface. It is an error to call a + * surface-modifying function on the result of this function. + * + * The caller owns the return value and should call + * cairo_surface_destroy() when finished with it. This function will not + * return %NULL, but will return a nil surface instead. + * + * Return value: The snapshot surface. + **/ +static cairo_surface_t * +_cairo_recording_surface_snapshot (void *abstract_other) +{ + cairo_recording_surface_t *other = abstract_other; + cairo_recording_surface_t *surface; + cairo_status_t status; + + surface = malloc (sizeof (cairo_recording_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &cairo_recording_surface_backend, + NULL, /* device */ + other->base.content); + + surface->extents_pixels = other->extents_pixels; + surface->extents = other->extents; + surface->unbounded = other->unbounded; + + surface->base.is_clear = other->base.is_clear; + + surface->bbtree.left = surface->bbtree.right = NULL; + surface->bbtree.chain = INVALID_CHAIN; + + surface->indices = NULL; + surface->num_indices = 0; + surface->optimize_clears = TRUE; + + _cairo_array_init (&surface->commands, sizeof (cairo_command_t *)); + status = _cairo_recording_surface_copy (surface, other); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return _cairo_surface_create_in_error (status); + } + + return &surface->base; +} + +static cairo_bool_t +_cairo_recording_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_recording_surface_t *surface = abstract_surface; + + if (surface->unbounded) + return FALSE; + + *rectangle = surface->extents; + return TRUE; +} + +static const cairo_surface_backend_t cairo_recording_surface_backend = { + CAIRO_SURFACE_TYPE_RECORDING, + _cairo_recording_surface_finish, + + _cairo_default_context_create, + + _cairo_recording_surface_create_similar, + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + _cairo_recording_surface_acquire_source_image, + _cairo_recording_surface_release_source_image, + _cairo_recording_surface_snapshot, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_recording_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + /* Here are the 5 basic drawing operations, (which are in some + * sense the only things that cairo_recording_surface should need to + * implement). However, we implement the more generic show_text_glyphs + * instead of show_glyphs. One or the other is eough. */ + + _cairo_recording_surface_paint, + _cairo_recording_surface_mask, + _cairo_recording_surface_stroke, + _cairo_recording_surface_fill, + NULL, /* fill-stroke */ + NULL, + _cairo_recording_surface_has_show_text_glyphs, + _cairo_recording_surface_show_text_glyphs, +}; + +cairo_int_status_t +_cairo_recording_surface_get_path (cairo_surface_t *abstract_surface, + cairo_path_fixed_t *path) +{ + cairo_recording_surface_t *surface; + cairo_command_t **elements; + int i, num_elements; + cairo_int_status_t status; + + if (unlikely (abstract_surface->status)) + return abstract_surface->status; + + surface = (cairo_recording_surface_t *) abstract_surface; + status = CAIRO_STATUS_SUCCESS; + + num_elements = surface->commands.num_elements; + elements = _cairo_array_index (&surface->commands, 0); + for (i = 0; i < num_elements; i++) { + cairo_command_t *command = elements[i]; + + switch (command->header.type) { + case CAIRO_COMMAND_PAINT: + case CAIRO_COMMAND_MASK: + status = CAIRO_INT_STATUS_UNSUPPORTED; + break; + + case CAIRO_COMMAND_STROKE: + { + cairo_traps_t traps; + + _cairo_traps_init (&traps); + + /* XXX call cairo_stroke_to_path() when that is implemented */ + status = _cairo_path_fixed_stroke_polygon_to_traps (&command->stroke.path, + &command->stroke.style, + &command->stroke.ctm, + &command->stroke.ctm_inverse, + command->stroke.tolerance, + &traps); + + if (status == CAIRO_INT_STATUS_SUCCESS) + status = _cairo_traps_path (&traps, path); + + _cairo_traps_fini (&traps); + break; + } + case CAIRO_COMMAND_FILL: + { + status = _cairo_path_fixed_append (path, + &command->fill.path, + 0, 0); + break; + } + case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: + { + status = _cairo_scaled_font_glyph_path (command->show_text_glyphs.scaled_font, + command->show_text_glyphs.glyphs, + command->show_text_glyphs.num_glyphs, + path); + break; + } + + default: + ASSERT_NOT_REACHED; + } + + if (unlikely (status)) + break; + } + + return status; +} + +static int +_cairo_recording_surface_get_visible_commands (cairo_recording_surface_t *surface, + const cairo_rectangle_int_t *extents) +{ + unsigned int num_visible, *indices; + cairo_box_t box; + + if (surface->commands.num_elements == 0) + return 0; + + _cairo_box_from_rectangle (&box, extents); + + if (surface->bbtree.chain == INVALID_CHAIN) + _cairo_recording_surface_create_bbtree (surface); + + indices = surface->indices; + bbtree_foreach_mark_visible (&surface->bbtree, &box, &indices); + num_visible = indices - surface->indices; + if (num_visible > 1) + sort_indices (surface->indices, num_visible); + + return num_visible; +} + +static void +_cairo_recording_surface_merge_source_attributes (cairo_recording_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source) +{ + if (op != CAIRO_OPERATOR_OVER) + surface->has_only_op_over = FALSE; + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *surf_pat = (cairo_surface_pattern_t *) source; + cairo_surface_t *surf = surf_pat->surface; + cairo_surface_t *free_me = NULL; + + if (_cairo_surface_is_snapshot (surf)) + free_me = surf = _cairo_surface_snapshot_get_target (surf); + + if (surf->type == CAIRO_SURFACE_TYPE_RECORDING) { + cairo_recording_surface_t *rec_surf = (cairo_recording_surface_t *) surf; + + if (! _cairo_recording_surface_has_only_bilevel_alpha (rec_surf)) + surface->has_bilevel_alpha = FALSE; + + if (! _cairo_recording_surface_has_only_op_over (rec_surf)) + surface->has_only_op_over = FALSE; + + } else if (surf->type == CAIRO_SURFACE_TYPE_IMAGE) { + cairo_image_surface_t *img_surf = (cairo_image_surface_t *) surf; + + if (_cairo_image_analyze_transparency (img_surf) == CAIRO_IMAGE_HAS_ALPHA) + surface->has_bilevel_alpha = FALSE; + + } else { + if (!_cairo_pattern_is_clear (source) && !_cairo_pattern_is_opaque (source, NULL)) + surface->has_bilevel_alpha = FALSE; + } + + cairo_surface_destroy (free_me); + return; + + } else if (source->type == CAIRO_PATTERN_TYPE_RASTER_SOURCE) { + cairo_surface_t *image; + cairo_surface_t *raster; + + image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); + raster = _cairo_raster_source_pattern_acquire (source, image, NULL); + cairo_surface_destroy (image); + if (raster) { + if (raster->type == CAIRO_SURFACE_TYPE_IMAGE) { + if (_cairo_image_analyze_transparency ((cairo_image_surface_t *)raster) == CAIRO_IMAGE_HAS_ALPHA) + surface->has_bilevel_alpha = FALSE; + } + + _cairo_raster_source_pattern_release (source, raster); + if (raster->type == CAIRO_SURFACE_TYPE_IMAGE) + return; + } + } + + if (!_cairo_pattern_is_clear (source) && !_cairo_pattern_is_opaque (source, NULL)) + surface->has_bilevel_alpha = FALSE; +} + +static cairo_status_t +_cairo_recording_surface_replay_internal (cairo_recording_surface_t *surface, + const cairo_rectangle_int_t *surface_extents, + const cairo_matrix_t *surface_transform, + cairo_surface_t *target, + const cairo_clip_t *target_clip, + cairo_recording_replay_type_t type, + cairo_recording_region_type_t region) +{ + cairo_surface_wrapper_t wrapper; + cairo_command_t **elements; + cairo_bool_t replay_all = + type == CAIRO_RECORDING_REPLAY && + region == CAIRO_RECORDING_REGION_ALL; + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + cairo_rectangle_int_t extents; + cairo_bool_t use_indices = FALSE; + const cairo_rectangle_int_t *r; + unsigned int i, num_elements; + + if (unlikely (surface->base.status)) + return surface->base.status; + + if (unlikely (target->status)) + return target->status; + + if (unlikely (surface->base.finished)) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + if (surface->base.is_clear) + return CAIRO_STATUS_SUCCESS; + + assert (_cairo_surface_is_recording (&surface->base)); + + _cairo_surface_wrapper_init (&wrapper, target); + if (surface_extents) + _cairo_surface_wrapper_intersect_extents (&wrapper, surface_extents); + r = &_cairo_unbounded_rectangle; + if (! surface->unbounded) { + _cairo_surface_wrapper_intersect_extents (&wrapper, &surface->extents); + r = &surface->extents; + } + _cairo_surface_wrapper_set_inverse_transform (&wrapper, surface_transform); + _cairo_surface_wrapper_set_clip (&wrapper, target_clip); + + /* Compute the extents of the target clip in recorded device space */ + if (! _cairo_surface_wrapper_get_target_extents (&wrapper, &extents)) + goto done; + + surface->has_bilevel_alpha = TRUE; + surface->has_only_op_over = TRUE; + + num_elements = surface->commands.num_elements; + elements = _cairo_array_index (&surface->commands, 0); + if (extents.width < r->width || extents.height < r->height) { + num_elements = + _cairo_recording_surface_get_visible_commands (surface, &extents); + use_indices = num_elements != surface->commands.num_elements; + } + + for (i = 0; i < num_elements; i++) { + cairo_command_t *command = elements[use_indices ? surface->indices[i] : i]; + + if (! replay_all && command->header.region != region) + continue; + + if (! _cairo_rectangle_intersects (&extents, &command->header.extents)) + continue; + + switch (command->header.type) { + case CAIRO_COMMAND_PAINT: + status = _cairo_surface_wrapper_paint (&wrapper, + command->header.op, + &command->paint.source.base, + command->header.clip); + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->paint.source.base); + } + break; + + case CAIRO_COMMAND_MASK: + status = _cairo_surface_wrapper_mask (&wrapper, + command->header.op, + &command->mask.source.base, + &command->mask.mask.base, + command->header.clip); + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->mask.source.base); + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->mask.mask.base); + } + break; + + case CAIRO_COMMAND_STROKE: + status = _cairo_surface_wrapper_stroke (&wrapper, + command->header.op, + &command->stroke.source.base, + &command->stroke.path, + &command->stroke.style, + &command->stroke.ctm, + &command->stroke.ctm_inverse, + command->stroke.tolerance, + command->stroke.antialias, + command->header.clip); + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->stroke.source.base); + } + break; + + case CAIRO_COMMAND_FILL: + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_surface_wrapper_has_fill_stroke (&wrapper)) { + cairo_command_t *stroke_command; + + stroke_command = NULL; + if (type != CAIRO_RECORDING_CREATE_REGIONS && i < num_elements - 1) + stroke_command = elements[i + 1]; + + if (stroke_command != NULL && + type == CAIRO_RECORDING_REPLAY && + region != CAIRO_RECORDING_REGION_ALL) + { + if (stroke_command->header.region != region) + stroke_command = NULL; + } + + if (stroke_command != NULL && + stroke_command->header.type == CAIRO_COMMAND_STROKE && + _cairo_path_fixed_equal (&command->fill.path, + &stroke_command->stroke.path) && + _cairo_clip_equal (command->header.clip, + stroke_command->header.clip)) + { + status = _cairo_surface_wrapper_fill_stroke (&wrapper, + command->header.op, + &command->fill.source.base, + command->fill.fill_rule, + command->fill.tolerance, + command->fill.antialias, + &command->fill.path, + stroke_command->header.op, + &stroke_command->stroke.source.base, + &stroke_command->stroke.style, + &stroke_command->stroke.ctm, + &stroke_command->stroke.ctm_inverse, + stroke_command->stroke.tolerance, + stroke_command->stroke.antialias, + command->header.clip); + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->fill.source.base); + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->stroke.source.base); + } + i++; + } + } + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = _cairo_surface_wrapper_fill (&wrapper, + command->header.op, + &command->fill.source.base, + &command->fill.path, + command->fill.fill_rule, + command->fill.tolerance, + command->fill.antialias, + command->header.clip); + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->fill.source.base); + } + } + break; + + case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: + status = _cairo_surface_wrapper_show_text_glyphs (&wrapper, + command->header.op, + &command->show_text_glyphs.source.base, + command->show_text_glyphs.utf8, command->show_text_glyphs.utf8_len, + command->show_text_glyphs.glyphs, command->show_text_glyphs.num_glyphs, + command->show_text_glyphs.clusters, command->show_text_glyphs.num_clusters, + command->show_text_glyphs.cluster_flags, + command->show_text_glyphs.scaled_font, + command->header.clip); + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + _cairo_recording_surface_merge_source_attributes (surface, + command->header.op, + &command->show_text_glyphs.source.base); + } + break; + + default: + ASSERT_NOT_REACHED; + } + + if (type == CAIRO_RECORDING_CREATE_REGIONS) { + if (status == CAIRO_INT_STATUS_SUCCESS) { + command->header.region = CAIRO_RECORDING_REGION_NATIVE; + } else if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) { + command->header.region = CAIRO_RECORDING_REGION_IMAGE_FALLBACK; + status = CAIRO_INT_STATUS_SUCCESS; + } else { + assert (_cairo_int_status_is_error (status)); + } + } + + if (unlikely (status)) + break; + } + +done: + _cairo_surface_wrapper_fini (&wrapper); + return _cairo_surface_set_error (&surface->base, status); +} + +cairo_status_t +_cairo_recording_surface_replay_one (cairo_recording_surface_t *surface, + long unsigned index, + cairo_surface_t *target) +{ + cairo_surface_wrapper_t wrapper; + cairo_command_t **elements, *command; + cairo_int_status_t status; + + if (unlikely (surface->base.status)) + return surface->base.status; + + if (unlikely (target->status)) + return target->status; + + if (unlikely (surface->base.finished)) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + assert (_cairo_surface_is_recording (&surface->base)); + + /* XXX + * Use a surface wrapper because we may want to do transformed + * replay in the future. + */ + _cairo_surface_wrapper_init (&wrapper, target); + + if (index > surface->commands.num_elements) + return _cairo_error (CAIRO_STATUS_READ_ERROR); + + elements = _cairo_array_index (&surface->commands, 0); + command = elements[index]; + switch (command->header.type) { + case CAIRO_COMMAND_PAINT: + status = _cairo_surface_wrapper_paint (&wrapper, + command->header.op, + &command->paint.source.base, + command->header.clip); + break; + + case CAIRO_COMMAND_MASK: + status = _cairo_surface_wrapper_mask (&wrapper, + command->header.op, + &command->mask.source.base, + &command->mask.mask.base, + command->header.clip); + break; + + case CAIRO_COMMAND_STROKE: + status = _cairo_surface_wrapper_stroke (&wrapper, + command->header.op, + &command->stroke.source.base, + &command->stroke.path, + &command->stroke.style, + &command->stroke.ctm, + &command->stroke.ctm_inverse, + command->stroke.tolerance, + command->stroke.antialias, + command->header.clip); + break; + + case CAIRO_COMMAND_FILL: + status = _cairo_surface_wrapper_fill (&wrapper, + command->header.op, + &command->fill.source.base, + &command->fill.path, + command->fill.fill_rule, + command->fill.tolerance, + command->fill.antialias, + command->header.clip); + break; + + case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: + status = _cairo_surface_wrapper_show_text_glyphs (&wrapper, + command->header.op, + &command->show_text_glyphs.source.base, + command->show_text_glyphs.utf8, command->show_text_glyphs.utf8_len, + command->show_text_glyphs.glyphs, command->show_text_glyphs.num_glyphs, + command->show_text_glyphs.clusters, command->show_text_glyphs.num_clusters, + command->show_text_glyphs.cluster_flags, + command->show_text_glyphs.scaled_font, + command->header.clip); + break; + + default: + ASSERT_NOT_REACHED; + } + + _cairo_surface_wrapper_fini (&wrapper); + return _cairo_surface_set_error (&surface->base, status); +} +/** + * _cairo_recording_surface_replay: + * @surface: the #cairo_recording_surface_t + * @target: a target #cairo_surface_t onto which to replay the operations + * @width_pixels: width of the surface, in pixels + * @height_pixels: height of the surface, in pixels + * + * A recording surface can be "replayed" against any target surface, + * after which the results in target will be identical to the results + * that would have been obtained if the original operations applied to + * the recording surface had instead been applied to the target surface. + **/ +cairo_status_t +_cairo_recording_surface_replay (cairo_surface_t *surface, + cairo_surface_t *target) +{ + return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, NULL, NULL, + target, NULL, + CAIRO_RECORDING_REPLAY, + CAIRO_RECORDING_REGION_ALL); +} + +cairo_status_t +_cairo_recording_surface_replay_with_clip (cairo_surface_t *surface, + const cairo_matrix_t *surface_transform, + cairo_surface_t *target, + const cairo_clip_t *target_clip) +{ + return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, NULL, surface_transform, + target, target_clip, + CAIRO_RECORDING_REPLAY, + CAIRO_RECORDING_REGION_ALL); +} + +/* Replay recording to surface. When the return status of each operation is + * one of %CAIRO_STATUS_SUCCESS, %CAIRO_INT_STATUS_UNSUPPORTED, or + * %CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY the status of each operation + * will be stored in the recording surface. Any other status will abort the + * replay and return the status. + */ +cairo_status_t +_cairo_recording_surface_replay_and_create_regions (cairo_surface_t *surface, + cairo_surface_t *target) +{ + return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, NULL, NULL, + target, NULL, + CAIRO_RECORDING_CREATE_REGIONS, + CAIRO_RECORDING_REGION_ALL); +} + +cairo_status_t +_cairo_recording_surface_replay_region (cairo_surface_t *surface, + const cairo_rectangle_int_t *surface_extents, + cairo_surface_t *target, + cairo_recording_region_type_t region) +{ + return _cairo_recording_surface_replay_internal ((cairo_recording_surface_t *) surface, + surface_extents, NULL, + target, NULL, + CAIRO_RECORDING_REPLAY, + region); +} + +static cairo_status_t +_recording_surface_get_ink_bbox (cairo_recording_surface_t *surface, + cairo_box_t *bbox, + const cairo_matrix_t *transform) +{ + cairo_surface_t *null_surface; + cairo_surface_t *analysis_surface; + cairo_status_t status; + + null_surface = _cairo_null_surface_create (surface->base.content); + analysis_surface = _cairo_analysis_surface_create (null_surface); + cairo_surface_destroy (null_surface); + + status = analysis_surface->status; + if (unlikely (status)) + return status; + + if (transform != NULL) + _cairo_analysis_surface_set_ctm (analysis_surface, transform); + + status = _cairo_recording_surface_replay (&surface->base, analysis_surface); + _cairo_analysis_surface_get_bounding_box (analysis_surface, bbox); + cairo_surface_destroy (analysis_surface); + + return status; +} + +/** + * cairo_recording_surface_ink_extents: + * @surface: a #cairo_recording_surface_t + * @x0: the x-coordinate of the top-left of the ink bounding box + * @y0: the y-coordinate of the top-left of the ink bounding box + * @width: the width of the ink bounding box + * @height: the height of the ink bounding box + * + * Measures the extents of the operations stored within the recording-surface. + * This is useful to compute the required size of an image surface (or + * equivalent) into which to replay the full sequence of drawing operations. + * + * Since: 1.10 + **/ +void +cairo_recording_surface_ink_extents (cairo_surface_t *surface, + double *x0, + double *y0, + double *width, + double *height) +{ + cairo_status_t status; + cairo_box_t bbox; + + memset (&bbox, 0, sizeof (bbox)); + + if (surface->status || ! _cairo_surface_is_recording (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + goto DONE; + } + + status = _recording_surface_get_ink_bbox ((cairo_recording_surface_t *) surface, + &bbox, + NULL); + if (unlikely (status)) + status = _cairo_surface_set_error (surface, status); + +DONE: + if (x0) + *x0 = _cairo_fixed_to_double (bbox.p1.x); + if (y0) + *y0 = _cairo_fixed_to_double (bbox.p1.y); + if (width) + *width = _cairo_fixed_to_double (bbox.p2.x - bbox.p1.x); + if (height) + *height = _cairo_fixed_to_double (bbox.p2.y - bbox.p1.y); +} + +cairo_status_t +_cairo_recording_surface_get_bbox (cairo_recording_surface_t *surface, + cairo_box_t *bbox, + const cairo_matrix_t *transform) +{ + if (! surface->unbounded) { + _cairo_box_from_rectangle (bbox, &surface->extents); + if (transform != NULL) + _cairo_matrix_transform_bounding_box_fixed (transform, bbox, NULL); + + return CAIRO_STATUS_SUCCESS; + } + + return _recording_surface_get_ink_bbox (surface, bbox, transform); +} + +cairo_status_t +_cairo_recording_surface_get_ink_bbox (cairo_recording_surface_t *surface, + cairo_box_t *bbox, + const cairo_matrix_t *transform) +{ + return _recording_surface_get_ink_bbox (surface, bbox, transform); +} + +/** + * cairo_recording_surface_get_extents: + * @surface: a #cairo_recording_surface_t + * @extents: the #cairo_rectangle_t to be assigned the extents + * + * Get the extents of the recording-surface. + * + * Return value: %TRUE if the surface is bounded, of recording type, and + * not in an error state, otherwise %FALSE + * + * Since: 1.12 + **/ +cairo_bool_t +cairo_recording_surface_get_extents (cairo_surface_t *surface, + cairo_rectangle_t *extents) +{ + cairo_recording_surface_t *record; + + if (surface->status || ! _cairo_surface_is_recording (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return FALSE; + } + + record = (cairo_recording_surface_t *)surface; + if (record->unbounded) + return FALSE; + + *extents = record->extents_pixels; + return TRUE; +} + +cairo_bool_t +_cairo_recording_surface_has_only_bilevel_alpha (cairo_recording_surface_t *surface) +{ + return surface->has_bilevel_alpha; +} + +cairo_bool_t +_cairo_recording_surface_has_only_op_over (cairo_recording_surface_t *surface) +{ + return surface->has_only_op_over; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-rectangle.c b/Build/source/libs/cairo/cairo-src/src/cairo-rectangle.c new file mode 100644 index 00000000000..2d51d7b10a4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-rectangle.c @@ -0,0 +1,299 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" + +const cairo_rectangle_int_t _cairo_empty_rectangle = { 0, 0, 0, 0 }; +const cairo_rectangle_int_t _cairo_unbounded_rectangle = { + CAIRO_RECT_INT_MIN, CAIRO_RECT_INT_MIN, + CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN, + CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN, +}; + +cairo_private void +_cairo_box_from_doubles (cairo_box_t *box, + double *x1, double *y1, + double *x2, double *y2) +{ + box->p1.x = _cairo_fixed_from_double (*x1); + box->p1.y = _cairo_fixed_from_double (*y1); + box->p2.x = _cairo_fixed_from_double (*x2); + box->p2.y = _cairo_fixed_from_double (*y2); +} + +cairo_private void +_cairo_box_to_doubles (const cairo_box_t *box, + double *x1, double *y1, + double *x2, double *y2) +{ + *x1 = _cairo_fixed_to_double (box->p1.x); + *y1 = _cairo_fixed_to_double (box->p1.y); + *x2 = _cairo_fixed_to_double (box->p2.x); + *y2 = _cairo_fixed_to_double (box->p2.y); +} + +void +_cairo_box_from_rectangle (cairo_box_t *box, + const cairo_rectangle_int_t *rect) +{ + box->p1.x = _cairo_fixed_from_int (rect->x); + box->p1.y = _cairo_fixed_from_int (rect->y); + box->p2.x = _cairo_fixed_from_int (rect->x + rect->width); + box->p2.y = _cairo_fixed_from_int (rect->y + rect->height); +} + +void +_cairo_boxes_get_extents (const cairo_box_t *boxes, + int num_boxes, + cairo_box_t *extents) +{ + assert (num_boxes > 0); + *extents = *boxes; + while (--num_boxes) + _cairo_box_add_box (extents, ++boxes); +} + +/* XXX We currently have a confusing mix of boxes and rectangles as + * exemplified by this function. A #cairo_box_t is a rectangular area + * represented by the coordinates of the upper left and lower right + * corners, expressed in fixed point numbers. A #cairo_rectangle_int_t is + * also a rectangular area, but represented by the upper left corner + * and the width and the height, as integer numbers. + * + * This function converts a #cairo_box_t to a #cairo_rectangle_int_t by + * increasing the area to the nearest integer coordinates. We should + * standardize on #cairo_rectangle_fixed_t and #cairo_rectangle_int_t, and + * this function could be renamed to the more reasonable + * _cairo_rectangle_fixed_round. + */ + +void +_cairo_box_round_to_rectangle (const cairo_box_t *box, + cairo_rectangle_int_t *rectangle) +{ + rectangle->x = _cairo_fixed_integer_floor (box->p1.x); + rectangle->y = _cairo_fixed_integer_floor (box->p1.y); + rectangle->width = _cairo_fixed_integer_ceil (box->p2.x) - rectangle->x; + rectangle->height = _cairo_fixed_integer_ceil (box->p2.y) - rectangle->y; +} + +cairo_bool_t +_cairo_rectangle_intersect (cairo_rectangle_int_t *dst, + const cairo_rectangle_int_t *src) +{ + int x1, y1, x2, y2; + + x1 = MAX (dst->x, src->x); + y1 = MAX (dst->y, src->y); + /* Beware the unsigned promotion, fortunately we have bits to spare + * as (CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN) < UINT_MAX + */ + x2 = MIN (dst->x + (int) dst->width, src->x + (int) src->width); + y2 = MIN (dst->y + (int) dst->height, src->y + (int) src->height); + + if (x1 >= x2 || y1 >= y2) { + dst->x = 0; + dst->y = 0; + dst->width = 0; + dst->height = 0; + + return FALSE; + } else { + dst->x = x1; + dst->y = y1; + dst->width = x2 - x1; + dst->height = y2 - y1; + + return TRUE; + } +} + +/* Extends the dst rectangle to also contain src. + * If one of the rectangles is empty, the result is undefined + */ +void +_cairo_rectangle_union (cairo_rectangle_int_t *dst, + const cairo_rectangle_int_t *src) +{ + int x1, y1, x2, y2; + + x1 = MIN (dst->x, src->x); + y1 = MIN (dst->y, src->y); + /* Beware the unsigned promotion, fortunately we have bits to spare + * as (CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN) < UINT_MAX + */ + x2 = MAX (dst->x + (int) dst->width, src->x + (int) src->width); + y2 = MAX (dst->y + (int) dst->height, src->y + (int) src->height); + + dst->x = x1; + dst->y = y1; + dst->width = x2 - x1; + dst->height = y2 - y1; +} + +#define P1x (line->p1.x) +#define P1y (line->p1.y) +#define P2x (line->p2.x) +#define P2y (line->p2.y) +#define B1x (box->p1.x) +#define B1y (box->p1.y) +#define B2x (box->p2.x) +#define B2y (box->p2.y) + +/* + * Check whether any part of line intersects box. This function essentially + * computes whether the ray starting at line->p1 in the direction of line->p2 + * intersects the box before it reaches p2. Normally, this is done + * by dividing by the lengths of the line projected onto each axis. Because + * we're in fixed point, this function does a bit more work to avoid having to + * do the division -- we don't care about the actual intersection point, so + * it's of no interest to us. + */ + +cairo_bool_t +_cairo_box_intersects_line_segment (const cairo_box_t *box, cairo_line_t *line) +{ + cairo_fixed_t t1=0, t2=0, t3=0, t4=0; + cairo_int64_t t1y, t2y, t3x, t4x; + + cairo_fixed_t xlen, ylen; + + if (_cairo_box_contains_point (box, &line->p1) || + _cairo_box_contains_point (box, &line->p2)) + return TRUE; + + xlen = P2x - P1x; + ylen = P2y - P1y; + + if (xlen) { + if (xlen > 0) { + t1 = B1x - P1x; + t2 = B2x - P1x; + } else { + t1 = P1x - B2x; + t2 = P1x - B1x; + xlen = - xlen; + } + + if ((t1 < 0 || t1 > xlen) && + (t2 < 0 || t2 > xlen)) + return FALSE; + } else { + /* Fully vertical line -- check that X is in bounds */ + if (P1x < B1x || P1x > B2x) + return FALSE; + } + + if (ylen) { + if (ylen > 0) { + t3 = B1y - P1y; + t4 = B2y - P1y; + } else { + t3 = P1y - B2y; + t4 = P1y - B1y; + ylen = - ylen; + } + + if ((t3 < 0 || t3 > ylen) && + (t4 < 0 || t4 > ylen)) + return FALSE; + } else { + /* Fully horizontal line -- check Y */ + if (P1y < B1y || P1y > B2y) + return FALSE; + } + + /* If we had a horizontal or vertical line, then it's already been checked */ + if (P1x == P2x || P1y == P2y) + return TRUE; + + /* Check overlap. Note that t1 < t2 and t3 < t4 here. */ + t1y = _cairo_int32x32_64_mul (t1, ylen); + t2y = _cairo_int32x32_64_mul (t2, ylen); + t3x = _cairo_int32x32_64_mul (t3, xlen); + t4x = _cairo_int32x32_64_mul (t4, xlen); + + if (_cairo_int64_lt(t1y, t4x) && + _cairo_int64_lt(t3x, t2y)) + return TRUE; + + return FALSE; +} + +static cairo_status_t +_cairo_box_add_spline_point (void *closure, + const cairo_point_t *point, + const cairo_slope_t *tangent) +{ + _cairo_box_add_point (closure, point); + + return CAIRO_STATUS_SUCCESS; +} + +/* assumes a has been previously added */ +void +_cairo_box_add_curve_to (cairo_box_t *extents, + const cairo_point_t *a, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + _cairo_box_add_point (extents, d); + if (!_cairo_box_contains_point (extents, b) || + !_cairo_box_contains_point (extents, c)) + { + cairo_status_t status; + + status = _cairo_spline_bound (_cairo_box_add_spline_point, + extents, a, b, c, d); + assert (status == CAIRO_STATUS_SUCCESS); + } +} + +void +_cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti, + const cairo_rectangle_t *rectf) +{ + recti->x = floor (rectf->x); + recti->y = floor (rectf->y); + recti->width = ceil (rectf->x + rectf->width) - floor (rectf->x); + recti->height = ceil (rectf->y + rectf->height) - floor (rectf->y); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-rectangular-scan-converter.c b/Build/source/libs/cairo/cairo-src/src/cairo-rectangular-scan-converter.c new file mode 100644 index 00000000000..e353b34e853 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-rectangular-scan-converter.c @@ -0,0 +1,791 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-combsort-inline.h" +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" +#include "cairo-list-private.h" +#include "cairo-spans-private.h" + +#include + +typedef struct _rectangle { + struct _rectangle *next, *prev; + cairo_fixed_t left, right; + cairo_fixed_t top, bottom; + int32_t top_y, bottom_y; + int dir; +} rectangle_t; + +#define UNROLL3(x) x x x + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +typedef struct _pqueue { + int size, max_size; + + rectangle_t **elements; + rectangle_t *elements_embedded[1024]; +} pqueue_t; + +typedef struct { + rectangle_t **start; + pqueue_t stop; + rectangle_t head, tail; + rectangle_t *insert_cursor; + int32_t current_y; + int32_t xmin, xmax; + + struct coverage { + struct cell { + struct cell *prev, *next; + int x, covered, uncovered; + } head, tail, *cursor; + unsigned int count; + cairo_freepool_t pool; + } coverage; + + cairo_half_open_span_t spans_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_half_open_span_t)]; + cairo_half_open_span_t *spans; + unsigned int num_spans; + unsigned int size_spans; + + jmp_buf jmpbuf; +} sweep_line_t; + +static inline int +rectangle_compare_start (const rectangle_t *a, + const rectangle_t *b) +{ + int cmp; + + cmp = a->top_y - b->top_y; + if (cmp) + return cmp; + + return a->left - b->left; +} + +static inline int +rectangle_compare_stop (const rectangle_t *a, + const rectangle_t *b) +{ + return a->bottom_y - b->bottom_y; +} + +static inline void +pqueue_init (pqueue_t *pq) +{ + pq->max_size = ARRAY_LENGTH (pq->elements_embedded); + pq->size = 0; + + pq->elements = pq->elements_embedded; + pq->elements[PQ_FIRST_ENTRY] = NULL; +} + +static inline void +pqueue_fini (pqueue_t *pq) +{ + if (pq->elements != pq->elements_embedded) + free (pq->elements); +} + +static cairo_bool_t +pqueue_grow (pqueue_t *pq) +{ + rectangle_t **new_elements; + pq->max_size *= 2; + + if (pq->elements == pq->elements_embedded) { + new_elements = _cairo_malloc_ab (pq->max_size, + sizeof (rectangle_t *)); + if (unlikely (new_elements == NULL)) + return FALSE; + + memcpy (new_elements, pq->elements_embedded, + sizeof (pq->elements_embedded)); + } else { + new_elements = _cairo_realloc_ab (pq->elements, + pq->max_size, + sizeof (rectangle_t *)); + if (unlikely (new_elements == NULL)) + return FALSE; + } + + pq->elements = new_elements; + return TRUE; +} + +static inline void +pqueue_push (sweep_line_t *sweep, rectangle_t *rectangle) +{ + rectangle_t **elements; + int i, parent; + + if (unlikely (sweep->stop.size + 1 == sweep->stop.max_size)) { + if (unlikely (! pqueue_grow (&sweep->stop))) + longjmp (sweep->jmpbuf, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + elements = sweep->stop.elements; + for (i = ++sweep->stop.size; + i != PQ_FIRST_ENTRY && + rectangle_compare_stop (rectangle, + elements[parent = PQ_PARENT_INDEX (i)]) < 0; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = rectangle; +} + +static inline void +pqueue_pop (pqueue_t *pq) +{ + rectangle_t **elements = pq->elements; + rectangle_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + rectangle_compare_stop (elements[child+1], + elements[child]) < 0) + { + child++; + } + + if (rectangle_compare_stop (elements[child], tail) >= 0) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static inline rectangle_t * +peek_stop (sweep_line_t *sweep) +{ + return sweep->stop.elements[PQ_FIRST_ENTRY]; +} + +CAIRO_COMBSORT_DECLARE (rectangle_sort, rectangle_t *, rectangle_compare_start) + +static void +sweep_line_init (sweep_line_t *sweep) +{ + sweep->head.left = INT_MIN; + sweep->head.next = &sweep->tail; + sweep->tail.left = INT_MAX; + sweep->tail.prev = &sweep->head; + sweep->insert_cursor = &sweep->tail; + + _cairo_freepool_init (&sweep->coverage.pool, sizeof (struct cell)); + + sweep->spans = sweep->spans_stack; + sweep->size_spans = ARRAY_LENGTH (sweep->spans_stack); + + sweep->coverage.head.prev = NULL; + sweep->coverage.head.x = INT_MIN; + sweep->coverage.tail.next = NULL; + sweep->coverage.tail.x = INT_MAX; + + pqueue_init (&sweep->stop); +} + +static void +sweep_line_fini (sweep_line_t *sweep) +{ + _cairo_freepool_fini (&sweep->coverage.pool); + pqueue_fini (&sweep->stop); + + if (sweep->spans != sweep->spans_stack) + free (sweep->spans); +} + +static inline void +add_cell (sweep_line_t *sweep, int x, int covered, int uncovered) +{ + struct cell *cell; + + cell = sweep->coverage.cursor; + if (cell->x > x) { + do { + UNROLL3({ + if (cell->prev->x < x) + break; + cell = cell->prev; + }) + } while (TRUE); + } else { + if (cell->x == x) + goto found; + + do { + UNROLL3({ + cell = cell->next; + if (cell->x >= x) + break; + }) + } while (TRUE); + } + + if (x != cell->x) { + struct cell *c; + + sweep->coverage.count++; + + c = _cairo_freepool_alloc (&sweep->coverage.pool); + if (unlikely (c == NULL)) { + longjmp (sweep->jmpbuf, + _cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + cell->prev->next = c; + c->prev = cell->prev; + c->next = cell; + cell->prev = c; + + c->x = x; + c->covered = 0; + c->uncovered = 0; + + cell = c; + } + +found: + cell->covered += covered; + cell->uncovered += uncovered; + sweep->coverage.cursor = cell; +} + +static inline void +_active_edges_to_spans (sweep_line_t *sweep) +{ + int32_t y = sweep->current_y; + rectangle_t *rectangle; + int coverage, prev_coverage; + int prev_x; + struct cell *cell; + + sweep->num_spans = 0; + if (sweep->head.next == &sweep->tail) + return; + + sweep->coverage.head.next = &sweep->coverage.tail; + sweep->coverage.tail.prev = &sweep->coverage.head; + sweep->coverage.cursor = &sweep->coverage.tail; + sweep->coverage.count = 0; + + /* XXX cell coverage only changes when a rectangle appears or + * disappears. Try only modifying coverage at such times. + */ + for (rectangle = sweep->head.next; + rectangle != &sweep->tail; + rectangle = rectangle->next) + { + int height; + int frac, i; + + if (y == rectangle->bottom_y) { + height = rectangle->bottom & CAIRO_FIXED_FRAC_MASK; + if (height == 0) + continue; + } else + height = CAIRO_FIXED_ONE; + if (y == rectangle->top_y) + height -= rectangle->top & CAIRO_FIXED_FRAC_MASK; + height *= rectangle->dir; + + i = _cairo_fixed_integer_part (rectangle->left), + frac = _cairo_fixed_fractional_part (rectangle->left); + add_cell (sweep, i, + (CAIRO_FIXED_ONE-frac) * height, + frac * height); + + i = _cairo_fixed_integer_part (rectangle->right), + frac = _cairo_fixed_fractional_part (rectangle->right); + add_cell (sweep, i, + -(CAIRO_FIXED_ONE-frac) * height, + -frac * height); + } + + if (2*sweep->coverage.count >= sweep->size_spans) { + unsigned size; + + size = sweep->size_spans; + while (size <= 2*sweep->coverage.count) + size <<= 1; + + if (sweep->spans != sweep->spans_stack) + free (sweep->spans); + + sweep->spans = _cairo_malloc_ab (size, sizeof (cairo_half_open_span_t)); + if (unlikely (sweep->spans == NULL)) + longjmp (sweep->jmpbuf, _cairo_error (CAIRO_STATUS_NO_MEMORY)); + + sweep->size_spans = size; + } + + prev_coverage = coverage = 0; + prev_x = INT_MIN; + for (cell = sweep->coverage.head.next; cell != &sweep->coverage.tail; cell = cell->next) { + if (cell->x != prev_x && coverage != prev_coverage) { + int n = sweep->num_spans++; + int c = coverage >> (CAIRO_FIXED_FRAC_BITS * 2 - 8); + sweep->spans[n].x = prev_x; + sweep->spans[n].inverse = 0; + sweep->spans[n].coverage = c - (c >> 8); + prev_coverage = coverage; + } + + coverage += cell->covered; + if (coverage != prev_coverage) { + int n = sweep->num_spans++; + int c = coverage >> (CAIRO_FIXED_FRAC_BITS * 2 - 8); + sweep->spans[n].x = cell->x; + sweep->spans[n].inverse = 0; + sweep->spans[n].coverage = c - (c >> 8); + prev_coverage = coverage; + } + coverage += cell->uncovered; + prev_x = cell->x + 1; + } + _cairo_freepool_reset (&sweep->coverage.pool); + + if (sweep->num_spans) { + if (prev_x <= sweep->xmax) { + int n = sweep->num_spans++; + int c = coverage >> (CAIRO_FIXED_FRAC_BITS * 2 - 8); + sweep->spans[n].x = prev_x; + sweep->spans[n].inverse = 0; + sweep->spans[n].coverage = c - (c >> 8); + } + + if (coverage && prev_x < sweep->xmax) { + int n = sweep->num_spans++; + sweep->spans[n].x = sweep->xmax; + sweep->spans[n].inverse = 1; + sweep->spans[n].coverage = 0; + } + } +} + +static inline void +sweep_line_delete (sweep_line_t *sweep, + rectangle_t *rectangle) +{ + if (sweep->insert_cursor == rectangle) + sweep->insert_cursor = rectangle->next; + + rectangle->prev->next = rectangle->next; + rectangle->next->prev = rectangle->prev; + + pqueue_pop (&sweep->stop); +} + +static inline void +sweep_line_insert (sweep_line_t *sweep, + rectangle_t *rectangle) +{ + rectangle_t *pos; + + pos = sweep->insert_cursor; + if (pos->left != rectangle->left) { + if (pos->left > rectangle->left) { + do { + UNROLL3({ + if (pos->prev->left < rectangle->left) + break; + pos = pos->prev; + }) + } while (TRUE); + } else { + do { + UNROLL3({ + pos = pos->next; + if (pos->left >= rectangle->left) + break; + }); + } while (TRUE); + } + } + + pos->prev->next = rectangle; + rectangle->prev = pos->prev; + rectangle->next = pos; + pos->prev = rectangle; + sweep->insert_cursor = rectangle; + + pqueue_push (sweep, rectangle); +} + +static void +render_rows (sweep_line_t *sweep_line, + cairo_span_renderer_t *renderer, + int height) +{ + cairo_status_t status; + + _active_edges_to_spans (sweep_line); + + status = renderer->render_rows (renderer, + sweep_line->current_y, height, + sweep_line->spans, + sweep_line->num_spans); + if (unlikely (status)) + longjmp (sweep_line->jmpbuf, status); +} + +static cairo_status_t +generate (cairo_rectangular_scan_converter_t *self, + cairo_span_renderer_t *renderer, + rectangle_t **rectangles) +{ + sweep_line_t sweep_line; + rectangle_t *start, *stop; + cairo_status_t status; + + sweep_line_init (&sweep_line); + sweep_line.xmin = _cairo_fixed_integer_part (self->extents.p1.x); + sweep_line.xmax = _cairo_fixed_integer_part (self->extents.p2.x); + sweep_line.start = rectangles; + if ((status = setjmp (sweep_line.jmpbuf))) + goto out; + + sweep_line.current_y = _cairo_fixed_integer_part (self->extents.p1.y); + start = *sweep_line.start++; + do { + if (start->top_y != sweep_line.current_y) { + render_rows (&sweep_line, renderer, + start->top_y - sweep_line.current_y); + sweep_line.current_y = start->top_y; + } + + do { + sweep_line_insert (&sweep_line, start); + start = *sweep_line.start++; + if (start == NULL) + goto end; + if (start->top_y != sweep_line.current_y) + break; + } while (TRUE); + + render_rows (&sweep_line, renderer, 1); + + stop = peek_stop (&sweep_line); + while (stop->bottom_y == sweep_line.current_y) { + sweep_line_delete (&sweep_line, stop); + stop = peek_stop (&sweep_line); + if (stop == NULL) + break; + } + + sweep_line.current_y++; + + while (stop != NULL && stop->bottom_y < start->top_y) { + if (stop->bottom_y != sweep_line.current_y) { + render_rows (&sweep_line, renderer, + stop->bottom_y - sweep_line.current_y); + sweep_line.current_y = stop->bottom_y; + } + + render_rows (&sweep_line, renderer, 1); + + do { + sweep_line_delete (&sweep_line, stop); + stop = peek_stop (&sweep_line); + } while (stop != NULL && stop->bottom_y == sweep_line.current_y); + + sweep_line.current_y++; + } + } while (TRUE); + + end: + render_rows (&sweep_line, renderer, 1); + + stop = peek_stop (&sweep_line); + while (stop->bottom_y == sweep_line.current_y) { + sweep_line_delete (&sweep_line, stop); + stop = peek_stop (&sweep_line); + if (stop == NULL) + goto out; + } + + while (++sweep_line.current_y < _cairo_fixed_integer_part (self->extents.p2.y)) { + if (stop->bottom_y != sweep_line.current_y) { + render_rows (&sweep_line, renderer, + stop->bottom_y - sweep_line.current_y); + sweep_line.current_y = stop->bottom_y; + } + + render_rows (&sweep_line, renderer, 1); + + do { + sweep_line_delete (&sweep_line, stop); + stop = peek_stop (&sweep_line); + if (stop == NULL) + goto out; + } while (stop->bottom_y == sweep_line.current_y); + + } + + out: + sweep_line_fini (&sweep_line); + + return status; +} +static void generate_row(cairo_span_renderer_t *renderer, + const rectangle_t *r, + int y, int h, + uint16_t coverage) +{ + cairo_half_open_span_t spans[4]; + unsigned int num_spans = 0; + int x1 = _cairo_fixed_integer_part (r->left); + int x2 = _cairo_fixed_integer_part (r->right); + if (x2 > x1) { + if (! _cairo_fixed_is_integer (r->left)) { + spans[num_spans].x = x1; + spans[num_spans].coverage = + coverage * (256 - _cairo_fixed_fractional_part (r->left)) >> 8; + num_spans++; + x1++; + } + + if (x2 > x1) { + spans[num_spans].x = x1; + spans[num_spans].coverage = coverage - (coverage >> 8); + num_spans++; + } + + if (! _cairo_fixed_is_integer (r->right)) { + spans[num_spans].x = x2++; + spans[num_spans].coverage = + coverage * _cairo_fixed_fractional_part (r->right) >> 8; + num_spans++; + } + } else { + spans[num_spans].x = x2++; + spans[num_spans].coverage = coverage * (r->right - r->left) >> 8; + num_spans++; + } + + spans[num_spans].x = x2; + spans[num_spans].coverage = 0; + num_spans++; + + renderer->render_rows (renderer, y, h, spans, num_spans); +} + +static cairo_status_t +generate_box (cairo_rectangular_scan_converter_t *self, + cairo_span_renderer_t *renderer) +{ + const rectangle_t *r = self->chunks.base; + int y1 = _cairo_fixed_integer_part (r->top); + int y2 = _cairo_fixed_integer_part (r->bottom); + if (y2 > y1) { + if (! _cairo_fixed_is_integer (r->top)) { + generate_row(renderer, r, y1, 1, + 256 - _cairo_fixed_fractional_part (r->top)); + y1++; + } + + if (y2 > y1) + generate_row(renderer, r, y1, y2-y1, 256); + + if (! _cairo_fixed_is_integer (r->bottom)) + generate_row(renderer, r, y2, 1, + _cairo_fixed_fractional_part (r->bottom)); + } else + generate_row(renderer, r, y1, 1, r->bottom - r->top); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_rectangular_scan_converter_generate (void *converter, + cairo_span_renderer_t *renderer) +{ + cairo_rectangular_scan_converter_t *self = converter; + rectangle_t *rectangles_stack[CAIRO_STACK_ARRAY_LENGTH (rectangle_t *)]; + rectangle_t **rectangles; + struct _cairo_rectangular_scan_converter_chunk *chunk; + cairo_status_t status; + int i, j; + + if (unlikely (self->num_rectangles == 0)) { + return renderer->render_rows (renderer, + _cairo_fixed_integer_part (self->extents.p1.y), + _cairo_fixed_integer_part (self->extents.p2.y - self->extents.p1.y), + NULL, 0); + } + + if (self->num_rectangles == 1) + return generate_box (self, renderer); + + rectangles = rectangles_stack; + if (unlikely (self->num_rectangles >= ARRAY_LENGTH (rectangles_stack))) { + rectangles = _cairo_malloc_ab (self->num_rectangles + 1, + sizeof (rectangle_t *)); + if (unlikely (rectangles == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + j = 0; + for (chunk = &self->chunks; chunk != NULL; chunk = chunk->next) { + rectangle_t *rectangle; + + rectangle = chunk->base; + for (i = 0; i < chunk->count; i++) + rectangles[j++] = &rectangle[i]; + } + rectangle_sort (rectangles, j); + rectangles[j] = NULL; + + status = generate (self, renderer, rectangles); + + if (rectangles != rectangles_stack) + free (rectangles); + + return status; +} + +static rectangle_t * +_allocate_rectangle (cairo_rectangular_scan_converter_t *self) +{ + rectangle_t *rectangle; + struct _cairo_rectangular_scan_converter_chunk *chunk; + + chunk = self->tail; + if (chunk->count == chunk->size) { + int size; + + size = chunk->size * 2; + chunk->next = _cairo_malloc_ab_plus_c (size, + sizeof (rectangle_t), + sizeof (struct _cairo_rectangular_scan_converter_chunk)); + + if (unlikely (chunk->next == NULL)) + return NULL; + + chunk = chunk->next; + chunk->next = NULL; + chunk->count = 0; + chunk->size = size; + chunk->base = chunk + 1; + self->tail = chunk; + } + + rectangle = chunk->base; + return rectangle + chunk->count++; +} + +cairo_status_t +_cairo_rectangular_scan_converter_add_box (cairo_rectangular_scan_converter_t *self, + const cairo_box_t *box, + int dir) +{ + rectangle_t *rectangle; + + rectangle = _allocate_rectangle (self); + if (unlikely (rectangle == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + rectangle->dir = dir; + rectangle->left = MAX (box->p1.x, self->extents.p1.x); + rectangle->right = MIN (box->p2.x, self->extents.p2.x); + if (unlikely (rectangle->right <= rectangle->left)) { + self->tail->count--; + return CAIRO_STATUS_SUCCESS; + } + + rectangle->top = MAX (box->p1.y, self->extents.p1.y); + rectangle->top_y = _cairo_fixed_integer_floor (rectangle->top); + rectangle->bottom = MIN (box->p2.y, self->extents.p2.y); + rectangle->bottom_y = _cairo_fixed_integer_floor (rectangle->bottom); + if (likely (rectangle->bottom > rectangle->top)) + self->num_rectangles++; + else + self->tail->count--; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_rectangular_scan_converter_destroy (void *converter) +{ + cairo_rectangular_scan_converter_t *self = converter; + struct _cairo_rectangular_scan_converter_chunk *chunk, *next; + + for (chunk = self->chunks.next; chunk != NULL; chunk = next) { + next = chunk->next; + free (chunk); + } +} + +void +_cairo_rectangular_scan_converter_init (cairo_rectangular_scan_converter_t *self, + const cairo_rectangle_int_t *extents) +{ + self->base.destroy = _cairo_rectangular_scan_converter_destroy; + self->base.generate = _cairo_rectangular_scan_converter_generate; + + _cairo_box_from_rectangle (&self->extents, extents); + + self->chunks.base = self->buf; + self->chunks.next = NULL; + self->chunks.count = 0; + self->chunks.size = sizeof (self->buf) / sizeof (rectangle_t); + self->tail = &self->chunks; + + self->num_rectangles = 0; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-reference-count-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-reference-count-private.h new file mode 100644 index 00000000000..75fdf3538f5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-reference-count-private.h @@ -0,0 +1,62 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_REFRENCE_COUNT_PRIVATE_H +#define CAIRO_REFRENCE_COUNT_PRIVATE_H + +#include "cairo-atomic-private.h" + +/* Encapsulate operations on the object's reference count */ +typedef struct { + cairo_atomic_int_t ref_count; +} cairo_reference_count_t; + +#define _cairo_reference_count_inc(RC) _cairo_atomic_int_inc (&(RC)->ref_count) +#define _cairo_reference_count_dec(RC) _cairo_atomic_int_dec (&(RC)->ref_count) +#define _cairo_reference_count_dec_and_test(RC) _cairo_atomic_int_dec_and_test (&(RC)->ref_count) + +#define CAIRO_REFERENCE_COUNT_INIT(RC, VALUE) ((RC)->ref_count = (VALUE)) + +#define CAIRO_REFERENCE_COUNT_GET_VALUE(RC) _cairo_atomic_int_get (&(RC)->ref_count) + +#define CAIRO_REFERENCE_COUNT_INVALID_VALUE ((cairo_atomic_int_t) -1) +#define CAIRO_REFERENCE_COUNT_INVALID {CAIRO_REFERENCE_COUNT_INVALID_VALUE} + +#define CAIRO_REFERENCE_COUNT_IS_INVALID(RC) (CAIRO_REFERENCE_COUNT_GET_VALUE (RC) == CAIRO_REFERENCE_COUNT_INVALID_VALUE) + +#define CAIRO_REFERENCE_COUNT_HAS_REFERENCE(RC) (CAIRO_REFERENCE_COUNT_GET_VALUE (RC) > 0) + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-region-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-region-private.h new file mode 100644 index 00000000000..549e5087898 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-region-private.h @@ -0,0 +1,77 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Owen Taylor + * Vladimir Vukicevic + * Søren Sandmann + */ + +#ifndef CAIRO_REGION_PRIVATE_H +#define CAIRO_REGION_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-reference-count-private.h" + +#include + +CAIRO_BEGIN_DECLS + +struct _cairo_region { + cairo_reference_count_t ref_count; + cairo_status_t status; + + pixman_region32_t rgn; +}; + +cairo_private cairo_region_t * +_cairo_region_create_in_error (cairo_status_t status); + +cairo_private void +_cairo_region_init (cairo_region_t *region); + +cairo_private void +_cairo_region_init_rectangle (cairo_region_t *region, + const cairo_rectangle_int_t *rectangle); + +cairo_private void +_cairo_region_fini (cairo_region_t *region); + +cairo_private cairo_region_t * +_cairo_region_create_from_boxes (const cairo_box_t *boxes, int count); + +cairo_private cairo_box_t * +_cairo_region_get_boxes (const cairo_region_t *region, int *nbox); + +CAIRO_END_DECLS + +#endif /* CAIRO_REGION_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-region.c b/Build/source/libs/cairo/cairo-src/src/cairo-region.c new file mode 100644 index 00000000000..ccfb2200e14 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-region.c @@ -0,0 +1,939 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Owen Taylor + * Vladimir Vukicevic + * Søren Sandmann + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-region-private.h" + +/* XXX need to update pixman headers to be const as appropriate */ +#define CONST_CAST (pixman_region32_t *) + +/** + * SECTION:cairo-region + * @Title: Regions + * @Short_Description: Representing a pixel-aligned area + * + * Regions are a simple graphical data type representing an area of + * integer-aligned rectangles. They are often used on raster surfaces + * to track areas of interest, such as change or clip areas. + **/ + +static const cairo_region_t _cairo_region_nil = { + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + CAIRO_STATUS_NO_MEMORY, /* status */ +}; + +cairo_region_t * +_cairo_region_create_in_error (cairo_status_t status) +{ + switch (status) { + case CAIRO_STATUS_NO_MEMORY: + return (cairo_region_t *) &_cairo_region_nil; + + case CAIRO_STATUS_SUCCESS: + case CAIRO_STATUS_LAST_STATUS: + ASSERT_NOT_REACHED; + /* fall-through */ + case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: + case CAIRO_STATUS_INVALID_STATUS: + case CAIRO_STATUS_INVALID_CONTENT: + case CAIRO_STATUS_INVALID_FORMAT: + case CAIRO_STATUS_INVALID_VISUAL: + case CAIRO_STATUS_READ_ERROR: + case CAIRO_STATUS_WRITE_ERROR: + case CAIRO_STATUS_FILE_NOT_FOUND: + case CAIRO_STATUS_TEMP_FILE_ERROR: + case CAIRO_STATUS_INVALID_STRIDE: + case CAIRO_STATUS_INVALID_SIZE: + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: + case CAIRO_STATUS_DEVICE_ERROR: + case CAIRO_STATUS_INVALID_RESTORE: + case CAIRO_STATUS_INVALID_POP_GROUP: + case CAIRO_STATUS_NO_CURRENT_POINT: + case CAIRO_STATUS_INVALID_MATRIX: + case CAIRO_STATUS_NULL_POINTER: + case CAIRO_STATUS_INVALID_STRING: + case CAIRO_STATUS_INVALID_PATH_DATA: + case CAIRO_STATUS_SURFACE_FINISHED: + case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: + case CAIRO_STATUS_INVALID_DASH: + case CAIRO_STATUS_INVALID_DSC_COMMENT: + case CAIRO_STATUS_INVALID_INDEX: + case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: + case CAIRO_STATUS_FONT_TYPE_MISMATCH: + case CAIRO_STATUS_USER_FONT_IMMUTABLE: + case CAIRO_STATUS_USER_FONT_ERROR: + case CAIRO_STATUS_NEGATIVE_COUNT: + case CAIRO_STATUS_INVALID_CLUSTERS: + case CAIRO_STATUS_INVALID_SLANT: + case CAIRO_STATUS_INVALID_WEIGHT: + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: + case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: + case CAIRO_STATUS_DEVICE_FINISHED: + case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: + default: + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_region_t *) &_cairo_region_nil; + } +} + +/** + * _cairo_region_set_error: + * @region: a region + * @status: a status value indicating an error + * + * Atomically sets region->status to @status and calls _cairo_error; + * Does nothing if status is %CAIRO_STATUS_SUCCESS or any of the internal + * status values. + * + * All assignments of an error status to region->status should happen + * through _cairo_region_set_error(). Note that due to the nature of + * the atomic operation, it is not safe to call this function on the + * nil objects. + * + * The purpose of this function is to allow the user to set a + * breakpoint in _cairo_error() to generate a stack trace for when the + * user causes cairo to detect an error. + * + * Return value: the error status. + **/ +static cairo_status_t +_cairo_region_set_error (cairo_region_t *region, + cairo_status_t status) +{ + if (status == CAIRO_STATUS_SUCCESS) + return CAIRO_STATUS_SUCCESS; + + /* Don't overwrite an existing error. This preserves the first + * error, which is the most significant. */ + _cairo_status_set_error (®ion->status, status); + + return _cairo_error (status); +} + +void +_cairo_region_init (cairo_region_t *region) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (region, sizeof (cairo_region_t))); + + region->status = CAIRO_STATUS_SUCCESS; + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); + pixman_region32_init (®ion->rgn); +} + +void +_cairo_region_init_rectangle (cairo_region_t *region, + const cairo_rectangle_int_t *rectangle) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (region, sizeof (cairo_region_t))); + + region->status = CAIRO_STATUS_SUCCESS; + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); + pixman_region32_init_rect (®ion->rgn, + rectangle->x, rectangle->y, + rectangle->width, rectangle->height); +} + +void +_cairo_region_fini (cairo_region_t *region) +{ + assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); + pixman_region32_fini (®ion->rgn); + VG (VALGRIND_MAKE_MEM_NOACCESS (region, sizeof (cairo_region_t))); +} + +/** + * cairo_region_create: + * + * Allocates a new empty region object. + * + * Return value: A newly allocated #cairo_region_t. Free with + * cairo_region_destroy(). This function always returns a + * valid pointer; if memory cannot be allocated, then a special + * error object is returned where all operations on the object do nothing. + * You can check for this with cairo_region_status(). + * + * Since: 1.10 + **/ +cairo_region_t * +cairo_region_create (void) +{ + cairo_region_t *region; + + region = _cairo_malloc (sizeof (cairo_region_t)); + if (region == NULL) + return (cairo_region_t *) &_cairo_region_nil; + + region->status = CAIRO_STATUS_SUCCESS; + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); + + pixman_region32_init (®ion->rgn); + + return region; +} +slim_hidden_def (cairo_region_create); + +/** + * cairo_region_create_rectangles: + * @rects: an array of @count rectangles + * @count: number of rectangles + * + * Allocates a new region object containing the union of all given @rects. + * + * Return value: A newly allocated #cairo_region_t. Free with + * cairo_region_destroy(). This function always returns a + * valid pointer; if memory cannot be allocated, then a special + * error object is returned where all operations on the object do nothing. + * You can check for this with cairo_region_status(). + * + * Since: 1.10 + **/ +cairo_region_t * +cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, + int count) +{ + pixman_box32_t stack_pboxes[CAIRO_STACK_ARRAY_LENGTH (pixman_box32_t)]; + pixman_box32_t *pboxes = stack_pboxes; + cairo_region_t *region; + int i; + + region = _cairo_malloc (sizeof (cairo_region_t)); + if (unlikely (region == NULL)) + return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); + region->status = CAIRO_STATUS_SUCCESS; + + if (count == 1) { + pixman_region32_init_rect (®ion->rgn, + rects->x, rects->y, + rects->width, rects->height); + + return region; + } + + if (count > ARRAY_LENGTH (stack_pboxes)) { + pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t)); + if (unlikely (pboxes == NULL)) { + free (region); + return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + } + + for (i = 0; i < count; i++) { + pboxes[i].x1 = rects[i].x; + pboxes[i].y1 = rects[i].y; + pboxes[i].x2 = rects[i].x + rects[i].width; + pboxes[i].y2 = rects[i].y + rects[i].height; + } + + i = pixman_region32_init_rects (®ion->rgn, pboxes, count); + + if (pboxes != stack_pboxes) + free (pboxes); + + if (unlikely (i == 0)) { + free (region); + return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + return region; +} +slim_hidden_def (cairo_region_create_rectangles); + +cairo_region_t * +_cairo_region_create_from_boxes (const cairo_box_t *boxes, int count) +{ + cairo_region_t *region; + + region = _cairo_malloc (sizeof (cairo_region_t)); + if (unlikely (region == NULL)) + return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); + region->status = CAIRO_STATUS_SUCCESS; + + if (! pixman_region32_init_rects (®ion->rgn, + (pixman_box32_t *)boxes, count)) { + free (region); + return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + return region; +} + +cairo_box_t * +_cairo_region_get_boxes (const cairo_region_t *region, int *nbox) +{ + if (region->status) { + nbox = 0; + return NULL; + } + + return (cairo_box_t *) pixman_region32_rectangles (CONST_CAST ®ion->rgn, nbox); +} + +/** + * cairo_region_create_rectangle: + * @rectangle: a #cairo_rectangle_int_t + * + * Allocates a new region object containing @rectangle. + * + * Return value: A newly allocated #cairo_region_t. Free with + * cairo_region_destroy(). This function always returns a + * valid pointer; if memory cannot be allocated, then a special + * error object is returned where all operations on the object do nothing. + * You can check for this with cairo_region_status(). + * + * Since: 1.10 + **/ +cairo_region_t * +cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle) +{ + cairo_region_t *region; + + region = _cairo_malloc (sizeof (cairo_region_t)); + if (unlikely (region == NULL)) + return (cairo_region_t *) &_cairo_region_nil; + + region->status = CAIRO_STATUS_SUCCESS; + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); + + pixman_region32_init_rect (®ion->rgn, + rectangle->x, rectangle->y, + rectangle->width, rectangle->height); + + return region; +} +slim_hidden_def (cairo_region_create_rectangle); + +/** + * cairo_region_copy: + * @original: a #cairo_region_t + * + * Allocates a new region object copying the area from @original. + * + * Return value: A newly allocated #cairo_region_t. Free with + * cairo_region_destroy(). This function always returns a + * valid pointer; if memory cannot be allocated, then a special + * error object is returned where all operations on the object do nothing. + * You can check for this with cairo_region_status(). + * + * Since: 1.10 + **/ +cairo_region_t * +cairo_region_copy (const cairo_region_t *original) +{ + cairo_region_t *copy; + + if (original != NULL && original->status) + return (cairo_region_t *) &_cairo_region_nil; + + copy = cairo_region_create (); + if (unlikely (copy->status)) + return copy; + + if (original != NULL && + ! pixman_region32_copy (©->rgn, CONST_CAST &original->rgn)) + { + cairo_region_destroy (copy); + return (cairo_region_t *) &_cairo_region_nil; + } + + return copy; +} +slim_hidden_def (cairo_region_copy); + +/** + * cairo_region_reference: + * @region: a #cairo_region_t + * + * Increases the reference count on @region by one. This prevents + * @region from being destroyed until a matching call to + * cairo_region_destroy() is made. + * + * Return value: the referenced #cairo_region_t. + * + * Since: 1.10 + **/ +cairo_region_t * +cairo_region_reference (cairo_region_t *region) +{ + if (region == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (®ion->ref_count)) + return NULL; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); + + _cairo_reference_count_inc (®ion->ref_count); + return region; +} +slim_hidden_def (cairo_region_reference); + +/** + * cairo_region_destroy: + * @region: a #cairo_region_t + * + * Destroys a #cairo_region_t object created with + * cairo_region_create(), cairo_region_copy(), or + * or cairo_region_create_rectangle(). + * + * Since: 1.10 + **/ +void +cairo_region_destroy (cairo_region_t *region) +{ + if (region == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (®ion->ref_count)) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); + + if (! _cairo_reference_count_dec_and_test (®ion->ref_count)) + return; + + _cairo_region_fini (region); + free (region); +} +slim_hidden_def (cairo_region_destroy); + +/** + * cairo_region_num_rectangles: + * @region: a #cairo_region_t + * + * Returns the number of rectangles contained in @region. + * + * Return value: The number of rectangles contained in @region. + * + * Since: 1.10 + **/ +int +cairo_region_num_rectangles (const cairo_region_t *region) +{ + if (region->status) + return 0; + + return pixman_region32_n_rects (CONST_CAST ®ion->rgn); +} +slim_hidden_def (cairo_region_num_rectangles); + +/** + * cairo_region_get_rectangle: + * @region: a #cairo_region_t + * @nth: a number indicating which rectangle should be returned + * @rectangle: return location for a #cairo_rectangle_int_t + * + * Stores the @nth rectangle from the region in @rectangle. + * + * Since: 1.10 + **/ +void +cairo_region_get_rectangle (const cairo_region_t *region, + int nth, + cairo_rectangle_int_t *rectangle) +{ + pixman_box32_t *pbox; + + if (region->status) { + rectangle->x = rectangle->y = 0; + rectangle->width = rectangle->height = 0; + return; + } + + pbox = pixman_region32_rectangles (CONST_CAST ®ion->rgn, NULL) + nth; + + rectangle->x = pbox->x1; + rectangle->y = pbox->y1; + rectangle->width = pbox->x2 - pbox->x1; + rectangle->height = pbox->y2 - pbox->y1; +} +slim_hidden_def (cairo_region_get_rectangle); + +/** + * cairo_region_get_extents: + * @region: a #cairo_region_t + * @extents: rectangle into which to store the extents + * + * Gets the bounding rectangle of @region as a #cairo_rectangle_int_t + * + * Since: 1.10 + **/ +void +cairo_region_get_extents (const cairo_region_t *region, + cairo_rectangle_int_t *extents) +{ + pixman_box32_t *pextents; + + if (region->status) { + extents->x = extents->y = 0; + extents->width = extents->height = 0; + return; + } + + pextents = pixman_region32_extents (CONST_CAST ®ion->rgn); + + extents->x = pextents->x1; + extents->y = pextents->y1; + extents->width = pextents->x2 - pextents->x1; + extents->height = pextents->y2 - pextents->y1; +} +slim_hidden_def (cairo_region_get_extents); + +/** + * cairo_region_status: + * @region: a #cairo_region_t + * + * Checks whether an error has previous occurred for this + * region object. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_status (const cairo_region_t *region) +{ + return region->status; +} +slim_hidden_def (cairo_region_status); + +/** + * cairo_region_subtract: + * @dst: a #cairo_region_t + * @other: another #cairo_region_t + * + * Subtracts @other from @dst and places the result in @dst + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_subtract (cairo_region_t *dst, const cairo_region_t *other) +{ + if (dst->status) + return dst->status; + + if (other->status) + return _cairo_region_set_error (dst, other->status); + + if (! pixman_region32_subtract (&dst->rgn, + &dst->rgn, + CONST_CAST &other->rgn)) + { + return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + } + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_region_subtract); + +/** + * cairo_region_subtract_rectangle: + * @dst: a #cairo_region_t + * @rectangle: a #cairo_rectangle_int_t + * + * Subtracts @rectangle from @dst and places the result in @dst + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_subtract_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + pixman_region32_t region; + + if (dst->status) + return dst->status; + + pixman_region32_init_rect (®ion, + rectangle->x, rectangle->y, + rectangle->width, rectangle->height); + + if (! pixman_region32_subtract (&dst->rgn, &dst->rgn, ®ion)) + status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + pixman_region32_fini (®ion); + + return status; +} +slim_hidden_def (cairo_region_subtract_rectangle); + +/** + * cairo_region_intersect: + * @dst: a #cairo_region_t + * @other: another #cairo_region_t + * + * Computes the intersection of @dst with @other and places the result in @dst + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_intersect (cairo_region_t *dst, const cairo_region_t *other) +{ + if (dst->status) + return dst->status; + + if (other->status) + return _cairo_region_set_error (dst, other->status); + + if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn)) + return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_region_intersect); + +/** + * cairo_region_intersect_rectangle: + * @dst: a #cairo_region_t + * @rectangle: a #cairo_rectangle_int_t + * + * Computes the intersection of @dst with @rectangle and places the + * result in @dst + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_intersect_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + pixman_region32_t region; + + if (dst->status) + return dst->status; + + pixman_region32_init_rect (®ion, + rectangle->x, rectangle->y, + rectangle->width, rectangle->height); + + if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, ®ion)) + status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + pixman_region32_fini (®ion); + + return status; +} +slim_hidden_def (cairo_region_intersect_rectangle); + +/** + * cairo_region_union: + * @dst: a #cairo_region_t + * @other: another #cairo_region_t + * + * Computes the union of @dst with @other and places the result in @dst + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_union (cairo_region_t *dst, + const cairo_region_t *other) +{ + if (dst->status) + return dst->status; + + if (other->status) + return _cairo_region_set_error (dst, other->status); + + if (! pixman_region32_union (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn)) + return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_region_union); + +/** + * cairo_region_union_rectangle: + * @dst: a #cairo_region_t + * @rectangle: a #cairo_rectangle_int_t + * + * Computes the union of @dst with @rectangle and places the result in @dst. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_union_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + pixman_region32_t region; + + if (dst->status) + return dst->status; + + pixman_region32_init_rect (®ion, + rectangle->x, rectangle->y, + rectangle->width, rectangle->height); + + if (! pixman_region32_union (&dst->rgn, &dst->rgn, ®ion)) + status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + pixman_region32_fini (®ion); + + return status; +} +slim_hidden_def (cairo_region_union_rectangle); + +/** + * cairo_region_xor: + * @dst: a #cairo_region_t + * @other: another #cairo_region_t + * + * Computes the exclusive difference of @dst with @other and places the + * result in @dst. That is, @dst will be set to contain all areas that + * are either in @dst or in @other, but not in both. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + pixman_region32_t tmp; + + if (dst->status) + return dst->status; + + if (other->status) + return _cairo_region_set_error (dst, other->status); + + pixman_region32_init (&tmp); + + /* XXX: get an xor function into pixman */ + if (! pixman_region32_subtract (&tmp, CONST_CAST &other->rgn, &dst->rgn) || + ! pixman_region32_subtract (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn) || + ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp)) + status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + pixman_region32_fini (&tmp); + + return status; +} +slim_hidden_def (cairo_region_xor); + +/** + * cairo_region_xor_rectangle: + * @dst: a #cairo_region_t + * @rectangle: a #cairo_rectangle_int_t + * + * Computes the exclusive difference of @dst with @rectangle and places the + * result in @dst. That is, @dst will be set to contain all areas that are + * either in @dst or in @rectangle, but not in both. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY + * + * Since: 1.10 + **/ +cairo_status_t +cairo_region_xor_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + pixman_region32_t region, tmp; + + if (dst->status) + return dst->status; + + pixman_region32_init_rect (®ion, + rectangle->x, rectangle->y, + rectangle->width, rectangle->height); + pixman_region32_init (&tmp); + + /* XXX: get an xor function into pixman */ + if (! pixman_region32_subtract (&tmp, ®ion, &dst->rgn) || + ! pixman_region32_subtract (&dst->rgn, &dst->rgn, ®ion) || + ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp)) + status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY); + + pixman_region32_fini (&tmp); + pixman_region32_fini (®ion); + + return status; +} +slim_hidden_def (cairo_region_xor_rectangle); + +/** + * cairo_region_is_empty: + * @region: a #cairo_region_t + * + * Checks whether @region is empty. + * + * Return value: %TRUE if @region is empty, %FALSE if it isn't. + * + * Since: 1.10 + **/ +cairo_bool_t +cairo_region_is_empty (const cairo_region_t *region) +{ + if (region->status) + return TRUE; + + return ! pixman_region32_not_empty (CONST_CAST ®ion->rgn); +} +slim_hidden_def (cairo_region_is_empty); + +/** + * cairo_region_translate: + * @region: a #cairo_region_t + * @dx: Amount to translate in the x direction + * @dy: Amount to translate in the y direction + * + * Translates @region by (@dx, @dy). + * + * Since: 1.10 + **/ +void +cairo_region_translate (cairo_region_t *region, + int dx, int dy) +{ + if (region->status) + return; + + pixman_region32_translate (®ion->rgn, dx, dy); +} +slim_hidden_def (cairo_region_translate); + +/** + * cairo_region_contains_rectangle: + * @region: a #cairo_region_t + * @rectangle: a #cairo_rectangle_int_t + * + * Checks whether @rectangle is inside, outside or partially contained + * in @region + * + * Return value: + * %CAIRO_REGION_OVERLAP_IN if @rectangle is entirely inside @region, + * %CAIRO_REGION_OVERLAP_OUT if @rectangle is entirely outside @region, or + * %CAIRO_REGION_OVERLAP_PART if @rectangle is partially inside and partially outside @region. + * + * Since: 1.10 + **/ +cairo_region_overlap_t +cairo_region_contains_rectangle (const cairo_region_t *region, + const cairo_rectangle_int_t *rectangle) +{ + pixman_box32_t pbox; + pixman_region_overlap_t poverlap; + + if (region->status) + return CAIRO_REGION_OVERLAP_OUT; + + pbox.x1 = rectangle->x; + pbox.y1 = rectangle->y; + pbox.x2 = rectangle->x + rectangle->width; + pbox.y2 = rectangle->y + rectangle->height; + + poverlap = pixman_region32_contains_rectangle (CONST_CAST ®ion->rgn, + &pbox); + switch (poverlap) { + default: + case PIXMAN_REGION_OUT: return CAIRO_REGION_OVERLAP_OUT; + case PIXMAN_REGION_IN: return CAIRO_REGION_OVERLAP_IN; + case PIXMAN_REGION_PART: return CAIRO_REGION_OVERLAP_PART; + } +} +slim_hidden_def (cairo_region_contains_rectangle); + +/** + * cairo_region_contains_point: + * @region: a #cairo_region_t + * @x: the x coordinate of a point + * @y: the y coordinate of a point + * + * Checks whether (@x, @y) is contained in @region. + * + * Return value: %TRUE if (@x, @y) is contained in @region, %FALSE if it is not. + * + * Since: 1.10 + **/ +cairo_bool_t +cairo_region_contains_point (const cairo_region_t *region, + int x, int y) +{ + pixman_box32_t box; + + if (region->status) + return FALSE; + + return pixman_region32_contains_point (CONST_CAST ®ion->rgn, x, y, &box); +} +slim_hidden_def (cairo_region_contains_point); + +/** + * cairo_region_equal: + * @a: a #cairo_region_t or %NULL + * @b: a #cairo_region_t or %NULL + * + * Compares whether region_a is equivalent to region_b. %NULL as an argument + * is equal to itself, but not to any non-%NULL region. + * + * Return value: %TRUE if both regions contained the same coverage, + * %FALSE if it is not or any region is in an error status. + * + * Since: 1.10 + **/ +cairo_bool_t +cairo_region_equal (const cairo_region_t *a, + const cairo_region_t *b) +{ + /* error objects are never equal */ + if ((a != NULL && a->status) || (b != NULL && b->status)) + return FALSE; + + if (a == b) + return TRUE; + + if (a == NULL || b == NULL) + return FALSE; + + return pixman_region32_equal (CONST_CAST &a->rgn, CONST_CAST &b->rgn); +} +slim_hidden_def (cairo_region_equal); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-rtree-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-rtree-private.h new file mode 100644 index 00000000000..27806cab603 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-rtree-private.h @@ -0,0 +1,142 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + * + */ + +#ifndef CAIRO_RTREE_PRIVATE_H +#define CAIRO_RTREE_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" +#include "cairo-types-private.h" + +#include "cairo-freelist-private.h" +#include "cairo-list-inline.h" + +enum { + CAIRO_RTREE_NODE_AVAILABLE, + CAIRO_RTREE_NODE_DIVIDED, + CAIRO_RTREE_NODE_OCCUPIED, +}; + +typedef struct _cairo_rtree_node { + struct _cairo_rtree_node *children[4], *parent; + cairo_list_t link; + uint16_t pinned; + uint16_t state; + uint16_t x, y; + uint16_t width, height; +} cairo_rtree_node_t; + +typedef struct _cairo_rtree { + cairo_rtree_node_t root; + int min_size; + cairo_list_t pinned; + cairo_list_t available; + cairo_list_t evictable; + void (*destroy) (cairo_rtree_node_t *); + cairo_freepool_t node_freepool; +} cairo_rtree_t; + +cairo_private cairo_rtree_node_t * +_cairo_rtree_node_create (cairo_rtree_t *rtree, + cairo_rtree_node_t *parent, + int x, + int y, + int width, + int height); + +cairo_private cairo_status_t +_cairo_rtree_node_insert (cairo_rtree_t *rtree, + cairo_rtree_node_t *node, + int width, + int height, + cairo_rtree_node_t **out); + +cairo_private void +_cairo_rtree_node_collapse (cairo_rtree_t *rtree, cairo_rtree_node_t *node); + +cairo_private void +_cairo_rtree_node_remove (cairo_rtree_t *rtree, cairo_rtree_node_t *node); + +cairo_private void +_cairo_rtree_node_destroy (cairo_rtree_t *rtree, cairo_rtree_node_t *node); + +cairo_private void +_cairo_rtree_init (cairo_rtree_t *rtree, + int width, + int height, + int min_size, + int node_size, + void (*destroy)(cairo_rtree_node_t *)); + +cairo_private cairo_int_status_t +_cairo_rtree_insert (cairo_rtree_t *rtree, + int width, + int height, + cairo_rtree_node_t **out); + +cairo_private cairo_int_status_t +_cairo_rtree_evict_random (cairo_rtree_t *rtree, + int width, + int height, + cairo_rtree_node_t **out); + +cairo_private void +_cairo_rtree_foreach (cairo_rtree_t *rtree, + void (*func)(cairo_rtree_node_t *, void *data), + void *data); + +static inline void * +_cairo_rtree_pin (cairo_rtree_t *rtree, cairo_rtree_node_t *node) +{ + assert (node->state == CAIRO_RTREE_NODE_OCCUPIED); + if (! node->pinned) { + cairo_list_move (&node->link, &rtree->pinned); + node->pinned = 1; + } + + return node; +} + +cairo_private void +_cairo_rtree_unpin (cairo_rtree_t *rtree); + +cairo_private void +_cairo_rtree_reset (cairo_rtree_t *rtree); + +cairo_private void +_cairo_rtree_fini (cairo_rtree_t *rtree); + +#endif /* CAIRO_RTREE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-rtree.c b/Build/source/libs/cairo/cairo-src/src/cairo-rtree.c new file mode 100644 index 00000000000..dbc040929af --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-rtree.c @@ -0,0 +1,388 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + * + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-rtree-private.h" + +cairo_rtree_node_t * +_cairo_rtree_node_create (cairo_rtree_t *rtree, + cairo_rtree_node_t *parent, + int x, + int y, + int width, + int height) +{ + cairo_rtree_node_t *node; + + node = _cairo_freepool_alloc (&rtree->node_freepool); + if (node == NULL) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + node->children[0] = NULL; + node->parent = parent; + node->state = CAIRO_RTREE_NODE_AVAILABLE; + node->pinned = FALSE; + node->x = x; + node->y = y; + node->width = width; + node->height = height; + + cairo_list_add (&node->link, &rtree->available); + + return node; +} + +void +_cairo_rtree_node_destroy (cairo_rtree_t *rtree, cairo_rtree_node_t *node) +{ + int i; + + cairo_list_del (&node->link); + + if (node->state == CAIRO_RTREE_NODE_OCCUPIED) { + rtree->destroy (node); + } else { + for (i = 0; i < 4 && node->children[i] != NULL; i++) + _cairo_rtree_node_destroy (rtree, node->children[i]); + } + + _cairo_freepool_free (&rtree->node_freepool, node); +} + +void +_cairo_rtree_node_collapse (cairo_rtree_t *rtree, cairo_rtree_node_t *node) +{ + int i; + + do { + assert (node->state == CAIRO_RTREE_NODE_DIVIDED); + + for (i = 0; i < 4 && node->children[i] != NULL; i++) + if (node->children[i]->state != CAIRO_RTREE_NODE_AVAILABLE) + return; + + for (i = 0; i < 4 && node->children[i] != NULL; i++) + _cairo_rtree_node_destroy (rtree, node->children[i]); + + node->children[0] = NULL; + node->state = CAIRO_RTREE_NODE_AVAILABLE; + cairo_list_move (&node->link, &rtree->available); + } while ((node = node->parent) != NULL); +} + +cairo_status_t +_cairo_rtree_node_insert (cairo_rtree_t *rtree, + cairo_rtree_node_t *node, + int width, + int height, + cairo_rtree_node_t **out) +{ + int w, h, i; + + assert (node->state == CAIRO_RTREE_NODE_AVAILABLE); + assert (node->pinned == FALSE); + + if (node->width - width > rtree->min_size || + node->height - height > rtree->min_size) + { + w = node->width - width; + h = node->height - height; + + i = 0; + node->children[i] = _cairo_rtree_node_create (rtree, node, + node->x, node->y, + width, height); + if (unlikely (node->children[i] == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + i++; + + if (w > rtree->min_size) { + node->children[i] = _cairo_rtree_node_create (rtree, node, + node->x + width, + node->y, + w, height); + if (unlikely (node->children[i] == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + i++; + } + + if (h > rtree->min_size) { + node->children[i] = _cairo_rtree_node_create (rtree, node, + node->x, + node->y + height, + width, h); + if (unlikely (node->children[i] == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + i++; + + if (w > rtree->min_size) { + node->children[i] = _cairo_rtree_node_create (rtree, node, + node->x + width, + node->y + height, + w, h); + if (unlikely (node->children[i] == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + i++; + } + } + + if (i < 4) + node->children[i] = NULL; + + node->state = CAIRO_RTREE_NODE_DIVIDED; + cairo_list_move (&node->link, &rtree->evictable); + node = node->children[0]; + } + + node->state = CAIRO_RTREE_NODE_OCCUPIED; + cairo_list_move (&node->link, &rtree->evictable); + *out = node; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_rtree_node_remove (cairo_rtree_t *rtree, cairo_rtree_node_t *node) +{ + assert (node->state == CAIRO_RTREE_NODE_OCCUPIED); + assert (node->pinned == FALSE); + + rtree->destroy (node); + + node->state = CAIRO_RTREE_NODE_AVAILABLE; + cairo_list_move (&node->link, &rtree->available); + + _cairo_rtree_node_collapse (rtree, node->parent); +} + +cairo_int_status_t +_cairo_rtree_insert (cairo_rtree_t *rtree, + int width, + int height, + cairo_rtree_node_t **out) +{ + cairo_rtree_node_t *node; + + cairo_list_foreach_entry (node, cairo_rtree_node_t, + &rtree->available, link) + { + if (node->width >= width && node->height >= height) + return _cairo_rtree_node_insert (rtree, node, width, height, out); + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static uint32_t +hars_petruska_f54_1_random (void) +{ +#define rol(x,k) ((x << k) | (x >> (32-k))) + static uint32_t x; + return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; +#undef rol +} + +cairo_int_status_t +_cairo_rtree_evict_random (cairo_rtree_t *rtree, + int width, + int height, + cairo_rtree_node_t **out) +{ + cairo_int_status_t ret = CAIRO_INT_STATUS_UNSUPPORTED; + cairo_rtree_node_t *node, *next; + cairo_list_t tmp_pinned; + int i, cnt; + + cairo_list_init (&tmp_pinned); + + /* propagate pinned from children to root */ + cairo_list_foreach_entry_safe (node, next, + cairo_rtree_node_t, &rtree->pinned, link) { + node = node->parent; + while (node && ! node->pinned) { + node->pinned = 1; + cairo_list_move (&node->link, &tmp_pinned); + node = node->parent; + } + } + + cnt = 0; + cairo_list_foreach_entry (node, cairo_rtree_node_t, + &rtree->evictable, link) + { + if (node->width >= width && node->height >= height) + cnt++; + } + + if (cnt == 0) + goto out; + + cnt = hars_petruska_f54_1_random () % cnt; + cairo_list_foreach_entry (node, cairo_rtree_node_t, + &rtree->evictable, link) + { + if (node->width >= width && node->height >= height && cnt-- == 0) { + if (node->state == CAIRO_RTREE_NODE_OCCUPIED) { + rtree->destroy (node); + } else { + for (i = 0; i < 4 && node->children[i] != NULL; i++) + _cairo_rtree_node_destroy (rtree, node->children[i]); + node->children[0] = NULL; + } + + node->state = CAIRO_RTREE_NODE_AVAILABLE; + cairo_list_move (&node->link, &rtree->available); + + *out = node; + ret = CAIRO_STATUS_SUCCESS; + break; + } + } + +out: + while (! cairo_list_is_empty (&tmp_pinned)) { + node = cairo_list_first_entry (&tmp_pinned, cairo_rtree_node_t, link); + node->pinned = 0; + cairo_list_move (&node->link, &rtree->evictable); + } + return ret; +} + +void +_cairo_rtree_unpin (cairo_rtree_t *rtree) +{ + while (! cairo_list_is_empty (&rtree->pinned)) { + cairo_rtree_node_t *node = cairo_list_first_entry (&rtree->pinned, + cairo_rtree_node_t, + link); + node->pinned = 0; + cairo_list_move (&node->link, &rtree->evictable); + } +} + +void +_cairo_rtree_init (cairo_rtree_t *rtree, + int width, + int height, + int min_size, + int node_size, + void (*destroy) (cairo_rtree_node_t *)) +{ + assert (node_size >= (int) sizeof (cairo_rtree_node_t)); + _cairo_freepool_init (&rtree->node_freepool, node_size); + + cairo_list_init (&rtree->available); + cairo_list_init (&rtree->pinned); + cairo_list_init (&rtree->evictable); + + rtree->min_size = min_size; + rtree->destroy = destroy; + + memset (&rtree->root, 0, sizeof (rtree->root)); + rtree->root.width = width; + rtree->root.height = height; + rtree->root.state = CAIRO_RTREE_NODE_AVAILABLE; + cairo_list_add (&rtree->root.link, &rtree->available); +} + +void +_cairo_rtree_reset (cairo_rtree_t *rtree) +{ + int i; + + if (rtree->root.state == CAIRO_RTREE_NODE_OCCUPIED) { + rtree->destroy (&rtree->root); + } else { + for (i = 0; i < 4 && rtree->root.children[i] != NULL; i++) + _cairo_rtree_node_destroy (rtree, rtree->root.children[i]); + rtree->root.children[0] = NULL; + } + + cairo_list_init (&rtree->available); + cairo_list_init (&rtree->evictable); + cairo_list_init (&rtree->pinned); + + rtree->root.state = CAIRO_RTREE_NODE_AVAILABLE; + rtree->root.pinned = FALSE; + cairo_list_add (&rtree->root.link, &rtree->available); +} + +static void +_cairo_rtree_node_foreach (cairo_rtree_node_t *node, + void (*func)(cairo_rtree_node_t *, void *data), + void *data) +{ + int i; + + for (i = 0; i < 4 && node->children[i] != NULL; i++) + _cairo_rtree_node_foreach(node->children[i], func, data); + + func(node, data); +} + +void +_cairo_rtree_foreach (cairo_rtree_t *rtree, + void (*func)(cairo_rtree_node_t *, void *data), + void *data) +{ + int i; + + if (rtree->root.state == CAIRO_RTREE_NODE_OCCUPIED) { + func(&rtree->root, data); + } else { + for (i = 0; i < 4 && rtree->root.children[i] != NULL; i++) + _cairo_rtree_node_foreach (rtree->root.children[i], func, data); + } +} + +void +_cairo_rtree_fini (cairo_rtree_t *rtree) +{ + int i; + + if (rtree->root.state == CAIRO_RTREE_NODE_OCCUPIED) { + rtree->destroy (&rtree->root); + } else { + for (i = 0; i < 4 && rtree->root.children[i] != NULL; i++) + _cairo_rtree_node_destroy (rtree, rtree->root.children[i]); + } + + _cairo_freepool_fini (&rtree->node_freepool); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-private.h new file mode 100644 index 00000000000..da7b3469834 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-private.h @@ -0,0 +1,183 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_SCALED_FONT_PRIVATE_H +#define CAIRO_SCALED_FONT_PRIVATE_H + +#include "cairo.h" + +#include "cairo-types-private.h" +#include "cairo-list-private.h" +#include "cairo-mutex-type-private.h" +#include "cairo-reference-count-private.h" + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_scaled_glyph_page cairo_scaled_glyph_page_t; + +struct _cairo_scaled_font { + /* For most cairo objects, the rule for multiple threads is that + * the user is responsible for any locking if the same object is + * manipulated from multiple threads simultaneously. + * + * However, with the caching that cairo does for scaled fonts, a + * user can easily end up with the same cairo_scaled_font object + * being manipulated from multiple threads without the user ever + * being aware of this, (and in fact, unable to control it). + * + * So, as a special exception, the cairo implementation takes care + * of all locking needed for cairo_scaled_font_t. Most of what is + * in the scaled font is immutable, (which is what allows for the + * sharing in the first place). The things that are modified and + * the locks protecting them are as follows: + * + * 1. The reference count (scaled_font->ref_count) + * + * Modifications to the reference count are protected by the + * _cairo_scaled_font_map_mutex. This is because the reference + * count of a scaled font is intimately related with the font + * map itself, (and the magic holdovers array). + * + * 2. The cache of glyphs (scaled_font->glyphs) + * 3. The backend private data (scaled_font->surface_backend, + * scaled_font->surface_private) + * + * Modifications to these fields are protected with locks on + * scaled_font->mutex in the generic scaled_font code. + */ + + cairo_hash_entry_t hash_entry; + + /* useful bits for _cairo_scaled_font_nil */ + cairo_status_t status; + cairo_reference_count_t ref_count; + cairo_user_data_array_t user_data; + + cairo_font_face_t *original_font_face; /* may be NULL */ + + /* hash key members */ + cairo_font_face_t *font_face; /* may be NULL */ + cairo_matrix_t font_matrix; /* font space => user space */ + cairo_matrix_t ctm; /* user space => device space */ + cairo_font_options_t options; + + unsigned int placeholder : 1; /* protected by fontmap mutex */ + unsigned int holdover : 1; + unsigned int finished : 1; + + /* "live" scaled_font members */ + cairo_matrix_t scale; /* font space => device space */ + cairo_matrix_t scale_inverse; /* device space => font space */ + double max_scale; /* maximum x/y expansion of scale */ + cairo_font_extents_t extents; /* user space */ + cairo_font_extents_t fs_extents; /* font space */ + + /* The mutex protects modification to all subsequent fields. */ + cairo_mutex_t mutex; + + cairo_hash_table_t *glyphs; + cairo_list_t glyph_pages; + cairo_bool_t cache_frozen; + cairo_bool_t global_cache_frozen; + + cairo_list_t dev_privates; + + /* font backend managing this scaled font */ + const cairo_scaled_font_backend_t *backend; + cairo_list_t link; +}; + +struct _cairo_scaled_font_private { + cairo_list_t link; + const void *key; + void (*destroy) (cairo_scaled_font_private_t *, + cairo_scaled_font_t *); +}; + +struct _cairo_scaled_glyph { + cairo_hash_entry_t hash_entry; + + cairo_text_extents_t metrics; /* user-space metrics */ + cairo_text_extents_t fs_metrics; /* font-space metrics */ + cairo_box_t bbox; /* device-space bounds */ + int16_t x_advance; /* device-space rounded X advance */ + int16_t y_advance; /* device-space rounded Y advance */ + + unsigned int has_info; + cairo_image_surface_t *surface; /* device-space image */ + cairo_path_fixed_t *path; /* device-space outline */ + cairo_surface_t *recording_surface; /* device-space recording-surface */ + + const void *dev_private_key; + void *dev_private; + cairo_list_t dev_privates; +}; + +struct _cairo_scaled_glyph_private { + cairo_list_t link; + const void *key; + void (*destroy) (cairo_scaled_glyph_private_t *, + cairo_scaled_glyph_t *, + cairo_scaled_font_t *); +}; + +cairo_private cairo_scaled_font_private_t * +_cairo_scaled_font_find_private (cairo_scaled_font_t *scaled_font, + const void *key); + +cairo_private void +_cairo_scaled_font_attach_private (cairo_scaled_font_t *scaled_font, + cairo_scaled_font_private_t *priv, + const void *key, + void (*destroy) (cairo_scaled_font_private_t *, + cairo_scaled_font_t *)); + +cairo_private cairo_scaled_glyph_private_t * +_cairo_scaled_glyph_find_private (cairo_scaled_glyph_t *scaled_glyph, + const void *key); + +cairo_private void +_cairo_scaled_glyph_attach_private (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_glyph_private_t *priv, + const void *key, + void (*destroy) (cairo_scaled_glyph_private_t *, + cairo_scaled_glyph_t *, + cairo_scaled_font_t *)); + +CAIRO_END_DECLS + +#endif /* CAIRO_SCALED_FONT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets-private.h new file mode 100644 index 00000000000..866e63d7bca --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets-private.h @@ -0,0 +1,735 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H +#define CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H + +#include "cairoint.h" + +#if CAIRO_HAS_FONT_SUBSET + +typedef struct _cairo_scaled_font_subsets_glyph { + unsigned int font_id; + unsigned int subset_id; + unsigned int subset_glyph_index; + cairo_bool_t is_scaled; + cairo_bool_t is_composite; + cairo_bool_t is_latin; + double x_advance; + double y_advance; + cairo_bool_t utf8_is_mapped; + uint32_t unicode; +} cairo_scaled_font_subsets_glyph_t; + +/** + * _cairo_scaled_font_subsets_create_scaled: + * + * Create a new #cairo_scaled_font_subsets_t object which can be used + * to create subsets of any number of #cairo_scaled_font_t + * objects. This allows the (arbitrarily large and sparse) glyph + * indices of a #cairo_scaled_font_t to be mapped to one or more font + * subsets with glyph indices packed into the range + * [0 .. max_glyphs_per_subset). + * + * Return value: a pointer to the newly creates font subsets. The + * caller owns this object and should call + * _cairo_scaled_font_subsets_destroy() when done with it. + **/ +cairo_private cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_scaled (void); + +/** + * _cairo_scaled_font_subsets_create_simple: + * + * Create a new #cairo_scaled_font_subsets_t object which can be used + * to create font subsets suitable for embedding as Postscript or PDF + * simple fonts. + * + * Glyphs with an outline path available will be mapped to one font + * subset for each font face. Glyphs from bitmap fonts will mapped to + * separate font subsets for each #cairo_scaled_font_t object. + * + * The maximum number of glyphs per subset is 256. Each subset + * reserves the first glyph for the .notdef glyph. + * + * Return value: a pointer to the newly creates font subsets. The + * caller owns this object and should call + * _cairo_scaled_font_subsets_destroy() when done with it. + **/ +cairo_private cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_simple (void); + +/** + * _cairo_scaled_font_subsets_create_composite: + * + * Create a new #cairo_scaled_font_subsets_t object which can be used + * to create font subsets suitable for embedding as Postscript or PDF + * composite fonts. + * + * Glyphs with an outline path available will be mapped to one font + * subset for each font face. Each unscaled subset has a maximum of + * 65536 glyphs except for Type1 fonts which have a maximum of 256 glyphs. + * + * Glyphs from bitmap fonts will mapped to separate font subsets for + * each #cairo_scaled_font_t object. Each unscaled subset has a maximum + * of 256 glyphs. + * + * Each subset reserves the first glyph for the .notdef glyph. + * + * Return value: a pointer to the newly creates font subsets. The + * caller owns this object and should call + * _cairo_scaled_font_subsets_destroy() when done with it. + **/ +cairo_private cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_composite (void); + +/** + * _cairo_scaled_font_subsets_destroy: + * @font_subsets: a #cairo_scaled_font_subsets_t object to be destroyed + * + * Destroys @font_subsets and all resources associated with it. + **/ +cairo_private void +_cairo_scaled_font_subsets_destroy (cairo_scaled_font_subsets_t *font_subsets); + +/** + * _cairo_scaled_font_subsets_enable_latin_subset: + * @font_subsets: a #cairo_scaled_font_subsets_t object to be destroyed + * @use_latin: a #cairo_bool_t indicating if a latin subset is to be used + * + * If enabled, all CP1252 characters will be placed in a separate + * 8-bit latin subset. + **/ +cairo_private void +_cairo_scaled_font_subsets_enable_latin_subset (cairo_scaled_font_subsets_t *font_subsets, + cairo_bool_t use_latin); + +/** + * _cairo_scaled_font_subsets_map_glyph: + * @font_subsets: a #cairo_scaled_font_subsets_t + * @scaled_font: the font of the glyph to be mapped + * @scaled_font_glyph_index: the index of the glyph to be mapped + * @utf8: a string of text encoded in UTF-8 + * @utf8_len: length of @utf8 in bytes + * @subset_glyph_ret: return structure containing subset font and glyph id + * + * Map a glyph from a #cairo_scaled_font to a new index within a + * subset of that font. The mapping performed is from the tuple: + * + * (scaled_font, scaled_font_glyph_index) + * + * to the tuple: + * + * (font_id, subset_id, subset_glyph_index) + * + * This mapping is 1:1. If the input tuple has previously mapped, the + * the output tuple previously returned will be returned again. + * + * Otherwise, the return tuple will be constructed as follows: + * + * 1) There is a 1:1 correspondence between the input scaled_font + * value and the output font_id value. If no mapping has been + * previously performed with the scaled_font value then the + * smallest unused font_id value will be returned. + * + * 2) Within the set of output tuples of the same font_id value the + * smallest value of subset_id will be returned such that + * subset_glyph_index does not exceed max_glyphs_per_subset (as + * passed to _cairo_scaled_font_subsets_create()) and that the + * resulting tuple is unique. + * + * 3) The smallest value of subset_glyph_index is returned such that + * the resulting tuple is unique. + * + * The net result is that any #cairo_scaled_font_t will be represented + * by one or more font subsets. Each subset is effectively a tuple of + * (scaled_font, font_id, subset_id) and within each subset there + * exists a mapping of scaled_glyph_font_index to subset_glyph_index. + * + * This final description of a font subset is the same representation + * used by #cairo_scaled_font_subset_t as provided by + * _cairo_scaled_font_subsets_foreach. + * + * @utf8 and @utf8_len specify a string of unicode characters that the + * glyph @scaled_font_glyph_index maps to. If @utf8_is_mapped in + * @subset_glyph_ret is %TRUE, the font subsetting will (where index to + * unicode mapping is supported) ensure that @scaled_font_glyph_index + * maps to @utf8. If @utf8_is_mapped is %FALSE, + * @scaled_font_glyph_index has already been mapped to a different + * unicode string. + * + * The returned values in the #cairo_scaled_font_subsets_glyph_t struct are: + * + * @font_id: The font ID of the mapped glyph + * @subset_id : The subset ID of the mapped glyph within the @font_id + * @subset_glyph_index: The index of the mapped glyph within the @subset_id subset + * @is_scaled: If true, the mapped glyph is from a bitmap font, and separate font + * subset is created for each font scale used. If false, the outline of the mapped glyph + * is available. One font subset for each font face is created. + * @x_advance, @y_advance: When @is_scaled is true, @x_advance and @y_advance contain + * the x and y advance for the mapped glyph in device space. + * When @is_scaled is false, @x_advance and @y_advance contain the x and y advance for + * the the mapped glyph from an unhinted 1 point font. + * @utf8_is_mapped: If true the utf8 string provided to _cairo_scaled_font_subsets_map_glyph() + * is (or already was) the utf8 string mapped to this glyph. If false the glyph is already + * mapped to a different utf8 string. + * @unicode: the unicode character mapped to this glyph by the font backend. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero + * value indicating an error. Possible errors include + * %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_t *scaled_font, + unsigned long scaled_font_glyph_index, + const char * utf8, + int utf8_len, + cairo_scaled_font_subsets_glyph_t *subset_glyph_ret); + +typedef cairo_int_status_t +(*cairo_scaled_font_subset_callback_func_t) (cairo_scaled_font_subset_t *font_subset, + void *closure); + +/** + * _cairo_scaled_font_subsets_foreach_scaled: + * @font_subsets: a #cairo_scaled_font_subsets_t + * @font_subset_callback: a function to be called for each font subset + * @closure: closure data for the callback function + * + * Iterate over each unique scaled font subset as created by calls to + * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by + * unique pairs of (font_id, subset_id) as returned by + * _cairo_scaled_font_subsets_map_glyph(). + * + * For each subset, @font_subset_callback will be called and will be + * provided with both a #cairo_scaled_font_subset_t object containing + * all the glyphs in the subset as well as the value of @closure. + * + * The #cairo_scaled_font_subset_t object contains the scaled_font, + * the font_id, and the subset_id corresponding to all glyphs + * belonging to the subset. In addition, it contains an array providing + * a mapping between subset glyph indices and the original scaled font + * glyph indices. + * + * The index of the array corresponds to subset_glyph_index values + * returned by _cairo_scaled_font_subsets_map_glyph() while the + * values of the array correspond to the scaled_font_glyph_index + * values passed as input to the same function. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero + * value indicating an error. Possible errors include + * %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_scaled_font_subsets_foreach_scaled (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure); + +/** + * _cairo_scaled_font_subsets_foreach_unscaled: + * @font_subsets: a #cairo_scaled_font_subsets_t + * @font_subset_callback: a function to be called for each font subset + * @closure: closure data for the callback function + * + * Iterate over each unique unscaled font subset as created by calls to + * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by + * unique pairs of (font_id, subset_id) as returned by + * _cairo_scaled_font_subsets_map_glyph(). + * + * For each subset, @font_subset_callback will be called and will be + * provided with both a #cairo_scaled_font_subset_t object containing + * all the glyphs in the subset as well as the value of @closure. + * + * The #cairo_scaled_font_subset_t object contains the scaled_font, + * the font_id, and the subset_id corresponding to all glyphs + * belonging to the subset. In addition, it contains an array providing + * a mapping between subset glyph indices and the original scaled font + * glyph indices. + * + * The index of the array corresponds to subset_glyph_index values + * returned by _cairo_scaled_font_subsets_map_glyph() while the + * values of the array correspond to the scaled_font_glyph_index + * values passed as input to the same function. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero + * value indicating an error. Possible errors include + * %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_scaled_font_subsets_foreach_unscaled (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure); + +/** + * _cairo_scaled_font_subsets_foreach_user: + * @font_subsets: a #cairo_scaled_font_subsets_t + * @font_subset_callback: a function to be called for each font subset + * @closure: closure data for the callback function + * + * Iterate over each unique scaled font subset as created by calls to + * _cairo_scaled_font_subsets_map_glyph(). A subset is determined by + * unique pairs of (font_id, subset_id) as returned by + * _cairo_scaled_font_subsets_map_glyph(). + * + * For each subset, @font_subset_callback will be called and will be + * provided with both a #cairo_scaled_font_subset_t object containing + * all the glyphs in the subset as well as the value of @closure. + * + * The #cairo_scaled_font_subset_t object contains the scaled_font, + * the font_id, and the subset_id corresponding to all glyphs + * belonging to the subset. In addition, it contains an array providing + * a mapping between subset glyph indices and the original scaled font + * glyph indices. + * + * The index of the array corresponds to subset_glyph_index values + * returned by _cairo_scaled_font_subsets_map_glyph() while the + * values of the array correspond to the scaled_font_glyph_index + * values passed as input to the same function. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero + * value indicating an error. Possible errors include + * %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_scaled_font_subsets_foreach_user (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure); + +/** + * _cairo_scaled_font_subset_create_glyph_names: + * @font_subsets: a #cairo_scaled_font_subsets_t + * + * Create an array of strings containing the glyph name for each glyph + * in @font_subsets. The array as store in font_subsets->glyph_names. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font backend does not support + * mapping the glyph indices to unicode characters. Possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_int_status_t +_cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset); + +typedef struct _cairo_cff_subset { + char *family_name_utf8; + char *ps_name; + double *widths; + double x_min, y_min, x_max, y_max; + double ascent, descent; + char *data; + unsigned long data_length; +} cairo_cff_subset_t; + +/** + * _cairo_cff_subset_init: + * @cff_subset: a #cairo_cff_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a + * cff file corresponding to @font_subset and initialize + * @cff_subset with information about the subset and the cff + * data. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a + * cff file, or an non-zero value indicating an error. Possible + * errors include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_cff_subset_init (cairo_cff_subset_t *cff_subset, + const char *name, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_cff_subset_fini: + * @cff_subset: a #cairo_cff_subset_t + * + * Free all resources associated with @cff_subset. After this + * call, @cff_subset should not be used again without a + * subsequent call to _cairo_cff_subset_init() again first. + **/ +cairo_private void +_cairo_cff_subset_fini (cairo_cff_subset_t *cff_subset); + +/** + * _cairo_cff_scaled_font_is_cid_cff: + * @scaled_font: a #cairo_scaled_font_t + * + * Return %TRUE if @scaled_font is a CID CFF font, otherwise return %FALSE. + **/ +cairo_private cairo_bool_t +_cairo_cff_scaled_font_is_cid_cff (cairo_scaled_font_t *scaled_font); + +/** + * _cairo_cff_fallback_init: + * @cff_subset: a #cairo_cff_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a cff + * file corresponding to @font_subset and initialize @cff_subset + * with information about the subset and the cff data. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a + * cff file, or an non-zero value indicating an error. Possible + * errors include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_cff_fallback_init (cairo_cff_subset_t *cff_subset, + const char *name, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_cff_fallback_fini: + * @cff_subset: a #cairo_cff_subset_t + * + * Free all resources associated with @cff_subset. After this + * call, @cff_subset should not be used again without a + * subsequent call to _cairo_cff_subset_init() again first. + **/ +cairo_private void +_cairo_cff_fallback_fini (cairo_cff_subset_t *cff_subset); + +typedef struct _cairo_truetype_subset { + char *family_name_utf8; + char *ps_name; + double *widths; + double x_min, y_min, x_max, y_max; + double ascent, descent; + unsigned char *data; + unsigned long data_length; + unsigned long *string_offsets; + unsigned long num_string_offsets; +} cairo_truetype_subset_t; + +/** + * _cairo_truetype_subset_init_ps: + * @truetype_subset: a #cairo_truetype_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a + * truetype file corresponding to @font_subset and initialize + * @truetype_subset with information about the subset and the truetype + * data. The generated font will be suitable for embedding in + * PostScript. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a + * truetype file, or an non-zero value indicating an error. Possible + * errors include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_truetype_subset_init_ps (cairo_truetype_subset_t *truetype_subset, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_truetype_subset_init_pdf: + * @truetype_subset: a #cairo_truetype_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a + * truetype file corresponding to @font_subset and initialize + * @truetype_subset with information about the subset and the truetype + * data. The generated font will be suitable for embedding in + * PDF. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a + * truetype file, or an non-zero value indicating an error. Possible + * errors include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_truetype_subset_init_pdf (cairo_truetype_subset_t *truetype_subset, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_truetype_subset_fini: + * @truetype_subset: a #cairo_truetype_subset_t + * + * Free all resources associated with @truetype_subset. After this + * call, @truetype_subset should not be used again without a + * subsequent call to _cairo_truetype_subset_init() again first. + **/ +cairo_private void +_cairo_truetype_subset_fini (cairo_truetype_subset_t *truetype_subset); + +cairo_private const char * +_cairo_ps_standard_encoding_to_glyphname (int glyph); + +cairo_private int +_cairo_unicode_to_winansi (unsigned long unicode); + +cairo_private const char * +_cairo_winansi_to_glyphname (int glyph); + +typedef struct _cairo_type1_subset { + char *base_font; + double *widths; + double x_min, y_min, x_max, y_max; + double ascent, descent; + char *data; + unsigned long header_length; + unsigned long data_length; + unsigned long trailer_length; +} cairo_type1_subset_t; + + +/** + * _cairo_type1_subset_init: + * @type1_subset: a #cairo_type1_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * @hex_encode: if true the encrypted portion of the font is hex encoded + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a type1 + * file corresponding to @font_subset and initialize @type1_subset + * with information about the subset and the type1 data. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1 + * file, or an non-zero value indicating an error. Possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_type1_subset_init (cairo_type1_subset_t *type_subset, + const char *name, + cairo_scaled_font_subset_t *font_subset, + cairo_bool_t hex_encode); + +/** + * _cairo_type1_subset_fini: + * @type1_subset: a #cairo_type1_subset_t + * + * Free all resources associated with @type1_subset. After this call, + * @type1_subset should not be used again without a subsequent call to + * _cairo_truetype_type1_init() again first. + **/ +cairo_private void +_cairo_type1_subset_fini (cairo_type1_subset_t *subset); + +/** + * _cairo_type1_scaled_font_is_type1: + * @scaled_font: a #cairo_scaled_font_t + * + * Return %TRUE if @scaled_font is a Type 1 font, otherwise return %FALSE. + **/ +cairo_private cairo_bool_t +_cairo_type1_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font); + +/** + * _cairo_type1_fallback_init_binary: + * @type1_subset: a #cairo_type1_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a type1 + * file corresponding to @font_subset and initialize @type1_subset + * with information about the subset and the type1 data. The encrypted + * part of the font is binary encoded. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1 + * file, or an non-zero value indicating an error. Possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_type1_fallback_init_binary (cairo_type1_subset_t *type_subset, + const char *name, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_type1_fallback_init_hex: + * @type1_subset: a #cairo_type1_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate a type1 + * file corresponding to @font_subset and initialize @type1_subset + * with information about the subset and the type1 data. The encrypted + * part of the font is hex encoded. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1 + * file, or an non-zero value indicating an error. Possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_type1_fallback_init_hex (cairo_type1_subset_t *type_subset, + const char *name, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_type1_fallback_fini: + * @type1_subset: a #cairo_type1_subset_t + * + * Free all resources associated with @type1_subset. After this call, + * @type1_subset should not be used again without a subsequent call to + * _cairo_truetype_type1_init() again first. + **/ +cairo_private void +_cairo_type1_fallback_fini (cairo_type1_subset_t *subset); + +typedef struct _cairo_type2_charstrings { + int *widths; + long x_min, y_min, x_max, y_max; + long ascent, descent; + cairo_array_t charstrings; +} cairo_type2_charstrings_t; + +/** + * _cairo_type2_charstrings_init: + * @type2_subset: a #cairo_type2_subset_t to initialize + * @font_subset: the #cairo_scaled_font_subset_t to initialize from + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) generate type2 + * charstrings to @font_subset and initialize @type2_subset + * with information about the subset. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type2 + * charstrings, or an non-zero value indicating an error. Possible errors + * include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_status_t +_cairo_type2_charstrings_init (cairo_type2_charstrings_t *charstrings, + cairo_scaled_font_subset_t *font_subset); + +/** + * _cairo_type2_charstrings_fini: + * @subset: a #cairo_type2_charstrings_t + * + * Free all resources associated with @type2_charstring. After this call, + * @type2_charstring should not be used again without a subsequent call to + * _cairo_type2_charstring_init() again first. + **/ +cairo_private void +_cairo_type2_charstrings_fini (cairo_type2_charstrings_t *charstrings); + +/** + * _cairo_truetype_index_to_ucs4: + * @scaled_font: the #cairo_scaled_font_t + * @index: the glyph index + * @ucs4: return value for the unicode value of the glyph + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) assign + * the unicode character of the glyph to @ucs4. + * + * If mapping glyph indices to unicode is supported but the unicode + * value of the specified glyph is not available, @ucs4 is set to -1. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if mapping glyph indices to unicode + * is not supported. Possible errors include %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_int_status_t +_cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font, + unsigned long index, + uint32_t *ucs4); + +/** + * _cairo_truetype_read_font_name: + * @scaled_font: the #cairo_scaled_font_t + * @ps_name: returns the PostScript name of the font + * or %NULL if the name could not be found. + * @font_name: returns the font name or %NULL if the name could not be found. + * + * If possible (depending on the format of the underlying + * #cairo_scaled_font_t and the font backend in use) read the + * PostScript and Font names from a TrueType/OpenType font. + * + * The font name is the full name of the font eg "DejaVu Sans Bold". + * The PostScript name is a shortened name with spaces removed + * suitable for use as the font name in a PS or PDF file eg + * "DejaVuSans-Bold". + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font is not TrueType/OpenType + * or the name table is not present. Possible errors include + * %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_int_status_t +_cairo_truetype_read_font_name (cairo_scaled_font_t *scaled_font, + char **ps_name, + char **font_name); + +/** + * _cairo_truetype_get_style: + * @scaled_font: the #cairo_scaled_font_t + * @weight: returns the font weight from the OS/2 table + * @bold: returns true if font is bold + * @italic: returns true if font is italic + * + * If the font is a truetype/opentype font with an OS/2 table, get the + * weight, bold, and italic data from the OS/2 table. The weight + * values have the same meaning as the lfWeight field of the Windows + * LOGFONT structure. Refer to the TrueType Specification for + * definition of the weight values. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful, + * %CAIRO_INT_STATUS_UNSUPPORTED if the font is not TrueType/OpenType + * or the OS/2 table is not present. + **/ +cairo_private cairo_int_status_t +_cairo_truetype_get_style (cairo_scaled_font_t *scaled_font, + int *weight, + cairo_bool_t *bold, + cairo_bool_t *italic); + +/** + * _cairo_escape_ps_name: + * @ps_name: returns the PostScript name with all invalid characters escaped + * + * Ensure that PostSript name is a valid PDF/PostSript name object. + * In PDF names are treated as UTF8 and non ASCII bytes, ' ', + * and '#' are encoded as '#' followed by 2 hex digits that + * encode the byte. + * + * Return value: %CAIRO_STATUS_SUCCESS if successful. Possible errors include + * %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_private cairo_int_status_t +_cairo_escape_ps_name (char **ps_name); + +#endif /* CAIRO_HAS_FONT_SUBSET */ + +#endif /* CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets.c b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets.c new file mode 100644 index 00000000000..196fa999aa7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font-subsets.c @@ -0,0 +1,1301 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2003 University of Southern California + * Copyright © 2005 Red Hat, Inc + * Copyright © 2006 Keith Packard + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Kristian Høgsberg + * Keith Packard + * Adrian Johnson + */ + +#define _BSD_SOURCE /* for snprintf(), strdup() */ +#include "cairoint.h" +#include "cairo-error-private.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-user-font-private.h" + +#define MAX_GLYPHS_PER_SIMPLE_FONT 256 +#define MAX_GLYPHS_PER_COMPOSITE_FONT 65536 + +typedef enum { + CAIRO_SUBSETS_SCALED, + CAIRO_SUBSETS_SIMPLE, + CAIRO_SUBSETS_COMPOSITE +} cairo_subsets_type_t; + +typedef enum { + CAIRO_SUBSETS_FOREACH_UNSCALED, + CAIRO_SUBSETS_FOREACH_SCALED, + CAIRO_SUBSETS_FOREACH_USER +} cairo_subsets_foreach_type_t; + +typedef struct _cairo_sub_font { + cairo_hash_entry_t base; + + cairo_bool_t is_scaled; + cairo_bool_t is_composite; + cairo_bool_t is_user; + cairo_bool_t use_latin_subset; + cairo_scaled_font_subsets_t *parent; + cairo_scaled_font_t *scaled_font; + unsigned int font_id; + + int current_subset; + int num_glyphs_in_current_subset; + int num_glyphs_in_latin_subset; + int max_glyphs_per_subset; + char latin_char_map[256]; + + cairo_hash_table_t *sub_font_glyphs; + struct _cairo_sub_font *next; +} cairo_sub_font_t; + +struct _cairo_scaled_font_subsets { + cairo_subsets_type_t type; + cairo_bool_t use_latin_subset; + + int max_glyphs_per_unscaled_subset_used; + cairo_hash_table_t *unscaled_sub_fonts; + cairo_sub_font_t *unscaled_sub_fonts_list; + cairo_sub_font_t *unscaled_sub_fonts_list_end; + + int max_glyphs_per_scaled_subset_used; + cairo_hash_table_t *scaled_sub_fonts; + cairo_sub_font_t *scaled_sub_fonts_list; + cairo_sub_font_t *scaled_sub_fonts_list_end; + + int num_sub_fonts; +}; + +typedef struct _cairo_sub_font_glyph { + cairo_hash_entry_t base; + + unsigned int subset_id; + unsigned int subset_glyph_index; + double x_advance; + double y_advance; + + cairo_bool_t is_latin; + int latin_character; + cairo_bool_t is_mapped; + uint32_t unicode; + char *utf8; + int utf8_len; +} cairo_sub_font_glyph_t; + +typedef struct _cairo_sub_font_collection { + unsigned long *glyphs; /* scaled_font_glyph_index */ + char **utf8; + unsigned int glyphs_size; + int *to_latin_char; + unsigned long *latin_to_subset_glyph_index; + unsigned int max_glyph; + unsigned int num_glyphs; + + unsigned int subset_id; + + cairo_status_t status; + cairo_scaled_font_subset_callback_func_t font_subset_callback; + void *font_subset_callback_closure; +} cairo_sub_font_collection_t; + +typedef struct _cairo_string_entry { + cairo_hash_entry_t base; + char *string; +} cairo_string_entry_t; + +static cairo_status_t +_cairo_sub_font_map_glyph (cairo_sub_font_t *sub_font, + unsigned long scaled_font_glyph_index, + const char * utf8, + int utf8_len, + cairo_scaled_font_subsets_glyph_t *subset_glyph); + +static void +_cairo_sub_font_glyph_init_key (cairo_sub_font_glyph_t *sub_font_glyph, + unsigned long scaled_font_glyph_index) +{ + sub_font_glyph->base.hash = scaled_font_glyph_index; +} + +static cairo_sub_font_glyph_t * +_cairo_sub_font_glyph_create (unsigned long scaled_font_glyph_index, + unsigned int subset_id, + unsigned int subset_glyph_index, + double x_advance, + double y_advance, + int latin_character, + uint32_t unicode, + char *utf8, + int utf8_len) +{ + cairo_sub_font_glyph_t *sub_font_glyph; + + sub_font_glyph = malloc (sizeof (cairo_sub_font_glyph_t)); + if (unlikely (sub_font_glyph == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + _cairo_sub_font_glyph_init_key (sub_font_glyph, scaled_font_glyph_index); + sub_font_glyph->subset_id = subset_id; + sub_font_glyph->subset_glyph_index = subset_glyph_index; + sub_font_glyph->x_advance = x_advance; + sub_font_glyph->y_advance = y_advance; + sub_font_glyph->is_latin = (latin_character >= 0); + sub_font_glyph->latin_character = latin_character; + sub_font_glyph->is_mapped = FALSE; + sub_font_glyph->unicode = unicode; + sub_font_glyph->utf8 = utf8; + sub_font_glyph->utf8_len = utf8_len; + + return sub_font_glyph; +} + +static void +_cairo_sub_font_glyph_destroy (cairo_sub_font_glyph_t *sub_font_glyph) +{ + free (sub_font_glyph->utf8); + + free (sub_font_glyph); +} + +static void +_cairo_sub_font_glyph_pluck (void *entry, void *closure) +{ + cairo_sub_font_glyph_t *sub_font_glyph = entry; + cairo_hash_table_t *sub_font_glyphs = closure; + + _cairo_hash_table_remove (sub_font_glyphs, &sub_font_glyph->base); + _cairo_sub_font_glyph_destroy (sub_font_glyph); +} + +static void +_cairo_sub_font_glyph_collect (void *entry, void *closure) +{ + cairo_sub_font_glyph_t *sub_font_glyph = entry; + cairo_sub_font_collection_t *collection = closure; + unsigned long scaled_font_glyph_index; + unsigned int subset_glyph_index; + + if (sub_font_glyph->subset_id != collection->subset_id) + return; + + scaled_font_glyph_index = sub_font_glyph->base.hash; + subset_glyph_index = sub_font_glyph->subset_glyph_index; + + /* Ensure we don't exceed the allocated bounds. */ + assert (subset_glyph_index < collection->glyphs_size); + + collection->glyphs[subset_glyph_index] = scaled_font_glyph_index; + collection->utf8[subset_glyph_index] = sub_font_glyph->utf8; + collection->to_latin_char[subset_glyph_index] = sub_font_glyph->latin_character; + if (sub_font_glyph->is_latin) + collection->latin_to_subset_glyph_index[sub_font_glyph->latin_character] = subset_glyph_index; + + if (subset_glyph_index > collection->max_glyph) + collection->max_glyph = subset_glyph_index; + + collection->num_glyphs++; +} + +static cairo_bool_t +_cairo_sub_fonts_equal (const void *key_a, const void *key_b) +{ + const cairo_sub_font_t *sub_font_a = key_a; + const cairo_sub_font_t *sub_font_b = key_b; + cairo_scaled_font_t *a = sub_font_a->scaled_font; + cairo_scaled_font_t *b = sub_font_b->scaled_font; + + if (sub_font_a->is_scaled) + return a == b; + else + return a->font_face == b->font_face || a->original_font_face == b->original_font_face; +} + +static void +_cairo_sub_font_init_key (cairo_sub_font_t *sub_font, + cairo_scaled_font_t *scaled_font) +{ + if (sub_font->is_scaled) + { + sub_font->base.hash = (unsigned long) scaled_font; + sub_font->scaled_font = scaled_font; + } + else + { + sub_font->base.hash = (unsigned long) scaled_font->font_face; + sub_font->scaled_font = scaled_font; + } +} + +static cairo_status_t +_cairo_sub_font_create (cairo_scaled_font_subsets_t *parent, + cairo_scaled_font_t *scaled_font, + unsigned int font_id, + int max_glyphs_per_subset, + cairo_bool_t is_scaled, + cairo_bool_t is_composite, + cairo_sub_font_t **sub_font_out) +{ + cairo_sub_font_t *sub_font; + int i; + + sub_font = malloc (sizeof (cairo_sub_font_t)); + if (unlikely (sub_font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + sub_font->is_scaled = is_scaled; + sub_font->is_composite = is_composite; + sub_font->is_user = _cairo_font_face_is_user (scaled_font->font_face); + _cairo_sub_font_init_key (sub_font, scaled_font); + + sub_font->parent = parent; + sub_font->scaled_font = scaled_font; + sub_font->font_id = font_id; + + sub_font->use_latin_subset = parent->use_latin_subset; + + /* latin subsets of Type 3 and CID CFF fonts are not supported */ + if (sub_font->is_user || sub_font->is_scaled || + _cairo_cff_scaled_font_is_cid_cff (scaled_font) ) + { + sub_font->use_latin_subset = FALSE; + } + + if (sub_font->use_latin_subset) + sub_font->current_subset = 1; /* reserve subset 0 for latin glyphs */ + else + sub_font->current_subset = 0; + + sub_font->num_glyphs_in_current_subset = 0; + sub_font->num_glyphs_in_latin_subset = 0; + sub_font->max_glyphs_per_subset = max_glyphs_per_subset; + for (i = 0; i < 256; i++) + sub_font->latin_char_map[i] = FALSE; + + sub_font->sub_font_glyphs = _cairo_hash_table_create (NULL); + if (unlikely (sub_font->sub_font_glyphs == NULL)) { + free (sub_font); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + sub_font->next = NULL; + *sub_font_out = sub_font; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_sub_font_destroy (cairo_sub_font_t *sub_font) +{ + _cairo_hash_table_foreach (sub_font->sub_font_glyphs, + _cairo_sub_font_glyph_pluck, + sub_font->sub_font_glyphs); + _cairo_hash_table_destroy (sub_font->sub_font_glyphs); + cairo_scaled_font_destroy (sub_font->scaled_font); + free (sub_font); +} + +static void +_cairo_sub_font_pluck (void *entry, void *closure) +{ + cairo_sub_font_t *sub_font = entry; + cairo_hash_table_t *sub_fonts = closure; + + _cairo_hash_table_remove (sub_fonts, &sub_font->base); + _cairo_sub_font_destroy (sub_font); +} + +/* Characters 0x80 to 0x9f in the winansi encoding. + * All other characters in the range 0x00 to 0xff map 1:1 to unicode */ +static unsigned int _winansi_0x80_to_0x9f[] = { + 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, + 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, + 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178 +}; + +int +_cairo_unicode_to_winansi (unsigned long uni) +{ + int i; + + /* exclude the extra "hyphen" at 0xad to avoid duplicate glyphnames */ + if ((uni >= 0x20 && uni <= 0x7e) || + (uni >= 0xa1 && uni <= 0xff && uni != 0xad) || + uni == 0) + return uni; + + for (i = 0; i < 32; i++) + if (_winansi_0x80_to_0x9f[i] == uni) + return i + 0x80; + + return -1; +} + +static cairo_status_t +_cairo_sub_font_glyph_lookup_unicode (cairo_scaled_font_t *scaled_font, + unsigned long scaled_font_glyph_index, + uint32_t *unicode_out, + char **utf8_out, + int *utf8_len_out) +{ + uint32_t unicode; + char buf[8]; + int len; + cairo_status_t status; + + /* Do a reverse lookup on the glyph index. unicode is -1 if the + * index could not be mapped to a unicode character. */ + unicode = -1; + status = _cairo_truetype_index_to_ucs4 (scaled_font, + scaled_font_glyph_index, + &unicode); + if (_cairo_status_is_error (status)) + return status; + + if (unicode == (uint32_t)-1 && scaled_font->backend->index_to_ucs4) { + status = scaled_font->backend->index_to_ucs4 (scaled_font, + scaled_font_glyph_index, + &unicode); + if (unlikely (status)) + return status; + } + + *unicode_out = unicode; + *utf8_out = NULL; + *utf8_len_out = 0; + if (unicode != (uint32_t) -1) { + len = _cairo_ucs4_to_utf8 (unicode, buf); + if (len > 0) { + *utf8_out = malloc (len + 1); + if (unlikely (*utf8_out == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (*utf8_out, buf, len); + (*utf8_out)[len] = 0; + *utf8_len_out = len; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_sub_font_glyph_map_to_unicode (cairo_sub_font_glyph_t *sub_font_glyph, + const char *utf8, + int utf8_len, + cairo_bool_t *is_mapped) +{ + *is_mapped = FALSE; + + if (utf8_len < 0) + return CAIRO_STATUS_SUCCESS; + + if (utf8 != NULL && utf8_len != 0 && utf8[utf8_len - 1] == '\0') + utf8_len--; + + if (utf8 != NULL && utf8_len != 0) { + if (sub_font_glyph->utf8 != NULL) { + if (utf8_len == sub_font_glyph->utf8_len && + memcmp (utf8, sub_font_glyph->utf8, utf8_len) == 0) + { + /* Requested utf8 mapping matches the existing mapping */ + *is_mapped = TRUE; + } + } else { + /* No existing mapping. Use the requested mapping */ + sub_font_glyph->utf8 = malloc (utf8_len + 1); + if (unlikely (sub_font_glyph->utf8 == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (sub_font_glyph->utf8, utf8, utf8_len); + sub_font_glyph->utf8[utf8_len] = 0; + sub_font_glyph->utf8_len = utf8_len; + *is_mapped = TRUE; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_sub_font_lookup_glyph (cairo_sub_font_t *sub_font, + unsigned long scaled_font_glyph_index, + const char *utf8, + int utf8_len, + cairo_scaled_font_subsets_glyph_t *subset_glyph) +{ + cairo_sub_font_glyph_t key, *sub_font_glyph; + cairo_int_status_t status; + + _cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index); + sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs, + &key.base); + if (sub_font_glyph != NULL) { + subset_glyph->font_id = sub_font->font_id; + subset_glyph->subset_id = sub_font_glyph->subset_id; + if (sub_font_glyph->is_latin) + subset_glyph->subset_glyph_index = sub_font_glyph->latin_character; + else + subset_glyph->subset_glyph_index = sub_font_glyph->subset_glyph_index; + + subset_glyph->is_scaled = sub_font->is_scaled; + subset_glyph->is_composite = sub_font->is_composite; + subset_glyph->is_latin = sub_font_glyph->is_latin; + subset_glyph->x_advance = sub_font_glyph->x_advance; + subset_glyph->y_advance = sub_font_glyph->y_advance; + status = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph, + utf8, utf8_len, + &subset_glyph->utf8_is_mapped); + subset_glyph->unicode = sub_font_glyph->unicode; + + return status; + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_status_t +_cairo_sub_font_add_glyph (cairo_sub_font_t *sub_font, + unsigned long scaled_font_glyph_index, + cairo_bool_t is_latin, + int latin_character, + uint32_t unicode, + char *utf8, + int utf8_len, + cairo_sub_font_glyph_t **sub_font_glyph_out) +{ + cairo_scaled_glyph_t *scaled_glyph; + cairo_sub_font_glyph_t *sub_font_glyph; + int *num_glyphs_in_subset_ptr; + double x_advance; + double y_advance; + cairo_int_status_t status; + + _cairo_scaled_font_freeze_cache (sub_font->scaled_font); + status = _cairo_scaled_glyph_lookup (sub_font->scaled_font, + scaled_font_glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + assert (status != CAIRO_INT_STATUS_UNSUPPORTED); + if (unlikely (status)) { + _cairo_scaled_font_thaw_cache (sub_font->scaled_font); + return status; + } + + x_advance = scaled_glyph->metrics.x_advance; + y_advance = scaled_glyph->metrics.y_advance; + _cairo_scaled_font_thaw_cache (sub_font->scaled_font); + + if (!is_latin && sub_font->num_glyphs_in_current_subset == sub_font->max_glyphs_per_subset) + { + sub_font->current_subset++; + sub_font->num_glyphs_in_current_subset = 0; + } + + if (is_latin) + num_glyphs_in_subset_ptr = &sub_font->num_glyphs_in_latin_subset; + else + num_glyphs_in_subset_ptr = &sub_font->num_glyphs_in_current_subset; + + /* Reserve first glyph in subset for the .notdef glyph except for + * Type 3 fonts */ + if (*num_glyphs_in_subset_ptr == 0 && + scaled_font_glyph_index != 0 && + ! _cairo_font_face_is_user (sub_font->scaled_font->font_face)) + { + status = _cairo_sub_font_add_glyph (sub_font, + 0, + is_latin, + 0, + 0, + NULL, + -1, + &sub_font_glyph); + if (unlikely (status)) + return status; + } + + sub_font_glyph = _cairo_sub_font_glyph_create (scaled_font_glyph_index, + is_latin ? 0 : sub_font->current_subset, + *num_glyphs_in_subset_ptr, + x_advance, + y_advance, + is_latin ? latin_character : -1, + unicode, + utf8, + utf8_len); + + if (unlikely (sub_font_glyph == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_hash_table_insert (sub_font->sub_font_glyphs, &sub_font_glyph->base); + if (unlikely (status)) { + _cairo_sub_font_glyph_destroy (sub_font_glyph); + return status; + } + + (*num_glyphs_in_subset_ptr)++; + if (sub_font->is_scaled) { + if (*num_glyphs_in_subset_ptr > sub_font->parent->max_glyphs_per_scaled_subset_used) + sub_font->parent->max_glyphs_per_scaled_subset_used = *num_glyphs_in_subset_ptr; + } else { + if (*num_glyphs_in_subset_ptr > sub_font->parent->max_glyphs_per_unscaled_subset_used) + sub_font->parent->max_glyphs_per_unscaled_subset_used = *num_glyphs_in_subset_ptr; + } + + *sub_font_glyph_out = sub_font_glyph; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_sub_font_map_glyph (cairo_sub_font_t *sub_font, + unsigned long scaled_font_glyph_index, + const char *text_utf8, + int text_utf8_len, + cairo_scaled_font_subsets_glyph_t *subset_glyph) +{ + cairo_sub_font_glyph_t key, *sub_font_glyph; + cairo_status_t status; + + _cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index); + sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs, + &key.base); + if (sub_font_glyph == NULL) { + uint32_t font_unicode; + char *font_utf8; + int font_utf8_len; + cairo_bool_t is_latin; + int latin_character; + + status = _cairo_sub_font_glyph_lookup_unicode (sub_font->scaled_font, + scaled_font_glyph_index, + &font_unicode, + &font_utf8, + &font_utf8_len); + if (unlikely(status)) + return status; + + /* If the supplied utf8 is a valid single character, use it + * instead of the font lookup */ + if (text_utf8 != NULL && text_utf8_len > 0) { + uint32_t *ucs4; + int ucs4_len; + + status = _cairo_utf8_to_ucs4 (text_utf8, text_utf8_len, + &ucs4, &ucs4_len); + if (status == CAIRO_STATUS_SUCCESS) { + if (ucs4_len == 1) { + font_unicode = ucs4[0]; + free (font_utf8); + font_utf8 = malloc (text_utf8_len + 1); + if (font_utf8 == NULL) { + free (ucs4); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + memcpy (font_utf8, text_utf8, text_utf8_len); + font_utf8[text_utf8_len] = 0; + font_utf8_len = text_utf8_len; + } + free (ucs4); + } + } + + /* If glyph is in the winansi encoding and font is not a user + * font, put glyph in the latin subset. If glyph is .notdef + * the latin subset is preferred but only if the latin subset + * already contains at least one glyph. We don't want to + * create a separate subset just for the .notdef glyph. + */ + is_latin = FALSE; + latin_character = -1; + if (sub_font->use_latin_subset && + (! _cairo_font_face_is_user (sub_font->scaled_font->font_face))) + { + latin_character = _cairo_unicode_to_winansi (font_unicode); + if (latin_character > 0 || + (latin_character == 0 && sub_font->num_glyphs_in_latin_subset > 0)) + { + if (!sub_font->latin_char_map[latin_character]) { + sub_font->latin_char_map[latin_character] = TRUE; + is_latin = TRUE; + } + } + } + + status = _cairo_sub_font_add_glyph (sub_font, + scaled_font_glyph_index, + is_latin, + latin_character, + font_unicode, + font_utf8, + font_utf8_len, + &sub_font_glyph); + if (unlikely(status)) + return status; + } + + subset_glyph->font_id = sub_font->font_id; + subset_glyph->subset_id = sub_font_glyph->subset_id; + if (sub_font_glyph->is_latin) + subset_glyph->subset_glyph_index = sub_font_glyph->latin_character; + else + subset_glyph->subset_glyph_index = sub_font_glyph->subset_glyph_index; + + subset_glyph->is_scaled = sub_font->is_scaled; + subset_glyph->is_composite = sub_font->is_composite; + subset_glyph->is_latin = sub_font_glyph->is_latin; + subset_glyph->x_advance = sub_font_glyph->x_advance; + subset_glyph->y_advance = sub_font_glyph->y_advance; + status = _cairo_sub_font_glyph_map_to_unicode (sub_font_glyph, + text_utf8, text_utf8_len, + &subset_glyph->utf8_is_mapped); + subset_glyph->unicode = sub_font_glyph->unicode; + + return status; +} + +static void +_cairo_sub_font_collect (void *entry, void *closure) +{ + cairo_sub_font_t *sub_font = entry; + cairo_sub_font_collection_t *collection = closure; + cairo_scaled_font_subset_t subset; + int i; + unsigned int j; + + if (collection->status) + return; + + collection->status = sub_font->scaled_font->status; + if (collection->status) + return; + + for (i = 0; i <= sub_font->current_subset; i++) { + collection->subset_id = i; + collection->num_glyphs = 0; + collection->max_glyph = 0; + memset (collection->latin_to_subset_glyph_index, 0, 256*sizeof(unsigned long)); + + _cairo_hash_table_foreach (sub_font->sub_font_glyphs, + _cairo_sub_font_glyph_collect, collection); + if (collection->status) + break; + if (collection->num_glyphs == 0) + continue; + + /* Ensure the resulting array has no uninitialized holes */ + assert (collection->num_glyphs == collection->max_glyph + 1); + + subset.scaled_font = sub_font->scaled_font; + subset.is_composite = sub_font->is_composite; + subset.is_scaled = sub_font->is_scaled; + subset.font_id = sub_font->font_id; + subset.subset_id = i; + subset.glyphs = collection->glyphs; + subset.utf8 = collection->utf8; + subset.num_glyphs = collection->num_glyphs; + subset.glyph_names = NULL; + + subset.is_latin = FALSE; + if (sub_font->use_latin_subset && i == 0) { + subset.is_latin = TRUE; + subset.to_latin_char = collection->to_latin_char; + subset.latin_to_subset_glyph_index = collection->latin_to_subset_glyph_index; + } else { + subset.to_latin_char = NULL; + subset.latin_to_subset_glyph_index = NULL; + } + + collection->status = (collection->font_subset_callback) (&subset, + collection->font_subset_callback_closure); + + if (subset.glyph_names != NULL) { + for (j = 0; j < collection->num_glyphs; j++) + free (subset.glyph_names[j]); + free (subset.glyph_names); + } + + if (collection->status) + break; + } +} + +static cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_internal (cairo_subsets_type_t type) +{ + cairo_scaled_font_subsets_t *subsets; + + subsets = malloc (sizeof (cairo_scaled_font_subsets_t)); + if (unlikely (subsets == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; + } + + subsets->type = type; + subsets->use_latin_subset = FALSE; + subsets->max_glyphs_per_unscaled_subset_used = 0; + subsets->max_glyphs_per_scaled_subset_used = 0; + subsets->num_sub_fonts = 0; + + subsets->unscaled_sub_fonts = _cairo_hash_table_create (_cairo_sub_fonts_equal); + if (! subsets->unscaled_sub_fonts) { + free (subsets); + return NULL; + } + subsets->unscaled_sub_fonts_list = NULL; + subsets->unscaled_sub_fonts_list_end = NULL; + + subsets->scaled_sub_fonts = _cairo_hash_table_create (_cairo_sub_fonts_equal); + if (! subsets->scaled_sub_fonts) { + _cairo_hash_table_destroy (subsets->unscaled_sub_fonts); + free (subsets); + return NULL; + } + subsets->scaled_sub_fonts_list = NULL; + subsets->scaled_sub_fonts_list_end = NULL; + + return subsets; +} + +cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_scaled (void) +{ + return _cairo_scaled_font_subsets_create_internal (CAIRO_SUBSETS_SCALED); +} + +cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_simple (void) +{ + return _cairo_scaled_font_subsets_create_internal (CAIRO_SUBSETS_SIMPLE); +} + +cairo_scaled_font_subsets_t * +_cairo_scaled_font_subsets_create_composite (void) +{ + return _cairo_scaled_font_subsets_create_internal (CAIRO_SUBSETS_COMPOSITE); +} + +void +_cairo_scaled_font_subsets_destroy (cairo_scaled_font_subsets_t *subsets) +{ + _cairo_hash_table_foreach (subsets->scaled_sub_fonts, _cairo_sub_font_pluck, subsets->scaled_sub_fonts); + _cairo_hash_table_destroy (subsets->scaled_sub_fonts); + + _cairo_hash_table_foreach (subsets->unscaled_sub_fonts, _cairo_sub_font_pluck, subsets->unscaled_sub_fonts); + _cairo_hash_table_destroy (subsets->unscaled_sub_fonts); + + free (subsets); +} + +void +_cairo_scaled_font_subsets_enable_latin_subset (cairo_scaled_font_subsets_t *font_subsets, + cairo_bool_t use_latin) +{ + font_subsets->use_latin_subset = use_latin; +} + +cairo_status_t +_cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t *subsets, + cairo_scaled_font_t *scaled_font, + unsigned long scaled_font_glyph_index, + const char * utf8, + int utf8_len, + cairo_scaled_font_subsets_glyph_t *subset_glyph) +{ + cairo_sub_font_t key, *sub_font; + cairo_scaled_glyph_t *scaled_glyph; + cairo_font_face_t *font_face; + cairo_matrix_t identity; + cairo_font_options_t font_options; + cairo_scaled_font_t *unscaled_font; + cairo_int_status_t status; + int max_glyphs; + cairo_bool_t type1_font; + + /* Lookup glyph in unscaled subsets */ + if (subsets->type != CAIRO_SUBSETS_SCALED) { + key.is_scaled = FALSE; + _cairo_sub_font_init_key (&key, scaled_font); + sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts, + &key.base); + if (sub_font != NULL) { + status = _cairo_sub_font_lookup_glyph (sub_font, + scaled_font_glyph_index, + utf8, utf8_len, + subset_glyph); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + } + + /* Lookup glyph in scaled subsets */ + key.is_scaled = TRUE; + _cairo_sub_font_init_key (&key, scaled_font); + sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts, + &key.base); + if (sub_font != NULL) { + status = _cairo_sub_font_lookup_glyph (sub_font, + scaled_font_glyph_index, + utf8, utf8_len, + subset_glyph); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + /* Glyph not found. Determine whether the glyph is outline or + * bitmap and add to the appropriate subset. + * + * glyph_index 0 (the .notdef glyph) is a special case. Some fonts + * will return CAIRO_INT_STATUS_UNSUPPORTED when doing a + * _scaled_glyph_lookup(_GLYPH_INFO_PATH). Type1-fallback creates + * empty glyphs in this case so we can put the glyph in a unscaled + * subset. */ + if (scaled_font_glyph_index == 0 || + _cairo_font_face_is_user (scaled_font->font_face)) { + status = CAIRO_STATUS_SUCCESS; + } else { + _cairo_scaled_font_freeze_cache (scaled_font); + status = _cairo_scaled_glyph_lookup (scaled_font, + scaled_font_glyph_index, + CAIRO_SCALED_GLYPH_INFO_PATH, + &scaled_glyph); + _cairo_scaled_font_thaw_cache (scaled_font); + } + if (_cairo_int_status_is_error (status)) + return status; + + if (status == CAIRO_INT_STATUS_SUCCESS && + subsets->type != CAIRO_SUBSETS_SCALED && + ! _cairo_font_face_is_user (scaled_font->font_face)) + { + /* Path available. Add to unscaled subset. */ + key.is_scaled = FALSE; + _cairo_sub_font_init_key (&key, scaled_font); + sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts, + &key.base); + if (sub_font == NULL) { + font_face = cairo_scaled_font_get_font_face (scaled_font); + cairo_matrix_init_identity (&identity); + _cairo_font_options_init_default (&font_options); + cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF); + unscaled_font = cairo_scaled_font_create (font_face, + &identity, + &identity, + &font_options); + if (unlikely (unscaled_font->status)) + return unscaled_font->status; + + subset_glyph->is_scaled = FALSE; + type1_font = _cairo_type1_scaled_font_is_type1 (unscaled_font); + if (subsets->type == CAIRO_SUBSETS_COMPOSITE && !type1_font) { + max_glyphs = MAX_GLYPHS_PER_COMPOSITE_FONT; + subset_glyph->is_composite = TRUE; + } else { + max_glyphs = MAX_GLYPHS_PER_SIMPLE_FONT; + subset_glyph->is_composite = FALSE; + } + + status = _cairo_sub_font_create (subsets, + unscaled_font, + subsets->num_sub_fonts, + max_glyphs, + subset_glyph->is_scaled, + subset_glyph->is_composite, + &sub_font); + + if (unlikely (status)) { + cairo_scaled_font_destroy (unscaled_font); + return status; + } + + status = _cairo_hash_table_insert (subsets->unscaled_sub_fonts, + &sub_font->base); + + if (unlikely (status)) { + _cairo_sub_font_destroy (sub_font); + return status; + } + if (!subsets->unscaled_sub_fonts_list) + subsets->unscaled_sub_fonts_list = sub_font; + else + subsets->unscaled_sub_fonts_list_end->next = sub_font; + subsets->unscaled_sub_fonts_list_end = sub_font; + subsets->num_sub_fonts++; + } + } else { + /* No path available. Add to scaled subset. */ + key.is_scaled = TRUE; + _cairo_sub_font_init_key (&key, scaled_font); + sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts, + &key.base); + if (sub_font == NULL) { + subset_glyph->is_scaled = TRUE; + subset_glyph->is_composite = FALSE; + if (subsets->type == CAIRO_SUBSETS_SCALED) + max_glyphs = INT_MAX; + else + max_glyphs = MAX_GLYPHS_PER_SIMPLE_FONT; + + status = _cairo_sub_font_create (subsets, + cairo_scaled_font_reference (scaled_font), + subsets->num_sub_fonts, + max_glyphs, + subset_glyph->is_scaled, + subset_glyph->is_composite, + &sub_font); + if (unlikely (status)) { + cairo_scaled_font_destroy (scaled_font); + return status; + } + + status = _cairo_hash_table_insert (subsets->scaled_sub_fonts, + &sub_font->base); + if (unlikely (status)) { + _cairo_sub_font_destroy (sub_font); + return status; + } + if (!subsets->scaled_sub_fonts_list) + subsets->scaled_sub_fonts_list = sub_font; + else + subsets->scaled_sub_fonts_list_end->next = sub_font; + subsets->scaled_sub_fonts_list_end = sub_font; + subsets->num_sub_fonts++; + } + } + + return _cairo_sub_font_map_glyph (sub_font, + scaled_font_glyph_index, + utf8, utf8_len, + subset_glyph); +} + +static cairo_status_t +_cairo_scaled_font_subsets_foreach_internal (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure, + cairo_subsets_foreach_type_t type) +{ + cairo_sub_font_collection_t collection; + cairo_sub_font_t *sub_font; + cairo_bool_t is_scaled, is_user; + + is_scaled = FALSE; + is_user = FALSE; + + if (type == CAIRO_SUBSETS_FOREACH_USER) + is_user = TRUE; + + if (type == CAIRO_SUBSETS_FOREACH_SCALED || + type == CAIRO_SUBSETS_FOREACH_USER) + { + is_scaled = TRUE; + } + + if (is_scaled) + collection.glyphs_size = font_subsets->max_glyphs_per_scaled_subset_used; + else + collection.glyphs_size = font_subsets->max_glyphs_per_unscaled_subset_used; + + if (! collection.glyphs_size) + return CAIRO_STATUS_SUCCESS; + + collection.glyphs = _cairo_malloc_ab (collection.glyphs_size, sizeof(unsigned long)); + collection.utf8 = _cairo_malloc_ab (collection.glyphs_size, sizeof(char *)); + collection.to_latin_char = _cairo_malloc_ab (collection.glyphs_size, sizeof(int)); + collection.latin_to_subset_glyph_index = _cairo_malloc_ab (256, sizeof(unsigned long)); + if (unlikely (collection.glyphs == NULL || + collection.utf8 == NULL || + collection.to_latin_char == NULL || + collection.latin_to_subset_glyph_index == NULL)) { + free (collection.glyphs); + free (collection.utf8); + free (collection.to_latin_char); + free (collection.latin_to_subset_glyph_index); + + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + collection.font_subset_callback = font_subset_callback; + collection.font_subset_callback_closure = closure; + collection.status = CAIRO_STATUS_SUCCESS; + + if (is_scaled) + sub_font = font_subsets->scaled_sub_fonts_list; + else + sub_font = font_subsets->unscaled_sub_fonts_list; + + while (sub_font) { + if (sub_font->is_user == is_user) + _cairo_sub_font_collect (sub_font, &collection); + + sub_font = sub_font->next; + } + free (collection.utf8); + free (collection.glyphs); + free (collection.to_latin_char); + free (collection.latin_to_subset_glyph_index); + + return collection.status; +} + +cairo_status_t +_cairo_scaled_font_subsets_foreach_scaled (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure) +{ + return _cairo_scaled_font_subsets_foreach_internal (font_subsets, + font_subset_callback, + closure, + CAIRO_SUBSETS_FOREACH_SCALED); +} + +cairo_status_t +_cairo_scaled_font_subsets_foreach_unscaled (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure) +{ + return _cairo_scaled_font_subsets_foreach_internal (font_subsets, + font_subset_callback, + closure, + CAIRO_SUBSETS_FOREACH_UNSCALED); +} + +cairo_status_t +_cairo_scaled_font_subsets_foreach_user (cairo_scaled_font_subsets_t *font_subsets, + cairo_scaled_font_subset_callback_func_t font_subset_callback, + void *closure) +{ + return _cairo_scaled_font_subsets_foreach_internal (font_subsets, + font_subset_callback, + closure, + CAIRO_SUBSETS_FOREACH_USER); +} + +static cairo_bool_t +_cairo_string_equal (const void *key_a, const void *key_b) +{ + const cairo_string_entry_t *a = key_a; + const cairo_string_entry_t *b = key_b; + + if (strcmp (a->string, b->string) == 0) + return TRUE; + else + return FALSE; +} + +static void +_cairo_string_init_key (cairo_string_entry_t *key, char *s) +{ + unsigned long sum = 0; + unsigned int i; + + for (i = 0; i < strlen(s); i++) + sum += s[i]; + key->base.hash = sum; + key->string = s; +} + +static cairo_status_t +create_string_entry (char *s, cairo_string_entry_t **entry) +{ + *entry = malloc (sizeof (cairo_string_entry_t)); + if (unlikely (*entry == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_string_init_key (*entry, s); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_pluck_entry (void *entry, void *closure) +{ + _cairo_hash_table_remove (closure, entry); + free (entry); +} + +cairo_int_status_t +_cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset) +{ + unsigned int i; + cairo_hash_table_t *names; + cairo_string_entry_t key, *entry; + char buf[30]; + char *utf8; + uint16_t *utf16; + int utf16_len; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + names = _cairo_hash_table_create (_cairo_string_equal); + if (unlikely (names == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + subset->glyph_names = calloc (subset->num_glyphs, sizeof (char *)); + if (unlikely (subset->glyph_names == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_HASH; + } + + i = 0; + if (! subset->is_scaled) { + subset->glyph_names[0] = strdup (".notdef"); + if (unlikely (subset->glyph_names[0] == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_HASH; + } + + status = create_string_entry (subset->glyph_names[0], &entry); + if (unlikely (status)) + goto CLEANUP_HASH; + + status = _cairo_hash_table_insert (names, &entry->base); + if (unlikely (status)) { + free (entry); + goto CLEANUP_HASH; + } + i++; + } + + for (; i < subset->num_glyphs; i++) { + utf8 = subset->utf8[i]; + utf16 = NULL; + utf16_len = 0; + if (utf8 && *utf8) { + status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len); + if (unlikely (status)) + goto CLEANUP_HASH; + } + + if (utf16_len == 1) { + int ch = _cairo_unicode_to_winansi (utf16[0]); + if (ch > 0 && _cairo_winansi_to_glyphname (ch)) { + strncpy (buf, _cairo_winansi_to_glyphname (ch), sizeof (buf)); + buf[sizeof (buf)-1] = '\0'; + } else { + snprintf (buf, sizeof (buf), "uni%04X", (int) utf16[0]); + } + + _cairo_string_init_key (&key, buf); + entry = _cairo_hash_table_lookup (names, &key.base); + if (entry != NULL) + snprintf (buf, sizeof (buf), "g%d", i); + } else { + snprintf (buf, sizeof (buf), "g%d", i); + } + free (utf16); + + subset->glyph_names[i] = strdup (buf); + if (unlikely (subset->glyph_names[i] == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_HASH; + } + + status = create_string_entry (subset->glyph_names[i], &entry); + if (unlikely (status)) + goto CLEANUP_HASH; + + status = _cairo_hash_table_insert (names, &entry->base); + if (unlikely (status)) { + free (entry); + goto CLEANUP_HASH; + } + } + +CLEANUP_HASH: + _cairo_hash_table_foreach (names, _pluck_entry, names); + _cairo_hash_table_destroy (names); + + if (likely (status == CAIRO_STATUS_SUCCESS)) + return CAIRO_STATUS_SUCCESS; + + if (subset->glyph_names != NULL) { + for (i = 0; i < subset->num_glyphs; i++) { + free (subset->glyph_names[i]); + } + + free (subset->glyph_names); + subset->glyph_names = NULL; + } + + return status; +} + +cairo_int_status_t +_cairo_escape_ps_name (char **ps_name) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + /* Ensure PS name is a valid PDF/PS name object. In PDF names are + * treated as UTF8 and non ASCII bytes, ' ', and '#' are encoded + * as '#' followed by 2 hex digits that encode the byte. By also + * encoding the characters in the reserved string we ensure the + * name is also PS compatible. */ + if (*ps_name) { + static const char *reserved = "()<>[]{}/%#\\"; + char buf[128]; /* max name length is 127 bytes */ + char *src = *ps_name; + char *dst = buf; + + while (*src && dst < buf + 127) { + unsigned char c = *src; + if (c < 0x21 || c > 0x7e || strchr (reserved, c)) { + if (dst + 4 > buf + 127) + break; + + snprintf (dst, 4, "#%02X", c); + src++; + dst += 3; + } else { + *dst++ = *src++; + } + } + *dst = 0; + free (*ps_name); + *ps_name = strdup (buf); + if (*ps_name == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + return status; +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font.c b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font.c new file mode 100644 index 00000000000..ac80c97d1c5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-scaled-font.c @@ -0,0 +1,3158 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* + * Copyright © 2005 Keith Packard + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith Packard + * Carl D. Worth + * Graydon Hoare + * Owen Taylor + * Behdad Esfahbod + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-pattern-private.h" +#include "cairo-scaled-font-private.h" +#include "cairo-surface-backend-private.h" + +#if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE) +#define ISFINITE(x) isfinite (x) +#else +#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */ +#endif + +/** + * SECTION:cairo-scaled-font + * @Title: cairo_scaled_font_t + * @Short_Description: Font face at particular size and options + * @See_Also: #cairo_font_face_t, #cairo_matrix_t, #cairo_font_options_t + * + * #cairo_scaled_font_t represents a realization of a font face at a particular + * size and transformation and a certain set of font options. + **/ + +static uint32_t +_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font); + +/* Global Glyph Cache + * + * We maintain a global pool of glyphs split between all active fonts. This + * allows a heavily used individual font to cache more glyphs than we could + * manage if we used per-font glyph caches, but at the same time maintains + * fairness across all fonts and provides a cap on the maximum number of + * global glyphs. + * + * The glyphs are allocated in pages, which are capped in the global pool. + * Using pages means we can reduce the frequency at which we have to probe the + * global pool and ameliorates the memory allocation pressure. + */ + +/* XXX: This number is arbitrary---we've never done any measurement of this. */ +#define MAX_GLYPH_PAGES_CACHED 512 +static cairo_cache_t cairo_scaled_glyph_page_cache; + +#define CAIRO_SCALED_GLYPH_PAGE_SIZE 32 +struct _cairo_scaled_glyph_page { + cairo_cache_entry_t cache_entry; + + cairo_list_t link; + + unsigned int num_glyphs; + cairo_scaled_glyph_t glyphs[CAIRO_SCALED_GLYPH_PAGE_SIZE]; +}; + +/* + * Notes: + * + * To store rasterizations of glyphs, we use an image surface and the + * device offset to represent the glyph origin. + * + * A device_transform converts from device space (a conceptual space) to + * surface space. For simple cases of translation only, it's called a + * device_offset and is public API (cairo_surface_[gs]et_device_offset()). + * A possibly better name for those functions could have been + * cairo_surface_[gs]et_origin(). So, that's what they do: they set where + * the device-space origin (0,0) is in the surface. If the origin is inside + * the surface, device_offset values are positive. It may look like this: + * + * Device space: + * (-x,-y) <-- negative numbers + * +----------------+ + * | . | + * | . | + * |......(0,0) <---|-- device-space origin + * | | + * | | + * +----------------+ + * (width-x,height-y) + * + * Surface space: + * (0,0) <-- surface-space origin + * +---------------+ + * | . | + * | . | + * |......(x,y) <--|-- device_offset + * | | + * | | + * +---------------+ + * (width,height) + * + * In other words: device_offset is the coordinates of the device-space + * origin relative to the top-left of the surface. + * + * We use device offsets in a couple of places: + * + * - Public API: To let toolkits like Gtk+ give user a surface that + * only represents part of the final destination (say, the expose + * area), but has the same device space as the destination. In these + * cases device_offset is typically negative. Example: + * + * application window + * +---------------+ + * | . | + * | (x,y). | + * |......+---+ | + * | | | <--|-- expose area + * | +---+ | + * +---------------+ + * + * In this case, the user of cairo API can set the device_space on + * the expose area to (-x,-y) to move the device space origin to that + * of the application window, such that drawing in the expose area + * surface and painting it in the application window has the same + * effect as drawing in the application window directly. Gtk+ has + * been using this feature. + * + * - Glyph surfaces: In most font rendering systems, glyph surfaces + * have an origin at (0,0) and a bounding box that is typically + * represented as (x_bearing,y_bearing,width,height). Depending on + * which way y progresses in the system, y_bearing may typically be + * negative (for systems similar to cairo, with origin at top left), + * or be positive (in systems like PDF with origin at bottom left). + * No matter which is the case, it is important to note that + * (x_bearing,y_bearing) is the coordinates of top-left of the glyph + * relative to the glyph origin. That is, for example: + * + * Scaled-glyph space: + * + * (x_bearing,y_bearing) <-- negative numbers + * +----------------+ + * | . | + * | . | + * |......(0,0) <---|-- glyph origin + * | | + * | | + * +----------------+ + * (width+x_bearing,height+y_bearing) + * + * Note the similarity of the origin to the device space. That is + * exactly how we use the device_offset to represent scaled glyphs: + * to use the device-space origin as the glyph origin. + * + * Now compare the scaled-glyph space to device-space and surface-space + * and convince yourself that: + * + * (x_bearing,y_bearing) = (-x,-y) = - device_offset + * + * That's right. If you are not convinced yet, contrast the definition + * of the two: + * + * "(x_bearing,y_bearing) is the coordinates of top-left of the + * glyph relative to the glyph origin." + * + * "In other words: device_offset is the coordinates of the + * device-space origin relative to the top-left of the surface." + * + * and note that glyph origin = device-space origin. + */ + +static void +_cairo_scaled_font_fini_internal (cairo_scaled_font_t *scaled_font); + +static void +_cairo_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_t *scaled_glyph) +{ + while (! cairo_list_is_empty (&scaled_glyph->dev_privates)) { + cairo_scaled_glyph_private_t *private = + cairo_list_first_entry (&scaled_glyph->dev_privates, + cairo_scaled_glyph_private_t, + link); + private->destroy (private, scaled_glyph, scaled_font); + } + + _cairo_image_scaled_glyph_fini (scaled_font, scaled_glyph); + + if (scaled_glyph->surface != NULL) + cairo_surface_destroy (&scaled_glyph->surface->base); + + if (scaled_glyph->path != NULL) + _cairo_path_fixed_destroy (scaled_glyph->path); + + if (scaled_glyph->recording_surface != NULL) { + cairo_surface_finish (scaled_glyph->recording_surface); + cairo_surface_destroy (scaled_glyph->recording_surface); + } +} + +#define ZOMBIE 0 +static const cairo_scaled_font_t _cairo_scaled_font_nil = { + { ZOMBIE }, /* hash_entry */ + CAIRO_STATUS_NO_MEMORY, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL, /* original_font_face */ + NULL, /* font_face */ + { 1., 0., 0., 1., 0, 0}, /* font_matrix */ + { 1., 0., 0., 1., 0, 0}, /* ctm */ + { CAIRO_ANTIALIAS_DEFAULT, /* options */ + CAIRO_SUBPIXEL_ORDER_DEFAULT, + CAIRO_HINT_STYLE_DEFAULT, + CAIRO_HINT_METRICS_DEFAULT} , + FALSE, /* placeholder */ + FALSE, /* holdover */ + TRUE, /* finished */ + { 1., 0., 0., 1., 0, 0}, /* scale */ + { 1., 0., 0., 1., 0, 0}, /* scale_inverse */ + 1., /* max_scale */ + { 0., 0., 0., 0., 0. }, /* extents */ + { 0., 0., 0., 0., 0. }, /* fs_extents */ + CAIRO_MUTEX_NIL_INITIALIZER,/* mutex */ + NULL, /* glyphs */ + { NULL, NULL }, /* pages */ + FALSE, /* cache_frozen */ + FALSE, /* global_cache_frozen */ + { NULL, NULL }, /* privates */ + NULL /* backend */ +}; + +/** + * _cairo_scaled_font_set_error: + * @scaled_font: a scaled_font + * @status: a status value indicating an error + * + * Atomically sets scaled_font->status to @status and calls _cairo_error; + * Does nothing if status is %CAIRO_STATUS_SUCCESS. + * + * All assignments of an error status to scaled_font->status should happen + * through _cairo_scaled_font_set_error(). Note that due to the nature of + * the atomic operation, it is not safe to call this function on the nil + * objects. + * + * The purpose of this function is to allow the user to set a + * breakpoint in _cairo_error() to generate a stack trace for when the + * user causes cairo to detect an error. + * + * Return value: the error status. + **/ +cairo_status_t +_cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, + cairo_status_t status) +{ + if (status == CAIRO_STATUS_SUCCESS) + return status; + + /* Don't overwrite an existing error. This preserves the first + * error, which is the most significant. */ + _cairo_status_set_error (&scaled_font->status, status); + + return _cairo_error (status); +} + +/** + * cairo_scaled_font_get_type: + * @scaled_font: a #cairo_scaled_font_t + * + * This function returns the type of the backend used to create + * a scaled font. See #cairo_font_type_t for available types. + * However, this function never returns %CAIRO_FONT_TYPE_TOY. + * + * Return value: The type of @scaled_font. + * + * Since: 1.2 + **/ +cairo_font_type_t +cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + return CAIRO_FONT_TYPE_TOY; + + return scaled_font->backend->type; +} + +/** + * cairo_scaled_font_status: + * @scaled_font: a #cairo_scaled_font_t + * + * Checks whether an error has previously occurred for this + * scaled_font. + * + * Return value: %CAIRO_STATUS_SUCCESS or another error such as + * %CAIRO_STATUS_NO_MEMORY. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_scaled_font_status (cairo_scaled_font_t *scaled_font) +{ + return scaled_font->status; +} +slim_hidden_def (cairo_scaled_font_status); + +/* Here we keep a unique mapping from + * font_face/matrix/ctm/font_options => #cairo_scaled_font_t. + * + * Here are the things that we want to map: + * + * a) All otherwise referenced #cairo_scaled_font_t's + * b) Some number of not otherwise referenced #cairo_scaled_font_t's + * + * The implementation uses a hash table which covers (a) + * completely. Then, for (b) we have an array of otherwise + * unreferenced fonts (holdovers) which are expired in + * least-recently-used order. + * + * The cairo_scaled_font_create() code gets to treat this like a regular + * hash table. All of the magic for the little holdover cache is in + * cairo_scaled_font_reference() and cairo_scaled_font_destroy(). + */ + +/* This defines the size of the holdover array ... that is, the number + * of scaled fonts we keep around even when not otherwise referenced + */ +#define CAIRO_SCALED_FONT_MAX_HOLDOVERS 256 + +typedef struct _cairo_scaled_font_map { + cairo_scaled_font_t *mru_scaled_font; + cairo_hash_table_t *hash_table; + cairo_scaled_font_t *holdovers[CAIRO_SCALED_FONT_MAX_HOLDOVERS]; + int num_holdovers; +} cairo_scaled_font_map_t; + +static cairo_scaled_font_map_t *cairo_scaled_font_map; + +static int +_cairo_scaled_font_keys_equal (const void *abstract_key_a, const void *abstract_key_b); + +static cairo_scaled_font_map_t * +_cairo_scaled_font_map_lock (void) +{ + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); + + if (cairo_scaled_font_map == NULL) { + cairo_scaled_font_map = malloc (sizeof (cairo_scaled_font_map_t)); + if (unlikely (cairo_scaled_font_map == NULL)) + goto CLEANUP_MUTEX_LOCK; + + cairo_scaled_font_map->mru_scaled_font = NULL; + cairo_scaled_font_map->hash_table = + _cairo_hash_table_create (_cairo_scaled_font_keys_equal); + + if (unlikely (cairo_scaled_font_map->hash_table == NULL)) + goto CLEANUP_SCALED_FONT_MAP; + + cairo_scaled_font_map->num_holdovers = 0; + } + + return cairo_scaled_font_map; + + CLEANUP_SCALED_FONT_MAP: + free (cairo_scaled_font_map); + cairo_scaled_font_map = NULL; + CLEANUP_MUTEX_LOCK: + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return NULL; +} + +static void +_cairo_scaled_font_map_unlock (void) +{ + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); +} + +void +_cairo_scaled_font_map_destroy (void) +{ + cairo_scaled_font_map_t *font_map; + cairo_scaled_font_t *scaled_font; + + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); + + font_map = cairo_scaled_font_map; + if (unlikely (font_map == NULL)) { + goto CLEANUP_MUTEX_LOCK; + } + + scaled_font = font_map->mru_scaled_font; + if (scaled_font != NULL) { + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); + cairo_scaled_font_destroy (scaled_font); + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); + } + + /* remove scaled_fonts starting from the end so that font_map->holdovers + * is always in a consistent state when we release the mutex. */ + while (font_map->num_holdovers) { + scaled_font = font_map->holdovers[font_map->num_holdovers-1]; + assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); + _cairo_hash_table_remove (font_map->hash_table, + &scaled_font->hash_entry); + + font_map->num_holdovers--; + + /* This releases the font_map lock to avoid the possibility of a + * recursive deadlock when the scaled font destroy closure gets + * called + */ + _cairo_scaled_font_fini (scaled_font); + + free (scaled_font); + } + + _cairo_hash_table_destroy (font_map->hash_table); + + free (cairo_scaled_font_map); + cairo_scaled_font_map = NULL; + + CLEANUP_MUTEX_LOCK: + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); +} + +static void +_cairo_scaled_glyph_page_destroy (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_page_t *page) +{ + unsigned int n; + + assert (!scaled_font->cache_frozen); + assert (!scaled_font->global_cache_frozen); + + for (n = 0; n < page->num_glyphs; n++) { + _cairo_hash_table_remove (scaled_font->glyphs, + &page->glyphs[n].hash_entry); + _cairo_scaled_glyph_fini (scaled_font, &page->glyphs[n]); + } + + cairo_list_del (&page->link); + free (page); +} + +static void +_cairo_scaled_glyph_page_pluck (void *closure) +{ + cairo_scaled_glyph_page_t *page = closure; + cairo_scaled_font_t *scaled_font; + + assert (! cairo_list_is_empty (&page->link)); + + scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash; + + CAIRO_MUTEX_LOCK (scaled_font->mutex); + _cairo_scaled_glyph_page_destroy (scaled_font, page); + CAIRO_MUTEX_UNLOCK (scaled_font->mutex); +} + +/* If a scaled font wants to unlock the font map while still being + * created (needed for user-fonts), we need to take extra care not + * ending up with multiple identical scaled fonts being created. + * + * What we do is, we create a fake identical scaled font, and mark + * it as placeholder, lock its mutex, and insert that in the fontmap + * hash table. This makes other code trying to create an identical + * scaled font to just wait and retry. + * + * The reason we have to create a fake scaled font instead of just using + * scaled_font is for lifecycle management: we need to (or rather, + * other code needs to) reference the scaled_font in the hash table. + * We can't do that on the input scaled_font as it may be freed by + * font backend upon error. + */ + +cairo_status_t +_cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t *scaled_font) +{ + cairo_status_t status; + cairo_scaled_font_t *placeholder_scaled_font; + + assert (CAIRO_MUTEX_IS_LOCKED (_cairo_scaled_font_map_mutex)); + + status = scaled_font->status; + if (unlikely (status)) + return status; + + placeholder_scaled_font = malloc (sizeof (cairo_scaled_font_t)); + if (unlikely (placeholder_scaled_font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* full initialization is wasteful, but who cares... */ + status = _cairo_scaled_font_init (placeholder_scaled_font, + scaled_font->font_face, + &scaled_font->font_matrix, + &scaled_font->ctm, + &scaled_font->options, + NULL); + if (unlikely (status)) + goto FREE_PLACEHOLDER; + + placeholder_scaled_font->placeholder = TRUE; + + placeholder_scaled_font->hash_entry.hash + = _cairo_scaled_font_compute_hash (placeholder_scaled_font); + status = _cairo_hash_table_insert (cairo_scaled_font_map->hash_table, + &placeholder_scaled_font->hash_entry); + if (unlikely (status)) + goto FINI_PLACEHOLDER; + + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); + CAIRO_MUTEX_LOCK (placeholder_scaled_font->mutex); + + return CAIRO_STATUS_SUCCESS; + + FINI_PLACEHOLDER: + _cairo_scaled_font_fini_internal (placeholder_scaled_font); + FREE_PLACEHOLDER: + free (placeholder_scaled_font); + + return _cairo_scaled_font_set_error (scaled_font, status); +} + +void +_cairo_scaled_font_unregister_placeholder_and_lock_font_map (cairo_scaled_font_t *scaled_font) +{ + cairo_scaled_font_t *placeholder_scaled_font; + + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); + + /* temporary hash value to match the placeholder */ + scaled_font->hash_entry.hash + = _cairo_scaled_font_compute_hash (scaled_font); + placeholder_scaled_font = + _cairo_hash_table_lookup (cairo_scaled_font_map->hash_table, + &scaled_font->hash_entry); + assert (placeholder_scaled_font != NULL); + assert (placeholder_scaled_font->placeholder); + assert (CAIRO_MUTEX_IS_LOCKED (placeholder_scaled_font->mutex)); + + _cairo_hash_table_remove (cairo_scaled_font_map->hash_table, + &placeholder_scaled_font->hash_entry); + + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); + + CAIRO_MUTEX_UNLOCK (placeholder_scaled_font->mutex); + cairo_scaled_font_destroy (placeholder_scaled_font); + + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); +} + +static void +_cairo_scaled_font_placeholder_wait_for_creation_to_finish (cairo_scaled_font_t *placeholder_scaled_font) +{ + /* reference the place holder so it doesn't go away */ + cairo_scaled_font_reference (placeholder_scaled_font); + + /* now unlock the fontmap mutex so creation has a chance to finish */ + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); + + /* wait on placeholder mutex until we are awaken */ + CAIRO_MUTEX_LOCK (placeholder_scaled_font->mutex); + + /* ok, creation done. just clean up and back out */ + CAIRO_MUTEX_UNLOCK (placeholder_scaled_font->mutex); + cairo_scaled_font_destroy (placeholder_scaled_font); + + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); +} + +/* Fowler / Noll / Vo (FNV) Hash (http://www.isthe.com/chongo/tech/comp/fnv/) + * + * Not necessarily better than a lot of other hashes, but should be OK, and + * well tested with binary data. + */ + +#define FNV_32_PRIME ((uint32_t)0x01000193) +#define FNV1_32_INIT ((uint32_t)0x811c9dc5) + +static uint32_t +_hash_matrix_fnv (const cairo_matrix_t *matrix, + uint32_t hval) +{ + const uint8_t *buffer = (const uint8_t *) matrix; + int len = sizeof (cairo_matrix_t); + do { + hval *= FNV_32_PRIME; + hval ^= *buffer++; + } while (--len); + + return hval; +} + +static uint32_t +_hash_mix_bits (uint32_t hash) +{ + hash += hash << 12; + hash ^= hash >> 7; + hash += hash << 3; + hash ^= hash >> 17; + hash += hash << 5; + return hash; +} + +static uint32_t +_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font) +{ + uint32_t hash = FNV1_32_INIT; + + /* We do a bytewise hash on the font matrices */ + hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash); + hash = _hash_matrix_fnv (&scaled_font->ctm, hash); + hash = _hash_mix_bits (hash); + + hash ^= (unsigned long) scaled_font->original_font_face; + hash ^= cairo_font_options_hash (&scaled_font->options); + + /* final mixing of bits */ + hash = _hash_mix_bits (hash); + assert (hash != ZOMBIE); + + return hash; +} + +static void +_cairo_scaled_font_init_key (cairo_scaled_font_t *scaled_font, + cairo_font_face_t *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options) +{ + scaled_font->status = CAIRO_STATUS_SUCCESS; + scaled_font->placeholder = FALSE; + scaled_font->font_face = font_face; + scaled_font->original_font_face = font_face; + scaled_font->font_matrix = *font_matrix; + scaled_font->ctm = *ctm; + /* ignore translation values in the ctm */ + scaled_font->ctm.x0 = 0.; + scaled_font->ctm.y0 = 0.; + _cairo_font_options_init_copy (&scaled_font->options, options); + + scaled_font->hash_entry.hash = + _cairo_scaled_font_compute_hash (scaled_font); +} + +static cairo_bool_t +_cairo_scaled_font_keys_equal (const void *abstract_key_a, + const void *abstract_key_b) +{ + const cairo_scaled_font_t *key_a = abstract_key_a; + const cairo_scaled_font_t *key_b = abstract_key_b; + + return key_a->original_font_face == key_b->original_font_face && + memcmp ((unsigned char *)(&key_a->font_matrix.xx), + (unsigned char *)(&key_b->font_matrix.xx), + sizeof(cairo_matrix_t)) == 0 && + memcmp ((unsigned char *)(&key_a->ctm.xx), + (unsigned char *)(&key_b->ctm.xx), + sizeof(cairo_matrix_t)) == 0 && + cairo_font_options_equal (&key_a->options, &key_b->options); +} + +static cairo_bool_t +_cairo_scaled_font_matches (const cairo_scaled_font_t *scaled_font, + const cairo_font_face_t *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options) +{ + return scaled_font->original_font_face == font_face && + memcmp ((unsigned char *)(&scaled_font->font_matrix.xx), + (unsigned char *)(&font_matrix->xx), + sizeof(cairo_matrix_t)) == 0 && + memcmp ((unsigned char *)(&scaled_font->ctm.xx), + (unsigned char *)(&ctm->xx), + sizeof(cairo_matrix_t)) == 0 && + cairo_font_options_equal (&scaled_font->options, options); +} + +/* + * Basic #cairo_scaled_font_t object management + */ + +cairo_status_t +_cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, + cairo_font_face_t *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + const cairo_scaled_font_backend_t *backend) +{ + cairo_status_t status; + + status = cairo_font_options_status ((cairo_font_options_t *) options); + if (unlikely (status)) + return status; + + scaled_font->status = CAIRO_STATUS_SUCCESS; + scaled_font->placeholder = FALSE; + scaled_font->font_face = font_face; + scaled_font->original_font_face = font_face; + scaled_font->font_matrix = *font_matrix; + scaled_font->ctm = *ctm; + /* ignore translation values in the ctm */ + scaled_font->ctm.x0 = 0.; + scaled_font->ctm.y0 = 0.; + _cairo_font_options_init_copy (&scaled_font->options, options); + + cairo_matrix_multiply (&scaled_font->scale, + &scaled_font->font_matrix, + &scaled_font->ctm); + + scaled_font->max_scale = MAX (fabs (scaled_font->scale.xx) + fabs (scaled_font->scale.xy), + fabs (scaled_font->scale.yx) + fabs (scaled_font->scale.yy)); + scaled_font->scale_inverse = scaled_font->scale; + status = cairo_matrix_invert (&scaled_font->scale_inverse); + if (unlikely (status)) { + /* If the font scale matrix is rank 0, just using an all-zero inverse matrix + * makes everything work correctly. This make font size 0 work without + * producing an error. + * + * FIXME: If the scale is rank 1, we still go into error mode. But then + * again, that's what we do everywhere in cairo. + * + * Also, the check for == 0. below may be too harsh... + */ + if (_cairo_matrix_is_scale_0 (&scaled_font->scale)) { + cairo_matrix_init (&scaled_font->scale_inverse, + 0, 0, 0, 0, + -scaled_font->scale.x0, + -scaled_font->scale.y0); + } else + return status; + } + + scaled_font->glyphs = _cairo_hash_table_create (NULL); + if (unlikely (scaled_font->glyphs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + cairo_list_init (&scaled_font->glyph_pages); + scaled_font->cache_frozen = FALSE; + scaled_font->global_cache_frozen = FALSE; + + scaled_font->holdover = FALSE; + scaled_font->finished = FALSE; + + CAIRO_REFERENCE_COUNT_INIT (&scaled_font->ref_count, 1); + + _cairo_user_data_array_init (&scaled_font->user_data); + + cairo_font_face_reference (font_face); + scaled_font->original_font_face = NULL; + + CAIRO_MUTEX_INIT (scaled_font->mutex); + + cairo_list_init (&scaled_font->dev_privates); + + scaled_font->backend = backend; + cairo_list_init (&scaled_font->link); + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_scaled_font_freeze_cache (cairo_scaled_font_t *scaled_font) +{ + /* ensure we do not modify an error object */ + assert (scaled_font->status == CAIRO_STATUS_SUCCESS); + + CAIRO_MUTEX_LOCK (scaled_font->mutex); + scaled_font->cache_frozen = TRUE; +} + +void +_cairo_scaled_font_thaw_cache (cairo_scaled_font_t *scaled_font) +{ + assert (scaled_font->cache_frozen); + + if (scaled_font->global_cache_frozen) { + CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); + _cairo_cache_thaw (&cairo_scaled_glyph_page_cache); + CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); + scaled_font->global_cache_frozen = FALSE; + } + + scaled_font->cache_frozen = FALSE; + CAIRO_MUTEX_UNLOCK (scaled_font->mutex); +} + +void +_cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font) +{ + CAIRO_MUTEX_LOCK (scaled_font->mutex); + assert (! scaled_font->cache_frozen); + assert (! scaled_font->global_cache_frozen); + CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); + while (! cairo_list_is_empty (&scaled_font->glyph_pages)) { + cairo_scaled_glyph_page_t *page = + cairo_list_first_entry (&scaled_font->glyph_pages, + cairo_scaled_glyph_page_t, + link); + + cairo_scaled_glyph_page_cache.size -= page->cache_entry.size; + _cairo_hash_table_remove (cairo_scaled_glyph_page_cache.hash_table, + (cairo_hash_entry_t *) &page->cache_entry); + + _cairo_scaled_glyph_page_destroy (scaled_font, page); + } + CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); + CAIRO_MUTEX_UNLOCK (scaled_font->mutex); +} + +cairo_status_t +_cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font, + cairo_font_extents_t *fs_metrics) +{ + cairo_status_t status; + double font_scale_x, font_scale_y; + + scaled_font->fs_extents = *fs_metrics; + + status = _cairo_matrix_compute_basis_scale_factors (&scaled_font->font_matrix, + &font_scale_x, &font_scale_y, + 1); + if (unlikely (status)) + return status; + + /* + * The font responded in unscaled units, scale by the font + * matrix scale factors to get to user space + */ + + scaled_font->extents.ascent = fs_metrics->ascent * font_scale_y; + scaled_font->extents.descent = fs_metrics->descent * font_scale_y; + scaled_font->extents.height = fs_metrics->height * font_scale_y; + scaled_font->extents.max_x_advance = fs_metrics->max_x_advance * font_scale_x; + scaled_font->extents.max_y_advance = fs_metrics->max_y_advance * font_scale_y; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_scaled_font_fini_internal (cairo_scaled_font_t *scaled_font) +{ + assert (! scaled_font->cache_frozen); + assert (! scaled_font->global_cache_frozen); + scaled_font->finished = TRUE; + + _cairo_scaled_font_reset_cache (scaled_font); + _cairo_hash_table_destroy (scaled_font->glyphs); + + cairo_font_face_destroy (scaled_font->font_face); + cairo_font_face_destroy (scaled_font->original_font_face); + + CAIRO_MUTEX_FINI (scaled_font->mutex); + + while (! cairo_list_is_empty (&scaled_font->dev_privates)) { + cairo_scaled_font_private_t *private = + cairo_list_first_entry (&scaled_font->dev_privates, + cairo_scaled_font_private_t, + link); + private->destroy (private, scaled_font); + } + + if (scaled_font->backend != NULL && scaled_font->backend->fini != NULL) + scaled_font->backend->fini (scaled_font); + + _cairo_user_data_array_fini (&scaled_font->user_data); +} + +void +_cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font) +{ + /* Release the lock to avoid the possibility of a recursive + * deadlock when the scaled font destroy closure gets called. */ + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex); + _cairo_scaled_font_fini_internal (scaled_font); + CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex); +} + +void +_cairo_scaled_font_attach_private (cairo_scaled_font_t *scaled_font, + cairo_scaled_font_private_t *private, + const void *key, + void (*destroy) (cairo_scaled_font_private_t *, + cairo_scaled_font_t *)) +{ + private->key = key; + private->destroy = destroy; + cairo_list_add (&private->link, &scaled_font->dev_privates); +} + +cairo_scaled_font_private_t * +_cairo_scaled_font_find_private (cairo_scaled_font_t *scaled_font, + const void *key) +{ + cairo_scaled_font_private_t *priv; + + cairo_list_foreach_entry (priv, cairo_scaled_font_private_t, + &scaled_font->dev_privates, link) + { + if (priv->key == key) { + if (priv->link.prev != &scaled_font->dev_privates) + cairo_list_move (&priv->link, &scaled_font->dev_privates); + return priv; + } + } + + return NULL; +} + +void +_cairo_scaled_glyph_attach_private (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_glyph_private_t *private, + const void *key, + void (*destroy) (cairo_scaled_glyph_private_t *, + cairo_scaled_glyph_t *, + cairo_scaled_font_t *)) +{ + private->key = key; + private->destroy = destroy; + cairo_list_add (&private->link, &scaled_glyph->dev_privates); +} + +cairo_scaled_glyph_private_t * +_cairo_scaled_glyph_find_private (cairo_scaled_glyph_t *scaled_glyph, + const void *key) +{ + cairo_scaled_glyph_private_t *priv; + + cairo_list_foreach_entry (priv, cairo_scaled_glyph_private_t, + &scaled_glyph->dev_privates, link) + { + if (priv->key == key) { + if (priv->link.prev != &scaled_glyph->dev_privates) + cairo_list_move (&priv->link, &scaled_glyph->dev_privates); + return priv; + } + } + + return NULL; +} + +/** + * cairo_scaled_font_create: + * @font_face: a #cairo_font_face_t + * @font_matrix: font space to user space transformation matrix for the + * font. In the simplest case of a N point font, this matrix is + * just a scale by N, but it can also be used to shear the font + * or stretch it unequally along the two axes. See + * cairo_set_font_matrix(). + * @ctm: user to device transformation matrix with which the font will + * be used. + * @options: options to use when getting metrics for the font and + * rendering with it. + * + * Creates a #cairo_scaled_font_t object from a font face and matrices that + * describe the size of the font and the environment in which it will + * be used. + * + * Return value: a newly created #cairo_scaled_font_t. Destroy with + * cairo_scaled_font_destroy() + * + * Since: 1.0 + **/ +cairo_scaled_font_t * +cairo_scaled_font_create (cairo_font_face_t *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options) +{ + cairo_status_t status; + cairo_scaled_font_map_t *font_map; + cairo_font_face_t *original_font_face = font_face; + cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL, *dead = NULL; + double det; + + status = font_face->status; + if (unlikely (status)) + return _cairo_scaled_font_create_in_error (status); + + det = _cairo_matrix_compute_determinant (font_matrix); + if (! ISFINITE (det)) + return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_MATRIX)); + + det = _cairo_matrix_compute_determinant (ctm); + if (! ISFINITE (det)) + return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_MATRIX)); + + status = cairo_font_options_status ((cairo_font_options_t *) options); + if (unlikely (status)) + return _cairo_scaled_font_create_in_error (status); + + /* Note that degenerate ctm or font_matrix *are* allowed. + * We want to support a font size of 0. */ + + font_map = _cairo_scaled_font_map_lock (); + if (unlikely (font_map == NULL)) + return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + scaled_font = font_map->mru_scaled_font; + if (scaled_font != NULL && + _cairo_scaled_font_matches (scaled_font, + font_face, font_matrix, ctm, options)) + { + assert (scaled_font->hash_entry.hash != ZOMBIE); + assert (! scaled_font->placeholder); + + if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) { + /* We increment the reference count manually here, (rather + * than calling into cairo_scaled_font_reference), since we + * must modify the reference count while our lock is still + * held. */ + _cairo_reference_count_inc (&scaled_font->ref_count); + _cairo_scaled_font_map_unlock (); + return scaled_font; + } + + /* the font has been put into an error status - abandon the cache */ + _cairo_hash_table_remove (font_map->hash_table, + &scaled_font->hash_entry); + scaled_font->hash_entry.hash = ZOMBIE; + dead = scaled_font; + font_map->mru_scaled_font = NULL; + } + + _cairo_scaled_font_init_key (&key, font_face, font_matrix, ctm, options); + + while ((scaled_font = _cairo_hash_table_lookup (font_map->hash_table, + &key.hash_entry))) + { + if (! scaled_font->placeholder) + break; + + /* If the scaled font is being created (happens for user-font), + * just wait until it's done, then retry */ + _cairo_scaled_font_placeholder_wait_for_creation_to_finish (scaled_font); + } + + if (scaled_font != NULL) { + /* If the original reference count is 0, then this font must have + * been found in font_map->holdovers, (which means this caching is + * actually working). So now we remove it from the holdovers + * array, unless we caught the font in the middle of destruction. + */ + if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) { + if (scaled_font->holdover) { + int i; + + for (i = 0; i < font_map->num_holdovers; i++) { + if (font_map->holdovers[i] == scaled_font) { + font_map->num_holdovers--; + memmove (&font_map->holdovers[i], + &font_map->holdovers[i+1], + (font_map->num_holdovers - i) * sizeof (cairo_scaled_font_t*)); + break; + } + } + + scaled_font->holdover = FALSE; + } + + /* reset any error status */ + scaled_font->status = CAIRO_STATUS_SUCCESS; + } + + if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) { + /* We increment the reference count manually here, (rather + * than calling into cairo_scaled_font_reference), since we + * must modify the reference count while our lock is still + * held. */ + + old = font_map->mru_scaled_font; + font_map->mru_scaled_font = scaled_font; + /* increment reference count for the mru cache */ + _cairo_reference_count_inc (&scaled_font->ref_count); + /* and increment for the returned reference */ + _cairo_reference_count_inc (&scaled_font->ref_count); + _cairo_scaled_font_map_unlock (); + + cairo_scaled_font_destroy (old); + if (font_face != original_font_face) + cairo_font_face_destroy (font_face); + + return scaled_font; + } + + /* the font has been put into an error status - abandon the cache */ + _cairo_hash_table_remove (font_map->hash_table, + &scaled_font->hash_entry); + scaled_font->hash_entry.hash = ZOMBIE; + } + + + /* Otherwise create it and insert it into the hash table. */ + if (font_face->backend->get_implementation != NULL) { + font_face = font_face->backend->get_implementation (font_face, + font_matrix, + ctm, + options); + if (unlikely (font_face->status)) { + _cairo_scaled_font_map_unlock (); + return _cairo_scaled_font_create_in_error (font_face->status); + } + } + + status = font_face->backend->scaled_font_create (font_face, font_matrix, + ctm, options, &scaled_font); + /* Did we leave the backend in an error state? */ + if (unlikely (status)) { + _cairo_scaled_font_map_unlock (); + if (font_face != original_font_face) + cairo_font_face_destroy (font_face); + + if (dead != NULL) + cairo_scaled_font_destroy (dead); + + status = _cairo_font_face_set_error (font_face, status); + return _cairo_scaled_font_create_in_error (status); + } + /* Or did we encounter an error whilst constructing the scaled font? */ + if (unlikely (scaled_font->status)) { + _cairo_scaled_font_map_unlock (); + if (font_face != original_font_face) + cairo_font_face_destroy (font_face); + + if (dead != NULL) + cairo_scaled_font_destroy (dead); + + return scaled_font; + } + + /* Our caching above is defeated if the backend switches fonts on us - + * e.g. old incarnations of toy-font-face and lazily resolved + * ft-font-faces + */ + assert (scaled_font->font_face == font_face); + assert (! scaled_font->cache_frozen); + assert (! scaled_font->global_cache_frozen); + + scaled_font->original_font_face = + cairo_font_face_reference (original_font_face); + + scaled_font->hash_entry.hash = _cairo_scaled_font_compute_hash(scaled_font); + + status = _cairo_hash_table_insert (font_map->hash_table, + &scaled_font->hash_entry); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + old = font_map->mru_scaled_font; + font_map->mru_scaled_font = scaled_font; + _cairo_reference_count_inc (&scaled_font->ref_count); + } + + _cairo_scaled_font_map_unlock (); + + cairo_scaled_font_destroy (old); + if (font_face != original_font_face) + cairo_font_face_destroy (font_face); + + if (dead != NULL) + cairo_scaled_font_destroy (dead); + + if (unlikely (status)) { + /* We can't call _cairo_scaled_font_destroy here since it expects + * that the font has already been successfully inserted into the + * hash table. */ + _cairo_scaled_font_fini_internal (scaled_font); + free (scaled_font); + return _cairo_scaled_font_create_in_error (status); + } + + return scaled_font; +} +slim_hidden_def (cairo_scaled_font_create); + +static cairo_scaled_font_t *_cairo_scaled_font_nil_objects[CAIRO_STATUS_LAST_STATUS + 1]; + +/* XXX This should disappear in favour of a common pool of error objects. */ +cairo_scaled_font_t * +_cairo_scaled_font_create_in_error (cairo_status_t status) +{ + cairo_scaled_font_t *scaled_font; + + assert (status != CAIRO_STATUS_SUCCESS); + + if (status == CAIRO_STATUS_NO_MEMORY) + return (cairo_scaled_font_t *) &_cairo_scaled_font_nil; + + CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex); + scaled_font = _cairo_scaled_font_nil_objects[status]; + if (unlikely (scaled_font == NULL)) { + scaled_font = malloc (sizeof (cairo_scaled_font_t)); + if (unlikely (scaled_font == NULL)) { + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_scaled_font_t *) &_cairo_scaled_font_nil; + } + + *scaled_font = _cairo_scaled_font_nil; + scaled_font->status = status; + _cairo_scaled_font_nil_objects[status] = scaled_font; + } + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); + + return scaled_font; +} + +void +_cairo_scaled_font_reset_static_data (void) +{ + int status; + + CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex); + for (status = CAIRO_STATUS_SUCCESS; + status <= CAIRO_STATUS_LAST_STATUS; + status++) + { + free (_cairo_scaled_font_nil_objects[status]); + _cairo_scaled_font_nil_objects[status] = NULL; + } + CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); + + CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); + if (cairo_scaled_glyph_page_cache.hash_table != NULL) { + _cairo_cache_fini (&cairo_scaled_glyph_page_cache); + cairo_scaled_glyph_page_cache.hash_table = NULL; + } + CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); +} + +/** + * cairo_scaled_font_reference: + * @scaled_font: a #cairo_scaled_font_t, (may be %NULL in which case + * this function does nothing) + * + * Increases the reference count on @scaled_font by one. This prevents + * @scaled_font from being destroyed until a matching call to + * cairo_scaled_font_destroy() is made. + * + * The number of references to a #cairo_scaled_font_t can be get using + * cairo_scaled_font_get_reference_count(). + * + * Returns: the referenced #cairo_scaled_font_t + * + * Since: 1.0 + **/ +cairo_scaled_font_t * +cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font) +{ + if (scaled_font == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + return scaled_font; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); + + _cairo_reference_count_inc (&scaled_font->ref_count); + + return scaled_font; +} +slim_hidden_def (cairo_scaled_font_reference); + +/** + * cairo_scaled_font_destroy: + * @scaled_font: a #cairo_scaled_font_t + * + * Decreases the reference count on @font by one. If the result + * is zero, then @font and all associated resources are freed. + * See cairo_scaled_font_reference(). + * + * Since: 1.0 + **/ +void +cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font) +{ + cairo_scaled_font_t *lru = NULL; + cairo_scaled_font_map_t *font_map; + + assert (CAIRO_MUTEX_IS_UNLOCKED (_cairo_scaled_font_map_mutex)); + + if (scaled_font == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&scaled_font->ref_count)) + return; + + assert (! scaled_font->cache_frozen); + assert (! scaled_font->global_cache_frozen); + + font_map = _cairo_scaled_font_map_lock (); + assert (font_map != NULL); + + /* Another thread may have resurrected the font whilst we waited */ + if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) { + if (! scaled_font->placeholder && + scaled_font->hash_entry.hash != ZOMBIE) + { + /* Another thread may have already inserted us into the holdovers */ + if (scaled_font->holdover) + goto unlock; + + /* Rather than immediately destroying this object, we put it into + * the font_map->holdovers array in case it will get used again + * soon (and is why we must hold the lock over the atomic op on + * the reference count). To make room for it, we do actually + * destroy the least-recently-used holdover. + */ + + if (font_map->num_holdovers == CAIRO_SCALED_FONT_MAX_HOLDOVERS) { + lru = font_map->holdovers[0]; + assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&lru->ref_count)); + + _cairo_hash_table_remove (font_map->hash_table, + &lru->hash_entry); + + font_map->num_holdovers--; + memmove (&font_map->holdovers[0], + &font_map->holdovers[1], + font_map->num_holdovers * sizeof (cairo_scaled_font_t*)); + } + + font_map->holdovers[font_map->num_holdovers++] = scaled_font; + scaled_font->holdover = TRUE; + } else + lru = scaled_font; + } + + unlock: + _cairo_scaled_font_map_unlock (); + + /* If we pulled an item from the holdovers array, (while the font + * map lock was held, of course), then there is no way that anyone + * else could have acquired a reference to it. So we can now + * safely call fini on it without any lock held. This is desirable + * as we never want to call into any backend function with a lock + * held. */ + if (lru != NULL) { + _cairo_scaled_font_fini_internal (lru); + free (lru); + } +} +slim_hidden_def (cairo_scaled_font_destroy); + +/** + * cairo_scaled_font_get_reference_count: + * @scaled_font: a #cairo_scaled_font_t + * + * Returns the current reference count of @scaled_font. + * + * Return value: the current reference count of @scaled_font. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.4 + **/ +unsigned int +cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font) +{ + if (scaled_font == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&scaled_font->ref_count); +} + +/** + * cairo_scaled_font_get_user_data: + * @scaled_font: a #cairo_scaled_font_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @scaled_font using the + * specified key. If no user data has been attached with the given + * key this function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.4 + **/ +void * +cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font, + const cairo_user_data_key_t *key) +{ + return _cairo_user_data_array_get_data (&scaled_font->user_data, + key); +} +slim_hidden_def (cairo_scaled_font_get_user_data); + +/** + * cairo_scaled_font_set_user_data: + * @scaled_font: a #cairo_scaled_font_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the #cairo_scaled_font_t + * @destroy: a #cairo_destroy_func_t which will be called when the + * #cairo_t is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @scaled_font. To remove user data from a surface, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + return scaled_font->status; + + return _cairo_user_data_array_set_data (&scaled_font->user_data, + key, user_data, destroy); +} +slim_hidden_def (cairo_scaled_font_set_user_data); + +/* Public font API follows. */ + +/** + * cairo_scaled_font_extents: + * @scaled_font: a #cairo_scaled_font_t + * @extents: a #cairo_font_extents_t which to store the retrieved extents. + * + * Gets the metrics for a #cairo_scaled_font_t. + * + * Since: 1.0 + **/ +void +cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, + cairo_font_extents_t *extents) +{ + if (scaled_font->status) { + extents->ascent = 0.0; + extents->descent = 0.0; + extents->height = 0.0; + extents->max_x_advance = 0.0; + extents->max_y_advance = 0.0; + return; + } + + *extents = scaled_font->extents; +} +slim_hidden_def (cairo_scaled_font_extents); + +/** + * cairo_scaled_font_text_extents: + * @scaled_font: a #cairo_scaled_font_t + * @utf8: a NUL-terminated string of text, encoded in UTF-8 + * @extents: a #cairo_text_extents_t which to store the retrieved extents. + * + * Gets the extents for a string of text. The extents describe a + * user-space rectangle that encloses the "inked" portion of the text + * drawn at the origin (0,0) (as it would be drawn by cairo_show_text() + * if the cairo graphics state were set to the same font_face, + * font_matrix, ctm, and font_options as @scaled_font). Additionally, + * the x_advance and y_advance values indicate the amount by which the + * current point would be advanced by cairo_show_text(). + * + * Note that whitespace characters do not directly contribute to the + * size of the rectangle (extents.width and extents.height). They do + * contribute indirectly by changing the position of non-whitespace + * characters. In particular, trailing whitespace characters are + * likely to not affect the size of the rectangle, though they will + * affect the x_advance and y_advance values. + * + * Since: 1.2 + **/ +void +cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, + const char *utf8, + cairo_text_extents_t *extents) +{ + cairo_status_t status; + cairo_glyph_t *glyphs = NULL; + int num_glyphs; + + if (scaled_font->status) + goto ZERO_EXTENTS; + + if (utf8 == NULL) + goto ZERO_EXTENTS; + + status = cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., + utf8, -1, + &glyphs, &num_glyphs, + NULL, NULL, + NULL); + if (unlikely (status)) { + status = _cairo_scaled_font_set_error (scaled_font, status); + goto ZERO_EXTENTS; + } + + cairo_scaled_font_glyph_extents (scaled_font, glyphs, num_glyphs, extents); + free (glyphs); + + return; + +ZERO_EXTENTS: + extents->x_bearing = 0.0; + extents->y_bearing = 0.0; + extents->width = 0.0; + extents->height = 0.0; + extents->x_advance = 0.0; + extents->y_advance = 0.0; +} + +/** + * cairo_scaled_font_glyph_extents: + * @scaled_font: a #cairo_scaled_font_t + * @glyphs: an array of glyph IDs with X and Y offsets. + * @num_glyphs: the number of glyphs in the @glyphs array + * @extents: a #cairo_text_extents_t which to store the retrieved extents. + * + * Gets the extents for an array of glyphs. The extents describe a + * user-space rectangle that encloses the "inked" portion of the + * glyphs, (as they would be drawn by cairo_show_glyphs() if the cairo + * graphics state were set to the same font_face, font_matrix, ctm, + * and font_options as @scaled_font). Additionally, the x_advance and + * y_advance values indicate the amount by which the current point + * would be advanced by cairo_show_glyphs(). + * + * Note that whitespace glyphs do not contribute to the size of the + * rectangle (extents.width and extents.height). + * + * Since: 1.0 + **/ +void +cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents) +{ + cairo_status_t status; + int i; + double min_x = 0.0, min_y = 0.0, max_x = 0.0, max_y = 0.0; + cairo_bool_t visible = FALSE; + cairo_scaled_glyph_t *scaled_glyph = NULL; + + extents->x_bearing = 0.0; + extents->y_bearing = 0.0; + extents->width = 0.0; + extents->height = 0.0; + extents->x_advance = 0.0; + extents->y_advance = 0.0; + + if (unlikely (scaled_font->status)) + goto ZERO_EXTENTS; + + if (num_glyphs == 0) + goto ZERO_EXTENTS; + + if (unlikely (num_glyphs < 0)) { + _cairo_error_throw (CAIRO_STATUS_NEGATIVE_COUNT); + /* XXX Can't propagate error */ + goto ZERO_EXTENTS; + } + + if (unlikely (glyphs == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NULL_POINTER); + /* XXX Can't propagate error */ + goto ZERO_EXTENTS; + } + + _cairo_scaled_font_freeze_cache (scaled_font); + + for (i = 0; i < num_glyphs; i++) { + double left, top, right, bottom; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) { + status = _cairo_scaled_font_set_error (scaled_font, status); + goto UNLOCK; + } + + /* "Ink" extents should skip "invisible" glyphs */ + if (scaled_glyph->metrics.width == 0 || scaled_glyph->metrics.height == 0) + continue; + + left = scaled_glyph->metrics.x_bearing + glyphs[i].x; + right = left + scaled_glyph->metrics.width; + top = scaled_glyph->metrics.y_bearing + glyphs[i].y; + bottom = top + scaled_glyph->metrics.height; + + if (!visible) { + visible = TRUE; + min_x = left; + max_x = right; + min_y = top; + max_y = bottom; + } else { + if (left < min_x) min_x = left; + if (right > max_x) max_x = right; + if (top < min_y) min_y = top; + if (bottom > max_y) max_y = bottom; + } + } + + if (visible) { + extents->x_bearing = min_x - glyphs[0].x; + extents->y_bearing = min_y - glyphs[0].y; + extents->width = max_x - min_x; + extents->height = max_y - min_y; + } else { + extents->x_bearing = 0.0; + extents->y_bearing = 0.0; + extents->width = 0.0; + extents->height = 0.0; + } + + if (num_glyphs) { + double x0, y0, x1, y1; + + x0 = glyphs[0].x; + y0 = glyphs[0].y; + + /* scaled_glyph contains the glyph for num_glyphs - 1 already. */ + x1 = glyphs[num_glyphs - 1].x + scaled_glyph->metrics.x_advance; + y1 = glyphs[num_glyphs - 1].y + scaled_glyph->metrics.y_advance; + + extents->x_advance = x1 - x0; + extents->y_advance = y1 - y0; + } else { + extents->x_advance = 0.0; + extents->y_advance = 0.0; + } + + UNLOCK: + _cairo_scaled_font_thaw_cache (scaled_font); + return; + +ZERO_EXTENTS: + extents->x_bearing = 0.0; + extents->y_bearing = 0.0; + extents->width = 0.0; + extents->height = 0.0; + extents->x_advance = 0.0; + extents->y_advance = 0.0; +} +slim_hidden_def (cairo_scaled_font_glyph_extents); + +#define GLYPH_LUT_SIZE 64 +static cairo_status_t +cairo_scaled_font_text_to_glyphs_internal_cached (cairo_scaled_font_t *scaled_font, + double x, + double y, + const char *utf8, + cairo_glyph_t *glyphs, + cairo_text_cluster_t **clusters, + int num_chars) +{ + struct glyph_lut_elt { + unsigned long index; + double x_advance; + double y_advance; + } glyph_lut[GLYPH_LUT_SIZE]; + uint32_t glyph_lut_unicode[GLYPH_LUT_SIZE]; + cairo_status_t status; + const char *p; + int i; + + for (i = 0; i < GLYPH_LUT_SIZE; i++) + glyph_lut_unicode[i] = ~0U; + + p = utf8; + for (i = 0; i < num_chars; i++) { + int idx, num_bytes; + uint32_t unicode; + cairo_scaled_glyph_t *scaled_glyph; + struct glyph_lut_elt *glyph_slot; + + num_bytes = _cairo_utf8_get_char_validated (p, &unicode); + p += num_bytes; + + glyphs[i].x = x; + glyphs[i].y = y; + + idx = unicode % ARRAY_LENGTH (glyph_lut); + glyph_slot = &glyph_lut[idx]; + if (glyph_lut_unicode[idx] == unicode) { + glyphs[i].index = glyph_slot->index; + x += glyph_slot->x_advance; + y += glyph_slot->y_advance; + } else { + unsigned long g; + + g = scaled_font->backend->ucs4_to_index (scaled_font, unicode); + status = _cairo_scaled_glyph_lookup (scaled_font, + g, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) + return status; + + x += scaled_glyph->metrics.x_advance; + y += scaled_glyph->metrics.y_advance; + + glyph_lut_unicode[idx] = unicode; + glyph_slot->index = g; + glyph_slot->x_advance = scaled_glyph->metrics.x_advance; + glyph_slot->y_advance = scaled_glyph->metrics.y_advance; + + glyphs[i].index = g; + } + + if (clusters) { + (*clusters)[i].num_bytes = num_bytes; + (*clusters)[i].num_glyphs = 1; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_scaled_font_text_to_glyphs_internal_uncached (cairo_scaled_font_t *scaled_font, + double x, + double y, + const char *utf8, + cairo_glyph_t *glyphs, + cairo_text_cluster_t **clusters, + int num_chars) +{ + const char *p; + int i; + + p = utf8; + for (i = 0; i < num_chars; i++) { + unsigned long g; + int num_bytes; + uint32_t unicode; + cairo_scaled_glyph_t *scaled_glyph; + cairo_status_t status; + + num_bytes = _cairo_utf8_get_char_validated (p, &unicode); + p += num_bytes; + + glyphs[i].x = x; + glyphs[i].y = y; + + g = scaled_font->backend->ucs4_to_index (scaled_font, unicode); + + /* + * No advance needed for a single character string. So, let's speed up + * one-character strings by skipping glyph lookup. + */ + if (num_chars > 1) { + status = _cairo_scaled_glyph_lookup (scaled_font, + g, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) + return status; + + x += scaled_glyph->metrics.x_advance; + y += scaled_glyph->metrics.y_advance; + } + + glyphs[i].index = g; + + if (clusters) { + (*clusters)[i].num_bytes = num_bytes; + (*clusters)[i].num_glyphs = 1; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +/** + * cairo_scaled_font_text_to_glyphs: + * @x: X position to place first glyph + * @y: Y position to place first glyph + * @scaled_font: a #cairo_scaled_font_t + * @utf8: a string of text encoded in UTF-8 + * @utf8_len: length of @utf8 in bytes, or -1 if it is NUL-terminated + * @glyphs: pointer to array of glyphs to fill + * @num_glyphs: pointer to number of glyphs + * @clusters: pointer to array of cluster mapping information to fill, or %NULL + * @num_clusters: pointer to number of clusters, or %NULL + * @cluster_flags: pointer to location to store cluster flags corresponding to the + * output @clusters, or %NULL + * + * Converts UTF-8 text to an array of glyphs, optionally with cluster + * mapping, that can be used to render later using @scaled_font. + * + * If @glyphs initially points to a non-%NULL value, that array is used + * as a glyph buffer, and @num_glyphs should point to the number of glyph + * entries available there. If the provided glyph array is too short for + * the conversion, a new glyph array is allocated using cairo_glyph_allocate() + * and placed in @glyphs. Upon return, @num_glyphs always contains the + * number of generated glyphs. If the value @glyphs points to has changed + * after the call, the user is responsible for freeing the allocated glyph + * array using cairo_glyph_free(). This may happen even if the provided + * array was large enough. + * + * If @clusters is not %NULL, @num_clusters and @cluster_flags should not be %NULL, + * and cluster mapping will be computed. + * The semantics of how cluster array allocation works is similar to the glyph + * array. That is, + * if @clusters initially points to a non-%NULL value, that array is used + * as a cluster buffer, and @num_clusters should point to the number of cluster + * entries available there. If the provided cluster array is too short for + * the conversion, a new cluster array is allocated using cairo_text_cluster_allocate() + * and placed in @clusters. Upon return, @num_clusters always contains the + * number of generated clusters. If the value @clusters points at has changed + * after the call, the user is responsible for freeing the allocated cluster + * array using cairo_text_cluster_free(). This may happen even if the provided + * array was large enough. + * + * In the simplest case, @glyphs and @clusters can point to %NULL initially + * and a suitable array will be allocated. In code: + * + * cairo_status_t status; + * + * cairo_glyph_t *glyphs = NULL; + * int num_glyphs; + * cairo_text_cluster_t *clusters = NULL; + * int num_clusters; + * cairo_text_cluster_flags_t cluster_flags; + * + * status = cairo_scaled_font_text_to_glyphs (scaled_font, + * x, y, + * utf8, utf8_len, + * &glyphs, &num_glyphs, + * &clusters, &num_clusters, &cluster_flags); + * + * if (status == CAIRO_STATUS_SUCCESS) { + * cairo_show_text_glyphs (cr, + * utf8, utf8_len, + * glyphs, num_glyphs, + * clusters, num_clusters, cluster_flags); + * + * cairo_glyph_free (glyphs); + * cairo_text_cluster_free (clusters); + * } + * + * + * If no cluster mapping is needed: + * + * cairo_status_t status; + * + * cairo_glyph_t *glyphs = NULL; + * int num_glyphs; + * + * status = cairo_scaled_font_text_to_glyphs (scaled_font, + * x, y, + * utf8, utf8_len, + * &glyphs, &num_glyphs, + * NULL, NULL, + * NULL); + * + * if (status == CAIRO_STATUS_SUCCESS) { + * cairo_show_glyphs (cr, glyphs, num_glyphs); + * cairo_glyph_free (glyphs); + * } + * + * + * If stack-based glyph and cluster arrays are to be used for small + * arrays: + * + * cairo_status_t status; + * + * cairo_glyph_t stack_glyphs[40]; + * cairo_glyph_t *glyphs = stack_glyphs; + * int num_glyphs = sizeof (stack_glyphs) / sizeof (stack_glyphs[0]); + * cairo_text_cluster_t stack_clusters[40]; + * cairo_text_cluster_t *clusters = stack_clusters; + * int num_clusters = sizeof (stack_clusters) / sizeof (stack_clusters[0]); + * cairo_text_cluster_flags_t cluster_flags; + * + * status = cairo_scaled_font_text_to_glyphs (scaled_font, + * x, y, + * utf8, utf8_len, + * &glyphs, &num_glyphs, + * &clusters, &num_clusters, &cluster_flags); + * + * if (status == CAIRO_STATUS_SUCCESS) { + * cairo_show_text_glyphs (cr, + * utf8, utf8_len, + * glyphs, num_glyphs, + * clusters, num_clusters, cluster_flags); + * + * if (glyphs != stack_glyphs) + * cairo_glyph_free (glyphs); + * if (clusters != stack_clusters) + * cairo_text_cluster_free (clusters); + * } + * + * + * For details of how @clusters, @num_clusters, and @cluster_flags map input + * UTF-8 text to the output glyphs see cairo_show_text_glyphs(). + * + * The output values can be readily passed to cairo_show_text_glyphs() + * cairo_show_glyphs(), or related functions, assuming that the exact + * same @scaled_font is used for the operation. + * + * Return value: %CAIRO_STATUS_SUCCESS upon success, or an error status + * if the input values are wrong or if conversion failed. If the input + * values are correct but the conversion failed, the error status is also + * set on @scaled_font. + * + * Since: 1.8 + **/ +#define CACHING_THRESHOLD 16 +cairo_status_t +cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font, + double x, + double y, + const char *utf8, + int utf8_len, + cairo_glyph_t **glyphs, + int *num_glyphs, + cairo_text_cluster_t **clusters, + int *num_clusters, + cairo_text_cluster_flags_t *cluster_flags) +{ + int num_chars = 0; + cairo_int_status_t status; + cairo_glyph_t *orig_glyphs; + cairo_text_cluster_t *orig_clusters; + + status = scaled_font->status; + if (unlikely (status)) + return status; + + /* A slew of sanity checks */ + + /* glyphs and num_glyphs can't be NULL */ + if (glyphs == NULL || + num_glyphs == NULL) { + status = _cairo_error (CAIRO_STATUS_NULL_POINTER); + goto BAIL; + } + + /* Special case for NULL and -1 */ + if (utf8 == NULL && utf8_len == -1) + utf8_len = 0; + + /* No NULLs for non-NULLs! */ + if ((utf8_len && utf8 == NULL) || + (clusters && num_clusters == NULL) || + (clusters && cluster_flags == NULL)) { + status = _cairo_error (CAIRO_STATUS_NULL_POINTER); + goto BAIL; + } + + /* A -1 for utf8_len means NUL-terminated */ + if (utf8_len == -1) + utf8_len = strlen (utf8); + + /* A NULL *glyphs means no prealloced glyphs array */ + if (glyphs && *glyphs == NULL) + *num_glyphs = 0; + + /* A NULL *clusters means no prealloced clusters array */ + if (clusters && *clusters == NULL) + *num_clusters = 0; + + if (!clusters && num_clusters) { + num_clusters = NULL; + } + + if (cluster_flags) { + *cluster_flags = FALSE; + } + + if (!clusters && cluster_flags) { + cluster_flags = NULL; + } + + /* Apart from that, no negatives */ + if (utf8_len < 0 || + *num_glyphs < 0 || + (num_clusters && *num_clusters < 0)) { + status = _cairo_error (CAIRO_STATUS_NEGATIVE_COUNT); + goto BAIL; + } + + if (utf8_len == 0) { + status = CAIRO_STATUS_SUCCESS; + goto BAIL; + } + + /* validate input so backend does not have to */ + status = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, &num_chars); + if (unlikely (status)) + goto BAIL; + + _cairo_scaled_font_freeze_cache (scaled_font); + + orig_glyphs = *glyphs; + orig_clusters = clusters ? *clusters : NULL; + + if (scaled_font->backend->text_to_glyphs) { + status = scaled_font->backend->text_to_glyphs (scaled_font, x, y, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + if (status == CAIRO_INT_STATUS_SUCCESS) { + /* The checks here are crude; we only should do them in + * user-font backend, but they don't hurt here. This stuff + * can be hard to get right. */ + + if (*num_glyphs < 0) { + status = _cairo_error (CAIRO_STATUS_NEGATIVE_COUNT); + goto DONE; + } + if (num_glyphs && *glyphs == NULL) { + status = _cairo_error (CAIRO_STATUS_NULL_POINTER); + goto DONE; + } + + if (clusters) { + if (*num_clusters < 0) { + status = _cairo_error (CAIRO_STATUS_NEGATIVE_COUNT); + goto DONE; + } + if (num_clusters && *clusters == NULL) { + status = _cairo_error (CAIRO_STATUS_NULL_POINTER); + goto DONE; + } + + /* Don't trust the backend, validate clusters! */ + status = + _cairo_validate_text_clusters (utf8, utf8_len, + *glyphs, *num_glyphs, + *clusters, *num_clusters, + *cluster_flags); + } + } + + goto DONE; + } + } + + if (*num_glyphs < num_chars) { + *glyphs = cairo_glyph_allocate (num_chars); + if (unlikely (*glyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto DONE; + } + } + *num_glyphs = num_chars; + + if (clusters) { + if (*num_clusters < num_chars) { + *clusters = cairo_text_cluster_allocate (num_chars); + if (unlikely (*clusters == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto DONE; + } + } + *num_clusters = num_chars; + } + + if (num_chars > CACHING_THRESHOLD) + status = cairo_scaled_font_text_to_glyphs_internal_cached (scaled_font, + x, y, + utf8, + *glyphs, + clusters, + num_chars); + else + status = cairo_scaled_font_text_to_glyphs_internal_uncached (scaled_font, + x, y, + utf8, + *glyphs, + clusters, + num_chars); + + DONE: /* error that should be logged on scaled_font happened */ + _cairo_scaled_font_thaw_cache (scaled_font); + + if (unlikely (status)) { + *num_glyphs = 0; + if (*glyphs != orig_glyphs) { + cairo_glyph_free (*glyphs); + *glyphs = orig_glyphs; + } + + if (clusters) { + *num_clusters = 0; + if (*clusters != orig_clusters) { + cairo_text_cluster_free (*clusters); + *clusters = orig_clusters; + } + } + } + + return _cairo_scaled_font_set_error (scaled_font, status); + + BAIL: /* error with input arguments */ + + if (num_glyphs) + *num_glyphs = 0; + + if (num_clusters) + *num_clusters = 0; + + return status; +} +slim_hidden_def (cairo_scaled_font_text_to_glyphs); + +static inline cairo_bool_t +_range_contains_glyph (const cairo_box_t *extents, + cairo_fixed_t left, + cairo_fixed_t top, + cairo_fixed_t right, + cairo_fixed_t bottom) +{ + if (left == right || top == bottom) + return FALSE; + + return right > extents->p1.x && + left < extents->p2.x && + bottom > extents->p1.y && + top < extents->p2.y; +} + +static cairo_status_t +_cairo_scaled_font_single_glyph_device_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyph, + cairo_rectangle_int_t *extents) +{ + cairo_scaled_glyph_t *scaled_glyph; + cairo_status_t status; + + _cairo_scaled_font_freeze_cache (scaled_font); + status = _cairo_scaled_glyph_lookup (scaled_font, + glyph->index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + cairo_bool_t round_xy = _cairo_font_options_get_round_glyph_positions (&scaled_font->options) == CAIRO_ROUND_GLYPH_POS_ON; + cairo_box_t box; + cairo_fixed_t v; + + if (round_xy) + v = _cairo_fixed_from_int (_cairo_lround (glyph->x)); + else + v = _cairo_fixed_from_double (glyph->x); + box.p1.x = v + scaled_glyph->bbox.p1.x; + box.p2.x = v + scaled_glyph->bbox.p2.x; + + if (round_xy) + v = _cairo_fixed_from_int (_cairo_lround (glyph->y)); + else + v = _cairo_fixed_from_double (glyph->y); + box.p1.y = v + scaled_glyph->bbox.p1.y; + box.p2.y = v + scaled_glyph->bbox.p2.y; + + _cairo_box_round_to_rectangle (&box, extents); + } + _cairo_scaled_font_thaw_cache (scaled_font); + return status; +} + +/* + * Compute a device-space bounding box for the glyphs. + */ +cairo_status_t +_cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_rectangle_int_t *extents, + cairo_bool_t *overlap_out) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_box_t box = { { INT_MAX, INT_MAX }, { INT_MIN, INT_MIN }}; + cairo_scaled_glyph_t *glyph_cache[64]; + cairo_bool_t overlap = overlap_out ? FALSE : TRUE; + cairo_round_glyph_positions_t round_glyph_positions = _cairo_font_options_get_round_glyph_positions (&scaled_font->options); + int i; + + if (unlikely (scaled_font->status)) + return scaled_font->status; + + if (num_glyphs == 1) { + if (overlap_out) + *overlap_out = FALSE; + return _cairo_scaled_font_single_glyph_device_extents (scaled_font, + glyphs, + extents); + } + + _cairo_scaled_font_freeze_cache (scaled_font); + + memset (glyph_cache, 0, sizeof (glyph_cache)); + + for (i = 0; i < num_glyphs; i++) { + cairo_scaled_glyph_t *scaled_glyph; + cairo_fixed_t x, y, x1, y1, x2, y2; + int cache_index = glyphs[i].index % ARRAY_LENGTH (glyph_cache); + + scaled_glyph = glyph_cache[cache_index]; + if (scaled_glyph == NULL || + _cairo_scaled_glyph_index (scaled_glyph) != glyphs[i].index) + { + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) + break; + + glyph_cache[cache_index] = scaled_glyph; + } + + if (round_glyph_positions == CAIRO_ROUND_GLYPH_POS_ON) + x = _cairo_fixed_from_int (_cairo_lround (glyphs[i].x)); + else + x = _cairo_fixed_from_double (glyphs[i].x); + x1 = x + scaled_glyph->bbox.p1.x; + x2 = x + scaled_glyph->bbox.p2.x; + + if (round_glyph_positions == CAIRO_ROUND_GLYPH_POS_ON) + y = _cairo_fixed_from_int (_cairo_lround (glyphs[i].y)); + else + y = _cairo_fixed_from_double (glyphs[i].y); + y1 = y + scaled_glyph->bbox.p1.y; + y2 = y + scaled_glyph->bbox.p2.y; + + if (overlap == FALSE) + overlap = _range_contains_glyph (&box, x1, y1, x2, y2); + + if (x1 < box.p1.x) box.p1.x = x1; + if (x2 > box.p2.x) box.p2.x = x2; + if (y1 < box.p1.y) box.p1.y = y1; + if (y2 > box.p2.y) box.p2.y = y2; + } + + _cairo_scaled_font_thaw_cache (scaled_font); + if (unlikely (status)) + return _cairo_scaled_font_set_error (scaled_font, status); + + if (box.p1.x < box.p2.x) { + _cairo_box_round_to_rectangle (&box, extents); + } else { + extents->x = extents->y = 0; + extents->width = extents->height = 0; + } + + if (overlap_out != NULL) + *overlap_out = overlap; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_bool_t +_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_rectangle_int_t *extents) +{ + double x0, x1, y0, y1, pad; + int i; + + /* If any of the factors are suspect (i.e. the font is broken), bail */ + if (scaled_font->fs_extents.max_x_advance == 0 || + scaled_font->fs_extents.height == 0 || + scaled_font->max_scale == 0) + { + return FALSE; + } + + assert (num_glyphs); + + x0 = x1 = glyphs[0].x; + y0 = y1 = glyphs[0].y; + for (i = 1; i < num_glyphs; i++) { + double g; + + g = glyphs[i].x; + if (g < x0) x0 = g; + if (g > x1) x1 = g; + + g = glyphs[i].y; + if (g < y0) y0 = g; + if (g > y1) y1 = g; + } + + pad = MAX(scaled_font->fs_extents.max_x_advance, + scaled_font->fs_extents.height); + pad *= scaled_font->max_scale; + + extents->x = floor (x0 - pad); + extents->width = ceil (x1 + pad) - extents->x; + extents->y = floor (y0 - pad); + extents->height = ceil (y1 + pad) - extents->y; + return TRUE; +} + +#if 0 +/* XXX win32 */ +cairo_status_t +_cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, + cairo_operator_t op, + const cairo_pattern_t *pattern, + cairo_surface_t *surface, + int source_x, + int source_y, + int dest_x, + int dest_y, + unsigned int width, + unsigned int height, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_region_t *clip_region) +{ + cairo_int_status_t status; + cairo_surface_t *mask = NULL; + cairo_format_t mask_format = CAIRO_FORMAT_A1; /* shut gcc up */ + cairo_surface_pattern_t mask_pattern; + int i; + + /* These operators aren't interpreted the same way by the backends; + * they are implemented in terms of other operators in cairo-gstate.c + */ + assert (op != CAIRO_OPERATOR_SOURCE && op != CAIRO_OPERATOR_CLEAR); + + if (scaled_font->status) + return scaled_font->status; + + if (!num_glyphs) + return CAIRO_STATUS_SUCCESS; + + if (scaled_font->backend->show_glyphs != NULL) { + int remaining_glyphs = num_glyphs; + status = scaled_font->backend->show_glyphs (scaled_font, + op, pattern, + surface, + source_x, source_y, + dest_x, dest_y, + width, height, + glyphs, num_glyphs, + clip_region, + &remaining_glyphs); + glyphs += num_glyphs - remaining_glyphs; + num_glyphs = remaining_glyphs; + if (remaining_glyphs == 0) + status = CAIRO_INT_STATUS_SUCCESS; + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return _cairo_scaled_font_set_error (scaled_font, status); + } + + /* Font display routine either does not exist or failed. */ + + _cairo_scaled_font_freeze_cache (scaled_font); + + for (i = 0; i < num_glyphs; i++) { + int x, y; + cairo_image_surface_t *glyph_surface; + cairo_scaled_glyph_t *scaled_glyph; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + + if (unlikely (status)) + goto CLEANUP_MASK; + + glyph_surface = scaled_glyph->surface; + + /* To start, create the mask using the format from the first + * glyph. Later we'll deal with different formats. */ + if (mask == NULL) { + mask_format = glyph_surface->format; + mask = cairo_image_surface_create (mask_format, width, height); + status = mask->status; + if (unlikely (status)) + goto CLEANUP_MASK; + } + + /* If we have glyphs of different formats, we "upgrade" the mask + * to the wider of the formats. */ + if (glyph_surface->format != mask_format && + _cairo_format_bits_per_pixel (mask_format) < + _cairo_format_bits_per_pixel (glyph_surface->format) ) + { + cairo_surface_t *new_mask; + + switch (glyph_surface->format) { + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_A8: + case CAIRO_FORMAT_A1: + mask_format = glyph_surface->format; + break; + case CAIRO_FORMAT_RGB16_565: + case CAIRO_FORMAT_RGB24: + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_INVALID: + default: + ASSERT_NOT_REACHED; + mask_format = CAIRO_FORMAT_ARGB32; + break; + } + + new_mask = cairo_image_surface_create (mask_format, width, height); + status = new_mask->status; + if (unlikely (status)) { + cairo_surface_destroy (new_mask); + goto CLEANUP_MASK; + } + + _cairo_pattern_init_for_surface (&mask_pattern, mask); + /* Note that we only upgrade masks, i.e. A1 -> A8 -> ARGB32, so there is + * never any component alpha here. + */ + status = _cairo_surface_composite (CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + &mask_pattern.base, + new_mask, + 0, 0, + 0, 0, + 0, 0, + width, height, + NULL); + + _cairo_pattern_fini (&mask_pattern.base); + + if (unlikely (status)) { + cairo_surface_destroy (new_mask); + goto CLEANUP_MASK; + } + + cairo_surface_destroy (mask); + mask = new_mask; + } + + if (glyph_surface->width && glyph_surface->height) { + cairo_surface_pattern_t glyph_pattern; + + /* round glyph locations to the nearest pixel */ + /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ + x = _cairo_lround (glyphs[i].x - + glyph_surface->base.device_transform.x0); + y = _cairo_lround (glyphs[i].y - + glyph_surface->base.device_transform.y0); + + _cairo_pattern_init_for_surface (&glyph_pattern, + &glyph_surface->base); + if (mask_format == CAIRO_FORMAT_ARGB32) + glyph_pattern.base.has_component_alpha = TRUE; + + status = _cairo_surface_composite (CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + &glyph_pattern.base, + mask, + 0, 0, + 0, 0, + x - dest_x, y - dest_y, + glyph_surface->width, + glyph_surface->height, + NULL); + + _cairo_pattern_fini (&glyph_pattern.base); + + if (unlikely (status)) + goto CLEANUP_MASK; + } + } + + _cairo_pattern_init_for_surface (&mask_pattern, mask); + if (mask_format == CAIRO_FORMAT_ARGB32) + mask_pattern.base.has_component_alpha = TRUE; + + status = _cairo_surface_composite (op, pattern, &mask_pattern.base, + surface, + source_x, source_y, + 0, 0, + dest_x, dest_y, + width, height, + clip_region); + + _cairo_pattern_fini (&mask_pattern.base); + +CLEANUP_MASK: + _cairo_scaled_font_thaw_cache (scaled_font); + + if (mask != NULL) + cairo_surface_destroy (mask); + return _cairo_scaled_font_set_error (scaled_font, status); +} +#endif + +/* Add a single-device-unit rectangle to a path. */ +static cairo_status_t +_add_unit_rectangle_to_path (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y) +{ + cairo_status_t status; + + status = _cairo_path_fixed_move_to (path, x, y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (1), + _cairo_fixed_from_int (0)); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (0), + _cairo_fixed_from_int (1)); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_rel_line_to (path, + _cairo_fixed_from_int (-1), + _cairo_fixed_from_int (0)); + if (unlikely (status)) + return status; + + return _cairo_path_fixed_close_path (path); +} + +/** + * _trace_mask_to_path: + * @bitmap: An alpha mask (either %CAIRO_FORMAT_A1 or %CAIRO_FORMAT_A8) + * @path: An initialized path to hold the result + * + * Given a mask surface, (an alpha image), fill out the provided path + * so that when filled it would result in something that approximates + * the mask. + * + * Note: The current tracing code here is extremely primitive. It + * operates only on an A1 surface, (converting an A8 surface to A1 if + * necessary), and performs the tracing by drawing a little square + * around each pixel that is on in the mask. We do not pretend that + * this is a high-quality result. But we are leaving it up to someone + * who cares enough about getting a better result to implement + * something more sophisticated. + **/ +static cairo_status_t +_trace_mask_to_path (cairo_image_surface_t *mask, + cairo_path_fixed_t *path, + double tx, double ty) +{ + const uint8_t *row; + int rows, cols, bytes_per_row; + int x, y, bit; + double xoff, yoff; + cairo_fixed_t x0, y0; + cairo_fixed_t px, py; + cairo_status_t status; + + mask = _cairo_image_surface_coerce_to_format (mask, CAIRO_FORMAT_A1); + status = mask->base.status; + if (unlikely (status)) + return status; + + cairo_surface_get_device_offset (&mask->base, &xoff, &yoff); + x0 = _cairo_fixed_from_double (tx - xoff); + y0 = _cairo_fixed_from_double (ty - yoff); + + bytes_per_row = (mask->width + 7) / 8; + row = mask->data; + for (y = 0, rows = mask->height; rows--; row += mask->stride, y++) { + const uint8_t *byte_ptr = row; + x = 0; + py = _cairo_fixed_from_int (y); + for (cols = bytes_per_row; cols--; ) { + uint8_t byte = *byte_ptr++; + if (byte == 0) { + x += 8; + continue; + } + + byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (byte); + for (bit = 1 << 7; bit && x < mask->width; bit >>= 1, x++) { + if (byte & bit) { + px = _cairo_fixed_from_int (x); + status = _add_unit_rectangle_to_path (path, + px + x0, + py + y0); + if (unlikely (status)) + goto BAIL; + } + } + } + } + +BAIL: + cairo_surface_destroy (&mask->base); + + return status; +} + +cairo_status_t +_cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_path_fixed_t *path) +{ + cairo_int_status_t status; + int i; + + status = scaled_font->status; + if (unlikely (status)) + return status; + + _cairo_scaled_font_freeze_cache (scaled_font); + for (i = 0; i < num_glyphs; i++) { + cairo_scaled_glyph_t *scaled_glyph; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_PATH, + &scaled_glyph); + if (status == CAIRO_INT_STATUS_SUCCESS) { + status = _cairo_path_fixed_append (path, + scaled_glyph->path, + _cairo_fixed_from_double (glyphs[i].x), + _cairo_fixed_from_double (glyphs[i].y)); + + } else if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + /* If the font is incapable of providing a path, then we'll + * have to trace our own from a surface. + */ + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + if (unlikely (status)) + goto BAIL; + + status = _trace_mask_to_path (scaled_glyph->surface, path, + glyphs[i].x, glyphs[i].y); + } + + if (unlikely (status)) + goto BAIL; + } + BAIL: + _cairo_scaled_font_thaw_cache (scaled_font); + + return _cairo_scaled_font_set_error (scaled_font, status); +} + +/** + * _cairo_scaled_glyph_set_metrics: + * @scaled_glyph: a #cairo_scaled_glyph_t + * @scaled_font: a #cairo_scaled_font_t + * @fs_metrics: a #cairo_text_extents_t in font space + * + * _cairo_scaled_glyph_set_metrics() stores user space metrics + * for the specified glyph given font space metrics. It is + * called by the font backend when initializing a glyph with + * %CAIRO_SCALED_GLYPH_INFO_METRICS. + **/ +void +_cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_text_extents_t *fs_metrics) +{ + cairo_bool_t first = TRUE; + double hm, wm; + double min_user_x = 0.0, max_user_x = 0.0, min_user_y = 0.0, max_user_y = 0.0; + double min_device_x = 0.0, max_device_x = 0.0, min_device_y = 0.0, max_device_y = 0.0; + double device_x_advance, device_y_advance; + + scaled_glyph->fs_metrics = *fs_metrics; + + for (hm = 0.0; hm <= 1.0; hm += 1.0) + for (wm = 0.0; wm <= 1.0; wm += 1.0) { + double x, y; + + /* Transform this corner to user space */ + x = fs_metrics->x_bearing + fs_metrics->width * wm; + y = fs_metrics->y_bearing + fs_metrics->height * hm; + cairo_matrix_transform_point (&scaled_font->font_matrix, + &x, &y); + if (first) { + min_user_x = max_user_x = x; + min_user_y = max_user_y = y; + } else { + if (x < min_user_x) min_user_x = x; + if (x > max_user_x) max_user_x = x; + if (y < min_user_y) min_user_y = y; + if (y > max_user_y) max_user_y = y; + } + + /* Transform this corner to device space from glyph origin */ + x = fs_metrics->x_bearing + fs_metrics->width * wm; + y = fs_metrics->y_bearing + fs_metrics->height * hm; + cairo_matrix_transform_distance (&scaled_font->scale, + &x, &y); + + if (first) { + min_device_x = max_device_x = x; + min_device_y = max_device_y = y; + } else { + if (x < min_device_x) min_device_x = x; + if (x > max_device_x) max_device_x = x; + if (y < min_device_y) min_device_y = y; + if (y > max_device_y) max_device_y = y; + } + first = FALSE; + } + scaled_glyph->metrics.x_bearing = min_user_x; + scaled_glyph->metrics.y_bearing = min_user_y; + scaled_glyph->metrics.width = max_user_x - min_user_x; + scaled_glyph->metrics.height = max_user_y - min_user_y; + + scaled_glyph->metrics.x_advance = fs_metrics->x_advance; + scaled_glyph->metrics.y_advance = fs_metrics->y_advance; + cairo_matrix_transform_distance (&scaled_font->font_matrix, + &scaled_glyph->metrics.x_advance, + &scaled_glyph->metrics.y_advance); + + device_x_advance = fs_metrics->x_advance; + device_y_advance = fs_metrics->y_advance; + cairo_matrix_transform_distance (&scaled_font->scale, + &device_x_advance, + &device_y_advance); + + scaled_glyph->bbox.p1.x = _cairo_fixed_from_double (min_device_x); + scaled_glyph->bbox.p1.y = _cairo_fixed_from_double (min_device_y); + scaled_glyph->bbox.p2.x = _cairo_fixed_from_double (max_device_x); + scaled_glyph->bbox.p2.y = _cairo_fixed_from_double (max_device_y); + + scaled_glyph->x_advance = _cairo_lround (device_x_advance); + scaled_glyph->y_advance = _cairo_lround (device_y_advance); + + scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_METRICS; +} + +void +_cairo_scaled_glyph_set_surface (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_image_surface_t *surface) +{ + if (scaled_glyph->surface != NULL) + cairo_surface_destroy (&scaled_glyph->surface->base); + + /* sanity check the backend glyph contents */ + _cairo_debug_check_image_surface_is_defined (&surface->base); + scaled_glyph->surface = surface; + + if (surface != NULL) + scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_SURFACE; + else + scaled_glyph->has_info &= ~CAIRO_SCALED_GLYPH_INFO_SURFACE; +} + +void +_cairo_scaled_glyph_set_path (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_path_fixed_t *path) +{ + if (scaled_glyph->path != NULL) + _cairo_path_fixed_destroy (scaled_glyph->path); + + scaled_glyph->path = path; + + if (path != NULL) + scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_PATH; + else + scaled_glyph->has_info &= ~CAIRO_SCALED_GLYPH_INFO_PATH; +} + +void +_cairo_scaled_glyph_set_recording_surface (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_surface_t *recording_surface) +{ + if (scaled_glyph->recording_surface != NULL) { + cairo_surface_finish (scaled_glyph->recording_surface); + cairo_surface_destroy (scaled_glyph->recording_surface); + } + + scaled_glyph->recording_surface = recording_surface; + + if (recording_surface != NULL) + scaled_glyph->has_info |= CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE; + else + scaled_glyph->has_info &= ~CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE; +} + +static cairo_bool_t +_cairo_scaled_glyph_page_can_remove (const void *closure) +{ + const cairo_scaled_glyph_page_t *page = closure; + const cairo_scaled_font_t *scaled_font; + + scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash; + return scaled_font->cache_frozen == 0; +} + +static cairo_status_t +_cairo_scaled_font_allocate_glyph (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_t **scaled_glyph) +{ + cairo_scaled_glyph_page_t *page; + cairo_status_t status; + + assert (scaled_font->cache_frozen); + + /* only the first page in the list may contain available slots */ + if (! cairo_list_is_empty (&scaled_font->glyph_pages)) { + page = cairo_list_last_entry (&scaled_font->glyph_pages, + cairo_scaled_glyph_page_t, + link); + if (page->num_glyphs < CAIRO_SCALED_GLYPH_PAGE_SIZE) { + *scaled_glyph = &page->glyphs[page->num_glyphs++]; + return CAIRO_STATUS_SUCCESS; + } + } + + page = malloc (sizeof (cairo_scaled_glyph_page_t)); + if (unlikely (page == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + page->cache_entry.hash = (unsigned long) scaled_font; + page->cache_entry.size = 1; /* XXX occupancy weighting? */ + page->num_glyphs = 0; + + CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); + if (scaled_font->global_cache_frozen == FALSE) { + if (unlikely (cairo_scaled_glyph_page_cache.hash_table == NULL)) { + status = _cairo_cache_init (&cairo_scaled_glyph_page_cache, + NULL, + _cairo_scaled_glyph_page_can_remove, + _cairo_scaled_glyph_page_pluck, + MAX_GLYPH_PAGES_CACHED); + if (unlikely (status)) { + CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); + free (page); + return status; + } + } + + _cairo_cache_freeze (&cairo_scaled_glyph_page_cache); + scaled_font->global_cache_frozen = TRUE; + } + + status = _cairo_cache_insert (&cairo_scaled_glyph_page_cache, + &page->cache_entry); + CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); + if (unlikely (status)) { + free (page); + return status; + } + + cairo_list_add_tail (&page->link, &scaled_font->glyph_pages); + + *scaled_glyph = &page->glyphs[page->num_glyphs++]; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_scaled_font_free_last_glyph (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_scaled_glyph_page_t *page; + + assert (! cairo_list_is_empty (&scaled_font->glyph_pages)); + page = cairo_list_last_entry (&scaled_font->glyph_pages, + cairo_scaled_glyph_page_t, + link); + assert (scaled_glyph == &page->glyphs[page->num_glyphs-1]); + + _cairo_scaled_glyph_fini (scaled_font, scaled_glyph); + + if (--page->num_glyphs == 0) { + CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); + /* Temporarily disconnect callback to avoid recursive locking */ + cairo_scaled_glyph_page_cache.entry_destroy = NULL; + _cairo_cache_remove (&cairo_scaled_glyph_page_cache, + &page->cache_entry); + _cairo_scaled_glyph_page_destroy (scaled_font, page); + cairo_scaled_glyph_page_cache.entry_destroy = _cairo_scaled_glyph_page_pluck; + CAIRO_MUTEX_UNLOCK (_cairo_scaled_glyph_page_cache_mutex); + } +} + +/** + * _cairo_scaled_glyph_lookup: + * @scaled_font: a #cairo_scaled_font_t + * @index: the glyph to create + * @info: a #cairo_scaled_glyph_info_t marking which portions of + * the glyph should be filled in. + * @scaled_glyph_ret: a #cairo_scaled_glyph_t where the glyph + * is returned. + * + * If the desired info is not available, (for example, when trying to + * get INFO_PATH with a bitmapped font), this function will return + * %CAIRO_INT_STATUS_UNSUPPORTED. + * + * Note: This function must be called with the scaled font frozen, and it must + * remain frozen for as long as the @scaled_glyph_ret is alive. (If the scaled + * font was not frozen, then there is no guarantee that the glyph would not be + * evicted before you tried to access it.) See + * _cairo_scaled_font_freeze_cache() and _cairo_scaled_font_thaw_cache(). + * + * Returns: a glyph with the requested portions filled in. Glyph + * lookup is cached and glyph will be automatically freed along + * with the scaled_font so no explicit free is required. + * @info can be one or more of: + * %CAIRO_SCALED_GLYPH_INFO_METRICS - glyph metrics and bounding box + * %CAIRO_SCALED_GLYPH_INFO_SURFACE - surface holding glyph image + * %CAIRO_SCALED_GLYPH_INFO_PATH - path holding glyph outline in device space + **/ +cairo_int_status_t +_cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font, + unsigned long index, + cairo_scaled_glyph_info_t info, + cairo_scaled_glyph_t **scaled_glyph_ret) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + cairo_scaled_glyph_t *scaled_glyph; + cairo_scaled_glyph_info_t need_info; + + *scaled_glyph_ret = NULL; + + if (unlikely (scaled_font->status)) + return scaled_font->status; + + assert (CAIRO_MUTEX_IS_LOCKED(scaled_font->mutex)); + assert (scaled_font->cache_frozen); + + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* + * Check cache for glyph + */ + scaled_glyph = _cairo_hash_table_lookup (scaled_font->glyphs, + (cairo_hash_entry_t *) &index); + if (scaled_glyph == NULL) { + status = _cairo_scaled_font_allocate_glyph (scaled_font, &scaled_glyph); + if (unlikely (status)) + goto err; + + memset (scaled_glyph, 0, sizeof (cairo_scaled_glyph_t)); + _cairo_scaled_glyph_set_index (scaled_glyph, index); + cairo_list_init (&scaled_glyph->dev_privates); + + /* ask backend to initialize metrics and shape fields */ + status = + scaled_font->backend->scaled_glyph_init (scaled_font, + scaled_glyph, + info | CAIRO_SCALED_GLYPH_INFO_METRICS); + if (unlikely (status)) { + _cairo_scaled_font_free_last_glyph (scaled_font, scaled_glyph); + goto err; + } + + status = _cairo_hash_table_insert (scaled_font->glyphs, + &scaled_glyph->hash_entry); + if (unlikely (status)) { + _cairo_scaled_font_free_last_glyph (scaled_font, scaled_glyph); + goto err; + } + } + + /* + * Check and see if the glyph, as provided, + * already has the requested data and amend it if not + */ + need_info = info & ~scaled_glyph->has_info; + if (need_info) { + status = scaled_font->backend->scaled_glyph_init (scaled_font, + scaled_glyph, + need_info); + if (unlikely (status)) + goto err; + + /* Don't trust the scaled_glyph_init() return value, the font + * backend may not even know about some of the info. For example, + * no backend other than the user-fonts knows about recording-surface + * glyph info. */ + if (info & ~scaled_glyph->has_info) + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + *scaled_glyph_ret = scaled_glyph; + return CAIRO_STATUS_SUCCESS; + +err: + /* It's not an error for the backend to not support the info we want. */ + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + status = _cairo_scaled_font_set_error (scaled_font, status); + return status; +} + +double +_cairo_scaled_font_get_max_scale (cairo_scaled_font_t *scaled_font) +{ + return scaled_font->max_scale; +} + + +/** + * cairo_scaled_font_get_font_face: + * @scaled_font: a #cairo_scaled_font_t + * + * Gets the font face that this scaled font uses. This might be the + * font face passed to cairo_scaled_font_create(), but this does not + * hold true for all possible cases. + * + * Return value: The #cairo_font_face_t with which @scaled_font was + * created. This object is owned by cairo. To keep a reference to it, + * you must call cairo_scaled_font_reference(). + * + * Since: 1.2 + **/ +cairo_font_face_t * +cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font) +{ + if (scaled_font->status) + return (cairo_font_face_t*) &_cairo_font_face_nil; + + if (scaled_font->original_font_face != NULL) + return scaled_font->original_font_face; + + return scaled_font->font_face; +} +slim_hidden_def (cairo_scaled_font_get_font_face); + +/** + * cairo_scaled_font_get_font_matrix: + * @scaled_font: a #cairo_scaled_font_t + * @font_matrix: return value for the matrix + * + * Stores the font matrix with which @scaled_font was created into + * @matrix. + * + * Since: 1.2 + **/ +void +cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *font_matrix) +{ + if (scaled_font->status) { + cairo_matrix_init_identity (font_matrix); + return; + } + + *font_matrix = scaled_font->font_matrix; +} +slim_hidden_def (cairo_scaled_font_get_font_matrix); + +/** + * cairo_scaled_font_get_ctm: + * @scaled_font: a #cairo_scaled_font_t + * @ctm: return value for the CTM + * + * Stores the CTM with which @scaled_font was created into @ctm. + * Note that the translation offsets (x0, y0) of the CTM are ignored + * by cairo_scaled_font_create(). So, the matrix this + * function returns always has 0,0 as x0,y0. + * + * Since: 1.2 + **/ +void +cairo_scaled_font_get_ctm (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *ctm) +{ + if (scaled_font->status) { + cairo_matrix_init_identity (ctm); + return; + } + + *ctm = scaled_font->ctm; +} +slim_hidden_def (cairo_scaled_font_get_ctm); + +/** + * cairo_scaled_font_get_scale_matrix: + * @scaled_font: a #cairo_scaled_font_t + * @scale_matrix: return value for the matrix + * + * Stores the scale matrix of @scaled_font into @matrix. + * The scale matrix is product of the font matrix and the ctm + * associated with the scaled font, and hence is the matrix mapping from + * font space to device space. + * + * Since: 1.8 + **/ +void +cairo_scaled_font_get_scale_matrix (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *scale_matrix) +{ + if (scaled_font->status) { + cairo_matrix_init_identity (scale_matrix); + return; + } + + *scale_matrix = scaled_font->scale; +} + +/** + * cairo_scaled_font_get_font_options: + * @scaled_font: a #cairo_scaled_font_t + * @options: return value for the font options + * + * Stores the font options with which @scaled_font was created into + * @options. + * + * Since: 1.2 + **/ +void +cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font, + cairo_font_options_t *options) +{ + if (cairo_font_options_status (options)) + return; + + if (scaled_font->status) { + _cairo_font_options_init_default (options); + return; + } + + _cairo_font_options_init_copy (options, &scaled_font->options); +} +slim_hidden_def (cairo_scaled_font_get_font_options); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-script-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-script-private.h new file mode 100644 index 00000000000..5b506f500cd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-script-private.h @@ -0,0 +1,59 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SCRIPT_PRIVATE_H +#define CAIRO_SCRIPT_PRIVATE_H + +#include "cairo.h" +#include "cairo-script.h" + +#include "cairo-compiler-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-types-private.h" + +CAIRO_BEGIN_DECLS + +cairo_private cairo_device_t * +_cairo_script_context_create_internal (cairo_output_stream_t *stream); + +cairo_private void +_cairo_script_context_attach_snapshots (cairo_device_t *device, + cairo_bool_t enable); + +slim_hidden_proto (cairo_script_surface_create); + +CAIRO_END_DECLS + +#endif /* CAIRO_SCRIPT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-script-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-script-surface.c new file mode 100644 index 00000000000..a4cefdebb4b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-script-surface.c @@ -0,0 +1,3999 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + */ + +/* The script surface is one that records all operations performed on + * it in the form of a procedural script, similar in fashion to + * PostScript but using Cairo's imaging model. In essence, this is + * equivalent to the recording-surface, but as there is no impedance mismatch + * between Cairo and CairoScript, we can generate output immediately + * without having to copy and hold the data in memory. + */ + +/** + * SECTION:cairo-script + * @Title: Script Surfaces + * @Short_Description: Rendering to replayable scripts + * @See_Also: #cairo_surface_t + * + * The script surface provides the ability to render to a native + * script that matches the cairo drawing model. The scripts can + * be replayed using tools under the util/cairo-script directory, + * or with cairo-perf-trace. + **/ + +/** + * CAIRO_HAS_SCRIPT_SURFACE: + * + * Defined if the script surface backend is available. + * The script surface backend is always built in since 1.12. + * + * Since: 1.12 + **/ + + +#include "cairoint.h" + +#include "cairo-script.h" +#include "cairo-script-private.h" + +#include "cairo-analysis-surface-private.h" +#include "cairo-default-context-private.h" +#include "cairo-device-private.h" +#include "cairo-error-private.h" +#include "cairo-list-inline.h" +#include "cairo-image-surface-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-pattern-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-scaled-font-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-private.h" +#include "cairo-surface-wrapper-private.h" + +#if CAIRO_HAS_FT_FONT +#include "cairo-ft-private.h" +#endif + +#include + +#ifdef WORDS_BIGENDIAN +#define to_be32(x) x +#else +#define to_be32(x) bswap_32(x) +#endif + +#define _cairo_output_stream_puts(S, STR) \ + _cairo_output_stream_write ((S), (STR), strlen (STR)) + +#define static cairo_warn static + +typedef struct _cairo_script_context cairo_script_context_t; +typedef struct _cairo_script_surface cairo_script_surface_t; +typedef struct _cairo_script_implicit_context cairo_script_implicit_context_t; +typedef struct _cairo_script_font cairo_script_font_t; + +typedef struct _operand { + enum { + SURFACE, + DEFERRED, + } type; + cairo_list_t link; +} operand_t; + + +struct deferred_finish { + cairo_list_t link; + operand_t operand; +}; + +struct _cairo_script_context { + cairo_device_t base; + + int active; + int attach_snapshots; + + cairo_bool_t owns_stream; + cairo_output_stream_t *stream; + cairo_script_mode_t mode; + + struct _bitmap { + unsigned long min; + unsigned long count; + unsigned int map[64]; + struct _bitmap *next; + } surface_id, font_id; + + cairo_list_t operands; + cairo_list_t deferred; + + cairo_list_t fonts; + cairo_list_t defines; +}; + +struct _cairo_script_font { + cairo_scaled_font_private_t base; + + cairo_bool_t has_sfnt; + unsigned long id; + unsigned long subset_glyph_index; + cairo_list_t link; + cairo_scaled_font_t *parent; +}; + +struct _cairo_script_implicit_context { + cairo_operator_t current_operator; + cairo_fill_rule_t current_fill_rule; + double current_tolerance; + cairo_antialias_t current_antialias; + cairo_stroke_style_t current_style; + cairo_pattern_union_t current_source; + cairo_matrix_t current_ctm; + cairo_matrix_t current_stroke_matrix; + cairo_matrix_t current_font_matrix; + cairo_font_options_t current_font_options; + cairo_scaled_font_t *current_scaled_font; + cairo_path_fixed_t current_path; + cairo_bool_t has_clip; +}; + +struct _cairo_script_surface { + cairo_surface_t base; + + cairo_surface_wrapper_t wrapper; + + cairo_surface_clipper_t clipper; + + operand_t operand; + cairo_bool_t emitted; + cairo_bool_t defined; + cairo_bool_t active; + + double width, height; + + /* implicit flattened context */ + cairo_script_implicit_context_t cr; +}; + +static const cairo_surface_backend_t _cairo_script_surface_backend; + +static cairo_script_surface_t * +_cairo_script_surface_create_internal (cairo_script_context_t *ctx, + cairo_content_t content, + cairo_rectangle_t *extents, + cairo_surface_t *passthrough); + +static void +_cairo_script_scaled_font_fini (cairo_scaled_font_private_t *abstract_private, + cairo_scaled_font_t *scaled_font); + +static void +_cairo_script_implicit_context_init (cairo_script_implicit_context_t *cr); + +static void +_cairo_script_implicit_context_reset (cairo_script_implicit_context_t *cr); + +static void +_bitmap_release_id (struct _bitmap *b, unsigned long token) +{ + struct _bitmap **prev = NULL; + + do { + if (token < b->min + sizeof (b->map) * CHAR_BIT) { + unsigned int bit, elem; + + token -= b->min; + elem = token / (sizeof (b->map[0]) * CHAR_BIT); + bit = token % (sizeof (b->map[0]) * CHAR_BIT); + b->map[elem] &= ~(1 << bit); + if (! --b->count && prev) { + *prev = b->next; + free (b); + } + return; + } + prev = &b->next; + b = b->next; + } while (b != NULL); +} + +static cairo_status_t +_bitmap_next_id (struct _bitmap *b, + unsigned long *id) +{ + struct _bitmap *bb, **prev = NULL; + unsigned long min = 0; + + do { + if (b->min != min) + break; + + if (b->count < sizeof (b->map) * CHAR_BIT) { + unsigned int n, m, bit; + for (n = 0; n < ARRAY_LENGTH (b->map); n++) { + if (b->map[n] == (unsigned int) -1) + continue; + + for (m=0, bit=1; mmap[0])*CHAR_BIT; m++, bit<<=1) { + if ((b->map[n] & bit) == 0) { + b->map[n] |= bit; + b->count++; + *id = n * sizeof (b->map[0])*CHAR_BIT + m + b->min; + return CAIRO_STATUS_SUCCESS; + } + } + } + } + min += sizeof (b->map) * CHAR_BIT; + + prev = &b->next; + b = b->next; + } while (b != NULL); + + bb = malloc (sizeof (struct _bitmap)); + if (unlikely (bb == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + *prev = bb; + bb->next = b; + bb->min = min; + bb->count = 1; + bb->map[0] = 0x1; + memset (bb->map + 1, 0, sizeof (bb->map) - sizeof (bb->map[0])); + *id = min; + + return CAIRO_STATUS_SUCCESS; +} + +static void +_bitmap_fini (struct _bitmap *b) +{ + while (b != NULL) { + struct _bitmap *next = b->next; + free (b); + b = next; + } +} + +static const char * +_direction_to_string (cairo_bool_t backward) +{ + static const char *names[] = { + "FORWARD", + "BACKWARD" + }; + assert (backward < ARRAY_LENGTH (names)); + return names[backward]; +} + +static const char * +_operator_to_string (cairo_operator_t op) +{ + static const char *names[] = { + "CLEAR", /* CAIRO_OPERATOR_CLEAR */ + + "SOURCE", /* CAIRO_OPERATOR_SOURCE */ + "OVER", /* CAIRO_OPERATOR_OVER */ + "IN", /* CAIRO_OPERATOR_IN */ + "OUT", /* CAIRO_OPERATOR_OUT */ + "ATOP", /* CAIRO_OPERATOR_ATOP */ + + "DEST", /* CAIRO_OPERATOR_DEST */ + "DEST_OVER", /* CAIRO_OPERATOR_DEST_OVER */ + "DEST_IN", /* CAIRO_OPERATOR_DEST_IN */ + "DEST_OUT", /* CAIRO_OPERATOR_DEST_OUT */ + "DEST_ATOP", /* CAIRO_OPERATOR_DEST_ATOP */ + + "XOR", /* CAIRO_OPERATOR_XOR */ + "ADD", /* CAIRO_OPERATOR_ADD */ + "SATURATE", /* CAIRO_OPERATOR_SATURATE */ + + "MULTIPLY", /* CAIRO_OPERATOR_MULTIPLY */ + "SCREEN", /* CAIRO_OPERATOR_SCREEN */ + "OVERLAY", /* CAIRO_OPERATOR_OVERLAY */ + "DARKEN", /* CAIRO_OPERATOR_DARKEN */ + "LIGHTEN", /* CAIRO_OPERATOR_LIGHTEN */ + "DODGE", /* CAIRO_OPERATOR_COLOR_DODGE */ + "BURN", /* CAIRO_OPERATOR_COLOR_BURN */ + "HARD_LIGHT", /* CAIRO_OPERATOR_HARD_LIGHT */ + "SOFT_LIGHT", /* CAIRO_OPERATOR_SOFT_LIGHT */ + "DIFFERENCE", /* CAIRO_OPERATOR_DIFFERENCE */ + "EXCLUSION", /* CAIRO_OPERATOR_EXCLUSION */ + "HSL_HUE", /* CAIRO_OPERATOR_HSL_HUE */ + "HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */ + "HSL_COLOR", /* CAIRO_OPERATOR_HSL_COLOR */ + "HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */ + }; + assert (op < ARRAY_LENGTH (names)); + return names[op]; +} + +static const char * +_extend_to_string (cairo_extend_t extend) +{ + static const char *names[] = { + "EXTEND_NONE", /* CAIRO_EXTEND_NONE */ + "EXTEND_REPEAT", /* CAIRO_EXTEND_REPEAT */ + "EXTEND_REFLECT", /* CAIRO_EXTEND_REFLECT */ + "EXTEND_PAD" /* CAIRO_EXTEND_PAD */ + }; + assert (extend < ARRAY_LENGTH (names)); + return names[extend]; +} + +static const char * +_filter_to_string (cairo_filter_t filter) +{ + static const char *names[] = { + "FILTER_FAST", /* CAIRO_FILTER_FAST */ + "FILTER_GOOD", /* CAIRO_FILTER_GOOD */ + "FILTER_BEST", /* CAIRO_FILTER_BEST */ + "FILTER_NEAREST", /* CAIRO_FILTER_NEAREST */ + "FILTER_BILINEAR", /* CAIRO_FILTER_BILINEAR */ + "FILTER_GAUSSIAN", /* CAIRO_FILTER_GAUSSIAN */ + }; + assert (filter < ARRAY_LENGTH (names)); + return names[filter]; +} + +static const char * +_fill_rule_to_string (cairo_fill_rule_t rule) +{ + static const char *names[] = { + "WINDING", /* CAIRO_FILL_RULE_WINDING */ + "EVEN_ODD" /* CAIRO_FILL_RILE_EVEN_ODD */ + }; + assert (rule < ARRAY_LENGTH (names)); + return names[rule]; +} + +static const char * +_antialias_to_string (cairo_antialias_t antialias) +{ + static const char *names[] = { + "ANTIALIAS_DEFAULT", /* CAIRO_ANTIALIAS_DEFAULT */ + "ANTIALIAS_NONE", /* CAIRO_ANTIALIAS_NONE */ + "ANTIALIAS_GRAY", /* CAIRO_ANTIALIAS_GRAY */ + "ANTIALIAS_SUBPIXEL", /* CAIRO_ANTIALIAS_SUBPIXEL */ + "ANTIALIAS_FAST", /* CAIRO_ANTIALIAS_FAST */ + "ANTIALIAS_GOOD", /* CAIRO_ANTIALIAS_GOOD */ + "ANTIALIAS_BEST" /* CAIRO_ANTIALIAS_BEST */ + }; + assert (antialias < ARRAY_LENGTH (names)); + return names[antialias]; +} + +static const char * +_line_cap_to_string (cairo_line_cap_t line_cap) +{ + static const char *names[] = { + "LINE_CAP_BUTT", /* CAIRO_LINE_CAP_BUTT */ + "LINE_CAP_ROUND", /* CAIRO_LINE_CAP_ROUND */ + "LINE_CAP_SQUARE" /* CAIRO_LINE_CAP_SQUARE */ + }; + assert (line_cap < ARRAY_LENGTH (names)); + return names[line_cap]; +} + +static const char * +_line_join_to_string (cairo_line_join_t line_join) +{ + static const char *names[] = { + "LINE_JOIN_MITER", /* CAIRO_LINE_JOIN_MITER */ + "LINE_JOIN_ROUND", /* CAIRO_LINE_JOIN_ROUND */ + "LINE_JOIN_BEVEL", /* CAIRO_LINE_JOIN_BEVEL */ + }; + assert (line_join < ARRAY_LENGTH (names)); + return names[line_join]; +} + +static inline cairo_script_context_t * +to_context (cairo_script_surface_t *surface) +{ + return (cairo_script_context_t *) surface->base.device; +} + +static cairo_bool_t +target_is_active (cairo_script_surface_t *surface) +{ + return cairo_list_is_first (&surface->operand.link, + &to_context (surface)->operands); +} + +static void +target_push (cairo_script_surface_t *surface) +{ + cairo_list_move (&surface->operand.link, &to_context (surface)->operands); +} + +static int +target_depth (cairo_script_surface_t *surface) +{ + cairo_list_t *link; + int depth = 0; + + cairo_list_foreach (link, &to_context (surface)->operands) { + if (link == &surface->operand.link) + break; + depth++; + } + + return depth; +} + +static void +_get_target (cairo_script_surface_t *surface) +{ + cairo_script_context_t *ctx = to_context (surface); + + if (target_is_active (surface)) { + _cairo_output_stream_puts (ctx->stream, "dup "); + return; + } + + if (surface->defined) { + _cairo_output_stream_printf (ctx->stream, "s%u ", + surface->base.unique_id); + } else { + int depth = target_depth (surface); + + assert (! cairo_list_is_empty (&surface->operand.link)); + assert (! target_is_active (surface)); + + if (ctx->active) { + _cairo_output_stream_printf (ctx->stream, "%d index ", depth); + _cairo_output_stream_puts (ctx->stream, "/target get exch pop "); + } else { + if (depth == 1) { + _cairo_output_stream_puts (ctx->stream, "exch "); + } else { + _cairo_output_stream_printf (ctx->stream, + "%d -1 roll ", depth); + } + target_push (surface); + _cairo_output_stream_puts (ctx->stream, "dup "); + } + } +} + +static const char * +_content_to_string (cairo_content_t content) +{ + switch (content) { + case CAIRO_CONTENT_ALPHA: return "ALPHA"; + case CAIRO_CONTENT_COLOR: return "COLOR"; + default: + case CAIRO_CONTENT_COLOR_ALPHA: return "COLOR_ALPHA"; + } +} + +static cairo_status_t +_emit_surface (cairo_script_surface_t *surface) +{ + cairo_script_context_t *ctx = to_context (surface); + + _cairo_output_stream_printf (ctx->stream, + "<< /content //%s", + _content_to_string (surface->base.content)); + if (surface->width != -1 && surface->height != -1) { + _cairo_output_stream_printf (ctx->stream, + " /width %f /height %f", + surface->width, + surface->height); + } + + if (surface->base.x_fallback_resolution != + CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT || + surface->base.y_fallback_resolution != + CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT) + { + _cairo_output_stream_printf (ctx->stream, + " /fallback-resolution [%f %f]", + surface->base.x_fallback_resolution, + surface->base.y_fallback_resolution); + } + + if (surface->base.device_transform.x0 != 0. || + surface->base.device_transform.y0 != 0.) + { + /* XXX device offset is encoded into the pattern matrices etc. */ + if (0) { + _cairo_output_stream_printf (ctx->stream, + " /device-offset [%f %f]", + surface->base.device_transform.x0, + surface->base.device_transform.y0); + } + } + + _cairo_output_stream_puts (ctx->stream, " >> surface context\n"); + surface->emitted = TRUE; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_context (cairo_script_surface_t *surface) +{ + cairo_script_context_t *ctx = to_context (surface); + + if (target_is_active (surface)) + return CAIRO_STATUS_SUCCESS; + + while (! cairo_list_is_empty (&ctx->operands)) { + operand_t *op; + cairo_script_surface_t *old; + + op = cairo_list_first_entry (&ctx->operands, + operand_t, + link); + if (op->type == DEFERRED) + break; + + old = cairo_container_of (op, cairo_script_surface_t, operand); + if (old == surface) + break; + if (old->active) + break; + + if (! old->defined) { + assert (old->emitted); + _cairo_output_stream_printf (ctx->stream, + "/target get /s%u exch def pop\n", + old->base.unique_id); + old->defined = TRUE; + } else { + _cairo_output_stream_puts (ctx->stream, "pop\n"); + } + + cairo_list_del (&old->operand.link); + } + + if (target_is_active (surface)) + return CAIRO_STATUS_SUCCESS; + + if (! surface->emitted) { + cairo_status_t status; + + status = _emit_surface (surface); + if (unlikely (status)) + return status; + } else if (cairo_list_is_empty (&surface->operand.link)) { + assert (surface->defined); + _cairo_output_stream_printf (ctx->stream, + "s%u context\n", + surface->base.unique_id); + _cairo_script_implicit_context_reset (&surface->cr); + _cairo_surface_clipper_reset (&surface->clipper); + } else { + int depth = target_depth (surface); + if (depth == 1) { + _cairo_output_stream_puts (ctx->stream, "exch\n"); + } else { + _cairo_output_stream_printf (ctx->stream, + "%d -1 roll\n", + depth); + } + } + target_push (surface); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_operator (cairo_script_surface_t *surface, + cairo_operator_t op) +{ + assert (target_is_active (surface)); + + if (surface->cr.current_operator == op) + return CAIRO_STATUS_SUCCESS; + + surface->cr.current_operator = op; + + _cairo_output_stream_printf (to_context (surface)->stream, + "//%s set-operator\n", + _operator_to_string (op)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_fill_rule (cairo_script_surface_t *surface, + cairo_fill_rule_t fill_rule) +{ + assert (target_is_active (surface)); + + if (surface->cr.current_fill_rule == fill_rule) + return CAIRO_STATUS_SUCCESS; + + surface->cr.current_fill_rule = fill_rule; + + _cairo_output_stream_printf (to_context (surface)->stream, + "//%s set-fill-rule\n", + _fill_rule_to_string (fill_rule)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_tolerance (cairo_script_surface_t *surface, + double tolerance, + cairo_bool_t force) +{ + assert (target_is_active (surface)); + + if ((! force || + fabs (tolerance - CAIRO_GSTATE_TOLERANCE_DEFAULT) < 1e-5) && + surface->cr.current_tolerance == tolerance) + { + return CAIRO_STATUS_SUCCESS; + } + + surface->cr.current_tolerance = tolerance; + + _cairo_output_stream_printf (to_context (surface)->stream, + "%f set-tolerance\n", + tolerance); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_antialias (cairo_script_surface_t *surface, + cairo_antialias_t antialias) +{ + assert (target_is_active (surface)); + + if (surface->cr.current_antialias == antialias) + return CAIRO_STATUS_SUCCESS; + + surface->cr.current_antialias = antialias; + + _cairo_output_stream_printf (to_context (surface)->stream, + "//%s set-antialias\n", + _antialias_to_string (antialias)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_line_width (cairo_script_surface_t *surface, + double line_width, + cairo_bool_t force) +{ + assert (target_is_active (surface)); + + if ((! force || + fabs (line_width - CAIRO_GSTATE_LINE_WIDTH_DEFAULT) < 1e-5) && + surface->cr.current_style.line_width == line_width) + { + return CAIRO_STATUS_SUCCESS; + } + + surface->cr.current_style.line_width = line_width; + + _cairo_output_stream_printf (to_context (surface)->stream, + "%f set-line-width\n", + line_width); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_line_cap (cairo_script_surface_t *surface, + cairo_line_cap_t line_cap) +{ + assert (target_is_active (surface)); + + if (surface->cr.current_style.line_cap == line_cap) + return CAIRO_STATUS_SUCCESS; + + surface->cr.current_style.line_cap = line_cap; + + _cairo_output_stream_printf (to_context (surface)->stream, + "//%s set-line-cap\n", + _line_cap_to_string (line_cap)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_line_join (cairo_script_surface_t *surface, + cairo_line_join_t line_join) +{ + assert (target_is_active (surface)); + + if (surface->cr.current_style.line_join == line_join) + return CAIRO_STATUS_SUCCESS; + + surface->cr.current_style.line_join = line_join; + + _cairo_output_stream_printf (to_context (surface)->stream, + "//%s set-line-join\n", + _line_join_to_string (line_join)); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_miter_limit (cairo_script_surface_t *surface, + double miter_limit, + cairo_bool_t force) +{ + assert (target_is_active (surface)); + + if ((! force || + fabs (miter_limit - CAIRO_GSTATE_MITER_LIMIT_DEFAULT) < 1e-5) && + surface->cr.current_style.miter_limit == miter_limit) + { + return CAIRO_STATUS_SUCCESS; + } + + surface->cr.current_style.miter_limit = miter_limit; + + _cairo_output_stream_printf (to_context (surface)->stream, + "%f set-miter-limit\n", + miter_limit); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_dashes_equal (const double *a, const double *b, int num_dashes) +{ + while (num_dashes--) { + if (fabs (*a - *b) > 1e-5) + return FALSE; + a++, b++; + } + + return TRUE; +} + +static cairo_status_t +_emit_dash (cairo_script_surface_t *surface, + const double *dash, + unsigned int num_dashes, + double offset, + cairo_bool_t force) +{ + unsigned int n; + + assert (target_is_active (surface)); + + if (force && + num_dashes == 0 && + surface->cr.current_style.num_dashes == 0) + { + return CAIRO_STATUS_SUCCESS; + } + + if (! force && + (surface->cr.current_style.num_dashes == num_dashes && + (num_dashes == 0 || + (fabs (surface->cr.current_style.dash_offset - offset) < 1e-5 && + _dashes_equal (surface->cr.current_style.dash, dash, num_dashes))))) + { + return CAIRO_STATUS_SUCCESS; + } + + + if (num_dashes) { + surface->cr.current_style.dash = _cairo_realloc_ab + (surface->cr.current_style.dash, num_dashes, sizeof (double)); + if (unlikely (surface->cr.current_style.dash == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (surface->cr.current_style.dash, dash, + sizeof (double) * num_dashes); + } else { + free (surface->cr.current_style.dash); + surface->cr.current_style.dash = NULL; + } + + surface->cr.current_style.num_dashes = num_dashes; + surface->cr.current_style.dash_offset = offset; + + _cairo_output_stream_puts (to_context (surface)->stream, "["); + for (n = 0; n < num_dashes; n++) { + _cairo_output_stream_printf (to_context (surface)->stream, "%f", dash[n]); + if (n < num_dashes-1) + _cairo_output_stream_puts (to_context (surface)->stream, " "); + } + _cairo_output_stream_printf (to_context (surface)->stream, + "] %f set-dash\n", + offset); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_stroke_style (cairo_script_surface_t *surface, + const cairo_stroke_style_t *style, + cairo_bool_t force) +{ + cairo_status_t status; + + assert (target_is_active (surface)); + + status = _emit_line_width (surface, style->line_width, force); + if (unlikely (status)) + return status; + + status = _emit_line_cap (surface, style->line_cap); + if (unlikely (status)) + return status; + + status = _emit_line_join (surface, style->line_join); + if (unlikely (status)) + return status; + + status = _emit_miter_limit (surface, style->miter_limit, force); + if (unlikely (status)) + return status; + + status = _emit_dash (surface, + style->dash, style->num_dashes, style->dash_offset, + force); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static const char * +_format_to_string (cairo_format_t format) +{ + switch (format) { + case CAIRO_FORMAT_ARGB32: return "ARGB32"; + case CAIRO_FORMAT_RGB30: return "RGB30"; + case CAIRO_FORMAT_RGB24: return "RGB24"; + case CAIRO_FORMAT_RGB16_565: return "RGB16_565"; + case CAIRO_FORMAT_A8: return "A8"; + case CAIRO_FORMAT_A1: return "A1"; + case CAIRO_FORMAT_INVALID: return "INVALID"; + } + ASSERT_NOT_REACHED; + return "INVALID"; +} + +static cairo_status_t +_emit_solid_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; + cairo_script_context_t *ctx = to_context (surface); + + if (! CAIRO_COLOR_IS_OPAQUE (&solid->color)) + { + if (! (surface->base.content & CAIRO_CONTENT_COLOR) || + ((solid->color.red_short == 0 || solid->color.red_short == 0xffff) && + (solid->color.green_short == 0 || solid->color.green_short == 0xffff) && + (solid->color.blue_short == 0 || solid->color.blue_short == 0xffff) )) + { + _cairo_output_stream_printf (ctx->stream, + "%f a", + solid->color.alpha); + } + else + { + _cairo_output_stream_printf (ctx->stream, + "%f %f %f %f rgba", + solid->color.red, + solid->color.green, + solid->color.blue, + solid->color.alpha); + } + } + else + { + if (solid->color.red_short == solid->color.green_short && + solid->color.red_short == solid->color.blue_short) + { + _cairo_output_stream_printf (ctx->stream, + "%f g", + solid->color.red); + } + else + { + _cairo_output_stream_printf (ctx->stream, + "%f %f %f rgb", + solid->color.red, + solid->color.green, + solid->color.blue); + } + } + + return CAIRO_STATUS_SUCCESS; +} + + +static cairo_status_t +_emit_gradient_color_stops (cairo_gradient_pattern_t *gradient, + cairo_output_stream_t *output) +{ + unsigned int n; + + for (n = 0; n < gradient->n_stops; n++) { + _cairo_output_stream_printf (output, + "\n %f %f %f %f %f add-color-stop", + gradient->stops[n].offset, + gradient->stops[n].color.red, + gradient->stops[n].color.green, + gradient->stops[n].color.blue, + gradient->stops[n].color.alpha); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_linear_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_linear_pattern_t *linear; + + linear = (cairo_linear_pattern_t *) pattern; + + _cairo_output_stream_printf (ctx->stream, + "%f %f %f %f linear", + linear->pd1.x, linear->pd1.y, + linear->pd2.x, linear->pd2.y); + return _emit_gradient_color_stops (&linear->base, ctx->stream); +} + +static cairo_status_t +_emit_radial_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_radial_pattern_t *radial; + + radial = (cairo_radial_pattern_t *) pattern; + + _cairo_output_stream_printf (ctx->stream, + "%f %f %f %f %f %f radial", + radial->cd1.center.x, + radial->cd1.center.y, + radial->cd1.radius, + radial->cd2.center.x, + radial->cd2.center.y, + radial->cd2.radius); + return _emit_gradient_color_stops (&radial->base, ctx->stream); +} + +static cairo_status_t +_emit_mesh_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_pattern_t *mesh; + cairo_status_t status; + unsigned int i, n; + + mesh = (cairo_pattern_t *) pattern; + status = cairo_mesh_pattern_get_patch_count (mesh, &n); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (ctx->stream, "mesh"); + for (i = 0; i < n; i++) { + cairo_path_t *path; + cairo_path_data_t *data; + int j; + + _cairo_output_stream_printf (ctx->stream, "\n begin-patch"); + + path = cairo_mesh_pattern_get_path (mesh, i); + if (unlikely (path->status)) + return path->status; + + for (j = 0; j < path->num_data; j+=data[0].header.length) { + data = &path->data[j]; + switch (data->header.type) { + case CAIRO_PATH_MOVE_TO: + _cairo_output_stream_printf (ctx->stream, + "\n %f %f m", + data[1].point.x, data[1].point.y); + break; + case CAIRO_PATH_LINE_TO: + _cairo_output_stream_printf (ctx->stream, + "\n %f %f l", + data[1].point.x, data[1].point.y); + break; + case CAIRO_PATH_CURVE_TO: + _cairo_output_stream_printf (ctx->stream, + "\n %f %f %f %f %f %f c", + data[1].point.x, data[1].point.y, + data[2].point.x, data[2].point.y, + data[3].point.x, data[3].point.y); + break; + case CAIRO_PATH_CLOSE_PATH: + break; + } + } + cairo_path_destroy (path); + + for (j = 0; j < 4; j++) { + double x, y; + + status = cairo_mesh_pattern_get_control_point (mesh, i, j, &x, &y); + if (unlikely (status)) + return status; + _cairo_output_stream_printf (ctx->stream, + "\n %d %f %f set-control-point", + j, x, y); + } + + for (j = 0; j < 4; j++) { + double r, g, b, a; + + status = cairo_mesh_pattern_get_corner_color_rgba (mesh, i, j, &r, &g, &b, &a); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (ctx->stream, + "\n %d %f %f %f %f set-corner-color", + j, r, g, b, a); + } + + _cairo_output_stream_printf (ctx->stream, "\n end-patch"); + } + + return CAIRO_STATUS_SUCCESS; +} + +struct script_snapshot { + cairo_surface_t base; +}; + +static cairo_status_t +script_snapshot_finish (void *abstract_surface) +{ + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t script_snapshot_backend = { + CAIRO_SURFACE_TYPE_SCRIPT, + script_snapshot_finish, +}; + +static void +detach_snapshot (cairo_surface_t *abstract_surface) +{ + cairo_script_surface_t *surface = (cairo_script_surface_t *)abstract_surface; + cairo_script_context_t *ctx = to_context (surface); + + _cairo_output_stream_printf (ctx->stream, + "/s%d undef\n", + surface->base.unique_id); +} + +static void +attach_snapshot (cairo_script_context_t *ctx, + cairo_surface_t *source) +{ + struct script_snapshot *surface; + + if (! ctx->attach_snapshots) + return; + + surface = malloc (sizeof (*surface)); + if (unlikely (surface == NULL)) + return; + + _cairo_surface_init (&surface->base, + &script_snapshot_backend, + &ctx->base, + source->content); + + _cairo_output_stream_printf (ctx->stream, + "dup /s%d exch def ", + surface->base.unique_id); + + _cairo_surface_attach_snapshot (source, &surface->base, detach_snapshot); + cairo_surface_destroy (&surface->base); +} + +static cairo_status_t +_emit_recording_surface_pattern (cairo_script_surface_t *surface, + cairo_recording_surface_t *source) +{ + cairo_script_implicit_context_t old_cr; + cairo_script_context_t *ctx = to_context (surface); + cairo_script_surface_t *similar; + cairo_surface_t *snapshot; + cairo_rectangle_t r, *extents; + cairo_status_t status; + + snapshot = _cairo_surface_has_snapshot (&source->base, &script_snapshot_backend); + if (snapshot) { + _cairo_output_stream_printf (ctx->stream, "s%d", snapshot->unique_id); + return CAIRO_INT_STATUS_SUCCESS; + } + + extents = NULL; + if (_cairo_recording_surface_get_bounds (&source->base, &r)) + extents = &r; + + similar = _cairo_script_surface_create_internal (ctx, + source->base.content, + extents, + NULL); + if (unlikely (similar->base.status)) + return similar->base.status; + + similar->base.is_clear = TRUE; + + _cairo_output_stream_printf (ctx->stream, "//%s ", + _content_to_string (source->base.content)); + if (extents) { + _cairo_output_stream_printf (ctx->stream, "[%f %f %f %f]", + extents->x, extents->y, + extents->width, extents->height); + } else + _cairo_output_stream_puts (ctx->stream, "[]"); + _cairo_output_stream_puts (ctx->stream, " record\n"); + + attach_snapshot (ctx, &source->base); + + _cairo_output_stream_puts (ctx->stream, "dup context\n"); + + target_push (similar); + similar->emitted = TRUE; + + + old_cr = surface->cr; + _cairo_script_implicit_context_init (&surface->cr); + status = _cairo_recording_surface_replay (&source->base, &similar->base); + surface->cr = old_cr; + + if (unlikely (status)) { + cairo_surface_destroy (&similar->base); + return status; + } + + cairo_list_del (&similar->operand.link); + assert (target_is_active (surface)); + + _cairo_output_stream_puts (ctx->stream, "pop "); + cairo_surface_destroy (&similar->base); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_script_surface_pattern (cairo_script_surface_t *surface, + cairo_script_surface_t *source) +{ + _get_target (source); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_write_image_surface (cairo_output_stream_t *output, + const cairo_image_surface_t *image) +{ + int stride, row, width; + uint8_t row_stack[CAIRO_STACK_BUFFER_SIZE]; + uint8_t *rowdata; + uint8_t *data; + + stride = image->stride; + width = image->width; + data = image->data; +#if WORDS_BIGENDIAN + switch (image->format) { + case CAIRO_FORMAT_A1: + for (row = image->height; row--; ) { + _cairo_output_stream_write (output, data, (width+7)/8); + data += stride; + } + break; + case CAIRO_FORMAT_A8: + for (row = image->height; row--; ) { + _cairo_output_stream_write (output, data, width); + data += stride; + } + break; + case CAIRO_FORMAT_RGB16_565: + for (row = image->height; row--; ) { + _cairo_output_stream_write (output, data, 2*width); + data += stride; + } + break; + case CAIRO_FORMAT_RGB24: + for (row = image->height; row--; ) { + int col; + rowdata = data; + for (col = width; col--; ) { + _cairo_output_stream_write (output, rowdata, 3); + rowdata+=4; + } + data += stride; + } + break; + case CAIRO_FORMAT_ARGB32: + for (row = image->height; row--; ) { + _cairo_output_stream_write (output, data, 4*width); + data += stride; + } + break; + case CAIRO_FORMAT_INVALID: + default: + ASSERT_NOT_REACHED; + break; + } +#else + if (stride > ARRAY_LENGTH (row_stack)) { + rowdata = malloc (stride); + if (unlikely (rowdata == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + rowdata = row_stack; + + switch (image->format) { + case CAIRO_FORMAT_A1: + for (row = image->height; row--; ) { + int col; + for (col = 0; col < (width + 7)/8; col++) + rowdata[col] = CAIRO_BITSWAP8 (data[col]); + _cairo_output_stream_write (output, rowdata, (width+7)/8); + data += stride; + } + break; + case CAIRO_FORMAT_A8: + for (row = image->height; row--; ) { + _cairo_output_stream_write (output, data, width); + data += stride; + } + break; + case CAIRO_FORMAT_RGB16_565: + for (row = image->height; row--; ) { + uint16_t *src = (uint16_t *) data; + uint16_t *dst = (uint16_t *) rowdata; + int col; + for (col = 0; col < width; col++) + dst[col] = bswap_16 (src[col]); + _cairo_output_stream_write (output, rowdata, 2*width); + data += stride; + } + break; + case CAIRO_FORMAT_RGB24: + for (row = image->height; row--; ) { + uint8_t *src = data; + int col; + for (col = 0; col < width; col++) { + rowdata[3*col+2] = *src++; + rowdata[3*col+1] = *src++; + rowdata[3*col+0] = *src++; + src++; + } + _cairo_output_stream_write (output, rowdata, 3*width); + data += stride; + } + break; + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_ARGB32: + for (row = image->height; row--; ) { + uint32_t *src = (uint32_t *) data; + uint32_t *dst = (uint32_t *) rowdata; + int col; + for (col = 0; col < width; col++) + dst[col] = bswap_32 (src[col]); + _cairo_output_stream_write (output, rowdata, 4*width); + data += stride; + } + break; + case CAIRO_FORMAT_INVALID: + default: + ASSERT_NOT_REACHED; + break; + } + if (rowdata != row_stack) + free (rowdata); +#endif + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_png_surface (cairo_script_surface_t *surface, + cairo_image_surface_t *image) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_output_stream_t *base85_stream; + cairo_status_t status; + const uint8_t *mime_data; + unsigned long mime_data_length; + + cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_PNG, + &mime_data, &mime_data_length); + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_output_stream_printf (ctx->stream, + "<< " + "/width %d " + "/height %d " + "/format //%s " + "/mime-type (image/png) " + "/source <~", + image->width, image->height, + _format_to_string (image->format)); + + base85_stream = _cairo_base85_stream_create (ctx->stream); + _cairo_output_stream_write (base85_stream, mime_data, mime_data_length); + status = _cairo_output_stream_destroy (base85_stream); + if (unlikely (status)) + return status; + + _cairo_output_stream_puts (ctx->stream, "~> >> image "); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_image_surface (cairo_script_surface_t *surface, + cairo_image_surface_t *image) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_output_stream_t *base85_stream; + cairo_output_stream_t *zlib_stream; + cairo_int_status_t status, status2; + cairo_surface_t *snapshot; + const uint8_t *mime_data; + unsigned long mime_data_length; + + snapshot = _cairo_surface_has_snapshot (&image->base, + &script_snapshot_backend); + if (snapshot) { + _cairo_output_stream_printf (ctx->stream, "s%u ", snapshot->unique_id); + return CAIRO_INT_STATUS_SUCCESS; + } + + status = _emit_png_surface (surface, image); + if (_cairo_int_status_is_error (status)) { + return status; + } else if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_image_surface_t *clone; + uint32_t len; + + if (image->format == CAIRO_FORMAT_INVALID) { + clone = _cairo_image_surface_coerce (image); + } else { + clone = (cairo_image_surface_t *) + cairo_surface_reference (&image->base); + } + + _cairo_output_stream_printf (ctx->stream, + "<< " + "/width %d " + "/height %d " + "/format //%s " + "/source ", + clone->width, clone->height, + _format_to_string (clone->format)); + + switch (clone->format) { + case CAIRO_FORMAT_A1: + len = (clone->width + 7)/8; + break; + case CAIRO_FORMAT_A8: + len = clone->width; + break; + case CAIRO_FORMAT_RGB16_565: + len = clone->width * 2; + break; + case CAIRO_FORMAT_RGB24: + len = clone->width * 3; + break; + case CAIRO_FORMAT_RGB30: + case CAIRO_FORMAT_ARGB32: + len = clone->width * 4; + break; + case CAIRO_FORMAT_INVALID: + default: + ASSERT_NOT_REACHED; + len = 0; + break; + } + len *= clone->height; + + if (len > 24) { + _cairo_output_stream_puts (ctx->stream, "<|"); + + base85_stream = _cairo_base85_stream_create (ctx->stream); + + len = to_be32 (len); + _cairo_output_stream_write (base85_stream, &len, sizeof (len)); + + zlib_stream = _cairo_deflate_stream_create (base85_stream); + status = _write_image_surface (zlib_stream, clone); + + status2 = _cairo_output_stream_destroy (zlib_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + status2 = _cairo_output_stream_destroy (base85_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + if (unlikely (status)) + return status; + } else { + _cairo_output_stream_puts (ctx->stream, "<~"); + + base85_stream = _cairo_base85_stream_create (ctx->stream); + status = _write_image_surface (base85_stream, clone); + status2 = _cairo_output_stream_destroy (base85_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + if (unlikely (status)) + return status; + } + _cairo_output_stream_puts (ctx->stream, "~> >> image "); + + cairo_surface_destroy (&clone->base); + } + + cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_JPEG, + &mime_data, &mime_data_length); + if (mime_data != NULL) { + _cairo_output_stream_printf (ctx->stream, + "\n (%s) <~", + CAIRO_MIME_TYPE_JPEG); + + base85_stream = _cairo_base85_stream_create (ctx->stream); + _cairo_output_stream_write (base85_stream, mime_data, mime_data_length); + status = _cairo_output_stream_destroy (base85_stream); + if (unlikely (status)) + return status; + + _cairo_output_stream_puts (ctx->stream, "~> set-mime-data\n"); + } + + cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_JP2, + &mime_data, &mime_data_length); + if (mime_data != NULL) { + _cairo_output_stream_printf (ctx->stream, + "\n (%s) <~", + CAIRO_MIME_TYPE_JP2); + + base85_stream = _cairo_base85_stream_create (ctx->stream); + _cairo_output_stream_write (base85_stream, mime_data, mime_data_length); + status = _cairo_output_stream_destroy (base85_stream); + if (unlikely (status)) + return status; + + _cairo_output_stream_puts (ctx->stream, "~> set-mime-data\n"); + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_image_surface_pattern (cairo_script_surface_t *surface, + cairo_surface_t *source) +{ + cairo_image_surface_t *image; + cairo_status_t status; + void *extra; + + status = _cairo_surface_acquire_source_image (source, &image, &extra); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + status = _emit_image_surface (surface, image); + _cairo_surface_release_source_image (source, image, extra); + } + + return status; +} + +static cairo_int_status_t +_emit_subsurface_pattern (cairo_script_surface_t *surface, + cairo_surface_subsurface_t *sub) +{ + cairo_surface_t *source = sub->target; + cairo_int_status_t status; + + switch ((int) source->backend->type) { + case CAIRO_SURFACE_TYPE_RECORDING: + status = _emit_recording_surface_pattern (surface, (cairo_recording_surface_t *) source); + break; + case CAIRO_SURFACE_TYPE_SCRIPT: + status = _emit_script_surface_pattern (surface, (cairo_script_surface_t *) source); + break; + default: + status = _emit_image_surface_pattern (surface, source); + break; + } + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (to_context (surface)->stream, + "%d %d %d %d subsurface ", + sub->extents.x, + sub->extents.y, + sub->extents.width, + sub->extents.height); + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_surface_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_surface_pattern_t *surface_pattern; + cairo_surface_t *source, *snapshot, *free_me = NULL; + cairo_surface_t *take_snapshot = NULL; + cairo_int_status_t status; + + surface_pattern = (cairo_surface_pattern_t *) pattern; + source = surface_pattern->surface; + + if (_cairo_surface_is_snapshot (source)) { + snapshot = _cairo_surface_has_snapshot (source, &script_snapshot_backend); + if (snapshot) { + _cairo_output_stream_printf (ctx->stream, + "s%d pattern ", + snapshot->unique_id); + return CAIRO_INT_STATUS_SUCCESS; + } + + if (_cairo_surface_snapshot_is_reused (source)) + take_snapshot = source; + + free_me = source = _cairo_surface_snapshot_get_target (source); + } + + switch ((int) source->backend->type) { + case CAIRO_SURFACE_TYPE_RECORDING: + status = _emit_recording_surface_pattern (surface, (cairo_recording_surface_t *) source); + break; + case CAIRO_SURFACE_TYPE_SCRIPT: + status = _emit_script_surface_pattern (surface, (cairo_script_surface_t *) source); + break; + case CAIRO_SURFACE_TYPE_SUBSURFACE: + status = _emit_subsurface_pattern (surface, (cairo_surface_subsurface_t *) source); + break; + default: + status = _emit_image_surface_pattern (surface, source); + break; + } + cairo_surface_destroy (free_me); + if (unlikely (status)) + return status; + + if (take_snapshot) + attach_snapshot (ctx, take_snapshot); + + _cairo_output_stream_puts (ctx->stream, "pattern"); + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_raster_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_surface_t *source; + cairo_int_status_t status; + + source = _cairo_raster_source_pattern_acquire (pattern, &surface->base, NULL); + if (unlikely (source == NULL)) { + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_UNSUPPORTED; + } + if (unlikely (source->status)) + return source->status; + + status = _emit_image_surface_pattern (surface, source); + _cairo_raster_source_pattern_release (pattern, source); + if (unlikely (status)) + return status; + + _cairo_output_stream_puts (to_context(surface)->stream, "pattern"); + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_pattern (cairo_script_surface_t *surface, + const cairo_pattern_t *pattern) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_int_status_t status; + cairo_bool_t is_default_extend; + cairo_bool_t need_newline = TRUE; + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + /* solid colors do not need filter/extend/matrix */ + return _emit_solid_pattern (surface, pattern); + + case CAIRO_PATTERN_TYPE_LINEAR: + status = _emit_linear_pattern (surface, pattern); + is_default_extend = pattern->extend == CAIRO_EXTEND_GRADIENT_DEFAULT; + break; + case CAIRO_PATTERN_TYPE_RADIAL: + status = _emit_radial_pattern (surface, pattern); + is_default_extend = pattern->extend == CAIRO_EXTEND_GRADIENT_DEFAULT; + break; + case CAIRO_PATTERN_TYPE_MESH: + status = _emit_mesh_pattern (surface, pattern); + is_default_extend = TRUE; + break; + case CAIRO_PATTERN_TYPE_SURFACE: + status = _emit_surface_pattern (surface, pattern); + is_default_extend = pattern->extend == CAIRO_EXTEND_SURFACE_DEFAULT; + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + status = _emit_raster_pattern (surface, pattern); + is_default_extend = pattern->extend == CAIRO_EXTEND_SURFACE_DEFAULT; + break; + + default: + ASSERT_NOT_REACHED; + status = CAIRO_INT_STATUS_UNSUPPORTED; + } + if (unlikely (status)) + return status; + + if (! _cairo_matrix_is_identity (&pattern->matrix)) { + if (need_newline) { + _cairo_output_stream_puts (ctx->stream, "\n "); + need_newline = FALSE; + } + + _cairo_output_stream_printf (ctx->stream, + " [%f %f %f %f %f %f] set-matrix\n ", + pattern->matrix.xx, pattern->matrix.yx, + pattern->matrix.xy, pattern->matrix.yy, + pattern->matrix.x0, pattern->matrix.y0); + } + + /* XXX need to discriminate the user explicitly setting the default */ + if (pattern->filter != CAIRO_FILTER_DEFAULT) { + if (need_newline) { + _cairo_output_stream_puts (ctx->stream, "\n "); + need_newline = FALSE; + } + + _cairo_output_stream_printf (ctx->stream, + " //%s set-filter\n ", + _filter_to_string (pattern->filter)); + } + if (! is_default_extend ){ + if (need_newline) { + _cairo_output_stream_puts (ctx->stream, "\n "); + need_newline = FALSE; + } + + _cairo_output_stream_printf (ctx->stream, + " //%s set-extend\n ", + _extend_to_string (pattern->extend)); + } + + if (need_newline) + _cairo_output_stream_puts (ctx->stream, "\n "); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_identity (cairo_script_surface_t *surface, + cairo_bool_t *matrix_updated) +{ + assert (target_is_active (surface)); + + if (_cairo_matrix_is_identity (&surface->cr.current_ctm)) + return CAIRO_INT_STATUS_SUCCESS; + + _cairo_output_stream_puts (to_context (surface)->stream, + "identity set-matrix\n"); + + *matrix_updated = TRUE; + cairo_matrix_init_identity (&surface->cr.current_ctm); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_emit_source (cairo_script_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source) +{ + cairo_bool_t matrix_updated = FALSE; + cairo_int_status_t status; + + assert (target_is_active (surface)); + + if (op == CAIRO_OPERATOR_CLEAR) { + /* the source is ignored, so don't change it */ + return CAIRO_INT_STATUS_SUCCESS; + } + + if (_cairo_pattern_equal (&surface->cr.current_source.base, source)) + return CAIRO_INT_STATUS_SUCCESS; + + _cairo_pattern_fini (&surface->cr.current_source.base); + status = _cairo_pattern_init_copy (&surface->cr.current_source.base, + source); + if (unlikely (status)) + return status; + + status = _emit_identity (surface, &matrix_updated); + if (unlikely (status)) + return status; + + status = _emit_pattern (surface, source); + if (unlikely (status)) + return status; + + assert (target_is_active (surface)); + _cairo_output_stream_puts (to_context (surface)->stream, + " set-source\n"); + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_status_t +_path_move_to (void *closure, + const cairo_point_t *point) +{ + _cairo_output_stream_printf (closure, + " %f %f m", + _cairo_fixed_to_double (point->x), + _cairo_fixed_to_double (point->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_path_line_to (void *closure, + const cairo_point_t *point) +{ + _cairo_output_stream_printf (closure, + " %f %f l", + _cairo_fixed_to_double (point->x), + _cairo_fixed_to_double (point->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_path_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + _cairo_output_stream_printf (closure, + " %f %f %f %f %f %f c", + _cairo_fixed_to_double (p1->x), + _cairo_fixed_to_double (p1->y), + _cairo_fixed_to_double (p2->x), + _cairo_fixed_to_double (p2->y), + _cairo_fixed_to_double (p3->x), + _cairo_fixed_to_double (p3->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_path_close (void *closure) +{ + _cairo_output_stream_printf (closure, + " h"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_path_boxes (cairo_script_surface_t *surface, + const cairo_path_fixed_t *path) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_path_fixed_iter_t iter; + cairo_status_t status; + struct _cairo_boxes_chunk *chunk; + cairo_boxes_t boxes; + cairo_box_t box; + int i; + + _cairo_boxes_init (&boxes); + _cairo_path_fixed_iter_init (&iter, path); + while (_cairo_path_fixed_iter_is_fill_box (&iter, &box)) { + if (box.p1.y == box.p2.y || box.p1.x == box.p2.x) + continue; + + status = _cairo_boxes_add (&boxes, CAIRO_ANTIALIAS_DEFAULT, &box); + if (unlikely (status)) { + _cairo_boxes_fini (&boxes); + return status; + } + } + + if (! _cairo_path_fixed_iter_at_end (&iter)) { + _cairo_boxes_fini (&boxes); + return CAIRO_STATUS_INVALID_PATH_DATA; + } + + for (chunk = &boxes.chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + const cairo_box_t *b = &chunk->base[i]; + double x1 = _cairo_fixed_to_double (b->p1.x); + double y1 = _cairo_fixed_to_double (b->p1.y); + double x2 = _cairo_fixed_to_double (b->p2.x); + double y2 = _cairo_fixed_to_double (b->p2.y); + + _cairo_output_stream_printf (ctx->stream, + "\n %f %f %f %f rectangle", + x1, y1, x2 - x1, y2 - y1); + } + } + + _cairo_boxes_fini (&boxes); + return status; +} + +static cairo_status_t +_emit_path (cairo_script_surface_t *surface, + const cairo_path_fixed_t *path, + cairo_bool_t is_fill) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_box_t box; + cairo_int_status_t status; + + assert (target_is_active (surface)); + assert (_cairo_matrix_is_identity (&surface->cr.current_ctm)); + + if (_cairo_path_fixed_equal (&surface->cr.current_path, path)) + return CAIRO_STATUS_SUCCESS; + + _cairo_path_fixed_fini (&surface->cr.current_path); + + _cairo_output_stream_puts (ctx->stream, "n"); + + if (path == NULL) { + _cairo_path_fixed_init (&surface->cr.current_path); + _cairo_output_stream_puts (ctx->stream, "\n"); + return CAIRO_STATUS_SUCCESS; + } + + status = _cairo_path_fixed_init_copy (&surface->cr.current_path, path); + if (unlikely (status)) + return status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_is_rectangle (path, &box)) { + double x1 = _cairo_fixed_to_double (box.p1.x); + double y1 = _cairo_fixed_to_double (box.p1.y); + double x2 = _cairo_fixed_to_double (box.p2.x); + double y2 = _cairo_fixed_to_double (box.p2.y); + + assert (x1 > -9999); + + _cairo_output_stream_printf (ctx->stream, + " %f %f %f %f rectangle", + x1, y1, x2 - x1, y2 - y1); + status = CAIRO_INT_STATUS_SUCCESS; + } else if (is_fill && _cairo_path_fixed_fill_is_rectilinear (path)) { + status = _emit_path_boxes (surface, path); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = _cairo_path_fixed_interpret (path, + _path_move_to, + _path_line_to, + _path_curve_to, + _path_close, + ctx->stream); + } + + _cairo_output_stream_puts (ctx->stream, "\n"); + + return status; +} +static cairo_bool_t +_scaling_matrix_equal (const cairo_matrix_t *a, + const cairo_matrix_t *b) +{ + return fabs (a->xx - b->xx) < 1e-5 && + fabs (a->xy - b->xy) < 1e-5 && + fabs (a->yx - b->yx) < 1e-5 && + fabs (a->yy - b->yy) < 1e-5; +} + +static cairo_status_t +_emit_scaling_matrix (cairo_script_surface_t *surface, + const cairo_matrix_t *ctm, + cairo_bool_t *matrix_updated) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_bool_t was_identity; + assert (target_is_active (surface)); + + if (_scaling_matrix_equal (&surface->cr.current_ctm, ctm)) + return CAIRO_STATUS_SUCCESS; + + was_identity = _cairo_matrix_is_identity (&surface->cr.current_ctm); + + *matrix_updated = TRUE; + surface->cr.current_ctm = *ctm; + surface->cr.current_ctm.x0 = 0.; + surface->cr.current_ctm.y0 = 0.; + + if (_cairo_matrix_is_identity (&surface->cr.current_ctm)) { + _cairo_output_stream_puts (ctx->stream, + "identity set-matrix\n"); + } else if (was_identity && fabs (ctm->yx) < 1e-5 && fabs (ctm->xy) < 1e-5) { + _cairo_output_stream_printf (ctx->stream, + "%f %f scale\n", + ctm->xx, ctm->yy); + } else { + _cairo_output_stream_printf (ctx->stream, + "[%f %f %f %f 0 0] set-matrix\n", + ctm->xx, ctm->yx, + ctm->xy, ctm->yy); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_font_matrix (cairo_script_surface_t *surface, + const cairo_matrix_t *font_matrix) +{ + cairo_script_context_t *ctx = to_context (surface); + assert (target_is_active (surface)); + + if (memcmp (&surface->cr.current_font_matrix, + font_matrix, + sizeof (cairo_matrix_t)) == 0) + { + return CAIRO_STATUS_SUCCESS; + } + + surface->cr.current_font_matrix = *font_matrix; + + if (_cairo_matrix_is_identity (font_matrix)) { + _cairo_output_stream_puts (ctx->stream, + "identity set-font-matrix\n"); + } else { + _cairo_output_stream_printf (ctx->stream, + "[%f %f %f %f %f %f] set-font-matrix\n", + font_matrix->xx, font_matrix->yx, + font_matrix->xy, font_matrix->yy, + font_matrix->x0, font_matrix->y0); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_script_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_script_surface_t *surface, *other = abstract_surface; + cairo_surface_t *passthrough = NULL; + cairo_script_context_t *ctx; + cairo_rectangle_t extents; + cairo_status_t status; + + ctx = to_context (other); + + status = cairo_device_acquire (&ctx->base); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (! other->emitted) { + status = _emit_surface (other); + if (unlikely (status)) { + cairo_device_release (&ctx->base); + return _cairo_surface_create_in_error (status); + } + + target_push (other); + } + + if (_cairo_surface_wrapper_is_active (&other->wrapper)) { + passthrough = + _cairo_surface_wrapper_create_similar (&other->wrapper, + content, width, height); + if (unlikely (passthrough->status)) { + cairo_device_release (&ctx->base); + return passthrough; + } + } + + extents.x = extents.y = 0; + extents.width = width; + extents.height = height; + surface = _cairo_script_surface_create_internal (ctx, content, + &extents, passthrough); + cairo_surface_destroy (passthrough); + + if (unlikely (surface->base.status)) { + cairo_device_release (&ctx->base); + return &surface->base; + } + + _get_target (other); + _cairo_output_stream_printf (ctx->stream, + "%u %u //%s similar dup /s%u exch def context\n", + width, height, + _content_to_string (content), + surface->base.unique_id); + + surface->emitted = TRUE; + surface->defined = TRUE; + surface->base.is_clear = TRUE; + target_push (surface); + + cairo_device_release (&ctx->base); + return &surface->base; +} + +static cairo_status_t +_device_flush (void *abstract_device) +{ + cairo_script_context_t *ctx = abstract_device; + + return _cairo_output_stream_flush (ctx->stream); +} + +static void +_device_destroy (void *abstract_device) +{ + cairo_script_context_t *ctx = abstract_device; + cairo_status_t status; + + while (! cairo_list_is_empty (&ctx->fonts)) { + cairo_script_font_t *font; + + font = cairo_list_first_entry (&ctx->fonts, cairo_script_font_t, link); + cairo_list_del (&font->base.link); + cairo_list_del (&font->link); + free (font); + } + + _bitmap_fini (ctx->surface_id.next); + _bitmap_fini (ctx->font_id.next); + + if (ctx->owns_stream) + status = _cairo_output_stream_destroy (ctx->stream); + + free (ctx); +} + +static cairo_surface_t * +_cairo_script_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_script_surface_t *surface = abstract_surface; + + if (extents) { + extents->x = extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + } + + return &surface->base; +} + +static cairo_status_t +_cairo_script_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_script_surface_t *surface = abstract_surface; + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { + return _cairo_surface_wrapper_acquire_source_image (&surface->wrapper, + image_out, + image_extra); + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static void +_cairo_script_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_script_surface_t *surface = abstract_surface; + + assert (_cairo_surface_wrapper_is_active (&surface->wrapper)); + _cairo_surface_wrapper_release_source_image (&surface->wrapper, + image, + image_extra); +} + +static cairo_status_t +_cairo_script_surface_finish (void *abstract_surface) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_script_context_t *ctx = to_context (surface); + cairo_status_t status = CAIRO_STATUS_SUCCESS, status2; + + _cairo_surface_wrapper_fini (&surface->wrapper); + + free (surface->cr.current_style.dash); + surface->cr.current_style.dash = NULL; + + _cairo_pattern_fini (&surface->cr.current_source.base); + _cairo_path_fixed_fini (&surface->cr.current_path); + _cairo_surface_clipper_reset (&surface->clipper); + + status = cairo_device_acquire (&ctx->base); + if (unlikely (status)) + return status; + + if (surface->emitted) { + assert (! surface->active); + + if (! cairo_list_is_empty (&surface->operand.link)) { + if (! ctx->active) { + if (target_is_active (surface)) { + _cairo_output_stream_printf (ctx->stream, + "pop\n"); + } else { + int depth = target_depth (surface); + if (depth == 1) { + _cairo_output_stream_printf (ctx->stream, + "exch pop\n"); + } else { + _cairo_output_stream_printf (ctx->stream, + "%d -1 roll pop\n", + depth); + } + } + cairo_list_del (&surface->operand.link); + } else { + struct deferred_finish *link = malloc (sizeof (*link)); + if (link == NULL) { + status2 = _cairo_error (CAIRO_STATUS_NO_MEMORY); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + cairo_list_del (&surface->operand.link); + } else { + link->operand.type = DEFERRED; + cairo_list_swap (&link->operand.link, + &surface->operand.link); + cairo_list_add (&link->link, &ctx->deferred); + } + } + } + + if (surface->defined) { + _cairo_output_stream_printf (ctx->stream, + "/s%u undef\n", + surface->base.unique_id); + } + } + + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_output_stream_flush (to_context (surface)->stream); + + cairo_device_release (&ctx->base); + + return status; +} + +static cairo_int_status_t +_cairo_script_surface_copy_page (void *abstract_surface) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_status_t status; + + status = cairo_device_acquire (surface->base.device); + if (unlikely (status)) + return status; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + _cairo_output_stream_puts (to_context (surface)->stream, "copy-page\n"); + +BAIL: + cairo_device_release (surface->base.device); + return status; +} + +static cairo_int_status_t +_cairo_script_surface_show_page (void *abstract_surface) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_status_t status; + + status = cairo_device_acquire (surface->base.device); + if (unlikely (status)) + return status; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + _cairo_output_stream_puts (to_context (surface)->stream, "show-page\n"); + +BAIL: + cairo_device_release (surface->base.device); + return status; +} + +static cairo_status_t +_cairo_script_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_script_surface_t *surface = cairo_container_of (clipper, + cairo_script_surface_t, + clipper); + cairo_script_context_t *ctx = to_context (surface); + cairo_bool_t matrix_updated = FALSE; + cairo_status_t status; + cairo_box_t box; + + status = _emit_context (surface); + if (unlikely (status)) + return status; + + if (path == NULL) { + if (surface->cr.has_clip) { + _cairo_output_stream_puts (ctx->stream, "reset-clip\n"); + surface->cr.has_clip = FALSE; + } + return CAIRO_STATUS_SUCCESS; + } + + /* skip the trivial clip covering the surface extents */ + if (surface->width >= 0 && surface->height >= 0 && + _cairo_path_fixed_is_box (path, &box)) + { + if (box.p1.x <= 0 && box.p1.y <= 0 && + box.p2.x >= _cairo_fixed_from_double (surface->width) && + box.p2.y >= _cairo_fixed_from_double (surface->height)) + { + return CAIRO_STATUS_SUCCESS; + } + } + + status = _emit_identity (surface, &matrix_updated); + if (unlikely (status)) + return status; + + status = _emit_fill_rule (surface, fill_rule); + if (unlikely (status)) + return status; + + if (path->has_curve_to) { + status = _emit_tolerance (surface, tolerance, matrix_updated); + if (unlikely (status)) + return status; + } + + if (! _cairo_path_fixed_fill_maybe_region (path)) { + status = _emit_antialias (surface, antialias); + if (unlikely (status)) + return status; + } + + status = _emit_path (surface, path, TRUE); + if (unlikely (status)) + return status; + + _cairo_output_stream_puts (ctx->stream, "clip+\n"); + surface->cr.has_clip = TRUE; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +active (cairo_script_surface_t *surface) +{ + cairo_status_t status; + + status = cairo_device_acquire (surface->base.device); + if (unlikely (status)) + return status; + + if (surface->active++ == 0) + to_context (surface)->active++; + + return CAIRO_STATUS_SUCCESS; +} + +static void +inactive (cairo_script_surface_t *surface) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_list_t sorted; + + assert (surface->active > 0); + if (--surface->active) + goto DONE; + + assert (ctx->active > 0); + if (--ctx->active) + goto DONE; + + cairo_list_init (&sorted); + while (! cairo_list_is_empty (&ctx->deferred)) { + struct deferred_finish *df; + cairo_list_t *operand; + int depth; + + df = cairo_list_first_entry (&ctx->deferred, + struct deferred_finish, + link); + + depth = 0; + cairo_list_foreach (operand, &ctx->operands) { + if (operand == &df->operand.link) + break; + depth++; + } + + df->operand.type = depth; + + if (cairo_list_is_empty (&sorted)) { + cairo_list_move (&df->link, &sorted); + } else { + struct deferred_finish *pos; + + cairo_list_foreach_entry (pos, struct deferred_finish, + &sorted, + link) + { + if (df->operand.type < pos->operand.type) + break; + } + cairo_list_move_tail (&df->link, &pos->link); + } + } + + while (! cairo_list_is_empty (&sorted)) { + struct deferred_finish *df; + cairo_list_t *operand; + int depth; + + df = cairo_list_first_entry (&sorted, + struct deferred_finish, + link); + + depth = 0; + cairo_list_foreach (operand, &ctx->operands) { + if (operand == &df->operand.link) + break; + depth++; + } + + if (depth == 0) { + _cairo_output_stream_printf (ctx->stream, + "pop\n"); + } else if (depth == 1) { + _cairo_output_stream_printf (ctx->stream, + "exch pop\n"); + } else { + _cairo_output_stream_printf (ctx->stream, + "%d -1 roll pop\n", + depth); + } + + cairo_list_del (&df->operand.link); + cairo_list_del (&df->link); + free (df); + } + +DONE: + cairo_device_release (surface->base.device); +} + +static cairo_int_status_t +_cairo_script_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_status_t status; + + status = active (surface); + if (unlikely (status)) + return status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + goto BAIL; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + status = _emit_source (surface, op, source); + if (unlikely (status)) + goto BAIL; + + status = _emit_operator (surface, op); + if (unlikely (status)) + goto BAIL; + + _cairo_output_stream_puts (to_context (surface)->stream, + "paint\n"); + + inactive (surface); + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { + return _cairo_surface_wrapper_paint (&surface->wrapper, + op, source, clip); + } + + return CAIRO_STATUS_SUCCESS; + +BAIL: + inactive (surface); + return status; +} + +static cairo_int_status_t +_cairo_script_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_status_t status; + + status = active (surface); + if (unlikely (status)) + return status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + goto BAIL; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + status = _emit_source (surface, op, source); + if (unlikely (status)) + goto BAIL; + + status = _emit_operator (surface, op); + if (unlikely (status)) + goto BAIL; + + if (_cairo_pattern_equal (source, mask)) { + _cairo_output_stream_puts (to_context (surface)->stream, "/source get"); + } else { + status = _emit_pattern (surface, mask); + if (unlikely (status)) + goto BAIL; + } + + assert (surface->cr.current_operator == op); + + _cairo_output_stream_puts (to_context (surface)->stream, + " mask\n"); + + inactive (surface); + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { + return _cairo_surface_wrapper_mask (&surface->wrapper, + op, source, mask, clip); + } + + return CAIRO_STATUS_SUCCESS; + +BAIL: + inactive (surface); + return status; +} + +static cairo_int_status_t +_cairo_script_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_bool_t matrix_updated = FALSE; + cairo_status_t status; + + status = active (surface); + if (unlikely (status)) + return status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + goto BAIL; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + status = _emit_identity (surface, &matrix_updated); + if (unlikely (status)) + goto BAIL; + + status = _emit_path (surface, path, FALSE); + if (unlikely (status)) + goto BAIL; + + status = _emit_source (surface, op, source); + if (unlikely (status)) + goto BAIL; + + status = _emit_scaling_matrix (surface, ctm, &matrix_updated); + if (unlikely (status)) + goto BAIL; + + status = _emit_operator (surface, op); + if (unlikely (status)) + goto BAIL; + + if (_scaling_matrix_equal (&surface->cr.current_ctm, + &surface->cr.current_stroke_matrix)) + { + matrix_updated = FALSE; + } + else + { + matrix_updated = TRUE; + surface->cr.current_stroke_matrix = surface->cr.current_ctm; + } + + status = _emit_stroke_style (surface, style, matrix_updated); + if (unlikely (status)) + goto BAIL; + + status = _emit_tolerance (surface, tolerance, matrix_updated); + if (unlikely (status)) + goto BAIL; + + status = _emit_antialias (surface, antialias); + if (unlikely (status)) + goto BAIL; + + _cairo_output_stream_puts (to_context (surface)->stream, "stroke+\n"); + + inactive (surface); + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { + return _cairo_surface_wrapper_stroke (&surface->wrapper, + op, source, path, + style, + ctm, ctm_inverse, + tolerance, antialias, + clip); + } + + return CAIRO_STATUS_SUCCESS; + +BAIL: + inactive (surface); + return status; +} + +static cairo_int_status_t +_cairo_script_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_bool_t matrix_updated = FALSE; + cairo_status_t status; + cairo_box_t box; + + status = active (surface); + if (unlikely (status)) + return status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + goto BAIL; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + status = _emit_identity (surface, &matrix_updated); + if (unlikely (status)) + goto BAIL; + + status = _emit_source (surface, op, source); + if (unlikely (status)) + goto BAIL; + + if (! _cairo_path_fixed_is_box (path, &box)) { + status = _emit_fill_rule (surface, fill_rule); + if (unlikely (status)) + goto BAIL; + } + + if (path->has_curve_to) { + status = _emit_tolerance (surface, tolerance, matrix_updated); + if (unlikely (status)) + goto BAIL; + } + + if (! _cairo_path_fixed_fill_maybe_region (path)) { + status = _emit_antialias (surface, antialias); + if (unlikely (status)) + goto BAIL; + } + + status = _emit_path (surface, path, TRUE); + if (unlikely (status)) + goto BAIL; + + status = _emit_operator (surface, op); + if (unlikely (status)) + goto BAIL; + + _cairo_output_stream_puts (to_context (surface)->stream, "fill+\n"); + + inactive (surface); + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { + return _cairo_surface_wrapper_fill (&surface->wrapper, + op, source, path, + fill_rule, + tolerance, + antialias, + clip); + } + + return CAIRO_STATUS_SUCCESS; + +BAIL: + inactive (surface); + return status; +} + +static cairo_surface_t * +_cairo_script_surface_snapshot (void *abstract_surface) +{ + cairo_script_surface_t *surface = abstract_surface; + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) + return _cairo_surface_wrapper_snapshot (&surface->wrapper); + + return NULL; +} + +static cairo_bool_t +_cairo_script_surface_has_show_text_glyphs (void *abstract_surface) +{ + return TRUE; +} + +static const char * +_subpixel_order_to_string (cairo_subpixel_order_t subpixel_order) +{ + static const char *names[] = { + "SUBPIXEL_ORDER_DEFAULT", /* CAIRO_SUBPIXEL_ORDER_DEFAULT */ + "SUBPIXEL_ORDER_RGB", /* CAIRO_SUBPIXEL_ORDER_RGB */ + "SUBPIXEL_ORDER_BGR", /* CAIRO_SUBPIXEL_ORDER_BGR */ + "SUBPIXEL_ORDER_VRGB", /* CAIRO_SUBPIXEL_ORDER_VRGB */ + "SUBPIXEL_ORDER_VBGR" /* CAIRO_SUBPIXEL_ORDER_VBGR */ + }; + return names[subpixel_order]; +} +static const char * +_hint_style_to_string (cairo_hint_style_t hint_style) +{ + static const char *names[] = { + "HINT_STYLE_DEFAULT", /* CAIRO_HINT_STYLE_DEFAULT */ + "HINT_STYLE_NONE", /* CAIRO_HINT_STYLE_NONE */ + "HINT_STYLE_SLIGHT", /* CAIRO_HINT_STYLE_SLIGHT */ + "HINT_STYLE_MEDIUM", /* CAIRO_HINT_STYLE_MEDIUM */ + "HINT_STYLE_FULL" /* CAIRO_HINT_STYLE_FULL */ + }; + return names[hint_style]; +} +static const char * +_hint_metrics_to_string (cairo_hint_metrics_t hint_metrics) +{ + static const char *names[] = { + "HINT_METRICS_DEFAULT", /* CAIRO_HINT_METRICS_DEFAULT */ + "HINT_METRICS_OFF", /* CAIRO_HINT_METRICS_OFF */ + "HINT_METRICS_ON" /* CAIRO_HINT_METRICS_ON */ + }; + return names[hint_metrics]; +} + +static cairo_status_t +_emit_font_options (cairo_script_surface_t *surface, + cairo_font_options_t *font_options) +{ + cairo_script_context_t *ctx = to_context (surface); + + if (cairo_font_options_equal (&surface->cr.current_font_options, + font_options)) + { + return CAIRO_STATUS_SUCCESS; + } + + _cairo_output_stream_printf (ctx->stream, "<<"); + + if (font_options->antialias != surface->cr.current_font_options.antialias) { + _cairo_output_stream_printf (ctx->stream, + " /antialias //%s", + _antialias_to_string (font_options->antialias)); + } + + if (font_options->subpixel_order != + surface->cr.current_font_options.subpixel_order) + { + _cairo_output_stream_printf (ctx->stream, + " /subpixel-order //%s", + _subpixel_order_to_string (font_options->subpixel_order)); + } + + if (font_options->hint_style != + surface->cr.current_font_options.hint_style) + { + _cairo_output_stream_printf (ctx->stream, + " /hint-style //%s", + _hint_style_to_string (font_options->hint_style)); + } + + if (font_options->hint_metrics != + surface->cr.current_font_options.hint_metrics) + { + _cairo_output_stream_printf (ctx->stream, + " /hint-metrics //%s", + _hint_metrics_to_string (font_options->hint_metrics)); + } + + _cairo_output_stream_printf (ctx->stream, + " >> set-font-options\n"); + + surface->cr.current_font_options = *font_options; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_script_scaled_font_fini (cairo_scaled_font_private_t *abstract_private, + cairo_scaled_font_t *scaled_font) +{ + cairo_script_font_t *priv = (cairo_script_font_t *)abstract_private; + cairo_script_context_t *ctx = (cairo_script_context_t *)abstract_private->key; + cairo_status_t status; + + status = cairo_device_acquire (&ctx->base); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + _cairo_output_stream_printf (ctx->stream, + "/f%lu undef /sf%lu undef\n", + priv->id, + priv->id); + + _bitmap_release_id (&ctx->font_id, priv->id); + cairo_device_release (&ctx->base); + } + + cairo_list_del (&priv->link); + cairo_list_del (&priv->base.link); + free (priv); +} + +static cairo_script_font_t * +_cairo_script_font_get (cairo_script_context_t *ctx, cairo_scaled_font_t *font) +{ + return (cairo_script_font_t *) _cairo_scaled_font_find_private (font, ctx); +} + +static long unsigned +_cairo_script_font_id (cairo_script_context_t *ctx, cairo_scaled_font_t *font) +{ + return _cairo_script_font_get (ctx, font)->id; +} + +static cairo_status_t +_emit_type42_font (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font) +{ + cairo_script_context_t *ctx = to_context (surface); + const cairo_scaled_font_backend_t *backend; + cairo_output_stream_t *base85_stream; + cairo_output_stream_t *zlib_stream; + cairo_status_t status, status2; + unsigned long size; + unsigned int load_flags; + uint32_t len; + uint8_t *buf; + + backend = scaled_font->backend; + if (backend->load_truetype_table == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = 0; + status = backend->load_truetype_table (scaled_font, 0, 0, NULL, &size); + if (unlikely (status)) + return status; + + buf = malloc (size); + if (unlikely (buf == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = backend->load_truetype_table (scaled_font, 0, 0, buf, &size); + if (unlikely (status)) { + free (buf); + return status; + } + +#if CAIRO_HAS_FT_FONT + load_flags = _cairo_ft_scaled_font_get_load_flags (scaled_font); +#else + load_flags = 0; +#endif + _cairo_output_stream_printf (ctx->stream, + "<< " + "/type 42 " + "/index 0 " + "/flags %d " + "/source <|", + load_flags); + + base85_stream = _cairo_base85_stream_create (ctx->stream); + len = to_be32 (size); + _cairo_output_stream_write (base85_stream, &len, sizeof (len)); + + zlib_stream = _cairo_deflate_stream_create (base85_stream); + + _cairo_output_stream_write (zlib_stream, buf, size); + free (buf); + + status2 = _cairo_output_stream_destroy (zlib_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + status2 = _cairo_output_stream_destroy (base85_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + _cairo_output_stream_printf (ctx->stream, + "~> >> font dup /f%lu exch def set-font-face", + _cairo_script_font_id (ctx, scaled_font)); + + return status; +} + +static cairo_status_t +_emit_scaled_font_init (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font, + cairo_script_font_t **font_out) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_script_font_t *font_private; + cairo_int_status_t status; + + font_private = malloc (sizeof (cairo_script_font_t)); + if (unlikely (font_private == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_scaled_font_attach_private (scaled_font, &font_private->base, ctx, + _cairo_script_scaled_font_fini); + + font_private->parent = scaled_font; + font_private->subset_glyph_index = 0; + font_private->has_sfnt = TRUE; + + cairo_list_add (&font_private->link, &ctx->fonts); + + status = _bitmap_next_id (&ctx->font_id, + &font_private->id); + if (unlikely (status)) { + free (font_private); + return status; + } + + status = _emit_context (surface); + if (unlikely (status)) { + free (font_private); + return status; + } + + status = _emit_type42_font (surface, scaled_font); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + *font_out = font_private; + return status; + } + + font_private->has_sfnt = FALSE; + _cairo_output_stream_printf (ctx->stream, + "dict\n" + " /type 3 set\n" + " /metrics [%f %f %f %f %f] set\n" + " /glyphs array set\n" + " font dup /f%lu exch def set-font-face", + scaled_font->fs_extents.ascent, + scaled_font->fs_extents.descent, + scaled_font->fs_extents.height, + scaled_font->fs_extents.max_x_advance, + scaled_font->fs_extents.max_y_advance, + font_private->id); + + *font_out = font_private; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_scaled_font (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_matrix_t matrix; + cairo_font_options_t options; + cairo_bool_t matrix_updated = FALSE; + cairo_status_t status; + cairo_script_font_t *font_private; + + cairo_scaled_font_get_ctm (scaled_font, &matrix); + status = _emit_scaling_matrix (surface, &matrix, &matrix_updated); + if (unlikely (status)) + return status; + + if (! matrix_updated && surface->cr.current_scaled_font == scaled_font) + return CAIRO_STATUS_SUCCESS; + + surface->cr.current_scaled_font = scaled_font; + + font_private = _cairo_script_font_get (ctx, scaled_font); + if (font_private == NULL) { + cairo_scaled_font_get_font_matrix (scaled_font, &matrix); + status = _emit_font_matrix (surface, &matrix); + if (unlikely (status)) + return status; + + cairo_scaled_font_get_font_options (scaled_font, &options); + status = _emit_font_options (surface, &options); + if (unlikely (status)) + return status; + + status = _emit_scaled_font_init (surface, scaled_font, &font_private); + if (unlikely (status)) + return status; + + assert (target_is_active (surface)); + _cairo_output_stream_printf (ctx->stream, + " /scaled-font get /sf%lu exch def\n", + font_private->id); + } else { + _cairo_output_stream_printf (ctx->stream, + "sf%lu set-scaled-font\n", + font_private->id); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_scaled_glyph_vector (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font, + cairo_script_font_t *font_private, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_script_implicit_context_t old_cr; + cairo_status_t status; + unsigned long index; + + index = ++font_private->subset_glyph_index; + scaled_glyph->dev_private_key = ctx; + scaled_glyph->dev_private = (void *) index; + + _cairo_output_stream_printf (ctx->stream, + "%lu <<\n" + " /metrics [%f %f %f %f %f %f]\n" + " /render {\n", + index, + scaled_glyph->fs_metrics.x_bearing, + scaled_glyph->fs_metrics.y_bearing, + scaled_glyph->fs_metrics.width, + scaled_glyph->fs_metrics.height, + scaled_glyph->fs_metrics.x_advance, + scaled_glyph->fs_metrics.y_advance); + + if (! _cairo_matrix_is_identity (&scaled_font->scale_inverse)) { + _cairo_output_stream_printf (ctx->stream, + "[%f %f %f %f %f %f] transform\n", + scaled_font->scale_inverse.xx, + scaled_font->scale_inverse.yx, + scaled_font->scale_inverse.xy, + scaled_font->scale_inverse.yy, + scaled_font->scale_inverse.x0, + scaled_font->scale_inverse.y0); + } + + old_cr = surface->cr; + _cairo_script_implicit_context_init (&surface->cr); + status = _cairo_recording_surface_replay (scaled_glyph->recording_surface, + &surface->base); + surface->cr = old_cr; + + _cairo_output_stream_puts (ctx->stream, "} >> set\n"); + + return status; +} + +static cairo_status_t +_emit_scaled_glyph_bitmap (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font, + cairo_script_font_t *font_private, + cairo_scaled_glyph_t *scaled_glyph) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_status_t status; + unsigned long index; + + index = ++font_private->subset_glyph_index; + scaled_glyph->dev_private_key = ctx; + scaled_glyph->dev_private = (void *) index; + + _cairo_output_stream_printf (ctx->stream, + "%lu <<\n" + " /metrics [%f %f %f %f %f %f]\n" + " /render {\n" + "%f %f translate\n", + index, + scaled_glyph->fs_metrics.x_bearing, + scaled_glyph->fs_metrics.y_bearing, + scaled_glyph->fs_metrics.width, + scaled_glyph->fs_metrics.height, + scaled_glyph->fs_metrics.x_advance, + scaled_glyph->fs_metrics.y_advance, + scaled_glyph->fs_metrics.x_bearing, + scaled_glyph->fs_metrics.y_bearing); + + status = _emit_image_surface (surface, scaled_glyph->surface); + if (unlikely (status)) + return status; + + _cairo_output_stream_puts (ctx->stream, "pattern "); + + if (! _cairo_matrix_is_identity (&scaled_font->font_matrix)) { + _cairo_output_stream_printf (ctx->stream, + "\n [%f %f %f %f %f %f] set-matrix\n", + scaled_font->font_matrix.xx, + scaled_font->font_matrix.yx, + scaled_font->font_matrix.xy, + scaled_font->font_matrix.yy, + scaled_font->font_matrix.x0, + scaled_font->font_matrix.y0); + } + _cairo_output_stream_puts (ctx->stream, + "mask\n} >> set\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_scaled_glyph_prologue (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font) +{ + cairo_script_context_t *ctx = to_context (surface); + + _cairo_output_stream_printf (ctx->stream, "f%lu /glyphs get\n", + _cairo_script_font_id (ctx, scaled_font)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_emit_scaled_glyphs (cairo_script_surface_t *surface, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + unsigned int num_glyphs) +{ + cairo_script_context_t *ctx = to_context (surface); + cairo_script_font_t *font_private; + cairo_status_t status; + unsigned int n; + cairo_bool_t have_glyph_prologue = FALSE; + + if (num_glyphs == 0) + return CAIRO_STATUS_SUCCESS; + + font_private = _cairo_script_font_get (ctx, scaled_font); + if (font_private->has_sfnt) + return CAIRO_STATUS_SUCCESS; + + _cairo_scaled_font_freeze_cache (scaled_font); + for (n = 0; n < num_glyphs; n++) { + cairo_scaled_glyph_t *scaled_glyph; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[n].index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) + break; + + if (scaled_glyph->dev_private_key == ctx) + continue; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[n].index, + CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE, + &scaled_glyph); + if (_cairo_status_is_error (status)) + break; + + if (status == CAIRO_STATUS_SUCCESS) { + if (! have_glyph_prologue) { + status = _emit_scaled_glyph_prologue (surface, scaled_font); + if (unlikely (status)) + break; + + have_glyph_prologue = TRUE; + } + + status = _emit_scaled_glyph_vector (surface, + scaled_font, font_private, + scaled_glyph); + if (unlikely (status)) + break; + + continue; + } + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[n].index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + if (_cairo_status_is_error (status)) + break; + + if (status == CAIRO_STATUS_SUCCESS) { + if (! have_glyph_prologue) { + status = _emit_scaled_glyph_prologue (surface, scaled_font); + if (unlikely (status)) + break; + + have_glyph_prologue = TRUE; + } + + status = _emit_scaled_glyph_bitmap (surface, + scaled_font, + font_private, + scaled_glyph); + if (unlikely (status)) + break; + + continue; + } + } + _cairo_scaled_font_thaw_cache (scaled_font); + + if (have_glyph_prologue) { + _cairo_output_stream_puts (to_context (surface)->stream, "pop pop\n"); + } + + return status; +} + +static void +to_octal (int value, char *buf, size_t size) +{ + do { + buf[--size] = '0' + (value & 7); + value >>= 3; + } while (size); +} + +static void +_emit_string_literal (cairo_script_surface_t *surface, + const char *utf8, int len) +{ + cairo_script_context_t *ctx = to_context (surface); + char c; + const char *end; + + _cairo_output_stream_puts (ctx->stream, "("); + + if (utf8 == NULL) { + end = utf8; + } else { + if (len < 0) + len = strlen (utf8); + end = utf8 + len; + } + + while (utf8 < end) { + switch ((c = *utf8++)) { + case '\n': + c = 'n'; + goto ESCAPED_CHAR; + case '\r': + c = 'r'; + goto ESCAPED_CHAR; + case '\t': + c = 't'; + goto ESCAPED_CHAR; + case '\b': + c = 'b'; + goto ESCAPED_CHAR; + case '\f': + c = 'f'; + goto ESCAPED_CHAR; + case '\\': + case '(': + case ')': +ESCAPED_CHAR: + _cairo_output_stream_printf (ctx->stream, "\\%c", c); + break; + default: + if (isprint (c) || isspace (c)) { + _cairo_output_stream_printf (ctx->stream, "%c", c); + } else { + char buf[4] = { '\\' }; + + to_octal (c, buf+1, 3); + _cairo_output_stream_write (ctx->stream, buf, 4); + } + break; + } + } + _cairo_output_stream_puts (ctx->stream, ")"); +} + +static cairo_int_status_t +_cairo_script_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t backward, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_script_surface_t *surface = abstract_surface; + cairo_script_context_t *ctx = to_context (surface); + cairo_script_font_t *font_private; + cairo_scaled_glyph_t *scaled_glyph; + cairo_matrix_t matrix; + cairo_status_t status; + double x, y, ix, iy; + int n; + cairo_output_stream_t *base85_stream = NULL; + + status = active (surface); + if (unlikely (status)) + return status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + goto BAIL; + + status = _emit_context (surface); + if (unlikely (status)) + goto BAIL; + + status = _emit_source (surface, op, source); + if (unlikely (status)) + goto BAIL; + + status = _emit_scaled_font (surface, scaled_font); + if (unlikely (status)) + goto BAIL; + + status = _emit_operator (surface, op); + if (unlikely (status)) + goto BAIL; + + status = _emit_scaled_glyphs (surface, scaled_font, glyphs, num_glyphs); + if (unlikely (status)) + goto BAIL; + + /* (utf8) [cx cy [glyphs]] [clusters] backward show_text_glyphs */ + /* [cx cy [glyphs]] show_glyphs */ + + if (utf8 != NULL && clusters != NULL) { + _emit_string_literal (surface, utf8, utf8_len); + _cairo_output_stream_puts (ctx->stream, " "); + } + + matrix = surface->cr.current_ctm; + status = cairo_matrix_invert (&matrix); + assert (status == CAIRO_STATUS_SUCCESS); + + ix = x = glyphs[0].x; + iy = y = glyphs[0].y; + cairo_matrix_transform_point (&matrix, &ix, &iy); + ix -= scaled_font->font_matrix.x0; + iy -= scaled_font->font_matrix.y0; + + _cairo_scaled_font_freeze_cache (scaled_font); + font_private = _cairo_script_font_get (ctx, scaled_font); + + _cairo_output_stream_printf (ctx->stream, + "[%f %f ", + ix, iy); + + for (n = 0; n < num_glyphs; n++) { + if (font_private->has_sfnt) { + if (glyphs[n].index > 256) + break; + } else { + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[n].index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) { + _cairo_scaled_font_thaw_cache (scaled_font); + goto BAIL; + } + + if ((long unsigned) scaled_glyph->dev_private > 256) + break; + } + } + + if (n == num_glyphs) { + _cairo_output_stream_puts (ctx->stream, "<~"); + base85_stream = _cairo_base85_stream_create (ctx->stream); + } else + _cairo_output_stream_puts (ctx->stream, "["); + + for (n = 0; n < num_glyphs; n++) { + double dx, dy; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs[n].index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (unlikely (status)) { + _cairo_scaled_font_thaw_cache (scaled_font); + goto BAIL; + } + + if (fabs (glyphs[n].x - x) > 1e-5 || fabs (glyphs[n].y - y) > 1e-5) { + if (fabs (glyphs[n].y - y) < 1e-5) { + if (base85_stream != NULL) { + status = _cairo_output_stream_destroy (base85_stream); + if (unlikely (status)) { + base85_stream = NULL; + break; + } + + _cairo_output_stream_printf (ctx->stream, + "~> %f <~", glyphs[n].x - x); + base85_stream = _cairo_base85_stream_create (ctx->stream); + } else { + _cairo_output_stream_printf (ctx->stream, + " ] %f [ ", glyphs[n].x - x); + } + + x = glyphs[n].x; + } else { + ix = x = glyphs[n].x; + iy = y = glyphs[n].y; + cairo_matrix_transform_point (&matrix, &ix, &iy); + ix -= scaled_font->font_matrix.x0; + iy -= scaled_font->font_matrix.y0; + if (base85_stream != NULL) { + status = _cairo_output_stream_destroy (base85_stream); + if (unlikely (status)) { + base85_stream = NULL; + break; + } + + _cairo_output_stream_printf (ctx->stream, + "~> %f %f <~", + ix, iy); + base85_stream = _cairo_base85_stream_create (ctx->stream); + } else { + _cairo_output_stream_printf (ctx->stream, + " ] %f %f [ ", + ix, iy); + } + } + } + if (base85_stream != NULL) { + uint8_t c; + + if (font_private->has_sfnt) + c = glyphs[n].index; + else + c = (uint8_t) (long unsigned) scaled_glyph->dev_private; + + _cairo_output_stream_write (base85_stream, &c, 1); + } else { + if (font_private->has_sfnt) + _cairo_output_stream_printf (ctx->stream, " %lu", + glyphs[n].index); + else + _cairo_output_stream_printf (ctx->stream, " %lu", + (long unsigned) scaled_glyph->dev_private); + } + + dx = scaled_glyph->metrics.x_advance; + dy = scaled_glyph->metrics.y_advance; + cairo_matrix_transform_distance (&scaled_font->ctm, &dx, &dy); + x += dx; + y += dy; + } + _cairo_scaled_font_thaw_cache (scaled_font); + + if (base85_stream != NULL) { + cairo_status_t status2; + + status2 = _cairo_output_stream_destroy (base85_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + _cairo_output_stream_printf (ctx->stream, "~>"); + } else { + _cairo_output_stream_puts (ctx->stream, " ]"); + } + if (unlikely (status)) + return status; + + if (utf8 != NULL && clusters != NULL) { + for (n = 0; n < num_clusters; n++) { + if (clusters[n].num_bytes > UCHAR_MAX || + clusters[n].num_glyphs > UCHAR_MAX) + { + break; + } + } + + if (n < num_clusters) { + _cairo_output_stream_puts (ctx->stream, "] [ "); + for (n = 0; n < num_clusters; n++) { + _cairo_output_stream_printf (ctx->stream, + "%d %d ", + clusters[n].num_bytes, + clusters[n].num_glyphs); + } + _cairo_output_stream_puts (ctx->stream, "]"); + } + else + { + _cairo_output_stream_puts (ctx->stream, "] <~"); + base85_stream = _cairo_base85_stream_create (ctx->stream); + for (n = 0; n < num_clusters; n++) { + uint8_t c[2]; + c[0] = clusters[n].num_bytes; + c[1] = clusters[n].num_glyphs; + _cairo_output_stream_write (base85_stream, c, 2); + } + status = _cairo_output_stream_destroy (base85_stream); + if (unlikely (status)) + goto BAIL; + + _cairo_output_stream_puts (ctx->stream, "~>"); + } + + _cairo_output_stream_printf (ctx->stream, + " //%s show-text-glyphs\n", + _direction_to_string (backward)); + } else { + _cairo_output_stream_puts (ctx->stream, + "] show-glyphs\n"); + } + + inactive (surface); + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)){ + return _cairo_surface_wrapper_show_text_glyphs (&surface->wrapper, + op, source, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + backward, + scaled_font, + clip); + } + + return CAIRO_STATUS_SUCCESS; + +BAIL: + inactive (surface); + return status; +} + +static cairo_bool_t +_cairo_script_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_script_surface_t *surface = abstract_surface; + + if (_cairo_surface_wrapper_is_active (&surface->wrapper)) { + return _cairo_surface_wrapper_get_extents (&surface->wrapper, + rectangle); + } + + if (surface->width < 0 || surface->height < 0) + return FALSE; + + rectangle->x = 0; + rectangle->y = 0; + rectangle->width = surface->width; + rectangle->height = surface->height; + + return TRUE; +} + +static const cairo_surface_backend_t +_cairo_script_surface_backend = { + CAIRO_SURFACE_TYPE_SCRIPT, + _cairo_script_surface_finish, + + _cairo_default_context_create, + + _cairo_script_surface_create_similar, + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_script_surface_source, + _cairo_script_surface_acquire_source_image, + _cairo_script_surface_release_source_image, + _cairo_script_surface_snapshot, + + _cairo_script_surface_copy_page, + _cairo_script_surface_show_page, + + _cairo_script_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_script_surface_paint, + _cairo_script_surface_mask, + _cairo_script_surface_stroke, + _cairo_script_surface_fill, + NULL, /* fill/stroke */ + NULL, /* glyphs */ + _cairo_script_surface_has_show_text_glyphs, + _cairo_script_surface_show_text_glyphs +}; + +static void +_cairo_script_implicit_context_init (cairo_script_implicit_context_t *cr) +{ + cr->current_operator = CAIRO_GSTATE_OPERATOR_DEFAULT; + cr->current_fill_rule = CAIRO_GSTATE_FILL_RULE_DEFAULT; + cr->current_tolerance = CAIRO_GSTATE_TOLERANCE_DEFAULT; + cr->current_antialias = CAIRO_ANTIALIAS_DEFAULT; + _cairo_stroke_style_init (&cr->current_style); + _cairo_pattern_init_solid (&cr->current_source.solid, + CAIRO_COLOR_BLACK); + _cairo_path_fixed_init (&cr->current_path); + cairo_matrix_init_identity (&cr->current_ctm); + cairo_matrix_init_identity (&cr->current_stroke_matrix); + cairo_matrix_init_identity (&cr->current_font_matrix); + _cairo_font_options_init_default (&cr->current_font_options); + cr->current_scaled_font = NULL; + cr->has_clip = FALSE; +} + +static void +_cairo_script_implicit_context_reset (cairo_script_implicit_context_t *cr) +{ + free (cr->current_style.dash); + cr->current_style.dash = NULL; + + _cairo_pattern_fini (&cr->current_source.base); + _cairo_path_fixed_fini (&cr->current_path); + + _cairo_script_implicit_context_init (cr); +} + +static cairo_script_surface_t * +_cairo_script_surface_create_internal (cairo_script_context_t *ctx, + cairo_content_t content, + cairo_rectangle_t *extents, + cairo_surface_t *passthrough) +{ + cairo_script_surface_t *surface; + + if (unlikely (ctx == NULL)) + return (cairo_script_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); + + surface = malloc (sizeof (cairo_script_surface_t)); + if (unlikely (surface == NULL)) + return (cairo_script_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_script_surface_backend, + &ctx->base, + content); + + _cairo_surface_wrapper_init (&surface->wrapper, passthrough); + + _cairo_surface_clipper_init (&surface->clipper, + _cairo_script_surface_clipper_intersect_clip_path); + + surface->width = surface->height = -1; + if (extents) { + surface->width = extents->width; + surface->height = extents->height; + cairo_surface_set_device_offset (&surface->base, + -extents->x, -extents->y); + } + + surface->emitted = FALSE; + surface->defined = FALSE; + surface->active = FALSE; + surface->operand.type = SURFACE; + cairo_list_init (&surface->operand.link); + + _cairo_script_implicit_context_init (&surface->cr); + + return surface; +} + +static const cairo_device_backend_t _cairo_script_device_backend = { + CAIRO_DEVICE_TYPE_SCRIPT, + + NULL, NULL, /* lock, unlock */ + + _device_flush, /* flush */ + NULL, /* finish */ + _device_destroy +}; + +cairo_device_t * +_cairo_script_context_create_internal (cairo_output_stream_t *stream) +{ + cairo_script_context_t *ctx; + + ctx = malloc (sizeof (cairo_script_context_t)); + if (unlikely (ctx == NULL)) + return _cairo_device_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + memset (ctx, 0, sizeof (cairo_script_context_t)); + + _cairo_device_init (&ctx->base, &_cairo_script_device_backend); + + cairo_list_init (&ctx->operands); + cairo_list_init (&ctx->deferred); + ctx->stream = stream; + ctx->mode = CAIRO_SCRIPT_MODE_ASCII; + + cairo_list_init (&ctx->fonts); + cairo_list_init (&ctx->defines); + + ctx->attach_snapshots = TRUE; + + return &ctx->base; +} + +void +_cairo_script_context_attach_snapshots (cairo_device_t *device, + cairo_bool_t enable) +{ + cairo_script_context_t *ctx; + + ctx = (cairo_script_context_t *) device; + ctx->attach_snapshots = enable; +} + +static cairo_device_t * +_cairo_script_context_create (cairo_output_stream_t *stream) +{ + cairo_script_context_t *ctx; + + ctx = (cairo_script_context_t *) + _cairo_script_context_create_internal (stream); + if (unlikely (ctx->base.status)) + return &ctx->base; + + ctx->owns_stream = TRUE; + _cairo_output_stream_puts (ctx->stream, "%!CairoScript\n"); + return &ctx->base; +} + +/** + * cairo_script_create: + * @filename: the name (path) of the file to write the script to + * + * Creates a output device for emitting the script, used when + * creating the individual surfaces. + * + * Return value: a pointer to the newly created device. The caller + * owns the surface and should call cairo_device_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" device if an error such as out of memory + * occurs. You can use cairo_device_status() to check for this. + * + * Since: 1.12 + **/ +cairo_device_t * +cairo_script_create (const char *filename) +{ + cairo_output_stream_t *stream; + cairo_status_t status; + + stream = _cairo_output_stream_create_for_filename (filename); + if ((status = _cairo_output_stream_get_status (stream))) + return _cairo_device_create_in_error (status); + + return _cairo_script_context_create (stream); +} + +/** + * cairo_script_create_for_stream: + * @write_func: callback function passed the bytes written to the script + * @closure: user data to be passed to the callback + * + * Creates a output device for emitting the script, used when + * creating the individual surfaces. + * + * Return value: a pointer to the newly created device. The caller + * owns the surface and should call cairo_device_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" device if an error such as out of memory + * occurs. You can use cairo_device_status() to check for this. + * + * Since: 1.12 + **/ +cairo_device_t * +cairo_script_create_for_stream (cairo_write_func_t write_func, + void *closure) +{ + cairo_output_stream_t *stream; + cairo_status_t status; + + stream = _cairo_output_stream_create (write_func, NULL, closure); + if ((status = _cairo_output_stream_get_status (stream))) + return _cairo_device_create_in_error (status); + + return _cairo_script_context_create (stream); +} + +/** + * cairo_script_write_comment: + * @script: the script (output device) + * @comment: the string to emit + * @len:the length of the sting to write, or -1 to use strlen() + * + * Emit a string verbatim into the script. + * + * Since: 1.12 + **/ +void +cairo_script_write_comment (cairo_device_t *script, + const char *comment, + int len) +{ + cairo_script_context_t *context = (cairo_script_context_t *) script; + + if (len < 0) + len = strlen (comment); + + _cairo_output_stream_puts (context->stream, "% "); + _cairo_output_stream_write (context->stream, comment, len); + _cairo_output_stream_puts (context->stream, "\n"); +} + +/** + * cairo_script_set_mode: + * @script: The script (output device) + * @mode: the new mode + * + * Change the output mode of the script + * + * Since: 1.12 + **/ +void +cairo_script_set_mode (cairo_device_t *script, + cairo_script_mode_t mode) +{ + cairo_script_context_t *context = (cairo_script_context_t *) script; + + context->mode = mode; +} + +/** + * cairo_script_get_mode: + * @script: The script (output device) to query + * + * Queries the script for its current output mode. + * + * Return value: the current output mode of the script + * + * Since: 1.12 + **/ +cairo_script_mode_t +cairo_script_get_mode (cairo_device_t *script) +{ + cairo_script_context_t *context = (cairo_script_context_t *) script; + + return context->mode; +} + +/** + * cairo_script_surface_create: + * @script: the script (output device) + * @content: the content of the surface + * @width: width in pixels + * @height: height in pixels + * + * Create a new surface that will emit its rendering through @script + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_script_surface_create (cairo_device_t *script, + cairo_content_t content, + double width, + double height) +{ + cairo_rectangle_t *extents, r; + + if (unlikely (script->backend->type != CAIRO_DEVICE_TYPE_SCRIPT)) + return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + + if (unlikely (script->status)) + return _cairo_surface_create_in_error (script->status); + + extents = NULL; + if (width > 0 && height > 0) { + r.x = r.y = 0; + r.width = width; + r.height = height; + extents = &r; + } + return &_cairo_script_surface_create_internal ((cairo_script_context_t *) script, + content, extents, + NULL)->base; +} +slim_hidden_def (cairo_script_surface_create); + +/** + * cairo_script_surface_create_for_target: + * @script: the script (output device) + * @target: a target surface to wrap + * + * Create a pxoy surface that will render to @target and record + * the operations to @device. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_script_surface_create_for_target (cairo_device_t *script, + cairo_surface_t *target) +{ + cairo_rectangle_int_t extents; + cairo_rectangle_t rect, *r; + + if (unlikely (script->backend->type != CAIRO_DEVICE_TYPE_SCRIPT)) + return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + + if (unlikely (script->status)) + return _cairo_surface_create_in_error (script->status); + + if (unlikely (target->status)) + return _cairo_surface_create_in_error (target->status); + + r = NULL; + if (_cairo_surface_get_extents (target, &extents)) { + rect.x = rect.y = 0; + rect.width = extents.width; + rect.height = extents.height; + r= ▭ + } + return &_cairo_script_surface_create_internal ((cairo_script_context_t *) script, + target->content, r, + target)->base; +} + +/** + * cairo_script_from_recording_surface: + * @script: the script (output device) + * @recording_surface: the recording surface to replay + * + * Converts the record operations in @recording_surface into a script. + * + * Return value: #CAIRO_STATUS_SUCCESS on successful completion or an error code. + * + * Since: 1.12 + **/ +cairo_status_t +cairo_script_from_recording_surface (cairo_device_t *script, + cairo_surface_t *recording_surface) +{ + cairo_rectangle_t r, *extents; + cairo_surface_t *surface; + cairo_status_t status; + + if (unlikely (script->backend->type != CAIRO_DEVICE_TYPE_SCRIPT)) + return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + + if (unlikely (script->status)) + return _cairo_error (script->status); + + if (unlikely (recording_surface->status)) + return recording_surface->status; + + if (unlikely (! _cairo_surface_is_recording (recording_surface))) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + extents = NULL; + if (_cairo_recording_surface_get_bounds (recording_surface, &r)) + extents = &r; + + surface = &_cairo_script_surface_create_internal ((cairo_script_context_t *) script, + recording_surface->content, + extents, + NULL)->base; + if (unlikely (surface->status)) + return surface->status; + + status = _cairo_recording_surface_replay (recording_surface, surface); + cairo_surface_destroy (surface); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-script.h b/Build/source/libs/cairo/cairo-src/src/cairo-script.h new file mode 100644 index 00000000000..b5a8cf32d0b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-script.h @@ -0,0 +1,98 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SCRIPT_H +#define CAIRO_SCRIPT_H + +#include "cairo.h" + +#if CAIRO_HAS_SCRIPT_SURFACE + +CAIRO_BEGIN_DECLS + +/** + * cairo_script_mode_t: + * @CAIRO_SCRIPT_MODE_ASCII: the output will be in readable text (default). (Since 1.12) + * @CAIRO_SCRIPT_MODE_BINARY: the output will use byte codes. (Since 1.12) + * + * A set of script output variants. + * + * Since: 1.12 + **/ +typedef enum { + CAIRO_SCRIPT_MODE_ASCII, + CAIRO_SCRIPT_MODE_BINARY +} cairo_script_mode_t; + +cairo_public cairo_device_t * +cairo_script_create (const char *filename); + +cairo_public cairo_device_t * +cairo_script_create_for_stream (cairo_write_func_t write_func, + void *closure); + +cairo_public void +cairo_script_write_comment (cairo_device_t *script, + const char *comment, + int len); + +cairo_public void +cairo_script_set_mode (cairo_device_t *script, + cairo_script_mode_t mode); + +cairo_public cairo_script_mode_t +cairo_script_get_mode (cairo_device_t *script); + +cairo_public cairo_surface_t * +cairo_script_surface_create (cairo_device_t *script, + cairo_content_t content, + double width, + double height); + +cairo_public cairo_surface_t * +cairo_script_surface_create_for_target (cairo_device_t *script, + cairo_surface_t *target); + +cairo_public cairo_status_t +cairo_script_from_recording_surface (cairo_device_t *script, + cairo_surface_t *recording_surface); + +CAIRO_END_DECLS + +#else /*CAIRO_HAS_SCRIPT_SURFACE*/ +# error Cairo was not compiled with support for the CairoScript backend +#endif /*CAIRO_HAS_SCRIPT_SURFACE*/ + +#endif /*CAIRO_SCRIPT_H*/ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-shape-mask-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-shape-mask-compositor.c new file mode 100644 index 00000000000..3117267cccf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-shape-mask-compositor.c @@ -0,0 +1,340 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-compositor-private.h" +#include "cairo-clip-private.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-private.h" +#include "cairo-surface-offset-private.h" + +static cairo_int_status_t +_cairo_shape_mask_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_surface_t *mask; + cairo_surface_pattern_t pattern; + cairo_int_status_t status; + cairo_clip_t *clip; + + if (! extents->is_bounded) + return CAIRO_INT_STATUS_UNSUPPORTED; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + mask = _cairo_surface_create_scratch (extents->surface, + CAIRO_CONTENT_ALPHA, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (mask->status)) + return mask->status; + + clip = extents->clip; + if (! _cairo_clip_is_region (clip)) + clip = _cairo_clip_copy_region (clip); + + if (! mask->is_clear) { + status = _cairo_surface_offset_paint (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + clip); + if (unlikely (status)) + goto error; + } + + status = _cairo_surface_offset_stroke (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + path, style, ctm, ctm_inverse, + tolerance, antialias, + clip); + if (unlikely (status)) + goto error; + + if (clip != extents->clip) { + status = _cairo_clip_combine_with_surface (extents->clip, mask, + extents->bounded.x, + extents->bounded.y); + if (unlikely (status)) + goto error; + } + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->bounded.x, + -extents->bounded.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + if (extents->op == CAIRO_OPERATOR_SOURCE) { + status = _cairo_surface_mask (extents->surface, + CAIRO_OPERATOR_DEST_OUT, + &_cairo_pattern_white.base, + &pattern.base, + clip); + if ((status == CAIRO_INT_STATUS_SUCCESS)) { + status = _cairo_surface_mask (extents->surface, + CAIRO_OPERATOR_ADD, + &extents->source_pattern.base, + &pattern.base, + clip); + } + } else { + status = _cairo_surface_mask (extents->surface, + extents->op, + &extents->source_pattern.base, + &pattern.base, + clip); + } + _cairo_pattern_fini (&pattern.base); + +error: + cairo_surface_destroy (mask); + if (clip != extents->clip) + _cairo_clip_destroy (clip); + return status; +} + +static cairo_int_status_t +_cairo_shape_mask_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_surface_t *mask; + cairo_surface_pattern_t pattern; + cairo_int_status_t status; + cairo_clip_t *clip; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (! extents->is_bounded) + return CAIRO_INT_STATUS_UNSUPPORTED; + + mask = _cairo_surface_create_scratch (extents->surface, + CAIRO_CONTENT_ALPHA, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (mask->status)) + return mask->status; + + clip = extents->clip; + if (! _cairo_clip_is_region (clip)) + clip = _cairo_clip_copy_region (clip); + + if (! mask->is_clear) { + status = _cairo_surface_offset_paint (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + clip); + if (unlikely (status)) + goto error; + } + + status = _cairo_surface_offset_fill (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + path, fill_rule, tolerance, antialias, + clip); + if (unlikely (status)) + goto error; + + if (clip != extents->clip) { + status = _cairo_clip_combine_with_surface (extents->clip, mask, + extents->bounded.x, + extents->bounded.y); + if (unlikely (status)) + goto error; + } + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->bounded.x, + -extents->bounded.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + if (extents->op == CAIRO_OPERATOR_SOURCE) { + status = _cairo_surface_mask (extents->surface, + CAIRO_OPERATOR_DEST_OUT, + &_cairo_pattern_white.base, + &pattern.base, + clip); + if ((status == CAIRO_INT_STATUS_SUCCESS)) { + status = _cairo_surface_mask (extents->surface, + CAIRO_OPERATOR_ADD, + &extents->source_pattern.base, + &pattern.base, + clip); + } + } else { + status = _cairo_surface_mask (extents->surface, + extents->op, + &extents->source_pattern.base, + &pattern.base, + clip); + } + _cairo_pattern_fini (&pattern.base); + +error: + if (clip != extents->clip) + _cairo_clip_destroy (clip); + cairo_surface_destroy (mask); + return status; +} + +static cairo_int_status_t +_cairo_shape_mask_compositor_glyphs (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_surface_t *mask; + cairo_surface_pattern_t pattern; + cairo_int_status_t status; + cairo_clip_t *clip; + + if (! extents->is_bounded) + return CAIRO_INT_STATUS_UNSUPPORTED; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + mask = _cairo_surface_create_scratch (extents->surface, + CAIRO_CONTENT_ALPHA, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (mask->status)) + return mask->status; + + clip = extents->clip; + if (! _cairo_clip_is_region (clip)) + clip = _cairo_clip_copy_region (clip); + + if (! mask->is_clear) { + status = _cairo_surface_offset_paint (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + clip); + if (unlikely (status)) + goto error; + } + + status = _cairo_surface_offset_glyphs (mask, + extents->bounded.x, + extents->bounded.y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + scaled_font, glyphs, num_glyphs, + clip); + if (unlikely (status)) + goto error; + + if (clip != extents->clip) { + status = _cairo_clip_combine_with_surface (extents->clip, mask, + extents->bounded.x, + extents->bounded.y); + if (unlikely (status)) + goto error; + } + + _cairo_pattern_init_for_surface (&pattern, mask); + cairo_matrix_init_translate (&pattern.base.matrix, + -extents->bounded.x, + -extents->bounded.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + pattern.base.extend = CAIRO_EXTEND_NONE; + if (extents->op == CAIRO_OPERATOR_SOURCE) { + status = _cairo_surface_mask (extents->surface, + CAIRO_OPERATOR_DEST_OUT, + &_cairo_pattern_white.base, + &pattern.base, + clip); + if ((status == CAIRO_INT_STATUS_SUCCESS)) { + status = _cairo_surface_mask (extents->surface, + CAIRO_OPERATOR_ADD, + &extents->source_pattern.base, + &pattern.base, + clip); + } + } else { + status = _cairo_surface_mask (extents->surface, + extents->op, + &extents->source_pattern.base, + &pattern.base, + clip); + } + _cairo_pattern_fini (&pattern.base); + +error: + if (clip != extents->clip) + _cairo_clip_destroy (clip); + cairo_surface_destroy (mask); + return status; +} + +void +_cairo_shape_mask_compositor_init (cairo_compositor_t *compositor, + const cairo_compositor_t *delegate) +{ + compositor->delegate = delegate; + + compositor->paint = NULL; + compositor->mask = NULL; + compositor->fill = _cairo_shape_mask_compositor_fill; + compositor->stroke = _cairo_shape_mask_compositor_stroke; + compositor->glyphs = _cairo_shape_mask_compositor_glyphs; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-skia.h b/Build/source/libs/cairo/cairo-src/src/cairo-skia.h new file mode 100644 index 00000000000..99b92865699 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-skia.h @@ -0,0 +1,66 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_SKIA_H +#define CAIRO_SKIA_H + +#include "cairo.h" + +#if CAIRO_HAS_SKIA_SURFACE + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_skia_surface_create (cairo_format_t format, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_skia_surface_create_for_data (unsigned char *data, + cairo_format_t format, + int width, + int height, + int stride); + +CAIRO_END_DECLS + +#else + +# error Cairo was not compiled with support for the Skia backend + +#endif + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-slope-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-slope-private.h new file mode 100644 index 00000000000..6a58c9f456d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-slope-private.h @@ -0,0 +1,72 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef _CAIRO_SLOPE_PRIVATE_H +#define _CAIRO_SLOPE_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-fixed-private.h" + +static inline void +_cairo_slope_init (cairo_slope_t *slope, + const cairo_point_t *a, + const cairo_point_t *b) +{ + slope->dx = b->x - a->x; + slope->dy = b->y - a->y; +} + +static inline cairo_bool_t +_cairo_slope_equal (const cairo_slope_t *a, const cairo_slope_t *b) +{ + return _cairo_int64_eq (_cairo_int32x32_64_mul (a->dy, b->dx), + _cairo_int32x32_64_mul (b->dy, a->dx)); +} + +static inline cairo_bool_t +_cairo_slope_backwards (const cairo_slope_t *a, const cairo_slope_t *b) +{ + return _cairo_int64_negative (_cairo_int64_add (_cairo_int32x32_64_mul (a->dx, b->dx), + _cairo_int32x32_64_mul (a->dy, b->dy))); +} + +cairo_private int +_cairo_slope_compare (const cairo_slope_t *a, + const cairo_slope_t *b) cairo_pure; + + +#endif /* _CAIRO_SLOPE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-slope.c b/Build/source/libs/cairo/cairo-src/src/cairo-slope.c new file mode 100644 index 00000000000..cc5f30cb0b3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-slope.c @@ -0,0 +1,99 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-slope-private.h" + +/* Compare two slopes. Slope angles begin at 0 in the direction of the + positive X axis and increase in the direction of the positive Y + axis. + + This function always compares the slope vectors based on the + smaller angular difference between them, (that is based on an + angular difference that is strictly less than pi). To break ties + when comparing slope vectors with an angular difference of exactly + pi, the vector with a positive dx (or positive dy if dx's are zero) + is considered to be more positive than the other. + + Also, all slope vectors with both dx==0 and dy==0 are considered + equal and more positive than any non-zero vector. + + < 0 => a less positive than b + == 0 => a equal to b + > 0 => a more positive than b +*/ +int +_cairo_slope_compare (const cairo_slope_t *a, const cairo_slope_t *b) +{ + cairo_int64_t ady_bdx = _cairo_int32x32_64_mul (a->dy, b->dx); + cairo_int64_t bdy_adx = _cairo_int32x32_64_mul (b->dy, a->dx); + int cmp; + + cmp = _cairo_int64_cmp (ady_bdx, bdy_adx); + if (cmp) + return cmp; + + /* special-case zero vectors. the intended logic here is: + * zero vectors all compare equal, and more positive than any + * non-zero vector. + */ + if (a->dx == 0 && a->dy == 0 && b->dx == 0 && b->dy ==0) + return 0; + if (a->dx == 0 && a->dy == 0) + return 1; + if (b->dx == 0 && b->dy ==0) + return -1; + + /* Finally, we're looking at two vectors that are either equal or + * that differ by exactly pi. We can identify the "differ by pi" + * case by looking for a change in sign in either dx or dy between + * a and b. + * + * And in these cases, we eliminate the ambiguity by reducing the angle + * of b by an infinitesimally small amount, (that is, 'a' will + * always be considered less than 'b'). + */ + if ((a->dx ^ b->dx) < 0 || (a->dy ^ b->dy) < 0) { + if (a->dx > 0 || (a->dx == 0 && a->dy > 0)) + return -1; + else + return +1; + } + + /* Finally, for identical slopes, we obviously return 0. */ + return 0; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor-private.h new file mode 100644 index 00000000000..0babebd26b5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor-private.h @@ -0,0 +1,111 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SPANS_COMPOSITOR_PRIVATE_H +#define CAIRO_SPANS_COMPOSITOR_PRIVATE_H + +#include "cairo-compositor-private.h" +#include "cairo-types-private.h" +#include "cairo-spans-private.h" + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_abstract_span_renderer { + cairo_span_renderer_t base; + char data[4096]; +} cairo_abstract_span_renderer_t; + +struct cairo_spans_compositor { + cairo_compositor_t base; + + unsigned int flags; +#define CAIRO_SPANS_COMPOSITOR_HAS_LERP 0x1 + + /* pixel-aligned fast paths */ + cairo_int_status_t (*fill_boxes) (void *surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes); + + cairo_int_status_t (*draw_image_boxes) (void *surface, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy); + + cairo_int_status_t (*copy_boxes) (void *surface, + cairo_surface_t *src, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents, + int dx, int dy); + + cairo_surface_t * (*pattern_to_surface) (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y); + + cairo_int_status_t (*composite_boxes) (void *surface, + cairo_operator_t op, + cairo_surface_t *source, + cairo_surface_t *mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents); + + /* general shape masks using a span renderer */ + cairo_int_status_t (*renderer_init) (cairo_abstract_span_renderer_t *renderer, + const cairo_composite_rectangles_t *extents, + cairo_antialias_t antialias, + cairo_bool_t needs_clip); + + void (*renderer_fini) (cairo_abstract_span_renderer_t *renderer, + cairo_int_status_t status); +}; + +cairo_private void +_cairo_spans_compositor_init (cairo_spans_compositor_t *compositor, + const cairo_compositor_t *delegate); + +CAIRO_END_DECLS + +#endif /* CAIRO_SPANS_COMPOSITOR_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor.c new file mode 100644 index 00000000000..efbae254bf4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-spans-compositor.c @@ -0,0 +1,1201 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-compositor-private.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-paginated-private.h" +#include "cairo-pattern-inline.h" +#include "cairo-region-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-spans-compositor-private.h" +#include "cairo-surface-subsurface-private.h" +#include "cairo-surface-snapshot-private.h" +#include "cairo-surface-observer-private.h" + +typedef struct { + cairo_polygon_t *polygon; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; +} composite_spans_info_t; + +static cairo_int_status_t +composite_polygon (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias); + +static cairo_int_status_t +composite_boxes (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes); + +static cairo_int_status_t +clip_and_composite_polygon (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias); +static cairo_surface_t * +get_clip_surface (const cairo_spans_compositor_t *compositor, + cairo_surface_t *dst, + const cairo_clip_t *clip, + const cairo_rectangle_int_t *extents) +{ + cairo_composite_rectangles_t composite; + cairo_surface_t *surface; + cairo_box_t box; + cairo_polygon_t polygon; + const cairo_clip_path_t *clip_path; + cairo_antialias_t antialias; + cairo_fill_rule_t fill_rule; + cairo_int_status_t status; + + assert (clip->path); + + surface = _cairo_surface_create_scratch (dst, + CAIRO_CONTENT_ALPHA, + extents->width, + extents->height, + CAIRO_COLOR_TRANSPARENT); + + _cairo_box_from_rectangle (&box, extents); + _cairo_polygon_init (&polygon, &box, 1); + + clip_path = clip->path; + status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, + clip_path->tolerance, + &polygon); + if (unlikely (status)) + goto cleanup_polygon; + + polygon.num_limits = 0; + + antialias = clip_path->antialias; + fill_rule = clip_path->fill_rule; + + if (clip->boxes) { + cairo_polygon_t intersect; + cairo_boxes_t tmp; + + _cairo_boxes_init_for_array (&tmp, clip->boxes, clip->num_boxes); + status= _cairo_polygon_init_boxes (&intersect, &tmp); + if (unlikely (status)) + goto cleanup_polygon; + + status = _cairo_polygon_intersect (&polygon, fill_rule, + &intersect, CAIRO_FILL_RULE_WINDING); + _cairo_polygon_fini (&intersect); + + if (unlikely (status)) + goto cleanup_polygon; + + fill_rule = CAIRO_FILL_RULE_WINDING; + } + + polygon.limits = NULL; + polygon.num_limits = 0; + + clip_path = clip_path->prev; + while (clip_path) { + if (clip_path->antialias == antialias) { + cairo_polygon_t next; + + _cairo_polygon_init (&next, NULL, 0); + status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, + clip_path->tolerance, + &next); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = _cairo_polygon_intersect (&polygon, fill_rule, + &next, clip_path->fill_rule); + _cairo_polygon_fini (&next); + if (unlikely (status)) + goto cleanup_polygon; + + fill_rule = CAIRO_FILL_RULE_WINDING; + } + + clip_path = clip_path->prev; + } + + _cairo_polygon_translate (&polygon, -extents->x, -extents->y); + status = _cairo_composite_rectangles_init_for_polygon (&composite, surface, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + &polygon, + NULL); + if (unlikely (status)) + goto cleanup_polygon; + + status = composite_polygon (compositor, &composite, + &polygon, fill_rule, antialias); + _cairo_composite_rectangles_fini (&composite); + _cairo_polygon_fini (&polygon); + if (unlikely (status)) + goto error; + + _cairo_polygon_init (&polygon, &box, 1); + + clip_path = clip->path; + antialias = clip_path->antialias == CAIRO_ANTIALIAS_DEFAULT ? CAIRO_ANTIALIAS_NONE : CAIRO_ANTIALIAS_DEFAULT; + clip_path = clip_path->prev; + while (clip_path) { + if (clip_path->antialias == antialias) { + if (polygon.num_edges == 0) { + status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, + clip_path->tolerance, + &polygon); + + fill_rule = clip_path->fill_rule; + polygon.limits = NULL; + polygon.num_limits = 0; + } else { + cairo_polygon_t next; + + _cairo_polygon_init (&next, NULL, 0); + status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, + clip_path->tolerance, + &next); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = _cairo_polygon_intersect (&polygon, fill_rule, + &next, clip_path->fill_rule); + _cairo_polygon_fini (&next); + fill_rule = CAIRO_FILL_RULE_WINDING; + } + if (unlikely (status)) + goto error; + } + + clip_path = clip_path->prev; + } + + if (polygon.num_edges) { + _cairo_polygon_translate (&polygon, -extents->x, -extents->y); + status = _cairo_composite_rectangles_init_for_polygon (&composite, surface, + CAIRO_OPERATOR_IN, + &_cairo_pattern_white.base, + &polygon, + NULL); + if (unlikely (status)) + goto cleanup_polygon; + + status = composite_polygon (compositor, &composite, + &polygon, fill_rule, antialias); + _cairo_composite_rectangles_fini (&composite); + _cairo_polygon_fini (&polygon); + if (unlikely (status)) + goto error; + } + + return surface; + +cleanup_polygon: + _cairo_polygon_fini (&polygon); +error: + cairo_surface_destroy (surface); + return _cairo_int_surface_create_in_error (status); +} + +static cairo_int_status_t +fixup_unbounded_mask (const cairo_spans_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_composite_rectangles_t composite; + cairo_surface_t *clip; + cairo_int_status_t status; + + TRACE((stderr, "%s\n", __FUNCTION__)); + + clip = get_clip_surface (compositor, extents->surface, extents->clip, + &extents->unbounded); + if (unlikely (clip->status)) { + if ((cairo_int_status_t)clip->status == CAIRO_INT_STATUS_NOTHING_TO_DO) + return CAIRO_STATUS_SUCCESS; + + return clip->status; + } + + status = _cairo_composite_rectangles_init_for_boxes (&composite, + extents->surface, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + boxes, + NULL); + if (unlikely (status)) + goto cleanup_clip; + + _cairo_pattern_init_for_surface (&composite.mask_pattern.surface, clip); + composite.mask_pattern.base.filter = CAIRO_FILTER_NEAREST; + composite.mask_pattern.base.extend = CAIRO_EXTEND_NONE; + + status = composite_boxes (compositor, &composite, boxes); + + _cairo_pattern_fini (&composite.mask_pattern.base); + _cairo_composite_rectangles_fini (&composite); + +cleanup_clip: + cairo_surface_destroy (clip); + return status; +} + +static cairo_int_status_t +fixup_unbounded_polygon (const cairo_spans_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_polygon_t polygon, intersect; + cairo_composite_rectangles_t composite; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + cairo_int_status_t status; + + TRACE((stderr, "%s\n", __FUNCTION__)); + + /* Can we treat the clip as a regular clear-polygon and use it to fill? */ + status = _cairo_clip_get_polygon (extents->clip, &polygon, + &fill_rule, &antialias); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status= _cairo_polygon_init_boxes (&intersect, boxes); + if (unlikely (status)) + goto cleanup_polygon; + + status = _cairo_polygon_intersect (&polygon, fill_rule, + &intersect, CAIRO_FILL_RULE_WINDING); + _cairo_polygon_fini (&intersect); + + if (unlikely (status)) + goto cleanup_polygon; + + status = _cairo_composite_rectangles_init_for_polygon (&composite, + extents->surface, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + &polygon, + NULL); + if (unlikely (status)) + goto cleanup_polygon; + + status = composite_polygon (compositor, &composite, + &polygon, fill_rule, antialias); + + _cairo_composite_rectangles_fini (&composite); +cleanup_polygon: + _cairo_polygon_fini (&polygon); + + return status; +} + +static cairo_int_status_t +fixup_unbounded_boxes (const cairo_spans_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_boxes_t tmp, clear; + cairo_box_t box; + cairo_int_status_t status; + + assert (boxes->is_pixel_aligned); + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (extents->bounded.width == extents->unbounded.width && + extents->bounded.height == extents->unbounded.height) + { + return CAIRO_STATUS_SUCCESS; + } + + /* subtract the drawn boxes from the unbounded area */ + _cairo_boxes_init (&clear); + + box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); + box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); + box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); + box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); + + if (boxes->num_boxes) { + _cairo_boxes_init (&tmp); + + status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + tmp.chunks.next = &boxes->chunks; + tmp.num_boxes += boxes->num_boxes; + + status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, + CAIRO_FILL_RULE_WINDING, + &clear); + tmp.chunks.next = NULL; + if (unlikely (status)) + goto error; + } else { + box.p1.x = _cairo_fixed_from_int (extents->unbounded.x); + box.p2.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); + + status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + /* If we have a clip polygon, we need to intersect with that as well */ + if (extents->clip->path) { + status = fixup_unbounded_polygon (compositor, extents, &clear); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + status = fixup_unbounded_mask (compositor, extents, &clear); + } else { + /* Otherwise just intersect with the clip boxes */ + if (extents->clip->num_boxes) { + _cairo_boxes_init_for_array (&tmp, + extents->clip->boxes, + extents->clip->num_boxes); + status = _cairo_boxes_intersect (&clear, &tmp, &clear); + if (unlikely (status)) + goto error; + } + + if (clear.is_pixel_aligned) { + status = compositor->fill_boxes (extents->surface, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + } else { + cairo_composite_rectangles_t composite; + + status = _cairo_composite_rectangles_init_for_boxes (&composite, + extents->surface, + CAIRO_OPERATOR_CLEAR, + &_cairo_pattern_clear.base, + &clear, + NULL); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + status = composite_boxes (compositor, &composite, &clear); + _cairo_composite_rectangles_fini (&composite); + } + } + } + +error: + _cairo_boxes_fini (&clear); + return status; +} + +static cairo_surface_t * +unwrap_source (const cairo_pattern_t *pattern) +{ + cairo_rectangle_int_t limit; + + return _cairo_pattern_get_source ((cairo_surface_pattern_t *)pattern, + &limit); +} + +static cairo_bool_t +is_recording_pattern (const cairo_pattern_t *pattern) +{ + cairo_surface_t *surface; + + if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) + return FALSE; + + surface = ((const cairo_surface_pattern_t *) pattern)->surface; + return _cairo_surface_is_recording (surface); +} + +static cairo_bool_t +recording_pattern_contains_sample (const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *sample) +{ + cairo_recording_surface_t *surface; + + if (! is_recording_pattern (pattern)) + return FALSE; + + if (pattern->extend == CAIRO_EXTEND_NONE) + return TRUE; + + surface = (cairo_recording_surface_t *) unwrap_source (pattern); + if (surface->unbounded) + return TRUE; + + return _cairo_rectangle_contains_rectangle (&surface->extents, sample); +} + +static cairo_bool_t +op_reduces_to_source (const cairo_composite_rectangles_t *extents, + cairo_bool_t no_mask) +{ + if (extents->op == CAIRO_OPERATOR_SOURCE) + return TRUE; + + if (extents->surface->is_clear) + return extents->op == CAIRO_OPERATOR_OVER || extents->op == CAIRO_OPERATOR_ADD; + + if (no_mask && extents->op == CAIRO_OPERATOR_OVER) + return _cairo_pattern_is_opaque (&extents->source_pattern.base, + &extents->source_sample_area); + + return FALSE; +} + +static cairo_status_t +upload_boxes (const cairo_spans_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + const cairo_surface_pattern_t *source = &extents->source_pattern.surface; + cairo_surface_t *src; + cairo_rectangle_int_t limit; + cairo_int_status_t status; + int tx, ty; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + src = _cairo_pattern_get_source(source, &limit); + if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_matrix_is_integer_translation (&source->base.matrix, &tx, &ty)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Check that the data is entirely within the image */ + if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width || + extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height) + return CAIRO_INT_STATUS_UNSUPPORTED; + + tx += limit.x; + ty += limit.y; + + if (src->type == CAIRO_SURFACE_TYPE_IMAGE) + status = compositor->draw_image_boxes (dst, + (cairo_image_surface_t *)src, + boxes, tx, ty); + else + status = compositor->copy_boxes (dst, src, boxes, &extents->bounded, + tx, ty); + + return status; +} + +static cairo_bool_t +_clip_is_region (const cairo_clip_t *clip) +{ + int i; + + if (clip->is_region) + return TRUE; + + if (clip->path) + return FALSE; + + for (i = 0; i < clip->num_boxes; i++) { + const cairo_box_t *b = &clip->boxes[i]; + if (!_cairo_fixed_is_integer (b->p1.x | b->p1.y | b->p2.x | b->p2.y)) + return FALSE; + } + + return TRUE; +} + +static cairo_int_status_t +composite_aligned_boxes (const cairo_spans_compositor_t *compositor, + const cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + cairo_operator_t op = extents->op; + const cairo_pattern_t *source = &extents->source_pattern.base; + cairo_int_status_t status; + cairo_bool_t need_clip_mask = ! _clip_is_region (extents->clip); + cairo_bool_t op_is_source; + cairo_bool_t no_mask; + cairo_bool_t inplace; + + TRACE ((stderr, "%s: need_clip_mask=%d, is-bounded=%d\n", + __FUNCTION__, need_clip_mask, extents->is_bounded)); + if (need_clip_mask && ! extents->is_bounded) { + TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + no_mask = extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && + CAIRO_COLOR_IS_OPAQUE (&extents->mask_pattern.solid.color); + op_is_source = op_reduces_to_source (extents, no_mask); + inplace = ! need_clip_mask && op_is_source && no_mask; + + TRACE ((stderr, "%s: op-is-source=%d [op=%d], no-mask=%d, inplace=%d\n", + __FUNCTION__, op_is_source, op, no_mask, inplace)); + + if (op == CAIRO_OPERATOR_SOURCE && (need_clip_mask || ! no_mask)) { + /* SOURCE with a mask is actually a LERP in cairo semantics */ + if ((compositor->flags & CAIRO_SPANS_COMPOSITOR_HAS_LERP) == 0) { + TRACE ((stderr, "%s: unsupported lerp\n", __FUNCTION__)); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + + /* Are we just copying a recording surface? */ + if (inplace && + recording_pattern_contains_sample (&extents->source_pattern.base, + &extents->source_sample_area)) + { + cairo_clip_t *recording_clip; + const cairo_pattern_t *source = &extents->source_pattern.base; + const cairo_matrix_t *m; + cairo_matrix_t matrix; + + /* XXX could also do tiling repeat modes... */ + + /* first clear the area about to be overwritten */ + if (! dst->is_clear) { + status = compositor->fill_boxes (dst, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + boxes); + if (unlikely (status)) + return status; + + dst->is_clear = TRUE; + } + + m = &source->matrix; + if (_cairo_surface_has_device_transform (dst)) { + cairo_matrix_multiply (&matrix, + &source->matrix, + &dst->device_transform); + m = &matrix; + } + + recording_clip = _cairo_clip_from_boxes (boxes); + status = _cairo_recording_surface_replay_with_clip (unwrap_source (source), + m, dst, recording_clip); + _cairo_clip_destroy (recording_clip); + + return status; + } + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (! need_clip_mask && no_mask && source->type == CAIRO_PATTERN_TYPE_SOLID) { + const cairo_color_t *color; + + color = &((cairo_solid_pattern_t *) source)->color; + if (op_is_source) + op = CAIRO_OPERATOR_SOURCE; + status = compositor->fill_boxes (dst, op, color, boxes); + } else if (inplace && source->type == CAIRO_PATTERN_TYPE_SURFACE) { + status = upload_boxes (compositor, extents, boxes); + } + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_surface_t *src; + cairo_surface_t *mask = NULL; + int src_x, src_y; + int mask_x = 0, mask_y = 0; + + /* All typical cases will have been resolved before now... */ + if (need_clip_mask) { + mask = get_clip_surface (compositor, dst, extents->clip, + &extents->bounded); + if (unlikely (mask->status)) + return mask->status; + + mask_x = -extents->bounded.x; + mask_y = -extents->bounded.y; + } + + /* XXX but this is still ugly */ + if (! no_mask) { + src = compositor->pattern_to_surface (dst, + &extents->mask_pattern.base, + TRUE, + &extents->bounded, + &extents->mask_sample_area, + &src_x, &src_y); + if (unlikely (src->status)) { + cairo_surface_destroy (mask); + return src->status; + } + + if (mask != NULL) { + status = compositor->composite_boxes (mask, CAIRO_OPERATOR_IN, + src, NULL, + src_x, src_y, + 0, 0, + mask_x, mask_y, + boxes, &extents->bounded); + + cairo_surface_destroy (src); + } else { + mask = src; + mask_x = src_x; + mask_y = src_y; + } + } + + src = compositor->pattern_to_surface (dst, source, FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (likely (src->status == CAIRO_STATUS_SUCCESS)) { + status = compositor->composite_boxes (dst, op, src, mask, + src_x, src_y, + mask_x, mask_y, + 0, 0, + boxes, &extents->bounded); + cairo_surface_destroy (src); + } else + status = src->status; + + cairo_surface_destroy (mask); + } + + if (status == CAIRO_INT_STATUS_SUCCESS && ! extents->is_bounded) + status = fixup_unbounded_boxes (compositor, extents, boxes); + + return status; +} + +static cairo_bool_t +composite_needs_clip (const cairo_composite_rectangles_t *composite, + const cairo_box_t *extents) +{ + return !_cairo_clip_contains_box (composite->clip, extents); +} + +static cairo_int_status_t +composite_boxes (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_abstract_span_renderer_t renderer; + cairo_rectangular_scan_converter_t converter; + const struct _cairo_boxes_chunk *chunk; + cairo_int_status_t status; + cairo_box_t box; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + _cairo_box_from_rectangle (&box, &extents->unbounded); + if (composite_needs_clip (extents, &box)) { + TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + _cairo_rectangular_scan_converter_init (&converter, &extents->unbounded); + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box = chunk->base; + int i; + + for (i = 0; i < chunk->count; i++) { + status = _cairo_rectangular_scan_converter_add_box (&converter, &box[i], 1); + if (unlikely (status)) + goto cleanup_converter; + } + } + + status = compositor->renderer_init (&renderer, extents, + CAIRO_ANTIALIAS_DEFAULT, FALSE); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = converter.base.generate (&converter.base, &renderer.base); + compositor->renderer_fini (&renderer, status); + +cleanup_converter: + converter.base.destroy (&converter.base); + return status; +} + +static cairo_int_status_t +composite_polygon (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias) +{ + cairo_abstract_span_renderer_t renderer; + cairo_scan_converter_t *converter; + cairo_bool_t needs_clip; + cairo_int_status_t status; + + if (extents->is_bounded) + needs_clip = extents->clip->path != NULL; + else + needs_clip = !_clip_is_region (extents->clip) || extents->clip->num_boxes > 1; + TRACE ((stderr, "%s - needs_clip=%d\n", __FUNCTION__, needs_clip)); + if (needs_clip) { + TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); + return CAIRO_INT_STATUS_UNSUPPORTED; + converter = _cairo_clip_tor_scan_converter_create (extents->clip, + polygon, + fill_rule, antialias); + } else { + const cairo_rectangle_int_t *r = &extents->unbounded; + + if (antialias == CAIRO_ANTIALIAS_FAST) { + converter = _cairo_tor22_scan_converter_create (r->x, r->y, + r->x + r->width, + r->y + r->height, + fill_rule, antialias); + status = _cairo_tor22_scan_converter_add_polygon (converter, polygon); + } else if (antialias == CAIRO_ANTIALIAS_NONE) { + converter = _cairo_mono_scan_converter_create (r->x, r->y, + r->x + r->width, + r->y + r->height, + fill_rule); + status = _cairo_mono_scan_converter_add_polygon (converter, polygon); + } else { + converter = _cairo_tor_scan_converter_create (r->x, r->y, + r->x + r->width, + r->y + r->height, + fill_rule, antialias); + status = _cairo_tor_scan_converter_add_polygon (converter, polygon); + } + } + if (unlikely (status)) + goto cleanup_converter; + + status = compositor->renderer_init (&renderer, extents, + antialias, needs_clip); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = converter->generate (converter, &renderer.base); + compositor->renderer_fini (&renderer, status); + +cleanup_converter: + converter->destroy (converter); + return status; +} + +static cairo_int_status_t +trim_extents_to_boxes (cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_box_t box; + + _cairo_boxes_extents (boxes, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_int_status_t +trim_extents_to_polygon (cairo_composite_rectangles_t *extents, + cairo_polygon_t *polygon) +{ + return _cairo_composite_rectangles_intersect_mask_extents (extents, + &polygon->extents); +} + +static cairo_int_status_t +clip_and_composite_boxes (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_int_status_t status; + cairo_polygon_t polygon; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + status = trim_extents_to_boxes (extents, boxes); + if (unlikely (status)) + return status; + + if (boxes->num_boxes == 0) { + if (extents->is_bounded) + return CAIRO_STATUS_SUCCESS; + + return fixup_unbounded_boxes (compositor, extents, boxes); + } + + /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ + if (extents->clip->path != NULL && extents->is_bounded) { + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + cairo_clip_t *clip; + + clip = _cairo_clip_copy (extents->clip); + clip = _cairo_clip_intersect_boxes (clip, boxes); + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + status = _cairo_clip_get_polygon (clip, &polygon, + &fill_rule, &antialias); + _cairo_clip_path_destroy (clip->path); + clip->path = NULL; + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t *saved_clip = extents->clip; + extents->clip = clip; + + status = clip_and_composite_polygon (compositor, extents, &polygon, + fill_rule, antialias); + + clip = extents->clip; + extents->clip = saved_clip; + + _cairo_polygon_fini (&polygon); + } + _cairo_clip_destroy (clip); + + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + if (boxes->is_pixel_aligned) { + status = composite_aligned_boxes (compositor, extents, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + status = composite_boxes (compositor, extents, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_polygon_init_boxes (&polygon, boxes); + if (unlikely (status)) + return status; + + status = composite_polygon (compositor, extents, &polygon, + CAIRO_FILL_RULE_WINDING, + CAIRO_ANTIALIAS_DEFAULT); + _cairo_polygon_fini (&polygon); + + return status; +} + +static cairo_int_status_t +clip_and_composite_polygon (const cairo_spans_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + /* XXX simply uses polygon limits.point extemities, tessellation? */ + status = trim_extents_to_polygon (extents, polygon); + if (unlikely (status)) + return status; + + if (_cairo_polygon_is_empty (polygon)) { + cairo_boxes_t boxes; + + if (extents->is_bounded) + return CAIRO_STATUS_SUCCESS; + + _cairo_boxes_init (&boxes); + extents->bounded.width = extents->bounded.height = 0; + return fixup_unbounded_boxes (compositor, extents, &boxes); + } + + if (extents->is_bounded && extents->clip->path) { + cairo_polygon_t clipper; + cairo_antialias_t clip_antialias; + cairo_fill_rule_t clip_fill_rule; + + TRACE((stderr, "%s - combining shape with clip polygon\n", + __FUNCTION__)); + + status = _cairo_clip_get_polygon (extents->clip, + &clipper, + &clip_fill_rule, + &clip_antialias); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t *old_clip; + + if (clip_antialias == antialias) { + status = _cairo_polygon_intersect (polygon, fill_rule, + &clipper, clip_fill_rule); + _cairo_polygon_fini (&clipper); + if (unlikely (status)) + return status; + + old_clip = extents->clip; + extents->clip = _cairo_clip_copy_region (extents->clip); + _cairo_clip_destroy (old_clip); + + status = trim_extents_to_polygon (extents, polygon); + if (unlikely (status)) + return status; + + fill_rule = CAIRO_FILL_RULE_WINDING; + } else { + _cairo_polygon_fini (&clipper); + } + } + } + + return composite_polygon (compositor, extents, + polygon, fill_rule, antialias); +} + +/* high-level compositor interface */ + +static cairo_int_status_t +_cairo_spans_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; + cairo_boxes_t boxes; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + _cairo_clip_steal_boxes (extents->clip, &boxes); + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_clip_unsteal_boxes (extents->clip, &boxes); + + return status; +} + +static cairo_int_status_t +_cairo_spans_compositor_mask (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; + cairo_int_status_t status; + cairo_boxes_t boxes; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + _cairo_clip_steal_boxes (extents->clip, &boxes); + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_clip_unsteal_boxes (extents->clip, &boxes); + + return status; +} + +static cairo_int_status_t +_cairo_spans_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + TRACE_ (_cairo_debug_print_path (stderr, path)); + TRACE_ (_cairo_debug_print_clip (stderr, extents->clip)); + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_stroke_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init (&boxes); + if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) + _cairo_boxes_limit (&boxes, + extents->clip->boxes, + extents->clip->num_boxes); + + status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, + style, + ctm, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule = CAIRO_FILL_RULE_WINDING; + + if (! _cairo_rectangle_contains_rectangle (&extents->unbounded, + &extents->mask)) + { + if (extents->clip->num_boxes == 1) { + _cairo_polygon_init (&polygon, extents->clip->boxes, 1); + } else { + cairo_box_t limits; + _cairo_box_from_rectangle (&limits, &extents->unbounded); + _cairo_polygon_init (&polygon, &limits, 1); + } + } + else + { + _cairo_polygon_init (&polygon, NULL, 0); + } + status = _cairo_path_fixed_stroke_to_polygon (path, + style, + ctm, ctm_inverse, + tolerance, + &polygon); + TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); + polygon.num_limits = 0; + + if (status == CAIRO_INT_STATUS_SUCCESS && extents->clip->num_boxes > 1) { + status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, + extents->clip->boxes, + extents->clip->num_boxes); + } + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t *saved_clip = extents->clip; + + if (extents->is_bounded) { + extents->clip = _cairo_clip_copy_path (extents->clip); + extents->clip = _cairo_clip_intersect_box(extents->clip, + &polygon.extents); + } + + status = clip_and_composite_polygon (compositor, extents, &polygon, + fill_rule, antialias); + + if (extents->is_bounded) { + _cairo_clip_destroy (extents->clip); + extents->clip = saved_clip; + } + } + _cairo_polygon_fini (&polygon); + } + + return status; +} + +static cairo_int_status_t +_cairo_spans_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; + cairo_int_status_t status; + + TRACE((stderr, "%s op=%d, antialias=%d\n", __FUNCTION__, extents->op, antialias)); + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_fill_is_rectilinear (path)) { + cairo_boxes_t boxes; + + TRACE((stderr, "%s - rectilinear\n", __FUNCTION__)); + + _cairo_boxes_init (&boxes); + if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) + _cairo_boxes_limit (&boxes, + extents->clip->boxes, + extents->clip->num_boxes); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + fill_rule, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_boxes_fini (&boxes); + } + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_polygon_t polygon; + + TRACE((stderr, "%s - polygon\n", __FUNCTION__)); + + if (! _cairo_rectangle_contains_rectangle (&extents->unbounded, + &extents->mask)) + { + TRACE((stderr, "%s - clipping to bounds\n", __FUNCTION__)); + if (extents->clip->num_boxes == 1) { + _cairo_polygon_init (&polygon, extents->clip->boxes, 1); + } else { + cairo_box_t limits; + _cairo_box_from_rectangle (&limits, &extents->unbounded); + _cairo_polygon_init (&polygon, &limits, 1); + } + } + else + { + _cairo_polygon_init (&polygon, NULL, 0); + } + + status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); + TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); + polygon.num_limits = 0; + + if (status == CAIRO_INT_STATUS_SUCCESS && extents->clip->num_boxes > 1) { + TRACE((stderr, "%s - polygon intersect with %d clip boxes\n", + __FUNCTION__, extents->clip->num_boxes)); + status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, + extents->clip->boxes, + extents->clip->num_boxes); + } + TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t *saved_clip = extents->clip; + + if (extents->is_bounded) { + TRACE((stderr, "%s - polygon discard clip boxes\n", + __FUNCTION__)); + extents->clip = _cairo_clip_copy_path (extents->clip); + extents->clip = _cairo_clip_intersect_box(extents->clip, + &polygon.extents); + } + + status = clip_and_composite_polygon (compositor, extents, &polygon, + fill_rule, antialias); + + if (extents->is_bounded) { + _cairo_clip_destroy (extents->clip); + extents->clip = saved_clip; + } + } + _cairo_polygon_fini (&polygon); + + TRACE((stderr, "%s - polygon status=%d\n", __FUNCTION__, status)); + } + + return status; +} + +void +_cairo_spans_compositor_init (cairo_spans_compositor_t *compositor, + const cairo_compositor_t *delegate) +{ + compositor->base.delegate = delegate; + + compositor->base.paint = _cairo_spans_compositor_paint; + compositor->base.mask = _cairo_spans_compositor_mask; + compositor->base.fill = _cairo_spans_compositor_fill; + compositor->base.stroke = _cairo_spans_compositor_stroke; + compositor->base.glyphs = NULL; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-spans-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-spans-private.h new file mode 100644 index 00000000000..b158f4d360a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-spans-private.h @@ -0,0 +1,206 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright (c) 2008 M Joonas Pihlaja + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef CAIRO_SPANS_PRIVATE_H +#define CAIRO_SPANS_PRIVATE_H +#include "cairo-types-private.h" +#include "cairo-compiler-private.h" + +/* Number of bits of precision used for alpha. */ +#define CAIRO_SPANS_UNIT_COVERAGE_BITS 8 +#define CAIRO_SPANS_UNIT_COVERAGE ((1 << CAIRO_SPANS_UNIT_COVERAGE_BITS)-1) + +/* A structure representing an open-ended horizontal span of constant + * pixel coverage. */ +typedef struct _cairo_half_open_span { + int32_t x; /* The inclusive x-coordinate of the start of the span. */ + uint8_t coverage; /* The pixel coverage for the pixels to the right. */ + uint8_t inverse; /* between regular mask and clip */ +} cairo_half_open_span_t; + +/* Span renderer interface. Instances of renderers are provided by + * surfaces if they want to composite spans instead of trapezoids. */ +typedef struct _cairo_span_renderer cairo_span_renderer_t; +struct _cairo_span_renderer { + /* Private status variable. */ + cairo_status_t status; + + /* Called to destroy the renderer. */ + cairo_destroy_func_t destroy; + + /* Render the spans on row y of the destination by whatever compositing + * method is required. */ + cairo_status_t + (*render_rows) (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *coverages, + unsigned num_coverages); + + /* Called after all rows have been rendered to perform whatever + * final rendering step is required. This function is called just + * once before the renderer is destroyed. */ + cairo_status_t (*finish) (void *abstract_renderer); +}; + +/* Scan converter interface. */ +typedef struct _cairo_scan_converter cairo_scan_converter_t; +struct _cairo_scan_converter { + /* Destroy this scan converter. */ + cairo_destroy_func_t destroy; + + /* Generates coverage spans for rows for the added edges and calls + * the renderer function for each row. After generating spans the + * only valid thing to do with the converter is to destroy it. */ + cairo_status_t (*generate) (void *abstract_converter, + cairo_span_renderer_t *renderer); + + /* Private status. Read with _cairo_scan_converter_status(). */ + cairo_status_t status; +}; + +/* Scan converter constructors. */ + +cairo_private cairo_scan_converter_t * +_cairo_tor_scan_converter_create (int xmin, + int ymin, + int xmax, + int ymax, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias); +cairo_private cairo_status_t +_cairo_tor_scan_converter_add_polygon (void *converter, + const cairo_polygon_t *polygon); + +cairo_private cairo_scan_converter_t * +_cairo_tor22_scan_converter_create (int xmin, + int ymin, + int xmax, + int ymax, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias); +cairo_private cairo_status_t +_cairo_tor22_scan_converter_add_polygon (void *converter, + const cairo_polygon_t *polygon); + +cairo_private cairo_scan_converter_t * +_cairo_mono_scan_converter_create (int xmin, + int ymin, + int xmax, + int ymax, + cairo_fill_rule_t fill_rule); +cairo_private cairo_status_t +_cairo_mono_scan_converter_add_polygon (void *converter, + const cairo_polygon_t *polygon); + +cairo_private cairo_scan_converter_t * +_cairo_clip_tor_scan_converter_create (cairo_clip_t *clip, + cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias); + +typedef struct _cairo_rectangular_scan_converter { + cairo_scan_converter_t base; + + cairo_box_t extents; + + struct _cairo_rectangular_scan_converter_chunk { + struct _cairo_rectangular_scan_converter_chunk *next; + void *base; + int count; + int size; + } chunks, *tail; + char buf[CAIRO_STACK_BUFFER_SIZE]; + int num_rectangles; +} cairo_rectangular_scan_converter_t; + +cairo_private void +_cairo_rectangular_scan_converter_init (cairo_rectangular_scan_converter_t *self, + const cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_rectangular_scan_converter_add_box (cairo_rectangular_scan_converter_t *self, + const cairo_box_t *box, + int dir); + +typedef struct _cairo_botor_scan_converter { + cairo_scan_converter_t base; + + cairo_box_t extents; + cairo_fill_rule_t fill_rule; + + int xmin, xmax; + + struct _cairo_botor_scan_converter_chunk { + struct _cairo_botor_scan_converter_chunk *next; + void *base; + int count; + int size; + } chunks, *tail; + char buf[CAIRO_STACK_BUFFER_SIZE]; + int num_edges; +} cairo_botor_scan_converter_t; + +cairo_private void +_cairo_botor_scan_converter_init (cairo_botor_scan_converter_t *self, + const cairo_box_t *extents, + cairo_fill_rule_t fill_rule); + +/* cairo-spans.c: */ + +cairo_private cairo_scan_converter_t * +_cairo_scan_converter_create_in_error (cairo_status_t error); + +cairo_private cairo_status_t +_cairo_scan_converter_status (void *abstract_converter); + +cairo_private cairo_status_t +_cairo_scan_converter_set_error (void *abstract_converter, + cairo_status_t error); + +cairo_private cairo_span_renderer_t * +_cairo_span_renderer_create_in_error (cairo_status_t error); + +cairo_private cairo_status_t +_cairo_span_renderer_status (void *abstract_renderer); + +/* Set the renderer into an error state. This sets all the method + * pointers except ->destroy() of the renderer to no-op + * implementations that just return the error status. */ +cairo_private cairo_status_t +_cairo_span_renderer_set_error (void *abstract_renderer, + cairo_status_t error); + +cairo_private cairo_status_t +_cairo_surface_composite_polygon (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias, + const cairo_composite_rectangles_t *rects, + cairo_polygon_t *polygon, + cairo_region_t *clip_region); + +#endif /* CAIRO_SPANS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-spans.c b/Build/source/libs/cairo/cairo-src/src/cairo-spans.c new file mode 100644 index 00000000000..182390c205a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-spans.c @@ -0,0 +1,250 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright (c) 2008 M Joonas Pihlaja + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#include "cairoint.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-clip-private.h" +#include "cairo-error-private.h" +#include "cairo-fixed-private.h" +#include "cairo-types-private.h" + +static void +_cairo_nil_destroy (void *abstract) +{ + (void) abstract; +} + +static cairo_status_t +_cairo_nil_scan_converter_generate (void *abstract_converter, + cairo_span_renderer_t *renderer) +{ + (void) abstract_converter; + (void) renderer; + return _cairo_scan_converter_status (abstract_converter); +} + +cairo_status_t +_cairo_scan_converter_status (void *abstract_converter) +{ + cairo_scan_converter_t *converter = abstract_converter; + return converter->status; +} + +cairo_status_t +_cairo_scan_converter_set_error (void *abstract_converter, + cairo_status_t error) +{ + cairo_scan_converter_t *converter = abstract_converter; + if (error == CAIRO_STATUS_SUCCESS) + ASSERT_NOT_REACHED; + if (converter->status == CAIRO_STATUS_SUCCESS) { + converter->generate = _cairo_nil_scan_converter_generate; + converter->status = error; + } + return converter->status; +} + +static void +_cairo_nil_scan_converter_init (cairo_scan_converter_t *converter, + cairo_status_t status) +{ + converter->destroy = _cairo_nil_destroy; + converter->status = CAIRO_STATUS_SUCCESS; + status = _cairo_scan_converter_set_error (converter, status); +} + +cairo_scan_converter_t * +_cairo_scan_converter_create_in_error (cairo_status_t status) +{ +#define RETURN_NIL {\ + static cairo_scan_converter_t nil;\ + _cairo_nil_scan_converter_init (&nil, status);\ + return &nil;\ + } + switch (status) { + case CAIRO_STATUS_SUCCESS: + case CAIRO_STATUS_LAST_STATUS: + ASSERT_NOT_REACHED; + break; + case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL; + case CAIRO_STATUS_INVALID_POP_GROUP: RETURN_NIL; + case CAIRO_STATUS_NO_CURRENT_POINT: RETURN_NIL; + case CAIRO_STATUS_INVALID_MATRIX: RETURN_NIL; + case CAIRO_STATUS_INVALID_STATUS: RETURN_NIL; + case CAIRO_STATUS_NULL_POINTER: RETURN_NIL; + case CAIRO_STATUS_INVALID_STRING: RETURN_NIL; + case CAIRO_STATUS_INVALID_PATH_DATA: RETURN_NIL; + case CAIRO_STATUS_READ_ERROR: RETURN_NIL; + case CAIRO_STATUS_WRITE_ERROR: RETURN_NIL; + case CAIRO_STATUS_SURFACE_FINISHED: RETURN_NIL; + case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_INVALID_CONTENT: RETURN_NIL; + case CAIRO_STATUS_INVALID_FORMAT: RETURN_NIL; + case CAIRO_STATUS_INVALID_VISUAL: RETURN_NIL; + case CAIRO_STATUS_FILE_NOT_FOUND: RETURN_NIL; + case CAIRO_STATUS_INVALID_DASH: RETURN_NIL; + case CAIRO_STATUS_INVALID_DSC_COMMENT: RETURN_NIL; + case CAIRO_STATUS_INVALID_INDEX: RETURN_NIL; + case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: RETURN_NIL; + case CAIRO_STATUS_TEMP_FILE_ERROR: RETURN_NIL; + case CAIRO_STATUS_INVALID_STRIDE: RETURN_NIL; + case CAIRO_STATUS_FONT_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_USER_FONT_IMMUTABLE: RETURN_NIL; + case CAIRO_STATUS_USER_FONT_ERROR: RETURN_NIL; + case CAIRO_STATUS_NEGATIVE_COUNT: RETURN_NIL; + case CAIRO_STATUS_INVALID_CLUSTERS: RETURN_NIL; + case CAIRO_STATUS_INVALID_SLANT: RETURN_NIL; + case CAIRO_STATUS_INVALID_WEIGHT: RETURN_NIL; + case CAIRO_STATUS_NO_MEMORY: RETURN_NIL; + case CAIRO_STATUS_INVALID_SIZE: RETURN_NIL; + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: RETURN_NIL; + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_DEVICE_ERROR: RETURN_NIL; + case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: RETURN_NIL; + case CAIRO_STATUS_DEVICE_FINISHED: RETURN_NIL; + case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: + default: + break; + } + status = CAIRO_STATUS_NO_MEMORY; + RETURN_NIL; +#undef RETURN_NIL +} + +static cairo_status_t +_cairo_nil_span_renderer_render_rows ( + void *abstract_renderer, + int y, + int height, + const cairo_half_open_span_t *coverages, + unsigned num_coverages) +{ + (void) y; + (void) height; + (void) coverages; + (void) num_coverages; + return _cairo_span_renderer_status (abstract_renderer); +} + +static cairo_status_t +_cairo_nil_span_renderer_finish (void *abstract_renderer) +{ + return _cairo_span_renderer_status (abstract_renderer); +} + +cairo_status_t +_cairo_span_renderer_status (void *abstract_renderer) +{ + cairo_span_renderer_t *renderer = abstract_renderer; + return renderer->status; +} + +cairo_status_t +_cairo_span_renderer_set_error ( + void *abstract_renderer, + cairo_status_t error) +{ + cairo_span_renderer_t *renderer = abstract_renderer; + if (error == CAIRO_STATUS_SUCCESS) { + ASSERT_NOT_REACHED; + } + if (renderer->status == CAIRO_STATUS_SUCCESS) { + renderer->render_rows = _cairo_nil_span_renderer_render_rows; + renderer->finish = _cairo_nil_span_renderer_finish; + renderer->status = error; + } + return renderer->status; +} + +static void +_cairo_nil_span_renderer_init (cairo_span_renderer_t *renderer, + cairo_status_t status) +{ + renderer->destroy = _cairo_nil_destroy; + renderer->status = CAIRO_STATUS_SUCCESS; + status = _cairo_span_renderer_set_error (renderer, status); +} + +cairo_span_renderer_t * +_cairo_span_renderer_create_in_error (cairo_status_t status) +{ +#define RETURN_NIL {\ + static cairo_span_renderer_t nil;\ + _cairo_nil_span_renderer_init (&nil, status);\ + return &nil;\ + } + switch (status) { + case CAIRO_STATUS_SUCCESS: + case CAIRO_STATUS_LAST_STATUS: + ASSERT_NOT_REACHED; + break; + case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL; + case CAIRO_STATUS_INVALID_POP_GROUP: RETURN_NIL; + case CAIRO_STATUS_NO_CURRENT_POINT: RETURN_NIL; + case CAIRO_STATUS_INVALID_MATRIX: RETURN_NIL; + case CAIRO_STATUS_INVALID_STATUS: RETURN_NIL; + case CAIRO_STATUS_NULL_POINTER: RETURN_NIL; + case CAIRO_STATUS_INVALID_STRING: RETURN_NIL; + case CAIRO_STATUS_INVALID_PATH_DATA: RETURN_NIL; + case CAIRO_STATUS_READ_ERROR: RETURN_NIL; + case CAIRO_STATUS_WRITE_ERROR: RETURN_NIL; + case CAIRO_STATUS_SURFACE_FINISHED: RETURN_NIL; + case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_INVALID_CONTENT: RETURN_NIL; + case CAIRO_STATUS_INVALID_FORMAT: RETURN_NIL; + case CAIRO_STATUS_INVALID_VISUAL: RETURN_NIL; + case CAIRO_STATUS_FILE_NOT_FOUND: RETURN_NIL; + case CAIRO_STATUS_INVALID_DASH: RETURN_NIL; + case CAIRO_STATUS_INVALID_DSC_COMMENT: RETURN_NIL; + case CAIRO_STATUS_INVALID_INDEX: RETURN_NIL; + case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: RETURN_NIL; + case CAIRO_STATUS_TEMP_FILE_ERROR: RETURN_NIL; + case CAIRO_STATUS_INVALID_STRIDE: RETURN_NIL; + case CAIRO_STATUS_FONT_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_USER_FONT_IMMUTABLE: RETURN_NIL; + case CAIRO_STATUS_USER_FONT_ERROR: RETURN_NIL; + case CAIRO_STATUS_NEGATIVE_COUNT: RETURN_NIL; + case CAIRO_STATUS_INVALID_CLUSTERS: RETURN_NIL; + case CAIRO_STATUS_INVALID_SLANT: RETURN_NIL; + case CAIRO_STATUS_INVALID_WEIGHT: RETURN_NIL; + case CAIRO_STATUS_NO_MEMORY: RETURN_NIL; + case CAIRO_STATUS_INVALID_SIZE: RETURN_NIL; + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: RETURN_NIL; + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: RETURN_NIL; + case CAIRO_STATUS_DEVICE_ERROR: RETURN_NIL; + case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: RETURN_NIL; + case CAIRO_STATUS_DEVICE_FINISHED: RETURN_NIL; + case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: RETURN_NIL; + default: + break; + } + status = CAIRO_STATUS_NO_MEMORY; + RETURN_NIL; +#undef RETURN_NIL +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-spline.c b/Build/source/libs/cairo/cairo-src/src/cairo-spline.c new file mode 100644 index 00000000000..44634faec85 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-spline.c @@ -0,0 +1,424 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-slope-private.h" + +cairo_bool_t +_cairo_spline_intersects (const cairo_point_t *a, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d, + const cairo_box_t *box) +{ + cairo_box_t bounds; + + if (_cairo_box_contains_point (box, a) || + _cairo_box_contains_point (box, b) || + _cairo_box_contains_point (box, c) || + _cairo_box_contains_point (box, d)) + { + return TRUE; + } + + bounds.p2 = bounds.p1 = *a; + _cairo_box_add_point (&bounds, b); + _cairo_box_add_point (&bounds, c); + _cairo_box_add_point (&bounds, d); + + if (bounds.p2.x <= box->p1.x || bounds.p1.x >= box->p2.x || + bounds.p2.y <= box->p1.y || bounds.p1.y >= box->p2.y) + { + return FALSE; + } + +#if 0 /* worth refining? */ + bounds.p2 = bounds.p1 = *a; + _cairo_box_add_curve_to (&bounds, b, c, d); + if (bounds.p2.x <= box->p1.x || bounds.p1.x >= box->p2.x || + bounds.p2.y <= box->p1.y || bounds.p1.y >= box->p2.y) + { + return FALSE; + } +#endif + + return TRUE; +} + +cairo_bool_t +_cairo_spline_init (cairo_spline_t *spline, + cairo_spline_add_point_func_t add_point_func, + void *closure, + const cairo_point_t *a, const cairo_point_t *b, + const cairo_point_t *c, const cairo_point_t *d) +{ + /* If both tangents are zero, this is just a straight line */ + if (a->x == b->x && a->y == b->y && c->x == d->x && c->y == d->y) + return FALSE; + + spline->add_point_func = add_point_func; + spline->closure = closure; + + spline->knots.a = *a; + spline->knots.b = *b; + spline->knots.c = *c; + spline->knots.d = *d; + + if (a->x != b->x || a->y != b->y) + _cairo_slope_init (&spline->initial_slope, &spline->knots.a, &spline->knots.b); + else if (a->x != c->x || a->y != c->y) + _cairo_slope_init (&spline->initial_slope, &spline->knots.a, &spline->knots.c); + else if (a->x != d->x || a->y != d->y) + _cairo_slope_init (&spline->initial_slope, &spline->knots.a, &spline->knots.d); + else + return FALSE; + + if (c->x != d->x || c->y != d->y) + _cairo_slope_init (&spline->final_slope, &spline->knots.c, &spline->knots.d); + else if (b->x != d->x || b->y != d->y) + _cairo_slope_init (&spline->final_slope, &spline->knots.b, &spline->knots.d); + else + return FALSE; /* just treat this as a straight-line from a -> d */ + + /* XXX if the initial, final and vector are all equal, this is just a line */ + + return TRUE; +} + +static cairo_status_t +_cairo_spline_add_point (cairo_spline_t *spline, + const cairo_point_t *point, + const cairo_point_t *knot) +{ + cairo_point_t *prev; + cairo_slope_t slope; + + prev = &spline->last_point; + if (prev->x == point->x && prev->y == point->y) + return CAIRO_STATUS_SUCCESS; + + _cairo_slope_init (&slope, point, knot); + + spline->last_point = *point; + return spline->add_point_func (spline->closure, point, &slope); +} + +static void +_lerp_half (const cairo_point_t *a, const cairo_point_t *b, cairo_point_t *result) +{ + result->x = a->x + ((b->x - a->x) >> 1); + result->y = a->y + ((b->y - a->y) >> 1); +} + +static void +_de_casteljau (cairo_spline_knots_t *s1, cairo_spline_knots_t *s2) +{ + cairo_point_t ab, bc, cd; + cairo_point_t abbc, bccd; + cairo_point_t final; + + _lerp_half (&s1->a, &s1->b, &ab); + _lerp_half (&s1->b, &s1->c, &bc); + _lerp_half (&s1->c, &s1->d, &cd); + _lerp_half (&ab, &bc, &abbc); + _lerp_half (&bc, &cd, &bccd); + _lerp_half (&abbc, &bccd, &final); + + s2->a = final; + s2->b = bccd; + s2->c = cd; + s2->d = s1->d; + + s1->b = ab; + s1->c = abbc; + s1->d = final; +} + +/* Return an upper bound on the error (squared) that could result from + * approximating a spline as a line segment connecting the two endpoints. */ +static double +_cairo_spline_error_squared (const cairo_spline_knots_t *knots) +{ + double bdx, bdy, berr; + double cdx, cdy, cerr; + + /* We are going to compute the distance (squared) between each of the the b + * and c control points and the segment a-b. The maximum of these two + * distances will be our approximation error. */ + + bdx = _cairo_fixed_to_double (knots->b.x - knots->a.x); + bdy = _cairo_fixed_to_double (knots->b.y - knots->a.y); + + cdx = _cairo_fixed_to_double (knots->c.x - knots->a.x); + cdy = _cairo_fixed_to_double (knots->c.y - knots->a.y); + + if (knots->a.x != knots->d.x || knots->a.y != knots->d.y) { + /* Intersection point (px): + * px = p1 + u(p2 - p1) + * (p - px) ∙ (p2 - p1) = 0 + * Thus: + * u = ((p - p1) ∙ (p2 - p1)) / ∥p2 - p1∥²; + */ + + double dx, dy, u, v; + + dx = _cairo_fixed_to_double (knots->d.x - knots->a.x); + dy = _cairo_fixed_to_double (knots->d.y - knots->a.y); + v = dx * dx + dy * dy; + + u = bdx * dx + bdy * dy; + if (u <= 0) { + /* bdx -= 0; + * bdy -= 0; + */ + } else if (u >= v) { + bdx -= dx; + bdy -= dy; + } else { + bdx -= u/v * dx; + bdy -= u/v * dy; + } + + u = cdx * dx + cdy * dy; + if (u <= 0) { + /* cdx -= 0; + * cdy -= 0; + */ + } else if (u >= v) { + cdx -= dx; + cdy -= dy; + } else { + cdx -= u/v * dx; + cdy -= u/v * dy; + } + } + + berr = bdx * bdx + bdy * bdy; + cerr = cdx * cdx + cdy * cdy; + if (berr > cerr) + return berr; + else + return cerr; +} + +static cairo_status_t +_cairo_spline_decompose_into (cairo_spline_knots_t *s1, + double tolerance_squared, + cairo_spline_t *result) +{ + cairo_spline_knots_t s2; + cairo_status_t status; + + if (_cairo_spline_error_squared (s1) < tolerance_squared) + return _cairo_spline_add_point (result, &s1->a, &s1->b); + + _de_casteljau (s1, &s2); + + status = _cairo_spline_decompose_into (s1, tolerance_squared, result); + if (unlikely (status)) + return status; + + return _cairo_spline_decompose_into (&s2, tolerance_squared, result); +} + +cairo_status_t +_cairo_spline_decompose (cairo_spline_t *spline, double tolerance) +{ + cairo_spline_knots_t s1; + cairo_status_t status; + + s1 = spline->knots; + spline->last_point = s1.a; + status = _cairo_spline_decompose_into (&s1, tolerance * tolerance, spline); + if (unlikely (status)) + return status; + + return spline->add_point_func (spline->closure, + &spline->knots.d, &spline->final_slope); +} + +/* Note: this function is only good for computing bounds in device space. */ +cairo_status_t +_cairo_spline_bound (cairo_spline_add_point_func_t add_point_func, + void *closure, + const cairo_point_t *p0, const cairo_point_t *p1, + const cairo_point_t *p2, const cairo_point_t *p3) +{ + double x0, x1, x2, x3; + double y0, y1, y2, y3; + double a, b, c; + double t[4]; + int t_num = 0, i; + cairo_status_t status; + + x0 = _cairo_fixed_to_double (p0->x); + y0 = _cairo_fixed_to_double (p0->y); + x1 = _cairo_fixed_to_double (p1->x); + y1 = _cairo_fixed_to_double (p1->y); + x2 = _cairo_fixed_to_double (p2->x); + y2 = _cairo_fixed_to_double (p2->y); + x3 = _cairo_fixed_to_double (p3->x); + y3 = _cairo_fixed_to_double (p3->y); + + /* The spline can be written as a polynomial of the four points: + * + * (1-t)³p0 + 3t(1-t)²p1 + 3t²(1-t)p2 + t³p3 + * + * for 0≤t≤1. Now, the X and Y components of the spline follow the + * same polynomial but with x and y replaced for p. To find the + * bounds of the spline, we just need to find the X and Y bounds. + * To find the bound, we take the derivative and equal it to zero, + * and solve to find the t's that give the extreme points. + * + * Here is the derivative of the curve, sorted on t: + * + * 3t²(-p0+3p1-3p2+p3) + 2t(3p0-6p1+3p2) -3p0+3p1 + * + * Let: + * + * a = -p0+3p1-3p2+p3 + * b = p0-2p1+p2 + * c = -p0+p1 + * + * Gives: + * + * a.t² + 2b.t + c = 0 + * + * With: + * + * delta = b*b - a*c + * + * the extreme points are at -c/2b if a is zero, at (-b±√delta)/a if + * delta is positive, and at -b/a if delta is zero. + */ + +#define ADD(t0) \ + { \ + double _t0 = (t0); \ + if (0 < _t0 && _t0 < 1) \ + t[t_num++] = _t0; \ + } + +#define FIND_EXTREMES(a,b,c) \ + { \ + if (a == 0) { \ + if (b != 0) \ + ADD (-c / (2*b)); \ + } else { \ + double b2 = b * b; \ + double delta = b2 - a * c; \ + if (delta > 0) { \ + cairo_bool_t feasible; \ + double _2ab = 2 * a * b; \ + /* We are only interested in solutions t that satisfy 0= 0) \ + feasible = delta > b2 && delta < a*a + b2 + _2ab; \ + else if (-b / a >= 1) \ + feasible = delta < b2 && delta > a*a + b2 + _2ab; \ + else \ + feasible = delta < b2 || delta < a*a + b2 + _2ab; \ + \ + if (unlikely (feasible)) { \ + double sqrt_delta = sqrt (delta); \ + ADD ((-b - sqrt_delta) / a); \ + ADD ((-b + sqrt_delta) / a); \ + } \ + } else if (delta == 0) { \ + ADD (-b / a); \ + } \ + } \ + } + + /* Find X extremes */ + a = -x0 + 3*x1 - 3*x2 + x3; + b = x0 - 2*x1 + x2; + c = -x0 + x1; + FIND_EXTREMES (a, b, c); + + /* Find Y extremes */ + a = -y0 + 3*y1 - 3*y2 + y3; + b = y0 - 2*y1 + y2; + c = -y0 + y1; + FIND_EXTREMES (a, b, c); + + status = add_point_func (closure, p0, NULL); + if (unlikely (status)) + return status; + + for (i = 0; i < t_num; i++) { + cairo_point_t p; + double x, y; + double t_1_0, t_0_1; + double t_2_0, t_0_2; + double t_3_0, t_2_1_3, t_1_2_3, t_0_3; + + t_1_0 = t[i]; /* t */ + t_0_1 = 1 - t_1_0; /* (1 - t) */ + + t_2_0 = t_1_0 * t_1_0; /* t * t */ + t_0_2 = t_0_1 * t_0_1; /* (1 - t) * (1 - t) */ + + t_3_0 = t_2_0 * t_1_0; /* t * t * t */ + t_2_1_3 = t_2_0 * t_0_1 * 3; /* t * t * (1 - t) * 3 */ + t_1_2_3 = t_1_0 * t_0_2 * 3; /* t * (1 - t) * (1 - t) * 3 */ + t_0_3 = t_0_1 * t_0_2; /* (1 - t) * (1 - t) * (1 - t) */ + + /* Bezier polynomial */ + x = x0 * t_0_3 + + x1 * t_1_2_3 + + x2 * t_2_1_3 + + x3 * t_3_0; + y = y0 * t_0_3 + + y1 * t_1_2_3 + + y2 * t_2_1_3 + + y3 * t_3_0; + + p.x = _cairo_fixed_from_double (x); + p.y = _cairo_fixed_from_double (y); + status = add_point_func (closure, &p, NULL); + if (unlikely (status)) + return status; + } + + return add_point_func (closure, p3, NULL); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash-private.h new file mode 100644 index 00000000000..75c000cd73a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash-private.h @@ -0,0 +1,70 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#ifndef CAIRO_STROKE_DASH_PRIVATE_H +#define CAIRO_STROKE_DASH_PRIVATE_H + +#include "cairoint.h" + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_stroker_dash { + cairo_bool_t dashed; + unsigned int dash_index; + cairo_bool_t dash_on; + cairo_bool_t dash_starts_on; + double dash_remain; + + double dash_offset; + const double *dashes; + unsigned int num_dashes; +} cairo_stroker_dash_t; + +cairo_private void +_cairo_stroker_dash_init (cairo_stroker_dash_t *dash, + const cairo_stroke_style_t *style); + +cairo_private void +_cairo_stroker_dash_start (cairo_stroker_dash_t *dash); + +cairo_private void +_cairo_stroker_dash_step (cairo_stroker_dash_t *dash, double step); + +CAIRO_END_DECLS + +#endif /* CAIRO_STROKE_DASH_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash.c b/Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash.c new file mode 100644 index 00000000000..9494010f561 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-stroke-dash.c @@ -0,0 +1,96 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-stroke-dash-private.h" + +void +_cairo_stroker_dash_start (cairo_stroker_dash_t *dash) +{ + double offset; + cairo_bool_t on = TRUE; + unsigned int i = 0; + + if (! dash->dashed) + return; + + offset = dash->dash_offset; + + /* We stop searching for a starting point as soon as the + offset reaches zero. Otherwise when an initial dash + segment shrinks to zero it will be skipped over. */ + while (offset > 0.0 && offset >= dash->dashes[i]) { + offset -= dash->dashes[i]; + on = !on; + if (++i == dash->num_dashes) + i = 0; + } + + dash->dash_index = i; + dash->dash_on = dash->dash_starts_on = on; + dash->dash_remain = dash->dashes[i] - offset; +} + +void +_cairo_stroker_dash_step (cairo_stroker_dash_t *dash, double step) +{ + dash->dash_remain -= step; + if (dash->dash_remain < CAIRO_FIXED_ERROR_DOUBLE) { + if (++dash->dash_index == dash->num_dashes) + dash->dash_index = 0; + + dash->dash_on = ! dash->dash_on; + dash->dash_remain += dash->dashes[dash->dash_index]; + } +} + +void +_cairo_stroker_dash_init (cairo_stroker_dash_t *dash, + const cairo_stroke_style_t *style) +{ + dash->dashed = style->dash != NULL; + if (! dash->dashed) + return; + + dash->dashes = style->dash; + dash->num_dashes = style->num_dashes; + dash->dash_offset = style->dash_offset; + + _cairo_stroker_dash_start (dash); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-stroke-style.c b/Build/source/libs/cairo/cairo-src/src/cairo-stroke-style.c new file mode 100644 index 00000000000..51c9414c042 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-stroke-style.c @@ -0,0 +1,354 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +void +_cairo_stroke_style_init (cairo_stroke_style_t *style) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (style, sizeof (cairo_stroke_style_t))); + + style->line_width = CAIRO_GSTATE_LINE_WIDTH_DEFAULT; + style->line_cap = CAIRO_GSTATE_LINE_CAP_DEFAULT; + style->line_join = CAIRO_GSTATE_LINE_JOIN_DEFAULT; + style->miter_limit = CAIRO_GSTATE_MITER_LIMIT_DEFAULT; + + style->dash = NULL; + style->num_dashes = 0; + style->dash_offset = 0.0; +} + +cairo_status_t +_cairo_stroke_style_init_copy (cairo_stroke_style_t *style, + const cairo_stroke_style_t *other) +{ + if (CAIRO_INJECT_FAULT ()) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + VG (VALGRIND_MAKE_MEM_UNDEFINED (style, sizeof (cairo_stroke_style_t))); + + style->line_width = other->line_width; + style->line_cap = other->line_cap; + style->line_join = other->line_join; + style->miter_limit = other->miter_limit; + + style->num_dashes = other->num_dashes; + + if (other->dash == NULL) { + style->dash = NULL; + } else { + style->dash = _cairo_malloc_ab (style->num_dashes, sizeof (double)); + if (unlikely (style->dash == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (style->dash, other->dash, + style->num_dashes * sizeof (double)); + } + + style->dash_offset = other->dash_offset; + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_stroke_style_fini (cairo_stroke_style_t *style) +{ + free (style->dash); + style->dash = NULL; + + style->num_dashes = 0; + + VG (VALGRIND_MAKE_MEM_NOACCESS (style, sizeof (cairo_stroke_style_t))); +} + +/* + * For a stroke in the given style, compute the maximum distance + * from the path that vertices could be generated. In the case + * of rotation in the ctm, the distance will not be exact. + */ +void +_cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm, + double *dx, double *dy) +{ + double style_expansion = 0.5; + + if (style->line_cap == CAIRO_LINE_CAP_SQUARE) + style_expansion = M_SQRT1_2; + + if (style->line_join == CAIRO_LINE_JOIN_MITER && + ! path->stroke_is_rectilinear && + style_expansion < M_SQRT2 * style->miter_limit) + { + style_expansion = M_SQRT2 * style->miter_limit; + } + + style_expansion *= style->line_width; + + if (_cairo_matrix_has_unity_scale (ctm)) { + *dx = *dy = style_expansion; + } else { + *dx = style_expansion * hypot (ctm->xx, ctm->xy); + *dy = style_expansion * hypot (ctm->yy, ctm->yx); + } +} + +void +_cairo_stroke_style_max_line_distance_from_path (const cairo_stroke_style_t *style, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm, + double *dx, double *dy) +{ + double style_expansion = 0.5 * style->line_width; + if (_cairo_matrix_has_unity_scale (ctm)) { + *dx = *dy = style_expansion; + } else { + *dx = style_expansion * hypot (ctm->xx, ctm->xy); + *dy = style_expansion * hypot (ctm->yy, ctm->yx); + } +} + +void +_cairo_stroke_style_max_join_distance_from_path (const cairo_stroke_style_t *style, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm, + double *dx, double *dy) +{ + double style_expansion = 0.5; + + if (style->line_join == CAIRO_LINE_JOIN_MITER && + ! path->stroke_is_rectilinear && + style_expansion < M_SQRT2 * style->miter_limit) + { + style_expansion = M_SQRT2 * style->miter_limit; + } + + style_expansion *= style->line_width; + + if (_cairo_matrix_has_unity_scale (ctm)) { + *dx = *dy = style_expansion; + } else { + *dx = style_expansion * hypot (ctm->xx, ctm->xy); + *dy = style_expansion * hypot (ctm->yy, ctm->yx); + } +} +/* + * Computes the period of a dashed stroke style. + * Returns 0 for non-dashed styles. + */ +double +_cairo_stroke_style_dash_period (const cairo_stroke_style_t *style) +{ + double period; + unsigned int i; + + period = 0.0; + for (i = 0; i < style->num_dashes; i++) + period += style->dash[i]; + + if (style->num_dashes & 1) + period *= 2.0; + + return period; +} + +/* + * Coefficient of the linear approximation (minimizing square difference) + * of the surface covered by round caps + * + * This can be computed in the following way: + * the area inside the circle with radius w/2 and the region -d/2 <= x <= d/2 is: + * f(w,d) = 2 * integrate (sqrt (w*w/4 - x*x), x, -d/2, d/2) + * The square difference to a generic linear approximation (c*d) in the range (0,w) would be: + * integrate ((f(w,d) - c*d)^2, d, 0, w) + * To minimize this difference it is sufficient to find a solution of the differential with + * respect to c: + * solve ( diff (integrate ((f(w,d) - c*d)^2, d, 0, w), c), c) + * Which leads to c = 9/32*pi*w + * Since we're not interested in the true area, but just in a coverage extimate, + * we always divide the real area by the line width (w). + * The same computation for square caps would be + * f(w,d) = 2 * integrate(w/2, x, -d/2, d/2) + * c = 1*w + * but in this case it would not be an approximation, since f is already linear in d. + */ +#define ROUND_MINSQ_APPROXIMATION (9*M_PI/32) + +/* + * Computes the length of the "on" part of a dashed stroke style, + * taking into account also line caps. + * Returns 0 for non-dashed styles. + */ +double +_cairo_stroke_style_dash_stroked (const cairo_stroke_style_t *style) +{ + double stroked, cap_scale; + unsigned int i; + + switch (style->line_cap) { + default: ASSERT_NOT_REACHED; + case CAIRO_LINE_CAP_BUTT: cap_scale = 0.0; break; + case CAIRO_LINE_CAP_ROUND: cap_scale = ROUND_MINSQ_APPROXIMATION; break; + case CAIRO_LINE_CAP_SQUARE: cap_scale = 1.0; break; + } + + stroked = 0.0; + if (style->num_dashes & 1) { + /* Each dash element is used both as on and as off. The order in which they are summed is + * irrelevant, so sum the coverage of one dash element, taken both on and off at each iteration */ + for (i = 0; i < style->num_dashes; i++) + stroked += style->dash[i] + cap_scale * MIN (style->dash[i], style->line_width); + } else { + /* Even (0, 2, ...) dashes are on and simply counted for the coverage, odd dashes are off, thus + * their coverage is approximated based on the area covered by the caps of adjacent on dases. */ + for (i = 0; i + 1 < style->num_dashes; i += 2) + stroked += style->dash[i] + cap_scale * MIN (style->dash[i+1], style->line_width); + } + + return stroked; +} + +/* + * Verifies if _cairo_stroke_style_dash_approximate should be used to generate + * an approximation of the dash pattern in the specified style, when used for + * stroking a path with the given CTM and tolerance. + * Always %FALSE for non-dashed styles. + */ +cairo_bool_t +_cairo_stroke_style_dash_can_approximate (const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + double tolerance) +{ + double period; + + if (! style->num_dashes) + return FALSE; + + period = _cairo_stroke_style_dash_period (style); + return _cairo_matrix_transformed_circle_major_axis (ctm, period) < tolerance; +} + +/* + * Create a 2-dashes approximation of a dashed style, by making the "on" and "off" + * parts respect the original ratio. + */ +void +_cairo_stroke_style_dash_approximate (const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + double tolerance, + double *dash_offset, + double *dashes, + unsigned int *num_dashes) +{ + double coverage, scale, offset; + cairo_bool_t on = TRUE; + unsigned int i = 0; + + coverage = _cairo_stroke_style_dash_stroked (style) / _cairo_stroke_style_dash_period (style); + coverage = MIN (coverage, 1.0); + scale = tolerance / _cairo_matrix_transformed_circle_major_axis (ctm, 1.0); + + /* We stop searching for a starting point as soon as the + * offset reaches zero. Otherwise when an initial dash + * segment shrinks to zero it will be skipped over. */ + offset = style->dash_offset; + while (offset > 0.0 && offset >= style->dash[i]) { + offset -= style->dash[i]; + on = !on; + if (++i == style->num_dashes) + i = 0; + } + + *num_dashes = 2; + + /* + * We want to create a new dash pattern with the same relative coverage, + * but composed of just 2 elements with total length equal to scale. + * Based on the formula in _cairo_stroke_style_dash_stroked: + * scale * coverage = dashes[0] + cap_scale * MIN (dashes[1], line_width) + * = MIN (dashes[0] + cap_scale * (scale - dashes[0]), + * dashes[0] + cap_scale * line_width) = + * = MIN (dashes[0] * (1 - cap_scale) + cap_scale * scale, + * dashes[0] + cap_scale * line_width) + * + * Solving both cases we get: + * dashes[0] = scale * (coverage - cap_scale) / (1 - cap_scale) + * when scale - dashes[0] <= line_width + * dashes[0] = scale * coverage - cap_scale * line_width + * when scale - dashes[0] > line_width. + * + * Comparing the two cases we get: + * second > first + * second > scale * (coverage - cap_scale) / (1 - cap_scale) + * second - cap_scale * second - scale * coverage + scale * cap_scale > 0 + * (scale * coverage - cap_scale * line_width) - cap_scale * second - scale * coverage + scale * cap_scale > 0 + * - line_width - second + scale > 0 + * scale - second > line_width + * which is the condition for the second solution to be the valid one. + * So when second > first, the second solution is the correct one (i.e. + * the solution is always MAX (first, second). + */ + switch (style->line_cap) { + default: + ASSERT_NOT_REACHED; + dashes[0] = 0.0; + break; + + case CAIRO_LINE_CAP_BUTT: + /* Simplified formula (substituting 0 for cap_scale): */ + dashes[0] = scale * coverage; + break; + + case CAIRO_LINE_CAP_ROUND: + dashes[0] = MAX(scale * (coverage - ROUND_MINSQ_APPROXIMATION) / (1.0 - ROUND_MINSQ_APPROXIMATION), + scale * coverage - ROUND_MINSQ_APPROXIMATION * style->line_width); + break; + + case CAIRO_LINE_CAP_SQUARE: + /* + * Special attention is needed to handle the case cap_scale == 1 (since the first solution + * is either indeterminate or -inf in this case). Since dash lengths are always >=0, using + * 0 as first solution always leads to the correct solution. + */ + dashes[0] = MAX(0.0, scale * coverage - style->line_width); + break; + } + + dashes[1] = scale - dashes[0]; + + *dash_offset = on ? 0.0 : dashes[0]; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-backend-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-backend-private.h new file mode 100644 index 00000000000..955a79ff5c3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-backend-private.h @@ -0,0 +1,221 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_SURFACE_BACKEND_PRIVATE_H +#define CAIRO_SURFACE_BACKEND_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" + +CAIRO_BEGIN_DECLS + +struct _cairo_surface_backend { + cairo_surface_type_t type; + + cairo_warn cairo_status_t + (*finish) (void *surface); + + cairo_t * + (*create_context) (void *surface); + + cairo_surface_t * + (*create_similar) (void *surface, + cairo_content_t content, + int width, + int height); + cairo_surface_t * + (*create_similar_image) (void *surface, + cairo_format_t format, + int width, + int height); + + cairo_image_surface_t * + (*map_to_image) (void *surface, + const cairo_rectangle_int_t *extents); + cairo_int_status_t + (*unmap_image) (void *surface, + cairo_image_surface_t *image); + + cairo_surface_t * + (*source) (void *abstract_surface, + cairo_rectangle_int_t *extents); + + cairo_warn cairo_status_t + (*acquire_source_image) (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra); + + cairo_warn void + (*release_source_image) (void *abstract_surface, + cairo_image_surface_t *image_out, + void *image_extra); + + cairo_surface_t * + (*snapshot) (void *surface); + + cairo_warn cairo_int_status_t + (*copy_page) (void *surface); + + cairo_warn cairo_int_status_t + (*show_page) (void *surface); + + /* Get the extents of the current surface. For many surface types + * this will be as simple as { x=0, y=0, width=surface->width, + * height=surface->height}. + * + * If this function is not implemented, or if it returns + * FALSE the surface is considered to be + * boundless and infinite bounds are used for it. + */ + cairo_bool_t + (*get_extents) (void *surface, + cairo_rectangle_int_t *extents); + + void + (*get_font_options) (void *surface, + cairo_font_options_t *options); + + cairo_warn cairo_status_t + (*flush) (void *surface, + unsigned flags); + + cairo_warn cairo_status_t + (*mark_dirty_rectangle) (void *surface, + int x, + int y, + int width, + int height); + + cairo_warn cairo_int_status_t + (*paint) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + + cairo_warn cairo_int_status_t + (*mask) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + + cairo_warn cairo_int_status_t + (*stroke) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + + cairo_warn cairo_int_status_t + (*fill) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + + cairo_warn cairo_int_status_t + (*fill_stroke) (void *surface, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + const cairo_path_fixed_t*path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip); + + cairo_warn cairo_int_status_t + (*show_glyphs) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + + cairo_bool_t + (*has_show_text_glyphs) (void *surface); + + cairo_warn cairo_int_status_t + (*show_text_glyphs) (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + + const char ** + (*get_supported_mime_types) (void *surface); +}; + +cairo_private cairo_status_t +_cairo_surface_default_acquire_source_image (void *surface, + cairo_image_surface_t **image_out, + void **image_extra); + +cairo_private void +_cairo_surface_default_release_source_image (void *surface, + cairo_image_surface_t *image, + void *image_extra); + +cairo_private cairo_surface_t * +_cairo_surface_default_source (void *surface, + cairo_rectangle_int_t *extents); + +CAIRO_END_DECLS + +#endif /* CAIRO_SURFACE_BACKEND_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper-private.h new file mode 100644 index 00000000000..e5b00af7c66 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper-private.h @@ -0,0 +1,71 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_CLIPPER_PRIVATE_H +#define CAIRO_SURFACE_CLIPPER_PRIVATE_H + +#include "cairo-types-private.h" +#include "cairo-clip-private.h" + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_surface_clipper cairo_surface_clipper_t; + +typedef cairo_status_t +(*cairo_surface_clipper_intersect_clip_path_func_t) (cairo_surface_clipper_t *, + cairo_path_fixed_t *, + cairo_fill_rule_t, + double, + cairo_antialias_t); +struct _cairo_surface_clipper { + cairo_clip_t *clip; + cairo_surface_clipper_intersect_clip_path_func_t intersect_clip_path; +}; + +cairo_private cairo_status_t +_cairo_surface_clipper_set_clip (cairo_surface_clipper_t *clipper, + const cairo_clip_t *clip); + +cairo_private void +_cairo_surface_clipper_init (cairo_surface_clipper_t *clipper, + cairo_surface_clipper_intersect_clip_path_func_t intersect); + +cairo_private void +_cairo_surface_clipper_reset (cairo_surface_clipper_t *clipper); + +CAIRO_END_DECLS + +#endif /* CAIRO_SURFACE_CLIPPER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper.c new file mode 100644 index 00000000000..5309362c68f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-clipper.c @@ -0,0 +1,196 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-surface-clipper-private.h" + +/* A collection of routines to facilitate vector surface clipping */ + +/* XXX Eliminate repeated paths and nested clips */ + +static cairo_status_t +_cairo_path_fixed_add_box (cairo_path_fixed_t *path, + const cairo_box_t *box) +{ + cairo_status_t status; + + status = _cairo_path_fixed_move_to (path, box->p1.x, box->p1.y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p2.x, box->p1.y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p2.x, box->p2.y); + if (unlikely (status)) + return status; + + status = _cairo_path_fixed_line_to (path, box->p1.x, box->p2.y); + if (unlikely (status)) + return status; + + return _cairo_path_fixed_close_path (path); +} + +static cairo_status_t +_cairo_surface_clipper_intersect_clip_boxes (cairo_surface_clipper_t *clipper, + const cairo_clip_t *clip) +{ + cairo_path_fixed_t path; + cairo_status_t status; + int i; + + if (clip->num_boxes == 0) + return CAIRO_STATUS_SUCCESS; + + /* Reconstruct the path for the clip boxes. + * XXX maybe a new clipper callback? + */ + + _cairo_path_fixed_init (&path); + for (i = 0; i < clip->num_boxes; i++) { + status = _cairo_path_fixed_add_box (&path, &clip->boxes[i]); + if (unlikely (status)) { + _cairo_path_fixed_fini (&path); + return status; + } + } + + status = clipper->intersect_clip_path (clipper, &path, + CAIRO_FILL_RULE_WINDING, + 0., + CAIRO_ANTIALIAS_DEFAULT); + _cairo_path_fixed_fini (&path); + + return status; +} + +static cairo_status_t +_cairo_surface_clipper_intersect_clip_path_recursive (cairo_surface_clipper_t *clipper, + cairo_clip_path_t *clip_path, + cairo_clip_path_t *end) +{ + cairo_status_t status; + + if (clip_path->prev != end) { + status = + _cairo_surface_clipper_intersect_clip_path_recursive (clipper, + clip_path->prev, + end); + if (unlikely (status)) + return status; + } + + return clipper->intersect_clip_path (clipper, + &clip_path->path, + clip_path->fill_rule, + clip_path->tolerance, + clip_path->antialias); +} + +cairo_status_t +_cairo_surface_clipper_set_clip (cairo_surface_clipper_t *clipper, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_bool_t incremental = FALSE; + + if (_cairo_clip_equal (clip, clipper->clip)) + return CAIRO_STATUS_SUCCESS; + + /* all clipped out state should never propagate this far */ + assert (!_cairo_clip_is_all_clipped (clip)); + + /* XXX Is this an incremental clip? */ + if (clipper->clip && clip && + clip->num_boxes == clipper->clip->num_boxes && + memcmp (clip->boxes, clipper->clip->boxes, + sizeof (cairo_box_t) * clip->num_boxes) == 0) + { + cairo_clip_path_t *clip_path = clip->path; + while (clip_path != NULL && clip_path != clipper->clip->path) + clip_path = clip_path->prev; + + if (clip_path) { + incremental = TRUE; + status = _cairo_surface_clipper_intersect_clip_path_recursive (clipper, + clip->path, + clipper->clip->path); + } + } + + _cairo_clip_destroy (clipper->clip); + clipper->clip = _cairo_clip_copy (clip); + + if (incremental) + return status; + + status = clipper->intersect_clip_path (clipper, NULL, 0, 0, 0); + if (unlikely (status)) + return status; + + if (clip == NULL) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_clipper_intersect_clip_boxes (clipper, clip); + if (unlikely (status)) + return status; + + if (clip->path != NULL) { + status = _cairo_surface_clipper_intersect_clip_path_recursive (clipper, + clip->path, + NULL); + } + + return status; +} + +void +_cairo_surface_clipper_init (cairo_surface_clipper_t *clipper, + cairo_surface_clipper_intersect_clip_path_func_t func) +{ + clipper->clip = NULL; + clipper->intersect_clip_path = func; +} + +void +_cairo_surface_clipper_reset (cairo_surface_clipper_t *clipper) +{ + _cairo_clip_destroy (clipper->clip); + clipper->clip = NULL; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback-private.h new file mode 100644 index 00000000000..ecf7b0edf2b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback-private.h @@ -0,0 +1,95 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_FALLBACK_PRIVATE_H +#define CAIRO_SURFACE_FALLBACK_PRIVATE_H + +#include "cairoint.h" + +CAIRO_BEGIN_DECLS + +cairo_private cairo_int_status_t +_cairo_surface_fallback_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_surface_fallback_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_surface_fallback_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t*style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_surface_fallback_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_int_status_t +_cairo_surface_fallback_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + +CAIRO_END_DECLS + +#endif /* CAIRO_SURFACE_FALLBACK_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback.c new file mode 100644 index 00000000000..a0af1596921 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-fallback.c @@ -0,0 +1,115 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-compositor-private.h" +#include "cairo-surface-fallback-private.h" + +cairo_int_status_t +_cairo_surface_fallback_paint (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + return _cairo_compositor_paint (&_cairo_fallback_compositor, + surface, op, source, clip); +} + +cairo_int_status_t +_cairo_surface_fallback_mask (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + return _cairo_compositor_mask (&_cairo_fallback_compositor, + surface, op, source, mask, clip); +} + +cairo_int_status_t +_cairo_surface_fallback_stroke (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + const cairo_stroke_style_t*style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + return _cairo_compositor_stroke (&_cairo_fallback_compositor, + surface, op, source, path, + style, ctm,ctm_inverse, + tolerance, antialias, clip); +} + +cairo_int_status_t +_cairo_surface_fallback_fill (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + return _cairo_compositor_fill (&_cairo_fallback_compositor, + surface, op, source, path, + fill_rule, tolerance, antialias, + clip); +} + +cairo_int_status_t +_cairo_surface_fallback_glyphs (void *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + return _cairo_compositor_glyphs (&_cairo_fallback_compositor, + surface, op, source, + glyphs, num_glyphs, scaled_font, + clip); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-inline.h new file mode 100644 index 00000000000..85fbc9192bd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-inline.h @@ -0,0 +1,60 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_SURFACE_INLINE_H +#define CAIRO_SURFACE_INLINE_H + +#include "cairo-surface-private.h" + +static inline cairo_status_t +__cairo_surface_flush (cairo_surface_t *surface, unsigned flags) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + if (surface->backend->flush) + status = surface->backend->flush (surface, flags); + return status; +} + +static inline cairo_surface_t * +_cairo_surface_reference (cairo_surface_t *surface) +{ + if (!CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + _cairo_reference_count_inc (&surface->ref_count); + return surface; +} + +#endif /* CAIRO_SURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-inline.h new file mode 100644 index 00000000000..07b94770d4b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-inline.h @@ -0,0 +1,59 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_OBSERVER_INLINE_H +#define CAIRO_SURFACE_OBSERVER_INLINE_H + +#include "cairo-surface-observer-private.h" + +static inline cairo_surface_t * +_cairo_surface_observer_get_target (cairo_surface_t *surface) +{ + return ((cairo_surface_observer_t *) surface)->target; +} + +static inline cairo_bool_t +_cairo_surface_is_observer (cairo_surface_t *surface) +{ + return surface->backend->type == (cairo_surface_type_t)CAIRO_INTERNAL_SURFACE_TYPE_OBSERVER; +} + +static inline cairo_bool_t +_cairo_device_is_observer (cairo_device_t *device) +{ + return device->backend->type == (cairo_device_type_t)CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER; +} + +#endif /* CAIRO_SURFACE_OBSERVER_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-private.h new file mode 100644 index 00000000000..6ed0c18d17c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer-private.h @@ -0,0 +1,208 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_OBSERVER_PRIVATE_H +#define CAIRO_SURFACE_OBSERVER_PRIVATE_H + +#include "cairoint.h" + +#include "cairo-device-private.h" +#include "cairo-list-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-time-private.h" + +struct stat { + double min, max, sum, sum_sq; + unsigned count; +}; + +#define NUM_OPERATORS (CAIRO_OPERATOR_HSL_LUMINOSITY+1) +#define NUM_CAPS (CAIRO_LINE_CAP_SQUARE+1) +#define NUM_JOINS (CAIRO_LINE_JOIN_BEVEL+1) +#define NUM_ANTIALIAS (CAIRO_ANTIALIAS_BEST+1) +#define NUM_FILL_RULE (CAIRO_FILL_RULE_EVEN_ODD+1) + +struct extents { + struct stat area; + unsigned int bounded, unbounded; +}; + +struct pattern { + unsigned int type[8]; /* native/record/other surface/gradients */ +}; + +struct path { + unsigned int type[5]; /* empty/pixel/rectilinear/straight/curved */ +}; + +struct clip { + unsigned int type[6]; /* none, region, boxes, single path, polygon, general */ +}; + +typedef struct _cairo_observation cairo_observation_t; +typedef struct _cairo_observation_record cairo_observation_record_t; +typedef struct _cairo_device_observer cairo_device_observer_t; + +struct _cairo_observation_record { + cairo_content_t target_content; + int target_width; + int target_height; + + int index; + cairo_operator_t op; + int source; + int mask; + int num_glyphs; + int path; + int fill_rule; + double tolerance; + int antialias; + int clip; + cairo_time_t elapsed; +}; + +struct _cairo_observation { + int num_surfaces; + int num_contexts; + int num_sources_acquired; + + /* XXX put interesting stats here! */ + + struct paint { + cairo_time_t elapsed; + unsigned int count; + struct extents extents; + unsigned int operators[NUM_OPERATORS]; + struct pattern source; + struct clip clip; + unsigned int noop; + + cairo_observation_record_t slowest; + } paint; + + struct mask { + cairo_time_t elapsed; + unsigned int count; + struct extents extents; + unsigned int operators[NUM_OPERATORS]; + struct pattern source; + struct pattern mask; + struct clip clip; + unsigned int noop; + + cairo_observation_record_t slowest; + } mask; + + struct fill { + cairo_time_t elapsed; + unsigned int count; + struct extents extents; + unsigned int operators[NUM_OPERATORS]; + struct pattern source; + struct path path; + unsigned int antialias[NUM_ANTIALIAS]; + unsigned int fill_rule[NUM_FILL_RULE]; + struct clip clip; + unsigned int noop; + + cairo_observation_record_t slowest; + } fill; + + struct stroke { + cairo_time_t elapsed; + unsigned int count; + struct extents extents; + unsigned int operators[NUM_OPERATORS]; + unsigned int caps[NUM_CAPS]; + unsigned int joins[NUM_CAPS]; + unsigned int antialias[NUM_ANTIALIAS]; + struct pattern source; + struct path path; + struct stat line_width; + struct clip clip; + unsigned int noop; + + cairo_observation_record_t slowest; + } stroke; + + struct glyphs { + cairo_time_t elapsed; + unsigned int count; + struct extents extents; + unsigned int operators[NUM_OPERATORS]; + struct pattern source; + struct clip clip; + unsigned int noop; + + cairo_observation_record_t slowest; + } glyphs; + + cairo_array_t timings; + cairo_recording_surface_t *record; +}; + +struct _cairo_device_observer { + cairo_device_t base; + cairo_device_t *target; + + cairo_observation_t log; +}; + +struct callback_list { + cairo_list_t link; + + cairo_surface_observer_callback_t func; + void *data; +}; + +struct _cairo_surface_observer { + cairo_surface_t base; + cairo_surface_t *target; + + cairo_observation_t log; + + cairo_list_t paint_callbacks; + cairo_list_t mask_callbacks; + cairo_list_t fill_callbacks; + cairo_list_t stroke_callbacks; + cairo_list_t glyphs_callbacks; + + cairo_list_t flush_callbacks; + cairo_list_t finish_callbacks; +}; + +#endif /* CAIRO_SURFACE_OBSERVER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer.c new file mode 100644 index 00000000000..52b013644db --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-observer.c @@ -0,0 +1,2106 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-surface-observer-private.h" +#include "cairo-surface-observer-inline.h" + +#include "cairo-array-private.h" +#include "cairo-combsort-inline.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-pattern-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-subsurface-inline.h" +#include "cairo-reference-count-private.h" + +#if CAIRO_HAS_SCRIPT_SURFACE +#include "cairo-script-private.h" +#endif + +static const cairo_surface_backend_t _cairo_surface_observer_backend; + +/* observation/stats */ + +static void init_stats (struct stat *s) +{ + s->min = HUGE_VAL; + s->max = -HUGE_VAL; +} + +static void init_extents (struct extents *e) +{ + init_stats (&e->area); +} + +static void init_pattern (struct pattern *p) +{ +} + +static void init_path (struct path *p) +{ +} + +static void init_clip (struct clip *c) +{ +} + +static void init_paint (struct paint *p) +{ + init_extents (&p->extents); + init_pattern (&p->source); + init_clip (&p->clip); +} + +static void init_mask (struct mask *m) +{ + init_extents (&m->extents); + init_pattern (&m->source); + init_pattern (&m->mask); + init_clip (&m->clip); +} + +static void init_fill (struct fill *f) +{ + init_extents (&f->extents); + init_pattern (&f->source); + init_path (&f->path); + init_clip (&f->clip); +} + +static void init_stroke (struct stroke *s) +{ + init_extents (&s->extents); + init_pattern (&s->source); + init_path (&s->path); + init_clip (&s->clip); +} + +static void init_glyphs (struct glyphs *g) +{ + init_extents (&g->extents); + init_pattern (&g->source); + init_clip (&g->clip); +} + +static cairo_status_t +log_init (cairo_observation_t *log, + cairo_bool_t record) +{ + memset (log, 0, sizeof(*log)); + + init_paint (&log->paint); + init_mask (&log->mask); + init_fill (&log->fill); + init_stroke (&log->stroke); + init_glyphs (&log->glyphs); + + _cairo_array_init (&log->timings, sizeof (cairo_observation_record_t)); + + if (record) { + log->record = (cairo_recording_surface_t *) + cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL); + if (unlikely (log->record->base.status)) + return log->record->base.status; + + log->record->optimize_clears = FALSE; + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +log_fini (cairo_observation_t *log) +{ + _cairo_array_fini (&log->timings); + cairo_surface_destroy (&log->record->base); +} + +static cairo_surface_t* +get_pattern_surface (const cairo_pattern_t *pattern) +{ + return ((cairo_surface_pattern_t *)pattern)->surface; +} + +static int +classify_pattern (const cairo_pattern_t *pattern, + const cairo_surface_t *target) +{ + int classify; + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SURFACE: + if (get_pattern_surface (pattern)->type == target->type) + classify = 0; + else if (get_pattern_surface (pattern)->type == CAIRO_SURFACE_TYPE_RECORDING) + classify = 1; + else + classify = 2; + break; + default: + case CAIRO_PATTERN_TYPE_SOLID: + classify = 3; + break; + case CAIRO_PATTERN_TYPE_LINEAR: + classify = 4; + break; + case CAIRO_PATTERN_TYPE_RADIAL: + classify = 5; + break; + case CAIRO_PATTERN_TYPE_MESH: + classify = 6; + break; + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + classify = 7; + break; + } + return classify; +} + +static void +add_pattern (struct pattern *stats, + const cairo_pattern_t *pattern, + const cairo_surface_t *target) +{ + stats->type[classify_pattern(pattern, target)]++; +} + +static int +classify_path (const cairo_path_fixed_t *path, + cairo_bool_t is_fill) +{ + int classify; + + /* XXX improve for stroke */ + classify = -1; + if (is_fill) { + if (path->fill_is_empty) + classify = 0; + else if (_cairo_path_fixed_fill_is_rectilinear (path)) + classify = path->fill_maybe_region ? 1 : 2; + } else { + if (_cairo_path_fixed_stroke_is_rectilinear (path)) + classify = 2; + } + if (classify == -1) + classify = 3 + (path->has_curve_to != 0); + + return classify; +} + +static void +add_path (struct path *stats, + const cairo_path_fixed_t *path, + cairo_bool_t is_fill) +{ + stats->type[classify_path(path, is_fill)]++; +} + +static int +classify_clip (const cairo_clip_t *clip) +{ + int classify; + + if (clip == NULL) + classify = 0; + else if (_cairo_clip_is_region (clip)) + classify = 1; + else if (clip->path == NULL) + classify = 2; + else if (clip->path->prev == NULL) + classify = 3; + else if (_cairo_clip_is_polygon (clip)) + classify = 4; + else + classify = 5; + + return classify; +} + +static void +add_clip (struct clip *stats, + const cairo_clip_t *clip) +{ + stats->type[classify_clip (clip)]++; +} + +static void +stats_add (struct stat *s, double v) +{ + if (v < s->min) + s->min = v; + if (v > s->max) + s->max = v; + s->sum += v; + s->sum_sq += v*v; + s->count++; +} + +static void +add_extents (struct extents *stats, + const cairo_composite_rectangles_t *extents) +{ + const cairo_rectangle_int_t *r = extents->is_bounded ? &extents->bounded :&extents->unbounded; + stats_add (&stats->area, r->width * r->height); + stats->bounded += extents->is_bounded != 0; + stats->unbounded += extents->is_bounded == 0; +} + +/* device interface */ + +static void +_cairo_device_observer_lock (void *_device) +{ + cairo_device_observer_t *device = (cairo_device_observer_t *) _device; + cairo_status_t ignored; + + /* cairo_device_acquire() can fail for nil and finished + * devices. We don't care about observing them. */ + ignored = cairo_device_acquire (device->target); +} + +static void +_cairo_device_observer_unlock (void *_device) +{ + cairo_device_observer_t *device = (cairo_device_observer_t *) _device; + cairo_device_release (device->target); +} + +static cairo_status_t +_cairo_device_observer_flush (void *_device) +{ + cairo_device_observer_t *device = (cairo_device_observer_t *) _device; + + if (device->target == NULL) + return CAIRO_STATUS_SUCCESS; + + cairo_device_flush (device->target); + return device->target->status; +} + +static void +_cairo_device_observer_finish (void *_device) +{ + cairo_device_observer_t *device = (cairo_device_observer_t *) _device; + log_fini (&device->log); + cairo_device_finish (device->target); +} + +static void +_cairo_device_observer_destroy (void *_device) +{ + cairo_device_observer_t *device = (cairo_device_observer_t *) _device; + cairo_device_destroy (device->target); + free (device); +} + +static const cairo_device_backend_t _cairo_device_observer_backend = { + CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER, + + _cairo_device_observer_lock, + _cairo_device_observer_unlock, + + _cairo_device_observer_flush, + _cairo_device_observer_finish, + _cairo_device_observer_destroy, +}; + +static cairo_device_t * +_cairo_device_create_observer_internal (cairo_device_t *target, + cairo_bool_t record) +{ + cairo_device_observer_t *device; + cairo_status_t status; + + device = malloc (sizeof (cairo_device_observer_t)); + if (unlikely (device == NULL)) + return _cairo_device_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_device_init (&device->base, &_cairo_device_observer_backend); + status = log_init (&device->log, record); + if (unlikely (status)) { + free (device); + return _cairo_device_create_in_error (status); + } + + device->target = cairo_device_reference (target); + + return &device->base; +} + +/* surface interface */ + +static cairo_device_observer_t * +to_device (cairo_surface_observer_t *suface) +{ + return (cairo_device_observer_t *)suface->base.device; +} + +static cairo_surface_t * +_cairo_surface_create_observer_internal (cairo_device_t *device, + cairo_surface_t *target) +{ + cairo_surface_observer_t *surface; + cairo_status_t status; + + surface = malloc (sizeof (cairo_surface_observer_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_surface_observer_backend, device, + target->content); + + status = log_init (&surface->log, + ((cairo_device_observer_t *)device)->log.record != NULL); + if (unlikely (status)) { + free (surface); + return _cairo_surface_create_in_error (status); + } + + surface->target = cairo_surface_reference (target); + surface->base.type = surface->target->type; + surface->base.is_clear = surface->target->is_clear; + + cairo_list_init (&surface->paint_callbacks); + cairo_list_init (&surface->mask_callbacks); + cairo_list_init (&surface->fill_callbacks); + cairo_list_init (&surface->stroke_callbacks); + cairo_list_init (&surface->glyphs_callbacks); + + cairo_list_init (&surface->flush_callbacks); + cairo_list_init (&surface->finish_callbacks); + + surface->log.num_surfaces++; + to_device (surface)->log.num_surfaces++; + + return &surface->base; +} + +static inline void +do_callbacks (cairo_surface_observer_t *surface, cairo_list_t *head) +{ + struct callback_list *cb; + + cairo_list_foreach_entry (cb, struct callback_list, head, link) + cb->func (&surface->base, surface->target, cb->data); +} + + +static cairo_status_t +_cairo_surface_observer_finish (void *abstract_surface) +{ + cairo_surface_observer_t *surface = abstract_surface; + + do_callbacks (surface, &surface->finish_callbacks); + + cairo_surface_destroy (surface->target); + log_fini (&surface->log); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_surface_observer_create_similar (void *abstract_other, + cairo_content_t content, + int width, int height) +{ + cairo_surface_observer_t *other = abstract_other; + cairo_surface_t *target, *surface; + + target = NULL; + if (other->target->backend->create_similar) + target = other->target->backend->create_similar (other->target, content, + width, height); + if (target == NULL) + target = _cairo_image_surface_create_with_content (content, + width, height); + + surface = _cairo_surface_create_observer_internal (other->base.device, + target); + cairo_surface_destroy (target); + + return surface; +} + +static cairo_surface_t * +_cairo_surface_observer_create_similar_image (void *other, + cairo_format_t format, + int width, int height) +{ + cairo_surface_observer_t *surface = other; + + if (surface->target->backend->create_similar_image) + return surface->target->backend->create_similar_image (surface->target, + format, + width, height); + + return NULL; +} + +static cairo_image_surface_t * +_cairo_surface_observer_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_observer_t *surface = abstract_surface; + return _cairo_surface_map_to_image (surface->target, extents); +} + +static cairo_int_status_t +_cairo_surface_observer_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_surface_observer_t *surface = abstract_surface; + return _cairo_surface_unmap_image (surface->target, image); +} + +static void +record_target (cairo_observation_record_t *r, + cairo_surface_t *target) +{ + cairo_rectangle_int_t extents; + + r->target_content = target->content; + if (_cairo_surface_get_extents (target, &extents)) { + r->target_width = extents.width; + r->target_height = extents.height; + } else { + r->target_width = -1; + r->target_height = -1; + } +} + +static cairo_observation_record_t * +record_paint (cairo_observation_record_t *r, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + record_target (r, target); + + r->op = op; + r->source = classify_pattern (source, target); + r->mask = -1; + r->num_glyphs = -1; + r->path = -1; + r->fill_rule = -1; + r->tolerance = -1; + r->antialias = -1; + r->clip = classify_clip (clip); + r->elapsed = elapsed; + + return r; +} + +static cairo_observation_record_t * +record_mask (cairo_observation_record_t *r, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + record_target (r, target); + + r->op = op; + r->source = classify_pattern (source, target); + r->mask = classify_pattern (mask, target); + r->num_glyphs = -1; + r->path = -1; + r->fill_rule = -1; + r->tolerance = -1; + r->antialias = -1; + r->clip = classify_clip (clip); + r->elapsed = elapsed; + + return r; +} + +static cairo_observation_record_t * +record_fill (cairo_observation_record_t *r, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + record_target (r, target); + + r->op = op; + r->source = classify_pattern (source, target); + r->mask = -1; + r->num_glyphs = -1; + r->path = classify_path (path, TRUE); + r->fill_rule = fill_rule; + r->tolerance = tolerance; + r->antialias = antialias; + r->clip = classify_clip (clip); + r->elapsed = elapsed; + + return r; +} + +static cairo_observation_record_t * +record_stroke (cairo_observation_record_t *r, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + record_target (r, target); + + r->op = op; + r->source = classify_pattern (source, target); + r->mask = -1; + r->num_glyphs = -1; + r->path = classify_path (path, FALSE); + r->fill_rule = -1; + r->tolerance = tolerance; + r->antialias = antialias; + r->clip = classify_clip (clip); + r->elapsed = elapsed; + + return r; +} + +static cairo_observation_record_t * +record_glyphs (cairo_observation_record_t *r, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + record_target (r, target); + + r->op = op; + r->source = classify_pattern (source, target); + r->mask = -1; + r->path = -1; + r->num_glyphs = num_glyphs; + r->fill_rule = -1; + r->tolerance = -1; + r->antialias = -1; + r->clip = classify_clip (clip); + r->elapsed = elapsed; + + return r; +} + +static void +add_record (cairo_observation_t *log, + cairo_observation_record_t *r) +{ + cairo_int_status_t status; + + r->index = log->record ? log->record->commands.num_elements : 0; + + status = _cairo_array_append (&log->timings, r); + assert (status == CAIRO_INT_STATUS_SUCCESS); +} + +static void +_cairo_surface_sync (cairo_surface_t *target, int x, int y) +{ + cairo_rectangle_int_t extents; + + extents.x = x; + extents.y = y; + extents.width = 1; + extents.height = 1; + + _cairo_surface_unmap_image (target, + _cairo_surface_map_to_image (target, + &extents)); +} + +static void +midpt (const cairo_composite_rectangles_t *extents, int *x, int *y) +{ + *x = extents->bounded.x + extents->bounded.width / 2; + *y = extents->bounded.y + extents->bounded.height / 2; +} + +static void +add_record_paint (cairo_observation_t *log, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + cairo_observation_record_t record; + cairo_int_status_t status; + + add_record (log, + record_paint (&record, target, op, source, clip, elapsed)); + + /* We have to bypass the high-level surface layer in case it tries to be + * too smart and discard operations; we need to record exactly what just + * happened on the target. + */ + if (log->record) { + status = log->record->base.backend->paint (&log->record->base, + op, source, clip); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + if (_cairo_time_gt (elapsed, log->paint.slowest.elapsed)) + log->paint.slowest = record; + log->paint.elapsed = _cairo_time_add (log->paint.elapsed, elapsed); +} + +static cairo_int_status_t +_cairo_surface_observer_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_device_observer_t *device = to_device (surface); + cairo_composite_rectangles_t composite; + cairo_int_status_t status; + cairo_time_t t; + int x, y; + + /* XXX device locking */ + + surface->log.paint.count++; + surface->log.paint.operators[op]++; + add_pattern (&surface->log.paint.source, source, surface->target); + add_clip (&surface->log.paint.clip, clip); + + device->log.paint.count++; + device->log.paint.operators[op]++; + add_pattern (&device->log.paint.source, source, surface->target); + add_clip (&device->log.paint.clip, clip); + + status = _cairo_composite_rectangles_init_for_paint (&composite, + surface->target, + op, source, + clip); + if (unlikely (status)) { + surface->log.paint.noop++; + device->log.paint.noop++; + return status; + } + + midpt (&composite, &x, &y); + + add_extents (&surface->log.paint.extents, &composite); + add_extents (&device->log.paint.extents, &composite); + _cairo_composite_rectangles_fini (&composite); + + t = _cairo_time_get (); + status = _cairo_surface_paint (surface->target, + op, source, + clip); + if (unlikely (status)) + return status; + + _cairo_surface_sync (surface->target, x, y); + t = _cairo_time_get_delta (t); + + add_record_paint (&surface->log, surface->target, op, source, clip, t); + add_record_paint (&device->log, surface->target, op, source, clip, t); + + do_callbacks (surface, &surface->paint_callbacks); + + return CAIRO_STATUS_SUCCESS; +} + +static void +add_record_mask (cairo_observation_t *log, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + cairo_observation_record_t record; + cairo_int_status_t status; + + add_record (log, + record_mask (&record, target, op, source, mask, clip, elapsed)); + + if (log->record) { + status = log->record->base.backend->mask (&log->record->base, + op, source, mask, clip); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + if (_cairo_time_gt (elapsed, log->mask.slowest.elapsed)) + log->mask.slowest = record; + log->mask.elapsed = _cairo_time_add (log->mask.elapsed, elapsed); +} + +static cairo_int_status_t +_cairo_surface_observer_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_device_observer_t *device = to_device (surface); + cairo_composite_rectangles_t composite; + cairo_int_status_t status; + cairo_time_t t; + int x, y; + + surface->log.mask.count++; + surface->log.mask.operators[op]++; + add_pattern (&surface->log.mask.source, source, surface->target); + add_pattern (&surface->log.mask.mask, mask, surface->target); + add_clip (&surface->log.mask.clip, clip); + + device->log.mask.count++; + device->log.mask.operators[op]++; + add_pattern (&device->log.mask.source, source, surface->target); + add_pattern (&device->log.mask.mask, mask, surface->target); + add_clip (&device->log.mask.clip, clip); + + status = _cairo_composite_rectangles_init_for_mask (&composite, + surface->target, + op, source, mask, + clip); + if (unlikely (status)) { + surface->log.mask.noop++; + device->log.mask.noop++; + return status; + } + + midpt (&composite, &x, &y); + + add_extents (&surface->log.mask.extents, &composite); + add_extents (&device->log.mask.extents, &composite); + _cairo_composite_rectangles_fini (&composite); + + t = _cairo_time_get (); + status = _cairo_surface_mask (surface->target, + op, source, mask, + clip); + if (unlikely (status)) + return status; + + _cairo_surface_sync (surface->target, x, y); + t = _cairo_time_get_delta (t); + + add_record_mask (&surface->log, + surface->target, op, source, mask, clip, + t); + add_record_mask (&device->log, + surface->target, op, source, mask, clip, + t); + + do_callbacks (surface, &surface->mask_callbacks); + + return CAIRO_STATUS_SUCCESS; +} + +static void +add_record_fill (cairo_observation_t *log, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + cairo_observation_record_t record; + cairo_int_status_t status; + + add_record (log, + record_fill (&record, + target, op, source, + path, fill_rule, tolerance, antialias, + clip, elapsed)); + + if (log->record) { + status = log->record->base.backend->fill (&log->record->base, + op, source, + path, fill_rule, + tolerance, antialias, + clip); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + if (_cairo_time_gt (elapsed, log->fill.slowest.elapsed)) + log->fill.slowest = record; + log->fill.elapsed = _cairo_time_add (log->fill.elapsed, elapsed); +} + +static cairo_int_status_t +_cairo_surface_observer_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_device_observer_t *device = to_device (surface); + cairo_composite_rectangles_t composite; + cairo_int_status_t status; + cairo_time_t t; + int x, y; + + surface->log.fill.count++; + surface->log.fill.operators[op]++; + surface->log.fill.fill_rule[fill_rule]++; + surface->log.fill.antialias[antialias]++; + add_pattern (&surface->log.fill.source, source, surface->target); + add_path (&surface->log.fill.path, path, TRUE); + add_clip (&surface->log.fill.clip, clip); + + device->log.fill.count++; + device->log.fill.operators[op]++; + device->log.fill.fill_rule[fill_rule]++; + device->log.fill.antialias[antialias]++; + add_pattern (&device->log.fill.source, source, surface->target); + add_path (&device->log.fill.path, path, TRUE); + add_clip (&device->log.fill.clip, clip); + + status = _cairo_composite_rectangles_init_for_fill (&composite, + surface->target, + op, source, path, + clip); + if (unlikely (status)) { + surface->log.fill.noop++; + device->log.fill.noop++; + return status; + } + + midpt (&composite, &x, &y); + + add_extents (&surface->log.fill.extents, &composite); + add_extents (&device->log.fill.extents, &composite); + _cairo_composite_rectangles_fini (&composite); + + t = _cairo_time_get (); + status = _cairo_surface_fill (surface->target, + op, source, path, + fill_rule, tolerance, antialias, + clip); + if (unlikely (status)) + return status; + + _cairo_surface_sync (surface->target, x, y); + t = _cairo_time_get_delta (t); + + add_record_fill (&surface->log, + surface->target, op, source, path, + fill_rule, tolerance, antialias, + clip, t); + + add_record_fill (&device->log, + surface->target, op, source, path, + fill_rule, tolerance, antialias, + clip, t); + + do_callbacks (surface, &surface->fill_callbacks); + + return CAIRO_STATUS_SUCCESS; +} + +static void +add_record_stroke (cairo_observation_t *log, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + cairo_observation_record_t record; + cairo_int_status_t status; + + add_record (log, + record_stroke (&record, + target, op, source, + path, style, ctm,ctm_inverse, + tolerance, antialias, + clip, elapsed)); + + if (log->record) { + status = log->record->base.backend->stroke (&log->record->base, + op, source, + path, style, ctm,ctm_inverse, + tolerance, antialias, + clip); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + if (_cairo_time_gt (elapsed, log->stroke.slowest.elapsed)) + log->stroke.slowest = record; + log->stroke.elapsed = _cairo_time_add (log->stroke.elapsed, elapsed); +} + +static cairo_int_status_t +_cairo_surface_observer_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_device_observer_t *device = to_device (surface); + cairo_composite_rectangles_t composite; + cairo_int_status_t status; + cairo_time_t t; + int x, y; + + surface->log.stroke.count++; + surface->log.stroke.operators[op]++; + surface->log.stroke.antialias[antialias]++; + surface->log.stroke.caps[style->line_cap]++; + surface->log.stroke.joins[style->line_join]++; + add_pattern (&surface->log.stroke.source, source, surface->target); + add_path (&surface->log.stroke.path, path, FALSE); + add_clip (&surface->log.stroke.clip, clip); + + device->log.stroke.count++; + device->log.stroke.operators[op]++; + device->log.stroke.antialias[antialias]++; + device->log.stroke.caps[style->line_cap]++; + device->log.stroke.joins[style->line_join]++; + add_pattern (&device->log.stroke.source, source, surface->target); + add_path (&device->log.stroke.path, path, FALSE); + add_clip (&device->log.stroke.clip, clip); + + status = _cairo_composite_rectangles_init_for_stroke (&composite, + surface->target, + op, source, + path, style, ctm, + clip); + if (unlikely (status)) { + surface->log.stroke.noop++; + device->log.stroke.noop++; + return status; + } + + midpt (&composite, &x, &y); + + add_extents (&surface->log.stroke.extents, &composite); + add_extents (&device->log.stroke.extents, &composite); + _cairo_composite_rectangles_fini (&composite); + + t = _cairo_time_get (); + status = _cairo_surface_stroke (surface->target, + op, source, path, + style, ctm, ctm_inverse, + tolerance, antialias, + clip); + if (unlikely (status)) + return status; + + _cairo_surface_sync (surface->target, x, y); + t = _cairo_time_get_delta (t); + + add_record_stroke (&surface->log, + surface->target, op, source, path, + style, ctm,ctm_inverse, + tolerance, antialias, + clip, t); + + add_record_stroke (&device->log, + surface->target, op, source, path, + style, ctm,ctm_inverse, + tolerance, antialias, + clip, t); + + do_callbacks (surface, &surface->stroke_callbacks); + + return CAIRO_STATUS_SUCCESS; +} + +static void +add_record_glyphs (cairo_observation_t *log, + cairo_surface_t *target, + cairo_operator_t op, + const cairo_pattern_t*source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip, + cairo_time_t elapsed) +{ + cairo_observation_record_t record; + cairo_int_status_t status; + + add_record (log, + record_glyphs (&record, + target, op, source, + glyphs, num_glyphs, scaled_font, + clip, elapsed)); + + if (log->record) { + status = log->record->base.backend->show_text_glyphs (&log->record->base, + op, source, + NULL, 0, + glyphs, num_glyphs, + NULL, 0, 0, + scaled_font, + clip); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + if (_cairo_time_gt (elapsed, log->glyphs.slowest.elapsed)) + log->glyphs.slowest = record; + log->glyphs.elapsed = _cairo_time_add (log->glyphs.elapsed, elapsed); +} + +static cairo_int_status_t +_cairo_surface_observer_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_device_observer_t *device = to_device (surface); + cairo_composite_rectangles_t composite; + cairo_int_status_t status; + cairo_glyph_t *dev_glyphs; + cairo_time_t t; + int x, y; + + surface->log.glyphs.count++; + surface->log.glyphs.operators[op]++; + add_pattern (&surface->log.glyphs.source, source, surface->target); + add_clip (&surface->log.glyphs.clip, clip); + + device->log.glyphs.count++; + device->log.glyphs.operators[op]++; + add_pattern (&device->log.glyphs.source, source, surface->target); + add_clip (&device->log.glyphs.clip, clip); + + status = _cairo_composite_rectangles_init_for_glyphs (&composite, + surface->target, + op, source, + scaled_font, + glyphs, num_glyphs, + clip, + NULL); + if (unlikely (status)) { + surface->log.glyphs.noop++; + device->log.glyphs.noop++; + return status; + } + + midpt (&composite, &x, &y); + + add_extents (&surface->log.glyphs.extents, &composite); + add_extents (&device->log.glyphs.extents, &composite); + _cairo_composite_rectangles_fini (&composite); + + /* XXX We have to copy the glyphs, because the backend is allowed to + * modify! */ + dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); + if (unlikely (dev_glyphs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + memcpy (dev_glyphs, glyphs, num_glyphs * sizeof (cairo_glyph_t)); + + t = _cairo_time_get (); + status = _cairo_surface_show_text_glyphs (surface->target, op, source, + NULL, 0, + dev_glyphs, num_glyphs, + NULL, 0, 0, + scaled_font, + clip); + free (dev_glyphs); + if (unlikely (status)) + return status; + + _cairo_surface_sync (surface->target, x, y); + t = _cairo_time_get_delta (t); + + add_record_glyphs (&surface->log, + surface->target, op, source, + glyphs, num_glyphs, scaled_font, + clip, t); + + add_record_glyphs (&device->log, + surface->target, op, source, + glyphs, num_glyphs, scaled_font, + clip, t); + + do_callbacks (surface, &surface->glyphs_callbacks); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_surface_observer_flush (void *abstract_surface, unsigned flags) +{ + cairo_surface_observer_t *surface = abstract_surface; + + do_callbacks (surface, &surface->flush_callbacks); + return _cairo_surface_flush (surface->target, flags); +} + +static cairo_status_t +_cairo_surface_observer_mark_dirty (void *abstract_surface, + int x, int y, + int width, int height) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_status_t status; + + printf ("mark-dirty (%d, %d) x (%d, %d)\n", x, y, width, height); + + status = CAIRO_STATUS_SUCCESS; + if (surface->target->backend->mark_dirty_rectangle) + status = surface->target->backend->mark_dirty_rectangle (surface->target, + x,y, width,height); + + return status; +} + +static cairo_int_status_t +_cairo_surface_observer_copy_page (void *abstract_surface) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_status_t status; + + status = CAIRO_STATUS_SUCCESS; + if (surface->target->backend->copy_page) + status = surface->target->backend->copy_page (surface->target); + + return status; +} + +static cairo_int_status_t +_cairo_surface_observer_show_page (void *abstract_surface) +{ + cairo_surface_observer_t *surface = abstract_surface; + cairo_status_t status; + + status = CAIRO_STATUS_SUCCESS; + if (surface->target->backend->show_page) + status = surface->target->backend->show_page (surface->target); + + return status; +} + +static cairo_bool_t +_cairo_surface_observer_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_surface_observer_t *surface = abstract_surface; + return _cairo_surface_get_extents (surface->target, extents); +} + +static void +_cairo_surface_observer_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_surface_observer_t *surface = abstract_surface; + + if (surface->target->backend->get_font_options != NULL) + surface->target->backend->get_font_options (surface->target, options); +} + +static cairo_surface_t * +_cairo_surface_observer_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_surface_observer_t *surface = abstract_surface; + return _cairo_surface_get_source (surface->target, extents); +} + +static cairo_status_t +_cairo_surface_observer_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_surface_observer_t *surface = abstract_surface; + + surface->log.num_sources_acquired++; + to_device (surface)->log.num_sources_acquired++; + + return _cairo_surface_acquire_source_image (surface->target, + image_out, image_extra); +} + +static void +_cairo_surface_observer_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_observer_t *surface = abstract_surface; + + _cairo_surface_release_source_image (surface->target, image, image_extra); +} + +static cairo_surface_t * +_cairo_surface_observer_snapshot (void *abstract_surface) +{ + cairo_surface_observer_t *surface = abstract_surface; + + /* XXX hook onto the snapshot so that we measure number of reads */ + + if (surface->target->backend->snapshot) + return surface->target->backend->snapshot (surface->target); + + return NULL; +} + +static cairo_t * +_cairo_surface_observer_create_context(void *target) +{ + cairo_surface_observer_t *surface = target; + + if (_cairo_surface_is_subsurface (&surface->base)) + surface = (cairo_surface_observer_t *) + _cairo_surface_subsurface_get_target (&surface->base); + + surface->log.num_contexts++; + to_device (surface)->log.num_contexts++; + + return surface->target->backend->create_context (target); +} + +static const cairo_surface_backend_t _cairo_surface_observer_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_OBSERVER, + _cairo_surface_observer_finish, + + _cairo_surface_observer_create_context, + + _cairo_surface_observer_create_similar, + _cairo_surface_observer_create_similar_image, + _cairo_surface_observer_map_to_image, + _cairo_surface_observer_unmap_image, + + _cairo_surface_observer_source, + _cairo_surface_observer_acquire_source_image, + _cairo_surface_observer_release_source_image, + _cairo_surface_observer_snapshot, + + _cairo_surface_observer_copy_page, + _cairo_surface_observer_show_page, + + _cairo_surface_observer_get_extents, + _cairo_surface_observer_get_font_options, + + _cairo_surface_observer_flush, + _cairo_surface_observer_mark_dirty, + + _cairo_surface_observer_paint, + _cairo_surface_observer_mask, + _cairo_surface_observer_stroke, + _cairo_surface_observer_fill, + NULL, /* fill-stroke */ + _cairo_surface_observer_glyphs, +}; + +/** + * cairo_surface_create_observer: + * @target: an existing surface for which the observer will watch + * @mode: sets the mode of operation (normal vs. record) + * + * Create a new surface that exists solely to watch another is doing. In + * the process it will log operations and times, which are fast, which are + * slow, which are frequent, etc. + * + * The @mode parameter can be set to either CAIRO_SURFACE_OBSERVER_NORMAL + * or CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS, to control whether or not + * the internal observer should record operations. + * + * Return value: a pointer to the newly allocated surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if @other is already in an error state + * or any other error occurs. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_surface_create_observer (cairo_surface_t *target, + cairo_surface_observer_mode_t mode) +{ + cairo_device_t *device; + cairo_surface_t *surface; + cairo_bool_t record; + + if (unlikely (target->status)) + return _cairo_surface_create_in_error (target->status); + if (unlikely (target->finished)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + record = mode & CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS; + device = _cairo_device_create_observer_internal (target->device, record); + if (unlikely (device->status)) + return _cairo_surface_create_in_error (device->status); + + surface = _cairo_surface_create_observer_internal (device, target); + cairo_device_destroy (device); + + return surface; +} + +static cairo_status_t +_cairo_surface_observer_add_callback (cairo_list_t *head, + cairo_surface_observer_callback_t func, + void *data) +{ + struct callback_list *cb; + + cb = malloc (sizeof (*cb)); + if (unlikely (cb == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + cairo_list_add (&cb->link, head); + cb->func = func; + cb->data = data; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +cairo_surface_observer_add_paint_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->paint_callbacks, + func, data); +} + +cairo_status_t +cairo_surface_observer_add_mask_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->mask_callbacks, + func, data); +} + +cairo_status_t +cairo_surface_observer_add_fill_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->fill_callbacks, + func, data); +} + +cairo_status_t +cairo_surface_observer_add_stroke_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->stroke_callbacks, + func, data); +} + +cairo_status_t +cairo_surface_observer_add_glyphs_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->glyphs_callbacks, + func, data); +} + +cairo_status_t +cairo_surface_observer_add_flush_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->flush_callbacks, + func, data); +} + +cairo_status_t +cairo_surface_observer_add_finish_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return abstract_surface->status; + + if (! _cairo_surface_is_observer (abstract_surface)) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *)abstract_surface; + return _cairo_surface_observer_add_callback (&surface->finish_callbacks, + func, data); +} + +static void +print_extents (cairo_output_stream_t *stream, const struct extents *e) +{ + _cairo_output_stream_printf (stream, + " extents: total %g, avg %g [unbounded %d]\n", + e->area.sum, + e->area.sum / e->area.count, + e->unbounded); +} + +static inline int ordercmp (int a, int b, const unsigned int *array) +{ + /* high to low */ + return array[b] - array[a]; +} +CAIRO_COMBSORT_DECLARE_WITH_DATA (sort_order, int, ordercmp) + +static void +print_array (cairo_output_stream_t *stream, + const unsigned int *array, + const char **names, + int count) +{ + int order[64]; + int i, j; + + assert (count < ARRAY_LENGTH (order)); + for (i = j = 0; i < count; i++) { + if (array[i] != 0) + order[j++] = i; + } + + sort_order (order, j, (void *)array); + for (i = 0; i < j; i++) + _cairo_output_stream_printf (stream, " %d %s%s", + array[order[i]], names[order[i]], + i < j -1 ? "," : ""); +} + +static const char *operator_names[] = { + "CLEAR", /* CAIRO_OPERATOR_CLEAR */ + + "SOURCE", /* CAIRO_OPERATOR_SOURCE */ + "OVER", /* CAIRO_OPERATOR_OVER */ + "IN", /* CAIRO_OPERATOR_IN */ + "OUT", /* CAIRO_OPERATOR_OUT */ + "ATOP", /* CAIRO_OPERATOR_ATOP */ + + "DEST", /* CAIRO_OPERATOR_DEST */ + "DEST_OVER", /* CAIRO_OPERATOR_DEST_OVER */ + "DEST_IN", /* CAIRO_OPERATOR_DEST_IN */ + "DEST_OUT", /* CAIRO_OPERATOR_DEST_OUT */ + "DEST_ATOP", /* CAIRO_OPERATOR_DEST_ATOP */ + + "XOR", /* CAIRO_OPERATOR_XOR */ + "ADD", /* CAIRO_OPERATOR_ADD */ + "SATURATE", /* CAIRO_OPERATOR_SATURATE */ + + "MULTIPLY", /* CAIRO_OPERATOR_MULTIPLY */ + "SCREEN", /* CAIRO_OPERATOR_SCREEN */ + "OVERLAY", /* CAIRO_OPERATOR_OVERLAY */ + "DARKEN", /* CAIRO_OPERATOR_DARKEN */ + "LIGHTEN", /* CAIRO_OPERATOR_LIGHTEN */ + "DODGE", /* CAIRO_OPERATOR_COLOR_DODGE */ + "BURN", /* CAIRO_OPERATOR_COLOR_BURN */ + "HARD_LIGHT", /* CAIRO_OPERATOR_HARD_LIGHT */ + "SOFT_LIGHT", /* CAIRO_OPERATOR_SOFT_LIGHT */ + "DIFFERENCE", /* CAIRO_OPERATOR_DIFFERENCE */ + "EXCLUSION", /* CAIRO_OPERATOR_EXCLUSION */ + "HSL_HUE", /* CAIRO_OPERATOR_HSL_HUE */ + "HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */ + "HSL_COLOR", /* CAIRO_OPERATOR_HSL_COLOR */ + "HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */ +}; +static void +print_operators (cairo_output_stream_t *stream, unsigned int *array) +{ + _cairo_output_stream_printf (stream, " op:"); + print_array (stream, array, operator_names, NUM_OPERATORS); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *fill_rule_names[] = { + "non-zero", + "even-odd", +}; +static void +print_fill_rule (cairo_output_stream_t *stream, unsigned int *array) +{ + _cairo_output_stream_printf (stream, " fill rule:"); + print_array (stream, array, fill_rule_names, ARRAY_LENGTH(fill_rule_names)); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *cap_names[] = { + "butt", /* CAIRO_LINE_CAP_BUTT */ + "round", /* CAIRO_LINE_CAP_ROUND */ + "square" /* CAIRO_LINE_CAP_SQUARE */ +}; +static void +print_line_caps (cairo_output_stream_t *stream, unsigned int *array) +{ + _cairo_output_stream_printf (stream, " caps:"); + print_array (stream, array, cap_names, NUM_CAPS); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *join_names[] = { + "miter", /* CAIRO_LINE_JOIN_MITER */ + "round", /* CAIRO_LINE_JOIN_ROUND */ + "bevel", /* CAIRO_LINE_JOIN_BEVEL */ +}; +static void +print_line_joins (cairo_output_stream_t *stream, unsigned int *array) +{ + _cairo_output_stream_printf (stream, " joins:"); + print_array (stream, array, join_names, NUM_JOINS); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *antialias_names[] = { + "default", + "none", + "gray", + "subpixel", + "fast", + "good", + "best" +}; +static void +print_antialias (cairo_output_stream_t *stream, unsigned int *array) +{ + _cairo_output_stream_printf (stream, " antialias:"); + print_array (stream, array, antialias_names, NUM_ANTIALIAS); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *pattern_names[] = { + "native", + "record", + "other surface", + "solid", + "linear", + "radial", + "mesh", + "raster" +}; +static void +print_pattern (cairo_output_stream_t *stream, + const char *name, + const struct pattern *p) +{ + _cairo_output_stream_printf (stream, " %s:", name); + print_array (stream, p->type, pattern_names, ARRAY_LENGTH (pattern_names)); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *path_names[] = { + "empty", + "pixel-aligned", + "rectliinear", + "straight", + "curved", +}; +static void +print_path (cairo_output_stream_t *stream, + const struct path *p) +{ + _cairo_output_stream_printf (stream, " path:"); + print_array (stream, p->type, path_names, ARRAY_LENGTH (path_names)); + _cairo_output_stream_printf (stream, "\n"); +} + +static const char *clip_names[] = { + "none", + "region", + "boxes", + "single path", + "polygon", + "general", +}; +static void +print_clip (cairo_output_stream_t *stream, const struct clip *c) +{ + _cairo_output_stream_printf (stream, " clip:"); + print_array (stream, c->type, clip_names, ARRAY_LENGTH (clip_names)); + _cairo_output_stream_printf (stream, "\n"); +} + +static void +print_record (cairo_output_stream_t *stream, + cairo_observation_record_t *r) +{ + _cairo_output_stream_printf (stream, " op: %s\n", operator_names[r->op]); + _cairo_output_stream_printf (stream, " source: %s\n", + pattern_names[r->source]); + if (r->mask != -1) + _cairo_output_stream_printf (stream, " mask: %s\n", + pattern_names[r->mask]); + if (r->num_glyphs != -1) + _cairo_output_stream_printf (stream, " num_glyphs: %d\n", + r->num_glyphs); + if (r->path != -1) + _cairo_output_stream_printf (stream, " path: %s\n", + path_names[r->path]); + if (r->fill_rule != -1) + _cairo_output_stream_printf (stream, " fill rule: %s\n", + fill_rule_names[r->fill_rule]); + if (r->antialias != -1) + _cairo_output_stream_printf (stream, " antialias: %s\n", + antialias_names[r->antialias]); + _cairo_output_stream_printf (stream, " clip: %s\n", clip_names[r->clip]); + _cairo_output_stream_printf (stream, " elapsed: %f ns\n", + _cairo_time_to_ns (r->elapsed)); +} + +static double percent (cairo_time_t a, cairo_time_t b) +{ + /* Fake %.1f */ + return _cairo_round (_cairo_time_to_s (a) * 1000 / + _cairo_time_to_s (b)) / 10; +} + +static cairo_bool_t +replay_record (cairo_observation_t *log, + cairo_observation_record_t *r, + cairo_device_t *script) +{ +#if CAIRO_HAS_SCRIPT_SURFACE + cairo_surface_t *surface; + cairo_int_status_t status; + + if (log->record == NULL || script == NULL) + return FALSE; + + surface = cairo_script_surface_create (script, + r->target_content, + r->target_width, + r->target_height); + status = + _cairo_recording_surface_replay_one (log->record, r->index, surface); + cairo_surface_destroy (surface); + + assert (status == CAIRO_INT_STATUS_SUCCESS); + + return TRUE; +#else + return FALSE; +#endif +} + +static cairo_time_t +_cairo_observation_total_elapsed (cairo_observation_t *log) +{ + cairo_time_t total; + + total = log->paint.elapsed; + total = _cairo_time_add (total, log->mask.elapsed); + total = _cairo_time_add (total, log->fill.elapsed); + total = _cairo_time_add (total, log->stroke.elapsed); + total = _cairo_time_add (total, log->glyphs.elapsed); + + return total; +} + +static void +_cairo_observation_print (cairo_output_stream_t *stream, + cairo_observation_t *log) +{ + cairo_device_t *script; + cairo_time_t total; + +#if CAIRO_HAS_SCRIPT_SURFACE + script = _cairo_script_context_create_internal (stream); + _cairo_script_context_attach_snapshots (script, FALSE); +#else + script = NULL; +#endif + + total = _cairo_observation_total_elapsed (log); + + _cairo_output_stream_printf (stream, "elapsed: %f\n", + _cairo_time_to_ns (total)); + _cairo_output_stream_printf (stream, "surfaces: %d\n", + log->num_surfaces); + _cairo_output_stream_printf (stream, "contexts: %d\n", + log->num_contexts); + _cairo_output_stream_printf (stream, "sources acquired: %d\n", + log->num_sources_acquired); + + + _cairo_output_stream_printf (stream, "paint: count %d [no-op %d], elapsed %f [%f%%]\n", + log->paint.count, log->paint.noop, + _cairo_time_to_ns (log->paint.elapsed), + percent (log->paint.elapsed, total)); + if (log->paint.count) { + print_extents (stream, &log->paint.extents); + print_operators (stream, log->paint.operators); + print_pattern (stream, "source", &log->paint.source); + print_clip (stream, &log->paint.clip); + + _cairo_output_stream_printf (stream, "slowest paint: %f%%\n", + percent (log->paint.slowest.elapsed, + log->paint.elapsed)); + print_record (stream, &log->paint.slowest); + + _cairo_output_stream_printf (stream, "\n"); + if (replay_record (log, &log->paint.slowest, script)) + _cairo_output_stream_printf (stream, "\n\n"); + } + + _cairo_output_stream_printf (stream, "mask: count %d [no-op %d], elapsed %f [%f%%]\n", + log->mask.count, log->mask.noop, + _cairo_time_to_ns (log->mask.elapsed), + percent (log->mask.elapsed, total)); + if (log->mask.count) { + print_extents (stream, &log->mask.extents); + print_operators (stream, log->mask.operators); + print_pattern (stream, "source", &log->mask.source); + print_pattern (stream, "mask", &log->mask.mask); + print_clip (stream, &log->mask.clip); + + _cairo_output_stream_printf (stream, "slowest mask: %f%%\n", + percent (log->mask.slowest.elapsed, + log->mask.elapsed)); + print_record (stream, &log->mask.slowest); + + _cairo_output_stream_printf (stream, "\n"); + if (replay_record (log, &log->mask.slowest, script)) + _cairo_output_stream_printf (stream, "\n\n"); + } + + _cairo_output_stream_printf (stream, "fill: count %d [no-op %d], elaspsed %f [%f%%]\n", + log->fill.count, log->fill.noop, + _cairo_time_to_ns (log->fill.elapsed), + percent (log->fill.elapsed, total)); + if (log->fill.count) { + print_extents (stream, &log->fill.extents); + print_operators (stream, log->fill.operators); + print_pattern (stream, "source", &log->fill.source); + print_path (stream, &log->fill.path); + print_fill_rule (stream, log->fill.fill_rule); + print_antialias (stream, log->fill.antialias); + print_clip (stream, &log->fill.clip); + + _cairo_output_stream_printf (stream, "slowest fill: %f%%\n", + percent (log->fill.slowest.elapsed, + log->fill.elapsed)); + print_record (stream, &log->fill.slowest); + + _cairo_output_stream_printf (stream, "\n"); + if (replay_record (log, &log->fill.slowest, script)) + _cairo_output_stream_printf (stream, "\n\n"); + } + + _cairo_output_stream_printf (stream, "stroke: count %d [no-op %d], elapsed %f [%f%%]\n", + log->stroke.count, log->stroke.noop, + _cairo_time_to_ns (log->stroke.elapsed), + percent (log->stroke.elapsed, total)); + if (log->stroke.count) { + print_extents (stream, &log->stroke.extents); + print_operators (stream, log->stroke.operators); + print_pattern (stream, "source", &log->stroke.source); + print_path (stream, &log->stroke.path); + print_antialias (stream, log->stroke.antialias); + print_line_caps (stream, log->stroke.caps); + print_line_joins (stream, log->stroke.joins); + print_clip (stream, &log->stroke.clip); + + _cairo_output_stream_printf (stream, "slowest stroke: %f%%\n", + percent (log->stroke.slowest.elapsed, + log->stroke.elapsed)); + print_record (stream, &log->stroke.slowest); + + _cairo_output_stream_printf (stream, "\n"); + if (replay_record (log, &log->stroke.slowest, script)) + _cairo_output_stream_printf (stream, "\n\n"); + } + + _cairo_output_stream_printf (stream, "glyphs: count %d [no-op %d], elasped %f [%f%%]\n", + log->glyphs.count, log->glyphs.noop, + _cairo_time_to_ns (log->glyphs.elapsed), + percent (log->glyphs.elapsed, total)); + if (log->glyphs.count) { + print_extents (stream, &log->glyphs.extents); + print_operators (stream, log->glyphs.operators); + print_pattern (stream, "source", &log->glyphs.source); + print_clip (stream, &log->glyphs.clip); + + _cairo_output_stream_printf (stream, "slowest glyphs: %f%%\n", + percent (log->glyphs.slowest.elapsed, + log->glyphs.elapsed)); + print_record (stream, &log->glyphs.slowest); + + _cairo_output_stream_printf (stream, "\n"); + if (replay_record (log, &log->glyphs.slowest, script)) + _cairo_output_stream_printf (stream, "\n\n"); + } + + cairo_device_destroy (script); +} + +cairo_status_t +cairo_surface_observer_print (cairo_surface_t *abstract_surface, + cairo_write_func_t write_func, + void *closure) +{ + cairo_output_stream_t *stream; + cairo_surface_observer_t *surface; + + if (unlikely (abstract_surface->status)) + return abstract_surface->status; + + if (unlikely (! _cairo_surface_is_observer (abstract_surface))) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + surface = (cairo_surface_observer_t *) abstract_surface; + + stream = _cairo_output_stream_create (write_func, NULL, closure); + _cairo_observation_print (stream, &surface->log); + return _cairo_output_stream_destroy (stream); +} + +double +cairo_surface_observer_elapsed (cairo_surface_t *abstract_surface) +{ + cairo_surface_observer_t *surface; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count))) + return -1; + + if (! _cairo_surface_is_observer (abstract_surface)) + return -1; + + surface = (cairo_surface_observer_t *) abstract_surface; + return _cairo_time_to_ns (_cairo_observation_total_elapsed (&surface->log)); +} + +cairo_status_t +cairo_device_observer_print (cairo_device_t *abstract_device, + cairo_write_func_t write_func, + void *closure) +{ + cairo_output_stream_t *stream; + cairo_device_observer_t *device; + + if (unlikely (abstract_device->status)) + return abstract_device->status; + + if (unlikely (! _cairo_device_is_observer (abstract_device))) + return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + + device = (cairo_device_observer_t *) abstract_device; + + stream = _cairo_output_stream_create (write_func, NULL, closure); + _cairo_observation_print (stream, &device->log); + return _cairo_output_stream_destroy (stream); +} + +double +cairo_device_observer_elapsed (cairo_device_t *abstract_device) +{ + cairo_device_observer_t *device; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) + return -1; + + if (! _cairo_device_is_observer (abstract_device)) + return -1; + + device = (cairo_device_observer_t *) abstract_device; + return _cairo_time_to_ns (_cairo_observation_total_elapsed (&device->log)); +} + +double +cairo_device_observer_paint_elapsed (cairo_device_t *abstract_device) +{ + cairo_device_observer_t *device; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) + return -1; + + if (! _cairo_device_is_observer (abstract_device)) + return -1; + + device = (cairo_device_observer_t *) abstract_device; + return _cairo_time_to_ns (device->log.paint.elapsed); +} + +double +cairo_device_observer_mask_elapsed (cairo_device_t *abstract_device) +{ + cairo_device_observer_t *device; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) + return -1; + + if (! _cairo_device_is_observer (abstract_device)) + return -1; + + device = (cairo_device_observer_t *) abstract_device; + return _cairo_time_to_ns (device->log.mask.elapsed); +} + +double +cairo_device_observer_fill_elapsed (cairo_device_t *abstract_device) +{ + cairo_device_observer_t *device; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) + return -1; + + if (! _cairo_device_is_observer (abstract_device)) + return -1; + + device = (cairo_device_observer_t *) abstract_device; + return _cairo_time_to_ns (device->log.fill.elapsed); +} + +double +cairo_device_observer_stroke_elapsed (cairo_device_t *abstract_device) +{ + cairo_device_observer_t *device; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) + return -1; + + if (! _cairo_device_is_observer (abstract_device)) + return -1; + + device = (cairo_device_observer_t *) abstract_device; + return _cairo_time_to_ns (device->log.stroke.elapsed); +} + +double +cairo_device_observer_glyphs_elapsed (cairo_device_t *abstract_device) +{ + cairo_device_observer_t *device; + + if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count))) + return -1; + + if (! _cairo_device_is_observer (abstract_device)) + return -1; + + device = (cairo_device_observer_t *) abstract_device; + return _cairo_time_to_ns (device->log.glyphs.elapsed); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-offset-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-offset-private.h new file mode 100644 index 00000000000..310ba5691cd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-offset-private.h @@ -0,0 +1,95 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_OFFSET_PRIVATE_H +#define CAIRO_SURFACE_OFFSET_PRIVATE_H + +#include "cairo-types-private.h" + +CAIRO_BEGIN_DECLS + +cairo_private cairo_status_t +_cairo_surface_offset_paint (cairo_surface_t *target, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_offset_mask (cairo_surface_t *target, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_offset_stroke (cairo_surface_t *surface, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_offset_fill (cairo_surface_t *surface, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t*source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_offset_glyphs (cairo_surface_t *surface, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_clip_t *clip); + +#endif /* CAIRO_SURFACE_OFFSET_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-offset.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-offset.c new file mode 100644 index 00000000000..98f57f29804 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-offset.c @@ -0,0 +1,308 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * Copyright © 2007 Adrian Johnson + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-error-private.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-offset-private.h" + +/* A collection of routines to facilitate drawing to an alternate surface. */ + +static void +_copy_transformed_pattern (cairo_pattern_t *pattern, + const cairo_pattern_t *original, + const cairo_matrix_t *ctm_inverse) +{ + _cairo_pattern_init_static_copy (pattern, original); + + if (! _cairo_matrix_is_identity (ctm_inverse)) + _cairo_pattern_transform (pattern, ctm_inverse); +} + +cairo_status_t +_cairo_surface_offset_paint (cairo_surface_t *target, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_clip_t *dev_clip = (cairo_clip_t *) clip; + cairo_pattern_union_t source_copy; + + if (unlikely (target->status)) + return target->status; + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + if (x | y) { + cairo_matrix_t m; + + dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); + + cairo_matrix_init_translate (&m, x, y); + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + } + + status = _cairo_surface_paint (target, op, source, dev_clip); + + if (dev_clip != clip) + _cairo_clip_destroy (dev_clip); + + return status; +} + +cairo_status_t +_cairo_surface_offset_mask (cairo_surface_t *target, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_clip_t *dev_clip = (cairo_clip_t *) clip; + cairo_pattern_union_t source_copy; + cairo_pattern_union_t mask_copy; + + if (unlikely (target->status)) + return target->status; + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + if (x | y) { + cairo_matrix_t m; + + dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); + + cairo_matrix_init_translate (&m, x, y); + _copy_transformed_pattern (&source_copy.base, source, &m); + _copy_transformed_pattern (&mask_copy.base, mask, &m); + source = &source_copy.base; + mask = &mask_copy.base; + } + + status = _cairo_surface_mask (target, op, + source, mask, + dev_clip); + + if (dev_clip != clip) + _cairo_clip_destroy (dev_clip); + + return status; +} + +cairo_status_t +_cairo_surface_offset_stroke (cairo_surface_t *surface, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t*stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; + cairo_clip_t *dev_clip = (cairo_clip_t *) clip; + cairo_matrix_t dev_ctm = *ctm; + cairo_matrix_t dev_ctm_inverse = *ctm_inverse; + cairo_pattern_union_t source_copy; + cairo_status_t status; + + if (unlikely (surface->status)) + return surface->status; + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + if (x | y) { + cairo_matrix_t m; + + dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); + + status = _cairo_path_fixed_init_copy (&path_copy, dev_path); + if (unlikely (status)) + goto FINISH; + + _cairo_path_fixed_translate (&path_copy, + _cairo_fixed_from_int (-x), + _cairo_fixed_from_int (-y)); + dev_path = &path_copy; + + cairo_matrix_init_translate (&m, -x, -y); + cairo_matrix_multiply (&dev_ctm, &dev_ctm, &m); + + cairo_matrix_init_translate (&m, x, y); + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + cairo_matrix_multiply (&dev_ctm_inverse, &m, &dev_ctm_inverse); + } + + status = _cairo_surface_stroke (surface, op, source, + dev_path, stroke_style, + &dev_ctm, &dev_ctm_inverse, + tolerance, antialias, + dev_clip); + +FINISH: + if (dev_path != path) + _cairo_path_fixed_fini (dev_path); + if (dev_clip != clip) + _cairo_clip_destroy (dev_clip); + + return status; +} + +cairo_status_t +_cairo_surface_offset_fill (cairo_surface_t *surface, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t*source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; + cairo_clip_t *dev_clip = (cairo_clip_t *) clip; + cairo_pattern_union_t source_copy; + + if (unlikely (surface->status)) + return surface->status; + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + if (x | y) { + cairo_matrix_t m; + + dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); + + status = _cairo_path_fixed_init_copy (&path_copy, dev_path); + if (unlikely (status)) + goto FINISH; + + _cairo_path_fixed_translate (&path_copy, + _cairo_fixed_from_int (-x), + _cairo_fixed_from_int (-y)); + dev_path = &path_copy; + + cairo_matrix_init_translate (&m, x, y); + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + } + + status = _cairo_surface_fill (surface, op, source, + dev_path, fill_rule, + tolerance, antialias, + dev_clip); + +FINISH: + if (dev_path != path) + _cairo_path_fixed_fini (dev_path); + if (dev_clip != clip) + _cairo_clip_destroy (dev_clip); + + return status; +} + +cairo_status_t +_cairo_surface_offset_glyphs (cairo_surface_t *surface, + int x, int y, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_clip_t *dev_clip = (cairo_clip_t *) clip; + cairo_pattern_union_t source_copy; + cairo_glyph_t *dev_glyphs; + int i; + + if (unlikely (surface->status)) + return surface->status; + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); + if (dev_glyphs == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + memcpy (dev_glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); + + if (x | y) { + cairo_matrix_t m; + + dev_clip = _cairo_clip_copy_with_translation (clip, -x, -y); + + cairo_matrix_init_translate (&m, x, y); + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + + for (i = 0; i < num_glyphs; i++) { + dev_glyphs[i].x -= x; + dev_glyphs[i].y -= y; + } + } + + status = _cairo_surface_show_text_glyphs (surface, op, source, + NULL, 0, + dev_glyphs, num_glyphs, + NULL, 0, 0, + scaled_font, + dev_clip); + + if (dev_clip != clip) + _cairo_clip_destroy (dev_clip); + free (dev_glyphs); + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-private.h new file mode 100644 index 00000000000..f20ab073932 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-private.h @@ -0,0 +1,121 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_SURFACE_PRIVATE_H +#define CAIRO_SURFACE_PRIVATE_H + +#include "cairo.h" + +#include "cairo-types-private.h" +#include "cairo-list-private.h" +#include "cairo-reference-count-private.h" +#include "cairo-clip-private.h" +#include "cairo-surface-backend-private.h" + +typedef void (*cairo_surface_func_t) (cairo_surface_t *); + +struct _cairo_surface { + const cairo_surface_backend_t *backend; + cairo_device_t *device; + + /* We allow surfaces to override the backend->type by shoving something + * else into surface->type. This is for "wrapper" surfaces that want to + * hide their internal type from the user-level API. */ + cairo_surface_type_t type; + + cairo_content_t content; + + cairo_reference_count_t ref_count; + cairo_status_t status; + unsigned int unique_id; + unsigned int serial; + cairo_damage_t *damage; + + unsigned _finishing : 1; + unsigned finished : 1; + unsigned is_clear : 1; + unsigned has_font_options : 1; + unsigned owns_device : 1; + + cairo_user_data_array_t user_data; + cairo_user_data_array_t mime_data; + + cairo_matrix_t device_transform; + cairo_matrix_t device_transform_inverse; + cairo_list_t device_transform_observers; + + /* The actual resolution of the device, in dots per inch. */ + double x_resolution; + double y_resolution; + + /* The resolution that should be used when generating image-based + * fallback; generally only used by the analysis/paginated + * surfaces + */ + double x_fallback_resolution; + double y_fallback_resolution; + + /* A "snapshot" surface is immutable. See _cairo_surface_snapshot. */ + cairo_surface_t *snapshot_of; + cairo_surface_func_t snapshot_detach; + /* current snapshots of this surface*/ + cairo_list_t snapshots; + /* place upon snapshot list */ + cairo_list_t snapshot; + + /* + * Surface font options, falling back to backend's default options, + * and set using _cairo_surface_set_font_options(), and propagated by + * cairo_surface_create_similar(). + */ + cairo_font_options_t font_options; +}; + +cairo_private cairo_surface_t * +_cairo_surface_create_in_error (cairo_status_t status); + +cairo_private cairo_surface_t * +_cairo_int_surface_create_in_error (cairo_int_status_t status); + +cairo_private cairo_surface_t * +_cairo_surface_get_source (cairo_surface_t *surface, + cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_surface_flush (cairo_surface_t *surface, unsigned flags); + +#endif /* CAIRO_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-inline.h new file mode 100644 index 00000000000..bf89c772b42 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-inline.h @@ -0,0 +1,67 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_SNAPSHOT_INLINE_H +#define CAIRO_SURFACE_SNAPSHOT_INLINE_H + +#include "cairo-surface-snapshot-private.h" +#include "cairo-surface-inline.h" + +static inline cairo_bool_t +_cairo_surface_snapshot_is_reused (cairo_surface_t *surface) +{ + return CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count) > 2; +} + +static inline cairo_surface_t * +_cairo_surface_snapshot_get_target (cairo_surface_t *surface) +{ + cairo_surface_snapshot_t *snapshot = (cairo_surface_snapshot_t *) surface; + cairo_surface_t *target; + + CAIRO_MUTEX_LOCK (snapshot->mutex); + target = _cairo_surface_reference (snapshot->target); + CAIRO_MUTEX_UNLOCK (snapshot->mutex); + + return target; +} + +static inline cairo_bool_t +_cairo_surface_is_snapshot (cairo_surface_t *surface) +{ + return surface->backend->type == (cairo_surface_type_t)CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT; +} + +#endif /* CAIRO_SURFACE_SNAPSHOT_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-private.h new file mode 100644 index 00000000000..58bee7b49dd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot-private.h @@ -0,0 +1,51 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_SNAPSHOT_PRIVATE_H +#define CAIRO_SURFACE_SNAPSHOT_PRIVATE_H + +#include "cairo-mutex-private.h" +#include "cairo-surface-private.h" +#include "cairo-surface-backend-private.h" + +struct _cairo_surface_snapshot { + cairo_surface_t base; + + cairo_mutex_t mutex; + cairo_surface_t *target; + cairo_surface_t *clone; +}; + +#endif /* CAIRO_SURFACE_SNAPSHOT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot.c new file mode 100644 index 00000000000..68bf9054ecd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-snapshot.c @@ -0,0 +1,289 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-snapshot-inline.h" + +static cairo_status_t +_cairo_surface_snapshot_finish (void *abstract_surface) +{ + cairo_surface_snapshot_t *surface = abstract_surface; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (surface->clone != NULL) { + cairo_surface_finish (surface->clone); + status = surface->clone->status; + + cairo_surface_destroy (surface->clone); + } + + CAIRO_MUTEX_FINI (surface->mutex); + + return status; +} + +static cairo_status_t +_cairo_surface_snapshot_flush (void *abstract_surface, unsigned flags) +{ + cairo_surface_snapshot_t *surface = abstract_surface; + cairo_surface_t *target; + cairo_status_t status; + + target = _cairo_surface_snapshot_get_target (&surface->base); + status = _cairo_surface_flush (target, flags); + cairo_surface_destroy (target); + + return status; +} + +static cairo_surface_t * +_cairo_surface_snapshot_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_surface_snapshot_t *surface = abstract_surface; + return _cairo_surface_get_source (surface->target, extents); /* XXX racy */ +} + +struct snapshot_extra { + cairo_surface_t *target; + void *extra; +}; + +static cairo_status_t +_cairo_surface_snapshot_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **extra_out) +{ + cairo_surface_snapshot_t *surface = abstract_surface; + struct snapshot_extra *extra; + cairo_status_t status; + + extra = malloc (sizeof (*extra)); + if (unlikely (extra == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + extra->target = _cairo_surface_snapshot_get_target (&surface->base); + status = _cairo_surface_acquire_source_image (extra->target, image_out, &extra->extra); + if (unlikely (status)) { + cairo_surface_destroy (extra->target); + free (extra); + } + + *extra_out = extra; + return status; +} + +static void +_cairo_surface_snapshot_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *_extra) +{ + struct snapshot_extra *extra = _extra; + + _cairo_surface_release_source_image (extra->target, image, extra->extra); + cairo_surface_destroy (extra->target); + free (extra); +} + +static cairo_bool_t +_cairo_surface_snapshot_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_surface_snapshot_t *surface = abstract_surface; + cairo_surface_t *target; + cairo_bool_t bounded; + + target = _cairo_surface_snapshot_get_target (&surface->base); + bounded = _cairo_surface_get_extents (target, extents); + cairo_surface_destroy (target); + + return bounded; +} + +static const cairo_surface_backend_t _cairo_surface_snapshot_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT, + _cairo_surface_snapshot_finish, + NULL, + + NULL, /* create similar */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_snapshot_source, + _cairo_surface_snapshot_acquire_source_image, + _cairo_surface_snapshot_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_surface_snapshot_get_extents, + NULL, /* get-font-options */ + + _cairo_surface_snapshot_flush, +}; + +static void +_cairo_surface_snapshot_copy_on_write (cairo_surface_t *surface) +{ + cairo_surface_snapshot_t *snapshot = (cairo_surface_snapshot_t *) surface; + cairo_image_surface_t *image; + cairo_surface_t *clone; + void *extra; + cairo_status_t status; + + TRACE ((stderr, "%s: target=%d\n", + __FUNCTION__, snapshot->target->unique_id)); + + /* We need to make an image copy of the original surface since the + * snapshot may exceed the lifetime of the original device, i.e. + * when we later need to use the snapshot the data may have already + * been lost. + */ + + CAIRO_MUTEX_LOCK (snapshot->mutex); + + if (snapshot->target->backend->snapshot != NULL) { + clone = snapshot->target->backend->snapshot (snapshot->target); + if (clone != NULL) { + assert (clone->status || ! _cairo_surface_is_snapshot (clone)); + goto done; + } + } + + /* XXX copy to a similar surface, leave acquisition till later? + * We should probably leave such decisions to the backend in case we + * rely upon devices/connections like Xlib. + */ + status = _cairo_surface_acquire_source_image (snapshot->target, &image, &extra); + if (unlikely (status)) { + snapshot->target = _cairo_surface_create_in_error (status); + status = _cairo_surface_set_error (surface, status); + goto unlock; + } + clone = image->base.backend->snapshot (&image->base); + _cairo_surface_release_source_image (snapshot->target, image, extra); + +done: + status = _cairo_surface_set_error (surface, clone->status); + snapshot->target = snapshot->clone = clone; + snapshot->base.type = clone->type; +unlock: + CAIRO_MUTEX_UNLOCK (snapshot->mutex); +} + +/** + * _cairo_surface_snapshot: + * @surface: a #cairo_surface_t + * + * Make an immutable reference to @surface. It is an error to call a + * surface-modifying function on the result of this function. The + * resulting 'snapshot' is a lazily copied-on-write surface i.e. it + * remains a reference to the original surface until that surface is + * written to again, at which time a copy is made of the original surface + * and the snapshot then points to that instead. Multiple snapshots of the + * same unmodified surface point to the same copy. + * + * The caller owns the return value and should call + * cairo_surface_destroy() when finished with it. This function will not + * return %NULL, but will return a nil surface instead. + * + * Return value: The snapshot surface. Note that the return surface + * may not necessarily be of the same type as @surface. + **/ +cairo_surface_t * +_cairo_surface_snapshot (cairo_surface_t *surface) +{ + cairo_surface_snapshot_t *snapshot; + cairo_status_t status; + + TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, surface->unique_id)); + + if (unlikely (surface->status)) + return _cairo_surface_create_in_error (surface->status); + + if (unlikely (surface->finished)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (surface->snapshot_of != NULL) + return cairo_surface_reference (surface); + + if (_cairo_surface_is_snapshot (surface)) + return cairo_surface_reference (surface); + + snapshot = (cairo_surface_snapshot_t *) + _cairo_surface_has_snapshot (surface, &_cairo_surface_snapshot_backend); + if (snapshot != NULL) + return cairo_surface_reference (&snapshot->base); + + snapshot = malloc (sizeof (cairo_surface_snapshot_t)); + if (unlikely (snapshot == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + _cairo_surface_init (&snapshot->base, + &_cairo_surface_snapshot_backend, + NULL, /* device */ + surface->content); + snapshot->base.type = surface->type; + + CAIRO_MUTEX_INIT (snapshot->mutex); + snapshot->target = surface; + snapshot->clone = NULL; + + status = _cairo_surface_copy_mime_data (&snapshot->base, surface); + if (unlikely (status)) { + cairo_surface_destroy (&snapshot->base); + return _cairo_surface_create_in_error (status); + } + + snapshot->base.device_transform = surface->device_transform; + snapshot->base.device_transform_inverse = surface->device_transform_inverse; + + _cairo_surface_attach_snapshot (surface, + &snapshot->base, + _cairo_surface_snapshot_copy_on_write); + + return &snapshot->base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-inline.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-inline.h new file mode 100644 index 00000000000..0cd09e63e70 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-inline.h @@ -0,0 +1,72 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_SUBSURFACE_INLINE_H +#define CAIRO_SURFACE_SUBSURFACE_INLINE_H + +#include "cairo-surface-subsurface-private.h" + +static inline cairo_surface_t * +_cairo_surface_subsurface_get_target (cairo_surface_t *surface) +{ + return ((cairo_surface_subsurface_t *) surface)->target; +} + +static inline void +_cairo_surface_subsurface_offset (cairo_surface_t *surface, + int *x, int *y) +{ + cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; + *x += ss->extents.x; + *y += ss->extents.y; +} + +static inline cairo_surface_t * +_cairo_surface_subsurface_get_target_with_offset (cairo_surface_t *surface, + int *x, int *y) +{ + cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; + *x += ss->extents.x; + *y += ss->extents.y; + return ss->target; +} + +static inline cairo_bool_t +_cairo_surface_is_subsurface (cairo_surface_t *surface) +{ + return surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE; +} + +#endif /* CAIRO_SURFACE_SUBSURFACE_INLINE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-private.h new file mode 100644 index 00000000000..89c5cc01b9d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface-private.h @@ -0,0 +1,55 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_SUBSURFACE_PRIVATE_H +#define CAIRO_SURFACE_SUBSURFACE_PRIVATE_H + +#include "cairo-surface-private.h" +#include "cairo-surface-backend-private.h" + +struct _cairo_surface_subsurface { + cairo_surface_t base; + + cairo_rectangle_int_t extents; + + cairo_surface_t *target; + cairo_surface_t *snapshot; +}; + +cairo_private void +_cairo_surface_subsurface_set_snapshot (cairo_surface_t *surface, + cairo_surface_t *snapshot); + +#endif /* CAIRO_SURFACE_SUBSURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface.c new file mode 100644 index 00000000000..b7dfd9d9e0c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-subsurface.c @@ -0,0 +1,587 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-offset-private.h" +#include "cairo-surface-snapshot-private.h" +#include "cairo-surface-subsurface-private.h" + +static const cairo_surface_backend_t _cairo_surface_subsurface_backend; + +static cairo_status_t +_cairo_surface_subsurface_finish (void *abstract_surface) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + + cairo_surface_destroy (surface->target); + cairo_surface_destroy (surface->snapshot); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_surface_subsurface_create_similar (void *other, + cairo_content_t content, + int width, int height) +{ + cairo_surface_subsurface_t *surface = other; + + if (surface->target->backend->create_similar == NULL) + return NULL; + + return surface->target->backend->create_similar (surface->target, content, width, height); +} + +static cairo_surface_t * +_cairo_surface_subsurface_create_similar_image (void *other, + cairo_format_t format, + int width, int height) +{ + cairo_surface_subsurface_t *surface = other; + + if (surface->target->backend->create_similar_image == NULL) + return NULL; + + return surface->target->backend->create_similar_image (surface->target, + format, + width, height); +} + +static cairo_image_surface_t * +_cairo_surface_subsurface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_rectangle_int_t target_extents; + + target_extents.x = extents->x + surface->extents.x; + target_extents.y = extents->y + surface->extents.y; + target_extents.width = extents->width; + target_extents.height = extents->height; + + return _cairo_surface_map_to_image (surface->target, &target_extents); +} + +static cairo_int_status_t +_cairo_surface_subsurface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + return _cairo_surface_unmap_image (surface->target, image); +} + +static cairo_int_status_t +_cairo_surface_subsurface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; + cairo_status_t status; + cairo_clip_t *target_clip; + + target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); + status = _cairo_surface_offset_paint (surface->target, + -surface->extents.x, -surface->extents.y, + op, source, target_clip); + _cairo_clip_destroy (target_clip); + return status; +} + +static cairo_int_status_t +_cairo_surface_subsurface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; + cairo_status_t status; + cairo_clip_t *target_clip; + + target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); + status = _cairo_surface_offset_mask (surface->target, + -surface->extents.x, -surface->extents.y, + op, source, mask, target_clip); + _cairo_clip_destroy (target_clip); + return status; +} + +static cairo_int_status_t +_cairo_surface_subsurface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; + cairo_status_t status; + cairo_clip_t *target_clip; + + target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); + status = _cairo_surface_offset_fill (surface->target, + -surface->extents.x, -surface->extents.y, + op, source, path, fill_rule, tolerance, antialias, + target_clip); + _cairo_clip_destroy (target_clip); + return status; +} + +static cairo_int_status_t +_cairo_surface_subsurface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; + cairo_status_t status; + cairo_clip_t *target_clip; + + target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); + status = _cairo_surface_offset_stroke (surface->target, + -surface->extents.x, -surface->extents.y, + op, source, path, stroke_style, ctm, ctm_inverse, + tolerance, antialias, + target_clip); + _cairo_clip_destroy (target_clip); + return status; +} + +static cairo_int_status_t +_cairo_surface_subsurface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height }; + cairo_status_t status; + cairo_clip_t *target_clip; + + target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect); + status = _cairo_surface_offset_glyphs (surface->target, + -surface->extents.x, -surface->extents.y, + op, source, + scaled_font, glyphs, num_glyphs, + target_clip); + _cairo_clip_destroy (target_clip); + return status; +} + +static cairo_status_t +_cairo_surface_subsurface_flush (void *abstract_surface, unsigned flags) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + return _cairo_surface_flush (surface->target, flags); +} + +static cairo_status_t +_cairo_surface_subsurface_mark_dirty (void *abstract_surface, + int x, int y, + int width, int height) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_status_t status; + + status = CAIRO_STATUS_SUCCESS; + if (surface->target->backend->mark_dirty_rectangle != NULL) { + cairo_rectangle_int_t rect, extents; + + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + + extents.x = extents.y = 0; + extents.width = surface->extents.width; + extents.height = surface->extents.height; + + if (_cairo_rectangle_intersect (&rect, &extents)) { + status = surface->target->backend->mark_dirty_rectangle (surface->target, + rect.x + surface->extents.x, + rect.y + surface->extents.y, + rect.width, rect.height); + } + } + + return status; +} + +static cairo_bool_t +_cairo_surface_subsurface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + + extents->x = 0; + extents->y = 0; + extents->width = surface->extents.width; + extents->height = surface->extents.height; + + return TRUE; +} + +static void +_cairo_surface_subsurface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + + if (surface->target->backend->get_font_options != NULL) + surface->target->backend->get_font_options (surface->target, options); +} + +static cairo_surface_t * +_cairo_surface_subsurface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_surface_t *source; + + source = _cairo_surface_get_source (surface->target, extents); + if (extents) + *extents = surface->extents; + + return source; +} + +static cairo_status_t +_cairo_surface_subsurface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **extra_out) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_surface_pattern_t pattern; + cairo_surface_t *image; + cairo_status_t status; + + image = _cairo_image_surface_create_with_content (surface->base.content, + surface->extents.width, + surface->extents.height); + if (unlikely (image->status)) + return image->status; + + _cairo_pattern_init_for_surface (&pattern, surface->target); + cairo_matrix_init_translate (&pattern.base.matrix, + surface->extents.x, + surface->extents.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + status = _cairo_surface_paint (image, + CAIRO_OPERATOR_SOURCE, + &pattern.base, NULL); + _cairo_pattern_fini (&pattern.base); + if (unlikely (status)) { + cairo_surface_destroy (image); + return status; + } + + *image_out = (cairo_image_surface_t *)image; + *extra_out = NULL; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_surface_subsurface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *abstract_extra) +{ + cairo_surface_destroy (&image->base); +} + +static cairo_surface_t * +_cairo_surface_subsurface_snapshot (void *abstract_surface) +{ + cairo_surface_subsurface_t *surface = abstract_surface; + cairo_surface_pattern_t pattern; + cairo_surface_t *clone; + cairo_status_t status; + + TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, surface->target->unique_id)); + + clone = _cairo_surface_create_scratch (surface->target, + surface->target->content, + surface->extents.width, + surface->extents.height, + NULL); + if (unlikely (clone->status)) + return clone; + + _cairo_pattern_init_for_surface (&pattern, surface->target); + cairo_matrix_init_translate (&pattern.base.matrix, + surface->extents.x, surface->extents.y); + pattern.base.filter = CAIRO_FILTER_NEAREST; + status = _cairo_surface_paint (clone, + CAIRO_OPERATOR_SOURCE, + &pattern.base, NULL); + _cairo_pattern_fini (&pattern.base); + + if (unlikely (status)) { + cairo_surface_destroy (clone); + clone = _cairo_surface_create_in_error (status); + } + + return clone; +} + +static cairo_t * +_cairo_surface_subsurface_create_context(void *target) +{ + cairo_surface_subsurface_t *surface = target; + return surface->target->backend->create_context (&surface->base); +} + +static const cairo_surface_backend_t _cairo_surface_subsurface_backend = { + CAIRO_SURFACE_TYPE_SUBSURFACE, + _cairo_surface_subsurface_finish, + + _cairo_surface_subsurface_create_context, + + _cairo_surface_subsurface_create_similar, + _cairo_surface_subsurface_create_similar_image, + _cairo_surface_subsurface_map_to_image, + _cairo_surface_subsurface_unmap_image, + + _cairo_surface_subsurface_source, + _cairo_surface_subsurface_acquire_source_image, + _cairo_surface_subsurface_release_source_image, + _cairo_surface_subsurface_snapshot, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_surface_subsurface_get_extents, + _cairo_surface_subsurface_get_font_options, + + _cairo_surface_subsurface_flush, + _cairo_surface_subsurface_mark_dirty, + + _cairo_surface_subsurface_paint, + _cairo_surface_subsurface_mask, + _cairo_surface_subsurface_stroke, + _cairo_surface_subsurface_fill, + NULL, /* fill/stroke */ + _cairo_surface_subsurface_glyphs, +}; + +/** + * cairo_surface_create_for_rectangle: + * @target: an existing surface for which the sub-surface will point to + * @x: the x-origin of the sub-surface from the top-left of the target surface (in device-space units) + * @y: the y-origin of the sub-surface from the top-left of the target surface (in device-space units) + * @width: width of the sub-surface (in device-space units) + * @height: height of the sub-surface (in device-space units) + * + * Create a new surface that is a rectangle within the target surface. + * All operations drawn to this surface are then clipped and translated + * onto the target surface. Nothing drawn via this sub-surface outside of + * its bounds is drawn onto the target surface, making this a useful method + * for passing constrained child surfaces to library routines that draw + * directly onto the parent surface, i.e. with no further backend allocations, + * double buffering or copies. + * + * The semantics of subsurfaces have not been finalized yet + * unless the rectangle is in full device units, is contained within + * the extents of the target surface, and the target or subsurface's + * device transforms are not changed. + * + * Return value: a pointer to the newly allocated surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if @other is already in an error state + * or any other error occurs. + * + * Since: 1.10 + **/ +cairo_surface_t * +cairo_surface_create_for_rectangle (cairo_surface_t *target, + double x, double y, + double width, double height) +{ + cairo_surface_subsurface_t *surface; + + if (unlikely (width < 0 || height < 0)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + if (unlikely (target->status)) + return _cairo_surface_create_in_error (target->status); + if (unlikely (target->finished)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + surface = malloc (sizeof (cairo_surface_subsurface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + x *= target->device_transform.xx; + y *= target->device_transform.yy; + + width *= target->device_transform.xx; + height *= target->device_transform.yy; + + x += target->device_transform.x0; + y += target->device_transform.y0; + + _cairo_surface_init (&surface->base, + &_cairo_surface_subsurface_backend, + NULL, /* device */ + target->content); + + /* XXX forced integer alignment */ + surface->extents.x = ceil (x); + surface->extents.y = ceil (y); + surface->extents.width = floor (x + width) - surface->extents.x; + surface->extents.height = floor (y + height) - surface->extents.y; + if ((surface->extents.width | surface->extents.height) < 0) + surface->extents.width = surface->extents.height = 0; + + if (target->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + /* Maintain subsurfaces as 1-depth */ + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) target; + surface->extents.x += sub->extents.x; + surface->extents.y += sub->extents.y; + target = sub->target; + } + + surface->target = cairo_surface_reference (target); + surface->base.type = surface->target->type; + + surface->snapshot = NULL; + + cairo_surface_set_device_scale (&surface->base, + target->device_transform.xx, + target->device_transform.yy); + + return &surface->base; +} + +cairo_surface_t * +_cairo_surface_create_for_rectangle_int (cairo_surface_t *target, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_subsurface_t *surface; + + if (unlikely (target->status)) + return _cairo_surface_create_in_error (target->status); + if (unlikely (target->finished)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + assert (target->backend->type != CAIRO_SURFACE_TYPE_SUBSURFACE); + + surface = malloc (sizeof (cairo_surface_subsurface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_surface_subsurface_backend, + NULL, /* device */ + target->content); + + surface->extents = *extents; + surface->extents.x *= target->device_transform.xx; + surface->extents.y *= target->device_transform.yy; + surface->extents.width *= target->device_transform.xx; + surface->extents.height *= target->device_transform.yy; + surface->extents.x += target->device_transform.x0; + surface->extents.y += target->device_transform.y0; + + surface->target = cairo_surface_reference (target); + surface->base.type = surface->target->type; + + surface->snapshot = NULL; + + cairo_surface_set_device_scale (&surface->base, + target->device_transform.xx, + target->device_transform.yy); + + return &surface->base; +} +/* XXX observe mark-dirty */ + +static void +_cairo_surface_subsurface_detach_snapshot (cairo_surface_t *surface) +{ + cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; + + TRACE ((stderr, "%s: target=%d\n", __FUNCTION__, ss->target->unique_id)); + + cairo_surface_destroy (ss->snapshot); + ss->snapshot = NULL; +} + +void +_cairo_surface_subsurface_set_snapshot (cairo_surface_t *surface, + cairo_surface_t *snapshot) +{ + cairo_surface_subsurface_t *ss = (cairo_surface_subsurface_t *) surface; + + TRACE ((stderr, "%s: target=%d, snapshot=%d\n", __FUNCTION__, + ss->target->unique_id, snapshot->unique_id)); + + /* FIXME: attaching the subsurface as a snapshot to its target creates + * a reference cycle. Let's make this call as a no-op until that bug + * is fixed. + */ + return; + + if (ss->snapshot) + _cairo_surface_detach_snapshot (ss->snapshot); + + ss->snapshot = cairo_surface_reference (snapshot); + + _cairo_surface_attach_snapshot (ss->target, &ss->base, + _cairo_surface_subsurface_detach_snapshot); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper-private.h new file mode 100644 index 00000000000..6529ebc1115 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper-private.h @@ -0,0 +1,193 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_SURFACE_WRAPPER_PRIVATE_H +#define CAIRO_SURFACE_WRAPPER_PRIVATE_H + +#include "cairoint.h" +#include "cairo-types-private.h" +#include "cairo-surface-backend-private.h" + +CAIRO_BEGIN_DECLS + +struct _cairo_surface_wrapper { + cairo_surface_t *target; + + cairo_matrix_t transform; + + cairo_bool_t has_extents; + cairo_rectangle_int_t extents; + const cairo_clip_t *clip; + + cairo_bool_t needs_transform; +}; + +cairo_private void +_cairo_surface_wrapper_init (cairo_surface_wrapper_t *wrapper, + cairo_surface_t *target); + +cairo_private void +_cairo_surface_wrapper_intersect_extents (cairo_surface_wrapper_t *wrapper, + const cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_surface_wrapper_set_inverse_transform (cairo_surface_wrapper_t *wrapper, + const cairo_matrix_t *transform); + +cairo_private void +_cairo_surface_wrapper_set_clip (cairo_surface_wrapper_t *wrapper, + const cairo_clip_t *clip); + +cairo_private void +_cairo_surface_wrapper_fini (cairo_surface_wrapper_t *wrapper); + +static inline cairo_bool_t +_cairo_surface_wrapper_has_fill_stroke (cairo_surface_wrapper_t *wrapper) +{ + return wrapper->target->backend->fill_stroke != NULL; +} + +cairo_private cairo_status_t +_cairo_surface_wrapper_acquire_source_image (cairo_surface_wrapper_t *wrapper, + cairo_image_surface_t **image_out, + void **image_extra); + +cairo_private void +_cairo_surface_wrapper_release_source_image (cairo_surface_wrapper_t *wrapper, + cairo_image_surface_t *image, + void *image_extra); + + +cairo_private cairo_status_t +_cairo_surface_wrapper_paint (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_wrapper_mask (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_wrapper_stroke (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_wrapper_fill_stroke (cairo_surface_wrapper_t *wrapper, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + const cairo_path_fixed_t*path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_wrapper_fill (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_wrapper_show_text_glyphs (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + +cairo_private cairo_surface_t * +_cairo_surface_wrapper_create_similar (cairo_surface_wrapper_t *wrapper, + cairo_content_t content, + int width, + int height); +cairo_private cairo_bool_t +_cairo_surface_wrapper_get_extents (cairo_surface_wrapper_t *wrapper, + cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_surface_wrapper_get_font_options (cairo_surface_wrapper_t *wrapper, + cairo_font_options_t *options); + +cairo_private cairo_surface_t * +_cairo_surface_wrapper_snapshot (cairo_surface_wrapper_t *wrapper); + +cairo_private cairo_bool_t +_cairo_surface_wrapper_has_show_text_glyphs (cairo_surface_wrapper_t *wrapper); + +static inline cairo_bool_t +_cairo_surface_wrapper_is_active (cairo_surface_wrapper_t *wrapper) +{ + return wrapper->target != (cairo_surface_t *) 0; +} + +cairo_private cairo_bool_t +_cairo_surface_wrapper_get_target_extents (cairo_surface_wrapper_t *wrapper, + cairo_rectangle_int_t *extents); + +CAIRO_END_DECLS + +#endif /* CAIRO_SURFACE_WRAPPER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper.c new file mode 100644 index 00000000000..9236c8bf42e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface-wrapper.c @@ -0,0 +1,685 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * Copyright © 2007 Adrian Johnson + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-clip-inline.h" +#include "cairo-error-private.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-wrapper-private.h" + +/* A collection of routines to facilitate surface wrapping */ + +static void +_copy_transformed_pattern (cairo_pattern_t *pattern, + const cairo_pattern_t *original, + const cairo_matrix_t *ctm_inverse) +{ + _cairo_pattern_init_static_copy (pattern, original); + + if (! _cairo_matrix_is_identity (ctm_inverse)) + _cairo_pattern_transform (pattern, ctm_inverse); +} + +cairo_status_t +_cairo_surface_wrapper_acquire_source_image (cairo_surface_wrapper_t *wrapper, + cairo_image_surface_t **image_out, + void **image_extra) +{ + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + return _cairo_surface_acquire_source_image (wrapper->target, + image_out, image_extra); +} + +void +_cairo_surface_wrapper_release_source_image (cairo_surface_wrapper_t *wrapper, + cairo_image_surface_t *image, + void *image_extra) +{ + _cairo_surface_release_source_image (wrapper->target, image, image_extra); +} + +static void +_cairo_surface_wrapper_get_transform (cairo_surface_wrapper_t *wrapper, + cairo_matrix_t *m) +{ + cairo_matrix_init_identity (m); + + if (wrapper->has_extents && (wrapper->extents.x || wrapper->extents.y)) + cairo_matrix_translate (m, -wrapper->extents.x, -wrapper->extents.y); + + if (! _cairo_matrix_is_identity (&wrapper->transform)) + cairo_matrix_multiply (m, &wrapper->transform, m); + + if (! _cairo_matrix_is_identity (&wrapper->target->device_transform)) + cairo_matrix_multiply (m, &wrapper->target->device_transform, m); +} + +static void +_cairo_surface_wrapper_get_inverse_transform (cairo_surface_wrapper_t *wrapper, + cairo_matrix_t *m) +{ + cairo_matrix_init_identity (m); + + if (! _cairo_matrix_is_identity (&wrapper->target->device_transform_inverse)) + cairo_matrix_multiply (m, &wrapper->target->device_transform_inverse, m); + + if (! _cairo_matrix_is_identity (&wrapper->transform)) { + cairo_matrix_t inv; + cairo_status_t status; + + inv = wrapper->transform; + status = cairo_matrix_invert (&inv); + assert (status == CAIRO_STATUS_SUCCESS); + cairo_matrix_multiply (m, &inv, m); + } + + if (wrapper->has_extents && (wrapper->extents.x || wrapper->extents.y)) + cairo_matrix_translate (m, wrapper->extents.x, wrapper->extents.y); +} + +static cairo_clip_t * +_cairo_surface_wrapper_get_clip (cairo_surface_wrapper_t *wrapper, + const cairo_clip_t *clip) +{ + cairo_clip_t *copy; + + copy = _cairo_clip_copy (clip); + if (wrapper->has_extents) { + copy = _cairo_clip_intersect_rectangle (copy, &wrapper->extents); + } + copy = _cairo_clip_transform (copy, &wrapper->transform); + if (! _cairo_matrix_is_identity (&wrapper->target->device_transform)) + copy = _cairo_clip_transform (copy, &wrapper->target->device_transform); + if (wrapper->clip) + copy = _cairo_clip_intersect_clip (copy, wrapper->clip); + + return copy; +} + +cairo_status_t +_cairo_surface_wrapper_paint (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_clip_t *dev_clip; + cairo_pattern_union_t source_copy; + + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); + if (_cairo_clip_is_all_clipped (dev_clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (wrapper->needs_transform) { + cairo_matrix_t m; + + _cairo_surface_wrapper_get_transform (wrapper, &m); + + status = cairo_matrix_invert (&m); + assert (status == CAIRO_STATUS_SUCCESS); + + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + } + + status = _cairo_surface_paint (wrapper->target, op, source, dev_clip); + + _cairo_clip_destroy (dev_clip); + return status; +} + + +cairo_status_t +_cairo_surface_wrapper_mask (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_clip_t *dev_clip; + cairo_pattern_union_t source_copy; + cairo_pattern_union_t mask_copy; + + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); + if (_cairo_clip_is_all_clipped (dev_clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (wrapper->needs_transform) { + cairo_matrix_t m; + + _cairo_surface_wrapper_get_transform (wrapper, &m); + + status = cairo_matrix_invert (&m); + assert (status == CAIRO_STATUS_SUCCESS); + + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + + _copy_transformed_pattern (&mask_copy.base, mask, &m); + mask = &mask_copy.base; + } + + status = _cairo_surface_mask (wrapper->target, op, source, mask, dev_clip); + + _cairo_clip_destroy (dev_clip); + return status; +} + +cairo_status_t +_cairo_surface_wrapper_stroke (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; + cairo_clip_t *dev_clip; + cairo_matrix_t dev_ctm = *ctm; + cairo_matrix_t dev_ctm_inverse = *ctm_inverse; + cairo_pattern_union_t source_copy; + + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); + if (_cairo_clip_is_all_clipped (dev_clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (wrapper->needs_transform) { + cairo_matrix_t m; + + _cairo_surface_wrapper_get_transform (wrapper, &m); + + status = _cairo_path_fixed_init_copy (&path_copy, dev_path); + if (unlikely (status)) + goto FINISH; + + _cairo_path_fixed_transform (&path_copy, &m); + dev_path = &path_copy; + + cairo_matrix_multiply (&dev_ctm, &dev_ctm, &m); + + status = cairo_matrix_invert (&m); + assert (status == CAIRO_STATUS_SUCCESS); + + cairo_matrix_multiply (&dev_ctm_inverse, &m, &dev_ctm_inverse); + + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + } + + status = _cairo_surface_stroke (wrapper->target, op, source, + dev_path, stroke_style, + &dev_ctm, &dev_ctm_inverse, + tolerance, antialias, + dev_clip); + + FINISH: + if (dev_path != path) + _cairo_path_fixed_fini (dev_path); + _cairo_clip_destroy (dev_clip); + return status; +} + +cairo_status_t +_cairo_surface_wrapper_fill_stroke (cairo_surface_wrapper_t *wrapper, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + const cairo_path_fixed_t*path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *)path; + cairo_matrix_t dev_ctm = *stroke_ctm; + cairo_matrix_t dev_ctm_inverse = *stroke_ctm_inverse; + cairo_clip_t *dev_clip; + cairo_pattern_union_t stroke_source_copy; + cairo_pattern_union_t fill_source_copy; + + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); + if (_cairo_clip_is_all_clipped (dev_clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (wrapper->needs_transform) { + cairo_matrix_t m; + + _cairo_surface_wrapper_get_transform (wrapper, &m); + + status = _cairo_path_fixed_init_copy (&path_copy, dev_path); + if (unlikely (status)) + goto FINISH; + + _cairo_path_fixed_transform (&path_copy, &m); + dev_path = &path_copy; + + cairo_matrix_multiply (&dev_ctm, &dev_ctm, &m); + + status = cairo_matrix_invert (&m); + assert (status == CAIRO_STATUS_SUCCESS); + + cairo_matrix_multiply (&dev_ctm_inverse, &m, &dev_ctm_inverse); + + _copy_transformed_pattern (&stroke_source_copy.base, stroke_source, &m); + stroke_source = &stroke_source_copy.base; + + _copy_transformed_pattern (&fill_source_copy.base, fill_source, &m); + fill_source = &fill_source_copy.base; + } + + status = _cairo_surface_fill_stroke (wrapper->target, + fill_op, fill_source, fill_rule, + fill_tolerance, fill_antialias, + dev_path, + stroke_op, stroke_source, + stroke_style, + &dev_ctm, &dev_ctm_inverse, + stroke_tolerance, stroke_antialias, + dev_clip); + + FINISH: + if (dev_path != path) + _cairo_path_fixed_fini (dev_path); + _cairo_clip_destroy (dev_clip); + return status; +} + +cairo_status_t +_cairo_surface_wrapper_fill (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_path_fixed_t path_copy, *dev_path = (cairo_path_fixed_t *) path; + cairo_pattern_union_t source_copy; + cairo_clip_t *dev_clip; + + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); + if (_cairo_clip_is_all_clipped (dev_clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + if (wrapper->needs_transform) { + cairo_matrix_t m; + + _cairo_surface_wrapper_get_transform (wrapper, &m); + + status = _cairo_path_fixed_init_copy (&path_copy, dev_path); + if (unlikely (status)) + goto FINISH; + + _cairo_path_fixed_transform (&path_copy, &m); + dev_path = &path_copy; + + status = cairo_matrix_invert (&m); + assert (status == CAIRO_STATUS_SUCCESS); + + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + } + + status = _cairo_surface_fill (wrapper->target, op, source, + dev_path, fill_rule, + tolerance, antialias, + dev_clip); + + FINISH: + if (dev_path != path) + _cairo_path_fixed_fini (dev_path); + _cairo_clip_destroy (dev_clip); + return status; +} + +cairo_status_t +_cairo_surface_wrapper_show_text_glyphs (cairo_surface_wrapper_t *wrapper, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_clip_t *dev_clip; + cairo_glyph_t stack_glyphs [CAIRO_STACK_ARRAY_LENGTH(cairo_glyph_t)]; + cairo_glyph_t *dev_glyphs = stack_glyphs; + cairo_scaled_font_t *dev_scaled_font = scaled_font; + cairo_pattern_union_t source_copy; + cairo_font_options_t options; + + if (unlikely (wrapper->target->status)) + return wrapper->target->status; + + dev_clip = _cairo_surface_wrapper_get_clip (wrapper, clip); + if (_cairo_clip_is_all_clipped (dev_clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + cairo_surface_get_font_options (wrapper->target, &options); + cairo_font_options_merge (&options, &scaled_font->options); + + if (wrapper->needs_transform) { + cairo_matrix_t m; + int i; + + _cairo_surface_wrapper_get_transform (wrapper, &m); + + if (! _cairo_matrix_is_translation (&m)) { + cairo_matrix_t ctm; + + _cairo_matrix_multiply (&ctm, + &m, + &scaled_font->ctm); + dev_scaled_font = cairo_scaled_font_create (scaled_font->font_face, + &scaled_font->font_matrix, + &ctm, &options); + } + + if (num_glyphs > ARRAY_LENGTH (stack_glyphs)) { + dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); + if (unlikely (dev_glyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FINISH; + } + } + + for (i = 0; i < num_glyphs; i++) { + dev_glyphs[i] = glyphs[i]; + cairo_matrix_transform_point (&m, + &dev_glyphs[i].x, + &dev_glyphs[i].y); + } + + status = cairo_matrix_invert (&m); + assert (status == CAIRO_STATUS_SUCCESS); + + _copy_transformed_pattern (&source_copy.base, source, &m); + source = &source_copy.base; + } else { + if (! cairo_font_options_equal (&options, &scaled_font->options)) { + dev_scaled_font = cairo_scaled_font_create (scaled_font->font_face, + &scaled_font->font_matrix, + &scaled_font->ctm, + &options); + } + + /* show_text_glyphs is special because _cairo_surface_show_text_glyphs is allowed + * to modify the glyph array that's passed in. We must always + * copy the array before handing it to the backend. + */ + if (num_glyphs > ARRAY_LENGTH (stack_glyphs)) { + dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); + if (unlikely (dev_glyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FINISH; + } + } + + memcpy (dev_glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); + } + + status = _cairo_surface_show_text_glyphs (wrapper->target, op, source, + utf8, utf8_len, + dev_glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags, + dev_scaled_font, + dev_clip); + FINISH: + _cairo_clip_destroy (dev_clip); + if (dev_glyphs != stack_glyphs) + free (dev_glyphs); + if (dev_scaled_font != scaled_font) + cairo_scaled_font_destroy (dev_scaled_font); + return status; +} + +cairo_surface_t * +_cairo_surface_wrapper_create_similar (cairo_surface_wrapper_t *wrapper, + cairo_content_t content, + int width, + int height) +{ + return _cairo_surface_create_scratch (wrapper->target, + content, width, height, NULL); +} + +cairo_bool_t +_cairo_surface_wrapper_get_extents (cairo_surface_wrapper_t *wrapper, + cairo_rectangle_int_t *extents) +{ + if (wrapper->has_extents) { + if (_cairo_surface_get_extents (wrapper->target, extents)) + _cairo_rectangle_intersect (extents, &wrapper->extents); + else + *extents = wrapper->extents; + + return TRUE; + } else { + return _cairo_surface_get_extents (wrapper->target, extents); + } +} + +static cairo_bool_t +_cairo_surface_wrapper_needs_device_transform (cairo_surface_wrapper_t *wrapper) +{ + return + (wrapper->has_extents && (wrapper->extents.x | wrapper->extents.y)) || + ! _cairo_matrix_is_identity (&wrapper->transform) || + ! _cairo_matrix_is_identity (&wrapper->target->device_transform); +} + +void +_cairo_surface_wrapper_intersect_extents (cairo_surface_wrapper_t *wrapper, + const cairo_rectangle_int_t *extents) +{ + if (! wrapper->has_extents) { + wrapper->extents = *extents; + wrapper->has_extents = TRUE; + } else + _cairo_rectangle_intersect (&wrapper->extents, extents); + + wrapper->needs_transform = + _cairo_surface_wrapper_needs_device_transform (wrapper); +} + +void +_cairo_surface_wrapper_set_inverse_transform (cairo_surface_wrapper_t *wrapper, + const cairo_matrix_t *transform) +{ + cairo_status_t status; + + if (transform == NULL || _cairo_matrix_is_identity (transform)) { + cairo_matrix_init_identity (&wrapper->transform); + + wrapper->needs_transform = + _cairo_surface_wrapper_needs_device_transform (wrapper); + } else { + wrapper->transform = *transform; + status = cairo_matrix_invert (&wrapper->transform); + /* should always be invertible unless given pathological input */ + assert (status == CAIRO_STATUS_SUCCESS); + + wrapper->needs_transform = TRUE; + } +} + +void +_cairo_surface_wrapper_set_clip (cairo_surface_wrapper_t *wrapper, + const cairo_clip_t *clip) +{ + wrapper->clip = clip; +} + +void +_cairo_surface_wrapper_get_font_options (cairo_surface_wrapper_t *wrapper, + cairo_font_options_t *options) +{ + cairo_surface_get_font_options (wrapper->target, options); +} + +cairo_surface_t * +_cairo_surface_wrapper_snapshot (cairo_surface_wrapper_t *wrapper) +{ + if (wrapper->target->backend->snapshot) + return wrapper->target->backend->snapshot (wrapper->target); + + return NULL; +} + +cairo_bool_t +_cairo_surface_wrapper_has_show_text_glyphs (cairo_surface_wrapper_t *wrapper) +{ + return cairo_surface_has_show_text_glyphs (wrapper->target); +} + +void +_cairo_surface_wrapper_init (cairo_surface_wrapper_t *wrapper, + cairo_surface_t *target) +{ + wrapper->target = cairo_surface_reference (target); + cairo_matrix_init_identity (&wrapper->transform); + wrapper->has_extents = FALSE; + wrapper->extents.x = wrapper->extents.y = 0; + wrapper->clip = NULL; + + wrapper->needs_transform = FALSE; + if (target) { + wrapper->needs_transform = + ! _cairo_matrix_is_identity (&target->device_transform); + } +} + +void +_cairo_surface_wrapper_fini (cairo_surface_wrapper_t *wrapper) +{ + cairo_surface_destroy (wrapper->target); +} + +cairo_bool_t +_cairo_surface_wrapper_get_target_extents (cairo_surface_wrapper_t *wrapper, + cairo_rectangle_int_t *extents) +{ + cairo_rectangle_int_t clip; + cairo_bool_t has_clip; + + has_clip = _cairo_surface_get_extents (wrapper->target, &clip); + if (wrapper->clip) { + if (has_clip) { + if (! _cairo_rectangle_intersect (&clip, + _cairo_clip_get_extents (wrapper->clip))) + return FALSE; + } else { + has_clip = TRUE; + clip = *_cairo_clip_get_extents (wrapper->clip); + } + } + + if (has_clip && wrapper->needs_transform) { + cairo_matrix_t m; + double x1, y1, x2, y2; + + _cairo_surface_wrapper_get_inverse_transform (wrapper, &m); + + x1 = clip.x; + y1 = clip.y; + x2 = clip.x + clip.width; + y2 = clip.y + clip.height; + + _cairo_matrix_transform_bounding_box (&m, &x1, &y1, &x2, &y2, NULL); + + clip.x = floor (x1); + clip.y = floor (y1); + clip.width = ceil (x2) - clip.x; + clip.height = ceil (y2) - clip.y; + } + + if (has_clip) { + if (wrapper->has_extents) { + *extents = wrapper->extents; + return _cairo_rectangle_intersect (extents, &clip); + } else { + *extents = clip; + return TRUE; + } + } else if (wrapper->has_extents) { + *extents = wrapper->extents; + return TRUE; + } else { + _cairo_unbounded_rectangle_init (extents); + return TRUE; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-surface.c new file mode 100644 index 00000000000..bfe3fa1064c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-surface.c @@ -0,0 +1,2749 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-damage-private.h" +#include "cairo-device-private.h" +#include "cairo-error-private.h" +#include "cairo-list-inline.h" +#include "cairo-image-surface-inline.h" +#include "cairo-recording-surface-private.h" +#include "cairo-region-private.h" +#include "cairo-surface-inline.h" +#include "cairo-tee-surface-private.h" + +/** + * SECTION:cairo-surface + * @Title: cairo_surface_t + * @Short_Description: Base class for surfaces + * @See_Also: #cairo_t, #cairo_pattern_t + * + * #cairo_surface_t is the abstract type representing all different drawing + * targets that cairo can render to. The actual drawings are + * performed using a cairo context. + * + * A cairo surface is created by using backend-specific + * constructors, typically of the form + * cairo_backend_surface_create(). + * + * Most surface types allow accessing the surface without using Cairo + * functions. If you do this, keep in mind that it is mandatory that you call + * cairo_surface_flush() before reading from or writing to the surface and that + * you must use cairo_surface_mark_dirty() after modifying it. + * + * Directly modifying an image surface + * + * void + * modify_image_surface (cairo_surface_t *surface) + * { + * unsigned char *data; + * int width, height, stride; + * + * // flush to ensure all writing to the image was done + * cairo_surface_flush (surface); + * + * // modify the image + * data = cairo_image_surface_get_data (surface); + * width = cairo_image_surface_get_width (surface); + * height = cairo_image_surface_get_height (surface); + * stride = cairo_image_surface_get_stride (surface); + * modify_image_data (data, width, height, stride); + * + * // mark the image dirty so Cairo clears its caches. + * cairo_surface_mark_dirty (surface); + * } + * + * + * Note that for other surface types it might be necessary to acquire the + * surface's device first. See cairo_device_acquire() for a discussion of + * devices. + **/ + +#define DEFINE_NIL_SURFACE(status, name) \ +const cairo_surface_t name = { \ + NULL, /* backend */ \ + NULL, /* device */ \ + CAIRO_SURFACE_TYPE_IMAGE, /* type */ \ + CAIRO_CONTENT_COLOR, /* content */ \ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ + status, /* status */ \ + 0, /* unique id */ \ + 0, /* serial */ \ + NULL, /* damage */ \ + FALSE, /* _finishing */ \ + FALSE, /* finished */ \ + TRUE, /* is_clear */ \ + FALSE, /* has_font_options */ \ + FALSE, /* owns_device */ \ + { 0, 0, 0, NULL, }, /* user_data */ \ + { 0, 0, 0, NULL, }, /* mime_data */ \ + { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \ + { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform_inverse */ \ + { NULL, NULL }, /* device_transform_observers */ \ + 0.0, /* x_resolution */ \ + 0.0, /* y_resolution */ \ + 0.0, /* x_fallback_resolution */ \ + 0.0, /* y_fallback_resolution */ \ + NULL, /* snapshot_of */ \ + NULL, /* snapshot_detach */ \ + { NULL, NULL }, /* snapshots */ \ + { NULL, NULL }, /* snapshot */ \ + { CAIRO_ANTIALIAS_DEFAULT, /* antialias */ \ + CAIRO_SUBPIXEL_ORDER_DEFAULT, /* subpixel_order */ \ + CAIRO_LCD_FILTER_DEFAULT, /* lcd_filter */ \ + CAIRO_HINT_STYLE_DEFAULT, /* hint_style */ \ + CAIRO_HINT_METRICS_DEFAULT, /* hint_metrics */ \ + CAIRO_ROUND_GLYPH_POS_DEFAULT /* round_glyph_positions */ \ + } /* font_options */ \ +} + +/* XXX error object! */ + +static DEFINE_NIL_SURFACE(CAIRO_STATUS_NO_MEMORY, _cairo_surface_nil); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_SURFACE_TYPE_MISMATCH, _cairo_surface_nil_surface_type_mismatch); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STATUS, _cairo_surface_nil_invalid_status); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_CONTENT, _cairo_surface_nil_invalid_content); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_FORMAT, _cairo_surface_nil_invalid_format); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_VISUAL, _cairo_surface_nil_invalid_visual); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_FILE_NOT_FOUND, _cairo_surface_nil_file_not_found); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_TEMP_FILE_ERROR, _cairo_surface_nil_temp_file_error); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_READ_ERROR, _cairo_surface_nil_read_error); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_WRITE_ERROR, _cairo_surface_nil_write_error); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STRIDE, _cairo_surface_nil_invalid_stride); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_SIZE, _cairo_surface_nil_invalid_size); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_TYPE_MISMATCH, _cairo_surface_nil_device_type_mismatch); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_ERROR, _cairo_surface_nil_device_error); + +static DEFINE_NIL_SURFACE(CAIRO_INT_STATUS_UNSUPPORTED, _cairo_surface_nil_unsupported); +static DEFINE_NIL_SURFACE(CAIRO_INT_STATUS_NOTHING_TO_DO, _cairo_surface_nil_nothing_to_do); + +static void _cairo_surface_finish_snapshots (cairo_surface_t *surface); +static void _cairo_surface_finish (cairo_surface_t *surface); + +/** + * _cairo_surface_set_error: + * @surface: a surface + * @status: a status value indicating an error + * + * Atomically sets surface->status to @status and calls _cairo_error; + * Does nothing if status is %CAIRO_STATUS_SUCCESS or any of the internal + * status values. + * + * All assignments of an error status to surface->status should happen + * through _cairo_surface_set_error(). Note that due to the nature of + * the atomic operation, it is not safe to call this function on the + * nil objects. + * + * The purpose of this function is to allow the user to set a + * breakpoint in _cairo_error() to generate a stack trace for when the + * user causes cairo to detect an error. + * + * Return value: the error status. + **/ +cairo_int_status_t +_cairo_surface_set_error (cairo_surface_t *surface, + cairo_int_status_t status) +{ + /* NOTHING_TO_DO is magic. We use it to break out of the inner-most + * surface function, but anything higher just sees "success". + */ + if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) + status = CAIRO_INT_STATUS_SUCCESS; + + if (status == CAIRO_INT_STATUS_SUCCESS || + status >= (int)CAIRO_INT_STATUS_LAST_STATUS) + return status; + + /* Don't overwrite an existing error. This preserves the first + * error, which is the most significant. */ + _cairo_status_set_error (&surface->status, (cairo_status_t)status); + + return _cairo_error (status); +} + +/** + * cairo_surface_get_type: + * @surface: a #cairo_surface_t + * + * This function returns the type of the backend used to create + * a surface. See #cairo_surface_type_t for available types. + * + * Return value: The type of @surface. + * + * Since: 1.2 + **/ +cairo_surface_type_t +cairo_surface_get_type (cairo_surface_t *surface) +{ + /* We don't use surface->backend->type here so that some of the + * special "wrapper" surfaces such as cairo_paginated_surface_t + * can override surface->type with the type of the "child" + * surface. */ + return surface->type; +} + +/** + * cairo_surface_get_content: + * @surface: a #cairo_surface_t + * + * This function returns the content type of @surface which indicates + * whether the surface contains color and/or alpha information. See + * #cairo_content_t. + * + * Return value: The content type of @surface. + * + * Since: 1.2 + **/ +cairo_content_t +cairo_surface_get_content (cairo_surface_t *surface) +{ + return surface->content; +} + +/** + * cairo_surface_status: + * @surface: a #cairo_surface_t + * + * Checks whether an error has previously occurred for this + * surface. + * + * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_STATUS_NULL_POINTER, + * %CAIRO_STATUS_NO_MEMORY, %CAIRO_STATUS_READ_ERROR, + * %CAIRO_STATUS_INVALID_CONTENT, %CAIRO_STATUS_INVALID_FORMAT, or + * %CAIRO_STATUS_INVALID_VISUAL. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_surface_status (cairo_surface_t *surface) +{ + return surface->status; +} +slim_hidden_def (cairo_surface_status); + +static unsigned int +_cairo_surface_allocate_unique_id (void) +{ + static cairo_atomic_int_t unique_id; + +#if CAIRO_NO_MUTEX + if (++unique_id == 0) + unique_id = 1; + return unique_id; +#else + cairo_atomic_int_t old, id; + + do { + old = _cairo_atomic_uint_get (&unique_id); + id = old + 1; + if (id == 0) + id = 1; + } while (! _cairo_atomic_uint_cmpxchg (&unique_id, old, id)); + + return id; +#endif +} + +/** + * cairo_surface_get_device: + * @surface: a #cairo_surface_t + * + * This function returns the device for a @surface. + * See #cairo_device_t. + * + * Return value: The device for @surface or %NULL if the surface does + * not have an associated device. + * + * Since: 1.10 + **/ +cairo_device_t * +cairo_surface_get_device (cairo_surface_t *surface) +{ + if (unlikely (surface->status)) + return _cairo_device_create_in_error (surface->status); + + return surface->device; +} + +static cairo_bool_t +_cairo_surface_has_snapshots (cairo_surface_t *surface) +{ + return ! cairo_list_is_empty (&surface->snapshots); +} + +static cairo_bool_t +_cairo_surface_has_mime_data (cairo_surface_t *surface) +{ + return surface->mime_data.num_elements != 0; +} + +static void +_cairo_surface_detach_mime_data (cairo_surface_t *surface) +{ + if (! _cairo_surface_has_mime_data (surface)) + return; + + _cairo_user_data_array_fini (&surface->mime_data); + _cairo_user_data_array_init (&surface->mime_data); +} + +static void +_cairo_surface_detach_snapshots (cairo_surface_t *surface) +{ + while (_cairo_surface_has_snapshots (surface)) { + _cairo_surface_detach_snapshot (cairo_list_first_entry (&surface->snapshots, + cairo_surface_t, + snapshot)); + } +} + +void +_cairo_surface_detach_snapshot (cairo_surface_t *snapshot) +{ + assert (snapshot->snapshot_of != NULL); + + snapshot->snapshot_of = NULL; + cairo_list_del (&snapshot->snapshot); + + if (snapshot->snapshot_detach != NULL) + snapshot->snapshot_detach (snapshot); + + cairo_surface_destroy (snapshot); +} + +void +_cairo_surface_attach_snapshot (cairo_surface_t *surface, + cairo_surface_t *snapshot, + cairo_surface_func_t detach_func) +{ + assert (surface != snapshot); + assert (snapshot->snapshot_of != surface); + + cairo_surface_reference (snapshot); + + if (snapshot->snapshot_of != NULL) + _cairo_surface_detach_snapshot (snapshot); + + snapshot->snapshot_of = surface; + snapshot->snapshot_detach = detach_func; + + cairo_list_add (&snapshot->snapshot, &surface->snapshots); + + assert (_cairo_surface_has_snapshot (surface, snapshot->backend) == snapshot); +} + +cairo_surface_t * +_cairo_surface_has_snapshot (cairo_surface_t *surface, + const cairo_surface_backend_t *backend) +{ + cairo_surface_t *snapshot; + + cairo_list_foreach_entry (snapshot, cairo_surface_t, + &surface->snapshots, snapshot) + { + if (snapshot->backend == backend) + return snapshot; + } + + return NULL; +} + +cairo_status_t +_cairo_surface_begin_modification (cairo_surface_t *surface) +{ + assert (surface->status == CAIRO_STATUS_SUCCESS); + assert (! surface->finished); + + return _cairo_surface_flush (surface, 1); +} + +void +_cairo_surface_init (cairo_surface_t *surface, + const cairo_surface_backend_t *backend, + cairo_device_t *device, + cairo_content_t content) +{ + CAIRO_MUTEX_INITIALIZE (); + + surface->backend = backend; + surface->device = cairo_device_reference (device); + surface->content = content; + surface->type = backend->type; + + CAIRO_REFERENCE_COUNT_INIT (&surface->ref_count, 1); + surface->status = CAIRO_STATUS_SUCCESS; + surface->unique_id = _cairo_surface_allocate_unique_id (); + surface->finished = FALSE; + surface->_finishing = FALSE; + surface->is_clear = FALSE; + surface->serial = 0; + surface->damage = NULL; + surface->owns_device = (device != NULL); + + _cairo_user_data_array_init (&surface->user_data); + _cairo_user_data_array_init (&surface->mime_data); + + cairo_matrix_init_identity (&surface->device_transform); + cairo_matrix_init_identity (&surface->device_transform_inverse); + cairo_list_init (&surface->device_transform_observers); + + surface->x_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT; + surface->y_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT; + + surface->x_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT; + surface->y_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT; + + cairo_list_init (&surface->snapshots); + surface->snapshot_of = NULL; + + surface->has_font_options = FALSE; +} + +static void +_cairo_surface_copy_similar_properties (cairo_surface_t *surface, + cairo_surface_t *other) +{ + if (other->has_font_options || other->backend != surface->backend) { + cairo_font_options_t options; + + cairo_surface_get_font_options (other, &options); + _cairo_surface_set_font_options (surface, &options); + } + + cairo_surface_set_fallback_resolution (surface, + other->x_fallback_resolution, + other->y_fallback_resolution); +} + +/** + * cairo_surface_create_similar: + * @other: an existing surface used to select the backend of the new surface + * @content: the content for the new surface + * @width: width of the new surface, (in device-space units) + * @height: height of the new surface (in device-space units) + * + * Create a new surface that is as compatible as possible with an + * existing surface. For example the new surface will have the same + * fallback resolution and font options as @other. Generally, the new + * surface will also use the same backend as @other, unless that is + * not possible for some reason. The type of the returned surface may + * be examined with cairo_surface_get_type(). + * + * Initially the surface contents are all 0 (transparent if contents + * have transparency, black otherwise.) + * + * Use cairo_surface_create_similar_image() if you need an image surface + * which can be painted quickly to the target surface. + * + * Return value: a pointer to the newly allocated surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if @other is already in an error state + * or any other error occurs. + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_surface_create_similar (cairo_surface_t *other, + cairo_content_t content, + int width, + int height) +{ + cairo_surface_t *surface; + cairo_status_t status; + cairo_solid_pattern_t pattern; + + if (unlikely (other->status)) + return _cairo_surface_create_in_error (other->status); + if (unlikely (other->finished)) + return _cairo_surface_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); + if (unlikely (width < 0 || height < 0)) + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); + + if (unlikely (! CAIRO_CONTENT_VALID (content))) + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_CONTENT); + + if (unlikely (other->status)) + return _cairo_surface_create_in_error (other->status); + + /* We inherit the device scale, so create a larger surface */ + width = width * other->device_transform.xx; + height = height * other->device_transform.yy; + + surface = NULL; + if (other->backend->create_similar) + surface = other->backend->create_similar (other, content, width, height); + if (surface == NULL) + surface = cairo_surface_create_similar_image (other, + _cairo_format_from_content (content), + width, height); + + if (unlikely (surface->status)) + return surface; + + _cairo_surface_copy_similar_properties (surface, other); + cairo_surface_set_device_scale (surface, + other->device_transform.xx, + other->device_transform.yy); + + if (unlikely (surface->status)) + return surface; + + _cairo_pattern_init_solid (&pattern, CAIRO_COLOR_TRANSPARENT); + status = _cairo_surface_paint (surface, + CAIRO_OPERATOR_CLEAR, + &pattern.base, NULL); + if (unlikely (status)) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + + assert (surface->is_clear); + + return surface; +} + +/** + * cairo_surface_create_similar_image: + * @other: an existing surface used to select the preference of the new surface + * @format: the format for the new surface + * @width: width of the new surface, (in device-space units) + * @height: height of the new surface (in device-space units) + * + * Create a new image surface that is as compatible as possible for uploading + * to and the use in conjunction with an existing surface. However, this surface + * can still be used like any normal image surface. + * + * Initially the surface contents are all 0 (transparent if contents + * have transparency, black otherwise.) + * + * Use cairo_surface_create_similar() if you don't need an image surface. + * + * Return value: a pointer to the newly allocated image surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if @other is already in an error state + * or any other error occurs. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_surface_create_similar_image (cairo_surface_t *other, + cairo_format_t format, + int width, + int height) +{ + cairo_surface_t *image; + + if (unlikely (other->status)) + return _cairo_surface_create_in_error (other->status); + if (unlikely (other->finished)) + return _cairo_surface_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); + + if (unlikely (width < 0 || height < 0)) + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); + if (unlikely (! CAIRO_FORMAT_VALID (format))) + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_FORMAT); + + image = NULL; + if (other->backend->create_similar_image) + image = other->backend->create_similar_image (other, + format, width, height); + if (image == NULL) + image = cairo_image_surface_create (format, width, height); + + assert (image->is_clear); + + return image; +} +slim_hidden_def (cairo_surface_create_similar_image); + +/** + * _cairo_surface_map_to_image: + * @surface: an existing surface used to extract the image from + * @extents: limit the extraction to an rectangular region + * + * Returns an image surface that is the most efficient mechanism for + * modifying the backing store of the target surface. The region + * retrieved is limited to @extents. + * + * Note, the use of the original surface as a target or source whilst + * it is mapped is undefined. The result of mapping the surface + * multiple times is undefined. Calling cairo_surface_destroy() or + * cairo_surface_finish() on the resulting image surface results in + * undefined behavior. Changing the device transform of the image + * surface or of @surface before the image surface is unmapped results + * in undefined behavior. + * + * Assumes that @surface is valid (CAIRO_STATUS_SUCCESS, + * non-finished). + * + * Return value: a pointer to the newly allocated image surface. The + * caller must use _cairo_surface_unmap_image() to destroy this image + * surface. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if @other is already in an error state + * or any other error occurs. + * + * The returned image might have a %CAIRO_FORMAT_INVALID format. + **/ +cairo_image_surface_t * +_cairo_surface_map_to_image (cairo_surface_t *surface, + const cairo_rectangle_int_t *extents) +{ + cairo_image_surface_t *image = NULL; + + assert (extents != NULL); + + /* TODO: require map_to_image != NULL */ + if (surface->backend->map_to_image) + image = surface->backend->map_to_image (surface, extents); + + if (image == NULL) + image = _cairo_image_surface_clone_subimage (surface, extents); + + return image; +} + +/** + * _cairo_surface_unmap_image: + * @surface: the surface passed to _cairo_surface_map_to_image(). + * @image: the currently mapped image + * + * Unmaps the image surface as returned from + * _cairo_surface_map_to_image(). + * + * The content of the image will be uploaded to the target surface. + * Afterwards, the image is destroyed. + * + * Using an image surface which wasn't returned by + * _cairo_surface_map_to_image() results in undefined behavior. + * + * An image surface in error status can be passed to + * _cairo_surface_unmap_image(). + * + * Return value: the unmap status. + * + * Even if the unmap status is not successful, @image is destroyed. + **/ +cairo_int_status_t +_cairo_surface_unmap_image (cairo_surface_t *surface, + cairo_image_surface_t *image) +{ + cairo_surface_pattern_t pattern; + cairo_rectangle_int_t extents; + cairo_clip_t *clip; + cairo_int_status_t status; + + /* map_to_image can return error surfaces */ + if (unlikely (image->base.status)) { + status = image->base.status; + goto destroy; + } + + /* If the image is untouched just skip the update */ + if (image->base.serial == 0) { + status = CAIRO_STATUS_SUCCESS; + goto destroy; + } + + /* TODO: require unmap_image != NULL */ + if (surface->backend->unmap_image && + ! _cairo_image_surface_is_clone (image)) + { + status = surface->backend->unmap_image (surface, image); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + _cairo_pattern_init_for_surface (&pattern, &image->base); + pattern.base.filter = CAIRO_FILTER_NEAREST; + + /* We have to apply the translate from map_to_image's extents.x and .y */ + cairo_matrix_init_translate (&pattern.base.matrix, + image->base.device_transform.x0, + image->base.device_transform.y0); + + /* And we also have to clip the operation to the image's extents */ + extents.x = image->base.device_transform_inverse.x0; + extents.y = image->base.device_transform_inverse.y0; + extents.width = image->width; + extents.height = image->height; + clip = _cairo_clip_intersect_rectangle (NULL, &extents); + + status = _cairo_surface_paint (surface, + CAIRO_OPERATOR_SOURCE, + &pattern.base, + clip); + + _cairo_pattern_fini (&pattern.base); + _cairo_clip_destroy (clip); + +destroy: + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return status; +} + +/** + * cairo_surface_map_to_image: + * @surface: an existing surface used to extract the image from + * @extents: limit the extraction to an rectangular region + * + * Returns an image surface that is the most efficient mechanism for + * modifying the backing store of the target surface. The region retrieved + * may be limited to the @extents or %NULL for the whole surface + * + * Note, the use of the original surface as a target or source whilst + * it is mapped is undefined. The result of mapping the surface + * multiple times is undefined. Calling cairo_surface_destroy() or + * cairo_surface_finish() on the resulting image surface results in + * undefined behavior. Changing the device transform of the image + * surface or of @surface before the image surface is unmapped results + * in undefined behavior. + * + * Return value: a pointer to the newly allocated image surface. The caller + * must use cairo_surface_unmap_image() to destroy this image surface. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if @other is already in an error state + * or any other error occurs. If the returned pointer does not have an + * error status, it is guaranteed to be an image surface whose format + * is not %CAIRO_FORMAT_INVALID. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_surface_map_to_image (cairo_surface_t *surface, + const cairo_rectangle_int_t *extents) +{ + cairo_rectangle_int_t rect; + cairo_image_surface_t *image; + cairo_status_t status; + + if (unlikely (surface->status)) + return _cairo_surface_create_in_error (surface->status); + if (unlikely (surface->finished)) + return _cairo_surface_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); + + if (extents == NULL) { + if (unlikely (! surface->backend->get_extents (surface, &rect))) + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); + + extents = ▭ + } else { + cairo_rectangle_int_t surface_extents; + + /* If this surface is bounded, we can't map parts + * that are outside of it. */ + if (likely (surface->backend->get_extents (surface, &surface_extents))) { + if (unlikely (! _cairo_rectangle_contains_rectangle (&surface_extents, extents))) + return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE); + } + } + + image = _cairo_surface_map_to_image (surface, extents); + + status = image->base.status; + if (unlikely (status)) { + cairo_surface_destroy (&image->base); + return _cairo_surface_create_in_error (status); + } + + if (image->format == CAIRO_FORMAT_INVALID) { + cairo_surface_destroy (&image->base); + image = _cairo_image_surface_clone_subimage (surface, extents); + } + + return &image->base; +} + +/** + * cairo_surface_unmap_image: + * @surface: the surface passed to cairo_surface_map_to_image(). + * @image: the currently mapped image + * + * Unmaps the image surface as returned from #cairo_surface_map_to_image(). + * + * The content of the image will be uploaded to the target surface. + * Afterwards, the image is destroyed. + * + * Using an image surface which wasn't returned by cairo_surface_map_to_image() + * results in undefined behavior. + * + * Since: 1.12 + **/ +void +cairo_surface_unmap_image (cairo_surface_t *surface, + cairo_surface_t *image) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + + if (unlikely (surface->status)) { + status = surface->status; + goto error; + } + if (unlikely (surface->finished)) { + status = _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + goto error; + } + if (unlikely (image->status)) { + status = image->status; + goto error; + } + if (unlikely (image->finished)) { + status = _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + goto error; + } + if (unlikely (! _cairo_surface_is_image (image))) { + status = _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + goto error; + } + + status = _cairo_surface_unmap_image (surface, + (cairo_image_surface_t *) image); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return; + +error: + _cairo_surface_set_error (surface, status); + cairo_surface_finish (image); + cairo_surface_destroy (image); +} + +cairo_surface_t * +_cairo_surface_create_scratch (cairo_surface_t *other, + cairo_content_t content, + int width, + int height, + const cairo_color_t *color) +{ + cairo_surface_t *surface; + cairo_status_t status; + cairo_solid_pattern_t pattern; + + if (unlikely (other->status)) + return _cairo_surface_create_in_error (other->status); + + surface = NULL; + if (other->backend->create_similar) + surface = other->backend->create_similar (other, content, width, height); + if (surface == NULL) + surface = cairo_surface_create_similar_image (other, + _cairo_format_from_content (content), + width, height); + + if (unlikely (surface->status)) + return surface; + + _cairo_surface_copy_similar_properties (surface, other); + + if (unlikely (surface->status)) + return surface; + + if (color) { + _cairo_pattern_init_solid (&pattern, color); + status = _cairo_surface_paint (surface, + color == CAIRO_COLOR_TRANSPARENT ? + CAIRO_OPERATOR_CLEAR : CAIRO_OPERATOR_SOURCE, + &pattern.base, NULL); + if (unlikely (status)) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + } + + return surface; +} + +/** + * cairo_surface_reference: + * @surface: a #cairo_surface_t + * + * Increases the reference count on @surface by one. This prevents + * @surface from being destroyed until a matching call to + * cairo_surface_destroy() is made. + * + * The number of references to a #cairo_surface_t can be get using + * cairo_surface_get_reference_count(). + * + * Return value: the referenced #cairo_surface_t. + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_surface_reference (cairo_surface_t *surface) +{ + if (surface == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + return surface; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); + + _cairo_reference_count_inc (&surface->ref_count); + + return surface; +} +slim_hidden_def (cairo_surface_reference); + +/** + * cairo_surface_destroy: + * @surface: a #cairo_surface_t + * + * Decreases the reference count on @surface by one. If the result is + * zero, then @surface and all associated resources are freed. See + * cairo_surface_reference(). + * + * Since: 1.0 + **/ +void +cairo_surface_destroy (cairo_surface_t *surface) +{ + if (surface == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&surface->ref_count)) + return; + + assert (surface->snapshot_of == NULL); + + if (! surface->finished) { + _cairo_surface_finish_snapshots (surface); + /* We may have been referenced by a snapshot prior to have + * detaching it with the copy-on-write. + */ + if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count)) + return; + + _cairo_surface_finish (surface); + } + + if (surface->damage) + _cairo_damage_destroy (surface->damage); + + _cairo_user_data_array_fini (&surface->user_data); + _cairo_user_data_array_fini (&surface->mime_data); + + if (surface->owns_device) + cairo_device_destroy (surface->device); + + assert (surface->snapshot_of == NULL); + assert (! _cairo_surface_has_snapshots (surface)); + /* paranoid check that nobody took a reference whilst finishing */ + assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); + + free (surface); +} +slim_hidden_def(cairo_surface_destroy); + +/** + * cairo_surface_get_reference_count: + * @surface: a #cairo_surface_t + * + * Returns the current reference count of @surface. + * + * Return value: the current reference count of @surface. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.4 + **/ +unsigned int +cairo_surface_get_reference_count (cairo_surface_t *surface) +{ + if (surface == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count); +} + +static void +_cairo_surface_finish_snapshots (cairo_surface_t *surface) +{ + cairo_status_t status; + + /* update the snapshots *before* we declare the surface as finished */ + surface->_finishing = TRUE; + status = _cairo_surface_flush (surface, 0); + (void) status; +} + +static void +_cairo_surface_finish (cairo_surface_t *surface) +{ + cairo_status_t status; + + surface->finished = TRUE; + + /* call finish even if in error mode */ + if (surface->backend->finish) { + status = surface->backend->finish (surface); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + } + + assert (surface->snapshot_of == NULL); + assert (!_cairo_surface_has_snapshots (surface)); +} + +/** + * cairo_surface_finish: + * @surface: the #cairo_surface_t to finish + * + * This function finishes the surface and drops all references to + * external resources. For example, for the Xlib backend it means + * that cairo will no longer access the drawable, which can be freed. + * After calling cairo_surface_finish() the only valid operations on a + * surface are getting and setting user, referencing and + * destroying, and flushing and finishing it. + * Further drawing to the surface will not affect the + * surface but will instead trigger a %CAIRO_STATUS_SURFACE_FINISHED + * error. + * + * When the last call to cairo_surface_destroy() decreases the + * reference count to zero, cairo will call cairo_surface_finish() if + * it hasn't been called already, before freeing the resources + * associated with the surface. + * + * Since: 1.0 + **/ +void +cairo_surface_finish (cairo_surface_t *surface) +{ + if (surface == NULL) + return; + + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + return; + + if (surface->finished) + return; + + /* We have to be careful when decoupling potential reference cycles */ + cairo_surface_reference (surface); + + _cairo_surface_finish_snapshots (surface); + /* XXX need to block and wait for snapshot references */ + _cairo_surface_finish (surface); + + cairo_surface_destroy (surface); +} +slim_hidden_def (cairo_surface_finish); + +/** + * _cairo_surface_release_device_reference: + * @surface: a #cairo_surface_t + * + * This function makes @surface release the reference to its device. The + * function is intended to be used for avoiding cycling references for + * surfaces that are owned by their device, for example cache surfaces. + * Note that the @surface will still assume that the device is available. + * So it is the caller's responsibility to ensure the device stays around + * until the @surface is destroyed. Just calling cairo_surface_finish() is + * not enough. + **/ +void +_cairo_surface_release_device_reference (cairo_surface_t *surface) +{ + assert (surface->owns_device); + + cairo_device_destroy (surface->device); + surface->owns_device = FALSE; +} + +/** + * cairo_surface_get_user_data: + * @surface: a #cairo_surface_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @surface using the specified + * key. If no user data has been attached with the given key this + * function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.0 + **/ +void * +cairo_surface_get_user_data (cairo_surface_t *surface, + const cairo_user_data_key_t *key) +{ + /* Prevent reads of the array during teardown */ + if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) + return NULL; + + return _cairo_user_data_array_get_data (&surface->user_data, key); +} + +/** + * cairo_surface_set_user_data: + * @surface: a #cairo_surface_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the surface + * @destroy: a #cairo_destroy_func_t which will be called when the + * surface is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @surface. To remove user data from a surface, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.0 + **/ +cairo_status_t +cairo_surface_set_user_data (cairo_surface_t *surface, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + return surface->status; + + if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + return _cairo_user_data_array_set_data (&surface->user_data, + key, user_data, destroy); +} + +/** + * cairo_surface_get_mime_data: + * @surface: a #cairo_surface_t + * @mime_type: the mime type of the image data + * @data: the image data to attached to the surface + * @length: the length of the image data + * + * Return mime data previously attached to @surface using the + * specified mime type. If no data has been attached with the given + * mime type, @data is set %NULL. + * + * Since: 1.10 + **/ +void +cairo_surface_get_mime_data (cairo_surface_t *surface, + const char *mime_type, + const unsigned char **data, + unsigned long *length) +{ + cairo_user_data_slot_t *slots; + int i, num_slots; + + *data = NULL; + *length = 0; + + /* Prevent reads of the array during teardown */ + if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) + return; + + /* The number of mime-types attached to a surface is usually small, + * typically zero. Therefore it is quicker to do a strcmp() against + * each key than it is to intern the string (i.e. compute a hash, + * search the hash table, and do a final strcmp). + */ + num_slots = surface->mime_data.num_elements; + slots = _cairo_array_index (&surface->mime_data, 0); + for (i = 0; i < num_slots; i++) { + if (slots[i].key != NULL && strcmp ((char *) slots[i].key, mime_type) == 0) { + cairo_mime_data_t *mime_data = slots[i].user_data; + + *data = mime_data->data; + *length = mime_data->length; + return; + } + } +} +slim_hidden_def (cairo_surface_get_mime_data); + +static void +_cairo_mime_data_destroy (void *ptr) +{ + cairo_mime_data_t *mime_data = ptr; + + if (! _cairo_reference_count_dec_and_test (&mime_data->ref_count)) + return; + + if (mime_data->destroy && mime_data->closure) + mime_data->destroy (mime_data->closure); + + free (mime_data); +} + +/** + * CAIRO_MIME_TYPE_JBIG2: + * + * Joint Bi-level Image Experts Group image coding standard (ISO/IEC 11544). + * + * Since: 1.14 + **/ + +/** + * CAIRO_MIME_TYPE_JBIG2_GLOBAL: + * + * Joint Bi-level Image Experts Group image coding standard (ISO/IEC 11544) global segment. + * + * Since: 1.14 + **/ + +/** + * CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID: + * + * An unique identifier shared by a JBIG2 global segment and all JBIG2 images + * that depend on the global segment. + * + * Since: 1.14 + **/ + +/** + * CAIRO_MIME_TYPE_JP2: + * + * The Joint Photographic Experts Group (JPEG) 2000 image coding standard (ISO/IEC 15444-1). + * + * Since: 1.10 + **/ + +/** + * CAIRO_MIME_TYPE_JPEG: + * + * The Joint Photographic Experts Group (JPEG) image coding standard (ISO/IEC 10918-1). + * + * Since: 1.10 + **/ + +/** + * CAIRO_MIME_TYPE_PNG: + * + * The Portable Network Graphics image file format (ISO/IEC 15948). + * + * Since: 1.10 + **/ + +/** + * CAIRO_MIME_TYPE_URI: + * + * URI for an image file (unofficial MIME type). + * + * Since: 1.10 + **/ + +/** + * CAIRO_MIME_TYPE_UNIQUE_ID: + * + * Unique identifier for a surface (cairo specific MIME type). All surfaces with + * the same unique identifier will only be embedded once. + * + * Since: 1.12 + **/ + +/** + * cairo_surface_set_mime_data: + * @surface: a #cairo_surface_t + * @mime_type: the MIME type of the image data + * @data: the image data to attach to the surface + * @length: the length of the image data + * @destroy: a #cairo_destroy_func_t which will be called when the + * surface is destroyed or when new image data is attached using the + * same mime type. + * @closure: the data to be passed to the @destroy notifier + * + * Attach an image in the format @mime_type to @surface. To remove + * the data from a surface, call this function with same mime type + * and %NULL for @data. + * + * The attached image (or filename) data can later be used by backends + * which support it (currently: PDF, PS, SVG and Win32 Printing + * surfaces) to emit this data instead of making a snapshot of the + * @surface. This approach tends to be faster and requires less + * memory and disk space. + * + * The recognized MIME types are the following: %CAIRO_MIME_TYPE_JPEG, + * %CAIRO_MIME_TYPE_PNG, %CAIRO_MIME_TYPE_JP2, %CAIRO_MIME_TYPE_URI, + * %CAIRO_MIME_TYPE_UNIQUE_ID, %CAIRO_MIME_TYPE_JBIG2, + * %CAIRO_MIME_TYPE_JBIG2_GLOBAL, %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID. + * + * See corresponding backend surface docs for details about which MIME + * types it can handle. Caution: the associated MIME data will be + * discarded if you draw on the surface afterwards. Use this function + * with care. + * + * Even if a backend supports a MIME type, that does not mean cairo + * will always be able to use the attached MIME data. For example, if + * the backend does not natively support the compositing operation used + * to apply the MIME data to the backend. In that case, the MIME data + * will be ignored. Therefore, to apply an image in all cases, it is best + * to create an image surface which contains the decoded image data and + * then attach the MIME data to that. This ensures the image will always + * be used while still allowing the MIME data to be used whenever + * possible. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.10 + **/ +cairo_status_t +cairo_surface_set_mime_data (cairo_surface_t *surface, + const char *mime_type, + const unsigned char *data, + unsigned long length, + cairo_destroy_func_t destroy, + void *closure) +{ + cairo_status_t status; + cairo_mime_data_t *mime_data; + + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + return surface->status; + + if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + status = _cairo_intern_string (&mime_type, -1); + if (unlikely (status)) + return _cairo_surface_set_error (surface, status); + + if (data != NULL) { + mime_data = malloc (sizeof (cairo_mime_data_t)); + if (unlikely (mime_data == NULL)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_NO_MEMORY)); + + CAIRO_REFERENCE_COUNT_INIT (&mime_data->ref_count, 1); + + mime_data->data = (unsigned char *) data; + mime_data->length = length; + mime_data->destroy = destroy; + mime_data->closure = closure; + } else + mime_data = NULL; + + status = _cairo_user_data_array_set_data (&surface->mime_data, + (cairo_user_data_key_t *) mime_type, + mime_data, + _cairo_mime_data_destroy); + if (unlikely (status)) { + free (mime_data); + + return _cairo_surface_set_error (surface, status); + } + + return CAIRO_STATUS_SUCCESS; +} +slim_hidden_def (cairo_surface_set_mime_data); + +/** + * cairo_surface_supports_mime_type: + * @surface: a #cairo_surface_t + * @mime_type: the mime type + * + * Return whether @surface supports @mime_type. + * + * Return value: %TRUE if @surface supports + * @mime_type, %FALSE otherwise + * + * Since: 1.12 + **/ +cairo_bool_t +cairo_surface_supports_mime_type (cairo_surface_t *surface, + const char *mime_type) +{ + const char **types; + + if (unlikely (surface->status)) + return FALSE; + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (surface->backend->get_supported_mime_types) { + types = surface->backend->get_supported_mime_types (surface); + if (types) { + while (*types) { + if (strcmp (*types, mime_type) == 0) + return TRUE; + types++; + } + } + } + + return FALSE; +} +slim_hidden_def (cairo_surface_supports_mime_type); + +static void +_cairo_mime_data_reference (const void *key, void *elt, void *closure) +{ + cairo_mime_data_t *mime_data = elt; + + _cairo_reference_count_inc (&mime_data->ref_count); +} + +cairo_status_t +_cairo_surface_copy_mime_data (cairo_surface_t *dst, + cairo_surface_t *src) +{ + cairo_status_t status; + + if (dst->status) + return dst->status; + + if (src->status) + return _cairo_surface_set_error (dst, src->status); + + /* first copy the mime-data, discarding any already set on dst */ + status = _cairo_user_data_array_copy (&dst->mime_data, &src->mime_data); + if (unlikely (status)) + return _cairo_surface_set_error (dst, status); + + /* now increment the reference counters for the copies */ + _cairo_user_data_array_foreach (&dst->mime_data, + _cairo_mime_data_reference, + NULL); + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_surface_set_font_options: + * @surface: a #cairo_surface_t + * @options: a #cairo_font_options_t object that contains the + * options to use for this surface instead of backend's default + * font options. + * + * Sets the default font rendering options for the surface. + * This is useful to correctly propagate default font options when + * falling back to an image surface in a backend implementation. + * This affects the options returned in cairo_surface_get_font_options(). + * + * If @options is %NULL the surface options are reset to those of + * the backend default. + **/ +void +_cairo_surface_set_font_options (cairo_surface_t *surface, + cairo_font_options_t *options) +{ + if (surface->status) + return; + + assert (surface->snapshot_of == NULL); + + if (surface->finished) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (options) { + surface->has_font_options = TRUE; + _cairo_font_options_init_copy (&surface->font_options, options); + } else { + surface->has_font_options = FALSE; + } +} + +/** + * cairo_surface_get_font_options: + * @surface: a #cairo_surface_t + * @options: a #cairo_font_options_t object into which to store + * the retrieved options. All existing values are overwritten + * + * Retrieves the default font rendering options for the surface. + * This allows display surfaces to report the correct subpixel order + * for rendering on them, print surfaces to disable hinting of + * metrics and so forth. The result can then be used with + * cairo_scaled_font_create(). + * + * Since: 1.0 + **/ +void +cairo_surface_get_font_options (cairo_surface_t *surface, + cairo_font_options_t *options) +{ + if (cairo_font_options_status (options)) + return; + + if (surface->status) { + _cairo_font_options_init_default (options); + return; + } + + if (! surface->has_font_options) { + surface->has_font_options = TRUE; + + _cairo_font_options_init_default (&surface->font_options); + + if (!surface->finished && surface->backend->get_font_options) { + surface->backend->get_font_options (surface, &surface->font_options); + } + } + + _cairo_font_options_init_copy (options, &surface->font_options); +} +slim_hidden_def (cairo_surface_get_font_options); + +cairo_status_t +_cairo_surface_flush (cairo_surface_t *surface, unsigned flags) +{ + /* update the current snapshots *before* the user updates the surface */ + _cairo_surface_detach_snapshots (surface); + if (surface->snapshot_of != NULL) + _cairo_surface_detach_snapshot (surface); + _cairo_surface_detach_mime_data (surface); + + return __cairo_surface_flush (surface, flags); +} + +/** + * cairo_surface_flush: + * @surface: a #cairo_surface_t + * + * Do any pending drawing for the surface and also restore any temporary + * modifications cairo has made to the surface's state. This function + * must be called before switching from drawing on the surface with + * cairo to drawing on it directly with native APIs, or accessing its + * memory outside of Cairo. If the surface doesn't support direct + * access, then this function does nothing. + * + * Since: 1.0 + **/ +void +cairo_surface_flush (cairo_surface_t *surface) +{ + cairo_status_t status; + + if (surface->status) + return; + + if (surface->finished) + return; + + status = _cairo_surface_flush (surface, 0); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); +} +slim_hidden_def (cairo_surface_flush); + +/** + * cairo_surface_mark_dirty: + * @surface: a #cairo_surface_t + * + * Tells cairo that drawing has been done to surface using means other + * than cairo, and that cairo should reread any cached areas. Note + * that you must call cairo_surface_flush() before doing such drawing. + * + * Since: 1.0 + **/ +void +cairo_surface_mark_dirty (cairo_surface_t *surface) +{ + cairo_rectangle_int_t extents; + + if (unlikely (surface->status)) + return; + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + _cairo_surface_get_extents (surface, &extents); + cairo_surface_mark_dirty_rectangle (surface, + extents.x, extents.y, + extents.width, extents.height); +} +slim_hidden_def (cairo_surface_mark_dirty); + +/** + * cairo_surface_mark_dirty_rectangle: + * @surface: a #cairo_surface_t + * @x: X coordinate of dirty rectangle + * @y: Y coordinate of dirty rectangle + * @width: width of dirty rectangle + * @height: height of dirty rectangle + * + * Like cairo_surface_mark_dirty(), but drawing has been done only to + * the specified rectangle, so that cairo can retain cached contents + * for other parts of the surface. + * + * Any cached clip set on the surface will be reset by this function, + * to make sure that future cairo calls have the clip set that they + * expect. + * + * Since: 1.0 + **/ +void +cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, + int x, + int y, + int width, + int height) +{ + cairo_status_t status; + + if (unlikely (surface->status)) + return; + + assert (surface->snapshot_of == NULL); + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + /* The application *should* have called cairo_surface_flush() before + * modifying the surface independently of cairo (and thus having to + * call mark_dirty()). */ + assert (! _cairo_surface_has_snapshots (surface)); + assert (! _cairo_surface_has_mime_data (surface)); + + surface->is_clear = FALSE; + surface->serial++; + + if (surface->damage) { + cairo_box_t box; + + box.p1.x = x; + box.p1.y = y; + box.p2.x = x + width; + box.p2.y = y + height; + + surface->damage = _cairo_damage_add_box (surface->damage, &box); + } + + if (surface->backend->mark_dirty_rectangle != NULL) { + /* XXX: FRAGILE: We're ignoring the scaling component of + * device_transform here. I don't know what the right thing to + * do would actually be if there were some scaling here, but + * we avoid this since device_transfom scaling is not exported + * publicly and mark_dirty is not used internally. */ + status = surface->backend->mark_dirty_rectangle (surface, + x + surface->device_transform.x0, + y + surface->device_transform.y0, + width, height); + + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + } +} +slim_hidden_def (cairo_surface_mark_dirty_rectangle); + +/** + * cairo_surface_set_device_scale: + * @surface: a #cairo_surface_t + * @x_scale: a scale factor in the X direction + * @y_scale: a scale factor in the Y direction + * + * Sets a scale that is multiplied to the device coordinates determined + * by the CTM when drawing to @surface. One common use for this is to + * render to very high resolution display devices at a scale factor, so + * that code that assumes 1 pixel will be a certain size will still work. + * Setting a transformation via cairo_translate() isn't + * sufficient to do this, since functions like + * cairo_device_to_user() will expose the hidden scale. + * + * Note that the scale affects drawing to the surface as well as + * using the surface in a source pattern. + * + * Since: 1.14 + **/ +void +cairo_surface_set_device_scale (cairo_surface_t *surface, + double x_scale, + double y_scale) +{ + cairo_status_t status; + + if (unlikely (surface->status)) + return; + + assert (surface->snapshot_of == NULL); + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return; + } + + surface->device_transform.xx = x_scale; + surface->device_transform.yy = y_scale; + surface->device_transform.xy = 0.0; + surface->device_transform.yx = 0.0; + + surface->device_transform_inverse = surface->device_transform; + status = cairo_matrix_invert (&surface->device_transform_inverse); + /* should always be invertible unless given pathological input */ + assert (status == CAIRO_STATUS_SUCCESS); + + _cairo_observers_notify (&surface->device_transform_observers, surface); +} +slim_hidden_def (cairo_surface_set_device_scale); + +/** + * cairo_surface_get_device_scale: + * @surface: a #cairo_surface_t + * @x_scale: the scale in the X direction, in device units + * @y_scale: the scale in the Y direction, in device units + * + * This function returns the previous device offset set by + * cairo_surface_set_device_scale(). + * + * Since: 1.14 + **/ +void +cairo_surface_get_device_scale (cairo_surface_t *surface, + double *x_scale, + double *y_scale) +{ + if (x_scale) + *x_scale = surface->device_transform.xx; + if (y_scale) + *y_scale = surface->device_transform.yy; +} +slim_hidden_def (cairo_surface_get_device_scale); + +/** + * cairo_surface_set_device_offset: + * @surface: a #cairo_surface_t + * @x_offset: the offset in the X direction, in device units + * @y_offset: the offset in the Y direction, in device units + * + * Sets an offset that is added to the device coordinates determined + * by the CTM when drawing to @surface. One use case for this function + * is when we want to create a #cairo_surface_t that redirects drawing + * for a portion of an onscreen surface to an offscreen surface in a + * way that is completely invisible to the user of the cairo + * API. Setting a transformation via cairo_translate() isn't + * sufficient to do this, since functions like + * cairo_device_to_user() will expose the hidden offset. + * + * Note that the offset affects drawing to the surface as well as + * using the surface in a source pattern. + * + * Since: 1.0 + **/ +void +cairo_surface_set_device_offset (cairo_surface_t *surface, + double x_offset, + double y_offset) +{ + cairo_status_t status; + + if (unlikely (surface->status)) + return; + + assert (surface->snapshot_of == NULL); + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return; + } + + surface->device_transform.x0 = x_offset; + surface->device_transform.y0 = y_offset; + + surface->device_transform_inverse = surface->device_transform; + status = cairo_matrix_invert (&surface->device_transform_inverse); + /* should always be invertible unless given pathological input */ + assert (status == CAIRO_STATUS_SUCCESS); + + _cairo_observers_notify (&surface->device_transform_observers, surface); +} +slim_hidden_def (cairo_surface_set_device_offset); + +/** + * cairo_surface_get_device_offset: + * @surface: a #cairo_surface_t + * @x_offset: the offset in the X direction, in device units + * @y_offset: the offset in the Y direction, in device units + * + * This function returns the previous device offset set by + * cairo_surface_set_device_offset(). + * + * Since: 1.2 + **/ +void +cairo_surface_get_device_offset (cairo_surface_t *surface, + double *x_offset, + double *y_offset) +{ + if (x_offset) + *x_offset = surface->device_transform.x0; + if (y_offset) + *y_offset = surface->device_transform.y0; +} +slim_hidden_def (cairo_surface_get_device_offset); + +/** + * cairo_surface_set_fallback_resolution: + * @surface: a #cairo_surface_t + * @x_pixels_per_inch: horizontal setting for pixels per inch + * @y_pixels_per_inch: vertical setting for pixels per inch + * + * Set the horizontal and vertical resolution for image fallbacks. + * + * When certain operations aren't supported natively by a backend, + * cairo will fallback by rendering operations to an image and then + * overlaying that image onto the output. For backends that are + * natively vector-oriented, this function can be used to set the + * resolution used for these image fallbacks, (larger values will + * result in more detailed images, but also larger file sizes). + * + * Some examples of natively vector-oriented backends are the ps, pdf, + * and svg backends. + * + * For backends that are natively raster-oriented, image fallbacks are + * still possible, but they are always performed at the native + * device resolution. So this function has no effect on those + * backends. + * + * Note: The fallback resolution only takes effect at the time of + * completing a page (with cairo_show_page() or cairo_copy_page()) so + * there is currently no way to have more than one fallback resolution + * in effect on a single page. + * + * The default fallback resoultion is 300 pixels per inch in both + * dimensions. + * + * Since: 1.2 + **/ +void +cairo_surface_set_fallback_resolution (cairo_surface_t *surface, + double x_pixels_per_inch, + double y_pixels_per_inch) +{ + cairo_status_t status; + + if (unlikely (surface->status)) + return; + + assert (surface->snapshot_of == NULL); + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (x_pixels_per_inch <= 0 || y_pixels_per_inch <= 0) { + /* XXX Could delay raising the error until we fallback, but throwing + * the error here means that we can catch the real culprit. + */ + _cairo_surface_set_error (surface, CAIRO_STATUS_INVALID_MATRIX); + return; + } + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return; + } + + surface->x_fallback_resolution = x_pixels_per_inch; + surface->y_fallback_resolution = y_pixels_per_inch; +} +slim_hidden_def (cairo_surface_set_fallback_resolution); + +/** + * cairo_surface_get_fallback_resolution: + * @surface: a #cairo_surface_t + * @x_pixels_per_inch: horizontal pixels per inch + * @y_pixels_per_inch: vertical pixels per inch + * + * This function returns the previous fallback resolution set by + * cairo_surface_set_fallback_resolution(), or default fallback + * resolution if never set. + * + * Since: 1.8 + **/ +void +cairo_surface_get_fallback_resolution (cairo_surface_t *surface, + double *x_pixels_per_inch, + double *y_pixels_per_inch) +{ + if (x_pixels_per_inch) + *x_pixels_per_inch = surface->x_fallback_resolution; + if (y_pixels_per_inch) + *y_pixels_per_inch = surface->y_fallback_resolution; +} + +cairo_bool_t +_cairo_surface_has_device_transform (cairo_surface_t *surface) +{ + return ! _cairo_matrix_is_identity (&surface->device_transform); +} + +/** + * _cairo_surface_acquire_source_image: + * @surface: a #cairo_surface_t + * @image_out: location to store a pointer to an image surface that + * has identical contents to @surface. This surface could be @surface + * itself, a surface held internal to @surface, or it could be a new + * surface with a copy of the relevant portion of @surface. + * @image_extra: location to store image specific backend data + * + * Gets an image surface to use when drawing as a fallback when drawing with + * @surface as a source. _cairo_surface_release_source_image() must be called + * when finished. + * + * Return value: %CAIRO_STATUS_SUCCESS if an image was stored in @image_out. + * %CAIRO_INT_STATUS_UNSUPPORTED if an image cannot be retrieved for the specified + * surface. Or %CAIRO_STATUS_NO_MEMORY. + **/ +cairo_status_t +_cairo_surface_acquire_source_image (cairo_surface_t *surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_status_t status; + + if (unlikely (surface->status)) + return surface->status; + + assert (!surface->finished); + + if (surface->backend->acquire_source_image == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = surface->backend->acquire_source_image (surface, + image_out, image_extra); + if (unlikely (status)) + return _cairo_surface_set_error (surface, status); + + _cairo_debug_check_image_surface_is_defined (&(*image_out)->base); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_surface_default_acquire_source_image (void *_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_surface_t *surface = _surface; + cairo_rectangle_int_t extents; + + if (unlikely (! surface->backend->get_extents (surface, &extents))) + return _cairo_error (CAIRO_STATUS_INVALID_SIZE); + + *image_out = _cairo_surface_map_to_image (surface, &extents); + *image_extra = NULL; + return (*image_out)->base.status; +} + +/** + * _cairo_surface_release_source_image: + * @surface: a #cairo_surface_t + * @image_extra: same as return from the matching _cairo_surface_acquire_source_image() + * + * Releases any resources obtained with _cairo_surface_acquire_source_image() + **/ +void +_cairo_surface_release_source_image (cairo_surface_t *surface, + cairo_image_surface_t *image, + void *image_extra) +{ + assert (!surface->finished); + + if (surface->backend->release_source_image) + surface->backend->release_source_image (surface, image, image_extra); +} + +void +_cairo_surface_default_release_source_image (void *surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_status_t ignored; + + ignored = _cairo_surface_unmap_image (surface, image); + (void)ignored; +} + + +cairo_surface_t * +_cairo_surface_get_source (cairo_surface_t *surface, + cairo_rectangle_int_t *extents) +{ + assert (surface->backend->source); + return surface->backend->source (surface, extents); +} + +cairo_surface_t * +_cairo_surface_default_source (void *surface, + cairo_rectangle_int_t *extents) +{ + if (extents) + _cairo_surface_get_extents(surface, extents); + return surface; +} + +static cairo_status_t +_pattern_has_error (const cairo_pattern_t *pattern) +{ + const cairo_surface_pattern_t *spattern; + + if (unlikely (pattern->status)) + return pattern->status; + + if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) + return CAIRO_STATUS_SUCCESS; + + spattern = (const cairo_surface_pattern_t *) pattern; + if (unlikely (spattern->surface->status)) + return spattern->surface->status; + + if (unlikely (spattern->surface->finished)) + return _cairo_error (CAIRO_STATUS_SURFACE_FINISHED); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +nothing_to_do (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source) +{ + if (_cairo_pattern_is_clear (source)) { + if (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD) + return TRUE; + + if (op == CAIRO_OPERATOR_SOURCE) + op = CAIRO_OPERATOR_CLEAR; + } + + if (op == CAIRO_OPERATOR_CLEAR && surface->is_clear) + return TRUE; + + if (op == CAIRO_OPERATOR_ATOP && (surface->content & CAIRO_CONTENT_COLOR) ==0) + return TRUE; + + return FALSE; +} + +cairo_status_t +_cairo_surface_paint (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + status = _pattern_has_error (source); + if (unlikely (status)) + return status; + + if (nothing_to_do (surface, op, source)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) + return status; + + status = surface->backend->paint (surface, op, source, clip); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + surface->is_clear = op == CAIRO_OPERATOR_CLEAR && clip == NULL; + surface->serial++; + } + + return _cairo_surface_set_error (surface, status); +} + +cairo_status_t +_cairo_surface_mask (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + /* If the mask is blank, this is just an expensive no-op */ + if (_cairo_pattern_is_clear (mask) && + _cairo_operator_bounded_by_mask (op)) + { + return CAIRO_STATUS_SUCCESS; + } + + status = _pattern_has_error (source); + if (unlikely (status)) + return status; + + status = _pattern_has_error (mask); + if (unlikely (status)) + return status; + + if (nothing_to_do (surface, op, source)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) + return status; + + status = surface->backend->mask (surface, op, source, mask, clip); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + surface->is_clear = FALSE; + surface->serial++; + } + + return _cairo_surface_set_error (surface, status); +} + +cairo_status_t +_cairo_surface_fill_stroke (cairo_surface_t *surface, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + cairo_path_fixed_t *path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + if (surface->is_clear && + fill_op == CAIRO_OPERATOR_CLEAR && + stroke_op == CAIRO_OPERATOR_CLEAR) + { + return CAIRO_STATUS_SUCCESS; + } + + status = _pattern_has_error (fill_source); + if (unlikely (status)) + return status; + + status = _pattern_has_error (stroke_source); + if (unlikely (status)) + return status; + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) + return status; + + if (surface->backend->fill_stroke) { + cairo_matrix_t dev_ctm = *stroke_ctm; + cairo_matrix_t dev_ctm_inverse = *stroke_ctm_inverse; + + status = surface->backend->fill_stroke (surface, + fill_op, fill_source, fill_rule, + fill_tolerance, fill_antialias, + path, + stroke_op, stroke_source, + stroke_style, + &dev_ctm, &dev_ctm_inverse, + stroke_tolerance, stroke_antialias, + clip); + + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + goto FINISH; + } + + status = _cairo_surface_fill (surface, fill_op, fill_source, path, + fill_rule, fill_tolerance, fill_antialias, + clip); + if (unlikely (status)) + goto FINISH; + + status = _cairo_surface_stroke (surface, stroke_op, stroke_source, path, + stroke_style, stroke_ctm, stroke_ctm_inverse, + stroke_tolerance, stroke_antialias, + clip); + if (unlikely (status)) + goto FINISH; + + FINISH: + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + surface->is_clear = FALSE; + surface->serial++; + } + + return _cairo_surface_set_error (surface, status); +} + +cairo_status_t +_cairo_surface_stroke (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + status = _pattern_has_error (source); + if (unlikely (status)) + return status; + + if (nothing_to_do (surface, op, source)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) + return status; + + status = surface->backend->stroke (surface, op, source, + path, stroke_style, + ctm, ctm_inverse, + tolerance, antialias, + clip); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + surface->is_clear = FALSE; + surface->serial++; + } + + return _cairo_surface_set_error (surface, status); +} + +cairo_status_t +_cairo_surface_fill (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + status = _pattern_has_error (source); + if (unlikely (status)) + return status; + + if (nothing_to_do (surface, op, source)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) + return status; + + status = surface->backend->fill (surface, op, source, + path, fill_rule, + tolerance, antialias, + clip); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + surface->is_clear = FALSE; + surface->serial++; + } + + return _cairo_surface_set_error (surface, status); +} + +/** + * cairo_surface_copy_page: + * @surface: a #cairo_surface_t + * + * Emits the current page for backends that support multiple pages, + * but doesn't clear it, so that the contents of the current page will + * be retained for the next page. Use cairo_surface_show_page() if you + * want to get an empty page after the emission. + * + * There is a convenience function for this that takes a #cairo_t, + * namely cairo_copy_page(). + * + * Since: 1.6 + **/ +void +cairo_surface_copy_page (cairo_surface_t *surface) +{ + if (unlikely (surface->status)) + return; + + assert (surface->snapshot_of == NULL); + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); + return; + } + + /* It's fine if some backends don't implement copy_page */ + if (surface->backend->copy_page == NULL) + return; + + _cairo_surface_set_error (surface, surface->backend->copy_page (surface)); +} +slim_hidden_def (cairo_surface_copy_page); + +/** + * cairo_surface_show_page: + * @surface: a #cairo_Surface_t + * + * Emits and clears the current page for backends that support multiple + * pages. Use cairo_surface_copy_page() if you don't want to clear the page. + * + * There is a convenience function for this that takes a #cairo_t, + * namely cairo_show_page(). + * + * Since: 1.6 + **/ +void +cairo_surface_show_page (cairo_surface_t *surface) +{ + cairo_status_t status; + + if (unlikely (surface->status)) + return; + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); + return; + } + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return; + } + + /* It's fine if some backends don't implement show_page */ + if (surface->backend->show_page == NULL) + return; + + _cairo_surface_set_error (surface, surface->backend->show_page (surface)); +} +slim_hidden_def (cairo_surface_show_page); + +/** + * _cairo_surface_get_extents: + * @surface: the #cairo_surface_t to fetch extents for + * + * This function returns a bounding box for the surface. The surface + * bounds are defined as a region beyond which no rendering will + * possibly be recorded, in other words, it is the maximum extent of + * potentially usable coordinates. + * + * For vector surfaces, (PDF, PS, SVG and recording-surfaces), the surface + * might be conceived as unbounded, but we force the user to provide a + * maximum size at the time of surface_create. So get_extents uses + * that size. + * + * Note: The coordinates returned are in "backend" space rather than + * "surface" space. That is, they are relative to the true (0,0) + * origin rather than the device_transform origin. This might seem a + * bit inconsistent with other #cairo_surface_t interfaces, but all + * current callers are within the surface layer where backend space is + * desired. + * + * This behavior would have to be changed is we ever exported a public + * variant of this function. + **/ +cairo_bool_t +_cairo_surface_get_extents (cairo_surface_t *surface, + cairo_rectangle_int_t *extents) +{ + cairo_bool_t bounded; + + if (unlikely (surface->status)) + goto zero_extents; + if (unlikely (surface->finished)) { + _cairo_surface_set_error(surface, CAIRO_STATUS_SURFACE_FINISHED); + goto zero_extents; + } + + bounded = FALSE; + if (surface->backend->get_extents != NULL) + bounded = surface->backend->get_extents (surface, extents); + + if (! bounded) + _cairo_unbounded_rectangle_init (extents); + + return bounded; + +zero_extents: + extents->x = extents->y = 0; + extents->width = extents->height = 0; + return TRUE; +} + +/** + * cairo_surface_has_show_text_glyphs: + * @surface: a #cairo_surface_t + * + * Returns whether the surface supports + * sophisticated cairo_show_text_glyphs() operations. That is, + * whether it actually uses the provided text and cluster data + * to a cairo_show_text_glyphs() call. + * + * Note: Even if this function returns %FALSE, a + * cairo_show_text_glyphs() operation targeted at @surface will + * still succeed. It just will + * act like a cairo_show_glyphs() operation. Users can use this + * function to avoid computing UTF-8 text and cluster mapping if the + * target surface does not use it. + * + * Return value: %TRUE if @surface supports + * cairo_show_text_glyphs(), %FALSE otherwise + * + * Since: 1.8 + **/ +cairo_bool_t +cairo_surface_has_show_text_glyphs (cairo_surface_t *surface) +{ + if (unlikely (surface->status)) + return FALSE; + + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); + return FALSE; + } + + if (surface->backend->has_show_text_glyphs) + return surface->backend->has_show_text_glyphs (surface); + else + return surface->backend->show_text_glyphs != NULL; +} +slim_hidden_def (cairo_surface_has_show_text_glyphs); + +/* Note: the backends may modify the contents of the glyph array as long as + * they do not return %CAIRO_INT_STATUS_UNSUPPORTED. This makes it possible to + * avoid copying the array again and again, and edit it in-place. + * Backends are in fact free to use the array as a generic buffer as they + * see fit. + * + * For show_glyphs backend method, and NOT for show_text_glyphs method, + * when they do return UNSUPPORTED, they may adjust remaining_glyphs to notify + * that they have successfully rendered some of the glyphs (from the beginning + * of the array), but not all. If they don't touch remaining_glyphs, it + * defaults to all glyphs. + * + * See commits 5a9642c5746fd677aed35ce620ce90b1029b1a0c and + * 1781e6018c17909311295a9cc74b70500c6b4d0a for the rationale. + */ +cairo_status_t +_cairo_surface_show_text_glyphs (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + if (unlikely (surface->status)) + return surface->status; + if (unlikely (surface->finished)) + return _cairo_surface_set_error (surface, _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (num_glyphs == 0 && utf8_len == 0) + return CAIRO_STATUS_SUCCESS; + + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_STATUS_SUCCESS; + + status = _pattern_has_error (source); + if (unlikely (status)) + return status; + + if (nothing_to_do (surface, op, source)) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_begin_modification (surface); + if (unlikely (status)) + return status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + + /* The logic here is duplicated in _cairo_analysis_surface show_glyphs and + * show_text_glyphs. Keep in synch. */ + if (clusters) { + /* A real show_text_glyphs call. Try show_text_glyphs backend + * method first */ + if (surface->backend->show_text_glyphs != NULL) { + status = surface->backend->show_text_glyphs (surface, op, + source, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, cluster_flags, + scaled_font, + clip); + } + if (status == CAIRO_INT_STATUS_UNSUPPORTED && + surface->backend->show_glyphs) + { + status = surface->backend->show_glyphs (surface, op, + source, + glyphs, num_glyphs, + scaled_font, + clip); + } + } else { + /* A mere show_glyphs call. Try show_glyphs backend method first */ + if (surface->backend->show_glyphs != NULL) { + status = surface->backend->show_glyphs (surface, op, + source, + glyphs, num_glyphs, + scaled_font, + clip); + } else if (surface->backend->show_text_glyphs != NULL) { + /* Intentionally only try show_text_glyphs method for show_glyphs + * calls if backend does not have show_glyphs. If backend has + * both methods implemented, we don't fallback from show_glyphs to + * show_text_glyphs, and hence the backend can assume in its + * show_text_glyphs call that clusters is not NULL (which also + * implies that UTF-8 is not NULL, unless the text is + * zero-length). + */ + status = surface->backend->show_text_glyphs (surface, op, + source, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, cluster_flags, + scaled_font, + clip); + } + } + + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + surface->is_clear = FALSE; + surface->serial++; + } + + return _cairo_surface_set_error (surface, status); +} + +/** + * _cairo_surface_set_resolution: + * @surface: the surface + * @x_res: x resolution, in dpi + * @y_res: y resolution, in dpi + * + * Set the actual surface resolution of @surface to the given x and y DPI. + * Mainly used for correctly computing the scale factor when fallback + * rendering needs to take place in the paginated surface. + **/ +void +_cairo_surface_set_resolution (cairo_surface_t *surface, + double x_res, + double y_res) +{ + if (surface->status) + return; + + surface->x_resolution = x_res; + surface->y_resolution = y_res; +} + +/** + * _cairo_surface_create_in_error: + * @status: the error status + * + * Return an appropriate static error surface for the error status. + * On error, surface creation functions should always return a surface + * created with _cairo_surface_create_in_error() instead of a new surface + * in an error state. This simplifies internal code as no refcounting has + * to be done. + **/ +cairo_surface_t * +_cairo_surface_create_in_error (cairo_status_t status) +{ + assert (status < CAIRO_STATUS_LAST_STATUS); + switch (status) { + case CAIRO_STATUS_NO_MEMORY: + return (cairo_surface_t *) &_cairo_surface_nil; + case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: + return (cairo_surface_t *) &_cairo_surface_nil_surface_type_mismatch; + case CAIRO_STATUS_INVALID_STATUS: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_status; + case CAIRO_STATUS_INVALID_CONTENT: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_content; + case CAIRO_STATUS_INVALID_FORMAT: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_format; + case CAIRO_STATUS_INVALID_VISUAL: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_visual; + case CAIRO_STATUS_READ_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_read_error; + case CAIRO_STATUS_WRITE_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_write_error; + case CAIRO_STATUS_FILE_NOT_FOUND: + return (cairo_surface_t *) &_cairo_surface_nil_file_not_found; + case CAIRO_STATUS_TEMP_FILE_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_temp_file_error; + case CAIRO_STATUS_INVALID_STRIDE: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_stride; + case CAIRO_STATUS_INVALID_SIZE: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_size; + case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: + return (cairo_surface_t *) &_cairo_surface_nil_device_type_mismatch; + case CAIRO_STATUS_DEVICE_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_device_error; + case CAIRO_STATUS_SUCCESS: + case CAIRO_STATUS_LAST_STATUS: + ASSERT_NOT_REACHED; + /* fall-through */ + case CAIRO_STATUS_INVALID_RESTORE: + case CAIRO_STATUS_INVALID_POP_GROUP: + case CAIRO_STATUS_NO_CURRENT_POINT: + case CAIRO_STATUS_INVALID_MATRIX: + case CAIRO_STATUS_NULL_POINTER: + case CAIRO_STATUS_INVALID_STRING: + case CAIRO_STATUS_INVALID_PATH_DATA: + case CAIRO_STATUS_SURFACE_FINISHED: + case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: + case CAIRO_STATUS_INVALID_DASH: + case CAIRO_STATUS_INVALID_DSC_COMMENT: + case CAIRO_STATUS_INVALID_INDEX: + case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: + case CAIRO_STATUS_FONT_TYPE_MISMATCH: + case CAIRO_STATUS_USER_FONT_IMMUTABLE: + case CAIRO_STATUS_USER_FONT_ERROR: + case CAIRO_STATUS_NEGATIVE_COUNT: + case CAIRO_STATUS_INVALID_CLUSTERS: + case CAIRO_STATUS_INVALID_SLANT: + case CAIRO_STATUS_INVALID_WEIGHT: + case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: + case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: + case CAIRO_STATUS_DEVICE_FINISHED: + case CAIRO_STATUS_JBIG2_GLOBAL_MISSING: + default: + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_surface_t *) &_cairo_surface_nil; + } +} + +cairo_surface_t * +_cairo_int_surface_create_in_error (cairo_int_status_t status) +{ + if (status < CAIRO_INT_STATUS_LAST_STATUS) + return _cairo_surface_create_in_error (status); + + switch ((int)status) { + case CAIRO_INT_STATUS_UNSUPPORTED: + return (cairo_surface_t *) &_cairo_surface_nil_unsupported; + case CAIRO_INT_STATUS_NOTHING_TO_DO: + return (cairo_surface_t *) &_cairo_surface_nil_nothing_to_do; + default: + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_surface_t *) &_cairo_surface_nil; + } +} + +/* LocalWords: rasterized + */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-svg-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-svg-surface-private.h new file mode 100644 index 00000000000..ddbf464b1d2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-svg-surface-private.h @@ -0,0 +1,74 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * Copyright © 2005-2006 Emmanuel Pacaud + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Emmanuel Pacaud + * Carl Worth + */ + +#ifndef CAIRO_SVG_SURFACE_PRIVATE_H +#define CAIRO_SVG_SURFACE_PRIVATE_H + +#include "cairo-svg.h" + +#include "cairo-surface-private.h" +#include "cairo-surface-clipper-private.h" + +typedef struct cairo_svg_document cairo_svg_document_t; + +typedef struct cairo_svg_surface { + cairo_surface_t base; + + cairo_content_t content; + + double width; + double height; + + cairo_svg_document_t *document; + + cairo_output_stream_t *xml_node; + cairo_array_t page_set; + + cairo_surface_clipper_t clipper; + unsigned int clip_level; + unsigned int base_clip; + cairo_bool_t is_base_clip_emitted; + + cairo_paginated_mode_t paginated_mode; + + cairo_bool_t force_fallbacks; +} cairo_svg_surface_t; + +#endif /* CAIRO_SVG_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-svg-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-svg-surface.c new file mode 100644 index 00000000000..372ef45b86e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-svg-surface.c @@ -0,0 +1,2884 @@ +/* vim: set sw=4 sts=4: -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * Copyright © 2005-2007 Emmanuel Pacaud + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Kristian Høgsberg + * Emmanuel Pacaud + * Carl Worth + */ + +#define _BSD_SOURCE /* for snprintf() */ +#include "cairoint.h" + +#include "cairo-svg.h" + +#include "cairo-array-private.h" +#include "cairo-analysis-surface-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-info-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-output-stream-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-paginated-private.h" +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-svg-surface-private.h" + +/** + * SECTION:cairo-svg + * @Title: SVG Surfaces + * @Short_Description: Rendering SVG documents + * @See_Also: #cairo_surface_t + * + * The SVG surface is used to render cairo graphics to + * SVG files and is a multi-page vector surface backend. + **/ + +/** + * CAIRO_HAS_SVG_SURFACE: + * + * Defined if the SVG surface backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.2 + **/ + +typedef struct cairo_svg_page cairo_svg_page_t; + +static const int invalid_pattern_id = -1; + +static const cairo_svg_version_t _cairo_svg_versions[] = +{ + CAIRO_SVG_VERSION_1_1, + CAIRO_SVG_VERSION_1_2 +}; + +#define CAIRO_SVG_VERSION_LAST ARRAY_LENGTH (_cairo_svg_versions) + +static const char *_cairo_svg_supported_mime_types[] = +{ + CAIRO_MIME_TYPE_JPEG, + CAIRO_MIME_TYPE_PNG, + CAIRO_MIME_TYPE_URI, + NULL +}; + +static void +_cairo_svg_surface_emit_path (cairo_output_stream_t *output, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm_inverse); + +static cairo_bool_t +_cairo_svg_version_has_page_set_support (cairo_svg_version_t version) +{ + return version > CAIRO_SVG_VERSION_1_1; +} + +static const char * _cairo_svg_version_strings[CAIRO_SVG_VERSION_LAST] = +{ + "SVG 1.1", + "SVG 1.2" +}; + +static const char * _cairo_svg_internal_version_strings[CAIRO_SVG_VERSION_LAST] = +{ + "1.1", + "1.2" +}; + +struct cairo_svg_page { + unsigned int surface_id; + unsigned int clip_level; + cairo_output_stream_t *xml_node; +}; + +struct cairo_svg_document { + cairo_output_stream_t *output_stream; + unsigned long refcount; + cairo_surface_t *owner; + cairo_bool_t finished; + + double width; + double height; + + cairo_output_stream_t *xml_node_defs; + cairo_output_stream_t *xml_node_glyphs; + + unsigned int linear_pattern_id; + unsigned int radial_pattern_id; + unsigned int pattern_id; + unsigned int filter_id; + unsigned int clip_id; + unsigned int mask_id; + + cairo_bool_t alpha_filter; + + cairo_svg_version_t svg_version; + + cairo_scaled_font_subsets_t *font_subsets; +}; + +static cairo_status_t +_cairo_svg_document_create (cairo_output_stream_t *stream, + double width, + double height, + cairo_svg_version_t version, + cairo_svg_document_t **document_out); + +static cairo_status_t +_cairo_svg_document_destroy (cairo_svg_document_t *document); + +static cairo_status_t +_cairo_svg_document_finish (cairo_svg_document_t *document); + +static cairo_svg_document_t * +_cairo_svg_document_reference (cairo_svg_document_t *document); + +static unsigned int +_cairo_svg_document_allocate_mask_id (cairo_svg_document_t *document); + +static cairo_surface_t * +_cairo_svg_surface_create_for_document (cairo_svg_document_t *document, + cairo_content_t content, + double width, + double height); +static cairo_surface_t * +_cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t *stream, + double width, + double height, + cairo_svg_version_t version); + +static const cairo_surface_backend_t cairo_svg_surface_backend; +static const cairo_paginated_surface_backend_t cairo_svg_surface_paginated_backend; + +/** + * cairo_svg_surface_create_for_stream: + * @write_func: a #cairo_write_func_t to accept the output data, may be %NULL + * to indicate a no-op @write_func. With a no-op @write_func, + * the surface may be queried or used as a source without + * generating any temporary files. + * @closure: the closure argument for @write_func + * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) + * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) + * + * Creates a SVG surface of the specified size in points to be written + * incrementally to the stream represented by @write_func and @closure. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, + void *closure, + double width, + double height) +{ + cairo_output_stream_t *stream; + + stream = _cairo_output_stream_create (write_func, NULL, closure); + if (_cairo_output_stream_get_status (stream)) + return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); + + return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1); +} + +/** + * cairo_svg_surface_create: + * @filename: a filename for the SVG output (must be writable), %NULL may be + * used to specify no output. This will generate a SVG surface that + * may be queried and used as a source, without generating a + * temporary file. + * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) + * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) + * + * Creates a SVG surface of the specified size in points to be written + * to @filename. + * + * The SVG surface backend recognizes the following MIME types for the + * data attached to a surface (see cairo_surface_set_mime_data()) when + * it is used as a source pattern for drawing on this surface: + * %CAIRO_MIME_TYPE_JPEG, %CAIRO_MIME_TYPE_PNG, + * %CAIRO_MIME_TYPE_URI. If any of them is specified, the SVG backend + * emits a href with the content of MIME data instead of a surface + * snapshot (PNG, Base64-encoded) in the corresponding image tag. + * + * The unofficial MIME type %CAIRO_MIME_TYPE_URI is examined + * first. If present, the URI is emitted as is: assuring the + * correctness of URI is left to the client code. + * + * If %CAIRO_MIME_TYPE_URI is not present, but %CAIRO_MIME_TYPE_JPEG + * or %CAIRO_MIME_TYPE_PNG is specified, the corresponding data is + * Base64-encoded and emitted. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_svg_surface_create (const char *filename, + double width, + double height) +{ + cairo_output_stream_t *stream; + + stream = _cairo_output_stream_create_for_filename (filename); + if (_cairo_output_stream_get_status (stream)) + return _cairo_surface_create_in_error (_cairo_output_stream_destroy (stream)); + + return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1); +} + +static cairo_bool_t +_cairo_surface_is_svg (cairo_surface_t *surface) +{ + return surface->backend == &cairo_svg_surface_backend; +} + +/* If the abstract_surface is a paginated surface, and that paginated + * surface's target is a svg_surface, then set svg_surface to that + * target. Otherwise return FALSE. + */ +static cairo_bool_t +_extract_svg_surface (cairo_surface_t *surface, + cairo_svg_surface_t **svg_surface) +{ + cairo_surface_t *target; + cairo_status_t status_ignored; + + if (surface->status) + return FALSE; + if (surface->finished) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (! _cairo_surface_is_paginated (surface)) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return FALSE; + } + + target = _cairo_paginated_surface_get_target (surface); + if (target->status) { + status_ignored = _cairo_surface_set_error (surface, + target->status); + return FALSE; + } + if (target->finished) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return FALSE; + } + + if (! _cairo_surface_is_svg (target)) { + status_ignored = _cairo_surface_set_error (surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return FALSE; + } + + *svg_surface = (cairo_svg_surface_t *) target; + return TRUE; +} + +/** + * cairo_svg_surface_restrict_to_version: + * @surface: a SVG #cairo_surface_t + * @version: SVG version + * + * Restricts the generated SVG file to @version. See cairo_svg_get_versions() + * for a list of available version values that can be used here. + * + * This function should only be called before any drawing operations + * have been performed on the given surface. The simplest way to do + * this is to call this function immediately after creating the + * surface. + * + * Since: 1.2 + **/ +void +cairo_svg_surface_restrict_to_version (cairo_surface_t *abstract_surface, + cairo_svg_version_t version) +{ + cairo_svg_surface_t *surface = NULL; /* hide compiler warning */ + + if (! _extract_svg_surface (abstract_surface, &surface)) + return; + + if (version < CAIRO_SVG_VERSION_LAST) + surface->document->svg_version = version; +} + +/** + * cairo_svg_get_versions: + * @versions: supported version list + * @num_versions: list length + * + * Used to retrieve the list of supported versions. See + * cairo_svg_surface_restrict_to_version(). + * + * Since: 1.2 + **/ +void +cairo_svg_get_versions (cairo_svg_version_t const **versions, + int *num_versions) +{ + if (versions != NULL) + *versions = _cairo_svg_versions; + + if (num_versions != NULL) + *num_versions = CAIRO_SVG_VERSION_LAST; +} + +/** + * cairo_svg_version_to_string: + * @version: a version id + * + * Get the string representation of the given @version id. This function + * will return %NULL if @version isn't valid. See cairo_svg_get_versions() + * for a way to get the list of valid version ids. + * + * Return value: the string associated to given version. + * + * Since: 1.2 + **/ +const char * +cairo_svg_version_to_string (cairo_svg_version_t version) +{ + if (version >= CAIRO_SVG_VERSION_LAST) + return NULL; + + return _cairo_svg_version_strings[version]; +} + +static cairo_bool_t +_cliprect_covers_surface (cairo_svg_surface_t *surface, + cairo_path_fixed_t *path) +{ + cairo_box_t box; + + if (_cairo_path_fixed_is_box (path, &box)) { + if (box.p1.x <= 0 && + box.p1.y <= 0 && + _cairo_fixed_to_double (box.p2.x) >= surface->width && + _cairo_fixed_to_double (box.p2.y) >= surface->height) + { + return TRUE; + } + } + + return FALSE; +} + +static cairo_status_t +_cairo_svg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_svg_surface_t *surface = cairo_container_of (clipper, + cairo_svg_surface_t, + clipper); + cairo_svg_document_t *document = surface->document; + unsigned int i; + + if (path == NULL) { + for (i = 0; i < surface->clip_level; i++) + _cairo_output_stream_printf (surface->xml_node, "\n"); + + surface->clip_level = 0; + return CAIRO_STATUS_SUCCESS; + } + + /* skip trivial whole-page clips */ + if (_cliprect_covers_surface (surface, path)) + return CAIRO_STATUS_SUCCESS; + + _cairo_output_stream_printf (document->xml_node_defs, + "\n" + " clip_id); + _cairo_svg_surface_emit_path (document->xml_node_defs, path, NULL); + + _cairo_output_stream_printf (document->xml_node_defs, + "/>\n" + "\n"); + + _cairo_output_stream_printf (surface->xml_node, + "\n", + document->clip_id, + fill_rule == CAIRO_FILL_RULE_EVEN_ODD ? + "evenodd" : "nonzero"); + + document->clip_id++; + surface->clip_level++; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_svg_surface_create_for_document (cairo_svg_document_t *document, + cairo_content_t content, + double width, + double height) +{ + cairo_svg_surface_t *surface; + cairo_surface_t *paginated; + cairo_status_t status, status_ignored; + + surface = malloc (sizeof (cairo_svg_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &cairo_svg_surface_backend, + NULL, /* device */ + content); + + surface->width = width; + surface->height = height; + + surface->document = _cairo_svg_document_reference (document); + + surface->clip_level = 0; + _cairo_surface_clipper_init (&surface->clipper, + _cairo_svg_surface_clipper_intersect_clip_path); + + surface->base_clip = document->clip_id++; + surface->is_base_clip_emitted = FALSE; + + surface->xml_node = _cairo_memory_stream_create (); + status = _cairo_output_stream_get_status (surface->xml_node); + if (unlikely (status)) + goto CLEANUP; + + _cairo_array_init (&surface->page_set, sizeof (cairo_svg_page_t)); + + if (content == CAIRO_CONTENT_COLOR) { + _cairo_output_stream_printf (surface->xml_node, + "\n", + width, height); + status = _cairo_output_stream_get_status (surface->xml_node); + if (unlikely (status)) + goto CLEANUP; + } + + surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE; + surface->force_fallbacks = FALSE; + surface->content = content; + + paginated = _cairo_paginated_surface_create (&surface->base, + surface->content, + &cairo_svg_surface_paginated_backend); + status = paginated->status; + if (status == CAIRO_STATUS_SUCCESS) { + /* paginated keeps the only reference to surface now, drop ours */ + cairo_surface_destroy (&surface->base); + return paginated; + } + + /* ignore status as we are on the error path */ +CLEANUP: + status_ignored = _cairo_output_stream_destroy (surface->xml_node); + status_ignored = _cairo_svg_document_destroy (document); + + free (surface); + + return _cairo_surface_create_in_error (status); +} + +static cairo_surface_t * +_cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t *stream, + double width, + double height, + cairo_svg_version_t version) +{ + cairo_svg_document_t *document = NULL; /* silence compiler */ + cairo_surface_t *surface; + cairo_status_t status; + + status = _cairo_svg_document_create (stream, + width, height, version, + &document); + if (unlikely (status)) { + surface = _cairo_surface_create_in_error (status); + /* consume the output stream on behalf of caller */ + status = _cairo_output_stream_destroy (stream); + return surface; + } + + surface = _cairo_svg_surface_create_for_document (document, CAIRO_CONTENT_COLOR_ALPHA, + width, height); + if (surface->status) { + status = _cairo_svg_document_destroy (document); + return surface; + } + + document->owner = surface; + status = _cairo_svg_document_destroy (document); + /* the ref count should be 2 at this point */ + assert (status == CAIRO_STATUS_SUCCESS); + + return surface; +} + +static cairo_svg_page_t * +_cairo_svg_surface_store_page (cairo_svg_surface_t *surface) +{ + cairo_svg_page_t page; + cairo_output_stream_t *stream; + cairo_int_status_t status; + unsigned int i; + + stream = _cairo_memory_stream_create (); + if (_cairo_output_stream_get_status (stream)) { + status = _cairo_output_stream_destroy (stream); + return NULL; + } + + page.surface_id = surface->base.unique_id; + page.clip_level = surface->clip_level; + page.xml_node = surface->xml_node; + + if (_cairo_array_append (&surface->page_set, &page)) { + status = _cairo_output_stream_destroy (stream); + return NULL; + } + + surface->xml_node = stream; + surface->clip_level = 0; + for (i = 0; i < page.clip_level; i++) + _cairo_output_stream_printf (page.xml_node, "\n"); + + _cairo_surface_clipper_reset (&surface->clipper); + + return _cairo_array_index (&surface->page_set, + surface->page_set.num_elements - 1); +} + +static cairo_int_status_t +_cairo_svg_surface_copy_page (void *abstract_surface) +{ + cairo_svg_surface_t *surface = abstract_surface; + cairo_svg_page_t *page; + + page = _cairo_svg_surface_store_page (surface); + if (unlikely (page == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_memory_stream_copy (page->xml_node, surface->xml_node); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_show_page (void *abstract_surface) +{ + cairo_svg_surface_t *surface = abstract_surface; + + if (unlikely (_cairo_svg_surface_store_page (surface) == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_svg_surface_emit_transform (cairo_output_stream_t *output, + char const *attribute_str, + const cairo_matrix_t *object_matrix, + const cairo_matrix_t *parent_matrix) +{ + cairo_matrix_t matrix = *object_matrix; + + if (parent_matrix != NULL) + cairo_matrix_multiply (&matrix, &matrix, parent_matrix); + + if (!_cairo_matrix_is_identity (&matrix)) + _cairo_output_stream_printf (output, + "%s=\"matrix(%f,%f,%f,%f,%f,%f)\"", + attribute_str, + matrix.xx, matrix.yx, + matrix.xy, matrix.yy, + matrix.x0, matrix.y0); +} + +typedef struct { + cairo_output_stream_t *output; + const cairo_matrix_t *ctm_inverse; +} svg_path_info_t; + +static cairo_status_t +_cairo_svg_path_move_to (void *closure, + const cairo_point_t *point) +{ + svg_path_info_t *info = closure; + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (info->ctm_inverse) + cairo_matrix_transform_point (info->ctm_inverse, &x, &y); + + _cairo_output_stream_printf (info->output, "M %f %f ", x, y); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_path_line_to (void *closure, + const cairo_point_t *point) +{ + svg_path_info_t *info = closure; + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (info->ctm_inverse) + cairo_matrix_transform_point (info->ctm_inverse, &x, &y); + + _cairo_output_stream_printf (info->output, "L %f %f ", x, y); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_path_curve_to (void *closure, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d) +{ + svg_path_info_t *info = closure; + double bx = _cairo_fixed_to_double (b->x); + double by = _cairo_fixed_to_double (b->y); + double cx = _cairo_fixed_to_double (c->x); + double cy = _cairo_fixed_to_double (c->y); + double dx = _cairo_fixed_to_double (d->x); + double dy = _cairo_fixed_to_double (d->y); + + if (info->ctm_inverse) { + cairo_matrix_transform_point (info->ctm_inverse, &bx, &by); + cairo_matrix_transform_point (info->ctm_inverse, &cx, &cy); + cairo_matrix_transform_point (info->ctm_inverse, &dx, &dy); + } + + _cairo_output_stream_printf (info->output, + "C %f %f %f %f %f %f ", + bx, by, cx, cy, dx, dy); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_path_close_path (void *closure) +{ + svg_path_info_t *info = closure; + + _cairo_output_stream_printf (info->output, "Z "); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_svg_surface_emit_path (cairo_output_stream_t *output, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm_inverse) +{ + cairo_status_t status; + svg_path_info_t info; + + _cairo_output_stream_printf (output, "d=\""); + + info.output = output; + info.ctm_inverse = ctm_inverse; + status = _cairo_path_fixed_interpret (path, + _cairo_svg_path_move_to, + _cairo_svg_path_line_to, + _cairo_svg_path_curve_to, + _cairo_svg_path_close_path, + &info); + assert (status == CAIRO_STATUS_SUCCESS); + + _cairo_output_stream_printf (output, "\""); +} + +static cairo_int_status_t +_cairo_svg_document_emit_outline_glyph_data (cairo_svg_document_t *document, + cairo_scaled_font_t *scaled_font, + unsigned long glyph_index) +{ + cairo_scaled_glyph_t *scaled_glyph; + cairo_int_status_t status; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS| + CAIRO_SCALED_GLYPH_INFO_PATH, + &scaled_glyph); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (document->xml_node_glyphs, + "xml_node_glyphs, + scaled_glyph->path, NULL); + + _cairo_output_stream_printf (document->xml_node_glyphs, + "/>\n"); + + return status; +} + +static cairo_int_status_t +_cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t *document, + cairo_scaled_font_t *scaled_font, + unsigned long glyph_index) +{ + cairo_scaled_glyph_t *scaled_glyph; + cairo_image_surface_t *image; + cairo_status_t status; + uint8_t *row, *byte; + int rows, cols; + int x, y, bit; + + status = _cairo_scaled_glyph_lookup (scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS | + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + if (unlikely (status)) + return status; + + image = _cairo_image_surface_coerce_to_format (scaled_glyph->surface, + CAIRO_FORMAT_A1); + status = image->base.status; + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (document->xml_node_glyphs, "xml_node_glyphs, " transform", + &image->base.device_transform_inverse, NULL); + _cairo_output_stream_printf (document->xml_node_glyphs, ">\n"); + + for (y = 0, row = image->data, rows = image->height; rows; row += image->stride, rows--, y++) { + for (x = 0, byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) { + uint8_t output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte); + for (bit = 7; bit >= 0 && x < image->width; bit--, x++) { + if (output_byte & (1 << bit)) { + _cairo_output_stream_printf (document->xml_node_glyphs, + "\n", + x, y); + } + } + } + } + _cairo_output_stream_printf (document->xml_node_glyphs, "\n"); + + cairo_surface_destroy (&image->base); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_document_emit_glyph (cairo_svg_document_t *document, + cairo_scaled_font_t *scaled_font, + unsigned long scaled_font_glyph_index, + unsigned int font_id, + unsigned int subset_glyph_index) +{ + cairo_int_status_t status; + + _cairo_output_stream_printf (document->xml_node_glyphs, + "\n", + font_id, + subset_glyph_index); + + status = _cairo_svg_document_emit_outline_glyph_data (document, + scaled_font, + scaled_font_glyph_index); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + status = _cairo_svg_document_emit_bitmap_glyph_data (document, + scaled_font, + scaled_font_glyph_index); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (document->xml_node_glyphs, "\n"); + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_document_emit_font_subset (cairo_scaled_font_subset_t *font_subset, + void *closure) +{ + cairo_svg_document_t *document = closure; + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + unsigned int i; + + _cairo_scaled_font_freeze_cache (font_subset->scaled_font); + for (i = 0; i < font_subset->num_glyphs; i++) { + status = _cairo_svg_document_emit_glyph (document, + font_subset->scaled_font, + font_subset->glyphs[i], + font_subset->font_id, i); + if (unlikely (status)) + break; + } + _cairo_scaled_font_thaw_cache (font_subset->scaled_font); + + return status; +} + +static cairo_status_t +_cairo_svg_document_emit_font_subsets (cairo_svg_document_t *document) +{ + cairo_status_t status; + + status = _cairo_scaled_font_subsets_foreach_scaled (document->font_subsets, + _cairo_svg_document_emit_font_subset, + document); + if (unlikely (status)) + goto FAIL; + + status = _cairo_scaled_font_subsets_foreach_user (document->font_subsets, + _cairo_svg_document_emit_font_subset, + document); + + FAIL: + _cairo_scaled_font_subsets_destroy (document->font_subsets); + document->font_subsets = NULL; + + return status; +} + +static char const * +_cairo_svg_surface_operators[] = { + "clear", + + "src", "src-over", "src-in", + "src-out", "src-atop", + + "dst", "dst-over", "dst-in", + "dst-out", "dst-atop", + + "xor", "plus", + "color-dodge", /* FIXME: saturate ? */ + + "multiply", "screen", "overlay", + "darken", "lighten", + "color-dodge", "color-burn", + "hard-light", "soft-light", + "difference", "exclusion" +}; + +static cairo_bool_t +_cairo_svg_surface_analyze_operator (cairo_svg_surface_t *surface, + cairo_operator_t op) +{ + /* guard against newly added operators */ + if (op >= ARRAY_LENGTH (_cairo_svg_surface_operators)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* allow operators being NULL if they are unsupported */ + if (_cairo_svg_surface_operators[op] == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_analyze_operation (cairo_svg_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern) +{ + cairo_svg_document_t *document = surface->document; + + if (surface->force_fallbacks && + surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (pattern->type == CAIRO_PATTERN_TYPE_MESH) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* SVG doesn't support extend reflect for image pattern */ + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE && + pattern->extend == CAIRO_EXTEND_REFLECT) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (document->svg_version >= CAIRO_SVG_VERSION_1_2) + return _cairo_svg_surface_analyze_operator (surface, op); + + if (op == CAIRO_OPERATOR_OVER) + return CAIRO_STATUS_SUCCESS; + + /* The SOURCE operator is only supported if there is nothing + * painted underneath. */ + if (op == CAIRO_OPERATOR_SOURCE) + return CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY; + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_int_status_t +_cairo_svg_surface_operation_supported (cairo_svg_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *pattern) +{ + return _cairo_svg_surface_analyze_operation (surface, op, pattern) != CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_status_t +_cairo_svg_surface_finish (void *abstract_surface) +{ + cairo_status_t status, status2; + cairo_svg_surface_t *surface = abstract_surface; + cairo_svg_document_t *document = surface->document; + cairo_svg_page_t *page; + unsigned int i; + + if (_cairo_paginated_surface_get_target (document->owner) == &surface->base) + status = _cairo_svg_document_finish (document); + else + status = CAIRO_STATUS_SUCCESS; + + if (surface->xml_node != NULL) { + status2 = _cairo_output_stream_destroy (surface->xml_node); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + } + + for (i = 0; i < surface->page_set.num_elements; i++) { + page = _cairo_array_index (&surface->page_set, i); + status2 = _cairo_output_stream_destroy (page->xml_node); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + } + _cairo_array_fini (&surface->page_set); + + _cairo_surface_clipper_reset (&surface->clipper); + + status2 = _cairo_svg_document_destroy (document); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + return status; +} + + +static void +_cairo_svg_surface_emit_alpha_filter (cairo_svg_document_t *document) +{ + if (document->alpha_filter) + return; + + _cairo_output_stream_printf (document->xml_node_defs, + "\n" + " \n" + "\n"); + + document->alpha_filter = TRUE; +} + +typedef struct { + cairo_output_stream_t *output; + unsigned int in_mem; + unsigned int trailing; + unsigned char src[3]; +} base64_write_closure_t; + +static char const base64_table[64] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +static cairo_status_t +base64_write_func (void *closure, + const unsigned char *data, + unsigned int length) +{ + base64_write_closure_t *info = (base64_write_closure_t *) closure; + unsigned int i; + unsigned char *src; + + src = info->src; + + if (info->in_mem + length < 3) { + for (i = 0; i < length; i++) { + src[i + info->in_mem] = *data++; + } + info->in_mem += length; + return CAIRO_STATUS_SUCCESS; + } + + do { + unsigned char dst[4]; + + for (i = info->in_mem; i < 3; i++) { + src[i] = *data++; + length--; + } + info->in_mem = 0; + + dst[0] = base64_table[src[0] >> 2]; + dst[1] = base64_table[(src[0] & 0x03) << 4 | src[1] >> 4]; + dst[2] = base64_table[(src[1] & 0x0f) << 2 | src[2] >> 6]; + dst[3] = base64_table[src[2] & 0xfc >> 2]; + /* Special case for the last missing bits */ + switch (info->trailing) { + case 2: + dst[2] = '='; + case 1: + dst[3] = '='; + default: + break; + } + _cairo_output_stream_write (info->output, dst, 4); + } while (length >= 3); + + for (i = 0; i < length; i++) { + src[i] = *data++; + } + info->in_mem = length; + + return _cairo_output_stream_get_status (info->output); +} + +static cairo_int_status_t +_cairo_surface_base64_encode_jpeg (cairo_surface_t *surface, + cairo_output_stream_t *output) +{ + const unsigned char *mime_data; + unsigned long mime_data_length; + cairo_image_info_t image_info; + base64_write_closure_t info; + cairo_status_t status; + + cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_JPEG, + &mime_data, &mime_data_length); + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_image_info_get_jpeg_info (&image_info, mime_data, mime_data_length); + if (unlikely (status)) + return status; + + if (image_info.num_components == 4) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_output_stream_printf (output, "data:image/jpeg;base64,"); + + info.output = output; + info.in_mem = 0; + info.trailing = 0; + + status = base64_write_func (&info, mime_data, mime_data_length); + if (unlikely (status)) + return status; + + if (info.in_mem > 0) { + memset (info.src + info.in_mem, 0, 3 - info.in_mem); + info.trailing = 3 - info.in_mem; + info.in_mem = 3; + status = base64_write_func (&info, NULL, 0); + } + + return status; +} + +static cairo_int_status_t +_cairo_surface_base64_encode_png (cairo_surface_t *surface, + cairo_output_stream_t *output) +{ + const unsigned char *mime_data; + unsigned long mime_data_length; + base64_write_closure_t info; + cairo_status_t status; + + cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_PNG, + &mime_data, &mime_data_length); + if (unlikely (surface->status)) + return surface->status; + if (mime_data == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_output_stream_printf (output, "data:image/png;base64,"); + + info.output = output; + info.in_mem = 0; + info.trailing = 0; + + status = base64_write_func (&info, mime_data, mime_data_length); + if (unlikely (status)) + return status; + + if (info.in_mem > 0) { + memset (info.src + info.in_mem, 0, 3 - info.in_mem); + info.trailing = 3 - info.in_mem; + info.in_mem = 3; + status = base64_write_func (&info, NULL, 0); + } + + return status; +} + +static cairo_int_status_t +_cairo_surface_base64_encode (cairo_surface_t *surface, + cairo_output_stream_t *output) +{ + cairo_int_status_t status; + base64_write_closure_t info; + + status = _cairo_surface_base64_encode_jpeg (surface, output); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + status = _cairo_surface_base64_encode_png (surface, output); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + info.output = output; + info.in_mem = 0; + info.trailing = 0; + + _cairo_output_stream_printf (info.output, "data:image/png;base64,"); + + status = cairo_surface_write_to_png_stream (surface, base64_write_func, + (void *) &info); + + if (unlikely (status)) + return status; + + if (info.in_mem > 0) { + memset (info.src + info.in_mem, 0, 3 - info.in_mem); + info.trailing = 3 - info.in_mem; + info.in_mem = 3; + status = base64_write_func (&info, NULL, 0); + } + + return status; +} + +static void +_cairo_svg_surface_emit_operator (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op) +{ + if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2 && + op != CAIRO_OPERATOR_OVER) { + _cairo_output_stream_printf (output, " comp-op=\"%s\"", _cairo_svg_surface_operators[op]); + if (!_cairo_operator_bounded_by_source (op)) + _cairo_output_stream_printf (output, " clip-to-self=\"true\""); + } +} + +static void +_cairo_svg_surface_emit_operator_for_style (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op) +{ + if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2 && + op != CAIRO_OPERATOR_OVER) { + _cairo_output_stream_printf (output, "comp-op:%s;", _cairo_svg_surface_operators[op]); + if (!_cairo_operator_bounded_by_source (op)) + _cairo_output_stream_printf (output, "clip-to-self:true;"); + } +} + +/** + * _cairo_svg_surface_emit_attr_value: + * + * Write the value to output the stream as a sequence of characters, + * while escaping those which have special meaning in the XML + * attribute's value context: & and ". + **/ +static void +_cairo_svg_surface_emit_attr_value (cairo_output_stream_t *stream, + const unsigned char *value, + unsigned int length) +{ + const unsigned char *p; + const unsigned char *q; + unsigned int i; + + /* we'll accumulate non-special chars in [q, p) range */ + p = value; + q = p; + for (i = 0; i < length; i++, p++) { + if (*p == '&' || *p == '"') { + /* flush what's left before special char */ + if (p != q) { + _cairo_output_stream_write (stream, q, p - q); + q = p + 1; + } + + if (*p == '&') + _cairo_output_stream_printf (stream, "&"); + else // p == '"' + _cairo_output_stream_printf (stream, """); + } + } + + /* flush the trailing chars if any */ + if (p != q) + _cairo_output_stream_write (stream, q, p - q); +} + +static cairo_status_t +_cairo_svg_surface_emit_surface (cairo_svg_document_t *document, + cairo_surface_t *surface) +{ + cairo_rectangle_int_t extents; + cairo_bool_t is_bounded; + cairo_status_t status; + const unsigned char *uri; + unsigned long uri_len; + + if (_cairo_user_data_array_get_data (&surface->user_data, + (cairo_user_data_key_t *) document)) + { + return CAIRO_STATUS_SUCCESS; + } + + is_bounded = _cairo_surface_get_extents (surface, &extents); + assert (is_bounded); + + _cairo_output_stream_printf (document->xml_node_defs, + "unique_id, + extents.width, extents.height); + + _cairo_output_stream_printf (document->xml_node_defs, " xlink:href=\""); + + cairo_surface_get_mime_data (surface, CAIRO_MIME_TYPE_URI, + &uri, &uri_len); + if (uri != NULL) { + _cairo_svg_surface_emit_attr_value (document->xml_node_defs, + uri, uri_len); + } else { + status = _cairo_surface_base64_encode (surface, + document->xml_node_defs); + if (unlikely (status)) + return status; + } + + _cairo_output_stream_printf (document->xml_node_defs, "\"/>\n"); + + /* and tag it */ + return _cairo_user_data_array_set_data (&surface->user_data, + (cairo_user_data_key_t *) document, + document, NULL); +} + +static cairo_status_t +_cairo_svg_surface_emit_composite_surface_pattern (cairo_output_stream_t *output, + cairo_svg_surface_t *svg_surface, + cairo_operator_t op, + cairo_surface_pattern_t *pattern, + int pattern_id, + const cairo_matrix_t *parent_matrix, + const char *extra_attributes) +{ + cairo_status_t status; + cairo_matrix_t p2u; + + p2u = pattern->base.matrix; + status = cairo_matrix_invert (&p2u); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + status = _cairo_svg_surface_emit_surface (svg_surface->document, + pattern->surface); + if (unlikely (status)) + return status; + + if (pattern_id != invalid_pattern_id) { + cairo_rectangle_int_t extents; + cairo_bool_t is_bounded; + + is_bounded = _cairo_surface_get_extents (pattern->surface, &extents); + assert (is_bounded); + + _cairo_output_stream_printf (output, + "\n "); + } + + _cairo_output_stream_printf (output, + "surface->unique_id); + if (extra_attributes) + _cairo_output_stream_printf (output, " %s", extra_attributes); + + if (pattern_id == invalid_pattern_id) { + _cairo_svg_surface_emit_operator (output, svg_surface, op); + _cairo_svg_surface_emit_transform (output, + " transform", + &p2u, parent_matrix); + } + _cairo_output_stream_printf (output, "/>\n"); + + + if (pattern_id != invalid_pattern_id) + _cairo_output_stream_printf (output, "\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_surface_emit_recording_surface (cairo_svg_document_t *document, + cairo_recording_surface_t *source) +{ + cairo_status_t status; + cairo_surface_t *paginated_surface; + cairo_svg_surface_t *svg_surface; + cairo_array_t *page_set; + + cairo_output_stream_t *contents; + + if (_cairo_user_data_array_get_data (&source->base.user_data, + (cairo_user_data_key_t *) document)) + { + return CAIRO_STATUS_SUCCESS; + } + + paginated_surface = _cairo_svg_surface_create_for_document (document, + source->base.content, + source->extents_pixels.width, + source->extents_pixels.height); + if (unlikely (paginated_surface->status)) + return paginated_surface->status; + + svg_surface = (cairo_svg_surface_t *) + _cairo_paginated_surface_get_target (paginated_surface); + cairo_surface_set_fallback_resolution (paginated_surface, + document->owner->x_fallback_resolution, + document->owner->y_fallback_resolution); + cairo_surface_set_device_offset (&svg_surface->base, + -source->extents_pixels.x, + -source->extents_pixels.y); + + status = _cairo_recording_surface_replay (&source->base, paginated_surface); + if (unlikely (status)) { + cairo_surface_destroy (paginated_surface); + return status; + } + + cairo_surface_show_page (paginated_surface); + status = cairo_surface_status (paginated_surface); + if (unlikely (status)) { + cairo_surface_destroy (paginated_surface); + return status; + } + + if (! svg_surface->is_base_clip_emitted) { + svg_surface->is_base_clip_emitted = TRUE; + _cairo_output_stream_printf (document->xml_node_defs, + "\n" + " \n" + "\n", + svg_surface->base_clip, + svg_surface->width, + svg_surface->height); + } + + if (source->base.content == CAIRO_CONTENT_ALPHA) { + _cairo_svg_surface_emit_alpha_filter (document); + _cairo_output_stream_printf (document->xml_node_defs, + "\n", + source->base.unique_id, + svg_surface->base_clip); + } else { + _cairo_output_stream_printf (document->xml_node_defs, + "\n", + source->base.unique_id, + svg_surface->base_clip); + } + + contents = svg_surface->xml_node; + page_set = &svg_surface->page_set; + + if (_cairo_memory_stream_length (contents) > 0) { + if (unlikely (_cairo_svg_surface_store_page (svg_surface) == NULL)) { + cairo_surface_destroy (paginated_surface); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + if (page_set->num_elements > 0) { + cairo_svg_page_t *page; + + page = _cairo_array_index (page_set, page_set->num_elements - 1); + _cairo_memory_stream_copy (page->xml_node, document->xml_node_defs); + } + + _cairo_output_stream_printf (document->xml_node_defs, "\n"); + + status = cairo_surface_status (paginated_surface); + cairo_surface_destroy (paginated_surface); + + if (unlikely (status)) + return status; + + /* and tag it */ + return _cairo_user_data_array_set_data (&source->base.user_data, + (cairo_user_data_key_t *) document, + document, NULL); +} + +static cairo_recording_surface_t * +to_recording_surface (const cairo_surface_pattern_t *pattern) +{ + cairo_surface_t *surface = pattern->surface; + if (_cairo_surface_is_paginated (surface)) + surface = _cairo_paginated_surface_get_recording (surface); + if (_cairo_surface_is_snapshot (surface)) + surface = _cairo_surface_snapshot_get_target (surface); + return (cairo_recording_surface_t *) surface; +} + +static cairo_status_t +_cairo_svg_surface_emit_composite_recording_pattern (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op, + cairo_surface_pattern_t *pattern, + int pattern_id, + const cairo_matrix_t *parent_matrix, + const char *extra_attributes) +{ + cairo_svg_document_t *document = surface->document; + cairo_recording_surface_t *recording_surface; + cairo_matrix_t p2u; + cairo_status_t status; + + p2u = pattern->base.matrix; + status = cairo_matrix_invert (&p2u); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + recording_surface = to_recording_surface (pattern); + status = _cairo_svg_surface_emit_recording_surface (document, recording_surface); + if (unlikely (status)) + return status; + + if (pattern_id != invalid_pattern_id) { + _cairo_output_stream_printf (output, + "extents.width, + recording_surface->extents.height); + _cairo_svg_surface_emit_transform (output, " patternTransform", &p2u, parent_matrix); + _cairo_output_stream_printf (output, ">\n"); + } + + _cairo_output_stream_printf (output, + "base.unique_id); + + if (pattern_id == invalid_pattern_id) { + _cairo_svg_surface_emit_operator (output, surface, op); + _cairo_svg_surface_emit_transform (output, " transform", &p2u, parent_matrix); + } + + if (extra_attributes) + _cairo_output_stream_printf (output, " %s", extra_attributes); + + _cairo_output_stream_printf (output, "/>\n"); + + if (pattern_id != invalid_pattern_id) + _cairo_output_stream_printf (output, "\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_surface_emit_composite_pattern (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op, + cairo_surface_pattern_t *pattern, + int pattern_id, + const cairo_matrix_t *parent_matrix, + const char *extra_attributes) +{ + + if (pattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) { + return _cairo_svg_surface_emit_composite_recording_pattern (output, surface, + op, pattern, + pattern_id, + parent_matrix, + extra_attributes); + } + + return _cairo_svg_surface_emit_composite_surface_pattern (output, surface, + op, pattern, + pattern_id, + parent_matrix, + extra_attributes); +} + +static cairo_status_t +_cairo_svg_surface_emit_solid_pattern (cairo_svg_surface_t *surface, + cairo_solid_pattern_t *pattern, + cairo_output_stream_t *style, + cairo_bool_t is_stroke) +{ + _cairo_output_stream_printf (style, is_stroke ? + "stroke:rgb(%f%%,%f%%,%f%%);stroke-opacity:%f;": + "fill:rgb(%f%%,%f%%,%f%%);fill-opacity:%f;", + pattern->color.red * 100.0, + pattern->color.green * 100.0, + pattern->color.blue * 100.0, + pattern->color.alpha); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_surface_emit_surface_pattern (cairo_svg_surface_t *surface, + cairo_surface_pattern_t *pattern, + cairo_output_stream_t *style, + cairo_bool_t is_stroke, + const cairo_matrix_t *parent_matrix) +{ + cairo_svg_document_t *document = surface->document; + cairo_status_t status; + int pattern_id; + + pattern_id = document->pattern_id++; + status = _cairo_svg_surface_emit_composite_pattern (document->xml_node_defs, + surface, CAIRO_OPERATOR_SOURCE, pattern, + pattern_id, parent_matrix, NULL); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (style, + "%s:url(#pattern%d);", + is_stroke ? "stroke" : "fill", + pattern_id); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_surface_emit_pattern_stops (cairo_output_stream_t *output, + cairo_gradient_pattern_t const *pattern, + double start_offset, + cairo_bool_t reverse_stops, + cairo_bool_t emulate_reflect) +{ + cairo_gradient_stop_t *stops; + double offset; + unsigned int n_stops; + unsigned int i; + + if (pattern->n_stops < 1) + return CAIRO_STATUS_SUCCESS; + + if (pattern->n_stops == 1) { + _cairo_output_stream_printf (output, + "\n", + pattern->stops[0].offset, + pattern->stops[0].color.red * 100.0, + pattern->stops[0].color.green * 100.0, + pattern->stops[0].color.blue * 100.0, + pattern->stops[0].color.alpha); + return CAIRO_STATUS_SUCCESS; + } + + if (emulate_reflect || reverse_stops) { + n_stops = emulate_reflect ? pattern->n_stops * 2 - 2: pattern->n_stops; + stops = _cairo_malloc_ab (n_stops, sizeof (cairo_gradient_stop_t)); + if (unlikely (stops == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + for (i = 0; i < pattern->n_stops; i++) { + if (reverse_stops) { + stops[i] = pattern->stops[pattern->n_stops - i - 1]; + stops[i].offset = 1.0 - stops[i].offset; + } else + stops[i] = pattern->stops[i]; + if (emulate_reflect) { + stops[i].offset /= 2; + if (i > 0 && i < (pattern->n_stops - 1)) { + if (reverse_stops) { + stops[i + pattern->n_stops - 1] = pattern->stops[i]; + stops[i + pattern->n_stops - 1].offset = + 0.5 + 0.5 * stops[i + pattern->n_stops - 1].offset; + } else { + stops[i + pattern->n_stops - 1] = pattern->stops[pattern->n_stops - i - 1]; + stops[i + pattern->n_stops - 1].offset = + 1 - 0.5 * stops[i + pattern->n_stops - 1].offset; + } + } + } + } + } else { + n_stops = pattern->n_stops; + stops = pattern->stops; + } + + if (start_offset >= 0.0) + for (i = 0; i < n_stops; i++) { + offset = start_offset + (1 - start_offset ) * stops[i].offset; + _cairo_output_stream_printf (output, + "\n", + offset, + stops[i].color.red * 100.0, + stops[i].color.green * 100.0, + stops[i].color.blue * 100.0, + stops[i].color.alpha); + } + else { + cairo_bool_t found = FALSE; + unsigned int offset_index; + cairo_color_stop_t offset_color_start, offset_color_stop; + + for (i = 0; i < n_stops; i++) { + if (stops[i].offset >= -start_offset) { + if (i > 0) { + if (stops[i].offset != stops[i-1].offset) { + double x0, x1; + cairo_color_stop_t *color0, *color1; + + x0 = stops[i-1].offset; + x1 = stops[i].offset; + color0 = &stops[i-1].color; + color1 = &stops[i].color; + offset_color_start.red = color0->red + (color1->red - color0->red) + * (-start_offset - x0) / (x1 - x0); + offset_color_start.green = color0->green + (color1->green - color0->green) + * (-start_offset - x0) / (x1 - x0); + offset_color_start.blue = color0->blue + (color1->blue - color0->blue) + * (-start_offset - x0) / (x1 - x0); + offset_color_start.alpha = color0->alpha + (color1->alpha - color0->alpha) + * (-start_offset - x0) / (x1 - x0); + offset_color_stop = offset_color_start; + } else { + offset_color_stop = stops[i-1].color; + offset_color_start = stops[i].color; + } + } else + offset_color_stop = offset_color_start = stops[i].color; + offset_index = i; + found = TRUE; + break; + } + } + + if (!found) { + offset_index = n_stops - 1; + offset_color_stop = offset_color_start = stops[offset_index].color; + } + + _cairo_output_stream_printf (output, + "\n", + offset_color_start.red * 100.0, + offset_color_start.green * 100.0, + offset_color_start.blue * 100.0, + offset_color_start.alpha); + for (i = offset_index; i < n_stops; i++) { + _cairo_output_stream_printf (output, + "\n", + stops[i].offset + start_offset, + stops[i].color.red * 100.0, + stops[i].color.green * 100.0, + stops[i].color.blue * 100.0, + stops[i].color.alpha); + } + for (i = 0; i < offset_index; i++) { + _cairo_output_stream_printf (output, + "\n", + 1.0 + stops[i].offset + start_offset, + stops[i].color.red * 100.0, + stops[i].color.green * 100.0, + stops[i].color.blue * 100.0, + stops[i].color.alpha); + } + + _cairo_output_stream_printf (output, + "\n", + offset_color_stop.red * 100.0, + offset_color_stop.green * 100.0, + offset_color_stop.blue * 100.0, + offset_color_stop.alpha); + + } + + if (reverse_stops || emulate_reflect) + free (stops); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_svg_surface_emit_pattern_extend (cairo_output_stream_t *output, + cairo_pattern_t *pattern) +{ + switch (pattern->extend) { + case CAIRO_EXTEND_REPEAT: + _cairo_output_stream_printf (output, "spreadMethod=\"repeat\" "); + break; + case CAIRO_EXTEND_REFLECT: + _cairo_output_stream_printf (output, "spreadMethod=\"reflect\" "); + break; + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_PAD: + break; + } +} + +static cairo_status_t +_cairo_svg_surface_emit_linear_pattern (cairo_svg_surface_t *surface, + cairo_linear_pattern_t *pattern, + cairo_output_stream_t *style, + cairo_bool_t is_stroke, + const cairo_matrix_t *parent_matrix) +{ + cairo_svg_document_t *document = surface->document; + cairo_matrix_t p2u; + cairo_status_t status; + + p2u = pattern->base.base.matrix; + status = cairo_matrix_invert (&p2u); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + _cairo_output_stream_printf (document->xml_node_defs, + "linear_pattern_id, + pattern->pd1.x, pattern->pd1.y, + pattern->pd2.x, pattern->pd2.y); + + _cairo_svg_surface_emit_pattern_extend (document->xml_node_defs, &pattern->base.base), + _cairo_svg_surface_emit_transform (document->xml_node_defs, "gradientTransform", &p2u, parent_matrix); + _cairo_output_stream_printf (document->xml_node_defs, ">\n"); + + status = _cairo_svg_surface_emit_pattern_stops (document->xml_node_defs, + &pattern->base, 0.0, + FALSE, FALSE); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (document->xml_node_defs, + "\n"); + + _cairo_output_stream_printf (style, + "%s:url(#linear%d);", + is_stroke ? "stroke" : "fill", + document->linear_pattern_id); + + document->linear_pattern_id++; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_surface_emit_radial_pattern (cairo_svg_surface_t *surface, + cairo_radial_pattern_t *pattern, + cairo_output_stream_t *style, + cairo_bool_t is_stroke, + const cairo_matrix_t *parent_matrix) +{ + cairo_svg_document_t *document = surface->document; + cairo_matrix_t p2u; + cairo_extend_t extend; + double x0, y0, x1, y1, r0, r1; + double fx, fy; + cairo_bool_t reverse_stops; + cairo_status_t status; + cairo_circle_double_t *c0, *c1; + + extend = pattern->base.base.extend; + + if (pattern->cd1.radius < pattern->cd2.radius) { + c0 = &pattern->cd1; + c1 = &pattern->cd2; + reverse_stops = FALSE; + } else { + c0 = &pattern->cd2; + c1 = &pattern->cd1; + reverse_stops = TRUE; + } + + x0 = c0->center.x; + y0 = c0->center.y; + r0 = c0->radius; + x1 = c1->center.x; + y1 = c1->center.y; + r1 = c1->radius; + + p2u = pattern->base.base.matrix; + status = cairo_matrix_invert (&p2u); + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + if (r0 == r1) { + unsigned int n_stops = pattern->base.n_stops; + + _cairo_output_stream_printf (document->xml_node_defs, + "radial_pattern_id, + x1, y1, + x1, y1, r1); + _cairo_svg_surface_emit_transform (document->xml_node_defs, + "gradientTransform", + &p2u, parent_matrix); + _cairo_output_stream_printf (document->xml_node_defs, ">\n"); + + if (extend == CAIRO_EXTEND_NONE || n_stops < 1) + _cairo_output_stream_printf (document->xml_node_defs, + "\n"); + else { + _cairo_output_stream_printf (document->xml_node_defs, + "\n", + pattern->base.stops[0].color.red * 100.0, + pattern->base.stops[0].color.green * 100.0, + pattern->base.stops[0].color.blue * 100.0, + pattern->base.stops[0].color.alpha); + if (n_stops > 1) + _cairo_output_stream_printf (document->xml_node_defs, + "\n", + pattern->base.stops[n_stops - 1].color.red * 100.0, + pattern->base.stops[n_stops - 1].color.green * 100.0, + pattern->base.stops[n_stops - 1].color.blue * 100.0, + pattern->base.stops[n_stops - 1].color.alpha); + } + + } else { + double offset, r, x, y; + cairo_bool_t emulate_reflect = FALSE; + + fx = (r1 * x0 - r0 * x1) / (r1 - r0); + fy = (r1 * y0 - r0 * y1) / (r1 - r0); + + /* SVG doesn't support the inner circle and use instead a gradient focal. + * That means we need to emulate the cairo behaviour by processing the + * cairo gradient stops. + * The CAIRO_EXTENT_NONE and CAIRO_EXTENT_PAD modes are quite easy to handle, + * it's just a matter of stop position translation and calculation of + * the corresponding SVG radial gradient focal. + * The CAIRO_EXTENT_REFLECT and CAIRO_EXTEND_REPEAT modes require to compute a new + * radial gradient, with an new outer circle, equal to r1 - r0 in the CAIRO_EXTEND_REPEAT + * case, and 2 * (r1 - r0) in the CAIRO_EXTENT_REFLECT case, and a new gradient stop + * list that maps to the original cairo stop list. + */ + if ((extend == CAIRO_EXTEND_REFLECT + || extend == CAIRO_EXTEND_REPEAT) + && r0 > 0.0) { + double r_org = r1; + + if (extend == CAIRO_EXTEND_REFLECT) { + r1 = 2 * r1 - r0; + emulate_reflect = TRUE; + } + + offset = fmod (r1, r1 - r0) / (r1 - r0) - 1.0; + r = r1 - r0; + + /* New position of outer circle. */ + x = r * (x1 - fx) / r_org + fx; + y = r * (y1 - fy) / r_org + fy; + + x1 = x; + y1 = y; + r1 = r; + r0 = 0.0; + } else { + offset = r0 / r1; + } + + _cairo_output_stream_printf (document->xml_node_defs, + "radial_pattern_id, + x1, y1, + fx, fy, r1); + + if (emulate_reflect) + _cairo_output_stream_printf (document->xml_node_defs, "spreadMethod=\"repeat\" "); + else + _cairo_svg_surface_emit_pattern_extend (document->xml_node_defs, &pattern->base.base); + _cairo_svg_surface_emit_transform (document->xml_node_defs, "gradientTransform", &p2u, parent_matrix); + _cairo_output_stream_printf (document->xml_node_defs, ">\n"); + + /* To support cairo's EXTEND_NONE, (for which SVG has no similar + * notion), we add transparent color stops on either end of the + * user-provided stops. */ + if (extend == CAIRO_EXTEND_NONE) { + _cairo_output_stream_printf (document->xml_node_defs, + "\n"); + if (r0 != 0.0) + _cairo_output_stream_printf (document->xml_node_defs, + "\n", + r0 / r1); + } + status = _cairo_svg_surface_emit_pattern_stops (document->xml_node_defs, + &pattern->base, offset, + reverse_stops, + emulate_reflect); + if (unlikely (status)) + return status; + + if (pattern->base.base.extend == CAIRO_EXTEND_NONE) + _cairo_output_stream_printf (document->xml_node_defs, + "\n"); + } + + _cairo_output_stream_printf (document->xml_node_defs, + "\n"); + + _cairo_output_stream_printf (style, + "%s:url(#radial%d);", + is_stroke ? "stroke" : "fill", + document->radial_pattern_id); + + document->radial_pattern_id++; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_svg_surface_emit_pattern (cairo_svg_surface_t *surface, + const cairo_pattern_t *pattern, + cairo_output_stream_t *output, + cairo_bool_t is_stroke, + const cairo_matrix_t *parent_matrix) +{ + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return _cairo_svg_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern, + output, is_stroke); + + case CAIRO_PATTERN_TYPE_SURFACE: + return _cairo_svg_surface_emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern, + output, is_stroke, parent_matrix); + + case CAIRO_PATTERN_TYPE_LINEAR: + return _cairo_svg_surface_emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern, + output, is_stroke, parent_matrix); + + case CAIRO_PATTERN_TYPE_RADIAL: + return _cairo_svg_surface_emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern, + output, is_stroke, parent_matrix); + + case CAIRO_PATTERN_TYPE_MESH: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + ASSERT_NOT_REACHED; + } + return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH); +} + +static cairo_status_t +_cairo_svg_surface_emit_fill_style (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_fill_rule_t fill_rule, + const cairo_matrix_t *parent_matrix) +{ + _cairo_output_stream_printf (output, + "fill-rule:%s;", + fill_rule == CAIRO_FILL_RULE_EVEN_ODD ? + "evenodd" : "nonzero"); + _cairo_svg_surface_emit_operator_for_style (output, surface, op); + return _cairo_svg_surface_emit_pattern (surface, source, output, FALSE, parent_matrix); +} + +static cairo_status_t +_cairo_svg_surface_emit_stroke_style (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *parent_matrix) +{ + cairo_status_t status; + const char *line_cap, *line_join; + unsigned int i; + + switch (stroke_style->line_cap) { + case CAIRO_LINE_CAP_BUTT: + line_cap = "butt"; + break; + case CAIRO_LINE_CAP_ROUND: + line_cap = "round"; + break; + case CAIRO_LINE_CAP_SQUARE: + line_cap = "square"; + break; + default: + ASSERT_NOT_REACHED; + } + + switch (stroke_style->line_join) { + case CAIRO_LINE_JOIN_MITER: + line_join = "miter"; + break; + case CAIRO_LINE_JOIN_ROUND: + line_join = "round"; + break; + case CAIRO_LINE_JOIN_BEVEL: + line_join = "bevel"; + break; + default: + ASSERT_NOT_REACHED; + } + + _cairo_output_stream_printf (output, + "stroke-width:%f;" + "stroke-linecap:%s;" + "stroke-linejoin:%s;", + stroke_style->line_width, + line_cap, + line_join); + + status = _cairo_svg_surface_emit_pattern (surface, source, output, TRUE, parent_matrix); + if (unlikely (status)) + return status; + + _cairo_svg_surface_emit_operator_for_style (output, surface, op); + + if (stroke_style->num_dashes > 0) { + _cairo_output_stream_printf (output, "stroke-dasharray:"); + for (i = 0; i < stroke_style->num_dashes; i++) { + _cairo_output_stream_printf (output, "%f", + stroke_style->dash[i]); + if (i + 1 < stroke_style->num_dashes) + _cairo_output_stream_printf (output, ","); + else + _cairo_output_stream_printf (output, ";"); + } + if (stroke_style->dash_offset != 0.0) { + _cairo_output_stream_printf (output, + "stroke-dashoffset:%f;", + stroke_style->dash_offset); + } + } + + _cairo_output_stream_printf (output, + "stroke-miterlimit:%f;", + stroke_style->miter_limit); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_fill_stroke (void *abstract_surface, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + const cairo_path_fixed_t*path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip) +{ + cairo_svg_surface_t *surface = abstract_surface; + cairo_status_t status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, "xml_node, surface, fill_op, + fill_source, fill_rule, stroke_ctm_inverse); + if (unlikely (status)) + return status; + + status = _cairo_svg_surface_emit_stroke_style (surface->xml_node, surface, stroke_op, + stroke_source, stroke_style, stroke_ctm_inverse); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, "\" "); + + _cairo_svg_surface_emit_path (surface->xml_node, path, stroke_ctm_inverse); + + _cairo_svg_surface_emit_transform (surface->xml_node, " transform", stroke_ctm, NULL); + _cairo_output_stream_printf (surface->xml_node, "/>\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_svg_surface_t *surface = abstract_surface; + cairo_status_t status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return _cairo_svg_surface_analyze_operation (surface, op, source); + + assert (_cairo_svg_surface_operation_supported (surface, op, source)); + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, "xml_node, surface, op, source, fill_rule, NULL); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, "\" "); + + _cairo_svg_surface_emit_path (surface->xml_node, path, NULL); + + _cairo_output_stream_printf (surface->xml_node, "/>\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_svg_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_svg_surface_t *surface = abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + + /* XXX: The conversion to integers here is pretty bogus, (not to + * mention the arbitrary limitation of width to a short(!). We + * may need to come up with a better interface for get_size. + */ + rectangle->width = ceil (surface->width); + rectangle->height = ceil (surface->height); + + return TRUE; +} + +static cairo_status_t +_cairo_svg_surface_emit_paint (cairo_output_stream_t *output, + cairo_svg_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask_source, + const char *extra_attributes) +{ + cairo_status_t status; + + if (source->type == CAIRO_PATTERN_TYPE_SURFACE && + source->extend == CAIRO_EXTEND_NONE) + return _cairo_svg_surface_emit_composite_pattern (output, + surface, + op, + (cairo_surface_pattern_t *) source, + invalid_pattern_id, + mask_source ? &mask_source->matrix :NULL, + extra_attributes); + + _cairo_output_stream_printf (output, + "width, surface->height); + _cairo_svg_surface_emit_operator_for_style (output, surface, op); + status = _cairo_svg_surface_emit_pattern (surface, source, output, FALSE, NULL); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (output, "stroke:none;\""); + + if (extra_attributes) + _cairo_output_stream_printf (output, " %s", extra_attributes); + + _cairo_output_stream_printf (output, "/>\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_svg_surface_t *surface = abstract_surface; + + /* Emulation of clear and source operators, when no clipping region + * is defined. We just delete existing content of surface root node, + * and exit early if operator is clear. + */ + if ((op == CAIRO_OPERATOR_CLEAR || op == CAIRO_OPERATOR_SOURCE) && + clip == NULL) + { + switch (surface->paginated_mode) { + case CAIRO_PAGINATED_MODE_FALLBACK: + ASSERT_NOT_REACHED; + case CAIRO_PAGINATED_MODE_ANALYZE: + return CAIRO_STATUS_SUCCESS; + + case CAIRO_PAGINATED_MODE_RENDER: + status = _cairo_output_stream_destroy (surface->xml_node); + if (unlikely (status)) { + surface->xml_node = NULL; + return status; + } + + surface->xml_node = _cairo_memory_stream_create (); + if (_cairo_output_stream_get_status (surface->xml_node)) { + status = _cairo_output_stream_destroy (surface->xml_node); + surface->xml_node = NULL; + return status; + } + + if (op == CAIRO_OPERATOR_CLEAR) { + if (surface->content == CAIRO_CONTENT_COLOR) { + _cairo_output_stream_printf (surface->xml_node, + "\n", + surface->width, surface->height); + } + return CAIRO_STATUS_SUCCESS; + } + break; + } + } else { + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return _cairo_svg_surface_analyze_operation (surface, op, source); + + assert (_cairo_svg_surface_operation_supported (surface, op, source)); + } + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + return _cairo_svg_surface_emit_paint (surface->xml_node, + surface, op, source, 0, NULL); +} + +static cairo_int_status_t +_cairo_svg_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_status_t status; + cairo_svg_surface_t *surface = abstract_surface; + cairo_svg_document_t *document = surface->document; + cairo_output_stream_t *mask_stream; + char buffer[64]; + cairo_bool_t discard_filter = FALSE; + unsigned int mask_id; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) { + cairo_status_t source_status, mask_status; + + source_status = _cairo_svg_surface_analyze_operation (surface, op, source); + if (_cairo_status_is_error (source_status)) + return source_status; + + if (mask->has_component_alpha) { + mask_status = CAIRO_INT_STATUS_UNSUPPORTED; + } else { + mask_status = _cairo_svg_surface_analyze_operation (surface, op, mask); + if (_cairo_status_is_error (mask_status)) + return mask_status; + } + + return _cairo_analysis_surface_merge_status (source_status, + mask_status); + } + + assert (_cairo_svg_surface_operation_supported (surface, op, source)); + assert (_cairo_svg_surface_operation_supported (surface, CAIRO_OPERATOR_OVER, mask)); + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + if (mask->type == CAIRO_PATTERN_TYPE_SURFACE) { + const cairo_surface_pattern_t *surface_pattern = (const cairo_surface_pattern_t*) mask; + cairo_content_t content = surface_pattern->surface->content; + if (content == CAIRO_CONTENT_ALPHA) + discard_filter = TRUE; + } + + if (!discard_filter) + _cairo_svg_surface_emit_alpha_filter (document); + + /* _cairo_svg_surface_emit_paint() will output a pattern definition to + * document->xml_node_defs so we need to write the mask element to + * a temporary stream and then copy that to xml_node_defs. */ + mask_stream = _cairo_memory_stream_create (); + if (_cairo_output_stream_get_status (mask_stream)) + return _cairo_output_stream_destroy (mask_stream); + + mask_id = _cairo_svg_document_allocate_mask_id (document); + + _cairo_output_stream_printf (mask_stream, + "\n" + "%s", + mask_id, + discard_filter ? "" : " \n"); + status = _cairo_svg_surface_emit_paint (mask_stream, surface, CAIRO_OPERATOR_OVER, mask, source, NULL); + if (unlikely (status)) { + cairo_status_t ignore = _cairo_output_stream_destroy (mask_stream); + return status; + (void) ignore; + } + + _cairo_output_stream_printf (mask_stream, + "%s" + "\n", + discard_filter ? "" : " \n"); + _cairo_memory_stream_copy (mask_stream, document->xml_node_defs); + + status = _cairo_output_stream_destroy (mask_stream); + if (unlikely (status)) + return status; + + snprintf (buffer, sizeof buffer, "mask=\"url(#mask%d)\"", + mask_id); + status = _cairo_svg_surface_emit_paint (surface->xml_node, surface, op, source, 0, buffer); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_stroke (void *abstract_dst, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_svg_surface_t *surface = abstract_dst; + cairo_status_t status; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return _cairo_svg_surface_analyze_operation (surface, op, source); + + assert (_cairo_svg_surface_operation_supported (surface, op, source)); + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, "xml_node, surface, op, + source, stroke_style, ctm_inverse); + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, "\" "); + + _cairo_svg_surface_emit_path (surface->xml_node, path, ctm_inverse); + + _cairo_svg_surface_emit_transform (surface->xml_node, " transform", ctm, NULL); + _cairo_output_stream_printf (surface->xml_node, "/>\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_svg_surface_show_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *pattern, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_svg_surface_t *surface = abstract_surface; + cairo_svg_document_t *document = surface->document; + cairo_path_fixed_t path; + cairo_int_status_t status; + cairo_scaled_font_subsets_glyph_t subset_glyph; + int i; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return _cairo_svg_surface_analyze_operation (surface, op, pattern); + + assert (_cairo_svg_surface_operation_supported (surface, op, pattern)); + + if (num_glyphs <= 0) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + /* FIXME it's probably possible to apply a pattern of a gradient to + * a group of symbols, but I don't know how yet. Gradients or patterns + * are translated by x and y properties of use element. */ + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) + goto FALLBACK; + + _cairo_output_stream_printf (surface->xml_node, "xml_node, FALSE, NULL); + if (unlikely (status)) + return status; + + _cairo_svg_surface_emit_operator_for_style (surface->xml_node, surface, op); + + _cairo_output_stream_printf (surface->xml_node, "\">\n"); + + for (i = 0; i < num_glyphs; i++) { + status = _cairo_scaled_font_subsets_map_glyph (document->font_subsets, + scaled_font, glyphs[i].index, + NULL, 0, + &subset_glyph); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + _cairo_output_stream_printf (surface->xml_node, "\n"); + + glyphs += i; + num_glyphs -= i; + goto FALLBACK; + } + + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->xml_node, + " \n", + subset_glyph.font_id, + subset_glyph.subset_glyph_index, + glyphs[i].x, glyphs[i].y); + } + + _cairo_output_stream_printf (surface->xml_node, "\n"); + + return CAIRO_STATUS_SUCCESS; + +FALLBACK: + _cairo_path_fixed_init (&path); + + status = _cairo_scaled_font_glyph_path (scaled_font, + (cairo_glyph_t *) glyphs, + num_glyphs, &path); + + if (unlikely (status)) { + _cairo_path_fixed_fini (&path); + return status; + } + + status = _cairo_svg_surface_fill (abstract_surface, op, pattern, + &path, CAIRO_FILL_RULE_WINDING, + 0.0, CAIRO_ANTIALIAS_SUBPIXEL, + clip); + + _cairo_path_fixed_fini (&path); + + return status; +} + +static void +_cairo_svg_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + _cairo_font_options_init_default (options); + + cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); + _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); +} + + +static const char ** +_cairo_svg_surface_get_supported_mime_types (void *abstract_surface) +{ + return _cairo_svg_supported_mime_types; +} + +static const cairo_surface_backend_t cairo_svg_surface_backend = { + CAIRO_SURFACE_TYPE_SVG, + _cairo_svg_surface_finish, + + _cairo_default_context_create, + + NULL, /* create_similar: handled by wrapper */ + NULL, /* create_similar_image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + _cairo_svg_surface_copy_page, + _cairo_svg_surface_show_page, + + _cairo_svg_surface_get_extents, + _cairo_svg_surface_get_font_options, + + NULL, /* flush */ + NULL, /* mark dirty rectangle */ + + _cairo_svg_surface_paint, + _cairo_svg_surface_mask, + _cairo_svg_surface_stroke, + _cairo_svg_surface_fill, + _cairo_svg_surface_fill_stroke, + _cairo_svg_surface_show_glyphs, + NULL, /* has_show_text_glyphs */ + NULL, /* show_text_glyphs */ + _cairo_svg_surface_get_supported_mime_types, +}; + +static cairo_status_t +_cairo_svg_document_create (cairo_output_stream_t *output_stream, + double width, + double height, + cairo_svg_version_t version, + cairo_svg_document_t **document_out) +{ + cairo_svg_document_t *document; + cairo_status_t status, status_ignored; + + if (output_stream->status) + return output_stream->status; + + document = malloc (sizeof (cairo_svg_document_t)); + if (unlikely (document == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* The use of defs for font glyphs imposes no per-subset limit. */ + document->font_subsets = _cairo_scaled_font_subsets_create_scaled (); + if (unlikely (document->font_subsets == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_DOCUMENT; + } + + document->output_stream = output_stream; + document->refcount = 1; + document->owner = NULL; + document->finished = FALSE; + document->width = width; + document->height = height; + + document->linear_pattern_id = 0; + document->radial_pattern_id = 0; + document->pattern_id = 0; + document->filter_id = 0; + document->clip_id = 0; + document->mask_id = 0; + + document->xml_node_defs = _cairo_memory_stream_create (); + status = _cairo_output_stream_get_status (document->xml_node_defs); + if (unlikely (status)) + goto CLEANUP_NODE_DEFS; + + document->xml_node_glyphs = _cairo_memory_stream_create (); + status = _cairo_output_stream_get_status (document->xml_node_glyphs); + if (unlikely (status)) + goto CLEANUP_NODE_GLYPHS; + + document->alpha_filter = FALSE; + + document->svg_version = version; + + *document_out = document; + return CAIRO_STATUS_SUCCESS; + + CLEANUP_NODE_GLYPHS: + status_ignored = _cairo_output_stream_destroy (document->xml_node_glyphs); + CLEANUP_NODE_DEFS: + status_ignored = _cairo_output_stream_destroy (document->xml_node_defs); + _cairo_scaled_font_subsets_destroy (document->font_subsets); + CLEANUP_DOCUMENT: + free (document); + return status; +} + +static cairo_svg_document_t * +_cairo_svg_document_reference (cairo_svg_document_t *document) +{ + document->refcount++; + + return document; +} + +static unsigned int +_cairo_svg_document_allocate_mask_id (cairo_svg_document_t *document) +{ + return document->mask_id++; +} + +static cairo_status_t +_cairo_svg_document_destroy (cairo_svg_document_t *document) +{ + cairo_status_t status; + + document->refcount--; + if (document->refcount > 0) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_svg_document_finish (document); + + free (document); + + return status; +} + +static cairo_status_t +_cairo_svg_document_finish (cairo_svg_document_t *document) +{ + cairo_status_t status, status2; + cairo_output_stream_t *output = document->output_stream; + cairo_svg_page_t *page; + unsigned int i; + + if (document->finished) + return CAIRO_STATUS_SUCCESS; + + /* + * Should we add DOCTYPE? + * + * Google says no. + * + * http://tech.groups.yahoo.com/group/svg-developers/message/48562: + * There's a bunch of issues, but just to pick a few: + * - they'll give false positives. + * - they'll give false negatives. + * - they're namespace-unaware. + * - they don't wildcard. + * So when they say OK they really haven't checked anything, when + * they say NOT OK they might be on crack, and like all + * namespace-unaware things they're a dead branch of the XML tree. + * + * http://jwatt.org/svg/authoring/: + * Unfortunately the SVG DTDs are a source of so many issues that the + * SVG WG has decided not to write one for the upcoming SVG 1.2 + * standard. In fact SVG WG members are even telling people not to use + * a DOCTYPE declaration in SVG 1.0 and 1.1 documents. + */ + + _cairo_output_stream_printf (output, + "\n" + "\n", + document->width, document->height, + document->width, document->height, + _cairo_svg_internal_version_strings [document->svg_version]); + + status = _cairo_svg_document_emit_font_subsets (document); + + if (_cairo_memory_stream_length (document->xml_node_glyphs) > 0 || + _cairo_memory_stream_length (document->xml_node_defs) > 0) { + _cairo_output_stream_printf (output, "\n"); + if (_cairo_memory_stream_length (document->xml_node_glyphs) > 0) { + _cairo_output_stream_printf (output, "\n"); + _cairo_memory_stream_copy (document->xml_node_glyphs, output); + _cairo_output_stream_printf (output, "\n"); + } + _cairo_memory_stream_copy (document->xml_node_defs, output); + _cairo_output_stream_printf (output, "\n"); + } + + if (document->owner != NULL) { + cairo_svg_surface_t *surface; + + surface = (cairo_svg_surface_t *) _cairo_paginated_surface_get_target (document->owner); + if (surface->xml_node != NULL && + _cairo_memory_stream_length (surface->xml_node) > 0) { + if (unlikely (_cairo_svg_surface_store_page (surface) == NULL)) { + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + if (surface->page_set.num_elements > 1 && + _cairo_svg_version_has_page_set_support (document->svg_version)) { + _cairo_output_stream_printf (output, "\n"); + for (i = 0; i < surface->page_set.num_elements; i++) { + page = _cairo_array_index (&surface->page_set, i); + _cairo_output_stream_printf (output, "\n"); + _cairo_output_stream_printf (output, + "\n", + page->surface_id); + _cairo_memory_stream_copy (page->xml_node, output); + _cairo_output_stream_printf (output, "\n\n"); + } + _cairo_output_stream_printf (output, "\n"); + } else if (surface->page_set.num_elements > 0) { + page = _cairo_array_index (&surface->page_set, surface->page_set.num_elements - 1); + _cairo_output_stream_printf (output, + "\n", + page->surface_id); + _cairo_memory_stream_copy (page->xml_node, output); + _cairo_output_stream_printf (output, "\n"); + } + } + + _cairo_output_stream_printf (output, "\n"); + + status2 = _cairo_output_stream_destroy (document->xml_node_glyphs); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + status2 = _cairo_output_stream_destroy (document->xml_node_defs); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + status2 = _cairo_output_stream_destroy (output); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + document->finished = TRUE; + + return status; +} + +static void +_cairo_svg_surface_set_paginated_mode (void *abstract_surface, + cairo_paginated_mode_t paginated_mode) +{ + cairo_svg_surface_t *surface = abstract_surface; + + surface->paginated_mode = paginated_mode; +} + +static cairo_bool_t +_cairo_svg_surface_supports_fine_grained_fallbacks (void *abstract_surface) +{ + cairo_svg_surface_t *surface = abstract_surface; + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + if (surface->document->svg_version >= CAIRO_SVG_VERSION_1_2) { + status = _cairo_svg_surface_analyze_operator (surface, + CAIRO_OPERATOR_SOURCE); + } + + return status == CAIRO_INT_STATUS_SUCCESS; +} + +static const cairo_paginated_surface_backend_t cairo_svg_surface_paginated_backend = { + NULL /*_cairo_svg_surface_start_page*/, + _cairo_svg_surface_set_paginated_mode, + NULL, /* _cairo_svg_surface_set_bounding_box */ + NULL, /* _cairo_svg_surface_set_fallback_images_required */ + _cairo_svg_surface_supports_fine_grained_fallbacks, + +}; diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-svg.h b/Build/source/libs/cairo/cairo-src/src/cairo-svg.h new file mode 100644 index 00000000000..592c645f627 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-svg.h @@ -0,0 +1,84 @@ +/* cairo - a vector graphics library with display and print output + * + * cairo-svg.h + * + * Copyright © 2005 Emmanuel Pacaud + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#ifndef CAIRO_SVG_H +#define CAIRO_SVG_H + +#include "cairo.h" + +#if CAIRO_HAS_SVG_SURFACE + +CAIRO_BEGIN_DECLS + +/** + * cairo_svg_version_t: + * @CAIRO_SVG_VERSION_1_1: The version 1.1 of the SVG specification. (Since 1.2) + * @CAIRO_SVG_VERSION_1_2: The version 1.2 of the SVG specification. (Since 1.2) + * + * #cairo_svg_version_t is used to describe the version number of the SVG + * specification that a generated SVG file will conform to. + * + * Since: 1.2 + **/ +typedef enum _cairo_svg_version { + CAIRO_SVG_VERSION_1_1, + CAIRO_SVG_VERSION_1_2 +} cairo_svg_version_t; + +cairo_public cairo_surface_t * +cairo_svg_surface_create (const char *filename, + double width_in_points, + double height_in_points); + +cairo_public cairo_surface_t * +cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, + void *closure, + double width_in_points, + double height_in_points); + +cairo_public void +cairo_svg_surface_restrict_to_version (cairo_surface_t *surface, + cairo_svg_version_t version); + +cairo_public void +cairo_svg_get_versions (cairo_svg_version_t const **versions, + int *num_versions); + +cairo_public const char * +cairo_svg_version_to_string (cairo_svg_version_t version); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_SVG_SURFACE */ +# error Cairo was not compiled with support for the svg backend +#endif /* CAIRO_HAS_SVG_SURFACE */ + +#endif /* CAIRO_SVG_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tee-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-tee-surface-private.h new file mode 100644 index 00000000000..a83cfc959db --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tee-surface-private.h @@ -0,0 +1,47 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_TEE_SURFACE_PRIVATE_H +#define CAIRO_TEE_SURFACE_PRIVATE_H + +#include "cairoint.h" + +cairo_private cairo_surface_t * +_cairo_tee_surface_find_match (void *abstract_surface, + const cairo_surface_backend_t *backend, + cairo_content_t content); + +#endif /* CAIRO_TEE_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tee-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-tee-surface.c new file mode 100644 index 00000000000..294e5f162e2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tee-surface.c @@ -0,0 +1,602 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + * Chris Wilson + */ + +/* This surface supports redirecting all its input to multiple surfaces. + */ + +#include "cairoint.h" + +#include "cairo-tee.h" + +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-tee-surface-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-surface-wrapper-private.h" +#include "cairo-array-private.h" +#include "cairo-image-surface-inline.h" + +typedef struct _cairo_tee_surface { + cairo_surface_t base; + + cairo_surface_wrapper_t master; + cairo_array_t slaves; +} cairo_tee_surface_t; + +slim_hidden_proto (cairo_tee_surface_create); +slim_hidden_proto (cairo_tee_surface_add); + +static cairo_surface_t * +_cairo_tee_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + + cairo_tee_surface_t *other = abstract_surface; + cairo_surface_t *similar; + cairo_surface_t *surface; + cairo_surface_wrapper_t *slaves; + int n, num_slaves; + + similar = _cairo_surface_wrapper_create_similar (&other->master, + content, width, height); + surface = cairo_tee_surface_create (similar); + cairo_surface_destroy (similar); + if (unlikely (surface->status)) + return surface; + + num_slaves = _cairo_array_num_elements (&other->slaves); + slaves = _cairo_array_index (&other->slaves, 0); + for (n = 0; n < num_slaves; n++) { + + similar = _cairo_surface_wrapper_create_similar (&slaves[n], + content, + width, height); + cairo_tee_surface_add (surface, similar); + cairo_surface_destroy (similar); + } + + if (unlikely (surface->status)) { + cairo_status_t status = surface->status; + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + + return surface; +} + +static cairo_status_t +_cairo_tee_surface_finish (void *abstract_surface) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + int n, num_slaves; + + _cairo_surface_wrapper_fini (&surface->master); + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) + _cairo_surface_wrapper_fini (&slaves[n]); + + _cairo_array_fini (&surface->slaves); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_tee_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_tee_surface_t *surface = abstract_surface; + return _cairo_surface_get_source (surface->master.target, extents); +} + +static cairo_status_t +_cairo_tee_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + int num_slaves, n; + + /* we prefer to use a real image surface if available */ + if (_cairo_surface_is_image (surface->master.target)) { + return _cairo_surface_wrapper_acquire_source_image (&surface->master, + image_out, image_extra); + } + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + if (_cairo_surface_is_image (slaves[n].target)) { + return _cairo_surface_wrapper_acquire_source_image (&slaves[n], + image_out, + image_extra); + } + } + + return _cairo_surface_wrapper_acquire_source_image (&surface->master, + image_out, image_extra); +} + +static void +_cairo_tee_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_tee_surface_t *surface = abstract_surface; + + _cairo_surface_wrapper_release_source_image (&surface->master, + image, image_extra); +} + +static cairo_surface_t * +_cairo_tee_surface_snapshot (void *abstract_surface) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + int num_slaves, n; + + /* we prefer to use a recording surface for our snapshots */ + if (_cairo_surface_is_recording (surface->master.target)) + return _cairo_surface_wrapper_snapshot (&surface->master); + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + if (_cairo_surface_is_recording (slaves[n].target)) + return _cairo_surface_wrapper_snapshot (&slaves[n]); + } + + return _cairo_surface_wrapper_snapshot (&surface->master); +} + +static cairo_bool_t +_cairo_tee_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_tee_surface_t *surface = abstract_surface; + + return _cairo_surface_wrapper_get_extents (&surface->master, rectangle); +} + +static void +_cairo_tee_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_tee_surface_t *surface = abstract_surface; + + _cairo_surface_wrapper_get_font_options (&surface->master, options); +} + +static cairo_int_status_t +_cairo_tee_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + int n, num_slaves; + cairo_int_status_t status; + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + status = _cairo_surface_wrapper_paint (&slaves[n], op, source, clip); + if (unlikely (status)) + return status; + } + + return _cairo_surface_wrapper_paint (&surface->master, op, source, clip); +} + +static cairo_int_status_t +_cairo_tee_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + cairo_int_status_t status; + int n, num_slaves; + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + status = _cairo_surface_wrapper_mask (&slaves[n], + op, source, mask, clip); + if (unlikely (status)) + return status; + } + + return _cairo_surface_wrapper_mask (&surface->master, + op, source, mask, clip); +} + +static cairo_int_status_t +_cairo_tee_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + cairo_int_status_t status; + int n, num_slaves; + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + status = _cairo_surface_wrapper_stroke (&slaves[n], + op, source, + path, style, + ctm, ctm_inverse, + tolerance, antialias, + clip); + if (unlikely (status)) + return status; + } + + return _cairo_surface_wrapper_stroke (&surface->master, + op, source, + path, style, + ctm, ctm_inverse, + tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_tee_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + cairo_int_status_t status; + int n, num_slaves; + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + status = _cairo_surface_wrapper_fill (&slaves[n], + op, source, + path, fill_rule, + tolerance, antialias, + clip); + if (unlikely (status)) + return status; + } + + return _cairo_surface_wrapper_fill (&surface->master, + op, source, + path, fill_rule, + tolerance, antialias, + clip); +} + +static cairo_bool_t +_cairo_tee_surface_has_show_text_glyphs (void *abstract_surface) +{ + return TRUE; +} + +static cairo_int_status_t +_cairo_tee_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + cairo_int_status_t status; + int n, num_slaves; + cairo_glyph_t *glyphs_copy; + + /* XXX: This copying is ugly. */ + glyphs_copy = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); + if (unlikely (glyphs_copy == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + memcpy (glyphs_copy, glyphs, sizeof (cairo_glyph_t) * num_glyphs); + status = _cairo_surface_wrapper_show_text_glyphs (&slaves[n], op, + source, + utf8, utf8_len, + glyphs_copy, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font, + clip); + if (unlikely (status)) + goto CLEANUP; + } + + memcpy (glyphs_copy, glyphs, sizeof (cairo_glyph_t) * num_glyphs); + status = _cairo_surface_wrapper_show_text_glyphs (&surface->master, op, + source, + utf8, utf8_len, + glyphs_copy, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font, + clip); +CLEANUP: + free (glyphs_copy); + return status; +} + +static const cairo_surface_backend_t cairo_tee_surface_backend = { + CAIRO_SURFACE_TYPE_TEE, + _cairo_tee_surface_finish, + + _cairo_default_context_create, /* XXX */ + + _cairo_tee_surface_create_similar, + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_tee_surface_source, + _cairo_tee_surface_acquire_source_image, + _cairo_tee_surface_release_source_image, + _cairo_tee_surface_snapshot, + NULL, /* copy_page */ + NULL, /* show_page */ + _cairo_tee_surface_get_extents, + _cairo_tee_surface_get_font_options, + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_tee_surface_paint, + _cairo_tee_surface_mask, + _cairo_tee_surface_stroke, + _cairo_tee_surface_fill, + NULL, /* fill_stroke */ + + NULL, /* show_glyphs */ + + _cairo_tee_surface_has_show_text_glyphs, + _cairo_tee_surface_show_text_glyphs +}; + +cairo_surface_t * +cairo_tee_surface_create (cairo_surface_t *master) +{ + cairo_tee_surface_t *surface; + + if (unlikely (master->status)) + return _cairo_surface_create_in_error (master->status); + + surface = malloc (sizeof (cairo_tee_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &cairo_tee_surface_backend, + master->device, + master->content); + + _cairo_surface_wrapper_init (&surface->master, master); + + _cairo_array_init (&surface->slaves, sizeof (cairo_surface_wrapper_t)); + + return &surface->base; +} +slim_hidden_def (cairo_tee_surface_create); + +void +cairo_tee_surface_add (cairo_surface_t *abstract_surface, + cairo_surface_t *target) +{ + cairo_tee_surface_t *surface; + cairo_surface_wrapper_t slave; + cairo_status_t status; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (abstract_surface->backend != &cairo_tee_surface_backend) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + if (unlikely (target->status)) { + status = _cairo_surface_set_error (abstract_surface, target->status); + return; + } + + surface = (cairo_tee_surface_t *) abstract_surface; + + _cairo_surface_wrapper_init (&slave, target); + status = _cairo_array_append (&surface->slaves, &slave); + if (unlikely (status)) { + _cairo_surface_wrapper_fini (&slave); + status = _cairo_surface_set_error (&surface->base, status); + } +} +slim_hidden_def (cairo_tee_surface_add); + +void +cairo_tee_surface_remove (cairo_surface_t *abstract_surface, + cairo_surface_t *target) +{ + cairo_tee_surface_t *surface; + cairo_surface_wrapper_t *slaves; + int n, num_slaves; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (abstract_surface->backend != &cairo_tee_surface_backend) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + surface = (cairo_tee_surface_t *) abstract_surface; + if (target == surface->master.target) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_INVALID_INDEX)); + return; + } + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + if (slaves[n].target == target) + break; + } + + if (n == num_slaves) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_INVALID_INDEX)); + return; + } + + _cairo_surface_wrapper_fini (&slaves[n]); + for (n++; n < num_slaves; n++) + slaves[n-1] = slaves[n]; + surface->slaves.num_elements--; /* XXX: cairo_array_remove()? */ +} + +cairo_surface_t * +cairo_tee_surface_index (cairo_surface_t *abstract_surface, + unsigned int index) +{ + cairo_tee_surface_t *surface; + + if (unlikely (abstract_surface->status)) + return _cairo_surface_create_in_error (abstract_surface->status); + if (unlikely (abstract_surface->finished)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (abstract_surface->backend != &cairo_tee_surface_backend) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + + surface = (cairo_tee_surface_t *) abstract_surface; + if (index == 0) { + return surface->master.target; + } else { + cairo_surface_wrapper_t *slave; + + index--; + + if (index >= _cairo_array_num_elements (&surface->slaves)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_INDEX)); + + slave = _cairo_array_index (&surface->slaves, index); + return slave->target; + } +} + +cairo_surface_t * +_cairo_tee_surface_find_match (void *abstract_surface, + const cairo_surface_backend_t *backend, + cairo_content_t content) +{ + cairo_tee_surface_t *surface = abstract_surface; + cairo_surface_wrapper_t *slaves; + int num_slaves, n; + + /* exact match first */ + if (surface->master.target->backend == backend && + surface->master.target->content == content) + { + return surface->master.target; + } + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + if (slaves[n].target->backend == backend && + slaves[n].target->content == content) + { + return slaves[n].target; + } + } + + /* matching backend? */ + if (surface->master.target->backend == backend) + return surface->master.target; + + num_slaves = _cairo_array_num_elements (&surface->slaves); + slaves = _cairo_array_index (&surface->slaves, 0); + for (n = 0; n < num_slaves; n++) { + if (slaves[n].target->backend == backend) + return slaves[n].target; + } + + return NULL; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tee.h b/Build/source/libs/cairo/cairo-src/src/cairo-tee.h new file mode 100644 index 00000000000..9125a3a4a2b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tee.h @@ -0,0 +1,66 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_TEE_H +#define CAIRO_TEE_H + +#include "cairo.h" + +#if CAIRO_HAS_TEE_SURFACE + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_tee_surface_create (cairo_surface_t *master); + +cairo_public void +cairo_tee_surface_add (cairo_surface_t *surface, + cairo_surface_t *target); + +cairo_public void +cairo_tee_surface_remove (cairo_surface_t *surface, + cairo_surface_t *target); + +cairo_public cairo_surface_t * +cairo_tee_surface_index (cairo_surface_t *surface, + unsigned int index); + +CAIRO_END_DECLS + +#else /*CAIRO_HAS_TEE_SURFACE*/ +# error Cairo was not compiled with support for the TEE backend +#endif /*CAIRO_HAS_TEE_SURFACE*/ + +#endif /*CAIRO_TEE_H*/ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-time-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-time-private.h new file mode 100644 index 00000000000..06dc912b431 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-time-private.h @@ -0,0 +1,94 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright (C) 2011 Andrea Canciani + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of the + * copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Authors: Andrea Canciani + * + */ + +#ifndef CAIRO_TIME_PRIVATE_H +#define CAIRO_TIME_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-wideint-private.h" + +/* Make the base type signed for easier arithmetic */ +typedef cairo_int64_t cairo_time_t; + +#define _cairo_time_add _cairo_int64_add +#define _cairo_time_sub _cairo_int64_sub +#define _cairo_time_gt _cairo_int64_gt +#define _cairo_time_lt _cairo_int64_lt + +#define _cairo_time_to_double _cairo_int64_to_double +#define _cairo_time_from_double _cairo_double_to_int64 + +cairo_private int +_cairo_time_cmp (const void *a, + const void *b); + +cairo_private double +_cairo_time_to_s (cairo_time_t t); + +cairo_private cairo_time_t +_cairo_time_from_s (double t); + +cairo_private cairo_time_t +_cairo_time_get (void); + +static cairo_always_inline cairo_time_t +_cairo_time_get_delta (cairo_time_t t) +{ + cairo_time_t now; + + now = _cairo_time_get (); + + return _cairo_time_sub (now, t); +} + +static cairo_always_inline double +_cairo_time_to_ns (cairo_time_t t) +{ + return 1.e9 * _cairo_time_to_s (t); +} + +static cairo_always_inline cairo_time_t +_cairo_time_max (cairo_time_t a, cairo_time_t b) +{ + if (_cairo_int64_gt (a, b)) + return a; + else + return b; +} + +static cairo_always_inline cairo_time_t +_cairo_time_min (cairo_time_t a, cairo_time_t b) +{ + if (_cairo_int64_lt (a, b)) + return a; + else + return b; +} + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-time.c b/Build/source/libs/cairo/cairo-src/src/cairo-time.c new file mode 100644 index 00000000000..a0003fbfc2c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-time.c @@ -0,0 +1,225 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright (c) 2007 Netlabs + * Copyright (c) 2006 Mozilla Corporation + * Copyright (c) 2006 Red Hat, Inc. + * Copyright (c) 2011 Andrea Canciani + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * the authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The authors make no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Peter Weilbacher + * Vladimir Vukicevic + * Carl Worth + * Andrea Canciani + */ + +#include "cairoint.h" + +#include "cairo-time-private.h" + +#if HAVE_CLOCK_GETTIME +#if defined(CLOCK_MONOTONIC_RAW) +#define CAIRO_CLOCK CLOCK_MONOTONIC_RAW +#elif defined(CLOCK_MONOTONIC) +#define CAIRO_CLOCK CLOCK_MONOTONIC +#endif +#endif + +#if defined(__APPLE__) +#include + +static cairo_always_inline double +_cairo_time_1s (void) +{ + mach_timebase_info_data_t freq; + + mach_timebase_info (&freq); + + return 1000000000. * freq.denom / freq.numer; +} + +cairo_time_t +_cairo_time_get (void) +{ + return mach_absolute_time (); +} + +#elif defined(__OS2__) +#define INCL_BASE +#include + +static cairo_always_inline double +_cairo_time_1s (void) +{ + ULONG freq; + + DosTmrQueryFreq (&freq); + + return freq; +} + +cairo_time_t +_cairo_time_get (void) +{ + QWORD t; + cairo_int64_t r; + + DosTmrQueryTime (&t); + + r = _cairo_int64_lsl (_cairo_int32_to_int64 (t.ulHi), 32); + r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.ulLo)); + + return r; +} + +#elif _WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +static cairo_always_inline double +_cairo_time_1s (void) +{ + LARGE_INTEGER freq; + + QueryPerformanceFrequency (&freq); + + return freq.QuadPart; +} + +#ifndef HAVE_UINT64_T +static cairo_always_inline cairo_time_t +_cairo_time_from_large_integer (LARGE_INTEGER t) +{ + cairo_int64_t r; + + r = _cairo_int64_lsl (_cairo_int32_to_int64 (t.HighPart), 32); + r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.LowPart)); + + return r; +} +#else +static cairo_always_inline cairo_time_t +_cairo_time_from_large_integer (LARGE_INTEGER t) +{ + return t.QuadPart; +} +#endif + +cairo_time_t +_cairo_time_get (void) +{ + LARGE_INTEGER t; + + QueryPerformanceCounter (&t); + + return _cairo_time_from_large_integer(t); +} + +#elif defined(CAIRO_CLOCK) +#include + +static cairo_always_inline double +_cairo_time_1s (void) +{ + return 1000000000; +} + +cairo_time_t +_cairo_time_get (void) +{ + struct timespec t; + cairo_time_t r; + + clock_gettime (CAIRO_CLOCK, &t); + + r = _cairo_double_to_int64 (_cairo_time_1s ()); + r = _cairo_int64_mul (r, _cairo_int32_to_int64 (t.tv_sec)); + r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.tv_nsec)); + + return r; +} + +#else +#include + +static cairo_always_inline double +_cairo_time_1s (void) +{ + return 1000000; +} + +cairo_time_t +_cairo_time_get (void) +{ + struct timeval t; + cairo_time_t r; + + gettimeofday (&t, NULL); + + r = _cairo_double_to_int64 (_cairo_time_1s ()); + r = _cairo_int64_mul (r, _cairo_int32_to_int64 (t.tv_sec)); + r = _cairo_int64_add (r, _cairo_int32_to_int64 (t.tv_usec)); + + return r; +} + +#endif + +int +_cairo_time_cmp (const void *a, + const void *b) +{ + const cairo_time_t *ta = a, *tb = b; + return _cairo_int64_cmp (*ta, *tb); +} + +static double +_cairo_time_ticks_per_sec (void) +{ + static double ticks = 0; + + if (unlikely (ticks == 0)) + ticks = _cairo_time_1s (); + + return ticks; +} + +static double +_cairo_time_s_per_tick (void) +{ + static double s = 0; + + if (unlikely (s == 0)) + s = 1. / _cairo_time_ticks_per_sec (); + + return s; +} + +double +_cairo_time_to_s (cairo_time_t t) +{ + return _cairo_int64_to_double (t) * _cairo_time_s_per_tick (); +} + +cairo_time_t +_cairo_time_from_s (double t) +{ + return _cairo_double_to_int64 (t * _cairo_time_ticks_per_sec ()); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tor-scan-converter.c b/Build/source/libs/cairo/cairo-src/src/cairo-tor-scan-converter.c new file mode 100644 index 00000000000..b1b51872b19 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tor-scan-converter.c @@ -0,0 +1,1899 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* glitter-paths - polygon scan converter + * + * Copyright (c) 2008 M Joonas Pihlaja + * Copyright (c) 2007 David Turner + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +/* This is the Glitter paths scan converter incorporated into cairo. + * The source is from commit 734c53237a867a773640bd5b64816249fa1730f8 + * of + * + * http://gitweb.freedesktop.org/?p=users/joonas/glitter-paths + */ +/* Glitter-paths is a stand alone polygon rasteriser derived from + * David Turner's reimplementation of Tor Anderssons's 15x17 + * supersampling rasteriser from the Apparition graphics library. The + * main new feature here is cheaply choosing per-scan line between + * doing fully analytical coverage computation for an entire row at a + * time vs. using a supersampling approach. + * + * David Turner's code can be found at + * + * http://david.freetype.org/rasterizer-shootout/raster-comparison-20070813.tar.bz2 + * + * In particular this file incorporates large parts of ftgrays_tor10.h + * from raster-comparison-20070813.tar.bz2 + */ +/* Overview + * + * A scan converter's basic purpose to take polygon edges and convert + * them into an RLE compressed A8 mask. This one works in two phases: + * gathering edges and generating spans. + * + * 1) As the user feeds the scan converter edges they are vertically + * clipped and bucketted into a _polygon_ data structure. The edges + * are also snapped from the user's coordinates to the subpixel grid + * coordinates used during scan conversion. + * + * user + * | + * | edges + * V + * polygon buckets + * + * 2) Generating spans works by performing a vertical sweep of pixel + * rows from top to bottom and maintaining an _active_list_ of edges + * that intersect the row. From the active list the fill rule + * determines which edges are the left and right edges of the start of + * each span, and their contribution is then accumulated into a pixel + * coverage list (_cell_list_) as coverage deltas. Once the coverage + * deltas of all edges are known we can form spans of constant pixel + * coverage by summing the deltas during a traversal of the cell list. + * At the end of a pixel row the cell list is sent to a coverage + * blitter for rendering to some target surface. + * + * The pixel coverages are computed by either supersampling the row + * and box filtering a mono rasterisation, or by computing the exact + * coverages of edges in the active list. The supersampling method is + * used whenever some edge starts or stops within the row or there are + * edge intersections in the row. + * + * polygon bucket for \ + * current pixel row | + * | | + * | activate new edges | Repeat GRID_Y times if we + * V \ are supersampling this row, + * active list / or just once if we're computing + * | | analytical coverage. + * | coverage deltas | + * V | + * pixel coverage list / + * | + * V + * coverage blitter + */ +#include "cairoint.h" +#include "cairo-spans-private.h" +#include "cairo-error-private.h" + +#include +#include +#include +#include + +/*------------------------------------------------------------------------- + * cairo specific config + */ +#define I static + +/* Prefer cairo's status type. */ +#define GLITTER_HAVE_STATUS_T 1 +#define GLITTER_STATUS_SUCCESS CAIRO_STATUS_SUCCESS +#define GLITTER_STATUS_NO_MEMORY CAIRO_STATUS_NO_MEMORY +typedef cairo_status_t glitter_status_t; + +/* The input coordinate scale and the rasterisation grid scales. */ +#define GLITTER_INPUT_BITS CAIRO_FIXED_FRAC_BITS +#define GRID_X_BITS CAIRO_FIXED_FRAC_BITS +#define GRID_Y 15 + +/* Set glitter up to use a cairo span renderer to do the coverage + * blitting. */ +struct pool; +struct cell_list; + +/*------------------------------------------------------------------------- + * glitter-paths.h + */ + +/* "Input scaled" numbers are fixed precision reals with multiplier + * 2**GLITTER_INPUT_BITS. Input coordinates are given to glitter as + * pixel scaled numbers. These get converted to the internal grid + * scaled numbers as soon as possible. Internal overflow is possible + * if GRID_X/Y inside glitter-paths.c is larger than + * 1< +#include +#include + +/* All polygon coordinates are snapped onto a subsample grid. "Grid + * scaled" numbers are fixed precision reals with multiplier GRID_X or + * GRID_Y. */ +typedef int grid_scaled_t; +typedef int grid_scaled_x_t; +typedef int grid_scaled_y_t; + +/* Default x/y scale factors. + * You can either define GRID_X/Y_BITS to get a power-of-two scale + * or define GRID_X/Y separately. */ +#if !defined(GRID_X) && !defined(GRID_X_BITS) +# define GRID_X_BITS 8 +#endif +#if !defined(GRID_Y) && !defined(GRID_Y_BITS) +# define GRID_Y 15 +#endif + +/* Use GRID_X/Y_BITS to define GRID_X/Y if they're available. */ +#ifdef GRID_X_BITS +# define GRID_X (1 << GRID_X_BITS) +#endif +#ifdef GRID_Y_BITS +# define GRID_Y (1 << GRID_Y_BITS) +#endif + +/* The GRID_X_TO_INT_FRAC macro splits a grid scaled coordinate into + * integer and fractional parts. The integer part is floored. */ +#if defined(GRID_X_TO_INT_FRAC) + /* do nothing */ +#elif defined(GRID_X_BITS) +# define GRID_X_TO_INT_FRAC(x, i, f) \ + _GRID_TO_INT_FRAC_shift(x, i, f, GRID_X_BITS) +#else +# define GRID_X_TO_INT_FRAC(x, i, f) \ + _GRID_TO_INT_FRAC_general(x, i, f, GRID_X) +#endif + +#define _GRID_TO_INT_FRAC_general(t, i, f, m) do { \ + (i) = (t) / (m); \ + (f) = (t) % (m); \ + if ((f) < 0) { \ + --(i); \ + (f) += (m); \ + } \ +} while (0) + +#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do { \ + (f) = (t) & ((1 << (b)) - 1); \ + (i) = (t) >> (b); \ +} while (0) + +/* A grid area is a real in [0,1] scaled by 2*GRID_X*GRID_Y. We want + * to be able to represent exactly areas of subpixel trapezoids whose + * vertices are given in grid scaled coordinates. The scale factor + * comes from needing to accurately represent the area 0.5*dx*dy of a + * triangle with base dx and height dy in grid scaled numbers. */ +#define GRID_XY (2*GRID_X*GRID_Y) /* Unit area on the grid. */ + +/* GRID_AREA_TO_ALPHA(area): map [0,GRID_XY] to [0,255]. */ +#if GRID_XY == 510 +# define GRID_AREA_TO_ALPHA(c) (((c)+1) >> 1) +#elif GRID_XY == 255 +# define GRID_AREA_TO_ALPHA(c) (c) +#elif GRID_XY == 64 +# define GRID_AREA_TO_ALPHA(c) (((c) << 2) | -(((c) & 0x40) >> 6)) +#elif GRID_XY == 128 +# define GRID_AREA_TO_ALPHA(c) ((((c) << 1) | -((c) >> 7)) & 255) +#elif GRID_XY == 256 +# define GRID_AREA_TO_ALPHA(c) (((c) | -((c) >> 8)) & 255) +#elif GRID_XY == 15 +# define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) +#elif GRID_XY == 2*256*15 +# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) +#else +# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) +#endif + +#define UNROLL3(x) x x x + +struct quorem { + int32_t quo; + int64_t rem; +}; + +/* Header for a chunk of memory in a memory pool. */ +struct _pool_chunk { + /* # bytes used in this chunk. */ + size_t size; + + /* # bytes total in this chunk */ + size_t capacity; + + /* Pointer to the previous chunk or %NULL if this is the sentinel + * chunk in the pool header. */ + struct _pool_chunk *prev_chunk; + + /* Actual data starts here. Well aligned even for 64 bit types. */ + int64_t data; +}; + +/* The int64_t data member of _pool_chunk just exists to enforce alignment, + * it shouldn't be included in the allocated size for the struct. */ +#define SIZEOF_POOL_CHUNK (sizeof(struct _pool_chunk) - sizeof(int64_t)) + +/* A memory pool. This is supposed to be embedded on the stack or + * within some other structure. It may optionally be followed by an + * embedded array from which requests are fulfilled until + * malloc needs to be called to allocate a first real chunk. */ +struct pool { + /* Chunk we're allocating from. */ + struct _pool_chunk *current; + + jmp_buf *jmp; + + /* Free list of previously allocated chunks. All have >= default + * capacity. */ + struct _pool_chunk *first_free; + + /* The default capacity of a chunk. */ + size_t default_capacity; + + /* Header for the sentinel chunk. Directly following the pool + * struct should be some space for embedded elements from which + * the sentinel chunk allocates from. This is expressed as a char + * array so that the 'int64_t data' member of _pool_chunk isn't + * included. This way embedding struct pool in other structs works + * without wasting space. */ + char sentinel[SIZEOF_POOL_CHUNK]; +}; + +/* A polygon edge. */ +struct edge { + /* Next in y-bucket or active list. */ + struct edge *next, *prev; + + /* The clipped y of the top of the edge. */ + grid_scaled_y_t ytop; + + /* Number of subsample rows remaining to scan convert of this + * edge. */ + grid_scaled_y_t height_left; + + /* Original sign of the edge: +1 for downwards, -1 for upwards + * edges. */ + int dir; + int cell; + + /* Current x coordinate while the edge is on the active + * list. Initialised to the x coordinate of the top of the + * edge. The quotient is in grid_scaled_x_t units and the + * remainder is mod dy in grid_scaled_y_t units.*/ + struct quorem x; + + /* Advance of the current x when moving down a subsample line. */ + struct quorem dxdy; + + /* Advance of the current x when moving down a full pixel + * row. Only initialised when the height of the edge is large + * enough that there's a chance the edge could be stepped by a + * full row's worth of subsample rows at a time. */ + struct quorem dxdy_full; + + /* y2-y1 after orienting the edge downwards. */ + int64_t dy; +}; + +#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/GRID_Y) + +/* A collection of sorted and vertically clipped edges of the polygon. + * Edges are moved from the polygon to an active list while scan + * converting. */ +struct polygon { + /* The vertical clip extents. */ + grid_scaled_y_t ymin, ymax; + + /* Array of edges all starting in the same bucket. An edge is put + * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when + * it is added to the polygon. */ + struct edge **y_buckets; + struct edge *y_buckets_embedded[64]; + + struct { + struct pool base[1]; + struct edge embedded[32]; + } edge_pool; +}; + +/* A cell records the effect on pixel coverage of polygon edges + * passing through a pixel. It contains two accumulators of pixel + * coverage. + * + * Consider the effects of a polygon edge on the coverage of a pixel + * it intersects and that of the following one. The coverage of the + * following pixel is the height of the edge multiplied by the width + * of the pixel, and the coverage of the pixel itself is the area of + * the trapezoid formed by the edge and the right side of the pixel. + * + * +-----------------------+-----------------------+ + * | | | + * | | | + * |_______________________|_______________________| + * | \...................|.......................|\ + * | \..................|.......................| | + * | \.................|.......................| | + * | \....covered.....|.......................| | + * | \....area.......|.......................| } covered height + * | \..............|.......................| | + * |uncovered\.............|.......................| | + * | area \............|.......................| | + * |___________\...........|.......................|/ + * | | | + * | | | + * | | | + * +-----------------------+-----------------------+ + * + * Since the coverage of the following pixel will always be a multiple + * of the width of the pixel, we can store the height of the covered + * area instead. The coverage of the pixel itself is the total + * coverage minus the area of the uncovered area to the left of the + * edge. As it's faster to compute the uncovered area we only store + * that and subtract it from the total coverage later when forming + * spans to blit. + * + * The heights and areas are signed, with left edges of the polygon + * having positive sign and right edges having negative sign. When + * two edges intersect they swap their left/rightness so their + * contribution above and below the intersection point must be + * computed separately. */ +struct cell { + struct cell *next; + int x; + int16_t uncovered_area; + int16_t covered_height; +}; + +/* A cell list represents the scan line sparsely as cells ordered by + * ascending x. It is geared towards scanning the cells in order + * using an internal cursor. */ +struct cell_list { + /* Sentinel nodes */ + struct cell head, tail; + + /* Cursor state for iterating through the cell list. */ + struct cell *cursor, *rewind; + + /* Cells in the cell list are owned by the cell list and are + * allocated from this pool. */ + struct { + struct pool base[1]; + struct cell embedded[32]; + } cell_pool; +}; + +struct cell_pair { + struct cell *cell1; + struct cell *cell2; +}; + +/* The active list contains edges in the current scan line ordered by + * the x-coordinate of the intercept of the edge and the scan line. */ +struct active_list { + /* Leftmost edge on the current scan line. */ + struct edge head, tail; + + /* A lower bound on the height of the active edges is used to + * estimate how soon some active edge ends. We can't advance the + * scan conversion by a full pixel row if an edge ends somewhere + * within it. */ + grid_scaled_y_t min_height; + int is_vertical; +}; + +struct glitter_scan_converter { + struct polygon polygon[1]; + struct active_list active[1]; + struct cell_list coverages[1]; + + cairo_half_open_span_t *spans; + cairo_half_open_span_t spans_embedded[64]; + + /* Clip box. */ + grid_scaled_x_t xmin, xmax; + grid_scaled_y_t ymin, ymax; +}; + +static struct _pool_chunk * +_pool_chunk_init( + struct _pool_chunk *p, + struct _pool_chunk *prev_chunk, + size_t capacity) +{ + p->prev_chunk = prev_chunk; + p->size = 0; + p->capacity = capacity; + return p; +} + +static struct _pool_chunk * +_pool_chunk_create(struct pool *pool, size_t size) +{ + struct _pool_chunk *p; + + p = malloc(SIZEOF_POOL_CHUNK + size); + if (unlikely (NULL == p)) + longjmp (*pool->jmp, _cairo_error (CAIRO_STATUS_NO_MEMORY)); + + return _pool_chunk_init(p, pool->current, size); +} + +static void +pool_init(struct pool *pool, + jmp_buf *jmp, + size_t default_capacity, + size_t embedded_capacity) +{ + pool->jmp = jmp; + pool->current = (void*) pool->sentinel; + pool->first_free = NULL; + pool->default_capacity = default_capacity; + _pool_chunk_init(pool->current, NULL, embedded_capacity); +} + +static void +pool_fini(struct pool *pool) +{ + struct _pool_chunk *p = pool->current; + do { + while (NULL != p) { + struct _pool_chunk *prev = p->prev_chunk; + if (p != (void *) pool->sentinel) + free(p); + p = prev; + } + p = pool->first_free; + pool->first_free = NULL; + } while (NULL != p); +} + +/* Satisfy an allocation by first allocating a new large enough chunk + * and adding it to the head of the pool's chunk list. This function + * is called as a fallback if pool_alloc() couldn't do a quick + * allocation from the current chunk in the pool. */ +static void * +_pool_alloc_from_new_chunk( + struct pool *pool, + size_t size) +{ + struct _pool_chunk *chunk; + void *obj; + size_t capacity; + + /* If the allocation is smaller than the default chunk size then + * try getting a chunk off the free list. Force alloc of a new + * chunk for large requests. */ + capacity = size; + chunk = NULL; + if (size < pool->default_capacity) { + capacity = pool->default_capacity; + chunk = pool->first_free; + if (chunk) { + pool->first_free = chunk->prev_chunk; + _pool_chunk_init(chunk, pool->current, chunk->capacity); + } + } + + if (NULL == chunk) + chunk = _pool_chunk_create (pool, capacity); + pool->current = chunk; + + obj = ((unsigned char*)&chunk->data + chunk->size); + chunk->size += size; + return obj; +} + +/* Allocate size bytes from the pool. The first allocated address + * returned from a pool is aligned to 8 bytes. Subsequent + * addresses will maintain alignment as long as multiples of 8 are + * allocated. Returns the address of a new memory area or %NULL on + * allocation failures. The pool retains ownership of the returned + * memory. */ +inline static void * +pool_alloc (struct pool *pool, size_t size) +{ + struct _pool_chunk *chunk = pool->current; + + if (size <= chunk->capacity - chunk->size) { + void *obj = ((unsigned char*)&chunk->data + chunk->size); + chunk->size += size; + return obj; + } else { + return _pool_alloc_from_new_chunk(pool, size); + } +} + +/* Relinquish all pool_alloced memory back to the pool. */ +static void +pool_reset (struct pool *pool) +{ + /* Transfer all used chunks to the chunk free list. */ + struct _pool_chunk *chunk = pool->current; + if (chunk != (void *) pool->sentinel) { + while (chunk->prev_chunk != (void *) pool->sentinel) { + chunk = chunk->prev_chunk; + } + chunk->prev_chunk = pool->first_free; + pool->first_free = pool->current; + } + /* Reset the sentinel as the current chunk. */ + pool->current = (void *) pool->sentinel; + pool->current->size = 0; +} + +/* Rewinds the cell list's cursor to the beginning. After rewinding + * we're good to cell_list_find() the cell any x coordinate. */ +inline static void +cell_list_rewind (struct cell_list *cells) +{ + cells->cursor = &cells->head; +} + +inline static void +cell_list_maybe_rewind (struct cell_list *cells, int x) +{ + if (x < cells->cursor->x) { + cells->cursor = cells->rewind; + if (x < cells->cursor->x) + cells->cursor = &cells->head; + } +} + +inline static void +cell_list_set_rewind (struct cell_list *cells) +{ + cells->rewind = cells->cursor; +} + +static void +cell_list_init(struct cell_list *cells, jmp_buf *jmp) +{ + pool_init(cells->cell_pool.base, jmp, + 256*sizeof(struct cell), + sizeof(cells->cell_pool.embedded)); + cells->tail.next = NULL; + cells->tail.x = INT_MAX; + cells->head.x = INT_MIN; + cells->head.next = &cells->tail; + cell_list_rewind (cells); +} + +static void +cell_list_fini(struct cell_list *cells) +{ + pool_fini (cells->cell_pool.base); +} + +/* Empty the cell list. This is called at the start of every pixel + * row. */ +inline static void +cell_list_reset (struct cell_list *cells) +{ + cell_list_rewind (cells); + cells->head.next = &cells->tail; + pool_reset (cells->cell_pool.base); +} + +inline static struct cell * +cell_list_alloc (struct cell_list *cells, + struct cell *tail, + int x) +{ + struct cell *cell; + + cell = pool_alloc (cells->cell_pool.base, sizeof (struct cell)); + cell->next = tail->next; + tail->next = cell; + cell->x = x; + *(uint32_t *)&cell->uncovered_area = 0; + + return cell; +} + +/* Find a cell at the given x-coordinate. Returns %NULL if a new cell + * needed to be allocated but couldn't be. Cells must be found with + * non-decreasing x-coordinate until the cell list is rewound using + * cell_list_rewind(). Ownership of the returned cell is retained by + * the cell list. */ +inline static struct cell * +cell_list_find (struct cell_list *cells, int x) +{ + struct cell *tail = cells->cursor; + + if (tail->x == x) + return tail; + + while (1) { + UNROLL3({ + if (tail->next->x > x) + break; + tail = tail->next; + }); + } + + if (tail->x != x) + tail = cell_list_alloc (cells, tail, x); + return cells->cursor = tail; + +} + +/* Find two cells at x1 and x2. This is exactly equivalent + * to + * + * pair.cell1 = cell_list_find(cells, x1); + * pair.cell2 = cell_list_find(cells, x2); + * + * except with less function call overhead. */ +inline static struct cell_pair +cell_list_find_pair(struct cell_list *cells, int x1, int x2) +{ + struct cell_pair pair; + + pair.cell1 = cells->cursor; + while (1) { + UNROLL3({ + if (pair.cell1->next->x > x1) + break; + pair.cell1 = pair.cell1->next; + }); + } + if (pair.cell1->x != x1) + pair.cell1 = cell_list_alloc (cells, pair.cell1, x1); + + pair.cell2 = pair.cell1; + while (1) { + UNROLL3({ + if (pair.cell2->next->x > x2) + break; + pair.cell2 = pair.cell2->next; + }); + } + if (pair.cell2->x != x2) + pair.cell2 = cell_list_alloc (cells, pair.cell2, x2); + + cells->cursor = pair.cell2; + return pair; +} + +/* Add a subpixel span covering [x1, x2) to the coverage cells. */ +inline static void +cell_list_add_subspan(struct cell_list *cells, + grid_scaled_x_t x1, + grid_scaled_x_t x2) +{ + int ix1, fx1; + int ix2, fx2; + + if (x1 == x2) + return; + + GRID_X_TO_INT_FRAC(x1, ix1, fx1); + GRID_X_TO_INT_FRAC(x2, ix2, fx2); + + if (ix1 != ix2) { + struct cell_pair p; + p = cell_list_find_pair(cells, ix1, ix2); + p.cell1->uncovered_area += 2*fx1; + ++p.cell1->covered_height; + p.cell2->uncovered_area -= 2*fx2; + --p.cell2->covered_height; + } else { + struct cell *cell = cell_list_find(cells, ix1); + cell->uncovered_area += 2*(fx1-fx2); + } +} + +inline static void full_step (struct edge *e) +{ + if (e->dy == 0) + return; + + e->x.quo += e->dxdy_full.quo; + e->x.rem += e->dxdy_full.rem; + if (e->x.rem < 0) { + e->x.quo--; + e->x.rem += e->dy; + } else if (e->x.rem >= e->dy) { + ++e->x.quo; + e->x.rem -= e->dy; + } + + e->cell = e->x.quo + (e->x.rem >= e->dy/2); +} + + +/* Adds the analytical coverage of an edge crossing the current pixel + * row to the coverage cells and advances the edge's x position to the + * following row. + * + * This function is only called when we know that during this pixel row: + * + * 1) The relative order of all edges on the active list doesn't + * change. In particular, no edges intersect within this row to pixel + * precision. + * + * 2) No new edges start in this row. + * + * 3) No existing edges end mid-row. + * + * This function depends on being called with all edges from the + * active list in the order they appear on the list (i.e. with + * non-decreasing x-coordinate.) */ +static void +cell_list_render_edge(struct cell_list *cells, + struct edge *edge, + int sign) +{ + struct quorem x1, x2; + grid_scaled_x_t fx1, fx2; + int ix1, ix2; + + x1 = edge->x; + full_step (edge); + x2 = edge->x; + + /* Step back from the sample location (half-subrow) to the pixel origin */ + if (edge->dy) { + x1.quo -= edge->dxdy.quo / 2; + x1.rem -= edge->dxdy.rem / 2; + if (x1.rem < 0) { + --x1.quo; + x1.rem += edge->dy; + } else if (x1.rem >= edge->dy) { + ++x1.quo; + x1.rem -= edge->dy; + } + + x2.quo -= edge->dxdy.quo / 2; + x2.rem -= edge->dxdy.rem / 2; + if (x2.rem < 0) { + --x2.quo; + x2.rem += edge->dy; + } else if (x2.rem >= edge->dy) { + ++x2.quo; + x2.rem -= edge->dy; + } + } + + GRID_X_TO_INT_FRAC(x1.quo, ix1, fx1); + GRID_X_TO_INT_FRAC(x2.quo, ix2, fx2); + + cell_list_maybe_rewind(cells, MIN(ix1, ix2)); + + /* Edge is entirely within a column? */ + if (ix1 == ix2) { + /* We always know that ix1 is >= the cell list cursor in this + * case due to the no-intersections precondition. */ + struct cell *cell = cell_list_find(cells, ix1); + cell->covered_height += sign*GRID_Y; + cell->uncovered_area += sign*(fx1 + fx2)*GRID_Y; + return; + } + + /* Orient the edge left-to-right. */ + if (ix2 < ix1) { + struct quorem tx; + int t; + + t = ix1; + ix1 = ix2; + ix2 = t; + + t = fx1; + fx1 = fx2; + fx2 = t; + + tx = x1; + x1 = x2; + x2 = tx; + } + + /* Add coverage for all pixels [ix1,ix2] on this row crossed + * by the edge. */ + { + struct cell_pair pair; + struct quorem y; + int64_t tmp, dx; + int y_last; + + dx = (x2.quo - x1.quo) * edge->dy + (x2.rem - x1.rem); + + tmp = (ix1 + 1) * GRID_X * edge->dy; + tmp -= x1.quo * edge->dy + x1.rem; + tmp *= GRID_Y; + + y.quo = tmp / dx; + y.rem = tmp % dx; + + /* When rendering a previous edge on the active list we may + * advance the cell list cursor past the leftmost pixel of the + * current edge even though the two edges don't intersect. + * e.g. consider two edges going down and rightwards: + * + * --\_+---\_+-----+-----+---- + * \_ \_ | | + * | \_ | \_ | | + * | \_| \_| | + * | \_ \_ | + * ----+-----+-\---+-\---+---- + * + * The left edge touches cells past the starting cell of the + * right edge. Fortunately such cases are rare. + */ + + pair = cell_list_find_pair(cells, ix1, ix1+1); + pair.cell1->uncovered_area += sign*y.quo*(GRID_X + fx1); + pair.cell1->covered_height += sign*y.quo; + y_last = y.quo; + + if (ix1+1 < ix2) { + struct cell *cell = pair.cell2; + struct quorem dydx_full; + + dydx_full.quo = GRID_Y * GRID_X * edge->dy / dx; + dydx_full.rem = GRID_Y * GRID_X * edge->dy % dx; + + ++ix1; + do { + y.quo += dydx_full.quo; + y.rem += dydx_full.rem; + if (y.rem >= dx) { + y.quo++; + y.rem -= dx; + } + + cell->uncovered_area += sign*(y.quo - y_last)*GRID_X; + cell->covered_height += sign*(y.quo - y_last); + y_last = y.quo; + + ++ix1; + cell = cell_list_find(cells, ix1); + } while (ix1 != ix2); + + pair.cell2 = cell; + } + pair.cell2->uncovered_area += sign*(GRID_Y - y_last)*fx2; + pair.cell2->covered_height += sign*(GRID_Y - y_last); + } +} + +static void +polygon_init (struct polygon *polygon, jmp_buf *jmp) +{ + polygon->ymin = polygon->ymax = 0; + polygon->y_buckets = polygon->y_buckets_embedded; + pool_init (polygon->edge_pool.base, jmp, + 8192 - sizeof (struct _pool_chunk), + sizeof (polygon->edge_pool.embedded)); +} + +static void +polygon_fini (struct polygon *polygon) +{ + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + pool_fini (polygon->edge_pool.base); +} + +/* Empties the polygon of all edges. The polygon is then prepared to + * receive new edges and clip them to the vertical range + * [ymin,ymax). */ +static glitter_status_t +polygon_reset (struct polygon *polygon, + grid_scaled_y_t ymin, + grid_scaled_y_t ymax) +{ + unsigned h = ymax - ymin; + unsigned num_buckets = EDGE_Y_BUCKET_INDEX(ymax + GRID_Y-1, ymin); + + pool_reset(polygon->edge_pool.base); + + if (unlikely (h > 0x7FFFFFFFU - GRID_Y)) + goto bail_no_mem; /* even if you could, you wouldn't want to. */ + + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + polygon->y_buckets = polygon->y_buckets_embedded; + if (num_buckets > ARRAY_LENGTH (polygon->y_buckets_embedded)) { + polygon->y_buckets = _cairo_malloc_ab (num_buckets, + sizeof (struct edge *)); + if (unlikely (NULL == polygon->y_buckets)) + goto bail_no_mem; + } + memset (polygon->y_buckets, 0, num_buckets * sizeof (struct edge *)); + + polygon->ymin = ymin; + polygon->ymax = ymax; + return GLITTER_STATUS_SUCCESS; + +bail_no_mem: + polygon->ymin = 0; + polygon->ymax = 0; + return GLITTER_STATUS_NO_MEMORY; +} + +static void +_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, + struct edge *e) +{ + unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin); + struct edge **ptail = &polygon->y_buckets[ix]; + e->next = *ptail; + *ptail = e; +} + +static void +active_list_reset (struct active_list *active) +{ + active->head.height_left = INT_MAX; + active->head.dy = 0; + active->head.cell = INT_MIN; + active->head.prev = NULL; + active->head.next = &active->tail; + active->tail.prev = &active->head; + active->tail.next = NULL; + active->tail.cell = INT_MAX; + active->tail.height_left = INT_MAX; + active->tail.dy = 0; + active->min_height = 0; + active->is_vertical = 1; +} + +static void +active_list_init(struct active_list *active) +{ + active_list_reset(active); +} + +/* + * Merge two sorted edge lists. + * Input: + * - head_a: The head of the first list. + * - head_b: The head of the second list; head_b cannot be NULL. + * Output: + * Returns the head of the merged list. + * + * Implementation notes: + * To make it fast (in particular, to reduce to an insertion sort whenever + * one of the two input lists only has a single element) we iterate through + * a list until its head becomes greater than the head of the other list, + * then we switch their roles. As soon as one of the two lists is empty, we + * just attach the other one to the current list and exit. + * Writes to memory are only needed to "switch" lists (as it also requires + * attaching to the output list the list which we will be iterating next) and + * to attach the last non-empty list. + */ +static struct edge * +merge_sorted_edges (struct edge *head_a, struct edge *head_b) +{ + struct edge *head, **next, *prev; + int32_t x; + + prev = head_a->prev; + next = &head; + if (head_a->cell <= head_b->cell) { + head = head_a; + } else { + head = head_b; + head_b->prev = prev; + goto start_with_b; + } + + do { + x = head_b->cell; + while (head_a != NULL && head_a->cell <= x) { + prev = head_a; + next = &head_a->next; + head_a = head_a->next; + } + + head_b->prev = prev; + *next = head_b; + if (head_a == NULL) + return head; + +start_with_b: + x = head_a->cell; + while (head_b != NULL && head_b->cell <= x) { + prev = head_b; + next = &head_b->next; + head_b = head_b->next; + } + + head_a->prev = prev; + *next = head_a; + if (head_b == NULL) + return head; + } while (1); +} + +/* + * Sort (part of) a list. + * Input: + * - list: The list to be sorted; list cannot be NULL. + * - limit: Recursion limit. + * Output: + * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the + * input list; if the input list has fewer elements, head_out be a sorted list + * containing all the elements of the input list. + * Returns the head of the list of unprocessed elements (NULL if the sorted list contains + * all the elements of the input list). + * + * Implementation notes: + * Special case single element list, unroll/inline the sorting of the first two elements. + * Some tail recursion is used since we iterate on the bottom-up solution of the problem + * (we start with a small sorted list and keep merging other lists of the same size to it). + */ +static struct edge * +sort_edges (struct edge *list, + unsigned int level, + struct edge **head_out) +{ + struct edge *head_other, *remaining; + unsigned int i; + + head_other = list->next; + + if (head_other == NULL) { + *head_out = list; + return NULL; + } + + remaining = head_other->next; + if (list->cell <= head_other->cell) { + *head_out = list; + head_other->next = NULL; + } else { + *head_out = head_other; + head_other->prev = list->prev; + head_other->next = list; + list->prev = head_other; + list->next = NULL; + } + + for (i = 0; i < level && remaining; i++) { + remaining = sort_edges (remaining, i, &head_other); + *head_out = merge_sorted_edges (*head_out, head_other); + } + + return remaining; +} + + static struct edge * +merge_unsorted_edges (struct edge *head, struct edge *unsorted) +{ + sort_edges (unsorted, UINT_MAX, &unsorted); + return merge_sorted_edges (head, unsorted); +} + +/* Test if the edges on the active list can be safely advanced by a + * full row without intersections or any edges ending. */ +inline static int +can_do_full_row (struct active_list *active) +{ + const struct edge *e; + int prev_x = INT_MIN; + + /* Recomputes the minimum height of all edges on the active + * list if we have been dropping edges. */ + if (active->min_height <= 0) { + int min_height = INT_MAX; + int is_vertical = 1; + + e = active->head.next; + while (NULL != e) { + if (e->height_left < min_height) + min_height = e->height_left; + is_vertical &= e->dy == 0; + e = e->next; + } + + active->is_vertical = is_vertical; + active->min_height = min_height; + } + + if (active->min_height < GRID_Y) + return 0; + + /* Check for intersections as no edges end during the next row. */ + for (e = active->head.next; e != &active->tail; e = e->next) { + int cell; + + if (e->dy) { + struct quorem x = e->x; + x.quo += e->dxdy_full.quo; + x.rem += e->dxdy_full.rem; + if (x.rem < 0) { + x.quo--; + x.rem += e->dy; + } else if (x.rem >= e->dy) { + x.quo++; + x.rem -= e->dy; + } + cell = x.quo + (x.rem >= e->dy/2); + } else + cell = e->cell; + + if (cell < prev_x) + return 0; + + prev_x = cell; + } + + return 1; +} + +/* Merges edges on the given subpixel row from the polygon to the + * active_list. */ +inline static void +active_list_merge_edges_from_bucket(struct active_list *active, + struct edge *edges) +{ + active->head.next = merge_unsorted_edges (active->head.next, edges); +} + +inline static int +polygon_fill_buckets (struct active_list *active, + struct edge *edge, + int y, + struct edge **buckets) +{ + grid_scaled_y_t min_height = active->min_height; + int is_vertical = active->is_vertical; + int max_suby = 0; + + while (edge) { + struct edge *next = edge->next; + int suby = edge->ytop - y; + if (buckets[suby]) + buckets[suby]->prev = edge; + edge->next = buckets[suby]; + edge->prev = NULL; + buckets[suby] = edge; + if (edge->height_left < min_height) + min_height = edge->height_left; + is_vertical &= edge->dy == 0; + edge = next; + if (suby > max_suby) + max_suby = suby; + } + + active->is_vertical = is_vertical; + active->min_height = min_height; + + return max_suby; +} + +static void step (struct edge *edge) +{ + if (edge->dy == 0) + return; + + edge->x.quo += edge->dxdy.quo; + edge->x.rem += edge->dxdy.rem; + if (edge->x.rem < 0) { + --edge->x.quo; + edge->x.rem += edge->dy; + } else if (edge->x.rem >= edge->dy) { + ++edge->x.quo; + edge->x.rem -= edge->dy; + } + + edge->cell = edge->x.quo + (edge->x.rem >= edge->dy/2); +} + +inline static void +sub_row (struct active_list *active, + struct cell_list *coverages, + unsigned int mask) +{ + struct edge *edge = active->head.next; + int xstart = INT_MIN, prev_x = INT_MIN; + int winding = 0; + + cell_list_rewind (coverages); + + while (&active->tail != edge) { + struct edge *next = edge->next; + int xend = edge->cell; + + if (--edge->height_left) { + step (edge); + + if (edge->cell < prev_x) { + struct edge *pos = edge->prev; + pos->next = next; + next->prev = pos; + do { + pos = pos->prev; + } while (edge->cell < pos->cell); + pos->next->prev = edge; + edge->next = pos->next; + edge->prev = pos; + pos->next = edge; + } else + prev_x = edge->cell; + active->min_height = -1; + } else { + edge->prev->next = next; + next->prev = edge->prev; + } + + winding += edge->dir; + if ((winding & mask) == 0) { + if (next->cell != xend) { + cell_list_add_subspan (coverages, xstart, xend); + xstart = INT_MIN; + } + } else if (xstart == INT_MIN) + xstart = xend; + + edge = next; + } +} + +inline static void dec (struct active_list *a, struct edge *e, int h) +{ + e->height_left -= h; + if (e->height_left == 0) { + e->prev->next = e->next; + e->next->prev = e->prev; + a->min_height = -1; + } +} + +static void +full_row (struct active_list *active, + struct cell_list *coverages, + unsigned int mask) +{ + struct edge *left = active->head.next; + + while (&active->tail != left) { + struct edge *right; + int winding; + + dec (active, left, GRID_Y); + + winding = left->dir; + right = left->next; + do { + dec (active, right, GRID_Y); + + winding += right->dir; + if ((winding & mask) == 0 && right->next->cell != right->cell) + break; + + full_step (right); + + right = right->next; + } while (1); + + cell_list_set_rewind (coverages); + cell_list_render_edge (coverages, left, +1); + cell_list_render_edge (coverages, right, -1); + + left = right->next; + } +} + +static void +_glitter_scan_converter_init(glitter_scan_converter_t *converter, jmp_buf *jmp) +{ + polygon_init(converter->polygon, jmp); + active_list_init(converter->active); + cell_list_init(converter->coverages, jmp); + converter->xmin=0; + converter->ymin=0; + converter->xmax=0; + converter->ymax=0; +} + +static void +_glitter_scan_converter_fini(glitter_scan_converter_t *self) +{ + if (self->spans != self->spans_embedded) + free (self->spans); + + polygon_fini(self->polygon); + cell_list_fini(self->coverages); + + self->xmin=0; + self->ymin=0; + self->xmax=0; + self->ymax=0; +} + +static grid_scaled_t +int_to_grid_scaled(int i, int scale) +{ + /* Clamp to max/min representable scaled number. */ + if (i >= 0) { + if (i >= INT_MAX/scale) + i = INT_MAX/scale; + } + else { + if (i <= INT_MIN/scale) + i = INT_MIN/scale; + } + return i*scale; +} + +#define int_to_grid_scaled_x(x) int_to_grid_scaled((x), GRID_X) +#define int_to_grid_scaled_y(x) int_to_grid_scaled((x), GRID_Y) + +I glitter_status_t +glitter_scan_converter_reset( + glitter_scan_converter_t *converter, + int xmin, int ymin, + int xmax, int ymax) +{ + glitter_status_t status; + int max_num_spans; + + converter->xmin = 0; converter->xmax = 0; + converter->ymin = 0; converter->ymax = 0; + + max_num_spans = xmax - xmin + 1; + + if (max_num_spans > ARRAY_LENGTH(converter->spans_embedded)) { + converter->spans = _cairo_malloc_ab (max_num_spans, + sizeof (cairo_half_open_span_t)); + if (unlikely (converter->spans == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + converter->spans = converter->spans_embedded; + + xmin = int_to_grid_scaled_x(xmin); + ymin = int_to_grid_scaled_y(ymin); + xmax = int_to_grid_scaled_x(xmax); + ymax = int_to_grid_scaled_y(ymax); + + active_list_reset(converter->active); + cell_list_reset(converter->coverages); + status = polygon_reset(converter->polygon, ymin, ymax); + if (status) + return status; + + converter->xmin = xmin; + converter->xmax = xmax; + converter->ymin = ymin; + converter->ymax = ymax; + return GLITTER_STATUS_SUCCESS; +} + +/* INPUT_TO_GRID_X/Y (in_coord, out_grid_scaled, grid_scale) + * These macros convert an input coordinate in the client's + * device space to the rasterisation grid. + */ +/* Gah.. this bit of ugly defines INPUT_TO_GRID_X/Y so as to use + * shifts if possible, and something saneish if not. + */ +#if !defined(INPUT_TO_GRID_Y) && defined(GRID_Y_BITS) && GRID_Y_BITS <= GLITTER_INPUT_BITS +# define INPUT_TO_GRID_Y(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_Y_BITS) +#else +# define INPUT_TO_GRID_Y(in, out) INPUT_TO_GRID_general(in, out, GRID_Y) +#endif + +#if !defined(INPUT_TO_GRID_X) && defined(GRID_X_BITS) && GRID_X_BITS <= GLITTER_INPUT_BITS +# define INPUT_TO_GRID_X(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_X_BITS) +#else +# define INPUT_TO_GRID_X(in, out) INPUT_TO_GRID_general(in, out, GRID_X) +#endif + +#define INPUT_TO_GRID_general(in, out, grid_scale) do { \ + long long tmp__ = (long long)(grid_scale) * (in); \ + tmp__ += 1 << (GLITTER_INPUT_BITS-1); \ + tmp__ >>= GLITTER_INPUT_BITS; \ + (out) = tmp__; \ +} while (0) + +inline static void +polygon_add_edge (struct polygon *polygon, + const cairo_edge_t *edge) +{ + struct edge *e; + grid_scaled_y_t ytop, ybot; + const cairo_point_t *p1, *p2; + + INPUT_TO_GRID_Y (edge->top, ytop); + if (ytop < polygon->ymin) + ytop = polygon->ymin; + + INPUT_TO_GRID_Y (edge->bottom, ybot); + if (ybot > polygon->ymax) + ybot = polygon->ymax; + + if (ybot <= ytop) + return; + + e = pool_alloc (polygon->edge_pool.base, sizeof (struct edge)); + + e->ytop = ytop; + e->height_left = ybot - ytop; + if (edge->line.p2.y > edge->line.p1.y) { + e->dir = edge->dir; + p1 = &edge->line.p1; + p2 = &edge->line.p2; + } else { + e->dir = -edge->dir; + p1 = &edge->line.p2; + p2 = &edge->line.p1; + } + + if (p2->x == p1->x) { + e->cell = p1->x; + e->x.quo = p1->x; + e->x.rem = 0; + e->dxdy.quo = e->dxdy.rem = 0; + e->dxdy_full.quo = e->dxdy_full.rem = 0; + e->dy = 0; + } else { + int64_t Ex, Ey, tmp; + + Ex = (int64_t)(p2->x - p1->x) * GRID_X; + Ey = (int64_t)(p2->y - p1->y) * GRID_Y * (2 << GLITTER_INPUT_BITS); + + e->dxdy.quo = Ex * (2 << GLITTER_INPUT_BITS) / Ey; + e->dxdy.rem = Ex * (2 << GLITTER_INPUT_BITS) % Ey; + + tmp = (int64_t)(2*ytop + 1) << GLITTER_INPUT_BITS; + tmp -= (int64_t)p1->y * GRID_Y * 2; + tmp *= Ex; + e->x.quo = tmp / Ey; + e->x.rem = tmp % Ey; + +#if GRID_X_BITS == GLITTER_INPUT_BITS + e->x.quo += p1->x; +#else + tmp = (int64_t)p1->x * GRID_X; + e->x.quo += tmp >> GLITTER_INPUT_BITS; + e->x.rem += ((tmp & ((1 << GLITTER_INPUT_BITS) - 1)) * Ey) / (1 << GLITTER_INPUT_BITS); +#endif + + if (e->x.rem < 0) { + e->x.quo--; + e->x.rem += Ey; + } else if (e->x.rem >= Ey) { + e->x.quo++; + e->x.rem -= Ey; + } + + if (e->height_left >= GRID_Y) { + tmp = Ex * (2 * GRID_Y << GLITTER_INPUT_BITS); + e->dxdy_full.quo = tmp / Ey; + e->dxdy_full.rem = tmp % Ey; + } else + e->dxdy_full.quo = e->dxdy_full.rem = 0; + + e->cell = e->x.quo + (e->x.rem >= Ey/2); + e->dy = Ey; + } + + _polygon_insert_edge_into_its_y_bucket (polygon, e); +} + +/* Add a new polygon edge from pixel (x1,y1) to (x2,y2) to the scan + * converter. The coordinates represent pixel positions scaled by + * 2**GLITTER_PIXEL_BITS. If this function fails then the scan + * converter should be reset or destroyed. Dir must be +1 or -1, + * with the latter reversing the orientation of the edge. */ +I void +glitter_scan_converter_add_edge (glitter_scan_converter_t *converter, + const cairo_edge_t *edge) +{ + polygon_add_edge (converter->polygon, edge); +} + +static void +step_edges (struct active_list *active, int count) +{ + struct edge *edge; + + count *= GRID_Y; + for (edge = active->head.next; edge != &active->tail; edge = edge->next) { + edge->height_left -= count; + if (! edge->height_left) { + edge->prev->next = edge->next; + edge->next->prev = edge->prev; + active->min_height = -1; + } + } +} + +static glitter_status_t +blit_a8 (struct cell_list *cells, + cairo_span_renderer_t *renderer, + cairo_half_open_span_t *spans, + int y, int height, + int xmin, int xmax) +{ + struct cell *cell = cells->head.next; + int prev_x = xmin, last_x = -1; + int16_t cover = 0, last_cover = 0; + unsigned num_spans; + + if (cell == &cells->tail) + return CAIRO_STATUS_SUCCESS; + + /* Skip cells to the left of the clip region. */ + while (cell->x < xmin) { + cover += cell->covered_height; + cell = cell->next; + } + cover *= GRID_X*2; + + /* Form the spans from the coverages and areas. */ + num_spans = 0; + for (; cell->x < xmax; cell = cell->next) { + int x = cell->x; + int16_t area; + + if (x > prev_x && cover != last_cover) { + spans[num_spans].x = prev_x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); + last_cover = cover; + last_x = prev_x; + ++num_spans; + } + + cover += cell->covered_height*GRID_X*2; + area = cover - cell->uncovered_area; + + if (area != last_cover) { + spans[num_spans].x = x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (area); + last_cover = area; + last_x = x; + ++num_spans; + } + + prev_x = x+1; + } + + if (prev_x <= xmax && cover != last_cover) { + spans[num_spans].x = prev_x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); + last_cover = cover; + last_x = prev_x; + ++num_spans; + } + + if (last_x < xmax && last_cover) { + spans[num_spans].x = xmax; + spans[num_spans].coverage = 0; + ++num_spans; + } + + /* Dump them into the renderer. */ + return renderer->render_rows (renderer, y, height, spans, num_spans); +} + +#define GRID_AREA_TO_A1(A) ((GRID_AREA_TO_ALPHA (A) > 127) ? 255 : 0) +static glitter_status_t +blit_a1 (struct cell_list *cells, + cairo_span_renderer_t *renderer, + cairo_half_open_span_t *spans, + int y, int height, + int xmin, int xmax) +{ + struct cell *cell = cells->head.next; + int prev_x = xmin, last_x = -1; + int16_t cover = 0; + uint8_t coverage, last_cover = 0; + unsigned num_spans; + + if (cell == &cells->tail) + return CAIRO_STATUS_SUCCESS; + + /* Skip cells to the left of the clip region. */ + while (cell->x < xmin) { + cover += cell->covered_height; + cell = cell->next; + } + cover *= GRID_X*2; + + /* Form the spans from the coverages and areas. */ + num_spans = 0; + for (; cell->x < xmax; cell = cell->next) { + int x = cell->x; + int16_t area; + + coverage = GRID_AREA_TO_A1 (cover); + if (x > prev_x && coverage != last_cover) { + last_x = spans[num_spans].x = prev_x; + last_cover = spans[num_spans].coverage = coverage; + ++num_spans; + } + + cover += cell->covered_height*GRID_X*2; + area = cover - cell->uncovered_area; + + coverage = GRID_AREA_TO_A1 (area); + if (coverage != last_cover) { + last_x = spans[num_spans].x = x; + last_cover = spans[num_spans].coverage = coverage; + ++num_spans; + } + + prev_x = x+1; + } + + coverage = GRID_AREA_TO_A1 (cover); + if (prev_x <= xmax && coverage != last_cover) { + last_x = spans[num_spans].x = prev_x; + last_cover = spans[num_spans].coverage = coverage; + ++num_spans; + } + + if (last_x < xmax && last_cover) { + spans[num_spans].x = xmax; + spans[num_spans].coverage = 0; + ++num_spans; + } + if (num_spans == 1) + return CAIRO_STATUS_SUCCESS; + + /* Dump them into the renderer. */ + return renderer->render_rows (renderer, y, height, spans, num_spans); +} + + +I void +glitter_scan_converter_render(glitter_scan_converter_t *converter, + unsigned int winding_mask, + int antialias, + cairo_span_renderer_t *renderer) +{ + int i, j; + int ymax_i = converter->ymax / GRID_Y; + int ymin_i = converter->ymin / GRID_Y; + int xmin_i, xmax_i; + int h = ymax_i - ymin_i; + struct polygon *polygon = converter->polygon; + struct cell_list *coverages = converter->coverages; + struct active_list *active = converter->active; + struct edge *buckets[GRID_Y] = { 0 }; + + xmin_i = converter->xmin / GRID_X; + xmax_i = converter->xmax / GRID_X; + if (xmin_i >= xmax_i) + return; + + /* Render each pixel row. */ + for (i = 0; i < h; i = j) { + int do_full_row = 0; + + j = i + 1; + + /* Determine if we can ignore this row or use the full pixel + * stepper. */ + if (polygon_fill_buckets (active, + polygon->y_buckets[i], + (i+ymin_i)*GRID_Y, + buckets) == 0) { + if (buckets[0]) { + active_list_merge_edges_from_bucket (active, buckets[0]); + buckets[0] = NULL; + } + + if (active->head.next == &active->tail) { + active->min_height = INT_MAX; + active->is_vertical = 1; + for (; j < h && ! polygon->y_buckets[j]; j++) + ; + continue; + } + + do_full_row = can_do_full_row (active); + } + + if (do_full_row) { + /* Step by a full pixel row's worth. */ + full_row (active, coverages, winding_mask); + + if (active->is_vertical) { + while (j < h && + polygon->y_buckets[j] == NULL && + active->min_height >= 2*GRID_Y) + { + active->min_height -= GRID_Y; + j++; + } + if (j != i + 1) + step_edges (active, j - (i + 1)); + } + } else { + int sub; + + /* Subsample this row. */ + for (sub = 0; sub < GRID_Y; sub++) { + if (buckets[sub]) { + active_list_merge_edges_from_bucket (active, buckets[sub]); + buckets[sub] = NULL; + } + sub_row (active, coverages, winding_mask); + } + } + + if (antialias) + blit_a8 (coverages, renderer, converter->spans, + i+ymin_i, j-i, xmin_i, xmax_i); + else + blit_a1 (coverages, renderer, converter->spans, + i+ymin_i, j-i, xmin_i, xmax_i); + cell_list_reset (coverages); + + active->min_height -= GRID_Y; + } +} + +struct _cairo_tor_scan_converter { + cairo_scan_converter_t base; + + glitter_scan_converter_t converter[1]; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + + jmp_buf jmp; +}; + +typedef struct _cairo_tor_scan_converter cairo_tor_scan_converter_t; + +static void +_cairo_tor_scan_converter_destroy (void *converter) +{ + cairo_tor_scan_converter_t *self = converter; + if (self == NULL) { + return; + } + _glitter_scan_converter_fini (self->converter); + free(self); +} + +cairo_status_t +_cairo_tor_scan_converter_add_polygon (void *converter, + const cairo_polygon_t *polygon) +{ + cairo_tor_scan_converter_t *self = converter; + int i; + +#if 0 + FILE *file = fopen ("polygon.txt", "w"); + _cairo_debug_print_polygon (file, polygon); + fclose (file); +#endif + + for (i = 0; i < polygon->num_edges; i++) + glitter_scan_converter_add_edge (self->converter, &polygon->edges[i]); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_tor_scan_converter_generate (void *converter, + cairo_span_renderer_t *renderer) +{ + cairo_tor_scan_converter_t *self = converter; + cairo_status_t status; + + if ((status = setjmp (self->jmp))) + return _cairo_scan_converter_set_error (self, _cairo_error (status)); + + glitter_scan_converter_render (self->converter, + self->fill_rule == CAIRO_FILL_RULE_WINDING ? ~0 : 1, + self->antialias != CAIRO_ANTIALIAS_NONE, + renderer); + return CAIRO_STATUS_SUCCESS; +} + +cairo_scan_converter_t * +_cairo_tor_scan_converter_create (int xmin, + int ymin, + int xmax, + int ymax, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias) +{ + cairo_tor_scan_converter_t *self; + cairo_status_t status; + + self = malloc (sizeof(struct _cairo_tor_scan_converter)); + if (unlikely (self == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto bail_nomem; + } + + self->base.destroy = _cairo_tor_scan_converter_destroy; + self->base.generate = _cairo_tor_scan_converter_generate; + + _glitter_scan_converter_init (self->converter, &self->jmp); + status = glitter_scan_converter_reset (self->converter, + xmin, ymin, xmax, ymax); + if (unlikely (status)) + goto bail; + + self->fill_rule = fill_rule; + self->antialias = antialias; + + return &self->base; + + bail: + self->base.destroy(&self->base); + bail_nomem: + return _cairo_scan_converter_create_in_error (status); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tor22-scan-converter.c b/Build/source/libs/cairo/cairo-src/src/cairo-tor22-scan-converter.c new file mode 100644 index 00000000000..4cec5ee4f37 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tor22-scan-converter.c @@ -0,0 +1,1709 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* glitter-paths - polygon scan converter + * + * Copyright (c) 2008 M Joonas Pihlaja + * Copyright (c) 2007 David Turner + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +/* This is the Glitter paths scan converter incorporated into cairo. + * The source is from commit 734c53237a867a773640bd5b64816249fa1730f8 + * of + * + * http://gitweb.freedesktop.org/?p=users/joonas/glitter-paths + */ +/* Glitter-paths is a stand alone polygon rasteriser derived from + * David Turner's reimplementation of Tor Anderssons's 15x17 + * supersampling rasteriser from the Apparition graphics library. The + * main new feature here is cheaply choosing per-scan line between + * doing fully analytical coverage computation for an entire row at a + * time vs. using a supersampling approach. + * + * David Turner's code can be found at + * + * http://david.freetype.org/rasterizer-shootout/raster-comparison-20070813.tar.bz2 + * + * In particular this file incorporates large parts of ftgrays_tor10.h + * from raster-comparison-20070813.tar.bz2 + */ +/* Overview + * + * A scan converter's basic purpose to take polygon edges and convert + * them into an RLE compressed A8 mask. This one works in two phases: + * gathering edges and generating spans. + * + * 1) As the user feeds the scan converter edges they are vertically + * clipped and bucketted into a _polygon_ data structure. The edges + * are also snapped from the user's coordinates to the subpixel grid + * coordinates used during scan conversion. + * + * user + * | + * | edges + * V + * polygon buckets + * + * 2) Generating spans works by performing a vertical sweep of pixel + * rows from top to bottom and maintaining an _active_list_ of edges + * that intersect the row. From the active list the fill rule + * determines which edges are the left and right edges of the start of + * each span, and their contribution is then accumulated into a pixel + * coverage list (_cell_list_) as coverage deltas. Once the coverage + * deltas of all edges are known we can form spans of constant pixel + * coverage by summing the deltas during a traversal of the cell list. + * At the end of a pixel row the cell list is sent to a coverage + * blitter for rendering to some target surface. + * + * The pixel coverages are computed by either supersampling the row + * and box filtering a mono rasterisation, or by computing the exact + * coverages of edges in the active list. The supersampling method is + * used whenever some edge starts or stops within the row or there are + * edge intersections in the row. + * + * polygon bucket for \ + * current pixel row | + * | | + * | activate new edges | Repeat GRID_Y times if we + * V \ are supersampling this row, + * active list / or just once if we're computing + * | | analytical coverage. + * | coverage deltas | + * V | + * pixel coverage list / + * | + * V + * coverage blitter + */ +#include "cairoint.h" +#include "cairo-spans-private.h" +#include "cairo-error-private.h" + +#include +#include +#include +#include + +/*------------------------------------------------------------------------- + * cairo specific config + */ +#define I static + +/* Prefer cairo's status type. */ +#define GLITTER_HAVE_STATUS_T 1 +#define GLITTER_STATUS_SUCCESS CAIRO_STATUS_SUCCESS +#define GLITTER_STATUS_NO_MEMORY CAIRO_STATUS_NO_MEMORY +typedef cairo_status_t glitter_status_t; + +/* The input coordinate scale and the rasterisation grid scales. */ +#define GLITTER_INPUT_BITS CAIRO_FIXED_FRAC_BITS +//#define GRID_X_BITS CAIRO_FIXED_FRAC_BITS +//#define GRID_Y 15 +#define GRID_X_BITS 2 +#define GRID_Y_BITS 2 + +/* Set glitter up to use a cairo span renderer to do the coverage + * blitting. */ +struct pool; +struct cell_list; + +/*------------------------------------------------------------------------- + * glitter-paths.h + */ + +/* "Input scaled" numbers are fixed precision reals with multiplier + * 2**GLITTER_INPUT_BITS. Input coordinates are given to glitter as + * pixel scaled numbers. These get converted to the internal grid + * scaled numbers as soon as possible. Internal overflow is possible + * if GRID_X/Y inside glitter-paths.c is larger than + * 1< +#include +#include + +/* All polygon coordinates are snapped onto a subsample grid. "Grid + * scaled" numbers are fixed precision reals with multiplier GRID_X or + * GRID_Y. */ +typedef int grid_scaled_t; +typedef int grid_scaled_x_t; +typedef int grid_scaled_y_t; + +/* Default x/y scale factors. + * You can either define GRID_X/Y_BITS to get a power-of-two scale + * or define GRID_X/Y separately. */ +#if !defined(GRID_X) && !defined(GRID_X_BITS) +# define GRID_X_BITS 8 +#endif +#if !defined(GRID_Y) && !defined(GRID_Y_BITS) +# define GRID_Y 15 +#endif + +/* Use GRID_X/Y_BITS to define GRID_X/Y if they're available. */ +#ifdef GRID_X_BITS +# define GRID_X (1 << GRID_X_BITS) +#endif +#ifdef GRID_Y_BITS +# define GRID_Y (1 << GRID_Y_BITS) +#endif + +/* The GRID_X_TO_INT_FRAC macro splits a grid scaled coordinate into + * integer and fractional parts. The integer part is floored. */ +#if defined(GRID_X_TO_INT_FRAC) + /* do nothing */ +#elif defined(GRID_X_BITS) +# define GRID_X_TO_INT_FRAC(x, i, f) \ + _GRID_TO_INT_FRAC_shift(x, i, f, GRID_X_BITS) +#else +# define GRID_X_TO_INT_FRAC(x, i, f) \ + _GRID_TO_INT_FRAC_general(x, i, f, GRID_X) +#endif + +#define _GRID_TO_INT_FRAC_general(t, i, f, m) do { \ + (i) = (t) / (m); \ + (f) = (t) % (m); \ + if ((f) < 0) { \ + --(i); \ + (f) += (m); \ + } \ +} while (0) + +#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do { \ + (f) = (t) & ((1 << (b)) - 1); \ + (i) = (t) >> (b); \ +} while (0) + +/* A grid area is a real in [0,1] scaled by 2*GRID_X*GRID_Y. We want + * to be able to represent exactly areas of subpixel trapezoids whose + * vertices are given in grid scaled coordinates. The scale factor + * comes from needing to accurately represent the area 0.5*dx*dy of a + * triangle with base dx and height dy in grid scaled numbers. */ +#define GRID_XY (2*GRID_X*GRID_Y) /* Unit area on the grid. */ + +/* GRID_AREA_TO_ALPHA(area): map [0,GRID_XY] to [0,255]. */ +#if GRID_XY == 510 +# define GRID_AREA_TO_ALPHA(c) (((c)+1) >> 1) +#elif GRID_XY == 255 +# define GRID_AREA_TO_ALPHA(c) (c) +#elif GRID_XY == 64 +# define GRID_AREA_TO_ALPHA(c) (((c) << 2) | -(((c) & 0x40) >> 6)) +#elif GRID_XY == 32 +# define GRID_AREA_TO_ALPHA(c) (((c) << 3) | -(((c) & 0x20) >> 5)) +#elif GRID_XY == 128 +# define GRID_AREA_TO_ALPHA(c) ((((c) << 1) | -((c) >> 7)) & 255) +#elif GRID_XY == 256 +# define GRID_AREA_TO_ALPHA(c) (((c) | -((c) >> 8)) & 255) +#elif GRID_XY == 15 +# define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) +#elif GRID_XY == 2*256*15 +# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) +#else +# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) +#endif + +#define UNROLL3(x) x x x + +struct quorem { + int32_t quo; + int32_t rem; +}; + +/* Header for a chunk of memory in a memory pool. */ +struct _pool_chunk { + /* # bytes used in this chunk. */ + size_t size; + + /* # bytes total in this chunk */ + size_t capacity; + + /* Pointer to the previous chunk or %NULL if this is the sentinel + * chunk in the pool header. */ + struct _pool_chunk *prev_chunk; + + /* Actual data starts here. Well aligned for pointers. */ +}; + +/* A memory pool. This is supposed to be embedded on the stack or + * within some other structure. It may optionally be followed by an + * embedded array from which requests are fulfilled until + * malloc needs to be called to allocate a first real chunk. */ +struct pool { + /* Chunk we're allocating from. */ + struct _pool_chunk *current; + + jmp_buf *jmp; + + /* Free list of previously allocated chunks. All have >= default + * capacity. */ + struct _pool_chunk *first_free; + + /* The default capacity of a chunk. */ + size_t default_capacity; + + /* Header for the sentinel chunk. Directly following the pool + * struct should be some space for embedded elements from which + * the sentinel chunk allocates from. */ + struct _pool_chunk sentinel[1]; +}; + +/* A polygon edge. */ +struct edge { + /* Next in y-bucket or active list. */ + struct edge *next, *prev; + + /* Number of subsample rows remaining to scan convert of this + * edge. */ + grid_scaled_y_t height_left; + + /* Original sign of the edge: +1 for downwards, -1 for upwards + * edges. */ + int dir; + int vertical; + + /* Current x coordinate while the edge is on the active + * list. Initialised to the x coordinate of the top of the + * edge. The quotient is in grid_scaled_x_t units and the + * remainder is mod dy in grid_scaled_y_t units.*/ + struct quorem x; + + /* Advance of the current x when moving down a subsample line. */ + struct quorem dxdy; + + /* The clipped y of the top of the edge. */ + grid_scaled_y_t ytop; + + /* y2-y1 after orienting the edge downwards. */ + grid_scaled_y_t dy; +}; + +#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/GRID_Y) + +/* A collection of sorted and vertically clipped edges of the polygon. + * Edges are moved from the polygon to an active list while scan + * converting. */ +struct polygon { + /* The vertical clip extents. */ + grid_scaled_y_t ymin, ymax; + + /* Array of edges all starting in the same bucket. An edge is put + * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when + * it is added to the polygon. */ + struct edge **y_buckets; + struct edge *y_buckets_embedded[64]; + + struct { + struct pool base[1]; + struct edge embedded[32]; + } edge_pool; +}; + +/* A cell records the effect on pixel coverage of polygon edges + * passing through a pixel. It contains two accumulators of pixel + * coverage. + * + * Consider the effects of a polygon edge on the coverage of a pixel + * it intersects and that of the following one. The coverage of the + * following pixel is the height of the edge multiplied by the width + * of the pixel, and the coverage of the pixel itself is the area of + * the trapezoid formed by the edge and the right side of the pixel. + * + * +-----------------------+-----------------------+ + * | | | + * | | | + * |_______________________|_______________________| + * | \...................|.......................|\ + * | \..................|.......................| | + * | \.................|.......................| | + * | \....covered.....|.......................| | + * | \....area.......|.......................| } covered height + * | \..............|.......................| | + * |uncovered\.............|.......................| | + * | area \............|.......................| | + * |___________\...........|.......................|/ + * | | | + * | | | + * | | | + * +-----------------------+-----------------------+ + * + * Since the coverage of the following pixel will always be a multiple + * of the width of the pixel, we can store the height of the covered + * area instead. The coverage of the pixel itself is the total + * coverage minus the area of the uncovered area to the left of the + * edge. As it's faster to compute the uncovered area we only store + * that and subtract it from the total coverage later when forming + * spans to blit. + * + * The heights and areas are signed, with left edges of the polygon + * having positive sign and right edges having negative sign. When + * two edges intersect they swap their left/rightness so their + * contribution above and below the intersection point must be + * computed separately. */ +struct cell { + struct cell *next; + int x; + int16_t uncovered_area; + int16_t covered_height; +}; + +/* A cell list represents the scan line sparsely as cells ordered by + * ascending x. It is geared towards scanning the cells in order + * using an internal cursor. */ +struct cell_list { + /* Sentinel nodes */ + struct cell head, tail; + + /* Cursor state for iterating through the cell list. */ + struct cell *cursor, *rewind; + + /* Cells in the cell list are owned by the cell list and are + * allocated from this pool. */ + struct { + struct pool base[1]; + struct cell embedded[32]; + } cell_pool; +}; + +struct cell_pair { + struct cell *cell1; + struct cell *cell2; +}; + +/* The active list contains edges in the current scan line ordered by + * the x-coordinate of the intercept of the edge and the scan line. */ +struct active_list { + /* Leftmost edge on the current scan line. */ + struct edge head, tail; + + /* A lower bound on the height of the active edges is used to + * estimate how soon some active edge ends. We can't advance the + * scan conversion by a full pixel row if an edge ends somewhere + * within it. */ + grid_scaled_y_t min_height; + int is_vertical; +}; + +struct glitter_scan_converter { + struct polygon polygon[1]; + struct active_list active[1]; + struct cell_list coverages[1]; + + cairo_half_open_span_t *spans; + cairo_half_open_span_t spans_embedded[64]; + + /* Clip box. */ + grid_scaled_x_t xmin, xmax; + grid_scaled_y_t ymin, ymax; +}; + +/* Compute the floored division a/b. Assumes / and % perform symmetric + * division. */ +inline static struct quorem +floored_divrem(int a, int b) +{ + struct quorem qr; + qr.quo = a/b; + qr.rem = a%b; + if ((a^b)<0 && qr.rem) { + qr.quo -= 1; + qr.rem += b; + } + return qr; +} + +/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric + * division. */ +static struct quorem +floored_muldivrem(int x, int a, int b) +{ + struct quorem qr; + long long xa = (long long)x*a; + qr.quo = xa/b; + qr.rem = xa%b; + if ((xa>=0) != (b>=0) && qr.rem) { + qr.quo -= 1; + qr.rem += b; + } + return qr; +} + +static struct _pool_chunk * +_pool_chunk_init( + struct _pool_chunk *p, + struct _pool_chunk *prev_chunk, + size_t capacity) +{ + p->prev_chunk = prev_chunk; + p->size = 0; + p->capacity = capacity; + return p; +} + +static struct _pool_chunk * +_pool_chunk_create(struct pool *pool, size_t size) +{ + struct _pool_chunk *p; + + p = malloc(size + sizeof(struct _pool_chunk)); + if (unlikely (NULL == p)) + longjmp (*pool->jmp, _cairo_error (CAIRO_STATUS_NO_MEMORY)); + + return _pool_chunk_init(p, pool->current, size); +} + +static void +pool_init(struct pool *pool, + jmp_buf *jmp, + size_t default_capacity, + size_t embedded_capacity) +{ + pool->jmp = jmp; + pool->current = pool->sentinel; + pool->first_free = NULL; + pool->default_capacity = default_capacity; + _pool_chunk_init(pool->sentinel, NULL, embedded_capacity); +} + +static void +pool_fini(struct pool *pool) +{ + struct _pool_chunk *p = pool->current; + do { + while (NULL != p) { + struct _pool_chunk *prev = p->prev_chunk; + if (p != pool->sentinel) + free(p); + p = prev; + } + p = pool->first_free; + pool->first_free = NULL; + } while (NULL != p); +} + +/* Satisfy an allocation by first allocating a new large enough chunk + * and adding it to the head of the pool's chunk list. This function + * is called as a fallback if pool_alloc() couldn't do a quick + * allocation from the current chunk in the pool. */ +static void * +_pool_alloc_from_new_chunk( + struct pool *pool, + size_t size) +{ + struct _pool_chunk *chunk; + void *obj; + size_t capacity; + + /* If the allocation is smaller than the default chunk size then + * try getting a chunk off the free list. Force alloc of a new + * chunk for large requests. */ + capacity = size; + chunk = NULL; + if (size < pool->default_capacity) { + capacity = pool->default_capacity; + chunk = pool->first_free; + if (chunk) { + pool->first_free = chunk->prev_chunk; + _pool_chunk_init(chunk, pool->current, chunk->capacity); + } + } + + if (NULL == chunk) + chunk = _pool_chunk_create (pool, capacity); + pool->current = chunk; + + obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); + chunk->size += size; + return obj; +} + +/* Allocate size bytes from the pool. The first allocated address + * returned from a pool is aligned to sizeof(void*). Subsequent + * addresses will maintain alignment as long as multiples of void* are + * allocated. Returns the address of a new memory area or %NULL on + * allocation failures. The pool retains ownership of the returned + * memory. */ +inline static void * +pool_alloc (struct pool *pool, size_t size) +{ + struct _pool_chunk *chunk = pool->current; + + if (size <= chunk->capacity - chunk->size) { + void *obj = ((unsigned char*)chunk + sizeof(*chunk) + chunk->size); + chunk->size += size; + return obj; + } else { + return _pool_alloc_from_new_chunk(pool, size); + } +} + +/* Relinquish all pool_alloced memory back to the pool. */ +static void +pool_reset (struct pool *pool) +{ + /* Transfer all used chunks to the chunk free list. */ + struct _pool_chunk *chunk = pool->current; + if (chunk != pool->sentinel) { + while (chunk->prev_chunk != pool->sentinel) { + chunk = chunk->prev_chunk; + } + chunk->prev_chunk = pool->first_free; + pool->first_free = pool->current; + } + /* Reset the sentinel as the current chunk. */ + pool->current = pool->sentinel; + pool->sentinel->size = 0; +} + +/* Rewinds the cell list's cursor to the beginning. After rewinding + * we're good to cell_list_find() the cell any x coordinate. */ +inline static void +cell_list_rewind (struct cell_list *cells) +{ + cells->cursor = &cells->head; +} + +inline static void +cell_list_maybe_rewind (struct cell_list *cells, int x) +{ + if (x < cells->cursor->x) { + cells->cursor = cells->rewind; + if (x < cells->cursor->x) + cells->cursor = &cells->head; + } +} + +inline static void +cell_list_set_rewind (struct cell_list *cells) +{ + cells->rewind = cells->cursor; +} + +static void +cell_list_init(struct cell_list *cells, jmp_buf *jmp) +{ + pool_init(cells->cell_pool.base, jmp, + 256*sizeof(struct cell), + sizeof(cells->cell_pool.embedded)); + cells->tail.next = NULL; + cells->tail.x = INT_MAX; + cells->head.x = INT_MIN; + cells->head.next = &cells->tail; + cell_list_rewind (cells); +} + +static void +cell_list_fini(struct cell_list *cells) +{ + pool_fini (cells->cell_pool.base); +} + +/* Empty the cell list. This is called at the start of every pixel + * row. */ +inline static void +cell_list_reset (struct cell_list *cells) +{ + cell_list_rewind (cells); + cells->head.next = &cells->tail; + pool_reset (cells->cell_pool.base); +} + +inline static struct cell * +cell_list_alloc (struct cell_list *cells, + struct cell *tail, + int x) +{ + struct cell *cell; + + cell = pool_alloc (cells->cell_pool.base, sizeof (struct cell)); + cell->next = tail->next; + tail->next = cell; + cell->x = x; + *(uint32_t *)&cell->uncovered_area = 0; + + return cell; +} + +/* Find a cell at the given x-coordinate. Returns %NULL if a new cell + * needed to be allocated but couldn't be. Cells must be found with + * non-decreasing x-coordinate until the cell list is rewound using + * cell_list_rewind(). Ownership of the returned cell is retained by + * the cell list. */ +inline static struct cell * +cell_list_find (struct cell_list *cells, int x) +{ + struct cell *tail = cells->cursor; + + if (tail->x == x) + return tail; + + while (1) { + UNROLL3({ + if (tail->next->x > x) + break; + tail = tail->next; + }); + } + + if (tail->x != x) + tail = cell_list_alloc (cells, tail, x); + return cells->cursor = tail; + +} + +/* Find two cells at x1 and x2. This is exactly equivalent + * to + * + * pair.cell1 = cell_list_find(cells, x1); + * pair.cell2 = cell_list_find(cells, x2); + * + * except with less function call overhead. */ +inline static struct cell_pair +cell_list_find_pair(struct cell_list *cells, int x1, int x2) +{ + struct cell_pair pair; + + pair.cell1 = cells->cursor; + while (1) { + UNROLL3({ + if (pair.cell1->next->x > x1) + break; + pair.cell1 = pair.cell1->next; + }); + } + if (pair.cell1->x != x1) + pair.cell1 = cell_list_alloc (cells, pair.cell1, x1); + + pair.cell2 = pair.cell1; + while (1) { + UNROLL3({ + if (pair.cell2->next->x > x2) + break; + pair.cell2 = pair.cell2->next; + }); + } + if (pair.cell2->x != x2) + pair.cell2 = cell_list_alloc (cells, pair.cell2, x2); + + cells->cursor = pair.cell2; + return pair; +} + +/* Add a subpixel span covering [x1, x2) to the coverage cells. */ +inline static void +cell_list_add_subspan(struct cell_list *cells, + grid_scaled_x_t x1, + grid_scaled_x_t x2) +{ + int ix1, fx1; + int ix2, fx2; + + if (x1 == x2) + return; + + GRID_X_TO_INT_FRAC(x1, ix1, fx1); + GRID_X_TO_INT_FRAC(x2, ix2, fx2); + + if (ix1 != ix2) { + struct cell_pair p; + p = cell_list_find_pair(cells, ix1, ix2); + p.cell1->uncovered_area += 2*fx1; + ++p.cell1->covered_height; + p.cell2->uncovered_area -= 2*fx2; + --p.cell2->covered_height; + } else { + struct cell *cell = cell_list_find(cells, ix1); + cell->uncovered_area += 2*(fx1-fx2); + } +} + +/* Adds the analytical coverage of an edge crossing the current pixel + * row to the coverage cells and advances the edge's x position to the + * following row. + * + * This function is only called when we know that during this pixel row: + * + * 1) The relative order of all edges on the active list doesn't + * change. In particular, no edges intersect within this row to pixel + * precision. + * + * 2) No new edges start in this row. + * + * 3) No existing edges end mid-row. + * + * This function depends on being called with all edges from the + * active list in the order they appear on the list (i.e. with + * non-decreasing x-coordinate.) */ +static void +cell_list_render_edge(struct cell_list *cells, + struct edge *edge, + int sign) +{ + grid_scaled_x_t fx; + struct cell *cell; + int ix; + + GRID_X_TO_INT_FRAC(edge->x.quo, ix, fx); + + /* We always know that ix1 is >= the cell list cursor in this + * case due to the no-intersections precondition. */ + cell = cell_list_find(cells, ix); + cell->covered_height += sign*GRID_Y; + cell->uncovered_area += sign*2*fx*GRID_Y; +} + +static void +polygon_init (struct polygon *polygon, jmp_buf *jmp) +{ + polygon->ymin = polygon->ymax = 0; + polygon->y_buckets = polygon->y_buckets_embedded; + pool_init (polygon->edge_pool.base, jmp, + 8192 - sizeof (struct _pool_chunk), + sizeof (polygon->edge_pool.embedded)); +} + +static void +polygon_fini (struct polygon *polygon) +{ + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + pool_fini (polygon->edge_pool.base); +} + +/* Empties the polygon of all edges. The polygon is then prepared to + * receive new edges and clip them to the vertical range + * [ymin,ymax). */ +static glitter_status_t +polygon_reset (struct polygon *polygon, + grid_scaled_y_t ymin, + grid_scaled_y_t ymax) +{ + unsigned h = ymax - ymin; + unsigned num_buckets = EDGE_Y_BUCKET_INDEX(ymax + GRID_Y-1, ymin); + + pool_reset(polygon->edge_pool.base); + + if (unlikely (h > 0x7FFFFFFFU - GRID_Y)) + goto bail_no_mem; /* even if you could, you wouldn't want to. */ + + if (polygon->y_buckets != polygon->y_buckets_embedded) + free (polygon->y_buckets); + + polygon->y_buckets = polygon->y_buckets_embedded; + if (num_buckets > ARRAY_LENGTH (polygon->y_buckets_embedded)) { + polygon->y_buckets = _cairo_malloc_ab (num_buckets, + sizeof (struct edge *)); + if (unlikely (NULL == polygon->y_buckets)) + goto bail_no_mem; + } + memset (polygon->y_buckets, 0, num_buckets * sizeof (struct edge *)); + + polygon->ymin = ymin; + polygon->ymax = ymax; + return GLITTER_STATUS_SUCCESS; + +bail_no_mem: + polygon->ymin = 0; + polygon->ymax = 0; + return GLITTER_STATUS_NO_MEMORY; +} + +static void +_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, + struct edge *e) +{ + unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin); + struct edge **ptail = &polygon->y_buckets[ix]; + e->next = *ptail; + *ptail = e; +} + +inline static void +polygon_add_edge (struct polygon *polygon, + const cairo_edge_t *edge) +{ + struct edge *e; + grid_scaled_x_t dx; + grid_scaled_y_t dy; + grid_scaled_y_t ytop, ybot; + grid_scaled_y_t ymin = polygon->ymin; + grid_scaled_y_t ymax = polygon->ymax; + + if (unlikely (edge->top >= ymax || edge->bottom <= ymin)) + return; + + e = pool_alloc (polygon->edge_pool.base, sizeof (struct edge)); + + dx = edge->line.p2.x - edge->line.p1.x; + dy = edge->line.p2.y - edge->line.p1.y; + e->dy = dy; + e->dir = edge->dir; + + ytop = edge->top >= ymin ? edge->top : ymin; + ybot = edge->bottom <= ymax ? edge->bottom : ymax; + e->ytop = ytop; + e->height_left = ybot - ytop; + + if (dx == 0) { + e->vertical = TRUE; + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + e->dxdy.quo = 0; + e->dxdy.rem = 0; + } else { + e->vertical = FALSE; + e->dxdy = floored_divrem (dx, dy); + if (ytop == edge->line.p1.y) { + e->x.quo = edge->line.p1.x; + e->x.rem = 0; + } else { + e->x = floored_muldivrem (ytop - edge->line.p1.y, dx, dy); + e->x.quo += edge->line.p1.x; + } + } + + _polygon_insert_edge_into_its_y_bucket (polygon, e); + + e->x.rem -= dy; /* Bias the remainder for faster + * edge advancement. */ +} + +static void +active_list_reset (struct active_list *active) +{ + active->head.vertical = 1; + active->head.height_left = INT_MAX; + active->head.x.quo = INT_MIN; + active->head.prev = NULL; + active->head.next = &active->tail; + active->tail.prev = &active->head; + active->tail.next = NULL; + active->tail.x.quo = INT_MAX; + active->tail.height_left = INT_MAX; + active->tail.vertical = 1; + active->min_height = 0; + active->is_vertical = 1; +} + +static void +active_list_init(struct active_list *active) +{ + active_list_reset(active); +} + +/* + * Merge two sorted edge lists. + * Input: + * - head_a: The head of the first list. + * - head_b: The head of the second list; head_b cannot be NULL. + * Output: + * Returns the head of the merged list. + * + * Implementation notes: + * To make it fast (in particular, to reduce to an insertion sort whenever + * one of the two input lists only has a single element) we iterate through + * a list until its head becomes greater than the head of the other list, + * then we switch their roles. As soon as one of the two lists is empty, we + * just attach the other one to the current list and exit. + * Writes to memory are only needed to "switch" lists (as it also requires + * attaching to the output list the list which we will be iterating next) and + * to attach the last non-empty list. + */ +static struct edge * +merge_sorted_edges (struct edge *head_a, struct edge *head_b) +{ + struct edge *head, **next, *prev; + int32_t x; + + prev = head_a->prev; + next = &head; + if (head_a->x.quo <= head_b->x.quo) { + head = head_a; + } else { + head = head_b; + head_b->prev = prev; + goto start_with_b; + } + + do { + x = head_b->x.quo; + while (head_a != NULL && head_a->x.quo <= x) { + prev = head_a; + next = &head_a->next; + head_a = head_a->next; + } + + head_b->prev = prev; + *next = head_b; + if (head_a == NULL) + return head; + +start_with_b: + x = head_a->x.quo; + while (head_b != NULL && head_b->x.quo <= x) { + prev = head_b; + next = &head_b->next; + head_b = head_b->next; + } + + head_a->prev = prev; + *next = head_a; + if (head_b == NULL) + return head; + } while (1); +} + +/* + * Sort (part of) a list. + * Input: + * - list: The list to be sorted; list cannot be NULL. + * - limit: Recursion limit. + * Output: + * - head_out: The head of the sorted list containing the first 2^(level+1) elements of the + * input list; if the input list has fewer elements, head_out be a sorted list + * containing all the elements of the input list. + * Returns the head of the list of unprocessed elements (NULL if the sorted list contains + * all the elements of the input list). + * + * Implementation notes: + * Special case single element list, unroll/inline the sorting of the first two elements. + * Some tail recursion is used since we iterate on the bottom-up solution of the problem + * (we start with a small sorted list and keep merging other lists of the same size to it). + */ +static struct edge * +sort_edges (struct edge *list, + unsigned int level, + struct edge **head_out) +{ + struct edge *head_other, *remaining; + unsigned int i; + + head_other = list->next; + + if (head_other == NULL) { + *head_out = list; + return NULL; + } + + remaining = head_other->next; + if (list->x.quo <= head_other->x.quo) { + *head_out = list; + head_other->next = NULL; + } else { + *head_out = head_other; + head_other->prev = list->prev; + head_other->next = list; + list->prev = head_other; + list->next = NULL; + } + + for (i = 0; i < level && remaining; i++) { + remaining = sort_edges (remaining, i, &head_other); + *head_out = merge_sorted_edges (*head_out, head_other); + } + + return remaining; +} + +static struct edge * +merge_unsorted_edges (struct edge *head, struct edge *unsorted) +{ + sort_edges (unsorted, UINT_MAX, &unsorted); + return merge_sorted_edges (head, unsorted); +} + +/* Test if the edges on the active list can be safely advanced by a + * full row without intersections or any edges ending. */ +inline static int +can_do_full_row (struct active_list *active) +{ + const struct edge *e; + + /* Recomputes the minimum height of all edges on the active + * list if we have been dropping edges. */ + if (active->min_height <= 0) { + int min_height = INT_MAX; + int is_vertical = 1; + + e = active->head.next; + while (NULL != e) { + if (e->height_left < min_height) + min_height = e->height_left; + is_vertical &= e->vertical; + e = e->next; + } + + active->is_vertical = is_vertical; + active->min_height = min_height; + } + + if (active->min_height < GRID_Y) + return 0; + + return active->is_vertical; +} + +/* Merges edges on the given subpixel row from the polygon to the + * active_list. */ +inline static void +active_list_merge_edges_from_bucket(struct active_list *active, + struct edge *edges) +{ + active->head.next = merge_unsorted_edges (active->head.next, edges); +} + +inline static void +polygon_fill_buckets (struct active_list *active, + struct edge *edge, + int y, + struct edge **buckets) +{ + grid_scaled_y_t min_height = active->min_height; + int is_vertical = active->is_vertical; + + while (edge) { + struct edge *next = edge->next; + int suby = edge->ytop - y; + if (buckets[suby]) + buckets[suby]->prev = edge; + edge->next = buckets[suby]; + edge->prev = NULL; + buckets[suby] = edge; + if (edge->height_left < min_height) + min_height = edge->height_left; + is_vertical &= edge->vertical; + edge = next; + } + + active->is_vertical = is_vertical; + active->min_height = min_height; +} + +inline static void +sub_row (struct active_list *active, + struct cell_list *coverages, + unsigned int mask) +{ + struct edge *edge = active->head.next; + int xstart = INT_MIN, prev_x = INT_MIN; + int winding = 0; + + cell_list_rewind (coverages); + + while (&active->tail != edge) { + struct edge *next = edge->next; + int xend = edge->x.quo; + + if (--edge->height_left) { + edge->x.quo += edge->dxdy.quo; + edge->x.rem += edge->dxdy.rem; + if (edge->x.rem >= 0) { + ++edge->x.quo; + edge->x.rem -= edge->dy; + } + + if (edge->x.quo < prev_x) { + struct edge *pos = edge->prev; + pos->next = next; + next->prev = pos; + do { + pos = pos->prev; + } while (edge->x.quo < pos->x.quo); + pos->next->prev = edge; + edge->next = pos->next; + edge->prev = pos; + pos->next = edge; + } else + prev_x = edge->x.quo; + } else { + edge->prev->next = next; + next->prev = edge->prev; + } + + winding += edge->dir; + if ((winding & mask) == 0) { + if (next->x.quo != xend) { + cell_list_add_subspan (coverages, xstart, xend); + xstart = INT_MIN; + } + } else if (xstart == INT_MIN) + xstart = xend; + + edge = next; + } +} + +inline static void dec (struct edge *e, int h) +{ + e->height_left -= h; + if (e->height_left == 0) { + e->prev->next = e->next; + e->next->prev = e->prev; + } +} + +static void +full_row (struct active_list *active, + struct cell_list *coverages, + unsigned int mask) +{ + struct edge *left = active->head.next; + + while (&active->tail != left) { + struct edge *right; + int winding; + + dec (left, GRID_Y); + + winding = left->dir; + right = left->next; + do { + dec (right, GRID_Y); + + winding += right->dir; + if ((winding & mask) == 0 && right->next->x.quo != right->x.quo) + break; + + right = right->next; + } while (1); + + cell_list_set_rewind (coverages); + cell_list_render_edge (coverages, left, +1); + cell_list_render_edge (coverages, right, -1); + + left = right->next; + } +} + +static void +_glitter_scan_converter_init(glitter_scan_converter_t *converter, jmp_buf *jmp) +{ + polygon_init(converter->polygon, jmp); + active_list_init(converter->active); + cell_list_init(converter->coverages, jmp); + converter->xmin=0; + converter->ymin=0; + converter->xmax=0; + converter->ymax=0; +} + +static void +_glitter_scan_converter_fini(glitter_scan_converter_t *self) +{ + if (self->spans != self->spans_embedded) + free (self->spans); + + polygon_fini(self->polygon); + cell_list_fini(self->coverages); + + self->xmin=0; + self->ymin=0; + self->xmax=0; + self->ymax=0; +} + +static grid_scaled_t +int_to_grid_scaled(int i, int scale) +{ + /* Clamp to max/min representable scaled number. */ + if (i >= 0) { + if (i >= INT_MAX/scale) + i = INT_MAX/scale; + } + else { + if (i <= INT_MIN/scale) + i = INT_MIN/scale; + } + return i*scale; +} + +#define int_to_grid_scaled_x(x) int_to_grid_scaled((x), GRID_X) +#define int_to_grid_scaled_y(x) int_to_grid_scaled((x), GRID_Y) + +I glitter_status_t +glitter_scan_converter_reset( + glitter_scan_converter_t *converter, + int xmin, int ymin, + int xmax, int ymax) +{ + glitter_status_t status; + + converter->xmin = 0; converter->xmax = 0; + converter->ymin = 0; converter->ymax = 0; + + if (xmax - xmin > ARRAY_LENGTH(converter->spans_embedded)) { + converter->spans = _cairo_malloc_ab (xmax - xmin, + sizeof (cairo_half_open_span_t)); + if (unlikely (converter->spans == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } else + converter->spans = converter->spans_embedded; + + xmin = int_to_grid_scaled_x(xmin); + ymin = int_to_grid_scaled_y(ymin); + xmax = int_to_grid_scaled_x(xmax); + ymax = int_to_grid_scaled_y(ymax); + + active_list_reset(converter->active); + cell_list_reset(converter->coverages); + status = polygon_reset(converter->polygon, ymin, ymax); + if (status) + return status; + + converter->xmin = xmin; + converter->xmax = xmax; + converter->ymin = ymin; + converter->ymax = ymax; + return GLITTER_STATUS_SUCCESS; +} + +/* INPUT_TO_GRID_X/Y (in_coord, out_grid_scaled, grid_scale) + * These macros convert an input coordinate in the client's + * device space to the rasterisation grid. + */ +/* Gah.. this bit of ugly defines INPUT_TO_GRID_X/Y so as to use + * shifts if possible, and something saneish if not. + */ +#if !defined(INPUT_TO_GRID_Y) && defined(GRID_Y_BITS) && GRID_Y_BITS <= GLITTER_INPUT_BITS +# define INPUT_TO_GRID_Y(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_Y_BITS) +#else +# define INPUT_TO_GRID_Y(in, out) INPUT_TO_GRID_general(in, out, GRID_Y) +#endif + +#if !defined(INPUT_TO_GRID_X) && defined(GRID_X_BITS) && GRID_X_BITS <= GLITTER_INPUT_BITS +# define INPUT_TO_GRID_X(in, out) (out) = (in) >> (GLITTER_INPUT_BITS - GRID_X_BITS) +#else +# define INPUT_TO_GRID_X(in, out) INPUT_TO_GRID_general(in, out, GRID_X) +#endif + +#define INPUT_TO_GRID_general(in, out, grid_scale) do { \ + long long tmp__ = (long long)(grid_scale) * (in); \ + tmp__ >>= GLITTER_INPUT_BITS; \ + (out) = tmp__; \ +} while (0) + +/* Add a new polygon edge from pixel (x1,y1) to (x2,y2) to the scan + * converter. The coordinates represent pixel positions scaled by + * 2**GLITTER_PIXEL_BITS. If this function fails then the scan + * converter should be reset or destroyed. Dir must be +1 or -1, + * with the latter reversing the orientation of the edge. */ +I void +glitter_scan_converter_add_edge (glitter_scan_converter_t *converter, + const cairo_edge_t *edge) +{ + cairo_edge_t e; + + INPUT_TO_GRID_Y (edge->top, e.top); + INPUT_TO_GRID_Y (edge->bottom, e.bottom); + if (e.top >= e.bottom) + return; + + /* XXX: possible overflows if GRID_X/Y > 2**GLITTER_INPUT_BITS */ + INPUT_TO_GRID_Y (edge->line.p1.y, e.line.p1.y); + INPUT_TO_GRID_Y (edge->line.p2.y, e.line.p2.y); + if (e.line.p1.y == e.line.p2.y) + e.line.p2.y++; /* Fudge to prevent div-by-zero */ + + INPUT_TO_GRID_X (edge->line.p1.x, e.line.p1.x); + INPUT_TO_GRID_X (edge->line.p2.x, e.line.p2.x); + + e.dir = edge->dir; + + polygon_add_edge (converter->polygon, &e); +} + +static void +step_edges (struct active_list *active, int count) +{ + struct edge *edge; + + count *= GRID_Y; + for (edge = active->head.next; edge != &active->tail; edge = edge->next) { + edge->height_left -= count; + if (! edge->height_left) { + edge->prev->next = edge->next; + edge->next->prev = edge->prev; + } + } +} + +static glitter_status_t +blit_a8 (struct cell_list *cells, + cairo_span_renderer_t *renderer, + cairo_half_open_span_t *spans, + int y, int height, + int xmin, int xmax) +{ + struct cell *cell = cells->head.next; + int prev_x = xmin, last_x = -1; + int16_t cover = 0, last_cover = 0; + unsigned num_spans; + + if (cell == &cells->tail) + return CAIRO_STATUS_SUCCESS; + + /* Skip cells to the left of the clip region. */ + while (cell->x < xmin) { + cover += cell->covered_height; + cell = cell->next; + } + cover *= GRID_X*2; + + /* Form the spans from the coverages and areas. */ + num_spans = 0; + for (; cell->x < xmax; cell = cell->next) { + int x = cell->x; + int16_t area; + + if (x > prev_x && cover != last_cover) { + spans[num_spans].x = prev_x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); + last_cover = cover; + last_x = prev_x; + ++num_spans; + } + + cover += cell->covered_height*GRID_X*2; + area = cover - cell->uncovered_area; + + if (area != last_cover) { + spans[num_spans].x = x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (area); + last_cover = area; + last_x = x; + ++num_spans; + } + + prev_x = x+1; + } + + if (prev_x <= xmax && cover != last_cover) { + spans[num_spans].x = prev_x; + spans[num_spans].coverage = GRID_AREA_TO_ALPHA (cover); + last_cover = cover; + last_x = prev_x; + ++num_spans; + } + + if (last_x < xmax && last_cover) { + spans[num_spans].x = xmax; + spans[num_spans].coverage = 0; + ++num_spans; + } + + /* Dump them into the renderer. */ + return renderer->render_rows (renderer, y, height, spans, num_spans); +} + +#define GRID_AREA_TO_A1(A) ((GRID_AREA_TO_ALPHA (A) > 127) ? 255 : 0) +static glitter_status_t +blit_a1 (struct cell_list *cells, + cairo_span_renderer_t *renderer, + cairo_half_open_span_t *spans, + int y, int height, + int xmin, int xmax) +{ + struct cell *cell = cells->head.next; + int prev_x = xmin, last_x = -1; + int16_t cover = 0; + uint8_t coverage, last_cover = 0; + unsigned num_spans; + + if (cell == &cells->tail) + return CAIRO_STATUS_SUCCESS; + + /* Skip cells to the left of the clip region. */ + while (cell->x < xmin) { + cover += cell->covered_height; + cell = cell->next; + } + cover *= GRID_X*2; + + /* Form the spans from the coverages and areas. */ + num_spans = 0; + for (; cell->x < xmax; cell = cell->next) { + int x = cell->x; + int16_t area; + + coverage = GRID_AREA_TO_A1 (cover); + if (x > prev_x && coverage != last_cover) { + last_x = spans[num_spans].x = prev_x; + last_cover = spans[num_spans].coverage = coverage; + ++num_spans; + } + + cover += cell->covered_height*GRID_X*2; + area = cover - cell->uncovered_area; + + coverage = GRID_AREA_TO_A1 (area); + if (coverage != last_cover) { + last_x = spans[num_spans].x = x; + last_cover = spans[num_spans].coverage = coverage; + ++num_spans; + } + + prev_x = x+1; + } + + coverage = GRID_AREA_TO_A1 (cover); + if (prev_x <= xmax && coverage != last_cover) { + last_x = spans[num_spans].x = prev_x; + last_cover = spans[num_spans].coverage = coverage; + ++num_spans; + } + + if (last_x < xmax && last_cover) { + spans[num_spans].x = xmax; + spans[num_spans].coverage = 0; + ++num_spans; + } + if (num_spans == 1) + return CAIRO_STATUS_SUCCESS; + + /* Dump them into the renderer. */ + return renderer->render_rows (renderer, y, height, spans, num_spans); +} + + +I void +glitter_scan_converter_render(glitter_scan_converter_t *converter, + unsigned int winding_mask, + int antialias, + cairo_span_renderer_t *renderer) +{ + int i, j; + int ymax_i = converter->ymax / GRID_Y; + int ymin_i = converter->ymin / GRID_Y; + int xmin_i, xmax_i; + int h = ymax_i - ymin_i; + struct polygon *polygon = converter->polygon; + struct cell_list *coverages = converter->coverages; + struct active_list *active = converter->active; + struct edge *buckets[GRID_Y] = { 0 }; + + xmin_i = converter->xmin / GRID_X; + xmax_i = converter->xmax / GRID_X; + if (xmin_i >= xmax_i) + return; + + /* Render each pixel row. */ + for (i = 0; i < h; i = j) { + int do_full_row = 0; + + j = i + 1; + + /* Determine if we can ignore this row or use the full pixel + * stepper. */ + if (! polygon->y_buckets[i]) { + if (active->head.next == &active->tail) { + active->min_height = INT_MAX; + active->is_vertical = 1; + for (; j < h && ! polygon->y_buckets[j]; j++) + ; + continue; + } + + do_full_row = can_do_full_row (active); + } + + if (do_full_row) { + /* Step by a full pixel row's worth. */ + full_row (active, coverages, winding_mask); + + if (active->is_vertical) { + while (j < h && + polygon->y_buckets[j] == NULL && + active->min_height >= 2*GRID_Y) + { + active->min_height -= GRID_Y; + j++; + } + if (j != i + 1) + step_edges (active, j - (i + 1)); + } + } else { + int sub; + + polygon_fill_buckets (active, + polygon->y_buckets[i], + (i+ymin_i)*GRID_Y, + buckets); + + /* Subsample this row. */ + for (sub = 0; sub < GRID_Y; sub++) { + if (buckets[sub]) { + active_list_merge_edges_from_bucket (active, buckets[sub]); + buckets[sub] = NULL; + } + + sub_row (active, coverages, winding_mask); + } + } + + if (antialias) + blit_a8 (coverages, renderer, converter->spans, + i+ymin_i, j-i, xmin_i, xmax_i); + else + blit_a1 (coverages, renderer, converter->spans, + i+ymin_i, j-i, xmin_i, xmax_i); + cell_list_reset (coverages); + + active->min_height -= GRID_Y; + } +} + +struct _cairo_tor22_scan_converter { + cairo_scan_converter_t base; + + glitter_scan_converter_t converter[1]; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + + jmp_buf jmp; +}; + +typedef struct _cairo_tor22_scan_converter cairo_tor22_scan_converter_t; + +static void +_cairo_tor22_scan_converter_destroy (void *converter) +{ + cairo_tor22_scan_converter_t *self = converter; + if (self == NULL) { + return; + } + _glitter_scan_converter_fini (self->converter); + free(self); +} + +cairo_status_t +_cairo_tor22_scan_converter_add_polygon (void *converter, + const cairo_polygon_t *polygon) +{ + cairo_tor22_scan_converter_t *self = converter; + int i; + +#if 0 + FILE *file = fopen ("polygon.txt", "w"); + _cairo_debug_print_polygon (file, polygon); + fclose (file); +#endif + + for (i = 0; i < polygon->num_edges; i++) + glitter_scan_converter_add_edge (self->converter, &polygon->edges[i]); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_tor22_scan_converter_generate (void *converter, + cairo_span_renderer_t *renderer) +{ + cairo_tor22_scan_converter_t *self = converter; + cairo_status_t status; + + if ((status = setjmp (self->jmp))) + return _cairo_scan_converter_set_error (self, _cairo_error (status)); + + glitter_scan_converter_render (self->converter, + self->fill_rule == CAIRO_FILL_RULE_WINDING ? ~0 : 1, + self->antialias != CAIRO_ANTIALIAS_NONE, + renderer); + return CAIRO_STATUS_SUCCESS; +} + +cairo_scan_converter_t * +_cairo_tor22_scan_converter_create (int xmin, + int ymin, + int xmax, + int ymax, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias) +{ + cairo_tor22_scan_converter_t *self; + cairo_status_t status; + + self = malloc (sizeof(struct _cairo_tor22_scan_converter)); + if (unlikely (self == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto bail_nomem; + } + + self->base.destroy = _cairo_tor22_scan_converter_destroy; + self->base.generate = _cairo_tor22_scan_converter_generate; + + _glitter_scan_converter_init (self->converter, &self->jmp); + status = glitter_scan_converter_reset (self->converter, + xmin, ymin, xmax, ymax); + if (unlikely (status)) + goto bail; + + self->fill_rule = fill_rule; + self->antialias = antialias; + + return &self->base; + + bail: + self->base.destroy(&self->base); + bail_nomem: + return _cairo_scan_converter_create_in_error (status); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-toy-font-face.c b/Build/source/libs/cairo/cairo-src/src/cairo-toy-font-face.c new file mode 100644 index 00000000000..4fe94ab0919 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-toy-font-face.c @@ -0,0 +1,524 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005,2008 Red Hat Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Graydon Hoare + * Owen Taylor + * Behdad Esfahbod + */ + +#define _BSD_SOURCE /* for strdup() */ +#include "cairoint.h" +#include "cairo-error-private.h" + + +static const cairo_font_face_t _cairo_font_face_null_pointer = { + { 0 }, /* hash_entry */ + CAIRO_STATUS_NULL_POINTER, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL +}; + +static const cairo_font_face_t _cairo_font_face_invalid_string = { + { 0 }, /* hash_entry */ + CAIRO_STATUS_INVALID_STRING, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL +}; + +static const cairo_font_face_t _cairo_font_face_invalid_slant = { + { 0 }, /* hash_entry */ + CAIRO_STATUS_INVALID_SLANT, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL +}; + +static const cairo_font_face_t _cairo_font_face_invalid_weight = { + { 0 }, /* hash_entry */ + CAIRO_STATUS_INVALID_WEIGHT, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + NULL +}; + + +static const cairo_font_face_backend_t _cairo_toy_font_face_backend; + +static int +_cairo_toy_font_face_keys_equal (const void *key_a, + const void *key_b); + +/* We maintain a hash table from family/weight/slant => + * #cairo_font_face_t for #cairo_toy_font_t. The primary purpose of + * this mapping is to provide unique #cairo_font_face_t values so that + * our cache and mapping from #cairo_font_face_t => #cairo_scaled_font_t + * works. Once the corresponding #cairo_font_face_t objects fall out of + * downstream caches, we don't need them in this hash table anymore. + * + * Modifications to this hash table are protected by + * _cairo_toy_font_face_mutex. + */ +static cairo_hash_table_t *cairo_toy_font_face_hash_table = NULL; + +static cairo_hash_table_t * +_cairo_toy_font_face_hash_table_lock (void) +{ + CAIRO_MUTEX_LOCK (_cairo_toy_font_face_mutex); + + if (cairo_toy_font_face_hash_table == NULL) + { + cairo_toy_font_face_hash_table = + _cairo_hash_table_create (_cairo_toy_font_face_keys_equal); + + if (cairo_toy_font_face_hash_table == NULL) { + CAIRO_MUTEX_UNLOCK (_cairo_toy_font_face_mutex); + return NULL; + } + } + + return cairo_toy_font_face_hash_table; +} + +static void +_cairo_toy_font_face_hash_table_unlock (void) +{ + CAIRO_MUTEX_UNLOCK (_cairo_toy_font_face_mutex); +} + +/** + * _cairo_toy_font_face_init_key: + * + * Initialize those portions of #cairo_toy_font_face_t needed to use + * it as a hash table key, including the hash code buried away in + * font_face->base.hash_entry. No memory allocation is performed here + * so that no fini call is needed. We do this to make it easier to use + * an automatic #cairo_toy_font_face_t variable as a key. + **/ +static void +_cairo_toy_font_face_init_key (cairo_toy_font_face_t *key, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) +{ + unsigned long hash; + + key->family = family; + key->owns_family = FALSE; + + key->slant = slant; + key->weight = weight; + + /* 1607 and 1451 are just a couple of arbitrary primes. */ + hash = _cairo_hash_string (family); + hash += ((unsigned long) slant) * 1607; + hash += ((unsigned long) weight) * 1451; + + key->base.hash_entry.hash = hash; +} + +static cairo_status_t +_cairo_toy_font_face_create_impl_face (cairo_toy_font_face_t *font_face, + cairo_font_face_t **impl_font_face) +{ + const cairo_font_face_backend_t * backend = CAIRO_FONT_FACE_BACKEND_DEFAULT; + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + if (unlikely (font_face->base.status)) + return font_face->base.status; + + if (backend->create_for_toy != NULL && + 0 != strncmp (font_face->family, CAIRO_USER_FONT_FAMILY_DEFAULT, + strlen (CAIRO_USER_FONT_FAMILY_DEFAULT))) + { + status = backend->create_for_toy (font_face, impl_font_face); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + backend = &_cairo_user_font_face_backend; + status = backend->create_for_toy (font_face, impl_font_face); + } + + return status; +} + +static cairo_status_t +_cairo_toy_font_face_init (cairo_toy_font_face_t *font_face, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) +{ + char *family_copy; + cairo_status_t status; + + family_copy = strdup (family); + if (unlikely (family_copy == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_toy_font_face_init_key (font_face, family_copy, slant, weight); + font_face->owns_family = TRUE; + + _cairo_font_face_init (&font_face->base, &_cairo_toy_font_face_backend); + + status = _cairo_toy_font_face_create_impl_face (font_face, + &font_face->impl_face); + if (unlikely (status)) { + free (family_copy); + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_toy_font_face_fini (cairo_toy_font_face_t *font_face) +{ + /* We assert here that we own font_face->family before casting + * away the const qualifer. */ + assert (font_face->owns_family); + free ((char*) font_face->family); + + if (font_face->impl_face) + cairo_font_face_destroy (font_face->impl_face); +} + +static int +_cairo_toy_font_face_keys_equal (const void *key_a, + const void *key_b) +{ + const cairo_toy_font_face_t *face_a = key_a; + const cairo_toy_font_face_t *face_b = key_b; + + return (strcmp (face_a->family, face_b->family) == 0 && + face_a->slant == face_b->slant && + face_a->weight == face_b->weight); +} + +/** + * cairo_toy_font_face_create: + * @family: a font family name, encoded in UTF-8 + * @slant: the slant for the font + * @weight: the weight for the font + * + * Creates a font face from a triplet of family, slant, and weight. + * These font faces are used in implementation of the the #cairo_t "toy" + * font API. + * + * If @family is the zero-length string "", the platform-specific default + * family is assumed. The default family then can be queried using + * cairo_toy_font_face_get_family(). + * + * The cairo_select_font_face() function uses this to create font faces. + * See that function for limitations and other details of toy font faces. + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.8 + **/ +cairo_font_face_t * +cairo_toy_font_face_create (const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) +{ + cairo_status_t status; + cairo_toy_font_face_t key, *font_face; + cairo_hash_table_t *hash_table; + + if (family == NULL) + return (cairo_font_face_t*) &_cairo_font_face_null_pointer; + + /* Make sure we've got valid UTF-8 for the family */ + status = _cairo_utf8_to_ucs4 (family, -1, NULL, NULL); + if (unlikely (status)) { + if (status == CAIRO_STATUS_INVALID_STRING) + return (cairo_font_face_t*) &_cairo_font_face_invalid_string; + + return (cairo_font_face_t*) &_cairo_font_face_nil; + } + + switch (slant) { + case CAIRO_FONT_SLANT_NORMAL: + case CAIRO_FONT_SLANT_ITALIC: + case CAIRO_FONT_SLANT_OBLIQUE: + break; + default: + return (cairo_font_face_t*) &_cairo_font_face_invalid_slant; + } + + switch (weight) { + case CAIRO_FONT_WEIGHT_NORMAL: + case CAIRO_FONT_WEIGHT_BOLD: + break; + default: + return (cairo_font_face_t*) &_cairo_font_face_invalid_weight; + } + + if (*family == '\0') + family = CAIRO_FONT_FAMILY_DEFAULT; + + hash_table = _cairo_toy_font_face_hash_table_lock (); + if (unlikely (hash_table == NULL)) + goto UNWIND; + + _cairo_toy_font_face_init_key (&key, family, slant, weight); + + /* Return existing font_face if it exists in the hash table. */ + font_face = _cairo_hash_table_lookup (hash_table, + &key.base.hash_entry); + if (font_face != NULL) { + if (font_face->base.status == CAIRO_STATUS_SUCCESS) { + cairo_font_face_reference (&font_face->base); + _cairo_toy_font_face_hash_table_unlock (); + return &font_face->base; + } + + /* remove the bad font from the hash table */ + _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); + } + + /* Otherwise create it and insert into hash table. */ + font_face = malloc (sizeof (cairo_toy_font_face_t)); + if (unlikely (font_face == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto UNWIND_HASH_TABLE_LOCK; + } + + status = _cairo_toy_font_face_init (font_face, family, slant, weight); + if (unlikely (status)) + goto UNWIND_FONT_FACE_MALLOC; + + assert (font_face->base.hash_entry.hash == key.base.hash_entry.hash); + status = _cairo_hash_table_insert (hash_table, &font_face->base.hash_entry); + if (unlikely (status)) + goto UNWIND_FONT_FACE_INIT; + + _cairo_toy_font_face_hash_table_unlock (); + + return &font_face->base; + + UNWIND_FONT_FACE_INIT: + _cairo_toy_font_face_fini (font_face); + UNWIND_FONT_FACE_MALLOC: + free (font_face); + UNWIND_HASH_TABLE_LOCK: + _cairo_toy_font_face_hash_table_unlock (); + UNWIND: + return (cairo_font_face_t*) &_cairo_font_face_nil; +} +slim_hidden_def (cairo_toy_font_face_create); + +static cairo_bool_t +_cairo_toy_font_face_destroy (void *abstract_face) +{ + cairo_toy_font_face_t *font_face = abstract_face; + cairo_hash_table_t *hash_table; + + hash_table = _cairo_toy_font_face_hash_table_lock (); + /* All created objects must have been mapped in the hash table. */ + assert (hash_table != NULL); + + if (! _cairo_reference_count_dec_and_test (&font_face->base.ref_count)) { + /* somebody recreated the font whilst we waited for the lock */ + _cairo_toy_font_face_hash_table_unlock (); + return FALSE; + } + + /* Font faces in SUCCESS status are guaranteed to be in the + * hashtable. Font faces in an error status are removed from the + * hashtable if they are found during a lookup, thus they should + * only be removed if they are in the hashtable. */ + if (likely (font_face->base.status == CAIRO_STATUS_SUCCESS) || + _cairo_hash_table_lookup (hash_table, &font_face->base.hash_entry) == font_face) + _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); + + _cairo_toy_font_face_hash_table_unlock (); + + _cairo_toy_font_face_fini (font_face); + return TRUE; +} + +static cairo_status_t +_cairo_toy_font_face_scaled_font_create (void *abstract_font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + cairo_scaled_font_t **scaled_font) +{ + cairo_toy_font_face_t *font_face = (cairo_toy_font_face_t *) abstract_font_face; + + ASSERT_NOT_REACHED; + + return _cairo_font_face_set_error (&font_face->base, CAIRO_STATUS_FONT_TYPE_MISMATCH); +} + +static cairo_font_face_t * +_cairo_toy_font_face_get_implementation (void *abstract_font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options) +{ + cairo_toy_font_face_t *font_face = abstract_font_face; + + if (font_face->impl_face) { + cairo_font_face_t *impl = font_face->impl_face; + + if (impl->backend->get_implementation != NULL) { + return impl->backend->get_implementation (impl, + font_matrix, + ctm, + options); + } + + return cairo_font_face_reference (impl); + } + + return abstract_font_face; +} + +static cairo_bool_t +_cairo_font_face_is_toy (cairo_font_face_t *font_face) +{ + return font_face->backend == &_cairo_toy_font_face_backend; +} + +/** + * cairo_toy_font_face_get_family: + * @font_face: A toy font face + * + * Gets the familly name of a toy font. + * + * Return value: The family name. This string is owned by the font face + * and remains valid as long as the font face is alive (referenced). + * + * Since: 1.8 + **/ +const char * +cairo_toy_font_face_get_family (cairo_font_face_t *font_face) +{ + cairo_toy_font_face_t *toy_font_face; + + if (font_face->status) + return CAIRO_FONT_FAMILY_DEFAULT; + + toy_font_face = (cairo_toy_font_face_t *) font_face; + if (! _cairo_font_face_is_toy (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return CAIRO_FONT_FAMILY_DEFAULT; + } + assert (toy_font_face->owns_family); + return toy_font_face->family; +} + +/** + * cairo_toy_font_face_get_slant: + * @font_face: A toy font face + * + * Gets the slant a toy font. + * + * Return value: The slant value + * + * Since: 1.8 + **/ +cairo_font_slant_t +cairo_toy_font_face_get_slant (cairo_font_face_t *font_face) +{ + cairo_toy_font_face_t *toy_font_face; + + if (font_face->status) + return CAIRO_FONT_SLANT_DEFAULT; + + toy_font_face = (cairo_toy_font_face_t *) font_face; + if (! _cairo_font_face_is_toy (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return CAIRO_FONT_SLANT_DEFAULT; + } + return toy_font_face->slant; +} +slim_hidden_def (cairo_toy_font_face_get_slant); + +/** + * cairo_toy_font_face_get_weight: + * @font_face: A toy font face + * + * Gets the weight a toy font. + * + * Return value: The weight value + * + * Since: 1.8 + **/ +cairo_font_weight_t +cairo_toy_font_face_get_weight (cairo_font_face_t *font_face) +{ + cairo_toy_font_face_t *toy_font_face; + + if (font_face->status) + return CAIRO_FONT_WEIGHT_DEFAULT; + + toy_font_face = (cairo_toy_font_face_t *) font_face; + if (! _cairo_font_face_is_toy (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return CAIRO_FONT_WEIGHT_DEFAULT; + } + return toy_font_face->weight; +} +slim_hidden_def (cairo_toy_font_face_get_weight); + +static const cairo_font_face_backend_t _cairo_toy_font_face_backend = { + CAIRO_FONT_TYPE_TOY, + NULL, /* create_for_toy */ + _cairo_toy_font_face_destroy, + _cairo_toy_font_face_scaled_font_create, + _cairo_toy_font_face_get_implementation +}; + +void +_cairo_toy_font_face_reset_static_data (void) +{ + cairo_hash_table_t *hash_table; + + /* We manually acquire the lock rather than calling + * cairo_toy_font_face_hash_table_lock simply to avoid + * creating the table only to destroy it again. */ + CAIRO_MUTEX_LOCK (_cairo_toy_font_face_mutex); + hash_table = cairo_toy_font_face_hash_table; + cairo_toy_font_face_hash_table = NULL; + CAIRO_MUTEX_UNLOCK (_cairo_toy_font_face_mutex); + + if (hash_table != NULL) + _cairo_hash_table_destroy (hash_table); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-traps-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-traps-compositor.c new file mode 100644 index 00000000000..3414fc2684a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-traps-compositor.c @@ -0,0 +1,2351 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-pattern-inline.h" +#include "cairo-paginated-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-surface-subsurface-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-observer-private.h" +#include "cairo-region-private.h" +#include "cairo-spans-private.h" +#include "cairo-traps-private.h" +#include "cairo-tristrip-private.h" + +typedef cairo_int_status_t +(*draw_func_t) (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip); + +static void do_unaligned_row(void (*blt)(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage), + void *closure, + const cairo_box_t *b, + int tx, int y, int h, + uint16_t coverage) +{ + int x1 = _cairo_fixed_integer_part (b->p1.x) - tx; + int x2 = _cairo_fixed_integer_part (b->p2.x) - tx; + if (x2 > x1) { + if (! _cairo_fixed_is_integer (b->p1.x)) { + blt(closure, x1, y, 1, h, + coverage * (256 - _cairo_fixed_fractional_part (b->p1.x))); + x1++; + } + + if (x2 > x1) + blt(closure, x1, y, x2-x1, h, (coverage << 8) - (coverage >> 8)); + + if (! _cairo_fixed_is_integer (b->p2.x)) + blt(closure, x2, y, 1, h, + coverage * _cairo_fixed_fractional_part (b->p2.x)); + } else + blt(closure, x1, y, 1, h, + coverage * (b->p2.x - b->p1.x)); +} + +static void do_unaligned_box(void (*blt)(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage), + void *closure, + const cairo_box_t *b, int tx, int ty) +{ + int y1 = _cairo_fixed_integer_part (b->p1.y) - ty; + int y2 = _cairo_fixed_integer_part (b->p2.y) - ty; + if (y2 > y1) { + if (! _cairo_fixed_is_integer (b->p1.y)) { + do_unaligned_row(blt, closure, b, tx, y1, 1, + 256 - _cairo_fixed_fractional_part (b->p1.y)); + y1++; + } + + if (y2 > y1) + do_unaligned_row(blt, closure, b, tx, y1, y2-y1, 256); + + if (! _cairo_fixed_is_integer (b->p2.y)) + do_unaligned_row(blt, closure, b, tx, y2, 1, + _cairo_fixed_fractional_part (b->p2.y)); + } else + do_unaligned_row(blt, closure, b, tx, y1, 1, + b->p2.y - b->p1.y); +} + +struct blt_in { + const cairo_traps_compositor_t *compositor; + cairo_surface_t *dst; + cairo_boxes_t boxes; +}; + +static void blt_in(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct blt_in *info = closure; + cairo_color_t color; + + if (CAIRO_ALPHA_SHORT_IS_OPAQUE (coverage)) + return; + + _cairo_box_from_integers (&info->boxes.chunks.base[0], x, y, w, h); + + _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double) 0xffff); + info->compositor->fill_boxes (info->dst, + CAIRO_OPERATOR_IN, &color, + &info->boxes); +} + +static void +add_rect_with_offset (cairo_boxes_t *boxes, int x1, int y1, int x2, int y2, int dx, int dy) +{ + cairo_box_t box; + cairo_int_status_t status; + + box.p1.x = _cairo_fixed_from_int (x1 - dx); + box.p1.y = _cairo_fixed_from_int (y1 - dy); + box.p2.x = _cairo_fixed_from_int (x2 - dx); + box.p2.y = _cairo_fixed_from_int (y2 - dy); + + status = _cairo_boxes_add (boxes, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_INT_STATUS_SUCCESS); +} + +static cairo_int_status_t +combine_clip_as_traps (const cairo_traps_compositor_t *compositor, + cairo_surface_t *mask, + const cairo_clip_t *clip, + const cairo_rectangle_int_t *extents) +{ + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + cairo_traps_t traps; + cairo_surface_t *src; + cairo_box_t box; + cairo_rectangle_int_t fixup; + int src_x, src_y; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = _cairo_clip_get_polygon (clip, &polygon, + &fill_rule, &antialias); + if (status) + return status; + + _cairo_traps_init (&traps); + status = _cairo_bentley_ottmann_tessellate_polygon (&traps, + &polygon, + fill_rule); + _cairo_polygon_fini (&polygon); + if (unlikely (status)) + return status; + + src = compositor->pattern_to_surface (mask, NULL, FALSE, + extents, NULL, + &src_x, &src_y); + if (unlikely (src->status)) { + _cairo_traps_fini (&traps); + return src->status; + } + + status = compositor->composite_traps (mask, CAIRO_OPERATOR_IN, src, + src_x, src_y, + extents->x, extents->y, + extents, + antialias, &traps); + + _cairo_traps_extents (&traps, &box); + _cairo_box_round_to_rectangle (&box, &fixup); + _cairo_traps_fini (&traps); + cairo_surface_destroy (src); + + if (unlikely (status)) + return status; + + if (! _cairo_rectangle_intersect (&fixup, extents)) + return CAIRO_STATUS_SUCCESS; + + if (fixup.width < extents->width || fixup.height < extents->height) { + cairo_boxes_t clear; + + _cairo_boxes_init (&clear); + + /* top */ + if (fixup.y != extents->y) { + add_rect_with_offset (&clear, + extents->x, extents->y, + extents->x + extents->width, + fixup.y, + extents->x, extents->y); + } + /* left */ + if (fixup.x != extents->x) { + add_rect_with_offset (&clear, + extents->x, fixup.y, + fixup.x, + fixup.y + fixup.height, + extents->x, extents->y); + } + /* right */ + if (fixup.x + fixup.width != extents->x + extents->width) { + add_rect_with_offset (&clear, + fixup.x + fixup.width, + fixup.y, + extents->x + extents->width, + fixup.y + fixup.height, + extents->x, extents->y); + } + /* bottom */ + if (fixup.y + fixup.height != extents->y + extents->height) { + add_rect_with_offset (&clear, + extents->x, + fixup.y + fixup.height, + extents->x + extents->width, + extents->y + extents->height, + extents->x, extents->y); + } + + status = compositor->fill_boxes (mask, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + + _cairo_boxes_fini (&clear); + } + + return status; +} + +static cairo_status_t +__clip_to_surface (const cairo_traps_compositor_t *compositor, + const cairo_composite_rectangles_t *composite, + const cairo_rectangle_int_t *extents, + cairo_surface_t **surface) +{ + cairo_surface_t *mask; + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + cairo_traps_t traps; + cairo_boxes_t clear; + cairo_surface_t *src; + int src_x, src_y; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = _cairo_clip_get_polygon (composite->clip, &polygon, + &fill_rule, &antialias); + if (status) + return status; + + _cairo_traps_init (&traps); + status = _cairo_bentley_ottmann_tessellate_polygon (&traps, + &polygon, + fill_rule); + _cairo_polygon_fini (&polygon); + if (unlikely (status)) + return status; + + mask = _cairo_surface_create_scratch (composite->surface, + CAIRO_CONTENT_ALPHA, + extents->width, + extents->height, + NULL); + if (unlikely (mask->status)) { + _cairo_traps_fini (&traps); + return status; + } + + src = compositor->pattern_to_surface (mask, NULL, FALSE, + extents, NULL, + &src_x, &src_y); + if (unlikely (status = src->status)) + goto error; + + status = compositor->acquire (mask); + if (unlikely (status)) + goto error; + + _cairo_boxes_init_from_rectangle (&clear, + 0, 0, + extents->width, + extents->height); + status = compositor->fill_boxes (mask, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + if (unlikely (status)) + goto error_release; + + status = compositor->composite_traps (mask, CAIRO_OPERATOR_ADD, src, + src_x, src_y, + extents->x, extents->y, + extents, + antialias, &traps); + if (unlikely (status)) + goto error_release; + + compositor->release (mask); + *surface = mask; +out: + cairo_surface_destroy (src); + _cairo_traps_fini (&traps); + return status; + +error_release: + compositor->release (mask); +error: + cairo_surface_destroy (mask); + goto out; +} + +static cairo_surface_t * +traps_get_clip_surface (const cairo_traps_compositor_t *compositor, + const cairo_composite_rectangles_t *composite, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_t *surface = NULL; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = __clip_to_surface (compositor, composite, extents, &surface); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + surface = _cairo_surface_create_scratch (composite->surface, + CAIRO_CONTENT_ALPHA, + extents->width, + extents->height, + CAIRO_COLOR_WHITE); + if (unlikely (surface->status)) + return surface; + + status = _cairo_clip_combine_with_surface (composite->clip, surface, + extents->x, extents->y); + } + if (unlikely (status)) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + + return surface; +} + +static void blt_unaligned_boxes(const cairo_traps_compositor_t *compositor, + cairo_surface_t *surface, + int dx, int dy, + cairo_box_t *boxes, + int num_boxes) +{ + struct blt_in info; + int i; + + info.compositor = compositor; + info.dst = surface; + _cairo_boxes_init (&info.boxes); + info.boxes.num_boxes = 1; + for (i = 0; i < num_boxes; i++) { + cairo_box_t *b = &boxes[i]; + + if (! _cairo_fixed_is_integer (b->p1.x) || + ! _cairo_fixed_is_integer (b->p1.y) || + ! _cairo_fixed_is_integer (b->p2.x) || + ! _cairo_fixed_is_integer (b->p2.y)) + { + do_unaligned_box(blt_in, &info, b, dx, dy); + } + } +} + +static cairo_surface_t * +create_composite_mask (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *draw_closure, + draw_func_t draw_func, + draw_func_t mask_func, + const cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *surface, *src; + cairo_int_status_t status; + int src_x, src_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + surface = _cairo_surface_create_scratch (dst, CAIRO_CONTENT_ALPHA, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (surface->status)) + return surface; + + src = compositor->pattern_to_surface (surface, + &_cairo_pattern_white.base, + FALSE, + &extents->bounded, + &extents->bounded, + &src_x, &src_y); + if (unlikely (src->status)) { + cairo_surface_destroy (surface); + return src; + } + + status = compositor->acquire (surface); + if (unlikely (status)) { + cairo_surface_destroy (src); + cairo_surface_destroy (surface); + return _cairo_surface_create_in_error (status); + } + + if (!surface->is_clear) { + cairo_boxes_t clear; + + _cairo_boxes_init_from_rectangle (&clear, + 0, 0, + extents->bounded.width, + extents->bounded.height); + status = compositor->fill_boxes (surface, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + if (unlikely (status)) + goto error; + + surface->is_clear = TRUE; + } + + if (mask_func) { + status = mask_func (compositor, surface, draw_closure, + CAIRO_OPERATOR_SOURCE, src, src_x, src_y, + extents->bounded.x, extents->bounded.y, + &extents->bounded, extents->clip); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + surface->is_clear = FALSE; + goto out; + } + if (unlikely (status != CAIRO_INT_STATUS_UNSUPPORTED)) + goto error; + } + + /* Is it worth setting the clip region here? */ + status = draw_func (compositor, surface, draw_closure, + CAIRO_OPERATOR_ADD, src, src_x, src_y, + extents->bounded.x, extents->bounded.y, + &extents->bounded, NULL); + if (unlikely (status)) + goto error; + + surface->is_clear = FALSE; + if (extents->clip->path != NULL) { + status = combine_clip_as_traps (compositor, surface, + extents->clip, &extents->bounded); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = _cairo_clip_combine_with_surface (extents->clip, surface, + extents->bounded.x, + extents->bounded.y); + } + if (unlikely (status)) + goto error; + } else if (extents->clip->boxes) { + blt_unaligned_boxes(compositor, surface, + extents->bounded.x, extents->bounded.y, + extents->clip->boxes, extents->clip->num_boxes); + + } + +out: + compositor->release (surface); + cairo_surface_destroy (src); + return surface; + +error: + compositor->release (surface); + if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + cairo_surface_destroy (src); + return surface; +} + +/* Handles compositing with a clip surface when the operator allows + * us to combine the clip with the mask + */ +static cairo_status_t +clip_and_composite_with_mask (const cairo_traps_compositor_t *compositor, + const cairo_composite_rectangles_t*extents, + draw_func_t draw_func, + draw_func_t mask_func, + void *draw_closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, int src_y) +{ + cairo_surface_t *dst = extents->surface; + cairo_surface_t *mask; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + mask = create_composite_mask (compositor, dst, draw_closure, + draw_func, mask_func, + extents); + if (unlikely (mask->status)) + return mask->status; + + if (mask->is_clear) + goto skip; + + if (src != NULL || dst->content != CAIRO_CONTENT_ALPHA) { + compositor->composite (dst, op, src, mask, + extents->bounded.x + src_x, + extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } else { + compositor->composite (dst, op, mask, NULL, + 0, 0, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } + +skip: + cairo_surface_destroy (mask); + return CAIRO_STATUS_SUCCESS; +} + +/* Handles compositing with a clip surface when we have to do the operation + * in two pieces and combine them together. + */ +static cairo_status_t +clip_and_composite_combine (const cairo_traps_compositor_t *compositor, + const cairo_composite_rectangles_t*extents, + draw_func_t draw_func, + void *draw_closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, int src_y) +{ + cairo_surface_t *dst = extents->surface; + cairo_surface_t *tmp, *clip; + cairo_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + tmp = _cairo_surface_create_scratch (dst, dst->content, + extents->bounded.width, + extents->bounded.height, + NULL); + if (unlikely (tmp->status)) + return tmp->status; + + status = compositor->acquire (tmp); + if (unlikely (status)) { + cairo_surface_destroy (tmp); + return status; + } + + compositor->composite (tmp, + dst->is_clear ? CAIRO_OPERATOR_CLEAR : CAIRO_OPERATOR_SOURCE, + dst, NULL, + extents->bounded.x, extents->bounded.y, + 0, 0, + 0, 0, + extents->bounded.width, extents->bounded.height); + + status = draw_func (compositor, tmp, draw_closure, op, + src, src_x, src_y, + extents->bounded.x, extents->bounded.y, + &extents->bounded, NULL); + + if (unlikely (status)) + goto cleanup; + + clip = traps_get_clip_surface (compositor, extents, &extents->bounded); + if (unlikely ((status = clip->status))) + goto cleanup; + + if (dst->is_clear) { + compositor->composite (dst, CAIRO_OPERATOR_SOURCE, tmp, clip, + 0, 0, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } else { + compositor->lerp (dst, tmp, clip, + 0, 0, + 0,0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } + cairo_surface_destroy (clip); + +cleanup: + compositor->release (tmp); + cairo_surface_destroy (tmp); + + return status; +} + +/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's + * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) + */ +static cairo_status_t +clip_and_composite_source (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + draw_func_t draw_func, + draw_func_t mask_func, + void *draw_closure, + cairo_surface_t *src, + int src_x, + int src_y, + const cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *mask; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + /* Create a surface that is mask IN clip */ + mask = create_composite_mask (compositor, dst, draw_closure, + draw_func, mask_func, + extents); + if (unlikely (mask->status)) + return mask->status; + + if (mask->is_clear) + goto skip; + + if (dst->is_clear) { + compositor->composite (dst, CAIRO_OPERATOR_SOURCE, src, mask, + extents->bounded.x + src_x, extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } else { + compositor->lerp (dst, src, mask, + extents->bounded.x + src_x, extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + } + +skip: + cairo_surface_destroy (mask); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +can_reduce_alpha_op (cairo_operator_t op) +{ + int iop = op; + switch (iop) { + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_ADD: + return TRUE; + default: + return FALSE; + } +} + +static cairo_bool_t +reduce_alpha_op (cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *dst = extents->surface; + cairo_operator_t op = extents->op; + const cairo_pattern_t *pattern = &extents->source_pattern.base; + return dst->is_clear && + dst->content == CAIRO_CONTENT_ALPHA && + _cairo_pattern_is_opaque_solid (pattern) && + can_reduce_alpha_op (op); +} + +static cairo_status_t +fixup_unbounded_with_mask (const cairo_traps_compositor_t *compositor, + const cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *dst = extents->surface; + cairo_surface_t *mask; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + /* XXX can we avoid querying the clip surface again? */ + mask = traps_get_clip_surface (compositor, extents, &extents->unbounded); + if (unlikely (mask->status)) + return mask->status; + + /* top */ + if (extents->bounded.y != extents->unbounded.y) { + int x = extents->unbounded.x; + int y = extents->unbounded.y; + int width = extents->unbounded.width; + int height = extents->bounded.y - y; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + 0, 0, + 0, 0, + x, y, + width, height); + } + + /* left */ + if (extents->bounded.x != extents->unbounded.x) { + int x = extents->unbounded.x; + int y = extents->bounded.y; + int width = extents->bounded.x - x; + int height = extents->bounded.height; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + 0, y - extents->unbounded.y, + 0, 0, + x, y, + width, height); + } + + /* right */ + if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { + int x = extents->bounded.x + extents->bounded.width; + int y = extents->bounded.y; + int width = extents->unbounded.x + extents->unbounded.width - x; + int height = extents->bounded.height; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + x - extents->unbounded.x, y - extents->unbounded.y, + 0, 0, + x, y, + width, height); + } + + /* bottom */ + if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { + int x = extents->unbounded.x; + int y = extents->bounded.y + extents->bounded.height; + int width = extents->unbounded.width; + int height = extents->unbounded.y + extents->unbounded.height - y; + + compositor->composite (dst, CAIRO_OPERATOR_DEST_OUT, mask, NULL, + 0, y - extents->unbounded.y, + 0, 0, + x, y, + width, height); + } + + cairo_surface_destroy (mask); + + return CAIRO_STATUS_SUCCESS; +} + +static void +add_rect (cairo_boxes_t *boxes, int x1, int y1, int x2, int y2) +{ + cairo_box_t box; + cairo_int_status_t status; + + box.p1.x = _cairo_fixed_from_int (x1); + box.p1.y = _cairo_fixed_from_int (y1); + box.p2.x = _cairo_fixed_from_int (x2); + box.p2.y = _cairo_fixed_from_int (y2); + + status = _cairo_boxes_add (boxes, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_INT_STATUS_SUCCESS); +} + +static cairo_status_t +fixup_unbounded (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + cairo_boxes_t clear, tmp; + cairo_box_t box; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (extents->bounded.width == extents->unbounded.width && + extents->bounded.height == extents->unbounded.height) + { + return CAIRO_STATUS_SUCCESS; + } + + assert (extents->clip->path == NULL); + + /* subtract the drawn boxes from the unbounded area */ + _cairo_boxes_init (&clear); + + box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); + box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); + box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); + box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); + + if (boxes == NULL) { + if (extents->bounded.width == 0 || extents->bounded.height == 0) { + goto empty; + } else { + /* top */ + if (extents->bounded.y != extents->unbounded.y) { + add_rect (&clear, + extents->unbounded.x, extents->unbounded.y, + extents->unbounded.x + extents->unbounded.width, + extents->bounded.y); + } + /* left */ + if (extents->bounded.x != extents->unbounded.x) { + add_rect (&clear, + extents->unbounded.x, extents->bounded.y, + extents->bounded.x, + extents->bounded.y + extents->bounded.height); + } + /* right */ + if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { + add_rect (&clear, + extents->bounded.x + extents->bounded.width, + extents->bounded.y, + extents->unbounded.x + extents->unbounded.width, + extents->bounded.y + extents->bounded.height); + } + /* bottom */ + if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { + add_rect (&clear, + extents->unbounded.x, + extents->bounded.y + extents->bounded.height, + extents->unbounded.x + extents->unbounded.width, + extents->unbounded.y + extents->unbounded.height); + } + } + } else if (boxes->num_boxes) { + _cairo_boxes_init (&tmp); + + assert (boxes->is_pixel_aligned); + + status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_INT_STATUS_SUCCESS); + + tmp.chunks.next = &boxes->chunks; + tmp.num_boxes += boxes->num_boxes; + + status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, + CAIRO_FILL_RULE_WINDING, + &clear); + tmp.chunks.next = NULL; + if (unlikely (status)) + goto error; + } else { +empty: + box.p1.x = _cairo_fixed_from_int (extents->unbounded.x); + box.p2.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); + + status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_INT_STATUS_SUCCESS); + } + + /* Now intersect with the clip boxes */ + if (extents->clip->num_boxes) { + _cairo_boxes_init_for_array (&tmp, + extents->clip->boxes, + extents->clip->num_boxes); + status = _cairo_boxes_intersect (&clear, &tmp, &clear); + if (unlikely (status)) + goto error; + } + + status = compositor->fill_boxes (dst, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + +error: + _cairo_boxes_fini (&clear); + return status; +} + +enum { + NEED_CLIP_REGION = 0x1, + NEED_CLIP_SURFACE = 0x2, + FORCE_CLIP_REGION = 0x4, +}; + +static cairo_bool_t +need_bounded_clip (cairo_composite_rectangles_t *extents) +{ + unsigned int flags = 0; + + if (extents->clip->num_boxes > 1 || + extents->mask.width > extents->unbounded.width || + extents->mask.height > extents->unbounded.height) + { + flags |= NEED_CLIP_REGION; + } + + if (extents->clip->num_boxes > 1 || + extents->mask.width > extents->bounded.width || + extents->mask.height > extents->bounded.height) + { + flags |= FORCE_CLIP_REGION; + } + + if (! _cairo_clip_is_region (extents->clip)) + flags |= NEED_CLIP_SURFACE; + + return flags; +} + +static cairo_bool_t +need_unbounded_clip (cairo_composite_rectangles_t *extents) +{ + unsigned int flags = 0; + if (! extents->is_bounded) { + flags |= NEED_CLIP_REGION; + if (! _cairo_clip_is_region (extents->clip)) + flags |= NEED_CLIP_SURFACE; + } + if (extents->clip->path != NULL) + flags |= NEED_CLIP_SURFACE; + return flags; +} + +static cairo_status_t +clip_and_composite (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + draw_func_t draw_func, + draw_func_t mask_func, + void *draw_closure, + unsigned int need_clip) +{ + cairo_surface_t *dst = extents->surface; + cairo_operator_t op = extents->op; + cairo_pattern_t *source = &extents->source_pattern.base; + cairo_surface_t *src; + int src_x, src_y; + cairo_region_t *clip_region = NULL; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (reduce_alpha_op (extents)) { + op = CAIRO_OPERATOR_ADD; + source = NULL; + } + + if (op == CAIRO_OPERATOR_CLEAR) { + op = CAIRO_OPERATOR_DEST_OUT; + source = NULL; + } + + compositor->acquire (dst); + + if (need_clip & NEED_CLIP_REGION) { + const cairo_rectangle_int_t *limit; + + if ((need_clip & FORCE_CLIP_REGION) == 0) + limit = &extents->unbounded; + else + limit = &extents->destination; + + clip_region = _cairo_clip_get_region (extents->clip); + if (clip_region != NULL && + cairo_region_contains_rectangle (clip_region, + limit) == CAIRO_REGION_OVERLAP_IN) + clip_region = NULL; + + if (clip_region != NULL) { + status = compositor->set_clip_region (dst, clip_region); + if (unlikely (status)) { + compositor->release (dst); + return status; + } + } + } + + if (extents->bounded.width == 0 || extents->bounded.height == 0) + goto skip; + + src = compositor->pattern_to_surface (dst, source, FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (unlikely (status = src->status)) + goto error; + + if (op == CAIRO_OPERATOR_SOURCE) { + status = clip_and_composite_source (compositor, dst, + draw_func, mask_func, draw_closure, + src, src_x, src_y, + extents); + } else { + if (need_clip & NEED_CLIP_SURFACE) { + if (extents->is_bounded) { + status = clip_and_composite_with_mask (compositor, extents, + draw_func, mask_func, + draw_closure, + op, src, src_x, src_y); + } else { + status = clip_and_composite_combine (compositor, extents, + draw_func, draw_closure, + op, src, src_x, src_y); + } + } else { + status = draw_func (compositor, + dst, draw_closure, + op, src, src_x, src_y, + 0, 0, + &extents->bounded, + extents->clip); + } + } + cairo_surface_destroy (src); + +skip: + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { + if (need_clip & NEED_CLIP_SURFACE) + status = fixup_unbounded_with_mask (compositor, extents); + else + status = fixup_unbounded (compositor, extents, NULL); + } + +error: + if (clip_region) + compositor->set_clip_region (dst, NULL); + + compositor->release (dst); + + return status; +} + +/* meta-ops */ + +typedef struct { + cairo_traps_t traps; + cairo_antialias_t antialias; +} composite_traps_info_t; + +static cairo_int_status_t +composite_traps (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, int src_y, + int dst_x, int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + composite_traps_info_t *info = closure; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + return compositor->composite_traps (dst, op, src, + src_x - dst_x, src_y - dst_y, + dst_x, dst_y, + extents, + info->antialias, &info->traps); +} + +typedef struct { + cairo_tristrip_t strip; + cairo_antialias_t antialias; +} composite_tristrip_info_t; + +static cairo_int_status_t +composite_tristrip (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, int src_y, + int dst_x, int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + composite_tristrip_info_t *info = closure; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + return compositor->composite_tristrip (dst, op, src, + src_x - dst_x, src_y - dst_y, + dst_x, dst_y, + extents, + info->antialias, &info->strip); +} + +static cairo_bool_t +is_recording_pattern (const cairo_pattern_t *pattern) +{ + cairo_surface_t *surface; + + if (pattern->type != CAIRO_PATTERN_TYPE_SURFACE) + return FALSE; + + surface = ((const cairo_surface_pattern_t *) pattern)->surface; + surface = _cairo_surface_get_source (surface, NULL); + return _cairo_surface_is_recording (surface); +} + +static cairo_surface_t * +recording_pattern_get_surface (const cairo_pattern_t *pattern) +{ + cairo_surface_t *surface; + + surface = ((const cairo_surface_pattern_t *) pattern)->surface; + return _cairo_surface_get_source (surface, NULL); +} + +static cairo_bool_t +recording_pattern_contains_sample (const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *sample) +{ + cairo_recording_surface_t *surface; + + if (! is_recording_pattern (pattern)) + return FALSE; + + if (pattern->extend == CAIRO_EXTEND_NONE) + return TRUE; + + surface = (cairo_recording_surface_t *) recording_pattern_get_surface (pattern); + if (surface->unbounded) + return TRUE; + + return _cairo_rectangle_contains_rectangle (&surface->extents, sample); +} + +static cairo_bool_t +op_reduces_to_source (cairo_composite_rectangles_t *extents) +{ + if (extents->op == CAIRO_OPERATOR_SOURCE) + return TRUE; + + if (extents->surface->is_clear) + return extents->op == CAIRO_OPERATOR_OVER || extents->op == CAIRO_OPERATOR_ADD; + + return FALSE; +} + +static cairo_status_t +composite_aligned_boxes (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + cairo_operator_t op = extents->op; + cairo_bool_t need_clip_mask = ! _cairo_clip_is_region (extents->clip); + cairo_bool_t op_is_source; + cairo_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (need_clip_mask && + (! extents->is_bounded || extents->op == CAIRO_OPERATOR_SOURCE)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + op_is_source = op_reduces_to_source (extents); + + /* Are we just copying a recording surface? */ + if (! need_clip_mask && op_is_source && + recording_pattern_contains_sample (&extents->source_pattern.base, + &extents->source_sample_area)) + { + cairo_clip_t *recording_clip; + const cairo_pattern_t *source = &extents->source_pattern.base; + const cairo_matrix_t *m; + cairo_matrix_t matrix; + + /* XXX could also do tiling repeat modes... */ + + /* first clear the area about to be overwritten */ + if (! dst->is_clear) { + status = compositor->acquire (dst); + if (unlikely (status)) + return status; + + status = compositor->fill_boxes (dst, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + boxes); + compositor->release (dst); + if (unlikely (status)) + return status; + } + + m = &source->matrix; + if (_cairo_surface_has_device_transform (dst)) { + cairo_matrix_multiply (&matrix, + &source->matrix, + &dst->device_transform); + m = &matrix; + } + + recording_clip = _cairo_clip_from_boxes (boxes); + status = _cairo_recording_surface_replay_with_clip (recording_pattern_get_surface (source), + m, dst, recording_clip); + _cairo_clip_destroy (recording_clip); + + return status; + } + + status = compositor->acquire (dst); + if (unlikely (status)) + return status; + + if (! need_clip_mask && + (op == CAIRO_OPERATOR_CLEAR || + extents->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID)) + { + const cairo_color_t *color; + + if (op == CAIRO_OPERATOR_CLEAR) { + color = CAIRO_COLOR_TRANSPARENT; + } else { + color = &((cairo_solid_pattern_t *) &extents->source_pattern)->color; + if (op_is_source) + op = CAIRO_OPERATOR_SOURCE; + } + + status = compositor->fill_boxes (dst, op, color, boxes); + } + else + { + cairo_surface_t *src, *mask = NULL; + cairo_pattern_t *source = &extents->source_pattern.base; + int src_x, src_y; + int mask_x = 0, mask_y = 0; + + if (need_clip_mask) { + mask = traps_get_clip_surface (compositor, + extents, &extents->bounded); + if (unlikely (mask->status)) + return mask->status; + + mask_x = -extents->bounded.x; + mask_y = -extents->bounded.y; + + if (op == CAIRO_OPERATOR_CLEAR) { + source = NULL; + op = CAIRO_OPERATOR_DEST_OUT; + } + } else if (op_is_source) + op = CAIRO_OPERATOR_SOURCE; + + src = compositor->pattern_to_surface (dst, source, FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (likely (src->status == CAIRO_STATUS_SUCCESS)) { + status = compositor->composite_boxes (dst, op, src, mask, + src_x, src_y, + mask_x, mask_y, + 0, 0, + boxes, &extents->bounded); + cairo_surface_destroy (src); + } else + status = src->status; + + cairo_surface_destroy (mask); + } + + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) + status = fixup_unbounded (compositor, extents, boxes); + + compositor->release (dst); + + return status; +} + +static cairo_status_t +upload_boxes (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_surface_t *dst = extents->surface; + const cairo_pattern_t *source = &extents->source_pattern.base; + cairo_surface_t *src; + cairo_rectangle_int_t limit; + cairo_int_status_t status; + int tx, ty; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + src = _cairo_pattern_get_source((cairo_surface_pattern_t *)source, + &limit); + if (!(src->type == CAIRO_SURFACE_TYPE_IMAGE || src->type == dst->type)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Check that the data is entirely within the image */ + if (extents->bounded.x + tx < limit.x || extents->bounded.y + ty < limit.y) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (extents->bounded.x + extents->bounded.width + tx > limit.x + limit.width || + extents->bounded.y + extents->bounded.height + ty > limit.y + limit.height) + return CAIRO_INT_STATUS_UNSUPPORTED; + + tx += limit.x; + ty += limit.y; + + if (src->type == CAIRO_SURFACE_TYPE_IMAGE) + status = compositor->draw_image_boxes (dst, + (cairo_image_surface_t *)src, + boxes, tx, ty); + else + status = compositor->copy_boxes (dst, src, boxes, &extents->bounded, + tx, ty); + + return status; +} + +static cairo_int_status_t +trim_extents_to_traps (cairo_composite_rectangles_t *extents, + cairo_traps_t *traps) +{ + cairo_box_t box; + + _cairo_traps_extents (traps, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_int_status_t +trim_extents_to_tristrip (cairo_composite_rectangles_t *extents, + cairo_tristrip_t *strip) +{ + cairo_box_t box; + + _cairo_tristrip_extents (strip, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_int_status_t +trim_extents_to_boxes (cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_box_t box; + + _cairo_boxes_extents (boxes, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_int_status_t +boxes_for_traps (cairo_boxes_t *boxes, + cairo_traps_t *traps, + cairo_antialias_t antialias) +{ + int i, j; + + /* first check that the traps are rectilinear */ + if (antialias == CAIRO_ANTIALIAS_NONE) { + for (i = 0; i < traps->num_traps; i++) { + const cairo_trapezoid_t *t = &traps->traps[i]; + if (_cairo_fixed_integer_round_down (t->left.p1.x) != + _cairo_fixed_integer_round_down (t->left.p2.x) || + _cairo_fixed_integer_round_down (t->right.p1.x) != + _cairo_fixed_integer_round_down (t->right.p2.x)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + } else { + for (i = 0; i < traps->num_traps; i++) { + const cairo_trapezoid_t *t = &traps->traps[i]; + if (t->left.p1.x != t->left.p2.x || t->right.p1.x != t->right.p2.x) + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + + _cairo_boxes_init (boxes); + + boxes->chunks.base = (cairo_box_t *) traps->traps; + boxes->chunks.size = traps->num_traps; + + if (antialias != CAIRO_ANTIALIAS_NONE) { + for (i = j = 0; i < traps->num_traps; i++) { + /* Note the traps and boxes alias so we need to take the local copies first. */ + cairo_fixed_t x1 = traps->traps[i].left.p1.x; + cairo_fixed_t x2 = traps->traps[i].right.p1.x; + cairo_fixed_t y1 = traps->traps[i].top; + cairo_fixed_t y2 = traps->traps[i].bottom; + + if (x1 == x2 || y1 == y2) + continue; + + boxes->chunks.base[j].p1.x = x1; + boxes->chunks.base[j].p1.y = y1; + boxes->chunks.base[j].p2.x = x2; + boxes->chunks.base[j].p2.y = y2; + j++; + + if (boxes->is_pixel_aligned) { + boxes->is_pixel_aligned = + _cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) && + _cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2); + } + } + } else { + boxes->is_pixel_aligned = TRUE; + + for (i = j = 0; i < traps->num_traps; i++) { + /* Note the traps and boxes alias so we need to take the local copies first. */ + cairo_fixed_t x1 = traps->traps[i].left.p1.x; + cairo_fixed_t x2 = traps->traps[i].right.p1.x; + cairo_fixed_t y1 = traps->traps[i].top; + cairo_fixed_t y2 = traps->traps[i].bottom; + + /* round down here to match Pixman's behavior when using traps. */ + boxes->chunks.base[j].p1.x = _cairo_fixed_round_down (x1); + boxes->chunks.base[j].p1.y = _cairo_fixed_round_down (y1); + boxes->chunks.base[j].p2.x = _cairo_fixed_round_down (x2); + boxes->chunks.base[j].p2.y = _cairo_fixed_round_down (y2); + j += (boxes->chunks.base[j].p1.x != boxes->chunks.base[j].p2.x && + boxes->chunks.base[j].p1.y != boxes->chunks.base[j].p2.y); + } + } + boxes->chunks.count = j; + boxes->num_boxes = j; + + return CAIRO_INT_STATUS_SUCCESS; +} + +static cairo_status_t +clip_and_composite_boxes (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes); + +static cairo_status_t +clip_and_composite_polygon (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_polygon_t *polygon, + cairo_antialias_t antialias, + cairo_fill_rule_t fill_rule, + cairo_bool_t curvy) +{ + composite_traps_info_t traps; + cairo_surface_t *dst = extents->surface; + cairo_bool_t clip_surface = ! _cairo_clip_is_region (extents->clip); + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (polygon->num_edges == 0) { + status = CAIRO_INT_STATUS_SUCCESS; + + if (! extents->is_bounded) { + cairo_region_t *clip_region = _cairo_clip_get_region (extents->clip); + + if (clip_region && + cairo_region_contains_rectangle (clip_region, + &extents->unbounded) == CAIRO_REGION_OVERLAP_IN) + clip_region = NULL; + + if (clip_region != NULL) { + status = compositor->set_clip_region (dst, clip_region); + if (unlikely (status)) + return status; + } + + if (clip_surface) + status = fixup_unbounded_with_mask (compositor, extents); + else + status = fixup_unbounded (compositor, extents, NULL); + + if (clip_region != NULL) + compositor->set_clip_region (dst, NULL); + } + + return status; + } + + if (extents->clip->path != NULL && extents->is_bounded) { + cairo_polygon_t clipper; + cairo_fill_rule_t clipper_fill_rule; + cairo_antialias_t clipper_antialias; + + status = _cairo_clip_get_polygon (extents->clip, + &clipper, + &clipper_fill_rule, + &clipper_antialias); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + if (clipper_antialias == antialias) { + status = _cairo_polygon_intersect (polygon, fill_rule, + &clipper, clipper_fill_rule); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t * clip = _cairo_clip_copy_region (extents->clip); + _cairo_clip_destroy (extents->clip); + extents->clip = clip; + + fill_rule = CAIRO_FILL_RULE_WINDING; + } + _cairo_polygon_fini (&clipper); + } + } + } + + if (antialias == CAIRO_ANTIALIAS_NONE && curvy) { + cairo_boxes_t boxes; + + _cairo_boxes_init (&boxes); + status = _cairo_rasterise_polygon_to_boxes (polygon, fill_rule, &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + assert (boxes.is_pixel_aligned); + status = clip_and_composite_boxes (compositor, extents, &boxes); + } + _cairo_boxes_fini (&boxes); + if ((status != CAIRO_INT_STATUS_UNSUPPORTED)) + return status; + } + + _cairo_traps_init (&traps.traps); + + if (antialias == CAIRO_ANTIALIAS_NONE && curvy) { + status = _cairo_rasterise_polygon_to_traps (polygon, fill_rule, antialias, &traps.traps); + } else { + status = _cairo_bentley_ottmann_tessellate_polygon (&traps.traps, polygon, fill_rule); + } + if (unlikely (status)) + goto CLEANUP_TRAPS; + + status = trim_extents_to_traps (extents, &traps.traps); + if (unlikely (status)) + goto CLEANUP_TRAPS; + + /* Use a fast path if the trapezoids consist of a set of boxes. */ + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (1) { + cairo_boxes_t boxes; + + status = boxes_for_traps (&boxes, &traps.traps, antialias); + if (status == CAIRO_INT_STATUS_SUCCESS) { + status = clip_and_composite_boxes (compositor, extents, &boxes); + /* XXX need to reconstruct the traps! */ + assert (status != CAIRO_INT_STATUS_UNSUPPORTED); + } + } + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + /* Otherwise render the trapezoids to a mask and composite in the usual + * fashion. + */ + unsigned int flags = 0; + + /* For unbounded operations, the X11 server will estimate the + * affected rectangle and apply the operation to that. However, + * there are cases where this is an overestimate (e.g. the + * clip-fill-{eo,nz}-unbounded test). + * + * The clip will trim that overestimate to our expectations. + */ + if (! extents->is_bounded) + flags |= FORCE_CLIP_REGION; + + traps.antialias = antialias; + status = clip_and_composite (compositor, extents, + composite_traps, NULL, &traps, + need_unbounded_clip (extents) | flags); + } + +CLEANUP_TRAPS: + _cairo_traps_fini (&traps.traps); + + return status; +} + +struct composite_opacity_info { + const cairo_traps_compositor_t *compositor; + uint8_t op; + cairo_surface_t *dst; + cairo_surface_t *src; + int src_x, src_y; + double opacity; +}; + +static void composite_opacity(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct composite_opacity_info *info = closure; + const cairo_traps_compositor_t *compositor = info->compositor; + cairo_surface_t *mask; + int mask_x, mask_y; + cairo_color_t color; + cairo_solid_pattern_t solid; + + _cairo_color_init_rgba (&color, 0, 0, 0, info->opacity * coverage); + _cairo_pattern_init_solid (&solid, &color); + mask = compositor->pattern_to_surface (info->dst, &solid.base, TRUE, + &_cairo_unbounded_rectangle, + &_cairo_unbounded_rectangle, + &mask_x, &mask_y); + if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { + if (info->src) { + compositor->composite (info->dst, info->op, info->src, mask, + x + info->src_x, y + info->src_y, + mask_x, mask_y, + x, y, + w, h); + } else { + compositor->composite (info->dst, info->op, mask, NULL, + mask_x, mask_y, + 0, 0, + x, y, + w, h); + } + } + + cairo_surface_destroy (mask); +} + + +static cairo_int_status_t +composite_opacity_boxes (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + const cairo_solid_pattern_t *mask = closure; + struct composite_opacity_info info; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + info.compositor = compositor; + info.op = op; + info.dst = dst; + + info.src = src; + info.src_x = src_x; + info.src_y = src_y; + + info.opacity = mask->color.alpha / (double) 0xffff; + + /* XXX for lots of boxes create a clip region for the fully opaque areas */ + for (i = 0; i < clip->num_boxes; i++) + do_unaligned_box(composite_opacity, &info, + &clip->boxes[i], dst_x, dst_y); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_boxes (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + cairo_traps_t traps; + cairo_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = _cairo_traps_init_boxes (&traps, closure); + if (unlikely (status)) + return status; + + status = compositor->composite_traps (dst, op, src, + src_x - dst_x, src_y - dst_y, + dst_x, dst_y, + extents, + CAIRO_ANTIALIAS_DEFAULT, &traps); + _cairo_traps_fini (&traps); + + return status; +} + +static cairo_status_t +clip_and_composite_boxes (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (boxes->num_boxes == 0 && extents->is_bounded) + return CAIRO_STATUS_SUCCESS; + + status = trim_extents_to_boxes (extents, boxes); + if (unlikely (status)) + return status; + + if (boxes->is_pixel_aligned && extents->clip->path == NULL && + extents->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && + (op_reduces_to_source (extents) || + (extents->op == CAIRO_OPERATOR_OVER && + (extents->source_pattern.surface.surface->content & CAIRO_CONTENT_ALPHA) == 0))) + { + status = upload_boxes (compositor, extents, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ + if (extents->clip->path != NULL && extents->is_bounded) { + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + cairo_clip_t *clip; + + clip = _cairo_clip_copy (extents->clip); + clip = _cairo_clip_intersect_boxes (clip, boxes); + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + status = _cairo_clip_get_polygon (clip, &polygon, + &fill_rule, &antialias); + _cairo_clip_path_destroy (clip->path); + clip->path = NULL; + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t *saved_clip = extents->clip; + extents->clip = clip; + + status = clip_and_composite_polygon (compositor, extents, &polygon, + antialias, fill_rule, FALSE); + + clip = extents->clip; + extents->clip = saved_clip; + + _cairo_polygon_fini (&polygon); + } + _cairo_clip_destroy (clip); + + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + /* Use a fast path if the boxes are pixel aligned (or nearly aligned!) */ + if (boxes->is_pixel_aligned) { + status = composite_aligned_boxes (compositor, extents, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + return clip_and_composite (compositor, extents, + composite_boxes, NULL, boxes, + need_unbounded_clip (extents)); +} + +static cairo_int_status_t +composite_traps_as_boxes (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + composite_traps_info_t *info) +{ + cairo_boxes_t boxes; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (! _cairo_traps_to_boxes (&info->traps, info->antialias, &boxes)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return clip_and_composite_boxes (compositor, extents, &boxes); +} + +static cairo_int_status_t +clip_and_composite_traps (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + composite_traps_info_t *info, + unsigned flags) +{ + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = trim_extents_to_traps (extents, &info->traps); + if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) + return status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if ((flags & FORCE_CLIP_REGION) == 0) + status = composite_traps_as_boxes (compositor, extents, info); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + /* For unbounded operations, the X11 server will estimate the + * affected rectangle and apply the operation to that. However, + * there are cases where this is an overestimate (e.g. the + * clip-fill-{eo,nz}-unbounded test). + * + * The clip will trim that overestimate to our expectations. + */ + if (! extents->is_bounded) + flags |= FORCE_CLIP_REGION; + + status = clip_and_composite (compositor, extents, + composite_traps, NULL, info, + need_unbounded_clip (extents) | flags); + } + + return status; +} + +static cairo_int_status_t +clip_and_composite_tristrip (const cairo_traps_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + composite_tristrip_info_t *info) +{ + cairo_int_status_t status; + unsigned int flags = 0; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = trim_extents_to_tristrip (extents, &info->strip); + if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) + return status; + + if (! extents->is_bounded) + flags |= FORCE_CLIP_REGION; + + status = clip_and_composite (compositor, extents, + composite_tristrip, NULL, info, + need_unbounded_clip (extents) | flags); + + return status; +} + +struct composite_mask { + cairo_surface_t *mask; + int mask_x, mask_y; +}; + +static cairo_int_status_t +composite_mask (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + struct composite_mask *data = closure; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (src != NULL) { + compositor->composite (dst, op, src, data->mask, + extents->x + src_x, extents->y + src_y, + extents->x + data->mask_x, extents->y + data->mask_y, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + } else { + compositor->composite (dst, op, data->mask, NULL, + extents->x + data->mask_x, extents->y + data->mask_y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + } + + return CAIRO_STATUS_SUCCESS; +} + +struct composite_box_info { + const cairo_traps_compositor_t *compositor; + cairo_surface_t *dst; + cairo_surface_t *src; + int src_x, src_y; + uint8_t op; +}; + +static void composite_box(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct composite_box_info *info = closure; + const cairo_traps_compositor_t *compositor = info->compositor; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (! CAIRO_ALPHA_SHORT_IS_OPAQUE (coverage)) { + cairo_surface_t *mask; + cairo_color_t color; + cairo_solid_pattern_t solid; + int mask_x, mask_y; + + _cairo_color_init_rgba (&color, 0, 0, 0, coverage / (double)0xffff); + _cairo_pattern_init_solid (&solid, &color); + + mask = compositor->pattern_to_surface (info->dst, &solid.base, FALSE, + &_cairo_unbounded_rectangle, + &_cairo_unbounded_rectangle, + &mask_x, &mask_y); + + if (likely (mask->status == CAIRO_STATUS_SUCCESS)) { + compositor->composite (info->dst, info->op, info->src, mask, + x + info->src_x, y + info->src_y, + mask_x, mask_y, + x, y, + w, h); + } + + cairo_surface_destroy (mask); + } else { + compositor->composite (info->dst, info->op, info->src, NULL, + x + info->src_x, y + info->src_y, + 0, 0, + x, y, + w, h); + } +} + +static cairo_int_status_t +composite_mask_clip_boxes (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + struct composite_mask *data = closure; + struct composite_box_info info; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + info.compositor = compositor; + info.op = CAIRO_OPERATOR_SOURCE; + info.dst = dst; + info.src = data->mask; + info.src_x = data->mask_x; + info.src_y = data->mask_y; + + info.src_x += dst_x; + info.src_y += dst_y; + + for (i = 0; i < clip->num_boxes; i++) + do_unaligned_box(composite_box, &info, &clip->boxes[i], dst_x, dst_y); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_mask_clip (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + struct composite_mask *data = closure; + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + composite_traps_info_t info; + cairo_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = _cairo_clip_get_polygon (clip, &polygon, + &fill_rule, &info.antialias); + if (unlikely (status)) + return status; + + _cairo_traps_init (&info.traps); + status = _cairo_bentley_ottmann_tessellate_polygon (&info.traps, + &polygon, + fill_rule); + _cairo_polygon_fini (&polygon); + if (unlikely (status)) + return status; + + status = composite_traps (compositor, dst, &info, + CAIRO_OPERATOR_SOURCE, + data->mask, + data->mask_x + dst_x, data->mask_y + dst_y, + dst_x, dst_y, + extents, NULL); + _cairo_traps_fini (&info.traps); + + return status; +} + +/* high-level compositor interface */ + +static cairo_int_status_t +_cairo_traps_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t*)_compositor; + cairo_boxes_t boxes; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + _cairo_clip_steal_boxes (extents->clip, &boxes); + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_clip_unsteal_boxes (extents->clip, &boxes); + + return status; +} + +static cairo_int_status_t +_cairo_traps_compositor_mask (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t*)_compositor; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + if (extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && + extents->clip->path == NULL) { + status = clip_and_composite (compositor, extents, + composite_opacity_boxes, + composite_opacity_boxes, + &extents->mask_pattern, + need_unbounded_clip (extents)); + } else { + struct composite_mask data; + + data.mask = compositor->pattern_to_surface (extents->surface, + &extents->mask_pattern.base, + TRUE, + &extents->bounded, + &extents->mask_sample_area, + &data.mask_x, + &data.mask_y); + if (unlikely (data.mask->status)) + return data.mask->status; + + status = clip_and_composite (compositor, extents, + composite_mask, + extents->clip->path ? composite_mask_clip : composite_mask_clip_boxes, + &data, need_bounded_clip (extents)); + + cairo_surface_destroy (data.mask); + } + + return status; +} + +static cairo_int_status_t +_cairo_traps_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t *)_compositor; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_stroke_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, extents->clip); + status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, + style, + ctm, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED && 0 && + _cairo_clip_is_region (extents->clip)) /* XXX */ + { + composite_tristrip_info_t info; + + info.antialias = antialias; + _cairo_tristrip_init_with_clip (&info.strip, extents->clip); + status = _cairo_path_fixed_stroke_to_tristrip (path, style, + ctm, ctm_inverse, + tolerance, + &info.strip); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_tristrip (compositor, extents, &info); + _cairo_tristrip_fini (&info.strip); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED && + path->has_curve_to && antialias == CAIRO_ANTIALIAS_NONE) { + cairo_polygon_t polygon; + + _cairo_polygon_init_with_clip (&polygon, extents->clip); + status = _cairo_path_fixed_stroke_to_polygon (path, style, + ctm, ctm_inverse, + tolerance, + &polygon); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_polygon (compositor, + extents, &polygon, + CAIRO_ANTIALIAS_NONE, + CAIRO_FILL_RULE_WINDING, + TRUE); + _cairo_polygon_fini (&polygon); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_int_status_t (*func) (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_traps_t *traps); + composite_traps_info_t info; + unsigned flags; + + if (antialias == CAIRO_ANTIALIAS_BEST || antialias == CAIRO_ANTIALIAS_GOOD) { + func = _cairo_path_fixed_stroke_polygon_to_traps; + flags = 0; + } else { + func = _cairo_path_fixed_stroke_to_traps; + flags = need_bounded_clip (extents) & ~NEED_CLIP_SURFACE; + } + + info.antialias = antialias; + _cairo_traps_init_with_clip (&info.traps, extents->clip); + status = func (path, style, ctm, ctm_inverse, tolerance, &info.traps); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_traps (compositor, extents, &info, flags); + _cairo_traps_fini (&info.traps); + } + + return status; +} + +static cairo_int_status_t +_cairo_traps_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t *)_compositor; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_fill_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, extents->clip); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + fill_rule, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite_boxes (compositor, extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + cairo_polygon_t polygon; + +#if 0 + if (extents->mask.width > extents->unbounded.width || + extents->mask.height > extents->unbounded.height) + { + cairo_box_t limits; + _cairo_box_from_rectangle (&limits, &extents->unbounded); + _cairo_polygon_init (&polygon, &limits, 1); + } + else + { + _cairo_polygon_init (&polygon, NULL, 0); + } + + status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, + extents->clip->boxes, + extents->clip->num_boxes); + } +#else + _cairo_polygon_init_with_clip (&polygon, extents->clip); + status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); +#endif + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + status = clip_and_composite_polygon (compositor, extents, &polygon, + antialias, fill_rule, path->has_curve_to); + } + _cairo_polygon_fini (&polygon); + } + + return status; +} + +static cairo_int_status_t +composite_glyphs (const cairo_traps_compositor_t *compositor, + cairo_surface_t *dst, + void *closure, + cairo_operator_t op, + cairo_surface_t *src, + int src_x, int src_y, + int dst_x, int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + cairo_composite_glyphs_info_t *info = closure; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (op == CAIRO_OPERATOR_ADD && (dst->content & CAIRO_CONTENT_COLOR) == 0) + info->use_mask = 0; + + return compositor->composite_glyphs (dst, op, src, + src_x, src_y, + dst_x, dst_y, + info); +} + +static cairo_int_status_t +_cairo_traps_compositor_glyphs (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + const cairo_traps_compositor_t *compositor = (cairo_traps_compositor_t *)_compositor; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + status = compositor->check_composite (extents); + if (unlikely (status)) + return status; + + _cairo_scaled_font_freeze_cache (scaled_font); + status = compositor->check_composite_glyphs (extents, + scaled_font, glyphs, + &num_glyphs); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_composite_glyphs_info_t info; + + info.font = scaled_font; + info.glyphs = glyphs; + info.num_glyphs = num_glyphs; + info.use_mask = overlap || ! extents->is_bounded; + info.extents = extents->bounded; + + status = clip_and_composite (compositor, extents, + composite_glyphs, NULL, &info, + need_bounded_clip (extents) | FORCE_CLIP_REGION); + } + _cairo_scaled_font_thaw_cache (scaled_font); + + return status; +} + +void +_cairo_traps_compositor_init (cairo_traps_compositor_t *compositor, + const cairo_compositor_t *delegate) +{ + compositor->base.delegate = delegate; + + compositor->base.paint = _cairo_traps_compositor_paint; + compositor->base.mask = _cairo_traps_compositor_mask; + compositor->base.fill = _cairo_traps_compositor_fill; + compositor->base.stroke = _cairo_traps_compositor_stroke; + compositor->base.glyphs = _cairo_traps_compositor_glyphs; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-traps-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-traps-private.h new file mode 100644 index 00000000000..dcaf40d1863 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-traps-private.h @@ -0,0 +1,143 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_TRAPS_PRIVATE_H +#define CAIRO_TRAPS_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" +#include "cairo-types-private.h" + +CAIRO_BEGIN_DECLS + +struct _cairo_traps { + cairo_status_t status; + + cairo_box_t bounds; + const cairo_box_t *limits; + int num_limits; + + unsigned int maybe_region : 1; /* hint: 0 implies that it cannot be */ + unsigned int has_intersections : 1; + unsigned int is_rectilinear : 1; + unsigned int is_rectangular : 1; + + int num_traps; + int traps_size; + cairo_trapezoid_t *traps; + cairo_trapezoid_t traps_embedded[16]; +}; + +/* cairo-traps.c */ +cairo_private void +_cairo_traps_init (cairo_traps_t *traps); + +cairo_private void +_cairo_traps_init_with_clip (cairo_traps_t *traps, + const cairo_clip_t *clip); + +cairo_private void +_cairo_traps_limit (cairo_traps_t *traps, + const cairo_box_t *boxes, + int num_boxes); + +cairo_private cairo_status_t +_cairo_traps_init_boxes (cairo_traps_t *traps, + const cairo_boxes_t *boxes); + +cairo_private void +_cairo_traps_clear (cairo_traps_t *traps); + +cairo_private void +_cairo_traps_fini (cairo_traps_t *traps); + +#define _cairo_traps_status(T) (T)->status + +cairo_private void +_cairo_traps_translate (cairo_traps_t *traps, int x, int y); + +cairo_private void +_cairo_traps_tessellate_triangle_with_edges (cairo_traps_t *traps, + const cairo_point_t t[3], + const cairo_point_t edges[4]); + +cairo_private void +_cairo_traps_tessellate_convex_quad (cairo_traps_t *traps, + const cairo_point_t q[4]); + +cairo_private cairo_status_t +_cairo_traps_tessellate_rectangle (cairo_traps_t *traps, + const cairo_point_t *top_left, + const cairo_point_t *bottom_right); + +cairo_private void +_cairo_traps_add_trap (cairo_traps_t *traps, + cairo_fixed_t top, cairo_fixed_t bottom, + const cairo_line_t *left, + const cairo_line_t *right); + +cairo_private int +_cairo_traps_contain (const cairo_traps_t *traps, + double x, double y); + +cairo_private void +_cairo_traps_extents (const cairo_traps_t *traps, + cairo_box_t *extents); + +cairo_private cairo_int_status_t +_cairo_traps_extract_region (cairo_traps_t *traps, + cairo_antialias_t antialias, + cairo_region_t **region); + +cairo_private cairo_bool_t +_cairo_traps_to_boxes (cairo_traps_t *traps, + cairo_antialias_t antialias, + cairo_boxes_t *boxes); + +cairo_private cairo_status_t +_cairo_traps_path (const cairo_traps_t *traps, + cairo_path_fixed_t *path); + +cairo_private cairo_int_status_t +_cairo_rasterise_polygon_to_traps (cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias, + cairo_traps_t *traps); + +CAIRO_END_DECLS + +#endif /* CAIRO_TRAPS_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-traps.c b/Build/source/libs/cairo/cairo-src/src/cairo-traps.c new file mode 100644 index 00000000000..3aa0052f91f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-traps.c @@ -0,0 +1,1123 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* + * Copyright © 2002 Keith Packard + * Copyright © 2007 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith R. Packard + * Carl D. Worth + * + * 2002-07-15: Converted from XRenderCompositeDoublePoly to #cairo_trap_t. Carl D. Worth + */ + +#include "cairoint.h" + +#include "cairo-box-inline.h" +#include "cairo-boxes-private.h" +#include "cairo-error-private.h" +#include "cairo-line-private.h" +#include "cairo-region-private.h" +#include "cairo-slope-private.h" +#include "cairo-traps-private.h" +#include "cairo-spans-private.h" + +/* private functions */ + +void +_cairo_traps_init (cairo_traps_t *traps) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (traps, sizeof (cairo_traps_t))); + + traps->status = CAIRO_STATUS_SUCCESS; + + traps->maybe_region = 1; + traps->is_rectilinear = 0; + traps->is_rectangular = 0; + + traps->num_traps = 0; + + traps->traps_size = ARRAY_LENGTH (traps->traps_embedded); + traps->traps = traps->traps_embedded; + + traps->num_limits = 0; + traps->has_intersections = FALSE; +} + +void +_cairo_traps_limit (cairo_traps_t *traps, + const cairo_box_t *limits, + int num_limits) +{ + int i; + + traps->limits = limits; + traps->num_limits = num_limits; + + traps->bounds = limits[0]; + for (i = 1; i < num_limits; i++) + _cairo_box_add_box (&traps->bounds, &limits[i]); +} + +void +_cairo_traps_init_with_clip (cairo_traps_t *traps, + const cairo_clip_t *clip) +{ + _cairo_traps_init (traps); + if (clip) + _cairo_traps_limit (traps, clip->boxes, clip->num_boxes); +} + +void +_cairo_traps_clear (cairo_traps_t *traps) +{ + traps->status = CAIRO_STATUS_SUCCESS; + + traps->maybe_region = 1; + traps->is_rectilinear = 0; + traps->is_rectangular = 0; + + traps->num_traps = 0; + traps->has_intersections = FALSE; +} + +void +_cairo_traps_fini (cairo_traps_t *traps) +{ + if (traps->traps != traps->traps_embedded) + free (traps->traps); + + VG (VALGRIND_MAKE_MEM_NOACCESS (traps, sizeof (cairo_traps_t))); +} + +/* make room for at least one more trap */ +static cairo_bool_t +_cairo_traps_grow (cairo_traps_t *traps) +{ + cairo_trapezoid_t *new_traps; + int new_size = 4 * traps->traps_size; + + if (CAIRO_INJECT_FAULT ()) { + traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + if (traps->traps == traps->traps_embedded) { + new_traps = _cairo_malloc_ab (new_size, sizeof (cairo_trapezoid_t)); + if (new_traps != NULL) + memcpy (new_traps, traps->traps, sizeof (traps->traps_embedded)); + } else { + new_traps = _cairo_realloc_ab (traps->traps, + new_size, sizeof (cairo_trapezoid_t)); + } + + if (unlikely (new_traps == NULL)) { + traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + traps->traps = new_traps; + traps->traps_size = new_size; + return TRUE; +} + +void +_cairo_traps_add_trap (cairo_traps_t *traps, + cairo_fixed_t top, cairo_fixed_t bottom, + const cairo_line_t *left, + const cairo_line_t *right) +{ + cairo_trapezoid_t *trap; + + assert (left->p1.y != left->p2.y); + assert (right->p1.y != right->p2.y); + assert (bottom > top); + + if (unlikely (traps->num_traps == traps->traps_size)) { + if (unlikely (! _cairo_traps_grow (traps))) + return; + } + + trap = &traps->traps[traps->num_traps++]; + trap->top = top; + trap->bottom = bottom; + trap->left = *left; + trap->right = *right; +} + +static void +_cairo_traps_add_clipped_trap (cairo_traps_t *traps, + cairo_fixed_t _top, cairo_fixed_t _bottom, + const cairo_line_t *_left, + const cairo_line_t *_right) +{ + /* Note: With the goofy trapezoid specification, (where an + * arbitrary two points on the lines can specified for the left + * and right edges), these limit checks would not work in + * general. For example, one can imagine a trapezoid entirely + * within the limits, but with two points used to specify the left + * edge entirely to the right of the limits. Fortunately, for our + * purposes, cairo will never generate such a crazy + * trapezoid. Instead, cairo always uses for its points the + * extreme positions of the edge that are visible on at least some + * trapezoid. With this constraint, it's impossible for both + * points to be outside the limits while the relevant edge is + * entirely inside the limits. + */ + if (traps->num_limits) { + const cairo_box_t *b = &traps->bounds; + cairo_fixed_t top = _top, bottom = _bottom; + cairo_line_t left = *_left, right = *_right; + + /* Trivially reject if trapezoid is entirely to the right or + * to the left of the limits. */ + if (left.p1.x >= b->p2.x && left.p2.x >= b->p2.x) + return; + + if (right.p1.x <= b->p1.x && right.p2.x <= b->p1.x) + return; + + /* And reject if the trapezoid is entirely above or below */ + if (top >= b->p2.y || bottom <= b->p1.y) + return; + + /* Otherwise, clip the trapezoid to the limits. We only clip + * where an edge is entirely outside the limits. If we wanted + * to be more clever, we could handle cases where a trapezoid + * edge intersects the edge of the limits, but that would + * require slicing this trapezoid into multiple trapezoids, + * and I'm not sure the effort would be worth it. */ + if (top < b->p1.y) + top = b->p1.y; + + if (bottom > b->p2.y) + bottom = b->p2.y; + + if (left.p1.x <= b->p1.x && left.p2.x <= b->p1.x) + left.p1.x = left.p2.x = b->p1.x; + + if (right.p1.x >= b->p2.x && right.p2.x >= b->p2.x) + right.p1.x = right.p2.x = b->p2.x; + + /* Trivial discards for empty trapezoids that are likely to + * be produced by our tessellators (most notably convex_quad + * when given a simple rectangle). + */ + if (top >= bottom) + return; + + /* cheap colinearity check */ + if (right.p1.x <= left.p1.x && right.p1.y == left.p1.y && + right.p2.x <= left.p2.x && right.p2.y == left.p2.y) + return; + + _cairo_traps_add_trap (traps, top, bottom, &left, &right); + } else + _cairo_traps_add_trap (traps, _top, _bottom, _left, _right); +} + +static int +_compare_point_fixed_by_y (const void *av, const void *bv) +{ + const cairo_point_t *a = av, *b = bv; + int ret = a->y - b->y; + if (ret == 0) + ret = a->x - b->x; + return ret; +} + +void +_cairo_traps_tessellate_convex_quad (cairo_traps_t *traps, + const cairo_point_t q[4]) +{ + int a, b, c, d; + int i; + cairo_slope_t ab, ad; + cairo_bool_t b_left_of_d; + cairo_line_t left; + cairo_line_t right; + + /* Choose a as a point with minimal y */ + a = 0; + for (i = 1; i < 4; i++) + if (_compare_point_fixed_by_y (&q[i], &q[a]) < 0) + a = i; + + /* b and d are adjacent to a, while c is opposite */ + b = (a + 1) % 4; + c = (a + 2) % 4; + d = (a + 3) % 4; + + /* Choose between b and d so that b.y is less than d.y */ + if (_compare_point_fixed_by_y (&q[d], &q[b]) < 0) { + b = (a + 3) % 4; + d = (a + 1) % 4; + } + + /* Without freedom left to choose anything else, we have four + * cases to tessellate. + * + * First, we have to determine the Y-axis sort of the four + * vertices, (either abcd or abdc). After that we need to detemine + * which edges will be "left" and which will be "right" in the + * resulting trapezoids. This can be determined by computing a + * slope comparison of ab and ad to determine if b is left of d or + * not. + * + * Note that "left of" here is in the sense of which edges should + * be the left vs. right edges of the trapezoid. In particular, b + * left of d does *not* mean that b.x is less than d.x. + * + * This should hopefully be made clear in the lame ASCII art + * below. Since the same slope comparison is used in all cases, we + * compute it before testing for the Y-value sort. */ + + /* Note: If a == b then the ab slope doesn't give us any + * information. In that case, we can replace it with the ac (or + * equivalenly the bc) slope which gives us exactly the same + * information we need. At worst the names of the identifiers ab + * and b_left_of_d are inaccurate in this case, (would be ac, and + * c_left_of_d). */ + if (q[a].x == q[b].x && q[a].y == q[b].y) + _cairo_slope_init (&ab, &q[a], &q[c]); + else + _cairo_slope_init (&ab, &q[a], &q[b]); + + _cairo_slope_init (&ad, &q[a], &q[d]); + + b_left_of_d = _cairo_slope_compare (&ab, &ad) > 0; + + if (q[c].y <= q[d].y) { + if (b_left_of_d) { + /* Y-sort is abcd and b is left of d, (slope(ab) > slope (ad)) + * + * top bot left right + * _a a a + * / / /| |\ a.y b.y ab ad + * b / b | b \ + * / / | | \ \ b.y c.y bc ad + * c / c | c \ + * | / \| \ \ c.y d.y cd ad + * d d d + */ + left.p1 = q[a]; left.p2 = q[b]; + right.p1 = q[a]; right.p2 = q[d]; + _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); + left.p1 = q[b]; left.p2 = q[c]; + _cairo_traps_add_clipped_trap (traps, q[b].y, q[c].y, &left, &right); + left.p1 = q[c]; left.p2 = q[d]; + _cairo_traps_add_clipped_trap (traps, q[c].y, q[d].y, &left, &right); + } else { + /* Y-sort is abcd and b is right of d, (slope(ab) <= slope (ad)) + * + * a a a_ + * /| |\ \ \ a.y b.y ad ab + * / b | b \ b + * / / | | \ \ b.y c.y ad bc + * / c | c \ c + * / / |/ \ | c.y d.y ad cd + * d d d + */ + left.p1 = q[a]; left.p2 = q[d]; + right.p1 = q[a]; right.p2 = q[b]; + _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); + right.p1 = q[b]; right.p2 = q[c]; + _cairo_traps_add_clipped_trap (traps, q[b].y, q[c].y, &left, &right); + right.p1 = q[c]; right.p2 = q[d]; + _cairo_traps_add_clipped_trap (traps, q[c].y, q[d].y, &left, &right); + } + } else { + if (b_left_of_d) { + /* Y-sort is abdc and b is left of d, (slope (ab) > slope (ad)) + * + * a a a + * // / \ |\ a.y b.y ab ad + * /b/ b \ b \ + * / / \ \ \ \ b.y d.y bc ad + * /d/ \ d \ d + * // \ / \| d.y c.y bc dc + * c c c + */ + left.p1 = q[a]; left.p2 = q[b]; + right.p1 = q[a]; right.p2 = q[d]; + _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); + left.p1 = q[b]; left.p2 = q[c]; + _cairo_traps_add_clipped_trap (traps, q[b].y, q[d].y, &left, &right); + right.p1 = q[d]; right.p2 = q[c]; + _cairo_traps_add_clipped_trap (traps, q[d].y, q[c].y, &left, &right); + } else { + /* Y-sort is abdc and b is right of d, (slope (ab) <= slope (ad)) + * + * a a a + * /| / \ \\ a.y b.y ad ab + * / b / b \b\ + * / / / / \ \ b.y d.y ad bc + * d / d / \d\ + * |/ \ / \\ d.y c.y dc bc + * c c c + */ + left.p1 = q[a]; left.p2 = q[d]; + right.p1 = q[a]; right.p2 = q[b]; + _cairo_traps_add_clipped_trap (traps, q[a].y, q[b].y, &left, &right); + right.p1 = q[b]; right.p2 = q[c]; + _cairo_traps_add_clipped_trap (traps, q[b].y, q[d].y, &left, &right); + left.p1 = q[d]; left.p2 = q[c]; + _cairo_traps_add_clipped_trap (traps, q[d].y, q[c].y, &left, &right); + } + } +} + +static void add_tri (cairo_traps_t *traps, + int y1, int y2, + const cairo_line_t *left, + const cairo_line_t *right) +{ + if (y2 < y1) { + int tmp = y1; + y1 = y2; + y2 = tmp; + } + + if (cairo_lines_compare_at_y (left, right, y1) > 0) { + const cairo_line_t *tmp = left; + left = right; + right = tmp; + } + + _cairo_traps_add_clipped_trap (traps, y1, y2, left, right); +} + +void +_cairo_traps_tessellate_triangle_with_edges (cairo_traps_t *traps, + const cairo_point_t t[3], + const cairo_point_t edges[4]) +{ + cairo_line_t lines[3]; + + if (edges[0].y <= edges[1].y) { + lines[0].p1 = edges[0]; + lines[0].p2 = edges[1]; + } else { + lines[0].p1 = edges[1]; + lines[0].p2 = edges[0]; + } + + if (edges[2].y <= edges[3].y) { + lines[1].p1 = edges[2]; + lines[1].p2 = edges[3]; + } else { + lines[1].p1 = edges[3]; + lines[1].p2 = edges[2]; + } + + if (t[1].y == t[2].y) { + add_tri (traps, t[0].y, t[1].y, &lines[0], &lines[1]); + return; + } + + if (t[1].y <= t[2].y) { + lines[2].p1 = t[1]; + lines[2].p2 = t[2]; + } else { + lines[2].p1 = t[2]; + lines[2].p2 = t[1]; + } + + if (((t[1].y - t[0].y) < 0) ^ ((t[2].y - t[0].y) < 0)) { + add_tri (traps, t[0].y, t[1].y, &lines[0], &lines[2]); + add_tri (traps, t[0].y, t[2].y, &lines[1], &lines[2]); + } else if (abs(t[1].y - t[0].y) < abs(t[2].y - t[0].y)) { + add_tri (traps, t[0].y, t[1].y, &lines[0], &lines[1]); + add_tri (traps, t[1].y, t[2].y, &lines[2], &lines[1]); + } else { + add_tri (traps, t[0].y, t[2].y, &lines[1], &lines[0]); + add_tri (traps, t[1].y, t[2].y, &lines[2], &lines[0]); + } +} + +/** + * _cairo_traps_init_boxes: + * @traps: a #cairo_traps_t + * @box: an array box that will each be converted to a single trapezoid + * to store in @traps. + * + * Initializes a #cairo_traps_t to contain an array of rectangular + * trapezoids. + **/ +cairo_status_t +_cairo_traps_init_boxes (cairo_traps_t *traps, + const cairo_boxes_t *boxes) +{ + cairo_trapezoid_t *trap; + const struct _cairo_boxes_chunk *chunk; + + _cairo_traps_init (traps); + + while (traps->traps_size < boxes->num_boxes) { + if (unlikely (! _cairo_traps_grow (traps))) { + _cairo_traps_fini (traps); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + traps->num_traps = boxes->num_boxes; + traps->is_rectilinear = TRUE; + traps->is_rectangular = TRUE; + traps->maybe_region = boxes->is_pixel_aligned; + + trap = &traps->traps[0]; + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box; + int i; + + box = chunk->base; + for (i = 0; i < chunk->count; i++) { + trap->top = box->p1.y; + trap->bottom = box->p2.y; + + trap->left.p1 = box->p1; + trap->left.p2.x = box->p1.x; + trap->left.p2.y = box->p2.y; + + trap->right.p1.x = box->p2.x; + trap->right.p1.y = box->p1.y; + trap->right.p2 = box->p2; + + box++, trap++; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_traps_tessellate_rectangle (cairo_traps_t *traps, + const cairo_point_t *top_left, + const cairo_point_t *bottom_right) +{ + cairo_line_t left; + cairo_line_t right; + cairo_fixed_t top, bottom; + + if (top_left->y == bottom_right->y) + return CAIRO_STATUS_SUCCESS; + + if (top_left->x == bottom_right->x) + return CAIRO_STATUS_SUCCESS; + + left.p1.x = left.p2.x = top_left->x; + left.p1.y = right.p1.y = top_left->y; + right.p1.x = right.p2.x = bottom_right->x; + left.p2.y = right.p2.y = bottom_right->y; + + top = top_left->y; + bottom = bottom_right->y; + + if (traps->num_limits) { + cairo_bool_t reversed; + int n; + + if (top >= traps->bounds.p2.y || bottom <= traps->bounds.p1.y) + return CAIRO_STATUS_SUCCESS; + + /* support counter-clockwise winding for rectangular tessellation */ + reversed = top_left->x > bottom_right->x; + if (reversed) { + right.p1.x = right.p2.x = top_left->x; + left.p1.x = left.p2.x = bottom_right->x; + } + + if (left.p1.x >= traps->bounds.p2.x || right.p1.x <= traps->bounds.p1.x) + return CAIRO_STATUS_SUCCESS; + + for (n = 0; n < traps->num_limits; n++) { + const cairo_box_t *limits = &traps->limits[n]; + cairo_line_t _left, _right; + cairo_fixed_t _top, _bottom; + + if (top >= limits->p2.y) + continue; + if (bottom <= limits->p1.y) + continue; + + /* Trivially reject if trapezoid is entirely to the right or + * to the left of the limits. */ + if (left.p1.x >= limits->p2.x) + continue; + if (right.p1.x <= limits->p1.x) + continue; + + /* Otherwise, clip the trapezoid to the limits. */ + _top = top; + if (_top < limits->p1.y) + _top = limits->p1.y; + + _bottom = bottom; + if (_bottom > limits->p2.y) + _bottom = limits->p2.y; + + if (_bottom <= _top) + continue; + + _left = left; + if (_left.p1.x < limits->p1.x) { + _left.p1.x = limits->p1.x; + _left.p1.y = limits->p1.y; + _left.p2.x = limits->p1.x; + _left.p2.y = limits->p2.y; + } + + _right = right; + if (_right.p1.x > limits->p2.x) { + _right.p1.x = limits->p2.x; + _right.p1.y = limits->p1.y; + _right.p2.x = limits->p2.x; + _right.p2.y = limits->p2.y; + } + + if (left.p1.x >= right.p1.x) + continue; + + if (reversed) + _cairo_traps_add_trap (traps, _top, _bottom, &_right, &_left); + else + _cairo_traps_add_trap (traps, _top, _bottom, &_left, &_right); + } + } else { + _cairo_traps_add_trap (traps, top, bottom, &left, &right); + } + + return traps->status; +} + +void +_cairo_traps_translate (cairo_traps_t *traps, int x, int y) +{ + cairo_fixed_t xoff, yoff; + cairo_trapezoid_t *t; + int i; + + /* Ugh. The cairo_composite/(Render) interface doesn't allow + an offset for the trapezoids. Need to manually shift all + the coordinates to align with the offset origin of the + intermediate surface. */ + + xoff = _cairo_fixed_from_int (x); + yoff = _cairo_fixed_from_int (y); + + for (i = 0, t = traps->traps; i < traps->num_traps; i++, t++) { + t->top += yoff; + t->bottom += yoff; + t->left.p1.x += xoff; + t->left.p1.y += yoff; + t->left.p2.x += xoff; + t->left.p2.y += yoff; + t->right.p1.x += xoff; + t->right.p1.y += yoff; + t->right.p2.x += xoff; + t->right.p2.y += yoff; + } +} + +void +_cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps, + cairo_trapezoid_t *src_traps, + int num_traps, + double tx, double ty, + double sx, double sy) +{ + int i; + cairo_fixed_t xoff = _cairo_fixed_from_double (tx); + cairo_fixed_t yoff = _cairo_fixed_from_double (ty); + + if (sx == 1.0 && sy == 1.0) { + for (i = 0; i < num_traps; i++) { + offset_traps[i].top = src_traps[i].top + yoff; + offset_traps[i].bottom = src_traps[i].bottom + yoff; + offset_traps[i].left.p1.x = src_traps[i].left.p1.x + xoff; + offset_traps[i].left.p1.y = src_traps[i].left.p1.y + yoff; + offset_traps[i].left.p2.x = src_traps[i].left.p2.x + xoff; + offset_traps[i].left.p2.y = src_traps[i].left.p2.y + yoff; + offset_traps[i].right.p1.x = src_traps[i].right.p1.x + xoff; + offset_traps[i].right.p1.y = src_traps[i].right.p1.y + yoff; + offset_traps[i].right.p2.x = src_traps[i].right.p2.x + xoff; + offset_traps[i].right.p2.y = src_traps[i].right.p2.y + yoff; + } + } else { + cairo_fixed_t xsc = _cairo_fixed_from_double (sx); + cairo_fixed_t ysc = _cairo_fixed_from_double (sy); + + for (i = 0; i < num_traps; i++) { + offset_traps[i].top = _cairo_fixed_mul (src_traps[i].top + yoff, ysc); + offset_traps[i].bottom = _cairo_fixed_mul (src_traps[i].bottom + yoff, ysc); + offset_traps[i].left.p1.x = _cairo_fixed_mul (src_traps[i].left.p1.x + xoff, xsc); + offset_traps[i].left.p1.y = _cairo_fixed_mul (src_traps[i].left.p1.y + yoff, ysc); + offset_traps[i].left.p2.x = _cairo_fixed_mul (src_traps[i].left.p2.x + xoff, xsc); + offset_traps[i].left.p2.y = _cairo_fixed_mul (src_traps[i].left.p2.y + yoff, ysc); + offset_traps[i].right.p1.x = _cairo_fixed_mul (src_traps[i].right.p1.x + xoff, xsc); + offset_traps[i].right.p1.y = _cairo_fixed_mul (src_traps[i].right.p1.y + yoff, ysc); + offset_traps[i].right.p2.x = _cairo_fixed_mul (src_traps[i].right.p2.x + xoff, xsc); + offset_traps[i].right.p2.y = _cairo_fixed_mul (src_traps[i].right.p2.y + yoff, ysc); + } + } +} + +static cairo_bool_t +_cairo_trap_contains (cairo_trapezoid_t *t, cairo_point_t *pt) +{ + cairo_slope_t slope_left, slope_pt, slope_right; + + if (t->top > pt->y) + return FALSE; + if (t->bottom < pt->y) + return FALSE; + + _cairo_slope_init (&slope_left, &t->left.p1, &t->left.p2); + _cairo_slope_init (&slope_pt, &t->left.p1, pt); + + if (_cairo_slope_compare (&slope_left, &slope_pt) < 0) + return FALSE; + + _cairo_slope_init (&slope_right, &t->right.p1, &t->right.p2); + _cairo_slope_init (&slope_pt, &t->right.p1, pt); + + if (_cairo_slope_compare (&slope_pt, &slope_right) < 0) + return FALSE; + + return TRUE; +} + +cairo_bool_t +_cairo_traps_contain (const cairo_traps_t *traps, + double x, double y) +{ + int i; + cairo_point_t point; + + point.x = _cairo_fixed_from_double (x); + point.y = _cairo_fixed_from_double (y); + + for (i = 0; i < traps->num_traps; i++) { + if (_cairo_trap_contains (&traps->traps[i], &point)) + return TRUE; + } + + return FALSE; +} + +static cairo_fixed_t +_line_compute_intersection_x_for_y (const cairo_line_t *line, + cairo_fixed_t y) +{ + return _cairo_edge_compute_intersection_x_for_y (&line->p1, &line->p2, y); +} + +void +_cairo_traps_extents (const cairo_traps_t *traps, + cairo_box_t *extents) +{ + int i; + + if (traps->num_traps == 0) { + extents->p1.x = extents->p1.y = 0; + extents->p2.x = extents->p2.y = 0; + return; + } + + extents->p1.x = extents->p1.y = INT32_MAX; + extents->p2.x = extents->p2.y = INT32_MIN; + + for (i = 0; i < traps->num_traps; i++) { + const cairo_trapezoid_t *trap = &traps->traps[i]; + + if (trap->top < extents->p1.y) + extents->p1.y = trap->top; + if (trap->bottom > extents->p2.y) + extents->p2.y = trap->bottom; + + if (trap->left.p1.x < extents->p1.x) { + cairo_fixed_t x = trap->left.p1.x; + if (trap->top != trap->left.p1.y) { + x = _line_compute_intersection_x_for_y (&trap->left, + trap->top); + if (x < extents->p1.x) + extents->p1.x = x; + } else + extents->p1.x = x; + } + if (trap->left.p2.x < extents->p1.x) { + cairo_fixed_t x = trap->left.p2.x; + if (trap->bottom != trap->left.p2.y) { + x = _line_compute_intersection_x_for_y (&trap->left, + trap->bottom); + if (x < extents->p1.x) + extents->p1.x = x; + } else + extents->p1.x = x; + } + + if (trap->right.p1.x > extents->p2.x) { + cairo_fixed_t x = trap->right.p1.x; + if (trap->top != trap->right.p1.y) { + x = _line_compute_intersection_x_for_y (&trap->right, + trap->top); + if (x > extents->p2.x) + extents->p2.x = x; + } else + extents->p2.x = x; + } + if (trap->right.p2.x > extents->p2.x) { + cairo_fixed_t x = trap->right.p2.x; + if (trap->bottom != trap->right.p2.y) { + x = _line_compute_intersection_x_for_y (&trap->right, + trap->bottom); + if (x > extents->p2.x) + extents->p2.x = x; + } else + extents->p2.x = x; + } + } +} + +static cairo_bool_t +_mono_edge_is_vertical (const cairo_line_t *line) +{ + return _cairo_fixed_integer_round_down (line->p1.x) == _cairo_fixed_integer_round_down (line->p2.x); +} + +static cairo_bool_t +_traps_are_pixel_aligned (cairo_traps_t *traps, + cairo_antialias_t antialias) +{ + int i; + + if (antialias == CAIRO_ANTIALIAS_NONE) { + for (i = 0; i < traps->num_traps; i++) { + if (! _mono_edge_is_vertical (&traps->traps[i].left) || + ! _mono_edge_is_vertical (&traps->traps[i].right)) + { + traps->maybe_region = FALSE; + return FALSE; + } + } + } else { + for (i = 0; i < traps->num_traps; i++) { + if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x || + traps->traps[i].right.p1.x != traps->traps[i].right.p2.x || + ! _cairo_fixed_is_integer (traps->traps[i].top) || + ! _cairo_fixed_is_integer (traps->traps[i].bottom) || + ! _cairo_fixed_is_integer (traps->traps[i].left.p1.x) || + ! _cairo_fixed_is_integer (traps->traps[i].right.p1.x)) + { + traps->maybe_region = FALSE; + return FALSE; + } + } + } + + return TRUE; +} + +/** + * _cairo_traps_extract_region: + * @traps: a #cairo_traps_t + * @region: a #cairo_region_t + * + * Determines if a set of trapezoids are exactly representable as a + * cairo region. If so, the passed-in region is initialized to + * the area representing the given traps. It should be finalized + * with cairo_region_fini(). If not, %CAIRO_INT_STATUS_UNSUPPORTED + * is returned. + * + * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_INT_STATUS_UNSUPPORTED + * or %CAIRO_STATUS_NO_MEMORY + **/ +cairo_int_status_t +_cairo_traps_extract_region (cairo_traps_t *traps, + cairo_antialias_t antialias, + cairo_region_t **region) +{ + cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)]; + cairo_rectangle_int_t *rects = stack_rects; + cairo_int_status_t status; + int i, rect_count; + + /* we only treat this a hint... */ + if (antialias != CAIRO_ANTIALIAS_NONE && ! traps->maybe_region) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _traps_are_pixel_aligned (traps, antialias)) { + traps->maybe_region = FALSE; + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (traps->num_traps > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (traps->num_traps, sizeof (cairo_rectangle_int_t)); + + if (unlikely (rects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + rect_count = 0; + for (i = 0; i < traps->num_traps; i++) { + int x1, y1, x2, y2; + + if (antialias == CAIRO_ANTIALIAS_NONE) { + x1 = _cairo_fixed_integer_round_down (traps->traps[i].left.p1.x); + y1 = _cairo_fixed_integer_round_down (traps->traps[i].top); + x2 = _cairo_fixed_integer_round_down (traps->traps[i].right.p1.x); + y2 = _cairo_fixed_integer_round_down (traps->traps[i].bottom); + } else { + x1 = _cairo_fixed_integer_part (traps->traps[i].left.p1.x); + y1 = _cairo_fixed_integer_part (traps->traps[i].top); + x2 = _cairo_fixed_integer_part (traps->traps[i].right.p1.x); + y2 = _cairo_fixed_integer_part (traps->traps[i].bottom); + } + + if (x2 > x1 && y2 > y1) { + rects[rect_count].x = x1; + rects[rect_count].y = y1; + rects[rect_count].width = x2 - x1; + rects[rect_count].height = y2 - y1; + rect_count++; + } + } + + + *region = cairo_region_create_rectangles (rects, rect_count); + status = (*region)->status; + + if (rects != stack_rects) + free (rects); + + return status; +} + +cairo_bool_t +_cairo_traps_to_boxes (cairo_traps_t *traps, + cairo_antialias_t antialias, + cairo_boxes_t *boxes) +{ + int i; + + for (i = 0; i < traps->num_traps; i++) { + if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x || + traps->traps[i].right.p1.x != traps->traps[i].right.p2.x) + return FALSE; + } + + _cairo_boxes_init (boxes); + + boxes->num_boxes = traps->num_traps; + boxes->chunks.base = (cairo_box_t *) traps->traps; + boxes->chunks.count = traps->num_traps; + boxes->chunks.size = traps->num_traps; + + if (antialias != CAIRO_ANTIALIAS_NONE) { + for (i = 0; i < traps->num_traps; i++) { + /* Note the traps and boxes alias so we need to take the local copies first. */ + cairo_fixed_t x1 = traps->traps[i].left.p1.x; + cairo_fixed_t x2 = traps->traps[i].right.p1.x; + cairo_fixed_t y1 = traps->traps[i].top; + cairo_fixed_t y2 = traps->traps[i].bottom; + + boxes->chunks.base[i].p1.x = x1; + boxes->chunks.base[i].p1.y = y1; + boxes->chunks.base[i].p2.x = x2; + boxes->chunks.base[i].p2.y = y2; + + if (boxes->is_pixel_aligned) { + boxes->is_pixel_aligned = + _cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) && + _cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2); + } + } + } else { + boxes->is_pixel_aligned = TRUE; + + for (i = 0; i < traps->num_traps; i++) { + /* Note the traps and boxes alias so we need to take the local copies first. */ + cairo_fixed_t x1 = traps->traps[i].left.p1.x; + cairo_fixed_t x2 = traps->traps[i].right.p1.x; + cairo_fixed_t y1 = traps->traps[i].top; + cairo_fixed_t y2 = traps->traps[i].bottom; + + /* round down here to match Pixman's behavior when using traps. */ + boxes->chunks.base[i].p1.x = _cairo_fixed_round_down (x1); + boxes->chunks.base[i].p1.y = _cairo_fixed_round_down (y1); + boxes->chunks.base[i].p2.x = _cairo_fixed_round_down (x2); + boxes->chunks.base[i].p2.y = _cairo_fixed_round_down (y2); + } + } + + return TRUE; +} + +/* moves trap points such that they become the actual corners of the trapezoid */ +static void +_sanitize_trap (cairo_trapezoid_t *t) +{ + cairo_trapezoid_t s = *t; + +#define FIX(lr, tb, p) \ + if (t->lr.p.y != t->tb) { \ + t->lr.p.x = s.lr.p2.x + _cairo_fixed_mul_div_floor (s.lr.p1.x - s.lr.p2.x, s.tb - s.lr.p2.y, s.lr.p1.y - s.lr.p2.y); \ + t->lr.p.y = s.tb; \ + } + FIX (left, top, p1); + FIX (left, bottom, p2); + FIX (right, top, p1); + FIX (right, bottom, p2); +} + +cairo_private cairo_status_t +_cairo_traps_path (const cairo_traps_t *traps, + cairo_path_fixed_t *path) +{ + int i; + + for (i = 0; i < traps->num_traps; i++) { + cairo_status_t status; + cairo_trapezoid_t trap = traps->traps[i]; + + if (trap.top == trap.bottom) + continue; + + _sanitize_trap (&trap); + + status = _cairo_path_fixed_move_to (path, trap.left.p1.x, trap.top); + if (unlikely (status)) return status; + status = _cairo_path_fixed_line_to (path, trap.right.p1.x, trap.top); + if (unlikely (status)) return status; + status = _cairo_path_fixed_line_to (path, trap.right.p2.x, trap.bottom); + if (unlikely (status)) return status; + status = _cairo_path_fixed_line_to (path, trap.left.p2.x, trap.bottom); + if (unlikely (status)) return status; + status = _cairo_path_fixed_close_path (path); + if (unlikely (status)) return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_debug_print_traps (FILE *file, const cairo_traps_t *traps) +{ + cairo_box_t extents; + int n; + +#if 0 + if (traps->has_limits) { + printf ("%s: limits=(%d, %d, %d, %d)\n", + filename, + traps->limits.p1.x, traps->limits.p1.y, + traps->limits.p2.x, traps->limits.p2.y); + } +#endif + + _cairo_traps_extents (traps, &extents); + fprintf (file, "extents=(%d, %d, %d, %d)\n", + extents.p1.x, extents.p1.y, + extents.p2.x, extents.p2.y); + + for (n = 0; n < traps->num_traps; n++) { + fprintf (file, "%d %d L:(%d, %d), (%d, %d) R:(%d, %d), (%d, %d)\n", + traps->traps[n].top, + traps->traps[n].bottom, + traps->traps[n].left.p1.x, + traps->traps[n].left.p1.y, + traps->traps[n].left.p2.x, + traps->traps[n].left.p2.y, + traps->traps[n].right.p1.x, + traps->traps[n].right.p1.y, + traps->traps[n].right.p2.x, + traps->traps[n].right.p2.y); + } +} + +struct cairo_trap_renderer { + cairo_span_renderer_t base; + cairo_traps_t *traps; +}; + +static cairo_status_t +span_to_traps (void *abstract_renderer, int y, int h, + const cairo_half_open_span_t *spans, unsigned num_spans) +{ + struct cairo_trap_renderer *r = abstract_renderer; + cairo_fixed_t top, bot; + + if (num_spans == 0) + return CAIRO_STATUS_SUCCESS; + + top = _cairo_fixed_from_int (y); + bot = _cairo_fixed_from_int (y + h); + do { + if (spans[0].coverage) { + cairo_fixed_t x0 = _cairo_fixed_from_int(spans[0].x); + cairo_fixed_t x1 = _cairo_fixed_from_int(spans[1].x); + cairo_line_t left = { { x0, top }, { x0, bot } }, + right = { { x1, top }, { x1, bot } }; + _cairo_traps_add_trap (r->traps, top, bot, &left, &right); + } + spans++; + } while (--num_spans > 1); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_rasterise_polygon_to_traps (cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias, + cairo_traps_t *traps) +{ + struct cairo_trap_renderer renderer; + cairo_scan_converter_t *converter; + cairo_int_status_t status; + cairo_rectangle_int_t r; + + TRACE ((stderr, "%s: fill_rule=%d, antialias=%d\n", + __FUNCTION__, fill_rule, antialias)); + assert(antialias == CAIRO_ANTIALIAS_NONE); + + renderer.traps = traps; + renderer.base.render_rows = span_to_traps; + + _cairo_box_round_to_rectangle (&polygon->extents, &r); + converter = _cairo_mono_scan_converter_create (r.x, r.y, + r.x + r.width, + r.y + r.height, + fill_rule); + status = _cairo_mono_scan_converter_add_polygon (converter, polygon); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = converter->generate (converter, &renderer.base); + converter->destroy (converter); + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tristrip-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-tristrip-private.h new file mode 100644 index 00000000000..ccd28799e82 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tristrip-private.h @@ -0,0 +1,94 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_TRISTRIP_PRIVATE_H +#define CAIRO_TRISTRIP_PRIVATE_H + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" +#include "cairo-types-private.h" + +CAIRO_BEGIN_DECLS + +struct _cairo_tristrip { + cairo_status_t status; + + /* XXX clipping */ + + const cairo_box_t *limits; + int num_limits; + + int num_points; + int size_points; + cairo_point_t *points; + cairo_point_t points_embedded[64]; +}; + +cairo_private void +_cairo_tristrip_init (cairo_tristrip_t *strip); + +cairo_private void +_cairo_tristrip_limit (cairo_tristrip_t *strip, + const cairo_box_t *limits, + int num_limits); + +cairo_private void +_cairo_tristrip_init_with_clip (cairo_tristrip_t *strip, + const cairo_clip_t *clip); + +cairo_private void +_cairo_tristrip_translate (cairo_tristrip_t *strip, int x, int y); + +cairo_private void +_cairo_tristrip_move_to (cairo_tristrip_t *strip, + const cairo_point_t *point); + +cairo_private void +_cairo_tristrip_add_point (cairo_tristrip_t *strip, + const cairo_point_t *point); + +cairo_private void +_cairo_tristrip_extents (const cairo_tristrip_t *strip, + cairo_box_t *extents); + +cairo_private void +_cairo_tristrip_fini (cairo_tristrip_t *strip); + +#define _cairo_tristrip_status(T) ((T)->status) + +CAIRO_END_DECLS + +#endif /* CAIRO_TRISTRIP_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-tristrip.c b/Build/source/libs/cairo/cairo-src/src/cairo-tristrip.c new file mode 100644 index 00000000000..bb4972f5003 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-tristrip.c @@ -0,0 +1,185 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-error-private.h" +#include "cairo-tristrip-private.h" + +void +_cairo_tristrip_init (cairo_tristrip_t *strip) +{ + VG (VALGRIND_MAKE_MEM_UNDEFINED (strip, sizeof (cairo_tristrip_t))); + + strip->status = CAIRO_STATUS_SUCCESS; + + strip->num_limits = 0; + strip->num_points = 0; + + strip->size_points = ARRAY_LENGTH (strip->points_embedded); + strip->points = strip->points_embedded; +} + +void +_cairo_tristrip_fini (cairo_tristrip_t *strip) +{ + if (strip->points != strip->points_embedded) + free (strip->points); + + VG (VALGRIND_MAKE_MEM_NOACCESS (strip, sizeof (cairo_tristrip_t))); +} + + +void +_cairo_tristrip_limit (cairo_tristrip_t *strip, + const cairo_box_t *limits, + int num_limits) +{ + strip->limits = limits; + strip->num_limits = num_limits; +} + +void +_cairo_tristrip_init_with_clip (cairo_tristrip_t *strip, + const cairo_clip_t *clip) +{ + _cairo_tristrip_init (strip); + if (clip) + _cairo_tristrip_limit (strip, clip->boxes, clip->num_boxes); +} + +/* make room for at least one more trap */ +static cairo_bool_t +_cairo_tristrip_grow (cairo_tristrip_t *strip) +{ + cairo_point_t *points; + int new_size = 4 * strip->size_points; + + if (CAIRO_INJECT_FAULT ()) { + strip->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + if (strip->points == strip->points_embedded) { + points = _cairo_malloc_ab (new_size, sizeof (cairo_point_t)); + if (points != NULL) + memcpy (points, strip->points, sizeof (strip->points_embedded)); + } else { + points = _cairo_realloc_ab (strip->points, + new_size, sizeof (cairo_trapezoid_t)); + } + + if (unlikely (points == NULL)) { + strip->status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + return FALSE; + } + + strip->points = points; + strip->size_points = new_size; + return TRUE; +} + +void +_cairo_tristrip_add_point (cairo_tristrip_t *strip, + const cairo_point_t *p) +{ + if (unlikely (strip->num_points == strip->size_points)) { + if (unlikely (! _cairo_tristrip_grow (strip))) + return; + } + + strip->points[strip->num_points++] = *p; +} + +/* Insert degenerate triangles to advance to the given point. The + * next point inserted must also be @p. */ +void +_cairo_tristrip_move_to (cairo_tristrip_t *strip, + const cairo_point_t *p) +{ + if (strip->num_points == 0) + return; + + _cairo_tristrip_add_point (strip, &strip->points[strip->num_points-1]); + _cairo_tristrip_add_point (strip, p); +#if 0 + /* and one more for luck! (to preserve cw/ccw ordering) */ + _cairo_tristrip_add_point (strip, p); +#endif +} + +void +_cairo_tristrip_translate (cairo_tristrip_t *strip, int x, int y) +{ + cairo_fixed_t xoff, yoff; + cairo_point_t *p; + int i; + + xoff = _cairo_fixed_from_int (x); + yoff = _cairo_fixed_from_int (y); + + for (i = 0, p = strip->points; i < strip->num_points; i++, p++) { + p->x += xoff; + p->y += yoff; + } +} + +void +_cairo_tristrip_extents (const cairo_tristrip_t *strip, + cairo_box_t *extents) +{ + int i; + + if (strip->num_points == 0) { + extents->p1.x = extents->p1.y = 0; + extents->p2.x = extents->p2.y = 0; + return; + } + + extents->p2 = extents->p1 = strip->points[0]; + for (i = 1; i < strip->num_points; i++) { + const cairo_point_t *p = &strip->points[i]; + + if (p->x < extents->p1.x) + extents->p1.x = p->x; + else if (p->x > extents->p2.x) + extents->p2.x = p->x; + + if (p->y < extents->p1.y) + extents->p1.y = p->y; + else if (p->y > extents->p2.y) + extents->p2.y = p->y; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset-private.h new file mode 100644 index 00000000000..dc9573216f3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset-private.h @@ -0,0 +1,212 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Adrian Johnson + */ + +#ifndef CAIRO_TRUETYPE_SUBSET_PRIVATE_H +#define CAIRO_TRUETYPE_SUBSET_PRIVATE_H + +#include "cairoint.h" + +#if CAIRO_HAS_FONT_SUBSET + +/* The structs defined here should strictly follow the TrueType + * specification and not be padded. We use only 16-bit integer + * in their definition to guarantee that. The fields of type + * "FIXED" in the TT spec are broken into two *_1 and *_2 16-bit + * parts, and 64-bit members are broken into four. + * + * The test truetype-tables in the test suite makes sure that + * these tables have the right size. Please update that test + * if you add new tables/structs that should be packed. + */ + +#define MAKE_TT_TAG(a, b, c, d) (a<<24 | b<<16 | c<<8 | d) +#define TT_TAG_CFF MAKE_TT_TAG('C','F','F',' ') +#define TT_TAG_cmap MAKE_TT_TAG('c','m','a','p') +#define TT_TAG_cvt MAKE_TT_TAG('c','v','t',' ') +#define TT_TAG_fpgm MAKE_TT_TAG('f','p','g','m') +#define TT_TAG_glyf MAKE_TT_TAG('g','l','y','f') +#define TT_TAG_head MAKE_TT_TAG('h','e','a','d') +#define TT_TAG_hhea MAKE_TT_TAG('h','h','e','a') +#define TT_TAG_hmtx MAKE_TT_TAG('h','m','t','x') +#define TT_TAG_loca MAKE_TT_TAG('l','o','c','a') +#define TT_TAG_maxp MAKE_TT_TAG('m','a','x','p') +#define TT_TAG_name MAKE_TT_TAG('n','a','m','e') +#define TT_TAG_OS2 MAKE_TT_TAG('O','S','/','2') +#define TT_TAG_post MAKE_TT_TAG('p','o','s','t') +#define TT_TAG_prep MAKE_TT_TAG('p','r','e','p') + +/* All tt_* structs are big-endian */ +typedef struct _tt_cmap_index { + uint16_t platform; + uint16_t encoding; + uint32_t offset; +} tt_cmap_index_t; + +typedef struct _tt_cmap { + uint16_t version; + uint16_t num_tables; + tt_cmap_index_t index[1]; +} tt_cmap_t; + +typedef struct _segment_map { + uint16_t format; + uint16_t length; + uint16_t version; + uint16_t segCountX2; + uint16_t searchRange; + uint16_t entrySelector; + uint16_t rangeShift; + uint16_t endCount[1]; +} tt_segment_map_t; + +typedef struct _tt_head { + int16_t version_1; + int16_t version_2; + int16_t revision_1; + int16_t revision_2; + uint16_t checksum_1; + uint16_t checksum_2; + uint16_t magic_1; + uint16_t magic_2; + uint16_t flags; + uint16_t units_per_em; + int16_t created_1; + int16_t created_2; + int16_t created_3; + int16_t created_4; + int16_t modified_1; + int16_t modified_2; + int16_t modified_3; + int16_t modified_4; + int16_t x_min; /* FWORD */ + int16_t y_min; /* FWORD */ + int16_t x_max; /* FWORD */ + int16_t y_max; /* FWORD */ + uint16_t mac_style; + uint16_t lowest_rec_pppem; + int16_t font_direction_hint; + int16_t index_to_loc_format; + int16_t glyph_data_format; +} tt_head_t; + +typedef struct _tt_hhea { + int16_t version_1; + int16_t version_2; + int16_t ascender; /* FWORD */ + int16_t descender; /* FWORD */ + int16_t line_gap; /* FWORD */ + uint16_t advance_max_width; /* UFWORD */ + int16_t min_left_side_bearing; /* FWORD */ + int16_t min_right_side_bearing; /* FWORD */ + int16_t x_max_extent; /* FWORD */ + int16_t caret_slope_rise; + int16_t caret_slope_run; + int16_t reserved[5]; + int16_t metric_data_format; + uint16_t num_hmetrics; +} tt_hhea_t; + +typedef struct _tt_maxp { + int16_t version_1; + int16_t version_2; + uint16_t num_glyphs; + uint16_t max_points; + uint16_t max_contours; + uint16_t max_composite_points; + uint16_t max_composite_contours; + uint16_t max_zones; + uint16_t max_twilight_points; + uint16_t max_storage; + uint16_t max_function_defs; + uint16_t max_instruction_defs; + uint16_t max_stack_elements; + uint16_t max_size_of_instructions; + uint16_t max_component_elements; + uint16_t max_component_depth; +} tt_maxp_t; + +typedef struct _tt_name_record { + uint16_t platform; + uint16_t encoding; + uint16_t language; + uint16_t name; + uint16_t length; + uint16_t offset; +} tt_name_record_t; + +typedef struct _tt_name { + uint16_t format; + uint16_t num_records; + uint16_t strings_offset; + tt_name_record_t records[1]; +} tt_name_t; + + +/* bitmask for fsSelection field */ +#define TT_FS_SELECTION_ITALIC 1 +#define TT_FS_SELECTION_BOLD 32 + +/* _unused fields are defined in TT spec but not used by cairo */ +typedef struct _tt_os2 { + uint16_t _unused1[2]; + uint16_t usWeightClass; + uint16_t _unused2[28]; + uint16_t fsSelection; + uint16_t _unused3[11]; +} tt_os2_t; + +/* composite_glyph_t flags */ +#define TT_ARG_1_AND_2_ARE_WORDS 0x0001 +#define TT_WE_HAVE_A_SCALE 0x0008 +#define TT_MORE_COMPONENTS 0x0020 +#define TT_WE_HAVE_AN_X_AND_Y_SCALE 0x0040 +#define TT_WE_HAVE_A_TWO_BY_TWO 0x0080 + +typedef struct _tt_composite_glyph { + uint16_t flags; + uint16_t index; + uint16_t args[6]; /* 1 to 6 arguments depending on value of flags */ +} tt_composite_glyph_t; + +typedef struct _tt_glyph_data { + int16_t num_contours; + int8_t data[8]; + tt_composite_glyph_t glyph; +} tt_glyph_data_t; + +#endif /* CAIRO_HAS_FONT_SUBSET */ + +#endif /* CAIRO_TRUETYPE_SUBSET_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset.c b/Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset.c new file mode 100644 index 00000000000..645a89abf21 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-truetype-subset.c @@ -0,0 +1,1631 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Adrian Johnson + */ + +/* + * Useful links: + * http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html + * http://www.microsoft.com/typography/specs/default.htm + */ + +#define _BSD_SOURCE /* for snprintf(), strdup() */ +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-truetype-subset-private.h" + + +typedef struct subset_glyph subset_glyph_t; +struct subset_glyph { + int parent_index; + unsigned long location; +}; + +typedef struct _cairo_truetype_font cairo_truetype_font_t; + +typedef struct table table_t; +struct table { + unsigned long tag; + cairo_status_t (*write) (cairo_truetype_font_t *font, unsigned long tag); + int pos; /* position in the font directory */ +}; + +struct _cairo_truetype_font { + + cairo_scaled_font_subset_t *scaled_font_subset; + + table_t truetype_tables[10]; + int num_tables; + + struct { + char *font_name; + char *ps_name; + unsigned int num_glyphs; + int *widths; + long x_min, y_min, x_max, y_max; + long ascent, descent; + int units_per_em; + } base; + + subset_glyph_t *glyphs; + const cairo_scaled_font_backend_t *backend; + int num_glyphs_in_face; + int checksum_index; + cairo_array_t output; + cairo_array_t string_offsets; + unsigned long last_offset; + unsigned long last_boundary; + int *parent_to_subset; + cairo_status_t status; + cairo_bool_t is_pdf; +}; + +/* + * Test that the structs we define for TrueType tables have the + * correct size, ie. they are not padded. + */ +#define check(T, S) COMPILE_TIME_ASSERT (sizeof (T) == (S)) +check (tt_head_t, 54); +check (tt_hhea_t, 36); +check (tt_maxp_t, 32); +check (tt_name_record_t, 12); +check (tt_name_t, 18); +check (tt_name_t, 18); +check (tt_composite_glyph_t, 16); +check (tt_glyph_data_t, 26); +#undef check + +static cairo_status_t +cairo_truetype_font_use_glyph (cairo_truetype_font_t *font, + unsigned short glyph, + unsigned short *out); + +#define SFNT_VERSION 0x00010000 +#define SFNT_STRING_MAX_LENGTH 65535 + +static cairo_status_t +_cairo_truetype_font_set_error (cairo_truetype_font_t *font, + cairo_status_t status) +{ + if (status == CAIRO_STATUS_SUCCESS || + status == (int)CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + _cairo_status_set_error (&font->status, status); + + return _cairo_error (status); +} + +static cairo_status_t +_cairo_truetype_font_create (cairo_scaled_font_subset_t *scaled_font_subset, + cairo_bool_t is_pdf, + cairo_truetype_font_t **font_return) +{ + cairo_status_t status; + cairo_truetype_font_t *font; + const cairo_scaled_font_backend_t *backend; + tt_head_t head; + tt_hhea_t hhea; + tt_maxp_t maxp; + unsigned long size; + + backend = scaled_font_subset->scaled_font->backend; + if (!backend->load_truetype_table) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* FIXME: We should either support subsetting vertical fonts, or fail on + * vertical. Currently font_options_t doesn't have vertical flag, but + * it should be added in the future. For now, the freetype backend + * returns UNSUPPORTED in load_truetype_table if the font is vertical. + * + * if (cairo_font_options_get_vertical_layout (scaled_font_subset->scaled_font)) + * return CAIRO_INT_STATUS_UNSUPPORTED; + */ + + /* We need to use a fallback font generated from the synthesized outlines. */ + if (backend->is_synthetic && backend->is_synthetic (scaled_font_subset->scaled_font)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = sizeof (tt_head_t); + status = backend->load_truetype_table (scaled_font_subset->scaled_font, + TT_TAG_head, 0, + (unsigned char *) &head, + &size); + if (unlikely (status)) + return status; + + size = sizeof (tt_maxp_t); + status = backend->load_truetype_table (scaled_font_subset->scaled_font, + TT_TAG_maxp, 0, + (unsigned char *) &maxp, + &size); + if (unlikely (status)) + return status; + + size = sizeof (tt_hhea_t); + status = backend->load_truetype_table (scaled_font_subset->scaled_font, + TT_TAG_hhea, 0, + (unsigned char *) &hhea, + &size); + if (unlikely (status)) + return status; + + font = malloc (sizeof (cairo_truetype_font_t)); + if (unlikely (font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->backend = backend; + font->num_glyphs_in_face = be16_to_cpu (maxp.num_glyphs); + font->scaled_font_subset = scaled_font_subset; + + font->last_offset = 0; + font->last_boundary = 0; + _cairo_array_init (&font->output, sizeof (char)); + status = _cairo_array_grow_by (&font->output, 4096); + if (unlikely (status)) + goto fail1; + + font->glyphs = calloc (font->num_glyphs_in_face + 1, sizeof (subset_glyph_t)); + if (unlikely (font->glyphs == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + font->parent_to_subset = calloc (font->num_glyphs_in_face, sizeof (int)); + if (unlikely (font->parent_to_subset == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + + font->is_pdf = is_pdf; + font->base.num_glyphs = 0; + font->base.x_min = (int16_t) be16_to_cpu (head.x_min); + font->base.y_min = (int16_t) be16_to_cpu (head.y_min); + font->base.x_max = (int16_t) be16_to_cpu (head.x_max); + font->base.y_max = (int16_t) be16_to_cpu (head.y_max); + font->base.ascent = (int16_t) be16_to_cpu (hhea.ascender); + font->base.descent = (int16_t) be16_to_cpu (hhea.descender); + font->base.units_per_em = (int16_t) be16_to_cpu (head.units_per_em); + if (font->base.units_per_em == 0) + font->base.units_per_em = 2048; + + font->base.ps_name = NULL; + font->base.font_name = NULL; + status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font, + &font->base.ps_name, + &font->base.font_name); + if (_cairo_status_is_error (status)) + goto fail3; + + /* If the PS name is not found, create a CairoFont-x-y name. */ + if (font->base.ps_name == NULL) { + font->base.ps_name = malloc (30); + if (unlikely (font->base.ps_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + + snprintf(font->base.ps_name, 30, "CairoFont-%u-%u", + scaled_font_subset->font_id, + scaled_font_subset->subset_id); + } + + font->base.widths = calloc (font->num_glyphs_in_face, sizeof (int)); + if (unlikely (font->base.widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail4; + } + + _cairo_array_init (&font->string_offsets, sizeof (unsigned long)); + status = _cairo_array_grow_by (&font->string_offsets, 10); + if (unlikely (status)) + goto fail5; + + font->status = CAIRO_STATUS_SUCCESS; + + *font_return = font; + + return CAIRO_STATUS_SUCCESS; + + fail5: + _cairo_array_fini (&font->string_offsets); + free (font->base.widths); + fail4: + free (font->base.ps_name); + fail3: + free (font->parent_to_subset); + free (font->base.font_name); + fail2: + free (font->glyphs); + fail1: + _cairo_array_fini (&font->output); + free (font); + + return status; +} + +static void +cairo_truetype_font_destroy (cairo_truetype_font_t *font) +{ + _cairo_array_fini (&font->string_offsets); + free (font->base.widths); + free (font->base.ps_name); + free (font->base.font_name); + free (font->parent_to_subset); + free (font->glyphs); + _cairo_array_fini (&font->output); + free (font); +} + +static cairo_status_t +cairo_truetype_font_allocate_write_buffer (cairo_truetype_font_t *font, + size_t length, + unsigned char **buffer) +{ + cairo_status_t status; + + if (font->status) + return font->status; + + status = _cairo_array_allocate (&font->output, length, (void **) buffer); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + return CAIRO_STATUS_SUCCESS; +} + +static void +cairo_truetype_font_write (cairo_truetype_font_t *font, + const void *data, + size_t length) +{ + cairo_status_t status; + + if (font->status) + return; + + status = _cairo_array_append_multiple (&font->output, data, length); + if (unlikely (status)) + status = _cairo_truetype_font_set_error (font, status); +} + +static void +cairo_truetype_font_write_be16 (cairo_truetype_font_t *font, + uint16_t value) +{ + uint16_t be16_value; + + if (font->status) + return; + + be16_value = cpu_to_be16 (value); + cairo_truetype_font_write (font, &be16_value, sizeof be16_value); +} + +static void +cairo_truetype_font_write_be32 (cairo_truetype_font_t *font, + uint32_t value) +{ + uint32_t be32_value; + + if (font->status) + return; + + be32_value = cpu_to_be32 (value); + cairo_truetype_font_write (font, &be32_value, sizeof be32_value); +} + +static cairo_status_t +cairo_truetype_font_align_output (cairo_truetype_font_t *font, + unsigned long *aligned) +{ + int length, pad; + unsigned char *padding; + + length = _cairo_array_num_elements (&font->output); + *aligned = (length + 3) & ~3; + pad = *aligned - length; + + if (pad) { + cairo_status_t status; + + status = cairo_truetype_font_allocate_write_buffer (font, pad, + &padding); + if (unlikely (status)) + return status; + + memset (padding, 0, pad); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_check_boundary (cairo_truetype_font_t *font, + unsigned long boundary) +{ + cairo_status_t status; + + if (font->status) + return font->status; + + if (boundary - font->last_offset > SFNT_STRING_MAX_LENGTH) + { + status = _cairo_array_append (&font->string_offsets, + &font->last_boundary); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + font->last_offset = font->last_boundary; + } + font->last_boundary = boundary; + + return CAIRO_STATUS_SUCCESS; +} + +typedef struct _cmap_unicode_range { + unsigned int start; + unsigned int end; +} cmap_unicode_range_t; + +static cmap_unicode_range_t winansi_unicode_ranges[] = { + { 0x0020, 0x007f }, + { 0x00a0, 0x00ff }, + { 0x0152, 0x0153 }, + { 0x0160, 0x0161 }, + { 0x0178, 0x0178 }, + { 0x017d, 0x017e }, + { 0x0192, 0x0192 }, + { 0x02c6, 0x02c6 }, + { 0x02dc, 0x02dc }, + { 0x2013, 0x2026 }, + { 0x2030, 0x2030 }, + { 0x2039, 0x203a }, + { 0x20ac, 0x20ac }, + { 0x2122, 0x2122 }, +}; + +static cairo_status_t +cairo_truetype_font_write_cmap_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + int i; + unsigned int j; + int range_offset; + int num_ranges; + int entry_selector; + int length; + + num_ranges = ARRAY_LENGTH (winansi_unicode_ranges); + + length = 16 + (num_ranges + 1)*8; + for (i = 0; i < num_ranges; i++) + length += (winansi_unicode_ranges[i].end - winansi_unicode_ranges[i].start + 1)*2; + + entry_selector = 0; + while ((1 << entry_selector) <= (num_ranges + 1)) + entry_selector++; + + entry_selector--; + + cairo_truetype_font_write_be16 (font, 0); /* Table version */ + cairo_truetype_font_write_be16 (font, 1); /* Num tables */ + + cairo_truetype_font_write_be16 (font, 3); /* Platform */ + cairo_truetype_font_write_be16 (font, 1); /* Encoding */ + cairo_truetype_font_write_be32 (font, 12); /* Offset to start of table */ + + /* Output a format 4 encoding table for the winansi encoding */ + + cairo_truetype_font_write_be16 (font, 4); /* Format */ + cairo_truetype_font_write_be16 (font, length); /* Length */ + cairo_truetype_font_write_be16 (font, 0); /* Version */ + cairo_truetype_font_write_be16 (font, num_ranges*2 + 2); /* 2*segcount */ + cairo_truetype_font_write_be16 (font, (1 << (entry_selector + 1))); /* searchrange */ + cairo_truetype_font_write_be16 (font, entry_selector); /* entry selector */ + cairo_truetype_font_write_be16 (font, num_ranges*2 + 2 - (1 << (entry_selector + 1))); /* rangeshift */ + for (i = 0; i < num_ranges; i++) + cairo_truetype_font_write_be16 (font, winansi_unicode_ranges[i].end); /* end count[] */ + cairo_truetype_font_write_be16 (font, 0xffff); /* end count[] */ + + cairo_truetype_font_write_be16 (font, 0); /* reserved */ + + for (i = 0; i < num_ranges; i++) + cairo_truetype_font_write_be16 (font, winansi_unicode_ranges[i].start); /* startCode[] */ + cairo_truetype_font_write_be16 (font, 0xffff); /* startCode[] */ + + for (i = 0; i < num_ranges; i++) + cairo_truetype_font_write_be16 (font, 0x0000); /* delta[] */ + cairo_truetype_font_write_be16 (font, 1); /* delta[] */ + + range_offset = num_ranges*2 + 2; + for (i = 0; i < num_ranges; i++) { + cairo_truetype_font_write_be16 (font, range_offset); /* rangeOffset[] */ + range_offset += (winansi_unicode_ranges[i].end - winansi_unicode_ranges[i].start + 1)*2 - 2; + } + cairo_truetype_font_write_be16 (font, 0); /* rangeOffset[] */ + + for (i = 0; i < num_ranges; i++) { + for (j = winansi_unicode_ranges[i].start; j < winansi_unicode_ranges[i].end + 1; j++) { + int ch = _cairo_unicode_to_winansi (j); + int glyph; + + if (ch > 0) + glyph = font->scaled_font_subset->latin_to_subset_glyph_index[ch]; + else + glyph = 0; + cairo_truetype_font_write_be16 (font, glyph); + } + } + + return font->status; +} + +static cairo_status_t +cairo_truetype_font_write_generic_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + cairo_status_t status; + unsigned char *buffer; + unsigned long size; + + if (font->status) + return font->status; + + size = 0; + status = font->backend->load_truetype_table(font->scaled_font_subset->scaled_font, + tag, 0, NULL, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + tag, 0, buffer, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_remap_composite_glyph (cairo_truetype_font_t *font, + unsigned char *buffer, + unsigned long size) +{ + tt_glyph_data_t *glyph_data; + tt_composite_glyph_t *composite_glyph; + int num_args; + int has_more_components; + unsigned short flags; + unsigned short index; + cairo_status_t status; + unsigned char *end = buffer + size; + + if (font->status) + return font->status; + + glyph_data = (tt_glyph_data_t *) buffer; + if ((unsigned char *)(&glyph_data->data) >= end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((int16_t)be16_to_cpu (glyph_data->num_contours) >= 0) + return CAIRO_STATUS_SUCCESS; + + composite_glyph = &glyph_data->glyph; + do { + if ((unsigned char *)(&composite_glyph->args[1]) > end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + flags = be16_to_cpu (composite_glyph->flags); + has_more_components = flags & TT_MORE_COMPONENTS; + status = cairo_truetype_font_use_glyph (font, be16_to_cpu (composite_glyph->index), &index); + if (unlikely (status)) + return status; + + composite_glyph->index = cpu_to_be16 (index); + num_args = 1; + if (flags & TT_ARG_1_AND_2_ARE_WORDS) + num_args += 1; + + if (flags & TT_WE_HAVE_A_SCALE) + num_args += 1; + else if (flags & TT_WE_HAVE_AN_X_AND_Y_SCALE) + num_args += 2; + else if (flags & TT_WE_HAVE_A_TWO_BY_TWO) + num_args += 4; + + composite_glyph = (tt_composite_glyph_t *) &(composite_glyph->args[num_args]); + } while (has_more_components); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + unsigned long start_offset, index, size, next; + tt_head_t header; + unsigned long begin, end; + unsigned char *buffer; + unsigned int i; + union { + unsigned char *bytes; + uint16_t *short_offsets; + uint32_t *long_offsets; + } u; + cairo_status_t status; + + if (font->status) + return font->status; + + size = sizeof (tt_head_t); + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_head, 0, + (unsigned char*) &header, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + if (be16_to_cpu (header.index_to_loc_format) == 0) + size = sizeof (int16_t) * (font->num_glyphs_in_face + 1); + else + size = sizeof (int32_t) * (font->num_glyphs_in_face + 1); + + u.bytes = malloc (size); + if (unlikely (u.bytes == NULL)) + return _cairo_truetype_font_set_error (font, CAIRO_STATUS_NO_MEMORY); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_loca, 0, u.bytes, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + start_offset = _cairo_array_num_elements (&font->output); + for (i = 0; i < font->base.num_glyphs; i++) { + index = font->glyphs[i].parent_index; + if (be16_to_cpu (header.index_to_loc_format) == 0) { + begin = be16_to_cpu (u.short_offsets[index]) * 2; + end = be16_to_cpu (u.short_offsets[index + 1]) * 2; + } + else { + begin = be32_to_cpu (u.long_offsets[index]); + end = be32_to_cpu (u.long_offsets[index + 1]); + } + + /* quick sanity check... */ + if (end < begin) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto FAIL; + } + + size = end - begin; + status = cairo_truetype_font_align_output (font, &next); + if (unlikely (status)) + goto FAIL; + + status = cairo_truetype_font_check_boundary (font, next); + if (unlikely (status)) + goto FAIL; + + font->glyphs[i].location = next - start_offset; + + status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); + if (unlikely (status)) + goto FAIL; + + if (size != 0) { + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_glyf, begin, buffer, &size); + if (unlikely (status)) + goto FAIL; + + status = cairo_truetype_font_remap_composite_glyph (font, buffer, size); + if (unlikely (status)) + goto FAIL; + } + } + + status = cairo_truetype_font_align_output (font, &next); + if (unlikely (status)) + goto FAIL; + + font->glyphs[i].location = next - start_offset; + + status = font->status; +FAIL: + free (u.bytes); + + return _cairo_truetype_font_set_error (font, status); +} + +static cairo_status_t +cairo_truetype_font_write_head_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + unsigned char *buffer; + unsigned long size; + cairo_status_t status; + + if (font->status) + return font->status; + + size = 0; + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + tag, 0, NULL, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + font->checksum_index = _cairo_array_num_elements (&font->output) + 8; + status = cairo_truetype_font_allocate_write_buffer (font, size, &buffer); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + tag, 0, buffer, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + /* set checkSumAdjustment to 0 for table checksum calculation */ + *(uint32_t *)(buffer + 8) = 0; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_write_hhea_table (cairo_truetype_font_t *font, unsigned long tag) +{ + tt_hhea_t *hhea; + unsigned long size; + cairo_status_t status; + + if (font->status) + return font->status; + + size = sizeof (tt_hhea_t); + status = cairo_truetype_font_allocate_write_buffer (font, size, (unsigned char **) &hhea); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + tag, 0, (unsigned char *) hhea, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + hhea->num_hmetrics = cpu_to_be16 ((uint16_t)(font->base.num_glyphs)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_write_hmtx_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + unsigned long size; + unsigned long long_entry_size; + unsigned long short_entry_size; + short *p; + unsigned int i; + tt_hhea_t hhea; + int num_hmetrics; + cairo_status_t status; + + if (font->status) + return font->status; + + size = sizeof (tt_hhea_t); + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hhea, 0, + (unsigned char*) &hhea, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + num_hmetrics = be16_to_cpu(hhea.num_hmetrics); + + for (i = 0; i < font->base.num_glyphs; i++) { + long_entry_size = 2 * sizeof (int16_t); + short_entry_size = sizeof (int16_t); + status = cairo_truetype_font_allocate_write_buffer (font, + long_entry_size, + (unsigned char **) &p); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + if (font->glyphs[i].parent_index < num_hmetrics) { + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hmtx, + font->glyphs[i].parent_index * long_entry_size, + (unsigned char *) p, &long_entry_size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + } + else + { + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hmtx, + (num_hmetrics - 1) * long_entry_size, + (unsigned char *) p, &short_entry_size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_hmtx, + num_hmetrics * long_entry_size + + (font->glyphs[i].parent_index - num_hmetrics) * short_entry_size, + (unsigned char *) (p + 1), &short_entry_size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + } + font->base.widths[i] = be16_to_cpu (p[0]); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_write_loca_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + unsigned int i; + tt_head_t header; + unsigned long size; + cairo_status_t status; + + if (font->status) + return font->status; + + size = sizeof(tt_head_t); + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_head, 0, + (unsigned char*) &header, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + if (be16_to_cpu (header.index_to_loc_format) == 0) + { + for (i = 0; i < font->base.num_glyphs + 1; i++) + cairo_truetype_font_write_be16 (font, font->glyphs[i].location / 2); + } else { + for (i = 0; i < font->base.num_glyphs + 1; i++) + cairo_truetype_font_write_be32 (font, font->glyphs[i].location); + } + + return font->status; +} + +static cairo_status_t +cairo_truetype_font_write_maxp_table (cairo_truetype_font_t *font, + unsigned long tag) +{ + tt_maxp_t *maxp; + unsigned long size; + cairo_status_t status; + + if (font->status) + return font->status; + + size = sizeof (tt_maxp_t); + status = cairo_truetype_font_allocate_write_buffer (font, size, (unsigned char **) &maxp); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + tag, 0, (unsigned char *) maxp, &size); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + maxp->num_glyphs = cpu_to_be16 (font->base.num_glyphs); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_truetype_font_write_offset_table (cairo_truetype_font_t *font) +{ + cairo_status_t status; + unsigned char *table_buffer; + size_t table_buffer_length; + unsigned short search_range, entry_selector, range_shift; + + if (font->status) + return font->status; + + search_range = 1; + entry_selector = 0; + while (search_range * 2 <= font->num_tables) { + search_range *= 2; + entry_selector++; + } + search_range *= 16; + range_shift = font->num_tables * 16 - search_range; + + cairo_truetype_font_write_be32 (font, SFNT_VERSION); + cairo_truetype_font_write_be16 (font, font->num_tables); + cairo_truetype_font_write_be16 (font, search_range); + cairo_truetype_font_write_be16 (font, entry_selector); + cairo_truetype_font_write_be16 (font, range_shift); + + /* Allocate space for the table directory. Each directory entry + * will be filled in by cairo_truetype_font_update_entry() after + * the table is written. */ + table_buffer_length = font->num_tables * 16; + status = cairo_truetype_font_allocate_write_buffer (font, table_buffer_length, + &table_buffer); + if (unlikely (status)) + return _cairo_truetype_font_set_error (font, status); + + return CAIRO_STATUS_SUCCESS; +} + +static uint32_t +cairo_truetype_font_calculate_checksum (cairo_truetype_font_t *font, + unsigned long start, + unsigned long end) +{ + uint32_t *padded_end; + uint32_t *p; + uint32_t checksum; + char *data; + + checksum = 0; + data = _cairo_array_index (&font->output, 0); + p = (uint32_t *) (data + start); + padded_end = (uint32_t *) (data + ((end + 3) & ~3)); + while (p < padded_end) + checksum += be32_to_cpu(*p++); + + return checksum; +} + +static void +cairo_truetype_font_update_entry (cairo_truetype_font_t *font, + int index, + unsigned long tag, + unsigned long start, + unsigned long end) +{ + uint32_t *entry; + + entry = _cairo_array_index (&font->output, 12 + 16 * index); + entry[0] = cpu_to_be32 ((uint32_t)tag); + entry[1] = cpu_to_be32 (cairo_truetype_font_calculate_checksum (font, start, end)); + entry[2] = cpu_to_be32 ((uint32_t)start); + entry[3] = cpu_to_be32 ((uint32_t)(end - start)); +} + +static cairo_status_t +cairo_truetype_font_generate (cairo_truetype_font_t *font, + const char **data, + unsigned long *length, + const unsigned long **string_offsets, + unsigned long *num_strings) +{ + cairo_status_t status; + unsigned long start, end, next; + uint32_t checksum, *checksum_location; + int i; + + if (font->status) + return font->status; + + status = cairo_truetype_font_write_offset_table (font); + if (unlikely (status)) + goto FAIL; + + status = cairo_truetype_font_align_output (font, &start); + if (unlikely (status)) + goto FAIL; + + end = 0; + for (i = 0; i < font->num_tables; i++) { + status = font->truetype_tables[i].write (font, font->truetype_tables[i].tag); + if (unlikely (status)) + goto FAIL; + + end = _cairo_array_num_elements (&font->output); + status = cairo_truetype_font_align_output (font, &next); + if (unlikely (status)) + goto FAIL; + + cairo_truetype_font_update_entry (font, font->truetype_tables[i].pos, + font->truetype_tables[i].tag, start, end); + status = cairo_truetype_font_check_boundary (font, next); + if (unlikely (status)) + goto FAIL; + + start = next; + } + + checksum = + 0xb1b0afba - cairo_truetype_font_calculate_checksum (font, 0, end); + checksum_location = _cairo_array_index (&font->output, font->checksum_index); + *checksum_location = cpu_to_be32 (checksum); + + *data = _cairo_array_index (&font->output, 0); + *length = _cairo_array_num_elements (&font->output); + *num_strings = _cairo_array_num_elements (&font->string_offsets); + if (*num_strings != 0) + *string_offsets = _cairo_array_index (&font->string_offsets, 0); + else + *string_offsets = NULL; + + FAIL: + return _cairo_truetype_font_set_error (font, status); +} + +static cairo_status_t +cairo_truetype_font_use_glyph (cairo_truetype_font_t *font, + unsigned short glyph, + unsigned short *out) +{ + if (glyph >= font->num_glyphs_in_face) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (font->parent_to_subset[glyph] == 0) { + font->parent_to_subset[glyph] = font->base.num_glyphs; + font->glyphs[font->base.num_glyphs].parent_index = glyph; + font->base.num_glyphs++; + } + + *out = font->parent_to_subset[glyph]; + return CAIRO_STATUS_SUCCESS; +} + +static void +cairo_truetype_font_add_truetype_table (cairo_truetype_font_t *font, + unsigned long tag, + cairo_status_t (*write) (cairo_truetype_font_t *font, unsigned long tag), + int pos) +{ + font->truetype_tables[font->num_tables].tag = tag; + font->truetype_tables[font->num_tables].write = write; + font->truetype_tables[font->num_tables].pos = pos; + font->num_tables++; +} + +/* cairo_truetype_font_create_truetype_table_list() builds the list of + * truetype tables to be embedded in the subsetted font. Each call to + * cairo_truetype_font_add_truetype_table() adds a table, the callback + * for generating the table, and the position in the table directory + * to the truetype_tables array. + * + * As we write out the glyf table we remap composite glyphs. + * Remapping composite glyphs will reference the sub glyphs the + * composite glyph is made up of. The "glyf" table callback needs to + * be called first so we have all the glyphs in the subset before + * going further. + * + * The order in which tables are added to the truetype_table array + * using cairo_truetype_font_add_truetype_table() specifies the order + * in which the callback functions will be called. + * + * The tables in the table directory must be listed in alphabetical + * order. The "cvt", "fpgm", and "prep" are optional tables. They + * will only be embedded in the subset if they exist in the source + * font. "cmap" is only embedded for latin fonts. The pos parameter of + * cairo_truetype_font_add_truetype_table() specifies the position of + * the table in the table directory. + */ +static void +cairo_truetype_font_create_truetype_table_list (cairo_truetype_font_t *font) +{ + cairo_bool_t has_cvt = FALSE; + cairo_bool_t has_fpgm = FALSE; + cairo_bool_t has_prep = FALSE; + unsigned long size; + int pos; + + size = 0; + if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_cvt, 0, NULL, + &size) == CAIRO_INT_STATUS_SUCCESS) + has_cvt = TRUE; + + size = 0; + if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_fpgm, 0, NULL, + &size) == CAIRO_INT_STATUS_SUCCESS) + has_fpgm = TRUE; + + size = 0; + if (font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, + TT_TAG_prep, 0, NULL, + &size) == CAIRO_INT_STATUS_SUCCESS) + has_prep = TRUE; + + font->num_tables = 0; + pos = 0; + if (font->is_pdf && font->scaled_font_subset->is_latin) + pos++; + if (has_cvt) + pos++; + if (has_fpgm) + pos++; + cairo_truetype_font_add_truetype_table (font, TT_TAG_glyf, cairo_truetype_font_write_glyf_table, pos); + + pos = 0; + if (font->is_pdf && font->scaled_font_subset->is_latin) + cairo_truetype_font_add_truetype_table (font, TT_TAG_cmap, cairo_truetype_font_write_cmap_table, pos++); + if (has_cvt) + cairo_truetype_font_add_truetype_table (font, TT_TAG_cvt, cairo_truetype_font_write_generic_table, pos++); + if (has_fpgm) + cairo_truetype_font_add_truetype_table (font, TT_TAG_fpgm, cairo_truetype_font_write_generic_table, pos++); + pos++; + cairo_truetype_font_add_truetype_table (font, TT_TAG_head, cairo_truetype_font_write_head_table, pos++); + cairo_truetype_font_add_truetype_table (font, TT_TAG_hhea, cairo_truetype_font_write_hhea_table, pos++); + cairo_truetype_font_add_truetype_table (font, TT_TAG_hmtx, cairo_truetype_font_write_hmtx_table, pos++); + cairo_truetype_font_add_truetype_table (font, TT_TAG_loca, cairo_truetype_font_write_loca_table, pos++); + cairo_truetype_font_add_truetype_table (font, TT_TAG_maxp, cairo_truetype_font_write_maxp_table, pos++); + if (has_prep) + cairo_truetype_font_add_truetype_table (font, TT_TAG_prep, cairo_truetype_font_write_generic_table, pos); +} + +static cairo_status_t +cairo_truetype_subset_init_internal (cairo_truetype_subset_t *truetype_subset, + cairo_scaled_font_subset_t *font_subset, + cairo_bool_t is_pdf) +{ + cairo_truetype_font_t *font = NULL; + cairo_status_t status; + const char *data = NULL; /* squelch bogus compiler warning */ + unsigned long length = 0; /* squelch bogus compiler warning */ + unsigned long offsets_length; + unsigned int i; + const unsigned long *string_offsets = NULL; + unsigned long num_strings = 0; + + status = _cairo_truetype_font_create (font_subset, is_pdf, &font); + if (unlikely (status)) + return status; + + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + unsigned short parent_glyph = font->scaled_font_subset->glyphs[i]; + status = cairo_truetype_font_use_glyph (font, parent_glyph, &parent_glyph); + if (unlikely (status)) + goto fail1; + } + + cairo_truetype_font_create_truetype_table_list (font); + status = cairo_truetype_font_generate (font, &data, &length, + &string_offsets, &num_strings); + if (unlikely (status)) + goto fail1; + + truetype_subset->ps_name = strdup (font->base.ps_name); + if (unlikely (truetype_subset->ps_name == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + if (font->base.font_name != NULL) { + truetype_subset->family_name_utf8 = strdup (font->base.font_name); + if (unlikely (truetype_subset->family_name_utf8 == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + } else { + truetype_subset->family_name_utf8 = NULL; + } + + /* The widths array returned must contain only widths for the + * glyphs in font_subset. Any subglyphs appended after + * font_subset->num_glyphs are omitted. */ + truetype_subset->widths = calloc (sizeof (double), + font->scaled_font_subset->num_glyphs); + if (unlikely (truetype_subset->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) + truetype_subset->widths[i] = (double)font->base.widths[i]/font->base.units_per_em; + + truetype_subset->x_min = (double)font->base.x_min/font->base.units_per_em; + truetype_subset->y_min = (double)font->base.y_min/font->base.units_per_em; + truetype_subset->x_max = (double)font->base.x_max/font->base.units_per_em; + truetype_subset->y_max = (double)font->base.y_max/font->base.units_per_em; + truetype_subset->ascent = (double)font->base.ascent/font->base.units_per_em; + truetype_subset->descent = (double)font->base.descent/font->base.units_per_em; + + if (length) { + truetype_subset->data = malloc (length); + if (unlikely (truetype_subset->data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail4; + } + + memcpy (truetype_subset->data, data, length); + } else + truetype_subset->data = NULL; + truetype_subset->data_length = length; + + if (num_strings) { + offsets_length = num_strings * sizeof (unsigned long); + truetype_subset->string_offsets = malloc (offsets_length); + if (unlikely (truetype_subset->string_offsets == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail5; + } + + memcpy (truetype_subset->string_offsets, string_offsets, offsets_length); + truetype_subset->num_string_offsets = num_strings; + } else { + truetype_subset->string_offsets = NULL; + truetype_subset->num_string_offsets = 0; + } + + cairo_truetype_font_destroy (font); + + return CAIRO_STATUS_SUCCESS; + + fail5: + free (truetype_subset->data); + fail4: + free (truetype_subset->widths); + fail3: + free (truetype_subset->family_name_utf8); + fail2: + free (truetype_subset->ps_name); + fail1: + cairo_truetype_font_destroy (font); + + return status; +} + +cairo_status_t +_cairo_truetype_subset_init_ps (cairo_truetype_subset_t *truetype_subset, + cairo_scaled_font_subset_t *font_subset) +{ + return cairo_truetype_subset_init_internal (truetype_subset, font_subset, FALSE); +} + +cairo_status_t +_cairo_truetype_subset_init_pdf (cairo_truetype_subset_t *truetype_subset, + cairo_scaled_font_subset_t *font_subset) +{ + return cairo_truetype_subset_init_internal (truetype_subset, font_subset, TRUE); +} + +void +_cairo_truetype_subset_fini (cairo_truetype_subset_t *subset) +{ + free (subset->ps_name); + free (subset->family_name_utf8); + free (subset->widths); + free (subset->data); + free (subset->string_offsets); +} + +static cairo_int_status_t +_cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font, + unsigned long table_offset, + unsigned long index, + uint32_t *ucs4) +{ + cairo_status_t status; + const cairo_scaled_font_backend_t *backend; + tt_segment_map_t *map; + char buf[4]; + unsigned int num_segments, i; + unsigned long size; + uint16_t *start_code; + uint16_t *end_code; + uint16_t *delta; + uint16_t *range_offset; + uint16_t c; + + backend = scaled_font->backend; + size = 4; + status = backend->load_truetype_table (scaled_font, + TT_TAG_cmap, table_offset, + (unsigned char *) &buf, + &size); + if (unlikely (status)) + return status; + + /* All table formats have the same first two words */ + map = (tt_segment_map_t *) buf; + if (be16_to_cpu (map->format) != 4) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = be16_to_cpu (map->length); + map = malloc (size); + if (unlikely (map == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = backend->load_truetype_table (scaled_font, + TT_TAG_cmap, table_offset, + (unsigned char *) map, + &size); + if (unlikely (status)) + goto fail; + + num_segments = be16_to_cpu (map->segCountX2)/2; + + /* A Format 4 cmap contains 8 uint16_t numbers and 4 arrays of + * uint16_t each num_segments long. */ + if (size < (8 + 4*num_segments)*sizeof(uint16_t)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + end_code = map->endCount; + start_code = &(end_code[num_segments + 1]); + delta = &(start_code[num_segments]); + range_offset = &(delta[num_segments]); + + /* search for glyph in segments with rangeOffset=0 */ + for (i = 0; i < num_segments; i++) { + c = index - be16_to_cpu (delta[i]); + if (range_offset[i] == 0 && + c >= be16_to_cpu (start_code[i]) && + c <= be16_to_cpu (end_code[i])) + { + *ucs4 = c; + goto found; + } + } + + /* search for glyph in segments with rangeOffset=1 */ + for (i = 0; i < num_segments; i++) { + if (range_offset[i] != 0) { + uint16_t *glyph_ids = &range_offset[i] + be16_to_cpu (range_offset[i])/2; + int range_size = be16_to_cpu (end_code[i]) - be16_to_cpu (start_code[i]) + 1; + uint16_t g_id_be = cpu_to_be16 (index); + int j; + + if (range_size > 0) { + if ((char*)glyph_ids + 2*range_size > (char*)map + size) + return CAIRO_INT_STATUS_UNSUPPORTED; + + for (j = 0; j < range_size; j++) { + if (glyph_ids[j] == g_id_be) { + *ucs4 = be16_to_cpu (start_code[i]) + j; + goto found; + } + } + } + } + } + + /* glyph not found */ + *ucs4 = -1; + +found: + status = CAIRO_STATUS_SUCCESS; + +fail: + free (map); + + return status; +} + +cairo_int_status_t +_cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font, + unsigned long index, + uint32_t *ucs4) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + const cairo_scaled_font_backend_t *backend; + tt_cmap_t *cmap; + char buf[4]; + int num_tables, i; + unsigned long size; + + backend = scaled_font->backend; + if (!backend->load_truetype_table) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = 4; + status = backend->load_truetype_table (scaled_font, + TT_TAG_cmap, 0, + (unsigned char *) &buf, + &size); + if (unlikely (status)) + return status; + + cmap = (tt_cmap_t *) buf; + num_tables = be16_to_cpu (cmap->num_tables); + size = 4 + num_tables*sizeof(tt_cmap_index_t); + cmap = _cairo_malloc_ab_plus_c (num_tables, sizeof (tt_cmap_index_t), 4); + if (unlikely (cmap == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = backend->load_truetype_table (scaled_font, + TT_TAG_cmap, 0, + (unsigned char *) cmap, + &size); + if (unlikely (status)) + goto cleanup; + + /* Find a table with Unicode mapping */ + for (i = 0; i < num_tables; i++) { + if (be16_to_cpu (cmap->index[i].platform) == 3 && + be16_to_cpu (cmap->index[i].encoding) == 1) { + status = _cairo_truetype_reverse_cmap (scaled_font, + be32_to_cpu (cmap->index[i].offset), + index, + ucs4); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + break; + } + } + +cleanup: + free (cmap); + + return status; +} + +static cairo_status_t +find_name (tt_name_t *name, int name_id, int platform, int encoding, int language, char **str_out) +{ + tt_name_record_t *record; + int i, len; + char *str; + char *p; + cairo_bool_t has_tag; + cairo_status_t status; + + str = NULL; + for (i = 0; i < be16_to_cpu (name->num_records); i++) { + record = &(name->records[i]); + if (be16_to_cpu (record->name) == name_id && + be16_to_cpu (record->platform) == platform && + be16_to_cpu (record->encoding) == encoding && + (language == -1 || be16_to_cpu (record->language) == language)) { + + str = malloc (be16_to_cpu (record->length) + 1); + if (str == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + len = be16_to_cpu (record->length); + memcpy (str, + ((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset), + len); + str[be16_to_cpu (record->length)] = 0; + break; + } + } + if (str == NULL) { + *str_out = NULL; + return CAIRO_STATUS_SUCCESS; + } + + if (platform == 3) { /* Win platform, unicode encoding */ + /* convert to utf8 */ + int size = 0; + char *utf8; + uint16_t *u = (uint16_t *) str; + int u_len = len/2; + + for (i = 0; i < u_len; i++) + size += _cairo_ucs4_to_utf8 (be16_to_cpu(u[i]), NULL); + + utf8 = malloc (size + 1); + if (utf8 == NULL) { + status =_cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + p = utf8; + for (i = 0; i < u_len; i++) + p += _cairo_ucs4_to_utf8 (be16_to_cpu(u[i]), p); + *p = 0; + free (str); + str = utf8; + } else if (platform == 1) { /* Mac platform, Mac Roman encoding */ + /* Replace characters above 127 with underscores. We could use + * a lookup table to convert to unicode but since most fonts + * include a unicode name this is just a rarely used fallback. */ + for (i = 0; i < len; i++) { + if ((unsigned char)str[i] > 127) + str[i] = '_'; + } + } + + /* If font name is prefixed with a PDF subset tag, strip it off. */ + p = str; + len = strlen (str); + has_tag = FALSE; + if (len > 7 && p[6] == '+') { + has_tag = TRUE; + for (i = 0; i < 6; i++) { + if (p[i] < 'A' || p[i] > 'Z') { + has_tag = FALSE; + break; + } + } + } + if (has_tag) { + p = malloc (len - 6); + if (unlikely (p == NULL)) { + status =_cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail; + } + memcpy (p, str + 7, len - 7); + p[len-7] = 0; + free (str); + str = p; + } + + *str_out = str; + + return CAIRO_STATUS_SUCCESS; + + fail: + free (str); + + return status; +} + +cairo_int_status_t +_cairo_truetype_read_font_name (cairo_scaled_font_t *scaled_font, + char **ps_name_out, + char **font_name_out) +{ + cairo_status_t status; + const cairo_scaled_font_backend_t *backend; + tt_name_t *name; + unsigned long size; + char *ps_name = NULL; + char *family_name = NULL; + + backend = scaled_font->backend; + if (!backend->load_truetype_table) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = 0; + status = backend->load_truetype_table (scaled_font, + TT_TAG_name, 0, + NULL, + &size); + if (status) + return status; + + name = malloc (size); + if (name == NULL) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = backend->load_truetype_table (scaled_font, + TT_TAG_name, 0, + (unsigned char *) name, + &size); + if (status) + goto fail; + + /* Find PS Name (name_id = 6). OT spec says PS name must be one of + * the following two encodings */ + status = find_name (name, 6, 3, 1, 0x409, &ps_name); /* win, unicode, english-us */ + if (unlikely(status)) + goto fail; + + if (!ps_name) { + status = find_name (name, 6, 1, 0, 0, &ps_name); /* mac, roman, english */ + if (unlikely(status)) + goto fail; + } + + /* Find Family name (name_id = 1) */ + status = find_name (name, 1, 3, 1, 0x409, &family_name); /* win, unicode, english-us */ + if (unlikely(status)) + goto fail; + + if (!family_name) { + status = find_name (name, 1, 3, 0, 0x409, &family_name); /* win, symbol, english-us */ + if (unlikely(status)) + goto fail; + } + + if (!family_name) { + status = find_name (name, 1, 1, 0, 0, &family_name); /* mac, roman, english */ + if (unlikely(status)) + goto fail; + } + + if (!family_name) { + status = find_name (name, 1, 3, 1, -1, &family_name); /* win, unicode, any language */ + if (unlikely(status)) + goto fail; + } + + status = _cairo_escape_ps_name (&ps_name); + if (unlikely(status)) + goto fail; + + free (name); + + *ps_name_out = ps_name; + *font_name_out = family_name; + + return CAIRO_STATUS_SUCCESS; + +fail: + free (name); + free (ps_name); + free (family_name); + *ps_name_out = NULL; + *font_name_out = NULL; + + return status; +} + +cairo_int_status_t +_cairo_truetype_get_style (cairo_scaled_font_t *scaled_font, + int *weight, + cairo_bool_t *bold, + cairo_bool_t *italic) +{ + cairo_status_t status; + const cairo_scaled_font_backend_t *backend; + tt_os2_t os2; + unsigned long size; + uint16_t selection; + + backend = scaled_font->backend; + if (!backend->load_truetype_table) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = 0; + status = backend->load_truetype_table (scaled_font, + TT_TAG_OS2, 0, + NULL, + &size); + if (status) + return status; + + if (size < sizeof(os2)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = sizeof (os2); + status = backend->load_truetype_table (scaled_font, + TT_TAG_OS2, 0, + (unsigned char *) &os2, + &size); + if (status) + return status; + + *weight = be16_to_cpu (os2.usWeightClass); + selection = be16_to_cpu (os2.fsSelection); + *bold = (selection & TT_FS_SELECTION_BOLD) ? TRUE : FALSE; + *italic = (selection & TT_FS_SELECTION_ITALIC) ? TRUE : FALSE; + + return CAIRO_STATUS_SUCCESS; +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-type1-fallback.c b/Build/source/libs/cairo/cairo-src/src/cairo-type1-fallback.c new file mode 100644 index 00000000000..4a657413e48 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-type1-fallback.c @@ -0,0 +1,903 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Adrian Johnson + */ + +#define _BSD_SOURCE /* for snprintf(), strdup() */ +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-type1-private.h" +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-output-stream-private.h" + +typedef enum { + CAIRO_CHARSTRING_TYPE1, + CAIRO_CHARSTRING_TYPE2 +} cairo_charstring_type_t; + +typedef struct _cairo_type1_font { + int *widths; + + cairo_scaled_font_subset_t *scaled_font_subset; + cairo_scaled_font_t *type1_scaled_font; + + cairo_array_t contents; + + double x_min, y_min, x_max, y_max; + + const char *data; + unsigned long header_size; + unsigned long data_size; + unsigned long trailer_size; + int bbox_position; + int bbox_max_chars; + + cairo_output_stream_t *output; + + unsigned short eexec_key; + cairo_bool_t hex_encode; + int hex_column; +} cairo_type1_font_t; + +static cairo_status_t +cairo_type1_font_create (cairo_scaled_font_subset_t *scaled_font_subset, + cairo_type1_font_t **subset_return, + cairo_bool_t hex_encode) +{ + cairo_type1_font_t *font; + cairo_font_face_t *font_face; + cairo_matrix_t font_matrix; + cairo_matrix_t ctm; + cairo_font_options_t font_options; + cairo_status_t status; + + font = calloc (1, sizeof (cairo_type1_font_t)); + if (unlikely (font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + font->widths = calloc (scaled_font_subset->num_glyphs, sizeof (int)); + if (unlikely (font->widths == NULL)) { + free (font); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + font->scaled_font_subset = scaled_font_subset; + font->hex_encode = hex_encode; + + font_face = cairo_scaled_font_get_font_face (scaled_font_subset->scaled_font); + + cairo_matrix_init_scale (&font_matrix, 1000, -1000); + cairo_matrix_init_identity (&ctm); + + _cairo_font_options_init_default (&font_options); + cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF); + + font->type1_scaled_font = cairo_scaled_font_create (font_face, + &font_matrix, + &ctm, + &font_options); + status = font->type1_scaled_font->status; + if (unlikely (status)) + goto fail; + + _cairo_array_init (&font->contents, sizeof (unsigned char)); + font->output = NULL; + + *subset_return = font; + + return CAIRO_STATUS_SUCCESS; + +fail: + free (font->widths); + free (font); + + return status; +} + +/* Charstring commands. If the high byte is 0 the command is encoded + * with a single byte. */ +#define CHARSTRING_sbw 0x0c07 +#define CHARSTRING_rmoveto 0x0015 +#define CHARSTRING_rlineto 0x0005 +#define CHARSTRING_rcurveto 0x0008 +#define CHARSTRING_closepath 0x0009 +#define CHARSTRING_endchar 0x000e + +/* Before calling this function, the caller must allocate sufficient + * space in data (see _cairo_array_grow_by). The maximum number of + * bytes that will be used is 2. + */ +static void +charstring_encode_command (cairo_array_t *data, int command) +{ + cairo_status_t status; + unsigned int orig_size; + unsigned char buf[5]; + unsigned char *p = buf; + + if (command & 0xff00) + *p++ = command >> 8; + *p++ = command & 0x00ff; + + /* Ensure the array doesn't grow, which allows this function to + * have no possibility of failure. */ + orig_size = _cairo_array_size (data); + status = _cairo_array_append_multiple (data, buf, p - buf); + + assert (status == CAIRO_STATUS_SUCCESS); + assert (_cairo_array_size (data) == orig_size); +} + +/* Before calling this function, the caller must allocate sufficient + * space in data (see _cairo_array_grow_by). The maximum number of + * bytes that will be used is 5. + */ +static void +charstring_encode_integer (cairo_array_t *data, + int i, + cairo_charstring_type_t type) +{ + cairo_status_t status; + unsigned int orig_size; + unsigned char buf[10]; + unsigned char *p = buf; + + if (i >= -107 && i <= 107) { + *p++ = i + 139; + } else if (i >= 108 && i <= 1131) { + i -= 108; + *p++ = (i >> 8)+ 247; + *p++ = i & 0xff; + } else if (i >= -1131 && i <= -108) { + i = -i - 108; + *p++ = (i >> 8)+ 251; + *p++ = i & 0xff; + } else { + if (type == CAIRO_CHARSTRING_TYPE1) { + *p++ = 0xff; + *p++ = i >> 24; + *p++ = (i >> 16) & 0xff; + *p++ = (i >> 8) & 0xff; + *p++ = i & 0xff; + } else { + *p++ = 0xff; + *p++ = (i >> 8) & 0xff; + *p++ = i & 0xff; + *p++ = 0; + *p++ = 0; + } + } + + /* Ensure the array doesn't grow, which allows this function to + * have no possibility of failure. */ + orig_size = _cairo_array_size (data); + status = _cairo_array_append_multiple (data, buf, p - buf); + + assert (status == CAIRO_STATUS_SUCCESS); + assert (_cairo_array_size (data) == orig_size); +} + +typedef struct _ps_path_info { + cairo_array_t *data; + int current_x, current_y; + cairo_charstring_type_t type; +} t1_path_info_t; + +static cairo_status_t +_charstring_move_to (void *closure, + const cairo_point_t *point) +{ + t1_path_info_t *path_info = (t1_path_info_t *) closure; + int dx, dy; + cairo_status_t status; + + status = _cairo_array_grow_by (path_info->data, 12); + if (unlikely (status)) + return status; + + dx = _cairo_fixed_integer_part (point->x) - path_info->current_x; + dy = _cairo_fixed_integer_part (point->y) - path_info->current_y; + charstring_encode_integer (path_info->data, dx, path_info->type); + charstring_encode_integer (path_info->data, dy, path_info->type); + path_info->current_x += dx; + path_info->current_y += dy; + + charstring_encode_command (path_info->data, CHARSTRING_rmoveto); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_charstring_line_to (void *closure, + const cairo_point_t *point) +{ + t1_path_info_t *path_info = (t1_path_info_t *) closure; + int dx, dy; + cairo_status_t status; + + status = _cairo_array_grow_by (path_info->data, 12); + if (unlikely (status)) + return status; + + dx = _cairo_fixed_integer_part (point->x) - path_info->current_x; + dy = _cairo_fixed_integer_part (point->y) - path_info->current_y; + charstring_encode_integer (path_info->data, dx, path_info->type); + charstring_encode_integer (path_info->data, dy, path_info->type); + path_info->current_x += dx; + path_info->current_y += dy; + + charstring_encode_command (path_info->data, CHARSTRING_rlineto); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_charstring_curve_to (void *closure, + const cairo_point_t *point1, + const cairo_point_t *point2, + const cairo_point_t *point3) +{ + t1_path_info_t *path_info = (t1_path_info_t *) closure; + int dx1, dy1, dx2, dy2, dx3, dy3; + cairo_status_t status; + + status = _cairo_array_grow_by (path_info->data, 32); + if (unlikely (status)) + return status; + + dx1 = _cairo_fixed_integer_part (point1->x) - path_info->current_x; + dy1 = _cairo_fixed_integer_part (point1->y) - path_info->current_y; + dx2 = _cairo_fixed_integer_part (point2->x) - path_info->current_x - dx1; + dy2 = _cairo_fixed_integer_part (point2->y) - path_info->current_y - dy1; + dx3 = _cairo_fixed_integer_part (point3->x) - path_info->current_x - dx1 - dx2; + dy3 = _cairo_fixed_integer_part (point3->y) - path_info->current_y - dy1 - dy2; + charstring_encode_integer (path_info->data, dx1, path_info->type); + charstring_encode_integer (path_info->data, dy1, path_info->type); + charstring_encode_integer (path_info->data, dx2, path_info->type); + charstring_encode_integer (path_info->data, dy2, path_info->type); + charstring_encode_integer (path_info->data, dx3, path_info->type); + charstring_encode_integer (path_info->data, dy3, path_info->type); + path_info->current_x += dx1 + dx2 + dx3; + path_info->current_y += dy1 + dy2 + dy3; + charstring_encode_command (path_info->data, CHARSTRING_rcurveto); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_charstring_close_path (void *closure) +{ + cairo_status_t status; + t1_path_info_t *path_info = (t1_path_info_t *) closure; + + if (path_info->type == CAIRO_CHARSTRING_TYPE2) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_array_grow_by (path_info->data, 2); + if (unlikely (status)) + return status; + + charstring_encode_command (path_info->data, CHARSTRING_closepath); + + return CAIRO_STATUS_SUCCESS; +} + +static void +charstring_encrypt (cairo_array_t *data) +{ + unsigned char *d, *end; + uint16_t c, p, r; + + r = CAIRO_TYPE1_CHARSTRING_KEY; + d = (unsigned char *) _cairo_array_index (data, 0); + end = d + _cairo_array_num_elements (data); + while (d < end) { + p = *d; + c = p ^ (r >> 8); + r = (c + r) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; + *d++ = c; + } +} + +static cairo_int_status_t +cairo_type1_font_create_charstring (cairo_type1_font_t *font, + int subset_index, + int glyph_index, + cairo_charstring_type_t type, + cairo_array_t *data) +{ + cairo_int_status_t status; + cairo_scaled_glyph_t *scaled_glyph; + t1_path_info_t path_info; + cairo_text_extents_t *metrics; + cairo_bool_t emit_path = TRUE; + + /* This call may return CAIRO_INT_STATUS_UNSUPPORTED for bitmap fonts. */ + status = _cairo_scaled_glyph_lookup (font->type1_scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS| + CAIRO_SCALED_GLYPH_INFO_PATH, + &scaled_glyph); + + /* It is ok for the .notdef glyph to not have a path available. We + * just need the metrics to emit an empty glyph. */ + if (glyph_index == 0 && status == CAIRO_INT_STATUS_UNSUPPORTED) { + emit_path = FALSE; + status = _cairo_scaled_glyph_lookup (font->type1_scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + } + if (unlikely (status)) + return status; + + metrics = &scaled_glyph->metrics; + if (subset_index == 0) { + font->x_min = metrics->x_bearing; + font->y_min = metrics->y_bearing; + font->x_max = metrics->x_bearing + metrics->width; + font->y_max = metrics->y_bearing + metrics->height; + } else { + if (metrics->x_bearing < font->x_min) + font->x_min = metrics->x_bearing; + if (metrics->y_bearing < font->y_min) + font->y_min = metrics->y_bearing; + if (metrics->x_bearing + metrics->width > font->x_max) + font->x_max = metrics->x_bearing + metrics->width; + if (metrics->y_bearing + metrics->height > font->y_max) + font->y_max = metrics->y_bearing + metrics->height; + } + font->widths[subset_index] = metrics->x_advance; + + status = _cairo_array_grow_by (data, 30); + if (unlikely (status)) + return status; + + if (type == CAIRO_CHARSTRING_TYPE1) { + charstring_encode_integer (data, (int) scaled_glyph->metrics.x_bearing, type); + charstring_encode_integer (data, (int) scaled_glyph->metrics.y_bearing, type); + charstring_encode_integer (data, (int) scaled_glyph->metrics.x_advance, type); + charstring_encode_integer (data, (int) scaled_glyph->metrics.y_advance, type); + charstring_encode_command (data, CHARSTRING_sbw); + + path_info.current_x = (int) scaled_glyph->metrics.x_bearing; + path_info.current_y = (int) scaled_glyph->metrics.y_bearing; + } else { + charstring_encode_integer (data, (int) scaled_glyph->metrics.x_advance, type); + + path_info.current_x = 0; + path_info.current_y = 0; + } + path_info.data = data; + path_info.type = type; + if (emit_path) { + status = _cairo_path_fixed_interpret (scaled_glyph->path, + _charstring_move_to, + _charstring_line_to, + _charstring_curve_to, + _charstring_close_path, + &path_info); + if (unlikely (status)) + return status; + } + + status = _cairo_array_grow_by (data, 1); + if (unlikely (status)) + return status; + charstring_encode_command (path_info.data, CHARSTRING_endchar); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_type1_font_write_charstrings (cairo_type1_font_t *font, + cairo_output_stream_t *encrypted_output) +{ + cairo_status_t status; + unsigned char zeros[] = { 0, 0, 0, 0 }; + cairo_array_t data; + unsigned int i; + int length; + + _cairo_array_init (&data, sizeof (unsigned char)); + status = _cairo_array_grow_by (&data, 1024); + if (unlikely (status)) + goto fail; + + _cairo_output_stream_printf (encrypted_output, + "2 index /CharStrings %d dict dup begin\n", + font->scaled_font_subset->num_glyphs + 1); + + _cairo_scaled_font_freeze_cache (font->type1_scaled_font); + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + _cairo_array_truncate (&data, 0); + /* four "random" bytes required by encryption algorithm */ + status = _cairo_array_append_multiple (&data, zeros, 4); + if (unlikely (status)) + break; + + status = cairo_type1_font_create_charstring (font, i, + font->scaled_font_subset->glyphs[i], + CAIRO_CHARSTRING_TYPE1, + &data); + if (unlikely (status)) + break; + + charstring_encrypt (&data); + length = _cairo_array_num_elements (&data); + if (font->scaled_font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (encrypted_output, "/%s %d RD ", + font->scaled_font_subset->glyph_names[i], + length); + } else if (i == 0) { + _cairo_output_stream_printf (encrypted_output, "/.notdef %d RD ", length); + } else { + _cairo_output_stream_printf (encrypted_output, "/g%d %d RD ", i, length); + } + _cairo_output_stream_write (encrypted_output, + _cairo_array_index (&data, 0), + length); + _cairo_output_stream_printf (encrypted_output, " ND\n"); + } + _cairo_scaled_font_thaw_cache (font->type1_scaled_font); + +fail: + _cairo_array_fini (&data); + return status; +} + +static void +cairo_type1_font_write_header (cairo_type1_font_t *font, + const char *name) +{ + unsigned int i; + const char spaces[50] = " "; + + _cairo_output_stream_printf (font->output, + "%%!FontType1-1.1 %s 1.0\n" + "11 dict begin\n" + "/FontName /%s def\n" + "/PaintType 0 def\n" + "/FontType 1 def\n" + "/FontMatrix [0.001 0 0 0.001 0 0] readonly def\n", + name, + name); + + /* We don't know the bbox values until after the charstrings have + * been generated. Reserve some space and fill in the bbox + * later. */ + + /* Worst case for four signed ints with spaces between each number */ + font->bbox_max_chars = 50; + + _cairo_output_stream_printf (font->output, "/FontBBox {"); + font->bbox_position = _cairo_output_stream_get_position (font->output); + _cairo_output_stream_write (font->output, spaces, font->bbox_max_chars); + + _cairo_output_stream_printf (font->output, + "} readonly def\n" + "/Encoding 256 array\n" + "0 1 255 {1 index exch /.notdef put} for\n"); + if (font->scaled_font_subset->is_latin) { + for (i = 1; i < 256; i++) { + int subset_glyph = font->scaled_font_subset->latin_to_subset_glyph_index[i]; + + if (subset_glyph > 0) { + if (font->scaled_font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (font->output, "dup %d /%s put\n", + i, font->scaled_font_subset->glyph_names[subset_glyph]); + } else { + _cairo_output_stream_printf (font->output, "dup %d /g%d put\n", i, subset_glyph); + } + } + } + } else { + for (i = 1; i < font->scaled_font_subset->num_glyphs; i++) { + if (font->scaled_font_subset->glyph_names != NULL) { + _cairo_output_stream_printf (font->output, "dup %d /%s put\n", + i, font->scaled_font_subset->glyph_names[i]); + } else { + _cairo_output_stream_printf (font->output, "dup %d /g%d put\n", i, i); + } + } + } + _cairo_output_stream_printf (font->output, + "readonly def\n" + "currentdict end\n" + "currentfile eexec\n"); +} + +static cairo_status_t +cairo_type1_write_stream_encrypted (void *closure, + const unsigned char *data, + unsigned int length) +{ + const unsigned char *in, *end; + uint16_t c, p; + static const char hex_digits[16] = "0123456789abcdef"; + char digits[3]; + cairo_type1_font_t *font = closure; + + in = (const unsigned char *) data; + end = (const unsigned char *) data + length; + while (in < end) { + p = *in++; + c = p ^ (font->eexec_key >> 8); + font->eexec_key = (c + font->eexec_key) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; + + if (font->hex_encode) { + digits[0] = hex_digits[c >> 4]; + digits[1] = hex_digits[c & 0x0f]; + digits[2] = '\n'; + font->hex_column += 2; + + if (font->hex_column == 78) { + _cairo_output_stream_write (font->output, digits, 3); + font->hex_column = 0; + } else { + _cairo_output_stream_write (font->output, digits, 2); + } + } else { + digits[0] = c; + _cairo_output_stream_write (font->output, digits, 1); + } + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_type1_font_write_private_dict (cairo_type1_font_t *font, + const char *name) +{ + cairo_int_status_t status; + cairo_status_t status2; + cairo_output_stream_t *encrypted_output; + + font->eexec_key = CAIRO_TYPE1_PRIVATE_DICT_KEY; + font->hex_column = 0; + encrypted_output = _cairo_output_stream_create ( + cairo_type1_write_stream_encrypted, + NULL, + font); + if (_cairo_output_stream_get_status (encrypted_output)) + return _cairo_output_stream_destroy (encrypted_output); + + /* Note: the first four spaces at the start of this private dict + * are the four "random" bytes of plaintext required by the + * encryption algorithm */ + _cairo_output_stream_printf (encrypted_output, + " dup /Private 9 dict dup begin\n" + "/RD {string currentfile exch readstring pop}" + " bind executeonly def\n" + "/ND {noaccess def} executeonly def\n" + "/NP {noaccess put} executeonly def\n" + "/BlueValues [] def\n" + "/MinFeature {16 16} def\n" + "/lenIV 4 def\n" + "/password 5839 def\n"); + + status = cairo_type1_font_write_charstrings (font, encrypted_output); + if (unlikely (status)) + goto fail; + + _cairo_output_stream_printf (encrypted_output, + "end\n" + "end\n" + "readonly put\n" + "noaccess put\n" + "dup /FontName get exch definefont pop\n" + "mark currentfile closefile\n"); + + fail: + status2 = _cairo_output_stream_destroy (encrypted_output); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + + return status; +} + +static void +cairo_type1_font_write_trailer(cairo_type1_font_t *font) +{ + int i; + static const char zeros[65] = + "0000000000000000000000000000000000000000000000000000000000000000\n"; + + for (i = 0; i < 8; i++) + _cairo_output_stream_write (font->output, zeros, sizeof zeros); + + _cairo_output_stream_printf (font->output, "cleartomark\n"); +} + +static cairo_status_t +cairo_type1_write_stream (void *closure, + const unsigned char *data, + unsigned int length) +{ + cairo_type1_font_t *font = closure; + + return _cairo_array_append_multiple (&font->contents, data, length); +} + +static cairo_int_status_t +cairo_type1_font_write (cairo_type1_font_t *font, + const char *name) +{ + cairo_int_status_t status; + + cairo_type1_font_write_header (font, name); + font->header_size = _cairo_output_stream_get_position (font->output); + + status = cairo_type1_font_write_private_dict (font, name); + if (unlikely (status)) + return status; + + font->data_size = _cairo_output_stream_get_position (font->output) - + font->header_size; + + cairo_type1_font_write_trailer (font); + font->trailer_size = + _cairo_output_stream_get_position (font->output) - + font->header_size - font->data_size; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +cairo_type1_font_generate (cairo_type1_font_t *font, const char *name) +{ + cairo_int_status_t status; + + status = _cairo_array_grow_by (&font->contents, 4096); + if (unlikely (status)) + return status; + + font->output = _cairo_output_stream_create (cairo_type1_write_stream, NULL, font); + if (_cairo_output_stream_get_status (font->output)) + return _cairo_output_stream_destroy (font->output); + + status = cairo_type1_font_write (font, name); + if (unlikely (status)) + return status; + + font->data = _cairo_array_index (&font->contents, 0); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_type1_font_destroy (cairo_type1_font_t *font) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + free (font->widths); + cairo_scaled_font_destroy (font->type1_scaled_font); + _cairo_array_fini (&font->contents); + if (font->output) + status = _cairo_output_stream_destroy (font->output); + free (font); + + return status; +} + +static cairo_status_t +_cairo_type1_fallback_init_internal (cairo_type1_subset_t *type1_subset, + const char *name, + cairo_scaled_font_subset_t *scaled_font_subset, + cairo_bool_t hex_encode) +{ + cairo_type1_font_t *font; + cairo_status_t status; + unsigned long length; + unsigned int i, len; + + status = cairo_type1_font_create (scaled_font_subset, &font, hex_encode); + if (unlikely (status)) + return status; + + status = cairo_type1_font_generate (font, name); + if (unlikely (status)) + goto fail1; + + type1_subset->base_font = strdup (name); + if (unlikely (type1_subset->base_font == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + type1_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); + if (unlikely (type1_subset->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail2; + } + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) + type1_subset->widths[i] = (double)font->widths[i]/1000; + + type1_subset->x_min = (double)font->x_min/1000; + type1_subset->y_min = (double)font->y_min/1000; + type1_subset->x_max = (double)font->x_max/1000; + type1_subset->y_max = (double)font->y_max/1000; + type1_subset->ascent = (double)font->y_max/1000; + type1_subset->descent = (double)font->y_min/1000; + + length = font->header_size + font->data_size + + font->trailer_size; + type1_subset->data = malloc (length); + if (unlikely (type1_subset->data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail3; + } + memcpy (type1_subset->data, + _cairo_array_index (&font->contents, 0), length); + + len = snprintf(type1_subset->data + font->bbox_position, + font->bbox_max_chars, + "%d %d %d %d", + (int)font->x_min, + (int)font->y_min, + (int)font->x_max, + (int)font->y_max); + type1_subset->data[font->bbox_position + len] = ' '; + + type1_subset->header_length = font->header_size; + type1_subset->data_length = font->data_size; + type1_subset->trailer_length = font->trailer_size; + + return cairo_type1_font_destroy (font); + + fail3: + free (type1_subset->widths); + fail2: + free (type1_subset->base_font); + fail1: + /* status is already set, ignore further errors */ + cairo_type1_font_destroy (font); + + return status; +} + +cairo_status_t +_cairo_type1_fallback_init_binary (cairo_type1_subset_t *type1_subset, + const char *name, + cairo_scaled_font_subset_t *scaled_font_subset) +{ + return _cairo_type1_fallback_init_internal (type1_subset, + name, + scaled_font_subset, FALSE); +} + +cairo_status_t +_cairo_type1_fallback_init_hex (cairo_type1_subset_t *type1_subset, + const char *name, + cairo_scaled_font_subset_t *scaled_font_subset) +{ + return _cairo_type1_fallback_init_internal (type1_subset, + name, + scaled_font_subset, TRUE); +} + +void +_cairo_type1_fallback_fini (cairo_type1_subset_t *subset) +{ + free (subset->base_font); + free (subset->widths); + free (subset->data); +} + +cairo_status_t +_cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset, + cairo_scaled_font_subset_t *scaled_font_subset) +{ + cairo_type1_font_t *font; + cairo_status_t status; + unsigned int i; + cairo_array_t charstring; + + status = cairo_type1_font_create (scaled_font_subset, &font, FALSE); + if (unlikely (status)) + return status; + + _cairo_array_init (&type2_subset->charstrings, sizeof (cairo_array_t)); + + type2_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs); + if (unlikely (type2_subset->widths == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto fail1; + } + + _cairo_scaled_font_freeze_cache (font->type1_scaled_font); + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + _cairo_array_init (&charstring, sizeof (unsigned char)); + status = _cairo_array_grow_by (&charstring, 32); + if (unlikely (status)) + goto fail2; + + status = cairo_type1_font_create_charstring (font, i, + font->scaled_font_subset->glyphs[i], + CAIRO_CHARSTRING_TYPE2, + &charstring); + if (unlikely (status)) + goto fail2; + + status = _cairo_array_append (&type2_subset->charstrings, &charstring); + if (unlikely (status)) + goto fail2; + } + _cairo_scaled_font_thaw_cache (font->type1_scaled_font); + + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) + type2_subset->widths[i] = font->widths[i]; + + type2_subset->x_min = (int) font->x_min; + type2_subset->y_min = (int) font->y_min; + type2_subset->x_max = (int) font->x_max; + type2_subset->y_max = (int) font->y_max; + type2_subset->ascent = (int) font->y_max; + type2_subset->descent = (int) font->y_min; + + return cairo_type1_font_destroy (font); + +fail2: + _cairo_scaled_font_thaw_cache (font->type1_scaled_font); + _cairo_array_fini (&charstring); + _cairo_type2_charstrings_fini (type2_subset); +fail1: + cairo_type1_font_destroy (font); + return status; +} + +void +_cairo_type2_charstrings_fini (cairo_type2_charstrings_t *type2_subset) +{ + unsigned int i, num_charstrings; + cairo_array_t *charstring; + + num_charstrings = _cairo_array_num_elements (&type2_subset->charstrings); + for (i = 0; i < num_charstrings; i++) { + charstring = _cairo_array_index (&type2_subset->charstrings, i); + _cairo_array_fini (charstring); + } + _cairo_array_fini (&type2_subset->charstrings); + + free (type2_subset->widths); +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-type1-glyph-names.c b/Build/source/libs/cairo/cairo-src/src/cairo-type1-glyph-names.c new file mode 100644 index 00000000000..80ccb96269e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-type1-glyph-names.c @@ -0,0 +1,410 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + */ + +#include "cairoint.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-type1-private.h" +#include "cairo-scaled-font-subsets-private.h" + +#if 0 +/* + * The three tables that follow are generated using this perl code: + */ + +@ps_standard_encoding = ( + # 0 + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 16 + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 32 + "space", "exclam", "quotedbl", "numbersign", + "dollar", "percent", "ampersand", "quoteright", + "parenleft", "parenright", "asterisk", "plus", + "comma", "hyphen", "period", "slash", + # 48 + "zero", "one", "two", "three", + "four", "five", "six", "seven", + "eight", "nine", "colon", "semicolon", + "less", "equal", "greater", "question", + # 64 + "at", "A", "B", "C", + "D", "E", "F", "G", + "H", "I", "J", "K", + "L", "M", "N", "O", + # 80 + "P", "Q", "R", "S", + "T", "U", "V", "W", + "X", "Y", "Z", "bracketleft", + "backslash", "bracketright", "asciicircum", "underscore", + # 96 + "quoteleft", "a", "b", "c", + "d", "e", "f", "g", + "h", "i", "j", "k", + "l", "m", "n", "o", + # 112 + "p", "q", "r", "s", + "t", "u", "v", "w", + "x", "y", "z", "braceleft", + "bar", "braceright", "asciitilde", NULL, + # 128 + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 144 + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 160 + NULL, "exclamdown", "cent", "sterling", + "fraction", "yen", "florin", "section", + "currency", "quotesingle", "quotedblleft", "guillemotleft", + "guilsinglleft","guilsinglright","fi", "fl", + # 176 + NULL, "endash", "dagger", "daggerdbl", + "periodcentered",NULL, "paragraph", "bullet", + "quotesinglbase","quotedblbase","quotedblright","guillemotright", + "ellipsis", "perthousand", NULL, "questiondown", + # 192 + NULL, "grave", "acute", "circumflex", + "tilde", "macron", "breve", "dotaccent", + "dieresis", NULL, "ring", "cedilla", + NULL, "hungarumlaut", "ogonek", "caron", + # 208 + "emdash", NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 224 + NULL, "AE", NULL, "ordfeminine", + NULL, NULL, NULL, NULL, + "Lslash", "Oslash", "OE", "ordmasculine", + NULL, NULL, NULL, NULL, + # 240 + NULL, "ae", NULL, NULL, + NULL, "dotlessi", NULL, NULL, + "lslash", "oslash", "oe", "germandbls", + NULL, NULL, NULL, NULL + ); + +@winansi_encoding = ( + # 0 + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 16 + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + # 32 + "space", "exclam", "quotedbl", "numbersign", + "dollar", "percent", "ampersand", "quotesingle", + "parenleft", "parenright", "asterisk", "plus", + "comma", "hyphen", "period", "slash", + # 48 + "zero", "one", "two", "three", + "four", "five", "six", "seven", + "eight", "nine", "colon", "semicolon", + "less", "equal", "greater", "question", + # 64 + "at", "A", "B", "C", + "D", "E", "F", "G", + "H", "I", "J", "K", + "L", "M", "N", "O", + # 80 + "P", "Q", "R", "S", + "T", "U", "V", "W", + "X", "Y", "Z", "bracketleft", + "backslash", "bracketright", "asciicircum", "underscore", + # 96 + "grave", "a", "b", "c", + "d", "e", "f", "g", + "h", "i", "j", "k", + "l", "m", "n", "o", + # 112 + "p", "q", "r", "s", + "t", "u", "v", "w", + "x", "y", "z", "braceleft", + "bar", "braceright", "asciitilde", NULL, + # 128 + "Euro", NULL, "quotesinglbase","florin", + "quotedblbase", "ellipsis", "dagger", "daggerdbl", + "circumflex", "perthousand", "Scaron", "guilsinglleft", + "OE", NULL, "Zcaron", NULL, + # 144 + NULL, "quoteleft", "quoteright", "quotedblleft", + "quotedblright","bullet", "endash", "emdash", + "tilde", "trademark", "scaron", "guilsinglright", + "oe", NULL, "zcaron", "Ydieresis", + # 160 + NULL, "exclamdown", "cent", "sterling", + "currency", "yen", "brokenbar", "section", + "dieresis", "copyright", "ordfeminine", "guillemotleft", + # 173 is also "hyphen" but we leave this NULL to avoid duplicate names + "logicalnot", NULL, "registered", "macron", + # 176 + "degree", "plusminus", "twosuperior", "threesuperior", + "acute", "mu", "paragraph", "periodcentered", + "cedilla", "onesuperior", "ordmasculine", "guillemotright", + "onequarter", "onehalf", "threequarters","questiondown", + # 192 + "Agrave", "Aacute", "Acircumflex", "Atilde", + "Adieresis", "Aring", "AE", "Ccedilla", + "Egrave", "Eacute", "Ecircumflex", "Edieresis", + "Igrave", "Iacute", "Icircumflex", "Idieresis", + # 208 + "Eth", "Ntilde", "Ograve", "Oacute", + "Ocircumflex", "Otilde", "Odieresis", "multiply", + "Oslash", "Ugrave", "Uacute", "Ucircumflex", + "Udieresis", "Yacute", "Thorn", "germandbls", + # 224 + "agrave", "aacute", "acircumflex", "atilde", + "adieresis", "aring", "ae", "ccedilla", + "egrave", "eacute", "ecircumflex", "edieresis", + "igrave", "iacute", "icircumflex", "idieresis", + # 240 + "eth", "ntilde", "ograve", "oacute", + "ocircumflex", "otilde", "odieresis", "divide", + "oslash", "ugrave", "uacute", "ucircumflex", + "udieresis", "yacute", "thorn", "ydieresis" +); + +sub print_offsets { + $s = qq(); + for $sym (@_) { + if (! ($sym eq NULL)) { + $ss = qq( $hash{$sym}/*$sym*/,); + } else { + $ss = qq( 0,); + } + if (length($s) + length($ss) > 78) { + print qq( $s\n); + $s = ""; + } + $s .= $ss; + } + print qq( $s\n); +} + +@combined = (@ps_standard_encoding, @winansi_encoding); +print "static const char glyph_name_symbol[] = {\n"; +%hash = (); +$s = qq( "\\0"); +$offset = 1; +for $sym (@combined) { + if (! ($sym eq NULL)) { + if (! exists $hash{$sym}) { + $hash{$sym} = $offset; + $offset += length($sym) + 1; + $ss = qq( "$sym\\0"); + if (length($s) + length($ss) > 78) { + print qq( $s\n); + $s = ""; + } + $s .= $ss; + } + } +} +print qq( $s\n); +print "};\n\n"; + +print "static const int16_t ps_standard_encoding_offset[256] = {\n"; +print_offsets(@ps_standard_encoding); +print "};\n"; + +print "static const int16_t winansi_encoding_offset[256] = {\n"; +print_offsets(@winansi_encoding); +print "};\n"; + +exit; +#endif + +static const char glyph_name_symbol[] = { + "\0" "space\0" "exclam\0" "quotedbl\0" "numbersign\0" "dollar\0" "percent\0" + "ampersand\0" "quoteright\0" "parenleft\0" "parenright\0" "asterisk\0" + "plus\0" "comma\0" "hyphen\0" "period\0" "slash\0" "zero\0" "one\0" "two\0" + "three\0" "four\0" "five\0" "six\0" "seven\0" "eight\0" "nine\0" "colon\0" + "semicolon\0" "less\0" "equal\0" "greater\0" "question\0" "at\0" "A\0" "B\0" + "C\0" "D\0" "E\0" "F\0" "G\0" "H\0" "I\0" "J\0" "K\0" "L\0" "M\0" "N\0" "O\0" + "P\0" "Q\0" "R\0" "S\0" "T\0" "U\0" "V\0" "W\0" "X\0" "Y\0" "Z\0" + "bracketleft\0" "backslash\0" "bracketright\0" "asciicircum\0" "underscore\0" + "quoteleft\0" "a\0" "b\0" "c\0" "d\0" "e\0" "f\0" "g\0" "h\0" "i\0" "j\0" + "k\0" "l\0" "m\0" "n\0" "o\0" "p\0" "q\0" "r\0" "s\0" "t\0" "u\0" "v\0" "w\0" + "x\0" "y\0" "z\0" "braceleft\0" "bar\0" "braceright\0" "asciitilde\0" + "exclamdown\0" "cent\0" "sterling\0" "fraction\0" "yen\0" "florin\0" + "section\0" "currency\0" "quotesingle\0" "quotedblleft\0" "guillemotleft\0" + "guilsinglleft\0" "guilsinglright\0" "fi\0" "fl\0" "endash\0" "dagger\0" + "daggerdbl\0" "periodcentered\0" "paragraph\0" "bullet\0" "quotesinglbase\0" + "quotedblbase\0" "quotedblright\0" "guillemotright\0" "ellipsis\0" + "perthousand\0" "questiondown\0" "grave\0" "acute\0" "circumflex\0" "tilde\0" + "macron\0" "breve\0" "dotaccent\0" "dieresis\0" "ring\0" "cedilla\0" + "hungarumlaut\0" "ogonek\0" "caron\0" "emdash\0" "AE\0" "ordfeminine\0" + "Lslash\0" "Oslash\0" "OE\0" "ordmasculine\0" "ae\0" "dotlessi\0" "lslash\0" + "oslash\0" "oe\0" "germandbls\0" "Euro\0" "Scaron\0" "Zcaron\0" "trademark\0" + "scaron\0" "zcaron\0" "Ydieresis\0" "brokenbar\0" "copyright\0" + "logicalnot\0" "registered\0" "degree\0" "plusminus\0" "twosuperior\0" + "threesuperior\0" "mu\0" "onesuperior\0" "onequarter\0" "onehalf\0" + "threequarters\0" "Agrave\0" "Aacute\0" "Acircumflex\0" "Atilde\0" + "Adieresis\0" "Aring\0" "Ccedilla\0" "Egrave\0" "Eacute\0" "Ecircumflex\0" + "Edieresis\0" "Igrave\0" "Iacute\0" "Icircumflex\0" "Idieresis\0" "Eth\0" + "Ntilde\0" "Ograve\0" "Oacute\0" "Ocircumflex\0" "Otilde\0" "Odieresis\0" + "multiply\0" "Ugrave\0" "Uacute\0" "Ucircumflex\0" "Udieresis\0" "Yacute\0" + "Thorn\0" "agrave\0" "aacute\0" "acircumflex\0" "atilde\0" "adieresis\0" + "aring\0" "ccedilla\0" "egrave\0" "eacute\0" "ecircumflex\0" "edieresis\0" + "igrave\0" "iacute\0" "icircumflex\0" "idieresis\0" "eth\0" "ntilde\0" + "ograve\0" "oacute\0" "ocircumflex\0" "otilde\0" "odieresis\0" "divide\0" + "ugrave\0" "uacute\0" "ucircumflex\0" "udieresis\0" "yacute\0" "thorn\0" + "ydieresis\0" +}; + +static const int16_t ps_standard_encoding_offset[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1/*space*/, 7/*exclam*/, 14/*quotedbl*/, 23/*numbersign*/, + 34/*dollar*/, 41/*percent*/, 49/*ampersand*/, 59/*quoteright*/, + 70/*parenleft*/, 80/*parenright*/, 91/*asterisk*/, 100/*plus*/, 105/*comma*/, + 111/*hyphen*/, 118/*period*/, 125/*slash*/, 131/*zero*/, 136/*one*/, + 140/*two*/, 144/*three*/, 150/*four*/, 155/*five*/, 160/*six*/, 164/*seven*/, + 170/*eight*/, 176/*nine*/, 181/*colon*/, 187/*semicolon*/, 197/*less*/, + 202/*equal*/, 208/*greater*/, 216/*question*/, 225/*at*/, 228/*A*/, 230/*B*/, + 232/*C*/, 234/*D*/, 236/*E*/, 238/*F*/, 240/*G*/, 242/*H*/, 244/*I*/, + 246/*J*/, 248/*K*/, 250/*L*/, 252/*M*/, 254/*N*/, 256/*O*/, 258/*P*/, + 260/*Q*/, 262/*R*/, 264/*S*/, 266/*T*/, 268/*U*/, 270/*V*/, 272/*W*/, + 274/*X*/, 276/*Y*/, 278/*Z*/, 280/*bracketleft*/, 292/*backslash*/, + 302/*bracketright*/, 315/*asciicircum*/, 327/*underscore*/, 338/*quoteleft*/, + 348/*a*/, 350/*b*/, 352/*c*/, 354/*d*/, 356/*e*/, 358/*f*/, 360/*g*/, + 362/*h*/, 364/*i*/, 366/*j*/, 368/*k*/, 370/*l*/, 372/*m*/, 374/*n*/, + 376/*o*/, 378/*p*/, 380/*q*/, 382/*r*/, 384/*s*/, 386/*t*/, 388/*u*/, + 390/*v*/, 392/*w*/, 394/*x*/, 396/*y*/, 398/*z*/, 400/*braceleft*/, + 410/*bar*/, 414/*braceright*/, 425/*asciitilde*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 436/*exclamdown*/, 447/*cent*/, 452/*sterling*/, 461/*fraction*/, 470/*yen*/, + 474/*florin*/, 481/*section*/, 489/*currency*/, 498/*quotesingle*/, + 510/*quotedblleft*/, 523/*guillemotleft*/, 537/*guilsinglleft*/, + 551/*guilsinglright*/, 566/*fi*/, 569/*fl*/, 0, 572/*endash*/, 579/*dagger*/, + 586/*daggerdbl*/, 596/*periodcentered*/, 0, 611/*paragraph*/, 621/*bullet*/, + 628/*quotesinglbase*/, 643/*quotedblbase*/, 656/*quotedblright*/, + 670/*guillemotright*/, 685/*ellipsis*/, 694/*perthousand*/, 0, + 706/*questiondown*/, 0, 719/*grave*/, 725/*acute*/, 731/*circumflex*/, + 742/*tilde*/, 748/*macron*/, 755/*breve*/, 761/*dotaccent*/, 771/*dieresis*/, + 0, 780/*ring*/, 785/*cedilla*/, 0, 793/*hungarumlaut*/, 806/*ogonek*/, + 813/*caron*/, 819/*emdash*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 826/*AE*/, 0, 829/*ordfeminine*/, 0, 0, 0, 0, 841/*Lslash*/, 848/*Oslash*/, + 855/*OE*/, 858/*ordmasculine*/, 0, 0, 0, 0, 0, 871/*ae*/, 0, 0, 0, + 874/*dotlessi*/, 0, 0, 883/*lslash*/, 890/*oslash*/, 897/*oe*/, + 900/*germandbls*/, 0, 0, 0, 0, +}; + +static const int16_t winansi_encoding_offset[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1/*space*/, 7/*exclam*/, 14/*quotedbl*/, 23/*numbersign*/, + 34/*dollar*/, 41/*percent*/, 49/*ampersand*/, 498/*quotesingle*/, + 70/*parenleft*/, 80/*parenright*/, 91/*asterisk*/, 100/*plus*/, 105/*comma*/, + 111/*hyphen*/, 118/*period*/, 125/*slash*/, 131/*zero*/, 136/*one*/, + 140/*two*/, 144/*three*/, 150/*four*/, 155/*five*/, 160/*six*/, 164/*seven*/, + 170/*eight*/, 176/*nine*/, 181/*colon*/, 187/*semicolon*/, 197/*less*/, + 202/*equal*/, 208/*greater*/, 216/*question*/, 225/*at*/, 228/*A*/, 230/*B*/, + 232/*C*/, 234/*D*/, 236/*E*/, 238/*F*/, 240/*G*/, 242/*H*/, 244/*I*/, + 246/*J*/, 248/*K*/, 250/*L*/, 252/*M*/, 254/*N*/, 256/*O*/, 258/*P*/, + 260/*Q*/, 262/*R*/, 264/*S*/, 266/*T*/, 268/*U*/, 270/*V*/, 272/*W*/, + 274/*X*/, 276/*Y*/, 278/*Z*/, 280/*bracketleft*/, 292/*backslash*/, + 302/*bracketright*/, 315/*asciicircum*/, 327/*underscore*/, 719/*grave*/, + 348/*a*/, 350/*b*/, 352/*c*/, 354/*d*/, 356/*e*/, 358/*f*/, 360/*g*/, + 362/*h*/, 364/*i*/, 366/*j*/, 368/*k*/, 370/*l*/, 372/*m*/, 374/*n*/, + 376/*o*/, 378/*p*/, 380/*q*/, 382/*r*/, 384/*s*/, 386/*t*/, 388/*u*/, + 390/*v*/, 392/*w*/, 394/*x*/, 396/*y*/, 398/*z*/, 400/*braceleft*/, + 410/*bar*/, 414/*braceright*/, 425/*asciitilde*/, 0, 911/*Euro*/, 0, + 628/*quotesinglbase*/, 474/*florin*/, 643/*quotedblbase*/, 685/*ellipsis*/, + 579/*dagger*/, 586/*daggerdbl*/, 731/*circumflex*/, 694/*perthousand*/, + 916/*Scaron*/, 537/*guilsinglleft*/, 855/*OE*/, 0, 923/*Zcaron*/, 0, 0, + 338/*quoteleft*/, 59/*quoteright*/, 510/*quotedblleft*/, + 656/*quotedblright*/, 621/*bullet*/, 572/*endash*/, 819/*emdash*/, + 742/*tilde*/, 930/*trademark*/, 940/*scaron*/, 551/*guilsinglright*/, + 897/*oe*/, 0, 947/*zcaron*/, 954/*Ydieresis*/, 0, 436/*exclamdown*/, + 447/*cent*/, 452/*sterling*/, 489/*currency*/, 470/*yen*/, 964/*brokenbar*/, + 481/*section*/, 771/*dieresis*/, 974/*copyright*/, 829/*ordfeminine*/, + 523/*guillemotleft*/, 984/*logicalnot*/, 0, 995/*registered*/, 748/*macron*/, + 1006/*degree*/, 1013/*plusminus*/, 1023/*twosuperior*/, + 1035/*threesuperior*/, 725/*acute*/, 1049/*mu*/, 611/*paragraph*/, + 596/*periodcentered*/, 785/*cedilla*/, 1052/*onesuperior*/, + 858/*ordmasculine*/, 670/*guillemotright*/, 1064/*onequarter*/, + 1075/*onehalf*/, 1083/*threequarters*/, 706/*questiondown*/, 1097/*Agrave*/, + 1104/*Aacute*/, 1111/*Acircumflex*/, 1123/*Atilde*/, 1130/*Adieresis*/, + 1140/*Aring*/, 826/*AE*/, 1146/*Ccedilla*/, 1155/*Egrave*/, 1162/*Eacute*/, + 1169/*Ecircumflex*/, 1181/*Edieresis*/, 1191/*Igrave*/, 1198/*Iacute*/, + 1205/*Icircumflex*/, 1217/*Idieresis*/, 1227/*Eth*/, 1231/*Ntilde*/, + 1238/*Ograve*/, 1245/*Oacute*/, 1252/*Ocircumflex*/, 1264/*Otilde*/, + 1271/*Odieresis*/, 1281/*multiply*/, 848/*Oslash*/, 1290/*Ugrave*/, + 1297/*Uacute*/, 1304/*Ucircumflex*/, 1316/*Udieresis*/, 1326/*Yacute*/, + 1333/*Thorn*/, 900/*germandbls*/, 1339/*agrave*/, 1346/*aacute*/, + 1353/*acircumflex*/, 1365/*atilde*/, 1372/*adieresis*/, 1382/*aring*/, + 871/*ae*/, 1388/*ccedilla*/, 1397/*egrave*/, 1404/*eacute*/, + 1411/*ecircumflex*/, 1423/*edieresis*/, 1433/*igrave*/, 1440/*iacute*/, + 1447/*icircumflex*/, 1459/*idieresis*/, 1469/*eth*/, 1473/*ntilde*/, + 1480/*ograve*/, 1487/*oacute*/, 1494/*ocircumflex*/, 1506/*otilde*/, + 1513/*odieresis*/, 1523/*divide*/, 890/*oslash*/, 1530/*ugrave*/, + 1537/*uacute*/, 1544/*ucircumflex*/, 1556/*udieresis*/, 1566/*yacute*/, + 1573/*thorn*/, 1579/*ydieresis*/, +}; + +const char * +_cairo_ps_standard_encoding_to_glyphname (int glyph) +{ + if (ps_standard_encoding_offset[glyph]) + return glyph_name_symbol + ps_standard_encoding_offset[glyph]; + else + return NULL; +} + +const char * +_cairo_winansi_to_glyphname (int glyph) +{ + if (winansi_encoding_offset[glyph]) + return glyph_name_symbol + winansi_encoding_offset[glyph]; + else + return NULL; +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-type1-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-type1-private.h new file mode 100644 index 00000000000..1630397bca6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-type1-private.h @@ -0,0 +1,51 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Adrian Johnson + */ + +#ifndef CAIRO_TYPE1_PRIVATE_H +#define CAIRO_TYPE1_PRIVATE_H + +#include "cairoint.h" + +#if CAIRO_HAS_FONT_SUBSET + +/* Magic constants for the type1 eexec encryption */ +#define CAIRO_TYPE1_ENCRYPT_C1 ((unsigned short) 52845) +#define CAIRO_TYPE1_ENCRYPT_C2 ((unsigned short) 22719) +#define CAIRO_TYPE1_PRIVATE_DICT_KEY ((unsigned short) 55665) +#define CAIRO_TYPE1_CHARSTRING_KEY ((unsigned short) 4330) + +#endif /* CAIRO_HAS_FONT_SUBSET */ + +#endif /* CAIRO_TYPE1_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-type1-subset.c b/Build/source/libs/cairo/cairo-src/src/cairo-type1-subset.c new file mode 100644 index 00000000000..b15663509d3 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-type1-subset.c @@ -0,0 +1,1821 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + */ + +/* + * Useful links: + * http://partners.adobe.com/public/developer/en/font/T1_SPEC.PDF + */ + + +#define _BSD_SOURCE /* for snprintf(), strdup() */ +#include "cairoint.h" + +#include "cairo-array-private.h" +#include "cairo-error-private.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-type1-private.h" +#include "cairo-scaled-font-subsets-private.h" +#include "cairo-output-stream-private.h" + +#include + +#define TYPE1_STACKSIZE 24 /* Defined in Type 1 Font Format */ + + +typedef struct { + int subset_index; + double width; + const char *encrypted_charstring; + int encrypted_charstring_length; +} glyph_data_t; + +typedef struct _cairo_type1_font_subset { + cairo_scaled_font_subset_t *scaled_font_subset; + + struct { + unsigned int font_id; + char *base_font; + unsigned int num_glyphs; + double x_min, y_min, x_max, y_max; + double ascent, descent; + double units_per_em; + + const char *data; + unsigned long header_size; + unsigned long data_size; + unsigned long trailer_size; + } base; + + int num_glyphs; + + /* The glyphs and glyph_names arrays are indexed by the order of + * the Charstrings in the font. This is not necessarily the same + * order as the glyph index. The index_to_glyph_name() font backend + * function is used to map the glyph index to the glyph order in + * the Charstrings. */ + + glyph_data_t *glyphs; + char **glyph_names; + cairo_array_t glyphs_array; + cairo_array_t glyph_names_array; + + int num_subrs; + cairo_bool_t subset_subrs; + struct { + const char *subr_string; + int subr_length; + const char *np; + int np_length; + cairo_bool_t used; + } *subrs; + + /* Indexed by subset_index this maps to the glyph order in the + * glyph_names and glyphs arrays. Has font->num_golyphs + * elements. */ + int *subset_index_to_glyphs; + + cairo_output_stream_t *output; + cairo_array_t contents; + + const char *rd, *nd, *np; + + int lenIV; + + char *type1_data; + unsigned int type1_length; + char *type1_end; + + char *header_segment; + int header_segment_size; + char *eexec_segment; + int eexec_segment_size; + cairo_bool_t eexec_segment_is_ascii; + + char *cleartext; + char *cleartext_end; + + int header_size; + + unsigned short eexec_key; + cairo_bool_t hex_encode; + int hex_column; + + struct { + double stack[TYPE1_STACKSIZE]; + int sp; + } build_stack; + + struct { + int stack[TYPE1_STACKSIZE]; + int sp; + } ps_stack; + + +} cairo_type1_font_subset_t; + + +static cairo_status_t +_cairo_type1_font_subset_init (cairo_type1_font_subset_t *font, + cairo_scaled_font_subset_t *scaled_font_subset, + cairo_bool_t hex_encode) +{ + memset (font, 0, sizeof (*font)); + font->scaled_font_subset = scaled_font_subset; + + _cairo_array_init (&font->glyphs_array, sizeof (glyph_data_t)); + _cairo_array_init (&font->glyph_names_array, sizeof (char *)); + font->subset_index_to_glyphs = NULL; + font->base.num_glyphs = 0; + font->num_subrs = 0; + font->subset_subrs = TRUE; + font->subrs = NULL; + + font->hex_encode = hex_encode; + font->num_glyphs = 0; + + _cairo_array_init (&font->contents, sizeof (char)); + + return CAIRO_STATUS_SUCCESS; +} + +static void +cairo_type1_font_subset_use_glyph (cairo_type1_font_subset_t *font, int glyph) +{ + if (font->glyphs[glyph].subset_index >= 0) + return; + + font->glyphs[glyph].subset_index = font->num_glyphs; + font->subset_index_to_glyphs[font->num_glyphs] = glyph; + font->num_glyphs++; +} + +static cairo_bool_t +is_ps_delimiter(int c) +{ + static const char delimiters[] = "()[]{}<>/% \t\r\n"; + + return strchr (delimiters, c) != NULL; +} + +static const char * +find_token (const char *buffer, const char *end, const char *token) +{ + int i, length; + /* FIXME: find substring really must be find_token */ + + if (buffer == NULL) + return NULL; + + length = strlen (token); + for (i = 0; buffer + i < end - length + 1; i++) + if (memcmp (buffer + i, token, length) == 0) + if ((i == 0 || token[0] == '/' || is_ps_delimiter(buffer[i - 1])) && + (buffer + i == end - length || is_ps_delimiter(buffer[i + length]))) + return buffer + i; + + return NULL; +} + +static cairo_status_t +cairo_type1_font_subset_find_segments (cairo_type1_font_subset_t *font) +{ + unsigned char *p; + const char *eexec_token; + int size, i; + + p = (unsigned char *) font->type1_data; + font->type1_end = font->type1_data + font->type1_length; + if (p[0] == 0x80 && p[1] == 0x01) { + font->header_segment_size = + p[2] | (p[3] << 8) | (p[4] << 16) | (p[5] << 24); + font->header_segment = (char *) p + 6; + + p += 6 + font->header_segment_size; + font->eexec_segment_size = + p[2] | (p[3] << 8) | (p[4] << 16) | (p[5] << 24); + font->eexec_segment = (char *) p + 6; + font->eexec_segment_is_ascii = (p[1] == 1); + + p += 6 + font->eexec_segment_size; + while (p < (unsigned char *) (font->type1_end) && p[1] != 0x03) { + size = p[2] | (p[3] << 8) | (p[4] << 16) | (p[5] << 24); + p += 6 + size; + } + font->type1_end = (char *) p; + } else { + eexec_token = find_token ((char *) p, font->type1_end, "eexec"); + if (eexec_token == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + font->header_segment_size = eexec_token - (char *) p + strlen ("eexec\n"); + font->header_segment = (char *) p; + font->eexec_segment_size = font->type1_length - font->header_segment_size; + font->eexec_segment = (char *) p + font->header_segment_size; + font->eexec_segment_is_ascii = TRUE; + for (i = 0; i < 4; i++) { + if (!isxdigit(font->eexec_segment[i])) + font->eexec_segment_is_ascii = FALSE; + } + } + + return CAIRO_STATUS_SUCCESS; +} + +/* Search for the definition of key and erase it by overwriting with spaces. + * This function is looks for definitions of the form: + * + * /key1 1234 def + * /key2 [12 34 56] def + * + * ie a key defined as an integer or array of integers. + * + */ +static void +cairo_type1_font_erase_dict_key (cairo_type1_font_subset_t *font, + const char *key) +{ + const char *start, *p, *segment_end; + + segment_end = font->header_segment + font->header_segment_size; + + start = font->header_segment; + do { + start = find_token (start, segment_end, key); + if (start) { + p = start + strlen(key); + /* skip integers or array of integers */ + while (p < segment_end && + (_cairo_isspace(*p) || + _cairo_isdigit(*p) || + *p == '[' || + *p == ']')) + { + p++; + } + + if (p + 3 < segment_end && memcmp(p, "def", 3) == 0) { + /* erase definition of the key */ + memset((char *) start, ' ', p + 3 - start); + } + start += strlen(key); + } + } while (start); +} + +static cairo_status_t +cairo_type1_font_subset_get_matrix (cairo_type1_font_subset_t *font, + const char *name, + double *a, + double *b, + double *c, + double *d) +{ + const char *start, *end, *segment_end; + int ret, s_max, i, j; + char *s; + const char *decimal_point; + int decimal_point_len; + + decimal_point = cairo_get_locale_decimal_point (); + decimal_point_len = strlen (decimal_point); + + assert (decimal_point_len != 0); + + segment_end = font->header_segment + font->header_segment_size; + start = find_token (font->header_segment, segment_end, name); + if (start == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + end = find_token (start, segment_end, "def"); + if (end == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + s_max = end - start + 5*decimal_point_len + 1; + s = malloc (s_max); + if (unlikely (s == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + i = 0; + j = 0; + while (i < end - start && j < s_max - decimal_point_len) { + if (start[i] == '.') { + strncpy(s + j, decimal_point, decimal_point_len); + i++; + j += decimal_point_len; + } else { + s[j++] = start[i++]; + } + } + s[j] = 0; + + start = strpbrk (s, "{["); + if (!start) { + free (s); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + start++; + ret = 0; + if (*start) + ret = sscanf(start, "%lf %lf %lf %lf", a, b, c, d); + + free (s); + + if (ret != 4) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_type1_font_subset_get_bbox (cairo_type1_font_subset_t *font) +{ + cairo_status_t status; + double x_min, y_min, x_max, y_max; + double xx, yx, xy, yy; + + status = cairo_type1_font_subset_get_matrix (font, "/FontBBox", + &x_min, + &y_min, + &x_max, + &y_max); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_get_matrix (font, "/FontMatrix", + &xx, &yx, &xy, &yy); + if (unlikely (status)) + return status; + + if (yy == 0.0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Freetype uses 1/yy to get units per EM */ + font->base.units_per_em = 1.0/yy; + + font->base.x_min = x_min / font->base.units_per_em; + font->base.y_min = y_min / font->base.units_per_em; + font->base.x_max = x_max / font->base.units_per_em; + font->base.y_max = y_max / font->base.units_per_em; + font->base.ascent = font->base.y_max; + font->base.descent = font->base.y_min; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_type1_font_subset_get_fontname (cairo_type1_font_subset_t *font) +{ + const char *start, *end, *segment_end; + char *s; + int i; + cairo_status_t status; + + segment_end = font->header_segment + font->header_segment_size; + start = find_token (font->header_segment, segment_end, "/FontName"); + if (start == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + start += strlen ("/FontName"); + + end = find_token (start, segment_end, "def"); + if (end == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + while (end > start && _cairo_isspace(end[-1])) + end--; + + s = malloc (end - start + 1); + if (unlikely (s == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + strncpy (s, start, end - start); + s[end - start] = 0; + + start = strchr (s, '/'); + if (!start++ || !start) { + free (s); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* If font name is prefixed with a subset tag, strip it off. */ + if (strlen(start) > 7 && start[6] == '+') { + for (i = 0; i < 6; i++) { + if (start[i] < 'A' || start[i] > 'Z') + break; + } + if (i == 6) + start += 7; + } + + font->base.base_font = strdup (start); + free (s); + if (unlikely (font->base.base_font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_escape_ps_name (&font->base.base_font); + + return status; +} + +static cairo_status_t +cairo_type1_font_subset_write_header (cairo_type1_font_subset_t *font, + const char *name) +{ + const char *start, *end, *segment_end; + unsigned int i; + + /* FIXME: + * This function assumes that /FontName always appears + * before /Encoding. This appears to always be the case with Type1 + * fonts. + * + * The more recently added code for removing the UniqueID and XUID + * keys can not make any assumptions about the position of the + * keys in the dictionary so it is implemented by overwriting the + * key definition with spaces before we start copying the font to + * the output. + * + * This code should be rewritten to not make any assumptions about + * the order of dictionary keys. This will allow UniqueID to be + * stripped out instead of leaving a bunch of spaces in the + * output. + */ + cairo_type1_font_erase_dict_key (font, "/UniqueID"); + cairo_type1_font_erase_dict_key (font, "/XUID"); + + segment_end = font->header_segment + font->header_segment_size; + + /* Type 1 fonts created by Fontforge have some PostScript code at + * the start of the font that skips the font if the printer has a + * cached copy of the font with the same unique id. This breaks + * our subsetted font so we disable it by searching for the + * PostScript operator "known" when used to check for the + * "/UniqueID" dictionary key. We append " pop false " after it to + * pop the result of this check off the stack and replace it with + * "false" to make the PostScript code think "/UniqueID" does not + * exist. + */ + end = font->header_segment; + start = find_token (font->header_segment, segment_end, "/UniqueID"); + if (start) { + start += 9; + while (start < segment_end && _cairo_isspace (*start)) + start++; + if (start + 5 < segment_end && memcmp(start, "known", 5) == 0) { + _cairo_output_stream_write (font->output, font->header_segment, + start + 5 - font->header_segment); + _cairo_output_stream_printf (font->output, " pop false "); + end = start + 5; + } + } + + start = find_token (end, segment_end, "/FontName"); + if (start == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_output_stream_write (font->output, end, + start - end); + + _cairo_output_stream_printf (font->output, "/FontName /%s def", name); + + end = find_token (start, segment_end, "def"); + if (end == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + end += 3; + + start = find_token (end, segment_end, "/Encoding"); + if (start == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + _cairo_output_stream_write (font->output, end, start - end); + + _cairo_output_stream_printf (font->output, + "/Encoding 256 array\n" + "0 1 255 {1 index exch /.notdef put} for\n"); + if (font->scaled_font_subset->is_latin) { + for (i = 1; i < 256; i++) { + int subset_glyph = font->scaled_font_subset->latin_to_subset_glyph_index[i]; + + if (subset_glyph > 0) { + _cairo_output_stream_printf (font->output, + "dup %d /%s put\n", + i, + _cairo_winansi_to_glyphname (i)); + } + } + } else { + for (i = 0; i < font->base.num_glyphs; i++) { + if (font->glyphs[i].subset_index <= 0) + continue; + _cairo_output_stream_printf (font->output, + "dup %d /%s put\n", + font->glyphs[i].subset_index, + font->glyph_names[i]); + } + } + _cairo_output_stream_printf (font->output, "readonly def"); + + end = find_token (start, segment_end, "def"); + if (end == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + end += 3; + + /* There are some buggy fonts that contain more than one /Encoding */ + if (find_token (end, segment_end, "/Encoding")) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_output_stream_write (font->output, end, segment_end - end); + + return font->output->status; +} + +static int +hex_to_int (int ch) +{ + if (ch <= '9') + return ch - '0'; + else if (ch <= 'F') + return ch - 'A' + 10; + else + return ch - 'a' + 10; +} + +static cairo_status_t +cairo_type1_font_subset_write_encrypted (cairo_type1_font_subset_t *font, + const char *data, unsigned int length) +{ + const unsigned char *in, *end; + int c, p; + static const char hex_digits[16] = "0123456789abcdef"; + char digits[3]; + + in = (const unsigned char *) data; + end = (const unsigned char *) data + length; + while (in < end) { + p = *in++; + c = p ^ (font->eexec_key >> 8); + font->eexec_key = (c + font->eexec_key) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; + + if (font->hex_encode) { + digits[0] = hex_digits[c >> 4]; + digits[1] = hex_digits[c & 0x0f]; + digits[2] = '\n'; + font->hex_column += 2; + + if (font->hex_column == 78) { + _cairo_output_stream_write (font->output, digits, 3); + font->hex_column = 0; + } else { + _cairo_output_stream_write (font->output, digits, 2); + } + } else { + digits[0] = c; + _cairo_output_stream_write (font->output, digits, 1); + } + } + + return font->output->status; +} + +static cairo_status_t +cairo_type1_font_subset_decrypt_eexec_segment (cairo_type1_font_subset_t *font) +{ + unsigned short r = CAIRO_TYPE1_PRIVATE_DICT_KEY; + unsigned char *in, *end; + char *out; + int c, p; + int i; + + in = (unsigned char *) font->eexec_segment; + end = (unsigned char *) in + font->eexec_segment_size; + + font->cleartext = malloc (font->eexec_segment_size + 1); + if (unlikely (font->cleartext == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + out = font->cleartext; + while (in < end) { + if (font->eexec_segment_is_ascii) { + c = *in++; + if (_cairo_isspace (c)) + continue; + c = (hex_to_int (c) << 4) | hex_to_int (*in++); + } else { + c = *in++; + } + p = c ^ (r >> 8); + r = (c + r) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; + + *out++ = p; + } + font->cleartext_end = out; + + /* Overwrite random bytes with spaces. + * + * The first 4 bytes of the cleartext are the random bytes + * required by the encryption algorithm. When encrypting the + * cleartext, the first ciphertext byte must not be a white space + * character and the first 4 bytes must not be an ASCII Hex + * character. Some fonts do not check that their randomly chosen + * bytes results in ciphertext that complies with this + * restriction. This may cause problems for some PDF consumers. By + * replacing the random bytes with spaces, the first four bytes of + * ciphertext will always be 0xf9, 0x83, 0xef, 0x00 which complies + * with this restriction. Using spaces also means we don't have to + * skip over the random bytes when parsing the cleartext. + */ + for (i = 0; i < 4 && i < font->eexec_segment_size; i++) + font->cleartext[i] = ' '; + + /* Ensure strtol() can not scan past the end of the cleartext */ + font->cleartext[font->eexec_segment_size] = 0; + + return CAIRO_STATUS_SUCCESS; +} + +static const char * +skip_token (const char *p, const char *end) +{ + while (p < end && _cairo_isspace(*p)) + p++; + + while (p < end && !_cairo_isspace(*p)) + p++; + + if (p == end) + return NULL; + + return p; +} + +static void +cairo_type1_font_subset_decrypt_charstring (const unsigned char *in, int size, unsigned char *out) +{ + unsigned short r = CAIRO_TYPE1_CHARSTRING_KEY; + int c, p, i; + + for (i = 0; i < size; i++) { + c = *in++; + p = c ^ (r >> 8); + r = (c + r) * CAIRO_TYPE1_ENCRYPT_C1 + CAIRO_TYPE1_ENCRYPT_C2; + *out++ = p; + } +} + +static const unsigned char * +cairo_type1_font_subset_decode_integer (const unsigned char *p, int *integer) +{ + if (*p <= 246) { + *integer = *p++ - 139; + } else if (*p <= 250) { + *integer = (p[0] - 247) * 256 + p[1] + 108; + p += 2; + } else if (*p <= 254) { + *integer = -(p[0] - 251) * 256 - p[1] - 108; + p += 2; + } else { + *integer = (p[1] << 24) | (p[2] << 16) | (p[3] << 8) | p[4]; + p += 5; + } + + return p; +} + +static cairo_status_t +use_standard_encoding_glyph (cairo_type1_font_subset_t *font, int index) +{ + const char *glyph_name; + unsigned int i; + + if (index < 0 || index > 255) + return CAIRO_STATUS_SUCCESS; + + glyph_name = _cairo_ps_standard_encoding_to_glyphname (index); + if (glyph_name == NULL) + return CAIRO_STATUS_SUCCESS; + + for (i = 0; i < font->base.num_glyphs; i++) { + if (font->glyph_names[i] && strcmp (font->glyph_names[i], glyph_name) == 0) { + cairo_type1_font_subset_use_glyph (font, i); + + return CAIRO_STATUS_SUCCESS; + } + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + + +#define TYPE1_CHARSTRING_COMMAND_HSTEM 0x01 +#define TYPE1_CHARSTRING_COMMAND_VSTEM 0x03 +#define TYPE1_CHARSTRING_COMMAND_VMOVETO 0x04 +#define TYPE1_CHARSTRING_COMMAND_RLINETO 0x05 +#define TYPE1_CHARSTRING_COMMAND_HLINETO 0x06 +#define TYPE1_CHARSTRING_COMMAND_VLINETO 0x07 +#define TYPE1_CHARSTRING_COMMAND_RRCURVETO 0x08 +#define TYPE1_CHARSTRING_COMMAND_CLOSEPATH 0x09 +#define TYPE1_CHARSTRING_COMMAND_CALLSUBR 0x0a +#define TYPE1_CHARSTRING_COMMAND_RETURN 0x0b +#define TYPE1_CHARSTRING_COMMAND_ESCAPE 0x0c +#define TYPE1_CHARSTRING_COMMAND_HSBW 0x0d +#define TYPE1_CHARSTRING_COMMAND_ENDCHAR 0x0e +#define TYPE1_CHARSTRING_COMMAND_RMOVETO 0x15 +#define TYPE1_CHARSTRING_COMMAND_HMOVETO 0x16 +#define TYPE1_CHARSTRING_COMMAND_VHCURVETO 0x1e +#define TYPE1_CHARSTRING_COMMAND_HVCURVETO 0x1f +#define TYPE1_CHARSTRING_COMMAND_DOTSECTION 0x0c00 +#define TYPE1_CHARSTRING_COMMAND_VSTEM3 0x0c01 +#define TYPE1_CHARSTRING_COMMAND_HSTEM3 0x0c02 +#define TYPE1_CHARSTRING_COMMAND_SEAC 0x0c06 +#define TYPE1_CHARSTRING_COMMAND_SBW 0x0c07 +#define TYPE1_CHARSTRING_COMMAND_DIV 0x0c0c +#define TYPE1_CHARSTRING_COMMAND_CALLOTHERSUBR 0x0c10 +#define TYPE1_CHARSTRING_COMMAND_POP 0x0c11 +#define TYPE1_CHARSTRING_COMMAND_SETCURRENTPOINT 0x0c21 + +/* Parse the charstring, including recursing into subroutines. Find + * the glyph width, subroutines called, and glyphs required by the + * SEAC operator. */ +static cairo_status_t +cairo_type1_font_subset_parse_charstring (cairo_type1_font_subset_t *font, + int glyph, + const char *encrypted_charstring, + int encrypted_charstring_length) +{ + cairo_status_t status; + unsigned char *charstring; + const unsigned char *end; + const unsigned char *p; + int command; + + charstring = malloc (encrypted_charstring_length); + if (unlikely (charstring == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + cairo_type1_font_subset_decrypt_charstring ((const unsigned char *) + encrypted_charstring, + encrypted_charstring_length, + charstring); + end = charstring + encrypted_charstring_length; + p = charstring + font->lenIV; + status = CAIRO_STATUS_SUCCESS; + while (p < end) { + if (*p < 32) { + command = *p++; + switch (command) { + case TYPE1_CHARSTRING_COMMAND_HSTEM: + case TYPE1_CHARSTRING_COMMAND_VSTEM: + case TYPE1_CHARSTRING_COMMAND_VMOVETO: + case TYPE1_CHARSTRING_COMMAND_RLINETO: + case TYPE1_CHARSTRING_COMMAND_HLINETO: + case TYPE1_CHARSTRING_COMMAND_VLINETO: + case TYPE1_CHARSTRING_COMMAND_RRCURVETO: + case TYPE1_CHARSTRING_COMMAND_CLOSEPATH: + case TYPE1_CHARSTRING_COMMAND_RMOVETO: + case TYPE1_CHARSTRING_COMMAND_HMOVETO: + case TYPE1_CHARSTRING_COMMAND_VHCURVETO: + case TYPE1_CHARSTRING_COMMAND_HVCURVETO: + case TYPE1_CHARSTRING_COMMAND_RETURN: + case TYPE1_CHARSTRING_COMMAND_ENDCHAR: + default: + /* stack clearing operator */ + font->build_stack.sp = 0; + break; + + case TYPE1_CHARSTRING_COMMAND_CALLSUBR: + if (font->subset_subrs && font->build_stack.sp > 0) { + double int_val; + if (modf(font->build_stack.stack[--font->build_stack.sp], &int_val) == 0.0) { + int subr_num = int_val; + if (subr_num >= 0 && subr_num < font->num_subrs) { + font->subrs[subr_num].used = TRUE; + status = cairo_type1_font_subset_parse_charstring ( + font, + glyph, + font->subrs[subr_num].subr_string, + font->subrs[subr_num].subr_length); + break; + } + } + } + font->subset_subrs = FALSE; + break; + + case TYPE1_CHARSTRING_COMMAND_HSBW: + if (font->build_stack.sp < 2) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + + font->glyphs[glyph].width = font->build_stack.stack[1]/font->base.units_per_em; + font->build_stack.sp = 0; + break; + + case TYPE1_CHARSTRING_COMMAND_ESCAPE: + command = command << 8 | *p++; + switch (command) { + case TYPE1_CHARSTRING_COMMAND_DOTSECTION: + case TYPE1_CHARSTRING_COMMAND_VSTEM3: + case TYPE1_CHARSTRING_COMMAND_HSTEM3: + case TYPE1_CHARSTRING_COMMAND_SETCURRENTPOINT: + default: + /* stack clearing operator */ + font->build_stack.sp = 0; + break; + + case TYPE1_CHARSTRING_COMMAND_SEAC: + /* The seac command takes five integer arguments. The + * last two are glyph indices into the PS standard + * encoding give the names of the glyphs that this + * glyph is composed from. All we need to do is to + * make sure those glyphs are present in the subset + * under their standard names. */ + if (font->build_stack.sp < 5) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + + status = use_standard_encoding_glyph (font, font->build_stack.stack[3]); + if (unlikely (status)) + goto cleanup; + + status = use_standard_encoding_glyph (font, font->build_stack.stack[4]); + if (unlikely (status)) + goto cleanup; + + font->build_stack.sp = 0; + break; + + case TYPE1_CHARSTRING_COMMAND_SBW: + if (font->build_stack.sp < 4) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + + font->glyphs[glyph].width = font->build_stack.stack[2]/font->base.units_per_em; + font->build_stack.sp = 0; + break; + + case TYPE1_CHARSTRING_COMMAND_DIV: + if (font->build_stack.sp < 2) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } else { + double num1 = font->build_stack.stack[font->build_stack.sp - 2]; + double num2 = font->build_stack.stack[font->build_stack.sp - 1]; + font->build_stack.sp--; + if (num2 == 0.0) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + font->build_stack.stack[font->build_stack.sp - 1] = num1/num2; + } + break; + + case TYPE1_CHARSTRING_COMMAND_CALLOTHERSUBR: + if (font->build_stack.sp < 1) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + + font->build_stack.sp--; + font->ps_stack.sp = 0; + while (font->build_stack.sp) + font->ps_stack.stack[font->ps_stack.sp++] = font->build_stack.stack[--font->build_stack.sp]; + + break; + + case TYPE1_CHARSTRING_COMMAND_POP: + if (font->ps_stack.sp < 1) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + + /* T1 spec states that if the interpreter does not + * support executing the callothersub, the results + * must be taken from the callothersub arguments. */ + font->build_stack.stack[font->build_stack.sp++] = font->ps_stack.stack[--font->ps_stack.sp]; + break; + } + break; + } + } else { + /* integer argument */ + if (font->build_stack.sp < TYPE1_STACKSIZE) { + int val; + p = cairo_type1_font_subset_decode_integer (p, &val); + font->build_stack.stack[font->build_stack.sp++] = val; + } else { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto cleanup; + } + } + } + +cleanup: + free (charstring); + + return status; +} + +static cairo_status_t +cairo_type1_font_subset_build_subr_list (cairo_type1_font_subset_t *font, + int subr_number, + const char *encrypted_charstring, int encrypted_charstring_length, + const char *np, int np_length) +{ + + font->subrs[subr_number].subr_string = encrypted_charstring; + font->subrs[subr_number].subr_length = encrypted_charstring_length; + font->subrs[subr_number].np = np; + font->subrs[subr_number].np_length = np_length; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +write_used_subrs (cairo_type1_font_subset_t *font, + int subr_number, + const char *subr_string, int subr_string_length, + const char *np, int np_length) +{ + cairo_status_t status; + char buffer[256]; + int length; + + if (!font->subrs[subr_number].used) + return CAIRO_STATUS_SUCCESS; + + length = snprintf (buffer, sizeof buffer, + "dup %d %d %s ", + subr_number, subr_string_length, font->rd); + status = cairo_type1_font_subset_write_encrypted (font, buffer, length); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_write_encrypted (font, + subr_string, + subr_string_length); + if (unlikely (status)) + return status; + + if (np) { + status = cairo_type1_font_subset_write_encrypted (font, np, np_length); + } else { + length = snprintf (buffer, sizeof buffer, "%s\n", font->np); + status = cairo_type1_font_subset_write_encrypted (font, buffer, length); + } + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +typedef cairo_status_t (*subr_func_t) (cairo_type1_font_subset_t *font, + int subr_number, + const char *subr_string, int subr_string_length, + const char *np, int np_length); + +static cairo_status_t +cairo_type1_font_for_each_subr (cairo_type1_font_subset_t *font, + const char *array_start, + const char *cleartext_end, + subr_func_t func, + const char **array_end) +{ + const char *p, *subr_string; + char *end; + int subr_num, subr_length; + const char *np; + int np_length; + cairo_status_t status; + + /* We're looking at "dup" at the start of the first subroutine. The subroutines + * definitions are on the form: + * + * dup 5 23 RD <23 binary bytes> NP + * + * or alternatively using -| and |- instead of RD and ND. + * The first number is the subroutine number. + */ + + p = array_start; + while (p + 3 < cleartext_end && strncmp (p, "dup", 3) == 0) { + p = skip_token (p, cleartext_end); + + /* get subr number */ + subr_num = strtol (p, &end, 10); + if (p == end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (subr_num < 0 || subr_num >= font->num_subrs) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* get subr length */ + p = end; + subr_length = strtol (p, &end, 10); + if (p == end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Skip past -| or RD to binary data. There is exactly one space + * between the -| or RD token and the encrypted data, thus '+ 1'. */ + subr_string = skip_token (end, cleartext_end) + 1; + + np = NULL; + np_length = 0; + + /* Skip binary data and | or NP token. */ + p = skip_token (subr_string + subr_length, cleartext_end); + while (p < cleartext_end && _cairo_isspace(*p)) + p++; + + /* Some fonts have "noaccess put" instead of "NP" */ + if (p + 3 < cleartext_end && strncmp (p, "put", 3) == 0) { + p = skip_token (p, cleartext_end); + while (p < cleartext_end && _cairo_isspace(*p)) + p++; + + np = subr_string + subr_length; + np_length = p - np; + } + + status = func (font, subr_num, + subr_string, subr_length, np, np_length); + if (unlikely (status)) + return status; + + } + + *array_end = (char *) p; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_type1_font_subset_build_glyph_list (cairo_type1_font_subset_t *font, + int glyph_number, + const char *name, int name_length, + const char *encrypted_charstring, int encrypted_charstring_length) +{ + char *s; + glyph_data_t glyph; + cairo_status_t status; + + s = malloc (name_length + 1); + if (unlikely (s == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + strncpy (s, name, name_length); + s[name_length] = 0; + + status = _cairo_array_append (&font->glyph_names_array, &s); + if (unlikely (status)) + return status; + + glyph.subset_index = -1; + glyph.width = 0; + glyph.encrypted_charstring = encrypted_charstring; + glyph.encrypted_charstring_length = encrypted_charstring_length; + status = _cairo_array_append (&font->glyphs_array, &glyph); + + return status; +} + +static cairo_status_t +write_used_glyphs (cairo_type1_font_subset_t *font, + int glyph_number, + const char *name, int name_length, + const char *charstring, int charstring_length) +{ + cairo_status_t status; + char buffer[256]; + int length; + unsigned int subset_id; + int ch; + const char *wa_name; + + if (font->glyphs[glyph_number].subset_index < 0) + return CAIRO_STATUS_SUCCESS; + + if (font->scaled_font_subset->is_latin) { + /* When using the WinAnsi encoding in PDF, the /Encoding array + * is ignored and instead glyphs are keyed by glyph names. To + * ensure correct rendering we replace the glyph name in the + * font with the standard name. + **/ + subset_id = font->glyphs[glyph_number].subset_index; + /* Any additional glyph included for use by the seac operator + * will either have subset_id >= font->scaled_font_subset->num_glyphs + * or will not map to a winansi name (wa_name = NULL). In this + * case the original name is used. + */ + if (subset_id > 0 && subset_id < font->scaled_font_subset->num_glyphs) { + ch = font->scaled_font_subset->to_latin_char[subset_id]; + wa_name = _cairo_winansi_to_glyphname (ch); + if (wa_name) { + name = wa_name; + name_length = strlen(name); + } + } + } + + length = snprintf (buffer, sizeof buffer, + "/%.*s %d %s ", + name_length, name, charstring_length, font->rd); + status = cairo_type1_font_subset_write_encrypted (font, buffer, length); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_write_encrypted (font, + charstring, + charstring_length); + if (unlikely (status)) + return status; + + length = snprintf (buffer, sizeof buffer, "%s\n", font->nd); + status = cairo_type1_font_subset_write_encrypted (font, buffer, length); + if (unlikely (status)) + return status; + + return CAIRO_STATUS_SUCCESS; +} + +typedef cairo_status_t (*glyph_func_t) (cairo_type1_font_subset_t *font, + int glyph_number, + const char *name, int name_length, + const char *charstring, int charstring_length); + +static cairo_status_t +cairo_type1_font_subset_for_each_glyph (cairo_type1_font_subset_t *font, + const char *dict_start, + const char *dict_end, + glyph_func_t func, + const char **dict_out) +{ + int charstring_length, name_length; + const char *p, *charstring, *name; + char *end; + cairo_status_t status; + int glyph_count; + + /* We're looking at '/' in the name of the first glyph. The glyph + * definitions are on the form: + * + * /name 23 RD <23 binary bytes> ND + * + * or alternatively using -| and |- instead of RD and ND. + * + * We parse the glyph name and see if it is in the subset. If it + * is, we call the specified callback with the glyph name and + * glyph data, otherwise we just skip it. We need to parse + * through a glyph definition; we can't just find the next '/', + * since the binary data could contain a '/'. + */ + + p = dict_start; + glyph_count = 0; + while (*p == '/') { + name = p + 1; + p = skip_token (p, dict_end); + name_length = p - name; + + charstring_length = strtol (p, &end, 10); + if (p == end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Skip past -| or RD to binary data. There is exactly one space + * between the -| or RD token and the encrypted data, thus '+ 1'. */ + charstring = skip_token (end, dict_end) + 1; + + /* Skip binary data and |- or ND token. */ + p = skip_token (charstring + charstring_length, dict_end); + while (p < dict_end && _cairo_isspace(*p)) + p++; + + /* In case any of the skip_token() calls above reached EOF, p will + * be equal to dict_end. */ + if (p == dict_end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = func (font, glyph_count++, + name, name_length, + charstring, charstring_length); + if (unlikely (status)) + return status; + } + + *dict_out = p; + + return CAIRO_STATUS_SUCCESS; +} + + +static cairo_status_t +cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font, + const char *name) +{ + cairo_status_t status; + const char *p, *subrs, *charstrings, *array_start, *array_end, *dict_start, *dict_end; + const char *lenIV_start, *lenIV_end, *closefile_token; + char buffer[32], *lenIV_str, *subr_count_end, *glyph_count_end; + int ret, lenIV, length; + const cairo_scaled_font_backend_t *backend; + unsigned int i; + int glyph, j; + + /* The private dict holds hint information, common subroutines and + * the actual glyph definitions (charstrings). + * + * What we do here is scan directly to the /Subrs token, which + * marks the beginning of the subroutines. We read in all the + * subroutines, then move on to the /CharString token, which marks + * the beginning of the glyph definitions, and read in the charstrings. + * + * The charstrings are parsed to extract glyph widths, work out + * which subroutines are called, and to see if any extra glyphs + * need to be included due to the use of the seac glyph combining + * operator. + * + * Finally, the private dict is copied to the subset font minus the + * subroutines and charstrings not required. + */ + + /* Determine lenIV, the number of random characters at the start of + each encrypted charstring. The default is 4, but this can be + overridden in the private dict. */ + font->lenIV = 4; + if ((lenIV_start = find_token (font->cleartext, font->cleartext_end, "/lenIV")) != NULL) { + lenIV_start += 6; + lenIV_end = find_token (lenIV_start, font->cleartext_end, "def"); + if (lenIV_end == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + lenIV_str = malloc (lenIV_end - lenIV_start + 1); + if (unlikely (lenIV_str == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + strncpy (lenIV_str, lenIV_start, lenIV_end - lenIV_start); + lenIV_str[lenIV_end - lenIV_start] = 0; + + ret = sscanf(lenIV_str, "%d", &lenIV); + free(lenIV_str); + + if (unlikely (ret <= 0)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Apparently some fonts signal unencrypted charstrings with a negative lenIV, + though this is not part of the Type 1 Font Format specification. See, e.g. + http://lists.gnu.org/archive/html/freetype-devel/2000-06/msg00064.html. */ + if (unlikely (lenIV < 0)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + font->lenIV = lenIV; + } + + /* Find start of Subrs */ + subrs = find_token (font->cleartext, font->cleartext_end, "/Subrs"); + if (subrs == NULL) { + font->subset_subrs = FALSE; + p = font->cleartext; + array_start = NULL; + goto skip_subrs; + } + + /* Scan past /Subrs and get the array size. */ + p = subrs + strlen ("/Subrs"); + font->num_subrs = strtol (p, &subr_count_end, 10); + if (subr_count_end == p) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (font->num_subrs <= 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + font->subrs = calloc (font->num_subrs, sizeof (font->subrs[0])); + if (unlikely (font->subrs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + /* look for "dup" which marks the beginning of the first subr */ + array_start = find_token (subr_count_end, font->cleartext_end, "dup"); + if (subrs == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Read in the subroutines */ + status = cairo_type1_font_for_each_subr (font, + array_start, + font->cleartext_end, + cairo_type1_font_subset_build_subr_list, + &array_end); + if (unlikely(status)) + return status; + + p = array_end; +skip_subrs: + + /* Find start of CharStrings */ + charstrings = find_token (p, font->cleartext_end, "/CharStrings"); + if (charstrings == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Scan past /CharStrings and the integer following it. */ + p = charstrings + strlen ("/CharStrings"); + strtol (p, &glyph_count_end, 10); + if (p == glyph_count_end) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Look for a '/' which marks the beginning of the first glyph + * definition. */ + for (p = glyph_count_end; p < font->cleartext_end; p++) + if (*p == '/') + break; + if (p == font->cleartext_end) + return CAIRO_INT_STATUS_UNSUPPORTED; + dict_start = p; + + /* Now that we have the private dictionary broken down in + * sections, do the first pass through the glyph definitions to + * build a list of glyph names and charstrings. */ + status = cairo_type1_font_subset_for_each_glyph (font, + dict_start, + font->cleartext_end, + cairo_type1_font_subset_build_glyph_list, + &dict_end); + if (unlikely(status)) + return status; + + font->glyphs = _cairo_array_index (&font->glyphs_array, 0); + font->glyph_names = _cairo_array_index (&font->glyph_names_array, 0); + font->base.num_glyphs = _cairo_array_num_elements (&font->glyphs_array); + font->subset_index_to_glyphs = calloc (font->base.num_glyphs, sizeof font->subset_index_to_glyphs[0]); + if (unlikely (font->subset_index_to_glyphs == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + backend = font->scaled_font_subset->scaled_font->backend; + if (!backend->index_to_glyph_name) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Find the glyph number corresponding to each glyph in the subset + * and mark it as in use */ + + for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) { + unsigned long index; + + status = backend->index_to_glyph_name (font->scaled_font_subset->scaled_font, + font->glyph_names, + font->base.num_glyphs, + font->scaled_font_subset->glyphs[i], + &index); + if (unlikely(status)) + return status; + + cairo_type1_font_subset_use_glyph (font, index); + } + + /* Go through the charstring of each glyph in use, get the glyph + * width and figure out which extra glyphs may be required by the + * seac operator (which may cause font->num_glyphs to increase + * while this loop is executing). Also subset the Subrs. */ + for (j = 0; j < font->num_glyphs; j++) { + glyph = font->subset_index_to_glyphs[j]; + font->build_stack.sp = 0; + font->ps_stack.sp = 0; + status = cairo_type1_font_subset_parse_charstring (font, + glyph, + font->glyphs[glyph].encrypted_charstring, + font->glyphs[glyph].encrypted_charstring_length); + if (unlikely (status)) + return status; + } + + /* Always include the first five subroutines in case the Flex/hint mechanism is + * being used. */ + for (j = 0; j < MIN (font->num_subrs, 5); j++) { + font->subrs[j].used = TRUE; + } + + closefile_token = find_token (dict_end, font->cleartext_end, "closefile"); + if (closefile_token == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* We're ready to start outputting. First write the header, + * i.e. the public part of the font dict.*/ + status = cairo_type1_font_subset_write_header (font, name); + if (unlikely (status)) + return status; + + font->base.header_size = _cairo_output_stream_get_position (font->output); + + /* Start outputting the private dict */ + if (font->subset_subrs) { + /* First output everything up to the start of the Subrs array. */ + status = cairo_type1_font_subset_write_encrypted (font, font->cleartext, + array_start - font->cleartext); + if (unlikely (status)) + return status; + + /* Write out the subr definitions for each of the glyphs in + * the subset. */ + status = cairo_type1_font_for_each_subr (font, + array_start, + font->cleartext_end, + write_used_subrs, + &p); + if (unlikely (status)) + return status; + } else { + p = font->cleartext; + } + + /* If subr subsetting, output everything from end of subrs to + * start of /CharStrings token. If not subr subsetting, output + * everything start of private dict to start of /CharStrings + * token. */ + status = cairo_type1_font_subset_write_encrypted (font, p, charstrings - p); + if (unlikely (status)) + return status; + + /* Write out new charstring count */ + length = snprintf (buffer, sizeof buffer, + "/CharStrings %d", font->num_glyphs); + status = cairo_type1_font_subset_write_encrypted (font, buffer, length); + if (unlikely (status)) + return status; + + /* Write out text between the charstring count and the first + * charstring definition */ + status = cairo_type1_font_subset_write_encrypted (font, glyph_count_end, + dict_start - glyph_count_end); + if (unlikely (status)) + return status; + + /* Write out the charstring definitions for each of the glyphs in + * the subset. */ + status = cairo_type1_font_subset_for_each_glyph (font, + dict_start, + font->cleartext_end, + write_used_glyphs, + &p); + if (unlikely (status)) + return status; + + /* Output what's left between the end of the glyph definitions and + * the end of the private dict to the output. */ + status = cairo_type1_font_subset_write_encrypted (font, p, + closefile_token - p + strlen ("closefile") + 1); + if (unlikely (status)) + return status; + + if (font->hex_encode) + _cairo_output_stream_write (font->output, "\n", 1); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +cairo_type1_font_subset_write_trailer(cairo_type1_font_subset_t *font) +{ + const char *cleartomark_token; + int i; + static const char zeros[65] = + "0000000000000000000000000000000000000000000000000000000000000000\n"; + + + for (i = 0; i < 8; i++) + _cairo_output_stream_write (font->output, zeros, sizeof zeros); + + cleartomark_token = find_token (font->type1_data, font->type1_end, "cleartomark"); + if (cleartomark_token) { + /* Some fonts have conditional save/restore around the entire + * font dict, so we need to retain whatever postscript code + * that may come after 'cleartomark'. */ + + _cairo_output_stream_write (font->output, cleartomark_token, + font->type1_end - cleartomark_token); + if (*(font->type1_end - 1) != '\n') + _cairo_output_stream_printf (font->output, "\n"); + + } else if (!font->eexec_segment_is_ascii) { + /* Fonts embedded in PDF may omit the fixed-content portion + * that includes the 'cleartomark' operator. Type 1 in PDF is + * always binary. */ + + _cairo_output_stream_printf (font->output, "cleartomark\n"); + } else { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* some fonts do not have a newline at the end of the last line */ + _cairo_output_stream_printf (font->output, "\n"); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +type1_font_write (void *closure, const unsigned char *data, unsigned int length) +{ + cairo_type1_font_subset_t *font = closure; + + return _cairo_array_append_multiple (&font->contents, data, length); +} + +static cairo_status_t +cairo_type1_font_subset_write (cairo_type1_font_subset_t *font, + const char *name) +{ + cairo_status_t status; + + status = cairo_type1_font_subset_find_segments (font); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_decrypt_eexec_segment (font); + if (unlikely (status)) + return status; + + /* Determine which glyph definition delimiters to use. */ + if (find_token (font->cleartext, font->cleartext_end, "/-|") != NULL) { + font->rd = "-|"; + font->nd = "|-"; + font->np = "|"; + } else if (find_token (font->cleartext, font->cleartext_end, "/RD") != NULL) { + font->rd = "RD"; + font->nd = "ND"; + font->np = "NP"; + } else { + /* Don't know *what* kind of font this is... */ + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + font->eexec_key = CAIRO_TYPE1_PRIVATE_DICT_KEY; + font->hex_column = 0; + + status = cairo_type1_font_subset_get_bbox (font); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_get_fontname (font); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_write_private_dict (font, name); + if (unlikely (status)) + return status; + + font->base.data_size = _cairo_output_stream_get_position (font->output) - + font->base.header_size; + + status = cairo_type1_font_subset_write_trailer (font); + if (unlikely (status)) + return status; + + font->base.trailer_size = + _cairo_output_stream_get_position (font->output) - + font->base.header_size - font->base.data_size; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +check_fontdata_is_type1 (const unsigned char *data, long length) +{ + /* Test for Type 1 Binary (PFB) */ + if (length > 2 && data[0] == 0x80 && data[1] == 0x01) + return TRUE; + + /* Test for Type 1 1 ASCII (PFA) */ + if (length > 2 && data[0] == '%' && data[1] == '!') + return TRUE; + + return FALSE; +} + +static cairo_status_t +cairo_type1_font_subset_generate (void *abstract_font, + const char *name) + +{ + cairo_type1_font_subset_t *font = abstract_font; + cairo_scaled_font_t *scaled_font; + cairo_status_t status; + unsigned long data_length; + + scaled_font = font->scaled_font_subset->scaled_font; + if (!scaled_font->backend->load_type1_data) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = scaled_font->backend->load_type1_data (scaled_font, 0, NULL, &data_length); + if (status) + return CAIRO_INT_STATUS_UNSUPPORTED; + + font->type1_length = data_length; + font->type1_data = malloc (font->type1_length); + if (unlikely (font->type1_data == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = scaled_font->backend->load_type1_data (scaled_font, 0, + (unsigned char *) font->type1_data, + &data_length); + if (unlikely (status)) + return status; + + if (!check_fontdata_is_type1 ((unsigned char *)font->type1_data, data_length)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_array_grow_by (&font->contents, 4096); + if (unlikely (status)) + return status; + + font->output = _cairo_output_stream_create (type1_font_write, NULL, font); + if (unlikely ((status = font->output->status))) + return status; + + status = cairo_type1_font_subset_write (font, name); + if (unlikely (status)) + return status; + + font->base.data = _cairo_array_index (&font->contents, 0); + + return status; +} + +static cairo_status_t +_cairo_type1_font_subset_fini (cairo_type1_font_subset_t *font) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + unsigned int i; + + /* If the subset generation failed, some of the pointers below may + * be NULL depending on at which point the error occurred. */ + + _cairo_array_fini (&font->contents); + + free (font->type1_data); + for (i = 0; i < _cairo_array_num_elements (&font->glyph_names_array); i++) { + char **s; + + s = _cairo_array_index (&font->glyph_names_array, i); + free (*s); + } + _cairo_array_fini (&font->glyph_names_array); + _cairo_array_fini (&font->glyphs_array); + + free (font->subrs); + + if (font->output != NULL) + status = _cairo_output_stream_destroy (font->output); + + free (font->base.base_font); + + free (font->subset_index_to_glyphs); + + free (font->cleartext); + + return status; +} + +cairo_status_t +_cairo_type1_subset_init (cairo_type1_subset_t *type1_subset, + const char *name, + cairo_scaled_font_subset_t *scaled_font_subset, + cairo_bool_t hex_encode) +{ + cairo_type1_font_subset_t font; + cairo_status_t status; + unsigned long length; + unsigned int i; + char buf[30]; + + /* We need to use a fallback font generated from the synthesized outlines. */ + if (scaled_font_subset->scaled_font->backend->is_synthetic && + scaled_font_subset->scaled_font->backend->is_synthetic (scaled_font_subset->scaled_font)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_type1_font_subset_init (&font, scaled_font_subset, hex_encode); + if (unlikely (status)) + return status; + + status = cairo_type1_font_subset_generate (&font, name); + if (unlikely (status)) + goto fail1; + + if (font.base.base_font) { + type1_subset->base_font = strdup (font.base.base_font); + } else { + snprintf(buf, sizeof (buf), "CairoFont-%u-%u", + scaled_font_subset->font_id, scaled_font_subset->subset_id); + type1_subset->base_font = strdup (buf); + } + if (unlikely (type1_subset->base_font == NULL)) + goto fail1; + + type1_subset->widths = calloc (sizeof (double), font.num_glyphs); + if (unlikely (type1_subset->widths == NULL)) + goto fail2; + for (i = 0; i < font.base.num_glyphs; i++) { + if (font.glyphs[i].subset_index < 0) + continue; + type1_subset->widths[font.glyphs[i].subset_index] = + font.glyphs[i].width; + } + + type1_subset->x_min = font.base.x_min; + type1_subset->y_min = font.base.y_min; + type1_subset->x_max = font.base.x_max; + type1_subset->y_max = font.base.y_max; + type1_subset->ascent = font.base.ascent; + type1_subset->descent = font.base.descent; + + length = font.base.header_size + + font.base.data_size + + font.base.trailer_size; + type1_subset->data = malloc (length); + if (unlikely (type1_subset->data == NULL)) + goto fail3; + + memcpy (type1_subset->data, + _cairo_array_index (&font.contents, 0), length); + + type1_subset->header_length = font.base.header_size; + type1_subset->data_length = font.base.data_size; + type1_subset->trailer_length = font.base.trailer_size; + + return _cairo_type1_font_subset_fini (&font); + + fail3: + free (type1_subset->widths); + fail2: + free (type1_subset->base_font); + fail1: + _cairo_type1_font_subset_fini (&font); + + return status; +} + +void +_cairo_type1_subset_fini (cairo_type1_subset_t *subset) +{ + free (subset->base_font); + free (subset->widths); + free (subset->data); +} + +cairo_bool_t +_cairo_type1_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font) +{ + cairo_status_t status; + unsigned long length; + unsigned char buf[64]; + + if (!scaled_font->backend->load_type1_data) + return FALSE; + + status = scaled_font->backend->load_type1_data (scaled_font, 0, NULL, &length); + if (status) + return FALSE; + + /* We only need a few bytes to test for Type 1 */ + if (length > sizeof (buf)) + length = sizeof (buf); + + status = scaled_font->backend->load_type1_data (scaled_font, 0, buf, &length); + if (status) + return FALSE; + + return check_fontdata_is_type1 (buf, length); +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface-private.h new file mode 100644 index 00000000000..6f40f1c25b4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface-private.h @@ -0,0 +1,89 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + */ + +#ifndef CAIRO_TYPE3_GLYPH_SURFACE_PRIVATE_H +#define CAIRO_TYPE3_GLYPH_SURFACE_PRIVATE_H + +#include "cairoint.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-surface-private.h" +#include "cairo-surface-clipper-private.h" +#include "cairo-pdf-operators-private.h" + +typedef cairo_int_status_t +(*cairo_type3_glyph_surface_emit_image_t) (cairo_image_surface_t *image, + cairo_output_stream_t *stream); + +typedef struct cairo_type3_glyph_surface { + cairo_surface_t base; + + cairo_scaled_font_t *scaled_font; + cairo_output_stream_t *stream; + cairo_pdf_operators_t pdf_operators; + cairo_matrix_t cairo_to_pdf; + cairo_type3_glyph_surface_emit_image_t emit_image; + + cairo_surface_clipper_t clipper; +} cairo_type3_glyph_surface_t; + +cairo_private cairo_surface_t * +_cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, + cairo_output_stream_t *stream, + cairo_type3_glyph_surface_emit_image_t emit_image, + cairo_scaled_font_subsets_t *font_subsets, + cairo_bool_t ps_output); + +cairo_private void +_cairo_type3_glyph_surface_set_font_subsets_callback (void *abstract_surface, + cairo_pdf_operators_use_font_subset_t use_font_subset, + void *closure); + +cairo_private cairo_status_t +_cairo_type3_glyph_surface_analyze_glyph (void *abstract_surface, + unsigned long glyph_index); + +cairo_private cairo_status_t +_cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, + cairo_output_stream_t *stream, + unsigned long glyph_index, + cairo_box_t *bbox, + double *width); + +#endif /* CAIRO_HAS_FONT_SUBSET */ + +#endif /* CAIRO_TYPE3_GLYPH_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface.c new file mode 100644 index 00000000000..c99d461066c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-type3-glyph-surface.c @@ -0,0 +1,568 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Adrian Johnson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Adrian Johnson. + * + * Contributor(s): + * Adrian Johnson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_FONT_SUBSET + +#include "cairo-type3-glyph-surface-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-analysis-surface-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-clipper-private.h" + +static const cairo_surface_backend_t cairo_type3_glyph_surface_backend; + +static cairo_status_t +_cairo_type3_glyph_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_type3_glyph_surface_t *surface = cairo_container_of (clipper, + cairo_type3_glyph_surface_t, + clipper); + + if (path == NULL) { + _cairo_output_stream_printf (surface->stream, "Q q\n"); + return CAIRO_STATUS_SUCCESS; + } + + return _cairo_pdf_operators_clip (&surface->pdf_operators, + path, + fill_rule); +} + +cairo_surface_t * +_cairo_type3_glyph_surface_create (cairo_scaled_font_t *scaled_font, + cairo_output_stream_t *stream, + cairo_type3_glyph_surface_emit_image_t emit_image, + cairo_scaled_font_subsets_t *font_subsets, + cairo_bool_t ps) +{ + cairo_type3_glyph_surface_t *surface; + cairo_matrix_t invert_y_axis; + + if (unlikely (stream != NULL && stream->status)) + return _cairo_surface_create_in_error (stream->status); + + surface = malloc (sizeof (cairo_type3_glyph_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &cairo_type3_glyph_surface_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + surface->scaled_font = scaled_font; + surface->stream = stream; + surface->emit_image = emit_image; + + /* Setup the transform from the user-font device space to Type 3 + * font space. The Type 3 font space is defined by the FontMatrix + * entry in the Type 3 dictionary. In the PDF backend this is an + * identity matrix. */ + surface->cairo_to_pdf = scaled_font->scale_inverse; + cairo_matrix_init_scale (&invert_y_axis, 1, -1); + cairo_matrix_multiply (&surface->cairo_to_pdf, &surface->cairo_to_pdf, &invert_y_axis); + + _cairo_pdf_operators_init (&surface->pdf_operators, + surface->stream, + &surface->cairo_to_pdf, + font_subsets, + ps); + + _cairo_surface_clipper_init (&surface->clipper, + _cairo_type3_glyph_surface_clipper_intersect_clip_path); + + return &surface->base; +} + +static cairo_status_t +_cairo_type3_glyph_surface_emit_image (cairo_type3_glyph_surface_t *surface, + cairo_image_surface_t *image, + cairo_matrix_t *image_matrix) +{ + cairo_status_t status; + + /* The only image type supported by Type 3 fonts are 1-bit masks */ + image = _cairo_image_surface_coerce_to_format (image, CAIRO_FORMAT_A1); + status = image->base.status; + if (unlikely (status)) + return status; + + _cairo_output_stream_printf (surface->stream, + "q %f %f %f %f %f %f cm\n", + image_matrix->xx, + image_matrix->xy, + image_matrix->yx, + image_matrix->yy, + image_matrix->x0, + image_matrix->y0); + + status = surface->emit_image (image, surface->stream); + cairo_surface_destroy (&image->base); + + _cairo_output_stream_printf (surface->stream, + "Q\n"); + + return status; +} + +static cairo_status_t +_cairo_type3_glyph_surface_emit_image_pattern (cairo_type3_glyph_surface_t *surface, + cairo_image_surface_t *image, + const cairo_matrix_t *pattern_matrix) +{ + cairo_matrix_t mat, upside_down; + cairo_status_t status; + + if (image->width == 0 || image->height == 0) + return CAIRO_STATUS_SUCCESS; + + mat = *pattern_matrix; + + /* Get the pattern space to user space matrix */ + status = cairo_matrix_invert (&mat); + + /* cairo_pattern_set_matrix ensures the matrix is invertible */ + assert (status == CAIRO_STATUS_SUCCESS); + + /* Make this a pattern space to Type 3 font space matrix */ + cairo_matrix_multiply (&mat, &mat, &surface->cairo_to_pdf); + + /* PDF images are in a 1 unit by 1 unit image space. Turn the 1 by + * 1 image upside down to convert to flip the Y-axis going from + * cairo to PDF. Then scale the image up to the required size. */ + cairo_matrix_scale (&mat, image->width, image->height); + cairo_matrix_init (&upside_down, 1, 0, 0, -1, 0, 1); + cairo_matrix_multiply (&mat, &upside_down, &mat); + + return _cairo_type3_glyph_surface_emit_image (surface, image, &mat); +} + +static cairo_status_t +_cairo_type3_glyph_surface_finish (void *abstract_surface) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + + return _cairo_pdf_operators_fini (&surface->pdf_operators); +} + +static cairo_int_status_t +_cairo_type3_glyph_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + const cairo_surface_pattern_t *pattern; + cairo_image_surface_t *image; + void *image_extra; + cairo_status_t status; + + if (source->type != CAIRO_PATTERN_TYPE_SURFACE) + return CAIRO_INT_STATUS_IMAGE_FALLBACK; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + pattern = (const cairo_surface_pattern_t *) source; + status = _cairo_surface_acquire_source_image (pattern->surface, + &image, &image_extra); + if (unlikely (status)) + goto fail; + + status = _cairo_type3_glyph_surface_emit_image_pattern (surface, + image, + &pattern->base.matrix); + +fail: + _cairo_surface_release_source_image (pattern->surface, image, image_extra); + + return status; +} + +static cairo_int_status_t +_cairo_type3_glyph_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + return _cairo_type3_glyph_surface_paint (abstract_surface, + op, mask, + clip); +} + +static cairo_int_status_t +_cairo_type3_glyph_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + return _cairo_pdf_operators_stroke (&surface->pdf_operators, + path, + style, + ctm, + ctm_inverse); +} + +static cairo_int_status_t +_cairo_type3_glyph_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + return _cairo_pdf_operators_fill (&surface->pdf_operators, + path, + fill_rule); +} + +static cairo_int_status_t +_cairo_type3_glyph_surface_show_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + cairo_int_status_t status; + cairo_scaled_font_t *font; + cairo_matrix_t new_ctm, invert_y_axis; + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) + return status; + + cairo_matrix_init_scale (&invert_y_axis, 1, -1); + cairo_matrix_multiply (&new_ctm, &invert_y_axis, &scaled_font->ctm); + cairo_matrix_multiply (&new_ctm, &surface->cairo_to_pdf, &new_ctm); + font = cairo_scaled_font_create (scaled_font->font_face, + &scaled_font->font_matrix, + &new_ctm, + &scaled_font->options); + if (unlikely (font->status)) + return font->status; + + status = _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators, + NULL, 0, + glyphs, num_glyphs, + NULL, 0, + FALSE, + font); + + cairo_scaled_font_destroy (font); + + return status; +} + +static const cairo_surface_backend_t cairo_type3_glyph_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_TYPE3_GLYPH, + _cairo_type3_glyph_surface_finish, + + _cairo_default_context_create, /* XXX usable through a context? */ + + NULL, /* create similar */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + NULL, /* source */ + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* copy page */ + NULL, /* show page */ + + NULL, /* _cairo_type3_glyph_surface_get_extents */ + NULL, /* _cairo_type3_glyph_surface_get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_type3_glyph_surface_paint, + _cairo_type3_glyph_surface_mask, + _cairo_type3_glyph_surface_stroke, + _cairo_type3_glyph_surface_fill, + NULL, /* fill-stroke */ + _cairo_type3_glyph_surface_show_glyphs, +}; + +static void +_cairo_type3_glyph_surface_set_stream (cairo_type3_glyph_surface_t *surface, + cairo_output_stream_t *stream) +{ + surface->stream = stream; + _cairo_pdf_operators_set_stream (&surface->pdf_operators, stream); +} + +static cairo_status_t +_cairo_type3_glyph_surface_emit_fallback_image (cairo_type3_glyph_surface_t *surface, + unsigned long glyph_index) +{ + cairo_scaled_glyph_t *scaled_glyph; + cairo_status_t status; + cairo_image_surface_t *image; + cairo_matrix_t mat; + double x, y; + + status = _cairo_scaled_glyph_lookup (surface->scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS | + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + if (unlikely (status)) + return status; + + image = scaled_glyph->surface; + if (image->width == 0 || image->height == 0) + return CAIRO_STATUS_SUCCESS; + + x = _cairo_fixed_to_double (scaled_glyph->bbox.p1.x); + y = _cairo_fixed_to_double (scaled_glyph->bbox.p2.y); + mat.xx = image->width; + mat.xy = 0; + mat.yx = 0; + mat.yy = image->height; + mat.x0 = x; + mat.y0 = y; + cairo_matrix_multiply (&mat, &mat, &surface->scaled_font->scale_inverse); + mat.y0 *= -1; + + return _cairo_type3_glyph_surface_emit_image (surface, image, &mat); +} + +void +_cairo_type3_glyph_surface_set_font_subsets_callback (void *abstract_surface, + cairo_pdf_operators_use_font_subset_t use_font_subset, + void *closure) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + + if (unlikely (surface->base.status)) + return; + + _cairo_pdf_operators_set_font_subsets_callback (&surface->pdf_operators, + use_font_subset, + closure); +} + +cairo_status_t +_cairo_type3_glyph_surface_analyze_glyph (void *abstract_surface, + unsigned long glyph_index) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + cairo_scaled_glyph_t *scaled_glyph; + cairo_int_status_t status, status2; + cairo_output_stream_t *null_stream; + + if (unlikely (surface->base.status)) + return surface->base.status; + + null_stream = _cairo_null_stream_create (); + if (unlikely (null_stream->status)) + return null_stream->status; + + _cairo_type3_glyph_surface_set_stream (surface, null_stream); + + _cairo_scaled_font_freeze_cache (surface->scaled_font); + status = _cairo_scaled_glyph_lookup (surface->scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE, + &scaled_glyph); + + if (_cairo_int_status_is_error (status)) + goto cleanup; + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = CAIRO_INT_STATUS_SUCCESS; + goto cleanup; + } + + status = _cairo_recording_surface_replay (scaled_glyph->recording_surface, + &surface->base); + if (unlikely (status)) + goto cleanup; + + status = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) + status = CAIRO_INT_STATUS_SUCCESS; + +cleanup: + _cairo_scaled_font_thaw_cache (surface->scaled_font); + + status2 = _cairo_output_stream_destroy (null_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + + return status; +} + +cairo_status_t +_cairo_type3_glyph_surface_emit_glyph (void *abstract_surface, + cairo_output_stream_t *stream, + unsigned long glyph_index, + cairo_box_t *bbox, + double *width) +{ + cairo_type3_glyph_surface_t *surface = abstract_surface; + cairo_scaled_glyph_t *scaled_glyph; + cairo_int_status_t status, status2; + double x_advance, y_advance; + cairo_matrix_t font_matrix_inverse; + + if (unlikely (surface->base.status)) + return surface->base.status; + + _cairo_type3_glyph_surface_set_stream (surface, stream); + + _cairo_scaled_font_freeze_cache (surface->scaled_font); + status = _cairo_scaled_glyph_lookup (surface->scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS | + CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE, + &scaled_glyph); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = _cairo_scaled_glyph_lookup (surface->scaled_font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &scaled_glyph); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = CAIRO_INT_STATUS_IMAGE_FALLBACK; + } + if (_cairo_int_status_is_error (status)) { + _cairo_scaled_font_thaw_cache (surface->scaled_font); + return status; + } + + x_advance = scaled_glyph->metrics.x_advance; + y_advance = scaled_glyph->metrics.y_advance; + font_matrix_inverse = surface->scaled_font->font_matrix; + status2 = cairo_matrix_invert (&font_matrix_inverse); + + /* The invertability of font_matrix is tested in + * pdf_operators_show_glyphs before any glyphs are mapped to the + * subset. */ + assert (status2 == CAIRO_INT_STATUS_SUCCESS); + + cairo_matrix_transform_distance (&font_matrix_inverse, &x_advance, &y_advance); + *width = x_advance; + + *bbox = scaled_glyph->bbox; + _cairo_matrix_transform_bounding_box_fixed (&surface->scaled_font->scale_inverse, + bbox, NULL); + + _cairo_output_stream_printf (surface->stream, + "%f 0 %f %f %f %f d1\n", + x_advance, + _cairo_fixed_to_double (bbox->p1.x), + - _cairo_fixed_to_double (bbox->p2.y), + _cairo_fixed_to_double (bbox->p2.x), + - _cairo_fixed_to_double (bbox->p1.y)); + + if (status == CAIRO_INT_STATUS_SUCCESS) { + cairo_output_stream_t *mem_stream; + + mem_stream = _cairo_memory_stream_create (); + status = mem_stream->status; + if (unlikely (status)) + goto FAIL; + + _cairo_type3_glyph_surface_set_stream (surface, mem_stream); + + _cairo_output_stream_printf (surface->stream, "q\n"); + status = _cairo_recording_surface_replay (scaled_glyph->recording_surface, + &surface->base); + + status2 = _cairo_pdf_operators_flush (&surface->pdf_operators); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + + _cairo_output_stream_printf (surface->stream, "Q\n"); + + _cairo_type3_glyph_surface_set_stream (surface, stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + _cairo_memory_stream_copy (mem_stream, stream); + + status2 = _cairo_output_stream_destroy (mem_stream); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = status2; + } + + if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) + status = _cairo_type3_glyph_surface_emit_fallback_image (surface, glyph_index); + + FAIL: + _cairo_scaled_font_thaw_cache (surface->scaled_font); + + return status; +} + +#endif /* CAIRO_HAS_FONT_SUBSET */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-types-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-types-private.h new file mode 100644 index 00000000000..3d15d968e4b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-types-private.h @@ -0,0 +1,429 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_TYPES_PRIVATE_H +#define CAIRO_TYPES_PRIVATE_H + +#include "cairo.h" +#include "cairo-fixed-type-private.h" +#include "cairo-list-private.h" +#include "cairo-reference-count-private.h" + +CAIRO_BEGIN_DECLS + +/** + * SECTION:cairo-types + * @Title: Types + * @Short_Description: Generic data types + * + * This section lists generic data types used in the cairo API. + **/ + +typedef struct _cairo_array cairo_array_t; +typedef struct _cairo_backend cairo_backend_t; +typedef struct _cairo_boxes_t cairo_boxes_t; +typedef struct _cairo_cache cairo_cache_t; +typedef struct _cairo_composite_rectangles cairo_composite_rectangles_t; +typedef struct _cairo_clip cairo_clip_t; +typedef struct _cairo_clip_path cairo_clip_path_t; +typedef struct _cairo_color cairo_color_t; +typedef struct _cairo_color_stop cairo_color_stop_t; +typedef struct _cairo_contour cairo_contour_t; +typedef struct _cairo_contour_chain cairo_contour_chain_t; +typedef struct _cairo_contour_iter cairo_contour_iter_t; +typedef struct _cairo_damage cairo_damage_t; +typedef struct _cairo_device_backend cairo_device_backend_t; +typedef struct _cairo_font_face_backend cairo_font_face_backend_t; +typedef struct _cairo_gstate cairo_gstate_t; +typedef struct _cairo_gstate_backend cairo_gstate_backend_t; +typedef struct _cairo_glyph_text_info cairo_glyph_text_info_t; +typedef struct _cairo_hash_entry cairo_hash_entry_t; +typedef struct _cairo_hash_table cairo_hash_table_t; +typedef struct _cairo_image_surface cairo_image_surface_t; +typedef struct _cairo_mime_data cairo_mime_data_t; +typedef struct _cairo_observer cairo_observer_t; +typedef struct _cairo_output_stream cairo_output_stream_t; +typedef struct _cairo_paginated_surface_backend cairo_paginated_surface_backend_t; +typedef struct _cairo_path_fixed cairo_path_fixed_t; +typedef struct _cairo_rectangle_int16 cairo_glyph_size_t; +typedef struct _cairo_scaled_font_subsets cairo_scaled_font_subsets_t; +typedef struct _cairo_solid_pattern cairo_solid_pattern_t; +typedef struct _cairo_surface_attributes cairo_surface_attributes_t; +typedef struct _cairo_surface_backend cairo_surface_backend_t; +typedef struct _cairo_surface_observer cairo_surface_observer_t; +typedef struct _cairo_surface_snapshot cairo_surface_snapshot_t; +typedef struct _cairo_surface_subsurface cairo_surface_subsurface_t; +typedef struct _cairo_surface_wrapper cairo_surface_wrapper_t; +typedef struct _cairo_traps cairo_traps_t; +typedef struct _cairo_tristrip cairo_tristrip_t; +typedef struct _cairo_unscaled_font_backend cairo_unscaled_font_backend_t; +typedef struct _cairo_xlib_screen_info cairo_xlib_screen_info_t; + +typedef cairo_array_t cairo_user_data_array_t; + +typedef struct _cairo_scaled_font_private cairo_scaled_font_private_t; +typedef struct _cairo_scaled_font_backend cairo_scaled_font_backend_t; +typedef struct _cairo_scaled_glyph cairo_scaled_glyph_t; +typedef struct _cairo_scaled_glyph_private cairo_scaled_glyph_private_t; + +typedef struct cairo_compositor cairo_compositor_t; +typedef struct cairo_fallback_compositor cairo_fallback_compositor_t; +typedef struct cairo_mask_compositor cairo_mask_compositor_t; +typedef struct cairo_traps_compositor cairo_traps_compositor_t; +typedef struct cairo_spans_compositor cairo_spans_compositor_t; + +struct _cairo_observer { + cairo_list_t link; + void (*callback) (cairo_observer_t *self, void *arg); +}; + +/** + * _cairo_hash_entry: + * + * A #cairo_hash_entry_t contains both a key and a value for + * #cairo_hash_table_t. User-derived types for #cairo_hash_entry_t must + * be type-compatible with this structure (eg. they must have an + * unsigned long as the first parameter. The easiest way to get this + * is to use: + * + * typedef _my_entry { + * cairo_hash_entry_t base; + * ... Remainder of key and value fields here .. + * } my_entry_t; + * + * which then allows a pointer to my_entry_t to be passed to any of + * the #cairo_hash_table_t functions as follows without requiring a cast: + * + * _cairo_hash_table_insert (hash_table, &my_entry->base); + * + * IMPORTANT: The caller is responsible for initializing + * my_entry->base.hash with a hash code derived from the key. The + * essential property of the hash code is that keys_equal must never + * return %TRUE for two keys that have different hashes. The best hash + * code will reduce the frequency of two keys with the same code for + * which keys_equal returns %FALSE. + * + * Which parts of the entry make up the "key" and which part make up + * the value are entirely up to the caller, (as determined by the + * computation going into base.hash as well as the keys_equal + * function). A few of the #cairo_hash_table_t functions accept an entry + * which will be used exclusively as a "key", (indicated by a + * parameter name of key). In these cases, the value-related fields of + * the entry need not be initialized if so desired. + **/ +struct _cairo_hash_entry { + unsigned long hash; +}; + +struct _cairo_array { + unsigned int size; + unsigned int num_elements; + unsigned int element_size; + char *elements; +}; + +/** + * _cairo_lcd_filter: + * @CAIRO_LCD_FILTER_DEFAULT: Use the default LCD filter for + * font backend and target device + * @CAIRO_LCD_FILTER_NONE: Do not perform LCD filtering + * @CAIRO_LCD_FILTER_INTRA_PIXEL: Intra-pixel filter + * @CAIRO_LCD_FILTER_FIR3: FIR filter with a 3x3 kernel + * @CAIRO_LCD_FILTER_FIR5: FIR filter with a 5x5 kernel + * + * The LCD filter specifies the low-pass filter applied to LCD-optimized + * bitmaps generated with an antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL. + * + * Note: This API was temporarily made available in the public + * interface during the 1.7.x development series, but was made private + * before 1.8. + **/ +typedef enum _cairo_lcd_filter { + CAIRO_LCD_FILTER_DEFAULT, + CAIRO_LCD_FILTER_NONE, + CAIRO_LCD_FILTER_INTRA_PIXEL, + CAIRO_LCD_FILTER_FIR3, + CAIRO_LCD_FILTER_FIR5 +} cairo_lcd_filter_t; + +typedef enum _cairo_round_glyph_positions { + CAIRO_ROUND_GLYPH_POS_DEFAULT, + CAIRO_ROUND_GLYPH_POS_ON, + CAIRO_ROUND_GLYPH_POS_OFF +} cairo_round_glyph_positions_t; + +struct _cairo_font_options { + cairo_antialias_t antialias; + cairo_subpixel_order_t subpixel_order; + cairo_lcd_filter_t lcd_filter; + cairo_hint_style_t hint_style; + cairo_hint_metrics_t hint_metrics; + cairo_round_glyph_positions_t round_glyph_positions; +}; + +struct _cairo_glyph_text_info { + const char *utf8; + int utf8_len; + + const cairo_text_cluster_t *clusters; + int num_clusters; + cairo_text_cluster_flags_t cluster_flags; +}; + + +/* XXX: Right now, the _cairo_color structure puts unpremultiplied + color in the doubles and premultiplied color in the shorts. Yes, + this is crazy insane, (but at least we don't export this + madness). I'm still working on a cleaner API, but in the meantime, + at least this does prevent precision loss in color when changing + alpha. */ +struct _cairo_color { + double red; + double green; + double blue; + double alpha; + + unsigned short red_short; + unsigned short green_short; + unsigned short blue_short; + unsigned short alpha_short; +}; + +struct _cairo_color_stop { + /* unpremultiplied */ + double red; + double green; + double blue; + double alpha; + + /* unpremultipled, for convenience */ + uint16_t red_short; + uint16_t green_short; + uint16_t blue_short; + uint16_t alpha_short; +}; + +typedef enum _cairo_paginated_mode { + CAIRO_PAGINATED_MODE_ANALYZE, /* analyze page regions */ + CAIRO_PAGINATED_MODE_RENDER, /* render page contents */ + CAIRO_PAGINATED_MODE_FALLBACK /* paint fallback images */ +} cairo_paginated_mode_t; + +typedef enum _cairo_internal_surface_type { + CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT = 0x1000, + CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, + CAIRO_INTERNAL_SURFACE_TYPE_ANALYSIS, + CAIRO_INTERNAL_SURFACE_TYPE_OBSERVER, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_WRAPPING, + CAIRO_INTERNAL_SURFACE_TYPE_NULL, + CAIRO_INTERNAL_SURFACE_TYPE_TYPE3_GLYPH +} cairo_internal_surface_type_t; + +typedef enum _cairo_internal_device_type { + CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER = 0x1000, +} cairo_device_surface_type_t; + +#define CAIRO_HAS_TEST_PAGINATED_SURFACE 1 + +typedef struct _cairo_slope { + cairo_fixed_t dx; + cairo_fixed_t dy; +} cairo_slope_t, cairo_distance_t; + +typedef struct _cairo_point_double { + double x; + double y; +} cairo_point_double_t; + +typedef struct _cairo_circle_double { + cairo_point_double_t center; + double radius; +} cairo_circle_double_t; + +typedef struct _cairo_distance_double { + double dx; + double dy; +} cairo_distance_double_t; + +typedef struct _cairo_box_double { + cairo_point_double_t p1; + cairo_point_double_t p2; +} cairo_box_double_t; + +typedef struct _cairo_line { + cairo_point_t p1; + cairo_point_t p2; +} cairo_line_t, cairo_box_t; + +typedef struct _cairo_trapezoid { + cairo_fixed_t top, bottom; + cairo_line_t left, right; +} cairo_trapezoid_t; + +typedef struct _cairo_point_int { + int x, y; +} cairo_point_int_t; + +#define CAIRO_RECT_INT_MIN (INT_MIN >> CAIRO_FIXED_FRAC_BITS) +#define CAIRO_RECT_INT_MAX (INT_MAX >> CAIRO_FIXED_FRAC_BITS) + +typedef enum _cairo_direction { + CAIRO_DIRECTION_FORWARD, + CAIRO_DIRECTION_REVERSE +} cairo_direction_t; + +typedef struct _cairo_edge { + cairo_line_t line; + int top, bottom; + int dir; +} cairo_edge_t; + +typedef struct _cairo_polygon { + cairo_status_t status; + + cairo_box_t extents; + cairo_box_t limit; + const cairo_box_t *limits; + int num_limits; + + int num_edges; + int edges_size; + cairo_edge_t *edges; + cairo_edge_t edges_embedded[32]; +} cairo_polygon_t; + +typedef cairo_warn cairo_status_t +(*cairo_spline_add_point_func_t) (void *closure, + const cairo_point_t *point, + const cairo_slope_t *tangent); + +typedef struct _cairo_spline_knots { + cairo_point_t a, b, c, d; +} cairo_spline_knots_t; + +typedef struct _cairo_spline { + cairo_spline_add_point_func_t add_point_func; + void *closure; + + cairo_spline_knots_t knots; + + cairo_slope_t initial_slope; + cairo_slope_t final_slope; + + cairo_bool_t has_point; + cairo_point_t last_point; +} cairo_spline_t; + +typedef struct _cairo_pen_vertex { + cairo_point_t point; + + cairo_slope_t slope_ccw; + cairo_slope_t slope_cw; +} cairo_pen_vertex_t; + +typedef struct _cairo_pen { + double radius; + double tolerance; + + int num_vertices; + cairo_pen_vertex_t *vertices; + cairo_pen_vertex_t vertices_embedded[32]; +} cairo_pen_t; + +typedef struct _cairo_stroke_style { + double line_width; + cairo_line_cap_t line_cap; + cairo_line_join_t line_join; + double miter_limit; + double *dash; + unsigned int num_dashes; + double dash_offset; +} cairo_stroke_style_t; + +typedef struct _cairo_format_masks { + int bpp; + unsigned long alpha_mask; + unsigned long red_mask; + unsigned long green_mask; + unsigned long blue_mask; +} cairo_format_masks_t; + +typedef enum { + CAIRO_STOCK_WHITE, + CAIRO_STOCK_BLACK, + CAIRO_STOCK_TRANSPARENT, + CAIRO_STOCK_NUM_COLORS, +} cairo_stock_t; + +typedef enum _cairo_image_transparency { + CAIRO_IMAGE_IS_OPAQUE, + CAIRO_IMAGE_HAS_BILEVEL_ALPHA, + CAIRO_IMAGE_HAS_ALPHA, + CAIRO_IMAGE_UNKNOWN +} cairo_image_transparency_t; + +typedef enum _cairo_image_color { + CAIRO_IMAGE_IS_COLOR, + CAIRO_IMAGE_IS_GRAYSCALE, + CAIRO_IMAGE_IS_MONOCHROME, + CAIRO_IMAGE_UNKNOWN_COLOR +} cairo_image_color_t; + + +struct _cairo_mime_data { + cairo_reference_count_t ref_count; + unsigned char *data; + unsigned long length; + cairo_destroy_func_t destroy; + void *closure; +}; + +/* + * A #cairo_unscaled_font_t is just an opaque handle we use in the + * glyph cache. + */ +typedef struct _cairo_unscaled_font { + cairo_hash_entry_t hash_entry; + cairo_reference_count_t ref_count; + const cairo_unscaled_font_backend_t *backend; +} cairo_unscaled_font_t; +CAIRO_END_DECLS + +#endif /* CAIRO_TYPES_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-unicode.c b/Build/source/libs/cairo/cairo-src/src/cairo-unicode.c new file mode 100644 index 00000000000..88de39516b6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-unicode.c @@ -0,0 +1,422 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * The code in this file is derived from GLib's gutf8.c and + * ultimately from libunicode. It is relicensed under the + * dual LGPL/MPL with permission of the original authors. + * + * Copyright © 1999 Tom Tromey + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Tom Tromey. + * and Red Hat, Inc. + * + * Contributor(s): + * Owen Taylor + */ + +#include "cairoint.h" +#include "cairo-error-private.h" + +#define UTF8_COMPUTE(Char, Mask, Len) \ + if (Char < 128) \ + { \ + Len = 1; \ + Mask = 0x7f; \ + } \ + else if ((Char & 0xe0) == 0xc0) \ + { \ + Len = 2; \ + Mask = 0x1f; \ + } \ + else if ((Char & 0xf0) == 0xe0) \ + { \ + Len = 3; \ + Mask = 0x0f; \ + } \ + else if ((Char & 0xf8) == 0xf0) \ + { \ + Len = 4; \ + Mask = 0x07; \ + } \ + else if ((Char & 0xfc) == 0xf8) \ + { \ + Len = 5; \ + Mask = 0x03; \ + } \ + else if ((Char & 0xfe) == 0xfc) \ + { \ + Len = 6; \ + Mask = 0x01; \ + } \ + else \ + Len = -1; + +#define UTF8_LENGTH(Char) \ + ((Char) < 0x80 ? 1 : \ + ((Char) < 0x800 ? 2 : \ + ((Char) < 0x10000 ? 3 : \ + ((Char) < 0x200000 ? 4 : \ + ((Char) < 0x4000000 ? 5 : 6))))) + +#define UTF8_GET(Result, Chars, Count, Mask, Len) \ + (Result) = (Chars)[0] & (Mask); \ + for ((Count) = 1; (Count) < (Len); ++(Count)) \ + { \ + if (((Chars)[(Count)] & 0xc0) != 0x80) \ + { \ + (Result) = -1; \ + break; \ + } \ + (Result) <<= 6; \ + (Result) |= ((Chars)[(Count)] & 0x3f); \ + } + +#define UNICODE_VALID(Char) \ + ((Char) < 0x110000 && \ + (((Char) & 0xFFFFF800) != 0xD800) && \ + ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \ + ((Char) & 0xFFFE) != 0xFFFE) + +static const char utf8_skip_data[256] = { + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1 +}; + +#define UTF8_NEXT_CHAR(p) ((p) + utf8_skip_data[*(unsigned char *)(p)]) + +/* Converts a sequence of bytes encoded as UTF-8 to a Unicode character. + * If @p does not point to a valid UTF-8 encoded character, results are + * undefined. + **/ +static uint32_t +_utf8_get_char (const unsigned char *p) +{ + int i, mask = 0, len; + uint32_t result; + unsigned char c = (unsigned char) *p; + + UTF8_COMPUTE (c, mask, len); + if (len == -1) + return (uint32_t)-1; + UTF8_GET (result, p, i, mask, len); + + return result; +} + +/* Like _utf8_get_char, but take a maximum length + * and return (uint32_t)-2 on incomplete trailing character + */ +static uint32_t +_utf8_get_char_extended (const unsigned char *p, + long max_len) +{ + int i, len; + uint32_t wc = (unsigned char) *p; + + if (wc < 0x80) { + return wc; + } else if (wc < 0xc0) { + return (uint32_t)-1; + } else if (wc < 0xe0) { + len = 2; + wc &= 0x1f; + } else if (wc < 0xf0) { + len = 3; + wc &= 0x0f; + } else if (wc < 0xf8) { + len = 4; + wc &= 0x07; + } else if (wc < 0xfc) { + len = 5; + wc &= 0x03; + } else if (wc < 0xfe) { + len = 6; + wc &= 0x01; + } else { + return (uint32_t)-1; + } + + if (max_len >= 0 && len > max_len) { + for (i = 1; i < max_len; i++) { + if ((((unsigned char *)p)[i] & 0xc0) != 0x80) + return (uint32_t)-1; + } + return (uint32_t)-2; + } + + for (i = 1; i < len; ++i) { + uint32_t ch = ((unsigned char *)p)[i]; + + if ((ch & 0xc0) != 0x80) { + if (ch) + return (uint32_t)-1; + else + return (uint32_t)-2; + } + + wc <<= 6; + wc |= (ch & 0x3f); + } + + if (UTF8_LENGTH(wc) != len) + return (uint32_t)-1; + + return wc; +} + +/** + * _cairo_utf8_get_char_validated: + * @p: a UTF-8 string + * @unicode: location to store one Unicode character + * + * Decodes the first character of a valid UTF-8 string, and returns + * the number of bytes consumed. + * + * Note that the string should be valid. Do not use this without + * validating the string first. + * + * Returns: the number of bytes forming the character returned. + **/ +int +_cairo_utf8_get_char_validated (const char *p, + uint32_t *unicode) +{ + int i, mask = 0, len; + uint32_t result; + unsigned char c = (unsigned char) *p; + + UTF8_COMPUTE (c, mask, len); + if (len == -1) { + if (unicode) + *unicode = (uint32_t)-1; + return 1; + } + UTF8_GET (result, p, i, mask, len); + + if (unicode) + *unicode = result; + return len; +} + +/** + * _cairo_utf8_to_ucs4: + * @str: an UTF-8 string + * @len: length of @str in bytes, or -1 if it is nul-terminated. + * If @len is supplied and the string has an embedded nul + * byte, only the portion before the nul byte is converted. + * @result: location to store a pointer to a newly allocated UTF-32 + * string (always native endian), or %NULL. Free with free(). A 0 + * word will be written after the last character. + * @items_written: location to store number of 32-bit words + * written. (Not including the trailing 0) + * + * Converts a UTF-8 string to UCS-4. UCS-4 is an encoding of Unicode + * with 1 32-bit word per character. The string is validated to + * consist entirely of valid Unicode characters. + * + * Return value: %CAIRO_STATUS_SUCCESS if the entire string was + * successfully converted. %CAIRO_STATUS_INVALID_STRING if an + * invalid sequence was found. + **/ +cairo_status_t +_cairo_utf8_to_ucs4 (const char *str, + int len, + uint32_t **result, + int *items_written) +{ + uint32_t *str32 = NULL; + int n_chars, i; + const unsigned char *in; + const unsigned char * const ustr = (const unsigned char *) str; + + in = ustr; + n_chars = 0; + while ((len < 0 || ustr + len - in > 0) && *in) + { + uint32_t wc = _utf8_get_char_extended (in, ustr + len - in); + if (wc & 0x80000000 || !UNICODE_VALID (wc)) + return _cairo_error (CAIRO_STATUS_INVALID_STRING); + + n_chars++; + if (n_chars == INT_MAX) + return _cairo_error (CAIRO_STATUS_INVALID_STRING); + + in = UTF8_NEXT_CHAR (in); + } + + if (result) { + str32 = _cairo_malloc_ab (n_chars + 1, sizeof (uint32_t)); + if (!str32) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + in = ustr; + for (i=0; i < n_chars; i++) { + str32[i] = _utf8_get_char (in); + in = UTF8_NEXT_CHAR (in); + } + str32[i] = 0; + + *result = str32; + } + + if (items_written) + *items_written = n_chars; + + return CAIRO_STATUS_SUCCESS; +} + +/** + * _cairo_ucs4_to_utf8: + * @unicode: a UCS-4 character + * @utf8: buffer to write utf8 string into. Must have at least 4 bytes + * space available. Or %NULL. + * + * This space left intentionally blank. + * + * Return value: Number of bytes in the utf8 string or 0 if an invalid + * unicode character + **/ +int +_cairo_ucs4_to_utf8 (uint32_t unicode, + char *utf8) +{ + int bytes; + char *p; + + if (unicode < 0x80) { + if (utf8) + *utf8 = unicode; + return 1; + } else if (unicode < 0x800) { + bytes = 2; + } else if (unicode < 0x10000) { + bytes = 3; + } else if (unicode < 0x200000) { + bytes = 4; + } else { + return 0; + } + + if (!utf8) + return bytes; + + p = utf8 + bytes; + while (p > utf8) { + *--p = 0x80 | (unicode & 0x3f); + unicode >>= 6; + } + *p |= 0xf0 << (4 - bytes); + + return bytes; +} + +#if CAIRO_HAS_UTF8_TO_UTF16 +/** + * _cairo_utf8_to_utf16: + * @str: an UTF-8 string + * @len: length of @str in bytes, or -1 if it is nul-terminated. + * If @len is supplied and the string has an embedded nul + * byte, only the portion before the nul byte is converted. + * @result: location to store a pointer to a newly allocated UTF-16 + * string (always native endian). Free with free(). A 0 + * word will be written after the last character. + * @items_written: location to store number of 16-bit words + * written. (Not including the trailing 0) + * + * Converts a UTF-8 string to UTF-16. UTF-16 is an encoding of Unicode + * where characters are represented either as a single 16-bit word, or + * as a pair of 16-bit "surrogates". The string is validated to + * consist entirely of valid Unicode characters. + * + * Return value: %CAIRO_STATUS_SUCCESS if the entire string was + * successfully converted. %CAIRO_STATUS_INVALID_STRING if an + * an invalid sequence was found. + **/ +cairo_status_t +_cairo_utf8_to_utf16 (const char *str, + int len, + uint16_t **result, + int *items_written) +{ + uint16_t *str16 = NULL; + int n16, i; + const unsigned char *in; + const unsigned char * const ustr = (const unsigned char *) str; + + in = ustr; + n16 = 0; + while ((len < 0 || ustr + len - in > 0) && *in) { + uint32_t wc = _utf8_get_char_extended (in, ustr + len - in); + if (wc & 0x80000000 || !UNICODE_VALID (wc)) + return _cairo_error (CAIRO_STATUS_INVALID_STRING); + + if (wc < 0x10000) + n16 += 1; + else + n16 += 2; + + if (n16 == INT_MAX - 1 || n16 == INT_MAX) + return _cairo_error (CAIRO_STATUS_INVALID_STRING); + + in = UTF8_NEXT_CHAR (in); + } + + str16 = _cairo_malloc_ab (n16 + 1, sizeof (uint16_t)); + if (!str16) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + in = ustr; + for (i = 0; i < n16;) { + uint32_t wc = _utf8_get_char (in); + + if (wc < 0x10000) { + str16[i++] = wc; + } else { + str16[i++] = (wc - 0x10000) / 0x400 + 0xd800; + str16[i++] = (wc - 0x10000) % 0x400 + 0xdc00; + } + + in = UTF8_NEXT_CHAR (in); + } + + str16[i] = 0; + + *result = str16; + if (items_written) + *items_written = n16; + + return CAIRO_STATUS_SUCCESS; +} +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-uninstalled.pc.in b/Build/source/libs/cairo/cairo-src/src/cairo-uninstalled.pc.in new file mode 100644 index 00000000000..9dc3231ae45 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-uninstalled.pc.in @@ -0,0 +1,8 @@ +Name: cairo +Description: Multi-platform 2D graphics library +Version: @VERSION@ + +@PKGCONFIG_REQUIRES@: @CAIRO_REQUIRES@ +Libs: ${pc_top_builddir}/${pcfiledir}/src/libcairo.la +Libs.private: @CAIRO_NONPKGCONFIG_LIBS@ +Cflags: -I${pc_top_builddir}/${pcfiledir}/@srcdir@/src diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-user-font-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-user-font-private.h new file mode 100644 index 00000000000..d54ef78b44e --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-user-font-private.h @@ -0,0 +1,46 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006, 2008 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Behdad Esfahbod + */ + +#ifndef CAIRO_USER_FONT_PRIVATE_H +#define CAIRO_USER_FONT_PRIVATE_H + +#include "cairo.h" +#include "cairo-compiler-private.h" + +cairo_private cairo_bool_t +_cairo_font_face_is_user (cairo_font_face_t *font_face); + +#endif /* CAIRO_USER_FONT_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-user-font.c b/Build/source/libs/cairo/cairo-src/src/cairo-user-font.c new file mode 100644 index 00000000000..6d2de2097d5 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-user-font.c @@ -0,0 +1,831 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006, 2008 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Kristian Høgsberg + * Behdad Esfahbod + */ + +#include "cairoint.h" +#include "cairo-user-font-private.h" +#include "cairo-recording-surface-private.h" +#include "cairo-analysis-surface-private.h" +#include "cairo-error-private.h" + +/** + * SECTION:cairo-user-fonts + * @Title:User Fonts + * @Short_Description: Font support with font data provided by the user + * + * The user-font feature allows the cairo user to provide drawings for glyphs + * in a font. This is most useful in implementing fonts in non-standard + * formats, like SVG fonts and Flash fonts, but can also be used by games and + * other application to draw "funky" fonts. + **/ + +/** + * CAIRO_HAS_USER_FONT: + * + * Defined if the user font backend is available. + * This macro can be used to conditionally compile backend-specific code. + * The user font backend is always built in versions of cairo that support + * this feature (1.8 and later). + * + * Since: 1.8 + **/ + +typedef struct _cairo_user_scaled_font_methods { + cairo_user_scaled_font_init_func_t init; + cairo_user_scaled_font_render_glyph_func_t render_glyph; + cairo_user_scaled_font_unicode_to_glyph_func_t unicode_to_glyph; + cairo_user_scaled_font_text_to_glyphs_func_t text_to_glyphs; +} cairo_user_scaled_font_methods_t; + +typedef struct _cairo_user_font_face { + cairo_font_face_t base; + + /* Set to true after first scaled font is created. At that point, + * the scaled_font_methods cannot change anymore. */ + cairo_bool_t immutable; + + cairo_user_scaled_font_methods_t scaled_font_methods; +} cairo_user_font_face_t; + +typedef struct _cairo_user_scaled_font { + cairo_scaled_font_t base; + + cairo_text_extents_t default_glyph_extents; + + /* space to compute extents in, and factors to convert back to user space */ + cairo_matrix_t extent_scale; + double extent_x_scale; + double extent_y_scale; + + /* multiplier for metrics hinting */ + double snap_x_scale; + double snap_y_scale; + +} cairo_user_scaled_font_t; + +/* #cairo_user_scaled_font_t */ + +static cairo_surface_t * +_cairo_user_scaled_font_create_recording_surface (const cairo_user_scaled_font_t *scaled_font) +{ + cairo_content_t content; + + content = scaled_font->base.options.antialias == CAIRO_ANTIALIAS_SUBPIXEL ? + CAIRO_CONTENT_COLOR_ALPHA : + CAIRO_CONTENT_ALPHA; + + return cairo_recording_surface_create (content, NULL); +} + + +static cairo_t * +_cairo_user_scaled_font_create_recording_context (const cairo_user_scaled_font_t *scaled_font, + cairo_surface_t *recording_surface) +{ + cairo_t *cr; + + cr = cairo_create (recording_surface); + + if (!_cairo_matrix_is_scale_0 (&scaled_font->base.scale)) { + cairo_matrix_t scale; + scale = scaled_font->base.scale; + scale.x0 = scale.y0 = 0.; + cairo_set_matrix (cr, &scale); + } + + cairo_set_font_size (cr, 1.0); + cairo_set_font_options (cr, &scaled_font->base.options); + cairo_set_source_rgb (cr, 1., 1., 1.); + + return cr; +} + +static cairo_int_status_t +_cairo_user_scaled_glyph_init (void *abstract_font, + cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_glyph_info_t info) +{ + cairo_int_status_t status = CAIRO_STATUS_SUCCESS; + cairo_user_scaled_font_t *scaled_font = abstract_font; + cairo_surface_t *recording_surface = scaled_glyph->recording_surface; + + if (!scaled_glyph->recording_surface) { + cairo_user_font_face_t *face = + (cairo_user_font_face_t *) scaled_font->base.font_face; + cairo_text_extents_t extents = scaled_font->default_glyph_extents; + cairo_t *cr; + + if (!face->scaled_font_methods.render_glyph) + return CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED; + + recording_surface = _cairo_user_scaled_font_create_recording_surface (scaled_font); + + /* special case for 0 rank matrix (as in _cairo_scaled_font_init): empty surface */ + if (!_cairo_matrix_is_scale_0 (&scaled_font->base.scale)) { + cr = _cairo_user_scaled_font_create_recording_context (scaled_font, recording_surface); + status = face->scaled_font_methods.render_glyph ((cairo_scaled_font_t *)scaled_font, + _cairo_scaled_glyph_index(scaled_glyph), + cr, &extents); + if (status == CAIRO_INT_STATUS_SUCCESS) + status = cairo_status (cr); + + cairo_destroy (cr); + + if (unlikely (status)) { + cairo_surface_destroy (recording_surface); + return status; + } + } + + _cairo_scaled_glyph_set_recording_surface (scaled_glyph, + &scaled_font->base, + recording_surface); + + + /* set metrics */ + + if (extents.width == 0.) { + cairo_box_t bbox; + double x1, y1, x2, y2; + double x_scale, y_scale; + + /* Compute extents.x/y/width/height from recording_surface, + * in font space. + */ + status = _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface, + &bbox, + &scaled_font->extent_scale); + if (unlikely (status)) + return status; + + _cairo_box_to_doubles (&bbox, &x1, &y1, &x2, &y2); + + x_scale = scaled_font->extent_x_scale; + y_scale = scaled_font->extent_y_scale; + extents.x_bearing = x1 * x_scale; + extents.y_bearing = y1 * y_scale; + extents.width = (x2 - x1) * x_scale; + extents.height = (y2 - y1) * y_scale; + } + + if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF) { + extents.x_advance = _cairo_lround (extents.x_advance / scaled_font->snap_x_scale) * scaled_font->snap_x_scale; + extents.y_advance = _cairo_lround (extents.y_advance / scaled_font->snap_y_scale) * scaled_font->snap_y_scale; + } + + _cairo_scaled_glyph_set_metrics (scaled_glyph, + &scaled_font->base, + &extents); + } + + if (info & CAIRO_SCALED_GLYPH_INFO_SURFACE) { + cairo_surface_t *surface; + cairo_format_t format; + int width, height; + + /* TODO + * extend the glyph cache to support argb glyphs. + * need to figure out the semantics and interaction with subpixel + * rendering first. + */ + + width = _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.x) - + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x); + height = _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.y) - + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y); + + switch (scaled_font->base.options.antialias) { + default: + case CAIRO_ANTIALIAS_DEFAULT: + case CAIRO_ANTIALIAS_FAST: + case CAIRO_ANTIALIAS_GOOD: + case CAIRO_ANTIALIAS_GRAY: format = CAIRO_FORMAT_A8; break; + case CAIRO_ANTIALIAS_NONE: format = CAIRO_FORMAT_A1; break; + case CAIRO_ANTIALIAS_BEST: + case CAIRO_ANTIALIAS_SUBPIXEL: format = CAIRO_FORMAT_ARGB32; break; + } + surface = cairo_image_surface_create (format, width, height); + + cairo_surface_set_device_offset (surface, + - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x), + - _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y)); + status = _cairo_recording_surface_replay (recording_surface, surface); + + if (unlikely (status)) { + cairo_surface_destroy(surface); + return status; + } + + _cairo_scaled_glyph_set_surface (scaled_glyph, + &scaled_font->base, + (cairo_image_surface_t *) surface); + } + + if (info & CAIRO_SCALED_GLYPH_INFO_PATH) { + cairo_path_fixed_t *path = _cairo_path_fixed_create (); + if (!path) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_recording_surface_get_path (recording_surface, path); + if (unlikely (status)) { + _cairo_path_fixed_destroy (path); + return status; + } + + _cairo_scaled_glyph_set_path (scaled_glyph, + &scaled_font->base, + path); + } + + return status; +} + +static unsigned long +_cairo_user_ucs4_to_index (void *abstract_font, + uint32_t ucs4) +{ + cairo_user_scaled_font_t *scaled_font = abstract_font; + cairo_user_font_face_t *face = + (cairo_user_font_face_t *) scaled_font->base.font_face; + unsigned long glyph = 0; + + if (face->scaled_font_methods.unicode_to_glyph) { + cairo_status_t status; + + status = face->scaled_font_methods.unicode_to_glyph (&scaled_font->base, + ucs4, &glyph); + + if (status == CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED) + goto not_implemented; + + if (status != CAIRO_STATUS_SUCCESS) { + status = _cairo_scaled_font_set_error (&scaled_font->base, status); + glyph = 0; + } + + } else { +not_implemented: + glyph = ucs4; + } + + return glyph; +} + +static cairo_int_status_t +_cairo_user_text_to_glyphs (void *abstract_font, + double x, + double y, + const char *utf8, + int utf8_len, + cairo_glyph_t **glyphs, + int *num_glyphs, + cairo_text_cluster_t **clusters, + int *num_clusters, + cairo_text_cluster_flags_t *cluster_flags) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_UNSUPPORTED; + + cairo_user_scaled_font_t *scaled_font = abstract_font; + cairo_user_font_face_t *face = + (cairo_user_font_face_t *) scaled_font->base.font_face; + + if (face->scaled_font_methods.text_to_glyphs) { + int i; + cairo_glyph_t *orig_glyphs = *glyphs; + int orig_num_glyphs = *num_glyphs; + + status = face->scaled_font_methods.text_to_glyphs (&scaled_font->base, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, cluster_flags); + + if (status != CAIRO_INT_STATUS_SUCCESS && + status != CAIRO_INT_STATUS_USER_FONT_NOT_IMPLEMENTED) + return status; + + if (status == CAIRO_INT_STATUS_USER_FONT_NOT_IMPLEMENTED || + *num_glyphs < 0) { + if (orig_glyphs != *glyphs) { + cairo_glyph_free (*glyphs); + *glyphs = orig_glyphs; + } + *num_glyphs = orig_num_glyphs; + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* Convert from font space to user space and add x,y */ + for (i = 0; i < *num_glyphs; i++) { + double gx = (*glyphs)[i].x; + double gy = (*glyphs)[i].y; + + cairo_matrix_transform_point (&scaled_font->base.font_matrix, + &gx, &gy); + + (*glyphs)[i].x = gx + x; + (*glyphs)[i].y = gy + y; + } + } + + return status; +} + +static cairo_status_t +_cairo_user_font_face_scaled_font_create (void *abstract_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + cairo_scaled_font_t **scaled_font); + +static cairo_status_t +_cairo_user_font_face_create_for_toy (cairo_toy_font_face_t *toy_face, + cairo_font_face_t **font_face) +{ + return _cairo_font_face_twin_create_for_toy (toy_face, font_face); +} + +static const cairo_scaled_font_backend_t _cairo_user_scaled_font_backend = { + CAIRO_FONT_TYPE_USER, + NULL, /* scaled_font_fini */ + _cairo_user_scaled_glyph_init, + _cairo_user_text_to_glyphs, + _cairo_user_ucs4_to_index, + NULL, /* show_glyphs */ + NULL, /* load_truetype_table */ + NULL /* index_to_ucs4 */ +}; + +/* #cairo_user_font_face_t */ + +static cairo_status_t +_cairo_user_font_face_scaled_font_create (void *abstract_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + cairo_scaled_font_t **scaled_font) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_user_font_face_t *font_face = abstract_face; + cairo_user_scaled_font_t *user_scaled_font = NULL; + cairo_font_extents_t font_extents = {1., 0., 1., 1., 0.}; + + font_face->immutable = TRUE; + + user_scaled_font = malloc (sizeof (cairo_user_scaled_font_t)); + if (unlikely (user_scaled_font == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = _cairo_scaled_font_init (&user_scaled_font->base, + &font_face->base, + font_matrix, ctm, options, + &_cairo_user_scaled_font_backend); + + if (unlikely (status)) { + free (user_scaled_font); + return status; + } + + /* XXX metrics hinting? */ + + /* compute a normalized version of font scale matrix to compute + * extents in. This is to minimize error caused by the cairo_fixed_t + * representation. */ + { + double fixed_scale, x_scale, y_scale; + + user_scaled_font->extent_scale = user_scaled_font->base.scale_inverse; + status = _cairo_matrix_compute_basis_scale_factors (&user_scaled_font->extent_scale, + &x_scale, &y_scale, + 1); + if (status == CAIRO_STATUS_SUCCESS) { + + if (x_scale == 0) x_scale = 1.; + if (y_scale == 0) y_scale = 1.; + + user_scaled_font->snap_x_scale = x_scale; + user_scaled_font->snap_y_scale = y_scale; + + /* since glyphs are pretty much 1.0x1.0, we can reduce error by + * scaling to a larger square. say, 1024.x1024. */ + fixed_scale = 1024.; + x_scale /= fixed_scale; + y_scale /= fixed_scale; + + cairo_matrix_scale (&user_scaled_font->extent_scale, 1. / x_scale, 1. / y_scale); + + user_scaled_font->extent_x_scale = x_scale; + user_scaled_font->extent_y_scale = y_scale; + } + } + + if (status == CAIRO_STATUS_SUCCESS && + font_face->scaled_font_methods.init != NULL) + { + /* Lock the scaled_font mutex such that user doesn't accidentally try + * to use it just yet. */ + CAIRO_MUTEX_LOCK (user_scaled_font->base.mutex); + + /* Give away fontmap lock such that user-font can use other fonts */ + status = _cairo_scaled_font_register_placeholder_and_unlock_font_map (&user_scaled_font->base); + if (status == CAIRO_STATUS_SUCCESS) { + cairo_surface_t *recording_surface; + cairo_t *cr; + + recording_surface = _cairo_user_scaled_font_create_recording_surface (user_scaled_font); + cr = _cairo_user_scaled_font_create_recording_context (user_scaled_font, recording_surface); + cairo_surface_destroy (recording_surface); + + status = font_face->scaled_font_methods.init (&user_scaled_font->base, + cr, + &font_extents); + + if (status == CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED) + status = CAIRO_STATUS_SUCCESS; + + if (status == CAIRO_STATUS_SUCCESS) + status = cairo_status (cr); + + cairo_destroy (cr); + + _cairo_scaled_font_unregister_placeholder_and_lock_font_map (&user_scaled_font->base); + } + + CAIRO_MUTEX_UNLOCK (user_scaled_font->base.mutex); + } + + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_scaled_font_set_metrics (&user_scaled_font->base, &font_extents); + + if (status != CAIRO_STATUS_SUCCESS) { + _cairo_scaled_font_fini (&user_scaled_font->base); + free (user_scaled_font); + } else { + user_scaled_font->default_glyph_extents.x_bearing = 0.; + user_scaled_font->default_glyph_extents.y_bearing = -font_extents.ascent; + user_scaled_font->default_glyph_extents.width = 0.; + user_scaled_font->default_glyph_extents.height = font_extents.ascent + font_extents.descent; + user_scaled_font->default_glyph_extents.x_advance = font_extents.max_x_advance; + user_scaled_font->default_glyph_extents.y_advance = 0.; + + *scaled_font = &user_scaled_font->base; + } + + return status; +} + +const cairo_font_face_backend_t _cairo_user_font_face_backend = { + CAIRO_FONT_TYPE_USER, + _cairo_user_font_face_create_for_toy, + _cairo_font_face_destroy, + _cairo_user_font_face_scaled_font_create +}; + + +cairo_bool_t +_cairo_font_face_is_user (cairo_font_face_t *font_face) +{ + return font_face->backend == &_cairo_user_font_face_backend; +} + +/* Implement the public interface */ + +/** + * cairo_user_font_face_create: + * + * Creates a new user font-face. + * + * Use the setter functions to associate callbacks with the returned + * user font. The only mandatory callback is render_glyph. + * + * After the font-face is created, the user can attach arbitrary data + * (the actual font data) to it using cairo_font_face_set_user_data() + * and access it from the user-font callbacks by using + * cairo_scaled_font_get_font_face() followed by + * cairo_font_face_get_user_data(). + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.8 + **/ +cairo_font_face_t * +cairo_user_font_face_create (void) +{ + cairo_user_font_face_t *font_face; + + font_face = malloc (sizeof (cairo_user_font_face_t)); + if (!font_face) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_font_face_t *)&_cairo_font_face_nil; + } + + _cairo_font_face_init (&font_face->base, &_cairo_user_font_face_backend); + + font_face->immutable = FALSE; + memset (&font_face->scaled_font_methods, 0, sizeof (font_face->scaled_font_methods)); + + return &font_face->base; +} +slim_hidden_def(cairo_user_font_face_create); + +/* User-font method setters */ + + +/** + * cairo_user_font_face_set_init_func: + * @font_face: A user font face + * @init_func: The init callback, or %NULL + * + * Sets the scaled-font initialization function of a user-font. + * See #cairo_user_scaled_font_init_func_t for details of how the callback + * works. + * + * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE + * error will occur. A user font-face is immutable as soon as a scaled-font + * is created from it. + * + * Since: 1.8 + **/ +void +cairo_user_font_face_set_init_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_init_func_t init_func) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + if (user_font_face->immutable) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) + return; + } + user_font_face->scaled_font_methods.init = init_func; +} +slim_hidden_def(cairo_user_font_face_set_init_func); + +/** + * cairo_user_font_face_set_render_glyph_func: + * @font_face: A user font face + * @render_glyph_func: The render_glyph callback, or %NULL + * + * Sets the glyph rendering function of a user-font. + * See #cairo_user_scaled_font_render_glyph_func_t for details of how the callback + * works. + * + * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE + * error will occur. A user font-face is immutable as soon as a scaled-font + * is created from it. + * + * The render_glyph callback is the only mandatory callback of a user-font. + * If the callback is %NULL and a glyph is tried to be rendered using + * @font_face, a %CAIRO_STATUS_USER_FONT_ERROR will occur. + * + * Since: 1.8 + **/ +void +cairo_user_font_face_set_render_glyph_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_render_glyph_func_t render_glyph_func) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + if (user_font_face->immutable) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) + return; + } + user_font_face->scaled_font_methods.render_glyph = render_glyph_func; +} +slim_hidden_def(cairo_user_font_face_set_render_glyph_func); + +/** + * cairo_user_font_face_set_text_to_glyphs_func: + * @font_face: A user font face + * @text_to_glyphs_func: The text_to_glyphs callback, or %NULL + * + * Sets th text-to-glyphs conversion function of a user-font. + * See #cairo_user_scaled_font_text_to_glyphs_func_t for details of how the callback + * works. + * + * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE + * error will occur. A user font-face is immutable as soon as a scaled-font + * is created from it. + * + * Since: 1.8 + **/ +void +cairo_user_font_face_set_text_to_glyphs_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_text_to_glyphs_func_t text_to_glyphs_func) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + if (user_font_face->immutable) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) + return; + } + user_font_face->scaled_font_methods.text_to_glyphs = text_to_glyphs_func; +} + +/** + * cairo_user_font_face_set_unicode_to_glyph_func: + * @font_face: A user font face + * @unicode_to_glyph_func: The unicode_to_glyph callback, or %NULL + * + * Sets the unicode-to-glyph conversion function of a user-font. + * See #cairo_user_scaled_font_unicode_to_glyph_func_t for details of how the callback + * works. + * + * The font-face should not be immutable or a %CAIRO_STATUS_USER_FONT_IMMUTABLE + * error will occur. A user font-face is immutable as soon as a scaled-font + * is created from it. + * + * Since: 1.8 + **/ +void +cairo_user_font_face_set_unicode_to_glyph_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_unicode_to_glyph_func_t unicode_to_glyph_func) +{ + cairo_user_font_face_t *user_font_face; + if (font_face->status) + return; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + if (user_font_face->immutable) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_USER_FONT_IMMUTABLE)) + return; + } + user_font_face->scaled_font_methods.unicode_to_glyph = unicode_to_glyph_func; +} +slim_hidden_def(cairo_user_font_face_set_unicode_to_glyph_func); + +/* User-font method getters */ + +/** + * cairo_user_font_face_get_init_func: + * @font_face: A user font face + * + * Gets the scaled-font initialization function of a user-font. + * + * Return value: The init callback of @font_face + * or %NULL if none set or an error has occurred. + * + * Since: 1.8 + **/ +cairo_user_scaled_font_init_func_t +cairo_user_font_face_get_init_func (cairo_font_face_t *font_face) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return NULL; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return NULL; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + return user_font_face->scaled_font_methods.init; +} + +/** + * cairo_user_font_face_get_render_glyph_func: + * @font_face: A user font face + * + * Gets the glyph rendering function of a user-font. + * + * Return value: The render_glyph callback of @font_face + * or %NULL if none set or an error has occurred. + * + * Since: 1.8 + **/ +cairo_user_scaled_font_render_glyph_func_t +cairo_user_font_face_get_render_glyph_func (cairo_font_face_t *font_face) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return NULL; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return NULL; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + return user_font_face->scaled_font_methods.render_glyph; +} + +/** + * cairo_user_font_face_get_text_to_glyphs_func: + * @font_face: A user font face + * + * Gets the text-to-glyphs conversion function of a user-font. + * + * Return value: The text_to_glyphs callback of @font_face + * or %NULL if none set or an error occurred. + * + * Since: 1.8 + **/ +cairo_user_scaled_font_text_to_glyphs_func_t +cairo_user_font_face_get_text_to_glyphs_func (cairo_font_face_t *font_face) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return NULL; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return NULL; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + return user_font_face->scaled_font_methods.text_to_glyphs; +} + +/** + * cairo_user_font_face_get_unicode_to_glyph_func: + * @font_face: A user font face + * + * Gets the unicode-to-glyph conversion function of a user-font. + * + * Return value: The unicode_to_glyph callback of @font_face + * or %NULL if none set or an error occurred. + * + * Since: 1.8 + **/ +cairo_user_scaled_font_unicode_to_glyph_func_t +cairo_user_font_face_get_unicode_to_glyph_func (cairo_font_face_t *font_face) +{ + cairo_user_font_face_t *user_font_face; + + if (font_face->status) + return NULL; + + if (! _cairo_font_face_is_user (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return NULL; + } + + user_font_face = (cairo_user_font_face_t *) font_face; + return user_font_face->scaled_font_methods.unicode_to_glyph; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-version.c b/Build/source/libs/cairo/cairo-src/src/cairo-version.c new file mode 100644 index 00000000000..a94cef6819d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-version.c @@ -0,0 +1,261 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#define CAIRO_VERSION_H 1 + +#include "cairoint.h" + +/* get the "real" version info instead of dummy cairo-version.h */ +#undef CAIRO_VERSION_H +#include "../cairo-version.h" + +/** + * SECTION:cairo-version + * @Title: Version Information + * @Short_Description: Compile-time and run-time version checks. + * + * Cairo has a three-part version number scheme. In this scheme, we use + * even vs. odd numbers to distinguish fixed points in the software + * vs. in-progress development, (such as from git instead of a tar file, + * or as a "snapshot" tar file as opposed to a "release" tar file). + * + * + * _____ Major. Always 1, until we invent a new scheme. + * / ___ Minor. Even/Odd = Release/Snapshot (tar files) or Branch/Head (git) + * | / _ Micro. Even/Odd = Tar-file/git + * | | / + * 1.0.0 + * + * + * Here are a few examples of versions that one might see. + * + * Releases + * -------- + * 1.0.0 - A major release + * 1.0.2 - A subsequent maintenance release + * 1.2.0 - Another major release + *   + * Snapshots + * --------- + * 1.1.2 - A snapshot (working toward the 1.2.0 release) + *   + * In-progress development (eg. from git) + * -------------------------------------- + * 1.0.1 - Development on a maintenance branch (toward 1.0.2 release) + * 1.1.1 - Development on head (toward 1.1.2 snapshot and 1.2.0 release) + * + * + * + * Compatibility + * + * The API/ABI compatibility guarantees for various versions are as + * follows. First, let's assume some cairo-using application code that is + * successfully using the API/ABI "from" one version of cairo. Then let's + * ask the question whether this same code can be moved "to" the API/ABI + * of another version of cairo. + * + * Moving from a release to any later version (release, snapshot, + * development) is always guaranteed to provide compatibility. + * + * Moving from a snapshot to any later version is not guaranteed to + * provide compatibility, since snapshots may introduce new API that ends + * up being removed before the next release. + * + * Moving from an in-development version (odd micro component) to any + * later version is not guaranteed to provide compatibility. In fact, + * there's not even a guarantee that the code will even continue to work + * with the same in-development version number. This is because these + * numbers don't correspond to any fixed state of the software, but + * rather the many states between snapshots and releases. + * + * + * + * Examining the version + * + * Cairo provides the ability to examine the version at either + * compile-time or run-time and in both a human-readable form as well as + * an encoded form suitable for direct comparison. Cairo also provides the + * macro CAIRO_VERSION_ENCODE() to perform the encoding. + * + * + * Compile-time + * ------------ + * CAIRO_VERSION_STRING Human-readable + * CAIRO_VERSION Encoded, suitable for comparison + *   + * Run-time + * -------- + * cairo_version_string() Human-readable + * cairo_version() Encoded, suitable for comparison + * + * + * For example, checking that the cairo version is greater than or equal + * to 1.0.0 could be achieved at compile-time or run-time as follows: + * + * + * ##if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 0, 0) + * printf ("Compiling with suitable cairo version: %s\n", %CAIRO_VERSION_STRING); + * ##endif + * + * if (cairo_version() >= CAIRO_VERSION_ENCODE(1, 0, 0)) + * printf ("Running with suitable cairo version: %s\n", cairo_version_string ()); + * + * + * + * + **/ + +/** + * CAIRO_VERSION: + * + * The version of cairo available at compile-time, encoded using + * CAIRO_VERSION_ENCODE(). + * + * Since: 1.0 + **/ + +/** + * CAIRO_VERSION_MAJOR: + * + * The major component of the version of cairo available at compile-time. + * + * Since: 1.0 + **/ + +/** + * CAIRO_VERSION_MINOR: + * + * The minor component of the version of cairo available at compile-time. + * + * Since: 1.0 + **/ + +/** + * CAIRO_VERSION_MICRO: + * + * The micro component of the version of cairo available at compile-time. + * + * Since: 1.0 + **/ + +/** + * CAIRO_VERSION_STRING: + * + * A human-readable string literal containing the version of cairo available + * at compile-time, in the form of "X.Y.Z". + * + * Since: 1.8 + **/ + +/** + * CAIRO_VERSION_ENCODE: + * @major: the major component of the version number + * @minor: the minor component of the version number + * @micro: the micro component of the version number + * + * This macro encodes the given cairo version into an integer. The numbers + * returned by %CAIRO_VERSION and cairo_version() are encoded using this macro. + * Two encoded version numbers can be compared as integers. The encoding ensures + * that later versions compare greater than earlier versions. + * + * Returns: the encoded version. + * + * Since: 1.0 + **/ + +/** + * CAIRO_VERSION_STRINGIZE: + * @major: the major component of the version number + * @minor: the minor component of the version number + * @micro: the micro component of the version number + * + * This macro encodes the given cairo version into an string. The numbers + * returned by %CAIRO_VERSION_STRING and cairo_version_string() are encoded using this macro. + * The parameters to this macro must expand to numerical literals. + * + * Returns: a string literal containing the version. + * + * Since: 1.8 + **/ + +/** + * cairo_version: + * + * Returns the version of the cairo library encoded in a single + * integer as per %CAIRO_VERSION_ENCODE. The encoding ensures that + * later versions compare greater than earlier versions. + * + * A run-time comparison to check that cairo's version is greater than + * or equal to version X.Y.Z could be performed as follows: + * + * + * if (cairo_version() >= CAIRO_VERSION_ENCODE(X,Y,Z)) {...} + * + * + * See also cairo_version_string() as well as the compile-time + * equivalents %CAIRO_VERSION and %CAIRO_VERSION_STRING. + * + * Return value: the encoded version. + * + * Since: 1.0 + **/ +int +cairo_version (void) +{ + return CAIRO_VERSION; +} + +/** + * cairo_version_string: + * + * Returns the version of the cairo library as a human-readable string + * of the form "X.Y.Z". + * + * See also cairo_version() as well as the compile-time equivalents + * %CAIRO_VERSION_STRING and %CAIRO_VERSION. + * + * Return value: a string containing the version. + * + * Since: 1.0 + **/ +const char* +cairo_version_string (void) +{ + return CAIRO_VERSION_STRING; +} +slim_hidden_def (cairo_version_string); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-version.h b/Build/source/libs/cairo/cairo-src/src/cairo-version.h new file mode 100644 index 00000000000..51008003f98 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-version.h @@ -0,0 +1,14 @@ +/* This is a dummy file. + * The actual version info is in toplevel cairo-version.h. + * The purpose of this file is to make most of the source files NOT depend + * on the real cairo-version.h, and as a result, changing library version + * would not cause a complete rebuild of all object files (just a relink). + * This is useful when bisecting. */ +#ifndef CAIRO_VERSION_H +#define CAIRO_VERSION_H + +#define CAIRO_VERSION_MAJOR USE_cairo_version_OR_cairo_version_string_INSTEAD +#define CAIRO_VERSION_MINOR USE_cairo_version_OR_cairo_version_string_INSTEAD +#define CAIRO_VERSION_MICRO USE_cairo_version_OR_cairo_version_string_INSTEAD + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-vg-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-vg-surface.c new file mode 100644 index 00000000000..6e0d9a0ed69 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-vg-surface.c @@ -0,0 +1,1853 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Opened Hand Ltd. + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.og/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Pierre Tardy + * Øyvind Kolås + * Vladimi Vukicevic (stubbed out base backend) + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-vg.h" + +#include "cairo-cache-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-path-fixed-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-surface-clipper-private.h" + +#include +#include + +//#define OPENVG_DEBUG + +/* + * Work that needs to be done: + * - Glyph cache / proper font support + * + * - First-class paths + * Paths are expensive for OpenVG, reuse paths whenever possible. + * So add a path cache, and first class paths! + */ + +typedef struct _cairo_vg_surface cairo_vg_surface_t; + +/* XXX need GL specific context control. :( */ +struct _cairo_vg_context { + cairo_status_t status; + cairo_reference_count_t ref_count; + + unsigned long target_id; + + VGPaint paint; + cairo_vg_surface_t *source; + double alpha; + + cairo_cache_t snapshot_cache; + + void *display; + void *context; + + cairo_status_t (*create_target) (cairo_vg_context_t *, + cairo_vg_surface_t *); + cairo_status_t (*set_target) (cairo_vg_context_t *, + cairo_vg_surface_t *); + void (*destroy_target) (cairo_vg_context_t *, cairo_vg_surface_t *); +}; + +struct _cairo_vg_surface { + cairo_surface_t base; + + cairo_vg_context_t *context; + + VGImage image; + VGImageFormat format; + int width; + int height; + cairo_bool_t own_image; + + cairo_cache_entry_t snapshot_cache_entry; + + cairo_surface_clipper_t clipper; + + unsigned long target_id; +}; + +static const cairo_surface_backend_t cairo_vg_surface_backend; + +slim_hidden_proto (cairo_vg_surface_create); + +static cairo_surface_t * +_vg_surface_create_internal (cairo_vg_context_t *context, + VGImage image, + VGImageFormat format, + int width, int height); + +static cairo_vg_context_t * +_vg_context_reference (cairo_vg_context_t *context) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&context->ref_count)); + + _cairo_reference_count_inc (&context->ref_count); + + return context; +} + +static cairo_vg_context_t * +_vg_context_lock (cairo_vg_context_t *context) +{ + /* XXX if we need to add locking, then it has to be recursive */ + return context; +} + +static cairo_int_status_t +_vg_context_set_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ + cairo_status_t status; + + if (surface->target_id == 0) { + status = context->create_target (context, surface); + if (unlikely (status)) + return status; + } + + if (context->target_id == surface->target_id) + return CAIRO_STATUS_SUCCESS; + + context->target_id = surface->target_id; + + return context->set_target (context, surface); +} + +static void +_vg_context_destroy_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ + if (surface->target_id == 0) + return; + + if (context->target_id == surface->target_id) + context->set_target (context, NULL); + + context->destroy_target (context, surface); +} + +static cairo_bool_t +_vg_snapshot_cache_can_remove (const void *entry) +{ + return TRUE; +} + +static void +_vg_snapshot_cache_remove (void *cache_entry) +{ + cairo_vg_surface_t *surface = cairo_container_of (cache_entry, + cairo_vg_surface_t, + snapshot_cache_entry); + surface->snapshot_cache_entry.hash = 0; + cairo_surface_destroy (&surface->base); +} + +static cairo_status_t +_vg_context_init (cairo_vg_context_t *context) +{ + cairo_status_t status; + + context->status = CAIRO_STATUS_SUCCESS; + CAIRO_REFERENCE_COUNT_INIT (&context->ref_count, 1); + + status = _cairo_cache_init (&context->snapshot_cache, + NULL, + _vg_snapshot_cache_can_remove, + _vg_snapshot_cache_remove, + 16*1024*1024); + if (unlikely (status)) + return status; + + context->target_id = 0; + context->source = NULL; + context->alpha = 1.0; + + context->paint = vgCreatePaint (); + vgLoadIdentity (); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_vg_context_destroy (cairo_vg_context_t *context) +{ + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&context->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&context->ref_count)) + return; + + if (context->paint != VG_INVALID_HANDLE) + vgDestroyPaint (context->paint); + + _cairo_cache_fini (&context->snapshot_cache); + free (context); +} + +static void +_vg_context_unlock (cairo_vg_context_t *context) +{ +} + +#ifdef OPENVG_DEBUG +static void check_vg_errors(const char*function,int line) +{ + int err = vgGetError(); + if (err != VG_NO_ERROR){ + printf("%s+%d:vgError detected: 0x%08x.\n",function, line,err); + assert(err == VG_NO_ERROR); + } + +} +#define CHECK_VG_ERRORS() check_vg_errors(__FILE__,__LINE__) +#else +#define CHECK_VG_ERRORS() do{}while(0) +#endif //OPENVG_DEBUG + +static pixman_format_code_t +_vg_format_to_pixman (VGImageFormat format, + cairo_bool_t *needs_premult_fixup) +{ + *needs_premult_fixup = FALSE; + switch (format) { + /* RGB{A,X} channel ordering */ + case VG_sRGBX_8888: return PIXMAN_r8g8b8x8; + case VG_sRGBA_8888: *needs_premult_fixup = TRUE; return PIXMAN_r8g8b8a8; + case VG_sRGBA_8888_PRE: return PIXMAN_r8g8b8a8; + case VG_sRGB_565: return PIXMAN_r5g6b5; + case VG_sRGBA_5551: return 0; + case VG_sRGBA_4444: return 0; + case VG_sL_8: return PIXMAN_g8; + case VG_lRGBX_8888: return 0; + case VG_lRGBA_8888: return 0; + case VG_lRGBA_8888_PRE: return 0; + case VG_lL_8: return 0; + case VG_A_8: return PIXMAN_a8; + case VG_BW_1: return PIXMAN_a1; + case VG_A_1: return PIXMAN_a1; + case VG_A_4: return PIXMAN_a4; + + /* {A,X}RGB channel ordering */ + case VG_sXRGB_8888: return PIXMAN_x8r8g8b8; + case VG_sARGB_8888: *needs_premult_fixup = TRUE; return PIXMAN_a8r8g8b8; + case VG_sARGB_8888_PRE: return PIXMAN_a8r8g8b8; + case VG_sARGB_1555: return 0; + case VG_sARGB_4444: return 0; + case VG_lXRGB_8888: return 0; + case VG_lARGB_8888: return 0; + case VG_lARGB_8888_PRE: return 0; + + /* BGR{A,X} channel ordering */ + case VG_sBGRX_8888: return PIXMAN_b8g8r8x8; + case VG_sBGRA_8888: *needs_premult_fixup = TRUE; return PIXMAN_b8g8r8a8; + case VG_sBGRA_8888_PRE: return PIXMAN_b8g8r8a8; + case VG_sBGR_565: return PIXMAN_b5g6r5; + case VG_sBGRA_5551: return 0; + case VG_sBGRA_4444: return 0; + case VG_lBGRX_8888: return 0; + case VG_lBGRA_8888: return 0; + case VG_lBGRA_8888_PRE: return 0; + + /* {A,X}BGR channel ordering */ + case VG_sXBGR_8888: return PIXMAN_x8b8g8r8; + case VG_sABGR_8888: *needs_premult_fixup = TRUE; return PIXMAN_a8b8g8r8; + case VG_sABGR_8888_PRE: return PIXMAN_a8b8g8r8; + case VG_sABGR_1555: return 0; + case VG_sABGR_4444: return 0; + case VG_lXBGR_8888: return 0; + case VG_lABGR_8888: return 0; + case VG_lABGR_8888_PRE: return 0; + default: return 0; + } +} + +static pixman_format_code_t +_vg_format_to_content (VGImageFormat format) +{ + /* XXX could use more simple bit tests */ + switch (format) { + /* RGB{A,X} channel ordering */ + case VG_sRGBX_8888: return CAIRO_CONTENT_COLOR; + case VG_sRGBA_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sRGBA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sRGB_565: return CAIRO_CONTENT_COLOR; + case VG_sRGBA_5551: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sRGBA_4444: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sL_8: return CAIRO_CONTENT_ALPHA; + case VG_lRGBX_8888: return CAIRO_CONTENT_COLOR; + case VG_lRGBA_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lRGBA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lL_8: return CAIRO_CONTENT_ALPHA; + case VG_A_8: return CAIRO_CONTENT_ALPHA; + case VG_A_4: return CAIRO_CONTENT_ALPHA; + case VG_A_1: return CAIRO_CONTENT_ALPHA; + case VG_BW_1: return CAIRO_CONTENT_ALPHA; + + /* {A,X}RGB channel ordering */ + case VG_sXRGB_8888: return CAIRO_CONTENT_COLOR; + case VG_sARGB_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sARGB_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sARGB_1555: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sARGB_4444: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lXRGB_8888: return CAIRO_CONTENT_COLOR; + case VG_lARGB_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lARGB_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + + /* BGR{A,X} channel ordering */ + case VG_sBGRX_8888: return CAIRO_CONTENT_COLOR; + case VG_sBGRA_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sBGRA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sBGR_565: return CAIRO_CONTENT_COLOR; + case VG_sBGRA_5551: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sBGRA_4444: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lBGRX_8888: return CAIRO_CONTENT_COLOR; + case VG_lBGRA_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lBGRA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + + /* {A,X}BGR channel ordering */ + case VG_sXBGR_8888: return CAIRO_CONTENT_COLOR; + case VG_sABGR_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sABGR_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sABGR_1555: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_sABGR_4444: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lXBGR_8888: return CAIRO_CONTENT_COLOR; + case VG_lABGR_8888: return CAIRO_CONTENT_COLOR_ALPHA; + case VG_lABGR_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA; + default: return 0; + } +} + +static VGImageFormat +_vg_format_from_pixman (pixman_format_code_t format) +{ + /* XXX _PRE needs fixup */ + switch ((int) format) { + case PIXMAN_r5g6b5: return VG_sRGB_565; + case PIXMAN_g8: return VG_sL_8; + case PIXMAN_a8: return VG_A_8; + case PIXMAN_a1: return VG_BW_1; + case PIXMAN_x8r8g8b8: return VG_sXRGB_8888; + case PIXMAN_a8r8g8b8: return VG_sARGB_8888; // _PRE + case PIXMAN_b8g8r8x8: return VG_sBGRX_8888; + case PIXMAN_b8g8r8a8: return VG_sBGRA_8888; // _PRE + case PIXMAN_b5g6r5: return VG_sBGR_565; + case PIXMAN_x8b8g8r8: return VG_sXBGR_8888; + case PIXMAN_a8b8g8r8: return VG_sABGR_8888; // _PRE + default: return 0; + } +} + +static VGImageFormat +_vg_format_for_content (cairo_content_t content) +{ + switch (content) { + case CAIRO_CONTENT_ALPHA: return VG_A_8; + case CAIRO_CONTENT_COLOR: return VG_sXRGB_8888; + default: ASSERT_NOT_REACHED; + case CAIRO_CONTENT_COLOR_ALPHA: return VG_sARGB_8888; // _PRE + } +} + +static cairo_surface_t * +_vg_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_vg_surface_t *surface = abstract_surface; + + if (width > vgGeti (VG_MAX_IMAGE_WIDTH) || + height > vgGeti (VG_MAX_IMAGE_HEIGHT)) + { + return NULL; + } + + return cairo_vg_surface_create (surface->context, content, width, height); +} + +static cairo_status_t +_vg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper, + cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_vg_surface_t *surface = cairo_container_of (clipper, + cairo_vg_surface_t, + clipper); + cairo_vg_surface_t *mask; + cairo_status_t status; + + if (path == NULL) { + vgMask (VG_INVALID_HANDLE, + VG_FILL_MASK, 0, 0, surface->width, surface->height); + vgSeti (VG_MASKING, VG_FALSE); + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; + } + + mask = (cairo_vg_surface_t *) + _vg_surface_create_similar (surface, CAIRO_CONTENT_ALPHA, + surface->width, surface->height); + if (unlikely (mask == NULL)) + return CAIRO_INT_STATUS_UNSUPPORTED; + if (unlikely (mask->base.status)) + return mask->base.status; + + status = _cairo_surface_fill (&mask->base, + CAIRO_OPERATOR_SOURCE, + &_cairo_pattern_white.base, + path, fill_rule, tolerance, antialias, + NULL); + if (status) { + cairo_surface_destroy (&mask->base); + return status; + } + + vgSeti (VG_MASKING, VG_TRUE); + vgMask (mask->image, VG_INTERSECT_MASK, 0, 0, mask->width, mask->height); + + cairo_surface_destroy (&mask->base); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_vg_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_vg_surface_t *surface = abstract_surface; + + extents->x = 0; + extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + + return TRUE; +} + +#define MAX_SEG 16 /* max number of knots to upload in a batch */ + +typedef struct _vg_path { + VGPath path; + const cairo_matrix_t *ctm_inverse; + + VGubyte gseg[MAX_SEG]; + VGfloat gdata[MAX_SEG*3*2]; + int dcount; + int scount; +} vg_path_t; + +static cairo_status_t +_vg_move_to (void *closure, + const cairo_point_t *point) +{ + vg_path_t *path = closure; + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (path->ctm_inverse) + cairo_matrix_transform_point (path->ctm_inverse, &x, &y); + + path->gseg[path->scount++] = VG_MOVE_TO; + path->gdata[path->dcount++] = x; + path->gdata[path->dcount++] = y; + + if (path->scount >= MAX_SEG-1) { + vgAppendPathData (path->path, path->scount, path->gseg, path->gdata); + path->scount = 0; + path->dcount = 0; + } + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_vg_line_to (void *closure, + const cairo_point_t *point) +{ + vg_path_t *path = closure; + double x = _cairo_fixed_to_double (point->x); + double y = _cairo_fixed_to_double (point->y); + + if (path->ctm_inverse) + cairo_matrix_transform_point (path->ctm_inverse, &x, &y); + + path->gseg[path->scount++] = VG_LINE_TO; + path->gdata[path->dcount++] = x; + path->gdata[path->dcount++] = y; + + if (path->scount >= MAX_SEG-1) { + vgAppendPathData (path->path, path->scount, path->gseg, path->gdata); + path->scount = 0; + path->dcount = 0; + } + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_vg_curve_to (void *closure, + const cairo_point_t *p0, + const cairo_point_t *p1, + const cairo_point_t *p2) +{ + vg_path_t *path = closure; + double x0 = _cairo_fixed_to_double (p0->x); + double y0 = _cairo_fixed_to_double (p0->y); + double x1 = _cairo_fixed_to_double (p1->x); + double y1 = _cairo_fixed_to_double (p1->y); + double x2 = _cairo_fixed_to_double (p2->x); + double y2 = _cairo_fixed_to_double (p2->y); + + if (path->ctm_inverse) { + cairo_matrix_transform_point (path->ctm_inverse, &x0, &y0); + cairo_matrix_transform_point (path->ctm_inverse, &x1, &y1); + cairo_matrix_transform_point (path->ctm_inverse, &x2, &y2); + } + + path->gseg[path->scount++] = VG_CUBIC_TO; + path->gdata[path->dcount++] = x0; + path->gdata[path->dcount++] = y0; + path->gdata[path->dcount++] = x1; + path->gdata[path->dcount++] = y1; + path->gdata[path->dcount++] = x2; + path->gdata[path->dcount++] = y2; + + if (path->scount >= MAX_SEG-1) { + vgAppendPathData(path->path, path->scount, path->gseg, path->gdata); + path->scount = 0; + path->dcount = 0; + } + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_vg_close_path (void *closure) +{ + vg_path_t *path = closure; + + path->gseg[path->scount++] = VG_CLOSE_PATH; + + if (path->scount >= MAX_SEG-1) { + vgAppendPathData (path->path, path->scount, path->gseg, path->gdata); + path->scount = 0; + path->dcount = 0; + } + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static void +_vg_path_from_cairo (vg_path_t *vg_path, + const cairo_path_fixed_t *path) +{ + cairo_status_t status; + + vg_path->scount = 0; + vg_path->dcount = 0; + + status = _cairo_path_fixed_interpret (path, + _vg_move_to, + _vg_line_to, + _vg_curve_to, + _vg_close_path, + vg_path); + assert (status == CAIRO_STATUS_SUCCESS); + + vgAppendPathData (vg_path->path, + vg_path->scount, vg_path->gseg, vg_path->gdata); + CHECK_VG_ERRORS(); +} + +static cairo_bool_t +_vg_is_supported_operator (cairo_operator_t op) +{ + switch ((int) op) { + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_IN: + case CAIRO_OPERATOR_DEST_OVER: + case CAIRO_OPERATOR_DEST_IN: + case CAIRO_OPERATOR_ADD: + return TRUE; + + default: + return FALSE; + } +} + +static VGBlendMode +_vg_operator (cairo_operator_t op) +{ + switch ((int) op) { + case CAIRO_OPERATOR_SOURCE: + return VG_BLEND_SRC; + case CAIRO_OPERATOR_OVER: + return VG_BLEND_SRC_OVER; + case CAIRO_OPERATOR_IN: + return VG_BLEND_SRC_IN; + case CAIRO_OPERATOR_DEST_OVER: + return VG_BLEND_DST_OVER; + case CAIRO_OPERATOR_DEST_IN: + return VG_BLEND_DST_IN; + case CAIRO_OPERATOR_ADD: + return VG_BLEND_ADDITIVE; + default: + ASSERT_NOT_REACHED; + return VG_BLEND_SRC_OVER; + } +} + +static VGFillRule +_vg_fill_rule_from_cairo (cairo_fill_rule_t rule) +{ + switch (rule) { + case CAIRO_FILL_RULE_EVEN_ODD: return VG_EVEN_ODD; + case CAIRO_FILL_RULE_WINDING: return VG_NON_ZERO; + } + + ASSERT_NOT_REACHED; + return VG_NON_ZERO; +} + +static VGRenderingQuality +_vg_rendering_quality_from_cairo (cairo_antialias_t aa) +{ + switch (aa) { + case CAIRO_ANTIALIAS_DEFAULT: + case CAIRO_ANTIALIAS_SUBPIXEL: + case CAIRO_ANTIALIAS_GOOD: + case CAIRO_ANTIALIAS_BEST: + return VG_RENDERING_QUALITY_BETTER; + + case CAIRO_ANTIALIAS_GRAY: + case CAIRO_ANTIALIAS_FAST: + return VG_RENDERING_QUALITY_FASTER; + + case CAIRO_ANTIALIAS_NONE: + return VG_RENDERING_QUALITY_NONANTIALIASED; + } + + ASSERT_NOT_REACHED; + return VG_RENDERING_QUALITY_BETTER; +} + +static VGCapStyle +_vg_line_cap_from_cairo (cairo_line_cap_t cap) +{ + switch (cap) { + case CAIRO_LINE_CAP_BUTT: return VG_CAP_BUTT; + case CAIRO_LINE_CAP_ROUND: return VG_CAP_ROUND; + case CAIRO_LINE_CAP_SQUARE: return VG_CAP_SQUARE; + } + + ASSERT_NOT_REACHED; + return VG_CAP_BUTT; +} + +static VGJoinStyle +_vg_line_join_from_cairo (cairo_line_join_t join) +{ + switch (join) { + case CAIRO_LINE_JOIN_MITER: return VG_JOIN_MITER; + case CAIRO_LINE_JOIN_ROUND: return VG_JOIN_ROUND; + case CAIRO_LINE_JOIN_BEVEL: return VG_JOIN_BEVEL; + } + + ASSERT_NOT_REACHED; + return VG_JOIN_MITER; +} + +static void +_vg_matrix_from_cairo (VGfloat *dst, const cairo_matrix_t *src) +{ + dst[0] = /* sx */ src->xx; + dst[1] = /* shy */ src->yx; + dst[2] = /* w0 */ 0; + dst[3] = /* shx */ src->xy; + dst[4] = /* sy */ src->yy; + dst[5] = /* w1 */ 0; + dst[6] = /* tx */ src->x0; + dst[7] = /* ty */ src->y0; + dst[8] = /* w2 */ 0; +} + +static cairo_status_t +_vg_setup_gradient_stops (cairo_vg_context_t *context, + const cairo_gradient_pattern_t *pattern) +{ + VGint numstops = pattern->n_stops; + VGfloat *stops, stack_stops[CAIRO_STACK_ARRAY_LENGTH (VGfloat)]; + int i; + + if (numstops*5 < ARRAY_LENGTH (stack_stops)) { + stops = stack_stops; + } else { + stops = _cairo_malloc_ab (numstops, 5*sizeof (VGfloat)); + if (unlikely (stops == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + for (i = 0; i < numstops; i++) { + stops[i*5 + 0] = pattern->stops[i].offset; + stops[i*5 + 1] = pattern->stops[i].color.red; + stops[i*5 + 2] = pattern->stops[i].color.green; + stops[i*5 + 3] = pattern->stops[i].color.blue; + stops[i*5 + 4] = pattern->stops[i].color.alpha * context->alpha; + } + + vgSetParameterfv (context->paint, + VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops); + + if (stops != stack_stops) + free (stops); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static void +_vg_set_source_matrix (const cairo_pattern_t *pat) +{ + cairo_matrix_t mat; + cairo_status_t status; + VGfloat vmat[9]; + + mat = pat->matrix; + status = cairo_matrix_invert (&mat); + assert (status == CAIRO_STATUS_SUCCESS); + + _vg_matrix_from_cairo (vmat, &mat); + + vgSeti (VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); + vgLoadMatrix (vmat); + vgSeti (VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER); + vgLoadMatrix (vmat); + vgSeti (VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); + + CHECK_VG_ERRORS(); +} + +static cairo_status_t +_vg_setup_linear_source (cairo_vg_context_t *context, + const cairo_linear_pattern_t *lpat) +{ + VGfloat linear[4]; + + linear[0] = lpat->pd1.x; + linear[1] = lpat->pd1.y; + linear[2] = lpat->pd2.x; + linear[3] = lpat->pd2.y; + + vgSetParameteri (context->paint, + VG_PAINT_COLOR_RAMP_SPREAD_MODE, + VG_COLOR_RAMP_SPREAD_PAD); + vgSetParameteri (context->paint, + VG_PAINT_TYPE, + VG_PAINT_TYPE_LINEAR_GRADIENT); + vgSetParameterfv (context->paint, + VG_PAINT_LINEAR_GRADIENT, 4, linear); + + _vg_set_source_matrix (&lpat->base.base); + + CHECK_VG_ERRORS(); + return _vg_setup_gradient_stops (context, &lpat->base); + +} + +static cairo_status_t +_vg_setup_radial_source (cairo_vg_context_t *context, + const cairo_radial_pattern_t *rpat) +{ + VGfloat radial[5]; + + radial[0] = rpat->cd1.center.x; + radial[1] = rpat->cd1.center.y; + radial[2] = rpat->cd2.center.x; + radial[3] = rpat->cd2.center.y; + radial[4] = rpat->cd2.radius; + + vgSetParameteri (context->paint, + VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD); + vgSetParameteri (context->paint, + VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT); + vgSetParameterfv (context->paint, + VG_PAINT_RADIAL_GRADIENT, 5, radial); + + _vg_set_source_matrix (&rpat->base.base); + + /* FIXME: copy/adapt fixes from SVG backend to add inner radius */ + + CHECK_VG_ERRORS(); + return _vg_setup_gradient_stops (context, &rpat->base); +} + +static cairo_status_t +_vg_setup_solid_source (cairo_vg_context_t *context, + const cairo_solid_pattern_t *spat) +{ + VGfloat color[] = { + spat->color.red, + spat->color.green, + spat->color.blue, + spat->color.alpha * context->alpha + }; + + vgSetParameteri (context->paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); + vgSetParameterfv (context->paint, VG_PAINT_COLOR, 4, color); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_vg_surface_t * +_vg_clone_recording_surface (cairo_vg_context_t *context, + cairo_surface_t *surface) +{ + VGImage vg_image; + VGImageFormat format; + cairo_status_t status; + cairo_rectangle_int_t extents; + cairo_vg_surface_t *clone; + + status = _cairo_surface_get_extents (surface, &extents); + if (status) + return NULL; + + if (extents.width > vgGeti (VG_MAX_IMAGE_WIDTH) || + extents.height > vgGeti (VG_MAX_IMAGE_HEIGHT)) + { + return NULL; + } + + format = _vg_format_for_content (surface->content); + + /* NONALIASED, FASTER, BETTER */ + vg_image = vgCreateImage (format, + extents.width, extents.height, + VG_IMAGE_QUALITY_FASTER); + clone = (cairo_vg_surface_t *) + _vg_surface_create_internal (context, vg_image, format, + extents.width, extents.height); + cairo_surface_set_device_offset (&clone->base, -extents.x, -extents.y); + + status = _cairo_recording_surface_replay (surface, &clone->base); + if (unlikely (status)) { + cairo_surface_destroy (&clone->base); + return (cairo_vg_surface_t *) _cairo_surface_create_in_error (status); + } + + return clone; +} + +static cairo_vg_surface_t * +_vg_clone_image_surface (cairo_vg_context_t *context, + cairo_surface_t *surface) +{ + cairo_image_surface_t *image; + void *image_extra; + cairo_status_t status; + VGImage vg_image; + VGImageFormat format; + cairo_rectangle_int_t extents; + cairo_vg_surface_t *clone; + + if (surface->backend->acquire_source_image == NULL) + return NULL; + + status = _cairo_surface_get_extents (surface, &extents); + if (status) + return NULL; + + if (extents.width > vgGeti (VG_MAX_IMAGE_WIDTH) || + extents.height > vgGeti (VG_MAX_IMAGE_HEIGHT)) + { + return NULL; + } + + status = _cairo_surface_acquire_source_image (surface, + &image, &image_extra); + if (unlikely (status)) + return (cairo_vg_surface_t *) _cairo_surface_create_in_error (status); + + format = _vg_format_from_pixman (image->pixman_format); + if (format == 0) + format = _vg_format_for_content (image->base.content); + + /* NONALIASED, FASTER, BETTER */ + vg_image = vgCreateImage (format, + image->width, image->height, + VG_IMAGE_QUALITY_FASTER); + clone = (cairo_vg_surface_t *) + _vg_surface_create_internal (context, vg_image, format, + image->width, image->height); + if (unlikely (clone->base.status)) + return clone; + + vgImageSubData (clone->image, + image->data, image->stride, + format, 0, 0, image->width, image->height); + + _cairo_surface_release_source_image (surface, image, image_extra); + + return clone; +} + +static void +_vg_surface_remove_from_cache (cairo_surface_t *abstract_surface) +{ + cairo_vg_surface_t *surface = (cairo_vg_surface_t *) abstract_surface; + + if (surface->snapshot_cache_entry.hash) { + cairo_vg_context_t *context; + + context = _vg_context_lock (surface->context); + _cairo_cache_remove (&context->snapshot_cache, + &surface->snapshot_cache_entry); + _vg_context_unlock (context); + + surface->snapshot_cache_entry.hash = 0; + } +} + +static cairo_status_t +_vg_setup_surface_source (cairo_vg_context_t *context, + const cairo_surface_pattern_t *spat) +{ + cairo_surface_t *snapshot; + cairo_vg_surface_t *clone; + cairo_status_t status; + + snapshot = _cairo_surface_has_snapshot (spat->surface, + &cairo_vg_surface_backend); + if (snapshot != NULL) { + clone = (cairo_vg_surface_t *) cairo_surface_reference (snapshot); + goto DONE; + } + + if (_cairo_surface_is_recording (spat->surface)) + clone = _vg_clone_recording_surface (context, spat->surface); + else + clone = _vg_clone_image_surface (context, spat->surface); + if (clone == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + if (unlikely (clone->base.status)) + return clone->base.status; + + clone->snapshot_cache_entry.hash = clone->base.unique_id; + status = _cairo_cache_insert (&context->snapshot_cache, + &clone->snapshot_cache_entry); + if (unlikely (status)) { + clone->snapshot_cache_entry.hash = 0; + cairo_surface_destroy (&clone->base); + return status; + } + + _cairo_surface_attach_snapshot (spat->surface, &clone->base, + _vg_surface_remove_from_cache); + +DONE: + cairo_surface_destroy (&context->source->base); + context->source = clone; + + vgSetParameteri (context->paint, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN); + + switch (spat->base.extend) { + case CAIRO_EXTEND_PAD: + vgSetParameteri (context->paint, + VG_PAINT_PATTERN_TILING_MODE, + VG_TILE_PAD); + break; + + case CAIRO_EXTEND_NONE: + vgSetParameteri (context->paint, + VG_PAINT_PATTERN_TILING_MODE, + VG_TILE_FILL); + { + VGfloat color[] = {0,0,0,0}; + vgSetfv (VG_TILE_FILL_COLOR, 4, color); + } + break; + + case CAIRO_EXTEND_REPEAT: + vgSetParameteri (context->paint, + VG_PAINT_PATTERN_TILING_MODE, + VG_TILE_REPEAT); + break; + + default: + ASSERT_NOT_REACHED; + case CAIRO_EXTEND_REFLECT: + vgSetParameteri (context->paint, + VG_PAINT_PATTERN_TILING_MODE, + VG_TILE_REFLECT); + break; + } + vgPaintPattern (context->paint, context->source->image); + + _vg_set_source_matrix (&spat->base); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +setup_source (cairo_vg_context_t *context, + const cairo_pattern_t *source) +{ + switch (source->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return _vg_setup_solid_source (context, + (cairo_solid_pattern_t *) source); + case CAIRO_PATTERN_TYPE_LINEAR: + return _vg_setup_linear_source (context, + (cairo_linear_pattern_t *) source); + case CAIRO_PATTERN_TYPE_RADIAL: + return _vg_setup_radial_source (context, + (cairo_radial_pattern_t *) source); + case CAIRO_PATTERN_TYPE_SURFACE: + return _vg_setup_surface_source (context, + (cairo_surface_pattern_t *) source); + default: + ASSERT_NOT_REACHED; + return CAIRO_INT_STATUS_UNSUPPORTED; + } +} + +static cairo_int_status_t +_vg_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_vg_surface_t *surface = abstract_surface; + cairo_vg_context_t *context; + cairo_status_t status; + VGfloat state[9]; + VGfloat strokeTransform[9]; + vg_path_t vg_path; + + if (! _vg_is_supported_operator (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + context = _vg_context_lock (surface->context); + status = _vg_context_set_target (context, surface); + if (status) { + _vg_context_unlock (context); + return status; + } + + status = setup_source (context, source); + if (status) { + _vg_context_unlock (context); + return status; + } + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) { + _vg_context_unlock (context); + return status; + } + + vg_path.path = vgCreatePath (VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1, 0, 0, 0, + VG_PATH_CAPABILITY_ALL); + + vgGetMatrix (state); + _vg_matrix_from_cairo (strokeTransform, ctm); + vgMultMatrix (strokeTransform); + + vg_path.ctm_inverse = ctm_inverse; + + _vg_path_from_cairo (&vg_path, path); + + /* XXX DASH_PATTERN, DASH_PHASE */ + vgSetf (VG_STROKE_LINE_WIDTH, style->line_width); + vgSetf (VG_STROKE_MITER_LIMIT, style->miter_limit); + vgSetf (VG_STROKE_JOIN_STYLE, _vg_line_join_from_cairo (style->line_join)); + vgSetf (VG_STROKE_CAP_STYLE, _vg_line_cap_from_cairo (style->line_cap)); + + vgSeti (VG_BLEND_MODE, _vg_operator (op)); + + vgSetPaint (context->paint, VG_STROKE_PATH); + + vgDrawPath (vg_path.path, VG_STROKE_PATH); + + vgDestroyPath (vg_path.path); + + vgLoadMatrix (state); + + CHECK_VG_ERRORS(); + _vg_context_unlock (context); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_vg_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_vg_surface_t *surface = abstract_surface; + cairo_vg_context_t *context; + cairo_status_t status; + vg_path_t vg_path; + + if (op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (! _vg_is_supported_operator (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + context = _vg_context_lock (surface->context); + status = _vg_context_set_target (context, surface); + if (status) { + _vg_context_unlock (context); + return status; + } + + status = setup_source (context, source); + if (status) { + _vg_context_unlock (context); + return status; + } + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) { + _vg_context_unlock (context); + return status; + } + + vg_path.path = vgCreatePath (VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1, 0, + 0, 0, + VG_PATH_CAPABILITY_ALL); + vg_path.ctm_inverse = NULL; + + _vg_path_from_cairo (&vg_path, path); + + /* XXX tolerance */ + + vgSeti (VG_BLEND_MODE, _vg_operator (op)); + vgSetf (VG_FILL_RULE, _vg_fill_rule_from_cairo (fill_rule)); + vgSetf (VG_RENDERING_QUALITY, _vg_rendering_quality_from_cairo (antialias)); + + vgSetPaint (context->paint, VG_FILL_PATH); + + vgDrawPath (vg_path.path, VG_FILL_PATH); + + vgDestroyPath (vg_path.path); + + _vg_context_unlock (context); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_vg_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_vg_surface_t *surface = abstract_surface; + cairo_vg_context_t *context; + cairo_status_t status; + + if (op == CAIRO_OPERATOR_DEST) + return CAIRO_STATUS_SUCCESS; + + if (! _vg_is_supported_operator (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + context = _vg_context_lock (surface->context); + status = _vg_context_set_target (context, surface); + if (status) { + _vg_context_unlock (context); + return status; + } + + status = setup_source (context, source); + if (status) { + _vg_context_unlock (context); + return status; + } + + status = _cairo_surface_clipper_set_clip (&surface->clipper, clip); + if (unlikely (status)) { + _vg_context_unlock (context); + return status; + } + + vgSeti (VG_BLEND_MODE, _vg_operator (op)); + vgSetPaint (context->paint, VG_FILL_PATH); + + { /* creating a rectangular path that should cover the extent */ + VGubyte segs[] = { + VG_MOVE_TO_ABS, VG_LINE_TO_ABS, + VG_LINE_TO_ABS, VG_LINE_TO_ABS, + VG_CLOSE_PATH + }; + VGfloat data[] = { + 0, 0, + surface->width, 0, + surface->width, surface->height, + 0, surface->height + }; + VGPath fullext; + + fullext = vgCreatePath (VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1,0,0,0, VG_PATH_CAPABILITY_ALL); + vgAppendPathData (fullext, sizeof(segs), segs, data); + + vgDrawPath (fullext, VG_FILL_PATH); + + vgDestroyPath (fullext); + } + + _vg_context_unlock (context); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_vg_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_vg_surface_t *surface = abstract_surface; + cairo_status_t status; + + if (! _vg_is_supported_operator (op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Handle paint-with-alpha to do fades cheaply */ + if (mask->type == CAIRO_PATTERN_TYPE_SOLID) { + cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) mask; + cairo_vg_context_t *context = _vg_context_lock (surface->context); + double alpha = context->alpha; + + context->alpha = solid->color.alpha; + status = _vg_surface_paint (abstract_surface, op, source, clip); + context->alpha = alpha; + + _vg_context_unlock (context); + + return status; + } + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static void +_vg_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + _cairo_font_options_init_default (options); + + cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON); + _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF); +} + +static cairo_int_status_t +_vg_surface_show_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_path_fixed_t path; + + if (num_glyphs <= 0) + return CAIRO_STATUS_SUCCESS; + + _cairo_path_fixed_init (&path); + + /* XXX Glyph cache! OpenVG font support in 1.1? */ + + status = _cairo_scaled_font_glyph_path (scaled_font, + glyphs, num_glyphs, + &path); + if (unlikely (status)) + goto BAIL; + + status = _vg_surface_fill (abstract_surface, + op, source, &path, + CAIRO_FILL_RULE_WINDING, + CAIRO_GSTATE_TOLERANCE_DEFAULT, + CAIRO_ANTIALIAS_DEFAULT, + clip); +BAIL: + _cairo_path_fixed_fini (&path); + return status; +} + +static inline int +multiply_alpha (int alpha, int color) +{ + int temp = alpha * color + 0x80; + return (temp + (temp >> 8)) >> 8; +} + +static void +premultiply_argb (uint8_t *data, + int width, + int height, + int stride) +{ + int i; + + while (height --) { + uint32_t *row = (uint32_t *) data; + + for (i = 0; i < width; i++) { + uint32_t p = row[i]; + uint8_t alpha; + + alpha = p >> 24; + if (alpha == 0) { + row[i] = 0; + } else if (alpha != 0xff) { + uint8_t r = multiply_alpha (alpha, (p >> 16) & 0xff); + uint8_t g = multiply_alpha (alpha, (p >> 8) & 0xff); + uint8_t b = multiply_alpha (alpha, (p >> 0) & 0xff); + row[i] = (alpha << 24) | (r << 16) | (g << 8) | (b << 0); + } + } + + data += stride; + } +} + +static cairo_int_status_t +_vg_get_image (cairo_vg_surface_t *surface, + int x, int y, + int width, int height, + cairo_image_surface_t **image_out) +{ + cairo_image_surface_t *image; + pixman_image_t *pixman_image; + pixman_format_code_t pixman_format; + cairo_bool_t needs_premultiply; + + pixman_format = _vg_format_to_pixman (surface->format, + &needs_premultiply); + if (pixman_format == 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + pixman_image = pixman_image_create_bits (pixman_format, + width, height, + NULL, 0); + if (unlikely (pixman_image == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + vgFinish (); + CHECK_VG_ERRORS(); + + vgGetImageSubData (surface->image, + pixman_image_get_data (pixman_image), + pixman_image_get_stride (pixman_image), + surface->format, + x, y, width, height); + + image = (cairo_image_surface_t *) + _cairo_image_surface_create_for_pixman_image (pixman_image, + pixman_format); + if (unlikely (image->base.status)) { + pixman_image_unref (pixman_image); + return image->base.status; + } + + if (needs_premultiply) + premultiply_argb (image->data, width, height, image->stride); + + *image_out = image; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_vg_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_vg_surface_t *surface = abstract_surface; + + CHECK_VG_ERRORS(); + *image_extra = NULL; + return _vg_get_image (surface, + 0, 0, surface->width, surface->height, + image_out); +} + +static void +_vg_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); +} + +static cairo_status_t +_vg_surface_finish (void *abstract_surface) +{ + cairo_vg_surface_t *surface = abstract_surface; + cairo_vg_context_t *context = _vg_context_lock (surface->context); + + if (surface->snapshot_cache_entry.hash) { + _cairo_cache_remove (&context->snapshot_cache, + &surface->snapshot_cache_entry); + + surface->snapshot_cache_entry.hash = 0; + } + + _cairo_surface_clipper_reset (&surface->clipper); + + if (surface->own_image) + vgDestroyImage (surface->image); + + _vg_context_destroy_target (context, surface); + + _vg_context_unlock (context); + _vg_context_destroy (context); + + CHECK_VG_ERRORS(); + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t cairo_vg_surface_backend = { + CAIRO_SURFACE_TYPE_VG, + _vg_surface_finish, + + _cairo_default_context_create, /* XXX */ + + _vg_surface_create_similar, + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + _vg_surface_acquire_source_image, + _vg_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _vg_surface_get_extents, + _vg_surface_get_font_options, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark dirty */ + + _vg_surface_paint, + _vg_surface_mask, + _vg_surface_stroke, + _vg_surface_fill, + NULL, /* fill-stroke */ + _vg_surface_show_glyphs, +}; + +static cairo_surface_t * +_vg_surface_create_internal (cairo_vg_context_t *context, + VGImage image, + VGImageFormat format, + int width, int height) +{ + cairo_vg_surface_t *surface; + + surface = malloc (sizeof (cairo_vg_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface->context = _vg_context_reference (context); + + surface->image = image; + surface->format = format; + + _cairo_surface_init (&surface->base, + &cairo_vg_surface_backend, + NULL, /* device */ + _vg_format_to_content (format)); + + surface->width = width; + surface->height = height; + + _cairo_surface_clipper_init (&surface->clipper, + _vg_surface_clipper_intersect_clip_path); + + surface->snapshot_cache_entry.hash = 0; + + surface->target_id = 0; + + CHECK_VG_ERRORS(); + return &surface->base; +} + +cairo_surface_t * +cairo_vg_surface_create_for_image (cairo_vg_context_t *context, + VGImage image, + VGImageFormat format, + int width, int height) +{ + cairo_bool_t premult; + + if (context->status) + return _cairo_surface_create_in_error (context->status); + + if (image == VG_INVALID_HANDLE) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + if (_vg_format_to_pixman (format, &premult) == 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + + return _vg_surface_create_internal (context, image, format, width, height); +} + +cairo_surface_t * +cairo_vg_surface_create (cairo_vg_context_t *context, + cairo_content_t content, + int width, + int height) +{ + VGImage image; + VGImageFormat format; + cairo_surface_t *surface; + + if (context->status) + return _cairo_surface_create_in_error (context->status); + + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); + + if (width > vgGeti (VG_MAX_IMAGE_WIDTH) || + height > vgGeti (VG_MAX_IMAGE_HEIGHT)) + { + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + } + + + format = _vg_format_for_content (content); + image = vgCreateImage (format, width, height, VG_IMAGE_QUALITY_BETTER); + if (image == VG_INVALID_HANDLE) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface = _vg_surface_create_internal (context, + image, format, width, height); + if (unlikely (surface->status)) + return surface; + + ((cairo_vg_surface_t *) surface)->own_image = TRUE; + return surface; +} +slim_hidden_def (cairo_vg_surface_create); + +VGImage +cairo_vg_surface_get_image (cairo_surface_t *abstract_surface) +{ + cairo_vg_surface_t *surface; + + if (abstract_surface->backend != &cairo_vg_surface_backend) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return VG_INVALID_HANDLE; + } + + surface = (cairo_vg_surface_t *) abstract_surface; + return surface->image; +} + +int +cairo_vg_surface_get_width (cairo_surface_t *abstract_surface) +{ + cairo_vg_surface_t *surface; + + if (abstract_surface->backend != &cairo_vg_surface_backend) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + surface = (cairo_vg_surface_t *) abstract_surface; + return surface->width; +} + +int +cairo_vg_surface_get_height (cairo_surface_t *abstract_surface) +{ + cairo_vg_surface_t *surface; + + if (abstract_surface->backend != &cairo_vg_surface_backend) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + surface = (cairo_vg_surface_t *) abstract_surface; + return surface->height; +} + +VGImageFormat +cairo_vg_surface_get_format (cairo_surface_t *abstract_surface) +{ + cairo_vg_surface_t *surface; + + if (abstract_surface->backend != &cairo_vg_surface_backend) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + surface = (cairo_vg_surface_t *) abstract_surface; + return surface->format; +} + +/* GL specific context support :-( + * + * OpenVG like cairo defers creation of surface (and the necessary + * paraphernalia to the application. + */ + +static const cairo_vg_context_t _vg_context_nil = { + CAIRO_STATUS_NO_MEMORY, + CAIRO_REFERENCE_COUNT_INVALID +}; + +static const cairo_vg_context_t _vg_context_nil_invalid_visual = { + CAIRO_STATUS_INVALID_VISUAL, + CAIRO_REFERENCE_COUNT_INVALID +}; + +#if CAIRO_HAS_GLX_FUNCTIONS +#include + +static cairo_status_t +glx_create_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ + /* XXX hmm, magic required for creating an FBO points to VGImage! */ + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_status_t +glx_set_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ +#if 0 + glXMakeContextCurrent (context->display, + (GLXDrawable) surface->target_id, + (GLXDrawable) surface->target_id, + context->context); +#else + return CAIRO_INT_STATUS_UNSUPPORTED; +#endif +} + +static void +glx_destroy_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ +} + +cairo_vg_context_t * +cairo_vg_context_create_for_glx (Display *dpy, GLXContext ctx) +{ + cairo_vg_context_t *context; + cairo_status_t status; + + context = malloc (sizeof (*context)); + if (unlikely (context == NULL)) + return (cairo_vg_context_t *) &_vg_context_nil; + + context->display = dpy; + context->context = ctx; + + context->create_target = glx_create_target; + context->set_target = glx_set_target; + context->destroy_target = glx_destroy_target; + + status = _vg_context_init (context); + if (unlikely (status)) { + free (context); + return (cairo_vg_context_t *) &_vg_context_nil; + } + + return context; +} +#endif + +#if CAIRO_HAS_EGL_FUNCTIONS +static cairo_status_t +egl_create_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ + EGLSurface *egl_surface; +#define RED 1 +#define GREEN 3 +#define BLUE 5 +#define ALPHA 7 + int attribs[] = { + EGL_RED_SIZE, 0, + EGL_GREEN_SIZE, 0, + EGL_BLUE_SIZE, 0, + EGL_ALPHA_SIZE, 0, + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, + EGL_NONE + }; + pixman_format_code_t pixman_format; + EGLConfig config; + int num_configs = 0; + cairo_bool_t needs_premultiply; + + pixman_format = _vg_format_to_pixman (surface->format, &needs_premultiply); + if (pixman_format == 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* XXX no control over pixel ordering! */ + attribs[RED] = PIXMAN_FORMAT_R (pixman_format); + attribs[GREEN] = PIXMAN_FORMAT_G (pixman_format); + attribs[BLUE] = PIXMAN_FORMAT_B (pixman_format); + attribs[ALPHA] = PIXMAN_FORMAT_A (pixman_format); + + if (! eglChooseConfig (context->display, + attribs, + &config, 1, &num_configs) || + num_configs != 1) + { + fprintf(stderr, "Error: eglChooseConfig() failed.\n"); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + egl_surface = + eglCreatePbufferFromClientBuffer (context->display, + EGL_OPENVG_IMAGE, + (EGLClientBuffer) surface->image, + config, + NULL); + surface->target_id = (unsigned long) egl_surface; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +egl_set_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ + if (! eglMakeCurrent (context->display, + (EGLSurface *) surface->target_id, + (EGLSurface *) surface->target_id, + context->context)) + { + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +egl_destroy_target (cairo_vg_context_t *context, + cairo_vg_surface_t *surface) +{ + eglDestroySurface (context->display, + (EGLSurface *) surface->target_id); +} + +cairo_vg_context_t * +cairo_vg_context_create_for_egl (EGLDisplay egl_display, + EGLContext egl_context) +{ + cairo_vg_context_t *context; + cairo_status_t status; + + context = malloc (sizeof (*context)); + if (unlikely (context == NULL)) + return (cairo_vg_context_t *) &_vg_context_nil; + + status = _vg_context_init (context); + if (unlikely (status)) { + free (context); + return (cairo_vg_context_t *) &_vg_context_nil; + } + + context->display = egl_display; + context->context = egl_context; + + context->create_target = egl_create_target; + context->set_target = egl_set_target; + context->destroy_target = egl_destroy_target; + + return context; +} +#endif + +cairo_status_t +cairo_vg_context_status (cairo_vg_context_t *context) +{ + return context->status; +} + +void +cairo_vg_context_destroy (cairo_vg_context_t *context) +{ + if (context == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&context->ref_count)) + return; + + _vg_context_destroy (context); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-vg.h b/Build/source/libs/cairo/cairo-src/src/cairo-vg.h new file mode 100644 index 00000000000..f9a62e51c69 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-vg.h @@ -0,0 +1,103 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright 2007 * Mozilla Corporation + * Copyright 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Mozilla Corporation. + * + * Contributor(s): + * Vladimir Vukicevic + * Chris Wilson + */ + +#ifndef CAIRO_VG_H +#define CAIRO_VG_H + +#include "cairo.h" + +#if CAIRO_HAS_VG_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +typedef struct _cairo_vg_context cairo_vg_context_t; + +#if CAIRO_HAS_GLX_FUNCTIONS +typedef struct __GLXcontextRec *GLXContext; +typedef struct _XDisplay Display; + +cairo_public cairo_vg_context_t * +cairo_vg_context_create_for_glx (Display *dpy, + GLXContext ctx); +#endif + +#if CAIRO_HAS_EGL_FUNCTIONS +#include + +cairo_public cairo_vg_context_t * +cairo_vg_context_create_for_egl (EGLDisplay egl_display, + EGLContext egl_context); +#endif + +cairo_public cairo_status_t +cairo_vg_context_status (cairo_vg_context_t *context); + +cairo_public void +cairo_vg_context_destroy (cairo_vg_context_t *context); + +cairo_public cairo_surface_t * +cairo_vg_surface_create (cairo_vg_context_t *context, + cairo_content_t content, int width, int height); + +cairo_public cairo_surface_t * +cairo_vg_surface_create_for_image (cairo_vg_context_t *context, + VGImage image, + VGImageFormat format, + int width, int height); + +cairo_public VGImage +cairo_vg_surface_get_image (cairo_surface_t *abstract_surface); + +cairo_public VGImageFormat +cairo_vg_surface_get_format (cairo_surface_t *abstract_surface); + +cairo_public int +cairo_vg_surface_get_height (cairo_surface_t *abstract_surface); + +cairo_public int +cairo_vg_surface_get_width (cairo_surface_t *abstract_surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_VG_SURFACE*/ +# error Cairo was not compiled with support for the OpenVG backend +#endif /* CAIRO_HAS_VG_SURFACE*/ + +#endif /* CAIRO_VG_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-wgl-context.c b/Build/source/libs/cairo/cairo-src/src/cairo-wgl-context.c new file mode 100644 index 00000000000..48723744648 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-wgl-context.c @@ -0,0 +1,261 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Eric Anholt + * Copyright © 2009 Chris Wilson + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + * Chris Wilson + * Zoxc + */ + +#include "cairoint.h" + +#include "cairo-gl-private.h" + +#include "cairo-error-private.h" + +#define WIN32_LEAN_AND_MEAN +#include + +typedef struct _cairo_wgl_context { + cairo_gl_context_t base; + + HDC dummy_dc; + HWND dummy_wnd; + HGLRC rc; + + HDC prev_dc; + HGLRC prev_rc; +} cairo_wgl_context_t; + +typedef struct _cairo_wgl_surface { + cairo_gl_surface_t base; + + HDC dc; +} cairo_wgl_surface_t; + +static void +_wgl_acquire (void *abstract_ctx) +{ + cairo_wgl_context_t *ctx = abstract_ctx; + + HDC current_dc; + + ctx->prev_dc = wglGetCurrentDC (); + ctx->prev_rc = wglGetCurrentContext (); + + if (ctx->base.current_target == NULL || + _cairo_gl_surface_is_texture (ctx->base.current_target)) + { + current_dc = ctx->dummy_dc; + } + else + { + cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) ctx->base.current_target; + current_dc = surface->dc; + } + + if (ctx->prev_dc != current_dc || + (ctx->prev_rc != ctx->rc && + current_dc != ctx->dummy_dc)) + { + wglMakeCurrent (current_dc, ctx->rc); + } +} + +static void +_wgl_make_current (void *abstract_ctx, cairo_gl_surface_t *abstract_surface) +{ + cairo_wgl_context_t *ctx = abstract_ctx; + cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) abstract_surface; + + /* Set the window as the target of our context. */ + wglMakeCurrent (surface->dc, ctx->rc); +} + +static void +_wgl_release (void *abstract_ctx) +{ + cairo_wgl_context_t *ctx = abstract_ctx; + + if (ctx->prev_dc != wglGetCurrentDC () || + ctx->prev_rc != wglGetCurrentContext ()) + { + wglMakeCurrent (ctx->prev_dc, + ctx->prev_rc); + } +} + +static void +_wgl_swap_buffers (void *abstract_ctx, + cairo_gl_surface_t *abstract_surface) +{ + cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) abstract_surface; + + SwapBuffers (surface->dc); +} + +static void +_wgl_destroy (void *abstract_ctx) +{ + cairo_wgl_context_t *ctx = abstract_ctx; + + if (ctx->dummy_dc != 0) { + wglMakeCurrent (ctx->dummy_dc, 0); + ReleaseDC (ctx->dummy_wnd, ctx->dummy_dc); + DestroyWindow (ctx->dummy_wnd); + } +} + +static cairo_status_t +_wgl_dummy_ctx (cairo_wgl_context_t *ctx) +{ + WNDCLASSEXA wincl; + PIXELFORMATDESCRIPTOR pfd; + int format; + HDC dc; + + ZeroMemory (&wincl, sizeof (WNDCLASSEXA)); + wincl.cbSize = sizeof (WNDCLASSEXA); + wincl.hInstance = GetModuleHandle (0); + wincl.lpszClassName = "cairo_wgl_context_dummy"; + wincl.lpfnWndProc = DefWindowProcA; + wincl.style = CS_OWNDC; + + RegisterClassExA (&wincl); + + ctx->dummy_wnd = CreateWindowA ("cairo_wgl_context_dummy", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + ctx->dummy_dc = GetDC (ctx->dummy_wnd); + + ZeroMemory (&pfd, sizeof (PIXELFORMATDESCRIPTOR)); + pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 24; + pfd.cDepthBits = 16; + pfd.iLayerType = PFD_MAIN_PLANE; + + format = ChoosePixelFormat (ctx->dummy_dc, &pfd); + SetPixelFormat (ctx->dummy_dc, format, &pfd); + + wglMakeCurrent(ctx->dummy_dc, ctx->rc); + + return CAIRO_STATUS_SUCCESS; +} + +cairo_device_t * +cairo_wgl_device_create (HGLRC rc) +{ + cairo_wgl_context_t *ctx; + cairo_status_t status; + + ctx = calloc (1, sizeof (cairo_wgl_context_t)); + if (unlikely (ctx == NULL)) + return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); + + ctx->rc = rc; + ctx->prev_dc = 0; + ctx->prev_rc = 0; + + status = _wgl_dummy_ctx (ctx); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + ctx->base.acquire = _wgl_acquire; + ctx->base.release = _wgl_release; + ctx->base.make_current = _wgl_make_current; + ctx->base.swap_buffers = _wgl_swap_buffers; + ctx->base.destroy = _wgl_destroy; + + status = _cairo_gl_dispatch_init (&ctx->base.dispatch, + (cairo_gl_get_proc_addr_func_t) wglGetProcAddress); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + status = _cairo_gl_context_init (&ctx->base); + if (unlikely (status)) { + free (ctx); + return _cairo_gl_context_create_in_error (status); + } + + ctx->base.release (ctx); + + return &ctx->base.base; +} + +HGLRC +cairo_wgl_device_get_context (cairo_device_t *device) +{ + cairo_wgl_context_t *ctx; + + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) { + _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + return NULL; + } + + ctx = (cairo_wgl_context_t *) device; + + return ctx->rc; +} + +cairo_surface_t * +cairo_gl_surface_create_for_dc (cairo_device_t *device, + HDC dc, + int width, + int height) +{ + cairo_wgl_surface_t *surface; + + if (unlikely (device->status)) + return _cairo_surface_create_in_error (device->status); + + if (device->backend->type != CAIRO_DEVICE_TYPE_GL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + + if (width <= 0 || height <= 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + surface = calloc (1, sizeof (cairo_wgl_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_gl_surface_init (device, &surface->base, + CAIRO_CONTENT_COLOR_ALPHA, width, height); + surface->dc = dc; + + return &surface->base.base; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-wideint-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-wideint-private.h new file mode 100644 index 00000000000..3f5491bb1c0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-wideint-private.h @@ -0,0 +1,338 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Keith Packard + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith R. Packard + * + */ + +#ifndef CAIRO_WIDEINT_H +#define CAIRO_WIDEINT_H + +#include "cairo-wideint-type-private.h" + +#include "cairo-compiler-private.h" + +/* + * 64-bit datatypes. Two separate implementations, one using + * built-in 64-bit signed/unsigned types another implemented + * as a pair of 32-bit ints + */ + +#define I cairo_private cairo_const + +#if !HAVE_UINT64_T + +cairo_uquorem64_t I +_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den); + +cairo_uint64_t I _cairo_double_to_uint64 (double i); +double I _cairo_uint64_to_double (cairo_uint64_t i); +cairo_int64_t I _cairo_double_to_int64 (double i); +double I _cairo_int64_to_double (cairo_uint64_t i); + +cairo_uint64_t I _cairo_uint32_to_uint64 (uint32_t i); +#define _cairo_uint64_to_uint32(a) ((a).lo) +cairo_uint64_t I _cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b); +cairo_uint64_t I _cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b); +cairo_uint64_t I _cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b); +cairo_uint64_t I _cairo_uint32x32_64_mul (uint32_t a, uint32_t b); +cairo_uint64_t I _cairo_uint64_lsl (cairo_uint64_t a, int shift); +cairo_uint64_t I _cairo_uint64_rsl (cairo_uint64_t a, int shift); +cairo_uint64_t I _cairo_uint64_rsa (cairo_uint64_t a, int shift); +int I _cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b); +int I _cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b); +int I _cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b); +cairo_uint64_t I _cairo_uint64_negate (cairo_uint64_t a); +#define _cairo_uint64_is_zero(a) ((a).hi == 0 && (a).lo == 0) +#define _cairo_uint64_negative(a) (((int32_t) ((a).hi)) < 0) +cairo_uint64_t I _cairo_uint64_not (cairo_uint64_t a); + +#define _cairo_uint64_to_int64(i) (i) +#define _cairo_int64_to_uint64(i) (i) + +cairo_int64_t I _cairo_int32_to_int64(int32_t i); +#define _cairo_int64_to_int32(a) ((int32_t) _cairo_uint64_to_uint32(a)) +#define _cairo_int64_add(a,b) _cairo_uint64_add (a,b) +#define _cairo_int64_sub(a,b) _cairo_uint64_sub (a,b) +#define _cairo_int64_mul(a,b) _cairo_uint64_mul (a,b) +cairo_int64_t I _cairo_int32x32_64_mul (int32_t a, int32_t b); +int I _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b); +int I _cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b); +#define _cairo_int64_is_zero(a) _cairo_uint64_is_zero (a) +#define _cairo_int64_eq(a,b) _cairo_uint64_eq (a,b) +#define _cairo_int64_lsl(a,b) _cairo_uint64_lsl (a,b) +#define _cairo_int64_rsl(a,b) _cairo_uint64_rsl (a,b) +#define _cairo_int64_rsa(a,b) _cairo_uint64_rsa (a,b) +#define _cairo_int64_negate(a) _cairo_uint64_negate(a) +#define _cairo_int64_negative(a) (((int32_t) ((a).hi)) < 0) +#define _cairo_int64_not(a) _cairo_uint64_not(a) + +#else + +static inline cairo_uquorem64_t +_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den) +{ + cairo_uquorem64_t qr; + + qr.quo = num / den; + qr.rem = num % den; + return qr; +} + +/* + * These need to be functions or gcc will complain when used on the + * result of a function: + * + * warning: cast from function call of type ‘#cairo_uint64_t’ to + * non-matching type ‘double’ + */ +static cairo_always_inline cairo_const cairo_uint64_t _cairo_double_to_uint64 (double i) { return i; } +static cairo_always_inline cairo_const double _cairo_uint64_to_double (cairo_uint64_t i) { return i; } + +static cairo_always_inline cairo_int64_t I _cairo_double_to_int64 (double i) { return i; } +static cairo_always_inline double I _cairo_int64_to_double (cairo_int64_t i) { return i; } + +#define _cairo_uint32_to_uint64(i) ((uint64_t) (i)) +#define _cairo_uint64_to_uint32(i) ((uint32_t) (i)) +#define _cairo_uint64_add(a,b) ((a) + (b)) +#define _cairo_uint64_sub(a,b) ((a) - (b)) +#define _cairo_uint64_mul(a,b) ((a) * (b)) +#define _cairo_uint32x32_64_mul(a,b) ((uint64_t) (a) * (b)) +#define _cairo_uint64_lsl(a,b) ((a) << (b)) +#define _cairo_uint64_rsl(a,b) ((uint64_t) (a) >> (b)) +#define _cairo_uint64_rsa(a,b) ((uint64_t) ((int64_t) (a) >> (b))) +#define _cairo_uint64_lt(a,b) ((a) < (b)) +#define _cairo_uint64_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) +#define _cairo_uint64_is_zero(a) ((a) == 0) +#define _cairo_uint64_eq(a,b) ((a) == (b)) +#define _cairo_uint64_negate(a) ((uint64_t) -((int64_t) (a))) +#define _cairo_uint64_negative(a) ((int64_t) (a) < 0) +#define _cairo_uint64_not(a) (~(a)) + +#define _cairo_uint64_to_int64(i) ((int64_t) (i)) +#define _cairo_int64_to_uint64(i) ((uint64_t) (i)) + +#define _cairo_int32_to_int64(i) ((int64_t) (i)) +#define _cairo_int64_to_int32(i) ((int32_t) (i)) +#define _cairo_int64_add(a,b) ((a) + (b)) +#define _cairo_int64_sub(a,b) ((a) - (b)) +#define _cairo_int64_mul(a,b) ((a) * (b)) +#define _cairo_int32x32_64_mul(a,b) ((int64_t) (a) * (b)) +#define _cairo_int64_lt(a,b) ((a) < (b)) +#define _cairo_int64_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) +#define _cairo_int64_is_zero(a) ((a) == 0) +#define _cairo_int64_eq(a,b) ((a) == (b)) +#define _cairo_int64_lsl(a,b) ((a) << (b)) +#define _cairo_int64_rsl(a,b) ((int64_t) ((uint64_t) (a) >> (b))) +#define _cairo_int64_rsa(a,b) ((int64_t) (a) >> (b)) +#define _cairo_int64_negate(a) (-(a)) +#define _cairo_int64_negative(a) ((a) < 0) +#define _cairo_int64_not(a) (~(a)) + +#endif + +/* + * 64-bit comparisons derived from lt or eq + */ +#define _cairo_uint64_le(a,b) (!_cairo_uint64_gt(a,b)) +#define _cairo_uint64_ne(a,b) (!_cairo_uint64_eq(a,b)) +#define _cairo_uint64_ge(a,b) (!_cairo_uint64_lt(a,b)) +#define _cairo_uint64_gt(a,b) _cairo_uint64_lt(b,a) + +#define _cairo_int64_le(a,b) (!_cairo_int64_gt(a,b)) +#define _cairo_int64_ne(a,b) (!_cairo_int64_eq(a,b)) +#define _cairo_int64_ge(a,b) (!_cairo_int64_lt(a,b)) +#define _cairo_int64_gt(a,b) _cairo_int64_lt(b,a) + +/* + * As the C implementation always computes both, create + * a function which returns both for the 'native' type as well + */ + +static inline cairo_quorem64_t +_cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den) +{ + int num_neg = _cairo_int64_negative (num); + int den_neg = _cairo_int64_negative (den); + cairo_uquorem64_t uqr; + cairo_quorem64_t qr; + + if (num_neg) + num = _cairo_int64_negate (num); + if (den_neg) + den = _cairo_int64_negate (den); + uqr = _cairo_uint64_divrem (num, den); + if (num_neg) + qr.rem = _cairo_int64_negate (uqr.rem); + else + qr.rem = uqr.rem; + if (num_neg != den_neg) + qr.quo = (cairo_int64_t) _cairo_int64_negate (uqr.quo); + else + qr.quo = (cairo_int64_t) uqr.quo; + return qr; +} + +static inline int32_t +_cairo_int64_32_div (cairo_int64_t num, int32_t den) +{ +#if !HAVE_UINT64_T + return _cairo_int64_to_int32 + (_cairo_int64_divrem (num, _cairo_int32_to_int64 (den)).quo); +#else + return num / den; +#endif +} + +/* + * 128-bit datatypes. Again, provide two implementations in + * case the machine has a native 128-bit datatype. GCC supports int128_t + * on ia64 + */ + +#if !HAVE_UINT128_T + +cairo_uint128_t I _cairo_uint32_to_uint128 (uint32_t i); +cairo_uint128_t I _cairo_uint64_to_uint128 (cairo_uint64_t i); +#define _cairo_uint128_to_uint64(a) ((a).lo) +#define _cairo_uint128_to_uint32(a) _cairo_uint64_to_uint32(_cairo_uint128_to_uint64(a)) +cairo_uint128_t I _cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b); +cairo_uint128_t I _cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b); +cairo_uint128_t I _cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b); +cairo_uint128_t I _cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b); +cairo_uint128_t I _cairo_uint128_lsl (cairo_uint128_t a, int shift); +cairo_uint128_t I _cairo_uint128_rsl (cairo_uint128_t a, int shift); +cairo_uint128_t I _cairo_uint128_rsa (cairo_uint128_t a, int shift); +int I _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b); +int I _cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b); +int I _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b); +#define _cairo_uint128_is_zero(a) (_cairo_uint64_is_zero ((a).hi) && _cairo_uint64_is_zero ((a).lo)) +cairo_uint128_t I _cairo_uint128_negate (cairo_uint128_t a); +#define _cairo_uint128_negative(a) (_cairo_uint64_negative(a.hi)) +cairo_uint128_t I _cairo_uint128_not (cairo_uint128_t a); + +#define _cairo_uint128_to_int128(i) (i) +#define _cairo_int128_to_uint128(i) (i) + +cairo_int128_t I _cairo_int32_to_int128 (int32_t i); +cairo_int128_t I _cairo_int64_to_int128 (cairo_int64_t i); +#define _cairo_int128_to_int64(a) ((cairo_int64_t) (a).lo) +#define _cairo_int128_to_int32(a) _cairo_int64_to_int32(_cairo_int128_to_int64(a)) +#define _cairo_int128_add(a,b) _cairo_uint128_add(a,b) +#define _cairo_int128_sub(a,b) _cairo_uint128_sub(a,b) +#define _cairo_int128_mul(a,b) _cairo_uint128_mul(a,b) +cairo_int128_t I _cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b); +#define _cairo_int64x32_128_mul(a, b) _cairo_int64x64_128_mul(a, _cairo_int32_to_int64(b)) +#define _cairo_int128_lsl(a,b) _cairo_uint128_lsl(a,b) +#define _cairo_int128_rsl(a,b) _cairo_uint128_rsl(a,b) +#define _cairo_int128_rsa(a,b) _cairo_uint128_rsa(a,b) +int I _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b); +int I _cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b); +#define _cairo_int128_is_zero(a) _cairo_uint128_is_zero (a) +#define _cairo_int128_eq(a,b) _cairo_uint128_eq (a,b) +#define _cairo_int128_negate(a) _cairo_uint128_negate(a) +#define _cairo_int128_negative(a) (_cairo_uint128_negative(a)) +#define _cairo_int128_not(a) _cairo_uint128_not(a) + +#else /* !HAVE_UINT128_T */ + +#define _cairo_uint32_to_uint128(i) ((uint128_t) (i)) +#define _cairo_uint64_to_uint128(i) ((uint128_t) (i)) +#define _cairo_uint128_to_uint64(i) ((uint64_t) (i)) +#define _cairo_uint128_to_uint32(i) ((uint32_t) (i)) +#define _cairo_uint128_add(a,b) ((a) + (b)) +#define _cairo_uint128_sub(a,b) ((a) - (b)) +#define _cairo_uint128_mul(a,b) ((a) * (b)) +#define _cairo_uint64x64_128_mul(a,b) ((uint128_t) (a) * (b)) +#define _cairo_uint128_lsl(a,b) ((a) << (b)) +#define _cairo_uint128_rsl(a,b) ((uint128_t) (a) >> (b)) +#define _cairo_uint128_rsa(a,b) ((uint128_t) ((int128_t) (a) >> (b))) +#define _cairo_uint128_lt(a,b) ((a) < (b)) +#define _cairo_uint128_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) +#define _cairo_uint128_is_zero(a) ((a) == 0) +#define _cairo_uint128_eq(a,b) ((a) == (b)) +#define _cairo_uint128_negate(a) ((uint128_t) -((int128_t) (a))) +#define _cairo_uint128_negative(a) ((int128_t) (a) < 0) +#define _cairo_uint128_not(a) (~(a)) + +#define _cairo_uint128_to_int128(i) ((int128_t) (i)) +#define _cairo_int128_to_uint128(i) ((uint128_t) (i)) + +#define _cairo_int32_to_int128(i) ((int128_t) (i)) +#define _cairo_int64_to_int128(i) ((int128_t) (i)) +#define _cairo_int128_to_int64(i) ((int64_t) (i)) +#define _cairo_int128_to_int32(i) ((int32_t) (i)) +#define _cairo_int128_add(a,b) ((a) + (b)) +#define _cairo_int128_sub(a,b) ((a) - (b)) +#define _cairo_int128_mul(a,b) ((a) * (b)) +#define _cairo_int64x64_128_mul(a,b) ((int128_t) (a) * (b)) +#define _cairo_int64x32_128_mul(a, b) _cairo_int64x64_128_mul(a, _cairo_int32_to_int64(b)) +#define _cairo_int128_lt(a,b) ((a) < (b)) +#define _cairo_int128_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) +#define _cairo_int128_is_zero(a) ((a) == 0) +#define _cairo_int128_eq(a,b) ((a) == (b)) +#define _cairo_int128_lsl(a,b) ((a) << (b)) +#define _cairo_int128_rsl(a,b) ((int128_t) ((uint128_t) (a) >> (b))) +#define _cairo_int128_rsa(a,b) ((int128_t) (a) >> (b)) +#define _cairo_int128_negate(a) (-(a)) +#define _cairo_int128_negative(a) ((a) < 0) +#define _cairo_int128_not(a) (~(a)) + +#endif /* HAVE_UINT128_T */ + +cairo_uquorem128_t I +_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den); + +cairo_quorem128_t I +_cairo_int128_divrem (cairo_int128_t num, cairo_int128_t den); + +cairo_uquorem64_t I +_cairo_uint_96by64_32x64_divrem (cairo_uint128_t num, + cairo_uint64_t den); + +cairo_quorem64_t I +_cairo_int_96by64_32x64_divrem (cairo_int128_t num, + cairo_int64_t den); + +#define _cairo_uint128_le(a,b) (!_cairo_uint128_gt(a,b)) +#define _cairo_uint128_ne(a,b) (!_cairo_uint128_eq(a,b)) +#define _cairo_uint128_ge(a,b) (!_cairo_uint128_lt(a,b)) +#define _cairo_uint128_gt(a,b) _cairo_uint128_lt(b,a) + +#define _cairo_int128_le(a,b) (!_cairo_int128_gt(a,b)) +#define _cairo_int128_ne(a,b) (!_cairo_int128_eq(a,b)) +#define _cairo_int128_ge(a,b) (!_cairo_int128_lt(a,b)) +#define _cairo_int128_gt(a,b) _cairo_int128_lt(b,a) + +#undef I + +#endif /* CAIRO_WIDEINT_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-wideint-type-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-wideint-type-private.h new file mode 100644 index 00000000000..84a3cbab0d2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-wideint-type-private.h @@ -0,0 +1,158 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Keith Packard + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith R. Packard + * + */ + +#ifndef CAIRO_WIDEINT_TYPE_H +#define CAIRO_WIDEINT_TYPE_H + +#include "cairo.h" + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#if HAVE_STDINT_H +# include +#elif HAVE_INTTYPES_H +# include +#elif HAVE_SYS_INT_TYPES_H +# include +#elif defined(_MSC_VER) + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +# ifndef HAVE_UINT64_T +# define HAVE_UINT64_T 1 +# endif +#else +#error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.) +#endif + +#ifndef INT16_MIN +# define INT16_MIN (-32767-1) +#endif +#ifndef INT16_MAX +# define INT16_MAX (32767) +#endif +#ifndef UINT16_MAX +# define UINT16_MAX (65535) +#endif +#ifndef INT32_MIN +# define INT32_MIN (-2147483647-1) +#endif +#ifndef INT32_MAX +# define INT32_MAX (2147483647) +#endif +#ifndef UINT32_MAX +# define UINT32_MAX (4294967295U) +#endif + +#if HAVE_BYTESWAP_H +# include +#endif +#ifndef bswap_16 +# define bswap_16(p) \ + (((((uint16_t)(p)) & 0x00ff) << 8) | \ + (((uint16_t)(p)) >> 8)); +#endif +#ifndef bswap_32 +# define bswap_32(p) \ + (((((uint32_t)(p)) & 0x000000ff) << 24) | \ + ((((uint32_t)(p)) & 0x0000ff00) << 8) | \ + ((((uint32_t)(p)) & 0x00ff0000) >> 8) | \ + ((((uint32_t)(p))) >> 24)); +#endif + + +#if !HAVE_UINT64_T + +typedef struct _cairo_uint64 { + uint32_t lo, hi; +} cairo_uint64_t, cairo_int64_t; + +#else + +typedef uint64_t cairo_uint64_t; +typedef int64_t cairo_int64_t; + +#endif + +typedef struct _cairo_uquorem64 { + cairo_uint64_t quo; + cairo_uint64_t rem; +} cairo_uquorem64_t; + +typedef struct _cairo_quorem64 { + cairo_int64_t quo; + cairo_int64_t rem; +} cairo_quorem64_t; + +/* gcc has a non-standard name. */ +#if HAVE___UINT128_T && !HAVE_UINT128_T +typedef __uint128_t uint128_t; +typedef __int128_t int128_t; +#define HAVE_UINT128_T 1 +#endif + +#if !HAVE_UINT128_T + +typedef struct cairo_uint128 { + cairo_uint64_t lo, hi; +} cairo_uint128_t, cairo_int128_t; + +#else + +typedef uint128_t cairo_uint128_t; +typedef int128_t cairo_int128_t; + +#endif + +typedef struct _cairo_uquorem128 { + cairo_uint128_t quo; + cairo_uint128_t rem; +} cairo_uquorem128_t; + +typedef struct _cairo_quorem128 { + cairo_int128_t quo; + cairo_int128_t rem; +} cairo_quorem128_t; + + +#endif /* CAIRO_WIDEINT_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-wideint.c b/Build/source/libs/cairo/cairo-src/src/cairo-wideint.c new file mode 100644 index 00000000000..2e056fa36a2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-wideint.c @@ -0,0 +1,852 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2004 Keith Packard + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Keith Packard + * + * Contributor(s): + * Keith R. Packard + */ + +#include "cairoint.h" + +#if HAVE_UINT64_T + +#define uint64_lo32(i) ((i) & 0xffffffff) +#define uint64_hi32(i) ((i) >> 32) +#define uint64_lo(i) ((i) & 0xffffffff) +#define uint64_hi(i) ((i) >> 32) +#define uint64_shift32(i) ((i) << 32) +#define uint64_carry32 (((uint64_t) 1) << 32) + +#define _cairo_uint32s_to_uint64(h,l) ((uint64_t) (h) << 32 | (l)) + +#else + +#define uint64_lo32(i) ((i).lo) +#define uint64_hi32(i) ((i).hi) + +static cairo_uint64_t +uint64_lo (cairo_uint64_t i) +{ + cairo_uint64_t s; + + s.lo = i.lo; + s.hi = 0; + return s; +} + +static cairo_uint64_t +uint64_hi (cairo_uint64_t i) +{ + cairo_uint64_t s; + + s.lo = i.hi; + s.hi = 0; + return s; +} + +static cairo_uint64_t +uint64_shift32 (cairo_uint64_t i) +{ + cairo_uint64_t s; + + s.lo = 0; + s.hi = i.lo; + return s; +} + +static const cairo_uint64_t uint64_carry32 = { 0, 1 }; + +cairo_uint64_t +_cairo_double_to_uint64 (double i) +{ + cairo_uint64_t q; + + q.hi = i * (1. / 4294967296.); + q.lo = i - q.hi * 4294967296.; + return q; +} + +double +_cairo_uint64_to_double (cairo_uint64_t i) +{ + return i.hi * 4294967296. + i.lo; +} + +cairo_int64_t +_cairo_double_to_int64 (double i) +{ + cairo_uint64_t q; + + q.hi = i * (1. / INT32_MAX); + q.lo = i - q.hi * (double)INT32_MAX; + return q; +} + +double +_cairo_int64_to_double (cairo_int64_t i) +{ + return i.hi * INT32_MAX + i.lo; +} + +cairo_uint64_t +_cairo_uint32_to_uint64 (uint32_t i) +{ + cairo_uint64_t q; + + q.lo = i; + q.hi = 0; + return q; +} + +cairo_int64_t +_cairo_int32_to_int64 (int32_t i) +{ + cairo_uint64_t q; + + q.lo = i; + q.hi = i < 0 ? -1 : 0; + return q; +} + +static cairo_uint64_t +_cairo_uint32s_to_uint64 (uint32_t h, uint32_t l) +{ + cairo_uint64_t q; + + q.lo = l; + q.hi = h; + return q; +} + +cairo_uint64_t +_cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b) +{ + cairo_uint64_t s; + + s.hi = a.hi + b.hi; + s.lo = a.lo + b.lo; + if (s.lo < a.lo) + s.hi++; + return s; +} + +cairo_uint64_t +_cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b) +{ + cairo_uint64_t s; + + s.hi = a.hi - b.hi; + s.lo = a.lo - b.lo; + if (s.lo > a.lo) + s.hi--; + return s; +} + +#define uint32_lo(i) ((i) & 0xffff) +#define uint32_hi(i) ((i) >> 16) +#define uint32_carry16 ((1) << 16) + +cairo_uint64_t +_cairo_uint32x32_64_mul (uint32_t a, uint32_t b) +{ + cairo_uint64_t s; + + uint16_t ah, al, bh, bl; + uint32_t r0, r1, r2, r3; + + al = uint32_lo (a); + ah = uint32_hi (a); + bl = uint32_lo (b); + bh = uint32_hi (b); + + r0 = (uint32_t) al * bl; + r1 = (uint32_t) al * bh; + r2 = (uint32_t) ah * bl; + r3 = (uint32_t) ah * bh; + + r1 += uint32_hi(r0); /* no carry possible */ + r1 += r2; /* but this can carry */ + if (r1 < r2) /* check */ + r3 += uint32_carry16; + + s.hi = r3 + uint32_hi(r1); + s.lo = (uint32_lo (r1) << 16) + uint32_lo (r0); + return s; +} + +cairo_int64_t +_cairo_int32x32_64_mul (int32_t a, int32_t b) +{ + cairo_int64_t s; + s = _cairo_uint32x32_64_mul ((uint32_t) a, (uint32_t) b); + if (a < 0) + s.hi -= b; + if (b < 0) + s.hi -= a; + return s; +} + +cairo_uint64_t +_cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b) +{ + cairo_uint64_t s; + + s = _cairo_uint32x32_64_mul (a.lo, b.lo); + s.hi += a.lo * b.hi + a.hi * b.lo; + return s; +} + +cairo_uint64_t +_cairo_uint64_lsl (cairo_uint64_t a, int shift) +{ + if (shift >= 32) + { + a.hi = a.lo; + a.lo = 0; + shift -= 32; + } + if (shift) + { + a.hi = a.hi << shift | a.lo >> (32 - shift); + a.lo = a.lo << shift; + } + return a; +} + +cairo_uint64_t +_cairo_uint64_rsl (cairo_uint64_t a, int shift) +{ + if (shift >= 32) + { + a.lo = a.hi; + a.hi = 0; + shift -= 32; + } + if (shift) + { + a.lo = a.lo >> shift | a.hi << (32 - shift); + a.hi = a.hi >> shift; + } + return a; +} + +#define _cairo_uint32_rsa(a,n) ((uint32_t) (((int32_t) (a)) >> (n))) + +cairo_int64_t +_cairo_uint64_rsa (cairo_int64_t a, int shift) +{ + if (shift >= 32) + { + a.lo = a.hi; + a.hi = _cairo_uint32_rsa (a.hi, 31); + shift -= 32; + } + if (shift) + { + a.lo = a.lo >> shift | a.hi << (32 - shift); + a.hi = _cairo_uint32_rsa (a.hi, shift); + } + return a; +} + +int +_cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b) +{ + return (a.hi < b.hi || + (a.hi == b.hi && a.lo < b.lo)); +} + +int +_cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b) +{ + return a.hi == b.hi && a.lo == b.lo; +} + +int +_cairo_int64_lt (cairo_int64_t a, cairo_int64_t b) +{ + if (_cairo_int64_negative (a) && !_cairo_int64_negative (b)) + return 1; + if (!_cairo_int64_negative (a) && _cairo_int64_negative (b)) + return 0; + return _cairo_uint64_lt (a, b); +} + +int +_cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b) +{ + if (a.hi < b.hi) + return -1; + else if (a.hi > b.hi) + return 1; + else if (a.lo < b.lo) + return -1; + else if (a.lo > b.lo) + return 1; + else + return 0; +} + +int +_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b) +{ + if (_cairo_int64_negative (a) && !_cairo_int64_negative (b)) + return -1; + if (!_cairo_int64_negative (a) && _cairo_int64_negative (b)) + return 1; + + return _cairo_uint64_cmp (a, b); +} + +cairo_uint64_t +_cairo_uint64_not (cairo_uint64_t a) +{ + a.lo = ~a.lo; + a.hi = ~a.hi; + return a; +} + +cairo_uint64_t +_cairo_uint64_negate (cairo_uint64_t a) +{ + a.lo = ~a.lo; + a.hi = ~a.hi; + if (++a.lo == 0) + ++a.hi; + return a; +} + +/* + * Simple bit-at-a-time divide. + */ +cairo_uquorem64_t +_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den) +{ + cairo_uquorem64_t qr; + cairo_uint64_t bit; + cairo_uint64_t quo; + + bit = _cairo_uint32_to_uint64 (1); + + /* normalize to make den >= num, but not overflow */ + while (_cairo_uint64_lt (den, num) && (den.hi & 0x80000000) == 0) + { + bit = _cairo_uint64_lsl (bit, 1); + den = _cairo_uint64_lsl (den, 1); + } + quo = _cairo_uint32_to_uint64 (0); + + /* generate quotient, one bit at a time */ + while (bit.hi | bit.lo) + { + if (_cairo_uint64_le (den, num)) + { + num = _cairo_uint64_sub (num, den); + quo = _cairo_uint64_add (quo, bit); + } + bit = _cairo_uint64_rsl (bit, 1); + den = _cairo_uint64_rsl (den, 1); + } + qr.quo = quo; + qr.rem = num; + return qr; +} + +#endif /* !HAVE_UINT64_T */ + +#if HAVE_UINT128_T +cairo_uquorem128_t +_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den) +{ + cairo_uquorem128_t qr; + + qr.quo = num / den; + qr.rem = num % den; + return qr; +} + +#else + +cairo_uint128_t +_cairo_uint32_to_uint128 (uint32_t i) +{ + cairo_uint128_t q; + + q.lo = _cairo_uint32_to_uint64 (i); + q.hi = _cairo_uint32_to_uint64 (0); + return q; +} + +cairo_int128_t +_cairo_int32_to_int128 (int32_t i) +{ + cairo_int128_t q; + + q.lo = _cairo_int32_to_int64 (i); + q.hi = _cairo_int32_to_int64 (i < 0 ? -1 : 0); + return q; +} + +cairo_uint128_t +_cairo_uint64_to_uint128 (cairo_uint64_t i) +{ + cairo_uint128_t q; + + q.lo = i; + q.hi = _cairo_uint32_to_uint64 (0); + return q; +} + +cairo_int128_t +_cairo_int64_to_int128 (cairo_int64_t i) +{ + cairo_int128_t q; + + q.lo = i; + q.hi = _cairo_int32_to_int64 (_cairo_int64_negative(i) ? -1 : 0); + return q; +} + +cairo_uint128_t +_cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b) +{ + cairo_uint128_t s; + + s.hi = _cairo_uint64_add (a.hi, b.hi); + s.lo = _cairo_uint64_add (a.lo, b.lo); + if (_cairo_uint64_lt (s.lo, a.lo)) + s.hi = _cairo_uint64_add (s.hi, _cairo_uint32_to_uint64 (1)); + return s; +} + +cairo_uint128_t +_cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b) +{ + cairo_uint128_t s; + + s.hi = _cairo_uint64_sub (a.hi, b.hi); + s.lo = _cairo_uint64_sub (a.lo, b.lo); + if (_cairo_uint64_gt (s.lo, a.lo)) + s.hi = _cairo_uint64_sub (s.hi, _cairo_uint32_to_uint64(1)); + return s; +} + +cairo_uint128_t +_cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b) +{ + cairo_uint128_t s; + uint32_t ah, al, bh, bl; + cairo_uint64_t r0, r1, r2, r3; + + al = uint64_lo32 (a); + ah = uint64_hi32 (a); + bl = uint64_lo32 (b); + bh = uint64_hi32 (b); + + r0 = _cairo_uint32x32_64_mul (al, bl); + r1 = _cairo_uint32x32_64_mul (al, bh); + r2 = _cairo_uint32x32_64_mul (ah, bl); + r3 = _cairo_uint32x32_64_mul (ah, bh); + + r1 = _cairo_uint64_add (r1, uint64_hi (r0)); /* no carry possible */ + r1 = _cairo_uint64_add (r1, r2); /* but this can carry */ + if (_cairo_uint64_lt (r1, r2)) /* check */ + r3 = _cairo_uint64_add (r3, uint64_carry32); + + s.hi = _cairo_uint64_add (r3, uint64_hi(r1)); + s.lo = _cairo_uint64_add (uint64_shift32 (r1), + uint64_lo (r0)); + return s; +} + +cairo_int128_t +_cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b) +{ + cairo_int128_t s; + s = _cairo_uint64x64_128_mul (_cairo_int64_to_uint64(a), + _cairo_int64_to_uint64(b)); + if (_cairo_int64_negative (a)) + s.hi = _cairo_uint64_sub (s.hi, + _cairo_int64_to_uint64 (b)); + if (_cairo_int64_negative (b)) + s.hi = _cairo_uint64_sub (s.hi, + _cairo_int64_to_uint64 (a)); + return s; +} + +cairo_uint128_t +_cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b) +{ + cairo_uint128_t s; + + s = _cairo_uint64x64_128_mul (a.lo, b.lo); + s.hi = _cairo_uint64_add (s.hi, + _cairo_uint64_mul (a.lo, b.hi)); + s.hi = _cairo_uint64_add (s.hi, + _cairo_uint64_mul (a.hi, b.lo)); + return s; +} + +cairo_uint128_t +_cairo_uint128_lsl (cairo_uint128_t a, int shift) +{ + if (shift >= 64) + { + a.hi = a.lo; + a.lo = _cairo_uint32_to_uint64 (0); + shift -= 64; + } + if (shift) + { + a.hi = _cairo_uint64_add (_cairo_uint64_lsl (a.hi, shift), + _cairo_uint64_rsl (a.lo, (64 - shift))); + a.lo = _cairo_uint64_lsl (a.lo, shift); + } + return a; +} + +cairo_uint128_t +_cairo_uint128_rsl (cairo_uint128_t a, int shift) +{ + if (shift >= 64) + { + a.lo = a.hi; + a.hi = _cairo_uint32_to_uint64 (0); + shift -= 64; + } + if (shift) + { + a.lo = _cairo_uint64_add (_cairo_uint64_rsl (a.lo, shift), + _cairo_uint64_lsl (a.hi, (64 - shift))); + a.hi = _cairo_uint64_rsl (a.hi, shift); + } + return a; +} + +cairo_uint128_t +_cairo_uint128_rsa (cairo_int128_t a, int shift) +{ + if (shift >= 64) + { + a.lo = a.hi; + a.hi = _cairo_uint64_rsa (a.hi, 64-1); + shift -= 64; + } + if (shift) + { + a.lo = _cairo_uint64_add (_cairo_uint64_rsl (a.lo, shift), + _cairo_uint64_lsl (a.hi, (64 - shift))); + a.hi = _cairo_uint64_rsa (a.hi, shift); + } + return a; +} + +int +_cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b) +{ + return (_cairo_uint64_lt (a.hi, b.hi) || + (_cairo_uint64_eq (a.hi, b.hi) && + _cairo_uint64_lt (a.lo, b.lo))); +} + +int +_cairo_int128_lt (cairo_int128_t a, cairo_int128_t b) +{ + if (_cairo_int128_negative (a) && !_cairo_int128_negative (b)) + return 1; + if (!_cairo_int128_negative (a) && _cairo_int128_negative (b)) + return 0; + return _cairo_uint128_lt (a, b); +} + +int +_cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b) +{ + int cmp; + + cmp = _cairo_uint64_cmp (a.hi, b.hi); + if (cmp) + return cmp; + return _cairo_uint64_cmp (a.lo, b.lo); +} + +int +_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b) +{ + if (_cairo_int128_negative (a) && !_cairo_int128_negative (b)) + return -1; + if (!_cairo_int128_negative (a) && _cairo_int128_negative (b)) + return 1; + + return _cairo_uint128_cmp (a, b); +} + +int +_cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b) +{ + return (_cairo_uint64_eq (a.hi, b.hi) && + _cairo_uint64_eq (a.lo, b.lo)); +} + +#if HAVE_UINT64_T +#define _cairo_msbset64(q) (q & ((uint64_t) 1 << 63)) +#else +#define _cairo_msbset64(q) (q.hi & ((uint32_t) 1 << 31)) +#endif + +cairo_uquorem128_t +_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den) +{ + cairo_uquorem128_t qr; + cairo_uint128_t bit; + cairo_uint128_t quo; + + bit = _cairo_uint32_to_uint128 (1); + + /* normalize to make den >= num, but not overflow */ + while (_cairo_uint128_lt (den, num) && !_cairo_msbset64(den.hi)) + { + bit = _cairo_uint128_lsl (bit, 1); + den = _cairo_uint128_lsl (den, 1); + } + quo = _cairo_uint32_to_uint128 (0); + + /* generate quotient, one bit at a time */ + while (_cairo_uint128_ne (bit, _cairo_uint32_to_uint128(0))) + { + if (_cairo_uint128_le (den, num)) + { + num = _cairo_uint128_sub (num, den); + quo = _cairo_uint128_add (quo, bit); + } + bit = _cairo_uint128_rsl (bit, 1); + den = _cairo_uint128_rsl (den, 1); + } + qr.quo = quo; + qr.rem = num; + return qr; +} + +cairo_uint128_t +_cairo_uint128_negate (cairo_uint128_t a) +{ + a.lo = _cairo_uint64_not (a.lo); + a.hi = _cairo_uint64_not (a.hi); + return _cairo_uint128_add (a, _cairo_uint32_to_uint128 (1)); +} + +cairo_uint128_t +_cairo_uint128_not (cairo_uint128_t a) +{ + a.lo = _cairo_uint64_not (a.lo); + a.hi = _cairo_uint64_not (a.hi); + return a; +} + +#endif /* !HAVE_UINT128_T */ + +cairo_quorem128_t +_cairo_int128_divrem (cairo_int128_t num, cairo_int128_t den) +{ + int num_neg = _cairo_int128_negative (num); + int den_neg = _cairo_int128_negative (den); + cairo_uquorem128_t uqr; + cairo_quorem128_t qr; + + if (num_neg) + num = _cairo_int128_negate (num); + if (den_neg) + den = _cairo_int128_negate (den); + uqr = _cairo_uint128_divrem (num, den); + if (num_neg) + qr.rem = _cairo_int128_negate (uqr.rem); + else + qr.rem = uqr.rem; + if (num_neg != den_neg) + qr.quo = _cairo_int128_negate (uqr.quo); + else + qr.quo = uqr.quo; + return qr; +} + +/** + * _cairo_uint_96by64_32x64_divrem: + * + * Compute a 32 bit quotient and 64 bit remainder of a 96 bit unsigned + * dividend and 64 bit divisor. If the quotient doesn't fit into 32 + * bits then the returned remainder is equal to the divisor, and the + * quotient is the largest representable 64 bit integer. It is an + * error to call this function with the high 32 bits of @num being + * non-zero. + **/ +cairo_uquorem64_t +_cairo_uint_96by64_32x64_divrem (cairo_uint128_t num, + cairo_uint64_t den) +{ + cairo_uquorem64_t result; + cairo_uint64_t B = _cairo_uint32s_to_uint64 (1, 0); + + /* These are the high 64 bits of the *96* bit numerator. We're + * going to represent the numerator as xB + y, where x is a 64, + * and y is a 32 bit number. */ + cairo_uint64_t x = _cairo_uint128_to_uint64 (_cairo_uint128_rsl(num, 32)); + + /* Initialise the result to indicate overflow. */ + result.quo = _cairo_uint32s_to_uint64 (-1U, -1U); + result.rem = den; + + /* Don't bother if the quotient is going to overflow. */ + if (_cairo_uint64_ge (x, den)) { + return /* overflow */ result; + } + + if (_cairo_uint64_lt (x, B)) { + /* When the final quotient is known to fit in 32 bits, then + * num < 2^64 if and only if den < 2^32. */ + return _cairo_uint64_divrem (_cairo_uint128_to_uint64 (num), den); + } + else { + /* Denominator is >= 2^32. the numerator is >= 2^64, and the + * division won't overflow: need two divrems. Write the + * numerator and denominator as + * + * num = xB + y x : 64 bits, y : 32 bits + * den = uB + v u, v : 32 bits + */ + uint32_t y = _cairo_uint128_to_uint32 (num); + uint32_t u = uint64_hi32 (den); + uint32_t v = _cairo_uint64_to_uint32 (den); + + /* Compute a lower bound approximate quotient of num/den + * from x/(u+1). Then we have + * + * x = q(u+1) + r ; q : 32 bits, r <= u : 32 bits. + * + * xB + y = q(u+1)B + (rB+y) + * = q(uB + B + v - v) + (rB+y) + * = q(uB + v) + qB - qv + (rB+y) + * = q(uB + v) + q(B-v) + (rB+y) + * + * The true quotient of num/den then is q plus the + * contribution of q(B-v) + (rB+y). The main contribution + * comes from the term q(B-v), with the term (rB+y) only + * contributing at most one part. + * + * The term q(B-v) must fit into 64 bits, since q fits into 32 + * bits on account of being a lower bound to the true + * quotient, and as B-v <= 2^32, we may safely use a single + * 64/64 bit division to find its contribution. */ + + cairo_uquorem64_t quorem; + cairo_uint64_t remainder; /* will contain final remainder */ + uint32_t quotient; /* will contain final quotient. */ + uint32_t q; + uint32_t r; + + /* Approximate quotient by dividing the high 64 bits of num by + * u+1. Watch out for overflow of u+1. */ + if (u+1) { + quorem = _cairo_uint64_divrem (x, _cairo_uint32_to_uint64 (u+1)); + q = _cairo_uint64_to_uint32 (quorem.quo); + r = _cairo_uint64_to_uint32 (quorem.rem); + } + else { + q = uint64_hi32 (x); + r = _cairo_uint64_to_uint32 (x); + } + quotient = q; + + /* Add the main term's contribution to quotient. Note B-v = + * -v as an uint32 (unless v = 0) */ + if (v) + quorem = _cairo_uint64_divrem (_cairo_uint32x32_64_mul (q, -v), den); + else + quorem = _cairo_uint64_divrem (_cairo_uint32s_to_uint64 (q, 0), den); + quotient += _cairo_uint64_to_uint32 (quorem.quo); + + /* Add the contribution of the subterm and start computing the + * true remainder. */ + remainder = _cairo_uint32s_to_uint64 (r, y); + if (_cairo_uint64_ge (remainder, den)) { + remainder = _cairo_uint64_sub (remainder, den); + quotient++; + } + + /* Add the contribution of the main term's remainder. The + * funky test here checks that remainder + main_rem >= den, + * taking into account overflow of the addition. */ + remainder = _cairo_uint64_add (remainder, quorem.rem); + if (_cairo_uint64_ge (remainder, den) || + _cairo_uint64_lt (remainder, quorem.rem)) + { + remainder = _cairo_uint64_sub (remainder, den); + quotient++; + } + + result.quo = _cairo_uint32_to_uint64 (quotient); + result.rem = remainder; + } + return result; +} + +cairo_quorem64_t +_cairo_int_96by64_32x64_divrem (cairo_int128_t num, cairo_int64_t den) +{ + int num_neg = _cairo_int128_negative (num); + int den_neg = _cairo_int64_negative (den); + cairo_uint64_t nonneg_den; + cairo_uquorem64_t uqr; + cairo_quorem64_t qr; + + if (num_neg) + num = _cairo_int128_negate (num); + if (den_neg) + nonneg_den = _cairo_int64_negate (den); + else + nonneg_den = den; + + uqr = _cairo_uint_96by64_32x64_divrem (num, nonneg_den); + if (_cairo_uint64_eq (uqr.rem, nonneg_den)) { + /* bail on overflow. */ + qr.quo = _cairo_uint32s_to_uint64 (0x7FFFFFFF, -1U); + qr.rem = den; + return qr; + } + + if (num_neg) + qr.rem = _cairo_int64_negate (uqr.rem); + else + qr.rem = uqr.rem; + if (num_neg != den_neg) + qr.quo = _cairo_int64_negate (uqr.quo); + else + qr.quo = uqr.quo; + return qr; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-win32.h b/Build/source/libs/cairo/cairo-src/src/cairo-win32.h new file mode 100644 index 00000000000..3d2e1c60169 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-win32.h @@ -0,0 +1,112 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Owen Taylor + */ + +#ifndef _CAIRO_WIN32_H_ +#define _CAIRO_WIN32_H_ + +#include "cairo.h" + +#if CAIRO_HAS_WIN32_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_win32_surface_create (HDC hdc); + +cairo_public cairo_surface_t * +cairo_win32_printing_surface_create (HDC hdc); + +cairo_public cairo_surface_t * +cairo_win32_surface_create_with_ddb (HDC hdc, + cairo_format_t format, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_win32_surface_create_with_dib (cairo_format_t format, + int width, + int height); + +cairo_public HDC +cairo_win32_surface_get_dc (cairo_surface_t *surface); + +cairo_public cairo_surface_t * +cairo_win32_surface_get_image (cairo_surface_t *surface); + +#if CAIRO_HAS_WIN32_FONT + +/* + * Win32 font support + */ + +cairo_public cairo_font_face_t * +cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont); + +cairo_public cairo_font_face_t * +cairo_win32_font_face_create_for_hfont (HFONT font); + +cairo_public cairo_font_face_t * +cairo_win32_font_face_create_for_logfontw_hfont (LOGFONTW *logfont, HFONT font); + +cairo_public cairo_status_t +cairo_win32_scaled_font_select_font (cairo_scaled_font_t *scaled_font, + HDC hdc); + +cairo_public void +cairo_win32_scaled_font_done_font (cairo_scaled_font_t *scaled_font); + +cairo_public double +cairo_win32_scaled_font_get_metrics_factor (cairo_scaled_font_t *scaled_font); + +cairo_public void +cairo_win32_scaled_font_get_logical_to_device (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *logical_to_device); + +cairo_public void +cairo_win32_scaled_font_get_device_to_logical (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *device_to_logical); + +#endif /* CAIRO_HAS_WIN32_FONT */ + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_WIN32_SURFACE */ +# error Cairo was not compiled with support for the win32 backend +#endif /* CAIRO_HAS_WIN32_SURFACE */ + +#endif /* _CAIRO_WIN32_H_ */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-core.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-core.c new file mode 100644 index 00000000000..e01dc1a8361 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-core.c @@ -0,0 +1,300 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-xcb-private.h" + +#include + +xcb_pixmap_t +_cairo_xcb_connection_create_pixmap (cairo_xcb_connection_t *connection, + uint8_t depth, + xcb_drawable_t drawable, + uint16_t width, + uint16_t height) +{ + xcb_pixmap_t pixmap = _cairo_xcb_connection_get_xid (connection); + + assert (width > 0); + assert (height > 0); + xcb_create_pixmap (connection->xcb_connection, + depth, pixmap, drawable, + width, height); + return pixmap; +} + +void +_cairo_xcb_connection_free_pixmap (cairo_xcb_connection_t *connection, + xcb_pixmap_t pixmap) +{ + xcb_free_pixmap (connection->xcb_connection, pixmap); + _cairo_xcb_connection_put_xid (connection, pixmap); +} + +xcb_gcontext_t +_cairo_xcb_connection_create_gc (cairo_xcb_connection_t *connection, + xcb_drawable_t drawable, + uint32_t value_mask, + uint32_t *values) +{ + xcb_gcontext_t gc = _cairo_xcb_connection_get_xid (connection); + xcb_create_gc (connection->xcb_connection, gc, drawable, + value_mask, values); + return gc; +} + +void +_cairo_xcb_connection_free_gc (cairo_xcb_connection_t *connection, + xcb_gcontext_t gc) +{ + xcb_free_gc (connection->xcb_connection, gc); + _cairo_xcb_connection_put_xid (connection, gc); +} + +void +_cairo_xcb_connection_change_gc (cairo_xcb_connection_t *connection, + xcb_gcontext_t gc, + uint32_t value_mask, + uint32_t *values) +{ + xcb_change_gc (connection->xcb_connection, gc, + value_mask, values); +} + +void +_cairo_xcb_connection_copy_area (cairo_xcb_connection_t *connection, + xcb_drawable_t src, + xcb_drawable_t dst, + xcb_gcontext_t gc, + int16_t src_x, + int16_t src_y, + int16_t dst_x, + int16_t dst_y, + uint16_t width, + uint16_t height) +{ + xcb_copy_area (connection->xcb_connection, src, dst, gc, + src_x, src_y, dst_x, dst_y, width, height); +} + +void +_cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint32_t num_rectangles, + xcb_rectangle_t *rectangles) +{ + xcb_poly_fill_rectangle (connection->xcb_connection, dst, gc, + num_rectangles, rectangles); +} + +void +_cairo_xcb_connection_put_image (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint16_t width, + uint16_t height, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + uint32_t stride, + void *data) +{ + const uint32_t req_size = 18; + uint32_t length = height * stride; + uint32_t len = (req_size + length) >> 2; + + if (len < connection->maximum_request_length) { + xcb_put_image (connection->xcb_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, + dst, gc, width, height, dst_x, dst_y, 0, depth, + length, data); + } else { + int rows = (connection->maximum_request_length - req_size - 4) / stride; + if (rows > 0) { + do { + if (rows > height) + rows = height; + + length = rows * stride; + + xcb_put_image (connection->xcb_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, + dst, gc, width, rows, dst_x, dst_y, 0, depth, length, data); + + height -= rows; + dst_y += rows; + data = (char *) data + length; + } while (height); + } else { + ASSERT_NOT_REACHED; + } + } +} + +static void +_cairo_xcb_connection_do_put_subimage (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + uint16_t cpp, + int stride, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + void *_data) +{ + xcb_protocol_request_t xcb_req = { + 0 /* count */, + 0 /* ext */, + XCB_PUT_IMAGE /* opcode */, + 1 /* isvoid (doesn't cause a reply) */ + }; + xcb_put_image_request_t req; + struct iovec vec_stack[CAIRO_STACK_ARRAY_LENGTH (struct iovec)]; + struct iovec *vec = vec_stack; + uint32_t len = 0; + uint8_t *data = _data; + int n = 3; + /* Two extra entries are needed for xcb, two for us */ + int entries_needed = height + 2 + 2; + + req.format = XCB_IMAGE_FORMAT_Z_PIXMAP; + req.drawable = dst; + req.gc = gc; + req.width = width; + req.height = height; + req.dst_x = dst_x; + req.dst_y = dst_y; + req.left_pad = 0; + req.depth = depth; + req.pad0[0] = 0; + req.pad0[1] = 0; + + if (entries_needed > ARRAY_LENGTH (vec_stack)) { + vec = _cairo_malloc_ab (entries_needed, sizeof (struct iovec)); + if (unlikely (vec == NULL)) { + /* XXX loop over ARRAY_LENGTH (vec_stack) */ + return; + } + } + + data += src_y * stride + src_x * cpp; + /* vec[1] will be used in XCB if it has to use BigRequests or insert a sync, + * vec[0] is used if the internal queue needs to be flushed. */ + vec[2].iov_base = (char *) &req; + vec[2].iov_len = sizeof (req); + + /* Now comes the actual data */ + while (height--) { + vec[n].iov_base = data; + vec[n].iov_len = cpp * width; + len += cpp * width; + data += stride; + n++; + } + + /* And again some padding */ + vec[n].iov_base = 0; + vec[n].iov_len = -len & 3; + n++; + + /* For efficiency reasons, this functions writes the request "directly" to + * the xcb connection to avoid having to copy the data around. */ + assert (n == entries_needed); + xcb_req.count = n - 2; + xcb_send_request (connection->xcb_connection, 0, &vec[2], &xcb_req); + + if (vec != vec_stack) + free (vec); +} + +void +_cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + uint16_t cpp, + int stride, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + void *_data) +{ + const uint32_t req_size = sizeof(xcb_put_image_request_t); + uint32_t length = height * cpp * width; + uint32_t len = (req_size + length) >> 2; + + if (len < connection->maximum_request_length) { + _cairo_xcb_connection_do_put_subimage (connection, dst, gc, src_x, src_y, + width, height, cpp, stride, dst_x, dst_y, depth, _data); + } else { + int rows = (connection->maximum_request_length - req_size - 4) / (cpp * width); + if (rows > 0) { + do { + if (rows > height) + rows = height; + + _cairo_xcb_connection_do_put_subimage (connection, dst, gc, src_x, src_y, + width, rows, cpp, stride, dst_x, dst_y, depth, _data); + + height -= rows; + dst_y += rows; + _data = (char *) _data + stride * rows; + } while (height); + } else { + ASSERT_NOT_REACHED; + } + } +} + +xcb_get_image_reply_t * +_cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection, + xcb_drawable_t src, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height) +{ + return xcb_get_image_reply (connection->xcb_connection, + xcb_get_image (connection->xcb_connection, + XCB_IMAGE_FORMAT_Z_PIXMAP, + src, + src_x, src_y, + width, height, + (uint32_t) -1), + NULL); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-render.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-render.c new file mode 100644 index 00000000000..61119653e9a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-render.c @@ -0,0 +1,299 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-xcb-private.h" + +#include + +void +_cairo_xcb_connection_render_create_picture (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_drawable_t drawable, + xcb_render_pictformat_t format, + uint32_t value_mask, + uint32_t *value_list) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_create_picture (connection->xcb_connection, picture, drawable, + format, value_mask, value_list); +} + +void +_cairo_xcb_connection_render_change_picture (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + uint32_t value_mask, + uint32_t *value_list) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_change_picture (connection->xcb_connection, picture, + value_mask, value_list); +} + +void +_cairo_xcb_connection_render_set_picture_clip_rectangles (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + int16_t clip_x_origin, + int16_t clip_y_origin, + uint32_t rectangles_len, + xcb_rectangle_t *rectangles) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_set_picture_clip_rectangles (connection->xcb_connection, picture, + clip_x_origin, clip_y_origin, + rectangles_len, rectangles); +} + +void +_cairo_xcb_connection_render_free_picture (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_free_picture (connection->xcb_connection, picture); + _cairo_xcb_connection_put_xid (connection, picture); +} + +void +_cairo_xcb_connection_render_composite (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t mask, + xcb_render_picture_t dst, + int16_t src_x, + int16_t src_y, + int16_t mask_x, + int16_t mask_y, + int16_t dst_x, + int16_t dst_y, + uint16_t width, + uint16_t height) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE); + xcb_render_composite (connection->xcb_connection, op, src, mask, dst, + src_x, src_y, mask_x, mask_y, dst_x, dst_y, width, height); +} + +void +_cairo_xcb_connection_render_trapezoids (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + int16_t src_x, + int16_t src_y, + uint32_t traps_len, + xcb_render_trapezoid_t *traps) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS); + xcb_render_trapezoids (connection->xcb_connection, op, src, dst, + mask_format, src_x, src_y, traps_len, traps); +} + +void +_cairo_xcb_connection_render_create_glyph_set (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t id, + xcb_render_pictformat_t format) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_create_glyph_set (connection->xcb_connection, id, format); +} + +void +_cairo_xcb_connection_render_free_glyph_set (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t glyphset) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_free_glyph_set (connection->xcb_connection, glyphset); + _cairo_xcb_connection_put_xid (connection, glyphset); +} + +void +_cairo_xcb_connection_render_add_glyphs (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t glyphset, + uint32_t num_glyphs, + uint32_t *glyphs_id, + xcb_render_glyphinfo_t *glyphs, + uint32_t data_len, + uint8_t *data) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_add_glyphs (connection->xcb_connection, glyphset, num_glyphs, + glyphs_id, glyphs, data_len, data); +} + +void +_cairo_xcb_connection_render_free_glyphs (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t glyphset, + uint32_t num_glyphs, + xcb_render_glyph_t *glyphs) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_free_glyphs (connection->xcb_connection, glyphset, num_glyphs, glyphs); +} + +void +_cairo_xcb_connection_render_composite_glyphs_8 (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t glyphcmds_len, + uint8_t *glyphcmds) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_composite_glyphs_8 (connection->xcb_connection, op, src, dst, mask_format, + glyphset, src_x, src_y, glyphcmds_len, glyphcmds); +} + +void +_cairo_xcb_connection_render_composite_glyphs_16 (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t glyphcmds_len, + uint8_t *glyphcmds) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_composite_glyphs_16 (connection->xcb_connection, op, src, dst, mask_format, + glyphset, src_x, src_y, glyphcmds_len, glyphcmds); +} + +void +_cairo_xcb_connection_render_composite_glyphs_32 (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t glyphcmds_len, + uint8_t *glyphcmds) +{ + assert (connection->flags & CAIRO_XCB_HAS_RENDER); + xcb_render_composite_glyphs_32 (connection->xcb_connection, op, src, dst, mask_format, + glyphset, src_x, src_y, glyphcmds_len, glyphcmds); +} + +void +_cairo_xcb_connection_render_fill_rectangles (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t dst, + xcb_render_color_t color, + uint32_t num_rects, + xcb_rectangle_t *rects) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES); + xcb_render_fill_rectangles (connection->xcb_connection, op, dst, color, + num_rects, rects); +} + +void +_cairo_xcb_connection_render_set_picture_transform (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_transform_t *transform) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM); + xcb_render_set_picture_transform (connection->xcb_connection, picture, *transform); +} + +void +_cairo_xcb_connection_render_set_picture_filter (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + uint16_t filter_len, + char *filter) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_FILTERS); + xcb_render_set_picture_filter (connection->xcb_connection, picture, + filter_len, filter, 0, NULL); +} + +void +_cairo_xcb_connection_render_create_solid_fill (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_color_t color) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); + xcb_render_create_solid_fill (connection->xcb_connection, picture, color); +} + +void +_cairo_xcb_connection_render_create_linear_gradient (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_pointfix_t p1, + xcb_render_pointfix_t p2, + uint32_t num_stops, + xcb_render_fixed_t *stops, + xcb_render_color_t *colors) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); + xcb_render_create_linear_gradient (connection->xcb_connection, picture, + p1, p2, num_stops, stops, colors); +} + +void +_cairo_xcb_connection_render_create_radial_gradient (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_pointfix_t inner, + xcb_render_pointfix_t outer, + xcb_render_fixed_t inner_radius, + xcb_render_fixed_t outer_radius, + uint32_t num_stops, + xcb_render_fixed_t *stops, + xcb_render_color_t *colors) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); + xcb_render_create_radial_gradient (connection->xcb_connection, picture, + inner, outer, inner_radius, outer_radius, + num_stops, stops, colors); +} + +void +_cairo_xcb_connection_render_create_conical_gradient (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_pointfix_t center, + xcb_render_fixed_t angle, + uint32_t num_stops, + xcb_render_fixed_t *stops, + xcb_render_color_t *colors) +{ + assert (connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS); + xcb_render_create_conical_gradient (connection->xcb_connection, picture, + center, angle, num_stops, stops, colors); +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-shm.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-shm.c new file mode 100644 index 00000000000..7720bbbd25b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection-shm.c @@ -0,0 +1,115 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + +#include "cairo-xcb-private.h" + +#include +#include + +uint32_t +_cairo_xcb_connection_shm_attach (cairo_xcb_connection_t *connection, + uint32_t id, + cairo_bool_t readonly) +{ + uint32_t segment = _cairo_xcb_connection_get_xid (connection); + assert (connection->flags & CAIRO_XCB_HAS_SHM); + xcb_shm_attach (connection->xcb_connection, segment, id, readonly); + return segment; +} + +void +_cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint16_t total_width, + uint16_t total_height, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + uint32_t shm, + uint32_t offset) +{ + assert (connection->flags & CAIRO_XCB_HAS_SHM); + xcb_shm_put_image (connection->xcb_connection, dst, gc, total_width, total_height, + src_x, src_y, width, height, dst_x, dst_y, depth, + XCB_IMAGE_FORMAT_Z_PIXMAP, 0, shm, offset); +} + +cairo_status_t +_cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection, + xcb_drawable_t src, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + uint32_t shmseg, + uint32_t offset) +{ + xcb_shm_get_image_reply_t *reply; + + assert (connection->flags & CAIRO_XCB_HAS_SHM); + reply = xcb_shm_get_image_reply (connection->xcb_connection, + xcb_shm_get_image (connection->xcb_connection, + src, + src_x, src_y, + width, height, + (uint32_t) -1, + XCB_IMAGE_FORMAT_Z_PIXMAP, + shmseg, offset), + NULL); + free (reply); + + if (!reply) { + /* an error here should be impossible */ + return _cairo_error (CAIRO_STATUS_READ_ERROR); + } + + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_xcb_connection_shm_detach (cairo_xcb_connection_t *connection, + uint32_t segment) +{ + assert (connection->flags & CAIRO_XCB_HAS_SHM); + xcb_shm_detach (connection->xcb_connection, segment); + _cairo_xcb_connection_put_xid (connection, segment); +} + +#endif /* CAIRO_HAS_XCB_SHM_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection.c new file mode 100644 index 00000000000..67897fa4ecc --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-connection.c @@ -0,0 +1,1006 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Authors: + * Chris Wilson + */ + + +#include "cairoint.h" + +#include "cairo-xcb-private.h" +#include "cairo-hash-private.h" +#include "cairo-freelist-private.h" +#include "cairo-list-inline.h" + +#include +#include +#include + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS +#include +#include +#include +#endif + +typedef struct _cairo_xcb_xrender_format { + cairo_hash_entry_t key; + xcb_render_pictformat_t xrender_format; +} cairo_xcb_xrender_format_t; + +typedef struct _cairo_xcb_xid { + cairo_list_t link; + uint32_t xid; +} cairo_xcb_xid_t; + +#define XCB_RENDER_AT_LEAST(V, major, minor) \ + (((V)->major_version > major) || \ + (((V)->major_version == major) && ((V)->minor_version >= minor))) + +#define XCB_RENDER_HAS_CREATE_PICTURE(surface) XCB_RENDER_AT_LEAST((surface), 0, 0) +#define XCB_RENDER_HAS_COMPOSITE(surface) XCB_RENDER_AT_LEAST((surface), 0, 0) +#define XCB_RENDER_HAS_COMPOSITE_TEXT(surface) XCB_RENDER_AT_LEAST((surface), 0, 0) + +#define XCB_RENDER_HAS_FILL_RECTANGLES(surface) XCB_RENDER_AT_LEAST((surface), 0, 1) + +#define XCB_RENDER_HAS_DISJOINT(surface) XCB_RENDER_AT_LEAST((surface), 0, 2) +#define XCB_RENDER_HAS_CONJOINT(surface) XCB_RENDER_AT_LEAST((surface), 0, 2) + +#define XCB_RENDER_HAS_TRAPEZOIDS(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) +#define XCB_RENDER_HAS_TRIANGLES(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) +#define XCB_RENDER_HAS_TRISTRIP(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) +#define XCB_RENDER_HAS_TRIFAN(surface) XCB_RENDER_AT_LEAST((surface), 0, 4) + +#define XCB_RENDER_HAS_PICTURE_TRANSFORM(surface) XCB_RENDER_AT_LEAST((surface), 0, 6) +#define XCB_RENDER_HAS_FILTERS(surface) XCB_RENDER_AT_LEAST((surface), 0, 6) +#define XCB_RENDER_HAS_FILTER_GOOD(surface) FALSE +#define XCB_RENDER_HAS_FILTER_BEST(surface) FALSE +#define XCB_RENDER_HAS_SUBPIXEL_ORDER(surface) XCB_RENDER_AT_LEAST((surface), 0, 6) + +#define XCB_RENDER_HAS_EXTENDED_REPEAT(surface) XCB_RENDER_AT_LEAST((surface), 0, 10) +#define XCB_RENDER_HAS_GRADIENTS(surface) XCB_RENDER_AT_LEAST((surface), 0, 10) + +#define XCB_RENDER_HAS_PDF_OPERATORS(surface) XCB_RENDER_AT_LEAST((surface), 0, 11) + +static cairo_list_t connections; + +static cairo_status_t +_cairo_xcb_connection_find_visual_formats (cairo_xcb_connection_t *connection, + const xcb_render_query_pict_formats_reply_t *formats) +{ + xcb_render_pictscreen_iterator_t screens; + xcb_render_pictdepth_iterator_t depths; + xcb_render_pictvisual_iterator_t visuals; + + for (screens = xcb_render_query_pict_formats_screens_iterator (formats); + screens.rem; + xcb_render_pictscreen_next (&screens)) + { + for (depths = xcb_render_pictscreen_depths_iterator (screens.data); + depths.rem; + xcb_render_pictdepth_next (&depths)) + { + for (visuals = xcb_render_pictdepth_visuals_iterator (depths.data); + visuals.rem; + xcb_render_pictvisual_next (&visuals)) + { + cairo_xcb_xrender_format_t *f; + cairo_status_t status; + + f = malloc (sizeof (cairo_xcb_xrender_format_t)); + if (unlikely (f == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + f->key.hash = visuals.data->visual; + f->xrender_format = visuals.data->format; + status = _cairo_hash_table_insert (connection->visual_to_xrender_format, + &f->key); + if (unlikely (status)) + return status; + } + } + } + + return CAIRO_STATUS_SUCCESS; +} + +#if 0 +static xcb_format_t * +find_format_for_depth (const xcb_setup_t *setup, uint8_t depth) +{ + xcb_format_t *fmt = xcb_setup_pixmap_formats (setup); + xcb_format_t *fmtend = fmt + xcb_setup_pixmap_formats_length (setup); + + for (; fmt != fmtend; ++fmt) + if (fmt->depth == depth) + return fmt; + + return 0; +} +#endif + +static cairo_status_t +_cairo_xcb_connection_parse_xrender_formats (cairo_xcb_connection_t *connection, + const xcb_render_query_pict_formats_reply_t *formats) +{ + xcb_render_pictforminfo_iterator_t i; + cairo_status_t status; + + for (i = xcb_render_query_pict_formats_formats_iterator (formats); + i.rem; + xcb_render_pictforminfo_next (&i)) + { + cairo_format_masks_t masks; + pixman_format_code_t pixman_format; + + if (i.data->type != XCB_RENDER_PICT_TYPE_DIRECT) + continue; + + masks.alpha_mask = + (unsigned long) i.data->direct.alpha_mask << i.data->direct.alpha_shift; + masks.red_mask = + (unsigned long) i.data->direct.red_mask << i.data->direct.red_shift; + masks.green_mask = + (unsigned long) i.data->direct.green_mask << i.data->direct.green_shift; + masks.blue_mask = + (unsigned long) i.data->direct.blue_mask << i.data->direct.blue_shift; + masks.bpp = i.data->depth; + + if (_pixman_format_from_masks (&masks, &pixman_format)) { + cairo_hash_entry_t key; + + key.hash = pixman_format; + if (! _cairo_hash_table_lookup (connection->xrender_formats, &key)) { + cairo_xcb_xrender_format_t *f; + + f = malloc (sizeof (cairo_xcb_xrender_format_t)); + if (unlikely (f == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + f->key.hash = pixman_format; + f->xrender_format = i.data->id; + status = _cairo_hash_table_insert (connection->xrender_formats, + &f->key); + if (unlikely (status)) + return status; + +#if 0 + printf ("xrender %x -> (%lx, %lx, %lx, %lx, %d) %x [%d, %d]\n", + i.data->id, + masks.alpha_mask, + masks.red_mask, + masks.green_mask, + masks.blue_mask, + masks.bpp, + pixman_format, + PIXMAN_FORMAT_DEPTH(pixman_format), + PIXMAN_FORMAT_BPP(pixman_format)); +#endif + } + } + } + + status = _cairo_xcb_connection_find_visual_formats (connection, formats); + if (unlikely (status)) + return status; + + connection->standard_formats[CAIRO_FORMAT_A1] = + _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a1); + + connection->standard_formats[CAIRO_FORMAT_A8] = + _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a8); + + connection->standard_formats[CAIRO_FORMAT_RGB24] = + _cairo_xcb_connection_get_xrender_format (connection, + PIXMAN_FORMAT (24, + PIXMAN_TYPE_ARGB, + 0, 8, 8, 8)); + if (connection->standard_formats[CAIRO_FORMAT_RGB24] == XCB_NONE) { + connection->standard_formats[CAIRO_FORMAT_RGB24] = + _cairo_xcb_connection_get_xrender_format (connection, + PIXMAN_FORMAT (24, PIXMAN_TYPE_ABGR, + 0, 8, 8, 8)); + } + + connection->standard_formats[CAIRO_FORMAT_ARGB32] = + _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a8r8g8b8); + if (connection->standard_formats[CAIRO_FORMAT_ARGB32] == XCB_NONE) { + connection->standard_formats[CAIRO_FORMAT_ARGB32] = + _cairo_xcb_connection_get_xrender_format (connection, PIXMAN_a8b8g8r8); + } + + return CAIRO_STATUS_SUCCESS; +} + +/* + * We require support for depth 1, 8, 24 and 32 pixmaps + */ +#define DEPTH_MASK(d) (1 << ((d) - 1)) +#define REQUIRED_DEPTHS (DEPTH_MASK(1) | \ + DEPTH_MASK(8) | \ + DEPTH_MASK(24) | \ + DEPTH_MASK(32)) +static cairo_bool_t +pixmap_depths_usable (cairo_xcb_connection_t *connection, + uint32_t missing, + xcb_drawable_t root) +{ + xcb_connection_t *c = connection->xcb_connection; + xcb_void_cookie_t create_cookie[32]; + xcb_pixmap_t pixmap; + cairo_bool_t success = TRUE; + int depth, i, j; + + pixmap = _cairo_xcb_connection_get_xid (connection); + + for (depth = 1, i = 0; depth <= 32; depth++) { + if (missing & DEPTH_MASK(depth)) { + create_cookie[i] = xcb_create_pixmap_checked (c, depth, pixmap, root, 1, 1); + xcb_free_pixmap (c, pixmap); + if (!create_cookie[i].sequence) { + success = FALSE; + break; + } + i++; + } + } + + for (j = 0; j < i; j++) { + xcb_generic_error_t *create_error = xcb_request_check (c, create_cookie[j]); + success &= create_error == NULL; + free (create_error); + } + + _cairo_xcb_connection_put_xid (connection, pixmap); + + return success; +} + +static cairo_bool_t +has_required_depths (cairo_xcb_connection_t *connection) +{ + xcb_screen_iterator_t screens; + + for (screens = xcb_setup_roots_iterator (connection->root); + screens.rem; + xcb_screen_next (&screens)) + { + xcb_depth_iterator_t depths; + uint32_t missing = REQUIRED_DEPTHS; + + for (depths = xcb_screen_allowed_depths_iterator (screens.data); + depths.rem; + xcb_depth_next (&depths)) + { + missing &= ~DEPTH_MASK (depths.data->depth); + } + if (missing == 0) + continue; + + /* + * Ok, this is ugly. It should be sufficient at this + * point to just return false, but Xinerama is broken at + * this point and only advertises depths which have an + * associated visual. Of course, the other depths still + * work, but the only way to find out is to try them. + */ + if (! pixmap_depths_usable (connection, missing, screens.data->root)) + return FALSE; + } + + return TRUE; +} + +static xcb_render_query_version_reply_t * +_render_restrict_env(xcb_render_query_version_reply_t *version) +{ + const char *env; + + if (version == NULL) + return NULL; + + env = getenv ("CAIRO_DEBUG"); + if (env != NULL) + env = strstr (env, "xrender-version="); + if (env != NULL) { + int max_render_major, max_render_minor; + + env += sizeof ("xrender-version=") - 1; + if (sscanf (env, "%d.%d", &max_render_major, &max_render_minor) != 2) + max_render_major = max_render_minor = -1; + + if (max_render_major < 0 || max_render_minor < 0) { + free (version); + return NULL; + } + + if (max_render_major < (int) version->major_version || + (max_render_major == (int) version->major_version && + max_render_minor < (int) version->minor_version)) + { + version->major_version = max_render_major; + version->minor_version = max_render_minor; + } + } + + return version; +} + +static cairo_status_t +_cairo_xcb_connection_query_render (cairo_xcb_connection_t *connection) +{ + xcb_connection_t *c = connection->xcb_connection; + xcb_render_query_version_cookie_t version_cookie; + xcb_render_query_pict_formats_cookie_t formats_cookie; + xcb_render_query_version_reply_t *version; + xcb_render_query_pict_formats_reply_t *formats; + cairo_status_t status; + cairo_bool_t present; + + version_cookie = xcb_render_query_version (c, XCB_RENDER_MAJOR_VERSION, XCB_RENDER_MINOR_VERSION); + formats_cookie = xcb_render_query_pict_formats (c); + + present = has_required_depths (connection); + version = xcb_render_query_version_reply (c, version_cookie, 0); + formats = xcb_render_query_pict_formats_reply (c, formats_cookie, 0); + + version = _render_restrict_env (version); + + if (! present || version == NULL || formats == NULL) { + free (version); + free (formats); + return CAIRO_STATUS_SUCCESS; + } + + /* always true if the extension is present (i.e. >= 0.0) */ + connection->flags |= CAIRO_XCB_HAS_RENDER; + connection->flags |= CAIRO_XCB_RENDER_HAS_COMPOSITE; + connection->flags |= CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS; + + if (XCB_RENDER_HAS_FILL_RECTANGLES (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES; + + if (XCB_RENDER_HAS_TRAPEZOIDS (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS; + + if (XCB_RENDER_HAS_PICTURE_TRANSFORM (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM; + + if (XCB_RENDER_HAS_FILTERS (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_FILTERS; + + if (XCB_RENDER_HAS_FILTER_GOOD (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_FILTER_GOOD; + + if (XCB_RENDER_HAS_FILTER_BEST (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_FILTER_BEST; + + if (XCB_RENDER_HAS_PDF_OPERATORS (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_PDF_OPERATORS; + + if (XCB_RENDER_HAS_EXTENDED_REPEAT (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT; + + if (XCB_RENDER_HAS_GRADIENTS (version)) + connection->flags |= CAIRO_XCB_RENDER_HAS_GRADIENTS; + + if (XCB_RENDER_HAS_SUBPIXEL_ORDER (version)) { + uint32_t screen; + uint32_t *subpixel = xcb_render_query_pict_formats_subpixels(formats); + + /* The spec explicitly allows to have too few entries in the reply... */ + for (screen = 0; screen < formats->num_subpixel && screen < connection->root->roots_len; screen++) + connection->subpixel_orders[screen] = subpixel[screen]; + } + + free (version); + + status = _cairo_xcb_connection_parse_xrender_formats (connection, formats); + free (formats); + + return status; +} + +#if 0 +static void +_cairo_xcb_connection_query_cairo (cairo_xcb_connection_t *connection) +{ + xcb_connection_t *c = connection->xcb_connection; + xcb_cairo_query_version_reply_t *version; + + version = xcb_cairo_query_version_reply (c, + xcb_cairo_query_version (c, 0, 0), + 0); + + free (version); +} +#endif + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS +static cairo_bool_t +can_use_shm (cairo_xcb_connection_t *connection) +{ + cairo_bool_t success = TRUE; + xcb_connection_t *c = connection->xcb_connection; + xcb_void_cookie_t cookie[2]; + xcb_generic_error_t *error; + int shmid; + uint32_t shmseg; + void *ptr; + + shmid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | 0600); + if (shmid == -1) + return FALSE; + + ptr = shmat (shmid, NULL, 0); + if (ptr == (char *) -1) { + shmctl (shmid, IPC_RMID, NULL); + return FALSE; + } + + shmseg = _cairo_xcb_connection_get_xid (connection); + cookie[0] = xcb_shm_attach_checked (c, shmseg, shmid, FALSE); + cookie[1] = xcb_shm_detach_checked (c, shmseg); + _cairo_xcb_connection_put_xid (connection, shmseg); + + error = xcb_request_check (c, cookie[0]); + if (error != NULL) + success = FALSE; + + error = xcb_request_check (c, cookie[1]); + if (error != NULL) + success = FALSE; + + shmctl (shmid, IPC_RMID, NULL); + shmdt (ptr); + + return success; +} + +static void +_cairo_xcb_connection_query_shm (cairo_xcb_connection_t *connection) +{ + xcb_connection_t *c = connection->xcb_connection; + xcb_shm_query_version_reply_t *version; + + version = xcb_shm_query_version_reply (c, xcb_shm_query_version (c), 0); + if (version == NULL) + return; + + free (version); + + if (can_use_shm (connection)) + connection->flags |= CAIRO_XCB_HAS_SHM; +} +#endif + +static cairo_status_t +_device_flush (void *device) +{ + cairo_xcb_connection_t *connection = device; + cairo_status_t status; + + status = cairo_device_acquire (&connection->device); + if (unlikely (status)) + return status; + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + _cairo_xcb_connection_shm_mem_pools_flush (connection); +#endif + + xcb_flush (connection->xcb_connection); + + cairo_device_release (&connection->device); + return CAIRO_STATUS_SUCCESS; +} + +static void +_pluck_xrender_format (void *entry, + void *closure) +{ + _cairo_hash_table_remove (closure, entry); + free (entry); +} + +static void +_device_finish (void *device) +{ + cairo_xcb_connection_t *connection = device; + cairo_bool_t was_cached = FALSE; + + if (! cairo_list_is_empty (&connection->link)) { + CAIRO_MUTEX_LOCK (_cairo_xcb_connections_mutex); + cairo_list_del (&connection->link); + CAIRO_MUTEX_UNLOCK (_cairo_xcb_connections_mutex); + was_cached = TRUE; + } + + while (! cairo_list_is_empty (&connection->fonts)) { + cairo_xcb_font_t *font; + + font = cairo_list_first_entry (&connection->fonts, + cairo_xcb_font_t, + link); + _cairo_xcb_font_close (font); + } + + while (! cairo_list_is_empty (&connection->screens)) { + cairo_xcb_screen_t *screen; + + screen = cairo_list_first_entry (&connection->screens, + cairo_xcb_screen_t, + link); + _cairo_xcb_screen_finish (screen); + } + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + /* _cairo_xcb_screen_finish finishes surfaces. If any of those surfaces had + * a fallback image, we might have done a SHM PutImage. */ + _cairo_xcb_connection_shm_mem_pools_flush (connection); +#endif + + if (was_cached) + cairo_device_destroy (device); +} + +static void +_device_destroy (void *device) +{ + cairo_xcb_connection_t *connection = device; + + _cairo_hash_table_foreach (connection->xrender_formats, + _pluck_xrender_format, connection->xrender_formats); + _cairo_hash_table_destroy (connection->xrender_formats); + + _cairo_hash_table_foreach (connection->visual_to_xrender_format, + _pluck_xrender_format, + connection->visual_to_xrender_format); + _cairo_hash_table_destroy (connection->visual_to_xrender_format); + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + _cairo_xcb_connection_shm_mem_pools_fini (connection); +#endif + _cairo_freepool_fini (&connection->shm_info_freelist); + + _cairo_freepool_fini (&connection->xid_pool); + + CAIRO_MUTEX_FINI (connection->shm_mutex); + CAIRO_MUTEX_FINI (connection->screens_mutex); + + free (connection->subpixel_orders); + free (connection); +} + +static const cairo_device_backend_t _cairo_xcb_device_backend = { + CAIRO_DEVICE_TYPE_XCB, + + NULL, NULL, /* lock, unlock */ + + _device_flush, + _device_finish, + _device_destroy, +}; + +cairo_xcb_connection_t * +_cairo_xcb_connection_get (xcb_connection_t *xcb_connection) +{ + cairo_xcb_connection_t *connection; + const xcb_query_extension_reply_t *ext; + cairo_status_t status; + + CAIRO_MUTEX_INITIALIZE (); + + CAIRO_MUTEX_LOCK (_cairo_xcb_connections_mutex); + if (connections.next == NULL) { + /* XXX _cairo_init () */ + cairo_list_init (&connections); + } + + cairo_list_foreach_entry (connection, + cairo_xcb_connection_t, + &connections, + link) + { + if (connection->xcb_connection == xcb_connection) { + /* Maintain MRU order. */ + if (connections.next != &connection->link) + cairo_list_move (&connection->link, &connections); + + goto unlock; + } + } + + connection = malloc (sizeof (cairo_xcb_connection_t)); + if (unlikely (connection == NULL)) + goto unlock; + + _cairo_device_init (&connection->device, &_cairo_xcb_device_backend); + + connection->xcb_connection = xcb_connection; + + cairo_list_init (&connection->fonts); + cairo_list_init (&connection->screens); + cairo_list_init (&connection->link); + connection->xrender_formats = _cairo_hash_table_create (NULL); + if (connection->xrender_formats == NULL) { + CAIRO_MUTEX_FINI (connection->device.mutex); + free (connection); + connection = NULL; + goto unlock; + } + + connection->visual_to_xrender_format = _cairo_hash_table_create (NULL); + if (connection->visual_to_xrender_format == NULL) { + _cairo_hash_table_destroy (connection->xrender_formats); + CAIRO_MUTEX_FINI (connection->device.mutex); + free (connection); + connection = NULL; + goto unlock; + } + + cairo_list_init (&connection->free_xids); + _cairo_freepool_init (&connection->xid_pool, + sizeof (cairo_xcb_xid_t)); + + cairo_list_init (&connection->shm_pools); + cairo_list_init (&connection->shm_pending); + _cairo_freepool_init (&connection->shm_info_freelist, + sizeof (cairo_xcb_shm_info_t)); + + connection->maximum_request_length = + xcb_get_maximum_request_length (xcb_connection); + + CAIRO_MUTEX_INIT (connection->shm_mutex); + CAIRO_MUTEX_INIT (connection->screens_mutex); + + CAIRO_MUTEX_LOCK (connection->device.mutex); + + connection->flags = 0; + connection->force_precision = -1; + + xcb_prefetch_extension_data (xcb_connection, &xcb_big_requests_id); + xcb_prefetch_extension_data (xcb_connection, &xcb_render_id); +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + xcb_prefetch_extension_data (xcb_connection, &xcb_shm_id); +#endif +#if 0 + xcb_prefetch_extension_data (xcb_connection, &xcb_cairo_id); +#endif + + xcb_prefetch_maximum_request_length (xcb_connection); + + connection->root = xcb_get_setup (xcb_connection); + connection->render = NULL; + connection->subpixel_orders = calloc (connection->root->roots_len, sizeof(*connection->subpixel_orders)); + if (unlikely (connection->subpixel_orders == NULL)) { + CAIRO_MUTEX_UNLOCK (connection->device.mutex); + _cairo_xcb_connection_destroy (connection); + connection = NULL; + goto unlock; + } + + ext = xcb_get_extension_data (xcb_connection, &xcb_render_id); + if (ext != NULL && ext->present) { + status = _cairo_xcb_connection_query_render (connection); + if (unlikely (status)) { + CAIRO_MUTEX_UNLOCK (connection->device.mutex); + _cairo_xcb_connection_destroy (connection); + connection = NULL; + goto unlock; + } + + connection->render = ext; + } + +#if 0 + ext = xcb_get_extension_data (connection, &xcb_cairo_id); + if (ext != NULL && ext->present) + _cairo_xcb_connection_query_cairo (connection); +#endif + + connection->shm = NULL; +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + ext = xcb_get_extension_data (xcb_connection, &xcb_shm_id); + if (ext != NULL && ext->present) { + _cairo_xcb_connection_query_shm (connection); + connection->shm = ext; + } +#endif + + connection->original_flags = connection->flags; + + CAIRO_MUTEX_UNLOCK (connection->device.mutex); + + cairo_list_add (&connection->link, &connections); +unlock: + CAIRO_MUTEX_UNLOCK (_cairo_xcb_connections_mutex); + + return connection; +} + +xcb_render_pictformat_t +_cairo_xcb_connection_get_xrender_format (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format) +{ + cairo_hash_entry_t key; + cairo_xcb_xrender_format_t *format; + + key.hash = pixman_format; + format = _cairo_hash_table_lookup (connection->xrender_formats, &key); + return format ? format->xrender_format : XCB_NONE; +} + +xcb_render_pictformat_t +_cairo_xcb_connection_get_xrender_format_for_visual (cairo_xcb_connection_t *connection, + const xcb_visualid_t visual) +{ + cairo_hash_entry_t key; + cairo_xcb_xrender_format_t *format; + + key.hash = visual; + format = _cairo_hash_table_lookup (connection->visual_to_xrender_format, &key); + return format ? format->xrender_format : XCB_NONE; +} + +void +_cairo_xcb_connection_put_xid (cairo_xcb_connection_t *connection, + uint32_t xid) +{ + cairo_xcb_xid_t *cache; + + assert (CAIRO_MUTEX_IS_LOCKED (connection->device.mutex)); + cache = _cairo_freepool_alloc (&connection->xid_pool); + if (likely (cache != NULL)) { + cache->xid = xid; + cairo_list_add (&cache->link, &connection->free_xids); + } +} + +uint32_t +_cairo_xcb_connection_get_xid (cairo_xcb_connection_t *connection) +{ + uint32_t xid; + + assert (CAIRO_MUTEX_IS_LOCKED (connection->device.mutex)); + if (! cairo_list_is_empty (&connection->free_xids)) { + cairo_xcb_xid_t *cache; + + cache = cairo_list_first_entry (&connection->free_xids, + cairo_xcb_xid_t, + link); + xid = cache->xid; + + cairo_list_del (&cache->link); + _cairo_freepool_free (&connection->xid_pool, cache); + } else { + xid = xcb_generate_id (connection->xcb_connection); + } + + return xid; +} + +/** + * cairo_xcb_device_get_connection: + * @device: a #cairo_device_t for the XCB backend + * + * Get the connection for the XCB device. + * + * Returns: the #xcb_connection_t for the connection + * + * Since: 1.12 + **/ +xcb_connection_t * +cairo_xcb_device_get_connection (cairo_device_t *device) +{ + if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) + return NULL; + + return ((cairo_xcb_connection_t *)device)->xcb_connection; +} + +/* public (debug) interface */ + +/** + * cairo_xcb_device_debug_cap_xshm_version: + * @device: a #cairo_device_t for the XCB backend + * @major_version: major version to restrict to + * @minor_version: minor version to restrict to + * + * Restricts all future XCB surfaces for this devices to the specified version + * of the SHM extension. This function exists solely for debugging purpose. + * It let's you find out how cairo would behave with an older version of + * the SHM extension. + * + * Use the special values -1 and -1 for disabling the SHM extension. + * + * Since: 1.12 + **/ +void +cairo_xcb_device_debug_cap_xshm_version (cairo_device_t *device, + int major_version, + int minor_version) +{ + cairo_xcb_connection_t *connection = (cairo_xcb_connection_t *) device; + + if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return; + } + + /* First reset all the SHM flags to their original value. This works + * because we only ever clear bits after the connection was created. + */ + connection->flags |= (connection->original_flags & CAIRO_XCB_SHM_MASK); + + /* clear any flags that are inappropriate for the desired version */ + if (major_version < 0 && minor_version < 0) { + connection->flags &= ~(CAIRO_XCB_HAS_SHM); + } +} + +/** + * cairo_xcb_device_debug_cap_xrender_version: + * @device: a #cairo_device_t for the XCB backend + * @major_version: major version to restrict to + * @minor_version: minor version to restrict to + * + * Restricts all future XCB surfaces for this devices to the specified version + * of the RENDER extension. This function exists solely for debugging purpose. + * It let's you find out how cairo would behave with an older version of + * the RENDER extension. + * + * Use the special values -1 and -1 for disabling the RENDER extension. + * + * Since: 1.12 + **/ +void +cairo_xcb_device_debug_cap_xrender_version (cairo_device_t *device, + int major_version, + int minor_version) +{ + cairo_xcb_connection_t *connection = (cairo_xcb_connection_t *) device; + + if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return; + } + + /* First reset all the RENDER flags to their original value. This works + * because we only ever clear bits after the connection was created. + */ + connection->flags |= (connection->original_flags & CAIRO_XCB_RENDER_MASK); + + /* clear any flags that are inappropriate for the desired version */ + if (major_version < 0 && minor_version < 0) { + connection->flags &= ~(CAIRO_XCB_HAS_RENDER | + CAIRO_XCB_RENDER_HAS_COMPOSITE | + CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS | + CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES | + CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | + CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM | + CAIRO_XCB_RENDER_HAS_FILTERS | + CAIRO_XCB_RENDER_HAS_FILTER_GOOD | + CAIRO_XCB_RENDER_HAS_FILTER_BEST | + CAIRO_XCB_RENDER_HAS_PDF_OPERATORS | + CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT | + CAIRO_XCB_RENDER_HAS_GRADIENTS); + } else { + xcb_render_query_version_reply_t version; + + version.major_version = major_version; + version.minor_version = minor_version; + + if (! XCB_RENDER_HAS_FILL_RECTANGLES (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES; + + if (! XCB_RENDER_HAS_TRAPEZOIDS (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS; + + if (! XCB_RENDER_HAS_PICTURE_TRANSFORM (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM; + + if (! XCB_RENDER_HAS_FILTERS (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_FILTERS; + + if (! XCB_RENDER_HAS_PDF_OPERATORS (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_PDF_OPERATORS; + + if (! XCB_RENDER_HAS_EXTENDED_REPEAT (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT; + + if (! XCB_RENDER_HAS_GRADIENTS (&version)) + connection->flags &= ~CAIRO_XCB_RENDER_HAS_GRADIENTS; + } +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_device_debug_cap_xrender_version); +#endif + +/** + * cairo_xcb_device_debug_set_precision: + * @device: a #cairo_device_t for the XCB backend + * @precision: the precision to use + * + * Render supports two modes of precision when rendering trapezoids. Set + * the precision to the desired mode. + * + * Since: 1.12 + **/ +void +cairo_xcb_device_debug_set_precision (cairo_device_t *device, + int precision) +{ + if (device == NULL || device->status) + return; + if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return; + } + + ((cairo_xcb_connection_t *) device)->force_precision = precision; +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_device_debug_set_precision); +#endif + +/** + * cairo_xcb_device_debug_get_precision: + * @device: a #cairo_device_t for the XCB backend + * + * Get the Xrender precision mode. + * + * Returns: the render precision mode + * + * Since: 1.12 + **/ +int +cairo_xcb_device_debug_get_precision (cairo_device_t *device) +{ + if (device == NULL || device->status) + return -1; + if (device->backend->type != CAIRO_DEVICE_TYPE_XCB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return -1; + } + + return ((cairo_xcb_connection_t *) device)->force_precision; +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_device_debug_get_precision); +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-private.h new file mode 100644 index 00000000000..f5d5a4c81c7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-private.h @@ -0,0 +1,801 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributors(s): + * Chris Wilson + */ + +#ifndef CAIRO_XCB_PRIVATE_H +#define CAIRO_XCB_PRIVATE_H + +#include "cairoint.h" + +#include "cairo-xcb.h" + +#include "cairo-cache-private.h" +#include "cairo-compiler-private.h" +#include "cairo-device-private.h" +#include "cairo-error-private.h" +#include "cairo-freelist-private.h" +#include "cairo-list-private.h" +#include "cairo-mutex-private.h" +#include "cairo-pattern-private.h" +#include "cairo-reference-count-private.h" +#include "cairo-scaled-font-private.h" +#include "cairo-spans-private.h" +#include "cairo-surface-private.h" + +#include +#include +#include +#include + +#define XLIB_COORD_MAX 32767 + +/* maximum number of cached GC's */ +#define GC_CACHE_SIZE 4 + +#define CAIRO_XCB_RENDER_AT_LEAST(major, minor) \ + ((XCB_RENDER_MAJOR_VERSION > major) || \ + ((XCB_RENDER_MAJOR_VERSION == major) && (XCB_RENDER_MINOR_VERSION >= minor))) + +typedef struct _cairo_xcb_connection cairo_xcb_connection_t; +typedef struct _cairo_xcb_font cairo_xcb_font_t; +typedef struct _cairo_xcb_screen cairo_xcb_screen_t; +typedef struct _cairo_xcb_surface cairo_xcb_surface_t; +typedef struct _cairo_xcb_picture cairo_xcb_picture_t; +typedef struct _cairo_xcb_shm_mem_pool cairo_xcb_shm_mem_pool_t; +typedef struct _cairo_xcb_shm_info cairo_xcb_shm_info_t; +typedef struct _cairo_xcb_resources cairo_xcb_resources_t; + +struct _cairo_xcb_shm_info { + cairo_xcb_connection_t *connection; + uint32_t shm; + uint32_t offset; + size_t size; + void *mem; + cairo_xcb_shm_mem_pool_t *pool; + xcb_get_input_focus_cookie_t sync; + cairo_list_t pending; +}; + +struct _cairo_xcb_surface { + cairo_surface_t base; + cairo_image_surface_t *fallback; + cairo_boxes_t fallback_damage; + + cairo_xcb_connection_t *connection; + cairo_xcb_screen_t *screen; + + xcb_drawable_t drawable; + cairo_bool_t owns_pixmap; + + cairo_bool_t deferred_clear; + cairo_color_t deferred_clear_color; + + int width; + int height; + int depth; + + xcb_render_picture_t picture; + xcb_render_pictformat_t xrender_format; + pixman_format_code_t pixman_format; + uint32_t precision; + + cairo_list_t link; +}; + +struct _cairo_xcb_picture { + cairo_surface_t base; + + cairo_xcb_screen_t *screen; + xcb_render_picture_t picture; + xcb_render_pictformat_t xrender_format; + pixman_format_code_t pixman_format; + + int width, height; + + cairo_extend_t extend; + cairo_filter_t filter; + cairo_bool_t has_component_alpha; + xcb_render_transform_t transform; + + int x0, y0; + int x, y; + + cairo_list_t link; +}; + +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +typedef struct _cairo_xlib_xcb_surface { + cairo_surface_t base; + + cairo_xcb_surface_t *xcb; + + /* original settings for query */ + void *display; + void *screen; + void *visual; + void *format; +} cairo_xlib_xcb_surface_t; +#endif + + +enum { + GLYPHSET_INDEX_ARGB32, + GLYPHSET_INDEX_A8, + GLYPHSET_INDEX_A1, + NUM_GLYPHSETS +}; + +typedef struct _cairo_xcb_font_glyphset_free_glyphs { + xcb_render_glyphset_t glyphset; + int glyph_count; + xcb_render_glyph_t glyph_indices[128]; +} cairo_xcb_font_glyphset_free_glyphs_t; + +typedef struct _cairo_xcb_font_glyphset_info { + xcb_render_glyphset_t glyphset; + cairo_format_t format; + xcb_render_pictformat_t xrender_format; + cairo_xcb_font_glyphset_free_glyphs_t *pending_free_glyphs; +} cairo_xcb_font_glyphset_info_t; + +struct _cairo_xcb_font { + cairo_scaled_font_private_t base; + cairo_scaled_font_t *scaled_font; + cairo_xcb_connection_t *connection; + cairo_xcb_font_glyphset_info_t glyphset_info[NUM_GLYPHSETS]; + cairo_list_t link; +}; + +struct _cairo_xcb_screen { + cairo_xcb_connection_t *connection; + + xcb_screen_t *xcb_screen; + xcb_render_sub_pixel_t subpixel_order; + + xcb_gcontext_t gc[GC_CACHE_SIZE]; + uint8_t gc_depths[GC_CACHE_SIZE]; + + cairo_surface_t *stock_colors[CAIRO_STOCK_NUM_COLORS]; + struct { + cairo_surface_t *picture; + cairo_color_t color; + } solid_cache[16]; + int solid_cache_size; + + cairo_cache_t linear_pattern_cache; + cairo_cache_t radial_pattern_cache; + cairo_freelist_t pattern_cache_entry_freelist; + + cairo_list_t link; + cairo_list_t surfaces; + cairo_list_t pictures; + + cairo_bool_t has_font_options; + cairo_font_options_t font_options; +}; + +struct _cairo_xcb_connection { + cairo_device_t device; + + xcb_connection_t *xcb_connection; + + xcb_render_pictformat_t standard_formats[5]; + cairo_hash_table_t *xrender_formats; + cairo_hash_table_t *visual_to_xrender_format; + + unsigned int maximum_request_length; + unsigned int flags; + unsigned int original_flags; + + int force_precision; + + const xcb_setup_t *root; + const xcb_query_extension_reply_t *render; + const xcb_query_extension_reply_t *shm; + xcb_render_sub_pixel_t *subpixel_orders; + + cairo_list_t free_xids; + cairo_freepool_t xid_pool; + + cairo_mutex_t shm_mutex; + cairo_list_t shm_pools; + cairo_list_t shm_pending; + cairo_freepool_t shm_info_freelist; + + cairo_mutex_t screens_mutex; + cairo_list_t screens; + + cairo_list_t fonts; + + cairo_list_t link; +}; + +struct _cairo_xcb_resources { + cairo_bool_t xft_antialias; + int xft_lcdfilter; + cairo_bool_t xft_hinting; + int xft_hintstyle; + int xft_rgba; +}; + +enum { + CAIRO_XCB_HAS_RENDER = 0x0001, + CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES = 0x0002, + CAIRO_XCB_RENDER_HAS_COMPOSITE = 0x0004, + CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS = 0x0008, + CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS = 0x0010, + CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM = 0x0020, + CAIRO_XCB_RENDER_HAS_FILTERS = 0x0040, + CAIRO_XCB_RENDER_HAS_PDF_OPERATORS = 0x0080, + CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT = 0x0100, + CAIRO_XCB_RENDER_HAS_GRADIENTS = 0x0200, + CAIRO_XCB_RENDER_HAS_FILTER_GOOD = 0x0400, + CAIRO_XCB_RENDER_HAS_FILTER_BEST = 0x0800, + + CAIRO_XCB_HAS_SHM = 0x80000000, + + CAIRO_XCB_RENDER_MASK = CAIRO_XCB_HAS_RENDER | + CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES | + CAIRO_XCB_RENDER_HAS_COMPOSITE | + CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | + CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS | + CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM | + CAIRO_XCB_RENDER_HAS_FILTERS | + CAIRO_XCB_RENDER_HAS_PDF_OPERATORS | + CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT | + CAIRO_XCB_RENDER_HAS_GRADIENTS | + CAIRO_XCB_RENDER_HAS_FILTER_GOOD | + CAIRO_XCB_RENDER_HAS_FILTER_BEST, + CAIRO_XCB_SHM_MASK = CAIRO_XCB_HAS_SHM +}; + +#define CAIRO_XCB_SHM_SMALL_IMAGE 8192 + +cairo_private extern const cairo_surface_backend_t _cairo_xcb_surface_backend; + +/** + * _cairo_surface_is_xcb: + * @surface: a #cairo_surface_t + * + * Checks if a surface is an #cairo_xcb_surface_t + * + * Return value: %TRUE if the surface is an xcb surface + **/ +static inline cairo_bool_t +_cairo_surface_is_xcb (const cairo_surface_t *surface) +{ + /* _cairo_surface_nil sets a NULL backend so be safe */ + return surface->backend && surface->backend->type == CAIRO_SURFACE_TYPE_XCB; +} + +cairo_private cairo_xcb_connection_t * +_cairo_xcb_connection_get (xcb_connection_t *connection); + +static inline cairo_xcb_connection_t * +_cairo_xcb_connection_reference (cairo_xcb_connection_t *connection) +{ + return (cairo_xcb_connection_t *) cairo_device_reference (&connection->device); +} + +cairo_private xcb_render_pictformat_t +_cairo_xcb_connection_get_xrender_format (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format); + +cairo_private xcb_render_pictformat_t +_cairo_xcb_connection_get_xrender_format_for_visual (cairo_xcb_connection_t *connection, + const xcb_visualid_t visual); + +static inline cairo_status_t cairo_warn +_cairo_xcb_connection_acquire (cairo_xcb_connection_t *connection) +{ + return cairo_device_acquire (&connection->device); +} + +cairo_private uint32_t +_cairo_xcb_connection_get_xid (cairo_xcb_connection_t *connection); + +cairo_private void +_cairo_xcb_connection_put_xid (cairo_xcb_connection_t *connection, + uint32_t xid); + +static inline void +_cairo_xcb_connection_release (cairo_xcb_connection_t *connection) +{ + cairo_device_release (&connection->device); +} + +static inline void +_cairo_xcb_connection_destroy (cairo_xcb_connection_t *connection) +{ + cairo_device_destroy (&connection->device); +} + +cairo_private cairo_int_status_t +_cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *display, + size_t size, + cairo_bool_t might_reuse, + cairo_xcb_shm_info_t **shm_info_out); + +cairo_private void +_cairo_xcb_shm_info_destroy (cairo_xcb_shm_info_t *shm_info); + +cairo_private void +_cairo_xcb_connection_shm_mem_pools_flush (cairo_xcb_connection_t *connection); + +cairo_private void +_cairo_xcb_connection_shm_mem_pools_fini (cairo_xcb_connection_t *connection); + +cairo_private void +_cairo_xcb_font_close (cairo_xcb_font_t *font); + +cairo_private cairo_xcb_screen_t * +_cairo_xcb_screen_get (xcb_connection_t *connection, + xcb_screen_t *screen); + +cairo_private void +_cairo_xcb_screen_finish (cairo_xcb_screen_t *screen); + +cairo_private xcb_gcontext_t +_cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen, + xcb_drawable_t drawable, + int depth); + +cairo_private void +_cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t gc); + +cairo_private cairo_font_options_t * +_cairo_xcb_screen_get_font_options (cairo_xcb_screen_t *screen); + +cairo_private cairo_status_t +_cairo_xcb_screen_store_linear_picture (cairo_xcb_screen_t *screen, + const cairo_linear_pattern_t *linear, + cairo_surface_t *picture); + +cairo_private cairo_surface_t * +_cairo_xcb_screen_lookup_linear_picture (cairo_xcb_screen_t *screen, + const cairo_linear_pattern_t *linear); + +cairo_private cairo_status_t +_cairo_xcb_screen_store_radial_picture (cairo_xcb_screen_t *screen, + const cairo_radial_pattern_t *radial, + cairo_surface_t *picture); + +cairo_private cairo_surface_t * +_cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen, + const cairo_radial_pattern_t *radial); + +cairo_private cairo_surface_t * +_cairo_xcb_surface_create_similar_image (void *abstrct_other, + cairo_format_t format, + int width, + int height); + +cairo_private cairo_surface_t * +_cairo_xcb_surface_create_similar (void *abstract_other, + cairo_content_t content, + int width, + int height); + +cairo_private cairo_surface_t * +_cairo_xcb_surface_create_internal (cairo_xcb_screen_t *screen, + xcb_drawable_t drawable, + cairo_bool_t owns_pixmap, + pixman_format_code_t pixman_format, + xcb_render_pictformat_t xrender_format, + int width, + int height); + +cairo_private_no_warn cairo_bool_t +_cairo_xcb_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents); + +cairo_private cairo_int_status_t +_cairo_xcb_render_compositor_paint (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents); + +cairo_private cairo_int_status_t +_cairo_xcb_render_compositor_mask (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents); + +cairo_private cairo_int_status_t +_cairo_xcb_render_compositor_stroke (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias); + +cairo_private cairo_int_status_t +_cairo_xcb_render_compositor_fill (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias); + +cairo_private cairo_int_status_t +_cairo_xcb_render_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap); +cairo_private void +_cairo_xcb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font); + +cairo_private void +_cairo_xcb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font); + +cairo_private cairo_status_t +_cairo_xcb_surface_clear (cairo_xcb_surface_t *dst); + +cairo_private cairo_status_t +_cairo_xcb_surface_core_copy_boxes (cairo_xcb_surface_t *dst, + const cairo_pattern_t *src_pattern, + const cairo_rectangle_int_t *extents, + const cairo_boxes_t *boxes); + +cairo_private cairo_status_t +_cairo_xcb_surface_core_fill_boxes (cairo_xcb_surface_t *dst, + const cairo_color_t *color, + cairo_boxes_t *boxes); + +cairo_private xcb_pixmap_t +_cairo_xcb_connection_create_pixmap (cairo_xcb_connection_t *connection, + uint8_t depth, + xcb_drawable_t drawable, + uint16_t width, + uint16_t height); + +cairo_private void +_cairo_xcb_connection_free_pixmap (cairo_xcb_connection_t *connection, + xcb_pixmap_t pixmap); + +cairo_private xcb_gcontext_t +_cairo_xcb_connection_create_gc (cairo_xcb_connection_t *connection, + xcb_drawable_t drawable, + uint32_t value_mask, + uint32_t *values); + +cairo_private void +_cairo_xcb_connection_free_gc (cairo_xcb_connection_t *connection, + xcb_gcontext_t gc); + +cairo_private void +_cairo_xcb_connection_change_gc (cairo_xcb_connection_t *connection, + xcb_gcontext_t gc, + uint32_t value_mask, + uint32_t *values); + +cairo_private void +_cairo_xcb_connection_copy_area (cairo_xcb_connection_t *connection, + xcb_drawable_t src, + xcb_drawable_t dst, + xcb_gcontext_t gc, + int16_t src_x, + int16_t src_y, + int16_t dst_x, + int16_t dst_y, + uint16_t width, + uint16_t height); + +cairo_private void +_cairo_xcb_connection_put_image (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint16_t width, + uint16_t height, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + uint32_t length, + void *data); + +cairo_private void +_cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + uint16_t cpp, + int stride, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + void *data); + +cairo_private xcb_get_image_reply_t * +_cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection, + xcb_drawable_t src, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height); + +cairo_private void +_cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint32_t num_rectangles, + xcb_rectangle_t *rectangles); + +cairo_private cairo_status_t +_cairo_xcb_shm_image_create (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format, + int width, int height, + cairo_image_surface_t **image_out, + cairo_xcb_shm_info_t **shm_info_out); + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS +cairo_private uint32_t +_cairo_xcb_connection_shm_attach (cairo_xcb_connection_t *connection, + uint32_t id, + cairo_bool_t readonly); + +cairo_private void +_cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint16_t total_width, + uint16_t total_height, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + uint32_t shm, + uint32_t offset); + +cairo_private cairo_status_t +_cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection, + xcb_drawable_t src, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + uint32_t shmseg, + uint32_t offset); + +cairo_private void +_cairo_xcb_connection_shm_detach (cairo_xcb_connection_t *connection, + uint32_t segment); +#else +static inline void +_cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection, + xcb_drawable_t dst, + xcb_gcontext_t gc, + uint16_t total_width, + uint16_t total_height, + int16_t src_x, + int16_t src_y, + uint16_t width, + uint16_t height, + int16_t dst_x, + int16_t dst_y, + uint8_t depth, + uint32_t shm, + uint32_t offset) +{ + ASSERT_NOT_REACHED; +} +#endif + +cairo_private void +_cairo_xcb_connection_render_create_picture (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_drawable_t drawable, + xcb_render_pictformat_t format, + uint32_t value_mask, + uint32_t *value_list); + +cairo_private void +_cairo_xcb_connection_render_change_picture (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + uint32_t value_mask, + uint32_t *value_list); + +cairo_private void +_cairo_xcb_connection_render_set_picture_clip_rectangles (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + int16_t clip_x_origin, + int16_t clip_y_origin, + uint32_t rectangles_len, + xcb_rectangle_t *rectangles); + +cairo_private void +_cairo_xcb_connection_render_free_picture (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture); + +cairo_private void +_cairo_xcb_connection_render_composite (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t mask, + xcb_render_picture_t dst, + int16_t src_x, + int16_t src_y, + int16_t mask_x, + int16_t mask_y, + int16_t dst_x, + int16_t dst_y, + uint16_t width, + uint16_t height); + +cairo_private void +_cairo_xcb_connection_render_trapezoids (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + int16_t src_x, + int16_t src_y, + uint32_t traps_len, + xcb_render_trapezoid_t *traps); + +cairo_private void +_cairo_xcb_connection_render_create_glyph_set (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t id, + xcb_render_pictformat_t format); + +cairo_private void +_cairo_xcb_connection_render_free_glyph_set (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t glyphset); + +cairo_private void +_cairo_xcb_connection_render_add_glyphs (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t glyphset, + uint32_t num_glyphs, + uint32_t *glyphs_id, + xcb_render_glyphinfo_t *glyphs, + uint32_t data_len, + uint8_t *data); + +cairo_private void +_cairo_xcb_connection_render_free_glyphs (cairo_xcb_connection_t *connection, + xcb_render_glyphset_t glyphset, + uint32_t num_glyphs, + xcb_render_glyph_t *glyphs); + +cairo_private void +_cairo_xcb_connection_render_composite_glyphs_8 (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t glyphcmds_len, + uint8_t *glyphcmds); + +cairo_private void +_cairo_xcb_connection_render_composite_glyphs_16 (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t glyphcmds_len, + uint8_t *glyphcmds); + +cairo_private void +_cairo_xcb_connection_render_composite_glyphs_32 (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t glyphcmds_len, + uint8_t *glyphcmds); + +cairo_private void +_cairo_xcb_connection_render_fill_rectangles (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t dst, + xcb_render_color_t color, + uint32_t num_rects, + xcb_rectangle_t *rects); + +cairo_private void +_cairo_xcb_connection_render_set_picture_transform (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_transform_t *transform); + +cairo_private void +_cairo_xcb_connection_render_set_picture_filter (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + uint16_t filter_len, + char *filter); + +cairo_private void +_cairo_xcb_connection_render_create_solid_fill (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_color_t color); + +cairo_private void +_cairo_xcb_connection_render_create_linear_gradient (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_pointfix_t p1, + xcb_render_pointfix_t p2, + uint32_t num_stops, + xcb_render_fixed_t *stops, + xcb_render_color_t *colors); + +cairo_private void +_cairo_xcb_connection_render_create_radial_gradient (cairo_xcb_connection_t *connection, + xcb_render_picture_t picture, + xcb_render_pointfix_t inner, + xcb_render_pointfix_t outer, + xcb_render_fixed_t inner_radius, + xcb_render_fixed_t outer_radius, + uint32_t num_stops, + xcb_render_fixed_t *stops, + xcb_render_color_t *colors); + +cairo_private void +_cairo_xcb_connection_render_create_conical_gradient (cairo_xcb_connection_t *c, + xcb_render_picture_t picture, + xcb_render_pointfix_t center, + xcb_render_fixed_t angle, + uint32_t num_stops, + xcb_render_fixed_t *stops, + xcb_render_color_t *colors); +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_proto (cairo_xcb_surface_create); +slim_hidden_proto (cairo_xcb_surface_create_for_bitmap); +slim_hidden_proto (cairo_xcb_surface_create_with_xrender_format); +slim_hidden_proto (cairo_xcb_surface_set_size); +slim_hidden_proto (cairo_xcb_surface_set_drawable); +slim_hidden_proto (cairo_xcb_device_debug_get_precision); +slim_hidden_proto_no_warn (cairo_xcb_device_debug_set_precision); +slim_hidden_proto_no_warn (cairo_xcb_device_debug_cap_xrender_version); +#endif + +cairo_private void +_cairo_xcb_resources_get (cairo_xcb_screen_t *screen, + cairo_xcb_resources_t *resources); + +#endif /* CAIRO_XCB_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-resources.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-resources.c new file mode 100644 index 00000000000..1877758c25a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-resources.c @@ -0,0 +1,281 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2014 Lukas Lalinsky + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Authors: + * Lukas Lalinsky + * + * Partially on code from xftdpy.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "cairoint.h" + +#include "cairo-xcb-private.h" + +#include "cairo-fontconfig-private.h" + +static void +parse_boolean (const char *v, cairo_bool_t *out) +{ + char c0, c1; + + c0 = *v; + if (c0 == 't' || c0 == 'T' || c0 == 'y' || c0 == 'Y' || c0 == '1') + *out = TRUE; + if (c0 == 'f' || c0 == 'F' || c0 == 'n' || c0 == 'N' || c0 == '0') + *out = FALSE; + if (c0 == 'o') { + c1 = v[1]; + if (c1 == 'n' || c1 == 'N') + *out = TRUE; + if (c1 == 'f' || c1 == 'F') + *out = FALSE; + } +} + +static void +parse_integer (const char *v, int *out) +{ + char *e; + int value; + +#if CAIRO_HAS_FC_FONT + if (FcNameConstant ((FcChar8 *) v, out)) + return; +#endif + + value = strtol (v, &e, 0); + if (e != v) + *out = value; +} + +static char * +skip_spaces(char *str) +{ + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + return str; +} + +struct resource_parser { + int buffer_size; + int bytes_in_buffer; + char* buffer; + cairo_xcb_resources_t *resources; +}; + +static cairo_bool_t +resource_parse_line (char *name, cairo_xcb_resources_t *resources) +{ + char *value; + + value = strchr (name, ':'); + if (value == NULL) + return FALSE; + + *value++ = 0; + + name = skip_spaces (name); + value = skip_spaces (value); + + if (strcmp (name, "Xft.antialias") == 0) + parse_boolean (value, &(resources->xft_antialias)); + else if (strcmp (name, "Xft.lcdfilter") == 0) + parse_integer (value, &(resources->xft_lcdfilter)); + else if (strcmp (name, "Xft.rgba") == 0) + parse_integer (value, &(resources->xft_rgba)); + else if (strcmp (name, "Xft.hinting") == 0) + parse_boolean (value, &(resources->xft_hinting)); + else if (strcmp (name, "Xft.hintstyle") == 0) + parse_integer (value, &(resources->xft_hintstyle)); + + return TRUE; +} + +static int +resource_parse_lines (struct resource_parser *parser) +{ + char *line, *newline; + + line = parser->buffer; + while (1) { + newline = strchr (line, '\n'); + if (newline == NULL) + break; + + *newline++ = 0; + + if (! resource_parse_line (line, parser->resources)) + break; + + line = newline; + } + + return line - parser->buffer; +} + +static void +resource_parser_init (struct resource_parser *parser, cairo_xcb_resources_t *resources) +{ + parser->buffer_size = 0; + parser->bytes_in_buffer = 0; + parser->buffer = NULL; + parser->resources = resources; +} + +static cairo_bool_t +resource_parser_update (struct resource_parser *parser, const char *data, int length) +{ + int bytes_parsed; + + if (parser->bytes_in_buffer + length + 1 > parser->buffer_size) { + parser->buffer_size = parser->bytes_in_buffer + length + 1; + parser->buffer = realloc(parser->buffer, parser->buffer_size); + if (! parser->buffer) { + parser->buffer_size = 0; + parser->bytes_in_buffer = 0; + return FALSE; + } + } + + memmove (parser->buffer + parser->bytes_in_buffer, data, length); + parser->bytes_in_buffer += length; + parser->buffer[parser->bytes_in_buffer] = 0; + + bytes_parsed = resource_parse_lines (parser); + + if (parser->bytes_in_buffer > bytes_parsed) { + memmove (parser->buffer, parser->buffer + bytes_parsed, parser->bytes_in_buffer - bytes_parsed); + parser->bytes_in_buffer -= bytes_parsed; + } else { + parser->bytes_in_buffer = 0; + } + + return TRUE; +} + +static void +resource_parser_done (struct resource_parser *parser) +{ + if (parser->bytes_in_buffer > 0) { + parser->buffer[parser->bytes_in_buffer] = 0; + resource_parse_line (parser->buffer, parser->resources); + } + + free (parser->buffer); +} + +static void +get_resources(xcb_connection_t *connection, xcb_screen_t *screen, cairo_xcb_resources_t *resources) +{ + xcb_get_property_cookie_t cookie; + xcb_get_property_reply_t *reply; + struct resource_parser parser; + int offset; + cairo_bool_t has_more_data; + + resources->xft_antialias = TRUE; + resources->xft_lcdfilter = -1; + resources->xft_hinting = TRUE; + resources->xft_hintstyle = FC_HINT_FULL; + resources->xft_rgba = FC_RGBA_UNKNOWN; + + resource_parser_init (&parser, resources); + + offset = 0; + has_more_data = FALSE; + do { + cookie = xcb_get_property (connection, 0, screen->root, XCB_ATOM_RESOURCE_MANAGER, XCB_ATOM_STRING, offset, 1024); + reply = xcb_get_property_reply (connection, cookie, NULL); + + if (reply) { + if (reply->format == 8 && reply->type == XCB_ATOM_STRING) { + char *value = (char *) xcb_get_property_value (reply); + int length = xcb_get_property_value_length (reply); + + offset += length / 4; /* X needs the offset in 'long' units */ + has_more_data = reply->bytes_after > 0; + + if (! resource_parser_update (&parser, value, length)) + has_more_data = FALSE; /* early exit on error */ + } + + free (reply); + } + } while (has_more_data); + + resource_parser_done (&parser); +} + +void +_cairo_xcb_resources_get (cairo_xcb_screen_t *screen, cairo_xcb_resources_t *resources) +{ + get_resources (screen->connection->xcb_connection, screen->xcb_screen, resources); + + if (resources->xft_rgba == FC_RGBA_UNKNOWN) { + switch (screen->subpixel_order) { + case XCB_RENDER_SUB_PIXEL_UNKNOWN: + resources->xft_rgba = FC_RGBA_UNKNOWN; + break; + case XCB_RENDER_SUB_PIXEL_HORIZONTAL_RGB: + resources->xft_rgba = FC_RGBA_RGB; + break; + case XCB_RENDER_SUB_PIXEL_HORIZONTAL_BGR: + resources->xft_rgba = FC_RGBA_BGR; + break; + case XCB_RENDER_SUB_PIXEL_VERTICAL_RGB: + resources->xft_rgba = FC_RGBA_VRGB; + break; + case XCB_RENDER_SUB_PIXEL_VERTICAL_BGR: + resources->xft_rgba = FC_RGBA_VBGR; + break; + case XCB_RENDER_SUB_PIXEL_NONE: + resources->xft_rgba = FC_RGBA_NONE; + break; + } + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-screen.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-screen.c new file mode 100644 index 00000000000..d0019f9cdff --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-screen.c @@ -0,0 +1,494 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Chris Wilson + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Authors: + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-xcb-private.h" +#include "cairo-list-inline.h" + +#include "cairo-fontconfig-private.h" + +static void +_cairo_xcb_init_screen_font_options (cairo_xcb_screen_t *screen) +{ + cairo_xcb_resources_t res; + cairo_antialias_t antialias; + cairo_subpixel_order_t subpixel_order; + cairo_lcd_filter_t lcd_filter; + cairo_hint_style_t hint_style; + + _cairo_xcb_resources_get (screen, &res); + + /* the rest of the code in this function is copied from + _cairo_xlib_init_screen_font_options in cairo-xlib-screen.c */ + + if (res.xft_hinting) { + switch (res.xft_hintstyle) { + case FC_HINT_NONE: + hint_style = CAIRO_HINT_STYLE_NONE; + break; + case FC_HINT_SLIGHT: + hint_style = CAIRO_HINT_STYLE_SLIGHT; + break; + case FC_HINT_MEDIUM: + hint_style = CAIRO_HINT_STYLE_MEDIUM; + break; + case FC_HINT_FULL: + hint_style = CAIRO_HINT_STYLE_FULL; + break; + default: + hint_style = CAIRO_HINT_STYLE_DEFAULT; + } + } else { + hint_style = CAIRO_HINT_STYLE_NONE; + } + + switch (res.xft_rgba) { + case FC_RGBA_RGB: + subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; + break; + case FC_RGBA_BGR: + subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; + break; + case FC_RGBA_VRGB: + subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; + break; + case FC_RGBA_VBGR: + subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; + break; + case FC_RGBA_UNKNOWN: + case FC_RGBA_NONE: + default: + subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + } + + switch (res.xft_lcdfilter) { + case FC_LCD_NONE: + lcd_filter = CAIRO_LCD_FILTER_NONE; + break; + case FC_LCD_DEFAULT: + lcd_filter = CAIRO_LCD_FILTER_FIR5; + break; + case FC_LCD_LIGHT: + lcd_filter = CAIRO_LCD_FILTER_FIR3; + break; + case FC_LCD_LEGACY: + lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL; + break; + default: + lcd_filter = CAIRO_LCD_FILTER_DEFAULT; + break; + } + + if (res.xft_antialias) { + if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT) + antialias = CAIRO_ANTIALIAS_GRAY; + else + antialias = CAIRO_ANTIALIAS_SUBPIXEL; + } else { + antialias = CAIRO_ANTIALIAS_NONE; + } + + cairo_font_options_set_hint_style (&screen->font_options, hint_style); + cairo_font_options_set_antialias (&screen->font_options, antialias); + cairo_font_options_set_subpixel_order (&screen->font_options, subpixel_order); + _cairo_font_options_set_lcd_filter (&screen->font_options, lcd_filter); + cairo_font_options_set_hint_metrics (&screen->font_options, CAIRO_HINT_METRICS_ON); +} + +struct pattern_cache_entry { + cairo_cache_entry_t key; + cairo_xcb_screen_t *screen; + cairo_pattern_union_t pattern; + cairo_surface_t *picture; +}; + +void +_cairo_xcb_screen_finish (cairo_xcb_screen_t *screen) +{ + int i; + + CAIRO_MUTEX_LOCK (screen->connection->screens_mutex); + cairo_list_del (&screen->link); + CAIRO_MUTEX_UNLOCK (screen->connection->screens_mutex); + + while (! cairo_list_is_empty (&screen->surfaces)) { + cairo_surface_t *surface; + + surface = &cairo_list_first_entry (&screen->surfaces, + cairo_xcb_surface_t, + link)->base; + + cairo_surface_finish (surface); + } + + while (! cairo_list_is_empty (&screen->pictures)) { + cairo_surface_t *surface; + + surface = &cairo_list_first_entry (&screen->pictures, + cairo_xcb_picture_t, + link)->base; + + cairo_surface_finish (surface); + } + + for (i = 0; i < screen->solid_cache_size; i++) + cairo_surface_destroy (screen->solid_cache[i].picture); + + for (i = 0; i < ARRAY_LENGTH (screen->stock_colors); i++) + cairo_surface_destroy (screen->stock_colors[i]); + + for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) { + if (screen->gc_depths[i] != 0) + _cairo_xcb_connection_free_gc (screen->connection, screen->gc[i]); + } + + _cairo_cache_fini (&screen->linear_pattern_cache); + _cairo_cache_fini (&screen->radial_pattern_cache); + _cairo_freelist_fini (&screen->pattern_cache_entry_freelist); + + free (screen); +} + +static cairo_bool_t +_linear_pattern_cache_entry_equal (const void *A, const void *B) +{ + const struct pattern_cache_entry *a = A, *b = B; + + return _cairo_linear_pattern_equal (&a->pattern.gradient.linear, + &b->pattern.gradient.linear); +} + +static cairo_bool_t +_radial_pattern_cache_entry_equal (const void *A, const void *B) +{ + const struct pattern_cache_entry *a = A, *b = B; + + return _cairo_radial_pattern_equal (&a->pattern.gradient.radial, + &b->pattern.gradient.radial); +} + +static void +_pattern_cache_entry_destroy (void *closure) +{ + struct pattern_cache_entry *entry = closure; + + _cairo_pattern_fini (&entry->pattern.base); + cairo_surface_destroy (entry->picture); + _cairo_freelist_free (&entry->screen->pattern_cache_entry_freelist, entry); +} + +static int _get_screen_index(cairo_xcb_connection_t *xcb_connection, + xcb_screen_t *xcb_screen) +{ + int idx = 0; + xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_connection->root); + for (; iter.rem; xcb_screen_next(&iter), idx++) + if (iter.data->root == xcb_screen->root) + return idx; + + ASSERT_NOT_REACHED; +} + +cairo_xcb_screen_t * +_cairo_xcb_screen_get (xcb_connection_t *xcb_connection, + xcb_screen_t *xcb_screen) +{ + cairo_xcb_connection_t *connection; + cairo_xcb_screen_t *screen; + cairo_status_t status; + int screen_idx; + int i; + + connection = _cairo_xcb_connection_get (xcb_connection); + if (unlikely (connection == NULL)) + return NULL; + + CAIRO_MUTEX_LOCK (connection->screens_mutex); + + cairo_list_foreach_entry (screen, + cairo_xcb_screen_t, + &connection->screens, + link) + { + if (screen->xcb_screen == xcb_screen) { + /* Maintain list in MRU order */ + if (&screen->link != connection->screens.next) + cairo_list_move (&screen->link, &connection->screens); + + goto unlock; + } + } + + screen = malloc (sizeof (cairo_xcb_screen_t)); + if (unlikely (screen == NULL)) + goto unlock; + + screen_idx = _get_screen_index(connection, xcb_screen); + + screen->connection = connection; + screen->xcb_screen = xcb_screen; + screen->has_font_options = FALSE; + screen->subpixel_order = connection->subpixel_orders[screen_idx]; + + _cairo_freelist_init (&screen->pattern_cache_entry_freelist, + sizeof (struct pattern_cache_entry)); + cairo_list_init (&screen->link); + cairo_list_init (&screen->surfaces); + cairo_list_init (&screen->pictures); + + memset (screen->gc_depths, 0, sizeof (screen->gc_depths)); + memset (screen->gc, 0, sizeof (screen->gc)); + + screen->solid_cache_size = 0; + for (i = 0; i < ARRAY_LENGTH (screen->stock_colors); i++) + screen->stock_colors[i] = NULL; + + status = _cairo_cache_init (&screen->linear_pattern_cache, + _linear_pattern_cache_entry_equal, + NULL, + _pattern_cache_entry_destroy, + 16); + if (unlikely (status)) + goto error_screen; + + status = _cairo_cache_init (&screen->radial_pattern_cache, + _radial_pattern_cache_entry_equal, + NULL, + _pattern_cache_entry_destroy, + 4); + if (unlikely (status)) + goto error_linear; + + cairo_list_add (&screen->link, &connection->screens); + +unlock: + CAIRO_MUTEX_UNLOCK (connection->screens_mutex); + + return screen; + +error_linear: + _cairo_cache_fini (&screen->linear_pattern_cache); +error_screen: + CAIRO_MUTEX_UNLOCK (connection->screens_mutex); + free (screen); + + return NULL; +} + +static xcb_gcontext_t +_create_gc (cairo_xcb_screen_t *screen, + xcb_drawable_t drawable) +{ + uint32_t values[] = { 0 }; + + return _cairo_xcb_connection_create_gc (screen->connection, drawable, + XCB_GC_GRAPHICS_EXPOSURES, + values); +} + +xcb_gcontext_t +_cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen, + xcb_drawable_t drawable, + int depth) +{ + int i; + + assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); + + for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) { + if (screen->gc_depths[i] == depth) { + screen->gc_depths[i] = 0; + return screen->gc[i]; + } + } + + return _create_gc (screen, drawable); +} + +void +_cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t gc) +{ + int i; + + assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); + + for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) { + if (screen->gc_depths[i] == 0) + break; + } + + if (i == ARRAY_LENGTH (screen->gc)) { + /* perform random substitution to ensure fair caching over depths */ + i = rand () % ARRAY_LENGTH (screen->gc); + _cairo_xcb_connection_free_gc (screen->connection, screen->gc[i]); + } + + screen->gc[i] = gc; + screen->gc_depths[i] = depth; +} + +cairo_status_t +_cairo_xcb_screen_store_linear_picture (cairo_xcb_screen_t *screen, + const cairo_linear_pattern_t *linear, + cairo_surface_t *picture) +{ + struct pattern_cache_entry *entry; + cairo_status_t status; + + assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); + + entry = _cairo_freelist_alloc (&screen->pattern_cache_entry_freelist); + if (unlikely (entry == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + entry->key.hash = _cairo_linear_pattern_hash (_CAIRO_HASH_INIT_VALUE, linear); + entry->key.size = 1; + + status = _cairo_pattern_init_copy (&entry->pattern.base, &linear->base.base); + if (unlikely (status)) { + _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); + return status; + } + + entry->picture = cairo_surface_reference (picture); + entry->screen = screen; + + status = _cairo_cache_insert (&screen->linear_pattern_cache, + &entry->key); + if (unlikely (status)) { + cairo_surface_destroy (picture); + _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_surface_t * +_cairo_xcb_screen_lookup_linear_picture (cairo_xcb_screen_t *screen, + const cairo_linear_pattern_t *linear) +{ + cairo_surface_t *picture = NULL; + struct pattern_cache_entry tmpl; + struct pattern_cache_entry *entry; + + assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); + + tmpl.key.hash = _cairo_linear_pattern_hash (_CAIRO_HASH_INIT_VALUE, linear); + _cairo_pattern_init_static_copy (&tmpl.pattern.base, &linear->base.base); + + entry = _cairo_cache_lookup (&screen->linear_pattern_cache, &tmpl.key); + if (entry != NULL) + picture = cairo_surface_reference (entry->picture); + + return picture; +} + +cairo_status_t +_cairo_xcb_screen_store_radial_picture (cairo_xcb_screen_t *screen, + const cairo_radial_pattern_t *radial, + cairo_surface_t *picture) +{ + struct pattern_cache_entry *entry; + cairo_status_t status; + + assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); + + entry = _cairo_freelist_alloc (&screen->pattern_cache_entry_freelist); + if (unlikely (entry == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + entry->key.hash = _cairo_radial_pattern_hash (_CAIRO_HASH_INIT_VALUE, radial); + entry->key.size = 1; + + status = _cairo_pattern_init_copy (&entry->pattern.base, &radial->base.base); + if (unlikely (status)) { + _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); + return status; + } + + entry->picture = cairo_surface_reference (picture); + entry->screen = screen; + + status = _cairo_cache_insert (&screen->radial_pattern_cache, &entry->key); + if (unlikely (status)) { + cairo_surface_destroy (picture); + _cairo_freelist_free (&screen->pattern_cache_entry_freelist, entry); + return status; + } + + return CAIRO_STATUS_SUCCESS; +} + +cairo_surface_t * +_cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen, + const cairo_radial_pattern_t *radial) +{ + cairo_surface_t *picture = NULL; + struct pattern_cache_entry tmpl; + struct pattern_cache_entry *entry; + + assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex)); + + tmpl.key.hash = _cairo_radial_pattern_hash (_CAIRO_HASH_INIT_VALUE, radial); + _cairo_pattern_init_static_copy (&tmpl.pattern.base, &radial->base.base); + + entry = _cairo_cache_lookup (&screen->radial_pattern_cache, &tmpl.key); + if (entry != NULL) + picture = cairo_surface_reference (entry->picture); + + return picture; +} + +cairo_font_options_t * +_cairo_xcb_screen_get_font_options (cairo_xcb_screen_t *screen) +{ + if (! screen->has_font_options) { + _cairo_font_options_init_default (&screen->font_options); + _cairo_font_options_set_round_glyph_positions (&screen->font_options, CAIRO_ROUND_GLYPH_POS_ON); + + /* XXX: This is disabled because something seems to be merging + font options incorrectly for xcb. This effectively reverts + the changes brought in git e691d242, and restores ~150 tests + to resume passing. See mailing list archives for Sep 17, + 2014 for more discussion. */ + if (0 && ! _cairo_xcb_connection_acquire (screen->connection)) { + _cairo_xcb_init_screen_font_options (screen); + _cairo_xcb_connection_release (screen->connection); + } + + screen->has_font_options = TRUE; + } + + return &screen->font_options; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-shm.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-shm.c new file mode 100644 index 00000000000..2be2dac5bf9 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-shm.c @@ -0,0 +1,337 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributors(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + +#include "cairo-xcb-private.h" +#include "cairo-list-inline.h" +#include "cairo-mempool-private.h" + +#include +#include +#include +#include + +#define CAIRO_MAX_SHM_MEMORY (16*1024*1024) + +/* a simple buddy allocator for memory pools + * XXX fragmentation? use Doug Lea's malloc? + */ + +typedef struct _cairo_xcb_shm_mem_block cairo_xcb_shm_mem_block_t; + +typedef enum { + PENDING_WAIT, + PENDING_POLL +} shm_wait_type_t; + +struct _cairo_xcb_shm_mem_pool { + int shmid; + uint32_t shmseg; + void *shm; + + cairo_mempool_t mem; + + cairo_list_t link; +}; + +static void +_cairo_xcb_shm_mem_pool_destroy (cairo_xcb_shm_mem_pool_t *pool) +{ + cairo_list_del (&pool->link); + + shmdt (pool->shm); + _cairo_mempool_fini (&pool->mem); + + free (pool); +} + +static void +_cairo_xcb_shm_info_finalize (cairo_xcb_shm_info_t *shm_info) +{ + cairo_xcb_connection_t *connection = shm_info->connection; + + assert (CAIRO_MUTEX_IS_LOCKED (connection->shm_mutex)); + + _cairo_mempool_free (&shm_info->pool->mem, shm_info->mem); + _cairo_freepool_free (&connection->shm_info_freelist, shm_info); + + /* scan for old, unused pools - hold at least one in reserve */ + if (! cairo_list_is_singular (&connection->shm_pools)) + { + cairo_xcb_shm_mem_pool_t *pool, *next; + cairo_list_t head; + + cairo_list_init (&head); + cairo_list_move (connection->shm_pools.next, &head); + + cairo_list_foreach_entry_safe (pool, next, cairo_xcb_shm_mem_pool_t, + &connection->shm_pools, link) + { + if (pool->mem.free_bytes == pool->mem.max_bytes) { + _cairo_xcb_connection_shm_detach (connection, pool->shmseg); + _cairo_xcb_shm_mem_pool_destroy (pool); + } + } + + cairo_list_move (head.next, &connection->shm_pools); + } +} + +static void +_cairo_xcb_shm_process_pending (cairo_xcb_connection_t *connection, shm_wait_type_t wait) +{ + cairo_xcb_shm_info_t *info, *next; + xcb_get_input_focus_reply_t *reply; + + assert (CAIRO_MUTEX_IS_LOCKED (connection->shm_mutex)); + cairo_list_foreach_entry_safe (info, next, cairo_xcb_shm_info_t, + &connection->shm_pending, pending) + { + switch (wait) { + case PENDING_WAIT: + reply = xcb_wait_for_reply (connection->xcb_connection, + info->sync.sequence, NULL); + break; + case PENDING_POLL: + if (! xcb_poll_for_reply (connection->xcb_connection, + info->sync.sequence, + (void **) &reply, NULL)) + /* We cannot be sure the server finished with this image yet, so + * try again later. All other shm info are guaranteed to have a + * larger sequence number and thus don't have to be checked. */ + return; + break; + default: + /* silence Clang static analyzer warning */ + ASSERT_NOT_REACHED; + reply = NULL; + } + + free (reply); + cairo_list_del (&info->pending); + _cairo_xcb_shm_info_finalize (info); + } +} + +cairo_int_status_t +_cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection, + size_t size, + cairo_bool_t might_reuse, + cairo_xcb_shm_info_t **shm_info_out) +{ + cairo_xcb_shm_info_t *shm_info; + cairo_xcb_shm_mem_pool_t *pool, *next; + size_t bytes, maxbits = 16, minbits = 8; + size_t shm_allocated = 0; + void *mem = NULL; + cairo_status_t status; + + assert (connection->flags & CAIRO_XCB_HAS_SHM); + + CAIRO_MUTEX_LOCK (connection->shm_mutex); + _cairo_xcb_shm_process_pending (connection, PENDING_POLL); + + if (might_reuse) { + cairo_list_foreach_entry (shm_info, cairo_xcb_shm_info_t, + &connection->shm_pending, pending) { + if (shm_info->size >= size) { + cairo_list_del (&shm_info->pending); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + + xcb_discard_reply (connection->xcb_connection, shm_info->sync.sequence); + shm_info->sync.sequence = XCB_NONE; + + *shm_info_out = shm_info; + return CAIRO_STATUS_SUCCESS; + } + } + } + + cairo_list_foreach_entry_safe (pool, next, cairo_xcb_shm_mem_pool_t, + &connection->shm_pools, link) + { + if (pool->mem.free_bytes > size) { + mem = _cairo_mempool_alloc (&pool->mem, size); + if (mem != NULL) { + /* keep the active pools towards the front */ + cairo_list_move (&pool->link, &connection->shm_pools); + goto allocate_shm_info; + } + } + /* scan for old, unused pools */ + if (pool->mem.free_bytes == pool->mem.max_bytes) { + _cairo_xcb_connection_shm_detach (connection, + pool->shmseg); + _cairo_xcb_shm_mem_pool_destroy (pool); + } else { + shm_allocated += pool->mem.max_bytes; + } + } + + if (unlikely (shm_allocated >= CAIRO_MAX_SHM_MEMORY)) { + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pool = malloc (sizeof (cairo_xcb_shm_mem_pool_t)); + if (unlikely (pool == NULL)) { + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + bytes = 1 << maxbits; + while (bytes <= size) + bytes <<= 1, maxbits++; + bytes <<= 3; + + do { + pool->shmid = shmget (IPC_PRIVATE, bytes, IPC_CREAT | 0600); + if (pool->shmid != -1) + break; + + /* If the allocation failed because we asked for too much memory, we try + * again with a smaller request, as long as our allocation still fits. */ + bytes >>= 1; + if (errno != EINVAL || bytes < size) + break; + } while (TRUE); + if (pool->shmid == -1) { + int err = errno; + if (! (err == EINVAL || err == ENOMEM)) + connection->flags &= ~CAIRO_XCB_HAS_SHM; + free (pool); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + pool->shm = shmat (pool->shmid, NULL, 0); + if (unlikely (pool->shm == (char *) -1)) { + shmctl (pool->shmid, IPC_RMID, NULL); + free (pool); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + status = _cairo_mempool_init (&pool->mem, pool->shm, bytes, + minbits, maxbits - minbits + 1); + if (unlikely (status)) { + shmdt (pool->shm); + free (pool); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + return status; + } + + pool->shmseg = _cairo_xcb_connection_shm_attach (connection, pool->shmid, FALSE); + shmctl (pool->shmid, IPC_RMID, NULL); + + cairo_list_add (&pool->link, &connection->shm_pools); + mem = _cairo_mempool_alloc (&pool->mem, size); + + allocate_shm_info: + shm_info = _cairo_freepool_alloc (&connection->shm_info_freelist); + if (unlikely (shm_info == NULL)) { + _cairo_mempool_free (&pool->mem, mem); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + shm_info->connection = connection; + shm_info->pool = pool; + shm_info->shm = pool->shmseg; + shm_info->size = size; + shm_info->offset = (char *) mem - (char *) pool->shm; + shm_info->mem = mem; + shm_info->sync.sequence = XCB_NONE; + + /* scan for old, unused pools */ + cairo_list_foreach_entry_safe (pool, next, cairo_xcb_shm_mem_pool_t, + &connection->shm_pools, link) + { + if (pool->mem.free_bytes == pool->mem.max_bytes) { + _cairo_xcb_connection_shm_detach (connection, + pool->shmseg); + _cairo_xcb_shm_mem_pool_destroy (pool); + } + } + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); + + *shm_info_out = shm_info; + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_xcb_shm_info_destroy (cairo_xcb_shm_info_t *shm_info) +{ + cairo_xcb_connection_t *connection = shm_info->connection; + + /* We can only return shm_info->mem to the allocator when we can be sure + * that the X server no longer reads from it. Since the X server processes + * requests in order, we send a GetInputFocus here. + * _cairo_xcb_shm_process_pending () will later check if the reply for that + * request was received and then actually mark this memory area as free. */ + + CAIRO_MUTEX_LOCK (connection->shm_mutex); + assert (shm_info->sync.sequence == XCB_NONE); + shm_info->sync = xcb_get_input_focus (connection->xcb_connection); + + cairo_list_init (&shm_info->pending); + cairo_list_add_tail (&shm_info->pending, &connection->shm_pending); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); +} + +void +_cairo_xcb_connection_shm_mem_pools_flush (cairo_xcb_connection_t *connection) +{ + CAIRO_MUTEX_LOCK (connection->shm_mutex); + _cairo_xcb_shm_process_pending (connection, PENDING_WAIT); + CAIRO_MUTEX_UNLOCK (connection->shm_mutex); +} + +void +_cairo_xcb_connection_shm_mem_pools_fini (cairo_xcb_connection_t *connection) +{ + assert (cairo_list_is_empty (&connection->shm_pending)); + while (! cairo_list_is_empty (&connection->shm_pools)) { + _cairo_xcb_shm_mem_pool_destroy (cairo_list_first_entry (&connection->shm_pools, + cairo_xcb_shm_mem_pool_t, + link)); + } +} + +#endif /* CAIRO_HAS_XCB_SHM_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-core.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-core.c new file mode 100644 index 00000000000..9c0c0a0957d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-core.c @@ -0,0 +1,639 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-boxes-private.h" +#include "cairo-xcb-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-backend-private.h" + +/* XXX dithering */ + +typedef struct _cairo_xcb_pixmap { + cairo_surface_t base; + + cairo_xcb_connection_t *connection; + cairo_xcb_screen_t *screen; + + cairo_surface_t *owner; + xcb_pixmap_t pixmap; + int width; + int height; + int depth; + int x0, y0; + cairo_bool_t repeat; +} cairo_xcb_pixmap_t; + +static cairo_status_t +_cairo_xcb_pixmap_finish (void *abstract_surface) +{ + cairo_xcb_pixmap_t *surface = abstract_surface; + cairo_status_t status; + + if (surface->owner != NULL) { + cairo_surface_destroy (surface->owner); + } else { + status = _cairo_xcb_connection_acquire (surface->connection); + if (unlikely (status)) + return status; + + _cairo_xcb_connection_free_pixmap (surface->connection, + surface->pixmap); + _cairo_xcb_connection_release (surface->connection); + } + + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t _cairo_xcb_pixmap_backend = { + CAIRO_SURFACE_TYPE_XCB, + _cairo_xcb_pixmap_finish, +}; + +static cairo_xcb_pixmap_t * +_cairo_xcb_pixmap_create (cairo_xcb_surface_t *target, + int width, int height) +{ + cairo_xcb_pixmap_t *surface; + + surface = malloc (sizeof (cairo_xcb_pixmap_t)); + if (unlikely (surface == NULL)) + return (cairo_xcb_pixmap_t *) + _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_xcb_pixmap_backend, + NULL, + target->base.content); + + surface->connection = target->connection; + surface->screen = target->screen; + surface->owner = NULL; + surface->width = width; + surface->height = height; + surface->depth = target->depth; + surface->x0 = surface->y0 = 0; + surface->repeat = FALSE; + + surface->pixmap = + _cairo_xcb_connection_create_pixmap (surface->connection, + surface->depth, + target->drawable, + width, height); + + return surface; +} + +static cairo_xcb_pixmap_t * +_cairo_xcb_pixmap_copy (cairo_xcb_surface_t *target) +{ + cairo_xcb_pixmap_t *surface; + + surface = malloc (sizeof (cairo_xcb_pixmap_t)); + if (unlikely (surface == NULL)) + return (cairo_xcb_pixmap_t *) + _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_xcb_pixmap_backend, + NULL, + target->base.content); + + surface->connection = target->connection; + surface->screen = target->screen; + surface->pixmap = target->drawable; + surface->owner = cairo_surface_reference (&target->base); + surface->width = target->width; + surface->height = target->height; + surface->depth = target->depth; + surface->x0 = surface->y0 = 0; + surface->repeat = FALSE; + + return surface; +} + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS +static cairo_status_t +_cairo_xcb_shm_image_create_shm (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format, + int width, int height, + cairo_image_surface_t **image_out, + cairo_xcb_shm_info_t **shm_info_out) +{ + cairo_surface_t *image = NULL; + cairo_xcb_shm_info_t *shm_info = NULL; + cairo_status_t status; + size_t size, stride; + + if (! (connection->flags & CAIRO_XCB_HAS_SHM)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, PIXMAN_FORMAT_BPP (pixman_format)); + size = stride * height; + if (size <= CAIRO_XCB_SHM_SMALL_IMAGE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_xcb_connection_allocate_shm_info (connection, size, + FALSE, &shm_info); + if (unlikely (status)) + return status; + + image = _cairo_image_surface_create_with_pixman_format (shm_info->mem, + pixman_format, + width, height, + stride); + status = image->status; + if (unlikely (status)) { + _cairo_xcb_shm_info_destroy (shm_info); + return status; + } + + status = _cairo_user_data_array_set_data (&image->user_data, + (const cairo_user_data_key_t *) connection, + shm_info, + (cairo_destroy_func_t) _cairo_xcb_shm_info_destroy); + + if (unlikely (status)) { + cairo_surface_destroy (image); + _cairo_xcb_shm_info_destroy (shm_info); + return status; + } + + *image_out = (cairo_image_surface_t *) image; + *shm_info_out = shm_info; + return CAIRO_STATUS_SUCCESS; +} +#else +static cairo_status_t +_cairo_xcb_shm_image_create_shm (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format, + int width, int height, + cairo_image_surface_t **image_out, + cairo_xcb_shm_info_t **shm_info_out) +{ + return CAIRO_INT_STATUS_UNSUPPORTED; +} +#endif + +cairo_status_t +_cairo_xcb_shm_image_create (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format, + int width, int height, + cairo_image_surface_t **image_out, + cairo_xcb_shm_info_t **shm_info_out) +{ + cairo_surface_t *image = NULL; + cairo_xcb_shm_info_t *shm_info = NULL; + cairo_status_t status; + + status = _cairo_xcb_shm_image_create_shm (connection, + pixman_format, + width, + height, + image_out, + shm_info_out); + + if (status != CAIRO_STATUS_SUCCESS) { + image = _cairo_image_surface_create_with_pixman_format (NULL, + pixman_format, + width, height, + 0); + status = image->status; + if (unlikely (status)) + return status; + + *image_out = (cairo_image_surface_t *) image; + *shm_info_out = shm_info; + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_xcb_pixmap_t * +_pixmap_from_image (cairo_xcb_surface_t *target, + xcb_render_pictformat_t format, + cairo_image_surface_t *image, + cairo_xcb_shm_info_t *shm_info) +{ + xcb_gcontext_t gc; + cairo_xcb_pixmap_t *pixmap; + + pixmap = _cairo_xcb_pixmap_create (target, + image->width, + image->height); + if (unlikely (pixmap->base.status)) + return pixmap; + + gc = _cairo_xcb_screen_get_gc (target->screen, pixmap->pixmap, image->depth); + + if (shm_info != NULL) { + _cairo_xcb_connection_shm_put_image (target->connection, + pixmap->pixmap, gc, + image->width, image->height, + 0, 0, + image->width, image->height, + 0, 0, + image->depth, + shm_info->shm, + shm_info->offset); + } else { + int len; + + /* Do we need to trim the image? */ + len = CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, + PIXMAN_FORMAT_BPP (image->pixman_format)); + if (len == image->stride) { + _cairo_xcb_connection_put_image (target->connection, + pixmap->pixmap, gc, + image->width, image->height, + 0, 0, + image->depth, + image->stride, + image->data); + } else { + _cairo_xcb_connection_put_subimage (target->connection, + pixmap->pixmap, gc, + 0, 0, + image->width, image->height, + PIXMAN_FORMAT_BPP (image->pixman_format) / 8, + image->stride, + 0, 0, + image->depth, + image->data); + + } + } + + _cairo_xcb_screen_put_gc (target->screen, image->depth, gc); + + return pixmap; +} + +static cairo_xcb_pixmap_t * +_render_to_pixmap (cairo_xcb_surface_t *target, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + cairo_image_surface_t *image; + cairo_xcb_shm_info_t *shm_info; + cairo_pattern_union_t copy; + cairo_status_t status; + cairo_xcb_pixmap_t *pixmap; + + status = _cairo_xcb_shm_image_create (target->screen->connection, + target->pixman_format, + extents->width, extents->height, + &image, &shm_info); + if (unlikely (status)) + return (cairo_xcb_pixmap_t *) _cairo_surface_create_in_error (status); + + _cairo_pattern_init_static_copy (©.base, pattern); + cairo_matrix_translate (©.base.matrix, -extents->x, -extents->y); + status = _cairo_surface_paint (&image->base, + CAIRO_OPERATOR_SOURCE, + ©.base, + NULL); + if (unlikely (status)) { + cairo_surface_destroy (&image->base); + return (cairo_xcb_pixmap_t *) _cairo_surface_create_in_error (status); + } + + pixmap = _pixmap_from_image (target, target->xrender_format, image, shm_info); + cairo_surface_destroy (&image->base); + + if (unlikely (pixmap->base.status)) + return pixmap; + + pixmap->x0 = -extents->x; + pixmap->y0 = -extents->y; + return pixmap; +} + +static cairo_xcb_pixmap_t * +_copy_to_pixmap (cairo_xcb_surface_t *source) +{ + cairo_xcb_pixmap_t *pixmap; + + /* If the source may be a window, we need to copy it and its children + * via a temporary pixmap so that we can IncludeInferiors on the source + * and use ClipByChildren on the destination. + */ + if (source->owns_pixmap) { + pixmap = _cairo_xcb_pixmap_copy (source); + if (unlikely (pixmap->base.status)) + return pixmap; + } else { + uint32_t values[1]; + xcb_gcontext_t gc; + + pixmap = _cairo_xcb_pixmap_create (source, + source->width, + source->height); + if (unlikely (pixmap->base.status)) + return pixmap; + + gc = _cairo_xcb_screen_get_gc (source->screen, + pixmap->pixmap, + pixmap->depth); + + values[0] = TRUE; + _cairo_xcb_connection_change_gc (pixmap->connection, gc, + XCB_GC_SUBWINDOW_MODE, values); + + _cairo_xcb_connection_copy_area (pixmap->connection, + source->drawable, + pixmap->pixmap, gc, + 0, 0, + 0, 0, + source->width, + source->height); + + values[0] = FALSE; + _cairo_xcb_connection_change_gc (pixmap->connection, gc, + XCB_GC_SUBWINDOW_MODE, values); + + _cairo_xcb_screen_put_gc (source->screen, + pixmap->depth, + gc); + } + + return pixmap; +} +static cairo_xcb_pixmap_t * +_cairo_xcb_surface_pixmap (cairo_xcb_surface_t *target, + const cairo_surface_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + int tx, int ty) +{ + cairo_surface_t *source; + cairo_xcb_pixmap_t *pixmap; + + source = pattern->surface; + pixmap = (cairo_xcb_pixmap_t *) + _cairo_surface_has_snapshot (source, &_cairo_xcb_pixmap_backend); + if (pixmap != NULL && pixmap->screen == target->screen) + return (cairo_xcb_pixmap_t *) cairo_surface_reference (&pixmap->base); + + if (_cairo_surface_is_xcb(source) && + ((cairo_xcb_surface_t *) source)->screen == target->screen) + { + cairo_xcb_surface_t *xcb_source = (cairo_xcb_surface_t *) source; + + if (xcb_source->depth == target->depth) + pixmap = _copy_to_pixmap (xcb_source); + } +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS + else if (source->type == CAIRO_SURFACE_TYPE_XLIB && + ((cairo_xlib_xcb_surface_t *) source)->xcb->screen == target->screen) + { + cairo_xcb_surface_t *xcb_source = ((cairo_xlib_xcb_surface_t *) source)->xcb; + + if (xcb_source->depth == target->depth) + pixmap = _copy_to_pixmap (xcb_source); + } +#endif + + if (pixmap == NULL) { + cairo_rectangle_int_t rect; + + if (! _cairo_surface_get_extents (source, &rect)) { + rect.x = rect.y = 0; + rect.width = target->width; + rect.height = target->height; + } + + pixmap = _render_to_pixmap (target, &pattern->base, &rect); + } + + if (unlikely (pixmap->base.status)) + return pixmap; + + _cairo_surface_attach_snapshot (source, &pixmap->base, NULL); + + if (pattern->base.extend != CAIRO_EXTEND_NONE) { + if (extents->x < 0 || extents->y < 0 || + extents->x + extents->width > pixmap->width || + extents->y + extents->height > pixmap->height) + { + pixmap->repeat = TRUE; + } + } + + pixmap->x0 += tx; + pixmap->y0 += ty; + + return pixmap; +} + +static cairo_xcb_pixmap_t * +_cairo_xcb_pixmap_for_pattern (cairo_xcb_surface_t *target, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + int tx, ty; + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SURFACE: + /* Core can only perform a native, unscaled blit, but can handle tiles */ + if (_cairo_matrix_is_integer_translation (&pattern->matrix, &tx, &ty)) { + switch (pattern->extend) { + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_REPEAT: + return _cairo_xcb_surface_pixmap (target, + (cairo_surface_pattern_t *) pattern, + extents, tx, ty); + + default: + case CAIRO_EXTEND_PAD: + case CAIRO_EXTEND_REFLECT: + break; + } + } + /* fallthrough */ + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: + case CAIRO_PATTERN_TYPE_MESH: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _render_to_pixmap (target, pattern, extents); + + default: + case CAIRO_PATTERN_TYPE_SOLID: + ASSERT_NOT_REACHED; + return NULL; + } +} + +cairo_status_t +_cairo_xcb_surface_core_copy_boxes (cairo_xcb_surface_t *dst, + const cairo_pattern_t *src_pattern, + const cairo_rectangle_int_t *extents, + const cairo_boxes_t *boxes) +{ + cairo_xcb_pixmap_t *src; + const struct _cairo_boxes_chunk *chunk; + xcb_gcontext_t gc; + cairo_status_t status; + + status = _cairo_xcb_connection_acquire (dst->connection); + if (unlikely (status)) + return status; + + src = _cairo_xcb_pixmap_for_pattern (dst, src_pattern, extents); + status = src->base.status; + if (unlikely (status)) + goto CLEANUP_CONNECTION; + + assert (src->depth == dst->depth); + + gc = _cairo_xcb_screen_get_gc (dst->screen, src->pixmap, src->depth); + + if (src->repeat) { + uint32_t mask = + XCB_GC_FILL_STYLE | + XCB_GC_TILE | + XCB_GC_TILE_STIPPLE_ORIGIN_X | + XCB_GC_TILE_STIPPLE_ORIGIN_Y; + uint32_t values[] = { + XCB_FILL_STYLE_TILED, + src->pixmap, + - src->x0, - src->y0, + }; + xcb_rectangle_t *xcb_rects; + + _cairo_xcb_connection_change_gc (dst->connection, gc, mask, values); + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + int i; + + xcb_rects = (xcb_rectangle_t *) chunk->base; + + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_round (chunk->base[i].p1.x); + int x2 = _cairo_fixed_integer_round (chunk->base[i].p2.x); + int y1 = _cairo_fixed_integer_round (chunk->base[i].p1.y); + int y2 = _cairo_fixed_integer_round (chunk->base[i].p2.y); + + xcb_rects[i].x = x1; + xcb_rects[i].y = y1; + xcb_rects[i].width = x2 - x1; + xcb_rects[i].height = y2 - y1; + } + _cairo_xcb_connection_poly_fill_rectangle (dst->connection, + dst->drawable, + gc, chunk->count, xcb_rects); + } + + values[0] = 0; + _cairo_xcb_connection_change_gc (dst->connection, gc, XCB_GC_FILL_STYLE, values); + } else { + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + int i; + + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_round (chunk->base[i].p1.x); + int x2 = _cairo_fixed_integer_round (chunk->base[i].p2.x); + int y1 = _cairo_fixed_integer_round (chunk->base[i].p1.y); + int y2 = _cairo_fixed_integer_round (chunk->base[i].p2.y); + + _cairo_xcb_connection_copy_area (dst->connection, + src->pixmap, + dst->drawable, gc, + src->x0 + x1, + src->y0 + y1, + x1, y1, + x2 - x1, y2 - y1); + } + } + } + + _cairo_xcb_screen_put_gc (dst->screen, src->depth, gc); + cairo_surface_destroy (&src->base); + + CLEANUP_CONNECTION: + _cairo_xcb_connection_release (dst->connection); + + return status; +} + +cairo_status_t +_cairo_xcb_surface_core_fill_boxes (cairo_xcb_surface_t *dst, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + struct _cairo_boxes_chunk *chunk; + xcb_gcontext_t gc; + cairo_status_t status; + + status = _cairo_xcb_connection_acquire (dst->connection); + if (unlikely (status)) + return status; + + gc = _cairo_xcb_screen_get_gc (dst->screen, dst->drawable, dst->depth); + +#if 0 + xcb_pixmap_t source; + + source = _dither_source (dst, color); + XSetTSOrigin (surface->dpy, gc, 0, 0); + XSetTile (surface->dpy, gc, source); +#endif + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + xcb_rectangle_t *xcb_rects; + int i; + + xcb_rects = (xcb_rectangle_t *) chunk->base; + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_round (chunk->base[i].p1.x); + int x2 = _cairo_fixed_integer_round (chunk->base[i].p2.x); + int y1 = _cairo_fixed_integer_round (chunk->base[i].p1.y); + int y2 = _cairo_fixed_integer_round (chunk->base[i].p2.y); + + xcb_rects[i].x = x1; + xcb_rects[i].y = y1; + xcb_rects[i].width = x2 - x1; + xcb_rects[i].height = y2 - y1; + } + + _cairo_xcb_connection_poly_fill_rectangle (dst->connection, + dst->drawable, gc, + chunk->count, xcb_rects); + } + + _cairo_xcb_screen_put_gc (dst->screen, dst->depth, gc); + _cairo_xcb_connection_release (dst->connection); + + return CAIRO_STATUS_SUCCESS; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-render.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-render.c new file mode 100644 index 00000000000..044339bce8f --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface-render.c @@ -0,0 +1,4881 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "cairo-xcb-private.h" + +#include "cairo-boxes-private.h" +#include "cairo-clip-inline.h" +#include "cairo-clip-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-region-private.h" +#include "cairo-surface-offset-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-private.h" +#include "cairo-traps-private.h" +#include "cairo-recording-surface-inline.h" +#include "cairo-paginated-private.h" +#include "cairo-pattern-inline.h" + +#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ + +static cairo_status_t +_clip_and_composite_boxes (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + cairo_boxes_t *boxes, + cairo_composite_rectangles_t *extents); + +static inline cairo_xcb_connection_t * +_picture_to_connection (cairo_xcb_picture_t *picture) +{ + return (cairo_xcb_connection_t *) picture->base.device; +} + +static void +_cairo_xcb_surface_ensure_picture (cairo_xcb_surface_t *surface); + +static uint32_t +hars_petruska_f54_1_random (void) +{ +#define rol(x,k) ((x << k) | (x >> (32-k))) + static uint32_t x; + return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; +#undef rol +} + +static cairo_status_t +_cairo_xcb_picture_finish (void *abstract_surface) +{ + cairo_xcb_picture_t *surface = abstract_surface; + cairo_xcb_connection_t *connection = _picture_to_connection (surface); + cairo_status_t status; + + status = _cairo_xcb_connection_acquire (connection); + cairo_list_del (&surface->link); + if (unlikely (status)) + return status; + + _cairo_xcb_connection_render_free_picture (connection, surface->picture); + + _cairo_xcb_connection_release (connection); + + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t _cairo_xcb_picture_backend = { + CAIRO_SURFACE_TYPE_XCB, + _cairo_xcb_picture_finish, +}; + +static const struct xcb_render_transform_t identity_transform = { + 1 << 16, 0, 0, + 0, 1 << 16, 0, + 0, 0, 1 << 16, +}; + +static cairo_xcb_picture_t * +_cairo_xcb_picture_create (cairo_xcb_screen_t *screen, + pixman_format_code_t pixman_format, + xcb_render_pictformat_t xrender_format, + int width, int height) +{ + cairo_xcb_picture_t *surface; + + surface = malloc (sizeof (cairo_xcb_picture_t)); + if (unlikely (surface == NULL)) + return (cairo_xcb_picture_t *) + _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_xcb_picture_backend, + &screen->connection->device, + _cairo_content_from_pixman_format (pixman_format)); + + cairo_list_add (&surface->link, &screen->pictures); + + surface->screen = screen; + surface->picture = _cairo_xcb_connection_get_xid (screen->connection); + surface->pixman_format = pixman_format; + surface->xrender_format = xrender_format; + + surface->x0 = surface->y0 = 0; + surface->x = surface->y = 0; + surface->width = width; + surface->height = height; + + surface->transform = identity_transform; + surface->extend = CAIRO_EXTEND_NONE; + surface->filter = CAIRO_FILTER_NEAREST; + surface->has_component_alpha = FALSE; + + return surface; +} + +static inline cairo_bool_t +_operator_is_supported (uint32_t flags, cairo_operator_t op) +{ + if (op <= CAIRO_OPERATOR_SATURATE) + return TRUE; + + /* Can we use PDF operators? */ +#if CAIRO_XCB_RENDER_AT_LEAST(0, 11) + if (op <= CAIRO_OPERATOR_HSL_LUMINOSITY) + return flags & CAIRO_XCB_RENDER_HAS_PDF_OPERATORS; +#endif + + return FALSE; +} + +static int +_render_operator (cairo_operator_t op) +{ +#define C(x,y) case CAIRO_OPERATOR_##x: return XCB_RENDER_PICT_OP_##y + switch (op) { + C(CLEAR, CLEAR); + C(SOURCE, SRC); + + C(OVER, OVER); + C(IN, IN); + C(OUT, OUT); + C(ATOP, ATOP); + + C(DEST, DST); + C(DEST_OVER, OVER_REVERSE); + C(DEST_IN, IN_REVERSE); + C(DEST_OUT, OUT_REVERSE); + C(DEST_ATOP, ATOP_REVERSE); + + C(XOR, XOR); + C(ADD, ADD); + C(SATURATE, SATURATE); + + /* PDF operators were added in RENDER 0.11, check if the xcb headers have + * the defines, else fall through to the default case. */ +#if CAIRO_XCB_RENDER_AT_LEAST(0, 11) +#define BLEND(x,y) C(x,y) +#else +#define BLEND(x,y) case CAIRO_OPERATOR_##x: +#endif + BLEND(MULTIPLY, MULTIPLY); + BLEND(SCREEN, SCREEN); + BLEND(OVERLAY, OVERLAY); + BLEND(DARKEN, DARKEN); + BLEND(LIGHTEN, LIGHTEN); + BLEND(COLOR_DODGE, COLOR_DODGE); + BLEND(COLOR_BURN, COLOR_BURN); + BLEND(HARD_LIGHT, HARD_LIGHT); + BLEND(SOFT_LIGHT, SOFT_LIGHT); + BLEND(DIFFERENCE, DIFFERENCE); + BLEND(EXCLUSION, EXCLUSION); + BLEND(HSL_HUE, HSL_HUE); + BLEND(HSL_SATURATION, HSL_SATURATION); + BLEND(HSL_COLOR, HSL_COLOR); + BLEND(HSL_LUMINOSITY, HSL_LUMINOSITY); + + default: + ASSERT_NOT_REACHED; + return XCB_RENDER_PICT_OP_OVER; + } +} + +static cairo_status_t +_cairo_xcb_surface_set_clip_region (cairo_xcb_surface_t *surface, + cairo_region_t *region) +{ + xcb_rectangle_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (xcb_rectangle_t)]; + xcb_rectangle_t *rects = stack_rects; + int i, num_rects; + + num_rects = cairo_region_num_rectangles (region); + + if (num_rects > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (num_rects, sizeof (xcb_rectangle_t)); + if (unlikely (rects == NULL)) { + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + } + + for (i = 0; i < num_rects; i++) { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (region, i, &rect); + + rects[i].x = rect.x; + rects[i].y = rect.y; + rects[i].width = rect.width; + rects[i].height = rect.height; + } + + _cairo_xcb_connection_render_set_picture_clip_rectangles (surface->connection, + surface->picture, + 0, 0, + num_rects, rects); + + if (rects != stack_rects) + free (rects); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_xcb_surface_clear_clip_region (cairo_xcb_surface_t *surface) +{ + uint32_t values[] = { XCB_NONE }; + _cairo_xcb_connection_render_change_picture (surface->connection, + surface->picture, + XCB_RENDER_CP_CLIP_MASK, + values); +} + +static void +_cairo_xcb_surface_set_precision (cairo_xcb_surface_t *surface, + cairo_antialias_t antialias) +{ + cairo_xcb_connection_t *connection = surface->connection; + uint32_t precision; + + if (connection->force_precision != -1) + precision = connection->force_precision; + else switch (antialias) { + default: + case CAIRO_ANTIALIAS_DEFAULT: + case CAIRO_ANTIALIAS_GRAY: + case CAIRO_ANTIALIAS_NONE: + case CAIRO_ANTIALIAS_FAST: + case CAIRO_ANTIALIAS_GOOD: + precision = XCB_RENDER_POLY_MODE_IMPRECISE; + break; + case CAIRO_ANTIALIAS_SUBPIXEL: + case CAIRO_ANTIALIAS_BEST: + precision = XCB_RENDER_POLY_MODE_PRECISE; + break; + } + + if (surface->precision != precision) { + _cairo_xcb_connection_render_change_picture (connection, + surface->picture, + XCB_RENDER_CP_POLY_MODE, + &precision); + surface->precision = precision; + } +} + + +static void +_cairo_xcb_surface_ensure_picture (cairo_xcb_surface_t *surface) +{ + assert (surface->fallback == NULL); + if (surface->picture == XCB_NONE) { + uint32_t values[1]; + uint32_t flags = 0; + + if (surface->precision != XCB_RENDER_POLY_MODE_PRECISE) { + flags |= XCB_RENDER_CP_POLY_MODE; + values[0] = surface->precision; + } + + surface->picture = _cairo_xcb_connection_get_xid (surface->connection); + _cairo_xcb_connection_render_create_picture (surface->connection, + surface->picture, + surface->drawable, + surface->xrender_format, + flags, values); + } +} + +static cairo_xcb_picture_t * +_picture_from_image (cairo_xcb_surface_t *target, + xcb_render_pictformat_t format, + cairo_image_surface_t *image, + cairo_xcb_shm_info_t *shm_info) +{ + xcb_pixmap_t pixmap; + xcb_gcontext_t gc; + cairo_xcb_picture_t *picture; + + pixmap = _cairo_xcb_connection_create_pixmap (target->connection, + image->depth, + target->drawable, + image->width, image->height); + + gc = _cairo_xcb_screen_get_gc (target->screen, pixmap, image->depth); + + if (shm_info != NULL) { + _cairo_xcb_connection_shm_put_image (target->connection, + pixmap, gc, + image->width, image->height, + 0, 0, + image->width, image->height, + 0, 0, + image->depth, + shm_info->shm, + shm_info->offset); + } else { + int len; + + /* Do we need to trim the image? */ + len = CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, PIXMAN_FORMAT_BPP (image->pixman_format)); + if (len == image->stride) { + _cairo_xcb_connection_put_image (target->connection, + pixmap, gc, + image->width, image->height, + 0, 0, + image->depth, + image->stride, + image->data); + } else { + _cairo_xcb_connection_put_subimage (target->connection, + pixmap, gc, + 0, 0, + image->width, image->height, + PIXMAN_FORMAT_BPP (image->pixman_format) / 8, + image->stride, + 0, 0, + image->depth, + image->data); + + } + } + + _cairo_xcb_screen_put_gc (target->screen, image->depth, gc); + + picture = _cairo_xcb_picture_create (target->screen, + image->pixman_format, format, + image->width, image->height); + if (likely (picture->base.status == CAIRO_STATUS_SUCCESS)) { + _cairo_xcb_connection_render_create_picture (target->connection, + picture->picture, pixmap, format, + 0, 0); + } + + _cairo_xcb_connection_free_pixmap (target->connection, pixmap); + + return picture; +} + +static cairo_bool_t +_pattern_is_supported (uint32_t flags, + const cairo_pattern_t *pattern) + +{ + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) + return TRUE; + + switch (pattern->extend) { + default: + ASSERT_NOT_REACHED; + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_REPEAT: + break; + case CAIRO_EXTEND_PAD: + case CAIRO_EXTEND_REFLECT: + if ((flags & CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT) == 0) + return FALSE; + } + + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + switch (pattern->filter) { + case CAIRO_FILTER_FAST: + case CAIRO_FILTER_NEAREST: + return (flags & CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM) || + _cairo_matrix_is_integer_translation (&pattern->matrix, NULL, NULL); + case CAIRO_FILTER_GOOD: + return flags & CAIRO_XCB_RENDER_HAS_FILTER_GOOD; + case CAIRO_FILTER_BEST: + return flags & CAIRO_XCB_RENDER_HAS_FILTER_BEST; + case CAIRO_FILTER_BILINEAR: + case CAIRO_FILTER_GAUSSIAN: + default: + return flags & CAIRO_XCB_RENDER_HAS_FILTERS; + } + } else if (pattern->type == CAIRO_PATTERN_TYPE_MESH) { + return FALSE; + } else { /* gradient */ + if ((flags & CAIRO_XCB_RENDER_HAS_GRADIENTS) == 0) + return FALSE; + + /* The RENDER specification says that the inner circle has to be + * completely contained inside the outer one. */ + if (pattern->type == CAIRO_PATTERN_TYPE_RADIAL && + ! _cairo_radial_pattern_focus_is_inside ((cairo_radial_pattern_t *) pattern)) + { + return FALSE; + } + return TRUE; + } +} + +static void +_cairo_xcb_picture_set_matrix (cairo_xcb_picture_t *picture, + const cairo_matrix_t *matrix, + cairo_filter_t filter, + double xc, double yc) +{ + xcb_render_transform_t transform; + pixman_transform_t *pixman_transform; + cairo_int_status_t ignored; + + /* Casting between pixman_transform_t and xcb_render_transform_t is safe + * because they happen to be the exact same type. + */ + pixman_transform = (pixman_transform_t *) &transform; + + picture->x = picture->x0; + picture->y = picture->y0; + ignored = _cairo_matrix_to_pixman_matrix_offset (matrix, filter, xc, yc, + pixman_transform, + &picture->x, &picture->y); + (void) ignored; + + if (memcmp (&picture->transform, &transform, sizeof (xcb_render_transform_t))) { + _cairo_xcb_connection_render_set_picture_transform (_picture_to_connection (picture), + picture->picture, + &transform); + + picture->transform = transform; + } +} + +static void +_cairo_xcb_picture_set_filter (cairo_xcb_picture_t *picture, + cairo_filter_t filter) +{ + const char *render_filter; + int len; + + if (picture->filter == filter) + return; + + switch (filter) { + case CAIRO_FILTER_FAST: + render_filter = "fast"; + len = strlen ("fast"); + break; + + case CAIRO_FILTER_GOOD: + render_filter = "good"; + len = strlen ("good"); + break; + + case CAIRO_FILTER_BEST: + render_filter = "best"; + len = strlen ("best"); + break; + + case CAIRO_FILTER_NEAREST: + render_filter = "nearest"; + len = strlen ("nearest"); + break; + + case CAIRO_FILTER_BILINEAR: + render_filter = "bilinear"; + len = strlen ("bilinear"); + break; + + default: + ASSERT_NOT_REACHED; + case CAIRO_FILTER_GAUSSIAN: + render_filter = "best"; + len = strlen ("best"); + break; + } + + _cairo_xcb_connection_render_set_picture_filter (_picture_to_connection (picture), + picture->picture, + len, (char *) render_filter); + picture->filter = filter; +} + +static void +_cairo_xcb_picture_set_extend (cairo_xcb_picture_t *picture, + cairo_extend_t extend) +{ + uint32_t pa[1]; + + if (picture->extend == extend) + return; + + switch (extend) { + default: + ASSERT_NOT_REACHED; + case CAIRO_EXTEND_NONE: + pa[0] = XCB_RENDER_REPEAT_NONE; + break; + + case CAIRO_EXTEND_REPEAT: + pa[0] = XCB_RENDER_REPEAT_NORMAL; + break; + + case CAIRO_EXTEND_REFLECT: + pa[0] = XCB_RENDER_REPEAT_REFLECT; + break; + + case CAIRO_EXTEND_PAD: + pa[0] = XCB_RENDER_REPEAT_PAD; + break; + } + + _cairo_xcb_connection_render_change_picture (_picture_to_connection (picture), + picture->picture, + XCB_RENDER_CP_REPEAT, pa); + picture->extend = extend; +} + +static void +_cairo_xcb_picture_set_component_alpha (cairo_xcb_picture_t *picture, + cairo_bool_t ca) +{ + uint32_t pa[1]; + + if (picture->has_component_alpha == ca) + return; + + pa[0] = ca; + + _cairo_xcb_connection_render_change_picture (_picture_to_connection (picture), + picture->picture, + XCB_RENDER_CP_COMPONENT_ALPHA, + pa); + picture->has_component_alpha = ca; +} + +static cairo_xcb_picture_t * +_solid_picture (cairo_xcb_surface_t *target, + const cairo_color_t *color) +{ + xcb_render_color_t xcb_color; + xcb_render_pictformat_t xrender_format; + cairo_xcb_picture_t *picture; + + xcb_color.red = color->red_short; + xcb_color.green = color->green_short; + xcb_color.blue = color->blue_short; + xcb_color.alpha = color->alpha_short; + + xrender_format = target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32]; + picture = _cairo_xcb_picture_create (target->screen, + PIXMAN_a8r8g8b8, + xrender_format, + -1, -1); + if (unlikely (picture->base.status)) + return picture; + + if (target->connection->flags & CAIRO_XCB_RENDER_HAS_GRADIENTS) { + _cairo_xcb_connection_render_create_solid_fill (target->connection, + picture->picture, + xcb_color); + } else { + xcb_pixmap_t pixmap; + uint32_t values[] = { XCB_RENDER_REPEAT_NORMAL }; + + pixmap = _cairo_xcb_connection_create_pixmap (target->connection, + 32, target->drawable, 1, 1); + _cairo_xcb_connection_render_create_picture (target->connection, + picture->picture, + pixmap, + xrender_format, + XCB_RENDER_CP_REPEAT, + values); + if (target->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { + xcb_rectangle_t rect; + + rect.x = rect.y = 0; + rect.width = rect.height = 1; + + _cairo_xcb_connection_render_fill_rectangles (_picture_to_connection (picture), + XCB_RENDER_PICT_OP_SRC, + picture->picture, + xcb_color, 1, &rect); + } else { + xcb_gcontext_t gc; + uint32_t pixel; + + gc = _cairo_xcb_screen_get_gc (target->screen, pixmap, 32); + + /* XXX byte ordering? */ + pixel = ((color->alpha_short >> 8) << 24) | + ((color->red_short >> 8) << 16) | + ((color->green_short >> 8) << 8) | + ((color->blue_short >> 8) << 0); + + _cairo_xcb_connection_put_image (target->connection, + pixmap, gc, + 1, 1, 0, 0, + 32, 4, &pixel); + + _cairo_xcb_screen_put_gc (target->screen, 32, gc); + } + + _cairo_xcb_connection_free_pixmap (target->connection, pixmap); + } + + return picture; +} + +static cairo_xcb_picture_t * +_cairo_xcb_transparent_picture (cairo_xcb_surface_t *target) +{ + cairo_xcb_picture_t *picture; + + picture = (cairo_xcb_picture_t *) target->screen->stock_colors[CAIRO_STOCK_TRANSPARENT]; + if (picture == NULL) { + picture = _solid_picture (target, CAIRO_COLOR_TRANSPARENT); + target->screen->stock_colors[CAIRO_STOCK_TRANSPARENT] = &picture->base; + } + + return (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); +} + +static cairo_xcb_picture_t * +_cairo_xcb_black_picture (cairo_xcb_surface_t *target) +{ + cairo_xcb_picture_t *picture; + + picture = (cairo_xcb_picture_t *) target->screen->stock_colors[CAIRO_STOCK_BLACK]; + if (picture == NULL) { + picture = _solid_picture (target, CAIRO_COLOR_BLACK); + target->screen->stock_colors[CAIRO_STOCK_BLACK] = &picture->base; + } + + return (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); +} + +static cairo_xcb_picture_t * +_cairo_xcb_white_picture (cairo_xcb_surface_t *target) +{ + cairo_xcb_picture_t *picture; + + picture = (cairo_xcb_picture_t *) target->screen->stock_colors[CAIRO_STOCK_WHITE]; + if (picture == NULL) { + picture = _solid_picture (target, CAIRO_COLOR_WHITE); + target->screen->stock_colors[CAIRO_STOCK_WHITE] = &picture->base; + } + + return (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); +} + +static cairo_xcb_picture_t * +_cairo_xcb_solid_picture (cairo_xcb_surface_t *target, + const cairo_solid_pattern_t *pattern) +{ + cairo_xcb_picture_t *picture; + cairo_xcb_screen_t *screen; + int i, n_cached; + + if (pattern->color.alpha_short <= 0x00ff) + return _cairo_xcb_transparent_picture (target); + + if (pattern->color.alpha_short >= 0xff00) { + if (pattern->color.red_short <= 0x00ff && + pattern->color.green_short <= 0x00ff && + pattern->color.blue_short <= 0x00ff) + { + return _cairo_xcb_black_picture (target); + } + + if (pattern->color.red_short >= 0xff00 && + pattern->color.green_short >= 0xff00 && + pattern->color.blue_short >= 0xff00) + { + return _cairo_xcb_white_picture (target); + } + } + + screen = target->screen; + n_cached = screen->solid_cache_size; + for (i = 0; i < n_cached; i++) { + if (_cairo_color_equal (&screen->solid_cache[i].color, &pattern->color)) { + return (cairo_xcb_picture_t *) cairo_surface_reference (screen->solid_cache[i].picture); + } + } + + picture = _solid_picture (target, &pattern->color); + if (unlikely (picture->base.status)) + return picture; + + if (screen->solid_cache_size < ARRAY_LENGTH (screen->solid_cache)) { + i = screen->solid_cache_size++; + } else { + i = hars_petruska_f54_1_random () % ARRAY_LENGTH (screen->solid_cache); + cairo_surface_destroy (screen->solid_cache[i].picture); + } + screen->solid_cache[i].picture = cairo_surface_reference (&picture->base); + screen->solid_cache[i].color = pattern->color; + + return picture; +} + +static cairo_xcb_picture_t * +_render_to_picture (cairo_xcb_surface_t *target, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + cairo_image_surface_t *image; + cairo_xcb_shm_info_t *shm_info; + cairo_pattern_union_t copy; + cairo_status_t status; + cairo_xcb_picture_t *picture; + pixman_format_code_t pixman_format; + xcb_render_pictformat_t xrender_format; + + /* XXX handle extend modes via tiling? */ + /* XXX alpha-only masks? */ + + pixman_format = PIXMAN_a8r8g8b8; + xrender_format = target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32]; + + status = _cairo_xcb_shm_image_create (target->screen->connection, + pixman_format, + extents->width, extents->height, + &image, &shm_info); + if (unlikely (status)) + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + + _cairo_pattern_init_static_copy (©.base, pattern); + cairo_matrix_translate (©.base.matrix, extents->x, extents->y); + status = _cairo_surface_paint (&image->base, + CAIRO_OPERATOR_SOURCE, + ©.base, + NULL); + if (unlikely (status)) { + cairo_surface_destroy (&image->base); + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + } + + picture = _picture_from_image (target, xrender_format, image, shm_info); + cairo_surface_destroy (&image->base); + + if (unlikely (picture->base.status)) + return picture; + + _cairo_xcb_picture_set_component_alpha (picture, pattern->has_component_alpha); + picture->x = -extents->x; + picture->y = -extents->y; + + return picture; +} + +static xcb_render_fixed_t * +_gradient_to_xcb (const cairo_gradient_pattern_t *gradient, + unsigned int *n_stops, + char *buf, unsigned int buflen) +{ + xcb_render_fixed_t *stops; + xcb_render_color_t *colors; + unsigned int i; + + assert (gradient->n_stops > 0); + *n_stops = MAX (gradient->n_stops, 2); + + if (*n_stops * (sizeof (xcb_render_fixed_t) + sizeof (xcb_render_color_t)) < buflen) + { + stops = (xcb_render_fixed_t *) buf; + } + else + { + stops = + _cairo_malloc_ab (*n_stops, + sizeof (xcb_render_fixed_t) + sizeof (xcb_render_color_t)); + if (unlikely (stops == NULL)) + return NULL; + } + + colors = (xcb_render_color_t *) (stops + *n_stops); + for (i = 0; i < gradient->n_stops; i++) { + stops[i] = + _cairo_fixed_16_16_from_double (gradient->stops[i].offset); + + colors[i].red = gradient->stops[i].color.red_short; + colors[i].green = gradient->stops[i].color.green_short; + colors[i].blue = gradient->stops[i].color.blue_short; + colors[i].alpha = gradient->stops[i].color.alpha_short; + } + + /* RENDER does not support gradients with less than 2 stops. If a + * gradient has only a single stop, duplicate it to make RENDER + * happy. */ + if (gradient->n_stops == 1) { + stops[1] = _cairo_fixed_16_16_from_double (gradient->stops[0].offset); + + colors[1].red = gradient->stops[0].color.red_short; + colors[1].green = gradient->stops[0].color.green_short; + colors[1].blue = gradient->stops[0].color.blue_short; + colors[1].alpha = gradient->stops[0].color.alpha_short; + } + + return stops; +} + +static cairo_xcb_picture_t * +_cairo_xcb_linear_picture (cairo_xcb_surface_t *target, + const cairo_linear_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + char buf[CAIRO_STACK_BUFFER_SIZE]; + xcb_render_fixed_t *stops; + xcb_render_color_t *colors; + xcb_render_pointfix_t p1, p2; + cairo_matrix_t matrix; + cairo_circle_double_t extremes[2]; + cairo_xcb_picture_t *picture; + cairo_status_t status; + unsigned int n_stops; + + _cairo_gradient_pattern_fit_to_range (&pattern->base, PIXMAN_MAX_INT >> 1, &matrix, extremes); + + picture = (cairo_xcb_picture_t *) + _cairo_xcb_screen_lookup_linear_picture (target->screen, pattern); + if (picture != NULL) + goto setup_picture; + + stops = _gradient_to_xcb (&pattern->base, &n_stops, buf, sizeof (buf)); + if (unlikely (stops == NULL)) + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + picture = _cairo_xcb_picture_create (target->screen, + target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32], + PIXMAN_a8r8g8b8, + -1, -1); + if (unlikely (picture->base.status)) { + if (stops != (xcb_render_fixed_t *) buf) + free (stops); + return picture; + } + picture->filter = CAIRO_FILTER_DEFAULT; + + colors = (xcb_render_color_t *) (stops + n_stops); + + p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); + p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); + p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); + p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); + + _cairo_xcb_connection_render_create_linear_gradient (target->connection, + picture->picture, + p1, p2, + n_stops, + stops, colors); + + if (stops != (xcb_render_fixed_t *) buf) + free (stops); + + status = _cairo_xcb_screen_store_linear_picture (target->screen, + pattern, + &picture->base); + if (unlikely (status)) { + cairo_surface_destroy (&picture->base); + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + } + +setup_picture: + _cairo_xcb_picture_set_matrix (picture, &matrix, + pattern->base.base.filter, + extents->x + extents->width/2., + extents->y + extents->height/2.); + _cairo_xcb_picture_set_filter (picture, pattern->base.base.filter); + _cairo_xcb_picture_set_extend (picture, pattern->base.base.extend); + _cairo_xcb_picture_set_component_alpha (picture, + pattern->base.base.has_component_alpha); + + return picture; +} + +static cairo_xcb_picture_t * +_cairo_xcb_radial_picture (cairo_xcb_surface_t *target, + const cairo_radial_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + char buf[CAIRO_STACK_BUFFER_SIZE]; + xcb_render_fixed_t *stops; + xcb_render_color_t *colors; + xcb_render_pointfix_t p1, p2; + xcb_render_fixed_t r1, r2; + cairo_matrix_t matrix; + cairo_circle_double_t extremes[2]; + cairo_xcb_picture_t *picture; + cairo_status_t status; + unsigned int n_stops; + + _cairo_gradient_pattern_fit_to_range (&pattern->base, PIXMAN_MAX_INT >> 1, &matrix, extremes); + + picture = (cairo_xcb_picture_t *) + _cairo_xcb_screen_lookup_radial_picture (target->screen, pattern); + if (picture != NULL) + goto setup_picture; + + stops = _gradient_to_xcb (&pattern->base, &n_stops, buf, sizeof (buf)); + if (unlikely (stops == NULL)) + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + picture = _cairo_xcb_picture_create (target->screen, + target->screen->connection->standard_formats[CAIRO_FORMAT_ARGB32], + PIXMAN_a8r8g8b8, + -1, -1); + if (unlikely (picture->base.status)) { + if (stops != (xcb_render_fixed_t *) buf) + free (stops); + return picture; + } + picture->filter = CAIRO_FILTER_DEFAULT; + + colors = (xcb_render_color_t *) (stops + n_stops); + + p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); + p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); + p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); + p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); + + r1 = _cairo_fixed_16_16_from_double (extremes[0].radius); + r2 = _cairo_fixed_16_16_from_double (extremes[1].radius); + + _cairo_xcb_connection_render_create_radial_gradient (target->connection, + picture->picture, + p1, p2, r1, r2, + n_stops, + stops, colors); + + if (stops != (xcb_render_fixed_t *) buf) + free (stops); + + status = _cairo_xcb_screen_store_radial_picture (target->screen, + pattern, + &picture->base); + if (unlikely (status)) { + cairo_surface_destroy (&picture->base); + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + } + +setup_picture: + _cairo_xcb_picture_set_matrix (picture, &matrix, + pattern->base.base.filter, + extents->x + extents->width/2., + extents->y + extents->height/2.); + _cairo_xcb_picture_set_filter (picture, pattern->base.base.filter); + _cairo_xcb_picture_set_extend (picture, pattern->base.base.extend); + _cairo_xcb_picture_set_component_alpha (picture, + pattern->base.base.has_component_alpha); + + return picture; +} + +static cairo_xcb_picture_t * +_copy_to_picture (cairo_xcb_surface_t *source) +{ + cairo_xcb_picture_t *picture; + uint32_t values[] = { 0, 1 }; + + if (source->deferred_clear) { + cairo_status_t status = _cairo_xcb_surface_clear (source); + if (unlikely (status)) + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + } + + picture = _cairo_xcb_picture_create (source->screen, + source->xrender_format, + source->pixman_format, + source->width, + source->height); + if (unlikely (picture->base.status)) + return picture; + + _cairo_xcb_connection_render_create_picture (source->connection, + picture->picture, + source->drawable, + source->xrender_format, + XCB_RENDER_CP_GRAPHICS_EXPOSURE | + XCB_RENDER_CP_SUBWINDOW_MODE, + values); + + return picture; +} + +static void +_cairo_xcb_surface_setup_surface_picture(cairo_xcb_picture_t *picture, + const cairo_surface_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + cairo_filter_t filter; + + filter = pattern->base.filter; + if (filter != CAIRO_FILTER_NEAREST && + _cairo_matrix_is_pixel_exact (&pattern->base.matrix)) + { + filter = CAIRO_FILTER_NEAREST; + } + _cairo_xcb_picture_set_filter (picture, filter); + + _cairo_xcb_picture_set_matrix (picture, + &pattern->base.matrix, filter, + extents->x + extents->width/2., + extents->y + extents->height/2.); + + + _cairo_xcb_picture_set_extend (picture, pattern->base.extend); + _cairo_xcb_picture_set_component_alpha (picture, pattern->base.has_component_alpha); +} + +static cairo_xcb_picture_t * +record_to_picture (cairo_surface_t *target, + const cairo_surface_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_pattern_t tmp_pattern; + cairo_xcb_picture_t *picture; + cairo_status_t status; + cairo_matrix_t matrix; + cairo_surface_t *tmp; + cairo_surface_t *source; + cairo_rectangle_int_t limit; + cairo_extend_t extend; + + /* XXX: The following was once more or less copied from cairo-xlibs-ource.c, + * record_source() and recording_pattern_get_surface(), can we share a + * single version? + */ + + /* First get the 'real' recording surface and figure out the size for tmp */ + source = _cairo_pattern_get_source (pattern, &limit); + assert (_cairo_surface_is_recording (source)); + + if (! _cairo_matrix_is_identity (&pattern->base.matrix)) { + double x1, y1, x2, y2; + + matrix = pattern->base.matrix; + status = cairo_matrix_invert (&matrix); + assert (status == CAIRO_STATUS_SUCCESS); + + x1 = limit.x; + y1 = limit.y; + x2 = limit.x + limit.width; + y2 = limit.y + limit.height; + + _cairo_matrix_transform_bounding_box (&matrix, + &x1, &y1, &x2, &y2, NULL); + + limit.x = floor (x1); + limit.y = floor (y1); + limit.width = ceil (x2) - limit.x; + limit.height = ceil (y2) - limit.y; + } + extend = pattern->base.extend; + if (_cairo_rectangle_contains_rectangle (&limit, extents)) + extend = CAIRO_EXTEND_NONE; + if (extend == CAIRO_EXTEND_NONE && ! _cairo_rectangle_intersect (&limit, extents)) + return _cairo_xcb_transparent_picture ((cairo_xcb_surface_t *) target); + + /* Now draw the recording surface to an xcb surface */ + tmp = _cairo_surface_create_scratch (target, + source->content, + limit.width, + limit.height, + CAIRO_COLOR_TRANSPARENT); + if (tmp->status != CAIRO_STATUS_SUCCESS) { + return (cairo_xcb_picture_t *) tmp; + } + + cairo_matrix_init_translate (&matrix, limit.x, limit.y); + cairo_matrix_multiply (&matrix, &matrix, &pattern->base.matrix); + + status = _cairo_recording_surface_replay_with_clip (source, + &matrix, tmp, + NULL); + if (unlikely (status)) { + cairo_surface_destroy (tmp); + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + } + + /* Now that we have drawn this to an xcb surface, try again with that */ + _cairo_pattern_init_static_copy (&tmp_pattern.base, &pattern->base); + tmp_pattern.surface = tmp; + cairo_matrix_init_translate (&tmp_pattern.base.matrix, -limit.x, -limit.y); + + picture = _copy_to_picture ((cairo_xcb_surface_t *) tmp); + if (picture->base.status == CAIRO_STATUS_SUCCESS) + _cairo_xcb_surface_setup_surface_picture (picture, &tmp_pattern, extents); + cairo_surface_destroy (tmp); + return picture; +} + +static cairo_xcb_picture_t * +_cairo_xcb_surface_picture (cairo_xcb_surface_t *target, + const cairo_surface_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + cairo_surface_t *source = pattern->surface; + cairo_xcb_picture_t *picture; + + picture = (cairo_xcb_picture_t *) + _cairo_surface_has_snapshot (source, &_cairo_xcb_picture_backend); + if (picture != NULL) { + if (picture->screen == target->screen) { + picture = (cairo_xcb_picture_t *) cairo_surface_reference (&picture->base); + _cairo_xcb_surface_setup_surface_picture (picture, pattern, extents); + return picture; + } + picture = NULL; + } + + if (source->type == CAIRO_SURFACE_TYPE_XCB) + { + if (_cairo_surface_is_xcb(source)) { + cairo_xcb_surface_t *xcb = (cairo_xcb_surface_t *) source; + if (xcb->screen == target->screen && xcb->fallback == NULL) { + picture = _copy_to_picture ((cairo_xcb_surface_t *) source); + if (unlikely (picture->base.status)) + return picture; + } + } else if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; + cairo_xcb_surface_t *xcb = (cairo_xcb_surface_t *) sub->target; + + /* XXX repeat interval with source clipping? */ + if (FALSE && xcb->screen == target->screen && xcb->fallback == NULL) { + xcb_rectangle_t rect; + + picture = _copy_to_picture (xcb); + if (unlikely (picture->base.status)) + return picture; + + rect.x = sub->extents.x; + rect.y = sub->extents.y; + rect.width = sub->extents.width; + rect.height = sub->extents.height; + + _cairo_xcb_connection_render_set_picture_clip_rectangles (xcb->connection, + picture->picture, + 0, 0, + 1, &rect); + picture->x0 = rect.x; + picture->y0 = rect.y; + picture->width = rect.width; + picture->height = rect.height; + } + } else if (_cairo_surface_is_snapshot (source)) { + cairo_surface_snapshot_t *snap = (cairo_surface_snapshot_t *) source; + cairo_xcb_surface_t *xcb = (cairo_xcb_surface_t *) snap->target; + + if (xcb->screen == target->screen && xcb->fallback == NULL) { + picture = _copy_to_picture (xcb); + if (unlikely (picture->base.status)) + return picture; + } + } + } +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS + else if (source->type == CAIRO_SURFACE_TYPE_XLIB) + { + if (source->backend->type == CAIRO_SURFACE_TYPE_XLIB) { + cairo_xcb_surface_t *xcb = ((cairo_xlib_xcb_surface_t *) source)->xcb; + if (xcb->screen == target->screen && xcb->fallback == NULL) { + picture = _copy_to_picture (xcb); + if (unlikely (picture->base.status)) + return picture; + } + } else if (source->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) { + cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source; + cairo_xcb_surface_t *xcb = ((cairo_xlib_xcb_surface_t *) sub->target)->xcb; + + if (FALSE && xcb->screen == target->screen && xcb->fallback == NULL) { + xcb_rectangle_t rect; + + picture = _copy_to_picture (xcb); + if (unlikely (picture->base.status)) + return picture; + + rect.x = sub->extents.x; + rect.y = sub->extents.y; + rect.width = sub->extents.width; + rect.height = sub->extents.height; + + _cairo_xcb_connection_render_set_picture_clip_rectangles (xcb->connection, + picture->picture, + 0, 0, + 1, &rect); + picture->x0 = rect.x; + picture->y0 = rect.y; + picture->width = rect.width; + picture->height = rect.height; + } + } else if (_cairo_surface_is_snapshot (source)) { + cairo_surface_snapshot_t *snap = (cairo_surface_snapshot_t *) source; + cairo_xcb_surface_t *xcb = ((cairo_xlib_xcb_surface_t *) snap->target)->xcb; + + if (xcb->screen == target->screen && xcb->fallback == NULL) { + picture = _copy_to_picture (xcb); + if (unlikely (picture->base.status)) + return picture; + } + } + } +#endif +#if CAIRO_HAS_GL_FUNCTIONS + else if (source->type == CAIRO_SURFACE_TYPE_GL) + { + /* pixmap from texture */ + } +#endif + else if (source->type == CAIRO_SURFACE_TYPE_RECORDING) + { + /* We have to skip the call to attach_snapshot() because we possibly + * only drew part of the recording surface. + * TODO: When can we safely attach a snapshot? + */ + return record_to_picture(&target->base, pattern, extents); + } + + if (picture == NULL) { + cairo_image_surface_t *image; + void *image_extra; + cairo_status_t status; + + status = _cairo_surface_acquire_source_image (source, &image, &image_extra); + if (unlikely (status)) + return (cairo_xcb_picture_t *) _cairo_surface_create_in_error (status); + + if (image->format != CAIRO_FORMAT_INVALID) { + xcb_render_pictformat_t format; + + format = target->screen->connection->standard_formats[image->format]; + + picture = _picture_from_image (target, format, image, NULL); + _cairo_surface_release_source_image (source, image, image_extra); + } else { + cairo_image_surface_t *conv; + xcb_render_pictformat_t render_format; + + /* XXX XRenderPutImage! */ + + conv = _cairo_image_surface_coerce (image); + _cairo_surface_release_source_image (source, image, image_extra); + if (unlikely (conv->base.status)) + return (cairo_xcb_picture_t *) conv; + + render_format = target->screen->connection->standard_formats[conv->format]; + picture = _picture_from_image (target, render_format, conv, NULL); + cairo_surface_destroy (&conv->base); + } + + if (unlikely (picture->base.status)) + return picture; + } + + /* XXX: This causes too many problems and bugs, let's skip it for now. */ +#if 0 + _cairo_surface_attach_snapshot (source, + &picture->base, + NULL); +#endif + + _cairo_xcb_surface_setup_surface_picture (picture, pattern, extents); + return picture; +} + +static cairo_xcb_picture_t * +_cairo_xcb_picture_for_pattern (cairo_xcb_surface_t *target, + const cairo_pattern_t *pattern, + const cairo_rectangle_int_t *extents) +{ + if (pattern == NULL) + return _cairo_xcb_white_picture (target); + + if (! _pattern_is_supported (target->connection->flags, pattern)) + return _render_to_picture (target, pattern, extents); + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + return _cairo_xcb_solid_picture (target, (cairo_solid_pattern_t *) pattern); + + case CAIRO_PATTERN_TYPE_LINEAR: + return _cairo_xcb_linear_picture (target, + (cairo_linear_pattern_t *) pattern, + extents); + + case CAIRO_PATTERN_TYPE_RADIAL: + return _cairo_xcb_radial_picture (target, + (cairo_radial_pattern_t *) pattern, + extents); + + case CAIRO_PATTERN_TYPE_SURFACE: + return _cairo_xcb_surface_picture (target, + (cairo_surface_pattern_t *) pattern, + extents); + default: + ASSERT_NOT_REACHED; + case CAIRO_PATTERN_TYPE_MESH: + case CAIRO_PATTERN_TYPE_RASTER_SOURCE: + return _render_to_picture (target, pattern, extents); + } +} + +COMPILE_TIME_ASSERT (sizeof (xcb_rectangle_t) <= sizeof (cairo_box_t)); + +static cairo_status_t +_render_fill_boxes (void *abstract_dst, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + cairo_xcb_surface_t *dst = abstract_dst; + xcb_rectangle_t stack_xrects[CAIRO_STACK_ARRAY_LENGTH (xcb_rectangle_t)]; + xcb_rectangle_t *xrects = stack_xrects; + xcb_render_color_t render_color; + int render_op = _render_operator (op); + struct _cairo_boxes_chunk *chunk; + int max_count; + + render_color.red = color->red_short; + render_color.green = color->green_short; + render_color.blue = color->blue_short; + render_color.alpha = color->alpha_short; + + max_count = 0; + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + if (chunk->count > max_count) + max_count = chunk->count; + } + if (max_count > ARRAY_LENGTH (stack_xrects)) { + xrects = _cairo_malloc_ab (max_count, sizeof (xcb_rectangle_t)); + if (unlikely (xrects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + int i, j; + + for (i = j = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_round_down (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_round_down (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_round_down (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_round_down (chunk->base[i].p2.y); + + if (x2 > x1 && y2 > y1) { + xrects[j].x = x1; + xrects[j].y = y1; + xrects[j].width = x2 - x1; + xrects[j].height = y2 - y1; + j++; + } + } + + if (j) { + _cairo_xcb_connection_render_fill_rectangles + (dst->connection, + render_op, dst->picture, + render_color, j, xrects); + } + } + + if (xrects != stack_xrects) + free (xrects); + + return CAIRO_STATUS_SUCCESS; +} + +/* pixel aligned, non-overlapping boxes */ +static cairo_int_status_t +_render_composite_boxes (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + const cairo_pattern_t *mask_pattern, + const cairo_rectangle_int_t *extents, + const cairo_boxes_t *boxes) +{ + cairo_xcb_picture_t *src, *mask; + const struct _cairo_boxes_chunk *chunk; + xcb_rectangle_t stack_boxes[CAIRO_STACK_ARRAY_LENGTH (xcb_rectangle_t)]; + xcb_rectangle_t *clip_boxes; + cairo_rectangle_int_t stack_extents; + cairo_status_t status; + int num_boxes; + int render_op; + + render_op = _render_operator (op); + + if (src_pattern == NULL) { + src_pattern = mask_pattern; + mask_pattern = NULL; + } + + /* amalgamate into a single Composite call by setting a clip region */ + clip_boxes = stack_boxes; + if (boxes->num_boxes > ARRAY_LENGTH (stack_boxes)) { + clip_boxes = _cairo_malloc_ab (boxes->num_boxes, sizeof (xcb_rectangle_t)); + if (unlikely (clip_boxes == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + src = _cairo_xcb_picture_for_pattern (dst, src_pattern, extents); + status = src->base.status; + if (unlikely (status)) + goto cleanup_boxes; + + num_boxes = 0; + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + const cairo_box_t *box = chunk->base; + int i; + + for (i = 0; i < chunk->count; i++) { + int x = _cairo_fixed_integer_round_down (box[i].p1.x); + int y = _cairo_fixed_integer_round_down (box[i].p1.y); + int width = _cairo_fixed_integer_round_down (box[i].p2.x) - x; + int height = _cairo_fixed_integer_round_down (box[i].p2.y) - y; + + if (width && height) { + clip_boxes[num_boxes].x = x; + clip_boxes[num_boxes].y = y; + clip_boxes[num_boxes].width = width; + clip_boxes[num_boxes].height = height; + num_boxes++; + } + } + } + + if (num_boxes) { + if (num_boxes > 1) { + _cairo_xcb_connection_render_set_picture_clip_rectangles (dst->connection, + dst->picture, + 0, 0, + num_boxes, + clip_boxes); + } else { + stack_extents.x = clip_boxes[0].x; + stack_extents.y = clip_boxes[0].y; + stack_extents.width = clip_boxes[0].width; + stack_extents.height = clip_boxes[0].height; + extents = &stack_extents; + } + + if (mask_pattern != NULL) { + mask = _cairo_xcb_picture_for_pattern (dst, mask_pattern, extents); + status = mask->base.status; + if (unlikely (status)) + goto cleanup_clip; + + _cairo_xcb_connection_render_composite (dst->connection, + render_op, + src->picture, + mask->picture, + dst->picture, + src->x + extents->x, src->y + extents->y, + mask->x + extents->x, mask->y + extents->y, + extents->x, extents->y, + extents->width, extents->height); + + cairo_surface_destroy (&mask->base); + } else { + _cairo_xcb_connection_render_composite (dst->connection, + render_op, + src->picture, + XCB_NONE, + dst->picture, + src->x + extents->x, src->y + extents->y, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + } + +cleanup_clip: + + if (num_boxes > 1) + _cairo_xcb_surface_clear_clip_region (dst); + } + + cairo_surface_destroy (&src->base); + +cleanup_boxes: + + if (clip_boxes != stack_boxes) + free (clip_boxes); + + return status; +} + + +#define CAIRO_FIXED_16_16_MIN _cairo_fixed_from_int (-32768) +#define CAIRO_FIXED_16_16_MAX _cairo_fixed_from_int (32767) + +static cairo_bool_t +_line_exceeds_16_16 (const cairo_line_t *line) +{ + return + line->p1.x <= CAIRO_FIXED_16_16_MIN || + line->p1.x >= CAIRO_FIXED_16_16_MAX || + + line->p2.x <= CAIRO_FIXED_16_16_MIN || + line->p2.x >= CAIRO_FIXED_16_16_MAX || + + line->p1.y <= CAIRO_FIXED_16_16_MIN || + line->p1.y >= CAIRO_FIXED_16_16_MAX || + + line->p2.y <= CAIRO_FIXED_16_16_MIN || + line->p2.y >= CAIRO_FIXED_16_16_MAX; +} + +static void +_project_line_x_onto_16_16 (const cairo_line_t *line, + cairo_fixed_t top, + cairo_fixed_t bottom, + xcb_render_linefix_t *out) +{ + cairo_point_double_t p1, p2; + double m; + + p1.x = _cairo_fixed_to_double (line->p1.x); + p1.y = _cairo_fixed_to_double (line->p1.y); + + p2.x = _cairo_fixed_to_double (line->p2.x); + p2.y = _cairo_fixed_to_double (line->p2.y); + + m = (p2.x - p1.x) / (p2.y - p1.y); + out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); + out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); +} + +typedef struct { + cairo_traps_t traps; + cairo_antialias_t antialias; +} composite_traps_info_t; + +COMPILE_TIME_ASSERT (sizeof (xcb_render_trapezoid_t) <= sizeof (cairo_trapezoid_t)); + +static cairo_int_status_t +_composite_traps (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + composite_traps_info_t *info = closure; + const cairo_traps_t *traps = &info->traps; + cairo_xcb_picture_t *src; + cairo_format_t format; + xcb_render_pictformat_t xrender_format; + xcb_render_trapezoid_t *xtraps; + int render_reference_x, render_reference_y; + cairo_status_t status; + int i; + + if (dst->deferred_clear) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) + return status; + } + + src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); + if (unlikely (src->base.status)) + return src->base.status; + + if (info->antialias == CAIRO_ANTIALIAS_NONE) + format = CAIRO_FORMAT_A1; + else + format = CAIRO_FORMAT_A8; + xrender_format = dst->screen->connection->standard_formats[format]; + + xtraps = (xcb_render_trapezoid_t *) traps->traps; + for (i = 0; i < traps->num_traps; i++) { + cairo_trapezoid_t t = traps->traps[i]; + + /* top/bottom will be clamped to surface bounds */ + xtraps[i].top = _cairo_fixed_to_16_16 (t.top); + xtraps[i].top -= dst_y << 16; + xtraps[i].bottom = _cairo_fixed_to_16_16 (t.bottom); + xtraps[i].bottom -= dst_y << 16; + + /* However, all the other coordinates will have been left untouched so + * as not to introduce numerical error. Recompute them if they + * exceed the 16.16 limits. + */ + if (unlikely (_line_exceeds_16_16 (&t.left))) { + _project_line_x_onto_16_16 (&t.left, + t.top, + t.bottom, + &xtraps[i].left); + xtraps[i].left.p1.y = xtraps[i].top; + xtraps[i].left.p2.y = xtraps[i].bottom; + } else { + xtraps[i].left.p1.x = _cairo_fixed_to_16_16 (t.left.p1.x); + xtraps[i].left.p1.y = _cairo_fixed_to_16_16 (t.left.p1.y); + xtraps[i].left.p2.x = _cairo_fixed_to_16_16 (t.left.p2.x); + xtraps[i].left.p2.y = _cairo_fixed_to_16_16 (t.left.p2.y); + } + xtraps[i].left.p1.x -= dst_x << 16; + xtraps[i].left.p1.y -= dst_y << 16; + xtraps[i].left.p2.x -= dst_x << 16; + xtraps[i].left.p2.y -= dst_y << 16; + + if (unlikely (_line_exceeds_16_16 (&t.right))) { + _project_line_x_onto_16_16 (&t.right, + t.top, + t.bottom, + &xtraps[i].right); + xtraps[i].right.p1.y = xtraps[i].top; + xtraps[i].right.p2.y = xtraps[i].bottom; + } else { + xtraps[i].right.p1.x = _cairo_fixed_to_16_16 (t.right.p1.x); + xtraps[i].right.p1.y = _cairo_fixed_to_16_16 (t.right.p1.y); + xtraps[i].right.p2.x = _cairo_fixed_to_16_16 (t.right.p2.x); + xtraps[i].right.p2.y = _cairo_fixed_to_16_16 (t.right.p2.y); + } + xtraps[i].right.p1.x -= dst_x << 16; + xtraps[i].right.p1.y -= dst_y << 16; + xtraps[i].right.p2.x -= dst_x << 16; + xtraps[i].right.p2.y -= dst_y << 16; + } + + if (xtraps[0].left.p1.y < xtraps[0].left.p2.y) { + render_reference_x = xtraps[0].left.p1.x >> 16; + render_reference_y = xtraps[0].left.p1.y >> 16; + } else { + render_reference_x = xtraps[0].left.p2.x >> 16; + render_reference_y = xtraps[0].left.p2.y >> 16; + } + render_reference_x += src->x + dst_x; + render_reference_y += src->y + dst_y; + + _cairo_xcb_surface_set_precision (dst, info->antialias); + _cairo_xcb_connection_render_trapezoids (dst->connection, + _render_operator (op), + src->picture, + dst->picture, + xrender_format, + render_reference_x, + render_reference_y, + traps->num_traps, xtraps); + + cairo_surface_destroy (&src->base); + + return CAIRO_STATUS_SUCCESS; +} + +/* low-level composite driver */ + +static cairo_xcb_surface_t * +get_clip_surface (const cairo_clip_t *clip, + cairo_xcb_surface_t *target, + int *tx, int *ty) +{ + cairo_surface_t *surface; + cairo_status_t status; + + surface = _cairo_surface_create_scratch (&target->base, + CAIRO_CONTENT_ALPHA, + clip->extents.width, + clip->extents.height, + CAIRO_COLOR_WHITE); + if (unlikely (surface->status)) + return (cairo_xcb_surface_t *) surface; + + assert (surface->backend == &_cairo_xcb_surface_backend); + status = _cairo_clip_combine_with_surface (clip, surface, + clip->extents.x, clip->extents.y); + if (unlikely (status)) { + cairo_surface_destroy (surface); + surface = _cairo_surface_create_in_error (status); + } + + *tx = clip->extents.x; + *ty = clip->extents.y; + + return (cairo_xcb_surface_t *) surface; +} + +typedef cairo_int_status_t +(*xcb_draw_func_t) (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip); + +static void do_unaligned_row(void (*blt)(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage), + void *closure, + const cairo_box_t *b, + int tx, int y, int h, + uint16_t coverage) +{ + int x1 = _cairo_fixed_integer_part (b->p1.x) - tx; + int x2 = _cairo_fixed_integer_part (b->p2.x) - tx; + if (x2 > x1) { + if (! _cairo_fixed_is_integer (b->p1.x)) { + blt(closure, x1, y, 1, h, + coverage * (256 - _cairo_fixed_fractional_part (b->p1.x))); + x1++; + } + + if (x2 > x1) + blt(closure, x1, y, x2-x1, h, (coverage << 8) - (coverage >> 8)); + + if (! _cairo_fixed_is_integer (b->p2.x)) + blt(closure, x2, y, 1, h, + coverage * _cairo_fixed_fractional_part (b->p2.x)); + } else + blt(closure, x1, y, 1, h, + coverage * (b->p2.x - b->p1.x)); +} + +static void do_unaligned_box(void (*blt)(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage), + void *closure, + const cairo_box_t *b, int tx, int ty) +{ + int y1 = _cairo_fixed_integer_part (b->p1.y) - ty; + int y2 = _cairo_fixed_integer_part (b->p2.y) - ty; + if (y2 > y1) { + if (! _cairo_fixed_is_integer (b->p1.y)) { + do_unaligned_row(blt, closure, b, tx, y1, 1, + 256 - _cairo_fixed_fractional_part (b->p1.y)); + y1++; + } + + if (y2 > y1) + do_unaligned_row(blt, closure, b, tx, y1, y2-y1, 256); + + if (! _cairo_fixed_is_integer (b->p2.y)) + do_unaligned_row(blt, closure, b, tx, y2, 1, + _cairo_fixed_fractional_part (b->p2.y)); + } else + do_unaligned_row(blt, closure, b, tx, y1, 1, + b->p2.y - b->p1.y); +} + + +static void blt_in(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + cairo_xcb_surface_t *mask = closure; + xcb_render_color_t color; + xcb_rectangle_t rect; + + if (coverage == 0xffff) + return; + + color.red = color.green = color.blue = 0; + color.alpha = coverage; + + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + + _cairo_xcb_connection_render_fill_rectangles (mask->connection, + XCB_RENDER_PICT_OP_IN, + mask->picture, + color, 1, &rect); +} + +static cairo_xcb_surface_t * +_create_composite_mask (cairo_clip_t *clip, + xcb_draw_func_t draw_func, + xcb_draw_func_t mask_func, + void *draw_closure, + cairo_xcb_surface_t *dst, + const cairo_rectangle_int_t*extents) +{ + cairo_xcb_surface_t *surface; + cairo_bool_t need_clip_combine; + cairo_int_status_t status; + + surface = (cairo_xcb_surface_t *) + _cairo_xcb_surface_create_similar (dst, CAIRO_CONTENT_ALPHA, + extents->width, extents->height); + if (unlikely (surface->base.status)) + return surface; + + _cairo_xcb_surface_ensure_picture (surface); + + surface->deferred_clear_color = *CAIRO_COLOR_TRANSPARENT; + surface->deferred_clear = TRUE; + surface->base.is_clear = TRUE; + + if (mask_func) { + status = mask_func (draw_closure, surface, + CAIRO_OPERATOR_ADD, NULL, + extents->x, extents->y, + extents, clip); + if (likely (status != CAIRO_INT_STATUS_UNSUPPORTED)) + return surface; + } + + /* Is it worth setting the clip region here? */ + status = draw_func (draw_closure, surface, + CAIRO_OPERATOR_ADD, NULL, + extents->x, extents->y, + extents, NULL); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return (cairo_xcb_surface_t *) _cairo_surface_create_in_error (status); + } + + if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { + int i; + + for (i = 0; i < clip->num_boxes; i++) { + cairo_box_t *b = &clip->boxes[i]; + + if (! _cairo_fixed_is_integer (b->p1.x) || + ! _cairo_fixed_is_integer (b->p1.y) || + ! _cairo_fixed_is_integer (b->p2.x) || + ! _cairo_fixed_is_integer (b->p2.y)) + { + do_unaligned_box(blt_in, surface, b, extents->x, extents->y); + } + } + + need_clip_combine = clip->path != NULL; + } else + need_clip_combine = ! _cairo_clip_is_region (clip); + + if (need_clip_combine) { + status = _cairo_clip_combine_with_surface (clip, &surface->base, + extents->x, extents->y); + if (unlikely (status)) { + cairo_surface_destroy (&surface->base); + return (cairo_xcb_surface_t *) _cairo_surface_create_in_error (status); + } + } + + return surface; +} + +/* Handles compositing with a clip surface when the operator allows + * us to combine the clip with the mask + */ +static cairo_status_t +_clip_and_composite_with_mask (cairo_clip_t *clip, + cairo_operator_t op, + const cairo_pattern_t *pattern, + xcb_draw_func_t draw_func, + xcb_draw_func_t mask_func, + void *draw_closure, + cairo_xcb_surface_t *dst, + const cairo_rectangle_int_t*extents) +{ + cairo_xcb_surface_t *mask; + cairo_xcb_picture_t *src; + + mask = _create_composite_mask (clip, + draw_func, mask_func, draw_closure, + dst, extents); + if (unlikely (mask->base.status)) + return mask->base.status; + + if (pattern != NULL || dst->base.content != CAIRO_CONTENT_ALPHA) { + src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); + if (unlikely (src->base.status)) { + cairo_surface_destroy (&mask->base); + return src->base.status; + } + + _cairo_xcb_connection_render_composite (dst->connection, + _render_operator (op), + src->picture, + mask->picture, + dst->picture, + extents->x + src->x, extents->y + src->y, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + + cairo_surface_destroy (&src->base); + } else { + _cairo_xcb_connection_render_composite (dst->connection, + _render_operator (op), + mask->picture, + XCB_NONE, + dst->picture, + 0, 0, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + } + cairo_surface_destroy (&mask->base); + + return CAIRO_STATUS_SUCCESS; +} + +/* Handles compositing with a clip surface when we have to do the operation + * in two pieces and combine them together. + */ +static cairo_status_t +_clip_and_composite_combine (cairo_clip_t *clip, + cairo_operator_t op, + const cairo_pattern_t *pattern, + xcb_draw_func_t draw_func, + void *draw_closure, + cairo_xcb_surface_t *dst, + const cairo_rectangle_int_t*extents) +{ + cairo_xcb_surface_t *tmp; + cairo_xcb_surface_t *clip_surface; + int clip_x = 0, clip_y = 0; + xcb_render_picture_t clip_picture; + cairo_status_t status; + + tmp = (cairo_xcb_surface_t *) + _cairo_xcb_surface_create_similar (dst, dst->base.content, + extents->width, extents->height); + if (unlikely (tmp->base.status)) + return tmp->base.status; + + /* create_similar() could have done a fallback to an image surface */ + assert (tmp->base.backend == &_cairo_xcb_surface_backend); + + _cairo_xcb_surface_ensure_picture (tmp); + + if (pattern == NULL) { + status = (*draw_func) (draw_closure, tmp, + CAIRO_OPERATOR_ADD, NULL, + extents->x, extents->y, + extents, NULL); + } else { + /* Initialize the temporary surface from the destination surface */ + if (! dst->base.is_clear || + (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) == 0) + { + /* XCopyArea may actually be quicker here. + * A good driver should translate if appropriate. + */ + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_SRC, + dst->picture, + XCB_NONE, + tmp->picture, + extents->x, extents->y, + 0, 0, + 0, 0, + extents->width, extents->height); + } + else + { + xcb_render_color_t clear; + xcb_rectangle_t xrect; + + clear.red = clear.green = clear.blue = clear.alpha = 0; + + xrect.x = xrect.y = 0; + xrect.width = extents->width; + xrect.height = extents->height; + + _cairo_xcb_connection_render_fill_rectangles (dst->connection, + XCB_RENDER_PICT_OP_CLEAR, + dst->picture, + clear, 1, &xrect); + } + + status = (*draw_func) (draw_closure, tmp, op, pattern, + extents->x, extents->y, + extents, NULL); + } + if (unlikely (status)) + goto CLEANUP_SURFACE; + + clip_surface = get_clip_surface (clip, dst, &clip_x, &clip_y); + status = clip_surface->base.status; + if (unlikely (status)) + goto CLEANUP_SURFACE; + + assert (clip_surface->base.backend == &_cairo_xcb_surface_backend); + clip_picture = clip_surface->picture; + assert (clip_picture != XCB_NONE); + + if (dst->base.is_clear) { + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_SRC, + tmp->picture, clip_picture, dst->picture, + 0, 0, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + } else { + /* Punch the clip out of the destination */ + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_OUT_REVERSE, + clip_picture, XCB_NONE, dst->picture, + extents->x - clip_x, + extents->y - clip_y, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + + /* Now add the two results together */ + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_ADD, + tmp->picture, clip_picture, dst->picture, + 0, 0, + extents->x - clip_x, + extents->y - clip_y, + extents->x, extents->y, + extents->width, extents->height); + } + cairo_surface_destroy (&clip_surface->base); + + CLEANUP_SURFACE: + cairo_surface_destroy (&tmp->base); + + return status; +} + +/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's + * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) + */ +static cairo_status_t +_clip_and_composite_source (cairo_clip_t *clip, + const cairo_pattern_t *pattern, + xcb_draw_func_t draw_func, + xcb_draw_func_t mask_func, + void *draw_closure, + cairo_xcb_surface_t *dst, + const cairo_rectangle_int_t *extents) +{ + cairo_xcb_surface_t *mask; + cairo_xcb_picture_t *src; + + /* Create a surface that is mask IN clip */ + mask = _create_composite_mask (clip, + draw_func, mask_func, draw_closure, + dst, extents); + if (unlikely (mask->base.status)) + return mask->base.status; + + src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); + if (unlikely (src->base.status)) { + cairo_surface_destroy (&mask->base); + return src->base.status; + } + + if (dst->base.is_clear) { + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_SRC, + src->picture, + mask->picture, + dst->picture, + extents->x + src->x, extents->y + src->y, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + } else { + /* Compute dest' = dest OUT (mask IN clip) */ + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_OUT_REVERSE, + mask->picture, + XCB_NONE, + dst->picture, + 0, 0, 0, 0, + extents->x, extents->y, + extents->width, extents->height); + + /* Now compute (src IN (mask IN clip)) ADD dest' */ + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_ADD, + src->picture, + mask->picture, + dst->picture, + extents->x + src->x, extents->y + src->y, + 0, 0, + extents->x, extents->y, + extents->width, extents->height); + } + + cairo_surface_destroy (&src->base); + cairo_surface_destroy (&mask->base); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +can_reduce_alpha_op (cairo_operator_t op) +{ + int iop = op; + switch (iop) { + case CAIRO_OPERATOR_OVER: + case CAIRO_OPERATOR_SOURCE: + case CAIRO_OPERATOR_ADD: + return TRUE; + default: + return FALSE; + } +} + +static cairo_bool_t +reduce_alpha_op (cairo_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *pattern) +{ + return dst->is_clear && + dst->content == CAIRO_CONTENT_ALPHA && + _cairo_pattern_is_opaque_solid (pattern) && + can_reduce_alpha_op (op); +} + +static cairo_status_t +_cairo_xcb_surface_fixup_unbounded (cairo_xcb_surface_t *dst, + const cairo_composite_rectangles_t *rects) +{ + xcb_rectangle_t xrects[4]; + int n; + + if (rects->bounded.width == rects->unbounded.width && + rects->bounded.height == rects->unbounded.height) + { + return CAIRO_STATUS_SUCCESS; + } + + n = 0; + if (rects->bounded.width == 0 || rects->bounded.height == 0) { + xrects[n].x = rects->unbounded.x; + xrects[n].width = rects->unbounded.width; + xrects[n].y = rects->unbounded.y; + xrects[n].height = rects->unbounded.height; + n++; + } else { + /* top */ + if (rects->bounded.y != rects->unbounded.y) { + xrects[n].x = rects->unbounded.x; + xrects[n].width = rects->unbounded.width; + xrects[n].y = rects->unbounded.y; + xrects[n].height = rects->bounded.y - rects->unbounded.y; + n++; + } + /* left */ + if (rects->bounded.x != rects->unbounded.x) { + xrects[n].x = rects->unbounded.x; + xrects[n].width = rects->bounded.x - rects->unbounded.x; + xrects[n].y = rects->bounded.y; + xrects[n].height = rects->bounded.height; + n++; + } + /* right */ + if (rects->bounded.x + rects->bounded.width != rects->unbounded.x + rects->unbounded.width) { + xrects[n].x = rects->bounded.x + rects->bounded.width; + xrects[n].width = rects->unbounded.x + rects->unbounded.width - xrects[n].x; + xrects[n].y = rects->bounded.y; + xrects[n].height = rects->bounded.height; + n++; + } + /* bottom */ + if (rects->bounded.y + rects->bounded.height != rects->unbounded.y + rects->unbounded.height) { + xrects[n].x = rects->unbounded.x; + xrects[n].width = rects->unbounded.width; + xrects[n].y = rects->bounded.y + rects->bounded.height; + xrects[n].height = rects->unbounded.y + rects->unbounded.height - xrects[n].y; + n++; + } + } + + if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { + xcb_render_color_t color; + + color.red = 0; + color.green = 0; + color.blue = 0; + color.alpha = 0; + + _cairo_xcb_connection_render_fill_rectangles (dst->connection, + XCB_RENDER_PICT_OP_CLEAR, + dst->picture, + color, n, xrects); + } else { + int i; + cairo_xcb_picture_t *src; + + src = _cairo_xcb_transparent_picture (dst); + if (unlikely (src->base.status)) + return src->base.status; + + for (i = 0; i < n; i++) { + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_CLEAR, + src->picture, XCB_NONE, dst->picture, + 0, 0, + 0, 0, + xrects[i].x, xrects[i].y, + xrects[i].width, xrects[i].height); + } + cairo_surface_destroy (&src->base); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xcb_surface_fixup_unbounded_with_mask (cairo_xcb_surface_t *dst, + const cairo_composite_rectangles_t *rects, + cairo_clip_t *clip) +{ + cairo_xcb_surface_t *mask; + int mask_x = 0, mask_y = 0; + + mask = get_clip_surface (clip, dst, &mask_x, &mask_y); + if (unlikely (mask->base.status)) + return mask->base.status; + + /* top */ + if (rects->bounded.y != rects->unbounded.y) { + int x = rects->unbounded.x; + int y = rects->unbounded.y; + int width = rects->unbounded.width; + int height = rects->bounded.y - y; + + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_OUT_REVERSE, + mask->picture, XCB_NONE, dst->picture, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + /* left */ + if (rects->bounded.x != rects->unbounded.x) { + int x = rects->unbounded.x; + int y = rects->bounded.y; + int width = rects->bounded.x - x; + int height = rects->bounded.height; + + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_OUT_REVERSE, + mask->picture, XCB_NONE, dst->picture, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + /* right */ + if (rects->bounded.x + rects->bounded.width != rects->unbounded.x + rects->unbounded.width) { + int x = rects->bounded.x + rects->bounded.width; + int y = rects->bounded.y; + int width = rects->unbounded.x + rects->unbounded.width - x; + int height = rects->bounded.height; + + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_OUT_REVERSE, + mask->picture, XCB_NONE, dst->picture, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + /* bottom */ + if (rects->bounded.y + rects->bounded.height != rects->unbounded.y + rects->unbounded.height) { + int x = rects->unbounded.x; + int y = rects->bounded.y + rects->bounded.height; + int width = rects->unbounded.width; + int height = rects->unbounded.y + rects->unbounded.height - y; + + _cairo_xcb_connection_render_composite (dst->connection, + XCB_RENDER_PICT_OP_OUT_REVERSE, + mask->picture, XCB_NONE, dst->picture, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + cairo_surface_destroy (&mask->base); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xcb_surface_fixup_unbounded_boxes (cairo_xcb_surface_t *dst, + const cairo_composite_rectangles_t *extents, + cairo_clip_t *clip, + cairo_boxes_t *boxes) +{ + cairo_boxes_t clear; + cairo_box_t box; + cairo_status_t status; + struct _cairo_boxes_chunk *chunk; + int i; + + if (boxes->num_boxes <= 1 && clip == NULL) + return _cairo_xcb_surface_fixup_unbounded (dst, extents); + + _cairo_boxes_init (&clear); + + box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width); + box.p1.y = _cairo_fixed_from_int (extents->unbounded.y); + box.p2.x = _cairo_fixed_from_int (extents->unbounded.x); + box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height); + + if (clip == NULL) { + cairo_boxes_t tmp; + + _cairo_boxes_init (&tmp); + + status = _cairo_boxes_add (&tmp, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_STATUS_SUCCESS); + + tmp.chunks.next = &boxes->chunks; + tmp.num_boxes += boxes->num_boxes; + + status = _cairo_bentley_ottmann_tessellate_boxes (&tmp, + CAIRO_FILL_RULE_WINDING, + &clear); + + tmp.chunks.next = NULL; + } else { + _cairo_boxes_init_with_clip (&clear, clip); + + status = _cairo_boxes_add (&clear, CAIRO_ANTIALIAS_DEFAULT, &box); + assert (status == CAIRO_STATUS_SUCCESS); + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + status = _cairo_boxes_add (&clear, + CAIRO_ANTIALIAS_DEFAULT, + &chunk->base[i]); + if (unlikely (status)) { + _cairo_boxes_fini (&clear); + return status; + } + } + } + + status = _cairo_bentley_ottmann_tessellate_boxes (&clear, + CAIRO_FILL_RULE_WINDING, + &clear); + } + + if (likely (status == CAIRO_STATUS_SUCCESS)) { + if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) + status = _render_fill_boxes (dst, + CAIRO_OPERATOR_CLEAR, + CAIRO_COLOR_TRANSPARENT, + &clear); + else + status = _cairo_xcb_surface_core_fill_boxes (dst, + CAIRO_COLOR_TRANSPARENT, + &clear); + } + + _cairo_boxes_fini (&clear); + + return status; +} + +cairo_status_t +_cairo_xcb_surface_clear (cairo_xcb_surface_t *dst) +{ + xcb_gcontext_t gc; + xcb_rectangle_t rect; + cairo_status_t status; + + status = _cairo_xcb_connection_acquire (dst->connection); + if (unlikely (status)) + return status; + + rect.x = rect.y = 0; + rect.width = dst->width; + rect.height = dst->height; + + if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES) { + xcb_render_color_t color; + uint8_t op; + + color.red = dst->deferred_clear_color.red_short; + color.green = dst->deferred_clear_color.green_short; + color.blue = dst->deferred_clear_color.blue_short; + color.alpha = dst->deferred_clear_color.alpha_short; + + if (color.alpha == 0) + op = XCB_RENDER_PICT_OP_CLEAR; + else + op = XCB_RENDER_PICT_OP_SRC; + + _cairo_xcb_surface_ensure_picture (dst); + _cairo_xcb_connection_render_fill_rectangles (dst->connection, + op, dst->picture, color, + 1, &rect); + } else { + gc = _cairo_xcb_screen_get_gc (dst->screen, dst->drawable, dst->depth); + + /* XXX color */ + _cairo_xcb_connection_poly_fill_rectangle (dst->connection, + dst->drawable, gc, + 1, &rect); + + _cairo_xcb_screen_put_gc (dst->screen, dst->depth, gc); + } + + _cairo_xcb_connection_release (dst->connection); + + dst->deferred_clear = FALSE; + return CAIRO_STATUS_SUCCESS; +} + +enum { + NEED_CLIP_REGION = 0x1, + NEED_CLIP_SURFACE = 0x2, + FORCE_CLIP_REGION = 0x4, +}; + +static cairo_bool_t +need_bounded_clip (cairo_composite_rectangles_t *extents) +{ + unsigned int flags = NEED_CLIP_REGION; + if (! _cairo_clip_is_region (extents->clip)) + flags |= NEED_CLIP_SURFACE; + return flags; +} + +static cairo_bool_t +need_unbounded_clip (cairo_composite_rectangles_t *extents) +{ + unsigned int flags = 0; + if (! extents->is_bounded) { + flags |= NEED_CLIP_REGION; + if (! _cairo_clip_is_region (extents->clip)) + flags |= NEED_CLIP_SURFACE; + } + if (extents->clip->path != NULL) + flags |= NEED_CLIP_SURFACE; + return flags; +} + +static cairo_status_t +_clip_and_composite (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + xcb_draw_func_t draw_func, + xcb_draw_func_t mask_func, + void *draw_closure, + cairo_composite_rectangles_t*extents, + unsigned int need_clip) +{ + cairo_region_t *clip_region = NULL; + cairo_status_t status; + + status = _cairo_xcb_connection_acquire (dst->connection); + if (unlikely (status)) + return status; + + if (dst->deferred_clear) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) { + _cairo_xcb_connection_release (dst->connection); + return status; + } + } + + _cairo_xcb_surface_ensure_picture (dst); + + if (need_clip & NEED_CLIP_REGION) { + clip_region = _cairo_clip_get_region (extents->clip); + if ((need_clip & FORCE_CLIP_REGION) == 0 && clip_region != NULL && + cairo_region_contains_rectangle (clip_region, + &extents->unbounded) == CAIRO_REGION_OVERLAP_IN) + clip_region = NULL; + if (clip_region != NULL) { + status = _cairo_xcb_surface_set_clip_region (dst, clip_region); + if (unlikely (status)) { + _cairo_xcb_connection_release (dst->connection); + return status; + } + } + } + + if (reduce_alpha_op (&dst->base, op, src)) { + op = CAIRO_OPERATOR_ADD; + src = NULL; + } + + if (extents->bounded.width != 0 && extents->bounded.height != 0) { + if (op == CAIRO_OPERATOR_SOURCE) { + status = _clip_and_composite_source (extents->clip, src, + draw_func, mask_func, draw_closure, + dst, &extents->bounded); + } else { + if (op == CAIRO_OPERATOR_CLEAR) { + op = CAIRO_OPERATOR_DEST_OUT; + src = NULL; + } + + if (need_clip & NEED_CLIP_SURFACE) { + if (extents->is_bounded) { + status = _clip_and_composite_with_mask (extents->clip, op, src, + draw_func, + mask_func, + draw_closure, + dst, &extents->bounded); + } else { + status = _clip_and_composite_combine (extents->clip, op, src, + draw_func, draw_closure, + dst, &extents->bounded); + } + } else { + status = draw_func (draw_closure, + dst, op, src, + 0, 0, + &extents->bounded, + extents->clip); + } + } + } + + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { + if (need_clip & NEED_CLIP_SURFACE) + status = _cairo_xcb_surface_fixup_unbounded_with_mask (dst, extents, extents->clip); + else + status = _cairo_xcb_surface_fixup_unbounded (dst, extents); + } + + if (clip_region) + _cairo_xcb_surface_clear_clip_region (dst); + + _cairo_xcb_connection_release (dst->connection); + + return status; +} + +static cairo_status_t +_core_boxes (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + cairo_boxes_t *boxes, + const cairo_composite_rectangles_t *extents) +{ + if (! boxes->is_pixel_aligned) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_clip_is_region (extents->clip)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (op == CAIRO_OPERATOR_CLEAR) + return _cairo_xcb_surface_core_fill_boxes (dst, CAIRO_COLOR_TRANSPARENT, boxes); + + if (op == CAIRO_OPERATOR_OVER) { + if (dst->base.is_clear || _cairo_pattern_is_opaque (src, &extents->bounded)) + op = CAIRO_OPERATOR_SOURCE; + } + if (op != CAIRO_OPERATOR_SOURCE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (src->type == CAIRO_PATTERN_TYPE_SOLID) { + return _cairo_xcb_surface_core_fill_boxes (dst, + &((cairo_solid_pattern_t *) src)->color, + boxes); + } + + return _cairo_xcb_surface_core_copy_boxes (dst, src, &extents->bounded, boxes); +} + +static cairo_status_t +_composite_boxes (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + cairo_boxes_t *boxes, + const cairo_composite_rectangles_t *extents) +{ + cairo_clip_t *clip = extents->clip; + cairo_bool_t need_clip_mask = ! _cairo_clip_is_region (clip); + cairo_status_t status; + + /* If the boxes are not pixel-aligned, we will need to compute a real mask */ + if (! boxes->is_pixel_aligned) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (need_clip_mask && + (! extents->is_bounded || op == CAIRO_OPERATOR_SOURCE)) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = _cairo_xcb_connection_acquire (dst->connection); + if (unlikely (status)) + return status; + + _cairo_xcb_surface_ensure_picture (dst); + if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES && ! need_clip_mask && + (op == CAIRO_OPERATOR_CLEAR || src->type == CAIRO_PATTERN_TYPE_SOLID)) + { + const cairo_color_t *color; + + if (op == CAIRO_OPERATOR_CLEAR) + color = CAIRO_COLOR_TRANSPARENT; + else + color = &((cairo_solid_pattern_t *) src)->color; + + status = _render_fill_boxes (dst, op, color, boxes); + } + else + { + cairo_surface_pattern_t mask; + + if (need_clip_mask) { + cairo_xcb_surface_t *clip_surface; + int clip_x = 0, clip_y = 0; + + clip_surface = get_clip_surface (extents->clip, dst, + &clip_x, &clip_y); + if (unlikely (clip_surface->base.status)) + return clip_surface->base.status; + + _cairo_pattern_init_for_surface (&mask, &clip_surface->base); + mask.base.filter = CAIRO_FILTER_NEAREST; + cairo_matrix_init_translate (&mask.base.matrix, + -clip_x, + -clip_y); + cairo_surface_destroy (&clip_surface->base); + + if (op == CAIRO_OPERATOR_CLEAR) { + src = NULL; + op = CAIRO_OPERATOR_DEST_OUT; + } + } + + status = _render_composite_boxes (dst, op, src, + need_clip_mask ? &mask.base : NULL, + &extents->bounded, boxes); + + if (need_clip_mask) + _cairo_pattern_fini (&mask.base); + } + + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) { + status = + _cairo_xcb_surface_fixup_unbounded_boxes (dst, extents, + clip, boxes); + } + + _cairo_xcb_connection_release (dst->connection); + + return status; +} + +static cairo_bool_t +cairo_boxes_for_each_box (cairo_boxes_t *boxes, + cairo_bool_t (*func) (cairo_box_t *box, + void *data), + void *data) +{ + struct _cairo_boxes_chunk *chunk; + int i; + + for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) + if (! func (&chunk->base[i], data)) + return FALSE; + } + + return TRUE; +} + +struct _image_contains_box { + int width, height; + int tx, ty; +}; + +static cairo_bool_t image_contains_box (cairo_box_t *box, void *closure) +{ + struct _image_contains_box *data = closure; + + /* The box is pixel-aligned so the truncation is safe. */ + return + _cairo_fixed_integer_part (box->p1.x) + data->tx >= 0 && + _cairo_fixed_integer_part (box->p1.y) + data->ty >= 0 && + _cairo_fixed_integer_part (box->p2.x) + data->tx <= data->width && + _cairo_fixed_integer_part (box->p2.y) + data->ty <= data->height; +} + +struct _image_upload_box { + cairo_xcb_surface_t *surface; + cairo_image_surface_t *image; + xcb_gcontext_t gc; + int tx, ty; +}; + +static cairo_bool_t image_upload_box (cairo_box_t *box, void *closure) +{ + const struct _image_upload_box *iub = closure; + /* The box is pixel-aligned so the truncation is safe. */ + int x = _cairo_fixed_integer_part (box->p1.x); + int y = _cairo_fixed_integer_part (box->p1.y); + int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); + int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); + int bpp = PIXMAN_FORMAT_BPP (iub->image->pixman_format); + int len = CAIRO_STRIDE_FOR_WIDTH_BPP (width, bpp); + if (len == iub->image->stride) { + _cairo_xcb_connection_put_image (iub->surface->connection, + iub->surface->drawable, + iub->gc, + width, height, + x, y, + iub->image->depth, + iub->image->stride, + iub->image->data + + (y + iub->ty) * iub->image->stride + + (x + iub->tx) * bpp/8); + } else { + _cairo_xcb_connection_put_subimage (iub->surface->connection, + iub->surface->drawable, + iub->gc, + x + iub->tx, + y + iub->ty, + width, height, + bpp / 8, + iub->image->stride, + x, y, + iub->image->depth, + iub->image->data); + } + + return TRUE; +} + +static cairo_status_t +_upload_image_inplace (cairo_xcb_surface_t *surface, + const cairo_pattern_t *source, + cairo_boxes_t *boxes) +{ + const cairo_surface_pattern_t *pattern; + struct _image_contains_box icb; + struct _image_upload_box iub; + cairo_image_surface_t *image; + cairo_status_t status; + int tx, ty; + + if (! boxes->is_pixel_aligned) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (source->type != CAIRO_PATTERN_TYPE_SURFACE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + pattern = (const cairo_surface_pattern_t *) source; + if (! _cairo_surface_is_image (pattern->surface)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Have we already upload this image to a pixmap? */ + { + cairo_xcb_picture_t *snapshot; + + snapshot = (cairo_xcb_picture_t *) + _cairo_surface_has_snapshot (pattern->surface, &_cairo_xcb_picture_backend); + if (snapshot != NULL) { + if (snapshot->screen == surface->screen) + return CAIRO_INT_STATUS_UNSUPPORTED; + } + } + + image = (cairo_image_surface_t *) pattern->surface; + if (image->format == CAIRO_FORMAT_INVALID) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (image->depth != surface->depth) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Check that the data is entirely within the image */ + icb.width = image->width; + icb.height = image->height; + icb.tx = tx; + icb.ty = ty; + if (! cairo_boxes_for_each_box (boxes, image_contains_box, &icb)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (surface->deferred_clear) { + status = _cairo_xcb_surface_clear (surface); + if (unlikely (status)) + return status; + } + + status = _cairo_xcb_connection_acquire (surface->connection); + if (unlikely (status)) + return status; + + iub.surface = surface; + iub.image = image; + iub.gc = _cairo_xcb_screen_get_gc (surface->screen, + surface->drawable, + image->depth); + iub.tx = tx; + iub.ty = ty; + cairo_boxes_for_each_box (boxes, image_upload_box, &iub); + + _cairo_xcb_screen_put_gc (surface->screen, image->depth, iub.gc); + _cairo_xcb_connection_release (surface->connection); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +trim_extents_to_traps (cairo_composite_rectangles_t *extents, + cairo_traps_t *traps) +{ + cairo_box_t box; + + /* X trims the affected area to the extents of the trapezoids, so + * we need to compensate when fixing up the unbounded area. + */ + _cairo_traps_extents (traps, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_bool_t +_mono_edge_is_vertical (const cairo_line_t *line) +{ + return _cairo_fixed_integer_round_down (line->p1.x) == _cairo_fixed_integer_round_down (line->p2.x); +} + +static cairo_bool_t +_traps_are_pixel_aligned (cairo_traps_t *traps, + cairo_antialias_t antialias) +{ + int i; + + if (antialias == CAIRO_ANTIALIAS_NONE) { + for (i = 0; i < traps->num_traps; i++) { + if (! _mono_edge_is_vertical (&traps->traps[i].left) || + ! _mono_edge_is_vertical (&traps->traps[i].right)) + { + traps->maybe_region = FALSE; + return FALSE; + } + } + } else { + for (i = 0; i < traps->num_traps; i++) { + if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x || + traps->traps[i].right.p1.x != traps->traps[i].right.p2.x || + ! _cairo_fixed_is_integer (traps->traps[i].top) || + ! _cairo_fixed_is_integer (traps->traps[i].bottom) || + ! _cairo_fixed_is_integer (traps->traps[i].left.p1.x) || + ! _cairo_fixed_is_integer (traps->traps[i].right.p1.x)) + { + traps->maybe_region = FALSE; + return FALSE; + } + } + } + + return TRUE; +} + +static void +_boxes_for_traps (cairo_boxes_t *boxes, + cairo_traps_t *traps, + cairo_antialias_t antialias) +{ + int i, j; + + _cairo_boxes_init (boxes); + + boxes->chunks.base = (cairo_box_t *) traps->traps; + boxes->chunks.size = traps->num_traps; + + if (antialias != CAIRO_ANTIALIAS_NONE) { + for (i = j = 0; i < traps->num_traps; i++) { + /* Note the traps and boxes alias so we need to take the local copies first. */ + cairo_fixed_t x1 = traps->traps[i].left.p1.x; + cairo_fixed_t x2 = traps->traps[i].right.p1.x; + cairo_fixed_t y1 = traps->traps[i].top; + cairo_fixed_t y2 = traps->traps[i].bottom; + + if (x1 == x2 || y1 == y2) + continue; + + boxes->chunks.base[j].p1.x = x1; + boxes->chunks.base[j].p1.y = y1; + boxes->chunks.base[j].p2.x = x2; + boxes->chunks.base[j].p2.y = y2; + j++; + + if (boxes->is_pixel_aligned) { + boxes->is_pixel_aligned = + _cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) && + _cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2); + } + } + } else { + boxes->is_pixel_aligned = TRUE; + + for (i = j = 0; i < traps->num_traps; i++) { + /* Note the traps and boxes alias so we need to take the local copies first. */ + cairo_fixed_t x1 = traps->traps[i].left.p1.x; + cairo_fixed_t x2 = traps->traps[i].right.p1.x; + cairo_fixed_t y1 = traps->traps[i].top; + cairo_fixed_t y2 = traps->traps[i].bottom; + + /* round down here to match Pixman's behavior when using traps. */ + boxes->chunks.base[j].p1.x = _cairo_fixed_round_down (x1); + boxes->chunks.base[j].p1.y = _cairo_fixed_round_down (y1); + boxes->chunks.base[j].p2.x = _cairo_fixed_round_down (x2); + boxes->chunks.base[j].p2.y = _cairo_fixed_round_down (y2); + + j += (boxes->chunks.base[j].p1.x != boxes->chunks.base[j].p2.x && + boxes->chunks.base[j].p1.y != boxes->chunks.base[j].p2.y); + } + } + + boxes->num_boxes = j; + boxes->chunks.count = j; +} + +static cairo_status_t +_composite_polygon (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_polygon_t *polygon, + cairo_antialias_t antialias, + cairo_fill_rule_t fill_rule, + cairo_composite_rectangles_t *extents) +{ + composite_traps_info_t traps; + cairo_bool_t clip_surface = ! _cairo_clip_is_region (extents->clip); + cairo_region_t *clip_region = _cairo_clip_get_region (extents->clip); + cairo_status_t status; + + if (polygon->num_edges == 0) { + status = CAIRO_STATUS_SUCCESS; + + if (! extents->is_bounded) { + if (cairo_region_contains_rectangle (clip_region, &extents->unbounded) == CAIRO_REGION_OVERLAP_IN) + clip_region = NULL; + + if (clip_surface == FALSE) { + if (clip_region != NULL) { + status = _cairo_xcb_surface_set_clip_region (dst, clip_region); + if (unlikely (status)) + return status; + } + + status = _cairo_xcb_surface_fixup_unbounded (dst, extents); + + if (clip_region != NULL) + _cairo_xcb_surface_clear_clip_region (dst); + } else { + status = _cairo_xcb_surface_fixup_unbounded_with_mask (dst, + extents, + extents->clip); + } + } + + return status; + } + + if (extents->clip->path != NULL && extents->is_bounded) { + cairo_polygon_t clipper; + cairo_fill_rule_t clipper_fill_rule; + cairo_antialias_t clipper_antialias; + + status = _cairo_clip_get_polygon (extents->clip, + &clipper, + &clipper_fill_rule, + &clipper_antialias); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + if (clipper_antialias == antialias) { + status = _cairo_polygon_intersect (polygon, fill_rule, + &clipper, clipper_fill_rule); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + cairo_clip_t * clip = _cairo_clip_copy_region (extents->clip); + _cairo_clip_destroy (extents->clip); + extents->clip = clip; + + fill_rule = CAIRO_FILL_RULE_WINDING; + } + _cairo_polygon_fini (&clipper); + } + } + } + + _cairo_traps_init (&traps.traps); + + status = _cairo_bentley_ottmann_tessellate_polygon (&traps.traps, polygon, fill_rule); + if (unlikely (status)) + goto CLEANUP_TRAPS; + + if (traps.traps.has_intersections) { + if (traps.traps.is_rectangular) + status = _cairo_bentley_ottmann_tessellate_rectangular_traps (&traps.traps, CAIRO_FILL_RULE_WINDING); + else if (traps.traps.is_rectilinear) + status = _cairo_bentley_ottmann_tessellate_rectilinear_traps (&traps.traps, CAIRO_FILL_RULE_WINDING); + else + status = _cairo_bentley_ottmann_tessellate_traps (&traps.traps, CAIRO_FILL_RULE_WINDING); + if (unlikely (status)) + goto CLEANUP_TRAPS; + } + + /* Use a fast path if the trapezoids consist of a simple region, + * but we can only do this if we do not have a clip surface, or can + * substitute the mask with the clip. + */ + if (traps.traps.maybe_region && + _traps_are_pixel_aligned (&traps.traps, antialias) && + (! clip_surface || + (extents->is_bounded && op != CAIRO_OPERATOR_SOURCE))) + { + cairo_boxes_t boxes; + + _boxes_for_traps (&boxes, &traps.traps, antialias); + status = _clip_and_composite_boxes (dst, op, source, &boxes, extents); + } + else + { + /* Otherwise render the trapezoids to a mask and composite in the usual + * fashion. + */ + traps.antialias = antialias; + status = trim_extents_to_traps (extents, &traps.traps); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + unsigned int flags = 0; + + /* For unbounded operations, the X11 server will estimate the + * affected rectangle and apply the operation to that. However, + * there are cases where this is an overestimate (e.g. the + * clip-fill-{eo,nz}-unbounded test). + * + * The clip will trim that overestimate to our expectations. + */ + if (! extents->is_bounded) + flags |= FORCE_CLIP_REGION; + + status = _clip_and_composite (dst, op, source, _composite_traps, + NULL, &traps, extents, + need_unbounded_clip (extents) | flags); + } + } + +CLEANUP_TRAPS: + _cairo_traps_fini (&traps.traps); + + return status; +} + +static cairo_status_t +_clip_and_composite_boxes (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src, + cairo_boxes_t *boxes, + cairo_composite_rectangles_t *extents) +{ + composite_traps_info_t info; + cairo_int_status_t status; + + if (boxes->num_boxes == 0 && extents->is_bounded) + return CAIRO_STATUS_SUCCESS; + + if (boxes->is_pixel_aligned && _cairo_clip_is_region (extents->clip) && + (op == CAIRO_OPERATOR_SOURCE || + (dst->base.is_clear && (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD)))) + { + if (boxes->num_boxes == 1 && + extents->bounded.width == dst->width && + extents->bounded.height == dst->height) + { + op = CAIRO_OPERATOR_SOURCE; + dst->deferred_clear = FALSE; + } + + status = _upload_image_inplace (dst, src, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ + if (dst->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS && + extents->clip->path != NULL && extents->is_bounded) { + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + cairo_antialias_t antialias; + cairo_clip_t *clip; + + clip = _cairo_clip_copy (extents->clip); + clip = _cairo_clip_intersect_boxes (clip, boxes); + if (_cairo_clip_is_all_clipped (clip)) + return CAIRO_INT_STATUS_NOTHING_TO_DO; + + status = _cairo_clip_get_polygon (clip, &polygon, + &fill_rule, &antialias); + _cairo_clip_path_destroy (clip->path); + clip->path = NULL; + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + cairo_clip_t *saved_clip = extents->clip; + extents->clip = clip; + status = _composite_polygon (dst, op, src, + &polygon, + antialias, + fill_rule, + extents); + if (extents->clip != clip) + clip = NULL; + extents->clip = saved_clip; + _cairo_polygon_fini (&polygon); + } + if (clip) + _cairo_clip_destroy (clip); + + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + if (dst->deferred_clear) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) + return status; + } + + if (boxes->is_pixel_aligned && + _cairo_clip_is_region (extents->clip) && + op == CAIRO_OPERATOR_SOURCE) { + status = _upload_image_inplace (dst, src, boxes); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + } + + if ((dst->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) == 0) + return _core_boxes (dst, op, src, boxes, extents); + + /* Use a fast path if the boxes are pixel aligned */ + status = _composite_boxes (dst, op, src, boxes, extents); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + return status; + + if ((dst->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) == 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* Otherwise render via a mask and composite in the usual fashion. */ + status = _cairo_traps_init_boxes (&info.traps, boxes); + if (unlikely (status)) + return status; + + info.antialias = CAIRO_ANTIALIAS_DEFAULT; + status = trim_extents_to_traps (extents, &info.traps); + if (status == CAIRO_INT_STATUS_SUCCESS) { + status = _clip_and_composite (dst, op, src, + _composite_traps, NULL, &info, + extents, need_unbounded_clip (extents)); + } + + _cairo_traps_fini (&info.traps); + return status; +} + +static cairo_int_status_t +_composite_mask (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + const cairo_pattern_t *mask_pattern = closure; + cairo_xcb_picture_t *src, *mask = NULL; + cairo_status_t status; + + if (dst->base.is_clear) { + if (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD) + op = CAIRO_OPERATOR_SOURCE; + } + + if (op == CAIRO_OPERATOR_SOURCE && clip == NULL) + dst->deferred_clear = FALSE; + + if (dst->deferred_clear) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) + return status; + } + + if (src_pattern != NULL) { + src = _cairo_xcb_picture_for_pattern (dst, src_pattern, extents); + if (unlikely (src->base.status)) + return src->base.status; + + mask = _cairo_xcb_picture_for_pattern (dst, mask_pattern, extents); + if (unlikely (mask->base.status)) { + cairo_surface_destroy (&src->base); + return mask->base.status; + } + + _cairo_xcb_connection_render_composite (dst->connection, + _render_operator (op), + src->picture, + mask->picture, + dst->picture, + extents->x + src->x, extents->y + src->y, + extents->x + mask->x, extents->y + mask->y, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + cairo_surface_destroy (&mask->base); + cairo_surface_destroy (&src->base); + } else { + src = _cairo_xcb_picture_for_pattern (dst, mask_pattern, extents); + if (unlikely (src->base.status)) + return src->base.status; + + _cairo_xcb_connection_render_composite (dst->connection, + _render_operator (op), + src->picture, + XCB_NONE, + dst->picture, + extents->x + src->x, extents->y + src->y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + cairo_surface_destroy (&src->base); + } + + return CAIRO_STATUS_SUCCESS; +} + +struct composite_box_info { + cairo_xcb_surface_t *dst; + cairo_xcb_picture_t *src; + uint8_t op; +}; + +static void composite_box(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct composite_box_info *info = closure; + + if (coverage < 0xff00) { + cairo_xcb_picture_t *mask; + cairo_color_t color; + + color.red_short = color.green_short = color.blue_short = 0; + color.alpha_short = coverage; + + mask = _solid_picture (info->dst, &color); + if (likely (mask->base.status == CAIRO_STATUS_SUCCESS)) { + _cairo_xcb_connection_render_composite (info->dst->connection, + info->op, + info->src->picture, + mask->picture, + info->dst->picture, + x + info->src->x, y + info->src->y, + 0, 0, + x, y, + w, h); + } + cairo_surface_destroy (&mask->base); + } else { + _cairo_xcb_connection_render_composite (info->dst->connection, + info->op, + info->src->picture, + XCB_NONE, + info->dst->picture, + x + info->src->x, y + info->src->y, + 0, 0, + x, y, + w, h); + } +} + +static cairo_int_status_t +_composite_mask_clip_boxes (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + struct composite_box_info info; + cairo_status_t status; + int i; + + assert (src_pattern == NULL); + assert (op == CAIRO_OPERATOR_ADD); + assert (dst->base.is_clear); + + if (clip->num_boxes > 1) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) + return status; + } + + info.op = XCB_RENDER_PICT_OP_SRC; + info.dst = dst; + info.src = _cairo_xcb_picture_for_pattern (dst, closure, extents); + if (unlikely (info.src->base.status)) + return info.src->base.status; + + info.src->x += dst_x; + info.src->y += dst_y; + + for (i = 0; i < clip->num_boxes; i++) + do_unaligned_box(composite_box, &info, &clip->boxes[i], dst_x, dst_y); + cairo_surface_destroy (&info.src->base); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_composite_mask_clip (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + const cairo_pattern_t *mask_pattern = closure; + cairo_polygon_t polygon; + cairo_fill_rule_t fill_rule; + composite_traps_info_t info; + cairo_status_t status; + + assert (src_pattern == NULL); + assert (op == CAIRO_OPERATOR_ADD); + assert (dst->base.is_clear); + + status = _cairo_clip_get_polygon (clip, &polygon, + &fill_rule, &info.antialias); + if (unlikely (status)) + return status; + + _cairo_traps_init (&info.traps); + status = _cairo_bentley_ottmann_tessellate_polygon (&info.traps, + &polygon, + fill_rule); + _cairo_polygon_fini (&polygon); + if (unlikely (status)) + return status; + + if (info.traps.has_intersections) { + if (info.traps.is_rectangular) + status = _cairo_bentley_ottmann_tessellate_rectangular_traps (&info.traps, CAIRO_FILL_RULE_WINDING); + else if (info.traps.is_rectilinear) + status = _cairo_bentley_ottmann_tessellate_rectilinear_traps (&info.traps, CAIRO_FILL_RULE_WINDING); + else + status = _cairo_bentley_ottmann_tessellate_traps (&info.traps, CAIRO_FILL_RULE_WINDING); + if (unlikely (status)) { + _cairo_traps_fini (&info.traps); + return status; + } + } + + dst->deferred_clear = FALSE; /* assert(trap extents == extents); */ + + status = _composite_traps (&info, + dst, CAIRO_OPERATOR_SOURCE, mask_pattern, + dst_x, dst_y, + extents, NULL); + _cairo_traps_fini (&info.traps); + + return status; +} + +struct composite_opacity_info { + uint8_t op; + cairo_xcb_surface_t *dst; + cairo_xcb_picture_t *src; + double opacity; +}; + +static void composite_opacity(void *closure, + int16_t x, int16_t y, + int16_t w, int16_t h, + uint16_t coverage) +{ + struct composite_opacity_info *info = closure; + cairo_xcb_picture_t *mask; + cairo_color_t color; + + color.red_short = color.green_short = color.blue_short = 0; + color.alpha_short = info->opacity * coverage; + + mask = _solid_picture (info->dst, &color); + if (likely (mask->base.status == CAIRO_STATUS_SUCCESS)) { + if (info->src) { + _cairo_xcb_connection_render_composite (info->dst->connection, + info->op, + info->src->picture, + mask->picture, + info->dst->picture, + x + info->src->x, y + info->src->y, + 0, 0, + x, y, + w, h); + } else { + _cairo_xcb_connection_render_composite (info->dst->connection, + info->op, + mask->picture, + XCB_NONE, + info->dst->picture, + 0, 0, + 0, 0, + x, y, + w, h); + } + } + + cairo_surface_destroy (&mask->base); +} + +static cairo_int_status_t +_composite_opacity_boxes (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *src_pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + const cairo_solid_pattern_t *mask_pattern = closure; + struct composite_opacity_info info; + cairo_status_t status; + int i; + + if (dst->base.is_clear) { + if (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD) + op = CAIRO_OPERATOR_SOURCE; + } + + if (op == CAIRO_OPERATOR_SOURCE && + (clip == NULL || + (clip->extents.width >= extents->width && + clip->extents.height >= extents->height))) + dst->deferred_clear = FALSE; + + if (dst->deferred_clear) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) + return status; + } + + info.op = _render_operator (op); + info.dst = dst; + + if (src_pattern != NULL) { + info.src = _cairo_xcb_picture_for_pattern (dst, src_pattern, extents); + if (unlikely (info.src->base.status)) + return info.src->base.status; + } else + info.src = NULL; + + info.opacity = mask_pattern->color.alpha; + + /* XXX for lots of boxes create a clip region for the fully opaque areas */ + if (clip) { + for (i = 0; i < clip->num_boxes; i++) + do_unaligned_box(composite_opacity, &info, + &clip->boxes[i], dst_x, dst_y); + } else { + composite_opacity(&info, + extents->x - dst_x, + extents->y - dst_y, + extents->width, + extents->height, + 0xffff); + } + cairo_surface_destroy (&info.src->base); + + return CAIRO_STATUS_SUCCESS; +} + +/* high level rasteriser -> compositor */ + +cairo_int_status_t +_cairo_xcb_render_compositor_paint (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; + cairo_operator_t op = composite->op; + cairo_pattern_t *source = &composite->source_pattern.base; + cairo_boxes_t boxes; + cairo_status_t status; + + if (unlikely (! _operator_is_supported (surface->connection->flags, op))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | + CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + if (composite->clip == NULL && + source->type == CAIRO_PATTERN_TYPE_SOLID && + (op == CAIRO_OPERATOR_SOURCE || + op == CAIRO_OPERATOR_CLEAR || + (surface->base.is_clear && + (op == CAIRO_OPERATOR_ADD || op == CAIRO_OPERATOR_OVER)))) + { + surface->deferred_clear = TRUE; + surface->deferred_clear_color = composite->source_pattern.solid.color; + return CAIRO_STATUS_SUCCESS; + } + + _cairo_clip_steal_boxes(composite->clip, &boxes); + status = _clip_and_composite_boxes (surface, op, source, &boxes, composite); + _cairo_clip_unsteal_boxes (composite->clip, &boxes); + + return status; +} + +cairo_int_status_t +_cairo_xcb_render_compositor_mask (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; + cairo_operator_t op = composite->op; + cairo_pattern_t *source = &composite->source_pattern.base; + cairo_pattern_t *mask = &composite->mask_pattern.base; + cairo_status_t status; + + if (unlikely (! _operator_is_supported (surface->connection->flags, op))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) == 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (mask->type == CAIRO_PATTERN_TYPE_SOLID && + composite->clip->path == NULL && + ! _cairo_clip_is_region (composite->clip)) { + status = _clip_and_composite (surface, op, source, + _composite_opacity_boxes, + _composite_opacity_boxes, + (void *) mask, + composite, need_unbounded_clip (composite)); + } else { + xcb_draw_func_t mask_func = NULL; + if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) + mask_func = composite->clip->path ? _composite_mask_clip : _composite_mask_clip_boxes; + status = _clip_and_composite (surface, op, source, + _composite_mask, mask_func, + (void *) mask, + composite, need_bounded_clip (composite)); + } + + return status; +} + +static cairo_int_status_t +_cairo_xcb_surface_render_stroke_as_polygon (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + cairo_composite_rectangles_t *extents) +{ + cairo_polygon_t polygon; + cairo_status_t status; + + _cairo_polygon_init_with_clip (&polygon, extents->clip); + status = _cairo_path_fixed_stroke_to_polygon (path, + stroke_style, + ctm, ctm_inverse, + tolerance, + &polygon); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + status = _composite_polygon (dst, op, source, + &polygon, antialias, + CAIRO_FILL_RULE_WINDING, + extents); + } + _cairo_polygon_fini (&polygon); + + return status; +} + +static cairo_status_t +_cairo_xcb_surface_render_stroke_via_mask (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *image; + cairo_status_t status; + cairo_clip_t *clip; + int x, y; + + x = extents->bounded.x; + y = extents->bounded.y; + image = _cairo_xcb_surface_create_similar_image (dst, CAIRO_FORMAT_A8, + extents->bounded.width, + extents->bounded.height); + if (unlikely (image->status)) + return image->status; + + clip = _cairo_clip_copy_region (extents->clip); + status = _cairo_surface_offset_stroke (image, x, y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + path, stroke_style, + ctm, ctm_inverse, + tolerance, antialias, + clip); + _cairo_clip_destroy (clip); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + cairo_surface_pattern_t mask; + + _cairo_pattern_init_for_surface (&mask, image); + mask.base.filter = CAIRO_FILTER_NEAREST; + + cairo_matrix_init_translate (&mask.base.matrix, -x, -y); + status = _clip_and_composite (dst, op, source, + _composite_mask, NULL, &mask.base, + extents, need_bounded_clip (extents)); + _cairo_pattern_fini (&mask.base); + } + + cairo_surface_finish (image); + cairo_surface_destroy (image); + + return status; +} + +cairo_int_status_t +_cairo_xcb_render_compositor_stroke (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; + cairo_operator_t op = composite->op; + cairo_pattern_t *source = &composite->source_pattern.base; + cairo_int_status_t status; + + if (unlikely (! _operator_is_supported (surface->connection->flags, op))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | + CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_stroke_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, composite->clip); + status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, + style, + ctm, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + status = _clip_and_composite_boxes (surface, op, source, + &boxes, composite); + } + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) { + status = _cairo_xcb_surface_render_stroke_as_polygon (surface, op, source, + path, style, + ctm, ctm_inverse, + tolerance, antialias, + composite); + } else if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) { + status = _cairo_xcb_surface_render_stroke_via_mask (surface, op, source, + path, style, + ctm, ctm_inverse, + tolerance, antialias, + composite); + } else { + ASSERT_NOT_REACHED; + } + } + + return status; +} + +static cairo_status_t +_cairo_xcb_surface_render_fill_as_polygon (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t*source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + cairo_composite_rectangles_t *extents) +{ + cairo_polygon_t polygon; + cairo_status_t status; + + _cairo_polygon_init_with_clip (&polygon, extents->clip); + status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + status = _composite_polygon (dst, op, source, + &polygon, + antialias, + fill_rule, + extents); + } + _cairo_polygon_fini (&polygon); + + return status; +} + +static cairo_status_t +_cairo_xcb_surface_render_fill_via_mask (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *image; + cairo_status_t status; + cairo_clip_t *clip; + int x, y; + + x = extents->bounded.x; + y = extents->bounded.y; + image = _cairo_xcb_surface_create_similar_image (dst, CAIRO_FORMAT_A8, + extents->bounded.width, + extents->bounded.height); + if (unlikely (image->status)) + return image->status; + + clip = _cairo_clip_copy_region (extents->clip); + status = _cairo_surface_offset_fill (image, x, y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + path, fill_rule, tolerance, antialias, + clip); + _cairo_clip_destroy (clip); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + cairo_surface_pattern_t mask; + + _cairo_pattern_init_for_surface (&mask, image); + mask.base.filter = CAIRO_FILTER_NEAREST; + + cairo_matrix_init_translate (&mask.base.matrix, -x, -y); + status = _clip_and_composite (dst, op, source, + _composite_mask, NULL, &mask.base, + extents, need_bounded_clip (extents)); + + _cairo_pattern_fini (&mask.base); + } + + cairo_surface_finish (image); + cairo_surface_destroy (image); + + return status; +} + +cairo_int_status_t +_cairo_xcb_render_compositor_fill (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; + cairo_operator_t op = composite->op; + cairo_pattern_t *source = &composite->source_pattern.base; + cairo_int_status_t status; + + if (unlikely (! _operator_is_supported (surface->connection->flags, op))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS | + CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_path_fixed_fill_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, composite->clip); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + fill_rule, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + status = _clip_and_composite_boxes (surface, op, source, + &boxes, composite); + } + _cairo_boxes_fini (&boxes); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS) { + status = _cairo_xcb_surface_render_fill_as_polygon (surface, op, source, path, + fill_rule, tolerance, antialias, + composite); + } else if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE) { + status = _cairo_xcb_surface_render_fill_via_mask (surface, op, source, path, + fill_rule, tolerance, antialias, + composite); + } else { + ASSERT_NOT_REACHED; + } + } + + return status; +} + +static cairo_status_t +_cairo_xcb_surface_render_glyphs_via_mask (cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_composite_rectangles_t *extents) +{ + cairo_surface_t *image; + cairo_content_t content; + cairo_status_t status; + cairo_clip_t *clip; + int x, y; + + content = CAIRO_CONTENT_ALPHA; + if (scaled_font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL) + content = CAIRO_CONTENT_COLOR_ALPHA; + + x = extents->bounded.x; + y = extents->bounded.y; + image = _cairo_xcb_surface_create_similar_image (dst, + _cairo_format_from_content (content), + extents->bounded.width, + extents->bounded.height); + if (unlikely (image->status)) + return image->status; + + clip = _cairo_clip_copy_region (extents->clip); + status = _cairo_surface_offset_glyphs (image, x, y, + CAIRO_OPERATOR_ADD, + &_cairo_pattern_white.base, + scaled_font, glyphs, num_glyphs, + clip); + _cairo_clip_destroy (clip); + if (likely (status == CAIRO_STATUS_SUCCESS)) { + cairo_surface_pattern_t mask; + + _cairo_pattern_init_for_surface (&mask, image); + mask.base.filter = CAIRO_FILTER_NEAREST; + if (content & CAIRO_CONTENT_COLOR) + mask.base.has_component_alpha = TRUE; + + cairo_matrix_init_translate (&mask.base.matrix, -x, -y); + status = _clip_and_composite (dst, op, source, + _composite_mask, NULL, &mask.base, + extents, need_bounded_clip (extents)); + + _cairo_pattern_fini (&mask.base); + } + + cairo_surface_finish (image); + cairo_surface_destroy (image); + + return status; +} + +/* Build a struct of the same size of #cairo_glyph_t that can be used both as + * an input glyph with double coordinates, and as "working" glyph with + * integer from-current-point offsets. */ +typedef union { + cairo_glyph_t d; + unsigned long index; + struct { + unsigned long index; + int x; + int y; + } i; +} cairo_xcb_glyph_t; + +/* compile-time assert that #cairo_xcb_glyph_t is the same size as #cairo_glyph_t */ +COMPILE_TIME_ASSERT (sizeof (cairo_xcb_glyph_t) == sizeof (cairo_glyph_t)); + +typedef struct { + cairo_scaled_font_t *font; + cairo_xcb_glyph_t *glyphs; + int num_glyphs; + cairo_bool_t use_mask; +} composite_glyphs_info_t; + +static cairo_status_t +_can_composite_glyphs (cairo_xcb_surface_t *dst, + cairo_rectangle_int_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs) +{ +#define GLYPH_CACHE_SIZE 64 + cairo_box_t bbox_cache[GLYPH_CACHE_SIZE]; + unsigned long glyph_cache[GLYPH_CACHE_SIZE]; +#undef GLYPH_CACHE_SIZE + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_glyph_t *glyphs_end, *valid_glyphs; + const int max_glyph_size = dst->connection->maximum_request_length - 64; + + /* We must initialize the cache with values that cannot match the + * "hash" to guarantee that when compared for the first time they + * will result in a mismatch. The hash function is simply modulus, + * so we cannot use 0 in glyph_cache[0], but we can use it in all + * other array cells. + */ + memset (glyph_cache, 0, sizeof (glyph_cache)); + glyph_cache[0] = 1; + + /* Scan for oversized glyphs or glyphs outside the representable + * range and fallback in that case, discard glyphs outside of the + * image. + */ + valid_glyphs = glyphs; + for (glyphs_end = glyphs + *num_glyphs; glyphs != glyphs_end; glyphs++) { + double x1, y1, x2, y2; + cairo_scaled_glyph_t *glyph; + cairo_box_t *bbox; + int width, height, len; + int g; + + g = glyphs->index % ARRAY_LENGTH (glyph_cache); + if (glyph_cache[g] != glyphs->index) { + status = _cairo_scaled_glyph_lookup (scaled_font, + glyphs->index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &glyph); + if (unlikely (status)) + break; + + glyph_cache[g] = glyphs->index; + bbox_cache[g] = glyph->bbox; + } + bbox = &bbox_cache[g]; + + /* Drop glyphs outside the clipping */ + x1 = _cairo_fixed_to_double (bbox->p1.x); + y1 = _cairo_fixed_to_double (bbox->p1.y); + y2 = _cairo_fixed_to_double (bbox->p2.y); + x2 = _cairo_fixed_to_double (bbox->p2.x); + if (unlikely (glyphs->x + x2 <= extents->x || + glyphs->y + y2 <= extents->y || + glyphs->x + x1 >= extents->x + extents->width || + glyphs->y + y1 >= extents->y + extents->height)) + { + (*num_glyphs)--; + continue; + } + + /* XRenderAddGlyph does not handle a glyph surface larger than + * the extended maximum XRequest size. + */ + width = _cairo_fixed_integer_ceil (bbox->p2.x - bbox->p1.x); + height = _cairo_fixed_integer_ceil (bbox->p2.y - bbox->p1.y); + len = CAIRO_STRIDE_FOR_WIDTH_BPP (width, 32) * height; + if (unlikely (len >= max_glyph_size)) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + break; + } + + /* The glyph coordinates must be representable in an int16_t. + * When possible, they will be expressed as an offset from the + * previous glyph, otherwise they will be an offset from the + * operation extents or from the surface origin. If the last + * two options are not valid, fallback. + */ + if (unlikely (glyphs->x > INT16_MAX || + glyphs->y > INT16_MAX || + glyphs->x - extents->x < INT16_MIN || + glyphs->y - extents->y < INT16_MIN)) + { + status = CAIRO_INT_STATUS_UNSUPPORTED; + break; + } + + + if (unlikely (valid_glyphs != glyphs)) + *valid_glyphs = *glyphs; + valid_glyphs++; + } + + if (unlikely (valid_glyphs != glyphs)) { + for (; glyphs != glyphs_end; glyphs++) { + *valid_glyphs = *glyphs; + valid_glyphs++; + } + } + + return status; +} + +/* Start a new element for the first glyph, + * or for any glyph that has unexpected position, + * or if current element has too many glyphs + * (Xrender limits each element to 252 glyphs, we limit them to 128) + * + * These same conditions need to be mirrored between + * _cairo_xcb_surface_emit_glyphs and _emit_glyph_chunks + */ +#define _start_new_glyph_elt(count, glyph) \ + (((count) & 127) == 0 || (glyph)->i.x || (glyph)->i.y) + +/* sz_xGlyphtElt required alignment to a 32-bit boundary, so ensure we have + * enough room for padding */ +typedef struct { + uint8_t len; + uint8_t pad1; + uint16_t pad2; + int16_t deltax; + int16_t deltay; +} x_glyph_elt_t; +#define _cairo_sz_x_glyph_elt_t (sizeof (x_glyph_elt_t) + 4) + +static void +_cairo_xcb_font_destroy (cairo_xcb_font_t *font) +{ + int i; + + for (i = 0; i < NUM_GLYPHSETS; i++) { + cairo_xcb_font_glyphset_info_t *info; + + info = &font->glyphset_info[i]; + free (info->pending_free_glyphs); + } + + cairo_list_del (&font->base.link); + cairo_list_del (&font->link); + + _cairo_xcb_connection_destroy (font->connection); + + free (font); +} + +static void +_cairo_xcb_font_fini (cairo_scaled_font_private_t *abstract_private, + cairo_scaled_font_t *scaled_font) +{ + cairo_xcb_font_t *font_private = (cairo_xcb_font_t *)abstract_private; + cairo_xcb_connection_t *connection; + cairo_bool_t have_connection; + cairo_status_t status; + int i; + + connection = font_private->connection; + + status = _cairo_xcb_connection_acquire (connection); + have_connection = status == CAIRO_STATUS_SUCCESS; + + for (i = 0; i < NUM_GLYPHSETS; i++) { + cairo_xcb_font_glyphset_info_t *info; + + info = &font_private->glyphset_info[i]; + if (info->glyphset && status == CAIRO_STATUS_SUCCESS) { + _cairo_xcb_connection_render_free_glyph_set (connection, + info->glyphset); + } + } + + if (have_connection) + _cairo_xcb_connection_release (connection); + + _cairo_xcb_font_destroy (font_private); +} + + +static cairo_xcb_font_t * +_cairo_xcb_font_create (cairo_xcb_connection_t *connection, + cairo_scaled_font_t *font) +{ + cairo_xcb_font_t *priv; + int i; + + priv = malloc (sizeof (cairo_xcb_font_t)); + if (unlikely (priv == NULL)) + return NULL; + + _cairo_scaled_font_attach_private (font, &priv->base, connection, + _cairo_xcb_font_fini); + + priv->scaled_font = font; + priv->connection = _cairo_xcb_connection_reference (connection); + cairo_list_add (&priv->link, &connection->fonts); + + for (i = 0; i < NUM_GLYPHSETS; i++) { + cairo_xcb_font_glyphset_info_t *info = &priv->glyphset_info[i]; + switch (i) { + case GLYPHSET_INDEX_ARGB32: info->format = CAIRO_FORMAT_ARGB32; break; + case GLYPHSET_INDEX_A8: info->format = CAIRO_FORMAT_A8; break; + case GLYPHSET_INDEX_A1: info->format = CAIRO_FORMAT_A1; break; + default: ASSERT_NOT_REACHED; break; + } + info->xrender_format = 0; + info->glyphset = XCB_NONE; + info->pending_free_glyphs = NULL; + } + + return priv; +} + +void +_cairo_xcb_font_close (cairo_xcb_font_t *font) +{ + cairo_scaled_font_t *scaled_font; + + scaled_font = font->scaled_font; + + //scaled_font->surface_private = NULL; + _cairo_scaled_font_reset_cache (scaled_font); + + _cairo_xcb_font_destroy (font); +} + +static void +_cairo_xcb_render_free_glyphs (cairo_xcb_connection_t *connection, + cairo_xcb_font_glyphset_free_glyphs_t *to_free) +{ + _cairo_xcb_connection_render_free_glyphs (connection, + to_free->glyphset, + to_free->glyph_count, + to_free->glyph_indices); +} + +static int +_cairo_xcb_get_glyphset_index_for_format (cairo_format_t format) +{ + if (format == CAIRO_FORMAT_A8) + return GLYPHSET_INDEX_A8; + if (format == CAIRO_FORMAT_A1) + return GLYPHSET_INDEX_A1; + + assert (format == CAIRO_FORMAT_ARGB32); + return GLYPHSET_INDEX_ARGB32; +} + + + +static inline cairo_xcb_font_t * +_cairo_xcb_font_get (const cairo_xcb_connection_t *c, + cairo_scaled_font_t *font) +{ + return (cairo_xcb_font_t *)_cairo_scaled_font_find_private (font, c); +} + + +static cairo_xcb_font_glyphset_info_t * +_cairo_xcb_scaled_font_get_glyphset_info_for_format (cairo_xcb_connection_t *c, + cairo_scaled_font_t *font, + cairo_format_t format) +{ + cairo_xcb_font_t *priv; + cairo_xcb_font_glyphset_info_t *info; + int glyphset_index; + + glyphset_index = _cairo_xcb_get_glyphset_index_for_format (format); + + priv = _cairo_xcb_font_get (c, font); + if (priv == NULL) { + priv = _cairo_xcb_font_create (c, font); + if (priv == NULL) + return NULL; + } + + info = &priv->glyphset_info[glyphset_index]; + if (info->glyphset == XCB_NONE) { + info->glyphset = _cairo_xcb_connection_get_xid (c); + info->xrender_format = c->standard_formats[info->format]; + + _cairo_xcb_connection_render_create_glyph_set (c, + info->glyphset, + info->xrender_format); + } + + return info; +} + +static cairo_bool_t +_cairo_xcb_glyphset_info_has_pending_free_glyph ( + cairo_xcb_font_glyphset_info_t *info, + unsigned long glyph_index) +{ + if (info->pending_free_glyphs != NULL) { + cairo_xcb_font_glyphset_free_glyphs_t *to_free; + int i; + + to_free = info->pending_free_glyphs; + for (i = 0; i < to_free->glyph_count; i++) { + if (to_free->glyph_indices[i] == glyph_index) { + to_free->glyph_count--; + memmove (&to_free->glyph_indices[i], + &to_free->glyph_indices[i+1], + (to_free->glyph_count - i) * sizeof (to_free->glyph_indices[0])); + return TRUE; + } + } + } + + return FALSE; +} + +typedef struct { + cairo_scaled_glyph_private_t base; + + cairo_xcb_font_glyphset_info_t *glyphset; +} cairo_xcb_glyph_private_t; + +static cairo_xcb_font_glyphset_info_t * +_cairo_xcb_scaled_font_get_glyphset_info_for_pending_free_glyph (cairo_xcb_connection_t *c, + cairo_scaled_font_t *font, + unsigned long glyph_index, + cairo_image_surface_t *surface) +{ + cairo_xcb_font_t *priv; + int i; + + priv = _cairo_xcb_font_get (c, font); + if (priv == NULL) + return NULL; + + if (surface != NULL) { + i = _cairo_xcb_get_glyphset_index_for_format (surface->format); + + if (_cairo_xcb_glyphset_info_has_pending_free_glyph ( + &priv->glyphset_info[i], + glyph_index)) + { + return &priv->glyphset_info[i]; + } + } else { + for (i = 0; i < NUM_GLYPHSETS; i++) { + if (_cairo_xcb_glyphset_info_has_pending_free_glyph ( + &priv->glyphset_info[i], + glyph_index)) + { + return &priv->glyphset_info[i]; + } + } + } + + return NULL; +} + +static void +_cairo_xcb_glyph_fini (cairo_scaled_glyph_private_t *glyph_private, + cairo_scaled_glyph_t *glyph, + cairo_scaled_font_t *font) +{ + cairo_xcb_glyph_private_t *priv = (cairo_xcb_glyph_private_t *)glyph_private; + + if (! font->finished) { + cairo_xcb_font_glyphset_info_t *info = priv->glyphset; + cairo_xcb_font_glyphset_free_glyphs_t *to_free; + cairo_xcb_font_t *font_private; + + font_private = _cairo_xcb_font_get (glyph_private->key, font); + assert (font_private); + + to_free = info->pending_free_glyphs; + if (to_free != NULL && + to_free->glyph_count == ARRAY_LENGTH (to_free->glyph_indices)) + { + _cairo_xcb_render_free_glyphs (font_private->connection, to_free); + to_free = info->pending_free_glyphs = NULL; + } + + if (to_free == NULL) { + to_free = malloc (sizeof (cairo_xcb_font_glyphset_free_glyphs_t)); + if (unlikely (to_free == NULL)) { + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return; /* XXX cannot propagate failure */ + } + + to_free->glyphset = info->glyphset; + to_free->glyph_count = 0; + info->pending_free_glyphs = to_free; + } + + to_free->glyph_indices[to_free->glyph_count++] = + _cairo_scaled_glyph_index (glyph); + } + + cairo_list_del (&glyph_private->link); + free (glyph_private); +} + + +static cairo_status_t +_cairo_xcb_glyph_attach (cairo_xcb_connection_t *c, + cairo_scaled_glyph_t *glyph, + cairo_xcb_font_glyphset_info_t *info) +{ + cairo_xcb_glyph_private_t *priv; + + priv = malloc (sizeof (*priv)); + if (unlikely (priv == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_scaled_glyph_attach_private (glyph, &priv->base, c, + _cairo_xcb_glyph_fini); + priv->glyphset = info; + + glyph->dev_private = info; + glyph->dev_private_key = c; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xcb_surface_add_glyph (cairo_xcb_connection_t *connection, + cairo_scaled_font_t *font, + cairo_scaled_glyph_t **scaled_glyph_out) +{ + xcb_render_glyphinfo_t glyph_info; + uint32_t glyph_index; + uint8_t *data; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_scaled_glyph_t *scaled_glyph = *scaled_glyph_out; + cairo_image_surface_t *glyph_surface = scaled_glyph->surface; + cairo_bool_t already_had_glyph_surface; + cairo_xcb_font_glyphset_info_t *info; + + glyph_index = _cairo_scaled_glyph_index (scaled_glyph); + + /* check to see if we have a pending XRenderFreeGlyph for this glyph */ + info = _cairo_xcb_scaled_font_get_glyphset_info_for_pending_free_glyph (connection, font, glyph_index, glyph_surface); + if (info != NULL) + return _cairo_xcb_glyph_attach (connection, scaled_glyph, info); + + if (glyph_surface == NULL) { + status = _cairo_scaled_glyph_lookup (font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS | + CAIRO_SCALED_GLYPH_INFO_SURFACE, + scaled_glyph_out); + if (unlikely (status)) + return status; + + scaled_glyph = *scaled_glyph_out; + glyph_surface = scaled_glyph->surface; + already_had_glyph_surface = FALSE; + } else { + already_had_glyph_surface = TRUE; + } + + info = _cairo_xcb_scaled_font_get_glyphset_info_for_format (connection, + font, + glyph_surface->format); + if (unlikely (info == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + +#if 0 + /* If the glyph surface has zero height or width, we create + * a clear 1x1 surface, to avoid various X server bugs. + */ + if (glyph_surface->width == 0 || glyph_surface->height == 0) { + cairo_surface_t *tmp_surface; + + tmp_surface = cairo_image_surface_create (info->format, 1, 1); + status = tmp_surface->status; + if (unlikely (status)) + goto BAIL; + + tmp_surface->device_transform = glyph_surface->base.device_transform; + tmp_surface->device_transform_inverse = glyph_surface->base.device_transform_inverse; + + glyph_surface = (cairo_image_surface_t *) tmp_surface; + } +#endif + + /* If the glyph format does not match the font format, then we + * create a temporary surface for the glyph image with the font's + * format. + */ + if (glyph_surface->format != info->format) { + glyph_surface = _cairo_image_surface_coerce_to_format (glyph_surface, + info->format); + status = glyph_surface->base.status; + if (unlikely (status)) + goto BAIL; + } + + /* XXX: FRAGILE: We're ignore device_transform scaling here. A bug? */ + glyph_info.x = _cairo_lround (glyph_surface->base.device_transform.x0); + glyph_info.y = _cairo_lround (glyph_surface->base.device_transform.y0); + glyph_info.width = glyph_surface->width; + glyph_info.height = glyph_surface->height; + glyph_info.x_off = scaled_glyph->x_advance; + glyph_info.y_off = scaled_glyph->y_advance; + + data = glyph_surface->data; + + /* flip formats around */ + switch (_cairo_xcb_get_glyphset_index_for_format (scaled_glyph->surface->format)) { + case GLYPHSET_INDEX_A1: + /* local bitmaps are always stored with bit == byte */ + if (_cairo_is_little_endian() != (connection->root->bitmap_format_bit_order == XCB_IMAGE_ORDER_LSB_FIRST)) { + int c = glyph_surface->stride * glyph_surface->height; + const uint8_t *d; + uint8_t *new, *n; + + if (c == 0) + break; + + new = malloc (c); + if (unlikely (new == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + + n = new; + d = data; + do { + uint8_t b = *d++; + b = ((b << 1) & 0xaa) | ((b >> 1) & 0x55); + b = ((b << 2) & 0xcc) | ((b >> 2) & 0x33); + b = ((b << 4) & 0xf0) | ((b >> 4) & 0x0f); + *n++ = b; + } while (--c); + data = new; + } + break; + + case GLYPHSET_INDEX_A8: + break; + + case GLYPHSET_INDEX_ARGB32: + if (_cairo_is_little_endian() != (connection->root->image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST)) { + unsigned int c = glyph_surface->stride * glyph_surface->height / 4; + const uint32_t *d; + uint32_t *new, *n; + + if (c == 0) + break; + + new = malloc (4 * c); + if (unlikely (new == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + + n = new; + d = (uint32_t *) data; + do { + *n++ = bswap_32 (*d); + d++; + } while (--c); + data = (uint8_t *) new; + } + break; + + default: + ASSERT_NOT_REACHED; + break; + } + /* XXX assume X server wants pixman padding. Xft assumes this as well */ + + _cairo_xcb_connection_render_add_glyphs (connection, + info->glyphset, + 1, &glyph_index, &glyph_info, + glyph_surface->stride * glyph_surface->height, + data); + + if (data != glyph_surface->data) + free (data); + + status = _cairo_xcb_glyph_attach (connection, scaled_glyph, info); + + BAIL: + if (glyph_surface != scaled_glyph->surface) + cairo_surface_destroy (&glyph_surface->base); + + /* If the scaled glyph didn't already have a surface attached + * to it, release the created surface now that we have it + * uploaded to the X server. If the surface has already been + * there (e.g. because image backend requested it), leave it in + * the cache + */ + if (! already_had_glyph_surface) + _cairo_scaled_glyph_set_surface (scaled_glyph, font, NULL); + + return status; +} + +typedef void (*cairo_xcb_render_composite_text_func_t) + (cairo_xcb_connection_t *connection, + uint8_t op, + xcb_render_picture_t src, + xcb_render_picture_t dst, + xcb_render_pictformat_t mask_format, + xcb_render_glyphset_t glyphset, + int16_t src_x, + int16_t src_y, + uint32_t len, + uint8_t *cmd); + + +static cairo_status_t +_emit_glyphs_chunk (cairo_xcb_surface_t *dst, + cairo_operator_t op, + cairo_xcb_picture_t *src, + /* info for this chunk */ + cairo_xcb_glyph_t *glyphs, + int num_glyphs, + int width, + int estimated_req_size, + cairo_xcb_font_glyphset_info_t *info, + xcb_render_pictformat_t mask_format) +{ + cairo_xcb_render_composite_text_func_t composite_text_func; + uint8_t stack_buf[CAIRO_STACK_BUFFER_SIZE]; + uint8_t *buf = stack_buf; + x_glyph_elt_t *elt = NULL; /* silence compiler */ + uint32_t len; + int i; + + if (estimated_req_size > ARRAY_LENGTH (stack_buf)) { + buf = malloc (estimated_req_size); + if (unlikely (buf == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + len = 0; + for (i = 0; i < num_glyphs; i++) { + if (_start_new_glyph_elt (i, &glyphs[i])) { + if (len & 3) + len += 4 - (len & 3); + + elt = (x_glyph_elt_t *) (buf + len); + elt->len = 0; + elt->deltax = glyphs[i].i.x; + elt->deltay = glyphs[i].i.y; + len += sizeof (x_glyph_elt_t); + } + + switch (width) { + case 1: *(uint8_t *) (buf + len) = glyphs[i].index; break; + case 2: *(uint16_t *) (buf + len) = glyphs[i].index; break; + default: + case 4: *(uint32_t *) (buf + len) = glyphs[i].index; break; + } + len += width; + elt->len++; + } + if (len & 3) + len += 4 - (len & 3); + + switch (width) { + case 1: + composite_text_func = _cairo_xcb_connection_render_composite_glyphs_8; + break; + case 2: + composite_text_func = _cairo_xcb_connection_render_composite_glyphs_16; + break; + default: + case 4: + composite_text_func = _cairo_xcb_connection_render_composite_glyphs_32; + break; + } + composite_text_func (dst->connection, + _render_operator (op), + src->picture, + dst->picture, + mask_format, + info->glyphset, + src->x + glyphs[0].i.x, + src->y + glyphs[0].i.y, + len, buf); + + if (buf != stack_buf) + free (buf); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_composite_glyphs (void *closure, + cairo_xcb_surface_t *dst, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_clip_t *clip) +{ + composite_glyphs_info_t *info = closure; + cairo_scaled_glyph_t *glyph_cache[64]; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_fixed_t x = 0, y = 0; + cairo_xcb_font_glyphset_info_t *glyphset_info = NULL, *this_glyphset_info; + const unsigned int max_request_size = dst->connection->maximum_request_length - 64; + cairo_xcb_picture_t *src; + + unsigned long max_index = 0; + int width = 1; + + unsigned int request_size = 0; + int i; + + if (dst->deferred_clear) { + status = _cairo_xcb_surface_clear (dst); + if (unlikely (status)) + return status; + } + + src = _cairo_xcb_picture_for_pattern (dst, pattern, extents); + if (unlikely (src->base.status)) + return src->base.status; + + memset (glyph_cache, 0, sizeof (glyph_cache)); + + for (i = 0; i < info->num_glyphs; i++) { + cairo_scaled_glyph_t *glyph; + unsigned long glyph_index = info->glyphs[i].index; + int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); + int old_width = width; + int this_x, this_y; + + glyph = glyph_cache[cache_index]; + if (glyph == NULL || + _cairo_scaled_glyph_index (glyph) != glyph_index) + { + status = _cairo_scaled_glyph_lookup (info->font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &glyph); + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return status; + } + + /* Send unseen glyphs to the server */ + if (glyph->dev_private_key != dst->connection) { + status = _cairo_xcb_surface_add_glyph (dst->connection, + info->font, + &glyph); + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return status; + } + } + + glyph_cache[cache_index] = glyph; + } + + this_x = _cairo_lround (info->glyphs[i].d.x) - dst_x; + this_y = _cairo_lround (info->glyphs[i].d.y) - dst_y; + + this_glyphset_info = glyph->dev_private; + if (glyphset_info == NULL) + glyphset_info = this_glyphset_info; + + /* Update max glyph index */ + if (glyph_index > max_index) { + max_index = glyph_index; + if (max_index >= 65536) + width = 4; + else if (max_index >= 256) + width = 2; + if (width != old_width) + request_size += (width - old_width) * i; + } + + /* If we will pass the max request size by adding this glyph, + * flush current glyphs. Note that we account for a + * possible element being added below. + * + * Also flush if changing glyphsets, as Xrender limits one mask + * format per request, so we can either break up, or use a + * wide-enough mask format. We do the former. One reason to + * prefer the latter is the fact that Xserver ADDs all glyphs + * to the mask first, and then composes that to final surface, + * though it's not a big deal. + * + * If the glyph has a coordinate which cannot be represented + * as a 16-bit offset from the previous glyph, flush the + * current chunk. The current glyph will be the first one in + * the next chunk, thus its coordinates will be an offset from + * the destination origin. This offset is guaranteed to be + * representable as 16-bit offset in _can_composite_glyphs(). + */ + if (request_size + width > max_request_size - _cairo_sz_x_glyph_elt_t || + this_x - x > INT16_MAX || this_x - x < INT16_MIN || + this_y - y > INT16_MAX || this_y - y < INT16_MIN || + this_glyphset_info != glyphset_info) + { + status = _emit_glyphs_chunk (dst, op, src, + info->glyphs, i, + old_width, request_size, + glyphset_info, + info->use_mask ? glyphset_info->xrender_format : 0); + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return status; + } + + info->glyphs += i; + info->num_glyphs -= i; + i = 0; + + max_index = info->glyphs[0].index; + width = max_index < 256 ? 1 : max_index < 65536 ? 2 : 4; + + request_size = 0; + + x = y = 0; + glyphset_info = this_glyphset_info; + } + + /* Convert absolute glyph position to relative-to-current-point + * position */ + info->glyphs[i].i.x = this_x - x; + info->glyphs[i].i.y = this_y - y; + + /* Start a new element for the first glyph, + * or for any glyph that has unexpected position, + * or if current element has too many glyphs. + * + * These same conditions are mirrored in _emit_glyphs_chunk(). + */ + if (_start_new_glyph_elt (i, &info->glyphs[i])) + request_size += _cairo_sz_x_glyph_elt_t; + + /* adjust current-position */ + x = this_x + glyph->x_advance; + y = this_y + glyph->y_advance; + + request_size += width; + } + + if (i) { + status = _emit_glyphs_chunk (dst, op, src, + info->glyphs, i, + width, request_size, + glyphset_info, + info->use_mask ? glyphset_info->xrender_format : 0); + } + + cairo_surface_destroy (&src->base); + + return status; +} + +cairo_int_status_t +_cairo_xcb_render_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *composite, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface; + cairo_operator_t op = composite->op; + cairo_pattern_t *source = &composite->source_pattern.base; + cairo_int_status_t status; + + if (unlikely (! _operator_is_supported (surface->connection->flags, op))) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if ((surface->connection->flags & (CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS | CAIRO_XCB_RENDER_HAS_COMPOSITE)) == 0) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS) { + _cairo_scaled_font_freeze_cache (scaled_font); + + status = _can_composite_glyphs (surface, &composite->bounded, + scaled_font, glyphs, &num_glyphs); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { + composite_glyphs_info_t info; + unsigned flags = 0; + + info.font = scaled_font; + info.glyphs = (cairo_xcb_glyph_t *) glyphs; + info.num_glyphs = num_glyphs; + info.use_mask = + overlap || + ! composite->is_bounded || + ! _cairo_clip_is_region(composite->clip); + + if (composite->mask.width > composite->unbounded.width || + composite->mask.height > composite->unbounded.height) + { + /* Glyphs are tricky since we do not directly control the + * geometry and their inked extents depend on the + * individual glyph-surface size. We must set a clip region + * so that the X server can trim the glyphs appropriately. + */ + flags |= FORCE_CLIP_REGION; + } + status = _clip_and_composite (surface, op, source, + _composite_glyphs, NULL, + &info, composite, + need_bounded_clip (composite) | + flags); + } + + _cairo_scaled_font_thaw_cache (scaled_font); + } + + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + assert (surface->connection->flags & CAIRO_XCB_RENDER_HAS_COMPOSITE); + status = + _cairo_xcb_surface_render_glyphs_via_mask (surface, op, source, + scaled_font, glyphs, num_glyphs, + composite); + } + + return status; +} diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface.c new file mode 100644 index 00000000000..d4d60ad7285 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb-surface.c @@ -0,0 +1,1529 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Behdad Esfahbod + * Carl D. Worth + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ + +#include "cairoint.h" + +#include "cairo-xcb.h" +#include "cairo-xcb-private.h" + +#include "cairo-composite-rectangles-private.h" +#include "cairo-default-context-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-list-inline.h" +#include "cairo-surface-backend-private.h" +#include "cairo-compositor-private.h" + +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_proto (cairo_xcb_surface_create); +slim_hidden_proto (cairo_xcb_surface_create_for_bitmap); +slim_hidden_proto (cairo_xcb_surface_create_with_xrender_format); +#endif + +/** + * SECTION:cairo-xcb + * @Title: XCB Surfaces + * @Short_Description: X Window System rendering using the XCB library + * @See_Also: #cairo_surface_t + * + * The XCB surface is used to render cairo graphics to X Window System + * windows and pixmaps using the XCB library. + * + * Note that the XCB surface automatically takes advantage of the X render + * extension if it is available. + **/ + +/** + * CAIRO_HAS_XCB_SURFACE: + * + * Defined if the xcb surface backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.12 + **/ + +cairo_surface_t * +_cairo_xcb_surface_create_similar (void *abstract_other, + cairo_content_t content, + int width, + int height) +{ + cairo_xcb_surface_t *other = abstract_other; + cairo_xcb_surface_t *surface; + cairo_xcb_connection_t *connection; + xcb_pixmap_t pixmap; + cairo_status_t status; + + if (unlikely(width > XLIB_COORD_MAX || + height > XLIB_COORD_MAX || + width <= 0 || + height <= 0)) + return cairo_image_surface_create (_cairo_format_from_content (content), + width, height); + + if ((other->connection->flags & CAIRO_XCB_HAS_RENDER) == 0) + return _cairo_xcb_surface_create_similar_image (other, + _cairo_format_from_content (content), + width, height); + + connection = other->connection; + status = _cairo_xcb_connection_acquire (connection); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (content == other->base.content) { + pixmap = _cairo_xcb_connection_create_pixmap (connection, + other->depth, + other->drawable, + width, height); + + surface = (cairo_xcb_surface_t *) + _cairo_xcb_surface_create_internal (other->screen, + pixmap, TRUE, + other->pixman_format, + other->xrender_format, + width, height); + } else { + cairo_format_t format; + pixman_format_code_t pixman_format; + + /* XXX find a compatible xrender format */ + switch (content) { + case CAIRO_CONTENT_ALPHA: + pixman_format = PIXMAN_a8; + format = CAIRO_FORMAT_A8; + break; + case CAIRO_CONTENT_COLOR: + pixman_format = PIXMAN_x8r8g8b8; + format = CAIRO_FORMAT_RGB24; + break; + default: + ASSERT_NOT_REACHED; + case CAIRO_CONTENT_COLOR_ALPHA: + pixman_format = PIXMAN_a8r8g8b8; + format = CAIRO_FORMAT_ARGB32; + break; + } + + pixmap = _cairo_xcb_connection_create_pixmap (connection, + PIXMAN_FORMAT_DEPTH (pixman_format), + other->drawable, + width, height); + + surface = (cairo_xcb_surface_t *) + _cairo_xcb_surface_create_internal (other->screen, + pixmap, TRUE, + pixman_format, + connection->standard_formats[format], + width, height); + } + + if (unlikely (surface->base.status)) + _cairo_xcb_connection_free_pixmap (connection, pixmap); + + _cairo_xcb_connection_release (connection); + + return &surface->base; +} + +cairo_surface_t * +_cairo_xcb_surface_create_similar_image (void *abstract_other, + cairo_format_t format, + int width, + int height) +{ + cairo_xcb_surface_t *other = abstract_other; + cairo_xcb_connection_t *connection = other->connection; + + cairo_xcb_shm_info_t *shm_info; + cairo_image_surface_t *image; + cairo_status_t status; + pixman_format_code_t pixman_format; + + if (unlikely(width > XLIB_COORD_MAX || + height > XLIB_COORD_MAX || + width <= 0 || + height <= 0)) + return NULL; + + pixman_format = _cairo_format_to_pixman_format_code (format); + + status = _cairo_xcb_shm_image_create (connection, pixman_format, + width, height, &image, + &shm_info); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (! image->base.is_clear) { + memset (image->data, 0, image->stride * image->height); + image->base.is_clear = TRUE; + } + + return &image->base; +} + +static cairo_status_t +_cairo_xcb_surface_finish (void *abstract_surface) +{ + cairo_xcb_surface_t *surface = abstract_surface; + cairo_status_t status; + + if (surface->fallback != NULL) { + cairo_surface_finish (&surface->fallback->base); + cairo_surface_destroy (&surface->fallback->base); + } + _cairo_boxes_fini (&surface->fallback_damage); + + cairo_list_del (&surface->link); + + status = _cairo_xcb_connection_acquire (surface->connection); + if (status == CAIRO_STATUS_SUCCESS) { + if (surface->picture != XCB_NONE) { + _cairo_xcb_connection_render_free_picture (surface->connection, + surface->picture); + } + + if (surface->owns_pixmap) + _cairo_xcb_connection_free_pixmap (surface->connection, surface->drawable); + _cairo_xcb_connection_release (surface->connection); + } + + _cairo_xcb_connection_destroy (surface->connection); + + return status; +} + +static void +_destroy_image (pixman_image_t *image, void *data) +{ + free (data); +} + +#if CAIRO_HAS_XCB_SHM_FUNCTIONS +static cairo_surface_t * +_cairo_xcb_surface_create_shm_image (cairo_xcb_connection_t *connection, + pixman_format_code_t pixman_format, + int width, int height, + cairo_bool_t might_reuse, + cairo_xcb_shm_info_t **shm_info_out) +{ + cairo_surface_t *image; + cairo_xcb_shm_info_t *shm_info; + cairo_int_status_t status; + size_t stride; + + *shm_info_out = NULL; + + stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, + PIXMAN_FORMAT_BPP (pixman_format)); + status = _cairo_xcb_connection_allocate_shm_info (connection, + stride * height, + might_reuse, + &shm_info); + if (unlikely (status)) { + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + return NULL; + + return _cairo_surface_create_in_error (status); + } + + image = _cairo_image_surface_create_with_pixman_format (shm_info->mem, + pixman_format, + width, height, + stride); + if (unlikely (image->status)) { + _cairo_xcb_shm_info_destroy (shm_info); + return image; + } + + status = _cairo_user_data_array_set_data (&image->user_data, + (const cairo_user_data_key_t *) connection, + shm_info, + (cairo_destroy_func_t) _cairo_xcb_shm_info_destroy); + if (unlikely (status)) { + cairo_surface_destroy (image); + _cairo_xcb_shm_info_destroy (shm_info); + return _cairo_surface_create_in_error (status); + } + + *shm_info_out = shm_info; + return image; +} +#endif + +static cairo_surface_t * +_get_shm_image (cairo_xcb_surface_t *surface, + int x, int y, + int width, int height) +{ +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + cairo_xcb_shm_info_t *shm_info; + cairo_surface_t *image; + cairo_status_t status; + + if ((surface->connection->flags & CAIRO_XCB_HAS_SHM) == 0) + return NULL; + + image = _cairo_xcb_surface_create_shm_image (surface->connection, + surface->pixman_format, + width, height, + TRUE, + &shm_info); + if (unlikely (image == NULL || image->status)) + goto done; + + status = _cairo_xcb_connection_shm_get_image (surface->connection, + surface->drawable, + x, y, + width, height, + shm_info->shm, + shm_info->offset); + if (unlikely (status)) { + cairo_surface_destroy (image); + image = _cairo_surface_create_in_error (status); + } + +done: + return image; +#else + return NULL; +#endif +} + +static cairo_surface_t * +_get_image (cairo_xcb_surface_t *surface, + cairo_bool_t use_shm, + int x, int y, + int width, int height) +{ + cairo_surface_t *image; + cairo_xcb_connection_t *connection; + xcb_get_image_reply_t *reply; + cairo_int_status_t status; + + assert (surface->fallback == NULL); + assert (x >= 0); + assert (y >= 0); + assert (x + width <= surface->width); + assert (y + height <= surface->height); + + if (surface->deferred_clear) { + image = + _cairo_image_surface_create_with_pixman_format (NULL, + surface->pixman_format, + width, height, + 0); + if (surface->deferred_clear_color.alpha_short > 0x00ff) { + cairo_solid_pattern_t solid; + + _cairo_pattern_init_solid (&solid, &surface->deferred_clear_color); + status = _cairo_surface_paint (image, + CAIRO_OPERATOR_SOURCE, + &solid.base, + NULL); + if (unlikely (status)) { + cairo_surface_destroy (image); + image = _cairo_surface_create_in_error (status); + } + } + return image; + } + + connection = surface->connection; + + status = _cairo_xcb_connection_acquire (connection); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (use_shm) { + image = _get_shm_image (surface, x, y, width, height); + if (image) { + if (image->status == CAIRO_STATUS_SUCCESS) { + _cairo_xcb_connection_release (connection); + return image; + } + cairo_surface_destroy (image); + } + } + + reply =_cairo_xcb_connection_get_image (connection, + surface->drawable, + x, y, + width, height); + + if (reply == NULL && ! surface->owns_pixmap) { + /* xcb_get_image_t from a window is dangerous because it can + * produce errors if the window is unmapped or partially + * outside the screen. We could check for errors and + * retry, but to keep things simple, we just create a + * temporary pixmap + * + * If we hit this fallback too often, we should remember so and + * skip the round-trip from the above GetImage request, + * similar to what cairo-xlib does. + */ + xcb_pixmap_t pixmap; + xcb_gcontext_t gc; + + gc = _cairo_xcb_screen_get_gc (surface->screen, + surface->drawable, + surface->depth); + pixmap = _cairo_xcb_connection_create_pixmap (connection, + surface->depth, + surface->drawable, + width, height); + + /* XXX IncludeInferiors? */ + _cairo_xcb_connection_copy_area (connection, + surface->drawable, + pixmap, gc, + x, y, + 0, 0, + width, height); + + _cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc); + + reply = _cairo_xcb_connection_get_image (connection, + pixmap, + 0, 0, + width, height); + _cairo_xcb_connection_free_pixmap (connection, pixmap); + } + + if (unlikely (reply == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto FAIL; + } + + /* XXX byte swap */ + /* XXX format conversion */ + assert (reply->depth == surface->depth); + + image = _cairo_image_surface_create_with_pixman_format + (xcb_get_image_data (reply), + surface->pixman_format, + width, height, + CAIRO_STRIDE_FOR_WIDTH_BPP (width, + PIXMAN_FORMAT_BPP (surface->pixman_format))); + status = image->status; + if (unlikely (status)) { + free (reply); + goto FAIL; + } + + /* XXX */ + pixman_image_set_destroy_function (((cairo_image_surface_t *)image)->pixman_image, _destroy_image, reply); + + _cairo_xcb_connection_release (connection); + + return image; + +FAIL: + _cairo_xcb_connection_release (connection); + return _cairo_surface_create_in_error (status); +} + +static cairo_surface_t * +_cairo_xcb_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_xcb_surface_t *surface = abstract_surface; + + if (extents) { + extents->x = extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + } + + return &surface->base; +} + +static cairo_status_t +_cairo_xcb_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_xcb_surface_t *surface = abstract_surface; + cairo_surface_t *image; + + if (surface->fallback != NULL) { + image = cairo_surface_reference (&surface->fallback->base); + goto DONE; + } + + image = _cairo_surface_has_snapshot (&surface->base, + &_cairo_image_surface_backend); + if (image != NULL) { + image = cairo_surface_reference (image); + goto DONE; + } + + image = _get_image (surface, FALSE, 0, 0, surface->width, surface->height); + if (unlikely (image->status)) + return image->status; + + _cairo_surface_attach_snapshot (&surface->base, image, NULL); + +DONE: + *image_out = (cairo_image_surface_t *) image; + *image_extra = NULL; + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_xcb_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_surface_destroy (&image->base); +} + +cairo_bool_t +_cairo_xcb_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_xcb_surface_t *surface = abstract_surface; + + extents->x = extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + return TRUE; +} + +static void +_cairo_xcb_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_xcb_surface_t *surface = abstract_surface; + + *options = *_cairo_xcb_screen_get_font_options (surface->screen); +} + +static cairo_status_t +_put_shm_image (cairo_xcb_surface_t *surface, + xcb_gcontext_t gc, + cairo_image_surface_t *image) +{ +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + cairo_xcb_shm_info_t *shm_info; + + shm_info = _cairo_user_data_array_get_data (&image->base.user_data, + (const cairo_user_data_key_t *) surface->connection); + if (shm_info == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + _cairo_xcb_connection_shm_put_image (surface->connection, + surface->drawable, + gc, + surface->width, surface->height, + 0, 0, + image->width, image->height, + image->base.device_transform_inverse.x0, + image->base.device_transform_inverse.y0, + image->depth, + shm_info->shm, + shm_info->offset); + + return CAIRO_STATUS_SUCCESS; +#else + return CAIRO_INT_STATUS_UNSUPPORTED; +#endif +} + +static cairo_status_t +_put_image (cairo_xcb_surface_t *surface, + cairo_image_surface_t *image) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + + /* XXX track damaged region? */ + + status = _cairo_xcb_connection_acquire (surface->connection); + if (unlikely (status)) + return status; + + if (image->pixman_format == surface->pixman_format) { + xcb_gcontext_t gc; + + assert (image->depth == surface->depth); + assert (image->stride == (int) CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, PIXMAN_FORMAT_BPP (image->pixman_format))); + + gc = _cairo_xcb_screen_get_gc (surface->screen, + surface->drawable, + surface->depth); + + status = _put_shm_image (surface, gc, image); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + _cairo_xcb_connection_put_image (surface->connection, + surface->drawable, gc, + image->width, image->height, + image->base.device_transform_inverse.x0, + image->base.device_transform_inverse.y0, + image->depth, + image->stride, + image->data); + status = CAIRO_STATUS_SUCCESS; + } + + _cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc); + } else { + ASSERT_NOT_REACHED; + } + + _cairo_xcb_connection_release (surface->connection); + return status; +} + +static cairo_int_status_t +_put_shm_image_boxes (cairo_xcb_surface_t *surface, + cairo_image_surface_t *image, + xcb_gcontext_t gc, + cairo_boxes_t *boxes) +{ +#if CAIRO_HAS_XCB_SHM_FUNCTIONS + cairo_xcb_shm_info_t *shm_info; + + shm_info = _cairo_user_data_array_get_data (&image->base.user_data, + (const cairo_user_data_key_t *) surface->connection); + if (shm_info != NULL) { + struct _cairo_boxes_chunk *chunk; + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + int i; + + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + int x = _cairo_fixed_integer_part (b->p1.x); + int y = _cairo_fixed_integer_part (b->p1.y); + int width = _cairo_fixed_integer_part (b->p2.x - b->p1.x); + int height = _cairo_fixed_integer_part (b->p2.y - b->p1.y); + + _cairo_xcb_connection_shm_put_image (surface->connection, + surface->drawable, + gc, + surface->width, surface->height, + x, y, + width, height, + x, y, + image->depth, + shm_info->shm, + shm_info->offset); + } + } + return CAIRO_INT_STATUS_SUCCESS; + } +#endif + + return CAIRO_INT_STATUS_UNSUPPORTED; +} + +static cairo_status_t +_put_image_boxes (cairo_xcb_surface_t *surface, + cairo_image_surface_t *image, + cairo_boxes_t *boxes) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + xcb_gcontext_t gc; + + if (boxes->num_boxes == 0) + return CAIRO_STATUS_SUCCESS; + + /* XXX track damaged region? */ + + status = _cairo_xcb_connection_acquire (surface->connection); + if (unlikely (status)) + return status; + + assert (image->pixman_format == surface->pixman_format); + assert (image->depth == surface->depth); + assert (image->stride == (int) CAIRO_STRIDE_FOR_WIDTH_BPP (image->width, PIXMAN_FORMAT_BPP (image->pixman_format))); + + gc = _cairo_xcb_screen_get_gc (surface->screen, + surface->drawable, + surface->depth); + + status = _put_shm_image_boxes (surface, image, gc, boxes); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + struct _cairo_boxes_chunk *chunk; + + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + int i; + + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + int x = _cairo_fixed_integer_part (b->p1.x); + int y = _cairo_fixed_integer_part (b->p1.y); + int width = _cairo_fixed_integer_part (b->p2.x - b->p1.x); + int height = _cairo_fixed_integer_part (b->p2.y - b->p1.y); + _cairo_xcb_connection_put_subimage (surface->connection, + surface->drawable, gc, + x, y, + width, height, + PIXMAN_FORMAT_BPP (image->pixman_format) / 8, + image->stride, + x, y, + image->depth, + image->data); + + } + } + status = CAIRO_STATUS_SUCCESS; + } + + _cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc); + _cairo_xcb_connection_release (surface->connection); + return status; +} + +static cairo_status_t +_cairo_xcb_surface_flush (void *abstract_surface, + unsigned flags) +{ + cairo_xcb_surface_t *surface = abstract_surface; + cairo_status_t status; + + if (flags) + return CAIRO_STATUS_SUCCESS; + + if (likely (surface->fallback == NULL)) { + status = CAIRO_STATUS_SUCCESS; + if (! surface->base.finished && surface->deferred_clear) + status = _cairo_xcb_surface_clear (surface); + + return status; + } + + status = surface->base.status; + if (status == CAIRO_STATUS_SUCCESS && + (! surface->base._finishing || ! surface->owns_pixmap)) { + status = cairo_surface_status (&surface->fallback->base); + + if (status == CAIRO_STATUS_SUCCESS) + status = _cairo_bentley_ottmann_tessellate_boxes (&surface->fallback_damage, + CAIRO_FILL_RULE_WINDING, + &surface->fallback_damage); + + if (status == CAIRO_STATUS_SUCCESS) + status = _put_image_boxes (surface, + surface->fallback, + &surface->fallback_damage); + + if (status == CAIRO_STATUS_SUCCESS && ! surface->base._finishing) { + _cairo_surface_attach_snapshot (&surface->base, + &surface->fallback->base, + cairo_surface_finish); + } + } + + _cairo_boxes_clear (&surface->fallback_damage); + cairo_surface_destroy (&surface->fallback->base); + surface->fallback = NULL; + + return status; +} + +static cairo_image_surface_t * +_cairo_xcb_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_xcb_surface_t *surface = abstract_surface; + cairo_surface_t *image; + cairo_status_t status; + + if (surface->fallback) + return _cairo_surface_map_to_image (&surface->fallback->base, extents); + + image = _get_image (surface, TRUE, + extents->x, extents->y, + extents->width, extents->height); + status = cairo_surface_status (image); + if (unlikely (status)) { + cairo_surface_destroy(image); + return _cairo_image_surface_create_in_error (status); + } + + /* Do we have a deferred clear and this image surface does NOT cover the + * whole xcb surface? Have to apply the clear in that case, else + * uploading the image will handle the problem for us. + */ + if (surface->deferred_clear && + ! (extents->width == surface->width && + extents->height == surface->height)) { + status = _cairo_xcb_surface_clear (surface); + if (unlikely (status)) { + cairo_surface_destroy(image); + return _cairo_image_surface_create_in_error (status); + } + } + surface->deferred_clear = FALSE; + + cairo_surface_set_device_offset (image, -extents->x, -extents->y); + return (cairo_image_surface_t *) image; +} + +static cairo_int_status_t +_cairo_xcb_surface_unmap (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_xcb_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + if (surface->fallback) + return _cairo_surface_unmap_image (&surface->fallback->base, image); + + status = _put_image (abstract_surface, image); + + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return status; +} + +static cairo_surface_t * +_cairo_xcb_surface_fallback (cairo_xcb_surface_t *surface, + cairo_composite_rectangles_t *composite) +{ + cairo_image_surface_t *image; + cairo_status_t status; + + status = _cairo_composite_rectangles_add_to_damage (composite, + &surface->fallback_damage); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (surface->fallback) + return &surface->fallback->base; + + image = (cairo_image_surface_t *) + _get_image (surface, TRUE, 0, 0, surface->width, surface->height); + + /* If there was a deferred clear, _get_image applied it */ + if (image->base.status == CAIRO_STATUS_SUCCESS) { + surface->deferred_clear = FALSE; + + surface->fallback = image; + } + + return &surface->fallback->base; +} + +static cairo_int_status_t +_cairo_xcb_fallback_compositor_paint (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; + cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); + + return _cairo_surface_paint (fallback, extents->op, + &extents->source_pattern.base, + extents->clip); +} + +static cairo_int_status_t +_cairo_xcb_fallback_compositor_mask (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; + cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); + + return _cairo_surface_mask (fallback, extents->op, + &extents->source_pattern.base, + &extents->mask_pattern.base, + extents->clip); +} + +static cairo_int_status_t +_cairo_xcb_fallback_compositor_stroke (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; + cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); + + return _cairo_surface_stroke (fallback, extents->op, + &extents->source_pattern.base, + path, style, ctm, ctm_inverse, + tolerance, antialias, + extents->clip); +} + +static cairo_int_status_t +_cairo_xcb_fallback_compositor_fill (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; + cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); + + return _cairo_surface_fill (fallback, extents->op, + &extents->source_pattern.base, + path, fill_rule, tolerance, + antialias, extents->clip); +} + +static cairo_int_status_t +_cairo_xcb_fallback_compositor_glyphs (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface; + cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents); + + return _cairo_surface_show_text_glyphs (fallback, extents->op, + &extents->source_pattern.base, + NULL, 0, glyphs, num_glyphs, + NULL, 0, 0, + scaled_font, extents->clip); +} + +static const cairo_compositor_t _cairo_xcb_fallback_compositor = { + &__cairo_no_compositor, + + _cairo_xcb_fallback_compositor_paint, + _cairo_xcb_fallback_compositor_mask, + _cairo_xcb_fallback_compositor_stroke, + _cairo_xcb_fallback_compositor_fill, + _cairo_xcb_fallback_compositor_glyphs, +}; + +static const cairo_compositor_t _cairo_xcb_render_compositor = { + &_cairo_xcb_fallback_compositor, + + _cairo_xcb_render_compositor_paint, + _cairo_xcb_render_compositor_mask, + _cairo_xcb_render_compositor_stroke, + _cairo_xcb_render_compositor_fill, + _cairo_xcb_render_compositor_glyphs, +}; + +static inline const cairo_compositor_t * +get_compositor (cairo_surface_t **s) +{ + cairo_xcb_surface_t *surface = (cairo_xcb_surface_t * )*s; + if (surface->fallback) { + *s = &surface->fallback->base; + return ((cairo_image_surface_t *) *s)->compositor; + } + + return &_cairo_xcb_render_compositor; +} + +static cairo_int_status_t +_cairo_xcb_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_surface_t *surface = abstract_surface; + const cairo_compositor_t *compositor = get_compositor (&surface); + return _cairo_compositor_paint (compositor, surface, op, source, clip); +} + +static cairo_int_status_t +_cairo_xcb_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_surface_t *surface = abstract_surface; + const cairo_compositor_t *compositor = get_compositor (&surface); + return _cairo_compositor_mask (compositor, surface, op, source, mask, clip); +} + +static cairo_int_status_t +_cairo_xcb_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_surface_t *surface = abstract_surface; + const cairo_compositor_t *compositor = get_compositor (&surface); + return _cairo_compositor_stroke (compositor, surface, op, source, + path, style, ctm, ctm_inverse, + tolerance, antialias, clip); +} + +static cairo_int_status_t +_cairo_xcb_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_surface_t *surface = abstract_surface; + const cairo_compositor_t *compositor = get_compositor (&surface); + return _cairo_compositor_fill (compositor, surface, op, + source, path, fill_rule, + tolerance, antialias, clip); +} + +static cairo_int_status_t +_cairo_xcb_surface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_surface_t *surface = abstract_surface; + const cairo_compositor_t *compositor = get_compositor (&surface); + return _cairo_compositor_glyphs (compositor, surface, op, + source, glyphs, num_glyphs, + scaled_font, clip); +} + +const cairo_surface_backend_t _cairo_xcb_surface_backend = { + CAIRO_SURFACE_TYPE_XCB, + _cairo_xcb_surface_finish, + _cairo_default_context_create, + + _cairo_xcb_surface_create_similar, + _cairo_xcb_surface_create_similar_image, + _cairo_xcb_surface_map_to_image, + _cairo_xcb_surface_unmap, + + _cairo_xcb_surface_source, + _cairo_xcb_surface_acquire_source_image, + _cairo_xcb_surface_release_source_image, + NULL, /* snapshot */ + + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_xcb_surface_get_extents, + _cairo_xcb_surface_get_font_options, + + _cairo_xcb_surface_flush, + NULL, + + _cairo_xcb_surface_paint, + _cairo_xcb_surface_mask, + _cairo_xcb_surface_stroke, + _cairo_xcb_surface_fill, + NULL, /* fill-stroke */ + _cairo_xcb_surface_glyphs, +}; + +cairo_surface_t * +_cairo_xcb_surface_create_internal (cairo_xcb_screen_t *screen, + xcb_drawable_t drawable, + cairo_bool_t owns_pixmap, + pixman_format_code_t pixman_format, + xcb_render_pictformat_t xrender_format, + int width, + int height) +{ + cairo_xcb_surface_t *surface; + + surface = malloc (sizeof (cairo_xcb_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_xcb_surface_backend, + &screen->connection->device, + _cairo_content_from_pixman_format (pixman_format)); + + surface->connection = _cairo_xcb_connection_reference (screen->connection); + surface->screen = screen; + cairo_list_add (&surface->link, &screen->surfaces); + + surface->drawable = drawable; + surface->owns_pixmap = owns_pixmap; + + surface->deferred_clear = FALSE; + surface->deferred_clear_color = *CAIRO_COLOR_TRANSPARENT; + + surface->width = width; + surface->height = height; + surface->depth = PIXMAN_FORMAT_DEPTH (pixman_format); + + surface->picture = XCB_NONE; + if (screen->connection->force_precision != -1) + surface->precision = screen->connection->force_precision; + else + surface->precision = XCB_RENDER_POLY_MODE_IMPRECISE; + + surface->pixman_format = pixman_format; + surface->xrender_format = xrender_format; + + surface->fallback = NULL; + _cairo_boxes_init (&surface->fallback_damage); + + return &surface->base; +} + +static xcb_screen_t * +_cairo_xcb_screen_from_visual (xcb_connection_t *connection, + xcb_visualtype_t *visual, + int *depth) +{ + xcb_depth_iterator_t d; + xcb_screen_iterator_t s; + + s = xcb_setup_roots_iterator (xcb_get_setup (connection)); + for (; s.rem; xcb_screen_next (&s)) { + if (s.data->root_visual == visual->visual_id) { + *depth = s.data->root_depth; + return s.data; + } + + d = xcb_screen_allowed_depths_iterator(s.data); + for (; d.rem; xcb_depth_next (&d)) { + xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator (d.data); + + for (; v.rem; xcb_visualtype_next (&v)) { + if (v.data->visual_id == visual->visual_id) { + *depth = d.data->depth; + return s.data; + } + } + } + } + + return NULL; +} + +/** + * cairo_xcb_surface_create: + * @connection: an XCB connection + * @drawable: an XCB drawable + * @visual: the visual to use for drawing to @drawable. The depth + * of the visual must match the depth of the drawable. + * Currently, only TrueColor visuals are fully supported. + * @width: the current width of @drawable + * @height: the current height of @drawable + * + * Creates an XCB surface that draws to the given drawable. + * The way that colors are represented in the drawable is specified + * by the provided visual. + * + * Note: If @drawable is a Window, then the function + * cairo_xcb_surface_set_size() must be called whenever the size of the + * window changes. + * + * When @drawable is a Window containing child windows then drawing to + * the created surface will be clipped by those child windows. When + * the created surface is used as a source, the contents of the + * children will be included. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_xcb_surface_create (xcb_connection_t *connection, + xcb_drawable_t drawable, + xcb_visualtype_t *visual, + int width, + int height) +{ + cairo_xcb_screen_t *screen; + xcb_screen_t *xcb_screen; + cairo_format_masks_t image_masks; + pixman_format_code_t pixman_format; + xcb_render_pictformat_t xrender_format; + int depth; + + if (xcb_connection_has_error (connection)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); + + if (unlikely (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + if (unlikely (width <= 0 || height <= 0)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + xcb_screen = _cairo_xcb_screen_from_visual (connection, visual, &depth); + if (unlikely (xcb_screen == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); + + image_masks.alpha_mask = 0; + image_masks.red_mask = visual->red_mask; + image_masks.green_mask = visual->green_mask; + image_masks.blue_mask = visual->blue_mask; + if (depth == 32) /* XXX visuals have no alpha! */ + image_masks.alpha_mask = + 0xffffffff & ~(visual->red_mask | visual->green_mask | visual->blue_mask); + if (depth > 16) + image_masks.bpp = 32; + else if (depth > 8) + image_masks.bpp = 16; + else if (depth > 1) + image_masks.bpp = 8; + else + image_masks.bpp = 1; + + if (! _pixman_format_from_masks (&image_masks, &pixman_format)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + + screen = _cairo_xcb_screen_get (connection, xcb_screen); + if (unlikely (screen == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + xrender_format = + _cairo_xcb_connection_get_xrender_format_for_visual (screen->connection, + visual->visual_id); + + return _cairo_xcb_surface_create_internal (screen, drawable, FALSE, + pixman_format, + xrender_format, + width, height); +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_surface_create); +#endif + +/** + * cairo_xcb_surface_create_for_bitmap: + * @connection: an XCB connection + * @screen: the XCB screen associated with @bitmap + * @bitmap: an XCB drawable (a Pixmap with depth 1) + * @width: the current width of @bitmap + * @height: the current height of @bitmap + * + * Creates an XCB surface that draws to the given bitmap. + * This will be drawn to as a %CAIRO_FORMAT_A1 object. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_xcb_surface_create_for_bitmap (xcb_connection_t *connection, + xcb_screen_t *screen, + xcb_pixmap_t bitmap, + int width, + int height) +{ + cairo_xcb_screen_t *cairo_xcb_screen; + + if (xcb_connection_has_error (connection)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); + + if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + if (unlikely (width <= 0 || height <= 0)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + cairo_xcb_screen = _cairo_xcb_screen_get (connection, screen); + if (unlikely (cairo_xcb_screen == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + return _cairo_xcb_surface_create_internal (cairo_xcb_screen, bitmap, FALSE, + PIXMAN_a1, + cairo_xcb_screen->connection->standard_formats[CAIRO_FORMAT_A1], + width, height); +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_surface_create_for_bitmap); +#endif + +/** + * cairo_xcb_surface_create_with_xrender_format: + * @connection: an XCB connection + * @drawable: an XCB drawable + * @screen: the XCB screen associated with @drawable + * @format: the picture format to use for drawing to @drawable. The + * depth of @format mush match the depth of the drawable. + * @width: the current width of @drawable + * @height: the current height of @drawable + * + * Creates an XCB surface that draws to the given drawable. + * The way that colors are represented in the drawable is specified + * by the provided picture format. + * + * Note: If @drawable is a Window, then the function + * cairo_xcb_surface_set_size() must be called whenever the size of the + * window changes. + * + * When @drawable is a Window containing child windows then drawing to + * the created surface will be clipped by those child windows. When + * the created surface is used as a source, the contents of the + * children will be included. + * + * Return value: a pointer to the newly created surface. The caller + * owns the surface and should call cairo_surface_destroy() when done + * with it. + * + * This function always returns a valid pointer, but it will return a + * pointer to a "nil" surface if an error such as out of memory + * occurs. You can use cairo_surface_status() to check for this. + * + * Since: 1.12 + **/ +cairo_surface_t * +cairo_xcb_surface_create_with_xrender_format (xcb_connection_t *connection, + xcb_screen_t *screen, + xcb_drawable_t drawable, + xcb_render_pictforminfo_t *format, + int width, + int height) +{ + cairo_xcb_screen_t *cairo_xcb_screen; + cairo_format_masks_t image_masks; + pixman_format_code_t pixman_format; + + if (xcb_connection_has_error (connection)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); + + if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + if (unlikely (width <= 0 || height <= 0)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + image_masks.alpha_mask = + (unsigned long) format->direct.alpha_mask << format->direct.alpha_shift; + image_masks.red_mask = + (unsigned long) format->direct.red_mask << format->direct.red_shift; + image_masks.green_mask = + (unsigned long) format->direct.green_mask << format->direct.green_shift; + image_masks.blue_mask = + (unsigned long) format->direct.blue_mask << format->direct.blue_shift; +#if 0 + image_masks.bpp = format->depth; +#else + if (format->depth > 16) + image_masks.bpp = 32; + else if (format->depth > 8) + image_masks.bpp = 16; + else if (format->depth > 1) + image_masks.bpp = 8; + else + image_masks.bpp = 1; +#endif + + if (! _pixman_format_from_masks (&image_masks, &pixman_format)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); + + cairo_xcb_screen = _cairo_xcb_screen_get (connection, screen); + if (unlikely (cairo_xcb_screen == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + return _cairo_xcb_surface_create_internal (cairo_xcb_screen, + drawable, + FALSE, + pixman_format, + format->id, + width, height); +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_surface_create_with_xrender_format); +#endif + +/* This does the necessary fixup when a surface's drawable or size changed. */ +static void +_drawable_changed (cairo_xcb_surface_t *surface) +{ + _cairo_surface_set_error (&surface->base, + _cairo_surface_begin_modification (&surface->base)); + _cairo_boxes_clear (&surface->fallback_damage); + cairo_surface_destroy (&surface->fallback->base); + + surface->deferred_clear = FALSE; + surface->fallback = NULL; +} + +/** + * cairo_xcb_surface_set_size: + * @surface: a #cairo_surface_t for the XCB backend + * @width: the new width of the surface + * @height: the new height of the surface + * + * Informs cairo of the new size of the XCB drawable underlying the + * surface. For a surface created for a window (rather than a pixmap), + * this function must be called each time the size of the window + * changes. (For a subwindow, you are normally resizing the window + * yourself, but for a toplevel window, it is necessary to listen for + * ConfigureNotify events.) + * + * A pixmap can never change size, so it is never necessary to call + * this function on a surface created for a pixmap. + * + * If cairo_surface_flush() wasn't called, some pending operations + * might be discarded. + * + * Since: 1.12 + **/ +void +cairo_xcb_surface_set_size (cairo_surface_t *abstract_surface, + int width, + int height) +{ + cairo_xcb_surface_t *surface; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + + if ( !_cairo_surface_is_xcb(abstract_surface)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX || width <= 0 || height <= 0) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_INVALID_SIZE)); + return; + } + + surface = (cairo_xcb_surface_t *) abstract_surface; + + _drawable_changed(surface); + surface->width = width; + surface->height = height; +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_surface_set_size); +#endif + +/** + * cairo_xcb_surface_set_drawable: + * @surface: a #cairo_surface_t for the XCB backend + * @drawable: the new drawable of the surface + * @width: the new width of the surface + * @height: the new height of the surface + * + * Informs cairo of the new drawable and size of the XCB drawable underlying the + * surface. + * + * If cairo_surface_flush() wasn't called, some pending operations + * might be discarded. + * + * Since: 1.12 + **/ +void +cairo_xcb_surface_set_drawable (cairo_surface_t *abstract_surface, + xcb_drawable_t drawable, + int width, + int height) +{ + cairo_xcb_surface_t *surface; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + + if ( !_cairo_surface_is_xcb(abstract_surface)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX || width <= 0 || height <= 0) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_INVALID_SIZE)); + return; + } + + surface = (cairo_xcb_surface_t *) abstract_surface; + + /* XXX: and what about this case? */ + if (surface->owns_pixmap) + return; + + _drawable_changed (surface); + + if (surface->drawable != drawable) { + cairo_status_t status; + status = _cairo_xcb_connection_acquire (surface->connection); + if (unlikely (status)) + return; + + if (surface->picture != XCB_NONE) { + _cairo_xcb_connection_render_free_picture (surface->connection, + surface->picture); + surface->picture = XCB_NONE; + } + + _cairo_xcb_connection_release (surface->connection); + + surface->drawable = drawable; + } + surface->width = width; + surface->height = height; +} +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS +slim_hidden_def (cairo_xcb_surface_set_drawable); +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xcb.h b/Build/source/libs/cairo/cairo-src/src/cairo-xcb.h new file mode 100644 index 00000000000..e321d8482c2 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xcb.h @@ -0,0 +1,116 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#ifndef CAIRO_XCB_H +#define CAIRO_XCB_H + +#include "cairo.h" + +#if CAIRO_HAS_XCB_SURFACE + +#include +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_xcb_surface_create (xcb_connection_t *connection, + xcb_drawable_t drawable, + xcb_visualtype_t *visual, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_xcb_surface_create_for_bitmap (xcb_connection_t *connection, + xcb_screen_t *screen, + xcb_pixmap_t bitmap, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_xcb_surface_create_with_xrender_format (xcb_connection_t *connection, + xcb_screen_t *screen, + xcb_drawable_t drawable, + xcb_render_pictforminfo_t *format, + int width, + int height); + +cairo_public void +cairo_xcb_surface_set_size (cairo_surface_t *surface, + int width, + int height); + +cairo_public void +cairo_xcb_surface_set_drawable (cairo_surface_t *surface, + xcb_drawable_t drawable, + int width, + int height); + +cairo_public xcb_connection_t * +cairo_xcb_device_get_connection (cairo_device_t *device); + +/* debug interface */ + +cairo_public void +cairo_xcb_device_debug_cap_xshm_version (cairo_device_t *device, + int major_version, + int minor_version); + +cairo_public void +cairo_xcb_device_debug_cap_xrender_version (cairo_device_t *device, + int major_version, + int minor_version); + +/* + * @precision: -1 implies automatically choose based on antialiasing mode, + * any other value overrides and sets the corresponding PolyMode. + */ +cairo_public void +cairo_xcb_device_debug_set_precision (cairo_device_t *device, + int precision); + +cairo_public int +cairo_xcb_device_debug_get_precision (cairo_device_t *device); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_XCB_SURFACE */ +# error Cairo was not compiled with support for the xcb backend +#endif /* CAIRO_HAS_XCB_SURFACE */ + +#endif /* CAIRO_XCB_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-core-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-core-compositor.c new file mode 100644 index 00000000000..5babcc81bed --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-core-compositor.c @@ -0,0 +1,650 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Behdad Esfahbod + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ + +/* The original X drawing API was very restrictive in what it could handle, + * pixel-aligned fill/blits are all that map into Cairo's drawing model. + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" +#include "cairo-xlib-surface-private.h" + +#include "cairo-boxes-private.h" +#include "cairo-clip-inline.h" +#include "cairo-compositor-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-pattern-private.h" +#include "cairo-region-private.h" +#include "cairo-surface-offset-private.h" + +/* the low-level interface */ + +static cairo_int_status_t +acquire (void *abstract_dst) +{ + cairo_xlib_surface_t *dst = abstract_dst; + return _cairo_xlib_display_acquire (dst->base.device, &dst->display); +} + +static cairo_int_status_t +release (void *abstract_dst) +{ + cairo_xlib_surface_t *dst = abstract_dst; + + cairo_device_release (&dst->display->base); + dst->display = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +struct _fill_box { + Display *dpy; + Drawable drawable; + GC gc; + //cairo_surface_t *dither = NULL; +}; + +static cairo_bool_t fill_box (cairo_box_t *box, void *closure) +{ + struct _fill_box *data = closure; + int x = _cairo_fixed_integer_part (box->p1.x); + int y = _cairo_fixed_integer_part (box->p1.y); + int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); + int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); + + XFillRectangle (data->dpy, data->drawable, data->gc, x, y, width, height); + return TRUE; +} + +static void +_characterize_field (uint32_t mask, int *width, int *shift) +{ + *width = _cairo_popcount (mask); + /* The final '& 31' is to force a 0 mask to result in 0 shift. */ + *shift = _cairo_popcount ((mask - 1) & ~mask) & 31; +} + +static uint32_t +color_to_pixel (cairo_xlib_surface_t *dst, + const cairo_color_t *color) +{ + uint32_t rgba = 0; + int width, shift; + + _characterize_field (dst->a_mask, &width, &shift); + rgba |= color->alpha_short >> (16 - width) << shift; + + _characterize_field (dst->r_mask, &width, &shift); + rgba |= color->red_short >> (16 - width) << shift; + + _characterize_field (dst->g_mask, &width, &shift); + rgba |= color->green_short >> (16 - width) << shift; + + _characterize_field (dst->b_mask, &width, &shift); + rgba |= color->blue_short >> (16 - width) << shift; + + return rgba; +} + +static cairo_int_status_t +_fill_box_init (struct _fill_box *fb, + cairo_xlib_surface_t *dst, + const cairo_color_t *color) +{ + cairo_int_status_t status; + + status = _cairo_xlib_surface_get_gc (dst->display, dst, &fb->gc); + if (unlikely (status)) + return status; + + fb->dpy = dst->display->display; + fb->drawable = dst->drawable; + + if (dst->visual && dst->visual->class != TrueColor && 0) { +#if 0 + cairo_solid_pattern_t solid; + cairo_surface_attributes_t attrs; + + _cairo_pattern_init_solid (&solid, color); + status = _cairo_pattern_acquire_surface (&solid.base, &dst->base, + 0, 0, + ARRAY_LENGTH (dither_pattern[0]), + ARRAY_LENGTH (dither_pattern), + CAIRO_PATTERN_ACQUIRE_NONE, + &dither, + &attrs); + if (unlikely (status)) { + _cairo_xlib_surface_put_gc (dst->display, dst, fb.gc); + return status; + } + + XSetTSOrigin (fb->dpy, fb->gc, + - (dst->base.device_transform.x0 + attrs.x_offset), + - (dst->base.device_transform.y0 + attrs.y_offset)); + XSetTile (fb->dpy, fb->gc, ((cairo_xlib_surface_t *) dither)->drawable); +#endif + } else { + XGCValues gcv; + + gcv.foreground = color_to_pixel (dst, color); + gcv.fill_style = FillSolid; + + XChangeGC (fb->dpy, fb->gc, GCFillStyle | GCForeground, &gcv); + } + + return CAIRO_INT_STATUS_SUCCESS; +} + +static void +_fill_box_fini (struct _fill_box *fb, + cairo_xlib_surface_t *dst) +{ + _cairo_xlib_surface_put_gc (dst->display, dst, fb->gc); + //cairo_surface_destroy (fb->dither); +} + +cairo_int_status_t +_cairo_xlib_core_fill_boxes (cairo_xlib_surface_t *dst, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + cairo_int_status_t status; + struct _fill_box fb; + + status = _fill_box_init (&fb, dst, color); + if (unlikely (status)) + return status; + + _cairo_boxes_for_each_box (boxes, fill_box, &fb); + + _fill_box_fini (&fb, dst); + return CAIRO_STATUS_SUCCESS; +} + +cairo_int_status_t +_cairo_xlib_core_fill_rectangles (cairo_xlib_surface_t *dst, + const cairo_color_t *color, + int num_rects, + cairo_rectangle_int_t *rects) +{ + cairo_int_status_t status; + struct _fill_box fb; + int i; + + status = _fill_box_init (&fb, dst, color); + if (unlikely (status)) + return status; + + for (i = 0; i < num_rects; i++) + XFillRectangle (fb.dpy, fb.drawable, fb.gc, + rects[i].x, rects[i].y, + rects[i].width, rects[i].height); + + _fill_box_fini (&fb, dst); + return CAIRO_STATUS_SUCCESS; +} + +struct _fallback_box { + cairo_xlib_surface_t *dst; + cairo_format_t format; + const cairo_pattern_t *pattern; +}; + +static cairo_bool_t fallback_box (cairo_box_t *box, void *closure) +{ + struct _fallback_box *data = closure; + int x = _cairo_fixed_integer_part (box->p1.x); + int y = _cairo_fixed_integer_part (box->p1.y); + int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); + int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); + cairo_surface_t *image; + cairo_status_t status; + + /* XXX for EXTEND_NONE and if the box is wholly outside we can just fill */ + + image = cairo_surface_create_similar_image (&data->dst->base, data->format, + width, height); + status = _cairo_surface_offset_paint (image, x, y, + CAIRO_OPERATOR_SOURCE, + data->pattern, NULL); + if (status == CAIRO_STATUS_SUCCESS) { + status = _cairo_xlib_surface_draw_image (data->dst, + (cairo_image_surface_t *)image, + 0, 0, + width, height, + x, y); + } + cairo_surface_destroy (image); + + return status == CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +fallback_boxes (cairo_xlib_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_boxes_t *boxes) +{ + struct _fallback_box fb; + + /* XXX create_similar_image using pixman_format? */ + switch (dst->depth) { + case 8: fb.format = CAIRO_FORMAT_A8; break; + case 16: fb.format = CAIRO_FORMAT_RGB16_565; break; + case 24: fb.format = CAIRO_FORMAT_RGB24; break; + case 30: fb.format = CAIRO_FORMAT_RGB30; break; + case 32: fb.format = CAIRO_FORMAT_ARGB32; break; + default: return CAIRO_INT_STATUS_UNSUPPORTED; + } + + fb.dst = dst; + fb.pattern = pattern; + + if (! _cairo_boxes_for_each_box (boxes, fallback_box, &fb)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +render_boxes (cairo_xlib_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_boxes_t *boxes) +{ + if (pattern->filter != CAIRO_FILTER_NEAREST) + return fallback_boxes (dst, pattern, boxes); + + switch (pattern->extend) { + default: + case CAIRO_EXTEND_NONE: + case CAIRO_EXTEND_REFLECT: + case CAIRO_EXTEND_PAD: + return fallback_boxes (dst, pattern, boxes); + + case CAIRO_EXTEND_REPEAT: /* XXX Use tiling */ + return fallback_boxes (dst, pattern, boxes); + } +} + +/* the mid-level: converts boxes into drawing operations */ + +struct _box_data { + Display *dpy; + cairo_xlib_surface_t *dst; + cairo_surface_t *src; + GC gc; + int tx, ty; + int width, height; +}; + +static cairo_bool_t source_contains_box (cairo_box_t *box, void *closure) +{ + struct _box_data *data = closure; + + /* The box is pixel-aligned so the truncation is safe. */ + return + _cairo_fixed_integer_part (box->p1.x) + data->tx >= 0 && + _cairo_fixed_integer_part (box->p1.y) + data->ty >= 0 && + _cairo_fixed_integer_part (box->p2.x) + data->tx <= data->width && + _cairo_fixed_integer_part (box->p2.y) + data->ty <= data->height; +} + +static cairo_bool_t image_upload_box (cairo_box_t *box, void *closure) +{ + const struct _box_data *iub = closure; + int x = _cairo_fixed_integer_part (box->p1.x); + int y = _cairo_fixed_integer_part (box->p1.y); + int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); + int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); + + return _cairo_xlib_surface_draw_image (iub->dst, + (cairo_image_surface_t *)iub->src, + x + iub->tx, y + iub->ty, + width, height, + x, y) == CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +surface_matches_image_format (cairo_xlib_surface_t *surface, + cairo_image_surface_t *image) +{ + cairo_format_masks_t format; + + return (_pixman_format_to_masks (image->pixman_format, &format) && + (format.alpha_mask == surface->a_mask || surface->a_mask == 0) && + (format.red_mask == surface->r_mask || surface->r_mask == 0) && + (format.green_mask == surface->g_mask || surface->g_mask == 0) && + (format.blue_mask == surface->b_mask || surface->b_mask == 0)); +} + +static cairo_status_t +upload_image_inplace (cairo_xlib_surface_t *dst, + const cairo_pattern_t *source, + cairo_boxes_t *boxes) +{ + const cairo_surface_pattern_t *pattern; + struct _box_data iub; + cairo_image_surface_t *image; + + if (source->type != CAIRO_PATTERN_TYPE_SURFACE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + pattern = (const cairo_surface_pattern_t *) source; + if (pattern->surface->type != CAIRO_SURFACE_TYPE_IMAGE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + image = (cairo_image_surface_t *) pattern->surface; + if (image->format == CAIRO_FORMAT_INVALID) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (image->depth != dst->depth) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! surface_matches_image_format (dst, image)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* XXX subsurface */ + + if (! _cairo_matrix_is_integer_translation (&source->matrix, + &iub.tx, &iub.ty)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + iub.dst = dst; + iub.src = &image->base; + iub.width = image->width; + iub.height = image->height; + + /* First check that the data is entirely within the image */ + if (! _cairo_boxes_for_each_box (boxes, source_contains_box, &iub)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_boxes_for_each_box (boxes, image_upload_box, &iub)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t copy_box (cairo_box_t *box, void *closure) +{ + const struct _box_data *cb = closure; + int x = _cairo_fixed_integer_part (box->p1.x); + int y = _cairo_fixed_integer_part (box->p1.y); + int width = _cairo_fixed_integer_part (box->p2.x - box->p1.x); + int height = _cairo_fixed_integer_part (box->p2.y - box->p1.y); + + XCopyArea (cb->dpy, + ((cairo_xlib_surface_t *)cb->src)->drawable, + cb->dst->drawable, + cb->gc, + x + cb->tx, y + cb->ty, + width, height, + x, y); + return TRUE; +} + +static cairo_status_t +copy_boxes (cairo_xlib_surface_t *dst, + const cairo_pattern_t *source, + cairo_boxes_t *boxes) +{ + const cairo_surface_pattern_t *pattern; + struct _box_data cb; + cairo_xlib_surface_t *src; + cairo_status_t status; + + if (source->type != CAIRO_PATTERN_TYPE_SURFACE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* XXX subsurface */ + + pattern = (const cairo_surface_pattern_t *) source; + if (pattern->surface->backend->type != CAIRO_SURFACE_TYPE_XLIB) + return CAIRO_INT_STATUS_UNSUPPORTED; + + src = (cairo_xlib_surface_t *) pattern->surface; + if (src->depth != dst->depth) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* We can only have a single control for subwindow_mode on the + * GC. If we have a Window destination, we need to set ClipByChildren, + * but if we have a Window source, we need IncludeInferiors. If we have + * both a Window destination and source, we must fallback. There is + * no convenient way to detect if a drawable is a Pixmap or Window, + * therefore we can only rely on those surfaces that we created + * ourselves to be Pixmaps, and treat everything else as a potential + * Window. + */ + if (! src->owns_pixmap && ! dst->owns_pixmap) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_xlib_surface_same_screen (dst, src)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (! _cairo_matrix_is_integer_translation (&source->matrix, + &cb.tx, &cb.ty)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + cb.dpy = dst->display->display; + cb.dst = dst; + cb.src = &src->base; + cb.width = src->width; + cb.height = src->height; + + /* First check that the data is entirely within the image */ + if (! _cairo_boxes_for_each_box (boxes, source_contains_box, &cb)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_xlib_surface_get_gc (dst->display, dst, &cb.gc); + if (unlikely (status)) + return status; + + if (! src->owns_pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = IncludeInferiors; + XChangeGC (dst->display->display, cb.gc, GCSubwindowMode, &gcv); + } + + status = CAIRO_STATUS_SUCCESS; + if (! _cairo_boxes_for_each_box (boxes, copy_box, &cb)) + status = CAIRO_INT_STATUS_UNSUPPORTED; + + if (! src->owns_pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = ClipByChildren; + XChangeGC (dst->display->display, cb.gc, GCSubwindowMode, &gcv); + } + + _cairo_xlib_surface_put_gc (dst->display, dst, cb.gc); + + return status; +} + +static cairo_status_t +draw_boxes (cairo_composite_rectangles_t *extents, + cairo_boxes_t *boxes) +{ + cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)extents->surface; + cairo_operator_t op = extents->op; + const cairo_pattern_t *src = &extents->source_pattern.base; + cairo_int_status_t status; + + if (boxes->num_boxes == 0 && extents->is_bounded) + return CAIRO_STATUS_SUCCESS; + + if (! boxes->is_pixel_aligned) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (op == CAIRO_OPERATOR_CLEAR) + op = CAIRO_OPERATOR_SOURCE; + + if (op == CAIRO_OPERATOR_OVER && + _cairo_pattern_is_opaque (src, &extents->bounded)) + op = CAIRO_OPERATOR_SOURCE; + + if (dst->base.is_clear && op == CAIRO_OPERATOR_OVER) + op = CAIRO_OPERATOR_SOURCE; + + if (op != CAIRO_OPERATOR_SOURCE) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = acquire (dst); + if (unlikely (status)) + return status; + + if (src->type == CAIRO_PATTERN_TYPE_SOLID) { + status = _cairo_xlib_core_fill_boxes + (dst, &((cairo_solid_pattern_t *) src)->color, boxes); + } else { + status = upload_image_inplace (dst, src, boxes); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + status = copy_boxes (dst, src, boxes); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) + status = render_boxes (dst, src, boxes); + } + + release (dst); + + return status; +} + +/* high-level compositor interface */ + +static cairo_int_status_t +_cairo_xlib_core_compositor_paint (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_int_status_t status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (_cairo_clip_is_region (extents->clip)) { + cairo_boxes_t boxes; + + _cairo_clip_steal_boxes (extents->clip, &boxes); + status = draw_boxes (extents, &boxes); + _cairo_clip_unsteal_boxes (extents->clip, &boxes); + } + + return status; +} + +static cairo_int_status_t +_cairo_xlib_core_compositor_stroke (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_int_status_t status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (extents->clip->path == NULL && + _cairo_path_fixed_stroke_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, extents->clip); + status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, + style, + ctm, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = draw_boxes (extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + return status; +} + +static cairo_int_status_t +_cairo_xlib_core_compositor_fill (const cairo_compositor_t *compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_int_status_t status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (extents->clip->path == NULL && + _cairo_path_fixed_fill_is_rectilinear (path)) { + cairo_boxes_t boxes; + + _cairo_boxes_init_with_clip (&boxes, extents->clip); + status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, + fill_rule, + antialias, + &boxes); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = draw_boxes (extents, &boxes); + _cairo_boxes_fini (&boxes); + } + + return status; +} + +const cairo_compositor_t * +_cairo_xlib_core_compositor_get (void) +{ + static cairo_compositor_t compositor; + + if (compositor.delegate == NULL) { + compositor.delegate = _cairo_xlib_fallback_compositor_get (); + + compositor.paint = _cairo_xlib_core_compositor_paint; + compositor.mask = NULL; + compositor.fill = _cairo_xlib_core_compositor_fill; + compositor.stroke = _cairo_xlib_core_compositor_stroke; + compositor.glyphs = NULL; /* XXX PolyGlyph? */ + } + + return &compositor; +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-display.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-display.c new file mode 100644 index 00000000000..a2a3bc7924b --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-display.c @@ -0,0 +1,655 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Karl Tomlinson , Mozilla Corporation + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" +#include "cairo-xlib-xrender-private.h" +#include "cairo-freelist-private.h" +#include "cairo-error-private.h" +#include "cairo-list-inline.h" + +#include /* For XESetCloseDisplay */ + +typedef int (*cairo_xlib_error_func_t) (Display *display, + XErrorEvent *event); + +static cairo_xlib_display_t *_cairo_xlib_display_list; + +static int +_noop_error_handler (Display *display, + XErrorEvent *event) +{ + return False; /* return value is ignored */ +} + +static void +_cairo_xlib_display_finish (void *abstract_display) +{ + cairo_xlib_display_t *display = abstract_display; + Display *dpy = display->display; + + _cairo_xlib_display_fini_shm (display); + + if (! cairo_device_acquire (&display->base)) { + cairo_xlib_error_func_t old_handler; + + /* protect the notifies from triggering XErrors */ + XSync (dpy, False); + old_handler = XSetErrorHandler (_noop_error_handler); + + while (! cairo_list_is_empty (&display->fonts)) { + _cairo_xlib_font_close (cairo_list_first_entry (&display->fonts, + cairo_xlib_font_t, + link)); + } + + while (! cairo_list_is_empty (&display->screens)) { + _cairo_xlib_screen_destroy (display, + cairo_list_first_entry (&display->screens, + cairo_xlib_screen_t, + link)); + } + + XSync (dpy, False); + XSetErrorHandler (old_handler); + + cairo_device_release (&display->base); + } +} + +static void +_cairo_xlib_display_destroy (void *abstract_display) +{ + cairo_xlib_display_t *display = abstract_display; + + free (display); +} + +static int +_cairo_xlib_close_display (Display *dpy, XExtCodes *codes) +{ + cairo_xlib_display_t *display, **prev, *next; + + CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); + for (display = _cairo_xlib_display_list; display; display = display->next) + if (display->display == dpy) + break; + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + if (display == NULL) + return 0; + + cairo_device_finish (&display->base); + + /* + * Unhook from the global list + */ + CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); + prev = &_cairo_xlib_display_list; + for (display = _cairo_xlib_display_list; display; display = next) { + next = display->next; + if (display->display == dpy) { + *prev = next; + break; + } else + prev = &display->next; + } + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + + display->display = NULL; /* catch any later invalid access */ + cairo_device_destroy (&display->base); + + /* Return value in accordance with requirements of + * XESetCloseDisplay */ + return 0; +} + +static const cairo_device_backend_t _cairo_xlib_device_backend = { + CAIRO_DEVICE_TYPE_XLIB, + + NULL, + NULL, + + NULL, /* flush */ + _cairo_xlib_display_finish, + _cairo_xlib_display_destroy, +}; + +static void _cairo_xlib_display_select_compositor (cairo_xlib_display_t *display) +{ +#if 1 + if (display->render_major > 0 || display->render_minor >= 4) + display->compositor = _cairo_xlib_traps_compositor_get (); + else if (display->render_major > 0 || display->render_minor >= 0) + display->compositor = _cairo_xlib_mask_compositor_get (); + else + display->compositor = _cairo_xlib_core_compositor_get (); +#else + display->compositor = _cairo_xlib_fallback_compositor_get (); +#endif +} + +/** + * _cairo_xlib_device_create: + * @dpy: the display to create the device for + * + * Gets the device belonging to @dpy, or creates it if it doesn't exist yet. + * + * Returns: the device belonging to @dpy + **/ +cairo_device_t * +_cairo_xlib_device_create (Display *dpy) +{ + cairo_xlib_display_t *display; + cairo_xlib_display_t **prev; + cairo_device_t *device; + XExtCodes *codes; + const char *env; + + CAIRO_MUTEX_INITIALIZE (); + + /* There is an apparent deadlock between this mutex and the + * mutex for the display, but it's actually safe. For the + * app to call XCloseDisplay() while any other thread is + * inside this function would be an error in the logic + * app, and the CloseDisplay hook is the only other place we + * acquire this mutex. + */ + CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); + + for (prev = &_cairo_xlib_display_list; (display = *prev); prev = &(*prev)->next) + { + if (display->display == dpy) { + /* + * MRU the list + */ + if (prev != &_cairo_xlib_display_list) { + *prev = display->next; + display->next = _cairo_xlib_display_list; + _cairo_xlib_display_list = display; + } + device = cairo_device_reference (&display->base); + goto UNLOCK; + } + } + + display = malloc (sizeof (cairo_xlib_display_t)); + if (unlikely (display == NULL)) { + device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); + goto UNLOCK; + } + + _cairo_device_init (&display->base, &_cairo_xlib_device_backend); + + display->display = dpy; + cairo_list_init (&display->screens); + cairo_list_init (&display->fonts); + display->closed = FALSE; + + /* Xlib calls out to the extension close_display hooks in LIFO + * order. So we have to ensure that all extensions that we depend + * on in our close_display hook are properly initialized before we + * add our hook. For now, that means Render, so we call into its + * QueryVersion function to ensure it gets initialized. + */ + display->render_major = display->render_minor = -1; + XRenderQueryVersion (dpy, &display->render_major, &display->render_minor); + env = getenv ("CAIRO_DEBUG"); + if (env != NULL && (env = strstr (env, "xrender-version=")) != NULL) { + int max_render_major, max_render_minor; + + env += sizeof ("xrender-version=") - 1; + if (sscanf (env, "%d.%d", &max_render_major, &max_render_minor) != 2) + max_render_major = max_render_minor = -1; + + if (max_render_major < display->render_major || + (max_render_major == display->render_major && + max_render_minor < display->render_minor)) + { + display->render_major = max_render_major; + display->render_minor = max_render_minor; + } + } + + _cairo_xlib_display_select_compositor (display); + + display->white = NULL; + memset (display->alpha, 0, sizeof (display->alpha)); + memset (display->solid, 0, sizeof (display->solid)); + memset (display->solid_cache, 0, sizeof (display->solid_cache)); + memset (display->last_solid_cache, 0, sizeof (display->last_solid_cache)); + + memset (display->cached_xrender_formats, 0, + sizeof (display->cached_xrender_formats)); + + display->force_precision = -1; + + _cairo_xlib_display_init_shm (display); + + /* Prior to Render 0.10, there is no protocol support for gradients and + * we call function stubs instead, which would silently consume the drawing. + */ +#if RENDER_MAJOR == 0 && RENDER_MINOR < 10 + display->buggy_gradients = TRUE; +#else + display->buggy_gradients = FALSE; +#endif + display->buggy_pad_reflect = FALSE; + display->buggy_repeat = FALSE; + + /* This buggy_repeat condition is very complicated because there + * are multiple X server code bases (with multiple versioning + * schemes within a code base), and multiple bugs. + * + * The X servers: + * + * 1. The Vendor=="XFree86" code base with release numbers such + * as 4.7.0 (VendorRelease==40700000). + * + * 2. The Vendor=="X.Org" code base (a descendant of the + * XFree86 code base). It originally had things like + * VendorRelease==60700000 for release 6.7.0 but then changed + * its versioning scheme so that, for example, + * VendorRelease==10400000 for the 1.4.0 X server within the + * X.Org 7.3 release. + * + * The bugs: + * + * 1. The original bug that led to the buggy_repeat + * workaround. This was a bug that Owen Taylor investigated, + * understood well, and characterized against various X + * servers. Confirmed X servers with this bug include: + * + * "XFree86" <= 40500000 + * "X.Org" <= 60802000 (only with old numbering >= 60700000) + * + * 2. A separate bug resulting in a crash of the X server when + * using cairo's extend-reflect test case, (which, surprisingly + * enough was not passing RepeatReflect to the X server, but + * instead using RepeatNormal in a workaround). Nobody to date + * has understood the bug well, but it appears to be gone as of + * the X.Org 1.4.0 server. This bug is coincidentally avoided + * by using the same buggy_repeat workaround. Confirmed X + * servers with this bug include: + * + * "X.org" == 60900000 (old versioning scheme) + * "X.org" < 10400000 (new numbering scheme) + * + * For the old-versioning-scheme X servers we don't know + * exactly when second the bug started, but since bug 1 is + * present through 6.8.2 and bug 2 is present in 6.9.0 it seems + * safest to just blacklist all old-versioning-scheme X servers, + * (just using VendorRelease < 70000000), as buggy_repeat=TRUE. + */ + if (_cairo_xlib_vendor_is_xorg (dpy)) { + if (VendorRelease (dpy) >= 60700000) { + if (VendorRelease (dpy) < 70000000) + display->buggy_repeat = TRUE; + + /* We know that gradients simply do not work in early Xorg servers */ + if (VendorRelease (dpy) < 70200000) + display->buggy_gradients = TRUE; + + /* And the extended repeat modes were not fixed until much later */ + display->buggy_pad_reflect = TRUE; + } else { + if (VendorRelease (dpy) < 10400000) + display->buggy_repeat = TRUE; + + /* Too many bugs in the early drivers */ + if (VendorRelease (dpy) < 10699000) + display->buggy_pad_reflect = TRUE; + } + } else if (strstr (ServerVendor (dpy), "XFree86") != NULL) { + if (VendorRelease (dpy) <= 40500000) + display->buggy_repeat = TRUE; + + display->buggy_gradients = TRUE; + display->buggy_pad_reflect = TRUE; + } + + codes = XAddExtension (dpy); + if (unlikely (codes == NULL)) { + device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); + free (display); + goto UNLOCK; + } + + XESetCloseDisplay (dpy, codes->extension, _cairo_xlib_close_display); + cairo_device_reference (&display->base); /* add one for the CloseDisplay */ + + display->next = _cairo_xlib_display_list; + _cairo_xlib_display_list = display; + + device = &display->base; + +UNLOCK: + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + return device; +} + +cairo_status_t +_cairo_xlib_display_acquire (cairo_device_t *device, cairo_xlib_display_t **display) +{ + cairo_status_t status; + + status = cairo_device_acquire (device); + if (status) + return status; + + *display = (cairo_xlib_display_t *) device; + return CAIRO_STATUS_SUCCESS; +} + +XRenderPictFormat * +_cairo_xlib_display_get_xrender_format_for_pixman(cairo_xlib_display_t *display, + pixman_format_code_t format) +{ + Display *dpy = display->display; + XRenderPictFormat tmpl; + int mask; + +#define MASK(x) ((1<<(x))-1) + + tmpl.depth = PIXMAN_FORMAT_DEPTH(format); + mask = PictFormatType | PictFormatDepth; + + switch (PIXMAN_FORMAT_TYPE(format)) { + case PIXMAN_TYPE_ARGB: + tmpl.type = PictTypeDirect; + + tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); + if (PIXMAN_FORMAT_A(format)) + tmpl.direct.alpha = (PIXMAN_FORMAT_R(format) + + PIXMAN_FORMAT_G(format) + + PIXMAN_FORMAT_B(format)); + + tmpl.direct.redMask = MASK(PIXMAN_FORMAT_R(format)); + tmpl.direct.red = (PIXMAN_FORMAT_G(format) + + PIXMAN_FORMAT_B(format)); + + tmpl.direct.greenMask = MASK(PIXMAN_FORMAT_G(format)); + tmpl.direct.green = PIXMAN_FORMAT_B(format); + + tmpl.direct.blueMask = MASK(PIXMAN_FORMAT_B(format)); + tmpl.direct.blue = 0; + + mask |= PictFormatRed | PictFormatRedMask; + mask |= PictFormatGreen | PictFormatGreenMask; + mask |= PictFormatBlue | PictFormatBlueMask; + mask |= PictFormatAlpha | PictFormatAlphaMask; + break; + + case PIXMAN_TYPE_ABGR: + tmpl.type = PictTypeDirect; + + tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); + if (tmpl.direct.alphaMask) + tmpl.direct.alpha = (PIXMAN_FORMAT_B(format) + + PIXMAN_FORMAT_G(format) + + PIXMAN_FORMAT_R(format)); + + tmpl.direct.blueMask = MASK(PIXMAN_FORMAT_B(format)); + tmpl.direct.blue = (PIXMAN_FORMAT_G(format) + + PIXMAN_FORMAT_R(format)); + + tmpl.direct.greenMask = MASK(PIXMAN_FORMAT_G(format)); + tmpl.direct.green = PIXMAN_FORMAT_R(format); + + tmpl.direct.redMask = MASK(PIXMAN_FORMAT_R(format)); + tmpl.direct.red = 0; + + mask |= PictFormatRed | PictFormatRedMask; + mask |= PictFormatGreen | PictFormatGreenMask; + mask |= PictFormatBlue | PictFormatBlueMask; + mask |= PictFormatAlpha | PictFormatAlphaMask; + break; + + case PIXMAN_TYPE_BGRA: + tmpl.type = PictTypeDirect; + + tmpl.direct.blueMask = MASK(PIXMAN_FORMAT_B(format)); + tmpl.direct.blue = (PIXMAN_FORMAT_BPP(format) - PIXMAN_FORMAT_B(format)); + + tmpl.direct.greenMask = MASK(PIXMAN_FORMAT_G(format)); + tmpl.direct.green = (PIXMAN_FORMAT_BPP(format) - PIXMAN_FORMAT_B(format) - + PIXMAN_FORMAT_G(format)); + + tmpl.direct.redMask = MASK(PIXMAN_FORMAT_R(format)); + tmpl.direct.red = (PIXMAN_FORMAT_BPP(format) - PIXMAN_FORMAT_B(format) - + PIXMAN_FORMAT_G(format) - PIXMAN_FORMAT_R(format)); + + tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); + tmpl.direct.alpha = 0; + + mask |= PictFormatRed | PictFormatRedMask; + mask |= PictFormatGreen | PictFormatGreenMask; + mask |= PictFormatBlue | PictFormatBlueMask; + mask |= PictFormatAlpha | PictFormatAlphaMask; + break; + + case PIXMAN_TYPE_A: + tmpl.type = PictTypeDirect; + + tmpl.direct.alpha = 0; + tmpl.direct.alphaMask = MASK(PIXMAN_FORMAT_A(format)); + + mask |= PictFormatAlpha | PictFormatAlphaMask; + break; + + case PIXMAN_TYPE_COLOR: + case PIXMAN_TYPE_GRAY: + /* XXX Find matching visual/colormap */ + tmpl.type = PictTypeIndexed; + //tmpl.colormap = screen->visuals[PIXMAN_FORMAT_VIS(format)].vid; + //mask |= PictFormatColormap; + return NULL; + } +#undef MASK + + /* XXX caching? */ + return XRenderFindFormat(dpy, mask, &tmpl, 0); +} + +XRenderPictFormat * +_cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display, + cairo_format_t format) +{ + XRenderPictFormat *xrender_format; + + xrender_format = display->cached_xrender_formats[format]; + if (xrender_format == NULL) { + int pict_format = PictStandardNUM; + + switch (format) { + case CAIRO_FORMAT_A1: + pict_format = PictStandardA1; break; + case CAIRO_FORMAT_A8: + pict_format = PictStandardA8; break; + case CAIRO_FORMAT_RGB24: + pict_format = PictStandardRGB24; break; + case CAIRO_FORMAT_RGB16_565: + xrender_format = _cairo_xlib_display_get_xrender_format_for_pixman(display, + PIXMAN_r5g6b5); + break; + case CAIRO_FORMAT_RGB30: + xrender_format = _cairo_xlib_display_get_xrender_format_for_pixman(display, + PIXMAN_x2r10g10b10); + break; + case CAIRO_FORMAT_INVALID: + default: + ASSERT_NOT_REACHED; + case CAIRO_FORMAT_ARGB32: + pict_format = PictStandardARGB32; break; + } + if (pict_format != PictStandardNUM) + xrender_format = + XRenderFindStandardFormat (display->display, pict_format); + display->cached_xrender_formats[format] = xrender_format; + } + + return xrender_format; +} + +cairo_xlib_screen_t * +_cairo_xlib_display_get_screen (cairo_xlib_display_t *display, + Screen *screen) +{ + cairo_xlib_screen_t *info; + + cairo_list_foreach_entry (info, cairo_xlib_screen_t, &display->screens, link) { + if (info->screen == screen) { + if (display->screens.next != &info->link) + cairo_list_move (&info->link, &display->screens); + return info; + } + } + + return NULL; +} + +cairo_bool_t +_cairo_xlib_display_has_repeat (cairo_device_t *device) +{ + return ! ((cairo_xlib_display_t *) device)->buggy_repeat; +} + +cairo_bool_t +_cairo_xlib_display_has_reflect (cairo_device_t *device) +{ + return ! ((cairo_xlib_display_t *) device)->buggy_pad_reflect; +} + +cairo_bool_t +_cairo_xlib_display_has_gradients (cairo_device_t *device) +{ + return ! ((cairo_xlib_display_t *) device)->buggy_gradients; +} + +/** + * cairo_xlib_device_debug_cap_xrender_version: + * @device: a #cairo_device_t for the Xlib backend + * @major_version: major version to restrict to + * @minor_version: minor version to restrict to + * + * Restricts all future Xlib surfaces for this devices to the specified version + * of the RENDER extension. This function exists solely for debugging purpose. + * It lets you find out how cairo would behave with an older version of + * the RENDER extension. + * + * Use the special values -1 and -1 for disabling the RENDER extension. + * + * Since: 1.12 + **/ +void +cairo_xlib_device_debug_cap_xrender_version (cairo_device_t *device, + int major_version, + int minor_version) +{ + cairo_xlib_display_t *display = (cairo_xlib_display_t *) device; + + if (device == NULL || device->status) + return; + + if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) + return; + + if (major_version < display->render_major || + (major_version == display->render_major && + minor_version < display->render_minor)) + { + display->render_major = major_version; + display->render_minor = minor_version; + } + + _cairo_xlib_display_select_compositor (display); +} + +/** + * cairo_xlib_device_debug_set_precision: + * @device: a #cairo_device_t for the Xlib backend + * @precision: the precision to use + * + * Render supports two modes of precision when rendering trapezoids. Set + * the precision to the desired mode. + * + * Since: 1.12 + **/ +void +cairo_xlib_device_debug_set_precision (cairo_device_t *device, + int precision) +{ + if (device == NULL || device->status) + return; + if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return; + } + + ((cairo_xlib_display_t *) device)->force_precision = precision; +} + +/** + * cairo_xlib_device_debug_get_precision: + * @device: a #cairo_device_t for the Xlib backend + * + * Get the Xrender precision mode. + * + * Returns: the render precision mode + * + * Since: 1.12 + **/ +int +cairo_xlib_device_debug_get_precision (cairo_device_t *device) +{ + if (device == NULL || device->status) + return -1; + if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return -1; + } + + return ((cairo_xlib_display_t *) device)->force_precision; +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-fallback-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-fallback-compositor.c new file mode 100644 index 00000000000..ed2845db57d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-fallback-compositor.c @@ -0,0 +1,248 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Behdad Esfahbod + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-offset-private.h" + +static const cairo_compositor_t * +_get_compositor (cairo_surface_t *surface) +{ + return ((cairo_image_surface_t *)surface)->compositor; +} + +static cairo_bool_t +unclipped (cairo_xlib_surface_t *xlib, cairo_clip_t *clip) +{ + cairo_rectangle_int_t r; + + r.x = r.y = 0; + r.width = xlib->width; + r.height = xlib->height; + return _cairo_clip_contains_rectangle (clip, &r); +} + +static cairo_int_status_t +_cairo_xlib_shm_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; + cairo_int_status_t status; + cairo_surface_t *shm; + cairo_bool_t overwrite; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + overwrite = + extents->op <= CAIRO_OPERATOR_SOURCE && unclipped (xlib, extents->clip); + + shm = _cairo_xlib_surface_get_shm (xlib, overwrite); + if (shm == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_paint (_get_compositor (shm), shm, + extents->op, + &extents->source_pattern.base, + extents->clip); + if (unlikely (status)) + return status; + + xlib->base.is_clear = + extents->op == CAIRO_OPERATOR_CLEAR && unclipped (xlib, extents->clip); + xlib->base.serial++; + xlib->fallback++; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_xlib_shm_compositor_mask (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; + cairo_int_status_t status; + cairo_surface_t *shm; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + shm = _cairo_xlib_surface_get_shm (xlib, FALSE); + if (shm == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_mask (_get_compositor (shm), shm, + extents->op, + &extents->source_pattern.base, + &extents->mask_pattern.base, + extents->clip); + if (unlikely (status)) + return status; + + xlib->base.is_clear = FALSE; + xlib->base.serial++; + xlib->fallback++; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_xlib_shm_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; + cairo_int_status_t status; + cairo_surface_t *shm; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + shm = _cairo_xlib_surface_get_shm (xlib, FALSE); + if (shm == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_stroke (_get_compositor (shm), shm, + extents->op, + &extents->source_pattern.base, + path, style, + ctm, ctm_inverse, + tolerance, + antialias, + extents->clip); + if (unlikely (status)) + return status; + + xlib->base.is_clear = FALSE; + xlib->base.serial++; + xlib->fallback++; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_xlib_shm_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; + cairo_int_status_t status; + cairo_surface_t *shm; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + shm = _cairo_xlib_surface_get_shm (xlib, FALSE); + if (shm == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_fill (_get_compositor (shm), shm, + extents->op, + &extents->source_pattern.base, + path, + fill_rule, tolerance, antialias, + extents->clip); + if (unlikely (status)) + return status; + + xlib->base.is_clear = FALSE; + xlib->base.serial++; + xlib->fallback++; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static cairo_int_status_t +_cairo_xlib_shm_compositor_glyphs (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface; + cairo_int_status_t status; + cairo_surface_t *shm; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + shm = _cairo_xlib_surface_get_shm (xlib, FALSE); + if (shm == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = _cairo_compositor_glyphs (_get_compositor (shm), shm, + extents->op, + &extents->source_pattern.base, + glyphs, num_glyphs, scaled_font, + extents->clip); + if (unlikely (status)) + return status; + + xlib->base.is_clear = FALSE; + xlib->base.serial++; + xlib->fallback++; + return CAIRO_INT_STATUS_NOTHING_TO_DO; +} + +static const cairo_compositor_t _cairo_xlib_shm_compositor = { + &_cairo_fallback_compositor, + + _cairo_xlib_shm_compositor_paint, + _cairo_xlib_shm_compositor_mask, + _cairo_xlib_shm_compositor_stroke, + _cairo_xlib_shm_compositor_fill, + _cairo_xlib_shm_compositor_glyphs, +}; + +const cairo_compositor_t * +_cairo_xlib_fallback_compositor_get (void) +{ + return &_cairo_xlib_shm_compositor; +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-private.h new file mode 100644 index 00000000000..0f2f2e1faa0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-private.h @@ -0,0 +1,470 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributors(s): + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ + +#ifndef CAIRO_XLIB_PRIVATE_H +#define CAIRO_XLIB_PRIVATE_H + +#include "cairo-xlib-xrender-private.h" +#include "cairo-xlib.h" + +#include "cairo-compiler-private.h" +#include "cairo-device-private.h" +#include "cairo-freelist-type-private.h" +#include "cairo-list-private.h" +#include "cairo-reference-count-private.h" +#include "cairo-types-private.h" +#include "cairo-scaled-font-private.h" +#include "cairo-surface-private.h" + +#include +#include + +typedef struct _cairo_xlib_display cairo_xlib_display_t; +typedef struct _cairo_xlib_shm_display cairo_xlib_shm_display_t; +typedef struct _cairo_xlib_screen cairo_xlib_screen_t; +typedef struct _cairo_xlib_source cairo_xlib_source_t; +typedef struct _cairo_xlib_proxy cairo_xlib_proxy_t; +typedef struct _cairo_xlib_surface cairo_xlib_surface_t; + +/* size of color cube */ +#define CUBE_SIZE 6 +/* size of gray ramp */ +#define RAMP_SIZE 16 +/* maximum number of cached GC's */ +#define GC_CACHE_SIZE 4 + +struct _cairo_xlib_display { + cairo_device_t base; + + cairo_xlib_display_t *next; + + Display *display; + cairo_list_t screens; + cairo_list_t fonts; + + cairo_xlib_shm_display_t *shm; + + const cairo_compositor_t *compositor; + + int render_major; + int render_minor; + XRenderPictFormat *cached_xrender_formats[CAIRO_FORMAT_RGB30 + 1]; + + int force_precision; + + cairo_surface_t *white; + cairo_surface_t *alpha[256]; + cairo_surface_t *solid[32]; + uint32_t solid_cache[32]; /* low 16 are opaque, high 16 transparent */ + struct { + uint32_t color; + int index; + } last_solid_cache[2]; + + /* TRUE if the server has a bug with repeating pictures + * + * https://bugs.freedesktop.org/show_bug.cgi?id=3566 + * + * We can't test for this because it depends on whether the + * picture is in video memory or not. + * + * We also use this variable as a guard against a second + * independent bug with transformed repeating pictures: + * + * http://lists.freedesktop.org/archives/cairo/2004-September/001839.html + * + * Both are fixed in xorg >= 6.9 and hopefully in > 6.8.2, so + * we can reuse the test for now. + */ + unsigned int buggy_gradients : 1; + unsigned int buggy_pad_reflect : 1; + unsigned int buggy_repeat : 1; + unsigned int closed :1; +}; + +typedef struct _cairo_xlib_visual_info { + cairo_list_t link; + VisualID visualid; + struct { uint8_t a, r, g, b; } colors[256]; + uint8_t cube_to_pseudocolor[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE]; + uint8_t field8_to_cube[256]; + int8_t dither8_to_cube[256]; + uint8_t gray8_to_pseudocolor[256]; +} cairo_xlib_visual_info_t; + +struct _cairo_xlib_screen { + cairo_list_t link; + + cairo_device_t *device; + Screen *screen; + + cairo_list_t surfaces; + + cairo_bool_t has_font_options; + cairo_font_options_t font_options; + + GC gc[GC_CACHE_SIZE]; + uint8_t gc_depths[GC_CACHE_SIZE]; + + cairo_list_t visuals; +}; + +enum { + GLYPHSET_INDEX_ARGB32, + GLYPHSET_INDEX_A8, + GLYPHSET_INDEX_A1, + NUM_GLYPHSETS +}; + +typedef struct _cairo_xlib_font_glyphset { + GlyphSet glyphset; + cairo_format_t format; + XRenderPictFormat *xrender_format; + struct _cairo_xlib_font_glyphset_free_glyphs { + int count; + unsigned long indices[128]; + } to_free; +} cairo_xlib_font_glyphset_t; + +typedef struct _cairo_xlib_font { + cairo_scaled_font_private_t base; + cairo_scaled_font_t *font; + cairo_device_t *device; + cairo_list_t link; + cairo_xlib_font_glyphset_t glyphset[NUM_GLYPHSETS]; +} cairo_xlib_font_t; + +struct _cairo_xlib_surface { + cairo_surface_t base; + + Picture picture; + Drawable drawable; + + const cairo_compositor_t *compositor; + cairo_surface_t *shm; + int fallback; + + cairo_xlib_display_t *display; + cairo_xlib_screen_t *screen; + cairo_list_t link; + + Display *dpy; /* only valid between acquire/release */ + cairo_bool_t owns_pixmap; + Visual *visual; + + int use_pixmap; + + int width; + int height; + int depth; + + int precision; + XRenderPictFormat *xrender_format; + /* XXX pixman_format instead of masks? */ + uint32_t a_mask; + uint32_t r_mask; + uint32_t g_mask; + uint32_t b_mask; + + struct _cairo_xlib_source { + cairo_surface_t base; + + Picture picture; + Pixmap pixmap; + Display *dpy; + + unsigned int filter:3; + unsigned int extend:3; + unsigned int has_matrix:1; + unsigned int has_component_alpha:1; + } embedded_source; +}; + +struct _cairo_xlib_proxy { + struct _cairo_xlib_source source; + cairo_surface_t *owner; +}; + +inline static cairo_bool_t +_cairo_xlib_vendor_is_xorg (Display *dpy) +{ + const char *const vendor = ServerVendor (dpy); + return strstr (vendor, "X.Org") || strstr (vendor, "Xorg"); +} + +cairo_private cairo_status_t +_cairo_xlib_surface_get_gc (cairo_xlib_display_t *display, + cairo_xlib_surface_t *surface, + GC *gc); + +cairo_private cairo_device_t * +_cairo_xlib_device_create (Display *display); + +cairo_private void +_cairo_xlib_display_init_shm (cairo_xlib_display_t *display); + +cairo_private void +_cairo_xlib_display_fini_shm (cairo_xlib_display_t *display); + +cairo_private cairo_xlib_screen_t * +_cairo_xlib_display_get_screen (cairo_xlib_display_t *display, + Screen *screen); + +cairo_private cairo_status_t +_cairo_xlib_display_acquire (cairo_device_t *device, + cairo_xlib_display_t **display); + +cairo_private cairo_bool_t +_cairo_xlib_display_has_repeat (cairo_device_t *device); + +cairo_private cairo_bool_t +_cairo_xlib_display_has_reflect (cairo_device_t *device); + +cairo_private cairo_bool_t +_cairo_xlib_display_has_gradients (cairo_device_t *device); + +cairo_private void +_cairo_xlib_display_set_precision(cairo_device_t *device, + int precision); + +cairo_private XRenderPictFormat * +_cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display, + cairo_format_t format); + +cairo_private XRenderPictFormat * +_cairo_xlib_display_get_xrender_format_for_pixman (cairo_xlib_display_t *display, + pixman_format_code_t format); + +cairo_private cairo_status_t +_cairo_xlib_screen_get (Display *dpy, + Screen *screen, + cairo_xlib_screen_t **out); + +cairo_private void +_cairo_xlib_screen_destroy (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info); + +cairo_private GC +_cairo_xlib_screen_get_gc (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info, + int depth, + Drawable drawable); +cairo_private void +_cairo_xlib_screen_put_gc (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info, + int depth, + GC gc); + +cairo_private cairo_font_options_t * +_cairo_xlib_screen_get_font_options (cairo_xlib_screen_t *info); + +cairo_private cairo_status_t +_cairo_xlib_screen_get_visual_info (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info, + Visual *visual, + cairo_xlib_visual_info_t **out); + +cairo_private cairo_status_t +_cairo_xlib_visual_info_create (Display *dpy, + int screen, + VisualID visualid, + cairo_xlib_visual_info_t **out); + +cairo_private void +_cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info); + +cairo_private const cairo_compositor_t * +_cairo_xlib_core_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_xlib_fallback_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_xlib_mask_compositor_get (void); + +cairo_private const cairo_compositor_t * +_cairo_xlib_traps_compositor_get (void); + +cairo_private void +_cairo_xlib_surface_ensure_picture (cairo_xlib_surface_t *surface); + +cairo_private void +_cairo_xlib_surface_set_precision (cairo_xlib_surface_t *surface, + cairo_antialias_t antialias); + +cairo_private cairo_int_status_t +_cairo_xlib_surface_set_attributes (cairo_xlib_display_t *display, + cairo_xlib_surface_t *surface, + cairo_surface_attributes_t *attributes, + double xc, + double yc); + +cairo_private cairo_status_t +_cairo_xlib_surface_draw_image (cairo_xlib_surface_t *surface, + cairo_image_surface_t *image, + int src_x, + int src_y, + int width, + int height, + int dst_x, + int dst_y); + +cairo_private cairo_surface_t * +_cairo_xlib_source_create_for_pattern (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y); + +cairo_private void +_cairo_xlib_font_close (cairo_xlib_font_t *font); + +#define CAIRO_RENDER_AT_LEAST(surface, major, minor) \ + (((surface)->render_major > major) || \ + (((surface)->render_major == major) && ((surface)->render_minor >= minor))) + +#define CAIRO_RENDER_HAS_CREATE_PICTURE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0) +#define CAIRO_RENDER_HAS_COMPOSITE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0) +#define CAIRO_RENDER_HAS_COMPOSITE_TEXT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0) + +#define CAIRO_RENDER_HAS_FILL_RECTANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 1) + +#define CAIRO_RENDER_HAS_DISJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2) +#define CAIRO_RENDER_HAS_CONJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2) + +#define CAIRO_RENDER_HAS_TRAPEZOIDS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) +#define CAIRO_RENDER_HAS_TRIANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) +#define CAIRO_RENDER_HAS_TRISTRIP(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) +#define CAIRO_RENDER_HAS_TRIFAN(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4) + +#define CAIRO_RENDER_HAS_PICTURE_TRANSFORM(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6) +#define CAIRO_RENDER_HAS_FILTERS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6) +#define CAIRO_RENDER_HAS_FILTER_GOOD(surface) FALSE +#define CAIRO_RENDER_HAS_FILTER_BEST(surface) FALSE + +#define CAIRO_RENDER_HAS_EXTENDED_REPEAT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10) +#define CAIRO_RENDER_HAS_GRADIENTS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10) + +#define CAIRO_RENDER_HAS_PDF_OPERATORS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 11) + +#define CAIRO_RENDER_SUPPORTS_OPERATOR(surface, op) \ + ((op) <= CAIRO_OPERATOR_SATURATE || \ + (CAIRO_RENDER_HAS_PDF_OPERATORS(surface) && \ + (op) <= CAIRO_OPERATOR_HSL_LUMINOSITY)) + +/* + * Return whether two xlib surfaces share the same + * screen. Both core and Render drawing require this + * when using multiple drawables in an operation. + */ +static inline cairo_bool_t +_cairo_xlib_surface_same_screen (cairo_xlib_surface_t *dst, + cairo_xlib_surface_t *src) +{ + return dst->screen == src->screen; +} + +cairo_private cairo_int_status_t +_cairo_xlib_core_fill_boxes (cairo_xlib_surface_t *dst, + const cairo_color_t *color, + cairo_boxes_t *boxes); + +cairo_private cairo_int_status_t +_cairo_xlib_core_fill_rectangles (cairo_xlib_surface_t *dst, + const cairo_color_t *color, + int num_rects, + cairo_rectangle_int_t *rects); + +static inline void +_cairo_xlib_surface_put_gc (cairo_xlib_display_t *display, + cairo_xlib_surface_t *surface, + GC gc) +{ + _cairo_xlib_screen_put_gc (display, + surface->screen, + surface->depth, + gc); +} + +cairo_private cairo_surface_t * +_cairo_xlib_surface_create_similar_shm (void *surface, + cairo_format_t format, + int width, int height); + +cairo_private cairo_surface_t * +_cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface, + cairo_bool_t overwrite); + +cairo_private cairo_int_status_t +_cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface); + +cairo_private cairo_surface_t * +_cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other, + pixman_format_code_t format, + int width, int height); + +cairo_private cairo_surface_t * +_cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface, + pixman_format_code_t format, + int width, int height); + +cairo_private void +_cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface, + XImage *ximage); + +cairo_private void * +_cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface); + +cairo_private void +_cairo_xlib_shm_surface_mark_active (cairo_surface_t *shm); + +cairo_private cairo_bool_t +_cairo_xlib_shm_surface_is_active (cairo_surface_t *surface); + +cairo_private cairo_bool_t +_cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface); + +cairo_private Pixmap +_cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface); + +cairo_private XRenderPictFormat * +_cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface); + +cairo_private pixman_format_code_t +_pixman_format_for_xlib_surface (cairo_xlib_surface_t *surface); + +#endif /* CAIRO_XLIB_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-render-compositor.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-render-compositor.c new file mode 100644 index 00000000000..8a1ec7bd731 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-render-compositor.c @@ -0,0 +1,2005 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Behdad Esfahbod + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-damage-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-pattern-private.h" +#include "cairo-pixman-private.h" +#include "cairo-traps-private.h" +#include "cairo-tristrip-private.h" + +static cairo_int_status_t +check_composite (const cairo_composite_rectangles_t *extents) +{ + cairo_xlib_display_t *display = ((cairo_xlib_surface_t *)extents->surface)->display; + + if (! CAIRO_RENDER_SUPPORTS_OPERATOR (display, extents->op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +acquire (void *abstract_dst) +{ + cairo_xlib_surface_t *dst = abstract_dst; + cairo_int_status_t status; + + status = _cairo_xlib_display_acquire (dst->base.device, &dst->display); + if (unlikely (status)) + return status; + + dst->dpy = dst->display->display; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +release (void *abstract_dst) +{ + cairo_xlib_surface_t *dst = abstract_dst; + + cairo_device_release (&dst->display->base); + dst->dpy = NULL; + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +set_clip_region (void *_surface, + cairo_region_t *region) +{ + cairo_xlib_surface_t *surface = _surface; + + _cairo_xlib_surface_ensure_picture (surface); + + if (region != NULL) { + XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *rects = stack_rects; + int n_rects, i; + + n_rects = cairo_region_num_rectangles (region); + if (n_rects > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle)); + if (unlikely (rects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + for (i = 0; i < n_rects; i++) { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (region, i, &rect); + + rects[i].x = rect.x; + rects[i].y = rect.y; + rects[i].width = rect.width; + rects[i].height = rect.height; + } + XRenderSetPictureClipRectangles (surface->dpy, + surface->picture, + 0, 0, + rects, n_rects); + if (rects != stack_rects) + free (rects); + } else { + XRenderPictureAttributes pa; + pa.clip_mask = None; + XRenderChangePicture (surface->dpy, + surface->picture, + CPClipMask, &pa); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +copy_image_boxes (void *_dst, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy) +{ + cairo_xlib_surface_t *dst = _dst; + struct _cairo_boxes_chunk *chunk; + cairo_int_status_t status; + Pixmap src; + GC gc; + int i, j; + + assert (image->depth == dst->depth); + + status = acquire (dst); + if (unlikely (status)) + return status; + + status = _cairo_xlib_surface_get_gc (dst->display, dst, &gc); + if (unlikely (status)) { + release (dst); + return status; + } + + src = _cairo_xlib_shm_surface_get_pixmap (&image->base); + if (boxes->num_boxes == 1) { + int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); + int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); + int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); + int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); + + _cairo_xlib_shm_surface_mark_active (&image->base); + XCopyArea (dst->dpy, src, dst->drawable, gc, + x1 + dx, y1 + dy, + x2 - x1, y2 - y1, + x1, y1); + } else { + XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *rects = stack_rects; + + if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); + if (unlikely (rects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + j = 0; + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + + if (x2 > x1 && y2 > y1) { + rects[j].x = x1; + rects[j].y = y1; + rects[j].width = x2 - x1; + rects[j].height = y2 - y1; + j++; + } + } + } + + XSetClipRectangles (dst->dpy, gc, 0, 0, rects, j, Unsorted); + _cairo_xlib_shm_surface_mark_active (&image->base); + XCopyArea (dst->dpy, src, dst->drawable, gc, + 0, 0, image->width, image->height, -dx, -dy); + XSetClipMask (dst->dpy, gc, None); + + if (rects != stack_rects) + free (rects); + } + + _cairo_xlib_surface_put_gc (dst->display, dst, gc); + release (dst); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +boxes_cover_surface (cairo_boxes_t *boxes, + cairo_xlib_surface_t *surface) +{ + cairo_box_t *b; + + if (boxes->num_boxes != 1) + return FALSE; + + b = &boxes->chunks.base[0]; + + if (_cairo_fixed_integer_part (b->p1.x) > 0 || + _cairo_fixed_integer_part (b->p1.y) > 0) + return FALSE; + + if (_cairo_fixed_integer_part (b->p2.x) < surface->width || + _cairo_fixed_integer_part (b->p2.y) < surface->height) + return FALSE; + + return TRUE; +} + +static cairo_int_status_t +draw_image_boxes (void *_dst, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy) +{ + cairo_xlib_surface_t *dst = _dst; + struct _cairo_boxes_chunk *chunk; + cairo_image_surface_t *shm = NULL; + cairo_int_status_t status; + int i; + + if (image->base.device == dst->base.device) { + if (image->depth != dst->depth) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (_cairo_xlib_shm_surface_get_pixmap (&image->base)) + return copy_image_boxes (dst, image, boxes, dx, dy); + + goto draw_image_boxes; + } + + if (boxes_cover_surface (boxes, dst)) + shm = (cairo_image_surface_t *) _cairo_xlib_surface_get_shm (dst, TRUE); + if (shm) { + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + cairo_rectangle_int_t r; + + r.x = _cairo_fixed_integer_part (b->p1.x); + r.y = _cairo_fixed_integer_part (b->p1.y); + r.width = _cairo_fixed_integer_part (b->p2.x) - r.x; + r.height = _cairo_fixed_integer_part (b->p2.y) - r.y; + + if (shm->pixman_format != image->pixman_format || + ! pixman_blt ((uint32_t *)image->data, (uint32_t *)shm->data, + image->stride / sizeof (uint32_t), + shm->stride / sizeof (uint32_t), + PIXMAN_FORMAT_BPP (image->pixman_format), + PIXMAN_FORMAT_BPP (shm->pixman_format), + r.x + dx, r.y + dy, + r.x, r.y, + r.width, r.height)) + { + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, NULL, shm->pixman_image, + r.x + dx, r.y + dy, + 0, 0, + r.x, r.y, + r.width, r.height); + } + + shm->base.damage = + _cairo_damage_add_rectangle (shm->base.damage, &r); + } + } + dst->base.is_clear = FALSE; + dst->fallback++; + dst->base.serial++; + return CAIRO_INT_STATUS_NOTHING_TO_DO; + } + + if (image->depth == dst->depth && + ((cairo_xlib_display_t *)dst->display)->shm) { + cairo_box_t extents; + cairo_rectangle_int_t r; + + _cairo_boxes_extents (boxes, &extents); + _cairo_box_round_to_rectangle (&extents, &r); + + shm = (cairo_image_surface_t *) + _cairo_xlib_surface_create_shm (dst, image->pixman_format, + r.width, r.height); + if (shm) { + int tx = -r.x, ty = -r.y; + + assert (shm->pixman_format == image->pixman_format); + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + + r.x = _cairo_fixed_integer_part (b->p1.x); + r.y = _cairo_fixed_integer_part (b->p1.y); + r.width = _cairo_fixed_integer_part (b->p2.x) - r.x; + r.height = _cairo_fixed_integer_part (b->p2.y) - r.y; + + if (! pixman_blt ((uint32_t *)image->data, (uint32_t *)shm->data, + image->stride / sizeof (uint32_t), + shm->stride / sizeof (uint32_t), + PIXMAN_FORMAT_BPP (image->pixman_format), + PIXMAN_FORMAT_BPP (shm->pixman_format), + r.x + dx, r.y + dy, + r.x + tx, r.y + ty, + r.width, r.height)) + { + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, NULL, shm->pixman_image, + r.x + dx, r.y + dy, + 0, 0, + r.x + tx, r.y + ty, + r.width, r.height); + } + } + } + + dx = tx; + dy = ty; + image = shm; + + if (_cairo_xlib_shm_surface_get_pixmap (&image->base)) { + status = copy_image_boxes (dst, image, boxes, dx, dy); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) + goto out; + } + } + } + +draw_image_boxes: + status = CAIRO_STATUS_SUCCESS; + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + cairo_box_t *b = &chunk->base[i]; + int x1 = _cairo_fixed_integer_part (b->p1.x); + int y1 = _cairo_fixed_integer_part (b->p1.y); + int x2 = _cairo_fixed_integer_part (b->p2.x); + int y2 = _cairo_fixed_integer_part (b->p2.y); + if (_cairo_xlib_surface_draw_image (dst, image, + x1 + dx, y1 + dy, + x2 - x1, y2 - y1, + x1, y1)) { + status = CAIRO_INT_STATUS_UNSUPPORTED; + goto out; + } + } + } + +out: + cairo_surface_destroy (&shm->base); + return status; +} + +static cairo_int_status_t +copy_boxes (void *_dst, + cairo_surface_t *_src, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents, + int dx, int dy) +{ + cairo_xlib_surface_t *dst = _dst; + cairo_xlib_surface_t *src = (cairo_xlib_surface_t *)_src; + struct _cairo_boxes_chunk *chunk; + cairo_int_status_t status; + GC gc; + Drawable d; + int i, j; + + if (! _cairo_xlib_surface_same_screen (dst, src)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + if (dst->depth != src->depth) + return CAIRO_INT_STATUS_UNSUPPORTED; + + status = acquire (dst); + if (unlikely (status)) + return status; + + status = _cairo_xlib_surface_get_gc (dst->display, dst, &gc); + if (unlikely (status)) { + release (dst); + return status; + } + + if (src->fallback && src->shm->damage->dirty) { + assert (src != dst); + d = _cairo_xlib_shm_surface_get_pixmap (src->shm); + assert (d != 0); + } else { + if (! src->owns_pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = IncludeInferiors; + XChangeGC (dst->display->display, gc, GCSubwindowMode, &gcv); + } + d = src->drawable; + } + + if (boxes->num_boxes == 1) { + int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); + int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); + int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); + int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); + + XCopyArea (dst->dpy, d, dst->drawable, gc, + x1 + dx, y1 + dy, + x2 - x1, y2 - y1, + x1, y1); + } else { + /* We can only have a single control for subwindow_mode on the + * GC. If we have a Window destination, we need to set ClipByChildren, + * but if we have a Window source, we need IncludeInferiors. If we have + * both a Window destination and source, we must fallback. There is + * no convenient way to detect if a drawable is a Pixmap or Window, + * therefore we can only rely on those surfaces that we created + * ourselves to be Pixmaps, and treat everything else as a potential + * Window. + */ + if (src == dst || (!src->owns_pixmap && !dst->owns_pixmap)) { + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + XCopyArea (dst->dpy, d, dst->drawable, gc, + x1 + dx, y1 + dy, + x2 - x1, y2 - y1, + x1, y1); + } + } + } else { + XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *rects = stack_rects; + + if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); + if (unlikely (rects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + j = 0; + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + + rects[j].x = x1; + rects[j].y = y1; + rects[j].width = x2 - x1; + rects[j].height = y2 - y1; + j++; + } + } + assert (j == boxes->num_boxes); + + XSetClipRectangles (dst->dpy, gc, 0, 0, rects, j, Unsorted); + + XCopyArea (dst->dpy, d, dst->drawable, gc, + extents->x + dx, extents->y + dy, + extents->width, extents->height, + extents->x, extents->y); + + XSetClipMask (dst->dpy, gc, None); + + if (rects != stack_rects) + free (rects); + } + } + + if (src->fallback && src->shm->damage->dirty) { + _cairo_xlib_shm_surface_mark_active (src->shm); + } else if (! src->owns_pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = ClipByChildren; + XChangeGC (dst->display->display, gc, GCSubwindowMode, &gcv); + } + + _cairo_xlib_surface_put_gc (dst->display, dst, gc); + release (dst); + return CAIRO_STATUS_SUCCESS; +} + +static int +_render_operator (cairo_operator_t op) +{ + switch (op) { + case CAIRO_OPERATOR_CLEAR: + return PictOpClear; + + case CAIRO_OPERATOR_SOURCE: + return PictOpSrc; + case CAIRO_OPERATOR_OVER: + return PictOpOver; + case CAIRO_OPERATOR_IN: + return PictOpIn; + case CAIRO_OPERATOR_OUT: + return PictOpOut; + case CAIRO_OPERATOR_ATOP: + return PictOpAtop; + + case CAIRO_OPERATOR_DEST: + return PictOpDst; + case CAIRO_OPERATOR_DEST_OVER: + return PictOpOverReverse; + case CAIRO_OPERATOR_DEST_IN: + return PictOpInReverse; + case CAIRO_OPERATOR_DEST_OUT: + return PictOpOutReverse; + case CAIRO_OPERATOR_DEST_ATOP: + return PictOpAtopReverse; + + case CAIRO_OPERATOR_XOR: + return PictOpXor; + case CAIRO_OPERATOR_ADD: + return PictOpAdd; + case CAIRO_OPERATOR_SATURATE: + return PictOpSaturate; + + case CAIRO_OPERATOR_MULTIPLY: + return PictOpMultiply; + case CAIRO_OPERATOR_SCREEN: + return PictOpScreen; + case CAIRO_OPERATOR_OVERLAY: + return PictOpOverlay; + case CAIRO_OPERATOR_DARKEN: + return PictOpDarken; + case CAIRO_OPERATOR_LIGHTEN: + return PictOpLighten; + case CAIRO_OPERATOR_COLOR_DODGE: + return PictOpColorDodge; + case CAIRO_OPERATOR_COLOR_BURN: + return PictOpColorBurn; + case CAIRO_OPERATOR_HARD_LIGHT: + return PictOpHardLight; + case CAIRO_OPERATOR_SOFT_LIGHT: + return PictOpSoftLight; + case CAIRO_OPERATOR_DIFFERENCE: + return PictOpDifference; + case CAIRO_OPERATOR_EXCLUSION: + return PictOpExclusion; + case CAIRO_OPERATOR_HSL_HUE: + return PictOpHSLHue; + case CAIRO_OPERATOR_HSL_SATURATION: + return PictOpHSLSaturation; + case CAIRO_OPERATOR_HSL_COLOR: + return PictOpHSLColor; + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return PictOpHSLLuminosity; + + default: + ASSERT_NOT_REACHED; + return PictOpOver; + } +} + +static cairo_bool_t +fill_reduces_to_source (cairo_operator_t op, + const cairo_color_t *color, + cairo_xlib_surface_t *dst) +{ + if (dst->base.is_clear || CAIRO_COLOR_IS_OPAQUE (color)) { + if (op == CAIRO_OPERATOR_OVER) + return TRUE; + if (op == CAIRO_OPERATOR_ADD) + return (dst->base.content & CAIRO_CONTENT_COLOR) == 0; + } + + return FALSE; +} + +static cairo_int_status_t +fill_rectangles (void *abstract_surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_rectangle_int_t *rects, + int num_rects) +{ + cairo_xlib_surface_t *dst = abstract_surface; + XRenderColor render_color; + int i; + + //X_DEBUG ((display->display, "fill_rectangles (dst=%x)", (unsigned int) surface->drawable)); + + if (fill_reduces_to_source (op, color, dst)) + op = CAIRO_OPERATOR_SOURCE; + + if (!CAIRO_RENDER_HAS_FILL_RECTANGLES(dst->display)) { + cairo_int_status_t status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (op == CAIRO_OPERATOR_SOURCE) + status = _cairo_xlib_core_fill_rectangles (dst, color, num_rects, rects); + return status; + } + + render_color.red = color->red_short; + render_color.green = color->green_short; + render_color.blue = color->blue_short; + render_color.alpha = color->alpha_short; + + _cairo_xlib_surface_ensure_picture (dst); + if (num_rects == 1) { + /* Take advantage of the protocol compaction that libXrender performs + * to amalgamate sequences of XRenderFillRectangle(). + */ + XRenderFillRectangle (dst->dpy, + _render_operator (op), + dst->picture, + &render_color, + rects->x, rects->y, + rects->width, rects->height); + } else { + XRectangle stack_xrects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *xrects = stack_xrects; + + if (num_rects > ARRAY_LENGTH (stack_xrects)) { + xrects = _cairo_malloc_ab (num_rects, sizeof (XRectangle)); + if (unlikely (xrects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + for (i = 0; i < num_rects; i++) { + xrects[i].x = rects[i].x; + xrects[i].y = rects[i].y; + xrects[i].width = rects[i].width; + xrects[i].height = rects[i].height; + } + + XRenderFillRectangles (dst->dpy, + _render_operator (op), + dst->picture, + &render_color, xrects, num_rects); + + if (xrects != stack_xrects) + free (xrects); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +fill_boxes (void *abstract_surface, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + cairo_xlib_surface_t *dst = abstract_surface; + XRenderColor render_color; + + if (fill_reduces_to_source (op, color, dst)) + op = CAIRO_OPERATOR_SOURCE; + + if (!CAIRO_RENDER_HAS_FILL_RECTANGLES(dst->display)) { + cairo_int_status_t status; + + status = CAIRO_INT_STATUS_UNSUPPORTED; + if (op == CAIRO_OPERATOR_SOURCE) + status = _cairo_xlib_core_fill_boxes (dst, color, boxes); + return status; + } + + render_color.red = color->red_short; + render_color.green = color->green_short; + render_color.blue = color->blue_short; + render_color.alpha = color->alpha_short; + + _cairo_xlib_surface_ensure_picture (dst); + if (boxes->num_boxes == 1) { + int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); + int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); + int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); + int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); + + /* Take advantage of the protocol compaction that libXrender performs + * to amalgamate sequences of XRenderFillRectangle(). + */ + XRenderFillRectangle (dst->dpy, + _render_operator (op), + dst->picture, + &render_color, + x1, y1, + x2 - x1, y2 - y1); + } else { + XRectangle stack_xrects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *xrects = stack_xrects; + struct _cairo_boxes_chunk *chunk; + int i, j; + + if (boxes->num_boxes > ARRAY_LENGTH (stack_xrects)) { + xrects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); + if (unlikely (xrects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + j = 0; + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + + xrects[j].x = x1; + xrects[j].y = y1; + xrects[j].width = x2 - x1; + xrects[j].height = y2 - y1; + j++; + } + } + + XRenderFillRectangles (dst->dpy, + _render_operator (op), + dst->picture, + &render_color, xrects, j); + + if (xrects != stack_xrects) + free (xrects); + } + + return CAIRO_STATUS_SUCCESS; +} + +#if 0 +check_composite () + operation = _categorize_composite_operation (dst, op, src_pattern, + mask_pattern != NULL); + if (operation == DO_UNSUPPORTED) + return UNSUPPORTED ("unsupported operation"); + + //X_DEBUG ((display->display, "composite (dst=%x)", (unsigned int) dst->drawable)); + + operation = _recategorize_composite_operation (dst, op, src, &src_attr, + mask_pattern != NULL); + if (operation == DO_UNSUPPORTED) { + status = UNSUPPORTED ("unsupported operation"); + goto BAIL; + } +#endif + +static cairo_int_status_t +composite (void *abstract_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + cairo_xlib_surface_t *dst = abstract_dst; + cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; + + op = _render_operator (op); + + _cairo_xlib_surface_ensure_picture (dst); + if (abstract_mask) { + cairo_xlib_source_t *mask = (cairo_xlib_source_t *)abstract_mask; + + XRenderComposite (dst->dpy, op, + src->picture, mask->picture, dst->picture, + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height); + } else { + XRenderComposite (dst->dpy, op, + src->picture, 0, dst->picture, + src_x, src_y, + 0, 0, + dst_x, dst_y, + width, height); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +lerp (void *abstract_dst, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + cairo_xlib_surface_t *dst = abstract_dst; + cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; + cairo_xlib_source_t *mask = (cairo_xlib_source_t *)abstract_mask; + + _cairo_xlib_surface_ensure_picture (dst); + XRenderComposite (dst->dpy, PictOpOutReverse, + mask->picture, None, dst->picture, + mask_x, mask_y, + 0, 0, + dst_x, dst_y, + width, height); + XRenderComposite (dst->dpy, PictOpAdd, + src->picture, mask->picture, dst->picture, + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_boxes (void *abstract_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents) +{ + cairo_xlib_surface_t *dst = abstract_dst; + Picture src = ((cairo_xlib_source_t *)abstract_src)->picture; + Picture mask = abstract_mask ? ((cairo_xlib_source_t *)abstract_mask)->picture : 0; + XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *rects = stack_rects; + struct _cairo_boxes_chunk *chunk; + int i, j; + + op = _render_operator (op); + _cairo_xlib_surface_ensure_picture (dst); + if (boxes->num_boxes == 1) { + int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x); + int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y); + int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x); + int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y); + + XRenderComposite (dst->dpy, op, + src, mask, dst->picture, + x1 + src_x, y1 + src_y, + x1 + mask_x, y1 + mask_y, + x1 - dst_x, y1 - dst_y, + x2 - x1, y2 - y1); + return CAIRO_STATUS_SUCCESS; + } + + if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle)); + if (unlikely (rects == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + j = 0; + for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { + for (i = 0; i < chunk->count; i++) { + int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); + int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); + int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); + int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); + + rects[j].x = x1 - dst_x; + rects[j].y = y1 - dst_y; + rects[j].width = x2 - x1; + rects[j].height = y2 - y1; + j++; + } + } + assert (j == boxes->num_boxes); + + XRenderSetPictureClipRectangles (dst->dpy, + dst->picture, + 0, 0, + rects, j); + if (rects != stack_rects) + free (rects); + + XRenderComposite (dst->dpy, op, + src, mask, dst->picture, + extents->x + src_x, extents->y + src_y, + extents->x + mask_x, extents->y + mask_y, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + set_clip_region (dst, NULL); + + return CAIRO_STATUS_SUCCESS; +} + +/* font rendering */ + +void +_cairo_xlib_font_close (cairo_xlib_font_t *priv) +{ + cairo_xlib_display_t *display = (cairo_xlib_display_t *)priv->base.key; + int i; + + /* XXX All I really want is to do is zap my glyphs... */ + _cairo_scaled_font_reset_cache (priv->font); + + for (i = 0; i < NUM_GLYPHSETS; i++) { + cairo_xlib_font_glyphset_t *info; + + info = &priv->glyphset[i]; + if (info->glyphset) + XRenderFreeGlyphSet (display->display, info->glyphset); + } + + /* XXX locking */ + cairo_list_del (&priv->link); + cairo_list_del (&priv->base.link); + free (priv); +} + +static void +_cairo_xlib_font_fini (cairo_scaled_font_private_t *abstract_private, + cairo_scaled_font_t *font) +{ + cairo_xlib_font_t *priv = (cairo_xlib_font_t *) abstract_private; + cairo_status_t status; + cairo_xlib_display_t *display; + int i; + + cairo_list_del (&priv->base.link); + cairo_list_del (&priv->link); + + status = _cairo_xlib_display_acquire (priv->device, &display); + if (status) + goto BAIL; + + for (i = 0; i < NUM_GLYPHSETS; i++) { + cairo_xlib_font_glyphset_t *info; + + info = &priv->glyphset[i]; + if (info->glyphset) + XRenderFreeGlyphSet (display->display, info->glyphset); + } + + cairo_device_release (&display->base); +BAIL: + cairo_device_destroy (&display->base); + free (priv); +} + +static cairo_xlib_font_t * +_cairo_xlib_font_create (cairo_xlib_display_t *display, + cairo_scaled_font_t *font) +{ + cairo_xlib_font_t *priv; + int i; + + priv = malloc (sizeof (cairo_xlib_font_t)); + if (unlikely (priv == NULL)) + return NULL; + + _cairo_scaled_font_attach_private (font, &priv->base, display, + _cairo_xlib_font_fini); + + priv->device = cairo_device_reference (&display->base); + priv->font = font; + cairo_list_add (&priv->link, &display->fonts); + + for (i = 0; i < NUM_GLYPHSETS; i++) { + cairo_xlib_font_glyphset_t *info = &priv->glyphset[i]; + switch (i) { + case GLYPHSET_INDEX_ARGB32: info->format = CAIRO_FORMAT_ARGB32; break; + case GLYPHSET_INDEX_A8: info->format = CAIRO_FORMAT_A8; break; + case GLYPHSET_INDEX_A1: info->format = CAIRO_FORMAT_A1; break; + default: ASSERT_NOT_REACHED; break; + } + info->xrender_format = NULL; + info->glyphset = None; + info->to_free.count = 0; + } + + return priv; +} + +static int +_cairo_xlib_get_glyphset_index_for_format (cairo_format_t format) +{ + if (format == CAIRO_FORMAT_A8) + return GLYPHSET_INDEX_A8; + if (format == CAIRO_FORMAT_A1) + return GLYPHSET_INDEX_A1; + + assert (format == CAIRO_FORMAT_ARGB32); + return GLYPHSET_INDEX_ARGB32; +} + +static inline cairo_xlib_font_t * +_cairo_xlib_font_get (const cairo_xlib_display_t *display, + cairo_scaled_font_t *font) +{ + return (cairo_xlib_font_t *)_cairo_scaled_font_find_private (font, display); +} + +typedef struct { + cairo_scaled_glyph_private_t base; + + + cairo_xlib_font_glyphset_t *glyphset; +} cairo_xlib_glyph_private_t; + +static void +_cairo_xlib_glyph_fini (cairo_scaled_glyph_private_t *glyph_private, + cairo_scaled_glyph_t *glyph, + cairo_scaled_font_t *font) +{ + cairo_xlib_glyph_private_t *priv = (cairo_xlib_glyph_private_t *)glyph_private; + + if (! font->finished) { + cairo_xlib_font_t *font_private; + struct _cairo_xlib_font_glyphset_free_glyphs *to_free; + cairo_xlib_font_glyphset_t *info; + + font_private = _cairo_xlib_font_get (glyph_private->key, font); + assert (font_private); + + info = priv->glyphset; + to_free = &info->to_free; + if (to_free->count == ARRAY_LENGTH (to_free->indices)) { + cairo_xlib_display_t *display; + + if (_cairo_xlib_display_acquire (font_private->device, + &display) == CAIRO_STATUS_SUCCESS) { + XRenderFreeGlyphs (display->display, + info->glyphset, + to_free->indices, + to_free->count); + cairo_device_release (&display->base); + } + + to_free->count = 0; + } + + to_free->indices[to_free->count++] = + _cairo_scaled_glyph_index (glyph); + } + + cairo_list_del (&glyph_private->link); + free (glyph_private); +} + +static cairo_status_t +_cairo_xlib_glyph_attach (cairo_xlib_display_t *display, + cairo_scaled_glyph_t *glyph, + cairo_xlib_font_glyphset_t *info) +{ + cairo_xlib_glyph_private_t *priv; + + priv = malloc (sizeof (*priv)); + if (unlikely (priv == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_scaled_glyph_attach_private (glyph, &priv->base, display, + _cairo_xlib_glyph_fini); + priv->glyphset = info; + + glyph->dev_private = info; + glyph->dev_private_key = display; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_xlib_font_glyphset_t * +_cairo_xlib_font_get_glyphset_info_for_format (cairo_xlib_display_t *display, + cairo_scaled_font_t *font, + cairo_format_t format) +{ + cairo_xlib_font_t *priv; + cairo_xlib_font_glyphset_t *info; + int glyphset_index; + + glyphset_index = _cairo_xlib_get_glyphset_index_for_format (format); + + priv = _cairo_xlib_font_get (display, font); + if (priv == NULL) { + priv = _cairo_xlib_font_create (display, font); + if (priv == NULL) + return NULL; + } + + info = &priv->glyphset[glyphset_index]; + if (info->glyphset == None) { + info->xrender_format = + _cairo_xlib_display_get_xrender_format (display, info->format); + info->glyphset = XRenderCreateGlyphSet (display->display, + info->xrender_format); + } + + return info; +} + +static cairo_bool_t +has_pending_free_glyph (cairo_xlib_font_glyphset_t *info, + unsigned long glyph_index) +{ + struct _cairo_xlib_font_glyphset_free_glyphs *to_free; + int i; + + to_free = &info->to_free; + for (i = 0; i < to_free->count; i++) { + if (to_free->indices[i] == glyph_index) { + to_free->count--; + memmove (&to_free->indices[i], + &to_free->indices[i+1], + (to_free->count - i) * sizeof (to_free->indices[0])); + return TRUE; + } + } + + return FALSE; +} + +static cairo_xlib_font_glyphset_t * +find_pending_free_glyph (cairo_xlib_display_t *display, + cairo_scaled_font_t *font, + unsigned long glyph_index, + cairo_image_surface_t *surface) +{ + cairo_xlib_font_t *priv; + int i; + + priv = _cairo_xlib_font_get (display, font); + if (priv == NULL) + return NULL; + + if (surface != NULL) { + i = _cairo_xlib_get_glyphset_index_for_format (surface->format); + if (has_pending_free_glyph (&priv->glyphset[i], glyph_index)) + return &priv->glyphset[i]; + } else { + for (i = 0; i < NUM_GLYPHSETS; i++) { + if (has_pending_free_glyph (&priv->glyphset[i], glyph_index)) + return &priv->glyphset[i]; + } + } + + return NULL; +} + +static cairo_status_t +_cairo_xlib_surface_add_glyph (cairo_xlib_display_t *display, + cairo_scaled_font_t *font, + cairo_scaled_glyph_t **pscaled_glyph) +{ + XGlyphInfo glyph_info; + unsigned long glyph_index; + unsigned char *data; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + cairo_scaled_glyph_t *glyph = *pscaled_glyph; + cairo_image_surface_t *glyph_surface = glyph->surface; + cairo_bool_t already_had_glyph_surface; + cairo_xlib_font_glyphset_t *info; + + glyph_index = _cairo_scaled_glyph_index (glyph); + + /* check to see if we have a pending XRenderFreeGlyph for this glyph */ + info = find_pending_free_glyph (display, font, glyph_index, glyph_surface); + if (info != NULL) + return _cairo_xlib_glyph_attach (display, glyph, info); + + if (glyph_surface == NULL) { + status = _cairo_scaled_glyph_lookup (font, + glyph_index, + CAIRO_SCALED_GLYPH_INFO_METRICS | + CAIRO_SCALED_GLYPH_INFO_SURFACE, + pscaled_glyph); + if (unlikely (status)) + return status; + + glyph = *pscaled_glyph; + glyph_surface = glyph->surface; + already_had_glyph_surface = FALSE; + } else { + already_had_glyph_surface = TRUE; + } + + info = _cairo_xlib_font_get_glyphset_info_for_format (display, font, + glyph_surface->format); + +#if 0 + /* If the glyph surface has zero height or width, we create + * a clear 1x1 surface, to avoid various X server bugs. + */ + if (glyph_surface->width == 0 || glyph_surface->height == 0) { + cairo_surface_t *tmp_surface; + + tmp_surface = cairo_image_surface_create (info->format, 1, 1); + status = tmp_surface->status; + if (unlikely (status)) + goto BAIL; + + tmp_surface->device_transform = glyph_surface->base.device_transform; + tmp_surface->device_transform_inverse = glyph_surface->base.device_transform_inverse; + + glyph_surface = (cairo_image_surface_t *) tmp_surface; + } +#endif + + /* If the glyph format does not match the font format, then we + * create a temporary surface for the glyph image with the font's + * format. + */ + if (glyph_surface->format != info->format) { + cairo_surface_pattern_t pattern; + cairo_surface_t *tmp_surface; + + tmp_surface = cairo_image_surface_create (info->format, + glyph_surface->width, + glyph_surface->height); + status = tmp_surface->status; + if (unlikely (status)) + goto BAIL; + + tmp_surface->device_transform = glyph_surface->base.device_transform; + tmp_surface->device_transform_inverse = glyph_surface->base.device_transform_inverse; + + _cairo_pattern_init_for_surface (&pattern, &glyph_surface->base); + status = _cairo_surface_paint (tmp_surface, + CAIRO_OPERATOR_SOURCE, &pattern.base, + NULL); + _cairo_pattern_fini (&pattern.base); + + glyph_surface = (cairo_image_surface_t *) tmp_surface; + + if (unlikely (status)) + goto BAIL; + } + + /* XXX: FRAGILE: We're ignore device_transform scaling here. A bug? */ + glyph_info.x = _cairo_lround (glyph_surface->base.device_transform.x0); + glyph_info.y = _cairo_lround (glyph_surface->base.device_transform.y0); + glyph_info.width = glyph_surface->width; + glyph_info.height = glyph_surface->height; + glyph_info.xOff = glyph->x_advance; + glyph_info.yOff = glyph->y_advance; + + data = glyph_surface->data; + + /* flip formats around */ + switch (_cairo_xlib_get_glyphset_index_for_format (glyph->surface->format)) { + case GLYPHSET_INDEX_A1: + /* local bitmaps are always stored with bit == byte */ + if (_cairo_is_little_endian() != (BitmapBitOrder (display->display) == LSBFirst)) { + int c = glyph_surface->stride * glyph_surface->height; + unsigned char *d; + unsigned char *new, *n; + + if (c == 0) + break; + + new = malloc (c); + if (!new) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + n = new; + d = data; + do { + char b = *d++; + b = ((b << 1) & 0xaa) | ((b >> 1) & 0x55); + b = ((b << 2) & 0xcc) | ((b >> 2) & 0x33); + b = ((b << 4) & 0xf0) | ((b >> 4) & 0x0f); + *n++ = b; + } while (--c); + data = new; + } + break; + case GLYPHSET_INDEX_A8: + break; + case GLYPHSET_INDEX_ARGB32: + if (_cairo_is_little_endian() != (ImageByteOrder (display->display) == LSBFirst)) { + unsigned int c = glyph_surface->stride * glyph_surface->height / 4; + const uint32_t *d; + uint32_t *new, *n; + + if (c == 0) + break; + + new = malloc (4 * c); + if (unlikely (new == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + n = new; + d = (uint32_t *) data; + do { + *n++ = bswap_32 (*d); + d++; + } while (--c); + data = (uint8_t *) new; + } + break; + default: + ASSERT_NOT_REACHED; + break; + } + /* XXX assume X server wants pixman padding. Xft assumes this as well */ + + XRenderAddGlyphs (display->display, info->glyphset, + &glyph_index, &glyph_info, 1, + (char *) data, + glyph_surface->stride * glyph_surface->height); + + if (data != glyph_surface->data) + free (data); + + status = _cairo_xlib_glyph_attach (display, glyph, info); + + BAIL: + if (glyph_surface != glyph->surface) + cairo_surface_destroy (&glyph_surface->base); + + /* if the scaled glyph didn't already have a surface attached + * to it, release the created surface now that we have it + * uploaded to the X server. If the surface has already been + * there (eg. because image backend requested it), leave it in + * the cache + */ + if (!already_had_glyph_surface) + _cairo_scaled_glyph_set_surface (glyph, font, NULL); + + return status; +} + +typedef void (*cairo_xrender_composite_text_func_t) + (Display *dpy, + int op, + Picture src, + Picture dst, + _Xconst XRenderPictFormat *maskFormat, + int xSrc, + int ySrc, + int xDst, + int yDst, + _Xconst XGlyphElt8 *elts, + int nelt); + +/* Build a struct of the same size of #cairo_glyph_t that can be used both as + * an input glyph with double coordinates, and as "working" glyph with + * integer from-current-point offsets. */ +typedef union { + cairo_glyph_t d; + unsigned long index; + struct { + unsigned long index; + int x; + int y; + } i; +} cairo_xlib_glyph_t; + +/* compile-time assert that #cairo_xlib_glyph_t is the same size as #cairo_glyph_t */ +COMPILE_TIME_ASSERT (sizeof (cairo_xlib_glyph_t) == sizeof (cairo_glyph_t)); + +/* Start a new element for the first glyph, + * or for any glyph that has unexpected position, + * or if current element has too many glyphs + * (Xrender limits each element to 252 glyphs, we limit them to 128) + * + * These same conditions need to be mirrored between + * _cairo_xlib_surface_emit_glyphs and _emit_glyph_chunks + */ +#define _start_new_glyph_elt(count, glyph) \ + (((count) & 127) == 0 || (glyph)->i.x || (glyph)->i.y) + +static cairo_status_t +_emit_glyphs_chunk (cairo_xlib_display_t *display, + cairo_xlib_surface_t *dst, + int dst_x, int dst_y, + cairo_xlib_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *font, + cairo_bool_t use_mask, + cairo_operator_t op, + cairo_xlib_source_t *src, + int src_x, int src_y, + /* info for this chunk */ + int num_elts, + int width, + cairo_xlib_font_glyphset_t *info) +{ + /* Which XRenderCompositeText function to use */ + cairo_xrender_composite_text_func_t composite_text_func; + int size; + + /* Element buffer stuff */ + XGlyphElt8 *elts; + XGlyphElt8 stack_elts[CAIRO_STACK_ARRAY_LENGTH (XGlyphElt8)]; + + /* Reuse the input glyph array for output char generation */ + char *char8 = (char *) glyphs; + unsigned short *char16 = (unsigned short *) glyphs; + unsigned int *char32 = (unsigned int *) glyphs; + + int i; + int nelt; /* Element index */ + int n; /* Num output glyphs in current element */ + int j; /* Num output glyphs so far */ + + switch (width) { + case 1: + /* don't cast the 8-variant, to catch possible mismatches */ + composite_text_func = XRenderCompositeText8; + size = sizeof (char); + break; + case 2: + composite_text_func = (cairo_xrender_composite_text_func_t) XRenderCompositeText16; + size = sizeof (unsigned short); + break; + default: + case 4: + composite_text_func = (cairo_xrender_composite_text_func_t) XRenderCompositeText32; + size = sizeof (unsigned int); + } + + /* Allocate element array */ + if (num_elts <= ARRAY_LENGTH (stack_elts)) { + elts = stack_elts; + } else { + elts = _cairo_malloc_ab (num_elts, sizeof (XGlyphElt8)); + if (unlikely (elts == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + /* Fill them in */ + nelt = 0; + n = 0; + j = 0; + for (i = 0; i < num_glyphs; i++) { + /* Start a new element for first output glyph, + * or for any glyph that has unexpected position, + * or if current element has too many glyphs. + * + * These same conditions are mirrored in _cairo_xlib_surface_emit_glyphs() + */ + if (_start_new_glyph_elt (j, &glyphs[i])) { + if (j) { + elts[nelt].nchars = n; + nelt++; + n = 0; + } + elts[nelt].chars = char8 + size * j; + elts[nelt].glyphset = info->glyphset; + elts[nelt].xOff = glyphs[i].i.x; + elts[nelt].yOff = glyphs[i].i.y; + } + + switch (width) { + case 1: char8 [j] = (char) glyphs[i].index; break; + case 2: char16[j] = (unsigned short) glyphs[i].index; break; + default: + case 4: char32[j] = (unsigned int) glyphs[i].index; break; + } + + n++; + j++; + } + + if (n) { + elts[nelt].nchars = n; + nelt++; + } + + /* Check that we agree with _cairo_xlib_surface_emit_glyphs() on the + * expected number of xGlyphElts. */ + assert (nelt == num_elts); + + composite_text_func (display->display, op, + src->picture, + dst->picture, + use_mask ? info->xrender_format : NULL, + src_x + elts[0].xOff + dst_x, + src_y + elts[0].yOff + dst_y, + elts[0].xOff, elts[0].yOff, + (XGlyphElt8 *) elts, nelt); + + if (elts != stack_elts) + free (elts); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +check_composite_glyphs (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *font, + cairo_glyph_t *glyphs, + int *num_glyphs) +{ + cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)extents->surface; + cairo_xlib_display_t *display = dst->display; + int max_request_size, size; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (! CAIRO_RENDER_SUPPORTS_OPERATOR (display, extents->op)) + return CAIRO_INT_STATUS_UNSUPPORTED; + + /* The glyph coordinates must be representable in an int16_t. + * When possible, they will be expressed as an offset from the + * previous glyph, otherwise they will be an offset from the + * surface origin. If we can't guarantee this to be possible, + * fallback. + */ + if (extents->bounded.x + extents->bounded.width > INT16_MAX || + extents->bounded.y + extents->bounded.height> INT16_MAX || + extents->bounded.x < INT16_MIN || + extents->bounded.y < INT16_MIN) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } + + /* Approximate the size of the largest glyph and fallback if we can not + * upload it to the xserver. + */ + size = ceil (font->max_scale); + size = 4 * size * size; + max_request_size = (XExtendedMaxRequestSize (display->display) ? XExtendedMaxRequestSize (display->display) + : XMaxRequestSize (display->display)) * 4 - + sz_xRenderAddGlyphsReq - + sz_xGlyphInfo - + 8; + if (size >= max_request_size) + return CAIRO_INT_STATUS_UNSUPPORTED; + + return CAIRO_STATUS_SUCCESS; +} + +/* sz_xGlyphtElt required alignment to a 32-bit boundary, so ensure we have + * enough room for padding */ +#define _cairo_sz_xGlyphElt (sz_xGlyphElt + 4) + +static cairo_int_status_t +composite_glyphs (void *surface, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + cairo_xlib_surface_t *dst = surface; + cairo_xlib_glyph_t *glyphs = (cairo_xlib_glyph_t *)info->glyphs; + cairo_xlib_source_t *src = (cairo_xlib_source_t *)_src; + cairo_xlib_display_t *display = dst->display; + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + cairo_scaled_glyph_t *glyph; + cairo_fixed_t x = dst_x, y = dst_y; + cairo_xlib_font_glyphset_t *glyphset = NULL, *this_glyphset_info; + + unsigned long max_index = 0; + int width = 1; + int num_elts = 0; + int num_out_glyphs = 0; + int num_glyphs = info->num_glyphs; + + int max_request_size = XMaxRequestSize (display->display) * 4 + - MAX (sz_xRenderCompositeGlyphs8Req, + MAX(sz_xRenderCompositeGlyphs16Req, + sz_xRenderCompositeGlyphs32Req)); + int request_size = 0; + int i; + + op = _render_operator (op), + _cairo_xlib_surface_ensure_picture (dst); + for (i = 0; i < num_glyphs; i++) { + int this_x, this_y; + int old_width; + + status = _cairo_scaled_glyph_lookup (info->font, + glyphs[i].index, + CAIRO_SCALED_GLYPH_INFO_METRICS, + &glyph); + if (unlikely (status)) + return status; + + this_x = _cairo_lround (glyphs[i].d.x); + this_y = _cairo_lround (glyphs[i].d.y); + + /* Send unsent glyphs to the server */ + if (glyph->dev_private_key != display) { + status = _cairo_xlib_surface_add_glyph (display, info->font, &glyph); + if (unlikely (status)) + return status; + } + + this_glyphset_info = glyph->dev_private; + if (!glyphset) + glyphset = this_glyphset_info; + + /* The invariant here is that we can always flush the glyphs + * accumulated before this one, using old_width, and they + * would fit in the request. + */ + old_width = width; + + /* Update max glyph index */ + if (glyphs[i].index > max_index) { + max_index = glyphs[i].index; + if (max_index >= 65536) + width = 4; + else if (max_index >= 256) + width = 2; + if (width != old_width) + request_size += (width - old_width) * num_out_glyphs; + } + + /* If we will pass the max request size by adding this glyph, + * flush current glyphs. Note that we account for a + * possible element being added below. + * + * Also flush if changing glyphsets, as Xrender limits one mask + * format per request, so we can either break up, or use a + * wide-enough mask format. We do the former. One reason to + * prefer the latter is the fact that Xserver ADDs all glyphs + * to the mask first, and then composes that to final surface, + * though it's not a big deal. + * + * If the glyph has a coordinate which cannot be represented + * as a 16-bit offset from the previous glyph, flush the + * current chunk. The current glyph will be the first one in + * the next chunk, thus its coordinates will be an offset from + * the destination origin. This offset is guaranteed to be + * representable as 16-bit offset (otherwise we would have + * fallen back). + */ + if (request_size + width > max_request_size - _cairo_sz_xGlyphElt || + this_x - x > INT16_MAX || this_x - x < INT16_MIN || + this_y - y > INT16_MAX || this_y - y < INT16_MIN || + (this_glyphset_info != glyphset)) { + status = _emit_glyphs_chunk (display, dst, dst_x, dst_y, + glyphs, i, info->font, info->use_mask, + op, src, src_x, src_y, + num_elts, old_width, glyphset); + if (unlikely (status)) + return status; + + glyphs += i; + num_glyphs -= i; + i = 0; + max_index = glyphs[i].index; + width = max_index < 256 ? 1 : max_index < 65536 ? 2 : 4; + request_size = 0; + num_elts = 0; + num_out_glyphs = 0; + x = y = 0; + glyphset = this_glyphset_info; + } + + /* Convert absolute glyph position to relative-to-current-point + * position */ + glyphs[i].i.x = this_x - x; + glyphs[i].i.y = this_y - y; + + /* Start a new element for the first glyph, + * or for any glyph that has unexpected position, + * or if current element has too many glyphs. + * + * These same conditions are mirrored in _emit_glyphs_chunk(). + */ + if (_start_new_glyph_elt (num_out_glyphs, &glyphs[i])) { + num_elts++; + request_size += _cairo_sz_xGlyphElt; + } + + /* adjust current-position */ + x = this_x + glyph->x_advance; + y = this_y + glyph->y_advance; + + num_out_glyphs++; + request_size += width; + } + + if (num_elts) { + status = _emit_glyphs_chunk (display, dst, dst_x, dst_y, + glyphs, i, info->font, info->use_mask, + op, src, src_x, src_y, + num_elts, width, glyphset); + } + + return status; +} + +const cairo_compositor_t * +_cairo_xlib_mask_compositor_get (void) +{ + static cairo_mask_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_mask_compositor_init (&compositor, + _cairo_xlib_fallback_compositor_get ()); + + compositor.acquire = acquire; + compositor.release = release; + compositor.set_clip_region = set_clip_region; + compositor.pattern_to_surface = _cairo_xlib_source_create_for_pattern; + compositor.draw_image_boxes = draw_image_boxes; + compositor.fill_rectangles = fill_rectangles; + compositor.fill_boxes = fill_boxes; + compositor.copy_boxes = copy_boxes; + compositor.check_composite = check_composite; + compositor.composite = composite; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + compositor.check_composite_glyphs = check_composite_glyphs; + compositor.composite_glyphs = composite_glyphs; + } + + return &compositor.base; +} + +#define CAIRO_FIXED_16_16_MIN -32768 +#define CAIRO_FIXED_16_16_MAX 32767 + +static cairo_bool_t +line_exceeds_16_16 (const cairo_line_t *line) +{ + return + line->p1.x < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || + line->p1.x > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX) || + line->p2.x < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || + line->p2.x > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX) || + line->p1.y < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || + line->p1.y > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX) || + line->p2.y < _cairo_fixed_from_int (CAIRO_FIXED_16_16_MIN) || + line->p2.y > _cairo_fixed_from_int (CAIRO_FIXED_16_16_MAX); +} + +static void +project_line_x_onto_16_16 (const cairo_line_t *line, + cairo_fixed_t top, + cairo_fixed_t bottom, + XLineFixed *out) +{ + cairo_point_double_t p1, p2; + double m; + + p1.x = _cairo_fixed_to_double (line->p1.x); + p1.y = _cairo_fixed_to_double (line->p1.y); + + p2.x = _cairo_fixed_to_double (line->p2.x); + p2.y = _cairo_fixed_to_double (line->p2.y); + + m = (p2.x - p1.x) / (p2.y - p1.y); + out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); + out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); +} +#if 0 +static cairo_int_status_T +check_composite_trapezoids () +{ + operation = _categorize_composite_operation (dst, op, pattern, TRUE); + if (operation == DO_UNSUPPORTED) + return UNSUPPORTED ("unsupported operation"); + + operation = _recategorize_composite_operation (dst, op, src, + &attributes, TRUE); + if (operation == DO_UNSUPPORTED) { + status = UNSUPPORTED ("unsupported operation"); + goto BAIL; + } + +} +#endif + +static cairo_int_status_t +composite_traps (void *abstract_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_traps_t *traps) +{ + cairo_xlib_surface_t *dst = abstract_dst; + cairo_xlib_display_t *display = dst->display; + cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; + XRenderPictFormat *pict_format; + XTrapezoid xtraps_stack[CAIRO_STACK_ARRAY_LENGTH (XTrapezoid)]; + XTrapezoid *xtraps = xtraps_stack; + int dx, dy; + int i; + + //X_DEBUG ((display->display, "composite_trapezoids (dst=%x)", (unsigned int) dst->drawable)); + + if (dst->base.is_clear && + (op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD)) + { + op = CAIRO_OPERATOR_SOURCE; + } + + pict_format = + _cairo_xlib_display_get_xrender_format (display, + antialias == CAIRO_ANTIALIAS_NONE ? CAIRO_FORMAT_A1 : CAIRO_FORMAT_A8); + + if (traps->num_traps > ARRAY_LENGTH (xtraps_stack)) { + xtraps = _cairo_malloc_ab (traps->num_traps, sizeof (XTrapezoid)); + if (unlikely (xtraps == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + dx = -dst_x << 16; + dy = -dst_y << 16; + for (i = 0; i < traps->num_traps; i++) { + cairo_trapezoid_t *t = &traps->traps[i]; + + /* top/bottom will be clamped to surface bounds */ + xtraps[i].top = _cairo_fixed_to_16_16(t->top) + dy; + xtraps[i].bottom = _cairo_fixed_to_16_16(t->bottom) + dy; + + /* However, all the other coordinates will have been left untouched so + * as not to introduce numerical error. Recompute them if they + * exceed the 16.16 limits. + */ + if (unlikely (line_exceeds_16_16 (&t->left))) { + project_line_x_onto_16_16 (&t->left, t->top, t->bottom, + &xtraps[i].left); + xtraps[i].left.p1.x += dx; + xtraps[i].left.p2.x += dx; + xtraps[i].left.p1.y = xtraps[i].top; + xtraps[i].left.p2.y = xtraps[i].bottom; + } else { + xtraps[i].left.p1.x = _cairo_fixed_to_16_16(t->left.p1.x) + dx; + xtraps[i].left.p1.y = _cairo_fixed_to_16_16(t->left.p1.y) + dy; + xtraps[i].left.p2.x = _cairo_fixed_to_16_16(t->left.p2.x) + dx; + xtraps[i].left.p2.y = _cairo_fixed_to_16_16(t->left.p2.y) + dy; + } + + if (unlikely (line_exceeds_16_16 (&t->right))) { + project_line_x_onto_16_16 (&t->right, t->top, t->bottom, + &xtraps[i].right); + xtraps[i].right.p1.x += dx; + xtraps[i].right.p2.x += dx; + xtraps[i].right.p1.y = xtraps[i].top; + xtraps[i].right.p2.y = xtraps[i].bottom; + } else { + xtraps[i].right.p1.x = _cairo_fixed_to_16_16(t->right.p1.x) + dx; + xtraps[i].right.p1.y = _cairo_fixed_to_16_16(t->right.p1.y) + dy; + xtraps[i].right.p2.x = _cairo_fixed_to_16_16(t->right.p2.x) + dx; + xtraps[i].right.p2.y = _cairo_fixed_to_16_16(t->right.p2.y) + dy; + } + } + + if (xtraps[0].left.p1.y < xtraps[0].left.p2.y) { + src_x += _cairo_fixed_16_16_floor (xtraps[0].left.p1.x); + src_y += _cairo_fixed_16_16_floor (xtraps[0].left.p1.y); + } else { + src_x += _cairo_fixed_16_16_floor (xtraps[0].left.p2.x); + src_y += _cairo_fixed_16_16_floor (xtraps[0].left.p2.y); + } + src_x += dst_x; + src_y += dst_y; + + _cairo_xlib_surface_ensure_picture (dst); + _cairo_xlib_surface_set_precision (dst, antialias); + XRenderCompositeTrapezoids (dst->dpy, + _render_operator (op), + src->picture, dst->picture, + pict_format, + src_x, src_y, + xtraps, traps->num_traps); + + if (xtraps != xtraps_stack) + free (xtraps); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_tristrip (void *abstract_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_tristrip_t *strip) +{ + cairo_xlib_surface_t *dst = abstract_dst; + cairo_xlib_display_t *display = dst->display; + cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src; + XRenderPictFormat *pict_format; + XPointFixed points_stack[CAIRO_STACK_ARRAY_LENGTH (XPointFixed)]; + XPointFixed *points = points_stack; + int dx, dy; + int i; + + //X_DEBUG ((display->display, "composite_trapezoids (dst=%x)", (unsigned int) dst->drawable)); + + pict_format = + _cairo_xlib_display_get_xrender_format (display, + antialias == CAIRO_ANTIALIAS_NONE ? CAIRO_FORMAT_A1 : CAIRO_FORMAT_A8); + + if (strip->num_points > ARRAY_LENGTH (points_stack)) { + points = _cairo_malloc_ab (strip->num_points, sizeof (XPointFixed)); + if (unlikely (points == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + dx = -dst_x << 16; + dy = -dst_y << 16; + for (i = 0; i < strip->num_points; i++) { + cairo_point_t *p = &strip->points[i]; + + points[i].x = _cairo_fixed_to_16_16(p->x) + dx; + points[i].y = _cairo_fixed_to_16_16(p->y) + dy; + } + + src_x += _cairo_fixed_16_16_floor (points[0].x) + dst_x; + src_y += _cairo_fixed_16_16_floor (points[0].y) + dst_y; + + _cairo_xlib_surface_ensure_picture (dst); + _cairo_xlib_surface_set_precision (dst, antialias); + XRenderCompositeTriStrip (dst->dpy, + _render_operator (op), + src->picture, dst->picture, + pict_format, + src_x, src_y, + points, strip->num_points); + + if (points != points_stack) + free (points); + + return CAIRO_STATUS_SUCCESS; +} + +const cairo_compositor_t * +_cairo_xlib_traps_compositor_get (void) +{ + static cairo_traps_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_traps_compositor_init (&compositor, + _cairo_xlib_mask_compositor_get ()); + + compositor.acquire = acquire; + compositor.release = release; + compositor.set_clip_region = set_clip_region; + compositor.pattern_to_surface = _cairo_xlib_source_create_for_pattern; + compositor.draw_image_boxes = draw_image_boxes; + compositor.copy_boxes = copy_boxes; + compositor.fill_boxes = fill_boxes; + compositor.check_composite = check_composite; + compositor.composite = composite; + compositor.lerp = lerp; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + //compositor.check_composite_traps = check_composite_traps; + compositor.composite_traps = composite_traps; + //compositor.check_composite_tristrip = check_composite_tristrip; + compositor.composite_tristrip = composite_tristrip; + compositor.check_composite_glyphs = check_composite_glyphs; + compositor.composite_glyphs = composite_glyphs; + } + + return &compositor.base; +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-screen.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-screen.c new file mode 100644 index 00000000000..57beeaab426 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-screen.c @@ -0,0 +1,467 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Partially on code from xftdpy.c + * + * Copyright © 2000 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" +#include "cairo-xlib-xrender-private.h" + +#include "cairo-xlib-surface-private.h" +#include "cairo-error-private.h" +#include "cairo-list-inline.h" + +#include "cairo-fontconfig-private.h" + +static int +parse_boolean (const char *v) +{ + char c0, c1; + + c0 = *v; + if (c0 == 't' || c0 == 'T' || c0 == 'y' || c0 == 'Y' || c0 == '1') + return 1; + if (c0 == 'f' || c0 == 'F' || c0 == 'n' || c0 == 'N' || c0 == '0') + return 0; + if (c0 == 'o') + { + c1 = v[1]; + if (c1 == 'n' || c1 == 'N') + return 1; + if (c1 == 'f' || c1 == 'F') + return 0; + } + + return -1; +} + +static cairo_bool_t +get_boolean_default (Display *dpy, + const char *option, + cairo_bool_t *value) +{ + char *v; + int i; + + v = XGetDefault (dpy, "Xft", option); + if (v) { + i = parse_boolean (v); + if (i >= 0) { + *value = i; + return TRUE; + } + } + + return FALSE; +} + +static cairo_bool_t +get_integer_default (Display *dpy, + const char *option, + int *value) +{ + char *v, *e; + + v = XGetDefault (dpy, "Xft", option); + if (v) { +#if CAIRO_HAS_FC_FONT + if (FcNameConstant ((FcChar8 *) v, value)) + return TRUE; +#endif + + *value = strtol (v, &e, 0); + if (e != v) + return TRUE; + } + + return FALSE; +} + +static void +_cairo_xlib_init_screen_font_options (Display *dpy, + cairo_xlib_screen_t *info) +{ + cairo_bool_t xft_hinting; + cairo_bool_t xft_antialias; + int xft_hintstyle; + int xft_rgba; + int xft_lcdfilter; + cairo_antialias_t antialias; + cairo_subpixel_order_t subpixel_order; + cairo_lcd_filter_t lcd_filter; + cairo_hint_style_t hint_style; + + if (!get_boolean_default (dpy, "antialias", &xft_antialias)) + xft_antialias = TRUE; + + if (!get_integer_default (dpy, "lcdfilter", &xft_lcdfilter)) { + /* -1 is an non-existant Fontconfig constant used to differentiate + * the case when no lcdfilter property is available. + */ + xft_lcdfilter = -1; + } + + if (!get_boolean_default (dpy, "hinting", &xft_hinting)) + xft_hinting = TRUE; + + if (!get_integer_default (dpy, "hintstyle", &xft_hintstyle)) + xft_hintstyle = FC_HINT_FULL; + + if (!get_integer_default (dpy, "rgba", &xft_rgba)) + { + cairo_xlib_display_t *display = (cairo_xlib_display_t *) info->device; + + xft_rgba = FC_RGBA_UNKNOWN; + +#if RENDER_MAJOR > 0 || RENDER_MINOR >= 6 + if (display->render_major > 0 || display->render_minor >= 6) { + int render_order = XRenderQuerySubpixelOrder (dpy, + XScreenNumberOfScreen (info->screen)); + + switch (render_order) { + default: + case SubPixelUnknown: + xft_rgba = FC_RGBA_UNKNOWN; + break; + case SubPixelHorizontalRGB: + xft_rgba = FC_RGBA_RGB; + break; + case SubPixelHorizontalBGR: + xft_rgba = FC_RGBA_BGR; + break; + case SubPixelVerticalRGB: + xft_rgba = FC_RGBA_VRGB; + break; + case SubPixelVerticalBGR: + xft_rgba = FC_RGBA_VBGR; + break; + case SubPixelNone: + xft_rgba = FC_RGBA_NONE; + break; + } + } +#endif + } + + if (xft_hinting) { + switch (xft_hintstyle) { + case FC_HINT_NONE: + hint_style = CAIRO_HINT_STYLE_NONE; + break; + case FC_HINT_SLIGHT: + hint_style = CAIRO_HINT_STYLE_SLIGHT; + break; + case FC_HINT_MEDIUM: + hint_style = CAIRO_HINT_STYLE_MEDIUM; + break; + case FC_HINT_FULL: + hint_style = CAIRO_HINT_STYLE_FULL; + break; + default: + hint_style = CAIRO_HINT_STYLE_DEFAULT; + } + } else { + hint_style = CAIRO_HINT_STYLE_NONE; + } + + switch (xft_rgba) { + case FC_RGBA_RGB: + subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; + break; + case FC_RGBA_BGR: + subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; + break; + case FC_RGBA_VRGB: + subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; + break; + case FC_RGBA_VBGR: + subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; + break; + case FC_RGBA_UNKNOWN: + case FC_RGBA_NONE: + default: + subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + } + + switch (xft_lcdfilter) { + case FC_LCD_NONE: + lcd_filter = CAIRO_LCD_FILTER_NONE; + break; + case FC_LCD_DEFAULT: + lcd_filter = CAIRO_LCD_FILTER_FIR5; + break; + case FC_LCD_LIGHT: + lcd_filter = CAIRO_LCD_FILTER_FIR3; + break; + case FC_LCD_LEGACY: + lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL; + break; + default: + lcd_filter = CAIRO_LCD_FILTER_DEFAULT; + break; + } + + if (xft_antialias) { + if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT) + antialias = CAIRO_ANTIALIAS_GRAY; + else + antialias = CAIRO_ANTIALIAS_SUBPIXEL; + } else { + antialias = CAIRO_ANTIALIAS_NONE; + } + + cairo_font_options_set_hint_style (&info->font_options, hint_style); + cairo_font_options_set_antialias (&info->font_options, antialias); + cairo_font_options_set_subpixel_order (&info->font_options, subpixel_order); + _cairo_font_options_set_lcd_filter (&info->font_options, lcd_filter); + cairo_font_options_set_hint_metrics (&info->font_options, CAIRO_HINT_METRICS_ON); +} + +void +_cairo_xlib_screen_destroy (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info) +{ + Display *dpy; + int i; + + dpy = display->display; + + while (! cairo_list_is_empty (&info->surfaces)) { + cairo_xlib_surface_t *surface; + + surface = cairo_list_first_entry (&info->surfaces, + cairo_xlib_surface_t, + link); + cairo_surface_finish (&surface->base); + } + + for (i = 0; i < ARRAY_LENGTH (info->gc); i++) { + if (info->gc_depths[i] != 0) { + XFreeGC (dpy, info->gc[i]); + info->gc_depths[i] = 0; + } + } + + while (! cairo_list_is_empty (&info->visuals)) { + _cairo_xlib_visual_info_destroy (cairo_list_first_entry (&info->visuals, + cairo_xlib_visual_info_t, + link)); + } + + cairo_list_del (&info->link); + + free (info); +} + +cairo_status_t +_cairo_xlib_screen_get (Display *dpy, + Screen *screen, + cairo_xlib_screen_t **out) +{ + cairo_xlib_display_t *display; + cairo_device_t *device; + cairo_xlib_screen_t *info; + cairo_status_t status; + + device = _cairo_xlib_device_create (dpy); + status = device->status; + if (unlikely (status)) + goto CLEANUP_DEVICE; + + status = _cairo_xlib_display_acquire (device, &display); + if (unlikely (status)) + goto CLEANUP_DEVICE; + + info = _cairo_xlib_display_get_screen (display, screen); + if (info != NULL) { + *out = info; + goto CLEANUP_DISPLAY; + } + + info = malloc (sizeof (cairo_xlib_screen_t)); + if (unlikely (info == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto CLEANUP_DISPLAY; + } + + info->device = device; + info->screen = screen; + info->has_font_options = FALSE; + memset (info->gc_depths, 0, sizeof (info->gc_depths)); + memset (info->gc, 0, sizeof (info->gc)); + + cairo_list_init (&info->surfaces); + cairo_list_init (&info->visuals); + cairo_list_add (&info->link, &display->screens); + + *out = info; + + CLEANUP_DISPLAY: + cairo_device_release (&display->base); + + CLEANUP_DEVICE: + cairo_device_destroy (device); + return status; +} + +GC +_cairo_xlib_screen_get_gc (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info, + int depth, + Drawable drawable) +{ + GC gc = NULL; + int i; + + for (i = 0; i < ARRAY_LENGTH (info->gc); i++) { + if (info->gc_depths[i] == depth) { + info->gc_depths[i] = 0; + gc = info->gc[i]; + break; + } + } + + if (gc == NULL) { + XGCValues gcv; + + gcv.graphics_exposures = False; + gcv.fill_style = FillTiled; + gc = XCreateGC (display->display, + drawable, + GCGraphicsExposures | GCFillStyle, &gcv); + } + + return gc; +} + +void +_cairo_xlib_screen_put_gc (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info, + int depth, + GC gc) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (info->gc); i++) { + if (info->gc_depths[i] == 0) + break; + } + + if (i == ARRAY_LENGTH (info->gc)) { + /* perform random substitution to ensure fair caching over depths */ + i = rand () % ARRAY_LENGTH (info->gc); + XFreeGC(display->display, info->gc[i]); + } + + info->gc[i] = gc; + info->gc_depths[i] = depth; +} + +cairo_status_t +_cairo_xlib_screen_get_visual_info (cairo_xlib_display_t *display, + cairo_xlib_screen_t *info, + Visual *v, + cairo_xlib_visual_info_t **out) +{ + cairo_xlib_visual_info_t *visual; + cairo_status_t status; + + cairo_list_foreach_entry (visual, + cairo_xlib_visual_info_t, + &info->visuals, + link) + { + if (visual->visualid == v->visualid) { + *out = visual; + return CAIRO_STATUS_SUCCESS; + } + } + + status = _cairo_xlib_visual_info_create (display->display, + XScreenNumberOfScreen (info->screen), + v->visualid, + &visual); + if (unlikely (status)) + return status; + + cairo_list_add (&visual->link, &info->visuals); + *out = visual; + return CAIRO_STATUS_SUCCESS; +} + +cairo_font_options_t * +_cairo_xlib_screen_get_font_options (cairo_xlib_screen_t *info) +{ + if (! info->has_font_options) { + _cairo_font_options_init_default (&info->font_options); + _cairo_font_options_set_round_glyph_positions (&info->font_options, CAIRO_ROUND_GLYPH_POS_ON); + + if (info->screen != NULL) { + cairo_xlib_display_t *display; + + if (! _cairo_xlib_display_acquire (info->device, &display)) { + _cairo_xlib_init_screen_font_options (display->display, + info); + cairo_device_release (&display->base); + } + } + + info->has_font_options = TRUE; + } + + return &info->font_options; +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-source.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-source.c new file mode 100644 index 00000000000..1591f5874f6 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-source.c @@ -0,0 +1,1168 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Behdad Esfahbod + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" +#include "cairo-xlib-surface-private.h" + +#include "cairo-error-private.h" +#include "cairo-image-surface-inline.h" +#include "cairo-paginated-private.h" +#include "cairo-pattern-inline.h" +#include "cairo-recording-surface-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-surface-offset-private.h" +#include "cairo-surface-observer-private.h" +#include "cairo-surface-snapshot-inline.h" +#include "cairo-surface-subsurface-inline.h" + +#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e) /* need to ensure deltas also fit */ + +static cairo_xlib_surface_t * +unwrap_source (const cairo_surface_pattern_t *pattern) +{ + cairo_rectangle_int_t limits; + return (cairo_xlib_surface_t *)_cairo_pattern_get_source (pattern, &limits); +} + +static cairo_status_t +_cairo_xlib_source_finish (void *abstract_surface) +{ + cairo_xlib_source_t *source = abstract_surface; + + XRenderFreePicture (source->dpy, source->picture); + if (source->pixmap) + XFreePixmap (source->dpy, source->pixmap); + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t cairo_xlib_source_backend = { + CAIRO_SURFACE_TYPE_XLIB, + _cairo_xlib_source_finish, + NULL, /* read-only wrapper */ +}; + +static cairo_status_t +_cairo_xlib_proxy_finish (void *abstract_surface) +{ + cairo_xlib_proxy_t *proxy = abstract_surface; + + _cairo_xlib_shm_surface_mark_active (proxy->owner); + XRenderFreePicture (proxy->source.dpy, proxy->source.picture); + if (proxy->source.pixmap) + XFreePixmap (proxy->source.dpy, proxy->source.pixmap); + cairo_surface_destroy (proxy->owner); + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t cairo_xlib_proxy_backend = { + CAIRO_SURFACE_TYPE_XLIB, + _cairo_xlib_proxy_finish, + NULL, /* read-only wrapper */ +}; + +static cairo_surface_t * +source (cairo_xlib_surface_t *dst, Picture picture, Pixmap pixmap) +{ + cairo_xlib_source_t *source; + + if (picture == None) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + source = malloc (sizeof (*source)); + if (unlikely (source == NULL)) { + XRenderFreePicture (dst->display->display, picture); + if (pixmap) + XFreePixmap (dst->display->display, pixmap); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + _cairo_surface_init (&source->base, + &cairo_xlib_source_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + /* The source exists only within an operation */ + source->picture = picture; + source->pixmap = pixmap; + source->dpy = dst->display->display; + + return &source->base; +} + +static uint32_t +hars_petruska_f54_1_random (void) +{ +#define rol(x,k) ((x << k) | (x >> (32-k))) + static uint32_t x; + return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849; +#undef rol +} + +static const XTransform identity = { + { + { 1 << 16, 0x00000, 0x00000 }, + { 0x00000, 1 << 16, 0x00000 }, + { 0x00000, 0x00000, 1 << 16 }, + } +}; + +static cairo_bool_t +picture_set_matrix (cairo_xlib_display_t *display, + Picture picture, + const cairo_matrix_t *matrix, + cairo_filter_t filter, + double xc, + double yc, + int *x_offset, + int *y_offset) +{ + XTransform xtransform; + pixman_transform_t *pixman_transform; + cairo_int_status_t status; + + /* Casting between pixman_transform_t and XTransform is safe because + * they happen to be the exact same type. + */ + pixman_transform = (pixman_transform_t *) &xtransform; + status = _cairo_matrix_to_pixman_matrix_offset (matrix, filter, xc, yc, + pixman_transform, + x_offset, y_offset); + if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) + return TRUE; + if (unlikely (status != CAIRO_INT_STATUS_SUCCESS)) + return FALSE; + + if (memcmp (&xtransform, &identity, sizeof (XTransform)) == 0) + return TRUE; + + /* a late check in case we perturb the matrix too far */ + if (! CAIRO_RENDER_HAS_PICTURE_TRANSFORM (display)) + return FALSE; + + XRenderSetPictureTransform (display->display, picture, &xtransform); + return TRUE; +} + +static cairo_status_t +picture_set_filter (Display *dpy, + Picture picture, + cairo_filter_t filter) +{ + const char *render_filter; + + switch (filter) { + case CAIRO_FILTER_FAST: + render_filter = FilterFast; + break; + case CAIRO_FILTER_GOOD: + render_filter = FilterGood; + break; + case CAIRO_FILTER_BEST: + render_filter = FilterBest; + break; + case CAIRO_FILTER_NEAREST: + render_filter = FilterNearest; + break; + case CAIRO_FILTER_BILINEAR: + render_filter = FilterBilinear; + break; + case CAIRO_FILTER_GAUSSIAN: + /* XXX: The GAUSSIAN value has no implementation in cairo + * whatsoever, so it was really a mistake to have it in the + * API. We could fix this by officially deprecating it, or + * else inventing semantics and providing an actual + * implementation for it. */ + default: + render_filter = FilterBest; + break; + } + + XRenderSetPictureFilter (dpy, picture, (char *) render_filter, NULL, 0); + return CAIRO_STATUS_SUCCESS; +} + +static int +extend_to_repeat (cairo_extend_t extend) +{ + switch (extend) { + default: + ASSERT_NOT_REACHED; + case CAIRO_EXTEND_NONE: + return RepeatNone; + case CAIRO_EXTEND_REPEAT: + return RepeatNormal; + case CAIRO_EXTEND_REFLECT: + return RepeatReflect; + case CAIRO_EXTEND_PAD: + return RepeatPad; + } +} + +static cairo_bool_t +picture_set_properties (cairo_xlib_display_t *display, + Picture picture, + const cairo_pattern_t *pattern, + const cairo_matrix_t *matrix, + const cairo_rectangle_int_t *extents, + int *x_off, int *y_off) +{ + XRenderPictureAttributes pa; + int mask = 0; + + if (! picture_set_matrix (display, picture, matrix, pattern->filter, + extents->x + extents->width / 2, + extents->y + extents->height / 2, + x_off, y_off)) + return FALSE; + + picture_set_filter (display->display, picture, pattern->filter); + + if (pattern->has_component_alpha) { + pa.component_alpha = 1; + mask |= CPComponentAlpha; + } + + if (pattern->extend != CAIRO_EXTEND_NONE) { + pa.repeat = extend_to_repeat (pattern->extend); + mask |= CPRepeat; + } + + if (mask) + XRenderChangePicture (display->display, picture, mask, &pa); + + return TRUE; +} + +static cairo_surface_t * +render_pattern (cairo_xlib_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + int *src_x, int *src_y) +{ + Display *dpy = dst->display->display; + cairo_xlib_surface_t *src; + cairo_image_surface_t *image; + cairo_status_t status; + cairo_rectangle_int_t map_extents; + + src = (cairo_xlib_surface_t *) + _cairo_surface_create_scratch (&dst->base, + is_mask ? CAIRO_CONTENT_ALPHA : CAIRO_CONTENT_COLOR_ALPHA, + extents->width, + extents->height, + NULL); + if (src->base.type != CAIRO_SURFACE_TYPE_XLIB) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + map_extents = *extents; + map_extents.x = map_extents.y = 0; + + image = _cairo_surface_map_to_image (&src->base, &map_extents); + status = _cairo_surface_offset_paint (&image->base, extents->x, extents->y, + CAIRO_OPERATOR_SOURCE, pattern, + NULL); + status = _cairo_surface_unmap_image (&src->base, image); + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (status); + } + + status = _cairo_xlib_surface_put_shm (src); + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (status); + } + + src->picture = XRenderCreatePicture (dpy, + src->drawable, src->xrender_format, + 0, NULL); + + *src_x = -extents->x; + *src_y = -extents->y; + return &src->base; +} + +static cairo_surface_t * +gradient_source (cairo_xlib_surface_t *dst, + const cairo_gradient_pattern_t *gradient, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + int *src_x, int *src_y) +{ + cairo_xlib_display_t *display = dst->display; + cairo_matrix_t matrix = gradient->base.matrix; + char buf[CAIRO_STACK_BUFFER_SIZE]; + cairo_circle_double_t extremes[2]; + XFixed *stops; + XRenderColor *colors; + Picture picture; + unsigned int i, n_stops; + + /* The RENDER specification says that the inner circle has + * to be completely contained inside the outer one. */ + if (gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL && + ! _cairo_radial_pattern_focus_is_inside ((cairo_radial_pattern_t *) gradient)) + return render_pattern (dst, &gradient->base, is_mask, extents, src_x, src_y); + + assert (gradient->n_stops > 0); + n_stops = MAX (gradient->n_stops, 2); + + if (n_stops < sizeof (buf) / (sizeof (XFixed) + sizeof (XRenderColor))) + { + stops = (XFixed *) buf; + } + else + { + stops = + _cairo_malloc_ab (n_stops, + sizeof (XFixed) + sizeof (XRenderColor)); + if (unlikely (stops == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + colors = (XRenderColor *) (stops + n_stops); + for (i = 0; i < gradient->n_stops; i++) { + stops[i] = + _cairo_fixed_16_16_from_double (gradient->stops[i].offset); + + colors[i].red = gradient->stops[i].color.red_short; + colors[i].green = gradient->stops[i].color.green_short; + colors[i].blue = gradient->stops[i].color.blue_short; + colors[i].alpha = gradient->stops[i].color.alpha_short; + } + + /* RENDER does not support gradients with less than 2 + * stops. If a gradient has only a single stop, duplicate + * it to make RENDER happy. */ + if (gradient->n_stops == 1) { + stops[1] = + _cairo_fixed_16_16_from_double (gradient->stops[0].offset); + + colors[1].red = gradient->stops[0].color.red_short; + colors[1].green = gradient->stops[0].color.green_short; + colors[1].blue = gradient->stops[0].color.blue_short; + colors[1].alpha = gradient->stops[0].color.alpha_short; + } + +#if 0 + /* For some weird reason the X server is sometimes getting + * CreateGradient requests with bad length. So far I've only seen + * XRenderCreateLinearGradient request with 4 stops sometime end up + * with length field matching 0 stops at the server side. I've + * looked at the libXrender code and I can't see anything that + * could cause this behavior. However, for some reason having a + * XSync call here seems to avoid the issue so I'll keep it here + * until it's solved. + */ + XSync (display->display, False); +#endif + + _cairo_gradient_pattern_fit_to_range (gradient, PIXMAN_MAX_INT >> 1, &matrix, extremes); + + if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) { + XLinearGradient grad; + + grad.p1.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); + grad.p1.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); + grad.p2.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); + grad.p2.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); + + picture = XRenderCreateLinearGradient (display->display, &grad, + stops, colors, + n_stops); + } else { + XRadialGradient grad; + + grad.inner.x = _cairo_fixed_16_16_from_double (extremes[0].center.x); + grad.inner.y = _cairo_fixed_16_16_from_double (extremes[0].center.y); + grad.inner.radius = _cairo_fixed_16_16_from_double (extremes[0].radius); + grad.outer.x = _cairo_fixed_16_16_from_double (extremes[1].center.x); + grad.outer.y = _cairo_fixed_16_16_from_double (extremes[1].center.y); + grad.outer.radius = _cairo_fixed_16_16_from_double (extremes[1].radius); + + picture = XRenderCreateRadialGradient (display->display, &grad, + stops, colors, + n_stops); + } + + if (stops != (XFixed *) buf) + free (stops); + + *src_x = *src_y = 0; + if (! picture_set_properties (display, picture, + &gradient->base, &gradient->base.matrix, + extents, + src_x, src_y)) { + XRenderFreePicture (display->display, picture); + return render_pattern (dst, &gradient->base, is_mask, extents, src_x, src_y); + } + + return source (dst, picture, None); +} + +static cairo_surface_t * +color_source (cairo_xlib_surface_t *dst, const cairo_color_t *color) +{ + Display *dpy = dst->display->display; + XRenderColor xcolor; + Picture picture; + Pixmap pixmap = None; + + xcolor.red = color->red_short; + xcolor.green = color->green_short; + xcolor.blue = color->blue_short; + xcolor.alpha = color->alpha_short; + + if (CAIRO_RENDER_HAS_GRADIENTS(dst->display)) { + picture = XRenderCreateSolidFill (dpy, &xcolor); + } else { + XRenderPictureAttributes pa; + int mask = 0; + + pa.repeat = RepeatNormal; + mask |= CPRepeat; + + pixmap = XCreatePixmap (dpy, dst->drawable, 1, 1, 32); + picture = XRenderCreatePicture (dpy, pixmap, + _cairo_xlib_display_get_xrender_format (dst->display, CAIRO_FORMAT_ARGB32), + mask, &pa); + + if (CAIRO_RENDER_HAS_FILL_RECTANGLES(dst->display)) { + XRectangle r = { 0, 0, 1, 1}; + XRenderFillRectangles (dpy, PictOpSrc, picture, &xcolor, &r, 1); + } else { + XGCValues gcv; + GC gc; + + gc = _cairo_xlib_screen_get_gc (dst->display, dst->screen, + 32, pixmap); + if (unlikely (gc == NULL)) { + XFreePixmap (dpy, pixmap); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + gcv.foreground = 0; + gcv.foreground |= color->alpha_short >> 8 << 24; + gcv.foreground |= color->red_short >> 8 << 16; + gcv.foreground |= color->green_short >> 8 << 8; + gcv.foreground |= color->blue_short >> 8 << 0; + gcv.fill_style = FillSolid; + + XChangeGC (dpy, gc, GCFillStyle | GCForeground, &gcv); + XFillRectangle (dpy, pixmap, gc, 0, 0, 1, 1); + + _cairo_xlib_screen_put_gc (dst->display, dst->screen, 32, gc); + } + } + + return source (dst, picture, pixmap); +} + +static cairo_surface_t * +alpha_source (cairo_xlib_surface_t *dst, uint8_t alpha) +{ + cairo_xlib_display_t *display = dst->display; + + if (display->alpha[alpha] == NULL) { + cairo_color_t color; + + color.red_short = color.green_short = color.blue_short = 0; + color.alpha_short = alpha << 8 | alpha; + + display->alpha[alpha] = color_source (dst, &color); + } + + return cairo_surface_reference (display->alpha[alpha]); +} + +static cairo_surface_t * +white_source (cairo_xlib_surface_t *dst) +{ + cairo_xlib_display_t *display = dst->display; + + if (display->white == NULL) + display->white = color_source (dst, CAIRO_COLOR_WHITE); + + return cairo_surface_reference (display->white); +} + +static cairo_surface_t * +opaque_source (cairo_xlib_surface_t *dst, const cairo_color_t *color) +{ + cairo_xlib_display_t *display = dst->display; + uint32_t pixel = + 0xff000000 | + color->red_short >> 8 << 16 | + color->green_short >> 8 << 8 | + color->blue_short >> 8 << 0; + int i; + + if (display->last_solid_cache[0].color == pixel) + return cairo_surface_reference (display->solid[display->last_solid_cache[0].index]); + + for (i = 0; i < 16; i++) { + if (display->solid_cache[i] == pixel) + goto done; + } + + i = hars_petruska_f54_1_random () % 16; + cairo_surface_destroy (display->solid[i]); + + display->solid[i] = color_source (dst, color); + display->solid_cache[i] = pixel; + +done: + display->last_solid_cache[0].color = pixel; + display->last_solid_cache[0].index = i; + return cairo_surface_reference (display->solid[i]); +} + +static cairo_surface_t * +transparent_source (cairo_xlib_surface_t *dst, const cairo_color_t *color) +{ + cairo_xlib_display_t *display = dst->display; + uint32_t pixel = + color->alpha_short >> 8 << 24 | + color->red_short >> 8 << 16 | + color->green_short >> 8 << 8 | + color->blue_short >> 8 << 0; + int i; + + if (display->last_solid_cache[1].color == pixel) { + assert (display->solid[display->last_solid_cache[1].index]); + return cairo_surface_reference (display->solid[display->last_solid_cache[1].index]); + } + + for (i = 16; i < 32; i++) { + if (display->solid_cache[i] == pixel) + goto done; + } + + i = 16 + (hars_petruska_f54_1_random () % 16); + cairo_surface_destroy (display->solid[i]); + + display->solid[i] = color_source (dst, color); + display->solid_cache[i] = pixel; + +done: + display->last_solid_cache[1].color = pixel; + display->last_solid_cache[1].index = i; + assert (display->solid[i]); + return cairo_surface_reference (display->solid[i]); +} + +static cairo_surface_t * +solid_source (cairo_xlib_surface_t *dst, + const cairo_color_t *color) +{ + if ((color->red_short | color->green_short | color->blue_short) <= 0xff) + return alpha_source (dst, color->alpha_short >> 8); + + if (CAIRO_ALPHA_SHORT_IS_OPAQUE (color->alpha_short)) { + if (color->red_short >= 0xff00 && color->green_short >= 0xff00 && color->blue_short >= 0xff00) + return white_source (dst); + + return opaque_source (dst, color); + } else + return transparent_source (dst, color); +} + +static cairo_xlib_source_t *init_source (cairo_xlib_surface_t *dst, + cairo_xlib_surface_t *src) +{ + Display *dpy = dst->display->display; + cairo_xlib_source_t *source = &src->embedded_source; + + /* As these are frequent and meant to be fast, we track pictures for + * native surface and minimise update requests. + */ + if (source->picture == None) { + XRenderPictureAttributes pa; + + _cairo_surface_init (&source->base, + &cairo_xlib_source_backend, + NULL, /* device */ + CAIRO_CONTENT_COLOR_ALPHA); + + pa.subwindow_mode = IncludeInferiors; + source->picture = XRenderCreatePicture (dpy, + src->drawable, + src->xrender_format, + CPSubwindowMode, &pa); + + source->has_component_alpha = 0; + source->has_matrix = 0; + source->filter = CAIRO_FILTER_NEAREST; + source->extend = CAIRO_EXTEND_NONE; + } + + return (cairo_xlib_source_t *) cairo_surface_reference (&source->base); +} + +static cairo_surface_t * +embedded_source (cairo_xlib_surface_t *dst, + const cairo_surface_pattern_t *pattern, + const cairo_rectangle_int_t *extents, + int *src_x, int *src_y, + cairo_xlib_source_t *source) +{ + Display *dpy = dst->display->display; + cairo_int_status_t status; + XTransform xtransform; + XRenderPictureAttributes pa; + unsigned mask = 0; + + status = _cairo_matrix_to_pixman_matrix_offset (&pattern->base.matrix, + pattern->base.filter, + extents->x + extents->width / 2, + extents->y + extents->height / 2, + (pixman_transform_t *)&xtransform, + src_x, src_y); + + if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) { + if (source->has_matrix) { + source->has_matrix = 0; + memcpy (&xtransform, &identity, sizeof (identity)); + status = CAIRO_INT_STATUS_SUCCESS; + } + } else + source->has_matrix = 1; + if (status == CAIRO_INT_STATUS_SUCCESS) + XRenderSetPictureTransform (dpy, source->picture, &xtransform); + + if (source->filter != pattern->base.filter) { + picture_set_filter (dpy, source->picture, pattern->base.filter); + source->filter = pattern->base.filter; + } + + if (source->has_component_alpha != pattern->base.has_component_alpha) { + pa.component_alpha = pattern->base.has_component_alpha; + mask |= CPComponentAlpha; + source->has_component_alpha = pattern->base.has_component_alpha; + } + + if (source->extend != pattern->base.extend) { + pa.repeat = extend_to_repeat (pattern->base.extend); + mask |= CPRepeat; + source->extend = pattern->base.extend; + } + + if (mask) + XRenderChangePicture (dpy, source->picture, mask, &pa); + + return &source->base; +} + +static cairo_surface_t * +subsurface_source (cairo_xlib_surface_t *dst, + const cairo_surface_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_surface_subsurface_t *sub; + cairo_xlib_surface_t *src; + cairo_xlib_source_t *source; + Display *dpy = dst->display->display; + cairo_int_status_t status; + cairo_surface_pattern_t local_pattern; + XTransform xtransform; + XRenderPictureAttributes pa; + unsigned mask = 0; + + sub = (cairo_surface_subsurface_t *) pattern->surface; + + if (sample->x >= 0 && sample->y >= 0 && + sample->x + sample->width <= sub->extents.width && + sample->y + sample->height <= sub->extents.height) + { + src = (cairo_xlib_surface_t *) sub->target; + status = _cairo_surface_flush (&src->base, 0); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (pattern->base.filter == CAIRO_FILTER_NEAREST && + _cairo_matrix_is_translation (&pattern->base.matrix)) + { + *src_x += pattern->base.matrix.x0 + sub->extents.x; + *src_y += pattern->base.matrix.y0 + sub->extents.y; + + _cairo_xlib_surface_ensure_picture (src); + return cairo_surface_reference (&src->base); + } + else + { + cairo_surface_pattern_t local_pattern = *pattern; + local_pattern.base.matrix.x0 += sub->extents.x; + local_pattern.base.matrix.y0 += sub->extents.y; + local_pattern.base.extend = CAIRO_EXTEND_NONE; + return embedded_source (dst, &local_pattern, extents, + src_x, src_y, init_source (dst, src)); + } + } + + if (sub->snapshot && sub->snapshot->type == CAIRO_SURFACE_TYPE_XLIB) { + src = (cairo_xlib_surface_t *) cairo_surface_reference (sub->snapshot); + source = &src->embedded_source; + } else { + src = (cairo_xlib_surface_t *) + _cairo_surface_create_scratch (&dst->base, + sub->base.content, + sub->extents.width, + sub->extents.height, + NULL); + if (src->base.type != CAIRO_SURFACE_TYPE_XLIB) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_pattern_init_for_surface (&local_pattern, sub->target); + cairo_matrix_init_translate (&local_pattern.base.matrix, + sub->extents.x, sub->extents.y); + local_pattern.base.filter = CAIRO_FILTER_NEAREST; + status = _cairo_surface_paint (&src->base, + CAIRO_OPERATOR_SOURCE, + &local_pattern.base, + NULL); + _cairo_pattern_fini (&local_pattern.base); + + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (status); + } + + _cairo_xlib_surface_ensure_picture (src); + _cairo_surface_subsurface_set_snapshot (&sub->base, &src->base); + + source = &src->embedded_source; + source->has_component_alpha = 0; + source->has_matrix = 0; + source->filter = CAIRO_FILTER_NEAREST; + source->extend = CAIRO_EXTEND_NONE; + } + + status = _cairo_matrix_to_pixman_matrix_offset (&pattern->base.matrix, + pattern->base.filter, + extents->x + extents->width / 2, + extents->y + extents->height / 2, + (pixman_transform_t *)&xtransform, + src_x, src_y); + if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) { + if (source->has_matrix) { + source->has_matrix = 0; + memcpy (&xtransform, &identity, sizeof (identity)); + status = CAIRO_INT_STATUS_SUCCESS; + } + } else + source->has_matrix = 1; + if (status == CAIRO_INT_STATUS_SUCCESS) + XRenderSetPictureTransform (dpy, src->picture, &xtransform); + + if (source->filter != pattern->base.filter) { + picture_set_filter (dpy, src->picture, pattern->base.filter); + source->filter = pattern->base.filter; + } + + if (source->has_component_alpha != pattern->base.has_component_alpha) { + pa.component_alpha = pattern->base.has_component_alpha; + mask |= CPComponentAlpha; + source->has_component_alpha = pattern->base.has_component_alpha; + } + + if (source->extend != pattern->base.extend) { + pa.repeat = extend_to_repeat (pattern->base.extend); + mask |= CPRepeat; + source->extend = pattern->base.extend; + } + + if (mask) + XRenderChangePicture (dpy, src->picture, mask, &pa); + + return &src->base; +} + +static cairo_surface_t * +native_source (cairo_xlib_surface_t *dst, + const cairo_surface_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_xlib_surface_t *src; + cairo_int_status_t status; + + if (_cairo_surface_is_subsurface (pattern->surface)) + return subsurface_source (dst, pattern, is_mask, + extents, sample, + src_x, src_y); + + src = unwrap_source (pattern); + status = _cairo_surface_flush (&src->base, 0); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + if (pattern->base.filter == CAIRO_FILTER_NEAREST && + sample->x >= 0 && sample->y >= 0 && + sample->x + sample->width <= src->width && + sample->y + sample->height <= src->height && + _cairo_matrix_is_translation (&pattern->base.matrix)) + { + *src_x += pattern->base.matrix.x0; + *src_y += pattern->base.matrix.y0; + _cairo_xlib_surface_ensure_picture (src); + return cairo_surface_reference (&src->base); + } + + return embedded_source (dst, pattern, extents, src_x, src_y, + init_source (dst, src)); +} + +static cairo_surface_t * +recording_pattern_get_surface (const cairo_pattern_t *pattern) +{ + cairo_surface_t *surface; + + surface = ((const cairo_surface_pattern_t *) pattern)->surface; + + if (_cairo_surface_is_paginated (surface)) + return cairo_surface_reference (_cairo_paginated_surface_get_recording (surface)); + + if (_cairo_surface_is_snapshot (surface)) + return _cairo_surface_snapshot_get_target (surface); + + return cairo_surface_reference (surface); +} + +static cairo_surface_t * +record_source (cairo_xlib_surface_t *dst, + const cairo_surface_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_xlib_surface_t *src; + cairo_surface_t *recording; + cairo_matrix_t matrix, m; + cairo_status_t status; + cairo_rectangle_int_t upload, limit; + + upload = *sample; + if (_cairo_surface_get_extents (pattern->surface, &limit) && + ! _cairo_rectangle_intersect (&upload, &limit)) + { + if (pattern->base.extend == CAIRO_EXTEND_NONE) + return alpha_source (dst, 0); + + upload = limit; + } + + src = (cairo_xlib_surface_t *) + _cairo_surface_create_scratch (&dst->base, + pattern->surface->content, + upload.width, + upload.height, + NULL); + if (src->base.type != CAIRO_SURFACE_TYPE_XLIB) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + cairo_matrix_init_translate (&matrix, upload.x, upload.y); + recording = recording_pattern_get_surface (&pattern->base), + status = _cairo_recording_surface_replay_with_clip (recording, + &matrix, &src->base, + NULL); + cairo_surface_destroy (recording); + if (unlikely (status)) { + cairo_surface_destroy (&src->base); + return _cairo_surface_create_in_error (status); + } + + matrix = pattern->base.matrix; + if (upload.x | upload.y) { + cairo_matrix_init_translate (&m, -upload.x, -upload.y); + cairo_matrix_multiply (&matrix, &matrix, &m); + } + + _cairo_xlib_surface_ensure_picture (src); + if (! picture_set_properties (src->display, src->picture, + &pattern->base, &matrix, extents, + src_x, src_y)) + { + cairo_surface_destroy (&src->base); + return render_pattern (dst, &pattern->base, is_mask, + extents, src_x, src_y); + } + + return &src->base; +} + +static cairo_surface_t * +surface_source (cairo_xlib_surface_t *dst, + const cairo_surface_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_surface_t *src; + cairo_xlib_surface_t *xsrc; + cairo_surface_pattern_t local_pattern; + cairo_status_t status; + cairo_rectangle_int_t upload, limit; + + src = pattern->surface; + if (src->type == CAIRO_SURFACE_TYPE_IMAGE && + src->device == dst->base.device && + _cairo_xlib_shm_surface_get_pixmap (src)) { + cairo_xlib_proxy_t *proxy; + + proxy = malloc (sizeof(*proxy)); + if (unlikely (proxy == NULL)) + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_surface_init (&proxy->source.base, + &cairo_xlib_proxy_backend, + dst->base.device, + src->content); + + proxy->source.dpy = dst->display->display; + proxy->source.picture = XRenderCreatePicture (proxy->source.dpy, + _cairo_xlib_shm_surface_get_pixmap (src), + _cairo_xlib_shm_surface_get_xrender_format (src), + 0, NULL); + proxy->source.pixmap = None; + + proxy->source.has_component_alpha = 0; + proxy->source.has_matrix = 0; + proxy->source.filter = CAIRO_FILTER_NEAREST; + proxy->source.extend = CAIRO_EXTEND_NONE; + proxy->owner = cairo_surface_reference (src); + + return embedded_source (dst, pattern, extents, src_x, src_y, + &proxy->source); + } + + upload = *sample; + if (_cairo_surface_get_extents (pattern->surface, &limit)) { + if (pattern->base.extend == CAIRO_EXTEND_NONE) { + if (! _cairo_rectangle_intersect (&upload, &limit)) + return alpha_source (dst, 0); + } else if (pattern->base.extend == CAIRO_EXTEND_PAD) { + if (! _cairo_rectangle_intersect (&upload, &limit)) + upload = limit; + } else { + if (upload.x < limit.x || + upload.x + upload.width > limit.x + limit.width || + upload.y < limit.y || + upload.y + upload.height > limit.y + limit.height) + { + upload = limit; + } + } + } + + xsrc = (cairo_xlib_surface_t *) + _cairo_surface_create_scratch (&dst->base, + src->content, + upload.width, + upload.height, + NULL); + if (xsrc->base.type != CAIRO_SURFACE_TYPE_XLIB) { + cairo_surface_destroy (src); + cairo_surface_destroy (&xsrc->base); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + if (_cairo_surface_is_image (src)) { + status = _cairo_xlib_surface_draw_image (xsrc, (cairo_image_surface_t *)src, + upload.x, upload.y, + upload.width, upload.height, + 0, 0); + } else { + cairo_image_surface_t *image; + cairo_rectangle_int_t map_extents = { 0,0, upload.width,upload.height }; + + image = _cairo_surface_map_to_image (&xsrc->base, &map_extents); + + _cairo_pattern_init_for_surface (&local_pattern, pattern->surface); + cairo_matrix_init_translate (&local_pattern.base.matrix, + upload.x, upload.y); + + status = _cairo_surface_paint (&image->base, + CAIRO_OPERATOR_SOURCE, + &local_pattern.base, + NULL); + _cairo_pattern_fini (&local_pattern.base); + + status = _cairo_surface_unmap_image (&xsrc->base, image); + if (unlikely (status)) { + cairo_surface_destroy (&xsrc->base); + return _cairo_surface_create_in_error (status); + } + + status = _cairo_xlib_surface_put_shm (xsrc); + if (unlikely (status)) { + cairo_surface_destroy (&xsrc->base); + return _cairo_surface_create_in_error (status); + } + } + + _cairo_pattern_init_static_copy (&local_pattern.base, &pattern->base); + if (upload.x | upload.y) { + cairo_matrix_t m; + cairo_matrix_init_translate (&m, -upload.x, -upload.y); + cairo_matrix_multiply (&local_pattern.base.matrix, + &local_pattern.base.matrix, + &m); + } + + *src_x = *src_y = 0; + _cairo_xlib_surface_ensure_picture (xsrc); + if (! picture_set_properties (xsrc->display, + xsrc->picture, + &local_pattern.base, + &local_pattern.base.matrix, + extents, + src_x, src_y)) + { + cairo_surface_destroy (&xsrc->base); + return render_pattern (dst, &pattern->base, + is_mask, extents, + src_x, src_y); + } + + return &xsrc->base; +} + +static cairo_bool_t +pattern_is_supported (cairo_xlib_display_t *display, + const cairo_pattern_t *pattern) +{ + if (pattern->type == CAIRO_PATTERN_TYPE_MESH) + return FALSE; + + if (display->buggy_pad_reflect) { + if (pattern->extend == CAIRO_EXTEND_REPEAT || pattern->extend == CAIRO_EXTEND_PAD) + return FALSE; + } + + if (display->buggy_gradients) { + if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || pattern->type == CAIRO_PATTERN_TYPE_RADIAL) + return FALSE; + } + + switch (pattern->filter) { + case CAIRO_FILTER_FAST: + case CAIRO_FILTER_NEAREST: + return CAIRO_RENDER_HAS_PICTURE_TRANSFORM (display) || + _cairo_matrix_is_integer_translation (&pattern->matrix, NULL, NULL); + case CAIRO_FILTER_GOOD: + return CAIRO_RENDER_HAS_FILTER_GOOD (display); + case CAIRO_FILTER_BEST: + return CAIRO_RENDER_HAS_FILTER_BEST (display); + case CAIRO_FILTER_BILINEAR: + case CAIRO_FILTER_GAUSSIAN: + default: + return CAIRO_RENDER_HAS_FILTERS (display); + } +} + +cairo_surface_t * +_cairo_xlib_source_create_for_pattern (cairo_surface_t *_dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + cairo_xlib_surface_t *dst = (cairo_xlib_surface_t *)_dst; + + *src_x = *src_y = 0; + + if (pattern == NULL || pattern->type == CAIRO_PATTERN_TYPE_SOLID) { + if (pattern == NULL) + pattern = &_cairo_pattern_white.base; + + return solid_source (dst, &((cairo_solid_pattern_t *)pattern)->color); + } + + if (pattern_is_supported (dst->display, pattern)) { + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { + cairo_surface_pattern_t *spattern = (cairo_surface_pattern_t *)pattern; + if (spattern->surface->type == CAIRO_SURFACE_TYPE_XLIB && + _cairo_xlib_surface_same_screen (dst, + unwrap_source (spattern))) + return native_source (dst, spattern, is_mask, + extents, sample, + src_x, src_y); + + if (spattern->surface->type == CAIRO_SURFACE_TYPE_RECORDING) + return record_source (dst, spattern, is_mask, + extents, sample, + src_x, src_y); + + return surface_source (dst, spattern, is_mask, + extents, sample, + src_x, src_y); + } + + if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR || + pattern->type == CAIRO_PATTERN_TYPE_RADIAL) + { + cairo_gradient_pattern_t *gpattern = (cairo_gradient_pattern_t *)pattern; + return gradient_source (dst, gpattern, is_mask, extents, src_x, src_y); + } + } + + return render_pattern (dst, pattern, is_mask, extents, src_x, src_y); +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-private.h new file mode 100644 index 00000000000..83d9b63cc4c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-private.h @@ -0,0 +1,44 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + */ + +#ifndef CAIRO_XLIB_SURFACE_PRIVATE_H +#define CAIRO_XLIB_SURFACE_PRIVATE_H + +#include "cairo-xlib-xrender-private.h" +#include "cairo-xlib.h" +#include "cairo-xlib-private.h" + +#include "cairo-surface-private.h" +#include "cairo-surface-backend-private.h" + + +#endif /* CAIRO_XLIB_SURFACE_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-shm.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-shm.c new file mode 100644 index 00000000000..fb40699dc1d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface-shm.c @@ -0,0 +1,1459 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" +#include "cairo-xlib-surface-private.h" + +#if !HAVE_X11_EXTENSIONS_XSHM_H || !(HAVE_X11_EXTENSIONS_SHMPROTO_H || HAVE_X11_EXTENSIONS_SHMSTR_H) +void _cairo_xlib_display_init_shm (cairo_xlib_display_t *display) {} + +cairo_surface_t * +_cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface, + cairo_bool_t overwrite) +{ + return NULL; +} + +cairo_int_status_t +_cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface) +{ + assert (!surface->fallback); + return CAIRO_INT_STATUS_SUCCESS; +} + +cairo_surface_t * +_cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other, + pixman_format_code_t format, + int width, int height) +{ + return NULL; +} + +cairo_surface_t * +_cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface, + pixman_format_code_t format, + int width, int height) +{ + return NULL; +} + +cairo_surface_t * +_cairo_xlib_surface_create_similar_shm (void *other, + cairo_format_t format, + int width, int height) +{ + return cairo_image_surface_create (format, width, height); +} + +void +_cairo_xlib_shm_surface_mark_active (cairo_surface_t *_shm) +{ + ASSERT_NOT_REACHED; +} + +void +_cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface, + XImage *ximage) +{ + ASSERT_NOT_REACHED; +} + +void * +_cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface) +{ + ASSERT_NOT_REACHED; + return NULL; +} + +Pixmap +_cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface) +{ + ASSERT_NOT_REACHED; + return 0; +} + +XRenderPictFormat * +_cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface) +{ + ASSERT_NOT_REACHED; + return NULL; +} + +cairo_bool_t +_cairo_xlib_shm_surface_is_active (cairo_surface_t *surface) +{ + ASSERT_NOT_REACHED; + return FALSE; +} + +cairo_bool_t +_cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface) +{ + ASSERT_NOT_REACHED; + return TRUE; +} + +void _cairo_xlib_display_fini_shm (cairo_xlib_display_t *display) {} + +#else + +#include "cairo-damage-private.h" +#include "cairo-default-context-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-mempool-private.h" + +#include +#include +#include +#if HAVE_X11_EXTENSIONS_SHMPROTO_H +#include +#elif HAVE_X11_EXTENSIONS_SHMSTR_H +#include +#endif +#include +#include + +#define MIN_PIXMAP_SIZE 4096 + +#define MIN_BITS 8 +#define MIN_SIZE (1<<(MIN_BITS-1)) + +typedef struct _cairo_xlib_shm cairo_xlib_shm_t; +typedef struct _cairo_xlib_shm_info cairo_xlib_shm_info_t; +typedef struct _cairo_xlib_shm_surface cairo_xlib_shm_surface_t; + +struct _cairo_xlib_shm { + cairo_mempool_t mem; + + XShmSegmentInfo shm; + unsigned long attached; + cairo_list_t link; +}; + +struct _cairo_xlib_shm_info { + unsigned long last_request; + void *mem; + size_t size; + cairo_xlib_shm_t *pool; +}; + +struct _cairo_xlib_shm_surface { + cairo_image_surface_t image; + + cairo_list_t link; + cairo_xlib_shm_info_t *info; + Pixmap pixmap; + unsigned long active; + int idle; +}; + +/* the parent is always given by index/2 */ +#define PQ_PARENT_INDEX(i) ((i) >> 1) +#define PQ_FIRST_ENTRY 1 + +/* left and right children are index * 2 and (index * 2) +1 respectively */ +#define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) + +#define PQ_TOP(pq) ((pq)->elements[PQ_FIRST_ENTRY]) + +struct pqueue { + int size, max_size; + cairo_xlib_shm_info_t **elements; +}; + +struct _cairo_xlib_shm_display { + int has_pixmaps; + int opcode; + int event; + + Window window; + unsigned long last_request; + unsigned long last_event; + + cairo_list_t surfaces; + + cairo_list_t pool; + struct pqueue info; +}; + +static inline cairo_bool_t +seqno_passed (unsigned long a, unsigned long b) +{ + return (long)(b - a) >= 0; +} + +static inline cairo_bool_t +seqno_before (unsigned long a, unsigned long b) +{ + return (long)(b - a) > 0; +} + +static inline cairo_bool_t +seqno_after (unsigned long a, unsigned long b) +{ + return (long)(a - b) > 0; +} + +static inline cairo_status_t +_pqueue_init (struct pqueue *pq) +{ + pq->max_size = 32; + pq->size = 0; + + pq->elements = _cairo_malloc_ab (pq->max_size, + sizeof (cairo_xlib_shm_info_t *)); + if (unlikely (pq->elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + PQ_TOP(pq) = NULL; + return CAIRO_STATUS_SUCCESS; +} + +static inline void +_pqueue_fini (struct pqueue *pq) +{ + free (pq->elements); +} + +static cairo_status_t +_pqueue_grow (struct pqueue *pq) +{ + cairo_xlib_shm_info_t **new_elements; + + new_elements = _cairo_realloc_ab (pq->elements, + 2 * pq->max_size, + sizeof (cairo_xlib_shm_info_t *)); + if (unlikely (new_elements == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + pq->elements = new_elements; + pq->max_size *= 2; + return CAIRO_STATUS_SUCCESS; +} + +static void +_pqueue_shrink (struct pqueue *pq, int min_size) +{ + cairo_xlib_shm_info_t **new_elements; + + if (min_size > pq->max_size) + return; + + new_elements = _cairo_realloc_ab (pq->elements, + min_size, + sizeof (cairo_xlib_shm_info_t *)); + if (unlikely (new_elements == NULL)) + return; + + pq->elements = new_elements; + pq->max_size = min_size; +} + +static inline cairo_status_t +_pqueue_push (struct pqueue *pq, cairo_xlib_shm_info_t *info) +{ + cairo_xlib_shm_info_t **elements; + int i, parent; + + if (unlikely (pq->size + 1 == pq->max_size)) { + cairo_status_t status; + + status = _pqueue_grow (pq); + if (unlikely (status)) + return status; + } + + elements = pq->elements; + + for (i = ++pq->size; + i != PQ_FIRST_ENTRY && + info->last_request < elements[parent = PQ_PARENT_INDEX (i)]->last_request; + i = parent) + { + elements[i] = elements[parent]; + } + + elements[i] = info; + + return CAIRO_STATUS_SUCCESS; +} + +static inline void +_pqueue_pop (struct pqueue *pq) +{ + cairo_xlib_shm_info_t **elements = pq->elements; + cairo_xlib_shm_info_t *tail; + int child, i; + + tail = elements[pq->size--]; + if (pq->size == 0) { + elements[PQ_FIRST_ENTRY] = NULL; + _pqueue_shrink (pq, 32); + return; + } + + for (i = PQ_FIRST_ENTRY; + (child = PQ_LEFT_CHILD_INDEX (i)) <= pq->size; + i = child) + { + if (child != pq->size && + elements[child+1]->last_request < elements[child]->last_request) + { + child++; + } + + if (elements[child]->last_request >= tail->last_request) + break; + + elements[i] = elements[child]; + } + elements[i] = tail; +} + +static cairo_bool_t _x_error_occurred; + +static int +_check_error_handler (Display *display, + XErrorEvent *event) +{ + _x_error_occurred = TRUE; + return False; /* ignored */ +} + +static cairo_bool_t +can_use_shm (Display *dpy, int *has_pixmap) +{ + XShmSegmentInfo shm; + int (*old_handler) (Display *display, XErrorEvent *event); + Status success; + int major, minor; + + if (! XShmQueryExtension (dpy)) + return FALSE; + + XShmQueryVersion (dpy, &major, &minor, has_pixmap); + + shm.shmid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | 0600); + if (shm.shmid == -1) + return FALSE; + + shm.readOnly = FALSE; + shm.shmaddr = shmat (shm.shmid, NULL, 0); + if (shm.shmaddr == (char *) -1) { + shmctl (shm.shmid, IPC_RMID, NULL); + return FALSE; + } + + assert (CAIRO_MUTEX_IS_LOCKED (_cairo_xlib_display_mutex)); + _x_error_occurred = FALSE; + + XLockDisplay (dpy); + XSync (dpy, False); + old_handler = XSetErrorHandler (_check_error_handler); + + success = XShmAttach (dpy, &shm); + if (success) + XShmDetach (dpy, &shm); + + XSync (dpy, False); + XSetErrorHandler (old_handler); + XUnlockDisplay (dpy); + + shmctl (shm.shmid, IPC_RMID, NULL); + shmdt (shm.shmaddr); + + return success && ! _x_error_occurred; +} + +static inline Display * +peek_display (cairo_device_t *device) +{ + return ((cairo_xlib_display_t *)device)->display; +} + +static inline unsigned long +peek_processed (cairo_device_t *device) +{ + return LastKnownRequestProcessed (peek_display(device)); +} + +static void +_cairo_xlib_display_shm_pool_destroy (cairo_xlib_display_t *display, + cairo_xlib_shm_t *pool) +{ + shmdt (pool->shm.shmaddr); + if (display->display) /* may be called after CloseDisplay */ + XShmDetach (display->display, &pool->shm); + + _cairo_mempool_fini (&pool->mem); + + cairo_list_del (&pool->link); + free (pool); +} + +static void send_event(cairo_xlib_display_t *display, + cairo_xlib_shm_info_t *info, + unsigned long seqno) +{ + XShmCompletionEvent ev; + + if (! seqno_after (seqno, display->shm->last_event)) + return; + + ev.type = display->shm->event; + ev.send_event = 1; /* XXX or lie? */ + ev.serial = NextRequest (display->display); + ev.drawable = display->shm->window; + ev.major_code = display->shm->opcode; + ev.minor_code = X_ShmPutImage; + ev.shmseg = info->pool->shm.shmid; + ev.offset = (char *)info->mem - (char *)info->pool->shm.shmaddr; + + XSendEvent (display->display, ev.drawable, False, 0, (XEvent *)&ev); + + display->shm->last_event = ev.serial; +} + +static void _cairo_xlib_display_sync (cairo_xlib_display_t *display) +{ + cairo_xlib_shm_info_t *info; + struct pqueue *pq = &display->shm->info; + + XSync (display->display, False); + + while ((info = PQ_TOP(pq))) { + _cairo_mempool_free (&info->pool->mem, info->mem); + _pqueue_pop (&display->shm->info); + free (info); + } +} + +static void +_cairo_xlib_shm_info_cleanup (cairo_xlib_display_t *display) +{ + cairo_xlib_shm_info_t *info; + Display *dpy = display->display; + struct pqueue *pq = &display->shm->info; + unsigned long processed; + + if (PQ_TOP(pq) == NULL) + return; + + XEventsQueued (dpy, QueuedAfterReading); + processed = LastKnownRequestProcessed (dpy); + + info = PQ_TOP(pq); + do { + if (! seqno_passed (info->last_request, processed)) { + send_event (display, info, display->shm->last_request); + return; + } + + _cairo_mempool_free (&info->pool->mem, info->mem); + _pqueue_pop (&display->shm->info); + free (info); + } while ((info = PQ_TOP(pq))); +} + +static cairo_xlib_shm_t * +_cairo_xlib_shm_info_find (cairo_xlib_display_t *display, size_t size, + void **ptr, unsigned long *last_request) +{ + cairo_xlib_shm_info_t *info; + struct pqueue *pq = &display->shm->info; + + if (PQ_TOP(pq) == NULL) + return NULL; + + info = PQ_TOP(pq); + do { + cairo_xlib_shm_t *pool = info->pool; + + *last_request = info->last_request; + + _pqueue_pop (&display->shm->info); + _cairo_mempool_free (&pool->mem, info->mem); + free (info); + + if (pool->mem.free_bytes >= size) { + void *mem = _cairo_mempool_alloc (&pool->mem, size); + if (mem != NULL) { + *ptr = mem; + return pool; + } + } + } while ((info = PQ_TOP(pq))); + + return NULL; +} + +static cairo_xlib_shm_t * +_cairo_xlib_shm_pool_find (cairo_xlib_display_t *display, + size_t size, + void **ptr) +{ + cairo_xlib_shm_t *pool; + + cairo_list_foreach_entry (pool, cairo_xlib_shm_t, &display->shm->pool, link) { + if (pool->mem.free_bytes >= size) { + void *mem = _cairo_mempool_alloc (&pool->mem, size); + if (mem != NULL) { + *ptr = mem; + return pool; + } + } + } + + return NULL; +} + +static void +_cairo_xlib_shm_pool_cleanup (cairo_xlib_display_t *display) +{ + cairo_xlib_shm_t *pool, *next; + unsigned long processed; + + processed = LastKnownRequestProcessed (display->display); + + cairo_list_foreach_entry_safe (pool, next, cairo_xlib_shm_t, + &display->shm->pool, link) { + if (! seqno_passed (pool->attached, processed)) + break; + + if (pool->mem.free_bytes == pool->mem.max_bytes) + _cairo_xlib_display_shm_pool_destroy (display, pool); + } +} + +static cairo_xlib_shm_t * +_cairo_xlib_shm_pool_create(cairo_xlib_display_t *display, + size_t size, void **ptr) +{ + Display *dpy = display->display; + cairo_xlib_shm_t *pool; + size_t bytes, maxbits = 16, minbits = MIN_BITS; + Status success; + + pool = malloc (sizeof (cairo_xlib_shm_t)); + if (pool == NULL) + return NULL; + + bytes = 1 << maxbits; + while (bytes <= size) + bytes <<= 1, maxbits++; + bytes <<= 3; + + minbits += (maxbits - 16) / 2; + + pool->shm.shmid = shmget (IPC_PRIVATE, bytes, IPC_CREAT | 0600); + while (pool->shm.shmid == -1 && bytes >= 2*size) { + bytes >>= 1; + pool->shm.shmid = shmget (IPC_PRIVATE, bytes, IPC_CREAT | 0600); + } + if (pool->shm.shmid == -1) + goto cleanup; + + pool->shm.readOnly = FALSE; + pool->shm.shmaddr = shmat (pool->shm.shmid, NULL, 0); + if (pool->shm.shmaddr == (char *) -1) { + shmctl (pool->shm.shmid, IPC_RMID, NULL); + goto cleanup; + } + + pool->attached = NextRequest (dpy); + success = XShmAttach (dpy, &pool->shm); +#if !IPC_RMID_DEFERRED_RELEASE + XSync (dpy, FALSE); +#endif + shmctl (pool->shm.shmid, IPC_RMID, NULL); + + if (! success) + goto cleanup_shm; + + if (_cairo_mempool_init (&pool->mem, pool->shm.shmaddr, bytes, + minbits, maxbits - minbits + 1)) + goto cleanup_detach; + + cairo_list_add (&pool->link, &display->shm->pool); + + *ptr = _cairo_mempool_alloc (&pool->mem, size); + assert (*ptr != NULL); + return pool; + +cleanup_detach: + XShmDetach (dpy, &pool->shm); +cleanup_shm: + shmdt (pool->shm.shmaddr); +cleanup: + free (pool); + return NULL; +} + +static cairo_xlib_shm_info_t * +_cairo_xlib_shm_info_create (cairo_xlib_display_t *display, + size_t size, cairo_bool_t will_sync) +{ + cairo_xlib_shm_info_t *info; + cairo_xlib_shm_t *pool; + unsigned long last_request = 0; + void *mem = NULL; + + _cairo_xlib_shm_info_cleanup (display); + pool = _cairo_xlib_shm_pool_find (display, size, &mem); + _cairo_xlib_shm_pool_cleanup (display); + + if (pool == NULL && will_sync) + pool = _cairo_xlib_shm_info_find (display, size, &mem, &last_request); + if (pool == NULL) + pool = _cairo_xlib_shm_pool_create (display, size, &mem); + if (pool == NULL) + return NULL; + + assert (mem != NULL); + + info = malloc (sizeof (*info)); + if (info == NULL) { + _cairo_mempool_free (&pool->mem, mem); + return NULL; + } + + info->pool = pool; + info->mem = mem; + info->size = size; + info->last_request = last_request; + + return info; +} + +static cairo_status_t +_cairo_xlib_shm_surface_flush (void *abstract_surface, unsigned flags) +{ + cairo_xlib_shm_surface_t *shm = abstract_surface; + cairo_xlib_display_t *display; + Display *dpy; + cairo_status_t status; + + if (shm->active == 0) + return CAIRO_STATUS_SUCCESS; + + if (shm->image.base._finishing) + return CAIRO_STATUS_SUCCESS; + + if (seqno_passed (shm->active, peek_processed (shm->image.base.device))) { + shm->active = 0; + return CAIRO_STATUS_SUCCESS; + } + + status = _cairo_xlib_display_acquire (shm->image.base.device, &display); + if (unlikely (status)) + return status; + + send_event (display, shm->info, shm->active); + + dpy = display->display; + XEventsQueued (dpy, QueuedAfterReading); + while (! seqno_passed (shm->active, LastKnownRequestProcessed (dpy))) { + LockDisplay(dpy); + _XReadEvents(dpy); + UnlockDisplay(dpy); + } + + cairo_device_release (&display->base); + shm->active = 0; + + return CAIRO_STATUS_SUCCESS; +} + +static inline cairo_bool_t +active (cairo_xlib_shm_surface_t *shm, Display *dpy) +{ + return (shm->active && + ! seqno_passed (shm->active, LastKnownRequestProcessed (dpy))); +} + +static cairo_status_t +_cairo_xlib_shm_surface_finish (void *abstract_surface) +{ + cairo_xlib_shm_surface_t *shm = abstract_surface; + cairo_xlib_display_t *display; + cairo_status_t status; + + if (shm->image.base.damage) { + _cairo_damage_destroy (shm->image.base.damage); + shm->image.base.damage = _cairo_damage_create_in_error (CAIRO_STATUS_SURFACE_FINISHED); + } + + status = _cairo_xlib_display_acquire (shm->image.base.device, &display); + if (unlikely (status)) + return status; + + if (shm->pixmap) + XFreePixmap (display->display, shm->pixmap); + + if (active (shm, display->display)) { + shm->info->last_request = shm->active; + _pqueue_push (&display->shm->info, shm->info); + if (seqno_before (display->shm->last_request, shm->active)) + display->shm->last_request = shm->active; + } else { + _cairo_mempool_free (&shm->info->pool->mem, shm->info->mem); + free (shm->info); + + _cairo_xlib_shm_pool_cleanup (display); + } + + cairo_list_del (&shm->link); + + cairo_device_release (&display->base); + return _cairo_image_surface_finish (abstract_surface); +} + +static const cairo_surface_backend_t cairo_xlib_shm_surface_backend = { + CAIRO_SURFACE_TYPE_IMAGE, + _cairo_xlib_shm_surface_finish, + + _cairo_default_context_create, + + _cairo_image_surface_create_similar, + NULL, /* create similar image */ + _cairo_image_surface_map_to_image, + _cairo_image_surface_unmap_image, + + _cairo_image_surface_source, + _cairo_image_surface_acquire_source_image, + _cairo_image_surface_release_source_image, + _cairo_image_surface_snapshot, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_image_surface_get_extents, + _cairo_image_surface_get_font_options, + + _cairo_xlib_shm_surface_flush, + NULL, + + _cairo_image_surface_paint, + _cairo_image_surface_mask, + _cairo_image_surface_stroke, + _cairo_image_surface_fill, + NULL, /* fill-stroke */ + _cairo_image_surface_glyphs, +}; + +static cairo_bool_t +has_shm (cairo_xlib_surface_t *surface) +{ + cairo_xlib_display_t *display = (cairo_xlib_display_t *)surface->base.device; + return display->shm != NULL; +} + +static int +has_shm_pixmaps (cairo_xlib_surface_t *surface) +{ + cairo_xlib_display_t *display = (cairo_xlib_display_t *)surface->base.device; + if (!display->shm) + return 0; + + return display->shm->has_pixmaps; +} + +static cairo_xlib_shm_surface_t * +_cairo_xlib_shm_surface_create (cairo_xlib_surface_t *other, + pixman_format_code_t format, + int width, int height, + cairo_bool_t will_sync, + int create_pixmap) +{ + cairo_xlib_shm_surface_t *shm; + cairo_xlib_display_t *display; + pixman_image_t *image; + int stride, size; + + stride = CAIRO_STRIDE_FOR_WIDTH_BPP (width, PIXMAN_FORMAT_BPP(format)); + size = stride * height; + if (size < MIN_SIZE) + return NULL; + + shm = malloc (sizeof (*shm)); + if (unlikely (shm == NULL)) + return (cairo_xlib_shm_surface_t *)_cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_surface_init (&shm->image.base, + &cairo_xlib_shm_surface_backend, + other->base.device, + _cairo_content_from_pixman_format (format)); + + if (_cairo_xlib_display_acquire (other->base.device, &display)) + goto cleanup_shm; + + shm->info = _cairo_xlib_shm_info_create (display, size, will_sync); + if (shm->info == NULL) + goto cleanup_display; + + image = pixman_image_create_bits (format, width, height, + (uint32_t *) shm->info->mem, stride); + if (image == NULL) + goto cleanup_info; + + _cairo_image_surface_init (&shm->image, image, format); + + shm->pixmap = 0; + if (create_pixmap && size >= create_pixmap) { + shm->pixmap = XShmCreatePixmap (display->display, + other->drawable, + shm->info->mem, + &shm->info->pool->shm, + shm->image.width, + shm->image.height, + shm->image.depth); + } + shm->active = shm->info->last_request; + shm->idle = -5; + + assert (shm->active == 0 || will_sync); + + cairo_list_add (&shm->link, &display->shm->surfaces); + + cairo_device_release (&display->base); + + return shm; + +cleanup_info: + _cairo_mempool_free (&shm->info->pool->mem, shm->info->mem); + free(shm->info); +cleanup_display: + cairo_device_release (&display->base); +cleanup_shm: + free (shm); + return NULL; +} + +static void +_cairo_xlib_surface_update_shm (cairo_xlib_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface->shm; + cairo_xlib_display_t *display; + cairo_damage_t *damage; + GC gc; + + damage = _cairo_damage_reduce (surface->base.damage); + surface->base.damage = _cairo_damage_create(); + + if (_cairo_xlib_display_acquire (surface->base.device, &display)) + goto cleanup_damage; + + if (_cairo_xlib_surface_get_gc (display, surface, &gc)) + goto cleanup_display; + + if (! surface->owns_pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = IncludeInferiors; + XChangeGC (display->display, gc, GCSubwindowMode, &gcv); + } + + if (damage->region) { + XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *rects = stack_rects; + cairo_rectangle_int_t r; + int n_rects, i; + + n_rects = cairo_region_num_rectangles (damage->region); + if (n_rects == 0) { + } else if (n_rects == 1) { + cairo_region_get_rectangle (damage->region, 0, &r); + XCopyArea (display->display, + surface->drawable, shm->pixmap, gc, + r.x, r.y, + r.width, r.height, + r.x, r.y); + } else { + if (n_rects > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle)); + if (unlikely (rects == NULL)) { + rects = stack_rects; + n_rects = ARRAY_LENGTH (stack_rects); + } + } + for (i = 0; i < n_rects; i++) { + cairo_region_get_rectangle (damage->region, i, &r); + + rects[i].x = r.x; + rects[i].y = r.y; + rects[i].width = r.width; + rects[i].height = r.height; + } + XSetClipRectangles (display->display, gc, 0, 0, rects, i, YXBanded); + + XCopyArea (display->display, + surface->drawable, shm->pixmap, gc, + 0, 0, + shm->image.width, shm->image.height, + 0, 0); + + if (damage->status == CAIRO_STATUS_SUCCESS && damage->region) + XSetClipMask (display->display, gc, None); + } + } else { + XCopyArea (display->display, + surface->drawable, shm->pixmap, gc, + 0, 0, + shm->image.width, shm->image.height, + 0, 0); + } + + if (! surface->owns_pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = ClipByChildren; + XChangeGC (display->display, gc, GCSubwindowMode, &gcv); + } + + _cairo_xlib_display_sync (display); + shm->active = 0; + shm->idle--; + + _cairo_xlib_surface_put_gc (display, surface, gc); +cleanup_display: + cairo_device_release (&display->base); +cleanup_damage: + _cairo_damage_destroy (damage); +} + +static void +_cairo_xlib_surface_clear_shm (cairo_xlib_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface->shm; + + assert (shm->active == 0); + + _cairo_damage_destroy (surface->base.damage); + surface->base.damage = _cairo_damage_create(); + + memset (shm->image.data, 0, shm->image.stride * shm->image.height); + shm->image.base.is_clear = TRUE; +} + +static void inc_idle (cairo_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface; + shm->idle++; +} + +static void dec_idle (cairo_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *)surface; + shm->idle--; +} + +cairo_surface_t * +_cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface, + cairo_bool_t overwrite) +{ + if (surface->fallback) { + assert (surface->base.damage); + assert (surface->shm); + assert (surface->shm->damage); + goto done; + } + + if (surface->shm == NULL) { + pixman_format_code_t pixman_format; + cairo_bool_t will_sync; + + if (! has_shm_pixmaps (surface)) + return NULL; + + if ((surface->width | surface->height) < 32) + return NULL; + + pixman_format = _pixman_format_for_xlib_surface (surface); + if (pixman_format == 0) + return NULL; + + will_sync = !surface->base.is_clear && !overwrite; + + surface->shm = + &_cairo_xlib_shm_surface_create (surface, pixman_format, + surface->width, surface->height, + will_sync, 1)->image.base; + if (surface->shm == NULL) + return NULL; + + assert (surface->base.damage == NULL); + if (surface->base.serial || !surface->owns_pixmap) { + cairo_rectangle_int_t rect; + + rect.x = rect.y = 0; + rect.width = surface->width; + rect.height = surface->height; + + surface->base.damage = + _cairo_damage_add_rectangle (NULL, &rect); + } else + surface->base.damage = _cairo_damage_create (); + + surface->shm->damage = _cairo_damage_create (); + } + + if (overwrite) { + _cairo_damage_destroy (surface->base.damage); + surface->base.damage = _cairo_damage_create (); + } + + if (!surface->base.is_clear && surface->base.damage->dirty) + _cairo_xlib_surface_update_shm (surface); + + _cairo_xlib_shm_surface_flush (surface->shm, 1); + + if (surface->base.is_clear && surface->base.damage->dirty) + _cairo_xlib_surface_clear_shm (surface); + +done: + dec_idle(surface->shm); + return surface->shm; +} + +cairo_int_status_t +_cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface) +{ + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; + + if (!surface->fallback) { + if (surface->shm) + inc_idle (surface->shm); + return CAIRO_INT_STATUS_SUCCESS; + } + + if (surface->shm->damage->dirty) { + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface->shm; + cairo_xlib_display_t *display; + cairo_damage_t *damage; + GC gc; + + status = _cairo_xlib_display_acquire (surface->base.device, &display); + if (unlikely (status)) + return status; + + damage = _cairo_damage_reduce (shm->image.base.damage); + shm->image.base.damage = _cairo_damage_create (); + + TRACE ((stderr, "%s: flushing damage x %d\n", __FUNCTION__, + damage->region ? cairo_region_num_rectangles (damage->region) : 0)); + if (damage->status == CAIRO_STATUS_SUCCESS && damage->region) { + XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)]; + XRectangle *rects = stack_rects; + cairo_rectangle_int_t r; + int n_rects, i; + + n_rects = cairo_region_num_rectangles (damage->region); + if (n_rects == 0) + goto out; + + status = _cairo_xlib_surface_get_gc (display, surface, &gc); + if (unlikely (status)) + goto out; + + if (n_rects == 1) { + cairo_region_get_rectangle (damage->region, 0, &r); + _cairo_xlib_shm_surface_mark_active (surface->shm); + XCopyArea (display->display, + shm->pixmap, surface->drawable, gc, + r.x, r.y, + r.width, r.height, + r.x, r.y); + } else { + if (n_rects > ARRAY_LENGTH (stack_rects)) { + rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle)); + if (unlikely (rects == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + _cairo_xlib_surface_put_gc (display, surface, gc); + goto out; + } + } + for (i = 0; i < n_rects; i++) { + cairo_region_get_rectangle (damage->region, i, &r); + + rects[i].x = r.x; + rects[i].y = r.y; + rects[i].width = r.width; + rects[i].height = r.height; + } + XSetClipRectangles (display->display, gc, 0, 0, rects, i, YXBanded); + + _cairo_xlib_shm_surface_mark_active (surface->shm); + XCopyArea (display->display, + shm->pixmap, surface->drawable, gc, + 0, 0, + shm->image.width, shm->image.height, + 0, 0); + + if (damage->status == CAIRO_STATUS_SUCCESS && damage->region) + XSetClipMask (display->display, gc, None); + } + + _cairo_xlib_surface_put_gc (display, surface, gc); + } + +out: + _cairo_damage_destroy (damage); + cairo_device_release (&display->base); + } + + return status; +} + +cairo_surface_t * +_cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other, + pixman_format_code_t format, + int width, int height) +{ + cairo_surface_t *surface; + + surface = NULL; + if (has_shm (other)) + surface = &_cairo_xlib_shm_surface_create (other, format, width, height, + FALSE, has_shm_pixmaps (other))->image.base; + + return surface; +} + +cairo_surface_t * +_cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface, + pixman_format_code_t format, + int width, int height) +{ + if (! has_shm(surface)) + return NULL; + + return &_cairo_xlib_shm_surface_create (surface, format, width, height, + FALSE, 0)->image.base; +} + +cairo_surface_t * +_cairo_xlib_surface_create_similar_shm (void *other, + cairo_format_t format, + int width, int height) +{ + cairo_surface_t *surface; + + surface = _cairo_xlib_surface_create_shm (other, + _cairo_format_to_pixman_format_code (format), + width, height); + if (surface) { + if (! surface->is_clear) { + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface; + assert (shm->active == 0); + memset (shm->image.data, 0, shm->image.stride * shm->image.height); + shm->image.base.is_clear = TRUE; + } + } else + surface = cairo_image_surface_create (format, width, height); + + return surface; +} + +void +_cairo_xlib_shm_surface_mark_active (cairo_surface_t *_shm) +{ + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) _shm; + cairo_xlib_display_t *display = (cairo_xlib_display_t *) _shm->device; + + shm->active = NextRequest (display->display); +} + +void +_cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface, + XImage *ximage) +{ + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface; + int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; + cairo_format_masks_t image_masks; + int ret; + + ret = _pixman_format_to_masks (shm->image.pixman_format, &image_masks); + assert (ret); + + ximage->width = shm->image.width; + ximage->height = shm->image.height; + ximage->format = ZPixmap; + ximage->data = (char *) shm->image.data; + ximage->obdata = (char *)&shm->info->pool->shm; + ximage->byte_order = native_byte_order; + ximage->bitmap_unit = 32; /* always for libpixman */ + ximage->bitmap_bit_order = native_byte_order; + ximage->bitmap_pad = 32; /* always for libpixman */ + ximage->depth = shm->image.depth; + ximage->bytes_per_line = shm->image.stride; + ximage->bits_per_pixel = image_masks.bpp; + ximage->red_mask = image_masks.red_mask; + ximage->green_mask = image_masks.green_mask; + ximage->blue_mask = image_masks.blue_mask; + ximage->xoffset = 0; + + ret = XInitImage (ximage); + assert (ret != 0); +} + +void * +_cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface) +{ + cairo_xlib_display_t *display = (cairo_xlib_display_t *) surface->device; + cairo_xlib_shm_surface_t *shm = (cairo_xlib_shm_surface_t *) surface; + + display->shm->last_event = shm->active = NextRequest (display->display); + return &shm->info->pool->shm; +} + +Pixmap +_cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm; + + shm = (cairo_xlib_shm_surface_t *) surface; + return shm->pixmap; +} + +XRenderPictFormat * +_cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm; + + shm = (cairo_xlib_shm_surface_t *) surface; + if (shm->image.format != CAIRO_FORMAT_INVALID) + return _cairo_xlib_display_get_xrender_format ((cairo_xlib_display_t *)surface->device, + shm->image.format); + + return _cairo_xlib_display_get_xrender_format_for_pixman((cairo_xlib_display_t *)surface->device, + shm->image.pixman_format); +} + +cairo_bool_t +_cairo_xlib_shm_surface_is_active (cairo_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm; + + shm = (cairo_xlib_shm_surface_t *) surface; + if (shm->active == 0) + return FALSE; + + if (seqno_passed (shm->active, peek_processed (shm->image.base.device))) { + shm->active = 0; + return FALSE; + } + + return TRUE; +} + +cairo_bool_t +_cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface) +{ + cairo_xlib_shm_surface_t *shm; + + shm = (cairo_xlib_shm_surface_t *) surface; + return shm->idle > 0; +} + +#define XORG_VERSION_ENCODE(major,minor,patch,snap) \ + (((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap) + +static cairo_bool_t +has_broken_send_shm_event (cairo_xlib_display_t *display, + cairo_xlib_shm_display_t *shm) +{ + Display *dpy = display->display; + int (*old_handler) (Display *display, XErrorEvent *event); + XShmCompletionEvent ev; + XShmSegmentInfo info; + + info.shmid = shmget (IPC_PRIVATE, 0x1000, IPC_CREAT | 0600); + if (info.shmid == -1) + return TRUE; + + info.readOnly = FALSE; + info.shmaddr = shmat (info.shmid, NULL, 0); + if (info.shmaddr == (char *) -1) { + shmctl (info.shmid, IPC_RMID, NULL); + return TRUE; + } + + ev.type = shm->event; + ev.send_event = 1; + ev.serial = 1; + ev.drawable = shm->window; + ev.major_code = shm->opcode; + ev.minor_code = X_ShmPutImage; + + ev.shmseg = info.shmid; + ev.offset = 0; + + assert (CAIRO_MUTEX_IS_LOCKED (_cairo_xlib_display_mutex)); + _x_error_occurred = FALSE; + + XLockDisplay (dpy); + XSync (dpy, False); + old_handler = XSetErrorHandler (_check_error_handler); + + XShmAttach (dpy, &info); + XSendEvent (dpy, ev.drawable, False, 0, (XEvent *)&ev); + XShmDetach (dpy, &info); + + XSync (dpy, False); + XSetErrorHandler (old_handler); + XUnlockDisplay (dpy); + + shmctl (info.shmid, IPC_RMID, NULL); + shmdt (info.shmaddr); + + return _x_error_occurred; +} + +static cairo_bool_t +xorg_has_buggy_send_shm_completion_event(cairo_xlib_display_t *display, + cairo_xlib_shm_display_t *shm) +{ + Display *dpy = display->display; + + /* As libXext sets the SEND_EVENT bit in the ShmCompletionEvent, + * the Xserver may crash if it does not take care when processing + * the event type. For instance versions of Xorg prior to 1.11.1 + * exhibited this bug, and was fixed by: + * + * commit 2d2dce558d24eeea0eb011ec9ebaa6c5c2273c39 + * Author: Sam Spilsbury + * Date: Wed Sep 14 09:58:34 2011 +0800 + * + * Remove the SendEvent bit (0x80) before doing range checks on event type. + */ + if (_cairo_xlib_vendor_is_xorg (dpy) && + VendorRelease (dpy) < XORG_VERSION_ENCODE(1,11,0,1)) + return TRUE; + + /* For everyone else check that no error is generated */ + return has_broken_send_shm_event (display, shm); +} + +void +_cairo_xlib_display_init_shm (cairo_xlib_display_t *display) +{ + cairo_xlib_shm_display_t *shm; + XSetWindowAttributes attr; + XExtCodes *codes; + int has_pixmap, scr; + + display->shm = NULL; + + if (!can_use_shm (display->display, &has_pixmap)) + return; + + shm = malloc (sizeof (*shm)); + if (unlikely (shm == NULL)) + return; + + codes = XInitExtension (display->display, SHMNAME); + if (codes == NULL) { + free (shm); + return; + } + + shm->opcode = codes ->major_opcode; + shm->event = codes->first_event; + + if (unlikely (_pqueue_init (&shm->info))) { + free (shm); + return; + } + + scr = DefaultScreen (display->display); + attr.override_redirect = 1; + shm->window = XCreateWindow (display->display, + DefaultRootWindow (display->display), -1, -1, + 1, 1, 0, + DefaultDepth (display->display, scr), + InputOutput, + DefaultVisual (display->display, scr), + CWOverrideRedirect, &attr); + shm->last_event = 0; + shm->last_request = 0; + + if (xorg_has_buggy_send_shm_completion_event(display, shm)) + has_pixmap = 0; + + shm->has_pixmaps = has_pixmap ? MIN_PIXMAP_SIZE : 0; + cairo_list_init (&shm->pool); + + cairo_list_init (&shm->surfaces); + + display->shm = shm; +} + +void +_cairo_xlib_display_fini_shm (cairo_xlib_display_t *display) +{ + cairo_xlib_shm_display_t *shm = display->shm; + + if (shm == NULL) + return; + + while (!cairo_list_is_empty (&shm->surfaces)) + cairo_surface_finish (&cairo_list_first_entry (&shm->surfaces, + cairo_xlib_shm_surface_t, + link)->image.base); + + _pqueue_fini (&shm->info); + + while (!cairo_list_is_empty (&shm->pool)) { + cairo_xlib_shm_t *pool; + + pool = cairo_list_first_entry (&shm->pool, cairo_xlib_shm_t, link); + _cairo_xlib_display_shm_pool_destroy (display, pool); + } + + if (display->display) + XDestroyWindow (display->display, shm->window); + + free (shm); + display->shm = NULL; +} +#endif +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface.c new file mode 100644 index 00000000000..029a542b946 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-surface.c @@ -0,0 +1,2383 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Behdad Esfahbod + * Chris Wilson + * Karl Tomlinson , Mozilla Corporation + */ + +/* Heed well the words of Owen Taylor: + * "Any patch that works around a render bug, or claims to, without a + * specific reference to the bug filed in bugzilla.freedesktop.org will + * never pass approval." + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" +#include "cairo-xlib-surface-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-clip-private.h" +#include "cairo-damage-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-list-inline.h" +#include "cairo-pattern-private.h" +#include "cairo-pixman-private.h" +#include "cairo-region-private.h" +#include "cairo-scaled-font-private.h" +#include "cairo-surface-snapshot-private.h" +#include "cairo-surface-subsurface-private.h" + +#include /* for XDestroyImage */ + +#include +#include +#include + +#define XLIB_COORD_MAX 32767 + +#define DEBUG 0 + +#if DEBUG +#define UNSUPPORTED(reason) \ + fprintf (stderr, \ + "cairo-xlib: hit unsupported operation %s(), line %d: %s\n", \ + __FUNCTION__, __LINE__, reason), \ + CAIRO_INT_STATUS_UNSUPPORTED +#else +#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED +#endif + +#if DEBUG +#include +static void CAIRO_PRINTF_FORMAT (2, 3) +_x_bread_crumb (Display *dpy, + const char *fmt, + ...) +{ + xReq *req; + char buf[2048]; + unsigned int len, len_dwords; + va_list ap; + + va_start (ap, fmt); + len = vsnprintf (buf, sizeof (buf), fmt, ap); + va_end (ap); + + buf[len++] = '\0'; + while (len & 3) + buf[len++] = '\0'; + + LockDisplay (dpy); + GetEmptyReq (NoOperation, req); + + len_dwords = len >> 2; + SetReqLen (req, len_dwords, len_dwords); + Data (dpy, buf, len); + + UnlockDisplay (dpy); + SyncHandle (); +} +#define X_DEBUG(x) _x_bread_crumb x +#else +#define X_DEBUG(x) +#endif + +/** + * SECTION:cairo-xlib + * @Title: XLib Surfaces + * @Short_Description: X Window System rendering using XLib + * @See_Also: #cairo_surface_t + * + * The XLib surface is used to render cairo graphics to X Window System + * windows and pixmaps using the XLib library. + * + * Note that the XLib surface automatically takes advantage of X render extension + * if it is available. + **/ + +/** + * CAIRO_HAS_XLIB_SURFACE: + * + * Defined if the Xlib surface backend is available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.0 + **/ + +/** + * SECTION:cairo-xlib-xrender + * @Title: XLib-XRender Backend + * @Short_Description: X Window System rendering using XLib and the X Render extension + * @See_Also: #cairo_surface_t + * + * The XLib surface is used to render cairo graphics to X Window System + * windows and pixmaps using the XLib and Xrender libraries. + * + * Note that the XLib surface automatically takes advantage of X Render extension + * if it is available. + **/ + +/** + * CAIRO_HAS_XLIB_XRENDER_SURFACE: + * + * Defined if the XLib/XRender surface functions are available. + * This macro can be used to conditionally compile backend-specific code. + * + * Since: 1.6 + **/ + +/* Xlib doesn't define a typedef, so define one ourselves */ +typedef int (*cairo_xlib_error_func_t) (Display *display, + XErrorEvent *event); + +static cairo_surface_t * +_cairo_xlib_surface_create_internal (cairo_xlib_screen_t *screen, + Drawable drawable, + Visual *visual, + XRenderPictFormat *xrender_format, + int width, + int height, + int depth); + +static cairo_bool_t +_cairo_surface_is_xlib (cairo_surface_t *surface); + +/* + * Instead of taking two round trips for each blending request, + * assume that if a particular drawable fails GetImage that it will + * fail for a "while"; use temporary pixmaps to avoid the errors + */ + +#define CAIRO_ASSUME_PIXMAP 20 + +static const XTransform identity = { { + { 1 << 16, 0x00000, 0x00000 }, + { 0x00000, 1 << 16, 0x00000 }, + { 0x00000, 0x00000, 1 << 16 }, +} }; + +static Visual * +_visual_for_xrender_format(Screen *screen, + XRenderPictFormat *xrender_format) +{ + int d, v; + + /* XXX Consider searching through the list of known cairo_visual_t for + * the reverse mapping. + */ + + for (d = 0; d < screen->ndepths; d++) { + Depth *d_info = &screen->depths[d]; + + if (d_info->depth != xrender_format->depth) + continue; + + for (v = 0; v < d_info->nvisuals; v++) { + Visual *visual = &d_info->visuals[v]; + + switch (visual->class) { + case TrueColor: + if (xrender_format->type != PictTypeDirect) + continue; + break; + + case DirectColor: + /* Prefer TrueColor to DirectColor. + * (XRenderFindVisualFormat considers both TrueColor and DirectColor + * Visuals to match the same PictFormat.) + */ + continue; + + case StaticGray: + case GrayScale: + case StaticColor: + case PseudoColor: + if (xrender_format->type != PictTypeIndexed) + continue; + break; + } + + if (xrender_format == + XRenderFindVisualFormat (DisplayOfScreen(screen), visual)) + return visual; + } + } + + return NULL; +} + +static cairo_content_t +_xrender_format_to_content (XRenderPictFormat *xrender_format) +{ + cairo_content_t content; + + /* This only happens when using a non-Render server. Let's punt + * and say there's no alpha here. */ + if (xrender_format == NULL) + return CAIRO_CONTENT_COLOR; + + content = 0; + if (xrender_format->direct.alphaMask) + content |= CAIRO_CONTENT_ALPHA; + if (xrender_format->direct.redMask | + xrender_format->direct.greenMask | + xrender_format->direct.blueMask) + content |= CAIRO_CONTENT_COLOR; + + return content; +} + +static cairo_surface_t * +_cairo_xlib_surface_create_similar (void *abstract_src, + cairo_content_t content, + int width, + int height) +{ + cairo_xlib_surface_t *src = abstract_src; + XRenderPictFormat *xrender_format; + cairo_xlib_surface_t *surface; + cairo_xlib_display_t *display; + Pixmap pix; + + if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX) + return NULL; + + if (width == 0 || height == 0) + return NULL; + + if (_cairo_xlib_display_acquire (src->base.device, &display)) + return NULL; + + /* If we never found an XRenderFormat or if it isn't compatible + * with the content being requested, then we fallback to just + * constructing a cairo_format_t instead, (which will fairly + * arbitrarily pick a visual/depth for the similar surface. + */ + xrender_format = NULL; + if (src->xrender_format && + _xrender_format_to_content (src->xrender_format) == content) + { + xrender_format = src->xrender_format; + } + if (xrender_format == NULL) { + xrender_format = + _cairo_xlib_display_get_xrender_format (display, + _cairo_format_from_content (content)); + } + if (xrender_format) { + Visual *visual; + + /* We've got a compatible XRenderFormat now, which means the + * similar surface will match the existing surface as closely in + * visual/depth etc. as possible. */ + pix = XCreatePixmap (display->display, src->drawable, + width, height, xrender_format->depth); + + if (xrender_format == src->xrender_format) + visual = src->visual; + else + visual = _visual_for_xrender_format(src->screen->screen, + xrender_format); + + surface = (cairo_xlib_surface_t *) + _cairo_xlib_surface_create_internal (src->screen, pix, visual, + xrender_format, + width, height, + xrender_format->depth); + } + else + { + Screen *screen = src->screen->screen; + int depth; + + /* No compatible XRenderFormat, see if we can make an ordinary pixmap, + * so that we can still accelerate blits with XCopyArea(). */ + if (content != CAIRO_CONTENT_COLOR) { + cairo_device_release (&display->base); + return NULL; + } + + depth = DefaultDepthOfScreen (screen); + + pix = XCreatePixmap (display->display, RootWindowOfScreen (screen), + width <= 0 ? 1 : width, height <= 0 ? 1 : height, + depth); + + surface = (cairo_xlib_surface_t *) + _cairo_xlib_surface_create_internal (src->screen, pix, + DefaultVisualOfScreen (screen), + NULL, + width, height, depth); + } + + if (likely (surface->base.status == CAIRO_STATUS_SUCCESS)) + surface->owns_pixmap = TRUE; + else + XFreePixmap (display->display, pix); + + cairo_device_release (&display->base); + + return &surface->base; +} + +static void +_cairo_xlib_surface_discard_shm (cairo_xlib_surface_t *surface) +{ + if (surface->shm == NULL) + return; + + /* Force the flush for an external surface */ + if (!surface->owns_pixmap) + cairo_surface_flush (surface->shm); + + cairo_surface_finish (surface->shm); + cairo_surface_destroy (surface->shm); + surface->shm = NULL; + + _cairo_damage_destroy (surface->base.damage); + surface->base.damage = NULL; + + surface->fallback = 0; +} + +static cairo_status_t +_cairo_xlib_surface_finish (void *abstract_surface) +{ + cairo_xlib_surface_t *surface = abstract_surface; + cairo_status_t status; + cairo_xlib_display_t *display; + + cairo_list_del (&surface->link); + + status = _cairo_xlib_display_acquire (surface->base.device, &display); + if (unlikely (status)) + return status; + + X_DEBUG ((display->display, "finish (drawable=%x)", (unsigned int) surface->drawable)); + + if (surface->embedded_source.picture) + XRenderFreePicture (display->display, surface->embedded_source.picture); + if (surface->picture) + XRenderFreePicture (display->display, surface->picture); + + _cairo_xlib_surface_discard_shm (surface); + + if (surface->owns_pixmap) + XFreePixmap (display->display, surface->drawable); + + cairo_device_release (&display->base); + + return status; +} + +cairo_status_t +_cairo_xlib_surface_get_gc (cairo_xlib_display_t *display, + cairo_xlib_surface_t *surface, + GC *gc) +{ + *gc = _cairo_xlib_screen_get_gc (display, + surface->screen, + surface->depth, + surface->drawable); + if (unlikely (*gc == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} + +static int +_noop_error_handler (Display *display, + XErrorEvent *event) +{ + return False; /* return value is ignored */ +} + +static void +_swap_ximage_2bytes (XImage *ximage) +{ + int i, j; + char *line = ximage->data; + + for (j = ximage->height; j; j--) { + uint16_t *p = (uint16_t *) line; + for (i = ximage->width; i; i--) { + *p = bswap_16 (*p); + p++; + } + + line += ximage->bytes_per_line; + } +} + +static void +_swap_ximage_3bytes (XImage *ximage) +{ + int i, j; + char *line = ximage->data; + + for (j = ximage->height; j; j--) { + uint8_t *p = (uint8_t *) line; + for (i = ximage->width; i; i--) { + uint8_t tmp; + tmp = p[2]; + p[2] = p[0]; + p[0] = tmp; + p += 3; + } + + line += ximage->bytes_per_line; + } +} + +static void +_swap_ximage_4bytes (XImage *ximage) +{ + int i, j; + char *line = ximage->data; + + for (j = ximage->height; j; j--) { + uint32_t *p = (uint32_t *) line; + for (i = ximage->width; i; i--) { + *p = bswap_32 (*p); + p++; + } + + line += ximage->bytes_per_line; + } +} + +static void +_swap_ximage_nibbles (XImage *ximage) +{ + int i, j; + char *line = ximage->data; + + for (j = ximage->height; j; j--) { + uint8_t *p = (uint8_t *) line; + for (i = (ximage->width + 1) / 2; i; i--) { + *p = ((*p >> 4) & 0xf) | ((*p << 4) & ~0xf); + p++; + } + + line += ximage->bytes_per_line; + } +} + +static void +_swap_ximage_bits (XImage *ximage) +{ + int i, j; + char *line = ximage->data; + int unit = ximage->bitmap_unit; + int line_bytes = ((ximage->width + unit - 1) & ~(unit - 1)) / 8; + + for (j = ximage->height; j; j--) { + char *p = line; + + for (i = line_bytes; i; i--) { + char b = *p; + b = ((b << 1) & 0xaa) | ((b >> 1) & 0x55); + b = ((b << 2) & 0xcc) | ((b >> 2) & 0x33); + b = ((b << 4) & 0xf0) | ((b >> 4) & 0x0f); + *p = b; + + p++; + } + + line += ximage->bytes_per_line; + } +} + +static void +_swap_ximage_to_native (XImage *ximage) +{ + int unit_bytes = 0; + int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; + + if (ximage->bits_per_pixel == 1 && + ximage->bitmap_bit_order != native_byte_order) + { + _swap_ximage_bits (ximage); + if (ximage->bitmap_bit_order == ximage->byte_order) + return; + } + + if (ximage->byte_order == native_byte_order) + return; + + switch (ximage->bits_per_pixel) { + case 1: + unit_bytes = ximage->bitmap_unit / 8; + break; + case 4: + _swap_ximage_nibbles (ximage); + /* fall-through */ + case 8: + case 16: + case 20: + case 24: + case 28: + case 30: + case 32: + unit_bytes = (ximage->bits_per_pixel + 7) / 8; + break; + default: + /* This could be hit on some rare but possible cases. */ + ASSERT_NOT_REACHED; + } + + switch (unit_bytes) { + case 1: + break; + case 2: + _swap_ximage_2bytes (ximage); + break; + case 3: + _swap_ximage_3bytes (ximage); + break; + case 4: + _swap_ximage_4bytes (ximage); + break; + default: + ASSERT_NOT_REACHED; + } +} + + +/* Given a mask, (with a single sequence of contiguous 1 bits), return + * the number of 1 bits in 'width' and the number of 0 bits to its + * right in 'shift'. */ +static void +_characterize_field (uint32_t mask, int *width, int *shift) +{ + *width = _cairo_popcount (mask); + /* The final '& 31' is to force a 0 mask to result in 0 shift. */ + *shift = _cairo_popcount ((mask - 1) & ~mask) & 31; +} + +/* Convert a field of 'width' bits to 'new_width' bits with correct + * rounding. */ +static inline uint32_t +_resize_field (uint32_t field, int width, int new_width) +{ + if (width == 0) + return 0; + + if (width >= new_width) { + return field >> (width - new_width); + } else { + uint32_t result = field << (new_width - width); + + while (width < new_width) { + result |= result >> width; + width <<= 1; + } + return result; + } +} + +static inline uint32_t +_adjust_field (uint32_t field, int adjustment) +{ + return MIN (255, MAX(0, (int)field + adjustment)); +} + +/* Given a shifted field value, (described by 'width' and 'shift), + * resize it 8-bits and return that value. + * + * Note that the original field value must not have any non-field bits + * set. + */ +static inline uint32_t +_field_to_8 (uint32_t field, int width, int shift) +{ + return _resize_field (field >> shift, width, 8); +} + +static inline uint32_t +_field_to_8_undither (uint32_t field, int width, int shift, + int dither_adjustment) +{ + return _adjust_field (_field_to_8 (field, width, shift), - dither_adjustment>>width); +} + +/* Given an 8-bit value, convert it to a field of 'width', shift it up + * to 'shift, and return it. */ +static inline uint32_t +_field_from_8 (uint32_t field, int width, int shift) +{ + return _resize_field (field, 8, width) << shift; +} + +static inline uint32_t +_field_from_8_dither (uint32_t field, int width, int shift, + int8_t dither_adjustment) +{ + return _field_from_8 (_adjust_field (field, dither_adjustment>>width), width, shift); +} + +static inline uint32_t +_pseudocolor_from_rgb888_dither (cairo_xlib_visual_info_t *visual_info, + uint32_t r, uint32_t g, uint32_t b, + int8_t dither_adjustment) +{ + if (r == g && g == b) { + dither_adjustment /= RAMP_SIZE; + return visual_info->gray8_to_pseudocolor[_adjust_field (r, dither_adjustment)]; + } else { + dither_adjustment = visual_info->dither8_to_cube[dither_adjustment+128]; + return visual_info->cube_to_pseudocolor[visual_info->field8_to_cube[_adjust_field (r, dither_adjustment)]] + [visual_info->field8_to_cube[_adjust_field (g, dither_adjustment)]] + [visual_info->field8_to_cube[_adjust_field (b, dither_adjustment)]]; + } +} + +static inline uint32_t +_pseudocolor_to_rgb888 (cairo_xlib_visual_info_t *visual_info, + uint32_t pixel) +{ + uint32_t r, g, b; + pixel &= 0xff; + r = visual_info->colors[pixel].r; + g = visual_info->colors[pixel].g; + b = visual_info->colors[pixel].b; + return (r << 16) | + (g << 8) | + (b ); +} + +/* should range from -128 to 127 */ +#define X 16 +static const int8_t dither_pattern[4][4] = { + {-8*X, +0*X, -6*X, +2*X}, + {+4*X, -4*X, +6*X, -2*X}, + {-5*X, +4*X, -7*X, +1*X}, + {+7*X, -1*X, +5*X, -3*X} +}; +#undef X + +static int bits_per_pixel(cairo_xlib_surface_t *surface) +{ + if (surface->depth > 16) + return 32; + else if (surface->depth > 8) + return 16; + else if (surface->depth > 1) + return 8; + else + return 1; +} + +pixman_format_code_t +_pixman_format_for_xlib_surface (cairo_xlib_surface_t *surface) +{ + cairo_format_masks_t masks; + pixman_format_code_t format; + + masks.bpp = bits_per_pixel (surface); + masks.alpha_mask = surface->a_mask; + masks.red_mask = surface->r_mask; + masks.green_mask = surface->g_mask; + masks.blue_mask = surface->b_mask; + if (! _pixman_format_from_masks (&masks, &format)) + return 0; + + return format; +} + +static cairo_surface_t * +_get_image_surface (cairo_xlib_surface_t *surface, + const cairo_rectangle_int_t *extents, + int try_shm) +{ + cairo_int_status_t status; + cairo_image_surface_t *image = NULL; + XImage *ximage; + pixman_format_code_t pixman_format; + cairo_xlib_display_t *display; + + assert (extents->x >= 0); + assert (extents->y >= 0); + assert (extents->x + extents->width <= surface->width); + assert (extents->y + extents->height <= surface->height); + + if (surface->base.is_clear || + (surface->base.serial == 0 && surface->owns_pixmap)) + { + pixman_format = _pixman_format_for_xlib_surface (surface); + if (pixman_format) + { + return _cairo_image_surface_create_with_pixman_format (NULL, + pixman_format, + extents->width, + extents->height, + 0); + } + } + + if (surface->shm) { + cairo_image_surface_t *src = (cairo_image_surface_t *) surface->shm; + cairo_surface_t *dst; + cairo_surface_pattern_t pattern; + + dst = cairo_image_surface_create (src->format, + extents->width, extents->height); + if (unlikely (dst->status)) + return dst; + + _cairo_pattern_init_for_surface (&pattern, &src->base); + cairo_matrix_init_translate (&pattern.base.matrix, + extents->x, extents->y); + status = _cairo_surface_paint (dst, CAIRO_OPERATOR_SOURCE, &pattern.base, NULL); + _cairo_pattern_fini (&pattern.base); + if (unlikely (status)) { + cairo_surface_destroy (dst); + dst = _cairo_surface_create_in_error (status); + } + + return dst; + } + + status = _cairo_xlib_display_acquire (surface->base.device, &display); + if (status) + return _cairo_surface_create_in_error (status); + + pixman_format = _pixman_format_for_xlib_surface (surface); + if (try_shm && pixman_format) { + image = (cairo_image_surface_t *) + _cairo_xlib_surface_create_shm__image (surface, pixman_format, + extents->width, extents->height); + if (image && image->base.status == CAIRO_STATUS_SUCCESS) { + cairo_xlib_error_func_t old_handler; + XImage shm_image; + Bool success; + + _cairo_xlib_shm_surface_get_ximage (&image->base, &shm_image); + + old_handler = XSetErrorHandler (_noop_error_handler); + success = XShmGetImage (display->display, + surface->drawable, + &shm_image, + extents->x, extents->y, + AllPlanes); + XSetErrorHandler (old_handler); + + if (success) { + cairo_device_release (&display->base); + return &image->base; + } + + cairo_surface_destroy (&image->base); + } + } + + if (surface->use_pixmap == 0) { + cairo_xlib_error_func_t old_handler; + + old_handler = XSetErrorHandler (_noop_error_handler); + + ximage = XGetImage (display->display, + surface->drawable, + extents->x, extents->y, + extents->width, extents->height, + AllPlanes, ZPixmap); + + XSetErrorHandler (old_handler); + + /* If we get an error, the surface must have been a window, + * so retry with the safe code path. + */ + if (!ximage) + surface->use_pixmap = CAIRO_ASSUME_PIXMAP; + } else { + surface->use_pixmap--; + ximage = NULL; + } + + if (ximage == NULL) { + /* XGetImage from a window is dangerous because it can + * produce errors if the window is unmapped or partially + * outside the screen. We could check for errors and + * retry, but to keep things simple, we just create a + * temporary pixmap + */ + Pixmap pixmap; + GC gc; + + status = _cairo_xlib_surface_get_gc (display, surface, &gc); + if (unlikely (status)) + goto BAIL; + + pixmap = XCreatePixmap (display->display, + surface->drawable, + extents->width, extents->height, + surface->depth); + if (pixmap) { + XGCValues gcv; + + gcv.subwindow_mode = IncludeInferiors; + XChangeGC (display->display, gc, GCSubwindowMode, &gcv); + + XCopyArea (display->display, surface->drawable, pixmap, gc, + extents->x, extents->y, + extents->width, extents->height, + 0, 0); + + gcv.subwindow_mode = ClipByChildren; + XChangeGC (display->display, gc, GCSubwindowMode, &gcv); + + ximage = XGetImage (display->display, + pixmap, + 0, 0, + extents->width, extents->height, + AllPlanes, ZPixmap); + + XFreePixmap (display->display, pixmap); + } + + _cairo_xlib_surface_put_gc (display, surface, gc); + + if (ximage == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + } + + _swap_ximage_to_native (ximage); + + /* We can't use pixman to simply write to image if: + * (a) the pixels are not appropriately aligned, + * (b) pixman does not the pixel format, or + * (c) if the image is palettized and we need to convert. + */ + if (pixman_format && + ximage->bitmap_unit == 32 && ximage->bitmap_pad == 32 && + (surface->visual == NULL || surface->visual->class == TrueColor)) + { + image = (cairo_image_surface_t*) + _cairo_image_surface_create_with_pixman_format ((unsigned char *) ximage->data, + pixman_format, + ximage->width, + ximage->height, + ximage->bytes_per_line); + status = image->base.status; + if (unlikely (status)) + goto BAIL; + + /* Let the surface take ownership of the data */ + _cairo_image_surface_assume_ownership_of_data (image); + ximage->data = NULL; + } else { + /* The visual we are dealing with is not supported by the + * standard pixman formats. So we must first convert the data + * to a supported format. */ + + cairo_format_t format; + unsigned char *data; + uint32_t *row; + uint32_t in_pixel, out_pixel; + unsigned int rowstride; + uint32_t a_mask=0, r_mask=0, g_mask=0, b_mask=0; + int a_width=0, r_width=0, g_width=0, b_width=0; + int a_shift=0, r_shift=0, g_shift=0, b_shift=0; + int x, y, x0, y0, x_off, y_off; + cairo_xlib_visual_info_t *visual_info = NULL; + + if (surface->visual == NULL || surface->visual->class == TrueColor) { + cairo_bool_t has_alpha; + cairo_bool_t has_color; + + has_alpha = surface->a_mask; + has_color = (surface->r_mask || + surface->g_mask || + surface->b_mask); + + if (has_color) { + if (has_alpha) { + format = CAIRO_FORMAT_ARGB32; + } else { + format = CAIRO_FORMAT_RGB24; + } + } else { + /* XXX: Using CAIRO_FORMAT_A8 here would be more + * efficient, but would require slightly different code in + * the image conversion to put the alpha channel values + * into the right place. */ + format = CAIRO_FORMAT_ARGB32; + } + + a_mask = surface->a_mask; + r_mask = surface->r_mask; + g_mask = surface->g_mask; + b_mask = surface->b_mask; + + _characterize_field (a_mask, &a_width, &a_shift); + _characterize_field (r_mask, &r_width, &r_shift); + _characterize_field (g_mask, &g_width, &g_shift); + _characterize_field (b_mask, &b_width, &b_shift); + + } else { + format = CAIRO_FORMAT_RGB24; + + status = _cairo_xlib_screen_get_visual_info (display, + surface->screen, + surface->visual, + &visual_info); + if (unlikely (status)) + goto BAIL; + } + + image = (cairo_image_surface_t *) cairo_image_surface_create + (format, ximage->width, ximage->height); + status = image->base.status; + if (unlikely (status)) + goto BAIL; + + data = cairo_image_surface_get_data (&image->base); + rowstride = cairo_image_surface_get_stride (&image->base) >> 2; + row = (uint32_t *) data; + x0 = extents->x + surface->base.device_transform.x0; + y0 = extents->y + surface->base.device_transform.y0; + for (y = 0, y_off = y0 % ARRAY_LENGTH (dither_pattern); + y < ximage->height; + y++, y_off = (y_off+1) % ARRAY_LENGTH (dither_pattern)) { + const int8_t *dither_row = dither_pattern[y_off]; + for (x = 0, x_off = x0 % ARRAY_LENGTH (dither_pattern[0]); + x < ximage->width; + x++, x_off = (x_off+1) % ARRAY_LENGTH (dither_pattern[0])) { + int dither_adjustment = dither_row[x_off]; + + in_pixel = XGetPixel (ximage, x, y); + if (visual_info == NULL) { + out_pixel = ( + _field_to_8 (in_pixel & a_mask, a_width, a_shift) << 24 | + _field_to_8_undither (in_pixel & r_mask, r_width, r_shift, dither_adjustment) << 16 | + _field_to_8_undither (in_pixel & g_mask, g_width, g_shift, dither_adjustment) << 8 | + _field_to_8_undither (in_pixel & b_mask, b_width, b_shift, dither_adjustment)); + } else { + /* Undithering pseudocolor does not look better */ + out_pixel = _pseudocolor_to_rgb888 (visual_info, in_pixel); + } + row[x] = out_pixel; + } + row += rowstride; + } + cairo_surface_mark_dirty (&image->base); + } + + BAIL: + if (ximage) + XDestroyImage (ximage); + + cairo_device_release (&display->base); + + if (unlikely (status)) { + cairo_surface_destroy (&image->base); + return _cairo_surface_create_in_error (status); + } + + return &image->base; +} + +void +_cairo_xlib_surface_set_precision (cairo_xlib_surface_t *surface, + cairo_antialias_t antialias) +{ + cairo_xlib_display_t *display = surface->display; + int precision; + + if (display->force_precision != -1) + precision = display->force_precision; + else switch (antialias) { + default: + case CAIRO_ANTIALIAS_DEFAULT: + case CAIRO_ANTIALIAS_GRAY: + case CAIRO_ANTIALIAS_NONE: + case CAIRO_ANTIALIAS_FAST: + case CAIRO_ANTIALIAS_GOOD: + precision = PolyModeImprecise; + break; + case CAIRO_ANTIALIAS_BEST: + case CAIRO_ANTIALIAS_SUBPIXEL: + precision = PolyModePrecise; + break; + } + + if (surface->precision != precision) { + XRenderPictureAttributes pa; + + pa.poly_mode = precision; + XRenderChangePicture (display->display, surface->picture, + CPPolyMode, &pa); + + surface->precision = precision; + } +} + +void +_cairo_xlib_surface_ensure_picture (cairo_xlib_surface_t *surface) +{ + cairo_xlib_display_t *display = surface->display; + XRenderPictureAttributes pa; + int mask = 0; + + if (surface->picture) + return; + + if (display->force_precision != -1) + pa.poly_mode = display->force_precision; + else + pa.poly_mode = PolyModeImprecise; + if (pa.poly_mode) + mask |= CPPolyMode; + + surface->precision = pa.poly_mode; + surface->picture = XRenderCreatePicture (display->display, + surface->drawable, + surface->xrender_format, + mask, &pa); +} + +cairo_status_t +_cairo_xlib_surface_draw_image (cairo_xlib_surface_t *surface, + cairo_image_surface_t *image, + int src_x, + int src_y, + int width, + int height, + int dst_x, + int dst_y) +{ + cairo_xlib_display_t *display; + XImage ximage; + cairo_format_masks_t image_masks; + int native_byte_order = _cairo_is_little_endian () ? LSBFirst : MSBFirst; + cairo_surface_t *shm_image = NULL; + pixman_image_t *pixman_image = NULL; + cairo_status_t status; + cairo_bool_t own_data = FALSE; + cairo_bool_t is_rgb_image; + GC gc; + + ximage.width = image->width; + ximage.height = image->height; + ximage.format = ZPixmap; + ximage.byte_order = native_byte_order; + ximage.bitmap_unit = 32; /* always for libpixman */ + ximage.bitmap_bit_order = native_byte_order; + ximage.bitmap_pad = 32; /* always for libpixman */ + ximage.depth = surface->depth; + ximage.red_mask = surface->r_mask; + ximage.green_mask = surface->g_mask; + ximage.blue_mask = surface->b_mask; + ximage.xoffset = 0; + ximage.obdata = NULL; + + status = _cairo_xlib_display_acquire (surface->base.device, &display); + if (unlikely (status)) + return status; + + is_rgb_image = _pixman_format_to_masks (image->pixman_format, &image_masks); + + if (is_rgb_image && + (image_masks.alpha_mask == surface->a_mask || surface->a_mask == 0) && + (image_masks.red_mask == surface->r_mask || surface->r_mask == 0) && + (image_masks.green_mask == surface->g_mask || surface->g_mask == 0) && + (image_masks.blue_mask == surface->b_mask || surface->b_mask == 0)) + { + int ret; + + ximage.bits_per_pixel = image_masks.bpp; + ximage.bytes_per_line = image->stride; + ximage.data = (char *)image->data; + if (image->base.device != surface->base.device) { + /* If PutImage will break the image up into chunks, prefer to + * send it all in one pass with ShmPutImage. For larger images, + * it is further advantageous to reduce the number of copies, + * albeit at the expense of more SHM bookkeeping. + */ + int max_request_size = XExtendedMaxRequestSize (display->display); + if (max_request_size == 0) + max_request_size = XMaxRequestSize (display->display); + if (max_request_size > 8192) + max_request_size = 8192; + if (width * height * 4 > max_request_size) { + shm_image = _cairo_xlib_surface_create_shm__image (surface, + image->pixman_format, + width, height); + if (shm_image && shm_image->status == CAIRO_STATUS_SUCCESS) { + cairo_image_surface_t *clone = (cairo_image_surface_t *) shm_image; + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, NULL, clone->pixman_image, + src_x, src_y, + 0, 0, + 0, 0, + width, height); + ximage.obdata = _cairo_xlib_shm_surface_get_obdata (shm_image); + ximage.data = (char *)clone->data; + ximage.bytes_per_line = clone->stride; + ximage.width = width; + ximage.height = height; + src_x = src_y = 0; + } + } + } else + ximage.obdata = _cairo_xlib_shm_surface_get_obdata (&image->base); + + ret = XInitImage (&ximage); + assert (ret != 0); + } + else if (surface->visual == NULL || surface->visual->class == TrueColor) + { + pixman_format_code_t intermediate_format; + int ret; + + image_masks.alpha_mask = surface->a_mask; + image_masks.red_mask = surface->r_mask; + image_masks.green_mask = surface->g_mask; + image_masks.blue_mask = surface->b_mask; + image_masks.bpp = bits_per_pixel (surface); + ret = _pixman_format_from_masks (&image_masks, &intermediate_format); + assert (ret); + + shm_image = _cairo_xlib_surface_create_shm__image (surface, + intermediate_format, + width, height); + if (shm_image && shm_image->status == CAIRO_STATUS_SUCCESS) { + cairo_image_surface_t *clone = (cairo_image_surface_t *) shm_image; + + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, + NULL, + clone->pixman_image, + src_x, src_y, + 0, 0, + 0, 0, + width, height); + + ximage.data = (char *) clone->data; + ximage.obdata = _cairo_xlib_shm_surface_get_obdata (&clone->base); + ximage.bytes_per_line = clone->stride; + } else { + pixman_image = pixman_image_create_bits (intermediate_format, + width, height, NULL, 0); + if (pixman_image == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + + pixman_image_composite32 (PIXMAN_OP_SRC, + image->pixman_image, + NULL, + pixman_image, + src_x, src_y, + 0, 0, + 0, 0, + width, height); + + ximage.data = (char *) pixman_image_get_data (pixman_image); + ximage.bytes_per_line = pixman_image_get_stride (pixman_image); + } + + ximage.width = width; + ximage.height = height; + ximage.bits_per_pixel = image_masks.bpp; + + ret = XInitImage (&ximage); + assert (ret != 0); + + src_x = src_y = 0; + } + else + { + unsigned int stride, rowstride; + int x, y, x0, y0, x_off, y_off; + uint32_t in_pixel, out_pixel, *row; + int i_a_width=0, i_r_width=0, i_g_width=0, i_b_width=0; + int i_a_shift=0, i_r_shift=0, i_g_shift=0, i_b_shift=0; + int o_a_width=0, o_r_width=0, o_g_width=0, o_b_width=0; + int o_a_shift=0, o_r_shift=0, o_g_shift=0, o_b_shift=0; + cairo_xlib_visual_info_t *visual_info = NULL; + cairo_bool_t true_color; + int ret; + + ximage.bits_per_pixel = bits_per_pixel(surface); + stride = CAIRO_STRIDE_FOR_WIDTH_BPP (ximage.width, + ximage.bits_per_pixel); + ximage.bytes_per_line = stride; + ximage.data = _cairo_malloc_ab (stride, ximage.height); + if (unlikely (ximage.data == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto BAIL; + } + + own_data = TRUE; + + ret = XInitImage (&ximage); + assert (ret != 0); + + _characterize_field (image_masks.alpha_mask, &i_a_width, &i_a_shift); + _characterize_field (image_masks.red_mask , &i_r_width, &i_r_shift); + _characterize_field (image_masks.green_mask, &i_g_width, &i_g_shift); + _characterize_field (image_masks.blue_mask , &i_b_width, &i_b_shift); + + true_color = surface->visual == NULL || + surface->visual->class == TrueColor; + if (true_color) { + _characterize_field (surface->a_mask, &o_a_width, &o_a_shift); + _characterize_field (surface->r_mask, &o_r_width, &o_r_shift); + _characterize_field (surface->g_mask, &o_g_width, &o_g_shift); + _characterize_field (surface->b_mask, &o_b_width, &o_b_shift); + } else { + status = _cairo_xlib_screen_get_visual_info (display, + surface->screen, + surface->visual, + &visual_info); + if (unlikely (status)) + goto BAIL; + } + + rowstride = image->stride >> 2; + row = (uint32_t *) image->data; + x0 = dst_x + surface->base.device_transform.x0; + y0 = dst_y + surface->base.device_transform.y0; + for (y = 0, y_off = y0 % ARRAY_LENGTH (dither_pattern); + y < ximage.height; + y++, y_off = (y_off+1) % ARRAY_LENGTH (dither_pattern)) + { + const int8_t *dither_row = dither_pattern[y_off]; + + for (x = 0, x_off = x0 % ARRAY_LENGTH (dither_pattern[0]); + x < ximage.width; + x++, x_off = (x_off+1) % ARRAY_LENGTH (dither_pattern[0])) + { + int dither_adjustment = dither_row[x_off]; + int a, r, g, b; + + if (image_masks.bpp == 1) + in_pixel = !! (((uint8_t*)row)[x/8] & (1 << (x & 7))); + else if (image_masks.bpp <= 8) + in_pixel = ((uint8_t*)row)[x]; + else if (image_masks.bpp <= 16) + in_pixel = ((uint16_t*)row)[x]; + else if (image_masks.bpp <= 24) +#ifdef WORDS_BIGENDIAN + in_pixel = ((uint8_t*)row)[3 * x] << 16 | + ((uint8_t*)row)[3 * x + 1] << 8 | + ((uint8_t*)row)[3 * x + 2]; +#else + in_pixel = ((uint8_t*)row)[3 * x] | + ((uint8_t*)row)[3 * x + 1] << 8 | + ((uint8_t*)row)[3 * x + 2] << 16; +#endif + else + in_pixel = row[x]; + + /* If the incoming image has no alpha channel, then the input + * is opaque and the output should have the maximum alpha value. + * For all other channels, their absence implies 0. + */ + if (image_masks.alpha_mask == 0x0) + a = 0xff; + else + a = _field_to_8 (in_pixel & image_masks.alpha_mask, i_a_width, i_a_shift); + r = _field_to_8 (in_pixel & image_masks.red_mask , i_r_width, i_r_shift); + g = _field_to_8 (in_pixel & image_masks.green_mask, i_g_width, i_g_shift); + b = _field_to_8 (in_pixel & image_masks.blue_mask , i_b_width, i_b_shift); + + if (true_color) { + out_pixel = _field_from_8 (a, o_a_width, o_a_shift) | + _field_from_8_dither (r, o_r_width, o_r_shift, dither_adjustment) | + _field_from_8_dither (g, o_g_width, o_g_shift, dither_adjustment) | + _field_from_8_dither (b, o_b_width, o_b_shift, dither_adjustment); + } else { + out_pixel = _pseudocolor_from_rgb888_dither (visual_info, r, g, b, dither_adjustment); + } + + XPutPixel (&ximage, x, y, out_pixel); + } + + row += rowstride; + } + } + + status = _cairo_xlib_surface_get_gc (display, surface, &gc); + if (unlikely (status)) + goto BAIL; + + if (ximage.obdata) + XShmPutImage (display->display, surface->drawable, gc, &ximage, + src_x, src_y, dst_x, dst_y, width, height, True); + else + XPutImage (display->display, surface->drawable, gc, &ximage, + src_x, src_y, dst_x, dst_y, width, height); + + _cairo_xlib_surface_put_gc (display, surface, gc); + + BAIL: + cairo_device_release (&display->base); + + if (own_data) + free (ximage.data); + if (shm_image) + cairo_surface_destroy (shm_image); + if (pixman_image) + pixman_image_unref (pixman_image); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +_cairo_xlib_surface_source(void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_xlib_surface_t *surface = abstract_surface; + + if (extents) { + extents->x = extents->y = 0; + extents->width = surface->width; + extents->height = surface->height; + } + + return &surface->base; +} + +static cairo_status_t +_cairo_xlib_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_xlib_surface_t *surface = abstract_surface; + cairo_rectangle_int_t extents; + + *image_extra = NULL; + *image_out = (cairo_image_surface_t *) + _cairo_xlib_surface_get_shm (abstract_surface, FALSE); + if (*image_out) + return (*image_out)->base.status; + + extents.x = extents.y = 0; + extents.width = surface->width; + extents.height = surface->height; + + *image_out = (cairo_image_surface_t*) + _get_image_surface (surface, &extents, TRUE); + return (*image_out)->base.status; +} + +static cairo_surface_t * +_cairo_xlib_surface_snapshot (void *abstract_surface) +{ + cairo_xlib_surface_t *surface = abstract_surface; + cairo_rectangle_int_t extents; + + extents.x = extents.y = 0; + extents.width = surface->width; + extents.height = surface->height; + + return _get_image_surface (surface, &extents, FALSE); +} + +static void +_cairo_xlib_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image, + void *image_extra) +{ + cairo_xlib_surface_t *surface = abstract_surface; + + if (&image->base == surface->shm) + return; + + cairo_surface_destroy (&image->base); +} + +static cairo_image_surface_t * +_cairo_xlib_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_xlib_surface_t *surface = abstract_surface; + cairo_surface_t *image; + + image = _cairo_xlib_surface_get_shm (abstract_surface, FALSE); + if (image) { + assert (surface->base.damage); + surface->fallback++; + return _cairo_image_surface_map_to_image (image, extents); + } + + image = _get_image_surface (abstract_surface, extents, TRUE); + cairo_surface_set_device_offset (image, -extents->x, -extents->y); + + return (cairo_image_surface_t *) image; +} + +static cairo_int_status_t +_cairo_xlib_surface_unmap_image (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_xlib_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + if (surface->shm) { + cairo_rectangle_int_t r; + + assert (surface->fallback); + assert (surface->base.damage); + + r.x = image->base.device_transform_inverse.x0; + r.y = image->base.device_transform_inverse.y0; + r.width = image->width; + r.height = image->height; + + TRACE ((stderr, "%s: adding damage (%d,%d)x(%d,%d)\n", + __FUNCTION__, r.x, r.y, r.width, r.height)); + surface->shm->damage = + _cairo_damage_add_rectangle (surface->shm->damage, &r); + + return _cairo_image_surface_unmap_image (surface->shm, image); + } + + status = _cairo_xlib_surface_draw_image (abstract_surface, image, + 0, 0, + image->width, image->height, + image->base.device_transform_inverse.x0, + image->base.device_transform_inverse.y0); + + cairo_surface_finish (&image->base); + cairo_surface_destroy (&image->base); + + return status; +} + +static cairo_status_t +_cairo_xlib_surface_flush (void *abstract_surface, + unsigned flags) +{ + cairo_xlib_surface_t *surface = abstract_surface; + cairo_int_status_t status; + + if (flags) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_xlib_surface_put_shm (surface); + if (unlikely (status)) + return status; + + surface->fallback >>= 1; + if (surface->shm && _cairo_xlib_shm_surface_is_idle (surface->shm)) + _cairo_xlib_surface_discard_shm (surface); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_cairo_xlib_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_xlib_surface_t *surface = abstract_surface; + + rectangle->x = 0; + rectangle->y = 0; + + rectangle->width = surface->width; + rectangle->height = surface->height; + + return TRUE; +} + +static void +_cairo_xlib_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_xlib_surface_t *surface = abstract_surface; + + *options = *_cairo_xlib_screen_get_font_options (surface->screen); +} + +static inline cairo_int_status_t +get_compositor (cairo_xlib_surface_t **surface, + const cairo_compositor_t **compositor) +{ + cairo_xlib_surface_t *s = *surface; + cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS;; + + if (s->fallback) { + assert (s->base.damage != NULL); + assert (s->shm != NULL); + assert (s->shm->damage != NULL); + if (! _cairo_xlib_shm_surface_is_active (s->shm)) { + *surface = (cairo_xlib_surface_t *) s->shm; + *compositor = ((cairo_image_surface_t *) s->shm)->compositor; + s->fallback++; + } else { + status = _cairo_xlib_surface_put_shm (s); + s->fallback = 0; + *compositor = s->compositor; + } + } else + *compositor = s->compositor; + + return status; +} + +static cairo_int_status_t +_cairo_xlib_surface_paint (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_xlib_surface_t *surface = _surface; + const cairo_compositor_t *compositor; + cairo_int_status_t status; + + status = get_compositor (&surface, &compositor); + if (unlikely (status)) + return status; + + return _cairo_compositor_paint (compositor, &surface->base, + op, source, + clip); +} + +static cairo_int_status_t +_cairo_xlib_surface_mask (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_xlib_surface_t *surface = _surface; + const cairo_compositor_t *compositor; + cairo_int_status_t status; + + status = get_compositor (&surface, &compositor); + if (unlikely (status)) + return status; + + return _cairo_compositor_mask (compositor, &surface->base, + op, source, mask, + clip); +} + +static cairo_int_status_t +_cairo_xlib_surface_stroke (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_xlib_surface_t *surface = _surface; + const cairo_compositor_t *compositor; + cairo_int_status_t status; + + status = get_compositor (&surface, &compositor); + if (unlikely (status)) + return status; + + return _cairo_compositor_stroke (compositor, &surface->base, + op, source, + path, style, ctm, ctm_inverse, + tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_xlib_surface_fill (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_xlib_surface_t *surface = _surface; + const cairo_compositor_t *compositor; + cairo_int_status_t status; + + status = get_compositor (&surface, &compositor); + if (unlikely (status)) + return status; + + return _cairo_compositor_fill (compositor, &surface->base, + op, source, + path, fill_rule, tolerance, antialias, + clip); +} + +static cairo_int_status_t +_cairo_xlib_surface_glyphs (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_xlib_surface_t *surface = _surface; + const cairo_compositor_t *compositor; + cairo_int_status_t status; + + status = get_compositor (&surface, &compositor); + if (unlikely (status)) + return status; + + return _cairo_compositor_glyphs (compositor, &surface->base, + op, source, + glyphs, num_glyphs, scaled_font, + clip); +} + +static const cairo_surface_backend_t cairo_xlib_surface_backend = { + CAIRO_SURFACE_TYPE_XLIB, + _cairo_xlib_surface_finish, + + _cairo_default_context_create, + + _cairo_xlib_surface_create_similar, + _cairo_xlib_surface_create_similar_shm, + _cairo_xlib_surface_map_to_image, + _cairo_xlib_surface_unmap_image, + + _cairo_xlib_surface_source, + _cairo_xlib_surface_acquire_source_image, + _cairo_xlib_surface_release_source_image, + _cairo_xlib_surface_snapshot, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_xlib_surface_get_extents, + _cairo_xlib_surface_get_font_options, + + _cairo_xlib_surface_flush, + NULL, /* mark_dirty_rectangle */ + + _cairo_xlib_surface_paint, + _cairo_xlib_surface_mask, + _cairo_xlib_surface_stroke, + _cairo_xlib_surface_fill, + NULL, /* fill-stroke */ + _cairo_xlib_surface_glyphs, +}; + +/** + * _cairo_surface_is_xlib: + * @surface: a #cairo_surface_t + * + * Checks if a surface is a #cairo_xlib_surface_t + * + * Return value: True if the surface is an xlib surface + **/ +static cairo_bool_t +_cairo_surface_is_xlib (cairo_surface_t *surface) +{ + return surface->backend == &cairo_xlib_surface_backend; +} + +static cairo_surface_t * +_cairo_xlib_surface_create_internal (cairo_xlib_screen_t *screen, + Drawable drawable, + Visual *visual, + XRenderPictFormat *xrender_format, + int width, + int height, + int depth) +{ + cairo_xlib_surface_t *surface; + cairo_xlib_display_t *display; + cairo_status_t status; + + if (depth == 0) { + if (xrender_format) { + depth = xrender_format->depth; + + /* XXX find matching visual for core/dithering fallbacks? */ + } else if (visual) { + Screen *scr = screen->screen; + + if (visual == DefaultVisualOfScreen (scr)) { + depth = DefaultDepthOfScreen (scr); + } else { + int j, k; + + /* This is ugly, but we have to walk over all visuals + * for the display to find the correct depth. + */ + depth = 0; + for (j = 0; j < scr->ndepths; j++) { + Depth *d = &scr->depths[j]; + for (k = 0; k < d->nvisuals; k++) { + if (&d->visuals[k] == visual) { + depth = d->depth; + goto found; + } + } + } + } + } + + if (depth == 0) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); + +found: + ; + } + + surface = malloc (sizeof (cairo_xlib_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + status = _cairo_xlib_display_acquire (screen->device, &display); + if (unlikely (status)) { + free (surface); + return _cairo_surface_create_in_error (_cairo_error (status)); + } + + surface->display = display; + if (CAIRO_RENDER_HAS_CREATE_PICTURE (display)) { + if (!xrender_format) { + if (visual) { + xrender_format = XRenderFindVisualFormat (display->display, visual); + } else if (depth == 1) { + xrender_format = + _cairo_xlib_display_get_xrender_format (display, + CAIRO_FORMAT_A1); + } + } + } + + cairo_device_release (&display->base); + + _cairo_surface_init (&surface->base, + &cairo_xlib_surface_backend, + screen->device, + _xrender_format_to_content (xrender_format)); + + surface->screen = screen; + surface->compositor = display->compositor; + surface->shm = NULL; + surface->fallback = 0; + + surface->drawable = drawable; + surface->owns_pixmap = FALSE; + surface->use_pixmap = 0; + surface->width = width; + surface->height = height; + + surface->picture = None; + surface->precision = PolyModePrecise; + + surface->embedded_source.picture = None; + + surface->visual = visual; + surface->xrender_format = xrender_format; + surface->depth = depth; + + /* + * Compute the pixel format masks from either a XrenderFormat or + * else from a visual; failing that we assume the drawable is an + * alpha-only pixmap as it could only have been created that way + * through the cairo_xlib_surface_create_for_bitmap function. + */ + if (xrender_format) { + surface->a_mask = (unsigned long) + surface->xrender_format->direct.alphaMask + << surface->xrender_format->direct.alpha; + surface->r_mask = (unsigned long) + surface->xrender_format->direct.redMask + << surface->xrender_format->direct.red; + surface->g_mask = (unsigned long) + surface->xrender_format->direct.greenMask + << surface->xrender_format->direct.green; + surface->b_mask = (unsigned long) + surface->xrender_format->direct.blueMask + << surface->xrender_format->direct.blue; + } else if (visual) { + surface->a_mask = 0; + surface->r_mask = visual->red_mask; + surface->g_mask = visual->green_mask; + surface->b_mask = visual->blue_mask; + } else { + if (depth < 32) + surface->a_mask = (1 << depth) - 1; + else + surface->a_mask = 0xffffffff; + surface->r_mask = 0; + surface->g_mask = 0; + surface->b_mask = 0; + } + + cairo_list_add (&surface->link, &screen->surfaces); + + return &surface->base; +} + +static Screen * +_cairo_xlib_screen_from_visual (Display *dpy, Visual *visual) +{ + int s, d, v; + + for (s = 0; s < ScreenCount (dpy); s++) { + Screen *screen; + + screen = ScreenOfDisplay (dpy, s); + if (visual == DefaultVisualOfScreen (screen)) + return screen; + + for (d = 0; d < screen->ndepths; d++) { + Depth *depth; + + depth = &screen->depths[d]; + for (v = 0; v < depth->nvisuals; v++) + if (visual == &depth->visuals[v]) + return screen; + } + } + + return NULL; +} + +static cairo_bool_t valid_size (int width, int height) +{ + /* Note: the minimum surface size allowed in the X protocol is 1x1. + * However, as we historically did not check the minimum size we + * allowed applications to lie and set the correct size later (one hopes). + * To preserve compatability we must allow applications to use + * 0x0 surfaces. + */ + return (width >= 0 && width <= XLIB_COORD_MAX && + height >= 0 && height <= XLIB_COORD_MAX); +} + +/** + * cairo_xlib_surface_create: + * @dpy: an X Display + * @drawable: an X Drawable, (a Pixmap or a Window) + * @visual: the visual to use for drawing to @drawable. The depth + * of the visual must match the depth of the drawable. + * Currently, only TrueColor visuals are fully supported. + * @width: the current width of @drawable. + * @height: the current height of @drawable. + * + * Creates an Xlib surface that draws to the given drawable. + * The way that colors are represented in the drawable is specified + * by the provided visual. + * + * Note: If @drawable is a Window, then the function + * cairo_xlib_surface_set_size() must be called whenever the size of the + * window changes. + * + * When @drawable is a Window containing child windows then drawing to + * the created surface will be clipped by those child windows. When + * the created surface is used as a source, the contents of the + * children will be included. + * + * Return value: the newly created surface + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_xlib_surface_create (Display *dpy, + Drawable drawable, + Visual *visual, + int width, + int height) +{ + Screen *scr; + cairo_xlib_screen_t *screen; + cairo_status_t status; + + if (! valid_size (width, height)) { + /* you're lying, and you know it! */ + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + } + + scr = _cairo_xlib_screen_from_visual (dpy, visual); + if (scr == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); + + status = _cairo_xlib_screen_get (dpy, scr, &screen); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + X_DEBUG ((dpy, "create (drawable=%x)", (unsigned int) drawable)); + + return _cairo_xlib_surface_create_internal (screen, drawable, + visual, NULL, + width, height, 0); +} + +/** + * cairo_xlib_surface_create_for_bitmap: + * @dpy: an X Display + * @bitmap: an X Drawable, (a depth-1 Pixmap) + * @screen: the X Screen associated with @bitmap + * @width: the current width of @bitmap. + * @height: the current height of @bitmap. + * + * Creates an Xlib surface that draws to the given bitmap. + * This will be drawn to as a %CAIRO_FORMAT_A1 object. + * + * Return value: the newly created surface + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_xlib_surface_create_for_bitmap (Display *dpy, + Pixmap bitmap, + Screen *scr, + int width, + int height) +{ + cairo_xlib_screen_t *screen; + cairo_status_t status; + + if (! valid_size (width, height)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + status = _cairo_xlib_screen_get (dpy, scr, &screen); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + X_DEBUG ((dpy, "create_for_bitmap (drawable=%x)", (unsigned int) bitmap)); + + return _cairo_xlib_surface_create_internal (screen, bitmap, + NULL, NULL, + width, height, 1); +} + +#if CAIRO_HAS_XLIB_XRENDER_SURFACE +/** + * cairo_xlib_surface_create_with_xrender_format: + * @dpy: an X Display + * @drawable: an X Drawable, (a Pixmap or a Window) + * @screen: the X Screen associated with @drawable + * @format: the picture format to use for drawing to @drawable. The depth + * of @format must match the depth of the drawable. + * @width: the current width of @drawable. + * @height: the current height of @drawable. + * + * Creates an Xlib surface that draws to the given drawable. + * The way that colors are represented in the drawable is specified + * by the provided picture format. + * + * Note: If @drawable is a Window, then the function + * cairo_xlib_surface_set_size() must be called whenever the size of the + * window changes. + * + * Return value: the newly created surface + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_xlib_surface_create_with_xrender_format (Display *dpy, + Drawable drawable, + Screen *scr, + XRenderPictFormat *format, + int width, + int height) +{ + cairo_xlib_screen_t *screen; + cairo_status_t status; + + if (! valid_size (width, height)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + + status = _cairo_xlib_screen_get (dpy, scr, &screen); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + X_DEBUG ((dpy, "create_with_xrender_format (drawable=%x)", (unsigned int) drawable)); + + return _cairo_xlib_surface_create_internal (screen, drawable, + _visual_for_xrender_format (scr, format), + format, width, height, 0); +} + +/** + * cairo_xlib_surface_get_xrender_format: + * @surface: an xlib surface + * + * Gets the X Render picture format that @surface uses for rendering with the + * X Render extension. If the surface was created by + * cairo_xlib_surface_create_with_xrender_format() originally, the return + * value is the format passed to that constructor. + * + * Return value: the XRenderPictFormat* associated with @surface, + * or %NULL if the surface is not an xlib surface + * or if the X Render extension is not available. + * + * Since: 1.6 + **/ +XRenderPictFormat * +cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface) +{ + cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *) surface; + + /* Throw an error for a non-xlib surface */ + if (! _cairo_surface_is_xlib (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return xlib_surface->xrender_format; +} +#endif + +/** + * cairo_xlib_surface_set_size: + * @surface: a #cairo_surface_t for the XLib backend + * @width: the new width of the surface + * @height: the new height of the surface + * + * Informs cairo of the new size of the X Drawable underlying the + * surface. For a surface created for a Window (rather than a Pixmap), + * this function must be called each time the size of the window + * changes. (For a subwindow, you are normally resizing the window + * yourself, but for a toplevel window, it is necessary to listen for + * ConfigureNotify events.) + * + * A Pixmap can never change size, so it is never necessary to call + * this function on a surface created for a Pixmap. + * + * Since: 1.0 + **/ +void +cairo_xlib_surface_set_size (cairo_surface_t *abstract_surface, + int width, + int height) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; + cairo_status_t status; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + if (surface->width == width && surface->height == height) + return; + + if (! valid_size (width, height)) { + _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_INVALID_SIZE)); + return; + } + + status = _cairo_surface_flush (abstract_surface, 0); + if (unlikely (status)) { + _cairo_surface_set_error (abstract_surface, status); + return; + } + + _cairo_xlib_surface_discard_shm (surface); + + surface->width = width; + surface->height = height; +} + +/** + * cairo_xlib_surface_set_drawable: + * @surface: a #cairo_surface_t for the XLib backend + * @drawable: the new drawable for the surface + * @width: the width of the new drawable + * @height: the height of the new drawable + * + * Informs cairo of a new X Drawable underlying the + * surface. The drawable must match the display, screen + * and format of the existing drawable or the application + * will get X protocol errors and will probably terminate. + * No checks are done by this function to ensure this + * compatibility. + * + * Since: 1.0 + **/ +void +cairo_xlib_surface_set_drawable (cairo_surface_t *abstract_surface, + Drawable drawable, + int width, + int height) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *)abstract_surface; + cairo_status_t status; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (! _cairo_surface_is_xlib (abstract_surface)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH)); + return; + } + + if (! valid_size (width, height)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_INVALID_SIZE)); + return; + } + + /* XXX: and what about this case? */ + if (surface->owns_pixmap) + return; + + status = _cairo_surface_flush (abstract_surface, 0); + if (unlikely (status)) { + _cairo_surface_set_error (abstract_surface, status); + return; + } + + if (surface->drawable != drawable) { + cairo_xlib_display_t *display; + + status = _cairo_xlib_display_acquire (surface->base.device, &display); + if (unlikely (status)) + return; + + X_DEBUG ((display->display, "set_drawable (drawable=%x)", (unsigned int) drawable)); + + if (surface->picture != None) { + XRenderFreePicture (display->display, surface->picture); + if (unlikely (status)) { + status = _cairo_surface_set_error (&surface->base, status); + return; + } + + surface->picture = None; + } + + cairo_device_release (&display->base); + + surface->drawable = drawable; + } + + if (surface->width != width || surface->height != height) { + _cairo_xlib_surface_discard_shm (surface); + + surface->width = width; + surface->height = height; + } +} + +/** + * cairo_xlib_surface_get_display: + * @surface: a #cairo_xlib_surface_t + * + * Get the X Display for the underlying X Drawable. + * + * Return value: the display. + * + * Since: 1.2 + **/ +Display * +cairo_xlib_surface_get_display (cairo_surface_t *abstract_surface) +{ + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return ((cairo_xlib_display_t *) abstract_surface->device)->display; +} + +/** + * cairo_xlib_surface_get_drawable: + * @surface: a #cairo_xlib_surface_t + * + * Get the underlying X Drawable used for the surface. + * + * Return value: the drawable. + * + * Since: 1.2 + **/ +Drawable +cairo_xlib_surface_get_drawable (cairo_surface_t *abstract_surface) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; + + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->drawable; +} + +/** + * cairo_xlib_surface_get_screen: + * @surface: a #cairo_xlib_surface_t + * + * Get the X Screen for the underlying X Drawable. + * + * Return value: the screen. + * + * Since: 1.2 + **/ +Screen * +cairo_xlib_surface_get_screen (cairo_surface_t *abstract_surface) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; + + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return surface->screen->screen; +} + +/** + * cairo_xlib_surface_get_visual: + * @surface: a #cairo_xlib_surface_t + * + * Gets the X Visual associated with @surface, suitable for use with the + * underlying X Drawable. If @surface was created by + * cairo_xlib_surface_create(), the return value is the Visual passed to that + * constructor. + * + * Return value: the Visual or %NULL if there is no appropriate Visual for + * @surface. + * + * Since: 1.2 + **/ +Visual * +cairo_xlib_surface_get_visual (cairo_surface_t *surface) +{ + cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *) surface; + + if (! _cairo_surface_is_xlib (surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return xlib_surface->visual; +} + +/** + * cairo_xlib_surface_get_depth: + * @surface: a #cairo_xlib_surface_t + * + * Get the number of bits used to represent each pixel value. + * + * Return value: the depth of the surface in bits. + * + * Since: 1.2 + **/ +int +cairo_xlib_surface_get_depth (cairo_surface_t *abstract_surface) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; + + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->depth; +} + +/** + * cairo_xlib_surface_get_width: + * @surface: a #cairo_xlib_surface_t + * + * Get the width of the X Drawable underlying the surface in pixels. + * + * Return value: the width of the surface in pixels. + * + * Since: 1.2 + **/ +int +cairo_xlib_surface_get_width (cairo_surface_t *abstract_surface) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; + + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->width; +} + +/** + * cairo_xlib_surface_get_height: + * @surface: a #cairo_xlib_surface_t + * + * Get the height of the X Drawable underlying the surface in pixels. + * + * Return value: the height of the surface in pixels. + * + * Since: 1.2 + **/ +int +cairo_xlib_surface_get_height (cairo_surface_t *abstract_surface) +{ + cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; + + if (! _cairo_surface_is_xlib (abstract_surface)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->height; +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-visual.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-visual.c new file mode 100644 index 00000000000..863822eebbd --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-visual.c @@ -0,0 +1,194 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2008 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl D. Worth + */ + +#include "cairoint.h" + +#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib-private.h" + +#include "cairo-error-private.h" +#include "cairo-list-inline.h" + +/* A perceptual distance metric between two colors. No sqrt needed + * since the square of the distance is still a valid metric. */ + +/* XXX: This is currently using linear distance in RGB space which is + * decidedly not perceptually linear. If someone cared a lot about the + * quality, they might choose something else here. Then again, they + * might also choose not to use a PseudoColor visual... */ +static inline int +_color_distance (unsigned short r1, unsigned short g1, unsigned short b1, + unsigned short r2, unsigned short g2, unsigned short b2) +{ + r1 >>= 8; g1 >>= 8; b1 >>= 8; + r2 >>= 8; g2 >>= 8; b2 >>= 8; + + return ((r2 - r1) * (r2 - r1) + + (g2 - g1) * (g2 - g1) + + (b2 - b1) * (b2 - b1)); +} + +cairo_status_t +_cairo_xlib_visual_info_create (Display *dpy, + int screen, + VisualID visualid, + cairo_xlib_visual_info_t **out) +{ + cairo_xlib_visual_info_t *info; + Colormap colormap = DefaultColormap (dpy, screen); + XColor color; + int gray, red, green, blue; + int i, j, distance, min_distance = 0; + XColor colors[256]; + unsigned short cube_index_to_short[CUBE_SIZE]; + unsigned short ramp_index_to_short[RAMP_SIZE]; + unsigned char gray_to_pseudocolor[RAMP_SIZE]; + + for (i = 0; i < CUBE_SIZE; i++) + cube_index_to_short[i] = (0xffff * i + ((CUBE_SIZE-1)>>1)) / (CUBE_SIZE-1); + for (i = 0; i < RAMP_SIZE; i++) + ramp_index_to_short[i] = (0xffff * i + ((RAMP_SIZE-1)>>1)) / (RAMP_SIZE-1); + + info = malloc (sizeof (cairo_xlib_visual_info_t)); + if (unlikely (info == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + cairo_list_init (&info->link); + info->visualid = visualid; + + /* Allocate a gray ramp and a color cube. + * Give up as soon as failures start. */ + + for (gray = 0; gray < RAMP_SIZE; gray++) { + color.red = color.green = color.blue = ramp_index_to_short[gray]; + if (! XAllocColor (dpy, colormap, &color)) + goto DONE_ALLOCATE; + } + + /* XXX: Could do this in a more clever order to have the best + * possible results from early failure. Could also choose a cube + * uniformly distributed in a better space than RGB. */ + for (red = 0; red < CUBE_SIZE; red++) { + for (green = 0; green < CUBE_SIZE; green++) { + for (blue = 0; blue < CUBE_SIZE; blue++) { + color.red = cube_index_to_short[red]; + color.green = cube_index_to_short[green]; + color.blue = cube_index_to_short[blue]; + color.pixel = 0; + color.flags = 0; + color.pad = 0; + if (! XAllocColor (dpy, colormap, &color)) + goto DONE_ALLOCATE; + } + } + } + DONE_ALLOCATE: + + for (i = 0; i < ARRAY_LENGTH (colors); i++) + colors[i].pixel = i; + XQueryColors (dpy, colormap, colors, ARRAY_LENGTH (colors)); + + /* Search for nearest colors within allocated colormap. */ + for (gray = 0; gray < RAMP_SIZE; gray++) { + for (i = 0; i < 256; i++) { + distance = _color_distance (ramp_index_to_short[gray], + ramp_index_to_short[gray], + ramp_index_to_short[gray], + colors[i].red, + colors[i].green, + colors[i].blue); + if (i == 0 || distance < min_distance) { + gray_to_pseudocolor[gray] = colors[i].pixel; + min_distance = distance; + if (!min_distance) + break; + } + } + } + for (red = 0; red < CUBE_SIZE; red++) { + for (green = 0; green < CUBE_SIZE; green++) { + for (blue = 0; blue < CUBE_SIZE; blue++) { + for (i = 0; i < 256; i++) { + distance = _color_distance (cube_index_to_short[red], + cube_index_to_short[green], + cube_index_to_short[blue], + colors[i].red, + colors[i].green, + colors[i].blue); + if (i == 0 || distance < min_distance) { + info->cube_to_pseudocolor[red][green][blue] = colors[i].pixel; + min_distance = distance; + if (!min_distance) + break; + } + } + } + } + } + + for (i = 0, j = 0; i < 256; i++) { + if (j < CUBE_SIZE - 1 && (((i<<8)+i) - (int)cube_index_to_short[j]) > ((int)cube_index_to_short[j+1] - ((i<<8)+i))) + j++; + info->field8_to_cube[i] = j; + + info->dither8_to_cube[i] = ((int)i - 128) / (CUBE_SIZE - 1); + } + for (i = 0, j = 0; i < 256; i++) { + if (j < RAMP_SIZE - 1 && (((i<<8)+i) - (int)ramp_index_to_short[j]) > ((int)ramp_index_to_short[j+1] - ((i<<8)+i))) + j++; + info->gray8_to_pseudocolor[i] = gray_to_pseudocolor[j]; + } + + for (i = 0; i < 256; i++) { + info->colors[i].a = 0xff; + info->colors[i].r = colors[i].red >> 8; + info->colors[i].g = colors[i].green >> 8; + info->colors[i].b = colors[i].blue >> 8; + } + + *out = info; + return CAIRO_STATUS_SUCCESS; +} + +void +_cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info) +{ + /* No need for XFreeColors() whilst using DefaultColormap */ + _cairo_list_del (&info->link); + free (info); +} + +#endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xcb-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xcb-surface.c new file mode 100644 index 00000000000..af3e1557899 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xcb-surface.c @@ -0,0 +1,847 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" + +#if CAIRO_HAS_XLIB_XCB_FUNCTIONS + +#include "cairo-xlib.h" +#include "cairo-xcb.h" + +#include "cairo-xcb-private.h" +#include "cairo-xlib-xrender-private.h" + +#include "cairo-default-context-private.h" +#include "cairo-list-inline.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-backend-private.h" + +#include +#include /* For XESetCloseDisplay */ + +struct cairo_xlib_xcb_display_t { + cairo_device_t base; + + Display *dpy; + cairo_device_t *xcb_device; + XExtCodes *codes; + + cairo_list_t link; +}; +typedef struct cairo_xlib_xcb_display_t cairo_xlib_xcb_display_t; + +/* List of all #cairo_xlib_xcb_display_t alive, + * protected by _cairo_xlib_display_mutex */ +static cairo_list_t displays; + +static cairo_surface_t * +_cairo_xlib_xcb_surface_create (void *dpy, + void *scr, + void *visual, + void *format, + cairo_surface_t *xcb); + +static cairo_surface_t * +_cairo_xlib_xcb_surface_create_similar (void *abstract_other, + cairo_content_t content, + int width, + int height) +{ + cairo_xlib_xcb_surface_t *other = abstract_other; + cairo_surface_t *xcb; + + xcb = other->xcb->base.backend->create_similar (other->xcb, content, width, height); + if (unlikely (xcb == NULL || xcb->status)) + return xcb; + + return _cairo_xlib_xcb_surface_create (other->display, other->screen, NULL, NULL, xcb); +} + +static cairo_status_t +_cairo_xlib_xcb_surface_finish (void *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + cairo_status_t status; + + cairo_surface_finish (&surface->xcb->base); + status = surface->xcb->base.status; + cairo_surface_destroy (&surface->xcb->base); + surface->xcb = NULL; + + return status; +} + +static cairo_surface_t * +_cairo_xlib_xcb_surface_create_similar_image (void *abstract_other, + cairo_format_t format, + int width, + int height) +{ + cairo_xlib_xcb_surface_t *surface = abstract_other; + return cairo_surface_create_similar_image (&surface->xcb->base, format, width, height); +} + +static cairo_image_surface_t * +_cairo_xlib_xcb_surface_map_to_image (void *abstract_surface, + const cairo_rectangle_int_t *extents) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_map_to_image (&surface->xcb->base, extents); +} + +static cairo_int_status_t +_cairo_xlib_xcb_surface_unmap (void *abstract_surface, + cairo_image_surface_t *image) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_unmap_image (&surface->xcb->base, image); +} + +static cairo_surface_t * +_cairo_xlib_xcb_surface_source (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_get_source (&surface->xcb->base, extents); +} + +static cairo_status_t +_cairo_xlib_xcb_surface_acquire_source_image (void *abstract_surface, + cairo_image_surface_t **image_out, + void **image_extra) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_acquire_source_image (&surface->xcb->base, + image_out, image_extra); +} + +static void +_cairo_xlib_xcb_surface_release_source_image (void *abstract_surface, + cairo_image_surface_t *image_out, + void *image_extra) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + _cairo_surface_release_source_image (&surface->xcb->base, image_out, image_extra); +} + +static cairo_bool_t +_cairo_xlib_xcb_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *extents) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_get_extents (&surface->xcb->base, extents); +} + +static void +_cairo_xlib_xcb_surface_get_font_options (void *abstract_surface, + cairo_font_options_t *options) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + cairo_surface_get_font_options (&surface->xcb->base, options); +} + +static cairo_int_status_t +_cairo_xlib_xcb_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_paint (&surface->xcb->base, op, source, clip); +} + +static cairo_int_status_t +_cairo_xlib_xcb_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_mask (&surface->xcb->base, op, source, mask, clip); +} + +static cairo_int_status_t +_cairo_xlib_xcb_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_stroke (&surface->xcb->base, + op, source, path, style, ctm, ctm_inverse, + tolerance, antialias, clip); +} + +static cairo_int_status_t +_cairo_xlib_xcb_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_fill (&surface->xcb->base, + op, source, path, + fill_rule, tolerance, + antialias, clip); +} + +static cairo_int_status_t +_cairo_xlib_xcb_surface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + return _cairo_surface_show_text_glyphs (&surface->xcb->base, op, source, + NULL, 0, + glyphs, num_glyphs, + NULL, 0, 0, + scaled_font, clip); +} + +static cairo_status_t +_cairo_xlib_xcb_surface_flush (void *abstract_surface, unsigned flags) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + /* We have to call cairo_surface_flush() to make sure snapshots are detached */ + return _cairo_surface_flush (&surface->xcb->base, flags); +} + +static cairo_status_t +_cairo_xlib_xcb_surface_mark_dirty (void *abstract_surface, + int x, int y, + int width, int height) +{ + cairo_xlib_xcb_surface_t *surface = abstract_surface; + cairo_surface_mark_dirty_rectangle (&surface->xcb->base, x, y, width, height); + return cairo_surface_status (&surface->xcb->base); +} + +static const cairo_surface_backend_t _cairo_xlib_xcb_surface_backend = { + CAIRO_SURFACE_TYPE_XLIB, + _cairo_xlib_xcb_surface_finish, + + _cairo_default_context_create, /* XXX */ + + _cairo_xlib_xcb_surface_create_similar, + _cairo_xlib_xcb_surface_create_similar_image, + _cairo_xlib_xcb_surface_map_to_image, + _cairo_xlib_xcb_surface_unmap, + + _cairo_xlib_xcb_surface_source, + _cairo_xlib_xcb_surface_acquire_source_image, + _cairo_xlib_xcb_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_xlib_xcb_surface_get_extents, + _cairo_xlib_xcb_surface_get_font_options, + + _cairo_xlib_xcb_surface_flush, + _cairo_xlib_xcb_surface_mark_dirty, + + _cairo_xlib_xcb_surface_paint, + _cairo_xlib_xcb_surface_mask, + _cairo_xlib_xcb_surface_stroke, + _cairo_xlib_xcb_surface_fill, + NULL, /* fill_stroke */ + _cairo_xlib_xcb_surface_glyphs, +}; + +static void +_cairo_xlib_xcb_display_finish (void *abstract_display) +{ + cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) abstract_display; + + CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); + cairo_list_del (&display->link); + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + + cairo_device_destroy (display->xcb_device); + display->xcb_device = NULL; + + XESetCloseDisplay (display->dpy, display->codes->extension, NULL); + /* Drop the reference from _cairo_xlib_xcb_device_create */ + cairo_device_destroy (&display->base); +} + +static int +_cairo_xlib_xcb_close_display(Display *dpy, XExtCodes *codes) +{ + cairo_xlib_xcb_display_t *display; + + CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); + cairo_list_foreach_entry (display, + cairo_xlib_xcb_display_t, + &displays, + link) + { + if (display->dpy == dpy) + { + /* _cairo_xlib_xcb_display_finish will lock the mutex again + * -> deadlock (This mutex isn't recursive) */ + cairo_device_reference (&display->base); + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + + /* Make sure the xcb and xlib-xcb devices are finished */ + cairo_device_finish (display->xcb_device); + cairo_device_finish (&display->base); + + cairo_device_destroy (&display->base); + return 0; + } + } + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + + return 0; +} + +static const cairo_device_backend_t _cairo_xlib_xcb_device_backend = { + CAIRO_DEVICE_TYPE_XLIB, + + NULL, + NULL, + + NULL, /* flush */ + _cairo_xlib_xcb_display_finish, + free, /* destroy */ +}; + +static cairo_device_t * +_cairo_xlib_xcb_device_create (Display *dpy, cairo_device_t *xcb_device) +{ + cairo_xlib_xcb_display_t *display = NULL; + cairo_device_t *device; + + if (xcb_device == NULL) + return NULL; + + CAIRO_MUTEX_INITIALIZE (); + + CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex); + if (displays.next == NULL) { + cairo_list_init (&displays); + } + + cairo_list_foreach_entry (display, + cairo_xlib_xcb_display_t, + &displays, + link) + { + if (display->dpy == dpy) { + /* Maintain MRU order. */ + if (displays.next != &display->link) + cairo_list_move (&display->link, &displays); + + /* Grab a reference for our caller */ + device = cairo_device_reference (&display->base); + assert (display->xcb_device == xcb_device); + goto unlock; + } + } + + display = malloc (sizeof (cairo_xlib_xcb_display_t)); + if (unlikely (display == NULL)) { + device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); + goto unlock; + } + + display->codes = XAddExtension (dpy); + if (unlikely (display->codes == NULL)) { + device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); + free (display); + goto unlock; + } + + _cairo_device_init (&display->base, &_cairo_xlib_xcb_device_backend); + + XESetCloseDisplay (dpy, display->codes->extension, _cairo_xlib_xcb_close_display); + /* Add a reference for _cairo_xlib_xcb_display_finish. This basically means + * that the device's reference count never drops to zero + * as long as our Display* is alive. We need this because there is no + * "XDelExtension" to undo XAddExtension and having lots of registered + * extensions slows down libX11. */ + cairo_device_reference (&display->base); + + display->dpy = dpy; + display->xcb_device = cairo_device_reference(xcb_device); + + cairo_list_add (&display->link, &displays); + device = &display->base; + +unlock: + CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex); + + return device; +} + +static cairo_surface_t * +_cairo_xlib_xcb_surface_create (void *dpy, + void *scr, + void *visual, + void *format, + cairo_surface_t *xcb) +{ + cairo_xlib_xcb_surface_t *surface; + + if (unlikely (xcb->status)) + return xcb; + + surface = malloc (sizeof (*surface)); + if (unlikely (surface == NULL)) { + cairo_surface_destroy (xcb); + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); + } + + _cairo_surface_init (&surface->base, + &_cairo_xlib_xcb_surface_backend, + _cairo_xlib_xcb_device_create (dpy, xcb->device), + xcb->content); + + /* _cairo_surface_init() got another reference to the device, drop ours */ + cairo_device_destroy (surface->base.device); + + surface->display = dpy; + surface->screen = scr; + surface->visual = visual; + surface->format = format; + surface->xcb = (cairo_xcb_surface_t *) xcb; + + return &surface->base; +} + +static Screen * +_cairo_xlib_screen_from_visual (Display *dpy, Visual *visual) +{ + int s, d, v; + + for (s = 0; s < ScreenCount (dpy); s++) { + Screen *screen; + + screen = ScreenOfDisplay (dpy, s); + if (visual == DefaultVisualOfScreen (screen)) + return screen; + + for (d = 0; d < screen->ndepths; d++) { + Depth *depth; + + depth = &screen->depths[d]; + for (v = 0; v < depth->nvisuals; v++) + if (visual == &depth->visuals[v]) + return screen; + } + } + + return NULL; +} + +cairo_surface_t * +cairo_xlib_surface_create (Display *dpy, + Drawable drawable, + Visual *visual, + int width, + int height) +{ + Screen *scr; + xcb_visualtype_t xcb_visual; + + scr = _cairo_xlib_screen_from_visual (dpy, visual); + if (scr == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); + + xcb_visual.visual_id = visual->visualid; +#if defined(__cplusplus) || defined(c_plusplus) + xcb_visual._class = visual->c_class; +#else + xcb_visual._class = visual->class; +#endif + xcb_visual.bits_per_rgb_value = visual->bits_per_rgb; + xcb_visual.colormap_entries = visual->map_entries; + xcb_visual.red_mask = visual->red_mask; + xcb_visual.green_mask = visual->green_mask; + xcb_visual.blue_mask = visual->blue_mask; + + return _cairo_xlib_xcb_surface_create (dpy, scr, visual, NULL, + cairo_xcb_surface_create (XGetXCBConnection (dpy), + drawable, + &xcb_visual, + width, height)); +} + +static xcb_screen_t * +_cairo_xcb_screen_from_root (xcb_connection_t *connection, + xcb_window_t id) +{ + xcb_screen_iterator_t s; + + s = xcb_setup_roots_iterator (xcb_get_setup (connection)); + for (; s.rem; xcb_screen_next (&s)) { + if (s.data->root == id) + return s.data; + } + + return NULL; +} + +cairo_surface_t * +cairo_xlib_surface_create_for_bitmap (Display *dpy, + Pixmap bitmap, + Screen *scr, + int width, + int height) +{ + xcb_connection_t *connection = XGetXCBConnection (dpy); + xcb_screen_t *screen = _cairo_xcb_screen_from_root (connection, (xcb_window_t) scr->root); + return _cairo_xlib_xcb_surface_create (dpy, scr, NULL, NULL, + cairo_xcb_surface_create_for_bitmap (connection, + screen, + bitmap, + width, height)); +} + +#if CAIRO_HAS_XLIB_XRENDER_SURFACE +cairo_surface_t * +cairo_xlib_surface_create_with_xrender_format (Display *dpy, + Drawable drawable, + Screen *scr, + XRenderPictFormat *format, + int width, + int height) +{ + xcb_render_pictforminfo_t xcb_format; + xcb_connection_t *connection; + xcb_screen_t *screen; + + xcb_format.id = format->id; + xcb_format.type = format->type; + xcb_format.depth = format->depth; + xcb_format.direct.red_shift = format->direct.red; + xcb_format.direct.red_mask = format->direct.redMask; + xcb_format.direct.green_shift = format->direct.green; + xcb_format.direct.green_mask = format->direct.greenMask; + xcb_format.direct.blue_shift = format->direct.blue; + xcb_format.direct.blue_mask = format->direct.blueMask; + xcb_format.direct.alpha_shift = format->direct.alpha; + xcb_format.direct.alpha_mask = format->direct.alphaMask; + xcb_format.colormap = format->colormap; + + connection = XGetXCBConnection (dpy); + screen = _cairo_xcb_screen_from_root (connection, (xcb_window_t) scr->root); + + return _cairo_xlib_xcb_surface_create (dpy, scr, NULL, format, + cairo_xcb_surface_create_with_xrender_format (connection, screen, + drawable, + &xcb_format, + width, height)); +} + +XRenderPictFormat * +cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface) +{ + cairo_xlib_xcb_surface_t *xlib_surface = (cairo_xlib_xcb_surface_t *) surface; + + /* Throw an error for a non-xlib surface */ + if (surface->type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return xlib_surface->format; +} +#endif + +void +cairo_xlib_surface_set_size (cairo_surface_t *abstract_surface, + int width, + int height) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + cairo_status_t status; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + status = _cairo_surface_set_error (abstract_surface, + CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return; + } + + cairo_xcb_surface_set_size (&surface->xcb->base, width, height); + if (unlikely (surface->xcb->base.status)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (surface->xcb->base.status)); + } +} + +void +cairo_xlib_surface_set_drawable (cairo_surface_t *abstract_surface, + Drawable drawable, + int width, + int height) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *)abstract_surface; + cairo_status_t status; + + if (unlikely (abstract_surface->status)) + return; + if (unlikely (abstract_surface->finished)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + return; + } + + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + status = _cairo_surface_set_error (abstract_surface, + CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return; + } + + cairo_xcb_surface_set_drawable (&surface->xcb->base, drawable, width, height); + if (unlikely (surface->xcb->base.status)) { + status = _cairo_surface_set_error (abstract_surface, + _cairo_error (surface->xcb->base.status)); + } +} + +Display * +cairo_xlib_surface_get_display (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return surface->display; +} + +Drawable +cairo_xlib_surface_get_drawable (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (unlikely (abstract_surface->finished)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); + return 0; + } + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + /* This can happen when e.g. create_similar falls back to an image surface + * because we don't have the RENDER extension. */ + if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->xcb->drawable; +} + +Screen * +cairo_xlib_surface_get_screen (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return surface->screen; +} + +Visual * +cairo_xlib_surface_get_visual (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return NULL; + } + + return surface->visual; +} + +int +cairo_xlib_surface_get_depth (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (unlikely (abstract_surface->finished)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); + return 0; + } + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + /* This can happen when e.g. create_similar falls back to an image surface + * because we don't have the RENDER extension. */ + if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->xcb->depth; +} + +int +cairo_xlib_surface_get_width (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (unlikely (abstract_surface->finished)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); + return 0; + } + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + /* This can happen when e.g. create_similar falls back to an image surface + * because we don't have the RENDER extension. */ + if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->xcb->width; +} + +int +cairo_xlib_surface_get_height (cairo_surface_t *abstract_surface) +{ + cairo_xlib_xcb_surface_t *surface = (cairo_xlib_xcb_surface_t *) abstract_surface; + + if (unlikely (abstract_surface->finished)) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_FINISHED); + return 0; + } + if (surface->base.type != CAIRO_SURFACE_TYPE_XLIB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + /* This can happen when e.g. create_similar falls back to an image surface + * because we don't have the RENDER extension. */ + if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) { + _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + return 0; + } + + return surface->xcb->height; +} + +void +cairo_xlib_device_debug_cap_xrender_version (cairo_device_t *device, + int major, int minor) +{ + cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) device; + + if (device == NULL || device->status) + return; + + if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) + return; + + cairo_xcb_device_debug_cap_xrender_version (display->xcb_device, + major, minor); +} + +void +cairo_xlib_device_debug_set_precision (cairo_device_t *device, + int precision) +{ + cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) device; + + if (device == NULL || device->status) + return; + if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return; + } + + cairo_xcb_device_debug_set_precision (display->xcb_device, precision); +} + +int +cairo_xlib_device_debug_get_precision (cairo_device_t *device) +{ + cairo_xlib_xcb_display_t *display = (cairo_xlib_xcb_display_t *) device; + + if (device == NULL || device->status) + return -1; + if (device->backend->type != CAIRO_DEVICE_TYPE_XLIB) { + cairo_status_t status; + + status = _cairo_device_set_error (device, CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + (void) status; + return -1; + } + + return cairo_xcb_device_debug_get_precision (display->xcb_device); +} + +#endif /* CAIRO_HAS_XLIB_XCB_FUNCTIONS */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender-private.h b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender-private.h new file mode 100644 index 00000000000..90769467b2d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender-private.h @@ -0,0 +1,1173 @@ +/* Cairo - a vector graphics library with display and print output + * + * Copyright © 2007 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + */ + +#ifndef CAIRO_XLIB_XRENDER_PRIVATE_H +#define CAIRO_XLIB_XRENDER_PRIVATE_H + +#include "cairo-features.h" +#include "cairo-compiler-private.h" + +#include + +/* These prototypes are used when defining interfaces missing from the + * render headers. As it happens, it is the case that all libxrender + * functions take a pointer as first argument. */ + +__attribute__((__unused__)) static void _void_consume (void *p, ...) { } +__attribute__((__unused__)) static void * _voidp_consume (void *p, ...) { return (void *)0; } +__attribute__((__unused__)) static int _int_consume (void *p, ...) { return 0; } +__attribute__((__unused__)) static void _void_consume_free (Display *p, XID n) { } + + +#if CAIRO_HAS_XLIB_XRENDER_SURFACE + +#include "cairo-xlib-xrender.h" + +#include +#include + +/* We require Render >= 0.6. The following defines were only added in + * 0.10. Make sure they are defined. + */ + +/* Filters included in 0.10 */ +#ifndef FilterConvolution +#define FilterConvolution "convolution" +#endif + +/* Extended repeat attributes included in 0.10 */ +#ifndef RepeatNone +#define RepeatNone 0 +#define RepeatNormal 1 +#define RepeatPad 2 +#define RepeatReflect 3 +#endif + + +#ifndef PictOptBlendMinimum +/* + * Operators only available in version 0.11 + */ +#define PictOpBlendMinimum 0x30 +#define PictOpMultiply 0x30 +#define PictOpScreen 0x31 +#define PictOpOverlay 0x32 +#define PictOpDarken 0x33 +#define PictOpLighten 0x34 +#define PictOpColorDodge 0x35 +#define PictOpColorBurn 0x36 +#define PictOpHardLight 0x37 +#define PictOpSoftLight 0x38 +#define PictOpDifference 0x39 +#define PictOpExclusion 0x3a +#define PictOpHSLHue 0x3b +#define PictOpHSLSaturation 0x3c +#define PictOpHSLColor 0x3d +#define PictOpHSLLuminosity 0x3e +#define PictOpBlendMaximum 0x3e +#endif + +#if !HAVE_XRENDERCREATESOLIDFILL +#define XRenderCreateSolidFill _int_consume +#endif + +#if !HAVE_XRENDERCREATELINEARGRADIENT +#define XRenderCreateLinearGradient _int_consume + +typedef struct _XLinearGradient { + XPointFixed p1; + XPointFixed p2; +} XLinearGradient; +#endif + +#if !HAVE_XRENDERCREATERADIALGRADIENT +#define XRenderCreateRadialGradient _int_consume + +typedef struct _XCircle { + XFixed x; + XFixed y; + XFixed radius; +} XCircle; +typedef struct _XRadialGradient { + XCircle inner; + XCircle outer; +} XRadialGradient; +#endif + +#if !HAVE_XRENDERCREATECONICALGRADIENT +#define XRenderCreateConicalGradient _int_consume + +typedef struct _XConicalGradient { + XPointFixed center; + XFixed angle; /* in degrees */ +} XConicalGradient; +#endif + + +#else /* !CAIRO_HAS_XLIB_XRENDER_SURFACE */ + +/* Provide dummy symbols and macros to get it compile and take the fallback + * route, just like as if Xrender is not available in the server at run-time. */ + + +/* Functions */ + +#define XRenderQueryExtension _int_consume +#define XRenderQueryVersion _int_consume +#define XRenderQueryFormats _int_consume +#define XRenderQuerySubpixelOrder _int_consume +#define XRenderSetSubpixelOrder _int_consume +#define XRenderFindVisualFormat _voidp_consume +#define XRenderFindFormat _voidp_consume +#define XRenderFindStandardFormat _voidp_consume +#define XRenderQueryPictIndexValues _voidp_consume +#define XRenderCreatePicture _int_consume +#define XRenderChangePicture _void_consume +#define XRenderSetPictureClipRectangles _void_consume +#define XRenderSetPictureClipRegion _void_consume +#define XRenderSetPictureTransform _void_consume +#define XRenderFreePicture _void_consume_free +#define XRenderComposite _void_consume +#define XRenderCreateGlyphSet _int_consume +#define XRenderReferenceGlyphSet _int_consume +#define XRenderFreeGlyphSet _void_consume_free +#define XRenderAddGlyphs _void_consume +#define XRenderFreeGlyphs _void_consume +#define XRenderCompositeString8 _void_consume +#define XRenderCompositeString16 _void_consume +#define XRenderCompositeString32 _void_consume +#define XRenderCompositeText8 (cairo_xrender_composite_text_func_t) _void_consume +#define XRenderCompositeText16 _void_consume +#define XRenderCompositeText32 _void_consume +#define XRenderFillRectangle _void_consume +#define XRenderFillRectangles _void_consume +#define XRenderCompositeTrapezoids _void_consume +#define XRenderCompositeTriangles _void_consume +#define XRenderCompositeTriStrip _void_consume +#define XRenderCompositeTriFan _void_consume +#define XRenderCompositeDoublePoly _void_consume +#define XRenderParseColor _int_consume +#define XRenderCreateCursor _int_consume +#define XRenderQueryFilters _voidp_consume +#define XRenderSetPictureFilter _void_consume +#define XRenderCreateAnimCursor _int_consume +#define XRenderAddTraps _void_consume +#define XRenderCreateSolidFill _int_consume +#define XRenderCreateLinearGradient _int_consume +#define XRenderCreateRadialGradient _int_consume +#define XRenderCreateConicalGradient _int_consume + +#define cairo_xlib_surface_create_with_xrender_format _voidp_consume + + + +/* The rest of this file is copied from various Xrender header files, with + * the following copyright/license information: + * + * Copyright © 2000 SuSE, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of SuSE not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. SuSE makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Keith Packard, SuSE, Inc. + */ + + +/* Copied from X11/extensions/render.h */ + +typedef unsigned long Glyph; +typedef unsigned long GlyphSet; +typedef unsigned long Picture; +typedef unsigned long PictFormat; + +#define BadPictFormat 0 +#define BadPicture 1 +#define BadPictOp 2 +#define BadGlyphSet 3 +#define BadGlyph 4 +#define RenderNumberErrors (BadGlyph+1) + +#define PictTypeIndexed 0 +#define PictTypeDirect 1 + +#define PictOpMinimum 0 +#define PictOpClear 0 +#define PictOpSrc 1 +#define PictOpDst 2 +#define PictOpOver 3 +#define PictOpOverReverse 4 +#define PictOpIn 5 +#define PictOpInReverse 6 +#define PictOpOut 7 +#define PictOpOutReverse 8 +#define PictOpAtop 9 +#define PictOpAtopReverse 10 +#define PictOpXor 11 +#define PictOpAdd 12 +#define PictOpSaturate 13 +#define PictOpMaximum 13 + +/* + * Operators only available in version 0.2 + */ +#define PictOpDisjointMinimum 0x10 +#define PictOpDisjointClear 0x10 +#define PictOpDisjointSrc 0x11 +#define PictOpDisjointDst 0x12 +#define PictOpDisjointOver 0x13 +#define PictOpDisjointOverReverse 0x14 +#define PictOpDisjointIn 0x15 +#define PictOpDisjointInReverse 0x16 +#define PictOpDisjointOut 0x17 +#define PictOpDisjointOutReverse 0x18 +#define PictOpDisjointAtop 0x19 +#define PictOpDisjointAtopReverse 0x1a +#define PictOpDisjointXor 0x1b +#define PictOpDisjointMaximum 0x1b + +#define PictOpConjointMinimum 0x20 +#define PictOpConjointClear 0x20 +#define PictOpConjointSrc 0x21 +#define PictOpConjointDst 0x22 +#define PictOpConjointOver 0x23 +#define PictOpConjointOverReverse 0x24 +#define PictOpConjointIn 0x25 +#define PictOpConjointInReverse 0x26 +#define PictOpConjointOut 0x27 +#define PictOpConjointOutReverse 0x28 +#define PictOpConjointAtop 0x29 +#define PictOpConjointAtopReverse 0x2a +#define PictOpConjointXor 0x2b +#define PictOpConjointMaximum 0x2b + +/* + * Operators only available in version 0.11 + */ +#define PictOpBlendMinimum 0x30 +#define PictOpMultiply 0x30 +#define PictOpScreen 0x31 +#define PictOpOverlay 0x32 +#define PictOpDarken 0x33 +#define PictOpLighten 0x34 +#define PictOpColorDodge 0x35 +#define PictOpColorBurn 0x36 +#define PictOpHardLight 0x37 +#define PictOpSoftLight 0x38 +#define PictOpDifference 0x39 +#define PictOpExclusion 0x3a +#define PictOpHSLHue 0x3b +#define PictOpHSLSaturation 0x3c +#define PictOpHSLColor 0x3d +#define PictOpHSLLuminosity 0x3e +#define PictOpBlendMaximum 0x3e + +#define PolyEdgeSharp 0 +#define PolyEdgeSmooth 1 + +#define PolyModePrecise 0 +#define PolyModeImprecise 1 + +#define CPRepeat (1 << 0) +#define CPAlphaMap (1 << 1) +#define CPAlphaXOrigin (1 << 2) +#define CPAlphaYOrigin (1 << 3) +#define CPClipXOrigin (1 << 4) +#define CPClipYOrigin (1 << 5) +#define CPClipMask (1 << 6) +#define CPGraphicsExposure (1 << 7) +#define CPSubwindowMode (1 << 8) +#define CPPolyEdge (1 << 9) +#define CPPolyMode (1 << 10) +#define CPDither (1 << 11) +#define CPComponentAlpha (1 << 12) +#define CPLastBit 12 + +/* Filters included in 0.6 */ +#define FilterNearest "nearest" +#define FilterBilinear "bilinear" +/* Filters included in 0.10 */ +#define FilterConvolution "convolution" + +#define FilterFast "fast" +#define FilterGood "good" +#define FilterBest "best" + +#define FilterAliasNone -1 + +/* Subpixel orders included in 0.6 */ +#define SubPixelUnknown 0 +#define SubPixelHorizontalRGB 1 +#define SubPixelHorizontalBGR 2 +#define SubPixelVerticalRGB 3 +#define SubPixelVerticalBGR 4 +#define SubPixelNone 5 + +/* Extended repeat attributes included in 0.10 */ +#define RepeatNone 0 +#define RepeatNormal 1 +#define RepeatPad 2 +#define RepeatReflect 3 + + + +/* Copied from X11/extensions/Xrender.h */ + +typedef struct { + short red; + short redMask; + short green; + short greenMask; + short blue; + short blueMask; + short alpha; + short alphaMask; +} XRenderDirectFormat; + +typedef struct { + PictFormat id; + int type; + int depth; + XRenderDirectFormat direct; + Colormap colormap; +} XRenderPictFormat; + +#define PictFormatID (1 << 0) +#define PictFormatType (1 << 1) +#define PictFormatDepth (1 << 2) +#define PictFormatRed (1 << 3) +#define PictFormatRedMask (1 << 4) +#define PictFormatGreen (1 << 5) +#define PictFormatGreenMask (1 << 6) +#define PictFormatBlue (1 << 7) +#define PictFormatBlueMask (1 << 8) +#define PictFormatAlpha (1 << 9) +#define PictFormatAlphaMask (1 << 10) +#define PictFormatColormap (1 << 11) + +typedef struct _XRenderPictureAttributes { + int repeat; + Picture alpha_map; + int alpha_x_origin; + int alpha_y_origin; + int clip_x_origin; + int clip_y_origin; + Pixmap clip_mask; + Bool graphics_exposures; + int subwindow_mode; + int poly_edge; + int poly_mode; + Atom dither; + Bool component_alpha; +} XRenderPictureAttributes; + +typedef struct { + unsigned short red; + unsigned short green; + unsigned short blue; + unsigned short alpha; +} XRenderColor; + +typedef struct _XGlyphInfo { + unsigned short width; + unsigned short height; + short x; + short y; + short xOff; + short yOff; +} XGlyphInfo; + +typedef struct _XGlyphElt8 { + GlyphSet glyphset; + _Xconst char *chars; + int nchars; + int xOff; + int yOff; +} XGlyphElt8; + +typedef struct _XGlyphElt16 { + GlyphSet glyphset; + _Xconst unsigned short *chars; + int nchars; + int xOff; + int yOff; +} XGlyphElt16; + +typedef struct _XGlyphElt32 { + GlyphSet glyphset; + _Xconst unsigned int *chars; + int nchars; + int xOff; + int yOff; +} XGlyphElt32; + +typedef double XDouble; + +typedef struct _XPointDouble { + XDouble x, y; +} XPointDouble; + +#define XDoubleToFixed(f) ((XFixed) ((f) * 65536)) +#define XFixedToDouble(f) (((XDouble) (f)) / 65536) + +typedef int XFixed; + +typedef struct _XPointFixed { + XFixed x, y; +} XPointFixed; + +typedef struct _XLineFixed { + XPointFixed p1, p2; +} XLineFixed; + +typedef struct _XTriangle { + XPointFixed p1, p2, p3; +} XTriangle; + +typedef struct _XCircle { + XFixed x; + XFixed y; + XFixed radius; +} XCircle; + +typedef struct _XTrapezoid { + XFixed top, bottom; + XLineFixed left, right; +} XTrapezoid; + +typedef struct _XTransform { + XFixed matrix[3][3]; +} XTransform; + +typedef struct _XFilters { + int nfilter; + char **filter; + int nalias; + short *alias; +} XFilters; + +typedef struct _XIndexValue { + unsigned long pixel; + unsigned short red, green, blue, alpha; +} XIndexValue; + +typedef struct _XAnimCursor { + Cursor cursor; + unsigned long delay; +} XAnimCursor; + +typedef struct _XSpanFix { + XFixed left, right, y; +} XSpanFix; + +typedef struct _XTrap { + XSpanFix top, bottom; +} XTrap; + +typedef struct _XLinearGradient { + XPointFixed p1; + XPointFixed p2; +} XLinearGradient; + +typedef struct _XRadialGradient { + XCircle inner; + XCircle outer; +} XRadialGradient; + +typedef struct _XConicalGradient { + XPointFixed center; + XFixed angle; /* in degrees */ +} XConicalGradient; + +#define PictStandardARGB32 0 +#define PictStandardRGB24 1 +#define PictStandardA8 2 +#define PictStandardA4 3 +#define PictStandardA1 4 +#define PictStandardNUM 5 + + + +/* Copied from X11/extensions/renderproto.h */ + +#include + +#define Window CARD32 +#define Drawable CARD32 +#define Font CARD32 +#define Pixmap CARD32 +#define Cursor CARD32 +#define Colormap CARD32 +#define GContext CARD32 +#define Atom CARD32 +#define VisualID CARD32 +#define Time CARD32 +#define KeyCode CARD8 +#define KeySym CARD32 + +#define Picture CARD32 +#define PictFormat CARD32 +#define Fixed INT32 +#define Glyphset CARD32 +#define Glyph CARD32 + +/* + * data structures + */ + +typedef struct { + CARD16 red B16; + CARD16 redMask B16; + CARD16 green B16; + CARD16 greenMask B16; + CARD16 blue B16; + CARD16 blueMask B16; + CARD16 alpha B16; + CARD16 alphaMask B16; +} xDirectFormat; + +#define sz_xDirectFormat 16 + +typedef struct { + PictFormat id B32; + CARD8 type; + CARD8 depth; + CARD16 pad1 B16; + xDirectFormat direct; + Colormap colormap; +} xPictFormInfo; + +#define sz_xPictFormInfo 28 + +typedef struct { + VisualID visual; + PictFormat format; +} xPictVisual; + +#define sz_xPictVisual 8 + +typedef struct { + CARD8 depth; + CARD8 pad1; + CARD16 nPictVisuals B16; + CARD32 pad2 B32; +} xPictDepth; + +#define sz_xPictDepth 8 + +typedef struct { + CARD32 nDepth B32; + PictFormat fallback B32; +} xPictScreen; + +#define sz_xPictScreen 8 + +typedef struct { + CARD32 pixel B32; + CARD16 red B16; + CARD16 green B16; + CARD16 blue B16; + CARD16 alpha B16; +} xIndexValue; + +#define sz_xIndexValue 12 + +typedef struct { + CARD16 red B16; + CARD16 green B16; + CARD16 blue B16; + CARD16 alpha B16; +} xRenderColor; + +#define sz_xRenderColor 8 + +typedef struct { + Fixed x B32; + Fixed y B32; +} xPointFixed; + +#define sz_xPointFixed 8 + +typedef struct { + xPointFixed p1; + xPointFixed p2; +} xLineFixed; + +#define sz_xLineFixed 16 + +typedef struct { + xPointFixed p1, p2, p3; +} xTriangle; + +#define sz_xTriangle 24 + +typedef struct { + Fixed top B32; + Fixed bottom B32; + xLineFixed left; + xLineFixed right; +} xTrapezoid; + +#define sz_xTrapezoid 40 + +typedef struct { + CARD16 width B16; + CARD16 height B16; + INT16 x B16; + INT16 y B16; + INT16 xOff B16; + INT16 yOff B16; +} xGlyphInfo; + +#define sz_xGlyphInfo 12 + +typedef struct { + CARD8 len; + CARD8 pad1; + CARD16 pad2; + INT16 deltax; + INT16 deltay; +} xGlyphElt; + +#define sz_xGlyphElt 8 + +typedef struct { + Fixed l, r, y; +} xSpanFix; + +#define sz_xSpanFix 12 + +typedef struct { + xSpanFix top, bot; +} xTrap; + +#define sz_xTrap 24 + +/* + * requests and replies + */ +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD32 majorVersion B32; + CARD32 minorVersion B32; +} xRenderQueryVersionReq; + +#define sz_xRenderQueryVersionReq 12 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 majorVersion B32; + CARD32 minorVersion B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; +} xRenderQueryVersionReply; + +#define sz_xRenderQueryVersionReply 32 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; +} xRenderQueryPictFormatsReq; + +#define sz_xRenderQueryPictFormatsReq 4 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 numFormats B32; + CARD32 numScreens B32; + CARD32 numDepths B32; + CARD32 numVisuals B32; + CARD32 numSubpixel B32; /* Version 0.6 */ + CARD32 pad5 B32; +} xRenderQueryPictFormatsReply; + +#define sz_xRenderQueryPictFormatsReply 32 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + PictFormat format B32; +} xRenderQueryPictIndexValuesReq; + +#define sz_xRenderQueryPictIndexValuesReq 8 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 numIndexValues; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xRenderQueryPictIndexValuesReply; + +#define sz_xRenderQueryPictIndexValuesReply 32 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture pid B32; + Drawable drawable B32; + PictFormat format B32; + CARD32 mask B32; +} xRenderCreatePictureReq; + +#define sz_xRenderCreatePictureReq 20 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture picture B32; + CARD32 mask B32; +} xRenderChangePictureReq; + +#define sz_xRenderChangePictureReq 12 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture picture B32; + INT16 xOrigin B16; + INT16 yOrigin B16; +} xRenderSetPictureClipRectanglesReq; + +#define sz_xRenderSetPictureClipRectanglesReq 12 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture picture B32; +} xRenderFreePictureReq; + +#define sz_xRenderFreePictureReq 8 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture src B32; + Picture mask B32; + Picture dst B32; + INT16 xSrc B16; + INT16 ySrc B16; + INT16 xMask B16; + INT16 yMask B16; + INT16 xDst B16; + INT16 yDst B16; + CARD16 width B16; + CARD16 height B16; +} xRenderCompositeReq; + +#define sz_xRenderCompositeReq 36 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture src B32; + Picture dst B32; + CARD32 colorScale B32; + CARD32 alphaScale B32; + INT16 xSrc B16; + INT16 ySrc B16; + INT16 xDst B16; + INT16 yDst B16; + CARD16 width B16; + CARD16 height B16; +} xRenderScaleReq; + +#define sz_xRenderScaleReq 32 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture src B32; + Picture dst B32; + PictFormat maskFormat B32; + INT16 xSrc B16; + INT16 ySrc B16; +} xRenderTrapezoidsReq; + +#define sz_xRenderTrapezoidsReq 24 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture src B32; + Picture dst B32; + PictFormat maskFormat B32; + INT16 xSrc B16; + INT16 ySrc B16; +} xRenderTrianglesReq; + +#define sz_xRenderTrianglesReq 24 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture src B32; + Picture dst B32; + PictFormat maskFormat B32; + INT16 xSrc B16; + INT16 ySrc B16; +} xRenderTriStripReq; + +#define sz_xRenderTriStripReq 24 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture src B32; + Picture dst B32; + PictFormat maskFormat B32; + INT16 xSrc B16; + INT16 ySrc B16; +} xRenderTriFanReq; + +#define sz_xRenderTriFanReq 24 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Glyphset gsid B32; + PictFormat format B32; +} xRenderCreateGlyphSetReq; + +#define sz_xRenderCreateGlyphSetReq 12 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Glyphset gsid B32; + Glyphset existing B32; +} xRenderReferenceGlyphSetReq; + +#define sz_xRenderReferenceGlyphSetReq 24 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Glyphset glyphset B32; +} xRenderFreeGlyphSetReq; + +#define sz_xRenderFreeGlyphSetReq 8 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Glyphset glyphset B32; + CARD32 nglyphs; +} xRenderAddGlyphsReq; + +#define sz_xRenderAddGlyphsReq 12 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Glyphset glyphset B32; +} xRenderFreeGlyphsReq; + +#define sz_xRenderFreeGlyphsReq 8 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture src B32; + Picture dst B32; + PictFormat maskFormat B32; + Glyphset glyphset B32; + INT16 xSrc B16; + INT16 ySrc B16; +} xRenderCompositeGlyphsReq, xRenderCompositeGlyphs8Req, +xRenderCompositeGlyphs16Req, xRenderCompositeGlyphs32Req; + +#define sz_xRenderCompositeGlyphs8Req 28 +#define sz_xRenderCompositeGlyphs16Req 28 +#define sz_xRenderCompositeGlyphs32Req 28 + +/* 0.1 and higher */ + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + CARD8 op; + CARD8 pad1; + CARD16 pad2 B16; + Picture dst B32; + xRenderColor color; +} xRenderFillRectanglesReq; + +#define sz_xRenderFillRectanglesReq 20 + +/* 0.5 and higher */ + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Cursor cid B32; + Picture src B32; + CARD16 x B16; + CARD16 y B16; +} xRenderCreateCursorReq; + +#define sz_xRenderCreateCursorReq 16 + +/* 0.6 and higher */ + +/* + * This can't use an array because 32-bit values may be in bitfields + */ +typedef struct { + Fixed matrix11 B32; + Fixed matrix12 B32; + Fixed matrix13 B32; + Fixed matrix21 B32; + Fixed matrix22 B32; + Fixed matrix23 B32; + Fixed matrix31 B32; + Fixed matrix32 B32; + Fixed matrix33 B32; +} xRenderTransform; + +#define sz_xRenderTransform 36 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture picture B32; + xRenderTransform transform; +} xRenderSetPictureTransformReq; + +#define sz_xRenderSetPictureTransformReq 44 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Drawable drawable B32; +} xRenderQueryFiltersReq; + +#define sz_xRenderQueryFiltersReq 8 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 numAliases B32; /* LISTofCARD16 */ + CARD32 numFilters B32; /* LISTofSTRING8 */ + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; +} xRenderQueryFiltersReply; + +#define sz_xRenderQueryFiltersReply 32 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture picture B32; + CARD16 nbytes B16; /* number of bytes in name */ + CARD16 pad B16; +} xRenderSetPictureFilterReq; + +#define sz_xRenderSetPictureFilterReq 12 + +/* 0.8 and higher */ + +typedef struct { + Cursor cursor B32; + CARD32 delay B32; +} xAnimCursorElt; + +#define sz_xAnimCursorElt 8 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Cursor cid B32; +} xRenderCreateAnimCursorReq; + +#define sz_xRenderCreateAnimCursorReq 8 + +/* 0.9 and higher */ + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture picture; + INT16 xOff B16; + INT16 yOff B16; +} xRenderAddTrapsReq; + +#define sz_xRenderAddTrapsReq 12 + +/* 0.10 and higher */ + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture pid B32; + xRenderColor color; +} xRenderCreateSolidFillReq; + +#define sz_xRenderCreateSolidFillReq 16 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture pid B32; + xPointFixed p1; + xPointFixed p2; + CARD32 nStops; +} xRenderCreateLinearGradientReq; + +#define sz_xRenderCreateLinearGradientReq 28 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture pid B32; + xPointFixed inner; + xPointFixed outer; + Fixed inner_radius; + Fixed outer_radius; + CARD32 nStops; +} xRenderCreateRadialGradientReq; + +#define sz_xRenderCreateRadialGradientReq 36 + +typedef struct { + CARD8 reqType; + CARD8 renderReqType; + CARD16 length B16; + Picture pid B32; + xPointFixed center; + Fixed angle; /* in degrees */ + CARD32 nStops; +} xRenderCreateConicalGradientReq; + +#define sz_xRenderCreateConicalGradientReq 24 + +#undef Window +#undef Drawable +#undef Font +#undef Pixmap +#undef Cursor +#undef Colormap +#undef GContext +#undef Atom +#undef VisualID +#undef Time +#undef KeyCode +#undef KeySym + +#undef Picture +#undef PictFormat +#undef Fixed +#undef Glyphset +#undef Glyph + + +#endif /* CAIRO_HAS_XLIB_XRENDER_SURFACE */ + +#endif /* CAIRO_XLIB_XRENDER_PRIVATE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender.h b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender.h new file mode 100644 index 00000000000..b34b057de4c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib-xrender.h @@ -0,0 +1,66 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_XLIB_XRENDER_H +#define CAIRO_XLIB_XRENDER_H + +#include "cairo.h" + +#if CAIRO_HAS_XLIB_XRENDER_SURFACE + +#include +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_xlib_surface_create_with_xrender_format (Display *dpy, + Drawable drawable, + Screen *screen, + XRenderPictFormat *format, + int width, + int height); + +cairo_public XRenderPictFormat * +cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_XLIB_XRENDER_SURFACE */ +# error Cairo was not compiled with support for the xlib XRender backend +#endif /* CAIRO_HAS_XLIB_XRENDER_SURFACE */ + +#endif /* CAIRO_XLIB_XRENDER_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xlib.h b/Build/source/libs/cairo/cairo-src/src/cairo-xlib.h new file mode 100644 index 00000000000..ecf8d6c86be --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xlib.h @@ -0,0 +1,118 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_XLIB_H +#define CAIRO_XLIB_H + +#include "cairo.h" + +#if CAIRO_HAS_XLIB_SURFACE + +#include + +CAIRO_BEGIN_DECLS + +cairo_public cairo_surface_t * +cairo_xlib_surface_create (Display *dpy, + Drawable drawable, + Visual *visual, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_xlib_surface_create_for_bitmap (Display *dpy, + Pixmap bitmap, + Screen *screen, + int width, + int height); + +cairo_public void +cairo_xlib_surface_set_size (cairo_surface_t *surface, + int width, + int height); + +cairo_public void +cairo_xlib_surface_set_drawable (cairo_surface_t *surface, + Drawable drawable, + int width, + int height); + +cairo_public Display * +cairo_xlib_surface_get_display (cairo_surface_t *surface); + +cairo_public Drawable +cairo_xlib_surface_get_drawable (cairo_surface_t *surface); + +cairo_public Screen * +cairo_xlib_surface_get_screen (cairo_surface_t *surface); + +cairo_public Visual * +cairo_xlib_surface_get_visual (cairo_surface_t *surface); + +cairo_public int +cairo_xlib_surface_get_depth (cairo_surface_t *surface); + +cairo_public int +cairo_xlib_surface_get_width (cairo_surface_t *surface); + +cairo_public int +cairo_xlib_surface_get_height (cairo_surface_t *surface); + +/* debug interface */ + +cairo_public void +cairo_xlib_device_debug_cap_xrender_version (cairo_device_t *device, + int major_version, + int minor_version); + +/* + * @precision: -1 implies automatically choose based on antialiasing mode, + * any other value overrides and sets the corresponding PolyMode. + */ +cairo_public void +cairo_xlib_device_debug_set_precision (cairo_device_t *device, + int precision); + +cairo_public int +cairo_xlib_device_debug_get_precision (cairo_device_t *device); + +CAIRO_END_DECLS + +#else /* CAIRO_HAS_XLIB_SURFACE */ +# error Cairo was not compiled with support for the xlib backend +#endif /* CAIRO_HAS_XLIB_SURFACE */ + +#endif /* CAIRO_XLIB_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xml-surface.c b/Build/source/libs/cairo/cairo-src/src/cairo-xml-surface.c new file mode 100644 index 00000000000..6dbafdba2ba --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xml-surface.c @@ -0,0 +1,1209 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson. + * + * Contributor(s): + * Chris Wilson + */ + +/* This surface is intended to produce a verbose, hierarchical, DAG XML file + * representing a single surface. It is intended to be used by debuggers, + * such as cairo-sphinx, or by application test-suites that what a log of + * operations. + */ + +#include "cairoint.h" + +#include "cairo-xml.h" + +#include "cairo-clip-private.h" +#include "cairo-device-private.h" +#include "cairo-default-context-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-error-private.h" +#include "cairo-output-stream-private.h" +#include "cairo-recording-surface-inline.h" + +#define static cairo_warn static + +typedef struct _cairo_xml_surface cairo_xml_surface_t; + +typedef struct _cairo_xml { + cairo_device_t base; + + cairo_output_stream_t *stream; + int indent; +} cairo_xml_t; + +struct _cairo_xml_surface { + cairo_surface_t base; + + double width, height; +}; + +slim_hidden_proto (cairo_xml_for_recording_surface); + +static const cairo_surface_backend_t _cairo_xml_surface_backend; + +static const char * +_operator_to_string (cairo_operator_t op) +{ + static const char *names[] = { + "CLEAR", /* CAIRO_OPERATOR_CLEAR */ + + "SOURCE", /* CAIRO_OPERATOR_SOURCE */ + "OVER", /* CAIRO_OPERATOR_OVER */ + "IN", /* CAIRO_OPERATOR_IN */ + "OUT", /* CAIRO_OPERATOR_OUT */ + "ATOP", /* CAIRO_OPERATOR_ATOP */ + + "DEST", /* CAIRO_OPERATOR_DEST */ + "DEST_OVER", /* CAIRO_OPERATOR_DEST_OVER */ + "DEST_IN", /* CAIRO_OPERATOR_DEST_IN */ + "DEST_OUT", /* CAIRO_OPERATOR_DEST_OUT */ + "DEST_ATOP", /* CAIRO_OPERATOR_DEST_ATOP */ + + "XOR", /* CAIRO_OPERATOR_XOR */ + "ADD", /* CAIRO_OPERATOR_ADD */ + "SATURATE", /* CAIRO_OPERATOR_SATURATE */ + + "MULTIPLY", /* CAIRO_OPERATOR_MULTIPLY */ + "SCREEN", /* CAIRO_OPERATOR_SCREEN */ + "OVERLAY", /* CAIRO_OPERATOR_OVERLAY */ + "DARKEN", /* CAIRO_OPERATOR_DARKEN */ + "LIGHTEN", /* CAIRO_OPERATOR_LIGHTEN */ + "DODGE", /* CAIRO_OPERATOR_COLOR_DODGE */ + "BURN", /* CAIRO_OPERATOR_COLOR_BURN */ + "HARD_LIGHT", /* CAIRO_OPERATOR_HARD_LIGHT */ + "SOFT_LIGHT", /* CAIRO_OPERATOR_SOFT_LIGHT */ + "DIFFERENCE", /* CAIRO_OPERATOR_DIFFERENCE */ + "EXCLUSION", /* CAIRO_OPERATOR_EXCLUSION */ + "HSL_HUE", /* CAIRO_OPERATOR_HSL_HUE */ + "HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */ + "HSL_COLOR", /* CAIRO_OPERATOR_HSL_COLOR */ + "HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */ + }; + assert (op < ARRAY_LENGTH (names)); + return names[op]; +} + +static const char * +_extend_to_string (cairo_extend_t extend) +{ + static const char *names[] = { + "EXTEND_NONE", /* CAIRO_EXTEND_NONE */ + "EXTEND_REPEAT", /* CAIRO_EXTEND_REPEAT */ + "EXTEND_REFLECT", /* CAIRO_EXTEND_REFLECT */ + "EXTEND_PAD" /* CAIRO_EXTEND_PAD */ + }; + assert (extend < ARRAY_LENGTH (names)); + return names[extend]; +} + +static const char * +_filter_to_string (cairo_filter_t filter) +{ + static const char *names[] = { + "FILTER_FAST", /* CAIRO_FILTER_FAST */ + "FILTER_GOOD", /* CAIRO_FILTER_GOOD */ + "FILTER_BEST", /* CAIRO_FILTER_BEST */ + "FILTER_NEAREST", /* CAIRO_FILTER_NEAREST */ + "FILTER_BILINEAR", /* CAIRO_FILTER_BILINEAR */ + "FILTER_GAUSSIAN", /* CAIRO_FILTER_GAUSSIAN */ + }; + assert (filter < ARRAY_LENGTH (names)); + return names[filter]; +} + +static const char * +_fill_rule_to_string (cairo_fill_rule_t rule) +{ + static const char *names[] = { + "WINDING", /* CAIRO_FILL_RULE_WINDING */ + "EVEN_ODD" /* CAIRO_FILL_RILE_EVEN_ODD */ + }; + assert (rule < ARRAY_LENGTH (names)); + return names[rule]; +} + +static const char * +_antialias_to_string (cairo_antialias_t antialias) +{ + static const char *names[] = { + "DEFAULT", /* CAIRO_ANTIALIAS_DEFAULT */ + "NONE", /* CAIRO_ANTIALIAS_NONE */ + "GRAY", /* CAIRO_ANTIALIAS_GRAY */ + "SUBPIXEL", /* CAIRO_ANTIALIAS_SUBPIXEL */ + "FAST", /* CAIRO_ANTIALIAS_FAST */ + "GOOD", /* CAIRO_ANTIALIAS_GOOD */ + "BEST", /* CAIRO_ANTIALIAS_BEST */ + }; + assert (antialias < ARRAY_LENGTH (names)); + return names[antialias]; +} + +static const char * +_line_cap_to_string (cairo_line_cap_t line_cap) +{ + static const char *names[] = { + "LINE_CAP_BUTT", /* CAIRO_LINE_CAP_BUTT */ + "LINE_CAP_ROUND", /* CAIRO_LINE_CAP_ROUND */ + "LINE_CAP_SQUARE" /* CAIRO_LINE_CAP_SQUARE */ + }; + assert (line_cap < ARRAY_LENGTH (names)); + return names[line_cap]; +} + +static const char * +_line_join_to_string (cairo_line_join_t line_join) +{ + static const char *names[] = { + "LINE_JOIN_MITER", /* CAIRO_LINE_JOIN_MITER */ + "LINE_JOIN_ROUND", /* CAIRO_LINE_JOIN_ROUND */ + "LINE_JOIN_BEVEL", /* CAIRO_LINE_JOIN_BEVEL */ + }; + assert (line_join < ARRAY_LENGTH (names)); + return names[line_join]; +} + +static const char * +_content_to_string (cairo_content_t content) +{ + switch (content) { + case CAIRO_CONTENT_ALPHA: return "ALPHA"; + case CAIRO_CONTENT_COLOR: return "COLOR"; + default: + case CAIRO_CONTENT_COLOR_ALPHA: return "COLOR_ALPHA"; + } +} + +static const char * +_format_to_string (cairo_format_t format) +{ + switch (format) { + case CAIRO_FORMAT_ARGB32: return "ARGB32"; + case CAIRO_FORMAT_RGB30: return "RGB30"; + case CAIRO_FORMAT_RGB24: return "RGB24"; + case CAIRO_FORMAT_RGB16_565: return "RGB16_565"; + case CAIRO_FORMAT_A8: return "A8"; + case CAIRO_FORMAT_A1: return "A1"; + case CAIRO_FORMAT_INVALID: return "INVALID"; + } + ASSERT_NOT_REACHED; + return "INVALID"; +} + +static cairo_status_t +_device_flush (void *abstract_device) +{ + cairo_xml_t *xml = abstract_device; + cairo_status_t status; + + status = _cairo_output_stream_flush (xml->stream); + + return status; +} + +static void +_device_destroy (void *abstract_device) +{ + cairo_xml_t *xml = abstract_device; + cairo_status_t status; + + status = _cairo_output_stream_destroy (xml->stream); + + free (xml); +} + +static const cairo_device_backend_t _cairo_xml_device_backend = { + CAIRO_DEVICE_TYPE_XML, + + NULL, NULL, /* lock, unlock */ + + _device_flush, + NULL, /* finish */ + _device_destroy +}; + +static cairo_device_t * +_cairo_xml_create_internal (cairo_output_stream_t *stream) +{ + cairo_xml_t *xml; + + xml = malloc (sizeof (cairo_xml_t)); + if (unlikely (xml == NULL)) + return _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY); + + memset (xml, 0, sizeof (cairo_xml_t)); + + _cairo_device_init (&xml->base, &_cairo_xml_device_backend); + + xml->indent = 0; + xml->stream = stream; + + return &xml->base; +} + +static void +_cairo_xml_indent (cairo_xml_t *xml, int indent) +{ + xml->indent += indent; + assert (xml->indent >= 0); +} + +static void CAIRO_PRINTF_FORMAT (2, 3) +_cairo_xml_printf (cairo_xml_t *xml, const char *fmt, ...) +{ + va_list ap; + char indent[80]; + int len; + + len = MIN (xml->indent, ARRAY_LENGTH (indent)); + memset (indent, ' ', len); + _cairo_output_stream_write (xml->stream, indent, len); + + va_start (ap, fmt); + _cairo_output_stream_vprintf (xml->stream, fmt, ap); + va_end (ap); + + _cairo_output_stream_write (xml->stream, "\n", 1); +} + +static void CAIRO_PRINTF_FORMAT (2, 3) +_cairo_xml_printf_start (cairo_xml_t *xml, const char *fmt, ...) +{ + char indent[80]; + int len; + + len = MIN (xml->indent, ARRAY_LENGTH (indent)); + memset (indent, ' ', len); + _cairo_output_stream_write (xml->stream, indent, len); + + if (fmt != NULL) { + va_list ap; + + va_start (ap, fmt); + _cairo_output_stream_vprintf (xml->stream, fmt, ap); + va_end (ap); + } +} + +static void CAIRO_PRINTF_FORMAT (2, 3) +_cairo_xml_printf_continue (cairo_xml_t *xml, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + _cairo_output_stream_vprintf (xml->stream, fmt, ap); + va_end (ap); +} + +static void CAIRO_PRINTF_FORMAT (2, 3) +_cairo_xml_printf_end (cairo_xml_t *xml, const char *fmt, ...) +{ + if (fmt != NULL) { + va_list ap; + + va_start (ap, fmt); + _cairo_output_stream_vprintf (xml->stream, fmt, ap); + va_end (ap); + } + + _cairo_output_stream_write (xml->stream, "\n", 1); +} + +static cairo_surface_t * +_cairo_xml_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_rectangle_t extents; + + extents.x = extents.y = 0; + extents.width = width; + extents.height = height; + + return cairo_recording_surface_create (content, &extents); +} + +static cairo_bool_t +_cairo_xml_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + cairo_xml_surface_t *surface = abstract_surface; + + if (surface->width < 0 || surface->height < 0) + return FALSE; + + rectangle->x = 0; + rectangle->y = 0; + rectangle->width = surface->width; + rectangle->height = surface->height; + + return TRUE; +} + +static cairo_status_t +_cairo_xml_move_to (void *closure, + const cairo_point_t *p1) +{ + _cairo_xml_printf_continue (closure, " %f %f m", + _cairo_fixed_to_double (p1->x), + _cairo_fixed_to_double (p1->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_line_to (void *closure, + const cairo_point_t *p1) +{ + _cairo_xml_printf_continue (closure, " %f %f l", + _cairo_fixed_to_double (p1->x), + _cairo_fixed_to_double (p1->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_curve_to (void *closure, + const cairo_point_t *p1, + const cairo_point_t *p2, + const cairo_point_t *p3) +{ + _cairo_xml_printf_continue (closure, " %f %f %f %f %f %f c", + _cairo_fixed_to_double (p1->x), + _cairo_fixed_to_double (p1->y), + _cairo_fixed_to_double (p2->x), + _cairo_fixed_to_double (p2->y), + _cairo_fixed_to_double (p3->x), + _cairo_fixed_to_double (p3->y)); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_close_path (void *closure) +{ + _cairo_xml_printf_continue (closure, " h"); + + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_xml_emit_path (cairo_xml_t *xml, + const cairo_path_fixed_t *path) +{ + cairo_status_t status; + + _cairo_xml_printf_start (xml, ""); + status = _cairo_path_fixed_interpret (path, + _cairo_xml_move_to, + _cairo_xml_line_to, + _cairo_xml_curve_to, + _cairo_xml_close_path, + xml); + assert (status == CAIRO_STATUS_SUCCESS); + _cairo_xml_printf_end (xml, ""); +} + +static void +_cairo_xml_emit_string (cairo_xml_t *xml, + const char *node, + const char *data) +{ + _cairo_xml_printf (xml, "<%s>%s", node, data, node); +} + +static void +_cairo_xml_emit_double (cairo_xml_t *xml, + const char *node, + double data) +{ + _cairo_xml_printf (xml, "<%s>%f", node, data, node); +} + +static cairo_xml_t * +to_xml (cairo_xml_surface_t *surface) +{ + return (cairo_xml_t *) surface->base.device; +} + +static cairo_status_t +_cairo_xml_surface_emit_clip_boxes (cairo_xml_surface_t *surface, + const cairo_clip_t *clip) +{ + cairo_box_t *box; + cairo_xml_t *xml; + int n; + + if (clip->num_boxes == 0) + return CAIRO_STATUS_SUCCESS; + + /* skip the trivial clip covering the surface extents */ + if (surface->width >= 0 && surface->height >= 0 && clip->num_boxes == 1) { + box = &clip->boxes[0]; + if (box->p1.x <= 0 && box->p1.y <= 0 && + box->p2.x - box->p1.x >= _cairo_fixed_from_double (surface->width) && + box->p2.y - box->p1.y >= _cairo_fixed_from_double (surface->height)) + { + return CAIRO_STATUS_SUCCESS; + } + } + + xml = to_xml (surface); + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + for (n = 0; n < clip->num_boxes; n++) { + box = &clip->boxes[n]; + + _cairo_xml_printf_start (xml, "%f %f m", + _cairo_fixed_to_double (box->p1.x), + _cairo_fixed_to_double (box->p1.y)); + _cairo_xml_printf_continue (xml, " %f %f l", + _cairo_fixed_to_double (box->p2.x), + _cairo_fixed_to_double (box->p1.y)); + _cairo_xml_printf_continue (xml, " %f %f l", + _cairo_fixed_to_double (box->p2.x), + _cairo_fixed_to_double (box->p2.y)); + _cairo_xml_printf_continue (xml, " %f %f l", + _cairo_fixed_to_double (box->p1.x), + _cairo_fixed_to_double (box->p2.y)); + _cairo_xml_printf_end (xml, " h"); + } + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + _cairo_xml_emit_double (xml, "tolerance", 1.0); + _cairo_xml_emit_string (xml, "antialias", + _antialias_to_string (CAIRO_ANTIALIAS_NONE)); + _cairo_xml_emit_string (xml, "fill-rule", + _fill_rule_to_string (CAIRO_FILL_RULE_WINDING)); + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_surface_emit_clip_path (cairo_xml_surface_t *surface, + const cairo_clip_path_t *clip_path) +{ + cairo_box_t box; + cairo_status_t status; + cairo_xml_t *xml; + + if (clip_path == NULL) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_xml_surface_emit_clip_path (surface, clip_path->prev); + if (unlikely (status)) + return status; + + /* skip the trivial clip covering the surface extents */ + if (surface->width >= 0 && surface->height >= 0 && + _cairo_path_fixed_is_box (&clip_path->path, &box)) + { + if (box.p1.x <= 0 && box.p1.y <= 0 && + box.p2.x - box.p1.x >= _cairo_fixed_from_double (surface->width) && + box.p2.y - box.p1.y >= _cairo_fixed_from_double (surface->height)) + { + return CAIRO_STATUS_SUCCESS; + } + } + + xml = to_xml (surface); + + _cairo_xml_printf_start (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_emit_path (xml, &clip_path->path); + _cairo_xml_emit_double (xml, "tolerance", clip_path->tolerance); + _cairo_xml_emit_string (xml, "antialias", + _antialias_to_string (clip_path->antialias)); + _cairo_xml_emit_string (xml, "fill-rule", + _fill_rule_to_string (clip_path->fill_rule)); + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf_end (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_surface_emit_clip (cairo_xml_surface_t *surface, + const cairo_clip_t *clip) +{ + cairo_status_t status; + + if (clip == NULL) + return CAIRO_STATUS_SUCCESS; + + status = _cairo_xml_surface_emit_clip_boxes (surface, clip); + if (unlikely (status)) + return status; + + return _cairo_xml_surface_emit_clip_path (surface, clip->path); +} + +static cairo_status_t +_cairo_xml_emit_solid (cairo_xml_t *xml, + const cairo_solid_pattern_t *solid) +{ + _cairo_xml_printf (xml, "%f %f %f %f", + solid->color.red, + solid->color.green, + solid->color.blue, + solid->color.alpha); + return CAIRO_STATUS_SUCCESS; +} + +static void +_cairo_xml_emit_matrix (cairo_xml_t *xml, + const cairo_matrix_t *matrix) +{ + if (! _cairo_matrix_is_identity (matrix)) { + _cairo_xml_printf (xml, "%f %f %f %f %f %f", + matrix->xx, matrix->yx, + matrix->xy, matrix->yy, + matrix->x0, matrix->y0); + } +} + +static void +_cairo_xml_emit_gradient (cairo_xml_t *xml, + const cairo_gradient_pattern_t *gradient) +{ + unsigned int i; + + for (i = 0; i < gradient->n_stops; i++) { + _cairo_xml_printf (xml, + "%f %f %f %f %f", + gradient->stops[i].offset, + gradient->stops[i].color.red, + gradient->stops[i].color.green, + gradient->stops[i].color.blue, + gradient->stops[i].color.alpha); + } +} + +static cairo_status_t +_cairo_xml_emit_linear (cairo_xml_t *xml, + const cairo_linear_pattern_t *linear) +{ + _cairo_xml_printf (xml, + "", + linear->pd1.x, linear->pd1.y, + linear->pd2.x, linear->pd2.y); + _cairo_xml_indent (xml, 2); + _cairo_xml_emit_gradient (xml, &linear->base); + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_emit_radial (cairo_xml_t *xml, + const cairo_radial_pattern_t *radial) +{ + _cairo_xml_printf (xml, + "", + radial->cd1.center.x, radial->cd1.center.y, radial->cd1.radius, + radial->cd2.center.x, radial->cd2.center.y, radial->cd2.radius); + _cairo_xml_indent (xml, 2); + _cairo_xml_emit_gradient (xml, &radial->base); + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_write_func (void *closure, const unsigned char *data, unsigned len) +{ + _cairo_output_stream_write (closure, data, len); + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_emit_image (cairo_xml_t *xml, + cairo_image_surface_t *image) +{ + cairo_output_stream_t *stream; + cairo_status_t status; + + _cairo_xml_printf_start (xml, + "", + image->width, image->height, + _format_to_string (image->format)); + + stream = _cairo_base64_stream_create (xml->stream); + status = cairo_surface_write_to_png_stream (&image->base, + _write_func, stream); + assert (status == CAIRO_STATUS_SUCCESS); + status = _cairo_output_stream_destroy (stream); + if (unlikely (status)) + return status; + + _cairo_xml_printf_end (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_emit_surface (cairo_xml_t *xml, + const cairo_surface_pattern_t *pattern) +{ + cairo_surface_t *source = pattern->surface; + cairo_status_t status; + + if (_cairo_surface_is_recording (source)) { + status = cairo_xml_for_recording_surface (&xml->base, source); + } else { + cairo_image_surface_t *image; + void *image_extra; + + status = _cairo_surface_acquire_source_image (source, + &image, &image_extra); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_image (xml, image); + + _cairo_surface_release_source_image (source, image, image_extra); + } + + return status; +} + +static cairo_status_t +_cairo_xml_emit_pattern (cairo_xml_t *xml, + const char *source_or_mask, + const cairo_pattern_t *pattern) +{ + cairo_status_t status; + + _cairo_xml_printf (xml, "<%s-pattern>", source_or_mask); + _cairo_xml_indent (xml, 2); + + switch (pattern->type) { + case CAIRO_PATTERN_TYPE_SOLID: + status = _cairo_xml_emit_solid (xml, (cairo_solid_pattern_t *) pattern); + break; + case CAIRO_PATTERN_TYPE_LINEAR: + status = _cairo_xml_emit_linear (xml, (cairo_linear_pattern_t *) pattern); + break; + case CAIRO_PATTERN_TYPE_RADIAL: + status = _cairo_xml_emit_radial (xml, (cairo_radial_pattern_t *) pattern); + break; + case CAIRO_PATTERN_TYPE_SURFACE: + status = _cairo_xml_emit_surface (xml, (cairo_surface_pattern_t *) pattern); + break; + default: + ASSERT_NOT_REACHED; + status = CAIRO_INT_STATUS_UNSUPPORTED; + break; + } + + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) { + _cairo_xml_emit_matrix (xml, &pattern->matrix); + _cairo_xml_printf (xml, + "%s", + _extend_to_string (pattern->extend)); + _cairo_xml_printf (xml, + "%s", + _filter_to_string (pattern->filter)); + } + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, "", source_or_mask); + + return status; +} + +static cairo_int_status_t +_cairo_xml_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + cairo_xml_surface_t *surface = abstract_surface; + cairo_xml_t *xml = to_xml (surface); + cairo_status_t status; + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); + + status = _cairo_xml_surface_emit_clip (surface, clip); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_pattern (xml, "source", source); + if (unlikely (status)) + return status; + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_xml_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + cairo_xml_surface_t *surface = abstract_surface; + cairo_xml_t *xml = to_xml (surface); + cairo_status_t status; + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); + + status = _cairo_xml_surface_emit_clip (surface, clip); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_pattern (xml, "source", source); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_pattern (xml, "mask", mask); + if (unlikely (status)) + return status; + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_xml_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_xml_surface_t *surface = abstract_surface; + cairo_xml_t *xml = to_xml (surface); + cairo_status_t status; + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); + _cairo_xml_emit_double (xml, "line-width", style->line_width); + _cairo_xml_emit_double (xml, "miter-limit", style->miter_limit); + _cairo_xml_emit_string (xml, "line-cap", _line_cap_to_string (style->line_cap)); + _cairo_xml_emit_string (xml, "line-join", _line_join_to_string (style->line_join)); + + status = _cairo_xml_surface_emit_clip (surface, clip); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_pattern (xml, "source", source); + if (unlikely (status)) + return status; + + if (style->num_dashes) { + unsigned int i; + + _cairo_xml_printf_start (xml, "", + style->dash_offset); + for (i = 0; i < style->num_dashes; i++) + _cairo_xml_printf_continue (xml, "%f ", style->dash[i]); + + _cairo_xml_printf_end (xml, ""); + } + + _cairo_xml_emit_path (xml, path); + _cairo_xml_emit_double (xml, "tolerance", tolerance); + _cairo_xml_emit_string (xml, "antialias", _antialias_to_string (antialias)); + + _cairo_xml_emit_matrix (xml, ctm); + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +_cairo_xml_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t*path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + cairo_xml_surface_t *surface = abstract_surface; + cairo_xml_t *xml = to_xml (surface); + cairo_status_t status; + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); + + status = _cairo_xml_surface_emit_clip (surface, clip); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_pattern (xml, "source", source); + if (unlikely (status)) + return status; + + _cairo_xml_emit_path (xml, path); + _cairo_xml_emit_double (xml, "tolerance", tolerance); + _cairo_xml_emit_string (xml, "antialias", _antialias_to_string (antialias)); + _cairo_xml_emit_string (xml, "fill-rule", _fill_rule_to_string (fill_rule)); + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +#if CAIRO_HAS_FT_FONT +#include "cairo-ft-private.h" +static cairo_status_t +_cairo_xml_emit_type42_font (cairo_xml_t *xml, + cairo_scaled_font_t *scaled_font) +{ + const cairo_scaled_font_backend_t *backend; + cairo_output_stream_t *base64_stream; + cairo_output_stream_t *zlib_stream; + cairo_status_t status, status2; + unsigned long size; + uint32_t len; + uint8_t *buf; + + backend = scaled_font->backend; + if (backend->load_truetype_table == NULL) + return CAIRO_INT_STATUS_UNSUPPORTED; + + size = 0; + status = backend->load_truetype_table (scaled_font, 0, 0, NULL, &size); + if (unlikely (status)) + return status; + + buf = malloc (size); + if (unlikely (buf == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = backend->load_truetype_table (scaled_font, 0, 0, buf, &size); + if (unlikely (status)) { + free (buf); + return status; + } + + _cairo_xml_printf_start (xml, "", + _cairo_ft_scaled_font_get_load_flags (scaled_font)); + + + base64_stream = _cairo_base64_stream_create (xml->stream); + len = size; + _cairo_output_stream_write (base64_stream, &len, sizeof (len)); + + zlib_stream = _cairo_deflate_stream_create (base64_stream); + + _cairo_output_stream_write (zlib_stream, buf, size); + free (buf); + + status2 = _cairo_output_stream_destroy (zlib_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + status2 = _cairo_output_stream_destroy (base64_stream); + if (status == CAIRO_STATUS_SUCCESS) + status = status2; + + _cairo_xml_printf_end (xml, ""); + + return status; +} +#else +static cairo_status_t +_cairo_xml_emit_type42_font (cairo_xml_t *xml, + cairo_scaled_font_t *scaled_font) +{ + return CAIRO_INT_STATUS_UNSUPPORTED; +} +#endif + +static cairo_status_t +_cairo_xml_emit_type3_font (cairo_xml_t *xml, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs) +{ + _cairo_xml_printf_start (xml, ""); + _cairo_xml_printf_end (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +_cairo_xml_emit_scaled_font (cairo_xml_t *xml, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs) +{ + cairo_int_status_t status; + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + status = _cairo_xml_emit_type42_font (xml, scaled_font); + if (status == CAIRO_INT_STATUS_UNSUPPORTED) { + status = _cairo_xml_emit_type3_font (xml, scaled_font, + glyphs, num_glyphs); + } + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return status; +} + +static cairo_int_status_t +_cairo_xml_surface_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + cairo_xml_surface_t *surface = abstract_surface; + cairo_xml_t *xml = to_xml (surface); + cairo_status_t status; + int i; + + _cairo_xml_printf (xml, ""); + _cairo_xml_indent (xml, 2); + + _cairo_xml_emit_string (xml, "operator", _operator_to_string (op)); + + status = _cairo_xml_surface_emit_clip (surface, clip); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_pattern (xml, "source", source); + if (unlikely (status)) + return status; + + status = _cairo_xml_emit_scaled_font (xml, scaled_font, glyphs, num_glyphs); + if (unlikely (status)) + return status; + + for (i = 0; i < num_glyphs; i++) { + _cairo_xml_printf (xml, "%f %f", + glyphs[i].index, + glyphs[i].x, + glyphs[i].y); + } + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_surface_backend_t +_cairo_xml_surface_backend = { + CAIRO_SURFACE_TYPE_XML, + NULL, + + _cairo_default_context_create, + + _cairo_xml_surface_create_similar, + NULL, /* create_similar_image */ + NULL, /* map_to_image */ + NULL, /* unmap_image */ + + _cairo_surface_default_source, + NULL, /* acquire source image */ + NULL, /* release source image */ + NULL, /* snapshot */ + + NULL, /* copy page */ + NULL, /* show page */ + + _cairo_xml_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + _cairo_xml_surface_paint, + _cairo_xml_surface_mask, + _cairo_xml_surface_stroke, + _cairo_xml_surface_fill, + NULL, /* fill_stroke */ + _cairo_xml_surface_glyphs, +}; + +static cairo_surface_t * +_cairo_xml_surface_create_internal (cairo_device_t *device, + cairo_content_t content, + double width, + double height) +{ + cairo_xml_surface_t *surface; + + surface = malloc (sizeof (cairo_xml_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &_cairo_xml_surface_backend, + device, + content); + + surface->width = width; + surface->height = height; + + return &surface->base; +} + +cairo_device_t * +cairo_xml_create (const char *filename) +{ + cairo_output_stream_t *stream; + cairo_status_t status; + + stream = _cairo_output_stream_create_for_filename (filename); + if ((status = _cairo_output_stream_get_status (stream))) + return _cairo_device_create_in_error (status); + + return _cairo_xml_create_internal (stream); +} + +cairo_device_t * +cairo_xml_create_for_stream (cairo_write_func_t write_func, + void *closure) +{ + cairo_output_stream_t *stream; + cairo_status_t status; + + stream = _cairo_output_stream_create (write_func, NULL, closure); + if ((status = _cairo_output_stream_get_status (stream))) + return _cairo_device_create_in_error (status); + + return _cairo_xml_create_internal (stream); +} + +cairo_surface_t * +cairo_xml_surface_create (cairo_device_t *device, + cairo_content_t content, + double width, double height) +{ + if (unlikely (device->backend->type != CAIRO_DEVICE_TYPE_XML)) + return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + + if (unlikely (device->status)) + return _cairo_surface_create_in_error (device->status); + + return _cairo_xml_surface_create_internal (device, content, width, height); +} + +cairo_status_t +cairo_xml_for_recording_surface (cairo_device_t *device, + cairo_surface_t *recording_surface) +{ + cairo_box_t bbox; + cairo_rectangle_int_t extents; + cairo_surface_t *surface; + cairo_xml_t *xml; + cairo_status_t status; + + if (unlikely (device->status)) + return device->status; + + if (unlikely (recording_surface->status)) + return recording_surface->status; + + if (unlikely (device->backend->type != CAIRO_DEVICE_TYPE_XML)) + return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH); + + if (unlikely (! _cairo_surface_is_recording (recording_surface))) + return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); + + status = _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface, + &bbox, NULL); + if (unlikely (status)) + return status; + + _cairo_box_round_to_rectangle (&bbox, &extents); + surface = _cairo_xml_surface_create_internal (device, + recording_surface->content, + extents.width, + extents.height); + if (unlikely (surface->status)) + return surface->status; + + xml = (cairo_xml_t *) device; + + _cairo_xml_printf (xml, + "", + _content_to_string (recording_surface->content), + extents.width, extents.height); + _cairo_xml_indent (xml, 2); + + cairo_surface_set_device_offset (surface, -extents.x, -extents.y); + status = _cairo_recording_surface_replay (recording_surface, surface); + cairo_surface_destroy (surface); + + _cairo_xml_indent (xml, -2); + _cairo_xml_printf (xml, ""); + + return status; +} +slim_hidden_def (cairo_xml_for_recording_surface); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo-xml.h b/Build/source/libs/cairo/cairo-src/src/cairo-xml.h new file mode 100644 index 00000000000..9ae76e90aae --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo-xml.h @@ -0,0 +1,67 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2009 Chris Wilson + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Chris Wilson + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef CAIRO_XML_H +#define CAIRO_XML_H + +#include "cairo.h" + +#if CAIRO_HAS_XML_SURFACE + +CAIRO_BEGIN_DECLS + +cairo_public cairo_device_t * +cairo_xml_create (const char *filename); + +cairo_public cairo_device_t * +cairo_xml_create_for_stream (cairo_write_func_t write_func, + void *closure); + +cairo_public cairo_surface_t * +cairo_xml_surface_create (cairo_device_t *xml, + cairo_content_t content, + double width, double height); + +cairo_public cairo_status_t +cairo_xml_for_recording_surface (cairo_device_t *xml, + cairo_surface_t *surface); + +CAIRO_END_DECLS + +#else /*CAIRO_HAS_XML_SURFACE*/ +# error Cairo was not compiled with support for the XML backend +#endif /*CAIRO_HAS_XML_SURFACE*/ + +#endif /*CAIRO_XML_H*/ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo.c b/Build/source/libs/cairo/cairo-src/src/cairo.c new file mode 100644 index 00000000000..e3acf4d46c7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo.c @@ -0,0 +1,4031 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Chris Wilson + */ + +#include "cairoint.h" +#include "cairo-private.h" + +#include "cairo-backend-private.h" +#include "cairo-error-private.h" +#include "cairo-path-private.h" +#include "cairo-pattern-private.h" +#include "cairo-surface-private.h" +#include "cairo-surface-backend-private.h" + +#include + +/** + * SECTION:cairo + * @Title: cairo_t + * @Short_Description: The cairo drawing context + * @See_Also: #cairo_surface_t + * + * #cairo_t is the main object used when drawing with cairo. To + * draw with cairo, you create a #cairo_t, set the target surface, + * and drawing options for the #cairo_t, create shapes with + * functions like cairo_move_to() and cairo_line_to(), and then + * draw shapes with cairo_stroke() or cairo_fill(). + * + * #cairo_t's can be pushed to a stack via cairo_save(). + * They may then safely be changed, without losing the current state. + * Use cairo_restore() to restore to the saved state. + **/ + +/** + * SECTION:cairo-text + * @Title: text + * @Short_Description: Rendering text and glyphs + * @See_Also: #cairo_font_face_t, #cairo_scaled_font_t, cairo_text_path(), + * cairo_glyph_path() + * + * The functions with text in their name form cairo's + * toy text API. The toy API takes UTF-8 encoded + * text and is limited in its functionality to rendering simple + * left-to-right text with no advanced features. That means for example + * that most complex scripts like Hebrew, Arabic, and Indic scripts are + * out of question. No kerning or correct positioning of diacritical marks + * either. The font selection is pretty limited too and doesn't handle the + * case that the selected font does not cover the characters in the text. + * This set of functions are really that, a toy text API, for testing and + * demonstration purposes. Any serious application should avoid them. + * + * The functions with glyphs in their name form cairo's + * low-level text API. The low-level API relies on + * the user to convert text to a set of glyph indexes and positions. This + * is a very hard problem and is best handled by external libraries, like + * the pangocairo that is part of the Pango text layout and rendering library. + * Pango is available from http://www.pango.org/. + **/ + +/** + * SECTION:cairo-transforms + * @Title: Transformations + * @Short_Description: Manipulating the current transformation matrix + * @See_Also: #cairo_matrix_t + * + * The current transformation matrix, ctm, is a + * two-dimensional affine transformation that maps all coordinates and other + * drawing instruments from the user space into the + * surface's canonical coordinate system, also known as the device + * space. + **/ + +#define DEFINE_NIL_CONTEXT(status) \ + { \ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ + status, /* status */ \ + { 0, 0, 0, NULL }, /* user_data */ \ + NULL \ + } + +static const cairo_t _cairo_nil[] = { + DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_MEMORY), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_RESTORE), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_POP_GROUP), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_CURRENT_POINT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MATRIX), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STATUS), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_NULL_POINTER), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRING), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_PATH_DATA), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_READ_ERROR), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_WRITE_ERROR), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_FINISHED), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_TYPE_MISMATCH), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_PATTERN_TYPE_MISMATCH), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CONTENT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_FORMAT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_VISUAL), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_FILE_NOT_FOUND), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DASH), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DSC_COMMENT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_INDEX), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_TEMP_FILE_ERROR), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRIDE), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_FONT_TYPE_MISMATCH), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_IMMUTABLE), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_ERROR), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_NEGATIVE_COUNT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CLUSTERS), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SLANT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_WEIGHT), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SIZE), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_TYPE_MISMATCH), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_ERROR), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MESH_CONSTRUCTION), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_FINISHED), + DEFINE_NIL_CONTEXT (CAIRO_STATUS_JBIG2_GLOBAL_MISSING) + +}; +COMPILE_TIME_ASSERT (ARRAY_LENGTH (_cairo_nil) == CAIRO_STATUS_LAST_STATUS - 1); + +/** + * _cairo_set_error: + * @cr: a cairo context + * @status: a status value indicating an error + * + * Atomically sets cr->status to @status and calls _cairo_error; + * Does nothing if status is %CAIRO_STATUS_SUCCESS. + * + * All assignments of an error status to cr->status should happen + * through _cairo_set_error(). Note that due to the nature of the atomic + * operation, it is not safe to call this function on the nil objects. + * + * The purpose of this function is to allow the user to set a + * breakpoint in _cairo_error() to generate a stack trace for when the + * user causes cairo to detect an error. + **/ +static void +_cairo_set_error (cairo_t *cr, cairo_status_t status) +{ + /* Don't overwrite an existing error. This preserves the first + * error, which is the most significant. */ + _cairo_status_set_error (&cr->status, _cairo_error (status)); +} + +cairo_t * +_cairo_create_in_error (cairo_status_t status) +{ + cairo_t *cr; + + assert (status != CAIRO_STATUS_SUCCESS); + + cr = (cairo_t *) &_cairo_nil[status - CAIRO_STATUS_NO_MEMORY]; + assert (status == cr->status); + + return cr; +} + +/** + * cairo_create: + * @target: target surface for the context + * + * Creates a new #cairo_t with all graphics state parameters set to + * default values and with @target as a target surface. The target + * surface should be constructed with a backend-specific function such + * as cairo_image_surface_create() (or any other + * cairo_backend_surface_create() + * variant). + * + * This function references @target, so you can immediately + * call cairo_surface_destroy() on it if you don't need to + * maintain a separate reference to it. + * + * Return value: a newly allocated #cairo_t with a reference + * count of 1. The initial reference count should be released + * with cairo_destroy() when you are done using the #cairo_t. + * This function never returns %NULL. If memory cannot be + * allocated, a special #cairo_t object will be returned on + * which cairo_status() returns %CAIRO_STATUS_NO_MEMORY. If + * you attempt to target a surface which does not support + * writing (such as #cairo_mime_surface_t) then a + * %CAIRO_STATUS_WRITE_ERROR will be raised. You can use this + * object normally, but no drawing will be done. + * + * Since: 1.0 + **/ +cairo_t * +cairo_create (cairo_surface_t *target) +{ + if (unlikely (target == NULL)) + return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); + if (unlikely (target->status)) + return _cairo_create_in_error (target->status); + if (unlikely (target->finished)) + return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); + + if (target->backend->create_context == NULL) + return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR)); + + return target->backend->create_context (target); + +} +slim_hidden_def (cairo_create); + +void +_cairo_init (cairo_t *cr, + const cairo_backend_t *backend) +{ + CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1); + cr->status = CAIRO_STATUS_SUCCESS; + _cairo_user_data_array_init (&cr->user_data); + + cr->backend = backend; +} + +/** + * cairo_reference: + * @cr: a #cairo_t + * + * Increases the reference count on @cr by one. This prevents + * @cr from being destroyed until a matching call to cairo_destroy() + * is made. + * + * The number of references to a #cairo_t can be get using + * cairo_get_reference_count(). + * + * Return value: the referenced #cairo_t. + * + * Since: 1.0 + **/ +cairo_t * +cairo_reference (cairo_t *cr) +{ + if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) + return cr; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count)); + + _cairo_reference_count_inc (&cr->ref_count); + + return cr; +} + +void +_cairo_fini (cairo_t *cr) +{ + _cairo_user_data_array_fini (&cr->user_data); +} + +/** + * cairo_destroy: + * @cr: a #cairo_t + * + * Decreases the reference count on @cr by one. If the result + * is zero, then @cr and all associated resources are freed. + * See cairo_reference(). + * + * Since: 1.0 + **/ +void +cairo_destroy (cairo_t *cr) +{ + if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) + return; + + assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count)); + + if (! _cairo_reference_count_dec_and_test (&cr->ref_count)) + return; + + cr->backend->destroy (cr); +} +slim_hidden_def (cairo_destroy); + +/** + * cairo_get_user_data: + * @cr: a #cairo_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @cr using the specified + * key. If no user data has been attached with the given key this + * function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.4 + **/ +void * +cairo_get_user_data (cairo_t *cr, + const cairo_user_data_key_t *key) +{ + return _cairo_user_data_array_get_data (&cr->user_data, key); +} + +/** + * cairo_set_user_data: + * @cr: a #cairo_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the #cairo_t + * @destroy: a #cairo_destroy_func_t which will be called when the + * #cairo_t is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @cr. To remove user data from a surface, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.4 + **/ +cairo_status_t +cairo_set_user_data (cairo_t *cr, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) + return cr->status; + + return _cairo_user_data_array_set_data (&cr->user_data, + key, user_data, destroy); +} + +/** + * cairo_get_reference_count: + * @cr: a #cairo_t + * + * Returns the current reference count of @cr. + * + * Return value: the current reference count of @cr. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.4 + **/ +unsigned int +cairo_get_reference_count (cairo_t *cr) +{ + if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&cr->ref_count); +} + +/** + * cairo_save: + * @cr: a #cairo_t + * + * Makes a copy of the current state of @cr and saves it + * on an internal stack of saved states for @cr. When + * cairo_restore() is called, @cr will be restored to + * the saved state. Multiple calls to cairo_save() and + * cairo_restore() can be nested; each call to cairo_restore() + * restores the state from the matching paired cairo_save(). + * + * It isn't necessary to clear all saved states before + * a #cairo_t is freed. If the reference count of a #cairo_t + * drops to zero in response to a call to cairo_destroy(), + * any saved states will be freed along with the #cairo_t. + * + * Since: 1.0 + **/ +void +cairo_save (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->save (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_save); + +/** + * cairo_restore: + * @cr: a #cairo_t + * + * Restores @cr to the state saved by a preceding call to + * cairo_save() and removes that state from the stack of + * saved states. + * + * Since: 1.0 + **/ +void +cairo_restore (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->restore (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_restore); + +/** + * cairo_push_group: + * @cr: a cairo context + * + * Temporarily redirects drawing to an intermediate surface known as a + * group. The redirection lasts until the group is completed by a call + * to cairo_pop_group() or cairo_pop_group_to_source(). These calls + * provide the result of any drawing to the group as a pattern, + * (either as an explicit object, or set as the source pattern). + * + * This group functionality can be convenient for performing + * intermediate compositing. One common use of a group is to render + * objects as opaque within the group, (so that they occlude each + * other), and then blend the result with translucence onto the + * destination. + * + * Groups can be nested arbitrarily deep by making balanced calls to + * cairo_push_group()/cairo_pop_group(). Each call pushes/pops the new + * target group onto/from a stack. + * + * The cairo_push_group() function calls cairo_save() so that any + * changes to the graphics state will not be visible outside the + * group, (the pop_group functions call cairo_restore()). + * + * By default the intermediate group will have a content type of + * %CAIRO_CONTENT_COLOR_ALPHA. Other content types can be chosen for + * the group by using cairo_push_group_with_content() instead. + * + * As an example, here is how one might fill and stroke a path with + * translucence, but without any portion of the fill being visible + * under the stroke: + * + * + * cairo_push_group (cr); + * cairo_set_source (cr, fill_pattern); + * cairo_fill_preserve (cr); + * cairo_set_source (cr, stroke_pattern); + * cairo_stroke (cr); + * cairo_pop_group_to_source (cr); + * cairo_paint_with_alpha (cr, alpha); + * + * + * Since: 1.2 + **/ +void +cairo_push_group (cairo_t *cr) +{ + cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA); +} + +/** + * cairo_push_group_with_content: + * @cr: a cairo context + * @content: a #cairo_content_t indicating the type of group that + * will be created + * + * Temporarily redirects drawing to an intermediate surface known as a + * group. The redirection lasts until the group is completed by a call + * to cairo_pop_group() or cairo_pop_group_to_source(). These calls + * provide the result of any drawing to the group as a pattern, + * (either as an explicit object, or set as the source pattern). + * + * The group will have a content type of @content. The ability to + * control this content type is the only distinction between this + * function and cairo_push_group() which you should see for a more + * detailed description of group rendering. + * + * Since: 1.2 + **/ +void +cairo_push_group_with_content (cairo_t *cr, cairo_content_t content) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->push_group (cr, content); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_push_group_with_content); + +/** + * cairo_pop_group: + * @cr: a cairo context + * + * Terminates the redirection begun by a call to cairo_push_group() or + * cairo_push_group_with_content() and returns a new pattern + * containing the results of all drawing operations performed to the + * group. + * + * The cairo_pop_group() function calls cairo_restore(), (balancing a + * call to cairo_save() by the push_group function), so that any + * changes to the graphics state will not be visible outside the + * group. + * + * Return value: a newly created (surface) pattern containing the + * results of all drawing operations performed to the group. The + * caller owns the returned object and should call + * cairo_pattern_destroy() when finished with it. + * + * Since: 1.2 + **/ +cairo_pattern_t * +cairo_pop_group (cairo_t *cr) +{ + cairo_pattern_t *group_pattern; + + if (unlikely (cr->status)) + return _cairo_pattern_create_in_error (cr->status); + + group_pattern = cr->backend->pop_group (cr); + if (unlikely (group_pattern->status)) + _cairo_set_error (cr, group_pattern->status); + + return group_pattern; +} +slim_hidden_def(cairo_pop_group); + +/** + * cairo_pop_group_to_source: + * @cr: a cairo context + * + * Terminates the redirection begun by a call to cairo_push_group() or + * cairo_push_group_with_content() and installs the resulting pattern + * as the source pattern in the given cairo context. + * + * The behavior of this function is equivalent to the sequence of + * operations: + * + * + * cairo_pattern_t *group = cairo_pop_group (cr); + * cairo_set_source (cr, group); + * cairo_pattern_destroy (group); + * + * + * but is more convenient as their is no need for a variable to store + * the short-lived pointer to the pattern. + * + * The cairo_pop_group() function calls cairo_restore(), (balancing a + * call to cairo_save() by the push_group function), so that any + * changes to the graphics state will not be visible outside the + * group. + * + * Since: 1.2 + **/ +void +cairo_pop_group_to_source (cairo_t *cr) +{ + cairo_pattern_t *group_pattern; + + group_pattern = cairo_pop_group (cr); + cairo_set_source (cr, group_pattern); + cairo_pattern_destroy (group_pattern); +} + +/** + * cairo_set_operator: + * @cr: a #cairo_t + * @op: a compositing operator, specified as a #cairo_operator_t + * + * Sets the compositing operator to be used for all drawing + * operations. See #cairo_operator_t for details on the semantics of + * each available compositing operator. + * + * The default operator is %CAIRO_OPERATOR_OVER. + * + * Since: 1.0 + **/ +void +cairo_set_operator (cairo_t *cr, cairo_operator_t op) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_operator (cr, op); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_operator); + + +#if 0 +/** + * cairo_set_opacity: + * @cr: a #cairo_t + * @opacity: the level of opacity to use when compositing + * + * Sets the compositing opacity to be used for all drawing + * operations. The effect is to fade out the operations + * using the alpha value. + * + * The default opacity is 1. + * + * Since: TBD + **/ +void +cairo_set_opacity (cairo_t *cr, double opacity) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_opacity (cr, opacity); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +#endif + +/** + * cairo_set_source_rgb: + * @cr: a cairo context + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * + * Sets the source pattern within @cr to an opaque color. This opaque + * color will then be used for any subsequent drawing operation until + * a new source pattern is set. + * + * The color components are floating point numbers in the range 0 to + * 1. If the values passed in are outside that range, they will be + * clamped. + * + * The default source pattern is opaque black, (that is, it is + * equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)). + * + * Since: 1.0 + **/ +void +cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_source_rgba (cr, red, green, blue, 1.); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_source_rgb); + +/** + * cairo_set_source_rgba: + * @cr: a cairo context + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * @alpha: alpha component of color + * + * Sets the source pattern within @cr to a translucent color. This + * color will then be used for any subsequent drawing operation until + * a new source pattern is set. + * + * The color and alpha components are floating point numbers in the + * range 0 to 1. If the values passed in are outside that range, they + * will be clamped. + * + * The default source pattern is opaque black, (that is, it is + * equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)). + * + * Since: 1.0 + **/ +void +cairo_set_source_rgba (cairo_t *cr, + double red, double green, double blue, + double alpha) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_source_rgba (cr, red, green, blue, alpha); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_set_source_surface: + * @cr: a cairo context + * @surface: a surface to be used to set the source pattern + * @x: User-space X coordinate for surface origin + * @y: User-space Y coordinate for surface origin + * + * This is a convenience function for creating a pattern from @surface + * and setting it as the source in @cr with cairo_set_source(). + * + * The @x and @y parameters give the user-space coordinate at which + * the surface origin should appear. (The surface origin is its + * upper-left corner before any transformation has been applied.) The + * @x and @y parameters are negated and then set as translation values + * in the pattern matrix. + * + * Other than the initial translation pattern matrix, as described + * above, all other pattern attributes, (such as its extend mode), are + * set to the default values as in cairo_pattern_create_for_surface(). + * The resulting pattern can be queried with cairo_get_source() so + * that these attributes can be modified if desired, (eg. to create a + * repeating pattern with cairo_pattern_set_extend()). + * + * Since: 1.0 + **/ +void +cairo_set_source_surface (cairo_t *cr, + cairo_surface_t *surface, + double x, + double y) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (unlikely (surface == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + status = cr->backend->set_source_surface (cr, surface, x, y); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_source_surface); + +/** + * cairo_set_source: + * @cr: a cairo context + * @source: a #cairo_pattern_t to be used as the source for + * subsequent drawing operations. + * + * Sets the source pattern within @cr to @source. This pattern + * will then be used for any subsequent drawing operation until a new + * source pattern is set. + * + * Note: The pattern's transformation matrix will be locked to the + * user space in effect at the time of cairo_set_source(). This means + * that further modifications of the current transformation matrix + * will not affect the source pattern. See cairo_pattern_set_matrix(). + * + * The default source pattern is a solid pattern that is opaque black, + * (that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, + * 0.0)). + * + * Since: 1.0 + **/ +void +cairo_set_source (cairo_t *cr, cairo_pattern_t *source) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (unlikely (source == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + if (unlikely (source->status)) { + _cairo_set_error (cr, source->status); + return; + } + + status = cr->backend->set_source (cr, source); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_source); + +/** + * cairo_get_source: + * @cr: a cairo context + * + * Gets the current source pattern for @cr. + * + * Return value: the current source pattern. This object is owned by + * cairo. To keep a reference to it, you must call + * cairo_pattern_reference(). + * + * Since: 1.0 + **/ +cairo_pattern_t * +cairo_get_source (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_pattern_create_in_error (cr->status); + + return cr->backend->get_source (cr); +} + +/** + * cairo_set_tolerance: + * @cr: a #cairo_t + * @tolerance: the tolerance, in device units (typically pixels) + * + * Sets the tolerance used when converting paths into trapezoids. + * Curved segments of the path will be subdivided until the maximum + * deviation between the original path and the polygonal approximation + * is less than @tolerance. The default value is 0.1. A larger + * value will give better performance, a smaller value, better + * appearance. (Reducing the value from the default value of 0.1 + * is unlikely to improve appearance significantly.) The accuracy of paths + * within Cairo is limited by the precision of its internal arithmetic, and + * the prescribed @tolerance is restricted to the smallest + * representable internal value. + * + * Since: 1.0 + **/ +void +cairo_set_tolerance (cairo_t *cr, double tolerance) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_tolerance (cr, tolerance); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_tolerance); + +/** + * cairo_set_antialias: + * @cr: a #cairo_t + * @antialias: the new antialiasing mode + * + * Set the antialiasing mode of the rasterizer used for drawing shapes. + * This value is a hint, and a particular backend may or may not support + * a particular value. At the current time, no backend supports + * %CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes. + * + * Note that this option does not affect text rendering, instead see + * cairo_font_options_set_antialias(). + * + * Since: 1.0 + **/ +void +cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_antialias (cr, antialias); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_set_fill_rule: + * @cr: a #cairo_t + * @fill_rule: a fill rule, specified as a #cairo_fill_rule_t + * + * Set the current fill rule within the cairo context. The fill rule + * is used to determine which regions are inside or outside a complex + * (potentially self-intersecting) path. The current fill rule affects + * both cairo_fill() and cairo_clip(). See #cairo_fill_rule_t for details + * on the semantics of each available fill rule. + * + * The default fill rule is %CAIRO_FILL_RULE_WINDING. + * + * Since: 1.0 + **/ +void +cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_fill_rule (cr, fill_rule); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_set_line_width: + * @cr: a #cairo_t + * @width: a line width + * + * Sets the current line width within the cairo context. The line + * width value specifies the diameter of a pen that is circular in + * user space, (though device-space pen may be an ellipse in general + * due to scaling/shear/rotation of the CTM). + * + * Note: When the description above refers to user space and CTM it + * refers to the user space and CTM in effect at the time of the + * stroking operation, not the user space and CTM in effect at the + * time of the call to cairo_set_line_width(). The simplest usage + * makes both of these spaces identical. That is, if there is no + * change to the CTM between a call to cairo_set_line_width() and the + * stroking operation, then one can just pass user-space values to + * cairo_set_line_width() and ignore this note. + * + * As with the other stroke parameters, the current line width is + * examined by cairo_stroke(), cairo_stroke_extents(), and + * cairo_stroke_to_path(), but does not have any effect during path + * construction. + * + * The default line width value is 2.0. + * + * Since: 1.0 + **/ +void +cairo_set_line_width (cairo_t *cr, double width) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (width < 0.) + width = 0.; + + status = cr->backend->set_line_width (cr, width); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_line_width); + +/** + * cairo_set_line_cap: + * @cr: a cairo context + * @line_cap: a line cap style + * + * Sets the current line cap style within the cairo context. See + * #cairo_line_cap_t for details about how the available line cap + * styles are drawn. + * + * As with the other stroke parameters, the current line cap style is + * examined by cairo_stroke(), cairo_stroke_extents(), and + * cairo_stroke_to_path(), but does not have any effect during path + * construction. + * + * The default line cap style is %CAIRO_LINE_CAP_BUTT. + * + * Since: 1.0 + **/ +void +cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_line_cap (cr, line_cap); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_line_cap); + +/** + * cairo_set_line_join: + * @cr: a cairo context + * @line_join: a line join style + * + * Sets the current line join style within the cairo context. See + * #cairo_line_join_t for details about how the available line join + * styles are drawn. + * + * As with the other stroke parameters, the current line join style is + * examined by cairo_stroke(), cairo_stroke_extents(), and + * cairo_stroke_to_path(), but does not have any effect during path + * construction. + * + * The default line join style is %CAIRO_LINE_JOIN_MITER. + * + * Since: 1.0 + **/ +void +cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_line_join (cr, line_join); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_line_join); + +/** + * cairo_set_dash: + * @cr: a cairo context + * @dashes: an array specifying alternate lengths of on and off stroke portions + * @num_dashes: the length of the dashes array + * @offset: an offset into the dash pattern at which the stroke should start + * + * Sets the dash pattern to be used by cairo_stroke(). A dash pattern + * is specified by @dashes, an array of positive values. Each value + * provides the length of alternate "on" and "off" portions of the + * stroke. The @offset specifies an offset into the pattern at which + * the stroke begins. + * + * Each "on" segment will have caps applied as if the segment were a + * separate sub-path. In particular, it is valid to use an "on" length + * of 0.0 with %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE in order + * to distributed dots or squares along a path. + * + * Note: The length values are in user-space units as evaluated at the + * time of stroking. This is not necessarily the same as the user + * space at the time of cairo_set_dash(). + * + * If @num_dashes is 0 dashing is disabled. + * + * If @num_dashes is 1 a symmetric pattern is assumed with alternating + * on and off portions of the size specified by the single value in + * @dashes. + * + * If any value in @dashes is negative, or if all values are 0, then + * @cr will be put into an error state with a status of + * %CAIRO_STATUS_INVALID_DASH. + * + * Since: 1.0 + **/ +void +cairo_set_dash (cairo_t *cr, + const double *dashes, + int num_dashes, + double offset) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_dash (cr, dashes, num_dashes, offset); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_get_dash_count: + * @cr: a #cairo_t + * + * This function returns the length of the dash array in @cr (0 if dashing + * is not currently in effect). + * + * See also cairo_set_dash() and cairo_get_dash(). + * + * Return value: the length of the dash array, or 0 if no dash array set. + * + * Since: 1.4 + **/ +int +cairo_get_dash_count (cairo_t *cr) +{ + int num_dashes; + + if (unlikely (cr->status)) + return 0; + + cr->backend->get_dash (cr, NULL, &num_dashes, NULL); + + return num_dashes; +} + +/** + * cairo_get_dash: + * @cr: a #cairo_t + * @dashes: return value for the dash array, or %NULL + * @offset: return value for the current dash offset, or %NULL + * + * Gets the current dash array. If not %NULL, @dashes should be big + * enough to hold at least the number of values returned by + * cairo_get_dash_count(). + * + * Since: 1.4 + **/ +void +cairo_get_dash (cairo_t *cr, + double *dashes, + double *offset) +{ + if (unlikely (cr->status)) + return; + + cr->backend->get_dash (cr, dashes, NULL, offset); +} + +/** + * cairo_set_miter_limit: + * @cr: a cairo context + * @limit: miter limit to set + * + * Sets the current miter limit within the cairo context. + * + * If the current line join style is set to %CAIRO_LINE_JOIN_MITER + * (see cairo_set_line_join()), the miter limit is used to determine + * whether the lines should be joined with a bevel instead of a miter. + * Cairo divides the length of the miter by the line width. + * If the result is greater than the miter limit, the style is + * converted to a bevel. + * + * As with the other stroke parameters, the current line miter limit is + * examined by cairo_stroke(), cairo_stroke_extents(), and + * cairo_stroke_to_path(), but does not have any effect during path + * construction. + * + * The default miter limit value is 10.0, which will convert joins + * with interior angles less than 11 degrees to bevels instead of + * miters. For reference, a miter limit of 2.0 makes the miter cutoff + * at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90 + * degrees. + * + * A miter limit for a desired angle can be computed as: miter limit = + * 1/sin(angle/2) + * + * Since: 1.0 + **/ +void +cairo_set_miter_limit (cairo_t *cr, double limit) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_miter_limit (cr, limit); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_translate: + * @cr: a cairo context + * @tx: amount to translate in the X direction + * @ty: amount to translate in the Y direction + * + * Modifies the current transformation matrix (CTM) by translating the + * user-space origin by (@tx, @ty). This offset is interpreted as a + * user-space coordinate according to the CTM in place before the new + * call to cairo_translate(). In other words, the translation of the + * user-space origin takes place after any existing transformation. + * + * Since: 1.0 + **/ +void +cairo_translate (cairo_t *cr, double tx, double ty) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->translate (cr, tx, ty); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_translate); + +/** + * cairo_scale: + * @cr: a cairo context + * @sx: scale factor for the X dimension + * @sy: scale factor for the Y dimension + * + * Modifies the current transformation matrix (CTM) by scaling the X + * and Y user-space axes by @sx and @sy respectively. The scaling of + * the axes takes place after any existing transformation of user + * space. + * + * Since: 1.0 + **/ +void +cairo_scale (cairo_t *cr, double sx, double sy) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->scale (cr, sx, sy); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_scale); + +/** + * cairo_rotate: + * @cr: a cairo context + * @angle: angle (in radians) by which the user-space axes will be + * rotated + * + * Modifies the current transformation matrix (CTM) by rotating the + * user-space axes by @angle radians. The rotation of the axes takes + * places after any existing transformation of user space. The + * rotation direction for positive angles is from the positive X axis + * toward the positive Y axis. + * + * Since: 1.0 + **/ +void +cairo_rotate (cairo_t *cr, double angle) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->rotate (cr, angle); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_transform: + * @cr: a cairo context + * @matrix: a transformation to be applied to the user-space axes + * + * Modifies the current transformation matrix (CTM) by applying + * @matrix as an additional transformation. The new transformation of + * user space takes place after any existing transformation. + * + * Since: 1.0 + **/ +void +cairo_transform (cairo_t *cr, + const cairo_matrix_t *matrix) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->transform (cr, matrix); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_transform); + +/** + * cairo_set_matrix: + * @cr: a cairo context + * @matrix: a transformation matrix from user space to device space + * + * Modifies the current transformation matrix (CTM) by setting it + * equal to @matrix. + * + * Since: 1.0 + **/ +void +cairo_set_matrix (cairo_t *cr, + const cairo_matrix_t *matrix) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_matrix (cr, matrix); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_matrix); + +/** + * cairo_identity_matrix: + * @cr: a cairo context + * + * Resets the current transformation matrix (CTM) by setting it equal + * to the identity matrix. That is, the user-space and device-space + * axes will be aligned and one user-space unit will transform to one + * device-space unit. + * + * Since: 1.0 + **/ +void +cairo_identity_matrix (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_identity_matrix (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_user_to_device: + * @cr: a cairo context + * @x: X value of coordinate (in/out parameter) + * @y: Y value of coordinate (in/out parameter) + * + * Transform a coordinate from user space to device space by + * multiplying the given point by the current transformation matrix + * (CTM). + * + * Since: 1.0 + **/ +void +cairo_user_to_device (cairo_t *cr, double *x, double *y) +{ + if (unlikely (cr->status)) + return; + + cr->backend->user_to_device (cr, x, y); +} +slim_hidden_def (cairo_user_to_device); + +/** + * cairo_user_to_device_distance: + * @cr: a cairo context + * @dx: X component of a distance vector (in/out parameter) + * @dy: Y component of a distance vector (in/out parameter) + * + * Transform a distance vector from user space to device space. This + * function is similar to cairo_user_to_device() except that the + * translation components of the CTM will be ignored when transforming + * (@dx,@dy). + * + * Since: 1.0 + **/ +void +cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy) +{ + if (unlikely (cr->status)) + return; + + cr->backend->user_to_device_distance (cr, dx, dy); +} +slim_hidden_def (cairo_user_to_device_distance); + +/** + * cairo_device_to_user: + * @cr: a cairo + * @x: X value of coordinate (in/out parameter) + * @y: Y value of coordinate (in/out parameter) + * + * Transform a coordinate from device space to user space by + * multiplying the given point by the inverse of the current + * transformation matrix (CTM). + * + * Since: 1.0 + **/ +void +cairo_device_to_user (cairo_t *cr, double *x, double *y) +{ + if (unlikely (cr->status)) + return; + + cr->backend->device_to_user (cr, x, y); +} +slim_hidden_def (cairo_device_to_user); + +/** + * cairo_device_to_user_distance: + * @cr: a cairo context + * @dx: X component of a distance vector (in/out parameter) + * @dy: Y component of a distance vector (in/out parameter) + * + * Transform a distance vector from device space to user space. This + * function is similar to cairo_device_to_user() except that the + * translation components of the inverse CTM will be ignored when + * transforming (@dx,@dy). + * + * Since: 1.0 + **/ +void +cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy) +{ + if (unlikely (cr->status)) + return; + + cr->backend->device_to_user_distance (cr, dx, dy); +} + +/** + * cairo_new_path: + * @cr: a cairo context + * + * Clears the current path. After this call there will be no path and + * no current point. + * + * Since: 1.0 + **/ +void +cairo_new_path (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->new_path (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_new_path); + +/** + * cairo_new_sub_path: + * @cr: a cairo context + * + * Begin a new sub-path. Note that the existing path is not + * affected. After this call there will be no current point. + * + * In many cases, this call is not needed since new sub-paths are + * frequently started with cairo_move_to(). + * + * A call to cairo_new_sub_path() is particularly useful when + * beginning a new sub-path with one of the cairo_arc() calls. This + * makes things easier as it is no longer necessary to manually + * compute the arc's initial coordinates for a call to + * cairo_move_to(). + * + * Since: 1.2 + **/ +void +cairo_new_sub_path (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->new_sub_path (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_move_to: + * @cr: a cairo context + * @x: the X coordinate of the new position + * @y: the Y coordinate of the new position + * + * Begin a new sub-path. After this call the current point will be (@x, + * @y). + * + * Since: 1.0 + **/ +void +cairo_move_to (cairo_t *cr, double x, double y) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->move_to (cr, x, y); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_move_to); + + +/** + * cairo_line_to: + * @cr: a cairo context + * @x: the X coordinate of the end of the new line + * @y: the Y coordinate of the end of the new line + * + * Adds a line to the path from the current point to position (@x, @y) + * in user-space coordinates. After this call the current point + * will be (@x, @y). + * + * If there is no current point before the call to cairo_line_to() + * this function will behave as cairo_move_to(@cr, @x, @y). + * + * Since: 1.0 + **/ +void +cairo_line_to (cairo_t *cr, double x, double y) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->line_to (cr, x, y); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_line_to); + +/** + * cairo_curve_to: + * @cr: a cairo context + * @x1: the X coordinate of the first control point + * @y1: the Y coordinate of the first control point + * @x2: the X coordinate of the second control point + * @y2: the Y coordinate of the second control point + * @x3: the X coordinate of the end of the curve + * @y3: the Y coordinate of the end of the curve + * + * Adds a cubic Bézier spline to the path from the current point to + * position (@x3, @y3) in user-space coordinates, using (@x1, @y1) and + * (@x2, @y2) as the control points. After this call the current point + * will be (@x3, @y3). + * + * If there is no current point before the call to cairo_curve_to() + * this function will behave as if preceded by a call to + * cairo_move_to(@cr, @x1, @y1). + * + * Since: 1.0 + **/ +void +cairo_curve_to (cairo_t *cr, + double x1, double y1, + double x2, double y2, + double x3, double y3) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->curve_to (cr, + x1, y1, + x2, y2, + x3, y3); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_curve_to); + +/** + * cairo_arc: + * @cr: a cairo context + * @xc: X position of the center of the arc + * @yc: Y position of the center of the arc + * @radius: the radius of the arc + * @angle1: the start angle, in radians + * @angle2: the end angle, in radians + * + * Adds a circular arc of the given @radius to the current path. The + * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in + * the direction of increasing angles to end at @angle2. If @angle2 is + * less than @angle1 it will be progressively increased by + * 2*M_PI until it is greater than @angle1. + * + * If there is a current point, an initial line segment will be added + * to the path to connect the current point to the beginning of the + * arc. If this initial line is undesired, it can be avoided by + * calling cairo_new_sub_path() before calling cairo_arc(). + * + * Angles are measured in radians. An angle of 0.0 is in the direction + * of the positive X axis (in user space). An angle of + * M_PI/2.0 radians (90 degrees) is in the + * direction of the positive Y axis (in user space). Angles increase + * in the direction from the positive X axis toward the positive Y + * axis. So with the default transformation matrix, angles increase in + * a clockwise direction. + * + * (To convert from degrees to radians, use degrees * (M_PI / + * 180.).) + * + * This function gives the arc in the direction of increasing angles; + * see cairo_arc_negative() to get the arc in the direction of + * decreasing angles. + * + * The arc is circular in user space. To achieve an elliptical arc, + * you can scale the current transformation matrix by different + * amounts in the X and Y directions. For example, to draw an ellipse + * in the box given by @x, @y, @width, @height: + * + * + * cairo_save (cr); + * cairo_translate (cr, x + width / 2., y + height / 2.); + * cairo_scale (cr, width / 2., height / 2.); + * cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI); + * cairo_restore (cr); + * + * + * Since: 1.0 + **/ +void +cairo_arc (cairo_t *cr, + double xc, double yc, + double radius, + double angle1, double angle2) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (angle2 < angle1) { + /* increase angle2 by multiples of full circle until it + * satisfies angle2 >= angle1 */ + angle2 = fmod (angle2 - angle1, 2 * M_PI); + if (angle2 < 0) + angle2 += 2 * M_PI; + angle2 += angle1; + } + + status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, TRUE); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_arc_negative: + * @cr: a cairo context + * @xc: X position of the center of the arc + * @yc: Y position of the center of the arc + * @radius: the radius of the arc + * @angle1: the start angle, in radians + * @angle2: the end angle, in radians + * + * Adds a circular arc of the given @radius to the current path. The + * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in + * the direction of decreasing angles to end at @angle2. If @angle2 is + * greater than @angle1 it will be progressively decreased by + * 2*M_PI until it is less than @angle1. + * + * See cairo_arc() for more details. This function differs only in the + * direction of the arc between the two angles. + * + * Since: 1.0 + **/ +void +cairo_arc_negative (cairo_t *cr, + double xc, double yc, + double radius, + double angle1, double angle2) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (angle2 > angle1) { + /* decrease angle2 by multiples of full circle until it + * satisfies angle2 <= angle1 */ + angle2 = fmod (angle2 - angle1, 2 * M_PI); + if (angle2 > 0) + angle2 -= 2 * M_PI; + angle2 += angle1; + } + + status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, FALSE); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/* XXX: NYI +void +cairo_arc_to (cairo_t *cr, + double x1, double y1, + double x2, double y2, + double radius) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->arc_to (cr, x1, y1, x2, y2, radius); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +void +cairo_rel_arc_to (cairo_t *cr, + double dx1, double dy1, + double dx2, double dy2, + double radius) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->rel_arc_to (cr, dx1, dy1, dx2, dy2, radius); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +*/ + +/** + * cairo_rel_move_to: + * @cr: a cairo context + * @dx: the X offset + * @dy: the Y offset + * + * Begin a new sub-path. After this call the current point will offset + * by (@x, @y). + * + * Given a current point of (x, y), cairo_rel_move_to(@cr, @dx, @dy) + * is logically equivalent to cairo_move_to(@cr, x + @dx, y + @dy). + * + * It is an error to call this function with no current point. Doing + * so will cause @cr to shutdown with a status of + * %CAIRO_STATUS_NO_CURRENT_POINT. + * + * Since: 1.0 + **/ +void +cairo_rel_move_to (cairo_t *cr, double dx, double dy) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->rel_move_to (cr, dx, dy); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_rel_line_to: + * @cr: a cairo context + * @dx: the X offset to the end of the new line + * @dy: the Y offset to the end of the new line + * + * Relative-coordinate version of cairo_line_to(). Adds a line to the + * path from the current point to a point that is offset from the + * current point by (@dx, @dy) in user space. After this call the + * current point will be offset by (@dx, @dy). + * + * Given a current point of (x, y), cairo_rel_line_to(@cr, @dx, @dy) + * is logically equivalent to cairo_line_to(@cr, x + @dx, y + @dy). + * + * It is an error to call this function with no current point. Doing + * so will cause @cr to shutdown with a status of + * %CAIRO_STATUS_NO_CURRENT_POINT. + * + * Since: 1.0 + **/ +void +cairo_rel_line_to (cairo_t *cr, double dx, double dy) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->rel_line_to (cr, dx, dy); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_rel_line_to); + +/** + * cairo_rel_curve_to: + * @cr: a cairo context + * @dx1: the X offset to the first control point + * @dy1: the Y offset to the first control point + * @dx2: the X offset to the second control point + * @dy2: the Y offset to the second control point + * @dx3: the X offset to the end of the curve + * @dy3: the Y offset to the end of the curve + * + * Relative-coordinate version of cairo_curve_to(). All offsets are + * relative to the current point. Adds a cubic Bézier spline to the + * path from the current point to a point offset from the current + * point by (@dx3, @dy3), using points offset by (@dx1, @dy1) and + * (@dx2, @dy2) as the control points. After this call the current + * point will be offset by (@dx3, @dy3). + * + * Given a current point of (x, y), cairo_rel_curve_to(@cr, @dx1, + * @dy1, @dx2, @dy2, @dx3, @dy3) is logically equivalent to + * cairo_curve_to(@cr, x+@dx1, y+@dy1, x+@dx2, y+@dy2, x+@dx3, y+@dy3). + * + * It is an error to call this function with no current point. Doing + * so will cause @cr to shutdown with a status of + * %CAIRO_STATUS_NO_CURRENT_POINT. + * + * Since: 1.0 + **/ +void +cairo_rel_curve_to (cairo_t *cr, + double dx1, double dy1, + double dx2, double dy2, + double dx3, double dy3) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->rel_curve_to (cr, + dx1, dy1, + dx2, dy2, + dx3, dy3); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_rectangle: + * @cr: a cairo context + * @x: the X coordinate of the top left corner of the rectangle + * @y: the Y coordinate to the top left corner of the rectangle + * @width: the width of the rectangle + * @height: the height of the rectangle + * + * Adds a closed sub-path rectangle of the given size to the current + * path at position (@x, @y) in user-space coordinates. + * + * This function is logically equivalent to: + * + * cairo_move_to (cr, x, y); + * cairo_rel_line_to (cr, width, 0); + * cairo_rel_line_to (cr, 0, height); + * cairo_rel_line_to (cr, -width, 0); + * cairo_close_path (cr); + * + * + * Since: 1.0 + **/ +void +cairo_rectangle (cairo_t *cr, + double x, double y, + double width, double height) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->rectangle (cr, x, y, width, height); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +#if 0 +/* XXX: NYI */ +void +cairo_stroke_to_path (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + /* The code in _cairo_recording_surface_get_path has a poorman's stroke_to_path */ + + status = _cairo_gstate_stroke_path (cr->gstate); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +#endif + +/** + * cairo_close_path: + * @cr: a cairo context + * + * Adds a line segment to the path from the current point to the + * beginning of the current sub-path, (the most recent point passed to + * cairo_move_to()), and closes this sub-path. After this call the + * current point will be at the joined endpoint of the sub-path. + * + * The behavior of cairo_close_path() is distinct from simply calling + * cairo_line_to() with the equivalent coordinate in the case of + * stroking. When a closed sub-path is stroked, there are no caps on + * the ends of the sub-path. Instead, there is a line join connecting + * the final and initial segments of the sub-path. + * + * If there is no current point before the call to cairo_close_path(), + * this function will have no effect. + * + * Note: As of cairo version 1.2.4 any call to cairo_close_path() will + * place an explicit MOVE_TO element into the path immediately after + * the CLOSE_PATH element, (which can be seen in cairo_copy_path() for + * example). This can simplify path processing in some cases as it may + * not be necessary to save the "last move_to point" during processing + * as the MOVE_TO immediately after the CLOSE_PATH will provide that + * point. + * + * Since: 1.0 + **/ +void +cairo_close_path (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->close_path (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_close_path); + +/** + * cairo_path_extents: + * @cr: a cairo context + * @x1: left of the resulting extents + * @y1: top of the resulting extents + * @x2: right of the resulting extents + * @y2: bottom of the resulting extents + * + * Computes a bounding box in user-space coordinates covering the + * points on the current path. If the current path is empty, returns + * an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule, + * surface dimensions and clipping are not taken into account. + * + * Contrast with cairo_fill_extents() and cairo_stroke_extents() which + * return the extents of only the area that would be "inked" by + * the corresponding drawing operations. + * + * The result of cairo_path_extents() is defined as equivalent to the + * limit of cairo_stroke_extents() with %CAIRO_LINE_CAP_ROUND as the + * line width approaches 0.0, (but never reaching the empty-rectangle + * returned by cairo_stroke_extents() for a line width of 0.0). + * + * Specifically, this means that zero-area sub-paths such as + * cairo_move_to();cairo_line_to() segments, (even degenerate cases + * where the coordinates to both calls are identical), will be + * considered as contributing to the extents. However, a lone + * cairo_move_to() will not contribute to the results of + * cairo_path_extents(). + * + * Since: 1.6 + **/ +void +cairo_path_extents (cairo_t *cr, + double *x1, double *y1, double *x2, double *y2) +{ + if (unlikely (cr->status)) { + if (x1) + *x1 = 0.0; + if (y1) + *y1 = 0.0; + if (x2) + *x2 = 0.0; + if (y2) + *y2 = 0.0; + + return; + } + + cr->backend->path_extents (cr, x1, y1, x2, y2); +} + +/** + * cairo_paint: + * @cr: a cairo context + * + * A drawing operator that paints the current source everywhere within + * the current clip region. + * + * Since: 1.0 + **/ +void +cairo_paint (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->paint (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_paint); + +/** + * cairo_paint_with_alpha: + * @cr: a cairo context + * @alpha: alpha value, between 0 (transparent) and 1 (opaque) + * + * A drawing operator that paints the current source everywhere within + * the current clip region using a mask of constant alpha value + * @alpha. The effect is similar to cairo_paint(), but the drawing + * is faded out using the alpha value. + * + * Since: 1.0 + **/ +void +cairo_paint_with_alpha (cairo_t *cr, + double alpha) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->paint_with_alpha (cr, alpha); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_mask: + * @cr: a cairo context + * @pattern: a #cairo_pattern_t + * + * A drawing operator that paints the current source + * using the alpha channel of @pattern as a mask. (Opaque + * areas of @pattern are painted with the source, transparent + * areas are not painted.) + * + * Since: 1.0 + **/ +void +cairo_mask (cairo_t *cr, + cairo_pattern_t *pattern) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (unlikely (pattern == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + if (unlikely (pattern->status)) { + _cairo_set_error (cr, pattern->status); + return; + } + + status = cr->backend->mask (cr, pattern); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_mask); + +/** + * cairo_mask_surface: + * @cr: a cairo context + * @surface: a #cairo_surface_t + * @surface_x: X coordinate at which to place the origin of @surface + * @surface_y: Y coordinate at which to place the origin of @surface + * + * A drawing operator that paints the current source + * using the alpha channel of @surface as a mask. (Opaque + * areas of @surface are painted with the source, transparent + * areas are not painted.) + * + * Since: 1.0 + **/ +void +cairo_mask_surface (cairo_t *cr, + cairo_surface_t *surface, + double surface_x, + double surface_y) +{ + cairo_pattern_t *pattern; + cairo_matrix_t matrix; + + if (unlikely (cr->status)) + return; + + pattern = cairo_pattern_create_for_surface (surface); + + cairo_matrix_init_translate (&matrix, - surface_x, - surface_y); + cairo_pattern_set_matrix (pattern, &matrix); + + cairo_mask (cr, pattern); + + cairo_pattern_destroy (pattern); +} + +/** + * cairo_stroke: + * @cr: a cairo context + * + * A drawing operator that strokes the current path according to the + * current line width, line join, line cap, and dash settings. After + * cairo_stroke(), the current path will be cleared from the cairo + * context. See cairo_set_line_width(), cairo_set_line_join(), + * cairo_set_line_cap(), cairo_set_dash(), and + * cairo_stroke_preserve(). + * + * Note: Degenerate segments and sub-paths are treated specially and + * provide a useful result. These can result in two different + * situations: + * + * 1. Zero-length "on" segments set in cairo_set_dash(). If the cap + * style is %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE then these + * segments will be drawn as circular dots or squares respectively. In + * the case of %CAIRO_LINE_CAP_SQUARE, the orientation of the squares + * is determined by the direction of the underlying path. + * + * 2. A sub-path created by cairo_move_to() followed by either a + * cairo_close_path() or one or more calls to cairo_line_to() to the + * same coordinate as the cairo_move_to(). If the cap style is + * %CAIRO_LINE_CAP_ROUND then these sub-paths will be drawn as circular + * dots. Note that in the case of %CAIRO_LINE_CAP_SQUARE a degenerate + * sub-path will not be drawn at all, (since the correct orientation + * is indeterminate). + * + * In no case will a cap style of %CAIRO_LINE_CAP_BUTT cause anything + * to be drawn in the case of either degenerate segments or sub-paths. + * + * Since: 1.0 + **/ +void +cairo_stroke (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->stroke (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_stroke); + +/** + * cairo_stroke_preserve: + * @cr: a cairo context + * + * A drawing operator that strokes the current path according to the + * current line width, line join, line cap, and dash settings. Unlike + * cairo_stroke(), cairo_stroke_preserve() preserves the path within the + * cairo context. + * + * See cairo_set_line_width(), cairo_set_line_join(), + * cairo_set_line_cap(), cairo_set_dash(), and + * cairo_stroke_preserve(). + * + * Since: 1.0 + **/ +void +cairo_stroke_preserve (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->stroke_preserve (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_stroke_preserve); + +/** + * cairo_fill: + * @cr: a cairo context + * + * A drawing operator that fills the current path according to the + * current fill rule, (each sub-path is implicitly closed before being + * filled). After cairo_fill(), the current path will be cleared from + * the cairo context. See cairo_set_fill_rule() and + * cairo_fill_preserve(). + * + * Since: 1.0 + **/ +void +cairo_fill (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->fill (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_fill_preserve: + * @cr: a cairo context + * + * A drawing operator that fills the current path according to the + * current fill rule, (each sub-path is implicitly closed before being + * filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the + * path within the cairo context. + * + * See cairo_set_fill_rule() and cairo_fill(). + * + * Since: 1.0 + **/ +void +cairo_fill_preserve (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->fill_preserve (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_fill_preserve); + +/** + * cairo_copy_page: + * @cr: a cairo context + * + * Emits the current page for backends that support multiple pages, but + * doesn't clear it, so, the contents of the current page will be retained + * for the next page too. Use cairo_show_page() if you want to get an + * empty page after the emission. + * + * This is a convenience function that simply calls + * cairo_surface_copy_page() on @cr's target. + * + * Since: 1.0 + **/ +void +cairo_copy_page (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->copy_page (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_show_page: + * @cr: a cairo context + * + * Emits and clears the current page for backends that support multiple + * pages. Use cairo_copy_page() if you don't want to clear the page. + * + * This is a convenience function that simply calls + * cairo_surface_show_page() on @cr's target. + * + * Since: 1.0 + **/ +void +cairo_show_page (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->show_page (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_in_stroke: + * @cr: a cairo context + * @x: X coordinate of the point to test + * @y: Y coordinate of the point to test + * + * Tests whether the given point is inside the area that would be + * affected by a cairo_stroke() operation given the current path and + * stroking parameters. Surface dimensions and clipping are not taken + * into account. + * + * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(), + * cairo_set_line_cap(), cairo_set_dash(), and + * cairo_stroke_preserve(). + * + * Return value: A non-zero value if the point is inside, or zero if + * outside. + * + * Since: 1.0 + **/ +cairo_bool_t +cairo_in_stroke (cairo_t *cr, double x, double y) +{ + cairo_status_t status; + cairo_bool_t inside = FALSE; + + if (unlikely (cr->status)) + return FALSE; + + status = cr->backend->in_stroke (cr, x, y, &inside); + if (unlikely (status)) + _cairo_set_error (cr, status); + + return inside; +} + +/** + * cairo_in_fill: + * @cr: a cairo context + * @x: X coordinate of the point to test + * @y: Y coordinate of the point to test + * + * Tests whether the given point is inside the area that would be + * affected by a cairo_fill() operation given the current path and + * filling parameters. Surface dimensions and clipping are not taken + * into account. + * + * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve(). + * + * Return value: A non-zero value if the point is inside, or zero if + * outside. + * + * Since: 1.0 + **/ +cairo_bool_t +cairo_in_fill (cairo_t *cr, double x, double y) +{ + cairo_status_t status; + cairo_bool_t inside = FALSE; + + if (unlikely (cr->status)) + return FALSE; + + status = cr->backend->in_fill (cr, x, y, &inside); + if (unlikely (status)) + _cairo_set_error (cr, status); + + return inside; +} + +/** + * cairo_stroke_extents: + * @cr: a cairo context + * @x1: left of the resulting extents + * @y1: top of the resulting extents + * @x2: right of the resulting extents + * @y2: bottom of the resulting extents + * + * Computes a bounding box in user coordinates covering the area that + * would be affected, (the "inked" area), by a cairo_stroke() + * operation given the current path and stroke parameters. + * If the current path is empty, returns an empty rectangle ((0,0), (0,0)). + * Surface dimensions and clipping are not taken into account. + * + * Note that if the line width is set to exactly zero, then + * cairo_stroke_extents() will return an empty rectangle. Contrast with + * cairo_path_extents() which can be used to compute the non-empty + * bounds as the line width approaches zero. + * + * Note that cairo_stroke_extents() must necessarily do more work to + * compute the precise inked areas in light of the stroke parameters, + * so cairo_path_extents() may be more desirable for sake of + * performance if non-inked path extents are desired. + * + * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(), + * cairo_set_line_cap(), cairo_set_dash(), and + * cairo_stroke_preserve(). + * + * Since: 1.0 + **/ +void +cairo_stroke_extents (cairo_t *cr, + double *x1, double *y1, double *x2, double *y2) +{ + cairo_status_t status; + + if (unlikely (cr->status)) { + if (x1) + *x1 = 0.0; + if (y1) + *y1 = 0.0; + if (x2) + *x2 = 0.0; + if (y2) + *y2 = 0.0; + + return; + } + + status = cr->backend->stroke_extents (cr, x1, y1, x2, y2); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_fill_extents: + * @cr: a cairo context + * @x1: left of the resulting extents + * @y1: top of the resulting extents + * @x2: right of the resulting extents + * @y2: bottom of the resulting extents + * + * Computes a bounding box in user coordinates covering the area that + * would be affected, (the "inked" area), by a cairo_fill() operation + * given the current path and fill parameters. If the current path is + * empty, returns an empty rectangle ((0,0), (0,0)). Surface + * dimensions and clipping are not taken into account. + * + * Contrast with cairo_path_extents(), which is similar, but returns + * non-zero extents for some paths with no inked area, (such as a + * simple line segment). + * + * Note that cairo_fill_extents() must necessarily do more work to + * compute the precise inked areas in light of the fill rule, so + * cairo_path_extents() may be more desirable for sake of performance + * if the non-inked path extents are desired. + * + * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve(). + * + * Since: 1.0 + **/ +void +cairo_fill_extents (cairo_t *cr, + double *x1, double *y1, double *x2, double *y2) +{ + cairo_status_t status; + + if (unlikely (cr->status)) { + if (x1) + *x1 = 0.0; + if (y1) + *y1 = 0.0; + if (x2) + *x2 = 0.0; + if (y2) + *y2 = 0.0; + + return; + } + + status = cr->backend->fill_extents (cr, x1, y1, x2, y2); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_clip: + * @cr: a cairo context + * + * Establishes a new clip region by intersecting the current clip + * region with the current path as it would be filled by cairo_fill() + * and according to the current fill rule (see cairo_set_fill_rule()). + * + * After cairo_clip(), the current path will be cleared from the cairo + * context. + * + * The current clip region affects all drawing operations by + * effectively masking out any changes to the surface that are outside + * the current clip region. + * + * Calling cairo_clip() can only make the clip region smaller, never + * larger. But the current clip is part of the graphics state, so a + * temporary restriction of the clip region can be achieved by + * calling cairo_clip() within a cairo_save()/cairo_restore() + * pair. The only other means of increasing the size of the clip + * region is cairo_reset_clip(). + * + * Since: 1.0 + **/ +void +cairo_clip (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->clip (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_clip_preserve: + * @cr: a cairo context + * + * Establishes a new clip region by intersecting the current clip + * region with the current path as it would be filled by cairo_fill() + * and according to the current fill rule (see cairo_set_fill_rule()). + * + * Unlike cairo_clip(), cairo_clip_preserve() preserves the path within + * the cairo context. + * + * The current clip region affects all drawing operations by + * effectively masking out any changes to the surface that are outside + * the current clip region. + * + * Calling cairo_clip_preserve() can only make the clip region smaller, never + * larger. But the current clip is part of the graphics state, so a + * temporary restriction of the clip region can be achieved by + * calling cairo_clip_preserve() within a cairo_save()/cairo_restore() + * pair. The only other means of increasing the size of the clip + * region is cairo_reset_clip(). + * + * Since: 1.0 + **/ +void +cairo_clip_preserve (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->clip_preserve (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def(cairo_clip_preserve); + +/** + * cairo_reset_clip: + * @cr: a cairo context + * + * Reset the current clip region to its original, unrestricted + * state. That is, set the clip region to an infinitely large shape + * containing the target surface. Equivalently, if infinity is too + * hard to grasp, one can imagine the clip region being reset to the + * exact bounds of the target surface. + * + * Note that code meant to be reusable should not call + * cairo_reset_clip() as it will cause results unexpected by + * higher-level code which calls cairo_clip(). Consider using + * cairo_save() and cairo_restore() around cairo_clip() as a more + * robust means of temporarily restricting the clip region. + * + * Since: 1.0 + **/ +void +cairo_reset_clip (cairo_t *cr) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->reset_clip (cr); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_clip_extents: + * @cr: a cairo context + * @x1: left of the resulting extents + * @y1: top of the resulting extents + * @x2: right of the resulting extents + * @y2: bottom of the resulting extents + * + * Computes a bounding box in user coordinates covering the area inside the + * current clip. + * + * Since: 1.4 + **/ +void +cairo_clip_extents (cairo_t *cr, + double *x1, double *y1, + double *x2, double *y2) +{ + cairo_status_t status; + + if (x1) + *x1 = 0.0; + if (y1) + *y1 = 0.0; + if (x2) + *x2 = 0.0; + if (y2) + *y2 = 0.0; + + if (unlikely (cr->status)) + return; + + status = cr->backend->clip_extents (cr, x1, y1, x2, y2); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_in_clip: + * @cr: a cairo context + * @x: X coordinate of the point to test + * @y: Y coordinate of the point to test + * + * Tests whether the given point is inside the area that would be + * visible through the current clip, i.e. the area that would be filled by + * a cairo_paint() operation. + * + * See cairo_clip(), and cairo_clip_preserve(). + * + * Return value: A non-zero value if the point is inside, or zero if + * outside. + * + * Since: 1.10 + **/ +cairo_bool_t +cairo_in_clip (cairo_t *cr, double x, double y) +{ + cairo_status_t status; + cairo_bool_t inside = FALSE; + + if (unlikely (cr->status)) + return FALSE; + + status = cr->backend->in_clip (cr, x, y, &inside); + if (unlikely (status)) + _cairo_set_error (cr, status); + + return inside; +} + +/** + * cairo_copy_clip_rectangle_list: + * @cr: a cairo context + * + * Gets the current clip region as a list of rectangles in user coordinates. + * Never returns %NULL. + * + * The status in the list may be %CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to + * indicate that the clip region cannot be represented as a list of + * user-space rectangles. The status may have other values to indicate + * other errors. + * + * Returns: the current clip region as a list of rectangles in user coordinates, + * which should be destroyed using cairo_rectangle_list_destroy(). + * + * Since: 1.4 + **/ +cairo_rectangle_list_t * +cairo_copy_clip_rectangle_list (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_rectangle_list_create_in_error (cr->status); + + return cr->backend->clip_copy_rectangle_list (cr); +} + +/** + * cairo_select_font_face: + * @cr: a #cairo_t + * @family: a font family name, encoded in UTF-8 + * @slant: the slant for the font + * @weight: the weight for the font + * + * Note: The cairo_select_font_face() function call is part of what + * the cairo designers call the "toy" text API. It is convenient for + * short demos and simple programs, but it is not expected to be + * adequate for serious text-using applications. + * + * Selects a family and style of font from a simplified description as + * a family name, slant and weight. Cairo provides no operation to + * list available family names on the system (this is a "toy", + * remember), but the standard CSS2 generic family names, ("serif", + * "sans-serif", "cursive", "fantasy", "monospace"), are likely to + * work as expected. + * + * If @family starts with the string "@cairo:", or if no native font + * backends are compiled in, cairo will use an internal font family. + * The internal font family recognizes many modifiers in the @family + * string, most notably, it recognizes the string "monospace". That is, + * the family name "@cairo:monospace" will use the monospace version of + * the internal font family. + * + * For "real" font selection, see the font-backend-specific + * font_face_create functions for the font backend you are using. (For + * example, if you are using the freetype-based cairo-ft font backend, + * see cairo_ft_font_face_create_for_ft_face() or + * cairo_ft_font_face_create_for_pattern().) The resulting font face + * could then be used with cairo_scaled_font_create() and + * cairo_set_scaled_font(). + * + * Similarly, when using the "real" font support, you can call + * directly into the underlying font system, (such as fontconfig or + * freetype), for operations such as listing available fonts, etc. + * + * It is expected that most applications will need to use a more + * comprehensive font handling and text layout library, (for example, + * pango), in conjunction with cairo. + * + * If text is drawn without a call to cairo_select_font_face(), (nor + * cairo_set_font_face() nor cairo_set_scaled_font()), the default + * family is platform-specific, but is essentially "sans-serif". + * Default slant is %CAIRO_FONT_SLANT_NORMAL, and default weight is + * %CAIRO_FONT_WEIGHT_NORMAL. + * + * This function is equivalent to a call to cairo_toy_font_face_create() + * followed by cairo_set_font_face(). + * + * Since: 1.0 + **/ +void +cairo_select_font_face (cairo_t *cr, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) +{ + cairo_font_face_t *font_face; + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + font_face = cairo_toy_font_face_create (family, slant, weight); + if (unlikely (font_face->status)) { + _cairo_set_error (cr, font_face->status); + return; + } + + status = cr->backend->set_font_face (cr, font_face); + cairo_font_face_destroy (font_face); + + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_font_extents: + * @cr: a #cairo_t + * @extents: a #cairo_font_extents_t object into which the results + * will be stored. + * + * Gets the font extents for the currently selected font. + * + * Since: 1.0 + **/ +void +cairo_font_extents (cairo_t *cr, + cairo_font_extents_t *extents) +{ + cairo_status_t status; + + extents->ascent = 0.0; + extents->descent = 0.0; + extents->height = 0.0; + extents->max_x_advance = 0.0; + extents->max_y_advance = 0.0; + + if (unlikely (cr->status)) + return; + + status = cr->backend->font_extents (cr, extents); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_set_font_face: + * @cr: a #cairo_t + * @font_face: a #cairo_font_face_t, or %NULL to restore to the default font + * + * Replaces the current #cairo_font_face_t object in the #cairo_t with + * @font_face. The replaced font face in the #cairo_t will be + * destroyed if there are no other references to it. + * + * Since: 1.0 + **/ +void +cairo_set_font_face (cairo_t *cr, + cairo_font_face_t *font_face) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_font_face (cr, font_face); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_get_font_face: + * @cr: a #cairo_t + * + * Gets the current font face for a #cairo_t. + * + * Return value: the current font face. This object is owned by + * cairo. To keep a reference to it, you must call + * cairo_font_face_reference(). + * + * This function never returns %NULL. If memory cannot be allocated, a + * special "nil" #cairo_font_face_t object will be returned on which + * cairo_font_face_status() returns %CAIRO_STATUS_NO_MEMORY. Using + * this nil object will cause its error state to propagate to other + * objects it is passed to, (for example, calling + * cairo_set_font_face() with a nil font will trigger an error that + * will shutdown the #cairo_t object). + * + * Since: 1.0 + **/ +cairo_font_face_t * +cairo_get_font_face (cairo_t *cr) +{ + if (unlikely (cr->status)) + return (cairo_font_face_t*) &_cairo_font_face_nil; + + return cr->backend->get_font_face (cr); +} + +/** + * cairo_set_font_size: + * @cr: a #cairo_t + * @size: the new font size, in user space units + * + * Sets the current font matrix to a scale by a factor of @size, replacing + * any font matrix previously set with cairo_set_font_size() or + * cairo_set_font_matrix(). This results in a font size of @size user space + * units. (More precisely, this matrix will result in the font's + * em-square being a @size by @size square in user space.) + * + * If text is drawn without a call to cairo_set_font_size(), (nor + * cairo_set_font_matrix() nor cairo_set_scaled_font()), the default + * font size is 10.0. + * + * Since: 1.0 + **/ +void +cairo_set_font_size (cairo_t *cr, double size) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_font_size (cr, size); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_font_size); + +/** + * cairo_set_font_matrix: + * @cr: a #cairo_t + * @matrix: a #cairo_matrix_t describing a transform to be applied to + * the current font. + * + * Sets the current font matrix to @matrix. The font matrix gives a + * transformation from the design space of the font (in this space, + * the em-square is 1 unit by 1 unit) to user space. Normally, a + * simple scale is used (see cairo_set_font_size()), but a more + * complex font matrix can be used to shear the font + * or stretch it unequally along the two axes + * + * Since: 1.0 + **/ +void +cairo_set_font_matrix (cairo_t *cr, + const cairo_matrix_t *matrix) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cr->backend->set_font_matrix (cr, matrix); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_font_matrix); + +/** + * cairo_get_font_matrix: + * @cr: a #cairo_t + * @matrix: return value for the matrix + * + * Stores the current font matrix into @matrix. See + * cairo_set_font_matrix(). + * + * Since: 1.0 + **/ +void +cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix) +{ + if (unlikely (cr->status)) { + cairo_matrix_init_identity (matrix); + return; + } + + cr->backend->get_font_matrix (cr, matrix); +} + +/** + * cairo_set_font_options: + * @cr: a #cairo_t + * @options: font options to use + * + * Sets a set of custom font rendering options for the #cairo_t. + * Rendering options are derived by merging these options with the + * options derived from underlying surface; if the value in @options + * has a default value (like %CAIRO_ANTIALIAS_DEFAULT), then the value + * from the surface is used. + * + * Since: 1.0 + **/ +void +cairo_set_font_options (cairo_t *cr, + const cairo_font_options_t *options) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + status = cairo_font_options_status ((cairo_font_options_t *) options); + if (unlikely (status)) { + _cairo_set_error (cr, status); + return; + } + + status = cr->backend->set_font_options (cr, options); + if (unlikely (status)) + _cairo_set_error (cr, status); +} +slim_hidden_def (cairo_set_font_options); + +/** + * cairo_get_font_options: + * @cr: a #cairo_t + * @options: a #cairo_font_options_t object into which to store + * the retrieved options. All existing values are overwritten + * + * Retrieves font rendering options set via #cairo_set_font_options. + * Note that the returned options do not include any options derived + * from the underlying surface; they are literally the options + * passed to cairo_set_font_options(). + * + * Since: 1.0 + **/ +void +cairo_get_font_options (cairo_t *cr, + cairo_font_options_t *options) +{ + /* check that we aren't trying to overwrite the nil object */ + if (cairo_font_options_status (options)) + return; + + if (unlikely (cr->status)) { + _cairo_font_options_init_default (options); + return; + } + + cr->backend->get_font_options (cr, options); +} + +/** + * cairo_set_scaled_font: + * @cr: a #cairo_t + * @scaled_font: a #cairo_scaled_font_t + * + * Replaces the current font face, font matrix, and font options in + * the #cairo_t with those of the #cairo_scaled_font_t. Except for + * some translation, the current CTM of the #cairo_t should be the + * same as that of the #cairo_scaled_font_t, which can be accessed + * using cairo_scaled_font_get_ctm(). + * + * Since: 1.2 + **/ +void +cairo_set_scaled_font (cairo_t *cr, + const cairo_scaled_font_t *scaled_font) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if ((scaled_font == NULL)) { + _cairo_set_error (cr, _cairo_error (CAIRO_STATUS_NULL_POINTER)); + return; + } + + status = scaled_font->status; + if (unlikely (status)) { + _cairo_set_error (cr, status); + return; + } + + status = cr->backend->set_scaled_font (cr, (cairo_scaled_font_t *) scaled_font); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_get_scaled_font: + * @cr: a #cairo_t + * + * Gets the current scaled font for a #cairo_t. + * + * Return value: the current scaled font. This object is owned by + * cairo. To keep a reference to it, you must call + * cairo_scaled_font_reference(). + * + * This function never returns %NULL. If memory cannot be allocated, a + * special "nil" #cairo_scaled_font_t object will be returned on which + * cairo_scaled_font_status() returns %CAIRO_STATUS_NO_MEMORY. Using + * this nil object will cause its error state to propagate to other + * objects it is passed to, (for example, calling + * cairo_set_scaled_font() with a nil font will trigger an error that + * will shutdown the #cairo_t object). + * + * Since: 1.4 + **/ +cairo_scaled_font_t * +cairo_get_scaled_font (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_scaled_font_create_in_error (cr->status); + + return cr->backend->get_scaled_font (cr); +} +slim_hidden_def (cairo_get_scaled_font); + +/** + * cairo_text_extents: + * @cr: a #cairo_t + * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL + * @extents: a #cairo_text_extents_t object into which the results + * will be stored + * + * Gets the extents for a string of text. The extents describe a + * user-space rectangle that encloses the "inked" portion of the text, + * (as it would be drawn by cairo_show_text()). Additionally, the + * x_advance and y_advance values indicate the amount by which the + * current point would be advanced by cairo_show_text(). + * + * Note that whitespace characters do not directly contribute to the + * size of the rectangle (extents.width and extents.height). They do + * contribute indirectly by changing the position of non-whitespace + * characters. In particular, trailing whitespace characters are + * likely to not affect the size of the rectangle, though they will + * affect the x_advance and y_advance values. + * + * Since: 1.0 + **/ +void +cairo_text_extents (cairo_t *cr, + const char *utf8, + cairo_text_extents_t *extents) +{ + cairo_status_t status; + cairo_scaled_font_t *scaled_font; + cairo_glyph_t *glyphs = NULL; + int num_glyphs = 0; + double x, y; + + extents->x_bearing = 0.0; + extents->y_bearing = 0.0; + extents->width = 0.0; + extents->height = 0.0; + extents->x_advance = 0.0; + extents->y_advance = 0.0; + + if (unlikely (cr->status)) + return; + + if (utf8 == NULL) + return; + + scaled_font = cairo_get_scaled_font (cr); + if (unlikely (scaled_font->status)) { + _cairo_set_error (cr, scaled_font->status); + return; + } + + cairo_get_current_point (cr, &x, &y); + status = cairo_scaled_font_text_to_glyphs (scaled_font, + x, y, + utf8, -1, + &glyphs, &num_glyphs, + NULL, NULL, NULL); + + if (likely (status == CAIRO_STATUS_SUCCESS)) { + status = cr->backend->glyph_extents (cr, + glyphs, num_glyphs, + extents); + } + cairo_glyph_free (glyphs); + + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_glyph_extents: + * @cr: a #cairo_t + * @glyphs: an array of #cairo_glyph_t objects + * @num_glyphs: the number of elements in @glyphs + * @extents: a #cairo_text_extents_t object into which the results + * will be stored + * + * Gets the extents for an array of glyphs. The extents describe a + * user-space rectangle that encloses the "inked" portion of the + * glyphs, (as they would be drawn by cairo_show_glyphs()). + * Additionally, the x_advance and y_advance values indicate the + * amount by which the current point would be advanced by + * cairo_show_glyphs(). + * + * Note that whitespace glyphs do not contribute to the size of the + * rectangle (extents.width and extents.height). + * + * Since: 1.0 + **/ +void +cairo_glyph_extents (cairo_t *cr, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents) +{ + cairo_status_t status; + + extents->x_bearing = 0.0; + extents->y_bearing = 0.0; + extents->width = 0.0; + extents->height = 0.0; + extents->x_advance = 0.0; + extents->y_advance = 0.0; + + if (unlikely (cr->status)) + return; + + if (num_glyphs == 0) + return; + + if (unlikely (num_glyphs < 0)) { + _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); + return; + } + + if (unlikely (glyphs == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + status = cr->backend->glyph_extents (cr, glyphs, num_glyphs, extents); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_show_text: + * @cr: a cairo context + * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL + * + * A drawing operator that generates the shape from a string of UTF-8 + * characters, rendered according to the current font_face, font_size + * (font_matrix), and font_options. + * + * This function first computes a set of glyphs for the string of + * text. The first glyph is placed so that its origin is at the + * current point. The origin of each subsequent glyph is offset from + * that of the previous glyph by the advance values of the previous + * glyph. + * + * After this call the current point is moved to the origin of where + * the next glyph would be placed in this same progression. That is, + * the current point will be at the origin of the final glyph offset + * by its advance values. This allows for easy display of a single + * logical string with multiple calls to cairo_show_text(). + * + * Note: The cairo_show_text() function call is part of what the cairo + * designers call the "toy" text API. It is convenient for short demos + * and simple programs, but it is not expected to be adequate for + * serious text-using applications. See cairo_show_glyphs() for the + * "real" text display API in cairo. + * + * Since: 1.0 + **/ +void +cairo_show_text (cairo_t *cr, const char *utf8) +{ + cairo_text_extents_t extents; + cairo_status_t status; + cairo_glyph_t *glyphs, *last_glyph; + cairo_text_cluster_t *clusters; + int utf8_len, num_glyphs, num_clusters; + cairo_text_cluster_flags_t cluster_flags; + double x, y; + cairo_bool_t has_show_text_glyphs; + cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; + cairo_text_cluster_t stack_clusters[CAIRO_STACK_ARRAY_LENGTH (cairo_text_cluster_t)]; + cairo_scaled_font_t *scaled_font; + cairo_glyph_text_info_t info, *i; + + if (unlikely (cr->status)) + return; + + if (utf8 == NULL) + return; + + scaled_font = cairo_get_scaled_font (cr); + if (unlikely (scaled_font->status)) { + _cairo_set_error (cr, scaled_font->status); + return; + } + + utf8_len = strlen (utf8); + + has_show_text_glyphs = + cairo_surface_has_show_text_glyphs (cairo_get_target (cr)); + + glyphs = stack_glyphs; + num_glyphs = ARRAY_LENGTH (stack_glyphs); + + if (has_show_text_glyphs) { + clusters = stack_clusters; + num_clusters = ARRAY_LENGTH (stack_clusters); + } else { + clusters = NULL; + num_clusters = 0; + } + + cairo_get_current_point (cr, &x, &y); + status = cairo_scaled_font_text_to_glyphs (scaled_font, + x, y, + utf8, utf8_len, + &glyphs, &num_glyphs, + has_show_text_glyphs ? &clusters : NULL, &num_clusters, + &cluster_flags); + if (unlikely (status)) + goto BAIL; + + if (num_glyphs == 0) + return; + + i = NULL; + if (has_show_text_glyphs) { + info.utf8 = utf8; + info.utf8_len = utf8_len; + info.clusters = clusters; + info.num_clusters = num_clusters; + info.cluster_flags = cluster_flags; + i = &info; + } + + status = cr->backend->glyphs (cr, glyphs, num_glyphs, i); + if (unlikely (status)) + goto BAIL; + + last_glyph = &glyphs[num_glyphs - 1]; + status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents); + if (unlikely (status)) + goto BAIL; + + x = last_glyph->x + extents.x_advance; + y = last_glyph->y + extents.y_advance; + cr->backend->move_to (cr, x, y); + + BAIL: + if (glyphs != stack_glyphs) + cairo_glyph_free (glyphs); + if (clusters != stack_clusters) + cairo_text_cluster_free (clusters); + + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_show_glyphs: + * @cr: a cairo context + * @glyphs: array of glyphs to show + * @num_glyphs: number of glyphs to show + * + * A drawing operator that generates the shape from an array of glyphs, + * rendered according to the current font face, font size + * (font matrix), and font options. + * + * Since: 1.0 + **/ +void +cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (num_glyphs == 0) + return; + + if (num_glyphs < 0) { + _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); + return; + } + + if (glyphs == NULL) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_show_text_glyphs: + * @cr: a cairo context + * @utf8: a string of text encoded in UTF-8 + * @utf8_len: length of @utf8 in bytes, or -1 if it is NUL-terminated + * @glyphs: array of glyphs to show + * @num_glyphs: number of glyphs to show + * @clusters: array of cluster mapping information + * @num_clusters: number of clusters in the mapping + * @cluster_flags: cluster mapping flags + * + * This operation has rendering effects similar to cairo_show_glyphs() + * but, if the target surface supports it, uses the provided text and + * cluster mapping to embed the text for the glyphs shown in the output. + * If the target does not support the extended attributes, this function + * acts like the basic cairo_show_glyphs() as if it had been passed + * @glyphs and @num_glyphs. + * + * The mapping between @utf8 and @glyphs is provided by an array of + * clusters. Each cluster covers a number of + * text bytes and glyphs, and neighboring clusters cover neighboring + * areas of @utf8 and @glyphs. The clusters should collectively cover @utf8 + * and @glyphs in entirety. + * + * The first cluster always covers bytes from the beginning of @utf8. + * If @cluster_flags do not have the %CAIRO_TEXT_CLUSTER_FLAG_BACKWARD + * set, the first cluster also covers the beginning + * of @glyphs, otherwise it covers the end of the @glyphs array and + * following clusters move backward. + * + * See #cairo_text_cluster_t for constraints on valid clusters. + * + * Since: 1.8 + **/ +void +cairo_show_text_glyphs (cairo_t *cr, + const char *utf8, + int utf8_len, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + /* A slew of sanity checks */ + + /* Special case for NULL and -1 */ + if (utf8 == NULL && utf8_len == -1) + utf8_len = 0; + + /* No NULLs for non-zeros */ + if ((num_glyphs && glyphs == NULL) || + (utf8_len && utf8 == NULL) || + (num_clusters && clusters == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + /* A -1 for utf8_len means NUL-terminated */ + if (utf8_len == -1) + utf8_len = strlen (utf8); + + /* Apart from that, no negatives */ + if (num_glyphs < 0 || utf8_len < 0 || num_clusters < 0) { + _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); + return; + } + + if (num_glyphs == 0 && utf8_len == 0) + return; + + if (utf8) { + /* Make sure clusters cover the entire glyphs and utf8 arrays, + * and that cluster boundaries are UTF-8 boundaries. */ + status = _cairo_validate_text_clusters (utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, cluster_flags); + if (status == CAIRO_STATUS_INVALID_CLUSTERS) { + /* Either got invalid UTF-8 text, or cluster mapping is bad. + * Differentiate those. */ + + cairo_status_t status2; + + status2 = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL); + if (status2) + status = status2; + } else { + cairo_glyph_text_info_t info; + + info.utf8 = utf8; + info.utf8_len = utf8_len; + info.clusters = clusters; + info.num_clusters = num_clusters; + info.cluster_flags = cluster_flags; + + status = cr->backend->glyphs (cr, glyphs, num_glyphs, &info); + } + } else { + status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL); + } + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_text_path: + * @cr: a cairo context + * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL + * + * Adds closed paths for text to the current path. The generated + * path if filled, achieves an effect similar to that of + * cairo_show_text(). + * + * Text conversion and positioning is done similar to cairo_show_text(). + * + * Like cairo_show_text(), After this call the current point is + * moved to the origin of where the next glyph would be placed in + * this same progression. That is, the current point will be at + * the origin of the final glyph offset by its advance values. + * This allows for chaining multiple calls to to cairo_text_path() + * without having to set current point in between. + * + * Note: The cairo_text_path() function call is part of what the cairo + * designers call the "toy" text API. It is convenient for short demos + * and simple programs, but it is not expected to be adequate for + * serious text-using applications. See cairo_glyph_path() for the + * "real" text path API in cairo. + * + * Since: 1.0 + **/ +void +cairo_text_path (cairo_t *cr, const char *utf8) +{ + cairo_status_t status; + cairo_text_extents_t extents; + cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)]; + cairo_glyph_t *glyphs, *last_glyph; + cairo_scaled_font_t *scaled_font; + int num_glyphs; + double x, y; + + if (unlikely (cr->status)) + return; + + if (utf8 == NULL) + return; + + + glyphs = stack_glyphs; + num_glyphs = ARRAY_LENGTH (stack_glyphs); + + scaled_font = cairo_get_scaled_font (cr); + if (unlikely (scaled_font->status)) { + _cairo_set_error (cr, scaled_font->status); + return; + } + + cairo_get_current_point (cr, &x, &y); + status = cairo_scaled_font_text_to_glyphs (scaled_font, + x, y, + utf8, -1, + &glyphs, &num_glyphs, + NULL, NULL, NULL); + + if (num_glyphs == 0) + return; + + status = cr->backend->glyph_path (cr, glyphs, num_glyphs); + + if (unlikely (status)) + goto BAIL; + + last_glyph = &glyphs[num_glyphs - 1]; + status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents); + + if (unlikely (status)) + goto BAIL; + + x = last_glyph->x + extents.x_advance; + y = last_glyph->y + extents.y_advance; + cr->backend->move_to (cr, x, y); + + BAIL: + if (glyphs != stack_glyphs) + cairo_glyph_free (glyphs); + + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_glyph_path: + * @cr: a cairo context + * @glyphs: array of glyphs to show + * @num_glyphs: number of glyphs to show + * + * Adds closed paths for the glyphs to the current path. The generated + * path if filled, achieves an effect similar to that of + * cairo_show_glyphs(). + * + * Since: 1.0 + **/ +void +cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (num_glyphs == 0) + return; + + if (unlikely (num_glyphs < 0)) { + _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT); + return; + } + + if (unlikely (glyphs == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + status = cr->backend->glyph_path (cr, glyphs, num_glyphs); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_get_operator: + * @cr: a cairo context + * + * Gets the current compositing operator for a cairo context. + * + * Return value: the current compositing operator. + * + * Since: 1.0 + **/ +cairo_operator_t +cairo_get_operator (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_OPERATOR_DEFAULT; + + return cr->backend->get_operator (cr); +} + +#if 0 +/** + * cairo_get_opacity: + * @cr: a cairo context + * + * Gets the current compositing opacity for a cairo context. + * + * Return value: the current compositing opacity. + * + * Since: TBD + **/ +double +cairo_get_opacity (cairo_t *cr) +{ + if (unlikely (cr->status)) + return 1.; + + return cr->backend->get_opacity (cr); +} +#endif + +/** + * cairo_get_tolerance: + * @cr: a cairo context + * + * Gets the current tolerance value, as set by cairo_set_tolerance(). + * + * Return value: the current tolerance value. + * + * Since: 1.0 + **/ +double +cairo_get_tolerance (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_TOLERANCE_DEFAULT; + + return cr->backend->get_tolerance (cr); +} +slim_hidden_def (cairo_get_tolerance); + +/** + * cairo_get_antialias: + * @cr: a cairo context + * + * Gets the current shape antialiasing mode, as set by + * cairo_set_antialias(). + * + * Return value: the current shape antialiasing mode. + * + * Since: 1.0 + **/ +cairo_antialias_t +cairo_get_antialias (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_ANTIALIAS_DEFAULT; + + return cr->backend->get_antialias (cr); +} + +/** + * cairo_has_current_point: + * @cr: a cairo context + * + * Returns whether a current point is defined on the current path. + * See cairo_get_current_point() for details on the current point. + * + * Return value: whether a current point is defined. + * + * Since: 1.6 + **/ +cairo_bool_t +cairo_has_current_point (cairo_t *cr) +{ + if (unlikely (cr->status)) + return FALSE; + + return cr->backend->has_current_point (cr); +} + +/** + * cairo_get_current_point: + * @cr: a cairo context + * @x: return value for X coordinate of the current point + * @y: return value for Y coordinate of the current point + * + * Gets the current point of the current path, which is + * conceptually the final point reached by the path so far. + * + * The current point is returned in the user-space coordinate + * system. If there is no defined current point or if @cr is in an + * error status, @x and @y will both be set to 0.0. It is possible to + * check this in advance with cairo_has_current_point(). + * + * Most path construction functions alter the current point. See the + * following for details on how they affect the current point: + * cairo_new_path(), cairo_new_sub_path(), + * cairo_append_path(), cairo_close_path(), + * cairo_move_to(), cairo_line_to(), cairo_curve_to(), + * cairo_rel_move_to(), cairo_rel_line_to(), cairo_rel_curve_to(), + * cairo_arc(), cairo_arc_negative(), cairo_rectangle(), + * cairo_text_path(), cairo_glyph_path(), cairo_stroke_to_path(). + * + * Some functions use and alter the current point but do not + * otherwise change current path: + * cairo_show_text(). + * + * Some functions unset the current path and as a result, current point: + * cairo_fill(), cairo_stroke(). + * + * Since: 1.0 + **/ +void +cairo_get_current_point (cairo_t *cr, double *x_ret, double *y_ret) +{ + double x, y; + + x = y = 0; + if (cr->status == CAIRO_STATUS_SUCCESS && + cr->backend->has_current_point (cr)) + { + cr->backend->get_current_point (cr, &x, &y); + } + + if (x_ret) + *x_ret = x; + if (y_ret) + *y_ret = y; +} +slim_hidden_def(cairo_get_current_point); + +/** + * cairo_get_fill_rule: + * @cr: a cairo context + * + * Gets the current fill rule, as set by cairo_set_fill_rule(). + * + * Return value: the current fill rule. + * + * Since: 1.0 + **/ +cairo_fill_rule_t +cairo_get_fill_rule (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_FILL_RULE_DEFAULT; + + return cr->backend->get_fill_rule (cr); +} + +/** + * cairo_get_line_width: + * @cr: a cairo context + * + * This function returns the current line width value exactly as set by + * cairo_set_line_width(). Note that the value is unchanged even if + * the CTM has changed between the calls to cairo_set_line_width() and + * cairo_get_line_width(). + * + * Return value: the current line width. + * + * Since: 1.0 + **/ +double +cairo_get_line_width (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_LINE_WIDTH_DEFAULT; + + return cr->backend->get_line_width (cr); +} +slim_hidden_def (cairo_get_line_width); + +/** + * cairo_get_line_cap: + * @cr: a cairo context + * + * Gets the current line cap style, as set by cairo_set_line_cap(). + * + * Return value: the current line cap style. + * + * Since: 1.0 + **/ +cairo_line_cap_t +cairo_get_line_cap (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_LINE_CAP_DEFAULT; + + return cr->backend->get_line_cap (cr); +} + +/** + * cairo_get_line_join: + * @cr: a cairo context + * + * Gets the current line join style, as set by cairo_set_line_join(). + * + * Return value: the current line join style. + * + * Since: 1.0 + **/ +cairo_line_join_t +cairo_get_line_join (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_LINE_JOIN_DEFAULT; + + return cr->backend->get_line_join (cr); +} + +/** + * cairo_get_miter_limit: + * @cr: a cairo context + * + * Gets the current miter limit, as set by cairo_set_miter_limit(). + * + * Return value: the current miter limit. + * + * Since: 1.0 + **/ +double +cairo_get_miter_limit (cairo_t *cr) +{ + if (unlikely (cr->status)) + return CAIRO_GSTATE_MITER_LIMIT_DEFAULT; + + return cr->backend->get_miter_limit (cr); +} + +/** + * cairo_get_matrix: + * @cr: a cairo context + * @matrix: return value for the matrix + * + * Stores the current transformation matrix (CTM) into @matrix. + * + * Since: 1.0 + **/ +void +cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix) +{ + if (unlikely (cr->status)) { + cairo_matrix_init_identity (matrix); + return; + } + + cr->backend->get_matrix (cr, matrix); +} +slim_hidden_def (cairo_get_matrix); + +/** + * cairo_get_target: + * @cr: a cairo context + * + * Gets the target surface for the cairo context as passed to + * cairo_create(). + * + * This function will always return a valid pointer, but the result + * can be a "nil" surface if @cr is already in an error state, + * (ie. cairo_status() != %CAIRO_STATUS_SUCCESS). + * A nil surface is indicated by cairo_surface_status() + * != %CAIRO_STATUS_SUCCESS. + * + * Return value: the target surface. This object is owned by cairo. To + * keep a reference to it, you must call cairo_surface_reference(). + * + * Since: 1.0 + **/ +cairo_surface_t * +cairo_get_target (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_surface_create_in_error (cr->status); + + return cr->backend->get_original_target (cr); +} +slim_hidden_def (cairo_get_target); + +/** + * cairo_get_group_target: + * @cr: a cairo context + * + * Gets the current destination surface for the context. This is either + * the original target surface as passed to cairo_create() or the target + * surface for the current group as started by the most recent call to + * cairo_push_group() or cairo_push_group_with_content(). + * + * This function will always return a valid pointer, but the result + * can be a "nil" surface if @cr is already in an error state, + * (ie. cairo_status() != %CAIRO_STATUS_SUCCESS). + * A nil surface is indicated by cairo_surface_status() + * != %CAIRO_STATUS_SUCCESS. + * + * Return value: the target surface. This object is owned by cairo. To + * keep a reference to it, you must call cairo_surface_reference(). + * + * Since: 1.2 + **/ +cairo_surface_t * +cairo_get_group_target (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_surface_create_in_error (cr->status); + + return cr->backend->get_current_target (cr); +} + +/** + * cairo_copy_path: + * @cr: a cairo context + * + * Creates a copy of the current path and returns it to the user as a + * #cairo_path_t. See #cairo_path_data_t for hints on how to iterate + * over the returned data structure. + * + * This function will always return a valid pointer, but the result + * will have no data (data==%NULL and + * num_data==0), if either of the following + * conditions hold: + * + * + * If there is insufficient memory to copy the path. In this + * case path->status will be set to + * %CAIRO_STATUS_NO_MEMORY. + * If @cr is already in an error state. In this case + * path->status will contain the same status that + * would be returned by cairo_status(). + * + * + * Return value: the copy of the current path. The caller owns the + * returned object and should call cairo_path_destroy() when finished + * with it. + * + * Since: 1.0 + **/ +cairo_path_t * +cairo_copy_path (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_path_create_in_error (cr->status); + + return cr->backend->copy_path (cr); +} + +/** + * cairo_copy_path_flat: + * @cr: a cairo context + * + * Gets a flattened copy of the current path and returns it to the + * user as a #cairo_path_t. See #cairo_path_data_t for hints on + * how to iterate over the returned data structure. + * + * This function is like cairo_copy_path() except that any curves + * in the path will be approximated with piecewise-linear + * approximations, (accurate to within the current tolerance + * value). That is, the result is guaranteed to not have any elements + * of type %CAIRO_PATH_CURVE_TO which will instead be replaced by a + * series of %CAIRO_PATH_LINE_TO elements. + * + * This function will always return a valid pointer, but the result + * will have no data (data==%NULL and + * num_data==0), if either of the following + * conditions hold: + * + * + * If there is insufficient memory to copy the path. In this + * case path->status will be set to + * %CAIRO_STATUS_NO_MEMORY. + * If @cr is already in an error state. In this case + * path->status will contain the same status that + * would be returned by cairo_status(). + * + * + * Return value: the copy of the current path. The caller owns the + * returned object and should call cairo_path_destroy() when finished + * with it. + * + * Since: 1.0 + **/ +cairo_path_t * +cairo_copy_path_flat (cairo_t *cr) +{ + if (unlikely (cr->status)) + return _cairo_path_create_in_error (cr->status); + + return cr->backend->copy_path_flat (cr); +} + +/** + * cairo_append_path: + * @cr: a cairo context + * @path: path to be appended + * + * Append the @path onto the current path. The @path may be either the + * return value from one of cairo_copy_path() or + * cairo_copy_path_flat() or it may be constructed manually. See + * #cairo_path_t for details on how the path data structure should be + * initialized, and note that path->status must be + * initialized to %CAIRO_STATUS_SUCCESS. + * + * Since: 1.0 + **/ +void +cairo_append_path (cairo_t *cr, + const cairo_path_t *path) +{ + cairo_status_t status; + + if (unlikely (cr->status)) + return; + + if (unlikely (path == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + if (unlikely (path->status)) { + if (path->status > CAIRO_STATUS_SUCCESS && + path->status <= CAIRO_STATUS_LAST_STATUS) + _cairo_set_error (cr, path->status); + else + _cairo_set_error (cr, CAIRO_STATUS_INVALID_STATUS); + return; + } + + if (path->num_data == 0) + return; + + if (unlikely (path->data == NULL)) { + _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER); + return; + } + + status = cr->backend->append_path (cr, path); + if (unlikely (status)) + _cairo_set_error (cr, status); +} + +/** + * cairo_status: + * @cr: a cairo context + * + * Checks whether an error has previously occurred for this context. + * + * Returns: the current status of this context, see #cairo_status_t + * + * Since: 1.0 + **/ +cairo_status_t +cairo_status (cairo_t *cr) +{ + return cr->status; +} +slim_hidden_def (cairo_status); diff --git a/Build/source/libs/cairo/cairo-src/src/cairo.h b/Build/source/libs/cairo/cairo-src/src/cairo.h new file mode 100644 index 00000000000..3104d47e4c4 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo.h @@ -0,0 +1,3153 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +#ifndef CAIRO_H +#define CAIRO_H + +#include "cairo-version.h" +#include "cairo-features.h" +#include "cairo-deprecated.h" + +#ifdef __cplusplus +# define CAIRO_BEGIN_DECLS extern "C" { +# define CAIRO_END_DECLS } +#else +# define CAIRO_BEGIN_DECLS +# define CAIRO_END_DECLS +#endif + +#ifndef cairo_public +# if defined (_MSC_VER) && ! defined (CAIRO_WIN32_STATIC_BUILD) +# define cairo_public __declspec(dllimport) +# else +# define cairo_public +# endif +#endif + +CAIRO_BEGIN_DECLS + +#define CAIRO_VERSION_ENCODE(major, minor, micro) ( \ + ((major) * 10000) \ + + ((minor) * 100) \ + + ((micro) * 1)) + +#define CAIRO_VERSION CAIRO_VERSION_ENCODE( \ + CAIRO_VERSION_MAJOR, \ + CAIRO_VERSION_MINOR, \ + CAIRO_VERSION_MICRO) + + +#define CAIRO_VERSION_STRINGIZE_(major, minor, micro) \ + #major"."#minor"."#micro +#define CAIRO_VERSION_STRINGIZE(major, minor, micro) \ + CAIRO_VERSION_STRINGIZE_(major, minor, micro) + +#define CAIRO_VERSION_STRING CAIRO_VERSION_STRINGIZE( \ + CAIRO_VERSION_MAJOR, \ + CAIRO_VERSION_MINOR, \ + CAIRO_VERSION_MICRO) + + +cairo_public int +cairo_version (void); + +cairo_public const char* +cairo_version_string (void); + +/** + * cairo_bool_t: + * + * #cairo_bool_t is used for boolean values. Returns of type + * #cairo_bool_t will always be either 0 or 1, but testing against + * these values explicitly is not encouraged; just use the + * value as a boolean condition. + * + * + * if (cairo_in_stroke (cr, x, y)) { + * /* do something */ + * } + * + * + * Since: 1.0 + **/ +typedef int cairo_bool_t; + +/** + * cairo_t: + * + * A #cairo_t contains the current state of the rendering device, + * including coordinates of yet to be drawn shapes. + * + * Cairo contexts, as #cairo_t objects are named, are central to + * cairo and all drawing with cairo is always done to a #cairo_t + * object. + * + * Memory management of #cairo_t is done with + * cairo_reference() and cairo_destroy(). + * + * Since: 1.0 + **/ +typedef struct _cairo cairo_t; + +/** + * cairo_surface_t: + * + * A #cairo_surface_t represents an image, either as the destination + * of a drawing operation or as source when drawing onto another + * surface. To draw to a #cairo_surface_t, create a cairo context + * with the surface as the target, using cairo_create(). + * + * There are different subtypes of #cairo_surface_t for + * different drawing backends; for example, cairo_image_surface_create() + * creates a bitmap image in memory. + * The type of a surface can be queried with cairo_surface_get_type(). + * + * The initial contents of a surface after creation depend upon the manner + * of its creation. If cairo creates the surface and backing storage for + * the user, it will be initially cleared; for example, + * cairo_image_surface_create() and cairo_surface_create_similar(). + * Alternatively, if the user passes in a reference to some backing storage + * and asks cairo to wrap that in a #cairo_surface_t, then the contents are + * not modified; for example, cairo_image_surface_create_for_data() and + * cairo_xlib_surface_create(). + * + * Memory management of #cairo_surface_t is done with + * cairo_surface_reference() and cairo_surface_destroy(). + * + * Since: 1.0 + **/ +typedef struct _cairo_surface cairo_surface_t; + +/** + * cairo_device_t: + * + * A #cairo_device_t represents the driver interface for drawing + * operations to a #cairo_surface_t. There are different subtypes of + * #cairo_device_t for different drawing backends; for example, + * cairo_egl_device_create() creates a device that wraps an EGL display and + * context. + * + * The type of a device can be queried with cairo_device_get_type(). + * + * Memory management of #cairo_device_t is done with + * cairo_device_reference() and cairo_device_destroy(). + * + * Since: 1.10 + **/ +typedef struct _cairo_device cairo_device_t; + +/** + * cairo_matrix_t: + * @xx: xx component of the affine transformation + * @yx: yx component of the affine transformation + * @xy: xy component of the affine transformation + * @yy: yy component of the affine transformation + * @x0: X translation component of the affine transformation + * @y0: Y translation component of the affine transformation + * + * A #cairo_matrix_t holds an affine transformation, such as a scale, + * rotation, shear, or a combination of those. The transformation of + * a point (x, y) is given by: + * + * x_new = xx * x + xy * y + x0; + * y_new = yx * x + yy * y + y0; + * + * + * Since: 1.0 + **/ +typedef struct _cairo_matrix { + double xx; double yx; + double xy; double yy; + double x0; double y0; +} cairo_matrix_t; + +/** + * cairo_pattern_t: + * + * A #cairo_pattern_t represents a source when drawing onto a + * surface. There are different subtypes of #cairo_pattern_t, + * for different types of sources; for example, + * cairo_pattern_create_rgb() creates a pattern for a solid + * opaque color. + * + * Other than various + * cairo_pattern_create_type() + * functions, some of the pattern types can be implicitly created using various + * cairo_set_source_type() functions; + * for example cairo_set_source_rgb(). + * + * The type of a pattern can be queried with cairo_pattern_get_type(). + * + * Memory management of #cairo_pattern_t is done with + * cairo_pattern_reference() and cairo_pattern_destroy(). + * + * Since: 1.0 + **/ +typedef struct _cairo_pattern cairo_pattern_t; + +/** + * cairo_destroy_func_t: + * @data: The data element being destroyed. + * + * #cairo_destroy_func_t the type of function which is called when a + * data element is destroyed. It is passed the pointer to the data + * element and should free any memory and resources allocated for it. + * + * Since: 1.0 + **/ +typedef void (*cairo_destroy_func_t) (void *data); + +/** + * cairo_user_data_key_t: + * @unused: not used; ignore. + * + * #cairo_user_data_key_t is used for attaching user data to cairo + * data structures. The actual contents of the struct is never used, + * and there is no need to initialize the object; only the unique + * address of a #cairo_data_key_t object is used. Typically, you + * would just use the address of a static #cairo_data_key_t object. + * + * Since: 1.0 + **/ +typedef struct _cairo_user_data_key { + int unused; +} cairo_user_data_key_t; + +/** + * cairo_status_t: + * @CAIRO_STATUS_SUCCESS: no error has occurred (Since 1.0) + * @CAIRO_STATUS_NO_MEMORY: out of memory (Since 1.0) + * @CAIRO_STATUS_INVALID_RESTORE: cairo_restore() called without matching cairo_save() (Since 1.0) + * @CAIRO_STATUS_INVALID_POP_GROUP: no saved group to pop, i.e. cairo_pop_group() without matching cairo_push_group() (Since 1.0) + * @CAIRO_STATUS_NO_CURRENT_POINT: no current point defined (Since 1.0) + * @CAIRO_STATUS_INVALID_MATRIX: invalid matrix (not invertible) (Since 1.0) + * @CAIRO_STATUS_INVALID_STATUS: invalid value for an input #cairo_status_t (Since 1.0) + * @CAIRO_STATUS_NULL_POINTER: %NULL pointer (Since 1.0) + * @CAIRO_STATUS_INVALID_STRING: input string not valid UTF-8 (Since 1.0) + * @CAIRO_STATUS_INVALID_PATH_DATA: input path data not valid (Since 1.0) + * @CAIRO_STATUS_READ_ERROR: error while reading from input stream (Since 1.0) + * @CAIRO_STATUS_WRITE_ERROR: error while writing to output stream (Since 1.0) + * @CAIRO_STATUS_SURFACE_FINISHED: target surface has been finished (Since 1.0) + * @CAIRO_STATUS_SURFACE_TYPE_MISMATCH: the surface type is not appropriate for the operation (Since 1.0) + * @CAIRO_STATUS_PATTERN_TYPE_MISMATCH: the pattern type is not appropriate for the operation (Since 1.0) + * @CAIRO_STATUS_INVALID_CONTENT: invalid value for an input #cairo_content_t (Since 1.0) + * @CAIRO_STATUS_INVALID_FORMAT: invalid value for an input #cairo_format_t (Since 1.0) + * @CAIRO_STATUS_INVALID_VISUAL: invalid value for an input Visual* (Since 1.0) + * @CAIRO_STATUS_FILE_NOT_FOUND: file not found (Since 1.0) + * @CAIRO_STATUS_INVALID_DASH: invalid value for a dash setting (Since 1.0) + * @CAIRO_STATUS_INVALID_DSC_COMMENT: invalid value for a DSC comment (Since 1.2) + * @CAIRO_STATUS_INVALID_INDEX: invalid index passed to getter (Since 1.4) + * @CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: clip region not representable in desired format (Since 1.4) + * @CAIRO_STATUS_TEMP_FILE_ERROR: error creating or writing to a temporary file (Since 1.6) + * @CAIRO_STATUS_INVALID_STRIDE: invalid value for stride (Since 1.6) + * @CAIRO_STATUS_FONT_TYPE_MISMATCH: the font type is not appropriate for the operation (Since 1.8) + * @CAIRO_STATUS_USER_FONT_IMMUTABLE: the user-font is immutable (Since 1.8) + * @CAIRO_STATUS_USER_FONT_ERROR: error occurred in a user-font callback function (Since 1.8) + * @CAIRO_STATUS_NEGATIVE_COUNT: negative number used where it is not allowed (Since 1.8) + * @CAIRO_STATUS_INVALID_CLUSTERS: input clusters do not represent the accompanying text and glyph array (Since 1.8) + * @CAIRO_STATUS_INVALID_SLANT: invalid value for an input #cairo_font_slant_t (Since 1.8) + * @CAIRO_STATUS_INVALID_WEIGHT: invalid value for an input #cairo_font_weight_t (Since 1.8) + * @CAIRO_STATUS_INVALID_SIZE: invalid value (typically too big) for the size of the input (surface, pattern, etc.) (Since 1.10) + * @CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: user-font method not implemented (Since 1.10) + * @CAIRO_STATUS_DEVICE_TYPE_MISMATCH: the device type is not appropriate for the operation (Since 1.10) + * @CAIRO_STATUS_DEVICE_ERROR: an operation to the device caused an unspecified error (Since 1.10) + * @CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: a mesh pattern + * construction operation was used outside of a + * cairo_mesh_pattern_begin_patch()/cairo_mesh_pattern_end_patch() + * pair (Since 1.12) + * @CAIRO_STATUS_DEVICE_FINISHED: target device has been finished (Since 1.12) + * @CAIRO_STATUS_JBIG2_GLOBAL_MISSING: %CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID has been used on at least one image + * but no image provided %CAIRO_MIME_TYPE_JBIG2_GLOBAL (Since 1.14) + * @CAIRO_STATUS_LAST_STATUS: this is a special value indicating the number of + * status values defined in this enumeration. When using this value, note + * that the version of cairo at run-time may have additional status values + * defined than the value of this symbol at compile-time. (Since 1.10) + * + * #cairo_status_t is used to indicate errors that can occur when + * using Cairo. In some cases it is returned directly by functions. + * but when using #cairo_t, the last error, if any, is stored in + * the context and can be retrieved with cairo_status(). + * + * New entries may be added in future versions. Use cairo_status_to_string() + * to get a human-readable representation of an error message. + * + * Since: 1.0 + **/ +typedef enum _cairo_status { + CAIRO_STATUS_SUCCESS = 0, + + CAIRO_STATUS_NO_MEMORY, + CAIRO_STATUS_INVALID_RESTORE, + CAIRO_STATUS_INVALID_POP_GROUP, + CAIRO_STATUS_NO_CURRENT_POINT, + CAIRO_STATUS_INVALID_MATRIX, + CAIRO_STATUS_INVALID_STATUS, + CAIRO_STATUS_NULL_POINTER, + CAIRO_STATUS_INVALID_STRING, + CAIRO_STATUS_INVALID_PATH_DATA, + CAIRO_STATUS_READ_ERROR, + CAIRO_STATUS_WRITE_ERROR, + CAIRO_STATUS_SURFACE_FINISHED, + CAIRO_STATUS_SURFACE_TYPE_MISMATCH, + CAIRO_STATUS_PATTERN_TYPE_MISMATCH, + CAIRO_STATUS_INVALID_CONTENT, + CAIRO_STATUS_INVALID_FORMAT, + CAIRO_STATUS_INVALID_VISUAL, + CAIRO_STATUS_FILE_NOT_FOUND, + CAIRO_STATUS_INVALID_DASH, + CAIRO_STATUS_INVALID_DSC_COMMENT, + CAIRO_STATUS_INVALID_INDEX, + CAIRO_STATUS_CLIP_NOT_REPRESENTABLE, + CAIRO_STATUS_TEMP_FILE_ERROR, + CAIRO_STATUS_INVALID_STRIDE, + CAIRO_STATUS_FONT_TYPE_MISMATCH, + CAIRO_STATUS_USER_FONT_IMMUTABLE, + CAIRO_STATUS_USER_FONT_ERROR, + CAIRO_STATUS_NEGATIVE_COUNT, + CAIRO_STATUS_INVALID_CLUSTERS, + CAIRO_STATUS_INVALID_SLANT, + CAIRO_STATUS_INVALID_WEIGHT, + CAIRO_STATUS_INVALID_SIZE, + CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, + CAIRO_STATUS_DEVICE_TYPE_MISMATCH, + CAIRO_STATUS_DEVICE_ERROR, + CAIRO_STATUS_INVALID_MESH_CONSTRUCTION, + CAIRO_STATUS_DEVICE_FINISHED, + CAIRO_STATUS_JBIG2_GLOBAL_MISSING, + + CAIRO_STATUS_LAST_STATUS +} cairo_status_t; + +/** + * cairo_content_t: + * @CAIRO_CONTENT_COLOR: The surface will hold color content only. (Since 1.0) + * @CAIRO_CONTENT_ALPHA: The surface will hold alpha content only. (Since 1.0) + * @CAIRO_CONTENT_COLOR_ALPHA: The surface will hold color and alpha content. (Since 1.0) + * + * #cairo_content_t is used to describe the content that a surface will + * contain, whether color information, alpha information (translucence + * vs. opacity), or both. + * + * Note: The large values here are designed to keep #cairo_content_t + * values distinct from #cairo_format_t values so that the + * implementation can detect the error if users confuse the two types. + * + * Since: 1.0 + **/ +typedef enum _cairo_content { + CAIRO_CONTENT_COLOR = 0x1000, + CAIRO_CONTENT_ALPHA = 0x2000, + CAIRO_CONTENT_COLOR_ALPHA = 0x3000 +} cairo_content_t; + +/** + * cairo_format_t: + * @CAIRO_FORMAT_INVALID: no such format exists or is supported. + * @CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with + * alpha in the upper 8 bits, then red, then green, then blue. + * The 32-bit quantities are stored native-endian. Pre-multiplied + * alpha is used. (That is, 50% transparent red is 0x80800000, + * not 0x80ff0000.) (Since 1.0) + * @CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with + * the upper 8 bits unused. Red, Green, and Blue are stored + * in the remaining 24 bits in that order. (Since 1.0) + * @CAIRO_FORMAT_A8: each pixel is a 8-bit quantity holding + * an alpha value. (Since 1.0) + * @CAIRO_FORMAT_A1: each pixel is a 1-bit quantity holding + * an alpha value. Pixels are packed together into 32-bit + * quantities. The ordering of the bits matches the + * endianess of the platform. On a big-endian machine, the + * first pixel is in the uppermost bit, on a little-endian + * machine the first pixel is in the least-significant bit. (Since 1.0) + * @CAIRO_FORMAT_RGB16_565: each pixel is a 16-bit quantity + * with red in the upper 5 bits, then green in the middle + * 6 bits, and blue in the lower 5 bits. (Since 1.2) + * @CAIRO_FORMAT_RGB30: like RGB24 but with 10bpc. (Since 1.12) + * + * #cairo_format_t is used to identify the memory format of + * image data. + * + * New entries may be added in future versions. + * + * Since: 1.0 + **/ +typedef enum _cairo_format { + CAIRO_FORMAT_INVALID = -1, + CAIRO_FORMAT_ARGB32 = 0, + CAIRO_FORMAT_RGB24 = 1, + CAIRO_FORMAT_A8 = 2, + CAIRO_FORMAT_A1 = 3, + CAIRO_FORMAT_RGB16_565 = 4, + CAIRO_FORMAT_RGB30 = 5 +} cairo_format_t; + + +/** + * cairo_write_func_t: + * @closure: the output closure + * @data: the buffer containing the data to write + * @length: the amount of data to write + * + * #cairo_write_func_t is the type of function which is called when a + * backend needs to write data to an output stream. It is passed the + * closure which was specified by the user at the time the write + * function was registered, the data to write and the length of the + * data in bytes. The write function should return + * %CAIRO_STATUS_SUCCESS if all the data was successfully written, + * %CAIRO_STATUS_WRITE_ERROR otherwise. + * + * Returns: the status code of the write operation + * + * Since: 1.0 + **/ +typedef cairo_status_t (*cairo_write_func_t) (void *closure, + const unsigned char *data, + unsigned int length); + +/** + * cairo_read_func_t: + * @closure: the input closure + * @data: the buffer into which to read the data + * @length: the amount of data to read + * + * #cairo_read_func_t is the type of function which is called when a + * backend needs to read data from an input stream. It is passed the + * closure which was specified by the user at the time the read + * function was registered, the buffer to read the data into and the + * length of the data in bytes. The read function should return + * %CAIRO_STATUS_SUCCESS if all the data was successfully read, + * %CAIRO_STATUS_READ_ERROR otherwise. + * + * Returns: the status code of the read operation + * + * Since: 1.0 + **/ +typedef cairo_status_t (*cairo_read_func_t) (void *closure, + unsigned char *data, + unsigned int length); + +/** + * cairo_rectangle_int_t: + * @x: X coordinate of the left side of the rectangle + * @y: Y coordinate of the the top side of the rectangle + * @width: width of the rectangle + * @height: height of the rectangle + * + * A data structure for holding a rectangle with integer coordinates. + * + * Since: 1.10 + **/ + +typedef struct _cairo_rectangle_int { + int x, y; + int width, height; +} cairo_rectangle_int_t; + + +/* Functions for manipulating state objects */ +cairo_public cairo_t * +cairo_create (cairo_surface_t *target); + +cairo_public cairo_t * +cairo_reference (cairo_t *cr); + +cairo_public void +cairo_destroy (cairo_t *cr); + +cairo_public unsigned int +cairo_get_reference_count (cairo_t *cr); + +cairo_public void * +cairo_get_user_data (cairo_t *cr, + const cairo_user_data_key_t *key); + +cairo_public cairo_status_t +cairo_set_user_data (cairo_t *cr, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + +cairo_public void +cairo_save (cairo_t *cr); + +cairo_public void +cairo_restore (cairo_t *cr); + +cairo_public void +cairo_push_group (cairo_t *cr); + +cairo_public void +cairo_push_group_with_content (cairo_t *cr, cairo_content_t content); + +cairo_public cairo_pattern_t * +cairo_pop_group (cairo_t *cr); + +cairo_public void +cairo_pop_group_to_source (cairo_t *cr); + +/* Modify state */ + +/** + * cairo_operator_t: + * @CAIRO_OPERATOR_CLEAR: clear destination layer (bounded) (Since 1.0) + * @CAIRO_OPERATOR_SOURCE: replace destination layer (bounded) (Since 1.0) + * @CAIRO_OPERATOR_OVER: draw source layer on top of destination layer + * (bounded) (Since 1.0) + * @CAIRO_OPERATOR_IN: draw source where there was destination content + * (unbounded) (Since 1.0) + * @CAIRO_OPERATOR_OUT: draw source where there was no destination + * content (unbounded) (Since 1.0) + * @CAIRO_OPERATOR_ATOP: draw source on top of destination content and + * only there (Since 1.0) + * @CAIRO_OPERATOR_DEST: ignore the source (Since 1.0) + * @CAIRO_OPERATOR_DEST_OVER: draw destination on top of source (Since 1.0) + * @CAIRO_OPERATOR_DEST_IN: leave destination only where there was + * source content (unbounded) (Since 1.0) + * @CAIRO_OPERATOR_DEST_OUT: leave destination only where there was no + * source content (Since 1.0) + * @CAIRO_OPERATOR_DEST_ATOP: leave destination on top of source content + * and only there (unbounded) (Since 1.0) + * @CAIRO_OPERATOR_XOR: source and destination are shown where there is only + * one of them (Since 1.0) + * @CAIRO_OPERATOR_ADD: source and destination layers are accumulated (Since 1.0) + * @CAIRO_OPERATOR_SATURATE: like over, but assuming source and dest are + * disjoint geometries (Since 1.0) + * @CAIRO_OPERATOR_MULTIPLY: source and destination layers are multiplied. + * This causes the result to be at least as dark as the darker inputs. (Since 1.10) + * @CAIRO_OPERATOR_SCREEN: source and destination are complemented and + * multiplied. This causes the result to be at least as light as the lighter + * inputs. (Since 1.10) + * @CAIRO_OPERATOR_OVERLAY: multiplies or screens, depending on the + * lightness of the destination color. (Since 1.10) + * @CAIRO_OPERATOR_DARKEN: replaces the destination with the source if it + * is darker, otherwise keeps the source. (Since 1.10) + * @CAIRO_OPERATOR_LIGHTEN: replaces the destination with the source if it + * is lighter, otherwise keeps the source. (Since 1.10) + * @CAIRO_OPERATOR_COLOR_DODGE: brightens the destination color to reflect + * the source color. (Since 1.10) + * @CAIRO_OPERATOR_COLOR_BURN: darkens the destination color to reflect + * the source color. (Since 1.10) + * @CAIRO_OPERATOR_HARD_LIGHT: Multiplies or screens, dependent on source + * color. (Since 1.10) + * @CAIRO_OPERATOR_SOFT_LIGHT: Darkens or lightens, dependent on source + * color. (Since 1.10) + * @CAIRO_OPERATOR_DIFFERENCE: Takes the difference of the source and + * destination color. (Since 1.10) + * @CAIRO_OPERATOR_EXCLUSION: Produces an effect similar to difference, but + * with lower contrast. (Since 1.10) + * @CAIRO_OPERATOR_HSL_HUE: Creates a color with the hue of the source + * and the saturation and luminosity of the target. (Since 1.10) + * @CAIRO_OPERATOR_HSL_SATURATION: Creates a color with the saturation + * of the source and the hue and luminosity of the target. Painting with + * this mode onto a gray area produces no change. (Since 1.10) + * @CAIRO_OPERATOR_HSL_COLOR: Creates a color with the hue and saturation + * of the source and the luminosity of the target. This preserves the gray + * levels of the target and is useful for coloring monochrome images or + * tinting color images. (Since 1.10) + * @CAIRO_OPERATOR_HSL_LUMINOSITY: Creates a color with the luminosity of + * the source and the hue and saturation of the target. This produces an + * inverse effect to @CAIRO_OPERATOR_HSL_COLOR. (Since 1.10) + * + * #cairo_operator_t is used to set the compositing operator for all cairo + * drawing operations. + * + * The default operator is %CAIRO_OPERATOR_OVER. + * + * The operators marked as unbounded modify their + * destination even outside of the mask layer (that is, their effect is not + * bound by the mask layer). However, their effect can still be limited by + * way of clipping. + * + * To keep things simple, the operator descriptions here + * document the behavior for when both source and destination are either fully + * transparent or fully opaque. The actual implementation works for + * translucent layers too. + * For a more detailed explanation of the effects of each operator, including + * the mathematical definitions, see + * http://cairographics.org/operators/. + * + * Since: 1.0 + **/ +typedef enum _cairo_operator { + CAIRO_OPERATOR_CLEAR, + + CAIRO_OPERATOR_SOURCE, + CAIRO_OPERATOR_OVER, + CAIRO_OPERATOR_IN, + CAIRO_OPERATOR_OUT, + CAIRO_OPERATOR_ATOP, + + CAIRO_OPERATOR_DEST, + CAIRO_OPERATOR_DEST_OVER, + CAIRO_OPERATOR_DEST_IN, + CAIRO_OPERATOR_DEST_OUT, + CAIRO_OPERATOR_DEST_ATOP, + + CAIRO_OPERATOR_XOR, + CAIRO_OPERATOR_ADD, + CAIRO_OPERATOR_SATURATE, + + CAIRO_OPERATOR_MULTIPLY, + CAIRO_OPERATOR_SCREEN, + CAIRO_OPERATOR_OVERLAY, + CAIRO_OPERATOR_DARKEN, + CAIRO_OPERATOR_LIGHTEN, + CAIRO_OPERATOR_COLOR_DODGE, + CAIRO_OPERATOR_COLOR_BURN, + CAIRO_OPERATOR_HARD_LIGHT, + CAIRO_OPERATOR_SOFT_LIGHT, + CAIRO_OPERATOR_DIFFERENCE, + CAIRO_OPERATOR_EXCLUSION, + CAIRO_OPERATOR_HSL_HUE, + CAIRO_OPERATOR_HSL_SATURATION, + CAIRO_OPERATOR_HSL_COLOR, + CAIRO_OPERATOR_HSL_LUMINOSITY +} cairo_operator_t; + +cairo_public void +cairo_set_operator (cairo_t *cr, cairo_operator_t op); + +cairo_public void +cairo_set_source (cairo_t *cr, cairo_pattern_t *source); + +cairo_public void +cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue); + +cairo_public void +cairo_set_source_rgba (cairo_t *cr, + double red, double green, double blue, + double alpha); + +cairo_public void +cairo_set_source_surface (cairo_t *cr, + cairo_surface_t *surface, + double x, + double y); + +cairo_public void +cairo_set_tolerance (cairo_t *cr, double tolerance); + +/** + * cairo_antialias_t: + * @CAIRO_ANTIALIAS_DEFAULT: Use the default antialiasing for + * the subsystem and target device, since 1.0 + * @CAIRO_ANTIALIAS_NONE: Use a bilevel alpha mask, since 1.0 + * @CAIRO_ANTIALIAS_GRAY: Perform single-color antialiasing (using + * shades of gray for black text on a white background, for example), since 1.0 + * @CAIRO_ANTIALIAS_SUBPIXEL: Perform antialiasing by taking + * advantage of the order of subpixel elements on devices + * such as LCD panels, since 1.0 + * @CAIRO_ANTIALIAS_FAST: Hint that the backend should perform some + * antialiasing but prefer speed over quality, since 1.12 + * @CAIRO_ANTIALIAS_GOOD: The backend should balance quality against + * performance, since 1.12 + * @CAIRO_ANTIALIAS_BEST: Hint that the backend should render at the highest + * quality, sacrificing speed if necessary, since 1.12 + * + * Specifies the type of antialiasing to do when rendering text or shapes. + * + * As it is not necessarily clear from the above what advantages a particular + * antialias method provides, since 1.12, there is also a set of hints: + * @CAIRO_ANTIALIAS_FAST: Allow the backend to degrade raster quality for speed + * @CAIRO_ANTIALIAS_GOOD: A balance between speed and quality + * @CAIRO_ANTIALIAS_BEST: A high-fidelity, but potentially slow, raster mode + * + * These make no guarantee on how the backend will perform its rasterisation + * (if it even rasterises!), nor that they have any differing effect other + * than to enable some form of antialiasing. In the case of glyph rendering, + * @CAIRO_ANTIALIAS_FAST and @CAIRO_ANTIALIAS_GOOD will be mapped to + * @CAIRO_ANTIALIAS_GRAY, with @CAIRO_ANTALIAS_BEST being equivalent to + * @CAIRO_ANTIALIAS_SUBPIXEL. + * + * The interpretation of @CAIRO_ANTIALIAS_DEFAULT is left entirely up to + * the backend, typically this will be similar to @CAIRO_ANTIALIAS_GOOD. + * + * Since: 1.0 + **/ +typedef enum _cairo_antialias { + CAIRO_ANTIALIAS_DEFAULT, + + /* method */ + CAIRO_ANTIALIAS_NONE, + CAIRO_ANTIALIAS_GRAY, + CAIRO_ANTIALIAS_SUBPIXEL, + + /* hints */ + CAIRO_ANTIALIAS_FAST, + CAIRO_ANTIALIAS_GOOD, + CAIRO_ANTIALIAS_BEST +} cairo_antialias_t; + +cairo_public void +cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias); + +/** + * cairo_fill_rule_t: + * @CAIRO_FILL_RULE_WINDING: If the path crosses the ray from + * left-to-right, counts +1. If the path crosses the ray + * from right to left, counts -1. (Left and right are determined + * from the perspective of looking along the ray from the starting + * point.) If the total count is non-zero, the point will be filled. (Since 1.0) + * @CAIRO_FILL_RULE_EVEN_ODD: Counts the total number of + * intersections, without regard to the orientation of the contour. If + * the total number of intersections is odd, the point will be + * filled. (Since 1.0) + * + * #cairo_fill_rule_t is used to select how paths are filled. For both + * fill rules, whether or not a point is included in the fill is + * determined by taking a ray from that point to infinity and looking + * at intersections with the path. The ray can be in any direction, + * as long as it doesn't pass through the end point of a segment + * or have a tricky intersection such as intersecting tangent to the path. + * (Note that filling is not actually implemented in this way. This + * is just a description of the rule that is applied.) + * + * The default fill rule is %CAIRO_FILL_RULE_WINDING. + * + * New entries may be added in future versions. + * + * Since: 1.0 + **/ +typedef enum _cairo_fill_rule { + CAIRO_FILL_RULE_WINDING, + CAIRO_FILL_RULE_EVEN_ODD +} cairo_fill_rule_t; + +cairo_public void +cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule); + +cairo_public void +cairo_set_line_width (cairo_t *cr, double width); + +/** + * cairo_line_cap_t: + * @CAIRO_LINE_CAP_BUTT: start(stop) the line exactly at the start(end) point (Since 1.0) + * @CAIRO_LINE_CAP_ROUND: use a round ending, the center of the circle is the end point (Since 1.0) + * @CAIRO_LINE_CAP_SQUARE: use squared ending, the center of the square is the end point (Since 1.0) + * + * Specifies how to render the endpoints of the path when stroking. + * + * The default line cap style is %CAIRO_LINE_CAP_BUTT. + * + * Since: 1.0 + **/ +typedef enum _cairo_line_cap { + CAIRO_LINE_CAP_BUTT, + CAIRO_LINE_CAP_ROUND, + CAIRO_LINE_CAP_SQUARE +} cairo_line_cap_t; + +cairo_public void +cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap); + +/** + * cairo_line_join_t: + * @CAIRO_LINE_JOIN_MITER: use a sharp (angled) corner, see + * cairo_set_miter_limit() (Since 1.0) + * @CAIRO_LINE_JOIN_ROUND: use a rounded join, the center of the circle is the + * joint point (Since 1.0) + * @CAIRO_LINE_JOIN_BEVEL: use a cut-off join, the join is cut off at half + * the line width from the joint point (Since 1.0) + * + * Specifies how to render the junction of two lines when stroking. + * + * The default line join style is %CAIRO_LINE_JOIN_MITER. + * + * Since: 1.0 + **/ +typedef enum _cairo_line_join { + CAIRO_LINE_JOIN_MITER, + CAIRO_LINE_JOIN_ROUND, + CAIRO_LINE_JOIN_BEVEL +} cairo_line_join_t; + +cairo_public void +cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join); + +cairo_public void +cairo_set_dash (cairo_t *cr, + const double *dashes, + int num_dashes, + double offset); + +cairo_public void +cairo_set_miter_limit (cairo_t *cr, double limit); + +cairo_public void +cairo_translate (cairo_t *cr, double tx, double ty); + +cairo_public void +cairo_scale (cairo_t *cr, double sx, double sy); + +cairo_public void +cairo_rotate (cairo_t *cr, double angle); + +cairo_public void +cairo_transform (cairo_t *cr, + const cairo_matrix_t *matrix); + +cairo_public void +cairo_set_matrix (cairo_t *cr, + const cairo_matrix_t *matrix); + +cairo_public void +cairo_identity_matrix (cairo_t *cr); + +cairo_public void +cairo_user_to_device (cairo_t *cr, double *x, double *y); + +cairo_public void +cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy); + +cairo_public void +cairo_device_to_user (cairo_t *cr, double *x, double *y); + +cairo_public void +cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy); + +/* Path creation functions */ +cairo_public void +cairo_new_path (cairo_t *cr); + +cairo_public void +cairo_move_to (cairo_t *cr, double x, double y); + +cairo_public void +cairo_new_sub_path (cairo_t *cr); + +cairo_public void +cairo_line_to (cairo_t *cr, double x, double y); + +cairo_public void +cairo_curve_to (cairo_t *cr, + double x1, double y1, + double x2, double y2, + double x3, double y3); + +cairo_public void +cairo_arc (cairo_t *cr, + double xc, double yc, + double radius, + double angle1, double angle2); + +cairo_public void +cairo_arc_negative (cairo_t *cr, + double xc, double yc, + double radius, + double angle1, double angle2); + +/* XXX: NYI +cairo_public void +cairo_arc_to (cairo_t *cr, + double x1, double y1, + double x2, double y2, + double radius); +*/ + +cairo_public void +cairo_rel_move_to (cairo_t *cr, double dx, double dy); + +cairo_public void +cairo_rel_line_to (cairo_t *cr, double dx, double dy); + +cairo_public void +cairo_rel_curve_to (cairo_t *cr, + double dx1, double dy1, + double dx2, double dy2, + double dx3, double dy3); + +cairo_public void +cairo_rectangle (cairo_t *cr, + double x, double y, + double width, double height); + +/* XXX: NYI +cairo_public void +cairo_stroke_to_path (cairo_t *cr); +*/ + +cairo_public void +cairo_close_path (cairo_t *cr); + +cairo_public void +cairo_path_extents (cairo_t *cr, + double *x1, double *y1, + double *x2, double *y2); + +/* Painting functions */ +cairo_public void +cairo_paint (cairo_t *cr); + +cairo_public void +cairo_paint_with_alpha (cairo_t *cr, + double alpha); + +cairo_public void +cairo_mask (cairo_t *cr, + cairo_pattern_t *pattern); + +cairo_public void +cairo_mask_surface (cairo_t *cr, + cairo_surface_t *surface, + double surface_x, + double surface_y); + +cairo_public void +cairo_stroke (cairo_t *cr); + +cairo_public void +cairo_stroke_preserve (cairo_t *cr); + +cairo_public void +cairo_fill (cairo_t *cr); + +cairo_public void +cairo_fill_preserve (cairo_t *cr); + +cairo_public void +cairo_copy_page (cairo_t *cr); + +cairo_public void +cairo_show_page (cairo_t *cr); + +/* Insideness testing */ +cairo_public cairo_bool_t +cairo_in_stroke (cairo_t *cr, double x, double y); + +cairo_public cairo_bool_t +cairo_in_fill (cairo_t *cr, double x, double y); + +cairo_public cairo_bool_t +cairo_in_clip (cairo_t *cr, double x, double y); + +/* Rectangular extents */ +cairo_public void +cairo_stroke_extents (cairo_t *cr, + double *x1, double *y1, + double *x2, double *y2); + +cairo_public void +cairo_fill_extents (cairo_t *cr, + double *x1, double *y1, + double *x2, double *y2); + +/* Clipping */ +cairo_public void +cairo_reset_clip (cairo_t *cr); + +cairo_public void +cairo_clip (cairo_t *cr); + +cairo_public void +cairo_clip_preserve (cairo_t *cr); + +cairo_public void +cairo_clip_extents (cairo_t *cr, + double *x1, double *y1, + double *x2, double *y2); + +/** + * cairo_rectangle_t: + * @x: X coordinate of the left side of the rectangle + * @y: Y coordinate of the the top side of the rectangle + * @width: width of the rectangle + * @height: height of the rectangle + * + * A data structure for holding a rectangle. + * + * Since: 1.4 + **/ +typedef struct _cairo_rectangle { + double x, y, width, height; +} cairo_rectangle_t; + +/** + * cairo_rectangle_list_t: + * @status: Error status of the rectangle list + * @rectangles: Array containing the rectangles + * @num_rectangles: Number of rectangles in this list + * + * A data structure for holding a dynamically allocated + * array of rectangles. + * + * Since: 1.4 + **/ +typedef struct _cairo_rectangle_list { + cairo_status_t status; + cairo_rectangle_t *rectangles; + int num_rectangles; +} cairo_rectangle_list_t; + +cairo_public cairo_rectangle_list_t * +cairo_copy_clip_rectangle_list (cairo_t *cr); + +cairo_public void +cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list); + +/* Font/Text functions */ + +/** + * cairo_scaled_font_t: + * + * A #cairo_scaled_font_t is a font scaled to a particular size and device + * resolution. A #cairo_scaled_font_t is most useful for low-level font + * usage where a library or application wants to cache a reference + * to a scaled font to speed up the computation of metrics. + * + * There are various types of scaled fonts, depending on the + * font backend they use. The type of a + * scaled font can be queried using cairo_scaled_font_get_type(). + * + * Memory management of #cairo_scaled_font_t is done with + * cairo_scaled_font_reference() and cairo_scaled_font_destroy(). + * + * Since: 1.0 + **/ +typedef struct _cairo_scaled_font cairo_scaled_font_t; + +/** + * cairo_font_face_t: + * + * A #cairo_font_face_t specifies all aspects of a font other + * than the size or font matrix (a font matrix is used to distort + * a font by sheering it or scaling it unequally in the two + * directions) . A font face can be set on a #cairo_t by using + * cairo_set_font_face(); the size and font matrix are set with + * cairo_set_font_size() and cairo_set_font_matrix(). + * + * There are various types of font faces, depending on the + * font backend they use. The type of a + * font face can be queried using cairo_font_face_get_type(). + * + * Memory management of #cairo_font_face_t is done with + * cairo_font_face_reference() and cairo_font_face_destroy(). + * + * Since: 1.0 + **/ +typedef struct _cairo_font_face cairo_font_face_t; + +/** + * cairo_glyph_t: + * @index: glyph index in the font. The exact interpretation of the + * glyph index depends on the font technology being used. + * @x: the offset in the X direction between the origin used for + * drawing or measuring the string and the origin of this glyph. + * @y: the offset in the Y direction between the origin used for + * drawing or measuring the string and the origin of this glyph. + * + * The #cairo_glyph_t structure holds information about a single glyph + * when drawing or measuring text. A font is (in simple terms) a + * collection of shapes used to draw text. A glyph is one of these + * shapes. There can be multiple glyphs for a single character + * (alternates to be used in different contexts, for example), or a + * glyph can be a ligature of multiple + * characters. Cairo doesn't expose any way of converting input text + * into glyphs, so in order to use the Cairo interfaces that take + * arrays of glyphs, you must directly access the appropriate + * underlying font system. + * + * Note that the offsets given by @x and @y are not cumulative. When + * drawing or measuring text, each glyph is individually positioned + * with respect to the overall origin + * + * Since: 1.0 + **/ +typedef struct { + unsigned long index; + double x; + double y; +} cairo_glyph_t; + +cairo_public cairo_glyph_t * +cairo_glyph_allocate (int num_glyphs); + +cairo_public void +cairo_glyph_free (cairo_glyph_t *glyphs); + +/** + * cairo_text_cluster_t: + * @num_bytes: the number of bytes of UTF-8 text covered by cluster + * @num_glyphs: the number of glyphs covered by cluster + * + * The #cairo_text_cluster_t structure holds information about a single + * text cluster. A text cluster is a minimal + * mapping of some glyphs corresponding to some UTF-8 text. + * + * For a cluster to be valid, both @num_bytes and @num_glyphs should + * be non-negative, and at least one should be non-zero. + * Note that clusters with zero glyphs are not as well supported as + * normal clusters. For example, PDF rendering applications typically + * ignore those clusters when PDF text is being selected. + * + * See cairo_show_text_glyphs() for how clusters are used in advanced + * text operations. + * + * Since: 1.8 + **/ +typedef struct { + int num_bytes; + int num_glyphs; +} cairo_text_cluster_t; + +cairo_public cairo_text_cluster_t * +cairo_text_cluster_allocate (int num_clusters); + +cairo_public void +cairo_text_cluster_free (cairo_text_cluster_t *clusters); + +/** + * cairo_text_cluster_flags_t: + * @CAIRO_TEXT_CLUSTER_FLAG_BACKWARD: The clusters in the cluster array + * map to glyphs in the glyph array from end to start. (Since 1.8) + * + * Specifies properties of a text cluster mapping. + * + * Since: 1.8 + **/ +typedef enum _cairo_text_cluster_flags { + CAIRO_TEXT_CLUSTER_FLAG_BACKWARD = 0x00000001 +} cairo_text_cluster_flags_t; + +/** + * cairo_text_extents_t: + * @x_bearing: the horizontal distance from the origin to the + * leftmost part of the glyphs as drawn. Positive if the + * glyphs lie entirely to the right of the origin. + * @y_bearing: the vertical distance from the origin to the + * topmost part of the glyphs as drawn. Positive only if the + * glyphs lie completely below the origin; will usually be + * negative. + * @width: width of the glyphs as drawn + * @height: height of the glyphs as drawn + * @x_advance:distance to advance in the X direction + * after drawing these glyphs + * @y_advance: distance to advance in the Y direction + * after drawing these glyphs. Will typically be zero except + * for vertical text layout as found in East-Asian languages. + * + * The #cairo_text_extents_t structure stores the extents of a single + * glyph or a string of glyphs in user-space coordinates. Because text + * extents are in user-space coordinates, they are mostly, but not + * entirely, independent of the current transformation matrix. If you call + * cairo_scale(cr, 2.0, 2.0), text will + * be drawn twice as big, but the reported text extents will not be + * doubled. They will change slightly due to hinting (so you can't + * assume that metrics are independent of the transformation matrix), + * but otherwise will remain unchanged. + * + * Since: 1.0 + **/ +typedef struct { + double x_bearing; + double y_bearing; + double width; + double height; + double x_advance; + double y_advance; +} cairo_text_extents_t; + +/** + * cairo_font_extents_t: + * @ascent: the distance that the font extends above the baseline. + * Note that this is not always exactly equal to the maximum + * of the extents of all the glyphs in the font, but rather + * is picked to express the font designer's intent as to + * how the font should align with elements above it. + * @descent: the distance that the font extends below the baseline. + * This value is positive for typical fonts that include + * portions below the baseline. Note that this is not always + * exactly equal to the maximum of the extents of all the + * glyphs in the font, but rather is picked to express the + * font designer's intent as to how the font should + * align with elements below it. + * @height: the recommended vertical distance between baselines when + * setting consecutive lines of text with the font. This + * is greater than @ascent+@descent by a + * quantity known as the line spacing + * or external leading. When space + * is at a premium, most fonts can be set with only + * a distance of @ascent+@descent between lines. + * @max_x_advance: the maximum distance in the X direction that + * the origin is advanced for any glyph in the font. + * @max_y_advance: the maximum distance in the Y direction that + * the origin is advanced for any glyph in the font. + * This will be zero for normal fonts used for horizontal + * writing. (The scripts of East Asia are sometimes written + * vertically.) + * + * The #cairo_font_extents_t structure stores metric information for + * a font. Values are given in the current user-space coordinate + * system. + * + * Because font metrics are in user-space coordinates, they are + * mostly, but not entirely, independent of the current transformation + * matrix. If you call cairo_scale(cr, 2.0, 2.0), + * text will be drawn twice as big, but the reported text extents will + * not be doubled. They will change slightly due to hinting (so you + * can't assume that metrics are independent of the transformation + * matrix), but otherwise will remain unchanged. + * + * Since: 1.0 + **/ +typedef struct { + double ascent; + double descent; + double height; + double max_x_advance; + double max_y_advance; +} cairo_font_extents_t; + +/** + * cairo_font_slant_t: + * @CAIRO_FONT_SLANT_NORMAL: Upright font style, since 1.0 + * @CAIRO_FONT_SLANT_ITALIC: Italic font style, since 1.0 + * @CAIRO_FONT_SLANT_OBLIQUE: Oblique font style, since 1.0 + * + * Specifies variants of a font face based on their slant. + * + * Since: 1.0 + **/ +typedef enum _cairo_font_slant { + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_SLANT_ITALIC, + CAIRO_FONT_SLANT_OBLIQUE +} cairo_font_slant_t; + +/** + * cairo_font_weight_t: + * @CAIRO_FONT_WEIGHT_NORMAL: Normal font weight, since 1.0 + * @CAIRO_FONT_WEIGHT_BOLD: Bold font weight, since 1.0 + * + * Specifies variants of a font face based on their weight. + * + * Since: 1.0 + **/ +typedef enum _cairo_font_weight { + CAIRO_FONT_WEIGHT_NORMAL, + CAIRO_FONT_WEIGHT_BOLD +} cairo_font_weight_t; + +/** + * cairo_subpixel_order_t: + * @CAIRO_SUBPIXEL_ORDER_DEFAULT: Use the default subpixel order for + * for the target device, since 1.0 + * @CAIRO_SUBPIXEL_ORDER_RGB: Subpixel elements are arranged horizontally + * with red at the left, since 1.0 + * @CAIRO_SUBPIXEL_ORDER_BGR: Subpixel elements are arranged horizontally + * with blue at the left, since 1.0 + * @CAIRO_SUBPIXEL_ORDER_VRGB: Subpixel elements are arranged vertically + * with red at the top, since 1.0 + * @CAIRO_SUBPIXEL_ORDER_VBGR: Subpixel elements are arranged vertically + * with blue at the top, since 1.0 + * + * The subpixel order specifies the order of color elements within + * each pixel on the display device when rendering with an + * antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL. + * + * Since: 1.0 + **/ +typedef enum _cairo_subpixel_order { + CAIRO_SUBPIXEL_ORDER_DEFAULT, + CAIRO_SUBPIXEL_ORDER_RGB, + CAIRO_SUBPIXEL_ORDER_BGR, + CAIRO_SUBPIXEL_ORDER_VRGB, + CAIRO_SUBPIXEL_ORDER_VBGR +} cairo_subpixel_order_t; + +/** + * cairo_hint_style_t: + * @CAIRO_HINT_STYLE_DEFAULT: Use the default hint style for + * font backend and target device, since 1.0 + * @CAIRO_HINT_STYLE_NONE: Do not hint outlines, since 1.0 + * @CAIRO_HINT_STYLE_SLIGHT: Hint outlines slightly to improve + * contrast while retaining good fidelity to the original + * shapes, since 1.0 + * @CAIRO_HINT_STYLE_MEDIUM: Hint outlines with medium strength + * giving a compromise between fidelity to the original shapes + * and contrast, since 1.0 + * @CAIRO_HINT_STYLE_FULL: Hint outlines to maximize contrast, since 1.0 + * + * Specifies the type of hinting to do on font outlines. Hinting + * is the process of fitting outlines to the pixel grid in order + * to improve the appearance of the result. Since hinting outlines + * involves distorting them, it also reduces the faithfulness + * to the original outline shapes. Not all of the outline hinting + * styles are supported by all font backends. + * + * New entries may be added in future versions. + * + * Since: 1.0 + **/ +typedef enum _cairo_hint_style { + CAIRO_HINT_STYLE_DEFAULT, + CAIRO_HINT_STYLE_NONE, + CAIRO_HINT_STYLE_SLIGHT, + CAIRO_HINT_STYLE_MEDIUM, + CAIRO_HINT_STYLE_FULL +} cairo_hint_style_t; + +/** + * cairo_hint_metrics_t: + * @CAIRO_HINT_METRICS_DEFAULT: Hint metrics in the default + * manner for the font backend and target device, since 1.0 + * @CAIRO_HINT_METRICS_OFF: Do not hint font metrics, since 1.0 + * @CAIRO_HINT_METRICS_ON: Hint font metrics, since 1.0 + * + * Specifies whether to hint font metrics; hinting font metrics + * means quantizing them so that they are integer values in + * device space. Doing this improves the consistency of + * letter and line spacing, however it also means that text + * will be laid out differently at different zoom factors. + * + * Since: 1.0 + **/ +typedef enum _cairo_hint_metrics { + CAIRO_HINT_METRICS_DEFAULT, + CAIRO_HINT_METRICS_OFF, + CAIRO_HINT_METRICS_ON +} cairo_hint_metrics_t; + +/** + * cairo_font_options_t: + * + * An opaque structure holding all options that are used when + * rendering fonts. + * + * Individual features of a #cairo_font_options_t can be set or + * accessed using functions named + * cairo_font_options_set_feature_name() and + * cairo_font_options_get_feature_name(), like + * cairo_font_options_set_antialias() and + * cairo_font_options_get_antialias(). + * + * New features may be added to a #cairo_font_options_t in the + * future. For this reason, cairo_font_options_copy(), + * cairo_font_options_equal(), cairo_font_options_merge(), and + * cairo_font_options_hash() should be used to copy, check + * for equality, merge, or compute a hash value of + * #cairo_font_options_t objects. + * + * Since: 1.0 + **/ +typedef struct _cairo_font_options cairo_font_options_t; + +cairo_public cairo_font_options_t * +cairo_font_options_create (void); + +cairo_public cairo_font_options_t * +cairo_font_options_copy (const cairo_font_options_t *original); + +cairo_public void +cairo_font_options_destroy (cairo_font_options_t *options); + +cairo_public cairo_status_t +cairo_font_options_status (cairo_font_options_t *options); + +cairo_public void +cairo_font_options_merge (cairo_font_options_t *options, + const cairo_font_options_t *other); +cairo_public cairo_bool_t +cairo_font_options_equal (const cairo_font_options_t *options, + const cairo_font_options_t *other); + +cairo_public unsigned long +cairo_font_options_hash (const cairo_font_options_t *options); + +cairo_public void +cairo_font_options_set_antialias (cairo_font_options_t *options, + cairo_antialias_t antialias); +cairo_public cairo_antialias_t +cairo_font_options_get_antialias (const cairo_font_options_t *options); + +cairo_public void +cairo_font_options_set_subpixel_order (cairo_font_options_t *options, + cairo_subpixel_order_t subpixel_order); +cairo_public cairo_subpixel_order_t +cairo_font_options_get_subpixel_order (const cairo_font_options_t *options); + +cairo_public void +cairo_font_options_set_hint_style (cairo_font_options_t *options, + cairo_hint_style_t hint_style); +cairo_public cairo_hint_style_t +cairo_font_options_get_hint_style (const cairo_font_options_t *options); + +cairo_public void +cairo_font_options_set_hint_metrics (cairo_font_options_t *options, + cairo_hint_metrics_t hint_metrics); +cairo_public cairo_hint_metrics_t +cairo_font_options_get_hint_metrics (const cairo_font_options_t *options); + +/* This interface is for dealing with text as text, not caring about the + font object inside the the cairo_t. */ + +cairo_public void +cairo_select_font_face (cairo_t *cr, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight); + +cairo_public void +cairo_set_font_size (cairo_t *cr, double size); + +cairo_public void +cairo_set_font_matrix (cairo_t *cr, + const cairo_matrix_t *matrix); + +cairo_public void +cairo_get_font_matrix (cairo_t *cr, + cairo_matrix_t *matrix); + +cairo_public void +cairo_set_font_options (cairo_t *cr, + const cairo_font_options_t *options); + +cairo_public void +cairo_get_font_options (cairo_t *cr, + cairo_font_options_t *options); + +cairo_public void +cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face); + +cairo_public cairo_font_face_t * +cairo_get_font_face (cairo_t *cr); + +cairo_public void +cairo_set_scaled_font (cairo_t *cr, + const cairo_scaled_font_t *scaled_font); + +cairo_public cairo_scaled_font_t * +cairo_get_scaled_font (cairo_t *cr); + +cairo_public void +cairo_show_text (cairo_t *cr, const char *utf8); + +cairo_public void +cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs); + +cairo_public void +cairo_show_text_glyphs (cairo_t *cr, + const char *utf8, + int utf8_len, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags); + +cairo_public void +cairo_text_path (cairo_t *cr, const char *utf8); + +cairo_public void +cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs); + +cairo_public void +cairo_text_extents (cairo_t *cr, + const char *utf8, + cairo_text_extents_t *extents); + +cairo_public void +cairo_glyph_extents (cairo_t *cr, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents); + +cairo_public void +cairo_font_extents (cairo_t *cr, + cairo_font_extents_t *extents); + +/* Generic identifier for a font style */ + +cairo_public cairo_font_face_t * +cairo_font_face_reference (cairo_font_face_t *font_face); + +cairo_public void +cairo_font_face_destroy (cairo_font_face_t *font_face); + +cairo_public unsigned int +cairo_font_face_get_reference_count (cairo_font_face_t *font_face); + +cairo_public cairo_status_t +cairo_font_face_status (cairo_font_face_t *font_face); + + +/** + * cairo_font_type_t: + * @CAIRO_FONT_TYPE_TOY: The font was created using cairo's toy font api (Since: 1.2) + * @CAIRO_FONT_TYPE_FT: The font is of type FreeType (Since: 1.2) + * @CAIRO_FONT_TYPE_WIN32: The font is of type Win32 (Since: 1.2) + * @CAIRO_FONT_TYPE_QUARTZ: The font is of type Quartz (Since: 1.6, in 1.2 and + * 1.4 it was named CAIRO_FONT_TYPE_ATSUI) + * @CAIRO_FONT_TYPE_USER: The font was create using cairo's user font api (Since: 1.8) + * + * #cairo_font_type_t is used to describe the type of a given font + * face or scaled font. The font types are also known as "font + * backends" within cairo. + * + * The type of a font face is determined by the function used to + * create it, which will generally be of the form + * cairo_type_font_face_create(). + * The font face type can be queried with cairo_font_face_get_type() + * + * The various #cairo_font_face_t functions can be used with a font face + * of any type. + * + * The type of a scaled font is determined by the type of the font + * face passed to cairo_scaled_font_create(). The scaled font type can + * be queried with cairo_scaled_font_get_type() + * + * The various #cairo_scaled_font_t functions can be used with scaled + * fonts of any type, but some font backends also provide + * type-specific functions that must only be called with a scaled font + * of the appropriate type. These functions have names that begin with + * cairo_type_scaled_font() + * such as cairo_ft_scaled_font_lock_face(). + * + * The behavior of calling a type-specific function with a scaled font + * of the wrong type is undefined. + * + * New entries may be added in future versions. + * + * Since: 1.2 + **/ +typedef enum _cairo_font_type { + CAIRO_FONT_TYPE_TOY, + CAIRO_FONT_TYPE_FT, + CAIRO_FONT_TYPE_WIN32, + CAIRO_FONT_TYPE_QUARTZ, + CAIRO_FONT_TYPE_USER +} cairo_font_type_t; + +cairo_public cairo_font_type_t +cairo_font_face_get_type (cairo_font_face_t *font_face); + +cairo_public void * +cairo_font_face_get_user_data (cairo_font_face_t *font_face, + const cairo_user_data_key_t *key); + +cairo_public cairo_status_t +cairo_font_face_set_user_data (cairo_font_face_t *font_face, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + +/* Portable interface to general font features. */ + +cairo_public cairo_scaled_font_t * +cairo_scaled_font_create (cairo_font_face_t *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options); + +cairo_public cairo_scaled_font_t * +cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font); + +cairo_public void +cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font); + +cairo_public unsigned int +cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font); + +cairo_public cairo_status_t +cairo_scaled_font_status (cairo_scaled_font_t *scaled_font); + +cairo_public cairo_font_type_t +cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font); + +cairo_public void * +cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font, + const cairo_user_data_key_t *key); + +cairo_public cairo_status_t +cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + +cairo_public void +cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, + cairo_font_extents_t *extents); + +cairo_public void +cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, + const char *utf8, + cairo_text_extents_t *extents); + +cairo_public void +cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_text_extents_t *extents); + +cairo_public cairo_status_t +cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font, + double x, + double y, + const char *utf8, + int utf8_len, + cairo_glyph_t **glyphs, + int *num_glyphs, + cairo_text_cluster_t **clusters, + int *num_clusters, + cairo_text_cluster_flags_t *cluster_flags); + +cairo_public cairo_font_face_t * +cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font); + +cairo_public void +cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *font_matrix); + +cairo_public void +cairo_scaled_font_get_ctm (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *ctm); + +cairo_public void +cairo_scaled_font_get_scale_matrix (cairo_scaled_font_t *scaled_font, + cairo_matrix_t *scale_matrix); + +cairo_public void +cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font, + cairo_font_options_t *options); + + +/* Toy fonts */ + +cairo_public cairo_font_face_t * +cairo_toy_font_face_create (const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight); + +cairo_public const char * +cairo_toy_font_face_get_family (cairo_font_face_t *font_face); + +cairo_public cairo_font_slant_t +cairo_toy_font_face_get_slant (cairo_font_face_t *font_face); + +cairo_public cairo_font_weight_t +cairo_toy_font_face_get_weight (cairo_font_face_t *font_face); + + +/* User fonts */ + +cairo_public cairo_font_face_t * +cairo_user_font_face_create (void); + +/* User-font method signatures */ + +/** + * cairo_user_scaled_font_init_func_t: + * @scaled_font: the scaled-font being created + * @cr: a cairo context, in font space + * @extents: font extents to fill in, in font space + * + * #cairo_user_scaled_font_init_func_t is the type of function which is + * called when a scaled-font needs to be created for a user font-face. + * + * The cairo context @cr is not used by the caller, but is prepared in font + * space, similar to what the cairo contexts passed to the render_glyph + * method will look like. The callback can use this context for extents + * computation for example. After the callback is called, @cr is checked + * for any error status. + * + * The @extents argument is where the user font sets the font extents for + * @scaled_font. It is in font space, which means that for most cases its + * ascent and descent members should add to 1.0. @extents is preset to + * hold a value of 1.0 for ascent, height, and max_x_advance, and 0.0 for + * descent and max_y_advance members. + * + * The callback is optional. If not set, default font extents as described + * in the previous paragraph will be used. + * + * Note that @scaled_font is not fully initialized at this + * point and trying to use it for text operations in the callback will result + * in deadlock. + * + * Returns: %CAIRO_STATUS_SUCCESS upon success, or an error status on error. + * + * Since: 1.8 + **/ +typedef cairo_status_t (*cairo_user_scaled_font_init_func_t) (cairo_scaled_font_t *scaled_font, + cairo_t *cr, + cairo_font_extents_t *extents); + +/** + * cairo_user_scaled_font_render_glyph_func_t: + * @scaled_font: user scaled-font + * @glyph: glyph code to render + * @cr: cairo context to draw to, in font space + * @extents: glyph extents to fill in, in font space + * + * #cairo_user_scaled_font_render_glyph_func_t is the type of function which + * is called when a user scaled-font needs to render a glyph. + * + * The callback is mandatory, and expected to draw the glyph with code @glyph to + * the cairo context @cr. @cr is prepared such that the glyph drawing is done in + * font space. That is, the matrix set on @cr is the scale matrix of @scaled_font, + * The @extents argument is where the user font sets the font extents for + * @scaled_font. However, if user prefers to draw in user space, they can + * achieve that by changing the matrix on @cr. All cairo rendering operations + * to @cr are permitted, however, the result is undefined if any source other + * than the default source on @cr is used. That means, glyph bitmaps should + * be rendered using cairo_mask() instead of cairo_paint(). + * + * Other non-default settings on @cr include a font size of 1.0 (given that + * it is set up to be in font space), and font options corresponding to + * @scaled_font. + * + * The @extents argument is preset to have x_bearing, + * width, and y_advance of zero, + * y_bearing set to -font_extents.ascent, + * height to font_extents.ascent+font_extents.descent, + * and x_advance to font_extents.max_x_advance. + * The only field user needs to set in majority of cases is + * x_advance. + * If the width field is zero upon the callback returning + * (which is its preset value), the glyph extents are automatically computed + * based on the drawings done to @cr. This is in most cases exactly what the + * desired behavior is. However, if for any reason the callback sets the + * extents, it must be ink extents, and include the extents of all drawing + * done to @cr in the callback. + * + * Returns: %CAIRO_STATUS_SUCCESS upon success, or + * %CAIRO_STATUS_USER_FONT_ERROR or any other error status on error. + * + * Since: 1.8 + **/ +typedef cairo_status_t (*cairo_user_scaled_font_render_glyph_func_t) (cairo_scaled_font_t *scaled_font, + unsigned long glyph, + cairo_t *cr, + cairo_text_extents_t *extents); + +/** + * cairo_user_scaled_font_text_to_glyphs_func_t: + * @scaled_font: the scaled-font being created + * @utf8: a string of text encoded in UTF-8 + * @utf8_len: length of @utf8 in bytes + * @glyphs: pointer to array of glyphs to fill, in font space + * @num_glyphs: pointer to number of glyphs + * @clusters: pointer to array of cluster mapping information to fill, or %NULL + * @num_clusters: pointer to number of clusters + * @cluster_flags: pointer to location to store cluster flags corresponding to the + * output @clusters + * + * #cairo_user_scaled_font_text_to_glyphs_func_t is the type of function which + * is called to convert input text to an array of glyphs. This is used by the + * cairo_show_text() operation. + * + * Using this callback the user-font has full control on glyphs and their + * positions. That means, it allows for features like ligatures and kerning, + * as well as complex shaping required for scripts like + * Arabic and Indic. + * + * The @num_glyphs argument is preset to the number of glyph entries available + * in the @glyphs buffer. If the @glyphs buffer is %NULL, the value of + * @num_glyphs will be zero. If the provided glyph array is too short for + * the conversion (or for convenience), a new glyph array may be allocated + * using cairo_glyph_allocate() and placed in @glyphs. Upon return, + * @num_glyphs should contain the number of generated glyphs. If the value + * @glyphs points at has changed after the call, the caller will free the + * allocated glyph array using cairo_glyph_free(). The caller will also free + * the original value of @glyphs, so the callback shouldn't do so. + * The callback should populate the glyph indices and positions (in font space) + * assuming that the text is to be shown at the origin. + * + * If @clusters is not %NULL, @num_clusters and @cluster_flags are also + * non-%NULL, and cluster mapping should be computed. The semantics of how + * cluster array allocation works is similar to the glyph array. That is, + * if @clusters initially points to a non-%NULL value, that array may be used + * as a cluster buffer, and @num_clusters points to the number of cluster + * entries available there. If the provided cluster array is too short for + * the conversion (or for convenience), a new cluster array may be allocated + * using cairo_text_cluster_allocate() and placed in @clusters. In this case, + * the original value of @clusters will still be freed by the caller. Upon + * return, @num_clusters should contain the number of generated clusters. + * If the value @clusters points at has changed after the call, the caller + * will free the allocated cluster array using cairo_text_cluster_free(). + * + * The callback is optional. If @num_glyphs is negative upon + * the callback returning or if the return value + * is %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, the unicode_to_glyph callback + * is tried. See #cairo_user_scaled_font_unicode_to_glyph_func_t. + * + * Note: While cairo does not impose any limitation on glyph indices, + * some applications may assume that a glyph index fits in a 16-bit + * unsigned integer. As such, it is advised that user-fonts keep their + * glyphs in the 0 to 65535 range. Furthermore, some applications may + * assume that glyph 0 is a special glyph-not-found glyph. User-fonts + * are advised to use glyph 0 for such purposes and do not use that + * glyph value for other purposes. + * + * Returns: %CAIRO_STATUS_SUCCESS upon success, + * %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED if fallback options should be tried, + * or %CAIRO_STATUS_USER_FONT_ERROR or any other error status on error. + * + * Since: 1.8 + **/ +typedef cairo_status_t (*cairo_user_scaled_font_text_to_glyphs_func_t) (cairo_scaled_font_t *scaled_font, + const char *utf8, + int utf8_len, + cairo_glyph_t **glyphs, + int *num_glyphs, + cairo_text_cluster_t **clusters, + int *num_clusters, + cairo_text_cluster_flags_t *cluster_flags); + +/** + * cairo_user_scaled_font_unicode_to_glyph_func_t: + * @scaled_font: the scaled-font being created + * @unicode: input unicode character code-point + * @glyph_index: output glyph index + * + * #cairo_user_scaled_font_unicode_to_glyph_func_t is the type of function which + * is called to convert an input Unicode character to a single glyph. + * This is used by the cairo_show_text() operation. + * + * This callback is used to provide the same functionality as the + * text_to_glyphs callback does (see #cairo_user_scaled_font_text_to_glyphs_func_t) + * but has much less control on the output, + * in exchange for increased ease of use. The inherent assumption to using + * this callback is that each character maps to one glyph, and that the + * mapping is context independent. It also assumes that glyphs are positioned + * according to their advance width. These mean no ligatures, kerning, or + * complex scripts can be implemented using this callback. + * + * The callback is optional, and only used if text_to_glyphs callback is not + * set or fails to return glyphs. If this callback is not set or if it returns + * %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, an identity mapping from Unicode + * code-points to glyph indices is assumed. + * + * Note: While cairo does not impose any limitation on glyph indices, + * some applications may assume that a glyph index fits in a 16-bit + * unsigned integer. As such, it is advised that user-fonts keep their + * glyphs in the 0 to 65535 range. Furthermore, some applications may + * assume that glyph 0 is a special glyph-not-found glyph. User-fonts + * are advised to use glyph 0 for such purposes and do not use that + * glyph value for other purposes. + * + * Returns: %CAIRO_STATUS_SUCCESS upon success, + * %CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED if fallback options should be tried, + * or %CAIRO_STATUS_USER_FONT_ERROR or any other error status on error. + * + * Since: 1.8 + **/ +typedef cairo_status_t (*cairo_user_scaled_font_unicode_to_glyph_func_t) (cairo_scaled_font_t *scaled_font, + unsigned long unicode, + unsigned long *glyph_index); + +/* User-font method setters */ + +cairo_public void +cairo_user_font_face_set_init_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_init_func_t init_func); + +cairo_public void +cairo_user_font_face_set_render_glyph_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_render_glyph_func_t render_glyph_func); + +cairo_public void +cairo_user_font_face_set_text_to_glyphs_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_text_to_glyphs_func_t text_to_glyphs_func); + +cairo_public void +cairo_user_font_face_set_unicode_to_glyph_func (cairo_font_face_t *font_face, + cairo_user_scaled_font_unicode_to_glyph_func_t unicode_to_glyph_func); + +/* User-font method getters */ + +cairo_public cairo_user_scaled_font_init_func_t +cairo_user_font_face_get_init_func (cairo_font_face_t *font_face); + +cairo_public cairo_user_scaled_font_render_glyph_func_t +cairo_user_font_face_get_render_glyph_func (cairo_font_face_t *font_face); + +cairo_public cairo_user_scaled_font_text_to_glyphs_func_t +cairo_user_font_face_get_text_to_glyphs_func (cairo_font_face_t *font_face); + +cairo_public cairo_user_scaled_font_unicode_to_glyph_func_t +cairo_user_font_face_get_unicode_to_glyph_func (cairo_font_face_t *font_face); + + +/* Query functions */ + +cairo_public cairo_operator_t +cairo_get_operator (cairo_t *cr); + +cairo_public cairo_pattern_t * +cairo_get_source (cairo_t *cr); + +cairo_public double +cairo_get_tolerance (cairo_t *cr); + +cairo_public cairo_antialias_t +cairo_get_antialias (cairo_t *cr); + +cairo_public cairo_bool_t +cairo_has_current_point (cairo_t *cr); + +cairo_public void +cairo_get_current_point (cairo_t *cr, double *x, double *y); + +cairo_public cairo_fill_rule_t +cairo_get_fill_rule (cairo_t *cr); + +cairo_public double +cairo_get_line_width (cairo_t *cr); + +cairo_public cairo_line_cap_t +cairo_get_line_cap (cairo_t *cr); + +cairo_public cairo_line_join_t +cairo_get_line_join (cairo_t *cr); + +cairo_public double +cairo_get_miter_limit (cairo_t *cr); + +cairo_public int +cairo_get_dash_count (cairo_t *cr); + +cairo_public void +cairo_get_dash (cairo_t *cr, double *dashes, double *offset); + +cairo_public void +cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix); + +cairo_public cairo_surface_t * +cairo_get_target (cairo_t *cr); + +cairo_public cairo_surface_t * +cairo_get_group_target (cairo_t *cr); + +/** + * cairo_path_data_type_t: + * @CAIRO_PATH_MOVE_TO: A move-to operation, since 1.0 + * @CAIRO_PATH_LINE_TO: A line-to operation, since 1.0 + * @CAIRO_PATH_CURVE_TO: A curve-to operation, since 1.0 + * @CAIRO_PATH_CLOSE_PATH: A close-path operation, since 1.0 + * + * #cairo_path_data_t is used to describe the type of one portion + * of a path when represented as a #cairo_path_t. + * See #cairo_path_data_t for details. + * + * Since: 1.0 + **/ +typedef enum _cairo_path_data_type { + CAIRO_PATH_MOVE_TO, + CAIRO_PATH_LINE_TO, + CAIRO_PATH_CURVE_TO, + CAIRO_PATH_CLOSE_PATH +} cairo_path_data_type_t; + +/** + * cairo_path_data_t: + * + * #cairo_path_data_t is used to represent the path data inside a + * #cairo_path_t. + * + * The data structure is designed to try to balance the demands of + * efficiency and ease-of-use. A path is represented as an array of + * #cairo_path_data_t, which is a union of headers and points. + * + * Each portion of the path is represented by one or more elements in + * the array, (one header followed by 0 or more points). The length + * value of the header is the number of array elements for the current + * portion including the header, (ie. length == 1 + # of points), and + * where the number of points for each element type is as follows: + * + * + * %CAIRO_PATH_MOVE_TO: 1 point + * %CAIRO_PATH_LINE_TO: 1 point + * %CAIRO_PATH_CURVE_TO: 3 points + * %CAIRO_PATH_CLOSE_PATH: 0 points + * + * + * The semantics and ordering of the coordinate values are consistent + * with cairo_move_to(), cairo_line_to(), cairo_curve_to(), and + * cairo_close_path(). + * + * Here is sample code for iterating through a #cairo_path_t: + * + * + * int i; + * cairo_path_t *path; + * cairo_path_data_t *data; + *   + * path = cairo_copy_path (cr); + *   + * for (i=0; i < path->num_data; i += path->data[i].header.length) { + * data = &path->data[i]; + * switch (data->header.type) { + * case CAIRO_PATH_MOVE_TO: + * do_move_to_things (data[1].point.x, data[1].point.y); + * break; + * case CAIRO_PATH_LINE_TO: + * do_line_to_things (data[1].point.x, data[1].point.y); + * break; + * case CAIRO_PATH_CURVE_TO: + * do_curve_to_things (data[1].point.x, data[1].point.y, + * data[2].point.x, data[2].point.y, + * data[3].point.x, data[3].point.y); + * break; + * case CAIRO_PATH_CLOSE_PATH: + * do_close_path_things (); + * break; + * } + * } + * cairo_path_destroy (path); + * + * + * As of cairo 1.4, cairo does not mind if there are more elements in + * a portion of the path than needed. Such elements can be used by + * users of the cairo API to hold extra values in the path data + * structure. For this reason, it is recommended that applications + * always use data->header.length to + * iterate over the path data, instead of hardcoding the number of + * elements for each element type. + * + * Since: 1.0 + **/ +typedef union _cairo_path_data_t cairo_path_data_t; +union _cairo_path_data_t { + struct { + cairo_path_data_type_t type; + int length; + } header; + struct { + double x, y; + } point; +}; + +/** + * cairo_path_t: + * @status: the current error status + * @data: the elements in the path + * @num_data: the number of elements in the data array + * + * A data structure for holding a path. This data structure serves as + * the return value for cairo_copy_path() and + * cairo_copy_path_flat() as well the input value for + * cairo_append_path(). + * + * See #cairo_path_data_t for hints on how to iterate over the + * actual data within the path. + * + * The num_data member gives the number of elements in the data + * array. This number is larger than the number of independent path + * portions (defined in #cairo_path_data_type_t), since the data + * includes both headers and coordinates for each portion. + * + * Since: 1.0 + **/ +typedef struct cairo_path { + cairo_status_t status; + cairo_path_data_t *data; + int num_data; +} cairo_path_t; + +cairo_public cairo_path_t * +cairo_copy_path (cairo_t *cr); + +cairo_public cairo_path_t * +cairo_copy_path_flat (cairo_t *cr); + +cairo_public void +cairo_append_path (cairo_t *cr, + const cairo_path_t *path); + +cairo_public void +cairo_path_destroy (cairo_path_t *path); + +/* Error status queries */ + +cairo_public cairo_status_t +cairo_status (cairo_t *cr); + +cairo_public const char * +cairo_status_to_string (cairo_status_t status); + +/* Backend device manipulation */ + +cairo_public cairo_device_t * +cairo_device_reference (cairo_device_t *device); + +/** + * cairo_device_type_t: + * @CAIRO_DEVICE_TYPE_DRM: The device is of type Direct Render Manager, since 1.10 + * @CAIRO_DEVICE_TYPE_GL: The device is of type OpenGL, since 1.10 + * @CAIRO_DEVICE_TYPE_SCRIPT: The device is of type script, since 1.10 + * @CAIRO_DEVICE_TYPE_XCB: The device is of type xcb, since 1.10 + * @CAIRO_DEVICE_TYPE_XLIB: The device is of type xlib, since 1.10 + * @CAIRO_DEVICE_TYPE_XML: The device is of type XML, since 1.10 + * @CAIRO_DEVICE_TYPE_COGL: The device is of type cogl, since 1.12 + * @CAIRO_DEVICE_TYPE_WIN32: The device is of type win32, since 1.12 + * @CAIRO_DEVICE_TYPE_INVALID: The device is invalid, since 1.10 + * + * #cairo_device_type_t is used to describe the type of a given + * device. The devices types are also known as "backends" within cairo. + * + * The device type can be queried with cairo_device_get_type() + * + * The various #cairo_device_t functions can be used with devices of + * any type, but some backends also provide type-specific functions + * that must only be called with a device of the appropriate + * type. These functions have names that begin with + * cairo_type_device such as + * cairo_xcb_device_debug_cap_xrender_version(). + * + * The behavior of calling a type-specific function with a device of + * the wrong type is undefined. + * + * New entries may be added in future versions. + * + * Since: 1.10 + **/ +typedef enum _cairo_device_type { + CAIRO_DEVICE_TYPE_DRM, + CAIRO_DEVICE_TYPE_GL, + CAIRO_DEVICE_TYPE_SCRIPT, + CAIRO_DEVICE_TYPE_XCB, + CAIRO_DEVICE_TYPE_XLIB, + CAIRO_DEVICE_TYPE_XML, + CAIRO_DEVICE_TYPE_COGL, + CAIRO_DEVICE_TYPE_WIN32, + + CAIRO_DEVICE_TYPE_INVALID = -1 +} cairo_device_type_t; + +cairo_public cairo_device_type_t +cairo_device_get_type (cairo_device_t *device); + +cairo_public cairo_status_t +cairo_device_status (cairo_device_t *device); + +cairo_public cairo_status_t +cairo_device_acquire (cairo_device_t *device); + +cairo_public void +cairo_device_release (cairo_device_t *device); + +cairo_public void +cairo_device_flush (cairo_device_t *device); + +cairo_public void +cairo_device_finish (cairo_device_t *device); + +cairo_public void +cairo_device_destroy (cairo_device_t *device); + +cairo_public unsigned int +cairo_device_get_reference_count (cairo_device_t *device); + +cairo_public void * +cairo_device_get_user_data (cairo_device_t *device, + const cairo_user_data_key_t *key); + +cairo_public cairo_status_t +cairo_device_set_user_data (cairo_device_t *device, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + + +/* Surface manipulation */ + +cairo_public cairo_surface_t * +cairo_surface_create_similar (cairo_surface_t *other, + cairo_content_t content, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_surface_create_similar_image (cairo_surface_t *other, + cairo_format_t format, + int width, + int height); + +cairo_public cairo_surface_t * +cairo_surface_map_to_image (cairo_surface_t *surface, + const cairo_rectangle_int_t *extents); + +cairo_public void +cairo_surface_unmap_image (cairo_surface_t *surface, + cairo_surface_t *image); + +cairo_public cairo_surface_t * +cairo_surface_create_for_rectangle (cairo_surface_t *target, + double x, + double y, + double width, + double height); + +/** + * cairo_surface_observer_mode_t: + * @CAIRO_SURFACE_OBSERVER_NORMAL: no recording is done + * @CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS: operations are recorded + * + * Whether operations should be recorded. + * + * Since: 1.12 + **/ +typedef enum { + CAIRO_SURFACE_OBSERVER_NORMAL = 0, + CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS = 0x1 +} cairo_surface_observer_mode_t; + +cairo_public cairo_surface_t * +cairo_surface_create_observer (cairo_surface_t *target, + cairo_surface_observer_mode_t mode); + +typedef void (*cairo_surface_observer_callback_t) (cairo_surface_t *observer, + cairo_surface_t *target, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_paint_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_mask_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_fill_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_stroke_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_glyphs_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_flush_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_add_finish_callback (cairo_surface_t *abstract_surface, + cairo_surface_observer_callback_t func, + void *data); + +cairo_public cairo_status_t +cairo_surface_observer_print (cairo_surface_t *surface, + cairo_write_func_t write_func, + void *closure); +cairo_public double +cairo_surface_observer_elapsed (cairo_surface_t *surface); + +cairo_public cairo_status_t +cairo_device_observer_print (cairo_device_t *device, + cairo_write_func_t write_func, + void *closure); + +cairo_public double +cairo_device_observer_elapsed (cairo_device_t *device); + +cairo_public double +cairo_device_observer_paint_elapsed (cairo_device_t *device); + +cairo_public double +cairo_device_observer_mask_elapsed (cairo_device_t *device); + +cairo_public double +cairo_device_observer_fill_elapsed (cairo_device_t *device); + +cairo_public double +cairo_device_observer_stroke_elapsed (cairo_device_t *device); + +cairo_public double +cairo_device_observer_glyphs_elapsed (cairo_device_t *device); + +cairo_public cairo_surface_t * +cairo_surface_reference (cairo_surface_t *surface); + +cairo_public void +cairo_surface_finish (cairo_surface_t *surface); + +cairo_public void +cairo_surface_destroy (cairo_surface_t *surface); + +cairo_public cairo_device_t * +cairo_surface_get_device (cairo_surface_t *surface); + +cairo_public unsigned int +cairo_surface_get_reference_count (cairo_surface_t *surface); + +cairo_public cairo_status_t +cairo_surface_status (cairo_surface_t *surface); + +/** + * cairo_surface_type_t: + * @CAIRO_SURFACE_TYPE_IMAGE: The surface is of type image, since 1.2 + * @CAIRO_SURFACE_TYPE_PDF: The surface is of type pdf, since 1.2 + * @CAIRO_SURFACE_TYPE_PS: The surface is of type ps, since 1.2 + * @CAIRO_SURFACE_TYPE_XLIB: The surface is of type xlib, since 1.2 + * @CAIRO_SURFACE_TYPE_XCB: The surface is of type xcb, since 1.2 + * @CAIRO_SURFACE_TYPE_GLITZ: The surface is of type glitz, since 1.2 + * @CAIRO_SURFACE_TYPE_QUARTZ: The surface is of type quartz, since 1.2 + * @CAIRO_SURFACE_TYPE_WIN32: The surface is of type win32, since 1.2 + * @CAIRO_SURFACE_TYPE_BEOS: The surface is of type beos, since 1.2 + * @CAIRO_SURFACE_TYPE_DIRECTFB: The surface is of type directfb, since 1.2 + * @CAIRO_SURFACE_TYPE_SVG: The surface is of type svg, since 1.2 + * @CAIRO_SURFACE_TYPE_OS2: The surface is of type os2, since 1.4 + * @CAIRO_SURFACE_TYPE_WIN32_PRINTING: The surface is a win32 printing surface, since 1.6 + * @CAIRO_SURFACE_TYPE_QUARTZ_IMAGE: The surface is of type quartz_image, since 1.6 + * @CAIRO_SURFACE_TYPE_SCRIPT: The surface is of type script, since 1.10 + * @CAIRO_SURFACE_TYPE_QT: The surface is of type Qt, since 1.10 + * @CAIRO_SURFACE_TYPE_RECORDING: The surface is of type recording, since 1.10 + * @CAIRO_SURFACE_TYPE_VG: The surface is a OpenVG surface, since 1.10 + * @CAIRO_SURFACE_TYPE_GL: The surface is of type OpenGL, since 1.10 + * @CAIRO_SURFACE_TYPE_DRM: The surface is of type Direct Render Manager, since 1.10 + * @CAIRO_SURFACE_TYPE_TEE: The surface is of type 'tee' (a multiplexing surface), since 1.10 + * @CAIRO_SURFACE_TYPE_XML: The surface is of type XML (for debugging), since 1.10 + * @CAIRO_SURFACE_TYPE_SKIA: The surface is of type Skia, since 1.10 + * @CAIRO_SURFACE_TYPE_SUBSURFACE: The surface is a subsurface created with + * cairo_surface_create_for_rectangle(), since 1.10 + * @CAIRO_SURFACE_TYPE_COGL: This surface is of type Cogl, since 1.12 + * + * #cairo_surface_type_t is used to describe the type of a given + * surface. The surface types are also known as "backends" or "surface + * backends" within cairo. + * + * The type of a surface is determined by the function used to create + * it, which will generally be of the form + * cairo_type_surface_create(), + * (though see cairo_surface_create_similar() as well). + * + * The surface type can be queried with cairo_surface_get_type() + * + * The various #cairo_surface_t functions can be used with surfaces of + * any type, but some backends also provide type-specific functions + * that must only be called with a surface of the appropriate + * type. These functions have names that begin with + * cairo_type_surface such as cairo_image_surface_get_width(). + * + * The behavior of calling a type-specific function with a surface of + * the wrong type is undefined. + * + * New entries may be added in future versions. + * + * Since: 1.2 + **/ +typedef enum _cairo_surface_type { + CAIRO_SURFACE_TYPE_IMAGE, + CAIRO_SURFACE_TYPE_PDF, + CAIRO_SURFACE_TYPE_PS, + CAIRO_SURFACE_TYPE_XLIB, + CAIRO_SURFACE_TYPE_XCB, + CAIRO_SURFACE_TYPE_GLITZ, + CAIRO_SURFACE_TYPE_QUARTZ, + CAIRO_SURFACE_TYPE_WIN32, + CAIRO_SURFACE_TYPE_BEOS, + CAIRO_SURFACE_TYPE_DIRECTFB, + CAIRO_SURFACE_TYPE_SVG, + CAIRO_SURFACE_TYPE_OS2, + CAIRO_SURFACE_TYPE_WIN32_PRINTING, + CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, + CAIRO_SURFACE_TYPE_SCRIPT, + CAIRO_SURFACE_TYPE_QT, + CAIRO_SURFACE_TYPE_RECORDING, + CAIRO_SURFACE_TYPE_VG, + CAIRO_SURFACE_TYPE_GL, + CAIRO_SURFACE_TYPE_DRM, + CAIRO_SURFACE_TYPE_TEE, + CAIRO_SURFACE_TYPE_XML, + CAIRO_SURFACE_TYPE_SKIA, + CAIRO_SURFACE_TYPE_SUBSURFACE, + CAIRO_SURFACE_TYPE_COGL +} cairo_surface_type_t; + +cairo_public cairo_surface_type_t +cairo_surface_get_type (cairo_surface_t *surface); + +cairo_public cairo_content_t +cairo_surface_get_content (cairo_surface_t *surface); + +#if CAIRO_HAS_PNG_FUNCTIONS + +cairo_public cairo_status_t +cairo_surface_write_to_png (cairo_surface_t *surface, + const char *filename); + +cairo_public cairo_status_t +cairo_surface_write_to_png_stream (cairo_surface_t *surface, + cairo_write_func_t write_func, + void *closure); + +#endif + +cairo_public void * +cairo_surface_get_user_data (cairo_surface_t *surface, + const cairo_user_data_key_t *key); + +cairo_public cairo_status_t +cairo_surface_set_user_data (cairo_surface_t *surface, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + +#define CAIRO_MIME_TYPE_JPEG "image/jpeg" +#define CAIRO_MIME_TYPE_PNG "image/png" +#define CAIRO_MIME_TYPE_JP2 "image/jp2" +#define CAIRO_MIME_TYPE_URI "text/x-uri" +#define CAIRO_MIME_TYPE_UNIQUE_ID "application/x-cairo.uuid" +#define CAIRO_MIME_TYPE_JBIG2 "application/x-cairo.jbig2" +#define CAIRO_MIME_TYPE_JBIG2_GLOBAL "application/x-cairo.jbig2-global" +#define CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID "application/x-cairo.jbig2-global-id" + +cairo_public void +cairo_surface_get_mime_data (cairo_surface_t *surface, + const char *mime_type, + const unsigned char **data, + unsigned long *length); + +cairo_public cairo_status_t +cairo_surface_set_mime_data (cairo_surface_t *surface, + const char *mime_type, + const unsigned char *data, + unsigned long length, + cairo_destroy_func_t destroy, + void *closure); + +cairo_public cairo_bool_t +cairo_surface_supports_mime_type (cairo_surface_t *surface, + const char *mime_type); + +cairo_public void +cairo_surface_get_font_options (cairo_surface_t *surface, + cairo_font_options_t *options); + +cairo_public void +cairo_surface_flush (cairo_surface_t *surface); + +cairo_public void +cairo_surface_mark_dirty (cairo_surface_t *surface); + +cairo_public void +cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, + int x, + int y, + int width, + int height); + +cairo_public void +cairo_surface_set_device_scale (cairo_surface_t *surface, + double x_scale, + double y_scale); + +cairo_public void +cairo_surface_get_device_scale (cairo_surface_t *surface, + double *x_scale, + double *y_scale); + +cairo_public void +cairo_surface_set_device_offset (cairo_surface_t *surface, + double x_offset, + double y_offset); + +cairo_public void +cairo_surface_get_device_offset (cairo_surface_t *surface, + double *x_offset, + double *y_offset); + +cairo_public void +cairo_surface_set_fallback_resolution (cairo_surface_t *surface, + double x_pixels_per_inch, + double y_pixels_per_inch); + +cairo_public void +cairo_surface_get_fallback_resolution (cairo_surface_t *surface, + double *x_pixels_per_inch, + double *y_pixels_per_inch); + +cairo_public void +cairo_surface_copy_page (cairo_surface_t *surface); + +cairo_public void +cairo_surface_show_page (cairo_surface_t *surface); + +cairo_public cairo_bool_t +cairo_surface_has_show_text_glyphs (cairo_surface_t *surface); + +/* Image-surface functions */ + +cairo_public cairo_surface_t * +cairo_image_surface_create (cairo_format_t format, + int width, + int height); + +cairo_public int +cairo_format_stride_for_width (cairo_format_t format, + int width); + +cairo_public cairo_surface_t * +cairo_image_surface_create_for_data (unsigned char *data, + cairo_format_t format, + int width, + int height, + int stride); + +cairo_public unsigned char * +cairo_image_surface_get_data (cairo_surface_t *surface); + +cairo_public cairo_format_t +cairo_image_surface_get_format (cairo_surface_t *surface); + +cairo_public int +cairo_image_surface_get_width (cairo_surface_t *surface); + +cairo_public int +cairo_image_surface_get_height (cairo_surface_t *surface); + +cairo_public int +cairo_image_surface_get_stride (cairo_surface_t *surface); + +#if CAIRO_HAS_PNG_FUNCTIONS + +cairo_public cairo_surface_t * +cairo_image_surface_create_from_png (const char *filename); + +cairo_public cairo_surface_t * +cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, + void *closure); + +#endif + +/* Recording-surface functions */ + +cairo_public cairo_surface_t * +cairo_recording_surface_create (cairo_content_t content, + const cairo_rectangle_t *extents); + +cairo_public void +cairo_recording_surface_ink_extents (cairo_surface_t *surface, + double *x0, + double *y0, + double *width, + double *height); + +cairo_public cairo_bool_t +cairo_recording_surface_get_extents (cairo_surface_t *surface, + cairo_rectangle_t *extents); + +/* raster-source pattern (callback) functions */ + +/** + * cairo_raster_source_acquire_func_t: + * @pattern: the pattern being rendered from + * @callback_data: the user data supplied during creation + * @target: the rendering target surface + * @extents: rectangular region of interest in pixels in sample space + * + * #cairo_raster_source_acquire_func_t is the type of function which is + * called when a pattern is being rendered from. It should create a surface + * that provides the pixel data for the region of interest as defined by + * extents, though the surface itself does not have to be limited to that + * area. For convenience the surface should probably be of image type, + * created with cairo_surface_create_similar_image() for the target (which + * enables the number of copies to be reduced during transfer to the + * device). Another option, might be to return a similar surface to the + * target for explicit handling by the application of a set of cached sources + * on the device. The region of sample data provided should be defined using + * cairo_surface_set_device_offset() to specify the top-left corner of the + * sample data (along with width and height of the surface). + * + * Returns: a #cairo_surface_t + * + * Since: 1.12 + **/ +typedef cairo_surface_t * +(*cairo_raster_source_acquire_func_t) (cairo_pattern_t *pattern, + void *callback_data, + cairo_surface_t *target, + const cairo_rectangle_int_t *extents); + +/** + * cairo_raster_source_release_func_t: + * @pattern: the pattern being rendered from + * @callback_data: the user data supplied during creation + * @surface: the surface created during acquire + * + * #cairo_raster_source_release_func_t is the type of function which is + * called when the pixel data is no longer being access by the pattern + * for the rendering operation. Typically this function will simply + * destroy the surface created during acquire. + * + * Since: 1.12 + **/ +typedef void +(*cairo_raster_source_release_func_t) (cairo_pattern_t *pattern, + void *callback_data, + cairo_surface_t *surface); + +/** + * cairo_raster_source_snapshot_func_t: + * @pattern: the pattern being rendered from + * @callback_data: the user data supplied during creation + * + * #cairo_raster_source_snapshot_func_t is the type of function which is + * called when the pixel data needs to be preserved for later use + * during printing. This pattern will be accessed again later, and it + * is expected to provide the pixel data that was current at the time + * of snapshotting. + * + * Return value: CAIRO_STATUS_SUCCESS on success, or one of the + * #cairo_status_t error codes for failure. + * + * Since: 1.12 + **/ +typedef cairo_status_t +(*cairo_raster_source_snapshot_func_t) (cairo_pattern_t *pattern, + void *callback_data); + +/** + * cairo_raster_source_copy_func_t: + * @pattern: the #cairo_pattern_t that was copied to + * @callback_data: the user data supplied during creation + * @other: the #cairo_pattern_t being used as the source for the copy + * + * #cairo_raster_source_copy_func_t is the type of function which is + * called when the pattern gets copied as a normal part of rendering. + * + * Return value: CAIRO_STATUS_SUCCESS on success, or one of the + * #cairo_status_t error codes for failure. + * + * Since: 1.12 + **/ +typedef cairo_status_t +(*cairo_raster_source_copy_func_t) (cairo_pattern_t *pattern, + void *callback_data, + const cairo_pattern_t *other); + +/** + * cairo_raster_source_finish_func_t: + * @pattern: the pattern being rendered from + * @callback_data: the user data supplied during creation + * + * #cairo_raster_source_finish_func_t is the type of function which is + * called when the pattern (or a copy thereof) is no longer required. + * + * Since: 1.12 + **/ +typedef void +(*cairo_raster_source_finish_func_t) (cairo_pattern_t *pattern, + void *callback_data); + +cairo_public cairo_pattern_t * +cairo_pattern_create_raster_source (void *user_data, + cairo_content_t content, + int width, int height); + +cairo_public void +cairo_raster_source_pattern_set_callback_data (cairo_pattern_t *pattern, + void *data); + +cairo_public void * +cairo_raster_source_pattern_get_callback_data (cairo_pattern_t *pattern); + +cairo_public void +cairo_raster_source_pattern_set_acquire (cairo_pattern_t *pattern, + cairo_raster_source_acquire_func_t acquire, + cairo_raster_source_release_func_t release); + +cairo_public void +cairo_raster_source_pattern_get_acquire (cairo_pattern_t *pattern, + cairo_raster_source_acquire_func_t *acquire, + cairo_raster_source_release_func_t *release); +cairo_public void +cairo_raster_source_pattern_set_snapshot (cairo_pattern_t *pattern, + cairo_raster_source_snapshot_func_t snapshot); + +cairo_public cairo_raster_source_snapshot_func_t +cairo_raster_source_pattern_get_snapshot (cairo_pattern_t *pattern); + +cairo_public void +cairo_raster_source_pattern_set_copy (cairo_pattern_t *pattern, + cairo_raster_source_copy_func_t copy); + +cairo_public cairo_raster_source_copy_func_t +cairo_raster_source_pattern_get_copy (cairo_pattern_t *pattern); + +cairo_public void +cairo_raster_source_pattern_set_finish (cairo_pattern_t *pattern, + cairo_raster_source_finish_func_t finish); + +cairo_public cairo_raster_source_finish_func_t +cairo_raster_source_pattern_get_finish (cairo_pattern_t *pattern); + +/* Pattern creation functions */ + +cairo_public cairo_pattern_t * +cairo_pattern_create_rgb (double red, double green, double blue); + +cairo_public cairo_pattern_t * +cairo_pattern_create_rgba (double red, double green, double blue, + double alpha); + +cairo_public cairo_pattern_t * +cairo_pattern_create_for_surface (cairo_surface_t *surface); + +cairo_public cairo_pattern_t * +cairo_pattern_create_linear (double x0, double y0, + double x1, double y1); + +cairo_public cairo_pattern_t * +cairo_pattern_create_radial (double cx0, double cy0, double radius0, + double cx1, double cy1, double radius1); + +cairo_public cairo_pattern_t * +cairo_pattern_create_mesh (void); + +cairo_public cairo_pattern_t * +cairo_pattern_reference (cairo_pattern_t *pattern); + +cairo_public void +cairo_pattern_destroy (cairo_pattern_t *pattern); + +cairo_public unsigned int +cairo_pattern_get_reference_count (cairo_pattern_t *pattern); + +cairo_public cairo_status_t +cairo_pattern_status (cairo_pattern_t *pattern); + +cairo_public void * +cairo_pattern_get_user_data (cairo_pattern_t *pattern, + const cairo_user_data_key_t *key); + +cairo_public cairo_status_t +cairo_pattern_set_user_data (cairo_pattern_t *pattern, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + +/** + * cairo_pattern_type_t: + * @CAIRO_PATTERN_TYPE_SOLID: The pattern is a solid (uniform) + * color. It may be opaque or translucent, since 1.2. + * @CAIRO_PATTERN_TYPE_SURFACE: The pattern is a based on a surface (an image), since 1.2. + * @CAIRO_PATTERN_TYPE_LINEAR: The pattern is a linear gradient, since 1.2. + * @CAIRO_PATTERN_TYPE_RADIAL: The pattern is a radial gradient, since 1.2. + * @CAIRO_PATTERN_TYPE_MESH: The pattern is a mesh, since 1.12. + * @CAIRO_PATTERN_TYPE_RASTER_SOURCE: The pattern is a user pattern providing raster data, since 1.12. + * + * #cairo_pattern_type_t is used to describe the type of a given pattern. + * + * The type of a pattern is determined by the function used to create + * it. The cairo_pattern_create_rgb() and cairo_pattern_create_rgba() + * functions create SOLID patterns. The remaining + * cairo_pattern_create functions map to pattern types in obvious + * ways. + * + * The pattern type can be queried with cairo_pattern_get_type() + * + * Most #cairo_pattern_t functions can be called with a pattern of any + * type, (though trying to change the extend or filter for a solid + * pattern will have no effect). A notable exception is + * cairo_pattern_add_color_stop_rgb() and + * cairo_pattern_add_color_stop_rgba() which must only be called with + * gradient patterns (either LINEAR or RADIAL). Otherwise the pattern + * will be shutdown and put into an error state. + * + * New entries may be added in future versions. + * + * Since: 1.2 + **/ +typedef enum _cairo_pattern_type { + CAIRO_PATTERN_TYPE_SOLID, + CAIRO_PATTERN_TYPE_SURFACE, + CAIRO_PATTERN_TYPE_LINEAR, + CAIRO_PATTERN_TYPE_RADIAL, + CAIRO_PATTERN_TYPE_MESH, + CAIRO_PATTERN_TYPE_RASTER_SOURCE +} cairo_pattern_type_t; + +cairo_public cairo_pattern_type_t +cairo_pattern_get_type (cairo_pattern_t *pattern); + +cairo_public void +cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, + double offset, + double red, double green, double blue); + +cairo_public void +cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, + double offset, + double red, double green, double blue, + double alpha); + +cairo_public void +cairo_mesh_pattern_begin_patch (cairo_pattern_t *pattern); + +cairo_public void +cairo_mesh_pattern_end_patch (cairo_pattern_t *pattern); + +cairo_public void +cairo_mesh_pattern_curve_to (cairo_pattern_t *pattern, + double x1, double y1, + double x2, double y2, + double x3, double y3); + +cairo_public void +cairo_mesh_pattern_line_to (cairo_pattern_t *pattern, + double x, double y); + +cairo_public void +cairo_mesh_pattern_move_to (cairo_pattern_t *pattern, + double x, double y); + +cairo_public void +cairo_mesh_pattern_set_control_point (cairo_pattern_t *pattern, + unsigned int point_num, + double x, double y); + +cairo_public void +cairo_mesh_pattern_set_corner_color_rgb (cairo_pattern_t *pattern, + unsigned int corner_num, + double red, double green, double blue); + +cairo_public void +cairo_mesh_pattern_set_corner_color_rgba (cairo_pattern_t *pattern, + unsigned int corner_num, + double red, double green, double blue, + double alpha); + +cairo_public void +cairo_pattern_set_matrix (cairo_pattern_t *pattern, + const cairo_matrix_t *matrix); + +cairo_public void +cairo_pattern_get_matrix (cairo_pattern_t *pattern, + cairo_matrix_t *matrix); + +/** + * cairo_extend_t: + * @CAIRO_EXTEND_NONE: pixels outside of the source pattern + * are fully transparent (Since 1.0) + * @CAIRO_EXTEND_REPEAT: the pattern is tiled by repeating (Since 1.0) + * @CAIRO_EXTEND_REFLECT: the pattern is tiled by reflecting + * at the edges (Since 1.0; but only implemented for surface patterns since 1.6) + * @CAIRO_EXTEND_PAD: pixels outside of the pattern copy + * the closest pixel from the source (Since 1.2; but only + * implemented for surface patterns since 1.6) + * + * #cairo_extend_t is used to describe how pattern color/alpha will be + * determined for areas "outside" the pattern's natural area, (for + * example, outside the surface bounds or outside the gradient + * geometry). + * + * Mesh patterns are not affected by the extend mode. + * + * The default extend mode is %CAIRO_EXTEND_NONE for surface patterns + * and %CAIRO_EXTEND_PAD for gradient patterns. + * + * New entries may be added in future versions. + * + * Since: 1.0 + **/ +typedef enum _cairo_extend { + CAIRO_EXTEND_NONE, + CAIRO_EXTEND_REPEAT, + CAIRO_EXTEND_REFLECT, + CAIRO_EXTEND_PAD +} cairo_extend_t; + +cairo_public void +cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend); + +cairo_public cairo_extend_t +cairo_pattern_get_extend (cairo_pattern_t *pattern); + +/** + * cairo_filter_t: + * @CAIRO_FILTER_FAST: A high-performance filter, with quality similar + * to %CAIRO_FILTER_NEAREST (Since 1.0) + * @CAIRO_FILTER_GOOD: A reasonable-performance filter, with quality + * similar to %CAIRO_FILTER_BILINEAR (Since 1.0) + * @CAIRO_FILTER_BEST: The highest-quality available, performance may + * not be suitable for interactive use. (Since 1.0) + * @CAIRO_FILTER_NEAREST: Nearest-neighbor filtering (Since 1.0) + * @CAIRO_FILTER_BILINEAR: Linear interpolation in two dimensions (Since 1.0) + * @CAIRO_FILTER_GAUSSIAN: This filter value is currently + * unimplemented, and should not be used in current code. (Since 1.0) + * + * #cairo_filter_t is used to indicate what filtering should be + * applied when reading pixel values from patterns. See + * cairo_pattern_set_filter() for indicating the desired filter to be + * used with a particular pattern. + * + * Since: 1.0 + **/ +typedef enum _cairo_filter { + CAIRO_FILTER_FAST, + CAIRO_FILTER_GOOD, + CAIRO_FILTER_BEST, + CAIRO_FILTER_NEAREST, + CAIRO_FILTER_BILINEAR, + CAIRO_FILTER_GAUSSIAN +} cairo_filter_t; + +cairo_public void +cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter); + +cairo_public cairo_filter_t +cairo_pattern_get_filter (cairo_pattern_t *pattern); + +cairo_public cairo_status_t +cairo_pattern_get_rgba (cairo_pattern_t *pattern, + double *red, double *green, + double *blue, double *alpha); + +cairo_public cairo_status_t +cairo_pattern_get_surface (cairo_pattern_t *pattern, + cairo_surface_t **surface); + + +cairo_public cairo_status_t +cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern, + int index, double *offset, + double *red, double *green, + double *blue, double *alpha); + +cairo_public cairo_status_t +cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern, + int *count); + +cairo_public cairo_status_t +cairo_pattern_get_linear_points (cairo_pattern_t *pattern, + double *x0, double *y0, + double *x1, double *y1); + +cairo_public cairo_status_t +cairo_pattern_get_radial_circles (cairo_pattern_t *pattern, + double *x0, double *y0, double *r0, + double *x1, double *y1, double *r1); + +cairo_public cairo_status_t +cairo_mesh_pattern_get_patch_count (cairo_pattern_t *pattern, + unsigned int *count); + +cairo_public cairo_path_t * +cairo_mesh_pattern_get_path (cairo_pattern_t *pattern, + unsigned int patch_num); + +cairo_public cairo_status_t +cairo_mesh_pattern_get_corner_color_rgba (cairo_pattern_t *pattern, + unsigned int patch_num, + unsigned int corner_num, + double *red, double *green, + double *blue, double *alpha); + +cairo_public cairo_status_t +cairo_mesh_pattern_get_control_point (cairo_pattern_t *pattern, + unsigned int patch_num, + unsigned int point_num, + double *x, double *y); + +/* Matrix functions */ + +cairo_public void +cairo_matrix_init (cairo_matrix_t *matrix, + double xx, double yx, + double xy, double yy, + double x0, double y0); + +cairo_public void +cairo_matrix_init_identity (cairo_matrix_t *matrix); + +cairo_public void +cairo_matrix_init_translate (cairo_matrix_t *matrix, + double tx, double ty); + +cairo_public void +cairo_matrix_init_scale (cairo_matrix_t *matrix, + double sx, double sy); + +cairo_public void +cairo_matrix_init_rotate (cairo_matrix_t *matrix, + double radians); + +cairo_public void +cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty); + +cairo_public void +cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy); + +cairo_public void +cairo_matrix_rotate (cairo_matrix_t *matrix, double radians); + +cairo_public cairo_status_t +cairo_matrix_invert (cairo_matrix_t *matrix); + +cairo_public void +cairo_matrix_multiply (cairo_matrix_t *result, + const cairo_matrix_t *a, + const cairo_matrix_t *b); + +cairo_public void +cairo_matrix_transform_distance (const cairo_matrix_t *matrix, + double *dx, double *dy); + +cairo_public void +cairo_matrix_transform_point (const cairo_matrix_t *matrix, + double *x, double *y); + +/* Region functions */ + +/** + * cairo_region_t: + * + * A #cairo_region_t represents a set of integer-aligned rectangles. + * + * It allows set-theoretical operations like cairo_region_union() and + * cairo_region_intersect() to be performed on them. + * + * Memory management of #cairo_region_t is done with + * cairo_region_reference() and cairo_region_destroy(). + * + * Since: 1.10 + **/ +typedef struct _cairo_region cairo_region_t; + +/** + * cairo_region_overlap_t: + * @CAIRO_REGION_OVERLAP_IN: The contents are entirely inside the region. (Since 1.10) + * @CAIRO_REGION_OVERLAP_OUT: The contents are entirely outside the region. (Since 1.10) + * @CAIRO_REGION_OVERLAP_PART: The contents are partially inside and + * partially outside the region. (Since 1.10) + * + * Used as the return value for cairo_region_contains_rectangle(). + * + * Since: 1.10 + **/ +typedef enum _cairo_region_overlap { + CAIRO_REGION_OVERLAP_IN, /* completely inside region */ + CAIRO_REGION_OVERLAP_OUT, /* completely outside region */ + CAIRO_REGION_OVERLAP_PART /* partly inside region */ +} cairo_region_overlap_t; + +cairo_public cairo_region_t * +cairo_region_create (void); + +cairo_public cairo_region_t * +cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle); + +cairo_public cairo_region_t * +cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, + int count); + +cairo_public cairo_region_t * +cairo_region_copy (const cairo_region_t *original); + +cairo_public cairo_region_t * +cairo_region_reference (cairo_region_t *region); + +cairo_public void +cairo_region_destroy (cairo_region_t *region); + +cairo_public cairo_bool_t +cairo_region_equal (const cairo_region_t *a, const cairo_region_t *b); + +cairo_public cairo_status_t +cairo_region_status (const cairo_region_t *region); + +cairo_public void +cairo_region_get_extents (const cairo_region_t *region, + cairo_rectangle_int_t *extents); + +cairo_public int +cairo_region_num_rectangles (const cairo_region_t *region); + +cairo_public void +cairo_region_get_rectangle (const cairo_region_t *region, + int nth, + cairo_rectangle_int_t *rectangle); + +cairo_public cairo_bool_t +cairo_region_is_empty (const cairo_region_t *region); + +cairo_public cairo_region_overlap_t +cairo_region_contains_rectangle (const cairo_region_t *region, + const cairo_rectangle_int_t *rectangle); + +cairo_public cairo_bool_t +cairo_region_contains_point (const cairo_region_t *region, int x, int y); + +cairo_public void +cairo_region_translate (cairo_region_t *region, int dx, int dy); + +cairo_public cairo_status_t +cairo_region_subtract (cairo_region_t *dst, const cairo_region_t *other); + +cairo_public cairo_status_t +cairo_region_subtract_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle); + +cairo_public cairo_status_t +cairo_region_intersect (cairo_region_t *dst, const cairo_region_t *other); + +cairo_public cairo_status_t +cairo_region_intersect_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle); + +cairo_public cairo_status_t +cairo_region_union (cairo_region_t *dst, const cairo_region_t *other); + +cairo_public cairo_status_t +cairo_region_union_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle); + +cairo_public cairo_status_t +cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other); + +cairo_public cairo_status_t +cairo_region_xor_rectangle (cairo_region_t *dst, + const cairo_rectangle_int_t *rectangle); + +/* Functions to be used while debugging (not intended for use in production code) */ +cairo_public void +cairo_debug_reset_static_data (void); + + +CAIRO_END_DECLS + +#endif /* CAIRO_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/cairo.pc.in b/Build/source/libs/cairo/cairo-src/src/cairo.pc.in new file mode 100644 index 00000000000..b361edf18fb --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairo.pc.in @@ -0,0 +1,13 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: cairo +Description: Multi-platform 2D graphics library +Version: @VERSION@ + +@PKGCONFIG_REQUIRES@: @CAIRO_REQUIRES@ +Libs: -L${libdir} -lcairo +Libs.private: @CAIRO_NONPKGCONFIG_LIBS@ +Cflags: -I${includedir}/cairo diff --git a/Build/source/libs/cairo/cairo-src/src/cairoint.h b/Build/source/libs/cairo/cairo-src/src/cairoint.h new file mode 100644 index 00000000000..555aa899030 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/cairoint.h @@ -0,0 +1,2082 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + */ + +/* + * These definitions are solely for use by the implementation of cairo + * and constitute no kind of standard. If you need any of these + * functions, please drop me a note. Either the library needs new + * functionality, or there's a way to do what you need using the + * existing published interfaces. cworth@cworth.org + */ + +#ifndef _CAIROINT_H_ +#define _CAIROINT_H_ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef _MSC_VER +#define cairo_public __declspec(dllexport) +#endif + +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#define _USE_MATH_DEFINES +#endif +#include +#include +#include + +#include "cairo.h" +#include + +#include "cairo-compiler-private.h" +#include "cairo-error-private.h" + +#if CAIRO_HAS_PDF_SURFACE || \ + CAIRO_HAS_PS_SURFACE || \ + CAIRO_HAS_SCRIPT_SURFACE || \ + CAIRO_HAS_XML_SURFACE +#define CAIRO_HAS_DEFLATE_STREAM 1 +#endif + +#if CAIRO_HAS_PS_SURFACE || \ + CAIRO_HAS_PDF_SURFACE || \ + CAIRO_HAS_SVG_SURFACE || \ + CAIRO_HAS_WIN32_SURFACE +#define CAIRO_HAS_FONT_SUBSET 1 +#endif + +#if CAIRO_HAS_PS_SURFACE || \ + CAIRO_HAS_PDF_SURFACE || \ + CAIRO_HAS_FONT_SUBSET +#define CAIRO_HAS_PDF_OPERATORS 1 +#endif + +CAIRO_BEGIN_DECLS + +#if _WIN32 && !_WIN32_WCE /* Permissions on WinCE? No worries! */ +cairo_private FILE * +_cairo_win32_tmpfile (void); +#define tmpfile() _cairo_win32_tmpfile() +#endif + +#undef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +#undef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 +#endif + +#ifndef M_SQRT1_2 +#define M_SQRT1_2 0.707106781186547524400844362104849039 +#endif + +#undef ARRAY_LENGTH +#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0]))) + +#undef STRINGIFY +#undef STRINGIFY_ARG +#define STRINGIFY(macro_or_string) STRINGIFY_ARG (macro_or_string) +#define STRINGIFY_ARG(contents) #contents + +#if defined (__GNUC__) +#define cairo_container_of(ptr, type, member) ({ \ + const __typeof__ (((type *) 0)->member) *mptr__ = (ptr); \ + (type *) ((char *) mptr__ - offsetof (type, member)); \ +}) +#else +#define cairo_container_of(ptr, type, member) \ + ((type *)((char *) (ptr) - (char *) &((type *)0)->member)) +#endif + + +#define ASSERT_NOT_REACHED \ +do { \ + assert (!"reached"); \ +} while (0) +#define COMPILE_TIME_ASSERT1(condition, line) \ + typedef int compile_time_assertion_at_line_##line##_failed [(condition)?1:-1] +#define COMPILE_TIME_ASSERT0(condition, line) COMPILE_TIME_ASSERT1(condition, line) +#define COMPILE_TIME_ASSERT(condition) COMPILE_TIME_ASSERT0(condition, __LINE__) + +#define CAIRO_ALPHA_IS_CLEAR(alpha) ((alpha) <= ((double)0x00ff / (double)0xffff)) +#define CAIRO_ALPHA_SHORT_IS_CLEAR(alpha) ((alpha) <= 0x00ff) + +#define CAIRO_ALPHA_IS_OPAQUE(alpha) ((alpha) >= ((double)0xff00 / (double)0xffff)) +#define CAIRO_ALPHA_SHORT_IS_OPAQUE(alpha) ((alpha) >= 0xff00) +#define CAIRO_ALPHA_IS_ZERO(alpha) ((alpha) <= 0.0) + +#define CAIRO_COLOR_IS_CLEAR(color) CAIRO_ALPHA_SHORT_IS_CLEAR ((color)->alpha_short) +#define CAIRO_COLOR_IS_OPAQUE(color) CAIRO_ALPHA_SHORT_IS_OPAQUE ((color)->alpha_short) + +/* Reverse the bits in a byte with 7 operations (no 64-bit): + * Devised by Sean Anderson, July 13, 2001. + * Source: http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits + */ +#define CAIRO_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16) + +/* Return the number of 1 bits in mask. + * + * GCC 3.4 supports a "population count" builtin, which on many targets is + * implemented with a single instruction. There is a fallback definition + * in libgcc in case a target does not have one, which should be just as + * good as the open-coded solution below, (which is "HACKMEM 169"). + */ +static inline int cairo_const +_cairo_popcount (uint32_t mask) +{ +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + return __builtin_popcount (mask); +#else + register int y; + + y = (mask >> 1) &033333333333; + y = mask - y - ((y >>1) & 033333333333); + return (((y + (y >> 3)) & 030707070707) % 077); +#endif +} + +static cairo_always_inline cairo_bool_t +_cairo_is_little_endian (void) +{ + static const int i = 1; + return *((char *) &i) == 0x01; +} + +#ifdef WORDS_BIGENDIAN +#define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) (c) +#else +#define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) CAIRO_BITSWAP8(c) +#endif + +#ifdef WORDS_BIGENDIAN + +#define cpu_to_be16(v) (v) +#define be16_to_cpu(v) (v) +#define cpu_to_be32(v) (v) +#define be32_to_cpu(v) (v) + +#else + +static inline uint16_t cairo_const +cpu_to_be16(uint16_t v) +{ + return (v << 8) | (v >> 8); +} + +static inline uint16_t cairo_const +be16_to_cpu(uint16_t v) +{ + return cpu_to_be16 (v); +} + +static inline uint32_t cairo_const +cpu_to_be32(uint32_t v) +{ + return (v >> 24) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | (v << 24); +} + +static inline uint32_t cairo_const +be32_to_cpu(uint32_t v) +{ + return cpu_to_be32 (v); +} + +#endif + +/* Unaligned big endian access + */ + +static inline uint16_t get_unaligned_be16 (const unsigned char *p) +{ + return p[0] << 8 | p[1]; +} + +static inline uint32_t get_unaligned_be32 (const unsigned char *p) +{ + return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; +} + +static inline void put_unaligned_be16 (uint16_t v, unsigned char *p) +{ + p[0] = (v >> 8) & 0xff; + p[1] = v & 0xff; +} + +static inline void put_unaligned_be32 (uint32_t v, unsigned char *p) +{ + p[0] = (v >> 24) & 0xff; + p[1] = (v >> 16) & 0xff; + p[2] = (v >> 8) & 0xff; + p[3] = v & 0xff; +} + +/* The glibc versions of ispace() and isdigit() are slow in UTF-8 locales. + */ + +static inline int cairo_const +_cairo_isspace (int c) +{ + return (c == 0x20 || (c >= 0x09 && c <= 0x0d)); +} + +static inline int cairo_const +_cairo_isdigit (int c) +{ + return (c >= '0' && c <= '9'); +} + +#include "cairo-types-private.h" +#include "cairo-cache-private.h" +#include "cairo-reference-count-private.h" +#include "cairo-spans-private.h" +#include "cairo-surface-private.h" + +cairo_private void +_cairo_box_from_doubles (cairo_box_t *box, + double *x1, double *y1, + double *x2, double *y2); + +cairo_private void +_cairo_box_to_doubles (const cairo_box_t *box, + double *x1, double *y1, + double *x2, double *y2); + +cairo_private void +_cairo_box_from_rectangle (cairo_box_t *box, + const cairo_rectangle_int_t *rectangle); + +cairo_private void +_cairo_box_round_to_rectangle (const cairo_box_t *box, + cairo_rectangle_int_t *rectangle); + +cairo_private void +_cairo_box_add_curve_to (cairo_box_t *extents, + const cairo_point_t *a, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d); + +cairo_private void +_cairo_boxes_get_extents (const cairo_box_t *boxes, + int num_boxes, + cairo_box_t *extents); + +cairo_private extern const cairo_rectangle_int_t _cairo_empty_rectangle; +cairo_private extern const cairo_rectangle_int_t _cairo_unbounded_rectangle; + +static inline void +_cairo_unbounded_rectangle_init (cairo_rectangle_int_t *rect) +{ + *rect = _cairo_unbounded_rectangle; +} + +cairo_private_no_warn cairo_bool_t +_cairo_rectangle_intersect (cairo_rectangle_int_t *dst, + const cairo_rectangle_int_t *src); + +static inline cairo_bool_t +_cairo_rectangle_intersects (const cairo_rectangle_int_t *dst, + const cairo_rectangle_int_t *src) +{ + return !(src->x >= dst->x + (int) dst->width || + src->x + (int) src->width <= dst->x || + src->y >= dst->y + (int) dst->height || + src->y + (int) src->height <= dst->y); +} + +static inline cairo_bool_t +_cairo_rectangle_contains_rectangle (const cairo_rectangle_int_t *a, + const cairo_rectangle_int_t *b) +{ + return (a->x <= b->x && + a->x + (int) a->width >= b->x + (int) b->width && + a->y <= b->y && + a->y + (int) a->height >= b->y + (int) b->height); +} + +cairo_private void +_cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti, + const cairo_rectangle_t *rectf); + +/* Extends the dst rectangle to also contain src. + * If one of the rectangles is empty, the result is undefined + */ +cairo_private void +_cairo_rectangle_union (cairo_rectangle_int_t *dst, + const cairo_rectangle_int_t *src); + +cairo_private cairo_bool_t +_cairo_box_intersects_line_segment (const cairo_box_t *box, + cairo_line_t *line) cairo_pure; + +cairo_private cairo_bool_t +_cairo_spline_intersects (const cairo_point_t *a, + const cairo_point_t *b, + const cairo_point_t *c, + const cairo_point_t *d, + const cairo_box_t *box) cairo_pure; + +typedef struct { + const cairo_user_data_key_t *key; + void *user_data; + cairo_destroy_func_t destroy; +} cairo_user_data_slot_t; + +cairo_private void +_cairo_user_data_array_init (cairo_user_data_array_t *array); + +cairo_private void +_cairo_user_data_array_fini (cairo_user_data_array_t *array); + +cairo_private void * +_cairo_user_data_array_get_data (cairo_user_data_array_t *array, + const cairo_user_data_key_t *key); + +cairo_private cairo_status_t +_cairo_user_data_array_set_data (cairo_user_data_array_t *array, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy); + +cairo_private cairo_status_t +_cairo_user_data_array_copy (cairo_user_data_array_t *dst, + const cairo_user_data_array_t *src); + +cairo_private void +_cairo_user_data_array_foreach (cairo_user_data_array_t *array, + void (*func) (const void *key, + void *elt, + void *closure), + void *closure); + +#define _CAIRO_HASH_INIT_VALUE 5381 + +cairo_private unsigned long +_cairo_hash_string (const char *c); + +cairo_private unsigned long +_cairo_hash_bytes (unsigned long hash, + const void *bytes, + unsigned int length); + +#define _cairo_scaled_glyph_index(g) ((g)->hash_entry.hash) +#define _cairo_scaled_glyph_set_index(g, i) ((g)->hash_entry.hash = (i)) + +#include "cairo-scaled-font-private.h" + +struct _cairo_font_face { + /* hash_entry must be first */ + cairo_hash_entry_t hash_entry; + cairo_status_t status; + cairo_reference_count_t ref_count; + cairo_user_data_array_t user_data; + const cairo_font_face_backend_t *backend; +}; + +cairo_private void +_cairo_default_context_reset_static_data (void); + +cairo_private void +_cairo_toy_font_face_reset_static_data (void); + +cairo_private void +_cairo_ft_font_reset_static_data (void); + +cairo_private void +_cairo_win32_font_reset_static_data (void); + +#if CAIRO_HAS_COGL_SURFACE +void +_cairo_cogl_context_reset_static_data (void); +#endif + +/* the font backend interface */ + +struct _cairo_unscaled_font_backend { + cairo_bool_t (*destroy) (void *unscaled_font); +}; + +/* #cairo_toy_font_face_t - simple family/slant/weight font faces used for + * the built-in font API + */ + +typedef struct _cairo_toy_font_face { + cairo_font_face_t base; + const char *family; + cairo_bool_t owns_family; + cairo_font_slant_t slant; + cairo_font_weight_t weight; + + cairo_font_face_t *impl_face; /* The non-toy font face this actually uses */ +} cairo_toy_font_face_t; + +typedef enum _cairo_scaled_glyph_info { + CAIRO_SCALED_GLYPH_INFO_METRICS = (1 << 0), + CAIRO_SCALED_GLYPH_INFO_SURFACE = (1 << 1), + CAIRO_SCALED_GLYPH_INFO_PATH = (1 << 2), + CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE = (1 << 3) +} cairo_scaled_glyph_info_t; + +typedef struct _cairo_scaled_font_subset { + cairo_scaled_font_t *scaled_font; + unsigned int font_id; + unsigned int subset_id; + + /* Index of glyphs array is subset_glyph_index. + * Value of glyphs array is scaled_font_glyph_index. + */ + unsigned long *glyphs; + char **utf8; + char **glyph_names; + int *to_latin_char; + unsigned long *latin_to_subset_glyph_index; + unsigned int num_glyphs; + cairo_bool_t is_composite; + cairo_bool_t is_scaled; + cairo_bool_t is_latin; +} cairo_scaled_font_subset_t; + +struct _cairo_scaled_font_backend { + cairo_font_type_t type; + + void + (*fini) (void *scaled_font); + + cairo_warn cairo_int_status_t + (*scaled_glyph_init) (void *scaled_font, + cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_glyph_info_t info); + + /* A backend only needs to implement this or ucs4_to_index(), not + * both. This allows the backend to do something more sophisticated + * then just converting characters one by one. + */ + cairo_warn cairo_int_status_t + (*text_to_glyphs) (void *scaled_font, + double x, + double y, + const char *utf8, + int utf8_len, + cairo_glyph_t **glyphs, + int *num_glyphs, + cairo_text_cluster_t **clusters, + int *num_clusters, + cairo_text_cluster_flags_t *cluster_flags); + + unsigned long + (*ucs4_to_index) (void *scaled_font, + uint32_t ucs4); + + /* Read data from a sfnt font table. + * @scaled_font: font + * @tag: 4 byte table name specifying the table to read. + * @offset: offset into the table + * @buffer: buffer to write data into. Caller must ensure there is sufficient space. + * If NULL, return the size of the table in @length. + * @length: If @buffer is NULL, the size of the table will be returned in @length. + * If @buffer is not null, @length specifies the number of bytes to read. + * + * If less than @length bytes are available to read this function + * returns CAIRO_INT_STATUS_UNSUPPORTED. Note that requesting more + * bytes than are available in the table may continue reading data + * from the following table and return success. If this is + * undesirable the caller should first query the table size. If an + * error occurs the output value of @length is undefined. + * + * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a sfnt style font or table not found. + */ + cairo_warn cairo_int_status_t + (*load_truetype_table)(void *scaled_font, + unsigned long tag, + long offset, + unsigned char *buffer, + unsigned long *length); + + /* ucs4 is set to -1 if the unicode character could not be found + * for the glyph */ + cairo_warn cairo_int_status_t + (*index_to_ucs4)(void *scaled_font, + unsigned long index, + uint32_t *ucs4); + + cairo_warn cairo_bool_t + (*is_synthetic)(void *scaled_font); + + /* For type 1 fonts, return the glyph name for a given glyph index. + * A glyph index and list of glyph names in the Type 1 fonts is provided. + * The function returns the index of the glyph in the list of glyph names. + * @scaled_font: font + * @glyph_names: the names of each glyph in the Type 1 font in the + * order they appear in the CharStrings array + * @num_glyph_names: the number of names in the glyph_names array + * @glyph_index: the given glyph index + * @glyph_array_index: (index into glyph_names) the glyph name corresponding + * to the glyph_index + */ + + cairo_warn cairo_int_status_t + (*index_to_glyph_name)(void *scaled_font, + char **glyph_names, + int num_glyph_names, + unsigned long glyph_index, + unsigned long *glyph_array_index); + + /* Read data from a PostScript font. + * @scaled_font: font + * @offset: offset into the table + * @buffer: buffer to write data into. Caller must ensure there is sufficient space. + * If NULL, return the size of the table in @length. + * @length: If @buffer is NULL, the size of the table will be returned in @length. + * If @buffer is not null, @length specifies the number of bytes to read. + * + * If less than @length bytes are available to read this function + * returns CAIRO_INT_STATUS_UNSUPPORTED. If an error occurs the + * output value of @length is undefined. + * + * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a Type 1 font. + */ + cairo_warn cairo_int_status_t + (*load_type1_data) (void *scaled_font, + long offset, + unsigned char *buffer, + unsigned long *length); +}; + +struct _cairo_font_face_backend { + cairo_font_type_t type; + + cairo_warn cairo_status_t + (*create_for_toy) (cairo_toy_font_face_t *toy_face, + cairo_font_face_t **font_face); + + /* The destroy() function is allowed to resurrect the font face + * by re-referencing. This is needed for the FreeType backend. + */ + cairo_bool_t + (*destroy) (void *font_face); + + cairo_warn cairo_status_t + (*scaled_font_create) (void *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + cairo_scaled_font_t **scaled_font); + + cairo_font_face_t * + (*get_implementation) (void *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options); +}; + +extern const cairo_private struct _cairo_font_face_backend _cairo_user_font_face_backend; + +/* concrete font backends */ +#if CAIRO_HAS_FT_FONT + +extern const cairo_private struct _cairo_font_face_backend _cairo_ft_font_face_backend; + +#endif + +#if CAIRO_HAS_WIN32_FONT + +extern const cairo_private struct _cairo_font_face_backend _cairo_win32_font_face_backend; + +#endif + +#if CAIRO_HAS_QUARTZ_FONT + +extern const cairo_private struct _cairo_font_face_backend _cairo_quartz_font_face_backend; + +#endif + +#define CAIRO_EXTEND_SURFACE_DEFAULT CAIRO_EXTEND_NONE +#define CAIRO_EXTEND_GRADIENT_DEFAULT CAIRO_EXTEND_PAD +#define CAIRO_FILTER_DEFAULT CAIRO_FILTER_GOOD + +extern const cairo_private cairo_solid_pattern_t _cairo_pattern_clear; +extern const cairo_private cairo_solid_pattern_t _cairo_pattern_black; +extern const cairo_private cairo_solid_pattern_t _cairo_pattern_white; + +struct _cairo_surface_attributes { + cairo_matrix_t matrix; + cairo_extend_t extend; + cairo_filter_t filter; + cairo_bool_t has_component_alpha; + int x_offset; + int y_offset; + void *extra; +}; + +#define CAIRO_FONT_SLANT_DEFAULT CAIRO_FONT_SLANT_NORMAL +#define CAIRO_FONT_WEIGHT_DEFAULT CAIRO_FONT_WEIGHT_NORMAL + +#define CAIRO_WIN32_FONT_FAMILY_DEFAULT "Arial" +#define CAIRO_QUARTZ_FONT_FAMILY_DEFAULT "Helvetica" +#define CAIRO_FT_FONT_FAMILY_DEFAULT "" +#define CAIRO_USER_FONT_FAMILY_DEFAULT "@cairo:" + +#if CAIRO_HAS_WIN32_FONT + +#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_WIN32_FONT_FAMILY_DEFAULT +#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_win32_font_face_backend + +#elif CAIRO_HAS_QUARTZ_FONT + +#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_QUARTZ_FONT_FAMILY_DEFAULT +#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_quartz_font_face_backend + +#elif CAIRO_HAS_FT_FONT + +#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_FT_FONT_FAMILY_DEFAULT +#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_ft_font_face_backend + +#else + +#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_FT_FONT_FAMILY_DEFAULT +#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_user_font_face_backend + +#endif + +#define CAIRO_GSTATE_OPERATOR_DEFAULT CAIRO_OPERATOR_OVER +#define CAIRO_GSTATE_TOLERANCE_DEFAULT 0.1 +#define CAIRO_GSTATE_FILL_RULE_DEFAULT CAIRO_FILL_RULE_WINDING +#define CAIRO_GSTATE_LINE_WIDTH_DEFAULT 2.0 +#define CAIRO_GSTATE_LINE_CAP_DEFAULT CAIRO_LINE_CAP_BUTT +#define CAIRO_GSTATE_LINE_JOIN_DEFAULT CAIRO_LINE_JOIN_MITER +#define CAIRO_GSTATE_MITER_LIMIT_DEFAULT 10.0 +#define CAIRO_GSTATE_DEFAULT_FONT_SIZE 10.0 + +#define CAIRO_SURFACE_RESOLUTION_DEFAULT 72.0 +#define CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT 300.0 + +typedef struct _cairo_stroke_face { + cairo_point_t ccw; + cairo_point_t point; + cairo_point_t cw; + cairo_slope_t dev_vector; + cairo_point_double_t dev_slope; + cairo_point_double_t usr_vector; + double length; +} cairo_stroke_face_t; + +/* cairo.c */ + +static inline double cairo_const +_cairo_restrict_value (double value, double min, double max) +{ + if (value < min) + return min; + else if (value > max) + return max; + else + return value; +} + +/* C99 round() rounds to the nearest integral value with halfway cases rounded + * away from 0. _cairo_round rounds halfway cases toward positive infinity. + * This matches the rounding behaviour of _cairo_lround. */ +static inline double cairo_const +_cairo_round (double r) +{ + return floor (r + .5); +} + +#if DISABLE_SOME_FLOATING_POINT +cairo_private int +_cairo_lround (double d) cairo_const; +#else +static inline int cairo_const +_cairo_lround (double r) +{ + return _cairo_round (r); +} +#endif + +cairo_private uint16_t +_cairo_half_from_float (float f) cairo_const; + +cairo_private cairo_bool_t +_cairo_operator_bounded_by_mask (cairo_operator_t op) cairo_const; + +cairo_private cairo_bool_t +_cairo_operator_bounded_by_source (cairo_operator_t op) cairo_const; + +enum { + CAIRO_OPERATOR_BOUND_BY_MASK = 1 << 1, + CAIRO_OPERATOR_BOUND_BY_SOURCE = 1 << 2, +}; + +cairo_private uint32_t +_cairo_operator_bounded_by_either (cairo_operator_t op) cairo_const; +/* cairo-color.c */ +cairo_private const cairo_color_t * +_cairo_stock_color (cairo_stock_t stock) cairo_pure; + +#define CAIRO_COLOR_WHITE _cairo_stock_color (CAIRO_STOCK_WHITE) +#define CAIRO_COLOR_BLACK _cairo_stock_color (CAIRO_STOCK_BLACK) +#define CAIRO_COLOR_TRANSPARENT _cairo_stock_color (CAIRO_STOCK_TRANSPARENT) + +cairo_private uint16_t +_cairo_color_double_to_short (double d) cairo_const; + +cairo_private void +_cairo_color_init_rgba (cairo_color_t *color, + double red, double green, double blue, + double alpha); + +cairo_private void +_cairo_color_multiply_alpha (cairo_color_t *color, + double alpha); + +cairo_private void +_cairo_color_get_rgba (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha); + +cairo_private void +_cairo_color_get_rgba_premultiplied (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha); + +cairo_private cairo_bool_t +_cairo_color_equal (const cairo_color_t *color_a, + const cairo_color_t *color_b) cairo_pure; + +cairo_private cairo_bool_t +_cairo_color_stop_equal (const cairo_color_stop_t *color_a, + const cairo_color_stop_t *color_b) cairo_pure; + +cairo_private cairo_content_t +_cairo_color_get_content (const cairo_color_t *color) cairo_pure; + +/* cairo-font-face.c */ + +extern const cairo_private cairo_font_face_t _cairo_font_face_nil; +extern const cairo_private cairo_font_face_t _cairo_font_face_nil_file_not_found; + +cairo_private void +_cairo_font_face_init (cairo_font_face_t *font_face, + const cairo_font_face_backend_t *backend); + +cairo_private cairo_bool_t +_cairo_font_face_destroy (void *abstract_face); + +cairo_private cairo_status_t +_cairo_font_face_set_error (cairo_font_face_t *font_face, + cairo_status_t status); + +cairo_private void +_cairo_unscaled_font_init (cairo_unscaled_font_t *font, + const cairo_unscaled_font_backend_t *backend); + +cairo_private_no_warn cairo_unscaled_font_t * +_cairo_unscaled_font_reference (cairo_unscaled_font_t *font); + +cairo_private void +_cairo_unscaled_font_destroy (cairo_unscaled_font_t *font); + +/* cairo-font-face-twin.c */ + +cairo_private cairo_font_face_t * +_cairo_font_face_twin_create_fallback (void); + +cairo_private cairo_status_t +_cairo_font_face_twin_create_for_toy (cairo_toy_font_face_t *toy_face, + cairo_font_face_t **font_face); + +/* cairo-font-face-twin-data.c */ + +extern const cairo_private int8_t _cairo_twin_outlines[]; +extern const cairo_private uint16_t _cairo_twin_charmap[128]; + +/* cairo-font-options.c */ + +cairo_private void +_cairo_font_options_init_default (cairo_font_options_t *options); + +cairo_private void +_cairo_font_options_init_copy (cairo_font_options_t *options, + const cairo_font_options_t *other); + +cairo_private void +_cairo_font_options_set_lcd_filter (cairo_font_options_t *options, + cairo_lcd_filter_t lcd_filter); + +cairo_private cairo_lcd_filter_t +_cairo_font_options_get_lcd_filter (const cairo_font_options_t *options); + +cairo_private void +_cairo_font_options_set_round_glyph_positions (cairo_font_options_t *options, + cairo_round_glyph_positions_t round); + +cairo_private cairo_round_glyph_positions_t +_cairo_font_options_get_round_glyph_positions (const cairo_font_options_t *options); + +/* cairo-hull.c */ +cairo_private cairo_status_t +_cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices); + +/* cairo-lzw.c */ +cairo_private unsigned char * +_cairo_lzw_compress (unsigned char *data, unsigned long *size_in_out); + +/* cairo-misc.c */ +cairo_private cairo_status_t +_cairo_validate_text_clusters (const char *utf8, + int utf8_len, + const cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags); + +cairo_private cairo_status_t +_cairo_intern_string (const char **str_inout, int len); + +cairo_private void +_cairo_intern_string_reset_static_data (void); + +cairo_private const char * +cairo_get_locale_decimal_point (void); + +/* cairo-path-fixed.c */ +cairo_private cairo_path_fixed_t * +_cairo_path_fixed_create (void); + +cairo_private void +_cairo_path_fixed_init (cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_path_fixed_init_copy (cairo_path_fixed_t *path, + const cairo_path_fixed_t *other); + +cairo_private void +_cairo_path_fixed_fini (cairo_path_fixed_t *path); + +cairo_private void +_cairo_path_fixed_destroy (cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_path_fixed_move_to (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y); + +cairo_private void +_cairo_path_fixed_new_sub_path (cairo_path_fixed_t *path); + +cairo_private cairo_status_t +_cairo_path_fixed_rel_move_to (cairo_path_fixed_t *path, + cairo_fixed_t dx, + cairo_fixed_t dy); + +cairo_private cairo_status_t +_cairo_path_fixed_line_to (cairo_path_fixed_t *path, + cairo_fixed_t x, + cairo_fixed_t y); + +cairo_private cairo_status_t +_cairo_path_fixed_rel_line_to (cairo_path_fixed_t *path, + cairo_fixed_t dx, + cairo_fixed_t dy); + +cairo_private cairo_status_t +_cairo_path_fixed_curve_to (cairo_path_fixed_t *path, + cairo_fixed_t x0, cairo_fixed_t y0, + cairo_fixed_t x1, cairo_fixed_t y1, + cairo_fixed_t x2, cairo_fixed_t y2); + +cairo_private cairo_status_t +_cairo_path_fixed_rel_curve_to (cairo_path_fixed_t *path, + cairo_fixed_t dx0, cairo_fixed_t dy0, + cairo_fixed_t dx1, cairo_fixed_t dy1, + cairo_fixed_t dx2, cairo_fixed_t dy2); + +cairo_private cairo_status_t +_cairo_path_fixed_close_path (cairo_path_fixed_t *path); + +cairo_private cairo_bool_t +_cairo_path_fixed_get_current_point (cairo_path_fixed_t *path, + cairo_fixed_t *x, + cairo_fixed_t *y); + +typedef cairo_status_t +(cairo_path_fixed_move_to_func_t) (void *closure, + const cairo_point_t *point); + +typedef cairo_status_t +(cairo_path_fixed_line_to_func_t) (void *closure, + const cairo_point_t *point); + +typedef cairo_status_t +(cairo_path_fixed_curve_to_func_t) (void *closure, + const cairo_point_t *p0, + const cairo_point_t *p1, + const cairo_point_t *p2); + +typedef cairo_status_t +(cairo_path_fixed_close_path_func_t) (void *closure); + +cairo_private cairo_status_t +_cairo_path_fixed_interpret (const cairo_path_fixed_t *path, + cairo_path_fixed_move_to_func_t *move_to, + cairo_path_fixed_line_to_func_t *line_to, + cairo_path_fixed_curve_to_func_t *curve_to, + cairo_path_fixed_close_path_func_t *close_path, + void *closure); + +cairo_private cairo_status_t +_cairo_path_fixed_interpret_flat (const cairo_path_fixed_t *path, + cairo_path_fixed_move_to_func_t *move_to, + cairo_path_fixed_line_to_func_t *line_to, + cairo_path_fixed_close_path_func_t *close_path, + void *closure, + double tolerance); + + +cairo_private cairo_bool_t +_cairo_path_bounder_extents (const cairo_path_fixed_t *path, + cairo_box_t *box); + +cairo_private cairo_bool_t +_cairo_path_fixed_extents (const cairo_path_fixed_t *path, + cairo_box_t *box); + +cairo_private void +_cairo_path_fixed_approximate_clip_extents (const cairo_path_fixed_t *path, + cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_path_fixed_approximate_fill_extents (const cairo_path_fixed_t *path, + cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_path_fixed_fill_extents (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_path_fixed_approximate_stroke_extents (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_rectangle_int_t *extents); + +cairo_private void +_cairo_path_fixed_transform (cairo_path_fixed_t *path, + const cairo_matrix_t *matrix); + +cairo_private cairo_bool_t +_cairo_path_fixed_is_box (const cairo_path_fixed_t *path, + cairo_box_t *box); + +cairo_private cairo_bool_t +_cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path, + cairo_box_t *box); + +/* cairo-path-in-fill.c */ +cairo_private cairo_bool_t +_cairo_path_fixed_in_fill (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + double x, + double y); + +/* cairo-path-fill.c */ +cairo_private cairo_status_t +_cairo_path_fixed_fill_to_polygon (const cairo_path_fixed_t *path, + double tolerance, + cairo_polygon_t *polygon); + +cairo_private cairo_status_t +_cairo_path_fixed_fill_rectilinear_to_polygon (const cairo_path_fixed_t *path, + cairo_antialias_t antialias, + cairo_polygon_t *polygon); + +cairo_private cairo_status_t +_cairo_path_fixed_fill_rectilinear_to_boxes (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + cairo_antialias_t antialias, + cairo_boxes_t *boxes); + +cairo_private cairo_region_t * +_cairo_path_fixed_fill_rectilinear_to_region (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + const cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_path_fixed_fill_to_traps (const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_traps_t *traps); + +/* cairo-path-stroke.c */ +cairo_private cairo_status_t +_cairo_path_fixed_stroke_to_polygon (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_polygon_t *polygon); + +cairo_private cairo_int_status_t +_cairo_path_fixed_stroke_to_tristrip (const cairo_path_fixed_t *path, + const cairo_stroke_style_t*style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_tristrip_t *strip); + +cairo_private cairo_status_t +_cairo_path_fixed_stroke_dashed_to_polygon (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_polygon_t *polygon); + +cairo_private cairo_int_status_t +_cairo_path_fixed_stroke_rectilinear_to_boxes (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + cairo_antialias_t antialias, + cairo_boxes_t *boxes); + +cairo_private cairo_int_status_t +_cairo_path_fixed_stroke_to_traps (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_traps_t *traps); + +cairo_private cairo_int_status_t +_cairo_path_fixed_stroke_polygon_to_traps (const cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_traps_t *traps); + +cairo_private cairo_status_t +_cairo_path_fixed_stroke_to_shaper (cairo_path_fixed_t *path, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_status_t (*add_triangle) (void *closure, + const cairo_point_t triangle[3]), + cairo_status_t (*add_triangle_fan) (void *closure, + const cairo_point_t *midpt, + const cairo_point_t *points, + int npoints), + cairo_status_t (*add_quad) (void *closure, + const cairo_point_t quad[4]), + void *closure); + +/* cairo-scaled-font.c */ + +cairo_private void +_cairo_scaled_font_freeze_cache (cairo_scaled_font_t *scaled_font); + +cairo_private void +_cairo_scaled_font_thaw_cache (cairo_scaled_font_t *scaled_font); + +cairo_private void +_cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font); + +cairo_private cairo_status_t +_cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, + cairo_status_t status); + +cairo_private cairo_scaled_font_t * +_cairo_scaled_font_create_in_error (cairo_status_t status); + +cairo_private void +_cairo_scaled_font_reset_static_data (void); + +cairo_private cairo_status_t +_cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t *scaled_font); + +cairo_private void +_cairo_scaled_font_unregister_placeholder_and_lock_font_map (cairo_scaled_font_t *scaled_font); + +cairo_private cairo_status_t +_cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, + cairo_font_face_t *font_face, + const cairo_matrix_t *font_matrix, + const cairo_matrix_t *ctm, + const cairo_font_options_t *options, + const cairo_scaled_font_backend_t *backend); + +cairo_private cairo_status_t +_cairo_scaled_font_set_metrics (cairo_scaled_font_t *scaled_font, + cairo_font_extents_t *fs_metrics); + +/* This should only be called on an error path by a scaled_font constructor */ +cairo_private void +_cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font); + +cairo_private cairo_status_t +_cairo_scaled_font_font_extents (cairo_scaled_font_t *scaled_font, + cairo_font_extents_t *extents); + +cairo_private cairo_status_t +_cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_rectangle_int_t *extents, + cairo_bool_t *overlap); + +cairo_private cairo_bool_t +_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_rectangle_int_t *extents); + +cairo_private cairo_status_t +_cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_surface_t *surface, + int source_x, + int source_y, + int dest_x, + int dest_y, + unsigned int width, + unsigned int height, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_region_t *clip_region); + +cairo_private cairo_status_t +_cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font, + const cairo_glyph_t *glyphs, + int num_glyphs, + cairo_path_fixed_t *path); + +cairo_private void +_cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_text_extents_t *fs_metrics); + +cairo_private void +_cairo_scaled_glyph_set_surface (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_image_surface_t *surface); + +cairo_private void +_cairo_scaled_glyph_set_path (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_path_fixed_t *path); + +cairo_private void +_cairo_scaled_glyph_set_recording_surface (cairo_scaled_glyph_t *scaled_glyph, + cairo_scaled_font_t *scaled_font, + cairo_surface_t *recording_surface); + +cairo_private cairo_int_status_t +_cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font, + unsigned long index, + cairo_scaled_glyph_info_t info, + cairo_scaled_glyph_t **scaled_glyph_ret); + +cairo_private double +_cairo_scaled_font_get_max_scale (cairo_scaled_font_t *scaled_font); + +cairo_private void +_cairo_scaled_font_map_destroy (void); + +/* cairo-stroke-style.c */ + +cairo_private void +_cairo_stroke_style_init (cairo_stroke_style_t *style); + +cairo_private cairo_status_t +_cairo_stroke_style_init_copy (cairo_stroke_style_t *style, + const cairo_stroke_style_t *other); + +cairo_private void +_cairo_stroke_style_fini (cairo_stroke_style_t *style); + +cairo_private void +_cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm, + double *dx, double *dy); +cairo_private void +_cairo_stroke_style_max_line_distance_from_path (const cairo_stroke_style_t *style, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm, + double *dx, double *dy); + +cairo_private void +_cairo_stroke_style_max_join_distance_from_path (const cairo_stroke_style_t *style, + const cairo_path_fixed_t *path, + const cairo_matrix_t *ctm, + double *dx, double *dy); + +cairo_private double +_cairo_stroke_style_dash_period (const cairo_stroke_style_t *style); + +cairo_private double +_cairo_stroke_style_dash_stroked (const cairo_stroke_style_t *style); + +cairo_private cairo_bool_t +_cairo_stroke_style_dash_can_approximate (const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + double tolerance); + +cairo_private void +_cairo_stroke_style_dash_approximate (const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + double tolerance, + double *dash_offset, + double *dashes, + unsigned int *num_dashes); + + +/* cairo-surface.c */ + +cairo_private cairo_status_t +_cairo_surface_copy_mime_data (cairo_surface_t *dst, + cairo_surface_t *src); + +cairo_private_no_warn cairo_int_status_t +_cairo_surface_set_error (cairo_surface_t *surface, + cairo_int_status_t status); + +cairo_private void +_cairo_surface_set_resolution (cairo_surface_t *surface, + double x_res, + double y_res); + +cairo_private cairo_surface_t * +_cairo_surface_create_for_rectangle_int (cairo_surface_t *target, + const cairo_rectangle_int_t *extents); + +cairo_private cairo_surface_t * +_cairo_surface_create_scratch (cairo_surface_t *other, + cairo_content_t content, + int width, + int height, + const cairo_color_t *color); + +cairo_private void +_cairo_surface_init (cairo_surface_t *surface, + const cairo_surface_backend_t *backend, + cairo_device_t *device, + cairo_content_t content); + +cairo_private void +_cairo_surface_set_font_options (cairo_surface_t *surface, + cairo_font_options_t *options); + +cairo_private cairo_status_t +_cairo_surface_paint (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip); + +cairo_private cairo_image_surface_t * +_cairo_surface_map_to_image (cairo_surface_t *surface, + const cairo_rectangle_int_t *extents); + +cairo_private_no_warn cairo_int_status_t +_cairo_surface_unmap_image (cairo_surface_t *surface, + cairo_image_surface_t *image); + +cairo_private cairo_status_t +_cairo_surface_mask (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_fill_stroke (cairo_surface_t *surface, + cairo_operator_t fill_op, + const cairo_pattern_t *fill_source, + cairo_fill_rule_t fill_rule, + double fill_tolerance, + cairo_antialias_t fill_antialias, + cairo_path_fixed_t *path, + cairo_operator_t stroke_op, + const cairo_pattern_t *stroke_source, + const cairo_stroke_style_t *stroke_style, + const cairo_matrix_t *stroke_ctm, + const cairo_matrix_t *stroke_ctm_inverse, + double stroke_tolerance, + cairo_antialias_t stroke_antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_stroke (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_fill (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_show_text_glyphs (cairo_surface_t *surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_surface_acquire_source_image (cairo_surface_t *surface, + cairo_image_surface_t **image_out, + void **image_extra); + +cairo_private void +_cairo_surface_release_source_image (cairo_surface_t *surface, + cairo_image_surface_t *image, + void *image_extra); + +cairo_private cairo_surface_t * +_cairo_surface_snapshot (cairo_surface_t *surface); + +cairo_private void +_cairo_surface_attach_snapshot (cairo_surface_t *surface, + cairo_surface_t *snapshot, + cairo_surface_func_t detach_func); + +cairo_private cairo_surface_t * +_cairo_surface_has_snapshot (cairo_surface_t *surface, + const cairo_surface_backend_t *backend); + +cairo_private void +_cairo_surface_detach_snapshot (cairo_surface_t *snapshot); + +cairo_private cairo_status_t +_cairo_surface_begin_modification (cairo_surface_t *surface); + +cairo_private_no_warn cairo_bool_t +_cairo_surface_get_extents (cairo_surface_t *surface, + cairo_rectangle_int_t *extents); + +cairo_private cairo_bool_t +_cairo_surface_has_device_transform (cairo_surface_t *surface) cairo_pure; + +cairo_private void +_cairo_surface_release_device_reference (cairo_surface_t *surface); + +/* cairo-image-surface.c */ + +/* XXX: In cairo 1.2.0 we added a new %CAIRO_FORMAT_RGB16_565 but + * neglected to adjust this macro. The net effect is that it's + * impossible to externally create an image surface with this + * format. This is perhaps a good thing since we also neglected to fix + * up things like cairo_surface_write_to_png() for the new format + * (-Wswitch-enum will tell you where). Is it obvious that format was + * added in haste? + * + * The reason for the new format was to allow the xlib backend to be + * used on X servers with a 565 visual. So the new format did its job + * for that, even without being considered "valid" for the sake of + * things like cairo_image_surface_create(). + * + * Since 1.2.0 we ran into the same situtation with X servers with BGR + * visuals. This time we invented #cairo_internal_format_t instead, + * (see it for more discussion). + * + * The punchline is that %CAIRO_FORMAT_VALID must not conside any + * internal format to be valid. Also we need to decide if the + * RGB16_565 should be moved to instead be an internal format. If so, + * this macro need not change for it. (We probably will need to leave + * an RGB16_565 value in the header files for the sake of code that + * might have that value in it.) + * + * If we do decide to start fully supporting RGB16_565 as an external + * format, then %CAIRO_FORMAT_VALID needs to be adjusted to include + * it. But that should not happen before all necessary code is fixed + * to support it (at least cairo_surface_write_to_png() and a few spots + * in cairo-xlib-surface.c--again see -Wswitch-enum). + */ +#define CAIRO_FORMAT_VALID(format) ((format) >= CAIRO_FORMAT_ARGB32 && \ + (format) <= CAIRO_FORMAT_RGB30) + +/* pixman-required stride alignment in bytes. */ +#define CAIRO_STRIDE_ALIGNMENT (sizeof (uint32_t)) +#define CAIRO_STRIDE_FOR_WIDTH_BPP(w,bpp) \ + ((((bpp)*(w)+7)/8 + CAIRO_STRIDE_ALIGNMENT-1) & -CAIRO_STRIDE_ALIGNMENT) + +#define CAIRO_CONTENT_VALID(content) ((content) && \ + (((content) & ~(CAIRO_CONTENT_COLOR | \ + CAIRO_CONTENT_ALPHA | \ + CAIRO_CONTENT_COLOR_ALPHA))\ + == 0)) + +cairo_private int +_cairo_format_bits_per_pixel (cairo_format_t format) cairo_const; + +cairo_private cairo_format_t +_cairo_format_from_content (cairo_content_t content) cairo_const; + +cairo_private cairo_format_t +_cairo_format_from_pixman_format (pixman_format_code_t pixman_format); + +cairo_private cairo_content_t +_cairo_content_from_format (cairo_format_t format) cairo_const; + +cairo_private cairo_content_t +_cairo_content_from_pixman_format (pixman_format_code_t pixman_format); + +cairo_private cairo_surface_t * +_cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image, + pixman_format_code_t pixman_format); + +cairo_private pixman_format_code_t +_cairo_format_to_pixman_format_code (cairo_format_t format); + +cairo_private cairo_bool_t +_pixman_format_from_masks (cairo_format_masks_t *masks, + pixman_format_code_t *format_ret); + +cairo_private cairo_bool_t +_pixman_format_to_masks (pixman_format_code_t pixman_format, + cairo_format_masks_t *masks); + +cairo_private void +_cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, + cairo_scaled_glyph_t *scaled_glyph); + +cairo_private void +_cairo_image_reset_static_data (void); + +cairo_private cairo_surface_t * +_cairo_image_surface_create_with_pixman_format (unsigned char *data, + pixman_format_code_t pixman_format, + int width, + int height, + int stride); + +cairo_private cairo_surface_t * +_cairo_image_surface_create_with_content (cairo_content_t content, + int width, + int height); + +cairo_private void +_cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface); + +cairo_private cairo_image_surface_t * +_cairo_image_surface_coerce (cairo_image_surface_t *surface); + +cairo_private cairo_image_surface_t * +_cairo_image_surface_coerce_to_format (cairo_image_surface_t *surface, + cairo_format_t format); + +cairo_private cairo_image_transparency_t +_cairo_image_analyze_transparency (cairo_image_surface_t *image); + +cairo_private cairo_image_color_t +_cairo_image_analyze_color (cairo_image_surface_t *image); + +/* cairo-pen.c */ +cairo_private int +_cairo_pen_vertices_needed (double tolerance, + double radius, + const cairo_matrix_t *matrix); + +cairo_private cairo_status_t +_cairo_pen_init (cairo_pen_t *pen, + double radius, + double tolerance, + const cairo_matrix_t *ctm); + +cairo_private void +_cairo_pen_init_empty (cairo_pen_t *pen); + +cairo_private cairo_status_t +_cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other); + +cairo_private void +_cairo_pen_fini (cairo_pen_t *pen); + +cairo_private cairo_status_t +_cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points); + +cairo_private int +_cairo_pen_find_active_cw_vertex_index (const cairo_pen_t *pen, + const cairo_slope_t *slope); + +cairo_private int +_cairo_pen_find_active_ccw_vertex_index (const cairo_pen_t *pen, + const cairo_slope_t *slope); + +cairo_private void +_cairo_pen_find_active_cw_vertices (const cairo_pen_t *pen, + const cairo_slope_t *in, + const cairo_slope_t *out, + int *start, int *stop); + +cairo_private void +_cairo_pen_find_active_ccw_vertices (const cairo_pen_t *pen, + const cairo_slope_t *in, + const cairo_slope_t *out, + int *start, int *stop); + +/* cairo-polygon.c */ +cairo_private void +_cairo_polygon_init (cairo_polygon_t *polygon, + const cairo_box_t *boxes, + int num_boxes); + +cairo_private void +_cairo_polygon_init_with_clip (cairo_polygon_t *polygon, + const cairo_clip_t *clip); + +cairo_private cairo_status_t +_cairo_polygon_init_boxes (cairo_polygon_t *polygon, + const cairo_boxes_t *boxes); + +cairo_private cairo_status_t +_cairo_polygon_init_box_array (cairo_polygon_t *polygon, + cairo_box_t *boxes, + int num_boxes); + +cairo_private void +_cairo_polygon_limit (cairo_polygon_t *polygon, + const cairo_box_t *limits, + int num_limits); + +cairo_private void +_cairo_polygon_limit_to_clip (cairo_polygon_t *polygon, + const cairo_clip_t *clip); + +cairo_private void +_cairo_polygon_fini (cairo_polygon_t *polygon); + +cairo_private_no_warn cairo_status_t +_cairo_polygon_add_line (cairo_polygon_t *polygon, + const cairo_line_t *line, + int top, int bottom, + int dir); + +cairo_private_no_warn cairo_status_t +_cairo_polygon_add_external_edge (void *polygon, + const cairo_point_t *p1, + const cairo_point_t *p2); + +cairo_private_no_warn cairo_status_t +_cairo_polygon_add_contour (cairo_polygon_t *polygon, + const cairo_contour_t *contour); + +cairo_private void +_cairo_polygon_translate (cairo_polygon_t *polygon, int dx, int dy); + +cairo_private cairo_status_t +_cairo_polygon_reduce (cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_status_t +_cairo_polygon_intersect (cairo_polygon_t *a, int winding_a, + cairo_polygon_t *b, int winding_b); + +cairo_private cairo_status_t +_cairo_polygon_intersect_with_boxes (cairo_polygon_t *polygon, + cairo_fill_rule_t *winding, + cairo_box_t *boxes, + int num_boxes); + +static inline cairo_bool_t +_cairo_polygon_is_empty (const cairo_polygon_t *polygon) +{ + return + polygon->num_edges == 0 || + polygon->extents.p2.x <= polygon->extents.p1.x; +} + +#define _cairo_polygon_status(P) ((cairo_polygon_t *) (P))->status + +/* cairo-spline.c */ +cairo_private cairo_bool_t +_cairo_spline_init (cairo_spline_t *spline, + cairo_spline_add_point_func_t add_point_func, + void *closure, + const cairo_point_t *a, const cairo_point_t *b, + const cairo_point_t *c, const cairo_point_t *d); + +cairo_private cairo_status_t +_cairo_spline_decompose (cairo_spline_t *spline, double tolerance); + +cairo_private cairo_status_t +_cairo_spline_bound (cairo_spline_add_point_func_t add_point_func, + void *closure, + const cairo_point_t *p0, const cairo_point_t *p1, + const cairo_point_t *p2, const cairo_point_t *p3); + +/* cairo-matrix.c */ +cairo_private void +_cairo_matrix_get_affine (const cairo_matrix_t *matrix, + double *xx, double *yx, + double *xy, double *yy, + double *x0, double *y0); + +cairo_private void +_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix, + double *x1, double *y1, + double *x2, double *y2, + cairo_bool_t *is_tight); + +cairo_private void +_cairo_matrix_transform_bounding_box_fixed (const cairo_matrix_t *matrix, + cairo_box_t *bbox, + cairo_bool_t *is_tight); + +cairo_private cairo_bool_t +_cairo_matrix_is_invertible (const cairo_matrix_t *matrix) cairo_pure; + +cairo_private cairo_bool_t +_cairo_matrix_is_scale_0 (const cairo_matrix_t *matrix) cairo_pure; + +cairo_private double +_cairo_matrix_compute_determinant (const cairo_matrix_t *matrix) cairo_pure; + +cairo_private cairo_status_t +_cairo_matrix_compute_basis_scale_factors (const cairo_matrix_t *matrix, + double *sx, double *sy, int x_major); + +static inline cairo_bool_t +_cairo_matrix_is_identity (const cairo_matrix_t *matrix) +{ + return (matrix->xx == 1.0 && matrix->yx == 0.0 && + matrix->xy == 0.0 && matrix->yy == 1.0 && + matrix->x0 == 0.0 && matrix->y0 == 0.0); +} + +static inline cairo_bool_t +_cairo_matrix_is_translation (const cairo_matrix_t *matrix) +{ + return (matrix->xx == 1.0 && matrix->yx == 0.0 && + matrix->xy == 0.0 && matrix->yy == 1.0); +} + +static inline cairo_bool_t +_cairo_matrix_is_scale (const cairo_matrix_t *matrix) +{ + return matrix->yx == 0.0 && matrix->xy == 0.0; +} + +cairo_private cairo_bool_t +_cairo_matrix_is_integer_translation(const cairo_matrix_t *matrix, + int *itx, int *ity); + +cairo_private cairo_bool_t +_cairo_matrix_has_unity_scale (const cairo_matrix_t *matrix); + +cairo_private cairo_bool_t +_cairo_matrix_is_pixel_exact (const cairo_matrix_t *matrix) cairo_pure; + +cairo_private double +_cairo_matrix_transformed_circle_major_axis (const cairo_matrix_t *matrix, + double radius) cairo_pure; + +cairo_private cairo_bool_t +_cairo_matrix_is_pixman_translation (const cairo_matrix_t *matrix, + cairo_filter_t filter, + int *out_x_offset, + int *out_y_offset); + +cairo_private cairo_status_t +_cairo_matrix_to_pixman_matrix_offset (const cairo_matrix_t *matrix, + cairo_filter_t filter, + double xc, + double yc, + pixman_transform_t *out_transform, + int *out_x_offset, + int *out_y_offset); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_rectilinear_polygon (cairo_traps_t *traps, + const cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t *traps, + const cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_traps (cairo_traps_t *traps, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_rectangular_traps (cairo_traps_t *traps, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_boxes (const cairo_boxes_t *in, + cairo_fill_rule_t fill_rule, + cairo_boxes_t *out); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_rectilinear_traps (cairo_traps_t *traps, + cairo_fill_rule_t fill_rule); + +cairo_private cairo_status_t +_cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (const cairo_polygon_t *polygon, + cairo_fill_rule_t fill_rule, + cairo_boxes_t *boxes); + +cairo_private void +_cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps, + cairo_trapezoid_t *src_traps, + int num_traps, + double tx, double ty, + double sx, double sy); + +#if CAIRO_HAS_DRM_SURFACE + +cairo_private void +_cairo_drm_device_reset_static_data (void); + +#endif + +cairo_private void +_cairo_clip_reset_static_data (void); + +cairo_private void +_cairo_pattern_reset_static_data (void); + +/* cairo-unicode.c */ + +cairo_private int +_cairo_utf8_get_char_validated (const char *p, + uint32_t *unicode); + +cairo_private cairo_status_t +_cairo_utf8_to_ucs4 (const char *str, + int len, + uint32_t **result, + int *items_written); + +cairo_private int +_cairo_ucs4_to_utf8 (uint32_t unicode, + char *utf8); + +#if CAIRO_HAS_WIN32_FONT || CAIRO_HAS_QUARTZ_FONT || CAIRO_HAS_PDF_OPERATORS +# define CAIRO_HAS_UTF8_TO_UTF16 1 +#endif +#if CAIRO_HAS_UTF8_TO_UTF16 +cairo_private cairo_status_t +_cairo_utf8_to_utf16 (const char *str, + int len, + uint16_t **result, + int *items_written); +#endif + +cairo_private void +_cairo_matrix_multiply (cairo_matrix_t *r, + const cairo_matrix_t *a, + const cairo_matrix_t *b); + +/* cairo-observer.c */ + +cairo_private void +_cairo_observers_notify (cairo_list_t *observers, void *arg); + +/* Avoid unnecessary PLT entries. */ +slim_hidden_proto (cairo_clip_preserve); +slim_hidden_proto (cairo_close_path); +slim_hidden_proto (cairo_create); +slim_hidden_proto (cairo_curve_to); +slim_hidden_proto (cairo_destroy); +slim_hidden_proto (cairo_fill_preserve); +slim_hidden_proto (cairo_font_face_destroy); +slim_hidden_proto (cairo_font_face_get_user_data); +slim_hidden_proto_no_warn (cairo_font_face_reference); +slim_hidden_proto (cairo_font_face_set_user_data); +slim_hidden_proto (cairo_font_options_equal); +slim_hidden_proto (cairo_font_options_hash); +slim_hidden_proto (cairo_font_options_merge); +slim_hidden_proto (cairo_font_options_set_antialias); +slim_hidden_proto (cairo_font_options_set_hint_metrics); +slim_hidden_proto (cairo_font_options_set_hint_style); +slim_hidden_proto (cairo_font_options_set_subpixel_order); +slim_hidden_proto (cairo_font_options_status); +slim_hidden_proto (cairo_format_stride_for_width); +slim_hidden_proto (cairo_get_current_point); +slim_hidden_proto (cairo_get_line_width); +slim_hidden_proto (cairo_get_matrix); +slim_hidden_proto (cairo_get_scaled_font); +slim_hidden_proto (cairo_get_target); +slim_hidden_proto (cairo_get_tolerance); +slim_hidden_proto (cairo_glyph_allocate); +slim_hidden_proto (cairo_glyph_free); +slim_hidden_proto (cairo_image_surface_create); +slim_hidden_proto (cairo_image_surface_create_for_data); +slim_hidden_proto (cairo_image_surface_get_data); +slim_hidden_proto (cairo_image_surface_get_format); +slim_hidden_proto (cairo_image_surface_get_height); +slim_hidden_proto (cairo_image_surface_get_stride); +slim_hidden_proto (cairo_image_surface_get_width); +slim_hidden_proto (cairo_line_to); +slim_hidden_proto (cairo_mask); +slim_hidden_proto (cairo_matrix_init); +slim_hidden_proto (cairo_matrix_init_identity); +slim_hidden_proto (cairo_matrix_init_rotate); +slim_hidden_proto (cairo_matrix_init_scale); +slim_hidden_proto (cairo_matrix_init_translate); +slim_hidden_proto (cairo_matrix_invert); +slim_hidden_proto (cairo_matrix_multiply); +slim_hidden_proto (cairo_matrix_scale); +slim_hidden_proto (cairo_matrix_transform_distance); +slim_hidden_proto (cairo_matrix_transform_point); +slim_hidden_proto (cairo_matrix_translate); +slim_hidden_proto (cairo_move_to); +slim_hidden_proto (cairo_new_path); +slim_hidden_proto (cairo_paint); +slim_hidden_proto (cairo_pattern_add_color_stop_rgba); +slim_hidden_proto (cairo_pattern_create_for_surface); +slim_hidden_proto (cairo_pattern_create_rgb); +slim_hidden_proto (cairo_pattern_create_rgba); +slim_hidden_proto (cairo_pattern_destroy); +slim_hidden_proto (cairo_pattern_get_extend); +slim_hidden_proto (cairo_mesh_pattern_curve_to); +slim_hidden_proto (cairo_mesh_pattern_get_control_point); +slim_hidden_proto (cairo_mesh_pattern_get_corner_color_rgba); +slim_hidden_proto (cairo_mesh_pattern_get_patch_count); +slim_hidden_proto (cairo_mesh_pattern_get_path); +slim_hidden_proto (cairo_mesh_pattern_line_to); +slim_hidden_proto (cairo_mesh_pattern_move_to); +slim_hidden_proto (cairo_mesh_pattern_set_corner_color_rgba); +slim_hidden_proto_no_warn (cairo_pattern_reference); +slim_hidden_proto (cairo_pattern_set_matrix); +slim_hidden_proto (cairo_pop_group); +slim_hidden_proto (cairo_push_group_with_content); +slim_hidden_proto_no_warn (cairo_path_destroy); +slim_hidden_proto (cairo_recording_surface_create); +slim_hidden_proto (cairo_rel_line_to); +slim_hidden_proto (cairo_restore); +slim_hidden_proto (cairo_save); +slim_hidden_proto (cairo_scale); +slim_hidden_proto (cairo_scaled_font_create); +slim_hidden_proto (cairo_scaled_font_destroy); +slim_hidden_proto (cairo_scaled_font_extents); +slim_hidden_proto (cairo_scaled_font_get_ctm); +slim_hidden_proto (cairo_scaled_font_get_font_face); +slim_hidden_proto (cairo_scaled_font_get_font_matrix); +slim_hidden_proto (cairo_scaled_font_get_font_options); +slim_hidden_proto (cairo_scaled_font_glyph_extents); +slim_hidden_proto_no_warn (cairo_scaled_font_reference); +slim_hidden_proto (cairo_scaled_font_status); +slim_hidden_proto (cairo_scaled_font_get_user_data); +slim_hidden_proto (cairo_scaled_font_set_user_data); +slim_hidden_proto (cairo_scaled_font_text_to_glyphs); +slim_hidden_proto (cairo_set_font_matrix); +slim_hidden_proto (cairo_set_font_options); +slim_hidden_proto (cairo_set_font_size); +slim_hidden_proto (cairo_set_line_cap); +slim_hidden_proto (cairo_set_line_join); +slim_hidden_proto (cairo_set_line_width); +slim_hidden_proto (cairo_set_matrix); +slim_hidden_proto (cairo_set_operator); +slim_hidden_proto (cairo_set_source); +slim_hidden_proto (cairo_set_source_rgb); +slim_hidden_proto (cairo_set_source_surface); +slim_hidden_proto (cairo_set_tolerance); +slim_hidden_proto (cairo_status); +slim_hidden_proto (cairo_stroke); +slim_hidden_proto (cairo_stroke_preserve); +slim_hidden_proto (cairo_surface_copy_page); +slim_hidden_proto (cairo_surface_create_similar_image); +slim_hidden_proto (cairo_surface_destroy); +slim_hidden_proto (cairo_surface_finish); +slim_hidden_proto (cairo_surface_flush); +slim_hidden_proto (cairo_surface_get_device_offset); +slim_hidden_proto (cairo_surface_get_device_scale); +slim_hidden_proto (cairo_surface_get_font_options); +slim_hidden_proto (cairo_surface_get_mime_data); +slim_hidden_proto (cairo_surface_has_show_text_glyphs); +slim_hidden_proto (cairo_surface_mark_dirty); +slim_hidden_proto (cairo_surface_mark_dirty_rectangle); +slim_hidden_proto_no_warn (cairo_surface_reference); +slim_hidden_proto (cairo_surface_set_device_offset); +slim_hidden_proto (cairo_surface_set_device_scale); +slim_hidden_proto (cairo_surface_set_fallback_resolution); +slim_hidden_proto (cairo_surface_set_mime_data); +slim_hidden_proto (cairo_surface_show_page); +slim_hidden_proto (cairo_surface_status); +slim_hidden_proto (cairo_surface_supports_mime_type); +slim_hidden_proto (cairo_text_cluster_allocate); +slim_hidden_proto (cairo_text_cluster_free); +slim_hidden_proto (cairo_toy_font_face_create); +slim_hidden_proto (cairo_toy_font_face_get_slant); +slim_hidden_proto (cairo_toy_font_face_get_weight); +slim_hidden_proto (cairo_translate); +slim_hidden_proto (cairo_transform); +slim_hidden_proto (cairo_user_font_face_create); +slim_hidden_proto (cairo_user_font_face_set_init_func); +slim_hidden_proto (cairo_user_font_face_set_render_glyph_func); +slim_hidden_proto (cairo_user_font_face_set_unicode_to_glyph_func); +slim_hidden_proto (cairo_device_to_user); +slim_hidden_proto (cairo_user_to_device); +slim_hidden_proto (cairo_user_to_device_distance); +slim_hidden_proto (cairo_version_string); +slim_hidden_proto (cairo_region_create); +slim_hidden_proto (cairo_region_create_rectangle); +slim_hidden_proto (cairo_region_create_rectangles); +slim_hidden_proto (cairo_region_copy); +slim_hidden_proto (cairo_region_reference); +slim_hidden_proto (cairo_region_destroy); +slim_hidden_proto (cairo_region_equal); +slim_hidden_proto (cairo_region_status); +slim_hidden_proto (cairo_region_get_extents); +slim_hidden_proto (cairo_region_num_rectangles); +slim_hidden_proto (cairo_region_get_rectangle); +slim_hidden_proto (cairo_region_is_empty); +slim_hidden_proto (cairo_region_contains_rectangle); +slim_hidden_proto (cairo_region_contains_point); +slim_hidden_proto (cairo_region_translate); +slim_hidden_proto (cairo_region_subtract); +slim_hidden_proto (cairo_region_subtract_rectangle); +slim_hidden_proto (cairo_region_intersect); +slim_hidden_proto (cairo_region_intersect_rectangle); +slim_hidden_proto (cairo_region_union); +slim_hidden_proto (cairo_region_union_rectangle); +slim_hidden_proto (cairo_region_xor); +slim_hidden_proto (cairo_region_xor_rectangle); + +#if CAIRO_HAS_PNG_FUNCTIONS + +slim_hidden_proto (cairo_surface_write_to_png_stream); + +#endif + +CAIRO_END_DECLS + +#include "cairo-mutex-private.h" +#include "cairo-fixed-private.h" +#include "cairo-wideint-private.h" +#include "cairo-malloc-private.h" +#include "cairo-hash-private.h" + +#if HAVE_VALGRIND +#include + +#define VG(x) x + +cairo_private void +_cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface); + +#else + +#define VG(x) +#define _cairo_debug_check_image_surface_is_defined(X) + +#endif + +cairo_private void +_cairo_debug_print_path (FILE *stream, cairo_path_fixed_t *path); + +cairo_private void +_cairo_debug_print_polygon (FILE *stream, cairo_polygon_t *polygon); + +cairo_private void +_cairo_debug_print_traps (FILE *file, const cairo_traps_t *traps); + +cairo_private void +_cairo_debug_print_clip (FILE *stream, const cairo_clip_t *clip); + +#if 0 +#define TRACE(x) fprintf (stderr, "%s: ", __FILE__), fprintf x +#define TRACE_(x) x +#else +#define TRACE(x) +#define TRACE_(x) +#endif + +#endif diff --git a/Build/source/libs/cairo/cairo-src/src/check-def.sh b/Build/source/libs/cairo/cairo-src/src/check-def.sh new file mode 100755 index 00000000000..beefb46a333 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-def.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +if which nm 2>/dev/null >/dev/null; then + : +else + echo "'nm' not found; skipping test" + exit 0 +fi + +test -z "$srcdir" && srcdir=. +test -z "$MAKE" && MAKE=make +stat=0 + +$MAKE check-has-hidden-symbols.i > /dev/null || exit 1 +if tail -1 check-has-hidden-symbols.i | grep CAIRO_HAS_HIDDEN_SYMBOLS >/dev/null; then + echo "Compiler doesn't support symbol visibility; skipping test" + exit 0 +fi + +if [ "`uname -s`" = "Linux" ]; then + get_cairo_syms='( objdump -t "$so" | grep "^[^ ]* [^l.*]*[.]"; objdump -t "$so" | grep "[.]hidden.*\\ /dev/null +for def in $defs; do + lib=`echo "$def" | sed 's/[.]def$//'` + lib=`echo "$lib" | sed 's@.*/@@'` + so=.libs/lib${lib}.so + + test -f "$so" || continue + + echo Checking that $so has the same symbol list as $def + + { + echo EXPORTS + eval $get_cairo_syms | c++filt --no-params | grep -v '^_cairo_test_\|^_fini\|^_init\|^_save[fg]pr\|^_rest[fg]pr\|^_Z\|^__gnu\|^__bss\|^_edata\|^_end' | sort -u + # cheat: copy the last line from the def file! + tail -n1 "$def" + } | diff "$def" - >&2 || stat=1 +done + +exit $stat diff --git a/Build/source/libs/cairo/cairo-src/src/check-doc-syntax.awk b/Build/source/libs/cairo/cairo-src/src/check-doc-syntax.awk new file mode 100755 index 00000000000..1fa8b8d2232 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-doc-syntax.awk @@ -0,0 +1,106 @@ +BEGIN { + name_found = 1 + SECTION_DOC = 0 + PUBLIC_DOC = 1 + PRIVATE_DOC = 2 +} + +function log_msg(severity, msg) +{ + printf "%s (%d): %s: %s %s\n", FILENAME, FNR, severity, doc_name, msg +} + +function log_error(msg) +{ + log_msg("ERROR", msg) +} + +function log_warning(msg) +{ + log_msg("WARNING", msg) +} + +/^\/\*\*$/ { + in_doc = 1 + doc_line = 0 +} + +/^(\/\*\*$| \*[ \t]| \*$| \*\*\/$)/ { + valid_doc = 1 +} + +in_doc { + if (!valid_doc) + log_error("bad line: '" $0 "'") + valid_doc = 0 + + doc_line++ + if (doc_line == 2) { + # new doc name. Did we find the previous one? + # (macros are not expected to be found in the same place as + # their documentation) + if (!name_found && doc_name !~ /CAIRO_/) + log_warning("not found") + doc_name = $2 + if (doc_name ~ /^SECTION:.*$/) { + doc_type = SECTION_DOC + name_found = 1 + } else if (tolower(doc_name) ~ /^cairo_[a-z0-9_]*:$/) { + doc_type = PUBLIC_DOC + name_found = 0 + real_name = substr(doc_name, 1, length(doc_name) - 1) + } else if (tolower(doc_name) ~ /^_[a-z0-9_]*:$/) { + doc_type = PRIVATE_DOC + name_found = 0 + real_name = substr(doc_name, 1, length(doc_name) - 1) + } else { + log_error("invalid doc id (should be 'cairo_...:')") + name_found = 1 + } + } +} + +!in_doc { + regex = "(^|[ \\t\\*])" real_name "([ ;()]|$)" + if ($0 ~ regex) + name_found = 1 +} + +/^ \* Since: ([0-9]*.[0-9]*|TBD)$/ { + if (doc_has_since != 0) { + log_error("Duplicate 'Since' field") + } + doc_has_since = doc_line +} + +/^ \*\*\// { + if (doc_type == PUBLIC_DOC) { + if (!doc_has_since) { + # private types can start with cairo_ + if (doc_name ~ /^cairo_.*_t:$/) + log_warning("missing 'Since' field (is it a private type?)") + else + log_error("missing 'Since' field") + } else if (doc_has_since != doc_line - 1) + log_warning("misplaced 'Since' field (should be right before the end of the comment)") + } else { + if (doc_has_since) + log_warning("'Since' field in non-public element") + } + + in_doc = 0 + doc_has_since = 0 + doc_type = 0 +} + +/\*\// { + if (in_doc) { + in_doc = 0 + log_error("documentation comment not closed with **/") + } +} + +END { + if (!name_found) + log_warning("not found") +} diff --git a/Build/source/libs/cairo/cairo-src/src/check-doc-syntax.sh b/Build/source/libs/cairo/cairo-src/src/check-doc-syntax.sh new file mode 100755 index 00000000000..762a48429b0 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-doc-syntax.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +if grep --version 2>/dev/null | grep GNU >/dev/null; then + : +else + echo "GNU grep not found; skipping test" + exit 0 +fi + +test -z "$srcdir" && srcdir=. +stat=0 + +echo Checking documentation for incorrect syntax + +cd "$srcdir" + +if test "x$SGML_DOCS" = x; then + FILES=$all_cairo_files + if test "x$FILES" = x; then + FILES=`find . -name 'cairo*.h' -or -name 'cairo*.c' -or -name 'cairo*.cpp'` + fi +fi + +enum_regexp="\([^%@']\|^\)\<\(FALSE\|TRUE\|NULL\|CAIRO_[0-9A-Z_]*\)\($\|[^(A-Za-z0-9_]\)" +if test "x$SGML_DOCS" = x; then + enum_regexp='^[^:]*:[/ ][*]\(\|[ \t].*\)'$enum_regexp\($\|[^:]\) +fi +if echo $FILES | xargs grep . /dev/null | sed -e '//,/<\/programlisting>/d' | grep "$enum_regexp" | grep -v '#####'; then + stat=1 + echo Error: some macros in the docs are not prefixed by percent sign. + echo Fix this by searching for the following regexp in the above files: + echo " '$enum_regexp'" +fi >&2 + +type_regexp="\( .*[^#']\| \|^\)\\($\|[^:]$\|[^:].\)" +if test "x$SGML_DOCS" = x; then + type_regexp='^[^:]*:[/ ][*]'$type_regexp +else + type_regexp='\(.'$type_regexp'\)\|\('$type_regexp'.\)' +fi + +if echo $FILES | xargs grep . /dev/null | sed -e '//,/<\/programlisting>/d' | grep -v "@Title" | grep "$type_regexp" | grep -v '#####'; then + stat=1 + echo Error: some type names in the docs are not prefixed by hash sign, + echo neither are the only token in the doc line followed by colon. + echo Fix this by searching for the following regexp in the above files: + echo " '$type_regexp'" +fi >&2 + +func_regexp="\([^#']\|^\)\<\(cairo_[][<>/0-9a-z_]*\>[^][<>(]\)" +if test "x$SGML_DOCS" = x; then + func_regexp='^[^:]*:[/ ][*]\(\|[ \t].*\)'$func_regexp +fi + +# We need to filter out gtk-doc markup errors for program listings. +if echo $FILES | xargs grep . /dev/null | sed -e '//,/<\/programlisting>/d' | grep "$func_regexp" | grep -v '^[^:]*: [*] [a-z_0-9]*:$' | grep -v '#####'; then + stat=1 + echo Error: some function names in the docs are not followed by parentheses. + echo Fix this by searching for the following regexp in the above files: + echo " '$func_regexp'" +fi >&2 + +note_regexp='\' +if echo $FILES | xargs grep "$note_regexp" /dev/null; then + stat=1 + echo Error: some source files contain the string 'NOTE'. + echo Be civil and replace it by 'Note' please. +fi >&2 + +# Only run the syntax checker on the source files (not doc/) +if test -e ./check-doc-syntax.awk; then + if echo $FILES | xargs awk -f ./check-doc-syntax.awk ; then + : + else + stat=1 + fi >&2 +fi + +exit $stat diff --git a/Build/source/libs/cairo/cairo-src/src/check-has-hidden-symbols.c b/Build/source/libs/cairo/cairo-src/src/check-has-hidden-symbols.c new file mode 100644 index 00000000000..12041277692 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-has-hidden-symbols.c @@ -0,0 +1,3 @@ +#include "cairoint.h" + +CAIRO_HAS_HIDDEN_SYMBOLS diff --git a/Build/source/libs/cairo/cairo-src/src/check-headers.sh b/Build/source/libs/cairo/cairo-src/src/check-headers.sh new file mode 100755 index 00000000000..61232954bae --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-headers.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + +echo Checking public headers for missing cairo_public decorators + +cd "$srcdir" +FILES=$all_cairo_headers +if test "x$FILES" = x; then + FILES=`find . -name 'cairo*.h' ! -name '*-private.h' ! -name 'cairoint.h'` +fi + +grep -B 1 '^cairo_.*[ ]\+(' /dev/null $FILES | +awk ' +/^--$/ { context=""; public=0; next; } +/:cairo_.*[ ]+\(/ { if (!public) {print context; print; print "--";} next; } +/-cairo_public.*[ ]/ {public=1;} +{ context=$0; } +' | +sed 's/[.]h-/.h:/' | +grep . >&2 && stat=1 + +exit $stat diff --git a/Build/source/libs/cairo/cairo-src/src/check-link.c b/Build/source/libs/cairo/cairo-src/src/check-link.c new file mode 100644 index 00000000000..66ca1b2413c --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-link.c @@ -0,0 +1,24 @@ +#define CAIRO_VERSION_H 1 + +#include + +/* get the "real" version info instead of dummy cairo-version.h */ +#undef CAIRO_VERSION_H +#include "../cairo-version.h" + +#include + +int +main (void) +{ + printf ("Check linking to the just built cairo library\n"); + if (cairo_version () == CAIRO_VERSION) { + return 0; + } else { + fprintf (stderr, + "Error: linked to cairo version %s instead of %s\n", + cairo_version_string (), + CAIRO_VERSION_STRING); + return 1; + } +} diff --git a/Build/source/libs/cairo/cairo-src/src/check-plt.sh b/Build/source/libs/cairo/cairo-src/src/check-plt.sh new file mode 100755 index 00000000000..5a9dae1269d --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-plt.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +if which readelf 2>/dev/null >/dev/null; then + : +else + echo "'readelf' not found; skipping test" + exit 0 +fi + +test -z "$srcdir" && srcdir=. +test -z "$MAKE" && MAKE=make +stat=0 + +$MAKE check-has-hidden-symbols.i > /dev/null || exit 1 +if tail -1 check-has-hidden-symbols.i | grep CAIRO_HAS_HIDDEN_SYMBOLS >/dev/null; then + echo "Compiler doesn't support symbol visibility; skipping test" + exit 0 +fi + +for so in .libs/lib*.so; do + echo Checking "$so" for local PLT entries + readelf -W -r "$so" | grep 'JU\?MP_SLO' | grep 'cairo' >&2 && stat=1 +done + +exit $stat diff --git a/Build/source/libs/cairo/cairo-src/src/check-preprocessor-syntax.sh b/Build/source/libs/cairo/cairo-src/src/check-preprocessor-syntax.sh new file mode 100755 index 00000000000..b718f604ee7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/check-preprocessor-syntax.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +cd "$srcdir" +stat=0 + + +HEADERS=$all_cairo_headers +test "x$HEADERS" = x && HEADERS=`find . -name 'cairo*.h' ! -name 'cairo*-private.h' ! -name 'cairo*-inline.h' ! -name 'cairoint.h'` + +PRIVATE=$all_cairo_private +test "x$PRIVATE" = x && PRIVATE=`find . -name 'cairo*-private.h' -or -name 'cairo*-inline.h' -or -name 'cairoint.h'` + +SOURCES=$all_cairo_sources +test "x$SOURCES" = x && SOURCES=`find . -name 'cairo*.c' -or -name 'cairo*.cpp'` + +ALL="/dev/null $HEADERS $PRIVATE $SOURCES" + +echo 'Checking that public header files #include "cairo.h" first (or none)' + +for x in $HEADERS; do + grep '#.*\' "$x" /dev/null | head -n 1 +done | +grep -v '"cairo[.]h"' | +grep -v 'cairo[.]h:' | +grep . >&2 && stat=1 + + +echo 'Checking that private header files #include "some cairo header" first (or none)' + +for x in $PRIVATE; do + grep '#.*\' "$x" /dev/null | head -n 1 +done | +grep -v '"cairo.*[.]h"' | +grep -v 'cairoint[.]h:' | +grep . >&2 && stat=1 + + +echo 'Checking that source files #include "cairoint.h" first (or none)' + +for x in $SOURCES; do + grep '#.*\' "$x" /dev/null | head -n 1 +done | +grep -v '"cairoint[.]h"' | +grep . >&2 && stat=1 + + +echo 'Checking that there is no #include ' +grep '#.*\.*<.*cairo' $ALL >&2 && stat=1 + + +echo 'Checking that feature conditionals are used with #if only (not #ifdef)' +grep '#ifdef CAIRO_HAS_' $ALL && stat=1 +grep '#if.*defined[ ]*(CAIRO_HAS_' $ALL && stat=1 + +exit $stat diff --git a/Build/source/libs/cairo/cairo-src/src/test-base-compositor-surface.c b/Build/source/libs/cairo/cairo-src/src/test-base-compositor-surface.c new file mode 100644 index 00000000000..ff84b10aff7 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-base-compositor-surface.c @@ -0,0 +1,824 @@ +/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is University of Southern + * California. + * + * Contributor(s): + * Carl D. Worth + * Joonas Pihlaja + * Chris Wilson + */ + +#include "cairoint.h" + +#include "test-compositor-surface-private.h" + +#include "cairo-clip-private.h" +#include "cairo-composite-rectangles-private.h" +#include "cairo-compositor-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-region-private.h" +#include "cairo-traps-private.h" + +/* The intention is that this is a surface that just works, and most + * important of all does not try to be clever! + */ + +typedef cairo_int_status_t +(*draw_func_t) (cairo_image_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents); + +static pixman_op_t +_pixman_operator (cairo_operator_t op) +{ + switch ((int) op) { + case CAIRO_OPERATOR_CLEAR: + return PIXMAN_OP_CLEAR; + + case CAIRO_OPERATOR_SOURCE: + return PIXMAN_OP_SRC; + case CAIRO_OPERATOR_OVER: + return PIXMAN_OP_OVER; + case CAIRO_OPERATOR_IN: + return PIXMAN_OP_IN; + case CAIRO_OPERATOR_OUT: + return PIXMAN_OP_OUT; + case CAIRO_OPERATOR_ATOP: + return PIXMAN_OP_ATOP; + + case CAIRO_OPERATOR_DEST: + return PIXMAN_OP_DST; + case CAIRO_OPERATOR_DEST_OVER: + return PIXMAN_OP_OVER_REVERSE; + case CAIRO_OPERATOR_DEST_IN: + return PIXMAN_OP_IN_REVERSE; + case CAIRO_OPERATOR_DEST_OUT: + return PIXMAN_OP_OUT_REVERSE; + case CAIRO_OPERATOR_DEST_ATOP: + return PIXMAN_OP_ATOP_REVERSE; + + case CAIRO_OPERATOR_XOR: + return PIXMAN_OP_XOR; + case CAIRO_OPERATOR_ADD: + return PIXMAN_OP_ADD; + case CAIRO_OPERATOR_SATURATE: + return PIXMAN_OP_SATURATE; + + case CAIRO_OPERATOR_MULTIPLY: + return PIXMAN_OP_MULTIPLY; + case CAIRO_OPERATOR_SCREEN: + return PIXMAN_OP_SCREEN; + case CAIRO_OPERATOR_OVERLAY: + return PIXMAN_OP_OVERLAY; + case CAIRO_OPERATOR_DARKEN: + return PIXMAN_OP_DARKEN; + case CAIRO_OPERATOR_LIGHTEN: + return PIXMAN_OP_LIGHTEN; + case CAIRO_OPERATOR_COLOR_DODGE: + return PIXMAN_OP_COLOR_DODGE; + case CAIRO_OPERATOR_COLOR_BURN: + return PIXMAN_OP_COLOR_BURN; + case CAIRO_OPERATOR_HARD_LIGHT: + return PIXMAN_OP_HARD_LIGHT; + case CAIRO_OPERATOR_SOFT_LIGHT: + return PIXMAN_OP_SOFT_LIGHT; + case CAIRO_OPERATOR_DIFFERENCE: + return PIXMAN_OP_DIFFERENCE; + case CAIRO_OPERATOR_EXCLUSION: + return PIXMAN_OP_EXCLUSION; + case CAIRO_OPERATOR_HSL_HUE: + return PIXMAN_OP_HSL_HUE; + case CAIRO_OPERATOR_HSL_SATURATION: + return PIXMAN_OP_HSL_SATURATION; + case CAIRO_OPERATOR_HSL_COLOR: + return PIXMAN_OP_HSL_COLOR; + case CAIRO_OPERATOR_HSL_LUMINOSITY: + return PIXMAN_OP_HSL_LUMINOSITY; + + default: + ASSERT_NOT_REACHED; + return PIXMAN_OP_OVER; + } +} + +static cairo_image_surface_t * +create_composite_mask (cairo_image_surface_t *dst, + void *draw_closure, + draw_func_t draw_func, + const cairo_composite_rectangles_t *extents) +{ + cairo_image_surface_t *surface; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + surface = (cairo_image_surface_t *) + _cairo_image_surface_create_with_pixman_format (NULL, PIXMAN_a8, + extents->bounded.width, + extents->bounded.height, + 0); + if (unlikely (surface->base.status)) + return surface; + + status = draw_func (surface, draw_closure, + CAIRO_OPERATOR_ADD, &_cairo_pattern_white.base, + extents->bounded.x, extents->bounded.y, + &extents->bounded); + if (unlikely (status)) + goto error; + + status = _cairo_clip_combine_with_surface (extents->clip, + &surface->base, + extents->bounded.x, + extents->bounded.y); + if (unlikely (status)) + goto error; + + return surface; + +error: + cairo_surface_destroy (&surface->base); + return (cairo_image_surface_t *)_cairo_surface_create_in_error (status); +} + +/* Handles compositing with a clip surface when the operator allows + * us to combine the clip with the mask + */ +static cairo_status_t +clip_and_composite_with_mask (const cairo_composite_rectangles_t*extents, + draw_func_t draw_func, + void *draw_closure) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; + cairo_image_surface_t *mask; + pixman_image_t *src; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + int src_x, src_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + mask = create_composite_mask (dst, draw_closure, draw_func, extents); + if (unlikely (mask->base.status)) + return mask->base.status; + + src = _pixman_image_for_pattern (dst, + &extents->source_pattern.base, FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (unlikely (src == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto error; + } + + pixman_image_composite32 (_pixman_operator (extents->op), + src, mask->pixman_image, dst->pixman_image, + extents->bounded.x + src_x, + extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + pixman_image_unref (src); +error: + cairo_surface_destroy (&mask->base); + return status; +} + +/* Handles compositing with a clip surface when we have to do the operation + * in two pieces and combine them together. + */ +static cairo_status_t +clip_and_composite_combine (const cairo_composite_rectangles_t*extents, + draw_func_t draw_func, + void *draw_closure) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; + cairo_image_surface_t *tmp, *clip; + int clip_x, clip_y; + cairo_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + tmp = (cairo_image_surface_t *) + _cairo_image_surface_create_with_pixman_format (NULL, + dst->pixman_format, + extents->bounded.width, + extents->bounded.height, + 0); + if (unlikely (tmp->base.status)) + return tmp->base.status; + + pixman_image_composite32 (PIXMAN_OP_SRC, + dst->pixman_image, NULL, tmp->pixman_image, + extents->bounded.x, extents->bounded.y, + 0, 0, + 0, 0, + extents->bounded.width, extents->bounded.height); + + status = draw_func (tmp, draw_closure, + extents->op, &extents->source_pattern.base, + extents->bounded.x, extents->bounded.y, + &extents->bounded); + if (unlikely (status)) + goto error; + + clip = (cairo_image_surface_t *) + _cairo_clip_get_surface (extents->clip, &dst->base, &clip_x, &clip_y); + if (unlikely (clip->base.status)) + goto error; + + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + clip->pixman_image, NULL, dst->pixman_image, + extents->bounded.x - clip_x, extents->bounded.y - clip_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + pixman_image_composite32 (PIXMAN_OP_ADD, + tmp->pixman_image, clip->pixman_image, dst->pixman_image, + 0, 0, + extents->bounded.x - clip_x, extents->bounded.y - clip_y, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + cairo_surface_destroy (&clip->base); + + error: + cairo_surface_destroy (&tmp->base); + + return status; +} + +/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's + * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip)) + */ +static cairo_status_t +clip_and_composite_source (const cairo_composite_rectangles_t *extents, + draw_func_t draw_func, + void *draw_closure) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; + cairo_image_surface_t *mask; + pixman_image_t *src; + int src_x, src_y; + cairo_status_t status = CAIRO_STATUS_SUCCESS; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + mask = create_composite_mask (dst, draw_closure, draw_func, extents); + if (unlikely (mask->base.status)) + return mask->base.status; + + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + mask->pixman_image, NULL, dst->pixman_image, + 0, 0, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + src = _pixman_image_for_pattern (dst, + &extents->source_pattern.base, FALSE, + &extents->bounded, + &extents->source_sample_area, + &src_x, &src_y); + if (unlikely (src == NULL)) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + goto error; + } + + pixman_image_composite32 (PIXMAN_OP_ADD, + src, mask->pixman_image, dst->pixman_image, + extents->bounded.x + src_x, extents->bounded.y + src_y, + 0, 0, + extents->bounded.x, extents->bounded.y, + extents->bounded.width, extents->bounded.height); + + pixman_image_unref (src); + +error: + cairo_surface_destroy (&mask->base); + return status; +} + +static cairo_status_t +fixup_unbounded (const cairo_composite_rectangles_t *extents) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *)extents->surface; + pixman_image_t *mask; + int mask_x, mask_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + if (! _cairo_clip_is_region (extents->clip)) { + cairo_image_surface_t *clip; + + clip = (cairo_image_surface_t *) + _cairo_clip_get_surface (extents->clip, &dst->base, + &mask_x, &mask_y); + if (unlikely (clip->base.status)) + return clip->base.status; + + mask = pixman_image_ref (clip->pixman_image); + cairo_surface_destroy (&clip->base); + } else { + mask_x = mask_y = 0; + mask = _pixman_image_for_color (CAIRO_COLOR_WHITE); + if (unlikely (mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + /* top */ + if (extents->bounded.y != extents->unbounded.y) { + int x = extents->unbounded.x; + int y = extents->unbounded.y; + int width = extents->unbounded.width; + int height = extents->bounded.y - y; + + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + mask, NULL, dst->pixman_image, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + /* left */ + if (extents->bounded.x != extents->unbounded.x) { + int x = extents->unbounded.x; + int y = extents->bounded.y; + int width = extents->bounded.x - x; + int height = extents->bounded.height; + + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + mask, NULL, dst->pixman_image, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + /* right */ + if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) { + int x = extents->bounded.x + extents->bounded.width; + int y = extents->bounded.y; + int width = extents->unbounded.x + extents->unbounded.width - x; + int height = extents->bounded.height; + + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + mask, NULL, dst->pixman_image, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + /* bottom */ + if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) { + int x = extents->unbounded.x; + int y = extents->bounded.y + extents->bounded.height; + int width = extents->unbounded.width; + int height = extents->unbounded.y + extents->unbounded.height - y; + + pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, + mask, NULL, dst->pixman_image, + x - mask_x, y - mask_y, + 0, 0, + x, y, + width, height); + } + + pixman_image_unref (mask); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +set_clip_region (cairo_composite_rectangles_t *extents) +{ + cairo_image_surface_t *dst = (cairo_image_surface_t *) extents->surface; + cairo_region_t *region = _cairo_clip_get_region (extents->clip); + pixman_region32_t *rgn = region ? ®ion->rgn : NULL; + if (! pixman_image_set_clip_region32 (dst->pixman_image, rgn)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +clip_and_composite (cairo_composite_rectangles_t *extents, + draw_func_t draw_func, + void *draw_closure) +{ + cairo_status_t status; + + status = set_clip_region (extents); + if (unlikely (status)) + return status; + + if (extents->op == CAIRO_OPERATOR_SOURCE) { + status = clip_and_composite_source (extents, draw_func, draw_closure); + } else { + if (extents->op == CAIRO_OPERATOR_CLEAR) { + extents->source_pattern.solid = _cairo_pattern_white; + extents->op = CAIRO_OPERATOR_DEST_OUT; + } + if (! _cairo_clip_is_region (extents->clip)) { + if (extents->is_bounded) + status = clip_and_composite_with_mask (extents, draw_func, draw_closure); + else + status = clip_and_composite_combine (extents, draw_func, draw_closure); + } else { + status = draw_func ((cairo_image_surface_t *) extents->surface, + draw_closure, + extents->op, + &extents->source_pattern.base, + 0, 0, + &extents->bounded); + } + } + + if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) + status = fixup_unbounded (extents); + + return status; +} + +/* high-level compositor interface */ + +static cairo_int_status_t +composite_paint (cairo_image_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents) +{ + cairo_rectangle_int_t sample; + pixman_image_t *src; + int src_x, src_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + _cairo_pattern_sampled_area (pattern, extents, &sample); + src = _pixman_image_for_pattern (dst, + pattern, FALSE, + extents, &sample, + &src_x, &src_y); + if (unlikely (src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + TRACE ((stderr, "%s: src=(%d, %d), dst=(%d, %d) size=%dx%d\n", __FUNCTION__, + extents->x + src_x, extents->y + src_y, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height)); + + pixman_image_composite32 (_pixman_operator (op), + src, NULL, dst->pixman_image, + extents->x + src_x, extents->y + src_y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + pixman_image_unref (src); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +base_compositor_paint (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + TRACE ((stderr, "%s\n", __FUNCTION__)); + return clip_and_composite (extents, composite_paint, NULL); +} + +static cairo_int_status_t +composite_mask (cairo_image_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents) +{ + cairo_rectangle_int_t sample; + pixman_image_t *src, *mask; + int src_x, src_y; + int mask_x, mask_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + _cairo_pattern_sampled_area (pattern, extents, &sample); + src = _pixman_image_for_pattern (dst, pattern, FALSE, + extents, &sample, + &src_x, &src_y); + if (unlikely (src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + _cairo_pattern_sampled_area (closure, extents, &sample); + mask = _pixman_image_for_pattern (dst, closure, TRUE, + extents, &sample, + &mask_x, &mask_y); + if (unlikely (mask == NULL)) { + pixman_image_unref (src); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + pixman_image_composite32 (_pixman_operator (op), + src, mask, dst->pixman_image, + extents->x + src_x, extents->y + src_y, + extents->x + mask_x, extents->y + mask_y, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + pixman_image_unref (mask); + pixman_image_unref (src); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +base_compositor_mask (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents) +{ + TRACE ((stderr, "%s\n", __FUNCTION__)); + return clip_and_composite (extents, composite_mask, &extents->mask_pattern.base); +} + +typedef struct { + cairo_traps_t traps; + cairo_antialias_t antialias; +} composite_traps_info_t; + +static cairo_int_status_t +composite_traps (cairo_image_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents) +{ + composite_traps_info_t *info = closure; + cairo_rectangle_int_t sample; + pixman_image_t *src, *mask; + int src_x, src_y; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + _cairo_pattern_sampled_area (pattern, extents, &sample); + src = _pixman_image_for_pattern (dst, pattern, FALSE, + extents, &sample, + &src_x, &src_y); + if (unlikely (src == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + mask = pixman_image_create_bits (info->antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8, + extents->width, extents->height, + NULL, 0); + if (unlikely (mask == NULL)) { + pixman_image_unref (src); + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + + _pixman_image_add_traps (mask, extents->x, extents->y, &info->traps); + pixman_image_composite32 (_pixman_operator (op), + src, mask, dst->pixman_image, + extents->x + src_x - dst_x, extents->y + src_y - dst_y, + 0, 0, + extents->x - dst_x, extents->y - dst_y, + extents->width, extents->height); + + pixman_image_unref (mask); + pixman_image_unref (src); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +trim_extents_to_traps (cairo_composite_rectangles_t *extents, + cairo_traps_t *traps) +{ + cairo_box_t box; + + /* X trims the affected area to the extents of the trapezoids, so + * we need to compensate when fixing up the unbounded area. + */ + _cairo_traps_extents (traps, &box); + return _cairo_composite_rectangles_intersect_mask_extents (extents, &box); +} + +static cairo_int_status_t +base_compositor_stroke (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias) +{ + composite_traps_info_t info; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + info.antialias = antialias; + _cairo_traps_init_with_clip (&info.traps, extents->clip); + status = _cairo_path_fixed_stroke_polygon_to_traps (path, style, + ctm, ctm_inverse, + tolerance, + &info.traps); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = trim_extents_to_traps (extents, &info.traps); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite (extents, composite_traps, &info); + _cairo_traps_fini (&info.traps); + + return status; +} + +static cairo_int_status_t +base_compositor_fill (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias) +{ + composite_traps_info_t info; + cairo_int_status_t status; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + info.antialias = antialias; + _cairo_traps_init_with_clip (&info.traps, extents->clip); + status = _cairo_path_fixed_fill_to_traps (path, + fill_rule, tolerance, + &info.traps); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = trim_extents_to_traps (extents, &info.traps); + if (likely (status == CAIRO_INT_STATUS_SUCCESS)) + status = clip_and_composite (extents, composite_traps, &info); + _cairo_traps_fini (&info.traps); + + return status; +} + +static cairo_int_status_t +composite_glyphs (cairo_image_surface_t *dst, + void *closure, + cairo_operator_t op, + const cairo_pattern_t *pattern, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents) +{ + cairo_composite_glyphs_info_t *info = closure; + pixman_image_t *mask; + cairo_status_t status; + int i; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + + mask = pixman_image_create_bits (PIXMAN_a8, + extents->width, extents->height, + NULL, 0); + if (unlikely (mask == NULL)) + return _cairo_error (CAIRO_STATUS_NO_MEMORY); + + status = CAIRO_STATUS_SUCCESS; + _cairo_scaled_font_freeze_cache (info->font); + for (i = 0; i < info->num_glyphs; i++) { + cairo_image_surface_t *glyph_surface; + cairo_scaled_glyph_t *scaled_glyph; + unsigned long glyph_index = info->glyphs[i].index; + int x, y; + + status = _cairo_scaled_glyph_lookup (info->font, glyph_index, + CAIRO_SCALED_GLYPH_INFO_SURFACE, + &scaled_glyph); + + if (unlikely (status)) + break; + + glyph_surface = scaled_glyph->surface; + if (glyph_surface->width && glyph_surface->height) { + /* round glyph locations to the nearest pixel */ + /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ + x = _cairo_lround (info->glyphs[i].x - + glyph_surface->base.device_transform.x0); + y = _cairo_lround (info->glyphs[i].y - + glyph_surface->base.device_transform.y0); + + pixman_image_composite32 (PIXMAN_OP_ADD, + glyph_surface->pixman_image, NULL, mask, + 0, 0, + 0, 0, + x - extents->x, y - extents->y, + glyph_surface->width, + glyph_surface->height); + } + } + _cairo_scaled_font_thaw_cache (info->font); + + if (status == CAIRO_STATUS_SUCCESS) { + cairo_rectangle_int_t sample; + pixman_image_t *src; + int src_x, src_y; + + _cairo_pattern_sampled_area (pattern, extents, &sample); + src = _pixman_image_for_pattern (dst, pattern, FALSE, + extents, &sample, + &src_x, &src_y); + if (src != NULL) { + dst_x = extents->x - dst_x; + dst_y = extents->y - dst_y; + pixman_image_composite32 (_pixman_operator (op), + src, mask, dst->pixman_image, + src_x + dst_x, src_y + dst_y, + 0, 0, + dst_x, dst_y, + extents->width, extents->height); + pixman_image_unref (src); + } else + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + } + pixman_image_unref (mask); + + return status; +} + +static cairo_int_status_t +base_compositor_glyphs (const cairo_compositor_t *_compositor, + cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_bool_t overlap) +{ + cairo_composite_glyphs_info_t info; + + info.font = scaled_font; + info.glyphs = glyphs; + info.num_glyphs = num_glyphs; + + TRACE ((stderr, "%s\n", __FUNCTION__)); + return clip_and_composite (extents, composite_glyphs, &info); +} + +static const cairo_compositor_t base_compositor = { + &__cairo_no_compositor, + + base_compositor_paint, + base_compositor_mask, + base_compositor_stroke, + base_compositor_fill, + base_compositor_glyphs, +}; + +cairo_surface_t * +_cairo_test_base_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (&base_compositor, + content, width, height); +} diff --git a/Build/source/libs/cairo/cairo-src/src/test-compositor-surface-private.h b/Build/source/libs/cairo/cairo-src/src/test-compositor-surface-private.h new file mode 100644 index 00000000000..491f241bacc --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-compositor-surface-private.h @@ -0,0 +1,56 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef TEST_COMPOSITOR_SURFACE_PRIVATE_H +#define TEST_COMPOSITOR_SURFACE_PRIVATE_H + +#include "cairo.h" + +#include "test-compositor-surface.h" + +#include "cairo-compiler-private.h" +#include "cairo-compositor-private.h" + +CAIRO_BEGIN_DECLS + +cairo_private cairo_surface_t * +test_compositor_surface_create (const cairo_compositor_t *compositor, + cairo_content_t content, + int width, + int height); + +CAIRO_END_DECLS + +#endif /* TEST_COMPOSITOR_SURFACE_PRIVATE H */ diff --git a/Build/source/libs/cairo/cairo-src/src/test-compositor-surface.c b/Build/source/libs/cairo/cairo-src/src/test-compositor-surface.c new file mode 100644 index 00000000000..1cc5f692120 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-compositor-surface.c @@ -0,0 +1,264 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#include "cairoint.h" + +#include "test-compositor-surface-private.h" + +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-backend-private.h" + +typedef struct _test_compositor_surface { + cairo_image_surface_t base; +} test_compositor_surface_t; + +static const cairo_surface_backend_t test_compositor_surface_backend; + +cairo_surface_t * +test_compositor_surface_create (const cairo_compositor_t *compositor, + cairo_content_t content, + int width, + int height) +{ + test_compositor_surface_t *surface; + pixman_image_t *pixman_image; + pixman_format_code_t pixman_format; + + switch (content) { + case CAIRO_CONTENT_ALPHA: + pixman_format = PIXMAN_a8; + break; + case CAIRO_CONTENT_COLOR: + pixman_format = PIXMAN_x8r8g8b8; + break; + case CAIRO_CONTENT_COLOR_ALPHA: + pixman_format = PIXMAN_a8r8g8b8; + break; + default: + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); + } + + pixman_image = pixman_image_create_bits (pixman_format, width, height, + NULL, 0); + if (unlikely (pixman_image == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface = malloc (sizeof (test_compositor_surface_t)); + if (unlikely (surface == NULL)) { + pixman_image_unref (pixman_image); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + _cairo_surface_init (&surface->base.base, + &test_compositor_surface_backend, + NULL, /* device */ + content); + _cairo_image_surface_init (&surface->base, pixman_image, pixman_format); + + surface->base.compositor = compositor; + + return &surface->base.base; +} + +static cairo_surface_t * +test_compositor_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + test_compositor_surface_t *surface = abstract_surface; + + return test_compositor_surface_create (surface->base.compositor, + content, width, height); +} + +static cairo_int_status_t +test_compositor_surface_paint (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_paint (surface->base.compositor, + _surface, op, source, + clip); +} + +static cairo_int_status_t +test_compositor_surface_mask (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_mask (surface->base.compositor, + _surface, op, source, mask, + clip); +} + +static cairo_int_status_t +test_compositor_surface_stroke (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + if (antialias == CAIRO_ANTIALIAS_DEFAULT) + antialias = CAIRO_ANTIALIAS_BEST; + return _cairo_compositor_stroke (surface->base.compositor, + _surface, op, source, + path, style, ctm, ctm_inverse, + tolerance, antialias, + clip); +} + +static cairo_int_status_t +test_compositor_surface_fill (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + if (antialias == CAIRO_ANTIALIAS_DEFAULT) + antialias = CAIRO_ANTIALIAS_BEST; + return _cairo_compositor_fill (surface->base.compositor, + _surface, op, source, + path, fill_rule, tolerance, antialias, + clip); +} + +static cairo_int_status_t +test_compositor_surface_glyphs (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_glyphs (surface->base.compositor, + _surface, op, source, + glyphs, num_glyphs, scaled_font, + clip); +} + +static const cairo_surface_backend_t test_compositor_surface_backend = { + CAIRO_SURFACE_TYPE_IMAGE, + _cairo_image_surface_finish, + _cairo_default_context_create, + + test_compositor_surface_create_similar, + NULL, /* create similar image */ + _cairo_image_surface_map_to_image, + _cairo_image_surface_unmap_image, + + _cairo_image_surface_source, + _cairo_image_surface_acquire_source_image, + _cairo_image_surface_release_source_image, + _cairo_image_surface_snapshot, + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_image_surface_get_extents, + _cairo_image_surface_get_font_options, + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + test_compositor_surface_paint, + test_compositor_surface_mask, + test_compositor_surface_stroke, + test_compositor_surface_fill, + NULL, /* fill/stroke */ + test_compositor_surface_glyphs, +}; + +static const cairo_compositor_t * +get_fallback_compositor (void) +{ + return &_cairo_fallback_compositor; +} + +cairo_surface_t * +_cairo_test_fallback_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (get_fallback_compositor(), + content, width, height); +} + +cairo_surface_t * +_cairo_test_mask_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (_cairo_image_mask_compositor_get(), + content, width, height); +} + +cairo_surface_t * +_cairo_test_traps_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (_cairo_image_traps_compositor_get(), + content, width, height); +} + +cairo_surface_t * +_cairo_test_spans_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (_cairo_image_spans_compositor_get(), + content, width, height); +} diff --git a/Build/source/libs/cairo/cairo-src/src/test-compositor-surface.h b/Build/source/libs/cairo/cairo-src/src/test-compositor-surface.h new file mode 100644 index 00000000000..8d8af2d5409 --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-compositor-surface.h @@ -0,0 +1,71 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef TEST_COMPOSITOR_SURFACE_H +#define TEST_COMPOSITOR_SURFACE_H + +#include "cairo.h" + +CAIRO_BEGIN_DECLS + +cairo_surface_t * +_cairo_test_fallback_compositor_surface_create (cairo_content_t content, + int width, + int height); + + +cairo_surface_t * +_cairo_test_mask_compositor_surface_create (cairo_content_t content, + int width, + int height); + +cairo_surface_t * +_cairo_test_traps_compositor_surface_create (cairo_content_t content, + int width, + int height); + +cairo_surface_t * +_cairo_test_spans_compositor_surface_create (cairo_content_t content, + int width, + int height); + +cairo_surface_t * +_cairo_test_base_compositor_surface_create (cairo_content_t content, + int width, + int height); + +CAIRO_END_DECLS + +#endif /* TEST_COMPOSITOR_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.c b/Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.c new file mode 100644 index 00000000000..2301055e30a --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.c @@ -0,0 +1,480 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + + +#include "cairoint.h" + +#include "test-null-compositor-surface.h" + +#include "cairo-compositor-private.h" +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-image-surface-private.h" +#include "cairo-surface-backend-private.h" +#include "cairo-spans-compositor-private.h" +#include "cairo-spans-private.h" + +typedef struct _test_compositor_surface { + cairo_image_surface_t base; +} test_compositor_surface_t; + +static const cairo_surface_backend_t test_compositor_surface_backend; + +static cairo_surface_t * +test_compositor_surface_create (const cairo_compositor_t *compositor, + cairo_content_t content, + int width, + int height) +{ + test_compositor_surface_t *surface; + pixman_image_t *pixman_image; + pixman_format_code_t pixman_format; + + switch (content) { + case CAIRO_CONTENT_ALPHA: + pixman_format = PIXMAN_a8; + break; + case CAIRO_CONTENT_COLOR: + pixman_format = PIXMAN_x8r8g8b8; + break; + case CAIRO_CONTENT_COLOR_ALPHA: + pixman_format = PIXMAN_a8r8g8b8; + break; + default: + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); + } + + pixman_image = pixman_image_create_bits (pixman_format, width, height, + NULL, 0); + if (unlikely (pixman_image == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + surface = malloc (sizeof (test_compositor_surface_t)); + if (unlikely (surface == NULL)) { + pixman_image_unref (pixman_image); + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + } + + _cairo_surface_init (&surface->base.base, + &test_compositor_surface_backend, + NULL, /* device */ + content); + _cairo_image_surface_init (&surface->base, pixman_image, pixman_format); + + surface->base.compositor = compositor; + + return &surface->base.base; +} + +static cairo_surface_t * +test_compositor_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + test_compositor_surface_t *surface = abstract_surface; + + return test_compositor_surface_create (surface->base.compositor, + content, width, height); +} + +static cairo_int_status_t +test_compositor_surface_paint (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_paint (surface->base.compositor, + _surface, op, source, + clip); +} + +static cairo_int_status_t +test_compositor_surface_mask (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_mask (surface->base.compositor, + _surface, op, source, mask, + clip); +} + +static cairo_int_status_t +test_compositor_surface_stroke (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_stroke (surface->base.compositor, + _surface, op, source, + path, style, ctm, ctm_inverse, + tolerance, antialias, + clip); +} + +static cairo_int_status_t +test_compositor_surface_fill (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_fill (surface->base.compositor, + _surface, op, source, + path, fill_rule, tolerance, antialias, + clip); +} + +static cairo_int_status_t +test_compositor_surface_glyphs (void *_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + cairo_glyph_t *glyphs, + int num_glyphs, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + test_compositor_surface_t *surface = _surface; + return _cairo_compositor_glyphs (surface->base.compositor, + _surface, op, source, + glyphs, num_glyphs, scaled_font, + clip); +} + +static const cairo_surface_backend_t test_compositor_surface_backend = { + CAIRO_SURFACE_TYPE_IMAGE, + _cairo_image_surface_finish, + _cairo_default_context_create, + + test_compositor_surface_create_similar, + NULL, /* create similar image */ + _cairo_image_surface_map_to_image, + _cairo_image_surface_unmap_image, + + _cairo_image_surface_source, + _cairo_image_surface_acquire_source_image, + _cairo_image_surface_release_source_image, + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _cairo_image_surface_get_extents, + _cairo_image_surface_get_font_options, + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + test_compositor_surface_paint, + test_compositor_surface_mask, + test_compositor_surface_stroke, + test_compositor_surface_fill, + NULL, /* fill/stroke */ + test_compositor_surface_glyphs, +}; + +static cairo_int_status_t +acquire (void *abstract_dst) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +release (void *abstract_dst) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +set_clip_region (void *_surface, + cairo_region_t *region) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t * +pattern_to_surface (cairo_surface_t *dst, + const cairo_pattern_t *pattern, + cairo_bool_t is_mask, + const cairo_rectangle_int_t *extents, + const cairo_rectangle_int_t *sample, + int *src_x, int *src_y) +{ + return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); +} + +static cairo_int_status_t +fill_boxes (void *_dst, + cairo_operator_t op, + const cairo_color_t *color, + cairo_boxes_t *boxes) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +draw_image_boxes (void *_dst, + cairo_image_surface_t *image, + cairo_boxes_t *boxes, + int dx, int dy) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +lerp (void *_dst, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + unsigned int width, + unsigned int height) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_boxes (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + cairo_surface_t *abstract_mask, + int src_x, + int src_y, + int mask_x, + int mask_y, + int dst_x, + int dst_y, + cairo_boxes_t *boxes, + const cairo_rectangle_int_t *extents) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_traps (void *_dst, + cairo_operator_t op, + cairo_surface_t *abstract_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + const cairo_rectangle_int_t *extents, + cairo_antialias_t antialias, + cairo_traps_t *traps) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +check_composite_glyphs (const cairo_composite_rectangles_t *extents, + cairo_scaled_font_t *scaled_font, + cairo_glyph_t *glyphs, + int *num_glyphs) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +composite_glyphs (void *_dst, + cairo_operator_t op, + cairo_surface_t *_src, + int src_x, + int src_y, + int dst_x, + int dst_y, + cairo_composite_glyphs_info_t *info) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +spans (void *abstract_renderer, + int y, int height, + const cairo_half_open_span_t *spans, + unsigned num_spans) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_status_t +finish_spans (void *abstract_renderer) +{ + return CAIRO_STATUS_SUCCESS; +} + +static cairo_int_status_t +span_renderer_init (cairo_abstract_span_renderer_t *_r, + const cairo_composite_rectangles_t *composite, + cairo_antialias_t antialias, + cairo_bool_t needs_clip) +{ + cairo_span_renderer_t *r = (cairo_span_renderer_t *)_r; + r->render_rows = spans; + r->finish = finish_spans; + return CAIRO_STATUS_SUCCESS; +} + +static void +span_renderer_fini (cairo_abstract_span_renderer_t *_r, + cairo_int_status_t status) +{ +} + +static const cairo_compositor_t * +no_fallback_compositor_get (void) +{ + return &__cairo_no_compositor; +} + +static cairo_int_status_t +check_composite (const cairo_composite_rectangles_t *extents) +{ + return CAIRO_STATUS_SUCCESS; +} + +static const cairo_compositor_t * +no_traps_compositor_get (void) +{ + static cairo_traps_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_traps_compositor_init (&compositor, + no_fallback_compositor_get ()); + + compositor.acquire = acquire; + compositor.release = release; + compositor.set_clip_region = set_clip_region; + compositor.pattern_to_surface = pattern_to_surface; + compositor.draw_image_boxes = draw_image_boxes; + //compositor.copy_boxes = copy_boxes; + compositor.fill_boxes = fill_boxes; + compositor.check_composite = check_composite; + compositor.composite = composite; + compositor.lerp = lerp; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + //compositor.check_composite_traps = check_composite_traps; + compositor.composite_traps = composite_traps; + compositor.check_composite_glyphs = check_composite_glyphs; + compositor.composite_glyphs = composite_glyphs; + } + + return &compositor.base; +} + +static const cairo_compositor_t * +no_spans_compositor_get (void) +{ + static cairo_spans_compositor_t compositor; + + if (compositor.base.delegate == NULL) { + _cairo_spans_compositor_init (&compositor, + no_traps_compositor_get()); + + //compositor.acquire = acquire; + //compositor.release = release; + compositor.fill_boxes = fill_boxes; + //compositor.check_composite_boxes = check_composite_boxes; + compositor.composite_boxes = composite_boxes; + //compositor.check_span_renderer = check_span_renderer; + compositor.renderer_init = span_renderer_init; + compositor.renderer_fini = span_renderer_fini; + } + + return &compositor.base; +} + +cairo_surface_t * +_cairo_test_no_fallback_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (no_fallback_compositor_get(), + content, width, height); +} + +cairo_surface_t * +_cairo_test_no_traps_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (no_traps_compositor_get(), + content, width, height); +} + +cairo_surface_t * +_cairo_test_no_spans_compositor_surface_create (cairo_content_t content, + int width, + int height) +{ + return test_compositor_surface_create (no_spans_compositor_get(), + content, width, height); +} diff --git a/Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.h b/Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.h new file mode 100644 index 00000000000..52d864b28df --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-null-compositor-surface.h @@ -0,0 +1,60 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2011 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Intel Corporation + * + * Contributor(s): + * Chris Wilson + */ + +#ifndef TEST_NULL_COMPOSITOR_SURFACE_H +#define TEST_NULL_COMPOSITOR_SURFACE_H + +#include "cairo.h" + +CAIRO_BEGIN_DECLS + +cairo_surface_t * +_cairo_test_no_fallback_compositor_surface_create (cairo_content_t content, + int width, + int height); + +cairo_surface_t * +_cairo_test_no_traps_compositor_surface_create (cairo_content_t content, + int width, + int height); + +cairo_surface_t * +_cairo_test_no_spans_compositor_surface_create (cairo_content_t content, + int width, + int height); + +CAIRO_END_DECLS + +#endif /* TEST_NULL_COMPOSITOR_SURFACE_H */ diff --git a/Build/source/libs/cairo/cairo-src/src/test-paginated-surface.c b/Build/source/libs/cairo/cairo-src/src/test-paginated-surface.c new file mode 100644 index 00000000000..0a7c79b37bf --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-paginated-surface.c @@ -0,0 +1,286 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + */ + +/* This isn't a "real" surface, but just something to be used by the + * test suite to help exercise the paginated-surface paths in cairo. + * + * The defining feature of this backend is that it uses a paginated + * surface to record all operations, and then replays everything to an + * image surface. + * + * It's possible that this code might serve as a good starting point + * for someone working on bringing up a new paginated-surface-based + * backend. + */ + +#include "cairoint.h" + +#include "test-paginated-surface.h" + +#include "cairo-default-context-private.h" +#include "cairo-error-private.h" +#include "cairo-paginated-private.h" +#include "cairo-surface-backend-private.h" + +typedef struct _test_paginated_surface { + cairo_surface_t base; + cairo_surface_t *target; + cairo_paginated_mode_t paginated_mode; +} test_paginated_surface_t; + +static const cairo_surface_backend_t test_paginated_surface_backend; +static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend; + +cairo_surface_t * +_cairo_test_paginated_surface_create (cairo_surface_t *target) +{ + cairo_status_t status; + cairo_surface_t *paginated; + test_paginated_surface_t *surface; + + status = cairo_surface_status (target); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); + + surface = malloc (sizeof (test_paginated_surface_t)); + if (unlikely (surface == NULL)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + + _cairo_surface_init (&surface->base, + &test_paginated_surface_backend, + NULL, /* device */ + target->content); + + surface->target = cairo_surface_reference (target); + + paginated = _cairo_paginated_surface_create (&surface->base, + target->content, + &test_paginated_surface_paginated_backend); + status = paginated->status; + if (status == CAIRO_STATUS_SUCCESS) { + /* paginated keeps the only reference to surface now, drop ours */ + cairo_surface_destroy (&surface->base); + return paginated; + } + + cairo_surface_destroy (target); + free (surface); + return _cairo_surface_create_in_error (status); +} + +static cairo_status_t +_test_paginated_surface_finish (void *abstract_surface) +{ + test_paginated_surface_t *surface = abstract_surface; + + cairo_surface_destroy (surface->target); + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_bool_t +_test_paginated_surface_get_extents (void *abstract_surface, + cairo_rectangle_int_t *rectangle) +{ + test_paginated_surface_t *surface = abstract_surface; + + return _cairo_surface_get_extents (surface->target, rectangle); +} + +static cairo_int_status_t +_test_paginated_surface_paint (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_clip_t *clip) +{ + test_paginated_surface_t *surface = abstract_surface; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return CAIRO_STATUS_SUCCESS; + + return _cairo_surface_paint (surface->target, op, source, clip); +} + +static cairo_int_status_t +_test_paginated_surface_mask (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_pattern_t *mask, + const cairo_clip_t *clip) +{ + test_paginated_surface_t *surface = abstract_surface; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return CAIRO_STATUS_SUCCESS; + + return _cairo_surface_mask (surface->target, + op, source, mask, clip); +} + +static cairo_int_status_t +_test_paginated_surface_stroke (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + const cairo_stroke_style_t *style, + const cairo_matrix_t *ctm, + const cairo_matrix_t *ctm_inverse, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + test_paginated_surface_t *surface = abstract_surface; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return CAIRO_STATUS_SUCCESS; + + return _cairo_surface_stroke (surface->target, op, source, + path, style, + ctm, ctm_inverse, + tolerance, antialias, + clip); +} + +static cairo_int_status_t +_test_paginated_surface_fill (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const cairo_path_fixed_t *path, + cairo_fill_rule_t fill_rule, + double tolerance, + cairo_antialias_t antialias, + const cairo_clip_t *clip) +{ + test_paginated_surface_t *surface = abstract_surface; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return CAIRO_STATUS_SUCCESS; + + return _cairo_surface_fill (surface->target, op, source, + path, fill_rule, + tolerance, antialias, + clip); +} + +static cairo_bool_t +_test_paginated_surface_has_show_text_glyphs (void *abstract_surface) +{ + test_paginated_surface_t *surface = abstract_surface; + + return cairo_surface_has_show_text_glyphs (surface->target); +} + +static cairo_int_status_t +_test_paginated_surface_show_text_glyphs (void *abstract_surface, + cairo_operator_t op, + const cairo_pattern_t *source, + const char *utf8, + int utf8_len, + cairo_glyph_t *glyphs, + int num_glyphs, + const cairo_text_cluster_t *clusters, + int num_clusters, + cairo_text_cluster_flags_t cluster_flags, + cairo_scaled_font_t *scaled_font, + const cairo_clip_t *clip) +{ + test_paginated_surface_t *surface = abstract_surface; + + if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) + return CAIRO_STATUS_SUCCESS; + + return _cairo_surface_show_text_glyphs (surface->target, op, source, + utf8, utf8_len, + glyphs, num_glyphs, + clusters, num_clusters, + cluster_flags, + scaled_font, + clip); +} + + +static void +_test_paginated_surface_set_paginated_mode (void *abstract_surface, + cairo_paginated_mode_t mode) +{ + test_paginated_surface_t *surface = abstract_surface; + + surface->paginated_mode = mode; +} + +static const cairo_surface_backend_t test_paginated_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED, + _test_paginated_surface_finish, + _cairo_default_context_create, + + /* Since we are a paginated user, we get to regard most of the + * surface backend interface as historical cruft and ignore it. */ + + NULL, /* create_similar */ + NULL, /* create similar image */ + NULL, /* map to image */ + NULL, /* unmap image */ + + _cairo_surface_default_source, + NULL, /* acquire_source_image */ + NULL, /* release_source_image */ + NULL, /* snapshot */ + + NULL, /* copy_page */ + NULL, /* show_page */ + + _test_paginated_surface_get_extents, + NULL, /* get_font_options */ + + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + + /* Here is the more "modern" section of the surface backend + * interface which is mostly just drawing functions */ + + _test_paginated_surface_paint, + _test_paginated_surface_mask, + _test_paginated_surface_stroke, + _test_paginated_surface_fill, + NULL, /* fill-stroke */ + NULL, /* replaced by show_text_glyphs */ + _test_paginated_surface_has_show_text_glyphs, + _test_paginated_surface_show_text_glyphs +}; + +static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend = { + NULL, /* start_page */ + _test_paginated_surface_set_paginated_mode +}; diff --git a/Build/source/libs/cairo/cairo-src/src/test-paginated-surface.h b/Build/source/libs/cairo/cairo-src/src/test-paginated-surface.h new file mode 100644 index 00000000000..2bd98aa5eee --- /dev/null +++ b/Build/source/libs/cairo/cairo-src/src/test-paginated-surface.h @@ -0,0 +1,48 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2005 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + * The Original Code is the cairo graphics library. + * + * The Initial Developer of the Original Code is Red Hat, Inc. + * + * Contributor(s): + * Carl Worth + */ + +#ifndef TEST_PAGINATED_SURFACE_H +#define TEST_PAGINATED_SURFACE_H + +#include "cairo.h" + +CAIRO_BEGIN_DECLS + +cairo_surface_t * +_cairo_test_paginated_surface_create (cairo_surface_t *target); + +CAIRO_END_DECLS + +#endif /* TEST_PAGINATED_SURFACE_H */ diff --git a/Build/source/libs/cairo/configure b/Build/source/libs/cairo/configure index 1c761b1c4fc..38af7a522eb 100755 --- a/Build/source/libs/cairo/configure +++ b/Build/source/libs/cairo/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for cairo (TeX Live) 1.14.2. +# Generated by GNU Autoconf 2.69 for cairo (TeX Live) 1.14.6. # # Report bugs to . # @@ -580,12 +580,12 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='cairo (TeX Live)' PACKAGE_TARNAME='cairo--tex-live-' -PACKAGE_VERSION='1.14.2' -PACKAGE_STRING='cairo (TeX Live) 1.14.2' +PACKAGE_VERSION='1.14.6' +PACKAGE_STRING='cairo (TeX Live) 1.14.6' PACKAGE_BUGREPORT='tex-k@tug.org' PACKAGE_URL='' -ac_unique_file="cairo-1.14.2/src/cairo.h" +ac_unique_file="cairo-src/src/cairo.h" # Factoring default headers for most tests. ac_includes_default="\ #include @@ -1349,7 +1349,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures cairo (TeX Live) 1.14.2 to adapt to many kinds of systems. +\`configure' configures cairo (TeX Live) 1.14.6 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1420,7 +1420,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of cairo (TeX Live) 1.14.2:";; + short | recursive ) echo "Configuration of cairo (TeX Live) 1.14.6:";; esac cat <<\_ACEOF @@ -1523,7 +1523,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -cairo (TeX Live) configure 1.14.2 +cairo (TeX Live) configure 1.14.6 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2129,7 +2129,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by cairo (TeX Live) $as_me 1.14.2, which was +It was created by cairo (TeX Live) $as_me 1.14.6, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -4383,7 +4383,7 @@ fi # Define the identity of the package. PACKAGE='cairo--tex-live-' - VERSION='1.14.2' + VERSION='1.14.6' cat >>confdefs.h <<_ACEOF @@ -6616,7 +6616,7 @@ LIBS=$kpse_save_LIBS echo timestamp >config.force fi -CAIRO_TREE=cairo-1.14.2 +CAIRO_TREE=cairo-src ac_config_files="$ac_config_files Makefile cairo/Makefile" @@ -7273,7 +7273,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by cairo (TeX Live) $as_me 1.14.2, which was +This file was extended by cairo (TeX Live) $as_me 1.14.6, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7339,7 +7339,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -cairo (TeX Live) config.status 1.14.2 +cairo (TeX Live) config.status 1.14.6 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/Build/source/libs/cairo/configure.ac b/Build/source/libs/cairo/configure.ac index 8818bcc142b..147aa8c8ea6 100644 --- a/Build/source/libs/cairo/configure.ac +++ b/Build/source/libs/cairo/configure.ac @@ -9,7 +9,7 @@ dnl m4_include([version.ac])[] dnl define cairo_version AC_INIT([cairo (TeX Live)], cairo_version, [tex-k@tug.org]) AC_PREREQ([2.65]) -AC_CONFIG_SRCDIR([cairo-]cairo_version[/src/cairo.h]) +AC_CONFIG_SRCDIR([cairo-src/src/cairo.h]) AC_CONFIG_AUX_DIR([../../build-aux]) AC_CONFIG_MACRO_DIRS([../../m4 m4]) @@ -92,7 +92,7 @@ KPSE_RESTORE_FLAGS echo timestamp >config.force fi -AC_SUBST([CAIRO_TREE], [cairo-]cairo_version) +AC_SUBST([CAIRO_TREE], [cairo-src]) AC_CONFIG_FILES([Makefile cairo/Makefile]) diff --git a/Build/source/libs/cairo/version.ac b/Build/source/libs/cairo/version.ac index 56690adf0de..711b9a9c961 100644 --- a/Build/source/libs/cairo/version.ac +++ b/Build/source/libs/cairo/version.ac @@ -8,4 +8,4 @@ dnl dnl -------------------------------------------------------- dnl dnl m4-include this file to define the current cairo version -m4_define([cairo_version], [1.14.2]) +m4_define([cairo_version], [1.14.6]) -- cgit v1.2.3